diff options
Diffstat (limited to 'node_modules/ajv/lib')
30 files changed, 322 insertions, 838 deletions
diff --git a/node_modules/ajv/lib/$data.js b/node_modules/ajv/lib/$data.js deleted file mode 100644 index 60cfc2d8d..000000000 --- a/node_modules/ajv/lib/$data.js +++ /dev/null @@ -1,49 +0,0 @@ -'use strict'; - -var KEYWORDS = [ - 'multipleOf', - 'maximum', - 'exclusiveMaximum', - 'minimum', - 'exclusiveMinimum', - 'maxLength', - 'minLength', - 'pattern', - 'additionalItems', - 'maxItems', - 'minItems', - 'uniqueItems', - 'maxProperties', - 'minProperties', - 'required', - 'additionalProperties', - 'enum', - 'format', - 'const' -]; - -module.exports = function (metaSchema, keywordsJsonPointers) { - for (var i=0; i<keywordsJsonPointers.length; i++) { - metaSchema = JSON.parse(JSON.stringify(metaSchema)); - var segments = keywordsJsonPointers[i].split('/'); - var keywords = metaSchema; - var j; - for (j=1; j<segments.length; j++) - keywords = keywords[segments[j]]; - - for (j=0; j<KEYWORDS.length; j++) { - var key = KEYWORDS[j]; - var schema = keywords[key]; - if (schema) { - keywords[key] = { - anyOf: [ - schema, - { $ref: 'https://raw.githubusercontent.com/epoberezkin/ajv/master/lib/refs/$data.json#' } - ] - }; - } - } - } - - return metaSchema; -}; diff --git a/node_modules/ajv/lib/ajv.d.ts b/node_modules/ajv/lib/ajv.d.ts index b687f7814..a6510c0ea 100644 --- a/node_modules/ajv/lib/ajv.d.ts +++ b/node_modules/ajv/lib/ajv.d.ts @@ -1,9 +1,9 @@ -declare var ajv: { +declare var ajv: { (options?: ajv.Options): ajv.Ajv; new (options?: ajv.Options): ajv.Ajv; ValidationError: ValidationError; MissingRefError: MissingRefError; - $dataMetaSchema: Object; + $dataMetaSchema: object; } declare namespace ajv { @@ -11,51 +11,51 @@ declare namespace ajv { /** * Validate data using schema * Schema will be compiled and cached (using serialized JSON as key, [fast-json-stable-stringify](https://github.com/epoberezkin/fast-json-stable-stringify) is used to serialize by default). - * @param {String|Object|Boolean} schemaKeyRef key, ref or schema object + * @param {string|object|Boolean} schemaKeyRef key, ref or schema object * @param {Any} data to be validated * @return {Boolean} validation result. Errors from the last validation will be available in `ajv.errors` (and also in compiled schema: `schema.errors`). */ - validate(schemaKeyRef: Object | string | boolean, data: any): boolean | Thenable<any>; + validate(schemaKeyRef: object | string | boolean, data: any): boolean | PromiseLike<any>; /** * Create validating function for passed schema. - * @param {Object|Boolean} schema schema object + * @param {object|Boolean} schema schema object * @return {Function} validating function */ - compile(schema: Object | boolean): ValidateFunction; + compile(schema: object | boolean): ValidateFunction; /** * Creates validating function for passed schema with asynchronous loading of missing schemas. * `loadSchema` option should be a function that accepts schema uri and node-style callback. * @this Ajv - * @param {Object|Boolean} schema schema object + * @param {object|Boolean} schema schema object * @param {Boolean} meta optional true to compile meta-schema; this parameter can be skipped * @param {Function} callback optional node-style callback, it is always called with 2 parameters: error (or null) and validating function. - * @return {Thenable<ValidateFunction>} validating function + * @return {PromiseLike<ValidateFunction>} validating function */ - compileAsync(schema: Object | boolean, meta?: Boolean, callback?: (err: Error, validate: ValidateFunction) => any): Thenable<ValidateFunction>; + compileAsync(schema: object | boolean, meta?: Boolean, callback?: (err: Error, validate: ValidateFunction) => any): PromiseLike<ValidateFunction>; /** * Adds schema to the instance. - * @param {Object|Array} schema schema or array of schemas. If array is passed, `key` and other parameters will be ignored. - * @param {String} key Optional schema key. Can be passed to `validate` method instead of schema object or id/ref. One schema per instance can have empty `id` and `key`. + * @param {object|Array} schema schema or array of schemas. If array is passed, `key` and other parameters will be ignored. + * @param {string} key Optional schema key. Can be passed to `validate` method instead of schema object or id/ref. One schema per instance can have empty `id` and `key`. * @return {Ajv} this for method chaining */ - addSchema(schema: Array<Object> | Object, key?: string): Ajv; + addSchema(schema: Array<object> | object, key?: string): Ajv; /** * Add schema that will be used to validate other schemas * options in META_IGNORE_OPTIONS are alway set to false - * @param {Object} schema schema object - * @param {String} key optional schema key + * @param {object} schema schema object + * @param {string} key optional schema key * @return {Ajv} this for method chaining */ - addMetaSchema(schema: Object, key?: string): Ajv; + addMetaSchema(schema: object, key?: string): Ajv; /** * Validate schema - * @param {Object|Boolean} schema schema to validate + * @param {object|Boolean} schema schema to validate * @return {Boolean} true if schema is valid */ - validateSchema(schema: Object | boolean): boolean; + validateSchema(schema: object | boolean): boolean; /** * Get compiled schema from the instance by `key` or `ref`. - * @param {String} keyRef `key` that was passed to `addSchema` or full schema reference (`schema.id` or resolved id). + * @param {string} keyRef `key` that was passed to `addSchema` or full schema reference (`schema.id` or resolved id). * @return {Function} schema validating function (with property `schema`). */ getSchema(keyRef: string): ValidateFunction; @@ -64,68 +64,64 @@ declare namespace ajv { * If no parameter is passed all schemas but meta-schemas are removed. * If RegExp is passed all schemas with key/id matching pattern but meta-schemas are removed. * Even if schema is referenced by other schemas it still can be removed as other schemas have local references. - * @param {String|Object|RegExp|Boolean} schemaKeyRef key, ref, pattern to match key/ref or schema object + * @param {string|object|RegExp|Boolean} schemaKeyRef key, ref, pattern to match key/ref or schema object * @return {Ajv} this for method chaining */ - removeSchema(schemaKeyRef?: Object | string | RegExp | boolean): Ajv; + removeSchema(schemaKeyRef?: object | string | RegExp | boolean): Ajv; /** * Add custom format - * @param {String} name format name - * @param {String|RegExp|Function} format string is converted to RegExp; function should return boolean (true when valid) + * @param {string} name format name + * @param {string|RegExp|Function} format string is converted to RegExp; function should return boolean (true when valid) * @return {Ajv} this for method chaining */ addFormat(name: string, format: FormatValidator | FormatDefinition): Ajv; /** * Define custom keyword * @this Ajv - * @param {String} keyword custom keyword, should be a valid identifier, should be different from all standard, custom and macro keywords. - * @param {Object} definition keyword definition object with properties `type` (type(s) which the keyword applies to), `validate` or `compile`. + * @param {string} keyword custom keyword, should be a valid identifier, should be different from all standard, custom and macro keywords. + * @param {object} definition keyword definition object with properties `type` (type(s) which the keyword applies to), `validate` or `compile`. * @return {Ajv} this for method chaining */ addKeyword(keyword: string, definition: KeywordDefinition): Ajv; /** * Get keyword definition * @this Ajv - * @param {String} keyword pre-defined or custom keyword. - * @return {Object|Boolean} custom keyword definition, `true` if it is a predefined keyword, `false` otherwise. + * @param {string} keyword pre-defined or custom keyword. + * @return {object|Boolean} custom keyword definition, `true` if it is a predefined keyword, `false` otherwise. */ - getKeyword(keyword: string): Object | boolean; + getKeyword(keyword: string): object | boolean; /** * Remove keyword * @this Ajv - * @param {String} keyword pre-defined or custom keyword. + * @param {string} keyword pre-defined or custom keyword. * @return {Ajv} this for method chaining */ removeKeyword(keyword: string): Ajv; /** * Convert array of error message objects to string - * @param {Array<Object>} errors optional array of validation errors, if not passed errors from the instance are used. - * @param {Object} options optional options with properties `separator` and `dataVar`. - * @return {String} human readable string with all errors descriptions + * @param {Array<object>} errors optional array of validation errors, if not passed errors from the instance are used. + * @param {object} options optional options with properties `separator` and `dataVar`. + * @return {string} human readable string with all errors descriptions */ - errorsText(errors?: Array<ErrorObject>, options?: ErrorsTextOptions): string; + errorsText(errors?: Array<ErrorObject> | null, options?: ErrorsTextOptions): string; errors?: Array<ErrorObject>; } - interface Thenable <R> { - then <U> (onFulfilled?: (value: R) => U | Thenable<U>, onRejected?: (error: any) => U | Thenable<U>): Thenable<U>; - } - interface ValidateFunction { ( data: any, dataPath?: string, - parentData?: Object | Array<any>, + parentData?: object | Array<any>, parentDataProperty?: string | number, - rootData?: Object | Array<any> - ): boolean | Thenable<any>; - schema?: Object | boolean; + rootData?: object | Array<any> + ): boolean | PromiseLike<any>; + schema?: object | boolean; errors?: null | Array<ErrorObject>; - refs?: Object; + refs?: object; refVal?: Array<any>; - root?: ValidateFunction | Object; + root?: ValidateFunction | object; $async?: true; - source?: Object; + source?: object; } interface Options { @@ -136,19 +132,19 @@ declare namespace ajv { uniqueItems?: boolean; unicode?: boolean; format?: string; - formats?: Object; + formats?: object; unknownFormats?: true | string[] | 'ignore'; - schemas?: Array<Object> | Object; - schemaId?: '$id' | 'id'; + schemas?: Array<object> | object; + schemaId?: '$id' | 'id' | 'auto'; missingRefs?: true | 'ignore' | 'fail'; extendRefs?: true | 'ignore' | 'fail'; - loadSchema?: (uri: string, cb?: (err: Error, schema: Object) => void) => Thenable<Object | boolean>; + loadSchema?: (uri: string, cb?: (err: Error, schema: object) => void) => PromiseLike<object | boolean>; removeAdditional?: boolean | 'all' | 'failing'; useDefaults?: boolean | 'shared'; coerceTypes?: boolean | 'array'; async?: boolean | string; transpile?: string | ((code: string) => string); - meta?: boolean | Object; + meta?: boolean | object; validateSchema?: boolean | 'log'; addUsedSchema?: boolean; inlineRefs?: boolean | number; @@ -160,44 +156,85 @@ declare namespace ajv { messages?: boolean; sourceCode?: boolean; processCode?: (code: string) => string; - cache?: Object; + cache?: object; } - type FormatValidator = string | RegExp | ((data: string) => boolean | Thenable<any>); + type FormatValidator = string | RegExp | ((data: string) => boolean | PromiseLike<any>); + type NumberFormatValidator = ((data: number) => boolean | PromiseLike<any>); + + interface NumberFormatDefinition { + type: "number", + validate: NumberFormatValidator; + compare?: (data1: number, data2: number) => number; + async?: boolean; + } - interface FormatDefinition { + interface StringFormatDefinition { + type?: "string", validate: FormatValidator; - compare: (data1: string, data2: string) => number; + compare?: (data1: string, data2: string) => number; async?: boolean; } + type FormatDefinition = NumberFormatDefinition | StringFormatDefinition; + interface KeywordDefinition { type?: string | Array<string>; async?: boolean; $data?: boolean; errors?: boolean | string; - metaSchema?: Object; + metaSchema?: object; // schema: false makes validate not to expect schema (ValidateFunction) schema?: boolean; modifying?: boolean; valid?: boolean; // one and only one of the following properties should be present validate?: SchemaValidateFunction | ValidateFunction; - compile?: (schema: any, parentSchema: Object) => ValidateFunction; - macro?: (schema: any, parentSchema: Object) => Object | boolean; - inline?: (it: Object, keyword: string, schema: any, parentSchema: Object) => string; + compile?: (schema: any, parentSchema: object, it: CompilationContext) => ValidateFunction; + macro?: (schema: any, parentSchema: object, it: CompilationContext) => object | boolean; + inline?: (it: CompilationContext, keyword: string, schema: any, parentSchema: object) => string; + } + + interface CompilationContext { + level: number; + dataLevel: number; + schema: any; + schemaPath: string; + baseId: string; + async: boolean; + opts: Options; + formats: { + [index: string]: FormatDefinition | undefined; + }; + compositeRule: boolean; + validate: (schema: object) => boolean; + util: { + copy(obj: any, target?: any): any; + toHash(source: string[]): { [index: string]: true | undefined }; + equal(obj: any, target: any): boolean; + getProperty(str: string): string; + schemaHasRules(schema: object, rules: any): string; + escapeQuotes(str: string): string; + toQuotedString(str: string): string; + getData(jsonPointer: string, dataLevel: number, paths: string[]): string; + escapeJsonPointer(str: string): string; + unescapeJsonPointer(str: string): string; + escapeFragment(str: string): string; + unescapeFragment(str: string): string; + }; + self: Ajv; } interface SchemaValidateFunction { ( schema: any, data: any, - parentSchema?: Object, + parentSchema?: object, dataPath?: string, - parentData?: Object | Array<any>, + parentData?: object | Array<any>, parentDataProperty?: string | number, - rootData?: Object | Array<any> - ): boolean | Thenable<any>; + rootData?: object | Array<any> + ): boolean | PromiseLike<any>; errors?: Array<ErrorObject>; } @@ -217,7 +254,7 @@ declare namespace ajv { message?: string; // These are added with the `verbose` option. schema?: any; - parentSchema?: Object; + parentSchema?: object; data?: any; } @@ -225,8 +262,8 @@ declare namespace ajv { DependenciesParams | FormatParams | ComparisonParams | MultipleOfParams | PatternParams | RequiredParams | TypeParams | UniqueItemsParams | CustomParams | - PatternGroupsParams | PatternRequiredParams | - PropertyNamesParams | SwitchParams | NoParams | EnumParams; + PatternRequiredParams | PropertyNamesParams | + IfParams | SwitchParams | NoParams | EnumParams; interface RefParams { ref: string; @@ -282,12 +319,6 @@ declare namespace ajv { keyword: string; } - interface PatternGroupsParams { - reason: string; - limit: number; - pattern: string; - } - interface PatternRequiredParams { missingPattern: string; } @@ -296,6 +327,10 @@ declare namespace ajv { propertyName: string; } + interface IfParams { + failingKeyword: string; + } + interface SwitchParams { caseIndex: number; } diff --git a/node_modules/ajv/lib/ajv.js b/node_modules/ajv/lib/ajv.js index 3148b8e37..4740eb6a7 100644 --- a/node_modules/ajv/lib/ajv.js +++ b/node_modules/ajv/lib/ajv.js @@ -7,10 +7,8 @@ var compileSchema = require('./compile') , stableStringify = require('fast-json-stable-stringify') , formats = require('./compile/formats') , rules = require('./compile/rules') - , $dataMetaSchema = require('./$data') - , patternGroups = require('./patternGroups') - , util = require('./compile/util') - , co = require('co'); + , $dataMetaSchema = require('./data') + , util = require('./compile/util'); module.exports = Ajv; @@ -38,7 +36,7 @@ Ajv.ValidationError = errorClasses.Validation; Ajv.MissingRefError = errorClasses.MissingRef; Ajv.$dataMetaSchema = $dataMetaSchema; -var META_SCHEMA_ID = 'http://json-schema.org/draft-06/schema'; +var META_SCHEMA_ID = 'http://json-schema.org/draft-07/schema'; var META_IGNORE_OPTIONS = [ 'removeAdditional', 'useDefaults', 'coerceTypes' ]; var META_SUPPORT_DATA = ['/properties']; @@ -75,7 +73,6 @@ function Ajv(opts) { addDraft6MetaSchema(this); if (typeof opts.meta == 'object') this.addMetaSchema(opts.meta); addInitialSchemas(this); - if (opts.patternGroups) patternGroups(this); } @@ -99,9 +96,7 @@ function validate(schemaKeyRef, data) { } var valid = v(data); - if (v.$async === true) - return this._opts.async == '*' ? co(valid) : valid; - this.errors = v.errors; + if (v.$async !== true) this.errors = v.errors; return valid; } @@ -356,6 +351,10 @@ function _compile(schemaObj, root) { var v; try { v = compileSchema.call(this, schemaObj.schema, root, schemaObj.localRefs); } + catch(e) { + delete schemaObj.validate; + throw e; + } finally { schemaObj.compiling = false; if (schemaObj.meta) this._opts = currentOpts; @@ -368,9 +367,11 @@ function _compile(schemaObj, root) { return v; + /* @this {*} - custom context, see passContext option */ function callValidate() { + /* jshint validthis: true */ var _validate = schemaObj.validate; - var result = _validate.apply(null, arguments); + var result = _validate.apply(this, arguments); callValidate.errors = _validate.errors; return result; } @@ -379,9 +380,9 @@ function _compile(schemaObj, root) { function chooseGetId(opts) { switch (opts.schemaId) { - case '$id': return _get$Id; + case 'auto': return _get$IdOrId; case 'id': return _getId; - default: return _get$IdOrId; + default: return _get$Id; } } @@ -445,11 +446,11 @@ function addFormat(name, format) { function addDraft6MetaSchema(self) { var $dataSchema; if (self._opts.$data) { - $dataSchema = require('./refs/$data.json'); + $dataSchema = require('./refs/data.json'); self.addMetaSchema($dataSchema, $dataSchema.$id, true); } if (self._opts.meta === false) return; - var metaSchema = require('./refs/json-schema-draft-06.json'); + var metaSchema = require('./refs/json-schema-draft-07.json'); if (self._opts.$data) metaSchema = $dataMetaSchema(metaSchema, META_SUPPORT_DATA); self.addMetaSchema(metaSchema, META_SCHEMA_ID, true); self._refs['http://json-schema.org/schema'] = META_SCHEMA_ID; diff --git a/node_modules/ajv/lib/compile/_rules.js b/node_modules/ajv/lib/compile/_rules.js deleted file mode 100644 index 3fe69973a..000000000 --- a/node_modules/ajv/lib/compile/_rules.js +++ /dev/null @@ -1,31 +0,0 @@ -'use strict'; - -//all requires must be explicit because browserify won't work with dynamic requires -module.exports = { - '$ref': require('../dotjs/ref'), - allOf: require('../dotjs/allOf'), - anyOf: require('../dotjs/anyOf'), - const: require('../dotjs/const'), - contains: require('../dotjs/contains'), - dependencies: require('../dotjs/dependencies'), - 'enum': require('../dotjs/enum'), - format: require('../dotjs/format'), - items: require('../dotjs/items'), - maximum: require('../dotjs/_limit'), - minimum: require('../dotjs/_limit'), - maxItems: require('../dotjs/_limitItems'), - minItems: require('../dotjs/_limitItems'), - maxLength: require('../dotjs/_limitLength'), - minLength: require('../dotjs/_limitLength'), - maxProperties: require('../dotjs/_limitProperties'), - minProperties: require('../dotjs/_limitProperties'), - multipleOf: require('../dotjs/multipleOf'), - not: require('../dotjs/not'), - oneOf: require('../dotjs/oneOf'), - pattern: require('../dotjs/pattern'), - properties: require('../dotjs/properties'), - propertyNames: require('../dotjs/propertyNames'), - required: require('../dotjs/required'), - uniqueItems: require('../dotjs/uniqueItems'), - validate: require('../dotjs/validate') -}; diff --git a/node_modules/ajv/lib/compile/formats.js b/node_modules/ajv/lib/compile/formats.js index b3a1541a6..97aca1a15 100644 --- a/node_modules/ajv/lib/compile/formats.js +++ b/node_modules/ajv/lib/compile/formats.js @@ -2,8 +2,8 @@ var util = require('./util'); -var DATE = /^\d\d\d\d-(\d\d)-(\d\d)$/; -var DAYS = [0,31,29,31,30,31,30,31,31,30,31,30,31]; +var DATE = /^(\d\d\d\d)-(\d\d)-(\d\d)$/; +var DAYS = [0,31,28,31,30,31,30,31,31,30,31,30,31]; var TIME = /^(\d\d):(\d\d):(\d\d)(\.\d+)?(z|[+-]\d\d:\d\d)?$/i; var HOSTNAME = /^[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?(?:\.[a-z0-9](?:[-0-9a-z]{0,61}[0-9a-z])?)*$/i; var URI = /^(?:[a-z][a-z0-9+\-.]*:)(?:\/?\/(?:(?:[a-z0-9\-._~!$&'()*+,;=:]|%[0-9a-f]{2})*@)?(?:\[(?:(?:(?:(?:[0-9a-f]{1,4}:){6}|::(?:[0-9a-f]{1,4}:){5}|(?:[0-9a-f]{1,4})?::(?:[0-9a-f]{1,4}:){4}|(?:(?:[0-9a-f]{1,4}:){0,1}[0-9a-f]{1,4})?::(?:[0-9a-f]{1,4}:){3}|(?:(?:[0-9a-f]{1,4}:){0,2}[0-9a-f]{1,4})?::(?:[0-9a-f]{1,4}:){2}|(?:(?:[0-9a-f]{1,4}:){0,3}[0-9a-f]{1,4})?::[0-9a-f]{1,4}:|(?:(?:[0-9a-f]{1,4}:){0,4}[0-9a-f]{1,4})?::)(?:[0-9a-f]{1,4}:[0-9a-f]{1,4}|(?:(?:25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(?:25[0-5]|2[0-4]\d|[01]?\d\d?))|(?:(?:[0-9a-f]{1,4}:){0,5}[0-9a-f]{1,4})?::[0-9a-f]{1,4}|(?:(?:[0-9a-f]{1,4}:){0,6}[0-9a-f]{1,4})?::)|[Vv][0-9a-f]+\.[a-z0-9\-._~!$&'()*+,;=:]+)\]|(?:(?:25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(?:25[0-5]|2[0-4]\d|[01]?\d\d?)|(?:[a-z0-9\-._~!$&'()*+,;=]|%[0-9a-f]{2})*)(?::\d*)?(?:\/(?:[a-z0-9\-._~!$&'()*+,;=:@]|%[0-9a-f]{2})*)*|\/(?:(?:[a-z0-9\-._~!$&'()*+,;=:@]|%[0-9a-f]{2})+(?:\/(?:[a-z0-9\-._~!$&'()*+,;=:@]|%[0-9a-f]{2})*)*)?|(?:[a-z0-9\-._~!$&'()*+,;=:@]|%[0-9a-f]{2})+(?:\/(?:[a-z0-9\-._~!$&'()*+,;=:@]|%[0-9a-f]{2})*)*)(?:\?(?:[a-z0-9\-._~!$&'()*+,;=:@/?]|%[0-9a-f]{2})*)?(?:#(?:[a-z0-9\-._~!$&'()*+,;=:@/?]|%[0-9a-f]{2})*)?$/i; @@ -16,7 +16,8 @@ var URITEMPLATE = /^(?:(?:[^\x00-\x20"'<>%\\^`{|}]|%[0-9a-f]{2})|\{[+#./;?&=,!@| // var URL = /^(?:(?:https?|ftp):\/\/)(?:\S+(?::\S*)?@)?(?:(?!10(?:\.\d{1,3}){3})(?!127(?:\.\d{1,3}){3})(?!169\.254(?:\.\d{1,3}){2})(?!192\.168(?:\.\d{1,3}){2})(?!172\.(?:1[6-9]|2\d|3[0-1])(?:\.\d{1,3}){2})(?:[1-9]\d?|1\d\d|2[01]\d|22[0-3])(?:\.(?:1?\d{1,2}|2[0-4]\d|25[0-5])){2}(?:\.(?:[1-9]\d?|1\d\d|2[0-4]\d|25[0-4]))|(?:(?:[a-z\u{00a1}-\u{ffff}0-9]+-?)*[a-z\u{00a1}-\u{ffff}0-9]+)(?:\.(?:[a-z\u{00a1}-\u{ffff}0-9]+-?)*[a-z\u{00a1}-\u{ffff}0-9]+)*(?:\.(?:[a-z\u{00a1}-\u{ffff}]{2,})))(?::\d{2,5})?(?:\/[^\s]*)?$/iu; var URL = /^(?:(?:http[s\u017F]?|ftp):\/\/)(?:(?:[\0-\x08\x0E-\x1F!-\x9F\xA1-\u167F\u1681-\u1FFF\u200B-\u2027\u202A-\u202E\u2030-\u205E\u2060-\u2FFF\u3001-\uD7FF\uE000-\uFEFE\uFF00-\uFFFF]|[\uD800-\uDBFF][\uDC00-\uDFFF]|[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?:[^\uD800-\uDBFF]|^)[\uDC00-\uDFFF])+(?::(?:[\0-\x08\x0E-\x1F!-\x9F\xA1-\u167F\u1681-\u1FFF\u200B-\u2027\u202A-\u202E\u2030-\u205E\u2060-\u2FFF\u3001-\uD7FF\uE000-\uFEFE\uFF00-\uFFFF]|[\uD800-\uDBFF][\uDC00-\uDFFF]|[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?:[^\uD800-\uDBFF]|^)[\uDC00-\uDFFF])*)?@)?(?:(?!10(?:\.[0-9]{1,3}){3})(?!127(?:\.[0-9]{1,3}){3})(?!169\.254(?:\.[0-9]{1,3}){2})(?!192\.168(?:\.[0-9]{1,3}){2})(?!172\.(?:1[6-9]|2[0-9]|3[01])(?:\.[0-9]{1,3}){2})(?:[1-9][0-9]?|1[0-9][0-9]|2[01][0-9]|22[0-3])(?:\.(?:1?[0-9]{1,2}|2[0-4][0-9]|25[0-5])){2}(?:\.(?:[1-9][0-9]?|1[0-9][0-9]|2[0-4][0-9]|25[0-4]))|(?:(?:(?:[0-9KSa-z\xA1-\uD7FF\uE000-\uFFFF]|[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?:[^\uD800-\uDBFF]|^)[\uDC00-\uDFFF])+-?)*(?:[0-9KSa-z\xA1-\uD7FF\uE000-\uFFFF]|[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?:[^\uD800-\uDBFF]|^)[\uDC00-\uDFFF])+)(?:\.(?:(?:[0-9KSa-z\xA1-\uD7FF\uE000-\uFFFF]|[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?:[^\uD800-\uDBFF]|^)[\uDC00-\uDFFF])+-?)*(?:[0-9KSa-z\xA1-\uD7FF\uE000-\uFFFF]|[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?:[^\uD800-\uDBFF]|^)[\uDC00-\uDFFF])+)*(?:\.(?:(?:[KSa-z\xA1-\uD7FF\uE000-\uFFFF]|[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?:[^\uD800-\uDBFF]|^)[\uDC00-\uDFFF]){2,})))(?::[0-9]{2,5})?(?:\/(?:[\0-\x08\x0E-\x1F!-\x9F\xA1-\u167F\u1681-\u1FFF\u200B-\u2027\u202A-\u202E\u2030-\u205E\u2060-\u2FFF\u3001-\uD7FF\uE000-\uFEFE\uFF00-\uFFFF]|[\uD800-\uDBFF][\uDC00-\uDFFF]|[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?:[^\uD800-\uDBFF]|^)[\uDC00-\uDFFF])*)?$/i; var UUID = /^(?:urn:uuid:)?[0-9a-f]{8}-(?:[0-9a-f]{4}-){3}[0-9a-f]{12}$/i; -var JSON_POINTER = /^(?:\/(?:[^~/]|~0|~1)*)*$|^#(?:\/(?:[a-z0-9_\-.!$&'()*+,;:=@]|%[0-9a-f]{2}|~0|~1)*)*$/i; +var JSON_POINTER = /^(?:\/(?:[^~/]|~0|~1)*)*$/; +var JSON_POINTER_URI_FRAGMENT = /^#(?:\/(?:[a-z0-9_\-.!$&'()*+,;:=@]|%[0-9a-f]{2}|~0|~1)*)*$/i; var RELATIVE_JSON_POINTER = /^(?:0|[1-9][0-9]*)(?:#|(?:\/(?:[^~/]|~0|~1)*)*)$/; @@ -32,11 +33,11 @@ formats.fast = { // date: http://tools.ietf.org/html/rfc3339#section-5.6 date: /^\d\d\d\d-[0-1]\d-[0-3]\d$/, // date-time: http://tools.ietf.org/html/rfc3339#section-5.6 - time: /^[0-2]\d:[0-5]\d:[0-5]\d(?:\.\d+)?(?:z|[+-]\d\d:\d\d)?$/i, - 'date-time': /^\d\d\d\d-[0-1]\d-[0-3]\d[t\s][0-2]\d:[0-5]\d:[0-5]\d(?:\.\d+)?(?:z|[+-]\d\d:\d\d)$/i, + time: /^(?:[0-2]\d:[0-5]\d:[0-5]\d|23:59:60)(?:\.\d+)?(?:z|[+-]\d\d:\d\d)?$/i, + 'date-time': /^\d\d\d\d-[0-1]\d-[0-3]\d[t\s](?:[0-2]\d:[0-5]\d:[0-5]\d|23:59:60)(?:\.\d+)?(?:z|[+-]\d\d:\d\d)$/i, // uri: https://github.com/mafintosh/is-my-json-valid/blob/master/formats.js - uri: /^(?:[a-z][a-z0-9+-.]*)(?::|\/)\/?[^\s]*$/i, - 'uri-reference': /^(?:(?:[a-z][a-z0-9+-.]*:)?\/\/)?[^\s]*$/i, + uri: /^(?:[a-z][a-z0-9+-.]*:)(?:\/?\/)?[^\s]*$/i, + 'uri-reference': /^(?:(?:[a-z][a-z0-9+-.]*:)?\/?\/)?(?:[^\\\s#][^\s#]*)?(?:#[^\\\s]*)?$/i, 'uri-template': URITEMPLATE, url: URL, // email (sources from jsen validator): @@ -54,6 +55,7 @@ formats.fast = { // JSON-pointer: https://tools.ietf.org/html/rfc6901 // uri fragment: https://tools.ietf.org/html/rfc3986#appendix-A 'json-pointer': JSON_POINTER, + 'json-pointer-uri-fragment': JSON_POINTER_URI_FRAGMENT, // relative JSON-pointer: http://tools.ietf.org/html/draft-luff-relative-json-pointer-00 'relative-json-pointer': RELATIVE_JSON_POINTER }; @@ -74,18 +76,28 @@ formats.full = { regex: regex, uuid: UUID, 'json-pointer': JSON_POINTER, + 'json-pointer-uri-fragment': JSON_POINTER_URI_FRAGMENT, 'relative-json-pointer': RELATIVE_JSON_POINTER }; +function isLeapYear(year) { + // https://tools.ietf.org/html/rfc3339#appendix-C + return year % 4 === 0 && (year % 100 !== 0 || year % 400 === 0); +} + + function date(str) { // full-date from http://tools.ietf.org/html/rfc3339#section-5.6 var matches = str.match(DATE); if (!matches) return false; - var month = +matches[1]; - var day = +matches[2]; - return month >= 1 && month <= 12 && day >= 1 && day <= DAYS[month]; + var year = +matches[1]; + var month = +matches[2]; + var day = +matches[3]; + + return month >= 1 && month <= 12 && day >= 1 && + day <= (month == 2 && isLeapYear(year) ? 29 : DAYS[month]); } @@ -97,7 +109,9 @@ function time(str, full) { var minute = matches[2]; var second = matches[3]; var timeZone = matches[5]; - return hour <= 23 && minute <= 59 && second <= 59 && (!full || timeZone); + return ((hour <= 23 && minute <= 59 && second <= 59) || + (hour == 23 && minute == 59 && second == 60)) && + (!full || timeZone); } diff --git a/node_modules/ajv/lib/compile/index.js b/node_modules/ajv/lib/compile/index.js index cf4f5b86b..8e369db3d 100644 --- a/node_modules/ajv/lib/compile/index.js +++ b/node_modules/ajv/lib/compile/index.js @@ -11,7 +11,6 @@ var validateGenerator = require('../dotjs/validate'); * Functions below are used inside compiled validations function */ -var co = require('co'); var ucs2length = util.ucs2length; var equal = require('fast-deep-equal'); @@ -70,9 +69,11 @@ function compile(schema, root, localRefs, baseId) { endCompiling.call(this, schema, root, baseId); } + /* @this {*} - custom context, see passContext option */ function callValidate() { + /* jshint validthis: true */ var validate = compilation.validate; - var result = validate.apply(null, arguments); + var result = validate.apply(this, arguments); callValidate.errors = validate.errors; return result; } @@ -124,7 +125,6 @@ function compile(schema, root, localRefs, baseId) { 'refVal', 'defaults', 'customRules', - 'co', 'equal', 'ucs2length', 'ValidationError', @@ -139,7 +139,6 @@ function compile(schema, root, localRefs, baseId) { refVal, defaults, customRules, - co, equal, ucs2length, ValidationError @@ -224,7 +223,7 @@ function compile(schema, root, localRefs, baseId) { function resolvedRef(refVal, code) { return typeof refVal == 'object' || typeof refVal == 'boolean' ? { code: code, schema: refVal, inline: true } - : { code: code, $async: refVal && refVal.$async }; + : { code: code, $async: refVal && !!refVal.$async }; } function usePattern(regexStr) { diff --git a/node_modules/ajv/lib/compile/resolve.js b/node_modules/ajv/lib/compile/resolve.js index 7d06afab8..66f2aee9b 100644 --- a/node_modules/ajv/lib/compile/resolve.js +++ b/node_modules/ajv/lib/compile/resolve.js @@ -1,6 +1,6 @@ 'use strict'; -var url = require('url') +var URI = require('uri-js') , equal = require('fast-deep-equal') , util = require('./util') , SchemaObject = require('./schema_obj') @@ -67,10 +67,10 @@ function resolve(compile, root, ref) { */ function resolveSchema(root, ref) { /* jshint validthis: true */ - var p = url.parse(ref, false, true) + var p = URI.parse(ref) , refPath = _getFullPath(p) , baseId = getFullPath(this._getId(root.schema)); - if (refPath !== baseId) { + if (Object.keys(root.schema).length === 0 || refPath !== baseId) { var id = normalizeId(refPath); var refVal = this._refs[id]; if (typeof refVal == 'string') { @@ -115,9 +115,9 @@ var PREVENT_SCOPE_CHANGE = util.toHash(['properties', 'patternProperties', 'enum /* @this Ajv */ function getJsonPointer(parsedRef, baseId, schema, root) { /* jshint validthis: true */ - parsedRef.hash = parsedRef.hash || ''; - if (parsedRef.hash.slice(0,2) != '#/') return; - var parts = parsedRef.hash.split('/'); + parsedRef.fragment = parsedRef.fragment || ''; + if (parsedRef.fragment.slice(0,1) != '/') return; + var parts = parsedRef.fragment.split('/'); for (var i = 1; i < parts.length; i++) { var part = parts[i]; @@ -206,14 +206,13 @@ function countKeys(schema) { function getFullPath(id, normalize) { if (normalize !== false) id = normalizeId(id); - var p = url.parse(id, false, true); + var p = URI.parse(id); return _getFullPath(p); } function _getFullPath(p) { - var protocolSeparator = p.protocol || p.href.slice(0,2) == '//' ? '//' : ''; - return (p.protocol||'') + protocolSeparator + (p.host||'') + (p.path||'') + '#'; + return URI.serialize(p).split('#')[0] + '#'; } @@ -225,7 +224,7 @@ function normalizeId(id) { function resolveUrl(baseId, id) { id = normalizeId(id); - return url.resolve(baseId, id); + return URI.resolve(baseId, id); } @@ -246,7 +245,7 @@ function resolveIds(schema) { fullPath += '/' + (typeof keyIndex == 'number' ? keyIndex : util.escapeFragment(keyIndex)); if (typeof id == 'string') { - id = baseId = normalizeId(baseId ? url.resolve(baseId, id) : id); + id = baseId = normalizeId(baseId ? URI.resolve(baseId, id) : id); var refVal = self._refs[id]; if (typeof refVal == 'string') refVal = self._refs[refVal]; diff --git a/node_modules/ajv/lib/compile/rules.js b/node_modules/ajv/lib/compile/rules.js index 44830ad72..66f196a93 100644 --- a/node_modules/ajv/lib/compile/rules.js +++ b/node_modules/ajv/lib/compile/rules.js @@ -1,6 +1,6 @@ 'use strict'; -var ruleModules = require('./_rules') +var ruleModules = require('../dotjs') , toHash = require('./util').toHash; module.exports = function rules() { @@ -11,17 +11,20 @@ module.exports = function rules() { { type: 'string', rules: [ 'maxLength', 'minLength', 'pattern', 'format' ] }, { type: 'array', - rules: [ 'maxItems', 'minItems', 'uniqueItems', 'contains', 'items' ] }, + rules: [ 'maxItems', 'minItems', 'items', 'contains', 'uniqueItems' ] }, { type: 'object', rules: [ 'maxProperties', 'minProperties', 'required', 'dependencies', 'propertyNames', { 'properties': ['additionalProperties', 'patternProperties'] } ] }, - { rules: [ '$ref', 'const', 'enum', 'not', 'anyOf', 'oneOf', 'allOf' ] } + { rules: [ '$ref', 'const', 'enum', 'not', 'anyOf', 'oneOf', 'allOf', 'if' ] } ]; - var ALL = [ 'type' ]; + var ALL = [ 'type', '$comment' ]; var KEYWORDS = [ - 'additionalItems', '$schema', '$id', 'id', 'title', - 'description', 'default', 'definitions' + '$schema', '$id', 'id', '$data', 'title', + 'description', 'default', 'definitions', + 'examples', 'readOnly', 'writeOnly', + 'contentMediaType', 'contentEncoding', + 'additionalItems', 'then', 'else' ]; var TYPES = [ 'number', 'integer', 'string', 'array', 'object', 'boolean', 'null' ]; RULES.all = toHash(ALL); @@ -48,6 +51,11 @@ module.exports = function rules() { return rule; }); + RULES.all.$comment = { + keyword: '$comment', + code: ruleModules.$comment + }; + if (group.type) RULES.types[group.type] = group; }); diff --git a/node_modules/ajv/lib/dot/_limit.jst b/node_modules/ajv/lib/dot/_limit.jst index 13e7649b3..e10806fd3 100644 --- a/node_modules/ajv/lib/dot/_limit.jst +++ b/node_modules/ajv/lib/dot/_limit.jst @@ -50,6 +50,14 @@ ) || {{=$data}} !== {{=$data}}) { var op{{=$lvl}} = {{=$exclusive}} ? '{{=$op}}' : '{{=$op}}='; + {{ + if ($schema === undefined) { + $errorKeyword = $exclusiveKeyword; + $errSchemaPath = it.errSchemaPath + '/' + $exclusiveKeyword; + $schemaValue = $schemaValueExcl; + $isData = $isDataExcl; + } + }} {{??}} {{ var $exclIsNumber = typeof $schemaExcl == 'number' diff --git a/node_modules/ajv/lib/dot/custom.jst b/node_modules/ajv/lib/dot/custom.jst index 402028e6b..d30588fb0 100644 --- a/node_modules/ajv/lib/dot/custom.jst +++ b/node_modules/ajv/lib/dot/custom.jst @@ -112,13 +112,13 @@ var {{=$valid}}; {{# def.storeDefOut:def_callRuleValidate }} {{? $rDef.errors === false }} - {{=$valid}} = {{? $asyncKeyword }}{{=it.yieldAwait}}{{?}}{{= def_callRuleValidate }}; + {{=$valid}} = {{? $asyncKeyword }}await {{?}}{{= def_callRuleValidate }}; {{??}} {{? $asyncKeyword }} {{ $ruleErrs = 'customErrors' + $lvl; }} var {{=$ruleErrs}} = null; try { - {{=$valid}} = {{=it.yieldAwait}}{{= def_callRuleValidate }}; + {{=$valid}} = await {{= def_callRuleValidate }}; } catch (e) { {{=$valid}} = false; if (e instanceof ValidationError) {{=$ruleErrs}} = e.errors; diff --git a/node_modules/ajv/lib/dot/errors.def b/node_modules/ajv/lib/dot/errors.def index b79646fc2..4d7f84840 100644 --- a/node_modules/ajv/lib/dot/errors.def +++ b/node_modules/ajv/lib/dot/errors.def @@ -94,13 +94,14 @@ 'false schema': "'boolean schema is false'", $ref: "'can\\\'t resolve reference {{=it.util.escapeQuotes($schema)}}'", additionalItems: "'should NOT have more than {{=$schema.length}} items'", - additionalProperties: "'should NOT have additional properties'", + additionalProperties: "'{{? it.opts._errorDataPathProperty }}is an invalid additional property{{??}}should NOT have additional properties{{?}}'", anyOf: "'should match some schema in anyOf'", const: "'should be equal to constant'", contains: "'should contain a valid item'", dependencies: "'should have {{? $deps.length == 1 }}property {{= it.util.escapeQuotes($deps[0]) }}{{??}}properties {{= it.util.escapeQuotes($deps.join(\", \")) }}{{?}} when property {{= it.util.escapeQuotes($property) }} is present'", 'enum': "'should be equal to one of the allowed values'", format: "'should match format \"{{#def.concatSchemaEQ}}\"'", + 'if': "'should match \"' + {{=$ifClause}} + '\" schema'", _limit: "'should be {{=$opStr}} {{#def.appendSchema}}", _exclusiveLimit: "'{{=$exclusiveKeyword}} should be boolean'", _limitItems: "'should NOT have {{?$keyword=='maxItems'}}more{{??}}less{{?}} than {{#def.concatSchema}} items'", @@ -110,7 +111,6 @@ not: "'should NOT be valid'", oneOf: "'should match exactly one schema in oneOf'", pattern: "'should match pattern \"{{#def.concatSchemaEQ}}\"'", - patternGroups: "'should NOT have {{=$moreOrLess}} than {{=$limit}} properties matching pattern \"{{=it.util.escapeQuotes($pgProperty)}}\"'", propertyNames: "'property name \\'{{=$invalidName}}\\' is invalid'", required: "'{{? it.opts._errorDataPathProperty }}is a required property{{??}}should have required property \\'{{=$missingProperty}}\\'{{?}}'", type: "'should be {{? $typeIsArray }}{{= $typeSchema.join(\",\") }}{{??}}{{=$typeSchema}}{{?}}'", @@ -137,6 +137,7 @@ dependencies: "validate.schema{{=$schemaPath}}", 'enum': "validate.schema{{=$schemaPath}}", format: "{{#def.schemaRefOrQS}}", + 'if': "validate.schema{{=$schemaPath}}", _limit: "{{#def.schemaRefOrVal}}", _exclusiveLimit: "validate.schema{{=$schemaPath}}", _limitItems: "{{#def.schemaRefOrVal}}", @@ -146,7 +147,6 @@ not: "validate.schema{{=$schemaPath}}", oneOf: "validate.schema{{=$schemaPath}}", pattern: "{{#def.schemaRefOrQS}}", - patternGroups: "validate.schema{{=$schemaPath}}", propertyNames: "validate.schema{{=$schemaPath}}", required: "validate.schema{{=$schemaPath}}", type: "validate.schema{{=$schemaPath}}", @@ -167,11 +167,12 @@ additionalItems: "{ limit: {{=$schema.length}} }", additionalProperties: "{ additionalProperty: '{{=$additionalProperty}}' }", anyOf: "{}", - const: "{}", + const: "{ allowedValue: schema{{=$lvl}} }", contains: "{}", dependencies: "{ property: '{{= it.util.escapeQuotes($property) }}', missingProperty: '{{=$missingProperty}}', depsCount: {{=$deps.length}}, deps: '{{= it.util.escapeQuotes($deps.length==1 ? $deps[0] : $deps.join(\", \")) }}' }", 'enum': "{ allowedValues: schema{{=$lvl}} }", format: "{ format: {{#def.schemaValueQS}} }", + 'if': "{ failingKeyword: {{=$ifClause}} }", _limit: "{ comparison: {{=$opExpr}}, limit: {{=$schemaValue}}, exclusive: {{=$exclusive}} }", _exclusiveLimit: "{}", _limitItems: "{ limit: {{=$schemaValue}} }", @@ -179,9 +180,8 @@ _limitProperties:"{ limit: {{=$schemaValue}} }", multipleOf: "{ multipleOf: {{=$schemaValue}} }", not: "{}", - oneOf: "{}", + oneOf: "{ passingSchemas: {{=$passingSchemas}} }", pattern: "{ pattern: {{#def.schemaValueQS}} }", - patternGroups: "{ reason: '{{=$reason}}', limit: {{=$limit}}, pattern: '{{=it.util.escapeQuotes($pgProperty)}}' }", propertyNames: "{ propertyName: '{{=$invalidName}}' }", required: "{ missingProperty: '{{=$missingProperty}}' }", type: "{ type: '{{? $typeIsArray }}{{= $typeSchema.join(\",\") }}{{??}}{{=$typeSchema}}{{?}}' }", diff --git a/node_modules/ajv/lib/dot/format.jst b/node_modules/ajv/lib/dot/format.jst index 484dddf79..37f14da80 100644 --- a/node_modules/ajv/lib/dot/format.jst +++ b/node_modules/ajv/lib/dot/format.jst @@ -24,7 +24,7 @@ ({{=$format}} && {{=$formatType}} == '{{=$ruleType}}' && !(typeof {{=$format}} == 'function' ? {{? it.async}} - (async{{=$lvl}} ? {{=it.yieldAwait}} {{=$format}}({{=$data}}) : {{=$format}}({{=$data}})) + (async{{=$lvl}} ? await {{=$format}}({{=$data}}) : {{=$format}}({{=$data}})) {{??}} {{=$format}}({{=$data}}) {{?}} @@ -97,7 +97,7 @@ if (!it.async) throw new Error('async format in sync schema'); var $formatRef = 'formats' + it.util.getProperty($schema) + '.validate'; }} - if (!({{=it.yieldAwait}} {{=$formatRef}}({{=$data}}))) { + if (!(await {{=$formatRef}}({{=$data}}))) { {{??}} if (!{{# def.checkFormat }}) { {{?}} diff --git a/node_modules/ajv/lib/dot/oneOf.jst b/node_modules/ajv/lib/dot/oneOf.jst index 59a435549..bcce2c6ed 100644 --- a/node_modules/ajv/lib/dot/oneOf.jst +++ b/node_modules/ajv/lib/dot/oneOf.jst @@ -3,11 +3,17 @@ {{# def.setupKeyword }} {{# def.setupNextLevel }} -var {{=$errs}} = errors; -var prevValid{{=$lvl}} = false; -var {{=$valid}} = false; +{{ + var $currentBaseId = $it.baseId + , $prevValid = 'prevValid' + $lvl + , $passingSchemas = 'passingSchemas' + $lvl; +}} + +var {{=$errs}} = errors + , {{=$prevValid}} = false + , {{=$valid}} = false + , {{=$passingSchemas}} = null; -{{ var $currentBaseId = $it.baseId; }} {{# def.setCompositeRule }} {{~ $schema:$sch:$i }} @@ -24,13 +30,17 @@ var {{=$valid}} = false; {{?}} {{? $i }} - if ({{=$nextValid}} && prevValid{{=$lvl}}) + if ({{=$nextValid}} && {{=$prevValid}}) { {{=$valid}} = false; - else { + {{=$passingSchemas}} = [{{=$passingSchemas}}, {{=$i}}]; + } else { {{ $closingBraces += '}'; }} {{?}} - if ({{=$nextValid}}) {{=$valid}} = prevValid{{=$lvl}} = true; + if ({{=$nextValid}}) { + {{=$valid}} = {{=$prevValid}} = true; + {{=$passingSchemas}} = {{=$i}}; + } {{~}} {{# def.resetCompositeRule }} diff --git a/node_modules/ajv/lib/dot/properties.jst b/node_modules/ajv/lib/dot/properties.jst index 8d56324b7..862067e75 100644 --- a/node_modules/ajv/lib/dot/properties.jst +++ b/node_modules/ajv/lib/dot/properties.jst @@ -42,13 +42,8 @@ , $currentBaseId = it.baseId; var $required = it.schema.required; - if ($required && !(it.opts.v5 && $required.$data) && $required.length < it.opts.loopRequired) + if ($required && !(it.opts.$data && $required.$data) && $required.length < it.opts.loopRequired) var $requiredHash = it.util.toHash($required); - - if (it.opts.patternGroups) { - var $pgProperties = it.schema.patternGroups || {} - , $pgPropertyKeys = Object.keys($pgProperties); - } }} @@ -63,8 +58,8 @@ var {{=$nextValid}} = true; {{? $someProperties }} var isAdditional{{=$lvl}} = !(false {{? $schemaKeys.length }} - {{? $schemaKeys.length > 5 }} - || validate.schema{{=$schemaPath}}[{{=$key}}] + {{? $schemaKeys.length > 8 }} + || validate.schema{{=$schemaPath}}.hasOwnProperty({{=$key}}) {{??}} {{~ $schemaKeys:$propertyKey }} || {{=$key}} == {{= it.util.toQuotedString($propertyKey) }} @@ -76,11 +71,6 @@ var {{=$nextValid}} = true; || {{= it.usePattern($pProperty) }}.test({{=$key}}) {{~}} {{?}} - {{? it.opts.patternGroups && $pgPropertyKeys.length }} - {{~ $pgPropertyKeys:$pgProperty:$i }} - || {{= it.usePattern($pgProperty) }}.test({{=$key}}) - {{~}} - {{?}} ); if (isAdditional{{=$lvl}}) { @@ -246,79 +236,6 @@ var {{=$nextValid}} = true; {{?}} -{{? it.opts.patternGroups && $pgPropertyKeys.length }} - {{~ $pgPropertyKeys:$pgProperty }} - {{ - var $pgSchema = $pgProperties[$pgProperty] - , $sch = $pgSchema.schema; - }} - - {{? {{# def.nonEmptySchema:$sch}} }} - {{ - $it.schema = $sch; - $it.schemaPath = it.schemaPath + '.patternGroups' + it.util.getProperty($pgProperty) + '.schema'; - $it.errSchemaPath = it.errSchemaPath + '/patternGroups/' - + it.util.escapeFragment($pgProperty) - + '/schema'; - }} - - var pgPropCount{{=$lvl}} = 0; - - {{# def.iterateProperties }} - if ({{= it.usePattern($pgProperty) }}.test({{=$key}})) { - pgPropCount{{=$lvl}}++; - - {{ - $it.errorPath = it.util.getPathExpr(it.errorPath, $key, it.opts.jsonPointers); - var $passData = $data + '[' + $key + ']'; - $it.dataPathArr[$dataNxt] = $key; - }} - - {{# def.generateSubschemaCode }} - {{# def.optimizeValidate }} - - {{? $breakOnError }} if (!{{=$nextValid}}) break; {{?}} - } - {{? $breakOnError }} else {{=$nextValid}} = true; {{?}} - } - - {{# def.ifResultValid }} - - {{ - var $pgMin = $pgSchema.minimum - , $pgMax = $pgSchema.maximum; - }} - {{? $pgMin !== undefined || $pgMax !== undefined }} - var {{=$valid}} = true; - - {{ var $currErrSchemaPath = $errSchemaPath; }} - - {{? $pgMin !== undefined }} - {{ var $limit = $pgMin, $reason = 'minimum', $moreOrLess = 'less'; }} - {{=$valid}} = pgPropCount{{=$lvl}} >= {{=$pgMin}}; - {{ $errSchemaPath = it.errSchemaPath + '/patternGroups/minimum'; }} - {{# def.checkError:'patternGroups' }} - {{? $pgMax !== undefined }} - else - {{?}} - {{?}} - - {{? $pgMax !== undefined }} - {{ var $limit = $pgMax, $reason = 'maximum', $moreOrLess = 'more'; }} - {{=$valid}} = pgPropCount{{=$lvl}} <= {{=$pgMax}}; - {{ $errSchemaPath = it.errSchemaPath + '/patternGroups/maximum'; }} - {{# def.checkError:'patternGroups' }} - {{?}} - - {{ $errSchemaPath = $currErrSchemaPath; }} - - {{# def.ifValid }} - {{?}} - {{?}} {{ /* def.nonEmptySchema */ }} - {{~}} -{{?}} - - {{? $breakOnError }} {{= $closingBraces }} if ({{=$errs}} == errors) { diff --git a/node_modules/ajv/lib/dot/ref.jst b/node_modules/ajv/lib/dot/ref.jst index 036bc2905..253e3507c 100644 --- a/node_modules/ajv/lib/dot/ref.jst +++ b/node_modules/ajv/lib/dot/ref.jst @@ -50,7 +50,7 @@ {{?}} {{??}} {{ - $async = $refVal.$async === true; + $async = $refVal.$async === true || (it.async && $refVal.$async !== false); $refCode = $refVal.code; }} {{?}} @@ -65,7 +65,7 @@ {{ if (!it.async) throw new Error('async schema referenced by sync schema'); }} {{? $breakOnError }} var {{=$valid}}; {{?}} try { - {{=it.yieldAwait}} {{=__callValidate}}; + await {{=__callValidate}}; {{? $breakOnError }} {{=$valid}} = true; {{?}} } catch (e) { if (!(e instanceof ValidationError)) throw e; diff --git a/node_modules/ajv/lib/dot/uniqueItems.jst b/node_modules/ajv/lib/dot/uniqueItems.jst index dfc42b03b..22f82f99d 100644 --- a/node_modules/ajv/lib/dot/uniqueItems.jst +++ b/node_modules/ajv/lib/dot/uniqueItems.jst @@ -14,18 +14,42 @@ else { {{?}} - var {{=$valid}} = true; - if ({{=$data}}.length > 1) { - var i = {{=$data}}.length, j; - outer: - for (;i--;) { - for (j = i; j--;) { - if (equal({{=$data}}[i], {{=$data}}[j])) { + var i = {{=$data}}.length + , {{=$valid}} = true + , j; + if (i > 1) { + {{ + var $itemType = it.schema.items && it.schema.items.type + , $typeIsArray = Array.isArray($itemType); + }} + {{? !$itemType || $itemType == 'object' || $itemType == 'array' || + ($typeIsArray && ($itemType.indexOf('object') >= 0 || $itemType.indexOf('array') >= 0)) }} + outer: + for (;i--;) { + for (j = i; j--;) { + if (equal({{=$data}}[i], {{=$data}}[j])) { + {{=$valid}} = false; + break outer; + } + } + } + {{??}} + var itemIndices = {}, item; + for (;i--;) { + var item = {{=$data}}[i]; + {{ var $method = 'checkDataType' + ($typeIsArray ? 's' : ''); }} + if ({{= it.util[$method]($itemType, 'item', true) }}) continue; + {{? $typeIsArray}} + if (typeof item == 'string') item = '"' + item; + {{?}} + if (typeof itemIndices[item] == 'number') { {{=$valid}} = false; - break outer; + j = itemIndices[item]; + break; } + itemIndices[item] = i; } - } + {{?}} } {{? $isData }} } {{?}} diff --git a/node_modules/ajv/lib/dot/validate.jst b/node_modules/ajv/lib/dot/validate.jst index 273e4c37e..27393cf30 100644 --- a/node_modules/ajv/lib/dot/validate.jst +++ b/node_modules/ajv/lib/dot/validate.jst @@ -21,29 +21,11 @@ }} {{? it.isTop }} - {{? $async }} - {{ - it.async = true; - var $es7 = it.opts.async == 'es7'; - it.yieldAwait = $es7 ? 'await' : 'yield'; - }} - {{?}} - - var validate = - {{? $async }} - {{? $es7 }} - (async function - {{??}} - {{? it.opts.async != '*'}}co.wrap{{?}}(function* - {{?}} - {{??}} - (function + var validate = {{?$async}}{{it.async = true;}}async {{?}}function(data, dataPath, parentData, parentDataProperty, rootData) { + 'use strict'; + {{? $id && (it.opts.sourceCode || it.opts.processCode) }} + {{= '/\*# sourceURL=' + $id + ' */' }} {{?}} - (data, dataPath, parentData, parentDataProperty, rootData) { - 'use strict'; - {{? $id && (it.opts.sourceCode || it.opts.processCode) }} - {{= '/\*# sourceURL=' + $id + ' */' }} - {{?}} {{?}} {{? typeof it.schema == 'boolean' || !($refKeywords || it.schema.$ref) }} @@ -70,7 +52,7 @@ {{?}} {{? it.isTop}} - }); + }; return validate; {{?}} @@ -145,6 +127,10 @@ {{?}} {{?}} +{{? it.schema.$comment && it.opts.$comment }} + {{= it.RULES.all.$comment.code(it, '$comment') }} +{{?}} + {{? $typeSchema }} {{? it.opts.coerceTypes }} {{ var $coerceToTypes = it.util.coerceToTypes(it.opts.coerceTypes, $typeSchema); }} @@ -176,9 +162,6 @@ {{ $closingBraces2 += '}'; }} {{?}} {{??}} - {{? it.opts.v5 && it.schema.patternGroups }} - {{ it.logger.warn('keyword "patternGroups" is deprecated and disabled. Use option patternGroups: true to enable.'); }} - {{?}} {{~ it.RULES:$rulesGroup }} {{? $shouldUseGroup($rulesGroup) }} {{? $rulesGroup.type }} @@ -237,7 +220,7 @@ validate.errors = vErrors; {{ /* don't edit, used in replace */ }} return errors === 0; {{ /* don't edit, used in replace */ }} {{?}} - }); + }; return validate; {{??}} diff --git a/node_modules/ajv/lib/dotjs/_limit.js b/node_modules/ajv/lib/dotjs/_limit.js index 10a187fb7..20485c8d0 100644 --- a/node_modules/ajv/lib/dotjs/_limit.js +++ b/node_modules/ajv/lib/dotjs/_limit.js @@ -65,7 +65,13 @@ module.exports = function generate__limit(it, $keyword, $ruleType) { if ($isData) { out += ' (' + ($schemaValue) + ' !== undefined && typeof ' + ($schemaValue) + ' != \'number\') || '; } - out += ' ' + ($exclType) + ' == \'number\' ? ( (' + ($exclusive) + ' = ' + ($schemaValue) + ' === undefined || ' + ($schemaValueExcl) + ' ' + ($op) + '= ' + ($schemaValue) + ') ? ' + ($data) + ' ' + ($notOp) + '= ' + ($schemaValueExcl) + ' : ' + ($data) + ' ' + ($notOp) + ' ' + ($schemaValue) + ' ) : ( (' + ($exclusive) + ' = ' + ($schemaValueExcl) + ' === true) ? ' + ($data) + ' ' + ($notOp) + '= ' + ($schemaValue) + ' : ' + ($data) + ' ' + ($notOp) + ' ' + ($schemaValue) + ' ) || ' + ($data) + ' !== ' + ($data) + ') { var op' + ($lvl) + ' = ' + ($exclusive) + ' ? \'' + ($op) + '\' : \'' + ($op) + '=\';'; + out += ' ' + ($exclType) + ' == \'number\' ? ( (' + ($exclusive) + ' = ' + ($schemaValue) + ' === undefined || ' + ($schemaValueExcl) + ' ' + ($op) + '= ' + ($schemaValue) + ') ? ' + ($data) + ' ' + ($notOp) + '= ' + ($schemaValueExcl) + ' : ' + ($data) + ' ' + ($notOp) + ' ' + ($schemaValue) + ' ) : ( (' + ($exclusive) + ' = ' + ($schemaValueExcl) + ' === true) ? ' + ($data) + ' ' + ($notOp) + '= ' + ($schemaValue) + ' : ' + ($data) + ' ' + ($notOp) + ' ' + ($schemaValue) + ' ) || ' + ($data) + ' !== ' + ($data) + ') { var op' + ($lvl) + ' = ' + ($exclusive) + ' ? \'' + ($op) + '\' : \'' + ($op) + '=\'; '; + if ($schema === undefined) { + $errorKeyword = $exclusiveKeyword; + $errSchemaPath = it.errSchemaPath + '/' + $exclusiveKeyword; + $schemaValue = $schemaValueExcl; + $isData = $isDataExcl; + } } else { var $exclIsNumber = typeof $schemaExcl == 'number', $opStr = $op; diff --git a/node_modules/ajv/lib/dotjs/const.js b/node_modules/ajv/lib/dotjs/const.js index d19756e14..acad86f79 100644 --- a/node_modules/ajv/lib/dotjs/const.js +++ b/node_modules/ajv/lib/dotjs/const.js @@ -25,7 +25,7 @@ module.exports = function generate_const(it, $keyword, $ruleType) { $$outStack.push(out); out = ''; /* istanbul ignore else */ if (it.createErrors !== false) { - out += ' { keyword: \'' + ('const') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: ' + (it.util.toQuotedString($errSchemaPath)) + ' , params: {} '; + out += ' { keyword: \'' + ('const') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: ' + (it.util.toQuotedString($errSchemaPath)) + ' , params: { allowedValue: schema' + ($lvl) + ' } '; if (it.opts.messages !== false) { out += ' , message: \'should be equal to constant\' '; } diff --git a/node_modules/ajv/lib/dotjs/custom.js b/node_modules/ajv/lib/dotjs/custom.js index bff06d111..0623e2440 100644 --- a/node_modules/ajv/lib/dotjs/custom.js +++ b/node_modules/ajv/lib/dotjs/custom.js @@ -99,13 +99,13 @@ module.exports = function generate_custom(it, $keyword, $ruleType) { if ($rDef.errors === false) { out += ' ' + ($valid) + ' = '; if ($asyncKeyword) { - out += '' + (it.yieldAwait); + out += 'await '; } out += '' + (def_callRuleValidate) + '; '; } else { if ($asyncKeyword) { $ruleErrs = 'customErrors' + $lvl; - out += ' var ' + ($ruleErrs) + ' = null; try { ' + ($valid) + ' = ' + (it.yieldAwait) + (def_callRuleValidate) + '; } catch (e) { ' + ($valid) + ' = false; if (e instanceof ValidationError) ' + ($ruleErrs) + ' = e.errors; else throw e; } '; + out += ' var ' + ($ruleErrs) + ' = null; try { ' + ($valid) + ' = await ' + (def_callRuleValidate) + '; } catch (e) { ' + ($valid) + ' = false; if (e instanceof ValidationError) ' + ($ruleErrs) + ' = e.errors; else throw e; } '; } else { out += ' ' + ($ruleErrs) + ' = null; ' + ($valid) + ' = ' + (def_callRuleValidate) + '; '; } diff --git a/node_modules/ajv/lib/dotjs/format.js b/node_modules/ajv/lib/dotjs/format.js index 68697f0de..20a467ee2 100644 --- a/node_modules/ajv/lib/dotjs/format.js +++ b/node_modules/ajv/lib/dotjs/format.js @@ -46,7 +46,7 @@ module.exports = function generate_format(it, $keyword, $ruleType) { } out += ' (' + ($format) + ' && ' + ($formatType) + ' == \'' + ($ruleType) + '\' && !(typeof ' + ($format) + ' == \'function\' ? '; if (it.async) { - out += ' (async' + ($lvl) + ' ? ' + (it.yieldAwait) + ' ' + ($format) + '(' + ($data) + ') : ' + ($format) + '(' + ($data) + ')) '; + out += ' (async' + ($lvl) + ' ? await ' + ($format) + '(' + ($data) + ') : ' + ($format) + '(' + ($data) + ')) '; } else { out += ' ' + ($format) + '(' + ($data) + ') '; } @@ -84,7 +84,7 @@ module.exports = function generate_format(it, $keyword, $ruleType) { if ($async) { if (!it.async) throw new Error('async format in sync schema'); var $formatRef = 'formats' + it.util.getProperty($schema) + '.validate'; - out += ' if (!(' + (it.yieldAwait) + ' ' + ($formatRef) + '(' + ($data) + '))) { '; + out += ' if (!(await ' + ($formatRef) + '(' + ($data) + '))) { '; } else { out += ' if (! '; var $formatRef = 'formats' + it.util.getProperty($schema); diff --git a/node_modules/ajv/lib/dotjs/oneOf.js b/node_modules/ajv/lib/dotjs/oneOf.js index b4cd46065..b6be64092 100644 --- a/node_modules/ajv/lib/dotjs/oneOf.js +++ b/node_modules/ajv/lib/dotjs/oneOf.js @@ -14,8 +14,10 @@ module.exports = function generate_oneOf(it, $keyword, $ruleType) { var $closingBraces = ''; $it.level++; var $nextValid = 'valid' + $it.level; - out += 'var ' + ($errs) + ' = errors;var prevValid' + ($lvl) + ' = false;var ' + ($valid) + ' = false;'; - var $currentBaseId = $it.baseId; + var $currentBaseId = $it.baseId, + $prevValid = 'prevValid' + $lvl, + $passingSchemas = 'passingSchemas' + $lvl; + out += 'var ' + ($errs) + ' = errors , ' + ($prevValid) + ' = false , ' + ($valid) + ' = false , ' + ($passingSchemas) + ' = null; '; var $wasComposite = it.compositeRule; it.compositeRule = $it.compositeRule = true; var arr1 = $schema; @@ -34,16 +36,16 @@ module.exports = function generate_oneOf(it, $keyword, $ruleType) { out += ' var ' + ($nextValid) + ' = true; '; } if ($i) { - out += ' if (' + ($nextValid) + ' && prevValid' + ($lvl) + ') ' + ($valid) + ' = false; else { '; + out += ' if (' + ($nextValid) + ' && ' + ($prevValid) + ') { ' + ($valid) + ' = false; ' + ($passingSchemas) + ' = [' + ($passingSchemas) + ', ' + ($i) + ']; } else { '; $closingBraces += '}'; } - out += ' if (' + ($nextValid) + ') ' + ($valid) + ' = prevValid' + ($lvl) + ' = true;'; + out += ' if (' + ($nextValid) + ') { ' + ($valid) + ' = ' + ($prevValid) + ' = true; ' + ($passingSchemas) + ' = ' + ($i) + '; }'; } } it.compositeRule = $it.compositeRule = $wasComposite; out += '' + ($closingBraces) + 'if (!' + ($valid) + ') { var err = '; /* istanbul ignore else */ if (it.createErrors !== false) { - out += ' { keyword: \'' + ('oneOf') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: ' + (it.util.toQuotedString($errSchemaPath)) + ' , params: {} '; + out += ' { keyword: \'' + ('oneOf') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: ' + (it.util.toQuotedString($errSchemaPath)) + ' , params: { passingSchemas: ' + ($passingSchemas) + ' } '; if (it.opts.messages !== false) { out += ' , message: \'should match exactly one schema in oneOf\' '; } diff --git a/node_modules/ajv/lib/dotjs/properties.js b/node_modules/ajv/lib/dotjs/properties.js index 3c6cecf63..409692fce 100644 --- a/node_modules/ajv/lib/dotjs/properties.js +++ b/node_modules/ajv/lib/dotjs/properties.js @@ -8,7 +8,6 @@ module.exports = function generate_properties(it, $keyword, $ruleType) { var $errSchemaPath = it.errSchemaPath + '/' + $keyword; var $breakOnError = !it.opts.allErrors; var $data = 'data' + ($dataLvl || ''); - var $valid = 'valid' + $lvl; var $errs = 'errs__' + $lvl; var $it = it.util.copy(it); var $closingBraces = ''; @@ -31,11 +30,7 @@ module.exports = function generate_properties(it, $keyword, $ruleType) { $ownProperties = it.opts.ownProperties, $currentBaseId = it.baseId; var $required = it.schema.required; - if ($required && !(it.opts.v5 && $required.$data) && $required.length < it.opts.loopRequired) var $requiredHash = it.util.toHash($required); - if (it.opts.patternGroups) { - var $pgProperties = it.schema.patternGroups || {}, - $pgPropertyKeys = Object.keys($pgProperties); - } + if ($required && !(it.opts.$data && $required.$data) && $required.length < it.opts.loopRequired) var $requiredHash = it.util.toHash($required); out += 'var ' + ($errs) + ' = errors;var ' + ($nextValid) + ' = true;'; if ($ownProperties) { out += ' var ' + ($dataProperties) + ' = undefined;'; @@ -49,8 +44,8 @@ module.exports = function generate_properties(it, $keyword, $ruleType) { if ($someProperties) { out += ' var isAdditional' + ($lvl) + ' = !(false '; if ($schemaKeys.length) { - if ($schemaKeys.length > 5) { - out += ' || validate.schema' + ($schemaPath) + '[' + ($key) + '] '; + if ($schemaKeys.length > 8) { + out += ' || validate.schema' + ($schemaPath) + '.hasOwnProperty(' + ($key) + ') '; } else { var arr1 = $schemaKeys; if (arr1) { @@ -74,17 +69,6 @@ module.exports = function generate_properties(it, $keyword, $ruleType) { } } } - if (it.opts.patternGroups && $pgPropertyKeys.length) { - var arr3 = $pgPropertyKeys; - if (arr3) { - var $pgProperty, $i = -1, - l3 = arr3.length - 1; - while ($i < l3) { - $pgProperty = arr3[$i += 1]; - out += ' || ' + (it.usePattern($pgProperty)) + '.test(' + ($key) + ') '; - } - } - } out += ' ); if (isAdditional' + ($lvl) + ') { '; } if ($removeAdditional == 'all') { @@ -108,7 +92,13 @@ module.exports = function generate_properties(it, $keyword, $ruleType) { if (it.createErrors !== false) { out += ' { keyword: \'' + ('additionalProperties') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: ' + (it.util.toQuotedString($errSchemaPath)) + ' , params: { additionalProperty: \'' + ($additionalProperty) + '\' } '; if (it.opts.messages !== false) { - out += ' , message: \'should NOT have additional properties\' '; + out += ' , message: \''; + if (it.opts._errorDataPathProperty) { + out += 'is an invalid additional property'; + } else { + out += 'should NOT have additional properties'; + } + out += '\' '; } if (it.opts.verbose) { out += ' , schema: false , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' '; @@ -185,12 +175,12 @@ module.exports = function generate_properties(it, $keyword, $ruleType) { } var $useDefaults = it.opts.useDefaults && !it.compositeRule; if ($schemaKeys.length) { - var arr4 = $schemaKeys; - if (arr4) { - var $propertyKey, i4 = -1, - l4 = arr4.length - 1; - while (i4 < l4) { - $propertyKey = arr4[i4 += 1]; + var arr3 = $schemaKeys; + if (arr3) { + var $propertyKey, i3 = -1, + l3 = arr3.length - 1; + while (i3 < l3) { + $propertyKey = arr3[i3 += 1]; var $sch = $schema[$propertyKey]; if (it.util.schemaHasRules($sch, it.RULES.all)) { var $prop = it.util.getProperty($propertyKey), @@ -287,12 +277,12 @@ module.exports = function generate_properties(it, $keyword, $ruleType) { } } if ($pPropertyKeys.length) { - var arr5 = $pPropertyKeys; - if (arr5) { - var $pProperty, i5 = -1, - l5 = arr5.length - 1; - while (i5 < l5) { - $pProperty = arr5[i5 += 1]; + var arr4 = $pPropertyKeys; + if (arr4) { + var $pProperty, i4 = -1, + l4 = arr4.length - 1; + while (i4 < l4) { + $pProperty = arr4[i4 += 1]; var $sch = $pProperties[$pProperty]; if (it.util.schemaHasRules($sch, it.RULES.all)) { $it.schema = $sch; @@ -330,136 +320,6 @@ module.exports = function generate_properties(it, $keyword, $ruleType) { } } } - if (it.opts.patternGroups && $pgPropertyKeys.length) { - var arr6 = $pgPropertyKeys; - if (arr6) { - var $pgProperty, i6 = -1, - l6 = arr6.length - 1; - while (i6 < l6) { - $pgProperty = arr6[i6 += 1]; - var $pgSchema = $pgProperties[$pgProperty], - $sch = $pgSchema.schema; - if (it.util.schemaHasRules($sch, it.RULES.all)) { - $it.schema = $sch; - $it.schemaPath = it.schemaPath + '.patternGroups' + it.util.getProperty($pgProperty) + '.schema'; - $it.errSchemaPath = it.errSchemaPath + '/patternGroups/' + it.util.escapeFragment($pgProperty) + '/schema'; - out += ' var pgPropCount' + ($lvl) + ' = 0; '; - if ($ownProperties) { - out += ' ' + ($dataProperties) + ' = ' + ($dataProperties) + ' || Object.keys(' + ($data) + '); for (var ' + ($idx) + '=0; ' + ($idx) + '<' + ($dataProperties) + '.length; ' + ($idx) + '++) { var ' + ($key) + ' = ' + ($dataProperties) + '[' + ($idx) + ']; '; - } else { - out += ' for (var ' + ($key) + ' in ' + ($data) + ') { '; - } - out += ' if (' + (it.usePattern($pgProperty)) + '.test(' + ($key) + ')) { pgPropCount' + ($lvl) + '++; '; - $it.errorPath = it.util.getPathExpr(it.errorPath, $key, it.opts.jsonPointers); - var $passData = $data + '[' + $key + ']'; - $it.dataPathArr[$dataNxt] = $key; - var $code = it.validate($it); - $it.baseId = $currentBaseId; - if (it.util.varOccurences($code, $nextData) < 2) { - out += ' ' + (it.util.varReplace($code, $nextData, $passData)) + ' '; - } else { - out += ' var ' + ($nextData) + ' = ' + ($passData) + '; ' + ($code) + ' '; - } - if ($breakOnError) { - out += ' if (!' + ($nextValid) + ') break; '; - } - out += ' } '; - if ($breakOnError) { - out += ' else ' + ($nextValid) + ' = true; '; - } - out += ' } '; - if ($breakOnError) { - out += ' if (' + ($nextValid) + ') { '; - $closingBraces += '}'; - } - var $pgMin = $pgSchema.minimum, - $pgMax = $pgSchema.maximum; - if ($pgMin !== undefined || $pgMax !== undefined) { - out += ' var ' + ($valid) + ' = true; '; - var $currErrSchemaPath = $errSchemaPath; - if ($pgMin !== undefined) { - var $limit = $pgMin, - $reason = 'minimum', - $moreOrLess = 'less'; - out += ' ' + ($valid) + ' = pgPropCount' + ($lvl) + ' >= ' + ($pgMin) + '; '; - $errSchemaPath = it.errSchemaPath + '/patternGroups/minimum'; - out += ' if (!' + ($valid) + ') { '; - var $$outStack = $$outStack || []; - $$outStack.push(out); - out = ''; /* istanbul ignore else */ - if (it.createErrors !== false) { - out += ' { keyword: \'' + ('patternGroups') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: ' + (it.util.toQuotedString($errSchemaPath)) + ' , params: { reason: \'' + ($reason) + '\', limit: ' + ($limit) + ', pattern: \'' + (it.util.escapeQuotes($pgProperty)) + '\' } '; - if (it.opts.messages !== false) { - out += ' , message: \'should NOT have ' + ($moreOrLess) + ' than ' + ($limit) + ' properties matching pattern "' + (it.util.escapeQuotes($pgProperty)) + '"\' '; - } - if (it.opts.verbose) { - out += ' , schema: validate.schema' + ($schemaPath) + ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' '; - } - out += ' } '; - } else { - out += ' {} '; - } - var __err = out; - out = $$outStack.pop(); - if (!it.compositeRule && $breakOnError) { /* istanbul ignore if */ - if (it.async) { - out += ' throw new ValidationError([' + (__err) + ']); '; - } else { - out += ' validate.errors = [' + (__err) + ']; return false; '; - } - } else { - out += ' var err = ' + (__err) + '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; '; - } - out += ' } '; - if ($pgMax !== undefined) { - out += ' else '; - } - } - if ($pgMax !== undefined) { - var $limit = $pgMax, - $reason = 'maximum', - $moreOrLess = 'more'; - out += ' ' + ($valid) + ' = pgPropCount' + ($lvl) + ' <= ' + ($pgMax) + '; '; - $errSchemaPath = it.errSchemaPath + '/patternGroups/maximum'; - out += ' if (!' + ($valid) + ') { '; - var $$outStack = $$outStack || []; - $$outStack.push(out); - out = ''; /* istanbul ignore else */ - if (it.createErrors !== false) { - out += ' { keyword: \'' + ('patternGroups') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: ' + (it.util.toQuotedString($errSchemaPath)) + ' , params: { reason: \'' + ($reason) + '\', limit: ' + ($limit) + ', pattern: \'' + (it.util.escapeQuotes($pgProperty)) + '\' } '; - if (it.opts.messages !== false) { - out += ' , message: \'should NOT have ' + ($moreOrLess) + ' than ' + ($limit) + ' properties matching pattern "' + (it.util.escapeQuotes($pgProperty)) + '"\' '; - } - if (it.opts.verbose) { - out += ' , schema: validate.schema' + ($schemaPath) + ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' '; - } - out += ' } '; - } else { - out += ' {} '; - } - var __err = out; - out = $$outStack.pop(); - if (!it.compositeRule && $breakOnError) { /* istanbul ignore if */ - if (it.async) { - out += ' throw new ValidationError([' + (__err) + ']); '; - } else { - out += ' validate.errors = [' + (__err) + ']; return false; '; - } - } else { - out += ' var err = ' + (__err) + '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; '; - } - out += ' } '; - } - $errSchemaPath = $currErrSchemaPath; - if ($breakOnError) { - out += ' if (' + ($valid) + ') { '; - $closingBraces += '}'; - } - } - } - } - } - } if ($breakOnError) { out += ' ' + ($closingBraces) + ' if (' + ($errs) + ' == errors) {'; } diff --git a/node_modules/ajv/lib/dotjs/ref.js b/node_modules/ajv/lib/dotjs/ref.js index a9d7bb909..cac481186 100644 --- a/node_modules/ajv/lib/dotjs/ref.js +++ b/node_modules/ajv/lib/dotjs/ref.js @@ -73,7 +73,7 @@ module.exports = function generate_ref(it, $keyword, $ruleType) { out += ' if (' + ($nextValid) + ') { '; } } else { - $async = $refVal.$async === true; + $async = $refVal.$async === true || (it.async && $refVal.$async !== false); $refCode = $refVal.code; } } @@ -100,7 +100,7 @@ module.exports = function generate_ref(it, $keyword, $ruleType) { if ($breakOnError) { out += ' var ' + ($valid) + '; '; } - out += ' try { ' + (it.yieldAwait) + ' ' + (__callValidate) + '; '; + out += ' try { await ' + (__callValidate) + '; '; if ($breakOnError) { out += ' ' + ($valid) + ' = true; '; } diff --git a/node_modules/ajv/lib/dotjs/uniqueItems.js b/node_modules/ajv/lib/dotjs/uniqueItems.js index d9b3185fc..d2dedf5a7 100644 --- a/node_modules/ajv/lib/dotjs/uniqueItems.js +++ b/node_modules/ajv/lib/dotjs/uniqueItems.js @@ -21,7 +21,21 @@ module.exports = function generate_uniqueItems(it, $keyword, $ruleType) { if ($isData) { out += ' var ' + ($valid) + '; if (' + ($schemaValue) + ' === false || ' + ($schemaValue) + ' === undefined) ' + ($valid) + ' = true; else if (typeof ' + ($schemaValue) + ' != \'boolean\') ' + ($valid) + ' = false; else { '; } - out += ' var ' + ($valid) + ' = true; if (' + ($data) + '.length > 1) { var i = ' + ($data) + '.length, j; outer: for (;i--;) { for (j = i; j--;) { if (equal(' + ($data) + '[i], ' + ($data) + '[j])) { ' + ($valid) + ' = false; break outer; } } } } '; + out += ' var i = ' + ($data) + '.length , ' + ($valid) + ' = true , j; if (i > 1) { '; + var $itemType = it.schema.items && it.schema.items.type, + $typeIsArray = Array.isArray($itemType); + if (!$itemType || $itemType == 'object' || $itemType == 'array' || ($typeIsArray && ($itemType.indexOf('object') >= 0 || $itemType.indexOf('array') >= 0))) { + out += ' outer: for (;i--;) { for (j = i; j--;) { if (equal(' + ($data) + '[i], ' + ($data) + '[j])) { ' + ($valid) + ' = false; break outer; } } } '; + } else { + out += ' var itemIndices = {}, item; for (;i--;) { var item = ' + ($data) + '[i]; '; + var $method = 'checkDataType' + ($typeIsArray ? 's' : ''); + out += ' if (' + (it.util[$method]($itemType, 'item', true)) + ') continue; '; + if ($typeIsArray) { + out += ' if (typeof item == \'string\') item = \'"\' + item; '; + } + out += ' if (typeof itemIndices[item] == \'number\') { ' + ($valid) + ' = false; j = itemIndices[item]; break; } itemIndices[item] = i; } '; + } + out += ' } '; if ($isData) { out += ' } '; } diff --git a/node_modules/ajv/lib/dotjs/validate.js b/node_modules/ajv/lib/dotjs/validate.js index 5ff9beee7..9f9e1ae40 100644 --- a/node_modules/ajv/lib/dotjs/validate.js +++ b/node_modules/ajv/lib/dotjs/validate.js @@ -5,25 +5,12 @@ module.exports = function generate_validate(it, $keyword, $ruleType) { $refKeywords = it.util.schemaHasRulesExcept(it.schema, it.RULES.all, '$ref'), $id = it.self._getId(it.schema); if (it.isTop) { - if ($async) { - it.async = true; - var $es7 = it.opts.async == 'es7'; - it.yieldAwait = $es7 ? 'await' : 'yield'; - } out += ' var validate = '; if ($async) { - if ($es7) { - out += ' (async function '; - } else { - if (it.opts.async != '*') { - out += 'co.wrap'; - } - out += '(function* '; - } - } else { - out += ' (function '; + it.async = true; + out += 'async '; } - out += ' (data, dataPath, parentData, parentDataProperty, rootData) { \'use strict\'; '; + out += 'function(data, dataPath, parentData, parentDataProperty, rootData) { \'use strict\'; '; if ($id && (it.opts.sourceCode || it.opts.processCode)) { out += ' ' + ('/\*# sourceURL=' + $id + ' */') + ' '; } @@ -83,7 +70,7 @@ module.exports = function generate_validate(it, $keyword, $ruleType) { } } if (it.isTop) { - out += ' }); return validate; '; + out += ' }; return validate; '; } return out; } @@ -126,6 +113,9 @@ module.exports = function generate_validate(it, $keyword, $ruleType) { it.logger.warn('$ref: keywords ignored in schema at path "' + it.errSchemaPath + '"'); } } + if (it.schema.$comment && it.opts.$comment) { + out += ' ' + (it.RULES.all.$comment.code(it, '$comment')); + } if ($typeSchema) { if (it.opts.coerceTypes) { var $coerceToTypes = it.util.coerceToTypes(it.opts.coerceTypes, $typeSchema); @@ -280,9 +270,6 @@ module.exports = function generate_validate(it, $keyword, $ruleType) { $closingBraces2 += '}'; } } else { - if (it.opts.v5 && it.schema.patternGroups) { - it.logger.warn('keyword "patternGroups" is deprecated and disabled. Use option patternGroups: true to enable.'); - } var arr2 = it.RULES; if (arr2) { var $rulesGroup, i2 = -1, @@ -430,7 +417,7 @@ module.exports = function generate_validate(it, $keyword, $ruleType) { out += ' validate.errors = vErrors; '; out += ' return errors === 0; '; } - out += ' }); return validate;'; + out += ' }; return validate;'; } else { out += ' var ' + ($valid) + ' = errors === errs_' + ($lvl) + ';'; } diff --git a/node_modules/ajv/lib/keyword.js b/node_modules/ajv/lib/keyword.js index 5fcfb75fc..6ed84c10a 100644 --- a/node_modules/ajv/lib/keyword.js +++ b/node_modules/ajv/lib/keyword.js @@ -51,7 +51,7 @@ function addKeyword(keyword, definition) { metaSchema = { anyOf: [ metaSchema, - { '$ref': 'https://raw.githubusercontent.com/epoberezkin/ajv/master/lib/refs/$data.json#' } + { '$ref': 'https://raw.githubusercontent.com/epoberezkin/ajv/master/lib/refs/data.json#' } ] }; } diff --git a/node_modules/ajv/lib/patternGroups.js b/node_modules/ajv/lib/patternGroups.js deleted file mode 100644 index 531a8d004..000000000 --- a/node_modules/ajv/lib/patternGroups.js +++ /dev/null @@ -1,36 +0,0 @@ -'use strict'; - -var META_SCHEMA_ID = 'http://json-schema.org/draft-06/schema'; - -module.exports = function (ajv) { - var defaultMeta = ajv._opts.defaultMeta; - var metaSchemaRef = typeof defaultMeta == 'string' - ? { $ref: defaultMeta } - : ajv.getSchema(META_SCHEMA_ID) - ? { $ref: META_SCHEMA_ID } - : {}; - - ajv.addKeyword('patternGroups', { - // implemented in properties.jst - metaSchema: { - type: 'object', - additionalProperties: { - type: 'object', - required: [ 'schema' ], - properties: { - maximum: { - type: 'integer', - minimum: 0 - }, - minimum: { - type: 'integer', - minimum: 0 - }, - schema: metaSchemaRef - }, - additionalProperties: false - } - } - }); - ajv.RULES.all.properties.implements.push('patternGroups'); -}; diff --git a/node_modules/ajv/lib/refs/$data.json b/node_modules/ajv/lib/refs/$data.json deleted file mode 100644 index 4a2edec55..000000000 --- a/node_modules/ajv/lib/refs/$data.json +++ /dev/null @@ -1,17 +0,0 @@ -{ - "$schema": "http://json-schema.org/draft-06/schema#", - "$id": "https://raw.githubusercontent.com/epoberezkin/ajv/master/lib/refs/$data.json#", - "description": "Meta-schema for $data reference (JSON-schema extension proposal)", - "type": "object", - "required": [ "$data" ], - "properties": { - "$data": { - "type": "string", - "anyOf": [ - { "format": "relative-json-pointer" }, - { "format": "json-pointer" } - ] - } - }, - "additionalProperties": false -} diff --git a/node_modules/ajv/lib/refs/json-schema-v5.json b/node_modules/ajv/lib/refs/json-schema-v5.json deleted file mode 100644 index cc679a459..000000000 --- a/node_modules/ajv/lib/refs/json-schema-v5.json +++ /dev/null @@ -1,250 +0,0 @@ -{ - "id": "https://raw.githubusercontent.com/epoberezkin/ajv/master/lib/refs/json-schema-v5.json#", - "$schema": "http://json-schema.org/draft-04/schema#", - "description": "Core schema meta-schema (v5 proposals - deprecated)", - "definitions": { - "schemaArray": { - "type": "array", - "minItems": 1, - "items": { "$ref": "#" } - }, - "positiveInteger": { - "type": "integer", - "minimum": 0 - }, - "positiveIntegerDefault0": { - "allOf": [ { "$ref": "#/definitions/positiveInteger" }, { "default": 0 } ] - }, - "simpleTypes": { - "enum": [ "array", "boolean", "integer", "null", "number", "object", "string" ] - }, - "stringArray": { - "type": "array", - "items": { "type": "string" }, - "minItems": 1, - "uniqueItems": true - }, - "$data": { - "type": "object", - "required": [ "$data" ], - "properties": { - "$data": { - "type": "string", - "anyOf": [ - { "format": "relative-json-pointer" }, - { "format": "json-pointer" } - ] - } - }, - "additionalProperties": false - } - }, - "type": "object", - "properties": { - "id": { - "type": "string", - "format": "uri" - }, - "$schema": { - "type": "string", - "format": "uri" - }, - "title": { - "type": "string" - }, - "description": { - "type": "string" - }, - "default": {}, - "multipleOf": { - "anyOf": [ - { - "type": "number", - "minimum": 0, - "exclusiveMinimum": true - }, - { "$ref": "#/definitions/$data" } - ] - }, - "maximum": { - "anyOf": [ - { "type": "number" }, - { "$ref": "#/definitions/$data" } - ] - }, - "exclusiveMaximum": { - "anyOf": [ - { - "type": "boolean", - "default": false - }, - { "$ref": "#/definitions/$data" } - ] - }, - "minimum": { - "anyOf": [ - { "type": "number" }, - { "$ref": "#/definitions/$data" } - ] - }, - "exclusiveMinimum": { - "anyOf": [ - { - "type": "boolean", - "default": false - }, - { "$ref": "#/definitions/$data" } - ] - }, - "maxLength": { - "anyOf": [ - { "$ref": "#/definitions/positiveInteger" }, - { "$ref": "#/definitions/$data" } - ] - }, - "minLength": { - "anyOf": [ - { "$ref": "#/definitions/positiveIntegerDefault0" }, - { "$ref": "#/definitions/$data" } - ] - }, - "pattern": { - "anyOf": [ - { - "type": "string", - "format": "regex" - }, - { "$ref": "#/definitions/$data" } - ] - }, - "additionalItems": { - "anyOf": [ - { "type": "boolean" }, - { "$ref": "#" }, - { "$ref": "#/definitions/$data" } - ], - "default": {} - }, - "items": { - "anyOf": [ - { "$ref": "#" }, - { "$ref": "#/definitions/schemaArray" } - ], - "default": {} - }, - "maxItems": { - "anyOf": [ - { "$ref": "#/definitions/positiveInteger" }, - { "$ref": "#/definitions/$data" } - ] - }, - "minItems": { - "anyOf": [ - { "$ref": "#/definitions/positiveIntegerDefault0" }, - { "$ref": "#/definitions/$data" } - ] - }, - "uniqueItems": { - "anyOf": [ - { - "type": "boolean", - "default": false - }, - { "$ref": "#/definitions/$data" } - ] - }, - "maxProperties": { - "anyOf": [ - { "$ref": "#/definitions/positiveInteger" }, - { "$ref": "#/definitions/$data" } - ] - }, - "minProperties": { - "anyOf": [ - { "$ref": "#/definitions/positiveIntegerDefault0" }, - { "$ref": "#/definitions/$data" } - ] - }, - "required": { - "anyOf": [ - { "$ref": "#/definitions/stringArray" }, - { "$ref": "#/definitions/$data" } - ] - }, - "additionalProperties": { - "anyOf": [ - { "type": "boolean" }, - { "$ref": "#" }, - { "$ref": "#/definitions/$data" } - ], - "default": {} - }, - "definitions": { - "type": "object", - "additionalProperties": { "$ref": "#" }, - "default": {} - }, - "properties": { - "type": "object", - "additionalProperties": { "$ref": "#" }, - "default": {} - }, - "patternProperties": { - "type": "object", - "additionalProperties": { "$ref": "#" }, - "default": {} - }, - "dependencies": { - "type": "object", - "additionalProperties": { - "anyOf": [ - { "$ref": "#" }, - { "$ref": "#/definitions/stringArray" } - ] - } - }, - "enum": { - "anyOf": [ - { - "type": "array", - "minItems": 1, - "uniqueItems": true - }, - { "$ref": "#/definitions/$data" } - ] - }, - "type": { - "anyOf": [ - { "$ref": "#/definitions/simpleTypes" }, - { - "type": "array", - "items": { "$ref": "#/definitions/simpleTypes" }, - "minItems": 1, - "uniqueItems": true - } - ] - }, - "allOf": { "$ref": "#/definitions/schemaArray" }, - "anyOf": { "$ref": "#/definitions/schemaArray" }, - "oneOf": { "$ref": "#/definitions/schemaArray" }, - "not": { "$ref": "#" }, - "format": { - "anyOf": [ - { "type": "string" }, - { "$ref": "#/definitions/$data" } - ] - }, - "constant": { - "anyOf": [ - {}, - { "$ref": "#/definitions/$data" } - ] - }, - "contains": { "$ref": "#" } - }, - "dependencies": { - "exclusiveMaximum": [ "maximum" ], - "exclusiveMinimum": [ "minimum" ] - }, - "default": {} -} |