4 var EXPORTED_SYMBOLS = ["Ajv"];
7 * ajv 6.12.6: Another JSON Schema Validator
9 * https://github.com/epoberezkin/ajv
11 * The MIT License (MIT)
13 * Copyright (c) 2015 Evgeny Poberezkin
15 * Permission is hereby granted, free of charge, to any person obtaining a copy
16 * of this software and associated documentation files (the "Software"), to deal
17 * in the Software without restriction, including without limitation the rights
18 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
19 * copies of the Software, and to permit persons to whom the Software is
20 * furnished to do so, subject to the following conditions:
22 * The above copyright notice and this permission notice shall be included in all
23 * copies or substantial portions of the Software.
25 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
26 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
27 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
28 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
29 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
30 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
34 // Everything below this comment was taken from the `dist/ajv.bundle.js` in the
35 // ajv node module. (You can get this by running `npm install ajv` in an empty
36 // directory and copying `node_modules/ajv/dist/ajv.bundle.js`).
38 (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){
42 var Cache = module.exports = function Cache() {
47 Cache.prototype.put = function Cache_put(key, value) {
48 this._cache[key] = value;
52 Cache.prototype.get = function Cache_get(key) {
53 return this._cache[key];
57 Cache.prototype.del = function Cache_del(key) {
58 delete this._cache[key];
62 Cache.prototype.clear = function Cache_clear() {
66 },{}],2:[function(require,module,exports){
69 var MissingRefError = require('./error_classes').MissingRef;
71 module.exports = compileAsync;
75 * Creates validating function for passed schema with asynchronous loading of missing schemas.
76 * `loadSchema` option should be a function that accepts schema uri and returns promise that resolves with the schema.
78 * @param {Object} schema schema object
79 * @param {Boolean} meta optional true to compile meta-schema; this parameter can be skipped
80 * @param {Function} callback an optional node-style callback, it is called with 2 parameters: error (or null) and validating function.
81 * @return {Promise} promise that resolves with a validating function.
83 function compileAsync(schema, meta, callback) {
84 /* eslint no-shadow: 0 */
86 /* jshint validthis: true */
88 if (typeof this._opts.loadSchema != 'function')
89 throw new Error('options.loadSchema should be a function');
91 if (typeof meta == 'function') {
96 var p = loadMetaSchemaOf(schema).then(function () {
97 var schemaObj = self._addSchema(schema, undefined, meta);
98 return schemaObj.validate || _compileAsync(schemaObj);
103 function(v) { callback(null, v); },
111 function loadMetaSchemaOf(sch) {
112 var $schema = sch.$schema;
113 return $schema && !self.getSchema($schema)
114 ? compileAsync.call(self, { $ref: $schema }, true)
119 function _compileAsync(schemaObj) {
120 try { return self._compile(schemaObj); }
122 if (e instanceof MissingRefError) return loadMissingSchema(e);
127 function loadMissingSchema(e) {
128 var ref = e.missingSchema;
129 if (added(ref)) throw new Error('Schema ' + ref + ' is loaded but ' + e.missingRef + ' cannot be resolved');
131 var schemaPromise = self._loadingSchemas[ref];
132 if (!schemaPromise) {
133 schemaPromise = self._loadingSchemas[ref] = self._opts.loadSchema(ref);
134 schemaPromise.then(removePromise, removePromise);
137 return schemaPromise.then(function (sch) {
139 return loadMetaSchemaOf(sch).then(function () {
140 if (!added(ref)) self.addSchema(sch, ref, undefined, meta);
144 return _compileAsync(schemaObj);
147 function removePromise() {
148 delete self._loadingSchemas[ref];
151 function added(ref) {
152 return self._refs[ref] || self._schemas[ref];
158 },{"./error_classes":3}],3:[function(require,module,exports){
161 var resolve = require('./resolve');
164 Validation: errorSubclass(ValidationError),
165 MissingRef: errorSubclass(MissingRefError)
169 function ValidationError(errors) {
170 this.message = 'validation failed';
171 this.errors = errors;
172 this.ajv = this.validation = true;
176 MissingRefError.message = function (baseId, ref) {
177 return 'can\'t resolve reference ' + ref + ' from id ' + baseId;
181 function MissingRefError(baseId, ref, message) {
182 this.message = message || MissingRefError.message(baseId, ref);
183 this.missingRef = resolve.url(baseId, ref);
184 this.missingSchema = resolve.normalizeId(resolve.fullPath(this.missingRef));
188 function errorSubclass(Subclass) {
189 Subclass.prototype = Object.create(Error.prototype);
190 Subclass.prototype.constructor = Subclass;
194 },{"./resolve":6}],4:[function(require,module,exports){
197 var util = require('./util');
199 var DATE = /^(\d\d\d\d)-(\d\d)-(\d\d)$/;
200 var DAYS = [0,31,28,31,30,31,30,31,31,30,31,30,31];
201 var TIME = /^(\d\d):(\d\d):(\d\d)(\.\d+)?(z|[+-]\d\d(?::?\d\d)?)?$/i;
202 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;
203 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;
204 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;
205 // uri-template: https://tools.ietf.org/html/rfc6570
206 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;
207 // For the source: https://gist.github.com/dperini/729294
208 // For test cases: https://mathiasbynens.be/demo/url-regex
209 // @todo Delete current URL in favour of the commented out URL rule when this issue is fixed https://github.com/eslint/eslint/issues/7983.
210 // 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;
211 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-9a-z\xA1-\uD7FF\uE000-\uFFFF]|[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?:[^\uD800-\uDBFF]|^)[\uDC00-\uDFFF])+-)*(?:[0-9a-z\xA1-\uD7FF\uE000-\uFFFF]|[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?:[^\uD800-\uDBFF]|^)[\uDC00-\uDFFF])+)(?:\.(?:(?:[0-9a-z\xA1-\uD7FF\uE000-\uFFFF]|[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?:[^\uD800-\uDBFF]|^)[\uDC00-\uDFFF])+-)*(?:[0-9a-z\xA1-\uD7FF\uE000-\uFFFF]|[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?:[^\uD800-\uDBFF]|^)[\uDC00-\uDFFF])+)*(?:\.(?:(?:[a-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;
212 var UUID = /^(?:urn:uuid:)?[0-9a-f]{8}-(?:[0-9a-f]{4}-){3}[0-9a-f]{12}$/i;
213 var JSON_POINTER = /^(?:\/(?:[^~/]|~0|~1)*)*$/;
214 var JSON_POINTER_URI_FRAGMENT = /^#(?:\/(?:[a-z0-9_\-.!$&'()*+,;:=@]|%[0-9a-f]{2}|~0|~1)*)*$/i;
215 var RELATIVE_JSON_POINTER = /^(?:0|[1-9][0-9]*)(?:#|(?:\/(?:[^~/]|~0|~1)*)*)$/;
218 module.exports = formats;
220 function formats(mode) {
221 mode = mode == 'full' ? 'full' : 'fast';
222 return util.copy(formats[mode]);
227 // date: http://tools.ietf.org/html/rfc3339#section-5.6
228 date: /^\d\d\d\d-[0-1]\d-[0-3]\d$/,
229 // date-time: http://tools.ietf.org/html/rfc3339#section-5.6
230 time: /^(?:[0-2]\d:[0-5]\d:[0-5]\d|23:59:60)(?:\.\d+)?(?:z|[+-]\d\d(?::?\d\d)?)?$/i,
231 '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,
232 // uri: https://github.com/mafintosh/is-my-json-valid/blob/master/formats.js
233 uri: /^(?:[a-z][a-z0-9+\-.]*:)(?:\/?\/)?[^\s]*$/i,
234 'uri-reference': /^(?:(?:[a-z][a-z0-9+\-.]*:)?\/?\/)?(?:[^\\\s#][^\s#]*)?(?:#[^\\\s]*)?$/i,
235 'uri-template': URITEMPLATE,
237 // email (sources from jsen validator):
238 // http://stackoverflow.com/questions/201323/using-a-regular-expression-to-validate-an-email-address#answer-8829363
239 // http://www.w3.org/TR/html5/forms.html#valid-e-mail-address (search for 'willful violation')
240 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,
242 // optimized https://www.safaribooksonline.com/library/view/regular-expressions-cookbook/9780596802837/ch07s16.html
243 ipv4: /^(?:(?:25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(?:25[0-5]|2[0-4]\d|[01]?\d\d?)$/,
244 // optimized http://stackoverflow.com/questions/53497/regular-expression-that-matches-valid-ipv6-addresses
245 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,
247 // uuid: http://tools.ietf.org/html/rfc4122
249 // JSON-pointer: https://tools.ietf.org/html/rfc6901
250 // uri fragment: https://tools.ietf.org/html/rfc3986#appendix-A
251 'json-pointer': JSON_POINTER,
252 'json-pointer-uri-fragment': JSON_POINTER_URI_FRAGMENT,
253 // relative JSON-pointer: http://tools.ietf.org/html/draft-luff-relative-json-pointer-00
254 'relative-json-pointer': RELATIVE_JSON_POINTER
261 'date-time': date_time,
263 'uri-reference': URIREF,
264 'uri-template': URITEMPLATE,
266 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,
268 ipv4: /^(?:(?:25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(?:25[0-5]|2[0-4]\d|[01]?\d\d?)$/,
269 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,
272 'json-pointer': JSON_POINTER,
273 'json-pointer-uri-fragment': JSON_POINTER_URI_FRAGMENT,
274 'relative-json-pointer': RELATIVE_JSON_POINTER
278 function isLeapYear(year) {
279 // https://tools.ietf.org/html/rfc3339#appendix-C
280 return year % 4 === 0 && (year % 100 !== 0 || year % 400 === 0);
285 // full-date from http://tools.ietf.org/html/rfc3339#section-5.6
286 var matches = str.match(DATE);
287 if (!matches) return false;
289 var year = +matches[1];
290 var month = +matches[2];
291 var day = +matches[3];
293 return month >= 1 && month <= 12 && day >= 1 &&
294 day <= (month == 2 && isLeapYear(year) ? 29 : DAYS[month]);
298 function time(str, full) {
299 var matches = str.match(TIME);
300 if (!matches) return false;
302 var hour = matches[1];
303 var minute = matches[2];
304 var second = matches[3];
305 var timeZone = matches[5];
306 return ((hour <= 23 && minute <= 59 && second <= 59) ||
307 (hour == 23 && minute == 59 && second == 60)) &&
312 var DATE_TIME_SEPARATOR = /t|\s/i;
313 function date_time(str) {
314 // http://tools.ietf.org/html/rfc3339#section-5.6
315 var dateTime = str.split(DATE_TIME_SEPARATOR);
316 return dateTime.length == 2 && date(dateTime[0]) && time(dateTime[1], true);
320 var NOT_URI_FRAGMENT = /\/|:/;
322 // http://jmrware.com/articles/2009/uri_regexp/URI_regex.html + optional protocol + required "."
323 return NOT_URI_FRAGMENT.test(str) && URI.test(str);
327 var Z_ANCHOR = /[^\\]\\Z/;
328 function regex(str) {
329 if (Z_ANCHOR.test(str)) return false;
338 },{"./util":10}],5:[function(require,module,exports){
341 var resolve = require('./resolve')
342 , util = require('./util')
343 , errorClasses = require('./error_classes')
344 , stableStringify = require('fast-json-stable-stringify');
346 var validateGenerator = require('../dotjs/validate');
349 * Functions below are used inside compiled validations function
352 var ucs2length = util.ucs2length;
353 var equal = require('fast-deep-equal');
355 // this error is thrown by async schemas to return validation errors via exception
356 var ValidationError = errorClasses.Validation;
358 module.exports = compile;
362 * Compiles schema to validation function
364 * @param {Object} schema schema object
365 * @param {Object} root object with information about the root schema for this schema
366 * @param {Object} localRefs the hash of local references inside the schema (created by resolve.id), used for inline resolution
367 * @param {String} baseId base ID for IDs in the schema
368 * @return {Function} validation function
370 function compile(schema, root, localRefs, baseId) {
371 /* jshint validthis: true, evil: true */
372 /* eslint no-shadow: 0 */
375 , refVal = [ undefined ]
383 root = root || { schema: schema, refVal: refVal, refs: refs };
385 var c = checkCompiling.call(this, schema, root, baseId);
386 var compilation = this._compilations[c.index];
387 if (c.compiling) return (compilation.callValidate = callValidate);
389 var formats = this._formats;
390 var RULES = this.RULES;
393 var v = localCompile(schema, root, localRefs, baseId);
394 compilation.validate = v;
395 var cv = compilation.callValidate;
397 cv.schema = v.schema;
400 cv.refVal = v.refVal;
402 cv.$async = v.$async;
403 if (opts.sourceCode) cv.source = v.source;
407 endCompiling.call(this, schema, root, baseId);
410 /* @this {*} - custom context, see passContext option */
411 function callValidate() {
412 /* jshint validthis: true */
413 var validate = compilation.validate;
414 var result = validate.apply(this, arguments);
415 callValidate.errors = validate.errors;
419 function localCompile(_schema, _root, localRefs, baseId) {
420 var isRoot = !_root || (_root && _root.schema == _schema);
421 if (_root.schema != root.schema)
422 return compile.call(self, _schema, _root, localRefs, baseId);
424 var $async = _schema.$async === true;
426 var sourceCode = validateGenerator({
435 MissingRefError: errorClasses.MissingRef,
437 validate: validateGenerator,
440 resolveRef: resolveRef,
441 usePattern: usePattern,
442 useDefault: useDefault,
443 useCustomRule: useCustomRule,
450 sourceCode = vars(refVal, refValCode) + vars(patterns, patternCode)
451 + vars(defaults, defaultCode) + vars(customRules, customRuleCode)
454 if (opts.processCode) sourceCode = opts.processCode(sourceCode, _schema);
455 // console.log('\n\n\n *** \n', JSON.stringify(sourceCode));
458 var makeValidate = new Function(
472 validate = makeValidate(
485 refVal[0] = validate;
487 self.logger.error('Error compiling schema, function code:', sourceCode);
491 validate.schema = _schema;
492 validate.errors = null;
493 validate.refs = refs;
494 validate.refVal = refVal;
495 validate.root = isRoot ? validate : _root;
496 if ($async) validate.$async = true;
497 if (opts.sourceCode === true) {
508 function resolveRef(baseId, ref, isRoot) {
509 ref = resolve.url(baseId, ref);
510 var refIndex = refs[ref];
511 var _refVal, refCode;
512 if (refIndex !== undefined) {
513 _refVal = refVal[refIndex];
514 refCode = 'refVal[' + refIndex + ']';
515 return resolvedRef(_refVal, refCode);
517 if (!isRoot && root.refs) {
518 var rootRefId = root.refs[ref];
519 if (rootRefId !== undefined) {
520 _refVal = root.refVal[rootRefId];
521 refCode = addLocalRef(ref, _refVal);
522 return resolvedRef(_refVal, refCode);
526 refCode = addLocalRef(ref);
527 var v = resolve.call(self, localCompile, root, ref);
528 if (v === undefined) {
529 var localSchema = localRefs && localRefs[ref];
531 v = resolve.inlineRef(localSchema, opts.inlineRefs)
533 : compile.call(self, localSchema, root, localRefs, baseId);
537 if (v === undefined) {
540 replaceLocalRef(ref, v);
541 return resolvedRef(v, refCode);
545 function addLocalRef(ref, v) {
546 var refId = refVal.length;
549 return 'refVal' + refId;
552 function removeLocalRef(ref) {
556 function replaceLocalRef(ref, v) {
557 var refId = refs[ref];
561 function resolvedRef(refVal, code) {
562 return typeof refVal == 'object' || typeof refVal == 'boolean'
563 ? { code: code, schema: refVal, inline: true }
564 : { code: code, $async: refVal && !!refVal.$async };
567 function usePattern(regexStr) {
568 var index = patternsHash[regexStr];
569 if (index === undefined) {
570 index = patternsHash[regexStr] = patterns.length;
571 patterns[index] = regexStr;
573 return 'pattern' + index;
576 function useDefault(value) {
577 switch (typeof value) {
582 return util.toQuotedString(value);
584 if (value === null) return 'null';
585 var valueStr = stableStringify(value);
586 var index = defaultsHash[valueStr];
587 if (index === undefined) {
588 index = defaultsHash[valueStr] = defaults.length;
589 defaults[index] = value;
591 return 'default' + index;
595 function useCustomRule(rule, schema, parentSchema, it) {
596 if (self._opts.validateSchema !== false) {
597 var deps = rule.definition.dependencies;
598 if (deps && !deps.every(function(keyword) {
599 return Object.prototype.hasOwnProperty.call(parentSchema, keyword);
601 throw new Error('parent schema must have all required keywords: ' + deps.join(','));
603 var validateSchema = rule.definition.validateSchema;
604 if (validateSchema) {
605 var valid = validateSchema(schema);
607 var message = 'keyword schema is invalid: ' + self.errorsText(validateSchema.errors);
608 if (self._opts.validateSchema == 'log') self.logger.error(message);
609 else throw new Error(message);
614 var compile = rule.definition.compile
615 , inline = rule.definition.inline
616 , macro = rule.definition.macro;
620 validate = compile.call(self, schema, parentSchema, it);
622 validate = macro.call(self, schema, parentSchema, it);
623 if (opts.validateSchema !== false) self.validateSchema(validate, true);
625 validate = inline.call(self, it, rule.keyword, schema, parentSchema);
627 validate = rule.definition.validate;
628 if (!validate) return;
631 if (validate === undefined)
632 throw new Error('custom keyword "' + rule.keyword + '"failed to compile');
634 var index = customRules.length;
635 customRules[index] = validate;
638 code: 'customRule' + index,
646 * Checks if the schema is currently compiled
648 * @param {Object} schema schema to compile
649 * @param {Object} root root object
650 * @param {String} baseId base schema ID
651 * @return {Object} object with properties "index" (compilation index) and "compiling" (boolean)
653 function checkCompiling(schema, root, baseId) {
654 /* jshint validthis: true */
655 var index = compIndex.call(this, schema, root, baseId);
656 if (index >= 0) return { index: index, compiling: true };
657 index = this._compilations.length;
658 this._compilations[index] = {
663 return { index: index, compiling: false };
668 * Removes the schema from the currently compiled list
670 * @param {Object} schema schema to compile
671 * @param {Object} root root object
672 * @param {String} baseId base schema ID
674 function endCompiling(schema, root, baseId) {
675 /* jshint validthis: true */
676 var i = compIndex.call(this, schema, root, baseId);
677 if (i >= 0) this._compilations.splice(i, 1);
682 * Index of schema compilation in the currently compiled list
684 * @param {Object} schema schema to compile
685 * @param {Object} root root object
686 * @param {String} baseId base schema ID
687 * @return {Integer} compilation index
689 function compIndex(schema, root, baseId) {
690 /* jshint validthis: true */
691 for (var i=0; i<this._compilations.length; i++) {
692 var c = this._compilations[i];
693 if (c.schema == schema && c.root == root && c.baseId == baseId) return i;
699 function patternCode(i, patterns) {
700 return 'var pattern' + i + ' = new RegExp(' + util.toQuotedString(patterns[i]) + ');';
704 function defaultCode(i) {
705 return 'var default' + i + ' = defaults[' + i + '];';
709 function refValCode(i, refVal) {
710 return refVal[i] === undefined ? '' : 'var refVal' + i + ' = refVal[' + i + '];';
714 function customRuleCode(i) {
715 return 'var customRule' + i + ' = customRules[' + i + '];';
719 function vars(arr, statement) {
720 if (!arr.length) return '';
722 for (var i=0; i<arr.length; i++)
723 code += statement(i, arr);
727 },{"../dotjs/validate":38,"./error_classes":3,"./resolve":6,"./util":10,"fast-deep-equal":42,"fast-json-stable-stringify":43}],6:[function(require,module,exports){
730 var URI = require('uri-js')
731 , equal = require('fast-deep-equal')
732 , util = require('./util')
733 , SchemaObject = require('./schema_obj')
734 , traverse = require('json-schema-traverse');
736 module.exports = resolve;
738 resolve.normalizeId = normalizeId;
739 resolve.fullPath = getFullPath;
740 resolve.url = resolveUrl;
741 resolve.ids = resolveIds;
742 resolve.inlineRef = inlineRef;
743 resolve.schema = resolveSchema;
746 * [resolve and compile the references ($ref)]
748 * @param {Function} compile reference to schema compilation funciton (localCompile)
749 * @param {Object} root object with information about the root schema for the current schema
750 * @param {String} ref reference to resolve
751 * @return {Object|Function} schema object (if the schema can be inlined) or validation function
753 function resolve(compile, root, ref) {
754 /* jshint validthis: true */
755 var refVal = this._refs[ref];
756 if (typeof refVal == 'string') {
757 if (this._refs[refVal]) refVal = this._refs[refVal];
758 else return resolve.call(this, compile, root, refVal);
761 refVal = refVal || this._schemas[ref];
762 if (refVal instanceof SchemaObject) {
763 return inlineRef(refVal.schema, this._opts.inlineRefs)
765 : refVal.validate || this._compile(refVal);
768 var res = resolveSchema.call(this, root, ref);
769 var schema, v, baseId;
776 if (schema instanceof SchemaObject) {
777 v = schema.validate || compile.call(this, schema.schema, root, undefined, baseId);
778 } else if (schema !== undefined) {
779 v = inlineRef(schema, this._opts.inlineRefs)
781 : compile.call(this, schema, root, undefined, baseId);
789 * Resolve schema, its root and baseId
791 * @param {Object} root root object with properties schema, refVal, refs
792 * @param {String} ref reference to resolve
793 * @return {Object} object with properties schema, root, baseId
795 function resolveSchema(root, ref) {
796 /* jshint validthis: true */
797 var p = URI.parse(ref)
798 , refPath = _getFullPath(p)
799 , baseId = getFullPath(this._getId(root.schema));
800 if (Object.keys(root.schema).length === 0 || refPath !== baseId) {
801 var id = normalizeId(refPath);
802 var refVal = this._refs[id];
803 if (typeof refVal == 'string') {
804 return resolveRecursive.call(this, root, refVal, p);
805 } else if (refVal instanceof SchemaObject) {
806 if (!refVal.validate) this._compile(refVal);
809 refVal = this._schemas[id];
810 if (refVal instanceof SchemaObject) {
811 if (!refVal.validate) this._compile(refVal);
812 if (id == normalizeId(ref))
813 return { schema: refVal, root: root, baseId: baseId };
819 if (!root.schema) return;
820 baseId = getFullPath(this._getId(root.schema));
822 return getJsonPointer.call(this, p, baseId, root.schema, root);
827 function resolveRecursive(root, ref, parsedRef) {
828 /* jshint validthis: true */
829 var res = resolveSchema.call(this, root, ref);
831 var schema = res.schema;
832 var baseId = res.baseId;
834 var id = this._getId(schema);
835 if (id) baseId = resolveUrl(baseId, id);
836 return getJsonPointer.call(this, parsedRef, baseId, schema, root);
841 var PREVENT_SCOPE_CHANGE = util.toHash(['properties', 'patternProperties', 'enum', 'dependencies', 'definitions']);
843 function getJsonPointer(parsedRef, baseId, schema, root) {
844 /* jshint validthis: true */
845 parsedRef.fragment = parsedRef.fragment || '';
846 if (parsedRef.fragment.slice(0,1) != '/') return;
847 var parts = parsedRef.fragment.split('/');
849 for (var i = 1; i < parts.length; i++) {
852 part = util.unescapeFragment(part);
853 schema = schema[part];
854 if (schema === undefined) break;
856 if (!PREVENT_SCOPE_CHANGE[part]) {
857 id = this._getId(schema);
858 if (id) baseId = resolveUrl(baseId, id);
860 var $ref = resolveUrl(baseId, schema.$ref);
861 var res = resolveSchema.call(this, root, $ref);
871 if (schema !== undefined && schema !== root.schema)
872 return { schema: schema, root: root, baseId: baseId };
876 var SIMPLE_INLINED = util.toHash([
877 'type', 'format', 'pattern',
878 'maxLength', 'minLength',
879 'maxProperties', 'minProperties',
880 'maxItems', 'minItems',
881 'maximum', 'minimum',
882 'uniqueItems', 'multipleOf',
885 function inlineRef(schema, limit) {
886 if (limit === false) return false;
887 if (limit === undefined || limit === true) return checkNoRef(schema);
888 else if (limit) return countKeys(schema) <= limit;
892 function checkNoRef(schema) {
894 if (Array.isArray(schema)) {
895 for (var i=0; i<schema.length; i++) {
897 if (typeof item == 'object' && !checkNoRef(item)) return false;
900 for (var key in schema) {
901 if (key == '$ref') return false;
903 if (typeof item == 'object' && !checkNoRef(item)) return false;
910 function countKeys(schema) {
912 if (Array.isArray(schema)) {
913 for (var i=0; i<schema.length; i++) {
915 if (typeof item == 'object') count += countKeys(item);
916 if (count == Infinity) return Infinity;
919 for (var key in schema) {
920 if (key == '$ref') return Infinity;
921 if (SIMPLE_INLINED[key]) {
925 if (typeof item == 'object') count += countKeys(item) + 1;
926 if (count == Infinity) return Infinity;
934 function getFullPath(id, normalize) {
935 if (normalize !== false) id = normalizeId(id);
936 var p = URI.parse(id);
937 return _getFullPath(p);
941 function _getFullPath(p) {
942 return URI.serialize(p).split('#')[0] + '#';
946 var TRAILING_SLASH_HASH = /#\/?$/;
947 function normalizeId(id) {
948 return id ? id.replace(TRAILING_SLASH_HASH, '') : '';
952 function resolveUrl(baseId, id) {
953 id = normalizeId(id);
954 return URI.resolve(baseId, id);
959 function resolveIds(schema) {
960 var schemaId = normalizeId(this._getId(schema));
961 var baseIds = {'': schemaId};
962 var fullPaths = {'': getFullPath(schemaId, false)};
966 traverse(schema, {allKeys: true}, function(sch, jsonPtr, rootSchema, parentJsonPtr, parentKeyword, parentSchema, keyIndex) {
967 if (jsonPtr === '') return;
968 var id = self._getId(sch);
969 var baseId = baseIds[parentJsonPtr];
970 var fullPath = fullPaths[parentJsonPtr] + '/' + parentKeyword;
971 if (keyIndex !== undefined)
972 fullPath += '/' + (typeof keyIndex == 'number' ? keyIndex : util.escapeFragment(keyIndex));
974 if (typeof id == 'string') {
975 id = baseId = normalizeId(baseId ? URI.resolve(baseId, id) : id);
977 var refVal = self._refs[id];
978 if (typeof refVal == 'string') refVal = self._refs[refVal];
979 if (refVal && refVal.schema) {
980 if (!equal(sch, refVal.schema))
981 throw new Error('id "' + id + '" resolves to more than one schema');
982 } else if (id != normalizeId(fullPath)) {
984 if (localRefs[id] && !equal(sch, localRefs[id]))
985 throw new Error('id "' + id + '" resolves to more than one schema');
988 self._refs[id] = fullPath;
992 baseIds[jsonPtr] = baseId;
993 fullPaths[jsonPtr] = fullPath;
999 },{"./schema_obj":8,"./util":10,"fast-deep-equal":42,"json-schema-traverse":44,"uri-js":45}],7:[function(require,module,exports){
1002 var ruleModules = require('../dotjs')
1003 , toHash = require('./util').toHash;
1005 module.exports = function rules() {
1008 rules: [ { 'maximum': ['exclusiveMaximum'] },
1009 { 'minimum': ['exclusiveMinimum'] }, 'multipleOf', 'format'] },
1011 rules: [ 'maxLength', 'minLength', 'pattern', 'format' ] },
1013 rules: [ 'maxItems', 'minItems', 'items', 'contains', 'uniqueItems' ] },
1015 rules: [ 'maxProperties', 'minProperties', 'required', 'dependencies', 'propertyNames',
1016 { 'properties': ['additionalProperties', 'patternProperties'] } ] },
1017 { rules: [ '$ref', 'const', 'enum', 'not', 'anyOf', 'oneOf', 'allOf', 'if' ] }
1020 var ALL = [ 'type', '$comment' ];
1022 '$schema', '$id', 'id', '$data', '$async', 'title',
1023 'description', 'default', 'definitions',
1024 'examples', 'readOnly', 'writeOnly',
1025 'contentMediaType', 'contentEncoding',
1026 'additionalItems', 'then', 'else'
1028 var TYPES = [ 'number', 'integer', 'string', 'array', 'object', 'boolean', 'null' ];
1029 RULES.all = toHash(ALL);
1030 RULES.types = toHash(TYPES);
1032 RULES.forEach(function (group) {
1033 group.rules = group.rules.map(function (keyword) {
1035 if (typeof keyword == 'object') {
1036 var key = Object.keys(keyword)[0];
1037 implKeywords = keyword[key];
1039 implKeywords.forEach(function (k) {
1041 RULES.all[k] = true;
1045 var rule = RULES.all[keyword] = {
1047 code: ruleModules[keyword],
1048 implements: implKeywords
1053 RULES.all.$comment = {
1054 keyword: '$comment',
1055 code: ruleModules.$comment
1058 if (group.type) RULES.types[group.type] = group;
1061 RULES.keywords = toHash(ALL.concat(KEYWORDS));
1067 },{"../dotjs":27,"./util":10}],8:[function(require,module,exports){
1070 var util = require('./util');
1072 module.exports = SchemaObject;
1074 function SchemaObject(obj) {
1075 util.copy(obj, this);
1078 },{"./util":10}],9:[function(require,module,exports){
1081 // https://mathiasbynens.be/notes/javascript-encoding
1082 // https://github.com/bestiejs/punycode.js - punycode.ucs2.decode
1083 module.exports = function ucs2length(str) {
1090 value = str.charCodeAt(pos++);
1091 if (value >= 0xD800 && value <= 0xDBFF && pos < len) {
1092 // high surrogate, and there is a next character
1093 value = str.charCodeAt(pos);
1094 if ((value & 0xFC00) == 0xDC00) pos++; // low surrogate
1100 },{}],10:[function(require,module,exports){
1106 checkDataType: checkDataType,
1107 checkDataTypes: checkDataTypes,
1108 coerceToTypes: coerceToTypes,
1110 getProperty: getProperty,
1111 escapeQuotes: escapeQuotes,
1112 equal: require('fast-deep-equal'),
1113 ucs2length: require('./ucs2length'),
1114 varOccurences: varOccurences,
1115 varReplace: varReplace,
1116 schemaHasRules: schemaHasRules,
1117 schemaHasRulesExcept: schemaHasRulesExcept,
1118 schemaUnknownRules: schemaUnknownRules,
1119 toQuotedString: toQuotedString,
1120 getPathExpr: getPathExpr,
1123 unescapeFragment: unescapeFragment,
1124 unescapeJsonPointer: unescapeJsonPointer,
1125 escapeFragment: escapeFragment,
1126 escapeJsonPointer: escapeJsonPointer
1130 function copy(o, to) {
1132 for (var key in o) to[key] = o[key];
1137 function checkDataType(dataType, data, strictNumbers, negate) {
1138 var EQUAL = negate ? ' !== ' : ' === '
1139 , AND = negate ? ' || ' : ' && '
1140 , OK = negate ? '!' : ''
1141 , NOT = negate ? '' : '!';
1143 case 'null': return data + EQUAL + 'null';
1144 case 'array': return OK + 'Array.isArray(' + data + ')';
1145 case 'object': return '(' + OK + data + AND +
1146 'typeof ' + data + EQUAL + '"object"' + AND +
1147 NOT + 'Array.isArray(' + data + '))';
1148 case 'integer': return '(typeof ' + data + EQUAL + '"number"' + AND +
1149 NOT + '(' + data + ' % 1)' +
1150 AND + data + EQUAL + data +
1151 (strictNumbers ? (AND + OK + 'isFinite(' + data + ')') : '') + ')';
1152 case 'number': return '(typeof ' + data + EQUAL + '"' + dataType + '"' +
1153 (strictNumbers ? (AND + OK + 'isFinite(' + data + ')') : '') + ')';
1154 default: return 'typeof ' + data + EQUAL + '"' + dataType + '"';
1159 function checkDataTypes(dataTypes, data, strictNumbers) {
1160 switch (dataTypes.length) {
1161 case 1: return checkDataType(dataTypes[0], data, strictNumbers, true);
1164 var types = toHash(dataTypes);
1165 if (types.array && types.object) {
1166 code = types.null ? '(': '(!' + data + ' || ';
1167 code += 'typeof ' + data + ' !== "object")';
1170 delete types.object;
1172 if (types.number) delete types.integer;
1173 for (var t in types)
1174 code += (code ? ' && ' : '' ) + checkDataType(t, data, strictNumbers, true);
1181 var COERCE_TO_TYPES = toHash([ 'string', 'number', 'integer', 'boolean', 'null' ]);
1182 function coerceToTypes(optionCoerceTypes, dataTypes) {
1183 if (Array.isArray(dataTypes)) {
1185 for (var i=0; i<dataTypes.length; i++) {
1186 var t = dataTypes[i];
1187 if (COERCE_TO_TYPES[t]) types[types.length] = t;
1188 else if (optionCoerceTypes === 'array' && t === 'array') types[types.length] = t;
1190 if (types.length) return types;
1191 } else if (COERCE_TO_TYPES[dataTypes]) {
1193 } else if (optionCoerceTypes === 'array' && dataTypes === 'array') {
1199 function toHash(arr) {
1201 for (var i=0; i<arr.length; i++) hash[arr[i]] = true;
1206 var IDENTIFIER = /^[a-z$_][a-z$_0-9]*$/i;
1207 var SINGLE_QUOTE = /'|\\/g;
1208 function getProperty(key) {
1209 return typeof key == 'number'
1211 : IDENTIFIER.test(key)
1213 : "['" + escapeQuotes(key) + "']";
1217 function escapeQuotes(str) {
1218 return str.replace(SINGLE_QUOTE, '\\$&')
1219 .replace(/\n/g, '\\n')
1220 .replace(/\r/g, '\\r')
1221 .replace(/\f/g, '\\f')
1222 .replace(/\t/g, '\\t');
1226 function varOccurences(str, dataVar) {
1227 dataVar += '[^0-9]';
1228 var matches = str.match(new RegExp(dataVar, 'g'));
1229 return matches ? matches.length : 0;
1233 function varReplace(str, dataVar, expr) {
1234 dataVar += '([^0-9])';
1235 expr = expr.replace(/\$/g, '$$$$');
1236 return str.replace(new RegExp(dataVar, 'g'), expr + '$1');
1240 function schemaHasRules(schema, rules) {
1241 if (typeof schema == 'boolean') return !schema;
1242 for (var key in schema) if (rules[key]) return true;
1246 function schemaHasRulesExcept(schema, rules, exceptKeyword) {
1247 if (typeof schema == 'boolean') return !schema && exceptKeyword != 'not';
1248 for (var key in schema) if (key != exceptKeyword && rules[key]) return true;
1252 function schemaUnknownRules(schema, rules) {
1253 if (typeof schema == 'boolean') return;
1254 for (var key in schema) if (!rules[key]) return key;
1258 function toQuotedString(str) {
1259 return '\'' + escapeQuotes(str) + '\'';
1263 function getPathExpr(currentPath, expr, jsonPointers, isNumber) {
1264 var path = jsonPointers // false by default
1265 ? '\'/\' + ' + expr + (isNumber ? '' : '.replace(/~/g, \'~0\').replace(/\\//g, \'~1\')')
1266 : (isNumber ? '\'[\' + ' + expr + ' + \']\'' : '\'[\\\'\' + ' + expr + ' + \'\\\']\'');
1267 return joinPaths(currentPath, path);
1271 function getPath(currentPath, prop, jsonPointers) {
1272 var path = jsonPointers // false by default
1273 ? toQuotedString('/' + escapeJsonPointer(prop))
1274 : toQuotedString(getProperty(prop));
1275 return joinPaths(currentPath, path);
1279 var JSON_POINTER = /^\/(?:[^~]|~0|~1)*$/;
1280 var RELATIVE_JSON_POINTER = /^([0-9]+)(#|\/(?:[^~]|~0|~1)*)?$/;
1281 function getData($data, lvl, paths) {
1282 var up, jsonPointer, data, matches;
1283 if ($data === '') return 'rootData';
1284 if ($data[0] == '/') {
1285 if (!JSON_POINTER.test($data)) throw new Error('Invalid JSON-pointer: ' + $data);
1286 jsonPointer = $data;
1289 matches = $data.match(RELATIVE_JSON_POINTER);
1290 if (!matches) throw new Error('Invalid JSON-pointer: ' + $data);
1292 jsonPointer = matches[2];
1293 if (jsonPointer == '#') {
1294 if (up >= lvl) throw new Error('Cannot access property/index ' + up + ' levels up, current level is ' + lvl);
1295 return paths[lvl - up];
1298 if (up > lvl) throw new Error('Cannot access data ' + up + ' levels up, current level is ' + lvl);
1299 data = 'data' + ((lvl - up) || '');
1300 if (!jsonPointer) return data;
1304 var segments = jsonPointer.split('/');
1305 for (var i=0; i<segments.length; i++) {
1306 var segment = segments[i];
1308 data += getProperty(unescapeJsonPointer(segment));
1309 expr += ' && ' + data;
1316 function joinPaths (a, b) {
1317 if (a == '""') return b;
1318 return (a + ' + ' + b).replace(/([^\\])' \+ '/g, '$1');
1322 function unescapeFragment(str) {
1323 return unescapeJsonPointer(decodeURIComponent(str));
1327 function escapeFragment(str) {
1328 return encodeURIComponent(escapeJsonPointer(str));
1332 function escapeJsonPointer(str) {
1333 return str.replace(/~/g, '~0').replace(/\//g, '~1');
1337 function unescapeJsonPointer(str) {
1338 return str.replace(/~1/g, '/').replace(/~0/g, '~');
1341 },{"./ucs2length":9,"fast-deep-equal":42}],11:[function(require,module,exports){
1360 'additionalProperties',
1366 module.exports = function (metaSchema, keywordsJsonPointers) {
1367 for (var i=0; i<keywordsJsonPointers.length; i++) {
1368 metaSchema = JSON.parse(JSON.stringify(metaSchema));
1369 var segments = keywordsJsonPointers[i].split('/');
1370 var keywords = metaSchema;
1372 for (j=1; j<segments.length; j++)
1373 keywords = keywords[segments[j]];
1375 for (j=0; j<KEYWORDS.length; j++) {
1376 var key = KEYWORDS[j];
1377 var schema = keywords[key];
1382 { $ref: 'https://raw.githubusercontent.com/ajv-validator/ajv/master/lib/refs/data.json#' }
1392 },{}],12:[function(require,module,exports){
1395 var metaSchema = require('./refs/json-schema-draft-07.json');
1398 $id: 'https://github.com/ajv-validator/ajv/blob/master/lib/definition_schema.js',
1400 simpleTypes: metaSchema.definitions.simpleTypes
1404 schema: ['validate'],
1405 $data: ['validate'],
1406 statements: ['inline'],
1407 valid: {not: {required: ['macro']}}
1410 type: metaSchema.properties.type,
1411 schema: {type: 'boolean'},
1412 statements: {type: 'boolean'},
1415 items: {type: 'string'}
1417 metaSchema: {type: 'object'},
1418 modifying: {type: 'boolean'},
1419 valid: {type: 'boolean'},
1420 $data: {type: 'boolean'},
1421 async: {type: 'boolean'},
1431 },{"./refs/json-schema-draft-07.json":41}],13:[function(require,module,exports){
1433 module.exports = function generate__limit(it, $keyword, $ruleType) {
1435 var $lvl = it.level;
1436 var $dataLvl = it.dataLevel;
1437 var $schema = it.schema[$keyword];
1438 var $schemaPath = it.schemaPath + it.util.getProperty($keyword);
1439 var $errSchemaPath = it.errSchemaPath + '/' + $keyword;
1440 var $breakOnError = !it.opts.allErrors;
1442 var $data = 'data' + ($dataLvl || '');
1443 var $isData = it.opts.$data && $schema && $schema.$data,
1446 out += ' var schema' + ($lvl) + ' = ' + (it.util.getData($schema.$data, $dataLvl, it.dataPathArr)) + '; ';
1447 $schemaValue = 'schema' + $lvl;
1449 $schemaValue = $schema;
1451 var $isMax = $keyword == 'maximum',
1452 $exclusiveKeyword = $isMax ? 'exclusiveMaximum' : 'exclusiveMinimum',
1453 $schemaExcl = it.schema[$exclusiveKeyword],
1454 $isDataExcl = it.opts.$data && $schemaExcl && $schemaExcl.$data,
1455 $op = $isMax ? '<' : '>',
1456 $notOp = $isMax ? '>' : '<',
1457 $errorKeyword = undefined;
1458 if (!($isData || typeof $schema == 'number' || $schema === undefined)) {
1459 throw new Error($keyword + ' must be number');
1461 if (!($isDataExcl || $schemaExcl === undefined || typeof $schemaExcl == 'number' || typeof $schemaExcl == 'boolean')) {
1462 throw new Error($exclusiveKeyword + ' must be number or boolean');
1465 var $schemaValueExcl = it.util.getData($schemaExcl.$data, $dataLvl, it.dataPathArr),
1466 $exclusive = 'exclusive' + $lvl,
1467 $exclType = 'exclType' + $lvl,
1468 $exclIsNumber = 'exclIsNumber' + $lvl,
1469 $opExpr = 'op' + $lvl,
1470 $opStr = '\' + ' + $opExpr + ' + \'';
1471 out += ' var schemaExcl' + ($lvl) + ' = ' + ($schemaValueExcl) + '; ';
1472 $schemaValueExcl = 'schemaExcl' + $lvl;
1473 out += ' var ' + ($exclusive) + '; var ' + ($exclType) + ' = typeof ' + ($schemaValueExcl) + '; if (' + ($exclType) + ' != \'boolean\' && ' + ($exclType) + ' != \'undefined\' && ' + ($exclType) + ' != \'number\') { ';
1474 var $errorKeyword = $exclusiveKeyword;
1475 var $$outStack = $$outStack || [];
1476 $$outStack.push(out);
1477 out = ''; /* istanbul ignore else */
1478 if (it.createErrors !== false) {
1479 out += ' { keyword: \'' + ($errorKeyword || '_exclusiveLimit') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: ' + (it.util.toQuotedString($errSchemaPath)) + ' , params: {} ';
1480 if (it.opts.messages !== false) {
1481 out += ' , message: \'' + ($exclusiveKeyword) + ' should be boolean\' ';
1483 if (it.opts.verbose) {
1484 out += ' , schema: validate.schema' + ($schemaPath) + ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' ';
1491 out = $$outStack.pop();
1492 if (!it.compositeRule && $breakOnError) {
1493 /* istanbul ignore if */
1495 out += ' throw new ValidationError([' + (__err) + ']); ';
1497 out += ' validate.errors = [' + (__err) + ']; return false; ';
1500 out += ' var err = ' + (__err) + '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ';
1502 out += ' } else if ( ';
1504 out += ' (' + ($schemaValue) + ' !== undefined && typeof ' + ($schemaValue) + ' != \'number\') || ';
1506 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) + '=\'; ';
1507 if ($schema === undefined) {
1508 $errorKeyword = $exclusiveKeyword;
1509 $errSchemaPath = it.errSchemaPath + '/' + $exclusiveKeyword;
1510 $schemaValue = $schemaValueExcl;
1511 $isData = $isDataExcl;
1514 var $exclIsNumber = typeof $schemaExcl == 'number',
1516 if ($exclIsNumber && $isData) {
1517 var $opExpr = '\'' + $opStr + '\'';
1520 out += ' (' + ($schemaValue) + ' !== undefined && typeof ' + ($schemaValue) + ' != \'number\') || ';
1522 out += ' ( ' + ($schemaValue) + ' === undefined || ' + ($schemaExcl) + ' ' + ($op) + '= ' + ($schemaValue) + ' ? ' + ($data) + ' ' + ($notOp) + '= ' + ($schemaExcl) + ' : ' + ($data) + ' ' + ($notOp) + ' ' + ($schemaValue) + ' ) || ' + ($data) + ' !== ' + ($data) + ') { ';
1524 if ($exclIsNumber && $schema === undefined) {
1526 $errorKeyword = $exclusiveKeyword;
1527 $errSchemaPath = it.errSchemaPath + '/' + $exclusiveKeyword;
1528 $schemaValue = $schemaExcl;
1531 if ($exclIsNumber) $schemaValue = Math[$isMax ? 'min' : 'max']($schemaExcl, $schema);
1532 if ($schemaExcl === ($exclIsNumber ? $schemaValue : true)) {
1534 $errorKeyword = $exclusiveKeyword;
1535 $errSchemaPath = it.errSchemaPath + '/' + $exclusiveKeyword;
1542 var $opExpr = '\'' + $opStr + '\'';
1545 out += ' (' + ($schemaValue) + ' !== undefined && typeof ' + ($schemaValue) + ' != \'number\') || ';
1547 out += ' ' + ($data) + ' ' + ($notOp) + ' ' + ($schemaValue) + ' || ' + ($data) + ' !== ' + ($data) + ') { ';
1550 $errorKeyword = $errorKeyword || $keyword;
1551 var $$outStack = $$outStack || [];
1552 $$outStack.push(out);
1553 out = ''; /* istanbul ignore else */
1554 if (it.createErrors !== false) {
1555 out += ' { keyword: \'' + ($errorKeyword || '_limit') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: ' + (it.util.toQuotedString($errSchemaPath)) + ' , params: { comparison: ' + ($opExpr) + ', limit: ' + ($schemaValue) + ', exclusive: ' + ($exclusive) + ' } ';
1556 if (it.opts.messages !== false) {
1557 out += ' , message: \'should be ' + ($opStr) + ' ';
1559 out += '\' + ' + ($schemaValue);
1561 out += '' + ($schemaValue) + '\'';
1564 if (it.opts.verbose) {
1565 out += ' , schema: ';
1567 out += 'validate.schema' + ($schemaPath);
1569 out += '' + ($schema);
1571 out += ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' ';
1578 out = $$outStack.pop();
1579 if (!it.compositeRule && $breakOnError) {
1580 /* istanbul ignore if */
1582 out += ' throw new ValidationError([' + (__err) + ']); ';
1584 out += ' validate.errors = [' + (__err) + ']; return false; ';
1587 out += ' var err = ' + (__err) + '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ';
1590 if ($breakOnError) {
1596 },{}],14:[function(require,module,exports){
1598 module.exports = function generate__limitItems(it, $keyword, $ruleType) {
1600 var $lvl = it.level;
1601 var $dataLvl = it.dataLevel;
1602 var $schema = it.schema[$keyword];
1603 var $schemaPath = it.schemaPath + it.util.getProperty($keyword);
1604 var $errSchemaPath = it.errSchemaPath + '/' + $keyword;
1605 var $breakOnError = !it.opts.allErrors;
1607 var $data = 'data' + ($dataLvl || '');
1608 var $isData = it.opts.$data && $schema && $schema.$data,
1611 out += ' var schema' + ($lvl) + ' = ' + (it.util.getData($schema.$data, $dataLvl, it.dataPathArr)) + '; ';
1612 $schemaValue = 'schema' + $lvl;
1614 $schemaValue = $schema;
1616 if (!($isData || typeof $schema == 'number')) {
1617 throw new Error($keyword + ' must be number');
1619 var $op = $keyword == 'maxItems' ? '>' : '<';
1622 out += ' (' + ($schemaValue) + ' !== undefined && typeof ' + ($schemaValue) + ' != \'number\') || ';
1624 out += ' ' + ($data) + '.length ' + ($op) + ' ' + ($schemaValue) + ') { ';
1625 var $errorKeyword = $keyword;
1626 var $$outStack = $$outStack || [];
1627 $$outStack.push(out);
1628 out = ''; /* istanbul ignore else */
1629 if (it.createErrors !== false) {
1630 out += ' { keyword: \'' + ($errorKeyword || '_limitItems') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: ' + (it.util.toQuotedString($errSchemaPath)) + ' , params: { limit: ' + ($schemaValue) + ' } ';
1631 if (it.opts.messages !== false) {
1632 out += ' , message: \'should NOT have ';
1633 if ($keyword == 'maxItems') {
1640 out += '\' + ' + ($schemaValue) + ' + \'';
1642 out += '' + ($schema);
1646 if (it.opts.verbose) {
1647 out += ' , schema: ';
1649 out += 'validate.schema' + ($schemaPath);
1651 out += '' + ($schema);
1653 out += ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' ';
1660 out = $$outStack.pop();
1661 if (!it.compositeRule && $breakOnError) {
1662 /* istanbul ignore if */
1664 out += ' throw new ValidationError([' + (__err) + ']); ';
1666 out += ' validate.errors = [' + (__err) + ']; return false; ';
1669 out += ' var err = ' + (__err) + '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ';
1672 if ($breakOnError) {
1678 },{}],15:[function(require,module,exports){
1680 module.exports = function generate__limitLength(it, $keyword, $ruleType) {
1682 var $lvl = it.level;
1683 var $dataLvl = it.dataLevel;
1684 var $schema = it.schema[$keyword];
1685 var $schemaPath = it.schemaPath + it.util.getProperty($keyword);
1686 var $errSchemaPath = it.errSchemaPath + '/' + $keyword;
1687 var $breakOnError = !it.opts.allErrors;
1689 var $data = 'data' + ($dataLvl || '');
1690 var $isData = it.opts.$data && $schema && $schema.$data,
1693 out += ' var schema' + ($lvl) + ' = ' + (it.util.getData($schema.$data, $dataLvl, it.dataPathArr)) + '; ';
1694 $schemaValue = 'schema' + $lvl;
1696 $schemaValue = $schema;
1698 if (!($isData || typeof $schema == 'number')) {
1699 throw new Error($keyword + ' must be number');
1701 var $op = $keyword == 'maxLength' ? '>' : '<';
1704 out += ' (' + ($schemaValue) + ' !== undefined && typeof ' + ($schemaValue) + ' != \'number\') || ';
1706 if (it.opts.unicode === false) {
1707 out += ' ' + ($data) + '.length ';
1709 out += ' ucs2length(' + ($data) + ') ';
1711 out += ' ' + ($op) + ' ' + ($schemaValue) + ') { ';
1712 var $errorKeyword = $keyword;
1713 var $$outStack = $$outStack || [];
1714 $$outStack.push(out);
1715 out = ''; /* istanbul ignore else */
1716 if (it.createErrors !== false) {
1717 out += ' { keyword: \'' + ($errorKeyword || '_limitLength') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: ' + (it.util.toQuotedString($errSchemaPath)) + ' , params: { limit: ' + ($schemaValue) + ' } ';
1718 if (it.opts.messages !== false) {
1719 out += ' , message: \'should NOT be ';
1720 if ($keyword == 'maxLength') {
1727 out += '\' + ' + ($schemaValue) + ' + \'';
1729 out += '' + ($schema);
1731 out += ' characters\' ';
1733 if (it.opts.verbose) {
1734 out += ' , schema: ';
1736 out += 'validate.schema' + ($schemaPath);
1738 out += '' + ($schema);
1740 out += ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' ';
1747 out = $$outStack.pop();
1748 if (!it.compositeRule && $breakOnError) {
1749 /* istanbul ignore if */
1751 out += ' throw new ValidationError([' + (__err) + ']); ';
1753 out += ' validate.errors = [' + (__err) + ']; return false; ';
1756 out += ' var err = ' + (__err) + '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ';
1759 if ($breakOnError) {
1765 },{}],16:[function(require,module,exports){
1767 module.exports = function generate__limitProperties(it, $keyword, $ruleType) {
1769 var $lvl = it.level;
1770 var $dataLvl = it.dataLevel;
1771 var $schema = it.schema[$keyword];
1772 var $schemaPath = it.schemaPath + it.util.getProperty($keyword);
1773 var $errSchemaPath = it.errSchemaPath + '/' + $keyword;
1774 var $breakOnError = !it.opts.allErrors;
1776 var $data = 'data' + ($dataLvl || '');
1777 var $isData = it.opts.$data && $schema && $schema.$data,
1780 out += ' var schema' + ($lvl) + ' = ' + (it.util.getData($schema.$data, $dataLvl, it.dataPathArr)) + '; ';
1781 $schemaValue = 'schema' + $lvl;
1783 $schemaValue = $schema;
1785 if (!($isData || typeof $schema == 'number')) {
1786 throw new Error($keyword + ' must be number');
1788 var $op = $keyword == 'maxProperties' ? '>' : '<';
1791 out += ' (' + ($schemaValue) + ' !== undefined && typeof ' + ($schemaValue) + ' != \'number\') || ';
1793 out += ' Object.keys(' + ($data) + ').length ' + ($op) + ' ' + ($schemaValue) + ') { ';
1794 var $errorKeyword = $keyword;
1795 var $$outStack = $$outStack || [];
1796 $$outStack.push(out);
1797 out = ''; /* istanbul ignore else */
1798 if (it.createErrors !== false) {
1799 out += ' { keyword: \'' + ($errorKeyword || '_limitProperties') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: ' + (it.util.toQuotedString($errSchemaPath)) + ' , params: { limit: ' + ($schemaValue) + ' } ';
1800 if (it.opts.messages !== false) {
1801 out += ' , message: \'should NOT have ';
1802 if ($keyword == 'maxProperties') {
1809 out += '\' + ' + ($schemaValue) + ' + \'';
1811 out += '' + ($schema);
1813 out += ' properties\' ';
1815 if (it.opts.verbose) {
1816 out += ' , schema: ';
1818 out += 'validate.schema' + ($schemaPath);
1820 out += '' + ($schema);
1822 out += ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' ';
1829 out = $$outStack.pop();
1830 if (!it.compositeRule && $breakOnError) {
1831 /* istanbul ignore if */
1833 out += ' throw new ValidationError([' + (__err) + ']); ';
1835 out += ' validate.errors = [' + (__err) + ']; return false; ';
1838 out += ' var err = ' + (__err) + '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ';
1841 if ($breakOnError) {
1847 },{}],17:[function(require,module,exports){
1849 module.exports = function generate_allOf(it, $keyword, $ruleType) {
1851 var $schema = it.schema[$keyword];
1852 var $schemaPath = it.schemaPath + it.util.getProperty($keyword);
1853 var $errSchemaPath = it.errSchemaPath + '/' + $keyword;
1854 var $breakOnError = !it.opts.allErrors;
1855 var $it = it.util.copy(it);
1856 var $closingBraces = '';
1858 var $nextValid = 'valid' + $it.level;
1859 var $currentBaseId = $it.baseId,
1860 $allSchemasEmpty = true;
1864 l1 = arr1.length - 1;
1866 $sch = arr1[$i += 1];
1867 if ((it.opts.strictKeywords ? (typeof $sch == 'object' && Object.keys($sch).length > 0) || $sch === false : it.util.schemaHasRules($sch, it.RULES.all))) {
1868 $allSchemasEmpty = false;
1870 $it.schemaPath = $schemaPath + '[' + $i + ']';
1871 $it.errSchemaPath = $errSchemaPath + '/' + $i;
1872 out += ' ' + (it.validate($it)) + ' ';
1873 $it.baseId = $currentBaseId;
1874 if ($breakOnError) {
1875 out += ' if (' + ($nextValid) + ') { ';
1876 $closingBraces += '}';
1881 if ($breakOnError) {
1882 if ($allSchemasEmpty) {
1883 out += ' if (true) { ';
1885 out += ' ' + ($closingBraces.slice(0, -1)) + ' ';
1891 },{}],18:[function(require,module,exports){
1893 module.exports = function generate_anyOf(it, $keyword, $ruleType) {
1895 var $lvl = it.level;
1896 var $dataLvl = it.dataLevel;
1897 var $schema = it.schema[$keyword];
1898 var $schemaPath = it.schemaPath + it.util.getProperty($keyword);
1899 var $errSchemaPath = it.errSchemaPath + '/' + $keyword;
1900 var $breakOnError = !it.opts.allErrors;
1901 var $data = 'data' + ($dataLvl || '');
1902 var $valid = 'valid' + $lvl;
1903 var $errs = 'errs__' + $lvl;
1904 var $it = it.util.copy(it);
1905 var $closingBraces = '';
1907 var $nextValid = 'valid' + $it.level;
1908 var $noEmptySchema = $schema.every(function($sch) {
1909 return (it.opts.strictKeywords ? (typeof $sch == 'object' && Object.keys($sch).length > 0) || $sch === false : it.util.schemaHasRules($sch, it.RULES.all));
1911 if ($noEmptySchema) {
1912 var $currentBaseId = $it.baseId;
1913 out += ' var ' + ($errs) + ' = errors; var ' + ($valid) + ' = false; ';
1914 var $wasComposite = it.compositeRule;
1915 it.compositeRule = $it.compositeRule = true;
1919 l1 = arr1.length - 1;
1921 $sch = arr1[$i += 1];
1923 $it.schemaPath = $schemaPath + '[' + $i + ']';
1924 $it.errSchemaPath = $errSchemaPath + '/' + $i;
1925 out += ' ' + (it.validate($it)) + ' ';
1926 $it.baseId = $currentBaseId;
1927 out += ' ' + ($valid) + ' = ' + ($valid) + ' || ' + ($nextValid) + '; if (!' + ($valid) + ') { ';
1928 $closingBraces += '}';
1931 it.compositeRule = $it.compositeRule = $wasComposite;
1932 out += ' ' + ($closingBraces) + ' if (!' + ($valid) + ') { var err = '; /* istanbul ignore else */
1933 if (it.createErrors !== false) {
1934 out += ' { keyword: \'' + ('anyOf') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: ' + (it.util.toQuotedString($errSchemaPath)) + ' , params: {} ';
1935 if (it.opts.messages !== false) {
1936 out += ' , message: \'should match some schema in anyOf\' ';
1938 if (it.opts.verbose) {
1939 out += ' , schema: validate.schema' + ($schemaPath) + ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' ';
1945 out += '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ';
1946 if (!it.compositeRule && $breakOnError) {
1947 /* istanbul ignore if */
1949 out += ' throw new ValidationError(vErrors); ';
1951 out += ' validate.errors = vErrors; return false; ';
1954 out += ' } else { errors = ' + ($errs) + '; if (vErrors !== null) { if (' + ($errs) + ') vErrors.length = ' + ($errs) + '; else vErrors = null; } ';
1955 if (it.opts.allErrors) {
1959 if ($breakOnError) {
1960 out += ' if (true) { ';
1966 },{}],19:[function(require,module,exports){
1968 module.exports = function generate_comment(it, $keyword, $ruleType) {
1970 var $schema = it.schema[$keyword];
1971 var $errSchemaPath = it.errSchemaPath + '/' + $keyword;
1972 var $breakOnError = !it.opts.allErrors;
1973 var $comment = it.util.toQuotedString($schema);
1974 if (it.opts.$comment === true) {
1975 out += ' console.log(' + ($comment) + ');';
1976 } else if (typeof it.opts.$comment == 'function') {
1977 out += ' self._opts.$comment(' + ($comment) + ', ' + (it.util.toQuotedString($errSchemaPath)) + ', validate.root.schema);';
1982 },{}],20:[function(require,module,exports){
1984 module.exports = function generate_const(it, $keyword, $ruleType) {
1986 var $lvl = it.level;
1987 var $dataLvl = it.dataLevel;
1988 var $schema = it.schema[$keyword];
1989 var $schemaPath = it.schemaPath + it.util.getProperty($keyword);
1990 var $errSchemaPath = it.errSchemaPath + '/' + $keyword;
1991 var $breakOnError = !it.opts.allErrors;
1992 var $data = 'data' + ($dataLvl || '');
1993 var $valid = 'valid' + $lvl;
1994 var $isData = it.opts.$data && $schema && $schema.$data,
1997 out += ' var schema' + ($lvl) + ' = ' + (it.util.getData($schema.$data, $dataLvl, it.dataPathArr)) + '; ';
1998 $schemaValue = 'schema' + $lvl;
2000 $schemaValue = $schema;
2003 out += ' var schema' + ($lvl) + ' = validate.schema' + ($schemaPath) + ';';
2005 out += 'var ' + ($valid) + ' = equal(' + ($data) + ', schema' + ($lvl) + '); if (!' + ($valid) + ') { ';
2006 var $$outStack = $$outStack || [];
2007 $$outStack.push(out);
2008 out = ''; /* istanbul ignore else */
2009 if (it.createErrors !== false) {
2010 out += ' { keyword: \'' + ('const') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: ' + (it.util.toQuotedString($errSchemaPath)) + ' , params: { allowedValue: schema' + ($lvl) + ' } ';
2011 if (it.opts.messages !== false) {
2012 out += ' , message: \'should be equal to constant\' ';
2014 if (it.opts.verbose) {
2015 out += ' , schema: validate.schema' + ($schemaPath) + ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' ';
2022 out = $$outStack.pop();
2023 if (!it.compositeRule && $breakOnError) {
2024 /* istanbul ignore if */
2026 out += ' throw new ValidationError([' + (__err) + ']); ';
2028 out += ' validate.errors = [' + (__err) + ']; return false; ';
2031 out += ' var err = ' + (__err) + '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ';
2034 if ($breakOnError) {
2040 },{}],21:[function(require,module,exports){
2042 module.exports = function generate_contains(it, $keyword, $ruleType) {
2044 var $lvl = it.level;
2045 var $dataLvl = it.dataLevel;
2046 var $schema = it.schema[$keyword];
2047 var $schemaPath = it.schemaPath + it.util.getProperty($keyword);
2048 var $errSchemaPath = it.errSchemaPath + '/' + $keyword;
2049 var $breakOnError = !it.opts.allErrors;
2050 var $data = 'data' + ($dataLvl || '');
2051 var $valid = 'valid' + $lvl;
2052 var $errs = 'errs__' + $lvl;
2053 var $it = it.util.copy(it);
2054 var $closingBraces = '';
2056 var $nextValid = 'valid' + $it.level;
2057 var $idx = 'i' + $lvl,
2058 $dataNxt = $it.dataLevel = it.dataLevel + 1,
2059 $nextData = 'data' + $dataNxt,
2060 $currentBaseId = it.baseId,
2061 $nonEmptySchema = (it.opts.strictKeywords ? (typeof $schema == 'object' && Object.keys($schema).length > 0) || $schema === false : it.util.schemaHasRules($schema, it.RULES.all));
2062 out += 'var ' + ($errs) + ' = errors;var ' + ($valid) + ';';
2063 if ($nonEmptySchema) {
2064 var $wasComposite = it.compositeRule;
2065 it.compositeRule = $it.compositeRule = true;
2066 $it.schema = $schema;
2067 $it.schemaPath = $schemaPath;
2068 $it.errSchemaPath = $errSchemaPath;
2069 out += ' var ' + ($nextValid) + ' = false; for (var ' + ($idx) + ' = 0; ' + ($idx) + ' < ' + ($data) + '.length; ' + ($idx) + '++) { ';
2070 $it.errorPath = it.util.getPathExpr(it.errorPath, $idx, it.opts.jsonPointers, true);
2071 var $passData = $data + '[' + $idx + ']';
2072 $it.dataPathArr[$dataNxt] = $idx;
2073 var $code = it.validate($it);
2074 $it.baseId = $currentBaseId;
2075 if (it.util.varOccurences($code, $nextData) < 2) {
2076 out += ' ' + (it.util.varReplace($code, $nextData, $passData)) + ' ';
2078 out += ' var ' + ($nextData) + ' = ' + ($passData) + '; ' + ($code) + ' ';
2080 out += ' if (' + ($nextValid) + ') break; } ';
2081 it.compositeRule = $it.compositeRule = $wasComposite;
2082 out += ' ' + ($closingBraces) + ' if (!' + ($nextValid) + ') {';
2084 out += ' if (' + ($data) + '.length == 0) {';
2086 var $$outStack = $$outStack || [];
2087 $$outStack.push(out);
2088 out = ''; /* istanbul ignore else */
2089 if (it.createErrors !== false) {
2090 out += ' { keyword: \'' + ('contains') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: ' + (it.util.toQuotedString($errSchemaPath)) + ' , params: {} ';
2091 if (it.opts.messages !== false) {
2092 out += ' , message: \'should contain a valid item\' ';
2094 if (it.opts.verbose) {
2095 out += ' , schema: validate.schema' + ($schemaPath) + ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' ';
2102 out = $$outStack.pop();
2103 if (!it.compositeRule && $breakOnError) {
2104 /* istanbul ignore if */
2106 out += ' throw new ValidationError([' + (__err) + ']); ';
2108 out += ' validate.errors = [' + (__err) + ']; return false; ';
2111 out += ' var err = ' + (__err) + '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ';
2113 out += ' } else { ';
2114 if ($nonEmptySchema) {
2115 out += ' errors = ' + ($errs) + '; if (vErrors !== null) { if (' + ($errs) + ') vErrors.length = ' + ($errs) + '; else vErrors = null; } ';
2117 if (it.opts.allErrors) {
2123 },{}],22:[function(require,module,exports){
2125 module.exports = function generate_custom(it, $keyword, $ruleType) {
2127 var $lvl = it.level;
2128 var $dataLvl = it.dataLevel;
2129 var $schema = it.schema[$keyword];
2130 var $schemaPath = it.schemaPath + it.util.getProperty($keyword);
2131 var $errSchemaPath = it.errSchemaPath + '/' + $keyword;
2132 var $breakOnError = !it.opts.allErrors;
2134 var $data = 'data' + ($dataLvl || '');
2135 var $valid = 'valid' + $lvl;
2136 var $errs = 'errs__' + $lvl;
2137 var $isData = it.opts.$data && $schema && $schema.$data,
2140 out += ' var schema' + ($lvl) + ' = ' + (it.util.getData($schema.$data, $dataLvl, it.dataPathArr)) + '; ';
2141 $schemaValue = 'schema' + $lvl;
2143 $schemaValue = $schema;
2146 $definition = 'definition' + $lvl,
2147 $rDef = $rule.definition,
2148 $closingBraces = '';
2149 var $compile, $inline, $macro, $ruleValidate, $validateCode;
2150 if ($isData && $rDef.$data) {
2151 $validateCode = 'keywordValidate' + $lvl;
2152 var $validateSchema = $rDef.validateSchema;
2153 out += ' var ' + ($definition) + ' = RULES.custom[\'' + ($keyword) + '\'].definition; var ' + ($validateCode) + ' = ' + ($definition) + '.validate;';
2155 $ruleValidate = it.useCustomRule($rule, $schema, it.schema, it);
2156 if (!$ruleValidate) return;
2157 $schemaValue = 'validate.schema' + $schemaPath;
2158 $validateCode = $ruleValidate.code;
2159 $compile = $rDef.compile;
2160 $inline = $rDef.inline;
2161 $macro = $rDef.macro;
2163 var $ruleErrs = $validateCode + '.errors',
2165 $ruleErr = 'ruleErr' + $lvl,
2166 $asyncKeyword = $rDef.async;
2167 if ($asyncKeyword && !it.async) throw new Error('async keyword in sync schema');
2168 if (!($inline || $macro)) {
2169 out += '' + ($ruleErrs) + ' = null;';
2171 out += 'var ' + ($errs) + ' = errors;var ' + ($valid) + ';';
2172 if ($isData && $rDef.$data) {
2173 $closingBraces += '}';
2174 out += ' if (' + ($schemaValue) + ' === undefined) { ' + ($valid) + ' = true; } else { ';
2175 if ($validateSchema) {
2176 $closingBraces += '}';
2177 out += ' ' + ($valid) + ' = ' + ($definition) + '.validateSchema(' + ($schemaValue) + '); if (' + ($valid) + ') { ';
2181 if ($rDef.statements) {
2182 out += ' ' + ($ruleValidate.validate) + ' ';
2184 out += ' ' + ($valid) + ' = ' + ($ruleValidate.validate) + '; ';
2186 } else if ($macro) {
2187 var $it = it.util.copy(it);
2188 var $closingBraces = '';
2190 var $nextValid = 'valid' + $it.level;
2191 $it.schema = $ruleValidate.validate;
2192 $it.schemaPath = '';
2193 var $wasComposite = it.compositeRule;
2194 it.compositeRule = $it.compositeRule = true;
2195 var $code = it.validate($it).replace(/validate\.schema/g, $validateCode);
2196 it.compositeRule = $it.compositeRule = $wasComposite;
2197 out += ' ' + ($code);
2199 var $$outStack = $$outStack || [];
2200 $$outStack.push(out);
2202 out += ' ' + ($validateCode) + '.call( ';
2203 if (it.opts.passContext) {
2208 if ($compile || $rDef.schema === false) {
2209 out += ' , ' + ($data) + ' ';
2211 out += ' , ' + ($schemaValue) + ' , ' + ($data) + ' , validate.schema' + (it.schemaPath) + ' ';
2213 out += ' , (dataPath || \'\')';
2214 if (it.errorPath != '""') {
2215 out += ' + ' + (it.errorPath);
2217 var $parentData = $dataLvl ? 'data' + (($dataLvl - 1) || '') : 'parentData',
2218 $parentDataProperty = $dataLvl ? it.dataPathArr[$dataLvl] : 'parentDataProperty';
2219 out += ' , ' + ($parentData) + ' , ' + ($parentDataProperty) + ' , rootData ) ';
2220 var def_callRuleValidate = out;
2221 out = $$outStack.pop();
2222 if ($rDef.errors === false) {
2223 out += ' ' + ($valid) + ' = ';
2224 if ($asyncKeyword) {
2227 out += '' + (def_callRuleValidate) + '; ';
2229 if ($asyncKeyword) {
2230 $ruleErrs = 'customErrors' + $lvl;
2231 out += ' var ' + ($ruleErrs) + ' = null; try { ' + ($valid) + ' = await ' + (def_callRuleValidate) + '; } catch (e) { ' + ($valid) + ' = false; if (e instanceof ValidationError) ' + ($ruleErrs) + ' = e.errors; else throw e; } ';
2233 out += ' ' + ($ruleErrs) + ' = null; ' + ($valid) + ' = ' + (def_callRuleValidate) + '; ';
2237 if ($rDef.modifying) {
2238 out += ' if (' + ($parentData) + ') ' + ($data) + ' = ' + ($parentData) + '[' + ($parentDataProperty) + '];';
2240 out += '' + ($closingBraces);
2242 if ($breakOnError) {
2243 out += ' if (true) { ';
2247 if ($rDef.valid === undefined) {
2250 out += '' + ($nextValid);
2252 out += '' + ($valid);
2255 out += ' ' + (!$rDef.valid) + ' ';
2258 $errorKeyword = $rule.keyword;
2259 var $$outStack = $$outStack || [];
2260 $$outStack.push(out);
2262 var $$outStack = $$outStack || [];
2263 $$outStack.push(out);
2264 out = ''; /* istanbul ignore else */
2265 if (it.createErrors !== false) {
2266 out += ' { keyword: \'' + ($errorKeyword || 'custom') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: ' + (it.util.toQuotedString($errSchemaPath)) + ' , params: { keyword: \'' + ($rule.keyword) + '\' } ';
2267 if (it.opts.messages !== false) {
2268 out += ' , message: \'should pass "' + ($rule.keyword) + '" keyword validation\' ';
2270 if (it.opts.verbose) {
2271 out += ' , schema: validate.schema' + ($schemaPath) + ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' ';
2278 out = $$outStack.pop();
2279 if (!it.compositeRule && $breakOnError) {
2280 /* istanbul ignore if */
2282 out += ' throw new ValidationError([' + (__err) + ']); ';
2284 out += ' validate.errors = [' + (__err) + ']; return false; ';
2287 out += ' var err = ' + (__err) + '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ';
2289 var def_customError = out;
2290 out = $$outStack.pop();
2293 if ($rDef.errors != 'full') {
2294 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) + '"; } ';
2295 if (it.opts.verbose) {
2296 out += ' ' + ($ruleErr) + '.schema = ' + ($schemaValue) + '; ' + ($ruleErr) + '.data = ' + ($data) + '; ';
2301 if ($rDef.errors === false) {
2302 out += ' ' + (def_customError) + ' ';
2304 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) + '"; } ';
2305 if (it.opts.verbose) {
2306 out += ' ' + ($ruleErr) + '.schema = ' + ($schemaValue) + '; ' + ($ruleErr) + '.data = ' + ($data) + '; ';
2311 } else if ($macro) {
2312 out += ' var err = '; /* istanbul ignore else */
2313 if (it.createErrors !== false) {
2314 out += ' { keyword: \'' + ($errorKeyword || 'custom') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: ' + (it.util.toQuotedString($errSchemaPath)) + ' , params: { keyword: \'' + ($rule.keyword) + '\' } ';
2315 if (it.opts.messages !== false) {
2316 out += ' , message: \'should pass "' + ($rule.keyword) + '" keyword validation\' ';
2318 if (it.opts.verbose) {
2319 out += ' , schema: validate.schema' + ($schemaPath) + ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' ';
2325 out += '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ';
2326 if (!it.compositeRule && $breakOnError) {
2327 /* istanbul ignore if */
2329 out += ' throw new ValidationError(vErrors); ';
2331 out += ' validate.errors = vErrors; return false; ';
2335 if ($rDef.errors === false) {
2336 out += ' ' + (def_customError) + ' ';
2338 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) + '"; ';
2339 if (it.opts.verbose) {
2340 out += ' ' + ($ruleErr) + '.schema = ' + ($schemaValue) + '; ' + ($ruleErr) + '.data = ' + ($data) + '; ';
2342 out += ' } } else { ' + (def_customError) + ' } ';
2346 if ($breakOnError) {
2353 },{}],23:[function(require,module,exports){
2355 module.exports = function generate_dependencies(it, $keyword, $ruleType) {
2357 var $lvl = it.level;
2358 var $dataLvl = it.dataLevel;
2359 var $schema = it.schema[$keyword];
2360 var $schemaPath = it.schemaPath + it.util.getProperty($keyword);
2361 var $errSchemaPath = it.errSchemaPath + '/' + $keyword;
2362 var $breakOnError = !it.opts.allErrors;
2363 var $data = 'data' + ($dataLvl || '');
2364 var $errs = 'errs__' + $lvl;
2365 var $it = it.util.copy(it);
2366 var $closingBraces = '';
2368 var $nextValid = 'valid' + $it.level;
2369 var $schemaDeps = {},
2371 $ownProperties = it.opts.ownProperties;
2372 for ($property in $schema) {
2373 if ($property == '__proto__') continue;
2374 var $sch = $schema[$property];
2375 var $deps = Array.isArray($sch) ? $propertyDeps : $schemaDeps;
2376 $deps[$property] = $sch;
2378 out += 'var ' + ($errs) + ' = errors;';
2379 var $currentErrorPath = it.errorPath;
2380 out += 'var missing' + ($lvl) + ';';
2381 for (var $property in $propertyDeps) {
2382 $deps = $propertyDeps[$property];
2384 out += ' if ( ' + ($data) + (it.util.getProperty($property)) + ' !== undefined ';
2385 if ($ownProperties) {
2386 out += ' && Object.prototype.hasOwnProperty.call(' + ($data) + ', \'' + (it.util.escapeQuotes($property)) + '\') ';
2388 if ($breakOnError) {
2392 var $propertyKey, $i = -1,
2393 l1 = arr1.length - 1;
2395 $propertyKey = arr1[$i += 1];
2399 var $prop = it.util.getProperty($propertyKey),
2400 $useData = $data + $prop;
2401 out += ' ( ( ' + ($useData) + ' === undefined ';
2402 if ($ownProperties) {
2403 out += ' || ! Object.prototype.hasOwnProperty.call(' + ($data) + ', \'' + (it.util.escapeQuotes($propertyKey)) + '\') ';
2405 out += ') && (missing' + ($lvl) + ' = ' + (it.util.toQuotedString(it.opts.jsonPointers ? $propertyKey : $prop)) + ') ) ';
2409 var $propertyPath = 'missing' + $lvl,
2410 $missingProperty = '\' + ' + $propertyPath + ' + \'';
2411 if (it.opts._errorDataPathProperty) {
2412 it.errorPath = it.opts.jsonPointers ? it.util.getPathExpr($currentErrorPath, $propertyPath, true) : $currentErrorPath + ' + ' + $propertyPath;
2414 var $$outStack = $$outStack || [];
2415 $$outStack.push(out);
2416 out = ''; /* istanbul ignore else */
2417 if (it.createErrors !== false) {
2418 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(", "))) + '\' } ';
2419 if (it.opts.messages !== false) {
2420 out += ' , message: \'should have ';
2421 if ($deps.length == 1) {
2422 out += 'property ' + (it.util.escapeQuotes($deps[0]));
2424 out += 'properties ' + (it.util.escapeQuotes($deps.join(", ")));
2426 out += ' when property ' + (it.util.escapeQuotes($property)) + ' is present\' ';
2428 if (it.opts.verbose) {
2429 out += ' , schema: validate.schema' + ($schemaPath) + ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' ';
2436 out = $$outStack.pop();
2437 if (!it.compositeRule && $breakOnError) {
2438 /* istanbul ignore if */
2440 out += ' throw new ValidationError([' + (__err) + ']); ';
2442 out += ' validate.errors = [' + (__err) + ']; return false; ';
2445 out += ' var err = ' + (__err) + '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ';
2451 var $propertyKey, i2 = -1,
2452 l2 = arr2.length - 1;
2454 $propertyKey = arr2[i2 += 1];
2455 var $prop = it.util.getProperty($propertyKey),
2456 $missingProperty = it.util.escapeQuotes($propertyKey),
2457 $useData = $data + $prop;
2458 if (it.opts._errorDataPathProperty) {
2459 it.errorPath = it.util.getPath($currentErrorPath, $propertyKey, it.opts.jsonPointers);
2461 out += ' if ( ' + ($useData) + ' === undefined ';
2462 if ($ownProperties) {
2463 out += ' || ! Object.prototype.hasOwnProperty.call(' + ($data) + ', \'' + (it.util.escapeQuotes($propertyKey)) + '\') ';
2465 out += ') { var err = '; /* istanbul ignore else */
2466 if (it.createErrors !== false) {
2467 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(", "))) + '\' } ';
2468 if (it.opts.messages !== false) {
2469 out += ' , message: \'should have ';
2470 if ($deps.length == 1) {
2471 out += 'property ' + (it.util.escapeQuotes($deps[0]));
2473 out += 'properties ' + (it.util.escapeQuotes($deps.join(", ")));
2475 out += ' when property ' + (it.util.escapeQuotes($property)) + ' is present\' ';
2477 if (it.opts.verbose) {
2478 out += ' , schema: validate.schema' + ($schemaPath) + ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' ';
2484 out += '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; } ';
2489 if ($breakOnError) {
2490 $closingBraces += '}';
2495 it.errorPath = $currentErrorPath;
2496 var $currentBaseId = $it.baseId;
2497 for (var $property in $schemaDeps) {
2498 var $sch = $schemaDeps[$property];
2499 if ((it.opts.strictKeywords ? (typeof $sch == 'object' && Object.keys($sch).length > 0) || $sch === false : it.util.schemaHasRules($sch, it.RULES.all))) {
2500 out += ' ' + ($nextValid) + ' = true; if ( ' + ($data) + (it.util.getProperty($property)) + ' !== undefined ';
2501 if ($ownProperties) {
2502 out += ' && Object.prototype.hasOwnProperty.call(' + ($data) + ', \'' + (it.util.escapeQuotes($property)) + '\') ';
2506 $it.schemaPath = $schemaPath + it.util.getProperty($property);
2507 $it.errSchemaPath = $errSchemaPath + '/' + it.util.escapeFragment($property);
2508 out += ' ' + (it.validate($it)) + ' ';
2509 $it.baseId = $currentBaseId;
2511 if ($breakOnError) {
2512 out += ' if (' + ($nextValid) + ') { ';
2513 $closingBraces += '}';
2517 if ($breakOnError) {
2518 out += ' ' + ($closingBraces) + ' if (' + ($errs) + ' == errors) {';
2523 },{}],24:[function(require,module,exports){
2525 module.exports = function generate_enum(it, $keyword, $ruleType) {
2527 var $lvl = it.level;
2528 var $dataLvl = it.dataLevel;
2529 var $schema = it.schema[$keyword];
2530 var $schemaPath = it.schemaPath + it.util.getProperty($keyword);
2531 var $errSchemaPath = it.errSchemaPath + '/' + $keyword;
2532 var $breakOnError = !it.opts.allErrors;
2533 var $data = 'data' + ($dataLvl || '');
2534 var $valid = 'valid' + $lvl;
2535 var $isData = it.opts.$data && $schema && $schema.$data,
2538 out += ' var schema' + ($lvl) + ' = ' + (it.util.getData($schema.$data, $dataLvl, it.dataPathArr)) + '; ';
2539 $schemaValue = 'schema' + $lvl;
2541 $schemaValue = $schema;
2543 var $i = 'i' + $lvl,
2544 $vSchema = 'schema' + $lvl;
2546 out += ' var ' + ($vSchema) + ' = validate.schema' + ($schemaPath) + ';';
2548 out += 'var ' + ($valid) + ';';
2550 out += ' if (schema' + ($lvl) + ' === undefined) ' + ($valid) + ' = true; else if (!Array.isArray(schema' + ($lvl) + ')) ' + ($valid) + ' = false; else {';
2552 out += '' + ($valid) + ' = false;for (var ' + ($i) + '=0; ' + ($i) + '<' + ($vSchema) + '.length; ' + ($i) + '++) if (equal(' + ($data) + ', ' + ($vSchema) + '[' + ($i) + '])) { ' + ($valid) + ' = true; break; }';
2556 out += ' if (!' + ($valid) + ') { ';
2557 var $$outStack = $$outStack || [];
2558 $$outStack.push(out);
2559 out = ''; /* istanbul ignore else */
2560 if (it.createErrors !== false) {
2561 out += ' { keyword: \'' + ('enum') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: ' + (it.util.toQuotedString($errSchemaPath)) + ' , params: { allowedValues: schema' + ($lvl) + ' } ';
2562 if (it.opts.messages !== false) {
2563 out += ' , message: \'should be equal to one of the allowed values\' ';
2565 if (it.opts.verbose) {
2566 out += ' , schema: validate.schema' + ($schemaPath) + ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' ';
2573 out = $$outStack.pop();
2574 if (!it.compositeRule && $breakOnError) {
2575 /* istanbul ignore if */
2577 out += ' throw new ValidationError([' + (__err) + ']); ';
2579 out += ' validate.errors = [' + (__err) + ']; return false; ';
2582 out += ' var err = ' + (__err) + '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ';
2585 if ($breakOnError) {
2591 },{}],25:[function(require,module,exports){
2593 module.exports = function generate_format(it, $keyword, $ruleType) {
2595 var $lvl = it.level;
2596 var $dataLvl = it.dataLevel;
2597 var $schema = it.schema[$keyword];
2598 var $schemaPath = it.schemaPath + it.util.getProperty($keyword);
2599 var $errSchemaPath = it.errSchemaPath + '/' + $keyword;
2600 var $breakOnError = !it.opts.allErrors;
2601 var $data = 'data' + ($dataLvl || '');
2602 if (it.opts.format === false) {
2603 if ($breakOnError) {
2604 out += ' if (true) { ';
2608 var $isData = it.opts.$data && $schema && $schema.$data,
2611 out += ' var schema' + ($lvl) + ' = ' + (it.util.getData($schema.$data, $dataLvl, it.dataPathArr)) + '; ';
2612 $schemaValue = 'schema' + $lvl;
2614 $schemaValue = $schema;
2616 var $unknownFormats = it.opts.unknownFormats,
2617 $allowUnknown = Array.isArray($unknownFormats);
2619 var $format = 'format' + $lvl,
2620 $isObject = 'isObject' + $lvl,
2621 $formatType = 'formatType' + $lvl;
2622 out += ' var ' + ($format) + ' = formats[' + ($schemaValue) + ']; var ' + ($isObject) + ' = typeof ' + ($format) + ' == \'object\' && !(' + ($format) + ' instanceof RegExp) && ' + ($format) + '.validate; var ' + ($formatType) + ' = ' + ($isObject) + ' && ' + ($format) + '.type || \'string\'; if (' + ($isObject) + ') { ';
2624 out += ' var async' + ($lvl) + ' = ' + ($format) + '.async; ';
2626 out += ' ' + ($format) + ' = ' + ($format) + '.validate; } if ( ';
2628 out += ' (' + ($schemaValue) + ' !== undefined && typeof ' + ($schemaValue) + ' != \'string\') || ';
2631 if ($unknownFormats != 'ignore') {
2632 out += ' (' + ($schemaValue) + ' && !' + ($format) + ' ';
2633 if ($allowUnknown) {
2634 out += ' && self._opts.unknownFormats.indexOf(' + ($schemaValue) + ') == -1 ';
2638 out += ' (' + ($format) + ' && ' + ($formatType) + ' == \'' + ($ruleType) + '\' && !(typeof ' + ($format) + ' == \'function\' ? ';
2640 out += ' (async' + ($lvl) + ' ? await ' + ($format) + '(' + ($data) + ') : ' + ($format) + '(' + ($data) + ')) ';
2642 out += ' ' + ($format) + '(' + ($data) + ') ';
2644 out += ' : ' + ($format) + '.test(' + ($data) + '))))) {';
2646 var $format = it.formats[$schema];
2648 if ($unknownFormats == 'ignore') {
2649 it.logger.warn('unknown format "' + $schema + '" ignored in schema at path "' + it.errSchemaPath + '"');
2650 if ($breakOnError) {
2651 out += ' if (true) { ';
2654 } else if ($allowUnknown && $unknownFormats.indexOf($schema) >= 0) {
2655 if ($breakOnError) {
2656 out += ' if (true) { ';
2660 throw new Error('unknown format "' + $schema + '" is used in schema at path "' + it.errSchemaPath + '"');
2663 var $isObject = typeof $format == 'object' && !($format instanceof RegExp) && $format.validate;
2664 var $formatType = $isObject && $format.type || 'string';
2666 var $async = $format.async === true;
2667 $format = $format.validate;
2669 if ($formatType != $ruleType) {
2670 if ($breakOnError) {
2671 out += ' if (true) { ';
2676 if (!it.async) throw new Error('async format in sync schema');
2677 var $formatRef = 'formats' + it.util.getProperty($schema) + '.validate';
2678 out += ' if (!(await ' + ($formatRef) + '(' + ($data) + '))) { ';
2681 var $formatRef = 'formats' + it.util.getProperty($schema);
2682 if ($isObject) $formatRef += '.validate';
2683 if (typeof $format == 'function') {
2684 out += ' ' + ($formatRef) + '(' + ($data) + ') ';
2686 out += ' ' + ($formatRef) + '.test(' + ($data) + ') ';
2691 var $$outStack = $$outStack || [];
2692 $$outStack.push(out);
2693 out = ''; /* istanbul ignore else */
2694 if (it.createErrors !== false) {
2695 out += ' { keyword: \'' + ('format') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: ' + (it.util.toQuotedString($errSchemaPath)) + ' , params: { format: ';
2697 out += '' + ($schemaValue);
2699 out += '' + (it.util.toQuotedString($schema));
2702 if (it.opts.messages !== false) {
2703 out += ' , message: \'should match format "';
2705 out += '\' + ' + ($schemaValue) + ' + \'';
2707 out += '' + (it.util.escapeQuotes($schema));
2711 if (it.opts.verbose) {
2712 out += ' , schema: ';
2714 out += 'validate.schema' + ($schemaPath);
2716 out += '' + (it.util.toQuotedString($schema));
2718 out += ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' ';
2725 out = $$outStack.pop();
2726 if (!it.compositeRule && $breakOnError) {
2727 /* istanbul ignore if */
2729 out += ' throw new ValidationError([' + (__err) + ']); ';
2731 out += ' validate.errors = [' + (__err) + ']; return false; ';
2734 out += ' var err = ' + (__err) + '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ';
2737 if ($breakOnError) {
2743 },{}],26:[function(require,module,exports){
2745 module.exports = function generate_if(it, $keyword, $ruleType) {
2747 var $lvl = it.level;
2748 var $dataLvl = it.dataLevel;
2749 var $schema = it.schema[$keyword];
2750 var $schemaPath = it.schemaPath + it.util.getProperty($keyword);
2751 var $errSchemaPath = it.errSchemaPath + '/' + $keyword;
2752 var $breakOnError = !it.opts.allErrors;
2753 var $data = 'data' + ($dataLvl || '');
2754 var $valid = 'valid' + $lvl;
2755 var $errs = 'errs__' + $lvl;
2756 var $it = it.util.copy(it);
2758 var $nextValid = 'valid' + $it.level;
2759 var $thenSch = it.schema['then'],
2760 $elseSch = it.schema['else'],
2761 $thenPresent = $thenSch !== undefined && (it.opts.strictKeywords ? (typeof $thenSch == 'object' && Object.keys($thenSch).length > 0) || $thenSch === false : it.util.schemaHasRules($thenSch, it.RULES.all)),
2762 $elsePresent = $elseSch !== undefined && (it.opts.strictKeywords ? (typeof $elseSch == 'object' && Object.keys($elseSch).length > 0) || $elseSch === false : it.util.schemaHasRules($elseSch, it.RULES.all)),
2763 $currentBaseId = $it.baseId;
2764 if ($thenPresent || $elsePresent) {
2766 $it.createErrors = false;
2767 $it.schema = $schema;
2768 $it.schemaPath = $schemaPath;
2769 $it.errSchemaPath = $errSchemaPath;
2770 out += ' var ' + ($errs) + ' = errors; var ' + ($valid) + ' = true; ';
2771 var $wasComposite = it.compositeRule;
2772 it.compositeRule = $it.compositeRule = true;
2773 out += ' ' + (it.validate($it)) + ' ';
2774 $it.baseId = $currentBaseId;
2775 $it.createErrors = true;
2776 out += ' errors = ' + ($errs) + '; if (vErrors !== null) { if (' + ($errs) + ') vErrors.length = ' + ($errs) + '; else vErrors = null; } ';
2777 it.compositeRule = $it.compositeRule = $wasComposite;
2779 out += ' if (' + ($nextValid) + ') { ';
2780 $it.schema = it.schema['then'];
2781 $it.schemaPath = it.schemaPath + '.then';
2782 $it.errSchemaPath = it.errSchemaPath + '/then';
2783 out += ' ' + (it.validate($it)) + ' ';
2784 $it.baseId = $currentBaseId;
2785 out += ' ' + ($valid) + ' = ' + ($nextValid) + '; ';
2786 if ($thenPresent && $elsePresent) {
2787 $ifClause = 'ifClause' + $lvl;
2788 out += ' var ' + ($ifClause) + ' = \'then\'; ';
2790 $ifClause = '\'then\'';
2797 out += ' if (!' + ($nextValid) + ') { ';
2800 $it.schema = it.schema['else'];
2801 $it.schemaPath = it.schemaPath + '.else';
2802 $it.errSchemaPath = it.errSchemaPath + '/else';
2803 out += ' ' + (it.validate($it)) + ' ';
2804 $it.baseId = $currentBaseId;
2805 out += ' ' + ($valid) + ' = ' + ($nextValid) + '; ';
2806 if ($thenPresent && $elsePresent) {
2807 $ifClause = 'ifClause' + $lvl;
2808 out += ' var ' + ($ifClause) + ' = \'else\'; ';
2810 $ifClause = '\'else\'';
2814 out += ' if (!' + ($valid) + ') { var err = '; /* istanbul ignore else */
2815 if (it.createErrors !== false) {
2816 out += ' { keyword: \'' + ('if') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: ' + (it.util.toQuotedString($errSchemaPath)) + ' , params: { failingKeyword: ' + ($ifClause) + ' } ';
2817 if (it.opts.messages !== false) {
2818 out += ' , message: \'should match "\' + ' + ($ifClause) + ' + \'" schema\' ';
2820 if (it.opts.verbose) {
2821 out += ' , schema: validate.schema' + ($schemaPath) + ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' ';
2827 out += '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ';
2828 if (!it.compositeRule && $breakOnError) {
2829 /* istanbul ignore if */
2831 out += ' throw new ValidationError(vErrors); ';
2833 out += ' validate.errors = vErrors; return false; ';
2837 if ($breakOnError) {
2841 if ($breakOnError) {
2842 out += ' if (true) { ';
2848 },{}],27:[function(require,module,exports){
2851 //all requires must be explicit because browserify won't work with dynamic requires
2853 '$ref': require('./ref'),
2854 allOf: require('./allOf'),
2855 anyOf: require('./anyOf'),
2856 '$comment': require('./comment'),
2857 const: require('./const'),
2858 contains: require('./contains'),
2859 dependencies: require('./dependencies'),
2860 'enum': require('./enum'),
2861 format: require('./format'),
2862 'if': require('./if'),
2863 items: require('./items'),
2864 maximum: require('./_limit'),
2865 minimum: require('./_limit'),
2866 maxItems: require('./_limitItems'),
2867 minItems: require('./_limitItems'),
2868 maxLength: require('./_limitLength'),
2869 minLength: require('./_limitLength'),
2870 maxProperties: require('./_limitProperties'),
2871 minProperties: require('./_limitProperties'),
2872 multipleOf: require('./multipleOf'),
2873 not: require('./not'),
2874 oneOf: require('./oneOf'),
2875 pattern: require('./pattern'),
2876 properties: require('./properties'),
2877 propertyNames: require('./propertyNames'),
2878 required: require('./required'),
2879 uniqueItems: require('./uniqueItems'),
2880 validate: require('./validate')
2883 },{"./_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){
2885 module.exports = function generate_items(it, $keyword, $ruleType) {
2887 var $lvl = it.level;
2888 var $dataLvl = it.dataLevel;
2889 var $schema = it.schema[$keyword];
2890 var $schemaPath = it.schemaPath + it.util.getProperty($keyword);
2891 var $errSchemaPath = it.errSchemaPath + '/' + $keyword;
2892 var $breakOnError = !it.opts.allErrors;
2893 var $data = 'data' + ($dataLvl || '');
2894 var $valid = 'valid' + $lvl;
2895 var $errs = 'errs__' + $lvl;
2896 var $it = it.util.copy(it);
2897 var $closingBraces = '';
2899 var $nextValid = 'valid' + $it.level;
2900 var $idx = 'i' + $lvl,
2901 $dataNxt = $it.dataLevel = it.dataLevel + 1,
2902 $nextData = 'data' + $dataNxt,
2903 $currentBaseId = it.baseId;
2904 out += 'var ' + ($errs) + ' = errors;var ' + ($valid) + ';';
2905 if (Array.isArray($schema)) {
2906 var $additionalItems = it.schema.additionalItems;
2907 if ($additionalItems === false) {
2908 out += ' ' + ($valid) + ' = ' + ($data) + '.length <= ' + ($schema.length) + '; ';
2909 var $currErrSchemaPath = $errSchemaPath;
2910 $errSchemaPath = it.errSchemaPath + '/additionalItems';
2911 out += ' if (!' + ($valid) + ') { ';
2912 var $$outStack = $$outStack || [];
2913 $$outStack.push(out);
2914 out = ''; /* istanbul ignore else */
2915 if (it.createErrors !== false) {
2916 out += ' { keyword: \'' + ('additionalItems') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: ' + (it.util.toQuotedString($errSchemaPath)) + ' , params: { limit: ' + ($schema.length) + ' } ';
2917 if (it.opts.messages !== false) {
2918 out += ' , message: \'should NOT have more than ' + ($schema.length) + ' items\' ';
2920 if (it.opts.verbose) {
2921 out += ' , schema: false , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' ';
2928 out = $$outStack.pop();
2929 if (!it.compositeRule && $breakOnError) {
2930 /* istanbul ignore if */
2932 out += ' throw new ValidationError([' + (__err) + ']); ';
2934 out += ' validate.errors = [' + (__err) + ']; return false; ';
2937 out += ' var err = ' + (__err) + '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ';
2940 $errSchemaPath = $currErrSchemaPath;
2941 if ($breakOnError) {
2942 $closingBraces += '}';
2949 l1 = arr1.length - 1;
2951 $sch = arr1[$i += 1];
2952 if ((it.opts.strictKeywords ? (typeof $sch == 'object' && Object.keys($sch).length > 0) || $sch === false : it.util.schemaHasRules($sch, it.RULES.all))) {
2953 out += ' ' + ($nextValid) + ' = true; if (' + ($data) + '.length > ' + ($i) + ') { ';
2954 var $passData = $data + '[' + $i + ']';
2956 $it.schemaPath = $schemaPath + '[' + $i + ']';
2957 $it.errSchemaPath = $errSchemaPath + '/' + $i;
2958 $it.errorPath = it.util.getPathExpr(it.errorPath, $i, it.opts.jsonPointers, true);
2959 $it.dataPathArr[$dataNxt] = $i;
2960 var $code = it.validate($it);
2961 $it.baseId = $currentBaseId;
2962 if (it.util.varOccurences($code, $nextData) < 2) {
2963 out += ' ' + (it.util.varReplace($code, $nextData, $passData)) + ' ';
2965 out += ' var ' + ($nextData) + ' = ' + ($passData) + '; ' + ($code) + ' ';
2968 if ($breakOnError) {
2969 out += ' if (' + ($nextValid) + ') { ';
2970 $closingBraces += '}';
2975 if (typeof $additionalItems == 'object' && (it.opts.strictKeywords ? (typeof $additionalItems == 'object' && Object.keys($additionalItems).length > 0) || $additionalItems === false : it.util.schemaHasRules($additionalItems, it.RULES.all))) {
2976 $it.schema = $additionalItems;
2977 $it.schemaPath = it.schemaPath + '.additionalItems';
2978 $it.errSchemaPath = it.errSchemaPath + '/additionalItems';
2979 out += ' ' + ($nextValid) + ' = true; if (' + ($data) + '.length > ' + ($schema.length) + ') { for (var ' + ($idx) + ' = ' + ($schema.length) + '; ' + ($idx) + ' < ' + ($data) + '.length; ' + ($idx) + '++) { ';
2980 $it.errorPath = it.util.getPathExpr(it.errorPath, $idx, it.opts.jsonPointers, true);
2981 var $passData = $data + '[' + $idx + ']';
2982 $it.dataPathArr[$dataNxt] = $idx;
2983 var $code = it.validate($it);
2984 $it.baseId = $currentBaseId;
2985 if (it.util.varOccurences($code, $nextData) < 2) {
2986 out += ' ' + (it.util.varReplace($code, $nextData, $passData)) + ' ';
2988 out += ' var ' + ($nextData) + ' = ' + ($passData) + '; ' + ($code) + ' ';
2990 if ($breakOnError) {
2991 out += ' if (!' + ($nextValid) + ') break; ';
2994 if ($breakOnError) {
2995 out += ' if (' + ($nextValid) + ') { ';
2996 $closingBraces += '}';
2999 } else if ((it.opts.strictKeywords ? (typeof $schema == 'object' && Object.keys($schema).length > 0) || $schema === false : it.util.schemaHasRules($schema, it.RULES.all))) {
3000 $it.schema = $schema;
3001 $it.schemaPath = $schemaPath;
3002 $it.errSchemaPath = $errSchemaPath;
3003 out += ' for (var ' + ($idx) + ' = ' + (0) + '; ' + ($idx) + ' < ' + ($data) + '.length; ' + ($idx) + '++) { ';
3004 $it.errorPath = it.util.getPathExpr(it.errorPath, $idx, it.opts.jsonPointers, true);
3005 var $passData = $data + '[' + $idx + ']';
3006 $it.dataPathArr[$dataNxt] = $idx;
3007 var $code = it.validate($it);
3008 $it.baseId = $currentBaseId;
3009 if (it.util.varOccurences($code, $nextData) < 2) {
3010 out += ' ' + (it.util.varReplace($code, $nextData, $passData)) + ' ';
3012 out += ' var ' + ($nextData) + ' = ' + ($passData) + '; ' + ($code) + ' ';
3014 if ($breakOnError) {
3015 out += ' if (!' + ($nextValid) + ') break; ';
3019 if ($breakOnError) {
3020 out += ' ' + ($closingBraces) + ' if (' + ($errs) + ' == errors) {';
3025 },{}],29:[function(require,module,exports){
3027 module.exports = function generate_multipleOf(it, $keyword, $ruleType) {
3029 var $lvl = it.level;
3030 var $dataLvl = it.dataLevel;
3031 var $schema = it.schema[$keyword];
3032 var $schemaPath = it.schemaPath + it.util.getProperty($keyword);
3033 var $errSchemaPath = it.errSchemaPath + '/' + $keyword;
3034 var $breakOnError = !it.opts.allErrors;
3035 var $data = 'data' + ($dataLvl || '');
3036 var $isData = it.opts.$data && $schema && $schema.$data,
3039 out += ' var schema' + ($lvl) + ' = ' + (it.util.getData($schema.$data, $dataLvl, it.dataPathArr)) + '; ';
3040 $schemaValue = 'schema' + $lvl;
3042 $schemaValue = $schema;
3044 if (!($isData || typeof $schema == 'number')) {
3045 throw new Error($keyword + ' must be number');
3047 out += 'var division' + ($lvl) + ';if (';
3049 out += ' ' + ($schemaValue) + ' !== undefined && ( typeof ' + ($schemaValue) + ' != \'number\' || ';
3051 out += ' (division' + ($lvl) + ' = ' + ($data) + ' / ' + ($schemaValue) + ', ';
3052 if (it.opts.multipleOfPrecision) {
3053 out += ' Math.abs(Math.round(division' + ($lvl) + ') - division' + ($lvl) + ') > 1e-' + (it.opts.multipleOfPrecision) + ' ';
3055 out += ' division' + ($lvl) + ' !== parseInt(division' + ($lvl) + ') ';
3062 var $$outStack = $$outStack || [];
3063 $$outStack.push(out);
3064 out = ''; /* istanbul ignore else */
3065 if (it.createErrors !== false) {
3066 out += ' { keyword: \'' + ('multipleOf') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: ' + (it.util.toQuotedString($errSchemaPath)) + ' , params: { multipleOf: ' + ($schemaValue) + ' } ';
3067 if (it.opts.messages !== false) {
3068 out += ' , message: \'should be multiple of ';
3070 out += '\' + ' + ($schemaValue);
3072 out += '' + ($schemaValue) + '\'';
3075 if (it.opts.verbose) {
3076 out += ' , schema: ';
3078 out += 'validate.schema' + ($schemaPath);
3080 out += '' + ($schema);
3082 out += ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' ';
3089 out = $$outStack.pop();
3090 if (!it.compositeRule && $breakOnError) {
3091 /* istanbul ignore if */
3093 out += ' throw new ValidationError([' + (__err) + ']); ';
3095 out += ' validate.errors = [' + (__err) + ']; return false; ';
3098 out += ' var err = ' + (__err) + '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ';
3101 if ($breakOnError) {
3107 },{}],30:[function(require,module,exports){
3109 module.exports = function generate_not(it, $keyword, $ruleType) {
3111 var $lvl = it.level;
3112 var $dataLvl = it.dataLevel;
3113 var $schema = it.schema[$keyword];
3114 var $schemaPath = it.schemaPath + it.util.getProperty($keyword);
3115 var $errSchemaPath = it.errSchemaPath + '/' + $keyword;
3116 var $breakOnError = !it.opts.allErrors;
3117 var $data = 'data' + ($dataLvl || '');
3118 var $errs = 'errs__' + $lvl;
3119 var $it = it.util.copy(it);
3121 var $nextValid = 'valid' + $it.level;
3122 if ((it.opts.strictKeywords ? (typeof $schema == 'object' && Object.keys($schema).length > 0) || $schema === false : it.util.schemaHasRules($schema, it.RULES.all))) {
3123 $it.schema = $schema;
3124 $it.schemaPath = $schemaPath;
3125 $it.errSchemaPath = $errSchemaPath;
3126 out += ' var ' + ($errs) + ' = errors; ';
3127 var $wasComposite = it.compositeRule;
3128 it.compositeRule = $it.compositeRule = true;
3129 $it.createErrors = false;
3130 var $allErrorsOption;
3131 if ($it.opts.allErrors) {
3132 $allErrorsOption = $it.opts.allErrors;
3133 $it.opts.allErrors = false;
3135 out += ' ' + (it.validate($it)) + ' ';
3136 $it.createErrors = true;
3137 if ($allErrorsOption) $it.opts.allErrors = $allErrorsOption;
3138 it.compositeRule = $it.compositeRule = $wasComposite;
3139 out += ' if (' + ($nextValid) + ') { ';
3140 var $$outStack = $$outStack || [];
3141 $$outStack.push(out);
3142 out = ''; /* istanbul ignore else */
3143 if (it.createErrors !== false) {
3144 out += ' { keyword: \'' + ('not') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: ' + (it.util.toQuotedString($errSchemaPath)) + ' , params: {} ';
3145 if (it.opts.messages !== false) {
3146 out += ' , message: \'should NOT be valid\' ';
3148 if (it.opts.verbose) {
3149 out += ' , schema: validate.schema' + ($schemaPath) + ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' ';
3156 out = $$outStack.pop();
3157 if (!it.compositeRule && $breakOnError) {
3158 /* istanbul ignore if */
3160 out += ' throw new ValidationError([' + (__err) + ']); ';
3162 out += ' validate.errors = [' + (__err) + ']; return false; ';
3165 out += ' var err = ' + (__err) + '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ';
3167 out += ' } else { errors = ' + ($errs) + '; if (vErrors !== null) { if (' + ($errs) + ') vErrors.length = ' + ($errs) + '; else vErrors = null; } ';
3168 if (it.opts.allErrors) {
3172 out += ' var err = '; /* istanbul ignore else */
3173 if (it.createErrors !== false) {
3174 out += ' { keyword: \'' + ('not') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: ' + (it.util.toQuotedString($errSchemaPath)) + ' , params: {} ';
3175 if (it.opts.messages !== false) {
3176 out += ' , message: \'should NOT be valid\' ';
3178 if (it.opts.verbose) {
3179 out += ' , schema: validate.schema' + ($schemaPath) + ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' ';
3185 out += '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ';
3186 if ($breakOnError) {
3187 out += ' if (false) { ';
3193 },{}],31:[function(require,module,exports){
3195 module.exports = function generate_oneOf(it, $keyword, $ruleType) {
3197 var $lvl = it.level;
3198 var $dataLvl = it.dataLevel;
3199 var $schema = it.schema[$keyword];
3200 var $schemaPath = it.schemaPath + it.util.getProperty($keyword);
3201 var $errSchemaPath = it.errSchemaPath + '/' + $keyword;
3202 var $breakOnError = !it.opts.allErrors;
3203 var $data = 'data' + ($dataLvl || '');
3204 var $valid = 'valid' + $lvl;
3205 var $errs = 'errs__' + $lvl;
3206 var $it = it.util.copy(it);
3207 var $closingBraces = '';
3209 var $nextValid = 'valid' + $it.level;
3210 var $currentBaseId = $it.baseId,
3211 $prevValid = 'prevValid' + $lvl,
3212 $passingSchemas = 'passingSchemas' + $lvl;
3213 out += 'var ' + ($errs) + ' = errors , ' + ($prevValid) + ' = false , ' + ($valid) + ' = false , ' + ($passingSchemas) + ' = null; ';
3214 var $wasComposite = it.compositeRule;
3215 it.compositeRule = $it.compositeRule = true;
3219 l1 = arr1.length - 1;
3221 $sch = arr1[$i += 1];
3222 if ((it.opts.strictKeywords ? (typeof $sch == 'object' && Object.keys($sch).length > 0) || $sch === false : it.util.schemaHasRules($sch, it.RULES.all))) {
3224 $it.schemaPath = $schemaPath + '[' + $i + ']';
3225 $it.errSchemaPath = $errSchemaPath + '/' + $i;
3226 out += ' ' + (it.validate($it)) + ' ';
3227 $it.baseId = $currentBaseId;
3229 out += ' var ' + ($nextValid) + ' = true; ';
3232 out += ' if (' + ($nextValid) + ' && ' + ($prevValid) + ') { ' + ($valid) + ' = false; ' + ($passingSchemas) + ' = [' + ($passingSchemas) + ', ' + ($i) + ']; } else { ';
3233 $closingBraces += '}';
3235 out += ' if (' + ($nextValid) + ') { ' + ($valid) + ' = ' + ($prevValid) + ' = true; ' + ($passingSchemas) + ' = ' + ($i) + '; }';
3238 it.compositeRule = $it.compositeRule = $wasComposite;
3239 out += '' + ($closingBraces) + 'if (!' + ($valid) + ') { var err = '; /* istanbul ignore else */
3240 if (it.createErrors !== false) {
3241 out += ' { keyword: \'' + ('oneOf') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: ' + (it.util.toQuotedString($errSchemaPath)) + ' , params: { passingSchemas: ' + ($passingSchemas) + ' } ';
3242 if (it.opts.messages !== false) {
3243 out += ' , message: \'should match exactly one schema in oneOf\' ';
3245 if (it.opts.verbose) {
3246 out += ' , schema: validate.schema' + ($schemaPath) + ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' ';
3252 out += '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ';
3253 if (!it.compositeRule && $breakOnError) {
3254 /* istanbul ignore if */
3256 out += ' throw new ValidationError(vErrors); ';
3258 out += ' validate.errors = vErrors; return false; ';
3261 out += '} else { errors = ' + ($errs) + '; if (vErrors !== null) { if (' + ($errs) + ') vErrors.length = ' + ($errs) + '; else vErrors = null; }';
3262 if (it.opts.allErrors) {
3268 },{}],32:[function(require,module,exports){
3270 module.exports = function generate_pattern(it, $keyword, $ruleType) {
3272 var $lvl = it.level;
3273 var $dataLvl = it.dataLevel;
3274 var $schema = it.schema[$keyword];
3275 var $schemaPath = it.schemaPath + it.util.getProperty($keyword);
3276 var $errSchemaPath = it.errSchemaPath + '/' + $keyword;
3277 var $breakOnError = !it.opts.allErrors;
3278 var $data = 'data' + ($dataLvl || '');
3279 var $isData = it.opts.$data && $schema && $schema.$data,
3282 out += ' var schema' + ($lvl) + ' = ' + (it.util.getData($schema.$data, $dataLvl, it.dataPathArr)) + '; ';
3283 $schemaValue = 'schema' + $lvl;
3285 $schemaValue = $schema;
3287 var $regexp = $isData ? '(new RegExp(' + $schemaValue + '))' : it.usePattern($schema);
3290 out += ' (' + ($schemaValue) + ' !== undefined && typeof ' + ($schemaValue) + ' != \'string\') || ';
3292 out += ' !' + ($regexp) + '.test(' + ($data) + ') ) { ';
3293 var $$outStack = $$outStack || [];
3294 $$outStack.push(out);
3295 out = ''; /* istanbul ignore else */
3296 if (it.createErrors !== false) {
3297 out += ' { keyword: \'' + ('pattern') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: ' + (it.util.toQuotedString($errSchemaPath)) + ' , params: { pattern: ';
3299 out += '' + ($schemaValue);
3301 out += '' + (it.util.toQuotedString($schema));
3304 if (it.opts.messages !== false) {
3305 out += ' , message: \'should match pattern "';
3307 out += '\' + ' + ($schemaValue) + ' + \'';
3309 out += '' + (it.util.escapeQuotes($schema));
3313 if (it.opts.verbose) {
3314 out += ' , schema: ';
3316 out += 'validate.schema' + ($schemaPath);
3318 out += '' + (it.util.toQuotedString($schema));
3320 out += ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' ';
3327 out = $$outStack.pop();
3328 if (!it.compositeRule && $breakOnError) {
3329 /* istanbul ignore if */
3331 out += ' throw new ValidationError([' + (__err) + ']); ';
3333 out += ' validate.errors = [' + (__err) + ']; return false; ';
3336 out += ' var err = ' + (__err) + '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ';
3339 if ($breakOnError) {
3345 },{}],33:[function(require,module,exports){
3347 module.exports = function generate_properties(it, $keyword, $ruleType) {
3349 var $lvl = it.level;
3350 var $dataLvl = it.dataLevel;
3351 var $schema = it.schema[$keyword];
3352 var $schemaPath = it.schemaPath + it.util.getProperty($keyword);
3353 var $errSchemaPath = it.errSchemaPath + '/' + $keyword;
3354 var $breakOnError = !it.opts.allErrors;
3355 var $data = 'data' + ($dataLvl || '');
3356 var $errs = 'errs__' + $lvl;
3357 var $it = it.util.copy(it);
3358 var $closingBraces = '';
3360 var $nextValid = 'valid' + $it.level;
3361 var $key = 'key' + $lvl,
3362 $idx = 'idx' + $lvl,
3363 $dataNxt = $it.dataLevel = it.dataLevel + 1,
3364 $nextData = 'data' + $dataNxt,
3365 $dataProperties = 'dataProperties' + $lvl;
3366 var $schemaKeys = Object.keys($schema || {}).filter(notProto),
3367 $pProperties = it.schema.patternProperties || {},
3368 $pPropertyKeys = Object.keys($pProperties).filter(notProto),
3369 $aProperties = it.schema.additionalProperties,
3370 $someProperties = $schemaKeys.length || $pPropertyKeys.length,
3371 $noAdditional = $aProperties === false,
3372 $additionalIsSchema = typeof $aProperties == 'object' && Object.keys($aProperties).length,
3373 $removeAdditional = it.opts.removeAdditional,
3374 $checkAdditional = $noAdditional || $additionalIsSchema || $removeAdditional,
3375 $ownProperties = it.opts.ownProperties,
3376 $currentBaseId = it.baseId;
3377 var $required = it.schema.required;
3378 if ($required && !(it.opts.$data && $required.$data) && $required.length < it.opts.loopRequired) {
3379 var $requiredHash = it.util.toHash($required);
3382 function notProto(p) {
3383 return p !== '__proto__';
3385 out += 'var ' + ($errs) + ' = errors;var ' + ($nextValid) + ' = true;';
3386 if ($ownProperties) {
3387 out += ' var ' + ($dataProperties) + ' = undefined;';
3389 if ($checkAdditional) {
3390 if ($ownProperties) {
3391 out += ' ' + ($dataProperties) + ' = ' + ($dataProperties) + ' || Object.keys(' + ($data) + '); for (var ' + ($idx) + '=0; ' + ($idx) + '<' + ($dataProperties) + '.length; ' + ($idx) + '++) { var ' + ($key) + ' = ' + ($dataProperties) + '[' + ($idx) + ']; ';
3393 out += ' for (var ' + ($key) + ' in ' + ($data) + ') { ';
3395 if ($someProperties) {
3396 out += ' var isAdditional' + ($lvl) + ' = !(false ';
3397 if ($schemaKeys.length) {
3398 if ($schemaKeys.length > 8) {
3399 out += ' || validate.schema' + ($schemaPath) + '.hasOwnProperty(' + ($key) + ') ';
3401 var arr1 = $schemaKeys;
3403 var $propertyKey, i1 = -1,
3404 l1 = arr1.length - 1;
3406 $propertyKey = arr1[i1 += 1];
3407 out += ' || ' + ($key) + ' == ' + (it.util.toQuotedString($propertyKey)) + ' ';
3412 if ($pPropertyKeys.length) {
3413 var arr2 = $pPropertyKeys;
3415 var $pProperty, $i = -1,
3416 l2 = arr2.length - 1;
3418 $pProperty = arr2[$i += 1];
3419 out += ' || ' + (it.usePattern($pProperty)) + '.test(' + ($key) + ') ';
3423 out += ' ); if (isAdditional' + ($lvl) + ') { ';
3425 if ($removeAdditional == 'all') {
3426 out += ' delete ' + ($data) + '[' + ($key) + ']; ';
3428 var $currentErrorPath = it.errorPath;
3429 var $additionalProperty = '\' + ' + $key + ' + \'';
3430 if (it.opts._errorDataPathProperty) {
3431 it.errorPath = it.util.getPathExpr(it.errorPath, $key, it.opts.jsonPointers);
3433 if ($noAdditional) {
3434 if ($removeAdditional) {
3435 out += ' delete ' + ($data) + '[' + ($key) + ']; ';
3437 out += ' ' + ($nextValid) + ' = false; ';
3438 var $currErrSchemaPath = $errSchemaPath;
3439 $errSchemaPath = it.errSchemaPath + '/additionalProperties';
3440 var $$outStack = $$outStack || [];
3441 $$outStack.push(out);
3442 out = ''; /* istanbul ignore else */
3443 if (it.createErrors !== false) {
3444 out += ' { keyword: \'' + ('additionalProperties') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: ' + (it.util.toQuotedString($errSchemaPath)) + ' , params: { additionalProperty: \'' + ($additionalProperty) + '\' } ';
3445 if (it.opts.messages !== false) {
3446 out += ' , message: \'';
3447 if (it.opts._errorDataPathProperty) {
3448 out += 'is an invalid additional property';
3450 out += 'should NOT have additional properties';
3454 if (it.opts.verbose) {
3455 out += ' , schema: false , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' ';
3462 out = $$outStack.pop();
3463 if (!it.compositeRule && $breakOnError) {
3464 /* istanbul ignore if */
3466 out += ' throw new ValidationError([' + (__err) + ']); ';
3468 out += ' validate.errors = [' + (__err) + ']; return false; ';
3471 out += ' var err = ' + (__err) + '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ';
3473 $errSchemaPath = $currErrSchemaPath;
3474 if ($breakOnError) {
3478 } else if ($additionalIsSchema) {
3479 if ($removeAdditional == 'failing') {
3480 out += ' var ' + ($errs) + ' = errors; ';
3481 var $wasComposite = it.compositeRule;
3482 it.compositeRule = $it.compositeRule = true;
3483 $it.schema = $aProperties;
3484 $it.schemaPath = it.schemaPath + '.additionalProperties';
3485 $it.errSchemaPath = it.errSchemaPath + '/additionalProperties';
3486 $it.errorPath = it.opts._errorDataPathProperty ? it.errorPath : it.util.getPathExpr(it.errorPath, $key, it.opts.jsonPointers);
3487 var $passData = $data + '[' + $key + ']';
3488 $it.dataPathArr[$dataNxt] = $key;
3489 var $code = it.validate($it);
3490 $it.baseId = $currentBaseId;
3491 if (it.util.varOccurences($code, $nextData) < 2) {
3492 out += ' ' + (it.util.varReplace($code, $nextData, $passData)) + ' ';
3494 out += ' var ' + ($nextData) + ' = ' + ($passData) + '; ' + ($code) + ' ';
3496 out += ' if (!' + ($nextValid) + ') { errors = ' + ($errs) + '; if (validate.errors !== null) { if (errors) validate.errors.length = errors; else validate.errors = null; } delete ' + ($data) + '[' + ($key) + ']; } ';
3497 it.compositeRule = $it.compositeRule = $wasComposite;
3499 $it.schema = $aProperties;
3500 $it.schemaPath = it.schemaPath + '.additionalProperties';
3501 $it.errSchemaPath = it.errSchemaPath + '/additionalProperties';
3502 $it.errorPath = it.opts._errorDataPathProperty ? it.errorPath : it.util.getPathExpr(it.errorPath, $key, it.opts.jsonPointers);
3503 var $passData = $data + '[' + $key + ']';
3504 $it.dataPathArr[$dataNxt] = $key;
3505 var $code = it.validate($it);
3506 $it.baseId = $currentBaseId;
3507 if (it.util.varOccurences($code, $nextData) < 2) {
3508 out += ' ' + (it.util.varReplace($code, $nextData, $passData)) + ' ';
3510 out += ' var ' + ($nextData) + ' = ' + ($passData) + '; ' + ($code) + ' ';
3512 if ($breakOnError) {
3513 out += ' if (!' + ($nextValid) + ') break; ';
3517 it.errorPath = $currentErrorPath;
3519 if ($someProperties) {
3523 if ($breakOnError) {
3524 out += ' if (' + ($nextValid) + ') { ';
3525 $closingBraces += '}';
3528 var $useDefaults = it.opts.useDefaults && !it.compositeRule;
3529 if ($schemaKeys.length) {
3530 var arr3 = $schemaKeys;
3532 var $propertyKey, i3 = -1,
3533 l3 = arr3.length - 1;
3535 $propertyKey = arr3[i3 += 1];
3536 var $sch = $schema[$propertyKey];
3537 if ((it.opts.strictKeywords ? (typeof $sch == 'object' && Object.keys($sch).length > 0) || $sch === false : it.util.schemaHasRules($sch, it.RULES.all))) {
3538 var $prop = it.util.getProperty($propertyKey),
3539 $passData = $data + $prop,
3540 $hasDefault = $useDefaults && $sch.default !== undefined;
3542 $it.schemaPath = $schemaPath + $prop;
3543 $it.errSchemaPath = $errSchemaPath + '/' + it.util.escapeFragment($propertyKey);
3544 $it.errorPath = it.util.getPath(it.errorPath, $propertyKey, it.opts.jsonPointers);
3545 $it.dataPathArr[$dataNxt] = it.util.toQuotedString($propertyKey);
3546 var $code = it.validate($it);
3547 $it.baseId = $currentBaseId;
3548 if (it.util.varOccurences($code, $nextData) < 2) {
3549 $code = it.util.varReplace($code, $nextData, $passData);
3550 var $useData = $passData;
3552 var $useData = $nextData;
3553 out += ' var ' + ($nextData) + ' = ' + ($passData) + '; ';
3556 out += ' ' + ($code) + ' ';
3558 if ($requiredHash && $requiredHash[$propertyKey]) {
3559 out += ' if ( ' + ($useData) + ' === undefined ';
3560 if ($ownProperties) {
3561 out += ' || ! Object.prototype.hasOwnProperty.call(' + ($data) + ', \'' + (it.util.escapeQuotes($propertyKey)) + '\') ';
3563 out += ') { ' + ($nextValid) + ' = false; ';
3564 var $currentErrorPath = it.errorPath,
3565 $currErrSchemaPath = $errSchemaPath,
3566 $missingProperty = it.util.escapeQuotes($propertyKey);
3567 if (it.opts._errorDataPathProperty) {
3568 it.errorPath = it.util.getPath($currentErrorPath, $propertyKey, it.opts.jsonPointers);
3570 $errSchemaPath = it.errSchemaPath + '/required';
3571 var $$outStack = $$outStack || [];
3572 $$outStack.push(out);
3573 out = ''; /* istanbul ignore else */
3574 if (it.createErrors !== false) {
3575 out += ' { keyword: \'' + ('required') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: ' + (it.util.toQuotedString($errSchemaPath)) + ' , params: { missingProperty: \'' + ($missingProperty) + '\' } ';
3576 if (it.opts.messages !== false) {
3577 out += ' , message: \'';
3578 if (it.opts._errorDataPathProperty) {
3579 out += 'is a required property';
3581 out += 'should have required property \\\'' + ($missingProperty) + '\\\'';
3585 if (it.opts.verbose) {
3586 out += ' , schema: validate.schema' + ($schemaPath) + ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' ';
3593 out = $$outStack.pop();
3594 if (!it.compositeRule && $breakOnError) {
3595 /* istanbul ignore if */
3597 out += ' throw new ValidationError([' + (__err) + ']); ';
3599 out += ' validate.errors = [' + (__err) + ']; return false; ';
3602 out += ' var err = ' + (__err) + '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ';
3604 $errSchemaPath = $currErrSchemaPath;
3605 it.errorPath = $currentErrorPath;
3606 out += ' } else { ';
3608 if ($breakOnError) {
3609 out += ' if ( ' + ($useData) + ' === undefined ';
3610 if ($ownProperties) {
3611 out += ' || ! Object.prototype.hasOwnProperty.call(' + ($data) + ', \'' + (it.util.escapeQuotes($propertyKey)) + '\') ';
3613 out += ') { ' + ($nextValid) + ' = true; } else { ';
3615 out += ' if (' + ($useData) + ' !== undefined ';
3616 if ($ownProperties) {
3617 out += ' && Object.prototype.hasOwnProperty.call(' + ($data) + ', \'' + (it.util.escapeQuotes($propertyKey)) + '\') ';
3622 out += ' ' + ($code) + ' } ';
3625 if ($breakOnError) {
3626 out += ' if (' + ($nextValid) + ') { ';
3627 $closingBraces += '}';
3632 if ($pPropertyKeys.length) {
3633 var arr4 = $pPropertyKeys;
3635 var $pProperty, i4 = -1,
3636 l4 = arr4.length - 1;
3638 $pProperty = arr4[i4 += 1];
3639 var $sch = $pProperties[$pProperty];
3640 if ((it.opts.strictKeywords ? (typeof $sch == 'object' && Object.keys($sch).length > 0) || $sch === false : it.util.schemaHasRules($sch, it.RULES.all))) {
3642 $it.schemaPath = it.schemaPath + '.patternProperties' + it.util.getProperty($pProperty);
3643 $it.errSchemaPath = it.errSchemaPath + '/patternProperties/' + it.util.escapeFragment($pProperty);
3644 if ($ownProperties) {
3645 out += ' ' + ($dataProperties) + ' = ' + ($dataProperties) + ' || Object.keys(' + ($data) + '); for (var ' + ($idx) + '=0; ' + ($idx) + '<' + ($dataProperties) + '.length; ' + ($idx) + '++) { var ' + ($key) + ' = ' + ($dataProperties) + '[' + ($idx) + ']; ';
3647 out += ' for (var ' + ($key) + ' in ' + ($data) + ') { ';
3649 out += ' if (' + (it.usePattern($pProperty)) + '.test(' + ($key) + ')) { ';
3650 $it.errorPath = it.util.getPathExpr(it.errorPath, $key, it.opts.jsonPointers);
3651 var $passData = $data + '[' + $key + ']';
3652 $it.dataPathArr[$dataNxt] = $key;
3653 var $code = it.validate($it);
3654 $it.baseId = $currentBaseId;
3655 if (it.util.varOccurences($code, $nextData) < 2) {
3656 out += ' ' + (it.util.varReplace($code, $nextData, $passData)) + ' ';
3658 out += ' var ' + ($nextData) + ' = ' + ($passData) + '; ' + ($code) + ' ';
3660 if ($breakOnError) {
3661 out += ' if (!' + ($nextValid) + ') break; ';
3664 if ($breakOnError) {
3665 out += ' else ' + ($nextValid) + ' = true; ';
3668 if ($breakOnError) {
3669 out += ' if (' + ($nextValid) + ') { ';
3670 $closingBraces += '}';
3676 if ($breakOnError) {
3677 out += ' ' + ($closingBraces) + ' if (' + ($errs) + ' == errors) {';
3682 },{}],34:[function(require,module,exports){
3684 module.exports = function generate_propertyNames(it, $keyword, $ruleType) {
3686 var $lvl = it.level;
3687 var $dataLvl = it.dataLevel;
3688 var $schema = it.schema[$keyword];
3689 var $schemaPath = it.schemaPath + it.util.getProperty($keyword);
3690 var $errSchemaPath = it.errSchemaPath + '/' + $keyword;
3691 var $breakOnError = !it.opts.allErrors;
3692 var $data = 'data' + ($dataLvl || '');
3693 var $errs = 'errs__' + $lvl;
3694 var $it = it.util.copy(it);
3695 var $closingBraces = '';
3697 var $nextValid = 'valid' + $it.level;
3698 out += 'var ' + ($errs) + ' = errors;';
3699 if ((it.opts.strictKeywords ? (typeof $schema == 'object' && Object.keys($schema).length > 0) || $schema === false : it.util.schemaHasRules($schema, it.RULES.all))) {
3700 $it.schema = $schema;
3701 $it.schemaPath = $schemaPath;
3702 $it.errSchemaPath = $errSchemaPath;
3703 var $key = 'key' + $lvl,
3704 $idx = 'idx' + $lvl,
3706 $invalidName = '\' + ' + $key + ' + \'',
3707 $dataNxt = $it.dataLevel = it.dataLevel + 1,
3708 $nextData = 'data' + $dataNxt,
3709 $dataProperties = 'dataProperties' + $lvl,
3710 $ownProperties = it.opts.ownProperties,
3711 $currentBaseId = it.baseId;
3712 if ($ownProperties) {
3713 out += ' var ' + ($dataProperties) + ' = undefined; ';
3715 if ($ownProperties) {
3716 out += ' ' + ($dataProperties) + ' = ' + ($dataProperties) + ' || Object.keys(' + ($data) + '); for (var ' + ($idx) + '=0; ' + ($idx) + '<' + ($dataProperties) + '.length; ' + ($idx) + '++) { var ' + ($key) + ' = ' + ($dataProperties) + '[' + ($idx) + ']; ';
3718 out += ' for (var ' + ($key) + ' in ' + ($data) + ') { ';
3720 out += ' var startErrs' + ($lvl) + ' = errors; ';
3721 var $passData = $key;
3722 var $wasComposite = it.compositeRule;
3723 it.compositeRule = $it.compositeRule = true;
3724 var $code = it.validate($it);
3725 $it.baseId = $currentBaseId;
3726 if (it.util.varOccurences($code, $nextData) < 2) {
3727 out += ' ' + (it.util.varReplace($code, $nextData, $passData)) + ' ';
3729 out += ' var ' + ($nextData) + ' = ' + ($passData) + '; ' + ($code) + ' ';
3731 it.compositeRule = $it.compositeRule = $wasComposite;
3732 out += ' if (!' + ($nextValid) + ') { for (var ' + ($i) + '=startErrs' + ($lvl) + '; ' + ($i) + '<errors; ' + ($i) + '++) { vErrors[' + ($i) + '].propertyName = ' + ($key) + '; } var err = '; /* istanbul ignore else */
3733 if (it.createErrors !== false) {
3734 out += ' { keyword: \'' + ('propertyNames') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: ' + (it.util.toQuotedString($errSchemaPath)) + ' , params: { propertyName: \'' + ($invalidName) + '\' } ';
3735 if (it.opts.messages !== false) {
3736 out += ' , message: \'property name \\\'' + ($invalidName) + '\\\' is invalid\' ';
3738 if (it.opts.verbose) {
3739 out += ' , schema: validate.schema' + ($schemaPath) + ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' ';
3745 out += '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ';
3746 if (!it.compositeRule && $breakOnError) {
3747 /* istanbul ignore if */
3749 out += ' throw new ValidationError(vErrors); ';
3751 out += ' validate.errors = vErrors; return false; ';
3754 if ($breakOnError) {
3759 if ($breakOnError) {
3760 out += ' ' + ($closingBraces) + ' if (' + ($errs) + ' == errors) {';
3765 },{}],35:[function(require,module,exports){
3767 module.exports = function generate_ref(it, $keyword, $ruleType) {
3769 var $lvl = it.level;
3770 var $dataLvl = it.dataLevel;
3771 var $schema = it.schema[$keyword];
3772 var $errSchemaPath = it.errSchemaPath + '/' + $keyword;
3773 var $breakOnError = !it.opts.allErrors;
3774 var $data = 'data' + ($dataLvl || '');
3775 var $valid = 'valid' + $lvl;
3776 var $async, $refCode;
3777 if ($schema == '#' || $schema == '#/') {
3780 $refCode = 'validate';
3782 $async = it.root.schema.$async === true;
3783 $refCode = 'root.refVal[0]';
3786 var $refVal = it.resolveRef(it.baseId, $schema, it.isRoot);
3787 if ($refVal === undefined) {
3788 var $message = it.MissingRefError.message(it.baseId, $schema);
3789 if (it.opts.missingRefs == 'fail') {
3790 it.logger.error($message);
3791 var $$outStack = $$outStack || [];
3792 $$outStack.push(out);
3793 out = ''; /* istanbul ignore else */
3794 if (it.createErrors !== false) {
3795 out += ' { keyword: \'' + ('$ref') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: ' + (it.util.toQuotedString($errSchemaPath)) + ' , params: { ref: \'' + (it.util.escapeQuotes($schema)) + '\' } ';
3796 if (it.opts.messages !== false) {
3797 out += ' , message: \'can\\\'t resolve reference ' + (it.util.escapeQuotes($schema)) + '\' ';
3799 if (it.opts.verbose) {
3800 out += ' , schema: ' + (it.util.toQuotedString($schema)) + ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' ';
3807 out = $$outStack.pop();
3808 if (!it.compositeRule && $breakOnError) {
3809 /* istanbul ignore if */
3811 out += ' throw new ValidationError([' + (__err) + ']); ';
3813 out += ' validate.errors = [' + (__err) + ']; return false; ';
3816 out += ' var err = ' + (__err) + '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ';
3818 if ($breakOnError) {
3819 out += ' if (false) { ';
3821 } else if (it.opts.missingRefs == 'ignore') {
3822 it.logger.warn($message);
3823 if ($breakOnError) {
3824 out += ' if (true) { ';
3827 throw new it.MissingRefError(it.baseId, $schema, $message);
3829 } else if ($refVal.inline) {
3830 var $it = it.util.copy(it);
3832 var $nextValid = 'valid' + $it.level;
3833 $it.schema = $refVal.schema;
3834 $it.schemaPath = '';
3835 $it.errSchemaPath = $schema;
3836 var $code = it.validate($it).replace(/validate\.schema/g, $refVal.code);
3837 out += ' ' + ($code) + ' ';
3838 if ($breakOnError) {
3839 out += ' if (' + ($nextValid) + ') { ';
3842 $async = $refVal.$async === true || (it.async && $refVal.$async !== false);
3843 $refCode = $refVal.code;
3847 var $$outStack = $$outStack || [];
3848 $$outStack.push(out);
3850 if (it.opts.passContext) {
3851 out += ' ' + ($refCode) + '.call(this, ';
3853 out += ' ' + ($refCode) + '( ';
3855 out += ' ' + ($data) + ', (dataPath || \'\')';
3856 if (it.errorPath != '""') {
3857 out += ' + ' + (it.errorPath);
3859 var $parentData = $dataLvl ? 'data' + (($dataLvl - 1) || '') : 'parentData',
3860 $parentDataProperty = $dataLvl ? it.dataPathArr[$dataLvl] : 'parentDataProperty';
3861 out += ' , ' + ($parentData) + ' , ' + ($parentDataProperty) + ', rootData) ';
3862 var __callValidate = out;
3863 out = $$outStack.pop();
3865 if (!it.async) throw new Error('async schema referenced by sync schema');
3866 if ($breakOnError) {
3867 out += ' var ' + ($valid) + '; ';
3869 out += ' try { await ' + (__callValidate) + '; ';
3870 if ($breakOnError) {
3871 out += ' ' + ($valid) + ' = true; ';
3873 out += ' } catch (e) { if (!(e instanceof ValidationError)) throw e; if (vErrors === null) vErrors = e.errors; else vErrors = vErrors.concat(e.errors); errors = vErrors.length; ';
3874 if ($breakOnError) {
3875 out += ' ' + ($valid) + ' = false; ';
3878 if ($breakOnError) {
3879 out += ' if (' + ($valid) + ') { ';
3882 out += ' if (!' + (__callValidate) + ') { if (vErrors === null) vErrors = ' + ($refCode) + '.errors; else vErrors = vErrors.concat(' + ($refCode) + '.errors); errors = vErrors.length; } ';
3883 if ($breakOnError) {
3891 },{}],36:[function(require,module,exports){
3893 module.exports = function generate_required(it, $keyword, $ruleType) {
3895 var $lvl = it.level;
3896 var $dataLvl = it.dataLevel;
3897 var $schema = it.schema[$keyword];
3898 var $schemaPath = it.schemaPath + it.util.getProperty($keyword);
3899 var $errSchemaPath = it.errSchemaPath + '/' + $keyword;
3900 var $breakOnError = !it.opts.allErrors;
3901 var $data = 'data' + ($dataLvl || '');
3902 var $valid = 'valid' + $lvl;
3903 var $isData = it.opts.$data && $schema && $schema.$data,
3906 out += ' var schema' + ($lvl) + ' = ' + (it.util.getData($schema.$data, $dataLvl, it.dataPathArr)) + '; ';
3907 $schemaValue = 'schema' + $lvl;
3909 $schemaValue = $schema;
3911 var $vSchema = 'schema' + $lvl;
3913 if ($schema.length < it.opts.loopRequired && it.schema.properties && Object.keys(it.schema.properties).length) {
3917 var $property, i1 = -1,
3918 l1 = arr1.length - 1;
3920 $property = arr1[i1 += 1];
3921 var $propertySch = it.schema.properties[$property];
3922 if (!($propertySch && (it.opts.strictKeywords ? (typeof $propertySch == 'object' && Object.keys($propertySch).length > 0) || $propertySch === false : it.util.schemaHasRules($propertySch, it.RULES.all)))) {
3923 $required[$required.length] = $property;
3928 var $required = $schema;
3931 if ($isData || $required.length) {
3932 var $currentErrorPath = it.errorPath,
3933 $loopRequired = $isData || $required.length >= it.opts.loopRequired,
3934 $ownProperties = it.opts.ownProperties;
3935 if ($breakOnError) {
3936 out += ' var missing' + ($lvl) + '; ';
3937 if ($loopRequired) {
3939 out += ' var ' + ($vSchema) + ' = validate.schema' + ($schemaPath) + '; ';
3941 var $i = 'i' + $lvl,
3942 $propertyPath = 'schema' + $lvl + '[' + $i + ']',
3943 $missingProperty = '\' + ' + $propertyPath + ' + \'';
3944 if (it.opts._errorDataPathProperty) {
3945 it.errorPath = it.util.getPathExpr($currentErrorPath, $propertyPath, it.opts.jsonPointers);
3947 out += ' var ' + ($valid) + ' = true; ';
3949 out += ' if (schema' + ($lvl) + ' === undefined) ' + ($valid) + ' = true; else if (!Array.isArray(schema' + ($lvl) + ')) ' + ($valid) + ' = false; else {';
3951 out += ' for (var ' + ($i) + ' = 0; ' + ($i) + ' < ' + ($vSchema) + '.length; ' + ($i) + '++) { ' + ($valid) + ' = ' + ($data) + '[' + ($vSchema) + '[' + ($i) + ']] !== undefined ';
3952 if ($ownProperties) {
3953 out += ' && Object.prototype.hasOwnProperty.call(' + ($data) + ', ' + ($vSchema) + '[' + ($i) + ']) ';
3955 out += '; if (!' + ($valid) + ') break; } ';
3959 out += ' if (!' + ($valid) + ') { ';
3960 var $$outStack = $$outStack || [];
3961 $$outStack.push(out);
3962 out = ''; /* istanbul ignore else */
3963 if (it.createErrors !== false) {
3964 out += ' { keyword: \'' + ('required') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: ' + (it.util.toQuotedString($errSchemaPath)) + ' , params: { missingProperty: \'' + ($missingProperty) + '\' } ';
3965 if (it.opts.messages !== false) {
3966 out += ' , message: \'';
3967 if (it.opts._errorDataPathProperty) {
3968 out += 'is a required property';
3970 out += 'should have required property \\\'' + ($missingProperty) + '\\\'';
3974 if (it.opts.verbose) {
3975 out += ' , schema: validate.schema' + ($schemaPath) + ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' ';
3982 out = $$outStack.pop();
3983 if (!it.compositeRule && $breakOnError) {
3984 /* istanbul ignore if */
3986 out += ' throw new ValidationError([' + (__err) + ']); ';
3988 out += ' validate.errors = [' + (__err) + ']; return false; ';
3991 out += ' var err = ' + (__err) + '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ';
3993 out += ' } else { ';
3996 var arr2 = $required;
3998 var $propertyKey, $i = -1,
3999 l2 = arr2.length - 1;
4001 $propertyKey = arr2[$i += 1];
4005 var $prop = it.util.getProperty($propertyKey),
4006 $useData = $data + $prop;
4007 out += ' ( ( ' + ($useData) + ' === undefined ';
4008 if ($ownProperties) {
4009 out += ' || ! Object.prototype.hasOwnProperty.call(' + ($data) + ', \'' + (it.util.escapeQuotes($propertyKey)) + '\') ';
4011 out += ') && (missing' + ($lvl) + ' = ' + (it.util.toQuotedString(it.opts.jsonPointers ? $propertyKey : $prop)) + ') ) ';
4015 var $propertyPath = 'missing' + $lvl,
4016 $missingProperty = '\' + ' + $propertyPath + ' + \'';
4017 if (it.opts._errorDataPathProperty) {
4018 it.errorPath = it.opts.jsonPointers ? it.util.getPathExpr($currentErrorPath, $propertyPath, true) : $currentErrorPath + ' + ' + $propertyPath;
4020 var $$outStack = $$outStack || [];
4021 $$outStack.push(out);
4022 out = ''; /* istanbul ignore else */
4023 if (it.createErrors !== false) {
4024 out += ' { keyword: \'' + ('required') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: ' + (it.util.toQuotedString($errSchemaPath)) + ' , params: { missingProperty: \'' + ($missingProperty) + '\' } ';
4025 if (it.opts.messages !== false) {
4026 out += ' , message: \'';
4027 if (it.opts._errorDataPathProperty) {
4028 out += 'is a required property';
4030 out += 'should have required property \\\'' + ($missingProperty) + '\\\'';
4034 if (it.opts.verbose) {
4035 out += ' , schema: validate.schema' + ($schemaPath) + ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' ';
4042 out = $$outStack.pop();
4043 if (!it.compositeRule && $breakOnError) {
4044 /* istanbul ignore if */
4046 out += ' throw new ValidationError([' + (__err) + ']); ';
4048 out += ' validate.errors = [' + (__err) + ']; return false; ';
4051 out += ' var err = ' + (__err) + '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ';
4053 out += ' } else { ';
4056 if ($loopRequired) {
4058 out += ' var ' + ($vSchema) + ' = validate.schema' + ($schemaPath) + '; ';
4060 var $i = 'i' + $lvl,
4061 $propertyPath = 'schema' + $lvl + '[' + $i + ']',
4062 $missingProperty = '\' + ' + $propertyPath + ' + \'';
4063 if (it.opts._errorDataPathProperty) {
4064 it.errorPath = it.util.getPathExpr($currentErrorPath, $propertyPath, it.opts.jsonPointers);
4067 out += ' if (' + ($vSchema) + ' && !Array.isArray(' + ($vSchema) + ')) { var err = '; /* istanbul ignore else */
4068 if (it.createErrors !== false) {
4069 out += ' { keyword: \'' + ('required') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: ' + (it.util.toQuotedString($errSchemaPath)) + ' , params: { missingProperty: \'' + ($missingProperty) + '\' } ';
4070 if (it.opts.messages !== false) {
4071 out += ' , message: \'';
4072 if (it.opts._errorDataPathProperty) {
4073 out += 'is a required property';
4075 out += 'should have required property \\\'' + ($missingProperty) + '\\\'';
4079 if (it.opts.verbose) {
4080 out += ' , schema: validate.schema' + ($schemaPath) + ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' ';
4086 out += '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; } else if (' + ($vSchema) + ' !== undefined) { ';
4088 out += ' for (var ' + ($i) + ' = 0; ' + ($i) + ' < ' + ($vSchema) + '.length; ' + ($i) + '++) { if (' + ($data) + '[' + ($vSchema) + '[' + ($i) + ']] === undefined ';
4089 if ($ownProperties) {
4090 out += ' || ! Object.prototype.hasOwnProperty.call(' + ($data) + ', ' + ($vSchema) + '[' + ($i) + ']) ';
4092 out += ') { var err = '; /* istanbul ignore else */
4093 if (it.createErrors !== false) {
4094 out += ' { keyword: \'' + ('required') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: ' + (it.util.toQuotedString($errSchemaPath)) + ' , params: { missingProperty: \'' + ($missingProperty) + '\' } ';
4095 if (it.opts.messages !== false) {
4096 out += ' , message: \'';
4097 if (it.opts._errorDataPathProperty) {
4098 out += 'is a required property';
4100 out += 'should have required property \\\'' + ($missingProperty) + '\\\'';
4104 if (it.opts.verbose) {
4105 out += ' , schema: validate.schema' + ($schemaPath) + ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' ';
4111 out += '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; } } ';
4116 var arr3 = $required;
4118 var $propertyKey, i3 = -1,
4119 l3 = arr3.length - 1;
4121 $propertyKey = arr3[i3 += 1];
4122 var $prop = it.util.getProperty($propertyKey),
4123 $missingProperty = it.util.escapeQuotes($propertyKey),
4124 $useData = $data + $prop;
4125 if (it.opts._errorDataPathProperty) {
4126 it.errorPath = it.util.getPath($currentErrorPath, $propertyKey, it.opts.jsonPointers);
4128 out += ' if ( ' + ($useData) + ' === undefined ';
4129 if ($ownProperties) {
4130 out += ' || ! Object.prototype.hasOwnProperty.call(' + ($data) + ', \'' + (it.util.escapeQuotes($propertyKey)) + '\') ';
4132 out += ') { var err = '; /* istanbul ignore else */
4133 if (it.createErrors !== false) {
4134 out += ' { keyword: \'' + ('required') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: ' + (it.util.toQuotedString($errSchemaPath)) + ' , params: { missingProperty: \'' + ($missingProperty) + '\' } ';
4135 if (it.opts.messages !== false) {
4136 out += ' , message: \'';
4137 if (it.opts._errorDataPathProperty) {
4138 out += 'is a required property';
4140 out += 'should have required property \\\'' + ($missingProperty) + '\\\'';
4144 if (it.opts.verbose) {
4145 out += ' , schema: validate.schema' + ($schemaPath) + ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' ';
4151 out += '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; } ';
4156 it.errorPath = $currentErrorPath;
4157 } else if ($breakOnError) {
4158 out += ' if (true) {';
4163 },{}],37:[function(require,module,exports){
4165 module.exports = function generate_uniqueItems(it, $keyword, $ruleType) {
4167 var $lvl = it.level;
4168 var $dataLvl = it.dataLevel;
4169 var $schema = it.schema[$keyword];
4170 var $schemaPath = it.schemaPath + it.util.getProperty($keyword);
4171 var $errSchemaPath = it.errSchemaPath + '/' + $keyword;
4172 var $breakOnError = !it.opts.allErrors;
4173 var $data = 'data' + ($dataLvl || '');
4174 var $valid = 'valid' + $lvl;
4175 var $isData = it.opts.$data && $schema && $schema.$data,
4178 out += ' var schema' + ($lvl) + ' = ' + (it.util.getData($schema.$data, $dataLvl, it.dataPathArr)) + '; ';
4179 $schemaValue = 'schema' + $lvl;
4181 $schemaValue = $schema;
4183 if (($schema || $isData) && it.opts.uniqueItems !== false) {
4185 out += ' var ' + ($valid) + '; if (' + ($schemaValue) + ' === false || ' + ($schemaValue) + ' === undefined) ' + ($valid) + ' = true; else if (typeof ' + ($schemaValue) + ' != \'boolean\') ' + ($valid) + ' = false; else { ';
4187 out += ' var i = ' + ($data) + '.length , ' + ($valid) + ' = true , j; if (i > 1) { ';
4188 var $itemType = it.schema.items && it.schema.items.type,
4189 $typeIsArray = Array.isArray($itemType);
4190 if (!$itemType || $itemType == 'object' || $itemType == 'array' || ($typeIsArray && ($itemType.indexOf('object') >= 0 || $itemType.indexOf('array') >= 0))) {
4191 out += ' outer: for (;i--;) { for (j = i; j--;) { if (equal(' + ($data) + '[i], ' + ($data) + '[j])) { ' + ($valid) + ' = false; break outer; } } } ';
4193 out += ' var itemIndices = {}, item; for (;i--;) { var item = ' + ($data) + '[i]; ';
4194 var $method = 'checkDataType' + ($typeIsArray ? 's' : '');
4195 out += ' if (' + (it.util[$method]($itemType, 'item', it.opts.strictNumbers, true)) + ') continue; ';
4197 out += ' if (typeof item == \'string\') item = \'"\' + item; ';
4199 out += ' if (typeof itemIndices[item] == \'number\') { ' + ($valid) + ' = false; j = itemIndices[item]; break; } itemIndices[item] = i; } ';
4205 out += ' if (!' + ($valid) + ') { ';
4206 var $$outStack = $$outStack || [];
4207 $$outStack.push(out);
4208 out = ''; /* istanbul ignore else */
4209 if (it.createErrors !== false) {
4210 out += ' { keyword: \'' + ('uniqueItems') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: ' + (it.util.toQuotedString($errSchemaPath)) + ' , params: { i: i, j: j } ';
4211 if (it.opts.messages !== false) {
4212 out += ' , message: \'should NOT have duplicate items (items ## \' + j + \' and \' + i + \' are identical)\' ';
4214 if (it.opts.verbose) {
4215 out += ' , schema: ';
4217 out += 'validate.schema' + ($schemaPath);
4219 out += '' + ($schema);
4221 out += ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' ';
4228 out = $$outStack.pop();
4229 if (!it.compositeRule && $breakOnError) {
4230 /* istanbul ignore if */
4232 out += ' throw new ValidationError([' + (__err) + ']); ';
4234 out += ' validate.errors = [' + (__err) + ']; return false; ';
4237 out += ' var err = ' + (__err) + '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ';
4240 if ($breakOnError) {
4244 if ($breakOnError) {
4245 out += ' if (true) { ';
4251 },{}],38:[function(require,module,exports){
4253 module.exports = function generate_validate(it, $keyword, $ruleType) {
4255 var $async = it.schema.$async === true,
4256 $refKeywords = it.util.schemaHasRulesExcept(it.schema, it.RULES.all, '$ref'),
4257 $id = it.self._getId(it.schema);
4258 if (it.opts.strictKeywords) {
4259 var $unknownKwd = it.util.schemaUnknownRules(it.schema, it.RULES.keywords);
4261 var $keywordsMsg = 'unknown keyword: ' + $unknownKwd;
4262 if (it.opts.strictKeywords === 'log') it.logger.warn($keywordsMsg);
4263 else throw new Error($keywordsMsg);
4267 out += ' var validate = ';
4272 out += 'function(data, dataPath, parentData, parentDataProperty, rootData) { \'use strict\'; ';
4273 if ($id && (it.opts.sourceCode || it.opts.processCode)) {
4274 out += ' ' + ('/\*# sourceURL=' + $id + ' */') + ' ';
4277 if (typeof it.schema == 'boolean' || !($refKeywords || it.schema.$ref)) {
4278 var $keyword = 'false schema';
4279 var $lvl = it.level;
4280 var $dataLvl = it.dataLevel;
4281 var $schema = it.schema[$keyword];
4282 var $schemaPath = it.schemaPath + it.util.getProperty($keyword);
4283 var $errSchemaPath = it.errSchemaPath + '/' + $keyword;
4284 var $breakOnError = !it.opts.allErrors;
4286 var $data = 'data' + ($dataLvl || '');
4287 var $valid = 'valid' + $lvl;
4288 if (it.schema === false) {
4290 $breakOnError = true;
4292 out += ' var ' + ($valid) + ' = false; ';
4294 var $$outStack = $$outStack || [];
4295 $$outStack.push(out);
4296 out = ''; /* istanbul ignore else */
4297 if (it.createErrors !== false) {
4298 out += ' { keyword: \'' + ($errorKeyword || 'false schema') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: ' + (it.util.toQuotedString($errSchemaPath)) + ' , params: {} ';
4299 if (it.opts.messages !== false) {
4300 out += ' , message: \'boolean schema is false\' ';
4302 if (it.opts.verbose) {
4303 out += ' , schema: false , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' ';
4310 out = $$outStack.pop();
4311 if (!it.compositeRule && $breakOnError) {
4312 /* istanbul ignore if */
4314 out += ' throw new ValidationError([' + (__err) + ']); ';
4316 out += ' validate.errors = [' + (__err) + ']; return false; ';
4319 out += ' var err = ' + (__err) + '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ';
4324 out += ' return data; ';
4326 out += ' validate.errors = null; return true; ';
4329 out += ' var ' + ($valid) + ' = true; ';
4333 out += ' }; return validate; ';
4338 var $top = it.isTop,
4339 $lvl = it.level = 0,
4340 $dataLvl = it.dataLevel = 0,
4342 it.rootId = it.resolve.fullPath(it.self._getId(it.root.schema));
4343 it.baseId = it.baseId || it.rootId;
4345 it.dataPathArr = [""];
4346 if (it.schema.default !== undefined && it.opts.useDefaults && it.opts.strictDefaults) {
4347 var $defaultMsg = 'default is ignored in the schema root';
4348 if (it.opts.strictDefaults === 'log') it.logger.warn($defaultMsg);
4349 else throw new Error($defaultMsg);
4351 out += ' var vErrors = null; ';
4352 out += ' var errors = 0; ';
4353 out += ' if (rootData === undefined) rootData = data; ';
4355 var $lvl = it.level,
4356 $dataLvl = it.dataLevel,
4357 $data = 'data' + ($dataLvl || '');
4358 if ($id) it.baseId = it.resolve.url(it.baseId, $id);
4359 if ($async && !it.async) throw new Error('async schema in sync schema');
4360 out += ' var errs_' + ($lvl) + ' = errors;';
4362 var $valid = 'valid' + $lvl,
4363 $breakOnError = !it.opts.allErrors,
4364 $closingBraces1 = '',
4365 $closingBraces2 = '';
4367 var $typeSchema = it.schema.type,
4368 $typeIsArray = Array.isArray($typeSchema);
4369 if ($typeSchema && it.opts.nullable && it.schema.nullable === true) {
4371 if ($typeSchema.indexOf('null') == -1) $typeSchema = $typeSchema.concat('null');
4372 } else if ($typeSchema != 'null') {
4373 $typeSchema = [$typeSchema, 'null'];
4374 $typeIsArray = true;
4377 if ($typeIsArray && $typeSchema.length == 1) {
4378 $typeSchema = $typeSchema[0];
4379 $typeIsArray = false;
4381 if (it.schema.$ref && $refKeywords) {
4382 if (it.opts.extendRefs == 'fail') {
4383 throw new Error('$ref: validation keywords used in schema at path "' + it.errSchemaPath + '" (see option extendRefs)');
4384 } else if (it.opts.extendRefs !== true) {
4385 $refKeywords = false;
4386 it.logger.warn('$ref: keywords ignored in schema at path "' + it.errSchemaPath + '"');
4389 if (it.schema.$comment && it.opts.$comment) {
4390 out += ' ' + (it.RULES.all.$comment.code(it, '$comment'));
4393 if (it.opts.coerceTypes) {
4394 var $coerceToTypes = it.util.coerceToTypes(it.opts.coerceTypes, $typeSchema);
4396 var $rulesGroup = it.RULES.types[$typeSchema];
4397 if ($coerceToTypes || $typeIsArray || $rulesGroup === true || ($rulesGroup && !$shouldUseGroup($rulesGroup))) {
4398 var $schemaPath = it.schemaPath + '.type',
4399 $errSchemaPath = it.errSchemaPath + '/type';
4400 var $schemaPath = it.schemaPath + '.type',
4401 $errSchemaPath = it.errSchemaPath + '/type',
4402 $method = $typeIsArray ? 'checkDataTypes' : 'checkDataType';
4403 out += ' if (' + (it.util[$method]($typeSchema, $data, it.opts.strictNumbers, true)) + ') { ';
4404 if ($coerceToTypes) {
4405 var $dataType = 'dataType' + $lvl,
4406 $coerced = 'coerced' + $lvl;
4407 out += ' var ' + ($dataType) + ' = typeof ' + ($data) + '; var ' + ($coerced) + ' = undefined; ';
4408 if (it.opts.coerceTypes == 'array') {
4409 out += ' if (' + ($dataType) + ' == \'object\' && Array.isArray(' + ($data) + ') && ' + ($data) + '.length == 1) { ' + ($data) + ' = ' + ($data) + '[0]; ' + ($dataType) + ' = typeof ' + ($data) + '; if (' + (it.util.checkDataType(it.schema.type, $data, it.opts.strictNumbers)) + ') ' + ($coerced) + ' = ' + ($data) + '; } ';
4411 out += ' if (' + ($coerced) + ' !== undefined) ; ';
4412 var arr1 = $coerceToTypes;
4415 l1 = arr1.length - 1;
4417 $type = arr1[$i += 1];
4418 if ($type == 'string') {
4419 out += ' else if (' + ($dataType) + ' == \'number\' || ' + ($dataType) + ' == \'boolean\') ' + ($coerced) + ' = \'\' + ' + ($data) + '; else if (' + ($data) + ' === null) ' + ($coerced) + ' = \'\'; ';
4420 } else if ($type == 'number' || $type == 'integer') {
4421 out += ' else if (' + ($dataType) + ' == \'boolean\' || ' + ($data) + ' === null || (' + ($dataType) + ' == \'string\' && ' + ($data) + ' && ' + ($data) + ' == +' + ($data) + ' ';
4422 if ($type == 'integer') {
4423 out += ' && !(' + ($data) + ' % 1)';
4425 out += ')) ' + ($coerced) + ' = +' + ($data) + '; ';
4426 } else if ($type == 'boolean') {
4427 out += ' else if (' + ($data) + ' === \'false\' || ' + ($data) + ' === 0 || ' + ($data) + ' === null) ' + ($coerced) + ' = false; else if (' + ($data) + ' === \'true\' || ' + ($data) + ' === 1) ' + ($coerced) + ' = true; ';
4428 } else if ($type == 'null') {
4429 out += ' else if (' + ($data) + ' === \'\' || ' + ($data) + ' === 0 || ' + ($data) + ' === false) ' + ($coerced) + ' = null; ';
4430 } else if (it.opts.coerceTypes == 'array' && $type == 'array') {
4431 out += ' else if (' + ($dataType) + ' == \'string\' || ' + ($dataType) + ' == \'number\' || ' + ($dataType) + ' == \'boolean\' || ' + ($data) + ' == null) ' + ($coerced) + ' = [' + ($data) + ']; ';
4436 var $$outStack = $$outStack || [];
4437 $$outStack.push(out);
4438 out = ''; /* istanbul ignore else */
4439 if (it.createErrors !== false) {
4440 out += ' { keyword: \'' + ($errorKeyword || 'type') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: ' + (it.util.toQuotedString($errSchemaPath)) + ' , params: { type: \'';
4442 out += '' + ($typeSchema.join(","));
4444 out += '' + ($typeSchema);
4447 if (it.opts.messages !== false) {
4448 out += ' , message: \'should be ';
4450 out += '' + ($typeSchema.join(","));
4452 out += '' + ($typeSchema);
4456 if (it.opts.verbose) {
4457 out += ' , schema: validate.schema' + ($schemaPath) + ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' ';
4464 out = $$outStack.pop();
4465 if (!it.compositeRule && $breakOnError) {
4466 /* istanbul ignore if */
4468 out += ' throw new ValidationError([' + (__err) + ']); ';
4470 out += ' validate.errors = [' + (__err) + ']; return false; ';
4473 out += ' var err = ' + (__err) + '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ';
4475 out += ' } if (' + ($coerced) + ' !== undefined) { ';
4476 var $parentData = $dataLvl ? 'data' + (($dataLvl - 1) || '') : 'parentData',
4477 $parentDataProperty = $dataLvl ? it.dataPathArr[$dataLvl] : 'parentDataProperty';
4478 out += ' ' + ($data) + ' = ' + ($coerced) + '; ';
4480 out += 'if (' + ($parentData) + ' !== undefined)';
4482 out += ' ' + ($parentData) + '[' + ($parentDataProperty) + '] = ' + ($coerced) + '; } ';
4484 var $$outStack = $$outStack || [];
4485 $$outStack.push(out);
4486 out = ''; /* istanbul ignore else */
4487 if (it.createErrors !== false) {
4488 out += ' { keyword: \'' + ($errorKeyword || 'type') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: ' + (it.util.toQuotedString($errSchemaPath)) + ' , params: { type: \'';
4490 out += '' + ($typeSchema.join(","));
4492 out += '' + ($typeSchema);
4495 if (it.opts.messages !== false) {
4496 out += ' , message: \'should be ';
4498 out += '' + ($typeSchema.join(","));
4500 out += '' + ($typeSchema);
4504 if (it.opts.verbose) {
4505 out += ' , schema: validate.schema' + ($schemaPath) + ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' ';
4512 out = $$outStack.pop();
4513 if (!it.compositeRule && $breakOnError) {
4514 /* istanbul ignore if */
4516 out += ' throw new ValidationError([' + (__err) + ']); ';
4518 out += ' validate.errors = [' + (__err) + ']; return false; ';
4521 out += ' var err = ' + (__err) + '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ';
4527 if (it.schema.$ref && !$refKeywords) {
4528 out += ' ' + (it.RULES.all.$ref.code(it, '$ref')) + ' ';
4529 if ($breakOnError) {
4530 out += ' } if (errors === ';
4534 out += 'errs_' + ($lvl);
4537 $closingBraces2 += '}';
4540 var arr2 = it.RULES;
4542 var $rulesGroup, i2 = -1,
4543 l2 = arr2.length - 1;
4545 $rulesGroup = arr2[i2 += 1];
4546 if ($shouldUseGroup($rulesGroup)) {
4547 if ($rulesGroup.type) {
4548 out += ' if (' + (it.util.checkDataType($rulesGroup.type, $data, it.opts.strictNumbers)) + ') { ';
4550 if (it.opts.useDefaults) {
4551 if ($rulesGroup.type == 'object' && it.schema.properties) {
4552 var $schema = it.schema.properties,
4553 $schemaKeys = Object.keys($schema);
4554 var arr3 = $schemaKeys;
4556 var $propertyKey, i3 = -1,
4557 l3 = arr3.length - 1;
4559 $propertyKey = arr3[i3 += 1];
4560 var $sch = $schema[$propertyKey];
4561 if ($sch.default !== undefined) {
4562 var $passData = $data + it.util.getProperty($propertyKey);
4563 if (it.compositeRule) {
4564 if (it.opts.strictDefaults) {
4565 var $defaultMsg = 'default is ignored for: ' + $passData;
4566 if (it.opts.strictDefaults === 'log') it.logger.warn($defaultMsg);
4567 else throw new Error($defaultMsg);
4570 out += ' if (' + ($passData) + ' === undefined ';
4571 if (it.opts.useDefaults == 'empty') {
4572 out += ' || ' + ($passData) + ' === null || ' + ($passData) + ' === \'\' ';
4574 out += ' ) ' + ($passData) + ' = ';
4575 if (it.opts.useDefaults == 'shared') {
4576 out += ' ' + (it.useDefault($sch.default)) + ' ';
4578 out += ' ' + (JSON.stringify($sch.default)) + ' ';
4585 } else if ($rulesGroup.type == 'array' && Array.isArray(it.schema.items)) {
4586 var arr4 = it.schema.items;
4589 l4 = arr4.length - 1;
4591 $sch = arr4[$i += 1];
4592 if ($sch.default !== undefined) {
4593 var $passData = $data + '[' + $i + ']';
4594 if (it.compositeRule) {
4595 if (it.opts.strictDefaults) {
4596 var $defaultMsg = 'default is ignored for: ' + $passData;
4597 if (it.opts.strictDefaults === 'log') it.logger.warn($defaultMsg);
4598 else throw new Error($defaultMsg);
4601 out += ' if (' + ($passData) + ' === undefined ';
4602 if (it.opts.useDefaults == 'empty') {
4603 out += ' || ' + ($passData) + ' === null || ' + ($passData) + ' === \'\' ';
4605 out += ' ) ' + ($passData) + ' = ';
4606 if (it.opts.useDefaults == 'shared') {
4607 out += ' ' + (it.useDefault($sch.default)) + ' ';
4609 out += ' ' + (JSON.stringify($sch.default)) + ' ';
4618 var arr5 = $rulesGroup.rules;
4621 l5 = arr5.length - 1;
4623 $rule = arr5[i5 += 1];
4624 if ($shouldUseRule($rule)) {
4625 var $code = $rule.code(it, $rule.keyword, $rulesGroup.type);
4627 out += ' ' + ($code) + ' ';
4628 if ($breakOnError) {
4629 $closingBraces1 += '}';
4635 if ($breakOnError) {
4636 out += ' ' + ($closingBraces1) + ' ';
4637 $closingBraces1 = '';
4639 if ($rulesGroup.type) {
4641 if ($typeSchema && $typeSchema === $rulesGroup.type && !$coerceToTypes) {
4643 var $schemaPath = it.schemaPath + '.type',
4644 $errSchemaPath = it.errSchemaPath + '/type';
4645 var $$outStack = $$outStack || [];
4646 $$outStack.push(out);
4647 out = ''; /* istanbul ignore else */
4648 if (it.createErrors !== false) {
4649 out += ' { keyword: \'' + ($errorKeyword || 'type') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: ' + (it.util.toQuotedString($errSchemaPath)) + ' , params: { type: \'';
4651 out += '' + ($typeSchema.join(","));
4653 out += '' + ($typeSchema);
4656 if (it.opts.messages !== false) {
4657 out += ' , message: \'should be ';
4659 out += '' + ($typeSchema.join(","));
4661 out += '' + ($typeSchema);
4665 if (it.opts.verbose) {
4666 out += ' , schema: validate.schema' + ($schemaPath) + ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' ';
4673 out = $$outStack.pop();
4674 if (!it.compositeRule && $breakOnError) {
4675 /* istanbul ignore if */
4677 out += ' throw new ValidationError([' + (__err) + ']); ';
4679 out += ' validate.errors = [' + (__err) + ']; return false; ';
4682 out += ' var err = ' + (__err) + '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ';
4687 if ($breakOnError) {
4688 out += ' if (errors === ';
4692 out += 'errs_' + ($lvl);
4695 $closingBraces2 += '}';
4701 if ($breakOnError) {
4702 out += ' ' + ($closingBraces2) + ' ';
4706 out += ' if (errors === 0) return data; ';
4707 out += ' else throw new ValidationError(vErrors); ';
4709 out += ' validate.errors = vErrors; ';
4710 out += ' return errors === 0; ';
4712 out += ' }; return validate;';
4714 out += ' var ' + ($valid) + ' = errors === errs_' + ($lvl) + ';';
4717 function $shouldUseGroup($rulesGroup) {
4718 var rules = $rulesGroup.rules;
4719 for (var i = 0; i < rules.length; i++)
4720 if ($shouldUseRule(rules[i])) return true;
4723 function $shouldUseRule($rule) {
4724 return it.schema[$rule.keyword] !== undefined || ($rule.implements && $ruleImplementsSomeKeyword($rule));
4727 function $ruleImplementsSomeKeyword($rule) {
4728 var impl = $rule.implements;
4729 for (var i = 0; i < impl.length; i++)
4730 if (it.schema[impl[i]] !== undefined) return true;
4735 },{}],39:[function(require,module,exports){
4738 var IDENTIFIER = /^[a-z_$][a-z0-9_$-]*$/i;
4739 var customRuleCode = require('./dotjs/custom');
4740 var definitionSchema = require('./definition_schema');
4745 remove: removeKeyword,
4746 validate: validateKeyword
4751 * Define custom keyword
4753 * @param {String} keyword custom keyword, should be unique (including different from all standard, custom and macro keywords).
4754 * @param {Object} definition keyword definition object with properties `type` (type(s) which the keyword applies to), `validate` or `compile`.
4755 * @return {Ajv} this for method chaining
4757 function addKeyword(keyword, definition) {
4758 /* jshint validthis: true */
4759 /* eslint no-shadow: 0 */
4760 var RULES = this.RULES;
4761 if (RULES.keywords[keyword])
4762 throw new Error('Keyword ' + keyword + ' is already defined');
4764 if (!IDENTIFIER.test(keyword))
4765 throw new Error('Keyword ' + keyword + ' is not a valid identifier');
4768 this.validateKeyword(definition, true);
4770 var dataType = definition.type;
4771 if (Array.isArray(dataType)) {
4772 for (var i=0; i<dataType.length; i++)
4773 _addRule(keyword, dataType[i], definition);
4775 _addRule(keyword, dataType, definition);
4778 var metaSchema = definition.metaSchema;
4780 if (definition.$data && this._opts.$data) {
4784 { '$ref': 'https://raw.githubusercontent.com/ajv-validator/ajv/master/lib/refs/data.json#' }
4788 definition.validateSchema = this.compile(metaSchema, true);
4792 RULES.keywords[keyword] = RULES.all[keyword] = true;
4795 function _addRule(keyword, dataType, definition) {
4797 for (var i=0; i<RULES.length; i++) {
4799 if (rg.type == dataType) {
4806 ruleGroup = { type: dataType, rules: [] };
4807 RULES.push(ruleGroup);
4812 definition: definition,
4814 code: customRuleCode,
4815 implements: definition.implements
4817 ruleGroup.rules.push(rule);
4818 RULES.custom[keyword] = rule;
4828 * @param {String} keyword pre-defined or custom keyword.
4829 * @return {Object|Boolean} custom keyword definition, `true` if it is a predefined keyword, `false` otherwise.
4831 function getKeyword(keyword) {
4832 /* jshint validthis: true */
4833 var rule = this.RULES.custom[keyword];
4834 return rule ? rule.definition : this.RULES.keywords[keyword] || false;
4841 * @param {String} keyword pre-defined or custom keyword.
4842 * @return {Ajv} this for method chaining
4844 function removeKeyword(keyword) {
4845 /* jshint validthis: true */
4846 var RULES = this.RULES;
4847 delete RULES.keywords[keyword];
4848 delete RULES.all[keyword];
4849 delete RULES.custom[keyword];
4850 for (var i=0; i<RULES.length; i++) {
4851 var rules = RULES[i].rules;
4852 for (var j=0; j<rules.length; j++) {
4853 if (rules[j].keyword == keyword) {
4864 * Validate keyword definition
4866 * @param {Object} definition keyword definition object.
4867 * @param {Boolean} throwError true to throw exception if definition is invalid
4868 * @return {boolean} validation result
4870 function validateKeyword(definition, throwError) {
4871 validateKeyword.errors = null;
4872 var v = this._validateKeyword = this._validateKeyword
4873 || this.compile(definitionSchema, true);
4875 if (v(definition)) return true;
4876 validateKeyword.errors = v.errors;
4878 throw new Error('custom keyword definition is invalid: ' + this.errorsText(v.errors));
4883 },{"./definition_schema":12,"./dotjs/custom":22}],40:[function(require,module,exports){
4885 "$schema": "http://json-schema.org/draft-07/schema#",
4886 "$id": "https://raw.githubusercontent.com/ajv-validator/ajv/master/lib/refs/data.json#",
4887 "description": "Meta-schema for $data reference (JSON Schema extension proposal)",
4889 "required": [ "$data" ],
4894 { "format": "relative-json-pointer" },
4895 { "format": "json-pointer" }
4899 "additionalProperties": false
4902 },{}],41:[function(require,module,exports){
4904 "$schema": "http://json-schema.org/draft-07/schema#",
4905 "$id": "http://json-schema.org/draft-07/schema#",
4906 "title": "Core schema meta-schema",
4911 "items": { "$ref": "#" }
4913 "nonNegativeInteger": {
4917 "nonNegativeIntegerDefault0": {
4919 { "$ref": "#/definitions/nonNegativeInteger" },
4936 "items": { "type": "string" },
4937 "uniqueItems": true,
4941 "type": ["object", "boolean"],
4945 "format": "uri-reference"
4953 "format": "uri-reference"
4975 "exclusiveMinimum": 0
4980 "exclusiveMaximum": {
4986 "exclusiveMinimum": {
4989 "maxLength": { "$ref": "#/definitions/nonNegativeInteger" },
4990 "minLength": { "$ref": "#/definitions/nonNegativeIntegerDefault0" },
4995 "additionalItems": { "$ref": "#" },
4999 { "$ref": "#/definitions/schemaArray" }
5003 "maxItems": { "$ref": "#/definitions/nonNegativeInteger" },
5004 "minItems": { "$ref": "#/definitions/nonNegativeIntegerDefault0" },
5009 "contains": { "$ref": "#" },
5010 "maxProperties": { "$ref": "#/definitions/nonNegativeInteger" },
5011 "minProperties": { "$ref": "#/definitions/nonNegativeIntegerDefault0" },
5012 "required": { "$ref": "#/definitions/stringArray" },
5013 "additionalProperties": { "$ref": "#" },
5016 "additionalProperties": { "$ref": "#" },
5021 "additionalProperties": { "$ref": "#" },
5024 "patternProperties": {
5026 "additionalProperties": { "$ref": "#" },
5027 "propertyNames": { "format": "regex" },
5032 "additionalProperties": {
5035 { "$ref": "#/definitions/stringArray" }
5039 "propertyNames": { "$ref": "#" },
5049 { "$ref": "#/definitions/simpleTypes" },
5052 "items": { "$ref": "#/definitions/simpleTypes" },
5058 "format": { "type": "string" },
5059 "contentMediaType": { "type": "string" },
5060 "contentEncoding": { "type": "string" },
5061 "if": {"$ref": "#"},
5062 "then": {"$ref": "#"},
5063 "else": {"$ref": "#"},
5064 "allOf": { "$ref": "#/definitions/schemaArray" },
5065 "anyOf": { "$ref": "#/definitions/schemaArray" },
5066 "oneOf": { "$ref": "#/definitions/schemaArray" },
5067 "not": { "$ref": "#" }
5072 },{}],42:[function(require,module,exports){
5075 // do not edit .js files directly - edit src/index.jst
5079 module.exports = function equal(a, b) {
5080 if (a === b) return true;
5082 if (a && b && typeof a == 'object' && typeof b == 'object') {
5083 if (a.constructor !== b.constructor) return false;
5085 var length, i, keys;
5086 if (Array.isArray(a)) {
5088 if (length != b.length) return false;
5089 for (i = length; i-- !== 0;)
5090 if (!equal(a[i], b[i])) return false;
5096 if (a.constructor === RegExp) return a.source === b.source && a.flags === b.flags;
5097 if (a.valueOf !== Object.prototype.valueOf) return a.valueOf() === b.valueOf();
5098 if (a.toString !== Object.prototype.toString) return a.toString() === b.toString();
5100 keys = Object.keys(a);
5101 length = keys.length;
5102 if (length !== Object.keys(b).length) return false;
5104 for (i = length; i-- !== 0;)
5105 if (!Object.prototype.hasOwnProperty.call(b, keys[i])) return false;
5107 for (i = length; i-- !== 0;) {
5110 if (!equal(a[key], b[key])) return false;
5116 // true if both NaN, false otherwise
5117 return a!==a && b!==b;
5120 },{}],43:[function(require,module,exports){
5123 module.exports = function (data, opts) {
5124 if (!opts) opts = {};
5125 if (typeof opts === 'function') opts = { cmp: opts };
5126 var cycles = (typeof opts.cycles === 'boolean') ? opts.cycles : false;
5128 var cmp = opts.cmp && (function (f) {
5129 return function (node) {
5130 return function (a, b) {
5131 var aobj = { key: a, value: node[a] };
5132 var bobj = { key: b, value: node[b] };
5133 return f(aobj, bobj);
5139 return (function stringify (node) {
5140 if (node && node.toJSON && typeof node.toJSON === 'function') {
5141 node = node.toJSON();
5144 if (node === undefined) return;
5145 if (typeof node == 'number') return isFinite(node) ? '' + node : 'null';
5146 if (typeof node !== 'object') return JSON.stringify(node);
5149 if (Array.isArray(node)) {
5151 for (i = 0; i < node.length; i++) {
5153 out += stringify(node[i]) || 'null';
5158 if (node === null) return 'null';
5160 if (seen.indexOf(node) !== -1) {
5161 if (cycles) return JSON.stringify('__cycle__');
5162 throw new TypeError('Converting circular structure to JSON');
5165 var seenIndex = seen.push(node) - 1;
5166 var keys = Object.keys(node).sort(cmp && cmp(node));
5168 for (i = 0; i < keys.length; i++) {
5170 var value = stringify(node[key]);
5172 if (!value) continue;
5173 if (out) out += ',';
5174 out += JSON.stringify(key) + ':' + value;
5176 seen.splice(seenIndex, 1);
5177 return '{' + out + '}';
5181 },{}],44:[function(require,module,exports){
5184 var traverse = module.exports = function (schema, opts, cb) {
5185 // Legacy support for v0.3.1 and earlier.
5186 if (typeof opts == 'function') {
5192 var pre = (typeof cb == 'function') ? cb : cb.pre || function() {};
5193 var post = cb.post || function() {};
5195 _traverse(opts, pre, post, schema, '', schema);
5199 traverse.keywords = {
5200 additionalItems: true,
5203 additionalProperties: true,
5204 propertyNames: true,
5208 traverse.arrayKeywords = {
5215 traverse.propsKeywords = {
5218 patternProperties: true,
5222 traverse.skipKeywords = {
5229 exclusiveMaximum: true,
5230 exclusiveMinimum: true,
5239 maxProperties: true,
5244 function _traverse(opts, pre, post, schema, jsonPtr, rootSchema, parentJsonPtr, parentKeyword, parentSchema, keyIndex) {
5245 if (schema && typeof schema == 'object' && !Array.isArray(schema)) {
5246 pre(schema, jsonPtr, rootSchema, parentJsonPtr, parentKeyword, parentSchema, keyIndex);
5247 for (var key in schema) {
5248 var sch = schema[key];
5249 if (Array.isArray(sch)) {
5250 if (key in traverse.arrayKeywords) {
5251 for (var i=0; i<sch.length; i++)
5252 _traverse(opts, pre, post, sch[i], jsonPtr + '/' + key + '/' + i, rootSchema, jsonPtr, key, schema, i);
5254 } else if (key in traverse.propsKeywords) {
5255 if (sch && typeof sch == 'object') {
5256 for (var prop in sch)
5257 _traverse(opts, pre, post, sch[prop], jsonPtr + '/' + key + '/' + escapeJsonPtr(prop), rootSchema, jsonPtr, key, schema, prop);
5259 } else if (key in traverse.keywords || (opts.allKeys && !(key in traverse.skipKeywords))) {
5260 _traverse(opts, pre, post, sch, jsonPtr + '/' + key, rootSchema, jsonPtr, key, schema);
5263 post(schema, jsonPtr, rootSchema, parentJsonPtr, parentKeyword, parentSchema, keyIndex);
5268 function escapeJsonPtr(str) {
5269 return str.replace(/~/g, '~0').replace(/\//g, '~1');
5272 },{}],45:[function(require,module,exports){
5273 /** @license URI.js v4.4.0 (c) 2011 Gary Court. License: http://github.com/garycourt/uri-js */
5274 (function (global, factory) {
5275 typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
5276 typeof define === 'function' && define.amd ? define(['exports'], factory) :
5277 (factory((global.URI = global.URI || {})));
5278 }(this, (function (exports) { 'use strict';
5281 for (var _len = arguments.length, sets = Array(_len), _key = 0; _key < _len; _key++) {
5282 sets[_key] = arguments[_key];
5285 if (sets.length > 1) {
5286 sets[0] = sets[0].slice(0, -1);
5287 var xl = sets.length - 1;
5288 for (var x = 1; x < xl; ++x) {
5289 sets[x] = sets[x].slice(1, -1);
5291 sets[xl] = sets[xl].slice(1);
5292 return sets.join('');
5297 function subexp(str) {
5298 return "(?:" + str + ")";
5300 function typeOf(o) {
5301 return o === undefined ? "undefined" : o === null ? "null" : Object.prototype.toString.call(o).split(" ").pop().split("]").shift().toLowerCase();
5303 function toUpperCase(str) {
5304 return str.toUpperCase();
5306 function toArray(obj) {
5307 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) : [];
5309 function assign(target, source) {
5312 for (var key in source) {
5313 obj[key] = source[key];
5319 function buildExps(isIRI) {
5320 var ALPHA$$ = "[A-Za-z]",
5323 DQUOTE$$ = "[\\x22]",
5324 HEXDIG$$ = merge(DIGIT$$, "[A-Fa-f]"),
5328 PCT_ENCODED$ = subexp(subexp("%[EFef]" + HEXDIG$$ + "%" + HEXDIG$$ + HEXDIG$$ + "%" + HEXDIG$$ + HEXDIG$$) + "|" + subexp("%[89A-Fa-f]" + HEXDIG$$ + "%" + HEXDIG$$ + HEXDIG$$) + "|" + subexp("%" + HEXDIG$$ + HEXDIG$$)),
5330 GEN_DELIMS$$ = "[\\:\\/\\?\\#\\[\\]\\@]",
5331 SUB_DELIMS$$ = "[\\!\\$\\&\\'\\(\\)\\*\\+\\,\\;\\=]",
5332 RESERVED$$ = merge(GEN_DELIMS$$, SUB_DELIMS$$),
5333 UCSCHAR$$ = isIRI ? "[\\xA0-\\u200D\\u2010-\\u2029\\u202F-\\uD7FF\\uF900-\\uFDCF\\uFDF0-\\uFFEF]" : "[]",
5334 //subset, excludes bidi control characters
5335 IPRIVATE$$ = isIRI ? "[\\uE000-\\uF8FF]" : "[]",
5337 UNRESERVED$$ = merge(ALPHA$$, DIGIT$$, "[\\-\\.\\_\\~]", UCSCHAR$$),
5338 SCHEME$ = subexp(ALPHA$$ + merge(ALPHA$$, DIGIT$$, "[\\+\\-\\.]") + "*"),
5339 USERINFO$ = subexp(subexp(PCT_ENCODED$ + "|" + merge(UNRESERVED$$, SUB_DELIMS$$, "[\\:]")) + "*"),
5340 DEC_OCTET$ = subexp(subexp("25[0-5]") + "|" + subexp("2[0-4]" + DIGIT$$) + "|" + subexp("1" + DIGIT$$ + DIGIT$$) + "|" + subexp("[1-9]" + DIGIT$$) + "|" + DIGIT$$),
5341 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$$),
5342 //relaxed parsing rules
5343 IPV4ADDRESS$ = subexp(DEC_OCTET_RELAXED$ + "\\." + DEC_OCTET_RELAXED$ + "\\." + DEC_OCTET_RELAXED$ + "\\." + DEC_OCTET_RELAXED$),
5344 H16$ = subexp(HEXDIG$$ + "{1,4}"),
5345 LS32$ = subexp(subexp(H16$ + "\\:" + H16$) + "|" + IPV4ADDRESS$),
5346 IPV6ADDRESS1$ = subexp(subexp(H16$ + "\\:") + "{6}" + LS32$),
5347 // 6( h16 ":" ) ls32
5348 IPV6ADDRESS2$ = subexp("\\:\\:" + subexp(H16$ + "\\:") + "{5}" + LS32$),
5349 // "::" 5( h16 ":" ) ls32
5350 IPV6ADDRESS3$ = subexp(subexp(H16$) + "?\\:\\:" + subexp(H16$ + "\\:") + "{4}" + LS32$),
5351 //[ h16 ] "::" 4( h16 ":" ) ls32
5352 IPV6ADDRESS4$ = subexp(subexp(subexp(H16$ + "\\:") + "{0,1}" + H16$) + "?\\:\\:" + subexp(H16$ + "\\:") + "{3}" + LS32$),
5353 //[ *1( h16 ":" ) h16 ] "::" 3( h16 ":" ) ls32
5354 IPV6ADDRESS5$ = subexp(subexp(subexp(H16$ + "\\:") + "{0,2}" + H16$) + "?\\:\\:" + subexp(H16$ + "\\:") + "{2}" + LS32$),
5355 //[ *2( h16 ":" ) h16 ] "::" 2( h16 ":" ) ls32
5356 IPV6ADDRESS6$ = subexp(subexp(subexp(H16$ + "\\:") + "{0,3}" + H16$) + "?\\:\\:" + H16$ + "\\:" + LS32$),
5357 //[ *3( h16 ":" ) h16 ] "::" h16 ":" ls32
5358 IPV6ADDRESS7$ = subexp(subexp(subexp(H16$ + "\\:") + "{0,4}" + H16$) + "?\\:\\:" + LS32$),
5359 //[ *4( h16 ":" ) h16 ] "::" ls32
5360 IPV6ADDRESS8$ = subexp(subexp(subexp(H16$ + "\\:") + "{0,5}" + H16$) + "?\\:\\:" + H16$),
5361 //[ *5( h16 ":" ) h16 ] "::" h16
5362 IPV6ADDRESS9$ = subexp(subexp(subexp(H16$ + "\\:") + "{0,6}" + H16$) + "?\\:\\:"),
5363 //[ *6( h16 ":" ) h16 ] "::"
5364 IPV6ADDRESS$ = subexp([IPV6ADDRESS1$, IPV6ADDRESS2$, IPV6ADDRESS3$, IPV6ADDRESS4$, IPV6ADDRESS5$, IPV6ADDRESS6$, IPV6ADDRESS7$, IPV6ADDRESS8$, IPV6ADDRESS9$].join("|")),
5365 ZONEID$ = subexp(subexp(UNRESERVED$$ + "|" + PCT_ENCODED$) + "+"),
5367 IPV6ADDRZ$ = subexp(IPV6ADDRESS$ + "\\%25" + ZONEID$),
5369 IPV6ADDRZ_RELAXED$ = subexp(IPV6ADDRESS$ + subexp("\\%25|\\%(?!" + HEXDIG$$ + "{2})") + ZONEID$),
5370 //RFC 6874, with relaxed parsing rules
5371 IPVFUTURE$ = subexp("[vV]" + HEXDIG$$ + "+\\." + merge(UNRESERVED$$, SUB_DELIMS$$, "[\\:]") + "+"),
5372 IP_LITERAL$ = subexp("\\[" + subexp(IPV6ADDRZ_RELAXED$ + "|" + IPV6ADDRESS$ + "|" + IPVFUTURE$) + "\\]"),
5374 REG_NAME$ = subexp(subexp(PCT_ENCODED$ + "|" + merge(UNRESERVED$$, SUB_DELIMS$$)) + "*"),
5375 HOST$ = subexp(IP_LITERAL$ + "|" + IPV4ADDRESS$ + "(?!" + REG_NAME$ + ")" + "|" + REG_NAME$),
5376 PORT$ = subexp(DIGIT$$ + "*"),
5377 AUTHORITY$ = subexp(subexp(USERINFO$ + "@") + "?" + HOST$ + subexp("\\:" + PORT$) + "?"),
5378 PCHAR$ = subexp(PCT_ENCODED$ + "|" + merge(UNRESERVED$$, SUB_DELIMS$$, "[\\:\\@]")),
5379 SEGMENT$ = subexp(PCHAR$ + "*"),
5380 SEGMENT_NZ$ = subexp(PCHAR$ + "+"),
5381 SEGMENT_NZ_NC$ = subexp(subexp(PCT_ENCODED$ + "|" + merge(UNRESERVED$$, SUB_DELIMS$$, "[\\@]")) + "+"),
5382 PATH_ABEMPTY$ = subexp(subexp("\\/" + SEGMENT$) + "*"),
5383 PATH_ABSOLUTE$ = subexp("\\/" + subexp(SEGMENT_NZ$ + PATH_ABEMPTY$) + "?"),
5385 PATH_NOSCHEME$ = subexp(SEGMENT_NZ_NC$ + PATH_ABEMPTY$),
5387 PATH_ROOTLESS$ = subexp(SEGMENT_NZ$ + PATH_ABEMPTY$),
5389 PATH_EMPTY$ = "(?!" + PCHAR$ + ")",
5390 PATH$ = subexp(PATH_ABEMPTY$ + "|" + PATH_ABSOLUTE$ + "|" + PATH_NOSCHEME$ + "|" + PATH_ROOTLESS$ + "|" + PATH_EMPTY$),
5391 QUERY$ = subexp(subexp(PCHAR$ + "|" + merge("[\\/\\?]", IPRIVATE$$)) + "*"),
5392 FRAGMENT$ = subexp(subexp(PCHAR$ + "|[\\/\\?]") + "*"),
5393 HIER_PART$ = subexp(subexp("\\/\\/" + AUTHORITY$ + PATH_ABEMPTY$) + "|" + PATH_ABSOLUTE$ + "|" + PATH_ROOTLESS$ + "|" + PATH_EMPTY$),
5394 URI$ = subexp(SCHEME$ + "\\:" + HIER_PART$ + subexp("\\?" + QUERY$) + "?" + subexp("\\#" + FRAGMENT$) + "?"),
5395 RELATIVE_PART$ = subexp(subexp("\\/\\/" + AUTHORITY$ + PATH_ABEMPTY$) + "|" + PATH_ABSOLUTE$ + "|" + PATH_NOSCHEME$ + "|" + PATH_EMPTY$),
5396 RELATIVE$ = subexp(RELATIVE_PART$ + subexp("\\?" + QUERY$) + "?" + subexp("\\#" + FRAGMENT$) + "?"),
5397 URI_REFERENCE$ = subexp(URI$ + "|" + RELATIVE$),
5398 ABSOLUTE_URI$ = subexp(SCHEME$ + "\\:" + HIER_PART$ + subexp("\\?" + QUERY$) + "?"),
5399 GENERIC_REF$ = "^(" + SCHEME$ + ")\\:" + subexp(subexp("\\/\\/(" + subexp("(" + USERINFO$ + ")@") + "?(" + HOST$ + ")" + subexp("\\:(" + PORT$ + ")") + "?)") + "?(" + PATH_ABEMPTY$ + "|" + PATH_ABSOLUTE$ + "|" + PATH_ROOTLESS$ + "|" + PATH_EMPTY$ + ")") + subexp("\\?(" + QUERY$ + ")") + "?" + subexp("\\#(" + FRAGMENT$ + ")") + "?$",
5400 RELATIVE_REF$ = "^(){0}" + subexp(subexp("\\/\\/(" + subexp("(" + USERINFO$ + ")@") + "?(" + HOST$ + ")" + subexp("\\:(" + PORT$ + ")") + "?)") + "?(" + PATH_ABEMPTY$ + "|" + PATH_ABSOLUTE$ + "|" + PATH_NOSCHEME$ + "|" + PATH_EMPTY$ + ")") + subexp("\\?(" + QUERY$ + ")") + "?" + subexp("\\#(" + FRAGMENT$ + ")") + "?$",
5401 ABSOLUTE_REF$ = "^(" + SCHEME$ + ")\\:" + subexp(subexp("\\/\\/(" + subexp("(" + USERINFO$ + ")@") + "?(" + HOST$ + ")" + subexp("\\:(" + PORT$ + ")") + "?)") + "?(" + PATH_ABEMPTY$ + "|" + PATH_ABSOLUTE$ + "|" + PATH_ROOTLESS$ + "|" + PATH_EMPTY$ + ")") + subexp("\\?(" + QUERY$ + ")") + "?$",
5402 SAMEDOC_REF$ = "^" + subexp("\\#(" + FRAGMENT$ + ")") + "?$",
5403 AUTHORITY_REF$ = "^" + subexp("(" + USERINFO$ + ")@") + "?(" + HOST$ + ")" + subexp("\\:(" + PORT$ + ")") + "?$";
5405 NOT_SCHEME: new RegExp(merge("[^]", ALPHA$$, DIGIT$$, "[\\+\\-\\.]"), "g"),
5406 NOT_USERINFO: new RegExp(merge("[^\\%\\:]", UNRESERVED$$, SUB_DELIMS$$), "g"),
5407 NOT_HOST: new RegExp(merge("[^\\%\\[\\]\\:]", UNRESERVED$$, SUB_DELIMS$$), "g"),
5408 NOT_PATH: new RegExp(merge("[^\\%\\/\\:\\@]", UNRESERVED$$, SUB_DELIMS$$), "g"),
5409 NOT_PATH_NOSCHEME: new RegExp(merge("[^\\%\\/\\@]", UNRESERVED$$, SUB_DELIMS$$), "g"),
5410 NOT_QUERY: new RegExp(merge("[^\\%]", UNRESERVED$$, SUB_DELIMS$$, "[\\:\\@\\/\\?]", IPRIVATE$$), "g"),
5411 NOT_FRAGMENT: new RegExp(merge("[^\\%]", UNRESERVED$$, SUB_DELIMS$$, "[\\:\\@\\/\\?]"), "g"),
5412 ESCAPE: new RegExp(merge("[^]", UNRESERVED$$, SUB_DELIMS$$), "g"),
5413 UNRESERVED: new RegExp(UNRESERVED$$, "g"),
5414 OTHER_CHARS: new RegExp(merge("[^\\%]", UNRESERVED$$, RESERVED$$), "g"),
5415 PCT_ENCODED: new RegExp(PCT_ENCODED$, "g"),
5416 IPV4ADDRESS: new RegExp("^(" + IPV4ADDRESS$ + ")$"),
5417 IPV6ADDRESS: new RegExp("^\\[?(" + IPV6ADDRESS$ + ")" + subexp(subexp("\\%25|\\%(?!" + HEXDIG$$ + "{2})") + "(" + ZONEID$ + ")") + "?\\]?$") //RFC 6874, with relaxed parsing rules
5420 var URI_PROTOCOL = buildExps(false);
5422 var IRI_PROTOCOL = buildExps(true);
5424 var slicedToArray = function () {
5425 function sliceIterator(arr, i) {
5432 for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) {
5433 _arr.push(_s.value);
5435 if (i && _arr.length === i) break;
5442 if (!_n && _i["return"]) _i["return"]();
5451 return function (arr, i) {
5452 if (Array.isArray(arr)) {
5454 } else if (Symbol.iterator in Object(arr)) {
5455 return sliceIterator(arr, i);
5457 throw new TypeError("Invalid attempt to destructure non-iterable instance");
5474 var toConsumableArray = function (arr) {
5475 if (Array.isArray(arr)) {
5476 for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) arr2[i] = arr[i];
5480 return Array.from(arr);
5484 /** Highest positive signed 32-bit float value */
5486 var maxInt = 2147483647; // aka. 0x7FFFFFFF or 2^31-1
5488 /** Bootstring parameters */
5494 var initialBias = 72;
5495 var initialN = 128; // 0x80
5496 var delimiter = '-'; // '\x2D'
5498 /** Regular expressions */
5499 var regexPunycode = /^xn--/;
5500 var regexNonASCII = /[^\0-\x7E]/; // non-ASCII chars
5501 var regexSeparators = /[\x2E\u3002\uFF0E\uFF61]/g; // RFC 3490 separators
5503 /** Error messages */
5505 'overflow': 'Overflow: input needs wider integers to process',
5506 'not-basic': 'Illegal input >= 0x80 (not a basic code point)',
5507 'invalid-input': 'Invalid input'
5510 /** Convenience shortcuts */
5511 var baseMinusTMin = base - tMin;
5512 var floor = Math.floor;
5513 var stringFromCharCode = String.fromCharCode;
5515 /*--------------------------------------------------------------------------*/
5518 * A generic error utility function.
5520 * @param {String} type The error type.
5521 * @returns {Error} Throws a `RangeError` with the applicable error message.
5523 function error$1(type) {
5524 throw new RangeError(errors[type]);
5528 * A generic `Array#map` utility function.
5530 * @param {Array} array The array to iterate over.
5531 * @param {Function} callback The function that gets called for every array
5533 * @returns {Array} A new array of values returned by the callback function.
5535 function map(array, fn) {
5537 var length = array.length;
5539 result[length] = fn(array[length]);
5545 * A simple `Array#map`-like wrapper to work with domain name strings or email
5548 * @param {String} domain The domain name or email address.
5549 * @param {Function} callback The function that gets called for every
5551 * @returns {Array} A new string of characters returned by the callback
5554 function mapDomain(string, fn) {
5555 var parts = string.split('@');
5557 if (parts.length > 1) {
5558 // In email addresses, only the domain name should be punycoded. Leave
5559 // the local part (i.e. everything up to `@`) intact.
5560 result = parts[0] + '@';
5563 // Avoid `split(regex)` for IE8 compatibility. See #17.
5564 string = string.replace(regexSeparators, '\x2E');
5565 var labels = string.split('.');
5566 var encoded = map(labels, fn).join('.');
5567 return result + encoded;
5571 * Creates an array containing the numeric code points of each Unicode
5572 * character in the string. While JavaScript uses UCS-2 internally,
5573 * this function will convert a pair of surrogate halves (each of which
5574 * UCS-2 exposes as separate characters) into a single code point,
5576 * @see `punycode.ucs2.encode`
5577 * @see <https://mathiasbynens.be/notes/javascript-encoding>
5578 * @memberOf punycode.ucs2
5580 * @param {String} string The Unicode input string (UCS-2).
5581 * @returns {Array} The new array of code points.
5583 function ucs2decode(string) {
5586 var length = string.length;
5587 while (counter < length) {
5588 var value = string.charCodeAt(counter++);
5589 if (value >= 0xD800 && value <= 0xDBFF && counter < length) {
5590 // It's a high surrogate, and there is a next character.
5591 var extra = string.charCodeAt(counter++);
5592 if ((extra & 0xFC00) == 0xDC00) {
5594 output.push(((value & 0x3FF) << 10) + (extra & 0x3FF) + 0x10000);
5596 // It's an unmatched surrogate; only append this code unit, in case the
5597 // next code unit is the high surrogate of a surrogate pair.
5609 * Creates a string based on an array of numeric code points.
5610 * @see `punycode.ucs2.decode`
5611 * @memberOf punycode.ucs2
5613 * @param {Array} codePoints The array of numeric code points.
5614 * @returns {String} The new Unicode string (UCS-2).
5616 var ucs2encode = function ucs2encode(array) {
5617 return String.fromCodePoint.apply(String, toConsumableArray(array));
5621 * Converts a basic code point into a digit/integer.
5622 * @see `digitToBasic()`
5624 * @param {Number} codePoint The basic numeric code point value.
5625 * @returns {Number} The numeric value of a basic code point (for use in
5626 * representing integers) in the range `0` to `base - 1`, or `base` if
5627 * the code point does not represent a value.
5629 var basicToDigit = function basicToDigit(codePoint) {
5630 if (codePoint - 0x30 < 0x0A) {
5631 return codePoint - 0x16;
5633 if (codePoint - 0x41 < 0x1A) {
5634 return codePoint - 0x41;
5636 if (codePoint - 0x61 < 0x1A) {
5637 return codePoint - 0x61;
5643 * Converts a digit/integer into a basic code point.
5644 * @see `basicToDigit()`
5646 * @param {Number} digit The numeric value of a basic code point.
5647 * @returns {Number} The basic code point whose value (when used for
5648 * representing integers) is `digit`, which needs to be in the range
5649 * `0` to `base - 1`. If `flag` is non-zero, the uppercase form is
5650 * used; else, the lowercase form is used. The behavior is undefined
5651 * if `flag` is non-zero and `digit` has no uppercase form.
5653 var digitToBasic = function digitToBasic(digit, flag) {
5654 // 0..25 map to ASCII a..z or A..Z
5655 // 26..35 map to ASCII 0..9
5656 return digit + 22 + 75 * (digit < 26) - ((flag != 0) << 5);
5660 * Bias adaptation function as per section 3.4 of RFC 3492.
5661 * https://tools.ietf.org/html/rfc3492#section-3.4
5664 var adapt = function adapt(delta, numPoints, firstTime) {
5666 delta = firstTime ? floor(delta / damp) : delta >> 1;
5667 delta += floor(delta / numPoints);
5668 for (; /* no initialization */delta > baseMinusTMin * tMax >> 1; k += base) {
5669 delta = floor(delta / baseMinusTMin);
5671 return floor(k + (baseMinusTMin + 1) * delta / (delta + skew));
5675 * Converts a Punycode string of ASCII-only symbols to a string of Unicode
5677 * @memberOf punycode
5678 * @param {String} input The Punycode string of ASCII-only symbols.
5679 * @returns {String} The resulting string of Unicode symbols.
5681 var decode = function decode(input) {
5684 var inputLength = input.length;
5687 var bias = initialBias;
5689 // Handle the basic code points: let `basic` be the number of input code
5690 // points before the last delimiter, or `0` if there is none, then copy
5691 // the first basic code points to the output.
5693 var basic = input.lastIndexOf(delimiter);
5698 for (var j = 0; j < basic; ++j) {
5699 // if it's not a basic code point
5700 if (input.charCodeAt(j) >= 0x80) {
5701 error$1('not-basic');
5703 output.push(input.charCodeAt(j));
5706 // Main decoding loop: start just after the last delimiter if any basic code
5707 // points were copied; start at the beginning otherwise.
5709 for (var index = basic > 0 ? basic + 1 : 0; index < inputLength;) /* no final expression */{
5711 // `index` is the index of the next character to be consumed.
5712 // Decode a generalized variable-length integer into `delta`,
5713 // which gets added to `i`. The overflow checking is easier
5714 // if we increase `i` as we go, then subtract off its starting
5715 // value at the end to obtain `delta`.
5717 for (var w = 1, k = base;; /* no condition */k += base) {
5719 if (index >= inputLength) {
5720 error$1('invalid-input');
5723 var digit = basicToDigit(input.charCodeAt(index++));
5725 if (digit >= base || digit > floor((maxInt - i) / w)) {
5726 error$1('overflow');
5730 var t = k <= bias ? tMin : k >= bias + tMax ? tMax : k - bias;
5736 var baseMinusT = base - t;
5737 if (w > floor(maxInt / baseMinusT)) {
5738 error$1('overflow');
5744 var out = output.length + 1;
5745 bias = adapt(i - oldi, out, oldi == 0);
5747 // `i` was supposed to wrap around from `out` to `0`,
5748 // incrementing `n` each time, so we'll fix that now:
5749 if (floor(i / out) > maxInt - n) {
5750 error$1('overflow');
5753 n += floor(i / out);
5756 // Insert `n` at position `i` of the output.
5757 output.splice(i++, 0, n);
5760 return String.fromCodePoint.apply(String, output);
5764 * Converts a string of Unicode symbols (e.g. a domain name label) to a
5765 * Punycode string of ASCII-only symbols.
5766 * @memberOf punycode
5767 * @param {String} input The string of Unicode symbols.
5768 * @returns {String} The resulting Punycode string of ASCII-only symbols.
5770 var encode = function encode(input) {
5773 // Convert the input in UCS-2 to an array of Unicode code points.
5774 input = ucs2decode(input);
5776 // Cache the length.
5777 var inputLength = input.length;
5779 // Initialize the state.
5782 var bias = initialBias;
5784 // Handle the basic code points.
5785 var _iteratorNormalCompletion = true;
5786 var _didIteratorError = false;
5787 var _iteratorError = undefined;
5790 for (var _iterator = input[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
5791 var _currentValue2 = _step.value;
5793 if (_currentValue2 < 0x80) {
5794 output.push(stringFromCharCode(_currentValue2));
5798 _didIteratorError = true;
5799 _iteratorError = err;
5802 if (!_iteratorNormalCompletion && _iterator.return) {
5806 if (_didIteratorError) {
5807 throw _iteratorError;
5812 var basicLength = output.length;
5813 var handledCPCount = basicLength;
5815 // `handledCPCount` is the number of code points that have been handled;
5816 // `basicLength` is the number of basic code points.
5818 // Finish the basic string with a delimiter unless it's empty.
5820 output.push(delimiter);
5823 // Main encoding loop:
5824 while (handledCPCount < inputLength) {
5826 // All non-basic code points < n have been handled already. Find the next
5829 var _iteratorNormalCompletion2 = true;
5830 var _didIteratorError2 = false;
5831 var _iteratorError2 = undefined;
5834 for (var _iterator2 = input[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) {
5835 var currentValue = _step2.value;
5837 if (currentValue >= n && currentValue < m) {
5842 // Increase `delta` enough to advance the decoder's <n,i> state to <m,0>,
5843 // but guard against overflow.
5845 _didIteratorError2 = true;
5846 _iteratorError2 = err;
5849 if (!_iteratorNormalCompletion2 && _iterator2.return) {
5850 _iterator2.return();
5853 if (_didIteratorError2) {
5854 throw _iteratorError2;
5859 var handledCPCountPlusOne = handledCPCount + 1;
5860 if (m - n > floor((maxInt - delta) / handledCPCountPlusOne)) {
5861 error$1('overflow');
5864 delta += (m - n) * handledCPCountPlusOne;
5867 var _iteratorNormalCompletion3 = true;
5868 var _didIteratorError3 = false;
5869 var _iteratorError3 = undefined;
5872 for (var _iterator3 = input[Symbol.iterator](), _step3; !(_iteratorNormalCompletion3 = (_step3 = _iterator3.next()).done); _iteratorNormalCompletion3 = true) {
5873 var _currentValue = _step3.value;
5875 if (_currentValue < n && ++delta > maxInt) {
5876 error$1('overflow');
5878 if (_currentValue == n) {
5879 // Represent delta as a generalized variable-length integer.
5881 for (var k = base;; /* no condition */k += base) {
5882 var t = k <= bias ? tMin : k >= bias + tMax ? tMax : k - bias;
5886 var qMinusT = q - t;
5887 var baseMinusT = base - t;
5888 output.push(stringFromCharCode(digitToBasic(t + qMinusT % baseMinusT, 0)));
5889 q = floor(qMinusT / baseMinusT);
5892 output.push(stringFromCharCode(digitToBasic(q, 0)));
5893 bias = adapt(delta, handledCPCountPlusOne, handledCPCount == basicLength);
5899 _didIteratorError3 = true;
5900 _iteratorError3 = err;
5903 if (!_iteratorNormalCompletion3 && _iterator3.return) {
5904 _iterator3.return();
5907 if (_didIteratorError3) {
5908 throw _iteratorError3;
5916 return output.join('');
5920 * Converts a Punycode string representing a domain name or an email address
5921 * to Unicode. Only the Punycoded parts of the input will be converted, i.e.
5922 * it doesn't matter if you call it on a string that has already been
5923 * converted to Unicode.
5924 * @memberOf punycode
5925 * @param {String} input The Punycoded domain name or email address to
5926 * convert to Unicode.
5927 * @returns {String} The Unicode representation of the given Punycode
5930 var toUnicode = function toUnicode(input) {
5931 return mapDomain(input, function (string) {
5932 return regexPunycode.test(string) ? decode(string.slice(4).toLowerCase()) : string;
5937 * Converts a Unicode string representing a domain name or an email address to
5938 * Punycode. Only the non-ASCII parts of the domain name will be converted,
5939 * i.e. it doesn't matter if you call it with a domain that's already in
5941 * @memberOf punycode
5942 * @param {String} input The domain name or email address to convert, as a
5944 * @returns {String} The Punycode representation of the given domain name or
5947 var toASCII = function toASCII(input) {
5948 return mapDomain(input, function (string) {
5949 return regexNonASCII.test(string) ? 'xn--' + encode(string) : string;
5953 /*--------------------------------------------------------------------------*/
5955 /** Define the public API */
5958 * A string representing the current Punycode.js version number.
5959 * @memberOf punycode
5964 * An object of methods to convert from JavaScript's internal character
5965 * representation (UCS-2) to Unicode code points, and back.
5966 * @see <https://mathiasbynens.be/notes/javascript-encoding>
5967 * @memberOf punycode
5971 'decode': ucs2decode,
5972 'encode': ucs2encode
5977 'toUnicode': toUnicode
5983 * @fileoverview An RFC 3986 compliant, scheme extendable URI parsing/validating/resolving library for JavaScript.
5984 * @author <a href="mailto:gary.court@gmail.com">Gary Court</a>
5985 * @see http://github.com/garycourt/uri-js
5988 * Copyright 2011 Gary Court. All rights reserved.
5990 * Redistribution and use in source and binary forms, with or without modification, are
5991 * permitted provided that the following conditions are met:
5993 * 1. Redistributions of source code must retain the above copyright notice, this list of
5994 * conditions and the following disclaimer.
5996 * 2. Redistributions in binary form must reproduce the above copyright notice, this list
5997 * of conditions and the following disclaimer in the documentation and/or other materials
5998 * provided with the distribution.
6000 * THIS SOFTWARE IS PROVIDED BY GARY COURT ``AS IS'' AND ANY EXPRESS OR IMPLIED
6001 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
6002 * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GARY COURT OR
6003 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
6004 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
6005 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
6006 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
6007 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
6008 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
6010 * The views and conclusions contained in the software and documentation are those of the
6011 * authors and should not be interpreted as representing official policies, either expressed
6012 * or implied, of Gary Court.
6015 function pctEncChar(chr) {
6016 var c = chr.charCodeAt(0);
6018 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();
6021 function pctDecChars(str) {
6024 var il = str.length;
6026 var c = parseInt(str.substr(i + 1, 2), 16);
6028 newStr += String.fromCharCode(c);
6030 } else if (c >= 194 && c < 224) {
6032 var c2 = parseInt(str.substr(i + 4, 2), 16);
6033 newStr += String.fromCharCode((c & 31) << 6 | c2 & 63);
6035 newStr += str.substr(i, 6);
6038 } else if (c >= 224) {
6040 var _c = parseInt(str.substr(i + 4, 2), 16);
6041 var c3 = parseInt(str.substr(i + 7, 2), 16);
6042 newStr += String.fromCharCode((c & 15) << 12 | (_c & 63) << 6 | c3 & 63);
6044 newStr += str.substr(i, 9);
6048 newStr += str.substr(i, 3);
6054 function _normalizeComponentEncoding(components, protocol) {
6055 function decodeUnreserved(str) {
6056 var decStr = pctDecChars(str);
6057 return !decStr.match(protocol.UNRESERVED) ? str : decStr;
6059 if (components.scheme) components.scheme = String(components.scheme).replace(protocol.PCT_ENCODED, decodeUnreserved).toLowerCase().replace(protocol.NOT_SCHEME, "");
6060 if (components.userinfo !== undefined) components.userinfo = String(components.userinfo).replace(protocol.PCT_ENCODED, decodeUnreserved).replace(protocol.NOT_USERINFO, pctEncChar).replace(protocol.PCT_ENCODED, toUpperCase);
6061 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);
6062 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);
6063 if (components.query !== undefined) components.query = String(components.query).replace(protocol.PCT_ENCODED, decodeUnreserved).replace(protocol.NOT_QUERY, pctEncChar).replace(protocol.PCT_ENCODED, toUpperCase);
6064 if (components.fragment !== undefined) components.fragment = String(components.fragment).replace(protocol.PCT_ENCODED, decodeUnreserved).replace(protocol.NOT_FRAGMENT, pctEncChar).replace(protocol.PCT_ENCODED, toUpperCase);
6068 function _stripLeadingZeros(str) {
6069 return str.replace(/^0*(.*)/, "$1") || "0";
6071 function _normalizeIPv4(host, protocol) {
6072 var matches = host.match(protocol.IPV4ADDRESS) || [];
6074 var _matches = slicedToArray(matches, 2),
6075 address = _matches[1];
6078 return address.split(".").map(_stripLeadingZeros).join(".");
6083 function _normalizeIPv6(host, protocol) {
6084 var matches = host.match(protocol.IPV6ADDRESS) || [];
6086 var _matches2 = slicedToArray(matches, 3),
6087 address = _matches2[1],
6088 zone = _matches2[2];
6091 var _address$toLowerCase$ = address.toLowerCase().split('::').reverse(),
6092 _address$toLowerCase$2 = slicedToArray(_address$toLowerCase$, 2),
6093 last = _address$toLowerCase$2[0],
6094 first = _address$toLowerCase$2[1];
6096 var firstFields = first ? first.split(":").map(_stripLeadingZeros) : [];
6097 var lastFields = last.split(":").map(_stripLeadingZeros);
6098 var isLastFieldIPv4Address = protocol.IPV4ADDRESS.test(lastFields[lastFields.length - 1]);
6099 var fieldCount = isLastFieldIPv4Address ? 7 : 8;
6100 var lastFieldsStart = lastFields.length - fieldCount;
6101 var fields = Array(fieldCount);
6102 for (var x = 0; x < fieldCount; ++x) {
6103 fields[x] = firstFields[x] || lastFields[lastFieldsStart + x] || '';
6105 if (isLastFieldIPv4Address) {
6106 fields[fieldCount - 1] = _normalizeIPv4(fields[fieldCount - 1], protocol);
6108 var allZeroFields = fields.reduce(function (acc, field, index) {
6109 if (!field || field === "0") {
6110 var lastLongest = acc[acc.length - 1];
6111 if (lastLongest && lastLongest.index + lastLongest.length === index) {
6112 lastLongest.length++;
6114 acc.push({ index: index, length: 1 });
6119 var longestZeroFields = allZeroFields.sort(function (a, b) {
6120 return b.length - a.length;
6122 var newHost = void 0;
6123 if (longestZeroFields && longestZeroFields.length > 1) {
6124 var newFirst = fields.slice(0, longestZeroFields.index);
6125 var newLast = fields.slice(longestZeroFields.index + longestZeroFields.length);
6126 newHost = newFirst.join(":") + "::" + newLast.join(":");
6128 newHost = fields.join(":");
6131 newHost += "%" + zone;
6138 var URI_PARSE = /^(?:([^:\/?#]+):)?(?:\/\/((?:([^\/?#@]*)@)?(\[[^\/?#\]]+\]|[^\/?#:]*)(?:\:(\d*))?))?([^?#]*)(?:\?([^#]*))?(?:#((?:.|\n|\r)*))?/i;
6139 var NO_MATCH_IS_UNDEFINED = "".match(/(){0}/)[1] === undefined;
6140 function parse(uriString) {
6141 var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
6143 var components = {};
6144 var protocol = options.iri !== false ? IRI_PROTOCOL : URI_PROTOCOL;
6145 if (options.reference === "suffix") uriString = (options.scheme ? options.scheme + ":" : "") + "//" + uriString;
6146 var matches = uriString.match(URI_PARSE);
6148 if (NO_MATCH_IS_UNDEFINED) {
6149 //store each component
6150 components.scheme = matches[1];
6151 components.userinfo = matches[3];
6152 components.host = matches[4];
6153 components.port = parseInt(matches[5], 10);
6154 components.path = matches[6] || "";
6155 components.query = matches[7];
6156 components.fragment = matches[8];
6158 if (isNaN(components.port)) {
6159 components.port = matches[5];
6162 //IE FIX for improper RegExp matching
6163 //store each component
6164 components.scheme = matches[1] || undefined;
6165 components.userinfo = uriString.indexOf("@") !== -1 ? matches[3] : undefined;
6166 components.host = uriString.indexOf("//") !== -1 ? matches[4] : undefined;
6167 components.port = parseInt(matches[5], 10);
6168 components.path = matches[6] || "";
6169 components.query = uriString.indexOf("?") !== -1 ? matches[7] : undefined;
6170 components.fragment = uriString.indexOf("#") !== -1 ? matches[8] : undefined;
6172 if (isNaN(components.port)) {
6173 components.port = uriString.match(/\/\/(?:.|\n)*\:(?:\/|\?|\#|$)/) ? matches[4] : undefined;
6176 if (components.host) {
6177 //normalize IP hosts
6178 components.host = _normalizeIPv6(_normalizeIPv4(components.host, protocol), protocol);
6180 //determine reference type
6181 if (components.scheme === undefined && components.userinfo === undefined && components.host === undefined && components.port === undefined && !components.path && components.query === undefined) {
6182 components.reference = "same-document";
6183 } else if (components.scheme === undefined) {
6184 components.reference = "relative";
6185 } else if (components.fragment === undefined) {
6186 components.reference = "absolute";
6188 components.reference = "uri";
6190 //check for reference errors
6191 if (options.reference && options.reference !== "suffix" && options.reference !== components.reference) {
6192 components.error = components.error || "URI is not a " + options.reference + " reference.";
6194 //find scheme handler
6195 var schemeHandler = SCHEMES[(options.scheme || components.scheme || "").toLowerCase()];
6196 //check if scheme can't handle IRIs
6197 if (!options.unicodeSupport && (!schemeHandler || !schemeHandler.unicodeSupport)) {
6198 //if host component is a domain name
6199 if (components.host && (options.domainHost || schemeHandler && schemeHandler.domainHost)) {
6200 //convert Unicode IDN -> ASCII IDN
6202 components.host = punycode.toASCII(components.host.replace(protocol.PCT_ENCODED, pctDecChars).toLowerCase());
6204 components.error = components.error || "Host's domain name can not be converted to ASCII via punycode: " + e;
6207 //convert IRI -> URI
6208 _normalizeComponentEncoding(components, URI_PROTOCOL);
6210 //normalize encodings
6211 _normalizeComponentEncoding(components, protocol);
6213 //perform scheme specific parsing
6214 if (schemeHandler && schemeHandler.parse) {
6215 schemeHandler.parse(components, options);
6218 components.error = components.error || "URI can not be parsed.";
6223 function _recomposeAuthority(components, options) {
6224 var protocol = options.iri !== false ? IRI_PROTOCOL : URI_PROTOCOL;
6226 if (components.userinfo !== undefined) {
6227 uriTokens.push(components.userinfo);
6228 uriTokens.push("@");
6230 if (components.host !== undefined) {
6231 //normalize IP hosts, add brackets and escape zone separator for IPv6
6232 uriTokens.push(_normalizeIPv6(_normalizeIPv4(String(components.host), protocol), protocol).replace(protocol.IPV6ADDRESS, function (_, $1, $2) {
6233 return "[" + $1 + ($2 ? "%25" + $2 : "") + "]";
6236 if (typeof components.port === "number" || typeof components.port === "string") {
6237 uriTokens.push(":");
6238 uriTokens.push(String(components.port));
6240 return uriTokens.length ? uriTokens.join("") : undefined;
6243 var RDS1 = /^\.\.?\//;
6244 var RDS2 = /^\/\.(\/|$)/;
6245 var RDS3 = /^\/\.\.(\/|$)/;
6246 var RDS5 = /^\/?(?:.|\n)*?(?=\/|$)/;
6247 function removeDotSegments(input) {
6249 while (input.length) {
6250 if (input.match(RDS1)) {
6251 input = input.replace(RDS1, "");
6252 } else if (input.match(RDS2)) {
6253 input = input.replace(RDS2, "/");
6254 } else if (input.match(RDS3)) {
6255 input = input.replace(RDS3, "/");
6257 } else if (input === "." || input === "..") {
6260 var im = input.match(RDS5);
6263 input = input.slice(s.length);
6266 throw new Error("Unexpected dot segment condition");
6270 return output.join("");
6273 function serialize(components) {
6274 var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
6276 var protocol = options.iri ? IRI_PROTOCOL : URI_PROTOCOL;
6278 //find scheme handler
6279 var schemeHandler = SCHEMES[(options.scheme || components.scheme || "").toLowerCase()];
6280 //perform scheme specific serialization
6281 if (schemeHandler && schemeHandler.serialize) schemeHandler.serialize(components, options);
6282 if (components.host) {
6283 //if host component is an IPv6 address
6284 if (protocol.IPV6ADDRESS.test(components.host)) {}
6285 //TODO: normalize IPv6 address as per RFC 5952
6287 //if host component is a domain name
6288 else if (options.domainHost || schemeHandler && schemeHandler.domainHost) {
6289 //convert IDN via punycode
6291 components.host = !options.iri ? punycode.toASCII(components.host.replace(protocol.PCT_ENCODED, pctDecChars).toLowerCase()) : punycode.toUnicode(components.host);
6293 components.error = components.error || "Host's domain name can not be converted to " + (!options.iri ? "ASCII" : "Unicode") + " via punycode: " + e;
6297 //normalize encoding
6298 _normalizeComponentEncoding(components, protocol);
6299 if (options.reference !== "suffix" && components.scheme) {
6300 uriTokens.push(components.scheme);
6301 uriTokens.push(":");
6303 var authority = _recomposeAuthority(components, options);
6304 if (authority !== undefined) {
6305 if (options.reference !== "suffix") {
6306 uriTokens.push("//");
6308 uriTokens.push(authority);
6309 if (components.path && components.path.charAt(0) !== "/") {
6310 uriTokens.push("/");
6313 if (components.path !== undefined) {
6314 var s = components.path;
6315 if (!options.absolutePath && (!schemeHandler || !schemeHandler.absolutePath)) {
6316 s = removeDotSegments(s);
6318 if (authority === undefined) {
6319 s = s.replace(/^\/\//, "/%2F"); //don't allow the path to start with "//"
6323 if (components.query !== undefined) {
6324 uriTokens.push("?");
6325 uriTokens.push(components.query);
6327 if (components.fragment !== undefined) {
6328 uriTokens.push("#");
6329 uriTokens.push(components.fragment);
6331 return uriTokens.join(""); //merge tokens into a string
6334 function resolveComponents(base, relative) {
6335 var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
6336 var skipNormalization = arguments[3];
6339 if (!skipNormalization) {
6340 base = parse(serialize(base, options), options); //normalize base components
6341 relative = parse(serialize(relative, options), options); //normalize relative components
6343 options = options || {};
6344 if (!options.tolerant && relative.scheme) {
6345 target.scheme = relative.scheme;
6346 //target.authority = relative.authority;
6347 target.userinfo = relative.userinfo;
6348 target.host = relative.host;
6349 target.port = relative.port;
6350 target.path = removeDotSegments(relative.path || "");
6351 target.query = relative.query;
6353 if (relative.userinfo !== undefined || relative.host !== undefined || relative.port !== undefined) {
6354 //target.authority = relative.authority;
6355 target.userinfo = relative.userinfo;
6356 target.host = relative.host;
6357 target.port = relative.port;
6358 target.path = removeDotSegments(relative.path || "");
6359 target.query = relative.query;
6361 if (!relative.path) {
6362 target.path = base.path;
6363 if (relative.query !== undefined) {
6364 target.query = relative.query;
6366 target.query = base.query;
6369 if (relative.path.charAt(0) === "/") {
6370 target.path = removeDotSegments(relative.path);
6372 if ((base.userinfo !== undefined || base.host !== undefined || base.port !== undefined) && !base.path) {
6373 target.path = "/" + relative.path;
6374 } else if (!base.path) {
6375 target.path = relative.path;
6377 target.path = base.path.slice(0, base.path.lastIndexOf("/") + 1) + relative.path;
6379 target.path = removeDotSegments(target.path);
6381 target.query = relative.query;
6383 //target.authority = base.authority;
6384 target.userinfo = base.userinfo;
6385 target.host = base.host;
6386 target.port = base.port;
6388 target.scheme = base.scheme;
6390 target.fragment = relative.fragment;
6394 function resolve(baseURI, relativeURI, options) {
6395 var schemelessOptions = assign({ scheme: 'null' }, options);
6396 return serialize(resolveComponents(parse(baseURI, schemelessOptions), parse(relativeURI, schemelessOptions), schemelessOptions, true), schemelessOptions);
6399 function normalize(uri, options) {
6400 if (typeof uri === "string") {
6401 uri = serialize(parse(uri, options), options);
6402 } else if (typeOf(uri) === "object") {
6403 uri = parse(serialize(uri, options), options);
6408 function equal(uriA, uriB, options) {
6409 if (typeof uriA === "string") {
6410 uriA = serialize(parse(uriA, options), options);
6411 } else if (typeOf(uriA) === "object") {
6412 uriA = serialize(uriA, options);
6414 if (typeof uriB === "string") {
6415 uriB = serialize(parse(uriB, options), options);
6416 } else if (typeOf(uriB) === "object") {
6417 uriB = serialize(uriB, options);
6419 return uriA === uriB;
6422 function escapeComponent(str, options) {
6423 return str && str.toString().replace(!options || !options.iri ? URI_PROTOCOL.ESCAPE : IRI_PROTOCOL.ESCAPE, pctEncChar);
6426 function unescapeComponent(str, options) {
6427 return str && str.toString().replace(!options || !options.iri ? URI_PROTOCOL.PCT_ENCODED : IRI_PROTOCOL.PCT_ENCODED, pctDecChars);
6433 parse: function parse(components, options) {
6434 //report missing host
6435 if (!components.host) {
6436 components.error = components.error || "HTTP URIs must have a host.";
6440 serialize: function serialize(components, options) {
6441 var secure = String(components.scheme).toLowerCase() === "https";
6442 //normalize the default port
6443 if (components.port === (secure ? 443 : 80) || components.port === "") {
6444 components.port = undefined;
6446 //normalize the empty path
6447 if (!components.path) {
6448 components.path = "/";
6450 //NOTE: We do not parse query strings for HTTP URIs
6451 //as WWW Form Url Encoded query strings are part of the HTML4+ spec,
6452 //and not the HTTP spec.
6459 domainHost: handler.domainHost,
6460 parse: handler.parse,
6461 serialize: handler.serialize
6464 function isSecure(wsComponents) {
6465 return typeof wsComponents.secure === 'boolean' ? wsComponents.secure : String(wsComponents.scheme).toLowerCase() === "wss";
6471 parse: function parse(components, options) {
6472 var wsComponents = components;
6473 //indicate if the secure flag is set
6474 wsComponents.secure = isSecure(wsComponents);
6475 //construct resouce name
6476 wsComponents.resourceName = (wsComponents.path || '/') + (wsComponents.query ? '?' + wsComponents.query : '');
6477 wsComponents.path = undefined;
6478 wsComponents.query = undefined;
6479 return wsComponents;
6481 serialize: function serialize(wsComponents, options) {
6482 //normalize the default port
6483 if (wsComponents.port === (isSecure(wsComponents) ? 443 : 80) || wsComponents.port === "") {
6484 wsComponents.port = undefined;
6486 //ensure scheme matches secure flag
6487 if (typeof wsComponents.secure === 'boolean') {
6488 wsComponents.scheme = wsComponents.secure ? 'wss' : 'ws';
6489 wsComponents.secure = undefined;
6491 //reconstruct path from resource name
6492 if (wsComponents.resourceName) {
6493 var _wsComponents$resourc = wsComponents.resourceName.split('?'),
6494 _wsComponents$resourc2 = slicedToArray(_wsComponents$resourc, 2),
6495 path = _wsComponents$resourc2[0],
6496 query = _wsComponents$resourc2[1];
6498 wsComponents.path = path && path !== '/' ? path : undefined;
6499 wsComponents.query = query;
6500 wsComponents.resourceName = undefined;
6502 //forbid fragment component
6503 wsComponents.fragment = undefined;
6504 return wsComponents;
6510 domainHost: handler$2.domainHost,
6511 parse: handler$2.parse,
6512 serialize: handler$2.serialize
6518 var UNRESERVED$$ = "[A-Za-z0-9\\-\\.\\_\\~" + (isIRI ? "\\xA0-\\u200D\\u2010-\\u2029\\u202F-\\uD7FF\\uF900-\\uFDCF\\uFDF0-\\uFFEF" : "") + "]";
6519 var HEXDIG$$ = "[0-9A-Fa-f]"; //case-insensitive
6520 var PCT_ENCODED$ = subexp(subexp("%[EFef]" + HEXDIG$$ + "%" + HEXDIG$$ + HEXDIG$$ + "%" + HEXDIG$$ + HEXDIG$$) + "|" + subexp("%[89A-Fa-f]" + HEXDIG$$ + "%" + HEXDIG$$ + HEXDIG$$) + "|" + subexp("%" + HEXDIG$$ + HEXDIG$$)); //expanded
6521 //RFC 5322, except these symbols as per RFC 6068: @ : / ? # [ ] & ; =
6522 //const ATEXT$$ = "[A-Za-z0-9\\!\\#\\$\\%\\&\\'\\*\\+\\-\\/\\=\\?\\^\\_\\`\\{\\|\\}\\~]";
6523 //const WSP$$ = "[\\x20\\x09]";
6524 //const OBS_QTEXT$$ = "[\\x01-\\x08\\x0B\\x0C\\x0E-\\x1F\\x7F]"; //(%d1-8 / %d11-12 / %d14-31 / %d127)
6525 //const QTEXT$$ = merge("[\\x21\\x23-\\x5B\\x5D-\\x7E]", OBS_QTEXT$$); //%d33 / %d35-91 / %d93-126 / obs-qtext
6526 //const VCHAR$$ = "[\\x21-\\x7E]";
6527 //const WSP$$ = "[\\x20\\x09]";
6528 //const OBS_QP$ = subexp("\\\\" + merge("[\\x00\\x0D\\x0A]", OBS_QTEXT$$)); //%d0 / CR / LF / obs-qtext
6529 //const FWS$ = subexp(subexp(WSP$$ + "*" + "\\x0D\\x0A") + "?" + WSP$$ + "+");
6530 //const QUOTED_PAIR$ = subexp(subexp("\\\\" + subexp(VCHAR$$ + "|" + WSP$$)) + "|" + OBS_QP$);
6531 //const QUOTED_STRING$ = subexp('\\"' + subexp(FWS$ + "?" + QCONTENT$) + "*" + FWS$ + "?" + '\\"');
6532 var ATEXT$$ = "[A-Za-z0-9\\!\\$\\%\\'\\*\\+\\-\\^\\_\\`\\{\\|\\}\\~]";
6533 var QTEXT$$ = "[\\!\\$\\%\\'\\(\\)\\*\\+\\,\\-\\.0-9\\<\\>A-Z\\x5E-\\x7E]";
6534 var VCHAR$$ = merge(QTEXT$$, "[\\\"\\\\]");
6535 var SOME_DELIMS$$ = "[\\!\\$\\'\\(\\)\\*\\+\\,\\;\\:\\@]";
6536 var UNRESERVED = new RegExp(UNRESERVED$$, "g");
6537 var PCT_ENCODED = new RegExp(PCT_ENCODED$, "g");
6538 var NOT_LOCAL_PART = new RegExp(merge("[^]", ATEXT$$, "[\\.]", '[\\"]', VCHAR$$), "g");
6539 var NOT_HFNAME = new RegExp(merge("[^]", UNRESERVED$$, SOME_DELIMS$$), "g");
6540 var NOT_HFVALUE = NOT_HFNAME;
6541 function decodeUnreserved(str) {
6542 var decStr = pctDecChars(str);
6543 return !decStr.match(UNRESERVED) ? str : decStr;
6547 parse: function parse$$1(components, options) {
6548 var mailtoComponents = components;
6549 var to = mailtoComponents.to = mailtoComponents.path ? mailtoComponents.path.split(",") : [];
6550 mailtoComponents.path = undefined;
6551 if (mailtoComponents.query) {
6552 var unknownHeaders = false;
6554 var hfields = mailtoComponents.query.split("&");
6555 for (var x = 0, xl = hfields.length; x < xl; ++x) {
6556 var hfield = hfields[x].split("=");
6557 switch (hfield[0]) {
6559 var toAddrs = hfield[1].split(",");
6560 for (var _x = 0, _xl = toAddrs.length; _x < _xl; ++_x) {
6561 to.push(toAddrs[_x]);
6565 mailtoComponents.subject = unescapeComponent(hfield[1], options);
6568 mailtoComponents.body = unescapeComponent(hfield[1], options);
6571 unknownHeaders = true;
6572 headers[unescapeComponent(hfield[0], options)] = unescapeComponent(hfield[1], options);
6576 if (unknownHeaders) mailtoComponents.headers = headers;
6578 mailtoComponents.query = undefined;
6579 for (var _x2 = 0, _xl2 = to.length; _x2 < _xl2; ++_x2) {
6580 var addr = to[_x2].split("@");
6581 addr[0] = unescapeComponent(addr[0]);
6582 if (!options.unicodeSupport) {
6583 //convert Unicode IDN -> ASCII IDN
6585 addr[1] = punycode.toASCII(unescapeComponent(addr[1], options).toLowerCase());
6587 mailtoComponents.error = mailtoComponents.error || "Email address's domain name can not be converted to ASCII via punycode: " + e;
6590 addr[1] = unescapeComponent(addr[1], options).toLowerCase();
6592 to[_x2] = addr.join("@");
6594 return mailtoComponents;
6596 serialize: function serialize$$1(mailtoComponents, options) {
6597 var components = mailtoComponents;
6598 var to = toArray(mailtoComponents.to);
6600 for (var x = 0, xl = to.length; x < xl; ++x) {
6601 var toAddr = String(to[x]);
6602 var atIdx = toAddr.lastIndexOf("@");
6603 var localPart = toAddr.slice(0, atIdx).replace(PCT_ENCODED, decodeUnreserved).replace(PCT_ENCODED, toUpperCase).replace(NOT_LOCAL_PART, pctEncChar);
6604 var domain = toAddr.slice(atIdx + 1);
6605 //convert IDN via punycode
6607 domain = !options.iri ? punycode.toASCII(unescapeComponent(domain, options).toLowerCase()) : punycode.toUnicode(domain);
6609 components.error = components.error || "Email address's domain name can not be converted to " + (!options.iri ? "ASCII" : "Unicode") + " via punycode: " + e;
6611 to[x] = localPart + "@" + domain;
6613 components.path = to.join(",");
6615 var headers = mailtoComponents.headers = mailtoComponents.headers || {};
6616 if (mailtoComponents.subject) headers["subject"] = mailtoComponents.subject;
6617 if (mailtoComponents.body) headers["body"] = mailtoComponents.body;
6619 for (var name in headers) {
6620 if (headers[name] !== O[name]) {
6621 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));
6624 if (fields.length) {
6625 components.query = fields.join("&");
6631 var URN_PARSE = /^([^\:]+)\:(.*)/;
6635 parse: function parse$$1(components, options) {
6636 var matches = components.path && components.path.match(URN_PARSE);
6637 var urnComponents = components;
6639 var scheme = options.scheme || urnComponents.scheme || "urn";
6640 var nid = matches[1].toLowerCase();
6641 var nss = matches[2];
6642 var urnScheme = scheme + ":" + (options.nid || nid);
6643 var schemeHandler = SCHEMES[urnScheme];
6644 urnComponents.nid = nid;
6645 urnComponents.nss = nss;
6646 urnComponents.path = undefined;
6647 if (schemeHandler) {
6648 urnComponents = schemeHandler.parse(urnComponents, options);
6651 urnComponents.error = urnComponents.error || "URN can not be parsed.";
6653 return urnComponents;
6655 serialize: function serialize$$1(urnComponents, options) {
6656 var scheme = options.scheme || urnComponents.scheme || "urn";
6657 var nid = urnComponents.nid;
6658 var urnScheme = scheme + ":" + (options.nid || nid);
6659 var schemeHandler = SCHEMES[urnScheme];
6660 if (schemeHandler) {
6661 urnComponents = schemeHandler.serialize(urnComponents, options);
6663 var uriComponents = urnComponents;
6664 var nss = urnComponents.nss;
6665 uriComponents.path = (nid || options.nid) + ":" + nss;
6666 return uriComponents;
6670 var UUID = /^[0-9A-Fa-f]{8}(?:\-[0-9A-Fa-f]{4}){3}\-[0-9A-Fa-f]{12}$/;
6674 parse: function parse(urnComponents, options) {
6675 var uuidComponents = urnComponents;
6676 uuidComponents.uuid = uuidComponents.nss;
6677 uuidComponents.nss = undefined;
6678 if (!options.tolerant && (!uuidComponents.uuid || !uuidComponents.uuid.match(UUID))) {
6679 uuidComponents.error = uuidComponents.error || "UUID is not valid.";
6681 return uuidComponents;
6683 serialize: function serialize(uuidComponents, options) {
6684 var urnComponents = uuidComponents;
6686 urnComponents.nss = (uuidComponents.uuid || "").toLowerCase();
6687 return urnComponents;
6691 SCHEMES[handler.scheme] = handler;
6692 SCHEMES[handler$1.scheme] = handler$1;
6693 SCHEMES[handler$2.scheme] = handler$2;
6694 SCHEMES[handler$3.scheme] = handler$3;
6695 SCHEMES[handler$4.scheme] = handler$4;
6696 SCHEMES[handler$5.scheme] = handler$5;
6697 SCHEMES[handler$6.scheme] = handler$6;
6699 exports.SCHEMES = SCHEMES;
6700 exports.pctEncChar = pctEncChar;
6701 exports.pctDecChars = pctDecChars;
6702 exports.parse = parse;
6703 exports.removeDotSegments = removeDotSegments;
6704 exports.serialize = serialize;
6705 exports.resolveComponents = resolveComponents;
6706 exports.resolve = resolve;
6707 exports.normalize = normalize;
6708 exports.equal = equal;
6709 exports.escapeComponent = escapeComponent;
6710 exports.unescapeComponent = unescapeComponent;
6712 Object.defineProperty(exports, '__esModule', { value: true });
6717 },{}],"ajv":[function(require,module,exports){
6720 var compileSchema = require('./compile')
6721 , resolve = require('./compile/resolve')
6722 , Cache = require('./cache')
6723 , SchemaObject = require('./compile/schema_obj')
6724 , stableStringify = require('fast-json-stable-stringify')
6725 , formats = require('./compile/formats')
6726 , rules = require('./compile/rules')
6727 , $dataMetaSchema = require('./data')
6728 , util = require('./compile/util');
6730 module.exports = Ajv;
6732 Ajv.prototype.validate = validate;
6733 Ajv.prototype.compile = compile;
6734 Ajv.prototype.addSchema = addSchema;
6735 Ajv.prototype.addMetaSchema = addMetaSchema;
6736 Ajv.prototype.validateSchema = validateSchema;
6737 Ajv.prototype.getSchema = getSchema;
6738 Ajv.prototype.removeSchema = removeSchema;
6739 Ajv.prototype.addFormat = addFormat;
6740 Ajv.prototype.errorsText = errorsText;
6742 Ajv.prototype._addSchema = _addSchema;
6743 Ajv.prototype._compile = _compile;
6745 Ajv.prototype.compileAsync = require('./compile/async');
6746 var customKeyword = require('./keyword');
6747 Ajv.prototype.addKeyword = customKeyword.add;
6748 Ajv.prototype.getKeyword = customKeyword.get;
6749 Ajv.prototype.removeKeyword = customKeyword.remove;
6750 Ajv.prototype.validateKeyword = customKeyword.validate;
6752 var errorClasses = require('./compile/error_classes');
6753 Ajv.ValidationError = errorClasses.Validation;
6754 Ajv.MissingRefError = errorClasses.MissingRef;
6755 Ajv.$dataMetaSchema = $dataMetaSchema;
6757 var META_SCHEMA_ID = 'http://json-schema.org/draft-07/schema';
6759 var META_IGNORE_OPTIONS = [ 'removeAdditional', 'useDefaults', 'coerceTypes', 'strictDefaults' ];
6760 var META_SUPPORT_DATA = ['/properties'];
6763 * Creates validator instance.
6764 * Usage: `Ajv(opts)`
6765 * @param {Object} opts optional options
6766 * @return {Object} ajv instance
6768 function Ajv(opts) {
6769 if (!(this instanceof Ajv)) return new Ajv(opts);
6770 opts = this._opts = util.copy(opts) || {};
6774 this._fragments = {};
6775 this._formats = formats(opts.format);
6777 this._cache = opts.cache || new Cache;
6778 this._loadingSchemas = {};
6779 this._compilations = [];
6780 this.RULES = rules();
6781 this._getId = chooseGetId(opts);
6783 opts.loopRequired = opts.loopRequired || Infinity;
6784 if (opts.errorDataPath == 'property') opts._errorDataPathProperty = true;
6785 if (opts.serialize === undefined) opts.serialize = stableStringify;
6786 this._metaOpts = getMetaSchemaOptions(this);
6788 if (opts.formats) addInitialFormats(this);
6789 if (opts.keywords) addInitialKeywords(this);
6790 addDefaultMetaSchema(this);
6791 if (typeof opts.meta == 'object') this.addMetaSchema(opts.meta);
6792 if (opts.nullable) this.addKeyword('nullable', {metaSchema: {type: 'boolean'}});
6793 addInitialSchemas(this);
6799 * Validate data using schema
6800 * 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.
6802 * @param {String|Object} schemaKeyRef key, ref or schema object
6803 * @param {Any} data to be validated
6804 * @return {Boolean} validation result. Errors from the last validation will be available in `ajv.errors` (and also in compiled schema: `schema.errors`).
6806 function validate(schemaKeyRef, data) {
6808 if (typeof schemaKeyRef == 'string') {
6809 v = this.getSchema(schemaKeyRef);
6810 if (!v) throw new Error('no schema with key or ref "' + schemaKeyRef + '"');
6812 var schemaObj = this._addSchema(schemaKeyRef);
6813 v = schemaObj.validate || this._compile(schemaObj);
6816 var valid = v(data);
6817 if (v.$async !== true) this.errors = v.errors;
6823 * Create validating function for passed schema.
6825 * @param {Object} schema schema object
6826 * @param {Boolean} _meta true if schema is a meta-schema. Used internally to compile meta schemas of custom keywords.
6827 * @return {Function} validating function
6829 function compile(schema, _meta) {
6830 var schemaObj = this._addSchema(schema, undefined, _meta);
6831 return schemaObj.validate || this._compile(schemaObj);
6836 * Adds schema to the instance.
6838 * @param {Object|Array} schema schema or array of schemas. If array is passed, `key` and other parameters will be ignored.
6839 * @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`.
6840 * @param {Boolean} _skipValidation true to skip schema validation. Used internally, option validateSchema should be used instead.
6841 * @param {Boolean} _meta true if schema is a meta-schema. Used internally, addMetaSchema should be used instead.
6842 * @return {Ajv} this for method chaining
6844 function addSchema(schema, key, _skipValidation, _meta) {
6845 if (Array.isArray(schema)){
6846 for (var i=0; i<schema.length; i++) this.addSchema(schema[i], undefined, _skipValidation, _meta);
6849 var id = this._getId(schema);
6850 if (id !== undefined && typeof id != 'string')
6851 throw new Error('schema id must be string');
6852 key = resolve.normalizeId(key || id);
6853 checkUnique(this, key);
6854 this._schemas[key] = this._addSchema(schema, _skipValidation, _meta, true);
6860 * Add schema that will be used to validate other schemas
6861 * options in META_IGNORE_OPTIONS are alway set to false
6863 * @param {Object} schema schema object
6864 * @param {String} key optional schema key
6865 * @param {Boolean} skipValidation true to skip schema validation, can be used to override validateSchema option for meta-schema
6866 * @return {Ajv} this for method chaining
6868 function addMetaSchema(schema, key, skipValidation) {
6869 this.addSchema(schema, key, skipValidation, true);
6877 * @param {Object} schema schema to validate
6878 * @param {Boolean} throwOrLogError pass true to throw (or log) an error if invalid
6879 * @return {Boolean} true if schema is valid
6881 function validateSchema(schema, throwOrLogError) {
6882 var $schema = schema.$schema;
6883 if ($schema !== undefined && typeof $schema != 'string')
6884 throw new Error('$schema must be a string');
6885 $schema = $schema || this._opts.defaultMeta || defaultMeta(this);
6887 this.logger.warn('meta-schema not available');
6891 var valid = this.validate($schema, schema);
6892 if (!valid && throwOrLogError) {
6893 var message = 'schema is invalid: ' + this.errorsText();
6894 if (this._opts.validateSchema == 'log') this.logger.error(message);
6895 else throw new Error(message);
6901 function defaultMeta(self) {
6902 var meta = self._opts.meta;
6903 self._opts.defaultMeta = typeof meta == 'object'
6904 ? self._getId(meta) || meta
6905 : self.getSchema(META_SCHEMA_ID)
6908 return self._opts.defaultMeta;
6913 * Get compiled schema from the instance by `key` or `ref`.
6915 * @param {String} keyRef `key` that was passed to `addSchema` or full schema reference (`schema.id` or resolved id).
6916 * @return {Function} schema validating function (with property `schema`).
6918 function getSchema(keyRef) {
6919 var schemaObj = _getSchemaObj(this, keyRef);
6920 switch (typeof schemaObj) {
6921 case 'object': return schemaObj.validate || this._compile(schemaObj);
6922 case 'string': return this.getSchema(schemaObj);
6923 case 'undefined': return _getSchemaFragment(this, keyRef);
6928 function _getSchemaFragment(self, ref) {
6929 var res = resolve.schema.call(self, { schema: {} }, ref);
6931 var schema = res.schema
6933 , baseId = res.baseId;
6934 var v = compileSchema.call(self, schema, root, undefined, baseId);
6935 self._fragments[ref] = new SchemaObject({
6948 function _getSchemaObj(self, keyRef) {
6949 keyRef = resolve.normalizeId(keyRef);
6950 return self._schemas[keyRef] || self._refs[keyRef] || self._fragments[keyRef];
6955 * Remove cached schema(s).
6956 * If no parameter is passed all schemas but meta-schemas are removed.
6957 * If RegExp is passed all schemas with key/id matching pattern but meta-schemas are removed.
6958 * Even if schema is referenced by other schemas it still can be removed as other schemas have local references.
6960 * @param {String|Object|RegExp} schemaKeyRef key, ref, pattern to match key/ref or schema object
6961 * @return {Ajv} this for method chaining
6963 function removeSchema(schemaKeyRef) {
6964 if (schemaKeyRef instanceof RegExp) {
6965 _removeAllSchemas(this, this._schemas, schemaKeyRef);
6966 _removeAllSchemas(this, this._refs, schemaKeyRef);
6969 switch (typeof schemaKeyRef) {
6971 _removeAllSchemas(this, this._schemas);
6972 _removeAllSchemas(this, this._refs);
6973 this._cache.clear();
6976 var schemaObj = _getSchemaObj(this, schemaKeyRef);
6977 if (schemaObj) this._cache.del(schemaObj.cacheKey);
6978 delete this._schemas[schemaKeyRef];
6979 delete this._refs[schemaKeyRef];
6982 var serialize = this._opts.serialize;
6983 var cacheKey = serialize ? serialize(schemaKeyRef) : schemaKeyRef;
6984 this._cache.del(cacheKey);
6985 var id = this._getId(schemaKeyRef);
6987 id = resolve.normalizeId(id);
6988 delete this._schemas[id];
6989 delete this._refs[id];
6996 function _removeAllSchemas(self, schemas, regex) {
6997 for (var keyRef in schemas) {
6998 var schemaObj = schemas[keyRef];
6999 if (!schemaObj.meta && (!regex || regex.test(keyRef))) {
7000 self._cache.del(schemaObj.cacheKey);
7001 delete schemas[keyRef];
7008 function _addSchema(schema, skipValidation, meta, shouldAddSchema) {
7009 if (typeof schema != 'object' && typeof schema != 'boolean')
7010 throw new Error('schema should be object or boolean');
7011 var serialize = this._opts.serialize;
7012 var cacheKey = serialize ? serialize(schema) : schema;
7013 var cached = this._cache.get(cacheKey);
7014 if (cached) return cached;
7016 shouldAddSchema = shouldAddSchema || this._opts.addUsedSchema !== false;
7018 var id = resolve.normalizeId(this._getId(schema));
7019 if (id && shouldAddSchema) checkUnique(this, id);
7021 var willValidate = this._opts.validateSchema !== false && !skipValidation;
7023 if (willValidate && !(recursiveMeta = id && id == resolve.normalizeId(schema.$schema)))
7024 this.validateSchema(schema, true);
7026 var localRefs = resolve.ids.call(this, schema);
7028 var schemaObj = new SchemaObject({
7031 localRefs: localRefs,
7036 if (id[0] != '#' && shouldAddSchema) this._refs[id] = schemaObj;
7037 this._cache.put(cacheKey, schemaObj);
7039 if (willValidate && recursiveMeta) this.validateSchema(schema, true);
7046 function _compile(schemaObj, root) {
7047 if (schemaObj.compiling) {
7048 schemaObj.validate = callValidate;
7049 callValidate.schema = schemaObj.schema;
7050 callValidate.errors = null;
7051 callValidate.root = root ? root : callValidate;
7052 if (schemaObj.schema.$async === true)
7053 callValidate.$async = true;
7054 return callValidate;
7056 schemaObj.compiling = true;
7059 if (schemaObj.meta) {
7060 currentOpts = this._opts;
7061 this._opts = this._metaOpts;
7065 try { v = compileSchema.call(this, schemaObj.schema, root, schemaObj.localRefs); }
7067 delete schemaObj.validate;
7071 schemaObj.compiling = false;
7072 if (schemaObj.meta) this._opts = currentOpts;
7075 schemaObj.validate = v;
7076 schemaObj.refs = v.refs;
7077 schemaObj.refVal = v.refVal;
7078 schemaObj.root = v.root;
7082 /* @this {*} - custom context, see passContext option */
7083 function callValidate() {
7084 /* jshint validthis: true */
7085 var _validate = schemaObj.validate;
7086 var result = _validate.apply(this, arguments);
7087 callValidate.errors = _validate.errors;
7093 function chooseGetId(opts) {
7094 switch (opts.schemaId) {
7095 case 'auto': return _get$IdOrId;
7096 case 'id': return _getId;
7097 default: return _get$Id;
7102 function _getId(schema) {
7103 if (schema.$id) this.logger.warn('schema $id ignored', schema.$id);
7108 function _get$Id(schema) {
7109 if (schema.id) this.logger.warn('schema id ignored', schema.id);
7114 function _get$IdOrId(schema) {
7115 if (schema.$id && schema.id && schema.$id != schema.id)
7116 throw new Error('schema $id is different from id');
7117 return schema.$id || schema.id;
7122 * Convert array of error message objects to string
7124 * @param {Array<Object>} errors optional array of validation errors, if not passed errors from the instance are used.
7125 * @param {Object} options optional options with properties `separator` and `dataVar`.
7126 * @return {String} human readable string with all errors descriptions
7128 function errorsText(errors, options) {
7129 errors = errors || this.errors;
7130 if (!errors) return 'No errors';
7131 options = options || {};
7132 var separator = options.separator === undefined ? ', ' : options.separator;
7133 var dataVar = options.dataVar === undefined ? 'data' : options.dataVar;
7136 for (var i=0; i<errors.length; i++) {
7138 if (e) text += dataVar + e.dataPath + ' ' + e.message + separator;
7140 return text.slice(0, -separator.length);
7147 * @param {String} name format name
7148 * @param {String|RegExp|Function} format string is converted to RegExp; function should return boolean (true when valid)
7149 * @return {Ajv} this for method chaining
7151 function addFormat(name, format) {
7152 if (typeof format == 'string') format = new RegExp(format);
7153 this._formats[name] = format;
7158 function addDefaultMetaSchema(self) {
7160 if (self._opts.$data) {
7161 $dataSchema = require('./refs/data.json');
7162 self.addMetaSchema($dataSchema, $dataSchema.$id, true);
7164 if (self._opts.meta === false) return;
7165 var metaSchema = require('./refs/json-schema-draft-07.json');
7166 if (self._opts.$data) metaSchema = $dataMetaSchema(metaSchema, META_SUPPORT_DATA);
7167 self.addMetaSchema(metaSchema, META_SCHEMA_ID, true);
7168 self._refs['http://json-schema.org/schema'] = META_SCHEMA_ID;
7172 function addInitialSchemas(self) {
7173 var optsSchemas = self._opts.schemas;
7174 if (!optsSchemas) return;
7175 if (Array.isArray(optsSchemas)) self.addSchema(optsSchemas);
7176 else for (var key in optsSchemas) self.addSchema(optsSchemas[key], key);
7180 function addInitialFormats(self) {
7181 for (var name in self._opts.formats) {
7182 var format = self._opts.formats[name];
7183 self.addFormat(name, format);
7188 function addInitialKeywords(self) {
7189 for (var name in self._opts.keywords) {
7190 var keyword = self._opts.keywords[name];
7191 self.addKeyword(name, keyword);
7196 function checkUnique(self, id) {
7197 if (self._schemas[id] || self._refs[id])
7198 throw new Error('schema with key or id "' + id + '" already exists');
7202 function getMetaSchemaOptions(self) {
7203 var metaOpts = util.copy(self._opts);
7204 for (var i=0; i<META_IGNORE_OPTIONS.length; i++)
7205 delete metaOpts[META_IGNORE_OPTIONS[i]];
7210 function setLogger(self) {
7211 var logger = self._opts.logger;
7212 if (logger === false) {
7213 self.logger = {log: noop, warn: noop, error: noop};
7215 if (logger === undefined) logger = console;
7216 if (!(typeof logger == 'object' && logger.log && logger.warn && logger.error))
7217 throw new Error('logger must implement log, warn and error methods');
7218 self.logger = logger;
7225 },{"./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")