Update checked-in dependencies
This commit is contained in:
parent
79817eb679
commit
9c3b394d7f
402 changed files with 12598 additions and 2912 deletions
86
node_modules/@humanwhocodes/object-schema/src/object-schema.js
generated
vendored
86
node_modules/@humanwhocodes/object-schema/src/object-schema.js
generated
vendored
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue