@sorbetai/schema 0.0.0-stage → 0.1.0-alpha.16

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.
@@ -0,0 +1,1933 @@
1
+ //#region ../../node_modules/.pnpm/@earendil-works+pi-schema@1.5.0_patch_hash=3a50e14587df64dfdea0adbae45b34d11585bb58009be0694fa2cf4a7986fbdf/node_modules/@earendil-works/pi-schema/dist/resolver.js
2
+ /** The base URI of a root schema without `$id`; relative references resolve against it. */
3
+ const DEFAULT_BASE = "https://json-schema.invalid/root.json";
4
+ /**
5
+ * Resolves references in the root schema and the registered documents. The schema is indexed on the first
6
+ * reference, so a schema without references is never walked for identifiers.
7
+ */
8
+ var Resolver = class {
9
+ draft;
10
+ rootBase;
11
+ /** Schema object to the base URI it was indexed under. */
12
+ baseOf = /* @__PURE__ */ new Map();
13
+ /** URI (with a `#name` fragment) of every `$dynamicAnchor`, to its schema. */
14
+ dynamicAnchors = /* @__PURE__ */ new Map();
15
+ root;
16
+ options;
17
+ registry = /* @__PURE__ */ new Map();
18
+ rejectUnresolved;
19
+ /** The references that named nothing and resolved to `false` (with `unresolvedRefs: "reject"`). */
20
+ unresolved = /* @__PURE__ */ new Set();
21
+ resources = /* @__PURE__ */ new Map();
22
+ anchors = /* @__PURE__ */ new Map();
23
+ indexed = false;
24
+ constructor(root, options) {
25
+ this.draft = options.draft === "7" ? "7" : "2020-12";
26
+ this.root = root;
27
+ this.options = options;
28
+ this.rejectUnresolved = options.unresolvedRefs === "reject";
29
+ this.rootBase = isSchemaObject(root) ? this.baseFor(root, DEFAULT_BASE) : DEFAULT_BASE;
30
+ }
31
+ /**
32
+ * The base URI of `node`, whose parent has `base`: its `$id` changes it, unless draft 7 makes the `$id` inert. Once
33
+ * the schema is indexed, the indexed base (a resolved reference target already has its own).
34
+ */
35
+ baseFor(node, base) {
36
+ const indexed = this.baseOf.get(node);
37
+ if (indexed !== void 0) return indexed;
38
+ const id = node.$id;
39
+ if (typeof id !== "string") return base;
40
+ if (this.draft === "7" && (typeof node.$ref === "string" || id.startsWith("#"))) return base;
41
+ return documentOf(resolveUri(id, base));
42
+ }
43
+ /** Indexes the root schema and the registered documents' URIs (once). */
44
+ ensureIndexed() {
45
+ if (this.indexed) return;
46
+ this.indexed = true;
47
+ for (const [uri, schema] of Object.entries(this.options.schemas ?? {})) this.registry.set(documentOf(resolveUri(uri, DEFAULT_BASE)), schema);
48
+ this.resources.set(DEFAULT_BASE, this.root);
49
+ this.index(this.root, DEFAULT_BASE);
50
+ }
51
+ /**
52
+ * The schema a reference names, with the base URI it compiles under. Throws if it names nothing, or, with
53
+ * `unresolvedRefs: "reject"`, resolves to `false`, the schema no value passes.
54
+ */
55
+ resolve(ref, base) {
56
+ this.ensureIndexed();
57
+ if (!this.rejectUnresolved) return this.find(ref, base);
58
+ try {
59
+ return this.find(ref, base);
60
+ } catch {
61
+ this.unresolved.add(resolveUri(ref, base));
62
+ return {
63
+ node: false,
64
+ base
65
+ };
66
+ }
67
+ }
68
+ /** Whether `ref`, from `base`, named nothing and resolved to `false`. */
69
+ isUnresolved(ref, base) {
70
+ return this.unresolved.has(resolveUri(ref, base));
71
+ }
72
+ find(ref, base) {
73
+ const uri = resolveUri(ref, base);
74
+ const doc = documentOf(uri);
75
+ const fragment = uri.length > doc.length ? decodeURIComponent(uri.slice(doc.length + 1)) : "";
76
+ const root = this.resources.has(doc) ? this.resources.get(doc) : this.load(doc);
77
+ if (root === void 0) throw new Error(`Unresolved $ref ${ref} (no schema registered for ${doc})`);
78
+ if (fragment === "") return {
79
+ node: root,
80
+ base: doc
81
+ };
82
+ if (fragment.startsWith("/")) return this.pointer(root, doc, fragment);
83
+ const target = this.anchors.get(`${doc}#${fragment}`);
84
+ if (target === void 0) throw new Error(`Unresolved $ref ${ref} (no anchor ${fragment} in ${doc})`);
85
+ return {
86
+ node: target,
87
+ base: this.baseOf.get(target) ?? doc
88
+ };
89
+ }
90
+ /** Whether `node` is the root of the schema resource at `base`. */
91
+ isResource(node, base) {
92
+ this.ensureIndexed();
93
+ return this.resources.get(base) === node;
94
+ }
95
+ index(node, base) {
96
+ if (!isSchemaObject(node) || this.baseOf.has(node)) return;
97
+ let b = base;
98
+ const refOnly = this.draft === "7" && typeof node.$ref === "string";
99
+ if (!refOnly && typeof node.$id === "string") if (this.draft === "7" && node.$id.startsWith("#")) this.anchors.set(documentOf(b) + node.$id, node);
100
+ else {
101
+ const uri = resolveUri(node.$id, b);
102
+ b = documentOf(uri);
103
+ this.resources.set(b, node);
104
+ if (uri.length > b.length + 1) this.anchors.set(uri, node);
105
+ }
106
+ this.baseOf.set(node, b);
107
+ if (refOnly) return;
108
+ if (this.draft !== "7") {
109
+ if (typeof node.$anchor === "string") this.anchors.set(`${b}#${node.$anchor}`, node);
110
+ if (typeof node.$dynamicAnchor === "string") {
111
+ this.anchors.set(`${b}#${node.$dynamicAnchor}`, node);
112
+ this.dynamicAnchors.set(`${b}#${node.$dynamicAnchor}`, node);
113
+ }
114
+ }
115
+ for (const key of SCHEMA_KEYWORDS) this.index(node[key], b);
116
+ for (const key of MAP_KEYWORDS) {
117
+ const map = node[key];
118
+ if (isSchemaObject(map)) for (const k of Object.keys(map)) this.index(map[k], b);
119
+ }
120
+ for (const key of ARRAY_KEYWORDS) {
121
+ const list = node[key];
122
+ if (Array.isArray(list)) for (const s of list) this.index(s, b);
123
+ }
124
+ }
125
+ load(doc) {
126
+ const schema = this.registry.get(doc);
127
+ if (schema === void 0) return void 0;
128
+ this.resources.set(doc, schema);
129
+ this.index(schema, doc);
130
+ return schema;
131
+ }
132
+ pointer(root, base, fragment) {
133
+ let node = root;
134
+ let b = base;
135
+ for (const raw of fragment.split("/").slice(1)) {
136
+ const key = raw.replace(/~1/g, "/").replace(/~0/g, "~");
137
+ node = typeof node === "object" && node !== null && Object.hasOwn(node, key) ? node[key] : void 0;
138
+ if (node === void 0) throw new Error(`Unresolved $ref #${fragment} in ${base}`);
139
+ if (typeof node === "object" && node !== null) b = this.baseOf.get(node) ?? b;
140
+ }
141
+ return {
142
+ node,
143
+ base: b
144
+ };
145
+ }
146
+ };
147
+ const SCHEMA_KEYWORDS = [
148
+ "additionalProperties",
149
+ "propertyNames",
150
+ "contains",
151
+ "not",
152
+ "if",
153
+ "then",
154
+ "else",
155
+ "unevaluatedProperties",
156
+ "unevaluatedItems",
157
+ "additionalItems",
158
+ "contentSchema",
159
+ "items"
160
+ ];
161
+ const MAP_KEYWORDS = [
162
+ "properties",
163
+ "patternProperties",
164
+ "$defs",
165
+ "definitions",
166
+ "dependentSchemas",
167
+ "dependencies"
168
+ ];
169
+ const ARRAY_KEYWORDS = [
170
+ "allOf",
171
+ "anyOf",
172
+ "oneOf",
173
+ "prefixItems",
174
+ "items"
175
+ ];
176
+ /** Whether `value` is a schema object (not `true`/`false`, an array or a primitive). */
177
+ function isSchemaObject(value) {
178
+ return typeof value === "object" && value !== null && !Array.isArray(value);
179
+ }
180
+ /** `ref` resolved against `base`. URNs and other bases a URL parser rejects take fragment-only references. */
181
+ function resolveUri(ref, base) {
182
+ try {
183
+ return new URL(ref, base).href;
184
+ } catch {
185
+ return ref.startsWith("#") ? documentOf(base) + ref : ref;
186
+ }
187
+ }
188
+ /** `uri` without its fragment. */
189
+ function documentOf(uri) {
190
+ const hash = uri.indexOf("#");
191
+ return hash < 0 ? uri : uri.slice(0, hash);
192
+ }
193
+
194
+ //#endregion
195
+ //#region ../../node_modules/.pnpm/@earendil-works+pi-schema@1.5.0_patch_hash=3a50e14587df64dfdea0adbae45b34d11585bb58009be0694fa2cf4a7986fbdf/node_modules/@earendil-works/pi-schema/dist/shared.js
196
+ /**
197
+ * The regular expression of a `pattern` source, shared by source. Patterns are ECMAScript regular expressions with
198
+ * the `u` flag; a source that is invalid with it (some older schemas escape characters `u` rejects) compiles
199
+ * without it.
200
+ */
201
+ function sharedRegex(source) {
202
+ const hit = regexes.get(source)?.deref();
203
+ if (hit !== void 0) return hit;
204
+ let re;
205
+ try {
206
+ re = new RegExp(source, "u");
207
+ } catch {
208
+ re = new RegExp(source);
209
+ }
210
+ regexes.set(source, new WeakRef(re));
211
+ regexCleanup.register(re, source);
212
+ return re;
213
+ }
214
+ const regexes = /* @__PURE__ */ new Map();
215
+ const regexCleanup = new FinalizationRegistry((source) => {
216
+ if (regexes.get(source)?.deref() === void 0) regexes.delete(source);
217
+ });
218
+
219
+ //#endregion
220
+ //#region ../../node_modules/.pnpm/@earendil-works+pi-schema@1.5.0_patch_hash=3a50e14587df64dfdea0adbae45b34d11585bb58009be0694fa2cf4a7986fbdf/node_modules/@earendil-works/pi-schema/dist/coerce.js
221
+ /** Coerces values for one compiled schema. */
222
+ var Coercer = class {
223
+ c;
224
+ schema;
225
+ /**
226
+ * The (schema node, value) pairs pass 2 is converting through a re-entry point, as a stack. Conversion can enter
227
+ * a node again with the same value only through a `$ref` or by wrapping a single value into an array (also for
228
+ * schemas that cycle through shared JS objects): a recursive schema that meets a value no branch accepts would
229
+ * convert it without end. A pair already on the stack (primitives by value, objects by reference) leaves the value
230
+ * unchanged. Only those two points push, so schemas without references or wraps pay nothing.
231
+ */
232
+ entered = [];
233
+ /** How often a re-entry was cut short in this coerce() call; results computed across one are not memoized. */
234
+ cuts = 0;
235
+ /**
236
+ * Results of `$ref` targets by (node, value) within one coerce() call: a recursive union whose branches all
237
+ * convert the same children (and all fail) would convert them once per branch, exponentially in the depth.
238
+ */
239
+ memo = void 0;
240
+ constructor(compiler$1, schema) {
241
+ this.c = compiler$1;
242
+ this.schema = schema;
243
+ }
244
+ /** `value` coerced: a copy along the changed paths only, or `value` itself when nothing changes. */
245
+ coerce(value) {
246
+ const base = this.c.r.rootBase;
247
+ const withoutNulls = this.dropOptionalNulls(value, this.schema, base);
248
+ return this.coerceTypes(this.convertOnly(withoutNulls), this.schema, base);
249
+ }
250
+ /** Pass 2 alone, as TypeBox's `Value.Convert` (the TypeBox conformance tests run it). */
251
+ convertOnly(value) {
252
+ try {
253
+ return this.convert(this.schema, this.c.r.rootBase, value);
254
+ } finally {
255
+ this.memo = void 0;
256
+ this.cuts = 0;
257
+ }
258
+ }
259
+ /** `node` converted for `value` at a re-entry point: unchanged when that pair is already being converted. */
260
+ reenter(node, base, value, memoize) {
261
+ const entered = this.entered;
262
+ for (let i = 0; i < entered.length; i += 2) if (entered[i] === node && Object.is(entered[i + 1], value)) {
263
+ this.cuts++;
264
+ return value;
265
+ }
266
+ const memo = memoize ? this.memo?.get(node) : void 0;
267
+ if (memo?.has(value)) return memo.get(value);
268
+ const cuts = this.cuts;
269
+ entered.push(node, value);
270
+ let result;
271
+ try {
272
+ result = this.convert(node, base, value);
273
+ } finally {
274
+ entered.length -= 2;
275
+ }
276
+ if (memoize && this.cuts === cuts) {
277
+ this.memo ??= /* @__PURE__ */ new Map();
278
+ let values = this.memo.get(node);
279
+ if (values === void 0) {
280
+ values = /* @__PURE__ */ new Map();
281
+ this.memo.set(node, values);
282
+ }
283
+ values.set(value, result);
284
+ }
285
+ return result;
286
+ }
287
+ /** Whether `value` passes the schema `node`; undefined when `node` cannot be compiled. */
288
+ passes(node, base, value) {
289
+ try {
290
+ return this.c.check(node, this.baseOf(node, base))(value);
291
+ } catch {
292
+ return;
293
+ }
294
+ }
295
+ baseOf(node, base) {
296
+ return isSchemaObject(node) ? this.c.r.baseOf.get(node) ?? base : base;
297
+ }
298
+ dropOptionalNulls(value, schema, base) {
299
+ if (!isSchemaObject(schema)) return value;
300
+ const b = this.baseOf(schema, base);
301
+ if (Array.isArray(value)) return mapItems(value, (item, i) => {
302
+ const itemSchema = itemSchemaAt(schema, i);
303
+ return itemSchema === void 0 ? item : this.dropOptionalNulls(item, itemSchema, b);
304
+ });
305
+ if (!isPlainObject(value)) return value;
306
+ const properties = isSchemaObject(schema.properties) ? schema.properties : {};
307
+ const patterns = isSchemaObject(schema.patternProperties) ? Object.entries(schema.patternProperties).map(([pattern, item]) => [sharedRegex(pattern), item]) : [];
308
+ const additional = isSchemaObject(schema.additionalProperties) ? schema.additionalProperties : void 0;
309
+ if (patterns.length === 0 && additional === void 0 && !isSchemaObject(schema.properties)) return value;
310
+ const required = new Set(Array.isArray(schema.required) ? schema.required : []);
311
+ let out;
312
+ const set = (key, next) => {
313
+ if (next === (out ?? value)[key]) return;
314
+ out ??= { ...value };
315
+ out[key] = next;
316
+ };
317
+ for (const [key, property] of Object.entries(properties)) {
318
+ if (!Object.hasOwn(value, key)) continue;
319
+ const isRef = isSchemaObject(property) && typeof property.$ref === "string";
320
+ if (value[key] === null && !required.has(key) && !isRef && this.passes(property, b, null) === false) {
321
+ out ??= { ...value };
322
+ delete out[key];
323
+ continue;
324
+ }
325
+ set(key, this.dropOptionalNulls(value[key], property, b));
326
+ }
327
+ if (patterns.length > 0 || additional !== void 0) for (const key of Object.keys(value)) {
328
+ let matched = Object.hasOwn(properties, key);
329
+ for (const [pattern, item] of patterns) {
330
+ if (!pattern.test(key)) continue;
331
+ matched = true;
332
+ set(key, this.dropOptionalNulls((out ?? value)[key], item, b));
333
+ }
334
+ if (!matched && additional !== void 0) set(key, this.dropOptionalNulls(value[key], additional, b));
335
+ }
336
+ return out ?? value;
337
+ }
338
+ convert(node, base, value) {
339
+ if (!isSchemaObject(node)) return value;
340
+ const b = this.baseOf(node, base);
341
+ if (typeof node.$ref === "string") {
342
+ let target;
343
+ try {
344
+ target = this.c.r.resolve(node.$ref, b);
345
+ } catch {
346
+ return value;
347
+ }
348
+ return isSchemaObject(target.node) ? this.reenter(target.node, target.base, value, true) : value;
349
+ }
350
+ return this.convertNode(node, b, value);
351
+ }
352
+ /** One schema node's conversion: its first keyword among `const`, `enum`, the unions, `allOf` and `type`. */
353
+ convertNode(node, b, value) {
354
+ if (Object.hasOwn(node, "const")) return convertLiteral(node.const, value);
355
+ if (Array.isArray(node.enum)) return this.convertEnum(node, node.enum, b, value);
356
+ if (Array.isArray(node.anyOf)) return this.convertUnion(node, node.anyOf, b, value);
357
+ if (Array.isArray(node.oneOf)) return this.convertUnion(node, node.oneOf, b, value);
358
+ if (Array.isArray(node.allOf)) {
359
+ let next = value;
360
+ for (const member of node.allOf) next = this.convert(member, b, next);
361
+ return this.convertMembers(node, b, next);
362
+ }
363
+ switch (node.type) {
364
+ case "string": return orValue(tryString(value), value);
365
+ case "number": return orValue(tryNumber(value), value);
366
+ case "integer": {
367
+ const result = tryNumber(value);
368
+ return result === void 0 ? value : Math.trunc(result.value);
369
+ }
370
+ case "boolean": return orValue(tryBoolean(value), value);
371
+ case "null": return orValue(tryNull(value), value);
372
+ case "array": return this.convertArray(node, b, value);
373
+ case "object": return this.convertObject(node, b, value);
374
+ case void 0:
375
+ if (node.properties !== void 0 || node.patternProperties !== void 0) return this.convertObject(node, b, value);
376
+ if (node.items !== void 0 || node.prefixItems !== void 0) return this.convertArray(node, b, value);
377
+ return value;
378
+ default: return value;
379
+ }
380
+ }
381
+ /** An enum is a union of its values: a member stays, else the first value the input converts to. */
382
+ convertEnum(node, values, base, value) {
383
+ if (values.some((member) => member === value)) return value;
384
+ for (const member of values) {
385
+ const candidate = convertLiteral(member, value);
386
+ if (candidate !== value && this.passes(node, base, candidate) === true) return candidate;
387
+ }
388
+ return value;
389
+ }
390
+ /**
391
+ * A value one branch accepts stays; else the first branch's conversion that the whole union accepts. Branches are
392
+ * converted in order and only until one is accepted, so a later recursive branch is not entered needlessly. A node
393
+ * that also declares members (plain JSON Schema; TypeBox's never do) converts them into each candidate before it is
394
+ * checked, so a branch is not discarded for a sibling property that is converted after it.
395
+ */
396
+ convertUnion(node, branches, base, value) {
397
+ if (branches.some((branch) => this.passes(branch, base, value) === true)) return this.convertMembers(node, base, value);
398
+ for (const branch of branches) {
399
+ const candidate = this.convertMembers(node, base, this.convert(branch, base, value));
400
+ if (this.passes(node, base, candidate) === true) return candidate;
401
+ }
402
+ return this.convertMembers(node, base, value);
403
+ }
404
+ /** The object members of a union or intersection node, when it declares any. */
405
+ convertMembers(node, base, value) {
406
+ return node.properties !== void 0 || node.patternProperties !== void 0 || node.additionalProperties !== void 0 ? this.convertObject(node, base, value) : value;
407
+ }
408
+ convertArray(node, base, value) {
409
+ const prefix = Array.isArray(node.items) ? node.items : Array.isArray(node.prefixItems) ? node.prefixItems : void 0;
410
+ if (prefix !== void 0) {
411
+ if (!Array.isArray(value)) return value;
412
+ const rest = Array.isArray(node.items) ? void 0 : node.items;
413
+ return mapItems(value, (item$1, i) => {
414
+ const schema = i < prefix.length ? prefix[i] : rest;
415
+ return schema === void 0 ? item$1 : this.convert(schema, base, item$1);
416
+ });
417
+ }
418
+ if (Array.isArray(value)) return node.items === void 0 ? value : mapItems(value, (item$1) => this.convert(node.items, base, item$1));
419
+ const item = node.items;
420
+ return [isSchemaObject(item) ? this.reenter(item, base, value, false) : value];
421
+ }
422
+ convertObject(node, base, value) {
423
+ if (!isPlainObject(value)) return value;
424
+ const properties = isSchemaObject(node.properties) ? node.properties : {};
425
+ const patterns = isSchemaObject(node.patternProperties) ? Object.entries(node.patternProperties).map(([pattern, schema]) => [sharedRegex(pattern), schema]) : [];
426
+ const additional = isSchemaObject(node.additionalProperties) ? node.additionalProperties : void 0;
427
+ let out;
428
+ for (const key of Object.keys(value)) {
429
+ if (value[key] === void 0) continue;
430
+ let next = value[key];
431
+ let matched = Object.hasOwn(properties, key);
432
+ if (matched) next = this.convert(properties[key], base, next);
433
+ for (const [pattern, schema] of patterns) {
434
+ if (!pattern.test(key)) continue;
435
+ matched = true;
436
+ next = this.convert(schema, base, next);
437
+ }
438
+ if (!matched && additional !== void 0) next = this.convert(additional, base, next);
439
+ if (next !== value[key]) {
440
+ out ??= { ...value };
441
+ out[key] = next;
442
+ }
443
+ }
444
+ return out ?? value;
445
+ }
446
+ coerceTypes(value, schema, base) {
447
+ if (!isSchemaObject(schema)) return value;
448
+ const b = this.baseOf(schema, base);
449
+ let next = value;
450
+ if (Array.isArray(schema.allOf)) for (const member of schema.allOf) next = this.coerceTypes(next, member, b);
451
+ if (Array.isArray(schema.anyOf)) next = this.coerceUnion(next, schema.anyOf, b);
452
+ if (Array.isArray(schema.oneOf)) next = this.coerceUnion(next, schema.oneOf, b);
453
+ const types = typesOf(schema);
454
+ const matchesUnionMember = types.length > 1 && types.some((type) => matchesType(next, type));
455
+ if (types.length > 0 && !matchesUnionMember) for (const type of types) {
456
+ const candidate = coercePrimitive(next, type);
457
+ if (candidate !== next) {
458
+ next = candidate;
459
+ break;
460
+ }
461
+ }
462
+ if (types.includes("object") && isPlainObject(next)) next = this.coerceProperties(next, schema, b);
463
+ if (types.includes("array") && Array.isArray(next)) next = this.coerceItems(next, schema, b);
464
+ return next;
465
+ }
466
+ coerceUnion(value, branches, base) {
467
+ for (const branch of branches) if (this.passes(branch, base, value) === true) return value;
468
+ for (const branch of branches) {
469
+ const coerced = this.coerceTypes(value, branch, base);
470
+ if (this.passes(branch, base, coerced) === true) return coerced;
471
+ }
472
+ return value;
473
+ }
474
+ coerceProperties(value, schema, base) {
475
+ const properties = isSchemaObject(schema.properties) ? schema.properties : {};
476
+ const patterns = isSchemaObject(schema.patternProperties) ? Object.entries(schema.patternProperties).map(([pattern, item]) => [sharedRegex(pattern), item]) : [];
477
+ const additional = isSchemaObject(schema.additionalProperties) ? schema.additionalProperties : void 0;
478
+ let out;
479
+ const set = (key, next) => {
480
+ if (next === (out ?? value)[key]) return;
481
+ out ??= { ...value };
482
+ out[key] = next;
483
+ };
484
+ for (const [key, property] of Object.entries(properties)) if (key in value) set(key, this.coerceTypes(value[key], property, base));
485
+ for (const key of Object.keys(value)) {
486
+ let matched = Object.hasOwn(properties, key);
487
+ for (const [pattern, item] of patterns) {
488
+ if (!pattern.test(key)) continue;
489
+ matched = true;
490
+ set(key, this.coerceTypes((out ?? value)[key], item, base));
491
+ }
492
+ if (!matched && additional !== void 0) set(key, this.coerceTypes(value[key], additional, base));
493
+ }
494
+ return out ?? value;
495
+ }
496
+ coerceItems(value, schema, base) {
497
+ return mapItems(value, (item, i) => {
498
+ const itemSchema = itemSchemaAt(schema, i);
499
+ return isSchemaObject(itemSchema) ? this.coerceTypes(item, itemSchema, base) : item;
500
+ });
501
+ }
502
+ };
503
+ /**
504
+ * The schema of an array's item at `index`: a tuple's (`prefixItems`, or a draft-7 `items` array) for its prefix,
505
+ * `items` after `prefixItems`, or `items` for every item. Undefined when nothing applies.
506
+ */
507
+ function itemSchemaAt(schema, index) {
508
+ if (Array.isArray(schema.items)) return schema.items[index];
509
+ if (Array.isArray(schema.prefixItems) && index < schema.prefixItems.length) return schema.prefixItems[index];
510
+ return schema.items;
511
+ }
512
+ /** `items` mapped by `map`; the same array when every item maps to itself. */
513
+ function mapItems(items, map) {
514
+ let out;
515
+ for (let i = 0; i < items.length; i++) {
516
+ const next = map(items[i], i);
517
+ if (next === items[i]) continue;
518
+ out ??= items.slice();
519
+ out[i] = next;
520
+ }
521
+ return out ?? items;
522
+ }
523
+ function orValue(result, value) {
524
+ return result === void 0 ? value : result.value;
525
+ }
526
+ /** A literal (`const`, an enum value) taken from a value of another type that converts to exactly it. */
527
+ function convertLiteral(literal, value) {
528
+ if (literal === value) return value;
529
+ const result = typeof literal === "string" ? tryString(value) : typeof literal === "number" ? tryNumber(value) : typeof literal === "boolean" ? tryBoolean(value) : void 0;
530
+ return result !== void 0 && result.value === literal ? result.value : value;
531
+ }
532
+ function tryString(value) {
533
+ if (typeof value === "bigint" || typeof value === "boolean" || isFiniteNumber(value)) return { value: String(value) };
534
+ if (value === null) return { value: "null" };
535
+ if (typeof value === "string") return { value };
536
+ if (value === void 0) return { value: "" };
537
+ }
538
+ const MAX_BIGINT = BigInt(Number.MAX_SAFE_INTEGER);
539
+ const MIN_BIGINT = BigInt(Number.MIN_SAFE_INTEGER);
540
+ function tryNumber(value) {
541
+ if (typeof value === "bigint") return value <= MAX_BIGINT && value >= MIN_BIGINT ? { value: Number(value) } : void 0;
542
+ if (typeof value === "boolean") return { value: value ? 1 : 0 };
543
+ if (isFiniteNumber(value)) return { value };
544
+ if (value === null || value === void 0) return { value: 0 };
545
+ if (typeof value !== "string") return void 0;
546
+ const coerced = +value;
547
+ if (Number.isFinite(coerced)) return { value: coerced };
548
+ const lowercase = value.toLowerCase();
549
+ if (lowercase === "false") return { value: 0 };
550
+ if (lowercase === "true") return { value: 1 };
551
+ const big = bigIntOfString(value);
552
+ return big !== void 0 && big <= MAX_BIGINT && big >= MIN_BIGINT ? { value: Number(big) } : void 0;
553
+ }
554
+ /** TypeBox's TryBigInt of a string: `12n`, `12.5` (truncated) or `12`; true and false are not reached from tryNumber. */
555
+ function bigIntOfString(value) {
556
+ if (/^-?(0|[1-9]\d*)n$/.test(value)) return BigInt(value.slice(0, -1));
557
+ if (/^-?(0|[1-9]\d*)\.\d+$/.test(value)) return BigInt(value.split(".")[0]);
558
+ if (/^-?(0|[1-9]\d*)$/.test(value)) return BigInt(value);
559
+ }
560
+ function tryBoolean(value) {
561
+ if (typeof value === "bigint") return value === 0n ? { value: false } : value === 1n ? { value: true } : void 0;
562
+ if (typeof value === "boolean") return { value };
563
+ if (isFiniteNumber(value)) return value === 0 ? { value: false } : value === 1 ? { value: true } : void 0;
564
+ if (value === null || value === void 0) return { value: false };
565
+ if (typeof value !== "string") return void 0;
566
+ const lowercase = value.toLowerCase();
567
+ if (lowercase === "false" || value === "0") return { value: false };
568
+ if (lowercase === "true" || value === "1") return { value: true };
569
+ }
570
+ function tryNull(value) {
571
+ if (typeof value === "bigint") return value === 0n ? { value: null } : void 0;
572
+ if (typeof value === "boolean") return value === false ? { value: null } : void 0;
573
+ if (isFiniteNumber(value)) return value === 0 ? { value: null } : void 0;
574
+ if (value === null || value === void 0) return { value: null };
575
+ if (typeof value !== "string") return void 0;
576
+ const lowercase = value.toLowerCase();
577
+ return lowercase === "undefined" || lowercase === "null" || value === "" || value === "0" ? { value: null } : void 0;
578
+ }
579
+ function isFiniteNumber(value) {
580
+ return typeof value === "number" && Number.isFinite(value);
581
+ }
582
+ function typesOf(schema) {
583
+ if (typeof schema.type === "string") return [schema.type];
584
+ if (Array.isArray(schema.type)) return schema.type.filter((type) => typeof type === "string");
585
+ return [];
586
+ }
587
+ function matchesType(value, type) {
588
+ switch (type) {
589
+ case "number": return typeof value === "number";
590
+ case "integer": return typeof value === "number" && Number.isInteger(value);
591
+ case "boolean": return typeof value === "boolean";
592
+ case "string": return typeof value === "string";
593
+ case "null": return value === null;
594
+ case "array": return Array.isArray(value);
595
+ case "object": return isPlainObject(value);
596
+ default: return false;
597
+ }
598
+ }
599
+ function coercePrimitive(value, type) {
600
+ switch (type) {
601
+ case "number":
602
+ case "integer":
603
+ if (value === null) return 0;
604
+ if (typeof value === "string" && value.trim() !== "") {
605
+ const parsed = Number(value);
606
+ if (type === "number" ? Number.isFinite(parsed) : Number.isInteger(parsed)) return parsed;
607
+ }
608
+ if (typeof value === "boolean") return value ? 1 : 0;
609
+ return value;
610
+ case "boolean":
611
+ if (value === null) return false;
612
+ if (value === "true" || value === 1) return true;
613
+ if (value === "false" || value === 0) return false;
614
+ return value;
615
+ case "string":
616
+ if (value === null) return "";
617
+ if (typeof value === "number" || typeof value === "boolean") return String(value);
618
+ return value;
619
+ case "null": return value === "" || value === 0 || value === false ? null : value;
620
+ default: return value;
621
+ }
622
+ }
623
+ function isPlainObject(value) {
624
+ return typeof value === "object" && value !== null && !Array.isArray(value);
625
+ }
626
+
627
+ //#endregion
628
+ //#region ../../node_modules/.pnpm/@earendil-works+pi-schema@1.5.0_patch_hash=3a50e14587df64dfdea0adbae45b34d11585bb58009be0694fa2cf4a7986fbdf/node_modules/@earendil-works/pi-schema/dist/checks.js
629
+ const ALWAYS = () => true;
630
+ const NEVER = () => false;
631
+ const IS_STRING = (v) => typeof v === "string";
632
+ const IS_NUMBER = (v) => Number.isFinite(v);
633
+ const IS_INTEGER = (v) => Number.isInteger(v);
634
+ const IS_BOOLEAN = (v) => typeof v === "boolean";
635
+ const IS_NULL = (v) => v === null;
636
+ const IS_ARRAY = (v) => Array.isArray(v);
637
+ const IS_BYTES = (v) => v instanceof Uint8Array;
638
+ const IS_OBJECT = (v) => isObject(v);
639
+ /** Whether `v` is a JSON object: not null, an array or bytes. */
640
+ function isObject(v) {
641
+ return typeof v === "object" && v !== null && !Array.isArray(v) && !(v instanceof Uint8Array);
642
+ }
643
+ /** The check of a `type` name; `bytes` (a Uint8Array) extends JSON Schema for values that never pass through JSON. */
644
+ const TYPE_CHECKS = new Map([
645
+ ["string", IS_STRING],
646
+ ["number", IS_NUMBER],
647
+ ["integer", IS_INTEGER],
648
+ ["boolean", IS_BOOLEAN],
649
+ ["null", IS_NULL],
650
+ ["array", IS_ARRAY],
651
+ ["object", IS_OBJECT],
652
+ ["bytes", IS_BYTES]
653
+ ]);
654
+ /** Leaf checks that object and array loops run inline by code instead of calling them. */
655
+ const LEAF_CODES = new Map([
656
+ [IS_STRING, 1],
657
+ [IS_NUMBER, 2],
658
+ [IS_INTEGER, 3],
659
+ [IS_BOOLEAN, 4],
660
+ [IS_NULL, 5],
661
+ [ALWAYS, 6]
662
+ ]);
663
+ function leafOk(code, x) {
664
+ switch (code) {
665
+ case 1: return typeof x === "string";
666
+ case 2: return Number.isFinite(x);
667
+ case 3: return Number.isInteger(x);
668
+ case 4: return typeof x === "boolean";
669
+ case 5: return x === null;
670
+ default: return true;
671
+ }
672
+ }
673
+ /** Whether a combined object or array check also checks the type: not at all, strictly, or passing other types. */
674
+ const GUARD_NONE = 0;
675
+ const GUARD_STRICT = 1;
676
+ const GUARD_LOOSE = 2;
677
+ /** Flags of a declared property in an object check's entries: its leaf code and two bits. */
678
+ const CODE = 7;
679
+ const REQUIRED = 8;
680
+ const INHERITED = 16;
681
+ /** All of `parts`; two and three parts get closures without a loop. */
682
+ function and(parts) {
683
+ switch (parts.length) {
684
+ case 0: return ALWAYS;
685
+ case 1: return parts[0];
686
+ case 2: {
687
+ const [a, b] = parts;
688
+ return (v) => a(v) && b(v);
689
+ }
690
+ case 3: {
691
+ const [a, b, c] = parts;
692
+ return (v) => a(v) && b(v) && c(v);
693
+ }
694
+ default: return (v) => {
695
+ for (let i = 0; i < parts.length; i++) if (!parts[i](v)) return false;
696
+ return true;
697
+ };
698
+ }
699
+ }
700
+ /** A check whose implementation is set later: the indirection a recursive reference goes through. */
701
+ function indirect(slot) {
702
+ return (v) => slot.check(v);
703
+ }
704
+ /** `check` with `uri` pushed onto the dynamic scope while it runs (only for schemas with `$dynamicRef`). */
705
+ function scopedCheck(scope, uri, check) {
706
+ return (v) => {
707
+ scope.push(uri);
708
+ const ok = check(v);
709
+ scope.pop();
710
+ return ok;
711
+ };
712
+ }
713
+ /** Any of the named types. */
714
+ function typeCheck(types) {
715
+ const checks = types.map((t) => (typeof t === "string" ? TYPE_CHECKS.get(t) : void 0) ?? NEVER);
716
+ if (checks.length === 1) return checks[0];
717
+ return (v) => {
718
+ for (let i = 0; i < checks.length; i++) if (checks[i](v)) return true;
719
+ return false;
720
+ };
721
+ }
722
+ /** A Uint8Array within the length bounds. */
723
+ function bytesCheck(min, max) {
724
+ return (v) => v instanceof Uint8Array && v.length >= min && v.length <= max;
725
+ }
726
+ /** The number of Unicode code points of `s`: JSON Schema string lengths count code points, not UTF-16 units. */
727
+ function codePoints(s) {
728
+ let n = 0;
729
+ for (let i = 0; i < s.length; i++, n++) {
730
+ const c = s.charCodeAt(i);
731
+ if (c >= 55296 && c <= 56319 && i + 1 < s.length) {
732
+ const next = s.charCodeAt(i + 1);
733
+ if (next >= 56320 && next <= 57343) i++;
734
+ }
735
+ }
736
+ return n;
737
+ }
738
+ function lengthOk(s, min, max) {
739
+ const units = s.length;
740
+ if (units < min) return false;
741
+ if (units < 2 * min && codePoints(s) < min) return false;
742
+ return units <= max || codePoints(s) <= max;
743
+ }
744
+ /** The string keywords: length bounds, pattern and format. */
745
+ function stringCheck(strict, min, max, re, format) {
746
+ if (re !== void 0 && min === 0 && max === Number.POSITIVE_INFINITY && format === void 0) return strict ? (v) => typeof v === "string" && re.test(v) : (v) => typeof v !== "string" || re.test(v);
747
+ if (re === void 0 && format === void 0) return strict ? (v) => typeof v === "string" && lengthOk(v, min, max) : (v) => typeof v !== "string" || lengthOk(v, min, max);
748
+ return (v) => {
749
+ if (typeof v !== "string") return !strict;
750
+ return lengthOk(v, min, max) && (re === void 0 || re.test(v)) && (format === void 0 || format(v));
751
+ };
752
+ }
753
+ /** The number keywords. `mode`: 0 passes other types, 1 requires a number, 2 an integer. */
754
+ function numberCheck(mode, min, max, xmin, xmax, multipleOf) {
755
+ return (v) => {
756
+ if (typeof v !== "number") return mode === 0;
757
+ if (mode === 2 && !Number.isInteger(v)) return false;
758
+ return v >= min && v <= max && v > xmin && v < xmax && (multipleOf === void 0 || isMultiple(v, multipleOf));
759
+ };
760
+ }
761
+ /** Whether `v` is a multiple of `d`, exactly for decimals: 0.0075 / 0.0001 is 74.99999999999999 in floating point. */
762
+ function isMultiple(v, d) {
763
+ const q = v / d;
764
+ if (Number.isInteger(q)) return true;
765
+ if (!Number.isFinite(q)) return v % d === 0;
766
+ const [vc, ve] = decimal(v);
767
+ const [dc, de] = decimal(d);
768
+ return ve >= de ? vc * 10n ** BigInt(ve - de) % dc === 0n : vc % (dc * 10n ** BigInt(de - ve)) === 0n;
769
+ }
770
+ function decimal(x) {
771
+ const [mantissa, exponent = "0"] = Math.abs(x).toString().split("e");
772
+ const point = mantissa.indexOf(".");
773
+ const fraction = point < 0 ? 0 : mantissa.length - point - 1;
774
+ return [BigInt(mantissa.replace(".", "")), Number(exponent) - fraction];
775
+ }
776
+ /** `inner` for objects; other values pass unless `strict`. */
777
+ function guardObject(inner, strict) {
778
+ return strict ? (v) => isObject(v) && inner(v) : (v) => !isObject(v) || inner(v);
779
+ }
780
+ /** `inner` for arrays; other values pass unless `strict`. */
781
+ function guardArray(inner, strict) {
782
+ return strict ? (v) => Array.isArray(v) && inner(v) : (v) => !Array.isArray(v) || inner(v);
783
+ }
784
+ /**
785
+ * An object with declared properties: `entries` is `[key, check, flags]` per property. The value's own keys are
786
+ * walked with for...in (whose `o[k]` V8 reads from the enum cache, unlike a load by a name from a list), each found
787
+ * among the declared names; `closed` rejects any other key. A property whose value is `undefined` counts as absent.
788
+ */
789
+ function declaredObject(entries$1, requiredCount, closed, guard) {
790
+ const n = entries$1.length;
791
+ return (v) => {
792
+ if (guard !== GUARD_NONE && !isObject(v)) return guard === GUARD_LOOSE;
793
+ const o = v;
794
+ let required = 0;
795
+ for (const k in o) {
796
+ let i = 0;
797
+ while (i < n && entries$1[i] !== k) i += 3;
798
+ if (i === n) {
799
+ if (closed) return false;
800
+ continue;
801
+ }
802
+ const x = o[k];
803
+ if (x === void 0) continue;
804
+ const f = entries$1[i + 2];
805
+ const c = f & CODE;
806
+ if (c !== 0 ? !leafOk(c, x) : !entries$1[i + 1](x)) return false;
807
+ if (f & REQUIRED) required++;
808
+ }
809
+ return required === requiredCount;
810
+ };
811
+ }
812
+ /** An object with declared properties, required keys not declared, pattern properties and additional properties. */
813
+ function openObject(entries$1, keys, extraRequired, patterns, additional, guard) {
814
+ const known = patterns.length > 0 || additional !== void 0 ? new Set(keys) : void 0;
815
+ return (v) => {
816
+ if (guard !== GUARD_NONE && !isObject(v)) return guard === GUARD_LOOSE;
817
+ const o = v;
818
+ for (let i = 0; i < entries$1.length; i += 3) {
819
+ const k = entries$1[i];
820
+ const x = o[k];
821
+ const f = entries$1[i + 2];
822
+ if (x === void 0 || f & INHERITED && !Object.hasOwn(o, k)) {
823
+ if (f & REQUIRED) return false;
824
+ continue;
825
+ }
826
+ const c = f & CODE;
827
+ if (c !== 0 ? !leafOk(c, x) : !entries$1[i + 1](x)) return false;
828
+ }
829
+ for (let i = 0; i < extraRequired.length; i++) if (!Object.hasOwn(o, extraRequired[i])) return false;
830
+ if (known === void 0) return true;
831
+ for (const k of Object.keys(o)) {
832
+ let matched = known.has(k);
833
+ for (let i = 0; i < patterns.length; i++) if (patterns[i][0].test(k)) {
834
+ matched = true;
835
+ if (!patterns[i][1](o[k])) return false;
836
+ }
837
+ if (!matched && additional !== void 0 && !additional(o[k])) return false;
838
+ }
839
+ return true;
840
+ };
841
+ }
842
+ /** Every property name passes `check` (`v` is an object). */
843
+ function propertyNamesCheck(check) {
844
+ return (v) => {
845
+ for (const k in v) if (!check(k)) return false;
846
+ return true;
847
+ };
848
+ }
849
+ /** `minProperties` and `maxProperties` (`v` is an object). */
850
+ function propertyCountCheck(min, max) {
851
+ return (v) => {
852
+ let n = 0;
853
+ for (const _ in v) n++;
854
+ return n >= min && n <= max;
855
+ };
856
+ }
857
+ /** `dependentRequired` (`v` is an object). */
858
+ function dependentRequiredCheck(entries$1) {
859
+ return (v) => {
860
+ const o = v;
861
+ for (const [k, list] of entries$1) if (Object.hasOwn(o, k)) {
862
+ for (const r of list) if (!Object.hasOwn(o, r)) return false;
863
+ }
864
+ return true;
865
+ };
866
+ }
867
+ /** `dependentSchemas` (`v` is an object). */
868
+ function dependentSchemasCheck(entries$1) {
869
+ return (v) => {
870
+ for (const [k, check] of entries$1) if (Object.hasOwn(v, k) && !check(v)) return false;
871
+ return true;
872
+ };
873
+ }
874
+ /** The common array: guard, length bounds, prefix items and the items after them, in one closure. */
875
+ function listCheck(guard, min, max, prefix, rest) {
876
+ const n = prefix.length;
877
+ const code = rest === void 0 ? 0 : LEAF_CODES.get(rest) ?? 0;
878
+ return (v) => {
879
+ if (!Array.isArray(v)) return guard === GUARD_LOOSE;
880
+ const length = v.length;
881
+ if (length < min || length > max) return false;
882
+ const m = length < n ? length : n;
883
+ for (let i = 0; i < m; i++) if (!prefix[i](v[i])) return false;
884
+ if (rest === void 0) return true;
885
+ if (code !== 0) {
886
+ for (let i = n; i < length; i++) if (!leafOk(code, v[i])) return false;
887
+ return true;
888
+ }
889
+ for (let i = n; i < length; i++) if (!rest(v[i])) return false;
890
+ return true;
891
+ };
892
+ }
893
+ /** Prefix items and the items after them (`v` is an array). */
894
+ function itemsCheck(prefix, rest) {
895
+ return listCheck(GUARD_NONE, 0, Number.POSITIVE_INFINITY, prefix, rest);
896
+ }
897
+ /** `minItems` and `maxItems` (`v` is an array). */
898
+ function lengthCheck(min, max) {
899
+ return (v) => v.length >= min && v.length <= max;
900
+ }
901
+ /** `contains` with its bounds (`v` is an array). */
902
+ function containsCheck(check, min, max) {
903
+ return (v) => {
904
+ const list = v;
905
+ let n = 0;
906
+ for (let i = 0; i < list.length; i++) if (check(list[i]) && ++n > max) return false;
907
+ return n >= min;
908
+ };
909
+ }
910
+ /** `uniqueItems` (`v` is an array). */
911
+ function uniqueCheck(v) {
912
+ const list = v;
913
+ for (let i = 1; i < list.length; i++) for (let j = 0; j < i; j++) if (deepEqual(list[i], list[j])) return false;
914
+ return true;
915
+ }
916
+ /** `enum`: up to 8 primitives by a scan, more by a Set, objects and arrays by deep equality. */
917
+ function enumCheck(values) {
918
+ const primitives = values.filter((x) => typeof x !== "object" || x === null);
919
+ if (primitives.length === values.length && primitives.length <= 8) return (v) => {
920
+ for (let i = 0; i < primitives.length; i++) if (primitives[i] === v) return true;
921
+ return false;
922
+ };
923
+ const set = new Set(primitives);
924
+ const objects = values.filter((x) => typeof x === "object" && x !== null);
925
+ return (v) => set.has(v) || typeof v === "object" && objects.some((o) => deepEqual(v, o));
926
+ }
927
+ /** `const`. */
928
+ function constCheck(value) {
929
+ if (typeof value !== "object" || value === null) return (v) => v === value;
930
+ return (v) => deepEqual(v, value);
931
+ }
932
+ /** `anyOf`. */
933
+ function anyCheck(checks) {
934
+ return (v) => {
935
+ for (let i = 0; i < checks.length; i++) if (checks[i](v)) return true;
936
+ return false;
937
+ };
938
+ }
939
+ /** `oneOf`. */
940
+ function oneCheck(checks) {
941
+ return (v) => {
942
+ let n = 0;
943
+ for (let i = 0; i < checks.length; i++) if (checks[i](v) && ++n > 1) return false;
944
+ return n === 1;
945
+ };
946
+ }
947
+ /** `not`. */
948
+ function notCheck(check) {
949
+ return (v) => !check(v);
950
+ }
951
+ /** `if`, `then` and `else`. */
952
+ function ifCheck(cond, then, otherwise) {
953
+ return (v) => cond(v) ? then(v) : otherwise(v);
954
+ }
955
+ /** A union of objects tagged by a const on `key`: the tag selects the one branch that can match. */
956
+ function taggedCheck(key, tags, checks) {
957
+ return (v) => {
958
+ if (!isObject(v)) return false;
959
+ const tag = v[key];
960
+ for (let i = 0; i < tags.length; i++) if (tags[i] === tag) return checks[i](v);
961
+ return false;
962
+ };
963
+ }
964
+ /** JSON equality: same primitives, arrays with equal items in order, objects with the same keys and equal values. */
965
+ function deepEqual(a, b) {
966
+ if (a === b) return true;
967
+ if (typeof a !== "object" || typeof b !== "object" || a === null || b === null) return false;
968
+ const array = Array.isArray(a);
969
+ if (array !== Array.isArray(b)) return false;
970
+ if (array) {
971
+ const x$1 = a;
972
+ const y$1 = b;
973
+ if (x$1.length !== y$1.length) return false;
974
+ for (let i = 0; i < x$1.length; i++) if (!deepEqual(x$1[i], y$1[i])) return false;
975
+ return true;
976
+ }
977
+ const x = a;
978
+ const y = b;
979
+ const keys = Object.keys(x);
980
+ if (keys.length !== Object.keys(y).length) return false;
981
+ for (const k of keys) if (!Object.hasOwn(y, k) || !deepEqual(x[k], y[k])) return false;
982
+ return true;
983
+ }
984
+
985
+ //#endregion
986
+ //#region ../../node_modules/.pnpm/@earendil-works+pi-schema@1.5.0_patch_hash=3a50e14587df64dfdea0adbae45b34d11585bb58009be0694fa2cf4a7986fbdf/node_modules/@earendil-works/pi-schema/dist/annotations.js
987
+ /** Empty annotations. */
988
+ function newAnnotations() {
989
+ return {
990
+ props: null,
991
+ allProps: false,
992
+ items: 0,
993
+ allItems: false,
994
+ indexes: null
995
+ };
996
+ }
997
+ function merge(a, b) {
998
+ if (b.props !== null) for (const k of b.props) addProp(a, k);
999
+ a.allProps ||= b.allProps;
1000
+ if (b.items > a.items) a.items = b.items;
1001
+ a.allItems ||= b.allItems;
1002
+ if (b.indexes !== null) for (const i of b.indexes) addIndex(a, i);
1003
+ }
1004
+ function addProp(a, key) {
1005
+ if (a.props === null) a.props = /* @__PURE__ */ new Set();
1006
+ a.props.add(key);
1007
+ }
1008
+ function addIndex(a, index) {
1009
+ if (a.indexes === null) a.indexes = /* @__PURE__ */ new Set();
1010
+ a.indexes.add(index);
1011
+ }
1012
+ const ANNOTATING_TRUE = () => true;
1013
+ const ANNOTATING_FALSE = () => false;
1014
+ /** The indirection a recursive reference goes through. */
1015
+ function indirectAnnotating(slot) {
1016
+ return (v, a) => slot.check(v, a);
1017
+ }
1018
+ /** A plain check in annotating position: it evaluates nothing that unevaluated* sees. */
1019
+ function ignoreAnnotations(check) {
1020
+ return (v) => check(v);
1021
+ }
1022
+ /** An annotating check run as a plain check, with fresh annotations. */
1023
+ function withFreshAnnotations(check) {
1024
+ return (v) => check(v, newAnnotations());
1025
+ }
1026
+ /** `check` with `uri` pushed onto the dynamic scope while it runs. */
1027
+ function scopedAnnotating(scope, uri, check) {
1028
+ return (v, a) => {
1029
+ scope.push(uri);
1030
+ const ok = check(v, a);
1031
+ scope.pop();
1032
+ return ok;
1033
+ };
1034
+ }
1035
+ /** unevaluated* sees only the annotations of its own schema, never those of its siblings in the parent. */
1036
+ function isolateAnnotations(check) {
1037
+ return (v, a) => {
1038
+ const b = newAnnotations();
1039
+ if (!check(v, b)) return false;
1040
+ merge(a, b);
1041
+ return true;
1042
+ };
1043
+ }
1044
+ /** The non-annotating keywords, then each annotating part in order. */
1045
+ function annotateAll(plain, parts) {
1046
+ return (v, a) => {
1047
+ if (!plain(v)) return false;
1048
+ for (let i = 0; i < parts.length; i++) if (!parts[i](v, a)) return false;
1049
+ return true;
1050
+ };
1051
+ }
1052
+ /** `properties`, `patternProperties` and `additionalProperties`. */
1053
+ function annotateObject(props, patterns, additional) {
1054
+ const declared = new Set(props.map(([k]) => k));
1055
+ return (v, a) => {
1056
+ if (!isObject(v)) return true;
1057
+ const seen = [];
1058
+ for (const [k, check] of props) {
1059
+ if (!Object.hasOwn(v, k)) continue;
1060
+ if (!check(v[k])) return false;
1061
+ seen.push(k);
1062
+ }
1063
+ for (const k of Object.keys(v)) {
1064
+ let matched = declared.has(k);
1065
+ for (const [re, check] of patterns) if (re.test(k)) {
1066
+ if (!check(v[k])) return false;
1067
+ matched = true;
1068
+ seen.push(k);
1069
+ }
1070
+ if (!matched && additional !== void 0) {
1071
+ if (!additional(v[k])) return false;
1072
+ seen.push(k);
1073
+ }
1074
+ }
1075
+ for (const k of seen) addProp(a, k);
1076
+ return true;
1077
+ };
1078
+ }
1079
+ /** `prefixItems`/`items`/`additionalItems` and `contains` with its bounds. */
1080
+ function annotateArray(prefix, rest, contains, minContains, maxContains) {
1081
+ return (v, a) => {
1082
+ if (!Array.isArray(v)) return true;
1083
+ const m = Math.min(v.length, prefix.length);
1084
+ for (let i = 0; i < m; i++) if (!prefix[i](v[i])) return false;
1085
+ if (rest !== void 0) {
1086
+ for (let i = prefix.length; i < v.length; i++) if (!rest(v[i])) return false;
1087
+ a.allItems = true;
1088
+ }
1089
+ if (m > a.items) a.items = m;
1090
+ if (contains !== void 0) {
1091
+ let n = 0;
1092
+ for (let i = 0; i < v.length; i++) if (contains(v[i])) {
1093
+ n++;
1094
+ addIndex(a, i);
1095
+ }
1096
+ if (n < minContains || n > maxContains) return false;
1097
+ }
1098
+ return true;
1099
+ };
1100
+ }
1101
+ /** `anyOf` (or `oneOf` when `exactlyOne`): every passing branch contributes its annotations. */
1102
+ function annotateAny(branches, exactlyOne) {
1103
+ return (v, a) => {
1104
+ let n = 0;
1105
+ for (const branch of branches) {
1106
+ const b = newAnnotations();
1107
+ if (branch(v, b)) {
1108
+ n++;
1109
+ merge(a, b);
1110
+ }
1111
+ }
1112
+ return exactlyOne ? n === 1 : n > 0;
1113
+ };
1114
+ }
1115
+ /** `if`, `then` and `else`: a passing `if` contributes its annotations even without `then`. */
1116
+ function annotateIf(cond, then, otherwise) {
1117
+ return (v, a) => {
1118
+ const b = newAnnotations();
1119
+ if (cond(v, b)) {
1120
+ merge(a, b);
1121
+ return then === void 0 || then(v, a);
1122
+ }
1123
+ return otherwise === void 0 || otherwise(v, a);
1124
+ };
1125
+ }
1126
+ /** One `dependentSchemas` entry. */
1127
+ function annotateDependent(key, check) {
1128
+ return (v, a) => !isObject(v) || !Object.hasOwn(v, key) || check(v, a);
1129
+ }
1130
+ /** `unevaluatedProperties`: every property no other keyword evaluated passes `check`. */
1131
+ function unevaluatedProperties(check) {
1132
+ return (v, a) => {
1133
+ if (!isObject(v) || a.allProps) return true;
1134
+ for (const k of Object.keys(v)) if (!(a.props?.has(k) ?? false) && !check(v[k])) return false;
1135
+ a.allProps = true;
1136
+ return true;
1137
+ };
1138
+ }
1139
+ /** `unevaluatedItems`: every item no other keyword evaluated passes `check`. */
1140
+ function unevaluatedItems(check) {
1141
+ return (v, a) => {
1142
+ if (!Array.isArray(v) || a.allItems) return true;
1143
+ for (let i = a.items; i < v.length; i++) if (!(a.indexes?.has(i) ?? false) && !check(v[i])) return false;
1144
+ a.allItems = true;
1145
+ return true;
1146
+ };
1147
+ }
1148
+
1149
+ //#endregion
1150
+ //#region ../../node_modules/.pnpm/@earendil-works+pi-schema@1.5.0_patch_hash=3a50e14587df64dfdea0adbae45b34d11585bb58009be0694fa2cf4a7986fbdf/node_modules/@earendil-works/pi-schema/dist/compiler.js
1151
+ /** Thrown when a compile without dynamic scope tracking meets a bookended `$dynamicRef`: compile again with it. */
1152
+ const RESTART = Symbol("restart");
1153
+ /** One compile of a schema. Its caches and indexes are garbage once the root check is built. */
1154
+ var Compiler = class {
1155
+ r;
1156
+ draft;
1157
+ formats;
1158
+ /** Whether checks track the dynamic scope (the schema has a bookended `$dynamicRef`). */
1159
+ dynamic;
1160
+ schema;
1161
+ scope;
1162
+ cache = /* @__PURE__ */ new Map();
1163
+ annotatingCache = /* @__PURE__ */ new Map();
1164
+ constructor(schema, options, dynamic) {
1165
+ this.schema = schema;
1166
+ this.r = new Resolver(schema, options);
1167
+ this.draft = this.r.draft;
1168
+ this.formats = options.formats;
1169
+ this.dynamic = dynamic;
1170
+ this.scope = [];
1171
+ }
1172
+ /** The check of the root schema. */
1173
+ root() {
1174
+ return this.check(this.schema, this.r.rootBase);
1175
+ }
1176
+ /** The check of a schema (cached by schema object; a recursive reference goes through an indirection). */
1177
+ check(node, base) {
1178
+ if (node === true) return ALWAYS;
1179
+ if (node === false) return NEVER;
1180
+ if (!isSchemaObject(node)) throw new Error(`A schema must be an object or a boolean, got ${JSON.stringify(node)}`);
1181
+ const cached = this.cache.get(node);
1182
+ if (cached !== void 0) return cached;
1183
+ const bare = this.bareType(node);
1184
+ if (bare !== void 0) return bare;
1185
+ const slot = { check: void 0 };
1186
+ this.cache.set(node, indirect(slot));
1187
+ const check = this.build(node, this.r.baseFor(node, base));
1188
+ slot.check = check;
1189
+ this.cache.set(node, check);
1190
+ return check;
1191
+ }
1192
+ build(node, base) {
1193
+ if (this.draft === "7" && typeof node.$ref === "string") return this.ref(node.$ref, base);
1194
+ if (this.draft !== "7" && (node.unevaluatedProperties !== void 0 || node.unevaluatedItems !== void 0)) return withFreshAnnotations(this.annotating(node, base));
1195
+ const check = this.plain(node, base);
1196
+ return this.dynamic && this.r.isResource(node, base) ? scopedCheck(this.scope, base, check) : check;
1197
+ }
1198
+ /**
1199
+ * The module-level check of a schema that is only a `type` (with annotations), `ALWAYS` for one with no assertion
1200
+ * at all; undefined for every other schema. These are the most common subschemas and cost nothing to share.
1201
+ */
1202
+ bareType(node) {
1203
+ let type;
1204
+ for (const k in node) if (k === "type") type = node.type;
1205
+ else if (!NEUTRAL_KEYWORDS.has(k)) return void 0;
1206
+ if (type === void 0) return ALWAYS;
1207
+ return typeof type === "string" ? TYPE_CHECKS.get(type) : void 0;
1208
+ }
1209
+ /** Every keyword of `node`, not tracking annotations. */
1210
+ plain(node, base) {
1211
+ const parts = [];
1212
+ const types = node.type === void 0 ? void 0 : Array.isArray(node.type) ? node.type : [node.type];
1213
+ const single = types?.length === 1 ? types[0] : void 0;
1214
+ let typeInGroup = false;
1215
+ if (single === "bytes") {
1216
+ parts.push(bytesCheck(number(node.minLength) ?? 0, number(node.maxLength) ?? Number.POSITIVE_INFINITY));
1217
+ typeInGroup = true;
1218
+ } else {
1219
+ const string = this.stringGroup(node, single === "string");
1220
+ if (string !== void 0) parts.push(string);
1221
+ const numeric = single === "number" || single === "integer";
1222
+ const number$1 = this.numberGroup(node, single === "number" ? 1 : single === "integer" ? 2 : 0);
1223
+ if (number$1 !== void 0) parts.push(number$1);
1224
+ const object = this.objectGroup(node, base, single === "object");
1225
+ if (object !== void 0) parts.push(object);
1226
+ const array = this.arrayGroup(node, base, single === "array");
1227
+ if (array !== void 0) parts.push(array);
1228
+ typeInGroup = single === "string" && string !== void 0 || numeric && number$1 !== void 0 || single === "object" && object !== void 0 || single === "array" && array !== void 0;
1229
+ }
1230
+ if (types !== void 0 && !typeInGroup) parts.unshift(typeCheck(types));
1231
+ this.inPlace(node, base, parts);
1232
+ return and(parts);
1233
+ }
1234
+ inPlace(node, base, parts) {
1235
+ if (Array.isArray(node.enum)) parts.push(enumCheck(node.enum));
1236
+ if (Object.hasOwn(node, "const")) parts.push(constCheck(node.const));
1237
+ if (Array.isArray(node.allOf)) parts.push(and(node.allOf.map((s) => this.check(s, base))));
1238
+ if (Array.isArray(node.anyOf)) parts.push(this.union(node.anyOf, base, false));
1239
+ if (Array.isArray(node.oneOf)) parts.push(this.union(node.oneOf, base, true));
1240
+ if (node.not !== void 0) parts.push(notCheck(this.check(node.not, base)));
1241
+ if (node.if !== void 0 && (node.then !== void 0 || node.else !== void 0)) {
1242
+ const then = node.then === void 0 ? ALWAYS : this.check(node.then, base);
1243
+ const otherwise = node.else === void 0 ? ALWAYS : this.check(node.else, base);
1244
+ parts.push(ifCheck(this.check(node.if, base), then, otherwise));
1245
+ }
1246
+ if (typeof node.$ref === "string") parts.push(this.ref(node.$ref, base));
1247
+ if (this.draft !== "7" && typeof node.$dynamicRef === "string") parts.push(this.dynamicRef(node.$dynamicRef, base));
1248
+ }
1249
+ union(branches, base, exactlyOne) {
1250
+ const checks = () => branches.map((s) => this.check(s, base));
1251
+ return constUnion(branches, exactlyOne) ?? this.tagged(branches, base) ?? (exactlyOne ? oneCheck(checks()) : anyCheck(checks()));
1252
+ }
1253
+ ref(ref, base) {
1254
+ const target = this.r.resolve(ref, base);
1255
+ const check = this.check(target.node, target.base);
1256
+ return this.dynamic && target.base !== base ? scopedCheck(this.scope, target.base, check) : check;
1257
+ }
1258
+ dynamicRef(ref, base) {
1259
+ const resolved = this.bookended(ref, base);
1260
+ if (resolved === void 0) return this.ref(ref, base);
1261
+ const { initial, name } = resolved;
1262
+ const fallback = this.check(initial.node, initial.base);
1263
+ const lookup = this.dynamicLookup(name, (node, b) => this.check(node, b));
1264
+ const scope = this.scope;
1265
+ return (v) => {
1266
+ for (let i = 0; i < scope.length; i++) {
1267
+ const check = lookup(scope[i]);
1268
+ if (check !== null) return check(v);
1269
+ }
1270
+ return fallback(v);
1271
+ };
1272
+ }
1273
+ /** The initial target and anchor name of a `$dynamicRef` that resolves dynamically, or undefined for a plain ref. */
1274
+ bookended(ref, base) {
1275
+ const initial = this.r.resolve(ref, base);
1276
+ const uri = resolveUri(ref, base);
1277
+ const name = uri.slice(documentOf(uri).length + 1);
1278
+ const anchored = isSchemaObject(initial.node) && initial.node.$dynamicAnchor === name;
1279
+ if (name === "" || name.startsWith("/") || !anchored) return void 0;
1280
+ if (!this.dynamic) throw RESTART;
1281
+ return {
1282
+ initial,
1283
+ name
1284
+ };
1285
+ }
1286
+ dynamicLookup(name, compile$1) {
1287
+ const found = /* @__PURE__ */ new Map();
1288
+ return (uri) => {
1289
+ const key = `${uri}#${name}`;
1290
+ let check = found.get(key);
1291
+ if (check === void 0) {
1292
+ const target = this.r.dynamicAnchors.get(key);
1293
+ check = target === void 0 ? null : compile$1(target, this.r.baseOf.get(target) ?? uri);
1294
+ found.set(key, check);
1295
+ }
1296
+ return check;
1297
+ };
1298
+ }
1299
+ /** anyOf/oneOf whose branches are all objects with a distinct required const on one key: the tag picks the branch. */
1300
+ tagged(branches, base) {
1301
+ if (branches.length < 2) return void 0;
1302
+ const resolved = [];
1303
+ for (const branch of branches) {
1304
+ if (!isSchemaObject(branch)) return void 0;
1305
+ const ref = typeof branch.$ref === "string" && Object.keys(branch).length === 1 ? branch.$ref : void 0;
1306
+ const node = ref === void 0 ? branch : this.r.resolve(ref, this.r.baseFor(branch, base)).node;
1307
+ if (!isSchemaObject(node)) return void 0;
1308
+ resolved.push(node);
1309
+ }
1310
+ const first = resolved[0].properties;
1311
+ if (!isSchemaObject(first)) return void 0;
1312
+ for (const key of Object.keys(first)) {
1313
+ const tags = resolved.map((s) => tagOf(s, key));
1314
+ if (tags.some((t) => t === void 0) || new Set(tags).size !== tags.length) continue;
1315
+ return taggedCheck(key, tags, branches.map((s) => this.check(s, base)));
1316
+ }
1317
+ }
1318
+ stringGroup(node, strict) {
1319
+ const min = number(node.minLength) ?? 0;
1320
+ const max = number(node.maxLength) ?? Number.POSITIVE_INFINITY;
1321
+ const re = typeof node.pattern === "string" ? sharedRegex(node.pattern) : void 0;
1322
+ const format = this.formats !== void 0 && typeof node.format === "string" && Object.hasOwn(this.formats, node.format) ? this.formats[node.format] : void 0;
1323
+ if (min === 0 && max === Number.POSITIVE_INFINITY && re === void 0 && format === void 0) return void 0;
1324
+ return stringCheck(strict, min, max, re, format);
1325
+ }
1326
+ numberGroup(node, mode) {
1327
+ const min = number(node.minimum);
1328
+ const max = number(node.maximum);
1329
+ const xmin = number(node.exclusiveMinimum);
1330
+ const xmax = number(node.exclusiveMaximum);
1331
+ const multipleOf = number(node.multipleOf);
1332
+ if ([
1333
+ min,
1334
+ max,
1335
+ xmin,
1336
+ xmax,
1337
+ multipleOf
1338
+ ].every((x) => x === void 0)) return void 0;
1339
+ const inf = Number.POSITIVE_INFINITY;
1340
+ return numberCheck(mode, min ?? -inf, max ?? inf, xmin ?? -inf, xmax ?? inf, multipleOf);
1341
+ }
1342
+ objectGroup(node, base, strict) {
1343
+ const onlyCore = OBJECT_EXTRAS.every((k) => node[k] === void 0);
1344
+ const core = this.objectCore(node, base, onlyCore ? strict ? GUARD_STRICT : GUARD_LOOSE : GUARD_NONE);
1345
+ if (core !== void 0 && onlyCore) return core;
1346
+ const parts = core === void 0 ? [] : [core];
1347
+ if (node.propertyNames !== void 0) parts.push(propertyNamesCheck(this.check(node.propertyNames, base)));
1348
+ const minProperties = number(node.minProperties);
1349
+ const maxProperties = number(node.maxProperties);
1350
+ if (minProperties !== void 0 || maxProperties !== void 0) parts.push(propertyCountCheck(minProperties ?? 0, maxProperties ?? Number.POSITIVE_INFINITY));
1351
+ const dependentRequired = [];
1352
+ const dependentSchemas = [];
1353
+ if (this.draft !== "7") {
1354
+ for (const [k, list] of entries(node.dependentRequired)) if (Array.isArray(list)) dependentRequired.push([k, list]);
1355
+ for (const [k, s] of entries(node.dependentSchemas)) dependentSchemas.push([k, this.check(s, base)]);
1356
+ }
1357
+ for (const [k, d] of entries(node.dependencies)) if (Array.isArray(d)) dependentRequired.push([k, d]);
1358
+ else dependentSchemas.push([k, this.check(d, base)]);
1359
+ if (dependentRequired.length > 0) parts.push(dependentRequiredCheck(dependentRequired));
1360
+ if (dependentSchemas.length > 0) parts.push(dependentSchemasCheck(dependentSchemas));
1361
+ if (parts.length === 0) return strict ? IS_OBJECT : void 0;
1362
+ return guardObject(and(parts), strict);
1363
+ }
1364
+ objectCore(node, base, guard) {
1365
+ const properties = isSchemaObject(node.properties) ? node.properties : {};
1366
+ const required = Array.isArray(node.required) ? node.required.filter((k) => typeof k === "string") : [];
1367
+ const patterns = isSchemaObject(node.patternProperties) ? node.patternProperties : {};
1368
+ const additional = node.additionalProperties;
1369
+ const keys = Object.keys(properties);
1370
+ const patternKeys = Object.keys(patterns);
1371
+ if (keys.length + required.length + patternKeys.length === 0 && (additional === void 0 || additional === true)) return;
1372
+ const entries$1 = [];
1373
+ for (const k of keys) {
1374
+ const check = this.check(properties[k], base);
1375
+ const flags = (LEAF_CODES.get(check) ?? 0) | (required.includes(k) ? REQUIRED : 0) | (k in Object.prototype ? INHERITED : 0);
1376
+ entries$1.push(k, check, flags);
1377
+ }
1378
+ const extraRequired = required.filter((k) => !Object.hasOwn(properties, k));
1379
+ const pats = patternKeys.map((p) => [sharedRegex(p), this.check(patterns[p], base)]);
1380
+ const extra = additional === void 0 || additional === true ? void 0 : this.check(additional, base);
1381
+ if (pats.length === 0 && extraRequired.length === 0 && (extra === void 0 || additional === false)) {
1382
+ const requiredCount = keys.filter((k) => required.includes(k)).length;
1383
+ return declaredObject(entries$1, requiredCount, additional === false, guard);
1384
+ }
1385
+ return openObject(entries$1, keys, extraRequired, pats, extra, guard);
1386
+ }
1387
+ arrayGroup(node, base, strict) {
1388
+ let prefix = [];
1389
+ let rest;
1390
+ if (Array.isArray(node.items)) {
1391
+ prefix = node.items;
1392
+ rest = node.additionalItems;
1393
+ } else {
1394
+ if (this.draft !== "7" && Array.isArray(node.prefixItems)) prefix = node.prefixItems;
1395
+ rest = node.items;
1396
+ }
1397
+ const prefixChecks = prefix.map((s) => this.check(s, base));
1398
+ const restCheck = rest === void 0 || rest === true ? void 0 : this.check(rest, base);
1399
+ const minItems = number(node.minItems);
1400
+ const maxItems = number(node.maxItems);
1401
+ if (node.contains === void 0 && node.uniqueItems !== true && (prefixChecks.length > 0 || restCheck !== void 0)) return listCheck(strict ? GUARD_STRICT : GUARD_LOOSE, minItems ?? 0, maxItems ?? Number.POSITIVE_INFINITY, prefixChecks, restCheck);
1402
+ const parts = [];
1403
+ if (prefixChecks.length > 0 || restCheck !== void 0) parts.push(itemsCheck(prefixChecks, restCheck));
1404
+ if (minItems !== void 0 || maxItems !== void 0) parts.push(lengthCheck(minItems ?? 0, maxItems ?? Number.POSITIVE_INFINITY));
1405
+ if (node.contains !== void 0) {
1406
+ const min = this.draft === "7" ? 1 : number(node.minContains) ?? 1;
1407
+ const max = this.draft === "7" ? Number.POSITIVE_INFINITY : number(node.maxContains) ?? Number.POSITIVE_INFINITY;
1408
+ parts.push(containsCheck(this.check(node.contains, base), min, max));
1409
+ }
1410
+ if (node.uniqueItems === true) parts.push(uniqueCheck);
1411
+ if (parts.length === 0) return strict ? IS_ARRAY : void 0;
1412
+ return guardArray(and(parts), strict);
1413
+ }
1414
+ /** The annotating check of a schema evaluated in place (only below `unevaluatedProperties`/`unevaluatedItems`). */
1415
+ annotating(node, base) {
1416
+ if (node === true) return ANNOTATING_TRUE;
1417
+ if (node === false) return ANNOTATING_FALSE;
1418
+ if (!isSchemaObject(node)) throw new Error(`A schema must be an object or a boolean, got ${JSON.stringify(node)}`);
1419
+ const cached = this.annotatingCache.get(node);
1420
+ if (cached !== void 0) return cached;
1421
+ const slot = { check: void 0 };
1422
+ this.annotatingCache.set(node, indirectAnnotating(slot));
1423
+ const check = this.buildAnnotating(node, this.r.baseFor(node, base));
1424
+ slot.check = check;
1425
+ this.annotatingCache.set(node, check);
1426
+ return check;
1427
+ }
1428
+ buildAnnotating(node, base) {
1429
+ const rest = {};
1430
+ let annotates = false;
1431
+ for (const k of Object.keys(node)) if (ANNOTATING.has(k)) annotates = true;
1432
+ else rest[k] = node[k];
1433
+ const plain = this.plain(rest, base);
1434
+ const parts = [];
1435
+ if (annotates) this.annotatingParts(node, base, parts);
1436
+ const all = parts.length === 0 ? ignoreAnnotations(plain) : annotateAll(plain, parts);
1437
+ const own = node.unevaluatedProperties !== void 0 || node.unevaluatedItems !== void 0 ? isolateAnnotations(all) : all;
1438
+ return this.dynamic && this.r.isResource(node, base) ? scopedAnnotating(this.scope, base, own) : own;
1439
+ }
1440
+ annotatingParts(node, base, parts) {
1441
+ if (node.properties !== void 0 || node.patternProperties !== void 0 || node.additionalProperties !== void 0) {
1442
+ const props = entries(node.properties).map(([k, s]) => [k, this.check(s, base)]);
1443
+ const pats = entries(node.patternProperties).map(([p, s]) => [sharedRegex(p), this.check(s, base)]);
1444
+ const extra = node.additionalProperties === void 0 ? void 0 : this.check(node.additionalProperties, base);
1445
+ parts.push(annotateObject(props, pats, extra));
1446
+ }
1447
+ if (node.prefixItems !== void 0 || node.items !== void 0 || node.contains !== void 0) {
1448
+ const prefix = Array.isArray(node.prefixItems) ? node.prefixItems : Array.isArray(node.items) ? node.items : [];
1449
+ const rest = Array.isArray(node.items) ? node.additionalItems : node.items;
1450
+ parts.push(annotateArray(prefix.map((s) => this.check(s, base)), rest === void 0 ? void 0 : this.check(rest, base), node.contains === void 0 ? void 0 : this.check(node.contains, base), number(node.minContains) ?? 1, number(node.maxContains) ?? Number.POSITIVE_INFINITY));
1451
+ }
1452
+ if (Array.isArray(node.allOf)) for (const s of node.allOf) parts.push(this.annotating(s, base));
1453
+ if (Array.isArray(node.anyOf)) parts.push(annotateAny(node.anyOf.map((s) => this.annotating(s, base)), false));
1454
+ if (Array.isArray(node.oneOf)) parts.push(annotateAny(node.oneOf.map((s) => this.annotating(s, base)), true));
1455
+ if (node.if !== void 0) {
1456
+ const then = node.then === void 0 ? void 0 : this.annotating(node.then, base);
1457
+ const otherwise = node.else === void 0 ? void 0 : this.annotating(node.else, base);
1458
+ parts.push(annotateIf(this.annotating(node.if, base), then, otherwise));
1459
+ }
1460
+ if (typeof node.$ref === "string") parts.push(this.annotatingRef(node.$ref, base));
1461
+ if (typeof node.$dynamicRef === "string") parts.push(this.annotatingDynamicRef(node.$dynamicRef, base));
1462
+ for (const [k, s] of entries(node.dependentSchemas)) parts.push(annotateDependent(k, this.annotating(s, base)));
1463
+ if (node.unevaluatedProperties !== void 0) parts.push(unevaluatedProperties(this.check(node.unevaluatedProperties, base)));
1464
+ if (node.unevaluatedItems !== void 0) parts.push(unevaluatedItems(this.check(node.unevaluatedItems, base)));
1465
+ }
1466
+ annotatingRef(ref, base) {
1467
+ const target = this.r.resolve(ref, base);
1468
+ const check = this.annotating(target.node, target.base);
1469
+ return this.dynamic && target.base !== base ? scopedAnnotating(this.scope, target.base, check) : check;
1470
+ }
1471
+ annotatingDynamicRef(ref, base) {
1472
+ const resolved = this.bookended(ref, base);
1473
+ if (resolved === void 0) return this.annotatingRef(ref, base);
1474
+ const { initial, name } = resolved;
1475
+ const fallback = this.annotating(initial.node, initial.base);
1476
+ const lookup = this.dynamicLookup(name, (node, b) => this.annotating(node, b));
1477
+ const scope = this.scope;
1478
+ return (v, a) => {
1479
+ for (let i = 0; i < scope.length; i++) {
1480
+ const check = lookup(scope[i]);
1481
+ if (check !== null) return check(v, a);
1482
+ }
1483
+ return fallback(v, a);
1484
+ };
1485
+ }
1486
+ };
1487
+ /** Keywords that never affect a check. */
1488
+ const NEUTRAL_KEYWORDS = new Set([
1489
+ "$schema",
1490
+ "$comment",
1491
+ "title",
1492
+ "description",
1493
+ "default",
1494
+ "examples",
1495
+ "deprecated",
1496
+ "readOnly",
1497
+ "writeOnly",
1498
+ "$defs",
1499
+ "definitions",
1500
+ "contentEncoding",
1501
+ "contentMediaType",
1502
+ "minContains",
1503
+ "maxContains",
1504
+ "$vocabulary"
1505
+ ]);
1506
+ const OBJECT_EXTRAS = [
1507
+ "propertyNames",
1508
+ "minProperties",
1509
+ "maxProperties",
1510
+ "dependentRequired",
1511
+ "dependentSchemas",
1512
+ "dependencies"
1513
+ ];
1514
+ const ANNOTATING = new Set([
1515
+ "properties",
1516
+ "patternProperties",
1517
+ "additionalProperties",
1518
+ "prefixItems",
1519
+ "items",
1520
+ "additionalItems",
1521
+ "contains",
1522
+ "minContains",
1523
+ "maxContains",
1524
+ "allOf",
1525
+ "anyOf",
1526
+ "oneOf",
1527
+ "if",
1528
+ "then",
1529
+ "else",
1530
+ "$ref",
1531
+ "$dynamicRef",
1532
+ "dependentSchemas",
1533
+ "unevaluatedProperties",
1534
+ "unevaluatedItems"
1535
+ ]);
1536
+ /** anyOf/oneOf whose branches are all `{ const: primitive }`: an enum (distinct values make oneOf the same). */
1537
+ function constUnion(branches, exactlyOne) {
1538
+ const values = [];
1539
+ for (const branch of branches) {
1540
+ if (!isSchemaObject(branch) || !Object.hasOwn(branch, "const")) return void 0;
1541
+ for (const k of Object.keys(branch)) if (k !== "const" && !NEUTRAL_KEYWORDS.has(k)) return void 0;
1542
+ if (typeof branch.const === "object" && branch.const !== null) return void 0;
1543
+ if (exactlyOne && values.includes(branch.const)) return void 0;
1544
+ values.push(branch.const);
1545
+ }
1546
+ return enumCheck(values);
1547
+ }
1548
+ function tagOf(branch, key) {
1549
+ const properties = branch.properties;
1550
+ if (branch.type !== "object" || !Array.isArray(branch.required) || !branch.required.includes(key)) return void 0;
1551
+ const tag = isSchemaObject(properties) ? properties[key] : void 0;
1552
+ if (!isSchemaObject(tag) || !Object.hasOwn(tag, "const")) return void 0;
1553
+ return typeof tag.const === "object" && tag.const !== null ? void 0 : tag.const;
1554
+ }
1555
+ function number(value) {
1556
+ return typeof value === "number" ? value : void 0;
1557
+ }
1558
+ function entries(value) {
1559
+ return isSchemaObject(value) ? Object.entries(value) : [];
1560
+ }
1561
+
1562
+ //#endregion
1563
+ //#region ../../node_modules/.pnpm/@earendil-works+pi-schema@1.5.0_patch_hash=3a50e14587df64dfdea0adbae45b34d11585bb58009be0694fa2cf4a7986fbdf/node_modules/@earendil-works/pi-schema/dist/explain.js
1564
+ /** Explains failures of one compiled schema. */
1565
+ var Explainer = class {
1566
+ c;
1567
+ schema;
1568
+ /**
1569
+ * The errors of `$ref` targets for object values, within one errors() call: a recursive union explains each branch
1570
+ * to pick the one to blame, and every branch would explain the same children again, exponentially in the depth.
1571
+ */
1572
+ memo = void 0;
1573
+ constructor(compiler$1, schema) {
1574
+ this.c = compiler$1;
1575
+ this.schema = schema;
1576
+ compiler$1.root();
1577
+ }
1578
+ /** The errors of `value`, at least one (`value` failed the check). */
1579
+ errors(value) {
1580
+ const out = [];
1581
+ try {
1582
+ this.walk(this.schema, this.c.r.rootBase, value, "", out);
1583
+ } finally {
1584
+ this.memo = void 0;
1585
+ }
1586
+ if (out.length === 0) out.push({
1587
+ path: "",
1588
+ keyword: "schema",
1589
+ message: "invalid"
1590
+ });
1591
+ return out;
1592
+ }
1593
+ ok(node, base, v) {
1594
+ return this.c.check(node, base)(v);
1595
+ }
1596
+ walk(node, base, v, path, out) {
1597
+ if (node === true) return;
1598
+ if (node === false) {
1599
+ out.push({
1600
+ path,
1601
+ keyword: "false",
1602
+ message: "no value is allowed here"
1603
+ });
1604
+ return;
1605
+ }
1606
+ if (!isSchemaObject(node)) return;
1607
+ const b = this.c.r.baseFor(node, base);
1608
+ if (this.ok(node, b, v)) return;
1609
+ const start = out.length;
1610
+ const push = (keyword, message, at = path) => {
1611
+ out.push({
1612
+ path: at,
1613
+ keyword,
1614
+ message
1615
+ });
1616
+ };
1617
+ if (this.c.draft === "7" && typeof node.$ref === "string") {
1618
+ this.walkRef(node.$ref, b, v, path, out);
1619
+ return;
1620
+ }
1621
+ if (node.type !== void 0) {
1622
+ const types = Array.isArray(node.type) ? node.type : [node.type];
1623
+ if (!types.map((t) => (typeof t === "string" ? TYPE_CHECKS.get(t) : void 0) ?? NEVER).some((check) => check(v))) {
1624
+ push("type", `expected ${types.join(" or ")}, got ${typeName(v)}`);
1625
+ return;
1626
+ }
1627
+ }
1628
+ if (Array.isArray(node.enum) && !enumCheck(node.enum)(v)) push("enum", `expected one of ${listValues(node.enum)}`);
1629
+ if (Object.hasOwn(node, "const") && !constCheck(node.const)(v)) push("const", `expected ${JSON.stringify(node.const)}`);
1630
+ if (typeof v === "string" && node.type !== "bytes") this.walkString(node, v, push);
1631
+ if (v instanceof Uint8Array && node.type === "bytes") this.walkBytes(node, v, push);
1632
+ if (typeof v === "number") this.walkNumber(node, v, push);
1633
+ if (isObject(v)) this.walkObject(node, b, v, path, out, push);
1634
+ if (Array.isArray(v)) this.walkArray(node, b, v, path, out, push);
1635
+ if (Array.isArray(node.allOf)) for (const s of node.allOf) this.walk(s, b, v, path, out);
1636
+ if (Array.isArray(node.anyOf)) this.walkUnion(node.anyOf, b, v, path, out, false);
1637
+ if (Array.isArray(node.oneOf)) this.walkUnion(node.oneOf, b, v, path, out, true);
1638
+ if (node.not !== void 0 && this.ok(node.not, b, v)) push("not", "must not match the schema in not");
1639
+ if (node.if !== void 0) {
1640
+ const branch = this.ok(node.if, b, v) ? node.then : node.else;
1641
+ if (branch !== void 0) this.walk(branch, b, v, path, out);
1642
+ }
1643
+ if (typeof node.$ref === "string") this.walkRef(node.$ref, b, v, path, out);
1644
+ if (out.length === start && (node.unevaluatedProperties !== void 0 || node.unevaluatedItems !== void 0)) this.walkUnevaluated(node, b, v, path, out);
1645
+ if (out.length === start && typeof node.$dynamicRef === "string") push("$dynamicRef", "does not match the dynamically referenced schema");
1646
+ }
1647
+ walkRef(ref, base, v, path, out) {
1648
+ const target = this.c.r.resolve(ref, base);
1649
+ if (target.node === false && this.c.r.isUnresolved(ref, base)) {
1650
+ out.push({
1651
+ path,
1652
+ keyword: "$ref",
1653
+ message: `unresolved reference ${ref}`
1654
+ });
1655
+ return;
1656
+ }
1657
+ if (!isSchemaObject(target.node) || typeof v !== "object" || v === null) {
1658
+ this.walk(target.node, target.base, v, path, out);
1659
+ return;
1660
+ }
1661
+ this.memo ??= /* @__PURE__ */ new Map();
1662
+ let values = this.memo.get(target.node);
1663
+ const known = values?.get(v);
1664
+ if (known !== void 0 && known.path === path) {
1665
+ out.push(...known.errors);
1666
+ return;
1667
+ }
1668
+ const errors = [];
1669
+ this.walk(target.node, target.base, v, path, errors);
1670
+ if (values === void 0) {
1671
+ values = /* @__PURE__ */ new Map();
1672
+ this.memo.set(target.node, values);
1673
+ }
1674
+ values.set(v, {
1675
+ path,
1676
+ errors
1677
+ });
1678
+ out.push(...errors);
1679
+ }
1680
+ walkString(node, v, push) {
1681
+ const n = codePoints(v);
1682
+ if (typeof node.minLength === "number" && n < node.minLength) push("minLength", `expected at least ${node.minLength} characters`);
1683
+ if (typeof node.maxLength === "number" && n > node.maxLength) push("maxLength", `expected at most ${node.maxLength} characters`);
1684
+ if (typeof node.pattern === "string" && !sharedRegex(node.pattern).test(v)) push("pattern", `expected to match ${node.pattern}`);
1685
+ const formats = this.c.formats;
1686
+ const format = formats !== void 0 && typeof node.format === "string" && Object.hasOwn(formats, node.format) ? formats[node.format] : void 0;
1687
+ if (format !== void 0 && !format(v)) push("format", `expected format ${node.format}`);
1688
+ }
1689
+ walkBytes(node, v, push) {
1690
+ if (typeof node.minLength === "number" && v.length < node.minLength) push("minLength", `expected at least ${node.minLength} bytes`);
1691
+ if (typeof node.maxLength === "number" && v.length > node.maxLength) push("maxLength", `expected at most ${node.maxLength} bytes`);
1692
+ }
1693
+ walkNumber(node, v, push) {
1694
+ if (typeof node.minimum === "number" && v < node.minimum) push("minimum", `expected >= ${node.minimum}`);
1695
+ if (typeof node.maximum === "number" && v > node.maximum) push("maximum", `expected <= ${node.maximum}`);
1696
+ if (typeof node.exclusiveMinimum === "number" && v <= node.exclusiveMinimum) push("exclusiveMinimum", `expected > ${node.exclusiveMinimum}`);
1697
+ if (typeof node.exclusiveMaximum === "number" && v >= node.exclusiveMaximum) push("exclusiveMaximum", `expected < ${node.exclusiveMaximum}`);
1698
+ if (typeof node.multipleOf === "number" && !isMultiple(v, node.multipleOf)) push("multipleOf", `expected a multiple of ${node.multipleOf}`);
1699
+ }
1700
+ walkObject(node, b, v, path, out, push) {
1701
+ const properties = isSchemaObject(node.properties) ? node.properties : {};
1702
+ const required = Array.isArray(node.required) ? node.required : [];
1703
+ for (const k of required) if (typeof k === "string" && (!Object.hasOwn(v, k) || v[k] === void 0)) push("required", "missing", pointer(path, k));
1704
+ for (const k of Object.keys(properties)) if (Object.hasOwn(v, k) && v[k] !== void 0) this.walk(properties[k], b, v[k], pointer(path, k), out);
1705
+ const patterns = isSchemaObject(node.patternProperties) ? Object.entries(node.patternProperties) : [];
1706
+ for (const k of Object.keys(v)) {
1707
+ let matched = Object.hasOwn(properties, k);
1708
+ for (const [p, s] of patterns) if (sharedRegex(p).test(k)) {
1709
+ matched = true;
1710
+ this.walk(s, b, v[k], pointer(path, k), out);
1711
+ }
1712
+ if (!matched && node.additionalProperties !== void 0) if (node.additionalProperties === false) push("additionalProperties", "unknown field", pointer(path, k));
1713
+ else this.walk(node.additionalProperties, b, v[k], pointer(path, k), out);
1714
+ if (node.propertyNames !== void 0 && !this.ok(node.propertyNames, b, k)) push("propertyNames", "invalid property name", pointer(path, k));
1715
+ }
1716
+ const count = Object.keys(v).length;
1717
+ if (typeof node.minProperties === "number" && count < node.minProperties) push("minProperties", `expected at least ${node.minProperties} properties`);
1718
+ if (typeof node.maxProperties === "number" && count > node.maxProperties) push("maxProperties", `expected at most ${node.maxProperties} properties`);
1719
+ const dependencies = {
1720
+ ...this.c.draft === "7" || !isSchemaObject(node.dependentRequired) ? {} : node.dependentRequired,
1721
+ ...isSchemaObject(node.dependencies) ? node.dependencies : {}
1722
+ };
1723
+ for (const [k, d] of Object.entries(dependencies)) {
1724
+ if (!Object.hasOwn(v, k)) continue;
1725
+ if (!Array.isArray(d)) this.walk(d, b, v, path, out);
1726
+ else for (const r of d) if (!Object.hasOwn(v, r)) push("dependentRequired", `required when ${k} is present`, pointer(path, r));
1727
+ }
1728
+ if (this.c.draft !== "7" && isSchemaObject(node.dependentSchemas)) {
1729
+ for (const [k, s] of Object.entries(node.dependentSchemas)) if (Object.hasOwn(v, k)) this.walk(s, b, v, path, out);
1730
+ }
1731
+ }
1732
+ walkArray(node, b, v, path, out, push) {
1733
+ let prefix = [];
1734
+ let rest;
1735
+ if (Array.isArray(node.items)) {
1736
+ prefix = node.items;
1737
+ rest = node.additionalItems;
1738
+ } else {
1739
+ if (this.c.draft !== "7" && Array.isArray(node.prefixItems)) prefix = node.prefixItems;
1740
+ rest = node.items;
1741
+ }
1742
+ for (let i = 0; i < v.length; i++) {
1743
+ const s = i < prefix.length ? prefix[i] : rest;
1744
+ if (s !== void 0) this.walk(s, b, v[i], `${path}/${i}`, out);
1745
+ }
1746
+ if (typeof node.minItems === "number" && v.length < node.minItems) push("minItems", `expected at least ${node.minItems} items`);
1747
+ if (typeof node.maxItems === "number" && v.length > node.maxItems) push("maxItems", `expected at most ${node.maxItems} items`);
1748
+ if (node.uniqueItems === true && !uniqueCheck(v)) push("uniqueItems", "expected unique items");
1749
+ if (node.contains !== void 0) {
1750
+ const draft7 = this.c.draft === "7";
1751
+ const min = draft7 || typeof node.minContains !== "number" ? 1 : node.minContains;
1752
+ const max = draft7 || typeof node.maxContains !== "number" ? Number.POSITIVE_INFINITY : node.maxContains;
1753
+ if (!containsCheck(this.c.check(node.contains, b), min, max)(v)) push("contains", containsMessage(min, max));
1754
+ }
1755
+ }
1756
+ walkUnion(branches, b, v, path, out, exactlyOne) {
1757
+ const matches = branches.filter((s) => this.ok(s, b, v)).length;
1758
+ if (matches === 1 || !exactlyOne && matches > 0) return;
1759
+ const keyword = exactlyOne ? "oneOf" : "anyOf";
1760
+ if (matches > 1) {
1761
+ out.push({
1762
+ path,
1763
+ keyword,
1764
+ message: "matches more than one alternative"
1765
+ });
1766
+ return;
1767
+ }
1768
+ const tag = this.tagOf(branches, b);
1769
+ if (tag !== void 0 && isObject(v)) {
1770
+ const i = tag.values.indexOf(v[tag.key]);
1771
+ if (i < 0) out.push({
1772
+ path: pointer(path, tag.key),
1773
+ keyword,
1774
+ message: `expected one of ${listValues(tag.values)}`
1775
+ });
1776
+ else this.walk(branches[i], b, v, path, out);
1777
+ return;
1778
+ }
1779
+ let best;
1780
+ for (const s of branches) {
1781
+ const errors = [];
1782
+ this.walk(s, b, v, path, errors);
1783
+ if (errors.length === 0) continue;
1784
+ const declared = isObject(v) ? this.declaredKeys(s, b, v) : 0;
1785
+ if (best === void 0 || declared > best.declared || declared === best.declared && errors[0].path.length > best.errors[0].path.length) best = {
1786
+ errors,
1787
+ declared
1788
+ };
1789
+ }
1790
+ out.push(...best?.errors ?? [{
1791
+ path,
1792
+ keyword,
1793
+ message: "matches no alternative"
1794
+ }]);
1795
+ }
1796
+ /** How many of the keys of `v` the branch `s` (through a `$ref`) declares in `properties`. */
1797
+ declaredKeys(s, b, v) {
1798
+ const node = isSchemaObject(s) && typeof s.$ref === "string" ? this.c.r.resolve(s.$ref, b).node : s;
1799
+ const properties = isSchemaObject(node) && isSchemaObject(node.properties) ? node.properties : {};
1800
+ return Object.keys(v).filter((k) => Object.hasOwn(properties, k)).length;
1801
+ }
1802
+ tagOf(branches, b) {
1803
+ const resolved = branches.map((s) => isSchemaObject(s) && typeof s.$ref === "string" ? this.c.r.resolve(s.$ref, b).node : s);
1804
+ const first = resolved[0];
1805
+ if (!isSchemaObject(first) || !isSchemaObject(first.properties)) return void 0;
1806
+ for (const key of Object.keys(first.properties)) {
1807
+ const values = resolved.map((s) => {
1808
+ const tag = isSchemaObject(s) && isSchemaObject(s.properties) ? s.properties[key] : void 0;
1809
+ return isSchemaObject(tag) ? tag.const : void 0;
1810
+ });
1811
+ if (values.every((x) => x !== void 0 && (typeof x !== "object" || x === null)) && new Set(values).size === values.length) return {
1812
+ key,
1813
+ values
1814
+ };
1815
+ }
1816
+ }
1817
+ walkUnevaluated(node, b, v, path, out) {
1818
+ const { unevaluatedProperties: unevaluatedProperties$1, unevaluatedItems: unevaluatedItems$1,...rest } = node;
1819
+ const a = newAnnotations();
1820
+ this.c.annotating(rest, b)(v, a);
1821
+ if (isObject(v) && unevaluatedProperties$1 !== void 0 && !a.allProps) for (const k of Object.keys(v)) {
1822
+ if (a.props?.has(k)) continue;
1823
+ if (unevaluatedProperties$1 === false) out.push({
1824
+ path: pointer(path, k),
1825
+ keyword: "unevaluatedProperties",
1826
+ message: "unknown field"
1827
+ });
1828
+ else this.walk(unevaluatedProperties$1, b, v[k], pointer(path, k), out);
1829
+ }
1830
+ if (Array.isArray(v) && unevaluatedItems$1 !== void 0 && !a.allItems) for (let i = a.items; i < v.length; i++) {
1831
+ if (a.indexes?.has(i)) continue;
1832
+ if (unevaluatedItems$1 === false) out.push({
1833
+ path: `${path}/${i}`,
1834
+ keyword: "unevaluatedItems",
1835
+ message: "unexpected item"
1836
+ });
1837
+ else this.walk(unevaluatedItems$1, b, v[i], `${path}/${i}`, out);
1838
+ }
1839
+ }
1840
+ };
1841
+ const LISTED_VALUES = 20;
1842
+ /** `values` as JSON, at most LISTED_VALUES of them, then how many more there are. */
1843
+ function listValues(values) {
1844
+ if (values.length <= LISTED_VALUES) return JSON.stringify(values);
1845
+ return `${JSON.stringify(values.slice(0, LISTED_VALUES)).slice(0, -1)}, ... and ${values.length - LISTED_VALUES} more]`;
1846
+ }
1847
+ function containsMessage(min, max) {
1848
+ if (max === Number.POSITIVE_INFINITY) return `expected at least ${min} matching ${min === 1 ? "item" : "items"}`;
1849
+ if (min === 0) return `expected at most ${max} matching ${max === 1 ? "item" : "items"}`;
1850
+ return `expected between ${min} and ${max} matching items`;
1851
+ }
1852
+ function pointer(path, key) {
1853
+ return `${path}/${String(key).replace(/~/g, "~0").replace(/\//g, "~1")}`;
1854
+ }
1855
+ function typeName(v) {
1856
+ if (v === null) return "null";
1857
+ if (Array.isArray(v)) return "array";
1858
+ if (v instanceof Uint8Array) return "bytes";
1859
+ if (typeof v === "number" && Number.isInteger(v)) return "integer";
1860
+ return typeof v;
1861
+ }
1862
+
1863
+ //#endregion
1864
+ //#region ../../node_modules/.pnpm/@earendil-works+pi-schema@1.5.0_patch_hash=3a50e14587df64dfdea0adbae45b34d11585bb58009be0694fa2cf4a7986fbdf/node_modules/@earendil-works/pi-schema/dist/validator.js
1865
+ function compile(schema, options = NO_OPTIONS) {
1866
+ const check = compileCheck(schema, options);
1867
+ return options.coerce === true ? new CoercingValidator(schema, options, check) : new Validator(schema, options, check);
1868
+ }
1869
+ const NO_OPTIONS = Object.freeze({});
1870
+ /** A compiled schema whose valid values have type `T` (`unknown` unless the schema was built with the builders). */
1871
+ var Validator = class {
1872
+ /** Whether `value` is valid. A plain function: it may be passed around without its validator. */
1873
+ check;
1874
+ schema;
1875
+ options;
1876
+ explainer = void 0;
1877
+ constructor(schema, options, check) {
1878
+ this.check = check;
1879
+ this.schema = schema;
1880
+ this.options = options;
1881
+ }
1882
+ /**
1883
+ * Why `value` is invalid: one error per failing keyword, `[]` when it is valid. Built on the first failure and
1884
+ * kept, so a validator whose values always pass never pays for it.
1885
+ */
1886
+ errors(value) {
1887
+ if (this.check(value)) return [];
1888
+ this.explainer ??= new Explainer(compiler(this.schema, this.options), this.schema);
1889
+ return this.explainer.errors(value);
1890
+ }
1891
+ };
1892
+ /** A validator compiled with `coerce: true`: it also coerces loosely typed input towards the schema. */
1893
+ var CoercingValidator = class extends Validator {
1894
+ coercer = void 0;
1895
+ /**
1896
+ * `value` coerced towards the schema: numeric strings to numbers, `"true"` to `true`, a single value to a one-item
1897
+ * array, an optional `null` dropped, the first union branch the value converts to (the README lists every rule).
1898
+ * Only the changed paths are copied; `value` comes back itself when nothing changes, and is never modified. Values
1899
+ * that cannot be coerced stay as they are. The rules are built on the first call.
1900
+ */
1901
+ coerce(value) {
1902
+ this.coercer ??= new Coercer(compiler(this.schema, this.options), this.schema);
1903
+ return this.coercer.coerce(value);
1904
+ }
1905
+ /** Coerces `value`, then checks it: the coerced value when it is valid, else its errors. */
1906
+ parse(value) {
1907
+ const coerced = this.coerce(value);
1908
+ return this.check(coerced) ? {
1909
+ ok: true,
1910
+ value: coerced
1911
+ } : {
1912
+ ok: false,
1913
+ errors: this.errors(coerced)
1914
+ };
1915
+ }
1916
+ };
1917
+ function compileCheck(schema, options) {
1918
+ return compiler(schema, options).root();
1919
+ }
1920
+ function compiler(schema, options) {
1921
+ const plain = new Compiler(schema, options, false);
1922
+ try {
1923
+ plain.root();
1924
+ return plain;
1925
+ } catch (error) {
1926
+ if (error !== RESTART) throw error;
1927
+ return new Compiler(schema, options, true);
1928
+ }
1929
+ }
1930
+
1931
+ //#endregion
1932
+ export { compile };
1933
+ //# sourceMappingURL=compiler.js.map