You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

7143 lines
264 KiB

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