| 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 e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){ |
| 2 | 'use strict'; |
| 3 | |
| 4 | var KEYWORDS = [ |
| 5 | 'multipleOf', |
| 6 | 'maximum', |
| 7 | 'exclusiveMaximum', |
| 8 | 'minimum', |
| 9 | 'exclusiveMinimum', |
| 10 | 'maxLength', |
| 11 | 'minLength', |
| 12 | 'pattern', |
| 13 | 'additionalItems', |
| 14 | 'maxItems', |
| 15 | 'minItems', |
| 16 | 'uniqueItems', |
| 17 | 'maxProperties', |
| 18 | 'minProperties', |
| 19 | 'required', |
| 20 | 'additionalProperties', |
| 21 | 'enum', |
| 22 | 'format', |
| 23 | 'const' |
| 24 | ]; |
| 25 | |
| 26 | module.exports = function (metaSchema, keywordsJsonPointers) { |
| 27 | for (var i=0; i<keywordsJsonPointers.length; i++) { |
| 28 | metaSchema = JSON.parse(JSON.stringify(metaSchema)); |
| 29 | var segments = keywordsJsonPointers[i].split('/'); |
| 30 | var keywords = metaSchema; |
| 31 | var j; |
| 32 | for (j=1; j<segments.length; j++) |
| 33 | keywords = keywords[segments[j]]; |
| 34 | |
| 35 | for (j=0; j<KEYWORDS.length; j++) { |
| 36 | var key = KEYWORDS[j]; |
| 37 | var schema = keywords[key]; |
| 38 | if (schema) { |
| 39 | keywords[key] = { |
| 40 | anyOf: [ |
| 41 | schema, |
| 42 | { $ref: 'https://raw.githubusercontent.com/epoberezkin/ajv/master/lib/refs/$data.json#' } |
| 43 | ] |
| 44 | }; |
| 45 | } |
| 46 | } |
| 47 | } |
| 48 | |
| 49 | return metaSchema; |
| 50 | }; |
| 51 | |
| 52 | },{}],2:[function(require,module,exports){ |
| 53 | 'use strict'; |
| 54 | |
| 55 | |
| 56 | var Cache = module.exports = function Cache() { |
| 57 | this._cache = {}; |
| 58 | }; |
| 59 | |
| 60 | |
| 61 | Cache.prototype.put = function Cache_put(key, value) { |
| 62 | this._cache[key] = value; |
| 63 | }; |
| 64 | |
| 65 | |
| 66 | Cache.prototype.get = function Cache_get(key) { |
| 67 | return this._cache[key]; |
| 68 | }; |
| 69 | |
| 70 | |
| 71 | Cache.prototype.del = function Cache_del(key) { |
| 72 | delete this._cache[key]; |
| 73 | }; |
| 74 | |
| 75 | |
| 76 | Cache.prototype.clear = function Cache_clear() { |
| 77 | this._cache = {}; |
| 78 | }; |
| 79 | |
| 80 | },{}],3:[function(require,module,exports){ |
| 81 | 'use strict'; |
| 82 | |
| 83 | //all requires must be explicit because browserify won't work with dynamic requires |
| 84 | module.exports = { |
| 85 | '$ref': require('../dotjs/ref'), |
| 86 | allOf: require('../dotjs/allOf'), |
| 87 | anyOf: require('../dotjs/anyOf'), |
| 88 | const: require('../dotjs/const'), |
| 89 | contains: require('../dotjs/contains'), |
| 90 | dependencies: require('../dotjs/dependencies'), |
| 91 | 'enum': require('../dotjs/enum'), |
| 92 | format: require('../dotjs/format'), |
| 93 | items: require('../dotjs/items'), |
| 94 | maximum: require('../dotjs/_limit'), |
| 95 | minimum: require('../dotjs/_limit'), |
| 96 | maxItems: require('../dotjs/_limitItems'), |
| 97 | minItems: require('../dotjs/_limitItems'), |
| 98 | maxLength: require('../dotjs/_limitLength'), |
| 99 | minLength: require('../dotjs/_limitLength'), |
| 100 | maxProperties: require('../dotjs/_limitProperties'), |
| 101 | minProperties: require('../dotjs/_limitProperties'), |
| 102 | multipleOf: require('../dotjs/multipleOf'), |
| 103 | not: require('../dotjs/not'), |
| 104 | oneOf: require('../dotjs/oneOf'), |
| 105 | pattern: require('../dotjs/pattern'), |
| 106 | properties: require('../dotjs/properties'), |
| 107 | propertyNames: require('../dotjs/propertyNames'), |
| 108 | required: require('../dotjs/required'), |
| 109 | uniqueItems: require('../dotjs/uniqueItems'), |
| 110 | validate: require('../dotjs/validate') |
| 111 | }; |
| 112 | |
| 113 | },{"../dotjs/_limit":13,"../dotjs/_limitItems":14,"../dotjs/_limitLength":15,"../dotjs/_limitProperties":16,"../dotjs/allOf":17,"../dotjs/anyOf":18,"../dotjs/const":19,"../dotjs/contains":20,"../dotjs/dependencies":22,"../dotjs/enum":23,"../dotjs/format":24,"../dotjs/items":25,"../dotjs/multipleOf":26,"../dotjs/not":27,"../dotjs/oneOf":28,"../dotjs/pattern":29,"../dotjs/properties":30,"../dotjs/propertyNames":31,"../dotjs/ref":32,"../dotjs/required":33,"../dotjs/uniqueItems":34,"../dotjs/validate":35}],4:[function(require,module,exports){ |
| 114 | 'use strict'; |
| 115 | |
| 116 | var MissingRefError = require('./error_classes').MissingRef; |
| 117 | |
| 118 | module.exports = compileAsync; |
| 119 | |
| 120 | |
| 121 | /** |
| 122 | * Creates validating function for passed schema with asynchronous loading of missing schemas. |
| 123 | * `loadSchema` option should be a function that accepts schema uri and returns promise that resolves with the schema. |
| 124 | * @this Ajv |
| 125 | * @param {Object} schema schema object |
| 126 | * @param {Boolean} meta optional true to compile meta-schema; this parameter can be skipped |
| 127 | * @param {Function} callback an optional node-style callback, it is called with 2 parameters: error (or null) and validating function. |
| 128 | * @return {Promise} promise that resolves with a validating function. |
| 129 | */ |
| 130 | function compileAsync(schema, meta, callback) { |
| 131 | /* eslint no-shadow: 0 */ |
| 132 | /* global Promise */ |
| 133 | /* jshint validthis: true */ |
| 134 | var self = this; |
| 135 | if (typeof this._opts.loadSchema != 'function') |
| 136 | throw new Error('options.loadSchema should be a function'); |
| 137 | |
| 138 | if (typeof meta == 'function') { |
| 139 | callback = meta; |
| 140 | meta = undefined; |
| 141 | } |
| 142 | |
| 143 | var p = loadMetaSchemaOf(schema).then(function () { |
| 144 | var schemaObj = self._addSchema(schema, undefined, meta); |
| 145 | return schemaObj.validate || _compileAsync(schemaObj); |
| 146 | }); |
| 147 | |
| 148 | if (callback) { |
| 149 | p.then( |
| 150 | function(v) { callback(null, v); }, |
| 151 | callback |
| 152 | ); |
| 153 | } |
| 154 | |
| 155 | return p; |
| 156 | |
| 157 | |
| 158 | function loadMetaSchemaOf(sch) { |
| 159 | var $schema = sch.$schema; |
| 160 | return $schema && !self.getSchema($schema) |
| 161 | ? compileAsync.call(self, { $ref: $schema }, true) |
| 162 | : Promise.resolve(); |
| 163 | } |
| 164 | |
| 165 | |
| 166 | function _compileAsync(schemaObj) { |
| 167 | try { return self._compile(schemaObj); } |
| 168 | catch(e) { |
| 169 | if (e instanceof MissingRefError) return loadMissingSchema(e); |
| 170 | throw e; |
| 171 | } |
| 172 | |
| 173 | |
| 174 | function loadMissingSchema(e) { |
| 175 | var ref = e.missingSchema; |
| 176 | if (added(ref)) throw new Error('Schema ' + ref + ' is loaded but ' + e.missingRef + ' cannot be resolved'); |
| 177 | |
| 178 | var schemaPromise = self._loadingSchemas[ref]; |
| 179 | if (!schemaPromise) { |
| 180 | schemaPromise = self._loadingSchemas[ref] = self._opts.loadSchema(ref); |
| 181 | schemaPromise.then(removePromise, removePromise); |
| 182 | } |
| 183 | |
| 184 | return schemaPromise.then(function (sch) { |
| 185 | if (!added(ref)) { |
| 186 | return loadMetaSchemaOf(sch).then(function () { |
| 187 | if (!added(ref)) self.addSchema(sch, ref, undefined, meta); |
| 188 | }); |
| 189 | } |
| 190 | }).then(function() { |
| 191 | return _compileAsync(schemaObj); |
| 192 | }); |
| 193 | |
| 194 | function removePromise() { |
| 195 | delete self._loadingSchemas[ref]; |
| 196 | } |
| 197 | |
| 198 | function added(ref) { |
| 199 | return self._refs[ref] || self._schemas[ref]; |
| 200 | } |
| 201 | } |
| 202 | } |
| 203 | } |
| 204 | |
| 205 | },{"./error_classes":5}],5:[function(require,module,exports){ |
| 206 | 'use strict'; |
| 207 | |
| 208 | var resolve = require('./resolve'); |
| 209 | |
| 210 | module.exports = { |
| 211 | Validation: errorSubclass(ValidationError), |
| 212 | MissingRef: errorSubclass(MissingRefError) |
| 213 | }; |
| 214 | |
| 215 | |
| 216 | function ValidationError(errors) { |
| 217 | this.message = 'validation failed'; |
| 218 | this.errors = errors; |
| 219 | this.ajv = this.validation = true; |
| 220 | } |
| 221 | |
| 222 | |
| 223 | MissingRefError.message = function (baseId, ref) { |
| 224 | return 'can\'t resolve reference ' + ref + ' from id ' + baseId; |
| 225 | }; |
| 226 | |
| 227 | |
| 228 | function MissingRefError(baseId, ref, message) { |
| 229 | this.message = message || MissingRefError.message(baseId, ref); |
| 230 | this.missingRef = resolve.url(baseId, ref); |
| 231 | this.missingSchema = resolve.normalizeId(resolve.fullPath(this.missingRef)); |
| 232 | } |
| 233 | |
| 234 | |
| 235 | function errorSubclass(Subclass) { |
| 236 | Subclass.prototype = Object.create(Error.prototype); |
| 237 | Subclass.prototype.constructor = Subclass; |
| 238 | return Subclass; |
| 239 | } |
| 240 | |
| 241 | },{"./resolve":8}],6:[function(require,module,exports){ |
| 242 | 'use strict'; |
| 243 | |
| 244 | var util = require('./util'); |
| 245 | |
| 246 | var DATE = /^\d\d\d\d-(\d\d)-(\d\d)$/; |
| 247 | var DAYS = [0,31,29,31,30,31,30,31,31,30,31,30,31]; |
| 248 | var TIME = /^(\d\d):(\d\d):(\d\d)(\.\d+)?(z|[+-]\d\d:\d\d)?$/i; |
| 249 | var HOSTNAME = /^[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?(?:\.[a-z0-9](?:[-0-9a-z]{0,61}[0-9a-z])?)*$/i; |
| 250 | 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; |
| 251 | 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; |
| 252 | // uri-template: https://tools.ietf.org/html/rfc6570 |
| 253 | 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; |
| 254 | // For the source: https://gist.github.com/dperini/729294 |
| 255 | // For test cases: https://mathiasbynens.be/demo/url-regex |
| 256 | // @todo Delete current URL in favour of the commented out URL rule when this issue is fixed https://github.com/eslint/eslint/issues/7983. |
| 257 | // 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; |
| 258 | 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; |
| 259 | var UUID = /^(?:urn:uuid:)?[0-9a-f]{8}-(?:[0-9a-f]{4}-){3}[0-9a-f]{12}$/i; |
| 260 | var JSON_POINTER = /^(?:\/(?:[^~/]|~0|~1)*)*$|^#(?:\/(?:[a-z0-9_\-.!$&'()*+,;:=@]|%[0-9a-f]{2}|~0|~1)*)*$/i; |
| 261 | var RELATIVE_JSON_POINTER = /^(?:0|[1-9][0-9]*)(?:#|(?:\/(?:[^~/]|~0|~1)*)*)$/; |
| 262 | |
| 263 | |
| 264 | module.exports = formats; |
| 265 | |
| 266 | function formats(mode) { |
| 267 | mode = mode == 'full' ? 'full' : 'fast'; |
| 268 | return util.copy(formats[mode]); |
| 269 | } |
| 270 | |
| 271 | |
| 272 | formats.fast = { |
| 273 | // date: http://tools.ietf.org/html/rfc3339#section-5.6 |
| 274 | date: /^\d\d\d\d-[0-1]\d-[0-3]\d$/, |
| 275 | // date-time: http://tools.ietf.org/html/rfc3339#section-5.6 |
| 276 | time: /^[0-2]\d:[0-5]\d:[0-5]\d(?:\.\d+)?(?:z|[+-]\d\d:\d\d)?$/i, |
| 277 | 'date-time': /^\d\d\d\d-[0-1]\d-[0-3]\d[t\s][0-2]\d:[0-5]\d:[0-5]\d(?:\.\d+)?(?:z|[+-]\d\d:\d\d)$/i, |
| 278 | // uri: https://github.com/mafintosh/is-my-json-valid/blob/master/formats.js |
| 279 | uri: /^(?:[a-z][a-z0-9+-.]*)(?::|\/)\/?[^\s]*$/i, |
| 280 | 'uri-reference': /^(?:(?:[a-z][a-z0-9+-.]*:)?\/\/)?[^\s]*$/i, |
| 281 | 'uri-template': URITEMPLATE, |
| 282 | url: URL, |
| 283 | // email (sources from jsen validator): |
| 284 | // http://stackoverflow.com/questions/201323/using-a-regular-expression-to-validate-an-email-address#answer-8829363 |
| 285 | // http://www.w3.org/TR/html5/forms.html#valid-e-mail-address (search for 'willful violation') |
| 286 | 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, |
| 287 | hostname: HOSTNAME, |
| 288 | // optimized https://www.safaribooksonline.com/library/view/regular-expressions-cookbook/9780596802837/ch07s16.html |
| 289 | ipv4: /^(?:(?:25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(?:25[0-5]|2[0-4]\d|[01]?\d\d?)$/, |
| 290 | // optimized http://stackoverflow.com/questions/53497/regular-expression-that-matches-valid-ipv6-addresses |
| 291 | 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, |
| 292 | regex: regex, |
| 293 | // uuid: http://tools.ietf.org/html/rfc4122 |
| 294 | uuid: UUID, |
| 295 | // JSON-pointer: https://tools.ietf.org/html/rfc6901 |
| 296 | // uri fragment: https://tools.ietf.org/html/rfc3986#appendix-A |
| 297 | 'json-pointer': JSON_POINTER, |
| 298 | // relative JSON-pointer: http://tools.ietf.org/html/draft-luff-relative-json-pointer-00 |
| 299 | 'relative-json-pointer': RELATIVE_JSON_POINTER |
| 300 | }; |
| 301 | |
| 302 | |
| 303 | formats.full = { |
| 304 | date: date, |
| 305 | time: time, |
| 306 | 'date-time': date_time, |
| 307 | uri: uri, |
| 308 | 'uri-reference': URIREF, |
| 309 | 'uri-template': URITEMPLATE, |
| 310 | url: URL, |
| 311 | 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, |
| 312 | hostname: hostname, |
| 313 | ipv4: /^(?:(?:25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(?:25[0-5]|2[0-4]\d|[01]?\d\d?)$/, |
| 314 | 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, |
| 315 | regex: regex, |
| 316 | uuid: UUID, |
| 317 | 'json-pointer': JSON_POINTER, |
| 318 | 'relative-json-pointer': RELATIVE_JSON_POINTER |
| 319 | }; |
| 320 | |
| 321 | |
| 322 | function date(str) { |
| 323 | // full-date from http://tools.ietf.org/html/rfc3339#section-5.6 |
| 324 | var matches = str.match(DATE); |
| 325 | if (!matches) return false; |
| 326 | |
| 327 | var month = +matches[1]; |
| 328 | var day = +matches[2]; |
| 329 | return month >= 1 && month <= 12 && day >= 1 && day <= DAYS[month]; |
| 330 | } |
| 331 | |
| 332 | |
| 333 | function time(str, full) { |
| 334 | var matches = str.match(TIME); |
| 335 | if (!matches) return false; |
| 336 | |
| 337 | var hour = matches[1]; |
| 338 | var minute = matches[2]; |
| 339 | var second = matches[3]; |
| 340 | var timeZone = matches[5]; |
| 341 | return hour <= 23 && minute <= 59 && second <= 59 && (!full || timeZone); |
| 342 | } |
| 343 | |
| 344 | |
| 345 | var DATE_TIME_SEPARATOR = /t|\s/i; |
| 346 | function date_time(str) { |
| 347 | // http://tools.ietf.org/html/rfc3339#section-5.6 |
| 348 | var dateTime = str.split(DATE_TIME_SEPARATOR); |
| 349 | return dateTime.length == 2 && date(dateTime[0]) && time(dateTime[1], true); |
| 350 | } |
| 351 | |
| 352 | |
| 353 | function hostname(str) { |
| 354 | // https://tools.ietf.org/html/rfc1034#section-3.5 |
| 355 | // https://tools.ietf.org/html/rfc1123#section-2 |
| 356 | return str.length <= 255 && HOSTNAME.test(str); |
| 357 | } |
| 358 | |
| 359 | |
| 360 | var NOT_URI_FRAGMENT = /\/|:/; |
| 361 | function uri(str) { |
| 362 | // http://jmrware.com/articles/2009/uri_regexp/URI_regex.html + optional protocol + required "." |
| 363 | return NOT_URI_FRAGMENT.test(str) && URI.test(str); |
| 364 | } |
| 365 | |
| 366 | |
| 367 | var Z_ANCHOR = /[^\\]\\Z/; |
| 368 | function regex(str) { |
| 369 | if (Z_ANCHOR.test(str)) return false; |
| 370 | try { |
| 371 | new RegExp(str); |
| 372 | return true; |
| 373 | } catch(e) { |
| 374 | return false; |
| 375 | } |
| 376 | } |
| 377 | |
| 378 | },{"./util":12}],7:[function(require,module,exports){ |
| 379 | 'use strict'; |
| 380 | |
| 381 | var resolve = require('./resolve') |
| 382 | , util = require('./util') |
| 383 | , errorClasses = require('./error_classes') |
| 384 | , stableStringify = require('fast-json-stable-stringify'); |
| 385 | |
| 386 | var validateGenerator = require('../dotjs/validate'); |
| 387 | |
| 388 | /** |
| 389 | * Functions below are used inside compiled validations function |
| 390 | */ |
| 391 | |
| 392 | var co = require('co'); |
| 393 | var ucs2length = util.ucs2length; |
| 394 | var equal = require('fast-deep-equal'); |
| 395 | |
| 396 | // this error is thrown by async schemas to return validation errors via exception |
| 397 | var ValidationError = errorClasses.Validation; |
| 398 | |
| 399 | module.exports = compile; |
| 400 | |
| 401 | |
| 402 | /** |
| 403 | * Compiles schema to validation function |
| 404 | * @this Ajv |
| 405 | * @param {Object} schema schema object |
| 406 | * @param {Object} root object with information about the root schema for this schema |
| 407 | * @param {Object} localRefs the hash of local references inside the schema (created by resolve.id), used for inline resolution |
| 408 | * @param {String} baseId base ID for IDs in the schema |
| 409 | * @return {Function} validation function |
| 410 | */ |
| 411 | function compile(schema, root, localRefs, baseId) { |
| 412 | /* jshint validthis: true, evil: true */ |
| 413 | /* eslint no-shadow: 0 */ |
| 414 | var self = this |
| 415 | , opts = this._opts |
| 416 | , refVal = [ undefined ] |
| 417 | , refs = {} |
| 418 | , patterns = [] |
| 419 | , patternsHash = {} |
| 420 | , defaults = [] |
| 421 | , defaultsHash = {} |
| 422 | , customRules = []; |
| 423 | |
| 424 | root = root || { schema: schema, refVal: refVal, refs: refs }; |
| 425 | |
| 426 | var c = checkCompiling.call(this, schema, root, baseId); |
| 427 | var compilation = this._compilations[c.index]; |
| 428 | if (c.compiling) return (compilation.callValidate = callValidate); |
| 429 | |
| 430 | var formats = this._formats; |
| 431 | var RULES = this.RULES; |
| 432 | |
| 433 | try { |
| 434 | var v = localCompile(schema, root, localRefs, baseId); |
| 435 | compilation.validate = v; |
| 436 | var cv = compilation.callValidate; |
| 437 | if (cv) { |
| 438 | cv.schema = v.schema; |
| 439 | cv.errors = null; |
| 440 | cv.refs = v.refs; |
| 441 | cv.refVal = v.refVal; |
| 442 | cv.root = v.root; |
| 443 | cv.$async = v.$async; |
| 444 | if (opts.sourceCode) cv.source = v.source; |
| 445 | } |
| 446 | return v; |
| 447 | } finally { |
| 448 | endCompiling.call(this, schema, root, baseId); |
| 449 | } |
| 450 | |
| 451 | function callValidate() { |
| 452 | var validate = compilation.validate; |
| 453 | var result = validate.apply(null, arguments); |
| 454 | callValidate.errors = validate.errors; |
| 455 | return result; |
| 456 | } |
| 457 | |
| 458 | function localCompile(_schema, _root, localRefs, baseId) { |
| 459 | var isRoot = !_root || (_root && _root.schema == _schema); |
| 460 | if (_root.schema != root.schema) |
| 461 | return compile.call(self, _schema, _root, localRefs, baseId); |
| 462 | |
| 463 | var $async = _schema.$async === true; |
| 464 | |
| 465 | var sourceCode = validateGenerator({ |
| 466 | isTop: true, |
| 467 | schema: _schema, |
| 468 | isRoot: isRoot, |
| 469 | baseId: baseId, |
| 470 | root: _root, |
| 471 | schemaPath: '', |
| 472 | errSchemaPath: '#', |
| 473 | errorPath: '""', |
| 474 | MissingRefError: errorClasses.MissingRef, |
| 475 | RULES: RULES, |
| 476 | validate: validateGenerator, |
| 477 | util: util, |
| 478 | resolve: resolve, |
| 479 | resolveRef: resolveRef, |
| 480 | usePattern: usePattern, |
| 481 | useDefault: useDefault, |
| 482 | useCustomRule: useCustomRule, |
| 483 | opts: opts, |
| 484 | formats: formats, |
| 485 | logger: self.logger, |
| 486 | self: self |
| 487 | }); |
| 488 | |
| 489 | sourceCode = vars(refVal, refValCode) + vars(patterns, patternCode) |
| 490 | + vars(defaults, defaultCode) + vars(customRules, customRuleCode) |
| 491 | + sourceCode; |
| 492 | |
| 493 | if (opts.processCode) sourceCode = opts.processCode(sourceCode); |
| 494 | // console.log('\n\n\n *** \n', JSON.stringify(sourceCode)); |
| 495 | var validate; |
| 496 | try { |
| 497 | var makeValidate = new Function( |
| 498 | 'self', |
| 499 | 'RULES', |
| 500 | 'formats', |
| 501 | 'root', |
| 502 | 'refVal', |
| 503 | 'defaults', |
| 504 | 'customRules', |
| 505 | 'co', |
| 506 | 'equal', |
| 507 | 'ucs2length', |
| 508 | 'ValidationError', |
| 509 | sourceCode |
| 510 | ); |
| 511 | |
| 512 | validate = makeValidate( |
| 513 | self, |
| 514 | RULES, |
| 515 | formats, |
| 516 | root, |
| 517 | refVal, |
| 518 | defaults, |
| 519 | customRules, |
| 520 | co, |
| 521 | equal, |
| 522 | ucs2length, |
| 523 | ValidationError |
| 524 | ); |
| 525 | |
| 526 | refVal[0] = validate; |
| 527 | } catch(e) { |
| 528 | self.logger.error('Error compiling schema, function code:', sourceCode); |
| 529 | throw e; |
| 530 | } |
| 531 | |
| 532 | validate.schema = _schema; |
| 533 | validate.errors = null; |
| 534 | validate.refs = refs; |
| 535 | validate.refVal = refVal; |
| 536 | validate.root = isRoot ? validate : _root; |
| 537 | if ($async) validate.$async = true; |
| 538 | if (opts.sourceCode === true) { |
| 539 | validate.source = { |
| 540 | code: sourceCode, |
| 541 | patterns: patterns, |
| 542 | defaults: defaults |
| 543 | }; |
| 544 | } |
| 545 | |
| 546 | return validate; |
| 547 | } |
| 548 | |
| 549 | function resolveRef(baseId, ref, isRoot) { |
| 550 | ref = resolve.url(baseId, ref); |
| 551 | var refIndex = refs[ref]; |
| 552 | var _refVal, refCode; |
| 553 | if (refIndex !== undefined) { |
| 554 | _refVal = refVal[refIndex]; |
| 555 | refCode = 'refVal[' + refIndex + ']'; |
| 556 | return resolvedRef(_refVal, refCode); |
| 557 | } |
| 558 | if (!isRoot && root.refs) { |
| 559 | var rootRefId = root.refs[ref]; |
| 560 | if (rootRefId !== undefined) { |
| 561 | _refVal = root.refVal[rootRefId]; |
| 562 | refCode = addLocalRef(ref, _refVal); |
| 563 | return resolvedRef(_refVal, refCode); |
| 564 | } |
| 565 | } |
| 566 | |
| 567 | refCode = addLocalRef(ref); |
| 568 | var v = resolve.call(self, localCompile, root, ref); |
| 569 | if (v === undefined) { |
| 570 | var localSchema = localRefs && localRefs[ref]; |
| 571 | if (localSchema) { |
| 572 | v = resolve.inlineRef(localSchema, opts.inlineRefs) |
| 573 | ? localSchema |
| 574 | : compile.call(self, localSchema, root, localRefs, baseId); |
| 575 | } |
| 576 | } |
| 577 | |
| 578 | if (v === undefined) { |
| 579 | removeLocalRef(ref); |
| 580 | } else { |
| 581 | replaceLocalRef(ref, v); |
| 582 | return resolvedRef(v, refCode); |
| 583 | } |
| 584 | } |
| 585 | |
| 586 | function addLocalRef(ref, v) { |
| 587 | var refId = refVal.length; |
| 588 | refVal[refId] = v; |
| 589 | refs[ref] = refId; |
| 590 | return 'refVal' + refId; |
| 591 | } |
| 592 | |
| 593 | function removeLocalRef(ref) { |
| 594 | delete refs[ref]; |
| 595 | } |
| 596 | |
| 597 | function replaceLocalRef(ref, v) { |
| 598 | var refId = refs[ref]; |
| 599 | refVal[refId] = v; |
| 600 | } |
| 601 | |
| 602 | function resolvedRef(refVal, code) { |
| 603 | return typeof refVal == 'object' || typeof refVal == 'boolean' |
| 604 | ? { code: code, schema: refVal, inline: true } |
| 605 | : { code: code, $async: refVal && refVal.$async }; |
| 606 | } |
| 607 | |
| 608 | function usePattern(regexStr) { |
| 609 | var index = patternsHash[regexStr]; |
| 610 | if (index === undefined) { |
| 611 | index = patternsHash[regexStr] = patterns.length; |
| 612 | patterns[index] = regexStr; |
| 613 | } |
| 614 | return 'pattern' + index; |
| 615 | } |
| 616 | |
| 617 | function useDefault(value) { |
| 618 | switch (typeof value) { |
| 619 | case 'boolean': |
| 620 | case 'number': |
| 621 | return '' + value; |
| 622 | case 'string': |
| 623 | return util.toQuotedString(value); |
| 624 | case 'object': |
| 625 | if (value === null) return 'null'; |
| 626 | var valueStr = stableStringify(value); |
| 627 | var index = defaultsHash[valueStr]; |
| 628 | if (index === undefined) { |
| 629 | index = defaultsHash[valueStr] = defaults.length; |
| 630 | defaults[index] = value; |
| 631 | } |
| 632 | return 'default' + index; |
| 633 | } |
| 634 | } |
| 635 | |
| 636 | function useCustomRule(rule, schema, parentSchema, it) { |
| 637 | var validateSchema = rule.definition.validateSchema; |
| 638 | if (validateSchema && self._opts.validateSchema !== false) { |
| 639 | var valid = validateSchema(schema); |
| 640 | if (!valid) { |
| 641 | var message = 'keyword schema is invalid: ' + self.errorsText(validateSchema.errors); |
| 642 | if (self._opts.validateSchema == 'log') self.logger.error(message); |
| 643 | else throw new Error(message); |
| 644 | } |
| 645 | } |
| 646 | |
| 647 | var compile = rule.definition.compile |
| 648 | , inline = rule.definition.inline |
| 649 | , macro = rule.definition.macro; |
| 650 | |
| 651 | var validate; |
| 652 | if (compile) { |
| 653 | validate = compile.call(self, schema, parentSchema, it); |
| 654 | } else if (macro) { |
| 655 | validate = macro.call(self, schema, parentSchema, it); |
| 656 | if (opts.validateSchema !== false) self.validateSchema(validate, true); |
| 657 | } else if (inline) { |
| 658 | validate = inline.call(self, it, rule.keyword, schema, parentSchema); |
| 659 | } else { |
| 660 | validate = rule.definition.validate; |
| 661 | if (!validate) return; |
| 662 | } |
| 663 | |
| 664 | if (validate === undefined) |
| 665 | throw new Error('custom keyword "' + rule.keyword + '"failed to compile'); |
| 666 | |
| 667 | var index = customRules.length; |
| 668 | customRules[index] = validate; |
| 669 | |
| 670 | return { |
| 671 | code: 'customRule' + index, |
| 672 | validate: validate |
| 673 | }; |
| 674 | } |
| 675 | } |
| 676 | |
| 677 | |
| 678 | /** |
| 679 | * Checks if the schema is currently compiled |
| 680 | * @this Ajv |
| 681 | * @param {Object} schema schema to compile |
| 682 | * @param {Object} root root object |
| 683 | * @param {String} baseId base schema ID |
| 684 | * @return {Object} object with properties "index" (compilation index) and "compiling" (boolean) |
| 685 | */ |
| 686 | function checkCompiling(schema, root, baseId) { |
| 687 | /* jshint validthis: true */ |
| 688 | var index = compIndex.call(this, schema, root, baseId); |
| 689 | if (index >= 0) return { index: index, compiling: true }; |
| 690 | index = this._compilations.length; |
| 691 | this._compilations[index] = { |
| 692 | schema: schema, |
| 693 | root: root, |
| 694 | baseId: baseId |
| 695 | }; |
| 696 | return { index: index, compiling: false }; |
| 697 | } |
| 698 | |
| 699 | |
| 700 | /** |
| 701 | * Removes the schema from the currently compiled list |
| 702 | * @this Ajv |
| 703 | * @param {Object} schema schema to compile |
| 704 | * @param {Object} root root object |
| 705 | * @param {String} baseId base schema ID |
| 706 | */ |
| 707 | function endCompiling(schema, root, baseId) { |
| 708 | /* jshint validthis: true */ |
| 709 | var i = compIndex.call(this, schema, root, baseId); |
| 710 | if (i >= 0) this._compilations.splice(i, 1); |
| 711 | } |
| 712 | |
| 713 | |
| 714 | /** |
| 715 | * Index of schema compilation in the currently compiled list |
| 716 | * @this Ajv |
| 717 | * @param {Object} schema schema to compile |
| 718 | * @param {Object} root root object |
| 719 | * @param {String} baseId base schema ID |
| 720 | * @return {Integer} compilation index |
| 721 | */ |
| 722 | function compIndex(schema, root, baseId) { |
| 723 | /* jshint validthis: true */ |
| 724 | for (var i=0; i<this._compilations.length; i++) { |
| 725 | var c = this._compilations[i]; |
| 726 | if (c.schema == schema && c.root == root && c.baseId == baseId) return i; |
| 727 | } |
| 728 | return -1; |
| 729 | } |
| 730 | |
| 731 | |
| 732 | function patternCode(i, patterns) { |
| 733 | return 'var pattern' + i + ' = new RegExp(' + util.toQuotedString(patterns[i]) + ');'; |
| 734 | } |
| 735 | |
| 736 | |
| 737 | function defaultCode(i) { |
| 738 | return 'var default' + i + ' = defaults[' + i + '];'; |
| 739 | } |
| 740 | |
| 741 | |
| 742 | function refValCode(i, refVal) { |
| 743 | return refVal[i] === undefined ? '' : 'var refVal' + i + ' = refVal[' + i + '];'; |
| 744 | } |
| 745 | |
| 746 | |
| 747 | function customRuleCode(i) { |
| 748 | return 'var customRule' + i + ' = customRules[' + i + '];'; |
| 749 | } |
| 750 | |
| 751 | |
| 752 | function vars(arr, statement) { |
| 753 | if (!arr.length) return ''; |
| 754 | var code = ''; |
| 755 | for (var i=0; i<arr.length; i++) |
| 756 | code += statement(i, arr); |
| 757 | return code; |
| 758 | } |
| 759 | |
| 760 | },{"../dotjs/validate":35,"./error_classes":5,"./resolve":8,"./util":12,"co":40,"fast-deep-equal":41,"fast-json-stable-stringify":42}],8:[function(require,module,exports){ |
| 761 | 'use strict'; |
| 762 | |
| 763 | var url = require('url') |
| 764 | , equal = require('fast-deep-equal') |
| 765 | , util = require('./util') |
| 766 | , SchemaObject = require('./schema_obj') |
| 767 | , traverse = require('json-schema-traverse'); |
| 768 | |
| 769 | module.exports = resolve; |
| 770 | |
| 771 | resolve.normalizeId = normalizeId; |
| 772 | resolve.fullPath = getFullPath; |
| 773 | resolve.url = resolveUrl; |
| 774 | resolve.ids = resolveIds; |
| 775 | resolve.inlineRef = inlineRef; |
| 776 | resolve.schema = resolveSchema; |
| 777 | |
| 778 | /** |
| 779 | * [resolve and compile the references ($ref)] |
| 780 | * @this Ajv |
| 781 | * @param {Function} compile reference to schema compilation funciton (localCompile) |
| 782 | * @param {Object} root object with information about the root schema for the current schema |
| 783 | * @param {String} ref reference to resolve |
| 784 | * @return {Object|Function} schema object (if the schema can be inlined) or validation function |
| 785 | */ |
| 786 | function resolve(compile, root, ref) { |
| 787 | /* jshint validthis: true */ |
| 788 | var refVal = this._refs[ref]; |
| 789 | if (typeof refVal == 'string') { |
| 790 | if (this._refs[refVal]) refVal = this._refs[refVal]; |
| 791 | else return resolve.call(this, compile, root, refVal); |
| 792 | } |
| 793 | |
| 794 | refVal = refVal || this._schemas[ref]; |
| 795 | if (refVal instanceof SchemaObject) { |
| 796 | return inlineRef(refVal.schema, this._opts.inlineRefs) |
| 797 | ? refVal.schema |
| 798 | : refVal.validate || this._compile(refVal); |
| 799 | } |
| 800 | |
| 801 | var res = resolveSchema.call(this, root, ref); |
| 802 | var schema, v, baseId; |
| 803 | if (res) { |
| 804 | schema = res.schema; |
| 805 | root = res.root; |
| 806 | baseId = res.baseId; |
| 807 | } |
| 808 | |
| 809 | if (schema instanceof SchemaObject) { |
| 810 | v = schema.validate || compile.call(this, schema.schema, root, undefined, baseId); |
| 811 | } else if (schema !== undefined) { |
| 812 | v = inlineRef(schema, this._opts.inlineRefs) |
| 813 | ? schema |
| 814 | : compile.call(this, schema, root, undefined, baseId); |
| 815 | } |
| 816 | |
| 817 | return v; |
| 818 | } |
| 819 | |
| 820 | |
| 821 | /** |
| 822 | * Resolve schema, its root and baseId |
| 823 | * @this Ajv |
| 824 | * @param {Object} root root object with properties schema, refVal, refs |
| 825 | * @param {String} ref reference to resolve |
| 826 | * @return {Object} object with properties schema, root, baseId |
| 827 | */ |
| 828 | function resolveSchema(root, ref) { |
| 829 | /* jshint validthis: true */ |
| 830 | var p = url.parse(ref, false, true) |
| 831 | , refPath = _getFullPath(p) |
| 832 | , baseId = getFullPath(this._getId(root.schema)); |
| 833 | if (refPath !== baseId) { |
| 834 | var id = normalizeId(refPath); |
| 835 | var refVal = this._refs[id]; |
| 836 | if (typeof refVal == 'string') { |
| 837 | return resolveRecursive.call(this, root, refVal, p); |
| 838 | } else if (refVal instanceof SchemaObject) { |
| 839 | if (!refVal.validate) this._compile(refVal); |
| 840 | root = refVal; |
| 841 | } else { |
| 842 | refVal = this._schemas[id]; |
| 843 | if (refVal instanceof SchemaObject) { |
| 844 | if (!refVal.validate) this._compile(refVal); |
| 845 | if (id == normalizeId(ref)) |
| 846 | return { schema: refVal, root: root, baseId: baseId }; |
| 847 | root = refVal; |
| 848 | } else { |
| 849 | return; |
| 850 | } |
| 851 | } |
| 852 | if (!root.schema) return; |
| 853 | baseId = getFullPath(this._getId(root.schema)); |
| 854 | } |
| 855 | return getJsonPointer.call(this, p, baseId, root.schema, root); |
| 856 | } |
| 857 | |
| 858 | |
| 859 | /* @this Ajv */ |
| 860 | function resolveRecursive(root, ref, parsedRef) { |
| 861 | /* jshint validthis: true */ |
| 862 | var res = resolveSchema.call(this, root, ref); |
| 863 | if (res) { |
| 864 | var schema = res.schema; |
| 865 | var baseId = res.baseId; |
| 866 | root = res.root; |
| 867 | var id = this._getId(schema); |
| 868 | if (id) baseId = resolveUrl(baseId, id); |
| 869 | return getJsonPointer.call(this, parsedRef, baseId, schema, root); |
| 870 | } |
| 871 | } |
| 872 | |
| 873 | |
| 874 | var PREVENT_SCOPE_CHANGE = util.toHash(['properties', 'patternProperties', 'enum', 'dependencies', 'definitions']); |
| 875 | /* @this Ajv */ |
| 876 | function getJsonPointer(parsedRef, baseId, schema, root) { |
| 877 | /* jshint validthis: true */ |
| 878 | parsedRef.hash = parsedRef.hash || ''; |
| 879 | if (parsedRef.hash.slice(0,2) != '#/') return; |
| 880 | var parts = parsedRef.hash.split('/'); |
| 881 | |
| 882 | for (var i = 1; i < parts.length; i++) { |
| 883 | var part = parts[i]; |
| 884 | if (part) { |
| 885 | part = util.unescapeFragment(part); |
| 886 | schema = schema[part]; |
| 887 | if (schema === undefined) break; |
| 888 | var id; |
| 889 | if (!PREVENT_SCOPE_CHANGE[part]) { |
| 890 | id = this._getId(schema); |
| 891 | if (id) baseId = resolveUrl(baseId, id); |
| 892 | if (schema.$ref) { |
| 893 | var $ref = resolveUrl(baseId, schema.$ref); |
| 894 | var res = resolveSchema.call(this, root, $ref); |
| 895 | if (res) { |
| 896 | schema = res.schema; |
| 897 | root = res.root; |
| 898 | baseId = res.baseId; |
| 899 | } |
| 900 | } |
| 901 | } |
| 902 | } |
| 903 | } |
| 904 | if (schema !== undefined && schema !== root.schema) |
| 905 | return { schema: schema, root: root, baseId: baseId }; |
| 906 | } |
| 907 | |
| 908 | |
| 909 | var SIMPLE_INLINED = util.toHash([ |
| 910 | 'type', 'format', 'pattern', |
| 911 | 'maxLength', 'minLength', |
| 912 | 'maxProperties', 'minProperties', |
| 913 | 'maxItems', 'minItems', |
| 914 | 'maximum', 'minimum', |
| 915 | 'uniqueItems', 'multipleOf', |
| 916 | 'required', 'enum' |
| 917 | ]); |
| 918 | function inlineRef(schema, limit) { |
| 919 | if (limit === false) return false; |
| 920 | if (limit === undefined || limit === true) return checkNoRef(schema); |
| 921 | else if (limit) return countKeys(schema) <= limit; |
| 922 | } |
| 923 | |
| 924 | |
| 925 | function checkNoRef(schema) { |
| 926 | var item; |
| 927 | if (Array.isArray(schema)) { |
| 928 | for (var i=0; i<schema.length; i++) { |
| 929 | item = schema[i]; |
| 930 | if (typeof item == 'object' && !checkNoRef(item)) return false; |
| 931 | } |
| 932 | } else { |
| 933 | for (var key in schema) { |
| 934 | if (key == '$ref') return false; |
| 935 | item = schema[key]; |
| 936 | if (typeof item == 'object' && !checkNoRef(item)) return false; |
| 937 | } |
| 938 | } |
| 939 | return true; |
| 940 | } |
| 941 | |
| 942 | |
| 943 | function countKeys(schema) { |
| 944 | var count = 0, item; |
| 945 | if (Array.isArray(schema)) { |
| 946 | for (var i=0; i<schema.length; i++) { |
| 947 | item = schema[i]; |
| 948 | if (typeof item == 'object') count += countKeys(item); |
| 949 | if (count == Infinity) return Infinity; |
| 950 | } |
| 951 | } else { |
| 952 | for (var key in schema) { |
| 953 | if (key == '$ref') return Infinity; |
| 954 | if (SIMPLE_INLINED[key]) { |
| 955 | count++; |
| 956 | } else { |
| 957 | item = schema[key]; |
| 958 | if (typeof item == 'object') count += countKeys(item) + 1; |
| 959 | if (count == Infinity) return Infinity; |
| 960 | } |
| 961 | } |
| 962 | } |
| 963 | return count; |
| 964 | } |
| 965 | |
| 966 | |
| 967 | function getFullPath(id, normalize) { |
| 968 | if (normalize !== false) id = normalizeId(id); |
| 969 | var p = url.parse(id, false, true); |
| 970 | return _getFullPath(p); |
| 971 | } |
| 972 | |
| 973 | |
| 974 | function _getFullPath(p) { |
| 975 | var protocolSeparator = p.protocol || p.href.slice(0,2) == '//' ? '//' : ''; |
| 976 | return (p.protocol||'') + protocolSeparator + (p.host||'') + (p.path||'') + '#'; |
| 977 | } |
| 978 | |
| 979 | |
| 980 | var TRAILING_SLASH_HASH = /#\/?$/; |
| 981 | function normalizeId(id) { |
| 982 | return id ? id.replace(TRAILING_SLASH_HASH, '') : ''; |
| 983 | } |
| 984 | |
| 985 | |
| 986 | function resolveUrl(baseId, id) { |
| 987 | id = normalizeId(id); |
| 988 | return url.resolve(baseId, id); |
| 989 | } |
| 990 | |
| 991 | |
| 992 | /* @this Ajv */ |
| 993 | function resolveIds(schema) { |
| 994 | var schemaId = normalizeId(this._getId(schema)); |
| 995 | var baseIds = {'': schemaId}; |
| 996 | var fullPaths = {'': getFullPath(schemaId, false)}; |
| 997 | var localRefs = {}; |
| 998 | var self = this; |
| 999 | |
| 1000 | traverse(schema, {allKeys: true}, function(sch, jsonPtr, rootSchema, parentJsonPtr, parentKeyword, parentSchema, keyIndex) { |
| 1001 | if (jsonPtr === '') return; |
| 1002 | var id = self._getId(sch); |
| 1003 | var baseId = baseIds[parentJsonPtr]; |
| 1004 | var fullPath = fullPaths[parentJsonPtr] + '/' + parentKeyword; |
| 1005 | if (keyIndex !== undefined) |
| 1006 | fullPath += '/' + (typeof keyIndex == 'number' ? keyIndex : util.escapeFragment(keyIndex)); |
| 1007 | |
| 1008 | if (typeof id == 'string') { |
| 1009 | id = baseId = normalizeId(baseId ? url.resolve(baseId, id) : id); |
| 1010 | |
| 1011 | var refVal = self._refs[id]; |
| 1012 | if (typeof refVal == 'string') refVal = self._refs[refVal]; |
| 1013 | if (refVal && refVal.schema) { |
| 1014 | if (!equal(sch, refVal.schema)) |
| 1015 | throw new Error('id "' + id + '" resolves to more than one schema'); |
| 1016 | } else if (id != normalizeId(fullPath)) { |
| 1017 | if (id[0] == '#') { |
| 1018 | if (localRefs[id] && !equal(sch, localRefs[id])) |
| 1019 | throw new Error('id "' + id + '" resolves to more than one schema'); |
| 1020 | localRefs[id] = sch; |
| 1021 | } else { |
| 1022 | self._refs[id] = fullPath; |
| 1023 | } |
| 1024 | } |
| 1025 | } |
| 1026 | baseIds[jsonPtr] = baseId; |
| 1027 | fullPaths[jsonPtr] = fullPath; |
| 1028 | }); |
| 1029 | |
| 1030 | return localRefs; |
| 1031 | } |
| 1032 | |
| 1033 | },{"./schema_obj":10,"./util":12,"fast-deep-equal":41,"json-schema-traverse":43,"url":48}],9:[function(require,module,exports){ |
| 1034 | 'use strict'; |
| 1035 | |
| 1036 | var ruleModules = require('./_rules') |
| 1037 | , toHash = require('./util').toHash; |
| 1038 | |
| 1039 | module.exports = function rules() { |
| 1040 | var RULES = [ |
| 1041 | { type: 'number', |
| 1042 | rules: [ { 'maximum': ['exclusiveMaximum'] }, |
| 1043 | { 'minimum': ['exclusiveMinimum'] }, 'multipleOf', 'format'] }, |
| 1044 | { type: 'string', |
| 1045 | rules: [ 'maxLength', 'minLength', 'pattern', 'format' ] }, |
| 1046 | { type: 'array', |
| 1047 | rules: [ 'maxItems', 'minItems', 'uniqueItems', 'contains', 'items' ] }, |
| 1048 | { type: 'object', |
| 1049 | rules: [ 'maxProperties', 'minProperties', 'required', 'dependencies', 'propertyNames', |
| 1050 | { 'properties': ['additionalProperties', 'patternProperties'] } ] }, |
| 1051 | { rules: [ '$ref', 'const', 'enum', 'not', 'anyOf', 'oneOf', 'allOf' ] } |
| 1052 | ]; |
| 1053 | |
| 1054 | var ALL = [ 'type' ]; |
| 1055 | var KEYWORDS = [ |
| 1056 | 'additionalItems', '$schema', '$id', 'id', 'title', |
| 1057 | 'description', 'default', 'definitions' |
| 1058 | ]; |
| 1059 | var TYPES = [ 'number', 'integer', 'string', 'array', 'object', 'boolean', 'null' ]; |
| 1060 | RULES.all = toHash(ALL); |
| 1061 | RULES.types = toHash(TYPES); |
| 1062 | |
| 1063 | RULES.forEach(function (group) { |
| 1064 | group.rules = group.rules.map(function (keyword) { |
| 1065 | var implKeywords; |
| 1066 | if (typeof keyword == 'object') { |
| 1067 | var key = Object.keys(keyword)[0]; |
| 1068 | implKeywords = keyword[key]; |
| 1069 | keyword = key; |
| 1070 | implKeywords.forEach(function (k) { |
| 1071 | ALL.push(k); |
| 1072 | RULES.all[k] = true; |
| 1073 | }); |
| 1074 | } |
| 1075 | ALL.push(keyword); |
| 1076 | var rule = RULES.all[keyword] = { |
| 1077 | keyword: keyword, |
| 1078 | code: ruleModules[keyword], |
| 1079 | implements: implKeywords |
| 1080 | }; |
| 1081 | return rule; |
| 1082 | }); |
| 1083 | |
| 1084 | if (group.type) RULES.types[group.type] = group; |
| 1085 | }); |
| 1086 | |
| 1087 | RULES.keywords = toHash(ALL.concat(KEYWORDS)); |
| 1088 | RULES.custom = {}; |
| 1089 | |
| 1090 | return RULES; |
| 1091 | }; |
| 1092 | |
| 1093 | },{"./_rules":3,"./util":12}],10:[function(require,module,exports){ |
| 1094 | 'use strict'; |
| 1095 | |
| 1096 | var util = require('./util'); |
| 1097 | |
| 1098 | module.exports = SchemaObject; |
| 1099 | |
| 1100 | function SchemaObject(obj) { |
| 1101 | util.copy(obj, this); |
| 1102 | } |
| 1103 | |
| 1104 | },{"./util":12}],11:[function(require,module,exports){ |
| 1105 | 'use strict'; |
| 1106 | |
| 1107 | // https://mathiasbynens.be/notes/javascript-encoding |
| 1108 | // https://github.com/bestiejs/punycode.js - punycode.ucs2.decode |
| 1109 | module.exports = function ucs2length(str) { |
| 1110 | var length = 0 |
| 1111 | , len = str.length |
| 1112 | , pos = 0 |
| 1113 | , value; |
| 1114 | while (pos < len) { |
| 1115 | length++; |
| 1116 | value = str.charCodeAt(pos++); |
| 1117 | if (value >= 0xD800 && value <= 0xDBFF && pos < len) { |
| 1118 | // high surrogate, and there is a next character |
| 1119 | value = str.charCodeAt(pos); |
| 1120 | if ((value & 0xFC00) == 0xDC00) pos++; // low surrogate |
| 1121 | } |
| 1122 | } |
| 1123 | return length; |
| 1124 | }; |
| 1125 | |
| 1126 | },{}],12:[function(require,module,exports){ |
| 1127 | 'use strict'; |
| 1128 | |
| 1129 | |
| 1130 | module.exports = { |
| 1131 | copy: copy, |
| 1132 | checkDataType: checkDataType, |
| 1133 | checkDataTypes: checkDataTypes, |
| 1134 | coerceToTypes: coerceToTypes, |
| 1135 | toHash: toHash, |
| 1136 | getProperty: getProperty, |
| 1137 | escapeQuotes: escapeQuotes, |
| 1138 | equal: require('fast-deep-equal'), |
| 1139 | ucs2length: require('./ucs2length'), |
| 1140 | varOccurences: varOccurences, |
| 1141 | varReplace: varReplace, |
| 1142 | cleanUpCode: cleanUpCode, |
| 1143 | finalCleanUpCode: finalCleanUpCode, |
| 1144 | schemaHasRules: schemaHasRules, |
| 1145 | schemaHasRulesExcept: schemaHasRulesExcept, |
| 1146 | toQuotedString: toQuotedString, |
| 1147 | getPathExpr: getPathExpr, |
| 1148 | getPath: getPath, |
| 1149 | getData: getData, |
| 1150 | unescapeFragment: unescapeFragment, |
| 1151 | unescapeJsonPointer: unescapeJsonPointer, |
| 1152 | escapeFragment: escapeFragment, |
| 1153 | escapeJsonPointer: escapeJsonPointer |
| 1154 | }; |
| 1155 | |
| 1156 | |
| 1157 | function copy(o, to) { |
| 1158 | to = to || {}; |
| 1159 | for (var key in o) to[key] = o[key]; |
| 1160 | return to; |
| 1161 | } |
| 1162 | |
| 1163 | |
| 1164 | function checkDataType(dataType, data, negate) { |
| 1165 | var EQUAL = negate ? ' !== ' : ' === ' |
| 1166 | , AND = negate ? ' || ' : ' && ' |
| 1167 | , OK = negate ? '!' : '' |
| 1168 | , NOT = negate ? '' : '!'; |
| 1169 | switch (dataType) { |
| 1170 | case 'null': return data + EQUAL + 'null'; |
| 1171 | case 'array': return OK + 'Array.isArray(' + data + ')'; |
| 1172 | case 'object': return '(' + OK + data + AND + |
| 1173 | 'typeof ' + data + EQUAL + '"object"' + AND + |
| 1174 | NOT + 'Array.isArray(' + data + '))'; |
| 1175 | case 'integer': return '(typeof ' + data + EQUAL + '"number"' + AND + |
| 1176 | NOT + '(' + data + ' % 1)' + |
| 1177 | AND + data + EQUAL + data + ')'; |
| 1178 | default: return 'typeof ' + data + EQUAL + '"' + dataType + '"'; |
| 1179 | } |
| 1180 | } |
| 1181 | |
| 1182 | |
| 1183 | function checkDataTypes(dataTypes, data) { |
| 1184 | switch (dataTypes.length) { |
| 1185 | case 1: return checkDataType(dataTypes[0], data, true); |
| 1186 | default: |
| 1187 | var code = ''; |
| 1188 | var types = toHash(dataTypes); |
| 1189 | if (types.array && types.object) { |
| 1190 | code = types.null ? '(': '(!' + data + ' || '; |
| 1191 | code += 'typeof ' + data + ' !== "object")'; |
| 1192 | delete types.null; |
| 1193 | delete types.array; |
| 1194 | delete types.object; |
| 1195 | } |
| 1196 | if (types.number) delete types.integer; |
| 1197 | for (var t in types) |
| 1198 | code += (code ? ' && ' : '' ) + checkDataType(t, data, true); |
| 1199 | |
| 1200 | return code; |
| 1201 | } |
| 1202 | } |
| 1203 | |
| 1204 | |
| 1205 | var COERCE_TO_TYPES = toHash([ 'string', 'number', 'integer', 'boolean', 'null' ]); |
| 1206 | function coerceToTypes(optionCoerceTypes, dataTypes) { |
| 1207 | if (Array.isArray(dataTypes)) { |
| 1208 | var types = []; |
| 1209 | for (var i=0; i<dataTypes.length; i++) { |
| 1210 | var t = dataTypes[i]; |
| 1211 | if (COERCE_TO_TYPES[t]) types[types.length] = t; |
| 1212 | else if (optionCoerceTypes === 'array' && t === 'array') types[types.length] = t; |
| 1213 | } |
| 1214 | if (types.length) return types; |
| 1215 | } else if (COERCE_TO_TYPES[dataTypes]) { |
| 1216 | return [dataTypes]; |
| 1217 | } else if (optionCoerceTypes === 'array' && dataTypes === 'array') { |
| 1218 | return ['array']; |
| 1219 | } |
| 1220 | } |
| 1221 | |
| 1222 | |
| 1223 | function toHash(arr) { |
| 1224 | var hash = {}; |
| 1225 | for (var i=0; i<arr.length; i++) hash[arr[i]] = true; |
| 1226 | return hash; |
| 1227 | } |
| 1228 | |
| 1229 | |
| 1230 | var IDENTIFIER = /^[a-z$_][a-z$_0-9]*$/i; |
| 1231 | var SINGLE_QUOTE = /'|\\/g; |
| 1232 | function getProperty(key) { |
| 1233 | return typeof key == 'number' |
| 1234 | ? '[' + key + ']' |
| 1235 | : IDENTIFIER.test(key) |
| 1236 | ? '.' + key |
| 1237 | : "['" + escapeQuotes(key) + "']"; |
| 1238 | } |
| 1239 | |
| 1240 | |
| 1241 | function escapeQuotes(str) { |
| 1242 | return str.replace(SINGLE_QUOTE, '\\$&') |
| 1243 | .replace(/\n/g, '\\n') |
| 1244 | .replace(/\r/g, '\\r') |
| 1245 | .replace(/\f/g, '\\f') |
| 1246 | .replace(/\t/g, '\\t'); |
| 1247 | } |
| 1248 | |
| 1249 | |
| 1250 | function varOccurences(str, dataVar) { |
| 1251 | dataVar += '[^0-9]'; |
| 1252 | var matches = str.match(new RegExp(dataVar, 'g')); |
| 1253 | return matches ? matches.length : 0; |
| 1254 | } |
| 1255 | |
| 1256 | |
| 1257 | function varReplace(str, dataVar, expr) { |
| 1258 | dataVar += '([^0-9])'; |
| 1259 | expr = expr.replace(/\$/g, '$$$$'); |
| 1260 | return str.replace(new RegExp(dataVar, 'g'), expr + '$1'); |
| 1261 | } |
| 1262 | |
| 1263 | |
| 1264 | var EMPTY_ELSE = /else\s*{\s*}/g |
| 1265 | , EMPTY_IF_NO_ELSE = /if\s*\([^)]+\)\s*\{\s*\}(?!\s*else)/g |
| 1266 | , EMPTY_IF_WITH_ELSE = /if\s*\(([^)]+)\)\s*\{\s*\}\s*else(?!\s*if)/g; |
| 1267 | function cleanUpCode(out) { |
| 1268 | return out.replace(EMPTY_ELSE, '') |
| 1269 | .replace(EMPTY_IF_NO_ELSE, '') |
| 1270 | .replace(EMPTY_IF_WITH_ELSE, 'if (!($1))'); |
| 1271 | } |
| 1272 | |
| 1273 | |
| 1274 | var ERRORS_REGEXP = /[^v.]errors/g |
| 1275 | , REMOVE_ERRORS = /var errors = 0;|var vErrors = null;|validate.errors = vErrors;/g |
| 1276 | , REMOVE_ERRORS_ASYNC = /var errors = 0;|var vErrors = null;/g |
| 1277 | , RETURN_VALID = 'return errors === 0;' |
| 1278 | , RETURN_TRUE = 'validate.errors = null; return true;' |
| 1279 | , RETURN_ASYNC = /if \(errors === 0\) return data;\s*else throw new ValidationError\(vErrors\);/ |
| 1280 | , RETURN_DATA_ASYNC = 'return data;' |
| 1281 | , ROOTDATA_REGEXP = /[^A-Za-z_$]rootData[^A-Za-z0-9_$]/g |
| 1282 | , REMOVE_ROOTDATA = /if \(rootData === undefined\) rootData = data;/; |
| 1283 | |
| 1284 | function finalCleanUpCode(out, async) { |
| 1285 | var matches = out.match(ERRORS_REGEXP); |
| 1286 | if (matches && matches.length == 2) { |
| 1287 | out = async |
| 1288 | ? out.replace(REMOVE_ERRORS_ASYNC, '') |
| 1289 | .replace(RETURN_ASYNC, RETURN_DATA_ASYNC) |
| 1290 | : out.replace(REMOVE_ERRORS, '') |
| 1291 | .replace(RETURN_VALID, RETURN_TRUE); |
| 1292 | } |
| 1293 | |
| 1294 | matches = out.match(ROOTDATA_REGEXP); |
| 1295 | if (!matches || matches.length !== 3) return out; |
| 1296 | return out.replace(REMOVE_ROOTDATA, ''); |
| 1297 | } |
| 1298 | |
| 1299 | |
| 1300 | function schemaHasRules(schema, rules) { |
| 1301 | if (typeof schema == 'boolean') return !schema; |
| 1302 | for (var key in schema) if (rules[key]) return true; |
| 1303 | } |
| 1304 | |
| 1305 | |
| 1306 | function schemaHasRulesExcept(schema, rules, exceptKeyword) { |
| 1307 | if (typeof schema == 'boolean') return !schema && exceptKeyword != 'not'; |
| 1308 | for (var key in schema) if (key != exceptKeyword && rules[key]) return true; |
| 1309 | } |
| 1310 | |
| 1311 | |
| 1312 | function toQuotedString(str) { |
| 1313 | return '\'' + escapeQuotes(str) + '\''; |
| 1314 | } |
| 1315 | |
| 1316 | |
| 1317 | function getPathExpr(currentPath, expr, jsonPointers, isNumber) { |
| 1318 | var path = jsonPointers // false by default |
| 1319 | ? '\'/\' + ' + expr + (isNumber ? '' : '.replace(/~/g, \'~0\').replace(/\\//g, \'~1\')') |
| 1320 | : (isNumber ? '\'[\' + ' + expr + ' + \']\'' : '\'[\\\'\' + ' + expr + ' + \'\\\']\''); |
| 1321 | return joinPaths(currentPath, path); |
| 1322 | } |
| 1323 | |
| 1324 | |
| 1325 | function getPath(currentPath, prop, jsonPointers) { |
| 1326 | var path = jsonPointers // false by default |
| 1327 | ? toQuotedString('/' + escapeJsonPointer(prop)) |
| 1328 | : toQuotedString(getProperty(prop)); |
| 1329 | return joinPaths(currentPath, path); |
| 1330 | } |
| 1331 | |
| 1332 | |
| 1333 | var JSON_POINTER = /^\/(?:[^~]|~0|~1)*$/; |
| 1334 | var RELATIVE_JSON_POINTER = /^([0-9]+)(#|\/(?:[^~]|~0|~1)*)?$/; |
| 1335 | function getData($data, lvl, paths) { |
| 1336 | var up, jsonPointer, data, matches; |
| 1337 | if ($data === '') return 'rootData'; |
| 1338 | if ($data[0] == '/') { |
| 1339 | if (!JSON_POINTER.test($data)) throw new Error('Invalid JSON-pointer: ' + $data); |
| 1340 | jsonPointer = $data; |
| 1341 | data = 'rootData'; |
| 1342 | } else { |
| 1343 | matches = $data.match(RELATIVE_JSON_POINTER); |
| 1344 | if (!matches) throw new Error('Invalid JSON-pointer: ' + $data); |
| 1345 | up = +matches[1]; |
| 1346 | jsonPointer = matches[2]; |
| 1347 | if (jsonPointer == '#') { |
| 1348 | if (up >= lvl) throw new Error('Cannot access property/index ' + up + ' levels up, current level is ' + lvl); |
| 1349 | return paths[lvl - up]; |
| 1350 | } |
| 1351 | |
| 1352 | if (up > lvl) throw new Error('Cannot access data ' + up + ' levels up, current level is ' + lvl); |
| 1353 | data = 'data' + ((lvl - up) || ''); |
| 1354 | if (!jsonPointer) return data; |
| 1355 | } |
| 1356 | |
| 1357 | var expr = data; |
| 1358 | var segments = jsonPointer.split('/'); |
| 1359 | for (var i=0; i<segments.length; i++) { |
| 1360 | var segment = segments[i]; |
| 1361 | if (segment) { |
| 1362 | data += getProperty(unescapeJsonPointer(segment)); |
| 1363 | expr += ' && ' + data; |
| 1364 | } |
| 1365 | } |
| 1366 | return expr; |
| 1367 | } |
| 1368 | |
| 1369 | |
| 1370 | function joinPaths (a, b) { |
| 1371 | if (a == '""') return b; |
| 1372 | return (a + ' + ' + b).replace(/' \+ '/g, ''); |
| 1373 | } |
| 1374 | |
| 1375 | |
| 1376 | function unescapeFragment(str) { |
| 1377 | return unescapeJsonPointer(decodeURIComponent(str)); |
| 1378 | } |
| 1379 | |
| 1380 | |
| 1381 | function escapeFragment(str) { |
| 1382 | return encodeURIComponent(escapeJsonPointer(str)); |
| 1383 | } |
| 1384 | |
| 1385 | |
| 1386 | function escapeJsonPointer(str) { |
| 1387 | return str.replace(/~/g, '~0').replace(/\//g, '~1'); |
| 1388 | } |
| 1389 | |
| 1390 | |
| 1391 | function unescapeJsonPointer(str) { |
| 1392 | return str.replace(/~1/g, '/').replace(/~0/g, '~'); |
| 1393 | } |
| 1394 | |
| 1395 | },{"./ucs2length":11,"fast-deep-equal":41}],13:[function(require,module,exports){ |
| 1396 | 'use strict'; |
| 1397 | module.exports = function generate__limit(it, $keyword, $ruleType) { |
| 1398 | var out = ' '; |
| 1399 | var $lvl = it.level; |
| 1400 | var $dataLvl = it.dataLevel; |
| 1401 | var $schema = it.schema[$keyword]; |
| 1402 | var $schemaPath = it.schemaPath + it.util.getProperty($keyword); |
| 1403 | var $errSchemaPath = it.errSchemaPath + '/' + $keyword; |
| 1404 | var $breakOnError = !it.opts.allErrors; |
| 1405 | var $errorKeyword; |
| 1406 | var $data = 'data' + ($dataLvl || ''); |
| 1407 | var $isData = it.opts.$data && $schema && $schema.$data, |
| 1408 | $schemaValue; |
| 1409 | if ($isData) { |
| 1410 | out += ' var schema' + ($lvl) + ' = ' + (it.util.getData($schema.$data, $dataLvl, it.dataPathArr)) + '; '; |
| 1411 | $schemaValue = 'schema' + $lvl; |
| 1412 | } else { |
| 1413 | $schemaValue = $schema; |
| 1414 | } |
| 1415 | var $isMax = $keyword == 'maximum', |
| 1416 | $exclusiveKeyword = $isMax ? 'exclusiveMaximum' : 'exclusiveMinimum', |
| 1417 | $schemaExcl = it.schema[$exclusiveKeyword], |
| 1418 | $isDataExcl = it.opts.$data && $schemaExcl && $schemaExcl.$data, |
| 1419 | $op = $isMax ? '<' : '>', |
| 1420 | $notOp = $isMax ? '>' : '<', |
| 1421 | $errorKeyword = undefined; |
| 1422 | if ($isDataExcl) { |
| 1423 | var $schemaValueExcl = it.util.getData($schemaExcl.$data, $dataLvl, it.dataPathArr), |
| 1424 | $exclusive = 'exclusive' + $lvl, |
| 1425 | $exclType = 'exclType' + $lvl, |
| 1426 | $exclIsNumber = 'exclIsNumber' + $lvl, |
| 1427 | $opExpr = 'op' + $lvl, |
| 1428 | $opStr = '\' + ' + $opExpr + ' + \''; |
| 1429 | out += ' var schemaExcl' + ($lvl) + ' = ' + ($schemaValueExcl) + '; '; |
| 1430 | $schemaValueExcl = 'schemaExcl' + $lvl; |
| 1431 | out += ' var ' + ($exclusive) + '; var ' + ($exclType) + ' = typeof ' + ($schemaValueExcl) + '; if (' + ($exclType) + ' != \'boolean\' && ' + ($exclType) + ' != \'undefined\' && ' + ($exclType) + ' != \'number\') { '; |
| 1432 | var $errorKeyword = $exclusiveKeyword; |
| 1433 | var $$outStack = $$outStack || []; |
| 1434 | $$outStack.push(out); |
| 1435 | out = ''; /* istanbul ignore else */ |
| 1436 | if (it.createErrors !== false) { |
| 1437 | out += ' { keyword: \'' + ($errorKeyword || '_exclusiveLimit') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: ' + (it.util.toQuotedString($errSchemaPath)) + ' , params: {} '; |
| 1438 | if (it.opts.messages !== false) { |
| 1439 | out += ' , message: \'' + ($exclusiveKeyword) + ' should be boolean\' '; |
| 1440 | } |
| 1441 | if (it.opts.verbose) { |
| 1442 | out += ' , schema: validate.schema' + ($schemaPath) + ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' '; |
| 1443 | } |
| 1444 | out += ' } '; |
| 1445 | } else { |
| 1446 | out += ' {} '; |
| 1447 | } |
| 1448 | var __err = out; |
| 1449 | out = $$outStack.pop(); |
| 1450 | if (!it.compositeRule && $breakOnError) { /* istanbul ignore if */ |
| 1451 | if (it.async) { |
| 1452 | out += ' throw new ValidationError([' + (__err) + ']); '; |
| 1453 | } else { |
| 1454 | out += ' validate.errors = [' + (__err) + ']; return false; '; |
| 1455 | } |
| 1456 | } else { |
| 1457 | out += ' var err = ' + (__err) + '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; '; |
| 1458 | } |
| 1459 | out += ' } else if ( '; |
| 1460 | if ($isData) { |
| 1461 | out += ' (' + ($schemaValue) + ' !== undefined && typeof ' + ($schemaValue) + ' != \'number\') || '; |
| 1462 | } |
| 1463 | 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) + '=\';'; |
| 1464 | } else { |
| 1465 | var $exclIsNumber = typeof $schemaExcl == 'number', |
| 1466 | $opStr = $op; |
| 1467 | if ($exclIsNumber && $isData) { |
| 1468 | var $opExpr = '\'' + $opStr + '\''; |
| 1469 | out += ' if ( '; |
| 1470 | if ($isData) { |
| 1471 | out += ' (' + ($schemaValue) + ' !== undefined && typeof ' + ($schemaValue) + ' != \'number\') || '; |
| 1472 | } |
| 1473 | out += ' ( ' + ($schemaValue) + ' === undefined || ' + ($schemaExcl) + ' ' + ($op) + '= ' + ($schemaValue) + ' ? ' + ($data) + ' ' + ($notOp) + '= ' + ($schemaExcl) + ' : ' + ($data) + ' ' + ($notOp) + ' ' + ($schemaValue) + ' ) || ' + ($data) + ' !== ' + ($data) + ') { '; |
| 1474 | } else { |
| 1475 | if ($exclIsNumber && $schema === undefined) { |
| 1476 | $exclusive = true; |
| 1477 | $errorKeyword = $exclusiveKeyword; |
| 1478 | $errSchemaPath = it.errSchemaPath + '/' + $exclusiveKeyword; |
| 1479 | $schemaValue = $schemaExcl; |
| 1480 | $notOp += '='; |
| 1481 | } else { |
| 1482 | if ($exclIsNumber) $schemaValue = Math[$isMax ? 'min' : 'max']($schemaExcl, $schema); |
| 1483 | if ($schemaExcl === ($exclIsNumber ? $schemaValue : true)) { |
| 1484 | $exclusive = true; |
| 1485 | $errorKeyword = $exclusiveKeyword; |
| 1486 | $errSchemaPath = it.errSchemaPath + '/' + $exclusiveKeyword; |
| 1487 | $notOp += '='; |
| 1488 | } else { |
| 1489 | $exclusive = false; |
| 1490 | $opStr += '='; |
| 1491 | } |
| 1492 | } |
| 1493 | var $opExpr = '\'' + $opStr + '\''; |
| 1494 | out += ' if ( '; |
| 1495 | if ($isData) { |
| 1496 | out += ' (' + ($schemaValue) + ' !== undefined && typeof ' + ($schemaValue) + ' != \'number\') || '; |
| 1497 | } |
| 1498 | out += ' ' + ($data) + ' ' + ($notOp) + ' ' + ($schemaValue) + ' || ' + ($data) + ' !== ' + ($data) + ') { '; |
| 1499 | } |
| 1500 | } |
| 1501 | $errorKeyword = $errorKeyword || $keyword; |
| 1502 | var $$outStack = $$outStack || []; |
| 1503 | $$outStack.push(out); |
| 1504 | out = ''; /* istanbul ignore else */ |
| 1505 | if (it.createErrors !== false) { |
| 1506 | out += ' { keyword: \'' + ($errorKeyword || '_limit') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: ' + (it.util.toQuotedString($errSchemaPath)) + ' , params: { comparison: ' + ($opExpr) + ', limit: ' + ($schemaValue) + ', exclusive: ' + ($exclusive) + ' } '; |
| 1507 | if (it.opts.messages !== false) { |
| 1508 | out += ' , message: \'should be ' + ($opStr) + ' '; |
| 1509 | if ($isData) { |
| 1510 | out += '\' + ' + ($schemaValue); |
| 1511 | } else { |
| 1512 | out += '' + ($schemaValue) + '\''; |
| 1513 | } |
| 1514 | } |
| 1515 | if (it.opts.verbose) { |
| 1516 | out += ' , schema: '; |
| 1517 | if ($isData) { |
| 1518 | out += 'validate.schema' + ($schemaPath); |
| 1519 | } else { |
| 1520 | out += '' + ($schema); |
| 1521 | } |
| 1522 | out += ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' '; |
| 1523 | } |
| 1524 | out += ' } '; |
| 1525 | } else { |
| 1526 | out += ' {} '; |
| 1527 | } |
| 1528 | var __err = out; |
| 1529 | out = $$outStack.pop(); |
| 1530 | if (!it.compositeRule && $breakOnError) { /* istanbul ignore if */ |
| 1531 | if (it.async) { |
| 1532 | out += ' throw new ValidationError([' + (__err) + ']); '; |
| 1533 | } else { |
| 1534 | out += ' validate.errors = [' + (__err) + ']; return false; '; |
| 1535 | } |
| 1536 | } else { |
| 1537 | out += ' var err = ' + (__err) + '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; '; |
| 1538 | } |
| 1539 | out += ' } '; |
| 1540 | if ($breakOnError) { |
| 1541 | out += ' else { '; |
| 1542 | } |
| 1543 | return out; |
| 1544 | } |
| 1545 | |
| 1546 | },{}],14:[function(require,module,exports){ |
| 1547 | 'use strict'; |
| 1548 | module.exports = function generate__limitItems(it, $keyword, $ruleType) { |
| 1549 | var out = ' '; |
| 1550 | var $lvl = it.level; |
| 1551 | var $dataLvl = it.dataLevel; |
| 1552 | var $schema = it.schema[$keyword]; |
| 1553 | var $schemaPath = it.schemaPath + it.util.getProperty($keyword); |
| 1554 | var $errSchemaPath = it.errSchemaPath + '/' + $keyword; |
| 1555 | var $breakOnError = !it.opts.allErrors; |
| 1556 | var $errorKeyword; |
| 1557 | var $data = 'data' + ($dataLvl || ''); |
| 1558 | var $isData = it.opts.$data && $schema && $schema.$data, |
| 1559 | $schemaValue; |
| 1560 | if ($isData) { |
| 1561 | out += ' var schema' + ($lvl) + ' = ' + (it.util.getData($schema.$data, $dataLvl, it.dataPathArr)) + '; '; |
| 1562 | $schemaValue = 'schema' + $lvl; |
| 1563 | } else { |
| 1564 | $schemaValue = $schema; |
| 1565 | } |
| 1566 | var $op = $keyword == 'maxItems' ? '>' : '<'; |
| 1567 | out += 'if ( '; |
| 1568 | if ($isData) { |
| 1569 | out += ' (' + ($schemaValue) + ' !== undefined && typeof ' + ($schemaValue) + ' != \'number\') || '; |
| 1570 | } |
| 1571 | out += ' ' + ($data) + '.length ' + ($op) + ' ' + ($schemaValue) + ') { '; |
| 1572 | var $errorKeyword = $keyword; |
| 1573 | var $$outStack = $$outStack || []; |
| 1574 | $$outStack.push(out); |
| 1575 | out = ''; /* istanbul ignore else */ |
| 1576 | if (it.createErrors !== false) { |
| 1577 | out += ' { keyword: \'' + ($errorKeyword || '_limitItems') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: ' + (it.util.toQuotedString($errSchemaPath)) + ' , params: { limit: ' + ($schemaValue) + ' } '; |
| 1578 | if (it.opts.messages !== false) { |
| 1579 | out += ' , message: \'should NOT have '; |
| 1580 | if ($keyword == 'maxItems') { |
| 1581 | out += 'more'; |
| 1582 | } else { |
| 1583 | out += 'less'; |
| 1584 | } |
| 1585 | out += ' than '; |
| 1586 | if ($isData) { |
| 1587 | out += '\' + ' + ($schemaValue) + ' + \''; |
| 1588 | } else { |
| 1589 | out += '' + ($schema); |
| 1590 | } |
| 1591 | out += ' items\' '; |
| 1592 | } |
| 1593 | if (it.opts.verbose) { |
| 1594 | out += ' , schema: '; |
| 1595 | if ($isData) { |
| 1596 | out += 'validate.schema' + ($schemaPath); |
| 1597 | } else { |
| 1598 | out += '' + ($schema); |
| 1599 | } |
| 1600 | out += ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' '; |
| 1601 | } |
| 1602 | out += ' } '; |
| 1603 | } else { |
| 1604 | out += ' {} '; |
| 1605 | } |
| 1606 | var __err = out; |
| 1607 | out = $$outStack.pop(); |
| 1608 | if (!it.compositeRule && $breakOnError) { /* istanbul ignore if */ |
| 1609 | if (it.async) { |
| 1610 | out += ' throw new ValidationError([' + (__err) + ']); '; |
| 1611 | } else { |
| 1612 | out += ' validate.errors = [' + (__err) + ']; return false; '; |
| 1613 | } |
| 1614 | } else { |
| 1615 | out += ' var err = ' + (__err) + '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; '; |
| 1616 | } |
| 1617 | out += '} '; |
| 1618 | if ($breakOnError) { |
| 1619 | out += ' else { '; |
| 1620 | } |
| 1621 | return out; |
| 1622 | } |
| 1623 | |
| 1624 | },{}],15:[function(require,module,exports){ |
| 1625 | 'use strict'; |
| 1626 | module.exports = function generate__limitLength(it, $keyword, $ruleType) { |
| 1627 | var out = ' '; |
| 1628 | var $lvl = it.level; |
| 1629 | var $dataLvl = it.dataLevel; |
| 1630 | var $schema = it.schema[$keyword]; |
| 1631 | var $schemaPath = it.schemaPath + it.util.getProperty($keyword); |
| 1632 | var $errSchemaPath = it.errSchemaPath + '/' + $keyword; |
| 1633 | var $breakOnError = !it.opts.allErrors; |
| 1634 | var $errorKeyword; |
| 1635 | var $data = 'data' + ($dataLvl || ''); |
| 1636 | var $isData = it.opts.$data && $schema && $schema.$data, |
| 1637 | $schemaValue; |
| 1638 | if ($isData) { |
| 1639 | out += ' var schema' + ($lvl) + ' = ' + (it.util.getData($schema.$data, $dataLvl, it.dataPathArr)) + '; '; |
| 1640 | $schemaValue = 'schema' + $lvl; |
| 1641 | } else { |
| 1642 | $schemaValue = $schema; |
| 1643 | } |
| 1644 | var $op = $keyword == 'maxLength' ? '>' : '<'; |
| 1645 | out += 'if ( '; |
| 1646 | if ($isData) { |
| 1647 | out += ' (' + ($schemaValue) + ' !== undefined && typeof ' + ($schemaValue) + ' != \'number\') || '; |
| 1648 | } |
| 1649 | if (it.opts.unicode === false) { |
| 1650 | out += ' ' + ($data) + '.length '; |
| 1651 | } else { |
| 1652 | out += ' ucs2length(' + ($data) + ') '; |
| 1653 | } |
| 1654 | out += ' ' + ($op) + ' ' + ($schemaValue) + ') { '; |
| 1655 | var $errorKeyword = $keyword; |
| 1656 | var $$outStack = $$outStack || []; |
| 1657 | $$outStack.push(out); |
| 1658 | out = ''; /* istanbul ignore else */ |
| 1659 | if (it.createErrors !== false) { |
| 1660 | out += ' { keyword: \'' + ($errorKeyword || '_limitLength') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: ' + (it.util.toQuotedString($errSchemaPath)) + ' , params: { limit: ' + ($schemaValue) + ' } '; |
| 1661 | if (it.opts.messages !== false) { |
| 1662 | out += ' , message: \'should NOT be '; |
| 1663 | if ($keyword == 'maxLength') { |
| 1664 | out += 'longer'; |
| 1665 | } else { |
| 1666 | out += 'shorter'; |
| 1667 | } |
| 1668 | out += ' than '; |
| 1669 | if ($isData) { |
| 1670 | out += '\' + ' + ($schemaValue) + ' + \''; |
| 1671 | } else { |
| 1672 | out += '' + ($schema); |
| 1673 | } |
| 1674 | out += ' characters\' '; |
| 1675 | } |
| 1676 | if (it.opts.verbose) { |
| 1677 | out += ' , schema: '; |
| 1678 | if ($isData) { |
| 1679 | out += 'validate.schema' + ($schemaPath); |
| 1680 | } else { |
| 1681 | out += '' + ($schema); |
| 1682 | } |
| 1683 | out += ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' '; |
| 1684 | } |
| 1685 | out += ' } '; |
| 1686 | } else { |
| 1687 | out += ' {} '; |
| 1688 | } |
| 1689 | var __err = out; |
| 1690 | out = $$outStack.pop(); |
| 1691 | if (!it.compositeRule && $breakOnError) { /* istanbul ignore if */ |
| 1692 | if (it.async) { |
| 1693 | out += ' throw new ValidationError([' + (__err) + ']); '; |
| 1694 | } else { |
| 1695 | out += ' validate.errors = [' + (__err) + ']; return false; '; |
| 1696 | } |
| 1697 | } else { |
| 1698 | out += ' var err = ' + (__err) + '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; '; |
| 1699 | } |
| 1700 | out += '} '; |
| 1701 | if ($breakOnError) { |
| 1702 | out += ' else { '; |
| 1703 | } |
| 1704 | return out; |
| 1705 | } |
| 1706 | |
| 1707 | },{}],16:[function(require,module,exports){ |
| 1708 | 'use strict'; |
| 1709 | module.exports = function generate__limitProperties(it, $keyword, $ruleType) { |
| 1710 | var out = ' '; |
| 1711 | var $lvl = it.level; |
| 1712 | var $dataLvl = it.dataLevel; |
| 1713 | var $schema = it.schema[$keyword]; |
| 1714 | var $schemaPath = it.schemaPath + it.util.getProperty($keyword); |
| 1715 | var $errSchemaPath = it.errSchemaPath + '/' + $keyword; |
| 1716 | var $breakOnError = !it.opts.allErrors; |
| 1717 | var $errorKeyword; |
| 1718 | var $data = 'data' + ($dataLvl || ''); |
| 1719 | var $isData = it.opts.$data && $schema && $schema.$data, |
| 1720 | $schemaValue; |
| 1721 | if ($isData) { |
| 1722 | out += ' var schema' + ($lvl) + ' = ' + (it.util.getData($schema.$data, $dataLvl, it.dataPathArr)) + '; '; |
| 1723 | $schemaValue = 'schema' + $lvl; |
| 1724 | } else { |
| 1725 | $schemaValue = $schema; |
| 1726 | } |
| 1727 | var $op = $keyword == 'maxProperties' ? '>' : '<'; |
| 1728 | out += 'if ( '; |
| 1729 | if ($isData) { |
| 1730 | out += ' (' + ($schemaValue) + ' !== undefined && typeof ' + ($schemaValue) + ' != \'number\') || '; |
| 1731 | } |
| 1732 | out += ' Object.keys(' + ($data) + ').length ' + ($op) + ' ' + ($schemaValue) + ') { '; |
| 1733 | var $errorKeyword = $keyword; |
| 1734 | var $$outStack = $$outStack || []; |
| 1735 | $$outStack.push(out); |
| 1736 | out = ''; /* istanbul ignore else */ |
| 1737 | if (it.createErrors !== false) { |
| 1738 | out += ' { keyword: \'' + ($errorKeyword || '_limitProperties') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: ' + (it.util.toQuotedString($errSchemaPath)) + ' , params: { limit: ' + ($schemaValue) + ' } '; |
| 1739 | if (it.opts.messages !== false) { |
| 1740 | out += ' , message: \'should NOT have '; |
| 1741 | if ($keyword == 'maxProperties') { |
| 1742 | out += 'more'; |
| 1743 | } else { |
| 1744 | out += 'less'; |
| 1745 | } |
| 1746 | out += ' than '; |
| 1747 | if ($isData) { |
| 1748 | out += '\' + ' + ($schemaValue) + ' + \''; |
| 1749 | } else { |
| 1750 | out += '' + ($schema); |
| 1751 | } |
| 1752 | out += ' properties\' '; |
| 1753 | } |
| 1754 | if (it.opts.verbose) { |
| 1755 | out += ' , schema: '; |
| 1756 | if ($isData) { |
| 1757 | out += 'validate.schema' + ($schemaPath); |
| 1758 | } else { |
| 1759 | out += '' + ($schema); |
| 1760 | } |
| 1761 | out += ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' '; |
| 1762 | } |
| 1763 | out += ' } '; |
| 1764 | } else { |
| 1765 | out += ' {} '; |
| 1766 | } |
| 1767 | var __err = out; |
| 1768 | out = $$outStack.pop(); |
| 1769 | if (!it.compositeRule && $breakOnError) { /* istanbul ignore if */ |
| 1770 | if (it.async) { |
| 1771 | out += ' throw new ValidationError([' + (__err) + ']); '; |
| 1772 | } else { |
| 1773 | out += ' validate.errors = [' + (__err) + ']; return false; '; |
| 1774 | } |
| 1775 | } else { |
| 1776 | out += ' var err = ' + (__err) + '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; '; |
| 1777 | } |
| 1778 | out += '} '; |
| 1779 | if ($breakOnError) { |
| 1780 | out += ' else { '; |
| 1781 | } |
| 1782 | return out; |
| 1783 | } |
| 1784 | |
| 1785 | },{}],17:[function(require,module,exports){ |
| 1786 | 'use strict'; |
| 1787 | module.exports = function generate_allOf(it, $keyword, $ruleType) { |
| 1788 | var out = ' '; |
| 1789 | var $schema = it.schema[$keyword]; |
| 1790 | var $schemaPath = it.schemaPath + it.util.getProperty($keyword); |
| 1791 | var $errSchemaPath = it.errSchemaPath + '/' + $keyword; |
| 1792 | var $breakOnError = !it.opts.allErrors; |
| 1793 | var $it = it.util.copy(it); |
| 1794 | var $closingBraces = ''; |
| 1795 | $it.level++; |
| 1796 | var $nextValid = 'valid' + $it.level; |
| 1797 | var $currentBaseId = $it.baseId, |
| 1798 | $allSchemasEmpty = true; |
| 1799 | var arr1 = $schema; |
| 1800 | if (arr1) { |
| 1801 | var $sch, $i = -1, |
| 1802 | l1 = arr1.length - 1; |
| 1803 | while ($i < l1) { |
| 1804 | $sch = arr1[$i += 1]; |
| 1805 | if (it.util.schemaHasRules($sch, it.RULES.all)) { |
| 1806 | $allSchemasEmpty = false; |
| 1807 | $it.schema = $sch; |
| 1808 | $it.schemaPath = $schemaPath + '[' + $i + ']'; |
| 1809 | $it.errSchemaPath = $errSchemaPath + '/' + $i; |
| 1810 | out += ' ' + (it.validate($it)) + ' '; |
| 1811 | $it.baseId = $currentBaseId; |
| 1812 | if ($breakOnError) { |
| 1813 | out += ' if (' + ($nextValid) + ') { '; |
| 1814 | $closingBraces += '}'; |
| 1815 | } |
| 1816 | } |
| 1817 | } |
| 1818 | } |
| 1819 | if ($breakOnError) { |
| 1820 | if ($allSchemasEmpty) { |
| 1821 | out += ' if (true) { '; |
| 1822 | } else { |
| 1823 | out += ' ' + ($closingBraces.slice(0, -1)) + ' '; |
| 1824 | } |
| 1825 | } |
| 1826 | out = it.util.cleanUpCode(out); |
| 1827 | return out; |
| 1828 | } |
| 1829 | |
| 1830 | },{}],18:[function(require,module,exports){ |
| 1831 | 'use strict'; |
| 1832 | module.exports = function generate_anyOf(it, $keyword, $ruleType) { |
| 1833 | var out = ' '; |
| 1834 | var $lvl = it.level; |
| 1835 | var $dataLvl = it.dataLevel; |
| 1836 | var $schema = it.schema[$keyword]; |
| 1837 | var $schemaPath = it.schemaPath + it.util.getProperty($keyword); |
| 1838 | var $errSchemaPath = it.errSchemaPath + '/' + $keyword; |
| 1839 | var $breakOnError = !it.opts.allErrors; |
| 1840 | var $data = 'data' + ($dataLvl || ''); |
| 1841 | var $valid = 'valid' + $lvl; |
| 1842 | var $errs = 'errs__' + $lvl; |
| 1843 | var $it = it.util.copy(it); |
| 1844 | var $closingBraces = ''; |
| 1845 | $it.level++; |
| 1846 | var $nextValid = 'valid' + $it.level; |
| 1847 | var $noEmptySchema = $schema.every(function($sch) { |
| 1848 | return it.util.schemaHasRules($sch, it.RULES.all); |
| 1849 | }); |
| 1850 | if ($noEmptySchema) { |
| 1851 | var $currentBaseId = $it.baseId; |
| 1852 | out += ' var ' + ($errs) + ' = errors; var ' + ($valid) + ' = false; '; |
| 1853 | var $wasComposite = it.compositeRule; |
| 1854 | it.compositeRule = $it.compositeRule = true; |
| 1855 | var arr1 = $schema; |
| 1856 | if (arr1) { |
| 1857 | var $sch, $i = -1, |
| 1858 | l1 = arr1.length - 1; |
| 1859 | while ($i < l1) { |
| 1860 | $sch = arr1[$i += 1]; |
| 1861 | $it.schema = $sch; |
| 1862 | $it.schemaPath = $schemaPath + '[' + $i + ']'; |
| 1863 | $it.errSchemaPath = $errSchemaPath + '/' + $i; |
| 1864 | out += ' ' + (it.validate($it)) + ' '; |
| 1865 | $it.baseId = $currentBaseId; |
| 1866 | out += ' ' + ($valid) + ' = ' + ($valid) + ' || ' + ($nextValid) + '; if (!' + ($valid) + ') { '; |
| 1867 | $closingBraces += '}'; |
| 1868 | } |
| 1869 | } |
| 1870 | it.compositeRule = $it.compositeRule = $wasComposite; |
| 1871 | out += ' ' + ($closingBraces) + ' if (!' + ($valid) + ') { var err = '; /* istanbul ignore else */ |
| 1872 | if (it.createErrors !== false) { |
| 1873 | out += ' { keyword: \'' + ('anyOf') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: ' + (it.util.toQuotedString($errSchemaPath)) + ' , params: {} '; |
| 1874 | if (it.opts.messages !== false) { |
| 1875 | out += ' , message: \'should match some schema in anyOf\' '; |
| 1876 | } |
| 1877 | if (it.opts.verbose) { |
| 1878 | out += ' , schema: validate.schema' + ($schemaPath) + ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' '; |
| 1879 | } |
| 1880 | out += ' } '; |
| 1881 | } else { |
| 1882 | out += ' {} '; |
| 1883 | } |
| 1884 | out += '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; '; |
| 1885 | if (!it.compositeRule && $breakOnError) { /* istanbul ignore if */ |
| 1886 | if (it.async) { |
| 1887 | out += ' throw new ValidationError(vErrors); '; |
| 1888 | } else { |
| 1889 | out += ' validate.errors = vErrors; return false; '; |
| 1890 | } |
| 1891 | } |
| 1892 | out += ' } else { errors = ' + ($errs) + '; if (vErrors !== null) { if (' + ($errs) + ') vErrors.length = ' + ($errs) + '; else vErrors = null; } '; |
| 1893 | if (it.opts.allErrors) { |
| 1894 | out += ' } '; |
| 1895 | } |
| 1896 | out = it.util.cleanUpCode(out); |
| 1897 | } else { |
| 1898 | if ($breakOnError) { |
| 1899 | out += ' if (true) { '; |
| 1900 | } |
| 1901 | } |
| 1902 | return out; |
| 1903 | } |
| 1904 | |
| 1905 | },{}],19:[function(require,module,exports){ |
| 1906 | 'use strict'; |
| 1907 | module.exports = function generate_const(it, $keyword, $ruleType) { |
| 1908 | var out = ' '; |
| 1909 | var $lvl = it.level; |
| 1910 | var $dataLvl = it.dataLevel; |
| 1911 | var $schema = it.schema[$keyword]; |
| 1912 | var $schemaPath = it.schemaPath + it.util.getProperty($keyword); |
| 1913 | var $errSchemaPath = it.errSchemaPath + '/' + $keyword; |
| 1914 | var $breakOnError = !it.opts.allErrors; |
| 1915 | var $data = 'data' + ($dataLvl || ''); |
| 1916 | var $valid = 'valid' + $lvl; |
| 1917 | var $isData = it.opts.$data && $schema && $schema.$data, |
| 1918 | $schemaValue; |
| 1919 | if ($isData) { |
| 1920 | out += ' var schema' + ($lvl) + ' = ' + (it.util.getData($schema.$data, $dataLvl, it.dataPathArr)) + '; '; |
| 1921 | $schemaValue = 'schema' + $lvl; |
| 1922 | } else { |
| 1923 | $schemaValue = $schema; |
| 1924 | } |
| 1925 | if (!$isData) { |
| 1926 | out += ' var schema' + ($lvl) + ' = validate.schema' + ($schemaPath) + ';'; |
| 1927 | } |
| 1928 | out += 'var ' + ($valid) + ' = equal(' + ($data) + ', schema' + ($lvl) + '); if (!' + ($valid) + ') { '; |
| 1929 | var $$outStack = $$outStack || []; |
| 1930 | $$outStack.push(out); |
| 1931 | out = ''; /* istanbul ignore else */ |
| 1932 | if (it.createErrors !== false) { |
| 1933 | out += ' { keyword: \'' + ('const') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: ' + (it.util.toQuotedString($errSchemaPath)) + ' , params: {} '; |
| 1934 | if (it.opts.messages !== false) { |
| 1935 | out += ' , message: \'should be equal to constant\' '; |
| 1936 | } |
| 1937 | if (it.opts.verbose) { |
| 1938 | out += ' , schema: validate.schema' + ($schemaPath) + ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' '; |
| 1939 | } |
| 1940 | out += ' } '; |
| 1941 | } else { |
| 1942 | out += ' {} '; |
| 1943 | } |
| 1944 | var __err = out; |
| 1945 | out = $$outStack.pop(); |
| 1946 | if (!it.compositeRule && $breakOnError) { /* istanbul ignore if */ |
| 1947 | if (it.async) { |
| 1948 | out += ' throw new ValidationError([' + (__err) + ']); '; |
| 1949 | } else { |
| 1950 | out += ' validate.errors = [' + (__err) + ']; return false; '; |
| 1951 | } |
| 1952 | } else { |
| 1953 | out += ' var err = ' + (__err) + '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; '; |
| 1954 | } |
| 1955 | out += ' }'; |
| 1956 | if ($breakOnError) { |
| 1957 | out += ' else { '; |
| 1958 | } |
| 1959 | return out; |
| 1960 | } |
| 1961 | |
| 1962 | },{}],20:[function(require,module,exports){ |
| 1963 | 'use strict'; |
| 1964 | module.exports = function generate_contains(it, $keyword, $ruleType) { |
| 1965 | var out = ' '; |
| 1966 | var $lvl = it.level; |
| 1967 | var $dataLvl = it.dataLevel; |
| 1968 | var $schema = it.schema[$keyword]; |
| 1969 | var $schemaPath = it.schemaPath + it.util.getProperty($keyword); |
| 1970 | var $errSchemaPath = it.errSchemaPath + '/' + $keyword; |
| 1971 | var $breakOnError = !it.opts.allErrors; |
| 1972 | var $data = 'data' + ($dataLvl || ''); |
| 1973 | var $valid = 'valid' + $lvl; |
| 1974 | var $errs = 'errs__' + $lvl; |
| 1975 | var $it = it.util.copy(it); |
| 1976 | var $closingBraces = ''; |
| 1977 | $it.level++; |
| 1978 | var $nextValid = 'valid' + $it.level; |
| 1979 | var $idx = 'i' + $lvl, |
| 1980 | $dataNxt = $it.dataLevel = it.dataLevel + 1, |
| 1981 | $nextData = 'data' + $dataNxt, |
| 1982 | $currentBaseId = it.baseId, |
| 1983 | $nonEmptySchema = it.util.schemaHasRules($schema, it.RULES.all); |
| 1984 | out += 'var ' + ($errs) + ' = errors;var ' + ($valid) + ';'; |
| 1985 | if ($nonEmptySchema) { |
| 1986 | var $wasComposite = it.compositeRule; |
| 1987 | it.compositeRule = $it.compositeRule = true; |
| 1988 | $it.schema = $schema; |
| 1989 | $it.schemaPath = $schemaPath; |
| 1990 | $it.errSchemaPath = $errSchemaPath; |
| 1991 | out += ' var ' + ($nextValid) + ' = false; for (var ' + ($idx) + ' = 0; ' + ($idx) + ' < ' + ($data) + '.length; ' + ($idx) + '++) { '; |
| 1992 | $it.errorPath = it.util.getPathExpr(it.errorPath, $idx, it.opts.jsonPointers, true); |
| 1993 | var $passData = $data + '[' + $idx + ']'; |
| 1994 | $it.dataPathArr[$dataNxt] = $idx; |
| 1995 | var $code = it.validate($it); |
| 1996 | $it.baseId = $currentBaseId; |
| 1997 | if (it.util.varOccurences($code, $nextData) < 2) { |
| 1998 | out += ' ' + (it.util.varReplace($code, $nextData, $passData)) + ' '; |
| 1999 | } else { |
| 2000 | out += ' var ' + ($nextData) + ' = ' + ($passData) + '; ' + ($code) + ' '; |
| 2001 | } |
| 2002 | out += ' if (' + ($nextValid) + ') break; } '; |
| 2003 | it.compositeRule = $it.compositeRule = $wasComposite; |
| 2004 | out += ' ' + ($closingBraces) + ' if (!' + ($nextValid) + ') {'; |
| 2005 | } else { |
| 2006 | out += ' if (' + ($data) + '.length == 0) {'; |
| 2007 | } |
| 2008 | var $$outStack = $$outStack || []; |
| 2009 | $$outStack.push(out); |
| 2010 | out = ''; /* istanbul ignore else */ |
| 2011 | if (it.createErrors !== false) { |
| 2012 | out += ' { keyword: \'' + ('contains') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: ' + (it.util.toQuotedString($errSchemaPath)) + ' , params: {} '; |
| 2013 | if (it.opts.messages !== false) { |
| 2014 | out += ' , message: \'should contain a valid item\' '; |
| 2015 | } |
| 2016 | if (it.opts.verbose) { |
| 2017 | out += ' , schema: validate.schema' + ($schemaPath) + ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' '; |
| 2018 | } |
| 2019 | out += ' } '; |
| 2020 | } else { |
| 2021 | out += ' {} '; |
| 2022 | } |
| 2023 | var __err = out; |
| 2024 | out = $$outStack.pop(); |
| 2025 | if (!it.compositeRule && $breakOnError) { /* istanbul ignore if */ |
| 2026 | if (it.async) { |
| 2027 | out += ' throw new ValidationError([' + (__err) + ']); '; |
| 2028 | } else { |
| 2029 | out += ' validate.errors = [' + (__err) + ']; return false; '; |
| 2030 | } |
| 2031 | } else { |
| 2032 | out += ' var err = ' + (__err) + '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; '; |
| 2033 | } |
| 2034 | out += ' } else { '; |
| 2035 | if ($nonEmptySchema) { |
| 2036 | out += ' errors = ' + ($errs) + '; if (vErrors !== null) { if (' + ($errs) + ') vErrors.length = ' + ($errs) + '; else vErrors = null; } '; |
| 2037 | } |
| 2038 | if (it.opts.allErrors) { |
| 2039 | out += ' } '; |
| 2040 | } |
| 2041 | out = it.util.cleanUpCode(out); |
| 2042 | return out; |
| 2043 | } |
| 2044 | |
| 2045 | },{}],21:[function(require,module,exports){ |
| 2046 | 'use strict'; |
| 2047 | module.exports = function generate_custom(it, $keyword, $ruleType) { |
| 2048 | var out = ' '; |
| 2049 | var $lvl = it.level; |
| 2050 | var $dataLvl = it.dataLevel; |
| 2051 | var $schema = it.schema[$keyword]; |
| 2052 | var $schemaPath = it.schemaPath + it.util.getProperty($keyword); |
| 2053 | var $errSchemaPath = it.errSchemaPath + '/' + $keyword; |
| 2054 | var $breakOnError = !it.opts.allErrors; |
| 2055 | var $errorKeyword; |
| 2056 | var $data = 'data' + ($dataLvl || ''); |
| 2057 | var $valid = 'valid' + $lvl; |
| 2058 | var $errs = 'errs__' + $lvl; |
| 2059 | var $isData = it.opts.$data && $schema && $schema.$data, |
| 2060 | $schemaValue; |
| 2061 | if ($isData) { |
| 2062 | out += ' var schema' + ($lvl) + ' = ' + (it.util.getData($schema.$data, $dataLvl, it.dataPathArr)) + '; '; |
| 2063 | $schemaValue = 'schema' + $lvl; |
| 2064 | } else { |
| 2065 | $schemaValue = $schema; |
| 2066 | } |
| 2067 | var $rule = this, |
| 2068 | $definition = 'definition' + $lvl, |
| 2069 | $rDef = $rule.definition, |
| 2070 | $closingBraces = ''; |
| 2071 | var $compile, $inline, $macro, $ruleValidate, $validateCode; |
| 2072 | if ($isData && $rDef.$data) { |
| 2073 | $validateCode = 'keywordValidate' + $lvl; |
| 2074 | var $validateSchema = $rDef.validateSchema; |
| 2075 | out += ' var ' + ($definition) + ' = RULES.custom[\'' + ($keyword) + '\'].definition; var ' + ($validateCode) + ' = ' + ($definition) + '.validate;'; |
| 2076 | } else { |
| 2077 | $ruleValidate = it.useCustomRule($rule, $schema, it.schema, it); |
| 2078 | if (!$ruleValidate) return; |
| 2079 | $schemaValue = 'validate.schema' + $schemaPath; |
| 2080 | $validateCode = $ruleValidate.code; |
| 2081 | $compile = $rDef.compile; |
| 2082 | $inline = $rDef.inline; |
| 2083 | $macro = $rDef.macro; |
| 2084 | } |
| 2085 | var $ruleErrs = $validateCode + '.errors', |
| 2086 | $i = 'i' + $lvl, |
| 2087 | $ruleErr = 'ruleErr' + $lvl, |
| 2088 | $asyncKeyword = $rDef.async; |
| 2089 | if ($asyncKeyword && !it.async) throw new Error('async keyword in sync schema'); |
| 2090 | if (!($inline || $macro)) { |
| 2091 | out += '' + ($ruleErrs) + ' = null;'; |
| 2092 | } |
| 2093 | out += 'var ' + ($errs) + ' = errors;var ' + ($valid) + ';'; |
| 2094 | if ($isData && $rDef.$data) { |
| 2095 | $closingBraces += '}'; |
| 2096 | out += ' if (' + ($schemaValue) + ' === undefined) { ' + ($valid) + ' = true; } else { '; |
| 2097 | if ($validateSchema) { |
| 2098 | $closingBraces += '}'; |
| 2099 | out += ' ' + ($valid) + ' = ' + ($definition) + '.validateSchema(' + ($schemaValue) + '); if (' + ($valid) + ') { '; |
| 2100 | } |
| 2101 | } |
| 2102 | if ($inline) { |
| 2103 | if ($rDef.statements) { |
| 2104 | out += ' ' + ($ruleValidate.validate) + ' '; |
| 2105 | } else { |
| 2106 | out += ' ' + ($valid) + ' = ' + ($ruleValidate.validate) + '; '; |
| 2107 | } |
| 2108 | } else if ($macro) { |
| 2109 | var $it = it.util.copy(it); |
| 2110 | var $closingBraces = ''; |
| 2111 | $it.level++; |
| 2112 | var $nextValid = 'valid' + $it.level; |
| 2113 | $it.schema = $ruleValidate.validate; |
| 2114 | $it.schemaPath = ''; |
| 2115 | var $wasComposite = it.compositeRule; |
| 2116 | it.compositeRule = $it.compositeRule = true; |
| 2117 | var $code = it.validate($it).replace(/validate\.schema/g, $validateCode); |
| 2118 | it.compositeRule = $it.compositeRule = $wasComposite; |
| 2119 | out += ' ' + ($code); |
| 2120 | } else { |
| 2121 | var $$outStack = $$outStack || []; |
| 2122 | $$outStack.push(out); |
| 2123 | out = ''; |
| 2124 | out += ' ' + ($validateCode) + '.call( '; |
| 2125 | if (it.opts.passContext) { |
| 2126 | out += 'this'; |
| 2127 | } else { |
| 2128 | out += 'self'; |
| 2129 | } |
| 2130 | if ($compile || $rDef.schema === false) { |
| 2131 | out += ' , ' + ($data) + ' '; |
| 2132 | } else { |
| 2133 | out += ' , ' + ($schemaValue) + ' , ' + ($data) + ' , validate.schema' + (it.schemaPath) + ' '; |
| 2134 | } |
| 2135 | out += ' , (dataPath || \'\')'; |
| 2136 | if (it.errorPath != '""') { |
| 2137 | out += ' + ' + (it.errorPath); |
| 2138 | } |
| 2139 | var $parentData = $dataLvl ? 'data' + (($dataLvl - 1) || '') : 'parentData', |
| 2140 | $parentDataProperty = $dataLvl ? it.dataPathArr[$dataLvl] : 'parentDataProperty'; |
| 2141 | out += ' , ' + ($parentData) + ' , ' + ($parentDataProperty) + ' , rootData ) '; |
| 2142 | var def_callRuleValidate = out; |
| 2143 | out = $$outStack.pop(); |
| 2144 | if ($rDef.errors === false) { |
| 2145 | out += ' ' + ($valid) + ' = '; |
| 2146 | if ($asyncKeyword) { |
| 2147 | out += '' + (it.yieldAwait); |
| 2148 | } |
| 2149 | out += '' + (def_callRuleValidate) + '; '; |
| 2150 | } else { |
| 2151 | if ($asyncKeyword) { |
| 2152 | $ruleErrs = 'customErrors' + $lvl; |
| 2153 | out += ' var ' + ($ruleErrs) + ' = null; try { ' + ($valid) + ' = ' + (it.yieldAwait) + (def_callRuleValidate) + '; } catch (e) { ' + ($valid) + ' = false; if (e instanceof ValidationError) ' + ($ruleErrs) + ' = e.errors; else throw e; } '; |
| 2154 | } else { |
| 2155 | out += ' ' + ($ruleErrs) + ' = null; ' + ($valid) + ' = ' + (def_callRuleValidate) + '; '; |
| 2156 | } |
| 2157 | } |
| 2158 | } |
| 2159 | if ($rDef.modifying) { |
| 2160 | out += ' if (' + ($parentData) + ') ' + ($data) + ' = ' + ($parentData) + '[' + ($parentDataProperty) + '];'; |
| 2161 | } |
| 2162 | out += '' + ($closingBraces); |
| 2163 | if ($rDef.valid) { |
| 2164 | if ($breakOnError) { |
| 2165 | out += ' if (true) { '; |
| 2166 | } |
| 2167 | } else { |
| 2168 | out += ' if ( '; |
| 2169 | if ($rDef.valid === undefined) { |
| 2170 | out += ' !'; |
| 2171 | if ($macro) { |
| 2172 | out += '' + ($nextValid); |
| 2173 | } else { |
| 2174 | out += '' + ($valid); |
| 2175 | } |
| 2176 | } else { |
| 2177 | out += ' ' + (!$rDef.valid) + ' '; |
| 2178 | } |
| 2179 | out += ') { '; |
| 2180 | $errorKeyword = $rule.keyword; |
| 2181 | var $$outStack = $$outStack || []; |
| 2182 | $$outStack.push(out); |
| 2183 | out = ''; |
| 2184 | var $$outStack = $$outStack || []; |
| 2185 | $$outStack.push(out); |
| 2186 | out = ''; /* istanbul ignore else */ |
| 2187 | if (it.createErrors !== false) { |
| 2188 | out += ' { keyword: \'' + ($errorKeyword || 'custom') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: ' + (it.util.toQuotedString($errSchemaPath)) + ' , params: { keyword: \'' + ($rule.keyword) + '\' } '; |
| 2189 | if (it.opts.messages !== false) { |
| 2190 | out += ' , message: \'should pass "' + ($rule.keyword) + '" keyword validation\' '; |
| 2191 | } |
| 2192 | if (it.opts.verbose) { |
| 2193 | out += ' , schema: validate.schema' + ($schemaPath) + ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' '; |
| 2194 | } |
| 2195 | out += ' } '; |
| 2196 | } else { |
| 2197 | out += ' {} '; |
| 2198 | } |
| 2199 | var __err = out; |
| 2200 | out = $$outStack.pop(); |
| 2201 | if (!it.compositeRule && $breakOnError) { /* istanbul ignore if */ |
| 2202 | if (it.async) { |
| 2203 | out += ' throw new ValidationError([' + (__err) + ']); '; |
| 2204 | } else { |
| 2205 | out += ' validate.errors = [' + (__err) + ']; return false; '; |
| 2206 | } |
| 2207 | } else { |
| 2208 | out += ' var err = ' + (__err) + '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; '; |
| 2209 | } |
| 2210 | var def_customError = out; |
| 2211 | out = $$outStack.pop(); |
| 2212 | if ($inline) { |
| 2213 | if ($rDef.errors) { |
| 2214 | if ($rDef.errors != 'full') { |
| 2215 | 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) + '"; } '; |
| 2216 | if (it.opts.verbose) { |
| 2217 | out += ' ' + ($ruleErr) + '.schema = ' + ($schemaValue) + '; ' + ($ruleErr) + '.data = ' + ($data) + '; '; |
| 2218 | } |
| 2219 | out += ' } '; |
| 2220 | } |
| 2221 | } else { |
| 2222 | if ($rDef.errors === false) { |
| 2223 | out += ' ' + (def_customError) + ' '; |
| 2224 | } else { |
| 2225 | 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) + '"; } '; |
| 2226 | if (it.opts.verbose) { |
| 2227 | out += ' ' + ($ruleErr) + '.schema = ' + ($schemaValue) + '; ' + ($ruleErr) + '.data = ' + ($data) + '; '; |
| 2228 | } |
| 2229 | out += ' } } '; |
| 2230 | } |
| 2231 | } |
| 2232 | } else if ($macro) { |
| 2233 | out += ' var err = '; /* istanbul ignore else */ |
| 2234 | if (it.createErrors !== false) { |
| 2235 | out += ' { keyword: \'' + ($errorKeyword || 'custom') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: ' + (it.util.toQuotedString($errSchemaPath)) + ' , params: { keyword: \'' + ($rule.keyword) + '\' } '; |
| 2236 | if (it.opts.messages !== false) { |
| 2237 | out += ' , message: \'should pass "' + ($rule.keyword) + '" keyword validation\' '; |
| 2238 | } |
| 2239 | if (it.opts.verbose) { |
| 2240 | out += ' , schema: validate.schema' + ($schemaPath) + ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' '; |
| 2241 | } |
| 2242 | out += ' } '; |
| 2243 | } else { |
| 2244 | out += ' {} '; |
| 2245 | } |
| 2246 | out += '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; '; |
| 2247 | if (!it.compositeRule && $breakOnError) { /* istanbul ignore if */ |
| 2248 | if (it.async) { |
| 2249 | out += ' throw new ValidationError(vErrors); '; |
| 2250 | } else { |
| 2251 | out += ' validate.errors = vErrors; return false; '; |
| 2252 | } |
| 2253 | } |
| 2254 | } else { |
| 2255 | if ($rDef.errors === false) { |
| 2256 | out += ' ' + (def_customError) + ' '; |
| 2257 | } else { |
| 2258 | 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) + '"; '; |
| 2259 | if (it.opts.verbose) { |
| 2260 | out += ' ' + ($ruleErr) + '.schema = ' + ($schemaValue) + '; ' + ($ruleErr) + '.data = ' + ($data) + '; '; |
| 2261 | } |
| 2262 | out += ' } } else { ' + (def_customError) + ' } '; |
| 2263 | } |
| 2264 | } |
| 2265 | out += ' } '; |
| 2266 | if ($breakOnError) { |
| 2267 | out += ' else { '; |
| 2268 | } |
| 2269 | } |
| 2270 | return out; |
| 2271 | } |
| 2272 | |
| 2273 | },{}],22:[function(require,module,exports){ |
| 2274 | 'use strict'; |
| 2275 | module.exports = function generate_dependencies(it, $keyword, $ruleType) { |
| 2276 | var out = ' '; |
| 2277 | var $lvl = it.level; |
| 2278 | var $dataLvl = it.dataLevel; |
| 2279 | var $schema = it.schema[$keyword]; |
| 2280 | var $schemaPath = it.schemaPath + it.util.getProperty($keyword); |
| 2281 | var $errSchemaPath = it.errSchemaPath + '/' + $keyword; |
| 2282 | var $breakOnError = !it.opts.allErrors; |
| 2283 | var $data = 'data' + ($dataLvl || ''); |
| 2284 | var $errs = 'errs__' + $lvl; |
| 2285 | var $it = it.util.copy(it); |
| 2286 | var $closingBraces = ''; |
| 2287 | $it.level++; |
| 2288 | var $nextValid = 'valid' + $it.level; |
| 2289 | var $schemaDeps = {}, |
| 2290 | $propertyDeps = {}, |
| 2291 | $ownProperties = it.opts.ownProperties; |
| 2292 | for ($property in $schema) { |
| 2293 | var $sch = $schema[$property]; |
| 2294 | var $deps = Array.isArray($sch) ? $propertyDeps : $schemaDeps; |
| 2295 | $deps[$property] = $sch; |
| 2296 | } |
| 2297 | out += 'var ' + ($errs) + ' = errors;'; |
| 2298 | var $currentErrorPath = it.errorPath; |
| 2299 | out += 'var missing' + ($lvl) + ';'; |
| 2300 | for (var $property in $propertyDeps) { |
| 2301 | $deps = $propertyDeps[$property]; |
| 2302 | if ($deps.length) { |
| 2303 | out += ' if ( ' + ($data) + (it.util.getProperty($property)) + ' !== undefined '; |
| 2304 | if ($ownProperties) { |
| 2305 | out += ' && Object.prototype.hasOwnProperty.call(' + ($data) + ', \'' + (it.util.escapeQuotes($property)) + '\') '; |
| 2306 | } |
| 2307 | if ($breakOnError) { |
| 2308 | out += ' && ( '; |
| 2309 | var arr1 = $deps; |
| 2310 | if (arr1) { |
| 2311 | var $propertyKey, $i = -1, |
| 2312 | l1 = arr1.length - 1; |
| 2313 | while ($i < l1) { |
| 2314 | $propertyKey = arr1[$i += 1]; |
| 2315 | if ($i) { |
| 2316 | out += ' || '; |
| 2317 | } |
| 2318 | var $prop = it.util.getProperty($propertyKey), |
| 2319 | $useData = $data + $prop; |
| 2320 | out += ' ( ( ' + ($useData) + ' === undefined '; |
| 2321 | if ($ownProperties) { |
| 2322 | out += ' || ! Object.prototype.hasOwnProperty.call(' + ($data) + ', \'' + (it.util.escapeQuotes($propertyKey)) + '\') '; |
| 2323 | } |
| 2324 | out += ') && (missing' + ($lvl) + ' = ' + (it.util.toQuotedString(it.opts.jsonPointers ? $propertyKey : $prop)) + ') ) '; |
| 2325 | } |
| 2326 | } |
| 2327 | out += ')) { '; |
| 2328 | var $propertyPath = 'missing' + $lvl, |
| 2329 | $missingProperty = '\' + ' + $propertyPath + ' + \''; |
| 2330 | if (it.opts._errorDataPathProperty) { |
| 2331 | it.errorPath = it.opts.jsonPointers ? it.util.getPathExpr($currentErrorPath, $propertyPath, true) : $currentErrorPath + ' + ' + $propertyPath; |
| 2332 | } |
| 2333 | var $$outStack = $$outStack || []; |
| 2334 | $$outStack.push(out); |
| 2335 | out = ''; /* istanbul ignore else */ |
| 2336 | if (it.createErrors !== false) { |
| 2337 | 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(", "))) + '\' } '; |
| 2338 | if (it.opts.messages !== false) { |
| 2339 | out += ' , message: \'should have '; |
| 2340 | if ($deps.length == 1) { |
| 2341 | out += 'property ' + (it.util.escapeQuotes($deps[0])); |
| 2342 | } else { |
| 2343 | out += 'properties ' + (it.util.escapeQuotes($deps.join(", "))); |
| 2344 | } |
| 2345 | out += ' when property ' + (it.util.escapeQuotes($property)) + ' is present\' '; |
| 2346 | } |
| 2347 | if (it.opts.verbose) { |
| 2348 | out += ' , schema: validate.schema' + ($schemaPath) + ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' '; |
| 2349 | } |
| 2350 | out += ' } '; |
| 2351 | } else { |
| 2352 | out += ' {} '; |
| 2353 | } |
| 2354 | var __err = out; |
| 2355 | out = $$outStack.pop(); |
| 2356 | if (!it.compositeRule && $breakOnError) { /* istanbul ignore if */ |
| 2357 | if (it.async) { |
| 2358 | out += ' throw new ValidationError([' + (__err) + ']); '; |
| 2359 | } else { |
| 2360 | out += ' validate.errors = [' + (__err) + ']; return false; '; |
| 2361 | } |
| 2362 | } else { |
| 2363 | out += ' var err = ' + (__err) + '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; '; |
| 2364 | } |
| 2365 | } else { |
| 2366 | out += ' ) { '; |
| 2367 | var arr2 = $deps; |
| 2368 | if (arr2) { |
| 2369 | var $propertyKey, i2 = -1, |
| 2370 | l2 = arr2.length - 1; |
| 2371 | while (i2 < l2) { |
| 2372 | $propertyKey = arr2[i2 += 1]; |
| 2373 | var $prop = it.util.getProperty($propertyKey), |
| 2374 | $missingProperty = it.util.escapeQuotes($propertyKey), |
| 2375 | $useData = $data + $prop; |
| 2376 | if (it.opts._errorDataPathProperty) { |
| 2377 | it.errorPath = it.util.getPath($currentErrorPath, $propertyKey, it.opts.jsonPointers); |
| 2378 | } |
| 2379 | out += ' if ( ' + ($useData) + ' === undefined '; |
| 2380 | if ($ownProperties) { |
| 2381 | out += ' || ! Object.prototype.hasOwnProperty.call(' + ($data) + ', \'' + (it.util.escapeQuotes($propertyKey)) + '\') '; |
| 2382 | } |
| 2383 | out += ') { var err = '; /* istanbul ignore else */ |
| 2384 | if (it.createErrors !== false) { |
| 2385 | 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(", "))) + '\' } '; |
| 2386 | if (it.opts.messages !== false) { |
| 2387 | out += ' , message: \'should have '; |
| 2388 | if ($deps.length == 1) { |
| 2389 | out += 'property ' + (it.util.escapeQuotes($deps[0])); |
| 2390 | } else { |
| 2391 | out += 'properties ' + (it.util.escapeQuotes($deps.join(", "))); |
| 2392 | } |
| 2393 | out += ' when property ' + (it.util.escapeQuotes($property)) + ' is present\' '; |
| 2394 | } |
| 2395 | if (it.opts.verbose) { |
| 2396 | out += ' , schema: validate.schema' + ($schemaPath) + ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' '; |
| 2397 | } |
| 2398 | out += ' } '; |
| 2399 | } else { |
| 2400 | out += ' {} '; |
| 2401 | } |
| 2402 | out += '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; } '; |
| 2403 | } |
| 2404 | } |
| 2405 | } |
| 2406 | out += ' } '; |
| 2407 | if ($breakOnError) { |
| 2408 | $closingBraces += '}'; |
| 2409 | out += ' else { '; |
| 2410 | } |
| 2411 | } |
| 2412 | } |
| 2413 | it.errorPath = $currentErrorPath; |
| 2414 | var $currentBaseId = $it.baseId; |
| 2415 | for (var $property in $schemaDeps) { |
| 2416 | var $sch = $schemaDeps[$property]; |
| 2417 | if (it.util.schemaHasRules($sch, it.RULES.all)) { |
| 2418 | out += ' ' + ($nextValid) + ' = true; if ( ' + ($data) + (it.util.getProperty($property)) + ' !== undefined '; |
| 2419 | if ($ownProperties) { |
| 2420 | out += ' && Object.prototype.hasOwnProperty.call(' + ($data) + ', \'' + (it.util.escapeQuotes($property)) + '\') '; |
| 2421 | } |
| 2422 | out += ') { '; |
| 2423 | $it.schema = $sch; |
| 2424 | $it.schemaPath = $schemaPath + it.util.getProperty($property); |
| 2425 | $it.errSchemaPath = $errSchemaPath + '/' + it.util.escapeFragment($property); |
| 2426 | out += ' ' + (it.validate($it)) + ' '; |
| 2427 | $it.baseId = $currentBaseId; |
| 2428 | out += ' } '; |
| 2429 | if ($breakOnError) { |
| 2430 | out += ' if (' + ($nextValid) + ') { '; |
| 2431 | $closingBraces += '}'; |
| 2432 | } |
| 2433 | } |
| 2434 | } |
| 2435 | if ($breakOnError) { |
| 2436 | out += ' ' + ($closingBraces) + ' if (' + ($errs) + ' == errors) {'; |
| 2437 | } |
| 2438 | out = it.util.cleanUpCode(out); |
| 2439 | return out; |
| 2440 | } |
| 2441 | |
| 2442 | },{}],23:[function(require,module,exports){ |
| 2443 | 'use strict'; |
| 2444 | module.exports = function generate_enum(it, $keyword, $ruleType) { |
| 2445 | var out = ' '; |
| 2446 | var $lvl = it.level; |
| 2447 | var $dataLvl = it.dataLevel; |
| 2448 | var $schema = it.schema[$keyword]; |
| 2449 | var $schemaPath = it.schemaPath + it.util.getProperty($keyword); |
| 2450 | var $errSchemaPath = it.errSchemaPath + '/' + $keyword; |
| 2451 | var $breakOnError = !it.opts.allErrors; |
| 2452 | var $data = 'data' + ($dataLvl || ''); |
| 2453 | var $valid = 'valid' + $lvl; |
| 2454 | var $isData = it.opts.$data && $schema && $schema.$data, |
| 2455 | $schemaValue; |
| 2456 | if ($isData) { |
| 2457 | out += ' var schema' + ($lvl) + ' = ' + (it.util.getData($schema.$data, $dataLvl, it.dataPathArr)) + '; '; |
| 2458 | $schemaValue = 'schema' + $lvl; |
| 2459 | } else { |
| 2460 | $schemaValue = $schema; |
| 2461 | } |
| 2462 | var $i = 'i' + $lvl, |
| 2463 | $vSchema = 'schema' + $lvl; |
| 2464 | if (!$isData) { |
| 2465 | out += ' var ' + ($vSchema) + ' = validate.schema' + ($schemaPath) + ';'; |
| 2466 | } |
| 2467 | out += 'var ' + ($valid) + ';'; |
| 2468 | if ($isData) { |
| 2469 | out += ' if (schema' + ($lvl) + ' === undefined) ' + ($valid) + ' = true; else if (!Array.isArray(schema' + ($lvl) + ')) ' + ($valid) + ' = false; else {'; |
| 2470 | } |
| 2471 | out += '' + ($valid) + ' = false;for (var ' + ($i) + '=0; ' + ($i) + '<' + ($vSchema) + '.length; ' + ($i) + '++) if (equal(' + ($data) + ', ' + ($vSchema) + '[' + ($i) + '])) { ' + ($valid) + ' = true; break; }'; |
| 2472 | if ($isData) { |
| 2473 | out += ' } '; |
| 2474 | } |
| 2475 | out += ' if (!' + ($valid) + ') { '; |
| 2476 | var $$outStack = $$outStack || []; |
| 2477 | $$outStack.push(out); |
| 2478 | out = ''; /* istanbul ignore else */ |
| 2479 | if (it.createErrors !== false) { |
| 2480 | out += ' { keyword: \'' + ('enum') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: ' + (it.util.toQuotedString($errSchemaPath)) + ' , params: { allowedValues: schema' + ($lvl) + ' } '; |
| 2481 | if (it.opts.messages !== false) { |
| 2482 | out += ' , message: \'should be equal to one of the allowed values\' '; |
| 2483 | } |
| 2484 | if (it.opts.verbose) { |
| 2485 | out += ' , schema: validate.schema' + ($schemaPath) + ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' '; |
| 2486 | } |
| 2487 | out += ' } '; |
| 2488 | } else { |
| 2489 | out += ' {} '; |
| 2490 | } |
| 2491 | var __err = out; |
| 2492 | out = $$outStack.pop(); |
| 2493 | if (!it.compositeRule && $breakOnError) { /* istanbul ignore if */ |
| 2494 | if (it.async) { |
| 2495 | out += ' throw new ValidationError([' + (__err) + ']); '; |
| 2496 | } else { |
| 2497 | out += ' validate.errors = [' + (__err) + ']; return false; '; |
| 2498 | } |
| 2499 | } else { |
| 2500 | out += ' var err = ' + (__err) + '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; '; |
| 2501 | } |
| 2502 | out += ' }'; |
| 2503 | if ($breakOnError) { |
| 2504 | out += ' else { '; |
| 2505 | } |
| 2506 | return out; |
| 2507 | } |
| 2508 | |
| 2509 | },{}],24:[function(require,module,exports){ |
| 2510 | 'use strict'; |
| 2511 | module.exports = function generate_format(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 | if (it.opts.format === false) { |
| 2521 | if ($breakOnError) { |
| 2522 | out += ' if (true) { '; |
| 2523 | } |
| 2524 | return out; |
| 2525 | } |
| 2526 | var $isData = it.opts.$data && $schema && $schema.$data, |
| 2527 | $schemaValue; |
| 2528 | if ($isData) { |
| 2529 | out += ' var schema' + ($lvl) + ' = ' + (it.util.getData($schema.$data, $dataLvl, it.dataPathArr)) + '; '; |
| 2530 | $schemaValue = 'schema' + $lvl; |
| 2531 | } else { |
| 2532 | $schemaValue = $schema; |
| 2533 | } |
| 2534 | var $unknownFormats = it.opts.unknownFormats, |
| 2535 | $allowUnknown = Array.isArray($unknownFormats); |
| 2536 | if ($isData) { |
| 2537 | var $format = 'format' + $lvl, |
| 2538 | $isObject = 'isObject' + $lvl, |
| 2539 | $formatType = 'formatType' + $lvl; |
| 2540 | out += ' var ' + ($format) + ' = formats[' + ($schemaValue) + ']; var ' + ($isObject) + ' = typeof ' + ($format) + ' == \'object\' && !(' + ($format) + ' instanceof RegExp) && ' + ($format) + '.validate; var ' + ($formatType) + ' = ' + ($isObject) + ' && ' + ($format) + '.type || \'string\'; if (' + ($isObject) + ') { '; |
| 2541 | if (it.async) { |
| 2542 | out += ' var async' + ($lvl) + ' = ' + ($format) + '.async; '; |
| 2543 | } |
| 2544 | out += ' ' + ($format) + ' = ' + ($format) + '.validate; } if ( '; |
| 2545 | if ($isData) { |
| 2546 | out += ' (' + ($schemaValue) + ' !== undefined && typeof ' + ($schemaValue) + ' != \'string\') || '; |
| 2547 | } |
| 2548 | out += ' ('; |
| 2549 | if ($unknownFormats != 'ignore') { |
| 2550 | out += ' (' + ($schemaValue) + ' && !' + ($format) + ' '; |
| 2551 | if ($allowUnknown) { |
| 2552 | out += ' && self._opts.unknownFormats.indexOf(' + ($schemaValue) + ') == -1 '; |
| 2553 | } |
| 2554 | out += ') || '; |
| 2555 | } |
| 2556 | out += ' (' + ($format) + ' && ' + ($formatType) + ' == \'' + ($ruleType) + '\' && !(typeof ' + ($format) + ' == \'function\' ? '; |
| 2557 | if (it.async) { |
| 2558 | out += ' (async' + ($lvl) + ' ? ' + (it.yieldAwait) + ' ' + ($format) + '(' + ($data) + ') : ' + ($format) + '(' + ($data) + ')) '; |
| 2559 | } else { |
| 2560 | out += ' ' + ($format) + '(' + ($data) + ') '; |
| 2561 | } |
| 2562 | out += ' : ' + ($format) + '.test(' + ($data) + '))))) {'; |
| 2563 | } else { |
| 2564 | var $format = it.formats[$schema]; |
| 2565 | if (!$format) { |
| 2566 | if ($unknownFormats == 'ignore') { |
| 2567 | it.logger.warn('unknown format "' + $schema + '" ignored in schema at path "' + it.errSchemaPath + '"'); |
| 2568 | if ($breakOnError) { |
| 2569 | out += ' if (true) { '; |
| 2570 | } |
| 2571 | return out; |
| 2572 | } else if ($allowUnknown && $unknownFormats.indexOf($schema) >= 0) { |
| 2573 | if ($breakOnError) { |
| 2574 | out += ' if (true) { '; |
| 2575 | } |
| 2576 | return out; |
| 2577 | } else { |
| 2578 | throw new Error('unknown format "' + $schema + '" is used in schema at path "' + it.errSchemaPath + '"'); |
| 2579 | } |
| 2580 | } |
| 2581 | var $isObject = typeof $format == 'object' && !($format instanceof RegExp) && $format.validate; |
| 2582 | var $formatType = $isObject && $format.type || 'string'; |
| 2583 | if ($isObject) { |
| 2584 | var $async = $format.async === true; |
| 2585 | $format = $format.validate; |
| 2586 | } |
| 2587 | if ($formatType != $ruleType) { |
| 2588 | if ($breakOnError) { |
| 2589 | out += ' if (true) { '; |
| 2590 | } |
| 2591 | return out; |
| 2592 | } |
| 2593 | if ($async) { |
| 2594 | if (!it.async) throw new Error('async format in sync schema'); |
| 2595 | var $formatRef = 'formats' + it.util.getProperty($schema) + '.validate'; |
| 2596 | out += ' if (!(' + (it.yieldAwait) + ' ' + ($formatRef) + '(' + ($data) + '))) { '; |
| 2597 | } else { |
| 2598 | out += ' if (! '; |
| 2599 | var $formatRef = 'formats' + it.util.getProperty($schema); |
| 2600 | if ($isObject) $formatRef += '.validate'; |
| 2601 | if (typeof $format == 'function') { |
| 2602 | out += ' ' + ($formatRef) + '(' + ($data) + ') '; |
| 2603 | } else { |
| 2604 | out += ' ' + ($formatRef) + '.test(' + ($data) + ') '; |
| 2605 | } |
| 2606 | out += ') { '; |
| 2607 | } |
| 2608 | } |
| 2609 | var $$outStack = $$outStack || []; |
| 2610 | $$outStack.push(out); |
| 2611 | out = ''; /* istanbul ignore else */ |
| 2612 | if (it.createErrors !== false) { |
| 2613 | out += ' { keyword: \'' + ('format') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: ' + (it.util.toQuotedString($errSchemaPath)) + ' , params: { format: '; |
| 2614 | if ($isData) { |
| 2615 | out += '' + ($schemaValue); |
| 2616 | } else { |
| 2617 | out += '' + (it.util.toQuotedString($schema)); |
| 2618 | } |
| 2619 | out += ' } '; |
| 2620 | if (it.opts.messages !== false) { |
| 2621 | out += ' , message: \'should match format "'; |
| 2622 | if ($isData) { |
| 2623 | out += '\' + ' + ($schemaValue) + ' + \''; |
| 2624 | } else { |
| 2625 | out += '' + (it.util.escapeQuotes($schema)); |
| 2626 | } |
| 2627 | out += '"\' '; |
| 2628 | } |
| 2629 | if (it.opts.verbose) { |
| 2630 | out += ' , schema: '; |
| 2631 | if ($isData) { |
| 2632 | out += 'validate.schema' + ($schemaPath); |
| 2633 | } else { |
| 2634 | out += '' + (it.util.toQuotedString($schema)); |
| 2635 | } |
| 2636 | out += ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' '; |
| 2637 | } |
| 2638 | out += ' } '; |
| 2639 | } else { |
| 2640 | out += ' {} '; |
| 2641 | } |
| 2642 | var __err = out; |
| 2643 | out = $$outStack.pop(); |
| 2644 | if (!it.compositeRule && $breakOnError) { /* istanbul ignore if */ |
| 2645 | if (it.async) { |
| 2646 | out += ' throw new ValidationError([' + (__err) + ']); '; |
| 2647 | } else { |
| 2648 | out += ' validate.errors = [' + (__err) + ']; return false; '; |
| 2649 | } |
| 2650 | } else { |
| 2651 | out += ' var err = ' + (__err) + '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; '; |
| 2652 | } |
| 2653 | out += ' } '; |
| 2654 | if ($breakOnError) { |
| 2655 | out += ' else { '; |
| 2656 | } |
| 2657 | return out; |
| 2658 | } |
| 2659 | |
| 2660 | },{}],25:[function(require,module,exports){ |
| 2661 | 'use strict'; |
| 2662 | module.exports = function generate_items(it, $keyword, $ruleType) { |
| 2663 | var out = ' '; |
| 2664 | var $lvl = it.level; |
| 2665 | var $dataLvl = it.dataLevel; |
| 2666 | var $schema = it.schema[$keyword]; |
| 2667 | var $schemaPath = it.schemaPath + it.util.getProperty($keyword); |
| 2668 | var $errSchemaPath = it.errSchemaPath + '/' + $keyword; |
| 2669 | var $breakOnError = !it.opts.allErrors; |
| 2670 | var $data = 'data' + ($dataLvl || ''); |
| 2671 | var $valid = 'valid' + $lvl; |
| 2672 | var $errs = 'errs__' + $lvl; |
| 2673 | var $it = it.util.copy(it); |
| 2674 | var $closingBraces = ''; |
| 2675 | $it.level++; |
| 2676 | var $nextValid = 'valid' + $it.level; |
| 2677 | var $idx = 'i' + $lvl, |
| 2678 | $dataNxt = $it.dataLevel = it.dataLevel + 1, |
| 2679 | $nextData = 'data' + $dataNxt, |
| 2680 | $currentBaseId = it.baseId; |
| 2681 | out += 'var ' + ($errs) + ' = errors;var ' + ($valid) + ';'; |
| 2682 | if (Array.isArray($schema)) { |
| 2683 | var $additionalItems = it.schema.additionalItems; |
| 2684 | if ($additionalItems === false) { |
| 2685 | out += ' ' + ($valid) + ' = ' + ($data) + '.length <= ' + ($schema.length) + '; '; |
| 2686 | var $currErrSchemaPath = $errSchemaPath; |
| 2687 | $errSchemaPath = it.errSchemaPath + '/additionalItems'; |
| 2688 | out += ' if (!' + ($valid) + ') { '; |
| 2689 | var $$outStack = $$outStack || []; |
| 2690 | $$outStack.push(out); |
| 2691 | out = ''; /* istanbul ignore else */ |
| 2692 | if (it.createErrors !== false) { |
| 2693 | out += ' { keyword: \'' + ('additionalItems') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: ' + (it.util.toQuotedString($errSchemaPath)) + ' , params: { limit: ' + ($schema.length) + ' } '; |
| 2694 | if (it.opts.messages !== false) { |
| 2695 | out += ' , message: \'should NOT have more than ' + ($schema.length) + ' items\' '; |
| 2696 | } |
| 2697 | if (it.opts.verbose) { |
| 2698 | out += ' , schema: false , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' '; |
| 2699 | } |
| 2700 | out += ' } '; |
| 2701 | } else { |
| 2702 | out += ' {} '; |
| 2703 | } |
| 2704 | var __err = out; |
| 2705 | out = $$outStack.pop(); |
| 2706 | if (!it.compositeRule && $breakOnError) { /* istanbul ignore if */ |
| 2707 | if (it.async) { |
| 2708 | out += ' throw new ValidationError([' + (__err) + ']); '; |
| 2709 | } else { |
| 2710 | out += ' validate.errors = [' + (__err) + ']; return false; '; |
| 2711 | } |
| 2712 | } else { |
| 2713 | out += ' var err = ' + (__err) + '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; '; |
| 2714 | } |
| 2715 | out += ' } '; |
| 2716 | $errSchemaPath = $currErrSchemaPath; |
| 2717 | if ($breakOnError) { |
| 2718 | $closingBraces += '}'; |
| 2719 | out += ' else { '; |
| 2720 | } |
| 2721 | } |
| 2722 | var arr1 = $schema; |
| 2723 | if (arr1) { |
| 2724 | var $sch, $i = -1, |
| 2725 | l1 = arr1.length - 1; |
| 2726 | while ($i < l1) { |
| 2727 | $sch = arr1[$i += 1]; |
| 2728 | if (it.util.schemaHasRules($sch, it.RULES.all)) { |
| 2729 | out += ' ' + ($nextValid) + ' = true; if (' + ($data) + '.length > ' + ($i) + ') { '; |
| 2730 | var $passData = $data + '[' + $i + ']'; |
| 2731 | $it.schema = $sch; |
| 2732 | $it.schemaPath = $schemaPath + '[' + $i + ']'; |
| 2733 | $it.errSchemaPath = $errSchemaPath + '/' + $i; |
| 2734 | $it.errorPath = it.util.getPathExpr(it.errorPath, $i, it.opts.jsonPointers, true); |
| 2735 | $it.dataPathArr[$dataNxt] = $i; |
| 2736 | var $code = it.validate($it); |
| 2737 | $it.baseId = $currentBaseId; |
| 2738 | if (it.util.varOccurences($code, $nextData) < 2) { |
| 2739 | out += ' ' + (it.util.varReplace($code, $nextData, $passData)) + ' '; |
| 2740 | } else { |
| 2741 | out += ' var ' + ($nextData) + ' = ' + ($passData) + '; ' + ($code) + ' '; |
| 2742 | } |
| 2743 | out += ' } '; |
| 2744 | if ($breakOnError) { |
| 2745 | out += ' if (' + ($nextValid) + ') { '; |
| 2746 | $closingBraces += '}'; |
| 2747 | } |
| 2748 | } |
| 2749 | } |
| 2750 | } |
| 2751 | if (typeof $additionalItems == 'object' && it.util.schemaHasRules($additionalItems, it.RULES.all)) { |
| 2752 | $it.schema = $additionalItems; |
| 2753 | $it.schemaPath = it.schemaPath + '.additionalItems'; |
| 2754 | $it.errSchemaPath = it.errSchemaPath + '/additionalItems'; |
| 2755 | out += ' ' + ($nextValid) + ' = true; if (' + ($data) + '.length > ' + ($schema.length) + ') { for (var ' + ($idx) + ' = ' + ($schema.length) + '; ' + ($idx) + ' < ' + ($data) + '.length; ' + ($idx) + '++) { '; |
| 2756 | $it.errorPath = it.util.getPathExpr(it.errorPath, $idx, it.opts.jsonPointers, true); |
| 2757 | var $passData = $data + '[' + $idx + ']'; |
| 2758 | $it.dataPathArr[$dataNxt] = $idx; |
| 2759 | var $code = it.validate($it); |
| 2760 | $it.baseId = $currentBaseId; |
| 2761 | if (it.util.varOccurences($code, $nextData) < 2) { |
| 2762 | out += ' ' + (it.util.varReplace($code, $nextData, $passData)) + ' '; |
| 2763 | } else { |
| 2764 | out += ' var ' + ($nextData) + ' = ' + ($passData) + '; ' + ($code) + ' '; |
| 2765 | } |
| 2766 | if ($breakOnError) { |
| 2767 | out += ' if (!' + ($nextValid) + ') break; '; |
| 2768 | } |
| 2769 | out += ' } } '; |
| 2770 | if ($breakOnError) { |
| 2771 | out += ' if (' + ($nextValid) + ') { '; |
| 2772 | $closingBraces += '}'; |
| 2773 | } |
| 2774 | } |
| 2775 | } else if (it.util.schemaHasRules($schema, it.RULES.all)) { |
| 2776 | $it.schema = $schema; |
| 2777 | $it.schemaPath = $schemaPath; |
| 2778 | $it.errSchemaPath = $errSchemaPath; |
| 2779 | out += ' for (var ' + ($idx) + ' = ' + (0) + '; ' + ($idx) + ' < ' + ($data) + '.length; ' + ($idx) + '++) { '; |
| 2780 | $it.errorPath = it.util.getPathExpr(it.errorPath, $idx, it.opts.jsonPointers, true); |
| 2781 | var $passData = $data + '[' + $idx + ']'; |
| 2782 | $it.dataPathArr[$dataNxt] = $idx; |
| 2783 | var $code = it.validate($it); |
| 2784 | $it.baseId = $currentBaseId; |
| 2785 | if (it.util.varOccurences($code, $nextData) < 2) { |
| 2786 | out += ' ' + (it.util.varReplace($code, $nextData, $passData)) + ' '; |
| 2787 | } else { |
| 2788 | out += ' var ' + ($nextData) + ' = ' + ($passData) + '; ' + ($code) + ' '; |
| 2789 | } |
| 2790 | if ($breakOnError) { |
| 2791 | out += ' if (!' + ($nextValid) + ') break; '; |
| 2792 | } |
| 2793 | out += ' }'; |
| 2794 | } |
| 2795 | if ($breakOnError) { |
| 2796 | out += ' ' + ($closingBraces) + ' if (' + ($errs) + ' == errors) {'; |
| 2797 | } |
| 2798 | out = it.util.cleanUpCode(out); |
| 2799 | return out; |
| 2800 | } |
| 2801 | |
| 2802 | },{}],26:[function(require,module,exports){ |
| 2803 | 'use strict'; |
| 2804 | module.exports = function generate_multipleOf(it, $keyword, $ruleType) { |
| 2805 | var out = ' '; |
| 2806 | var $lvl = it.level; |
| 2807 | var $dataLvl = it.dataLevel; |
| 2808 | var $schema = it.schema[$keyword]; |
| 2809 | var $schemaPath = it.schemaPath + it.util.getProperty($keyword); |
| 2810 | var $errSchemaPath = it.errSchemaPath + '/' + $keyword; |
| 2811 | var $breakOnError = !it.opts.allErrors; |
| 2812 | var $data = 'data' + ($dataLvl || ''); |
| 2813 | var $isData = it.opts.$data && $schema && $schema.$data, |
| 2814 | $schemaValue; |
| 2815 | if ($isData) { |
| 2816 | out += ' var schema' + ($lvl) + ' = ' + (it.util.getData($schema.$data, $dataLvl, it.dataPathArr)) + '; '; |
| 2817 | $schemaValue = 'schema' + $lvl; |
| 2818 | } else { |
| 2819 | $schemaValue = $schema; |
| 2820 | } |
| 2821 | out += 'var division' + ($lvl) + ';if ('; |
| 2822 | if ($isData) { |
| 2823 | out += ' ' + ($schemaValue) + ' !== undefined && ( typeof ' + ($schemaValue) + ' != \'number\' || '; |
| 2824 | } |
| 2825 | out += ' (division' + ($lvl) + ' = ' + ($data) + ' / ' + ($schemaValue) + ', '; |
| 2826 | if (it.opts.multipleOfPrecision) { |
| 2827 | out += ' Math.abs(Math.round(division' + ($lvl) + ') - division' + ($lvl) + ') > 1e-' + (it.opts.multipleOfPrecision) + ' '; |
| 2828 | } else { |
| 2829 | out += ' division' + ($lvl) + ' !== parseInt(division' + ($lvl) + ') '; |
| 2830 | } |
| 2831 | out += ' ) '; |
| 2832 | if ($isData) { |
| 2833 | out += ' ) '; |
| 2834 | } |
| 2835 | out += ' ) { '; |
| 2836 | var $$outStack = $$outStack || []; |
| 2837 | $$outStack.push(out); |
| 2838 | out = ''; /* istanbul ignore else */ |
| 2839 | if (it.createErrors !== false) { |
| 2840 | out += ' { keyword: \'' + ('multipleOf') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: ' + (it.util.toQuotedString($errSchemaPath)) + ' , params: { multipleOf: ' + ($schemaValue) + ' } '; |
| 2841 | if (it.opts.messages !== false) { |
| 2842 | out += ' , message: \'should be multiple of '; |
| 2843 | if ($isData) { |
| 2844 | out += '\' + ' + ($schemaValue); |
| 2845 | } else { |
| 2846 | out += '' + ($schemaValue) + '\''; |
| 2847 | } |
| 2848 | } |
| 2849 | if (it.opts.verbose) { |
| 2850 | out += ' , schema: '; |
| 2851 | if ($isData) { |
| 2852 | out += 'validate.schema' + ($schemaPath); |
| 2853 | } else { |
| 2854 | out += '' + ($schema); |
| 2855 | } |
| 2856 | out += ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' '; |
| 2857 | } |
| 2858 | out += ' } '; |
| 2859 | } else { |
| 2860 | out += ' {} '; |
| 2861 | } |
| 2862 | var __err = out; |
| 2863 | out = $$outStack.pop(); |
| 2864 | if (!it.compositeRule && $breakOnError) { /* istanbul ignore if */ |
| 2865 | if (it.async) { |
| 2866 | out += ' throw new ValidationError([' + (__err) + ']); '; |
| 2867 | } else { |
| 2868 | out += ' validate.errors = [' + (__err) + ']; return false; '; |
| 2869 | } |
| 2870 | } else { |
| 2871 | out += ' var err = ' + (__err) + '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; '; |
| 2872 | } |
| 2873 | out += '} '; |
| 2874 | if ($breakOnError) { |
| 2875 | out += ' else { '; |
| 2876 | } |
| 2877 | return out; |
| 2878 | } |
| 2879 | |
| 2880 | },{}],27:[function(require,module,exports){ |
| 2881 | 'use strict'; |
| 2882 | module.exports = function generate_not(it, $keyword, $ruleType) { |
| 2883 | var out = ' '; |
| 2884 | var $lvl = it.level; |
| 2885 | var $dataLvl = it.dataLevel; |
| 2886 | var $schema = it.schema[$keyword]; |
| 2887 | var $schemaPath = it.schemaPath + it.util.getProperty($keyword); |
| 2888 | var $errSchemaPath = it.errSchemaPath + '/' + $keyword; |
| 2889 | var $breakOnError = !it.opts.allErrors; |
| 2890 | var $data = 'data' + ($dataLvl || ''); |
| 2891 | var $errs = 'errs__' + $lvl; |
| 2892 | var $it = it.util.copy(it); |
| 2893 | $it.level++; |
| 2894 | var $nextValid = 'valid' + $it.level; |
| 2895 | if (it.util.schemaHasRules($schema, it.RULES.all)) { |
| 2896 | $it.schema = $schema; |
| 2897 | $it.schemaPath = $schemaPath; |
| 2898 | $it.errSchemaPath = $errSchemaPath; |
| 2899 | out += ' var ' + ($errs) + ' = errors; '; |
| 2900 | var $wasComposite = it.compositeRule; |
| 2901 | it.compositeRule = $it.compositeRule = true; |
| 2902 | $it.createErrors = false; |
| 2903 | var $allErrorsOption; |
| 2904 | if ($it.opts.allErrors) { |
| 2905 | $allErrorsOption = $it.opts.allErrors; |
| 2906 | $it.opts.allErrors = false; |
| 2907 | } |
| 2908 | out += ' ' + (it.validate($it)) + ' '; |
| 2909 | $it.createErrors = true; |
| 2910 | if ($allErrorsOption) $it.opts.allErrors = $allErrorsOption; |
| 2911 | it.compositeRule = $it.compositeRule = $wasComposite; |
| 2912 | out += ' if (' + ($nextValid) + ') { '; |
| 2913 | var $$outStack = $$outStack || []; |
| 2914 | $$outStack.push(out); |
| 2915 | out = ''; /* istanbul ignore else */ |
| 2916 | if (it.createErrors !== false) { |
| 2917 | out += ' { keyword: \'' + ('not') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: ' + (it.util.toQuotedString($errSchemaPath)) + ' , params: {} '; |
| 2918 | if (it.opts.messages !== false) { |
| 2919 | out += ' , message: \'should NOT be valid\' '; |
| 2920 | } |
| 2921 | if (it.opts.verbose) { |
| 2922 | out += ' , schema: validate.schema' + ($schemaPath) + ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' '; |
| 2923 | } |
| 2924 | out += ' } '; |
| 2925 | } else { |
| 2926 | out += ' {} '; |
| 2927 | } |
| 2928 | var __err = out; |
| 2929 | out = $$outStack.pop(); |
| 2930 | if (!it.compositeRule && $breakOnError) { /* istanbul ignore if */ |
| 2931 | if (it.async) { |
| 2932 | out += ' throw new ValidationError([' + (__err) + ']); '; |
| 2933 | } else { |
| 2934 | out += ' validate.errors = [' + (__err) + ']; return false; '; |
| 2935 | } |
| 2936 | } else { |
| 2937 | out += ' var err = ' + (__err) + '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; '; |
| 2938 | } |
| 2939 | out += ' } else { errors = ' + ($errs) + '; if (vErrors !== null) { if (' + ($errs) + ') vErrors.length = ' + ($errs) + '; else vErrors = null; } '; |
| 2940 | if (it.opts.allErrors) { |
| 2941 | out += ' } '; |
| 2942 | } |
| 2943 | } else { |
| 2944 | out += ' var err = '; /* istanbul ignore else */ |
| 2945 | if (it.createErrors !== false) { |
| 2946 | out += ' { keyword: \'' + ('not') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: ' + (it.util.toQuotedString($errSchemaPath)) + ' , params: {} '; |
| 2947 | if (it.opts.messages !== false) { |
| 2948 | out += ' , message: \'should NOT be valid\' '; |
| 2949 | } |
| 2950 | if (it.opts.verbose) { |
| 2951 | out += ' , schema: validate.schema' + ($schemaPath) + ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' '; |
| 2952 | } |
| 2953 | out += ' } '; |
| 2954 | } else { |
| 2955 | out += ' {} '; |
| 2956 | } |
| 2957 | out += '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; '; |
| 2958 | if ($breakOnError) { |
| 2959 | out += ' if (false) { '; |
| 2960 | } |
| 2961 | } |
| 2962 | return out; |
| 2963 | } |
| 2964 | |
| 2965 | },{}],28:[function(require,module,exports){ |
| 2966 | 'use strict'; |
| 2967 | module.exports = function generate_oneOf(it, $keyword, $ruleType) { |
| 2968 | var out = ' '; |
| 2969 | var $lvl = it.level; |
| 2970 | var $dataLvl = it.dataLevel; |
| 2971 | var $schema = it.schema[$keyword]; |
| 2972 | var $schemaPath = it.schemaPath + it.util.getProperty($keyword); |
| 2973 | var $errSchemaPath = it.errSchemaPath + '/' + $keyword; |
| 2974 | var $breakOnError = !it.opts.allErrors; |
| 2975 | var $data = 'data' + ($dataLvl || ''); |
| 2976 | var $valid = 'valid' + $lvl; |
| 2977 | var $errs = 'errs__' + $lvl; |
| 2978 | var $it = it.util.copy(it); |
| 2979 | var $closingBraces = ''; |
| 2980 | $it.level++; |
| 2981 | var $nextValid = 'valid' + $it.level; |
| 2982 | out += 'var ' + ($errs) + ' = errors;var prevValid' + ($lvl) + ' = false;var ' + ($valid) + ' = false;'; |
| 2983 | var $currentBaseId = $it.baseId; |
| 2984 | var $wasComposite = it.compositeRule; |
| 2985 | it.compositeRule = $it.compositeRule = true; |
| 2986 | var arr1 = $schema; |
| 2987 | if (arr1) { |
| 2988 | var $sch, $i = -1, |
| 2989 | l1 = arr1.length - 1; |
| 2990 | while ($i < l1) { |
| 2991 | $sch = arr1[$i += 1]; |
| 2992 | if (it.util.schemaHasRules($sch, it.RULES.all)) { |
| 2993 | $it.schema = $sch; |
| 2994 | $it.schemaPath = $schemaPath + '[' + $i + ']'; |
| 2995 | $it.errSchemaPath = $errSchemaPath + '/' + $i; |
| 2996 | out += ' ' + (it.validate($it)) + ' '; |
| 2997 | $it.baseId = $currentBaseId; |
| 2998 | } else { |
| 2999 | out += ' var ' + ($nextValid) + ' = true; '; |
| 3000 | } |
| 3001 | if ($i) { |
| 3002 | out += ' if (' + ($nextValid) + ' && prevValid' + ($lvl) + ') ' + ($valid) + ' = false; else { '; |
| 3003 | $closingBraces += '}'; |
| 3004 | } |
| 3005 | out += ' if (' + ($nextValid) + ') ' + ($valid) + ' = prevValid' + ($lvl) + ' = true;'; |
| 3006 | } |
| 3007 | } |
| 3008 | it.compositeRule = $it.compositeRule = $wasComposite; |
| 3009 | out += '' + ($closingBraces) + 'if (!' + ($valid) + ') { var err = '; /* istanbul ignore else */ |
| 3010 | if (it.createErrors !== false) { |
| 3011 | out += ' { keyword: \'' + ('oneOf') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: ' + (it.util.toQuotedString($errSchemaPath)) + ' , params: {} '; |
| 3012 | if (it.opts.messages !== false) { |
| 3013 | out += ' , message: \'should match exactly one schema in oneOf\' '; |
| 3014 | } |
| 3015 | if (it.opts.verbose) { |
| 3016 | out += ' , schema: validate.schema' + ($schemaPath) + ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' '; |
| 3017 | } |
| 3018 | out += ' } '; |
| 3019 | } else { |
| 3020 | out += ' {} '; |
| 3021 | } |
| 3022 | out += '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; '; |
| 3023 | if (!it.compositeRule && $breakOnError) { /* istanbul ignore if */ |
| 3024 | if (it.async) { |
| 3025 | out += ' throw new ValidationError(vErrors); '; |
| 3026 | } else { |
| 3027 | out += ' validate.errors = vErrors; return false; '; |
| 3028 | } |
| 3029 | } |
| 3030 | out += '} else { errors = ' + ($errs) + '; if (vErrors !== null) { if (' + ($errs) + ') vErrors.length = ' + ($errs) + '; else vErrors = null; }'; |
| 3031 | if (it.opts.allErrors) { |
| 3032 | out += ' } '; |
| 3033 | } |
| 3034 | return out; |
| 3035 | } |
| 3036 | |
| 3037 | },{}],29:[function(require,module,exports){ |
| 3038 | 'use strict'; |
| 3039 | module.exports = function generate_pattern(it, $keyword, $ruleType) { |
| 3040 | var out = ' '; |
| 3041 | var $lvl = it.level; |
| 3042 | var $dataLvl = it.dataLevel; |
| 3043 | var $schema = it.schema[$keyword]; |
| 3044 | var $schemaPath = it.schemaPath + it.util.getProperty($keyword); |
| 3045 | var $errSchemaPath = it.errSchemaPath + '/' + $keyword; |
| 3046 | var $breakOnError = !it.opts.allErrors; |
| 3047 | var $data = 'data' + ($dataLvl || ''); |
| 3048 | var $isData = it.opts.$data && $schema && $schema.$data, |
| 3049 | $schemaValue; |
| 3050 | if ($isData) { |
| 3051 | out += ' var schema' + ($lvl) + ' = ' + (it.util.getData($schema.$data, $dataLvl, it.dataPathArr)) + '; '; |
| 3052 | $schemaValue = 'schema' + $lvl; |
| 3053 | } else { |
| 3054 | $schemaValue = $schema; |
| 3055 | } |
| 3056 | var $regexp = $isData ? '(new RegExp(' + $schemaValue + '))' : it.usePattern($schema); |
| 3057 | out += 'if ( '; |
| 3058 | if ($isData) { |
| 3059 | out += ' (' + ($schemaValue) + ' !== undefined && typeof ' + ($schemaValue) + ' != \'string\') || '; |
| 3060 | } |
| 3061 | out += ' !' + ($regexp) + '.test(' + ($data) + ') ) { '; |
| 3062 | var $$outStack = $$outStack || []; |
| 3063 | $$outStack.push(out); |
| 3064 | out = ''; /* istanbul ignore else */ |
| 3065 | if (it.createErrors !== false) { |
| 3066 | out += ' { keyword: \'' + ('pattern') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: ' + (it.util.toQuotedString($errSchemaPath)) + ' , params: { pattern: '; |
| 3067 | if ($isData) { |
| 3068 | out += '' + ($schemaValue); |
| 3069 | } else { |
| 3070 | out += '' + (it.util.toQuotedString($schema)); |
| 3071 | } |
| 3072 | out += ' } '; |
| 3073 | if (it.opts.messages !== false) { |
| 3074 | out += ' , message: \'should match pattern "'; |
| 3075 | if ($isData) { |
| 3076 | out += '\' + ' + ($schemaValue) + ' + \''; |
| 3077 | } else { |
| 3078 | out += '' + (it.util.escapeQuotes($schema)); |
| 3079 | } |
| 3080 | out += '"\' '; |
| 3081 | } |
| 3082 | if (it.opts.verbose) { |
| 3083 | out += ' , schema: '; |
| 3084 | if ($isData) { |
| 3085 | out += 'validate.schema' + ($schemaPath); |
| 3086 | } else { |
| 3087 | out += '' + (it.util.toQuotedString($schema)); |
| 3088 | } |
| 3089 | out += ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' '; |
| 3090 | } |
| 3091 | out += ' } '; |
| 3092 | } else { |
| 3093 | out += ' {} '; |
| 3094 | } |
| 3095 | var __err = out; |
| 3096 | out = $$outStack.pop(); |
| 3097 | if (!it.compositeRule && $breakOnError) { /* istanbul ignore if */ |
| 3098 | if (it.async) { |
| 3099 | out += ' throw new ValidationError([' + (__err) + ']); '; |
| 3100 | } else { |
| 3101 | out += ' validate.errors = [' + (__err) + ']; return false; '; |
| 3102 | } |
| 3103 | } else { |
| 3104 | out += ' var err = ' + (__err) + '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; '; |
| 3105 | } |
| 3106 | out += '} '; |
| 3107 | if ($breakOnError) { |
| 3108 | out += ' else { '; |
| 3109 | } |
| 3110 | return out; |
| 3111 | } |
| 3112 | |
| 3113 | },{}],30:[function(require,module,exports){ |
| 3114 | 'use strict'; |
| 3115 | module.exports = function generate_properties(it, $keyword, $ruleType) { |
| 3116 | var out = ' '; |
| 3117 | var $lvl = it.level; |
| 3118 | var $dataLvl = it.dataLevel; |
| 3119 | var $schema = it.schema[$keyword]; |
| 3120 | var $schemaPath = it.schemaPath + it.util.getProperty($keyword); |
| 3121 | var $errSchemaPath = it.errSchemaPath + '/' + $keyword; |
| 3122 | var $breakOnError = !it.opts.allErrors; |
| 3123 | var $data = 'data' + ($dataLvl || ''); |
| 3124 | var $valid = 'valid' + $lvl; |
| 3125 | var $errs = 'errs__' + $lvl; |
| 3126 | var $it = it.util.copy(it); |
| 3127 | var $closingBraces = ''; |
| 3128 | $it.level++; |
| 3129 | var $nextValid = 'valid' + $it.level; |
| 3130 | var $key = 'key' + $lvl, |
| 3131 | $idx = 'idx' + $lvl, |
| 3132 | $dataNxt = $it.dataLevel = it.dataLevel + 1, |
| 3133 | $nextData = 'data' + $dataNxt, |
| 3134 | $dataProperties = 'dataProperties' + $lvl; |
| 3135 | var $schemaKeys = Object.keys($schema || {}), |
| 3136 | $pProperties = it.schema.patternProperties || {}, |
| 3137 | $pPropertyKeys = Object.keys($pProperties), |
| 3138 | $aProperties = it.schema.additionalProperties, |
| 3139 | $someProperties = $schemaKeys.length || $pPropertyKeys.length, |
| 3140 | $noAdditional = $aProperties === false, |
| 3141 | $additionalIsSchema = typeof $aProperties == 'object' && Object.keys($aProperties).length, |
| 3142 | $removeAdditional = it.opts.removeAdditional, |
| 3143 | $checkAdditional = $noAdditional || $additionalIsSchema || $removeAdditional, |
| 3144 | $ownProperties = it.opts.ownProperties, |
| 3145 | $currentBaseId = it.baseId; |
| 3146 | var $required = it.schema.required; |
| 3147 | if ($required && !(it.opts.v5 && $required.$data) && $required.length < it.opts.loopRequired) var $requiredHash = it.util.toHash($required); |
| 3148 | if (it.opts.patternGroups) { |
| 3149 | var $pgProperties = it.schema.patternGroups || {}, |
| 3150 | $pgPropertyKeys = Object.keys($pgProperties); |
| 3151 | } |
| 3152 | out += 'var ' + ($errs) + ' = errors;var ' + ($nextValid) + ' = true;'; |
| 3153 | if ($ownProperties) { |
| 3154 | out += ' var ' + ($dataProperties) + ' = undefined;'; |
| 3155 | } |
| 3156 | if ($checkAdditional) { |
| 3157 | if ($ownProperties) { |
| 3158 | out += ' ' + ($dataProperties) + ' = ' + ($dataProperties) + ' || Object.keys(' + ($data) + '); for (var ' + ($idx) + '=0; ' + ($idx) + '<' + ($dataProperties) + '.length; ' + ($idx) + '++) { var ' + ($key) + ' = ' + ($dataProperties) + '[' + ($idx) + ']; '; |
| 3159 | } else { |
| 3160 | out += ' for (var ' + ($key) + ' in ' + ($data) + ') { '; |
| 3161 | } |
| 3162 | if ($someProperties) { |
| 3163 | out += ' var isAdditional' + ($lvl) + ' = !(false '; |
| 3164 | if ($schemaKeys.length) { |
| 3165 | if ($schemaKeys.length > 5) { |
| 3166 | out += ' || validate.schema' + ($schemaPath) + '[' + ($key) + '] '; |
| 3167 | } else { |
| 3168 | var arr1 = $schemaKeys; |
| 3169 | if (arr1) { |
| 3170 | var $propertyKey, i1 = -1, |
| 3171 | l1 = arr1.length - 1; |
| 3172 | while (i1 < l1) { |
| 3173 | $propertyKey = arr1[i1 += 1]; |
| 3174 | out += ' || ' + ($key) + ' == ' + (it.util.toQuotedString($propertyKey)) + ' '; |
| 3175 | } |
| 3176 | } |
| 3177 | } |
| 3178 | } |
| 3179 | if ($pPropertyKeys.length) { |
| 3180 | var arr2 = $pPropertyKeys; |
| 3181 | if (arr2) { |
| 3182 | var $pProperty, $i = -1, |
| 3183 | l2 = arr2.length - 1; |
| 3184 | while ($i < l2) { |
| 3185 | $pProperty = arr2[$i += 1]; |
| 3186 | out += ' || ' + (it.usePattern($pProperty)) + '.test(' + ($key) + ') '; |
| 3187 | } |
| 3188 | } |
| 3189 | } |
| 3190 | if (it.opts.patternGroups && $pgPropertyKeys.length) { |
| 3191 | var arr3 = $pgPropertyKeys; |
| 3192 | if (arr3) { |
| 3193 | var $pgProperty, $i = -1, |
| 3194 | l3 = arr3.length - 1; |
| 3195 | while ($i < l3) { |
| 3196 | $pgProperty = arr3[$i += 1]; |
| 3197 | out += ' || ' + (it.usePattern($pgProperty)) + '.test(' + ($key) + ') '; |
| 3198 | } |
| 3199 | } |
| 3200 | } |
| 3201 | out += ' ); if (isAdditional' + ($lvl) + ') { '; |
| 3202 | } |
| 3203 | if ($removeAdditional == 'all') { |
| 3204 | out += ' delete ' + ($data) + '[' + ($key) + ']; '; |
| 3205 | } else { |
| 3206 | var $currentErrorPath = it.errorPath; |
| 3207 | var $additionalProperty = '\' + ' + $key + ' + \''; |
| 3208 | if (it.opts._errorDataPathProperty) { |
| 3209 | it.errorPath = it.util.getPathExpr(it.errorPath, $key, it.opts.jsonPointers); |
| 3210 | } |
| 3211 | if ($noAdditional) { |
| 3212 | if ($removeAdditional) { |
| 3213 | out += ' delete ' + ($data) + '[' + ($key) + ']; '; |
| 3214 | } else { |
| 3215 | out += ' ' + ($nextValid) + ' = false; '; |
| 3216 | var $currErrSchemaPath = $errSchemaPath; |
| 3217 | $errSchemaPath = it.errSchemaPath + '/additionalProperties'; |
| 3218 | var $$outStack = $$outStack || []; |
| 3219 | $$outStack.push(out); |
| 3220 | out = ''; /* istanbul ignore else */ |
| 3221 | if (it.createErrors !== false) { |
| 3222 | out += ' { keyword: \'' + ('additionalProperties') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: ' + (it.util.toQuotedString($errSchemaPath)) + ' , params: { additionalProperty: \'' + ($additionalProperty) + '\' } '; |
| 3223 | if (it.opts.messages !== false) { |
| 3224 | out += ' , message: \'should NOT have additional properties\' '; |
| 3225 | } |
| 3226 | if (it.opts.verbose) { |
| 3227 | out += ' , schema: false , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' '; |
| 3228 | } |
| 3229 | out += ' } '; |
| 3230 | } else { |
| 3231 | out += ' {} '; |
| 3232 | } |
| 3233 | var __err = out; |
| 3234 | out = $$outStack.pop(); |
| 3235 | if (!it.compositeRule && $breakOnError) { /* istanbul ignore if */ |
| 3236 | if (it.async) { |
| 3237 | out += ' throw new ValidationError([' + (__err) + ']); '; |
| 3238 | } else { |
| 3239 | out += ' validate.errors = [' + (__err) + ']; return false; '; |
| 3240 | } |
| 3241 | } else { |
| 3242 | out += ' var err = ' + (__err) + '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; '; |
| 3243 | } |
| 3244 | $errSchemaPath = $currErrSchemaPath; |
| 3245 | if ($breakOnError) { |
| 3246 | out += ' break; '; |
| 3247 | } |
| 3248 | } |
| 3249 | } else if ($additionalIsSchema) { |
| 3250 | if ($removeAdditional == 'failing') { |
| 3251 | out += ' var ' + ($errs) + ' = errors; '; |
| 3252 | var $wasComposite = it.compositeRule; |
| 3253 | it.compositeRule = $it.compositeRule = true; |
| 3254 | $it.schema = $aProperties; |
| 3255 | $it.schemaPath = it.schemaPath + '.additionalProperties'; |
| 3256 | $it.errSchemaPath = it.errSchemaPath + '/additionalProperties'; |
| 3257 | $it.errorPath = it.opts._errorDataPathProperty ? it.errorPath : it.util.getPathExpr(it.errorPath, $key, it.opts.jsonPointers); |
| 3258 | var $passData = $data + '[' + $key + ']'; |
| 3259 | $it.dataPathArr[$dataNxt] = $key; |
| 3260 | var $code = it.validate($it); |
| 3261 | $it.baseId = $currentBaseId; |
| 3262 | if (it.util.varOccurences($code, $nextData) < 2) { |
| 3263 | out += ' ' + (it.util.varReplace($code, $nextData, $passData)) + ' '; |
| 3264 | } else { |
| 3265 | out += ' var ' + ($nextData) + ' = ' + ($passData) + '; ' + ($code) + ' '; |
| 3266 | } |
| 3267 | out += ' if (!' + ($nextValid) + ') { errors = ' + ($errs) + '; if (validate.errors !== null) { if (errors) validate.errors.length = errors; else validate.errors = null; } delete ' + ($data) + '[' + ($key) + ']; } '; |
| 3268 | it.compositeRule = $it.compositeRule = $wasComposite; |
| 3269 | } else { |
| 3270 | $it.schema = $aProperties; |
| 3271 | $it.schemaPath = it.schemaPath + '.additionalProperties'; |
| 3272 | $it.errSchemaPath = it.errSchemaPath + '/additionalProperties'; |
| 3273 | $it.errorPath = it.opts._errorDataPathProperty ? it.errorPath : it.util.getPathExpr(it.errorPath, $key, it.opts.jsonPointers); |
| 3274 | var $passData = $data + '[' + $key + ']'; |
| 3275 | $it.dataPathArr[$dataNxt] = $key; |
| 3276 | var $code = it.validate($it); |
| 3277 | $it.baseId = $currentBaseId; |
| 3278 | if (it.util.varOccurences($code, $nextData) < 2) { |
| 3279 | out += ' ' + (it.util.varReplace($code, $nextData, $passData)) + ' '; |
| 3280 | } else { |
| 3281 | out += ' var ' + ($nextData) + ' = ' + ($passData) + '; ' + ($code) + ' '; |
| 3282 | } |
| 3283 | if ($breakOnError) { |
| 3284 | out += ' if (!' + ($nextValid) + ') break; '; |
| 3285 | } |
| 3286 | } |
| 3287 | } |
| 3288 | it.errorPath = $currentErrorPath; |
| 3289 | } |
| 3290 | if ($someProperties) { |
| 3291 | out += ' } '; |
| 3292 | } |
| 3293 | out += ' } '; |
| 3294 | if ($breakOnError) { |
| 3295 | out += ' if (' + ($nextValid) + ') { '; |
| 3296 | $closingBraces += '}'; |
| 3297 | } |
| 3298 | } |
| 3299 | var $useDefaults = it.opts.useDefaults && !it.compositeRule; |
| 3300 | if ($schemaKeys.length) { |
| 3301 | var arr4 = $schemaKeys; |
| 3302 | if (arr4) { |
| 3303 | var $propertyKey, i4 = -1, |
| 3304 | l4 = arr4.length - 1; |
| 3305 | while (i4 < l4) { |
| 3306 | $propertyKey = arr4[i4 += 1]; |
| 3307 | var $sch = $schema[$propertyKey]; |
| 3308 | if (it.util.schemaHasRules($sch, it.RULES.all)) { |
| 3309 | var $prop = it.util.getProperty($propertyKey), |
| 3310 | $passData = $data + $prop, |
| 3311 | $hasDefault = $useDefaults && $sch.default !== undefined; |
| 3312 | $it.schema = $sch; |
| 3313 | $it.schemaPath = $schemaPath + $prop; |
| 3314 | $it.errSchemaPath = $errSchemaPath + '/' + it.util.escapeFragment($propertyKey); |
| 3315 | $it.errorPath = it.util.getPath(it.errorPath, $propertyKey, it.opts.jsonPointers); |
| 3316 | $it.dataPathArr[$dataNxt] = it.util.toQuotedString($propertyKey); |
| 3317 | var $code = it.validate($it); |
| 3318 | $it.baseId = $currentBaseId; |
| 3319 | if (it.util.varOccurences($code, $nextData) < 2) { |
| 3320 | $code = it.util.varReplace($code, $nextData, $passData); |
| 3321 | var $useData = $passData; |
| 3322 | } else { |
| 3323 | var $useData = $nextData; |
| 3324 | out += ' var ' + ($nextData) + ' = ' + ($passData) + '; '; |
| 3325 | } |
| 3326 | if ($hasDefault) { |
| 3327 | out += ' ' + ($code) + ' '; |
| 3328 | } else { |
| 3329 | if ($requiredHash && $requiredHash[$propertyKey]) { |
| 3330 | out += ' if ( ' + ($useData) + ' === undefined '; |
| 3331 | if ($ownProperties) { |
| 3332 | out += ' || ! Object.prototype.hasOwnProperty.call(' + ($data) + ', \'' + (it.util.escapeQuotes($propertyKey)) + '\') '; |
| 3333 | } |
| 3334 | out += ') { ' + ($nextValid) + ' = false; '; |
| 3335 | var $currentErrorPath = it.errorPath, |
| 3336 | $currErrSchemaPath = $errSchemaPath, |
| 3337 | $missingProperty = it.util.escapeQuotes($propertyKey); |
| 3338 | if (it.opts._errorDataPathProperty) { |
| 3339 | it.errorPath = it.util.getPath($currentErrorPath, $propertyKey, it.opts.jsonPointers); |
| 3340 | } |
| 3341 | $errSchemaPath = it.errSchemaPath + '/required'; |
| 3342 | var $$outStack = $$outStack || []; |
| 3343 | $$outStack.push(out); |
| 3344 | out = ''; /* istanbul ignore else */ |
| 3345 | if (it.createErrors !== false) { |
| 3346 | out += ' { keyword: \'' + ('required') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: ' + (it.util.toQuotedString($errSchemaPath)) + ' , params: { missingProperty: \'' + ($missingProperty) + '\' } '; |
| 3347 | if (it.opts.messages !== false) { |
| 3348 | out += ' , message: \''; |
| 3349 | if (it.opts._errorDataPathProperty) { |
| 3350 | out += 'is a required property'; |
| 3351 | } else { |
| 3352 | out += 'should have required property \\\'' + ($missingProperty) + '\\\''; |
| 3353 | } |
| 3354 | out += '\' '; |
| 3355 | } |
| 3356 | if (it.opts.verbose) { |
| 3357 | out += ' , schema: validate.schema' + ($schemaPath) + ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' '; |
| 3358 | } |
| 3359 | out += ' } '; |
| 3360 | } else { |
| 3361 | out += ' {} '; |
| 3362 | } |
| 3363 | var __err = out; |
| 3364 | out = $$outStack.pop(); |
| 3365 | if (!it.compositeRule && $breakOnError) { /* istanbul ignore if */ |
| 3366 | if (it.async) { |
| 3367 | out += ' throw new ValidationError([' + (__err) + ']); '; |
| 3368 | } else { |
| 3369 | out += ' validate.errors = [' + (__err) + ']; return false; '; |
| 3370 | } |
| 3371 | } else { |
| 3372 | out += ' var err = ' + (__err) + '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; '; |
| 3373 | } |
| 3374 | $errSchemaPath = $currErrSchemaPath; |
| 3375 | it.errorPath = $currentErrorPath; |
| 3376 | out += ' } else { '; |
| 3377 | } else { |
| 3378 | if ($breakOnError) { |
| 3379 | out += ' if ( ' + ($useData) + ' === undefined '; |
| 3380 | if ($ownProperties) { |
| 3381 | out += ' || ! Object.prototype.hasOwnProperty.call(' + ($data) + ', \'' + (it.util.escapeQuotes($propertyKey)) + '\') '; |
| 3382 | } |
| 3383 | out += ') { ' + ($nextValid) + ' = true; } else { '; |
| 3384 | } else { |
| 3385 | out += ' if (' + ($useData) + ' !== undefined '; |
| 3386 | if ($ownProperties) { |
| 3387 | out += ' && Object.prototype.hasOwnProperty.call(' + ($data) + ', \'' + (it.util.escapeQuotes($propertyKey)) + '\') '; |
| 3388 | } |
| 3389 | out += ' ) { '; |
| 3390 | } |
| 3391 | } |
| 3392 | out += ' ' + ($code) + ' } '; |
| 3393 | } |
| 3394 | } |
| 3395 | if ($breakOnError) { |
| 3396 | out += ' if (' + ($nextValid) + ') { '; |
| 3397 | $closingBraces += '}'; |
| 3398 | } |
| 3399 | } |
| 3400 | } |
| 3401 | } |
| 3402 | if ($pPropertyKeys.length) { |
| 3403 | var arr5 = $pPropertyKeys; |
| 3404 | if (arr5) { |
| 3405 | var $pProperty, i5 = -1, |
| 3406 | l5 = arr5.length - 1; |
| 3407 | while (i5 < l5) { |
| 3408 | $pProperty = arr5[i5 += 1]; |
| 3409 | var $sch = $pProperties[$pProperty]; |
| 3410 | if (it.util.schemaHasRules($sch, it.RULES.all)) { |
| 3411 | $it.schema = $sch; |
| 3412 | $it.schemaPath = it.schemaPath + '.patternProperties' + it.util.getProperty($pProperty); |
| 3413 | $it.errSchemaPath = it.errSchemaPath + '/patternProperties/' + it.util.escapeFragment($pProperty); |
| 3414 | if ($ownProperties) { |
| 3415 | out += ' ' + ($dataProperties) + ' = ' + ($dataProperties) + ' || Object.keys(' + ($data) + '); for (var ' + ($idx) + '=0; ' + ($idx) + '<' + ($dataProperties) + '.length; ' + ($idx) + '++) { var ' + ($key) + ' = ' + ($dataProperties) + '[' + ($idx) + ']; '; |
| 3416 | } else { |
| 3417 | out += ' for (var ' + ($key) + ' in ' + ($data) + ') { '; |
| 3418 | } |
| 3419 | out += ' if (' + (it.usePattern($pProperty)) + '.test(' + ($key) + ')) { '; |
| 3420 | $it.errorPath = it.util.getPathExpr(it.errorPath, $key, it.opts.jsonPointers); |
| 3421 | var $passData = $data + '[' + $key + ']'; |
| 3422 | $it.dataPathArr[$dataNxt] = $key; |
| 3423 | var $code = it.validate($it); |
| 3424 | $it.baseId = $currentBaseId; |
| 3425 | if (it.util.varOccurences($code, $nextData) < 2) { |
| 3426 | out += ' ' + (it.util.varReplace($code, $nextData, $passData)) + ' '; |
| 3427 | } else { |
| 3428 | out += ' var ' + ($nextData) + ' = ' + ($passData) + '; ' + ($code) + ' '; |
| 3429 | } |
| 3430 | if ($breakOnError) { |
| 3431 | out += ' if (!' + ($nextValid) + ') break; '; |
| 3432 | } |
| 3433 | out += ' } '; |
| 3434 | if ($breakOnError) { |
| 3435 | out += ' else ' + ($nextValid) + ' = true; '; |
| 3436 | } |
| 3437 | out += ' } '; |
| 3438 | if ($breakOnError) { |
| 3439 | out += ' if (' + ($nextValid) + ') { '; |
| 3440 | $closingBraces += '}'; |
| 3441 | } |
| 3442 | } |
| 3443 | } |
| 3444 | } |
| 3445 | } |
| 3446 | if (it.opts.patternGroups && $pgPropertyKeys.length) { |
| 3447 | var arr6 = $pgPropertyKeys; |
| 3448 | if (arr6) { |
| 3449 | var $pgProperty, i6 = -1, |
| 3450 | l6 = arr6.length - 1; |
| 3451 | while (i6 < l6) { |
| 3452 | $pgProperty = arr6[i6 += 1]; |
| 3453 | var $pgSchema = $pgProperties[$pgProperty], |
| 3454 | $sch = $pgSchema.schema; |
| 3455 | if (it.util.schemaHasRules($sch, it.RULES.all)) { |
| 3456 | $it.schema = $sch; |
| 3457 | $it.schemaPath = it.schemaPath + '.patternGroups' + it.util.getProperty($pgProperty) + '.schema'; |
| 3458 | $it.errSchemaPath = it.errSchemaPath + '/patternGroups/' + it.util.escapeFragment($pgProperty) + '/schema'; |
| 3459 | out += ' var pgPropCount' + ($lvl) + ' = 0; '; |
| 3460 | if ($ownProperties) { |
| 3461 | out += ' ' + ($dataProperties) + ' = ' + ($dataProperties) + ' || Object.keys(' + ($data) + '); for (var ' + ($idx) + '=0; ' + ($idx) + '<' + ($dataProperties) + '.length; ' + ($idx) + '++) { var ' + ($key) + ' = ' + ($dataProperties) + '[' + ($idx) + ']; '; |
| 3462 | } else { |
| 3463 | out += ' for (var ' + ($key) + ' in ' + ($data) + ') { '; |
| 3464 | } |
| 3465 | out += ' if (' + (it.usePattern($pgProperty)) + '.test(' + ($key) + ')) { pgPropCount' + ($lvl) + '++; '; |
| 3466 | $it.errorPath = it.util.getPathExpr(it.errorPath, $key, it.opts.jsonPointers); |
| 3467 | var $passData = $data + '[' + $key + ']'; |
| 3468 | $it.dataPathArr[$dataNxt] = $key; |
| 3469 | var $code = it.validate($it); |
| 3470 | $it.baseId = $currentBaseId; |
| 3471 | if (it.util.varOccurences($code, $nextData) < 2) { |
| 3472 | out += ' ' + (it.util.varReplace($code, $nextData, $passData)) + ' '; |
| 3473 | } else { |
| 3474 | out += ' var ' + ($nextData) + ' = ' + ($passData) + '; ' + ($code) + ' '; |
| 3475 | } |
| 3476 | if ($breakOnError) { |
| 3477 | out += ' if (!' + ($nextValid) + ') break; '; |
| 3478 | } |
| 3479 | out += ' } '; |
| 3480 | if ($breakOnError) { |
| 3481 | out += ' else ' + ($nextValid) + ' = true; '; |
| 3482 | } |
| 3483 | out += ' } '; |
| 3484 | if ($breakOnError) { |
| 3485 | out += ' if (' + ($nextValid) + ') { '; |
| 3486 | $closingBraces += '}'; |
| 3487 | } |
| 3488 | var $pgMin = $pgSchema.minimum, |
| 3489 | $pgMax = $pgSchema.maximum; |
| 3490 | if ($pgMin !== undefined || $pgMax !== undefined) { |
| 3491 | out += ' var ' + ($valid) + ' = true; '; |
| 3492 | var $currErrSchemaPath = $errSchemaPath; |
| 3493 | if ($pgMin !== undefined) { |
| 3494 | var $limit = $pgMin, |
| 3495 | $reason = 'minimum', |
| 3496 | $moreOrLess = 'less'; |
| 3497 | out += ' ' + ($valid) + ' = pgPropCount' + ($lvl) + ' >= ' + ($pgMin) + '; '; |
| 3498 | $errSchemaPath = it.errSchemaPath + '/patternGroups/minimum'; |
| 3499 | out += ' if (!' + ($valid) + ') { '; |
| 3500 | var $$outStack = $$outStack || []; |
| 3501 | $$outStack.push(out); |
| 3502 | out = ''; /* istanbul ignore else */ |
| 3503 | if (it.createErrors !== false) { |
| 3504 | out += ' { keyword: \'' + ('patternGroups') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: ' + (it.util.toQuotedString($errSchemaPath)) + ' , params: { reason: \'' + ($reason) + '\', limit: ' + ($limit) + ', pattern: \'' + (it.util.escapeQuotes($pgProperty)) + '\' } '; |
| 3505 | if (it.opts.messages !== false) { |
| 3506 | out += ' , message: \'should NOT have ' + ($moreOrLess) + ' than ' + ($limit) + ' properties matching pattern "' + (it.util.escapeQuotes($pgProperty)) + '"\' '; |
| 3507 | } |
| 3508 | if (it.opts.verbose) { |
| 3509 | out += ' , schema: validate.schema' + ($schemaPath) + ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' '; |
| 3510 | } |
| 3511 | out += ' } '; |
| 3512 | } else { |
| 3513 | out += ' {} '; |
| 3514 | } |
| 3515 | var __err = out; |
| 3516 | out = $$outStack.pop(); |
| 3517 | if (!it.compositeRule && $breakOnError) { /* istanbul ignore if */ |
| 3518 | if (it.async) { |
| 3519 | out += ' throw new ValidationError([' + (__err) + ']); '; |
| 3520 | } else { |
| 3521 | out += ' validate.errors = [' + (__err) + ']; return false; '; |
| 3522 | } |
| 3523 | } else { |
| 3524 | out += ' var err = ' + (__err) + '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; '; |
| 3525 | } |
| 3526 | out += ' } '; |
| 3527 | if ($pgMax !== undefined) { |
| 3528 | out += ' else '; |
| 3529 | } |
| 3530 | } |
| 3531 | if ($pgMax !== undefined) { |
| 3532 | var $limit = $pgMax, |
| 3533 | $reason = 'maximum', |
| 3534 | $moreOrLess = 'more'; |
| 3535 | out += ' ' + ($valid) + ' = pgPropCount' + ($lvl) + ' <= ' + ($pgMax) + '; '; |
| 3536 | $errSchemaPath = it.errSchemaPath + '/patternGroups/maximum'; |
| 3537 | out += ' if (!' + ($valid) + ') { '; |
| 3538 | var $$outStack = $$outStack || []; |
| 3539 | $$outStack.push(out); |
| 3540 | out = ''; /* istanbul ignore else */ |
| 3541 | if (it.createErrors !== false) { |
| 3542 | out += ' { keyword: \'' + ('patternGroups') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: ' + (it.util.toQuotedString($errSchemaPath)) + ' , params: { reason: \'' + ($reason) + '\', limit: ' + ($limit) + ', pattern: \'' + (it.util.escapeQuotes($pgProperty)) + '\' } '; |
| 3543 | if (it.opts.messages !== false) { |
| 3544 | out += ' , message: \'should NOT have ' + ($moreOrLess) + ' than ' + ($limit) + ' properties matching pattern "' + (it.util.escapeQuotes($pgProperty)) + '"\' '; |
| 3545 | } |
| 3546 | if (it.opts.verbose) { |
| 3547 | out += ' , schema: validate.schema' + ($schemaPath) + ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' '; |
| 3548 | } |
| 3549 | out += ' } '; |
| 3550 | } else { |
| 3551 | out += ' {} '; |
| 3552 | } |
| 3553 | var __err = out; |
| 3554 | out = $$outStack.pop(); |
| 3555 | if (!it.compositeRule && $breakOnError) { /* istanbul ignore if */ |
| 3556 | if (it.async) { |
| 3557 | out += ' throw new ValidationError([' + (__err) + ']); '; |
| 3558 | } else { |
| 3559 | out += ' validate.errors = [' + (__err) + ']; return false; '; |
| 3560 | } |
| 3561 | } else { |
| 3562 | out += ' var err = ' + (__err) + '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; '; |
| 3563 | } |
| 3564 | out += ' } '; |
| 3565 | } |
| 3566 | $errSchemaPath = $currErrSchemaPath; |
| 3567 | if ($breakOnError) { |
| 3568 | out += ' if (' + ($valid) + ') { '; |
| 3569 | $closingBraces += '}'; |
| 3570 | } |
| 3571 | } |
| 3572 | } |
| 3573 | } |
| 3574 | } |
| 3575 | } |
| 3576 | if ($breakOnError) { |
| 3577 | out += ' ' + ($closingBraces) + ' if (' + ($errs) + ' == errors) {'; |
| 3578 | } |
| 3579 | out = it.util.cleanUpCode(out); |
| 3580 | return out; |
| 3581 | } |
| 3582 | |
| 3583 | },{}],31:[function(require,module,exports){ |
| 3584 | 'use strict'; |
| 3585 | module.exports = function generate_propertyNames(it, $keyword, $ruleType) { |
| 3586 | var out = ' '; |
| 3587 | var $lvl = it.level; |
| 3588 | var $dataLvl = it.dataLevel; |
| 3589 | var $schema = it.schema[$keyword]; |
| 3590 | var $schemaPath = it.schemaPath + it.util.getProperty($keyword); |
| 3591 | var $errSchemaPath = it.errSchemaPath + '/' + $keyword; |
| 3592 | var $breakOnError = !it.opts.allErrors; |
| 3593 | var $data = 'data' + ($dataLvl || ''); |
| 3594 | var $errs = 'errs__' + $lvl; |
| 3595 | var $it = it.util.copy(it); |
| 3596 | var $closingBraces = ''; |
| 3597 | $it.level++; |
| 3598 | var $nextValid = 'valid' + $it.level; |
| 3599 | if (it.util.schemaHasRules($schema, it.RULES.all)) { |
| 3600 | $it.schema = $schema; |
| 3601 | $it.schemaPath = $schemaPath; |
| 3602 | $it.errSchemaPath = $errSchemaPath; |
| 3603 | var $key = 'key' + $lvl, |
| 3604 | $idx = 'idx' + $lvl, |
| 3605 | $i = 'i' + $lvl, |
| 3606 | $invalidName = '\' + ' + $key + ' + \'', |
| 3607 | $dataNxt = $it.dataLevel = it.dataLevel + 1, |
| 3608 | $nextData = 'data' + $dataNxt, |
| 3609 | $dataProperties = 'dataProperties' + $lvl, |
| 3610 | $ownProperties = it.opts.ownProperties, |
| 3611 | $currentBaseId = it.baseId; |
| 3612 | out += ' var ' + ($errs) + ' = errors; '; |
| 3613 | if ($ownProperties) { |
| 3614 | out += ' var ' + ($dataProperties) + ' = undefined; '; |
| 3615 | } |
| 3616 | if ($ownProperties) { |
| 3617 | out += ' ' + ($dataProperties) + ' = ' + ($dataProperties) + ' || Object.keys(' + ($data) + '); for (var ' + ($idx) + '=0; ' + ($idx) + '<' + ($dataProperties) + '.length; ' + ($idx) + '++) { var ' + ($key) + ' = ' + ($dataProperties) + '[' + ($idx) + ']; '; |
| 3618 | } else { |
| 3619 | out += ' for (var ' + ($key) + ' in ' + ($data) + ') { '; |
| 3620 | } |
| 3621 | out += ' var startErrs' + ($lvl) + ' = errors; '; |
| 3622 | var $passData = $key; |
| 3623 | var $wasComposite = it.compositeRule; |
| 3624 | it.compositeRule = $it.compositeRule = true; |
| 3625 | var $code = it.validate($it); |
| 3626 | $it.baseId = $currentBaseId; |
| 3627 | if (it.util.varOccurences($code, $nextData) < 2) { |
| 3628 | out += ' ' + (it.util.varReplace($code, $nextData, $passData)) + ' '; |
| 3629 | } else { |
| 3630 | out += ' var ' + ($nextData) + ' = ' + ($passData) + '; ' + ($code) + ' '; |
| 3631 | } |
| 3632 | it.compositeRule = $it.compositeRule = $wasComposite; |
| 3633 | out += ' if (!' + ($nextValid) + ') { for (var ' + ($i) + '=startErrs' + ($lvl) + '; ' + ($i) + '<errors; ' + ($i) + '++) { vErrors[' + ($i) + '].propertyName = ' + ($key) + '; } var err = '; /* istanbul ignore else */ |
| 3634 | if (it.createErrors !== false) { |
| 3635 | out += ' { keyword: \'' + ('propertyNames') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: ' + (it.util.toQuotedString($errSchemaPath)) + ' , params: { propertyName: \'' + ($invalidName) + '\' } '; |
| 3636 | if (it.opts.messages !== false) { |
| 3637 | out += ' , message: \'property name \\\'' + ($invalidName) + '\\\' is invalid\' '; |
| 3638 | } |
| 3639 | if (it.opts.verbose) { |
| 3640 | out += ' , schema: validate.schema' + ($schemaPath) + ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' '; |
| 3641 | } |
| 3642 | out += ' } '; |
| 3643 | } else { |
| 3644 | out += ' {} '; |
| 3645 | } |
| 3646 | out += '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; '; |
| 3647 | if (!it.compositeRule && $breakOnError) { /* istanbul ignore if */ |
| 3648 | if (it.async) { |
| 3649 | out += ' throw new ValidationError(vErrors); '; |
| 3650 | } else { |
| 3651 | out += ' validate.errors = vErrors; return false; '; |
| 3652 | } |
| 3653 | } |
| 3654 | if ($breakOnError) { |
| 3655 | out += ' break; '; |
| 3656 | } |
| 3657 | out += ' } }'; |
| 3658 | } |
| 3659 | if ($breakOnError) { |
| 3660 | out += ' ' + ($closingBraces) + ' if (' + ($errs) + ' == errors) {'; |
| 3661 | } |
| 3662 | out = it.util.cleanUpCode(out); |
| 3663 | return out; |
| 3664 | } |
| 3665 | |
| 3666 | },{}],32:[function(require,module,exports){ |
| 3667 | 'use strict'; |
| 3668 | module.exports = function generate_ref(it, $keyword, $ruleType) { |
| 3669 | var out = ' '; |
| 3670 | var $lvl = it.level; |
| 3671 | var $dataLvl = it.dataLevel; |
| 3672 | var $schema = it.schema[$keyword]; |
| 3673 | var $errSchemaPath = it.errSchemaPath + '/' + $keyword; |
| 3674 | var $breakOnError = !it.opts.allErrors; |
| 3675 | var $data = 'data' + ($dataLvl || ''); |
| 3676 | var $valid = 'valid' + $lvl; |
| 3677 | var $async, $refCode; |
| 3678 | if ($schema == '#' || $schema == '#/') { |
| 3679 | if (it.isRoot) { |
| 3680 | $async = it.async; |
| 3681 | $refCode = 'validate'; |
| 3682 | } else { |
| 3683 | $async = it.root.schema.$async === true; |
| 3684 | $refCode = 'root.refVal[0]'; |
| 3685 | } |
| 3686 | } else { |
| 3687 | var $refVal = it.resolveRef(it.baseId, $schema, it.isRoot); |
| 3688 | if ($refVal === undefined) { |
| 3689 | var $message = it.MissingRefError.message(it.baseId, $schema); |
| 3690 | if (it.opts.missingRefs == 'fail') { |
| 3691 | it.logger.error($message); |
| 3692 | var $$outStack = $$outStack || []; |
| 3693 | $$outStack.push(out); |
| 3694 | out = ''; /* istanbul ignore else */ |
| 3695 | if (it.createErrors !== false) { |
| 3696 | out += ' { keyword: \'' + ('$ref') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: ' + (it.util.toQuotedString($errSchemaPath)) + ' , params: { ref: \'' + (it.util.escapeQuotes($schema)) + '\' } '; |
| 3697 | if (it.opts.messages !== false) { |
| 3698 | out += ' , message: \'can\\\'t resolve reference ' + (it.util.escapeQuotes($schema)) + '\' '; |
| 3699 | } |
| 3700 | if (it.opts.verbose) { |
| 3701 | out += ' , schema: ' + (it.util.toQuotedString($schema)) + ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' '; |
| 3702 | } |
| 3703 | out += ' } '; |
| 3704 | } else { |
| 3705 | out += ' {} '; |
| 3706 | } |
| 3707 | var __err = out; |
| 3708 | out = $$outStack.pop(); |
| 3709 | if (!it.compositeRule && $breakOnError) { /* istanbul ignore if */ |
| 3710 | if (it.async) { |
| 3711 | out += ' throw new ValidationError([' + (__err) + ']); '; |
| 3712 | } else { |
| 3713 | out += ' validate.errors = [' + (__err) + ']; return false; '; |
| 3714 | } |
| 3715 | } else { |
| 3716 | out += ' var err = ' + (__err) + '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; '; |
| 3717 | } |
| 3718 | if ($breakOnError) { |
| 3719 | out += ' if (false) { '; |
| 3720 | } |
| 3721 | } else if (it.opts.missingRefs == 'ignore') { |
| 3722 | it.logger.warn($message); |
| 3723 | if ($breakOnError) { |
| 3724 | out += ' if (true) { '; |
| 3725 | } |
| 3726 | } else { |
| 3727 | throw new it.MissingRefError(it.baseId, $schema, $message); |
| 3728 | } |
| 3729 | } else if ($refVal.inline) { |
| 3730 | var $it = it.util.copy(it); |
| 3731 | $it.level++; |
| 3732 | var $nextValid = 'valid' + $it.level; |
| 3733 | $it.schema = $refVal.schema; |
| 3734 | $it.schemaPath = ''; |
| 3735 | $it.errSchemaPath = $schema; |
| 3736 | var $code = it.validate($it).replace(/validate\.schema/g, $refVal.code); |
| 3737 | out += ' ' + ($code) + ' '; |
| 3738 | if ($breakOnError) { |
| 3739 | out += ' if (' + ($nextValid) + ') { '; |
| 3740 | } |
| 3741 | } else { |
| 3742 | $async = $refVal.$async === true; |
| 3743 | $refCode = $refVal.code; |
| 3744 | } |
| 3745 | } |
| 3746 | if ($refCode) { |
| 3747 | var $$outStack = $$outStack || []; |
| 3748 | $$outStack.push(out); |
| 3749 | out = ''; |
| 3750 | if (it.opts.passContext) { |
| 3751 | out += ' ' + ($refCode) + '.call(this, '; |
| 3752 | } else { |
| 3753 | out += ' ' + ($refCode) + '( '; |
| 3754 | } |
| 3755 | out += ' ' + ($data) + ', (dataPath || \'\')'; |
| 3756 | if (it.errorPath != '""') { |
| 3757 | out += ' + ' + (it.errorPath); |
| 3758 | } |
| 3759 | var $parentData = $dataLvl ? 'data' + (($dataLvl - 1) || '') : 'parentData', |
| 3760 | $parentDataProperty = $dataLvl ? it.dataPathArr[$dataLvl] : 'parentDataProperty'; |
| 3761 | out += ' , ' + ($parentData) + ' , ' + ($parentDataProperty) + ', rootData) '; |
| 3762 | var __callValidate = out; |
| 3763 | out = $$outStack.pop(); |
| 3764 | if ($async) { |
| 3765 | if (!it.async) throw new Error('async schema referenced by sync schema'); |
| 3766 | if ($breakOnError) { |
| 3767 | out += ' var ' + ($valid) + '; '; |
| 3768 | } |
| 3769 | out += ' try { ' + (it.yieldAwait) + ' ' + (__callValidate) + '; '; |
| 3770 | if ($breakOnError) { |
| 3771 | out += ' ' + ($valid) + ' = true; '; |
| 3772 | } |
| 3773 | out += ' } catch (e) { if (!(e instanceof ValidationError)) throw e; if (vErrors === null) vErrors = e.errors; else vErrors = vErrors.concat(e.errors); errors = vErrors.length; '; |
| 3774 | if ($breakOnError) { |
| 3775 | out += ' ' + ($valid) + ' = false; '; |
| 3776 | } |
| 3777 | out += ' } '; |
| 3778 | if ($breakOnError) { |
| 3779 | out += ' if (' + ($valid) + ') { '; |
| 3780 | } |
| 3781 | } else { |
| 3782 | out += ' if (!' + (__callValidate) + ') { if (vErrors === null) vErrors = ' + ($refCode) + '.errors; else vErrors = vErrors.concat(' + ($refCode) + '.errors); errors = vErrors.length; } '; |
| 3783 | if ($breakOnError) { |
| 3784 | out += ' else { '; |
| 3785 | } |
| 3786 | } |
| 3787 | } |
| 3788 | return out; |
| 3789 | } |
| 3790 | |
| 3791 | },{}],33:[function(require,module,exports){ |
| 3792 | 'use strict'; |
| 3793 | module.exports = function generate_required(it, $keyword, $ruleType) { |
| 3794 | var out = ' '; |
| 3795 | var $lvl = it.level; |
| 3796 | var $dataLvl = it.dataLevel; |
| 3797 | var $schema = it.schema[$keyword]; |
| 3798 | var $schemaPath = it.schemaPath + it.util.getProperty($keyword); |
| 3799 | var $errSchemaPath = it.errSchemaPath + '/' + $keyword; |
| 3800 | var $breakOnError = !it.opts.allErrors; |
| 3801 | var $data = 'data' + ($dataLvl || ''); |
| 3802 | var $valid = 'valid' + $lvl; |
| 3803 | var $isData = it.opts.$data && $schema && $schema.$data, |
| 3804 | $schemaValue; |
| 3805 | if ($isData) { |
| 3806 | out += ' var schema' + ($lvl) + ' = ' + (it.util.getData($schema.$data, $dataLvl, it.dataPathArr)) + '; '; |
| 3807 | $schemaValue = 'schema' + $lvl; |
| 3808 | } else { |
| 3809 | $schemaValue = $schema; |
| 3810 | } |
| 3811 | var $vSchema = 'schema' + $lvl; |
| 3812 | if (!$isData) { |
| 3813 | if ($schema.length < it.opts.loopRequired && it.schema.properties && Object.keys(it.schema.properties).length) { |
| 3814 | var $required = []; |
| 3815 | var arr1 = $schema; |
| 3816 | if (arr1) { |
| 3817 | var $property, i1 = -1, |
| 3818 | l1 = arr1.length - 1; |
| 3819 | while (i1 < l1) { |
| 3820 | $property = arr1[i1 += 1]; |
| 3821 | var $propertySch = it.schema.properties[$property]; |
| 3822 | if (!($propertySch && it.util.schemaHasRules($propertySch, it.RULES.all))) { |
| 3823 | $required[$required.length] = $property; |
| 3824 | } |
| 3825 | } |
| 3826 | } |
| 3827 | } else { |
| 3828 | var $required = $schema; |
| 3829 | } |
| 3830 | } |
| 3831 | if ($isData || $required.length) { |
| 3832 | var $currentErrorPath = it.errorPath, |
| 3833 | $loopRequired = $isData || $required.length >= it.opts.loopRequired, |
| 3834 | $ownProperties = it.opts.ownProperties; |
| 3835 | if ($breakOnError) { |
| 3836 | out += ' var missing' + ($lvl) + '; '; |
| 3837 | if ($loopRequired) { |
| 3838 | if (!$isData) { |
| 3839 | out += ' var ' + ($vSchema) + ' = validate.schema' + ($schemaPath) + '; '; |
| 3840 | } |
| 3841 | var $i = 'i' + $lvl, |
| 3842 | $propertyPath = 'schema' + $lvl + '[' + $i + ']', |
| 3843 | $missingProperty = '\' + ' + $propertyPath + ' + \''; |
| 3844 | if (it.opts._errorDataPathProperty) { |
| 3845 | it.errorPath = it.util.getPathExpr($currentErrorPath, $propertyPath, it.opts.jsonPointers); |
| 3846 | } |
| 3847 | out += ' var ' + ($valid) + ' = true; '; |
| 3848 | if ($isData) { |
| 3849 | out += ' if (schema' + ($lvl) + ' === undefined) ' + ($valid) + ' = true; else if (!Array.isArray(schema' + ($lvl) + ')) ' + ($valid) + ' = false; else {'; |
| 3850 | } |
| 3851 | out += ' for (var ' + ($i) + ' = 0; ' + ($i) + ' < ' + ($vSchema) + '.length; ' + ($i) + '++) { ' + ($valid) + ' = ' + ($data) + '[' + ($vSchema) + '[' + ($i) + ']] !== undefined '; |
| 3852 | if ($ownProperties) { |
| 3853 | out += ' && Object.prototype.hasOwnProperty.call(' + ($data) + ', ' + ($vSchema) + '[' + ($i) + ']) '; |
| 3854 | } |
| 3855 | out += '; if (!' + ($valid) + ') break; } '; |
| 3856 | if ($isData) { |
| 3857 | out += ' } '; |
| 3858 | } |
| 3859 | out += ' if (!' + ($valid) + ') { '; |
| 3860 | var $$outStack = $$outStack || []; |
| 3861 | $$outStack.push(out); |
| 3862 | out = ''; /* istanbul ignore else */ |
| 3863 | if (it.createErrors !== false) { |
| 3864 | out += ' { keyword: \'' + ('required') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: ' + (it.util.toQuotedString($errSchemaPath)) + ' , params: { missingProperty: \'' + ($missingProperty) + '\' } '; |
| 3865 | if (it.opts.messages !== false) { |
| 3866 | out += ' , message: \''; |
| 3867 | if (it.opts._errorDataPathProperty) { |
| 3868 | out += 'is a required property'; |
| 3869 | } else { |
| 3870 | out += 'should have required property \\\'' + ($missingProperty) + '\\\''; |
| 3871 | } |
| 3872 | out += '\' '; |
| 3873 | } |
| 3874 | if (it.opts.verbose) { |
| 3875 | out += ' , schema: validate.schema' + ($schemaPath) + ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' '; |
| 3876 | } |
| 3877 | out += ' } '; |
| 3878 | } else { |
| 3879 | out += ' {} '; |
| 3880 | } |
| 3881 | var __err = out; |
| 3882 | out = $$outStack.pop(); |
| 3883 | if (!it.compositeRule && $breakOnError) { /* istanbul ignore if */ |
| 3884 | if (it.async) { |
| 3885 | out += ' throw new ValidationError([' + (__err) + ']); '; |
| 3886 | } else { |
| 3887 | out += ' validate.errors = [' + (__err) + ']; return false; '; |
| 3888 | } |
| 3889 | } else { |
| 3890 | out += ' var err = ' + (__err) + '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; '; |
| 3891 | } |
| 3892 | out += ' } else { '; |
| 3893 | } else { |
| 3894 | out += ' if ( '; |
| 3895 | var arr2 = $required; |
| 3896 | if (arr2) { |
| 3897 | var $propertyKey, $i = -1, |
| 3898 | l2 = arr2.length - 1; |
| 3899 | while ($i < l2) { |
| 3900 | $propertyKey = arr2[$i += 1]; |
| 3901 | if ($i) { |
| 3902 | out += ' || '; |
| 3903 | } |
| 3904 | var $prop = it.util.getProperty($propertyKey), |
| 3905 | $useData = $data + $prop; |
| 3906 | out += ' ( ( ' + ($useData) + ' === undefined '; |
| 3907 | if ($ownProperties) { |
| 3908 | out += ' || ! Object.prototype.hasOwnProperty.call(' + ($data) + ', \'' + (it.util.escapeQuotes($propertyKey)) + '\') '; |
| 3909 | } |
| 3910 | out += ') && (missing' + ($lvl) + ' = ' + (it.util.toQuotedString(it.opts.jsonPointers ? $propertyKey : $prop)) + ') ) '; |
| 3911 | } |
| 3912 | } |
| 3913 | out += ') { '; |
| 3914 | var $propertyPath = 'missing' + $lvl, |
| 3915 | $missingProperty = '\' + ' + $propertyPath + ' + \''; |
| 3916 | if (it.opts._errorDataPathProperty) { |
| 3917 | it.errorPath = it.opts.jsonPointers ? it.util.getPathExpr($currentErrorPath, $propertyPath, true) : $currentErrorPath + ' + ' + $propertyPath; |
| 3918 | } |
| 3919 | var $$outStack = $$outStack || []; |
| 3920 | $$outStack.push(out); |
| 3921 | out = ''; /* istanbul ignore else */ |
| 3922 | if (it.createErrors !== false) { |
| 3923 | out += ' { keyword: \'' + ('required') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: ' + (it.util.toQuotedString($errSchemaPath)) + ' , params: { missingProperty: \'' + ($missingProperty) + '\' } '; |
| 3924 | if (it.opts.messages !== false) { |
| 3925 | out += ' , message: \''; |
| 3926 | if (it.opts._errorDataPathProperty) { |
| 3927 | out += 'is a required property'; |
| 3928 | } else { |
| 3929 | out += 'should have required property \\\'' + ($missingProperty) + '\\\''; |
| 3930 | } |
| 3931 | out += '\' '; |
| 3932 | } |
| 3933 | if (it.opts.verbose) { |
| 3934 | out += ' , schema: validate.schema' + ($schemaPath) + ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' '; |
| 3935 | } |
| 3936 | out += ' } '; |
| 3937 | } else { |
| 3938 | out += ' {} '; |
| 3939 | } |
| 3940 | var __err = out; |
| 3941 | out = $$outStack.pop(); |
| 3942 | if (!it.compositeRule && $breakOnError) { /* istanbul ignore if */ |
| 3943 | if (it.async) { |
| 3944 | out += ' throw new ValidationError([' + (__err) + ']); '; |
| 3945 | } else { |
| 3946 | out += ' validate.errors = [' + (__err) + ']; return false; '; |
| 3947 | } |
| 3948 | } else { |
| 3949 | out += ' var err = ' + (__err) + '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; '; |
| 3950 | } |
| 3951 | out += ' } else { '; |
| 3952 | } |
| 3953 | } else { |
| 3954 | if ($loopRequired) { |
| 3955 | if (!$isData) { |
| 3956 | out += ' var ' + ($vSchema) + ' = validate.schema' + ($schemaPath) + '; '; |
| 3957 | } |
| 3958 | var $i = 'i' + $lvl, |
| 3959 | $propertyPath = 'schema' + $lvl + '[' + $i + ']', |
| 3960 | $missingProperty = '\' + ' + $propertyPath + ' + \''; |
| 3961 | if (it.opts._errorDataPathProperty) { |
| 3962 | it.errorPath = it.util.getPathExpr($currentErrorPath, $propertyPath, it.opts.jsonPointers); |
| 3963 | } |
| 3964 | if ($isData) { |
| 3965 | out += ' if (' + ($vSchema) + ' && !Array.isArray(' + ($vSchema) + ')) { var err = '; /* istanbul ignore else */ |
| 3966 | if (it.createErrors !== false) { |
| 3967 | out += ' { keyword: \'' + ('required') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: ' + (it.util.toQuotedString($errSchemaPath)) + ' , params: { missingProperty: \'' + ($missingProperty) + '\' } '; |
| 3968 | if (it.opts.messages !== false) { |
| 3969 | out += ' , message: \''; |
| 3970 | if (it.opts._errorDataPathProperty) { |
| 3971 | out += 'is a required property'; |
| 3972 | } else { |
| 3973 | out += 'should have required property \\\'' + ($missingProperty) + '\\\''; |
| 3974 | } |
| 3975 | out += '\' '; |
| 3976 | } |
| 3977 | if (it.opts.verbose) { |
| 3978 | out += ' , schema: validate.schema' + ($schemaPath) + ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' '; |
| 3979 | } |
| 3980 | out += ' } '; |
| 3981 | } else { |
| 3982 | out += ' {} '; |
| 3983 | } |
| 3984 | out += '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; } else if (' + ($vSchema) + ' !== undefined) { '; |
| 3985 | } |
| 3986 | out += ' for (var ' + ($i) + ' = 0; ' + ($i) + ' < ' + ($vSchema) + '.length; ' + ($i) + '++) { if (' + ($data) + '[' + ($vSchema) + '[' + ($i) + ']] === undefined '; |
| 3987 | if ($ownProperties) { |
| 3988 | out += ' || ! Object.prototype.hasOwnProperty.call(' + ($data) + ', ' + ($vSchema) + '[' + ($i) + ']) '; |
| 3989 | } |
| 3990 | out += ') { var err = '; /* istanbul ignore else */ |
| 3991 | if (it.createErrors !== false) { |
| 3992 | out += ' { keyword: \'' + ('required') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: ' + (it.util.toQuotedString($errSchemaPath)) + ' , params: { missingProperty: \'' + ($missingProperty) + '\' } '; |
| 3993 | if (it.opts.messages !== false) { |
| 3994 | out += ' , message: \''; |
| 3995 | if (it.opts._errorDataPathProperty) { |
| 3996 | out += 'is a required property'; |
| 3997 | } else { |
| 3998 | out += 'should have required property \\\'' + ($missingProperty) + '\\\''; |
| 3999 | } |
| 4000 | out += '\' '; |
| 4001 | } |
| 4002 | if (it.opts.verbose) { |
| 4003 | out += ' , schema: validate.schema' + ($schemaPath) + ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' '; |
| 4004 | } |
| 4005 | out += ' } '; |
| 4006 | } else { |
| 4007 | out += ' {} '; |
| 4008 | } |
| 4009 | out += '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; } } '; |
| 4010 | if ($isData) { |
| 4011 | out += ' } '; |
| 4012 | } |
| 4013 | } else { |
| 4014 | var arr3 = $required; |
| 4015 | if (arr3) { |
| 4016 | var $propertyKey, i3 = -1, |
| 4017 | l3 = arr3.length - 1; |
| 4018 | while (i3 < l3) { |
| 4019 | $propertyKey = arr3[i3 += 1]; |
| 4020 | var $prop = it.util.getProperty($propertyKey), |
| 4021 | $missingProperty = it.util.escapeQuotes($propertyKey), |
| 4022 | $useData = $data + $prop; |
| 4023 | if (it.opts._errorDataPathProperty) { |
| 4024 | it.errorPath = it.util.getPath($currentErrorPath, $propertyKey, it.opts.jsonPointers); |
| 4025 | } |
| 4026 | out += ' if ( ' + ($useData) + ' === undefined '; |
| 4027 | if ($ownProperties) { |
| 4028 | out += ' || ! Object.prototype.hasOwnProperty.call(' + ($data) + ', \'' + (it.util.escapeQuotes($propertyKey)) + '\') '; |
| 4029 | } |
| 4030 | out += ') { var err = '; /* istanbul ignore else */ |
| 4031 | if (it.createErrors !== false) { |
| 4032 | out += ' { keyword: \'' + ('required') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: ' + (it.util.toQuotedString($errSchemaPath)) + ' , params: { missingProperty: \'' + ($missingProperty) + '\' } '; |
| 4033 | if (it.opts.messages !== false) { |
| 4034 | out += ' , message: \''; |
| 4035 | if (it.opts._errorDataPathProperty) { |
| 4036 | out += 'is a required property'; |
| 4037 | } else { |
| 4038 | out += 'should have required property \\\'' + ($missingProperty) + '\\\''; |
| 4039 | } |
| 4040 | out += '\' '; |
| 4041 | } |
| 4042 | if (it.opts.verbose) { |
| 4043 | out += ' , schema: validate.schema' + ($schemaPath) + ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' '; |
| 4044 | } |
| 4045 | out += ' } '; |
| 4046 | } else { |
| 4047 | out += ' {} '; |
| 4048 | } |
| 4049 | out += '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; } '; |
| 4050 | } |
| 4051 | } |
| 4052 | } |
| 4053 | } |
| 4054 | it.errorPath = $currentErrorPath; |
| 4055 | } else if ($breakOnError) { |
| 4056 | out += ' if (true) {'; |
| 4057 | } |
| 4058 | return out; |
| 4059 | } |
| 4060 | |
| 4061 | },{}],34:[function(require,module,exports){ |
| 4062 | 'use strict'; |
| 4063 | module.exports = function generate_uniqueItems(it, $keyword, $ruleType) { |
| 4064 | var out = ' '; |
| 4065 | var $lvl = it.level; |
| 4066 | var $dataLvl = it.dataLevel; |
| 4067 | var $schema = it.schema[$keyword]; |
| 4068 | var $schemaPath = it.schemaPath + it.util.getProperty($keyword); |
| 4069 | var $errSchemaPath = it.errSchemaPath + '/' + $keyword; |
| 4070 | var $breakOnError = !it.opts.allErrors; |
| 4071 | var $data = 'data' + ($dataLvl || ''); |
| 4072 | var $valid = 'valid' + $lvl; |
| 4073 | var $isData = it.opts.$data && $schema && $schema.$data, |
| 4074 | $schemaValue; |
| 4075 | if ($isData) { |
| 4076 | out += ' var schema' + ($lvl) + ' = ' + (it.util.getData($schema.$data, $dataLvl, it.dataPathArr)) + '; '; |
| 4077 | $schemaValue = 'schema' + $lvl; |
| 4078 | } else { |
| 4079 | $schemaValue = $schema; |
| 4080 | } |
| 4081 | if (($schema || $isData) && it.opts.uniqueItems !== false) { |
| 4082 | if ($isData) { |
| 4083 | out += ' var ' + ($valid) + '; if (' + ($schemaValue) + ' === false || ' + ($schemaValue) + ' === undefined) ' + ($valid) + ' = true; else if (typeof ' + ($schemaValue) + ' != \'boolean\') ' + ($valid) + ' = false; else { '; |
| 4084 | } |
| 4085 | out += ' var ' + ($valid) + ' = true; if (' + ($data) + '.length > 1) { var i = ' + ($data) + '.length, j; outer: for (;i--;) { for (j = i; j--;) { if (equal(' + ($data) + '[i], ' + ($data) + '[j])) { ' + ($valid) + ' = false; break outer; } } } } '; |
| 4086 | if ($isData) { |
| 4087 | out += ' } '; |
| 4088 | } |
| 4089 | out += ' if (!' + ($valid) + ') { '; |
| 4090 | var $$outStack = $$outStack || []; |
| 4091 | $$outStack.push(out); |
| 4092 | out = ''; /* istanbul ignore else */ |
| 4093 | if (it.createErrors !== false) { |
| 4094 | out += ' { keyword: \'' + ('uniqueItems') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: ' + (it.util.toQuotedString($errSchemaPath)) + ' , params: { i: i, j: j } '; |
| 4095 | if (it.opts.messages !== false) { |
| 4096 | out += ' , message: \'should NOT have duplicate items (items ## \' + j + \' and \' + i + \' are identical)\' '; |
| 4097 | } |
| 4098 | if (it.opts.verbose) { |
| 4099 | out += ' , schema: '; |
| 4100 | if ($isData) { |
| 4101 | out += 'validate.schema' + ($schemaPath); |
| 4102 | } else { |
| 4103 | out += '' + ($schema); |
| 4104 | } |
| 4105 | out += ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' '; |
| 4106 | } |
| 4107 | out += ' } '; |
| 4108 | } else { |
| 4109 | out += ' {} '; |
| 4110 | } |
| 4111 | var __err = out; |
| 4112 | out = $$outStack.pop(); |
| 4113 | if (!it.compositeRule && $breakOnError) { /* istanbul ignore if */ |
| 4114 | if (it.async) { |
| 4115 | out += ' throw new ValidationError([' + (__err) + ']); '; |
| 4116 | } else { |
| 4117 | out += ' validate.errors = [' + (__err) + ']; return false; '; |
| 4118 | } |
| 4119 | } else { |
| 4120 | out += ' var err = ' + (__err) + '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; '; |
| 4121 | } |
| 4122 | out += ' } '; |
| 4123 | if ($breakOnError) { |
| 4124 | out += ' else { '; |
| 4125 | } |
| 4126 | } else { |
| 4127 | if ($breakOnError) { |
| 4128 | out += ' if (true) { '; |
| 4129 | } |
| 4130 | } |
| 4131 | return out; |
| 4132 | } |
| 4133 | |
| 4134 | },{}],35:[function(require,module,exports){ |
| 4135 | 'use strict'; |
| 4136 | module.exports = function generate_validate(it, $keyword, $ruleType) { |
| 4137 | var out = ''; |
| 4138 | var $async = it.schema.$async === true, |
| 4139 | $refKeywords = it.util.schemaHasRulesExcept(it.schema, it.RULES.all, '$ref'), |
| 4140 | $id = it.self._getId(it.schema); |
| 4141 | if (it.isTop) { |
| 4142 | if ($async) { |
| 4143 | it.async = true; |
| 4144 | var $es7 = it.opts.async == 'es7'; |
| 4145 | it.yieldAwait = $es7 ? 'await' : 'yield'; |
| 4146 | } |
| 4147 | out += ' var validate = '; |
| 4148 | if ($async) { |
| 4149 | if ($es7) { |
| 4150 | out += ' (async function '; |
| 4151 | } else { |
| 4152 | if (it.opts.async != '*') { |
| 4153 | out += 'co.wrap'; |
| 4154 | } |
| 4155 | out += '(function* '; |
| 4156 | } |
| 4157 | } else { |
| 4158 | out += ' (function '; |
| 4159 | } |
| 4160 | out += ' (data, dataPath, parentData, parentDataProperty, rootData) { \'use strict\'; '; |
| 4161 | if ($id && (it.opts.sourceCode || it.opts.processCode)) { |
| 4162 | out += ' ' + ('/\*# sourceURL=' + $id + ' */') + ' '; |
| 4163 | } |
| 4164 | } |
| 4165 | if (typeof it.schema == 'boolean' || !($refKeywords || it.schema.$ref)) { |
| 4166 | var $keyword = 'false schema'; |
| 4167 | var $lvl = it.level; |
| 4168 | var $dataLvl = it.dataLevel; |
| 4169 | var $schema = it.schema[$keyword]; |
| 4170 | var $schemaPath = it.schemaPath + it.util.getProperty($keyword); |
| 4171 | var $errSchemaPath = it.errSchemaPath + '/' + $keyword; |
| 4172 | var $breakOnError = !it.opts.allErrors; |
| 4173 | var $errorKeyword; |
| 4174 | var $data = 'data' + ($dataLvl || ''); |
| 4175 | var $valid = 'valid' + $lvl; |
| 4176 | if (it.schema === false) { |
| 4177 | if (it.isTop) { |
| 4178 | $breakOnError = true; |
| 4179 | } else { |
| 4180 | out += ' var ' + ($valid) + ' = false; '; |
| 4181 | } |
| 4182 | var $$outStack = $$outStack || []; |
| 4183 | $$outStack.push(out); |
| 4184 | out = ''; /* istanbul ignore else */ |
| 4185 | if (it.createErrors !== false) { |
| 4186 | out += ' { keyword: \'' + ($errorKeyword || 'false schema') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: ' + (it.util.toQuotedString($errSchemaPath)) + ' , params: {} '; |
| 4187 | if (it.opts.messages !== false) { |
| 4188 | out += ' , message: \'boolean schema is false\' '; |
| 4189 | } |
| 4190 | if (it.opts.verbose) { |
| 4191 | out += ' , schema: false , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' '; |
| 4192 | } |
| 4193 | out += ' } '; |
| 4194 | } else { |
| 4195 | out += ' {} '; |
| 4196 | } |
| 4197 | var __err = out; |
| 4198 | out = $$outStack.pop(); |
| 4199 | if (!it.compositeRule && $breakOnError) { /* istanbul ignore if */ |
| 4200 | if (it.async) { |
| 4201 | out += ' throw new ValidationError([' + (__err) + ']); '; |
| 4202 | } else { |
| 4203 | out += ' validate.errors = [' + (__err) + ']; return false; '; |
| 4204 | } |
| 4205 | } else { |
| 4206 | out += ' var err = ' + (__err) + '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; '; |
| 4207 | } |
| 4208 | } else { |
| 4209 | if (it.isTop) { |
| 4210 | if ($async) { |
| 4211 | out += ' return data; '; |
| 4212 | } else { |
| 4213 | out += ' validate.errors = null; return true; '; |
| 4214 | } |
| 4215 | } else { |
| 4216 | out += ' var ' + ($valid) + ' = true; '; |
| 4217 | } |
| 4218 | } |
| 4219 | if (it.isTop) { |
| 4220 | out += ' }); return validate; '; |
| 4221 | } |
| 4222 | return out; |
| 4223 | } |
| 4224 | if (it.isTop) { |
| 4225 | var $top = it.isTop, |
| 4226 | $lvl = it.level = 0, |
| 4227 | $dataLvl = it.dataLevel = 0, |
| 4228 | $data = 'data'; |
| 4229 | it.rootId = it.resolve.fullPath(it.self._getId(it.root.schema)); |
| 4230 | it.baseId = it.baseId || it.rootId; |
| 4231 | delete it.isTop; |
| 4232 | it.dataPathArr = [undefined]; |
| 4233 | out += ' var vErrors = null; '; |
| 4234 | out += ' var errors = 0; '; |
| 4235 | out += ' if (rootData === undefined) rootData = data; '; |
| 4236 | } else { |
| 4237 | var $lvl = it.level, |
| 4238 | $dataLvl = it.dataLevel, |
| 4239 | $data = 'data' + ($dataLvl || ''); |
| 4240 | if ($id) it.baseId = it.resolve.url(it.baseId, $id); |
| 4241 | if ($async && !it.async) throw new Error('async schema in sync schema'); |
| 4242 | out += ' var errs_' + ($lvl) + ' = errors;'; |
| 4243 | } |
| 4244 | var $valid = 'valid' + $lvl, |
| 4245 | $breakOnError = !it.opts.allErrors, |
| 4246 | $closingBraces1 = '', |
| 4247 | $closingBraces2 = ''; |
| 4248 | var $errorKeyword; |
| 4249 | var $typeSchema = it.schema.type, |
| 4250 | $typeIsArray = Array.isArray($typeSchema); |
| 4251 | if ($typeIsArray && $typeSchema.length == 1) { |
| 4252 | $typeSchema = $typeSchema[0]; |
| 4253 | $typeIsArray = false; |
| 4254 | } |
| 4255 | if (it.schema.$ref && $refKeywords) { |
| 4256 | if (it.opts.extendRefs == 'fail') { |
| 4257 | throw new Error('$ref: validation keywords used in schema at path "' + it.errSchemaPath + '" (see option extendRefs)'); |
| 4258 | } else if (it.opts.extendRefs !== true) { |
| 4259 | $refKeywords = false; |
| 4260 | it.logger.warn('$ref: keywords ignored in schema at path "' + it.errSchemaPath + '"'); |
| 4261 | } |
| 4262 | } |
| 4263 | if ($typeSchema) { |
| 4264 | if (it.opts.coerceTypes) { |
| 4265 | var $coerceToTypes = it.util.coerceToTypes(it.opts.coerceTypes, $typeSchema); |
| 4266 | } |
| 4267 | var $rulesGroup = it.RULES.types[$typeSchema]; |
| 4268 | if ($coerceToTypes || $typeIsArray || $rulesGroup === true || ($rulesGroup && !$shouldUseGroup($rulesGroup))) { |
| 4269 | var $schemaPath = it.schemaPath + '.type', |
| 4270 | $errSchemaPath = it.errSchemaPath + '/type'; |
| 4271 | var $schemaPath = it.schemaPath + '.type', |
| 4272 | $errSchemaPath = it.errSchemaPath + '/type', |
| 4273 | $method = $typeIsArray ? 'checkDataTypes' : 'checkDataType'; |
| 4274 | out += ' if (' + (it.util[$method]($typeSchema, $data, true)) + ') { '; |
| 4275 | if ($coerceToTypes) { |
| 4276 | var $dataType = 'dataType' + $lvl, |
| 4277 | $coerced = 'coerced' + $lvl; |
| 4278 | out += ' var ' + ($dataType) + ' = typeof ' + ($data) + '; '; |
| 4279 | if (it.opts.coerceTypes == 'array') { |
| 4280 | out += ' if (' + ($dataType) + ' == \'object\' && Array.isArray(' + ($data) + ')) ' + ($dataType) + ' = \'array\'; '; |
| 4281 | } |
| 4282 | out += ' var ' + ($coerced) + ' = undefined; '; |
| 4283 | var $bracesCoercion = ''; |
| 4284 | var arr1 = $coerceToTypes; |
| 4285 | if (arr1) { |
| 4286 | var $type, $i = -1, |
| 4287 | l1 = arr1.length - 1; |
| 4288 | while ($i < l1) { |
| 4289 | $type = arr1[$i += 1]; |
| 4290 | if ($i) { |
| 4291 | out += ' if (' + ($coerced) + ' === undefined) { '; |
| 4292 | $bracesCoercion += '}'; |
| 4293 | } |
| 4294 | if (it.opts.coerceTypes == 'array' && $type != 'array') { |
| 4295 | out += ' if (' + ($dataType) + ' == \'array\' && ' + ($data) + '.length == 1) { ' + ($coerced) + ' = ' + ($data) + ' = ' + ($data) + '[0]; ' + ($dataType) + ' = typeof ' + ($data) + '; } '; |
| 4296 | } |
| 4297 | if ($type == 'string') { |
| 4298 | out += ' if (' + ($dataType) + ' == \'number\' || ' + ($dataType) + ' == \'boolean\') ' + ($coerced) + ' = \'\' + ' + ($data) + '; else if (' + ($data) + ' === null) ' + ($coerced) + ' = \'\'; '; |
| 4299 | } else if ($type == 'number' || $type == 'integer') { |
| 4300 | out += ' if (' + ($dataType) + ' == \'boolean\' || ' + ($data) + ' === null || (' + ($dataType) + ' == \'string\' && ' + ($data) + ' && ' + ($data) + ' == +' + ($data) + ' '; |
| 4301 | if ($type == 'integer') { |
| 4302 | out += ' && !(' + ($data) + ' % 1)'; |
| 4303 | } |
| 4304 | out += ')) ' + ($coerced) + ' = +' + ($data) + '; '; |
| 4305 | } else if ($type == 'boolean') { |
| 4306 | out += ' if (' + ($data) + ' === \'false\' || ' + ($data) + ' === 0 || ' + ($data) + ' === null) ' + ($coerced) + ' = false; else if (' + ($data) + ' === \'true\' || ' + ($data) + ' === 1) ' + ($coerced) + ' = true; '; |
| 4307 | } else if ($type == 'null') { |
| 4308 | out += ' if (' + ($data) + ' === \'\' || ' + ($data) + ' === 0 || ' + ($data) + ' === false) ' + ($coerced) + ' = null; '; |
| 4309 | } else if (it.opts.coerceTypes == 'array' && $type == 'array') { |
| 4310 | out += ' if (' + ($dataType) + ' == \'string\' || ' + ($dataType) + ' == \'number\' || ' + ($dataType) + ' == \'boolean\' || ' + ($data) + ' == null) ' + ($coerced) + ' = [' + ($data) + ']; '; |
| 4311 | } |
| 4312 | } |
| 4313 | } |
| 4314 | out += ' ' + ($bracesCoercion) + ' if (' + ($coerced) + ' === undefined) { '; |
| 4315 | var $$outStack = $$outStack || []; |
| 4316 | $$outStack.push(out); |
| 4317 | out = ''; /* istanbul ignore else */ |
| 4318 | if (it.createErrors !== false) { |
| 4319 | out += ' { keyword: \'' + ($errorKeyword || 'type') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: ' + (it.util.toQuotedString($errSchemaPath)) + ' , params: { type: \''; |
| 4320 | if ($typeIsArray) { |
| 4321 | out += '' + ($typeSchema.join(",")); |
| 4322 | } else { |
| 4323 | out += '' + ($typeSchema); |
| 4324 | } |
| 4325 | out += '\' } '; |
| 4326 | if (it.opts.messages !== false) { |
| 4327 | out += ' , message: \'should be '; |
| 4328 | if ($typeIsArray) { |
| 4329 | out += '' + ($typeSchema.join(",")); |
| 4330 | } else { |
| 4331 | out += '' + ($typeSchema); |
| 4332 | } |
| 4333 | out += '\' '; |
| 4334 | } |
| 4335 | if (it.opts.verbose) { |
| 4336 | out += ' , schema: validate.schema' + ($schemaPath) + ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' '; |
| 4337 | } |
| 4338 | out += ' } '; |
| 4339 | } else { |
| 4340 | out += ' {} '; |
| 4341 | } |
| 4342 | var __err = out; |
| 4343 | out = $$outStack.pop(); |
| 4344 | if (!it.compositeRule && $breakOnError) { /* istanbul ignore if */ |
| 4345 | if (it.async) { |
| 4346 | out += ' throw new ValidationError([' + (__err) + ']); '; |
| 4347 | } else { |
| 4348 | out += ' validate.errors = [' + (__err) + ']; return false; '; |
| 4349 | } |
| 4350 | } else { |
| 4351 | out += ' var err = ' + (__err) + '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; '; |
| 4352 | } |
| 4353 | out += ' } else { '; |
| 4354 | var $parentData = $dataLvl ? 'data' + (($dataLvl - 1) || '') : 'parentData', |
| 4355 | $parentDataProperty = $dataLvl ? it.dataPathArr[$dataLvl] : 'parentDataProperty'; |
| 4356 | out += ' ' + ($data) + ' = ' + ($coerced) + '; '; |
| 4357 | if (!$dataLvl) { |
| 4358 | out += 'if (' + ($parentData) + ' !== undefined)'; |
| 4359 | } |
| 4360 | out += ' ' + ($parentData) + '[' + ($parentDataProperty) + '] = ' + ($coerced) + '; } '; |
| 4361 | } else { |
| 4362 | var $$outStack = $$outStack || []; |
| 4363 | $$outStack.push(out); |
| 4364 | out = ''; /* istanbul ignore else */ |
| 4365 | if (it.createErrors !== false) { |
| 4366 | out += ' { keyword: \'' + ($errorKeyword || 'type') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: ' + (it.util.toQuotedString($errSchemaPath)) + ' , params: { type: \''; |
| 4367 | if ($typeIsArray) { |
| 4368 | out += '' + ($typeSchema.join(",")); |
| 4369 | } else { |
| 4370 | out += '' + ($typeSchema); |
| 4371 | } |
| 4372 | out += '\' } '; |
| 4373 | if (it.opts.messages !== false) { |
| 4374 | out += ' , message: \'should be '; |
| 4375 | if ($typeIsArray) { |
| 4376 | out += '' + ($typeSchema.join(",")); |
| 4377 | } else { |
| 4378 | out += '' + ($typeSchema); |
| 4379 | } |
| 4380 | out += '\' '; |
| 4381 | } |
| 4382 | if (it.opts.verbose) { |
| 4383 | out += ' , schema: validate.schema' + ($schemaPath) + ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' '; |
| 4384 | } |
| 4385 | out += ' } '; |
| 4386 | } else { |
| 4387 | out += ' {} '; |
| 4388 | } |
| 4389 | var __err = out; |
| 4390 | out = $$outStack.pop(); |
| 4391 | if (!it.compositeRule && $breakOnError) { /* istanbul ignore if */ |
| 4392 | if (it.async) { |
| 4393 | out += ' throw new ValidationError([' + (__err) + ']); '; |
| 4394 | } else { |
| 4395 | out += ' validate.errors = [' + (__err) + ']; return false; '; |
| 4396 | } |
| 4397 | } else { |
| 4398 | out += ' var err = ' + (__err) + '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; '; |
| 4399 | } |
| 4400 | } |
| 4401 | out += ' } '; |
| 4402 | } |
| 4403 | } |
| 4404 | if (it.schema.$ref && !$refKeywords) { |
| 4405 | out += ' ' + (it.RULES.all.$ref.code(it, '$ref')) + ' '; |
| 4406 | if ($breakOnError) { |
| 4407 | out += ' } if (errors === '; |
| 4408 | if ($top) { |
| 4409 | out += '0'; |
| 4410 | } else { |
| 4411 | out += 'errs_' + ($lvl); |
| 4412 | } |
| 4413 | out += ') { '; |
| 4414 | $closingBraces2 += '}'; |
| 4415 | } |
| 4416 | } else { |
| 4417 | if (it.opts.v5 && it.schema.patternGroups) { |
| 4418 | it.logger.warn('keyword "patternGroups" is deprecated and disabled. Use option patternGroups: true to enable.'); |
| 4419 | } |
| 4420 | var arr2 = it.RULES; |
| 4421 | if (arr2) { |
| 4422 | var $rulesGroup, i2 = -1, |
| 4423 | l2 = arr2.length - 1; |
| 4424 | while (i2 < l2) { |
| 4425 | $rulesGroup = arr2[i2 += 1]; |
| 4426 | if ($shouldUseGroup($rulesGroup)) { |
| 4427 | if ($rulesGroup.type) { |
| 4428 | out += ' if (' + (it.util.checkDataType($rulesGroup.type, $data)) + ') { '; |
| 4429 | } |
| 4430 | if (it.opts.useDefaults && !it.compositeRule) { |
| 4431 | if ($rulesGroup.type == 'object' && it.schema.properties) { |
| 4432 | var $schema = it.schema.properties, |
| 4433 | $schemaKeys = Object.keys($schema); |
| 4434 | var arr3 = $schemaKeys; |
| 4435 | if (arr3) { |
| 4436 | var $propertyKey, i3 = -1, |
| 4437 | l3 = arr3.length - 1; |
| 4438 | while (i3 < l3) { |
| 4439 | $propertyKey = arr3[i3 += 1]; |
| 4440 | var $sch = $schema[$propertyKey]; |
| 4441 | if ($sch.default !== undefined) { |
| 4442 | var $passData = $data + it.util.getProperty($propertyKey); |
| 4443 | out += ' if (' + ($passData) + ' === undefined) ' + ($passData) + ' = '; |
| 4444 | if (it.opts.useDefaults == 'shared') { |
| 4445 | out += ' ' + (it.useDefault($sch.default)) + ' '; |
| 4446 | } else { |
| 4447 | out += ' ' + (JSON.stringify($sch.default)) + ' '; |
| 4448 | } |
| 4449 | out += '; '; |
| 4450 | } |
| 4451 | } |
| 4452 | } |
| 4453 | } else if ($rulesGroup.type == 'array' && Array.isArray(it.schema.items)) { |
| 4454 | var arr4 = it.schema.items; |
| 4455 | if (arr4) { |
| 4456 | var $sch, $i = -1, |
| 4457 | l4 = arr4.length - 1; |
| 4458 | while ($i < l4) { |
| 4459 | $sch = arr4[$i += 1]; |
| 4460 | if ($sch.default !== undefined) { |
| 4461 | var $passData = $data + '[' + $i + ']'; |
| 4462 | out += ' if (' + ($passData) + ' === undefined) ' + ($passData) + ' = '; |
| 4463 | if (it.opts.useDefaults == 'shared') { |
| 4464 | out += ' ' + (it.useDefault($sch.default)) + ' '; |
| 4465 | } else { |
| 4466 | out += ' ' + (JSON.stringify($sch.default)) + ' '; |
| 4467 | } |
| 4468 | out += '; '; |
| 4469 | } |
| 4470 | } |
| 4471 | } |
| 4472 | } |
| 4473 | } |
| 4474 | var arr5 = $rulesGroup.rules; |
| 4475 | if (arr5) { |
| 4476 | var $rule, i5 = -1, |
| 4477 | l5 = arr5.length - 1; |
| 4478 | while (i5 < l5) { |
| 4479 | $rule = arr5[i5 += 1]; |
| 4480 | if ($shouldUseRule($rule)) { |
| 4481 | var $code = $rule.code(it, $rule.keyword, $rulesGroup.type); |
| 4482 | if ($code) { |
| 4483 | out += ' ' + ($code) + ' '; |
| 4484 | if ($breakOnError) { |
| 4485 | $closingBraces1 += '}'; |
| 4486 | } |
| 4487 | } |
| 4488 | } |
| 4489 | } |
| 4490 | } |
| 4491 | if ($breakOnError) { |
| 4492 | out += ' ' + ($closingBraces1) + ' '; |
| 4493 | $closingBraces1 = ''; |
| 4494 | } |
| 4495 | if ($rulesGroup.type) { |
| 4496 | out += ' } '; |
| 4497 | if ($typeSchema && $typeSchema === $rulesGroup.type && !$coerceToTypes) { |
| 4498 | out += ' else { '; |
| 4499 | var $schemaPath = it.schemaPath + '.type', |
| 4500 | $errSchemaPath = it.errSchemaPath + '/type'; |
| 4501 | var $$outStack = $$outStack || []; |
| 4502 | $$outStack.push(out); |
| 4503 | out = ''; /* istanbul ignore else */ |
| 4504 | if (it.createErrors !== false) { |
| 4505 | out += ' { keyword: \'' + ($errorKeyword || 'type') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: ' + (it.util.toQuotedString($errSchemaPath)) + ' , params: { type: \''; |
| 4506 | if ($typeIsArray) { |
| 4507 | out += '' + ($typeSchema.join(",")); |
| 4508 | } else { |
| 4509 | out += '' + ($typeSchema); |
| 4510 | } |
| 4511 | out += '\' } '; |
| 4512 | if (it.opts.messages !== false) { |
| 4513 | out += ' , message: \'should be '; |
| 4514 | if ($typeIsArray) { |
| 4515 | out += '' + ($typeSchema.join(",")); |
| 4516 | } else { |
| 4517 | out += '' + ($typeSchema); |
| 4518 | } |
| 4519 | out += '\' '; |
| 4520 | } |
| 4521 | if (it.opts.verbose) { |
| 4522 | out += ' , schema: validate.schema' + ($schemaPath) + ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' '; |
| 4523 | } |
| 4524 | out += ' } '; |
| 4525 | } else { |
| 4526 | out += ' {} '; |
| 4527 | } |
| 4528 | var __err = out; |
| 4529 | out = $$outStack.pop(); |
| 4530 | if (!it.compositeRule && $breakOnError) { /* istanbul ignore if */ |
| 4531 | if (it.async) { |
| 4532 | out += ' throw new ValidationError([' + (__err) + ']); '; |
| 4533 | } else { |
| 4534 | out += ' validate.errors = [' + (__err) + ']; return false; '; |
| 4535 | } |
| 4536 | } else { |
| 4537 | out += ' var err = ' + (__err) + '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; '; |
| 4538 | } |
| 4539 | out += ' } '; |
| 4540 | } |
| 4541 | } |
| 4542 | if ($breakOnError) { |
| 4543 | out += ' if (errors === '; |
| 4544 | if ($top) { |
| 4545 | out += '0'; |
| 4546 | } else { |
| 4547 | out += 'errs_' + ($lvl); |
| 4548 | } |
| 4549 | out += ') { '; |
| 4550 | $closingBraces2 += '}'; |
| 4551 | } |
| 4552 | } |
| 4553 | } |
| 4554 | } |
| 4555 | } |
| 4556 | if ($breakOnError) { |
| 4557 | out += ' ' + ($closingBraces2) + ' '; |
| 4558 | } |
| 4559 | if ($top) { |
| 4560 | if ($async) { |
| 4561 | out += ' if (errors === 0) return data; '; |
| 4562 | out += ' else throw new ValidationError(vErrors); '; |
| 4563 | } else { |
| 4564 | out += ' validate.errors = vErrors; '; |
| 4565 | out += ' return errors === 0; '; |
| 4566 | } |
| 4567 | out += ' }); return validate;'; |
| 4568 | } else { |
| 4569 | out += ' var ' + ($valid) + ' = errors === errs_' + ($lvl) + ';'; |
| 4570 | } |
| 4571 | out = it.util.cleanUpCode(out); |
| 4572 | if ($top) { |
| 4573 | out = it.util.finalCleanUpCode(out, $async); |
| 4574 | } |
| 4575 | |
| 4576 | function $shouldUseGroup($rulesGroup) { |
| 4577 | var rules = $rulesGroup.rules; |
| 4578 | for (var i = 0; i < rules.length; i++) |
| 4579 | if ($shouldUseRule(rules[i])) return true; |
| 4580 | } |
| 4581 | |
| 4582 | function $shouldUseRule($rule) { |
| 4583 | return it.schema[$rule.keyword] !== undefined || ($rule.implements && $ruleImplementsSomeKeyword($rule)); |
| 4584 | } |
| 4585 | |
| 4586 | function $ruleImplementsSomeKeyword($rule) { |
| 4587 | var impl = $rule.implements; |
| 4588 | for (var i = 0; i < impl.length; i++) |
| 4589 | if (it.schema[impl[i]] !== undefined) return true; |
| 4590 | } |
| 4591 | return out; |
| 4592 | } |
| 4593 | |
| 4594 | },{}],36:[function(require,module,exports){ |
| 4595 | 'use strict'; |
| 4596 | |
| 4597 | var IDENTIFIER = /^[a-z_$][a-z0-9_$-]*$/i; |
| 4598 | var customRuleCode = require('./dotjs/custom'); |
| 4599 | |
| 4600 | module.exports = { |
| 4601 | add: addKeyword, |
| 4602 | get: getKeyword, |
| 4603 | remove: removeKeyword |
| 4604 | }; |
| 4605 | |
| 4606 | /** |
| 4607 | * Define custom keyword |
| 4608 | * @this Ajv |
| 4609 | * @param {String} keyword custom keyword, should be unique (including different from all standard, custom and macro keywords). |
| 4610 | * @param {Object} definition keyword definition object with properties `type` (type(s) which the keyword applies to), `validate` or `compile`. |
| 4611 | * @return {Ajv} this for method chaining |
| 4612 | */ |
| 4613 | function addKeyword(keyword, definition) { |
| 4614 | /* jshint validthis: true */ |
| 4615 | /* eslint no-shadow: 0 */ |
| 4616 | var RULES = this.RULES; |
| 4617 | |
| 4618 | if (RULES.keywords[keyword]) |
| 4619 | throw new Error('Keyword ' + keyword + ' is already defined'); |
| 4620 | |
| 4621 | if (!IDENTIFIER.test(keyword)) |
| 4622 | throw new Error('Keyword ' + keyword + ' is not a valid identifier'); |
| 4623 | |
| 4624 | if (definition) { |
| 4625 | if (definition.macro && definition.valid !== undefined) |
| 4626 | throw new Error('"valid" option cannot be used with macro keywords'); |
| 4627 | |
| 4628 | var dataType = definition.type; |
| 4629 | if (Array.isArray(dataType)) { |
| 4630 | var i, len = dataType.length; |
| 4631 | for (i=0; i<len; i++) checkDataType(dataType[i]); |
| 4632 | for (i=0; i<len; i++) _addRule(keyword, dataType[i], definition); |
| 4633 | } else { |
| 4634 | if (dataType) checkDataType(dataType); |
| 4635 | _addRule(keyword, dataType, definition); |
| 4636 | } |
| 4637 | |
| 4638 | var $data = definition.$data === true && this._opts.$data; |
| 4639 | if ($data && !definition.validate) |
| 4640 | throw new Error('$data support: "validate" function is not defined'); |
| 4641 | |
| 4642 | var metaSchema = definition.metaSchema; |
| 4643 | if (metaSchema) { |
| 4644 | if ($data) { |
| 4645 | metaSchema = { |
| 4646 | anyOf: [ |
| 4647 | metaSchema, |
| 4648 | { '$ref': 'https://raw.githubusercontent.com/epoberezkin/ajv/master/lib/refs/$data.json#' } |
| 4649 | ] |
| 4650 | }; |
| 4651 | } |
| 4652 | definition.validateSchema = this.compile(metaSchema, true); |
| 4653 | } |
| 4654 | } |
| 4655 | |
| 4656 | RULES.keywords[keyword] = RULES.all[keyword] = true; |
| 4657 | |
| 4658 | |
| 4659 | function _addRule(keyword, dataType, definition) { |
| 4660 | var ruleGroup; |
| 4661 | for (var i=0; i<RULES.length; i++) { |
| 4662 | var rg = RULES[i]; |
| 4663 | if (rg.type == dataType) { |
| 4664 | ruleGroup = rg; |
| 4665 | break; |
| 4666 | } |
| 4667 | } |
| 4668 | |
| 4669 | if (!ruleGroup) { |
| 4670 | ruleGroup = { type: dataType, rules: [] }; |
| 4671 | RULES.push(ruleGroup); |
| 4672 | } |
| 4673 | |
| 4674 | var rule = { |
| 4675 | keyword: keyword, |
| 4676 | definition: definition, |
| 4677 | custom: true, |
| 4678 | code: customRuleCode, |
| 4679 | implements: definition.implements |
| 4680 | }; |
| 4681 | ruleGroup.rules.push(rule); |
| 4682 | RULES.custom[keyword] = rule; |
| 4683 | } |
| 4684 | |
| 4685 | |
| 4686 | function checkDataType(dataType) { |
| 4687 | if (!RULES.types[dataType]) throw new Error('Unknown type ' + dataType); |
| 4688 | } |
| 4689 | |
| 4690 | return this; |
| 4691 | } |
| 4692 | |
| 4693 | |
| 4694 | /** |
| 4695 | * Get keyword |
| 4696 | * @this Ajv |
| 4697 | * @param {String} keyword pre-defined or custom keyword. |
| 4698 | * @return {Object|Boolean} custom keyword definition, `true` if it is a predefined keyword, `false` otherwise. |
| 4699 | */ |
| 4700 | function getKeyword(keyword) { |
| 4701 | /* jshint validthis: true */ |
| 4702 | var rule = this.RULES.custom[keyword]; |
| 4703 | return rule ? rule.definition : this.RULES.keywords[keyword] || false; |
| 4704 | } |
| 4705 | |
| 4706 | |
| 4707 | /** |
| 4708 | * Remove keyword |
| 4709 | * @this Ajv |
| 4710 | * @param {String} keyword pre-defined or custom keyword. |
| 4711 | * @return {Ajv} this for method chaining |
| 4712 | */ |
| 4713 | function removeKeyword(keyword) { |
| 4714 | /* jshint validthis: true */ |
| 4715 | var RULES = this.RULES; |
| 4716 | delete RULES.keywords[keyword]; |
| 4717 | delete RULES.all[keyword]; |
| 4718 | delete RULES.custom[keyword]; |
| 4719 | for (var i=0; i<RULES.length; i++) { |
| 4720 | var rules = RULES[i].rules; |
| 4721 | for (var j=0; j<rules.length; j++) { |
| 4722 | if (rules[j].keyword == keyword) { |
| 4723 | rules.splice(j, 1); |
| 4724 | break; |
| 4725 | } |
| 4726 | } |
| 4727 | } |
| 4728 | return this; |
| 4729 | } |
| 4730 | |
| 4731 | },{"./dotjs/custom":21}],37:[function(require,module,exports){ |
| 4732 | 'use strict'; |
| 4733 | |
| 4734 | var META_SCHEMA_ID = 'http://json-schema.org/draft-06/schema'; |
| 4735 | |
| 4736 | module.exports = function (ajv) { |
| 4737 | var defaultMeta = ajv._opts.defaultMeta; |
| 4738 | var metaSchemaRef = typeof defaultMeta == 'string' |
| 4739 | ? { $ref: defaultMeta } |
| 4740 | : ajv.getSchema(META_SCHEMA_ID) |
| 4741 | ? { $ref: META_SCHEMA_ID } |
| 4742 | : {}; |
| 4743 | |
| 4744 | ajv.addKeyword('patternGroups', { |
| 4745 | // implemented in properties.jst |
| 4746 | metaSchema: { |
| 4747 | type: 'object', |
| 4748 | additionalProperties: { |
| 4749 | type: 'object', |
| 4750 | required: [ 'schema' ], |
| 4751 | properties: { |
| 4752 | maximum: { |
| 4753 | type: 'integer', |
| 4754 | minimum: 0 |
| 4755 | }, |
| 4756 | minimum: { |
| 4757 | type: 'integer', |
| 4758 | minimum: 0 |
| 4759 | }, |
| 4760 | schema: metaSchemaRef |
| 4761 | }, |
| 4762 | additionalProperties: false |
| 4763 | } |
| 4764 | } |
| 4765 | }); |
| 4766 | ajv.RULES.all.properties.implements.push('patternGroups'); |
| 4767 | }; |
| 4768 | |
| 4769 | },{}],38:[function(require,module,exports){ |
| 4770 | module.exports={ |
| 4771 | "$schema": "http://json-schema.org/draft-06/schema#", |
| 4772 | "$id": "https://raw.githubusercontent.com/epoberezkin/ajv/master/lib/refs/$data.json#", |
| 4773 | "description": "Meta-schema for $data reference (JSON-schema extension proposal)", |
| 4774 | "type": "object", |
| 4775 | "required": [ "$data" ], |
| 4776 | "properties": { |
| 4777 | "$data": { |
| 4778 | "type": "string", |
| 4779 | "anyOf": [ |
| 4780 | { "format": "relative-json-pointer" }, |
| 4781 | { "format": "json-pointer" } |
| 4782 | ] |
| 4783 | } |
| 4784 | }, |
| 4785 | "additionalProperties": false |
| 4786 | } |
| 4787 | |
| 4788 | },{}],39:[function(require,module,exports){ |
| 4789 | module.exports={ |
| 4790 | "$schema": "http://json-schema.org/draft-06/schema#", |
| 4791 | "$id": "http://json-schema.org/draft-06/schema#", |
| 4792 | "title": "Core schema meta-schema", |
| 4793 | "definitions": { |
| 4794 | "schemaArray": { |
| 4795 | "type": "array", |
| 4796 | "minItems": 1, |
| 4797 | "items": { "$ref": "#" } |
| 4798 | }, |
| 4799 | "nonNegativeInteger": { |
| 4800 | "type": "integer", |
| 4801 | "minimum": 0 |
| 4802 | }, |
| 4803 | "nonNegativeIntegerDefault0": { |
| 4804 | "allOf": [ |
| 4805 | { "$ref": "#/definitions/nonNegativeInteger" }, |
| 4806 | { "default": 0 } |
| 4807 | ] |
| 4808 | }, |
| 4809 | "simpleTypes": { |
| 4810 | "enum": [ |
| 4811 | "array", |
| 4812 | "boolean", |
| 4813 | "integer", |
| 4814 | "null", |
| 4815 | "number", |
| 4816 | "object", |
| 4817 | "string" |
| 4818 | ] |
| 4819 | }, |
| 4820 | "stringArray": { |
| 4821 | "type": "array", |
| 4822 | "items": { "type": "string" }, |
| 4823 | "uniqueItems": true, |
| 4824 | "default": [] |
| 4825 | } |
| 4826 | }, |
| 4827 | "type": ["object", "boolean"], |
| 4828 | "properties": { |
| 4829 | "$id": { |
| 4830 | "type": "string", |
| 4831 | "format": "uri-reference" |
| 4832 | }, |
| 4833 | "$schema": { |
| 4834 | "type": "string", |
| 4835 | "format": "uri" |
| 4836 | }, |
| 4837 | "$ref": { |
| 4838 | "type": "string", |
| 4839 | "format": "uri-reference" |
| 4840 | }, |
| 4841 | "title": { |
| 4842 | "type": "string" |
| 4843 | }, |
| 4844 | "description": { |
| 4845 | "type": "string" |
| 4846 | }, |
| 4847 | "default": {}, |
| 4848 | "examples": { |
| 4849 | "type": "array", |
| 4850 | "items": {} |
| 4851 | }, |
| 4852 | "multipleOf": { |
| 4853 | "type": "number", |
| 4854 | "exclusiveMinimum": 0 |
| 4855 | }, |
| 4856 | "maximum": { |
| 4857 | "type": "number" |
| 4858 | }, |
| 4859 | "exclusiveMaximum": { |
| 4860 | "type": "number" |
| 4861 | }, |
| 4862 | "minimum": { |
| 4863 | "type": "number" |
| 4864 | }, |
| 4865 | "exclusiveMinimum": { |
| 4866 | "type": "number" |
| 4867 | }, |
| 4868 | "maxLength": { "$ref": "#/definitions/nonNegativeInteger" }, |
| 4869 | "minLength": { "$ref": "#/definitions/nonNegativeIntegerDefault0" }, |
| 4870 | "pattern": { |
| 4871 | "type": "string", |
| 4872 | "format": "regex" |
| 4873 | }, |
| 4874 | "additionalItems": { "$ref": "#" }, |
| 4875 | "items": { |
| 4876 | "anyOf": [ |
| 4877 | { "$ref": "#" }, |
| 4878 | { "$ref": "#/definitions/schemaArray" } |
| 4879 | ], |
| 4880 | "default": {} |
| 4881 | }, |
| 4882 | "maxItems": { "$ref": "#/definitions/nonNegativeInteger" }, |
| 4883 | "minItems": { "$ref": "#/definitions/nonNegativeIntegerDefault0" }, |
| 4884 | "uniqueItems": { |
| 4885 | "type": "boolean", |
| 4886 | "default": false |
| 4887 | }, |
| 4888 | "contains": { "$ref": "#" }, |
| 4889 | "maxProperties": { "$ref": "#/definitions/nonNegativeInteger" }, |
| 4890 | "minProperties": { "$ref": "#/definitions/nonNegativeIntegerDefault0" }, |
| 4891 | "required": { "$ref": "#/definitions/stringArray" }, |
| 4892 | "additionalProperties": { "$ref": "#" }, |
| 4893 | "definitions": { |
| 4894 | "type": "object", |
| 4895 | "additionalProperties": { "$ref": "#" }, |
| 4896 | "default": {} |
| 4897 | }, |
| 4898 | "properties": { |
| 4899 | "type": "object", |
| 4900 | "additionalProperties": { "$ref": "#" }, |
| 4901 | "default": {} |
| 4902 | }, |
| 4903 | "patternProperties": { |
| 4904 | "type": "object", |
| 4905 | "additionalProperties": { "$ref": "#" }, |
| 4906 | "default": {} |
| 4907 | }, |
| 4908 | "dependencies": { |
| 4909 | "type": "object", |
| 4910 | "additionalProperties": { |
| 4911 | "anyOf": [ |
| 4912 | { "$ref": "#" }, |
| 4913 | { "$ref": "#/definitions/stringArray" } |
| 4914 | ] |
| 4915 | } |
| 4916 | }, |
| 4917 | "propertyNames": { "$ref": "#" }, |
| 4918 | "const": {}, |
| 4919 | "enum": { |
| 4920 | "type": "array", |
| 4921 | "minItems": 1, |
| 4922 | "uniqueItems": true |
| 4923 | }, |
| 4924 | "type": { |
| 4925 | "anyOf": [ |
| 4926 | { "$ref": "#/definitions/simpleTypes" }, |
| 4927 | { |
| 4928 | "type": "array", |
| 4929 | "items": { "$ref": "#/definitions/simpleTypes" }, |
| 4930 | "minItems": 1, |
| 4931 | "uniqueItems": true |
| 4932 | } |
| 4933 | ] |
| 4934 | }, |
| 4935 | "format": { "type": "string" }, |
| 4936 | "allOf": { "$ref": "#/definitions/schemaArray" }, |
| 4937 | "anyOf": { "$ref": "#/definitions/schemaArray" }, |
| 4938 | "oneOf": { "$ref": "#/definitions/schemaArray" }, |
| 4939 | "not": { "$ref": "#" } |
| 4940 | }, |
| 4941 | "default": {} |
| 4942 | } |
| 4943 | |
| 4944 | },{}],40:[function(require,module,exports){ |
| 4945 | |
| 4946 | /** |
| 4947 | * slice() reference. |
| 4948 | */ |
| 4949 | |
| 4950 | var slice = Array.prototype.slice; |
| 4951 | |
| 4952 | /** |
| 4953 | * Expose `co`. |
| 4954 | */ |
| 4955 | |
| 4956 | module.exports = co['default'] = co.co = co; |
| 4957 | |
| 4958 | /** |
| 4959 | * Wrap the given generator `fn` into a |
| 4960 | * function that returns a promise. |
| 4961 | * This is a separate function so that |
| 4962 | * every `co()` call doesn't create a new, |
| 4963 | * unnecessary closure. |
| 4964 | * |
| 4965 | * @param {GeneratorFunction} fn |
| 4966 | * @return {Function} |
| 4967 | * @api public |
| 4968 | */ |
| 4969 | |
| 4970 | co.wrap = function (fn) { |
| 4971 | createPromise.__generatorFunction__ = fn; |
| 4972 | return createPromise; |
| 4973 | function createPromise() { |
| 4974 | return co.call(this, fn.apply(this, arguments)); |
| 4975 | } |
| 4976 | }; |
| 4977 | |
| 4978 | /** |
| 4979 | * Execute the generator function or a generator |
| 4980 | * and return a promise. |
| 4981 | * |
| 4982 | * @param {Function} fn |
| 4983 | * @return {Promise} |
| 4984 | * @api public |
| 4985 | */ |
| 4986 | |
| 4987 | function co(gen) { |
| 4988 | var ctx = this; |
| 4989 | var args = slice.call(arguments, 1) |
| 4990 | |
| 4991 | // we wrap everything in a promise to avoid promise chaining, |
| 4992 | // which leads to memory leak errors. |
| 4993 | // see https://github.com/tj/co/issues/180 |
| 4994 | return new Promise(function(resolve, reject) { |
| 4995 | if (typeof gen === 'function') gen = gen.apply(ctx, args); |
| 4996 | if (!gen || typeof gen.next !== 'function') return resolve(gen); |
| 4997 | |
| 4998 | onFulfilled(); |
| 4999 | |
| 5000 | /** |
| 5001 | * @param {Mixed} res |
| 5002 | * @return {Promise} |
| 5003 | * @api private |
| 5004 | */ |
| 5005 | |
| 5006 | function onFulfilled(res) { |
| 5007 | var ret; |
| 5008 | try { |
| 5009 | ret = gen.next(res); |
| 5010 | } catch (e) { |
| 5011 | return reject(e); |
| 5012 | } |
| 5013 | next(ret); |
| 5014 | } |
| 5015 | |
| 5016 | /** |
| 5017 | * @param {Error} err |
| 5018 | * @return {Promise} |
| 5019 | * @api private |
| 5020 | */ |
| 5021 | |
| 5022 | function onRejected(err) { |
| 5023 | var ret; |
| 5024 | try { |
| 5025 | ret = gen.throw(err); |
| 5026 | } catch (e) { |
| 5027 | return reject(e); |
| 5028 | } |
| 5029 | next(ret); |
| 5030 | } |
| 5031 | |
| 5032 | /** |
| 5033 | * Get the next value in the generator, |
| 5034 | * return a promise. |
| 5035 | * |
| 5036 | * @param {Object} ret |
| 5037 | * @return {Promise} |
| 5038 | * @api private |
| 5039 | */ |
| 5040 | |
| 5041 | function next(ret) { |
| 5042 | if (ret.done) return resolve(ret.value); |
| 5043 | var value = toPromise.call(ctx, ret.value); |
| 5044 | if (value && isPromise(value)) return value.then(onFulfilled, onRejected); |
| 5045 | return onRejected(new TypeError('You may only yield a function, promise, generator, array, or object, ' |
| 5046 | + 'but the following object was passed: "' + String(ret.value) + '"')); |
| 5047 | } |
| 5048 | }); |
| 5049 | } |
| 5050 | |
| 5051 | /** |
| 5052 | * Convert a `yield`ed value into a promise. |
| 5053 | * |
| 5054 | * @param {Mixed} obj |
| 5055 | * @return {Promise} |
| 5056 | * @api private |
| 5057 | */ |
| 5058 | |
| 5059 | function toPromise(obj) { |
| 5060 | if (!obj) return obj; |
| 5061 | if (isPromise(obj)) return obj; |
| 5062 | if (isGeneratorFunction(obj) || isGenerator(obj)) return co.call(this, obj); |
| 5063 | if ('function' == typeof obj) return thunkToPromise.call(this, obj); |
| 5064 | if (Array.isArray(obj)) return arrayToPromise.call(this, obj); |
| 5065 | if (isObject(obj)) return objectToPromise.call(this, obj); |
| 5066 | return obj; |
| 5067 | } |
| 5068 | |
| 5069 | /** |
| 5070 | * Convert a thunk to a promise. |
| 5071 | * |
| 5072 | * @param {Function} |
| 5073 | * @return {Promise} |
| 5074 | * @api private |
| 5075 | */ |
| 5076 | |
| 5077 | function thunkToPromise(fn) { |
| 5078 | var ctx = this; |
| 5079 | return new Promise(function (resolve, reject) { |
| 5080 | fn.call(ctx, function (err, res) { |
| 5081 | if (err) return reject(err); |
| 5082 | if (arguments.length > 2) res = slice.call(arguments, 1); |
| 5083 | resolve(res); |
| 5084 | }); |
| 5085 | }); |
| 5086 | } |
| 5087 | |
| 5088 | /** |
| 5089 | * Convert an array of "yieldables" to a promise. |
| 5090 | * Uses `Promise.all()` internally. |
| 5091 | * |
| 5092 | * @param {Array} obj |
| 5093 | * @return {Promise} |
| 5094 | * @api private |
| 5095 | */ |
| 5096 | |
| 5097 | function arrayToPromise(obj) { |
| 5098 | return Promise.all(obj.map(toPromise, this)); |
| 5099 | } |
| 5100 | |
| 5101 | /** |
| 5102 | * Convert an object of "yieldables" to a promise. |
| 5103 | * Uses `Promise.all()` internally. |
| 5104 | * |
| 5105 | * @param {Object} obj |
| 5106 | * @return {Promise} |
| 5107 | * @api private |
| 5108 | */ |
| 5109 | |
| 5110 | function objectToPromise(obj){ |
| 5111 | var results = new obj.constructor(); |
| 5112 | var keys = Object.keys(obj); |
| 5113 | var promises = []; |
| 5114 | for (var i = 0; i < keys.length; i++) { |
| 5115 | var key = keys[i]; |
| 5116 | var promise = toPromise.call(this, obj[key]); |
| 5117 | if (promise && isPromise(promise)) defer(promise, key); |
| 5118 | else results[key] = obj[key]; |
| 5119 | } |
| 5120 | return Promise.all(promises).then(function () { |
| 5121 | return results; |
| 5122 | }); |
| 5123 | |
| 5124 | function defer(promise, key) { |
| 5125 | // predefine the key in the result |
| 5126 | results[key] = undefined; |
| 5127 | promises.push(promise.then(function (res) { |
| 5128 | results[key] = res; |
| 5129 | })); |
| 5130 | } |
| 5131 | } |
| 5132 | |
| 5133 | /** |
| 5134 | * Check if `obj` is a promise. |
| 5135 | * |
| 5136 | * @param {Object} obj |
| 5137 | * @return {Boolean} |
| 5138 | * @api private |
| 5139 | */ |
| 5140 | |
| 5141 | function isPromise(obj) { |
| 5142 | return 'function' == typeof obj.then; |
| 5143 | } |
| 5144 | |
| 5145 | /** |
| 5146 | * Check if `obj` is a generator. |
| 5147 | * |
| 5148 | * @param {Mixed} obj |
| 5149 | * @return {Boolean} |
| 5150 | * @api private |
| 5151 | */ |
| 5152 | |
| 5153 | function isGenerator(obj) { |
| 5154 | return 'function' == typeof obj.next && 'function' == typeof obj.throw; |
| 5155 | } |
| 5156 | |
| 5157 | /** |
| 5158 | * Check if `obj` is a generator function. |
| 5159 | * |
| 5160 | * @param {Mixed} obj |
| 5161 | * @return {Boolean} |
| 5162 | * @api private |
| 5163 | */ |
| 5164 | function isGeneratorFunction(obj) { |
| 5165 | var constructor = obj.constructor; |
| 5166 | if (!constructor) return false; |
| 5167 | if ('GeneratorFunction' === constructor.name || 'GeneratorFunction' === constructor.displayName) return true; |
| 5168 | return isGenerator(constructor.prototype); |
| 5169 | } |
| 5170 | |
| 5171 | /** |
| 5172 | * Check for plain object. |
| 5173 | * |
| 5174 | * @param {Mixed} val |
| 5175 | * @return {Boolean} |
| 5176 | * @api private |
| 5177 | */ |
| 5178 | |
| 5179 | function isObject(val) { |
| 5180 | return Object == val.constructor; |
| 5181 | } |
| 5182 | |
| 5183 | },{}],41:[function(require,module,exports){ |
| 5184 | 'use strict'; |
| 5185 | |
| 5186 | module.exports = function equal(a, b) { |
| 5187 | if (a === b) return true; |
| 5188 | |
| 5189 | var arrA = Array.isArray(a) |
| 5190 | , arrB = Array.isArray(b) |
| 5191 | , i; |
| 5192 | |
| 5193 | if (arrA && arrB) { |
| 5194 | if (a.length != b.length) return false; |
| 5195 | for (i = 0; i < a.length; i++) |
| 5196 | if (!equal(a[i], b[i])) return false; |
| 5197 | return true; |
| 5198 | } |
| 5199 | |
| 5200 | if (arrA != arrB) return false; |
| 5201 | |
| 5202 | if (a && b && typeof a === 'object' && typeof b === 'object') { |
| 5203 | var keys = Object.keys(a); |
| 5204 | if (keys.length !== Object.keys(b).length) return false; |
| 5205 | |
| 5206 | var dateA = a instanceof Date |
| 5207 | , dateB = b instanceof Date; |
| 5208 | if (dateA && dateB) return a.getTime() == b.getTime(); |
| 5209 | if (dateA != dateB) return false; |
| 5210 | |
| 5211 | var regexpA = a instanceof RegExp |
| 5212 | , regexpB = b instanceof RegExp; |
| 5213 | if (regexpA && regexpB) return a.toString() == b.toString(); |
| 5214 | if (regexpA != regexpB) return false; |
| 5215 | |
| 5216 | for (i = 0; i < keys.length; i++) |
| 5217 | if (!Object.prototype.hasOwnProperty.call(b, keys[i])) return false; |
| 5218 | |
| 5219 | for (i = 0; i < keys.length; i++) |
| 5220 | if(!equal(a[keys[i]], b[keys[i]])) return false; |
| 5221 | |
| 5222 | return true; |
| 5223 | } |
| 5224 | |
| 5225 | return false; |
| 5226 | }; |
| 5227 | |
| 5228 | },{}],42:[function(require,module,exports){ |
| 5229 | 'use strict'; |
| 5230 | |
| 5231 | module.exports = function (data, opts) { |
| 5232 | if (!opts) opts = {}; |
| 5233 | if (typeof opts === 'function') opts = { cmp: opts }; |
| 5234 | var cycles = (typeof opts.cycles === 'boolean') ? opts.cycles : false; |
| 5235 | |
| 5236 | var cmp = opts.cmp && (function (f) { |
| 5237 | return function (node) { |
| 5238 | return function (a, b) { |
| 5239 | var aobj = { key: a, value: node[a] }; |
| 5240 | var bobj = { key: b, value: node[b] }; |
| 5241 | return f(aobj, bobj); |
| 5242 | }; |
| 5243 | }; |
| 5244 | })(opts.cmp); |
| 5245 | |
| 5246 | var seen = []; |
| 5247 | return (function stringify (node) { |
| 5248 | if (node && node.toJSON && typeof node.toJSON === 'function') { |
| 5249 | node = node.toJSON(); |
| 5250 | } |
| 5251 | |
| 5252 | if (node === undefined) return; |
| 5253 | if (typeof node == 'number') return isFinite(node) ? '' + node : 'null'; |
| 5254 | if (typeof node !== 'object') return JSON.stringify(node); |
| 5255 | |
| 5256 | var i, out; |
| 5257 | if (Array.isArray(node)) { |
| 5258 | out = '['; |
| 5259 | for (i = 0; i < node.length; i++) { |
| 5260 | if (i) out += ','; |
| 5261 | out += stringify(node[i]) || 'null'; |
| 5262 | } |
| 5263 | return out + ']'; |
| 5264 | } |
| 5265 | |
| 5266 | if (node === null) return 'null'; |
| 5267 | |
| 5268 | if (seen.indexOf(node) !== -1) { |
| 5269 | if (cycles) return JSON.stringify('__cycle__'); |
| 5270 | throw new TypeError('Converting circular structure to JSON'); |
| 5271 | } |
| 5272 | |
| 5273 | var seenIndex = seen.push(node) - 1; |
| 5274 | var keys = Object.keys(node).sort(cmp && cmp(node)); |
| 5275 | out = ''; |
| 5276 | for (i = 0; i < keys.length; i++) { |
| 5277 | var key = keys[i]; |
| 5278 | var value = stringify(node[key]); |
| 5279 | |
| 5280 | if (!value) continue; |
| 5281 | if (out) out += ','; |
| 5282 | out += JSON.stringify(key) + ':' + value; |
| 5283 | } |
| 5284 | seen.splice(seenIndex, 1); |
| 5285 | return '{' + out + '}'; |
| 5286 | })(data); |
| 5287 | }; |
| 5288 | |
| 5289 | },{}],43:[function(require,module,exports){ |
| 5290 | 'use strict'; |
| 5291 | |
| 5292 | var traverse = module.exports = function (schema, opts, cb) { |
| 5293 | if (typeof opts == 'function') { |
| 5294 | cb = opts; |
| 5295 | opts = {}; |
| 5296 | } |
| 5297 | _traverse(opts, cb, schema, '', schema); |
| 5298 | }; |
| 5299 | |
| 5300 | |
| 5301 | traverse.keywords = { |
| 5302 | additionalItems: true, |
| 5303 | items: true, |
| 5304 | contains: true, |
| 5305 | additionalProperties: true, |
| 5306 | propertyNames: true, |
| 5307 | not: true |
| 5308 | }; |
| 5309 | |
| 5310 | traverse.arrayKeywords = { |
| 5311 | items: true, |
| 5312 | allOf: true, |
| 5313 | anyOf: true, |
| 5314 | oneOf: true |
| 5315 | }; |
| 5316 | |
| 5317 | traverse.propsKeywords = { |
| 5318 | definitions: true, |
| 5319 | properties: true, |
| 5320 | patternProperties: true, |
| 5321 | dependencies: true |
| 5322 | }; |
| 5323 | |
| 5324 | traverse.skipKeywords = { |
| 5325 | enum: true, |
| 5326 | const: true, |
| 5327 | required: true, |
| 5328 | maximum: true, |
| 5329 | minimum: true, |
| 5330 | exclusiveMaximum: true, |
| 5331 | exclusiveMinimum: true, |
| 5332 | multipleOf: true, |
| 5333 | maxLength: true, |
| 5334 | minLength: true, |
| 5335 | pattern: true, |
| 5336 | format: true, |
| 5337 | maxItems: true, |
| 5338 | minItems: true, |
| 5339 | uniqueItems: true, |
| 5340 | maxProperties: true, |
| 5341 | minProperties: true |
| 5342 | }; |
| 5343 | |
| 5344 | |
| 5345 | function _traverse(opts, cb, schema, jsonPtr, rootSchema, parentJsonPtr, parentKeyword, parentSchema, keyIndex) { |
| 5346 | if (schema && typeof schema == 'object' && !Array.isArray(schema)) { |
| 5347 | cb(schema, jsonPtr, rootSchema, parentJsonPtr, parentKeyword, parentSchema, keyIndex); |
| 5348 | for (var key in schema) { |
| 5349 | var sch = schema[key]; |
| 5350 | if (Array.isArray(sch)) { |
| 5351 | if (key in traverse.arrayKeywords) { |
| 5352 | for (var i=0; i<sch.length; i++) |
| 5353 | _traverse(opts, cb, sch[i], jsonPtr + '/' + key + '/' + i, rootSchema, jsonPtr, key, schema, i); |
| 5354 | } |
| 5355 | } else if (key in traverse.pr |
| 5356 | … afgekapt |