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