source: frontend/node_modules/ajv/dist/ajv.bundle.js

Last change on this file was 9af201e, checked in by MBK <marija.karapandzova@…>, 12 days ago

Fix frontend appearance

  • Property mode set to 100644
File size: 266.8 KB
Line 
1(function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.Ajv = f()}})(function(){var define,module,exports;return (function(){function r(e,n,t){function o(i,f){if(!n[i]){if(!e[i]){var c="function"==typeof require&&require;if(!f&&c)return c(i,!0);if(u)return u(i,!0);var a=new Error("Cannot find module '"+i+"'");throw a.code="MODULE_NOT_FOUND",a}var p=n[i]={exports:{}};e[i][0].call(p.exports,function(r){var n=e[i][1][r];return o(n||r)},p,p.exports,r,e,n,t)}return n[i].exports}for(var u="function"==typeof require&&require,i=0;i<t.length;i++)o(t[i]);return o}return r})()({1:[function(require,module,exports){
2'use strict';
3
4
5var Cache = module.exports = function Cache() {
6 this._cache = {};
7};
8
9
10Cache.prototype.put = function Cache_put(key, value) {
11 this._cache[key] = value;
12};
13
14
15Cache.prototype.get = function Cache_get(key) {
16 return this._cache[key];
17};
18
19
20Cache.prototype.del = function Cache_del(key) {
21 delete this._cache[key];
22};
23
24
25Cache.prototype.clear = function Cache_clear() {
26 this._cache = {};
27};
28
29},{}],2:[function(require,module,exports){
30'use strict';
31
32var MissingRefError = require('./error_classes').MissingRef;
33
34module.exports = compileAsync;
35
36
37/**
38 * Creates validating function for passed schema with asynchronous loading of missing schemas.
39 * `loadSchema` option should be a function that accepts schema uri and returns promise that resolves with the schema.
40 * @this Ajv
41 * @param {Object} schema schema object
42 * @param {Boolean} meta optional true to compile meta-schema; this parameter can be skipped
43 * @param {Function} callback an optional node-style callback, it is called with 2 parameters: error (or null) and validating function.
44 * @return {Promise} promise that resolves with a validating function.
45 */
46function compileAsync(schema, meta, callback) {
47 /* eslint no-shadow: 0 */
48 /* global Promise */
49 /* jshint validthis: true */
50 var self = this;
51 if (typeof this._opts.loadSchema != 'function')
52 throw new Error('options.loadSchema should be a function');
53
54 if (typeof meta == 'function') {
55 callback = meta;
56 meta = undefined;
57 }
58
59 var p = loadMetaSchemaOf(schema).then(function () {
60 var schemaObj = self._addSchema(schema, undefined, meta);
61 return schemaObj.validate || _compileAsync(schemaObj);
62 });
63
64 if (callback) {
65 p.then(
66 function(v) { callback(null, v); },
67 callback
68 );
69 }
70
71 return p;
72
73
74 function loadMetaSchemaOf(sch) {
75 var $schema = sch.$schema;
76 return $schema && !self.getSchema($schema)
77 ? compileAsync.call(self, { $ref: $schema }, true)
78 : Promise.resolve();
79 }
80
81
82 function _compileAsync(schemaObj) {
83 try { return self._compile(schemaObj); }
84 catch(e) {
85 if (e instanceof MissingRefError) return loadMissingSchema(e);
86 throw e;
87 }
88
89
90 function loadMissingSchema(e) {
91 var ref = e.missingSchema;
92 if (added(ref)) throw new Error('Schema ' + ref + ' is loaded but ' + e.missingRef + ' cannot be resolved');
93
94 var schemaPromise = self._loadingSchemas[ref];
95 if (!schemaPromise) {
96 schemaPromise = self._loadingSchemas[ref] = self._opts.loadSchema(ref);
97 schemaPromise.then(removePromise, removePromise);
98 }
99
100 return schemaPromise.then(function (sch) {
101 if (!added(ref)) {
102 return loadMetaSchemaOf(sch).then(function () {
103 if (!added(ref)) self.addSchema(sch, ref, undefined, meta);
104 });
105 }
106 }).then(function() {
107 return _compileAsync(schemaObj);
108 });
109
110 function removePromise() {
111 delete self._loadingSchemas[ref];
112 }
113
114 function added(ref) {
115 return self._refs[ref] || self._schemas[ref];
116 }
117 }
118 }
119}
120
121},{"./error_classes":3}],3:[function(require,module,exports){
122'use strict';
123
124var resolve = require('./resolve');
125
126module.exports = {
127 Validation: errorSubclass(ValidationError),
128 MissingRef: errorSubclass(MissingRefError)
129};
130
131
132function ValidationError(errors) {
133 this.message = 'validation failed';
134 this.errors = errors;
135 this.ajv = this.validation = true;
136}
137
138
139MissingRefError.message = function (baseId, ref) {
140 return 'can\'t resolve reference ' + ref + ' from id ' + baseId;
141};
142
143
144function MissingRefError(baseId, ref, message) {
145 this.message = message || MissingRefError.message(baseId, ref);
146 this.missingRef = resolve.url(baseId, ref);
147 this.missingSchema = resolve.normalizeId(resolve.fullPath(this.missingRef));
148}
149
150
151function errorSubclass(Subclass) {
152 Subclass.prototype = Object.create(Error.prototype);
153 Subclass.prototype.constructor = Subclass;
154 return Subclass;
155}
156
157},{"./resolve":6}],4:[function(require,module,exports){
158'use strict';
159
160var util = require('./util');
161
162var DATE = /^(\d\d\d\d)-(\d\d)-(\d\d)$/;
163var DAYS = [0,31,28,31,30,31,30,31,31,30,31,30,31];
164var TIME = /^(\d\d):(\d\d):(\d\d)(\.\d+)?(z|[+-]\d\d(?::?\d\d)?)?$/i;
165var 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;
166var 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;
167var URIREF = /^(?:[a-z][a-z0-9+\-.]*:)?(?:\/?\/(?:(?:[a-z0-9\-._~!$&'()*+,;=:]|%[0-9a-f]{2})*@)?(?:\[(?:(?:(?:(?:[0-9a-f]{1,4}:){6}|::(?:[0-9a-f]{1,4}:){5}|(?:[0-9a-f]{1,4})?::(?:[0-9a-f]{1,4}:){4}|(?:(?:[0-9a-f]{1,4}:){0,1}[0-9a-f]{1,4})?::(?:[0-9a-f]{1,4}:){3}|(?:(?:[0-9a-f]{1,4}:){0,2}[0-9a-f]{1,4})?::(?:[0-9a-f]{1,4}:){2}|(?:(?:[0-9a-f]{1,4}:){0,3}[0-9a-f]{1,4})?::[0-9a-f]{1,4}:|(?:(?:[0-9a-f]{1,4}:){0,4}[0-9a-f]{1,4})?::)(?:[0-9a-f]{1,4}:[0-9a-f]{1,4}|(?:(?:25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(?:25[0-5]|2[0-4]\d|[01]?\d\d?))|(?:(?:[0-9a-f]{1,4}:){0,5}[0-9a-f]{1,4})?::[0-9a-f]{1,4}|(?:(?:[0-9a-f]{1,4}:){0,6}[0-9a-f]{1,4})?::)|[Vv][0-9a-f]+\.[a-z0-9\-._~!$&'()*+,;=:]+)\]|(?:(?:25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(?:25[0-5]|2[0-4]\d|[01]?\d\d?)|(?:[a-z0-9\-._~!$&'"()*+,;=]|%[0-9a-f]{2})*)(?::\d*)?(?:\/(?:[a-z0-9\-._~!$&'"()*+,;=:@]|%[0-9a-f]{2})*)*|\/(?:(?:[a-z0-9\-._~!$&'"()*+,;=:@]|%[0-9a-f]{2})+(?:\/(?:[a-z0-9\-._~!$&'"()*+,;=:@]|%[0-9a-f]{2})*)*)?|(?:[a-z0-9\-._~!$&'"()*+,;=:@]|%[0-9a-f]{2})+(?:\/(?:[a-z0-9\-._~!$&'"()*+,;=:@]|%[0-9a-f]{2})*)*)?(?:\?(?:[a-z0-9\-._~!$&'"()*+,;=:@/?]|%[0-9a-f]{2})*)?(?:#(?:[a-z0-9\-._~!$&'"()*+,;=:@/?]|%[0-9a-f]{2})*)?$/i;
168// uri-template: https://tools.ietf.org/html/rfc6570
169var URITEMPLATE = /^(?:(?:[^\x00-\x20"'<>%\\^`{|}]|%[0-9a-f]{2})|\{[+#./;?&=,!@|]?(?:[a-z0-9_]|%[0-9a-f]{2})+(?::[1-9][0-9]{0,3}|\*)?(?:,(?:[a-z0-9_]|%[0-9a-f]{2})+(?::[1-9][0-9]{0,3}|\*)?)*\})*$/i;
170// For the source: https://gist.github.com/dperini/729294
171// For test cases: https://mathiasbynens.be/demo/url-regex
172// @todo Delete current URL in favour of the commented out URL rule when this issue is fixed https://github.com/eslint/eslint/issues/7983.
173// var URL = /^(?:(?:https?|ftp):\/\/)(?:\S+(?::\S*)?@)?(?:(?!10(?:\.\d{1,3}){3})(?!127(?:\.\d{1,3}){3})(?!169\.254(?:\.\d{1,3}){2})(?!192\.168(?:\.\d{1,3}){2})(?!172\.(?:1[6-9]|2\d|3[0-1])(?:\.\d{1,3}){2})(?:[1-9]\d?|1\d\d|2[01]\d|22[0-3])(?:\.(?:1?\d{1,2}|2[0-4]\d|25[0-5])){2}(?:\.(?:[1-9]\d?|1\d\d|2[0-4]\d|25[0-4]))|(?:(?:[a-z\u{00a1}-\u{ffff}0-9]+-)*[a-z\u{00a1}-\u{ffff}0-9]+)(?:\.(?:[a-z\u{00a1}-\u{ffff}0-9]+-)*[a-z\u{00a1}-\u{ffff}0-9]+)*(?:\.(?:[a-z\u{00a1}-\u{ffff}]{2,})))(?::\d{2,5})?(?:\/[^\s]*)?$/iu;
174var 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;
175var UUID = /^(?:urn:uuid:)?[0-9a-f]{8}-(?:[0-9a-f]{4}-){3}[0-9a-f]{12}$/i;
176var JSON_POINTER = /^(?:\/(?:[^~/]|~0|~1)*)*$/;
177var JSON_POINTER_URI_FRAGMENT = /^#(?:\/(?:[a-z0-9_\-.!$&'()*+,;:=@]|%[0-9a-f]{2}|~0|~1)*)*$/i;
178var RELATIVE_JSON_POINTER = /^(?:0|[1-9][0-9]*)(?:#|(?:\/(?:[^~/]|~0|~1)*)*)$/;
179
180
181module.exports = formats;
182
183function formats(mode) {
184 mode = mode == 'full' ? 'full' : 'fast';
185 return util.copy(formats[mode]);
186}
187
188
189formats.fast = {
190 // date: http://tools.ietf.org/html/rfc3339#section-5.6
191 date: /^\d\d\d\d-[0-1]\d-[0-3]\d$/,
192 // date-time: http://tools.ietf.org/html/rfc3339#section-5.6
193 time: /^(?:[0-2]\d:[0-5]\d:[0-5]\d|23:59:60)(?:\.\d+)?(?:z|[+-]\d\d(?::?\d\d)?)?$/i,
194 'date-time': /^\d\d\d\d-[0-1]\d-[0-3]\d[t\s](?:[0-2]\d:[0-5]\d:[0-5]\d|23:59:60)(?:\.\d+)?(?:z|[+-]\d\d(?::?\d\d)?)$/i,
195 // uri: https://github.com/mafintosh/is-my-json-valid/blob/master/formats.js
196 uri: /^(?:[a-z][a-z0-9+\-.]*:)(?:\/?\/)?[^\s]*$/i,
197 'uri-reference': /^(?:(?:[a-z][a-z0-9+\-.]*:)?\/?\/)?(?:[^\\\s#][^\s#]*)?(?:#[^\\\s]*)?$/i,
198 'uri-template': URITEMPLATE,
199 url: URL,
200 // email (sources from jsen validator):
201 // http://stackoverflow.com/questions/201323/using-a-regular-expression-to-validate-an-email-address#answer-8829363
202 // http://www.w3.org/TR/html5/forms.html#valid-e-mail-address (search for 'willful violation')
203 email: /^[a-z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?(?:\.[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?)*$/i,
204 hostname: HOSTNAME,
205 // optimized https://www.safaribooksonline.com/library/view/regular-expressions-cookbook/9780596802837/ch07s16.html
206 ipv4: /^(?:(?:25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(?:25[0-5]|2[0-4]\d|[01]?\d\d?)$/,
207 // optimized http://stackoverflow.com/questions/53497/regular-expression-that-matches-valid-ipv6-addresses
208 ipv6: /^\s*(?:(?:(?:[0-9a-f]{1,4}:){7}(?:[0-9a-f]{1,4}|:))|(?:(?:[0-9a-f]{1,4}:){6}(?::[0-9a-f]{1,4}|(?:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(?:\.(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3})|:))|(?:(?:[0-9a-f]{1,4}:){5}(?:(?:(?::[0-9a-f]{1,4}){1,2})|:(?:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(?:\.(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3})|:))|(?:(?:[0-9a-f]{1,4}:){4}(?:(?:(?::[0-9a-f]{1,4}){1,3})|(?:(?::[0-9a-f]{1,4})?:(?:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(?:\.(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(?:(?:[0-9a-f]{1,4}:){3}(?:(?:(?::[0-9a-f]{1,4}){1,4})|(?:(?::[0-9a-f]{1,4}){0,2}:(?:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(?:\.(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(?:(?:[0-9a-f]{1,4}:){2}(?:(?:(?::[0-9a-f]{1,4}){1,5})|(?:(?::[0-9a-f]{1,4}){0,3}:(?:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(?:\.(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(?:(?:[0-9a-f]{1,4}:){1}(?:(?:(?::[0-9a-f]{1,4}){1,6})|(?:(?::[0-9a-f]{1,4}){0,4}:(?:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(?:\.(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(?::(?:(?:(?::[0-9a-f]{1,4}){1,7})|(?:(?::[0-9a-f]{1,4}){0,5}:(?:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(?:\.(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:)))(?:%.+)?\s*$/i,
209 regex: regex,
210 // uuid: http://tools.ietf.org/html/rfc4122
211 uuid: UUID,
212 // JSON-pointer: https://tools.ietf.org/html/rfc6901
213 // uri fragment: https://tools.ietf.org/html/rfc3986#appendix-A
214 'json-pointer': JSON_POINTER,
215 'json-pointer-uri-fragment': JSON_POINTER_URI_FRAGMENT,
216 // relative JSON-pointer: http://tools.ietf.org/html/draft-luff-relative-json-pointer-00
217 'relative-json-pointer': RELATIVE_JSON_POINTER
218};
219
220
221formats.full = {
222 date: date,
223 time: time,
224 'date-time': date_time,
225 uri: uri,
226 'uri-reference': URIREF,
227 'uri-template': URITEMPLATE,
228 url: URL,
229 email: /^[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?$/i,
230 hostname: HOSTNAME,
231 ipv4: /^(?:(?:25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(?:25[0-5]|2[0-4]\d|[01]?\d\d?)$/,
232 ipv6: /^\s*(?:(?:(?:[0-9a-f]{1,4}:){7}(?:[0-9a-f]{1,4}|:))|(?:(?:[0-9a-f]{1,4}:){6}(?::[0-9a-f]{1,4}|(?:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(?:\.(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3})|:))|(?:(?:[0-9a-f]{1,4}:){5}(?:(?:(?::[0-9a-f]{1,4}){1,2})|:(?:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(?:\.(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3})|:))|(?:(?:[0-9a-f]{1,4}:){4}(?:(?:(?::[0-9a-f]{1,4}){1,3})|(?:(?::[0-9a-f]{1,4})?:(?:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(?:\.(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(?:(?:[0-9a-f]{1,4}:){3}(?:(?:(?::[0-9a-f]{1,4}){1,4})|(?:(?::[0-9a-f]{1,4}){0,2}:(?:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(?:\.(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(?:(?:[0-9a-f]{1,4}:){2}(?:(?:(?::[0-9a-f]{1,4}){1,5})|(?:(?::[0-9a-f]{1,4}){0,3}:(?:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(?:\.(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(?:(?:[0-9a-f]{1,4}:){1}(?:(?:(?::[0-9a-f]{1,4}){1,6})|(?:(?::[0-9a-f]{1,4}){0,4}:(?:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(?:\.(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(?::(?:(?:(?::[0-9a-f]{1,4}){1,7})|(?:(?::[0-9a-f]{1,4}){0,5}:(?:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(?:\.(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:)))(?:%.+)?\s*$/i,
233 regex: regex,
234 uuid: UUID,
235 'json-pointer': JSON_POINTER,
236 'json-pointer-uri-fragment': JSON_POINTER_URI_FRAGMENT,
237 'relative-json-pointer': RELATIVE_JSON_POINTER
238};
239
240
241function isLeapYear(year) {
242 // https://tools.ietf.org/html/rfc3339#appendix-C
243 return year % 4 === 0 && (year % 100 !== 0 || year % 400 === 0);
244}
245
246
247function date(str) {
248 // full-date from http://tools.ietf.org/html/rfc3339#section-5.6
249 var matches = str.match(DATE);
250 if (!matches) return false;
251
252 var year = +matches[1];
253 var month = +matches[2];
254 var day = +matches[3];
255
256 return month >= 1 && month <= 12 && day >= 1 &&
257 day <= (month == 2 && isLeapYear(year) ? 29 : DAYS[month]);
258}
259
260
261function time(str, full) {
262 var matches = str.match(TIME);
263 if (!matches) return false;
264
265 var hour = matches[1];
266 var minute = matches[2];
267 var second = matches[3];
268 var timeZone = matches[5];
269 return ((hour <= 23 && minute <= 59 && second <= 59) ||
270 (hour == 23 && minute == 59 && second == 60)) &&
271 (!full || timeZone);
272}
273
274
275var DATE_TIME_SEPARATOR = /t|\s/i;
276function date_time(str) {
277 // http://tools.ietf.org/html/rfc3339#section-5.6
278 var dateTime = str.split(DATE_TIME_SEPARATOR);
279 return dateTime.length == 2 && date(dateTime[0]) && time(dateTime[1], true);
280}
281
282
283var NOT_URI_FRAGMENT = /\/|:/;
284function uri(str) {
285 // http://jmrware.com/articles/2009/uri_regexp/URI_regex.html + optional protocol + required "."
286 return NOT_URI_FRAGMENT.test(str) && URI.test(str);
287}
288
289
290var Z_ANCHOR = /[^\\]\\Z/;
291function regex(str) {
292 if (Z_ANCHOR.test(str)) return false;
293 try {
294 new RegExp(str);
295 return true;
296 } catch(e) {
297 return false;
298 }
299}
300
301},{"./util":10}],5:[function(require,module,exports){
302'use strict';
303
304var resolve = require('./resolve')
305 , util = require('./util')
306 , errorClasses = require('./error_classes')
307 , stableStringify = require('fast-json-stable-stringify');
308
309var validateGenerator = require('../dotjs/validate');
310
311/**
312 * Functions below are used inside compiled validations function
313 */
314
315var ucs2length = util.ucs2length;
316var equal = require('fast-deep-equal');
317
318// this error is thrown by async schemas to return validation errors via exception
319var ValidationError = errorClasses.Validation;
320
321module.exports = compile;
322
323
324/**
325 * Compiles schema to validation function
326 * @this Ajv
327 * @param {Object} schema schema object
328 * @param {Object} root object with information about the root schema for this schema
329 * @param {Object} localRefs the hash of local references inside the schema (created by resolve.id), used for inline resolution
330 * @param {String} baseId base ID for IDs in the schema
331 * @return {Function} validation function
332 */
333function compile(schema, root, localRefs, baseId) {
334 /* jshint validthis: true, evil: true */
335 /* eslint no-shadow: 0 */
336 var self = this
337 , opts = this._opts
338 , refVal = [ undefined ]
339 , refs = {}
340 , patterns = []
341 , patternsHash = {}
342 , defaults = []
343 , defaultsHash = {}
344 , customRules = [];
345
346 function patternCode(i, patterns) {
347 var regExpCode = opts.regExp ? 'regExp' : 'new RegExp';
348 return 'var pattern' + i + ' = ' + regExpCode + '(' + util.toQuotedString(patterns[i]) + ');';
349 }
350
351 root = root || { schema: schema, refVal: refVal, refs: refs };
352
353 var c = checkCompiling.call(this, schema, root, baseId);
354 var compilation = this._compilations[c.index];
355 if (c.compiling) return (compilation.callValidate = callValidate);
356
357 var formats = this._formats;
358 var RULES = this.RULES;
359
360 try {
361 var v = localCompile(schema, root, localRefs, baseId);
362 compilation.validate = v;
363 var cv = compilation.callValidate;
364 if (cv) {
365 cv.schema = v.schema;
366 cv.errors = null;
367 cv.refs = v.refs;
368 cv.refVal = v.refVal;
369 cv.root = v.root;
370 cv.$async = v.$async;
371 if (opts.sourceCode) cv.source = v.source;
372 }
373 return v;
374 } finally {
375 endCompiling.call(this, schema, root, baseId);
376 }
377
378 /* @this {*} - custom context, see passContext option */
379 function callValidate() {
380 /* jshint validthis: true */
381 var validate = compilation.validate;
382 var result = validate.apply(this, arguments);
383 callValidate.errors = validate.errors;
384 return result;
385 }
386
387 function localCompile(_schema, _root, localRefs, baseId) {
388 var isRoot = !_root || (_root && _root.schema == _schema);
389 if (_root.schema != root.schema)
390 return compile.call(self, _schema, _root, localRefs, baseId);
391
392 var $async = _schema.$async === true;
393
394 var sourceCode = validateGenerator({
395 isTop: true,
396 schema: _schema,
397 isRoot: isRoot,
398 baseId: baseId,
399 root: _root,
400 schemaPath: '',
401 errSchemaPath: '#',
402 errorPath: '""',
403 MissingRefError: errorClasses.MissingRef,
404 RULES: RULES,
405 validate: validateGenerator,
406 util: util,
407 resolve: resolve,
408 resolveRef: resolveRef,
409 usePattern: usePattern,
410 useDefault: useDefault,
411 useCustomRule: useCustomRule,
412 opts: opts,
413 formats: formats,
414 logger: self.logger,
415 self: self
416 });
417
418 sourceCode = vars(refVal, refValCode) + vars(patterns, patternCode)
419 + vars(defaults, defaultCode) + vars(customRules, customRuleCode)
420 + sourceCode;
421
422 if (opts.processCode) sourceCode = opts.processCode(sourceCode, _schema);
423 // console.log('\n\n\n *** \n', JSON.stringify(sourceCode));
424 var validate;
425 try {
426 var makeValidate = new Function(
427 'self',
428 'RULES',
429 'formats',
430 'root',
431 'refVal',
432 'defaults',
433 'customRules',
434 'equal',
435 'ucs2length',
436 'ValidationError',
437 'regExp',
438 sourceCode
439 );
440
441 validate = makeValidate(
442 self,
443 RULES,
444 formats,
445 root,
446 refVal,
447 defaults,
448 customRules,
449 equal,
450 ucs2length,
451 ValidationError,
452 opts.regExp
453 );
454
455 refVal[0] = validate;
456 } catch(e) {
457 self.logger.error('Error compiling schema, function code:', sourceCode);
458 throw e;
459 }
460
461 validate.schema = _schema;
462 validate.errors = null;
463 validate.refs = refs;
464 validate.refVal = refVal;
465 validate.root = isRoot ? validate : _root;
466 if ($async) validate.$async = true;
467 if (opts.sourceCode === true) {
468 validate.source = {
469 code: sourceCode,
470 patterns: patterns,
471 defaults: defaults
472 };
473 }
474
475 return validate;
476 }
477
478 function resolveRef(baseId, ref, isRoot) {
479 ref = resolve.url(baseId, ref);
480 var refIndex = refs[ref];
481 var _refVal, refCode;
482 if (refIndex !== undefined) {
483 _refVal = refVal[refIndex];
484 refCode = 'refVal[' + refIndex + ']';
485 return resolvedRef(_refVal, refCode);
486 }
487 if (!isRoot && root.refs) {
488 var rootRefId = root.refs[ref];
489 if (rootRefId !== undefined) {
490 _refVal = root.refVal[rootRefId];
491 refCode = addLocalRef(ref, _refVal);
492 return resolvedRef(_refVal, refCode);
493 }
494 }
495
496 refCode = addLocalRef(ref);
497 var v = resolve.call(self, localCompile, root, ref);
498 if (v === undefined) {
499 var localSchema = localRefs && localRefs[ref];
500 if (localSchema) {
501 v = resolve.inlineRef(localSchema, opts.inlineRefs)
502 ? localSchema
503 : compile.call(self, localSchema, root, localRefs, baseId);
504 }
505 }
506
507 if (v === undefined) {
508 removeLocalRef(ref);
509 } else {
510 replaceLocalRef(ref, v);
511 return resolvedRef(v, refCode);
512 }
513 }
514
515 function addLocalRef(ref, v) {
516 var refId = refVal.length;
517 refVal[refId] = v;
518 refs[ref] = refId;
519 return 'refVal' + refId;
520 }
521
522 function removeLocalRef(ref) {
523 delete refs[ref];
524 }
525
526 function replaceLocalRef(ref, v) {
527 var refId = refs[ref];
528 refVal[refId] = v;
529 }
530
531 function resolvedRef(refVal, code) {
532 return typeof refVal == 'object' || typeof refVal == 'boolean'
533 ? { code: code, schema: refVal, inline: true }
534 : { code: code, $async: refVal && !!refVal.$async };
535 }
536
537 function usePattern(regexStr) {
538 var index = patternsHash[regexStr];
539 if (index === undefined) {
540 index = patternsHash[regexStr] = patterns.length;
541 patterns[index] = regexStr;
542 }
543 return 'pattern' + index;
544 }
545
546 function useDefault(value) {
547 switch (typeof value) {
548 case 'boolean':
549 case 'number':
550 return '' + value;
551 case 'string':
552 return util.toQuotedString(value);
553 case 'object':
554 if (value === null) return 'null';
555 var valueStr = stableStringify(value);
556 var index = defaultsHash[valueStr];
557 if (index === undefined) {
558 index = defaultsHash[valueStr] = defaults.length;
559 defaults[index] = value;
560 }
561 return 'default' + index;
562 }
563 }
564
565 function useCustomRule(rule, schema, parentSchema, it) {
566 if (self._opts.validateSchema !== false) {
567 var deps = rule.definition.dependencies;
568 if (deps && !deps.every(function(keyword) {
569 return Object.prototype.hasOwnProperty.call(parentSchema, keyword);
570 }))
571 throw new Error('parent schema must have all required keywords: ' + deps.join(','));
572
573 var validateSchema = rule.definition.validateSchema;
574 if (validateSchema) {
575 var valid = validateSchema(schema);
576 if (!valid) {
577 var message = 'keyword schema is invalid: ' + self.errorsText(validateSchema.errors);
578 if (self._opts.validateSchema == 'log') self.logger.error(message);
579 else throw new Error(message);
580 }
581 }
582 }
583
584 var compile = rule.definition.compile
585 , inline = rule.definition.inline
586 , macro = rule.definition.macro;
587
588 var validate;
589 if (compile) {
590 validate = compile.call(self, schema, parentSchema, it);
591 } else if (macro) {
592 validate = macro.call(self, schema, parentSchema, it);
593 if (opts.validateSchema !== false) self.validateSchema(validate, true);
594 } else if (inline) {
595 validate = inline.call(self, it, rule.keyword, schema, parentSchema);
596 } else {
597 validate = rule.definition.validate;
598 if (!validate) return;
599 }
600
601 if (validate === undefined)
602 throw new Error('custom keyword "' + rule.keyword + '"failed to compile');
603
604 var index = customRules.length;
605 customRules[index] = validate;
606
607 return {
608 code: 'customRule' + index,
609 validate: validate
610 };
611 }
612}
613
614
615/**
616 * Checks if the schema is currently compiled
617 * @this Ajv
618 * @param {Object} schema schema to compile
619 * @param {Object} root root object
620 * @param {String} baseId base schema ID
621 * @return {Object} object with properties "index" (compilation index) and "compiling" (boolean)
622 */
623function checkCompiling(schema, root, baseId) {
624 /* jshint validthis: true */
625 var index = compIndex.call(this, schema, root, baseId);
626 if (index >= 0) return { index: index, compiling: true };
627 index = this._compilations.length;
628 this._compilations[index] = {
629 schema: schema,
630 root: root,
631 baseId: baseId
632 };
633 return { index: index, compiling: false };
634}
635
636
637/**
638 * Removes the schema from the currently compiled list
639 * @this Ajv
640 * @param {Object} schema schema to compile
641 * @param {Object} root root object
642 * @param {String} baseId base schema ID
643 */
644function endCompiling(schema, root, baseId) {
645 /* jshint validthis: true */
646 var i = compIndex.call(this, schema, root, baseId);
647 if (i >= 0) this._compilations.splice(i, 1);
648}
649
650
651/**
652 * Index of schema compilation in the currently compiled list
653 * @this Ajv
654 * @param {Object} schema schema to compile
655 * @param {Object} root root object
656 * @param {String} baseId base schema ID
657 * @return {Integer} compilation index
658 */
659function compIndex(schema, root, baseId) {
660 /* jshint validthis: true */
661 for (var i=0; i<this._compilations.length; i++) {
662 var c = this._compilations[i];
663 if (c.schema == schema && c.root == root && c.baseId == baseId) return i;
664 }
665 return -1;
666}
667
668
669function defaultCode(i) {
670 return 'var default' + i + ' = defaults[' + i + '];';
671}
672
673
674function refValCode(i, refVal) {
675 return refVal[i] === undefined ? '' : 'var refVal' + i + ' = refVal[' + i + '];';
676}
677
678
679function customRuleCode(i) {
680 return 'var customRule' + i + ' = customRules[' + i + '];';
681}
682
683
684function vars(arr, statement) {
685 if (!arr.length) return '';
686 var code = '';
687 for (var i=0; i<arr.length; i++)
688 code += statement(i, arr);
689 return code;
690}
691
692},{"../dotjs/validate":38,"./error_classes":3,"./resolve":6,"./util":10,"fast-deep-equal":42,"fast-json-stable-stringify":43}],6:[function(require,module,exports){
693'use strict';
694
695var URI = require('uri-js')
696 , equal = require('fast-deep-equal')
697 , util = require('./util')
698 , SchemaObject = require('./schema_obj')
699 , traverse = require('json-schema-traverse');
700
701module.exports = resolve;
702
703resolve.normalizeId = normalizeId;
704resolve.fullPath = getFullPath;
705resolve.url = resolveUrl;
706resolve.ids = resolveIds;
707resolve.inlineRef = inlineRef;
708resolve.schema = resolveSchema;
709
710/**
711 * [resolve and compile the references ($ref)]
712 * @this Ajv
713 * @param {Function} compile reference to schema compilation funciton (localCompile)
714 * @param {Object} root object with information about the root schema for the current schema
715 * @param {String} ref reference to resolve
716 * @return {Object|Function} schema object (if the schema can be inlined) or validation function
717 */
718function resolve(compile, root, ref) {
719 /* jshint validthis: true */
720 var refVal = this._refs[ref];
721 if (typeof refVal == 'string') {
722 if (this._refs[refVal]) refVal = this._refs[refVal];
723 else return resolve.call(this, compile, root, refVal);
724 }
725
726 refVal = refVal || this._schemas[ref];
727 if (refVal instanceof SchemaObject) {
728 return inlineRef(refVal.schema, this._opts.inlineRefs)
729 ? refVal.schema
730 : refVal.validate || this._compile(refVal);
731 }
732
733 var res = resolveSchema.call(this, root, ref);
734 var schema, v, baseId;
735 if (res) {
736 schema = res.schema;
737 root = res.root;
738 baseId = res.baseId;
739 }
740
741 if (schema instanceof SchemaObject) {
742 v = schema.validate || compile.call(this, schema.schema, root, undefined, baseId);
743 } else if (schema !== undefined) {
744 v = inlineRef(schema, this._opts.inlineRefs)
745 ? schema
746 : compile.call(this, schema, root, undefined, baseId);
747 }
748
749 return v;
750}
751
752
753/**
754 * Resolve schema, its root and baseId
755 * @this Ajv
756 * @param {Object} root root object with properties schema, refVal, refs
757 * @param {String} ref reference to resolve
758 * @return {Object} object with properties schema, root, baseId
759 */
760function resolveSchema(root, ref) {
761 /* jshint validthis: true */
762 var p = URI.parse(ref)
763 , refPath = _getFullPath(p)
764 , baseId = getFullPath(this._getId(root.schema));
765 if (Object.keys(root.schema).length === 0 || refPath !== baseId) {
766 var id = normalizeId(refPath);
767 var refVal = this._refs[id];
768 if (typeof refVal == 'string') {
769 return resolveRecursive.call(this, root, refVal, p);
770 } else if (refVal instanceof SchemaObject) {
771 if (!refVal.validate) this._compile(refVal);
772 root = refVal;
773 } else {
774 refVal = this._schemas[id];
775 if (refVal instanceof SchemaObject) {
776 if (!refVal.validate) this._compile(refVal);
777 if (id == normalizeId(ref))
778 return { schema: refVal, root: root, baseId: baseId };
779 root = refVal;
780 } else {
781 return;
782 }
783 }
784 if (!root.schema) return;
785 baseId = getFullPath(this._getId(root.schema));
786 }
787 return getJsonPointer.call(this, p, baseId, root.schema, root);
788}
789
790
791/* @this Ajv */
792function resolveRecursive(root, ref, parsedRef) {
793 /* jshint validthis: true */
794 var res = resolveSchema.call(this, root, ref);
795 if (res) {
796 var schema = res.schema;
797 var baseId = res.baseId;
798 root = res.root;
799 var id = this._getId(schema);
800 if (id) baseId = resolveUrl(baseId, id);
801 return getJsonPointer.call(this, parsedRef, baseId, schema, root);
802 }
803}
804
805
806var PREVENT_SCOPE_CHANGE = util.toHash(['properties', 'patternProperties', 'enum', 'dependencies', 'definitions']);
807/* @this Ajv */
808function getJsonPointer(parsedRef, baseId, schema, root) {
809 /* jshint validthis: true */
810 parsedRef.fragment = parsedRef.fragment || '';
811 if (parsedRef.fragment.slice(0,1) != '/') return;
812 var parts = parsedRef.fragment.split('/');
813
814 for (var i = 1; i < parts.length; i++) {
815 var part = parts[i];
816 if (part) {
817 part = util.unescapeFragment(part);
818 schema = schema[part];
819 if (schema === undefined) break;
820 var id;
821 if (!PREVENT_SCOPE_CHANGE[part]) {
822 id = this._getId(schema);
823 if (id) baseId = resolveUrl(baseId, id);
824 if (schema.$ref) {
825 var $ref = resolveUrl(baseId, schema.$ref);
826 var res = resolveSchema.call(this, root, $ref);
827 if (res) {
828 schema = res.schema;
829 root = res.root;
830 baseId = res.baseId;
831 }
832 }
833 }
834 }
835 }
836 if (schema !== undefined && schema !== root.schema)
837 return { schema: schema, root: root, baseId: baseId };
838}
839
840
841var SIMPLE_INLINED = util.toHash([
842 'type', 'format', 'pattern',
843 'maxLength', 'minLength',
844 'maxProperties', 'minProperties',
845 'maxItems', 'minItems',
846 'maximum', 'minimum',
847 'uniqueItems', 'multipleOf',
848 'required', 'enum'
849]);
850function inlineRef(schema, limit) {
851 if (limit === false) return false;
852 if (limit === undefined || limit === true) return checkNoRef(schema);
853 else if (limit) return countKeys(schema) <= limit;
854}
855
856
857function checkNoRef(schema) {
858 var item;
859 if (Array.isArray(schema)) {
860 for (var i=0; i<schema.length; i++) {
861 item = schema[i];
862 if (typeof item == 'object' && !checkNoRef(item)) return false;
863 }
864 } else {
865 for (var key in schema) {
866 if (key == '$ref') return false;
867 item = schema[key];
868 if (typeof item == 'object' && !checkNoRef(item)) return false;
869 }
870 }
871 return true;
872}
873
874
875function countKeys(schema) {
876 var count = 0, item;
877 if (Array.isArray(schema)) {
878 for (var i=0; i<schema.length; i++) {
879 item = schema[i];
880 if (typeof item == 'object') count += countKeys(item);
881 if (count == Infinity) return Infinity;
882 }
883 } else {
884 for (var key in schema) {
885 if (key == '$ref') return Infinity;
886 if (SIMPLE_INLINED[key]) {
887 count++;
888 } else {
889 item = schema[key];
890 if (typeof item == 'object') count += countKeys(item) + 1;
891 if (count == Infinity) return Infinity;
892 }
893 }
894 }
895 return count;
896}
897
898
899function getFullPath(id, normalize) {
900 if (normalize !== false) id = normalizeId(id);
901 var p = URI.parse(id);
902 return _getFullPath(p);
903}
904
905
906function _getFullPath(p) {
907 return URI.serialize(p).split('#')[0] + '#';
908}
909
910
911var TRAILING_SLASH_HASH = /#\/?$/;
912function normalizeId(id) {
913 return id ? id.replace(TRAILING_SLASH_HASH, '') : '';
914}
915
916
917function resolveUrl(baseId, id) {
918 id = normalizeId(id);
919 return URI.resolve(baseId, id);
920}
921
922
923/* @this Ajv */
924function resolveIds(schema) {
925 var schemaId = normalizeId(this._getId(schema));
926 var baseIds = {'': schemaId};
927 var fullPaths = {'': getFullPath(schemaId, false)};
928 var localRefs = {};
929 var self = this;
930
931 traverse(schema, {allKeys: true}, function(sch, jsonPtr, rootSchema, parentJsonPtr, parentKeyword, parentSchema, keyIndex) {
932 if (jsonPtr === '') return;
933 var id = self._getId(sch);
934 var baseId = baseIds[parentJsonPtr];
935 var fullPath = fullPaths[parentJsonPtr] + '/' + parentKeyword;
936 if (keyIndex !== undefined)
937 fullPath += '/' + (typeof keyIndex == 'number' ? keyIndex : util.escapeFragment(keyIndex));
938
939 if (typeof id == 'string') {
940 id = baseId = normalizeId(baseId ? URI.resolve(baseId, id) : id);
941
942 var refVal = self._refs[id];
943 if (typeof refVal == 'string') refVal = self._refs[refVal];
944 if (refVal && refVal.schema) {
945 if (!equal(sch, refVal.schema))
946 throw new Error('id "' + id + '" resolves to more than one schema');
947 } else if (id != normalizeId(fullPath)) {
948 if (id[0] == '#') {
949 if (localRefs[id] && !equal(sch, localRefs[id]))
950 throw new Error('id "' + id + '" resolves to more than one schema');
951 localRefs[id] = sch;
952 } else {
953 self._refs[id] = fullPath;
954 }
955 }
956 }
957 baseIds[jsonPtr] = baseId;
958 fullPaths[jsonPtr] = fullPath;
959 });
960
961 return localRefs;
962}
963
964},{"./schema_obj":8,"./util":10,"fast-deep-equal":42,"json-schema-traverse":44,"uri-js":45}],7:[function(require,module,exports){
965'use strict';
966
967var ruleModules = require('../dotjs')
968 , toHash = require('./util').toHash;
969
970module.exports = function rules() {
971 var RULES = [
972 { type: 'number',
973 rules: [ { 'maximum': ['exclusiveMaximum'] },
974 { 'minimum': ['exclusiveMinimum'] }, 'multipleOf', 'format'] },
975 { type: 'string',
976 rules: [ 'maxLength', 'minLength', 'pattern', 'format' ] },
977 { type: 'array',
978 rules: [ 'maxItems', 'minItems', 'items', 'contains', 'uniqueItems' ] },
979 { type: 'object',
980 rules: [ 'maxProperties', 'minProperties', 'required', 'dependencies', 'propertyNames',
981 { 'properties': ['additionalProperties', 'patternProperties'] } ] },
982 { rules: [ '$ref', 'const', 'enum', 'not', 'anyOf', 'oneOf', 'allOf', 'if' ] }
983 ];
984
985 var ALL = [ 'type', '$comment' ];
986 var KEYWORDS = [
987 '$schema', '$id', 'id', '$data', '$async', 'title',
988 'description', 'default', 'definitions',
989 'examples', 'readOnly', 'writeOnly',
990 'contentMediaType', 'contentEncoding',
991 'additionalItems', 'then', 'else'
992 ];
993 var TYPES = [ 'number', 'integer', 'string', 'array', 'object', 'boolean', 'null' ];
994 RULES.all = toHash(ALL);
995 RULES.types = toHash(TYPES);
996
997 RULES.forEach(function (group) {
998 group.rules = group.rules.map(function (keyword) {
999 var implKeywords;
1000 if (typeof keyword == 'object') {
1001 var key = Object.keys(keyword)[0];
1002 implKeywords = keyword[key];
1003 keyword = key;
1004 implKeywords.forEach(function (k) {
1005 ALL.push(k);
1006 RULES.all[k] = true;
1007 });
1008 }
1009 ALL.push(keyword);
1010 var rule = RULES.all[keyword] = {
1011 keyword: keyword,
1012 code: ruleModules[keyword],
1013 implements: implKeywords
1014 };
1015 return rule;
1016 });
1017
1018 RULES.all.$comment = {
1019 keyword: '$comment',
1020 code: ruleModules.$comment
1021 };
1022
1023 if (group.type) RULES.types[group.type] = group;
1024 });
1025
1026 RULES.keywords = toHash(ALL.concat(KEYWORDS));
1027 RULES.custom = {};
1028
1029 return RULES;
1030};
1031
1032},{"../dotjs":27,"./util":10}],8:[function(require,module,exports){
1033'use strict';
1034
1035var util = require('./util');
1036
1037module.exports = SchemaObject;
1038
1039function SchemaObject(obj) {
1040 util.copy(obj, this);
1041}
1042
1043},{"./util":10}],9:[function(require,module,exports){
1044'use strict';
1045
1046// https://mathiasbynens.be/notes/javascript-encoding
1047// https://github.com/bestiejs/punycode.js - punycode.ucs2.decode
1048module.exports = function ucs2length(str) {
1049 var length = 0
1050 , len = str.length
1051 , pos = 0
1052 , value;
1053 while (pos < len) {
1054 length++;
1055 value = str.charCodeAt(pos++);
1056 if (value >= 0xD800 && value <= 0xDBFF && pos < len) {
1057 // high surrogate, and there is a next character
1058 value = str.charCodeAt(pos);
1059 if ((value & 0xFC00) == 0xDC00) pos++; // low surrogate
1060 }
1061 }
1062 return length;
1063};
1064
1065},{}],10:[function(require,module,exports){
1066'use strict';
1067
1068
1069module.exports = {
1070 copy: copy,
1071 checkDataType: checkDataType,
1072 checkDataTypes: checkDataTypes,
1073 coerceToTypes: coerceToTypes,
1074 toHash: toHash,
1075 getProperty: getProperty,
1076 escapeQuotes: escapeQuotes,
1077 equal: require('fast-deep-equal'),
1078 ucs2length: require('./ucs2length'),
1079 varOccurences: varOccurences,
1080 varReplace: varReplace,
1081 schemaHasRules: schemaHasRules,
1082 schemaHasRulesExcept: schemaHasRulesExcept,
1083 schemaUnknownRules: schemaUnknownRules,
1084 toQuotedString: toQuotedString,
1085 getPathExpr: getPathExpr,
1086 getPath: getPath,
1087 getData: getData,
1088 unescapeFragment: unescapeFragment,
1089 unescapeJsonPointer: unescapeJsonPointer,
1090 escapeFragment: escapeFragment,
1091 escapeJsonPointer: escapeJsonPointer
1092};
1093
1094
1095function copy(o, to) {
1096 to = to || {};
1097 for (var key in o) to[key] = o[key];
1098 return to;
1099}
1100
1101
1102function checkDataType(dataType, data, strictNumbers, negate) {
1103 var EQUAL = negate ? ' !== ' : ' === '
1104 , AND = negate ? ' || ' : ' && '
1105 , OK = negate ? '!' : ''
1106 , NOT = negate ? '' : '!';
1107 switch (dataType) {
1108 case 'null': return data + EQUAL + 'null';
1109 case 'array': return OK + 'Array.isArray(' + data + ')';
1110 case 'object': return '(' + OK + data + AND +
1111 'typeof ' + data + EQUAL + '"object"' + AND +
1112 NOT + 'Array.isArray(' + data + '))';
1113 case 'integer': return '(typeof ' + data + EQUAL + '"number"' + AND +
1114 NOT + '(' + data + ' % 1)' +
1115 AND + data + EQUAL + data +
1116 (strictNumbers ? (AND + OK + 'isFinite(' + data + ')') : '') + ')';
1117 case 'number': return '(typeof ' + data + EQUAL + '"' + dataType + '"' +
1118 (strictNumbers ? (AND + OK + 'isFinite(' + data + ')') : '') + ')';
1119 default: return 'typeof ' + data + EQUAL + '"' + dataType + '"';
1120 }
1121}
1122
1123
1124function checkDataTypes(dataTypes, data, strictNumbers) {
1125 switch (dataTypes.length) {
1126 case 1: return checkDataType(dataTypes[0], data, strictNumbers, true);
1127 default:
1128 var code = '';
1129 var types = toHash(dataTypes);
1130 if (types.array && types.object) {
1131 code = types.null ? '(': '(!' + data + ' || ';
1132 code += 'typeof ' + data + ' !== "object")';
1133 delete types.null;
1134 delete types.array;
1135 delete types.object;
1136 }
1137 if (types.number) delete types.integer;
1138 for (var t in types)
1139 code += (code ? ' && ' : '' ) + checkDataType(t, data, strictNumbers, true);
1140
1141 return code;
1142 }
1143}
1144
1145
1146var COERCE_TO_TYPES = toHash([ 'string', 'number', 'integer', 'boolean', 'null' ]);
1147function coerceToTypes(optionCoerceTypes, dataTypes) {
1148 if (Array.isArray(dataTypes)) {
1149 var types = [];
1150 for (var i=0; i<dataTypes.length; i++) {
1151 var t = dataTypes[i];
1152 if (COERCE_TO_TYPES[t]) types[types.length] = t;
1153 else if (optionCoerceTypes === 'array' && t === 'array') types[types.length] = t;
1154 }
1155 if (types.length) return types;
1156 } else if (COERCE_TO_TYPES[dataTypes]) {
1157 return [dataTypes];
1158 } else if (optionCoerceTypes === 'array' && dataTypes === 'array') {
1159 return ['array'];
1160 }
1161}
1162
1163
1164function toHash(arr) {
1165 var hash = {};
1166 for (var i=0; i<arr.length; i++) hash[arr[i]] = true;
1167 return hash;
1168}
1169
1170
1171var IDENTIFIER = /^[a-z$_][a-z$_0-9]*$/i;
1172var SINGLE_QUOTE = /'|\\/g;
1173function getProperty(key) {
1174 return typeof key == 'number'
1175 ? '[' + key + ']'
1176 : IDENTIFIER.test(key)
1177 ? '.' + key
1178 : "['" + escapeQuotes(key) + "']";
1179}
1180
1181
1182function escapeQuotes(str) {
1183 return str.replace(SINGLE_QUOTE, '\\$&')
1184 .replace(/\n/g, '\\n')
1185 .replace(/\r/g, '\\r')
1186 .replace(/\f/g, '\\f')
1187 .replace(/\t/g, '\\t');
1188}
1189
1190
1191function varOccurences(str, dataVar) {
1192 dataVar += '[^0-9]';
1193 var matches = str.match(new RegExp(dataVar, 'g'));
1194 return matches ? matches.length : 0;
1195}
1196
1197
1198function varReplace(str, dataVar, expr) {
1199 dataVar += '([^0-9])';
1200 expr = expr.replace(/\$/g, '$$$$');
1201 return str.replace(new RegExp(dataVar, 'g'), expr + '$1');
1202}
1203
1204
1205function schemaHasRules(schema, rules) {
1206 if (typeof schema == 'boolean') return !schema;
1207 for (var key in schema) if (rules[key]) return true;
1208}
1209
1210
1211function schemaHasRulesExcept(schema, rules, exceptKeyword) {
1212 if (typeof schema == 'boolean') return !schema && exceptKeyword != 'not';
1213 for (var key in schema) if (key != exceptKeyword && rules[key]) return true;
1214}
1215
1216
1217function schemaUnknownRules(schema, rules) {
1218 if (typeof schema == 'boolean') return;
1219 for (var key in schema) if (!rules[key]) return key;
1220}
1221
1222
1223function toQuotedString(str) {
1224 return '\'' + escapeQuotes(str) + '\'';
1225}
1226
1227
1228function getPathExpr(currentPath, expr, jsonPointers, isNumber) {
1229 var path = jsonPointers // false by default
1230 ? '\'/\' + ' + expr + (isNumber ? '' : '.replace(/~/g, \'~0\').replace(/\\//g, \'~1\')')
1231 : (isNumber ? '\'[\' + ' + expr + ' + \']\'' : '\'[\\\'\' + ' + expr + ' + \'\\\']\'');
1232 return joinPaths(currentPath, path);
1233}
1234
1235
1236function getPath(currentPath, prop, jsonPointers) {
1237 var path = jsonPointers // false by default
1238 ? toQuotedString('/' + escapeJsonPointer(prop))
1239 : toQuotedString(getProperty(prop));
1240 return joinPaths(currentPath, path);
1241}
1242
1243
1244var JSON_POINTER = /^\/(?:[^~]|~0|~1)*$/;
1245var RELATIVE_JSON_POINTER = /^([0-9]+)(#|\/(?:[^~]|~0|~1)*)?$/;
1246function getData($data, lvl, paths) {
1247 var up, jsonPointer, data, matches;
1248 if ($data === '') return 'rootData';
1249 if ($data[0] == '/') {
1250 if (!JSON_POINTER.test($data)) throw new Error('Invalid JSON-pointer: ' + $data);
1251 jsonPointer = $data;
1252 data = 'rootData';
1253 } else {
1254 matches = $data.match(RELATIVE_JSON_POINTER);
1255 if (!matches) throw new Error('Invalid JSON-pointer: ' + $data);
1256 up = +matches[1];
1257 jsonPointer = matches[2];
1258 if (jsonPointer == '#') {
1259 if (up >= lvl) throw new Error('Cannot access property/index ' + up + ' levels up, current level is ' + lvl);
1260 return paths[lvl - up];
1261 }
1262
1263 if (up > lvl) throw new Error('Cannot access data ' + up + ' levels up, current level is ' + lvl);
1264 data = 'data' + ((lvl - up) || '');
1265 if (!jsonPointer) return data;
1266 }
1267
1268 var expr = data;
1269 var segments = jsonPointer.split('/');
1270 for (var i=0; i<segments.length; i++) {
1271 var segment = segments[i];
1272 if (segment) {
1273 data += getProperty(unescapeJsonPointer(segment));
1274 expr += ' && ' + data;
1275 }
1276 }
1277 return expr;
1278}
1279
1280
1281function joinPaths (a, b) {
1282 if (a == '""') return b;
1283 return (a + ' + ' + b).replace(/([^\\])' \+ '/g, '$1');
1284}
1285
1286
1287function unescapeFragment(str) {
1288 return unescapeJsonPointer(decodeURIComponent(str));
1289}
1290
1291
1292function escapeFragment(str) {
1293 return encodeURIComponent(escapeJsonPointer(str));
1294}
1295
1296
1297function escapeJsonPointer(str) {
1298 return str.replace(/~/g, '~0').replace(/\//g, '~1');
1299}
1300
1301
1302function unescapeJsonPointer(str) {
1303 return str.replace(/~1/g, '/').replace(/~0/g, '~');
1304}
1305
1306},{"./ucs2length":9,"fast-deep-equal":42}],11:[function(require,module,exports){
1307'use strict';
1308
1309var KEYWORDS = [
1310 'multipleOf',
1311 'maximum',
1312 'exclusiveMaximum',
1313 'minimum',
1314 'exclusiveMinimum',
1315 'maxLength',
1316 'minLength',
1317 'pattern',
1318 'additionalItems',
1319 'maxItems',
1320 'minItems',
1321 'uniqueItems',
1322 'maxProperties',
1323 'minProperties',
1324 'required',
1325 'additionalProperties',
1326 'enum',
1327 'format',
1328 'const'
1329];
1330
1331module.exports = function (metaSchema, keywordsJsonPointers) {
1332 for (var i=0; i<keywordsJsonPointers.length; i++) {
1333 metaSchema = JSON.parse(JSON.stringify(metaSchema));
1334 var segments = keywordsJsonPointers[i].split('/');
1335 var keywords = metaSchema;
1336 var j;
1337 for (j=1; j<segments.length; j++)
1338 keywords = keywords[segments[j]];
1339
1340 for (j=0; j<KEYWORDS.length; j++) {
1341 var key = KEYWORDS[j];
1342 var schema = keywords[key];
1343 if (schema) {
1344 keywords[key] = {
1345 anyOf: [
1346 schema,
1347 { $ref: 'https://raw.githubusercontent.com/ajv-validator/ajv/master/lib/refs/data.json#' }
1348 ]
1349 };
1350 }
1351 }
1352 }
1353
1354 return metaSchema;
1355};
1356
1357},{}],12:[function(require,module,exports){
1358'use strict';
1359
1360var metaSchema = require('./refs/json-schema-draft-07.json');
1361
1362module.exports = {
1363 $id: 'https://github.com/ajv-validator/ajv/blob/master/lib/definition_schema.js',
1364 definitions: {
1365 simpleTypes: metaSchema.definitions.simpleTypes
1366 },
1367 type: 'object',
1368 dependencies: {
1369 schema: ['validate'],
1370 $data: ['validate'],
1371 statements: ['inline'],
1372 valid: {not: {required: ['macro']}}
1373 },
1374 properties: {
1375 type: metaSchema.properties.type,
1376 schema: {type: 'boolean'},
1377 statements: {type: 'boolean'},
1378 dependencies: {
1379 type: 'array',
1380 items: {type: 'string'}
1381 },
1382 metaSchema: {type: 'object'},
1383 modifying: {type: 'boolean'},
1384 valid: {type: 'boolean'},
1385 $data: {type: 'boolean'},
1386 async: {type: 'boolean'},
1387 errors: {
1388 anyOf: [
1389 {type: 'boolean'},
1390 {const: 'full'}
1391 ]
1392 }
1393 }
1394};
1395
1396},{"./refs/json-schema-draft-07.json":41}],13:[function(require,module,exports){
1397'use strict';
1398module.exports = function generate__limit(it, $keyword, $ruleType) {
1399 var out = ' ';
1400 var $lvl = it.level;
1401 var $dataLvl = it.dataLevel;
1402 var $schema = it.schema[$keyword];
1403 var $schemaPath = it.schemaPath + it.util.getProperty($keyword);
1404 var $errSchemaPath = it.errSchemaPath + '/' + $keyword;
1405 var $breakOnError = !it.opts.allErrors;
1406 var $errorKeyword;
1407 var $data = 'data' + ($dataLvl || '');
1408 var $isData = it.opts.$data && $schema && $schema.$data,
1409 $schemaValue;
1410 if ($isData) {
1411 out += ' var schema' + ($lvl) + ' = ' + (it.util.getData($schema.$data, $dataLvl, it.dataPathArr)) + '; ';
1412 $schemaValue = 'schema' + $lvl;
1413 } else {
1414 $schemaValue = $schema;
1415 }
1416 var $isMax = $keyword == 'maximum',
1417 $exclusiveKeyword = $isMax ? 'exclusiveMaximum' : 'exclusiveMinimum',
1418 $schemaExcl = it.schema[$exclusiveKeyword],
1419 $isDataExcl = it.opts.$data && $schemaExcl && $schemaExcl.$data,
1420 $op = $isMax ? '<' : '>',
1421 $notOp = $isMax ? '>' : '<',
1422 $errorKeyword = undefined;
1423 if (!($isData || typeof $schema == 'number' || $schema === undefined)) {
1424 throw new Error($keyword + ' must be number');
1425 }
1426 if (!($isDataExcl || $schemaExcl === undefined || typeof $schemaExcl == 'number' || typeof $schemaExcl == 'boolean')) {
1427 throw new Error($exclusiveKeyword + ' must be number or boolean');
1428 }
1429 if ($isDataExcl) {
1430 var $schemaValueExcl = it.util.getData($schemaExcl.$data, $dataLvl, it.dataPathArr),
1431 $exclusive = 'exclusive' + $lvl,
1432 $exclType = 'exclType' + $lvl,
1433 $exclIsNumber = 'exclIsNumber' + $lvl,
1434 $opExpr = 'op' + $lvl,
1435 $opStr = '\' + ' + $opExpr + ' + \'';
1436 out += ' var schemaExcl' + ($lvl) + ' = ' + ($schemaValueExcl) + '; ';
1437 $schemaValueExcl = 'schemaExcl' + $lvl;
1438 out += ' var ' + ($exclusive) + '; var ' + ($exclType) + ' = typeof ' + ($schemaValueExcl) + '; if (' + ($exclType) + ' != \'boolean\' && ' + ($exclType) + ' != \'undefined\' && ' + ($exclType) + ' != \'number\') { ';
1439 var $errorKeyword = $exclusiveKeyword;
1440 var $$outStack = $$outStack || [];
1441 $$outStack.push(out);
1442 out = ''; /* istanbul ignore else */
1443 if (it.createErrors !== false) {
1444 out += ' { keyword: \'' + ($errorKeyword || '_exclusiveLimit') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: ' + (it.util.toQuotedString($errSchemaPath)) + ' , params: {} ';
1445 if (it.opts.messages !== false) {
1446 out += ' , message: \'' + ($exclusiveKeyword) + ' should be boolean\' ';
1447 }
1448 if (it.opts.verbose) {
1449 out += ' , schema: validate.schema' + ($schemaPath) + ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' ';
1450 }
1451 out += ' } ';
1452 } else {
1453 out += ' {} ';
1454 }
1455 var __err = out;
1456 out = $$outStack.pop();
1457 if (!it.compositeRule && $breakOnError) {
1458 /* istanbul ignore if */
1459 if (it.async) {
1460 out += ' throw new ValidationError([' + (__err) + ']); ';
1461 } else {
1462 out += ' validate.errors = [' + (__err) + ']; return false; ';
1463 }
1464 } else {
1465 out += ' var err = ' + (__err) + '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ';
1466 }
1467 out += ' } else if ( ';
1468 if ($isData) {
1469 out += ' (' + ($schemaValue) + ' !== undefined && typeof ' + ($schemaValue) + ' != \'number\') || ';
1470 }
1471 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) + '=\'; ';
1472 if ($schema === undefined) {
1473 $errorKeyword = $exclusiveKeyword;
1474 $errSchemaPath = it.errSchemaPath + '/' + $exclusiveKeyword;
1475 $schemaValue = $schemaValueExcl;
1476 $isData = $isDataExcl;
1477 }
1478 } else {
1479 var $exclIsNumber = typeof $schemaExcl == 'number',
1480 $opStr = $op;
1481 if ($exclIsNumber && $isData) {
1482 var $opExpr = '\'' + $opStr + '\'';
1483 out += ' if ( ';
1484 if ($isData) {
1485 out += ' (' + ($schemaValue) + ' !== undefined && typeof ' + ($schemaValue) + ' != \'number\') || ';
1486 }
1487 out += ' ( ' + ($schemaValue) + ' === undefined || ' + ($schemaExcl) + ' ' + ($op) + '= ' + ($schemaValue) + ' ? ' + ($data) + ' ' + ($notOp) + '= ' + ($schemaExcl) + ' : ' + ($data) + ' ' + ($notOp) + ' ' + ($schemaValue) + ' ) || ' + ($data) + ' !== ' + ($data) + ') { ';
1488 } else {
1489 if ($exclIsNumber && $schema === undefined) {
1490 $exclusive = true;
1491 $errorKeyword = $exclusiveKeyword;
1492 $errSchemaPath = it.errSchemaPath + '/' + $exclusiveKeyword;
1493 $schemaValue = $schemaExcl;
1494 $notOp += '=';
1495 } else {
1496 if ($exclIsNumber) $schemaValue = Math[$isMax ? 'min' : 'max']($schemaExcl, $schema);
1497 if ($schemaExcl === ($exclIsNumber ? $schemaValue : true)) {
1498 $exclusive = true;
1499 $errorKeyword = $exclusiveKeyword;
1500 $errSchemaPath = it.errSchemaPath + '/' + $exclusiveKeyword;
1501 $notOp += '=';
1502 } else {
1503 $exclusive = false;
1504 $opStr += '=';
1505 }
1506 }
1507 var $opExpr = '\'' + $opStr + '\'';
1508 out += ' if ( ';
1509 if ($isData) {
1510 out += ' (' + ($schemaValue) + ' !== undefined && typeof ' + ($schemaValue) + ' != \'number\') || ';
1511 }
1512 out += ' ' + ($data) + ' ' + ($notOp) + ' ' + ($schemaValue) + ' || ' + ($data) + ' !== ' + ($data) + ') { ';
1513 }
1514 }
1515 $errorKeyword = $errorKeyword || $keyword;
1516 var $$outStack = $$outStack || [];
1517 $$outStack.push(out);
1518 out = ''; /* istanbul ignore else */
1519 if (it.createErrors !== false) {
1520 out += ' { keyword: \'' + ($errorKeyword || '_limit') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: ' + (it.util.toQuotedString($errSchemaPath)) + ' , params: { comparison: ' + ($opExpr) + ', limit: ' + ($schemaValue) + ', exclusive: ' + ($exclusive) + ' } ';
1521 if (it.opts.messages !== false) {
1522 out += ' , message: \'should be ' + ($opStr) + ' ';
1523 if ($isData) {
1524 out += '\' + ' + ($schemaValue);
1525 } else {
1526 out += '' + ($schemaValue) + '\'';
1527 }
1528 }
1529 if (it.opts.verbose) {
1530 out += ' , schema: ';
1531 if ($isData) {
1532 out += 'validate.schema' + ($schemaPath);
1533 } else {
1534 out += '' + ($schema);
1535 }
1536 out += ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' ';
1537 }
1538 out += ' } ';
1539 } else {
1540 out += ' {} ';
1541 }
1542 var __err = out;
1543 out = $$outStack.pop();
1544 if (!it.compositeRule && $breakOnError) {
1545 /* istanbul ignore if */
1546 if (it.async) {
1547 out += ' throw new ValidationError([' + (__err) + ']); ';
1548 } else {
1549 out += ' validate.errors = [' + (__err) + ']; return false; ';
1550 }
1551 } else {
1552 out += ' var err = ' + (__err) + '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ';
1553 }
1554 out += ' } ';
1555 if ($breakOnError) {
1556 out += ' else { ';
1557 }
1558 return out;
1559}
1560
1561},{}],14:[function(require,module,exports){
1562'use strict';
1563module.exports = function generate__limitItems(it, $keyword, $ruleType) {
1564 var out = ' ';
1565 var $lvl = it.level;
1566 var $dataLvl = it.dataLevel;
1567 var $schema = it.schema[$keyword];
1568 var $schemaPath = it.schemaPath + it.util.getProperty($keyword);
1569 var $errSchemaPath = it.errSchemaPath + '/' + $keyword;
1570 var $breakOnError = !it.opts.allErrors;
1571 var $errorKeyword;
1572 var $data = 'data' + ($dataLvl || '');
1573 var $isData = it.opts.$data && $schema && $schema.$data,
1574 $schemaValue;
1575 if ($isData) {
1576 out += ' var schema' + ($lvl) + ' = ' + (it.util.getData($schema.$data, $dataLvl, it.dataPathArr)) + '; ';
1577 $schemaValue = 'schema' + $lvl;
1578 } else {
1579 $schemaValue = $schema;
1580 }
1581 if (!($isData || typeof $schema == 'number')) {
1582 throw new Error($keyword + ' must be number');
1583 }
1584 var $op = $keyword == 'maxItems' ? '>' : '<';
1585 out += 'if ( ';
1586 if ($isData) {
1587 out += ' (' + ($schemaValue) + ' !== undefined && typeof ' + ($schemaValue) + ' != \'number\') || ';
1588 }
1589 out += ' ' + ($data) + '.length ' + ($op) + ' ' + ($schemaValue) + ') { ';
1590 var $errorKeyword = $keyword;
1591 var $$outStack = $$outStack || [];
1592 $$outStack.push(out);
1593 out = ''; /* istanbul ignore else */
1594 if (it.createErrors !== false) {
1595 out += ' { keyword: \'' + ($errorKeyword || '_limitItems') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: ' + (it.util.toQuotedString($errSchemaPath)) + ' , params: { limit: ' + ($schemaValue) + ' } ';
1596 if (it.opts.messages !== false) {
1597 out += ' , message: \'should NOT have ';
1598 if ($keyword == 'maxItems') {
1599 out += 'more';
1600 } else {
1601 out += 'fewer';
1602 }
1603 out += ' than ';
1604 if ($isData) {
1605 out += '\' + ' + ($schemaValue) + ' + \'';
1606 } else {
1607 out += '' + ($schema);
1608 }
1609 out += ' items\' ';
1610 }
1611 if (it.opts.verbose) {
1612 out += ' , schema: ';
1613 if ($isData) {
1614 out += 'validate.schema' + ($schemaPath);
1615 } else {
1616 out += '' + ($schema);
1617 }
1618 out += ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' ';
1619 }
1620 out += ' } ';
1621 } else {
1622 out += ' {} ';
1623 }
1624 var __err = out;
1625 out = $$outStack.pop();
1626 if (!it.compositeRule && $breakOnError) {
1627 /* istanbul ignore if */
1628 if (it.async) {
1629 out += ' throw new ValidationError([' + (__err) + ']); ';
1630 } else {
1631 out += ' validate.errors = [' + (__err) + ']; return false; ';
1632 }
1633 } else {
1634 out += ' var err = ' + (__err) + '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ';
1635 }
1636 out += '} ';
1637 if ($breakOnError) {
1638 out += ' else { ';
1639 }
1640 return out;
1641}
1642
1643},{}],15:[function(require,module,exports){
1644'use strict';
1645module.exports = function generate__limitLength(it, $keyword, $ruleType) {
1646 var out = ' ';
1647 var $lvl = it.level;
1648 var $dataLvl = it.dataLevel;
1649 var $schema = it.schema[$keyword];
1650 var $schemaPath = it.schemaPath + it.util.getProperty($keyword);
1651 var $errSchemaPath = it.errSchemaPath + '/' + $keyword;
1652 var $breakOnError = !it.opts.allErrors;
1653 var $errorKeyword;
1654 var $data = 'data' + ($dataLvl || '');
1655 var $isData = it.opts.$data && $schema && $schema.$data,
1656 $schemaValue;
1657 if ($isData) {
1658 out += ' var schema' + ($lvl) + ' = ' + (it.util.getData($schema.$data, $dataLvl, it.dataPathArr)) + '; ';
1659 $schemaValue = 'schema' + $lvl;
1660 } else {
1661 $schemaValue = $schema;
1662 }
1663 if (!($isData || typeof $schema == 'number')) {
1664 throw new Error($keyword + ' must be number');
1665 }
1666 var $op = $keyword == 'maxLength' ? '>' : '<';
1667 out += 'if ( ';
1668 if ($isData) {
1669 out += ' (' + ($schemaValue) + ' !== undefined && typeof ' + ($schemaValue) + ' != \'number\') || ';
1670 }
1671 if (it.opts.unicode === false) {
1672 out += ' ' + ($data) + '.length ';
1673 } else {
1674 out += ' ucs2length(' + ($data) + ') ';
1675 }
1676 out += ' ' + ($op) + ' ' + ($schemaValue) + ') { ';
1677 var $errorKeyword = $keyword;
1678 var $$outStack = $$outStack || [];
1679 $$outStack.push(out);
1680 out = ''; /* istanbul ignore else */
1681 if (it.createErrors !== false) {
1682 out += ' { keyword: \'' + ($errorKeyword || '_limitLength') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: ' + (it.util.toQuotedString($errSchemaPath)) + ' , params: { limit: ' + ($schemaValue) + ' } ';
1683 if (it.opts.messages !== false) {
1684 out += ' , message: \'should NOT be ';
1685 if ($keyword == 'maxLength') {
1686 out += 'longer';
1687 } else {
1688 out += 'shorter';
1689 }
1690 out += ' than ';
1691 if ($isData) {
1692 out += '\' + ' + ($schemaValue) + ' + \'';
1693 } else {
1694 out += '' + ($schema);
1695 }
1696 out += ' characters\' ';
1697 }
1698 if (it.opts.verbose) {
1699 out += ' , schema: ';
1700 if ($isData) {
1701 out += 'validate.schema' + ($schemaPath);
1702 } else {
1703 out += '' + ($schema);
1704 }
1705 out += ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' ';
1706 }
1707 out += ' } ';
1708 } else {
1709 out += ' {} ';
1710 }
1711 var __err = out;
1712 out = $$outStack.pop();
1713 if (!it.compositeRule && $breakOnError) {
1714 /* istanbul ignore if */
1715 if (it.async) {
1716 out += ' throw new ValidationError([' + (__err) + ']); ';
1717 } else {
1718 out += ' validate.errors = [' + (__err) + ']; return false; ';
1719 }
1720 } else {
1721 out += ' var err = ' + (__err) + '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ';
1722 }
1723 out += '} ';
1724 if ($breakOnError) {
1725 out += ' else { ';
1726 }
1727 return out;
1728}
1729
1730},{}],16:[function(require,module,exports){
1731'use strict';
1732module.exports = function generate__limitProperties(it, $keyword, $ruleType) {
1733 var out = ' ';
1734 var $lvl = it.level;
1735 var $dataLvl = it.dataLevel;
1736 var $schema = it.schema[$keyword];
1737 var $schemaPath = it.schemaPath + it.util.getProperty($keyword);
1738 var $errSchemaPath = it.errSchemaPath + '/' + $keyword;
1739 var $breakOnError = !it.opts.allErrors;
1740 var $errorKeyword;
1741 var $data = 'data' + ($dataLvl || '');
1742 var $isData = it.opts.$data && $schema && $schema.$data,
1743 $schemaValue;
1744 if ($isData) {
1745 out += ' var schema' + ($lvl) + ' = ' + (it.util.getData($schema.$data, $dataLvl, it.dataPathArr)) + '; ';
1746 $schemaValue = 'schema' + $lvl;
1747 } else {
1748 $schemaValue = $schema;
1749 }
1750 if (!($isData || typeof $schema == 'number')) {
1751 throw new Error($keyword + ' must be number');
1752 }
1753 var $op = $keyword == 'maxProperties' ? '>' : '<';
1754 out += 'if ( ';
1755 if ($isData) {
1756 out += ' (' + ($schemaValue) + ' !== undefined && typeof ' + ($schemaValue) + ' != \'number\') || ';
1757 }
1758 out += ' Object.keys(' + ($data) + ').length ' + ($op) + ' ' + ($schemaValue) + ') { ';
1759 var $errorKeyword = $keyword;
1760 var $$outStack = $$outStack || [];
1761 $$outStack.push(out);
1762 out = ''; /* istanbul ignore else */
1763 if (it.createErrors !== false) {
1764 out += ' { keyword: \'' + ($errorKeyword || '_limitProperties') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: ' + (it.util.toQuotedString($errSchemaPath)) + ' , params: { limit: ' + ($schemaValue) + ' } ';
1765 if (it.opts.messages !== false) {
1766 out += ' , message: \'should NOT have ';
1767 if ($keyword == 'maxProperties') {
1768 out += 'more';
1769 } else {
1770 out += 'fewer';
1771 }
1772 out += ' than ';
1773 if ($isData) {
1774 out += '\' + ' + ($schemaValue) + ' + \'';
1775 } else {
1776 out += '' + ($schema);
1777 }
1778 out += ' properties\' ';
1779 }
1780 if (it.opts.verbose) {
1781 out += ' , schema: ';
1782 if ($isData) {
1783 out += 'validate.schema' + ($schemaPath);
1784 } else {
1785 out += '' + ($schema);
1786 }
1787 out += ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' ';
1788 }
1789 out += ' } ';
1790 } else {
1791 out += ' {} ';
1792 }
1793 var __err = out;
1794 out = $$outStack.pop();
1795 if (!it.compositeRule && $breakOnError) {
1796 /* istanbul ignore if */
1797 if (it.async) {
1798 out += ' throw new ValidationError([' + (__err) + ']); ';
1799 } else {
1800 out += ' validate.errors = [' + (__err) + ']; return false; ';
1801 }
1802 } else {
1803 out += ' var err = ' + (__err) + '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ';
1804 }
1805 out += '} ';
1806 if ($breakOnError) {
1807 out += ' else { ';
1808 }
1809 return out;
1810}
1811
1812},{}],17:[function(require,module,exports){
1813'use strict';
1814module.exports = function generate_allOf(it, $keyword, $ruleType) {
1815 var out = ' ';
1816 var $schema = it.schema[$keyword];
1817 var $schemaPath = it.schemaPath + it.util.getProperty($keyword);
1818 var $errSchemaPath = it.errSchemaPath + '/' + $keyword;
1819 var $breakOnError = !it.opts.allErrors;
1820 var $it = it.util.copy(it);
1821 var $closingBraces = '';
1822 $it.level++;
1823 var $nextValid = 'valid' + $it.level;
1824 var $currentBaseId = $it.baseId,
1825 $allSchemasEmpty = true;
1826 var arr1 = $schema;
1827 if (arr1) {
1828 var $sch, $i = -1,
1829 l1 = arr1.length - 1;
1830 while ($i < l1) {
1831 $sch = arr1[$i += 1];
1832 if ((it.opts.strictKeywords ? (typeof $sch == 'object' && Object.keys($sch).length > 0) || $sch === false : it.util.schemaHasRules($sch, it.RULES.all))) {
1833 $allSchemasEmpty = false;
1834 $it.schema = $sch;
1835 $it.schemaPath = $schemaPath + '[' + $i + ']';
1836 $it.errSchemaPath = $errSchemaPath + '/' + $i;
1837 out += ' ' + (it.validate($it)) + ' ';
1838 $it.baseId = $currentBaseId;
1839 if ($breakOnError) {
1840 out += ' if (' + ($nextValid) + ') { ';
1841 $closingBraces += '}';
1842 }
1843 }
1844 }
1845 }
1846 if ($breakOnError) {
1847 if ($allSchemasEmpty) {
1848 out += ' if (true) { ';
1849 } else {
1850 out += ' ' + ($closingBraces.slice(0, -1)) + ' ';
1851 }
1852 }
1853 return out;
1854}
1855
1856},{}],18:[function(require,module,exports){
1857'use strict';
1858module.exports = function generate_anyOf(it, $keyword, $ruleType) {
1859 var out = ' ';
1860 var $lvl = it.level;
1861 var $dataLvl = it.dataLevel;
1862 var $schema = it.schema[$keyword];
1863 var $schemaPath = it.schemaPath + it.util.getProperty($keyword);
1864 var $errSchemaPath = it.errSchemaPath + '/' + $keyword;
1865 var $breakOnError = !it.opts.allErrors;
1866 var $data = 'data' + ($dataLvl || '');
1867 var $valid = 'valid' + $lvl;
1868 var $errs = 'errs__' + $lvl;
1869 var $it = it.util.copy(it);
1870 var $closingBraces = '';
1871 $it.level++;
1872 var $nextValid = 'valid' + $it.level;
1873 var $noEmptySchema = $schema.every(function($sch) {
1874 return (it.opts.strictKeywords ? (typeof $sch == 'object' && Object.keys($sch).length > 0) || $sch === false : it.util.schemaHasRules($sch, it.RULES.all));
1875 });
1876 if ($noEmptySchema) {
1877 var $currentBaseId = $it.baseId;
1878 out += ' var ' + ($errs) + ' = errors; var ' + ($valid) + ' = false; ';
1879 var $wasComposite = it.compositeRule;
1880 it.compositeRule = $it.compositeRule = true;
1881 var arr1 = $schema;
1882 if (arr1) {
1883 var $sch, $i = -1,
1884 l1 = arr1.length - 1;
1885 while ($i < l1) {
1886 $sch = arr1[$i += 1];
1887 $it.schema = $sch;
1888 $it.schemaPath = $schemaPath + '[' + $i + ']';
1889 $it.errSchemaPath = $errSchemaPath + '/' + $i;
1890 out += ' ' + (it.validate($it)) + ' ';
1891 $it.baseId = $currentBaseId;
1892 out += ' ' + ($valid) + ' = ' + ($valid) + ' || ' + ($nextValid) + '; if (!' + ($valid) + ') { ';
1893 $closingBraces += '}';
1894 }
1895 }
1896 it.compositeRule = $it.compositeRule = $wasComposite;
1897 out += ' ' + ($closingBraces) + ' if (!' + ($valid) + ') { var err = '; /* istanbul ignore else */
1898 if (it.createErrors !== false) {
1899 out += ' { keyword: \'' + ('anyOf') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: ' + (it.util.toQuotedString($errSchemaPath)) + ' , params: {} ';
1900 if (it.opts.messages !== false) {
1901 out += ' , message: \'should match some schema in anyOf\' ';
1902 }
1903 if (it.opts.verbose) {
1904 out += ' , schema: validate.schema' + ($schemaPath) + ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' ';
1905 }
1906 out += ' } ';
1907 } else {
1908 out += ' {} ';
1909 }
1910 out += '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ';
1911 if (!it.compositeRule && $breakOnError) {
1912 /* istanbul ignore if */
1913 if (it.async) {
1914 out += ' throw new ValidationError(vErrors); ';
1915 } else {
1916 out += ' validate.errors = vErrors; return false; ';
1917 }
1918 }
1919 out += ' } else { errors = ' + ($errs) + '; if (vErrors !== null) { if (' + ($errs) + ') vErrors.length = ' + ($errs) + '; else vErrors = null; } ';
1920 if (it.opts.allErrors) {
1921 out += ' } ';
1922 }
1923 } else {
1924 if ($breakOnError) {
1925 out += ' if (true) { ';
1926 }
1927 }
1928 return out;
1929}
1930
1931},{}],19:[function(require,module,exports){
1932'use strict';
1933module.exports = function generate_comment(it, $keyword, $ruleType) {
1934 var out = ' ';
1935 var $schema = it.schema[$keyword];
1936 var $errSchemaPath = it.errSchemaPath + '/' + $keyword;
1937 var $breakOnError = !it.opts.allErrors;
1938 var $comment = it.util.toQuotedString($schema);
1939 if (it.opts.$comment === true) {
1940 out += ' console.log(' + ($comment) + ');';
1941 } else if (typeof it.opts.$comment == 'function') {
1942 out += ' self._opts.$comment(' + ($comment) + ', ' + (it.util.toQuotedString($errSchemaPath)) + ', validate.root.schema);';
1943 }
1944 return out;
1945}
1946
1947},{}],20:[function(require,module,exports){
1948'use strict';
1949module.exports = function generate_const(it, $keyword, $ruleType) {
1950 var out = ' ';
1951 var $lvl = it.level;
1952 var $dataLvl = it.dataLevel;
1953 var $schema = it.schema[$keyword];
1954 var $schemaPath = it.schemaPath + it.util.getProperty($keyword);
1955 var $errSchemaPath = it.errSchemaPath + '/' + $keyword;
1956 var $breakOnError = !it.opts.allErrors;
1957 var $data = 'data' + ($dataLvl || '');
1958 var $valid = 'valid' + $lvl;
1959 var $isData = it.opts.$data && $schema && $schema.$data,
1960 $schemaValue;
1961 if ($isData) {
1962 out += ' var schema' + ($lvl) + ' = ' + (it.util.getData($schema.$data, $dataLvl, it.dataPathArr)) + '; ';
1963 $schemaValue = 'schema' + $lvl;
1964 } else {
1965 $schemaValue = $schema;
1966 }
1967 if (!$isData) {
1968 out += ' var schema' + ($lvl) + ' = validate.schema' + ($schemaPath) + ';';
1969 }
1970 out += 'var ' + ($valid) + ' = equal(' + ($data) + ', schema' + ($lvl) + '); if (!' + ($valid) + ') { ';
1971 var $$outStack = $$outStack || [];
1972 $$outStack.push(out);
1973 out = ''; /* istanbul ignore else */
1974 if (it.createErrors !== false) {
1975 out += ' { keyword: \'' + ('const') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: ' + (it.util.toQuotedString($errSchemaPath)) + ' , params: { allowedValue: schema' + ($lvl) + ' } ';
1976 if (it.opts.messages !== false) {
1977 out += ' , message: \'should be equal to constant\' ';
1978 }
1979 if (it.opts.verbose) {
1980 out += ' , schema: validate.schema' + ($schemaPath) + ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' ';
1981 }
1982 out += ' } ';
1983 } else {
1984 out += ' {} ';
1985 }
1986 var __err = out;
1987 out = $$outStack.pop();
1988 if (!it.compositeRule && $breakOnError) {
1989 /* istanbul ignore if */
1990 if (it.async) {
1991 out += ' throw new ValidationError([' + (__err) + ']); ';
1992 } else {
1993 out += ' validate.errors = [' + (__err) + ']; return false; ';
1994 }
1995 } else {
1996 out += ' var err = ' + (__err) + '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ';
1997 }
1998 out += ' }';
1999 if ($breakOnError) {
2000 out += ' else { ';
2001 }
2002 return out;
2003}
2004
2005},{}],21:[function(require,module,exports){
2006'use strict';
2007module.exports = function generate_contains(it, $keyword, $ruleType) {
2008 var out = ' ';
2009 var $lvl = it.level;
2010 var $dataLvl = it.dataLevel;
2011 var $schema = it.schema[$keyword];
2012 var $schemaPath = it.schemaPath + it.util.getProperty($keyword);
2013 var $errSchemaPath = it.errSchemaPath + '/' + $keyword;
2014 var $breakOnError = !it.opts.allErrors;
2015 var $data = 'data' + ($dataLvl || '');
2016 var $valid = 'valid' + $lvl;
2017 var $errs = 'errs__' + $lvl;
2018 var $it = it.util.copy(it);
2019 var $closingBraces = '';
2020 $it.level++;
2021 var $nextValid = 'valid' + $it.level;
2022 var $idx = 'i' + $lvl,
2023 $dataNxt = $it.dataLevel = it.dataLevel + 1,
2024 $nextData = 'data' + $dataNxt,
2025 $currentBaseId = it.baseId,
2026 $nonEmptySchema = (it.opts.strictKeywords ? (typeof $schema == 'object' && Object.keys($schema).length > 0) || $schema === false : it.util.schemaHasRules($schema, it.RULES.all));
2027 out += 'var ' + ($errs) + ' = errors;var ' + ($valid) + ';';
2028 if ($nonEmptySchema) {
2029 var $wasComposite = it.compositeRule;
2030 it.compositeRule = $it.compositeRule = true;
2031 $it.schema = $schema;
2032 $it.schemaPath = $schemaPath;
2033 $it.errSchemaPath = $errSchemaPath;
2034 out += ' var ' + ($nextValid) + ' = false; for (var ' + ($idx) + ' = 0; ' + ($idx) + ' < ' + ($data) + '.length; ' + ($idx) + '++) { ';
2035 $it.errorPath = it.util.getPathExpr(it.errorPath, $idx, it.opts.jsonPointers, true);
2036 var $passData = $data + '[' + $idx + ']';
2037 $it.dataPathArr[$dataNxt] = $idx;
2038 var $code = it.validate($it);
2039 $it.baseId = $currentBaseId;
2040 if (it.util.varOccurences($code, $nextData) < 2) {
2041 out += ' ' + (it.util.varReplace($code, $nextData, $passData)) + ' ';
2042 } else {
2043 out += ' var ' + ($nextData) + ' = ' + ($passData) + '; ' + ($code) + ' ';
2044 }
2045 out += ' if (' + ($nextValid) + ') break; } ';
2046 it.compositeRule = $it.compositeRule = $wasComposite;
2047 out += ' ' + ($closingBraces) + ' if (!' + ($nextValid) + ') {';
2048 } else {
2049 out += ' if (' + ($data) + '.length == 0) {';
2050 }
2051 var $$outStack = $$outStack || [];
2052 $$outStack.push(out);
2053 out = ''; /* istanbul ignore else */
2054 if (it.createErrors !== false) {
2055 out += ' { keyword: \'' + ('contains') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: ' + (it.util.toQuotedString($errSchemaPath)) + ' , params: {} ';
2056 if (it.opts.messages !== false) {
2057 out += ' , message: \'should contain a valid item\' ';
2058 }
2059 if (it.opts.verbose) {
2060 out += ' , schema: validate.schema' + ($schemaPath) + ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' ';
2061 }
2062 out += ' } ';
2063 } else {
2064 out += ' {} ';
2065 }
2066 var __err = out;
2067 out = $$outStack.pop();
2068 if (!it.compositeRule && $breakOnError) {
2069 /* istanbul ignore if */
2070 if (it.async) {
2071 out += ' throw new ValidationError([' + (__err) + ']); ';
2072 } else {
2073 out += ' validate.errors = [' + (__err) + ']; return false; ';
2074 }
2075 } else {
2076 out += ' var err = ' + (__err) + '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ';
2077 }
2078 out += ' } else { ';
2079 if ($nonEmptySchema) {
2080 out += ' errors = ' + ($errs) + '; if (vErrors !== null) { if (' + ($errs) + ') vErrors.length = ' + ($errs) + '; else vErrors = null; } ';
2081 }
2082 if (it.opts.allErrors) {
2083 out += ' } ';
2084 }
2085 return out;
2086}
2087
2088},{}],22:[function(require,module,exports){
2089'use strict';
2090module.exports = function generate_custom(it, $keyword, $ruleType) {
2091 var out = ' ';
2092 var $lvl = it.level;
2093 var $dataLvl = it.dataLevel;
2094 var $schema = it.schema[$keyword];
2095 var $schemaPath = it.schemaPath + it.util.getProperty($keyword);
2096 var $errSchemaPath = it.errSchemaPath + '/' + $keyword;
2097 var $breakOnError = !it.opts.allErrors;
2098 var $errorKeyword;
2099 var $data = 'data' + ($dataLvl || '');
2100 var $valid = 'valid' + $lvl;
2101 var $errs = 'errs__' + $lvl;
2102 var $isData = it.opts.$data && $schema && $schema.$data,
2103 $schemaValue;
2104 if ($isData) {
2105 out += ' var schema' + ($lvl) + ' = ' + (it.util.getData($schema.$data, $dataLvl, it.dataPathArr)) + '; ';
2106 $schemaValue = 'schema' + $lvl;
2107 } else {
2108 $schemaValue = $schema;
2109 }
2110 var $rule = this,
2111 $definition = 'definition' + $lvl,
2112 $rDef = $rule.definition,
2113 $closingBraces = '';
2114 var $compile, $inline, $macro, $ruleValidate, $validateCode;
2115 if ($isData && $rDef.$data) {
2116 $validateCode = 'keywordValidate' + $lvl;
2117 var $validateSchema = $rDef.validateSchema;
2118 out += ' var ' + ($definition) + ' = RULES.custom[\'' + ($keyword) + '\'].definition; var ' + ($validateCode) + ' = ' + ($definition) + '.validate;';
2119 } else {
2120 $ruleValidate = it.useCustomRule($rule, $schema, it.schema, it);
2121 if (!$ruleValidate) return;
2122 $schemaValue = 'validate.schema' + $schemaPath;
2123 $validateCode = $ruleValidate.code;
2124 $compile = $rDef.compile;
2125 $inline = $rDef.inline;
2126 $macro = $rDef.macro;
2127 }
2128 var $ruleErrs = $validateCode + '.errors',
2129 $i = 'i' + $lvl,
2130 $ruleErr = 'ruleErr' + $lvl,
2131 $asyncKeyword = $rDef.async;
2132 if ($asyncKeyword && !it.async) throw new Error('async keyword in sync schema');
2133 if (!($inline || $macro)) {
2134 out += '' + ($ruleErrs) + ' = null;';
2135 }
2136 out += 'var ' + ($errs) + ' = errors;var ' + ($valid) + ';';
2137 if ($isData && $rDef.$data) {
2138 $closingBraces += '}';
2139 out += ' if (' + ($schemaValue) + ' === undefined) { ' + ($valid) + ' = true; } else { ';
2140 if ($validateSchema) {
2141 $closingBraces += '}';
2142 out += ' ' + ($valid) + ' = ' + ($definition) + '.validateSchema(' + ($schemaValue) + '); if (' + ($valid) + ') { ';
2143 }
2144 }
2145 if ($inline) {
2146 if ($rDef.statements) {
2147 out += ' ' + ($ruleValidate.validate) + ' ';
2148 } else {
2149 out += ' ' + ($valid) + ' = ' + ($ruleValidate.validate) + '; ';
2150 }
2151 } else if ($macro) {
2152 var $it = it.util.copy(it);
2153 var $closingBraces = '';
2154 $it.level++;
2155 var $nextValid = 'valid' + $it.level;
2156 $it.schema = $ruleValidate.validate;
2157 $it.schemaPath = '';
2158 var $wasComposite = it.compositeRule;
2159 it.compositeRule = $it.compositeRule = true;
2160 var $code = it.validate($it).replace(/validate\.schema/g, $validateCode);
2161 it.compositeRule = $it.compositeRule = $wasComposite;
2162 out += ' ' + ($code);
2163 } else {
2164 var $$outStack = $$outStack || [];
2165 $$outStack.push(out);
2166 out = '';
2167 out += ' ' + ($validateCode) + '.call( ';
2168 if (it.opts.passContext) {
2169 out += 'this';
2170 } else {
2171 out += 'self';
2172 }
2173 if ($compile || $rDef.schema === false) {
2174 out += ' , ' + ($data) + ' ';
2175 } else {
2176 out += ' , ' + ($schemaValue) + ' , ' + ($data) + ' , validate.schema' + (it.schemaPath) + ' ';
2177 }
2178 out += ' , (dataPath || \'\')';
2179 if (it.errorPath != '""') {
2180 out += ' + ' + (it.errorPath);
2181 }
2182 var $parentData = $dataLvl ? 'data' + (($dataLvl - 1) || '') : 'parentData',
2183 $parentDataProperty = $dataLvl ? it.dataPathArr[$dataLvl] : 'parentDataProperty';
2184 out += ' , ' + ($parentData) + ' , ' + ($parentDataProperty) + ' , rootData ) ';
2185 var def_callRuleValidate = out;
2186 out = $$outStack.pop();
2187 if ($rDef.errors === false) {
2188 out += ' ' + ($valid) + ' = ';
2189 if ($asyncKeyword) {
2190 out += 'await ';
2191 }
2192 out += '' + (def_callRuleValidate) + '; ';
2193 } else {
2194 if ($asyncKeyword) {
2195 $ruleErrs = 'customErrors' + $lvl;
2196 out += ' var ' + ($ruleErrs) + ' = null; try { ' + ($valid) + ' = await ' + (def_callRuleValidate) + '; } catch (e) { ' + ($valid) + ' = false; if (e instanceof ValidationError) ' + ($ruleErrs) + ' = e.errors; else throw e; } ';
2197 } else {
2198 out += ' ' + ($ruleErrs) + ' = null; ' + ($valid) + ' = ' + (def_callRuleValidate) + '; ';
2199 }
2200 }
2201 }
2202 if ($rDef.modifying) {
2203 out += ' if (' + ($parentData) + ') ' + ($data) + ' = ' + ($parentData) + '[' + ($parentDataProperty) + '];';
2204 }
2205 out += '' + ($closingBraces);
2206 if ($rDef.valid) {
2207 if ($breakOnError) {
2208 out += ' if (true) { ';
2209 }
2210 } else {
2211 out += ' if ( ';
2212 if ($rDef.valid === undefined) {
2213 out += ' !';
2214 if ($macro) {
2215 out += '' + ($nextValid);
2216 } else {
2217 out += '' + ($valid);
2218 }
2219 } else {
2220 out += ' ' + (!$rDef.valid) + ' ';
2221 }
2222 out += ') { ';
2223 $errorKeyword = $rule.keyword;
2224 var $$outStack = $$outStack || [];
2225 $$outStack.push(out);
2226 out = '';
2227 var $$outStack = $$outStack || [];
2228 $$outStack.push(out);
2229 out = ''; /* istanbul ignore else */
2230 if (it.createErrors !== false) {
2231 out += ' { keyword: \'' + ($errorKeyword || 'custom') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: ' + (it.util.toQuotedString($errSchemaPath)) + ' , params: { keyword: \'' + ($rule.keyword) + '\' } ';
2232 if (it.opts.messages !== false) {
2233 out += ' , message: \'should pass "' + ($rule.keyword) + '" keyword validation\' ';
2234 }
2235 if (it.opts.verbose) {
2236 out += ' , schema: validate.schema' + ($schemaPath) + ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' ';
2237 }
2238 out += ' } ';
2239 } else {
2240 out += ' {} ';
2241 }
2242 var __err = out;
2243 out = $$outStack.pop();
2244 if (!it.compositeRule && $breakOnError) {
2245 /* istanbul ignore if */
2246 if (it.async) {
2247 out += ' throw new ValidationError([' + (__err) + ']); ';
2248 } else {
2249 out += ' validate.errors = [' + (__err) + ']; return false; ';
2250 }
2251 } else {
2252 out += ' var err = ' + (__err) + '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ';
2253 }
2254 var def_customError = out;
2255 out = $$outStack.pop();
2256 if ($inline) {
2257 if ($rDef.errors) {
2258 if ($rDef.errors != 'full') {
2259 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) + '"; } ';
2260 if (it.opts.verbose) {
2261 out += ' ' + ($ruleErr) + '.schema = ' + ($schemaValue) + '; ' + ($ruleErr) + '.data = ' + ($data) + '; ';
2262 }
2263 out += ' } ';
2264 }
2265 } else {
2266 if ($rDef.errors === false) {
2267 out += ' ' + (def_customError) + ' ';
2268 } else {
2269 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) + '"; } ';
2270 if (it.opts.verbose) {
2271 out += ' ' + ($ruleErr) + '.schema = ' + ($schemaValue) + '; ' + ($ruleErr) + '.data = ' + ($data) + '; ';
2272 }
2273 out += ' } } ';
2274 }
2275 }
2276 } else if ($macro) {
2277 out += ' var err = '; /* istanbul ignore else */
2278 if (it.createErrors !== false) {
2279 out += ' { keyword: \'' + ($errorKeyword || 'custom') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: ' + (it.util.toQuotedString($errSchemaPath)) + ' , params: { keyword: \'' + ($rule.keyword) + '\' } ';
2280 if (it.opts.messages !== false) {
2281 out += ' , message: \'should pass "' + ($rule.keyword) + '" keyword validation\' ';
2282 }
2283 if (it.opts.verbose) {
2284 out += ' , schema: validate.schema' + ($schemaPath) + ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' ';
2285 }
2286 out += ' } ';
2287 } else {
2288 out += ' {} ';
2289 }
2290 out += '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ';
2291 if (!it.compositeRule && $breakOnError) {
2292 /* istanbul ignore if */
2293 if (it.async) {
2294 out += ' throw new ValidationError(vErrors); ';
2295 } else {
2296 out += ' validate.errors = vErrors; return false; ';
2297 }
2298 }
2299 } else {
2300 if ($rDef.errors === false) {
2301 out += ' ' + (def_customError) + ' ';
2302 } else {
2303 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) + '"; ';
2304 if (it.opts.verbose) {
2305 out += ' ' + ($ruleErr) + '.schema = ' + ($schemaValue) + '; ' + ($ruleErr) + '.data = ' + ($data) + '; ';
2306 }
2307 out += ' } } else { ' + (def_customError) + ' } ';
2308 }
2309 }
2310 out += ' } ';
2311 if ($breakOnError) {
2312 out += ' else { ';
2313 }
2314 }
2315 return out;
2316}
2317
2318},{}],23:[function(require,module,exports){
2319'use strict';
2320module.exports = function generate_dependencies(it, $keyword, $ruleType) {
2321 var out = ' ';
2322 var $lvl = it.level;
2323 var $dataLvl = it.dataLevel;
2324 var $schema = it.schema[$keyword];
2325 var $schemaPath = it.schemaPath + it.util.getProperty($keyword);
2326 var $errSchemaPath = it.errSchemaPath + '/' + $keyword;
2327 var $breakOnError = !it.opts.allErrors;
2328 var $data = 'data' + ($dataLvl || '');
2329 var $errs = 'errs__' + $lvl;
2330 var $it = it.util.copy(it);
2331 var $closingBraces = '';
2332 $it.level++;
2333 var $nextValid = 'valid' + $it.level;
2334 var $schemaDeps = {},
2335 $propertyDeps = {},
2336 $ownProperties = it.opts.ownProperties;
2337 for ($property in $schema) {
2338 if ($property == '__proto__') continue;
2339 var $sch = $schema[$property];
2340 var $deps = Array.isArray($sch) ? $propertyDeps : $schemaDeps;
2341 $deps[$property] = $sch;
2342 }
2343 out += 'var ' + ($errs) + ' = errors;';
2344 var $currentErrorPath = it.errorPath;
2345 out += 'var missing' + ($lvl) + ';';
2346 for (var $property in $propertyDeps) {
2347 $deps = $propertyDeps[$property];
2348 if ($deps.length) {
2349 out += ' if ( ' + ($data) + (it.util.getProperty($property)) + ' !== undefined ';
2350 if ($ownProperties) {
2351 out += ' && Object.prototype.hasOwnProperty.call(' + ($data) + ', \'' + (it.util.escapeQuotes($property)) + '\') ';
2352 }
2353 if ($breakOnError) {
2354 out += ' && ( ';
2355 var arr1 = $deps;
2356 if (arr1) {
2357 var $propertyKey, $i = -1,
2358 l1 = arr1.length - 1;
2359 while ($i < l1) {
2360 $propertyKey = arr1[$i += 1];
2361 if ($i) {
2362 out += ' || ';
2363 }
2364 var $prop = it.util.getProperty($propertyKey),
2365 $useData = $data + $prop;
2366 out += ' ( ( ' + ($useData) + ' === undefined ';
2367 if ($ownProperties) {
2368 out += ' || ! Object.prototype.hasOwnProperty.call(' + ($data) + ', \'' + (it.util.escapeQuotes($propertyKey)) + '\') ';
2369 }
2370 out += ') && (missing' + ($lvl) + ' = ' + (it.util.toQuotedString(it.opts.jsonPointers ? $propertyKey : $prop)) + ') ) ';
2371 }
2372 }
2373 out += ')) { ';
2374 var $propertyPath = 'missing' + $lvl,
2375 $missingProperty = '\' + ' + $propertyPath + ' + \'';
2376 if (it.opts._errorDataPathProperty) {
2377 it.errorPath = it.opts.jsonPointers ? it.util.getPathExpr($currentErrorPath, $propertyPath, true) : $currentErrorPath + ' + ' + $propertyPath;
2378 }
2379 var $$outStack = $$outStack || [];
2380 $$outStack.push(out);
2381 out = ''; /* istanbul ignore else */
2382 if (it.createErrors !== false) {
2383 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(", "))) + '\' } ';
2384 if (it.opts.messages !== false) {
2385 out += ' , message: \'should have ';
2386 if ($deps.length == 1) {
2387 out += 'property ' + (it.util.escapeQuotes($deps[0]));
2388 } else {
2389 out += 'properties ' + (it.util.escapeQuotes($deps.join(", ")));
2390 }
2391 out += ' when property ' + (it.util.escapeQuotes($property)) + ' is present\' ';
2392 }
2393 if (it.opts.verbose) {
2394 out += ' , schema: validate.schema' + ($schemaPath) + ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' ';
2395 }
2396 out += ' } ';
2397 } else {
2398 out += ' {} ';
2399 }
2400 var __err = out;
2401 out = $$outStack.pop();
2402 if (!it.compositeRule && $breakOnError) {
2403 /* istanbul ignore if */
2404 if (it.async) {
2405 out += ' throw new ValidationError([' + (__err) + ']); ';
2406 } else {
2407 out += ' validate.errors = [' + (__err) + ']; return false; ';
2408 }
2409 } else {
2410 out += ' var err = ' + (__err) + '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ';
2411 }
2412 } else {
2413 out += ' ) { ';
2414 var arr2 = $deps;
2415 if (arr2) {
2416 var $propertyKey, i2 = -1,
2417 l2 = arr2.length - 1;
2418 while (i2 < l2) {
2419 $propertyKey = arr2[i2 += 1];
2420 var $prop = it.util.getProperty($propertyKey),
2421 $missingProperty = it.util.escapeQuotes($propertyKey),
2422 $useData = $data + $prop;
2423 if (it.opts._errorDataPathProperty) {
2424 it.errorPath = it.util.getPath($currentErrorPath, $propertyKey, it.opts.jsonPointers);
2425 }
2426 out += ' if ( ' + ($useData) + ' === undefined ';
2427 if ($ownProperties) {
2428 out += ' || ! Object.prototype.hasOwnProperty.call(' + ($data) + ', \'' + (it.util.escapeQuotes($propertyKey)) + '\') ';
2429 }
2430 out += ') { var err = '; /* istanbul ignore else */
2431 if (it.createErrors !== false) {
2432 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(", "))) + '\' } ';
2433 if (it.opts.messages !== false) {
2434 out += ' , message: \'should have ';
2435 if ($deps.length == 1) {
2436 out += 'property ' + (it.util.escapeQuotes($deps[0]));
2437 } else {
2438 out += 'properties ' + (it.util.escapeQuotes($deps.join(", ")));
2439 }
2440 out += ' when property ' + (it.util.escapeQuotes($property)) + ' is present\' ';
2441 }
2442 if (it.opts.verbose) {
2443 out += ' , schema: validate.schema' + ($schemaPath) + ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' ';
2444 }
2445 out += ' } ';
2446 } else {
2447 out += ' {} ';
2448 }
2449 out += '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; } ';
2450 }
2451 }
2452 }
2453 out += ' } ';
2454 if ($breakOnError) {
2455 $closingBraces += '}';
2456 out += ' else { ';
2457 }
2458 }
2459 }
2460 it.errorPath = $currentErrorPath;
2461 var $currentBaseId = $it.baseId;
2462 for (var $property in $schemaDeps) {
2463 var $sch = $schemaDeps[$property];
2464 if ((it.opts.strictKeywords ? (typeof $sch == 'object' && Object.keys($sch).length > 0) || $sch === false : it.util.schemaHasRules($sch, it.RULES.all))) {
2465 out += ' ' + ($nextValid) + ' = true; if ( ' + ($data) + (it.util.getProperty($property)) + ' !== undefined ';
2466 if ($ownProperties) {
2467 out += ' && Object.prototype.hasOwnProperty.call(' + ($data) + ', \'' + (it.util.escapeQuotes($property)) + '\') ';
2468 }
2469 out += ') { ';
2470 $it.schema = $sch;
2471 $it.schemaPath = $schemaPath + it.util.getProperty($property);
2472 $it.errSchemaPath = $errSchemaPath + '/' + it.util.escapeFragment($property);
2473 out += ' ' + (it.validate($it)) + ' ';
2474 $it.baseId = $currentBaseId;
2475 out += ' } ';
2476 if ($breakOnError) {
2477 out += ' if (' + ($nextValid) + ') { ';
2478 $closingBraces += '}';
2479 }
2480 }
2481 }
2482 if ($breakOnError) {
2483 out += ' ' + ($closingBraces) + ' if (' + ($errs) + ' == errors) {';
2484 }
2485 return out;
2486}
2487
2488},{}],24:[function(require,module,exports){
2489'use strict';
2490module.exports = function generate_enum(it, $keyword, $ruleType) {
2491 var out = ' ';
2492 var $lvl = it.level;
2493 var $dataLvl = it.dataLevel;
2494 var $schema = it.schema[$keyword];
2495 var $schemaPath = it.schemaPath + it.util.getProperty($keyword);
2496 var $errSchemaPath = it.errSchemaPath + '/' + $keyword;
2497 var $breakOnError = !it.opts.allErrors;
2498 var $data = 'data' + ($dataLvl || '');
2499 var $valid = 'valid' + $lvl;
2500 var $isData = it.opts.$data && $schema && $schema.$data,
2501 $schemaValue;
2502 if ($isData) {
2503 out += ' var schema' + ($lvl) + ' = ' + (it.util.getData($schema.$data, $dataLvl, it.dataPathArr)) + '; ';
2504 $schemaValue = 'schema' + $lvl;
2505 } else {
2506 $schemaValue = $schema;
2507 }
2508 var $i = 'i' + $lvl,
2509 $vSchema = 'schema' + $lvl;
2510 if (!$isData) {
2511 out += ' var ' + ($vSchema) + ' = validate.schema' + ($schemaPath) + ';';
2512 }
2513 out += 'var ' + ($valid) + ';';
2514 if ($isData) {
2515 out += ' if (schema' + ($lvl) + ' === undefined) ' + ($valid) + ' = true; else if (!Array.isArray(schema' + ($lvl) + ')) ' + ($valid) + ' = false; else {';
2516 }
2517 out += '' + ($valid) + ' = false;for (var ' + ($i) + '=0; ' + ($i) + '<' + ($vSchema) + '.length; ' + ($i) + '++) if (equal(' + ($data) + ', ' + ($vSchema) + '[' + ($i) + '])) { ' + ($valid) + ' = true; break; }';
2518 if ($isData) {
2519 out += ' } ';
2520 }
2521 out += ' if (!' + ($valid) + ') { ';
2522 var $$outStack = $$outStack || [];
2523 $$outStack.push(out);
2524 out = ''; /* istanbul ignore else */
2525 if (it.createErrors !== false) {
2526 out += ' { keyword: \'' + ('enum') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: ' + (it.util.toQuotedString($errSchemaPath)) + ' , params: { allowedValues: schema' + ($lvl) + ' } ';
2527 if (it.opts.messages !== false) {
2528 out += ' , message: \'should be equal to one of the allowed values\' ';
2529 }
2530 if (it.opts.verbose) {
2531 out += ' , schema: validate.schema' + ($schemaPath) + ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' ';
2532 }
2533 out += ' } ';
2534 } else {
2535 out += ' {} ';
2536 }
2537 var __err = out;
2538 out = $$outStack.pop();
2539 if (!it.compositeRule && $breakOnError) {
2540 /* istanbul ignore if */
2541 if (it.async) {
2542 out += ' throw new ValidationError([' + (__err) + ']); ';
2543 } else {
2544 out += ' validate.errors = [' + (__err) + ']; return false; ';
2545 }
2546 } else {
2547 out += ' var err = ' + (__err) + '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ';
2548 }
2549 out += ' }';
2550 if ($breakOnError) {
2551 out += ' else { ';
2552 }
2553 return out;
2554}
2555
2556},{}],25:[function(require,module,exports){
2557'use strict';
2558module.exports = function generate_format(it, $keyword, $ruleType) {
2559 var out = ' ';
2560 var $lvl = it.level;
2561 var $dataLvl = it.dataLevel;
2562 var $schema = it.schema[$keyword];
2563 var $schemaPath = it.schemaPath + it.util.getProperty($keyword);
2564 var $errSchemaPath = it.errSchemaPath + '/' + $keyword;
2565 var $breakOnError = !it.opts.allErrors;
2566 var $data = 'data' + ($dataLvl || '');
2567 if (it.opts.format === false) {
2568 if ($breakOnError) {
2569 out += ' if (true) { ';
2570 }
2571 return out;
2572 }
2573 var $isData = it.opts.$data && $schema && $schema.$data,
2574 $schemaValue;
2575 if ($isData) {
2576 out += ' var schema' + ($lvl) + ' = ' + (it.util.getData($schema.$data, $dataLvl, it.dataPathArr)) + '; ';
2577 $schemaValue = 'schema' + $lvl;
2578 } else {
2579 $schemaValue = $schema;
2580 }
2581 var $unknownFormats = it.opts.unknownFormats,
2582 $allowUnknown = Array.isArray($unknownFormats);
2583 if ($isData) {
2584 var $format = 'format' + $lvl,
2585 $isObject = 'isObject' + $lvl,
2586 $formatType = 'formatType' + $lvl;
2587 out += ' var ' + ($format) + ' = formats[' + ($schemaValue) + ']; var ' + ($isObject) + ' = typeof ' + ($format) + ' == \'object\' && !(' + ($format) + ' instanceof RegExp) && ' + ($format) + '.validate; var ' + ($formatType) + ' = ' + ($isObject) + ' && ' + ($format) + '.type || \'string\'; if (' + ($isObject) + ') { ';
2588 if (it.async) {
2589 out += ' var async' + ($lvl) + ' = ' + ($format) + '.async; ';
2590 }
2591 out += ' ' + ($format) + ' = ' + ($format) + '.validate; } if ( ';
2592 if ($isData) {
2593 out += ' (' + ($schemaValue) + ' !== undefined && typeof ' + ($schemaValue) + ' != \'string\') || ';
2594 }
2595 out += ' (';
2596 if ($unknownFormats != 'ignore') {
2597 out += ' (' + ($schemaValue) + ' && !' + ($format) + ' ';
2598 if ($allowUnknown) {
2599 out += ' && self._opts.unknownFormats.indexOf(' + ($schemaValue) + ') == -1 ';
2600 }
2601 out += ') || ';
2602 }
2603 out += ' (' + ($format) + ' && ' + ($formatType) + ' == \'' + ($ruleType) + '\' && !(typeof ' + ($format) + ' == \'function\' ? ';
2604 if (it.async) {
2605 out += ' (async' + ($lvl) + ' ? await ' + ($format) + '(' + ($data) + ') : ' + ($format) + '(' + ($data) + ')) ';
2606 } else {
2607 out += ' ' + ($format) + '(' + ($data) + ') ';
2608 }
2609 out += ' : ' + ($format) + '.test(' + ($data) + '))))) {';
2610 } else {
2611 var $format = it.formats[$schema];
2612 if (!$format) {
2613 if ($unknownFormats == 'ignore') {
2614 it.logger.warn('unknown format "' + $schema + '" ignored in schema at path "' + it.errSchemaPath + '"');
2615 if ($breakOnError) {
2616 out += ' if (true) { ';
2617 }
2618 return out;
2619 } else if ($allowUnknown && $unknownFormats.indexOf($schema) >= 0) {
2620 if ($breakOnError) {
2621 out += ' if (true) { ';
2622 }
2623 return out;
2624 } else {
2625 throw new Error('unknown format "' + $schema + '" is used in schema at path "' + it.errSchemaPath + '"');
2626 }
2627 }
2628 var $isObject = typeof $format == 'object' && !($format instanceof RegExp) && $format.validate;
2629 var $formatType = $isObject && $format.type || 'string';
2630 if ($isObject) {
2631 var $async = $format.async === true;
2632 $format = $format.validate;
2633 }
2634 if ($formatType != $ruleType) {
2635 if ($breakOnError) {
2636 out += ' if (true) { ';
2637 }
2638 return out;
2639 }
2640 if ($async) {
2641 if (!it.async) throw new Error('async format in sync schema');
2642 var $formatRef = 'formats' + it.util.getProperty($schema) + '.validate';
2643 out += ' if (!(await ' + ($formatRef) + '(' + ($data) + '))) { ';
2644 } else {
2645 out += ' if (! ';
2646 var $formatRef = 'formats' + it.util.getProperty($schema);
2647 if ($isObject) $formatRef += '.validate';
2648 if (typeof $format == 'function') {
2649 out += ' ' + ($formatRef) + '(' + ($data) + ') ';
2650 } else {
2651 out += ' ' + ($formatRef) + '.test(' + ($data) + ') ';
2652 }
2653 out += ') { ';
2654 }
2655 }
2656 var $$outStack = $$outStack || [];
2657 $$outStack.push(out);
2658 out = ''; /* istanbul ignore else */
2659 if (it.createErrors !== false) {
2660 out += ' { keyword: \'' + ('format') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: ' + (it.util.toQuotedString($errSchemaPath)) + ' , params: { format: ';
2661 if ($isData) {
2662 out += '' + ($schemaValue);
2663 } else {
2664 out += '' + (it.util.toQuotedString($schema));
2665 }
2666 out += ' } ';
2667 if (it.opts.messages !== false) {
2668 out += ' , message: \'should match format "';
2669 if ($isData) {
2670 out += '\' + ' + ($schemaValue) + ' + \'';
2671 } else {
2672 out += '' + (it.util.escapeQuotes($schema));
2673 }
2674 out += '"\' ';
2675 }
2676 if (it.opts.verbose) {
2677 out += ' , schema: ';
2678 if ($isData) {
2679 out += 'validate.schema' + ($schemaPath);
2680 } else {
2681 out += '' + (it.util.toQuotedString($schema));
2682 }
2683 out += ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' ';
2684 }
2685 out += ' } ';
2686 } else {
2687 out += ' {} ';
2688 }
2689 var __err = out;
2690 out = $$outStack.pop();
2691 if (!it.compositeRule && $breakOnError) {
2692 /* istanbul ignore if */
2693 if (it.async) {
2694 out += ' throw new ValidationError([' + (__err) + ']); ';
2695 } else {
2696 out += ' validate.errors = [' + (__err) + ']; return false; ';
2697 }
2698 } else {
2699 out += ' var err = ' + (__err) + '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ';
2700 }
2701 out += ' } ';
2702 if ($breakOnError) {
2703 out += ' else { ';
2704 }
2705 return out;
2706}
2707
2708},{}],26:[function(require,module,exports){
2709'use strict';
2710module.exports = function generate_if(it, $keyword, $ruleType) {
2711 var out = ' ';
2712 var $lvl = it.level;
2713 var $dataLvl = it.dataLevel;
2714 var $schema = it.schema[$keyword];
2715 var $schemaPath = it.schemaPath + it.util.getProperty($keyword);
2716 var $errSchemaPath = it.errSchemaPath + '/' + $keyword;
2717 var $breakOnError = !it.opts.allErrors;
2718 var $data = 'data' + ($dataLvl || '');
2719 var $valid = 'valid' + $lvl;
2720 var $errs = 'errs__' + $lvl;
2721 var $it = it.util.copy(it);
2722 $it.level++;
2723 var $nextValid = 'valid' + $it.level;
2724 var $thenSch = it.schema['then'],
2725 $elseSch = it.schema['else'],
2726 $thenPresent = $thenSch !== undefined && (it.opts.strictKeywords ? (typeof $thenSch == 'object' && Object.keys($thenSch).length > 0) || $thenSch === false : it.util.schemaHasRules($thenSch, it.RULES.all)),
2727 $elsePresent = $elseSch !== undefined && (it.opts.strictKeywords ? (typeof $elseSch == 'object' && Object.keys($elseSch).length > 0) || $elseSch === false : it.util.schemaHasRules($elseSch, it.RULES.all)),
2728 $currentBaseId = $it.baseId;
2729 if ($thenPresent || $elsePresent) {
2730 var $ifClause;
2731 $it.createErrors = false;
2732 $it.schema = $schema;
2733 $it.schemaPath = $schemaPath;
2734 $it.errSchemaPath = $errSchemaPath;
2735 out += ' var ' + ($errs) + ' = errors; var ' + ($valid) + ' = true; ';
2736 var $wasComposite = it.compositeRule;
2737 it.compositeRule = $it.compositeRule = true;
2738 out += ' ' + (it.validate($it)) + ' ';
2739 $it.baseId = $currentBaseId;
2740 $it.createErrors = true;
2741 out += ' errors = ' + ($errs) + '; if (vErrors !== null) { if (' + ($errs) + ') vErrors.length = ' + ($errs) + '; else vErrors = null; } ';
2742 it.compositeRule = $it.compositeRule = $wasComposite;
2743 if ($thenPresent) {
2744 out += ' if (' + ($nextValid) + ') { ';
2745 $it.schema = it.schema['then'];
2746 $it.schemaPath = it.schemaPath + '.then';
2747 $it.errSchemaPath = it.errSchemaPath + '/then';
2748 out += ' ' + (it.validate($it)) + ' ';
2749 $it.baseId = $currentBaseId;
2750 out += ' ' + ($valid) + ' = ' + ($nextValid) + '; ';
2751 if ($thenPresent && $elsePresent) {
2752 $ifClause = 'ifClause' + $lvl;
2753 out += ' var ' + ($ifClause) + ' = \'then\'; ';
2754 } else {
2755 $ifClause = '\'then\'';
2756 }
2757 out += ' } ';
2758 if ($elsePresent) {
2759 out += ' else { ';
2760 }
2761 } else {
2762 out += ' if (!' + ($nextValid) + ') { ';
2763 }
2764 if ($elsePresent) {
2765 $it.schema = it.schema['else'];
2766 $it.schemaPath = it.schemaPath + '.else';
2767 $it.errSchemaPath = it.errSchemaPath + '/else';
2768 out += ' ' + (it.validate($it)) + ' ';
2769 $it.baseId = $currentBaseId;
2770 out += ' ' + ($valid) + ' = ' + ($nextValid) + '; ';
2771 if ($thenPresent && $elsePresent) {
2772 $ifClause = 'ifClause' + $lvl;
2773 out += ' var ' + ($ifClause) + ' = \'else\'; ';
2774 } else {
2775 $ifClause = '\'else\'';
2776 }
2777 out += ' } ';
2778 }
2779 out += ' if (!' + ($valid) + ') { var err = '; /* istanbul ignore else */
2780 if (it.createErrors !== false) {
2781 out += ' { keyword: \'' + ('if') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: ' + (it.util.toQuotedString($errSchemaPath)) + ' , params: { failingKeyword: ' + ($ifClause) + ' } ';
2782 if (it.opts.messages !== false) {
2783 out += ' , message: \'should match "\' + ' + ($ifClause) + ' + \'" schema\' ';
2784 }
2785 if (it.opts.verbose) {
2786 out += ' , schema: validate.schema' + ($schemaPath) + ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' ';
2787 }
2788 out += ' } ';
2789 } else {
2790 out += ' {} ';
2791 }
2792 out += '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ';
2793 if (!it.compositeRule && $breakOnError) {
2794 /* istanbul ignore if */
2795 if (it.async) {
2796 out += ' throw new ValidationError(vErrors); ';
2797 } else {
2798 out += ' validate.errors = vErrors; return false; ';
2799 }
2800 }
2801 out += ' } ';
2802 if ($breakOnError) {
2803 out += ' else { ';
2804 }
2805 } else {
2806 if ($breakOnError) {
2807 out += ' if (true) { ';
2808 }
2809 }
2810 return out;
2811}
2812
2813},{}],27:[function(require,module,exports){
2814'use strict';
2815
2816//all requires must be explicit because browserify won't work with dynamic requires
2817module.exports = {
2818 '$ref': require('./ref'),
2819 allOf: require('./allOf'),
2820 anyOf: require('./anyOf'),
2821 '$comment': require('./comment'),
2822 const: require('./const'),
2823 contains: require('./contains'),
2824 dependencies: require('./dependencies'),
2825 'enum': require('./enum'),
2826 format: require('./format'),
2827 'if': require('./if'),
2828 items: require('./items'),
2829 maximum: require('./_limit'),
2830 minimum: require('./_limit'),
2831 maxItems: require('./_limitItems'),
2832 minItems: require('./_limitItems'),
2833 maxLength: require('./_limitLength'),
2834 minLength: require('./_limitLength'),
2835 maxProperties: require('./_limitProperties'),
2836 minProperties: require('./_limitProperties'),
2837 multipleOf: require('./multipleOf'),
2838 not: require('./not'),
2839 oneOf: require('./oneOf'),
2840 pattern: require('./pattern'),
2841 properties: require('./properties'),
2842 propertyNames: require('./propertyNames'),
2843 required: require('./required'),
2844 uniqueItems: require('./uniqueItems'),
2845 validate: require('./validate')
2846};
2847
2848},{"./_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){
2849'use strict';
2850module.exports = function generate_items(it, $keyword, $ruleType) {
2851 var out = ' ';
2852 var $lvl = it.level;
2853 var $dataLvl = it.dataLevel;
2854 var $schema = it.schema[$keyword];
2855 var $schemaPath = it.schemaPath + it.util.getProperty($keyword);
2856 var $errSchemaPath = it.errSchemaPath + '/' + $keyword;
2857 var $breakOnError = !it.opts.allErrors;
2858 var $data = 'data' + ($dataLvl || '');
2859 var $valid = 'valid' + $lvl;
2860 var $errs = 'errs__' + $lvl;
2861 var $it = it.util.copy(it);
2862 var $closingBraces = '';
2863 $it.level++;
2864 var $nextValid = 'valid' + $it.level;
2865 var $idx = 'i' + $lvl,
2866 $dataNxt = $it.dataLevel = it.dataLevel + 1,
2867 $nextData = 'data' + $dataNxt,
2868 $currentBaseId = it.baseId;
2869 out += 'var ' + ($errs) + ' = errors;var ' + ($valid) + ';';
2870 if (Array.isArray($schema)) {
2871 var $additionalItems = it.schema.additionalItems;
2872 if ($additionalItems === false) {
2873 out += ' ' + ($valid) + ' = ' + ($data) + '.length <= ' + ($schema.length) + '; ';
2874 var $currErrSchemaPath = $errSchemaPath;
2875 $errSchemaPath = it.errSchemaPath + '/additionalItems';
2876 out += ' if (!' + ($valid) + ') { ';
2877 var $$outStack = $$outStack || [];
2878 $$outStack.push(out);
2879 out = ''; /* istanbul ignore else */
2880 if (it.createErrors !== false) {
2881 out += ' { keyword: \'' + ('additionalItems') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: ' + (it.util.toQuotedString($errSchemaPath)) + ' , params: { limit: ' + ($schema.length) + ' } ';
2882 if (it.opts.messages !== false) {
2883 out += ' , message: \'should NOT have more than ' + ($schema.length) + ' items\' ';
2884 }
2885 if (it.opts.verbose) {
2886 out += ' , schema: false , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' ';
2887 }
2888 out += ' } ';
2889 } else {
2890 out += ' {} ';
2891 }
2892 var __err = out;
2893 out = $$outStack.pop();
2894 if (!it.compositeRule && $breakOnError) {
2895 /* istanbul ignore if */
2896 if (it.async) {
2897 out += ' throw new ValidationError([' + (__err) + ']); ';
2898 } else {
2899 out += ' validate.errors = [' + (__err) + ']; return false; ';
2900 }
2901 } else {
2902 out += ' var err = ' + (__err) + '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ';
2903 }
2904 out += ' } ';
2905 $errSchemaPath = $currErrSchemaPath;
2906 if ($breakOnError) {
2907 $closingBraces += '}';
2908 out += ' else { ';
2909 }
2910 }
2911 var arr1 = $schema;
2912 if (arr1) {
2913 var $sch, $i = -1,
2914 l1 = arr1.length - 1;
2915 while ($i < l1) {
2916 $sch = arr1[$i += 1];
2917 if ((it.opts.strictKeywords ? (typeof $sch == 'object' && Object.keys($sch).length > 0) || $sch === false : it.util.schemaHasRules($sch, it.RULES.all))) {
2918 out += ' ' + ($nextValid) + ' = true; if (' + ($data) + '.length > ' + ($i) + ') { ';
2919 var $passData = $data + '[' + $i + ']';
2920 $it.schema = $sch;
2921 $it.schemaPath = $schemaPath + '[' + $i + ']';
2922 $it.errSchemaPath = $errSchemaPath + '/' + $i;
2923 $it.errorPath = it.util.getPathExpr(it.errorPath, $i, it.opts.jsonPointers, true);
2924 $it.dataPathArr[$dataNxt] = $i;
2925 var $code = it.validate($it);
2926 $it.baseId = $currentBaseId;
2927 if (it.util.varOccurences($code, $nextData) < 2) {
2928 out += ' ' + (it.util.varReplace($code, $nextData, $passData)) + ' ';
2929 } else {
2930 out += ' var ' + ($nextData) + ' = ' + ($passData) + '; ' + ($code) + ' ';
2931 }
2932 out += ' } ';
2933 if ($breakOnError) {
2934 out += ' if (' + ($nextValid) + ') { ';
2935 $closingBraces += '}';
2936 }
2937 }
2938 }
2939 }
2940 if (typeof $additionalItems == 'object' && (it.opts.strictKeywords ? (typeof $additionalItems == 'object' && Object.keys($additionalItems).length > 0) || $additionalItems === false : it.util.schemaHasRules($additionalItems, it.RULES.all))) {
2941 $it.schema = $additionalItems;
2942 $it.schemaPath = it.schemaPath + '.additionalItems';
2943 $it.errSchemaPath = it.errSchemaPath + '/additionalItems';
2944 out += ' ' + ($nextValid) + ' = true; if (' + ($data) + '.length > ' + ($schema.length) + ') { for (var ' + ($idx) + ' = ' + ($schema.length) + '; ' + ($idx) + ' < ' + ($data) + '.length; ' + ($idx) + '++) { ';
2945 $it.errorPath = it.util.getPathExpr(it.errorPath, $idx, it.opts.jsonPointers, true);
2946 var $passData = $data + '[' + $idx + ']';
2947 $it.dataPathArr[$dataNxt] = $idx;
2948 var $code = it.validate($it);
2949 $it.baseId = $currentBaseId;
2950 if (it.util.varOccurences($code, $nextData) < 2) {
2951 out += ' ' + (it.util.varReplace($code, $nextData, $passData)) + ' ';
2952 } else {
2953 out += ' var ' + ($nextData) + ' = ' + ($passData) + '; ' + ($code) + ' ';
2954 }
2955 if ($breakOnError) {
2956 out += ' if (!' + ($nextValid) + ') break; ';
2957 }
2958 out += ' } } ';
2959 if ($breakOnError) {
2960 out += ' if (' + ($nextValid) + ') { ';
2961 $closingBraces += '}';
2962 }
2963 }
2964 } else if ((it.opts.strictKeywords ? (typeof $schema == 'object' && Object.keys($schema).length > 0) || $schema === false : it.util.schemaHasRules($schema, it.RULES.all))) {
2965 $it.schema = $schema;
2966 $it.schemaPath = $schemaPath;
2967 $it.errSchemaPath = $errSchemaPath;
2968 out += ' for (var ' + ($idx) + ' = ' + (0) + '; ' + ($idx) + ' < ' + ($data) + '.length; ' + ($idx) + '++) { ';
2969 $it.errorPath = it.util.getPathExpr(it.errorPath, $idx, it.opts.jsonPointers, true);
2970 var $passData = $data + '[' + $idx + ']';
2971 $it.dataPathArr[$dataNxt] = $idx;
2972 var $code = it.validate($it);
2973 $it.baseId = $currentBaseId;
2974 if (it.util.varOccurences($code, $nextData) < 2) {
2975 out += ' ' + (it.util.varReplace($code, $nextData, $passData)) + ' ';
2976 } else {
2977 out += ' var ' + ($nextData) + ' = ' + ($passData) + '; ' + ($code) + ' ';
2978 }
2979 if ($breakOnError) {
2980 out += ' if (!' + ($nextValid) + ') break; ';
2981 }
2982 out += ' }';
2983 }
2984 if ($breakOnError) {
2985 out += ' ' + ($closingBraces) + ' if (' + ($errs) + ' == errors) {';
2986 }
2987 return out;
2988}
2989
2990},{}],29:[function(require,module,exports){
2991'use strict';
2992module.exports = function generate_multipleOf(it, $keyword, $ruleType) {
2993 var out = ' ';
2994 var $lvl = it.level;
2995 var $dataLvl = it.dataLevel;
2996 var $schema = it.schema[$keyword];
2997 var $schemaPath = it.schemaPath + it.util.getProperty($keyword);
2998 var $errSchemaPath = it.errSchemaPath + '/' + $keyword;
2999 var $breakOnError = !it.opts.allErrors;
3000 var $data = 'data' + ($dataLvl || '');
3001 var $isData = it.opts.$data && $schema && $schema.$data,
3002 $schemaValue;
3003 if ($isData) {
3004 out += ' var schema' + ($lvl) + ' = ' + (it.util.getData($schema.$data, $dataLvl, it.dataPathArr)) + '; ';
3005 $schemaValue = 'schema' + $lvl;
3006 } else {
3007 $schemaValue = $schema;
3008 }
3009 if (!($isData || typeof $schema == 'number')) {
3010 throw new Error($keyword + ' must be number');
3011 }
3012 out += 'var division' + ($lvl) + ';if (';
3013 if ($isData) {
3014 out += ' ' + ($schemaValue) + ' !== undefined && ( typeof ' + ($schemaValue) + ' != \'number\' || ';
3015 }
3016 out += ' (division' + ($lvl) + ' = ' + ($data) + ' / ' + ($schemaValue) + ', ';
3017 if (it.opts.multipleOfPrecision) {
3018 out += ' Math.abs(Math.round(division' + ($lvl) + ') - division' + ($lvl) + ') > 1e-' + (it.opts.multipleOfPrecision) + ' ';
3019 } else {
3020 out += ' division' + ($lvl) + ' !== parseInt(division' + ($lvl) + ') ';
3021 }
3022 out += ' ) ';
3023 if ($isData) {
3024 out += ' ) ';
3025 }
3026 out += ' ) { ';
3027 var $$outStack = $$outStack || [];
3028 $$outStack.push(out);
3029 out = ''; /* istanbul ignore else */
3030 if (it.createErrors !== false) {
3031 out += ' { keyword: \'' + ('multipleOf') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: ' + (it.util.toQuotedString($errSchemaPath)) + ' , params: { multipleOf: ' + ($schemaValue) + ' } ';
3032 if (it.opts.messages !== false) {
3033 out += ' , message: \'should be multiple of ';
3034 if ($isData) {
3035 out += '\' + ' + ($schemaValue);
3036 } else {
3037 out += '' + ($schemaValue) + '\'';
3038 }
3039 }
3040 if (it.opts.verbose) {
3041 out += ' , schema: ';
3042 if ($isData) {
3043 out += 'validate.schema' + ($schemaPath);
3044 } else {
3045 out += '' + ($schema);
3046 }
3047 out += ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' ';
3048 }
3049 out += ' } ';
3050 } else {
3051 out += ' {} ';
3052 }
3053 var __err = out;
3054 out = $$outStack.pop();
3055 if (!it.compositeRule && $breakOnError) {
3056 /* istanbul ignore if */
3057 if (it.async) {
3058 out += ' throw new ValidationError([' + (__err) + ']); ';
3059 } else {
3060 out += ' validate.errors = [' + (__err) + ']; return false; ';
3061 }
3062 } else {
3063 out += ' var err = ' + (__err) + '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ';
3064 }
3065 out += '} ';
3066 if ($breakOnError) {
3067 out += ' else { ';
3068 }
3069 return out;
3070}
3071
3072},{}],30:[function(require,module,exports){
3073'use strict';
3074module.exports = function generate_not(it, $keyword, $ruleType) {
3075 var out = ' ';
3076 var $lvl = it.level;
3077 var $dataLvl = it.dataLevel;
3078 var $schema = it.schema[$keyword];
3079 var $schemaPath = it.schemaPath + it.util.getProperty($keyword);
3080 var $errSchemaPath = it.errSchemaPath + '/' + $keyword;
3081 var $breakOnError = !it.opts.allErrors;
3082 var $data = 'data' + ($dataLvl || '');
3083 var $errs = 'errs__' + $lvl;
3084 var $it = it.util.copy(it);
3085 $it.level++;
3086 var $nextValid = 'valid' + $it.level;
3087 if ((it.opts.strictKeywords ? (typeof $schema == 'object' && Object.keys($schema).length > 0) || $schema === false : it.util.schemaHasRules($schema, it.RULES.all))) {
3088 $it.schema = $schema;
3089 $it.schemaPath = $schemaPath;
3090 $it.errSchemaPath = $errSchemaPath;
3091 out += ' var ' + ($errs) + ' = errors; ';
3092 var $wasComposite = it.compositeRule;
3093 it.compositeRule = $it.compositeRule = true;
3094 $it.createErrors = false;
3095 var $allErrorsOption;
3096 if ($it.opts.allErrors) {
3097 $allErrorsOption = $it.opts.allErrors;
3098 $it.opts.allErrors = false;
3099 }
3100 out += ' ' + (it.validate($it)) + ' ';
3101 $it.createErrors = true;
3102 if ($allErrorsOption) $it.opts.allErrors = $allErrorsOption;
3103 it.compositeRule = $it.compositeRule = $wasComposite;
3104 out += ' if (' + ($nextValid) + ') { ';
3105 var $$outStack = $$outStack || [];
3106 $$outStack.push(out);
3107 out = ''; /* istanbul ignore else */
3108 if (it.createErrors !== false) {
3109 out += ' { keyword: \'' + ('not') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: ' + (it.util.toQuotedString($errSchemaPath)) + ' , params: {} ';
3110 if (it.opts.messages !== false) {
3111 out += ' , message: \'should NOT be valid\' ';
3112 }
3113 if (it.opts.verbose) {
3114 out += ' , schema: validate.schema' + ($schemaPath) + ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' ';
3115 }
3116 out += ' } ';
3117 } else {
3118 out += ' {} ';
3119 }
3120 var __err = out;
3121 out = $$outStack.pop();
3122 if (!it.compositeRule && $breakOnError) {
3123 /* istanbul ignore if */
3124 if (it.async) {
3125 out += ' throw new ValidationError([' + (__err) + ']); ';
3126 } else {
3127 out += ' validate.errors = [' + (__err) + ']; return false; ';
3128 }
3129 } else {
3130 out += ' var err = ' + (__err) + '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ';
3131 }
3132 out += ' } else { errors = ' + ($errs) + '; if (vErrors !== null) { if (' + ($errs) + ') vErrors.length = ' + ($errs) + '; else vErrors = null; } ';
3133 if (it.opts.allErrors) {
3134 out += ' } ';
3135 }
3136 } else {
3137 out += ' var err = '; /* istanbul ignore else */
3138 if (it.createErrors !== false) {
3139 out += ' { keyword: \'' + ('not') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: ' + (it.util.toQuotedString($errSchemaPath)) + ' , params: {} ';
3140 if (it.opts.messages !== false) {
3141 out += ' , message: \'should NOT be valid\' ';
3142 }
3143 if (it.opts.verbose) {
3144 out += ' , schema: validate.schema' + ($schemaPath) + ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' ';
3145 }
3146 out += ' } ';
3147 } else {
3148 out += ' {} ';
3149 }
3150 out += '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ';
3151 if ($breakOnError) {
3152 out += ' if (false) { ';
3153 }
3154 }
3155 return out;
3156}
3157
3158},{}],31:[function(require,module,exports){
3159'use strict';
3160module.exports = function generate_oneOf(it, $keyword, $ruleType) {
3161 var out = ' ';
3162 var $lvl = it.level;
3163 var $dataLvl = it.dataLevel;
3164 var $schema = it.schema[$keyword];
3165 var $schemaPath = it.schemaPath + it.util.getProperty($keyword);
3166 var $errSchemaPath = it.errSchemaPath + '/' + $keyword;
3167 var $breakOnError = !it.opts.allErrors;
3168 var $data = 'data' + ($dataLvl || '');
3169 var $valid = 'valid' + $lvl;
3170 var $errs = 'errs__' + $lvl;
3171 var $it = it.util.copy(it);
3172 var $closingBraces = '';
3173 $it.level++;
3174 var $nextValid = 'valid' + $it.level;
3175 var $currentBaseId = $it.baseId,
3176 $prevValid = 'prevValid' + $lvl,
3177 $passingSchemas = 'passingSchemas' + $lvl;
3178 out += 'var ' + ($errs) + ' = errors , ' + ($prevValid) + ' = false , ' + ($valid) + ' = false , ' + ($passingSchemas) + ' = null; ';
3179 var $wasComposite = it.compositeRule;
3180 it.compositeRule = $it.compositeRule = true;
3181 var arr1 = $schema;
3182 if (arr1) {
3183 var $sch, $i = -1,
3184 l1 = arr1.length - 1;
3185 while ($i < l1) {
3186 $sch = arr1[$i += 1];
3187 if ((it.opts.strictKeywords ? (typeof $sch == 'object' && Object.keys($sch).length > 0) || $sch === false : it.util.schemaHasRules($sch, it.RULES.all))) {
3188 $it.schema = $sch;
3189 $it.schemaPath = $schemaPath + '[' + $i + ']';
3190 $it.errSchemaPath = $errSchemaPath + '/' + $i;
3191 out += ' ' + (it.validate($it)) + ' ';
3192 $it.baseId = $currentBaseId;
3193 } else {
3194 out += ' var ' + ($nextValid) + ' = true; ';
3195 }
3196 if ($i) {
3197 out += ' if (' + ($nextValid) + ' && ' + ($prevValid) + ') { ' + ($valid) + ' = false; ' + ($passingSchemas) + ' = [' + ($passingSchemas) + ', ' + ($i) + ']; } else { ';
3198 $closingBraces += '}';
3199 }
3200 out += ' if (' + ($nextValid) + ') { ' + ($valid) + ' = ' + ($prevValid) + ' = true; ' + ($passingSchemas) + ' = ' + ($i) + '; }';
3201 }
3202 }
3203 it.compositeRule = $it.compositeRule = $wasComposite;
3204 out += '' + ($closingBraces) + 'if (!' + ($valid) + ') { var err = '; /* istanbul ignore else */
3205 if (it.createErrors !== false) {
3206 out += ' { keyword: \'' + ('oneOf') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: ' + (it.util.toQuotedString($errSchemaPath)) + ' , params: { passingSchemas: ' + ($passingSchemas) + ' } ';
3207 if (it.opts.messages !== false) {
3208 out += ' , message: \'should match exactly one schema in oneOf\' ';
3209 }
3210 if (it.opts.verbose) {
3211 out += ' , schema: validate.schema' + ($schemaPath) + ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' ';
3212 }
3213 out += ' } ';
3214 } else {
3215 out += ' {} ';
3216 }
3217 out += '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ';
3218 if (!it.compositeRule && $breakOnError) {
3219 /* istanbul ignore if */
3220 if (it.async) {
3221 out += ' throw new ValidationError(vErrors); ';
3222 } else {
3223 out += ' validate.errors = vErrors; return false; ';
3224 }
3225 }
3226 out += '} else { errors = ' + ($errs) + '; if (vErrors !== null) { if (' + ($errs) + ') vErrors.length = ' + ($errs) + '; else vErrors = null; }';
3227 if (it.opts.allErrors) {
3228 out += ' } ';
3229 }
3230 return out;
3231}
3232
3233},{}],32:[function(require,module,exports){
3234'use strict';
3235module.exports = function generate_pattern(it, $keyword, $ruleType) {
3236 var out = ' ';
3237 var $lvl = it.level;
3238 var $dataLvl = it.dataLevel;
3239 var $schema = it.schema[$keyword];
3240 var $schemaPath = it.schemaPath + it.util.getProperty($keyword);
3241 var $errSchemaPath = it.errSchemaPath + '/' + $keyword;
3242 var $breakOnError = !it.opts.allErrors;
3243 var $data = 'data' + ($dataLvl || '');
3244 var $valid = 'valid' + $lvl;
3245 var $isData = it.opts.$data && $schema && $schema.$data,
3246 $schemaValue;
3247 if ($isData) {
3248 out += ' var schema' + ($lvl) + ' = ' + (it.util.getData($schema.$data, $dataLvl, it.dataPathArr)) + '; ';
3249 $schemaValue = 'schema' + $lvl;
3250 } else {
3251 $schemaValue = $schema;
3252 }
3253 var $regExpCode = it.opts.regExp ? 'regExp' : 'new RegExp';
3254 if ($isData) {
3255 out += ' var ' + ($valid) + ' = true; try { ' + ($valid) + ' = ' + ($regExpCode) + '(' + ($schemaValue) + ').test(' + ($data) + '); } catch(e) { ' + ($valid) + ' = false; } if ( ';
3256 if ($isData) {
3257 out += ' (' + ($schemaValue) + ' !== undefined && typeof ' + ($schemaValue) + ' != \'string\') || ';
3258 }
3259 out += ' !' + ($valid) + ') {';
3260 } else {
3261 var $regexp = it.usePattern($schema);
3262 out += ' if ( ';
3263 if ($isData) {
3264 out += ' (' + ($schemaValue) + ' !== undefined && typeof ' + ($schemaValue) + ' != \'string\') || ';
3265 }
3266 out += ' !' + ($regexp) + '.test(' + ($data) + ') ) {';
3267 }
3268 var $$outStack = $$outStack || [];
3269 $$outStack.push(out);
3270 out = ''; /* istanbul ignore else */
3271 if (it.createErrors !== false) {
3272 out += ' { keyword: \'' + ('pattern') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: ' + (it.util.toQuotedString($errSchemaPath)) + ' , params: { pattern: ';
3273 if ($isData) {
3274 out += '' + ($schemaValue);
3275 } else {
3276 out += '' + (it.util.toQuotedString($schema));
3277 }
3278 out += ' } ';
3279 if (it.opts.messages !== false) {
3280 out += ' , message: \'should match pattern "';
3281 if ($isData) {
3282 out += '\' + ' + ($schemaValue) + ' + \'';
3283 } else {
3284 out += '' + (it.util.escapeQuotes($schema));
3285 }
3286 out += '"\' ';
3287 }
3288 if (it.opts.verbose) {
3289 out += ' , schema: ';
3290 if ($isData) {
3291 out += 'validate.schema' + ($schemaPath);
3292 } else {
3293 out += '' + (it.util.toQuotedString($schema));
3294 }
3295 out += ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' ';
3296 }
3297 out += ' } ';
3298 } else {
3299 out += ' {} ';
3300 }
3301 var __err = out;
3302 out = $$outStack.pop();
3303 if (!it.compositeRule && $breakOnError) {
3304 /* istanbul ignore if */
3305 if (it.async) {
3306 out += ' throw new ValidationError([' + (__err) + ']); ';
3307 } else {
3308 out += ' validate.errors = [' + (__err) + ']; return false; ';
3309 }
3310 } else {
3311 out += ' var err = ' + (__err) + '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ';
3312 }
3313 out += '} ';
3314 if ($breakOnError) {
3315 out += ' else { ';
3316 }
3317 return out;
3318}
3319
3320},{}],33:[function(require,module,exports){
3321'use strict';
3322module.exports = function generate_properties(it, $keyword, $ruleType) {
3323 var out = ' ';
3324 var $lvl = it.level;
3325 var $dataLvl = it.dataLevel;
3326 var $schema = it.schema[$keyword];
3327 var $schemaPath = it.schemaPath + it.util.getProperty($keyword);
3328 var $errSchemaPath = it.errSchemaPath + '/' + $keyword;
3329 var $breakOnError = !it.opts.allErrors;
3330 var $data = 'data' + ($dataLvl || '');
3331 var $errs = 'errs__' + $lvl;
3332 var $it = it.util.copy(it);
3333 var $closingBraces = '';
3334 $it.level++;
3335 var $nextValid = 'valid' + $it.level;
3336 var $key = 'key' + $lvl,
3337 $idx = 'idx' + $lvl,
3338 $dataNxt = $it.dataLevel = it.dataLevel + 1,
3339 $nextData = 'data' + $dataNxt,
3340 $dataProperties = 'dataProperties' + $lvl;
3341 var $schemaKeys = Object.keys($schema || {}).filter(notProto),
3342 $pProperties = it.schema.patternProperties || {},
3343 $pPropertyKeys = Object.keys($pProperties).filter(notProto),
3344 $aProperties = it.schema.additionalProperties,
3345 $someProperties = $schemaKeys.length || $pPropertyKeys.length,
3346 $noAdditional = $aProperties === false,
3347 $additionalIsSchema = typeof $aProperties == 'object' && Object.keys($aProperties).length,
3348 $removeAdditional = it.opts.removeAdditional,
3349 $checkAdditional = $noAdditional || $additionalIsSchema || $removeAdditional,
3350 $ownProperties = it.opts.ownProperties,
3351 $currentBaseId = it.baseId;
3352 var $required = it.schema.required;
3353 if ($required && !(it.opts.$data && $required.$data) && $required.length < it.opts.loopRequired) {
3354 var $requiredHash = it.util.toHash($required);
3355 }
3356
3357 function notProto(p) {
3358 return p !== '__proto__';
3359 }
3360 out += 'var ' + ($errs) + ' = errors;var ' + ($nextValid) + ' = true;';
3361 if ($ownProperties) {
3362 out += ' var ' + ($dataProperties) + ' = undefined;';
3363 }
3364 if ($checkAdditional) {
3365 if ($ownProperties) {
3366 out += ' ' + ($dataProperties) + ' = ' + ($dataProperties) + ' || Object.keys(' + ($data) + '); for (var ' + ($idx) + '=0; ' + ($idx) + '<' + ($dataProperties) + '.length; ' + ($idx) + '++) { var ' + ($key) + ' = ' + ($dataProperties) + '[' + ($idx) + ']; ';
3367 } else {
3368 out += ' for (var ' + ($key) + ' in ' + ($data) + ') { ';
3369 }
3370 if ($someProperties) {
3371 out += ' var isAdditional' + ($lvl) + ' = !(false ';
3372 if ($schemaKeys.length) {
3373 if ($schemaKeys.length > 8) {
3374 out += ' || validate.schema' + ($schemaPath) + '.hasOwnProperty(' + ($key) + ') ';
3375 } else {
3376 var arr1 = $schemaKeys;
3377 if (arr1) {
3378 var $propertyKey, i1 = -1,
3379 l1 = arr1.length - 1;
3380 while (i1 < l1) {
3381 $propertyKey = arr1[i1 += 1];
3382 out += ' || ' + ($key) + ' == ' + (it.util.toQuotedString($propertyKey)) + ' ';
3383 }
3384 }
3385 }
3386 }
3387 if ($pPropertyKeys.length) {
3388 var arr2 = $pPropertyKeys;
3389 if (arr2) {
3390 var $pProperty, $i = -1,
3391 l2 = arr2.length - 1;
3392 while ($i < l2) {
3393 $pProperty = arr2[$i += 1];
3394 out += ' || ' + (it.usePattern($pProperty)) + '.test(' + ($key) + ') ';
3395 }
3396 }
3397 }
3398 out += ' ); if (isAdditional' + ($lvl) + ') { ';
3399 }
3400 if ($removeAdditional == 'all') {
3401 out += ' delete ' + ($data) + '[' + ($key) + ']; ';
3402 } else {
3403 var $currentErrorPath = it.errorPath;
3404 var $additionalProperty = '\' + ' + $key + ' + \'';
3405 if (it.opts._errorDataPathProperty) {
3406 it.errorPath = it.util.getPathExpr(it.errorPath, $key, it.opts.jsonPointers);
3407 }
3408 if ($noAdditional) {
3409 if ($removeAdditional) {
3410 out += ' delete ' + ($data) + '[' + ($key) + ']; ';
3411 } else {
3412 out += ' ' + ($nextValid) + ' = false; ';
3413 var $currErrSchemaPath = $errSchemaPath;
3414 $errSchemaPath = it.errSchemaPath + '/additionalProperties';
3415 var $$outStack = $$outStack || [];
3416 $$outStack.push(out);
3417 out = ''; /* istanbul ignore else */
3418 if (it.createErrors !== false) {
3419 out += ' { keyword: \'' + ('additionalProperties') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: ' + (it.util.toQuotedString($errSchemaPath)) + ' , params: { additionalProperty: \'' + ($additionalProperty) + '\' } ';
3420 if (it.opts.messages !== false) {
3421 out += ' , message: \'';
3422 if (it.opts._errorDataPathProperty) {
3423 out += 'is an invalid additional property';
3424 } else {
3425 out += 'should NOT have additional properties';
3426 }
3427 out += '\' ';
3428 }
3429 if (it.opts.verbose) {
3430 out += ' , schema: false , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' ';
3431 }
3432 out += ' } ';
3433 } else {
3434 out += ' {} ';
3435 }
3436 var __err = out;
3437 out = $$outStack.pop();
3438 if (!it.compositeRule && $breakOnError) {
3439 /* istanbul ignore if */
3440 if (it.async) {
3441 out += ' throw new ValidationError([' + (__err) + ']); ';
3442 } else {
3443 out += ' validate.errors = [' + (__err) + ']; return false; ';
3444 }
3445 } else {
3446 out += ' var err = ' + (__err) + '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ';
3447 }
3448 $errSchemaPath = $currErrSchemaPath;
3449 if ($breakOnError) {
3450 out += ' break; ';
3451 }
3452 }
3453 } else if ($additionalIsSchema) {
3454 if ($removeAdditional == 'failing') {
3455 out += ' var ' + ($errs) + ' = errors; ';
3456 var $wasComposite = it.compositeRule;
3457 it.compositeRule = $it.compositeRule = true;
3458 $it.schema = $aProperties;
3459 $it.schemaPath = it.schemaPath + '.additionalProperties';
3460 $it.errSchemaPath = it.errSchemaPath + '/additionalProperties';
3461 $it.errorPath = it.opts._errorDataPathProperty ? it.errorPath : it.util.getPathExpr(it.errorPath, $key, it.opts.jsonPointers);
3462 var $passData = $data + '[' + $key + ']';
3463 $it.dataPathArr[$dataNxt] = $key;
3464 var $code = it.validate($it);
3465 $it.baseId = $currentBaseId;
3466 if (it.util.varOccurences($code, $nextData) < 2) {
3467 out += ' ' + (it.util.varReplace($code, $nextData, $passData)) + ' ';
3468 } else {
3469 out += ' var ' + ($nextData) + ' = ' + ($passData) + '; ' + ($code) + ' ';
3470 }
3471 out += ' if (!' + ($nextValid) + ') { errors = ' + ($errs) + '; if (validate.errors !== null) { if (errors) validate.errors.length = errors; else validate.errors = null; } delete ' + ($data) + '[' + ($key) + ']; } ';
3472 it.compositeRule = $it.compositeRule = $wasComposite;
3473 } else {
3474 $it.schema = $aProperties;
3475 $it.schemaPath = it.schemaPath + '.additionalProperties';
3476 $it.errSchemaPath = it.errSchemaPath + '/additionalProperties';
3477 $it.errorPath = it.opts._errorDataPathProperty ? it.errorPath : it.util.getPathExpr(it.errorPath, $key, it.opts.jsonPointers);
3478 var $passData = $data + '[' + $key + ']';
3479 $it.dataPathArr[$dataNxt] = $key;
3480 var $code = it.validate($it);
3481 $it.baseId = $currentBaseId;
3482 if (it.util.varOccurences($code, $nextData) < 2) {
3483 out += ' ' + (it.util.varReplace($code, $nextData, $passData)) + ' ';
3484 } else {
3485 out += ' var ' + ($nextData) + ' = ' + ($passData) + '; ' + ($code) + ' ';
3486 }
3487 if ($breakOnError) {
3488 out += ' if (!' + ($nextValid) + ') break; ';
3489 }
3490 }
3491 }
3492 it.errorPath = $currentErrorPath;
3493 }
3494 if ($someProperties) {
3495 out += ' } ';
3496 }
3497 out += ' } ';
3498 if ($breakOnError) {
3499 out += ' if (' + ($nextValid) + ') { ';
3500 $closingBraces += '}';
3501 }
3502 }
3503 var $useDefaults = it.opts.useDefaults && !it.compositeRule;
3504 if ($schemaKeys.length) {
3505 var arr3 = $schemaKeys;
3506 if (arr3) {
3507 var $propertyKey, i3 = -1,
3508 l3 = arr3.length - 1;
3509 while (i3 < l3) {
3510 $propertyKey = arr3[i3 += 1];
3511 var $sch = $schema[$propertyKey];
3512 if ((it.opts.strictKeywords ? (typeof $sch == 'object' && Object.keys($sch).length > 0) || $sch === false : it.util.schemaHasRules($sch, it.RULES.all))) {
3513 var $prop = it.util.getProperty($propertyKey),
3514 $passData = $data + $prop,
3515 $hasDefault = $useDefaults && $sch.default !== undefined;
3516 $it.schema = $sch;
3517 $it.schemaPath = $schemaPath + $prop;
3518 $it.errSchemaPath = $errSchemaPath + '/' + it.util.escapeFragment($propertyKey);
3519 $it.errorPath = it.util.getPath(it.errorPath, $propertyKey, it.opts.jsonPointers);
3520 $it.dataPathArr[$dataNxt] = it.util.toQuotedString($propertyKey);
3521 var $code = it.validate($it);
3522 $it.baseId = $currentBaseId;
3523 if (it.util.varOccurences($code, $nextData) < 2) {
3524 $code = it.util.varReplace($code, $nextData, $passData);
3525 var $useData = $passData;
3526 } else {
3527 var $useData = $nextData;
3528 out += ' var ' + ($nextData) + ' = ' + ($passData) + '; ';
3529 }
3530 if ($hasDefault) {
3531 out += ' ' + ($code) + ' ';
3532 } else {
3533 if ($requiredHash && $requiredHash[$propertyKey]) {
3534 out += ' if ( ' + ($useData) + ' === undefined ';
3535 if ($ownProperties) {
3536 out += ' || ! Object.prototype.hasOwnProperty.call(' + ($data) + ', \'' + (it.util.escapeQuotes($propertyKey)) + '\') ';
3537 }
3538 out += ') { ' + ($nextValid) + ' = false; ';
3539 var $currentErrorPath = it.errorPath,
3540 $currErrSchemaPath = $errSchemaPath,
3541 $missingProperty = it.util.escapeQuotes($propertyKey);
3542 if (it.opts._errorDataPathProperty) {
3543 it.errorPath = it.util.getPath($currentErrorPath, $propertyKey, it.opts.jsonPointers);
3544 }
3545 $errSchemaPath = it.errSchemaPath + '/required';
3546 var $$outStack = $$outStack || [];
3547 $$outStack.push(out);
3548 out = ''; /* istanbul ignore else */
3549 if (it.createErrors !== false) {
3550 out += ' { keyword: \'' + ('required') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: ' + (it.util.toQuotedString($errSchemaPath)) + ' , params: { missingProperty: \'' + ($missingProperty) + '\' } ';
3551 if (it.opts.messages !== false) {
3552 out += ' , message: \'';
3553 if (it.opts._errorDataPathProperty) {
3554 out += 'is a required property';
3555 } else {
3556 out += 'should have required property \\\'' + ($missingProperty) + '\\\'';
3557 }
3558 out += '\' ';
3559 }
3560 if (it.opts.verbose) {
3561 out += ' , schema: validate.schema' + ($schemaPath) + ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' ';
3562 }
3563 out += ' } ';
3564 } else {
3565 out += ' {} ';
3566 }
3567 var __err = out;
3568 out = $$outStack.pop();
3569 if (!it.compositeRule && $breakOnError) {
3570 /* istanbul ignore if */
3571 if (it.async) {
3572 out += ' throw new ValidationError([' + (__err) + ']); ';
3573 } else {
3574 out += ' validate.errors = [' + (__err) + ']; return false; ';
3575 }
3576 } else {
3577 out += ' var err = ' + (__err) + '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ';
3578 }
3579 $errSchemaPath = $currErrSchemaPath;
3580 it.errorPath = $currentErrorPath;
3581 out += ' } else { ';
3582 } else {
3583 if ($breakOnError) {
3584 out += ' if ( ' + ($useData) + ' === undefined ';
3585 if ($ownProperties) {
3586 out += ' || ! Object.prototype.hasOwnProperty.call(' + ($data) + ', \'' + (it.util.escapeQuotes($propertyKey)) + '\') ';
3587 }
3588 out += ') { ' + ($nextValid) + ' = true; } else { ';
3589 } else {
3590 out += ' if (' + ($useData) + ' !== undefined ';
3591 if ($ownProperties) {
3592 out += ' && Object.prototype.hasOwnProperty.call(' + ($data) + ', \'' + (it.util.escapeQuotes($propertyKey)) + '\') ';
3593 }
3594 out += ' ) { ';
3595 }
3596 }
3597 out += ' ' + ($code) + ' } ';
3598 }
3599 }
3600 if ($breakOnError) {
3601 out += ' if (' + ($nextValid) + ') { ';
3602 $closingBraces += '}';
3603 }
3604 }
3605 }
3606 }
3607 if ($pPropertyKeys.length) {
3608 var arr4 = $pPropertyKeys;
3609 if (arr4) {
3610 var $pProperty, i4 = -1,
3611 l4 = arr4.length - 1;
3612 while (i4 < l4) {
3613 $pProperty = arr4[i4 += 1];
3614 var $sch = $pProperties[$pProperty];
3615 if ((it.opts.strictKeywords ? (typeof $sch == 'object' && Object.keys($sch).length > 0) || $sch === false : it.util.schemaHasRules($sch, it.RULES.all))) {
3616 $it.schema = $sch;
3617 $it.schemaPath = it.schemaPath + '.patternProperties' + it.util.getProperty($pProperty);
3618 $it.errSchemaPath = it.errSchemaPath + '/patternProperties/' + it.util.escapeFragment($pProperty);
3619 if ($ownProperties) {
3620 out += ' ' + ($dataProperties) + ' = ' + ($dataProperties) + ' || Object.keys(' + ($data) + '); for (var ' + ($idx) + '=0; ' + ($idx) + '<' + ($dataProperties) + '.length; ' + ($idx) + '++) { var ' + ($key) + ' = ' + ($dataProperties) + '[' + ($idx) + ']; ';
3621 } else {
3622 out += ' for (var ' + ($key) + ' in ' + ($data) + ') { ';
3623 }
3624 out += ' if (' + (it.usePattern($pProperty)) + '.test(' + ($key) + ')) { ';
3625 $it.errorPath = it.util.getPathExpr(it.errorPath, $key, it.opts.jsonPointers);
3626 var $passData = $data + '[' + $key + ']';
3627 $it.dataPathArr[$dataNxt] = $key;
3628 var $code = it.validate($it);
3629 $it.baseId = $currentBaseId;
3630 if (it.util.varOccurences($code, $nextData) < 2) {
3631 out += ' ' + (it.util.varReplace($code, $nextData, $passData)) + ' ';
3632 } else {
3633 out += ' var ' + ($nextData) + ' = ' + ($passData) + '; ' + ($code) + ' ';
3634 }
3635 if ($breakOnError) {
3636 out += ' if (!' + ($nextValid) + ') break; ';
3637 }
3638 out += ' } ';
3639 if ($breakOnError) {
3640 out += ' else ' + ($nextValid) + ' = true; ';
3641 }
3642 out += ' } ';
3643 if ($breakOnError) {
3644 out += ' if (' + ($nextValid) + ') { ';
3645 $closingBraces += '}';
3646 }
3647 }
3648 }
3649 }
3650 }
3651 if ($breakOnError) {
3652 out += ' ' + ($closingBraces) + ' if (' + ($errs) + ' == errors) {';
3653 }
3654 return out;
3655}
3656
3657},{}],34:[function(require,module,exports){
3658'use strict';
3659module.exports = function generate_propertyNames(it, $keyword, $ruleType) {
3660 var out = ' ';
3661 var $lvl = it.level;
3662 var $dataLvl = it.dataLevel;
3663 var $schema = it.schema[$keyword];
3664 var $schemaPath = it.schemaPath + it.util.getProperty($keyword);
3665 var $errSchemaPath = it.errSchemaPath + '/' + $keyword;
3666 var $breakOnError = !it.opts.allErrors;
3667 var $data = 'data' + ($dataLvl || '');
3668 var $errs = 'errs__' + $lvl;
3669 var $it = it.util.copy(it);
3670 var $closingBraces = '';
3671 $it.level++;
3672 var $nextValid = 'valid' + $it.level;
3673 out += 'var ' + ($errs) + ' = errors;';
3674 if ((it.opts.strictKeywords ? (typeof $schema == 'object' && Object.keys($schema).length > 0) || $schema === false : it.util.schemaHasRules($schema, it.RULES.all))) {
3675 $it.schema = $schema;
3676 $it.schemaPath = $schemaPath;
3677 $it.errSchemaPath = $errSchemaPath;
3678 var $key = 'key' + $lvl,
3679 $idx = 'idx' + $lvl,
3680 $i = 'i' + $lvl,
3681 $invalidName = '\' + ' + $key + ' + \'',
3682 $dataNxt = $it.dataLevel = it.dataLevel + 1,
3683 $nextData = 'data' + $dataNxt,
3684 $dataProperties = 'dataProperties' + $lvl,
3685 $ownProperties = it.opts.ownProperties,
3686 $currentBaseId = it.baseId;
3687 if ($ownProperties) {
3688 out += ' var ' + ($dataProperties) + ' = undefined; ';
3689 }
3690 if ($ownProperties) {
3691 out += ' ' + ($dataProperties) + ' = ' + ($dataProperties) + ' || Object.keys(' + ($data) + '); for (var ' + ($idx) + '=0; ' + ($idx) + '<' + ($dataProperties) + '.length; ' + ($idx) + '++) { var ' + ($key) + ' = ' + ($dataProperties) + '[' + ($idx) + ']; ';
3692 } else {
3693 out += ' for (var ' + ($key) + ' in ' + ($data) + ') { ';
3694 }
3695 out += ' var startErrs' + ($lvl) + ' = errors; ';
3696 var $passData = $key;
3697 var $wasComposite = it.compositeRule;
3698 it.compositeRule = $it.compositeRule = true;
3699 var $code = it.validate($it);
3700 $it.baseId = $currentBaseId;
3701 if (it.util.varOccurences($code, $nextData) < 2) {
3702 out += ' ' + (it.util.varReplace($code, $nextData, $passData)) + ' ';
3703 } else {
3704 out += ' var ' + ($nextData) + ' = ' + ($passData) + '; ' + ($code) + ' ';
3705 }
3706 it.compositeRule = $it.compositeRule = $wasComposite;
3707 out += ' if (!' + ($nextValid) + ') { for (var ' + ($i) + '=startErrs' + ($lvl) + '; ' + ($i) + '<errors; ' + ($i) + '++) { vErrors[' + ($i) + '].propertyName = ' + ($key) + '; } var err = '; /* istanbul ignore else */
3708 if (it.createErrors !== false) {
3709 out += ' { keyword: \'' + ('propertyNames') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: ' + (it.util.toQuotedString($errSchemaPath)) + ' , params: { propertyName: \'' + ($invalidName) + '\' } ';
3710 if (it.opts.messages !== false) {
3711 out += ' , message: \'property name \\\'' + ($invalidName) + '\\\' is invalid\' ';
3712 }
3713 if (it.opts.verbose) {
3714 out += ' , schema: validate.schema' + ($schemaPath) + ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' ';
3715 }
3716 out += ' } ';
3717 } else {
3718 out += ' {} ';
3719 }
3720 out += '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ';
3721 if (!it.compositeRule && $breakOnError) {
3722 /* istanbul ignore if */
3723 if (it.async) {
3724 out += ' throw new ValidationError(vErrors); ';
3725 } else {
3726 out += ' validate.errors = vErrors; return false; ';
3727 }
3728 }
3729 if ($breakOnError) {
3730 out += ' break; ';
3731 }
3732 out += ' } }';
3733 }
3734 if ($breakOnError) {
3735 out += ' ' + ($closingBraces) + ' if (' + ($errs) + ' == errors) {';
3736 }
3737 return out;
3738}
3739
3740},{}],35:[function(require,module,exports){
3741'use strict';
3742module.exports = function generate_ref(it, $keyword, $ruleType) {
3743 var out = ' ';
3744 var $lvl = it.level;
3745 var $dataLvl = it.dataLevel;
3746 var $schema = it.schema[$keyword];
3747 var $errSchemaPath = it.errSchemaPath + '/' + $keyword;
3748 var $breakOnError = !it.opts.allErrors;
3749 var $data = 'data' + ($dataLvl || '');
3750 var $valid = 'valid' + $lvl;
3751 var $async, $refCode;
3752 if ($schema == '#' || $schema == '#/') {
3753 if (it.isRoot) {
3754 $async = it.async;
3755 $refCode = 'validate';
3756 } else {
3757 $async = it.root.schema.$async === true;
3758 $refCode = 'root.refVal[0]';
3759 }
3760 } else {
3761 var $refVal = it.resolveRef(it.baseId, $schema, it.isRoot);
3762 if ($refVal === undefined) {
3763 var $message = it.MissingRefError.message(it.baseId, $schema);
3764 if (it.opts.missingRefs == 'fail') {
3765 it.logger.error($message);
3766 var $$outStack = $$outStack || [];
3767 $$outStack.push(out);
3768 out = ''; /* istanbul ignore else */
3769 if (it.createErrors !== false) {
3770 out += ' { keyword: \'' + ('$ref') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: ' + (it.util.toQuotedString($errSchemaPath)) + ' , params: { ref: \'' + (it.util.escapeQuotes($schema)) + '\' } ';
3771 if (it.opts.messages !== false) {
3772 out += ' , message: \'can\\\'t resolve reference ' + (it.util.escapeQuotes($schema)) + '\' ';
3773 }
3774 if (it.opts.verbose) {
3775 out += ' , schema: ' + (it.util.toQuotedString($schema)) + ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' ';
3776 }
3777 out += ' } ';
3778 } else {
3779 out += ' {} ';
3780 }
3781 var __err = out;
3782 out = $$outStack.pop();
3783 if (!it.compositeRule && $breakOnError) {
3784 /* istanbul ignore if */
3785 if (it.async) {
3786 out += ' throw new ValidationError([' + (__err) + ']); ';
3787 } else {
3788 out += ' validate.errors = [' + (__err) + ']; return false; ';
3789 }
3790 } else {
3791 out += ' var err = ' + (__err) + '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ';
3792 }
3793 if ($breakOnError) {
3794 out += ' if (false) { ';
3795 }
3796 } else if (it.opts.missingRefs == 'ignore') {
3797 it.logger.warn($message);
3798 if ($breakOnError) {
3799 out += ' if (true) { ';
3800 }
3801 } else {
3802 throw new it.MissingRefError(it.baseId, $schema, $message);
3803 }
3804 } else if ($refVal.inline) {
3805 var $it = it.util.copy(it);
3806 $it.level++;
3807 var $nextValid = 'valid' + $it.level;
3808 $it.schema = $refVal.schema;
3809 $it.schemaPath = '';
3810 $it.errSchemaPath = $schema;
3811 var $code = it.validate($it).replace(/validate\.schema/g, $refVal.code);
3812 out += ' ' + ($code) + ' ';
3813 if ($breakOnError) {
3814 out += ' if (' + ($nextValid) + ') { ';
3815 }
3816 } else {
3817 $async = $refVal.$async === true || (it.async && $refVal.$async !== false);
3818 $refCode = $refVal.code;
3819 }
3820 }
3821 if ($refCode) {
3822 var $$outStack = $$outStack || [];
3823 $$outStack.push(out);
3824 out = '';
3825 if (it.opts.passContext) {
3826 out += ' ' + ($refCode) + '.call(this, ';
3827 } else {
3828 out += ' ' + ($refCode) + '( ';
3829 }
3830 out += ' ' + ($data) + ', (dataPath || \'\')';
3831 if (it.errorPath != '""') {
3832 out += ' + ' + (it.errorPath);
3833 }
3834 var $parentData = $dataLvl ? 'data' + (($dataLvl - 1) || '') : 'parentData',
3835 $parentDataProperty = $dataLvl ? it.dataPathArr[$dataLvl] : 'parentDataProperty';
3836 out += ' , ' + ($parentData) + ' , ' + ($parentDataProperty) + ', rootData) ';
3837 var __callValidate = out;
3838 out = $$outStack.pop();
3839 if ($async) {
3840 if (!it.async) throw new Error('async schema referenced by sync schema');
3841 if ($breakOnError) {
3842 out += ' var ' + ($valid) + '; ';
3843 }
3844 out += ' try { await ' + (__callValidate) + '; ';
3845 if ($breakOnError) {
3846 out += ' ' + ($valid) + ' = true; ';
3847 }
3848 out += ' } catch (e) { if (!(e instanceof ValidationError)) throw e; if (vErrors === null) vErrors = e.errors; else vErrors = vErrors.concat(e.errors); errors = vErrors.length; ';
3849 if ($breakOnError) {
3850 out += ' ' + ($valid) + ' = false; ';
3851 }
3852 out += ' } ';
3853 if ($breakOnError) {
3854 out += ' if (' + ($valid) + ') { ';
3855 }
3856 } else {
3857 out += ' if (!' + (__callValidate) + ') { if (vErrors === null) vErrors = ' + ($refCode) + '.errors; else vErrors = vErrors.concat(' + ($refCode) + '.errors); errors = vErrors.length; } ';
3858 if ($breakOnError) {
3859 out += ' else { ';
3860 }
3861 }
3862 }
3863 return out;
3864}
3865
3866},{}],36:[function(require,module,exports){
3867'use strict';
3868module.exports = function generate_required(it, $keyword, $ruleType) {
3869 var out = ' ';
3870 var $lvl = it.level;
3871 var $dataLvl = it.dataLevel;
3872 var $schema = it.schema[$keyword];
3873 var $schemaPath = it.schemaPath + it.util.getProperty($keyword);
3874 var $errSchemaPath = it.errSchemaPath + '/' + $keyword;
3875 var $breakOnError = !it.opts.allErrors;
3876 var $data = 'data' + ($dataLvl || '');
3877 var $valid = 'valid' + $lvl;
3878 var $isData = it.opts.$data && $schema && $schema.$data,
3879 $schemaValue;
3880 if ($isData) {
3881 out += ' var schema' + ($lvl) + ' = ' + (it.util.getData($schema.$data, $dataLvl, it.dataPathArr)) + '; ';
3882 $schemaValue = 'schema' + $lvl;
3883 } else {
3884 $schemaValue = $schema;
3885 }
3886 var $vSchema = 'schema' + $lvl;
3887 if (!$isData) {
3888 if ($schema.length < it.opts.loopRequired && it.schema.properties && Object.keys(it.schema.properties).length) {
3889 var $required = [];
3890 var arr1 = $schema;
3891 if (arr1) {
3892 var $property, i1 = -1,
3893 l1 = arr1.length - 1;
3894 while (i1 < l1) {
3895 $property = arr1[i1 += 1];
3896 var $propertySch = it.schema.properties[$property];
3897 if (!($propertySch && (it.opts.strictKeywords ? (typeof $propertySch == 'object' && Object.keys($propertySch).length > 0) || $propertySch === false : it.util.schemaHasRules($propertySch, it.RULES.all)))) {
3898 $required[$required.length] = $property;
3899 }
3900 }
3901 }
3902 } else {
3903 var $required = $schema;
3904 }
3905 }
3906 if ($isData || $required.length) {
3907 var $currentErrorPath = it.errorPath,
3908 $loopRequired = $isData || $required.length >= it.opts.loopRequired,
3909 $ownProperties = it.opts.ownProperties;
3910 if ($breakOnError) {
3911 out += ' var missing' + ($lvl) + '; ';
3912 if ($loopRequired) {
3913 if (!$isData) {
3914 out += ' var ' + ($vSchema) + ' = validate.schema' + ($schemaPath) + '; ';
3915 }
3916 var $i = 'i' + $lvl,
3917 $propertyPath = 'schema' + $lvl + '[' + $i + ']',
3918 $missingProperty = '\' + ' + $propertyPath + ' + \'';
3919 if (it.opts._errorDataPathProperty) {
3920 it.errorPath = it.util.getPathExpr($currentErrorPath, $propertyPath, it.opts.jsonPointers);
3921 }
3922 out += ' var ' + ($valid) + ' = true; ';
3923 if ($isData) {
3924 out += ' if (schema' + ($lvl) + ' === undefined) ' + ($valid) + ' = true; else if (!Array.isArray(schema' + ($lvl) + ')) ' + ($valid) + ' = false; else {';
3925 }
3926 out += ' for (var ' + ($i) + ' = 0; ' + ($i) + ' < ' + ($vSchema) + '.length; ' + ($i) + '++) { ' + ($valid) + ' = ' + ($data) + '[' + ($vSchema) + '[' + ($i) + ']] !== undefined ';
3927 if ($ownProperties) {
3928 out += ' && Object.prototype.hasOwnProperty.call(' + ($data) + ', ' + ($vSchema) + '[' + ($i) + ']) ';
3929 }
3930 out += '; if (!' + ($valid) + ') break; } ';
3931 if ($isData) {
3932 out += ' } ';
3933 }
3934 out += ' if (!' + ($valid) + ') { ';
3935 var $$outStack = $$outStack || [];
3936 $$outStack.push(out);
3937 out = ''; /* istanbul ignore else */
3938 if (it.createErrors !== false) {
3939 out += ' { keyword: \'' + ('required') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: ' + (it.util.toQuotedString($errSchemaPath)) + ' , params: { missingProperty: \'' + ($missingProperty) + '\' } ';
3940 if (it.opts.messages !== false) {
3941 out += ' , message: \'';
3942 if (it.opts._errorDataPathProperty) {
3943 out += 'is a required property';
3944 } else {
3945 out += 'should have required property \\\'' + ($missingProperty) + '\\\'';
3946 }
3947 out += '\' ';
3948 }
3949 if (it.opts.verbose) {
3950 out += ' , schema: validate.schema' + ($schemaPath) + ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' ';
3951 }
3952 out += ' } ';
3953 } else {
3954 out += ' {} ';
3955 }
3956 var __err = out;
3957 out = $$outStack.pop();
3958 if (!it.compositeRule && $breakOnError) {
3959 /* istanbul ignore if */
3960 if (it.async) {
3961 out += ' throw new ValidationError([' + (__err) + ']); ';
3962 } else {
3963 out += ' validate.errors = [' + (__err) + ']; return false; ';
3964 }
3965 } else {
3966 out += ' var err = ' + (__err) + '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ';
3967 }
3968 out += ' } else { ';
3969 } else {
3970 out += ' if ( ';
3971 var arr2 = $required;
3972 if (arr2) {
3973 var $propertyKey, $i = -1,
3974 l2 = arr2.length - 1;
3975 while ($i < l2) {
3976 $propertyKey = arr2[$i += 1];
3977 if ($i) {
3978 out += ' || ';
3979 }
3980 var $prop = it.util.getProperty($propertyKey),
3981 $useData = $data + $prop;
3982 out += ' ( ( ' + ($useData) + ' === undefined ';
3983 if ($ownProperties) {
3984 out += ' || ! Object.prototype.hasOwnProperty.call(' + ($data) + ', \'' + (it.util.escapeQuotes($propertyKey)) + '\') ';
3985 }
3986 out += ') && (missing' + ($lvl) + ' = ' + (it.util.toQuotedString(it.opts.jsonPointers ? $propertyKey : $prop)) + ') ) ';
3987 }
3988 }
3989 out += ') { ';
3990 var $propertyPath = 'missing' + $lvl,
3991 $missingProperty = '\' + ' + $propertyPath + ' + \'';
3992 if (it.opts._errorDataPathProperty) {
3993 it.errorPath = it.opts.jsonPointers ? it.util.getPathExpr($currentErrorPath, $propertyPath, true) : $currentErrorPath + ' + ' + $propertyPath;
3994 }
3995 var $$outStack = $$outStack || [];
3996 $$outStack.push(out);
3997 out = ''; /* istanbul ignore else */
3998 if (it.createErrors !== false) {
3999 out += ' { keyword: \'' + ('required') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: ' + (it.util.toQuotedString($errSchemaPath)) + ' , params: { missingProperty: \'' + ($missingProperty) + '\' } ';
4000 if (it.opts.messages !== false) {
4001 out += ' , message: \'';
4002 if (it.opts._errorDataPathProperty) {
4003 out += 'is a required property';
4004 } else {
4005 out += 'should have required property \\\'' + ($missingProperty) + '\\\'';
4006 }
4007 out += '\' ';
4008 }
4009 if (it.opts.verbose) {
4010 out += ' , schema: validate.schema' + ($schemaPath) + ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' ';
4011 }
4012 out += ' } ';
4013 } else {
4014 out += ' {} ';
4015 }
4016 var __err = out;
4017 out = $$outStack.pop();
4018 if (!it.compositeRule && $breakOnError) {
4019 /* istanbul ignore if */
4020 if (it.async) {
4021 out += ' throw new ValidationError([' + (__err) + ']); ';
4022 } else {
4023 out += ' validate.errors = [' + (__err) + ']; return false; ';
4024 }
4025 } else {
4026 out += ' var err = ' + (__err) + '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ';
4027 }
4028 out += ' } else { ';
4029 }
4030 } else {
4031 if ($loopRequired) {
4032 if (!$isData) {
4033 out += ' var ' + ($vSchema) + ' = validate.schema' + ($schemaPath) + '; ';
4034 }
4035 var $i = 'i' + $lvl,
4036 $propertyPath = 'schema' + $lvl + '[' + $i + ']',
4037 $missingProperty = '\' + ' + $propertyPath + ' + \'';
4038 if (it.opts._errorDataPathProperty) {
4039 it.errorPath = it.util.getPathExpr($currentErrorPath, $propertyPath, it.opts.jsonPointers);
4040 }
4041 if ($isData) {
4042 out += ' if (' + ($vSchema) + ' && !Array.isArray(' + ($vSchema) + ')) { var err = '; /* istanbul ignore else */
4043 if (it.createErrors !== false) {
4044 out += ' { keyword: \'' + ('required') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: ' + (it.util.toQuotedString($errSchemaPath)) + ' , params: { missingProperty: \'' + ($missingProperty) + '\' } ';
4045 if (it.opts.messages !== false) {
4046 out += ' , message: \'';
4047 if (it.opts._errorDataPathProperty) {
4048 out += 'is a required property';
4049 } else {
4050 out += 'should have required property \\\'' + ($missingProperty) + '\\\'';
4051 }
4052 out += '\' ';
4053 }
4054 if (it.opts.verbose) {
4055 out += ' , schema: validate.schema' + ($schemaPath) + ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' ';
4056 }
4057 out += ' } ';
4058 } else {
4059 out += ' {} ';
4060 }
4061 out += '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; } else if (' + ($vSchema) + ' !== undefined) { ';
4062 }
4063 out += ' for (var ' + ($i) + ' = 0; ' + ($i) + ' < ' + ($vSchema) + '.length; ' + ($i) + '++) { if (' + ($data) + '[' + ($vSchema) + '[' + ($i) + ']] === undefined ';
4064 if ($ownProperties) {
4065 out += ' || ! Object.prototype.hasOwnProperty.call(' + ($data) + ', ' + ($vSchema) + '[' + ($i) + ']) ';
4066 }
4067 out += ') { 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';
4074 } else {
4075 out += 'should have required property \\\'' + ($missingProperty) + '\\\'';
4076 }
4077 out += '\' ';
4078 }
4079 if (it.opts.verbose) {
4080 out += ' , schema: validate.schema' + ($schemaPath) + ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' ';
4081 }
4082 out += ' } ';
4083 } else {
4084 out += ' {} ';
4085 }
4086 out += '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; } } ';
4087 if ($isData) {
4088 out += ' } ';
4089 }
4090 } else {
4091 var arr3 = $required;
4092 if (arr3) {
4093 var $propertyKey, i3 = -1,
4094 l3 = arr3.length - 1;
4095 while (i3 < l3) {
4096 $propertyKey = arr3[i3 += 1];
4097 var $prop = it.util.getProperty($propertyKey),
4098 $missingProperty = it.util.escapeQuotes($propertyKey),
4099 $useData = $data + $prop;
4100 if (it.opts._errorDataPathProperty) {
4101 it.errorPath = it.util.getPath($currentErrorPath, $propertyKey, it.opts.jsonPointers);
4102 }
4103 out += ' if ( ' + ($useData) + ' === undefined ';
4104 if ($ownProperties) {
4105 out += ' || ! Object.prototype.hasOwnProperty.call(' + ($data) + ', \'' + (it.util.escapeQuotes($propertyKey)) + '\') ';
4106 }
4107 out += ') { var err = '; /* istanbul ignore else */
4108 if (it.createErrors !== false) {
4109 out += ' { keyword: \'' + ('required') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: ' + (it.util.toQuotedString($errSchemaPath)) + ' , params: { missingProperty: \'' + ($missingProperty) + '\' } ';
4110 if (it.opts.messages !== false) {
4111 out += ' , message: \'';
4112 if (it.opts._errorDataPathProperty) {
4113 out += 'is a required property';
4114 } else {
4115 out += 'should have required property \\\'' + ($missingProperty) + '\\\'';
4116 }
4117 out += '\' ';
4118 }
4119 if (it.opts.verbose) {
4120 out += ' , schema: validate.schema' + ($schemaPath) + ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' ';
4121 }
4122 out += ' } ';
4123 } else {
4124 out += ' {} ';
4125 }
4126 out += '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; } ';
4127 }
4128 }
4129 }
4130 }
4131 it.errorPath = $currentErrorPath;
4132 } else if ($breakOnError) {
4133 out += ' if (true) {';
4134 }
4135 return out;
4136}
4137
4138},{}],37:[function(require,module,exports){
4139'use strict';
4140module.exports = function generate_uniqueItems(it, $keyword, $ruleType) {
4141 var out = ' ';
4142 var $lvl = it.level;
4143 var $dataLvl = it.dataLevel;
4144 var $schema = it.schema[$keyword];
4145 var $schemaPath = it.schemaPath + it.util.getProperty($keyword);
4146 var $errSchemaPath = it.errSchemaPath + '/' + $keyword;
4147 var $breakOnError = !it.opts.allErrors;
4148 var $data = 'data' + ($dataLvl || '');
4149 var $valid = 'valid' + $lvl;
4150 var $isData = it.opts.$data && $schema && $schema.$data,
4151 $schemaValue;
4152 if ($isData) {
4153 out += ' var schema' + ($lvl) + ' = ' + (it.util.getData($schema.$data, $dataLvl, it.dataPathArr)) + '; ';
4154 $schemaValue = 'schema' + $lvl;
4155 } else {
4156 $schemaValue = $schema;
4157 }
4158 if (($schema || $isData) && it.opts.uniqueItems !== false) {
4159 if ($isData) {
4160 out += ' var ' + ($valid) + '; if (' + ($schemaValue) + ' === false || ' + ($schemaValue) + ' === undefined) ' + ($valid) + ' = true; else if (typeof ' + ($schemaValue) + ' != \'boolean\') ' + ($valid) + ' = false; else { ';
4161 }
4162 out += ' var i = ' + ($data) + '.length , ' + ($valid) + ' = true , j; if (i > 1) { ';
4163 var $itemType = it.schema.items && it.schema.items.type,
4164 $typeIsArray = Array.isArray($itemType);
4165 if (!$itemType || $itemType == 'object' || $itemType == 'array' || ($typeIsArray && ($itemType.indexOf('object') >= 0 || $itemType.indexOf('array') >= 0))) {
4166 out += ' outer: for (;i--;) { for (j = i; j--;) { if (equal(' + ($data) + '[i], ' + ($data) + '[j])) { ' + ($valid) + ' = false; break outer; } } } ';
4167 } else {
4168 out += ' var itemIndices = {}, item; for (;i--;) { var item = ' + ($data) + '[i]; ';
4169 var $method = 'checkDataType' + ($typeIsArray ? 's' : '');
4170 out += ' if (' + (it.util[$method]($itemType, 'item', it.opts.strictNumbers, true)) + ') continue; ';
4171 if ($typeIsArray) {
4172 out += ' if (typeof item == \'string\') item = \'"\' + item; ';
4173 }
4174 out += ' if (typeof itemIndices[item] == \'number\') { ' + ($valid) + ' = false; j = itemIndices[item]; break; } itemIndices[item] = i; } ';
4175 }
4176 out += ' } ';
4177 if ($isData) {
4178 out += ' } ';
4179 }
4180 out += ' if (!' + ($valid) + ') { ';
4181 var $$outStack = $$outStack || [];
4182 $$outStack.push(out);
4183 out = ''; /* istanbul ignore else */
4184 if (it.createErrors !== false) {
4185 out += ' { keyword: \'' + ('uniqueItems') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: ' + (it.util.toQuotedString($errSchemaPath)) + ' , params: { i: i, j: j } ';
4186 if (it.opts.messages !== false) {
4187 out += ' , message: \'should NOT have duplicate items (items ## \' + j + \' and \' + i + \' are identical)\' ';
4188 }
4189 if (it.opts.verbose) {
4190 out += ' , schema: ';
4191 if ($isData) {
4192 out += 'validate.schema' + ($schemaPath);
4193 } else {
4194 out += '' + ($schema);
4195 }
4196 out += ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' ';
4197 }
4198 out += ' } ';
4199 } else {
4200 out += ' {} ';
4201 }
4202 var __err = out;
4203 out = $$outStack.pop();
4204 if (!it.compositeRule && $breakOnError) {
4205 /* istanbul ignore if */
4206 if (it.async) {
4207 out += ' throw new ValidationError([' + (__err) + ']); ';
4208 } else {
4209 out += ' validate.errors = [' + (__err) + ']; return false; ';
4210 }
4211 } else {
4212 out += ' var err = ' + (__err) + '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ';
4213 }
4214 out += ' } ';
4215 if ($breakOnError) {
4216 out += ' else { ';
4217 }
4218 } else {
4219 if ($breakOnError) {
4220 out += ' if (true) { ';
4221 }
4222 }
4223 return out;
4224}
4225
4226},{}],38:[function(require,module,exports){
4227'use strict';
4228module.exports = function generate_validate(it, $keyword, $ruleType) {
4229 var out = '';
4230 var $async = it.schema.$async === true,
4231 $refKeywords = it.util.schemaHasRulesExcept(it.schema, it.RULES.all, '$ref'),
4232 $id = it.self._getId(it.schema);
4233 if (it.opts.strictKeywords) {
4234 var $unknownKwd = it.util.schemaUnknownRules(it.schema, it.RULES.keywords);
4235 if ($unknownKwd) {
4236 var $keywordsMsg = 'unknown keyword: ' + $unknownKwd;
4237 if (it.opts.strictKeywords === 'log') it.logger.warn($keywordsMsg);
4238 else throw new Error($keywordsMsg);
4239 }
4240 }
4241 if (it.isTop) {
4242 out += ' var validate = ';
4243 if ($async) {
4244 it.async = true;
4245 out += 'async ';
4246 }
4247 out += 'function(data, dataPath, parentData, parentDataProperty, rootData) { \'use strict\'; ';
4248 if ($id && (it.opts.sourceCode || it.opts.processCode)) {
4249 out += ' ' + ('/\*# sourceURL=' + $id + ' */') + ' ';
4250 }
4251 }
4252 if (typeof it.schema == 'boolean' || !($refKeywords || it.schema.$ref)) {
4253 var $keyword = 'false schema';
4254 var $lvl = it.level;
4255 var $dataLvl = it.dataLevel;
4256 var $schema = it.schema[$keyword];
4257 var $schemaPath = it.schemaPath + it.util.getProperty($keyword);
4258 var $errSchemaPath = it.errSchemaPath + '/' + $keyword;
4259 var $breakOnError = !it.opts.allErrors;
4260 var $errorKeyword;
4261 var $data = 'data' + ($dataLvl || '');
4262 var $valid = 'valid' + $lvl;
4263 if (it.schema === false) {
4264 if (it.isTop) {
4265 $breakOnError = true;
4266 } else {
4267 out += ' var ' + ($valid) + ' = false; ';
4268 }
4269 var $$outStack = $$outStack || [];
4270 $$outStack.push(out);
4271 out = ''; /* istanbul ignore else */
4272 if (it.createErrors !== false) {
4273 out += ' { keyword: \'' + ($errorKeyword || 'false schema') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: ' + (it.util.toQuotedString($errSchemaPath)) + ' , params: {} ';
4274 if (it.opts.messages !== false) {
4275 out += ' , message: \'boolean schema is false\' ';
4276 }
4277 if (it.opts.verbose) {
4278 out += ' , schema: false , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' ';
4279 }
4280 out += ' } ';
4281 } else {
4282 out += ' {} ';
4283 }
4284 var __err = out;
4285 out = $$outStack.pop();
4286 if (!it.compositeRule && $breakOnError) {
4287 /* istanbul ignore if */
4288 if (it.async) {
4289 out += ' throw new ValidationError([' + (__err) + ']); ';
4290 } else {
4291 out += ' validate.errors = [' + (__err) + ']; return false; ';
4292 }
4293 } else {
4294 out += ' var err = ' + (__err) + '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ';
4295 }
4296 } else {
4297 if (it.isTop) {
4298 if ($async) {
4299 out += ' return data; ';
4300 } else {
4301 out += ' validate.errors = null; return true; ';
4302 }
4303 } else {
4304 out += ' var ' + ($valid) + ' = true; ';
4305 }
4306 }
4307 if (it.isTop) {
4308 out += ' }; return validate; ';
4309 }
4310 return out;
4311 }
4312 if (it.isTop) {
4313 var $top = it.isTop,
4314 $lvl = it.level = 0,
4315 $dataLvl = it.dataLevel = 0,
4316 $data = 'data';
4317 it.rootId = it.resolve.fullPath(it.self._getId(it.root.schema));
4318 it.baseId = it.baseId || it.rootId;
4319 delete it.isTop;
4320 it.dataPathArr = [""];
4321 if (it.schema.default !== undefined && it.opts.useDefaults && it.opts.strictDefaults) {
4322 var $defaultMsg = 'default is ignored in the schema root';
4323 if (it.opts.strictDefaults === 'log') it.logger.warn($defaultMsg);
4324 else throw new Error($defaultMsg);
4325 }
4326 out += ' var vErrors = null; ';
4327 out += ' var errors = 0; ';
4328 out += ' if (rootData === undefined) rootData = data; ';
4329 } else {
4330 var $lvl = it.level,
4331 $dataLvl = it.dataLevel,
4332 $data = 'data' + ($dataLvl || '');
4333 if ($id) it.baseId = it.resolve.url(it.baseId, $id);
4334 if ($async && !it.async) throw new Error('async schema in sync schema');
4335 out += ' var errs_' + ($lvl) + ' = errors;';
4336 }
4337 var $valid = 'valid' + $lvl,
4338 $breakOnError = !it.opts.allErrors,
4339 $closingBraces1 = '',
4340 $closingBraces2 = '';
4341 var $errorKeyword;
4342 var $typeSchema = it.schema.type,
4343 $typeIsArray = Array.isArray($typeSchema);
4344 if ($typeSchema && it.opts.nullable && it.schema.nullable === true) {
4345 if ($typeIsArray) {
4346 if ($typeSchema.indexOf('null') == -1) $typeSchema = $typeSchema.concat('null');
4347 } else if ($typeSchema != 'null') {
4348 $typeSchema = [$typeSchema, 'null'];
4349 $typeIsArray = true;
4350 }
4351 }
4352 if ($typeIsArray && $typeSchema.length == 1) {
4353 $typeSchema = $typeSchema[0];
4354 $typeIsArray = false;
4355 }
4356 if (it.schema.$ref && $refKeywords) {
4357 if (it.opts.extendRefs == 'fail') {
4358 throw new Error('$ref: validation keywords used in schema at path "' + it.errSchemaPath + '" (see option extendRefs)');
4359 } else if (it.opts.extendRefs !== true) {
4360 $refKeywords = false;
4361 it.logger.warn('$ref: keywords ignored in schema at path "' + it.errSchemaPath + '"');
4362 }
4363 }
4364 if (it.schema.$comment && it.opts.$comment) {
4365 out += ' ' + (it.RULES.all.$comment.code(it, '$comment'));
4366 }
4367 if ($typeSchema) {
4368 if (it.opts.coerceTypes) {
4369 var $coerceToTypes = it.util.coerceToTypes(it.opts.coerceTypes, $typeSchema);
4370 }
4371 var $rulesGroup = it.RULES.types[$typeSchema];
4372 if ($coerceToTypes || $typeIsArray || $rulesGroup === true || ($rulesGroup && !$shouldUseGroup($rulesGroup))) {
4373 var $schemaPath = it.schemaPath + '.type',
4374 $errSchemaPath = it.errSchemaPath + '/type';
4375 var $schemaPath = it.schemaPath + '.type',
4376 $errSchemaPath = it.errSchemaPath + '/type',
4377 $method = $typeIsArray ? 'checkDataTypes' : 'checkDataType';
4378 out += ' if (' + (it.util[$method]($typeSchema, $data, it.opts.strictNumbers, true)) + ') { ';
4379 if ($coerceToTypes) {
4380 var $dataType = 'dataType' + $lvl,
4381 $coerced = 'coerced' + $lvl;
4382 out += ' var ' + ($dataType) + ' = typeof ' + ($data) + '; var ' + ($coerced) + ' = undefined; ';
4383 if (it.opts.coerceTypes == 'array') {
4384 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) + '; } ';
4385 }
4386 out += ' if (' + ($coerced) + ' !== undefined) ; ';
4387 var arr1 = $coerceToTypes;
4388 if (arr1) {
4389 var $type, $i = -1,
4390 l1 = arr1.length - 1;
4391 while ($i < l1) {
4392 $type = arr1[$i += 1];
4393 if ($type == 'string') {
4394 out += ' else if (' + ($dataType) + ' == \'number\' || ' + ($dataType) + ' == \'boolean\') ' + ($coerced) + ' = \'\' + ' + ($data) + '; else if (' + ($data) + ' === null) ' + ($coerced) + ' = \'\'; ';
4395 } else if ($type == 'number' || $type == 'integer') {
4396 out += ' else if (' + ($dataType) + ' == \'boolean\' || ' + ($data) + ' === null || (' + ($dataType) + ' == \'string\' && ' + ($data) + ' && ' + ($data) + ' == +' + ($data) + ' ';
4397 if ($type == 'integer') {
4398 out += ' && !(' + ($data) + ' % 1)';
4399 }
4400 out += ')) ' + ($coerced) + ' = +' + ($data) + '; ';
4401 } else if ($type == 'boolean') {
4402 out += ' else if (' + ($data) + ' === \'false\' || ' + ($data) + ' === 0 || ' + ($data) + ' === null) ' + ($coerced) + ' = false; else if (' + ($data) + ' === \'true\' || ' + ($data) + ' === 1) ' + ($coerced) + ' = true; ';
4403 } else if ($type == 'null') {
4404 out += ' else if (' + ($data) + ' === \'\' || ' + ($data) + ' === 0 || ' + ($data) + ' === false) ' + ($coerced) + ' = null; ';
4405 } else if (it.opts.coerceTypes == 'array' && $type == 'array') {
4406 out += ' else if (' + ($dataType) + ' == \'string\' || ' + ($dataType) + ' == \'number\' || ' + ($dataType) + ' == \'boolean\' || ' + ($data) + ' == null) ' + ($coerced) + ' = [' + ($data) + ']; ';
4407 }
4408 }
4409 }
4410 out += ' else { ';
4411 var $$outStack = $$outStack || [];
4412 $$outStack.push(out);
4413 out = ''; /* istanbul ignore else */
4414 if (it.createErrors !== false) {
4415 out += ' { keyword: \'' + ($errorKeyword || 'type') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: ' + (it.util.toQuotedString($errSchemaPath)) + ' , params: { type: \'';
4416 if ($typeIsArray) {
4417 out += '' + ($typeSchema.join(","));
4418 } else {
4419 out += '' + ($typeSchema);
4420 }
4421 out += '\' } ';
4422 if (it.opts.messages !== false) {
4423 out += ' , message: \'should be ';
4424 if ($typeIsArray) {
4425 out += '' + ($typeSchema.join(","));
4426 } else {
4427 out += '' + ($typeSchema);
4428 }
4429 out += '\' ';
4430 }
4431 if (it.opts.verbose) {
4432 out += ' , schema: validate.schema' + ($schemaPath) + ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' ';
4433 }
4434 out += ' } ';
4435 } else {
4436 out += ' {} ';
4437 }
4438 var __err = out;
4439 out = $$outStack.pop();
4440 if (!it.compositeRule && $breakOnError) {
4441 /* istanbul ignore if */
4442 if (it.async) {
4443 out += ' throw new ValidationError([' + (__err) + ']); ';
4444 } else {
4445 out += ' validate.errors = [' + (__err) + ']; return false; ';
4446 }
4447 } else {
4448 out += ' var err = ' + (__err) + '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ';
4449 }
4450 out += ' } if (' + ($coerced) + ' !== undefined) { ';
4451 var $parentData = $dataLvl ? 'data' + (($dataLvl - 1) || '') : 'parentData',
4452 $parentDataProperty = $dataLvl ? it.dataPathArr[$dataLvl] : 'parentDataProperty';
4453 out += ' ' + ($data) + ' = ' + ($coerced) + '; ';
4454 if (!$dataLvl) {
4455 out += 'if (' + ($parentData) + ' !== undefined)';
4456 }
4457 out += ' ' + ($parentData) + '[' + ($parentDataProperty) + '] = ' + ($coerced) + '; } ';
4458 } else {
4459 var $$outStack = $$outStack || [];
4460 $$outStack.push(out);
4461 out = ''; /* istanbul ignore else */
4462 if (it.createErrors !== false) {
4463 out += ' { keyword: \'' + ($errorKeyword || 'type') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: ' + (it.util.toQuotedString($errSchemaPath)) + ' , params: { type: \'';
4464 if ($typeIsArray) {
4465 out += '' + ($typeSchema.join(","));
4466 } else {
4467 out += '' + ($typeSchema);
4468 }
4469 out += '\' } ';
4470 if (it.opts.messages !== false) {
4471 out += ' , message: \'should be ';
4472 if ($typeIsArray) {
4473 out += '' + ($typeSchema.join(","));
4474 } else {
4475 out += '' + ($typeSchema);
4476 }
4477 out += '\' ';
4478 }
4479 if (it.opts.verbose) {
4480 out += ' , schema: validate.schema' + ($schemaPath) + ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' ';
4481 }
4482 out += ' } ';
4483 } else {
4484 out += ' {} ';
4485 }
4486 var __err = out;
4487 out = $$outStack.pop();
4488 if (!it.compositeRule && $breakOnError) {
4489 /* istanbul ignore if */
4490 if (it.async) {
4491 out += ' throw new ValidationError([' + (__err) + ']); ';
4492 } else {
4493 out += ' validate.errors = [' + (__err) + ']; return false; ';
4494 }
4495 } else {
4496 out += ' var err = ' + (__err) + '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ';
4497 }
4498 }
4499 out += ' } ';
4500 }
4501 }
4502 if (it.schema.$ref && !$refKeywords) {
4503 out += ' ' + (it.RULES.all.$ref.code(it, '$ref')) + ' ';
4504 if ($breakOnError) {
4505 out += ' } if (errors === ';
4506 if ($top) {
4507 out += '0';
4508 } else {
4509 out += 'errs_' + ($lvl);
4510 }
4511 out += ') { ';
4512 $closingBraces2 += '}';
4513 }
4514 } else {
4515 var arr2 = it.RULES;
4516 if (arr2) {
4517 var $rulesGroup, i2 = -1,
4518 l2 = arr2.length - 1;
4519 while (i2 < l2) {
4520 $rulesGroup = arr2[i2 += 1];
4521 if ($shouldUseGroup($rulesGroup)) {
4522 if ($rulesGroup.type) {
4523 out += ' if (' + (it.util.checkDataType($rulesGroup.type, $data, it.opts.strictNumbers)) + ') { ';
4524 }
4525 if (it.opts.useDefaults) {
4526 if ($rulesGroup.type == 'object' && it.schema.properties) {
4527 var $schema = it.schema.properties,
4528 $schemaKeys = Object.keys($schema);
4529 var arr3 = $schemaKeys;
4530 if (arr3) {
4531 var $propertyKey, i3 = -1,
4532 l3 = arr3.length - 1;
4533 while (i3 < l3) {
4534 $propertyKey = arr3[i3 += 1];
4535 var $sch = $schema[$propertyKey];
4536 if ($sch.default !== undefined) {
4537 var $passData = $data + it.util.getProperty($propertyKey);
4538 if (it.compositeRule) {
4539 if (it.opts.strictDefaults) {
4540 var $defaultMsg = 'default is ignored for: ' + $passData;
4541 if (it.opts.strictDefaults === 'log') it.logger.warn($defaultMsg);
4542 else throw new Error($defaultMsg);
4543 }
4544 } else {
4545 out += ' if (' + ($passData) + ' === undefined ';
4546 if (it.opts.useDefaults == 'empty') {
4547 out += ' || ' + ($passData) + ' === null || ' + ($passData) + ' === \'\' ';
4548 }
4549 out += ' ) ' + ($passData) + ' = ';
4550 if (it.opts.useDefaults == 'shared') {
4551 out += ' ' + (it.useDefault($sch.default)) + ' ';
4552 } else {
4553 out += ' ' + (JSON.stringify($sch.default)) + ' ';
4554 }
4555 out += '; ';
4556 }
4557 }
4558 }
4559 }
4560 } else if ($rulesGroup.type == 'array' && Array.isArray(it.schema.items)) {
4561 var arr4 = it.schema.items;
4562 if (arr4) {
4563 var $sch, $i = -1,
4564 l4 = arr4.length - 1;
4565 while ($i < l4) {
4566 $sch = arr4[$i += 1];
4567 if ($sch.default !== undefined) {
4568 var $passData = $data + '[' + $i + ']';
4569 if (it.compositeRule) {
4570 if (it.opts.strictDefaults) {
4571 var $defaultMsg = 'default is ignored for: ' + $passData;
4572 if (it.opts.strictDefaults === 'log') it.logger.warn($defaultMsg);
4573 else throw new Error($defaultMsg);
4574 }
4575 } else {
4576 out += ' if (' + ($passData) + ' === undefined ';
4577 if (it.opts.useDefaults == 'empty') {
4578 out += ' || ' + ($passData) + ' === null || ' + ($passData) + ' === \'\' ';
4579 }
4580 out += ' ) ' + ($passData) + ' = ';
4581 if (it.opts.useDefaults == 'shared') {
4582 out += ' ' + (it.useDefault($sch.default)) + ' ';
4583 } else {
4584 out += ' ' + (JSON.stringify($sch.default)) + ' ';
4585 }
4586 out += '; ';
4587 }
4588 }
4589 }
4590 }
4591 }
4592 }
4593 var arr5 = $rulesGroup.rules;
4594 if (arr5) {
4595 var $rule, i5 = -1,
4596 l5 = arr5.length - 1;
4597 while (i5 < l5) {
4598 $rule = arr5[i5 += 1];
4599 if ($shouldUseRule($rule)) {
4600 var $code = $rule.code(it, $rule.keyword, $rulesGroup.type);
4601 if ($code) {
4602 out += ' ' + ($code) + ' ';
4603 if ($breakOnError) {
4604 $closingBraces1 += '}';
4605 }
4606 }
4607 }
4608 }
4609 }
4610 if ($breakOnError) {
4611 out += ' ' + ($closingBraces1) + ' ';
4612 $closingBraces1 = '';
4613 }
4614 if ($rulesGroup.type) {
4615 out += ' } ';
4616 if ($typeSchema && $typeSchema === $rulesGroup.type && !$coerceToTypes) {
4617 out += ' else { ';
4618 var $schemaPath = it.schemaPath + '.type',
4619 $errSchemaPath = it.errSchemaPath + '/type';
4620 var $$outStack = $$outStack || [];
4621 $$outStack.push(out);
4622 out = ''; /* istanbul ignore else */
4623 if (it.createErrors !== false) {
4624 out += ' { keyword: \'' + ($errorKeyword || 'type') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: ' + (it.util.toQuotedString($errSchemaPath)) + ' , params: { type: \'';
4625 if ($typeIsArray) {
4626 out += '' + ($typeSchema.join(","));
4627 } else {
4628 out += '' + ($typeSchema);
4629 }
4630 out += '\' } ';
4631 if (it.opts.messages !== false) {
4632 out += ' , message: \'should be ';
4633 if ($typeIsArray) {
4634 out += '' + ($typeSchema.join(","));
4635 } else {
4636 out += '' + ($typeSchema);
4637 }
4638 out += '\' ';
4639 }
4640 if (it.opts.verbose) {
4641 out += ' , schema: validate.schema' + ($schemaPath) + ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' ';
4642 }
4643 out += ' } ';
4644 } else {
4645 out += ' {} ';
4646 }
4647 var __err = out;
4648 out = $$outStack.pop();
4649 if (!it.compositeRule && $breakOnError) {
4650 /* istanbul ignore if */
4651 if (it.async) {
4652 out += ' throw new ValidationError([' + (__err) + ']); ';
4653 } else {
4654 out += ' validate.errors = [' + (__err) + ']; return false; ';
4655 }
4656 } else {
4657 out += ' var err = ' + (__err) + '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ';
4658 }
4659 out += ' } ';
4660 }
4661 }
4662 if ($breakOnError) {
4663 out += ' if (errors === ';
4664 if ($top) {
4665 out += '0';
4666 } else {
4667 out += 'errs_' + ($lvl);
4668 }
4669 out += ') { ';
4670 $closingBraces2 += '}';
4671 }
4672 }
4673 }
4674 }
4675 }
4676 if ($breakOnError) {
4677 out += ' ' + ($closingBraces2) + ' ';
4678 }
4679 if ($top) {
4680 if ($async) {
4681 out += ' if (errors === 0) return data; ';
4682 out += ' else throw new ValidationError(vErrors); ';
4683 } else {
4684 out += ' validate.errors = vErrors; ';
4685 out += ' return errors === 0; ';
4686 }
4687 out += ' }; return validate;';
4688 } else {
4689 out += ' var ' + ($valid) + ' = errors === errs_' + ($lvl) + ';';
4690 }
4691
4692 function $shouldUseGroup($rulesGroup) {
4693 var rules = $rulesGroup.rules;
4694 for (var i = 0; i < rules.length; i++)
4695 if ($shouldUseRule(rules[i])) return true;
4696 }
4697
4698 function $shouldUseRule($rule) {
4699 return it.schema[$rule.keyword] !== undefined || ($rule.implements && $ruleImplementsSomeKeyword($rule));
4700 }
4701
4702 function $ruleImplementsSomeKeyword($rule) {
4703 var impl = $rule.implements;
4704 for (var i = 0; i < impl.length; i++)
4705 if (it.schema[impl[i]] !== undefined) return true;
4706 }
4707 return out;
4708}
4709
4710},{}],39:[function(require,module,exports){
4711'use strict';
4712
4713var IDENTIFIER = /^[a-z_$][a-z0-9_$-]*$/i;
4714var customRuleCode = require('./dotjs/custom');
4715var definitionSchema = require('./definition_schema');
4716
4717module.exports = {
4718 add: addKeyword,
4719 get: getKeyword,
4720 remove: removeKeyword,
4721 validate: validateKeyword
4722};
4723
4724
4725/**
4726 * Define custom keyword
4727 * @this Ajv
4728 * @param {String} keyword custom keyword, should be unique (including different from all standard, custom and macro keywords).
4729 * @param {Object} definition keyword definition object with properties `type` (type(s) which the keyword applies to), `validate` or `compile`.
4730 * @return {Ajv} this for method chaining
4731 */
4732function addKeyword(keyword, definition) {
4733 /* jshint validthis: true */
4734 /* eslint no-shadow: 0 */
4735 var RULES = this.RULES;
4736 if (RULES.keywords[keyword])
4737 throw new Error('Keyword ' + keyword + ' is already defined');
4738
4739 if (!IDENTIFIER.test(keyword))
4740 throw new Error('Keyword ' + keyword + ' is not a valid identifier');
4741
4742 if (definition) {
4743 this.validateKeyword(definition, true);
4744
4745 var dataType = definition.type;
4746 if (Array.isArray(dataType)) {
4747 for (var i=0; i<dataType.length; i++)
4748 _addRule(keyword, dataType[i], definition);
4749 } else {
4750 _addRule(keyword, dataType, definition);
4751 }
4752
4753 var metaSchema = definition.metaSchema;
4754 if (metaSchema) {
4755 if (definition.$data && this._opts.$data) {
4756 metaSchema = {
4757 anyOf: [
4758 metaSchema,
4759 { '$ref': 'https://raw.githubusercontent.com/ajv-validator/ajv/master/lib/refs/data.json#' }
4760 ]
4761 };
4762 }
4763 definition.validateSchema = this.compile(metaSchema, true);
4764 }
4765 }
4766
4767 RULES.keywords[keyword] = RULES.all[keyword] = true;
4768
4769
4770 function _addRule(keyword, dataType, definition) {
4771 var ruleGroup;
4772 for (var i=0; i<RULES.length; i++) {
4773 var rg = RULES[i];
4774 if (rg.type == dataType) {
4775 ruleGroup = rg;
4776 break;
4777 }
4778 }
4779
4780 if (!ruleGroup) {
4781 ruleGroup = { type: dataType, rules: [] };
4782 RULES.push(ruleGroup);
4783 }
4784
4785 var rule = {
4786 keyword: keyword,
4787 definition: definition,
4788 custom: true,
4789 code: customRuleCode,
4790 implements: definition.implements
4791 };
4792 ruleGroup.rules.push(rule);
4793 RULES.custom[keyword] = rule;
4794 }
4795
4796 return this;
4797}
4798
4799
4800/**
4801 * Get keyword
4802 * @this Ajv
4803 * @param {String} keyword pre-defined or custom keyword.
4804 * @return {Object|Boolean} custom keyword definition, `true` if it is a predefined keyword, `false` otherwise.
4805 */
4806function getKeyword(keyword) {
4807 /* jshint validthis: true */
4808 var rule = this.RULES.custom[keyword];
4809 return rule ? rule.definition : this.RULES.keywords[keyword] || false;
4810}
4811
4812
4813/**
4814 * Remove keyword
4815 * @this Ajv
4816 * @param {String} keyword pre-defined or custom keyword.
4817 * @return {Ajv} this for method chaining
4818 */
4819function removeKeyword(keyword) {
4820 /* jshint validthis: true */
4821 var RULES = this.RULES;
4822 delete RULES.keywords[keyword];
4823 delete RULES.all[keyword];
4824 delete RULES.custom[keyword];
4825 for (var i=0; i<RULES.length; i++) {
4826 var rules = RULES[i].rules;
4827 for (var j=0; j<rules.length; j++) {
4828 if (rules[j].keyword == keyword) {
4829 rules.splice(j, 1);
4830 break;
4831 }
4832 }
4833 }
4834 return this;
4835}
4836
4837
4838/**
4839 * Validate keyword definition
4840 * @this Ajv
4841 * @param {Object} definition keyword definition object.
4842 * @param {Boolean} throwError true to throw exception if definition is invalid
4843 * @return {boolean} validation result
4844 */
4845function validateKeyword(definition, throwError) {
4846 validateKeyword.errors = null;
4847 var v = this._validateKeyword = this._validateKeyword
4848 || this.compile(definitionSchema, true);
4849
4850 if (v(definition)) return true;
4851 validateKeyword.errors = v.errors;
4852 if (throwError)
4853 throw new Error('custom keyword definition is invalid: ' + this.errorsText(v.errors));
4854 else
4855 return false;
4856}
4857
4858},{"./definition_schema":12,"./dotjs/custom":22}],40:[function(require,module,exports){
4859module.exports={
4860 "$schema": "http://json-schema.org/draft-07/schema#",
4861 "$id": "https://raw.githubusercontent.com/ajv-validator/ajv/master/lib/refs/data.json#",
4862 "description": "Meta-schema for $data reference (JSON Schema extension proposal)",
4863 "type": "object",
4864 "required": [ "$data" ],
4865 "properties": {
4866 "$data": {
4867 "type": "string",
4868 "anyOf": [
4869 { "format": "relative-json-pointer" },
4870 { "format": "json-pointer" }
4871 ]
4872 }
4873 },
4874 "additionalProperties": false
4875}
4876
4877},{}],41:[function(require,module,exports){
4878module.exports={
4879 "$schema": "http://json-schema.org/draft-07/schema#",
4880 "$id": "http://json-schema.org/draft-07/schema#",
4881 "title": "Core schema meta-schema",
4882 "definitions": {
4883 "schemaArray": {
4884 "type": "array",
4885 "minItems": 1,
4886 "items": { "$ref": "#" }
4887 },
4888 "nonNegativeInteger": {
4889 "type": "integer",
4890 "minimum": 0
4891 },
4892 "nonNegativeIntegerDefault0": {
4893 "allOf": [
4894 { "$ref": "#/definitions/nonNegativeInteger" },
4895 { "default": 0 }
4896 ]
4897 },
4898 "simpleTypes": {
4899 "enum": [
4900 "array",
4901 "boolean",
4902 "integer",
4903 "null",
4904 "number",
4905 "object",
4906 "string"
4907 ]
4908 },
4909 "stringArray": {
4910 "type": "array",
4911 "items": { "type": "string" },
4912 "uniqueItems": true,
4913 "default": []
4914 }
4915 },
4916 "type": ["object", "boolean"],
4917 "properties": {
4918 "$id": {
4919 "type": "string",
4920 "format": "uri-reference"
4921 },
4922 "$schema": {
4923 "type": "string",
4924 "format": "uri"
4925 },
4926 "$ref": {
4927 "type": "string",
4928 "format": "uri-reference"
4929 },
4930 "$comment": {
4931 "type": "string"
4932 },
4933 "title": {
4934 "type": "string"
4935 },
4936 "description": {
4937 "type": "string"
4938 },
4939 "default": true,
4940 "readOnly": {
4941 "type": "boolean",
4942 "default": false
4943 },
4944 "examples": {
4945 "type": "array",
4946 "items": true
4947 },
4948 "multipleOf": {
4949 "type": "number",
4950 "exclusiveMinimum": 0
4951 },
4952 "maximum": {
4953 "type": "number"
4954 },
4955 "exclusiveMaximum": {
4956 "type": "number"
4957 },
4958 "minimum": {
4959 "type": "number"
4960 },
4961 "exclusiveMinimum": {
4962 "type": "number"
4963 },
4964 "maxLength": { "$ref": "#/definitions/nonNegativeInteger" },
4965 "minLength": { "$ref": "#/definitions/nonNegativeIntegerDefault0" },
4966 "pattern": {
4967 "type": "string",
4968 "format": "regex"
4969 },
4970 "additionalItems": { "$ref": "#" },
4971 "items": {
4972 "anyOf": [
4973 { "$ref": "#" },
4974 { "$ref": "#/definitions/schemaArray" }
4975 ],
4976 "default": true
4977 },
4978 "maxItems": { "$ref": "#/definitions/nonNegativeInteger" },
4979 "minItems": { "$ref": "#/definitions/nonNegativeIntegerDefault0" },
4980 "uniqueItems": {
4981 "type": "boolean",
4982 "default": false
4983 },
4984 "contains": { "$ref": "#" },
4985 "maxProperties": { "$ref": "#/definitions/nonNegativeInteger" },
4986 "minProperties": { "$ref": "#/definitions/nonNegativeIntegerDefault0" },
4987 "required": { "$ref": "#/definitions/stringArray" },
4988 "additionalProperties": { "$ref": "#" },
4989 "definitions": {
4990 "type": "object",
4991 "additionalProperties": { "$ref": "#" },
4992 "default": {}
4993 },
4994 "properties": {
4995 "type": "object",
4996 "additionalProperties": { "$ref": "#" },
4997 "default": {}
4998 },
4999 "patternProperties": {
5000 "type": "object",
5001 "additionalProperties": { "$ref": "#" },
5002 "propertyNames": { "format": "regex" },
5003 "default": {}
5004 },
5005 "dependencies": {
5006 "type": "object",
5007 "additionalProperties": {
5008 "anyOf": [
5009 { "$ref": "#" },
5010 { "$ref": "#/definitions/stringArray" }
5011 ]
5012 }
5013 },
5014 "propertyNames": { "$ref": "#" },
5015 "const": true,
5016 "enum": {
5017 "type": "array",
5018 "items": true,
5019 "minItems": 1,
5020 "uniqueItems": true
5021 },
5022 "type": {
5023 "anyOf": [
5024 { "$ref": "#/definitions/simpleTypes" },
5025 {
5026 "type": "array",
5027 "items": { "$ref": "#/definitions/simpleTypes" },
5028 "minItems": 1,
5029 "uniqueItems": true
5030 }
5031 ]
5032 },
5033 "format": { "type": "string" },
5034 "contentMediaType": { "type": "string" },
5035 "contentEncoding": { "type": "string" },
5036 "if": {"$ref": "#"},
5037 "then": {"$ref": "#"},
5038 "else": {"$ref": "#"},
5039 "allOf": { "$ref": "#/definitions/schemaArray" },
5040 "anyOf": { "$ref": "#/definitions/schemaArray" },
5041 "oneOf": { "$ref": "#/definitions/schemaArray" },
5042 "not": { "$ref": "#" }
5043 },
5044 "default": true
5045}
5046
5047},{}],42:[function(require,module,exports){
5048'use strict';
5049
5050// do not edit .js files directly - edit src/index.jst
5051
5052
5053
5054module.exports = function equal(a, b) {
5055 if (a === b) return true;
5056
5057 if (a && b && typeof a == 'object' && typeof b == 'object') {
5058 if (a.constructor !== b.constructor) return false;
5059
5060 var length, i, keys;
5061 if (Array.isArray(a)) {
5062 length = a.length;
5063 if (length != b.length) return false;
5064 for (i = length; i-- !== 0;)
5065 if (!equal(a[i], b[i])) return false;
5066 return true;
5067 }
5068
5069
5070
5071 if (a.constructor === RegExp) return a.source === b.source && a.flags === b.flags;
5072 if (a.valueOf !== Object.prototype.valueOf) return a.valueOf() === b.valueOf();
5073 if (a.toString !== Object.prototype.toString) return a.toString() === b.toString();
5074
5075 keys = Object.keys(a);
5076 length = keys.length;
5077 if (length !== Object.keys(b).length) return false;
5078
5079 for (i = length; i-- !== 0;)
5080 if (!Object.prototype.hasOwnProperty.call(b, keys[i])) return false;
5081
5082 for (i = length; i-- !== 0;) {
5083 var key = keys[i];
5084
5085 if (!equal(a[key], b[key])) return false;
5086 }
5087
5088 return true;
5089 }
5090
5091 // true if both NaN, false otherwise
5092 return a!==a && b!==b;
5093};
5094
5095},{}],43:[function(require,module,exports){
5096'use strict';
5097
5098module.exports = function (data, opts) {
5099 if (!opts) opts = {};
5100 if (typeof opts === 'function') opts = { cmp: opts };
5101 var cycles = (typeof opts.cycles === 'boolean') ? opts.cycles : false;
5102
5103 var cmp = opts.cmp && (function (f) {
5104 return function (node) {
5105 return function (a, b) {
5106 var aobj = { key: a, value: node[a] };
5107 var bobj = { key: b, value: node[b] };
5108 return f(aobj, bobj);
5109 };
5110 };
5111 })(opts.cmp);
5112
5113 var seen = [];
5114 return (function stringify (node) {
5115 if (node && node.toJSON && typeof node.toJSON === 'function') {
5116 node = node.toJSON();
5117 }
5118
5119 if (node === undefined) return;
5120 if (typeof node == 'number') return isFinite(node) ? '' + node : 'null';
5121 if (typeof node !== 'object') return JSON.stringify(node);
5122
5123 var i, out;
5124 if (Array.isArray(node)) {
5125 out = '[';
5126 for (i = 0; i < node.length; i++) {
5127 if (i) out += ',';
5128 out += stringify(node[i]) || 'null';
5129 }
5130 return out + ']';
5131 }
5132
5133 if (node === null) return 'null';
5134
5135 if (seen.indexOf(node) !== -1) {
5136 if (cycles) return JSON.stringify('__cycle__');
5137 throw new TypeError('Converting circular structure to JSON');
5138 }
5139
5140 var seenIndex = seen.push(node) - 1;
5141 var keys = Object.keys(node).sort(cmp && cmp(node));
5142 out = '';
5143 for (i = 0; i < keys.length; i++) {
5144 var key = keys[i];
5145 var value = stringify(node[key]);
5146
5147 if (!value) continue;
5148 if (out) out += ',';
5149 out += JSON.stringify(key) + ':' + value;
5150 }
5151 seen.splice(seenIndex, 1);
5152 return '{' + out + '}';
5153 })(data);
5154};
5155
5156},{}],44:[function(require,module,exports){
5157'use strict';
5158
5159var traverse = module.exports = function (schema, opts, cb) {
5160 // Legacy support for v0.3.1 and earlier.
5161 if (typeof opts == 'function') {
5162 cb = opts;
5163 opts = {};
5164 }
5165
5166 cb = opts.cb || cb;
5167 var pre = (typeof cb == 'function') ? cb : cb.pre || function() {};
5168 var post = cb.post || function() {};
5169
5170 _traverse(opts, pre, post, schema, '', schema);
5171};
5172
5173
5174traverse.keywords = {
5175 additionalItems: true,
5176 items: true,
5177 contains: true,
5178 additionalProperties: true,
5179 propertyNames: true,
5180 not: true
5181};
5182
5183traverse.arrayKeywords = {
5184 items: true,
5185 allOf: true,
5186 anyOf: true,
5187 oneOf: true
5188};
5189
5190traverse.propsKeywords = {
5191 definitions: true,
5192 properties: true,
5193 patternProperties: true,
5194 dependencies: true
5195};
5196
5197traverse.skipKeywords = {
5198 default: true,
5199 enum: true,
5200 const: true,
5201 required: true,
5202 maximum: true,
5203 minimum: true,
5204 exclusiveMaximum: true,
5205 exclusiveMinimum: true,
5206 multipleOf: true,
5207 maxLength: true,
5208 minLength: true,
5209 pattern: true,
5210 format: true,
5211 maxItems: true,
5212 minItems: true,
5213 uniqueItems: true,
5214 maxProperties: true,
5215 minProperties: true
5216};
5217
5218
5219function _traverse(opts, pre, post, schema, jsonPtr, rootSchema, parentJsonPtr, parentKeyword, parentSchema, keyIndex) {
5220 if (schema && typeof schema == 'object' && !Array.isArray(schema)) {
5221 pre(schema, jsonPtr, rootSchema, parentJsonPtr, parentKeyword, parentSchema, keyIndex);
5222 for (var key in schema) {
5223 var sch = schema[key];
5224 if (Array.isArray(sch)) {
5225 if (key in traverse.arrayKeywords) {
5226 for (var i=0; i<sch.length; i++)
5227 _traverse(opts, pre, post, sch[i], jsonPtr + '/' + key + '/' + i, rootSchema, jsonPtr, key, schema, i);
5228 }
5229 } else if (key in traverse.propsKeywords) {
5230 if (sch && typeof sch == 'object') {
5231 for (var prop in sch)
5232 _traverse(opts, pre, post, sch[prop], jsonPtr + '/' + key + '/' + escapeJsonPtr(prop), rootSchema, jsonPtr, key, schema, prop);
5233 }
5234 } else if (key in traverse.keywords || (opts.allKeys && !(key in traverse.skipKeywords))) {
5235 _traverse(opts, pre, post, sch, jsonPtr + '/' + key, rootSchema, jsonPtr, key, schema);
5236 }
5237 }
5238 post(schema, jsonPtr, rootSchema, parentJsonPtr, parentKeyword, parentSchema, keyIndex);
5239 }
5240}
5241
5242
5243function escapeJsonPtr(str) {
5244 return str.replace(/~/g, '~0').replace(/\//g, '~1');
5245}
5246
5247},{}],45:[function(require,module,exports){
5248/** @license URI.js v4.4.1 (c) 2011 Gary Court. License: http://github.com/garycourt/uri-js */
5249(function (global, factory) {
5250 typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
5251 typeof define === 'function' && define.amd ? define(['exports'], factory) :
5252 (factory((global.URI = global.URI || {})));
5253}(this, (function (exports) { 'use strict';
5254
5255function merge() {
5256 for (var _len = arguments.length, sets = Array(_len), _key = 0; _key < _len; _key++) {
5257 sets[_key] = arguments[_key];
5258 }
5259
5260 if (sets.length > 1) {
5261 sets[0] = sets[0].slice(0, -1);
5262 var xl = sets.length - 1;
5263 for (var x = 1; x < xl; ++x) {
5264 sets[x] = sets[x].slice(1, -1);
5265 }
5266 sets[xl] = sets[xl].slice(1);
5267 return sets.join('');
5268 } else {
5269 return sets[0];
5270 }
5271}
5272function subexp(str) {
5273 return "(?:" + str + ")";
5274}
5275function typeOf(o) {
5276 return o === undefined ? "undefined" : o === null ? "null" : Object.prototype.toString.call(o).split(" ").pop().split("]").shift().toLowerCase();
5277}
5278function toUpperCase(str) {
5279 return str.toUpperCase();
5280}
5281function toArray(obj) {
5282 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) : [];
5283}
5284function assign(target, source) {
5285 var obj = target;
5286 if (source) {
5287 for (var key in source) {
5288 obj[key] = source[key];
5289 }
5290 }
5291 return obj;
5292}
5293
5294function buildExps(isIRI) {
5295 var ALPHA$$ = "[A-Za-z]",
5296 CR$ = "[\\x0D]",
5297 DIGIT$$ = "[0-9]",
5298 DQUOTE$$ = "[\\x22]",
5299 HEXDIG$$ = merge(DIGIT$$, "[A-Fa-f]"),
5300 //case-insensitive
5301 LF$$ = "[\\x0A]",
5302 SP$$ = "[\\x20]",
5303 PCT_ENCODED$ = subexp(subexp("%[EFef]" + HEXDIG$$ + "%" + HEXDIG$$ + HEXDIG$$ + "%" + HEXDIG$$ + HEXDIG$$) + "|" + subexp("%[89A-Fa-f]" + HEXDIG$$ + "%" + HEXDIG$$ + HEXDIG$$) + "|" + subexp("%" + HEXDIG$$ + HEXDIG$$)),
5304 //expanded
5305 GEN_DELIMS$$ = "[\\:\\/\\?\\#\\[\\]\\@]",
5306 SUB_DELIMS$$ = "[\\!\\$\\&\\'\\(\\)\\*\\+\\,\\;\\=]",
5307 RESERVED$$ = merge(GEN_DELIMS$$, SUB_DELIMS$$),
5308 UCSCHAR$$ = isIRI ? "[\\xA0-\\u200D\\u2010-\\u2029\\u202F-\\uD7FF\\uF900-\\uFDCF\\uFDF0-\\uFFEF]" : "[]",
5309 //subset, excludes bidi control characters
5310 IPRIVATE$$ = isIRI ? "[\\uE000-\\uF8FF]" : "[]",
5311 //subset
5312 UNRESERVED$$ = merge(ALPHA$$, DIGIT$$, "[\\-\\.\\_\\~]", UCSCHAR$$),
5313 SCHEME$ = subexp(ALPHA$$ + merge(ALPHA$$, DIGIT$$, "[\\+\\-\\.]") + "*"),
5314 USERINFO$ = subexp(subexp(PCT_ENCODED$ + "|" + merge(UNRESERVED$$, SUB_DELIMS$$, "[\\:]")) + "*"),
5315 DEC_OCTET$ = subexp(subexp("25[0-5]") + "|" + subexp("2[0-4]" + DIGIT$$) + "|" + subexp("1" + DIGIT$$ + DIGIT$$) + "|" + subexp("[1-9]" + DIGIT$$) + "|" + DIGIT$$),
5316 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$$),
5317 //relaxed parsing rules
5318 IPV4ADDRESS$ = subexp(DEC_OCTET_RELAXED$ + "\\." + DEC_OCTET_RELAXED$ + "\\." + DEC_OCTET_RELAXED$ + "\\." + DEC_OCTET_RELAXED$),
5319 H16$ = subexp(HEXDIG$$ + "{1,4}"),
5320 LS32$ = subexp(subexp(H16$ + "\\:" + H16$) + "|" + IPV4ADDRESS$),
5321 IPV6ADDRESS1$ = subexp(subexp(H16$ + "\\:") + "{6}" + LS32$),
5322 // 6( h16 ":" ) ls32
5323 IPV6ADDRESS2$ = subexp("\\:\\:" + subexp(H16$ + "\\:") + "{5}" + LS32$),
5324 // "::" 5( h16 ":" ) ls32
5325 IPV6ADDRESS3$ = subexp(subexp(H16$) + "?\\:\\:" + subexp(H16$ + "\\:") + "{4}" + LS32$),
5326 //[ h16 ] "::" 4( h16 ":" ) ls32
5327 IPV6ADDRESS4$ = subexp(subexp(subexp(H16$ + "\\:") + "{0,1}" + H16$) + "?\\:\\:" + subexp(H16$ + "\\:") + "{3}" + LS32$),
5328 //[ *1( h16 ":" ) h16 ] "::" 3( h16 ":" ) ls32
5329 IPV6ADDRESS5$ = subexp(subexp(subexp(H16$ + "\\:") + "{0,2}" + H16$) + "?\\:\\:" + subexp(H16$ + "\\:") + "{2}" + LS32$),
5330 //[ *2( h16 ":" ) h16 ] "::" 2( h16 ":" ) ls32
5331 IPV6ADDRESS6$ = subexp(subexp(subexp(H16$ + "\\:") + "{0,3}" + H16$) + "?\\:\\:" + H16$ + "\\:" + LS32$),
5332 //[ *3( h16 ":" ) h16 ] "::" h16 ":" ls32
5333 IPV6ADDRESS7$ = subexp(subexp(subexp(H16$ + "\\:") + "{0,4}" + H16$) + "?\\:\\:" + LS32$),
5334 //[ *4( h16 ":" ) h16 ] "::" ls32
5335 IPV6ADDRESS8$ = subexp(subexp(subexp(H16$ + "\\:") + "{0,5}" + H16$) + "?\\:\\:" + H16$),
5336 //[ *5( h16 ":" ) h16 ] "::" h16
5337 IPV6ADDRESS9$ = subexp(subexp(subexp(H16$ + "\\:") + "{0,6}" + H16$) + "?\\:\\:"),
5338 //[ *6( h16 ":" ) h16 ] "::"
5339 IPV6ADDRESS$ = subexp([IPV6ADDRESS1$, IPV6ADDRESS2$, IPV6ADDRESS3$, IPV6ADDRESS4$, IPV6ADDRESS5$, IPV6ADDRESS6$, IPV6ADDRESS7$, IPV6ADDRESS8$, IPV6ADDRESS9$].join("|")),
5340 ZONEID$ = subexp(subexp(UNRESERVED$$ + "|" + PCT_ENCODED$) + "+"),
5341 //RFC 6874
5342 IPV6ADDRZ$ = subexp(IPV6ADDRESS$ + "\\%25" + ZONEID$),
5343 //RFC 6874
5344 IPV6ADDRZ_RELAXED$ = subexp(IPV6ADDRESS$ + subexp("\\%25|\\%(?!" + HEXDIG$$ + "{2})") + ZONEID$),
5345 //RFC 6874, with relaxed parsing rules
5346 IPVFUTURE$ = subexp("[vV]" + HEXDIG$$ + "+\\." + merge(UNRESERVED$$, SUB_DELIMS$$, "[\\:]") + "+"),
5347 IP_LITERAL$ = subexp("\\[" + subexp(IPV6ADDRZ_RELAXED$ + "|" + IPV6ADDRESS$ + "|" + IPVFUTURE$) + "\\]"),
5348 //RFC 6874
5349 REG_NAME$ = subexp(subexp(PCT_ENCODED$ + "|" + merge(UNRESERVED$$, SUB_DELIMS$$)) + "*"),
5350 HOST$ = subexp(IP_LITERAL$ + "|" + IPV4ADDRESS$ + "(?!" + REG_NAME$ + ")" + "|" + REG_NAME$),
5351 PORT$ = subexp(DIGIT$$ + "*"),
5352 AUTHORITY$ = subexp(subexp(USERINFO$ + "@") + "?" + HOST$ + subexp("\\:" + PORT$) + "?"),
5353 PCHAR$ = subexp(PCT_ENCODED$ + "|" + merge(UNRESERVED$$, SUB_DELIMS$$, "[\\:\\@]")),
5354 SEGMENT$ = subexp(PCHAR$ + "*"),
5355 SEGMENT_NZ$ = subexp(PCHAR$ + "+"),
5356 SEGMENT_NZ_NC$ = subexp(subexp(PCT_ENCODED$ + "|" + merge(UNRESERVED$$, SUB_DELIMS$$, "[\\@]")) + "+"),
5357 PATH_ABEMPTY$ = subexp(subexp("\\/" + SEGMENT$) + "*"),
5358 PATH_ABSOLUTE$ = subexp("\\/" + subexp(SEGMENT_NZ$ + PATH_ABEMPTY$) + "?"),
5359 //simplified
5360 PATH_NOSCHEME$ = subexp(SEGMENT_NZ_NC$ + PATH_ABEMPTY$),
5361 //simplified
5362 PATH_ROOTLESS$ = subexp(SEGMENT_NZ$ + PATH_ABEMPTY$),
5363 //simplified
5364 PATH_EMPTY$ = "(?!" + PCHAR$ + ")",
5365 PATH$ = subexp(PATH_ABEMPTY$ + "|" + PATH_ABSOLUTE$ + "|" + PATH_NOSCHEME$ + "|" + PATH_ROOTLESS$ + "|" + PATH_EMPTY$),
5366 QUERY$ = subexp(subexp(PCHAR$ + "|" + merge("[\\/\\?]", IPRIVATE$$)) + "*"),
5367 FRAGMENT$ = subexp(subexp(PCHAR$ + "|[\\/\\?]") + "*"),
5368 HIER_PART$ = subexp(subexp("\\/\\/" + AUTHORITY$ + PATH_ABEMPTY$) + "|" + PATH_ABSOLUTE$ + "|" + PATH_ROOTLESS$ + "|" + PATH_EMPTY$),
5369 URI$ = subexp(SCHEME$ + "\\:" + HIER_PART$ + subexp("\\?" + QUERY$) + "?" + subexp("\\#" + FRAGMENT$) + "?"),
5370 RELATIVE_PART$ = subexp(subexp("\\/\\/" + AUTHORITY$ + PATH_ABEMPTY$) + "|" + PATH_ABSOLUTE$ + "|" + PATH_NOSCHEME$ + "|" + PATH_EMPTY$),
5371 RELATIVE$ = subexp(RELATIVE_PART$ + subexp("\\?" + QUERY$) + "?" + subexp("\\#" + FRAGMENT$) + "?"),
5372 URI_REFERENCE$ = subexp(URI$ + "|" + RELATIVE$),
5373 ABSOLUTE_URI$ = subexp(SCHEME$ + "\\:" + HIER_PART$ + subexp("\\?" + QUERY$) + "?"),
5374 GENERIC_REF$ = "^(" + SCHEME$ + ")\\:" + subexp(subexp("\\/\\/(" + subexp("(" + USERINFO$ + ")@") + "?(" + HOST$ + ")" + subexp("\\:(" + PORT$ + ")") + "?)") + "?(" + PATH_ABEMPTY$ + "|" + PATH_ABSOLUTE$ + "|" + PATH_ROOTLESS$ + "|" + PATH_EMPTY$ + ")") + subexp("\\?(" + QUERY$ + ")") + "?" + subexp("\\#(" + FRAGMENT$ + ")") + "?$",
5375 RELATIVE_REF$ = "^(){0}" + subexp(subexp("\\/\\/(" + subexp("(" + USERINFO$ + ")@") + "?(" + HOST$ + ")" + subexp("\\:(" + PORT$ + ")") + "?)") + "?(" + PATH_ABEMPTY$ + "|" + PATH_ABSOLUTE$ + "|" + PATH_NOSCHEME$ + "|" + PATH_EMPTY$ + ")") + subexp("\\?(" + QUERY$ + ")") + "?" + subexp("\\#(" + FRAGMENT$ + ")") + "?$",
5376 ABSOLUTE_REF$ = "^(" + SCHEME$ + ")\\:" + subexp(subexp("\\/\\/(" + subexp("(" + USERINFO$ + ")@") + "?(" + HOST$ + ")" + subexp("\\:(" + PORT$ + ")") + "?)") + "?(" + PATH_ABEMPTY$ + "|" + PATH_ABSOLUTE$ + "|" + PATH_ROOTLESS$ + "|" + PATH_EMPTY$ + ")") + subexp("\\?(" + QUERY$ + ")") + "?$",
5377 SAMEDOC_REF$ = "^" + subexp("\\#(" + FRAGMENT$ + ")") + "?$",
5378 AUTHORITY_REF$ = "^" + subexp("(" + USERINFO$ + ")@") + "?(" + HOST$ + ")" + subexp("\\:(" + PORT$ + ")") + "?$";
5379 return {
5380 NOT_SCHEME: new RegExp(merge("[^]", ALPHA$$, DIGIT$$, "[\\+\\-\\.]"), "g"),
5381 NOT_USERINFO: new RegExp(merge("[^\\%\\:]", UNRESERVED$$, SUB_DELIMS$$), "g"),
5382 NOT_HOST: new RegExp(merge("[^\\%\\[\\]\\:]", UNRESERVED$$, SUB_DELIMS$$), "g"),
5383 NOT_PATH: new RegExp(merge("[^\\%\\/\\:\\@]", UNRESERVED$$, SUB_DELIMS$$), "g"),
5384 NOT_PATH_NOSCHEME: new RegExp(merge("[^\\%\\/\\@]", UNRESERVED$$, SUB_DELIMS$$), "g"),
5385 NOT_QUERY: new RegExp(merge("[^\\%]", UNRESERVED$$, SUB_DELIMS$$, "[\\:\\@\\/\\?]", IPRIVATE$$), "g"),
5386 NOT_FRAGMENT: new RegExp(merge("[^\\%]", UNRESERVED$$, SUB_DELIMS$$, "[\\:\\@\\/\\?]"), "g"),
5387 ESCAPE: new RegExp(merge("[^]", UNRESERVED$$, SUB_DELIMS$$), "g"),
5388 UNRESERVED: new RegExp(UNRESERVED$$, "g"),
5389 OTHER_CHARS: new RegExp(merge("[^\\%]", UNRESERVED$$, RESERVED$$), "g"),
5390 PCT_ENCODED: new RegExp(PCT_ENCODED$, "g"),
5391 IPV4ADDRESS: new RegExp("^(" + IPV4ADDRESS$ + ")$"),
5392 IPV6ADDRESS: new RegExp("^\\[?(" + IPV6ADDRESS$ + ")" + subexp(subexp("\\%25|\\%(?!" + HEXDIG$$ + "{2})") + "(" + ZONEID$ + ")") + "?\\]?$") //RFC 6874, with relaxed parsing rules
5393 };
5394}
5395var URI_PROTOCOL = buildExps(false);
5396
5397var IRI_PROTOCOL = buildExps(true);
5398
5399var slicedToArray = function () {
5400 function sliceIterator(arr, i) {
5401 var _arr = [];
5402 var _n = true;
5403 var _d = false;
5404 var _e = undefined;
5405
5406 try {
5407 for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) {
5408 _arr.push(_s.value);
5409
5410 if (i && _arr.length === i) break;
5411 }
5412 } catch (err) {
5413 _d = true;
5414 _e = err;
5415 } finally {
5416 try {
5417 if (!_n && _i["return"]) _i["return"]();
5418 } finally {
5419 if (_d) throw _e;
5420 }
5421 }
5422
5423 return _arr;
5424 }
5425
5426 return function (arr, i) {
5427 if (Array.isArray(arr)) {
5428 return arr;
5429 } else if (Symbol.iterator in Object(arr)) {
5430 return sliceIterator(arr, i);
5431 } else {
5432 throw new TypeError("Invalid attempt to destructure non-iterable instance");
5433 }
5434 };
5435}();
5436
5437
5438
5439
5440
5441
5442
5443
5444
5445
5446
5447
5448
5449var toConsumableArray = function (arr) {
5450 if (Array.isArray(arr)) {
5451 for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) arr2[i] = arr[i];
5452
5453 return arr2;
5454 } else {
5455 return Array.from(arr);
5456 }
5457};
5458
5459/** Highest positive signed 32-bit float value */
5460
5461var maxInt = 2147483647; // aka. 0x7FFFFFFF or 2^31-1
5462
5463/** Bootstring parameters */
5464var base = 36;
5465var tMin = 1;
5466var tMax = 26;
5467var skew = 38;
5468var damp = 700;
5469var initialBias = 72;
5470var initialN = 128; // 0x80
5471var delimiter = '-'; // '\x2D'
5472
5473/** Regular expressions */
5474var regexPunycode = /^xn--/;
5475var regexNonASCII = /[^\0-\x7E]/; // non-ASCII chars
5476var regexSeparators = /[\x2E\u3002\uFF0E\uFF61]/g; // RFC 3490 separators
5477
5478/** Error messages */
5479var errors = {
5480 'overflow': 'Overflow: input needs wider integers to process',
5481 'not-basic': 'Illegal input >= 0x80 (not a basic code point)',
5482 'invalid-input': 'Invalid input'
5483};
5484
5485/** Convenience shortcuts */
5486var baseMinusTMin = base - tMin;
5487var floor = Math.floor;
5488var stringFromCharCode = String.fromCharCode;
5489
5490/*--------------------------------------------------------------------------*/
5491
5492/**
5493 * A generic error utility function.
5494 * @private
5495 * @param {String} type The error type.
5496 * @returns {Error} Throws a `RangeError` with the applicable error message.
5497 */
5498function error$1(type) {
5499 throw new RangeError(errors[type]);
5500}
5501
5502/**
5503 * A generic `Array#map` utility function.
5504 * @private
5505 * @param {Array} array The array to iterate over.
5506 * @param {Function} callback The function that gets called for every array
5507 * item.
5508 * @returns {Array} A new array of values returned by the callback function.
5509 */
5510function map(array, fn) {
5511 var result = [];
5512 var length = array.length;
5513 while (length--) {
5514 result[length] = fn(array[length]);
5515 }
5516 return result;
5517}
5518
5519/**
5520 * A simple `Array#map`-like wrapper to work with domain name strings or email
5521 * addresses.
5522 * @private
5523 * @param {String} domain The domain name or email address.
5524 * @param {Function} callback The function that gets called for every
5525 * character.
5526 * @returns {Array} A new string of characters returned by the callback
5527 * function.
5528 */
5529function mapDomain(string, fn) {
5530 var parts = string.split('@');
5531 var result = '';
5532 if (parts.length > 1) {
5533 // In email addresses, only the domain name should be punycoded. Leave
5534 // the local part (i.e. everything up to `@`) intact.
5535 result = parts[0] + '@';
5536 string = parts[1];
5537 }
5538 // Avoid `split(regex)` for IE8 compatibility. See #17.
5539 string = string.replace(regexSeparators, '\x2E');
5540 var labels = string.split('.');
5541 var encoded = map(labels, fn).join('.');
5542 return result + encoded;
5543}
5544
5545/**
5546 * Creates an array containing the numeric code points of each Unicode
5547 * character in the string. While JavaScript uses UCS-2 internally,
5548 * this function will convert a pair of surrogate halves (each of which
5549 * UCS-2 exposes as separate characters) into a single code point,
5550 * matching UTF-16.
5551 * @see `punycode.ucs2.encode`
5552 * @see <https://mathiasbynens.be/notes/javascript-encoding>
5553 * @memberOf punycode.ucs2
5554 * @name decode
5555 * @param {String} string The Unicode input string (UCS-2).
5556 * @returns {Array} The new array of code points.
5557 */
5558function ucs2decode(string) {
5559 var output = [];
5560 var counter = 0;
5561 var length = string.length;
5562 while (counter < length) {
5563 var value = string.charCodeAt(counter++);
5564 if (value >= 0xD800 && value <= 0xDBFF && counter < length) {
5565 // It's a high surrogate, and there is a next character.
5566 var extra = string.charCodeAt(counter++);
5567 if ((extra & 0xFC00) == 0xDC00) {
5568 // Low surrogate.
5569 output.push(((value & 0x3FF) << 10) + (extra & 0x3FF) + 0x10000);
5570 } else {
5571 // It's an unmatched surrogate; only append this code unit, in case the
5572 // next code unit is the high surrogate of a surrogate pair.
5573 output.push(value);
5574 counter--;
5575 }
5576 } else {
5577 output.push(value);
5578 }
5579 }
5580 return output;
5581}
5582
5583/**
5584 * Creates a string based on an array of numeric code points.
5585 * @see `punycode.ucs2.decode`
5586 * @memberOf punycode.ucs2
5587 * @name encode
5588 * @param {Array} codePoints The array of numeric code points.
5589 * @returns {String} The new Unicode string (UCS-2).
5590 */
5591var ucs2encode = function ucs2encode(array) {
5592 return String.fromCodePoint.apply(String, toConsumableArray(array));
5593};
5594
5595/**
5596 * Converts a basic code point into a digit/integer.
5597 * @see `digitToBasic()`
5598 * @private
5599 * @param {Number} codePoint The basic numeric code point value.
5600 * @returns {Number} The numeric value of a basic code point (for use in
5601 * representing integers) in the range `0` to `base - 1`, or `base` if
5602 * the code point does not represent a value.
5603 */
5604var basicToDigit = function basicToDigit(codePoint) {
5605 if (codePoint - 0x30 < 0x0A) {
5606 return codePoint - 0x16;
5607 }
5608 if (codePoint - 0x41 < 0x1A) {
5609 return codePoint - 0x41;
5610 }
5611 if (codePoint - 0x61 < 0x1A) {
5612 return codePoint - 0x61;
5613 }
5614 return base;
5615};
5616
5617/**
5618 * Converts a digit/integer into a basic code point.
5619 * @see `basicToDigit()`
5620 * @private
5621 * @param {Number} digit The numeric value of a basic code point.
5622 * @returns {Number} The basic code point whose value (when used for
5623 * representing integers) is `digit`, which needs to be in the range
5624 * `0` to `base - 1`. If `flag` is non-zero, the uppercase form is
5625 * used; else, the lowercase form is used. The behavior is undefined
5626 * if `flag` is non-zero and `digit` has no uppercase form.
5627 */
5628var digitToBasic = function digitToBasic(digit, flag) {
5629 // 0..25 map to ASCII a..z or A..Z
5630 // 26..35 map to ASCII 0..9
5631 return digit + 22 + 75 * (digit < 26) - ((flag != 0) << 5);
5632};
5633
5634/**
5635 * Bias adaptation function as per section 3.4 of RFC 3492.
5636 * https://tools.ietf.org/html/rfc3492#section-3.4
5637 * @private
5638 */
5639var adapt = function adapt(delta, numPoints, firstTime) {
5640 var k = 0;
5641 delta = firstTime ? floor(delta / damp) : delta >> 1;
5642 delta += floor(delta / numPoints);
5643 for (; /* no initialization */delta > baseMinusTMin * tMax >> 1; k += base) {
5644 delta = floor(delta / baseMinusTMin);
5645 }
5646 return floor(k + (baseMinusTMin + 1) * delta / (delta + skew));
5647};
5648
5649/**
5650 * Converts a Punycode string of ASCII-only symbols to a string of Unicode
5651 * symbols.
5652 * @memberOf punycode
5653 * @param {String} input The Punycode string of ASCII-only symbols.
5654 * @returns {String} The resulting string of Unicode symbols.
5655 */
5656var decode = function decode(input) {
5657 // Don't use UCS-2.
5658 var output = [];
5659 var inputLength = input.length;
5660 var i = 0;
5661 var n = initialN;
5662 var bias = initialBias;
5663
5664 // Handle the basic code points: let `basic` be the number of input code
5665 // points before the last delimiter, or `0` if there is none, then copy
5666 // the first basic code points to the output.
5667
5668 var basic = input.lastIndexOf(delimiter);
5669 if (basic < 0) {
5670 basic = 0;
5671 }
5672
5673 for (var j = 0; j < basic; ++j) {
5674 // if it's not a basic code point
5675 if (input.charCodeAt(j) >= 0x80) {
5676 error$1('not-basic');
5677 }
5678 output.push(input.charCodeAt(j));
5679 }
5680
5681 // Main decoding loop: start just after the last delimiter if any basic code
5682 // points were copied; start at the beginning otherwise.
5683
5684 for (var index = basic > 0 ? basic + 1 : 0; index < inputLength;) /* no final expression */{
5685
5686 // `index` is the index of the next character to be consumed.
5687 // Decode a generalized variable-length integer into `delta`,
5688 // which gets added to `i`. The overflow checking is easier
5689 // if we increase `i` as we go, then subtract off its starting
5690 // value at the end to obtain `delta`.
5691 var oldi = i;
5692 for (var w = 1, k = base;; /* no condition */k += base) {
5693
5694 if (index >= inputLength) {
5695 error$1('invalid-input');
5696 }
5697
5698 var digit = basicToDigit(input.charCodeAt(index++));
5699
5700 if (digit >= base || digit > floor((maxInt - i) / w)) {
5701 error$1('overflow');
5702 }
5703
5704 i += digit * w;
5705 var t = k <= bias ? tMin : k >= bias + tMax ? tMax : k - bias;
5706
5707 if (digit < t) {
5708 break;
5709 }
5710
5711 var baseMinusT = base - t;
5712 if (w > floor(maxInt / baseMinusT)) {
5713 error$1('overflow');
5714 }
5715
5716 w *= baseMinusT;
5717 }
5718
5719 var out = output.length + 1;
5720 bias = adapt(i - oldi, out, oldi == 0);
5721
5722 // `i` was supposed to wrap around from `out` to `0`,
5723 // incrementing `n` each time, so we'll fix that now:
5724 if (floor(i / out) > maxInt - n) {
5725 error$1('overflow');
5726 }
5727
5728 n += floor(i / out);
5729 i %= out;
5730
5731 // Insert `n` at position `i` of the output.
5732 output.splice(i++, 0, n);
5733 }
5734
5735 return String.fromCodePoint.apply(String, output);
5736};
5737
5738/**
5739 * Converts a string of Unicode symbols (e.g. a domain name label) to a
5740 * Punycode string of ASCII-only symbols.
5741 * @memberOf punycode
5742 * @param {String} input The string of Unicode symbols.
5743 * @returns {String} The resulting Punycode string of ASCII-only symbols.
5744 */
5745var encode = function encode(input) {
5746 var output = [];
5747
5748 // Convert the input in UCS-2 to an array of Unicode code points.
5749 input = ucs2decode(input);
5750
5751 // Cache the length.
5752 var inputLength = input.length;
5753
5754 // Initialize the state.
5755 var n = initialN;
5756 var delta = 0;
5757 var bias = initialBias;
5758
5759 // Handle the basic code points.
5760 var _iteratorNormalCompletion = true;
5761 var _didIteratorError = false;
5762 var _iteratorError = undefined;
5763
5764 try {
5765 for (var _iterator = input[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
5766 var _currentValue2 = _step.value;
5767
5768 if (_currentValue2 < 0x80) {
5769 output.push(stringFromCharCode(_currentValue2));
5770 }
5771 }
5772 } catch (err) {
5773 _didIteratorError = true;
5774 _iteratorError = err;
5775 } finally {
5776 try {
5777 if (!_iteratorNormalCompletion && _iterator.return) {
5778 _iterator.return();
5779 }
5780 } finally {
5781 if (_didIteratorError) {
5782 throw _iteratorError;
5783 }
5784 }
5785 }
5786
5787 var basicLength = output.length;
5788 var handledCPCount = basicLength;
5789
5790 // `handledCPCount` is the number of code points that have been handled;
5791 // `basicLength` is the number of basic code points.
5792
5793 // Finish the basic string with a delimiter unless it's empty.
5794 if (basicLength) {
5795 output.push(delimiter);
5796 }
5797
5798 // Main encoding loop:
5799 while (handledCPCount < inputLength) {
5800
5801 // All non-basic code points < n have been handled already. Find the next
5802 // larger one:
5803 var m = maxInt;
5804 var _iteratorNormalCompletion2 = true;
5805 var _didIteratorError2 = false;
5806 var _iteratorError2 = undefined;
5807
5808 try {
5809 for (var _iterator2 = input[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) {
5810 var currentValue = _step2.value;
5811
5812 if (currentValue >= n && currentValue < m) {
5813 m = currentValue;
5814 }
5815 }
5816
5817 // Increase `delta` enough to advance the decoder's <n,i> state to <m,0>,
5818 // but guard against overflow.
5819 } catch (err) {
5820 _didIteratorError2 = true;
5821 _iteratorError2 = err;
5822 } finally {
5823 try {
5824 if (!_iteratorNormalCompletion2 && _iterator2.return) {
5825 _iterator2.return();
5826 }
5827 } finally {
5828 if (_didIteratorError2) {
5829 throw _iteratorError2;
5830 }
5831 }
5832 }
5833
5834 var handledCPCountPlusOne = handledCPCount + 1;
5835 if (m - n > floor((maxInt - delta) / handledCPCountPlusOne)) {
5836 error$1('overflow');
5837 }
5838
5839 delta += (m - n) * handledCPCountPlusOne;
5840 n = m;
5841
5842 var _iteratorNormalCompletion3 = true;
5843 var _didIteratorError3 = false;
5844 var _iteratorError3 = undefined;
5845
5846 try {
5847 for (var _iterator3 = input[Symbol.iterator](), _step3; !(_iteratorNormalCompletion3 = (_step3 = _iterator3.next()).done); _iteratorNormalCompletion3 = true) {
5848 var _currentValue = _step3.value;
5849
5850 if (_currentValue < n && ++delta > maxInt) {
5851 error$1('overflow');
5852 }
5853 if (_currentValue == n) {
5854 // Represent delta as a generalized variable-length integer.
5855 var q = delta;
5856 for (var k = base;; /* no condition */k += base) {
5857 var t = k <= bias ? tMin : k >= bias + tMax ? tMax : k - bias;
5858 if (q < t) {
5859 break;
5860 }
5861 var qMinusT = q - t;
5862 var baseMinusT = base - t;
5863 output.push(stringFromCharCode(digitToBasic(t + qMinusT % baseMinusT, 0)));
5864 q = floor(qMinusT / baseMinusT);
5865 }
5866
5867 output.push(stringFromCharCode(digitToBasic(q, 0)));
5868 bias = adapt(delta, handledCPCountPlusOne, handledCPCount == basicLength);
5869 delta = 0;
5870 ++handledCPCount;
5871 }
5872 }
5873 } catch (err) {
5874 _didIteratorError3 = true;
5875 _iteratorError3 = err;
5876 } finally {
5877 try {
5878 if (!_iteratorNormalCompletion3 && _iterator3.return) {
5879 _iterator3.return();
5880 }
5881 } finally {
5882 if (_didIteratorError3) {
5883 throw _iteratorError3;
5884 }
5885 }
5886 }
5887
5888 ++delta;
5889 ++n;
5890 }
5891 return output.join('');
5892};
5893
5894/**
5895 * Converts a Punycode string representing a domain name or an email address
5896 * to Unicode. Only the Punycoded parts of the input will be converted, i.e.
5897 * it doesn't matter if you call it on a string that has already been
5898 * converted to Unicode.
5899 * @memberOf punycode
5900 * @param {String} input The Punycoded domain name or email address to
5901 * convert to Unicode.
5902 * @returns {String} The Unicode representation of the given Punycode
5903 * string.
5904 */
5905var toUnicode = function toUnicode(input) {
5906 return mapDomain(input, function (string) {
5907 return regexPunycode.test(string) ? decode(string.slice(4).toLowerCase()) : string;
5908 });
5909};
5910
5911/**
5912 * Converts a Unicode string representing a domain name or an email address to
5913 * Punycode. Only the non-ASCII parts of the domain name will be converted,
5914 * i.e. it doesn't matter if you call it with a domain that's already in
5915 * ASCII.
5916 * @memberOf punycode
5917 * @param {String} input The domain name or email address to convert, as a
5918 * Unicode string.
5919 * @returns {String} The Punycode representation of the given domain name or
5920 * email address.
5921 */
5922var toASCII = function toASCII(input) {
5923 return mapDomain(input, function (string) {
5924 return regexNonASCII.test(string) ? 'xn--' + encode(string) : string;
5925 });
5926};
5927
5928/*--------------------------------------------------------------------------*/
5929
5930/** Define the public API */
5931var punycode = {
5932 /**
5933 * A string representing the current Punycode.js version number.
5934 * @memberOf punycode
5935 * @type String
5936 */
5937 'version': '2.1.0',
5938 /**
5939 * An object of methods to convert from JavaScript's internal character
5940 * representation (UCS-2) to Unicode code points, and back.
5941 * @see <https://mathiasbynens.be/notes/javascript-encoding>
5942 * @memberOf punycode
5943 * @type Object
5944 */
5945 'ucs2': {
5946 'decode': ucs2decode,
5947 'encode': ucs2encode
5948 },
5949 'decode': decode,
5950 'encode': encode,
5951 'toASCII': toASCII,
5952 'toUnicode': toUnicode
5953};
5954
5955/**
5956 * URI.js
5957 *
5958 * @fileoverview An RFC 3986 compliant, scheme extendable URI parsing/validating/resolving library for JavaScript.
5959 * @author <a href="mailto:gary.court@gmail.com">Gary Court</a>
5960 * @see http://github.com/garycourt/uri-js
5961 */
5962/**
5963 * Copyright 2011 Gary Court. All rights reserved.
5964 *
5965 * Redistribution and use in source and binary forms, with or without modification, are
5966 * permitted provided that the following conditions are met:
5967 *
5968 * 1. Redistributions of source code must retain the above copyright notice, this list of
5969 * conditions and the following disclaimer.
5970 *
5971 * 2. Redistributions in binary form must reproduce the above copyright notice, this list
5972 * of conditions and the following disclaimer in the documentation and/or other materials
5973 * provided with the distribution.
5974 *
5975 * THIS SOFTWARE IS PROVIDED BY GARY COURT ``AS IS'' AND ANY EXPRESS OR IMPLIED
5976 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
5977 * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GARY COURT OR
5978 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
5979 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
5980 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
5981 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
5982 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
5983 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
5984 *
5985 * The views and conclusions contained in the software and documentation are those of the
5986 * authors and should not be interpreted as representing official policies, either expressed
5987 * or implied, of Gary Court.
5988 */
5989var SCHEMES = {};
5990function pctEncChar(chr) {
5991 var c = chr.charCodeAt(0);
5992 var e = void 0;
5993 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();
5994 return e;
5995}
5996function pctDecChars(str) {
5997 var newStr = "";
5998 var i = 0;
5999 var il = str.length;
6000 while (i < il) {
6001 var c = parseInt(str.substr(i + 1, 2), 16);
6002 if (c < 128) {
6003 newStr += String.fromCharCode(c);
6004 i += 3;
6005 } else if (c >= 194 && c < 224) {
6006 if (il - i >= 6) {
6007 var c2 = parseInt(str.substr(i + 4, 2), 16);
6008 newStr += String.fromCharCode((c & 31) << 6 | c2 & 63);
6009 } else {
6010 newStr += str.substr(i, 6);
6011 }
6012 i += 6;
6013 } else if (c >= 224) {
6014 if (il - i >= 9) {
6015 var _c = parseInt(str.substr(i + 4, 2), 16);
6016 var c3 = parseInt(str.substr(i + 7, 2), 16);
6017 newStr += String.fromCharCode((c & 15) << 12 | (_c & 63) << 6 | c3 & 63);
6018 } else {
6019 newStr += str.substr(i, 9);
6020 }
6021 i += 9;
6022 } else {
6023 newStr += str.substr(i, 3);
6024 i += 3;
6025 }
6026 }
6027 return newStr;
6028}
6029function _normalizeComponentEncoding(components, protocol) {
6030 function decodeUnreserved(str) {
6031 var decStr = pctDecChars(str);
6032 return !decStr.match(protocol.UNRESERVED) ? str : decStr;
6033 }
6034 if (components.scheme) components.scheme = String(components.scheme).replace(protocol.PCT_ENCODED, decodeUnreserved).toLowerCase().replace(protocol.NOT_SCHEME, "");
6035 if (components.userinfo !== undefined) components.userinfo = String(components.userinfo).replace(protocol.PCT_ENCODED, decodeUnreserved).replace(protocol.NOT_USERINFO, pctEncChar).replace(protocol.PCT_ENCODED, toUpperCase);
6036 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);
6037 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);
6038 if (components.query !== undefined) components.query = String(components.query).replace(protocol.PCT_ENCODED, decodeUnreserved).replace(protocol.NOT_QUERY, pctEncChar).replace(protocol.PCT_ENCODED, toUpperCase);
6039 if (components.fragment !== undefined) components.fragment = String(components.fragment).replace(protocol.PCT_ENCODED, decodeUnreserved).replace(protocol.NOT_FRAGMENT, pctEncChar).replace(protocol.PCT_ENCODED, toUpperCase);
6040 return components;
6041}
6042
6043function _stripLeadingZeros(str) {
6044 return str.replace(/^0*(.*)/, "$1") || "0";
6045}
6046function _normalizeIPv4(host, protocol) {
6047 var matches = host.match(protocol.IPV4ADDRESS) || [];
6048
6049 var _matches = slicedToArray(matches, 2),
6050 address = _matches[1];
6051
6052 if (address) {
6053 return address.split(".").map(_stripLeadingZeros).join(".");
6054 } else {
6055 return host;
6056 }
6057}
6058function _normalizeIPv6(host, protocol) {
6059 var matches = host.match(protocol.IPV6ADDRESS) || [];
6060
6061 var _matches2 = slicedToArray(matches, 3),
6062 address = _matches2[1],
6063 zone = _matches2[2];
6064
6065 if (address) {
6066 var _address$toLowerCase$ = address.toLowerCase().split('::').reverse(),
6067 _address$toLowerCase$2 = slicedToArray(_address$toLowerCase$, 2),
6068 last = _address$toLowerCase$2[0],
6069 first = _address$toLowerCase$2[1];
6070
6071 var firstFields = first ? first.split(":").map(_stripLeadingZeros) : [];
6072 var lastFields = last.split(":").map(_stripLeadingZeros);
6073 var isLastFieldIPv4Address = protocol.IPV4ADDRESS.test(lastFields[lastFields.length - 1]);
6074 var fieldCount = isLastFieldIPv4Address ? 7 : 8;
6075 var lastFieldsStart = lastFields.length - fieldCount;
6076 var fields = Array(fieldCount);
6077 for (var x = 0; x < fieldCount; ++x) {
6078 fields[x] = firstFields[x] || lastFields[lastFieldsStart + x] || '';
6079 }
6080 if (isLastFieldIPv4Address) {
6081 fields[fieldCount - 1] = _normalizeIPv4(fields[fieldCount - 1], protocol);
6082 }
6083 var allZeroFields = fields.reduce(function (acc, field, index) {
6084 if (!field || field === "0") {
6085 var lastLongest = acc[acc.length - 1];
6086 if (lastLongest && lastLongest.index + lastLongest.length === index) {
6087 lastLongest.length++;
6088 } else {
6089 acc.push({ index: index, length: 1 });
6090 }
6091 }
6092 return acc;
6093 }, []);
6094 var longestZeroFields = allZeroFields.sort(function (a, b) {
6095 return b.length - a.length;
6096 })[0];
6097 var newHost = void 0;
6098 if (longestZeroFields && longestZeroFields.length > 1) {
6099 var newFirst = fields.slice(0, longestZeroFields.index);
6100 var newLast = fields.slice(longestZeroFields.index + longestZeroFields.length);
6101 newHost = newFirst.join(":") + "::" + newLast.join(":");
6102 } else {
6103 newHost = fields.join(":");
6104 }
6105 if (zone) {
6106 newHost += "%" + zone;
6107 }
6108 return newHost;
6109 } else {
6110 return host;
6111 }
6112}
6113var URI_PARSE = /^(?:([^:\/?#]+):)?(?:\/\/((?:([^\/?#@]*)@)?(\[[^\/?#\]]+\]|[^\/?#:]*)(?:\:(\d*))?))?([^?#]*)(?:\?([^#]*))?(?:#((?:.|\n|\r)*))?/i;
6114var NO_MATCH_IS_UNDEFINED = "".match(/(){0}/)[1] === undefined;
6115function parse(uriString) {
6116 var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
6117
6118 var components = {};
6119 var protocol = options.iri !== false ? IRI_PROTOCOL : URI_PROTOCOL;
6120 if (options.reference === "suffix") uriString = (options.scheme ? options.scheme + ":" : "") + "//" + uriString;
6121 var matches = uriString.match(URI_PARSE);
6122 if (matches) {
6123 if (NO_MATCH_IS_UNDEFINED) {
6124 //store each component
6125 components.scheme = matches[1];
6126 components.userinfo = matches[3];
6127 components.host = matches[4];
6128 components.port = parseInt(matches[5], 10);
6129 components.path = matches[6] || "";
6130 components.query = matches[7];
6131 components.fragment = matches[8];
6132 //fix port number
6133 if (isNaN(components.port)) {
6134 components.port = matches[5];
6135 }
6136 } else {
6137 //IE FIX for improper RegExp matching
6138 //store each component
6139 components.scheme = matches[1] || undefined;
6140 components.userinfo = uriString.indexOf("@") !== -1 ? matches[3] : undefined;
6141 components.host = uriString.indexOf("//") !== -1 ? matches[4] : undefined;
6142 components.port = parseInt(matches[5], 10);
6143 components.path = matches[6] || "";
6144 components.query = uriString.indexOf("?") !== -1 ? matches[7] : undefined;
6145 components.fragment = uriString.indexOf("#") !== -1 ? matches[8] : undefined;
6146 //fix port number
6147 if (isNaN(components.port)) {
6148 components.port = uriString.match(/\/\/(?:.|\n)*\:(?:\/|\?|\#|$)/) ? matches[4] : undefined;
6149 }
6150 }
6151 if (components.host) {
6152 //normalize IP hosts
6153 components.host = _normalizeIPv6(_normalizeIPv4(components.host, protocol), protocol);
6154 }
6155 //determine reference type
6156 if (components.scheme === undefined && components.userinfo === undefined && components.host === undefined && components.port === undefined && !components.path && components.query === undefined) {
6157 components.reference = "same-document";
6158 } else if (components.scheme === undefined) {
6159 components.reference = "relative";
6160 } else if (components.fragment === undefined) {
6161 components.reference = "absolute";
6162 } else {
6163 components.reference = "uri";
6164 }
6165 //check for reference errors
6166 if (options.reference && options.reference !== "suffix" && options.reference !== components.reference) {
6167 components.error = components.error || "URI is not a " + options.reference + " reference.";
6168 }
6169 //find scheme handler
6170 var schemeHandler = SCHEMES[(options.scheme || components.scheme || "").toLowerCase()];
6171 //check if scheme can't handle IRIs
6172 if (!options.unicodeSupport && (!schemeHandler || !schemeHandler.unicodeSupport)) {
6173 //if host component is a domain name
6174 if (components.host && (options.domainHost || schemeHandler && schemeHandler.domainHost)) {
6175 //convert Unicode IDN -> ASCII IDN
6176 try {
6177 components.host = punycode.toASCII(components.host.replace(protocol.PCT_ENCODED, pctDecChars).toLowerCase());
6178 } catch (e) {
6179 components.error = components.error || "Host's domain name can not be converted to ASCII via punycode: " + e;
6180 }
6181 }
6182 //convert IRI -> URI
6183 _normalizeComponentEncoding(components, URI_PROTOCOL);
6184 } else {
6185 //normalize encodings
6186 _normalizeComponentEncoding(components, protocol);
6187 }
6188 //perform scheme specific parsing
6189 if (schemeHandler && schemeHandler.parse) {
6190 schemeHandler.parse(components, options);
6191 }
6192 } else {
6193 components.error = components.error || "URI can not be parsed.";
6194 }
6195 return components;
6196}
6197
6198function _recomposeAuthority(components, options) {
6199 var protocol = options.iri !== false ? IRI_PROTOCOL : URI_PROTOCOL;
6200 var uriTokens = [];
6201 if (components.userinfo !== undefined) {
6202 uriTokens.push(components.userinfo);
6203 uriTokens.push("@");
6204 }
6205 if (components.host !== undefined) {
6206 //normalize IP hosts, add brackets and escape zone separator for IPv6
6207 uriTokens.push(_normalizeIPv6(_normalizeIPv4(String(components.host), protocol), protocol).replace(protocol.IPV6ADDRESS, function (_, $1, $2) {
6208 return "[" + $1 + ($2 ? "%25" + $2 : "") + "]";
6209 }));
6210 }
6211 if (typeof components.port === "number" || typeof components.port === "string") {
6212 uriTokens.push(":");
6213 uriTokens.push(String(components.port));
6214 }
6215 return uriTokens.length ? uriTokens.join("") : undefined;
6216}
6217
6218var RDS1 = /^\.\.?\//;
6219var RDS2 = /^\/\.(\/|$)/;
6220var RDS3 = /^\/\.\.(\/|$)/;
6221var RDS5 = /^\/?(?:.|\n)*?(?=\/|$)/;
6222function removeDotSegments(input) {
6223 var output = [];
6224 while (input.length) {
6225 if (input.match(RDS1)) {
6226 input = input.replace(RDS1, "");
6227 } else if (input.match(RDS2)) {
6228 input = input.replace(RDS2, "/");
6229 } else if (input.match(RDS3)) {
6230 input = input.replace(RDS3, "/");
6231 output.pop();
6232 } else if (input === "." || input === "..") {
6233 input = "";
6234 } else {
6235 var im = input.match(RDS5);
6236 if (im) {
6237 var s = im[0];
6238 input = input.slice(s.length);
6239 output.push(s);
6240 } else {
6241 throw new Error("Unexpected dot segment condition");
6242 }
6243 }
6244 }
6245 return output.join("");
6246}
6247
6248function serialize(components) {
6249 var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
6250
6251 var protocol = options.iri ? IRI_PROTOCOL : URI_PROTOCOL;
6252 var uriTokens = [];
6253 //find scheme handler
6254 var schemeHandler = SCHEMES[(options.scheme || components.scheme || "").toLowerCase()];
6255 //perform scheme specific serialization
6256 if (schemeHandler && schemeHandler.serialize) schemeHandler.serialize(components, options);
6257 if (components.host) {
6258 //if host component is an IPv6 address
6259 if (protocol.IPV6ADDRESS.test(components.host)) {}
6260 //TODO: normalize IPv6 address as per RFC 5952
6261
6262 //if host component is a domain name
6263 else if (options.domainHost || schemeHandler && schemeHandler.domainHost) {
6264 //convert IDN via punycode
6265 try {
6266 components.host = !options.iri ? punycode.toASCII(components.host.replace(protocol.PCT_ENCODED, pctDecChars).toLowerCase()) : punycode.toUnicode(components.host);
6267 } catch (e) {
6268 components.error = components.error || "Host's domain name can not be converted to " + (!options.iri ? "ASCII" : "Unicode") + " via punycode: " + e;
6269 }
6270 }
6271 }
6272 //normalize encoding
6273 _normalizeComponentEncoding(components, protocol);
6274 if (options.reference !== "suffix" && components.scheme) {
6275 uriTokens.push(components.scheme);
6276 uriTokens.push(":");
6277 }
6278 var authority = _recomposeAuthority(components, options);
6279 if (authority !== undefined) {
6280 if (options.reference !== "suffix") {
6281 uriTokens.push("//");
6282 }
6283 uriTokens.push(authority);
6284 if (components.path && components.path.charAt(0) !== "/") {
6285 uriTokens.push("/");
6286 }
6287 }
6288 if (components.path !== undefined) {
6289 var s = components.path;
6290 if (!options.absolutePath && (!schemeHandler || !schemeHandler.absolutePath)) {
6291 s = removeDotSegments(s);
6292 }
6293 if (authority === undefined) {
6294 s = s.replace(/^\/\//, "/%2F"); //don't allow the path to start with "//"
6295 }
6296 uriTokens.push(s);
6297 }
6298 if (components.query !== undefined) {
6299 uriTokens.push("?");
6300 uriTokens.push(components.query);
6301 }
6302 if (components.fragment !== undefined) {
6303 uriTokens.push("#");
6304 uriTokens.push(components.fragment);
6305 }
6306 return uriTokens.join(""); //merge tokens into a string
6307}
6308
6309function resolveComponents(base, relative) {
6310 var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
6311 var skipNormalization = arguments[3];
6312
6313 var target = {};
6314 if (!skipNormalization) {
6315 base = parse(serialize(base, options), options); //normalize base components
6316 relative = parse(serialize(relative, options), options); //normalize relative components
6317 }
6318 options = options || {};
6319 if (!options.tolerant && relative.scheme) {
6320 target.scheme = relative.scheme;
6321 //target.authority = relative.authority;
6322 target.userinfo = relative.userinfo;
6323 target.host = relative.host;
6324 target.port = relative.port;
6325 target.path = removeDotSegments(relative.path || "");
6326 target.query = relative.query;
6327 } else {
6328 if (relative.userinfo !== undefined || relative.host !== undefined || relative.port !== undefined) {
6329 //target.authority = relative.authority;
6330 target.userinfo = relative.userinfo;
6331 target.host = relative.host;
6332 target.port = relative.port;
6333 target.path = removeDotSegments(relative.path || "");
6334 target.query = relative.query;
6335 } else {
6336 if (!relative.path) {
6337 target.path = base.path;
6338 if (relative.query !== undefined) {
6339 target.query = relative.query;
6340 } else {
6341 target.query = base.query;
6342 }
6343 } else {
6344 if (relative.path.charAt(0) === "/") {
6345 target.path = removeDotSegments(relative.path);
6346 } else {
6347 if ((base.userinfo !== undefined || base.host !== undefined || base.port !== undefined) && !base.path) {
6348 target.path = "/" + relative.path;
6349 } else if (!base.path) {
6350 target.path = relative.path;
6351 } else {
6352 target.path = base.path.slice(0, base.path.lastIndexOf("/") + 1) + relative.path;
6353 }
6354 target.path = removeDotSegments(target.path);
6355 }
6356 target.query = relative.query;
6357 }
6358 //target.authority = base.authority;
6359 target.userinfo = base.userinfo;
6360 target.host = base.host;
6361 target.port = base.port;
6362 }
6363 target.scheme = base.scheme;
6364 }
6365 target.fragment = relative.fragment;
6366 return target;
6367}
6368
6369function resolve(baseURI, relativeURI, options) {
6370 var schemelessOptions = assign({ scheme: 'null' }, options);
6371 return serialize(resolveComponents(parse(baseURI, schemelessOptions), parse(relativeURI, schemelessOptions), schemelessOptions, true), schemelessOptions);
6372}
6373
6374function normalize(uri, options) {
6375 if (typeof uri === "string") {
6376 uri = serialize(parse(uri, options), options);
6377 } else if (typeOf(uri) === "object") {
6378 uri = parse(serialize(uri, options), options);
6379 }
6380 return uri;
6381}
6382
6383function equal(uriA, uriB, options) {
6384 if (typeof uriA === "string") {
6385 uriA = serialize(parse(uriA, options), options);
6386 } else if (typeOf(uriA) === "object") {
6387 uriA = serialize(uriA, options);
6388 }
6389 if (typeof uriB === "string") {
6390 uriB = serialize(parse(uriB, options), options);
6391 } else if (typeOf(uriB) === "object") {
6392 uriB = serialize(uriB, options);
6393 }
6394 return uriA === uriB;
6395}
6396
6397function escapeComponent(str, options) {
6398 return str && str.toString().replace(!options || !options.iri ? URI_PROTOCOL.ESCAPE : IRI_PROTOCOL.ESCAPE, pctEncChar);
6399}
6400
6401function unescapeComponent(str, options) {
6402 return str && str.toString().replace(!options || !options.iri ? URI_PROTOCOL.PCT_ENCODED : IRI_PROTOCOL.PCT_ENCODED, pctDecChars);
6403}
6404
6405var handler = {
6406 scheme: "http",
6407 domainHost: true,
6408 parse: function parse(components, options) {
6409 //report missing host
6410 if (!components.host) {
6411 components.error = components.error || "HTTP URIs must have a host.";
6412 }
6413 return components;
6414 },
6415 serialize: function serialize(components, options) {
6416 var secure = String(components.scheme).toLowerCase() === "https";
6417 //normalize the default port
6418 if (components.port === (secure ? 443 : 80) || components.port === "") {
6419 components.port = undefined;
6420 }
6421 //normalize the empty path
6422 if (!components.path) {
6423 components.path = "/";
6424 }
6425 //NOTE: We do not parse query strings for HTTP URIs
6426 //as WWW Form Url Encoded query strings are part of the HTML4+ spec,
6427 //and not the HTTP spec.
6428 return components;
6429 }
6430};
6431
6432var handler$1 = {
6433 scheme: "https",
6434 domainHost: handler.domainHost,
6435 parse: handler.parse,
6436 serialize: handler.serialize
6437};
6438
6439function isSecure(wsComponents) {
6440 return typeof wsComponents.secure === 'boolean' ? wsComponents.secure : String(wsComponents.scheme).toLowerCase() === "wss";
6441}
6442//RFC 6455
6443var handler$2 = {
6444 scheme: "ws",
6445 domainHost: true,
6446 parse: function parse(components, options) {
6447 var wsComponents = components;
6448 //indicate if the secure flag is set
6449 wsComponents.secure = isSecure(wsComponents);
6450 //construct resouce name
6451 wsComponents.resourceName = (wsComponents.path || '/') + (wsComponents.query ? '?' + wsComponents.query : '');
6452 wsComponents.path = undefined;
6453 wsComponents.query = undefined;
6454 return wsComponents;
6455 },
6456 serialize: function serialize(wsComponents, options) {
6457 //normalize the default port
6458 if (wsComponents.port === (isSecure(wsComponents) ? 443 : 80) || wsComponents.port === "") {
6459 wsComponents.port = undefined;
6460 }
6461 //ensure scheme matches secure flag
6462 if (typeof wsComponents.secure === 'boolean') {
6463 wsComponents.scheme = wsComponents.secure ? 'wss' : 'ws';
6464 wsComponents.secure = undefined;
6465 }
6466 //reconstruct path from resource name
6467 if (wsComponents.resourceName) {
6468 var _wsComponents$resourc = wsComponents.resourceName.split('?'),
6469 _wsComponents$resourc2 = slicedToArray(_wsComponents$resourc, 2),
6470 path = _wsComponents$resourc2[0],
6471 query = _wsComponents$resourc2[1];
6472
6473 wsComponents.path = path && path !== '/' ? path : undefined;
6474 wsComponents.query = query;
6475 wsComponents.resourceName = undefined;
6476 }
6477 //forbid fragment component
6478 wsComponents.fragment = undefined;
6479 return wsComponents;
6480 }
6481};
6482
6483var handler$3 = {
6484 scheme: "wss",
6485 domainHost: handler$2.domainHost,
6486 parse: handler$2.parse,
6487 serialize: handler$2.serialize
6488};
6489
6490var O = {};
6491var isIRI = true;
6492//RFC 3986
6493var UNRESERVED$$ = "[A-Za-z0-9\\-\\.\\_\\~" + (isIRI ? "\\xA0-\\u200D\\u2010-\\u2029\\u202F-\\uD7FF\\uF900-\\uFDCF\\uFDF0-\\uFFEF" : "") + "]";
6494var HEXDIG$$ = "[0-9A-Fa-f]"; //case-insensitive
6495var PCT_ENCODED$ = subexp(subexp("%[EFef]" + HEXDIG$$ + "%" + HEXDIG$$ + HEXDIG$$ + "%" + HEXDIG$$ + HEXDIG$$) + "|" + subexp("%[89A-Fa-f]" + HEXDIG$$ + "%" + HEXDIG$$ + HEXDIG$$) + "|" + subexp("%" + HEXDIG$$ + HEXDIG$$)); //expanded
6496//RFC 5322, except these symbols as per RFC 6068: @ : / ? # [ ] & ; =
6497//const ATEXT$$ = "[A-Za-z0-9\\!\\#\\$\\%\\&\\'\\*\\+\\-\\/\\=\\?\\^\\_\\`\\{\\|\\}\\~]";
6498//const WSP$$ = "[\\x20\\x09]";
6499//const OBS_QTEXT$$ = "[\\x01-\\x08\\x0B\\x0C\\x0E-\\x1F\\x7F]"; //(%d1-8 / %d11-12 / %d14-31 / %d127)
6500//const QTEXT$$ = merge("[\\x21\\x23-\\x5B\\x5D-\\x7E]", OBS_QTEXT$$); //%d33 / %d35-91 / %d93-126 / obs-qtext
6501//const VCHAR$$ = "[\\x21-\\x7E]";
6502//const WSP$$ = "[\\x20\\x09]";
6503//const OBS_QP$ = subexp("\\\\" + merge("[\\x00\\x0D\\x0A]", OBS_QTEXT$$)); //%d0 / CR / LF / obs-qtext
6504//const FWS$ = subexp(subexp(WSP$$ + "*" + "\\x0D\\x0A") + "?" + WSP$$ + "+");
6505//const QUOTED_PAIR$ = subexp(subexp("\\\\" + subexp(VCHAR$$ + "|" + WSP$$)) + "|" + OBS_QP$);
6506//const QUOTED_STRING$ = subexp('\\"' + subexp(FWS$ + "?" + QCONTENT$) + "*" + FWS$ + "?" + '\\"');
6507var ATEXT$$ = "[A-Za-z0-9\\!\\$\\%\\'\\*\\+\\-\\^\\_\\`\\{\\|\\}\\~]";
6508var QTEXT$$ = "[\\!\\$\\%\\'\\(\\)\\*\\+\\,\\-\\.0-9\\<\\>A-Z\\x5E-\\x7E]";
6509var VCHAR$$ = merge(QTEXT$$, "[\\\"\\\\]");
6510var SOME_DELIMS$$ = "[\\!\\$\\'\\(\\)\\*\\+\\,\\;\\:\\@]";
6511var UNRESERVED = new RegExp(UNRESERVED$$, "g");
6512var PCT_ENCODED = new RegExp(PCT_ENCODED$, "g");
6513var NOT_LOCAL_PART = new RegExp(merge("[^]", ATEXT$$, "[\\.]", '[\\"]', VCHAR$$), "g");
6514var NOT_HFNAME = new RegExp(merge("[^]", UNRESERVED$$, SOME_DELIMS$$), "g");
6515var NOT_HFVALUE = NOT_HFNAME;
6516function decodeUnreserved(str) {
6517 var decStr = pctDecChars(str);
6518 return !decStr.match(UNRESERVED) ? str : decStr;
6519}
6520var handler$4 = {
6521 scheme: "mailto",
6522 parse: function parse$$1(components, options) {
6523 var mailtoComponents = components;
6524 var to = mailtoComponents.to = mailtoComponents.path ? mailtoComponents.path.split(",") : [];
6525 mailtoComponents.path = undefined;
6526 if (mailtoComponents.query) {
6527 var unknownHeaders = false;
6528 var headers = {};
6529 var hfields = mailtoComponents.query.split("&");
6530 for (var x = 0, xl = hfields.length; x < xl; ++x) {
6531 var hfield = hfields[x].split("=");
6532 switch (hfield[0]) {
6533 case "to":
6534 var toAddrs = hfield[1].split(",");
6535 for (var _x = 0, _xl = toAddrs.length; _x < _xl; ++_x) {
6536 to.push(toAddrs[_x]);
6537 }
6538 break;
6539 case "subject":
6540 mailtoComponents.subject = unescapeComponent(hfield[1], options);
6541 break;
6542 case "body":
6543 mailtoComponents.body = unescapeComponent(hfield[1], options);
6544 break;
6545 default:
6546 unknownHeaders = true;
6547 headers[unescapeComponent(hfield[0], options)] = unescapeComponent(hfield[1], options);
6548 break;
6549 }
6550 }
6551 if (unknownHeaders) mailtoComponents.headers = headers;
6552 }
6553 mailtoComponents.query = undefined;
6554 for (var _x2 = 0, _xl2 = to.length; _x2 < _xl2; ++_x2) {
6555 var addr = to[_x2].split("@");
6556 addr[0] = unescapeComponent(addr[0]);
6557 if (!options.unicodeSupport) {
6558 //convert Unicode IDN -> ASCII IDN
6559 try {
6560 addr[1] = punycode.toASCII(unescapeComponent(addr[1], options).toLowerCase());
6561 } catch (e) {
6562 mailtoComponents.error = mailtoComponents.error || "Email address's domain name can not be converted to ASCII via punycode: " + e;
6563 }
6564 } else {
6565 addr[1] = unescapeComponent(addr[1], options).toLowerCase();
6566 }
6567 to[_x2] = addr.join("@");
6568 }
6569 return mailtoComponents;
6570 },
6571 serialize: function serialize$$1(mailtoComponents, options) {
6572 var components = mailtoComponents;
6573 var to = toArray(mailtoComponents.to);
6574 if (to) {
6575 for (var x = 0, xl = to.length; x < xl; ++x) {
6576 var toAddr = String(to[x]);
6577 var atIdx = toAddr.lastIndexOf("@");
6578 var localPart = toAddr.slice(0, atIdx).replace(PCT_ENCODED, decodeUnreserved).replace(PCT_ENCODED, toUpperCase).replace(NOT_LOCAL_PART, pctEncChar);
6579 var domain = toAddr.slice(atIdx + 1);
6580 //convert IDN via punycode
6581 try {
6582 domain = !options.iri ? punycode.toASCII(unescapeComponent(domain, options).toLowerCase()) : punycode.toUnicode(domain);
6583 } catch (e) {
6584 components.error = components.error || "Email address's domain name can not be converted to " + (!options.iri ? "ASCII" : "Unicode") + " via punycode: " + e;
6585 }
6586 to[x] = localPart + "@" + domain;
6587 }
6588 components.path = to.join(",");
6589 }
6590 var headers = mailtoComponents.headers = mailtoComponents.headers || {};
6591 if (mailtoComponents.subject) headers["subject"] = mailtoComponents.subject;
6592 if (mailtoComponents.body) headers["body"] = mailtoComponents.body;
6593 var fields = [];
6594 for (var name in headers) {
6595 if (headers[name] !== O[name]) {
6596 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));
6597 }
6598 }
6599 if (fields.length) {
6600 components.query = fields.join("&");
6601 }
6602 return components;
6603 }
6604};
6605
6606var URN_PARSE = /^([^\:]+)\:(.*)/;
6607//RFC 2141
6608var handler$5 = {
6609 scheme: "urn",
6610 parse: function parse$$1(components, options) {
6611 var matches = components.path && components.path.match(URN_PARSE);
6612 var urnComponents = components;
6613 if (matches) {
6614 var scheme = options.scheme || urnComponents.scheme || "urn";
6615 var nid = matches[1].toLowerCase();
6616 var nss = matches[2];
6617 var urnScheme = scheme + ":" + (options.nid || nid);
6618 var schemeHandler = SCHEMES[urnScheme];
6619 urnComponents.nid = nid;
6620 urnComponents.nss = nss;
6621 urnComponents.path = undefined;
6622 if (schemeHandler) {
6623 urnComponents = schemeHandler.parse(urnComponents, options);
6624 }
6625 } else {
6626 urnComponents.error = urnComponents.error || "URN can not be parsed.";
6627 }
6628 return urnComponents;
6629 },
6630 serialize: function serialize$$1(urnComponents, options) {
6631 var scheme = options.scheme || urnComponents.scheme || "urn";
6632 var nid = urnComponents.nid;
6633 var urnScheme = scheme + ":" + (options.nid || nid);
6634 var schemeHandler = SCHEMES[urnScheme];
6635 if (schemeHandler) {
6636 urnComponents = schemeHandler.serialize(urnComponents, options);
6637 }
6638 var uriComponents = urnComponents;
6639 var nss = urnComponents.nss;
6640 uriComponents.path = (nid || options.nid) + ":" + nss;
6641 return uriComponents;
6642 }
6643};
6644
6645var UUID = /^[0-9A-Fa-f]{8}(?:\-[0-9A-Fa-f]{4}){3}\-[0-9A-Fa-f]{12}$/;
6646//RFC 4122
6647var handler$6 = {
6648 scheme: "urn:uuid",
6649 parse: function parse(urnComponents, options) {
6650 var uuidComponents = urnComponents;
6651 uuidComponents.uuid = uuidComponents.nss;
6652 uuidComponents.nss = undefined;
6653 if (!options.tolerant && (!uuidComponents.uuid || !uuidComponents.uuid.match(UUID))) {
6654 uuidComponents.error = uuidComponents.error || "UUID is not valid.";
6655 }
6656 return uuidComponents;
6657 },
6658 serialize: function serialize(uuidComponents, options) {
6659 var urnComponents = uuidComponents;
6660 //normalize UUID
6661 urnComponents.nss = (uuidComponents.uuid || "").toLowerCase();
6662 return urnComponents;
6663 }
6664};
6665
6666SCHEMES[handler.scheme] = handler;
6667SCHEMES[handler$1.scheme] = handler$1;
6668SCHEMES[handler$2.scheme] = handler$2;
6669SCHEMES[handler$3.scheme] = handler$3;
6670SCHEMES[handler$4.scheme] = handler$4;
6671SCHEMES[handler$5.scheme] = handler$5;
6672SCHEMES[handler$6.scheme] = handler$6;
6673
6674exports.SCHEMES = SCHEMES;
6675exports.pctEncChar = pctEncChar;
6676exports.pctDecChars = pctDecChars;
6677exports.parse = parse;
6678exports.removeDotSegments = removeDotSegments;
6679exports.serialize = serialize;
6680exports.resolveComponents = resolveComponents;
6681exports.resolve = resolve;
6682exports.normalize = normalize;
6683exports.equal = equal;
6684exports.escapeComponent = escapeComponent;
6685exports.unescapeComponent = unescapeComponent;
6686
6687Object.defineProperty(exports, '__esModule', { value: true });
6688
6689})));
6690
6691
6692},{}],"ajv":[function(require,module,exports){
6693'use strict';
6694
6695var compileSchema = require('./compile')
6696 , resolve = require('./compile/resolve')
6697 , Cache = require('./cache')
6698 , SchemaObject = require('./compile/schema_obj')
6699 , stableStringify = require('fast-json-stable-stringify')
6700 , formats = require('./compile/formats')
6701 , rules = require('./compile/rules')
6702 , $dataMetaSchema = require('./data')
6703 , util = require('./compile/util');
6704
6705module.exports = Ajv;
6706
6707Ajv.prototype.validate = validate;
6708Ajv.prototype.compile = compile;
6709Ajv.prototype.addSchema = addSchema;
6710Ajv.prototype.addMetaSchema = addMetaSchema;
6711Ajv.prototype.validateSchema = validateSchema;
6712Ajv.prototype.getSchema = getSchema;
6713Ajv.prototype.removeSchema = removeSchema;
6714Ajv.prototype.addFormat = addFormat;
6715Ajv.prototype.errorsText = errorsText;
6716
6717Ajv.prototype._addSchema = _addSchema;
6718Ajv.prototype._compile = _compile;
6719
6720Ajv.prototype.compileAsync = require('./compile/async');
6721var customKeyword = require('./keyword');
6722Ajv.prototype.addKeyword = customKeyword.add;
6723Ajv.prototype.getKeyword = customKeyword.get;
6724Ajv.prototype.removeKeyword = customKeyword.remove;
6725Ajv.prototype.validateKeyword = customKeyword.validate;
6726
6727var errorClasses = require('./compile/error_classes');
6728Ajv.ValidationError = errorClasses.Validation;
6729Ajv.MissingRefError = errorClasses.MissingRef;
6730Ajv.$dataMetaSchema = $dataMetaSchema;
6731
6732var META_SCHEMA_ID = 'http://json-schema.org/draft-07/schema';
6733
6734var META_IGNORE_OPTIONS = [ 'removeAdditional', 'useDefaults', 'coerceTypes', 'strictDefaults' ];
6735var META_SUPPORT_DATA = ['/properties'];
6736
6737/**
6738 * Creates validator instance.
6739 * Usage: `Ajv(opts)`
6740 * @param {Object} opts optional options
6741 * @return {Object} ajv instance
6742 */
6743function Ajv(opts) {
6744 if (!(this instanceof Ajv)) return new Ajv(opts);
6745 opts = this._opts = util.copy(opts) || {};
6746 setLogger(this);
6747 this._schemas = {};
6748 this._refs = {};
6749 this._fragments = {};
6750 this._formats = formats(opts.format);
6751
6752 this._cache = opts.cache || new Cache;
6753 this._loadingSchemas = {};
6754 this._compilations = [];
6755 this.RULES = rules();
6756 this._getId = chooseGetId(opts);
6757
6758 opts.loopRequired = opts.loopRequired || Infinity;
6759 if (opts.errorDataPath == 'property') opts._errorDataPathProperty = true;
6760 if (opts.serialize === undefined) opts.serialize = stableStringify;
6761 this._metaOpts = getMetaSchemaOptions(this);
6762
6763 if (opts.formats) addInitialFormats(this);
6764 if (opts.keywords) addInitialKeywords(this);
6765 addDefaultMetaSchema(this);
6766 if (typeof opts.meta == 'object') this.addMetaSchema(opts.meta);
6767 if (opts.nullable) this.addKeyword('nullable', {metaSchema: {type: 'boolean'}});
6768 addInitialSchemas(this);
6769}
6770
6771
6772
6773/**
6774 * Validate data using schema
6775 * 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.
6776 * @this Ajv
6777 * @param {String|Object} schemaKeyRef key, ref or schema object
6778 * @param {Any} data to be validated
6779 * @return {Boolean} validation result. Errors from the last validation will be available in `ajv.errors` (and also in compiled schema: `schema.errors`).
6780 */
6781function validate(schemaKeyRef, data) {
6782 var v;
6783 if (typeof schemaKeyRef == 'string') {
6784 v = this.getSchema(schemaKeyRef);
6785 if (!v) throw new Error('no schema with key or ref "' + schemaKeyRef + '"');
6786 } else {
6787 var schemaObj = this._addSchema(schemaKeyRef);
6788 v = schemaObj.validate || this._compile(schemaObj);
6789 }
6790
6791 var valid = v(data);
6792 if (v.$async !== true) this.errors = v.errors;
6793 return valid;
6794}
6795
6796
6797/**
6798 * Create validating function for passed schema.
6799 * @this Ajv
6800 * @param {Object} schema schema object
6801 * @param {Boolean} _meta true if schema is a meta-schema. Used internally to compile meta schemas of custom keywords.
6802 * @return {Function} validating function
6803 */
6804function compile(schema, _meta) {
6805 var schemaObj = this._addSchema(schema, undefined, _meta);
6806 return schemaObj.validate || this._compile(schemaObj);
6807}
6808
6809
6810/**
6811 * Adds schema to the instance.
6812 * @this Ajv
6813 * @param {Object|Array} schema schema or array of schemas. If array is passed, `key` and other parameters will be ignored.
6814 * @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`.
6815 * @param {Boolean} _skipValidation true to skip schema validation. Used internally, option validateSchema should be used instead.
6816 * @param {Boolean} _meta true if schema is a meta-schema. Used internally, addMetaSchema should be used instead.
6817 * @return {Ajv} this for method chaining
6818 */
6819function addSchema(schema, key, _skipValidation, _meta) {
6820 if (Array.isArray(schema)){
6821 for (var i=0; i<schema.length; i++) this.addSchema(schema[i], undefined, _skipValidation, _meta);
6822 return this;
6823 }
6824 var id = this._getId(schema);
6825 if (id !== undefined && typeof id != 'string')
6826 throw new Error('schema id must be string');
6827 key = resolve.normalizeId(key || id);
6828 checkUnique(this, key);
6829 this._schemas[key] = this._addSchema(schema, _skipValidation, _meta, true);
6830 return this;
6831}
6832
6833
6834/**
6835 * Add schema that will be used to validate other schemas
6836 * options in META_IGNORE_OPTIONS are alway set to false
6837 * @this Ajv
6838 * @param {Object} schema schema object
6839 * @param {String} key optional schema key
6840 * @param {Boolean} skipValidation true to skip schema validation, can be used to override validateSchema option for meta-schema
6841 * @return {Ajv} this for method chaining
6842 */
6843function addMetaSchema(schema, key, skipValidation) {
6844 this.addSchema(schema, key, skipValidation, true);
6845 return this;
6846}
6847
6848
6849/**
6850 * Validate schema
6851 * @this Ajv
6852 * @param {Object} schema schema to validate
6853 * @param {Boolean} throwOrLogError pass true to throw (or log) an error if invalid
6854 * @return {Boolean} true if schema is valid
6855 */
6856function validateSchema(schema, throwOrLogError) {
6857 var $schema = schema.$schema;
6858 if ($schema !== undefined && typeof $schema != 'string')
6859 throw new Error('$schema must be a string');
6860 $schema = $schema || this._opts.defaultMeta || defaultMeta(this);
6861 if (!$schema) {
6862 this.logger.warn('meta-schema not available');
6863 this.errors = null;
6864 return true;
6865 }
6866 var valid = this.validate($schema, schema);
6867 if (!valid && throwOrLogError) {
6868 var message = 'schema is invalid: ' + this.errorsText();
6869 if (this._opts.validateSchema == 'log') this.logger.error(message);
6870 else throw new Error(message);
6871 }
6872 return valid;
6873}
6874
6875
6876function defaultMeta(self) {
6877 var meta = self._opts.meta;
6878 self._opts.defaultMeta = typeof meta == 'object'
6879 ? self._getId(meta) || meta
6880 : self.getSchema(META_SCHEMA_ID)
6881 ? META_SCHEMA_ID
6882 : undefined;
6883 return self._opts.defaultMeta;
6884}
6885
6886
6887/**
6888 * Get compiled schema from the instance by `key` or `ref`.
6889 * @this Ajv
6890 * @param {String} keyRef `key` that was passed to `addSchema` or full schema reference (`schema.id` or resolved id).
6891 * @return {Function} schema validating function (with property `schema`).
6892 */
6893function getSchema(keyRef) {
6894 var schemaObj = _getSchemaObj(this, keyRef);
6895 switch (typeof schemaObj) {
6896 case 'object': return schemaObj.validate || this._compile(schemaObj);
6897 case 'string': return this.getSchema(schemaObj);
6898 case 'undefined': return _getSchemaFragment(this, keyRef);
6899 }
6900}
6901
6902
6903function _getSchemaFragment(self, ref) {
6904 var res = resolve.schema.call(self, { schema: {} }, ref);
6905 if (res) {
6906 var schema = res.schema
6907 , root = res.root
6908 , baseId = res.baseId;
6909 var v = compileSchema.call(self, schema, root, undefined, baseId);
6910 self._fragments[ref] = new SchemaObject({
6911 ref: ref,
6912 fragment: true,
6913 schema: schema,
6914 root: root,
6915 baseId: baseId,
6916 validate: v
6917 });
6918 return v;
6919 }
6920}
6921
6922
6923function _getSchemaObj(self, keyRef) {
6924 keyRef = resolve.normalizeId(keyRef);
6925 return self._schemas[keyRef] || self._refs[keyRef] || self._fragments[keyRef];
6926}
6927
6928
6929/**
6930 * Remove cached schema(s).
6931 * If no parameter is passed all schemas but meta-schemas are removed.
6932 * If RegExp is passed all schemas with key/id matching pattern but meta-schemas are removed.
6933 * Even if schema is referenced by other schemas it still can be removed as other schemas have local references.
6934 * @this Ajv
6935 * @param {String|Object|RegExp} schemaKeyRef key, ref, pattern to match key/ref or schema object
6936 * @return {Ajv} this for method chaining
6937 */
6938function removeSchema(schemaKeyRef) {
6939 if (schemaKeyRef instanceof RegExp) {
6940 _removeAllSchemas(this, this._schemas, schemaKeyRef);
6941 _removeAllSchemas(this, this._refs, schemaKeyRef);
6942 return this;
6943 }
6944 switch (typeof schemaKeyRef) {
6945 case 'undefined':
6946 _removeAllSchemas(this, this._schemas);
6947 _removeAllSchemas(this, this._refs);
6948 this._cache.clear();
6949 return this;
6950 case 'string':
6951 var schemaObj = _getSchemaObj(this, schemaKeyRef);
6952 if (schemaObj) this._cache.del(schemaObj.cacheKey);
6953 delete this._schemas[schemaKeyRef];
6954 delete this._refs[schemaKeyRef];
6955 return this;
6956 case 'object':
6957 var serialize = this._opts.serialize;
6958 var cacheKey = serialize ? serialize(schemaKeyRef) : schemaKeyRef;
6959 this._cache.del(cacheKey);
6960 var id = this._getId(schemaKeyRef);
6961 if (id) {
6962 id = resolve.normalizeId(id);
6963 delete this._schemas[id];
6964 delete this._refs[id];
6965 }
6966 }
6967 return this;
6968}
6969
6970
6971function _removeAllSchemas(self, schemas, regex) {
6972 for (var keyRef in schemas) {
6973 var schemaObj = schemas[keyRef];
6974 if (!schemaObj.meta && (!regex || regex.test(keyRef))) {
6975 self._cache.del(schemaObj.cacheKey);
6976 delete schemas[keyRef];
6977 }
6978 }
6979}
6980
6981
6982/* @this Ajv */
6983function _addSchema(schema, skipValidation, meta, shouldAddSchema) {
6984 if (typeof schema != 'object' && typeof schema != 'boolean')
6985 throw new Error('schema should be object or boolean');
6986 var serialize = this._opts.serialize;
6987 var cacheKey = serialize ? serialize(schema) : schema;
6988 var cached = this._cache.get(cacheKey);
6989 if (cached) return cached;
6990
6991 shouldAddSchema = shouldAddSchema || this._opts.addUsedSchema !== false;
6992
6993 var id = resolve.normalizeId(this._getId(schema));
6994 if (id && shouldAddSchema) checkUnique(this, id);
6995
6996 var willValidate = this._opts.validateSchema !== false && !skipValidation;
6997 var recursiveMeta;
6998 if (willValidate && !(recursiveMeta = id && id == resolve.normalizeId(schema.$schema)))
6999 this.validateSchema(schema, true);
7000
7001 var localRefs = resolve.ids.call(this, schema);
7002
7003 var schemaObj = new SchemaObject({
7004 id: id,
7005 schema: schema,
7006 localRefs: localRefs,
7007 cacheKey: cacheKey,
7008 meta: meta
7009 });
7010
7011 if (id[0] != '#' && shouldAddSchema) this._refs[id] = schemaObj;
7012 this._cache.put(cacheKey, schemaObj);
7013
7014 if (willValidate && recursiveMeta) this.validateSchema(schema, true);
7015
7016 return schemaObj;
7017}
7018
7019
7020/* @this Ajv */
7021function _compile(schemaObj, root) {
7022 if (schemaObj.compiling) {
7023 schemaObj.validate = callValidate;
7024 callValidate.schema = schemaObj.schema;
7025 callValidate.errors = null;
7026 callValidate.root = root ? root : callValidate;
7027 if (schemaObj.schema.$async === true)
7028 callValidate.$async = true;
7029 return callValidate;
7030 }
7031 schemaObj.compiling = true;
7032
7033 var currentOpts;
7034 if (schemaObj.meta) {
7035 currentOpts = this._opts;
7036 this._opts = this._metaOpts;
7037 }
7038
7039 var v;
7040 try { v = compileSchema.call(this, schemaObj.schema, root, schemaObj.localRefs); }
7041 catch(e) {
7042 delete schemaObj.validate;
7043 throw e;
7044 }
7045 finally {
7046 schemaObj.compiling = false;
7047 if (schemaObj.meta) this._opts = currentOpts;
7048 }
7049
7050 schemaObj.validate = v;
7051 schemaObj.refs = v.refs;
7052 schemaObj.refVal = v.refVal;
7053 schemaObj.root = v.root;
7054 return v;
7055
7056
7057 /* @this {*} - custom context, see passContext option */
7058 function callValidate() {
7059 /* jshint validthis: true */
7060 var _validate = schemaObj.validate;
7061 var result = _validate.apply(this, arguments);
7062 callValidate.errors = _validate.errors;
7063 return result;
7064 }
7065}
7066
7067
7068function chooseGetId(opts) {
7069 switch (opts.schemaId) {
7070 case 'auto': return _get$IdOrId;
7071 case 'id': return _getId;
7072 default: return _get$Id;
7073 }
7074}
7075
7076/* @this Ajv */
7077function _getId(schema) {
7078 if (schema.$id) this.logger.warn('schema $id ignored', schema.$id);
7079 return schema.id;
7080}
7081
7082/* @this Ajv */
7083function _get$Id(schema) {
7084 if (schema.id) this.logger.warn('schema id ignored', schema.id);
7085 return schema.$id;
7086}
7087
7088
7089function _get$IdOrId(schema) {
7090 if (schema.$id && schema.id && schema.$id != schema.id)
7091 throw new Error('schema $id is different from id');
7092 return schema.$id || schema.id;
7093}
7094
7095
7096/**
7097 * Convert array of error message objects to string
7098 * @this Ajv
7099 * @param {Array<Object>} errors optional array of validation errors, if not passed errors from the instance are used.
7100 * @param {Object} options optional options with properties `separator` and `dataVar`.
7101 * @return {String} human readable string with all errors descriptions
7102 */
7103function errorsText(errors, options) {
7104 errors = errors || this.errors;
7105 if (!errors) return 'No errors';
7106 options = options || {};
7107 var separator = options.separator === undefined ? ', ' : options.separator;
7108 var dataVar = options.dataVar === undefined ? 'data' : options.dataVar;
7109
7110 var text = '';
7111 for (var i=0; i<errors.length; i++) {
7112 var e = errors[i];
7113 if (e) text += dataVar + e.dataPath + ' ' + e.message + separator;
7114 }
7115 return text.slice(0, -separator.length);
7116}
7117
7118
7119/**
7120 * Add custom format
7121 * @this Ajv
7122 * @param {String} name format name
7123 * @param {String|RegExp|Function} format string is converted to RegExp; function should return boolean (true when valid)
7124 * @return {Ajv} this for method chaining
7125 */
7126function addFormat(name, format) {
7127 if (typeof format == 'string') format = new RegExp(format);
7128 this._formats[name] = format;
7129 return this;
7130}
7131
7132
7133function addDefaultMetaSchema(self) {
7134 var $dataSchema;
7135 if (self._opts.$data) {
7136 $dataSchema = require('./refs/data.json');
7137 self.addMetaSchema($dataSchema, $dataSchema.$id, true);
7138 }
7139 if (self._opts.meta === false) return;
7140 var metaSchema = require('./refs/json-schema-draft-07.json');
7141 if (self._opts.$data) metaSchema = $dataMetaSchema(metaSchema, META_SUPPORT_DATA);
7142 self.addMetaSchema(metaSchema, META_SCHEMA_ID, true);
7143 self._refs['http://json-schema.org/schema'] = META_SCHEMA_ID;
7144}
7145
7146
7147function addInitialSchemas(self) {
7148 var optsSchemas = self._opts.schemas;
7149 if (!optsSchemas) return;
7150 if (Array.isArray(optsSchemas)) self.addSchema(optsSchemas);
7151 else for (var key in optsSchemas) self.addSchema(optsSchemas[key], key);
7152}
7153
7154
7155function addInitialFormats(self) {
7156 for (var name in self._opts.formats) {
7157 var format = self._opts.formats[name];
7158 self.addFormat(name, format);
7159 }
7160}
7161
7162
7163function addInitialKeywords(self) {
7164 for (var name in self._opts.keywords) {
7165 var keyword = self._opts.keywords[name];
7166 self.addKeyword(name, keyword);
7167 }
7168}
7169
7170
7171function checkUnique(self, id) {
7172 if (self._schemas[id] || self._refs[id])
7173 throw new Error('schema with key or id "' + id + '" already exists');
7174}
7175
7176
7177function getMetaSchemaOptions(self) {
7178 var metaOpts = util.copy(self._opts);
7179 for (var i=0; i<META_IGNORE_OPTIONS.length; i++)
7180 delete metaOpts[META_IGNORE_OPTIONS[i]];
7181 return metaOpts;
7182}
7183
7184
7185function setLogger(self) {
7186 var logger = self._opts.logger;
7187 if (logger === false) {
7188 self.logger = {log: noop, warn: noop, error: noop};
7189 } else {
7190 if (logger === undefined) logger = console;
7191 if (!(typeof logger == 'object' && logger.log && logger.warn && logger.error))
7192 throw new Error('logger must implement log, warn and error methods');
7193 self.logger = logger;
7194 }
7195}
7196
7197
7198function noop() {}
7199
7200},{"./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")
7201});
Note: See TracBrowser for help on using the repository browser.