diff options
Diffstat (limited to 'node_modules/ajv/lib')
-rw-r--r-- | node_modules/ajv/lib/ajv.d.ts | 50 | ||||
-rw-r--r-- | node_modules/ajv/lib/ajv.js | 49 | ||||
-rw-r--r-- | node_modules/ajv/lib/compile/index.js | 7 | ||||
-rw-r--r-- | node_modules/ajv/lib/compile/rules.js | 2 | ||||
-rw-r--r-- | node_modules/ajv/lib/dot/format.jst | 2 | ||||
-rw-r--r-- | node_modules/ajv/lib/dot/ref.jst | 4 | ||||
-rw-r--r-- | node_modules/ajv/lib/dot/validate.jst | 8 | ||||
-rw-r--r-- | node_modules/ajv/lib/dotjs/format.js | 2 | ||||
-rw-r--r-- | node_modules/ajv/lib/dotjs/ref.js | 4 | ||||
-rw-r--r-- | node_modules/ajv/lib/dotjs/validate.js | 8 | ||||
-rw-r--r-- | node_modules/ajv/lib/keyword.js | 5 | ||||
-rw-r--r-- | node_modules/ajv/lib/refs/json-schema-draft-06.json | 4 |
12 files changed, 106 insertions, 39 deletions
diff --git a/node_modules/ajv/lib/ajv.d.ts b/node_modules/ajv/lib/ajv.d.ts index 1b5bd8188..b687f7814 100644 --- a/node_modules/ajv/lib/ajv.d.ts +++ b/node_modules/ajv/lib/ajv.d.ts @@ -1,13 +1,16 @@ declare var ajv: { (options?: ajv.Options): ajv.Ajv; new (options?: ajv.Options): ajv.Ajv; + ValidationError: ValidationError; + MissingRefError: MissingRefError; + $dataMetaSchema: Object; } declare namespace ajv { interface Ajv { /** * Validate data using schema - * Schema will be compiled and cached (using serialized JSON as key, [json-stable-stringify](https://github.com/substack/json-stable-stringify) is used to serialize by default). + * 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 {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`). @@ -33,15 +36,17 @@ declare namespace ajv { * 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`. + * @return {Ajv} this for method chaining */ - addSchema(schema: Array<Object> | Object, key?: string): void; + 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 + * @return {Ajv} this for method chaining */ - addMetaSchema(schema: Object, key?: string): void; + addMetaSchema(schema: Object, key?: string): Ajv; /** * Validate schema * @param {Object|Boolean} schema schema to validate @@ -60,21 +65,24 @@ declare namespace ajv { * 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 + * @return {Ajv} this for method chaining */ - removeSchema(schemaKeyRef?: Object | string | RegExp | boolean): void; + 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) + * @return {Ajv} this for method chaining */ - addFormat(name: string, format: FormatValidator | FormatDefinition): void; + 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`. + * @return {Ajv} this for method chaining */ - addKeyword(keyword: string, definition: KeywordDefinition): void; + addKeyword(keyword: string, definition: KeywordDefinition): Ajv; /** * Get keyword definition * @this Ajv @@ -86,8 +94,9 @@ declare namespace ajv { * Remove keyword * @this Ajv * @param {String} keyword pre-defined or custom keyword. + * @return {Ajv} this for method chaining */ - removeKeyword(keyword: string): void; + 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. @@ -110,8 +119,13 @@ declare namespace ajv { parentDataProperty?: string | number, rootData?: Object | Array<any> ): boolean | Thenable<any>; - errors?: Array<ErrorObject>; schema?: Object | boolean; + errors?: null | Array<ErrorObject>; + refs?: Object; + refVal?: Array<any>; + root?: ValidateFunction | Object; + $async?: true; + source?: Object; } interface Options { @@ -149,7 +163,7 @@ declare namespace ajv { cache?: Object; } - type FormatValidator = string | RegExp | ((data: string) => boolean); + type FormatValidator = string | RegExp | ((data: string) => boolean | Thenable<any>); interface FormatDefinition { validate: FormatValidator; @@ -293,4 +307,22 @@ declare namespace ajv { } } +declare class ValidationError extends Error { + constructor(errors: Array<ajv.ErrorObject>); + + message: string; + errors: Array<ajv.ErrorObject>; + ajv: true; + validation: true; +} + +declare class MissingRefError extends Error { + constructor(baseId: string, ref: string, message?: string); + static message: (baseId: string, ref: string) => string; + + message: string; + missingRef: string; + missingSchema: string; +} + export = ajv; diff --git a/node_modules/ajv/lib/ajv.js b/node_modules/ajv/lib/ajv.js index 14095599e..3148b8e37 100644 --- a/node_modules/ajv/lib/ajv.js +++ b/node_modules/ajv/lib/ajv.js @@ -4,7 +4,7 @@ var compileSchema = require('./compile') , resolve = require('./compile/resolve') , Cache = require('./cache') , SchemaObject = require('./compile/schema_obj') - , stableStringify = require('json-stable-stringify') + , stableStringify = require('fast-json-stable-stringify') , formats = require('./compile/formats') , rules = require('./compile/rules') , $dataMetaSchema = require('./$data') @@ -52,6 +52,7 @@ var META_SUPPORT_DATA = ['/properties']; function Ajv(opts) { if (!(this instanceof Ajv)) return new Ajv(opts); opts = this._opts = util.copy(opts) || {}; + setLogger(this); this._schemas = {}; this._refs = {}; this._fragments = {}; @@ -81,7 +82,7 @@ function Ajv(opts) { /** * Validate data using schema - * Schema will be compiled and cached (using serialized JSON as key. [json-stable-stringify](https://github.com/substack/json-stable-stringify) is used to serialize. + * 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. * @this Ajv * @param {String|Object} schemaKeyRef key, ref or schema object * @param {Any} data to be validated @@ -125,11 +126,12 @@ function compile(schema, _meta) { * @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 {Boolean} _skipValidation true to skip schema validation. Used internally, option validateSchema should be used instead. * @param {Boolean} _meta true if schema is a meta-schema. Used internally, addMetaSchema should be used instead. + * @return {Ajv} this for method chaining */ function addSchema(schema, key, _skipValidation, _meta) { if (Array.isArray(schema)){ for (var i=0; i<schema.length; i++) this.addSchema(schema[i], undefined, _skipValidation, _meta); - return; + return this; } var id = this._getId(schema); if (id !== undefined && typeof id != 'string') @@ -137,6 +139,7 @@ function addSchema(schema, key, _skipValidation, _meta) { key = resolve.normalizeId(key || id); checkUnique(this, key); this._schemas[key] = this._addSchema(schema, _skipValidation, _meta, true); + return this; } @@ -147,9 +150,11 @@ function addSchema(schema, key, _skipValidation, _meta) { * @param {Object} schema schema object * @param {String} key optional schema key * @param {Boolean} skipValidation true to skip schema validation, can be used to override validateSchema option for meta-schema + * @return {Ajv} this for method chaining */ function addMetaSchema(schema, key, skipValidation) { this.addSchema(schema, key, skipValidation, true); + return this; } @@ -166,7 +171,7 @@ function validateSchema(schema, throwOrLogError) { throw new Error('$schema must be a string'); $schema = $schema || this._opts.defaultMeta || defaultMeta(this); if (!$schema) { - console.warn('meta-schema not available'); + this.logger.warn('meta-schema not available'); this.errors = null; return true; } @@ -179,7 +184,7 @@ function validateSchema(schema, throwOrLogError) { finally { this._formats.uri = currentUriFormat; } if (!valid && throwOrLogError) { var message = 'schema is invalid: ' + this.errorsText(); - if (this._opts.validateSchema == 'log') console.error(message); + if (this._opts.validateSchema == 'log') this.logger.error(message); else throw new Error(message); } return valid; @@ -246,25 +251,26 @@ function _getSchemaObj(self, keyRef) { * Even if schema is referenced by other schemas it still can be removed as other schemas have local references. * @this Ajv * @param {String|Object|RegExp} schemaKeyRef key, ref, pattern to match key/ref or schema object + * @return {Ajv} this for method chaining */ function removeSchema(schemaKeyRef) { if (schemaKeyRef instanceof RegExp) { _removeAllSchemas(this, this._schemas, schemaKeyRef); _removeAllSchemas(this, this._refs, schemaKeyRef); - return; + return this; } switch (typeof schemaKeyRef) { case 'undefined': _removeAllSchemas(this, this._schemas); _removeAllSchemas(this, this._refs); this._cache.clear(); - return; + return this; case 'string': var schemaObj = _getSchemaObj(this, schemaKeyRef); if (schemaObj) this._cache.del(schemaObj.cacheKey); delete this._schemas[schemaKeyRef]; delete this._refs[schemaKeyRef]; - return; + return this; case 'object': var serialize = this._opts.serialize; var cacheKey = serialize ? serialize(schemaKeyRef) : schemaKeyRef; @@ -276,6 +282,7 @@ function removeSchema(schemaKeyRef) { delete this._refs[id]; } } + return this; } @@ -378,15 +385,15 @@ function chooseGetId(opts) { } } - +/* @this Ajv */ function _getId(schema) { - if (schema.$id) console.warn('schema $id ignored', schema.$id); + if (schema.$id) this.logger.warn('schema $id ignored', schema.$id); return schema.id; } - +/* @this Ajv */ function _get$Id(schema) { - if (schema.id) console.warn('schema id ignored', schema.id); + if (schema.id) this.logger.warn('schema id ignored', schema.id); return schema.$id; } @@ -426,10 +433,12 @@ function errorsText(errors, options) { * @this Ajv * @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 */ function addFormat(name, format) { if (typeof format == 'string') format = new RegExp(format); this._formats[name] = format; + return this; } @@ -475,3 +484,19 @@ function getMetaSchemaOptions(self) { delete metaOpts[META_IGNORE_OPTIONS[i]]; return metaOpts; } + + +function setLogger(self) { + var logger = self._opts.logger; + if (logger === false) { + self.logger = {log: noop, warn: noop, error: noop}; + } else { + if (logger === undefined) logger = console; + if (!(typeof logger == 'object' && logger.log && logger.warn && logger.error)) + throw new Error('logger must implement log, warn and error methods'); + self.logger = logger; + } +} + + +function noop() {} diff --git a/node_modules/ajv/lib/compile/index.js b/node_modules/ajv/lib/compile/index.js index 45e35d905..cf4f5b86b 100644 --- a/node_modules/ajv/lib/compile/index.js +++ b/node_modules/ajv/lib/compile/index.js @@ -3,7 +3,7 @@ var resolve = require('./resolve') , util = require('./util') , errorClasses = require('./error_classes') - , stableStringify = require('json-stable-stringify'); + , stableStringify = require('fast-json-stable-stringify'); var validateGenerator = require('../dotjs/validate'); @@ -104,6 +104,7 @@ function compile(schema, root, localRefs, baseId) { useCustomRule: useCustomRule, opts: opts, formats: formats, + logger: self.logger, self: self }); @@ -146,7 +147,7 @@ function compile(schema, root, localRefs, baseId) { refVal[0] = validate; } catch(e) { - console.error('Error compiling schema, function code:', sourceCode); + self.logger.error('Error compiling schema, function code:', sourceCode); throw e; } @@ -260,7 +261,7 @@ function compile(schema, root, localRefs, baseId) { var valid = validateSchema(schema); if (!valid) { var message = 'keyword schema is invalid: ' + self.errorsText(validateSchema.errors); - if (self._opts.validateSchema == 'log') console.error(message); + if (self._opts.validateSchema == 'log') self.logger.error(message); else throw new Error(message); } } diff --git a/node_modules/ajv/lib/compile/rules.js b/node_modules/ajv/lib/compile/rules.js index eaeab77fa..44830ad72 100644 --- a/node_modules/ajv/lib/compile/rules.js +++ b/node_modules/ajv/lib/compile/rules.js @@ -20,7 +20,7 @@ module.exports = function rules() { var ALL = [ 'type' ]; var KEYWORDS = [ - 'additionalItems', '$schema', 'id', 'title', + 'additionalItems', '$schema', '$id', 'id', 'title', 'description', 'default', 'definitions' ]; var TYPES = [ 'number', 'integer', 'string', 'array', 'object', 'boolean', 'null' ]; diff --git a/node_modules/ajv/lib/dot/format.jst b/node_modules/ajv/lib/dot/format.jst index 074d16c31..484dddf79 100644 --- a/node_modules/ajv/lib/dot/format.jst +++ b/node_modules/ajv/lib/dot/format.jst @@ -71,7 +71,7 @@ {{ var $format = it.formats[$schema]; }} {{? !$format }} {{? $unknownFormats == 'ignore' }} - {{ console.warn('unknown format "' + $schema + '" ignored in schema at path "' + it.errSchemaPath + '"'); }} + {{ it.logger.warn('unknown format "' + $schema + '" ignored in schema at path "' + it.errSchemaPath + '"'); }} {{# def.skipFormat }} {{?? $allowUnknown && $unknownFormats.indexOf($schema) >= 0 }} {{# def.skipFormat }} diff --git a/node_modules/ajv/lib/dot/ref.jst b/node_modules/ajv/lib/dot/ref.jst index 4a0889686..036bc2905 100644 --- a/node_modules/ajv/lib/dot/ref.jst +++ b/node_modules/ajv/lib/dot/ref.jst @@ -27,11 +27,11 @@ {{? $refVal === undefined }} {{ var $message = it.MissingRefError.message(it.baseId, $schema); }} {{? it.opts.missingRefs == 'fail' }} - {{ console.error($message); }} + {{ it.logger.error($message); }} {{# def.error:'$ref' }} {{? $breakOnError }} if (false) { {{?}} {{?? it.opts.missingRefs == 'ignore' }} - {{ console.warn($message); }} + {{ it.logger.warn($message); }} {{? $breakOnError }} if (true) { {{?}} {{??}} {{ throw new it.MissingRefError(it.baseId, $schema, $message); }} diff --git a/node_modules/ajv/lib/dot/validate.jst b/node_modules/ajv/lib/dot/validate.jst index 4ebc599c0..273e4c37e 100644 --- a/node_modules/ajv/lib/dot/validate.jst +++ b/node_modules/ajv/lib/dot/validate.jst @@ -140,7 +140,7 @@ {{?? it.opts.extendRefs !== true }} {{ $refKeywords = false; - console.warn('$ref: keywords ignored in schema at path "' + it.errSchemaPath + '"'); + it.logger.warn('$ref: keywords ignored in schema at path "' + it.errSchemaPath + '"'); }} {{?}} {{?}} @@ -177,7 +177,7 @@ {{?}} {{??}} {{? it.opts.v5 && it.schema.patternGroups }} - {{ console.warn('keyword "patternGroups" is deprecated and disabled. Use option patternGroups: true to enable.'); }} + {{ it.logger.warn('keyword "patternGroups" is deprecated and disabled. Use option patternGroups: true to enable.'); }} {{?}} {{~ it.RULES:$rulesGroup }} {{? $shouldUseGroup($rulesGroup) }} @@ -260,10 +260,10 @@ function $shouldUseRule($rule) { return it.schema[$rule.keyword] !== undefined || - ($rule.implements && $ruleImlementsSomeKeyword($rule)); + ($rule.implements && $ruleImplementsSomeKeyword($rule)); } - function $ruleImlementsSomeKeyword($rule) { + function $ruleImplementsSomeKeyword($rule) { var impl = $rule.implements; for (var i=0; i < impl.length; i++) if (it.schema[impl[i]] !== undefined) diff --git a/node_modules/ajv/lib/dotjs/format.js b/node_modules/ajv/lib/dotjs/format.js index eb13371c1..68697f0de 100644 --- a/node_modules/ajv/lib/dotjs/format.js +++ b/node_modules/ajv/lib/dotjs/format.js @@ -55,7 +55,7 @@ module.exports = function generate_format(it, $keyword, $ruleType) { var $format = it.formats[$schema]; if (!$format) { if ($unknownFormats == 'ignore') { - console.warn('unknown format "' + $schema + '" ignored in schema at path "' + it.errSchemaPath + '"'); + it.logger.warn('unknown format "' + $schema + '" ignored in schema at path "' + it.errSchemaPath + '"'); if ($breakOnError) { out += ' if (true) { '; } diff --git a/node_modules/ajv/lib/dotjs/ref.js b/node_modules/ajv/lib/dotjs/ref.js index 6fb950546..a9d7bb909 100644 --- a/node_modules/ajv/lib/dotjs/ref.js +++ b/node_modules/ajv/lib/dotjs/ref.js @@ -22,7 +22,7 @@ module.exports = function generate_ref(it, $keyword, $ruleType) { if ($refVal === undefined) { var $message = it.MissingRefError.message(it.baseId, $schema); if (it.opts.missingRefs == 'fail') { - console.error($message); + it.logger.error($message); var $$outStack = $$outStack || []; $$outStack.push(out); out = ''; /* istanbul ignore else */ @@ -53,7 +53,7 @@ module.exports = function generate_ref(it, $keyword, $ruleType) { out += ' if (false) { '; } } else if (it.opts.missingRefs == 'ignore') { - console.warn($message); + it.logger.warn($message); if ($breakOnError) { out += ' if (true) { '; } diff --git a/node_modules/ajv/lib/dotjs/validate.js b/node_modules/ajv/lib/dotjs/validate.js index 0ff9eda42..5ff9beee7 100644 --- a/node_modules/ajv/lib/dotjs/validate.js +++ b/node_modules/ajv/lib/dotjs/validate.js @@ -123,7 +123,7 @@ module.exports = function generate_validate(it, $keyword, $ruleType) { throw new Error('$ref: validation keywords used in schema at path "' + it.errSchemaPath + '" (see option extendRefs)'); } else if (it.opts.extendRefs !== true) { $refKeywords = false; - console.warn('$ref: keywords ignored in schema at path "' + it.errSchemaPath + '"'); + it.logger.warn('$ref: keywords ignored in schema at path "' + it.errSchemaPath + '"'); } } if ($typeSchema) { @@ -281,7 +281,7 @@ module.exports = function generate_validate(it, $keyword, $ruleType) { } } else { if (it.opts.v5 && it.schema.patternGroups) { - console.warn('keyword "patternGroups" is deprecated and disabled. Use option patternGroups: true to enable.'); + it.logger.warn('keyword "patternGroups" is deprecated and disabled. Use option patternGroups: true to enable.'); } var arr2 = it.RULES; if (arr2) { @@ -446,10 +446,10 @@ module.exports = function generate_validate(it, $keyword, $ruleType) { } function $shouldUseRule($rule) { - return it.schema[$rule.keyword] !== undefined || ($rule.implements && $ruleImlementsSomeKeyword($rule)); + return it.schema[$rule.keyword] !== undefined || ($rule.implements && $ruleImplementsSomeKeyword($rule)); } - function $ruleImlementsSomeKeyword($rule) { + function $ruleImplementsSomeKeyword($rule) { var impl = $rule.implements; for (var i = 0; i < impl.length; i++) if (it.schema[impl[i]] !== undefined) return true; diff --git a/node_modules/ajv/lib/keyword.js b/node_modules/ajv/lib/keyword.js index 85e64c600..5fcfb75fc 100644 --- a/node_modules/ajv/lib/keyword.js +++ b/node_modules/ajv/lib/keyword.js @@ -14,6 +14,7 @@ module.exports = { * @this Ajv * @param {String} keyword custom keyword, should be unique (including 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 */ function addKeyword(keyword, definition) { /* jshint validthis: true */ @@ -91,6 +92,8 @@ function addKeyword(keyword, definition) { function checkDataType(dataType) { if (!RULES.types[dataType]) throw new Error('Unknown type ' + dataType); } + + return this; } @@ -111,6 +114,7 @@ function getKeyword(keyword) { * Remove keyword * @this Ajv * @param {String} keyword pre-defined or custom keyword. + * @return {Ajv} this for method chaining */ function removeKeyword(keyword) { /* jshint validthis: true */ @@ -127,4 +131,5 @@ function removeKeyword(keyword) { } } } + return this; } diff --git a/node_modules/ajv/lib/refs/json-schema-draft-06.json b/node_modules/ajv/lib/refs/json-schema-draft-06.json index 621cc5102..5656240b9 100644 --- a/node_modules/ajv/lib/refs/json-schema-draft-06.json +++ b/node_modules/ajv/lib/refs/json-schema-draft-06.json @@ -57,6 +57,10 @@ "type": "string" }, "default": {}, + "examples": { + "type": "array", + "items": {} + }, "multipleOf": { "type": "number", "exclusiveMinimum": 0 |