Update checked-in dependencies

This commit is contained in:
github-actions[bot] 2023-10-23 18:03:04 +00:00
parent 79817eb679
commit 9c3b394d7f
402 changed files with 12598 additions and 2912 deletions

View file

@ -10,12 +10,12 @@ jobs:
strategy:
matrix:
os: [windows-latest, macOS-latest, ubuntu-latest]
node: [8.x, 10.x, 12.x, 14.x]
node: [18.x, 19.x, 20.x]
steps:
- uses: actions/checkout@v1
- uses: actions/checkout@v4
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v1
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
- name: npm install, build, and test

View file

@ -7,17 +7,17 @@ jobs:
release-please:
runs-on: ubuntu-latest
steps:
- uses: GoogleCloudPlatform/release-please-action@v2
- uses: GoogleCloudPlatform/release-please-action@v3
id: release
with:
release-type: node
package-name: test-release-please
package-name: object-schema
# The logic below handles the npm publication:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
# these if statements ensure that a publication only occurs when
# a new release is created:
if: ${{ steps.release.outputs.release_created }}
- uses: actions/setup-node@v1
- uses: actions/setup-node@v3
with:
node-version: 12
registry-url: 'https://registry.npmjs.org'

View file

@ -1,5 +1,23 @@
# Changelog
## [2.0.1](https://github.com/humanwhocodes/object-schema/compare/v2.0.0...v2.0.1) (2023-10-20)
### Bug Fixes
* Custom properties should be available on thrown errors ([6ca80b0](https://github.com/humanwhocodes/object-schema/commit/6ca80b001a4ffb678b9b5544fc53322117374376))
## [2.0.0](https://github.com/humanwhocodes/object-schema/compare/v1.2.1...v2.0.0) (2023-10-18)
### ⚠ BREAKING CHANGES
* Throw custom errors instead of generics.
### Features
* Throw custom errors instead of generics. ([c6c01d7](https://github.com/humanwhocodes/object-schema/commit/c6c01d71eb354bf7b1fb3e883c40f7bd9b61647c))
### [1.2.1](https://www.github.com/humanwhocodes/object-schema/compare/v1.2.0...v1.2.1) (2021-11-02)

View file

@ -1,6 +1,6 @@
{
"name": "@humanwhocodes/object-schema",
"version": "1.2.1",
"version": "2.0.1",
"description": "An object schema merger/validator",
"main": "src/index.js",
"directories": {

View file

@ -62,9 +62,77 @@ function validateDefinition(name, strategy) {
}
}
//-----------------------------------------------------------------------------
// Errors
//-----------------------------------------------------------------------------
/**
* Error when an unexpected key is found.
*/
class UnexpectedKeyError extends Error {
/**
* Creates a new instance.
* @param {string} key The key that was unexpected.
*/
constructor(key) {
super(`Unexpected key "${key}" found.`);
}
}
/**
* Error when a required key is missing.
*/
class MissingKeyError extends Error {
/**
* Creates a new instance.
* @param {string} key The key that was missing.
*/
constructor(key) {
super(`Missing required key "${key}".`);
}
}
/**
* Error when a key requires other keys that are missing.
*/
class MissingDependentKeysError extends Error {
/**
* Creates a new instance.
* @param {string} key The key that was unexpected.
* @param {Array<string>} requiredKeys The keys that are required.
*/
constructor(key, requiredKeys) {
super(`Key "${key}" requires keys "${requiredKeys.join("\", \"")}".`);
}
}
/**
* Wrapper error for errors occuring during a merge or validate operation.
*/
class WrapperError {
/**
* Creates a new instance.
* @param {string} key The object key causing the error.
* @param {Error} source The source error.
*/
constructor(key, source) {
return Object.create(source, {
message: {
value: `Key "${key}": ` + source.message,
configurable: true,
writable: true,
enumerable: true
}
});
}
}
//-----------------------------------------------------------------------------
// Class
// Main
//-----------------------------------------------------------------------------
/**
@ -159,11 +227,11 @@ class ObjectSchema {
// double check arguments
if (objects.length < 2) {
throw new Error("merge() requires at least two arguments.");
throw new TypeError("merge() requires at least two arguments.");
}
if (objects.some(object => (object == null || typeof object !== "object"))) {
throw new Error("All arguments must be objects.");
throw new TypeError("All arguments must be objects.");
}
return objects.reduce((result, object) => {
@ -179,8 +247,7 @@ class ObjectSchema {
}
}
} catch (ex) {
ex.message = `Key "${key}": ` + ex.message;
throw ex;
throw new WrapperError(key, ex);
}
}
return result;
@ -200,7 +267,7 @@ class ObjectSchema {
// check to see if the key is defined
if (!this.hasKey(key)) {
throw new Error(`Unexpected key "${key}" found.`);
throw new UnexpectedKeyError(key);
}
// validate existing keys
@ -209,7 +276,7 @@ class ObjectSchema {
// first check to see if any other keys are required
if (Array.isArray(strategy.requires)) {
if (!strategy.requires.every(otherKey => otherKey in object)) {
throw new Error(`Key "${key}" requires keys "${strategy.requires.join("\", \"")}".`);
throw new MissingDependentKeysError(key, strategy.requires);
}
}
@ -217,15 +284,14 @@ class ObjectSchema {
try {
strategy.validate.call(strategy, object[key]);
} catch (ex) {
ex.message = `Key "${key}": ` + ex.message;
throw ex;
throw new WrapperError(key, ex);
}
}
// ensure required keys aren't missing
for (const [key] of this[requiredKeys]) {
if (!(key in object)) {
throw new Error(`Missing required key "${key}".`);
throw new MissingKeyError(key);
}
}

View file

@ -110,6 +110,54 @@ describe("ObjectSchema", () => {
});
it("should throw an error when merge() throws an error with a readonly message", () => {
let schema = new ObjectSchema({
foo: {
merge() {
throw {
get message() {
return "Boom!";
}
};
},
validate() {}
}
});
assert.throws(() => {
schema.merge({ foo: true }, { foo: true });
}, /Key "foo": Boom!/);
});
it("should throw an error with custom properties when merge() throws an error with custom properties", () => {
let schema = new ObjectSchema({
foo: {
merge() {
throw {
get message() {
return "Boom!";
},
booya: true
};
},
validate() {}
}
});
let errorThrown = false;
try {
schema.merge({ foo: true }, { foo: true });
} catch (ex) {
errorThrown = true;
assert.isTrue(ex.booya);
}
assert.isTrue(errorThrown);
});
it("should call the merge() strategy for one key when called", () => {
schema = new ObjectSchema({