schema-utils
Advanced tools
Comparing version 4.2.0 to 4.3.0
@@ -6,6 +6,6 @@ export type JSONSchema4 = import("json-schema").JSONSchema4; | ||
export type Extend = { | ||
formatMinimum?: string | undefined; | ||
formatMaximum?: string | undefined; | ||
formatExclusiveMinimum?: string | undefined; | ||
formatExclusiveMaximum?: string | undefined; | ||
formatMinimum?: (string | number) | undefined; | ||
formatMaximum?: (string | number) | undefined; | ||
formatExclusiveMinimum?: (string | boolean) | undefined; | ||
formatExclusiveMaximum?: (string | boolean) | undefined; | ||
link?: string | undefined; | ||
@@ -12,0 +12,0 @@ undefinedAsNull?: boolean | undefined; |
@@ -87,3 +87,2 @@ "use strict"; | ||
} | ||
var _default = addAbsolutePathKeyword; | ||
exports.default = _default; | ||
var _default = exports.default = addAbsolutePathKeyword; |
@@ -36,3 +36,2 @@ "use strict"; | ||
} | ||
var _default = addUndefinedAsNullKeyword; | ||
exports.default = _default; | ||
var _default = exports.default = addUndefinedAsNullKeyword; |
@@ -29,3 +29,2 @@ "use strict"; | ||
}; | ||
var _default = memoize; | ||
exports.default = _default; | ||
var _default = exports.default = memoize; |
@@ -18,3 +18,3 @@ "use strict"; | ||
var _memorize = _interopRequireDefault(require("./util/memorize")); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; } | ||
const getAjv = (0, _memorize.default)(() => { | ||
@@ -39,4 +39,5 @@ // Use CommonJS require for ajv libs so TypeScript consumers aren't locked into esModuleInterop (see #110). | ||
ajvKeywords(ajv, ["instanceof", "patternRequired"]); | ||
// TODO set `{ keywords: true }` for the next major release and remove `keywords/limit.js` | ||
addFormats(ajv, { | ||
keywords: true | ||
keywords: false | ||
}); | ||
@@ -48,2 +49,6 @@ | ||
addAbsolutePathKeyword(ajv); | ||
// eslint-disable-next-line global-require | ||
const addLimitKeyword = require("./keywords/limit").default; | ||
addLimitKeyword(ajv); | ||
const addUndefinedAsNullKeyword = | ||
@@ -63,6 +68,6 @@ // eslint-disable-next-line global-require | ||
* @typedef {Object} Extend | ||
* @property {string=} formatMinimum | ||
* @property {string=} formatMaximum | ||
* @property {string=} formatExclusiveMinimum | ||
* @property {string=} formatExclusiveMaximum | ||
* @property {(string | number)=} formatMinimum | ||
* @property {(string | number)=} formatMaximum | ||
* @property {(string | boolean)=} formatExclusiveMinimum | ||
* @property {(string | boolean)=} formatExclusiveMaximum | ||
* @property {string=} link | ||
@@ -186,3 +191,3 @@ * @property {boolean=} undefinedAsNull | ||
let newErrors = []; | ||
for (const error of /** @type {Array<SchemaUtilErrorObject>} */errors) { | ||
for (const error of (/** @type {Array<SchemaUtilErrorObject>} */errors)) { | ||
const { | ||
@@ -189,0 +194,0 @@ instancePath |
@@ -8,3 +8,3 @@ "use strict"; | ||
var _memorize = _interopRequireDefault(require("./util/memorize")); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; } | ||
/** @typedef {import("json-schema").JSONSchema6} JSONSchema6 */ | ||
@@ -17,2 +17,3 @@ /** @typedef {import("json-schema").JSONSchema7} JSONSchema7 */ | ||
/** @typedef {import("./validate").SchemaUtilErrorObject} SchemaUtilErrorObject */ | ||
/** @enum {number} */ | ||
@@ -92,3 +93,3 @@ const SPECIFICITY = { | ||
*/ | ||
error => SPECIFICITY[/** @type {keyof typeof SPECIFICITY} */error.keyword] || 2); | ||
error => SPECIFICITY[(/** @type {keyof typeof SPECIFICITY} */error.keyword)] || 2); | ||
return newChildren; | ||
@@ -214,3 +215,3 @@ } | ||
function isObject(maybeObj) { | ||
return typeof maybeObj === "object" && maybeObj !== null; | ||
return typeof maybeObj === "object" && !Array.isArray(maybeObj) && maybeObj !== null; | ||
} | ||
@@ -387,3 +388,3 @@ | ||
for (let i = 1; i < newPath.length; i++) { | ||
const inner = schemaPart[/** @type {keyof Schema} */newPath[i]]; | ||
const inner = schemaPart[(/** @type {keyof Schema} */newPath[i])]; | ||
if (!inner) { | ||
@@ -431,3 +432,3 @@ break; | ||
} | ||
if ( /** @type {Schema & {instanceof: string | Array<string>}} */schema.instanceof) { | ||
if (/** @type {Schema & {instanceof: string | Array<string>}} */schema.instanceof) { | ||
const { | ||
@@ -457,14 +458,11 @@ instanceof: value | ||
if (schema.oneOf) { | ||
return (/** @type {Array<Schema>} */schema.oneOf.map(item => formatInnerSchema(item, true)).join(" | ") | ||
); | ||
return /** @type {Array<Schema>} */schema.oneOf.map(item => formatInnerSchema(item, true)).join(" | "); | ||
} | ||
if (schema.anyOf) { | ||
return (/** @type {Array<Schema>} */schema.anyOf.map(item => formatInnerSchema(item, true)).join(" | ") | ||
); | ||
return /** @type {Array<Schema>} */schema.anyOf.map(item => formatInnerSchema(item, true)).join(" | "); | ||
} | ||
if (schema.allOf) { | ||
return (/** @type {Array<Schema>} */schema.allOf.map(item => formatInnerSchema(item, true)).join(" & ") | ||
); | ||
return /** @type {Array<Schema>} */schema.allOf.map(item => formatInnerSchema(item, true)).join(" & "); | ||
} | ||
if ( /** @type {JSONSchema7} */schema.if) { | ||
if (/** @type {JSONSchema7} */schema.if) { | ||
const { | ||
@@ -510,4 +508,3 @@ if: ifValue, | ||
if (Array.isArray(schema.items) && schema.items.length > 0) { | ||
items = `${ | ||
/** @type {Array<Schema>} */schema.items.map(item => formatInnerSchema(item)).join(", ")}`; | ||
items = `${/** @type {Array<Schema>} */schema.items.map(item => formatInnerSchema(item)).join(", ")}`; | ||
if (hasAdditionalItems) { | ||
@@ -552,3 +549,3 @@ if (schema.additionalItems && isObject(schema.additionalItems) && Object.keys(schema.additionalItems).length > 0) { | ||
const required = schema.required ? schema.required : []; | ||
const allProperties = [...new Set( /** @type {Array<string>} */[].concat(required).concat(properties))]; | ||
const allProperties = [...new Set(/** @type {Array<string>} */[].concat(required).concat(properties))]; | ||
const objectStructure = allProperties.map(property => { | ||
@@ -617,3 +614,3 @@ const isRequired = required.includes(property); | ||
/** @type {Schema | undefined} */ | ||
const inner = schemaPart[/** @type {keyof Schema} */additionalPath[i]]; | ||
const inner = schemaPart[(/** @type {keyof Schema} */additionalPath[i])]; | ||
if (inner) { | ||
@@ -777,3 +774,3 @@ // eslint-disable-next-line no-param-reassign | ||
} = params; | ||
const [, ...hints] = getHints( /** @type {Schema} */parentSchema, true); | ||
const [, ...hints] = getHints(/** @type {Schema} */parentSchema, true); | ||
if (hints.length === 0) { | ||
@@ -892,4 +889,4 @@ hints.push(`should be ${comparison} ${limit}`); | ||
} = params; | ||
return `${instancePath} should not contain the item '${ | ||
/** @type {{ data: Array<any> }} **/error.data[i]}' twice${getSchemaNonTypes(parentSchema)}.${this.getSchemaPartDescription(parentSchema)}`; | ||
return `${instancePath} should not contain the item '${/** @type {{ data: Array<any> }} **/ | ||
error.data[i]}' twice${getSchemaNonTypes(parentSchema)}.${this.getSchemaPartDescription(parentSchema)}`; | ||
} | ||
@@ -921,3 +918,3 @@ case "additionalItems": | ||
const missingProperty = params.missingProperty.replace(/^\./, ""); | ||
const hasProperty = parentSchema && Boolean( /** @type {Schema} */ | ||
const hasProperty = parentSchema && Boolean(/** @type {Schema} */ | ||
parentSchema.properties && /** @type {Schema} */ | ||
@@ -989,3 +986,3 @@ parentSchema.properties[missingProperty]); | ||
{ | ||
const postfix = likeObject( /** @type {Schema} */error.parentSchema) ? `\n${this.getSchemaPartText(error.parentSchema)}` : ""; | ||
const postfix = likeObject(/** @type {Schema} */error.parentSchema) ? `\n${this.getSchemaPartText(error.parentSchema)}` : ""; | ||
const schemaOutput = this.getSchemaPartText(error.schema, false, false, false); | ||
@@ -1080,3 +1077,2 @@ if (canApplyNot(error.schema)) { | ||
} | ||
var _default = ValidationError; | ||
exports.default = _default; | ||
var _default = exports.default = ValidationError; |
{ | ||
"name": "schema-utils", | ||
"version": "4.2.0", | ||
"version": "4.3.0", | ||
"description": "webpack Validation Utils", | ||
@@ -17,3 +17,3 @@ "license": "MIT", | ||
"engines": { | ||
"node": ">= 12.13.0" | ||
"node": ">= 10.13.0" | ||
}, | ||
@@ -75,3 +75,3 @@ "scripts": { | ||
"typescript": "^4.9.5", | ||
"webpack": "^5.68.0" | ||
"webpack": "^5.97.1" | ||
}, | ||
@@ -78,0 +78,0 @@ "keywords": [ |
76517
21
1984