z-schema 12.2.0 → 12.3.1
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.
- package/README.md +2 -2
- package/bin/z-schema +1 -1
- package/cjs/{index.js → index.cjs} +696 -687
- package/cjs/{index.d.ts → index.d.cts} +47 -26
- package/dist/{errors.d.mts → errors.d.ts} +2 -2
- package/dist/{errors.mjs → errors.js} +1 -2
- package/dist/{format-validators.mjs → format-validators.js} +43 -36
- package/dist/{index.d.mts → index.d.ts} +9 -9
- package/dist/{index.mjs → index.js} +3 -3
- package/dist/{json-schema-versions.d.mts → json-schema-versions.d.ts} +34 -3
- package/dist/{json-schema.d.mts → json-schema.d.ts} +7 -7
- package/dist/{json-schema.mjs → json-schema.js} +7 -12
- package/dist/{json-validation.mjs → json-validation.js} +143 -127
- package/dist/{report.d.mts → report.d.ts} +7 -8
- package/dist/{report.mjs → report.js} +28 -31
- package/dist/{schema-cache.d.mts → schema-cache.d.ts} +4 -4
- package/dist/{schema-cache.mjs → schema-cache.js} +10 -11
- package/dist/{schema-compiler.d.mts → schema-compiler.d.ts} +4 -4
- package/dist/{schema-compiler.mjs → schema-compiler.js} +95 -77
- package/dist/{schema-validator.d.mts → schema-validator.d.ts} +5 -5
- package/dist/{schema-validator.mjs → schema-validator.js} +138 -166
- package/dist/utils/{array.mjs → array.js} +4 -3
- package/dist/utils/{base64.mjs → base64.js} +3 -2
- package/dist/utils/{clone.mjs → clone.js} +18 -20
- package/dist/utils/{hostname.mjs → hostname.js} +19 -22
- package/dist/utils/{json.mjs → json.js} +11 -7
- package/dist/utils/{schema-regex.mjs → schema-regex.js} +5 -5
- package/dist/utils/{time.mjs → time.js} +5 -5
- package/dist/utils/unicode.js +22 -0
- package/dist/utils/{what-is.mjs → what-is.js} +1 -2
- package/dist/validation/{array.mjs → array.js} +18 -20
- package/dist/validation/{combinators.mjs → combinators.js} +16 -16
- package/dist/validation/{numeric.mjs → numeric.js} +11 -11
- package/dist/validation/{object.mjs → object.js} +35 -34
- package/dist/validation/{ref.mjs → ref.js} +4 -4
- package/dist/validation/{shared.mjs → shared.js} +12 -11
- package/dist/validation/{string.mjs → string.js} +32 -32
- package/dist/validation/type.js +34 -0
- package/dist/{z-schema-base.d.mts → z-schema-base.d.ts} +11 -12
- package/dist/{z-schema-base.mjs → z-schema-base.js} +45 -40
- package/dist/{z-schema-options.d.mts → z-schema-options.d.ts} +3 -3
- package/dist/{z-schema-options.mjs → z-schema-options.js} +4 -4
- package/dist/{z-schema-reader.d.mts → z-schema-reader.d.ts} +1 -1
- package/dist/{z-schema-versions.mjs → z-schema-versions.js} +21 -21
- package/dist/{z-schema.d.mts → z-schema.d.ts} +5 -13
- package/dist/{z-schema.mjs → z-schema.js} +37 -47
- package/package.json +22 -23
- package/src/errors.ts +1 -2
- package/src/format-validators.ts +139 -59
- package/src/json-schema-versions.ts +56 -2
- package/src/json-schema.ts +10 -9
- package/src/json-validation.ts +189 -146
- package/src/report.ts +37 -49
- package/src/schema-cache.ts +13 -13
- package/src/schema-compiler.ts +170 -117
- package/src/schema-validator.ts +239 -238
- package/src/utils/array.ts +9 -6
- package/src/utils/base64.ts +13 -2
- package/src/utils/clone.ts +28 -30
- package/src/utils/date.ts +6 -3
- package/src/utils/hostname.ts +27 -27
- package/src/utils/json.ts +16 -9
- package/src/utils/properties.ts +2 -2
- package/src/utils/schema-regex.ts +4 -4
- package/src/utils/time.ts +5 -5
- package/src/utils/unicode.ts +12 -5
- package/src/utils/what-is.ts +1 -5
- package/src/validation/array.ts +24 -22
- package/src/validation/combinators.ts +14 -14
- package/src/validation/numeric.ts +14 -28
- package/src/validation/object.ts +32 -36
- package/src/validation/ref.ts +5 -6
- package/src/validation/shared.ts +22 -21
- package/src/validation/string.ts +29 -39
- package/src/validation/type.ts +17 -17
- package/src/z-schema-base.ts +49 -38
- package/src/z-schema-options.ts +4 -3
- package/src/z-schema.ts +35 -45
- package/umd/ZSchema.js +711 -695
- package/umd/ZSchema.min.js +2 -2
- package/umd/package.json +3 -0
- package/dist/utils/unicode.mjs +0 -12
- package/dist/validation/type.mjs +0 -32
- /package/dist/{format-validators.d.mts → format-validators.d.ts} +0 -0
- /package/dist/{json-schema-versions.mjs → json-schema-versions.js} +0 -0
- /package/dist/schemas/{draft-04-schema.mjs → draft-04-schema.js} +0 -0
- /package/dist/schemas/{draft-06-schema.mjs → draft-06-schema.js} +0 -0
- /package/dist/schemas/{draft-07-schema.mjs → draft-07-schema.js} +0 -0
- /package/dist/schemas/{draft-2019-09-meta-applicator.mjs → draft-2019-09-meta-applicator.js} +0 -0
- /package/dist/schemas/{draft-2019-09-meta-content.mjs → draft-2019-09-meta-content.js} +0 -0
- /package/dist/schemas/{draft-2019-09-meta-core.mjs → draft-2019-09-meta-core.js} +0 -0
- /package/dist/schemas/{draft-2019-09-meta-format.mjs → draft-2019-09-meta-format.js} +0 -0
- /package/dist/schemas/{draft-2019-09-meta-meta-data.mjs → draft-2019-09-meta-meta-data.js} +0 -0
- /package/dist/schemas/{draft-2019-09-meta-validation.mjs → draft-2019-09-meta-validation.js} +0 -0
- /package/dist/schemas/{draft-2019-09-schema.mjs → draft-2019-09-schema.js} +0 -0
- /package/dist/schemas/{draft-2020-12-meta-applicator.mjs → draft-2020-12-meta-applicator.js} +0 -0
- /package/dist/schemas/{draft-2020-12-meta-content.mjs → draft-2020-12-meta-content.js} +0 -0
- /package/dist/schemas/{draft-2020-12-meta-core.mjs → draft-2020-12-meta-core.js} +0 -0
- /package/dist/schemas/{draft-2020-12-meta-format-annotation.mjs → draft-2020-12-meta-format-annotation.js} +0 -0
- /package/dist/schemas/{draft-2020-12-meta-format-assertion.mjs → draft-2020-12-meta-format-assertion.js} +0 -0
- /package/dist/schemas/{draft-2020-12-meta-meta-data.mjs → draft-2020-12-meta-meta-data.js} +0 -0
- /package/dist/schemas/{draft-2020-12-meta-unevaluated.mjs → draft-2020-12-meta-unevaluated.js} +0 -0
- /package/dist/schemas/{draft-2020-12-meta-validation.mjs → draft-2020-12-meta-validation.js} +0 -0
- /package/dist/schemas/{draft-2020-12-schema.mjs → draft-2020-12-schema.js} +0 -0
- /package/dist/utils/{constants.mjs → constants.js} +0 -0
- /package/dist/utils/{date.mjs → date.js} +0 -0
- /package/dist/utils/{properties.mjs → properties.js} +0 -0
- /package/dist/utils/{symbols.mjs → symbols.js} +0 -0
- /package/dist/utils/{uri.mjs → uri.js} +0 -0
- /package/dist/{z-schema-reader.mjs → z-schema-reader.js} +0 -0
package/umd/ZSchema.js
CHANGED
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
10
10
|
var __getProtoOf = Object.getPrototypeOf;
|
|
11
11
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
12
|
-
var __commonJSMin = (cb, mod) => () => (mod || cb((mod = { exports: {} }).exports, mod), mod.exports);
|
|
12
|
+
var __commonJSMin = (cb, mod) => () => (mod || (cb((mod = { exports: {} }).exports, mod), cb = null), mod.exports);
|
|
13
13
|
var __copyProps = (to, from, except, desc) => {
|
|
14
14
|
if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
15
15
|
key = keys[i];
|
|
@@ -25,17 +25,6 @@
|
|
|
25
25
|
enumerable: true
|
|
26
26
|
}) : target, mod));
|
|
27
27
|
//#endregion
|
|
28
|
-
//#region src/utils/uri.ts
|
|
29
|
-
const getQueryPath = (uri) => {
|
|
30
|
-
const io = uri.indexOf("#");
|
|
31
|
-
return io === -1 ? void 0 : uri.slice(io + 1);
|
|
32
|
-
};
|
|
33
|
-
const getRemotePath = (uri) => {
|
|
34
|
-
const io = uri.indexOf("#");
|
|
35
|
-
return io === -1 ? uri : uri.slice(0, io);
|
|
36
|
-
};
|
|
37
|
-
const isAbsoluteUri = (uri) => /^[a-zA-Z][a-zA-Z\d+.-]*:/.test(uri);
|
|
38
|
-
//#endregion
|
|
39
28
|
//#region src/utils/constants.ts
|
|
40
29
|
/**
|
|
41
30
|
* Maximum allowed value for {@link ZSchemaOptions.asyncTimeout} in milliseconds.
|
|
@@ -51,6 +40,17 @@
|
|
|
51
40
|
*/
|
|
52
41
|
const MAX_SCHEMA_REGEX_LENGTH = 1e4;
|
|
53
42
|
//#endregion
|
|
43
|
+
//#region src/utils/uri.ts
|
|
44
|
+
const getQueryPath = (uri) => {
|
|
45
|
+
const io = uri.indexOf("#");
|
|
46
|
+
return io === -1 ? void 0 : uri.slice(io + 1);
|
|
47
|
+
};
|
|
48
|
+
const getRemotePath = (uri) => {
|
|
49
|
+
const io = uri.indexOf("#");
|
|
50
|
+
return io === -1 ? uri : uri.slice(0, io);
|
|
51
|
+
};
|
|
52
|
+
const isAbsoluteUri = (uri) => /^[a-zA-Z][a-zA-Z\d+.-]*:/.test(uri);
|
|
53
|
+
//#endregion
|
|
54
54
|
//#region src/utils/what-is.ts
|
|
55
55
|
const whatIs = (what) => {
|
|
56
56
|
if (typeof what === "object") {
|
|
@@ -59,8 +59,7 @@
|
|
|
59
59
|
return "object";
|
|
60
60
|
}
|
|
61
61
|
if (typeof what === "number") {
|
|
62
|
-
if (Number.isFinite(what))
|
|
63
|
-
else return "number";
|
|
62
|
+
if (Number.isFinite(what)) return what % 1 === 0 ? "integer" : "number";
|
|
64
63
|
if (Number.isNaN(what)) return "not-a-number";
|
|
65
64
|
return "unknown-number";
|
|
66
65
|
}
|
|
@@ -72,18 +71,12 @@
|
|
|
72
71
|
function isInteger(value) {
|
|
73
72
|
return typeof value === "number" && Number.isFinite(value) && value % 1 === 0;
|
|
74
73
|
}
|
|
75
|
-
|
|
76
|
-
//#region src/json-schema.ts
|
|
77
|
-
/**
|
|
78
|
-
* Keywords whose values are not JSON Schema sub-schemas and must not be
|
|
79
|
-
* traversed during schema walking (id collection, reference collection, etc.).
|
|
80
|
-
*/
|
|
81
|
-
const NON_SCHEMA_KEYWORDS = [
|
|
74
|
+
const NON_SCHEMA_KEYWORDS_SET = new Set([
|
|
82
75
|
"enum",
|
|
83
76
|
"const",
|
|
84
77
|
"default",
|
|
85
78
|
"examples"
|
|
86
|
-
];
|
|
79
|
+
]);
|
|
87
80
|
/** Returns true if the key is an internal z-schema property (prefixed with `__$`). */
|
|
88
81
|
const isInternalKey = (key) => key.startsWith("__$");
|
|
89
82
|
const getId = (schema) => {
|
|
@@ -104,7 +97,7 @@
|
|
|
104
97
|
} catch {}
|
|
105
98
|
}
|
|
106
99
|
if (!targetBaseUri || nextBaseUri === targetBaseUri) {
|
|
107
|
-
if (schemaId && (schemaId === id || schemaId
|
|
100
|
+
if (schemaId && (schemaId === id || schemaId.startsWith("#") && schemaId.slice(1) === id)) return schema;
|
|
108
101
|
if (schema.$anchor === id || schema.$dynamicAnchor === id) return schema;
|
|
109
102
|
}
|
|
110
103
|
let result;
|
|
@@ -116,7 +109,7 @@
|
|
|
116
109
|
const keys = Object.keys(schema);
|
|
117
110
|
for (let i = keys.length - 1; i >= 0; i--) {
|
|
118
111
|
const k = keys[i];
|
|
119
|
-
if (isInternalKey(k) ||
|
|
112
|
+
if (isInternalKey(k) || NON_SCHEMA_KEYWORDS_SET.has(k)) continue;
|
|
120
113
|
result = findId(schema[k], id, targetBaseUri, nextBaseUri, maxDepth, _depth + 1);
|
|
121
114
|
if (result) return result;
|
|
122
115
|
}
|
|
@@ -177,11 +170,10 @@
|
|
|
177
170
|
MAX_RECURSION_DEPTH_EXCEEDED: "Maximum recursion depth ({0}) exceeded. If your schema or data is deeply nested and valid, increase the maxRecursionDepth option."
|
|
178
171
|
};
|
|
179
172
|
var ValidateError = class extends Error {
|
|
180
|
-
name;
|
|
173
|
+
name = "ValidateError";
|
|
181
174
|
details;
|
|
182
175
|
constructor(message, details) {
|
|
183
176
|
super(message);
|
|
184
|
-
this.name = "z-schema validation error";
|
|
185
177
|
this.details = details;
|
|
186
178
|
}
|
|
187
179
|
};
|
|
@@ -202,49 +194,48 @@
|
|
|
202
194
|
//#region src/utils/clone.ts
|
|
203
195
|
const shallowClone = (src) => {
|
|
204
196
|
if (src == null || typeof src !== "object") return src;
|
|
205
|
-
let res;
|
|
206
197
|
if (Array.isArray(src)) {
|
|
207
|
-
res = [];
|
|
198
|
+
const res = [];
|
|
208
199
|
for (let i = 0; i < src.length; i++) res[i] = src[i];
|
|
209
|
-
|
|
210
|
-
res = {};
|
|
211
|
-
const keys = Object.keys(src).sort();
|
|
212
|
-
for (const key of keys) copyProp(src, res, key);
|
|
200
|
+
return res;
|
|
213
201
|
}
|
|
202
|
+
const res = {};
|
|
203
|
+
const keys = Object.keys(src).sort();
|
|
204
|
+
for (let i = 0; i < keys.length; i++) copyProp(src, res, keys[i]);
|
|
214
205
|
return res;
|
|
215
206
|
};
|
|
216
207
|
const deepClone = (src, maxDepth = 100) => {
|
|
217
208
|
let vidx = 0;
|
|
218
209
|
const visited = /* @__PURE__ */ new Map();
|
|
219
210
|
const cloned = [];
|
|
220
|
-
const cloneDeepInner = (
|
|
221
|
-
if (typeof
|
|
211
|
+
const cloneDeepInner = (node, _depth) => {
|
|
212
|
+
if (typeof node !== "object" || node === null) return node;
|
|
222
213
|
if (_depth >= maxDepth) throw new Error(`Maximum recursion depth (${maxDepth}) exceeded in deepClone. If your schema or data is deeply nested and valid, increase the maxRecursionDepth option.`);
|
|
223
|
-
|
|
224
|
-
const cidx = visited.get(src);
|
|
214
|
+
const cidx = visited.get(node);
|
|
225
215
|
if (cidx !== void 0) return cloned[cidx];
|
|
226
|
-
visited.set(
|
|
227
|
-
if (Array.isArray(
|
|
228
|
-
res = [];
|
|
216
|
+
visited.set(node, vidx++);
|
|
217
|
+
if (Array.isArray(node)) {
|
|
218
|
+
const res = [];
|
|
229
219
|
cloned.push(res);
|
|
230
|
-
for (let i = 0; i <
|
|
231
|
-
|
|
232
|
-
res = {};
|
|
233
|
-
cloned.push(res);
|
|
234
|
-
const keys = Object.keys(src).sort();
|
|
235
|
-
for (const key of keys) copyProp(src, res, key, (v) => cloneDeepInner(v, _depth + 1));
|
|
220
|
+
for (let i = 0; i < node.length; i++) res[i] = cloneDeepInner(node[i], _depth + 1);
|
|
221
|
+
return res;
|
|
236
222
|
}
|
|
223
|
+
const res = {};
|
|
224
|
+
cloned.push(res);
|
|
225
|
+
const keys = Object.keys(node).sort();
|
|
226
|
+
for (let i = 0; i < keys.length; i++) copyProp(node, res, keys[i], (v) => cloneDeepInner(v, _depth + 1));
|
|
237
227
|
return res;
|
|
238
228
|
};
|
|
239
229
|
return cloneDeepInner(src, 0);
|
|
240
230
|
};
|
|
241
231
|
//#endregion
|
|
242
232
|
//#region src/utils/json.ts
|
|
233
|
+
const sortedKeys = (obj) => Object.keys(obj).sort();
|
|
243
234
|
const areEqual = (json1, json2, options, _depth = 0) => {
|
|
244
235
|
const caseInsensitiveComparison = options?.caseInsensitiveComparison || false;
|
|
245
236
|
const maxDepth = options?.maxDepth ?? 100;
|
|
246
237
|
if (json1 === json2) return true;
|
|
247
|
-
if (caseInsensitiveComparison
|
|
238
|
+
if (caseInsensitiveComparison && typeof json1 === "string" && typeof json2 === "string" && json1.toUpperCase() === json2.toUpperCase()) return true;
|
|
248
239
|
if (_depth >= maxDepth) throw new Error(`Maximum recursion depth (${maxDepth}) exceeded in areEqual. If your data is deeply nested and valid, increase the maxRecursionDepth option.`);
|
|
249
240
|
let i, len;
|
|
250
241
|
if (Array.isArray(json1) && Array.isArray(json2)) {
|
|
@@ -262,13 +253,16 @@
|
|
|
262
253
|
}
|
|
263
254
|
return false;
|
|
264
255
|
};
|
|
265
|
-
const decodeJSONPointer = (str) =>
|
|
266
|
-
return decodeURIComponent(str).replace(/~[0-1]/g, (x) => x === "~1" ? "/" : "~");
|
|
267
|
-
};
|
|
268
|
-
const sortedKeys = (obj) => Object.keys(obj).sort();
|
|
256
|
+
const decodeJSONPointer = (str) => decodeURIComponent(str).replaceAll(/~[0-1]/g, (x) => x === "~1" ? "/" : "~");
|
|
269
257
|
const get = (obj, path) => {
|
|
270
258
|
if (typeof path === "string") path = path.split(".");
|
|
271
|
-
|
|
259
|
+
let acc = obj;
|
|
260
|
+
for (let i = 0; i < path.length; i++) {
|
|
261
|
+
const key = path[i];
|
|
262
|
+
if (acc && acc[key] !== void 0) acc = acc[key];
|
|
263
|
+
else return;
|
|
264
|
+
}
|
|
265
|
+
return acc;
|
|
272
266
|
};
|
|
273
267
|
//#endregion
|
|
274
268
|
//#region src/utils/symbols.ts
|
|
@@ -298,8 +292,8 @@
|
|
|
298
292
|
if (parentOrOptions instanceof Report) {
|
|
299
293
|
this.reportOptions = reportOptionsOrValidate || {};
|
|
300
294
|
this.validateOptions = validateOptions || parentOrOptions.validateOptions;
|
|
301
|
-
this.__$recursiveAnchorStack =
|
|
302
|
-
this.__$dynamicScopeStack =
|
|
295
|
+
this.__$recursiveAnchorStack = parentOrOptions.__$recursiveAnchorStack.slice();
|
|
296
|
+
this.__$dynamicScopeStack = parentOrOptions.__$dynamicScopeStack.slice();
|
|
303
297
|
this.__validationResultCache = parentOrOptions.__validationResultCache;
|
|
304
298
|
} else {
|
|
305
299
|
this.reportOptions = {};
|
|
@@ -382,30 +376,24 @@
|
|
|
382
376
|
setTimeout(checkTimeout, ASYNC_TIMEOUT_POLL_MS);
|
|
383
377
|
}
|
|
384
378
|
getPath(returnPathAsString) {
|
|
385
|
-
|
|
386
|
-
if (
|
|
387
|
-
path = path.concat(this.path);
|
|
388
|
-
if (returnPathAsString !== true) return "#/" + path.map(function(segment) {
|
|
379
|
+
const path = this.parentReport ? this.parentReport.path.concat(this.path) : this.path.slice();
|
|
380
|
+
if (returnPathAsString !== true) return `#/${path.map((segment) => {
|
|
389
381
|
segment = segment.toString();
|
|
390
|
-
if (isAbsoluteUri(segment)) return
|
|
391
|
-
return segment.
|
|
392
|
-
}).join("/")
|
|
382
|
+
if (isAbsoluteUri(segment)) return `uri(${segment})`;
|
|
383
|
+
return segment.replaceAll("~", "~0").replaceAll("/", "~1");
|
|
384
|
+
}).join("/")}`;
|
|
393
385
|
return path;
|
|
394
386
|
}
|
|
395
387
|
getSchemaPath() {
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
schemaPath = schemaPath.concat(this.schemaPath);
|
|
399
|
-
return schemaPath;
|
|
388
|
+
if (this.parentReport) return this.parentReport.schemaPath.concat(this.schemaPath);
|
|
389
|
+
return this.schemaPath.slice();
|
|
400
390
|
}
|
|
401
391
|
getSchemaId() {
|
|
402
392
|
if (!this.rootSchema) return;
|
|
403
|
-
|
|
404
|
-
if (this.parentReport) path = path.concat(this.parentReport.path);
|
|
405
|
-
path = path.concat(this.path);
|
|
393
|
+
const path = this.parentReport ? this.parentReport.path.concat(this.path) : this.path.slice();
|
|
406
394
|
while (path.length > 0) {
|
|
407
395
|
const obj = get(this.rootSchema, path);
|
|
408
|
-
if (obj && obj.id) return obj.id;
|
|
396
|
+
if (isObject(obj) && typeof obj.id === "string") return obj.id;
|
|
409
397
|
path.pop();
|
|
410
398
|
}
|
|
411
399
|
return this.rootSchema.id;
|
|
@@ -428,11 +416,11 @@
|
|
|
428
416
|
}
|
|
429
417
|
addCustomError(errorCode, errorMessage, params, subReports, schema, keyword) {
|
|
430
418
|
if (typeof this.reportOptions.maxErrors === "number" && this.errors.length >= this.reportOptions.maxErrors) return;
|
|
431
|
-
if (!errorMessage) throw new Error(
|
|
432
|
-
params
|
|
419
|
+
if (!errorMessage) throw new Error(`No errorMessage known for code ${errorCode}`);
|
|
420
|
+
params ||= [];
|
|
433
421
|
for (let idx = 0; idx < params.length; idx++) {
|
|
434
422
|
const param = params[idx] === null || isObject(params[idx]) ? JSON.stringify(params[idx]) : params[idx];
|
|
435
|
-
errorMessage = errorMessage.replace(
|
|
423
|
+
errorMessage = errorMessage.replace(`{${idx}}`, param.toString());
|
|
436
424
|
}
|
|
437
425
|
const err = {
|
|
438
426
|
code: errorCode,
|
|
@@ -441,10 +429,10 @@
|
|
|
441
429
|
path: this.getPath(this.options.reportPathAsArray),
|
|
442
430
|
schemaPath: this.getSchemaPath(),
|
|
443
431
|
schemaId: this.getSchemaId(),
|
|
444
|
-
keyword
|
|
432
|
+
keyword,
|
|
433
|
+
[schemaSymbol]: schema,
|
|
434
|
+
[jsonSymbol]: this.getJson()
|
|
445
435
|
};
|
|
446
|
-
err[schemaSymbol] = schema;
|
|
447
|
-
err[jsonSymbol] = this.getJson();
|
|
448
436
|
if (schema && typeof schema === "string") err.description = schema;
|
|
449
437
|
else if (schema && typeof schema === "object") {
|
|
450
438
|
if (schema.title) err.title = schema.title;
|
|
@@ -453,7 +441,10 @@
|
|
|
453
441
|
if (subReports != null) {
|
|
454
442
|
if (!Array.isArray(subReports)) subReports = [subReports];
|
|
455
443
|
err.inner = [];
|
|
456
|
-
for (
|
|
444
|
+
for (let si = 0; si < subReports.length; si++) {
|
|
445
|
+
const errs = subReports[si].errors;
|
|
446
|
+
for (let ei = 0; ei < errs.length; ei++) err.inner.push(errs[ei]);
|
|
447
|
+
}
|
|
457
448
|
if (err.inner.length === 0) err.inner = void 0;
|
|
458
449
|
}
|
|
459
450
|
if (Array.isArray(this.validateOptions.excludeErrors) && this.validateOptions.excludeErrors.includes(errorCode)) return;
|
|
@@ -503,7 +494,7 @@
|
|
|
503
494
|
let normalized;
|
|
504
495
|
if (typeof options === "object") {
|
|
505
496
|
let keys = Object.keys(options);
|
|
506
|
-
for (const key of keys) if (defaultOptions[key] === void 0) throw new Error(
|
|
497
|
+
for (const key of keys) if (defaultOptions[key] === void 0) throw new Error(`Unexpected option passed to constructor: ${key}`);
|
|
507
498
|
keys = Object.keys(defaultOptions);
|
|
508
499
|
for (const key of keys) if (options[key] === void 0) options[key] = shallowClone(defaultOptions[key]);
|
|
509
500
|
normalized = options;
|
|
@@ -531,7 +522,7 @@
|
|
|
531
522
|
}
|
|
532
523
|
const getEffectiveId = (schema) => {
|
|
533
524
|
let id = getId(schema);
|
|
534
|
-
if ((!id || !isAbsoluteUri(id)) && typeof schema.id === "string" && isAbsoluteUri(schema.id)) id = schema
|
|
525
|
+
if ((!id || !isAbsoluteUri(id)) && typeof schema.id === "string" && isAbsoluteUri(schema.id)) ({id} = schema);
|
|
535
526
|
return id;
|
|
536
527
|
};
|
|
537
528
|
/**
|
|
@@ -540,9 +531,7 @@
|
|
|
540
531
|
* the instance `validator.setRemoteReference()` (instance cache).
|
|
541
532
|
*/
|
|
542
533
|
function prepareRemoteSchema(schema, uri, validationOptions, maxCloneDepth) {
|
|
543
|
-
|
|
544
|
-
if (typeof schema === "string") _schema = JSON.parse(schema);
|
|
545
|
-
else _schema = deepClone(schema, maxCloneDepth);
|
|
534
|
+
const _schema = typeof schema === "string" ? JSON.parse(schema) : deepClone(schema, maxCloneDepth);
|
|
546
535
|
if (!_schema.id) _schema.id = uri;
|
|
547
536
|
if (validationOptions) _schema.__$validationOptions = normalizeOptions(validationOptions);
|
|
548
537
|
return _schema;
|
|
@@ -550,6 +539,7 @@
|
|
|
550
539
|
var SchemaCache = class SchemaCache {
|
|
551
540
|
static global_cache = Object.create(null);
|
|
552
541
|
cache = Object.create(null);
|
|
542
|
+
validator;
|
|
553
543
|
constructor(validator) {
|
|
554
544
|
this.validator = validator;
|
|
555
545
|
}
|
|
@@ -626,7 +616,7 @@
|
|
|
626
616
|
usesAncestorReport = true;
|
|
627
617
|
} else {
|
|
628
618
|
remoteReport = new Report(report);
|
|
629
|
-
const noCache = result.id && isAbsoluteUri(result.id)
|
|
619
|
+
const noCache = !(result.id && isAbsoluteUri(result.id));
|
|
630
620
|
if (this.validator.sc.compileSchema(remoteReport, result, { noCache })) {
|
|
631
621
|
const savedOptions = this.validator.options;
|
|
632
622
|
try {
|
|
@@ -1966,8 +1956,8 @@
|
|
|
1966
1956
|
module.exports.default = exports.default;
|
|
1967
1957
|
}));
|
|
1968
1958
|
//#endregion
|
|
1969
|
-
//#region
|
|
1970
|
-
var
|
|
1959
|
+
//#region node_modules/validator/lib/isURL.js
|
|
1960
|
+
var require_isURL = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
1971
1961
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1972
1962
|
exports.default = isURL;
|
|
1973
1963
|
var _assertString = _interopRequireDefault(require_assertString());
|
|
@@ -2132,9 +2122,12 @@
|
|
|
2132
2122
|
}
|
|
2133
2123
|
module.exports = exports.default;
|
|
2134
2124
|
module.exports.default = exports.default;
|
|
2135
|
-
}))
|
|
2136
|
-
|
|
2125
|
+
}));
|
|
2126
|
+
//#endregion
|
|
2127
|
+
//#region src/utils/date.ts
|
|
2137
2128
|
var import_isIP = /* @__PURE__ */ __toESM(require_isIP(), 1);
|
|
2129
|
+
var import_isEmail = /* @__PURE__ */ __toESM(require_isEmail(), 1);
|
|
2130
|
+
var import_isURL = /* @__PURE__ */ __toESM(require_isURL(), 1);
|
|
2138
2131
|
const isLeapYear = (year) => year % 4 === 0 && (year % 100 !== 0 || year % 400 === 0);
|
|
2139
2132
|
const getDaysInMonth = (year, month) => {
|
|
2140
2133
|
switch (month) {
|
|
@@ -2300,8 +2293,8 @@
|
|
|
2300
2293
|
let k = 0;
|
|
2301
2294
|
delta = firstTime ? floor(delta / damp) : delta >> 1;
|
|
2302
2295
|
delta += floor(delta / numPoints);
|
|
2303
|
-
for (; delta >
|
|
2304
|
-
return floor(k +
|
|
2296
|
+
for (; delta > 455; k += base) delta = floor(delta / baseMinusTMin);
|
|
2297
|
+
return floor(k + 36 * delta / (delta + skew));
|
|
2305
2298
|
};
|
|
2306
2299
|
/**
|
|
2307
2300
|
* Converts a Punycode string of ASCII-only symbols to a string of Unicode
|
|
@@ -2426,7 +2419,19 @@
|
|
|
2426
2419
|
});
|
|
2427
2420
|
};
|
|
2428
2421
|
module.exports = {
|
|
2422
|
+
/**
|
|
2423
|
+
* A string representing the current Punycode.js version number.
|
|
2424
|
+
* @memberOf punycode
|
|
2425
|
+
* @type String
|
|
2426
|
+
*/
|
|
2429
2427
|
"version": "2.3.1",
|
|
2428
|
+
/**
|
|
2429
|
+
* An object of methods to convert from JavaScript's internal character
|
|
2430
|
+
* representation (UCS-2) to Unicode code points, and back.
|
|
2431
|
+
* @see <https://mathiasbynens.be/notes/javascript-encoding>
|
|
2432
|
+
* @memberOf punycode
|
|
2433
|
+
* @type Object
|
|
2434
|
+
*/
|
|
2430
2435
|
"ucs2": {
|
|
2431
2436
|
"decode": ucs2decode,
|
|
2432
2437
|
"encode": ucs2encode
|
|
@@ -2437,13 +2442,16 @@
|
|
|
2437
2442
|
"toUnicode": toUnicode
|
|
2438
2443
|
};
|
|
2439
2444
|
})))(), 1);
|
|
2440
|
-
const IDN_SEPARATOR_REGEX = /[\u3002\
|
|
2441
|
-
const IDN_SEPARATOR_TEST_REGEX = /[\u3002\
|
|
2445
|
+
const IDN_SEPARATOR_REGEX = /[\u3002\uFF0E\uFF61]/g;
|
|
2446
|
+
const IDN_SEPARATOR_TEST_REGEX = /[\u3002\uFF0E\uFF61]/;
|
|
2442
2447
|
const splitHostnameLabels = (hostname) => {
|
|
2443
2448
|
if (hostname.length === 0 || hostname.length > 255) return null;
|
|
2444
2449
|
if (hostname.startsWith(".") || hostname.endsWith(".")) return null;
|
|
2445
2450
|
const labels = hostname.split(".");
|
|
2446
|
-
|
|
2451
|
+
for (let i = 0; i < labels.length; i++) {
|
|
2452
|
+
const len = labels[i].length;
|
|
2453
|
+
if (len === 0 || len > 63) return null;
|
|
2454
|
+
}
|
|
2447
2455
|
return labels;
|
|
2448
2456
|
};
|
|
2449
2457
|
const isAsciiHostnameLabel = (label) => /^[a-z0-9](?:[a-z0-9-]*[a-z0-9])?$/i.test(label);
|
|
@@ -2454,7 +2462,7 @@
|
|
|
2454
2462
|
if (!/^xn--/i.test(label)) return label;
|
|
2455
2463
|
try {
|
|
2456
2464
|
return import_punycode.default.toUnicode(label.toLowerCase());
|
|
2457
|
-
} catch
|
|
2465
|
+
} catch {
|
|
2458
2466
|
return null;
|
|
2459
2467
|
}
|
|
2460
2468
|
};
|
|
@@ -2462,34 +2470,27 @@
|
|
|
2462
2470
|
if (label.startsWith("-") || label.endsWith("-")) return false;
|
|
2463
2471
|
if (label.length >= 4 && label[2] === "-" && label[3] === "-" && !/^xn--/i.test(label)) return false;
|
|
2464
2472
|
if (/^\p{M}/u.test(label)) return false;
|
|
2465
|
-
if (/[\
|
|
2473
|
+
if (/[\u302E\u302F\u0640\u07FA]/u.test(label)) return false;
|
|
2466
2474
|
for (let idx = 0; idx < label.length; idx++) {
|
|
2467
2475
|
const char = label[idx];
|
|
2468
|
-
if (char === "·")
|
|
2469
|
-
|
|
2470
|
-
|
|
2471
|
-
if (char === "
|
|
2472
|
-
if (idx === label.length - 1 || !isGreek(label[idx + 1])) return false;
|
|
2473
|
-
}
|
|
2474
|
-
if (char === "׳" || char === "״") {
|
|
2475
|
-
if (idx === 0 || !isHebrew(label[idx - 1])) return false;
|
|
2476
|
-
}
|
|
2477
|
-
if (char === "") {
|
|
2478
|
-
if (idx === 0 || label[idx - 1] !== "्") return false;
|
|
2479
|
-
}
|
|
2476
|
+
if (char === "·" && (idx === 0 || idx === label.length - 1 || label[idx - 1] !== "l" || label[idx + 1] !== "l")) return false;
|
|
2477
|
+
if (char === "͵" && (idx === label.length - 1 || !isGreek(label[idx + 1]))) return false;
|
|
2478
|
+
if ((char === "׳" || char === "״") && (idx === 0 || !isHebrew(label[idx - 1]))) return false;
|
|
2479
|
+
if (char === "" && (idx === 0 || label[idx - 1] !== "्")) return false;
|
|
2480
2480
|
}
|
|
2481
|
-
if (label.includes("・") && !hasCjkKanaOrHan(label.
|
|
2481
|
+
if (label.includes("・") && !hasCjkKanaOrHan(label.replaceAll("・", ""))) return false;
|
|
2482
2482
|
const hasArabicIndic = /[\u0660-\u0669]/.test(label);
|
|
2483
|
-
const hasExtendedArabicIndic = /[\
|
|
2483
|
+
const hasExtendedArabicIndic = /[\u06F0-\u06F9]/.test(label);
|
|
2484
2484
|
if (hasArabicIndic && hasExtendedArabicIndic) return false;
|
|
2485
2485
|
return true;
|
|
2486
2486
|
};
|
|
2487
2487
|
const isValidHostname = (hostname) => {
|
|
2488
|
-
if (IDN_SEPARATOR_TEST_REGEX.test(hostname) || /[^\
|
|
2488
|
+
if (IDN_SEPARATOR_TEST_REGEX.test(hostname) || /[^\u0000-\u007F]/.test(hostname)) return false;
|
|
2489
2489
|
if (import_isIP.default.default(hostname, 4)) return false;
|
|
2490
2490
|
const labels = splitHostnameLabels(hostname);
|
|
2491
2491
|
if (labels === null) return false;
|
|
2492
|
-
for (
|
|
2492
|
+
for (let i = 0; i < labels.length; i++) {
|
|
2493
|
+
const label = labels[i];
|
|
2493
2494
|
if (!isAsciiHostnameLabel(label)) return false;
|
|
2494
2495
|
if (/^xn--/i.test(label)) {
|
|
2495
2496
|
const unicodeLabel = toUnicodeLabel(label);
|
|
@@ -2501,7 +2502,8 @@
|
|
|
2501
2502
|
const isValidIdnHostname = (hostname) => {
|
|
2502
2503
|
const labels = splitHostnameLabels(hostname.replace(IDN_SEPARATOR_REGEX, "."));
|
|
2503
2504
|
if (labels === null) return false;
|
|
2504
|
-
for (
|
|
2505
|
+
for (let i = 0; i < labels.length; i++) {
|
|
2506
|
+
const label = labels[i];
|
|
2505
2507
|
const unicodeLabel = toUnicodeLabel(label);
|
|
2506
2508
|
if (unicodeLabel === null || !isValidIdnUnicodeLabel(unicodeLabel)) return false;
|
|
2507
2509
|
}
|
|
@@ -2522,9 +2524,9 @@
|
|
|
2522
2524
|
const parseRfc3339Time = (time) => {
|
|
2523
2525
|
const matches = RFC3339_TIME_REGEX.exec(time);
|
|
2524
2526
|
if (matches === null) return null;
|
|
2525
|
-
const hour = parseInt(matches[1], 10);
|
|
2526
|
-
const minute = parseInt(matches[2], 10);
|
|
2527
|
-
const second = parseInt(matches[3], 10);
|
|
2527
|
+
const hour = Number.parseInt(matches[1], 10);
|
|
2528
|
+
const minute = Number.parseInt(matches[2], 10);
|
|
2529
|
+
const second = Number.parseInt(matches[3], 10);
|
|
2528
2530
|
if (hour > 23 || minute > 59 || second > 60) return null;
|
|
2529
2531
|
let utcHour = hour;
|
|
2530
2532
|
let utcMinute = minute;
|
|
@@ -2532,8 +2534,8 @@
|
|
|
2532
2534
|
const offsetMatches = /^([+-])([0-9]{2}):([0-9]{2})$/.exec(matches[5]);
|
|
2533
2535
|
if (offsetMatches === null) return null;
|
|
2534
2536
|
const offsetSign = offsetMatches[1];
|
|
2535
|
-
const offsetHour = parseInt(offsetMatches[2], 10);
|
|
2536
|
-
const offsetMinute = parseInt(offsetMatches[3], 10);
|
|
2537
|
+
const offsetHour = Number.parseInt(offsetMatches[2], 10);
|
|
2538
|
+
const offsetMinute = Number.parseInt(offsetMatches[3], 10);
|
|
2537
2539
|
if (offsetHour > 23 || offsetMinute > 59) return null;
|
|
2538
2540
|
const utc = toUtcTime(hour, minute, offsetSign, offsetHour, offsetMinute);
|
|
2539
2541
|
utcHour = utc.hour;
|
|
@@ -2554,17 +2556,18 @@
|
|
|
2554
2556
|
if (typeof date !== "string") return true;
|
|
2555
2557
|
const matches = /^([0-9]{4})-([0-9]{2})-([0-9]{2})$/.exec(date);
|
|
2556
2558
|
if (matches === null) return false;
|
|
2557
|
-
return isValidRfc3339Date(parseInt(matches[1], 10), parseInt(matches[2], 10), parseInt(matches[3], 10));
|
|
2559
|
+
return isValidRfc3339Date(Number.parseInt(matches[1], 10), Number.parseInt(matches[2], 10), Number.parseInt(matches[3], 10));
|
|
2558
2560
|
};
|
|
2559
2561
|
const dateTimeValidator = (dateTime) => {
|
|
2560
2562
|
if (typeof dateTime !== "string") return true;
|
|
2561
|
-
|
|
2562
|
-
if (
|
|
2563
|
-
|
|
2564
|
-
const
|
|
2563
|
+
let tIdx = dateTime.indexOf("T");
|
|
2564
|
+
if (tIdx === -1) tIdx = dateTime.indexOf("t");
|
|
2565
|
+
if (tIdx === -1) return false;
|
|
2566
|
+
const datePart = dateTime.slice(0, tIdx);
|
|
2567
|
+
const timePart = dateTime.slice(tIdx + 1);
|
|
2565
2568
|
const dateMatches = /^([0-9]{4})-([0-9]{2})-([0-9]{2})$/.exec(datePart);
|
|
2566
2569
|
if (dateMatches === null) return false;
|
|
2567
|
-
if (!isValidRfc3339Date(parseInt(dateMatches[1], 10), parseInt(dateMatches[2], 10), parseInt(dateMatches[3], 10))) return false;
|
|
2570
|
+
if (!isValidRfc3339Date(Number.parseInt(dateMatches[1], 10), Number.parseInt(dateMatches[2], 10), Number.parseInt(dateMatches[3], 10))) return false;
|
|
2568
2571
|
return parseRfc3339Time(timePart) !== null;
|
|
2569
2572
|
};
|
|
2570
2573
|
const emailValidator = (email) => {
|
|
@@ -2593,26 +2596,26 @@
|
|
|
2593
2596
|
if (ipv6.includes("%")) return false;
|
|
2594
2597
|
return import_isIP.default.default(ipv6, 6);
|
|
2595
2598
|
};
|
|
2599
|
+
const INVALID_REGEX_ESCAPES = new Set(["a"]);
|
|
2596
2600
|
const regexValidator = (input) => {
|
|
2597
2601
|
if (typeof input !== "string") return true;
|
|
2598
|
-
const invalidEscapes = new Set(["a"]);
|
|
2599
2602
|
for (let idx = 0; idx < input.length; idx++) {
|
|
2600
2603
|
if (input[idx] !== "\\") continue;
|
|
2601
2604
|
idx++;
|
|
2602
2605
|
if (idx >= input.length) return false;
|
|
2603
2606
|
const escaped = input[idx];
|
|
2604
|
-
if (
|
|
2607
|
+
if (INVALID_REGEX_ESCAPES.has(escaped)) return false;
|
|
2605
2608
|
}
|
|
2606
2609
|
try {
|
|
2607
|
-
RegExp(input);
|
|
2610
|
+
new RegExp(input);
|
|
2608
2611
|
return true;
|
|
2609
|
-
} catch
|
|
2612
|
+
} catch {
|
|
2610
2613
|
return false;
|
|
2611
2614
|
}
|
|
2612
2615
|
};
|
|
2613
2616
|
const durationValidator = (input) => {
|
|
2614
2617
|
if (typeof input !== "string") return true;
|
|
2615
|
-
if (!/^P[\
|
|
2618
|
+
if (!/^P[\u0000-\u007F]*$/.test(input)) return false;
|
|
2616
2619
|
if (!input.startsWith("P")) return false;
|
|
2617
2620
|
const body = input.slice(1);
|
|
2618
2621
|
if (body.length === 0) return false;
|
|
@@ -2622,7 +2625,7 @@
|
|
|
2622
2625
|
const datePart = parts[0];
|
|
2623
2626
|
const timePart = parts.length === 2 ? parts[1] : void 0;
|
|
2624
2627
|
if (datePart.length > 0 && !/^(?:\d+Y(?:\d+M(?:\d+D)?)?|\d+M(?:\d+D)?|\d+D)$/.test(datePart)) return false;
|
|
2625
|
-
const hasDateComponent =
|
|
2628
|
+
const hasDateComponent = datePart.length > 0;
|
|
2626
2629
|
let hasTimeComponent = false;
|
|
2627
2630
|
if (timePart !== void 0) {
|
|
2628
2631
|
if (timePart.length === 0) return false;
|
|
@@ -2637,32 +2640,31 @@
|
|
|
2637
2640
|
return /^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$/.test(input);
|
|
2638
2641
|
};
|
|
2639
2642
|
const strictUriValidator = (uri) => typeof uri !== "string" || import_isURL.default.default(uri);
|
|
2643
|
+
const isHexChar = (c) => c >= 48 && c <= 57 || c >= 65 && c <= 70 || c >= 97 && c <= 102;
|
|
2640
2644
|
const hasValidPercentEncoding = (str) => {
|
|
2641
|
-
for (let i = 0; i < str.length; i++) if (str[i] === "%")
|
|
2642
|
-
if (i + 2 >= str.length || !/[0-9a-fA-F]/.test(str[i + 1]) || !/[0-9a-fA-F]/.test(str[i + 2])) return false;
|
|
2643
|
-
}
|
|
2645
|
+
for (let i = 0; i < str.length; i++) if (str[i] === "%" && (i + 2 >= str.length || !isHexChar(str.charCodeAt(i + 1)) || !isHexChar(str.charCodeAt(i + 2)))) return false;
|
|
2644
2646
|
return true;
|
|
2645
2647
|
};
|
|
2646
|
-
const uriValidator =
|
|
2648
|
+
const uriValidator = (uri) => {
|
|
2647
2649
|
if (typeof uri !== "string") return true;
|
|
2648
|
-
if (/[^\
|
|
2650
|
+
if (/[^\u0000-\u007F]/.test(uri)) return false;
|
|
2649
2651
|
if (!hasValidPercentEncoding(uri)) return false;
|
|
2650
|
-
const match =
|
|
2652
|
+
const match = /^([a-zA-Z][a-zA-Z0-9+.-]*):\/\/([^/?#]*)/.exec(uri);
|
|
2651
2653
|
if (match) {
|
|
2652
2654
|
const authority = match[2];
|
|
2653
2655
|
const atIndex = authority.indexOf("@");
|
|
2654
2656
|
if (atIndex > 0) {
|
|
2655
|
-
const userinfo = authority.
|
|
2657
|
+
const userinfo = authority.slice(0, atIndex);
|
|
2656
2658
|
if (userinfo.includes("[") || userinfo.includes("]")) return false;
|
|
2657
2659
|
}
|
|
2658
|
-
let hostPort = atIndex
|
|
2660
|
+
let hostPort = atIndex === -1 ? authority : authority.slice(atIndex + 1);
|
|
2659
2661
|
if (hostPort.startsWith("[")) {
|
|
2660
2662
|
const bracketEnd = hostPort.indexOf("]");
|
|
2661
|
-
if (bracketEnd
|
|
2663
|
+
if (bracketEnd !== -1) hostPort = hostPort.slice(bracketEnd + 1);
|
|
2662
2664
|
}
|
|
2663
2665
|
const colonIndex = hostPort.lastIndexOf(":");
|
|
2664
|
-
if (colonIndex
|
|
2665
|
-
const port = hostPort.
|
|
2666
|
+
if (colonIndex !== -1) {
|
|
2667
|
+
const port = hostPort.slice(colonIndex + 1);
|
|
2666
2668
|
if (port.length > 0 && !/^\d+$/.test(port)) return false;
|
|
2667
2669
|
}
|
|
2668
2670
|
}
|
|
@@ -2670,7 +2672,7 @@
|
|
|
2670
2672
|
};
|
|
2671
2673
|
const uriReferenceValidator = (uri) => {
|
|
2672
2674
|
if (typeof uri !== "string") return true;
|
|
2673
|
-
if (/[^\
|
|
2675
|
+
if (/[^\u0000-\u007F]/.test(uri)) return false;
|
|
2674
2676
|
return /^([a-zA-Z][a-zA-Z0-9+.-]*:)?[^"\\<>^{}^`| ]*$/.test(uri);
|
|
2675
2677
|
};
|
|
2676
2678
|
const uriTemplateValidator = (uri) => {
|
|
@@ -2701,20 +2703,20 @@
|
|
|
2701
2703
|
if (typeof pointer !== "string") return true;
|
|
2702
2704
|
if (pointer === "") return true;
|
|
2703
2705
|
if (!/^(?:\/[^/]*)+$/.test(pointer)) return false;
|
|
2704
|
-
const tokens = pointer.split("/")
|
|
2705
|
-
for (
|
|
2706
|
+
const tokens = pointer.split("/");
|
|
2707
|
+
for (let i = 1; i < tokens.length; i++) if (!hasValidTildeEscapes(tokens[i])) return false;
|
|
2706
2708
|
return true;
|
|
2707
2709
|
};
|
|
2708
2710
|
const relativeJsonPointerValidator = (pointer) => {
|
|
2709
2711
|
if (typeof pointer !== "string") return true;
|
|
2710
|
-
const match =
|
|
2712
|
+
const match = /^(0|[1-9]\d*)(.*)$/.exec(pointer);
|
|
2711
2713
|
if (!match) return false;
|
|
2712
2714
|
const suffix = match[2];
|
|
2713
2715
|
if (suffix === "" || suffix === "#") return true;
|
|
2714
2716
|
if (!suffix.startsWith("/")) return false;
|
|
2715
2717
|
if (!/^(?:\/[^/]*)+$/.test(suffix)) return false;
|
|
2716
|
-
const tokens = suffix.split("/")
|
|
2717
|
-
for (
|
|
2718
|
+
const tokens = suffix.split("/");
|
|
2719
|
+
for (let i = 1; i < tokens.length; i++) if (!hasValidTildeEscapes(tokens[i])) return false;
|
|
2718
2720
|
return true;
|
|
2719
2721
|
};
|
|
2720
2722
|
const timeValidator = (time) => {
|
|
@@ -2735,7 +2737,7 @@
|
|
|
2735
2737
|
try {
|
|
2736
2738
|
new URL(iri);
|
|
2737
2739
|
return true;
|
|
2738
|
-
} catch
|
|
2740
|
+
} catch {
|
|
2739
2741
|
return false;
|
|
2740
2742
|
}
|
|
2741
2743
|
};
|
|
@@ -2767,13 +2769,12 @@
|
|
|
2767
2769
|
uuid: uuidValidator
|
|
2768
2770
|
};
|
|
2769
2771
|
const customValidators = {};
|
|
2770
|
-
function
|
|
2771
|
-
|
|
2772
|
-
|
|
2773
|
-
|
|
2774
|
-
|
|
2775
|
-
|
|
2776
|
-
};
|
|
2772
|
+
function resolveFormatValidator(name, options) {
|
|
2773
|
+
const custom = options?.customFormats;
|
|
2774
|
+
if (custom && Object.hasOwn(custom, name)) return custom[name];
|
|
2775
|
+
if (Object.hasOwn(customValidators, name)) return customValidators[name];
|
|
2776
|
+
if (options?.strictUris && name === "uri") return strictUriValidator;
|
|
2777
|
+
return inbuiltValidators[name];
|
|
2777
2778
|
}
|
|
2778
2779
|
function registerFormat(name, validatorFunction) {
|
|
2779
2780
|
customValidators[name] = validatorFunction;
|
|
@@ -3689,12 +3690,12 @@
|
|
|
3689
3690
|
ok: true,
|
|
3690
3691
|
value: new RegExp(pattern, "u")
|
|
3691
3692
|
};
|
|
3692
|
-
} catch (
|
|
3693
|
+
} catch (error) {
|
|
3693
3694
|
return {
|
|
3694
3695
|
ok: false,
|
|
3695
3696
|
error: {
|
|
3696
3697
|
pattern,
|
|
3697
|
-
message:
|
|
3698
|
+
message: error instanceof Error ? error.message : "Invalid regular expression"
|
|
3698
3699
|
}
|
|
3699
3700
|
};
|
|
3700
3701
|
}
|
|
@@ -3703,12 +3704,12 @@
|
|
|
3703
3704
|
ok: true,
|
|
3704
3705
|
value: new RegExp(pattern)
|
|
3705
3706
|
};
|
|
3706
|
-
} catch (
|
|
3707
|
+
} catch (error) {
|
|
3707
3708
|
return {
|
|
3708
3709
|
ok: false,
|
|
3709
3710
|
error: {
|
|
3710
3711
|
pattern,
|
|
3711
|
-
message:
|
|
3712
|
+
message: error instanceof Error ? error.message : "Invalid regular expression"
|
|
3712
3713
|
}
|
|
3713
3714
|
};
|
|
3714
3715
|
}
|
|
@@ -3737,7 +3738,7 @@
|
|
|
3737
3738
|
const seen = /* @__PURE__ */ new Set();
|
|
3738
3739
|
for (let i = 0; i < l; i++) {
|
|
3739
3740
|
const v = arr[i];
|
|
3740
|
-
const key = typeof v
|
|
3741
|
+
const key = `${typeof v}:${String(v)}`;
|
|
3741
3742
|
if (seen.has(key)) {
|
|
3742
3743
|
if (indexes) for (let j = 0; j < i; j++) {
|
|
3743
3744
|
const prev = arr[j];
|
|
@@ -3752,7 +3753,8 @@
|
|
|
3752
3753
|
}
|
|
3753
3754
|
return true;
|
|
3754
3755
|
}
|
|
3755
|
-
|
|
3756
|
+
const eqOpts = { maxDepth };
|
|
3757
|
+
for (let i = 0; i < l; i++) for (let j = i + 1; j < l; j++) if (areEqual(arr[i], arr[j], eqOpts)) {
|
|
3756
3758
|
if (indexes) indexes.push(i, j);
|
|
3757
3759
|
return false;
|
|
3758
3760
|
}
|
|
@@ -3767,11 +3769,7 @@
|
|
|
3767
3769
|
};
|
|
3768
3770
|
//#endregion
|
|
3769
3771
|
//#region src/validation/shared.ts
|
|
3770
|
-
const shouldSkipValidate =
|
|
3771
|
-
return options && Array.isArray(options.includeErrors) && options.includeErrors.length > 0 && !errors.some(function(err) {
|
|
3772
|
-
return options.includeErrors.includes(err);
|
|
3773
|
-
});
|
|
3774
|
-
};
|
|
3772
|
+
const shouldSkipValidate = (options, errors) => options && Array.isArray(options.includeErrors) && options.includeErrors.length > 0 && !errors.some((err) => options.includeErrors.includes(err));
|
|
3775
3773
|
const supportsDependentKeywords = (schema, version) => {
|
|
3776
3774
|
if (typeof schema.$schema === "string") return !/draft-04|draft-06|draft-07/.test(schema.$schema);
|
|
3777
3775
|
return !(version === "draft-04" || version === "draft-06" || version === "draft-07");
|
|
@@ -3811,7 +3809,7 @@
|
|
|
3811
3809
|
const metaSchema = currentSchemaMeta || rootSchemaMeta;
|
|
3812
3810
|
if (!metaSchema || typeof metaSchema !== "object" || !isObject(metaSchema.$vocabulary)) return true;
|
|
3813
3811
|
const vocabulary = metaSchema.$vocabulary;
|
|
3814
|
-
if (Object.hasOwn(vocabulary, VOCAB_VALIDATION_2019_09) || Object.hasOwn(vocabulary, VOCAB_VALIDATION_2020_12)) return vocabulary[VOCAB_VALIDATION_2019_09]
|
|
3812
|
+
if (Object.hasOwn(vocabulary, VOCAB_VALIDATION_2019_09) || Object.hasOwn(vocabulary, VOCAB_VALIDATION_2020_12)) return vocabulary[VOCAB_VALIDATION_2019_09] || vocabulary[VOCAB_VALIDATION_2020_12];
|
|
3815
3813
|
return false;
|
|
3816
3814
|
};
|
|
3817
3815
|
/**
|
|
@@ -3827,8 +3825,8 @@
|
|
|
3827
3825
|
const metaSchema = currentSchemaMeta || rootSchemaMeta;
|
|
3828
3826
|
if (!metaSchema || typeof metaSchema !== "object" || !isObject(metaSchema.$vocabulary)) return false;
|
|
3829
3827
|
const vocabulary = metaSchema.$vocabulary;
|
|
3830
|
-
if (Object.hasOwn(vocabulary, VOCAB_FORMAT_ASSERTION_2020_12)) return vocabulary[VOCAB_FORMAT_ASSERTION_2020_12]
|
|
3831
|
-
if (Object.hasOwn(vocabulary, VOCAB_FORMAT_2019_09)) return vocabulary[VOCAB_FORMAT_2019_09]
|
|
3828
|
+
if (Object.hasOwn(vocabulary, VOCAB_FORMAT_ASSERTION_2020_12)) return vocabulary[VOCAB_FORMAT_ASSERTION_2020_12];
|
|
3829
|
+
if (Object.hasOwn(vocabulary, VOCAB_FORMAT_2019_09)) return vocabulary[VOCAB_FORMAT_2019_09];
|
|
3832
3830
|
return false;
|
|
3833
3831
|
};
|
|
3834
3832
|
function cacheValidationResult(report, schema, json, passed) {
|
|
@@ -3852,9 +3850,14 @@
|
|
|
3852
3850
|
*/
|
|
3853
3851
|
function deferOrRunSync(report, subReports, decisionFn) {
|
|
3854
3852
|
const asyncTasksBefore = report.asyncTasks.length;
|
|
3855
|
-
for (
|
|
3853
|
+
for (let i = 0; i < subReports.length; i++) {
|
|
3854
|
+
const tasks = subReports[i].asyncTasks;
|
|
3855
|
+
for (let j = 0; j < tasks.length; j++) report.asyncTasks.push(tasks[j]);
|
|
3856
|
+
}
|
|
3856
3857
|
if (report.asyncTasks.length > asyncTasksBefore) report.addAsyncTaskWithPath((callback) => {
|
|
3857
|
-
setTimeout(() =>
|
|
3858
|
+
setTimeout(() => {
|
|
3859
|
+
callback(null);
|
|
3860
|
+
}, 0);
|
|
3858
3861
|
}, [], () => {
|
|
3859
3862
|
decisionFn();
|
|
3860
3863
|
});
|
|
@@ -3862,35 +3865,33 @@
|
|
|
3862
3865
|
}
|
|
3863
3866
|
//#endregion
|
|
3864
3867
|
//#region src/validation/array.ts
|
|
3865
|
-
function additionalItemsValidator(report, schema, json) {
|
|
3866
|
-
if (shouldSkipValidate(
|
|
3868
|
+
function additionalItemsValidator(ctx, report, schema, json) {
|
|
3869
|
+
if (shouldSkipValidate(ctx.validateOptions, ["ARRAY_ADDITIONAL_ITEMS"])) return;
|
|
3867
3870
|
if (!Array.isArray(json)) return;
|
|
3868
|
-
if (schema.additionalItems === false && Array.isArray(schema.items))
|
|
3869
|
-
if (json.length > schema.items.length) report.addError("ARRAY_ADDITIONAL_ITEMS", void 0, void 0, schema, "additionalItems");
|
|
3870
|
-
}
|
|
3871
|
+
if (schema.additionalItems === false && Array.isArray(schema.items) && json.length > schema.items.length) report.addError("ARRAY_ADDITIONAL_ITEMS", void 0, void 0, schema, "additionalItems");
|
|
3871
3872
|
}
|
|
3872
3873
|
function itemsValidator() {}
|
|
3873
3874
|
function prefixItemsValidator() {}
|
|
3874
|
-
function maxItemsValidator(report, schema, json) {
|
|
3875
|
-
if (shouldSkipValidate(
|
|
3875
|
+
function maxItemsValidator(ctx, report, schema, json) {
|
|
3876
|
+
if (shouldSkipValidate(ctx.validateOptions, ["ARRAY_LENGTH_LONG"])) return;
|
|
3876
3877
|
if (!Array.isArray(json)) return;
|
|
3877
3878
|
if (json.length > schema.maxItems) report.addError("ARRAY_LENGTH_LONG", [json.length, schema.maxItems], void 0, schema, "maxItems");
|
|
3878
3879
|
}
|
|
3879
|
-
function minItemsValidator(report, schema, json) {
|
|
3880
|
-
if (shouldSkipValidate(
|
|
3880
|
+
function minItemsValidator(ctx, report, schema, json) {
|
|
3881
|
+
if (shouldSkipValidate(ctx.validateOptions, ["ARRAY_LENGTH_SHORT"])) return;
|
|
3881
3882
|
if (!Array.isArray(json)) return;
|
|
3882
3883
|
if (json.length < schema.minItems) report.addError("ARRAY_LENGTH_SHORT", [json.length, schema.minItems], void 0, schema, "minItems");
|
|
3883
3884
|
}
|
|
3884
|
-
function uniqueItemsValidator(report, schema, json) {
|
|
3885
|
-
if (shouldSkipValidate(
|
|
3885
|
+
function uniqueItemsValidator(ctx, report, schema, json) {
|
|
3886
|
+
if (shouldSkipValidate(ctx.validateOptions, ["ARRAY_UNIQUE"])) return;
|
|
3886
3887
|
if (!Array.isArray(json)) return;
|
|
3887
3888
|
if (schema.uniqueItems === true) {
|
|
3888
3889
|
const matches = [];
|
|
3889
|
-
if (isUniqueArray(json, matches,
|
|
3890
|
+
if (!isUniqueArray(json, matches, ctx.options.maxRecursionDepth)) report.addError("ARRAY_UNIQUE", matches, void 0, schema, "uniqueItems");
|
|
3890
3891
|
}
|
|
3891
3892
|
}
|
|
3892
|
-
function containsValidator(report, schema, json) {
|
|
3893
|
-
if (shouldSkipValidate(
|
|
3893
|
+
function containsValidator(ctx, report, schema, json) {
|
|
3894
|
+
if (shouldSkipValidate(ctx.validateOptions, ["CONTAINS"])) return;
|
|
3894
3895
|
if (!Array.isArray(json)) return;
|
|
3895
3896
|
const containsSchema = schema.contains;
|
|
3896
3897
|
if (containsSchema === void 0) return;
|
|
@@ -3899,16 +3900,16 @@
|
|
|
3899
3900
|
for (let idx = 0; idx < json.length; idx++) {
|
|
3900
3901
|
const subReport = new Report_(report);
|
|
3901
3902
|
subReports.push(subReport);
|
|
3902
|
-
|
|
3903
|
+
ctx._jsonValidate(subReport, containsSchema, json[idx]);
|
|
3903
3904
|
cacheValidationResult(report, containsSchema, json[idx], subReport.errors.length === 0);
|
|
3904
3905
|
}
|
|
3905
3906
|
const addContainsErrorIfNeeded = () => {
|
|
3906
3907
|
let matchingItems = 0;
|
|
3907
|
-
for (
|
|
3908
|
-
const supportsContainsBounds =
|
|
3908
|
+
for (let i = 0; i < subReports.length; i++) if (subReports[i].errors.length === 0) matchingItems += 1;
|
|
3909
|
+
const supportsContainsBounds = ctx.options.version === "draft2019-09" || ctx.options.version === "draft2020-12";
|
|
3909
3910
|
const minContains = supportsContainsBounds && typeof schema.minContains === "number" ? schema.minContains ?? 1 : 1;
|
|
3910
3911
|
const maxContains = supportsContainsBounds && typeof schema.maxContains === "number" ? schema.maxContains : void 0;
|
|
3911
|
-
if (!(matchingItems >= minContains) || !(maxContains === void 0 || matchingItems <= maxContains)) report.addError("CONTAINS", void 0, subReports, schema
|
|
3912
|
+
if (!(matchingItems >= minContains) || !(maxContains === void 0 || matchingItems <= maxContains)) report.addError("CONTAINS", void 0, subReports, schema);
|
|
3912
3913
|
};
|
|
3913
3914
|
deferOrRunSync(report, subReports, addContainsErrorIfNeeded);
|
|
3914
3915
|
}
|
|
@@ -3916,18 +3917,18 @@
|
|
|
3916
3917
|
function minContainsValidator() {}
|
|
3917
3918
|
//#endregion
|
|
3918
3919
|
//#region src/validation/combinators.ts
|
|
3919
|
-
function allOfValidator(report, schema, json) {
|
|
3920
|
+
function allOfValidator(ctx, report, schema, json) {
|
|
3920
3921
|
for (let i = 0; i < schema.allOf.length; i++) {
|
|
3921
|
-
const validateResult =
|
|
3922
|
-
if (
|
|
3922
|
+
const validateResult = ctx._jsonValidate(report, schema.allOf[i], json);
|
|
3923
|
+
if (ctx.options.breakOnFirstError && !validateResult) break;
|
|
3923
3924
|
}
|
|
3924
3925
|
}
|
|
3925
|
-
function anyOfValidator(report, schema, json) {
|
|
3926
|
+
function anyOfValidator(ctx, report, schema, json) {
|
|
3926
3927
|
const subReports = [];
|
|
3927
3928
|
for (let i = 0; i < schema.anyOf.length; i++) {
|
|
3928
3929
|
const subReport = new Report(report);
|
|
3929
3930
|
subReports.push(subReport);
|
|
3930
|
-
|
|
3931
|
+
ctx._jsonValidate(subReport, schema.anyOf[i], json);
|
|
3931
3932
|
cacheValidationResult(report, schema.anyOf[i], json, subReport.errors.length === 0);
|
|
3932
3933
|
}
|
|
3933
3934
|
deferOrRunSync(report, subReports, () => {
|
|
@@ -3936,15 +3937,15 @@
|
|
|
3936
3937
|
passed = true;
|
|
3937
3938
|
break;
|
|
3938
3939
|
}
|
|
3939
|
-
if (passed
|
|
3940
|
+
if (!passed) report.addError("ANY_OF_MISSING", void 0, subReports, schema, "anyOf");
|
|
3940
3941
|
});
|
|
3941
3942
|
}
|
|
3942
|
-
function oneOfValidator(report, schema, json) {
|
|
3943
|
+
function oneOfValidator(ctx, report, schema, json) {
|
|
3943
3944
|
const subReports = [];
|
|
3944
3945
|
for (let i = 0; i < schema.oneOf.length; i++) {
|
|
3945
3946
|
const subReport = new Report(report);
|
|
3946
3947
|
subReports.push(subReport);
|
|
3947
|
-
|
|
3948
|
+
ctx._jsonValidate(subReport, schema.oneOf[i], json);
|
|
3948
3949
|
cacheValidationResult(report, schema.oneOf[i], json, subReport.errors.length === 0);
|
|
3949
3950
|
}
|
|
3950
3951
|
deferOrRunSync(report, subReports, () => {
|
|
@@ -3954,77 +3955,77 @@
|
|
|
3954
3955
|
else if (passes > 1) report.addError("ONE_OF_MULTIPLE", void 0, void 0, schema, "oneOf");
|
|
3955
3956
|
});
|
|
3956
3957
|
}
|
|
3957
|
-
function notValidator(report, schema, json) {
|
|
3958
|
+
function notValidator(ctx, report, schema, json) {
|
|
3958
3959
|
const subReport = new Report(report);
|
|
3959
|
-
if (
|
|
3960
|
+
if (ctx._jsonValidate(subReport, schema.not, json)) report.addError("NOT_PASSED", void 0, void 0, schema, "not");
|
|
3960
3961
|
}
|
|
3961
|
-
function ifValidator(report, schema, json) {
|
|
3962
|
-
if (
|
|
3962
|
+
function ifValidator(ctx, report, schema, json) {
|
|
3963
|
+
if (ctx.options.version === "draft-04" || ctx.options.version === "draft-06") return;
|
|
3963
3964
|
const conditionSchema = schema.if;
|
|
3964
3965
|
const thenSchema = schema.then;
|
|
3965
3966
|
const elseSchema = schema.else;
|
|
3966
3967
|
if (conditionSchema === void 0 || thenSchema === void 0 && elseSchema === void 0) return;
|
|
3967
3968
|
const conditionReport = new Report(report);
|
|
3968
|
-
|
|
3969
|
+
ctx._jsonValidate(conditionReport, conditionSchema, json);
|
|
3969
3970
|
cacheValidationResult(report, conditionSchema, json, conditionReport.errors.length === 0);
|
|
3970
3971
|
const branchSchema = conditionReport.errors.length === 0 ? thenSchema : elseSchema;
|
|
3971
3972
|
if (branchSchema === void 0) return;
|
|
3972
|
-
|
|
3973
|
+
ctx._jsonValidate(report, branchSchema, json);
|
|
3973
3974
|
}
|
|
3974
3975
|
function thenValidator() {}
|
|
3975
3976
|
function elseValidator() {}
|
|
3976
3977
|
//#endregion
|
|
3977
3978
|
//#region src/validation/numeric.ts
|
|
3978
|
-
function multipleOfValidator(report, schema, json) {
|
|
3979
|
-
if (shouldSkipValidate(
|
|
3979
|
+
function multipleOfValidator(ctx, report, schema, json) {
|
|
3980
|
+
if (shouldSkipValidate(ctx.validateOptions, ["MULTIPLE_OF"])) return;
|
|
3980
3981
|
if (typeof json !== "number") return;
|
|
3981
3982
|
const result = json / schema.multipleOf;
|
|
3982
3983
|
if (!Number.isFinite(result) || Math.abs(result - Math.round(result)) >= 1e-10) report.addError("MULTIPLE_OF", [json, schema.multipleOf], void 0, schema, "multipleOf");
|
|
3983
3984
|
}
|
|
3984
|
-
function maximumValidator(report, schema, json) {
|
|
3985
|
-
if (shouldSkipValidate(
|
|
3985
|
+
function maximumValidator(ctx, report, schema, json) {
|
|
3986
|
+
if (shouldSkipValidate(ctx.validateOptions, ["MAXIMUM", "MAXIMUM_EXCLUSIVE"])) return;
|
|
3986
3987
|
if (typeof json !== "number") return;
|
|
3987
3988
|
if (schema.exclusiveMaximum !== true) {
|
|
3988
3989
|
if (json > schema.maximum) report.addError("MAXIMUM", [json, schema.maximum], void 0, schema, "maximum");
|
|
3989
3990
|
} else if (json >= schema.maximum) report.addError("MAXIMUM_EXCLUSIVE", [json, schema.maximum], void 0, schema, "maximum");
|
|
3990
3991
|
}
|
|
3991
|
-
function exclusiveMaximumValidator(report, schema, json) {
|
|
3992
|
+
function exclusiveMaximumValidator(ctx, report, schema, json) {
|
|
3992
3993
|
if (typeof schema.exclusiveMaximum === "number") {
|
|
3993
|
-
if (shouldSkipValidate(
|
|
3994
|
+
if (shouldSkipValidate(ctx.validateOptions, ["MAXIMUM_EXCLUSIVE"])) return;
|
|
3994
3995
|
if (typeof json !== "number") return;
|
|
3995
3996
|
if (json >= schema.exclusiveMaximum) report.addError("MAXIMUM_EXCLUSIVE", [json, schema.exclusiveMaximum], void 0, schema, "exclusiveMaximum");
|
|
3996
3997
|
}
|
|
3997
3998
|
}
|
|
3998
|
-
function minimumValidator(report, schema, json) {
|
|
3999
|
-
if (shouldSkipValidate(
|
|
3999
|
+
function minimumValidator(ctx, report, schema, json) {
|
|
4000
|
+
if (shouldSkipValidate(ctx.validateOptions, ["MINIMUM", "MINIMUM_EXCLUSIVE"])) return;
|
|
4000
4001
|
if (typeof json !== "number") return;
|
|
4001
4002
|
if (schema.exclusiveMinimum !== true) {
|
|
4002
4003
|
if (json < schema.minimum) report.addError("MINIMUM", [json, schema.minimum], void 0, schema, "minimum");
|
|
4003
4004
|
} else if (json <= schema.minimum) report.addError("MINIMUM_EXCLUSIVE", [json, schema.minimum], void 0, schema, "minimum");
|
|
4004
4005
|
}
|
|
4005
|
-
function exclusiveMinimumValidator(report, schema, json) {
|
|
4006
|
+
function exclusiveMinimumValidator(ctx, report, schema, json) {
|
|
4006
4007
|
if (typeof schema.exclusiveMinimum === "number") {
|
|
4007
|
-
if (shouldSkipValidate(
|
|
4008
|
+
if (shouldSkipValidate(ctx.validateOptions, ["MINIMUM_EXCLUSIVE"])) return;
|
|
4008
4009
|
if (typeof json !== "number") return;
|
|
4009
4010
|
if (json <= schema.exclusiveMinimum) report.addError("MINIMUM_EXCLUSIVE", [json, schema.exclusiveMinimum], void 0, schema, "exclusiveMinimum");
|
|
4010
4011
|
}
|
|
4011
4012
|
}
|
|
4012
4013
|
//#endregion
|
|
4013
4014
|
//#region src/validation/object.ts
|
|
4014
|
-
function maxPropertiesValidator(report, schema, json) {
|
|
4015
|
-
if (shouldSkipValidate(
|
|
4015
|
+
function maxPropertiesValidator(ctx, report, schema, json) {
|
|
4016
|
+
if (shouldSkipValidate(ctx.validateOptions, ["OBJECT_PROPERTIES_MAXIMUM"])) return;
|
|
4016
4017
|
if (!isObject(json)) return;
|
|
4017
4018
|
const keysCount = Object.keys(json).length;
|
|
4018
4019
|
if (keysCount > schema.maxProperties) report.addError("OBJECT_PROPERTIES_MAXIMUM", [keysCount, schema.maxProperties], void 0, schema, "maxProperties");
|
|
4019
4020
|
}
|
|
4020
|
-
function minPropertiesValidator(report, schema, json) {
|
|
4021
|
-
if (shouldSkipValidate(
|
|
4021
|
+
function minPropertiesValidator(ctx, report, schema, json) {
|
|
4022
|
+
if (shouldSkipValidate(ctx.validateOptions, ["OBJECT_PROPERTIES_MINIMUM"])) return;
|
|
4022
4023
|
if (!isObject(json)) return;
|
|
4023
4024
|
const keysCount = Object.keys(json).length;
|
|
4024
4025
|
if (keysCount < schema.minProperties) report.addError("OBJECT_PROPERTIES_MINIMUM", [keysCount, schema.minProperties], void 0, schema, "minProperties");
|
|
4025
4026
|
}
|
|
4026
|
-
function requiredValidator(report, schema, json) {
|
|
4027
|
-
if (shouldSkipValidate(
|
|
4027
|
+
function requiredValidator(ctx, report, schema, json) {
|
|
4028
|
+
if (shouldSkipValidate(ctx.validateOptions, ["OBJECT_MISSING_REQUIRED_PROPERTY"])) return;
|
|
4028
4029
|
if (!isObject(json)) return;
|
|
4029
4030
|
const idx = schema.required.length;
|
|
4030
4031
|
for (let i = 0; i < idx; i++) {
|
|
@@ -4032,30 +4033,31 @@
|
|
|
4032
4033
|
if (!Object.hasOwn(json, requiredPropertyName)) report.addError("OBJECT_MISSING_REQUIRED_PROPERTY", [requiredPropertyName], void 0, schema, "required");
|
|
4033
4034
|
}
|
|
4034
4035
|
}
|
|
4035
|
-
function additionalPropertiesValidator(report, schema, json) {
|
|
4036
|
-
if (schema.properties === void 0 && schema.patternProperties === void 0)
|
|
4036
|
+
function additionalPropertiesValidator(ctx, report, schema, json) {
|
|
4037
|
+
if (schema.properties === void 0 && schema.patternProperties === void 0) propertiesValidator(ctx, report, schema, json);
|
|
4037
4038
|
}
|
|
4038
|
-
function patternPropertiesValidator(report, schema, json) {
|
|
4039
|
-
if (schema.properties === void 0)
|
|
4039
|
+
function patternPropertiesValidator(ctx, report, schema, json) {
|
|
4040
|
+
if (schema.properties === void 0) propertiesValidator(ctx, report, schema, json);
|
|
4040
4041
|
}
|
|
4041
|
-
function propertiesValidator(report, schema, json) {
|
|
4042
|
-
if (shouldSkipValidate(
|
|
4042
|
+
function propertiesValidator(ctx, report, schema, json) {
|
|
4043
|
+
if (shouldSkipValidate(ctx.validateOptions, ["OBJECT_ADDITIONAL_PROPERTIES"])) return;
|
|
4043
4044
|
if (!isObject(json)) return;
|
|
4044
|
-
const properties = schema.properties
|
|
4045
|
-
const patternProperties = schema.patternProperties
|
|
4045
|
+
const properties = schema.properties === void 0 ? {} : schema.properties;
|
|
4046
|
+
const patternProperties = schema.patternProperties === void 0 ? {} : schema.patternProperties;
|
|
4046
4047
|
if (schema.additionalProperties === false) {
|
|
4047
4048
|
let s = Object.keys(json);
|
|
4048
4049
|
const p = Object.keys(properties);
|
|
4049
4050
|
const pp = Object.keys(patternProperties);
|
|
4050
4051
|
s = difference(s, p);
|
|
4051
|
-
for (
|
|
4052
|
+
for (let i = 0; i < pp.length; i++) {
|
|
4053
|
+
const ppKey = pp[i];
|
|
4052
4054
|
const result = compileSchemaRegex(ppKey);
|
|
4053
4055
|
if (!result.ok) continue;
|
|
4054
4056
|
const regExp = result.value;
|
|
4055
|
-
for (let idx2 = s.length - 1; idx2 >= 0; idx2--) if (regExp.test(s[idx2])
|
|
4057
|
+
for (let idx2 = s.length - 1; idx2 >= 0; idx2--) if (regExp.test(s[idx2])) s.splice(idx2, 1);
|
|
4056
4058
|
}
|
|
4057
4059
|
if (s.length > 0) {
|
|
4058
|
-
if (Array.isArray(
|
|
4060
|
+
if (Array.isArray(ctx.options.assumeAdditional)) for (const allowed of ctx.options.assumeAdditional) {
|
|
4059
4061
|
const io = s.indexOf(allowed);
|
|
4060
4062
|
if (io !== -1) s.splice(io, 1);
|
|
4061
4063
|
}
|
|
@@ -4063,29 +4065,29 @@
|
|
|
4063
4065
|
}
|
|
4064
4066
|
}
|
|
4065
4067
|
}
|
|
4066
|
-
function dependenciesValidator(report, schema, json) {
|
|
4067
|
-
if (shouldSkipValidate(
|
|
4068
|
+
function dependenciesValidator(ctx, report, schema, json) {
|
|
4069
|
+
if (shouldSkipValidate(ctx.validateOptions, ["OBJECT_DEPENDENCY_KEY"])) return;
|
|
4068
4070
|
if (!isObject(json)) return;
|
|
4069
4071
|
const keys = Object.keys(schema.dependencies);
|
|
4070
4072
|
for (const dependencyName of keys) if (Object.hasOwn(json, dependencyName)) {
|
|
4071
4073
|
const dependencyDefinition = schema.dependencies[dependencyName];
|
|
4072
4074
|
if (Array.isArray(dependencyDefinition)) {
|
|
4073
4075
|
for (const requiredPropertyName of dependencyDefinition) if (!Object.hasOwn(json, requiredPropertyName)) report.addError("OBJECT_DEPENDENCY_KEY", [requiredPropertyName, dependencyName], void 0, schema, "dependencies");
|
|
4074
|
-
} else
|
|
4076
|
+
} else ctx._jsonValidate(report, dependencyDefinition, json);
|
|
4075
4077
|
}
|
|
4076
4078
|
}
|
|
4077
|
-
function dependentSchemasValidator(report, schema, json) {
|
|
4078
|
-
if (!supportsDependentKeywords(schema,
|
|
4079
|
+
function dependentSchemasValidator(ctx, report, schema, json) {
|
|
4080
|
+
if (!supportsDependentKeywords(schema, ctx.options.version)) return;
|
|
4079
4081
|
if (!isObject(json) || !isObject(schema.dependentSchemas)) return;
|
|
4080
4082
|
const keys = Object.keys(schema.dependentSchemas);
|
|
4081
4083
|
for (const dependencyName of keys) if (Object.hasOwn(json, dependencyName)) {
|
|
4082
4084
|
const dependencySchema = schema.dependentSchemas[dependencyName];
|
|
4083
|
-
|
|
4085
|
+
ctx._jsonValidate(report, dependencySchema, json);
|
|
4084
4086
|
}
|
|
4085
4087
|
}
|
|
4086
|
-
function dependentRequiredValidator(report, schema, json) {
|
|
4087
|
-
if (!supportsDependentKeywords(schema,
|
|
4088
|
-
if (shouldSkipValidate(
|
|
4088
|
+
function dependentRequiredValidator(ctx, report, schema, json) {
|
|
4089
|
+
if (!supportsDependentKeywords(schema, ctx.options.version)) return;
|
|
4090
|
+
if (shouldSkipValidate(ctx.validateOptions, ["OBJECT_DEPENDENCY_KEY"])) return;
|
|
4089
4091
|
if (!isObject(json) || !isObject(schema.dependentRequired)) return;
|
|
4090
4092
|
const keys = Object.keys(schema.dependentRequired);
|
|
4091
4093
|
for (const dependencyName of keys) {
|
|
@@ -4095,8 +4097,8 @@
|
|
|
4095
4097
|
for (const requiredPropertyName of requiredProperties) if (!Object.hasOwn(json, requiredPropertyName)) report.addError("OBJECT_DEPENDENCY_KEY", [requiredPropertyName, dependencyName], void 0, schema, "dependentRequired");
|
|
4096
4098
|
}
|
|
4097
4099
|
}
|
|
4098
|
-
function propertyNamesValidator(report, schema, json) {
|
|
4099
|
-
if (shouldSkipValidate(
|
|
4100
|
+
function propertyNamesValidator(ctx, report, schema, json) {
|
|
4101
|
+
if (shouldSkipValidate(ctx.validateOptions, ["PROPERTY_NAMES"])) return;
|
|
4100
4102
|
if (!isObject(json)) return;
|
|
4101
4103
|
const propertyNamesSchema = schema.propertyNames;
|
|
4102
4104
|
if (propertyNamesSchema === void 0) return;
|
|
@@ -4106,10 +4108,10 @@
|
|
|
4106
4108
|
for (const key of keys) {
|
|
4107
4109
|
const subReport = new Report_(report);
|
|
4108
4110
|
subReports.push(subReport);
|
|
4109
|
-
|
|
4111
|
+
ctx._jsonValidate(subReport, propertyNamesSchema, key);
|
|
4110
4112
|
}
|
|
4111
4113
|
const addPropertyNameErrors = () => {
|
|
4112
|
-
for (let idx = 0; idx < keys.length; idx++) if (subReports[idx].errors.length > 0) report.addError("PROPERTY_NAMES", [keys[idx]], subReports[idx], schema
|
|
4114
|
+
for (let idx = 0; idx < keys.length; idx++) if (subReports[idx].errors.length > 0) report.addError("PROPERTY_NAMES", [keys[idx]], subReports[idx], schema);
|
|
4113
4115
|
};
|
|
4114
4116
|
deferOrRunSync(report, subReports, addPropertyNameErrors);
|
|
4115
4117
|
}
|
|
@@ -4119,7 +4121,7 @@
|
|
|
4119
4121
|
const hashIdx = dynamicRef.indexOf("#");
|
|
4120
4122
|
if (hashIdx === -1) return;
|
|
4121
4123
|
const fragment = dynamicRef.slice(hashIdx + 1);
|
|
4122
|
-
if (!fragment || fragment
|
|
4124
|
+
if (!fragment || fragment.startsWith("/")) return;
|
|
4123
4125
|
return fragment;
|
|
4124
4126
|
};
|
|
4125
4127
|
const findDynamicAnchorInScope = (scopeSchema, anchorName) => {
|
|
@@ -4146,7 +4148,7 @@
|
|
|
4146
4148
|
*/
|
|
4147
4149
|
const resolveDynamicRef = (schema, dynamicScopeStack) => {
|
|
4148
4150
|
const resolved = schema.__$dynamicRefResolved;
|
|
4149
|
-
if (
|
|
4151
|
+
if (resolved === void 0 || !schema.$dynamicRef) return resolved;
|
|
4150
4152
|
let target = resolved;
|
|
4151
4153
|
const anchorName = getDynamicRefAnchorName(schema.$dynamicRef);
|
|
4152
4154
|
if (anchorName && typeof target === "object" && target.$dynamicAnchor === anchorName) for (let scopeIdx = 0; scopeIdx < dynamicScopeStack.length; scopeIdx++) {
|
|
@@ -4173,8 +4175,9 @@
|
|
|
4173
4175
|
} catch {
|
|
4174
4176
|
return;
|
|
4175
4177
|
}
|
|
4176
|
-
|
|
4177
|
-
|
|
4178
|
+
const bufferCtor = globalThis.Buffer;
|
|
4179
|
+
if (bufferCtor !== void 0) try {
|
|
4180
|
+
return bufferCtor.from(value, "base64").toString("utf-8");
|
|
4178
4181
|
} catch {
|
|
4179
4182
|
return;
|
|
4180
4183
|
}
|
|
@@ -4183,27 +4186,37 @@
|
|
|
4183
4186
|
//#region src/utils/unicode.ts
|
|
4184
4187
|
/**
|
|
4185
4188
|
* Returns the number of Unicode code points in the string.
|
|
4186
|
-
* Uses
|
|
4189
|
+
* Uses a surrogate-aware charCodeAt scan (equivalent to the string iterator)
|
|
4190
|
+
* that counts a surrogate pair as one code point and lone surrogates as one each.
|
|
4187
4191
|
*/
|
|
4188
4192
|
function unicodeLength(str) {
|
|
4189
|
-
let count =
|
|
4190
|
-
for (
|
|
4193
|
+
let count = str.length;
|
|
4194
|
+
for (let i = 0; i < str.length - 1; i++) {
|
|
4195
|
+
const hi = str.charCodeAt(i);
|
|
4196
|
+
if (hi >= 55296 && hi <= 56319) {
|
|
4197
|
+
const lo = str.charCodeAt(i + 1);
|
|
4198
|
+
if (lo >= 56320 && lo <= 57343) {
|
|
4199
|
+
count--;
|
|
4200
|
+
i++;
|
|
4201
|
+
}
|
|
4202
|
+
}
|
|
4203
|
+
}
|
|
4191
4204
|
return count;
|
|
4192
4205
|
}
|
|
4193
4206
|
//#endregion
|
|
4194
4207
|
//#region src/validation/string.ts
|
|
4195
|
-
function minLengthValidator(report, schema, json) {
|
|
4196
|
-
if (shouldSkipValidate(
|
|
4208
|
+
function minLengthValidator(ctx, report, schema, json) {
|
|
4209
|
+
if (shouldSkipValidate(ctx.validateOptions, ["MIN_LENGTH"])) return;
|
|
4197
4210
|
if (typeof json !== "string") return;
|
|
4198
4211
|
if (unicodeLength(json) < schema.minLength) report.addError("MIN_LENGTH", [json.length, schema.minLength], void 0, schema, "minLength");
|
|
4199
4212
|
}
|
|
4200
|
-
function maxLengthValidator(report, schema, json) {
|
|
4201
|
-
if (shouldSkipValidate(
|
|
4213
|
+
function maxLengthValidator(ctx, report, schema, json) {
|
|
4214
|
+
if (shouldSkipValidate(ctx.validateOptions, ["MAX_LENGTH"])) return;
|
|
4202
4215
|
if (typeof json !== "string") return;
|
|
4203
4216
|
if (unicodeLength(json) > schema.maxLength) report.addError("MAX_LENGTH", [json.length, schema.maxLength], void 0, schema, "maxLength");
|
|
4204
4217
|
}
|
|
4205
|
-
function patternValidator(report, schema, json) {
|
|
4206
|
-
if (shouldSkipValidate(
|
|
4218
|
+
function patternValidator(ctx, report, schema, json) {
|
|
4219
|
+
if (shouldSkipValidate(ctx.validateOptions, ["PATTERN"])) return;
|
|
4207
4220
|
if (typeof json !== "string") return;
|
|
4208
4221
|
const result = compileSchemaRegex(schema.pattern);
|
|
4209
4222
|
if (!result.ok) {
|
|
@@ -4216,46 +4229,46 @@
|
|
|
4216
4229
|
}
|
|
4217
4230
|
if (!result.value.test(json)) report.addError("PATTERN", [schema.pattern, json], void 0, schema, "pattern");
|
|
4218
4231
|
}
|
|
4219
|
-
function formatValidator(report, schema, json) {
|
|
4220
|
-
if (
|
|
4221
|
-
if (
|
|
4222
|
-
|
|
4223
|
-
|
|
4224
|
-
const isModernDraft = this.options.version === "draft2019-09" || this.options.version === "draft2020-12";
|
|
4225
|
-
const formatValidatorFn = getFormatValidators(this.options)[schema.format];
|
|
4232
|
+
function formatValidator(ctx, report, schema, json) {
|
|
4233
|
+
if (ctx.options.formatAssertions === false) return;
|
|
4234
|
+
if (ctx.options.formatAssertions === true && !isFormatAssertionVocabEnabled(schema, report, ctx.options.version)) return;
|
|
4235
|
+
const isModernDraft = ctx.options.version === "draft2019-09" || ctx.options.version === "draft2020-12";
|
|
4236
|
+
const formatValidatorFn = resolveFormatValidator(schema.format, ctx.options);
|
|
4226
4237
|
if (typeof formatValidatorFn === "function") {
|
|
4227
|
-
if (shouldSkipValidate(
|
|
4238
|
+
if (shouldSkipValidate(ctx.validateOptions, ["INVALID_FORMAT"])) return;
|
|
4228
4239
|
if (report.hasError("INVALID_TYPE", [schema.type, whatIs(json)])) return;
|
|
4229
|
-
if (formatValidatorFn.length === 2) report.addAsyncTaskWithPath(formatValidatorFn, [json],
|
|
4240
|
+
if (formatValidatorFn.length === 2) report.addAsyncTaskWithPath(formatValidatorFn, [json], (result) => {
|
|
4230
4241
|
if (result !== true) report.addError("INVALID_FORMAT", [schema.format, JSON.stringify(json)], void 0, schema, "format");
|
|
4231
4242
|
});
|
|
4232
4243
|
else {
|
|
4233
|
-
const result = formatValidatorFn.call(
|
|
4244
|
+
const result = formatValidatorFn.call(ctx, json);
|
|
4234
4245
|
if (result instanceof Promise) {
|
|
4235
4246
|
const promiseResult = result;
|
|
4236
4247
|
report.addAsyncTaskWithPath(async (callback) => {
|
|
4237
4248
|
try {
|
|
4238
4249
|
callback(await promiseResult);
|
|
4239
|
-
} catch
|
|
4250
|
+
} catch {
|
|
4240
4251
|
callback(false);
|
|
4241
4252
|
}
|
|
4242
|
-
}, [],
|
|
4253
|
+
}, [], (resolvedResult) => {
|
|
4243
4254
|
if (resolvedResult !== true) report.addError("INVALID_FORMAT", [schema.format, JSON.stringify(json)], void 0, schema, "format");
|
|
4244
4255
|
});
|
|
4245
|
-
} else if (result
|
|
4256
|
+
} else if (!result) report.addError("INVALID_FORMAT", [schema.format, JSON.stringify(json)], void 0, schema, "format");
|
|
4246
4257
|
}
|
|
4247
|
-
} else if (
|
|
4258
|
+
} else if (ctx.options.ignoreUnknownFormats !== true && !isModernDraft) report.addError("UNKNOWN_FORMAT", [schema.format], void 0, schema, "format");
|
|
4248
4259
|
}
|
|
4249
|
-
function contentEncodingValidator(report, schema, json) {
|
|
4250
|
-
if (
|
|
4260
|
+
function contentEncodingValidator(ctx, report, schema, json) {
|
|
4261
|
+
if (ctx.options.version !== "draft-07") return;
|
|
4251
4262
|
if (typeof json !== "string") return;
|
|
4252
|
-
|
|
4263
|
+
const { contentEncoding } = schema;
|
|
4264
|
+
if (contentEncoding !== "base64") return;
|
|
4253
4265
|
if (!isValidBase64(json)) report.addError("INVALID_FORMAT", ["contentEncoding:base64", JSON.stringify(json)], void 0, schema, "contentEncoding");
|
|
4254
4266
|
}
|
|
4255
|
-
function contentMediaTypeValidator(report, schema, json) {
|
|
4256
|
-
if (
|
|
4267
|
+
function contentMediaTypeValidator(ctx, report, schema, json) {
|
|
4268
|
+
if (ctx.options.version !== "draft-07") return;
|
|
4257
4269
|
if (typeof json !== "string") return;
|
|
4258
|
-
|
|
4270
|
+
const { contentMediaType } = schema;
|
|
4271
|
+
if (contentMediaType !== "application/json") return;
|
|
4259
4272
|
let payload = json;
|
|
4260
4273
|
if (schema.contentEncoding === "base64") {
|
|
4261
4274
|
const decoded = decodeBase64(json);
|
|
@@ -4273,38 +4286,40 @@
|
|
|
4273
4286
|
}
|
|
4274
4287
|
//#endregion
|
|
4275
4288
|
//#region src/validation/type.ts
|
|
4276
|
-
function typeValidator(report, schema, json) {
|
|
4277
|
-
if (shouldSkipValidate(
|
|
4289
|
+
function typeValidator(ctx, report, schema, json) {
|
|
4290
|
+
if (shouldSkipValidate(ctx.validateOptions, ["INVALID_TYPE"])) return;
|
|
4278
4291
|
const jsonType = whatIs(json);
|
|
4279
4292
|
if (typeof schema.type === "string") {
|
|
4280
4293
|
if (jsonType !== schema.type && (jsonType !== "integer" || schema.type !== "number")) report.addError("INVALID_TYPE", [schema.type, jsonType], void 0, schema, "type");
|
|
4281
4294
|
} else if (!schema.type.includes(jsonType) && (jsonType !== "integer" || !schema.type.includes("number"))) report.addError("INVALID_TYPE", [JSON.stringify(schema.type), jsonType], void 0, schema, "type");
|
|
4282
4295
|
}
|
|
4283
|
-
function enumValidator(report, schema, json) {
|
|
4284
|
-
if (shouldSkipValidate(
|
|
4285
|
-
|
|
4286
|
-
|
|
4296
|
+
function enumValidator(ctx, report, schema, json) {
|
|
4297
|
+
if (shouldSkipValidate(ctx.validateOptions, ["ENUM_CASE_MISMATCH", "ENUM_MISMATCH"])) return;
|
|
4298
|
+
const eqOpts = { maxDepth: ctx.options.maxRecursionDepth };
|
|
4299
|
+
const eqOptsCI = {
|
|
4300
|
+
caseInsensitiveComparison: true,
|
|
4301
|
+
maxDepth: ctx.options.maxRecursionDepth
|
|
4302
|
+
};
|
|
4303
|
+
let caseInsensitiveMatch = false, match = false;
|
|
4304
|
+
for (const enumVal of schema.enum) if (areEqual(json, enumVal, eqOpts)) {
|
|
4287
4305
|
match = true;
|
|
4288
4306
|
break;
|
|
4289
|
-
} else if (areEqual(json, enumVal,
|
|
4290
|
-
|
|
4291
|
-
|
|
4292
|
-
})) caseInsensitiveMatch = true;
|
|
4293
|
-
if (match === false) {
|
|
4294
|
-
const error = caseInsensitiveMatch && this.options.enumCaseInsensitiveComparison ? "ENUM_CASE_MISMATCH" : "ENUM_MISMATCH";
|
|
4307
|
+
} else if (areEqual(json, enumVal, eqOptsCI)) caseInsensitiveMatch = true;
|
|
4308
|
+
if (!match) {
|
|
4309
|
+
const error = caseInsensitiveMatch && ctx.options.enumCaseInsensitiveComparison ? "ENUM_CASE_MISMATCH" : "ENUM_MISMATCH";
|
|
4295
4310
|
report.addError(error, [JSON.stringify(json)], void 0, schema, "enum");
|
|
4296
4311
|
}
|
|
4297
4312
|
}
|
|
4298
|
-
function constValidator(report, schema, json) {
|
|
4313
|
+
function constValidator(ctx, report, schema, json) {
|
|
4299
4314
|
const constValue = schema.const;
|
|
4300
|
-
if (areEqual(json, constValue, { maxDepth:
|
|
4315
|
+
if (!areEqual(json, constValue, { maxDepth: ctx.options.maxRecursionDepth })) report.addError("CONST", [JSON.stringify(constValue)], void 0, schema);
|
|
4301
4316
|
}
|
|
4302
4317
|
//#endregion
|
|
4303
4318
|
//#region src/json-validation.ts
|
|
4304
|
-
function collectEvaluated(args) {
|
|
4319
|
+
function collectEvaluated(ctx, args) {
|
|
4305
4320
|
const { report, currentSchema, json, mode, depth } = args;
|
|
4306
4321
|
if (!currentSchema || typeof currentSchema === "boolean") return /* @__PURE__ */ new Set();
|
|
4307
|
-
if (depth > (
|
|
4322
|
+
if (depth > (ctx.options.maxRecursionDepth ?? 100)) {
|
|
4308
4323
|
report.addError("COLLECT_EVALUATED_DEPTH_EXCEEDED", [depth]);
|
|
4309
4324
|
return /* @__PURE__ */ new Set();
|
|
4310
4325
|
}
|
|
@@ -4315,7 +4330,7 @@
|
|
|
4315
4330
|
return false;
|
|
4316
4331
|
};
|
|
4317
4332
|
const recurse = (subSchema) => {
|
|
4318
|
-
if (mode === "items") return collectEvaluated
|
|
4333
|
+
if (mode === "items") return collectEvaluated(ctx, {
|
|
4319
4334
|
report,
|
|
4320
4335
|
currentSchema: subSchema,
|
|
4321
4336
|
json,
|
|
@@ -4323,7 +4338,7 @@
|
|
|
4323
4338
|
jsonArr: args.jsonArr,
|
|
4324
4339
|
depth: depth + 1
|
|
4325
4340
|
});
|
|
4326
|
-
return collectEvaluated
|
|
4341
|
+
return collectEvaluated(ctx, {
|
|
4327
4342
|
report,
|
|
4328
4343
|
currentSchema: subSchema,
|
|
4329
4344
|
json,
|
|
@@ -4333,7 +4348,7 @@
|
|
|
4333
4348
|
});
|
|
4334
4349
|
};
|
|
4335
4350
|
if (mode === "items") {
|
|
4336
|
-
const jsonArr = args
|
|
4351
|
+
const { jsonArr } = args;
|
|
4337
4352
|
if (Array.isArray(currentSchema.prefixItems)) {
|
|
4338
4353
|
const len = Math.min(currentSchema.prefixItems.length, jsonArr.length);
|
|
4339
4354
|
for (let i = 0; i < len; i++) evaluated.add(i);
|
|
@@ -4349,104 +4364,102 @@
|
|
|
4349
4364
|
let passed = getCachedValidationResult(report, currentSchema.contains, jsonArr[i]);
|
|
4350
4365
|
if (passed === void 0) {
|
|
4351
4366
|
const subReport = new Report(report);
|
|
4352
|
-
validate
|
|
4367
|
+
validate(ctx, subReport, currentSchema.contains, jsonArr[i]);
|
|
4353
4368
|
passed = subReport.errors.length === 0;
|
|
4354
4369
|
}
|
|
4355
4370
|
if (passed) evaluated.add(i);
|
|
4356
4371
|
}
|
|
4357
4372
|
if (currentSchema.unevaluatedItems === true) return "all";
|
|
4358
4373
|
} else {
|
|
4359
|
-
const jsonData = args
|
|
4374
|
+
const { jsonData } = args;
|
|
4360
4375
|
if (isObject(currentSchema.properties)) {
|
|
4361
|
-
|
|
4376
|
+
const propKeysCE = Object.keys(currentSchema.properties);
|
|
4377
|
+
for (let i = 0; i < propKeysCE.length; i++) {
|
|
4378
|
+
const key = propKeysCE[i];
|
|
4379
|
+
if (Object.hasOwn(jsonData, key)) evaluated.add(key);
|
|
4380
|
+
}
|
|
4362
4381
|
}
|
|
4363
4382
|
if (isObject(currentSchema.patternProperties)) for (const pattern of Object.keys(currentSchema.patternProperties)) {
|
|
4364
4383
|
const result = compileSchemaRegex(pattern);
|
|
4365
4384
|
if (result.ok) {
|
|
4366
|
-
|
|
4385
|
+
const jdKeys = Object.keys(jsonData);
|
|
4386
|
+
for (let i = 0; i < jdKeys.length; i++) if (result.value.test(jdKeys[i])) evaluated.add(jdKeys[i]);
|
|
4367
4387
|
}
|
|
4368
4388
|
}
|
|
4369
4389
|
if (currentSchema.additionalProperties !== void 0) {
|
|
4370
|
-
const
|
|
4390
|
+
const propKeySet = new Set(isObject(currentSchema.properties) ? Object.keys(currentSchema.properties) : []);
|
|
4371
4391
|
const patternRegexes = [];
|
|
4372
4392
|
if (isObject(currentSchema.patternProperties)) for (const pattern of Object.keys(currentSchema.patternProperties)) {
|
|
4373
4393
|
const result = compileSchemaRegex(pattern);
|
|
4374
4394
|
if (result.ok) patternRegexes.push(result.value);
|
|
4375
4395
|
}
|
|
4376
|
-
|
|
4377
|
-
|
|
4378
|
-
|
|
4396
|
+
const apKeys = Object.keys(jsonData);
|
|
4397
|
+
for (let i = 0; i < apKeys.length; i++) {
|
|
4398
|
+
const key = apKeys[i];
|
|
4399
|
+
if (propKeySet.has(key)) continue;
|
|
4400
|
+
let matchedPattern = false;
|
|
4401
|
+
for (let pi = 0; pi < patternRegexes.length; pi++) if (patternRegexes[pi].test(key)) {
|
|
4402
|
+
matchedPattern = true;
|
|
4403
|
+
break;
|
|
4404
|
+
}
|
|
4405
|
+
if (matchedPattern) continue;
|
|
4379
4406
|
evaluated.add(key);
|
|
4380
4407
|
}
|
|
4381
4408
|
}
|
|
4382
4409
|
if (isObject(currentSchema.dependentSchemas)) {
|
|
4383
|
-
for (const [depKey, depSchema] of Object.entries(currentSchema.dependentSchemas)) if (Object.hasOwn(jsonData, depKey))
|
|
4384
|
-
if (merge(recurse(depSchema))) return "all";
|
|
4385
|
-
}
|
|
4410
|
+
for (const [depKey, depSchema] of Object.entries(currentSchema.dependentSchemas)) if (Object.hasOwn(jsonData, depKey) && merge(recurse(depSchema))) return "all";
|
|
4386
4411
|
}
|
|
4387
4412
|
if (currentSchema.unevaluatedProperties === true) return "all";
|
|
4388
4413
|
}
|
|
4389
4414
|
if (Array.isArray(currentSchema.allOf)) {
|
|
4390
|
-
for (
|
|
4415
|
+
for (let i = 0; i < currentSchema.allOf.length; i++) if (merge(recurse(currentSchema.allOf[i]))) return "all";
|
|
4391
4416
|
}
|
|
4392
|
-
if (Array.isArray(currentSchema.anyOf)) for (
|
|
4417
|
+
if (Array.isArray(currentSchema.anyOf)) for (let i = 0; i < currentSchema.anyOf.length; i++) {
|
|
4418
|
+
const subSchema = currentSchema.anyOf[i];
|
|
4393
4419
|
let passed = getCachedValidationResult(report, subSchema, json);
|
|
4394
4420
|
if (passed === void 0) {
|
|
4395
4421
|
const subReport = new Report(report);
|
|
4396
|
-
validate
|
|
4422
|
+
validate(ctx, subReport, subSchema, json);
|
|
4397
4423
|
passed = subReport.errors.length === 0;
|
|
4398
4424
|
}
|
|
4399
|
-
if (passed)
|
|
4400
|
-
if (merge(recurse(subSchema))) return "all";
|
|
4401
|
-
}
|
|
4425
|
+
if (passed && merge(recurse(subSchema))) return "all";
|
|
4402
4426
|
}
|
|
4403
|
-
if (Array.isArray(currentSchema.oneOf)) for (
|
|
4427
|
+
if (Array.isArray(currentSchema.oneOf)) for (let i = 0; i < currentSchema.oneOf.length; i++) {
|
|
4428
|
+
const subSchema = currentSchema.oneOf[i];
|
|
4404
4429
|
let passed = getCachedValidationResult(report, subSchema, json);
|
|
4405
4430
|
if (passed === void 0) {
|
|
4406
4431
|
const subReport = new Report(report);
|
|
4407
|
-
validate
|
|
4432
|
+
validate(ctx, subReport, subSchema, json);
|
|
4408
4433
|
passed = subReport.errors.length === 0;
|
|
4409
4434
|
}
|
|
4410
|
-
if (passed)
|
|
4411
|
-
if (merge(recurse(subSchema))) return "all";
|
|
4412
|
-
}
|
|
4435
|
+
if (passed && merge(recurse(subSchema))) return "all";
|
|
4413
4436
|
}
|
|
4414
4437
|
if (currentSchema.if !== void 0) {
|
|
4415
4438
|
let condPassed = getCachedValidationResult(report, currentSchema.if, json);
|
|
4416
4439
|
if (condPassed === void 0) {
|
|
4417
4440
|
const condReport = new Report(report);
|
|
4418
|
-
validate
|
|
4441
|
+
validate(ctx, condReport, currentSchema.if, json);
|
|
4419
4442
|
condPassed = condReport.errors.length === 0;
|
|
4420
4443
|
}
|
|
4421
4444
|
if (condPassed) {
|
|
4422
4445
|
if (merge(recurse(currentSchema.if))) return "all";
|
|
4423
|
-
if (currentSchema.then !== void 0)
|
|
4424
|
-
|
|
4425
|
-
}
|
|
4426
|
-
} else if (currentSchema.else !== void 0) {
|
|
4427
|
-
if (merge(recurse(currentSchema.else))) return "all";
|
|
4428
|
-
}
|
|
4429
|
-
}
|
|
4430
|
-
if (currentSchema.__$refResolved && currentSchema.__$refResolved !== currentSchema) {
|
|
4431
|
-
if (merge(recurse(currentSchema.__$refResolved))) return "all";
|
|
4446
|
+
if (currentSchema.then !== void 0 && merge(recurse(currentSchema.then))) return "all";
|
|
4447
|
+
} else if (currentSchema.else !== void 0 && merge(recurse(currentSchema.else))) return "all";
|
|
4432
4448
|
}
|
|
4449
|
+
if (currentSchema.__$refResolved && currentSchema.__$refResolved !== currentSchema && merge(recurse(currentSchema.__$refResolved))) return "all";
|
|
4433
4450
|
const recursiveTarget = resolveRecursiveRef(currentSchema, report.__$recursiveAnchorStack);
|
|
4434
|
-
if (recursiveTarget && recursiveTarget !== currentSchema)
|
|
4435
|
-
if (merge(recurse(recursiveTarget))) return "all";
|
|
4436
|
-
}
|
|
4451
|
+
if (recursiveTarget && recursiveTarget !== currentSchema && merge(recurse(recursiveTarget))) return "all";
|
|
4437
4452
|
const dynamicTarget = resolveDynamicRef(currentSchema, report.__$dynamicScopeStack);
|
|
4438
|
-
if (dynamicTarget && dynamicTarget !== currentSchema)
|
|
4439
|
-
if (merge(recurse(dynamicTarget))) return "all";
|
|
4440
|
-
}
|
|
4453
|
+
if (dynamicTarget && dynamicTarget !== currentSchema && merge(recurse(dynamicTarget))) return "all";
|
|
4441
4454
|
return evaluated;
|
|
4442
4455
|
}
|
|
4443
|
-
function unevaluatedItemsValidator(report, schema, json) {
|
|
4456
|
+
function unevaluatedItemsValidator(ctx, report, schema, json) {
|
|
4444
4457
|
if (!Array.isArray(json)) return;
|
|
4445
4458
|
if (schema.unevaluatedItems === true) return;
|
|
4446
4459
|
const unevalSchema = schema.unevaluatedItems;
|
|
4447
4460
|
if (unevalSchema === void 0) return;
|
|
4448
4461
|
if (json.length === 0) return;
|
|
4449
|
-
const evaluatedItems = collectEvaluated
|
|
4462
|
+
const evaluatedItems = collectEvaluated(ctx, {
|
|
4450
4463
|
report,
|
|
4451
4464
|
currentSchema: schema,
|
|
4452
4465
|
json,
|
|
@@ -4459,23 +4472,24 @@
|
|
|
4459
4472
|
for (let i = 0; i < json.length; i++) if (!evaluatedItems.has(i)) unevaluatedIndices.push(i);
|
|
4460
4473
|
if (unevaluatedIndices.length === 0) return;
|
|
4461
4474
|
if (unevalSchema === false) report.addError("ARRAY_UNEVALUATED_ITEMS", void 0, void 0, schema, "unevaluatedItems");
|
|
4462
|
-
else for (
|
|
4475
|
+
else for (let i = 0; i < unevaluatedIndices.length; i++) {
|
|
4476
|
+
const idx = unevaluatedIndices[i];
|
|
4463
4477
|
const subReport = new Report(report);
|
|
4464
|
-
validate
|
|
4478
|
+
validate(ctx, subReport, unevalSchema, json[idx]);
|
|
4465
4479
|
if (subReport.errors.length > 0) {
|
|
4466
4480
|
report.addError("ARRAY_UNEVALUATED_ITEMS", void 0, void 0, schema, "unevaluatedItems");
|
|
4467
4481
|
break;
|
|
4468
4482
|
}
|
|
4469
4483
|
}
|
|
4470
4484
|
}
|
|
4471
|
-
function unevaluatedPropertiesValidator(report, schema, json) {
|
|
4485
|
+
function unevaluatedPropertiesValidator(ctx, report, schema, json) {
|
|
4472
4486
|
if (!isObject(json)) return;
|
|
4473
4487
|
if (schema.unevaluatedProperties === true) return;
|
|
4474
4488
|
const unevalSchema = schema.unevaluatedProperties;
|
|
4475
4489
|
if (unevalSchema === void 0) return;
|
|
4476
4490
|
const allKeys = Object.keys(json);
|
|
4477
4491
|
if (allKeys.length === 0) return;
|
|
4478
|
-
const evaluatedProperties = collectEvaluated
|
|
4492
|
+
const evaluatedProperties = collectEvaluated(ctx, {
|
|
4479
4493
|
report,
|
|
4480
4494
|
currentSchema: schema,
|
|
4481
4495
|
json,
|
|
@@ -4484,32 +4498,35 @@
|
|
|
4484
4498
|
depth: 0
|
|
4485
4499
|
});
|
|
4486
4500
|
if (evaluatedProperties === "all") return;
|
|
4487
|
-
const unevaluatedKeys =
|
|
4501
|
+
const unevaluatedKeys = [];
|
|
4502
|
+
for (let i = 0; i < allKeys.length; i++) if (!evaluatedProperties.has(allKeys[i])) unevaluatedKeys.push(allKeys[i]);
|
|
4488
4503
|
if (unevaluatedKeys.length === 0) return;
|
|
4489
4504
|
if (unevalSchema === false) report.addError("OBJECT_UNEVALUATED_PROPERTIES", [unevaluatedKeys.join(", ")], void 0, schema, "unevaluatedProperties");
|
|
4490
|
-
else for (
|
|
4505
|
+
else for (let i = 0; i < unevaluatedKeys.length; i++) {
|
|
4506
|
+
const key = unevaluatedKeys[i];
|
|
4491
4507
|
const subReport = new Report(report);
|
|
4492
|
-
validate
|
|
4508
|
+
validate(ctx, subReport, unevalSchema, json[key]);
|
|
4493
4509
|
if (subReport.errors.length > 0) report.addError("OBJECT_UNEVALUATED_PROPERTIES", [key], void 0, schema, "unevaluatedProperties");
|
|
4494
4510
|
}
|
|
4495
4511
|
}
|
|
4496
4512
|
function definitionsValidator() {}
|
|
4513
|
+
const noopValidator = () => {};
|
|
4497
4514
|
const JsonValidators = {
|
|
4498
|
-
id:
|
|
4499
|
-
$id:
|
|
4500
|
-
$ref:
|
|
4501
|
-
$schema:
|
|
4502
|
-
$dynamicAnchor:
|
|
4503
|
-
$dynamicRef:
|
|
4504
|
-
$anchor:
|
|
4505
|
-
$defs:
|
|
4506
|
-
$vocabulary:
|
|
4507
|
-
$recursiveAnchor:
|
|
4508
|
-
$recursiveRef:
|
|
4509
|
-
examples:
|
|
4510
|
-
title:
|
|
4511
|
-
description:
|
|
4512
|
-
default:
|
|
4515
|
+
id: noopValidator,
|
|
4516
|
+
$id: noopValidator,
|
|
4517
|
+
$ref: noopValidator,
|
|
4518
|
+
$schema: noopValidator,
|
|
4519
|
+
$dynamicAnchor: noopValidator,
|
|
4520
|
+
$dynamicRef: noopValidator,
|
|
4521
|
+
$anchor: noopValidator,
|
|
4522
|
+
$defs: noopValidator,
|
|
4523
|
+
$vocabulary: noopValidator,
|
|
4524
|
+
$recursiveAnchor: noopValidator,
|
|
4525
|
+
$recursiveRef: noopValidator,
|
|
4526
|
+
examples: noopValidator,
|
|
4527
|
+
title: noopValidator,
|
|
4528
|
+
description: noopValidator,
|
|
4529
|
+
default: noopValidator,
|
|
4513
4530
|
type: typeValidator,
|
|
4514
4531
|
enum: enumValidator,
|
|
4515
4532
|
const: constValidator,
|
|
@@ -4554,18 +4571,18 @@
|
|
|
4554
4571
|
else: elseValidator,
|
|
4555
4572
|
definitions: definitionsValidator
|
|
4556
4573
|
};
|
|
4557
|
-
|
|
4574
|
+
function recurseArray(ctx, report, schema, json) {
|
|
4558
4575
|
const schemaUri = typeof schema.$schema === "string" ? schema.$schema : void 0;
|
|
4559
|
-
const prefixItems = (schemaUri === "https://json-schema.org/draft/2020-12/schema" || !schemaUri &&
|
|
4576
|
+
const prefixItems = (schemaUri === "https://json-schema.org/draft/2020-12/schema" || !schemaUri && ctx.options.version === "draft2020-12") && Array.isArray(schema.prefixItems) ? schema.prefixItems : void 0;
|
|
4560
4577
|
if (prefixItems) {
|
|
4561
4578
|
for (let idx = 0; idx < json.length; idx++) if (idx < prefixItems.length) {
|
|
4562
4579
|
report.path.push(idx);
|
|
4563
|
-
validate
|
|
4580
|
+
validate(ctx, report, prefixItems[idx], json[idx]);
|
|
4564
4581
|
report.path.pop();
|
|
4565
4582
|
} else if (schema.items !== void 0 && !Array.isArray(schema.items)) {
|
|
4566
4583
|
report.path.push(idx);
|
|
4567
4584
|
report.schemaPath.push("items");
|
|
4568
|
-
validate
|
|
4585
|
+
validate(ctx, report, schema.items, json[idx]);
|
|
4569
4586
|
report.schemaPath.pop();
|
|
4570
4587
|
report.path.pop();
|
|
4571
4588
|
}
|
|
@@ -4574,50 +4591,56 @@
|
|
|
4574
4591
|
if (Array.isArray(schema.items)) {
|
|
4575
4592
|
for (let idx = 0; idx < json.length; idx++) if (idx < schema.items.length) {
|
|
4576
4593
|
report.path.push(idx);
|
|
4577
|
-
validate
|
|
4594
|
+
validate(ctx, report, schema.items[idx], json[idx]);
|
|
4578
4595
|
report.path.pop();
|
|
4579
4596
|
} else if (typeof schema.additionalItems === "object") {
|
|
4580
4597
|
report.path.push(idx);
|
|
4581
|
-
validate
|
|
4598
|
+
validate(ctx, report, schema.additionalItems, json[idx]);
|
|
4582
4599
|
report.path.pop();
|
|
4583
4600
|
}
|
|
4584
4601
|
} else if (typeof schema.items === "object" || typeof schema.items === "boolean") for (let idx = 0; idx < json.length; idx++) {
|
|
4585
4602
|
report.path.push(idx);
|
|
4586
4603
|
report.schemaPath.push("items");
|
|
4587
|
-
validate
|
|
4604
|
+
validate(ctx, report, schema.items, json[idx]);
|
|
4588
4605
|
report.schemaPath.pop();
|
|
4589
4606
|
report.path.pop();
|
|
4590
4607
|
}
|
|
4591
|
-
}
|
|
4592
|
-
|
|
4593
|
-
let additionalProperties = schema
|
|
4608
|
+
}
|
|
4609
|
+
function recurseObject(ctx, report, schema, json) {
|
|
4610
|
+
let { additionalProperties } = schema;
|
|
4594
4611
|
if (additionalProperties === true || additionalProperties === void 0) additionalProperties = {};
|
|
4595
4612
|
const p = schema.properties ? Object.keys(schema.properties) : [];
|
|
4596
4613
|
const pp = schema.patternProperties ? Object.keys(schema.patternProperties) : [];
|
|
4597
4614
|
const keys = Object.keys(json);
|
|
4615
|
+
const ppCompiled = [];
|
|
4616
|
+
for (let i = 0; i < pp.length; i++) {
|
|
4617
|
+
const r = compileSchemaRegex(pp[i]);
|
|
4618
|
+
if (r.ok) ppCompiled.push({
|
|
4619
|
+
key: pp[i],
|
|
4620
|
+
re: r.value
|
|
4621
|
+
});
|
|
4622
|
+
}
|
|
4598
4623
|
for (const m of keys) {
|
|
4599
4624
|
const propertyValue = json[m];
|
|
4625
|
+
const isProp = p.includes(m);
|
|
4600
4626
|
const s = [];
|
|
4601
|
-
if (
|
|
4602
|
-
for (
|
|
4603
|
-
const result = compileSchemaRegex(regexString);
|
|
4604
|
-
if (result.ok && result.value.test(m) === true) s.push(schema.patternProperties[regexString]);
|
|
4605
|
-
}
|
|
4627
|
+
if (isProp) s.push(schema.properties[m]);
|
|
4628
|
+
for (let i = 0; i < ppCompiled.length; i++) if (ppCompiled[i].re.test(m)) s.push(schema.patternProperties[ppCompiled[i].key]);
|
|
4606
4629
|
if (s.length === 0 && additionalProperties !== false) s.push(additionalProperties);
|
|
4607
4630
|
for (const schema_s of s) {
|
|
4608
4631
|
report.path.push(m);
|
|
4609
|
-
if (
|
|
4632
|
+
if (isProp) {
|
|
4610
4633
|
report.schemaPath.push("properties");
|
|
4611
4634
|
report.schemaPath.push(m);
|
|
4612
4635
|
} else report.schemaPath.push("additionalProperties");
|
|
4613
|
-
validate
|
|
4636
|
+
validate(ctx, report, schema_s, propertyValue);
|
|
4614
4637
|
report.path.pop();
|
|
4615
4638
|
report.schemaPath.pop();
|
|
4616
|
-
if (
|
|
4639
|
+
if (isProp) report.schemaPath.pop();
|
|
4617
4640
|
}
|
|
4618
4641
|
}
|
|
4619
|
-
}
|
|
4620
|
-
function validate(report, schema, json) {
|
|
4642
|
+
}
|
|
4643
|
+
function validate(ctx, report, schema, json) {
|
|
4621
4644
|
report.commonErrorMessage = "JSON_OBJECT_VALIDATION_FAILED";
|
|
4622
4645
|
if (schema === true) return true;
|
|
4623
4646
|
if (schema === false) {
|
|
@@ -4641,7 +4664,7 @@
|
|
|
4641
4664
|
let pushedDynamicScope = false;
|
|
4642
4665
|
const schemaId = getId(schema);
|
|
4643
4666
|
const dynamicScopeEntry = schema.__$resourceRoot || (isRoot || typeof schemaId === "string" ? schema : void 0);
|
|
4644
|
-
if (dynamicScopeEntry && dynamicScopeStack
|
|
4667
|
+
if (dynamicScopeEntry && dynamicScopeStack.at(-1) !== dynamicScopeEntry) {
|
|
4645
4668
|
dynamicScopeStack.push(dynamicScopeEntry);
|
|
4646
4669
|
pushedDynamicScope = true;
|
|
4647
4670
|
}
|
|
@@ -4649,10 +4672,11 @@
|
|
|
4649
4672
|
recursiveAnchorStack.push(schema);
|
|
4650
4673
|
pushedRecursiveAnchor = true;
|
|
4651
4674
|
}
|
|
4652
|
-
if (schema.$ref !== void 0) if (
|
|
4653
|
-
if (
|
|
4654
|
-
else
|
|
4655
|
-
|
|
4675
|
+
if (schema.$ref !== void 0) if (ctx.options.version === "draft2019-09" || ctx.options.version === "draft2020-12") {
|
|
4676
|
+
if (schema.__$refResolved) validate(ctx, report, schema.__$refResolved, json);
|
|
4677
|
+
else report.addError("REF_UNRESOLVED", [schema.$ref], void 0, schema);
|
|
4678
|
+
const refIdx = keys.indexOf("$ref");
|
|
4679
|
+
if (refIdx !== -1) keys.splice(refIdx, 1);
|
|
4656
4680
|
} else {
|
|
4657
4681
|
let maxRefs = 99;
|
|
4658
4682
|
while (schema.$ref && maxRefs > 0) {
|
|
@@ -4670,58 +4694,65 @@
|
|
|
4670
4694
|
report.schemaPath = [];
|
|
4671
4695
|
}
|
|
4672
4696
|
if (schema.$recursiveRef !== void 0) {
|
|
4673
|
-
if (
|
|
4697
|
+
if (ctx.options.version === "draft2019-09" || ctx.options.version === "draft2020-12") {
|
|
4674
4698
|
const recursiveRefTarget = resolveRecursiveRef(schema, recursiveAnchorStack);
|
|
4675
|
-
if (
|
|
4676
|
-
else
|
|
4677
|
-
|
|
4699
|
+
if (recursiveRefTarget) validate(ctx, report, recursiveRefTarget, json);
|
|
4700
|
+
else report.addError("REF_UNRESOLVED", [schema.$recursiveRef], void 0, schema);
|
|
4701
|
+
const recursiveRefIdx = keys.indexOf("$recursiveRef");
|
|
4702
|
+
if (recursiveRefIdx !== -1) keys.splice(recursiveRefIdx, 1);
|
|
4678
4703
|
}
|
|
4679
4704
|
}
|
|
4680
4705
|
if (schema.$dynamicRef !== void 0) {
|
|
4681
|
-
if (
|
|
4706
|
+
if (ctx.options.version === "draft2020-12") {
|
|
4682
4707
|
const dynamicRefTarget = resolveDynamicRef(schema, dynamicScopeStack);
|
|
4683
|
-
if (
|
|
4684
|
-
else validate
|
|
4685
|
-
|
|
4708
|
+
if (dynamicRefTarget === void 0) report.addError("REF_UNRESOLVED", [schema.$dynamicRef], void 0, schema);
|
|
4709
|
+
else validate(ctx, report, dynamicRefTarget, json);
|
|
4710
|
+
const dynamicRefIdx = keys.indexOf("$dynamicRef");
|
|
4711
|
+
if (dynamicRefIdx !== -1) keys.splice(dynamicRefIdx, 1);
|
|
4686
4712
|
}
|
|
4687
4713
|
}
|
|
4688
|
-
const validationVocabularyEnabled = isValidationVocabularyEnabled(schema, report,
|
|
4689
|
-
if (!validationVocabularyEnabled)
|
|
4714
|
+
const validationVocabularyEnabled = isValidationVocabularyEnabled(schema, report, ctx.options.version);
|
|
4715
|
+
if (!validationVocabularyEnabled) {
|
|
4716
|
+
let wi = 0;
|
|
4717
|
+
for (let ri = 0; ri < keys.length; ri++) if (!VALIDATION_VOCAB_KEYWORDS.has(keys[ri])) keys[wi++] = keys[ri];
|
|
4718
|
+
keys.length = wi;
|
|
4719
|
+
}
|
|
4690
4720
|
if (validationVocabularyEnabled && schema.type) {
|
|
4691
4721
|
keys.splice(keys.indexOf("type"), 1);
|
|
4692
4722
|
report.schemaPath.push("type");
|
|
4693
|
-
JsonValidators.type
|
|
4723
|
+
JsonValidators.type(ctx, report, schema, json);
|
|
4694
4724
|
report.schemaPath.pop();
|
|
4695
|
-
if (report.errors.length &&
|
|
4725
|
+
if (report.errors.length && ctx.options.breakOnFirstError) {
|
|
4696
4726
|
if (pushedRecursiveAnchor) recursiveAnchorStack.pop();
|
|
4697
4727
|
if (pushedDynamicScope) dynamicScopeStack.pop();
|
|
4698
4728
|
return false;
|
|
4699
4729
|
}
|
|
4700
4730
|
}
|
|
4701
4731
|
const deferredUnevaluatedKeys = [];
|
|
4702
|
-
for (
|
|
4732
|
+
for (let i = 0; i < keys.length; i++) {
|
|
4733
|
+
const key = keys[i];
|
|
4703
4734
|
if (key === "unevaluatedItems" || key === "unevaluatedProperties") {
|
|
4704
4735
|
deferredUnevaluatedKeys.push(key);
|
|
4705
4736
|
continue;
|
|
4706
4737
|
}
|
|
4707
4738
|
const validator = JsonValidators[key];
|
|
4708
4739
|
if (validator) {
|
|
4709
|
-
validator
|
|
4710
|
-
if (report.errors.length &&
|
|
4740
|
+
validator(ctx, report, schema, json);
|
|
4741
|
+
if (report.errors.length && ctx.options.breakOnFirstError) break;
|
|
4711
4742
|
}
|
|
4712
4743
|
}
|
|
4713
|
-
if (deferredUnevaluatedKeys.length > 0 && !(report.errors.length > 0 &&
|
|
4714
|
-
const validator = JsonValidators[
|
|
4744
|
+
if (deferredUnevaluatedKeys.length > 0 && !(report.errors.length > 0 && ctx.options.breakOnFirstError)) for (let i = 0; i < deferredUnevaluatedKeys.length; i++) {
|
|
4745
|
+
const validator = JsonValidators[deferredUnevaluatedKeys[i]];
|
|
4715
4746
|
if (validator) {
|
|
4716
|
-
validator
|
|
4717
|
-
if (report.errors.length &&
|
|
4747
|
+
validator(ctx, report, schema, json);
|
|
4748
|
+
if (report.errors.length && ctx.options.breakOnFirstError) break;
|
|
4718
4749
|
}
|
|
4719
4750
|
}
|
|
4720
|
-
if (report.errors.length === 0 ||
|
|
4721
|
-
if (Array.isArray(json)) recurseArray
|
|
4722
|
-
else if (isObject(json)) recurseObject
|
|
4751
|
+
if (report.errors.length === 0 || ctx.options.breakOnFirstError === false) {
|
|
4752
|
+
if (Array.isArray(json)) recurseArray(ctx, report, schema, json);
|
|
4753
|
+
else if (isObject(json)) recurseObject(ctx, report, schema, json);
|
|
4723
4754
|
}
|
|
4724
|
-
if (typeof
|
|
4755
|
+
if (typeof ctx.options.customValidator === "function") ctx.options.customValidator.call(ctx, report, schema, json);
|
|
4725
4756
|
if (pushedRecursiveAnchor) recursiveAnchorStack.pop();
|
|
4726
4757
|
if (pushedDynamicScope) dynamicScopeStack.pop();
|
|
4727
4758
|
if (isRoot) report.rootSchema = void 0;
|
|
@@ -4738,14 +4769,14 @@
|
|
|
4738
4769
|
}
|
|
4739
4770
|
//#endregion
|
|
4740
4771
|
//#region src/schema-compiler.ts
|
|
4741
|
-
const UNSAFE_TARGETS = [
|
|
4772
|
+
const UNSAFE_TARGETS = new Set([
|
|
4742
4773
|
Object.prototype,
|
|
4743
4774
|
Function.prototype,
|
|
4744
4775
|
Array.prototype
|
|
4745
|
-
];
|
|
4776
|
+
]);
|
|
4746
4777
|
/** Returns true if `obj` is a built-in prototype that must not be mutated. */
|
|
4747
4778
|
function isUnsafeTarget(obj) {
|
|
4748
|
-
return UNSAFE_TARGETS.
|
|
4779
|
+
return UNSAFE_TARGETS.has(obj);
|
|
4749
4780
|
}
|
|
4750
4781
|
/** Safely assign a property on `obj`, refusing prototype-polluting keys. */
|
|
4751
4782
|
function safeSetProperty(obj, key, value) {
|
|
@@ -4758,35 +4789,78 @@
|
|
|
4758
4789
|
if (isUnsafeTarget(obj)) return;
|
|
4759
4790
|
if (key !== "__proto__" && key !== "constructor" && key !== "prototype") delete obj[key];
|
|
4760
4791
|
}
|
|
4792
|
+
const resolveReference = (base, ref) => {
|
|
4793
|
+
if (isAbsoluteUri(ref)) return ref;
|
|
4794
|
+
const baseStr = base ?? "";
|
|
4795
|
+
if (ref.startsWith("#")) {
|
|
4796
|
+
const hashIndex = baseStr.indexOf("#");
|
|
4797
|
+
return (hashIndex === -1 ? baseStr : baseStr.slice(0, hashIndex)) + ref;
|
|
4798
|
+
}
|
|
4799
|
+
if (!baseStr) return ref;
|
|
4800
|
+
const hashIndex = baseStr.indexOf("#");
|
|
4801
|
+
const baseNoFrag = hashIndex === -1 ? baseStr : baseStr.slice(0, hashIndex);
|
|
4802
|
+
if (isAbsoluteUri(baseNoFrag)) try {
|
|
4803
|
+
return new URL(ref, baseNoFrag).toString();
|
|
4804
|
+
} catch {}
|
|
4805
|
+
let baseDir = baseNoFrag;
|
|
4806
|
+
if (!baseDir.endsWith("/")) {
|
|
4807
|
+
const lastSlash = baseDir.lastIndexOf("/");
|
|
4808
|
+
baseDir = lastSlash === -1 ? "" : baseDir.slice(0, lastSlash + 1);
|
|
4809
|
+
}
|
|
4810
|
+
return baseDir + ref;
|
|
4811
|
+
};
|
|
4812
|
+
const isSimpleIdentifier = (id) => !id.startsWith("#") && !id.includes("/") && !id.includes(".") && !id.includes("#");
|
|
4813
|
+
const resolveIdScope = (base, id) => {
|
|
4814
|
+
if (isAbsoluteUri(id)) return id;
|
|
4815
|
+
const baseStr = base ?? "";
|
|
4816
|
+
if (isSimpleIdentifier(id)) {
|
|
4817
|
+
const hashIndex = baseStr.indexOf("#");
|
|
4818
|
+
return `${hashIndex === -1 ? baseStr : baseStr.slice(0, hashIndex)}#${id}`;
|
|
4819
|
+
}
|
|
4820
|
+
return resolveReference(base, id);
|
|
4821
|
+
};
|
|
4822
|
+
const resolveSchemaScopeId = (base, schema, id) => {
|
|
4823
|
+
if (typeof schema.$id === "string") return resolveReference(base, id);
|
|
4824
|
+
return resolveIdScope(base, id);
|
|
4825
|
+
};
|
|
4761
4826
|
const collectIds = (obj, maxDepth = 100) => {
|
|
4762
4827
|
const ids = [];
|
|
4763
4828
|
function walk(node, scope, _depth = 0) {
|
|
4764
4829
|
if (typeof node !== "object" || node == null) return;
|
|
4830
|
+
const schemaNode = node;
|
|
4765
4831
|
if (_depth >= maxDepth) throw new Error(`Maximum recursion depth (${maxDepth}) exceeded in collectIds. If your schema is deeply nested and valid, increase the maxRecursionDepth option.`);
|
|
4766
4832
|
let addedScope = false;
|
|
4767
|
-
const nodeId = getId(
|
|
4833
|
+
const nodeId = getId(schemaNode);
|
|
4768
4834
|
if (typeof nodeId === "string") {
|
|
4769
4835
|
let type = isAbsoluteUri(nodeId) ? "absolute" : "relative";
|
|
4770
4836
|
if (scope.length === 0) type = "root";
|
|
4771
4837
|
const id = {
|
|
4772
4838
|
id: nodeId,
|
|
4773
4839
|
type,
|
|
4774
|
-
obj:
|
|
4840
|
+
obj: schemaNode
|
|
4775
4841
|
};
|
|
4776
4842
|
if (type === "absolute" || type === "root" && isAbsoluteUri(nodeId)) id.absoluteUri = nodeId;
|
|
4777
|
-
else if (type === "root" && typeof
|
|
4843
|
+
else if (type === "root" && typeof schemaNode.id === "string" && isAbsoluteUri(schemaNode.id) && schemaNode.id !== nodeId) id.absoluteUri = resolveSchemaScopeId(schemaNode.id, schemaNode, nodeId);
|
|
4778
4844
|
else if (type === "relative") {
|
|
4779
|
-
|
|
4780
|
-
|
|
4845
|
+
let absoluteParent;
|
|
4846
|
+
for (let i = scope.length - 1; i >= 0; i--) {
|
|
4847
|
+
const sc = scope[i];
|
|
4848
|
+
if (sc.type === "absolute" || sc.type === "root" && sc.absoluteUri) {
|
|
4849
|
+
absoluteParent = sc;
|
|
4850
|
+
break;
|
|
4851
|
+
}
|
|
4852
|
+
}
|
|
4853
|
+
id.absoluteParent = absoluteParent;
|
|
4854
|
+
if (id.absoluteParent) id.absoluteUri = resolveSchemaScopeId(id.absoluteParent.absoluteUri || id.absoluteParent.id, schemaNode, id.id);
|
|
4781
4855
|
}
|
|
4782
4856
|
ids.push(id);
|
|
4783
4857
|
scope.push(id);
|
|
4784
4858
|
addedScope = true;
|
|
4785
4859
|
}
|
|
4786
4860
|
if (Array.isArray(node)) for (const item of node) walk(item, scope, _depth + 1);
|
|
4787
|
-
else for (const key of Object.keys(
|
|
4788
|
-
if (isInternalKey(key) ||
|
|
4789
|
-
walk(
|
|
4861
|
+
else for (const key of Object.keys(schemaNode)) {
|
|
4862
|
+
if (isInternalKey(key) || NON_SCHEMA_KEYWORDS_SET.has(key)) continue;
|
|
4863
|
+
walk(schemaNode[key], scope, _depth + 1);
|
|
4790
4864
|
}
|
|
4791
4865
|
if (addedScope) scope.pop();
|
|
4792
4866
|
}
|
|
@@ -4794,42 +4868,42 @@
|
|
|
4794
4868
|
return ids;
|
|
4795
4869
|
};
|
|
4796
4870
|
const collectReferences = (obj, results, scope, path, options, maxDepth = 100, _depth = 0) => {
|
|
4797
|
-
results
|
|
4798
|
-
scope
|
|
4799
|
-
path
|
|
4800
|
-
options
|
|
4871
|
+
results ||= [];
|
|
4872
|
+
scope ||= [];
|
|
4873
|
+
path ||= [];
|
|
4874
|
+
options ||= {};
|
|
4801
4875
|
if (typeof obj !== "object" || obj === null) return results;
|
|
4802
4876
|
if (_depth >= maxDepth) throw new Error(`Maximum recursion depth (${maxDepth}) exceeded in collectReferences. If your schema is deeply nested and valid, increase the maxRecursionDepth option.`);
|
|
4803
|
-
const hasRef = typeof obj.$ref === "string" &&
|
|
4877
|
+
const hasRef = typeof obj.$ref === "string" && obj.__$refResolved === void 0;
|
|
4804
4878
|
let addedScope = false;
|
|
4805
4879
|
const isRootScope = scope.length === 0;
|
|
4806
4880
|
let scopeId = getId(obj);
|
|
4807
4881
|
if (typeof obj.id === "string" && isAbsoluteUri(obj.id) && (!scopeId || !isAbsoluteUri(scopeId))) scopeId = obj.id;
|
|
4808
4882
|
if (typeof scopeId === "string" && (isRootScope || !hasRef || options.useRefObjectScope === true)) {
|
|
4809
|
-
const base = scope.length > 0 ? scope
|
|
4883
|
+
const base = scope.length > 0 ? scope.at(-1) : void 0;
|
|
4810
4884
|
scope.push(resolveSchemaScopeId(base, obj, scopeId));
|
|
4811
4885
|
addedScope = true;
|
|
4812
4886
|
}
|
|
4813
4887
|
if (hasRef) results.push({
|
|
4814
|
-
ref: resolveReference(scope
|
|
4888
|
+
ref: resolveReference(scope.at(-1), obj.$ref),
|
|
4815
4889
|
key: "$ref",
|
|
4816
4890
|
obj,
|
|
4817
4891
|
path: path.slice(0)
|
|
4818
4892
|
});
|
|
4819
|
-
if (typeof obj.$recursiveRef === "string" &&
|
|
4820
|
-
ref: resolveReference(scope
|
|
4893
|
+
if (typeof obj.$recursiveRef === "string" && obj.__$recursiveRefResolved === void 0) results.push({
|
|
4894
|
+
ref: resolveReference(scope.at(-1), obj.$recursiveRef),
|
|
4821
4895
|
key: "$recursiveRef",
|
|
4822
4896
|
obj,
|
|
4823
4897
|
path: path.slice(0)
|
|
4824
4898
|
});
|
|
4825
|
-
if (typeof obj.$dynamicRef === "string" &&
|
|
4826
|
-
ref: resolveReference(scope
|
|
4899
|
+
if (typeof obj.$dynamicRef === "string" && obj.__$dynamicRefResolved === void 0) results.push({
|
|
4900
|
+
ref: resolveReference(scope.at(-1), obj.$dynamicRef),
|
|
4827
4901
|
key: "$dynamicRef",
|
|
4828
4902
|
obj,
|
|
4829
4903
|
path: path.slice(0)
|
|
4830
4904
|
});
|
|
4831
|
-
if (typeof obj.$schema === "string" &&
|
|
4832
|
-
ref: resolveReference(scope
|
|
4905
|
+
if (typeof obj.$schema === "string" && obj.__$schemaResolved === void 0) results.push({
|
|
4906
|
+
ref: resolveReference(scope.at(-1), obj.$schema),
|
|
4833
4907
|
key: "$schema",
|
|
4834
4908
|
obj,
|
|
4835
4909
|
path: path.slice(0)
|
|
@@ -4842,7 +4916,7 @@
|
|
|
4842
4916
|
else {
|
|
4843
4917
|
const keys = Object.keys(obj);
|
|
4844
4918
|
for (const key of keys) {
|
|
4845
|
-
if (isInternalKey(key) ||
|
|
4919
|
+
if (isInternalKey(key) || NON_SCHEMA_KEYWORDS_SET.has(key)) continue;
|
|
4846
4920
|
path.push(key);
|
|
4847
4921
|
collectReferences(obj[key], results, scope, path, options, maxDepth, _depth + 1);
|
|
4848
4922
|
path.pop();
|
|
@@ -4851,41 +4925,8 @@
|
|
|
4851
4925
|
if (addedScope) scope.pop();
|
|
4852
4926
|
return results;
|
|
4853
4927
|
};
|
|
4854
|
-
const resolveReference = (base, ref) => {
|
|
4855
|
-
if (isAbsoluteUri(ref)) return ref;
|
|
4856
|
-
const baseStr = base ?? "";
|
|
4857
|
-
if (ref[0] === "#") {
|
|
4858
|
-
const hashIndex = baseStr.indexOf("#");
|
|
4859
|
-
return (hashIndex === -1 ? baseStr : baseStr.slice(0, hashIndex)) + ref;
|
|
4860
|
-
}
|
|
4861
|
-
if (!baseStr) return ref;
|
|
4862
|
-
const hashIndex = baseStr.indexOf("#");
|
|
4863
|
-
const baseNoFrag = hashIndex === -1 ? baseStr : baseStr.slice(0, hashIndex);
|
|
4864
|
-
if (isAbsoluteUri(baseNoFrag)) try {
|
|
4865
|
-
return new URL(ref, baseNoFrag).toString();
|
|
4866
|
-
} catch {}
|
|
4867
|
-
let baseDir = baseNoFrag;
|
|
4868
|
-
if (!baseDir.endsWith("/")) {
|
|
4869
|
-
const lastSlash = baseDir.lastIndexOf("/");
|
|
4870
|
-
baseDir = lastSlash === -1 ? "" : baseDir.slice(0, lastSlash + 1);
|
|
4871
|
-
}
|
|
4872
|
-
return baseDir + ref;
|
|
4873
|
-
};
|
|
4874
|
-
const isSimpleIdentifier = (id) => id[0] !== "#" && !id.includes("/") && !id.includes(".") && !id.includes("#");
|
|
4875
|
-
const resolveIdScope = (base, id) => {
|
|
4876
|
-
if (isAbsoluteUri(id)) return id;
|
|
4877
|
-
const baseStr = base ?? "";
|
|
4878
|
-
if (isSimpleIdentifier(id)) {
|
|
4879
|
-
const hashIndex = baseStr.indexOf("#");
|
|
4880
|
-
return (hashIndex === -1 ? baseStr : baseStr.slice(0, hashIndex)) + "#" + id;
|
|
4881
|
-
}
|
|
4882
|
-
return resolveReference(base, id);
|
|
4883
|
-
};
|
|
4884
|
-
const resolveSchemaScopeId = (base, schema, id) => {
|
|
4885
|
-
if (typeof schema.$id === "string") return resolveReference(base, id);
|
|
4886
|
-
return resolveIdScope(base, id);
|
|
4887
|
-
};
|
|
4888
4928
|
var SchemaCompiler = class {
|
|
4929
|
+
validator;
|
|
4889
4930
|
constructor(validator) {
|
|
4890
4931
|
this.validator = validator;
|
|
4891
4932
|
}
|
|
@@ -4903,19 +4944,19 @@
|
|
|
4903
4944
|
report.commonErrorMessage = "SCHEMA_COMPILATION_FAILED";
|
|
4904
4945
|
if (typeof schema === "string") {
|
|
4905
4946
|
const loadedSchema = this.validator.scache.getSchemaByUri(report, schema);
|
|
4906
|
-
if (
|
|
4947
|
+
if (loadedSchema === void 0) {
|
|
4907
4948
|
report.addError("SCHEMA_NOT_REACHABLE", [schema]);
|
|
4908
4949
|
return false;
|
|
4909
4950
|
}
|
|
4910
4951
|
schema = loadedSchema;
|
|
4911
4952
|
}
|
|
4912
4953
|
if (Array.isArray(schema)) {
|
|
4913
|
-
if (!options?.noCache) schema.
|
|
4954
|
+
if (!options?.noCache) for (let i = 0; i < schema.length; i++) this.collectAndCacheIds(schema[i]);
|
|
4914
4955
|
return this.compileArrayOfSchemas(report, schema);
|
|
4915
4956
|
} else if (typeof schema === "boolean") return true;
|
|
4916
|
-
|
|
4957
|
+
if (!options?.noCache) this.collectAndCacheIds(schema);
|
|
4917
4958
|
const canMutateSchemaObject = schema !== Object.prototype && schema !== Function.prototype && schema !== Array.prototype;
|
|
4918
|
-
if (canMutateSchemaObject && schema.__$compiled && schema.id && this.validator.scache.checkCacheForUri(schema.id)
|
|
4959
|
+
if (canMutateSchemaObject && schema.__$compiled && schema.id && !this.validator.scache.checkCacheForUri(schema.id)) schema.__$compiled = void 0;
|
|
4919
4960
|
if (schema.__$compiled) return true;
|
|
4920
4961
|
if (canMutateSchemaObject && !schema.$schema && this.validator.options.version !== "none") schema.$schema = this.validator.getDefaultSchemaId();
|
|
4921
4962
|
if (schema.id && typeof schema.id === "string" && !options?.noCache) this.validator.scache.cacheSchemaByUri(schema.id, schema);
|
|
@@ -4930,7 +4971,7 @@
|
|
|
4930
4971
|
const refs = collectReferences(schema, void 0, void 0, void 0, { useRefObjectScope }, this.validator.options.maxRecursionDepth);
|
|
4931
4972
|
for (const refObj of refs) {
|
|
4932
4973
|
let response = this.validator.scache.getSchemaByUri(report, refObj.ref, schema);
|
|
4933
|
-
if (
|
|
4974
|
+
if (response === void 0) {
|
|
4934
4975
|
const schemaReader = getSchemaReader();
|
|
4935
4976
|
if (schemaReader) {
|
|
4936
4977
|
const remotePath = getRemotePath(refObj.ref);
|
|
@@ -4938,23 +4979,24 @@
|
|
|
4938
4979
|
if (s) {
|
|
4939
4980
|
s.id = remotePath;
|
|
4940
4981
|
const subreport = new Report(report);
|
|
4941
|
-
if (
|
|
4942
|
-
else
|
|
4982
|
+
if (this.compileSchema(subreport, s)) response = this.validator.scache.getSchemaByUri(report, refObj.ref, schema);
|
|
4983
|
+
else for (let i = 0; i < subreport.errors.length; i++) report.errors.push(subreport.errors[i]);
|
|
4943
4984
|
}
|
|
4944
4985
|
}
|
|
4945
4986
|
}
|
|
4946
|
-
if (
|
|
4987
|
+
if (response === void 0) {
|
|
4947
4988
|
const hasNotValid = report.hasError("REMOTE_NOT_VALID", [refObj.ref]);
|
|
4948
4989
|
const isAbsolute = isAbsoluteUri(refObj.ref);
|
|
4949
4990
|
let isDownloaded = false;
|
|
4950
4991
|
const ignoreUnresolvableRemotes = this.validator.options.ignoreUnresolvableReferences === true;
|
|
4951
4992
|
if (isAbsolute) isDownloaded = this.validator.scache.checkCacheForUri(refObj.ref);
|
|
4952
4993
|
if (hasNotValid) {} else if (ignoreUnresolvableRemotes && isAbsolute) {} else if (isDownloaded) {} else {
|
|
4953
|
-
|
|
4994
|
+
const pathLen = refObj.path.length;
|
|
4995
|
+
for (let i = 0; i < pathLen; i++) report.path.push(refObj.path[i]);
|
|
4954
4996
|
report.addError("UNRESOLVABLE_REFERENCE", [refObj.ref]);
|
|
4955
|
-
report.path
|
|
4997
|
+
report.path.length -= pathLen;
|
|
4956
4998
|
if (isValidExceptReferences && canMutateSchemaObject && !isUnsafeTarget(schema)) {
|
|
4957
|
-
schema.__$missingReferences
|
|
4999
|
+
schema.__$missingReferences ||= [];
|
|
4958
5000
|
schema.__$missingReferences.push(refObj);
|
|
4959
5001
|
}
|
|
4960
5002
|
}
|
|
@@ -4969,13 +5011,20 @@
|
|
|
4969
5011
|
compileArrayOfSchemas(report, arr) {
|
|
4970
5012
|
let compiled = 0, lastLoopCompiled;
|
|
4971
5013
|
do {
|
|
4972
|
-
|
|
5014
|
+
let wi = 0;
|
|
5015
|
+
for (let ri = 0; ri < report.errors.length; ri++) if (report.errors[ri].code !== "UNRESOLVABLE_REFERENCE") report.errors[wi++] = report.errors[ri];
|
|
5016
|
+
report.errors.length = wi;
|
|
4973
5017
|
lastLoopCompiled = compiled;
|
|
4974
5018
|
compiled = this.compileArrayOfSchemasLoop(report, arr);
|
|
5019
|
+
const idMap = /* @__PURE__ */ new Map();
|
|
5020
|
+
for (let i = 0; i < arr.length; i++) {
|
|
5021
|
+
const schemaId = arr[i].id;
|
|
5022
|
+
if (schemaId && !idMap.has(schemaId)) idMap.set(schemaId, arr[i]);
|
|
5023
|
+
}
|
|
4975
5024
|
for (const sch of arr) if (sch.__$missingReferences) {
|
|
4976
5025
|
for (let idx2 = sch.__$missingReferences.length - 1; idx2 >= 0; idx2--) {
|
|
4977
5026
|
const refObj = sch.__$missingReferences[idx2];
|
|
4978
|
-
const response =
|
|
5027
|
+
const response = idMap.get(refObj.ref);
|
|
4979
5028
|
if (response) {
|
|
4980
5029
|
safeSetProperty(refObj.obj, `__${refObj.key}Resolved`, response);
|
|
4981
5030
|
sch.__$missingReferences.splice(idx2, 1);
|
|
@@ -4991,62 +5040,74 @@
|
|
|
4991
5040
|
for (const schema of arr) {
|
|
4992
5041
|
const report = new Report(mainReport);
|
|
4993
5042
|
if (this.compileSchema(report, schema)) compiledCount++;
|
|
4994
|
-
|
|
5043
|
+
for (let i = 0; i < report.errors.length; i++) mainReport.errors.push(report.errors[i]);
|
|
4995
5044
|
}
|
|
4996
5045
|
return compiledCount;
|
|
4997
5046
|
}
|
|
4998
5047
|
};
|
|
4999
5048
|
//#endregion
|
|
5000
5049
|
//#region src/schema-validator.ts
|
|
5050
|
+
const PRIMITIVE_TYPES = [
|
|
5051
|
+
"array",
|
|
5052
|
+
"boolean",
|
|
5053
|
+
"integer",
|
|
5054
|
+
"number",
|
|
5055
|
+
"null",
|
|
5056
|
+
"object",
|
|
5057
|
+
"string"
|
|
5058
|
+
];
|
|
5059
|
+
const PRIMITIVE_TYPE_STR = PRIMITIVE_TYPES.join(",");
|
|
5060
|
+
const PRIMITIVE_TYPES_SET = new Set(PRIMITIVE_TYPES);
|
|
5001
5061
|
const SchemaValidators = {
|
|
5002
|
-
$ref
|
|
5062
|
+
$ref(report, schema) {
|
|
5003
5063
|
if (typeof schema.$ref !== "string") report.addError("KEYWORD_TYPE_EXPECTED", ["$ref", "string"], void 0, schema, "$ref");
|
|
5004
5064
|
},
|
|
5005
|
-
$schema
|
|
5065
|
+
$schema(report, schema) {
|
|
5006
5066
|
if (typeof schema.$schema !== "string") report.addError("KEYWORD_TYPE_EXPECTED", ["$schema", "string"], void 0, schema, "$schema");
|
|
5007
5067
|
},
|
|
5008
|
-
multipleOf
|
|
5068
|
+
multipleOf(report, schema) {
|
|
5009
5069
|
if (typeof schema.multipleOf !== "number") report.addError("KEYWORD_TYPE_EXPECTED", ["multipleOf", "number"], void 0, schema, "multipleOf");
|
|
5010
5070
|
else if (schema.multipleOf <= 0) report.addError("KEYWORD_MUST_BE", ["multipleOf", "strictly greater than 0"], void 0, schema, "multipleOf");
|
|
5011
5071
|
},
|
|
5012
|
-
maximum
|
|
5072
|
+
maximum(report, schema) {
|
|
5013
5073
|
if (typeof schema.maximum !== "number") report.addError("KEYWORD_TYPE_EXPECTED", ["maximum", "number"], void 0, schema, "maximum");
|
|
5014
5074
|
},
|
|
5015
|
-
exclusiveMaximum
|
|
5075
|
+
exclusiveMaximum(report, schema) {
|
|
5016
5076
|
if (report.options.version === "draft-04") {
|
|
5017
5077
|
if (typeof schema.exclusiveMaximum !== "boolean") report.addError("KEYWORD_TYPE_EXPECTED", ["exclusiveMaximum", "boolean"], void 0, schema, "exclusiveMaximum");
|
|
5018
5078
|
else if (schema.maximum === void 0) report.addError("KEYWORD_DEPENDENCY", ["exclusiveMaximum", "maximum"], void 0, schema, "exclusiveMaximum");
|
|
5019
5079
|
} else if (typeof schema.exclusiveMaximum !== "boolean" && typeof schema.exclusiveMaximum !== "number") report.addError("KEYWORD_TYPE_EXPECTED", ["exclusiveMaximum", ["boolean", "number"]], void 0, schema, "exclusiveMaximum");
|
|
5020
5080
|
},
|
|
5021
|
-
minimum
|
|
5081
|
+
minimum(report, schema) {
|
|
5022
5082
|
if (typeof schema.minimum !== "number") report.addError("KEYWORD_TYPE_EXPECTED", ["minimum", "number"], void 0, schema, "minimum");
|
|
5023
5083
|
},
|
|
5024
|
-
exclusiveMinimum
|
|
5084
|
+
exclusiveMinimum(report, schema) {
|
|
5025
5085
|
if (report.options.version === "draft-04") {
|
|
5026
5086
|
if (typeof schema.exclusiveMinimum !== "boolean") report.addError("KEYWORD_TYPE_EXPECTED", ["exclusiveMinimum", "boolean"], void 0, schema, "exclusiveMinimum");
|
|
5027
5087
|
else if (schema.minimum === void 0) report.addError("KEYWORD_DEPENDENCY", ["exclusiveMinimum", "minimum"], void 0, schema, "exclusiveMinimum");
|
|
5028
5088
|
} else if (typeof schema.exclusiveMinimum !== "boolean" && typeof schema.exclusiveMinimum !== "number") report.addError("KEYWORD_TYPE_EXPECTED", ["exclusiveMinimum", ["boolean", "number"]], void 0, schema, "exclusiveMinimum");
|
|
5029
5089
|
},
|
|
5030
|
-
maxLength
|
|
5090
|
+
maxLength(report, schema) {
|
|
5031
5091
|
if (!isInteger(schema.maxLength)) report.addError("KEYWORD_TYPE_EXPECTED", ["maxLength", "integer"], void 0, schema, "maxLength");
|
|
5032
5092
|
else if (schema.maxLength < 0) report.addError("KEYWORD_MUST_BE", ["maxLength", "greater than, or equal to 0"], void 0, schema, "maxLength");
|
|
5033
5093
|
},
|
|
5034
|
-
minLength
|
|
5094
|
+
minLength(report, schema) {
|
|
5035
5095
|
if (!isInteger(schema.minLength)) report.addError("KEYWORD_TYPE_EXPECTED", ["minLength", "integer"], void 0, schema, "minLength");
|
|
5036
5096
|
else if (schema.minLength < 0) report.addError("KEYWORD_MUST_BE", ["minLength", "greater than, or equal to 0"], void 0, schema, "minLength");
|
|
5037
5097
|
},
|
|
5038
|
-
pattern
|
|
5039
|
-
if (typeof schema.pattern !== "string")
|
|
5040
|
-
|
|
5041
|
-
|
|
5042
|
-
if (!result.ok) report.addError("KEYWORD_PATTERN", [
|
|
5043
|
-
"pattern",
|
|
5044
|
-
schema.pattern,
|
|
5045
|
-
result.error.message
|
|
5046
|
-
], void 0, schema, "pattern");
|
|
5098
|
+
pattern(report, schema) {
|
|
5099
|
+
if (typeof schema.pattern !== "string") {
|
|
5100
|
+
report.addError("KEYWORD_TYPE_EXPECTED", ["pattern", "string"], void 0, schema, "pattern");
|
|
5101
|
+
return;
|
|
5047
5102
|
}
|
|
5103
|
+
const result = compileSchemaRegex(schema.pattern);
|
|
5104
|
+
if (!result.ok) report.addError("KEYWORD_PATTERN", [
|
|
5105
|
+
"pattern",
|
|
5106
|
+
schema.pattern,
|
|
5107
|
+
result.error.message
|
|
5108
|
+
], void 0, schema, "pattern");
|
|
5048
5109
|
},
|
|
5049
|
-
additionalItems
|
|
5110
|
+
additionalItems(report, schema) {
|
|
5050
5111
|
if (typeof schema.additionalItems !== "boolean" && !isObject(schema.additionalItems)) report.addError("KEYWORD_TYPE_EXPECTED", ["additionalItems", ["boolean", "object"]], void 0, schema, "additionalItems");
|
|
5051
5112
|
else if (isObject(schema.additionalItems)) {
|
|
5052
5113
|
report.path.push("additionalItems");
|
|
@@ -5054,7 +5115,7 @@
|
|
|
5054
5115
|
report.path.pop();
|
|
5055
5116
|
}
|
|
5056
5117
|
},
|
|
5057
|
-
items
|
|
5118
|
+
items(report, schema) {
|
|
5058
5119
|
if (Array.isArray(schema.items)) for (let idx = 0; idx < schema.items.length; idx++) {
|
|
5059
5120
|
report.path.push("items");
|
|
5060
5121
|
report.path.push(idx);
|
|
@@ -5074,34 +5135,34 @@
|
|
|
5074
5135
|
if (this.options.forceAdditional === true && schema.additionalItems === void 0 && Array.isArray(schema.items)) report.addError("KEYWORD_UNDEFINED_STRICT", ["additionalItems"], void 0, schema, "additionalItems");
|
|
5075
5136
|
if (this.options.assumeAdditional && schema.additionalItems === void 0 && Array.isArray(schema.items)) schema.additionalItems = false;
|
|
5076
5137
|
},
|
|
5077
|
-
maxItems
|
|
5138
|
+
maxItems(report, schema) {
|
|
5078
5139
|
if (typeof schema.maxItems !== "number") report.addError("KEYWORD_TYPE_EXPECTED", ["maxItems", "integer"], void 0, schema, "maxItems");
|
|
5079
5140
|
else if (schema.maxItems < 0) report.addError("KEYWORD_MUST_BE", ["maxItems", "greater than, or equal to 0"], void 0, schema, "maxItems");
|
|
5080
5141
|
},
|
|
5081
|
-
minItems
|
|
5142
|
+
minItems(report, schema) {
|
|
5082
5143
|
if (!isInteger(schema.minItems)) report.addError("KEYWORD_TYPE_EXPECTED", ["minItems", "integer"], void 0, schema, "minItems");
|
|
5083
5144
|
else if (schema.minItems < 0) report.addError("KEYWORD_MUST_BE", ["minItems", "greater than, or equal to 0"], void 0, schema, "minItems");
|
|
5084
5145
|
},
|
|
5085
|
-
uniqueItems
|
|
5146
|
+
uniqueItems(report, schema) {
|
|
5086
5147
|
if (typeof schema.uniqueItems !== "boolean") report.addError("KEYWORD_TYPE_EXPECTED", ["uniqueItems", "boolean"], void 0, schema, "uniqueItems");
|
|
5087
5148
|
},
|
|
5088
|
-
maxProperties
|
|
5149
|
+
maxProperties(report, schema) {
|
|
5089
5150
|
if (!isInteger(schema.maxProperties)) report.addError("KEYWORD_TYPE_EXPECTED", ["maxProperties", "integer"], void 0, schema, "maxProperties");
|
|
5090
5151
|
else if (schema.maxProperties < 0) report.addError("KEYWORD_MUST_BE", ["maxProperties", "greater than, or equal to 0"], void 0, schema, "maxProperties");
|
|
5091
5152
|
},
|
|
5092
|
-
minProperties
|
|
5153
|
+
minProperties(report, schema) {
|
|
5093
5154
|
if (!isInteger(schema.minProperties)) report.addError("KEYWORD_TYPE_EXPECTED", ["minProperties", "integer"], void 0, schema, "minProperties");
|
|
5094
5155
|
else if (schema.minProperties < 0) report.addError("KEYWORD_MUST_BE", ["minProperties", "greater than, or equal to 0"], void 0, schema, "minProperties");
|
|
5095
5156
|
},
|
|
5096
|
-
required
|
|
5157
|
+
required(report, schema) {
|
|
5097
5158
|
if (!Array.isArray(schema.required)) report.addError("KEYWORD_TYPE_EXPECTED", ["required", "array"], void 0, schema, "required");
|
|
5098
5159
|
else if (report.options.version === "draft-04" && schema.required.length === 0) report.addError("KEYWORD_MUST_BE", ["required", "an array with at least one element"], void 0, schema, "required");
|
|
5099
5160
|
else {
|
|
5100
5161
|
for (const item of schema.required) if (typeof item !== "string") report.addError("KEYWORD_VALUE_TYPE", ["required", "string"], void 0, schema, "required");
|
|
5101
|
-
if (isUniqueArray(schema.required)
|
|
5162
|
+
if (!isUniqueArray(schema.required)) report.addError("KEYWORD_MUST_BE", ["required", "an array with unique items"], void 0, schema, "required");
|
|
5102
5163
|
}
|
|
5103
5164
|
},
|
|
5104
|
-
additionalProperties
|
|
5165
|
+
additionalProperties(report, schema) {
|
|
5105
5166
|
if (typeof schema.additionalProperties !== "boolean" && !isObject(schema.additionalProperties)) report.addError("KEYWORD_TYPE_EXPECTED", ["additionalProperties", ["boolean", "object"]], void 0, schema, "additionalProperties");
|
|
5106
5167
|
else if (isObject(schema.additionalProperties)) {
|
|
5107
5168
|
report.path.push("additionalProperties");
|
|
@@ -5109,7 +5170,7 @@
|
|
|
5109
5170
|
report.path.pop();
|
|
5110
5171
|
}
|
|
5111
5172
|
},
|
|
5112
|
-
properties
|
|
5173
|
+
properties(report, schema) {
|
|
5113
5174
|
if (!isObject(schema.properties)) {
|
|
5114
5175
|
report.addError("KEYWORD_TYPE_EXPECTED", ["properties", "object"], void 0, schema, "properties");
|
|
5115
5176
|
return;
|
|
@@ -5127,7 +5188,7 @@
|
|
|
5127
5188
|
if (this.options.assumeAdditional && schema.additionalProperties === void 0) schema.additionalProperties = false;
|
|
5128
5189
|
if (this.options.forceProperties === true && keys.length === 0) report.addError("CUSTOM_MODE_FORCE_PROPERTIES", ["properties"], void 0, schema, "properties");
|
|
5129
5190
|
},
|
|
5130
|
-
patternProperties
|
|
5191
|
+
patternProperties(report, schema) {
|
|
5131
5192
|
if (!isObject(schema.patternProperties)) {
|
|
5132
5193
|
report.addError("KEYWORD_TYPE_EXPECTED", ["patternProperties", "object"], void 0, schema, "patternProperties");
|
|
5133
5194
|
return;
|
|
@@ -5149,93 +5210,52 @@
|
|
|
5149
5210
|
}
|
|
5150
5211
|
if (this.options.forceProperties === true && keys.length === 0) report.addError("CUSTOM_MODE_FORCE_PROPERTIES", ["patternProperties"], void 0, schema, "patternProperties");
|
|
5151
5212
|
},
|
|
5152
|
-
dependencies
|
|
5153
|
-
if (!isObject(schema.dependencies))
|
|
5154
|
-
|
|
5155
|
-
|
|
5156
|
-
|
|
5157
|
-
|
|
5158
|
-
|
|
5159
|
-
|
|
5160
|
-
|
|
5161
|
-
|
|
5162
|
-
|
|
5163
|
-
|
|
5164
|
-
|
|
5165
|
-
|
|
5166
|
-
|
|
5167
|
-
|
|
5168
|
-
|
|
5169
|
-
|
|
5170
|
-
|
|
5213
|
+
dependencies(report, schema) {
|
|
5214
|
+
if (!isObject(schema.dependencies)) {
|
|
5215
|
+
report.addError("KEYWORD_TYPE_EXPECTED", ["dependencies", "object"], void 0, schema, "dependencies");
|
|
5216
|
+
return;
|
|
5217
|
+
}
|
|
5218
|
+
const keys = Object.keys(schema.dependencies);
|
|
5219
|
+
for (const schemaKey of keys) {
|
|
5220
|
+
const schemaDependency = schema.dependencies[schemaKey];
|
|
5221
|
+
if (isObject(schemaDependency) || report.options.version !== "draft-04" && typeof schemaDependency === "boolean") {
|
|
5222
|
+
report.path.push("dependencies");
|
|
5223
|
+
report.path.push(schemaKey);
|
|
5224
|
+
this.validateSchema(report, schemaDependency);
|
|
5225
|
+
report.path.pop();
|
|
5226
|
+
report.path.pop();
|
|
5227
|
+
} else if (Array.isArray(schemaDependency)) {
|
|
5228
|
+
const depArray = schemaDependency;
|
|
5229
|
+
if (report.options.version === "draft-04" && depArray.length === 0) report.addError("KEYWORD_MUST_BE", ["dependencies", "not empty array"], void 0, schema, "dependencies");
|
|
5230
|
+
for (const dep of depArray) if (typeof dep !== "string") report.addError("KEYWORD_VALUE_TYPE", ["dependencies", "string"], void 0, schema, "dependencies");
|
|
5231
|
+
if (!isUniqueArray(depArray)) report.addError("KEYWORD_MUST_BE", ["dependencies", "an array with unique items"], void 0, schema, "dependencies");
|
|
5232
|
+
} else report.addError("KEYWORD_VALUE_TYPE", ["dependencies", report.options.version === "draft-04" ? "object or array" : "boolean, object or array"], void 0, schema, "dependencies");
|
|
5171
5233
|
}
|
|
5172
5234
|
},
|
|
5173
|
-
enum
|
|
5174
|
-
if (Array.isArray(schema.enum)
|
|
5235
|
+
enum(report, schema) {
|
|
5236
|
+
if (!Array.isArray(schema.enum)) report.addError("KEYWORD_TYPE_EXPECTED", ["enum", "array"], void 0, schema, "enum");
|
|
5175
5237
|
else if (schema.enum.length === 0) report.addError("KEYWORD_MUST_BE", ["enum", "an array with at least one element"], void 0, schema, "enum");
|
|
5176
|
-
else if (isUniqueArray(schema.enum)
|
|
5238
|
+
else if (!isUniqueArray(schema.enum)) report.addError("KEYWORD_MUST_BE", ["enum", "an array with unique elements"], void 0, schema, "enum");
|
|
5177
5239
|
},
|
|
5178
|
-
type
|
|
5179
|
-
const primitiveTypes = [
|
|
5180
|
-
"array",
|
|
5181
|
-
"boolean",
|
|
5182
|
-
"integer",
|
|
5183
|
-
"number",
|
|
5184
|
-
"null",
|
|
5185
|
-
"object",
|
|
5186
|
-
"string"
|
|
5187
|
-
];
|
|
5188
|
-
const primitiveTypeStr = primitiveTypes.join(",");
|
|
5240
|
+
type(report, schema) {
|
|
5189
5241
|
const isArray = Array.isArray(schema.type);
|
|
5190
5242
|
if (Array.isArray(schema.type)) {
|
|
5191
|
-
for (const typeItem of schema.type) if (!
|
|
5192
|
-
if (isUniqueArray(schema.type)
|
|
5243
|
+
for (const typeItem of schema.type) if (!PRIMITIVE_TYPES_SET.has(typeItem)) report.addError("KEYWORD_TYPE_EXPECTED", ["type", PRIMITIVE_TYPE_STR], void 0, schema, "type");
|
|
5244
|
+
if (!isUniqueArray(schema.type)) report.addError("KEYWORD_MUST_BE", ["type", "an object with unique properties"], void 0, schema, "type");
|
|
5193
5245
|
} else if (typeof schema.type === "string") {
|
|
5194
|
-
if (!
|
|
5246
|
+
if (!PRIMITIVE_TYPES_SET.has(schema.type)) report.addError("KEYWORD_TYPE_EXPECTED", ["type", PRIMITIVE_TYPE_STR], void 0, schema, "type");
|
|
5195
5247
|
} else report.addError("KEYWORD_TYPE_EXPECTED", ["type", ["string", "array"]], void 0, schema, "type");
|
|
5196
|
-
if (this.options.noEmptyStrings === true)
|
|
5197
|
-
|
|
5198
|
-
|
|
5199
|
-
|
|
5200
|
-
|
|
5201
|
-
if (this.options.
|
|
5202
|
-
|
|
5203
|
-
|
|
5204
|
-
}
|
|
5205
|
-
}
|
|
5206
|
-
if (this.options.forceProperties === true) {
|
|
5207
|
-
if (schema.type === "object" || isArray && schema.type.includes("object")) {
|
|
5208
|
-
if (schema.properties === void 0 && schema.patternProperties === void 0) report.addError("KEYWORD_UNDEFINED_STRICT", ["properties"], void 0, schema, "properties");
|
|
5209
|
-
}
|
|
5210
|
-
}
|
|
5211
|
-
if (this.options.forceItems === true) {
|
|
5212
|
-
if (schema.type === "array" || isArray && schema.type.includes("array")) {
|
|
5213
|
-
if (schema.items === void 0) report.addError("KEYWORD_UNDEFINED_STRICT", ["items"], void 0, schema, "items");
|
|
5214
|
-
}
|
|
5215
|
-
}
|
|
5216
|
-
if (this.options.forceMinItems === true) {
|
|
5217
|
-
if (schema.type === "array" || isArray && schema.type.includes("array")) {
|
|
5218
|
-
if (schema.minItems === void 0) report.addError("KEYWORD_UNDEFINED_STRICT", ["minItems"], void 0, schema, "minItems");
|
|
5219
|
-
}
|
|
5220
|
-
}
|
|
5221
|
-
if (this.options.forceMaxItems === true) {
|
|
5222
|
-
if (schema.type === "array" || isArray && schema.type.includes("array")) {
|
|
5223
|
-
if (schema.maxItems === void 0) report.addError("KEYWORD_UNDEFINED_STRICT", ["maxItems"], void 0, schema, "maxItems");
|
|
5224
|
-
}
|
|
5225
|
-
}
|
|
5226
|
-
if (this.options.forceMinLength === true) {
|
|
5227
|
-
if (schema.type === "string" || isArray && schema.type.includes("string")) {
|
|
5228
|
-
if (schema.minLength === void 0 && schema.format === void 0 && schema.enum === void 0 && schema.pattern === void 0) report.addError("KEYWORD_UNDEFINED_STRICT", ["minLength"], void 0, schema, "minLength");
|
|
5229
|
-
}
|
|
5230
|
-
}
|
|
5231
|
-
if (this.options.forceMaxLength === true) {
|
|
5232
|
-
if (schema.type === "string" || isArray && schema.type.includes("string")) {
|
|
5233
|
-
if (schema.maxLength === void 0 && schema.format === void 0 && schema.enum === void 0 && schema.pattern === void 0) report.addError("KEYWORD_UNDEFINED_STRICT", ["maxLength"], void 0, schema, "maxLength");
|
|
5234
|
-
}
|
|
5235
|
-
}
|
|
5248
|
+
if (this.options.noEmptyStrings === true && (schema.type === "string" || isArray && schema.type.includes("string")) && schema.minLength === void 0 && schema.enum === void 0 && schema.format === void 0) schema.minLength = 1;
|
|
5249
|
+
if (this.options.noEmptyArrays === true && (schema.type === "array" || isArray && schema.type.includes("array")) && schema.minItems === void 0) schema.minItems = 1;
|
|
5250
|
+
if (this.options.forceProperties === true && (schema.type === "object" || isArray && schema.type.includes("object")) && schema.properties === void 0 && schema.patternProperties === void 0) report.addError("KEYWORD_UNDEFINED_STRICT", ["properties"], void 0, schema, "properties");
|
|
5251
|
+
if (this.options.forceItems === true && (schema.type === "array" || isArray && schema.type.includes("array")) && schema.items === void 0) report.addError("KEYWORD_UNDEFINED_STRICT", ["items"], void 0, schema, "items");
|
|
5252
|
+
if (this.options.forceMinItems === true && (schema.type === "array" || isArray && schema.type.includes("array")) && schema.minItems === void 0) report.addError("KEYWORD_UNDEFINED_STRICT", ["minItems"], void 0, schema, "minItems");
|
|
5253
|
+
if (this.options.forceMaxItems === true && (schema.type === "array" || isArray && schema.type.includes("array")) && schema.maxItems === void 0) report.addError("KEYWORD_UNDEFINED_STRICT", ["maxItems"], void 0, schema, "maxItems");
|
|
5254
|
+
if (this.options.forceMinLength === true && (schema.type === "string" || isArray && schema.type.includes("string")) && schema.minLength === void 0 && schema.format === void 0 && schema.enum === void 0 && schema.pattern === void 0) report.addError("KEYWORD_UNDEFINED_STRICT", ["minLength"], void 0, schema, "minLength");
|
|
5255
|
+
if (this.options.forceMaxLength === true && (schema.type === "string" || isArray && schema.type.includes("string")) && schema.maxLength === void 0 && schema.format === void 0 && schema.enum === void 0 && schema.pattern === void 0) report.addError("KEYWORD_UNDEFINED_STRICT", ["maxLength"], void 0, schema, "maxLength");
|
|
5236
5256
|
},
|
|
5237
|
-
allOf
|
|
5238
|
-
if (Array.isArray(schema.allOf)
|
|
5257
|
+
allOf(report, schema) {
|
|
5258
|
+
if (!Array.isArray(schema.allOf)) report.addError("KEYWORD_TYPE_EXPECTED", ["allOf", "array"], void 0, schema, "allOf");
|
|
5239
5259
|
else if (schema.allOf.length === 0) report.addError("KEYWORD_MUST_BE", ["allOf", "an array with at least one element"], void 0, schema, "allOf");
|
|
5240
5260
|
else for (let idx = 0; idx < schema.allOf.length; idx++) {
|
|
5241
5261
|
report.path.push("allOf");
|
|
@@ -5245,8 +5265,8 @@
|
|
|
5245
5265
|
report.path.pop();
|
|
5246
5266
|
}
|
|
5247
5267
|
},
|
|
5248
|
-
anyOf
|
|
5249
|
-
if (Array.isArray(schema.anyOf)
|
|
5268
|
+
anyOf(report, schema) {
|
|
5269
|
+
if (!Array.isArray(schema.anyOf)) report.addError("KEYWORD_TYPE_EXPECTED", ["anyOf", "array"], void 0, schema, "anyOf");
|
|
5250
5270
|
else if (schema.anyOf.length === 0) report.addError("KEYWORD_MUST_BE", ["anyOf", "an array with at least one element"], void 0, schema, "anyOf");
|
|
5251
5271
|
else for (let idx = 0; idx < schema.anyOf.length; idx++) {
|
|
5252
5272
|
report.path.push("anyOf");
|
|
@@ -5256,8 +5276,8 @@
|
|
|
5256
5276
|
report.path.pop();
|
|
5257
5277
|
}
|
|
5258
5278
|
},
|
|
5259
|
-
oneOf
|
|
5260
|
-
if (Array.isArray(schema.oneOf)
|
|
5279
|
+
oneOf(report, schema) {
|
|
5280
|
+
if (!Array.isArray(schema.oneOf)) report.addError("KEYWORD_TYPE_EXPECTED", ["oneOf", "array"], void 0, schema, "oneOf");
|
|
5261
5281
|
else if (schema.oneOf.length === 0) report.addError("KEYWORD_MUST_BE", ["oneOf", "an array with at least one element"], void 0, schema, "oneOf");
|
|
5262
5282
|
else for (let idx = 0; idx < schema.oneOf.length; idx++) {
|
|
5263
5283
|
report.path.push("oneOf");
|
|
@@ -5267,16 +5287,17 @@
|
|
|
5267
5287
|
report.path.pop();
|
|
5268
5288
|
}
|
|
5269
5289
|
},
|
|
5270
|
-
not
|
|
5290
|
+
not(report, schema) {
|
|
5271
5291
|
const notSchema = schema.not;
|
|
5272
|
-
if (!(report.options.version === "draft-04" ? isObject(notSchema) : typeof notSchema === "boolean" || isObject(notSchema)))
|
|
5273
|
-
|
|
5274
|
-
|
|
5275
|
-
this.validateSchema(report, notSchema);
|
|
5276
|
-
report.path.pop();
|
|
5292
|
+
if (!(report.options.version === "draft-04" ? isObject(notSchema) : typeof notSchema === "boolean" || isObject(notSchema))) {
|
|
5293
|
+
report.addError("KEYWORD_TYPE_EXPECTED", ["not", report.options.version === "draft-04" ? "object" : ["boolean", "object"]], void 0, schema, "not");
|
|
5294
|
+
return;
|
|
5277
5295
|
}
|
|
5296
|
+
report.path.push("not");
|
|
5297
|
+
this.validateSchema(report, notSchema);
|
|
5298
|
+
report.path.pop();
|
|
5278
5299
|
},
|
|
5279
|
-
if
|
|
5300
|
+
if(report, schema) {
|
|
5280
5301
|
if (report.options.version !== "draft-07") return;
|
|
5281
5302
|
const ifSchema = schema.if;
|
|
5282
5303
|
if (!(typeof ifSchema === "boolean" || isObject(ifSchema))) {
|
|
@@ -5287,7 +5308,7 @@
|
|
|
5287
5308
|
this.validateSchema(report, ifSchema);
|
|
5288
5309
|
report.path.pop();
|
|
5289
5310
|
},
|
|
5290
|
-
then
|
|
5311
|
+
then(report, schema) {
|
|
5291
5312
|
if (report.options.version !== "draft-07") return;
|
|
5292
5313
|
const thenSchema = schema.then;
|
|
5293
5314
|
if (!(typeof thenSchema === "boolean" || isObject(thenSchema))) {
|
|
@@ -5298,7 +5319,7 @@
|
|
|
5298
5319
|
this.validateSchema(report, thenSchema);
|
|
5299
5320
|
report.path.pop();
|
|
5300
5321
|
},
|
|
5301
|
-
else
|
|
5322
|
+
else(report, schema) {
|
|
5302
5323
|
if (report.options.version !== "draft-07") return;
|
|
5303
5324
|
const elseSchema = schema.else;
|
|
5304
5325
|
if (!(typeof elseSchema === "boolean" || isObject(elseSchema))) {
|
|
@@ -5309,21 +5330,22 @@
|
|
|
5309
5330
|
this.validateSchema(report, elseSchema);
|
|
5310
5331
|
report.path.pop();
|
|
5311
5332
|
},
|
|
5312
|
-
definitions
|
|
5313
|
-
if (!isObject(schema.definitions))
|
|
5314
|
-
|
|
5315
|
-
|
|
5316
|
-
|
|
5317
|
-
|
|
5318
|
-
|
|
5319
|
-
|
|
5320
|
-
|
|
5321
|
-
|
|
5322
|
-
|
|
5323
|
-
|
|
5333
|
+
definitions(report, schema) {
|
|
5334
|
+
if (!isObject(schema.definitions)) {
|
|
5335
|
+
report.addError("KEYWORD_TYPE_EXPECTED", ["definitions", "object"], void 0, schema, "definitions");
|
|
5336
|
+
return;
|
|
5337
|
+
}
|
|
5338
|
+
const keys = Object.keys(schema.definitions);
|
|
5339
|
+
for (const key of keys) {
|
|
5340
|
+
const val = schema.definitions[key];
|
|
5341
|
+
report.path.push("definitions");
|
|
5342
|
+
report.path.push(key);
|
|
5343
|
+
this.validateSchema(report, val);
|
|
5344
|
+
report.path.pop();
|
|
5345
|
+
report.path.pop();
|
|
5324
5346
|
}
|
|
5325
5347
|
},
|
|
5326
|
-
$defs
|
|
5348
|
+
$defs(report, schema) {
|
|
5327
5349
|
if (report.options.version !== "draft2019-09" && report.options.version !== "draft2020-12") return;
|
|
5328
5350
|
if (!isObject(schema.$defs)) {
|
|
5329
5351
|
report.addError("KEYWORD_TYPE_EXPECTED", ["$defs", "object"], void 0, schema, "$defs");
|
|
@@ -5339,34 +5361,36 @@
|
|
|
5339
5361
|
report.path.pop();
|
|
5340
5362
|
}
|
|
5341
5363
|
},
|
|
5342
|
-
format
|
|
5364
|
+
format(report, schema) {
|
|
5343
5365
|
if (this.options.formatAssertions === false) return;
|
|
5344
|
-
if (typeof schema.format !== "string")
|
|
5345
|
-
|
|
5346
|
-
|
|
5347
|
-
if (!isFormatSupported(schema.format, this.options.customFormats) && this.options.ignoreUnknownFormats !== true && !isModernDraft) report.addError("UNKNOWN_FORMAT", [schema.format], void 0, schema, "format");
|
|
5366
|
+
if (typeof schema.format !== "string") {
|
|
5367
|
+
report.addError("KEYWORD_TYPE_EXPECTED", ["format", "string"], void 0, schema, "format");
|
|
5368
|
+
return;
|
|
5348
5369
|
}
|
|
5370
|
+
const isModernDraft = this.options.version === "draft2019-09" || this.options.version === "draft2020-12";
|
|
5371
|
+
if (!isFormatSupported(schema.format, this.options.customFormats) && this.options.ignoreUnknownFormats !== true && !isModernDraft) report.addError("UNKNOWN_FORMAT", [schema.format], void 0, schema, "format");
|
|
5349
5372
|
},
|
|
5350
|
-
contentEncoding
|
|
5373
|
+
contentEncoding(report, schema) {
|
|
5351
5374
|
if (report.options.version !== "draft-07") return;
|
|
5352
5375
|
if (typeof schema.contentEncoding !== "string") report.addError("KEYWORD_TYPE_EXPECTED", ["contentEncoding", "string"], void 0, schema, "contentEncoding");
|
|
5353
5376
|
},
|
|
5354
|
-
contentMediaType
|
|
5377
|
+
contentMediaType(report, schema) {
|
|
5355
5378
|
if (report.options.version !== "draft-07") return;
|
|
5356
5379
|
if (typeof schema.contentMediaType !== "string") report.addError("KEYWORD_TYPE_EXPECTED", ["contentMediaType", "string"], void 0, schema, "contentMediaType");
|
|
5357
5380
|
},
|
|
5358
|
-
id
|
|
5381
|
+
id(report, schema) {
|
|
5359
5382
|
if (typeof schema.id !== "string") report.addError("KEYWORD_TYPE_EXPECTED", ["id", "string"], void 0, schema, "id");
|
|
5360
5383
|
},
|
|
5361
|
-
title
|
|
5384
|
+
title(report, schema) {
|
|
5362
5385
|
if (typeof schema.title !== "string") report.addError("KEYWORD_TYPE_EXPECTED", ["title", "string"], void 0, schema, "title");
|
|
5363
5386
|
},
|
|
5364
|
-
description
|
|
5387
|
+
description(report, schema) {
|
|
5365
5388
|
if (typeof schema.description !== "string") report.addError("KEYWORD_TYPE_EXPECTED", ["description", "string"], void 0, schema, "description");
|
|
5366
5389
|
},
|
|
5367
|
-
default
|
|
5390
|
+
default() {}
|
|
5368
5391
|
};
|
|
5369
5392
|
var SchemaValidator = class {
|
|
5393
|
+
validator;
|
|
5370
5394
|
constructor(validator) {
|
|
5371
5395
|
this.validator = validator;
|
|
5372
5396
|
}
|
|
@@ -5386,18 +5410,17 @@
|
|
|
5386
5410
|
if (hasParentSchema) {
|
|
5387
5411
|
if (schema.__$schemaResolved && schema.__$schemaResolved !== schema) {
|
|
5388
5412
|
const subReport = new Report(report);
|
|
5389
|
-
if (validate
|
|
5413
|
+
if (!validate(this.validator, subReport, schema.__$schemaResolved, schema)) report.addError("PARENT_SCHEMA_VALIDATION_FAILED", void 0, subReport, schema, "$schema");
|
|
5390
5414
|
} else if (this.validator.options.ignoreUnresolvableReferences !== true) report.addError("REF_UNRESOLVED", [schema.$schema], void 0, schema, "$schema");
|
|
5391
5415
|
}
|
|
5392
5416
|
if (this.validator.options.noTypeless === true) {
|
|
5393
5417
|
if (schema.type !== void 0) {
|
|
5394
|
-
|
|
5395
|
-
if (Array.isArray(schema.anyOf)) schemas = schemas.concat(schema.anyOf);
|
|
5396
|
-
if (Array.isArray(schema.oneOf)) schemas = schemas.concat(schema.oneOf);
|
|
5397
|
-
if (Array.isArray(schema.allOf)) schemas = schemas.concat(schema.allOf);
|
|
5398
|
-
schemas.forEach(function(sch) {
|
|
5418
|
+
const inheritType = (sch) => {
|
|
5399
5419
|
if (!sch.type) sch.type = schema.type;
|
|
5400
|
-
}
|
|
5420
|
+
};
|
|
5421
|
+
if (Array.isArray(schema.anyOf)) for (let i = 0; i < schema.anyOf.length; i++) inheritType(schema.anyOf[i]);
|
|
5422
|
+
if (Array.isArray(schema.oneOf)) for (let i = 0; i < schema.oneOf.length; i++) inheritType(schema.oneOf[i]);
|
|
5423
|
+
if (Array.isArray(schema.allOf)) for (let i = 0; i < schema.allOf.length; i++) inheritType(schema.allOf[i]);
|
|
5401
5424
|
}
|
|
5402
5425
|
if (schema.enum === void 0 && schema.type === void 0 && schema.anyOf === void 0 && schema.oneOf === void 0 && schema.not === void 0 && schema.$ref === void 0) report.addError("KEYWORD_UNDEFINED_STRICT", ["type"], void 0, schema, "type");
|
|
5403
5426
|
}
|
|
@@ -5405,9 +5428,7 @@
|
|
|
5405
5428
|
for (const key of keys) {
|
|
5406
5429
|
if (key.startsWith("__")) continue;
|
|
5407
5430
|
if (Object.hasOwn(SchemaValidators, key)) SchemaValidators[key].call(this, report, schema);
|
|
5408
|
-
else if (!hasParentSchema)
|
|
5409
|
-
if (this.validator.options.noExtraKeywords === true) report.addError("KEYWORD_UNEXPECTED", [key], void 0, schema, void 0);
|
|
5410
|
-
}
|
|
5431
|
+
else if (!hasParentSchema && this.validator.options.noExtraKeywords === true) report.addError("KEYWORD_UNEXPECTED", [key], void 0, schema);
|
|
5411
5432
|
}
|
|
5412
5433
|
if (this.validator.options.pedanticCheck === true) {
|
|
5413
5434
|
if (schema.enum) {
|
|
@@ -5417,14 +5438,14 @@
|
|
|
5417
5438
|
report.path.push("enum");
|
|
5418
5439
|
for (let idx = 0; idx < schema.enum.length; idx++) {
|
|
5419
5440
|
report.path.push(idx);
|
|
5420
|
-
validate
|
|
5441
|
+
validate(this.validator, report, tmpSchema, schema.enum[idx]);
|
|
5421
5442
|
report.path.pop();
|
|
5422
5443
|
}
|
|
5423
5444
|
report.path.pop();
|
|
5424
5445
|
}
|
|
5425
5446
|
if (schema.default) {
|
|
5426
5447
|
report.path.push("default");
|
|
5427
|
-
validate
|
|
5448
|
+
validate(this.validator, report, schema, schema.default);
|
|
5428
5449
|
report.path.pop();
|
|
5429
5450
|
}
|
|
5430
5451
|
}
|
|
@@ -5461,7 +5482,7 @@
|
|
|
5461
5482
|
* create a circular dependency).
|
|
5462
5483
|
*/
|
|
5463
5484
|
_jsonValidate(report, schema, json) {
|
|
5464
|
-
return validate
|
|
5485
|
+
return validate(this, report, schema, json);
|
|
5465
5486
|
}
|
|
5466
5487
|
getDefaultSchemaId() {
|
|
5467
5488
|
return this.options.version && this.options.version !== "none" ? VERSION_SCHEMA_URL_MAPPING[this.options.version] : VERSION_SCHEMA_URL_MAPPING[defaultOptions.version];
|
|
@@ -5474,9 +5495,9 @@
|
|
|
5474
5495
|
if (!options) options = {};
|
|
5475
5496
|
this.validateOptions = options;
|
|
5476
5497
|
if (typeof schema !== "string" && typeof schema !== "boolean" && !isObject(schema)) {
|
|
5477
|
-
const e = /* @__PURE__ */ new Error(
|
|
5498
|
+
const e = /* @__PURE__ */ new Error(`Invalid .validate call - schema must be a string or object but ${whatIs(schema)} was passed!`);
|
|
5478
5499
|
if (callback) {
|
|
5479
|
-
setTimeout(
|
|
5500
|
+
setTimeout(() => {
|
|
5480
5501
|
callback(e, false);
|
|
5481
5502
|
}, 0);
|
|
5482
5503
|
return;
|
|
@@ -5491,9 +5512,9 @@
|
|
|
5491
5512
|
const schemaName = schema;
|
|
5492
5513
|
_schema = this.scache.getSchema(report, schemaName);
|
|
5493
5514
|
if (!_schema) {
|
|
5494
|
-
const e = /* @__PURE__ */ new Error(
|
|
5515
|
+
const e = /* @__PURE__ */ new Error(`Schema with id '${schemaName}' wasn't found in the validator cache!`);
|
|
5495
5516
|
if (callback) {
|
|
5496
|
-
setTimeout(
|
|
5517
|
+
setTimeout(() => {
|
|
5497
5518
|
callback(e, false);
|
|
5498
5519
|
}, 0);
|
|
5499
5520
|
return;
|
|
@@ -5511,9 +5532,9 @@
|
|
|
5511
5532
|
report.rootSchema = _schema;
|
|
5512
5533
|
_schema = get(_schema, options.schemaPath);
|
|
5513
5534
|
if (!_schema) {
|
|
5514
|
-
const e = /* @__PURE__ */ new Error(
|
|
5535
|
+
const e = /* @__PURE__ */ new Error(`Schema path '${options.schemaPath}' wasn't found in the schema!`);
|
|
5515
5536
|
if (callback) {
|
|
5516
|
-
setTimeout(
|
|
5537
|
+
setTimeout(() => {
|
|
5517
5538
|
callback(e, false);
|
|
5518
5539
|
}, 0);
|
|
5519
5540
|
return;
|
|
@@ -5521,7 +5542,7 @@
|
|
|
5521
5542
|
throw e;
|
|
5522
5543
|
}
|
|
5523
5544
|
}
|
|
5524
|
-
if (!foundError) validate
|
|
5545
|
+
if (!foundError) validate(this, report, _schema, json);
|
|
5525
5546
|
if (callback) {
|
|
5526
5547
|
report.processAsyncTasks(this.options.asyncTimeout, callback);
|
|
5527
5548
|
return;
|
|
@@ -5592,8 +5613,8 @@
|
|
|
5592
5613
|
if (!err) return [];
|
|
5593
5614
|
const details = err.details || [];
|
|
5594
5615
|
const missingRefs = [];
|
|
5595
|
-
function collect(
|
|
5596
|
-
for (const detail of
|
|
5616
|
+
function collect(items) {
|
|
5617
|
+
for (const detail of items) {
|
|
5597
5618
|
if (detail.code === "UNRESOLVABLE_REFERENCE" || detail.code === "SCHEMA_NOT_REACHABLE") missingRefs.push(detail.params[0]);
|
|
5598
5619
|
if (detail.inner) collect(detail.inner);
|
|
5599
5620
|
}
|
|
@@ -5609,9 +5630,13 @@
|
|
|
5609
5630
|
getMissingRemoteReferences(err) {
|
|
5610
5631
|
const missingReferences = this.getMissingReferences(err);
|
|
5611
5632
|
const missingRemoteReferences = [];
|
|
5633
|
+
const seen = /* @__PURE__ */ new Set();
|
|
5612
5634
|
for (const ref of missingReferences) {
|
|
5613
5635
|
const remoteReference = getRemotePath(ref);
|
|
5614
|
-
if (remoteReference && !
|
|
5636
|
+
if (remoteReference && !seen.has(remoteReference)) {
|
|
5637
|
+
seen.add(remoteReference);
|
|
5638
|
+
missingRemoteReferences.push(remoteReference);
|
|
5639
|
+
}
|
|
5615
5640
|
}
|
|
5616
5641
|
return missingRemoteReferences;
|
|
5617
5642
|
}
|
|
@@ -5624,24 +5649,25 @@
|
|
|
5624
5649
|
getResolvedSchema(schemaId) {
|
|
5625
5650
|
const report = new Report(this.options);
|
|
5626
5651
|
const schema = this.scache.getSchemaByUri(report, schemaId);
|
|
5627
|
-
if (!schema) return
|
|
5652
|
+
if (!schema) return;
|
|
5628
5653
|
const clonedSchema = deepClone(schema, this.options.maxRecursionDepth);
|
|
5629
5654
|
const visited = /* @__PURE__ */ new WeakSet();
|
|
5630
|
-
const cleanup =
|
|
5631
|
-
|
|
5632
|
-
const typeOf = whatIs(schema);
|
|
5655
|
+
const cleanup = (node) => {
|
|
5656
|
+
const typeOf = whatIs(node);
|
|
5633
5657
|
if (typeOf !== "object" && typeOf !== "array") return;
|
|
5634
|
-
if (visited.has(
|
|
5635
|
-
visited.add(
|
|
5636
|
-
|
|
5637
|
-
|
|
5638
|
-
const
|
|
5639
|
-
|
|
5640
|
-
delete
|
|
5641
|
-
|
|
5658
|
+
if (visited.has(node)) return;
|
|
5659
|
+
visited.add(node);
|
|
5660
|
+
const schemaNode = node;
|
|
5661
|
+
if (schemaNode.$ref && schemaNode.__$refResolved) {
|
|
5662
|
+
const from = schemaNode.__$refResolved;
|
|
5663
|
+
const to = schemaNode;
|
|
5664
|
+
delete schemaNode.$ref;
|
|
5665
|
+
delete schemaNode.__$refResolved;
|
|
5666
|
+
for (const key in from) if (Object.hasOwn(from, key)) copyProp(from, to, key);
|
|
5642
5667
|
}
|
|
5643
|
-
|
|
5644
|
-
|
|
5668
|
+
const record = node;
|
|
5669
|
+
for (const key in record) if (Object.hasOwn(record, key)) if (isInternalKey(key)) delete record[key];
|
|
5670
|
+
else cleanup(record[key]);
|
|
5645
5671
|
};
|
|
5646
5672
|
cleanup(clonedSchema);
|
|
5647
5673
|
return clonedSchema;
|
|
@@ -5650,24 +5676,20 @@
|
|
|
5650
5676
|
//#endregion
|
|
5651
5677
|
//#region src/z-schema.ts
|
|
5652
5678
|
var ZSchema = class ZSchema extends ZSchemaBase {
|
|
5653
|
-
/** @internal Use ZSchema.create() instead. */
|
|
5654
|
-
constructor(options, token) {
|
|
5655
|
-
super(options, token);
|
|
5656
|
-
}
|
|
5657
5679
|
/**
|
|
5658
5680
|
* Register a global format validator available to all instances.
|
|
5659
5681
|
* @param name - The format name (e.g. `'email'`, `'date'`).
|
|
5660
5682
|
* @param validatorFunction - A sync or async function `(value: unknown) => boolean | Promise<boolean>`.
|
|
5661
5683
|
*/
|
|
5662
5684
|
static registerFormat(name, validatorFunction) {
|
|
5663
|
-
|
|
5685
|
+
registerFormat(name, validatorFunction);
|
|
5664
5686
|
}
|
|
5665
5687
|
/**
|
|
5666
5688
|
* Remove a globally registered format validator.
|
|
5667
5689
|
* @param name - The format name to unregister.
|
|
5668
5690
|
*/
|
|
5669
5691
|
static unregisterFormat(name) {
|
|
5670
|
-
|
|
5692
|
+
unregisterFormat(name);
|
|
5671
5693
|
}
|
|
5672
5694
|
/** Returns the names of all globally registered format validators. */
|
|
5673
5695
|
static getRegisteredFormats() {
|
|
@@ -5696,7 +5718,7 @@
|
|
|
5696
5718
|
* @param schemaReader - A function `(uri: string) => JsonSchema | undefined`, or `undefined` to clear.
|
|
5697
5719
|
*/
|
|
5698
5720
|
static setSchemaReader(schemaReader) {
|
|
5699
|
-
|
|
5721
|
+
setSchemaReader(schemaReader);
|
|
5700
5722
|
}
|
|
5701
5723
|
static schemaSymbol = schemaSymbol;
|
|
5702
5724
|
static jsonSymbol = jsonSymbol;
|
|
@@ -5732,10 +5754,10 @@
|
|
|
5732
5754
|
try {
|
|
5733
5755
|
this._validate(json, schema, options ?? {});
|
|
5734
5756
|
return { valid: true };
|
|
5735
|
-
} catch (
|
|
5757
|
+
} catch (error) {
|
|
5736
5758
|
return {
|
|
5737
5759
|
valid: false,
|
|
5738
|
-
err
|
|
5760
|
+
err: error
|
|
5739
5761
|
};
|
|
5740
5762
|
}
|
|
5741
5763
|
}
|
|
@@ -5750,9 +5772,12 @@
|
|
|
5750
5772
|
validateAsync(json, schema, options) {
|
|
5751
5773
|
return new Promise((resolve, reject) => {
|
|
5752
5774
|
try {
|
|
5753
|
-
this._validate(json, schema, options || {}, (err, valid) =>
|
|
5754
|
-
|
|
5755
|
-
|
|
5775
|
+
this._validate(json, schema, options || {}, (err, valid) => {
|
|
5776
|
+
if (err || !valid) reject(err ?? /* @__PURE__ */ new Error("Validation failed"));
|
|
5777
|
+
else resolve(valid);
|
|
5778
|
+
});
|
|
5779
|
+
} catch (error) {
|
|
5780
|
+
reject(error instanceof Error ? error : new Error(String(error), { cause: error }));
|
|
5756
5781
|
}
|
|
5757
5782
|
});
|
|
5758
5783
|
}
|
|
@@ -5773,10 +5798,10 @@
|
|
|
5773
5798
|
err
|
|
5774
5799
|
});
|
|
5775
5800
|
});
|
|
5776
|
-
} catch (
|
|
5801
|
+
} catch (error) {
|
|
5777
5802
|
resolve({
|
|
5778
5803
|
valid: false,
|
|
5779
|
-
err
|
|
5804
|
+
err: error
|
|
5780
5805
|
});
|
|
5781
5806
|
}
|
|
5782
5807
|
});
|
|
@@ -5799,10 +5824,10 @@
|
|
|
5799
5824
|
try {
|
|
5800
5825
|
this._validateSchema(schemaOrArr);
|
|
5801
5826
|
return { valid: true };
|
|
5802
|
-
} catch (
|
|
5827
|
+
} catch (error) {
|
|
5803
5828
|
return {
|
|
5804
5829
|
valid: false,
|
|
5805
|
-
err
|
|
5830
|
+
err: error
|
|
5806
5831
|
};
|
|
5807
5832
|
}
|
|
5808
5833
|
}
|
|
@@ -5812,10 +5837,6 @@
|
|
|
5812
5837
|
* Created via `ZSchema.create({ safe: true })`.
|
|
5813
5838
|
*/
|
|
5814
5839
|
var ZSchemaSafe = class extends ZSchemaBase {
|
|
5815
|
-
/** @internal Use ZSchema.create() instead. */
|
|
5816
|
-
constructor(options, token) {
|
|
5817
|
-
super(options, token);
|
|
5818
|
-
}
|
|
5819
5840
|
/**
|
|
5820
5841
|
* Validate JSON data against a schema.
|
|
5821
5842
|
* @param json - The data to validate.
|
|
@@ -5827,10 +5848,10 @@
|
|
|
5827
5848
|
try {
|
|
5828
5849
|
this._validate(json, schema, options);
|
|
5829
5850
|
return { valid: true };
|
|
5830
|
-
} catch (
|
|
5851
|
+
} catch (error) {
|
|
5831
5852
|
return {
|
|
5832
5853
|
valid: false,
|
|
5833
|
-
err
|
|
5854
|
+
err: error
|
|
5834
5855
|
};
|
|
5835
5856
|
}
|
|
5836
5857
|
}
|
|
@@ -5843,10 +5864,10 @@
|
|
|
5843
5864
|
try {
|
|
5844
5865
|
this._validateSchema(schemaOrArr);
|
|
5845
5866
|
return { valid: true };
|
|
5846
|
-
} catch (
|
|
5867
|
+
} catch (error) {
|
|
5847
5868
|
return {
|
|
5848
5869
|
valid: false,
|
|
5849
|
-
err
|
|
5870
|
+
err: error
|
|
5850
5871
|
};
|
|
5851
5872
|
}
|
|
5852
5873
|
}
|
|
@@ -5856,10 +5877,6 @@
|
|
|
5856
5877
|
* Created via `ZSchema.create({ async: true })`.
|
|
5857
5878
|
*/
|
|
5858
5879
|
var ZSchemaAsync = class extends ZSchemaBase {
|
|
5859
|
-
/** @internal Use ZSchema.create() instead. */
|
|
5860
|
-
constructor(options, token) {
|
|
5861
|
-
super(options, token);
|
|
5862
|
-
}
|
|
5863
5880
|
/**
|
|
5864
5881
|
* Validate JSON data against a schema asynchronously.
|
|
5865
5882
|
* @param json - The data to validate.
|
|
@@ -5871,9 +5888,12 @@
|
|
|
5871
5888
|
validate(json, schema, options = {}) {
|
|
5872
5889
|
return new Promise((resolve, reject) => {
|
|
5873
5890
|
try {
|
|
5874
|
-
this._validate(json, schema, options, (err, valid) =>
|
|
5875
|
-
|
|
5876
|
-
|
|
5891
|
+
this._validate(json, schema, options, (err, valid) => {
|
|
5892
|
+
if (err || !valid) reject(err ?? /* @__PURE__ */ new Error("Validation failed"));
|
|
5893
|
+
else resolve(valid);
|
|
5894
|
+
});
|
|
5895
|
+
} catch (error) {
|
|
5896
|
+
reject(error instanceof Error ? error : new Error(String(error), { cause: error }));
|
|
5877
5897
|
}
|
|
5878
5898
|
});
|
|
5879
5899
|
}
|
|
@@ -5892,10 +5912,6 @@
|
|
|
5892
5912
|
* Created via `ZSchema.create({ async: true, safe: true })`.
|
|
5893
5913
|
*/
|
|
5894
5914
|
var ZSchemaAsyncSafe = class extends ZSchemaBase {
|
|
5895
|
-
/** @internal Use ZSchema.create() instead. */
|
|
5896
|
-
constructor(options, token) {
|
|
5897
|
-
super(options, token);
|
|
5898
|
-
}
|
|
5899
5915
|
/**
|
|
5900
5916
|
* Validate JSON data against a schema asynchronously.
|
|
5901
5917
|
* The promise always resolves (never rejects).
|
|
@@ -5913,10 +5929,10 @@
|
|
|
5913
5929
|
err
|
|
5914
5930
|
});
|
|
5915
5931
|
});
|
|
5916
|
-
} catch (
|
|
5932
|
+
} catch (error) {
|
|
5917
5933
|
resolve({
|
|
5918
5934
|
valid: false,
|
|
5919
|
-
err
|
|
5935
|
+
err: error
|
|
5920
5936
|
});
|
|
5921
5937
|
}
|
|
5922
5938
|
});
|
|
@@ -5930,10 +5946,10 @@
|
|
|
5930
5946
|
try {
|
|
5931
5947
|
this._validateSchema(schemaOrArr);
|
|
5932
5948
|
return { valid: true };
|
|
5933
|
-
} catch (
|
|
5949
|
+
} catch (error) {
|
|
5934
5950
|
return {
|
|
5935
5951
|
valid: false,
|
|
5936
|
-
err
|
|
5952
|
+
err: error
|
|
5937
5953
|
};
|
|
5938
5954
|
}
|
|
5939
5955
|
}
|