1 (function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.Ajv = f()}})(function(){var define,module,exports;return (function(){function r(e,n,t){function o(i,f){if(!n[i]){if(!e[i]){var c="function"==typeof require&&require;if(!f&&c)return c(i,!0);if(u)return u(i,!0);var a=new Error("Cannot find module '"+i+"'");throw a.code="MODULE_NOT_FOUND",a}var p=n[i]={exports:{}};e[i][0].call(p.exports,function(r){var n=e[i][1][r];return o(n||r)},p,p.exports,r,e,n,t)}return n[i].exports}for(var u="function"==typeof require&&require,i=0;i<t.length;i++)o(t[i]);return o}return r})()({1:[function(require,module,exports){
5 var Cache = module.exports = function Cache() {
10 Cache.prototype.put = function Cache_put(key, value) {
11 this._cache[key] = value;
15 Cache.prototype.get = function Cache_get(key) {
16 return this._cache[key];
20 Cache.prototype.del = function Cache_del(key) {
21 delete this._cache[key];
25 Cache.prototype.clear = function Cache_clear() {
29 },{}],2:[function(require,module,exports){
32 var MissingRefError = require('./error_classes').MissingRef;
34 module.exports = compileAsync;
38 * Creates validating function for passed schema with asynchronous loading of missing schemas.
39 * `loadSchema` option should be a function that accepts schema uri and returns promise that resolves with the schema.
41 * @param {Object} schema schema object
42 * @param {Boolean} meta optional true to compile meta-schema; this parameter can be skipped
43 * @param {Function} callback an optional node-style callback, it is called with 2 parameters: error (or null) and validating function.
44 * @return {Promise} promise that resolves with a validating function.
46 function compileAsync(schema, meta, callback) {
47 /* eslint no-shadow: 0 */
49 /* jshint validthis: true */
51 if (typeof this._opts.loadSchema != 'function')
52 throw new Error('options.loadSchema should be a function');
54 if (typeof meta == 'function') {
59 var p = loadMetaSchemaOf(schema).then(function () {
60 var schemaObj = self._addSchema(schema, undefined, meta);
61 return schemaObj.validate || _compileAsync(schemaObj);
66 function(v) { callback(null, v); },
74 function loadMetaSchemaOf(sch) {
75 var $schema = sch.$schema;
76 return $schema && !self.getSchema($schema)
77 ? compileAsync.call(self, { $ref: $schema }, true)
82 function _compileAsync(schemaObj) {
83 try { return self._compile(schemaObj); }
85 if (e instanceof MissingRefError) return loadMissingSchema(e);
90 function loadMissingSchema(e) {
91 var ref = e.missingSchema;
92 if (added(ref)) throw new Error('Schema ' + ref + ' is loaded but ' + e.missingRef + ' cannot be resolved');
94 var schemaPromise = self._loadingSchemas[ref];
96 schemaPromise = self._loadingSchemas[ref] = self._opts.loadSchema(ref);
97 schemaPromise.then(removePromise, removePromise);
100 return schemaPromise.then(function (sch) {
102 return loadMetaSchemaOf(sch).then(function () {
103 if (!added(ref)) self.addSchema(sch, ref, undefined, meta);
107 return _compileAsync(schemaObj);
110 function removePromise() {
111 delete self._loadingSchemas[ref];
114 function added(ref) {
115 return self._refs[ref] || self._schemas[ref];
121 },{"./error_classes":3}],3:[function(require,module,exports){
124 var resolve = require('./resolve');
127 Validation: errorSubclass(ValidationError),
128 MissingRef: errorSubclass(MissingRefError)
132 function ValidationError(errors) {
133 this.message = 'validation failed';
134 this.errors = errors;
135 this.ajv = this.validation = true;
139 MissingRefError.message = function (baseId, ref) {
140 return 'can\'t resolve reference ' + ref + ' from id ' + baseId;
144 function MissingRefError(baseId, ref, message) {
145 this.message = message || MissingRefError.message(baseId, ref);
146 this.missingRef = resolve.url(baseId, ref);
147 this.missingSchema = resolve.normalizeId(resolve.fullPath(this.missingRef));
151 function errorSubclass(Subclass) {
152 Subclass.prototype = Object.create(Error.prototype);
153 Subclass.prototype.constructor = Subclass;
157 },{"./resolve":6}],4:[function(require,module,exports){
160 var util = require('./util');
162 var DATE = /^(\d\d\d\d)-(\d\d)-(\d\d)$/;
163 var DAYS = [0,31,28,31,30,31,30,31,31,30,31,30,31];
164 var TIME = /^(\d\d):(\d\d):(\d\d)(\.\d+)?(z|[+-]\d\d(?::?\d\d)?)?$/i;
165 var HOSTNAME = /^(?=.{1,253}\.?$)[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?(?:\.[a-z0-9](?:[-0-9a-z]{0,61}[0-9a-z])?)*\.?$/i;
166 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;
167 var URIREF = /^(?:[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;
168 // uri-template: https://tools.ietf.org/html/rfc6570
169 var URITEMPLATE = /^(?:(?:[^\x00-\x20"'<>%\\^`{|}]|%[0-9a-f]{2})|\{[+#./;?&=,!@|]?(?:[a-z0-9_]|%[0-9a-f]{2})+(?::[1-9][0-9]{0,3}|\*)?(?:,(?:[a-z0-9_]|%[0-9a-f]{2})+(?::[1-9][0-9]{0,3}|\*)?)*\})*$/i;
170 // For the source: https://gist.github.com/dperini/729294
171 // For test cases: https://mathiasbynens.be/demo/url-regex
172 // @todo Delete current URL in favour of the commented out URL rule when this issue is fixed https://github.com/eslint/eslint/issues/7983.
173 // 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;
174 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;
175 var UUID = /^(?:urn:uuid:)?[0-9a-f]{8}-(?:[0-9a-f]{4}-){3}[0-9a-f]{12}$/i;
176 var JSON_POINTER = /^(?:\/(?:[^~/]|~0|~1)*)*$/;
177 var JSON_POINTER_URI_FRAGMENT = /^#(?:\/(?:[a-z0-9_\-.!$&'()*+,;:=@]|%[0-9a-f]{2}|~0|~1)*)*$/i;
178 var RELATIVE_JSON_POINTER = /^(?:0|[1-9][0-9]*)(?:#|(?:\/(?:[^~/]|~0|~1)*)*)$/;
181 module.exports = formats;
183 function formats(mode) {
184 mode = mode == 'full' ? 'full' : 'fast';
185 return util.copy(formats[mode]);
190 // date: http://tools.ietf.org/html/rfc3339#section-5.6
191 date: /^\d\d\d\d-[0-1]\d-[0-3]\d$/,
192 // date-time: http://tools.ietf.org/html/rfc3339#section-5.6
193 time: /^(?:[0-2]\d:[0-5]\d:[0-5]\d|23:59:60)(?:\.\d+)?(?:z|[+-]\d\d(?::?\d\d)?)?$/i,
194 '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,
195 // uri: https://github.com/mafintosh/is-my-json-valid/blob/master/formats.js
196 uri: /^(?:[a-z][a-z0-9+-.]*:)(?:\/?\/)?[^\s]*$/i,
197 'uri-reference': /^(?:(?:[a-z][a-z0-9+-.]*:)?\/?\/)?(?:[^\\\s#][^\s#]*)?(?:#[^\\\s]*)?$/i,
198 'uri-template': URITEMPLATE,
200 // email (sources from jsen validator):
201 // http://stackoverflow.com/questions/201323/using-a-regular-expression-to-validate-an-email-address#answer-8829363
202 // http://www.w3.org/TR/html5/forms.html#valid-e-mail-address (search for 'willful violation')
203 email: /^[a-z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?(?:\.[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?)*$/i,
205 // optimized https://www.safaribooksonline.com/library/view/regular-expressions-cookbook/9780596802837/ch07s16.html
206 ipv4: /^(?:(?:25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(?:25[0-5]|2[0-4]\d|[01]?\d\d?)$/,
207 // optimized http://stackoverflow.com/questions/53497/regular-expression-that-matches-valid-ipv6-addresses
208 ipv6: /^\s*(?:(?:(?:[0-9a-f]{1,4}:){7}(?:[0-9a-f]{1,4}|:))|(?:(?:[0-9a-f]{1,4}:){6}(?::[0-9a-f]{1,4}|(?:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(?:\.(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3})|:))|(?:(?:[0-9a-f]{1,4}:){5}(?:(?:(?::[0-9a-f]{1,4}){1,2})|:(?:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(?:\.(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3})|:))|(?:(?:[0-9a-f]{1,4}:){4}(?:(?:(?::[0-9a-f]{1,4}){1,3})|(?:(?::[0-9a-f]{1,4})?:(?:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(?:\.(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(?:(?:[0-9a-f]{1,4}:){3}(?:(?:(?::[0-9a-f]{1,4}){1,4})|(?:(?::[0-9a-f]{1,4}){0,2}:(?:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(?:\.(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(?:(?:[0-9a-f]{1,4}:){2}(?:(?:(?::[0-9a-f]{1,4}){1,5})|(?:(?::[0-9a-f]{1,4}){0,3}:(?:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(?:\.(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(?:(?:[0-9a-f]{1,4}:){1}(?:(?:(?::[0-9a-f]{1,4}){1,6})|(?:(?::[0-9a-f]{1,4}){0,4}:(?:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(?:\.(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(?::(?:(?:(?::[0-9a-f]{1,4}){1,7})|(?:(?::[0-9a-f]{1,4}){0,5}:(?:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(?:\.(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:)))(?:%.+)?\s*$/i,
210 // uuid: http://tools.ietf.org/html/rfc4122
212 // JSON-pointer: https://tools.ietf.org/html/rfc6901
213 // uri fragment: https://tools.ietf.org/html/rfc3986#appendix-A
214 'json-pointer': JSON_POINTER,
215 'json-pointer-uri-fragment': JSON_POINTER_URI_FRAGMENT,
216 // relative JSON-pointer: http://tools.ietf.org/html/draft-luff-relative-json-pointer-00
217 'relative-json-pointer': RELATIVE_JSON_POINTER
224 'date-time': date_time,
226 'uri-reference': URIREF,
227 'uri-template': URITEMPLATE,
229 email: /^[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?$/i,
231 ipv4: /^(?:(?:25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(?:25[0-5]|2[0-4]\d|[01]?\d\d?)$/,
232 ipv6: /^\s*(?:(?:(?:[0-9a-f]{1,4}:){7}(?:[0-9a-f]{1,4}|:))|(?:(?:[0-9a-f]{1,4}:){6}(?::[0-9a-f]{1,4}|(?:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(?:\.(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3})|:))|(?:(?:[0-9a-f]{1,4}:){5}(?:(?:(?::[0-9a-f]{1,4}){1,2})|:(?:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(?:\.(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3})|:))|(?:(?:[0-9a-f]{1,4}:){4}(?:(?:(?::[0-9a-f]{1,4}){1,3})|(?:(?::[0-9a-f]{1,4})?:(?:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(?:\.(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(?:(?:[0-9a-f]{1,4}:){3}(?:(?:(?::[0-9a-f]{1,4}){1,4})|(?:(?::[0-9a-f]{1,4}){0,2}:(?:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(?:\.(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(?:(?:[0-9a-f]{1,4}:){2}(?:(?:(?::[0-9a-f]{1,4}){1,5})|(?:(?::[0-9a-f]{1,4}){0,3}:(?:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(?:\.(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(?:(?:[0-9a-f]{1,4}:){1}(?:(?:(?::[0-9a-f]{1,4}){1,6})|(?:(?::[0-9a-f]{1,4}){0,4}:(?:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(?:\.(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(?::(?:(?:(?::[0-9a-f]{1,4}){1,7})|(?:(?::[0-9a-f]{1,4}){0,5}:(?:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(?:\.(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:)))(?:%.+)?\s*$/i,
235 'json-pointer': JSON_POINTER,
236 'json-pointer-uri-fragment': JSON_POINTER_URI_FRAGMENT,
237 'relative-json-pointer': RELATIVE_JSON_POINTER
241 function isLeapYear(year) {
242 // https://tools.ietf.org/html/rfc3339#appendix-C
243 return year % 4 === 0 && (year % 100 !== 0 || year % 400 === 0);
248 // full-date from http://tools.ietf.org/html/rfc3339#section-5.6
249 var matches = str.match(DATE);
250 if (!matches) return false;
252 var year = +matches[1];
253 var month = +matches[2];
254 var day = +matches[3];
256 return month >= 1 && month <= 12 && day >= 1 &&
257 day <= (month == 2 && isLeapYear(year) ? 29 : DAYS[month]);
261 function time(str, full) {
262 var matches = str.match(TIME);
263 if (!matches) return false;
265 var hour = matches[1];
266 var minute = matches[2];
267 var second = matches[3];
268 var timeZone = matches[5];
269 return ((hour <= 23 && minute <= 59 && second <= 59) ||
270 (hour == 23 && minute == 59 && second == 60)) &&
275 var DATE_TIME_SEPARATOR = /t|\s/i;
276 function date_time(str) {
277 // http://tools.ietf.org/html/rfc3339#section-5.6
278 var dateTime = str.split(DATE_TIME_SEPARATOR);
279 return dateTime.length == 2 && date(dateTime[0]) && time(dateTime[1], true);
283 var NOT_URI_FRAGMENT = /\/|:/;
285 // http://jmrware.com/articles/2009/uri_regexp/URI_regex.html + optional protocol + required "."
286 return NOT_URI_FRAGMENT.test(str) && URI.test(str);
290 var Z_ANCHOR = /[^\\]\\Z/;
291 function regex(str) {
292 if (Z_ANCHOR.test(str)) return false;
301 },{"./util":10}],5:[function(require,module,exports){
304 var resolve = require('./resolve')
305 , util = require('./util')
306 , errorClasses = require('./error_classes')
307 , stableStringify = require('fast-json-stable-stringify');
309 var validateGenerator = require('../dotjs/validate');
312 * Functions below are used inside compiled validations function
315 var ucs2length = util.ucs2length;
316 var equal = require('fast-deep-equal');
318 // this error is thrown by async schemas to return validation errors via exception
319 var ValidationError = errorClasses.Validation;
321 module.exports = compile;
325 * Compiles schema to validation function
327 * @param {Object} schema schema object
328 * @param {Object} root object with information about the root schema for this schema
329 * @param {Object} localRefs the hash of local references inside the schema (created by resolve.id), used for inline resolution
330 * @param {String} baseId base ID for IDs in the schema
331 * @return {Function} validation function
333 function compile(schema, root, localRefs, baseId) {
334 /* jshint validthis: true, evil: true */
335 /* eslint no-shadow: 0 */
338 , refVal = [ undefined ]
346 root = root || { schema: schema, refVal: refVal, refs: refs };
348 var c = checkCompiling.call(this, schema, root, baseId);
349 var compilation = this._compilations[c.index];
350 if (c.compiling) return (compilation.callValidate = callValidate);
352 var formats = this._formats;
353 var RULES = this.RULES;
356 var v = localCompile(schema, root, localRefs, baseId);
357 compilation.validate = v;
358 var cv = compilation.callValidate;
360 cv.schema = v.schema;
363 cv.refVal = v.refVal;
365 cv.$async = v.$async;
366 if (opts.sourceCode) cv.source = v.source;
370 endCompiling.call(this, schema, root, baseId);
373 /* @this {*} - custom context, see passContext option */
374 function callValidate() {
375 /* jshint validthis: true */
376 var validate = compilation.validate;
377 var result = validate.apply(this, arguments);
378 callValidate.errors = validate.errors;
382 function localCompile(_schema, _root, localRefs, baseId) {
383 var isRoot = !_root || (_root && _root.schema == _schema);
384 if (_root.schema != root.schema)
385 return compile.call(self, _schema, _root, localRefs, baseId);
387 var $async = _schema.$async === true;
389 var sourceCode = validateGenerator({
398 MissingRefError: errorClasses.MissingRef,
400 validate: validateGenerator,
403 resolveRef: resolveRef,
404 usePattern: usePattern,
405 useDefault: useDefault,
406 useCustomRule: useCustomRule,
413 sourceCode = vars(refVal, refValCode) + vars(patterns, patternCode)
414 + vars(defaults, defaultCode) + vars(customRules, customRuleCode)
417 if (opts.processCode) sourceCode = opts.processCode(sourceCode, _schema);
418 // console.log('\n\n\n *** \n', JSON.stringify(sourceCode));
421 var makeValidate = new Function(
435 validate = makeValidate(
448 refVal[0] = validate;
450 self.logger.error('Error compiling schema, function code:', sourceCode);
454 validate.schema = _schema;
455 validate.errors = null;
456 validate.refs = refs;
457 validate.refVal = refVal;
458 validate.root = isRoot ? validate : _root;
459 if ($async) validate.$async = true;
460 if (opts.sourceCode === true) {
471 function resolveRef(baseId, ref, isRoot) {
472 ref = resolve.url(baseId, ref);
473 var refIndex = refs[ref];
474 var _refVal, refCode;
475 if (refIndex !== undefined) {
476 _refVal = refVal[refIndex];
477 refCode = 'refVal[' + refIndex + ']';
478 return resolvedRef(_refVal, refCode);
480 if (!isRoot && root.refs) {
481 var rootRefId = root.refs[ref];
482 if (rootRefId !== undefined) {
483 _refVal = root.refVal[rootRefId];
484 refCode = addLocalRef(ref, _refVal);
485 return resolvedRef(_refVal, refCode);
489 refCode = addLocalRef(ref);
490 var v = resolve.call(self, localCompile, root, ref);
491 if (v === undefined) {
492 var localSchema = localRefs && localRefs[ref];
494 v = resolve.inlineRef(localSchema, opts.inlineRefs)
496 : compile.call(self, localSchema, root, localRefs, baseId);
500 if (v === undefined) {
503 replaceLocalRef(ref, v);
504 return resolvedRef(v, refCode);
508 function addLocalRef(ref, v) {
509 var refId = refVal.length;
512 return 'refVal' + refId;
515 function removeLocalRef(ref) {
519 function replaceLocalRef(ref, v) {
520 var refId = refs[ref];
524 function resolvedRef(refVal, code) {
525 return typeof refVal == 'object' || typeof refVal == 'boolean'
526 ? { code: code, schema: refVal, inline: true }
527 : { code: code, $async: refVal && !!refVal.$async };
530 function usePattern(regexStr) {
531 var index = patternsHash[regexStr];
532 if (index === undefined) {
533 index = patternsHash[regexStr] = patterns.length;
534 patterns[index] = regexStr;
536 return 'pattern' + index;
539 function useDefault(value) {
540 switch (typeof value) {
545 return util.toQuotedString(value);
547 if (value === null) return 'null';
548 var valueStr = stableStringify(value);
549 var index = defaultsHash[valueStr];
550 if (index === undefined) {
551 index = defaultsHash[valueStr] = defaults.length;
552 defaults[index] = value;
554 return 'default' + index;
558 function useCustomRule(rule, schema, parentSchema, it) {
559 if (self._opts.validateSchema !== false) {
560 var deps = rule.definition.dependencies;
561 if (deps && !deps.every(function(keyword) {
562 return Object.prototype.hasOwnProperty.call(parentSchema, keyword);
564 throw new Error('parent schema must have all required keywords: ' + deps.join(','));
566 var validateSchema = rule.definition.validateSchema;
567 if (validateSchema) {
568 var valid = validateSchema(schema);
570 var message = 'keyword schema is invalid: ' + self.errorsText(validateSchema.errors);
571 if (self._opts.validateSchema == 'log') self.logger.error(message);
572 else throw new Error(message);
577 var compile = rule.definition.compile
578 , inline = rule.definition.inline
579 , macro = rule.definition.macro;
583 validate = compile.call(self, schema, parentSchema, it);
585 validate = macro.call(self, schema, parentSchema, it);
586 if (opts.validateSchema !== false) self.validateSchema(validate, true);
588 validate = inline.call(self, it, rule.keyword, schema, parentSchema);
590 validate = rule.definition.validate;
591 if (!validate) return;
594 if (validate === undefined)
595 throw new Error('custom keyword "' + rule.keyword + '"failed to compile');
597 var index = customRules.length;
598 customRules[index] = validate;
601 code: 'customRule' + index,
609 * Checks if the schema is currently compiled
611 * @param {Object} schema schema to compile
612 * @param {Object} root root object
613 * @param {String} baseId base schema ID
614 * @return {Object} object with properties "index" (compilation index) and "compiling" (boolean)
616 function checkCompiling(schema, root, baseId) {
617 /* jshint validthis: true */
618 var index = compIndex.call(this, schema, root, baseId);
619 if (index >= 0) return { index: index, compiling: true };
620 index = this._compilations.length;
621 this._compilations[index] = {
626 return { index: index, compiling: false };
631 * Removes the schema from the currently compiled list
633 * @param {Object} schema schema to compile
634 * @param {Object} root root object
635 * @param {String} baseId base schema ID
637 function endCompiling(schema, root, baseId) {
638 /* jshint validthis: true */
639 var i = compIndex.call(this, schema, root, baseId);
640 if (i >= 0) this._compilations.splice(i, 1);
645 * Index of schema compilation in the currently compiled list
647 * @param {Object} schema schema to compile
648 * @param {Object} root root object
649 * @param {String} baseId base schema ID
650 * @return {Integer} compilation index
652 function compIndex(schema, root, baseId) {
653 /* jshint validthis: true */
654 for (var i=0; i<this._compilations.length; i++) {
655 var c = this._compilations[i];
656 if (c.schema == schema && c.root == root && c.baseId == baseId) return i;
662 function patternCode(i, patterns) {
663 return 'var pattern' + i + ' = new RegExp(' + util.toQuotedString(patterns[i]) + ');';
667 function defaultCode(i) {
668 return 'var default' + i + ' = defaults[' + i + '];';
672 function refValCode(i, refVal) {
673 return refVal[i] === undefined ? '' : 'var refVal' + i + ' = refVal[' + i + '];';
677 function customRuleCode(i) {
678 return 'var customRule' + i + ' = customRules[' + i + '];';
682 function vars(arr, statement) {
683 if (!arr.length) return '';
685 for (var i=0; i<arr.length; i++)
686 code += statement(i, arr);
690 },{"../dotjs/validate":38,"./error_classes":3,"./resolve":6,"./util":10,"fast-deep-equal":42,"fast-json-stable-stringify":43}],6:[function(require,module,exports){
693 var URI = require('uri-js')
694 , equal = require('fast-deep-equal')
695 , util = require('./util')
696 , SchemaObject = require('./schema_obj')
697 , traverse = require('json-schema-traverse');
699 module.exports = resolve;
701 resolve.normalizeId = normalizeId;
702 resolve.fullPath = getFullPath;
703 resolve.url = resolveUrl;
704 resolve.ids = resolveIds;
705 resolve.inlineRef = inlineRef;
706 resolve.schema = resolveSchema;
709 * [resolve and compile the references ($ref)]
711 * @param {Function} compile reference to schema compilation funciton (localCompile)
712 * @param {Object} root object with information about the root schema for the current schema
713 * @param {String} ref reference to resolve
714 * @return {Object|Function} schema object (if the schema can be inlined) or validation function
716 function resolve(compile, root, ref) {
717 /* jshint validthis: true */
718 var refVal = this._refs[ref];
719 if (typeof refVal == 'string') {
720 if (this._refs[refVal]) refVal = this._refs[refVal];
721 else return resolve.call(this, compile, root, refVal);
724 refVal = refVal || this._schemas[ref];
725 if (refVal instanceof SchemaObject) {
726 return inlineRef(refVal.schema, this._opts.inlineRefs)
728 : refVal.validate || this._compile(refVal);
731 var res = resolveSchema.call(this, root, ref);
732 var schema, v, baseId;
739 if (schema instanceof SchemaObject) {
740 v = schema.validate || compile.call(this, schema.schema, root, undefined, baseId);
741 } else if (schema !== undefined) {
742 v = inlineRef(schema, this._opts.inlineRefs)
744 : compile.call(this, schema, root, undefined, baseId);
752 * Resolve schema, its root and baseId
754 * @param {Object} root root object with properties schema, refVal, refs
755 * @param {String} ref reference to resolve
756 * @return {Object} object with properties schema, root, baseId
758 function resolveSchema(root, ref) {
759 /* jshint validthis: true */
760 var p = URI.parse(ref)
761 , refPath = _getFullPath(p)
762 , baseId = getFullPath(this._getId(root.schema));
763 if (Object.keys(root.schema).length === 0 || refPath !== baseId) {
764 var id = normalizeId(refPath);
765 var refVal = this._refs[id];
766 if (typeof refVal == 'string') {
767 return resolveRecursive.call(this, root, refVal, p);
768 } else if (refVal instanceof SchemaObject) {
769 if (!refVal.validate) this._compile(refVal);
772 refVal = this._schemas[id];
773 if (refVal instanceof SchemaObject) {
774 if (!refVal.validate) this._compile(refVal);
775 if (id == normalizeId(ref))
776 return { schema: refVal, root: root, baseId: baseId };
782 if (!root.schema) return;
783 baseId = getFullPath(this._getId(root.schema));
785 return getJsonPointer.call(this, p, baseId, root.schema, root);
790 function resolveRecursive(root, ref, parsedRef) {
791 /* jshint validthis: true */
792 var res = resolveSchema.call(this, root, ref);
794 var schema = res.schema;
795 var baseId = res.baseId;
797 var id = this._getId(schema);
798 if (id) baseId = resolveUrl(baseId, id);
799 return getJsonPointer.call(this, parsedRef, baseId, schema, root);
804 var PREVENT_SCOPE_CHANGE = util.toHash(['properties', 'patternProperties', 'enum', 'dependencies', 'definitions']);
806 function getJsonPointer(parsedRef, baseId, schema, root) {
807 /* jshint validthis: true */
808 parsedRef.fragment = parsedRef.fragment || '';
809 if (parsedRef.fragment.slice(0,1) != '/') return;
810 var parts = parsedRef.fragment.split('/');
812 for (var i = 1; i < parts.length; i++) {
815 part = util.unescapeFragment(part);
816 schema = schema[part];
817 if (schema === undefined) break;
819 if (!PREVENT_SCOPE_CHANGE[part]) {
820 id = this._getId(schema);
821 if (id) baseId = resolveUrl(baseId, id);
823 var $ref = resolveUrl(baseId, schema.$ref);
824 var res = resolveSchema.call(this, root, $ref);
834 if (schema !== undefined && schema !== root.schema)
835 return { schema: schema, root: root, baseId: baseId };
839 var SIMPLE_INLINED = util.toHash([
840 'type', 'format', 'pattern',
841 'maxLength', 'minLength',
842 'maxProperties', 'minProperties',
843 'maxItems', 'minItems',
844 'maximum', 'minimum',
845 'uniqueItems', 'multipleOf',
848 function inlineRef(schema, limit) {
849 if (limit === false) return false;
850 if (limit === undefined || limit === true) return checkNoRef(schema);
851 else if (limit) return countKeys(schema) <= limit;
855 function checkNoRef(schema) {
857 if (Array.isArray(schema)) {
858 for (var i=0; i<schema.length; i++) {
860 if (typeof item == 'object' && !checkNoRef(item)) return false;
863 for (var key in schema) {
864 if (key == '$ref') return false;
866 if (typeof item == 'object' && !checkNoRef(item)) return false;
873 function countKeys(schema) {
875 if (Array.isArray(schema)) {
876 for (var i=0; i<schema.length; i++) {
878 if (typeof item == 'object') count += countKeys(item);
879 if (count == Infinity) return Infinity;
882 for (var key in schema) {
883 if (key == '$ref') return Infinity;
884 if (SIMPLE_INLINED[key]) {
888 if (typeof item == 'object') count += countKeys(item) + 1;
889 if (count == Infinity) return Infinity;
897 function getFullPath(id, normalize) {
898 if (normalize !== false) id = normalizeId(id);
899 var p = URI.parse(id);
900 return _getFullPath(p);
904 function _getFullPath(p) {
905 return URI.serialize(p).split('#')[0] + '#';
909 var TRAILING_SLASH_HASH = /#\/?$/;
910 function normalizeId(id) {
911 return id ? id.replace(TRAILING_SLASH_HASH, '') : '';
915 function resolveUrl(baseId, id) {
916 id = normalizeId(id);
917 return URI.resolve(baseId, id);
922 function resolveIds(schema) {
923 var schemaId = normalizeId(this._getId(schema));
924 var baseIds = {'': schemaId};
925 var fullPaths = {'': getFullPath(schemaId, false)};
929 traverse(schema, {allKeys: true}, function(sch, jsonPtr, rootSchema, parentJsonPtr, parentKeyword, parentSchema, keyIndex) {
930 if (jsonPtr === '') return;
931 var id = self._getId(sch);
932 var baseId = baseIds[parentJsonPtr];
933 var fullPath = fullPaths[parentJsonPtr] + '/' + parentKeyword;
934 if (keyIndex !== undefined)
935 fullPath += '/' + (typeof keyIndex == 'number' ? keyIndex : util.escapeFragment(keyIndex));
937 if (typeof id == 'string') {
938 id = baseId = normalizeId(baseId ? URI.resolve(baseId, id) : id);
940 var refVal = self._refs[id];
941 if (typeof refVal == 'string') refVal = self._refs[refVal];
942 if (refVal && refVal.schema) {
943 if (!equal(sch, refVal.schema))
944 throw new Error('id "' + id + '" resolves to more than one schema');
945 } else if (id != normalizeId(fullPath)) {
947 if (localRefs[id] && !equal(sch, localRefs[id]))
948 throw new Error('id "' + id + '" resolves to more than one schema');
951 self._refs[id] = fullPath;
955 baseIds[jsonPtr] = baseId;
956 fullPaths[jsonPtr] = fullPath;
962 },{"./schema_obj":8,"./util":10,"fast-deep-equal":42,"json-schema-traverse":44,"uri-js":45}],7:[function(require,module,exports){
965 var ruleModules = require('../dotjs')
966 , toHash = require('./util').toHash;
968 module.exports = function rules() {
971 rules: [ { 'maximum': ['exclusiveMaximum'] },
972 { 'minimum': ['exclusiveMinimum'] }, 'multipleOf', 'format'] },
974 rules: [ 'maxLength', 'minLength', 'pattern', 'format' ] },
976 rules: [ 'maxItems', 'minItems', 'items', 'contains', 'uniqueItems' ] },
978 rules: [ 'maxProperties', 'minProperties', 'required', 'dependencies', 'propertyNames',
979 { 'properties': ['additionalProperties', 'patternProperties'] } ] },
980 { rules: [ '$ref', 'const', 'enum', 'not', 'anyOf', 'oneOf', 'allOf', 'if' ] }
983 var ALL = [ 'type', '$comment' ];
985 '$schema', '$id', 'id', '$data', '$async', 'title',
986 'description', 'default', 'definitions',
987 'examples', 'readOnly', 'writeOnly',
988 'contentMediaType', 'contentEncoding',
989 'additionalItems', 'then', 'else'
991 var TYPES = [ 'number', 'integer', 'string', 'array', 'object', 'boolean', 'null' ];
992 RULES.all = toHash(ALL);
993 RULES.types = toHash(TYPES);
995 RULES.forEach(function (group) {
996 group.rules = group.rules.map(function (keyword) {
998 if (typeof keyword == 'object') {
999 var key = Object.keys(keyword)[0];
1000 implKeywords = keyword[key];
1002 implKeywords.forEach(function (k) {
1004 RULES.all[k] = true;
1008 var rule = RULES.all[keyword] = {
1010 code: ruleModules[keyword],
1011 implements: implKeywords
1016 RULES.all.$comment = {
1017 keyword: '$comment',
1018 code: ruleModules.$comment
1021 if (group.type) RULES.types[group.type] = group;
1024 RULES.keywords = toHash(ALL.concat(KEYWORDS));
1030 },{"../dotjs":27,"./util":10}],8:[function(require,module,exports){
1033 var util = require('./util');
1035 module.exports = SchemaObject;
1037 function SchemaObject(obj) {
1038 util.copy(obj, this);
1041 },{"./util":10}],9:[function(require,module,exports){
1044 // https://mathiasbynens.be/notes/javascript-encoding
1045 // https://github.com/bestiejs/punycode.js - punycode.ucs2.decode
1046 module.exports = function ucs2length(str) {
1053 value = str.charCodeAt(pos++);
1054 if (value >= 0xD800 && value <= 0xDBFF && pos < len) {
1055 // high surrogate, and there is a next character
1056 value = str.charCodeAt(pos);
1057 if ((value & 0xFC00) == 0xDC00) pos++; // low surrogate
1063 },{}],10:[function(require,module,exports){
1069 checkDataType: checkDataType,
1070 checkDataTypes: checkDataTypes,
1071 coerceToTypes: coerceToTypes,
1073 getProperty: getProperty,
1074 escapeQuotes: escapeQuotes,
1075 equal: require('fast-deep-equal'),
1076 ucs2length: require('./ucs2length'),
1077 varOccurences: varOccurences,
1078 varReplace: varReplace,
1079 schemaHasRules: schemaHasRules,
1080 schemaHasRulesExcept: schemaHasRulesExcept,
1081 schemaUnknownRules: schemaUnknownRules,
1082 toQuotedString: toQuotedString,
1083 getPathExpr: getPathExpr,
1086 unescapeFragment: unescapeFragment,
1087 unescapeJsonPointer: unescapeJsonPointer,
1088 escapeFragment: escapeFragment,
1089 escapeJsonPointer: escapeJsonPointer
1093 function copy(o, to) {
1095 for (var key in o) to[key] = o[key];
1100 function checkDataType(dataType, data, strictNumbers, negate) {
1101 var EQUAL = negate ? ' !== ' : ' === '
1102 , AND = negate ? ' || ' : ' && '
1103 , OK = negate ? '!' : ''
1104 , NOT = negate ? '' : '!';
1106 case 'null': return data + EQUAL + 'null';
1107 case 'array': return OK + 'Array.isArray(' + data + ')';
1108 case 'object': return '(' + OK + data + AND +
1109 'typeof ' + data + EQUAL + '"object"' + AND +
1110 NOT + 'Array.isArray(' + data + '))';
1111 case 'integer': return '(typeof ' + data + EQUAL + '"number"' + AND +
1112 NOT + '(' + data + ' % 1)' +
1113 AND + data + EQUAL + data +
1114 (strictNumbers ? (AND + OK + 'isFinite(' + data + ')') : '') + ')';
1115 case 'number': return '(typeof ' + data + EQUAL + '"' + dataType + '"' +
1116 (strictNumbers ? (AND + OK + 'isFinite(' + data + ')') : '') + ')';
1117 default: return 'typeof ' + data + EQUAL + '"' + dataType + '"';
1122 function checkDataTypes(dataTypes, data, strictNumbers) {
1123 switch (dataTypes.length) {
1124 case 1: return checkDataType(dataTypes[0], data, strictNumbers, true);
1127 var types = toHash(dataTypes);
1128 if (types.array && types.object) {
1129 code = types.null ? '(': '(!' + data + ' || ';
1130 code += 'typeof ' + data + ' !== "object")';
1133 delete types.object;
1135 if (types.number) delete types.integer;
1136 for (var t in types)
1137 code += (code ? ' && ' : '' ) + checkDataType(t, data, strictNumbers, true);
1144 var COERCE_TO_TYPES = toHash([ 'string', 'number', 'integer', 'boolean', 'null' ]);
1145 function coerceToTypes(optionCoerceTypes, dataTypes) {
1146 if (Array.isArray(dataTypes)) {
1148 for (var i=0; i<dataTypes.length; i++) {
1149 var t = dataTypes[i];
1150 if (COERCE_TO_TYPES[t]) types[types.length] = t;
1151 else if (optionCoerceTypes === 'array' && t === 'array') types[types.length] = t;
1153 if (types.length) return types;
1154 } else if (COERCE_TO_TYPES[dataTypes]) {
1156 } else if (optionCoerceTypes === 'array' && dataTypes === 'array') {
1162 function toHash(arr) {
1164 for (var i=0; i<arr.length; i++) hash[arr[i]] = true;
1169 var IDENTIFIER = /^[a-z$_][a-z$_0-9]*$/i;
1170 var SINGLE_QUOTE = /'|\\/g;
1171 function getProperty(key) {
1172 return typeof key == 'number'
1174 : IDENTIFIER.test(key)
1176 : "['" + escapeQuotes(key) + "']";
1180 function escapeQuotes(str) {
1181 return str.replace(SINGLE_QUOTE, '\\$&')
1182 .replace(/\n/g, '\\n')
1183 .replace(/\r/g, '\\r')
1184 .replace(/\f/g, '\\f')
1185 .replace(/\t/g, '\\t');
1189 function varOccurences(str, dataVar) {
1190 dataVar += '[^0-9]';
1191 var matches = str.match(new RegExp(dataVar, 'g'));
1192 return matches ? matches.length : 0;
1196 function varReplace(str, dataVar, expr) {
1197 dataVar += '([^0-9])';
1198 expr = expr.replace(/\$/g, '$$$$');
1199 return str.replace(new RegExp(dataVar, 'g'), expr + '$1');
1203 function schemaHasRules(schema, rules) {
1204 if (typeof schema == 'boolean') return !schema;
1205 for (var key in schema) if (rules[key]) return true;
1209 function schemaHasRulesExcept(schema, rules, exceptKeyword) {
1210 if (typeof schema == 'boolean') return !schema && exceptKeyword != 'not';
1211 for (var key in schema) if (key != exceptKeyword && rules[key]) return true;
1215 function schemaUnknownRules(schema, rules) {
1216 if (typeof schema == 'boolean') return;
1217 for (var key in schema) if (!rules[key]) return key;
1221 function toQuotedString(str) {
1222 return '\'' + escapeQuotes(str) + '\'';
1226 function getPathExpr(currentPath, expr, jsonPointers, isNumber) {
1227 var path = jsonPointers // false by default
1228 ? '\'/\' + ' + expr + (isNumber ? '' : '.replace(/~/g, \'~0\').replace(/\\//g, \'~1\')')
1229 : (isNumber ? '\'[\' + ' + expr + ' + \']\'' : '\'[\\\'\' + ' + expr + ' + \'\\\']\'');
1230 return joinPaths(currentPath, path);
1234 function getPath(currentPath, prop, jsonPointers) {
1235 var path = jsonPointers // false by default
1236 ? toQuotedString('/' + escapeJsonPointer(prop))
1237 : toQuotedString(getProperty(prop));
1238 return joinPaths(currentPath, path);
1242 var JSON_POINTER = /^\/(?:[^~]|~0|~1)*$/;
1243 var RELATIVE_JSON_POINTER = /^([0-9]+)(#|\/(?:[^~]|~0|~1)*)?$/;
1244 function getData($data, lvl, paths) {
1245 var up, jsonPointer, data, matches;
1246 if ($data === '') return 'rootData';
1247 if ($data[0] == '/') {
1248 if (!JSON_POINTER.test($data)) throw new Error('Invalid JSON-pointer: ' + $data);
1249 jsonPointer = $data;
1252 matches = $data.match(RELATIVE_JSON_POINTER);
1253 if (!matches) throw new Error('Invalid JSON-pointer: ' + $data);
1255 jsonPointer = matches[2];
1256 if (jsonPointer == '#') {
1257 if (up >= lvl) throw new Error('Cannot access property/index ' + up + ' levels up, current level is ' + lvl);
1258 return paths[lvl - up];
1261 if (up > lvl) throw new Error('Cannot access data ' + up + ' levels up, current level is ' + lvl);
1262 data = 'data' + ((lvl - up) || '');
1263 if (!jsonPointer) return data;
1267 var segments = jsonPointer.split('/');
1268 for (var i=0; i<segments.length; i++) {
1269 var segment = segments[i];
1271 data += getProperty(unescapeJsonPointer(segment));
1272 expr += ' && ' + data;
1279 function joinPaths (a, b) {
1280 if (a == '""') return b;
1281 return (a + ' + ' + b).replace(/([^\\])' \+ '/g, '$1');
1285 function unescapeFragment(str) {
1286 return unescapeJsonPointer(decodeURIComponent(str));
1290 function escapeFragment(str) {
1291 return encodeURIComponent(escapeJsonPointer(str));
1295 function escapeJsonPointer(str) {
1296 return str.replace(/~/g, '~0').replace(/\//g, '~1');
1300 function unescapeJsonPointer(str) {
1301 return str.replace(/~1/g, '/').replace(/~0/g, '~');
1304 },{"./ucs2length":9,"fast-deep-equal":42}],11:[function(require,module,exports){
1323 'additionalProperties',
1329 module.exports = function (metaSchema, keywordsJsonPointers) {
1330 for (var i=0; i<keywordsJsonPointers.length; i++) {
1331 metaSchema = JSON.parse(JSON.stringify(metaSchema));
1332 var segments = keywordsJsonPointers[i].split('/');
1333 var keywords = metaSchema;
1335 for (j=1; j<segments.length; j++)
1336 keywords = keywords[segments[j]];
1338 for (j=0; j<KEYWORDS.length; j++) {
1339 var key = KEYWORDS[j];
1340 var schema = keywords[key];
1345 { $ref: 'https://raw.githubusercontent.com/ajv-validator/ajv/master/lib/refs/data.json#' }
1355 },{}],12:[function(require,module,exports){
1358 var metaSchema = require('./refs/json-schema-draft-07.json');
1361 $id: 'https://github.com/ajv-validator/ajv/blob/master/lib/definition_schema.js',
1363 simpleTypes: metaSchema.definitions.simpleTypes
1367 schema: ['validate'],
1368 $data: ['validate'],
1369 statements: ['inline'],
1370 valid: {not: {required: ['macro']}}
1373 type: metaSchema.properties.type,
1374 schema: {type: 'boolean'},
1375 statements: {type: 'boolean'},
1378 items: {type: 'string'}
1380 metaSchema: {type: 'object'},
1381 modifying: {type: 'boolean'},
1382 valid: {type: 'boolean'},
1383 $data: {type: 'boolean'},
1384 async: {type: 'boolean'},
1394 },{"./refs/json-schema-draft-07.json":41}],13:[function(require,module,exports){
1396 module.exports = function generate__limit(it, $keyword, $ruleType) {
1398 var $lvl = it.level;
1399 var $dataLvl = it.dataLevel;
1400 var $schema = it.schema[$keyword];
1401 var $schemaPath = it.schemaPath + it.util.getProperty($keyword);
1402 var $errSchemaPath = it.errSchemaPath + '/' + $keyword;
1403 var $breakOnError = !it.opts.allErrors;
1405 var $data = 'data' + ($dataLvl || '');
1406 var $isData = it.opts.$data && $schema && $schema.$data,
1409 out += ' var schema' + ($lvl) + ' = ' + (it.util.getData($schema.$data, $dataLvl, it.dataPathArr)) + '; ';
1410 $schemaValue = 'schema' + $lvl;
1412 $schemaValue = $schema;
1414 var $isMax = $keyword == 'maximum',
1415 $exclusiveKeyword = $isMax ? 'exclusiveMaximum' : 'exclusiveMinimum',
1416 $schemaExcl = it.schema[$exclusiveKeyword],
1417 $isDataExcl = it.opts.$data && $schemaExcl && $schemaExcl.$data,
1418 $op = $isMax ? '<' : '>',
1419 $notOp = $isMax ? '>' : '<',
1420 $errorKeyword = undefined;
1421 if (!($isData || typeof $schema == 'number' || $schema === undefined)) {
1422 throw new Error($keyword + ' must be number');
1424 if (!($isDataExcl || $schemaExcl === undefined || typeof $schemaExcl == 'number' || typeof $schemaExcl == 'boolean')) {
1425 throw new Error($exclusiveKeyword + ' must be number or boolean');
1428 var $schemaValueExcl = it.util.getData($schemaExcl.$data, $dataLvl, it.dataPathArr),
1429 $exclusive = 'exclusive' + $lvl,
1430 $exclType = 'exclType' + $lvl,
1431 $exclIsNumber = 'exclIsNumber' + $lvl,
1432 $opExpr = 'op' + $lvl,
1433 $opStr = '\' + ' + $opExpr + ' + \'';
1434 out += ' var schemaExcl' + ($lvl) + ' = ' + ($schemaValueExcl) + '; ';
1435 $schemaValueExcl = 'schemaExcl' + $lvl;
1436 out += ' var ' + ($exclusive) + '; var ' + ($exclType) + ' = typeof ' + ($schemaValueExcl) + '; if (' + ($exclType) + ' != \'boolean\' && ' + ($exclType) + ' != \'undefined\' && ' + ($exclType) + ' != \'number\') { ';
1437 var $errorKeyword = $exclusiveKeyword;
1438 var $$outStack = $$outStack || [];
1439 $$outStack.push(out);
1440 out = ''; /* istanbul ignore else */
1441 if (it.createErrors !== false) {
1442 out += ' { keyword: \'' + ($errorKeyword || '_exclusiveLimit') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: ' + (it.util.toQuotedString($errSchemaPath)) + ' , params: {} ';
1443 if (it.opts.messages !== false) {
1444 out += ' , message: \'' + ($exclusiveKeyword) + ' should be boolean\' ';
1446 if (it.opts.verbose) {
1447 out += ' , schema: validate.schema' + ($schemaPath) + ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' ';
1454 out = $$outStack.pop();
1455 if (!it.compositeRule && $breakOnError) {
1456 /* istanbul ignore if */
1458 out += ' throw new ValidationError([' + (__err) + ']); ';
1460 out += ' validate.errors = [' + (__err) + ']; return false; ';
1463 out += ' var err = ' + (__err) + '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ';
1465 out += ' } else if ( ';
1467 out += ' (' + ($schemaValue) + ' !== undefined && typeof ' + ($schemaValue) + ' != \'number\') || ';
1469 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) + '=\'; ';
1470 if ($schema === undefined) {
1471 $errorKeyword = $exclusiveKeyword;
1472 $errSchemaPath = it.errSchemaPath + '/' + $exclusiveKeyword;
1473 $schemaValue = $schemaValueExcl;
1474 $isData = $isDataExcl;
1477 var $exclIsNumber = typeof $schemaExcl == 'number',
1479 if ($exclIsNumber && $isData) {
1480 var $opExpr = '\'' + $opStr + '\'';
1483 out += ' (' + ($schemaValue) + ' !== undefined && typeof ' + ($schemaValue) + ' != \'number\') || ';
1485 out += ' ( ' + ($schemaValue) + ' === undefined || ' + ($schemaExcl) + ' ' + ($op) + '= ' + ($schemaValue) + ' ? ' + ($data) + ' ' + ($notOp) + '= ' + ($schemaExcl) + ' : ' + ($data) + ' ' + ($notOp) + ' ' + ($schemaValue) + ' ) || ' + ($data) + ' !== ' + ($data) + ') { ';
1487 if ($exclIsNumber && $schema === undefined) {
1489 $errorKeyword = $exclusiveKeyword;
1490 $errSchemaPath = it.errSchemaPath + '/' + $exclusiveKeyword;
1491 $schemaValue = $schemaExcl;
1494 if ($exclIsNumber) $schemaValue = Math[$isMax ? 'min' : 'max']($schemaExcl, $schema);
1495 if ($schemaExcl === ($exclIsNumber ? $schemaValue : true)) {
1497 $errorKeyword = $exclusiveKeyword;
1498 $errSchemaPath = it.errSchemaPath + '/' + $exclusiveKeyword;
1505 var $opExpr = '\'' + $opStr + '\'';
1508 out += ' (' + ($schemaValue) + ' !== undefined && typeof ' + ($schemaValue) + ' != \'number\') || ';
1510 out += ' ' + ($data) + ' ' + ($notOp) + ' ' + ($schemaValue) + ' || ' + ($data) + ' !== ' + ($data) + ') { ';
1513 $errorKeyword = $errorKeyword || $keyword;
1514 var $$outStack = $$outStack || [];
1515 $$outStack.push(out);
1516 out = ''; /* istanbul ignore else */
1517 if (it.createErrors !== false) {
1518 out += ' { keyword: \'' + ($errorKeyword || '_limit') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: ' + (it.util.toQuotedString($errSchemaPath)) + ' , params: { comparison: ' + ($opExpr) + ', limit: ' + ($schemaValue) + ', exclusive: ' + ($exclusive) + ' } ';
1519 if (it.opts.messages !== false) {
1520 out += ' , message: \'should be ' + ($opStr) + ' ';
1522 out += '\' + ' + ($schemaValue);
1524 out += '' + ($schemaValue) + '\'';
1527 if (it.opts.verbose) {
1528 out += ' , schema: ';
1530 out += 'validate.schema' + ($schemaPath);
1532 out += '' + ($schema);
1534 out += ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' ';
1541 out = $$outStack.pop();
1542 if (!it.compositeRule && $breakOnError) {
1543 /* istanbul ignore if */
1545 out += ' throw new ValidationError([' + (__err) + ']); ';
1547 out += ' validate.errors = [' + (__err) + ']; return false; ';
1550 out += ' var err = ' + (__err) + '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ';
1553 if ($breakOnError) {
1559 },{}],14:[function(require,module,exports){
1561 module.exports = function generate__limitItems(it, $keyword, $ruleType) {
1563 var $lvl = it.level;
1564 var $dataLvl = it.dataLevel;
1565 var $schema = it.schema[$keyword];
1566 var $schemaPath = it.schemaPath + it.util.getProperty($keyword);
1567 var $errSchemaPath = it.errSchemaPath + '/' + $keyword;
1568 var $breakOnError = !it.opts.allErrors;
1570 var $data = 'data' + ($dataLvl || '');
1571 var $isData = it.opts.$data && $schema && $schema.$data,
1574 out += ' var schema' + ($lvl) + ' = ' + (it.util.getData($schema.$data, $dataLvl, it.dataPathArr)) + '; ';
1575 $schemaValue = 'schema' + $lvl;
1577 $schemaValue = $schema;
1579 if (!($isData || typeof $schema == 'number')) {
1580 throw new Error($keyword + ' must be number');
1582 var $op = $keyword == 'maxItems' ? '>' : '<';
1585 out += ' (' + ($schemaValue) + ' !== undefined && typeof ' + ($schemaValue) + ' != \'number\') || ';
1587 out += ' ' + ($data) + '.length ' + ($op) + ' ' + ($schemaValue) + ') { ';
1588 var $errorKeyword = $keyword;
1589 var $$outStack = $$outStack || [];
1590 $$outStack.push(out);
1591 out = ''; /* istanbul ignore else */
1592 if (it.createErrors !== false) {
1593 out += ' { keyword: \'' + ($errorKeyword || '_limitItems') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: ' + (it.util.toQuotedString($errSchemaPath)) + ' , params: { limit: ' + ($schemaValue) + ' } ';
1594 if (it.opts.messages !== false) {
1595 out += ' , message: \'should NOT have ';
1596 if ($keyword == 'maxItems') {
1603 out += '\' + ' + ($schemaValue) + ' + \'';
1605 out += '' + ($schema);
1609 if (it.opts.verbose) {
1610 out += ' , schema: ';
1612 out += 'validate.schema' + ($schemaPath);
1614 out += '' + ($schema);
1616 out += ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' ';
1623 out = $$outStack.pop();
1624 if (!it.compositeRule && $breakOnError) {
1625 /* istanbul ignore if */
1627 out += ' throw new ValidationError([' + (__err) + ']); ';
1629 out += ' validate.errors = [' + (__err) + ']; return false; ';
1632 out += ' var err = ' + (__err) + '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ';
1635 if ($breakOnError) {
1641 },{}],15:[function(require,module,exports){
1643 module.exports = function generate__limitLength(it, $keyword, $ruleType) {
1645 var $lvl = it.level;
1646 var $dataLvl = it.dataLevel;
1647 var $schema = it.schema[$keyword];
1648 var $schemaPath = it.schemaPath + it.util.getProperty($keyword);
1649 var $errSchemaPath = it.errSchemaPath + '/' + $keyword;
1650 var $breakOnError = !it.opts.allErrors;
1652 var $data = 'data' + ($dataLvl || '');
1653 var $isData = it.opts.$data && $schema && $schema.$data,
1656 out += ' var schema' + ($lvl) + ' = ' + (it.util.getData($schema.$data, $dataLvl, it.dataPathArr)) + '; ';
1657 $schemaValue = 'schema' + $lvl;
1659 $schemaValue = $schema;
1661 if (!($isData || typeof $schema == 'number')) {
1662 throw new Error($keyword + ' must be number');
1664 var $op = $keyword == 'maxLength' ? '>' : '<';
1667 out += ' (' + ($schemaValue) + ' !== undefined && typeof ' + ($schemaValue) + ' != \'number\') || ';
1669 if (it.opts.unicode === false) {
1670 out += ' ' + ($data) + '.length ';
1672 out += ' ucs2length(' + ($data) + ') ';
1674 out += ' ' + ($op) + ' ' + ($schemaValue) + ') { ';
1675 var $errorKeyword = $keyword;
1676 var $$outStack = $$outStack || [];
1677 $$outStack.push(out);
1678 out = ''; /* istanbul ignore else */
1679 if (it.createErrors !== false) {
1680 out += ' { keyword: \'' + ($errorKeyword || '_limitLength') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: ' + (it.util.toQuotedString($errSchemaPath)) + ' , params: { limit: ' + ($schemaValue) + ' } ';
1681 if (it.opts.messages !== false) {
1682 out += ' , message: \'should NOT be ';
1683 if ($keyword == 'maxLength') {
1690 out += '\' + ' + ($schemaValue) + ' + \'';
1692 out += '' + ($schema);
1694 out += ' characters\' ';
1696 if (it.opts.verbose) {
1697 out += ' , schema: ';
1699 out += 'validate.schema' + ($schemaPath);
1701 out += '' + ($schema);
1703 out += ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' ';
1710 out = $$outStack.pop();
1711 if (!it.compositeRule && $breakOnError) {
1712 /* istanbul ignore if */
1714 out += ' throw new ValidationError([' + (__err) + ']); ';
1716 out += ' validate.errors = [' + (__err) + ']; return false; ';
1719 out += ' var err = ' + (__err) + '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ';
1722 if ($breakOnError) {
1728 },{}],16:[function(require,module,exports){
1730 module.exports = function generate__limitProperties(it, $keyword, $ruleType) {
1732 var $lvl = it.level;
1733 var $dataLvl = it.dataLevel;
1734 var $schema = it.schema[$keyword];
1735 var $schemaPath = it.schemaPath + it.util.getProperty($keyword);
1736 var $errSchemaPath = it.errSchemaPath + '/' + $keyword;
1737 var $breakOnError = !it.opts.allErrors;
1739 var $data = 'data' + ($dataLvl || '');
1740 var $isData = it.opts.$data && $schema && $schema.$data,
1743 out += ' var schema' + ($lvl) + ' = ' + (it.util.getData($schema.$data, $dataLvl, it.dataPathArr)) + '; ';
1744 $schemaValue = 'schema' + $lvl;
1746 $schemaValue = $schema;
1748 if (!($isData || typeof $schema == 'number')) {
1749 throw new Error($keyword + ' must be number');
1751 var $op = $keyword == 'maxProperties' ? '>' : '<';
1754 out += ' (' + ($schemaValue) + ' !== undefined && typeof ' + ($schemaValue) + ' != \'number\') || ';
1756 out += ' Object.keys(' + ($data) + ').length ' + ($op) + ' ' + ($schemaValue) + ') { ';
1757 var $errorKeyword = $keyword;
1758 var $$outStack = $$outStack || [];
1759 $$outStack.push(out);
1760 out = ''; /* istanbul ignore else */
1761 if (it.createErrors !== false) {
1762 out += ' { keyword: \'' + ($errorKeyword || '_limitProperties') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: ' + (it.util.toQuotedString($errSchemaPath)) + ' , params: { limit: ' + ($schemaValue) + ' } ';
1763 if (it.opts.messages !== false) {
1764 out += ' , message: \'should NOT have ';
1765 if ($keyword == 'maxProperties') {
1772 out += '\' + ' + ($schemaValue) + ' + \'';
1774 out += '' + ($schema);
1776 out += ' properties\' ';
1778 if (it.opts.verbose) {
1779 out += ' , schema: ';
1781 out += 'validate.schema' + ($schemaPath);
1783 out += '' + ($schema);
1785 out += ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' ';
1792 out = $$outStack.pop();
1793 if (!it.compositeRule && $breakOnError) {
1794 /* istanbul ignore if */
1796 out += ' throw new ValidationError([' + (__err) + ']); ';
1798 out += ' validate.errors = [' + (__err) + ']; return false; ';
1801 out += ' var err = ' + (__err) + '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ';
1804 if ($breakOnError) {
1810 },{}],17:[function(require,module,exports){
1812 module.exports = function generate_allOf(it, $keyword, $ruleType) {
1814 var $schema = it.schema[$keyword];
1815 var $schemaPath = it.schemaPath + it.util.getProperty($keyword);
1816 var $errSchemaPath = it.errSchemaPath + '/' + $keyword;
1817 var $breakOnError = !it.opts.allErrors;
1818 var $it = it.util.copy(it);
1819 var $closingBraces = '';
1821 var $nextValid = 'valid' + $it.level;
1822 var $currentBaseId = $it.baseId,
1823 $allSchemasEmpty = true;
1827 l1 = arr1.length - 1;
1829 $sch = arr1[$i += 1];
1830 if ((it.opts.strictKeywords ? typeof $sch == 'object' && Object.keys($sch).length > 0 : it.util.schemaHasRules($sch, it.RULES.all))) {
1831 $allSchemasEmpty = false;
1833 $it.schemaPath = $schemaPath + '[' + $i + ']';
1834 $it.errSchemaPath = $errSchemaPath + '/' + $i;
1835 out += ' ' + (it.validate($it)) + ' ';
1836 $it.baseId = $currentBaseId;
1837 if ($breakOnError) {
1838 out += ' if (' + ($nextValid) + ') { ';
1839 $closingBraces += '}';
1844 if ($breakOnError) {
1845 if ($allSchemasEmpty) {
1846 out += ' if (true) { ';
1848 out += ' ' + ($closingBraces.slice(0, -1)) + ' ';
1854 },{}],18:[function(require,module,exports){
1856 module.exports = function generate_anyOf(it, $keyword, $ruleType) {
1858 var $lvl = it.level;
1859 var $dataLvl = it.dataLevel;
1860 var $schema = it.schema[$keyword];
1861 var $schemaPath = it.schemaPath + it.util.getProperty($keyword);
1862 var $errSchemaPath = it.errSchemaPath + '/' + $keyword;
1863 var $breakOnError = !it.opts.allErrors;
1864 var $data = 'data' + ($dataLvl || '');
1865 var $valid = 'valid' + $lvl;
1866 var $errs = 'errs__' + $lvl;
1867 var $it = it.util.copy(it);
1868 var $closingBraces = '';
1870 var $nextValid = 'valid' + $it.level;
1871 var $noEmptySchema = $schema.every(function($sch) {
1872 return (it.opts.strictKeywords ? typeof $sch == 'object' && Object.keys($sch).length > 0 : it.util.schemaHasRules($sch, it.RULES.all));
1874 if ($noEmptySchema) {
1875 var $currentBaseId = $it.baseId;
1876 out += ' var ' + ($errs) + ' = errors; var ' + ($valid) + ' = false; ';
1877 var $wasComposite = it.compositeRule;
1878 it.compositeRule = $it.compositeRule = true;
1882 l1 = arr1.length - 1;
1884 $sch = arr1[$i += 1];
1886 $it.schemaPath = $schemaPath + '[' + $i + ']';
1887 $it.errSchemaPath = $errSchemaPath + '/' + $i;
1888 out += ' ' + (it.validate($it)) + ' ';
1889 $it.baseId = $currentBaseId;
1890 out += ' ' + ($valid) + ' = ' + ($valid) + ' || ' + ($nextValid) + '; if (!' + ($valid) + ') { ';
1891 $closingBraces += '}';
1894 it.compositeRule = $it.compositeRule = $wasComposite;
1895 out += ' ' + ($closingBraces) + ' if (!' + ($valid) + ') { var err = '; /* istanbul ignore else */
1896 if (it.createErrors !== false) {
1897 out += ' { keyword: \'' + ('anyOf') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: ' + (it.util.toQuotedString($errSchemaPath)) + ' , params: {} ';
1898 if (it.opts.messages !== false) {
1899 out += ' , message: \'should match some schema in anyOf\' ';
1901 if (it.opts.verbose) {
1902 out += ' , schema: validate.schema' + ($schemaPath) + ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' ';
1908 out += '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ';
1909 if (!it.compositeRule && $breakOnError) {
1910 /* istanbul ignore if */
1912 out += ' throw new ValidationError(vErrors); ';
1914 out += ' validate.errors = vErrors; return false; ';
1917 out += ' } else { errors = ' + ($errs) + '; if (vErrors !== null) { if (' + ($errs) + ') vErrors.length = ' + ($errs) + '; else vErrors = null; } ';
1918 if (it.opts.allErrors) {
1922 if ($breakOnError) {
1923 out += ' if (true) { ';
1929 },{}],19:[function(require,module,exports){
1931 module.exports = function generate_comment(it, $keyword, $ruleType) {
1933 var $schema = it.schema[$keyword];
1934 var $errSchemaPath = it.errSchemaPath + '/' + $keyword;
1935 var $breakOnError = !it.opts.allErrors;
1936 var $comment = it.util.toQuotedString($schema);
1937 if (it.opts.$comment === true) {
1938 out += ' console.log(' + ($comment) + ');';
1939 } else if (typeof it.opts.$comment == 'function') {
1940 out += ' self._opts.$comment(' + ($comment) + ', ' + (it.util.toQuotedString($errSchemaPath)) + ', validate.root.schema);';
1945 },{}],20:[function(require,module,exports){
1947 module.exports = function generate_const(it, $keyword, $ruleType) {
1949 var $lvl = it.level;
1950 var $dataLvl = it.dataLevel;
1951 var $schema = it.schema[$keyword];
1952 var $schemaPath = it.schemaPath + it.util.getProperty($keyword);
1953 var $errSchemaPath = it.errSchemaPath + '/' + $keyword;
1954 var $breakOnError = !it.opts.allErrors;
1955 var $data = 'data' + ($dataLvl || '');
1956 var $valid = 'valid' + $lvl;
1957 var $isData = it.opts.$data && $schema && $schema.$data,
1960 out += ' var schema' + ($lvl) + ' = ' + (it.util.getData($schema.$data, $dataLvl, it.dataPathArr)) + '; ';
1961 $schemaValue = 'schema' + $lvl;
1963 $schemaValue = $schema;
1966 out += ' var schema' + ($lvl) + ' = validate.schema' + ($schemaPath) + ';';
1968 out += 'var ' + ($valid) + ' = equal(' + ($data) + ', schema' + ($lvl) + '); if (!' + ($valid) + ') { ';
1969 var $$outStack = $$outStack || [];
1970 $$outStack.push(out);
1971 out = ''; /* istanbul ignore else */
1972 if (it.createErrors !== false) {
1973 out += ' { keyword: \'' + ('const') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: ' + (it.util.toQuotedString($errSchemaPath)) + ' , params: { allowedValue: schema' + ($lvl) + ' } ';
1974 if (it.opts.messages !== false) {
1975 out += ' , message: \'should be equal to constant\' ';
1977 if (it.opts.verbose) {
1978 out += ' , schema: validate.schema' + ($schemaPath) + ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' ';
1985 out = $$outStack.pop();
1986 if (!it.compositeRule && $breakOnError) {
1987 /* istanbul ignore if */
1989 out += ' throw new ValidationError([' + (__err) + ']); ';
1991 out += ' validate.errors = [' + (__err) + ']; return false; ';
1994 out += ' var err = ' + (__err) + '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ';
1997 if ($breakOnError) {
2003 },{}],21:[function(require,module,exports){
2005 module.exports = function generate_contains(it, $keyword, $ruleType) {
2007 var $lvl = it.level;
2008 var $dataLvl = it.dataLevel;
2009 var $schema = it.schema[$keyword];
2010 var $schemaPath = it.schemaPath + it.util.getProperty($keyword);
2011 var $errSchemaPath = it.errSchemaPath + '/' + $keyword;
2012 var $breakOnError = !it.opts.allErrors;
2013 var $data = 'data' + ($dataLvl || '');
2014 var $valid = 'valid' + $lvl;
2015 var $errs = 'errs__' + $lvl;
2016 var $it = it.util.copy(it);
2017 var $closingBraces = '';
2019 var $nextValid = 'valid' + $it.level;
2020 var $idx = 'i' + $lvl,
2021 $dataNxt = $it.dataLevel = it.dataLevel + 1,
2022 $nextData = 'data' + $dataNxt,
2023 $currentBaseId = it.baseId,
2024 $nonEmptySchema = (it.opts.strictKeywords ? typeof $schema == 'object' && Object.keys($schema).length > 0 : it.util.schemaHasRules($schema, it.RULES.all));
2025 out += 'var ' + ($errs) + ' = errors;var ' + ($valid) + ';';
2026 if ($nonEmptySchema) {
2027 var $wasComposite = it.compositeRule;
2028 it.compositeRule = $it.compositeRule = true;
2029 $it.schema = $schema;
2030 $it.schemaPath = $schemaPath;
2031 $it.errSchemaPath = $errSchemaPath;
2032 out += ' var ' + ($nextValid) + ' = false; for (var ' + ($idx) + ' = 0; ' + ($idx) + ' < ' + ($data) + '.length; ' + ($idx) + '++) { ';
2033 $it.errorPath = it.util.getPathExpr(it.errorPath, $idx, it.opts.jsonPointers, true);
2034 var $passData = $data + '[' + $idx + ']';
2035 $it.dataPathArr[$dataNxt] = $idx;
2036 var $code = it.validate($it);
2037 $it.baseId = $currentBaseId;
2038 if (it.util.varOccurences($code, $nextData) < 2) {
2039 out += ' ' + (it.util.varReplace($code, $nextData, $passData)) + ' ';
2041 out += ' var ' + ($nextData) + ' = ' + ($passData) + '; ' + ($code) + ' ';
2043 out += ' if (' + ($nextValid) + ') break; } ';
2044 it.compositeRule = $it.compositeRule = $wasComposite;
2045 out += ' ' + ($closingBraces) + ' if (!' + ($nextValid) + ') {';
2047 out += ' if (' + ($data) + '.length == 0) {';
2049 var $$outStack = $$outStack || [];
2050 $$outStack.push(out);
2051 out = ''; /* istanbul ignore else */
2052 if (it.createErrors !== false) {
2053 out += ' { keyword: \'' + ('contains') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: ' + (it.util.toQuotedString($errSchemaPath)) + ' , params: {} ';
2054 if (it.opts.messages !== false) {
2055 out += ' , message: \'should contain a valid item\' ';
2057 if (it.opts.verbose) {
2058 out += ' , schema: validate.schema' + ($schemaPath) + ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' ';
2065 out = $$outStack.pop();
2066 if (!it.compositeRule && $breakOnError) {
2067 /* istanbul ignore if */
2069 out += ' throw new ValidationError([' + (__err) + ']); ';
2071 out += ' validate.errors = [' + (__err) + ']; return false; ';
2074 out += ' var err = ' + (__err) + '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ';
2076 out += ' } else { ';
2077 if ($nonEmptySchema) {
2078 out += ' errors = ' + ($errs) + '; if (vErrors !== null) { if (' + ($errs) + ') vErrors.length = ' + ($errs) + '; else vErrors = null; } ';
2080 if (it.opts.allErrors) {
2086 },{}],22:[function(require,module,exports){
2088 module.exports = function generate_custom(it, $keyword, $ruleType) {
2090 var $lvl = it.level;
2091 var $dataLvl = it.dataLevel;
2092 var $schema = it.schema[$keyword];
2093 var $schemaPath = it.schemaPath + it.util.getProperty($keyword);
2094 var $errSchemaPath = it.errSchemaPath + '/' + $keyword;
2095 var $breakOnError = !it.opts.allErrors;
2097 var $data = 'data' + ($dataLvl || '');
2098 var $valid = 'valid' + $lvl;
2099 var $errs = 'errs__' + $lvl;
2100 var $isData = it.opts.$data && $schema && $schema.$data,
2103 out += ' var schema' + ($lvl) + ' = ' + (it.util.getData($schema.$data, $dataLvl, it.dataPathArr)) + '; ';
2104 $schemaValue = 'schema' + $lvl;
2106 $schemaValue = $schema;
2109 $definition = 'definition' + $lvl,
2110 $rDef = $rule.definition,
2111 $closingBraces = '';
2112 var $compile, $inline, $macro, $ruleValidate, $validateCode;
2113 if ($isData && $rDef.$data) {
2114 $validateCode = 'keywordValidate' + $lvl;
2115 var $validateSchema = $rDef.validateSchema;
2116 out += ' var ' + ($definition) + ' = RULES.custom[\'' + ($keyword) + '\'].definition; var ' + ($validateCode) + ' = ' + ($definition) + '.validate;';
2118 $ruleValidate = it.useCustomRule($rule, $schema, it.schema, it);
2119 if (!$ruleValidate) return;
2120 $schemaValue = 'validate.schema' + $schemaPath;
2121 $validateCode = $ruleValidate.code;
2122 $compile = $rDef.compile;
2123 $inline = $rDef.inline;
2124 $macro = $rDef.macro;
2126 var $ruleErrs = $validateCode + '.errors',
2128 $ruleErr = 'ruleErr' + $lvl,
2129 $asyncKeyword = $rDef.async;
2130 if ($asyncKeyword && !it.async) throw new Error('async keyword in sync schema');
2131 if (!($inline || $macro)) {
2132 out += '' + ($ruleErrs) + ' = null;';
2134 out += 'var ' + ($errs) + ' = errors;var ' + ($valid) + ';';
2135 if ($isData && $rDef.$data) {
2136 $closingBraces += '}';
2137 out += ' if (' + ($schemaValue) + ' === undefined) { ' + ($valid) + ' = true; } else { ';
2138 if ($validateSchema) {
2139 $closingBraces += '}';
2140 out += ' ' + ($valid) + ' = ' + ($definition) + '.validateSchema(' + ($schemaValue) + '); if (' + ($valid) + ') { ';
2144 if ($rDef.statements) {
2145 out += ' ' + ($ruleValidate.validate) + ' ';
2147 out += ' ' + ($valid) + ' = ' + ($ruleValidate.validate) + '; ';
2149 } else if ($macro) {
2150 var $it = it.util.copy(it);
2151 var $closingBraces = '';
2153 var $nextValid = 'valid' + $it.level;
2154 $it.schema = $ruleValidate.validate;
2155 $it.schemaPath = '';
2156 var $wasComposite = it.compositeRule;
2157 it.compositeRule = $it.compositeRule = true;
2158 var $code = it.validate($it).replace(/validate\.schema/g, $validateCode);
2159 it.compositeRule = $it.compositeRule = $wasComposite;
2160 out += ' ' + ($code);
2162 var $$outStack = $$outStack || [];
2163 $$outStack.push(out);
2165 out += ' ' + ($validateCode) + '.call( ';
2166 if (it.opts.passContext) {
2171 if ($compile || $rDef.schema === false) {
2172 out += ' , ' + ($data) + ' ';
2174 out += ' , ' + ($schemaValue) + ' , ' + ($data) + ' , validate.schema' + (it.schemaPath) + ' ';
2176 out += ' , (dataPath || \'\')';
2177 if (it.errorPath != '""') {
2178 out += ' + ' + (it.errorPath);
2180 var $parentData = $dataLvl ? 'data' + (($dataLvl - 1) || '') : 'parentData',
2181 $parentDataProperty = $dataLvl ? it.dataPathArr[$dataLvl] : 'parentDataProperty';
2182 out += ' , ' + ($parentData) + ' , ' + ($parentDataProperty) + ' , rootData ) ';
2183 var def_callRuleValidate = out;
2184 out = $$outStack.pop();
2185 if ($rDef.errors === false) {
2186 out += ' ' + ($valid) + ' = ';
2187 if ($asyncKeyword) {
2190 out += '' + (def_callRuleValidate) + '; ';
2192 if ($asyncKeyword) {
2193 $ruleErrs = 'customErrors' + $lvl;
2194 out += ' var ' + ($ruleErrs) + ' = null; try { ' + ($valid) + ' = await ' + (def_callRuleValidate) + '; } catch (e) { ' + ($valid) + ' = false; if (e instanceof ValidationError) ' + ($ruleErrs) + ' = e.errors; else throw e; } ';
2196 out += ' ' + ($ruleErrs) + ' = null; ' + ($valid) + ' = ' + (def_callRuleValidate) + '; ';
2200 if ($rDef.modifying) {
2201 out += ' if (' + ($parentData) + ') ' + ($data) + ' = ' + ($parentData) + '[' + ($parentDataProperty) + '];';
2203 out += '' + ($closingBraces);
2205 if ($breakOnError) {
2206 out += ' if (true) { ';
2210 if ($rDef.valid === undefined) {
2213 out += '' + ($nextValid);
2215 out += '' + ($valid);
2218 out += ' ' + (!$rDef.valid) + ' ';
2221 $errorKeyword = $rule.keyword;
2222 var $$outStack = $$outStack || [];
2223 $$outStack.push(out);
2225 var $$outStack = $$outStack || [];
2226 $$outStack.push(out);
2227 out = ''; /* istanbul ignore else */
2228 if (it.createErrors !== false) {
2229 out += ' { keyword: \'' + ($errorKeyword || 'custom') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: ' + (it.util.toQuotedString($errSchemaPath)) + ' , params: { keyword: \'' + ($rule.keyword) + '\' } ';
2230 if (it.opts.messages !== false) {
2231 out += ' , message: \'should pass "' + ($rule.keyword) + '" keyword validation\' ';
2233 if (it.opts.verbose) {
2234 out += ' , schema: validate.schema' + ($schemaPath) + ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' ';
2241 out = $$outStack.pop();
2242 if (!it.compositeRule && $breakOnError) {
2243 /* istanbul ignore if */
2245 out += ' throw new ValidationError([' + (__err) + ']); ';
2247 out += ' validate.errors = [' + (__err) + ']; return false; ';
2250 out += ' var err = ' + (__err) + '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ';
2252 var def_customError = out;
2253 out = $$outStack.pop();
2256 if ($rDef.errors != 'full') {
2257 out += ' for (var ' + ($i) + '=' + ($errs) + '; ' + ($i) + '<errors; ' + ($i) + '++) { var ' + ($ruleErr) + ' = vErrors[' + ($i) + ']; if (' + ($ruleErr) + '.dataPath === undefined) ' + ($ruleErr) + '.dataPath = (dataPath || \'\') + ' + (it.errorPath) + '; if (' + ($ruleErr) + '.schemaPath === undefined) { ' + ($ruleErr) + '.schemaPath = "' + ($errSchemaPath) + '"; } ';
2258 if (it.opts.verbose) {
2259 out += ' ' + ($ruleErr) + '.schema = ' + ($schemaValue) + '; ' + ($ruleErr) + '.data = ' + ($data) + '; ';
2264 if ($rDef.errors === false) {
2265 out += ' ' + (def_customError) + ' ';
2267 out += ' if (' + ($errs) + ' == errors) { ' + (def_customError) + ' } else { for (var ' + ($i) + '=' + ($errs) + '; ' + ($i) + '<errors; ' + ($i) + '++) { var ' + ($ruleErr) + ' = vErrors[' + ($i) + ']; if (' + ($ruleErr) + '.dataPath === undefined) ' + ($ruleErr) + '.dataPath = (dataPath || \'\') + ' + (it.errorPath) + '; if (' + ($ruleErr) + '.schemaPath === undefined) { ' + ($ruleErr) + '.schemaPath = "' + ($errSchemaPath) + '"; } ';
2268 if (it.opts.verbose) {
2269 out += ' ' + ($ruleErr) + '.schema = ' + ($schemaValue) + '; ' + ($ruleErr) + '.data = ' + ($data) + '; ';
2274 } else if ($macro) {
2275 out += ' var err = '; /* istanbul ignore else */
2276 if (it.createErrors !== false) {
2277 out += ' { keyword: \'' + ($errorKeyword || 'custom') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: ' + (it.util.toQuotedString($errSchemaPath)) + ' , params: { keyword: \'' + ($rule.keyword) + '\' } ';
2278 if (it.opts.messages !== false) {
2279 out += ' , message: \'should pass "' + ($rule.keyword) + '" keyword validation\' ';
2281 if (it.opts.verbose) {
2282 out += ' , schema: validate.schema' + ($schemaPath) + ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' ';
2288 out += '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ';
2289 if (!it.compositeRule && $breakOnError) {
2290 /* istanbul ignore if */
2292 out += ' throw new ValidationError(vErrors); ';
2294 out += ' validate.errors = vErrors; return false; ';
2298 if ($rDef.errors === false) {
2299 out += ' ' + (def_customError) + ' ';
2301 out += ' if (Array.isArray(' + ($ruleErrs) + ')) { if (vErrors === null) vErrors = ' + ($ruleErrs) + '; else vErrors = vErrors.concat(' + ($ruleErrs) + '); errors = vErrors.length; for (var ' + ($i) + '=' + ($errs) + '; ' + ($i) + '<errors; ' + ($i) + '++) { var ' + ($ruleErr) + ' = vErrors[' + ($i) + ']; if (' + ($ruleErr) + '.dataPath === undefined) ' + ($ruleErr) + '.dataPath = (dataPath || \'\') + ' + (it.errorPath) + '; ' + ($ruleErr) + '.schemaPath = "' + ($errSchemaPath) + '"; ';
2302 if (it.opts.verbose) {
2303 out += ' ' + ($ruleErr) + '.schema = ' + ($schemaValue) + '; ' + ($ruleErr) + '.data = ' + ($data) + '; ';
2305 out += ' } } else { ' + (def_customError) + ' } ';
2309 if ($breakOnError) {
2316 },{}],23:[function(require,module,exports){
2318 module.exports = function generate_dependencies(it, $keyword, $ruleType) {
2320 var $lvl = it.level;
2321 var $dataLvl = it.dataLevel;
2322 var $schema = it.schema[$keyword];
2323 var $schemaPath = it.schemaPath + it.util.getProperty($keyword);
2324 var $errSchemaPath = it.errSchemaPath + '/' + $keyword;
2325 var $breakOnError = !it.opts.allErrors;
2326 var $data = 'data' + ($dataLvl || '');
2327 var $errs = 'errs__' + $lvl;
2328 var $it = it.util.copy(it);
2329 var $closingBraces = '';
2331 var $nextValid = 'valid' + $it.level;
2332 var $schemaDeps = {},
2334 $ownProperties = it.opts.ownProperties;
2335 for ($property in $schema) {
2336 if ($property == '__proto__') continue;
2337 var $sch = $schema[$property];
2338 var $deps = Array.isArray($sch) ? $propertyDeps : $schemaDeps;
2339 $deps[$property] = $sch;
2341 out += 'var ' + ($errs) + ' = errors;';
2342 var $currentErrorPath = it.errorPath;
2343 out += 'var missing' + ($lvl) + ';';
2344 for (var $property in $propertyDeps) {
2345 $deps = $propertyDeps[$property];
2347 out += ' if ( ' + ($data) + (it.util.getProperty($property)) + ' !== undefined ';
2348 if ($ownProperties) {
2349 out += ' && Object.prototype.hasOwnProperty.call(' + ($data) + ', \'' + (it.util.escapeQuotes($property)) + '\') ';
2351 if ($breakOnError) {
2355 var $propertyKey, $i = -1,
2356 l1 = arr1.length - 1;
2358 $propertyKey = arr1[$i += 1];
2362 var $prop = it.util.getProperty($propertyKey),
2363 $useData = $data + $prop;
2364 out += ' ( ( ' + ($useData) + ' === undefined ';
2365 if ($ownProperties) {
2366 out += ' || ! Object.prototype.hasOwnProperty.call(' + ($data) + ', \'' + (it.util.escapeQuotes($propertyKey)) + '\') ';
2368 out += ') && (missing' + ($lvl) + ' = ' + (it.util.toQuotedString(it.opts.jsonPointers ? $propertyKey : $prop)) + ') ) ';
2372 var $propertyPath = 'missing' + $lvl,
2373 $missingProperty = '\' + ' + $propertyPath + ' + \'';
2374 if (it.opts._errorDataPathProperty) {
2375 it.errorPath = it.opts.jsonPointers ? it.util.getPathExpr($currentErrorPath, $propertyPath, true) : $currentErrorPath + ' + ' + $propertyPath;
2377 var $$outStack = $$outStack || [];
2378 $$outStack.push(out);
2379 out = ''; /* istanbul ignore else */
2380 if (it.createErrors !== false) {
2381 out += ' { keyword: \'' + ('dependencies') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: ' + (it.util.toQuotedString($errSchemaPath)) + ' , params: { property: \'' + (it.util.escapeQuotes($property)) + '\', missingProperty: \'' + ($missingProperty) + '\', depsCount: ' + ($deps.length) + ', deps: \'' + (it.util.escapeQuotes($deps.length == 1 ? $deps[0] : $deps.join(", "))) + '\' } ';
2382 if (it.opts.messages !== false) {
2383 out += ' , message: \'should have ';
2384 if ($deps.length == 1) {
2385 out += 'property ' + (it.util.escapeQuotes($deps[0]));
2387 out += 'properties ' + (it.util.escapeQuotes($deps.join(", ")));
2389 out += ' when property ' + (it.util.escapeQuotes($property)) + ' is present\' ';
2391 if (it.opts.verbose) {
2392 out += ' , schema: validate.schema' + ($schemaPath) + ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' ';
2399 out = $$outStack.pop();
2400 if (!it.compositeRule && $breakOnError) {
2401 /* istanbul ignore if */
2403 out += ' throw new ValidationError([' + (__err) + ']); ';
2405 out += ' validate.errors = [' + (__err) + ']; return false; ';
2408 out += ' var err = ' + (__err) + '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ';
2414 var $propertyKey, i2 = -1,
2415 l2 = arr2.length - 1;
2417 $propertyKey = arr2[i2 += 1];
2418 var $prop = it.util.getProperty($propertyKey),
2419 $missingProperty = it.util.escapeQuotes($propertyKey),
2420 $useData = $data + $prop;
2421 if (it.opts._errorDataPathProperty) {
2422 it.errorPath = it.util.getPath($currentErrorPath, $propertyKey, it.opts.jsonPointers);
2424 out += ' if ( ' + ($useData) + ' === undefined ';
2425 if ($ownProperties) {
2426 out += ' || ! Object.prototype.hasOwnProperty.call(' + ($data) + ', \'' + (it.util.escapeQuotes($propertyKey)) + '\') ';
2428 out += ') { var err = '; /* istanbul ignore else */
2429 if (it.createErrors !== false) {
2430 out += ' { keyword: \'' + ('dependencies') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: ' + (it.util.toQuotedString($errSchemaPath)) + ' , params: { property: \'' + (it.util.escapeQuotes($property)) + '\', missingProperty: \'' + ($missingProperty) + '\', depsCount: ' + ($deps.length) + ', deps: \'' + (it.util.escapeQuotes($deps.length == 1 ? $deps[0] : $deps.join(", "))) + '\' } ';
2431 if (it.opts.messages !== false) {
2432 out += ' , message: \'should have ';
2433 if ($deps.length == 1) {
2434 out += 'property ' + (it.util.escapeQuotes($deps[0]));
2436 out += 'properties ' + (it.util.escapeQuotes($deps.join(", ")));
2438 out += ' when property ' + (it.util.escapeQuotes($property)) + ' is present\' ';
2440 if (it.opts.verbose) {
2441 out += ' , schema: validate.schema' + ($schemaPath) + ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' ';
2447 out += '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; } ';
2452 if ($breakOnError) {
2453 $closingBraces += '}';
2458 it.errorPath = $currentErrorPath;
2459 var $currentBaseId = $it.baseId;
2460 for (var $property in $schemaDeps) {
2461 var $sch = $schemaDeps[$property];
2462 if ((it.opts.strictKeywords ? typeof $sch == 'object' && Object.keys($sch).length > 0 : it.util.schemaHasRules($sch, it.RULES.all))) {
2463 out += ' ' + ($nextValid) + ' = true; if ( ' + ($data) + (it.util.getProperty($property)) + ' !== undefined ';
2464 if ($ownProperties) {
2465 out += ' && Object.prototype.hasOwnProperty.call(' + ($data) + ', \'' + (it.util.escapeQuotes($property)) + '\') ';
2469 $it.schemaPath = $schemaPath + it.util.getProperty($property);
2470 $it.errSchemaPath = $errSchemaPath + '/' + it.util.escapeFragment($property);
2471 out += ' ' + (it.validate($it)) + ' ';
2472 $it.baseId = $currentBaseId;
2474 if ($breakOnError) {
2475 out += ' if (' + ($nextValid) + ') { ';
2476 $closingBraces += '}';
2480 if ($breakOnError) {
2481 out += ' ' + ($closingBraces) + ' if (' + ($errs) + ' == errors) {';
2486 },{}],24:[function(require,module,exports){
2488 module.exports = function generate_enum(it, $keyword, $ruleType) {
2490 var $lvl = it.level;
2491 var $dataLvl = it.dataLevel;
2492 var $schema = it.schema[$keyword];
2493 var $schemaPath = it.schemaPath + it.util.getProperty($keyword);
2494 var $errSchemaPath = it.errSchemaPath + '/' + $keyword;
2495 var $breakOnError = !it.opts.allErrors;
2496 var $data = 'data' + ($dataLvl || '');
2497 var $valid = 'valid' + $lvl;
2498 var $isData = it.opts.$data && $schema && $schema.$data,
2501 out += ' var schema' + ($lvl) + ' = ' + (it.util.getData($schema.$data, $dataLvl, it.dataPathArr)) + '; ';
2502 $schemaValue = 'schema' + $lvl;
2504 $schemaValue = $schema;
2506 var $i = 'i' + $lvl,
2507 $vSchema = 'schema' + $lvl;
2509 out += ' var ' + ($vSchema) + ' = validate.schema' + ($schemaPath) + ';';
2511 out += 'var ' + ($valid) + ';';
2513 out += ' if (schema' + ($lvl) + ' === undefined) ' + ($valid) + ' = true; else if (!Array.isArray(schema' + ($lvl) + ')) ' + ($valid) + ' = false; else {';
2515 out += '' + ($valid) + ' = false;for (var ' + ($i) + '=0; ' + ($i) + '<' + ($vSchema) + '.length; ' + ($i) + '++) if (equal(' + ($data) + ', ' + ($vSchema) + '[' + ($i) + '])) { ' + ($valid) + ' = true; break; }';
2519 out += ' if (!' + ($valid) + ') { ';
2520 var $$outStack = $$outStack || [];
2521 $$outStack.push(out);
2522 out = ''; /* istanbul ignore else */
2523 if (it.createErrors !== false) {
2524 out += ' { keyword: \'' + ('enum') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: ' + (it.util.toQuotedString($errSchemaPath)) + ' , params: { allowedValues: schema' + ($lvl) + ' } ';
2525 if (it.opts.messages !== false) {
2526 out += ' , message: \'should be equal to one of the allowed values\' ';
2528 if (it.opts.verbose) {
2529 out += ' , schema: validate.schema' + ($schemaPath) + ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' ';
2536 out = $$outStack.pop();
2537 if (!it.compositeRule && $breakOnError) {
2538 /* istanbul ignore if */
2540 out += ' throw new ValidationError([' + (__err) + ']); ';
2542 out += ' validate.errors = [' + (__err) + ']; return false; ';
2545 out += ' var err = ' + (__err) + '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ';
2548 if ($breakOnError) {
2554 },{}],25:[function(require,module,exports){
2556 module.exports = function generate_format(it, $keyword, $ruleType) {
2558 var $lvl = it.level;
2559 var $dataLvl = it.dataLevel;
2560 var $schema = it.schema[$keyword];
2561 var $schemaPath = it.schemaPath + it.util.getProperty($keyword);
2562 var $errSchemaPath = it.errSchemaPath + '/' + $keyword;
2563 var $breakOnError = !it.opts.allErrors;
2564 var $data = 'data' + ($dataLvl || '');
2565 if (it.opts.format === false) {
2566 if ($breakOnError) {
2567 out += ' if (true) { ';
2571 var $isData = it.opts.$data && $schema && $schema.$data,
2574 out += ' var schema' + ($lvl) + ' = ' + (it.util.getData($schema.$data, $dataLvl, it.dataPathArr)) + '; ';
2575 $schemaValue = 'schema' + $lvl;
2577 $schemaValue = $schema;
2579 var $unknownFormats = it.opts.unknownFormats,
2580 $allowUnknown = Array.isArray($unknownFormats);
2582 var $format = 'format' + $lvl,
2583 $isObject = 'isObject' + $lvl,
2584 $formatType = 'formatType' + $lvl;
2585 out += ' var ' + ($format) + ' = formats[' + ($schemaValue) + ']; var ' + ($isObject) + ' = typeof ' + ($format) + ' == \'object\' && !(' + ($format) + ' instanceof RegExp) && ' + ($format) + '.validate; var ' + ($formatType) + ' = ' + ($isObject) + ' && ' + ($format) + '.type || \'string\'; if (' + ($isObject) + ') { ';
2587 out += ' var async' + ($lvl) + ' = ' + ($format) + '.async; ';
2589 out += ' ' + ($format) + ' = ' + ($format) + '.validate; } if ( ';
2591 out += ' (' + ($schemaValue) + ' !== undefined && typeof ' + ($schemaValue) + ' != \'string\') || ';
2594 if ($unknownFormats != 'ignore') {
2595 out += ' (' + ($schemaValue) + ' && !' + ($format) + ' ';
2596 if ($allowUnknown) {
2597 out += ' && self._opts.unknownFormats.indexOf(' + ($schemaValue) + ') == -1 ';
2601 out += ' (' + ($format) + ' && ' + ($formatType) + ' == \'' + ($ruleType) + '\' && !(typeof ' + ($format) + ' == \'function\' ? ';
2603 out += ' (async' + ($lvl) + ' ? await ' + ($format) + '(' + ($data) + ') : ' + ($format) + '(' + ($data) + ')) ';
2605 out += ' ' + ($format) + '(' + ($data) + ') ';
2607 out += ' : ' + ($format) + '.test(' + ($data) + '))))) {';
2609 var $format = it.formats[$schema];
2611 if ($unknownFormats == 'ignore') {
2612 it.logger.warn('unknown format "' + $schema + '" ignored in schema at path "' + it.errSchemaPath + '"');
2613 if ($breakOnError) {
2614 out += ' if (true) { ';
2617 } else if ($allowUnknown && $unknownFormats.indexOf($schema) >= 0) {
2618 if ($breakOnError) {
2619 out += ' if (true) { ';
2623 throw new Error('unknown format "' + $schema + '" is used in schema at path "' + it.errSchemaPath + '"');
2626 var $isObject = typeof $format == 'object' && !($format instanceof RegExp) && $format.validate;
2627 var $formatType = $isObject && $format.type || 'string';
2629 var $async = $format.async === true;
2630 $format = $format.validate;
2632 if ($formatType != $ruleType) {
2633 if ($breakOnError) {
2634 out += ' if (true) { ';
2639 if (!it.async) throw new Error('async format in sync schema');
2640 var $formatRef = 'formats' + it.util.getProperty($schema) + '.validate';
2641 out += ' if (!(await ' + ($formatRef) + '(' + ($data) + '))) { ';
2644 var $formatRef = 'formats' + it.util.getProperty($schema);
2645 if ($isObject) $formatRef += '.validate';
2646 if (typeof $format == 'function') {
2647 out += ' ' + ($formatRef) + '(' + ($data) + ') ';
2649 out += ' ' + ($formatRef) + '.test(' + ($data) + ') ';
2654 var $$outStack = $$outStack || [];
2655 $$outStack.push(out);
2656 out = ''; /* istanbul ignore else */
2657 if (it.createErrors !== false) {
2658 out += ' { keyword: \'' + ('format') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: ' + (it.util.toQuotedString($errSchemaPath)) + ' , params: { format: ';
2660 out += '' + ($schemaValue);
2662 out += '' + (it.util.toQuotedString($schema));
2665 if (it.opts.messages !== false) {
2666 out += ' , message: \'should match format "';
2668 out += '\' + ' + ($schemaValue) + ' + \'';
2670 out += '' + (it.util.escapeQuotes($schema));
2674 if (it.opts.verbose) {
2675 out += ' , schema: ';
2677 out += 'validate.schema' + ($schemaPath);
2679 out += '' + (it.util.toQuotedString($schema));
2681 out += ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' ';
2688 out = $$outStack.pop();
2689 if (!it.compositeRule && $breakOnError) {
2690 /* istanbul ignore if */
2692 out += ' throw new ValidationError([' + (__err) + ']); ';
2694 out += ' validate.errors = [' + (__err) + ']; return false; ';
2697 out += ' var err = ' + (__err) + '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ';
2700 if ($breakOnError) {
2706 },{}],26:[function(require,module,exports){
2708 module.exports = function generate_if(it, $keyword, $ruleType) {
2710 var $lvl = it.level;
2711 var $dataLvl = it.dataLevel;
2712 var $schema = it.schema[$keyword];
2713 var $schemaPath = it.schemaPath + it.util.getProperty($keyword);
2714 var $errSchemaPath = it.errSchemaPath + '/' + $keyword;
2715 var $breakOnError = !it.opts.allErrors;
2716 var $data = 'data' + ($dataLvl || '');
2717 var $valid = 'valid' + $lvl;
2718 var $errs = 'errs__' + $lvl;
2719 var $it = it.util.copy(it);
2721 var $nextValid = 'valid' + $it.level;
2722 var $thenSch = it.schema['then'],
2723 $elseSch = it.schema['else'],
2724 $thenPresent = $thenSch !== undefined && (it.opts.strictKeywords ? typeof $thenSch == 'object' && Object.keys($thenSch).length > 0 : it.util.schemaHasRules($thenSch, it.RULES.all)),
2725 $elsePresent = $elseSch !== undefined && (it.opts.strictKeywords ? typeof $elseSch == 'object' && Object.keys($elseSch).length > 0 : it.util.schemaHasRules($elseSch, it.RULES.all)),
2726 $currentBaseId = $it.baseId;
2727 if ($thenPresent || $elsePresent) {
2729 $it.createErrors = false;
2730 $it.schema = $schema;
2731 $it.schemaPath = $schemaPath;
2732 $it.errSchemaPath = $errSchemaPath;
2733 out += ' var ' + ($errs) + ' = errors; var ' + ($valid) + ' = true; ';
2734 var $wasComposite = it.compositeRule;
2735 it.compositeRule = $it.compositeRule = true;
2736 out += ' ' + (it.validate($it)) + ' ';
2737 $it.baseId = $currentBaseId;
2738 $it.createErrors = true;
2739 out += ' errors = ' + ($errs) + '; if (vErrors !== null) { if (' + ($errs) + ') vErrors.length = ' + ($errs) + '; else vErrors = null; } ';
2740 it.compositeRule = $it.compositeRule = $wasComposite;
2742 out += ' if (' + ($nextValid) + ') { ';
2743 $it.schema = it.schema['then'];
2744 $it.schemaPath = it.schemaPath + '.then';
2745 $it.errSchemaPath = it.errSchemaPath + '/then';
2746 out += ' ' + (it.validate($it)) + ' ';
2747 $it.baseId = $currentBaseId;
2748 out += ' ' + ($valid) + ' = ' + ($nextValid) + '; ';
2749 if ($thenPresent && $elsePresent) {
2750 $ifClause = 'ifClause' + $lvl;
2751 out += ' var ' + ($ifClause) + ' = \'then\'; ';
2753 $ifClause = '\'then\'';
2760 out += ' if (!' + ($nextValid) + ') { ';
2763 $it.schema = it.schema['else'];
2764 $it.schemaPath = it.schemaPath + '.else';
2765 $it.errSchemaPath = it.errSchemaPath + '/else';
2766 out += ' ' + (it.validate($it)) + ' ';
2767 $it.baseId = $currentBaseId;
2768 out += ' ' + ($valid) + ' = ' + ($nextValid) + '; ';
2769 if ($thenPresent && $elsePresent) {
2770 $ifClause = 'ifClause' + $lvl;
2771 out += ' var ' + ($ifClause) + ' = \'else\'; ';
2773 $ifClause = '\'else\'';
2777 out += ' if (!' + ($valid) + ') { var err = '; /* istanbul ignore else */
2778 if (it.createErrors !== false) {
2779 out += ' { keyword: \'' + ('if') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: ' + (it.util.toQuotedString($errSchemaPath)) + ' , params: { failingKeyword: ' + ($ifClause) + ' } ';
2780 if (it.opts.messages !== false) {
2781 out += ' , message: \'should match "\' + ' + ($ifClause) + ' + \'" schema\' ';
2783 if (it.opts.verbose) {
2784 out += ' , schema: validate.schema' + ($schemaPath) + ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' ';
2790 out += '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ';
2791 if (!it.compositeRule && $breakOnError) {
2792 /* istanbul ignore if */
2794 out += ' throw new ValidationError(vErrors); ';
2796 out += ' validate.errors = vErrors; return false; ';
2800 if ($breakOnError) {
2804 if ($breakOnError) {
2805 out += ' if (true) { ';
2811 },{}],27:[function(require,module,exports){
2814 //all requires must be explicit because browserify won't work with dynamic requires
2816 '$ref': require('./ref'),
2817 allOf: require('./allOf'),
2818 anyOf: require('./anyOf'),
2819 '$comment': require('./comment'),
2820 const: require('./const'),
2821 contains: require('./contains'),
2822 dependencies: require('./dependencies'),
2823 'enum': require('./enum'),
2824 format: require('./format'),
2825 'if': require('./if'),
2826 items: require('./items'),
2827 maximum: require('./_limit'),
2828 minimum: require('./_limit'),
2829 maxItems: require('./_limitItems'),
2830 minItems: require('./_limitItems'),
2831 maxLength: require('./_limitLength'),
2832 minLength: require('./_limitLength'),
2833 maxProperties: require('./_limitProperties'),
2834 minProperties: require('./_limitProperties'),
2835 multipleOf: require('./multipleOf'),
2836 not: require('./not'),
2837 oneOf: require('./oneOf'),
2838 pattern: require('./pattern'),
2839 properties: require('./properties'),
2840 propertyNames: require('./propertyNames'),
2841 required: require('./required'),
2842 uniqueItems: require('./uniqueItems'),
2843 validate: require('./validate')
2846 },{"./_limit":13,"./_limitItems":14,"./_limitLength":15,"./_limitProperties":16,"./allOf":17,"./anyOf":18,"./comment":19,"./const":20,"./contains":21,"./dependencies":23,"./enum":24,"./format":25,"./if":26,"./items":28,"./multipleOf":29,"./not":30,"./oneOf":31,"./pattern":32,"./properties":33,"./propertyNames":34,"./ref":35,"./required":36,"./uniqueItems":37,"./validate":38}],28:[function(require,module,exports){
2848 module.exports = function generate_items(it, $keyword, $ruleType) {
2850 var $lvl = it.level;
2851 var $dataLvl = it.dataLevel;
2852 var $schema = it.schema[$keyword];
2853 var $schemaPath = it.schemaPath + it.util.getProperty($keyword);
2854 var $errSchemaPath = it.errSchemaPath + '/' + $keyword;
2855 var $breakOnError = !it.opts.allErrors;
2856 var $data = 'data' + ($dataLvl || '');
2857 var $valid = 'valid' + $lvl;
2858 var $errs = 'errs__' + $lvl;
2859 var $it = it.util.copy(it);
2860 var $closingBraces = '';
2862 var $nextValid = 'valid' + $it.level;
2863 var $idx = 'i' + $lvl,
2864 $dataNxt = $it.dataLevel = it.dataLevel + 1,
2865 $nextData = 'data' + $dataNxt,
2866 $currentBaseId = it.baseId;
2867 out += 'var ' + ($errs) + ' = errors;var ' + ($valid) + ';';
2868 if (Array.isArray($schema)) {
2869 var $additionalItems = it.schema.additionalItems;
2870 if ($additionalItems === false) {
2871 out += ' ' + ($valid) + ' = ' + ($data) + '.length <= ' + ($schema.length) + '; ';
2872 var $currErrSchemaPath = $errSchemaPath;
2873 $errSchemaPath = it.errSchemaPath + '/additionalItems';
2874 out += ' if (!' + ($valid) + ') { ';
2875 var $$outStack = $$outStack || [];
2876 $$outStack.push(out);
2877 out = ''; /* istanbul ignore else */
2878 if (it.createErrors !== false) {
2879 out += ' { keyword: \'' + ('additionalItems') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: ' + (it.util.toQuotedString($errSchemaPath)) + ' , params: { limit: ' + ($schema.length) + ' } ';
2880 if (it.opts.messages !== false) {
2881 out += ' , message: \'should NOT have more than ' + ($schema.length) + ' items\' ';
2883 if (it.opts.verbose) {
2884 out += ' , schema: false , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' ';
2891 out = $$outStack.pop();
2892 if (!it.compositeRule && $breakOnError) {
2893 /* istanbul ignore if */
2895 out += ' throw new ValidationError([' + (__err) + ']); ';
2897 out += ' validate.errors = [' + (__err) + ']; return false; ';
2900 out += ' var err = ' + (__err) + '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ';
2903 $errSchemaPath = $currErrSchemaPath;
2904 if ($breakOnError) {
2905 $closingBraces += '}';
2912 l1 = arr1.length - 1;
2914 $sch = arr1[$i += 1];
2915 if ((it.opts.strictKeywords ? typeof $sch == 'object' && Object.keys($sch).length > 0 : it.util.schemaHasRules($sch, it.RULES.all))) {
2916 out += ' ' + ($nextValid) + ' = true; if (' + ($data) + '.length > ' + ($i) + ') { ';
2917 var $passData = $data + '[' + $i + ']';
2919 $it.schemaPath = $schemaPath + '[' + $i + ']';
2920 $it.errSchemaPath = $errSchemaPath + '/' + $i;
2921 $it.errorPath = it.util.getPathExpr(it.errorPath, $i, it.opts.jsonPointers, true);
2922 $it.dataPathArr[$dataNxt] = $i;
2923 var $code = it.validate($it);
2924 $it.baseId = $currentBaseId;
2925 if (it.util.varOccurences($code, $nextData) < 2) {
2926 out += ' ' + (it.util.varReplace($code, $nextData, $passData)) + ' ';
2928 out += ' var ' + ($nextData) + ' = ' + ($passData) + '; ' + ($code) + ' ';
2931 if ($breakOnError) {
2932 out += ' if (' + ($nextValid) + ') { ';
2933 $closingBraces += '}';
2938 if (typeof $additionalItems == 'object' && (it.opts.strictKeywords ? typeof $additionalItems == 'object' && Object.keys($additionalItems).length > 0 : it.util.schemaHasRules($additionalItems, it.RULES.all))) {
2939 $it.schema = $additionalItems;
2940 $it.schemaPath = it.schemaPath + '.additionalItems';
2941 $it.errSchemaPath = it.errSchemaPath + '/additionalItems';
2942 out += ' ' + ($nextValid) + ' = true; if (' + ($data) + '.length > ' + ($schema.length) + ') { for (var ' + ($idx) + ' = ' + ($schema.length) + '; ' + ($idx) + ' < ' + ($data) + '.length; ' + ($idx) + '++) { ';
2943 $it.errorPath = it.util.getPathExpr(it.errorPath, $idx, it.opts.jsonPointers, true);
2944 var $passData = $data + '[' + $idx + ']';
2945 $it.dataPathArr[$dataNxt] = $idx;
2946 var $code = it.validate($it);
2947 $it.baseId = $currentBaseId;
2948 if (it.util.varOccurences($code, $nextData) < 2) {
2949 out += ' ' + (it.util.varReplace($code, $nextData, $passData)) + ' ';
2951 out += ' var ' + ($nextData) + ' = ' + ($passData) + '; ' + ($code) + ' ';
2953 if ($breakOnError) {
2954 out += ' if (!' + ($nextValid) + ') break; ';
2957 if ($breakOnError) {
2958 out += ' if (' + ($nextValid) + ') { ';
2959 $closingBraces += '}';
2962 } else if ((it.opts.strictKeywords ? typeof $schema == 'object' && Object.keys($schema).length > 0 : it.util.schemaHasRules($schema, it.RULES.all))) {
2963 $it.schema = $schema;
2964 $it.schemaPath = $schemaPath;
2965 $it.errSchemaPath = $errSchemaPath;
2966 out += ' for (var ' + ($idx) + ' = ' + (0) + '; ' + ($idx) + ' < ' + ($data) + '.length; ' + ($idx) + '++) { ';
2967 $it.errorPath = it.util.getPathExpr(it.errorPath, $idx, it.opts.jsonPointers, true);
2968 var $passData = $data + '[' + $idx + ']';
2969 $it.dataPathArr[$dataNxt] = $idx;
2970 var $code = it.validate($it);
2971 $it.baseId = $currentBaseId;
2972 if (it.util.varOccurences($code, $nextData) < 2) {
2973 out += ' ' + (it.util.varReplace($code, $nextData, $passData)) + ' ';
2975 out += ' var ' + ($nextData) + ' = ' + ($passData) + '; ' + ($code) + ' ';
2977 if ($breakOnError) {
2978 out += ' if (!' + ($nextValid) + ') break; ';
2982 if ($breakOnError) {
2983 out += ' ' + ($closingBraces) + ' if (' + ($errs) + ' == errors) {';
2988 },{}],29:[function(require,module,exports){
2990 module.exports = function generate_multipleOf(it, $keyword, $ruleType) {
2992 var $lvl = it.level;
2993 var $dataLvl = it.dataLevel;
2994 var $schema = it.schema[$keyword];
2995 var $schemaPath = it.schemaPath + it.util.getProperty($keyword);
2996 var $errSchemaPath = it.errSchemaPath + '/' + $keyword;
2997 var $breakOnError = !it.opts.allErrors;
2998 var $data = 'data' + ($dataLvl || '');
2999 var $isData = it.opts.$data && $schema && $schema.$data,
3002 out += ' var schema' + ($lvl) + ' = ' + (it.util.getData($schema.$data, $dataLvl, it.dataPathArr)) + '; ';
3003 $schemaValue = 'schema' + $lvl;
3005 $schemaValue = $schema;
3007 if (!($isData || typeof $schema == 'number')) {
3008 throw new Error($keyword + ' must be number');
3010 out += 'var division' + ($lvl) + ';if (';
3012 out += ' ' + ($schemaValue) + ' !== undefined && ( typeof ' + ($schemaValue) + ' != \'number\' || ';
3014 out += ' (division' + ($lvl) + ' = ' + ($data) + ' / ' + ($schemaValue) + ', ';
3015 if (it.opts.multipleOfPrecision) {
3016 out += ' Math.abs(Math.round(division' + ($lvl) + ') - division' + ($lvl) + ') > 1e-' + (it.opts.multipleOfPrecision) + ' ';
3018 out += ' division' + ($lvl) + ' !== parseInt(division' + ($lvl) + ') ';
3025 var $$outStack = $$outStack || [];
3026 $$outStack.push(out);
3027 out = ''; /* istanbul ignore else */
3028 if (it.createErrors !== false) {
3029 out += ' { keyword: \'' + ('multipleOf') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: ' + (it.util.toQuotedString($errSchemaPath)) + ' , params: { multipleOf: ' + ($schemaValue) + ' } ';
3030 if (it.opts.messages !== false) {
3031 out += ' , message: \'should be multiple of ';
3033 out += '\' + ' + ($schemaValue);
3035 out += '' + ($schemaValue) + '\'';
3038 if (it.opts.verbose) {
3039 out += ' , schema: ';
3041 out += 'validate.schema' + ($schemaPath);
3043 out += '' + ($schema);
3045 out += ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' ';
3052 out = $$outStack.pop();
3053 if (!it.compositeRule && $breakOnError) {
3054 /* istanbul ignore if */
3056 out += ' throw new ValidationError([' + (__err) + ']); ';
3058 out += ' validate.errors = [' + (__err) + ']; return false; ';
3061 out += ' var err = ' + (__err) + '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ';
3064 if ($breakOnError) {
3070 },{}],30:[function(require,module,exports){
3072 module.exports = function generate_not(it, $keyword, $ruleType) {
3074 var $lvl = it.level;
3075 var $dataLvl = it.dataLevel;
3076 var $schema = it.schema[$keyword];
3077 var $schemaPath = it.schemaPath + it.util.getProperty($keyword);
3078 var $errSchemaPath = it.errSchemaPath + '/' + $keyword;
3079 var $breakOnError = !it.opts.allErrors;
3080 var $data = 'data' + ($dataLvl || '');
3081 var $errs = 'errs__' + $lvl;
3082 var $it = it.util.copy(it);
3084 var $nextValid = 'valid' + $it.level;
3085 if ((it.opts.strictKeywords ? typeof $schema == 'object' && Object.keys($schema).length > 0 : it.util.schemaHasRules($schema, it.RULES.all))) {
3086 $it.schema = $schema;
3087 $it.schemaPath = $schemaPath;
3088 $it.errSchemaPath = $errSchemaPath;
3089 out += ' var ' + ($errs) + ' = errors; ';
3090 var $wasComposite = it.compositeRule;
3091 it.compositeRule = $it.compositeRule = true;
3092 $it.createErrors = false;
3093 var $allErrorsOption;
3094 if ($it.opts.allErrors) {
3095 $allErrorsOption = $it.opts.allErrors;
3096 $it.opts.allErrors = false;
3098 out += ' ' + (it.validate($it)) + ' ';
3099 $it.createErrors = true;
3100 if ($allErrorsOption) $it.opts.allErrors = $allErrorsOption;
3101 it.compositeRule = $it.compositeRule = $wasComposite;
3102 out += ' if (' + ($nextValid) + ') { ';
3103 var $$outStack = $$outStack || [];
3104 $$outStack.push(out);
3105 out = ''; /* istanbul ignore else */
3106 if (it.createErrors !== false) {
3107 out += ' { keyword: \'' + ('not') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: ' + (it.util.toQuotedString($errSchemaPath)) + ' , params: {} ';
3108 if (it.opts.messages !== false) {
3109 out += ' , message: \'should NOT be valid\' ';
3111 if (it.opts.verbose) {
3112 out += ' , schema: validate.schema' + ($schemaPath) + ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' ';
3119 out = $$outStack.pop();
3120 if (!it.compositeRule && $breakOnError) {
3121 /* istanbul ignore if */
3123 out += ' throw new ValidationError([' + (__err) + ']); ';
3125 out += ' validate.errors = [' + (__err) + ']; return false; ';
3128 out += ' var err = ' + (__err) + '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ';
3130 out += ' } else { errors = ' + ($errs) + '; if (vErrors !== null) { if (' + ($errs) + ') vErrors.length = ' + ($errs) + '; else vErrors = null; } ';
3131 if (it.opts.allErrors) {
3135 out += ' var err = '; /* istanbul ignore else */
3136 if (it.createErrors !== false) {
3137 out += ' { keyword: \'' + ('not') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: ' + (it.util.toQuotedString($errSchemaPath)) + ' , params: {} ';
3138 if (it.opts.messages !== false) {
3139 out += ' , message: \'should NOT be valid\' ';
3141 if (it.opts.verbose) {
3142 out += ' , schema: validate.schema' + ($schemaPath) + ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' ';
3148 out += '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ';
3149 if ($breakOnError) {
3150 out += ' if (false) { ';
3156 },{}],31:[function(require,module,exports){
3158 module.exports = function generate_oneOf(it, $keyword, $ruleType) {
3160 var $lvl = it.level;
3161 var $dataLvl = it.dataLevel;
3162 var $schema = it.schema[$keyword];
3163 var $schemaPath = it.schemaPath + it.util.getProperty($keyword);
3164 var $errSchemaPath = it.errSchemaPath + '/' + $keyword;
3165 var $breakOnError = !it.opts.allErrors;
3166 var $data = 'data' + ($dataLvl || '');
3167 var $valid = 'valid' + $lvl;
3168 var $errs = 'errs__' + $lvl;
3169 var $it = it.util.copy(it);
3170 var $closingBraces = '';
3172 var $nextValid = 'valid' + $it.level;
3173 var $currentBaseId = $it.baseId,
3174 $prevValid = 'prevValid' + $lvl,
3175 $passingSchemas = 'passingSchemas' + $lvl;
3176 out += 'var ' + ($errs) + ' = errors , ' + ($prevValid) + ' = false , ' + ($valid) + ' = false , ' + ($passingSchemas) + ' = null; ';
3177 var $wasComposite = it.compositeRule;
3178 it.compositeRule = $it.compositeRule = true;
3182 l1 = arr1.length - 1;
3184 $sch = arr1[$i += 1];
3185 if ((it.opts.strictKeywords ? typeof $sch == 'object' && Object.keys($sch).length > 0 : it.util.schemaHasRules($sch, it.RULES.all))) {
3187 $it.schemaPath = $schemaPath + '[' + $i + ']';
3188 $it.errSchemaPath = $errSchemaPath + '/' + $i;
3189 out += ' ' + (it.validate($it)) + ' ';
3190 $it.baseId = $currentBaseId;
3192 out += ' var ' + ($nextValid) + ' = true; ';
3195 out += ' if (' + ($nextValid) + ' && ' + ($prevValid) + ') { ' + ($valid) + ' = false; ' + ($passingSchemas) + ' = [' + ($passingSchemas) + ', ' + ($i) + ']; } else { ';
3196 $closingBraces += '}';
3198 out += ' if (' + ($nextValid) + ') { ' + ($valid) + ' = ' + ($prevValid) + ' = true; ' + ($passingSchemas) + ' = ' + ($i) + '; }';
3201 it.compositeRule = $it.compositeRule = $wasComposite;
3202 out += '' + ($closingBraces) + 'if (!' + ($valid) + ') { var err = '; /* istanbul ignore else */
3203 if (it.createErrors !== false) {
3204 out += ' { keyword: \'' + ('oneOf') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: ' + (it.util.toQuotedString($errSchemaPath)) + ' , params: { passingSchemas: ' + ($passingSchemas) + ' } ';
3205 if (it.opts.messages !== false) {
3206 out += ' , message: \'should match exactly one schema in oneOf\' ';
3208 if (it.opts.verbose) {
3209 out += ' , schema: validate.schema' + ($schemaPath) + ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' ';
3215 out += '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ';
3216 if (!it.compositeRule && $breakOnError) {
3217 /* istanbul ignore if */
3219 out += ' throw new ValidationError(vErrors); ';
3221 out += ' validate.errors = vErrors; return false; ';
3224 out += '} else { errors = ' + ($errs) + '; if (vErrors !== null) { if (' + ($errs) + ') vErrors.length = ' + ($errs) + '; else vErrors = null; }';
3225 if (it.opts.allErrors) {
3231 },{}],32:[function(require,module,exports){
3233 module.exports = function generate_pattern(it, $keyword, $ruleType) {
3235 var $lvl = it.level;
3236 var $dataLvl = it.dataLevel;
3237 var $schema = it.schema[$keyword];
3238 var $schemaPath = it.schemaPath + it.util.getProperty($keyword);
3239 var $errSchemaPath = it.errSchemaPath + '/' + $keyword;
3240 var $breakOnError = !it.opts.allErrors;
3241 var $data = 'data' + ($dataLvl || '');
3242 var $isData = it.opts.$data && $schema && $schema.$data,
3245 out += ' var schema' + ($lvl) + ' = ' + (it.util.getData($schema.$data, $dataLvl, it.dataPathArr)) + '; ';
3246 $schemaValue = 'schema' + $lvl;
3248 $schemaValue = $schema;
3250 var $regexp = $isData ? '(new RegExp(' + $schemaValue + '))' : it.usePattern($schema);
3253 out += ' (' + ($schemaValue) + ' !== undefined && typeof ' + ($schemaValue) + ' != \'string\') || ';
3255 out += ' !' + ($regexp) + '.test(' + ($data) + ') ) { ';
3256 var $$outStack = $$outStack || [];
3257 $$outStack.push(out);
3258 out = ''; /* istanbul ignore else */
3259 if (it.createErrors !== false) {
3260 out += ' { keyword: \'' + ('pattern') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: ' + (it.util.toQuotedString($errSchemaPath)) + ' , params: { pattern: ';
3262 out += '' + ($schemaValue);
3264 out += '' + (it.util.toQuotedString($schema));
3267 if (it.opts.messages !== false) {
3268 out += ' , message: \'should match pattern "';
3270 out += '\' + ' + ($schemaValue) + ' + \'';
3272 out += '' + (it.util.escapeQuotes($schema));
3276 if (it.opts.verbose) {
3277 out += ' , schema: ';
3279 out += 'validate.schema' + ($schemaPath);
3281 out += '' + (it.util.toQuotedString($schema));
3283 out += ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' ';
3290 out = $$outStack.pop();
3291 if (!it.compositeRule && $breakOnError) {
3292 /* istanbul ignore if */
3294 out += ' throw new ValidationError([' + (__err) + ']); ';
3296 out += ' validate.errors = [' + (__err) + ']; return false; ';
3299 out += ' var err = ' + (__err) + '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ';
3302 if ($breakOnError) {
3308 },{}],33:[function(require,module,exports){
3310 module.exports = function generate_properties(it, $keyword, $ruleType) {
3312 var $lvl = it.level;
3313 var $dataLvl = it.dataLevel;
3314 var $schema = it.schema[$keyword];
3315 var $schemaPath = it.schemaPath + it.util.getProperty($keyword);
3316 var $errSchemaPath = it.errSchemaPath + '/' + $keyword;
3317 var $breakOnError = !it.opts.allErrors;
3318 var $data = 'data' + ($dataLvl || '');
3319 var $errs = 'errs__' + $lvl;
3320 var $it = it.util.copy(it);
3321 var $closingBraces = '';
3323 var $nextValid = 'valid' + $it.level;
3324 var $key = 'key' + $lvl,
3325 $idx = 'idx' + $lvl,
3326 $dataNxt = $it.dataLevel = it.dataLevel + 1,
3327 $nextData = 'data' + $dataNxt,
3328 $dataProperties = 'dataProperties' + $lvl;
3329 var $schemaKeys = Object.keys($schema || {}).filter(notProto),
3330 $pProperties = it.schema.patternProperties || {},
3331 $pPropertyKeys = Object.keys($pProperties).filter(notProto),
3332 $aProperties = it.schema.additionalProperties,
3333 $someProperties = $schemaKeys.length || $pPropertyKeys.length,
3334 $noAdditional = $aProperties === false,
3335 $additionalIsSchema = typeof $aProperties == 'object' && Object.keys($aProperties).length,
3336 $removeAdditional = it.opts.removeAdditional,
3337 $checkAdditional = $noAdditional || $additionalIsSchema || $removeAdditional,
3338 $ownProperties = it.opts.ownProperties,
3339 $currentBaseId = it.baseId;
3340 var $required = it.schema.required;
3341 if ($required && !(it.opts.$data && $required.$data) && $required.length < it.opts.loopRequired) {
3342 var $requiredHash = it.util.toHash($required);
3345 function notProto(p) {
3346 return p !== '__proto__';
3348 out += 'var ' + ($errs) + ' = errors;var ' + ($nextValid) + ' = true;';
3349 if ($ownProperties) {
3350 out += ' var ' + ($dataProperties) + ' = undefined;';
3352 if ($checkAdditional) {
3353 if ($ownProperties) {
3354 out += ' ' + ($dataProperties) + ' = ' + ($dataProperties) + ' || Object.keys(' + ($data) + '); for (var ' + ($idx) + '=0; ' + ($idx) + '<' + ($dataProperties) + '.length; ' + ($idx) + '++) { var ' + ($key) + ' = ' + ($dataProperties) + '[' + ($idx) + ']; ';
3356 out += ' for (var ' + ($key) + ' in ' + ($data) + ') { ';
3358 if ($someProperties) {
3359 out += ' var isAdditional' + ($lvl) + ' = !(false ';
3360 if ($schemaKeys.length) {
3361 if ($schemaKeys.length > 8) {
3362 out += ' || validate.schema' + ($schemaPath) + '.hasOwnProperty(' + ($key) + ') ';
3364 var arr1 = $schemaKeys;
3366 var $propertyKey, i1 = -1,
3367 l1 = arr1.length - 1;
3369 $propertyKey = arr1[i1 += 1];
3370 out += ' || ' + ($key) + ' == ' + (it.util.toQuotedString($propertyKey)) + ' ';
3375 if ($pPropertyKeys.length) {
3376 var arr2 = $pPropertyKeys;
3378 var $pProperty, $i = -1,
3379 l2 = arr2.length - 1;
3381 $pProperty = arr2[$i += 1];
3382 out += ' || ' + (it.usePattern($pProperty)) + '.test(' + ($key) + ') ';
3386 out += ' ); if (isAdditional' + ($lvl) + ') { ';
3388 if ($removeAdditional == 'all') {
3389 out += ' delete ' + ($data) + '[' + ($key) + ']; ';
3391 var $currentErrorPath = it.errorPath;
3392 var $additionalProperty = '\' + ' + $key + ' + \'';
3393 if (it.opts._errorDataPathProperty) {
3394 it.errorPath = it.util.getPathExpr(it.errorPath, $key, it.opts.jsonPointers);
3396 if ($noAdditional) {
3397 if ($removeAdditional) {
3398 out += ' delete ' + ($data) + '[' + ($key) + ']; ';
3400 out += ' ' + ($nextValid) + ' = false; ';
3401 var $currErrSchemaPath = $errSchemaPath;
3402 $errSchemaPath = it.errSchemaPath + '/additionalProperties';
3403 var $$outStack = $$outStack || [];
3404 $$outStack.push(out);
3405 out = ''; /* istanbul ignore else */
3406 if (it.createErrors !== false) {
3407 out += ' { keyword: \'' + ('additionalProperties') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: ' + (it.util.toQuotedString($errSchemaPath)) + ' , params: { additionalProperty: \'' + ($additionalProperty) + '\' } ';
3408 if (it.opts.messages !== false) {
3409 out += ' , message: \'';
3410 if (it.opts._errorDataPathProperty) {
3411 out += 'is an invalid additional property';
3413 out += 'should NOT have additional properties';
3417 if (it.opts.verbose) {
3418 out += ' , schema: false , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' ';
3425 out = $$outStack.pop();
3426 if (!it.compositeRule && $breakOnError) {
3427 /* istanbul ignore if */
3429 out += ' throw new ValidationError([' + (__err) + ']); ';
3431 out += ' validate.errors = [' + (__err) + ']; return false; ';
3434 out += ' var err = ' + (__err) + '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ';
3436 $errSchemaPath = $currErrSchemaPath;
3437 if ($breakOnError) {
3441 } else if ($additionalIsSchema) {
3442 if ($removeAdditional == 'failing') {
3443 out += ' var ' + ($errs) + ' = errors; ';
3444 var $wasComposite = it.compositeRule;
3445 it.compositeRule = $it.compositeRule = true;
3446 $it.schema = $aProperties;
3447 $it.schemaPath = it.schemaPath + '.additionalProperties';
3448 $it.errSchemaPath = it.errSchemaPath + '/additionalProperties';
3449 $it.errorPath = it.opts._errorDataPathProperty ? it.errorPath : it.util.getPathExpr(it.errorPath, $key, it.opts.jsonPointers);
3450 var $passData = $data + '[' + $key + ']';
3451 $it.dataPathArr[$dataNxt] = $key;
3452 var $code = it.validate($it);
3453 $it.baseId = $currentBaseId;
3454 if (it.util.varOccurences($code, $nextData) < 2) {
3455 out += ' ' + (it.util.varReplace($code, $nextData, $passData)) + ' ';
3457 out += ' var ' + ($nextData) + ' = ' + ($passData) + '; ' + ($code) + ' ';
3459 out += ' if (!' + ($nextValid) + ') { errors = ' + ($errs) + '; if (validate.errors !== null) { if (errors) validate.errors.length = errors; else validate.errors = null; } delete ' + ($data) + '[' + ($key) + ']; } ';
3460 it.compositeRule = $it.compositeRule = $wasComposite;
3462 $it.schema = $aProperties;
3463 $it.schemaPath = it.schemaPath + '.additionalProperties';
3464 $it.errSchemaPath = it.errSchemaPath + '/additionalProperties';
3465 $it.errorPath = it.opts._errorDataPathProperty ? it.errorPath : it.util.getPathExpr(it.errorPath, $key, it.opts.jsonPointers);
3466 var $passData = $data + '[' + $key + ']';
3467 $it.dataPathArr[$dataNxt] = $key;
3468 var $code = it.validate($it);
3469 $it.baseId = $currentBaseId;
3470 if (it.util.varOccurences($code, $nextData) < 2) {
3471 out += ' ' + (it.util.varReplace($code, $nextData, $passData)) + ' ';
3473 out += ' var ' + ($nextData) + ' = ' + ($passData) + '; ' + ($code) + ' ';
3475 if ($breakOnError) {
3476 out += ' if (!' + ($nextValid) + ') break; ';
3480 it.errorPath = $currentErrorPath;
3482 if ($someProperties) {
3486 if ($breakOnError) {
3487 out += ' if (' + ($nextValid) + ') { ';
3488 $closingBraces += '}';
3491 var $useDefaults = it.opts.useDefaults && !it.compositeRule;
3492 if ($schemaKeys.length) {
3493 var arr3 = $schemaKeys;
3495 var $propertyKey, i3 = -1,
3496 l3 = arr3.length - 1;
3498 $propertyKey = arr3[i3 += 1];
3499 var $sch = $schema[$propertyKey];
3500 if ((it.opts.strictKeywords ? typeof $sch == 'object' && Object.keys($sch).length > 0 : it.util.schemaHasRules($sch, it.RULES.all))) {
3501 var $prop = it.util.getProperty($propertyKey),
3502 $passData = $data + $prop,
3503 $hasDefault = $useDefaults && $sch.default !== undefined;
3505 $it.schemaPath = $schemaPath + $prop;
3506 $it.errSchemaPath = $errSchemaPath + '/' + it.util.escapeFragment($propertyKey);
3507 $it.errorPath = it.util.getPath(it.errorPath, $propertyKey, it.opts.jsonPointers);
3508 $it.dataPathArr[$dataNxt] = it.util.toQuotedString($propertyKey);
3509 var $code = it.validate($it);
3510 $it.baseId = $currentBaseId;
3511 if (it.util.varOccurences($code, $nextData) < 2) {
3512 $code = it.util.varReplace($code, $nextData, $passData);
3513 var $useData = $passData;
3515 var $useData = $nextData;
3516 out += ' var ' + ($nextData) + ' = ' + ($passData) + '; ';
3519 out += ' ' + ($code) + ' ';
3521 if ($requiredHash && $requiredHash[$propertyKey]) {
3522 out += ' if ( ' + ($useData) + ' === undefined ';
3523 if ($ownProperties) {
3524 out += ' || ! Object.prototype.hasOwnProperty.call(' + ($data) + ', \'' + (it.util.escapeQuotes($propertyKey)) + '\') ';
3526 out += ') { ' + ($nextValid) + ' = false; ';
3527 var $currentErrorPath = it.errorPath,
3528 $currErrSchemaPath = $errSchemaPath,
3529 $missingProperty = it.util.escapeQuotes($propertyKey);
3530 if (it.opts._errorDataPathProperty) {
3531 it.errorPath = it.util.getPath($currentErrorPath, $propertyKey, it.opts.jsonPointers);
3533 $errSchemaPath = it.errSchemaPath + '/required';
3534 var $$outStack = $$outStack || [];
3535 $$outStack.push(out);
3536 out = ''; /* istanbul ignore else */
3537 if (it.createErrors !== false) {
3538 out += ' { keyword: \'' + ('required') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: ' + (it.util.toQuotedString($errSchemaPath)) + ' , params: { missingProperty: \'' + ($missingProperty) + '\' } ';
3539 if (it.opts.messages !== false) {
3540 out += ' , message: \'';
3541 if (it.opts._errorDataPathProperty) {
3542 out += 'is a required property';
3544 out += 'should have required property \\\'' + ($missingProperty) + '\\\'';
3548 if (it.opts.verbose) {
3549 out += ' , schema: validate.schema' + ($schemaPath) + ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' ';
3556 out = $$outStack.pop();
3557 if (!it.compositeRule && $breakOnError) {
3558 /* istanbul ignore if */
3560 out += ' throw new ValidationError([' + (__err) + ']); ';
3562 out += ' validate.errors = [' + (__err) + ']; return false; ';
3565 out += ' var err = ' + (__err) + '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ';
3567 $errSchemaPath = $currErrSchemaPath;
3568 it.errorPath = $currentErrorPath;
3569 out += ' } else { ';
3571 if ($breakOnError) {
3572 out += ' if ( ' + ($useData) + ' === undefined ';
3573 if ($ownProperties) {
3574 out += ' || ! Object.prototype.hasOwnProperty.call(' + ($data) + ', \'' + (it.util.escapeQuotes($propertyKey)) + '\') ';
3576 out += ') { ' + ($nextValid) + ' = true; } else { ';
3578 out += ' if (' + ($useData) + ' !== undefined ';
3579 if ($ownProperties) {
3580 out += ' && Object.prototype.hasOwnProperty.call(' + ($data) + ', \'' + (it.util.escapeQuotes($propertyKey)) + '\') ';
3585 out += ' ' + ($code) + ' } ';
3588 if ($breakOnError) {
3589 out += ' if (' + ($nextValid) + ') { ';
3590 $closingBraces += '}';
3595 if ($pPropertyKeys.length) {
3596 var arr4 = $pPropertyKeys;
3598 var $pProperty, i4 = -1,
3599 l4 = arr4.length - 1;
3601 $pProperty = arr4[i4 += 1];
3602 var $sch = $pProperties[$pProperty];
3603 if ((it.opts.strictKeywords ? typeof $sch == 'object' && Object.keys($sch).length > 0 : it.util.schemaHasRules($sch, it.RULES.all))) {
3605 $it.schemaPath = it.schemaPath + '.patternProperties' + it.util.getProperty($pProperty);
3606 $it.errSchemaPath = it.errSchemaPath + '/patternProperties/' + it.util.escapeFragment($pProperty);
3607 if ($ownProperties) {
3608 out += ' ' + ($dataProperties) + ' = ' + ($dataProperties) + ' || Object.keys(' + ($data) + '); for (var ' + ($idx) + '=0; ' + ($idx) + '<' + ($dataProperties) + '.length; ' + ($idx) + '++) { var ' + ($key) + ' = ' + ($dataProperties) + '[' + ($idx) + ']; ';
3610 out += ' for (var ' + ($key) + ' in ' + ($data) + ') { ';
3612 out += ' if (' + (it.usePattern($pProperty)) + '.test(' + ($key) + ')) { ';
3613 $it.errorPath = it.util.getPathExpr(it.errorPath, $key, it.opts.jsonPointers);
3614 var $passData = $data + '[' + $key + ']';
3615 $it.dataPathArr[$dataNxt] = $key;
3616 var $code = it.validate($it);
3617 $it.baseId = $currentBaseId;
3618 if (it.util.varOccurences($code, $nextData) < 2) {
3619 out += ' ' + (it.util.varReplace($code, $nextData, $passData)) + ' ';
3621 out += ' var ' + ($nextData) + ' = ' + ($passData) + '; ' + ($code) + ' ';
3623 if ($breakOnError) {
3624 out += ' if (!' + ($nextValid) + ') break; ';
3627 if ($breakOnError) {
3628 out += ' else ' + ($nextValid) + ' = true; ';
3631 if ($breakOnError) {
3632 out += ' if (' + ($nextValid) + ') { ';
3633 $closingBraces += '}';
3639 if ($breakOnError) {
3640 out += ' ' + ($closingBraces) + ' if (' + ($errs) + ' == errors) {';
3645 },{}],34:[function(require,module,exports){
3647 module.exports = function generate_propertyNames(it, $keyword, $ruleType) {
3649 var $lvl = it.level;
3650 var $dataLvl = it.dataLevel;
3651 var $schema = it.schema[$keyword];
3652 var $schemaPath = it.schemaPath + it.util.getProperty($keyword);
3653 var $errSchemaPath = it.errSchemaPath + '/' + $keyword;
3654 var $breakOnError = !it.opts.allErrors;
3655 var $data = 'data' + ($dataLvl || '');
3656 var $errs = 'errs__' + $lvl;
3657 var $it = it.util.copy(it);
3658 var $closingBraces = '';
3660 var $nextValid = 'valid' + $it.level;
3661 out += 'var ' + ($errs) + ' = errors;';
3662 if ((it.opts.strictKeywords ? typeof $schema == 'object' && Object.keys($schema).length > 0 : it.util.schemaHasRules($schema, it.RULES.all))) {
3663 $it.schema = $schema;
3664 $it.schemaPath = $schemaPath;
3665 $it.errSchemaPath = $errSchemaPath;
3666 var $key = 'key' + $lvl,
3667 $idx = 'idx' + $lvl,
3669 $invalidName = '\' + ' + $key + ' + \'',
3670 $dataNxt = $it.dataLevel = it.dataLevel + 1,
3671 $nextData = 'data' + $dataNxt,
3672 $dataProperties = 'dataProperties' + $lvl,
3673 $ownProperties = it.opts.ownProperties,
3674 $currentBaseId = it.baseId;
3675 if ($ownProperties) {
3676 out += ' var ' + ($dataProperties) + ' = undefined; ';
3678 if ($ownProperties) {
3679 out += ' ' + ($dataProperties) + ' = ' + ($dataProperties) + ' || Object.keys(' + ($data) + '); for (var ' + ($idx) + '=0; ' + ($idx) + '<' + ($dataProperties) + '.length; ' + ($idx) + '++) { var ' + ($key) + ' = ' + ($dataProperties) + '[' + ($idx) + ']; ';
3681 out += ' for (var ' + ($key) + ' in ' + ($data) + ') { ';
3683 out += ' var startErrs' + ($lvl) + ' = errors; ';
3684 var $passData = $key;
3685 var $wasComposite = it.compositeRule;
3686 it.compositeRule = $it.compositeRule = true;
3687 var $code = it.validate($it);
3688 $it.baseId = $currentBaseId;
3689 if (it.util.varOccurences($code, $nextData) < 2) {
3690 out += ' ' + (it.util.varReplace($code, $nextData, $passData)) + ' ';
3692 out += ' var ' + ($nextData) + ' = ' + ($passData) + '; ' + ($code) + ' ';
3694 it.compositeRule = $it.compositeRule = $wasComposite;
3695 out += ' if (!' + ($nextValid) + ') { for (var ' + ($i) + '=startErrs' + ($lvl) + '; ' + ($i) + '<errors; ' + ($i) + '++) { vErrors[' + ($i) + '].propertyName = ' + ($key) + '; } var err = '; /* istanbul ignore else */
3696 if (it.createErrors !== false) {
3697 out += ' { keyword: \'' + ('propertyNames') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: ' + (it.util.toQuotedString($errSchemaPath)) + ' , params: { propertyName: \'' + ($invalidName) + '\' } ';
3698 if (it.opts.messages !== false) {
3699 out += ' , message: \'property name \\\'' + ($invalidName) + '\\\' is invalid\' ';
3701 if (it.opts.verbose) {
3702 out += ' , schema: validate.schema' + ($schemaPath) + ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' ';
3708 out += '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ';
3709 if (!it.compositeRule && $breakOnError) {
3710 /* istanbul ignore if */
3712 out += ' throw new ValidationError(vErrors); ';
3714 out += ' validate.errors = vErrors; return false; ';
3717 if ($breakOnError) {
3722 if ($breakOnError) {
3723 out += ' ' + ($closingBraces) + ' if (' + ($errs) + ' == errors) {';
3728 },{}],35:[function(require,module,exports){
3730 module.exports = function generate_ref(it, $keyword, $ruleType) {
3732 var $lvl = it.level;
3733 var $dataLvl = it.dataLevel;
3734 var $schema = it.schema[$keyword];
3735 var $errSchemaPath = it.errSchemaPath + '/' + $keyword;
3736 var $breakOnError = !it.opts.allErrors;
3737 var $data = 'data' + ($dataLvl || '');
3738 var $valid = 'valid' + $lvl;
3739 var $async, $refCode;
3740 if ($schema == '#' || $schema == '#/') {
3743 $refCode = 'validate';
3745 $async = it.root.schema.$async === true;
3746 $refCode = 'root.refVal[0]';
3749 var $refVal = it.resolveRef(it.baseId, $schema, it.isRoot);
3750 if ($refVal === undefined) {
3751 var $message = it.MissingRefError.message(it.baseId, $schema);
3752 if (it.opts.missingRefs == 'fail') {
3753 it.logger.error($message);
3754 var $$outStack = $$outStack || [];
3755 $$outStack.push(out);
3756 out = ''; /* istanbul ignore else */
3757 if (it.createErrors !== false) {
3758 out += ' { keyword: \'' + ('$ref') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: ' + (it.util.toQuotedString($errSchemaPath)) + ' , params: { ref: \'' + (it.util.escapeQuotes($schema)) + '\' } ';
3759 if (it.opts.messages !== false) {
3760 out += ' , message: \'can\\\'t resolve reference ' + (it.util.escapeQuotes($schema)) + '\' ';
3762 if (it.opts.verbose) {
3763 out += ' , schema: ' + (it.util.toQuotedString($schema)) + ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' ';
3770 out = $$outStack.pop();
3771 if (!it.compositeRule && $breakOnError) {
3772 /* istanbul ignore if */
3774 out += ' throw new ValidationError([' + (__err) + ']); ';
3776 out += ' validate.errors = [' + (__err) + ']; return false; ';
3779 out += ' var err = ' + (__err) + '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ';
3781 if ($breakOnError) {
3782 out += ' if (false) { ';
3784 } else if (it.opts.missingRefs == 'ignore') {
3785 it.logger.warn($message);
3786 if ($breakOnError) {
3787 out += ' if (true) { ';
3790 throw new it.MissingRefError(it.baseId, $schema, $message);
3792 } else if ($refVal.inline) {
3793 var $it = it.util.copy(it);
3795 var $nextValid = 'valid' + $it.level;
3796 $it.schema = $refVal.schema;
3797 $it.schemaPath = '';
3798 $it.errSchemaPath = $schema;
3799 var $code = it.validate($it).replace(/validate\.schema/g, $refVal.code);
3800 out += ' ' + ($code) + ' ';
3801 if ($breakOnError) {
3802 out += ' if (' + ($nextValid) + ') { ';
3805 $async = $refVal.$async === true || (it.async && $refVal.$async !== false);
3806 $refCode = $refVal.code;
3810 var $$outStack = $$outStack || [];
3811 $$outStack.push(out);
3813 if (it.opts.passContext) {
3814 out += ' ' + ($refCode) + '.call(this, ';
3816 out += ' ' + ($refCode) + '( ';
3818 out += ' ' + ($data) + ', (dataPath || \'\')';
3819 if (it.errorPath != '""') {
3820 out += ' + ' + (it.errorPath);
3822 var $parentData = $dataLvl ? 'data' + (($dataLvl - 1) || '') : 'parentData',
3823 $parentDataProperty = $dataLvl ? it.dataPathArr[$dataLvl] : 'parentDataProperty';
3824 out += ' , ' + ($parentData) + ' , ' + ($parentDataProperty) + ', rootData) ';
3825 var __callValidate = out;
3826 out = $$outStack.pop();
3828 if (!it.async) throw new Error('async schema referenced by sync schema');
3829 if ($breakOnError) {
3830 out += ' var ' + ($valid) + '; ';
3832 out += ' try { await ' + (__callValidate) + '; ';
3833 if ($breakOnError) {
3834 out += ' ' + ($valid) + ' = true; ';
3836 out += ' } catch (e) { if (!(e instanceof ValidationError)) throw e; if (vErrors === null) vErrors = e.errors; else vErrors = vErrors.concat(e.errors); errors = vErrors.length; ';
3837 if ($breakOnError) {
3838 out += ' ' + ($valid) + ' = false; ';
3841 if ($breakOnError) {
3842 out += ' if (' + ($valid) + ') { ';
3845 out += ' if (!' + (__callValidate) + ') { if (vErrors === null) vErrors = ' + ($refCode) + '.errors; else vErrors = vErrors.concat(' + ($refCode) + '.errors); errors = vErrors.length; } ';
3846 if ($breakOnError) {
3854 },{}],36:[function(require,module,exports){
3856 module.exports = function generate_required(it, $keyword, $ruleType) {
3858 var $lvl = it.level;
3859 var $dataLvl = it.dataLevel;
3860 var $schema = it.schema[$keyword];
3861 var $schemaPath = it.schemaPath + it.util.getProperty($keyword);
3862 var $errSchemaPath = it.errSchemaPath + '/' + $keyword;
3863 var $breakOnError = !it.opts.allErrors;
3864 var $data = 'data' + ($dataLvl || '');
3865 var $valid = 'valid' + $lvl;
3866 var $isData = it.opts.$data && $schema && $schema.$data,
3869 out += ' var schema' + ($lvl) + ' = ' + (it.util.getData($schema.$data, $dataLvl, it.dataPathArr)) + '; ';
3870 $schemaValue = 'schema' + $lvl;
3872 $schemaValue = $schema;
3874 var $vSchema = 'schema' + $lvl;
3876 if ($schema.length < it.opts.loopRequired && it.schema.properties && Object.keys(it.schema.properties).length) {
3880 var $property, i1 = -1,
3881 l1 = arr1.length - 1;
3883 $property = arr1[i1 += 1];
3884 var $propertySch = it.schema.properties[$property];
3885 if (!($propertySch && (it.opts.strictKeywords ? typeof $propertySch == 'object' && Object.keys($propertySch).length > 0 : it.util.schemaHasRules($propertySch, it.RULES.all)))) {
3886 $required[$required.length] = $property;
3891 var $required = $schema;
3894 if ($isData || $required.length) {
3895 var $currentErrorPath = it.errorPath,
3896 $loopRequired = $isData || $required.length >= it.opts.loopRequired,
3897 $ownProperties = it.opts.ownProperties;
3898 if ($breakOnError) {
3899 out += ' var missing' + ($lvl) + '; ';
3900 if ($loopRequired) {
3902 out += ' var ' + ($vSchema) + ' = validate.schema' + ($schemaPath) + '; ';
3904 var $i = 'i' + $lvl,
3905 $propertyPath = 'schema' + $lvl + '[' + $i + ']',
3906 $missingProperty = '\' + ' + $propertyPath + ' + \'';
3907 if (it.opts._errorDataPathProperty) {
3908 it.errorPath = it.util.getPathExpr($currentErrorPath, $propertyPath, it.opts.jsonPointers);
3910 out += ' var ' + ($valid) + ' = true; ';
3912 out += ' if (schema' + ($lvl) + ' === undefined) ' + ($valid) + ' = true; else if (!Array.isArray(schema' + ($lvl) + ')) ' + ($valid) + ' = false; else {';
3914 out += ' for (var ' + ($i) + ' = 0; ' + ($i) + ' < ' + ($vSchema) + '.length; ' + ($i) + '++) { ' + ($valid) + ' = ' + ($data) + '[' + ($vSchema) + '[' + ($i) + ']] !== undefined ';
3915 if ($ownProperties) {
3916 out += ' && Object.prototype.hasOwnProperty.call(' + ($data) + ', ' + ($vSchema) + '[' + ($i) + ']) ';
3918 out += '; if (!' + ($valid) + ') break; } ';
3922 out += ' if (!' + ($valid) + ') { ';
3923 var $$outStack = $$outStack || [];
3924 $$outStack.push(out);
3925 out = ''; /* istanbul ignore else */
3926 if (it.createErrors !== false) {
3927 out += ' { keyword: \'' + ('required') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: ' + (it.util.toQuotedString($errSchemaPath)) + ' , params: { missingProperty: \'' + ($missingProperty) + '\' } ';
3928 if (it.opts.messages !== false) {
3929 out += ' , message: \'';
3930 if (it.opts._errorDataPathProperty) {
3931 out += 'is a required property';
3933 out += 'should have required property \\\'' + ($missingProperty) + '\\\'';
3937 if (it.opts.verbose) {
3938 out += ' , schema: validate.schema' + ($schemaPath) + ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' ';
3945 out = $$outStack.pop();
3946 if (!it.compositeRule && $breakOnError) {
3947 /* istanbul ignore if */
3949 out += ' throw new ValidationError([' + (__err) + ']); ';
3951 out += ' validate.errors = [' + (__err) + ']; return false; ';
3954 out += ' var err = ' + (__err) + '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ';
3956 out += ' } else { ';
3959 var arr2 = $required;
3961 var $propertyKey, $i = -1,
3962 l2 = arr2.length - 1;
3964 $propertyKey = arr2[$i += 1];
3968 var $prop = it.util.getProperty($propertyKey),
3969 $useData = $data + $prop;
3970 out += ' ( ( ' + ($useData) + ' === undefined ';
3971 if ($ownProperties) {
3972 out += ' || ! Object.prototype.hasOwnProperty.call(' + ($data) + ', \'' + (it.util.escapeQuotes($propertyKey)) + '\') ';
3974 out += ') && (missing' + ($lvl) + ' = ' + (it.util.toQuotedString(it.opts.jsonPointers ? $propertyKey : $prop)) + ') ) ';
3978 var $propertyPath = 'missing' + $lvl,
3979 $missingProperty = '\' + ' + $propertyPath + ' + \'';
3980 if (it.opts._errorDataPathProperty) {
3981 it.errorPath = it.opts.jsonPointers ? it.util.getPathExpr($currentErrorPath, $propertyPath, true) : $currentErrorPath + ' + ' + $propertyPath;
3983 var $$outStack = $$outStack || [];
3984 $$outStack.push(out);
3985 out = ''; /* istanbul ignore else */
3986 if (it.createErrors !== false) {
3987 out += ' { keyword: \'' + ('required') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: ' + (it.util.toQuotedString($errSchemaPath)) + ' , params: { missingProperty: \'' + ($missingProperty) + '\' } ';
3988 if (it.opts.messages !== false) {
3989 out += ' , message: \'';
3990 if (it.opts._errorDataPathProperty) {
3991 out += 'is a required property';
3993 out += 'should have required property \\\'' + ($missingProperty) + '\\\'';
3997 if (it.opts.verbose) {
3998 out += ' , schema: validate.schema' + ($schemaPath) + ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' ';
4005 out = $$outStack.pop();
4006 if (!it.compositeRule && $breakOnError) {
4007 /* istanbul ignore if */
4009 out += ' throw new ValidationError([' + (__err) + ']); ';
4011 out += ' validate.errors = [' + (__err) + ']; return false; ';
4014 out += ' var err = ' + (__err) + '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ';
4016 out += ' } else { ';
4019 if ($loopRequired) {
4021 out += ' var ' + ($vSchema) + ' = validate.schema' + ($schemaPath) + '; ';
4023 var $i = 'i' + $lvl,
4024 $propertyPath = 'schema' + $lvl + '[' + $i + ']',
4025 $missingProperty = '\' + ' + $propertyPath + ' + \'';
4026 if (it.opts._errorDataPathProperty) {
4027 it.errorPath = it.util.getPathExpr($currentErrorPath, $propertyPath, it.opts.jsonPointers);
4030 out += ' if (' + ($vSchema) + ' && !Array.isArray(' + ($vSchema) + ')) { var err = '; /* istanbul ignore else */
4031 if (it.createErrors !== false) {
4032 out += ' { keyword: \'' + ('required') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: ' + (it.util.toQuotedString($errSchemaPath)) + ' , params: { missingProperty: \'' + ($missingProperty) + '\' } ';
4033 if (it.opts.messages !== false) {
4034 out += ' , message: \'';
4035 if (it.opts._errorDataPathProperty) {
4036 out += 'is a required property';
4038 out += 'should have required property \\\'' + ($missingProperty) + '\\\'';
4042 if (it.opts.verbose) {
4043 out += ' , schema: validate.schema' + ($schemaPath) + ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' ';
4049 out += '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; } else if (' + ($vSchema) + ' !== undefined) { ';
4051 out += ' for (var ' + ($i) + ' = 0; ' + ($i) + ' < ' + ($vSchema) + '.length; ' + ($i) + '++) { if (' + ($data) + '[' + ($vSchema) + '[' + ($i) + ']] === undefined ';
4052 if ($ownProperties) {
4053 out += ' || ! Object.prototype.hasOwnProperty.call(' + ($data) + ', ' + ($vSchema) + '[' + ($i) + ']) ';
4055 out += ') { var err = '; /* istanbul ignore else */
4056 if (it.createErrors !== false) {
4057 out += ' { keyword: \'' + ('required') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: ' + (it.util.toQuotedString($errSchemaPath)) + ' , params: { missingProperty: \'' + ($missingProperty) + '\' } ';
4058 if (it.opts.messages !== false) {
4059 out += ' , message: \'';
4060 if (it.opts._errorDataPathProperty) {
4061 out += 'is a required property';
4063 out += 'should have required property \\\'' + ($missingProperty) + '\\\'';
4067 if (it.opts.verbose) {
4068 out += ' , schema: validate.schema' + ($schemaPath) + ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' ';
4074 out += '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; } } ';
4079 var arr3 = $required;
4081 var $propertyKey, i3 = -1,
4082 l3 = arr3.length - 1;
4084 $propertyKey = arr3[i3 += 1];
4085 var $prop = it.util.getProperty($propertyKey),
4086 $missingProperty = it.util.escapeQuotes($propertyKey),
4087 $useData = $data + $prop;
4088 if (it.opts._errorDataPathProperty) {
4089 it.errorPath = it.util.getPath($currentErrorPath, $propertyKey, it.opts.jsonPointers);
4091 out += ' if ( ' + ($useData) + ' === undefined ';
4092 if ($ownProperties) {
4093 out += ' || ! Object.prototype.hasOwnProperty.call(' + ($data) + ', \'' + (it.util.escapeQuotes($propertyKey)) + '\') ';
4095 out += ') { var err = '; /* istanbul ignore else */
4096 if (it.createErrors !== false) {
4097 out += ' { keyword: \'' + ('required') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: ' + (it.util.toQuotedString($errSchemaPath)) + ' , params: { missingProperty: \'' + ($missingProperty) + '\' } ';
4098 if (it.opts.messages !== false) {
4099 out += ' , message: \'';
4100 if (it.opts._errorDataPathProperty) {
4101 out += 'is a required property';
4103 out += 'should have required property \\\'' + ($missingProperty) + '\\\'';
4107 if (it.opts.verbose) {
4108 out += ' , schema: validate.schema' + ($schemaPath) + ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' ';
4114 out += '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; } ';
4119 it.errorPath = $currentErrorPath;
4120 } else if ($breakOnError) {
4121 out += ' if (true) {';
4126 },{}],37:[function(require,module,exports){
4128 module.exports = function generate_uniqueItems(it, $keyword, $ruleType) {
4130 var $lvl = it.level;
4131 var $dataLvl = it.dataLevel;
4132 var $schema = it.schema[$keyword];
4133 var $schemaPath = it.schemaPath + it.util.getProperty($keyword);
4134 var $errSchemaPath = it.errSchemaPath + '/' + $keyword;
4135 var $breakOnError = !it.opts.allErrors;
4136 var $data = 'data' + ($dataLvl || '');
4137 var $valid = 'valid' + $lvl;
4138 var $isData = it.opts.$data && $schema && $schema.$data,
4141 out += ' var schema' + ($lvl) + ' = ' + (it.util.getData($schema.$data, $dataLvl, it.dataPathArr)) + '; ';
4142 $schemaValue = 'schema' + $lvl;
4144 $schemaValue = $schema;
4146 if (($schema || $isData) && it.opts.uniqueItems !== false) {
4148 out += ' var ' + ($valid) + '; if (' + ($schemaValue) + ' === false || ' + ($schemaValue) + ' === undefined) ' + ($valid) + ' = true; else if (typeof ' + ($schemaValue) + ' != \'boolean\') ' + ($valid) + ' = false; else { ';
4150 out += ' var i = ' + ($data) + '.length , ' + ($valid) + ' = true , j; if (i > 1) { ';
4151 var $itemType = it.schema.items && it.schema.items.type,
4152 $typeIsArray = Array.isArray($itemType);
4153 if (!$itemType || $itemType == 'object' || $itemType == 'array' || ($typeIsArray && ($itemType.indexOf('object') >= 0 || $itemType.indexOf('array') >= 0))) {
4154 out += ' outer: for (;i--;) { for (j = i; j--;) { if (equal(' + ($data) + '[i], ' + ($data) + '[j])) { ' + ($valid) + ' = false; break outer; } } } ';
4156 out += ' var itemIndices = {}, item; for (;i--;) { var item = ' + ($data) + '[i]; ';
4157 var $method = 'checkDataType' + ($typeIsArray ? 's' : '');
4158 out += ' if (' + (it.util[$method]($itemType, 'item', it.opts.strictNumbers, true)) + ') continue; ';
4160 out += ' if (typeof item == \'string\') item = \'"\' + item; ';
4162 out += ' if (typeof itemIndices[item] == \'number\') { ' + ($valid) + ' = false; j = itemIndices[item]; break; } itemIndices[item] = i; } ';
4168 out += ' if (!' + ($valid) + ') { ';
4169 var $$outStack = $$outStack || [];
4170 $$outStack.push(out);
4171 out = ''; /* istanbul ignore else */
4172 if (it.createErrors !== false) {
4173 out += ' { keyword: \'' + ('uniqueItems') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: ' + (it.util.toQuotedString($errSchemaPath)) + ' , params: { i: i, j: j } ';
4174 if (it.opts.messages !== false) {
4175 out += ' , message: \'should NOT have duplicate items (items ## \' + j + \' and \' + i + \' are identical)\' ';
4177 if (it.opts.verbose) {
4178 out += ' , schema: ';
4180 out += 'validate.schema' + ($schemaPath);
4182 out += '' + ($schema);
4184 out += ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' ';
4191 out = $$outStack.pop();
4192 if (!it.compositeRule && $breakOnError) {
4193 /* istanbul ignore if */
4195 out += ' throw new ValidationError([' + (__err) + ']); ';
4197 out += ' validate.errors = [' + (__err) + ']; return false; ';
4200 out += ' var err = ' + (__err) + '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ';
4203 if ($breakOnError) {
4207 if ($breakOnError) {
4208 out += ' if (true) { ';
4214 },{}],38:[function(require,module,exports){
4216 module.exports = function generate_validate(it, $keyword, $ruleType) {
4218 var $async = it.schema.$async === true,
4219 $refKeywords = it.util.schemaHasRulesExcept(it.schema, it.RULES.all, '$ref'),
4220 $id = it.self._getId(it.schema);
4221 if (it.opts.strictKeywords) {
4222 var $unknownKwd = it.util.schemaUnknownRules(it.schema, it.RULES.keywords);
4224 var $keywordsMsg = 'unknown keyword: ' + $unknownKwd;
4225 if (it.opts.strictKeywords === 'log') it.logger.warn($keywordsMsg);
4226 else throw new Error($keywordsMsg);
4230 out += ' var validate = ';
4235 out += 'function(data, dataPath, parentData, parentDataProperty, rootData) { \'use strict\'; ';
4236 if ($id && (it.opts.sourceCode || it.opts.processCode)) {
4237 out += ' ' + ('/\*# sourceURL=' + $id + ' */') + ' ';
4240 if (typeof it.schema == 'boolean' || !($refKeywords || it.schema.$ref)) {
4241 var $keyword = 'false schema';
4242 var $lvl = it.level;
4243 var $dataLvl = it.dataLevel;
4244 var $schema = it.schema[$keyword];
4245 var $schemaPath = it.schemaPath + it.util.getProperty($keyword);
4246 var $errSchemaPath = it.errSchemaPath + '/' + $keyword;
4247 var $breakOnError = !it.opts.allErrors;
4249 var $data = 'data' + ($dataLvl || '');
4250 var $valid = 'valid' + $lvl;
4251 if (it.schema === false) {
4253 $breakOnError = true;
4255 out += ' var ' + ($valid) + ' = false; ';
4257 var $$outStack = $$outStack || [];
4258 $$outStack.push(out);
4259 out = ''; /* istanbul ignore else */
4260 if (it.createErrors !== false) {
4261 out += ' { keyword: \'' + ($errorKeyword || 'false schema') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: ' + (it.util.toQuotedString($errSchemaPath)) + ' , params: {} ';
4262 if (it.opts.messages !== false) {
4263 out += ' , message: \'boolean schema is false\' ';
4265 if (it.opts.verbose) {
4266 out += ' , schema: false , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' ';
4273 out = $$outStack.pop();
4274 if (!it.compositeRule && $breakOnError) {
4275 /* istanbul ignore if */
4277 out += ' throw new ValidationError([' + (__err) + ']); ';
4279 out += ' validate.errors = [' + (__err) + ']; return false; ';
4282 out += ' var err = ' + (__err) + '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ';
4287 out += ' return data; ';
4289 out += ' validate.errors = null; return true; ';
4292 out += ' var ' + ($valid) + ' = true; ';
4296 out += ' }; return validate; ';
4301 var $top = it.isTop,
4302 $lvl = it.level = 0,
4303 $dataLvl = it.dataLevel = 0,
4305 it.rootId = it.resolve.fullPath(it.self._getId(it.root.schema));
4306 it.baseId = it.baseId || it.rootId;
4308 it.dataPathArr = [undefined];
4309 if (it.schema.default !== undefined && it.opts.useDefaults && it.opts.strictDefaults) {
4310 var $defaultMsg = 'default is ignored in the schema root';
4311 if (it.opts.strictDefaults === 'log') it.logger.warn($defaultMsg);
4312 else throw new Error($defaultMsg);
4314 out += ' var vErrors = null; ';
4315 out += ' var errors = 0; ';
4316 out += ' if (rootData === undefined) rootData = data; ';
4318 var $lvl = it.level,
4319 $dataLvl = it.dataLevel,
4320 $data = 'data' + ($dataLvl || '');
4321 if ($id) it.baseId = it.resolve.url(it.baseId, $id);
4322 if ($async && !it.async) throw new Error('async schema in sync schema');
4323 out += ' var errs_' + ($lvl) + ' = errors;';
4325 var $valid = 'valid' + $lvl,
4326 $breakOnError = !it.opts.allErrors,
4327 $closingBraces1 = '',
4328 $closingBraces2 = '';
4330 var $typeSchema = it.schema.type,
4331 $typeIsArray = Array.isArray($typeSchema);
4332 if ($typeSchema && it.opts.nullable && it.schema.nullable === true) {
4334 if ($typeSchema.indexOf('null') == -1) $typeSchema = $typeSchema.concat('null');
4335 } else if ($typeSchema != 'null') {
4336 $typeSchema = [$typeSchema, 'null'];
4337 $typeIsArray = true;
4340 if ($typeIsArray && $typeSchema.length == 1) {
4341 $typeSchema = $typeSchema[0];
4342 $typeIsArray = false;
4344 if (it.schema.$ref && $refKeywords) {
4345 if (it.opts.extendRefs == 'fail') {
4346 throw new Error('$ref: validation keywords used in schema at path "' + it.errSchemaPath + '" (see option extendRefs)');
4347 } else if (it.opts.extendRefs !== true) {
4348 $refKeywords = false;
4349 it.logger.warn('$ref: keywords ignored in schema at path "' + it.errSchemaPath + '"');
4352 if (it.schema.$comment && it.opts.$comment) {
4353 out += ' ' + (it.RULES.all.$comment.code(it, '$comment'));
4356 if (it.opts.coerceTypes) {
4357 var $coerceToTypes = it.util.coerceToTypes(it.opts.coerceTypes, $typeSchema);
4359 var $rulesGroup = it.RULES.types[$typeSchema];
4360 if ($coerceToTypes || $typeIsArray || $rulesGroup === true || ($rulesGroup && !$shouldUseGroup($rulesGroup))) {
4361 var $schemaPath = it.schemaPath + '.type',
4362 $errSchemaPath = it.errSchemaPath + '/type';
4363 var $schemaPath = it.schemaPath + '.type',
4364 $errSchemaPath = it.errSchemaPath + '/type',
4365 $method = $typeIsArray ? 'checkDataTypes' : 'checkDataType';
4366 out += ' if (' + (it.util[$method]($typeSchema, $data, it.opts.strictNumbers, true)) + ') { ';
4367 if ($coerceToTypes) {
4368 var $dataType = 'dataType' + $lvl,
4369 $coerced = 'coerced' + $lvl;
4370 out += ' var ' + ($dataType) + ' = typeof ' + ($data) + '; ';
4371 if (it.opts.coerceTypes == 'array') {
4372 out += ' if (' + ($dataType) + ' == \'object\' && Array.isArray(' + ($data) + ')) ' + ($dataType) + ' = \'array\'; ';
4374 out += ' var ' + ($coerced) + ' = undefined; ';
4375 var $bracesCoercion = '';
4376 var arr1 = $coerceToTypes;
4379 l1 = arr1.length - 1;
4381 $type = arr1[$i += 1];
4383 out += ' if (' + ($coerced) + ' === undefined) { ';
4384 $bracesCoercion += '}';
4386 if (it.opts.coerceTypes == 'array' && $type != 'array') {
4387 out += ' if (' + ($dataType) + ' == \'array\' && ' + ($data) + '.length == 1) { ' + ($coerced) + ' = ' + ($data) + ' = ' + ($data) + '[0]; ' + ($dataType) + ' = typeof ' + ($data) + '; } ';
4389 if ($type == 'string') {
4390 out += ' if (' + ($dataType) + ' == \'number\' || ' + ($dataType) + ' == \'boolean\') ' + ($coerced) + ' = \'\' + ' + ($data) + '; else if (' + ($data) + ' === null) ' + ($coerced) + ' = \'\'; ';
4391 } else if ($type == 'number' || $type == 'integer') {
4392 out += ' if (' + ($dataType) + ' == \'boolean\' || ' + ($data) + ' === null || (' + ($dataType) + ' == \'string\' && ' + ($data) + ' && ' + ($data) + ' == +' + ($data) + ' ';
4393 if ($type == 'integer') {
4394 out += ' && !(' + ($data) + ' % 1)';
4396 out += ')) ' + ($coerced) + ' = +' + ($data) + '; ';
4397 } else if ($type == 'boolean') {
4398 out += ' if (' + ($data) + ' === \'false\' || ' + ($data) + ' === 0 || ' + ($data) + ' === null) ' + ($coerced) + ' = false; else if (' + ($data) + ' === \'true\' || ' + ($data) + ' === 1) ' + ($coerced) + ' = true; ';
4399 } else if ($type == 'null') {
4400 out += ' if (' + ($data) + ' === \'\' || ' + ($data) + ' === 0 || ' + ($data) + ' === false) ' + ($coerced) + ' = null; ';
4401 } else if (it.opts.coerceTypes == 'array' && $type == 'array') {
4402 out += ' if (' + ($dataType) + ' == \'string\' || ' + ($dataType) + ' == \'number\' || ' + ($dataType) + ' == \'boolean\' || ' + ($data) + ' == null) ' + ($coerced) + ' = [' + ($data) + ']; ';
4406 out += ' ' + ($bracesCoercion) + ' if (' + ($coerced) + ' === undefined) { ';
4407 var $$outStack = $$outStack || [];
4408 $$outStack.push(out);
4409 out = ''; /* istanbul ignore else */
4410 if (it.createErrors !== false) {
4411 out += ' { keyword: \'' + ($errorKeyword || 'type') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: ' + (it.util.toQuotedString($errSchemaPath)) + ' , params: { type: \'';
4413 out += '' + ($typeSchema.join(","));
4415 out += '' + ($typeSchema);
4418 if (it.opts.messages !== false) {
4419 out += ' , message: \'should be ';
4421 out += '' + ($typeSchema.join(","));
4423 out += '' + ($typeSchema);
4427 if (it.opts.verbose) {
4428 out += ' , schema: validate.schema' + ($schemaPath) + ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' ';
4435 out = $$outStack.pop();
4436 if (!it.compositeRule && $breakOnError) {
4437 /* istanbul ignore if */
4439 out += ' throw new ValidationError([' + (__err) + ']); ';
4441 out += ' validate.errors = [' + (__err) + ']; return false; ';
4444 out += ' var err = ' + (__err) + '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ';
4446 out += ' } else { ';
4447 var $parentData = $dataLvl ? 'data' + (($dataLvl - 1) || '') : 'parentData',
4448 $parentDataProperty = $dataLvl ? it.dataPathArr[$dataLvl] : 'parentDataProperty';
4449 out += ' ' + ($data) + ' = ' + ($coerced) + '; ';
4451 out += 'if (' + ($parentData) + ' !== undefined)';
4453 out += ' ' + ($parentData) + '[' + ($parentDataProperty) + '] = ' + ($coerced) + '; } ';
4455 var $$outStack = $$outStack || [];
4456 $$outStack.push(out);
4457 out = ''; /* istanbul ignore else */
4458 if (it.createErrors !== false) {
4459 out += ' { keyword: \'' + ($errorKeyword || 'type') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: ' + (it.util.toQuotedString($errSchemaPath)) + ' , params: { type: \'';
4461 out += '' + ($typeSchema.join(","));
4463 out += '' + ($typeSchema);
4466 if (it.opts.messages !== false) {
4467 out += ' , message: \'should be ';
4469 out += '' + ($typeSchema.join(","));
4471 out += '' + ($typeSchema);
4475 if (it.opts.verbose) {
4476 out += ' , schema: validate.schema' + ($schemaPath) + ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' ';
4483 out = $$outStack.pop();
4484 if (!it.compositeRule && $breakOnError) {
4485 /* istanbul ignore if */
4487 out += ' throw new ValidationError([' + (__err) + ']); ';
4489 out += ' validate.errors = [' + (__err) + ']; return false; ';
4492 out += ' var err = ' + (__err) + '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ';
4498 if (it.schema.$ref && !$refKeywords) {
4499 out += ' ' + (it.RULES.all.$ref.code(it, '$ref')) + ' ';
4500 if ($breakOnError) {
4501 out += ' } if (errors === ';
4505 out += 'errs_' + ($lvl);
4508 $closingBraces2 += '}';
4511 var arr2 = it.RULES;
4513 var $rulesGroup, i2 = -1,
4514 l2 = arr2.length - 1;
4516 $rulesGroup = arr2[i2 += 1];
4517 if ($shouldUseGroup($rulesGroup)) {
4518 if ($rulesGroup.type) {
4519 out += ' if (' + (it.util.checkDataType($rulesGroup.type, $data, it.opts.strictNumbers)) + ') { ';
4521 if (it.opts.useDefaults) {
4522 if ($rulesGroup.type == 'object' && it.schema.properties) {
4523 var $schema = it.schema.properties,
4524 $schemaKeys = Object.keys($schema);
4525 var arr3 = $schemaKeys;
4527 var $propertyKey, i3 = -1,
4528 l3 = arr3.length - 1;
4530 $propertyKey = arr3[i3 += 1];
4531 var $sch = $schema[$propertyKey];
4532 if ($sch.default !== undefined) {
4533 var $passData = $data + it.util.getProperty($propertyKey);
4534 if (it.compositeRule) {
4535 if (it.opts.strictDefaults) {
4536 var $defaultMsg = 'default is ignored for: ' + $passData;
4537 if (it.opts.strictDefaults === 'log') it.logger.warn($defaultMsg);
4538 else throw new Error($defaultMsg);
4541 out += ' if (' + ($passData) + ' === undefined ';
4542 if (it.opts.useDefaults == 'empty') {
4543 out += ' || ' + ($passData) + ' === null || ' + ($passData) + ' === \'\' ';
4545 out += ' ) ' + ($passData) + ' = ';
4546 if (it.opts.useDefaults == 'shared') {
4547 out += ' ' + (it.useDefault($sch.default)) + ' ';
4549 out += ' ' + (JSON.stringify($sch.default)) + ' ';
4556 } else if ($rulesGroup.type == 'array' && Array.isArray(it.schema.items)) {
4557 var arr4 = it.schema.items;
4560 l4 = arr4.length - 1;
4562 $sch = arr4[$i += 1];
4563 if ($sch.default !== undefined) {
4564 var $passData = $data + '[' + $i + ']';
4565 if (it.compositeRule) {
4566 if (it.opts.strictDefaults) {
4567 var $defaultMsg = 'default is ignored for: ' + $passData;
4568 if (it.opts.strictDefaults === 'log') it.logger.warn($defaultMsg);
4569 else throw new Error($defaultMsg);
4572 out += ' if (' + ($passData) + ' === undefined ';
4573 if (it.opts.useDefaults == 'empty') {
4574 out += ' || ' + ($passData) + ' === null || ' + ($passData) + ' === \'\' ';
4576 out += ' ) ' + ($passData) + ' = ';
4577 if (it.opts.useDefaults == 'shared') {
4578 out += ' ' + (it.useDefault($sch.default)) + ' ';
4580 out += ' ' + (JSON.stringify($sch.default)) + ' ';
4589 var arr5 = $rulesGroup.rules;
4592 l5 = arr5.length - 1;
4594 $rule = arr5[i5 += 1];
4595 if ($shouldUseRule($rule)) {
4596 var $code = $rule.code(it, $rule.keyword, $rulesGroup.type);
4598 out += ' ' + ($code) + ' ';
4599 if ($breakOnError) {
4600 $closingBraces1 += '}';
4606 if ($breakOnError) {
4607 out += ' ' + ($closingBraces1) + ' ';
4608 $closingBraces1 = '';
4610 if ($rulesGroup.type) {
4612 if ($typeSchema && $typeSchema === $rulesGroup.type && !$coerceToTypes) {
4614 var $schemaPath = it.schemaPath + '.type',
4615 $errSchemaPath = it.errSchemaPath + '/type';
4616 var $$outStack = $$outStack || [];
4617 $$outStack.push(out);
4618 out = ''; /* istanbul ignore else */
4619 if (it.createErrors !== false) {
4620 out += ' { keyword: \'' + ($errorKeyword || 'type') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: ' + (it.util.toQuotedString($errSchemaPath)) + ' , params: { type: \'';
4622 out += '' + ($typeSchema.join(","));
4624 out += '' + ($typeSchema);
4627 if (it.opts.messages !== false) {
4628 out += ' , message: \'should be ';
4630 out += '' + ($typeSchema.join(","));
4632 out += '' + ($typeSchema);
4636 if (it.opts.verbose) {
4637 out += ' , schema: validate.schema' + ($schemaPath) + ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' ';
4644 out = $$outStack.pop();
4645 if (!it.compositeRule && $breakOnError) {
4646 /* istanbul ignore if */
4648 out += ' throw new ValidationError([' + (__err) + ']); ';
4650 out += ' validate.errors = [' + (__err) + ']; return false; ';
4653 out += ' var err = ' + (__err) + '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ';
4658 if ($breakOnError) {
4659 out += ' if (errors === ';
4663 out += 'errs_' + ($lvl);
4666 $closingBraces2 += '}';
4672 if ($breakOnError) {
4673 out += ' ' + ($closingBraces2) + ' ';
4677 out += ' if (errors === 0) return data; ';
4678 out += ' else throw new ValidationError(vErrors); ';
4680 out += ' validate.errors = vErrors; ';
4681 out += ' return errors === 0; ';
4683 out += ' }; return validate;';
4685 out += ' var ' + ($valid) + ' = errors === errs_' + ($lvl) + ';';
4688 function $shouldUseGroup($rulesGroup) {
4689 var rules = $rulesGroup.rules;
4690 for (var i = 0; i < rules.length; i++)
4691 if ($shouldUseRule(rules[i])) return true;
4694 function $shouldUseRule($rule) {
4695 return it.schema[$rule.keyword] !== undefined || ($rule.implements && $ruleImplementsSomeKeyword($rule));
4698 function $ruleImplementsSomeKeyword($rule) {
4699 var impl = $rule.implements;
4700 for (var i = 0; i < impl.length; i++)
4701 if (it.schema[impl[i]] !== undefined) return true;
4706 },{}],39:[function(require,module,exports){
4709 var IDENTIFIER = /^[a-z_$][a-z0-9_$-]*$/i;
4710 var customRuleCode = require('./dotjs/custom');
4711 var definitionSchema = require('./definition_schema');
4716 remove: removeKeyword,
4717 validate: validateKeyword
4722 * Define custom keyword
4724 * @param {String} keyword custom keyword, should be unique (including different from all standard, custom and macro keywords).
4725 * @param {Object} definition keyword definition object with properties `type` (type(s) which the keyword applies to), `validate` or `compile`.
4726 * @return {Ajv} this for method chaining
4728 function addKeyword(keyword, definition) {
4729 /* jshint validthis: true */
4730 /* eslint no-shadow: 0 */
4731 var RULES = this.RULES;
4732 if (RULES.keywords[keyword])
4733 throw new Error('Keyword ' + keyword + ' is already defined');
4735 if (!IDENTIFIER.test(keyword))
4736 throw new Error('Keyword ' + keyword + ' is not a valid identifier');
4739 this.validateKeyword(definition, true);
4741 var dataType = definition.type;
4742 if (Array.isArray(dataType)) {
4743 for (var i=0; i<dataType.length; i++)
4744 _addRule(keyword, dataType[i], definition);
4746 _addRule(keyword, dataType, definition);
4749 var metaSchema = definition.metaSchema;
4751 if (definition.$data && this._opts.$data) {
4755 { '$ref': 'https://raw.githubusercontent.com/ajv-validator/ajv/master/lib/refs/data.json#' }
4759 definition.validateSchema = this.compile(metaSchema, true);
4763 RULES.keywords[keyword] = RULES.all[keyword] = true;
4766 function _addRule(keyword, dataType, definition) {
4768 for (var i=0; i<RULES.length; i++) {
4770 if (rg.type == dataType) {
4777 ruleGroup = { type: dataType, rules: [] };
4778 RULES.push(ruleGroup);
4783 definition: definition,
4785 code: customRuleCode,
4786 implements: definition.implements
4788 ruleGroup.rules.push(rule);
4789 RULES.custom[keyword] = rule;
4799 * @param {String} keyword pre-defined or custom keyword.
4800 * @return {Object|Boolean} custom keyword definition, `true` if it is a predefined keyword, `false` otherwise.
4802 function getKeyword(keyword) {
4803 /* jshint validthis: true */
4804 var rule = this.RULES.custom[keyword];
4805 return rule ? rule.definition : this.RULES.keywords[keyword] || false;
4812 * @param {String} keyword pre-defined or custom keyword.
4813 * @return {Ajv} this for method chaining
4815 function removeKeyword(keyword) {
4816 /* jshint validthis: true */
4817 var RULES = this.RULES;
4818 delete RULES.keywords[keyword];
4819 delete RULES.all[keyword];
4820 delete RULES.custom[keyword];
4821 for (var i=0; i<RULES.length; i++) {
4822 var rules = RULES[i].rules;
4823 for (var j=0; j<rules.length; j++) {
4824 if (rules[j].keyword == keyword) {
4835 * Validate keyword definition
4837 * @param {Object} definition keyword definition object.
4838 * @param {Boolean} throwError true to throw exception if definition is invalid
4839 * @return {boolean} validation result
4841 function validateKeyword(definition, throwError) {
4842 validateKeyword.errors = null;
4843 var v = this._validateKeyword = this._validateKeyword
4844 || this.compile(definitionSchema, true);
4846 if (v(definition)) return true;
4847 validateKeyword.errors = v.errors;
4849 throw new Error('custom keyword definition is invalid: ' + this.errorsText(v.errors));
4854 },{"./definition_schema":12,"./dotjs/custom":22}],40:[function(require,module,exports){
4856 "$schema": "http://json-schema.org/draft-07/schema#",
4857 "$id": "https://raw.githubusercontent.com/ajv-validator/ajv/master/lib/refs/data.json#",
4858 "description": "Meta-schema for $data reference (JSON Schema extension proposal)",
4860 "required": [ "$data" ],
4865 { "format": "relative-json-pointer" },
4866 { "format": "json-pointer" }
4870 "additionalProperties": false
4873 },{}],41:[function(require,module,exports){
4875 "$schema": "http://json-schema.org/draft-07/schema#",
4876 "$id": "http://json-schema.org/draft-07/schema#",
4877 "title": "Core schema meta-schema",
4882 "items": { "$ref": "#" }
4884 "nonNegativeInteger": {
4888 "nonNegativeIntegerDefault0": {
4890 { "$ref": "#/definitions/nonNegativeInteger" },
4907 "items": { "type": "string" },
4908 "uniqueItems": true,
4912 "type": ["object", "boolean"],
4916 "format": "uri-reference"
4924 "format": "uri-reference"
4946 "exclusiveMinimum": 0
4951 "exclusiveMaximum": {
4957 "exclusiveMinimum": {
4960 "maxLength": { "$ref": "#/definitions/nonNegativeInteger" },
4961 "minLength": { "$ref": "#/definitions/nonNegativeIntegerDefault0" },
4966 "additionalItems": { "$ref": "#" },
4970 { "$ref": "#/definitions/schemaArray" }
4974 "maxItems": { "$ref": "#/definitions/nonNegativeInteger" },
4975 "minItems": { "$ref": "#/definitions/nonNegativeIntegerDefault0" },
4980 "contains": { "$ref": "#" },
4981 "maxProperties": { "$ref": "#/definitions/nonNegativeInteger" },
4982 "minProperties": { "$ref": "#/definitions/nonNegativeIntegerDefault0" },
4983 "required": { "$ref": "#/definitions/stringArray" },
4984 "additionalProperties": { "$ref": "#" },
4987 "additionalProperties": { "$ref": "#" },
4992 "additionalProperties": { "$ref": "#" },
4995 "patternProperties": {
4997 "additionalProperties": { "$ref": "#" },
4998 "propertyNames": { "format": "regex" },
5003 "additionalProperties": {
5006 { "$ref": "#/definitions/stringArray" }
5010 "propertyNames": { "$ref": "#" },
5020 { "$ref": "#/definitions/simpleTypes" },
5023 "items": { "$ref": "#/definitions/simpleTypes" },
5029 "format": { "type": "string" },
5030 "contentMediaType": { "type": "string" },
5031 "contentEncoding": { "type": "string" },
5032 "if": {"$ref": "#"},
5033 "then": {"$ref": "#"},
5034 "else": {"$ref": "#"},
5035 "allOf": { "$ref": "#/definitions/schemaArray" },
5036 "anyOf": { "$ref": "#/definitions/schemaArray" },
5037 "oneOf": { "$ref": "#/definitions/schemaArray" },
5038 "not": { "$ref": "#" }
5043 },{}],42:[function(require,module,exports){
5046 // do not edit .js files directly - edit src/index.jst
5050 module.exports = function equal(a, b) {
5051 if (a === b) return true;
5053 if (a && b && typeof a == 'object' && typeof b == 'object') {
5054 if (a.constructor !== b.constructor) return false;
5056 var length, i, keys;
5057 if (Array.isArray(a)) {
5059 if (length != b.length) return false;
5060 for (i = length; i-- !== 0;)
5061 if (!equal(a[i], b[i])) return false;
5067 if (a.constructor === RegExp) return a.source === b.source && a.flags === b.flags;
5068 if (a.valueOf !== Object.prototype.valueOf) return a.valueOf() === b.valueOf();
5069 if (a.toString !== Object.prototype.toString) return a.toString() === b.toString();
5071 keys = Object.keys(a);
5072 length = keys.length;
5073 if (length !== Object.keys(b).length) return false;
5075 for (i = length; i-- !== 0;)
5076 if (!Object.prototype.hasOwnProperty.call(b, keys[i])) return false;
5078 for (i = length; i-- !== 0;) {
5081 if (!equal(a[key], b[key])) return false;
5087 // true if both NaN, false otherwise
5088 return a!==a && b!==b;
5091 },{}],43:[function(require,module,exports){
5094 module.exports = function (data, opts) {
5095 if (!opts) opts = {};
5096 if (typeof opts === 'function') opts = { cmp: opts };
5097 var cycles = (typeof opts.cycles === 'boolean') ? opts.cycles : false;
5099 var cmp = opts.cmp && (function (f) {
5100 return function (node) {
5101 return function (a, b) {
5102 var aobj = { key: a, value: node[a] };
5103 var bobj = { key: b, value: node[b] };
5104 return f(aobj, bobj);
5110 return (function stringify (node) {
5111 if (node && node.toJSON && typeof node.toJSON === 'function') {
5112 node = node.toJSON();
5115 if (node === undefined) return;
5116 if (typeof node == 'number') return isFinite(node) ? '' + node : 'null';
5117 if (typeof node !== 'object') return JSON.stringify(node);
5120 if (Array.isArray(node)) {
5122 for (i = 0; i < node.length; i++) {
5124 out += stringify(node[i]) || 'null';
5129 if (node === null) return 'null';
5131 if (seen.indexOf(node) !== -1) {
5132 if (cycles) return JSON.stringify('__cycle__');
5133 throw new TypeError('Converting circular structure to JSON');
5136 var seenIndex = seen.push(node) - 1;
5137 var keys = Object.keys(node).sort(cmp && cmp(node));
5139 for (i = 0; i < keys.length; i++) {
5141 var value = stringify(node[key]);
5143 if (!value) continue;
5144 if (out) out += ',';
5145 out += JSON.stringify(key) + ':' + value;
5147 seen.splice(seenIndex, 1);
5148 return '{' + out + '}';
5152 },{}],44:[function(require,module,exports){
5155 var traverse = module.exports = function (schema, opts, cb) {
5156 // Legacy support for v0.3.1 and earlier.
5157 if (typeof opts == 'function') {
5163 var pre = (typeof cb == 'function') ? cb : cb.pre || function() {};
5164 var post = cb.post || function() {};
5166 _traverse(opts, pre, post, schema, '', schema);
5170 traverse.keywords = {
5171 additionalItems: true,
5174 additionalProperties: true,
5175 propertyNames: true,
5179 traverse.arrayKeywords = {
5186 traverse.propsKeywords = {
5189 patternProperties: true,
5193 traverse.skipKeywords = {
5200 exclusiveMaximum: true,
5201 exclusiveMinimum: true,
5210 maxProperties: true,
5215 function _traverse(opts, pre, post, schema, jsonPtr, rootSchema, parentJsonPtr, parentKeyword, parentSchema, keyIndex) {
5216 if (schema && typeof schema == 'object' && !Array.isArray(schema)) {
5217 pre(schema, jsonPtr, rootSchema, parentJsonPtr, parentKeyword, parentSchema, keyIndex);
5218 for (var key in schema) {
5219 var sch = schema[key];
5220 if (Array.isArray(sch)) {
5221 if (key in traverse.arrayKeywords) {
5222 for (var i=0; i<sch.length; i++)
5223 _traverse(opts, pre, post, sch[i], jsonPtr + '/' + key + '/' + i, rootSchema, jsonPtr, key, schema, i);
5225 } else if (key in traverse.propsKeywords) {
5226 if (sch && typeof sch == 'object') {
5227 for (var prop in sch)
5228 _traverse(opts, pre, post, sch[prop], jsonPtr + '/' + key + '/' + escapeJsonPtr(prop), rootSchema, jsonPtr, key, schema, prop);
5230 } else if (key in traverse.keywords || (opts.allKeys && !(key in traverse.skipKeywords))) {
5231 _traverse(opts, pre, post, sch, jsonPtr + '/' + key, rootSchema, jsonPtr, key, schema);
5234 post(schema, jsonPtr, rootSchema, parentJsonPtr, parentKeyword, parentSchema, keyIndex);
5239 function escapeJsonPtr(str) {
5240 return str.replace(/~/g, '~0').replace(/\//g, '~1');
5243 },{}],45:[function(require,module,exports){
5244 /** @license URI.js v4.2.1 (c) 2011 Gary Court. License: http://github.com/garycourt/uri-js */
5245 (function (global, factory) {
5246 typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
5247 typeof define === 'function' && define.amd ? define(['exports'], factory) :
5248 (factory((global.URI = global.URI || {})));
5249 }(this, (function (exports) { 'use strict';
5252 for (var _len = arguments.length, sets = Array(_len), _key = 0; _key < _len; _key++) {
5253 sets[_key] = arguments[_key];
5256 if (sets.length > 1) {
5257 sets[0] = sets[0].slice(0, -1);
5258 var xl = sets.length - 1;
5259 for (var x = 1; x < xl; ++x) {
5260 sets[x] = sets[x].slice(1, -1);
5262 sets[xl] = sets[xl].slice(1);
5263 return sets.join('');
5268 function subexp(str) {
5269 return "(?:" + str + ")";
5271 function typeOf(o) {
5272 return o === undefined ? "undefined" : o === null ? "null" : Object.prototype.toString.call(o).split(" ").pop().split("]").shift().toLowerCase();
5274 function toUpperCase(str) {
5275 return str.toUpperCase();
5277 function toArray(obj) {
5278 return obj !== undefined && obj !== null ? obj instanceof Array ? obj : typeof obj.length !== "number" || obj.split || obj.setInterval || obj.call ? [obj] : Array.prototype.slice.call(obj) : [];
5280 function assign(target, source) {
5283 for (var key in source) {
5284 obj[key] = source[key];
5290 function buildExps(isIRI) {
5291 var ALPHA$$ = "[A-Za-z]",
5294 DQUOTE$$ = "[\\x22]",
5295 HEXDIG$$ = merge(DIGIT$$, "[A-Fa-f]"),
5299 PCT_ENCODED$ = subexp(subexp("%[EFef]" + HEXDIG$$ + "%" + HEXDIG$$ + HEXDIG$$ + "%" + HEXDIG$$ + HEXDIG$$) + "|" + subexp("%[89A-Fa-f]" + HEXDIG$$ + "%" + HEXDIG$$ + HEXDIG$$) + "|" + subexp("%" + HEXDIG$$ + HEXDIG$$)),
5301 GEN_DELIMS$$ = "[\\:\\/\\?\\#\\[\\]\\@]",
5302 SUB_DELIMS$$ = "[\\!\\$\\&\\'\\(\\)\\*\\+\\,\\;\\=]",
5303 RESERVED$$ = merge(GEN_DELIMS$$, SUB_DELIMS$$),
5304 UCSCHAR$$ = isIRI ? "[\\xA0-\\u200D\\u2010-\\u2029\\u202F-\\uD7FF\\uF900-\\uFDCF\\uFDF0-\\uFFEF]" : "[]",
5305 //subset, excludes bidi control characters
5306 IPRIVATE$$ = isIRI ? "[\\uE000-\\uF8FF]" : "[]",
5308 UNRESERVED$$ = merge(ALPHA$$, DIGIT$$, "[\\-\\.\\_\\~]", UCSCHAR$$),
5309 SCHEME$ = subexp(ALPHA$$ + merge(ALPHA$$, DIGIT$$, "[\\+\\-\\.]") + "*"),
5310 USERINFO$ = subexp(subexp(PCT_ENCODED$ + "|" + merge(UNRESERVED$$, SUB_DELIMS$$, "[\\:]")) + "*"),
5311 DEC_OCTET$ = subexp(subexp("25[0-5]") + "|" + subexp("2[0-4]" + DIGIT$$) + "|" + subexp("1" + DIGIT$$ + DIGIT$$) + "|" + subexp("[1-9]" + DIGIT$$) + "|" + DIGIT$$),
5312 DEC_OCTET_RELAXED$ = subexp(subexp("25[0-5]") + "|" + subexp("2[0-4]" + DIGIT$$) + "|" + subexp("1" + DIGIT$$ + DIGIT$$) + "|" + subexp("0?[1-9]" + DIGIT$$) + "|0?0?" + DIGIT$$),
5313 //relaxed parsing rules
5314 IPV4ADDRESS$ = subexp(DEC_OCTET_RELAXED$ + "\\." + DEC_OCTET_RELAXED$ + "\\." + DEC_OCTET_RELAXED$ + "\\." + DEC_OCTET_RELAXED$),
5315 H16$ = subexp(HEXDIG$$ + "{1,4}"),
5316 LS32$ = subexp(subexp(H16$ + "\\:" + H16$) + "|" + IPV4ADDRESS$),
5317 IPV6ADDRESS1$ = subexp(subexp(H16$ + "\\:") + "{6}" + LS32$),
5318 // 6( h16 ":" ) ls32
5319 IPV6ADDRESS2$ = subexp("\\:\\:" + subexp(H16$ + "\\:") + "{5}" + LS32$),
5320 // "::" 5( h16 ":" ) ls32
5321 IPV6ADDRESS3$ = subexp(subexp(H16$) + "?\\:\\:" + subexp(H16$ + "\\:") + "{4}" + LS32$),
5322 //[ h16 ] "::" 4( h16 ":" ) ls32
5323 IPV6ADDRESS4$ = subexp(subexp(subexp(H16$ + "\\:") + "{0,1}" + H16$) + "?\\:\\:" + subexp(H16$ + "\\:") + "{3}" + LS32$),
5324 //[ *1( h16 ":" ) h16 ] "::" 3( h16 ":" ) ls32
5325 IPV6ADDRESS5$ = subexp(subexp(subexp(H16$ + "\\:") + "{0,2}" + H16$) + "?\\:\\:" + subexp(H16$ + "\\:") + "{2}" + LS32$),
5326 //[ *2( h16 ":" ) h16 ] "::" 2( h16 ":" ) ls32
5327 IPV6ADDRESS6$ = subexp(subexp(subexp(H16$ + "\\:") + "{0,3}" + H16$) + "?\\:\\:" + H16$ + "\\:" + LS32$),
5328 //[ *3( h16 ":" ) h16 ] "::" h16 ":" ls32
5329 IPV6ADDRESS7$ = subexp(subexp(subexp(H16$ + "\\:") + "{0,4}" + H16$) + "?\\:\\:" + LS32$),
5330 //[ *4( h16 ":" ) h16 ] "::" ls32
5331 IPV6ADDRESS8$ = subexp(subexp(subexp(H16$ + "\\:") + "{0,5}" + H16$) + "?\\:\\:" + H16$),
5332 //[ *5( h16 ":" ) h16 ] "::" h16
5333 IPV6ADDRESS9$ = subexp(subexp(subexp(H16$ + "\\:") + "{0,6}" + H16$) + "?\\:\\:"),
5334 //[ *6( h16 ":" ) h16 ] "::"
5335 IPV6ADDRESS$ = subexp([IPV6ADDRESS1$, IPV6ADDRESS2$, IPV6ADDRESS3$, IPV6ADDRESS4$, IPV6ADDRESS5$, IPV6ADDRESS6$, IPV6ADDRESS7$, IPV6ADDRESS8$, IPV6ADDRESS9$].join("|")),
5336 ZONEID$ = subexp(subexp(UNRESERVED$$ + "|" + PCT_ENCODED$) + "+"),
5338 IPV6ADDRZ$ = subexp(IPV6ADDRESS$ + "\\%25" + ZONEID$),
5340 IPV6ADDRZ_RELAXED$ = subexp(IPV6ADDRESS$ + subexp("\\%25|\\%(?!" + HEXDIG$$ + "{2})") + ZONEID$),
5341 //RFC 6874, with relaxed parsing rules
5342 IPVFUTURE$ = subexp("[vV]" + HEXDIG$$ + "+\\." + merge(UNRESERVED$$, SUB_DELIMS$$, "[\\:]") + "+"),
5343 IP_LITERAL$ = subexp("\\[" + subexp(IPV6ADDRZ_RELAXED$ + "|" + IPV6ADDRESS$ + "|" + IPVFUTURE$) + "\\]"),
5345 REG_NAME$ = subexp(subexp(PCT_ENCODED$ + "|" + merge(UNRESERVED$$, SUB_DELIMS$$)) + "*"),
5346 HOST$ = subexp(IP_LITERAL$ + "|" + IPV4ADDRESS$ + "(?!" + REG_NAME$ + ")" + "|" + REG_NAME$),
5347 PORT$ = subexp(DIGIT$$ + "*"),
5348 AUTHORITY$ = subexp(subexp(USERINFO$ + "@") + "?" + HOST$ + subexp("\\:" + PORT$) + "?"),
5349 PCHAR$ = subexp(PCT_ENCODED$ + "|" + merge(UNRESERVED$$, SUB_DELIMS$$, "[\\:\\@]")),
5350 SEGMENT$ = subexp(PCHAR$ + "*"),
5351 SEGMENT_NZ$ = subexp(PCHAR$ + "+"),
5352 SEGMENT_NZ_NC$ = subexp(subexp(PCT_ENCODED$ + "|" + merge(UNRESERVED$$, SUB_DELIMS$$, "[\\@]")) + "+"),
5353 PATH_ABEMPTY$ = subexp(subexp("\\/" + SEGMENT$) + "*"),
5354 PATH_ABSOLUTE$ = subexp("\\/" + subexp(SEGMENT_NZ$ + PATH_ABEMPTY$) + "?"),
5356 PATH_NOSCHEME$ = subexp(SEGMENT_NZ_NC$ + PATH_ABEMPTY$),
5358 PATH_ROOTLESS$ = subexp(SEGMENT_NZ$ + PATH_ABEMPTY$),
5360 PATH_EMPTY$ = "(?!" + PCHAR$ + ")",
5361 PATH$ = subexp(PATH_ABEMPTY$ + "|" + PATH_ABSOLUTE$ + "|" + PATH_NOSCHEME$ + "|" + PATH_ROOTLESS$ + "|" + PATH_EMPTY$),
5362 QUERY$ = subexp(subexp(PCHAR$ + "|" + merge("[\\/\\?]", IPRIVATE$$)) + "*"),
5363 FRAGMENT$ = subexp(subexp(PCHAR$ + "|[\\/\\?]") + "*"),
5364 HIER_PART$ = subexp(subexp("\\/\\/" + AUTHORITY$ + PATH_ABEMPTY$) + "|" + PATH_ABSOLUTE$ + "|" + PATH_ROOTLESS$ + "|" + PATH_EMPTY$),
5365 URI$ = subexp(SCHEME$ + "\\:" + HIER_PART$ + subexp("\\?" + QUERY$) + "?" + subexp("\\#" + FRAGMENT$) + "?"),
5366 RELATIVE_PART$ = subexp(subexp("\\/\\/" + AUTHORITY$ + PATH_ABEMPTY$) + "|" + PATH_ABSOLUTE$ + "|" + PATH_NOSCHEME$ + "|" + PATH_EMPTY$),
5367 RELATIVE$ = subexp(RELATIVE_PART$ + subexp("\\?" + QUERY$) + "?" + subexp("\\#" + FRAGMENT$) + "?"),
5368 URI_REFERENCE$ = subexp(URI$ + "|" + RELATIVE$),
5369 ABSOLUTE_URI$ = subexp(SCHEME$ + "\\:" + HIER_PART$ + subexp("\\?" + QUERY$) + "?"),
5370 GENERIC_REF$ = "^(" + SCHEME$ + ")\\:" + subexp(subexp("\\/\\/(" + subexp("(" + USERINFO$ + ")@") + "?(" + HOST$ + ")" + subexp("\\:(" + PORT$ + ")") + "?)") + "?(" + PATH_ABEMPTY$ + "|" + PATH_ABSOLUTE$ + "|" + PATH_ROOTLESS$ + "|" + PATH_EMPTY$ + ")") + subexp("\\?(" + QUERY$ + ")") + "?" + subexp("\\#(" + FRAGMENT$ + ")") + "?$",
5371 RELATIVE_REF$ = "^(){0}" + subexp(subexp("\\/\\/(" + subexp("(" + USERINFO$ + ")@") + "?(" + HOST$ + ")" + subexp("\\:(" + PORT$ + ")") + "?)") + "?(" + PATH_ABEMPTY$ + "|" + PATH_ABSOLUTE$ + "|" + PATH_NOSCHEME$ + "|" + PATH_EMPTY$ + ")") + subexp("\\?(" + QUERY$ + ")") + "?" + subexp("\\#(" + FRAGMENT$ + ")") + "?$",
5372 ABSOLUTE_REF$ = "^(" + SCHEME$ + ")\\:" + subexp(subexp("\\/\\/(" + subexp("(" + USERINFO$ + ")@") + "?(" + HOST$ + ")" + subexp("\\:(" + PORT$ + ")") + "?)") + "?(" + PATH_ABEMPTY$ + "|" + PATH_ABSOLUTE$ + "|" + PATH_ROOTLESS$ + "|" + PATH_EMPTY$ + ")") + subexp("\\?(" + QUERY$ + ")") + "?$",
5373 SAMEDOC_REF$ = "^" + subexp("\\#(" + FRAGMENT$ + ")") + "?$",
5374 AUTHORITY_REF$ = "^" + subexp("(" + USERINFO$ + ")@") + "?(" + HOST$ + ")" + subexp("\\:(" + PORT$ + ")") + "?$";
5376 NOT_SCHEME: new RegExp(merge("[^]", ALPHA$$, DIGIT$$, "[\\+\\-\\.]"), "g"),
5377 NOT_USERINFO: new RegExp(merge("[^\\%\\:]", UNRESERVED$$, SUB_DELIMS$$), "g"),
5378 NOT_HOST: new RegExp(merge("[^\\%\\[\\]\\:]", UNRESERVED$$, SUB_DELIMS$$), "g"),
5379 NOT_PATH: new RegExp(merge("[^\\%\\/\\:\\@]", UNRESERVED$$, SUB_DELIMS$$), "g"),
5380 NOT_PATH_NOSCHEME: new RegExp(merge("[^\\%\\/\\@]", UNRESERVED$$, SUB_DELIMS$$), "g"),
5381 NOT_QUERY: new RegExp(merge("[^\\%]", UNRESERVED$$, SUB_DELIMS$$, "[\\:\\@\\/\\?]", IPRIVATE$$), "g"),
5382 NOT_FRAGMENT: new RegExp(merge("[^\\%]", UNRESERVED$$, SUB_DELIMS$$, "[\\:\\@\\/\\?]"), "g"),
5383 ESCAPE: new RegExp(merge("[^]", UNRESERVED$$, SUB_DELIMS$$), "g"),
5384 UNRESERVED: new RegExp(UNRESERVED$$, "g"),
5385 OTHER_CHARS: new RegExp(merge("[^\\%]", UNRESERVED$$, RESERVED$$), "g"),
5386 PCT_ENCODED: new RegExp(PCT_ENCODED$, "g"),
5387 IPV4ADDRESS: new RegExp("^(" + IPV4ADDRESS$ + ")$"),
5388 IPV6ADDRESS: new RegExp("^\\[?(" + IPV6ADDRESS$ + ")" + subexp(subexp("\\%25|\\%(?!" + HEXDIG$$ + "{2})") + "(" + ZONEID$ + ")") + "?\\]?$") //RFC 6874, with relaxed parsing rules
5391 var URI_PROTOCOL = buildExps(false);
5393 var IRI_PROTOCOL = buildExps(true);
5395 var slicedToArray = function () {
5396 function sliceIterator(arr, i) {
5403 for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) {
5404 _arr.push(_s.value);
5406 if (i && _arr.length === i) break;
5413 if (!_n && _i["return"]) _i["return"]();
5422 return function (arr, i) {
5423 if (Array.isArray(arr)) {
5425 } else if (Symbol.iterator in Object(arr)) {
5426 return sliceIterator(arr, i);
5428 throw new TypeError("Invalid attempt to destructure non-iterable instance");
5445 var toConsumableArray = function (arr) {
5446 if (Array.isArray(arr)) {
5447 for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) arr2[i] = arr[i];
5451 return Array.from(arr);
5455 /** Highest positive signed 32-bit float value */
5457 var maxInt = 2147483647; // aka. 0x7FFFFFFF or 2^31-1
5459 /** Bootstring parameters */
5465 var initialBias = 72;
5466 var initialN = 128; // 0x80
5467 var delimiter = '-'; // '\x2D'
5469 /** Regular expressions */
5470 var regexPunycode = /^xn--/;
5471 var regexNonASCII = /[^\0-\x7E]/; // non-ASCII chars
5472 var regexSeparators = /[\x2E\u3002\uFF0E\uFF61]/g; // RFC 3490 separators
5474 /** Error messages */
5476 'overflow': 'Overflow: input needs wider integers to process',
5477 'not-basic': 'Illegal input >= 0x80 (not a basic code point)',
5478 'invalid-input': 'Invalid input'
5481 /** Convenience shortcuts */
5482 var baseMinusTMin = base - tMin;
5483 var floor = Math.floor;
5484 var stringFromCharCode = String.fromCharCode;
5486 /*--------------------------------------------------------------------------*/
5489 * A generic error utility function.
5491 * @param {String} type The error type.
5492 * @returns {Error} Throws a `RangeError` with the applicable error message.
5494 function error$1(type) {
5495 throw new RangeError(errors[type]);
5499 * A generic `Array#map` utility function.
5501 * @param {Array} array The array to iterate over.
5502 * @param {Function} callback The function that gets called for every array
5504 * @returns {Array} A new array of values returned by the callback function.
5506 function map(array, fn) {
5508 var length = array.length;
5510 result[length] = fn(array[length]);
5516 * A simple `Array#map`-like wrapper to work with domain name strings or email
5519 * @param {String} domain The domain name or email address.
5520 * @param {Function} callback The function that gets called for every
5522 * @returns {Array} A new string of characters returned by the callback
5525 function mapDomain(string, fn) {
5526 var parts = string.split('@');
5528 if (parts.length > 1) {
5529 // In email addresses, only the domain name should be punycoded. Leave
5530 // the local part (i.e. everything up to `@`) intact.
5531 result = parts[0] + '@';
5534 // Avoid `split(regex)` for IE8 compatibility. See #17.
5535 string = string.replace(regexSeparators, '\x2E');
5536 var labels = string.split('.');
5537 var encoded = map(labels, fn).join('.');
5538 return result + encoded;
5542 * Creates an array containing the numeric code points of each Unicode
5543 * character in the string. While JavaScript uses UCS-2 internally,
5544 * this function will convert a pair of surrogate halves (each of which
5545 * UCS-2 exposes as separate characters) into a single code point,
5547 * @see `punycode.ucs2.encode`
5548 * @see <https://mathiasbynens.be/notes/javascript-encoding>
5549 * @memberOf punycode.ucs2
5551 * @param {String} string The Unicode input string (UCS-2).
5552 * @returns {Array} The new array of code points.
5554 function ucs2decode(string) {
5557 var length = string.length;
5558 while (counter < length) {
5559 var value = string.charCodeAt(counter++);
5560 if (value >= 0xD800 && value <= 0xDBFF && counter < length) {
5561 // It's a high surrogate, and there is a next character.
5562 var extra = string.charCodeAt(counter++);
5563 if ((extra & 0xFC00) == 0xDC00) {
5565 output.push(((value & 0x3FF) << 10) + (extra & 0x3FF) + 0x10000);
5567 // It's an unmatched surrogate; only append this code unit, in case the
5568 // next code unit is the high surrogate of a surrogate pair.
5580 * Creates a string based on an array of numeric code points.
5581 * @see `punycode.ucs2.decode`
5582 * @memberOf punycode.ucs2
5584 * @param {Array} codePoints The array of numeric code points.
5585 * @returns {String} The new Unicode string (UCS-2).
5587 var ucs2encode = function ucs2encode(array) {
5588 return String.fromCodePoint.apply(String, toConsumableArray(array));
5592 * Converts a basic code point into a digit/integer.
5593 * @see `digitToBasic()`
5595 * @param {Number} codePoint The basic numeric code point value.
5596 * @returns {Number} The numeric value of a basic code point (for use in
5597 * representing integers) in the range `0` to `base - 1`, or `base` if
5598 * the code point does not represent a value.
5600 var basicToDigit = function basicToDigit(codePoint) {
5601 if (codePoint - 0x30 < 0x0A) {
5602 return codePoint - 0x16;
5604 if (codePoint - 0x41 < 0x1A) {
5605 return codePoint - 0x41;
5607 if (codePoint - 0x61 < 0x1A) {
5608 return codePoint - 0x61;
5614 * Converts a digit/integer into a basic code point.
5615 * @see `basicToDigit()`
5617 * @param {Number} digit The numeric value of a basic code point.
5618 * @returns {Number} The basic code point whose value (when used for
5619 * representing integers) is `digit`, which needs to be in the range
5620 * `0` to `base - 1`. If `flag` is non-zero, the uppercase form is
5621 * used; else, the lowercase form is used. The behavior is undefined
5622 * if `flag` is non-zero and `digit` has no uppercase form.
5624 var digitToBasic = function digitToBasic(digit, flag) {
5625 // 0..25 map to ASCII a..z or A..Z
5626 // 26..35 map to ASCII 0..9
5627 return digit + 22 + 75 * (digit < 26) - ((flag != 0) << 5);
5631 * Bias adaptation function as per section 3.4 of RFC 3492.
5632 * https://tools.ietf.org/html/rfc3492#section-3.4
5635 var adapt = function adapt(delta, numPoints, firstTime) {
5637 delta = firstTime ? floor(delta / damp) : delta >> 1;
5638 delta += floor(delta / numPoints);
5639 for (; /* no initialization */delta > baseMinusTMin * tMax >> 1; k += base) {
5640 delta = floor(delta / baseMinusTMin);
5642 return floor(k + (baseMinusTMin + 1) * delta / (delta + skew));
5646 * Converts a Punycode string of ASCII-only symbols to a string of Unicode
5648 * @memberOf punycode
5649 * @param {String} input The Punycode string of ASCII-only symbols.
5650 * @returns {String} The resulting string of Unicode symbols.
5652 var decode = function decode(input) {
5655 var inputLength = input.length;
5658 var bias = initialBias;
5660 // Handle the basic code points: let `basic` be the number of input code
5661 // points before the last delimiter, or `0` if there is none, then copy
5662 // the first basic code points to the output.
5664 var basic = input.lastIndexOf(delimiter);
5669 for (var j = 0; j < basic; ++j) {
5670 // if it's not a basic code point
5671 if (input.charCodeAt(j) >= 0x80) {
5672 error$1('not-basic');
5674 output.push(input.charCodeAt(j));
5677 // Main decoding loop: start just after the last delimiter if any basic code
5678 // points were copied; start at the beginning otherwise.
5680 for (var index = basic > 0 ? basic + 1 : 0; index < inputLength;) /* no final expression */{
5682 // `index` is the index of the next character to be consumed.
5683 // Decode a generalized variable-length integer into `delta`,
5684 // which gets added to `i`. The overflow checking is easier
5685 // if we increase `i` as we go, then subtract off its starting
5686 // value at the end to obtain `delta`.
5688 for (var w = 1, k = base;; /* no condition */k += base) {
5690 if (index >= inputLength) {
5691 error$1('invalid-input');
5694 var digit = basicToDigit(input.charCodeAt(index++));
5696 if (digit >= base || digit > floor((maxInt - i) / w)) {
5697 error$1('overflow');
5701 var t = k <= bias ? tMin : k >= bias + tMax ? tMax : k - bias;
5707 var baseMinusT = base - t;
5708 if (w > floor(maxInt / baseMinusT)) {
5709 error$1('overflow');
5715 var out = output.length + 1;
5716 bias = adapt(i - oldi, out, oldi == 0);
5718 // `i` was supposed to wrap around from `out` to `0`,
5719 // incrementing `n` each time, so we'll fix that now:
5720 if (floor(i / out) > maxInt - n) {
5721 error$1('overflow');
5724 n += floor(i / out);
5727 // Insert `n` at position `i` of the output.
5728 output.splice(i++, 0, n);
5731 return String.fromCodePoint.apply(String, output);
5735 * Converts a string of Unicode symbols (e.g. a domain name label) to a
5736 * Punycode string of ASCII-only symbols.
5737 * @memberOf punycode
5738 * @param {String} input The string of Unicode symbols.
5739 * @returns {String} The resulting Punycode string of ASCII-only symbols.
5741 var encode = function encode(input) {
5744 // Convert the input in UCS-2 to an array of Unicode code points.
5745 input = ucs2decode(input);
5747 // Cache the length.
5748 var inputLength = input.length;
5750 // Initialize the state.
5753 var bias = initialBias;
5755 // Handle the basic code points.
5756 var _iteratorNormalCompletion = true;
5757 var _didIteratorError = false;
5758 var _iteratorError = undefined;
5761 for (var _iterator = input[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
5762 var _currentValue2 = _step.value;
5764 if (_currentValue2 < 0x80) {
5765 output.push(stringFromCharCode(_currentValue2));
5769 _didIteratorError = true;
5770 _iteratorError = err;
5773 if (!_iteratorNormalCompletion && _iterator.return) {
5777 if (_didIteratorError) {
5778 throw _iteratorError;
5783 var basicLength = output.length;
5784 var handledCPCount = basicLength;
5786 // `handledCPCount` is the number of code points that have been handled;
5787 // `basicLength` is the number of basic code points.
5789 // Finish the basic string with a delimiter unless it's empty.
5791 output.push(delimiter);
5794 // Main encoding loop:
5795 while (handledCPCount < inputLength) {
5797 // All non-basic code points < n have been handled already. Find the next
5800 var _iteratorNormalCompletion2 = true;
5801 var _didIteratorError2 = false;
5802 var _iteratorError2 = undefined;
5805 for (var _iterator2 = input[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) {
5806 var currentValue = _step2.value;
5808 if (currentValue >= n && currentValue < m) {
5813 // Increase `delta` enough to advance the decoder's <n,i> state to <m,0>,
5814 // but guard against overflow.
5816 _didIteratorError2 = true;
5817 _iteratorError2 = err;
5820 if (!_iteratorNormalCompletion2 && _iterator2.return) {
5821 _iterator2.return();
5824 if (_didIteratorError2) {
5825 throw _iteratorError2;
5830 var handledCPCountPlusOne = handledCPCount + 1;
5831 if (m - n > floor((maxInt - delta) / handledCPCountPlusOne)) {
5832 error$1('overflow');
5835 delta += (m - n) * handledCPCountPlusOne;
5838 var _iteratorNormalCompletion3 = true;
5839 var _didIteratorError3 = false;
5840 var _iteratorError3 = undefined;
5843 for (var _iterator3 = input[Symbol.iterator](), _step3; !(_iteratorNormalCompletion3 = (_step3 = _iterator3.next()).done); _iteratorNormalCompletion3 = true) {
5844 var _currentValue = _step3.value;
5846 if (_currentValue < n && ++delta > maxInt) {
5847 error$1('overflow');
5849 if (_currentValue == n) {
5850 // Represent delta as a generalized variable-length integer.
5852 for (var k = base;; /* no condition */k += base) {
5853 var t = k <= bias ? tMin : k >= bias + tMax ? tMax : k - bias;
5857 var qMinusT = q - t;
5858 var baseMinusT = base - t;
5859 output.push(stringFromCharCode(digitToBasic(t + qMinusT % baseMinusT, 0)));
5860 q = floor(qMinusT / baseMinusT);
5863 output.push(stringFromCharCode(digitToBasic(q, 0)));
5864 bias = adapt(delta, handledCPCountPlusOne, handledCPCount == basicLength);
5870 _didIteratorError3 = true;
5871 _iteratorError3 = err;
5874 if (!_iteratorNormalCompletion3 && _iterator3.return) {
5875 _iterator3.return();
5878 if (_didIteratorError3) {
5879 throw _iteratorError3;
5887 return output.join('');
5891 * Converts a Punycode string representing a domain name or an email address
5892 * to Unicode. Only the Punycoded parts of the input will be converted, i.e.
5893 * it doesn't matter if you call it on a string that has already been
5894 * converted to Unicode.
5895 * @memberOf punycode
5896 * @param {String} input The Punycoded domain name or email address to
5897 * convert to Unicode.
5898 * @returns {String} The Unicode representation of the given Punycode
5901 var toUnicode = function toUnicode(input) {
5902 return mapDomain(input, function (string) {
5903 return regexPunycode.test(string) ? decode(string.slice(4).toLowerCase()) : string;
5908 * Converts a Unicode string representing a domain name or an email address to
5909 * Punycode. Only the non-ASCII parts of the domain name will be converted,
5910 * i.e. it doesn't matter if you call it with a domain that's already in
5912 * @memberOf punycode
5913 * @param {String} input The domain name or email address to convert, as a
5915 * @returns {String} The Punycode representation of the given domain name or
5918 var toASCII = function toASCII(input) {
5919 return mapDomain(input, function (string) {
5920 return regexNonASCII.test(string) ? 'xn--' + encode(string) : string;
5924 /*--------------------------------------------------------------------------*/
5926 /** Define the public API */
5929 * A string representing the current Punycode.js version number.
5930 * @memberOf punycode
5935 * An object of methods to convert from JavaScript's internal character
5936 * representation (UCS-2) to Unicode code points, and back.
5937 * @see <https://mathiasbynens.be/notes/javascript-encoding>
5938 * @memberOf punycode
5942 'decode': ucs2decode,
5943 'encode': ucs2encode
5948 'toUnicode': toUnicode
5954 * @fileoverview An RFC 3986 compliant, scheme extendable URI parsing/validating/resolving library for JavaScript.
5955 * @author <a href="mailto:gary.court@gmail.com">Gary Court</a>
5956 * @see http://github.com/garycourt/uri-js
5959 * Copyright 2011 Gary Court. All rights reserved.
5961 * Redistribution and use in source and binary forms, with or without modification, are
5962 * permitted provided that the following conditions are met:
5964 * 1. Redistributions of source code must retain the above copyright notice, this list of
5965 * conditions and the following disclaimer.
5967 * 2. Redistributions in binary form must reproduce the above copyright notice, this list
5968 * of conditions and the following disclaimer in the documentation and/or other materials
5969 * provided with the distribution.
5971 * THIS SOFTWARE IS PROVIDED BY GARY COURT ``AS IS'' AND ANY EXPRESS OR IMPLIED
5972 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
5973 * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GARY COURT OR
5974 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
5975 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
5976 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
5977 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
5978 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
5979 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
5981 * The views and conclusions contained in the software and documentation are those of the
5982 * authors and should not be interpreted as representing official policies, either expressed
5983 * or implied, of Gary Court.
5986 function pctEncChar(chr) {
5987 var c = chr.charCodeAt(0);
5989 if (c < 16) e = "%0" + c.toString(16).toUpperCase();else if (c < 128) e = "%" + c.toString(16).toUpperCase();else if (c < 2048) e = "%" + (c >> 6 | 192).toString(16).toUpperCase() + "%" + (c & 63 | 128).toString(16).toUpperCase();else e = "%" + (c >> 12 | 224).toString(16).toUpperCase() + "%" + (c >> 6 & 63 | 128).toString(16).toUpperCase() + "%" + (c & 63 | 128).toString(16).toUpperCase();
5992 function pctDecChars(str) {
5995 var il = str.length;
5997 var c = parseInt(str.substr(i + 1, 2), 16);
5999 newStr += String.fromCharCode(c);
6001 } else if (c >= 194 && c < 224) {
6003 var c2 = parseInt(str.substr(i + 4, 2), 16);
6004 newStr += String.fromCharCode((c & 31) << 6 | c2 & 63);
6006 newStr += str.substr(i, 6);
6009 } else if (c >= 224) {
6011 var _c = parseInt(str.substr(i + 4, 2), 16);
6012 var c3 = parseInt(str.substr(i + 7, 2), 16);
6013 newStr += String.fromCharCode((c & 15) << 12 | (_c & 63) << 6 | c3 & 63);
6015 newStr += str.substr(i, 9);
6019 newStr += str.substr(i, 3);
6025 function _normalizeComponentEncoding(components, protocol) {
6026 function decodeUnreserved(str) {
6027 var decStr = pctDecChars(str);
6028 return !decStr.match(protocol.UNRESERVED) ? str : decStr;
6030 if (components.scheme) components.scheme = String(components.scheme).replace(protocol.PCT_ENCODED, decodeUnreserved).toLowerCase().replace(protocol.NOT_SCHEME, "");
6031 if (components.userinfo !== undefined) components.userinfo = String(components.userinfo).replace(protocol.PCT_ENCODED, decodeUnreserved).replace(protocol.NOT_USERINFO, pctEncChar).replace(protocol.PCT_ENCODED, toUpperCase);
6032 if (components.host !== undefined) components.host = String(components.host).replace(protocol.PCT_ENCODED, decodeUnreserved).toLowerCase().replace(protocol.NOT_HOST, pctEncChar).replace(protocol.PCT_ENCODED, toUpperCase);
6033 if (components.path !== undefined) components.path = String(components.path).replace(protocol.PCT_ENCODED, decodeUnreserved).replace(components.scheme ? protocol.NOT_PATH : protocol.NOT_PATH_NOSCHEME, pctEncChar).replace(protocol.PCT_ENCODED, toUpperCase);
6034 if (components.query !== undefined) components.query = String(components.query).replace(protocol.PCT_ENCODED, decodeUnreserved).replace(protocol.NOT_QUERY, pctEncChar).replace(protocol.PCT_ENCODED, toUpperCase);
6035 if (components.fragment !== undefined) components.fragment = String(components.fragment).replace(protocol.PCT_ENCODED, decodeUnreserved).replace(protocol.NOT_FRAGMENT, pctEncChar).replace(protocol.PCT_ENCODED, toUpperCase);
6039 function _stripLeadingZeros(str) {
6040 return str.replace(/^0*(.*)/, "$1") || "0";
6042 function _normalizeIPv4(host, protocol) {
6043 var matches = host.match(protocol.IPV4ADDRESS) || [];
6045 var _matches = slicedToArray(matches, 2),
6046 address = _matches[1];
6049 return address.split(".").map(_stripLeadingZeros).join(".");
6054 function _normalizeIPv6(host, protocol) {
6055 var matches = host.match(protocol.IPV6ADDRESS) || [];
6057 var _matches2 = slicedToArray(matches, 3),
6058 address = _matches2[1],
6059 zone = _matches2[2];
6062 var _address$toLowerCase$ = address.toLowerCase().split('::').reverse(),
6063 _address$toLowerCase$2 = slicedToArray(_address$toLowerCase$, 2),
6064 last = _address$toLowerCase$2[0],
6065 first = _address$toLowerCase$2[1];
6067 var firstFields = first ? first.split(":").map(_stripLeadingZeros) : [];
6068 var lastFields = last.split(":").map(_stripLeadingZeros);
6069 var isLastFieldIPv4Address = protocol.IPV4ADDRESS.test(lastFields[lastFields.length - 1]);
6070 var fieldCount = isLastFieldIPv4Address ? 7 : 8;
6071 var lastFieldsStart = lastFields.length - fieldCount;
6072 var fields = Array(fieldCount);
6073 for (var x = 0; x < fieldCount; ++x) {
6074 fields[x] = firstFields[x] || lastFields[lastFieldsStart + x] || '';
6076 if (isLastFieldIPv4Address) {
6077 fields[fieldCount - 1] = _normalizeIPv4(fields[fieldCount - 1], protocol);
6079 var allZeroFields = fields.reduce(function (acc, field, index) {
6080 if (!field || field === "0") {
6081 var lastLongest = acc[acc.length - 1];
6082 if (lastLongest && lastLongest.index + lastLongest.length === index) {
6083 lastLongest.length++;
6085 acc.push({ index: index, length: 1 });
6090 var longestZeroFields = allZeroFields.sort(function (a, b) {
6091 return b.length - a.length;
6093 var newHost = void 0;
6094 if (longestZeroFields && longestZeroFields.length > 1) {
6095 var newFirst = fields.slice(0, longestZeroFields.index);
6096 var newLast = fields.slice(longestZeroFields.index + longestZeroFields.length);
6097 newHost = newFirst.join(":") + "::" + newLast.join(":");
6099 newHost = fields.join(":");
6102 newHost += "%" + zone;
6109 var URI_PARSE = /^(?:([^:\/?#]+):)?(?:\/\/((?:([^\/?#@]*)@)?(\[[^\/?#\]]+\]|[^\/?#:]*)(?:\:(\d*))?))?([^?#]*)(?:\?([^#]*))?(?:#((?:.|\n|\r)*))?/i;
6110 var NO_MATCH_IS_UNDEFINED = "".match(/(){0}/)[1] === undefined;
6111 function parse(uriString) {
6112 var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
6114 var components = {};
6115 var protocol = options.iri !== false ? IRI_PROTOCOL : URI_PROTOCOL;
6116 if (options.reference === "suffix") uriString = (options.scheme ? options.scheme + ":" : "") + "//" + uriString;
6117 var matches = uriString.match(URI_PARSE);
6119 if (NO_MATCH_IS_UNDEFINED) {
6120 //store each component
6121 components.scheme = matches[1];
6122 components.userinfo = matches[3];
6123 components.host = matches[4];
6124 components.port = parseInt(matches[5], 10);
6125 components.path = matches[6] || "";
6126 components.query = matches[7];
6127 components.fragment = matches[8];
6129 if (isNaN(components.port)) {
6130 components.port = matches[5];
6133 //IE FIX for improper RegExp matching
6134 //store each component
6135 components.scheme = matches[1] || undefined;
6136 components.userinfo = uriString.indexOf("@") !== -1 ? matches[3] : undefined;
6137 components.host = uriString.indexOf("//") !== -1 ? matches[4] : undefined;
6138 components.port = parseInt(matches[5], 10);
6139 components.path = matches[6] || "";
6140 components.query = uriString.indexOf("?") !== -1 ? matches[7] : undefined;
6141 components.fragment = uriString.indexOf("#") !== -1 ? matches[8] : undefined;
6143 if (isNaN(components.port)) {
6144 components.port = uriString.match(/\/\/(?:.|\n)*\:(?:\/|\?|\#|$)/) ? matches[4] : undefined;
6147 if (components.host) {
6148 //normalize IP hosts
6149 components.host = _normalizeIPv6(_normalizeIPv4(components.host, protocol), protocol);
6151 //determine reference type
6152 if (components.scheme === undefined && components.userinfo === undefined && components.host === undefined && components.port === undefined && !components.path && components.query === undefined) {
6153 components.reference = "same-document";
6154 } else if (components.scheme === undefined) {
6155 components.reference = "relative";
6156 } else if (components.fragment === undefined) {
6157 components.reference = "absolute";
6159 components.reference = "uri";
6161 //check for reference errors
6162 if (options.reference && options.reference !== "suffix" && options.reference !== components.reference) {
6163 components.error = components.error || "URI is not a " + options.reference + " reference.";
6165 //find scheme handler
6166 var schemeHandler = SCHEMES[(options.scheme || components.scheme || "").toLowerCase()];
6167 //check if scheme can't handle IRIs
6168 if (!options.unicodeSupport && (!schemeHandler || !schemeHandler.unicodeSupport)) {
6169 //if host component is a domain name
6170 if (components.host && (options.domainHost || schemeHandler && schemeHandler.domainHost)) {
6171 //convert Unicode IDN -> ASCII IDN
6173 components.host = punycode.toASCII(components.host.replace(protocol.PCT_ENCODED, pctDecChars).toLowerCase());
6175 components.error = components.error || "Host's domain name can not be converted to ASCII via punycode: " + e;
6178 //convert IRI -> URI
6179 _normalizeComponentEncoding(components, URI_PROTOCOL);
6181 //normalize encodings
6182 _normalizeComponentEncoding(components, protocol);
6184 //perform scheme specific parsing
6185 if (schemeHandler && schemeHandler.parse) {
6186 schemeHandler.parse(components, options);
6189 components.error = components.error || "URI can not be parsed.";
6194 function _recomposeAuthority(components, options) {
6195 var protocol = options.iri !== false ? IRI_PROTOCOL : URI_PROTOCOL;
6197 if (components.userinfo !== undefined) {
6198 uriTokens.push(components.userinfo);
6199 uriTokens.push("@");
6201 if (components.host !== undefined) {
6202 //normalize IP hosts, add brackets and escape zone separator for IPv6
6203 uriTokens.push(_normalizeIPv6(_normalizeIPv4(String(components.host), protocol), protocol).replace(protocol.IPV6ADDRESS, function (_, $1, $2) {
6204 return "[" + $1 + ($2 ? "%25" + $2 : "") + "]";
6207 if (typeof components.port === "number") {
6208 uriTokens.push(":");
6209 uriTokens.push(components.port.toString(10));
6211 return uriTokens.length ? uriTokens.join("") : undefined;
6214 var RDS1 = /^\.\.?\//;
6215 var RDS2 = /^\/\.(\/|$)/;
6216 var RDS3 = /^\/\.\.(\/|$)/;
6217 var RDS5 = /^\/?(?:.|\n)*?(?=\/|$)/;
6218 function removeDotSegments(input) {
6220 while (input.length) {
6221 if (input.match(RDS1)) {
6222 input = input.replace(RDS1, "");
6223 } else if (input.match(RDS2)) {
6224 input = input.replace(RDS2, "/");
6225 } else if (input.match(RDS3)) {
6226 input = input.replace(RDS3, "/");
6228 } else if (input === "." || input === "..") {
6231 var im = input.match(RDS5);
6234 input = input.slice(s.length);
6237 throw new Error("Unexpected dot segment condition");
6241 return output.join("");
6244 function serialize(components) {
6245 var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
6247 var protocol = options.iri ? IRI_PROTOCOL : URI_PROTOCOL;
6249 //find scheme handler
6250 var schemeHandler = SCHEMES[(options.scheme || components.scheme || "").toLowerCase()];
6251 //perform scheme specific serialization
6252 if (schemeHandler && schemeHandler.serialize) schemeHandler.serialize(components, options);
6253 if (components.host) {
6254 //if host component is an IPv6 address
6255 if (protocol.IPV6ADDRESS.test(components.host)) {}
6256 //TODO: normalize IPv6 address as per RFC 5952
6258 //if host component is a domain name
6259 else if (options.domainHost || schemeHandler && schemeHandler.domainHost) {
6260 //convert IDN via punycode
6262 components.host = !options.iri ? punycode.toASCII(components.host.replace(protocol.PCT_ENCODED, pctDecChars).toLowerCase()) : punycode.toUnicode(components.host);
6264 components.error = components.error || "Host's domain name can not be converted to " + (!options.iri ? "ASCII" : "Unicode") + " via punycode: " + e;
6268 //normalize encoding
6269 _normalizeComponentEncoding(components, protocol);
6270 if (options.reference !== "suffix" && components.scheme) {
6271 uriTokens.push(components.scheme);
6272 uriTokens.push(":");
6274 var authority = _recomposeAuthority(components, options);
6275 if (authority !== undefined) {
6276 if (options.reference !== "suffix") {
6277 uriTokens.push("//");
6279 uriTokens.push(authority);
6280 if (components.path && components.path.charAt(0) !== "/") {
6281 uriTokens.push("/");
6284 if (components.path !== undefined) {
6285 var s = components.path;
6286 if (!options.absolutePath && (!schemeHandler || !schemeHandler.absolutePath)) {
6287 s = removeDotSegments(s);
6289 if (authority === undefined) {
6290 s = s.replace(/^\/\//, "/%2F"); //don't allow the path to start with "//"
6294 if (components.query !== undefined) {
6295 uriTokens.push("?");
6296 uriTokens.push(components.query);
6298 if (components.fragment !== undefined) {
6299 uriTokens.push("#");
6300 uriTokens.push(components.fragment);
6302 return uriTokens.join(""); //merge tokens into a string
6305 function resolveComponents(base, relative) {
6306 var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
6307 var skipNormalization = arguments[3];
6310 if (!skipNormalization) {
6311 base = parse(serialize(base, options), options); //normalize base components
6312 relative = parse(serialize(relative, options), options); //normalize relative components
6314 options = options || {};
6315 if (!options.tolerant && relative.scheme) {
6316 target.scheme = relative.scheme;
6317 //target.authority = relative.authority;
6318 target.userinfo = relative.userinfo;
6319 target.host = relative.host;
6320 target.port = relative.port;
6321 target.path = removeDotSegments(relative.path || "");
6322 target.query = relative.query;
6324 if (relative.userinfo !== undefined || relative.host !== undefined || relative.port !== undefined) {
6325 //target.authority = relative.authority;
6326 target.userinfo = relative.userinfo;
6327 target.host = relative.host;
6328 target.port = relative.port;
6329 target.path = removeDotSegments(relative.path || "");
6330 target.query = relative.query;
6332 if (!relative.path) {
6333 target.path = base.path;
6334 if (relative.query !== undefined) {
6335 target.query = relative.query;
6337 target.query = base.query;
6340 if (relative.path.charAt(0) === "/") {
6341 target.path = removeDotSegments(relative.path);
6343 if ((base.userinfo !== undefined || base.host !== undefined || base.port !== undefined) && !base.path) {
6344 target.path = "/" + relative.path;
6345 } else if (!base.path) {
6346 target.path = relative.path;
6348 target.path = base.path.slice(0, base.path.lastIndexOf("/") + 1) + relative.path;
6350 target.path = removeDotSegments(target.path);
6352 target.query = relative.query;
6354 //target.authority = base.authority;
6355 target.userinfo = base.userinfo;
6356 target.host = base.host;
6357 target.port = base.port;
6359 target.scheme = base.scheme;
6361 target.fragment = relative.fragment;
6365 function resolve(baseURI, relativeURI, options) {
6366 var schemelessOptions = assign({ scheme: 'null' }, options);
6367 return serialize(resolveComponents(parse(baseURI, schemelessOptions), parse(relativeURI, schemelessOptions), schemelessOptions, true), schemelessOptions);
6370 function normalize(uri, options) {
6371 if (typeof uri === "string") {
6372 uri = serialize(parse(uri, options), options);
6373 } else if (typeOf(uri) === "object") {
6374 uri = parse(serialize(uri, options), options);
6379 function equal(uriA, uriB, options) {
6380 if (typeof uriA === "string") {
6381 uriA = serialize(parse(uriA, options), options);
6382 } else if (typeOf(uriA) === "object") {
6383 uriA = serialize(uriA, options);
6385 if (typeof uriB === "string") {
6386 uriB = serialize(parse(uriB, options), options);
6387 } else if (typeOf(uriB) === "object") {
6388 uriB = serialize(uriB, options);
6390 return uriA === uriB;
6393 function escapeComponent(str, options) {
6394 return str && str.toString().replace(!options || !options.iri ? URI_PROTOCOL.ESCAPE : IRI_PROTOCOL.ESCAPE, pctEncChar);
6397 function unescapeComponent(str, options) {
6398 return str && str.toString().replace(!options || !options.iri ? URI_PROTOCOL.PCT_ENCODED : IRI_PROTOCOL.PCT_ENCODED, pctDecChars);
6404 parse: function parse(components, options) {
6405 //report missing host
6406 if (!components.host) {
6407 components.error = components.error || "HTTP URIs must have a host.";
6411 serialize: function serialize(components, options) {
6412 //normalize the default port
6413 if (components.port === (String(components.scheme).toLowerCase() !== "https" ? 80 : 443) || components.port === "") {
6414 components.port = undefined;
6416 //normalize the empty path
6417 if (!components.path) {
6418 components.path = "/";
6420 //NOTE: We do not parse query strings for HTTP URIs
6421 //as WWW Form Url Encoded query strings are part of the HTML4+ spec,
6422 //and not the HTTP spec.
6429 domainHost: handler.domainHost,
6430 parse: handler.parse,
6431 serialize: handler.serialize
6437 var UNRESERVED$$ = "[A-Za-z0-9\\-\\.\\_\\~" + (isIRI ? "\\xA0-\\u200D\\u2010-\\u2029\\u202F-\\uD7FF\\uF900-\\uFDCF\\uFDF0-\\uFFEF" : "") + "]";
6438 var HEXDIG$$ = "[0-9A-Fa-f]"; //case-insensitive
6439 var PCT_ENCODED$ = subexp(subexp("%[EFef]" + HEXDIG$$ + "%" + HEXDIG$$ + HEXDIG$$ + "%" + HEXDIG$$ + HEXDIG$$) + "|" + subexp("%[89A-Fa-f]" + HEXDIG$$ + "%" + HEXDIG$$ + HEXDIG$$) + "|" + subexp("%" + HEXDIG$$ + HEXDIG$$)); //expanded
6440 //RFC 5322, except these symbols as per RFC 6068: @ : / ? # [ ] & ; =
6441 //const ATEXT$$ = "[A-Za-z0-9\\!\\#\\$\\%\\&\\'\\*\\+\\-\\/\\=\\?\\^\\_\\`\\{\\|\\}\\~]";
6442 //const WSP$$ = "[\\x20\\x09]";
6443 //const OBS_QTEXT$$ = "[\\x01-\\x08\\x0B\\x0C\\x0E-\\x1F\\x7F]"; //(%d1-8 / %d11-12 / %d14-31 / %d127)
6444 //const QTEXT$$ = merge("[\\x21\\x23-\\x5B\\x5D-\\x7E]", OBS_QTEXT$$); //%d33 / %d35-91 / %d93-126 / obs-qtext
6445 //const VCHAR$$ = "[\\x21-\\x7E]";
6446 //const WSP$$ = "[\\x20\\x09]";
6447 //const OBS_QP$ = subexp("\\\\" + merge("[\\x00\\x0D\\x0A]", OBS_QTEXT$$)); //%d0 / CR / LF / obs-qtext
6448 //const FWS$ = subexp(subexp(WSP$$ + "*" + "\\x0D\\x0A") + "?" + WSP$$ + "+");
6449 //const QUOTED_PAIR$ = subexp(subexp("\\\\" + subexp(VCHAR$$ + "|" + WSP$$)) + "|" + OBS_QP$);
6450 //const QUOTED_STRING$ = subexp('\\"' + subexp(FWS$ + "?" + QCONTENT$) + "*" + FWS$ + "?" + '\\"');
6451 var ATEXT$$ = "[A-Za-z0-9\\!\\$\\%\\'\\*\\+\\-\\^\\_\\`\\{\\|\\}\\~]";
6452 var QTEXT$$ = "[\\!\\$\\%\\'\\(\\)\\*\\+\\,\\-\\.0-9\\<\\>A-Z\\x5E-\\x7E]";
6453 var VCHAR$$ = merge(QTEXT$$, "[\\\"\\\\]");
6454 var SOME_DELIMS$$ = "[\\!\\$\\'\\(\\)\\*\\+\\,\\;\\:\\@]";
6455 var UNRESERVED = new RegExp(UNRESERVED$$, "g");
6456 var PCT_ENCODED = new RegExp(PCT_ENCODED$, "g");
6457 var NOT_LOCAL_PART = new RegExp(merge("[^]", ATEXT$$, "[\\.]", '[\\"]', VCHAR$$), "g");
6458 var NOT_HFNAME = new RegExp(merge("[^]", UNRESERVED$$, SOME_DELIMS$$), "g");
6459 var NOT_HFVALUE = NOT_HFNAME;
6460 function decodeUnreserved(str) {
6461 var decStr = pctDecChars(str);
6462 return !decStr.match(UNRESERVED) ? str : decStr;
6466 parse: function parse$$1(components, options) {
6467 var mailtoComponents = components;
6468 var to = mailtoComponents.to = mailtoComponents.path ? mailtoComponents.path.split(",") : [];
6469 mailtoComponents.path = undefined;
6470 if (mailtoComponents.query) {
6471 var unknownHeaders = false;
6473 var hfields = mailtoComponents.query.split("&");
6474 for (var x = 0, xl = hfields.length; x < xl; ++x) {
6475 var hfield = hfields[x].split("=");
6476 switch (hfield[0]) {
6478 var toAddrs = hfield[1].split(",");
6479 for (var _x = 0, _xl = toAddrs.length; _x < _xl; ++_x) {
6480 to.push(toAddrs[_x]);
6484 mailtoComponents.subject = unescapeComponent(hfield[1], options);
6487 mailtoComponents.body = unescapeComponent(hfield[1], options);
6490 unknownHeaders = true;
6491 headers[unescapeComponent(hfield[0], options)] = unescapeComponent(hfield[1], options);
6495 if (unknownHeaders) mailtoComponents.headers = headers;
6497 mailtoComponents.query = undefined;
6498 for (var _x2 = 0, _xl2 = to.length; _x2 < _xl2; ++_x2) {
6499 var addr = to[_x2].split("@");
6500 addr[0] = unescapeComponent(addr[0]);
6501 if (!options.unicodeSupport) {
6502 //convert Unicode IDN -> ASCII IDN
6504 addr[1] = punycode.toASCII(unescapeComponent(addr[1], options).toLowerCase());
6506 mailtoComponents.error = mailtoComponents.error || "Email address's domain name can not be converted to ASCII via punycode: " + e;
6509 addr[1] = unescapeComponent(addr[1], options).toLowerCase();
6511 to[_x2] = addr.join("@");
6513 return mailtoComponents;
6515 serialize: function serialize$$1(mailtoComponents, options) {
6516 var components = mailtoComponents;
6517 var to = toArray(mailtoComponents.to);
6519 for (var x = 0, xl = to.length; x < xl; ++x) {
6520 var toAddr = String(to[x]);
6521 var atIdx = toAddr.lastIndexOf("@");
6522 var localPart = toAddr.slice(0, atIdx).replace(PCT_ENCODED, decodeUnreserved).replace(PCT_ENCODED, toUpperCase).replace(NOT_LOCAL_PART, pctEncChar);
6523 var domain = toAddr.slice(atIdx + 1);
6524 //convert IDN via punycode
6526 domain = !options.iri ? punycode.toASCII(unescapeComponent(domain, options).toLowerCase()) : punycode.toUnicode(domain);
6528 components.error = components.error || "Email address's domain name can not be converted to " + (!options.iri ? "ASCII" : "Unicode") + " via punycode: " + e;
6530 to[x] = localPart + "@" + domain;
6532 components.path = to.join(",");
6534 var headers = mailtoComponents.headers = mailtoComponents.headers || {};
6535 if (mailtoComponents.subject) headers["subject"] = mailtoComponents.subject;
6536 if (mailtoComponents.body) headers["body"] = mailtoComponents.body;
6538 for (var name in headers) {
6539 if (headers[name] !== O[name]) {
6540 fields.push(name.replace(PCT_ENCODED, decodeUnreserved).replace(PCT_ENCODED, toUpperCase).replace(NOT_HFNAME, pctEncChar) + "=" + headers[name].replace(PCT_ENCODED, decodeUnreserved).replace(PCT_ENCODED, toUpperCase).replace(NOT_HFVALUE, pctEncChar));
6543 if (fields.length) {
6544 components.query = fields.join("&");
6550 var URN_PARSE = /^([^\:]+)\:(.*)/;
6554 parse: function parse$$1(components, options) {
6555 var matches = components.path && components.path.match(URN_PARSE);
6556 var urnComponents = components;
6558 var scheme = options.scheme || urnComponents.scheme || "urn";
6559 var nid = matches[1].toLowerCase();
6560 var nss = matches[2];
6561 var urnScheme = scheme + ":" + (options.nid || nid);
6562 var schemeHandler = SCHEMES[urnScheme];
6563 urnComponents.nid = nid;
6564 urnComponents.nss = nss;
6565 urnComponents.path = undefined;
6566 if (schemeHandler) {
6567 urnComponents = schemeHandler.parse(urnComponents, options);
6570 urnComponents.error = urnComponents.error || "URN can not be parsed.";
6572 return urnComponents;
6574 serialize: function serialize$$1(urnComponents, options) {
6575 var scheme = options.scheme || urnComponents.scheme || "urn";
6576 var nid = urnComponents.nid;
6577 var urnScheme = scheme + ":" + (options.nid || nid);
6578 var schemeHandler = SCHEMES[urnScheme];
6579 if (schemeHandler) {
6580 urnComponents = schemeHandler.serialize(urnComponents, options);
6582 var uriComponents = urnComponents;
6583 var nss = urnComponents.nss;
6584 uriComponents.path = (nid || options.nid) + ":" + nss;
6585 return uriComponents;
6589 var UUID = /^[0-9A-Fa-f]{8}(?:\-[0-9A-Fa-f]{4}){3}\-[0-9A-Fa-f]{12}$/;
6593 parse: function parse(urnComponents, options) {
6594 var uuidComponents = urnComponents;
6595 uuidComponents.uuid = uuidComponents.nss;
6596 uuidComponents.nss = undefined;
6597 if (!options.tolerant && (!uuidComponents.uuid || !uuidComponents.uuid.match(UUID))) {
6598 uuidComponents.error = uuidComponents.error || "UUID is not valid.";
6600 return uuidComponents;
6602 serialize: function serialize(uuidComponents, options) {
6603 var urnComponents = uuidComponents;
6605 urnComponents.nss = (uuidComponents.uuid || "").toLowerCase();
6606 return urnComponents;
6610 SCHEMES[handler.scheme] = handler;
6611 SCHEMES[handler$1.scheme] = handler$1;
6612 SCHEMES[handler$2.scheme] = handler$2;
6613 SCHEMES[handler$3.scheme] = handler$3;
6614 SCHEMES[handler$4.scheme] = handler$4;
6616 exports.SCHEMES = SCHEMES;
6617 exports.pctEncChar = pctEncChar;
6618 exports.pctDecChars = pctDecChars;
6619 exports.parse = parse;
6620 exports.removeDotSegments = removeDotSegments;
6621 exports.serialize = serialize;
6622 exports.resolveComponents = resolveComponents;
6623 exports.resolve = resolve;
6624 exports.normalize = normalize;
6625 exports.equal = equal;
6626 exports.escapeComponent = escapeComponent;
6627 exports.unescapeComponent = unescapeComponent;
6629 Object.defineProperty(exports, '__esModule', { value: true });
6634 },{}],"ajv":[function(require,module,exports){
6637 var compileSchema = require('./compile')
6638 , resolve = require('./compile/resolve')
6639 , Cache = require('./cache')
6640 , SchemaObject = require('./compile/schema_obj')
6641 , stableStringify = require('fast-json-stable-stringify')
6642 , formats = require('./compile/formats')
6643 , rules = require('./compile/rules')
6644 , $dataMetaSchema = require('./data')
6645 , util = require('./compile/util');
6647 module.exports = Ajv;
6649 Ajv.prototype.validate = validate;
6650 Ajv.prototype.compile = compile;
6651 Ajv.prototype.addSchema = addSchema;
6652 Ajv.prototype.addMetaSchema = addMetaSchema;
6653 Ajv.prototype.validateSchema = validateSchema;
6654 Ajv.prototype.getSchema = getSchema;
6655 Ajv.prototype.removeSchema = removeSchema;
6656 Ajv.prototype.addFormat = addFormat;
6657 Ajv.prototype.errorsText = errorsText;
6659 Ajv.prototype._addSchema = _addSchema;
6660 Ajv.prototype._compile = _compile;
6662 Ajv.prototype.compileAsync = require('./compile/async');
6663 var customKeyword = require('./keyword');
6664 Ajv.prototype.addKeyword = customKeyword.add;
6665 Ajv.prototype.getKeyword = customKeyword.get;
6666 Ajv.prototype.removeKeyword = customKeyword.remove;
6667 Ajv.prototype.validateKeyword = customKeyword.validate;
6669 var errorClasses = require('./compile/error_classes');
6670 Ajv.ValidationError = errorClasses.Validation;
6671 Ajv.MissingRefError = errorClasses.MissingRef;
6672 Ajv.$dataMetaSchema = $dataMetaSchema;
6674 var META_SCHEMA_ID = 'http://json-schema.org/draft-07/schema';
6676 var META_IGNORE_OPTIONS = [ 'removeAdditional', 'useDefaults', 'coerceTypes', 'strictDefaults' ];
6677 var META_SUPPORT_DATA = ['/properties'];
6680 * Creates validator instance.
6681 * Usage: `Ajv(opts)`
6682 * @param {Object} opts optional options
6683 * @return {Object} ajv instance
6685 function Ajv(opts) {
6686 if (!(this instanceof Ajv)) return new Ajv(opts);
6687 opts = this._opts = util.copy(opts) || {};
6691 this._fragments = {};
6692 this._formats = formats(opts.format);
6694 this._cache = opts.cache || new Cache;
6695 this._loadingSchemas = {};
6696 this._compilations = [];
6697 this.RULES = rules();
6698 this._getId = chooseGetId(opts);
6700 opts.loopRequired = opts.loopRequired || Infinity;
6701 if (opts.errorDataPath == 'property') opts._errorDataPathProperty = true;
6702 if (opts.serialize === undefined) opts.serialize = stableStringify;
6703 this._metaOpts = getMetaSchemaOptions(this);
6705 if (opts.formats) addInitialFormats(this);
6706 if (opts.keywords) addInitialKeywords(this);
6707 addDefaultMetaSchema(this);
6708 if (typeof opts.meta == 'object') this.addMetaSchema(opts.meta);
6709 if (opts.nullable) this.addKeyword('nullable', {metaSchema: {type: 'boolean'}});
6710 addInitialSchemas(this);
6716 * Validate data using schema
6717 * 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.
6719 * @param {String|Object} schemaKeyRef key, ref or schema object
6720 * @param {Any} data to be validated
6721 * @return {Boolean} validation result. Errors from the last validation will be available in `ajv.errors` (and also in compiled schema: `schema.errors`).
6723 function validate(schemaKeyRef, data) {
6725 if (typeof schemaKeyRef == 'string') {
6726 v = this.getSchema(schemaKeyRef);
6727 if (!v) throw new Error('no schema with key or ref "' + schemaKeyRef + '"');
6729 var schemaObj = this._addSchema(schemaKeyRef);
6730 v = schemaObj.validate || this._compile(schemaObj);
6733 var valid = v(data);
6734 if (v.$async !== true) this.errors = v.errors;
6740 * Create validating function for passed schema.
6742 * @param {Object} schema schema object
6743 * @param {Boolean} _meta true if schema is a meta-schema. Used internally to compile meta schemas of custom keywords.
6744 * @return {Function} validating function
6746 function compile(schema, _meta) {
6747 var schemaObj = this._addSchema(schema, undefined, _meta);
6748 return schemaObj.validate || this._compile(schemaObj);
6753 * Adds schema to the instance.
6755 * @param {Object|Array} schema schema or array of schemas. If array is passed, `key` and other parameters will be ignored.
6756 * @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`.
6757 * @param {Boolean} _skipValidation true to skip schema validation. Used internally, option validateSchema should be used instead.
6758 * @param {Boolean} _meta true if schema is a meta-schema. Used internally, addMetaSchema should be used instead.
6759 * @return {Ajv} this for method chaining
6761 function addSchema(schema, key, _skipValidation, _meta) {
6762 if (Array.isArray(schema)){
6763 for (var i=0; i<schema.length; i++) this.addSchema(schema[i], undefined, _skipValidation, _meta);
6766 var id = this._getId(schema);
6767 if (id !== undefined && typeof id != 'string')
6768 throw new Error('schema id must be string');
6769 key = resolve.normalizeId(key || id);
6770 checkUnique(this, key);
6771 this._schemas[key] = this._addSchema(schema, _skipValidation, _meta, true);
6777 * Add schema that will be used to validate other schemas
6778 * options in META_IGNORE_OPTIONS are alway set to false
6780 * @param {Object} schema schema object
6781 * @param {String} key optional schema key
6782 * @param {Boolean} skipValidation true to skip schema validation, can be used to override validateSchema option for meta-schema
6783 * @return {Ajv} this for method chaining
6785 function addMetaSchema(schema, key, skipValidation) {
6786 this.addSchema(schema, key, skipValidation, true);
6794 * @param {Object} schema schema to validate
6795 * @param {Boolean} throwOrLogError pass true to throw (or log) an error if invalid
6796 * @return {Boolean} true if schema is valid
6798 function validateSchema(schema, throwOrLogError) {
6799 var $schema = schema.$schema;
6800 if ($schema !== undefined && typeof $schema != 'string')
6801 throw new Error('$schema must be a string');
6802 $schema = $schema || this._opts.defaultMeta || defaultMeta(this);
6804 this.logger.warn('meta-schema not available');
6808 var valid = this.validate($schema, schema);
6809 if (!valid && throwOrLogError) {
6810 var message = 'schema is invalid: ' + this.errorsText();
6811 if (this._opts.validateSchema == 'log') this.logger.error(message);
6812 else throw new Error(message);
6818 function defaultMeta(self) {
6819 var meta = self._opts.meta;
6820 self._opts.defaultMeta = typeof meta == 'object'
6821 ? self._getId(meta) || meta
6822 : self.getSchema(META_SCHEMA_ID)
6825 return self._opts.defaultMeta;
6830 * Get compiled schema from the instance by `key` or `ref`.
6832 * @param {String} keyRef `key` that was passed to `addSchema` or full schema reference (`schema.id` or resolved id).
6833 * @return {Function} schema validating function (with property `schema`).
6835 function getSchema(keyRef) {
6836 var schemaObj = _getSchemaObj(this, keyRef);
6837 switch (typeof schemaObj) {
6838 case 'object': return schemaObj.validate || this._compile(schemaObj);
6839 case 'string': return this.getSchema(schemaObj);
6840 case 'undefined': return _getSchemaFragment(this, keyRef);
6845 function _getSchemaFragment(self, ref) {
6846 var res = resolve.schema.call(self, { schema: {} }, ref);
6848 var schema = res.schema
6850 , baseId = res.baseId;
6851 var v = compileSchema.call(self, schema, root, undefined, baseId);
6852 self._fragments[ref] = new SchemaObject({
6865 function _getSchemaObj(self, keyRef) {
6866 keyRef = resolve.normalizeId(keyRef);
6867 return self._schemas[keyRef] || self._refs[keyRef] || self._fragments[keyRef];
6872 * Remove cached schema(s).
6873 * If no parameter is passed all schemas but meta-schemas are removed.
6874 * If RegExp is passed all schemas with key/id matching pattern but meta-schemas are removed.
6875 * Even if schema is referenced by other schemas it still can be removed as other schemas have local references.
6877 * @param {String|Object|RegExp} schemaKeyRef key, ref, pattern to match key/ref or schema object
6878 * @return {Ajv} this for method chaining
6880 function removeSchema(schemaKeyRef) {
6881 if (schemaKeyRef instanceof RegExp) {
6882 _removeAllSchemas(this, this._schemas, schemaKeyRef);
6883 _removeAllSchemas(this, this._refs, schemaKeyRef);
6886 switch (typeof schemaKeyRef) {
6888 _removeAllSchemas(this, this._schemas);
6889 _removeAllSchemas(this, this._refs);
6890 this._cache.clear();
6893 var schemaObj = _getSchemaObj(this, schemaKeyRef);
6894 if (schemaObj) this._cache.del(schemaObj.cacheKey);
6895 delete this._schemas[schemaKeyRef];
6896 delete this._refs[schemaKeyRef];
6899 var serialize = this._opts.serialize;
6900 var cacheKey = serialize ? serialize(schemaKeyRef) : schemaKeyRef;
6901 this._cache.del(cacheKey);
6902 var id = this._getId(schemaKeyRef);
6904 id = resolve.normalizeId(id);
6905 delete this._schemas[id];
6906 delete this._refs[id];
6913 function _removeAllSchemas(self, schemas, regex) {
6914 for (var keyRef in schemas) {
6915 var schemaObj = schemas[keyRef];
6916 if (!schemaObj.meta && (!regex || regex.test(keyRef))) {
6917 self._cache.del(schemaObj.cacheKey);
6918 delete schemas[keyRef];
6925 function _addSchema(schema, skipValidation, meta, shouldAddSchema) {
6926 if (typeof schema != 'object' && typeof schema != 'boolean')
6927 throw new Error('schema should be object or boolean');
6928 var serialize = this._opts.serialize;
6929 var cacheKey = serialize ? serialize(schema) : schema;
6930 var cached = this._cache.get(cacheKey);
6931 if (cached) return cached;
6933 shouldAddSchema = shouldAddSchema || this._opts.addUsedSchema !== false;
6935 var id = resolve.normalizeId(this._getId(schema));
6936 if (id && shouldAddSchema) checkUnique(this, id);
6938 var willValidate = this._opts.validateSchema !== false && !skipValidation;
6940 if (willValidate && !(recursiveMeta = id && id == resolve.normalizeId(schema.$schema)))
6941 this.validateSchema(schema, true);
6943 var localRefs = resolve.ids.call(this, schema);
6945 var schemaObj = new SchemaObject({
6948 localRefs: localRefs,
6953 if (id[0] != '#' && shouldAddSchema) this._refs[id] = schemaObj;
6954 this._cache.put(cacheKey, schemaObj);
6956 if (willValidate && recursiveMeta) this.validateSchema(schema, true);
6963 function _compile(schemaObj, root) {
6964 if (schemaObj.compiling) {
6965 schemaObj.validate = callValidate;
6966 callValidate.schema = schemaObj.schema;
6967 callValidate.errors = null;
6968 callValidate.root = root ? root : callValidate;
6969 if (schemaObj.schema.$async === true)
6970 callValidate.$async = true;
6971 return callValidate;
6973 schemaObj.compiling = true;
6976 if (schemaObj.meta) {
6977 currentOpts = this._opts;
6978 this._opts = this._metaOpts;
6982 try { v = compileSchema.call(this, schemaObj.schema, root, schemaObj.localRefs); }
6984 delete schemaObj.validate;
6988 schemaObj.compiling = false;
6989 if (schemaObj.meta) this._opts = currentOpts;
6992 schemaObj.validate = v;
6993 schemaObj.refs = v.refs;
6994 schemaObj.refVal = v.refVal;
6995 schemaObj.root = v.root;
6999 /* @this {*} - custom context, see passContext option */
7000 function callValidate() {
7001 /* jshint validthis: true */
7002 var _validate = schemaObj.validate;
7003 var result = _validate.apply(this, arguments);
7004 callValidate.errors = _validate.errors;
7010 function chooseGetId(opts) {
7011 switch (opts.schemaId) {
7012 case 'auto': return _get$IdOrId;
7013 case 'id': return _getId;
7014 default: return _get$Id;
7019 function _getId(schema) {
7020 if (schema.$id) this.logger.warn('schema $id ignored', schema.$id);
7025 function _get$Id(schema) {
7026 if (schema.id) this.logger.warn('schema id ignored', schema.id);
7031 function _get$IdOrId(schema) {
7032 if (schema.$id && schema.id && schema.$id != schema.id)
7033 throw new Error('schema $id is different from id');
7034 return schema.$id || schema.id;
7039 * Convert array of error message objects to string
7041 * @param {Array<Object>} errors optional array of validation errors, if not passed errors from the instance are used.
7042 * @param {Object} options optional options with properties `separator` and `dataVar`.
7043 * @return {String} human readable string with all errors descriptions
7045 function errorsText(errors, options) {
7046 errors = errors || this.errors;
7047 if (!errors) return 'No errors';
7048 options = options || {};
7049 var separator = options.separator === undefined ? ', ' : options.separator;
7050 var dataVar = options.dataVar === undefined ? 'data' : options.dataVar;
7053 for (var i=0; i<errors.length; i++) {
7055 if (e) text += dataVar + e.dataPath + ' ' + e.message + separator;
7057 return text.slice(0, -separator.length);
7064 * @param {String} name format name
7065 * @param {String|RegExp|Function} format string is converted to RegExp; function should return boolean (true when valid)
7066 * @return {Ajv} this for method chaining
7068 function addFormat(name, format) {
7069 if (typeof format == 'string') format = new RegExp(format);
7070 this._formats[name] = format;
7075 function addDefaultMetaSchema(self) {
7077 if (self._opts.$data) {
7078 $dataSchema = require('./refs/data.json');
7079 self.addMetaSchema($dataSchema, $dataSchema.$id, true);
7081 if (self._opts.meta === false) return;
7082 var metaSchema = require('./refs/json-schema-draft-07.json');
7083 if (self._opts.$data) metaSchema = $dataMetaSchema(metaSchema, META_SUPPORT_DATA);
7084 self.addMetaSchema(metaSchema, META_SCHEMA_ID, true);
7085 self._refs['http://json-schema.org/schema'] = META_SCHEMA_ID;
7089 function addInitialSchemas(self) {
7090 var optsSchemas = self._opts.schemas;
7091 if (!optsSchemas) return;
7092 if (Array.isArray(optsSchemas)) self.addSchema(optsSchemas);
7093 else for (var key in optsSchemas) self.addSchema(optsSchemas[key], key);
7097 function addInitialFormats(self) {
7098 for (var name in self._opts.formats) {
7099 var format = self._opts.formats[name];
7100 self.addFormat(name, format);
7105 function addInitialKeywords(self) {
7106 for (var name in self._opts.keywords) {
7107 var keyword = self._opts.keywords[name];
7108 self.addKeyword(name, keyword);
7113 function checkUnique(self, id) {
7114 if (self._schemas[id] || self._refs[id])
7115 throw new Error('schema with key or id "' + id + '" already exists');
7119 function getMetaSchemaOptions(self) {
7120 var metaOpts = util.copy(self._opts);
7121 for (var i=0; i<META_IGNORE_OPTIONS.length; i++)
7122 delete metaOpts[META_IGNORE_OPTIONS[i]];
7127 function setLogger(self) {
7128 var logger = self._opts.logger;
7129 if (logger === false) {
7130 self.logger = {log: noop, warn: noop, error: noop};
7132 if (logger === undefined) logger = console;
7133 if (!(typeof logger == 'object' && logger.log && logger.warn && logger.error))
7134 throw new Error('logger must implement log, warn and error methods');
7135 self.logger = logger;
7142 },{"./cache":1,"./compile":5,"./compile/async":2,"./compile/error_classes":3,"./compile/formats":4,"./compile/resolve":6,"./compile/rules":7,"./compile/schema_obj":8,"./compile/util":10,"./data":11,"./keyword":39,"./refs/data.json":40,"./refs/json-schema-draft-07.json":41,"fast-json-stable-stringify":43}]},{},[])("ajv")