@earendil-works/pi-schema 0.0.0-stage → 1.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (176) hide show
  1. package/CHANGELOG.md +13 -0
  2. package/LICENSES/typebox-LICENSE +23 -0
  3. package/README.md +295 -2
  4. package/dist/annotations.d.ts +44 -0
  5. package/dist/annotations.d.ts.map +1 -0
  6. package/dist/annotations.js +193 -0
  7. package/dist/annotations.js.map +1 -0
  8. package/dist/builders.d.ts +114 -0
  9. package/dist/builders.d.ts.map +1 -0
  10. package/dist/builders.js +98 -0
  11. package/dist/builders.js.map +1 -0
  12. package/dist/checks.d.ts +87 -0
  13. package/dist/checks.d.ts.map +1 -0
  14. package/dist/checks.js +447 -0
  15. package/dist/checks.js.map +1 -0
  16. package/dist/coerce.d.ts +53 -0
  17. package/dist/coerce.d.ts.map +1 -0
  18. package/dist/coerce.js +585 -0
  19. package/dist/coerce.js.map +1 -0
  20. package/dist/compiler.d.ts +53 -0
  21. package/dist/compiler.d.ts.map +1 -0
  22. package/dist/compiler.js +532 -0
  23. package/dist/compiler.js.map +1 -0
  24. package/dist/explain.d.ts +29 -0
  25. package/dist/explain.d.ts.map +1 -0
  26. package/dist/explain.js +381 -0
  27. package/dist/explain.js.map +1 -0
  28. package/dist/formats/index.d.ts +7 -0
  29. package/dist/formats/index.d.ts.map +1 -0
  30. package/dist/formats/index.js +51 -0
  31. package/dist/formats/index.js.map +1 -0
  32. package/dist/formats/typebox/date.d.ts +7 -0
  33. package/dist/formats/typebox/date.d.ts.map +1 -0
  34. package/dist/formats/typebox/date.js +47 -0
  35. package/dist/formats/typebox/date.js.map +1 -0
  36. package/dist/formats/typebox/date_time.d.ts +7 -0
  37. package/dist/formats/typebox/date_time.d.ts.map +1 -0
  38. package/dist/formats/typebox/date_time.js +39 -0
  39. package/dist/formats/typebox/date_time.js.map +1 -0
  40. package/dist/formats/typebox/duration.d.ts +6 -0
  41. package/dist/formats/typebox/duration.d.ts.map +1 -0
  42. package/dist/formats/typebox/duration.js +36 -0
  43. package/dist/formats/typebox/duration.js.map +1 -0
  44. package/dist/formats/typebox/email.d.ts +6 -0
  45. package/dist/formats/typebox/email.d.ts.map +1 -0
  46. package/dist/formats/typebox/email.js +36 -0
  47. package/dist/formats/typebox/email.js.map +1 -0
  48. package/dist/formats/typebox/hostname.d.ts +8 -0
  49. package/dist/formats/typebox/hostname.d.ts.map +1 -0
  50. package/dist/formats/typebox/hostname.js +38 -0
  51. package/dist/formats/typebox/hostname.js.map +1 -0
  52. package/dist/formats/typebox/idn_email.d.ts +6 -0
  53. package/dist/formats/typebox/idn_email.d.ts.map +1 -0
  54. package/dist/formats/typebox/idn_email.js +36 -0
  55. package/dist/formats/typebox/idn_email.js.map +1 -0
  56. package/dist/formats/typebox/idn_hostname.d.ts +9 -0
  57. package/dist/formats/typebox/idn_hostname.d.ts.map +1 -0
  58. package/dist/formats/typebox/idn_hostname.js +39 -0
  59. package/dist/formats/typebox/idn_hostname.js.map +1 -0
  60. package/dist/formats/typebox/idna/format/bidi.d.ts +4 -0
  61. package/dist/formats/typebox/idna/format/bidi.d.ts.map +1 -0
  62. package/dist/formats/typebox/idna/format/bidi.js +132 -0
  63. package/dist/formats/typebox/idna/format/bidi.js.map +1 -0
  64. package/dist/formats/typebox/idna/format/puny.d.ts +4 -0
  65. package/dist/formats/typebox/idna/format/puny.d.ts.map +1 -0
  66. package/dist/formats/typebox/idna/format/puny.js +172 -0
  67. package/dist/formats/typebox/idna/format/puny.js.map +1 -0
  68. package/dist/formats/typebox/idna/hostname.d.ts +2 -0
  69. package/dist/formats/typebox/idna/hostname.d.ts.map +1 -0
  70. package/dist/formats/typebox/idna/hostname.js +43 -0
  71. package/dist/formats/typebox/idna/hostname.js.map +1 -0
  72. package/dist/formats/typebox/idna/idn-hostname.d.ts +2 -0
  73. package/dist/formats/typebox/idna/idn-hostname.d.ts.map +1 -0
  74. package/dist/formats/typebox/idna/idn-hostname.js +71 -0
  75. package/dist/formats/typebox/idna/idn-hostname.js.map +1 -0
  76. package/dist/formats/typebox/idna/index.d.ts +3 -0
  77. package/dist/formats/typebox/idna/index.d.ts.map +1 -0
  78. package/dist/formats/typebox/idna/index.js +30 -0
  79. package/dist/formats/typebox/idna/index.js.map +1 -0
  80. package/dist/formats/typebox/idna/label/ascii.d.ts +2 -0
  81. package/dist/formats/typebox/idna/label/ascii.d.ts.map +1 -0
  82. package/dist/formats/typebox/idna/label/ascii.js +37 -0
  83. package/dist/formats/typebox/idna/label/ascii.js.map +1 -0
  84. package/dist/formats/typebox/idna/label/puny.d.ts +2 -0
  85. package/dist/formats/typebox/idna/label/puny.d.ts.map +1 -0
  86. package/dist/formats/typebox/idna/label/puny.js +56 -0
  87. package/dist/formats/typebox/idna/label/puny.js.map +1 -0
  88. package/dist/formats/typebox/idna/label/unicode.d.ts +2 -0
  89. package/dist/formats/typebox/idna/label/unicode.d.ts.map +1 -0
  90. package/dist/formats/typebox/idna/label/unicode.js +134 -0
  91. package/dist/formats/typebox/idna/label/unicode.js.map +1 -0
  92. package/dist/formats/typebox/idna/pattern/pattern.d.ts +31 -0
  93. package/dist/formats/typebox/idna/pattern/pattern.d.ts.map +1 -0
  94. package/dist/formats/typebox/idna/pattern/pattern.js +98 -0
  95. package/dist/formats/typebox/idna/pattern/pattern.js.map +1 -0
  96. package/dist/formats/typebox/ipv4.d.ts +6 -0
  97. package/dist/formats/typebox/ipv4.d.ts.map +1 -0
  98. package/dist/formats/typebox/ipv4.js +36 -0
  99. package/dist/formats/typebox/ipv4.js.map +1 -0
  100. package/dist/formats/typebox/ipv6.d.ts +6 -0
  101. package/dist/formats/typebox/ipv6.d.ts.map +1 -0
  102. package/dist/formats/typebox/ipv6.js +36 -0
  103. package/dist/formats/typebox/ipv6.js.map +1 -0
  104. package/dist/formats/typebox/iri.d.ts +6 -0
  105. package/dist/formats/typebox/iri.d.ts.map +1 -0
  106. package/dist/formats/typebox/iri.js +63 -0
  107. package/dist/formats/typebox/iri.js.map +1 -0
  108. package/dist/formats/typebox/iri_reference.d.ts +6 -0
  109. package/dist/formats/typebox/iri_reference.d.ts.map +1 -0
  110. package/dist/formats/typebox/iri_reference.js +40 -0
  111. package/dist/formats/typebox/iri_reference.js.map +1 -0
  112. package/dist/formats/typebox/json_pointer.d.ts +7 -0
  113. package/dist/formats/typebox/json_pointer.d.ts.map +1 -0
  114. package/dist/formats/typebox/json_pointer.js +37 -0
  115. package/dist/formats/typebox/json_pointer.js.map +1 -0
  116. package/dist/formats/typebox/json_pointer_uri_fragment.d.ts +7 -0
  117. package/dist/formats/typebox/json_pointer_uri_fragment.d.ts.map +1 -0
  118. package/dist/formats/typebox/json_pointer_uri_fragment.js +37 -0
  119. package/dist/formats/typebox/json_pointer_uri_fragment.js.map +1 -0
  120. package/dist/formats/typebox/regex.d.ts +6 -0
  121. package/dist/formats/typebox/regex.d.ts.map +1 -0
  122. package/dist/formats/typebox/regex.js +41 -0
  123. package/dist/formats/typebox/regex.js.map +1 -0
  124. package/dist/formats/typebox/relative_json_pointer.d.ts +7 -0
  125. package/dist/formats/typebox/relative_json_pointer.d.ts.map +1 -0
  126. package/dist/formats/typebox/relative_json_pointer.js +37 -0
  127. package/dist/formats/typebox/relative_json_pointer.js.map +1 -0
  128. package/dist/formats/typebox/time.d.ts +6 -0
  129. package/dist/formats/typebox/time.d.ts.map +1 -0
  130. package/dist/formats/typebox/time.js +60 -0
  131. package/dist/formats/typebox/time.js.map +1 -0
  132. package/dist/formats/typebox/uri.d.ts +6 -0
  133. package/dist/formats/typebox/uri.d.ts.map +1 -0
  134. package/dist/formats/typebox/uri.js +36 -0
  135. package/dist/formats/typebox/uri.js.map +1 -0
  136. package/dist/formats/typebox/uri_reference.d.ts +6 -0
  137. package/dist/formats/typebox/uri_reference.d.ts.map +1 -0
  138. package/dist/formats/typebox/uri_reference.js +36 -0
  139. package/dist/formats/typebox/uri_reference.js.map +1 -0
  140. package/dist/formats/typebox/uri_template.d.ts +6 -0
  141. package/dist/formats/typebox/uri_template.d.ts.map +1 -0
  142. package/dist/formats/typebox/uri_template.js +37 -0
  143. package/dist/formats/typebox/uri_template.js.map +1 -0
  144. package/dist/formats/typebox/url.d.ts +7 -0
  145. package/dist/formats/typebox/url.d.ts.map +1 -0
  146. package/dist/formats/typebox/url.js +36 -0
  147. package/dist/formats/typebox/url.js.map +1 -0
  148. package/dist/formats/typebox/uuid.d.ts +7 -0
  149. package/dist/formats/typebox/uuid.d.ts.map +1 -0
  150. package/dist/formats/typebox/uuid.js +37 -0
  151. package/dist/formats/typebox/uuid.js.map +1 -0
  152. package/dist/index.d.ts +4 -0
  153. package/dist/index.d.ts.map +1 -0
  154. package/dist/index.js +5 -0
  155. package/dist/index.js.map +1 -0
  156. package/dist/resolver.d.ts +57 -0
  157. package/dist/resolver.d.ts.map +1 -0
  158. package/dist/resolver.js +202 -0
  159. package/dist/resolver.js.map +1 -0
  160. package/dist/shared.d.ts +9 -0
  161. package/dist/shared.d.ts.map +1 -0
  162. package/dist/shared.js +33 -0
  163. package/dist/shared.js.map +1 -0
  164. package/dist/typebox-static.d.ts +48 -0
  165. package/dist/typebox-static.d.ts.map +1 -0
  166. package/dist/typebox-static.js +5 -0
  167. package/dist/typebox-static.js.map +1 -0
  168. package/dist/types.d.ts +48 -0
  169. package/dist/types.d.ts.map +1 -0
  170. package/dist/types.js +3 -0
  171. package/dist/types.js.map +1 -0
  172. package/dist/validator.d.ts +39 -0
  173. package/dist/validator.d.ts.map +1 -0
  174. package/dist/validator.js +71 -0
  175. package/dist/validator.js.map +1 -0
  176. package/package.json +59 -5
@@ -0,0 +1,532 @@
1
+ // The compiler: a schema to one check closure, built once. Keywords group by the type they constrain, so a value
2
+ // is classified once per schema, and the common shapes (closed objects, arrays of one item schema, tagged unions,
3
+ // leaf schemas) get one specialized closure each.
4
+ import { ANNOTATING_FALSE, ANNOTATING_TRUE, annotateAll, annotateAny, annotateArray, annotateDependent, annotateIf, annotateObject, ignoreAnnotations, indirectAnnotating, isolateAnnotations, scopedAnnotating, unevaluatedItems, unevaluatedProperties, withFreshAnnotations, } from "./annotations.js";
5
+ import { ALWAYS, and, anyCheck, bytesCheck, constCheck, containsCheck, declaredObject, dependentRequiredCheck, dependentSchemasCheck, enumCheck, GUARD_LOOSE, GUARD_NONE, GUARD_STRICT, guardArray, guardObject, INHERITED, IS_ARRAY, IS_OBJECT, ifCheck, indirect, itemsCheck, LEAF_CODES, lengthCheck, listCheck, NEVER, notCheck, numberCheck, oneCheck, openObject, propertyCountCheck, propertyNamesCheck, REQUIRED, scopedCheck, stringCheck, TYPE_CHECKS, taggedCheck, typeCheck, uniqueCheck, } from "./checks.js";
6
+ import { documentOf, isSchemaObject, Resolver, resolveUri } from "./resolver.js";
7
+ import { sharedRegex } from "./shared.js";
8
+ /** Thrown when a compile without dynamic scope tracking meets a bookended `$dynamicRef`: compile again with it. */
9
+ export const RESTART = Symbol("restart");
10
+ /** One compile of a schema. Its caches and indexes are garbage once the root check is built. */
11
+ export class Compiler {
12
+ r;
13
+ draft;
14
+ formats;
15
+ /** Whether checks track the dynamic scope (the schema has a bookended `$dynamicRef`). */
16
+ dynamic;
17
+ schema;
18
+ scope;
19
+ cache = new Map();
20
+ annotatingCache = new Map();
21
+ constructor(schema, options, dynamic) {
22
+ this.schema = schema;
23
+ this.r = new Resolver(schema, options);
24
+ this.draft = this.r.draft;
25
+ this.formats = options.formats;
26
+ this.dynamic = dynamic;
27
+ this.scope = [];
28
+ }
29
+ /** The check of the root schema. */
30
+ root() {
31
+ return this.check(this.schema, this.r.rootBase);
32
+ }
33
+ /** The check of a schema (cached by schema object; a recursive reference goes through an indirection). */
34
+ check(node, base) {
35
+ if (node === true)
36
+ return ALWAYS;
37
+ if (node === false)
38
+ return NEVER;
39
+ if (!isSchemaObject(node))
40
+ throw new Error(`A schema must be an object or a boolean, got ${JSON.stringify(node)}`);
41
+ const cached = this.cache.get(node);
42
+ if (cached !== undefined)
43
+ return cached;
44
+ const bare = this.bareType(node);
45
+ if (bare !== undefined)
46
+ return bare;
47
+ const slot = { check: undefined };
48
+ this.cache.set(node, indirect(slot));
49
+ const check = this.build(node, this.r.baseFor(node, base));
50
+ slot.check = check;
51
+ this.cache.set(node, check);
52
+ return check;
53
+ }
54
+ build(node, base) {
55
+ if (this.draft === "7" && typeof node.$ref === "string")
56
+ return this.ref(node.$ref, base);
57
+ if (this.draft !== "7" && (node.unevaluatedProperties !== undefined || node.unevaluatedItems !== undefined)) {
58
+ return withFreshAnnotations(this.annotating(node, base));
59
+ }
60
+ const check = this.plain(node, base);
61
+ return this.dynamic && this.r.isResource(node, base) ? scopedCheck(this.scope, base, check) : check;
62
+ }
63
+ /**
64
+ * The module-level check of a schema that is only a `type` (with annotations), `ALWAYS` for one with no assertion
65
+ * at all; undefined for every other schema. These are the most common subschemas and cost nothing to share.
66
+ */
67
+ bareType(node) {
68
+ let type;
69
+ for (const k in node) {
70
+ if (k === "type")
71
+ type = node.type;
72
+ else if (!NEUTRAL_KEYWORDS.has(k))
73
+ return undefined;
74
+ }
75
+ if (type === undefined)
76
+ return ALWAYS;
77
+ return typeof type === "string" ? TYPE_CHECKS.get(type) : undefined;
78
+ }
79
+ /** Every keyword of `node`, not tracking annotations. */
80
+ plain(node, base) {
81
+ const parts = [];
82
+ const types = node.type === undefined ? undefined : Array.isArray(node.type) ? node.type : [node.type];
83
+ const single = types?.length === 1 ? types[0] : undefined;
84
+ let typeInGroup = false;
85
+ if (single === "bytes") {
86
+ parts.push(bytesCheck(number(node.minLength) ?? 0, number(node.maxLength) ?? Number.POSITIVE_INFINITY));
87
+ typeInGroup = true;
88
+ }
89
+ else {
90
+ const string = this.stringGroup(node, single === "string");
91
+ if (string !== undefined)
92
+ parts.push(string);
93
+ const numeric = single === "number" || single === "integer";
94
+ const number = this.numberGroup(node, single === "number" ? 1 : single === "integer" ? 2 : 0);
95
+ if (number !== undefined)
96
+ parts.push(number);
97
+ const object = this.objectGroup(node, base, single === "object");
98
+ if (object !== undefined)
99
+ parts.push(object);
100
+ const array = this.arrayGroup(node, base, single === "array");
101
+ if (array !== undefined)
102
+ parts.push(array);
103
+ typeInGroup =
104
+ (single === "string" && string !== undefined) ||
105
+ (numeric && number !== undefined) ||
106
+ (single === "object" && object !== undefined) ||
107
+ (single === "array" && array !== undefined);
108
+ }
109
+ if (types !== undefined && !typeInGroup)
110
+ parts.unshift(typeCheck(types));
111
+ this.inPlace(node, base, parts);
112
+ return and(parts);
113
+ }
114
+ // The keywords that apply to the value itself, whatever its type.
115
+ inPlace(node, base, parts) {
116
+ if (Array.isArray(node.enum))
117
+ parts.push(enumCheck(node.enum));
118
+ if (Object.hasOwn(node, "const"))
119
+ parts.push(constCheck(node.const));
120
+ if (Array.isArray(node.allOf))
121
+ parts.push(and(node.allOf.map((s) => this.check(s, base))));
122
+ if (Array.isArray(node.anyOf))
123
+ parts.push(this.union(node.anyOf, base, false));
124
+ if (Array.isArray(node.oneOf))
125
+ parts.push(this.union(node.oneOf, base, true));
126
+ if (node.not !== undefined)
127
+ parts.push(notCheck(this.check(node.not, base)));
128
+ if (node.if !== undefined && (node.then !== undefined || node.else !== undefined)) {
129
+ const then = node.then === undefined ? ALWAYS : this.check(node.then, base);
130
+ const otherwise = node.else === undefined ? ALWAYS : this.check(node.else, base);
131
+ parts.push(ifCheck(this.check(node.if, base), then, otherwise));
132
+ }
133
+ if (typeof node.$ref === "string")
134
+ parts.push(this.ref(node.$ref, base));
135
+ if (this.draft !== "7" && typeof node.$dynamicRef === "string") {
136
+ parts.push(this.dynamicRef(node.$dynamicRef, base));
137
+ }
138
+ }
139
+ union(branches, base, exactlyOne) {
140
+ const checks = () => branches.map((s) => this.check(s, base));
141
+ return (constUnion(branches, exactlyOne) ??
142
+ this.tagged(branches, base) ??
143
+ (exactlyOne ? oneCheck(checks()) : anyCheck(checks())));
144
+ }
145
+ ref(ref, base) {
146
+ const target = this.r.resolve(ref, base);
147
+ const check = this.check(target.node, target.base);
148
+ return this.dynamic && target.base !== base ? scopedCheck(this.scope, target.base, check) : check;
149
+ }
150
+ dynamicRef(ref, base) {
151
+ const resolved = this.bookended(ref, base);
152
+ if (resolved === undefined)
153
+ return this.ref(ref, base);
154
+ const { initial, name } = resolved;
155
+ const fallback = this.check(initial.node, initial.base);
156
+ const lookup = this.dynamicLookup(name, (node, b) => this.check(node, b));
157
+ const scope = this.scope;
158
+ return (v) => {
159
+ for (let i = 0; i < scope.length; i++) {
160
+ const check = lookup(scope[i]);
161
+ if (check !== null)
162
+ return check(v);
163
+ }
164
+ return fallback(v);
165
+ };
166
+ }
167
+ /** The initial target and anchor name of a `$dynamicRef` that resolves dynamically, or undefined for a plain ref. */
168
+ bookended(ref, base) {
169
+ const initial = this.r.resolve(ref, base);
170
+ const uri = resolveUri(ref, base);
171
+ const name = uri.slice(documentOf(uri).length + 1);
172
+ const anchored = isSchemaObject(initial.node) && initial.node.$dynamicAnchor === name;
173
+ if (name === "" || name.startsWith("/") || !anchored)
174
+ return undefined;
175
+ if (!this.dynamic)
176
+ throw RESTART;
177
+ return { initial, name };
178
+ }
179
+ // Resolved at run time against the dynamic scope, so a schema with a bookended $dynamicRef keeps its compiler.
180
+ dynamicLookup(name, compile) {
181
+ const found = new Map();
182
+ return (uri) => {
183
+ const key = `${uri}#${name}`;
184
+ let check = found.get(key);
185
+ if (check === undefined) {
186
+ const target = this.r.dynamicAnchors.get(key);
187
+ check = target === undefined ? null : compile(target, this.r.baseOf.get(target) ?? uri);
188
+ found.set(key, check);
189
+ }
190
+ return check;
191
+ };
192
+ }
193
+ /** anyOf/oneOf whose branches are all objects with a distinct required const on one key: the tag picks the branch. */
194
+ tagged(branches, base) {
195
+ if (branches.length < 2)
196
+ return undefined;
197
+ const resolved = [];
198
+ for (const branch of branches) {
199
+ if (!isSchemaObject(branch))
200
+ return undefined;
201
+ const ref = typeof branch.$ref === "string" && Object.keys(branch).length === 1 ? branch.$ref : undefined;
202
+ const node = ref === undefined ? branch : this.r.resolve(ref, this.r.baseFor(branch, base)).node;
203
+ if (!isSchemaObject(node))
204
+ return undefined;
205
+ resolved.push(node);
206
+ }
207
+ const first = resolved[0].properties;
208
+ if (!isSchemaObject(first))
209
+ return undefined;
210
+ for (const key of Object.keys(first)) {
211
+ const tags = resolved.map((s) => tagOf(s, key));
212
+ if (tags.some((t) => t === undefined) || new Set(tags).size !== tags.length)
213
+ continue;
214
+ return taggedCheck(key, tags, branches.map((s) => this.check(s, base)));
215
+ }
216
+ return undefined;
217
+ }
218
+ stringGroup(node, strict) {
219
+ const min = number(node.minLength) ?? 0;
220
+ const max = number(node.maxLength) ?? Number.POSITIVE_INFINITY;
221
+ const re = typeof node.pattern === "string" ? sharedRegex(node.pattern) : undefined;
222
+ const format = this.formats !== undefined && typeof node.format === "string" && Object.hasOwn(this.formats, node.format)
223
+ ? this.formats[node.format]
224
+ : undefined;
225
+ if (min === 0 && max === Number.POSITIVE_INFINITY && re === undefined && format === undefined)
226
+ return undefined;
227
+ return stringCheck(strict, min, max, re, format);
228
+ }
229
+ numberGroup(node, mode) {
230
+ const min = number(node.minimum);
231
+ const max = number(node.maximum);
232
+ const xmin = number(node.exclusiveMinimum);
233
+ const xmax = number(node.exclusiveMaximum);
234
+ const multipleOf = number(node.multipleOf);
235
+ if ([min, max, xmin, xmax, multipleOf].every((x) => x === undefined))
236
+ return undefined;
237
+ const inf = Number.POSITIVE_INFINITY;
238
+ return numberCheck(mode, min ?? -inf, max ?? inf, xmin ?? -inf, xmax ?? inf, multipleOf);
239
+ }
240
+ objectGroup(node, base, strict) {
241
+ const onlyCore = OBJECT_EXTRAS.every((k) => node[k] === undefined);
242
+ // A schema with only the core object keywords gets one closure that also does the type guard.
243
+ const core = this.objectCore(node, base, onlyCore ? (strict ? GUARD_STRICT : GUARD_LOOSE) : GUARD_NONE);
244
+ if (core !== undefined && onlyCore)
245
+ return core;
246
+ const parts = core === undefined ? [] : [core];
247
+ if (node.propertyNames !== undefined)
248
+ parts.push(propertyNamesCheck(this.check(node.propertyNames, base)));
249
+ const minProperties = number(node.minProperties);
250
+ const maxProperties = number(node.maxProperties);
251
+ if (minProperties !== undefined || maxProperties !== undefined) {
252
+ parts.push(propertyCountCheck(minProperties ?? 0, maxProperties ?? Number.POSITIVE_INFINITY));
253
+ }
254
+ const dependentRequired = [];
255
+ const dependentSchemas = [];
256
+ if (this.draft !== "7") {
257
+ for (const [k, list] of entries(node.dependentRequired))
258
+ if (Array.isArray(list))
259
+ dependentRequired.push([k, list]);
260
+ for (const [k, s] of entries(node.dependentSchemas))
261
+ dependentSchemas.push([k, this.check(s, base)]);
262
+ }
263
+ for (const [k, d] of entries(node.dependencies)) {
264
+ if (Array.isArray(d))
265
+ dependentRequired.push([k, d]);
266
+ else
267
+ dependentSchemas.push([k, this.check(d, base)]);
268
+ }
269
+ if (dependentRequired.length > 0)
270
+ parts.push(dependentRequiredCheck(dependentRequired));
271
+ if (dependentSchemas.length > 0)
272
+ parts.push(dependentSchemasCheck(dependentSchemas));
273
+ if (parts.length === 0)
274
+ return strict ? IS_OBJECT : undefined;
275
+ return guardObject(and(parts), strict);
276
+ }
277
+ objectCore(node, base, guard) {
278
+ const properties = isSchemaObject(node.properties) ? node.properties : {};
279
+ const required = Array.isArray(node.required) ? node.required.filter((k) => typeof k === "string") : [];
280
+ const patterns = isSchemaObject(node.patternProperties) ? node.patternProperties : {};
281
+ const additional = node.additionalProperties;
282
+ const keys = Object.keys(properties);
283
+ const patternKeys = Object.keys(patterns);
284
+ if (keys.length + required.length + patternKeys.length === 0 &&
285
+ (additional === undefined || additional === true)) {
286
+ return undefined;
287
+ }
288
+ // One array per object: key, check, flags (leaf code, required, key also names an Object.prototype member).
289
+ const entries = [];
290
+ for (const k of keys) {
291
+ const check = this.check(properties[k], base);
292
+ const flags = (LEAF_CODES.get(check) ?? 0) |
293
+ (required.includes(k) ? REQUIRED : 0) |
294
+ (k in Object.prototype ? INHERITED : 0);
295
+ entries.push(k, check, flags);
296
+ }
297
+ const extraRequired = required.filter((k) => !Object.hasOwn(properties, k));
298
+ const pats = patternKeys.map((p) => [sharedRegex(p), this.check(patterns[p], base)]);
299
+ const extra = additional === undefined || additional === true ? undefined : this.check(additional, base);
300
+ if (pats.length === 0 && extraRequired.length === 0 && (extra === undefined || additional === false)) {
301
+ const requiredCount = keys.filter((k) => required.includes(k)).length;
302
+ return declaredObject(entries, requiredCount, additional === false, guard);
303
+ }
304
+ return openObject(entries, keys, extraRequired, pats, extra, guard);
305
+ }
306
+ arrayGroup(node, base, strict) {
307
+ let prefix = [];
308
+ let rest;
309
+ if (Array.isArray(node.items)) {
310
+ prefix = node.items;
311
+ rest = node.additionalItems;
312
+ }
313
+ else {
314
+ if (this.draft !== "7" && Array.isArray(node.prefixItems))
315
+ prefix = node.prefixItems;
316
+ rest = node.items;
317
+ }
318
+ const prefixChecks = prefix.map((s) => this.check(s, base));
319
+ const restCheck = rest === undefined || rest === true ? undefined : this.check(rest, base);
320
+ const minItems = number(node.minItems);
321
+ const maxItems = number(node.maxItems);
322
+ if (node.contains === undefined &&
323
+ node.uniqueItems !== true &&
324
+ (prefixChecks.length > 0 || restCheck !== undefined)) {
325
+ // The common array: one closure for the guard, the length bounds and the items.
326
+ const guard = strict ? GUARD_STRICT : GUARD_LOOSE;
327
+ return listCheck(guard, minItems ?? 0, maxItems ?? Number.POSITIVE_INFINITY, prefixChecks, restCheck);
328
+ }
329
+ const parts = [];
330
+ if (prefixChecks.length > 0 || restCheck !== undefined)
331
+ parts.push(itemsCheck(prefixChecks, restCheck));
332
+ if (minItems !== undefined || maxItems !== undefined) {
333
+ parts.push(lengthCheck(minItems ?? 0, maxItems ?? Number.POSITIVE_INFINITY));
334
+ }
335
+ if (node.contains !== undefined) {
336
+ const min = this.draft === "7" ? 1 : (number(node.minContains) ?? 1);
337
+ const max = this.draft === "7" ? Number.POSITIVE_INFINITY : (number(node.maxContains) ?? Number.POSITIVE_INFINITY);
338
+ parts.push(containsCheck(this.check(node.contains, base), min, max));
339
+ }
340
+ if (node.uniqueItems === true)
341
+ parts.push(uniqueCheck);
342
+ if (parts.length === 0)
343
+ return strict ? IS_ARRAY : undefined;
344
+ return guardArray(and(parts), strict);
345
+ }
346
+ /** The annotating check of a schema evaluated in place (only below `unevaluatedProperties`/`unevaluatedItems`). */
347
+ annotating(node, base) {
348
+ if (node === true)
349
+ return ANNOTATING_TRUE;
350
+ if (node === false)
351
+ return ANNOTATING_FALSE;
352
+ if (!isSchemaObject(node))
353
+ throw new Error(`A schema must be an object or a boolean, got ${JSON.stringify(node)}`);
354
+ const cached = this.annotatingCache.get(node);
355
+ if (cached !== undefined)
356
+ return cached;
357
+ const slot = { check: undefined };
358
+ this.annotatingCache.set(node, indirectAnnotating(slot));
359
+ const check = this.buildAnnotating(node, this.r.baseFor(node, base));
360
+ slot.check = check;
361
+ this.annotatingCache.set(node, check);
362
+ return check;
363
+ }
364
+ buildAnnotating(node, base) {
365
+ const rest = {};
366
+ let annotates = false;
367
+ for (const k of Object.keys(node)) {
368
+ if (ANNOTATING.has(k))
369
+ annotates = true;
370
+ else
371
+ rest[k] = node[k];
372
+ }
373
+ const plain = this.plain(rest, base);
374
+ const parts = [];
375
+ if (annotates)
376
+ this.annotatingParts(node, base, parts);
377
+ const all = parts.length === 0 ? ignoreAnnotations(plain) : annotateAll(plain, parts);
378
+ const own = node.unevaluatedProperties !== undefined || node.unevaluatedItems !== undefined
379
+ ? isolateAnnotations(all)
380
+ : all;
381
+ return this.dynamic && this.r.isResource(node, base) ? scopedAnnotating(this.scope, base, own) : own;
382
+ }
383
+ annotatingParts(node, base, parts) {
384
+ if (node.properties !== undefined ||
385
+ node.patternProperties !== undefined ||
386
+ node.additionalProperties !== undefined) {
387
+ const props = entries(node.properties).map(([k, s]) => [k, this.check(s, base)]);
388
+ const pats = entries(node.patternProperties).map(([p, s]) => [sharedRegex(p), this.check(s, base)]);
389
+ const extra = node.additionalProperties === undefined ? undefined : this.check(node.additionalProperties, base);
390
+ parts.push(annotateObject(props, pats, extra));
391
+ }
392
+ if (node.prefixItems !== undefined || node.items !== undefined || node.contains !== undefined) {
393
+ const prefix = Array.isArray(node.prefixItems)
394
+ ? node.prefixItems
395
+ : Array.isArray(node.items)
396
+ ? node.items
397
+ : [];
398
+ const rest = Array.isArray(node.items) ? node.additionalItems : node.items;
399
+ parts.push(annotateArray(prefix.map((s) => this.check(s, base)), rest === undefined ? undefined : this.check(rest, base), node.contains === undefined ? undefined : this.check(node.contains, base), number(node.minContains) ?? 1, number(node.maxContains) ?? Number.POSITIVE_INFINITY));
400
+ }
401
+ if (Array.isArray(node.allOf))
402
+ for (const s of node.allOf)
403
+ parts.push(this.annotating(s, base));
404
+ if (Array.isArray(node.anyOf))
405
+ parts.push(annotateAny(node.anyOf.map((s) => this.annotating(s, base)), false));
406
+ if (Array.isArray(node.oneOf))
407
+ parts.push(annotateAny(node.oneOf.map((s) => this.annotating(s, base)), true));
408
+ if (node.if !== undefined) {
409
+ const then = node.then === undefined ? undefined : this.annotating(node.then, base);
410
+ const otherwise = node.else === undefined ? undefined : this.annotating(node.else, base);
411
+ parts.push(annotateIf(this.annotating(node.if, base), then, otherwise));
412
+ }
413
+ if (typeof node.$ref === "string")
414
+ parts.push(this.annotatingRef(node.$ref, base));
415
+ if (typeof node.$dynamicRef === "string")
416
+ parts.push(this.annotatingDynamicRef(node.$dynamicRef, base));
417
+ for (const [k, s] of entries(node.dependentSchemas))
418
+ parts.push(annotateDependent(k, this.annotating(s, base)));
419
+ if (node.unevaluatedProperties !== undefined) {
420
+ parts.push(unevaluatedProperties(this.check(node.unevaluatedProperties, base)));
421
+ }
422
+ if (node.unevaluatedItems !== undefined)
423
+ parts.push(unevaluatedItems(this.check(node.unevaluatedItems, base)));
424
+ }
425
+ annotatingRef(ref, base) {
426
+ const target = this.r.resolve(ref, base);
427
+ const check = this.annotating(target.node, target.base);
428
+ return this.dynamic && target.base !== base ? scopedAnnotating(this.scope, target.base, check) : check;
429
+ }
430
+ annotatingDynamicRef(ref, base) {
431
+ const resolved = this.bookended(ref, base);
432
+ if (resolved === undefined)
433
+ return this.annotatingRef(ref, base);
434
+ const { initial, name } = resolved;
435
+ const fallback = this.annotating(initial.node, initial.base);
436
+ const lookup = this.dynamicLookup(name, (node, b) => this.annotating(node, b));
437
+ const scope = this.scope;
438
+ return (v, a) => {
439
+ for (let i = 0; i < scope.length; i++) {
440
+ const check = lookup(scope[i]);
441
+ if (check !== null)
442
+ return check(v, a);
443
+ }
444
+ return fallback(v, a);
445
+ };
446
+ }
447
+ }
448
+ /** Keywords that never affect a check. */
449
+ export const NEUTRAL_KEYWORDS = new Set([
450
+ "$schema",
451
+ "$comment",
452
+ "title",
453
+ "description",
454
+ "default",
455
+ "examples",
456
+ "deprecated",
457
+ "readOnly",
458
+ "writeOnly",
459
+ "$defs",
460
+ "definitions",
461
+ "contentEncoding",
462
+ "contentMediaType",
463
+ "minContains",
464
+ "maxContains",
465
+ "$vocabulary",
466
+ ]);
467
+ // The object keywords besides the core (properties, required, patternProperties, additionalProperties).
468
+ const OBJECT_EXTRAS = [
469
+ "propertyNames",
470
+ "minProperties",
471
+ "maxProperties",
472
+ "dependentRequired",
473
+ "dependentSchemas",
474
+ "dependencies",
475
+ ];
476
+ // The keywords an annotating check handles itself; every other keyword compiles into its plain part.
477
+ const ANNOTATING = new Set([
478
+ "properties",
479
+ "patternProperties",
480
+ "additionalProperties",
481
+ "prefixItems",
482
+ "items",
483
+ "additionalItems",
484
+ "contains",
485
+ "minContains",
486
+ "maxContains",
487
+ "allOf",
488
+ "anyOf",
489
+ "oneOf",
490
+ "if",
491
+ "then",
492
+ "else",
493
+ "$ref",
494
+ "$dynamicRef",
495
+ "dependentSchemas",
496
+ "unevaluatedProperties",
497
+ "unevaluatedItems",
498
+ ]);
499
+ /** anyOf/oneOf whose branches are all `{ const: primitive }`: an enum (distinct values make oneOf the same). */
500
+ function constUnion(branches, exactlyOne) {
501
+ const values = [];
502
+ for (const branch of branches) {
503
+ if (!isSchemaObject(branch) || !Object.hasOwn(branch, "const"))
504
+ return undefined;
505
+ for (const k of Object.keys(branch))
506
+ if (k !== "const" && !NEUTRAL_KEYWORDS.has(k))
507
+ return undefined;
508
+ if (typeof branch.const === "object" && branch.const !== null)
509
+ return undefined;
510
+ if (exactlyOne && values.includes(branch.const))
511
+ return undefined;
512
+ values.push(branch.const);
513
+ }
514
+ return enumCheck(values);
515
+ }
516
+ // The tag of a tagged-union branch: a primitive const on a required property of an object schema.
517
+ function tagOf(branch, key) {
518
+ const properties = branch.properties;
519
+ if (branch.type !== "object" || !Array.isArray(branch.required) || !branch.required.includes(key))
520
+ return undefined;
521
+ const tag = isSchemaObject(properties) ? properties[key] : undefined;
522
+ if (!isSchemaObject(tag) || !Object.hasOwn(tag, "const"))
523
+ return undefined;
524
+ return typeof tag.const === "object" && tag.const !== null ? undefined : tag.const;
525
+ }
526
+ function number(value) {
527
+ return typeof value === "number" ? value : undefined;
528
+ }
529
+ function entries(value) {
530
+ return isSchemaObject(value) ? Object.entries(value) : [];
531
+ }
532
+ //# sourceMappingURL=compiler.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"compiler.js","sourceRoot":"","sources":["../src/compiler.ts"],"names":[],"mappings":"AAAA,iHAAiH;AACjH,kHAAkH;AAClH,kDAAkD;AAElD,OAAO,EACN,gBAAgB,EAChB,eAAe,EAEf,WAAW,EACX,WAAW,EACX,aAAa,EACb,iBAAiB,EACjB,UAAU,EACV,cAAc,EACd,iBAAiB,EACjB,kBAAkB,EAClB,kBAAkB,EAClB,gBAAgB,EAChB,gBAAgB,EAChB,qBAAqB,EACrB,oBAAoB,GACpB,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EACN,MAAM,EACN,GAAG,EACH,QAAQ,EACR,UAAU,EACV,UAAU,EACV,aAAa,EACb,cAAc,EACd,sBAAsB,EACtB,qBAAqB,EACrB,SAAS,EACT,WAAW,EACX,UAAU,EACV,YAAY,EAEZ,UAAU,EACV,WAAW,EACX,SAAS,EACT,QAAQ,EACR,SAAS,EACT,OAAO,EACP,QAAQ,EACR,UAAU,E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,CAAC,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,QAAQ,CAAC,GAAG,CAAC;QAAE,OAAO,SAAS,CAAC;IACpH,MAAM,GAAG,GAAG,cAAc,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;IACrE,IAAI,CAAC,cAAc,CAAC,GAAG,CAAC,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,GAAG,EAAE,OAAO,CAAC;QAAE,OAAO,SAAS,CAAC;IAC3E,OAAO,OAAO,GAAG,CAAC,KAAK,KAAK,QAAQ,IAAI,GAAG,CAAC,KAAK,KAAK,IAAI,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,GAAG,CAAC,KAAK,CAAC;AACpF,CAAC;AAED,SAAS,MAAM,CAAC,KAAc;IAC7B,OAAO,OAAO,KAAK,KAAK,QAAQ,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,SAAS,CAAC;AACtD,CAAC;AAED,SAAS,OAAO,CAAC,KAAc;IAC9B,OAAO,cAAc,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;AAC3D,CAAC","sourcesContent":["// The compiler: a schema to one check closure, built once. Keywords group by the type they constrain, so a value\n// is classified once per schema, and the common shapes (closed objects, arrays of one item schema, tagged unions,\n// leaf schemas) get one specialized closure each.\n\nimport {\n\tANNOTATING_FALSE,\n\tANNOTATING_TRUE,\n\ttype AnnotatingCheck,\n\tannotateAll,\n\tannotateAny,\n\tannotateArray,\n\tannotateDependent,\n\tannotateIf,\n\tannotateObject,\n\tignoreAnnotations,\n\tindirectAnnotating,\n\tisolateAnnotations,\n\tscopedAnnotating,\n\tunevaluatedItems,\n\tunevaluatedProperties,\n\twithFreshAnnotations,\n} from \"./annotations.ts\";\nimport {\n\tALWAYS,\n\tand,\n\tanyCheck,\n\tbytesCheck,\n\tconstCheck,\n\tcontainsCheck,\n\tdeclaredObject,\n\tdependentRequiredCheck,\n\tdependentSchemasCheck,\n\tenumCheck,\n\tGUARD_LOOSE,\n\tGUARD_NONE,\n\tGUARD_STRICT,\n\ttype Guard,\n\tguardArray,\n\tguardObject,\n\tINHERITED,\n\tIS_ARRAY,\n\tIS_OBJECT,\n\tifCheck,\n\tindirect,\n\titemsCheck,\n\tLEAF_CODES,\n\tlengthCheck,\n\tlistCheck,\n\tNEVER,\n\tnotCheck,\n\tnumberCheck,\n\toneCheck,\n\topenObject,\n\tpropertyCountCheck,\n\tpropertyNamesCheck,\n\tREQUIRED,\n\tscopedCheck,\n\tstringCheck,\n\tTYPE_CHECKS,\n\ttaggedCheck,\n\ttypeCheck,\n\tuniqueCheck,\n} from \"./checks.ts\";\nimport { documentOf, isSchemaObject, Resolver, resolveUri } from \"./resolver.ts\";\nimport { sharedRegex } from \"./shared.ts\";\nimport type { Check, CompileOptions, FormatCheck, JsonSchema, SchemaObject } from \"./types.ts\";\n\n/** Thrown when a compile without dynamic scope tracking meets a bookended `$dynamicRef`: compile again with it. */\nexport const RESTART = Symbol(\"restart\");\n\n/** One compile of a schema. Its caches and indexes are garbage once the root check is built. */\nexport class Compiler {\n\treadonly r: Resolver;\n\treadonly draft: \"2020-12\" | \"7\";\n\treadonly formats: Readonly<Record<string, FormatCheck>> | undefined;\n\t/** Whether checks track the dynamic scope (the schema has a bookended `$dynamicRef`). */\n\treadonly dynamic: boolean;\n\tprivate readonly schema: JsonSchema;\n\tprivate readonly scope: string[];\n\tprivate readonly cache = new Map<object, Check>();\n\tprivate readonly annotatingCache = new Map<object, AnnotatingCheck>();\n\n\tconstructor(schema: JsonSchema, options: CompileOptions, dynamic: boolean) {\n\t\tthis.schema = schema;\n\t\tthis.r = new Resolver(schema, options);\n\t\tthis.draft = this.r.draft;\n\t\tthis.formats = options.formats;\n\t\tthis.dynamic = dynamic;\n\t\tthis.scope = [];\n\t}\n\n\t/** The check of the root schema. */\n\troot(): Check {\n\t\treturn this.check(this.schema, this.r.rootBase);\n\t}\n\n\t/** The check of a schema (cached by schema object; a recursive reference goes through an indirection). */\n\tcheck(node: unknown, base: string): Check {\n\t\tif (node === true) return ALWAYS;\n\t\tif (node === false) return NEVER;\n\t\tif (!isSchemaObject(node))\n\t\t\tthrow new Error(`A schema must be an object or a boolean, got ${JSON.stringify(node)}`);\n\t\tconst cached = this.cache.get(node);\n\t\tif (cached !== undefined) return cached;\n\t\tconst bare = this.bareType(node);\n\t\tif (bare !== undefined) return bare;\n\t\tconst slot: { check: Check | undefined } = { check: undefined };\n\t\tthis.cache.set(node, indirect(slot));\n\t\tconst check = this.build(node, this.r.baseFor(node, base));\n\t\tslot.check = check;\n\t\tthis.cache.set(node, check);\n\t\treturn check;\n\t}\n\n\tprivate build(node: SchemaObject, base: string): Check {\n\t\tif (this.draft === \"7\" && typeof node.$ref === \"string\") return this.ref(node.$ref, base);\n\t\tif (this.draft !== \"7\" && (node.unevaluatedProperties !== undefined || node.unevaluatedItems !== undefined)) {\n\t\t\treturn withFreshAnnotations(this.annotating(node, base));\n\t\t}\n\t\tconst check = this.plain(node, base);\n\t\treturn this.dynamic && this.r.isResource(node, base) ? scopedCheck(this.scope, base, check) : check;\n\t}\n\n\t/**\n\t * The module-level check of a schema that is only a `type` (with annotations), `ALWAYS` for one with no assertion\n\t * at all; undefined for every other schema. These are the most common subschemas and cost nothing to share.\n\t */\n\tprivate bareType(node: SchemaObject): Check | undefined {\n\t\tlet type: unknown;\n\t\tfor (const k in node) {\n\t\t\tif (k === \"type\") type = node.type;\n\t\t\telse if (!NEUTRAL_KEYWORDS.has(k)) return undefined;\n\t\t}\n\t\tif (type === undefined) return ALWAYS;\n\t\treturn typeof type === \"string\" ? TYPE_CHECKS.get(type) : undefined;\n\t}\n\n\t/** Every keyword of `node`, not tracking annotations. */\n\tprivate plain(node: SchemaObject, base: string): Check {\n\t\tconst parts: Check[] = [];\n\t\tconst types = node.type === undefined ? undefined : Array.isArray(node.type) ? node.type : [node.type];\n\t\tconst single = types?.length === 1 ? types[0] : undefined;\n\t\tlet typeInGroup = false;\n\t\tif (single === \"bytes\") {\n\t\t\tparts.push(bytesCheck(number(node.minLength) ?? 0, number(node.maxLength) ?? Number.POSITIVE_INFINITY));\n\t\t\ttypeInGroup = true;\n\t\t} else {\n\t\t\tconst string = this.stringGroup(node, single === \"string\");\n\t\t\tif (string !== undefined) parts.push(string);\n\t\t\tconst numeric = single === \"number\" || single === \"integer\";\n\t\t\tconst number = this.numberGroup(node, single === \"number\" ? 1 : single === \"integer\" ? 2 : 0);\n\t\t\tif (number !== undefined) parts.push(number);\n\t\t\tconst object = this.objectGroup(node, base, single === \"object\");\n\t\t\tif (object !== undefined) parts.push(object);\n\t\t\tconst array = this.arrayGroup(node, base, single === \"array\");\n\t\t\tif (array !== undefined) parts.push(array);\n\t\t\ttypeInGroup =\n\t\t\t\t(single === \"string\" && string !== undefined) ||\n\t\t\t\t(numeric && number !== undefined) ||\n\t\t\t\t(single === \"object\" && object !== undefined) ||\n\t\t\t\t(single === \"array\" && array !== undefined);\n\t\t}\n\t\tif (types !== undefined && !typeInGroup) parts.unshift(typeCheck(types));\n\t\tthis.inPlace(node, base, parts);\n\t\treturn and(parts);\n\t}\n\n\t// The keywords that apply to the value itself, whatever its type.\n\tprivate inPlace(node: SchemaObject, base: string, parts: Check[]): void {\n\t\tif (Array.isArray(node.enum)) parts.push(enumCheck(node.enum));\n\t\tif (Object.hasOwn(node, \"const\")) parts.push(constCheck(node.const));\n\t\tif (Array.isArray(node.allOf)) parts.push(and(node.allOf.map((s) => this.check(s, base))));\n\t\tif (Array.isArray(node.anyOf)) parts.push(this.union(node.anyOf, base, false));\n\t\tif (Array.isArray(node.oneOf)) parts.push(this.union(node.oneOf, base, true));\n\t\tif (node.not !== undefined) parts.push(notCheck(this.check(node.not, base)));\n\t\tif (node.if !== undefined && (node.then !== undefined || node.else !== undefined)) {\n\t\t\tconst then = node.then === undefined ? ALWAYS : this.check(node.then, base);\n\t\t\tconst otherwise = node.else === undefined ? ALWAYS : this.check(node.else, base);\n\t\t\tparts.push(ifCheck(this.check(node.if, base), then, otherwise));\n\t\t}\n\t\tif (typeof node.$ref === \"string\") parts.push(this.ref(node.$ref, base));\n\t\tif (this.draft !== \"7\" && typeof node.$dynamicRef === \"string\") {\n\t\t\tparts.push(this.dynamicRef(node.$dynamicRef, base));\n\t\t}\n\t}\n\n\tprivate union(branches: readonly unknown[], base: string, exactlyOne: boolean): Check {\n\t\tconst checks = () => branches.map((s) => this.check(s, base));\n\t\treturn (\n\t\t\tconstUnion(branches, exactlyOne) ??\n\t\t\tthis.tagged(branches, base) ??\n\t\t\t(exactlyOne ? oneCheck(checks()) : anyCheck(checks()))\n\t\t);\n\t}\n\n\tprivate ref(ref: string, base: string): Check {\n\t\tconst target = this.r.resolve(ref, base);\n\t\tconst check = this.check(target.node, target.base);\n\t\treturn this.dynamic && target.base !== base ? scopedCheck(this.scope, target.base, check) : check;\n\t}\n\n\tprivate dynamicRef(ref: string, base: string): Check {\n\t\tconst resolved = this.bookended(ref, base);\n\t\tif (resolved === undefined) return this.ref(ref, base);\n\t\tconst { initial, name } = resolved;\n\t\tconst fallback = this.check(initial.node, initial.base);\n\t\tconst lookup = this.dynamicLookup(name, (node, b) => this.check(node, b));\n\t\tconst scope = this.scope;\n\t\treturn (v) => {\n\t\t\tfor (let i = 0; i < scope.length; i++) {\n\t\t\t\tconst check = lookup(scope[i]);\n\t\t\t\tif (check !== null) return check(v);\n\t\t\t}\n\t\t\treturn fallback(v);\n\t\t};\n\t}\n\n\t/** The initial target and anchor name of a `$dynamicRef` that resolves dynamically, or undefined for a plain ref. */\n\tprivate bookended(\n\t\tref: string,\n\t\tbase: string,\n\t): { initial: { node: unknown; base: string }; name: string } | undefined {\n\t\tconst initial = this.r.resolve(ref, base);\n\t\tconst uri = resolveUri(ref, base);\n\t\tconst name = uri.slice(documentOf(uri).length + 1);\n\t\tconst anchored = isSchemaObject(initial.node) && initial.node.$dynamicAnchor === name;\n\t\tif (name === \"\" || name.startsWith(\"/\") || !anchored) return undefined;\n\t\tif (!this.dynamic) throw RESTART;\n\t\treturn { initial, name };\n\t}\n\n\t// Resolved at run time against the dynamic scope, so a schema with a bookended $dynamicRef keeps its compiler.\n\tprivate dynamicLookup<T>(name: string, compile: (node: SchemaObject, base: string) => T): (uri: string) => T | null {\n\t\tconst found = new Map<string, T | null>();\n\t\treturn (uri) => {\n\t\t\tconst key = `${uri}#${name}`;\n\t\t\tlet check = found.get(key);\n\t\t\tif (check === undefined) {\n\t\t\t\tconst target = this.r.dynamicAnchors.get(key);\n\t\t\t\tcheck = target === undefined ? null : compile(target, this.r.baseOf.get(target) ?? uri);\n\t\t\t\tfound.set(key, check);\n\t\t\t}\n\t\t\treturn check;\n\t\t};\n\t}\n\n\t/** anyOf/oneOf whose branches are all objects with a distinct required const on one key: the tag picks the branch. */\n\tprivate tagged(branches: readonly unknown[], base: string): Check | undefined {\n\t\tif (branches.length < 2) return undefined;\n\t\tconst resolved: SchemaObject[] = [];\n\t\tfor (const branch of branches) {\n\t\t\tif (!isSchemaObject(branch)) return undefined;\n\t\t\tconst ref = typeof branch.$ref === \"string\" && Object.keys(branch).length === 1 ? branch.$ref : undefined;\n\t\t\tconst node = ref === undefined ? branch : this.r.resolve(ref, this.r.baseFor(branch, base)).node;\n\t\t\tif (!isSchemaObject(node)) return undefined;\n\t\t\tresolved.push(node);\n\t\t}\n\t\tconst first = resolved[0].properties;\n\t\tif (!isSchemaObject(first)) return undefined;\n\t\tfor (const key of Object.keys(first)) {\n\t\t\tconst tags = resolved.map((s) => tagOf(s, key));\n\t\t\tif (tags.some((t) => t === undefined) || new Set(tags).size !== tags.length) continue;\n\t\t\treturn taggedCheck(\n\t\t\t\tkey,\n\t\t\t\ttags,\n\t\t\t\tbranches.map((s) => this.check(s, base)),\n\t\t\t);\n\t\t}\n\t\treturn undefined;\n\t}\n\n\tprivate stringGroup(node: SchemaObject, strict: boolean): Check | undefined {\n\t\tconst min = number(node.minLength) ?? 0;\n\t\tconst max = number(node.maxLength) ?? Number.POSITIVE_INFINITY;\n\t\tconst re = typeof node.pattern === \"string\" ? sharedRegex(node.pattern) : undefined;\n\t\tconst format =\n\t\t\tthis.formats !== undefined && typeof node.format === \"string\" && Object.hasOwn(this.formats, node.format)\n\t\t\t\t? this.formats[node.format]\n\t\t\t\t: undefined;\n\t\tif (min === 0 && max === Number.POSITIVE_INFINITY && re === undefined && format === undefined) return undefined;\n\t\treturn stringCheck(strict, min, max, re, format);\n\t}\n\n\tprivate numberGroup(node: SchemaObject, mode: 0 | 1 | 2): Check | undefined {\n\t\tconst min = number(node.minimum);\n\t\tconst max = number(node.maximum);\n\t\tconst xmin = number(node.exclusiveMinimum);\n\t\tconst xmax = number(node.exclusiveMaximum);\n\t\tconst multipleOf = number(node.multipleOf);\n\t\tif ([min, max, xmin, xmax, multipleOf].every((x) => x === undefined)) return undefined;\n\t\tconst inf = Number.POSITIVE_INFINITY;\n\t\treturn numberCheck(mode, min ?? -inf, max ?? inf, xmin ?? -inf, xmax ?? inf, multipleOf);\n\t}\n\n\tprivate objectGroup(node: SchemaObject, base: string, strict: boolean): Check | undefined {\n\t\tconst onlyCore = OBJECT_EXTRAS.every((k) => node[k] === undefined);\n\t\t// A schema with only the core object keywords gets one closure that also does the type guard.\n\t\tconst core = this.objectCore(node, base, onlyCore ? (strict ? GUARD_STRICT : GUARD_LOOSE) : GUARD_NONE);\n\t\tif (core !== undefined && onlyCore) return core;\n\t\tconst parts: Check[] = core === undefined ? [] : [core];\n\t\tif (node.propertyNames !== undefined) parts.push(propertyNamesCheck(this.check(node.propertyNames, base)));\n\t\tconst minProperties = number(node.minProperties);\n\t\tconst maxProperties = number(node.maxProperties);\n\t\tif (minProperties !== undefined || maxProperties !== undefined) {\n\t\t\tparts.push(propertyCountCheck(minProperties ?? 0, maxProperties ?? Number.POSITIVE_INFINITY));\n\t\t}\n\t\tconst dependentRequired: [string, string[]][] = [];\n\t\tconst dependentSchemas: [string, Check][] = [];\n\t\tif (this.draft !== \"7\") {\n\t\t\tfor (const [k, list] of entries(node.dependentRequired))\n\t\t\t\tif (Array.isArray(list)) dependentRequired.push([k, list]);\n\t\t\tfor (const [k, s] of entries(node.dependentSchemas)) dependentSchemas.push([k, this.check(s, base)]);\n\t\t}\n\t\tfor (const [k, d] of entries(node.dependencies)) {\n\t\t\tif (Array.isArray(d)) dependentRequired.push([k, d]);\n\t\t\telse dependentSchemas.push([k, this.check(d, base)]);\n\t\t}\n\t\tif (dependentRequired.length > 0) parts.push(dependentRequiredCheck(dependentRequired));\n\t\tif (dependentSchemas.length > 0) parts.push(dependentSchemasCheck(dependentSchemas));\n\t\tif (parts.length === 0) return strict ? IS_OBJECT : undefined;\n\t\treturn guardObject(and(parts), strict);\n\t}\n\n\tprivate objectCore(node: SchemaObject, base: string, guard: Guard): Check | undefined {\n\t\tconst properties = isSchemaObject(node.properties) ? node.properties : {};\n\t\tconst required = Array.isArray(node.required) ? node.required.filter((k) => typeof k === \"string\") : [];\n\t\tconst patterns = isSchemaObject(node.patternProperties) ? node.patternProperties : {};\n\t\tconst additional = node.additionalProperties;\n\t\tconst keys = Object.keys(properties);\n\t\tconst patternKeys = Object.keys(patterns);\n\t\tif (\n\t\t\tkeys.length + required.length + patternKeys.length === 0 &&\n\t\t\t(additional === undefined || additional === true)\n\t\t) {\n\t\t\treturn undefined;\n\t\t}\n\t\t// One array per object: key, check, flags (leaf code, required, key also names an Object.prototype member).\n\t\tconst entries: unknown[] = [];\n\t\tfor (const k of keys) {\n\t\t\tconst check = this.check(properties[k], base);\n\t\t\tconst flags =\n\t\t\t\t(LEAF_CODES.get(check) ?? 0) |\n\t\t\t\t(required.includes(k) ? REQUIRED : 0) |\n\t\t\t\t(k in Object.prototype ? INHERITED : 0);\n\t\t\tentries.push(k, check, flags);\n\t\t}\n\t\tconst extraRequired = required.filter((k) => !Object.hasOwn(properties, k));\n\t\tconst pats = patternKeys.map((p) => [sharedRegex(p), this.check(patterns[p], base)] as const);\n\t\tconst extra = additional === undefined || additional === true ? undefined : this.check(additional, base);\n\t\tif (pats.length === 0 && extraRequired.length === 0 && (extra === undefined || additional === false)) {\n\t\t\tconst requiredCount = keys.filter((k) => required.includes(k)).length;\n\t\t\treturn declaredObject(entries, requiredCount, additional === false, guard);\n\t\t}\n\t\treturn openObject(entries, keys, extraRequired, pats, extra, guard);\n\t}\n\n\tprivate arrayGroup(node: SchemaObject, base: string, strict: boolean): Check | undefined {\n\t\tlet prefix: readonly unknown[] = [];\n\t\tlet rest: unknown;\n\t\tif (Array.isArray(node.items)) {\n\t\t\tprefix = node.items;\n\t\t\trest = node.additionalItems;\n\t\t} else {\n\t\t\tif (this.draft !== \"7\" && Array.isArray(node.prefixItems)) prefix = node.prefixItems;\n\t\t\trest = node.items;\n\t\t}\n\t\tconst prefixChecks = prefix.map((s) => this.check(s, base));\n\t\tconst restCheck = rest === undefined || rest === true ? undefined : this.check(rest, base);\n\t\tconst minItems = number(node.minItems);\n\t\tconst maxItems = number(node.maxItems);\n\t\tif (\n\t\t\tnode.contains === undefined &&\n\t\t\tnode.uniqueItems !== true &&\n\t\t\t(prefixChecks.length > 0 || restCheck !== undefined)\n\t\t) {\n\t\t\t// The common array: one closure for the guard, the length bounds and the items.\n\t\t\tconst guard = strict ? GUARD_STRICT : GUARD_LOOSE;\n\t\t\treturn listCheck(guard, minItems ?? 0, maxItems ?? Number.POSITIVE_INFINITY, prefixChecks, restCheck);\n\t\t}\n\t\tconst parts: Check[] = [];\n\t\tif (prefixChecks.length > 0 || restCheck !== undefined) parts.push(itemsCheck(prefixChecks, restCheck));\n\t\tif (minItems !== undefined || maxItems !== undefined) {\n\t\t\tparts.push(lengthCheck(minItems ?? 0, maxItems ?? Number.POSITIVE_INFINITY));\n\t\t}\n\t\tif (node.contains !== undefined) {\n\t\t\tconst min = this.draft === \"7\" ? 1 : (number(node.minContains) ?? 1);\n\t\t\tconst max =\n\t\t\t\tthis.draft === \"7\" ? Number.POSITIVE_INFINITY : (number(node.maxContains) ?? Number.POSITIVE_INFINITY);\n\t\t\tparts.push(containsCheck(this.check(node.contains, base), min, max));\n\t\t}\n\t\tif (node.uniqueItems === true) parts.push(uniqueCheck);\n\t\tif (parts.length === 0) return strict ? IS_ARRAY : undefined;\n\t\treturn guardArray(and(parts), strict);\n\t}\n\n\t/** The annotating check of a schema evaluated in place (only below `unevaluatedProperties`/`unevaluatedItems`). */\n\tannotating(node: unknown, base: string): AnnotatingCheck {\n\t\tif (node === true) return ANNOTATING_TRUE;\n\t\tif (node === false) return ANNOTATING_FALSE;\n\t\tif (!isSchemaObject(node))\n\t\t\tthrow new Error(`A schema must be an object or a boolean, got ${JSON.stringify(node)}`);\n\t\tconst cached = this.annotatingCache.get(node);\n\t\tif (cached !== undefined) return cached;\n\t\tconst slot: { check: AnnotatingCheck | undefined } = { check: undefined };\n\t\tthis.annotatingCache.set(node, indirectAnnotating(slot));\n\t\tconst check = this.buildAnnotating(node, this.r.baseFor(node, base));\n\t\tslot.check = check;\n\t\tthis.annotatingCache.set(node, check);\n\t\treturn check;\n\t}\n\n\tprivate buildAnnotating(node: SchemaObject, base: string): AnnotatingCheck {\n\t\tconst rest: Record<string, unknown> = {};\n\t\tlet annotates = false;\n\t\tfor (const k of Object.keys(node)) {\n\t\t\tif (ANNOTATING.has(k)) annotates = true;\n\t\t\telse rest[k] = node[k];\n\t\t}\n\t\tconst plain = this.plain(rest, base);\n\t\tconst parts: AnnotatingCheck[] = [];\n\t\tif (annotates) this.annotatingParts(node, base, parts);\n\t\tconst all = parts.length === 0 ? ignoreAnnotations(plain) : annotateAll(plain, parts);\n\t\tconst own =\n\t\t\tnode.unevaluatedProperties !== undefined || node.unevaluatedItems !== undefined\n\t\t\t\t? isolateAnnotations(all)\n\t\t\t\t: all;\n\t\treturn this.dynamic && this.r.isResource(node, base) ? scopedAnnotating(this.scope, base, own) : own;\n\t}\n\n\tprivate annotatingParts(node: SchemaObject, base: string, parts: AnnotatingCheck[]): void {\n\t\tif (\n\t\t\tnode.properties !== undefined ||\n\t\t\tnode.patternProperties !== undefined ||\n\t\t\tnode.additionalProperties !== undefined\n\t\t) {\n\t\t\tconst props = entries(node.properties).map(([k, s]) => [k, this.check(s, base)] as const);\n\t\t\tconst pats = entries(node.patternProperties).map(([p, s]) => [sharedRegex(p), this.check(s, base)] as const);\n\t\t\tconst extra =\n\t\t\t\tnode.additionalProperties === undefined ? undefined : this.check(node.additionalProperties, base);\n\t\t\tparts.push(annotateObject(props, pats, extra));\n\t\t}\n\t\tif (node.prefixItems !== undefined || node.items !== undefined || node.contains !== undefined) {\n\t\t\tconst prefix = Array.isArray(node.prefixItems)\n\t\t\t\t? node.prefixItems\n\t\t\t\t: Array.isArray(node.items)\n\t\t\t\t\t? node.items\n\t\t\t\t\t: [];\n\t\t\tconst rest = Array.isArray(node.items) ? node.additionalItems : node.items;\n\t\t\tparts.push(\n\t\t\t\tannotateArray(\n\t\t\t\t\tprefix.map((s) => this.check(s, base)),\n\t\t\t\t\trest === undefined ? undefined : this.check(rest, base),\n\t\t\t\t\tnode.contains === undefined ? undefined : this.check(node.contains, base),\n\t\t\t\t\tnumber(node.minContains) ?? 1,\n\t\t\t\t\tnumber(node.maxContains) ?? Number.POSITIVE_INFINITY,\n\t\t\t\t),\n\t\t\t);\n\t\t}\n\t\tif (Array.isArray(node.allOf)) for (const s of node.allOf) parts.push(this.annotating(s, base));\n\t\tif (Array.isArray(node.anyOf))\n\t\t\tparts.push(\n\t\t\t\tannotateAny(\n\t\t\t\t\tnode.anyOf.map((s) => this.annotating(s, base)),\n\t\t\t\t\tfalse,\n\t\t\t\t),\n\t\t\t);\n\t\tif (Array.isArray(node.oneOf))\n\t\t\tparts.push(\n\t\t\t\tannotateAny(\n\t\t\t\t\tnode.oneOf.map((s) => this.annotating(s, base)),\n\t\t\t\t\ttrue,\n\t\t\t\t),\n\t\t\t);\n\t\tif (node.if !== undefined) {\n\t\t\tconst then = node.then === undefined ? undefined : this.annotating(node.then, base);\n\t\t\tconst otherwise = node.else === undefined ? undefined : this.annotating(node.else, base);\n\t\t\tparts.push(annotateIf(this.annotating(node.if, base), then, otherwise));\n\t\t}\n\t\tif (typeof node.$ref === \"string\") parts.push(this.annotatingRef(node.$ref, base));\n\t\tif (typeof node.$dynamicRef === \"string\") parts.push(this.annotatingDynamicRef(node.$dynamicRef, base));\n\t\tfor (const [k, s] of entries(node.dependentSchemas)) parts.push(annotateDependent(k, this.annotating(s, base)));\n\t\tif (node.unevaluatedProperties !== undefined) {\n\t\t\tparts.push(unevaluatedProperties(this.check(node.unevaluatedProperties, base)));\n\t\t}\n\t\tif (node.unevaluatedItems !== undefined) parts.push(unevaluatedItems(this.check(node.unevaluatedItems, base)));\n\t}\n\n\tprivate annotatingRef(ref: string, base: string): AnnotatingCheck {\n\t\tconst target = this.r.resolve(ref, base);\n\t\tconst check = this.annotating(target.node, target.base);\n\t\treturn this.dynamic && target.base !== base ? scopedAnnotating(this.scope, target.base, check) : check;\n\t}\n\n\tprivate annotatingDynamicRef(ref: string, base: string): AnnotatingCheck {\n\t\tconst resolved = this.bookended(ref, base);\n\t\tif (resolved === undefined) return this.annotatingRef(ref, base);\n\t\tconst { initial, name } = resolved;\n\t\tconst fallback = this.annotating(initial.node, initial.base);\n\t\tconst lookup = this.dynamicLookup(name, (node, b) => this.annotating(node, b));\n\t\tconst scope = this.scope;\n\t\treturn (v, a) => {\n\t\t\tfor (let i = 0; i < scope.length; i++) {\n\t\t\t\tconst check = lookup(scope[i]);\n\t\t\t\tif (check !== null) return check(v, a);\n\t\t\t}\n\t\t\treturn fallback(v, a);\n\t\t};\n\t}\n}\n\n/** Keywords that never affect a check. */\nexport const NEUTRAL_KEYWORDS = new Set([\n\t\"$schema\",\n\t\"$comment\",\n\t\"title\",\n\t\"description\",\n\t\"default\",\n\t\"examples\",\n\t\"deprecated\",\n\t\"readOnly\",\n\t\"writeOnly\",\n\t\"$defs\",\n\t\"definitions\",\n\t\"contentEncoding\",\n\t\"contentMediaType\",\n\t\"minContains\",\n\t\"maxContains\",\n\t\"$vocabulary\",\n]);\n\n// The object keywords besides the core (properties, required, patternProperties, additionalProperties).\nconst OBJECT_EXTRAS = [\n\t\"propertyNames\",\n\t\"minProperties\",\n\t\"maxProperties\",\n\t\"dependentRequired\",\n\t\"dependentSchemas\",\n\t\"dependencies\",\n];\n\n// The keywords an annotating check handles itself; every other keyword compiles into its plain part.\nconst ANNOTATING = new Set([\n\t\"properties\",\n\t\"patternProperties\",\n\t\"additionalProperties\",\n\t\"prefixItems\",\n\t\"items\",\n\t\"additionalItems\",\n\t\"contains\",\n\t\"minContains\",\n\t\"maxContains\",\n\t\"allOf\",\n\t\"anyOf\",\n\t\"oneOf\",\n\t\"if\",\n\t\"then\",\n\t\"else\",\n\t\"$ref\",\n\t\"$dynamicRef\",\n\t\"dependentSchemas\",\n\t\"unevaluatedProperties\",\n\t\"unevaluatedItems\",\n]);\n\n/** anyOf/oneOf whose branches are all `{ const: primitive }`: an enum (distinct values make oneOf the same). */\nfunction constUnion(branches: readonly unknown[], exactlyOne: boolean): Check | undefined {\n\tconst values: unknown[] = [];\n\tfor (const branch of branches) {\n\t\tif (!isSchemaObject(branch) || !Object.hasOwn(branch, \"const\")) return undefined;\n\t\tfor (const k of Object.keys(branch)) if (k !== \"const\" && !NEUTRAL_KEYWORDS.has(k)) return undefined;\n\t\tif (typeof branch.const === \"object\" && branch.const !== null) return undefined;\n\t\tif (exactlyOne && values.includes(branch.const)) return undefined;\n\t\tvalues.push(branch.const);\n\t}\n\treturn enumCheck(values);\n}\n\n// The tag of a tagged-union branch: a primitive const on a required property of an object schema.\nfunction tagOf(branch: SchemaObject, key: string): unknown {\n\tconst properties = branch.properties;\n\tif (branch.type !== \"object\" || !Array.isArray(branch.required) || !branch.required.includes(key)) return undefined;\n\tconst tag = isSchemaObject(properties) ? properties[key] : undefined;\n\tif (!isSchemaObject(tag) || !Object.hasOwn(tag, \"const\")) return undefined;\n\treturn typeof tag.const === \"object\" && tag.const !== null ? undefined : tag.const;\n}\n\nfunction number(value: unknown): number | undefined {\n\treturn typeof value === \"number\" ? value : undefined;\n}\n\nfunction entries(value: unknown): [string, unknown][] {\n\treturn isSchemaObject(value) ? Object.entries(value) : [];\n}\n"]}