z-schema 12.0.4 → 12.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (176) hide show
  1. package/bin/z-schema +7 -2
  2. package/cjs/index.d.ts +541 -530
  3. package/cjs/index.js +3963 -7740
  4. package/dist/errors.d.mts +64 -0
  5. package/dist/errors.mjs +67 -0
  6. package/dist/format-validators.d.mts +14 -0
  7. package/dist/format-validators.mjs +261 -0
  8. package/dist/index.d.mts +10 -0
  9. package/dist/index.mjs +7 -0
  10. package/dist/json-schema-versions.d.mts +137 -0
  11. package/dist/json-schema-versions.mjs +11 -0
  12. package/dist/json-schema.d.mts +61 -0
  13. package/dist/json-schema.mjs +53 -0
  14. package/dist/json-validation.mjs +441 -0
  15. package/dist/report.d.mts +97 -0
  16. package/dist/report.mjs +194 -0
  17. package/dist/schema-cache.d.mts +23 -0
  18. package/dist/schema-cache.mjs +144 -0
  19. package/dist/schema-compiler.d.mts +23 -0
  20. package/dist/schema-compiler.mjs +265 -0
  21. package/dist/schema-validator.d.mts +15 -0
  22. package/dist/schema-validator.mjs +446 -0
  23. package/dist/schemas/draft-04-schema.mjs +125 -0
  24. package/dist/schemas/draft-06-schema.mjs +126 -0
  25. package/dist/schemas/draft-07-schema.mjs +141 -0
  26. package/dist/schemas/draft-2019-09-meta-applicator.mjs +46 -0
  27. package/dist/schemas/draft-2019-09-meta-content.mjs +15 -0
  28. package/dist/schemas/draft-2019-09-meta-core.mjs +52 -0
  29. package/dist/schemas/draft-2019-09-meta-format.mjs +11 -0
  30. package/dist/schemas/draft-2019-09-meta-meta-data.mjs +31 -0
  31. package/dist/schemas/draft-2019-09-meta-validation.mjs +80 -0
  32. package/dist/schemas/draft-2019-09-schema.mjs +39 -0
  33. package/dist/schemas/draft-2020-12-meta-applicator.mjs +45 -0
  34. package/dist/schemas/draft-2020-12-meta-content.mjs +15 -0
  35. package/dist/schemas/draft-2020-12-meta-core.mjs +46 -0
  36. package/dist/schemas/draft-2020-12-meta-format-annotation.mjs +11 -0
  37. package/dist/schemas/draft-2020-12-meta-format-assertion.mjs +11 -0
  38. package/dist/schemas/draft-2020-12-meta-meta-data.mjs +31 -0
  39. package/dist/schemas/draft-2020-12-meta-unevaluated.mjs +14 -0
  40. package/dist/schemas/draft-2020-12-meta-validation.mjs +80 -0
  41. package/dist/schemas/draft-2020-12-schema.mjs +55 -0
  42. package/dist/utils/array.mjs +54 -0
  43. package/dist/utils/base64.mjs +21 -0
  44. package/dist/utils/clone.mjs +42 -0
  45. package/dist/utils/constants.mjs +16 -0
  46. package/dist/utils/date.mjs +19 -0
  47. package/dist/utils/hostname.mjs +73 -0
  48. package/dist/utils/json.mjs +34 -0
  49. package/dist/utils/properties.mjs +11 -0
  50. package/dist/utils/schema-regex.mjs +49 -0
  51. package/dist/utils/symbols.mjs +5 -0
  52. package/dist/utils/time.mjs +42 -0
  53. package/dist/utils/unicode.mjs +12 -0
  54. package/dist/utils/uri.mjs +12 -0
  55. package/dist/utils/what-is.mjs +23 -0
  56. package/dist/validation/array.mjs +57 -0
  57. package/dist/validation/combinators.mjs +62 -0
  58. package/dist/validation/numeric.mjs +38 -0
  59. package/dist/validation/object.mjs +109 -0
  60. package/dist/validation/ref.mjs +49 -0
  61. package/dist/validation/shared.mjs +97 -0
  62. package/dist/validation/string.mjs +88 -0
  63. package/dist/validation/type.mjs +32 -0
  64. package/dist/z-schema-base.d.mts +85 -0
  65. package/dist/z-schema-base.mjs +230 -0
  66. package/dist/z-schema-options.d.mts +35 -0
  67. package/dist/z-schema-options.mjs +55 -0
  68. package/dist/z-schema-reader.d.mts +6 -0
  69. package/dist/z-schema-reader.mjs +10 -0
  70. package/dist/z-schema-versions.mjs +67 -0
  71. package/dist/z-schema.d.mts +193 -0
  72. package/dist/z-schema.mjs +300 -0
  73. package/package.json +49 -64
  74. package/src/index.ts +3 -3
  75. package/src/schema-compiler.ts +30 -10
  76. package/src/schema-validator.ts +1 -1
  77. package/src/utils/schema-regex.ts +13 -2
  78. package/src/z-schema-base.ts +1 -1
  79. package/src/z-schema-versions.ts +1 -2
  80. package/src/z-schema.ts +0 -1
  81. package/umd/ZSchema.js +5934 -8110
  82. package/umd/ZSchema.min.js +2 -1
  83. package/dist/errors.js +0 -72
  84. package/dist/format-validators.js +0 -392
  85. package/dist/index.js +0 -5
  86. package/dist/json-schema-versions.js +0 -8
  87. package/dist/json-schema.js +0 -84
  88. package/dist/json-validation.js +0 -728
  89. package/dist/package.json +0 -3
  90. package/dist/report.js +0 -265
  91. package/dist/schema-cache.js +0 -211
  92. package/dist/schema-compiler.js +0 -415
  93. package/dist/schema-validator.js +0 -721
  94. package/dist/schemas/draft-04-schema.json +0 -149
  95. package/dist/schemas/draft-06-schema.json +0 -155
  96. package/dist/schemas/draft-07-schema.json +0 -172
  97. package/dist/schemas/draft-2019-09-meta-applicator.json +0 -52
  98. package/dist/schemas/draft-2019-09-meta-content.json +0 -12
  99. package/dist/schemas/draft-2019-09-meta-core.json +0 -53
  100. package/dist/schemas/draft-2019-09-meta-format.json +0 -10
  101. package/dist/schemas/draft-2019-09-meta-meta-data.json +0 -32
  102. package/dist/schemas/draft-2019-09-meta-validation.json +0 -94
  103. package/dist/schemas/draft-2019-09-schema.json +0 -41
  104. package/dist/schemas/draft-2020-12-meta-applicator.json +0 -44
  105. package/dist/schemas/draft-2020-12-meta-content.json +0 -12
  106. package/dist/schemas/draft-2020-12-meta-core.json +0 -47
  107. package/dist/schemas/draft-2020-12-meta-format-annotation.json +0 -10
  108. package/dist/schemas/draft-2020-12-meta-format-assertion.json +0 -10
  109. package/dist/schemas/draft-2020-12-meta-meta-data.json +0 -32
  110. package/dist/schemas/draft-2020-12-meta-unevaluated.json +0 -11
  111. package/dist/schemas/draft-2020-12-meta-validation.json +0 -94
  112. package/dist/schemas/draft-2020-12-schema.json +0 -57
  113. package/dist/types/errors.d.ts +0 -64
  114. package/dist/types/format-validators.d.ts +0 -11
  115. package/dist/types/index.d.ts +0 -14
  116. package/dist/types/json-schema-versions.d.ts +0 -142
  117. package/dist/types/json-schema.d.ts +0 -66
  118. package/dist/types/json-validation.d.ts +0 -6
  119. package/dist/types/report.d.ts +0 -94
  120. package/dist/types/schema-cache.d.ts +0 -27
  121. package/dist/types/schema-compiler.d.ts +0 -31
  122. package/dist/types/schema-validator.d.ts +0 -10
  123. package/dist/types/utils/array.d.ts +0 -9
  124. package/dist/types/utils/base64.d.ts +0 -2
  125. package/dist/types/utils/clone.d.ts +0 -2
  126. package/dist/types/utils/constants.d.ts +0 -19
  127. package/dist/types/utils/date.d.ts +0 -1
  128. package/dist/types/utils/hostname.d.ts +0 -2
  129. package/dist/types/utils/json.d.ts +0 -9
  130. package/dist/types/utils/properties.d.ts +0 -1
  131. package/dist/types/utils/schema-regex.d.ts +0 -10
  132. package/dist/types/utils/symbols.d.ts +0 -2
  133. package/dist/types/utils/time.d.ts +0 -12
  134. package/dist/types/utils/unicode.d.ts +0 -5
  135. package/dist/types/utils/uri.d.ts +0 -4
  136. package/dist/types/utils/what-is.d.ts +0 -4
  137. package/dist/types/validation/array.d.ts +0 -12
  138. package/dist/types/validation/combinators.d.ts +0 -10
  139. package/dist/types/validation/numeric.d.ts +0 -8
  140. package/dist/types/validation/object.d.ts +0 -13
  141. package/dist/types/validation/ref.d.ts +0 -11
  142. package/dist/types/validation/shared.d.ts +0 -26
  143. package/dist/types/validation/string.d.ts +0 -9
  144. package/dist/types/validation/type.d.ts +0 -6
  145. package/dist/types/z-schema-base.d.ts +0 -87
  146. package/dist/types/z-schema-options.d.ts +0 -35
  147. package/dist/types/z-schema-reader.d.ts +0 -4
  148. package/dist/types/z-schema-versions.d.ts +0 -1
  149. package/dist/types/z-schema.d.ts +0 -191
  150. package/dist/utils/array.js +0 -69
  151. package/dist/utils/base64.js +0 -29
  152. package/dist/utils/clone.js +0 -59
  153. package/dist/utils/constants.js +0 -19
  154. package/dist/utils/date.js +0 -21
  155. package/dist/utils/hostname.js +0 -146
  156. package/dist/utils/json.js +0 -70
  157. package/dist/utils/properties.js +0 -10
  158. package/dist/utils/schema-regex.js +0 -52
  159. package/dist/utils/symbols.js +0 -2
  160. package/dist/utils/time.js +0 -50
  161. package/dist/utils/unicode.js +0 -12
  162. package/dist/utils/uri.js +0 -15
  163. package/dist/utils/what-is.js +0 -32
  164. package/dist/validation/array.js +0 -127
  165. package/dist/validation/combinators.js +0 -106
  166. package/dist/validation/numeric.js +0 -97
  167. package/dist/validation/object.js +0 -237
  168. package/dist/validation/ref.js +0 -70
  169. package/dist/validation/shared.js +0 -136
  170. package/dist/validation/string.js +0 -170
  171. package/dist/validation/type.js +0 -55
  172. package/dist/z-schema-base.js +0 -286
  173. package/dist/z-schema-options.js +0 -99
  174. package/dist/z-schema-reader.js +0 -7
  175. package/dist/z-schema-versions.js +0 -110
  176. package/dist/z-schema.js +0 -287
@@ -1,286 +0,0 @@
1
- import { getValidateError } from './errors.js';
2
- import { getSupportedFormats } from './format-validators.js';
3
- import { isInternalKey } from './json-schema.js';
4
- import { VERSION_SCHEMA_URL_MAPPING } from './json-schema-versions.js';
5
- import { validate as validateJson } from './json-validation.js';
6
- import { Report } from './report.js';
7
- import { prepareRemoteSchema, SchemaCache } from './schema-cache.js';
8
- import { SchemaCompiler } from './schema-compiler.js';
9
- import { SchemaValidator } from './schema-validator.js';
10
- import { deepClone } from './utils/clone.js';
11
- import { get, sortedKeys } from './utils/json.js';
12
- import { copyProp } from './utils/properties.js';
13
- import { getRemotePath } from './utils/uri.js';
14
- import { isObject, whatIs } from './utils/what-is.js';
15
- import { defaultOptions, normalizeOptions } from './z-schema-options.js';
16
- /**
17
- * Module-private symbol used by `ZSchema.create()` to authorise construction.
18
- * Not exported — external code cannot instantiate ZSchema variants directly.
19
- */
20
- export const FACTORY_TOKEN = Symbol('ZSchema.factory');
21
- export class ZSchemaBase {
22
- scache;
23
- sc;
24
- sv;
25
- validateOptions = {};
26
- options;
27
- constructor(options, token) {
28
- if (token !== FACTORY_TOKEN) {
29
- throw new Error('do not use new ZSchema(), use ZSchema.create() instead');
30
- }
31
- this.scache = new SchemaCache(this);
32
- this.sc = new SchemaCompiler(this);
33
- this.sv = new SchemaValidator(this);
34
- this.options = normalizeOptions(options);
35
- }
36
- /**
37
- * Internal recursive JSON validation — delegates to the `validate` function
38
- * in `json-validation.ts`. Exposed as a method so that per-keyword validator
39
- * modules (array, combinators, object) can call back into the core validator
40
- * via `this` without importing `json-validation.ts` directly (which would
41
- * create a circular dependency).
42
- */
43
- _jsonValidate(report, schema, json) {
44
- return validateJson.call(this, report, schema, json);
45
- }
46
- getDefaultSchemaId() {
47
- return this.options.version && this.options.version !== 'none'
48
- ? VERSION_SCHEMA_URL_MAPPING[this.options.version]
49
- : VERSION_SCHEMA_URL_MAPPING[defaultOptions.version];
50
- }
51
- _validate(json, schema, options, callback) {
52
- if (typeof options === 'function') {
53
- callback = options;
54
- options = {};
55
- }
56
- if (!options) {
57
- options = {};
58
- }
59
- this.validateOptions = options;
60
- if (typeof schema !== 'string' && typeof schema !== 'boolean' && !isObject(schema)) {
61
- const e = new Error('Invalid .validate call - schema must be a string or object but ' + whatIs(schema) + ' was passed!');
62
- if (callback) {
63
- setTimeout(function () {
64
- callback(e, false);
65
- }, 0);
66
- return;
67
- }
68
- throw e;
69
- }
70
- let foundError = false;
71
- const report = new Report(this.options, options);
72
- report.json = json;
73
- let _schema;
74
- if (typeof schema === 'string') {
75
- const schemaName = schema;
76
- _schema = this.scache.getSchema(report, schemaName);
77
- if (!_schema) {
78
- const e = new Error("Schema with id '" + schemaName + "' wasn't found in the validator cache!");
79
- if (callback) {
80
- setTimeout(function () {
81
- callback(e, false);
82
- }, 0);
83
- return;
84
- }
85
- throw e;
86
- }
87
- }
88
- else {
89
- _schema = this.scache.getSchema(report, schema);
90
- }
91
- let compiled = false;
92
- if (!foundError) {
93
- compiled = this.sc.compileSchema(report, _schema);
94
- }
95
- if (!compiled) {
96
- foundError = true;
97
- }
98
- let validated = false;
99
- if (!foundError) {
100
- validated = this.sv.validateSchema(report, _schema);
101
- }
102
- if (!validated) {
103
- foundError = true;
104
- }
105
- if (options.schemaPath) {
106
- report.rootSchema = _schema;
107
- _schema = get(_schema, options.schemaPath);
108
- if (!_schema) {
109
- const e = new Error("Schema path '" + options.schemaPath + "' wasn't found in the schema!");
110
- if (callback) {
111
- setTimeout(function () {
112
- callback(e, false);
113
- }, 0);
114
- return;
115
- }
116
- throw e;
117
- }
118
- }
119
- if (!foundError) {
120
- validateJson.call(this, report, _schema, json);
121
- }
122
- if (callback) {
123
- report.processAsyncTasks(this.options.asyncTimeout, callback);
124
- return;
125
- }
126
- else if (report.asyncTasks.length > 0) {
127
- throw new Error('This validation has async tasks and cannot be done in sync mode, please provide callback argument.');
128
- }
129
- if (!report.isValid()) {
130
- throw getValidateError({
131
- message: report.commonErrorMessage,
132
- details: report.errors,
133
- });
134
- }
135
- return true;
136
- }
137
- _validateSchema(schemaOrArr) {
138
- if (Array.isArray(schemaOrArr) && schemaOrArr.length === 0) {
139
- throw new Error('.compileSchema was called with an empty array');
140
- }
141
- const report = new Report(this.options);
142
- if (Array.isArray(schemaOrArr)) {
143
- const arr = this.scache.getSchema(report, schemaOrArr);
144
- const compiled = this.sc.compileSchema(report, arr);
145
- if (compiled) {
146
- this.sv.validateSchema(report, arr);
147
- }
148
- }
149
- else {
150
- const schema = this.scache.getSchema(report, schemaOrArr);
151
- const compiled = this.sc.compileSchema(report, schema);
152
- if (compiled) {
153
- this.sv.validateSchema(report, schema);
154
- }
155
- }
156
- if (!report.isValid()) {
157
- throw getValidateError({ message: report.commonErrorMessage, details: report.errors });
158
- }
159
- return true;
160
- }
161
- /**
162
- * Register a format validator on this instance only (does not affect other instances or the global registry).
163
- * @param name - The format name.
164
- * @param validatorFunction - A sync or async function `(value: unknown) => boolean | Promise<boolean>`.
165
- */
166
- registerFormat(name, validatorFunction) {
167
- if (!this.options.customFormats) {
168
- this.options.customFormats = {};
169
- }
170
- this.options.customFormats[name] = validatorFunction;
171
- }
172
- /**
173
- * Unregister an instance-scoped format validator.
174
- * @param name - The format name to unregister.
175
- */
176
- unregisterFormat(name) {
177
- if (!this.options.customFormats) {
178
- this.options.customFormats = {};
179
- }
180
- this.options.customFormats[name] = null;
181
- }
182
- /** Returns the names of format validators registered on this instance. */
183
- getRegisteredFormats() {
184
- return sortedKeys(this.options.customFormats || {}).filter((key) => this.options.customFormats?.[key] != null);
185
- }
186
- /** Returns all supported format names (global + instance-registered). */
187
- getSupportedFormats() {
188
- return getSupportedFormats(this.options.customFormats);
189
- }
190
- /**
191
- * Register a remote schema in this instance's cache so `$ref` can resolve to it.
192
- * @param uri - The URI the schema will be known by.
193
- * @param schema - The schema object or JSON string.
194
- * @param validationOptions - Optional options used for schema preparation.
195
- */
196
- setRemoteReference(uri, schema, validationOptions) {
197
- const _schema = prepareRemoteSchema(schema, uri, validationOptions, this.options.maxRecursionDepth);
198
- this.scache.cacheSchemaByUri(uri, _schema);
199
- }
200
- /**
201
- * Extract unresolvable `$ref` URIs from a validation error.
202
- * @param err - A `ValidateError` from a failed validation.
203
- * @returns An array of unresolvable reference URIs.
204
- */
205
- getMissingReferences(err) {
206
- if (!err)
207
- return [];
208
- const details = err.details || [];
209
- const missingRefs = [];
210
- function collect(details) {
211
- for (const detail of details) {
212
- if (detail.code === 'UNRESOLVABLE_REFERENCE' || detail.code === 'SCHEMA_NOT_REACHABLE') {
213
- missingRefs.push(detail.params[0]);
214
- }
215
- if (detail.inner) {
216
- collect(detail.inner);
217
- }
218
- }
219
- }
220
- collect(details);
221
- return missingRefs;
222
- }
223
- /**
224
- * Extract unresolvable **remote** `$ref` URIs from a validation error (local fragment-only refs are excluded).
225
- * @param err - A `ValidateError` from a failed validation.
226
- * @returns An array of remote reference base URIs.
227
- */
228
- getMissingRemoteReferences(err) {
229
- const missingReferences = this.getMissingReferences(err);
230
- const missingRemoteReferences = [];
231
- for (const ref of missingReferences) {
232
- const remoteReference = getRemotePath(ref);
233
- if (remoteReference && !missingRemoteReferences.includes(remoteReference)) {
234
- missingRemoteReferences.push(remoteReference);
235
- }
236
- }
237
- return missingRemoteReferences;
238
- }
239
- /**
240
- * Resolve a previously compiled schema by its `$id` / `id`, cleaning up internal bookkeeping properties
241
- * and inlining resolved `$ref` targets.
242
- * @param schemaId - The schema identifier to look up.
243
- * @returns A clean, resolved copy of the schema, or `undefined` if not found.
244
- */
245
- getResolvedSchema(schemaId) {
246
- const report = new Report(this.options);
247
- const schema = this.scache.getSchemaByUri(report, schemaId);
248
- if (!schema)
249
- return undefined;
250
- const clonedSchema = deepClone(schema, this.options.maxRecursionDepth);
251
- const visited = new WeakSet();
252
- // clean-up the schema and resolve references
253
- const cleanup = function (schema) {
254
- let key;
255
- const typeOf = whatIs(schema);
256
- if (typeOf !== 'object' && typeOf !== 'array') {
257
- return;
258
- }
259
- if (visited.has(schema)) {
260
- return;
261
- }
262
- visited.add(schema);
263
- if (schema.$ref && schema.__$refResolved) {
264
- const from = schema.__$refResolved;
265
- const to = schema;
266
- delete schema.$ref;
267
- delete schema.__$refResolved;
268
- for (key in from) {
269
- copyProp(from, to, key);
270
- }
271
- }
272
- for (key in schema) {
273
- if (Object.hasOwn(schema, key)) {
274
- if (isInternalKey(key)) {
275
- delete schema[key];
276
- }
277
- else {
278
- cleanup(schema[key]);
279
- }
280
- }
281
- }
282
- };
283
- cleanup(clonedSchema);
284
- return clonedSchema;
285
- }
286
- }
@@ -1,99 +0,0 @@
1
- import { CURRENT_DEFAULT_SCHEMA_VERSION } from './json-schema-versions.js';
2
- import { shallowClone } from './utils/clone.js';
3
- import { DEFAULT_MAX_RECURSION_DEPTH, MAX_ASYNC_TIMEOUT } from './utils/constants.js';
4
- export { DEFAULT_MAX_RECURSION_DEPTH, MAX_ASYNC_TIMEOUT };
5
- export const defaultOptions = {
6
- // default version to validate against
7
- version: CURRENT_DEFAULT_SCHEMA_VERSION,
8
- // default timeout for all async tasks
9
- asyncTimeout: 2000,
10
- // force additionalProperties and additionalItems to be defined on "object" and "array" types
11
- forceAdditional: false,
12
- // assume additionalProperties and additionalItems are defined as "false" where appropriate
13
- assumeAdditional: false,
14
- // do case insensitive comparison for enums
15
- enumCaseInsensitiveComparison: false,
16
- // force items to be defined on "array" types
17
- forceItems: false,
18
- // force minItems to be defined on "array" types
19
- forceMinItems: false,
20
- // force maxItems to be defined on "array" types
21
- forceMaxItems: false,
22
- // force minLength to be defined on "string" types
23
- forceMinLength: false,
24
- // force maxLength to be defined on "string" types
25
- forceMaxLength: false,
26
- // force properties or patternProperties to be defined on "object" types
27
- forceProperties: false,
28
- // ignore references that cannot be resolved (remote schemas)
29
- ignoreUnresolvableReferences: false,
30
- // disallow usage of keywords that this validator can't handle
31
- noExtraKeywords: false,
32
- // disallow usage of schema's without "type" defined
33
- noTypeless: false,
34
- // disallow zero length strings in validated objects
35
- noEmptyStrings: false,
36
- // disallow zero length arrays in validated objects
37
- noEmptyArrays: false,
38
- // forces "uri" format to be in fully rfc3986 compliant
39
- strictUris: false,
40
- // turn on some of the above
41
- strictMode: false,
42
- // report error paths as an array of path segments to get to the offending node
43
- reportPathAsArray: false,
44
- // stop validation as soon as an error is found
45
- breakOnFirstError: false,
46
- // check if schema follows best practices and common sense
47
- pedanticCheck: false,
48
- // ignore unknown formats (do not report them as an error)
49
- ignoreUnknownFormats: false,
50
- // control format assertion behavior:
51
- // true - respect vocabulary: for draft 2019-09/2020-12, check meta-schema $vocabulary
52
- // to determine if format is assertion or annotation-only
53
- // false - format is always annotation-only (never asserts)
54
- // null - legacy behavior: always assert format validation
55
- formatAssertions: null,
56
- // function to be called on every schema
57
- customValidator: null,
58
- // maximum recursion depth for deeply nested schema/data traversal (prevents stack overflow)
59
- maxRecursionDepth: DEFAULT_MAX_RECURSION_DEPTH,
60
- };
61
- export const normalizeOptions = (options) => {
62
- let normalized;
63
- // options
64
- if (typeof options === 'object') {
65
- let keys = Object.keys(options);
66
- // check that the options are correctly configured
67
- for (const key of keys) {
68
- if (defaultOptions[key] === undefined) {
69
- throw new Error('Unexpected option passed to constructor: ' + key);
70
- }
71
- }
72
- // copy the default options into passed options
73
- keys = Object.keys(defaultOptions);
74
- for (const key of keys) {
75
- if (options[key] === undefined) {
76
- options[key] = shallowClone(defaultOptions[key]);
77
- }
78
- }
79
- normalized = options;
80
- }
81
- else {
82
- normalized = shallowClone(defaultOptions);
83
- }
84
- // Clamp asyncTimeout to prevent resource exhaustion (CWE-400)
85
- if (normalized.asyncTimeout != null) {
86
- normalized.asyncTimeout = Math.min(Math.max(normalized.asyncTimeout, 0), MAX_ASYNC_TIMEOUT);
87
- }
88
- if (normalized.strictMode === true) {
89
- normalized.forceAdditional = true;
90
- normalized.forceItems = true;
91
- normalized.forceMaxLength = true;
92
- normalized.forceProperties = true;
93
- normalized.noExtraKeywords = true;
94
- normalized.noTypeless = true;
95
- normalized.noEmptyStrings = true;
96
- normalized.noEmptyArrays = true;
97
- }
98
- return normalized;
99
- };
@@ -1,7 +0,0 @@
1
- let _schemaReader;
2
- export function getSchemaReader() {
3
- return _schemaReader;
4
- }
5
- export function setSchemaReader(schemaReader) {
6
- _schemaReader = schemaReader;
7
- }
@@ -1,110 +0,0 @@
1
- import { SchemaCache } from './schema-cache.js';
2
- import { normalizeOptions } from './z-schema-options.js';
3
- // draft-04
4
- import _Draft4Schema from './schemas/draft-04-schema.json' with { type: 'json' };
5
- // draft-06
6
- import _Draft6Schema from './schemas/draft-06-schema.json' with { type: 'json' };
7
- // draft-07
8
- import _Draft7Schema from './schemas/draft-07-schema.json' with { type: 'json' };
9
- // draft2019-09
10
- import _Draft201909MetaApplicator from './schemas/draft-2019-09-meta-applicator.json' with { type: 'json' };
11
- import _Draft201909MetaContent from './schemas/draft-2019-09-meta-content.json' with { type: 'json' };
12
- import _Draft201909MetaCore from './schemas/draft-2019-09-meta-core.json' with { type: 'json' };
13
- import _Draft201909MetaFormat from './schemas/draft-2019-09-meta-format.json' with { type: 'json' };
14
- import _Draft201909MetaMetaData from './schemas/draft-2019-09-meta-meta-data.json' with { type: 'json' };
15
- import _Draft201909MetaValidation from './schemas/draft-2019-09-meta-validation.json' with { type: 'json' };
16
- import _Draft201909Schema from './schemas/draft-2019-09-schema.json' with { type: 'json' };
17
- // draft2020-12
18
- import _Draft202012MetaApplicator from './schemas/draft-2020-12-meta-applicator.json' with { type: 'json' };
19
- import _Draft202012MetaContent from './schemas/draft-2020-12-meta-content.json' with { type: 'json' };
20
- import _Draft202012MetaCore from './schemas/draft-2020-12-meta-core.json' with { type: 'json' };
21
- import _Draft202012MetaFormatAnnotation from './schemas/draft-2020-12-meta-format-annotation.json' with { type: 'json' };
22
- import _Draft202012MetaFormatAssertion from './schemas/draft-2020-12-meta-format-assertion.json' with { type: 'json' };
23
- import _Draft202012MetaMetaData from './schemas/draft-2020-12-meta-meta-data.json' with { type: 'json' };
24
- import _Draft202012MetaUnevaluated from './schemas/draft-2020-12-meta-unevaluated.json' with { type: 'json' };
25
- import _Draft202012MetaValidation from './schemas/draft-2020-12-meta-validation.json' with { type: 'json' };
26
- import _Draft202012Schema from './schemas/draft-2020-12-schema.json' with { type: 'json' };
27
- // draft-04
28
- const Draft4Schema = _Draft4Schema;
29
- // draft-06
30
- const Draft6Schema = _Draft6Schema;
31
- // draft-07
32
- const Draft7Schema = _Draft7Schema;
33
- // draft2019-09
34
- const Draft201909Schema = _Draft201909Schema;
35
- const Draft201909MetaApplicator = _Draft201909MetaApplicator;
36
- const Draft201909MetaContent = _Draft201909MetaContent;
37
- const Draft201909MetaCore = _Draft201909MetaCore;
38
- const Draft201909MetaFormat = _Draft201909MetaFormat;
39
- const Draft201909MetaMetaData = _Draft201909MetaMetaData;
40
- const Draft201909MetaValidation = _Draft201909MetaValidation;
41
- // draft2020-12
42
- const Draft202012Schema = _Draft202012Schema;
43
- const Draft202012MetaApplicator = _Draft202012MetaApplicator;
44
- const Draft202012MetaContent = _Draft202012MetaContent;
45
- const Draft202012MetaCore = _Draft202012MetaCore;
46
- const Draft202012MetaFormatAnnotation = _Draft202012MetaFormatAnnotation;
47
- const Draft202012MetaFormatAssertion = _Draft202012MetaFormatAssertion;
48
- const Draft202012MetaMetaData = _Draft202012MetaMetaData;
49
- const Draft202012MetaUnevaluated = _Draft202012MetaUnevaluated;
50
- const Draft202012MetaValidation = _Draft202012MetaValidation;
51
- const registerRemoteReference = (uri, schema, validationOptions) => {
52
- const preparedSchema = schema;
53
- if (!preparedSchema.id) {
54
- preparedSchema.id = uri;
55
- }
56
- if (validationOptions) {
57
- preparedSchema.__$validationOptions = normalizeOptions(validationOptions);
58
- }
59
- SchemaCache.cacheSchemaByUri(uri, preparedSchema);
60
- };
61
- // draft-04
62
- registerRemoteReference('http://json-schema.org/draft-04/schema', Draft4Schema, { version: 'none' });
63
- // draft-06
64
- registerRemoteReference('http://json-schema.org/draft-06/schema', Draft6Schema, { version: 'none' });
65
- // draft-07
66
- registerRemoteReference('http://json-schema.org/draft-07/schema', Draft7Schema, { version: 'none' });
67
- // draft2019-09
68
- registerRemoteReference('https://json-schema.org/draft/2019-09/schema', Draft201909Schema, { version: 'none' });
69
- registerRemoteReference('https://json-schema.org/draft/2019-09/meta/applicator', Draft201909MetaApplicator, {
70
- version: 'none',
71
- });
72
- registerRemoteReference('https://json-schema.org/draft/2019-09/meta/content', Draft201909MetaContent, {
73
- version: 'none',
74
- });
75
- registerRemoteReference('https://json-schema.org/draft/2019-09/meta/core', Draft201909MetaCore, {
76
- version: 'none',
77
- });
78
- registerRemoteReference('https://json-schema.org/draft/2019-09/meta/format', Draft201909MetaFormat, {
79
- version: 'none',
80
- });
81
- registerRemoteReference('https://json-schema.org/draft/2019-09/meta/meta-data', Draft201909MetaMetaData, {
82
- version: 'none',
83
- });
84
- registerRemoteReference('https://json-schema.org/draft/2019-09/meta/validation', Draft201909MetaValidation, {
85
- version: 'none',
86
- });
87
- // draft2020-12
88
- registerRemoteReference('https://json-schema.org/draft/2020-12/schema', Draft202012Schema, { version: 'none' });
89
- registerRemoteReference('https://json-schema.org/draft/2020-12/meta/applicator', Draft202012MetaApplicator, {
90
- version: 'none',
91
- });
92
- registerRemoteReference('https://json-schema.org/draft/2020-12/meta/content', Draft202012MetaContent, {
93
- version: 'none',
94
- });
95
- registerRemoteReference('https://json-schema.org/draft/2020-12/meta/core', Draft202012MetaCore, {
96
- version: 'none',
97
- });
98
- registerRemoteReference('https://json-schema.org/draft/2020-12/meta/format-annotation', Draft202012MetaFormatAnnotation, { version: 'none' });
99
- registerRemoteReference('https://json-schema.org/draft/2020-12/meta/format-assertion', Draft202012MetaFormatAssertion, {
100
- version: 'none',
101
- });
102
- registerRemoteReference('https://json-schema.org/draft/2020-12/meta/meta-data', Draft202012MetaMetaData, {
103
- version: 'none',
104
- });
105
- registerRemoteReference('https://json-schema.org/draft/2020-12/meta/unevaluated', Draft202012MetaUnevaluated, {
106
- version: 'none',
107
- });
108
- registerRemoteReference('https://json-schema.org/draft/2020-12/meta/validation', Draft202012MetaValidation, {
109
- version: 'none',
110
- });