@peripheries/renderer 0.27.0 → 0.28.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 +5 -2
- package/dist/catalog.js +1290 -37
- package/dist/chunks/{query-DOXxGTO2.js → query-D_f73wsU.js} +12 -0
- package/dist/chunks/{structure-B1PsD-AJ.js → structure-Ds2wfhkH.js} +1 -1
- package/dist/chunks/{validate-y5_6ws0s.js → validate-BfXuQLmV.js} +2 -2
- package/dist/core.js +3 -3
- package/dist/react.js +2 -2
- package/dist/testing.js +1 -1
- package/dist/types/catalog/draft-2020-12.d.ts +2 -0
- package/dist/types/catalog/index.d.ts +1 -0
- package/dist/types/catalog/json-schema.d.ts +15 -0
- package/package.json +5 -2
package/dist/catalog.js
CHANGED
|
@@ -1,7 +1,1266 @@
|
|
|
1
|
-
import { x as isEach } from "./chunks/query-
|
|
2
|
-
import { a as eachFormProblems, c as validatePage, i as componentsFor } from "./chunks/validate-
|
|
1
|
+
import { x as isEach } from "./chunks/query-D_f73wsU.js";
|
|
2
|
+
import { a as eachFormProblems, c as validatePage, i as componentsFor } from "./chunks/validate-BfXuQLmV.js";
|
|
3
3
|
import { KNOWLEDGE_BUDGETS, KNOWLEDGE_KEY } from "@peripheries/runtime";
|
|
4
|
-
|
|
4
|
+
function deepCompareStrict(a, b) {
|
|
5
|
+
const typeofa = typeof a;
|
|
6
|
+
if (typeofa !== typeof b) return false;
|
|
7
|
+
if (Array.isArray(a)) {
|
|
8
|
+
if (!Array.isArray(b)) return false;
|
|
9
|
+
const length = a.length;
|
|
10
|
+
if (length !== b.length) return false;
|
|
11
|
+
for (let i = 0; i < length; i++) if (!deepCompareStrict(a[i], b[i])) return false;
|
|
12
|
+
return true;
|
|
13
|
+
}
|
|
14
|
+
if (typeofa === "object") {
|
|
15
|
+
if (!a || !b) return a === b;
|
|
16
|
+
const aKeys = Object.keys(a);
|
|
17
|
+
const bKeys = Object.keys(b);
|
|
18
|
+
if (aKeys.length !== bKeys.length) return false;
|
|
19
|
+
for (const k of aKeys) if (!deepCompareStrict(a[k], b[k])) return false;
|
|
20
|
+
return true;
|
|
21
|
+
}
|
|
22
|
+
return a === b;
|
|
23
|
+
}
|
|
24
|
+
function encodePointer(p) {
|
|
25
|
+
return encodeURI(escapePointer(p));
|
|
26
|
+
}
|
|
27
|
+
function escapePointer(p) {
|
|
28
|
+
return p.replace(/~/g, "~0").replace(/\//g, "~1");
|
|
29
|
+
}
|
|
30
|
+
var schemaArrayKeyword = {
|
|
31
|
+
prefixItems: true,
|
|
32
|
+
items: true,
|
|
33
|
+
allOf: true,
|
|
34
|
+
anyOf: true,
|
|
35
|
+
oneOf: true
|
|
36
|
+
};
|
|
37
|
+
var schemaMapKeyword = {
|
|
38
|
+
$defs: true,
|
|
39
|
+
definitions: true,
|
|
40
|
+
properties: true,
|
|
41
|
+
patternProperties: true,
|
|
42
|
+
dependentSchemas: true
|
|
43
|
+
};
|
|
44
|
+
var ignoredKeyword = {
|
|
45
|
+
id: true,
|
|
46
|
+
$id: true,
|
|
47
|
+
$ref: true,
|
|
48
|
+
$schema: true,
|
|
49
|
+
$anchor: true,
|
|
50
|
+
$vocabulary: true,
|
|
51
|
+
$comment: true,
|
|
52
|
+
default: true,
|
|
53
|
+
enum: true,
|
|
54
|
+
const: true,
|
|
55
|
+
required: true,
|
|
56
|
+
type: true,
|
|
57
|
+
maximum: true,
|
|
58
|
+
minimum: true,
|
|
59
|
+
exclusiveMaximum: true,
|
|
60
|
+
exclusiveMinimum: true,
|
|
61
|
+
multipleOf: true,
|
|
62
|
+
maxLength: true,
|
|
63
|
+
minLength: true,
|
|
64
|
+
pattern: true,
|
|
65
|
+
format: true,
|
|
66
|
+
maxItems: true,
|
|
67
|
+
minItems: true,
|
|
68
|
+
uniqueItems: true,
|
|
69
|
+
maxProperties: true,
|
|
70
|
+
minProperties: true
|
|
71
|
+
};
|
|
72
|
+
var initialBaseURI = typeof self !== "undefined" && self.location && self.location.origin !== "null" ? new URL(self.location.origin + self.location.pathname + location.search) : new URL("https://github.com/cfworker");
|
|
73
|
+
function dereference(schema, lookup = Object.create(null), baseURI = initialBaseURI, basePointer = "") {
|
|
74
|
+
if (schema && typeof schema === "object" && !Array.isArray(schema)) {
|
|
75
|
+
const id = schema.$id || schema.id;
|
|
76
|
+
if (id) {
|
|
77
|
+
const url = new URL(id, baseURI.href);
|
|
78
|
+
if (url.hash.length > 1) lookup[url.href] = schema;
|
|
79
|
+
else {
|
|
80
|
+
url.hash = "";
|
|
81
|
+
if (basePointer === "") baseURI = url;
|
|
82
|
+
else dereference(schema, lookup, baseURI);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
} else if (schema !== true && schema !== false) return lookup;
|
|
86
|
+
const schemaURI = baseURI.href + (basePointer ? "#" + basePointer : "");
|
|
87
|
+
if (lookup[schemaURI] !== void 0) throw new Error(`Duplicate schema URI "${schemaURI}".`);
|
|
88
|
+
lookup[schemaURI] = schema;
|
|
89
|
+
if (schema === true || schema === false) return lookup;
|
|
90
|
+
if (schema.__absolute_uri__ === void 0) Object.defineProperty(schema, "__absolute_uri__", {
|
|
91
|
+
enumerable: false,
|
|
92
|
+
value: schemaURI
|
|
93
|
+
});
|
|
94
|
+
if (schema.$ref && schema.__absolute_ref__ === void 0) {
|
|
95
|
+
const url = new URL(schema.$ref, baseURI.href);
|
|
96
|
+
url.hash = url.hash;
|
|
97
|
+
Object.defineProperty(schema, "__absolute_ref__", {
|
|
98
|
+
enumerable: false,
|
|
99
|
+
value: url.href
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
if (schema.$recursiveRef && schema.__absolute_recursive_ref__ === void 0) {
|
|
103
|
+
const url = new URL(schema.$recursiveRef, baseURI.href);
|
|
104
|
+
url.hash = url.hash;
|
|
105
|
+
Object.defineProperty(schema, "__absolute_recursive_ref__", {
|
|
106
|
+
enumerable: false,
|
|
107
|
+
value: url.href
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
if (schema.$anchor) {
|
|
111
|
+
const url = new URL("#" + schema.$anchor, baseURI.href);
|
|
112
|
+
lookup[url.href] = schema;
|
|
113
|
+
}
|
|
114
|
+
for (let key in schema) {
|
|
115
|
+
if (ignoredKeyword[key]) continue;
|
|
116
|
+
const keyBase = `${basePointer}/${encodePointer(key)}`;
|
|
117
|
+
const subSchema = schema[key];
|
|
118
|
+
if (Array.isArray(subSchema)) {
|
|
119
|
+
if (schemaArrayKeyword[key]) {
|
|
120
|
+
const length = subSchema.length;
|
|
121
|
+
for (let i = 0; i < length; i++) dereference(subSchema[i], lookup, baseURI, `${keyBase}/${i}`);
|
|
122
|
+
}
|
|
123
|
+
} else if (schemaMapKeyword[key]) for (let subKey in subSchema) dereference(subSchema[subKey], lookup, baseURI, `${keyBase}/${encodePointer(subKey)}`);
|
|
124
|
+
else dereference(subSchema, lookup, baseURI, keyBase);
|
|
125
|
+
}
|
|
126
|
+
return lookup;
|
|
127
|
+
}
|
|
128
|
+
var DATE = /^(\d\d\d\d)-(\d\d)-(\d\d)$/;
|
|
129
|
+
var DAYS = [
|
|
130
|
+
0,
|
|
131
|
+
31,
|
|
132
|
+
28,
|
|
133
|
+
31,
|
|
134
|
+
30,
|
|
135
|
+
31,
|
|
136
|
+
30,
|
|
137
|
+
31,
|
|
138
|
+
31,
|
|
139
|
+
30,
|
|
140
|
+
31,
|
|
141
|
+
30,
|
|
142
|
+
31
|
|
143
|
+
];
|
|
144
|
+
var TIME = /^(\d\d):(\d\d):(\d\d)(\.\d+)?(z|[+-]\d\d(?::?\d\d)?)?$/i;
|
|
145
|
+
var HOSTNAME = /^(?=.{1,253}\.?$)[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?(?:\.[a-z0-9](?:[-0-9a-z]{0,61}[0-9a-z])?)*\.?$/i;
|
|
146
|
+
var URIREF = /^(?:[a-z][a-z0-9+\-.]*:)?(?:\/?\/(?:(?:[a-z0-9\-._~!$&'()*+,;=:]|%[0-9a-f]{2})*@)?(?:\[(?:(?:(?:(?:[0-9a-f]{1,4}:){6}|::(?:[0-9a-f]{1,4}:){5}|(?:[0-9a-f]{1,4})?::(?:[0-9a-f]{1,4}:){4}|(?:(?:[0-9a-f]{1,4}:){0,1}[0-9a-f]{1,4})?::(?:[0-9a-f]{1,4}:){3}|(?:(?:[0-9a-f]{1,4}:){0,2}[0-9a-f]{1,4})?::(?:[0-9a-f]{1,4}:){2}|(?:(?:[0-9a-f]{1,4}:){0,3}[0-9a-f]{1,4})?::[0-9a-f]{1,4}:|(?:(?:[0-9a-f]{1,4}:){0,4}[0-9a-f]{1,4})?::)(?:[0-9a-f]{1,4}:[0-9a-f]{1,4}|(?:(?:25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(?:25[0-5]|2[0-4]\d|[01]?\d\d?))|(?:(?:[0-9a-f]{1,4}:){0,5}[0-9a-f]{1,4})?::[0-9a-f]{1,4}|(?:(?:[0-9a-f]{1,4}:){0,6}[0-9a-f]{1,4})?::)|[Vv][0-9a-f]+\.[a-z0-9\-._~!$&'()*+,;=:]+)\]|(?:(?:25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(?:25[0-5]|2[0-4]\d|[01]?\d\d?)|(?:[a-z0-9\-._~!$&'"()*+,;=]|%[0-9a-f]{2})*)(?::\d*)?(?:\/(?:[a-z0-9\-._~!$&'"()*+,;=:@]|%[0-9a-f]{2})*)*|\/(?:(?:[a-z0-9\-._~!$&'"()*+,;=:@]|%[0-9a-f]{2})+(?:\/(?:[a-z0-9\-._~!$&'"()*+,;=:@]|%[0-9a-f]{2})*)*)?|(?:[a-z0-9\-._~!$&'"()*+,;=:@]|%[0-9a-f]{2})+(?:\/(?:[a-z0-9\-._~!$&'"()*+,;=:@]|%[0-9a-f]{2})*)*)?(?:\?(?:[a-z0-9\-._~!$&'"()*+,;=:@/?]|%[0-9a-f]{2})*)?(?:#(?:[a-z0-9\-._~!$&'"()*+,;=:@/?]|%[0-9a-f]{2})*)?$/i;
|
|
147
|
+
var URITEMPLATE = /^(?:(?:[^\x00-\x20"'<>%\\^`{|}]|%[0-9a-f]{2})|\{[+#./;?&=,!@|]?(?:[a-z0-9_]|%[0-9a-f]{2})+(?::[1-9][0-9]{0,3}|\*)?(?:,(?:[a-z0-9_]|%[0-9a-f]{2})+(?::[1-9][0-9]{0,3}|\*)?)*\})*$/i;
|
|
148
|
+
var URL_ = /^(?:(?:https?|ftp):\/\/)(?:\S+(?::\S*)?@)?(?:(?!10(?:\.\d{1,3}){3})(?!127(?:\.\d{1,3}){3})(?!169\.254(?:\.\d{1,3}){2})(?!192\.168(?:\.\d{1,3}){2})(?!172\.(?:1[6-9]|2\d|3[0-1])(?:\.\d{1,3}){2})(?:[1-9]\d?|1\d\d|2[01]\d|22[0-3])(?:\.(?:1?\d{1,2}|2[0-4]\d|25[0-5])){2}(?:\.(?:[1-9]\d?|1\d\d|2[0-4]\d|25[0-4]))|(?:(?:[a-z\u{00a1}-\u{ffff}0-9]+-?)*[a-z\u{00a1}-\u{ffff}0-9]+)(?:\.(?:[a-z\u{00a1}-\u{ffff}0-9]+-?)*[a-z\u{00a1}-\u{ffff}0-9]+)*(?:\.(?:[a-z\u{00a1}-\u{ffff}]{2,})))(?::\d{2,5})?(?:\/[^\s]*)?$/iu;
|
|
149
|
+
var UUID = /^(?:urn:uuid:)?[0-9a-f]{8}-(?:[0-9a-f]{4}-){3}[0-9a-f]{12}$/i;
|
|
150
|
+
var JSON_POINTER = /^(?:\/(?:[^~/]|~0|~1)*)*$/;
|
|
151
|
+
var JSON_POINTER_URI_FRAGMENT = /^#(?:\/(?:[a-z0-9_\-.!$&'()*+,;:=@]|%[0-9a-f]{2}|~0|~1)*)*$/i;
|
|
152
|
+
var RELATIVE_JSON_POINTER = /^(?:0|[1-9][0-9]*)(?:#|(?:\/(?:[^~/]|~0|~1)*)*)$/;
|
|
153
|
+
var EMAIL = (input) => {
|
|
154
|
+
if (input[0] === "\"") return false;
|
|
155
|
+
const [name, host, ...rest] = input.split("@");
|
|
156
|
+
if (!name || !host || rest.length !== 0 || name.length > 64 || host.length > 253) return false;
|
|
157
|
+
if (name[0] === "." || name.endsWith(".") || name.includes("..")) return false;
|
|
158
|
+
if (!/^[a-z0-9.-]+$/i.test(host) || !/^[a-z0-9.!#$%&'*+/=?^_`{|}~-]+$/i.test(name)) return false;
|
|
159
|
+
return host.split(".").every((part) => /^[a-z0-9]([a-z0-9-]{0,61}[a-z0-9])?$/i.test(part));
|
|
160
|
+
};
|
|
161
|
+
var IPV4 = /^(?:(?:25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(?:25[0-5]|2[0-4]\d|[01]?\d\d?)$/;
|
|
162
|
+
var IPV6 = /^((([0-9a-f]{1,4}:){7}([0-9a-f]{1,4}|:))|(([0-9a-f]{1,4}:){6}(:[0-9a-f]{1,4}|((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3})|:))|(([0-9a-f]{1,4}:){5}(((:[0-9a-f]{1,4}){1,2})|:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3})|:))|(([0-9a-f]{1,4}:){4}(((:[0-9a-f]{1,4}){1,3})|((:[0-9a-f]{1,4})?:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9a-f]{1,4}:){3}(((:[0-9a-f]{1,4}){1,4})|((:[0-9a-f]{1,4}){0,2}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9a-f]{1,4}:){2}(((:[0-9a-f]{1,4}){1,5})|((:[0-9a-f]{1,4}){0,3}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9a-f]{1,4}:){1}(((:[0-9a-f]{1,4}){1,6})|((:[0-9a-f]{1,4}){0,4}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(:(((:[0-9a-f]{1,4}){1,7})|((:[0-9a-f]{1,4}){0,5}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:)))$/i;
|
|
163
|
+
var DURATION = (input) => input.length > 1 && input.length < 80 && (/^P\d+([.,]\d+)?W$/.test(input) || /^P[\dYMDTHS]*(\d[.,]\d+)?[YMDHS]$/.test(input) && /^P([.,\d]+Y)?([.,\d]+M)?([.,\d]+D)?(T([.,\d]+H)?([.,\d]+M)?([.,\d]+S)?)?$/.test(input));
|
|
164
|
+
function bind(r) {
|
|
165
|
+
return r.test.bind(r);
|
|
166
|
+
}
|
|
167
|
+
var format = {
|
|
168
|
+
date,
|
|
169
|
+
time: time.bind(void 0, false),
|
|
170
|
+
"date-time": date_time,
|
|
171
|
+
duration: DURATION,
|
|
172
|
+
uri,
|
|
173
|
+
"uri-reference": bind(URIREF),
|
|
174
|
+
"uri-template": bind(URITEMPLATE),
|
|
175
|
+
url: bind(URL_),
|
|
176
|
+
email: EMAIL,
|
|
177
|
+
hostname: bind(HOSTNAME),
|
|
178
|
+
ipv4: bind(IPV4),
|
|
179
|
+
ipv6: bind(IPV6),
|
|
180
|
+
regex,
|
|
181
|
+
uuid: bind(UUID),
|
|
182
|
+
"json-pointer": bind(JSON_POINTER),
|
|
183
|
+
"json-pointer-uri-fragment": bind(JSON_POINTER_URI_FRAGMENT),
|
|
184
|
+
"relative-json-pointer": bind(RELATIVE_JSON_POINTER)
|
|
185
|
+
};
|
|
186
|
+
function isLeapYear(year) {
|
|
187
|
+
return year % 4 === 0 && (year % 100 !== 0 || year % 400 === 0);
|
|
188
|
+
}
|
|
189
|
+
function date(str) {
|
|
190
|
+
const matches = str.match(DATE);
|
|
191
|
+
if (!matches) return false;
|
|
192
|
+
const year = +matches[1];
|
|
193
|
+
const month = +matches[2];
|
|
194
|
+
const day = +matches[3];
|
|
195
|
+
return month >= 1 && month <= 12 && day >= 1 && day <= (month == 2 && isLeapYear(year) ? 29 : DAYS[month]);
|
|
196
|
+
}
|
|
197
|
+
function time(full, str) {
|
|
198
|
+
const matches = str.match(TIME);
|
|
199
|
+
if (!matches) return false;
|
|
200
|
+
const hour = +matches[1];
|
|
201
|
+
const minute = +matches[2];
|
|
202
|
+
const second = +matches[3];
|
|
203
|
+
const timeZone = !!matches[5];
|
|
204
|
+
return (hour <= 23 && minute <= 59 && second <= 59 || hour == 23 && minute == 59 && second == 60) && (!full || timeZone);
|
|
205
|
+
}
|
|
206
|
+
var DATE_TIME_SEPARATOR = /t|\s/i;
|
|
207
|
+
function date_time(str) {
|
|
208
|
+
const dateTime = str.split(DATE_TIME_SEPARATOR);
|
|
209
|
+
return dateTime.length == 2 && date(dateTime[0]) && time(true, dateTime[1]);
|
|
210
|
+
}
|
|
211
|
+
var NOT_URI_FRAGMENT = /\/|:/;
|
|
212
|
+
var URI_PATTERN = /^(?:[a-z][a-z0-9+\-.]*:)(?:\/?\/(?:(?:[a-z0-9\-._~!$&'()*+,;=:]|%[0-9a-f]{2})*@)?(?:\[(?:(?:(?:(?:[0-9a-f]{1,4}:){6}|::(?:[0-9a-f]{1,4}:){5}|(?:[0-9a-f]{1,4})?::(?:[0-9a-f]{1,4}:){4}|(?:(?:[0-9a-f]{1,4}:){0,1}[0-9a-f]{1,4})?::(?:[0-9a-f]{1,4}:){3}|(?:(?:[0-9a-f]{1,4}:){0,2}[0-9a-f]{1,4})?::(?:[0-9a-f]{1,4}:){2}|(?:(?:[0-9a-f]{1,4}:){0,3}[0-9a-f]{1,4})?::[0-9a-f]{1,4}:|(?:(?:[0-9a-f]{1,4}:){0,4}[0-9a-f]{1,4})?::)(?:[0-9a-f]{1,4}:[0-9a-f]{1,4}|(?:(?:25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(?:25[0-5]|2[0-4]\d|[01]?\d\d?))|(?:(?:[0-9a-f]{1,4}:){0,5}[0-9a-f]{1,4})?::[0-9a-f]{1,4}|(?:(?:[0-9a-f]{1,4}:){0,6}[0-9a-f]{1,4})?::)|[Vv][0-9a-f]+\.[a-z0-9\-._~!$&'()*+,;=:]+)\]|(?:(?:25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(?:25[0-5]|2[0-4]\d|[01]?\d\d?)|(?:[a-z0-9\-._~!$&'()*+,;=]|%[0-9a-f]{2})*)(?::\d*)?(?:\/(?:[a-z0-9\-._~!$&'()*+,;=:@]|%[0-9a-f]{2})*)*|\/(?:(?:[a-z0-9\-._~!$&'()*+,;=:@]|%[0-9a-f]{2})+(?:\/(?:[a-z0-9\-._~!$&'()*+,;=:@]|%[0-9a-f]{2})*)*)?|(?:[a-z0-9\-._~!$&'()*+,;=:@]|%[0-9a-f]{2})+(?:\/(?:[a-z0-9\-._~!$&'()*+,;=:@]|%[0-9a-f]{2})*)*)(?:\?(?:[a-z0-9\-._~!$&'()*+,;=:@/?]|%[0-9a-f]{2})*)?(?:#(?:[a-z0-9\-._~!$&'()*+,;=:@/?]|%[0-9a-f]{2})*)?$/i;
|
|
213
|
+
function uri(str) {
|
|
214
|
+
return NOT_URI_FRAGMENT.test(str) && URI_PATTERN.test(str);
|
|
215
|
+
}
|
|
216
|
+
var Z_ANCHOR = /[^\\]\\Z/;
|
|
217
|
+
function regex(str) {
|
|
218
|
+
if (Z_ANCHOR.test(str)) return false;
|
|
219
|
+
try {
|
|
220
|
+
new RegExp(str, "u");
|
|
221
|
+
return true;
|
|
222
|
+
} catch (e) {
|
|
223
|
+
return false;
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
function ucs2length(s) {
|
|
227
|
+
let result = 0;
|
|
228
|
+
let length = s.length;
|
|
229
|
+
let index = 0;
|
|
230
|
+
let charCode;
|
|
231
|
+
while (index < length) {
|
|
232
|
+
result++;
|
|
233
|
+
charCode = s.charCodeAt(index++);
|
|
234
|
+
if (charCode >= 55296 && charCode <= 56319 && index < length) {
|
|
235
|
+
charCode = s.charCodeAt(index);
|
|
236
|
+
if ((charCode & 64512) == 56320) index++;
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
return result;
|
|
240
|
+
}
|
|
241
|
+
function validate(instance, schema, draft = "2019-09", lookup = dereference(schema), shortCircuit = true, recursiveAnchor = null, instanceLocation = "#", schemaLocation = "#", evaluated = Object.create(null)) {
|
|
242
|
+
if (schema === true) return {
|
|
243
|
+
valid: true,
|
|
244
|
+
errors: []
|
|
245
|
+
};
|
|
246
|
+
if (schema === false) return {
|
|
247
|
+
valid: false,
|
|
248
|
+
errors: [{
|
|
249
|
+
instanceLocation,
|
|
250
|
+
keyword: "false",
|
|
251
|
+
keywordLocation: instanceLocation,
|
|
252
|
+
error: "False boolean schema."
|
|
253
|
+
}]
|
|
254
|
+
};
|
|
255
|
+
const rawInstanceType = typeof instance;
|
|
256
|
+
let instanceType;
|
|
257
|
+
switch (rawInstanceType) {
|
|
258
|
+
case "boolean":
|
|
259
|
+
case "number":
|
|
260
|
+
case "string":
|
|
261
|
+
instanceType = rawInstanceType;
|
|
262
|
+
break;
|
|
263
|
+
case "object":
|
|
264
|
+
if (instance === null) instanceType = "null";
|
|
265
|
+
else if (Array.isArray(instance)) instanceType = "array";
|
|
266
|
+
else instanceType = "object";
|
|
267
|
+
break;
|
|
268
|
+
default: throw new Error(`Instances of "${rawInstanceType}" type are not supported.`);
|
|
269
|
+
}
|
|
270
|
+
const { $ref, $recursiveRef, $recursiveAnchor, type: $type, const: $const, enum: $enum, required: $required, not: $not, anyOf: $anyOf, allOf: $allOf, oneOf: $oneOf, if: $if, then: $then, else: $else, format: $format, properties: $properties, patternProperties: $patternProperties, additionalProperties: $additionalProperties, unevaluatedProperties: $unevaluatedProperties, minProperties: $minProperties, maxProperties: $maxProperties, propertyNames: $propertyNames, dependentRequired: $dependentRequired, dependentSchemas: $dependentSchemas, dependencies: $dependencies, prefixItems: $prefixItems, items: $items, additionalItems: $additionalItems, unevaluatedItems: $unevaluatedItems, contains: $contains, minContains: $minContains, maxContains: $maxContains, minItems: $minItems, maxItems: $maxItems, uniqueItems: $uniqueItems, minimum: $minimum, maximum: $maximum, exclusiveMinimum: $exclusiveMinimum, exclusiveMaximum: $exclusiveMaximum, multipleOf: $multipleOf, minLength: $minLength, maxLength: $maxLength, pattern: $pattern, __absolute_ref__, __absolute_recursive_ref__ } = schema;
|
|
271
|
+
const errors = [];
|
|
272
|
+
if ($recursiveAnchor === true && recursiveAnchor === null) recursiveAnchor = schema;
|
|
273
|
+
if ($recursiveRef === "#") {
|
|
274
|
+
const refSchema = recursiveAnchor === null ? lookup[__absolute_recursive_ref__] : recursiveAnchor;
|
|
275
|
+
const keywordLocation = `${schemaLocation}/$recursiveRef`;
|
|
276
|
+
const result = validate(instance, recursiveAnchor === null ? schema : recursiveAnchor, draft, lookup, shortCircuit, refSchema, instanceLocation, keywordLocation, evaluated);
|
|
277
|
+
if (!result.valid) errors.push({
|
|
278
|
+
instanceLocation,
|
|
279
|
+
keyword: "$recursiveRef",
|
|
280
|
+
keywordLocation,
|
|
281
|
+
error: "A subschema had errors."
|
|
282
|
+
}, ...result.errors);
|
|
283
|
+
}
|
|
284
|
+
if ($ref !== void 0) {
|
|
285
|
+
const refSchema = lookup[__absolute_ref__ || $ref];
|
|
286
|
+
if (refSchema === void 0) {
|
|
287
|
+
let message = `Unresolved $ref "${$ref}".`;
|
|
288
|
+
if (__absolute_ref__ && __absolute_ref__ !== $ref) message += ` Absolute URI "${__absolute_ref__}".`;
|
|
289
|
+
message += `\nKnown schemas:\n- ${Object.keys(lookup).join("\n- ")}`;
|
|
290
|
+
throw new Error(message);
|
|
291
|
+
}
|
|
292
|
+
const keywordLocation = `${schemaLocation}/$ref`;
|
|
293
|
+
const result = validate(instance, refSchema, draft, lookup, shortCircuit, recursiveAnchor, instanceLocation, keywordLocation, evaluated);
|
|
294
|
+
if (!result.valid) errors.push({
|
|
295
|
+
instanceLocation,
|
|
296
|
+
keyword: "$ref",
|
|
297
|
+
keywordLocation,
|
|
298
|
+
error: "A subschema had errors."
|
|
299
|
+
}, ...result.errors);
|
|
300
|
+
if (draft === "4" || draft === "7") return {
|
|
301
|
+
valid: errors.length === 0,
|
|
302
|
+
errors
|
|
303
|
+
};
|
|
304
|
+
}
|
|
305
|
+
if (Array.isArray($type)) {
|
|
306
|
+
let length = $type.length;
|
|
307
|
+
let valid = false;
|
|
308
|
+
for (let i = 0; i < length; i++) if (instanceType === $type[i] || $type[i] === "integer" && instanceType === "number" && instance % 1 === 0 && instance === instance) {
|
|
309
|
+
valid = true;
|
|
310
|
+
break;
|
|
311
|
+
}
|
|
312
|
+
if (!valid) errors.push({
|
|
313
|
+
instanceLocation,
|
|
314
|
+
keyword: "type",
|
|
315
|
+
keywordLocation: `${schemaLocation}/type`,
|
|
316
|
+
error: `Instance type "${instanceType}" is invalid. Expected "${$type.join("\", \"")}".`
|
|
317
|
+
});
|
|
318
|
+
} else if ($type === "integer") {
|
|
319
|
+
if (instanceType !== "number" || instance % 1 || instance !== instance) errors.push({
|
|
320
|
+
instanceLocation,
|
|
321
|
+
keyword: "type",
|
|
322
|
+
keywordLocation: `${schemaLocation}/type`,
|
|
323
|
+
error: `Instance type "${instanceType}" is invalid. Expected "${$type}".`
|
|
324
|
+
});
|
|
325
|
+
} else if ($type !== void 0 && instanceType !== $type) errors.push({
|
|
326
|
+
instanceLocation,
|
|
327
|
+
keyword: "type",
|
|
328
|
+
keywordLocation: `${schemaLocation}/type`,
|
|
329
|
+
error: `Instance type "${instanceType}" is invalid. Expected "${$type}".`
|
|
330
|
+
});
|
|
331
|
+
if ($const !== void 0) {
|
|
332
|
+
if (instanceType === "object" || instanceType === "array") {
|
|
333
|
+
if (!deepCompareStrict(instance, $const)) errors.push({
|
|
334
|
+
instanceLocation,
|
|
335
|
+
keyword: "const",
|
|
336
|
+
keywordLocation: `${schemaLocation}/const`,
|
|
337
|
+
error: `Instance does not match ${JSON.stringify($const)}.`
|
|
338
|
+
});
|
|
339
|
+
} else if (instance !== $const) errors.push({
|
|
340
|
+
instanceLocation,
|
|
341
|
+
keyword: "const",
|
|
342
|
+
keywordLocation: `${schemaLocation}/const`,
|
|
343
|
+
error: `Instance does not match ${JSON.stringify($const)}.`
|
|
344
|
+
});
|
|
345
|
+
}
|
|
346
|
+
if ($enum !== void 0) {
|
|
347
|
+
if (instanceType === "object" || instanceType === "array") {
|
|
348
|
+
if (!$enum.some((value) => deepCompareStrict(instance, value))) errors.push({
|
|
349
|
+
instanceLocation,
|
|
350
|
+
keyword: "enum",
|
|
351
|
+
keywordLocation: `${schemaLocation}/enum`,
|
|
352
|
+
error: `Instance does not match any of ${JSON.stringify($enum)}.`
|
|
353
|
+
});
|
|
354
|
+
} else if (!$enum.some((value) => instance === value)) errors.push({
|
|
355
|
+
instanceLocation,
|
|
356
|
+
keyword: "enum",
|
|
357
|
+
keywordLocation: `${schemaLocation}/enum`,
|
|
358
|
+
error: `Instance does not match any of ${JSON.stringify($enum)}.`
|
|
359
|
+
});
|
|
360
|
+
}
|
|
361
|
+
if ($not !== void 0) {
|
|
362
|
+
const keywordLocation = `${schemaLocation}/not`;
|
|
363
|
+
if (validate(instance, $not, draft, lookup, shortCircuit, recursiveAnchor, instanceLocation, keywordLocation).valid) errors.push({
|
|
364
|
+
instanceLocation,
|
|
365
|
+
keyword: "not",
|
|
366
|
+
keywordLocation,
|
|
367
|
+
error: "Instance matched \"not\" schema."
|
|
368
|
+
});
|
|
369
|
+
}
|
|
370
|
+
let subEvaluateds = [];
|
|
371
|
+
if ($anyOf !== void 0) {
|
|
372
|
+
const keywordLocation = `${schemaLocation}/anyOf`;
|
|
373
|
+
const errorsLength = errors.length;
|
|
374
|
+
let anyValid = false;
|
|
375
|
+
for (let i = 0; i < $anyOf.length; i++) {
|
|
376
|
+
const subSchema = $anyOf[i];
|
|
377
|
+
const subEvaluated = Object.create(evaluated);
|
|
378
|
+
const result = validate(instance, subSchema, draft, lookup, shortCircuit, $recursiveAnchor === true ? recursiveAnchor : null, instanceLocation, `${keywordLocation}/${i}`, subEvaluated);
|
|
379
|
+
errors.push(...result.errors);
|
|
380
|
+
anyValid = anyValid || result.valid;
|
|
381
|
+
if (result.valid) subEvaluateds.push(subEvaluated);
|
|
382
|
+
}
|
|
383
|
+
if (anyValid) errors.length = errorsLength;
|
|
384
|
+
else errors.splice(errorsLength, 0, {
|
|
385
|
+
instanceLocation,
|
|
386
|
+
keyword: "anyOf",
|
|
387
|
+
keywordLocation,
|
|
388
|
+
error: "Instance does not match any subschemas."
|
|
389
|
+
});
|
|
390
|
+
}
|
|
391
|
+
if ($allOf !== void 0) {
|
|
392
|
+
const keywordLocation = `${schemaLocation}/allOf`;
|
|
393
|
+
const errorsLength = errors.length;
|
|
394
|
+
let allValid = true;
|
|
395
|
+
for (let i = 0; i < $allOf.length; i++) {
|
|
396
|
+
const subSchema = $allOf[i];
|
|
397
|
+
const subEvaluated = Object.create(evaluated);
|
|
398
|
+
const result = validate(instance, subSchema, draft, lookup, shortCircuit, $recursiveAnchor === true ? recursiveAnchor : null, instanceLocation, `${keywordLocation}/${i}`, subEvaluated);
|
|
399
|
+
errors.push(...result.errors);
|
|
400
|
+
allValid = allValid && result.valid;
|
|
401
|
+
if (result.valid) subEvaluateds.push(subEvaluated);
|
|
402
|
+
}
|
|
403
|
+
if (allValid) errors.length = errorsLength;
|
|
404
|
+
else errors.splice(errorsLength, 0, {
|
|
405
|
+
instanceLocation,
|
|
406
|
+
keyword: "allOf",
|
|
407
|
+
keywordLocation,
|
|
408
|
+
error: `Instance does not match every subschema.`
|
|
409
|
+
});
|
|
410
|
+
}
|
|
411
|
+
if ($oneOf !== void 0) {
|
|
412
|
+
const keywordLocation = `${schemaLocation}/oneOf`;
|
|
413
|
+
const errorsLength = errors.length;
|
|
414
|
+
const matches = $oneOf.filter((subSchema, i) => {
|
|
415
|
+
const subEvaluated = Object.create(evaluated);
|
|
416
|
+
const result = validate(instance, subSchema, draft, lookup, shortCircuit, $recursiveAnchor === true ? recursiveAnchor : null, instanceLocation, `${keywordLocation}/${i}`, subEvaluated);
|
|
417
|
+
errors.push(...result.errors);
|
|
418
|
+
if (result.valid) subEvaluateds.push(subEvaluated);
|
|
419
|
+
return result.valid;
|
|
420
|
+
}).length;
|
|
421
|
+
if (matches === 1) errors.length = errorsLength;
|
|
422
|
+
else errors.splice(errorsLength, 0, {
|
|
423
|
+
instanceLocation,
|
|
424
|
+
keyword: "oneOf",
|
|
425
|
+
keywordLocation,
|
|
426
|
+
error: `Instance does not match exactly one subschema (${matches} matches).`
|
|
427
|
+
});
|
|
428
|
+
}
|
|
429
|
+
if (instanceType === "object" || instanceType === "array") Object.assign(evaluated, ...subEvaluateds);
|
|
430
|
+
if ($if !== void 0) {
|
|
431
|
+
const keywordLocation = `${schemaLocation}/if`;
|
|
432
|
+
if (validate(instance, $if, draft, lookup, shortCircuit, recursiveAnchor, instanceLocation, keywordLocation, evaluated).valid) {
|
|
433
|
+
if ($then !== void 0) {
|
|
434
|
+
const thenResult = validate(instance, $then, draft, lookup, shortCircuit, recursiveAnchor, instanceLocation, `${schemaLocation}/then`, evaluated);
|
|
435
|
+
if (!thenResult.valid) errors.push({
|
|
436
|
+
instanceLocation,
|
|
437
|
+
keyword: "if",
|
|
438
|
+
keywordLocation,
|
|
439
|
+
error: `Instance does not match "then" schema.`
|
|
440
|
+
}, ...thenResult.errors);
|
|
441
|
+
}
|
|
442
|
+
} else if ($else !== void 0) {
|
|
443
|
+
const elseResult = validate(instance, $else, draft, lookup, shortCircuit, recursiveAnchor, instanceLocation, `${schemaLocation}/else`, evaluated);
|
|
444
|
+
if (!elseResult.valid) errors.push({
|
|
445
|
+
instanceLocation,
|
|
446
|
+
keyword: "if",
|
|
447
|
+
keywordLocation,
|
|
448
|
+
error: `Instance does not match "else" schema.`
|
|
449
|
+
}, ...elseResult.errors);
|
|
450
|
+
}
|
|
451
|
+
}
|
|
452
|
+
if (instanceType === "object") {
|
|
453
|
+
if ($required !== void 0) {
|
|
454
|
+
for (const key of $required) if (!(key in instance)) errors.push({
|
|
455
|
+
instanceLocation,
|
|
456
|
+
keyword: "required",
|
|
457
|
+
keywordLocation: `${schemaLocation}/required`,
|
|
458
|
+
error: `Instance does not have required property "${key}".`
|
|
459
|
+
});
|
|
460
|
+
}
|
|
461
|
+
const keys = Object.keys(instance);
|
|
462
|
+
if ($minProperties !== void 0 && keys.length < $minProperties) errors.push({
|
|
463
|
+
instanceLocation,
|
|
464
|
+
keyword: "minProperties",
|
|
465
|
+
keywordLocation: `${schemaLocation}/minProperties`,
|
|
466
|
+
error: `Instance does not have at least ${$minProperties} properties.`
|
|
467
|
+
});
|
|
468
|
+
if ($maxProperties !== void 0 && keys.length > $maxProperties) errors.push({
|
|
469
|
+
instanceLocation,
|
|
470
|
+
keyword: "maxProperties",
|
|
471
|
+
keywordLocation: `${schemaLocation}/maxProperties`,
|
|
472
|
+
error: `Instance does not have at least ${$maxProperties} properties.`
|
|
473
|
+
});
|
|
474
|
+
if ($propertyNames !== void 0) {
|
|
475
|
+
const keywordLocation = `${schemaLocation}/propertyNames`;
|
|
476
|
+
for (const key in instance) {
|
|
477
|
+
const subInstancePointer = `${instanceLocation}/${encodePointer(key)}`;
|
|
478
|
+
const result = validate(key, $propertyNames, draft, lookup, shortCircuit, recursiveAnchor, subInstancePointer, keywordLocation);
|
|
479
|
+
if (!result.valid) errors.push({
|
|
480
|
+
instanceLocation,
|
|
481
|
+
keyword: "propertyNames",
|
|
482
|
+
keywordLocation,
|
|
483
|
+
error: `Property name "${key}" does not match schema.`
|
|
484
|
+
}, ...result.errors);
|
|
485
|
+
}
|
|
486
|
+
}
|
|
487
|
+
if ($dependentRequired !== void 0) {
|
|
488
|
+
const keywordLocation = `${schemaLocation}/dependantRequired`;
|
|
489
|
+
for (const key in $dependentRequired) if (key in instance) {
|
|
490
|
+
const required = $dependentRequired[key];
|
|
491
|
+
for (const dependantKey of required) if (!(dependantKey in instance)) errors.push({
|
|
492
|
+
instanceLocation,
|
|
493
|
+
keyword: "dependentRequired",
|
|
494
|
+
keywordLocation,
|
|
495
|
+
error: `Instance has "${key}" but does not have "${dependantKey}".`
|
|
496
|
+
});
|
|
497
|
+
}
|
|
498
|
+
}
|
|
499
|
+
if ($dependentSchemas !== void 0) for (const key in $dependentSchemas) {
|
|
500
|
+
const keywordLocation = `${schemaLocation}/dependentSchemas`;
|
|
501
|
+
if (key in instance) {
|
|
502
|
+
const result = validate(instance, $dependentSchemas[key], draft, lookup, shortCircuit, recursiveAnchor, instanceLocation, `${keywordLocation}/${encodePointer(key)}`, evaluated);
|
|
503
|
+
if (!result.valid) errors.push({
|
|
504
|
+
instanceLocation,
|
|
505
|
+
keyword: "dependentSchemas",
|
|
506
|
+
keywordLocation,
|
|
507
|
+
error: `Instance has "${key}" but does not match dependant schema.`
|
|
508
|
+
}, ...result.errors);
|
|
509
|
+
}
|
|
510
|
+
}
|
|
511
|
+
if ($dependencies !== void 0) {
|
|
512
|
+
const keywordLocation = `${schemaLocation}/dependencies`;
|
|
513
|
+
for (const key in $dependencies) if (key in instance) {
|
|
514
|
+
const propsOrSchema = $dependencies[key];
|
|
515
|
+
if (Array.isArray(propsOrSchema)) {
|
|
516
|
+
for (const dependantKey of propsOrSchema) if (!(dependantKey in instance)) errors.push({
|
|
517
|
+
instanceLocation,
|
|
518
|
+
keyword: "dependencies",
|
|
519
|
+
keywordLocation,
|
|
520
|
+
error: `Instance has "${key}" but does not have "${dependantKey}".`
|
|
521
|
+
});
|
|
522
|
+
} else {
|
|
523
|
+
const result = validate(instance, propsOrSchema, draft, lookup, shortCircuit, recursiveAnchor, instanceLocation, `${keywordLocation}/${encodePointer(key)}`);
|
|
524
|
+
if (!result.valid) errors.push({
|
|
525
|
+
instanceLocation,
|
|
526
|
+
keyword: "dependencies",
|
|
527
|
+
keywordLocation,
|
|
528
|
+
error: `Instance has "${key}" but does not match dependant schema.`
|
|
529
|
+
}, ...result.errors);
|
|
530
|
+
}
|
|
531
|
+
}
|
|
532
|
+
}
|
|
533
|
+
const thisEvaluated = Object.create(null);
|
|
534
|
+
let stop = false;
|
|
535
|
+
if ($properties !== void 0) {
|
|
536
|
+
const keywordLocation = `${schemaLocation}/properties`;
|
|
537
|
+
for (const key in $properties) {
|
|
538
|
+
if (!(key in instance)) continue;
|
|
539
|
+
const subInstancePointer = `${instanceLocation}/${encodePointer(key)}`;
|
|
540
|
+
const result = validate(instance[key], $properties[key], draft, lookup, shortCircuit, recursiveAnchor, subInstancePointer, `${keywordLocation}/${encodePointer(key)}`);
|
|
541
|
+
if (result.valid) evaluated[key] = thisEvaluated[key] = true;
|
|
542
|
+
else {
|
|
543
|
+
stop = shortCircuit;
|
|
544
|
+
errors.push({
|
|
545
|
+
instanceLocation,
|
|
546
|
+
keyword: "properties",
|
|
547
|
+
keywordLocation,
|
|
548
|
+
error: `Property "${key}" does not match schema.`
|
|
549
|
+
}, ...result.errors);
|
|
550
|
+
if (stop) break;
|
|
551
|
+
}
|
|
552
|
+
}
|
|
553
|
+
}
|
|
554
|
+
if (!stop && $patternProperties !== void 0) {
|
|
555
|
+
const keywordLocation = `${schemaLocation}/patternProperties`;
|
|
556
|
+
for (const pattern in $patternProperties) {
|
|
557
|
+
const regex = new RegExp(pattern, "u");
|
|
558
|
+
const subSchema = $patternProperties[pattern];
|
|
559
|
+
for (const key in instance) {
|
|
560
|
+
if (!regex.test(key)) continue;
|
|
561
|
+
const subInstancePointer = `${instanceLocation}/${encodePointer(key)}`;
|
|
562
|
+
const result = validate(instance[key], subSchema, draft, lookup, shortCircuit, recursiveAnchor, subInstancePointer, `${keywordLocation}/${encodePointer(pattern)}`);
|
|
563
|
+
if (result.valid) evaluated[key] = thisEvaluated[key] = true;
|
|
564
|
+
else {
|
|
565
|
+
stop = shortCircuit;
|
|
566
|
+
errors.push({
|
|
567
|
+
instanceLocation,
|
|
568
|
+
keyword: "patternProperties",
|
|
569
|
+
keywordLocation,
|
|
570
|
+
error: `Property "${key}" matches pattern "${pattern}" but does not match associated schema.`
|
|
571
|
+
}, ...result.errors);
|
|
572
|
+
}
|
|
573
|
+
}
|
|
574
|
+
}
|
|
575
|
+
}
|
|
576
|
+
if (!stop && $additionalProperties !== void 0) {
|
|
577
|
+
const keywordLocation = `${schemaLocation}/additionalProperties`;
|
|
578
|
+
for (const key in instance) {
|
|
579
|
+
if (thisEvaluated[key]) continue;
|
|
580
|
+
const subInstancePointer = `${instanceLocation}/${encodePointer(key)}`;
|
|
581
|
+
const result = validate(instance[key], $additionalProperties, draft, lookup, shortCircuit, recursiveAnchor, subInstancePointer, keywordLocation);
|
|
582
|
+
if (result.valid) evaluated[key] = true;
|
|
583
|
+
else {
|
|
584
|
+
stop = shortCircuit;
|
|
585
|
+
errors.push({
|
|
586
|
+
instanceLocation,
|
|
587
|
+
keyword: "additionalProperties",
|
|
588
|
+
keywordLocation,
|
|
589
|
+
error: `Property "${key}" does not match additional properties schema.`
|
|
590
|
+
}, ...result.errors);
|
|
591
|
+
}
|
|
592
|
+
}
|
|
593
|
+
} else if (!stop && $unevaluatedProperties !== void 0) {
|
|
594
|
+
const keywordLocation = `${schemaLocation}/unevaluatedProperties`;
|
|
595
|
+
for (const key in instance) if (!evaluated[key]) {
|
|
596
|
+
const subInstancePointer = `${instanceLocation}/${encodePointer(key)}`;
|
|
597
|
+
const result = validate(instance[key], $unevaluatedProperties, draft, lookup, shortCircuit, recursiveAnchor, subInstancePointer, keywordLocation);
|
|
598
|
+
if (result.valid) evaluated[key] = true;
|
|
599
|
+
else errors.push({
|
|
600
|
+
instanceLocation,
|
|
601
|
+
keyword: "unevaluatedProperties",
|
|
602
|
+
keywordLocation,
|
|
603
|
+
error: `Property "${key}" does not match unevaluated properties schema.`
|
|
604
|
+
}, ...result.errors);
|
|
605
|
+
}
|
|
606
|
+
}
|
|
607
|
+
} else if (instanceType === "array") {
|
|
608
|
+
if ($maxItems !== void 0 && instance.length > $maxItems) errors.push({
|
|
609
|
+
instanceLocation,
|
|
610
|
+
keyword: "maxItems",
|
|
611
|
+
keywordLocation: `${schemaLocation}/maxItems`,
|
|
612
|
+
error: `Array has too many items (${instance.length} > ${$maxItems}).`
|
|
613
|
+
});
|
|
614
|
+
if ($minItems !== void 0 && instance.length < $minItems) errors.push({
|
|
615
|
+
instanceLocation,
|
|
616
|
+
keyword: "minItems",
|
|
617
|
+
keywordLocation: `${schemaLocation}/minItems`,
|
|
618
|
+
error: `Array has too few items (${instance.length} < ${$minItems}).`
|
|
619
|
+
});
|
|
620
|
+
const length = instance.length;
|
|
621
|
+
let i = 0;
|
|
622
|
+
let stop = false;
|
|
623
|
+
if ($prefixItems !== void 0) {
|
|
624
|
+
const keywordLocation = `${schemaLocation}/prefixItems`;
|
|
625
|
+
const length2 = Math.min($prefixItems.length, length);
|
|
626
|
+
for (; i < length2; i++) {
|
|
627
|
+
const result = validate(instance[i], $prefixItems[i], draft, lookup, shortCircuit, recursiveAnchor, `${instanceLocation}/${i}`, `${keywordLocation}/${i}`);
|
|
628
|
+
evaluated[i] = true;
|
|
629
|
+
if (!result.valid) {
|
|
630
|
+
stop = shortCircuit;
|
|
631
|
+
errors.push({
|
|
632
|
+
instanceLocation,
|
|
633
|
+
keyword: "prefixItems",
|
|
634
|
+
keywordLocation,
|
|
635
|
+
error: `Items did not match schema.`
|
|
636
|
+
}, ...result.errors);
|
|
637
|
+
if (stop) break;
|
|
638
|
+
}
|
|
639
|
+
}
|
|
640
|
+
}
|
|
641
|
+
if ($items !== void 0) {
|
|
642
|
+
const keywordLocation = `${schemaLocation}/items`;
|
|
643
|
+
if (Array.isArray($items)) {
|
|
644
|
+
const length2 = Math.min($items.length, length);
|
|
645
|
+
for (; i < length2; i++) {
|
|
646
|
+
const result = validate(instance[i], $items[i], draft, lookup, shortCircuit, recursiveAnchor, `${instanceLocation}/${i}`, `${keywordLocation}/${i}`);
|
|
647
|
+
evaluated[i] = true;
|
|
648
|
+
if (!result.valid) {
|
|
649
|
+
stop = shortCircuit;
|
|
650
|
+
errors.push({
|
|
651
|
+
instanceLocation,
|
|
652
|
+
keyword: "items",
|
|
653
|
+
keywordLocation,
|
|
654
|
+
error: `Items did not match schema.`
|
|
655
|
+
}, ...result.errors);
|
|
656
|
+
if (stop) break;
|
|
657
|
+
}
|
|
658
|
+
}
|
|
659
|
+
} else for (; i < length; i++) {
|
|
660
|
+
const result = validate(instance[i], $items, draft, lookup, shortCircuit, recursiveAnchor, `${instanceLocation}/${i}`, keywordLocation);
|
|
661
|
+
evaluated[i] = true;
|
|
662
|
+
if (!result.valid) {
|
|
663
|
+
stop = shortCircuit;
|
|
664
|
+
errors.push({
|
|
665
|
+
instanceLocation,
|
|
666
|
+
keyword: "items",
|
|
667
|
+
keywordLocation,
|
|
668
|
+
error: `Items did not match schema.`
|
|
669
|
+
}, ...result.errors);
|
|
670
|
+
if (stop) break;
|
|
671
|
+
}
|
|
672
|
+
}
|
|
673
|
+
if (!stop && $additionalItems !== void 0) {
|
|
674
|
+
const keywordLocation = `${schemaLocation}/additionalItems`;
|
|
675
|
+
for (; i < length; i++) {
|
|
676
|
+
const result = validate(instance[i], $additionalItems, draft, lookup, shortCircuit, recursiveAnchor, `${instanceLocation}/${i}`, keywordLocation);
|
|
677
|
+
evaluated[i] = true;
|
|
678
|
+
if (!result.valid) {
|
|
679
|
+
stop = shortCircuit;
|
|
680
|
+
errors.push({
|
|
681
|
+
instanceLocation,
|
|
682
|
+
keyword: "additionalItems",
|
|
683
|
+
keywordLocation,
|
|
684
|
+
error: `Items did not match additional items schema.`
|
|
685
|
+
}, ...result.errors);
|
|
686
|
+
}
|
|
687
|
+
}
|
|
688
|
+
}
|
|
689
|
+
}
|
|
690
|
+
if ($contains !== void 0) {
|
|
691
|
+
if (length === 0 && $minContains === void 0) errors.push({
|
|
692
|
+
instanceLocation,
|
|
693
|
+
keyword: "contains",
|
|
694
|
+
keywordLocation: `${schemaLocation}/contains`,
|
|
695
|
+
error: `Array is empty. It must contain at least one item matching the schema.`
|
|
696
|
+
});
|
|
697
|
+
else if ($minContains !== void 0 && length < $minContains) errors.push({
|
|
698
|
+
instanceLocation,
|
|
699
|
+
keyword: "minContains",
|
|
700
|
+
keywordLocation: `${schemaLocation}/minContains`,
|
|
701
|
+
error: `Array has less items (${length}) than minContains (${$minContains}).`
|
|
702
|
+
});
|
|
703
|
+
else {
|
|
704
|
+
const keywordLocation = `${schemaLocation}/contains`;
|
|
705
|
+
const errorsLength = errors.length;
|
|
706
|
+
let contained = 0;
|
|
707
|
+
for (let j = 0; j < length; j++) {
|
|
708
|
+
const result = validate(instance[j], $contains, draft, lookup, shortCircuit, recursiveAnchor, `${instanceLocation}/${j}`, keywordLocation);
|
|
709
|
+
if (result.valid) {
|
|
710
|
+
evaluated[j] = true;
|
|
711
|
+
contained++;
|
|
712
|
+
} else errors.push(...result.errors);
|
|
713
|
+
}
|
|
714
|
+
if (contained >= ($minContains || 0)) errors.length = errorsLength;
|
|
715
|
+
if ($minContains === void 0 && $maxContains === void 0 && contained === 0) errors.splice(errorsLength, 0, {
|
|
716
|
+
instanceLocation,
|
|
717
|
+
keyword: "contains",
|
|
718
|
+
keywordLocation,
|
|
719
|
+
error: `Array does not contain item matching schema.`
|
|
720
|
+
});
|
|
721
|
+
else if ($minContains !== void 0 && contained < $minContains) errors.push({
|
|
722
|
+
instanceLocation,
|
|
723
|
+
keyword: "minContains",
|
|
724
|
+
keywordLocation: `${schemaLocation}/minContains`,
|
|
725
|
+
error: `Array must contain at least ${$minContains} items matching schema. Only ${contained} items were found.`
|
|
726
|
+
});
|
|
727
|
+
else if ($maxContains !== void 0 && contained > $maxContains) errors.push({
|
|
728
|
+
instanceLocation,
|
|
729
|
+
keyword: "maxContains",
|
|
730
|
+
keywordLocation: `${schemaLocation}/maxContains`,
|
|
731
|
+
error: `Array may contain at most ${$maxContains} items matching schema. ${contained} items were found.`
|
|
732
|
+
});
|
|
733
|
+
}
|
|
734
|
+
}
|
|
735
|
+
if (!stop && $unevaluatedItems !== void 0) {
|
|
736
|
+
const keywordLocation = `${schemaLocation}/unevaluatedItems`;
|
|
737
|
+
for (; i < length; i++) {
|
|
738
|
+
if (evaluated[i]) continue;
|
|
739
|
+
const result = validate(instance[i], $unevaluatedItems, draft, lookup, shortCircuit, recursiveAnchor, `${instanceLocation}/${i}`, keywordLocation);
|
|
740
|
+
evaluated[i] = true;
|
|
741
|
+
if (!result.valid) errors.push({
|
|
742
|
+
instanceLocation,
|
|
743
|
+
keyword: "unevaluatedItems",
|
|
744
|
+
keywordLocation,
|
|
745
|
+
error: `Items did not match unevaluated items schema.`
|
|
746
|
+
}, ...result.errors);
|
|
747
|
+
}
|
|
748
|
+
}
|
|
749
|
+
if ($uniqueItems) for (let j = 0; j < length; j++) {
|
|
750
|
+
const a = instance[j];
|
|
751
|
+
const ao = typeof a === "object" && a !== null;
|
|
752
|
+
for (let k = 0; k < length; k++) {
|
|
753
|
+
if (j === k) continue;
|
|
754
|
+
const b = instance[k];
|
|
755
|
+
if (a === b || ao && typeof b === "object" && b !== null && deepCompareStrict(a, b)) {
|
|
756
|
+
errors.push({
|
|
757
|
+
instanceLocation,
|
|
758
|
+
keyword: "uniqueItems",
|
|
759
|
+
keywordLocation: `${schemaLocation}/uniqueItems`,
|
|
760
|
+
error: `Duplicate items at indexes ${j} and ${k}.`
|
|
761
|
+
});
|
|
762
|
+
j = Number.MAX_SAFE_INTEGER;
|
|
763
|
+
k = Number.MAX_SAFE_INTEGER;
|
|
764
|
+
}
|
|
765
|
+
}
|
|
766
|
+
}
|
|
767
|
+
} else if (instanceType === "number") {
|
|
768
|
+
if (draft === "4") {
|
|
769
|
+
if ($minimum !== void 0 && ($exclusiveMinimum === true && instance <= $minimum || instance < $minimum)) errors.push({
|
|
770
|
+
instanceLocation,
|
|
771
|
+
keyword: "minimum",
|
|
772
|
+
keywordLocation: `${schemaLocation}/minimum`,
|
|
773
|
+
error: `${instance} is less than ${$exclusiveMinimum ? "or equal to " : ""} ${$minimum}.`
|
|
774
|
+
});
|
|
775
|
+
if ($maximum !== void 0 && ($exclusiveMaximum === true && instance >= $maximum || instance > $maximum)) errors.push({
|
|
776
|
+
instanceLocation,
|
|
777
|
+
keyword: "maximum",
|
|
778
|
+
keywordLocation: `${schemaLocation}/maximum`,
|
|
779
|
+
error: `${instance} is greater than ${$exclusiveMaximum ? "or equal to " : ""} ${$maximum}.`
|
|
780
|
+
});
|
|
781
|
+
} else {
|
|
782
|
+
if ($minimum !== void 0 && instance < $minimum) errors.push({
|
|
783
|
+
instanceLocation,
|
|
784
|
+
keyword: "minimum",
|
|
785
|
+
keywordLocation: `${schemaLocation}/minimum`,
|
|
786
|
+
error: `${instance} is less than ${$minimum}.`
|
|
787
|
+
});
|
|
788
|
+
if ($maximum !== void 0 && instance > $maximum) errors.push({
|
|
789
|
+
instanceLocation,
|
|
790
|
+
keyword: "maximum",
|
|
791
|
+
keywordLocation: `${schemaLocation}/maximum`,
|
|
792
|
+
error: `${instance} is greater than ${$maximum}.`
|
|
793
|
+
});
|
|
794
|
+
if ($exclusiveMinimum !== void 0 && instance <= $exclusiveMinimum) errors.push({
|
|
795
|
+
instanceLocation,
|
|
796
|
+
keyword: "exclusiveMinimum",
|
|
797
|
+
keywordLocation: `${schemaLocation}/exclusiveMinimum`,
|
|
798
|
+
error: `${instance} is less than ${$exclusiveMinimum}.`
|
|
799
|
+
});
|
|
800
|
+
if ($exclusiveMaximum !== void 0 && instance >= $exclusiveMaximum) errors.push({
|
|
801
|
+
instanceLocation,
|
|
802
|
+
keyword: "exclusiveMaximum",
|
|
803
|
+
keywordLocation: `${schemaLocation}/exclusiveMaximum`,
|
|
804
|
+
error: `${instance} is greater than or equal to ${$exclusiveMaximum}.`
|
|
805
|
+
});
|
|
806
|
+
}
|
|
807
|
+
if ($multipleOf !== void 0) {
|
|
808
|
+
const remainder = instance % $multipleOf;
|
|
809
|
+
if (Math.abs(0 - remainder) >= 1.1920929e-7 && Math.abs($multipleOf - remainder) >= 1.1920929e-7) errors.push({
|
|
810
|
+
instanceLocation,
|
|
811
|
+
keyword: "multipleOf",
|
|
812
|
+
keywordLocation: `${schemaLocation}/multipleOf`,
|
|
813
|
+
error: `${instance} is not a multiple of ${$multipleOf}.`
|
|
814
|
+
});
|
|
815
|
+
}
|
|
816
|
+
} else if (instanceType === "string") {
|
|
817
|
+
const length = $minLength === void 0 && $maxLength === void 0 ? 0 : ucs2length(instance);
|
|
818
|
+
if ($minLength !== void 0 && length < $minLength) errors.push({
|
|
819
|
+
instanceLocation,
|
|
820
|
+
keyword: "minLength",
|
|
821
|
+
keywordLocation: `${schemaLocation}/minLength`,
|
|
822
|
+
error: `String is too short (${length} < ${$minLength}).`
|
|
823
|
+
});
|
|
824
|
+
if ($maxLength !== void 0 && length > $maxLength) errors.push({
|
|
825
|
+
instanceLocation,
|
|
826
|
+
keyword: "maxLength",
|
|
827
|
+
keywordLocation: `${schemaLocation}/maxLength`,
|
|
828
|
+
error: `String is too long (${length} > ${$maxLength}).`
|
|
829
|
+
});
|
|
830
|
+
if ($pattern !== void 0 && !new RegExp($pattern, "u").test(instance)) errors.push({
|
|
831
|
+
instanceLocation,
|
|
832
|
+
keyword: "pattern",
|
|
833
|
+
keywordLocation: `${schemaLocation}/pattern`,
|
|
834
|
+
error: `String does not match pattern.`
|
|
835
|
+
});
|
|
836
|
+
if ($format !== void 0 && format[$format] && !format[$format](instance)) errors.push({
|
|
837
|
+
instanceLocation,
|
|
838
|
+
keyword: "format",
|
|
839
|
+
keywordLocation: `${schemaLocation}/format`,
|
|
840
|
+
error: `String does not match format "${$format}".`
|
|
841
|
+
});
|
|
842
|
+
}
|
|
843
|
+
return {
|
|
844
|
+
valid: errors.length === 0,
|
|
845
|
+
errors
|
|
846
|
+
};
|
|
847
|
+
}
|
|
848
|
+
var Validator = class {
|
|
849
|
+
schema;
|
|
850
|
+
draft;
|
|
851
|
+
shortCircuit;
|
|
852
|
+
lookup;
|
|
853
|
+
constructor(schema, draft = "2019-09", shortCircuit = true) {
|
|
854
|
+
this.schema = schema;
|
|
855
|
+
this.draft = draft;
|
|
856
|
+
this.shortCircuit = shortCircuit;
|
|
857
|
+
this.lookup = dereference(schema);
|
|
858
|
+
}
|
|
859
|
+
validate(instance) {
|
|
860
|
+
return validate(instance, this.schema, this.draft, this.lookup, this.shortCircuit);
|
|
861
|
+
}
|
|
862
|
+
addSchema(schema, id) {
|
|
863
|
+
if (id) schema = {
|
|
864
|
+
...schema,
|
|
865
|
+
$id: id
|
|
866
|
+
};
|
|
867
|
+
dereference(schema, this.lookup);
|
|
868
|
+
}
|
|
869
|
+
};
|
|
870
|
+
var META_ROOT = {
|
|
871
|
+
$schema: "https://json-schema.org/draft/2020-12/schema",
|
|
872
|
+
$id: "https://json-schema.org/draft/2020-12/schema",
|
|
873
|
+
$vocabulary: {
|
|
874
|
+
"https://json-schema.org/draft/2020-12/vocab/core": true,
|
|
875
|
+
"https://json-schema.org/draft/2020-12/vocab/applicator": true,
|
|
876
|
+
"https://json-schema.org/draft/2020-12/vocab/unevaluated": true,
|
|
877
|
+
"https://json-schema.org/draft/2020-12/vocab/validation": true,
|
|
878
|
+
"https://json-schema.org/draft/2020-12/vocab/meta-data": true,
|
|
879
|
+
"https://json-schema.org/draft/2020-12/vocab/format-annotation": true,
|
|
880
|
+
"https://json-schema.org/draft/2020-12/vocab/content": true
|
|
881
|
+
},
|
|
882
|
+
$dynamicAnchor: "meta",
|
|
883
|
+
title: "Core and Validation specifications meta-schema",
|
|
884
|
+
allOf: [
|
|
885
|
+
{ $ref: "meta/core" },
|
|
886
|
+
{ $ref: "meta/applicator" },
|
|
887
|
+
{ $ref: "meta/unevaluated" },
|
|
888
|
+
{ $ref: "meta/validation" },
|
|
889
|
+
{ $ref: "meta/meta-data" },
|
|
890
|
+
{ $ref: "meta/format-annotation" },
|
|
891
|
+
{ $ref: "meta/content" }
|
|
892
|
+
],
|
|
893
|
+
type: ["object", "boolean"],
|
|
894
|
+
$comment: "This meta-schema also defines keywords that have appeared in previous drafts in order to prevent incompatible extensions as they remain in common use.",
|
|
895
|
+
properties: {
|
|
896
|
+
definitions: {
|
|
897
|
+
$comment: "\"definitions\" has been replaced by \"$defs\".",
|
|
898
|
+
type: "object",
|
|
899
|
+
additionalProperties: { $dynamicRef: "#meta" },
|
|
900
|
+
deprecated: true,
|
|
901
|
+
default: {}
|
|
902
|
+
},
|
|
903
|
+
dependencies: {
|
|
904
|
+
$comment: "\"dependencies\" has been split and replaced by \"dependentSchemas\" and \"dependentRequired\" in order to serve their differing semantics.",
|
|
905
|
+
type: "object",
|
|
906
|
+
additionalProperties: { anyOf: [{ $dynamicRef: "#meta" }, { $ref: "meta/validation#/$defs/stringArray" }] },
|
|
907
|
+
deprecated: true,
|
|
908
|
+
default: {}
|
|
909
|
+
},
|
|
910
|
+
$recursiveAnchor: {
|
|
911
|
+
$comment: "\"$recursiveAnchor\" has been replaced by \"$dynamicAnchor\".",
|
|
912
|
+
$ref: "meta/core#/$defs/anchorString",
|
|
913
|
+
deprecated: true
|
|
914
|
+
},
|
|
915
|
+
$recursiveRef: {
|
|
916
|
+
$comment: "\"$recursiveRef\" has been replaced by \"$dynamicRef\".",
|
|
917
|
+
$ref: "meta/core#/$defs/uriReferenceString",
|
|
918
|
+
deprecated: true
|
|
919
|
+
}
|
|
920
|
+
}
|
|
921
|
+
};
|
|
922
|
+
var META_VOCABULARIES = [
|
|
923
|
+
{
|
|
924
|
+
$schema: "https://json-schema.org/draft/2020-12/schema",
|
|
925
|
+
$id: "https://json-schema.org/draft/2020-12/meta/applicator",
|
|
926
|
+
$vocabulary: { "https://json-schema.org/draft/2020-12/vocab/applicator": true },
|
|
927
|
+
$dynamicAnchor: "meta",
|
|
928
|
+
title: "Applicator vocabulary meta-schema",
|
|
929
|
+
type: ["object", "boolean"],
|
|
930
|
+
properties: {
|
|
931
|
+
prefixItems: { $ref: "#/$defs/schemaArray" },
|
|
932
|
+
items: { $dynamicRef: "#meta" },
|
|
933
|
+
contains: { $dynamicRef: "#meta" },
|
|
934
|
+
additionalProperties: { $dynamicRef: "#meta" },
|
|
935
|
+
properties: {
|
|
936
|
+
type: "object",
|
|
937
|
+
additionalProperties: { $dynamicRef: "#meta" },
|
|
938
|
+
default: {}
|
|
939
|
+
},
|
|
940
|
+
patternProperties: {
|
|
941
|
+
type: "object",
|
|
942
|
+
additionalProperties: { $dynamicRef: "#meta" },
|
|
943
|
+
propertyNames: { format: "regex" },
|
|
944
|
+
default: {}
|
|
945
|
+
},
|
|
946
|
+
dependentSchemas: {
|
|
947
|
+
type: "object",
|
|
948
|
+
additionalProperties: { $dynamicRef: "#meta" },
|
|
949
|
+
default: {}
|
|
950
|
+
},
|
|
951
|
+
propertyNames: { $dynamicRef: "#meta" },
|
|
952
|
+
if: { $dynamicRef: "#meta" },
|
|
953
|
+
then: { $dynamicRef: "#meta" },
|
|
954
|
+
else: { $dynamicRef: "#meta" },
|
|
955
|
+
allOf: { $ref: "#/$defs/schemaArray" },
|
|
956
|
+
anyOf: { $ref: "#/$defs/schemaArray" },
|
|
957
|
+
oneOf: { $ref: "#/$defs/schemaArray" },
|
|
958
|
+
not: { $dynamicRef: "#meta" }
|
|
959
|
+
},
|
|
960
|
+
$defs: { schemaArray: {
|
|
961
|
+
type: "array",
|
|
962
|
+
minItems: 1,
|
|
963
|
+
items: { $dynamicRef: "#meta" }
|
|
964
|
+
} }
|
|
965
|
+
},
|
|
966
|
+
{
|
|
967
|
+
$schema: "https://json-schema.org/draft/2020-12/schema",
|
|
968
|
+
$id: "https://json-schema.org/draft/2020-12/meta/content",
|
|
969
|
+
$vocabulary: { "https://json-schema.org/draft/2020-12/vocab/content": true },
|
|
970
|
+
$dynamicAnchor: "meta",
|
|
971
|
+
title: "Content vocabulary meta-schema",
|
|
972
|
+
type: ["object", "boolean"],
|
|
973
|
+
properties: {
|
|
974
|
+
contentEncoding: { type: "string" },
|
|
975
|
+
contentMediaType: { type: "string" },
|
|
976
|
+
contentSchema: { $dynamicRef: "#meta" }
|
|
977
|
+
}
|
|
978
|
+
},
|
|
979
|
+
{
|
|
980
|
+
$schema: "https://json-schema.org/draft/2020-12/schema",
|
|
981
|
+
$id: "https://json-schema.org/draft/2020-12/meta/core",
|
|
982
|
+
$vocabulary: { "https://json-schema.org/draft/2020-12/vocab/core": true },
|
|
983
|
+
$dynamicAnchor: "meta",
|
|
984
|
+
title: "Core vocabulary meta-schema",
|
|
985
|
+
type: ["object", "boolean"],
|
|
986
|
+
properties: {
|
|
987
|
+
$id: {
|
|
988
|
+
$ref: "#/$defs/uriReferenceString",
|
|
989
|
+
$comment: "Non-empty fragments not allowed.",
|
|
990
|
+
pattern: "^[^#]*#?$"
|
|
991
|
+
},
|
|
992
|
+
$schema: { $ref: "#/$defs/uriString" },
|
|
993
|
+
$ref: { $ref: "#/$defs/uriReferenceString" },
|
|
994
|
+
$anchor: { $ref: "#/$defs/anchorString" },
|
|
995
|
+
$dynamicRef: { $ref: "#/$defs/uriReferenceString" },
|
|
996
|
+
$dynamicAnchor: { $ref: "#/$defs/anchorString" },
|
|
997
|
+
$vocabulary: {
|
|
998
|
+
type: "object",
|
|
999
|
+
propertyNames: { $ref: "#/$defs/uriString" },
|
|
1000
|
+
additionalProperties: { type: "boolean" }
|
|
1001
|
+
},
|
|
1002
|
+
$comment: { type: "string" },
|
|
1003
|
+
$defs: {
|
|
1004
|
+
type: "object",
|
|
1005
|
+
additionalProperties: { $dynamicRef: "#meta" }
|
|
1006
|
+
}
|
|
1007
|
+
},
|
|
1008
|
+
$defs: {
|
|
1009
|
+
anchorString: {
|
|
1010
|
+
type: "string",
|
|
1011
|
+
pattern: "^[A-Za-z_][-A-Za-z0-9._]*$"
|
|
1012
|
+
},
|
|
1013
|
+
uriString: {
|
|
1014
|
+
type: "string",
|
|
1015
|
+
format: "uri"
|
|
1016
|
+
},
|
|
1017
|
+
uriReferenceString: {
|
|
1018
|
+
type: "string",
|
|
1019
|
+
format: "uri-reference"
|
|
1020
|
+
}
|
|
1021
|
+
}
|
|
1022
|
+
},
|
|
1023
|
+
{
|
|
1024
|
+
$schema: "https://json-schema.org/draft/2020-12/schema",
|
|
1025
|
+
$id: "https://json-schema.org/draft/2020-12/meta/format-annotation",
|
|
1026
|
+
$vocabulary: { "https://json-schema.org/draft/2020-12/vocab/format-annotation": true },
|
|
1027
|
+
$dynamicAnchor: "meta",
|
|
1028
|
+
title: "Format vocabulary meta-schema for annotation results",
|
|
1029
|
+
type: ["object", "boolean"],
|
|
1030
|
+
properties: { format: { type: "string" } }
|
|
1031
|
+
},
|
|
1032
|
+
{
|
|
1033
|
+
$schema: "https://json-schema.org/draft/2020-12/schema",
|
|
1034
|
+
$id: "https://json-schema.org/draft/2020-12/meta/meta-data",
|
|
1035
|
+
$vocabulary: { "https://json-schema.org/draft/2020-12/vocab/meta-data": true },
|
|
1036
|
+
$dynamicAnchor: "meta",
|
|
1037
|
+
title: "Meta-data vocabulary meta-schema",
|
|
1038
|
+
type: ["object", "boolean"],
|
|
1039
|
+
properties: {
|
|
1040
|
+
title: { type: "string" },
|
|
1041
|
+
description: { type: "string" },
|
|
1042
|
+
default: true,
|
|
1043
|
+
deprecated: {
|
|
1044
|
+
type: "boolean",
|
|
1045
|
+
default: false
|
|
1046
|
+
},
|
|
1047
|
+
readOnly: {
|
|
1048
|
+
type: "boolean",
|
|
1049
|
+
default: false
|
|
1050
|
+
},
|
|
1051
|
+
writeOnly: {
|
|
1052
|
+
type: "boolean",
|
|
1053
|
+
default: false
|
|
1054
|
+
},
|
|
1055
|
+
examples: {
|
|
1056
|
+
type: "array",
|
|
1057
|
+
items: true
|
|
1058
|
+
}
|
|
1059
|
+
}
|
|
1060
|
+
},
|
|
1061
|
+
{
|
|
1062
|
+
$schema: "https://json-schema.org/draft/2020-12/schema",
|
|
1063
|
+
$id: "https://json-schema.org/draft/2020-12/meta/unevaluated",
|
|
1064
|
+
$vocabulary: { "https://json-schema.org/draft/2020-12/vocab/unevaluated": true },
|
|
1065
|
+
$dynamicAnchor: "meta",
|
|
1066
|
+
title: "Unevaluated applicator vocabulary meta-schema",
|
|
1067
|
+
type: ["object", "boolean"],
|
|
1068
|
+
properties: {
|
|
1069
|
+
unevaluatedItems: { $dynamicRef: "#meta" },
|
|
1070
|
+
unevaluatedProperties: { $dynamicRef: "#meta" }
|
|
1071
|
+
}
|
|
1072
|
+
},
|
|
1073
|
+
{
|
|
1074
|
+
$schema: "https://json-schema.org/draft/2020-12/schema",
|
|
1075
|
+
$id: "https://json-schema.org/draft/2020-12/meta/validation",
|
|
1076
|
+
$vocabulary: { "https://json-schema.org/draft/2020-12/vocab/validation": true },
|
|
1077
|
+
$dynamicAnchor: "meta",
|
|
1078
|
+
title: "Validation vocabulary meta-schema",
|
|
1079
|
+
type: ["object", "boolean"],
|
|
1080
|
+
properties: {
|
|
1081
|
+
type: { anyOf: [{ $ref: "#/$defs/simpleTypes" }, {
|
|
1082
|
+
type: "array",
|
|
1083
|
+
items: { $ref: "#/$defs/simpleTypes" },
|
|
1084
|
+
minItems: 1,
|
|
1085
|
+
uniqueItems: true
|
|
1086
|
+
}] },
|
|
1087
|
+
const: true,
|
|
1088
|
+
enum: {
|
|
1089
|
+
type: "array",
|
|
1090
|
+
items: true
|
|
1091
|
+
},
|
|
1092
|
+
multipleOf: {
|
|
1093
|
+
type: "number",
|
|
1094
|
+
exclusiveMinimum: 0
|
|
1095
|
+
},
|
|
1096
|
+
maximum: { type: "number" },
|
|
1097
|
+
exclusiveMaximum: { type: "number" },
|
|
1098
|
+
minimum: { type: "number" },
|
|
1099
|
+
exclusiveMinimum: { type: "number" },
|
|
1100
|
+
maxLength: { $ref: "#/$defs/nonNegativeInteger" },
|
|
1101
|
+
minLength: { $ref: "#/$defs/nonNegativeIntegerDefault0" },
|
|
1102
|
+
pattern: {
|
|
1103
|
+
type: "string",
|
|
1104
|
+
format: "regex"
|
|
1105
|
+
},
|
|
1106
|
+
maxItems: { $ref: "#/$defs/nonNegativeInteger" },
|
|
1107
|
+
minItems: { $ref: "#/$defs/nonNegativeIntegerDefault0" },
|
|
1108
|
+
uniqueItems: {
|
|
1109
|
+
type: "boolean",
|
|
1110
|
+
default: false
|
|
1111
|
+
},
|
|
1112
|
+
maxContains: { $ref: "#/$defs/nonNegativeInteger" },
|
|
1113
|
+
minContains: {
|
|
1114
|
+
$ref: "#/$defs/nonNegativeInteger",
|
|
1115
|
+
default: 1
|
|
1116
|
+
},
|
|
1117
|
+
maxProperties: { $ref: "#/$defs/nonNegativeInteger" },
|
|
1118
|
+
minProperties: { $ref: "#/$defs/nonNegativeIntegerDefault0" },
|
|
1119
|
+
required: { $ref: "#/$defs/stringArray" },
|
|
1120
|
+
dependentRequired: {
|
|
1121
|
+
type: "object",
|
|
1122
|
+
additionalProperties: { $ref: "#/$defs/stringArray" }
|
|
1123
|
+
}
|
|
1124
|
+
},
|
|
1125
|
+
$defs: {
|
|
1126
|
+
nonNegativeInteger: {
|
|
1127
|
+
type: "integer",
|
|
1128
|
+
minimum: 0
|
|
1129
|
+
},
|
|
1130
|
+
nonNegativeIntegerDefault0: {
|
|
1131
|
+
$ref: "#/$defs/nonNegativeInteger",
|
|
1132
|
+
default: 0
|
|
1133
|
+
},
|
|
1134
|
+
simpleTypes: { enum: [
|
|
1135
|
+
"array",
|
|
1136
|
+
"boolean",
|
|
1137
|
+
"integer",
|
|
1138
|
+
"null",
|
|
1139
|
+
"number",
|
|
1140
|
+
"object",
|
|
1141
|
+
"string"
|
|
1142
|
+
] },
|
|
1143
|
+
stringArray: {
|
|
1144
|
+
type: "array",
|
|
1145
|
+
items: { type: "string" },
|
|
1146
|
+
uniqueItems: true,
|
|
1147
|
+
default: []
|
|
1148
|
+
}
|
|
1149
|
+
}
|
|
1150
|
+
}
|
|
1151
|
+
];
|
|
1152
|
+
var SchemaUnrunnable = class extends Error {
|
|
1153
|
+
name = "SchemaUnrunnable";
|
|
1154
|
+
};
|
|
1155
|
+
var compiled = new WeakMap();
|
|
1156
|
+
var reported = new Set();
|
|
1157
|
+
var unrunnable = 0;
|
|
1158
|
+
var unrunnableSchemas = () => unrunnable;
|
|
1159
|
+
var resetUnrunnableSchemas = () => {
|
|
1160
|
+
unrunnable = 0;
|
|
1161
|
+
reported.clear();
|
|
1162
|
+
};
|
|
1163
|
+
function refuse(schema, cause) {
|
|
1164
|
+
const error = new SchemaUnrunnable(cause instanceof Error ? cause.message.split("\n")[0] : String(cause));
|
|
1165
|
+
const key = JSON.stringify(schema);
|
|
1166
|
+
if (!reported.has(key)) {
|
|
1167
|
+
reported.add(key);
|
|
1168
|
+
unrunnable += 1;
|
|
1169
|
+
console.error(`[json-schema] a props schema could not be run, so its props were not checked: ${error.message}`);
|
|
1170
|
+
}
|
|
1171
|
+
return error;
|
|
1172
|
+
}
|
|
1173
|
+
var CONTAINER = /^(properties|items|allOf|anyOf|oneOf|\$ref|additionalProperties|prefixItems|patternProperties)$/;
|
|
1174
|
+
function words(errors) {
|
|
1175
|
+
const leaves = errors.filter((e) => !CONTAINER.test(e.keyword));
|
|
1176
|
+
return (leaves.length ? leaves : errors).map((e) => `${e.instanceLocation.replace(/^#/, "")} ${e.error.replace(/^Instance /, "")}`.trim()).filter((line, i, all) => all.indexOf(line) === i).slice(0, 3).join("; ") || "does not fit its schema";
|
|
1177
|
+
}
|
|
1178
|
+
function judge(schema, value) {
|
|
1179
|
+
let validator = compiled.get(schema);
|
|
1180
|
+
if (!validator) {
|
|
1181
|
+
try {
|
|
1182
|
+
const problems = schemaProblems(schema);
|
|
1183
|
+
if (problems.length) throw new Error(`not valid JSON Schema: ${problems.join("; ")}`);
|
|
1184
|
+
validator = new Validator(schema, "2020-12", false);
|
|
1185
|
+
} catch (cause) {
|
|
1186
|
+
validator = refuse(schema, cause);
|
|
1187
|
+
}
|
|
1188
|
+
compiled.set(schema, validator);
|
|
1189
|
+
}
|
|
1190
|
+
if (validator instanceof SchemaUnrunnable) throw validator;
|
|
1191
|
+
let result;
|
|
1192
|
+
try {
|
|
1193
|
+
result = validator.validate(value);
|
|
1194
|
+
} catch (cause) {
|
|
1195
|
+
const error = refuse(schema, cause);
|
|
1196
|
+
compiled.set(schema, error);
|
|
1197
|
+
throw error;
|
|
1198
|
+
}
|
|
1199
|
+
return result.valid ? { valid: true } : {
|
|
1200
|
+
valid: false,
|
|
1201
|
+
message: words(result.errors)
|
|
1202
|
+
};
|
|
1203
|
+
}
|
|
1204
|
+
var meta;
|
|
1205
|
+
function metaValidator() {
|
|
1206
|
+
if (!meta) {
|
|
1207
|
+
meta = new Validator(META_ROOT, "2020-12", false);
|
|
1208
|
+
for (const vocabulary of META_VOCABULARIES) meta.addSchema(vocabulary, vocabulary.$id);
|
|
1209
|
+
}
|
|
1210
|
+
return meta;
|
|
1211
|
+
}
|
|
1212
|
+
var SCHEMA_VALUED = [
|
|
1213
|
+
"additionalProperties",
|
|
1214
|
+
"contains",
|
|
1215
|
+
"else",
|
|
1216
|
+
"if",
|
|
1217
|
+
"items",
|
|
1218
|
+
"not",
|
|
1219
|
+
"propertyNames",
|
|
1220
|
+
"then",
|
|
1221
|
+
"unevaluatedItems",
|
|
1222
|
+
"unevaluatedProperties",
|
|
1223
|
+
"contentSchema"
|
|
1224
|
+
];
|
|
1225
|
+
var SCHEMA_LISTS = [
|
|
1226
|
+
"allOf",
|
|
1227
|
+
"anyOf",
|
|
1228
|
+
"oneOf",
|
|
1229
|
+
"prefixItems"
|
|
1230
|
+
];
|
|
1231
|
+
var SCHEMA_MAPS = [
|
|
1232
|
+
"$defs",
|
|
1233
|
+
"definitions",
|
|
1234
|
+
"dependentSchemas",
|
|
1235
|
+
"patternProperties",
|
|
1236
|
+
"properties"
|
|
1237
|
+
];
|
|
1238
|
+
var isObject = (v) => !!v && typeof v === "object" && !Array.isArray(v);
|
|
1239
|
+
function schemaProblems(schema, at = "") {
|
|
1240
|
+
if (typeof schema === "boolean") return [];
|
|
1241
|
+
if (!isObject(schema)) return [`${at} must be a schema (an object or a boolean)`.trim()];
|
|
1242
|
+
const out = [];
|
|
1243
|
+
const own = { ...schema };
|
|
1244
|
+
for (const key of [
|
|
1245
|
+
...SCHEMA_VALUED,
|
|
1246
|
+
...SCHEMA_LISTS,
|
|
1247
|
+
...SCHEMA_MAPS
|
|
1248
|
+
]) delete own[key];
|
|
1249
|
+
const verdict = metaValidator().validate(own);
|
|
1250
|
+
if (!verdict.valid) out.push(...words(verdict.errors).split("; ").map((line) => `${at}${line}`.trim()));
|
|
1251
|
+
for (const key of SCHEMA_VALUED) if (key in schema) out.push(...schemaProblems(schema[key], `${at}/${key}`));
|
|
1252
|
+
for (const key of SCHEMA_LISTS) {
|
|
1253
|
+
const list = schema[key];
|
|
1254
|
+
if (Array.isArray(list)) list.forEach((sub, i) => out.push(...schemaProblems(sub, `${at}/${key}/${i}`)));
|
|
1255
|
+
else if (key in schema) out.push(`${at}/${key} must be an array of schemas`);
|
|
1256
|
+
}
|
|
1257
|
+
for (const key of SCHEMA_MAPS) {
|
|
1258
|
+
const map = schema[key];
|
|
1259
|
+
if (isObject(map)) for (const [name, sub] of Object.entries(map)) out.push(...schemaProblems(sub, `${at}/${key}/${name}`));
|
|
1260
|
+
else if (key in schema) out.push(`${at}/${key} must be an object of schemas`);
|
|
1261
|
+
}
|
|
1262
|
+
return out;
|
|
1263
|
+
}
|
|
5
1264
|
var ref = (kind, key) => `${kind}:${key}`;
|
|
6
1265
|
var size = (v) => JSON.stringify(v ?? null).length;
|
|
7
1266
|
var isReference = (v) => typeof v === "string" && (v.startsWith("@") || v.includes("${"));
|
|
@@ -21,10 +1280,6 @@ var exampleOf = (row) => row?.kind === "component" ? row.snippets?.[0] : void 0;
|
|
|
21
1280
|
function checkCatalog(input) {
|
|
22
1281
|
const out = [];
|
|
23
1282
|
const at = (row, field) => `${ref(row.kind, row.key)}${field ? `.${field}` : ""}`;
|
|
24
|
-
const ajv = new Ajv2020({
|
|
25
|
-
strict: false,
|
|
26
|
-
allErrors: true
|
|
27
|
-
});
|
|
28
1283
|
const schemaOf = (name) => (input.registry[name] ?? input.scopeRegistry?.[name])?.props_schema;
|
|
29
1284
|
const byRef = new Map();
|
|
30
1285
|
for (const row of input.rows) {
|
|
@@ -71,12 +1326,15 @@ function checkCatalog(input) {
|
|
|
71
1326
|
message: `${name} has no snippet`
|
|
72
1327
|
});
|
|
73
1328
|
const schema = entry.props_schema;
|
|
74
|
-
if (schema !== void 0 && schema !== null
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
1329
|
+
if (schema !== void 0 && schema !== null) {
|
|
1330
|
+
const problems = schemaProblems(schema);
|
|
1331
|
+
if (problems.length) out.push({
|
|
1332
|
+
severity: "error",
|
|
1333
|
+
code: "KNOWLEDGE_SCHEMA_INVALID",
|
|
1334
|
+
path: `component:${name}.props_schema`,
|
|
1335
|
+
message: `props_schema ${problems.join("; ")}`
|
|
1336
|
+
});
|
|
1337
|
+
}
|
|
80
1338
|
}
|
|
81
1339
|
for (const row of input.rows) if (row.kind === "component" && !input.registry[row.key]) out.push({
|
|
82
1340
|
severity: "error",
|
|
@@ -125,7 +1383,7 @@ function checkCatalog(input) {
|
|
|
125
1383
|
...input.registry
|
|
126
1384
|
})) catalog.components[name] = { props_schema: entry.props_schema };
|
|
127
1385
|
for (const row of input.rows) (row.snippets ?? []).forEach((snippet, i) => {
|
|
128
|
-
for (const problem of checkSnippet(snippet, catalog
|
|
1386
|
+
for (const problem of checkSnippet(snippet, catalog)) out.push({
|
|
129
1387
|
...problem,
|
|
130
1388
|
code: "KNOWLEDGE_SNIPPET_INVALID",
|
|
131
1389
|
path: `${at(row, `snippets[${i}]`)}${problem.path ? `.${problem.path}` : ""}`
|
|
@@ -183,7 +1441,7 @@ function checkCatalog(input) {
|
|
|
183
1441
|
});
|
|
184
1442
|
return out;
|
|
185
1443
|
}
|
|
186
|
-
function checkSnippet(snippet, catalog
|
|
1444
|
+
function checkSnippet(snippet, catalog) {
|
|
187
1445
|
if (!Array.isArray(snippet?.cells) || snippet.cells.length === 0) return [{
|
|
188
1446
|
severity: "error",
|
|
189
1447
|
message: "a snippet needs at least one cell"
|
|
@@ -199,7 +1457,7 @@ function checkSnippet(snippet, catalog, ajv) {
|
|
|
199
1457
|
},
|
|
200
1458
|
layout
|
|
201
1459
|
};
|
|
202
|
-
return [...validatePage(page, catalog), ...propsAgainstSchemas(page, catalog
|
|
1460
|
+
return [...validatePage(page, catalog), ...propsAgainstSchemas(page, catalog)].filter((d) => d.severity !== "legacy" && d.code !== "KNOWLEDGE_SCHEMA_INVALID").map((d) => ({
|
|
203
1461
|
severity: d.severity,
|
|
204
1462
|
cellId: d.cellId,
|
|
205
1463
|
path: d.path?.replace(/^content\./, ""),
|
|
@@ -207,13 +1465,10 @@ function checkSnippet(snippet, catalog, ajv) {
|
|
|
207
1465
|
}));
|
|
208
1466
|
}
|
|
209
1467
|
function validatePageProps(page, catalog) {
|
|
210
|
-
return propsAgainstSchemas(page, catalog
|
|
211
|
-
strict: false,
|
|
212
|
-
allErrors: true
|
|
213
|
-
}));
|
|
1468
|
+
return propsAgainstSchemas(page, catalog);
|
|
214
1469
|
}
|
|
215
1470
|
var asNode = (v) => v && typeof v === "object" && !Array.isArray(v) ? v : void 0;
|
|
216
|
-
function propsAgainstSchemas(page, catalog
|
|
1471
|
+
function propsAgainstSchemas(page, catalog) {
|
|
217
1472
|
const out = [];
|
|
218
1473
|
(Array.isArray(page.content?.cells) ? page.content.cells : []).forEach((cell, i) => {
|
|
219
1474
|
const properties = cell?.component ? componentsFor(catalog, cell)[cell.component]?.props_schema?.properties : void 0;
|
|
@@ -230,27 +1485,21 @@ function propsAgainstSchemas(page, catalog, ajv) {
|
|
|
230
1485
|
});
|
|
231
1486
|
if (!schema || typeof schema !== "object") continue;
|
|
232
1487
|
if (isEach(value)) {
|
|
233
|
-
if (eachFormProblems(value).length === 0) checkMap(value.map, asNode(asNode(schema)?.items), `${path}.map`, push
|
|
1488
|
+
if (eachFormProblems(value).length === 0) checkMap(value.map, asNode(asNode(schema)?.items), `${path}.map`, push);
|
|
234
1489
|
continue;
|
|
235
1490
|
}
|
|
236
1491
|
if (holdsReference(value)) continue;
|
|
237
|
-
|
|
238
|
-
try {
|
|
239
|
-
valid = ajv.validate(schema, value);
|
|
240
|
-
} catch {
|
|
241
|
-
continue;
|
|
242
|
-
}
|
|
243
|
-
if (!valid) push("error", "PROP_INVALID", path, ajv.errorsText(ajv.errors, { dataVar: "" }).replace(/^\s+/, ""));
|
|
1492
|
+
validateLiteral(schema, value, path, push);
|
|
244
1493
|
}
|
|
245
1494
|
});
|
|
246
1495
|
return out;
|
|
247
1496
|
}
|
|
248
|
-
function checkMap(map, items, path, push
|
|
1497
|
+
function checkMap(map, items, path, push) {
|
|
249
1498
|
if (!items) return;
|
|
250
1499
|
if (isEach(map)) return;
|
|
251
1500
|
const fields = asNode(map);
|
|
252
1501
|
if (!fields || !items.properties) {
|
|
253
|
-
if (map !== void 0 && !holdsReference(map)) validateLiteral(items, map, path, push
|
|
1502
|
+
if (map !== void 0 && !holdsReference(map)) validateLiteral(items, map, path, push);
|
|
254
1503
|
return;
|
|
255
1504
|
}
|
|
256
1505
|
for (const key of Array.isArray(items.required) ? items.required : []) if (typeof key === "string" && !(key in fields)) push("error", "PROP_INVALID", path, `each element needs "${key}"; the map doesn't give it`);
|
|
@@ -262,13 +1511,17 @@ function checkMap(map, items, path, push, ajv) {
|
|
|
262
1511
|
continue;
|
|
263
1512
|
}
|
|
264
1513
|
if (isEach(v)) {
|
|
265
|
-
if (eachFormProblems(v).length === 0) checkMap(v.map, asNode(sub.items), `${path}.${key}.map`, push
|
|
266
|
-
} else if (!holdsReference(v)) validateLiteral(sub, v, `${path}.${key}`, push
|
|
1514
|
+
if (eachFormProblems(v).length === 0) checkMap(v.map, asNode(sub.items), `${path}.${key}.map`, push);
|
|
1515
|
+
} else if (!holdsReference(v)) validateLiteral(sub, v, `${path}.${key}`, push);
|
|
267
1516
|
}
|
|
268
1517
|
}
|
|
269
|
-
function validateLiteral(schema, value, path, push
|
|
1518
|
+
function validateLiteral(schema, value, path, push) {
|
|
270
1519
|
try {
|
|
271
|
-
|
|
272
|
-
|
|
1520
|
+
const verdict = judge(schema, value);
|
|
1521
|
+
if (!verdict.valid) push("error", "PROP_INVALID", path, verdict.message);
|
|
1522
|
+
} catch (error) {
|
|
1523
|
+
if (!(error instanceof SchemaUnrunnable)) throw error;
|
|
1524
|
+
push("error", "KNOWLEDGE_SCHEMA_INVALID", path, `couldn’t be checked: its schema can’t be run (${error.message})`);
|
|
1525
|
+
}
|
|
273
1526
|
}
|
|
274
|
-
export { checkCatalog, validatePageProps };
|
|
1527
|
+
export { checkCatalog, resetUnrunnableSchemas, unrunnableSchemas, validatePageProps };
|