@atscript/typescript 0.1.109 → 0.2.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.
@@ -0,0 +1,3703 @@
1
+
2
+ //#region packages/typescript/src/runtime/validator-keys.ts
3
+ /**
4
+ * Annotation keys the validator pre-check reads, per kind of checked value — shared by the
5
+ * interpreted pre-check (validator-fast-check.ts) and the compiled checks (compiled-check/).
6
+ */ /** The format of a `decimal` value (a string). */ const DECIMAL_RE = /^[+-]?\d+(\.\d+)?$/;
7
+ /** Annotations of a string node, in check order. */ const STRING_KEYS = [
8
+ "meta.required",
9
+ "expect.minLength",
10
+ "expect.maxLength",
11
+ "expect.pattern"
12
+ ];
13
+ /** Annotations of a number node, in check order. */ const NUMBER_KEYS = [
14
+ "expect.int",
15
+ "expect.min",
16
+ "expect.max",
17
+ "expect.exclusiveMin",
18
+ "expect.exclusiveMax"
19
+ ];
20
+ /** Annotations of a boolean node. */ const BOOLEAN_KEYS = ["meta.required"];
21
+ /** Annotations of an array node, in check order. */ const ARRAY_KEYS = [
22
+ "expect.minLength",
23
+ "expect.maxLength",
24
+ "expect.array.uniqueItems"
25
+ ];
26
+ /**
27
+ * Every annotation key the validator pre-check reads. The order is the bit order of
28
+ * compiled-check layouts: changing it changes the layout format.
29
+ */ const VALIDATOR_KEYS = [
30
+ "meta.required",
31
+ "expect.minLength",
32
+ "expect.maxLength",
33
+ "expect.pattern",
34
+ "expect.int",
35
+ "expect.min",
36
+ "expect.max",
37
+ "expect.exclusiveMin",
38
+ "expect.exclusiveMax",
39
+ "expect.array.uniqueItems"
40
+ ];
41
+ /**
42
+ * The number a length / bound annotation compares with: the annotation is either the number
43
+ * itself or an object carrying it in `field` (`{ length }`, `{ minValue }`, …).
44
+ */ function boundOf(m, field) {
45
+ return typeof m === "number" ? m : m[field];
46
+ }
47
+ /** The props of array item type `of` (an object) marked `@expect.array.key`, in order. */ function arrayKeyProps(of) {
48
+ const out = [];
49
+ if (of?.type.kind === "object") {
50
+ for (const [key, prop] of of.type.props) if (prop.metadata.get("expect.array.key")) out.push(key);
51
+ }
52
+ return out;
53
+ }
54
+
55
+ //#endregion
56
+ //#region packages/typescript/src/runtime/compiled-check/tracking.ts
57
+ /**
58
+ * Mutation tracking for build-time compiled validator checks and cached layered metadata reads.
59
+ *
60
+ * A compiled check is bound to the live type tree before use (see registry.ts): the bind
61
+ * verifies that the tree still has the structure the check was compiled for and snapshots
62
+ * the constraint values the check reads. Every tracked mutation of an object a bind has
63
+ * read bumps one global epoch, which makes every compiled check re-bind on its next use.
64
+ *
65
+ * Tracked: `annotate()`, the metadata / props `Map` methods (`set` / `delete` / `clear`),
66
+ * the `defineAnnotatedType()` handle methods. Raw writes (`node.optional = …`,
67
+ * `node.metadata = …`, `type.items.push(…)`, editing a constraint object in place, …) cannot
68
+ * be seen: call {@link invalidateCompiledValidators} after them, with either validator engine.
69
+ */ const VALIDATOR_KEY_SET = new Set(VALIDATOR_KEYS);
70
+ const mapSet = Map.prototype.set;
71
+ /** Global mutation epoch: compiled checks bound in an older epoch re-bind before use. */ let epoch = 0;
72
+ /**
73
+ * Writes of metadata maps so far (any map, any key: `annotate()`, the `Map` methods, a node's map
74
+ * replaced, a layer flag or intrinsic mark registered): a lazy JSON schema or a layered map's
75
+ * flattened view built before the last one is built again (see `lazyJsonSchema`, `LayerMap`).
76
+ */ let metadataWrites = 0;
77
+ /** Some bind has watched an object (until then no mutation can affect a compiled check). */ let tracking = false;
78
+ /** Objects (nodes, type defs, metadata / props maps) read by some compiled-check bind. */ const watched = /* @__PURE__ */ new WeakSet();
79
+ /** The current mutation epoch. */ function currentEpoch() {
80
+ return epoch;
81
+ }
82
+ /** Marks `obj` as read by a bind: tracked mutations of it invalidate compiled checks. */ function watch(obj) {
83
+ tracking = true;
84
+ watched.add(obj);
85
+ }
86
+ /** Records a tracked mutation of `obj` (a no-op unless some bind has read it). */ function touched(obj) {
87
+ if (tracking && watched.has(obj)) epoch++;
88
+ }
89
+ /**
90
+ * Makes every compiled validator check re-verify the type tree it was compiled for, and every
91
+ * node that reads metadata through other nodes re-read them, before its next use.
92
+ *
93
+ * Validators (compiled checks emitted with `tsPlugin({ compileValidators: true })` and the
94
+ * interpreted walk alike) see mutations made through `annotate()`, the metadata / props `Map`
95
+ * methods and the `defineAnnotatedType()` handle methods automatically. Call this after
96
+ * changing a type tree any other way:
97
+ * - a raw property write: `node.optional = …`, `node.type = …`, `node.metadata = …`,
98
+ * `type.items.push(…)`, `type.of = …`, `type.propsPatterns.push(…)`;
99
+ * - an in-place edit of an annotation value: mutating a constraint object
100
+ * (`metadata.get('expect.min').minValue = 5`), editing or pushing onto an
101
+ * `@expect.pattern` array directly (use `annotate(metadata, key, value, true)` instead).
102
+ *
103
+ * Without it a compiled check may keep validating against the old shape or values, and a
104
+ * node that reads metadata through other nodes (a reference, a merged field, a path override)
105
+ * may keep reading the old values: the rule is the same for both engines.
106
+ *
107
+ * Any mutation of a type a compiled check has bound to (tracked or invalidated) makes every
108
+ * compiled check re-bind once on its next use: cheap during startup / configuration, but
109
+ * avoid mutating validated types per request.
110
+ */ function invalidateCompiledValidators() {
111
+ epoch++;
112
+ metadataWrites++;
113
+ }
114
+ /** The number of metadata writes so far (see `metadataWrites`). */ function metadataWriteCount() {
115
+ return metadataWrites;
116
+ }
117
+ /** Records a write of a node's metadata the maps do not see: the node's map replaced. */ function metadataReplaced() {
118
+ metadataWrites++;
119
+ }
120
+ /**
121
+ * `annotate(m, key, value, true)` where map `m` holds `own` as its own value of `key`: appended in
122
+ * place to an own list (the map sees no write: tracked here as one), else a list of both.
123
+ */ function appendOwn(m, key, own, value) {
124
+ if (Array.isArray(own)) {
125
+ own.push(value);
126
+ if (VALIDATOR_KEY_SET.has(key)) touched(m);
127
+ metadataWrites++;
128
+ } else m.set(key, [own, value]);
129
+ }
130
+ /**
131
+ * Metadata map of runtime type nodes: a `Map` whose writes to validator annotation keys
132
+ * are tracked (see {@link invalidateCompiledValidators}). Reads are the builtin ones.
133
+ */ var AnnotationMap = class extends Map {
134
+ set(key, value) {
135
+ super.set(key, value);
136
+ if (tracking && VALIDATOR_KEY_SET.has(key)) touched(this);
137
+ metadataWrites++;
138
+ return this;
139
+ }
140
+ delete(key) {
141
+ const deleted = super.delete(key);
142
+ if (deleted) {
143
+ if (tracking && VALIDATOR_KEY_SET.has(key)) touched(this);
144
+ metadataWrites++;
145
+ }
146
+ return deleted;
147
+ }
148
+ clear() {
149
+ super.clear();
150
+ touched(this);
151
+ metadataWrites++;
152
+ }
153
+ /** A new map holding `entries`: no write (a new map is in no compiled check nor schema). */ constructor(entries) {
154
+ super();
155
+ if (entries) for (const [key, value] of entries) mapSet.call(this, key, value);
156
+ }
157
+ };
158
+ /** Props map of runtime object types: a `Map` whose writes are tracked. */ var PropsMap = class extends Map {
159
+ set(key, value) {
160
+ super.set(key, value);
161
+ touched(this);
162
+ return this;
163
+ }
164
+ delete(key) {
165
+ const deleted = super.delete(key);
166
+ if (deleted) touched(this);
167
+ return deleted;
168
+ }
169
+ clear() {
170
+ super.clear();
171
+ touched(this);
172
+ }
173
+ /** A new map holding `entries` (untracked: a new map is in no compiled check). */ constructor(entries) {
174
+ super();
175
+ if (entries) for (const [key, value] of entries) mapSet.call(this, key, value);
176
+ }
177
+ };
178
+
179
+ //#endregion
180
+ //#region packages/typescript/src/runtime/layers.ts
181
+ /**
182
+ * Metadata layers: the runtime's one metadata mechanism.
183
+ *
184
+ * A node's metadata is its own map plus an ordered list of base nodes (`b`, priority order:
185
+ * `b[0]` first). A read returns the own value, else the first base that has the key; an append
186
+ * key returns the bases' values (lowest priority first), then the own ones. Writes (`set`,
187
+ * `delete`, `clear`) are the own map's: `delete` lets a base's value show again, and a write on
188
+ * a base shows through every layer over it.
189
+ *
190
+ * Reads go through a flattened view of the effective entries, rebuilt on the first read after any
191
+ * metadata write (one global write counter: `metadataWriteCount`). The view is used only while
192
+ * every map below is tracked (an `AnnotationMap` or a `LayerMap`, whose writes the counter
193
+ * sees); otherwise the reads are live. A raw write the counter does not see (a node's map swapped,
194
+ * `node.metadata = X`, or edited in place) must be followed by `invalidateCompiledValidators()`,
195
+ * as compiled checks require (PERF-2).
196
+ */ function _define_property$2(obj, key, value) {
197
+ if (key in obj) Object.defineProperty(obj, key, {
198
+ value,
199
+ enumerable: true,
200
+ configurable: true,
201
+ writable: true
202
+ });
203
+ else obj[key] = value;
204
+ return obj;
205
+ }
206
+ /** Append keys: concatenated across layers (registered by generated code, `$ak`). */ const APPEND = 1;
207
+ /** `passedWhenReferred: false` keys: never read through a reference layer (`$nr`). */ const NOT_REFERRED = 2;
208
+ /** The flags of the registered keys (one lookup per read). */ const FLAGS = /* @__PURE__ */ new Map();
209
+ function flag(keys, f) {
210
+ for (const key of keys) FLAGS.set(key, (FLAGS.get(key) ?? 0) | f);
211
+ metadataReplaced();
212
+ }
213
+ /** Registers append keys (`mergeStrategy: 'append'`). */ function $ak(...keys) {
214
+ flag(keys, APPEND);
215
+ }
216
+ /** Registers `passedWhenReferred: false` keys. */ function $nr(...keys) {
217
+ flag(keys, NOT_REFERRED);
218
+ }
219
+ /** Whether `key` is an append key (see {@link $ak}). */ function isAppendKey(key) {
220
+ return ((FLAGS.get(key) ?? 0) & APPEND) !== 0;
221
+ }
222
+ const notReferred = (key) => ((FLAGS.get(key) ?? 0) & NOT_REFERRED) !== 0;
223
+ /**
224
+ * Intrinsic entries per metadata map: a primitive extension's own annotations
225
+ * (`string.required` → `meta.required`) are part of the type, so they pass every reference layer
226
+ * although their key is `passedWhenReferred: false` (0.1.110).
227
+ */ const INTRINSIC = /* @__PURE__ */ new WeakMap();
228
+ /** Marks `keys` of map `m` intrinsic (see {@link INTRINSIC}). */ function markIntrinsic(m, keys) {
229
+ let s = INTRINSIC.get(m);
230
+ if (!s) INTRINSIC.set(m, s = /* @__PURE__ */ new Set());
231
+ for (const k of keys) s.add(k);
232
+ metadataReplaced();
233
+ }
234
+ /**
235
+ * A map replacing `from` (layered over its bases now) keeps its intrinsic marks. (No write
236
+ * counted: the callers count the map replaced.)
237
+ */ function moveIntrinsic(from, to) {
238
+ const s = INTRINSIC.get(from);
239
+ if (s) INTRINSIC.set(to, s);
240
+ }
241
+ const MISS = Symbol("miss");
242
+ /** The view of a layered map without effective entries (never written: views stay internal). */ const NO_ENTRIES = new AnnotationMap();
243
+ const mapGet = Map.prototype.get;
244
+ const mapHas = Map.prototype.has;
245
+ const ownSize = Object.getOwnPropertyDescriptor(Map.prototype, "size").get;
246
+ let _Symbol_iterator = Symbol.iterator;
247
+ /**
248
+ * A metadata map that reads through base nodes (see the file comment). `r`: the bases are
249
+ * reference layers (a prop's / element's type, a chain ref, `extends`, merge operands), so
250
+ * `passedWhenReferred: false` keys are not read through them.
251
+ */ var LayerMap = class extends AnnotationMap {
252
+ /**
253
+ * The flattened view (built again after a metadata write), `undefined`: read live. Internal:
254
+ * this module's readers and the validators read it (`readable`, `filledMeta`), never write.
255
+ */ view() {
256
+ return this.w === metadataWriteCount() ? this.f : this.flatten();
257
+ }
258
+ flatten() {
259
+ this.w = -1;
260
+ let f;
261
+ if (tracked(this, /* @__PURE__ */ new Set())) {
262
+ const keys = this.liveKeys();
263
+ f = keys.length === 0 ? NO_ENTRIES : new AnnotationMap(keys.map((k) => [k, this.liveGet(k)]));
264
+ }
265
+ this.f = f;
266
+ this.w = metadataWriteCount();
267
+ return f;
268
+ }
269
+ /** The value of `key` (not concatenated), or `MISS`; `nr`: a `passedWhenReferred:false` key. */ lookup(key, nr) {
270
+ if (ownSize.call(this) !== 0) {
271
+ const v = mapGet.call(this, key);
272
+ if (v !== void 0 || mapHas.call(this, key)) return v;
273
+ }
274
+ if (nr && this.r) {
275
+ for (const n of this.b) {
276
+ const x = intrinsicLookup(n.metadata, key);
277
+ if (x !== MISS) return x;
278
+ }
279
+ return MISS;
280
+ }
281
+ for (const n of this.b) {
282
+ const m = n.metadata;
283
+ let x;
284
+ if (m.b === void 0) {
285
+ x = m.get(key);
286
+ if (x === void 0 && !m.has(key)) x = MISS;
287
+ } else x = m.lookup(key, nr);
288
+ if (x !== MISS) return x;
289
+ }
290
+ return MISS;
291
+ }
292
+ get(key) {
293
+ const view = this.w === metadataWriteCount() ? this.f : this.flatten();
294
+ return view === void 0 ? this.liveGet(key) : mapGet.call(view, key);
295
+ }
296
+ /** `get` read through the layers (see the file comment). */ liveGet(key) {
297
+ const f = FLAGS.get(key);
298
+ if (f !== void 0 && (f & APPEND) !== 0) return this.append(key);
299
+ const v = this.lookup(key, f !== void 0 && (f & NOT_REFERRED) !== 0);
300
+ return v === MISS ? void 0 : v;
301
+ }
302
+ has(key) {
303
+ const view = this.view();
304
+ return view === void 0 ? this.lookup(key, notReferred(key)) !== MISS : mapHas.call(view, key);
305
+ }
306
+ /** An append key: the bases' values (lowest priority first), then the own ones. */ append(key) {
307
+ const own = mapGet.call(this, key);
308
+ if (this.r && notReferred(key)) {
309
+ const parts = [];
310
+ const acc = {
311
+ out: parts,
312
+ seen: /* @__PURE__ */ new Map()
313
+ };
314
+ for (let i = this.b.length - 1; i >= 0; i--) collect(this.b[i].metadata, key, acc, true);
315
+ if (parts.length === 0) return own;
316
+ if (own !== void 0) parts.push(own);
317
+ return parts.length === 1 ? parts[0] : parts.flat();
318
+ }
319
+ let one;
320
+ let count = 0;
321
+ for (const n of this.b) {
322
+ const x = n.metadata.get(key);
323
+ if (x !== void 0 && ++count === 1) one = x;
324
+ }
325
+ if (count === 0) return own;
326
+ if (count === 1 && own === void 0) return one;
327
+ const parts = [];
328
+ collect(this, key, {
329
+ out: parts,
330
+ seen: /* @__PURE__ */ new Map()
331
+ }, false);
332
+ if (parts.length === 1) return parts[0];
333
+ const out = [];
334
+ for (const p of parts) if (Array.isArray(p)) out.push(...p);
335
+ else out.push(p);
336
+ return out;
337
+ }
338
+ /** The effective keys: own first, then the bases' in priority order. */ effectiveKeys() {
339
+ const view = this.view();
340
+ return view === void 0 ? this.liveKeys() : [...view.keys()];
341
+ }
342
+ liveKeys() {
343
+ const out = /* @__PURE__ */ new Set();
344
+ keysOf(this, false, out, /* @__PURE__ */ new Map());
345
+ return [...out];
346
+ }
347
+ keys() {
348
+ return this.effectiveKeys()[Symbol.iterator]();
349
+ }
350
+ values() {
351
+ return this.effectiveKeys().map((k) => this.get(k))[Symbol.iterator]();
352
+ }
353
+ entries() {
354
+ return this.effectiveKeys().map((k) => [k, this.get(k)])[Symbol.iterator]();
355
+ }
356
+ [_Symbol_iterator]() {
357
+ return this.entries();
358
+ }
359
+ forEach(cb, thisArg) {
360
+ for (const k of this.effectiveKeys()) cb.call(thisArg, this.get(k), k, this);
361
+ }
362
+ constructor(bases, reference = false, own) {
363
+ super(own), _define_property$2(this, "b", void 0), _define_property$2(this, "r", void 0), _define_property$2(this, "f", void 0), _define_property$2(this, "w", void 0);
364
+ this.b = bases;
365
+ this.r = reference;
366
+ this.f = void 0;
367
+ this.w = -1;
368
+ }
369
+ };
370
+ Object.defineProperty(LayerMap.prototype, "size", {
371
+ get() {
372
+ const view = this.view();
373
+ if (view !== void 0) return view.size;
374
+ return metaEmpty(this) ? 0 : this.effectiveKeys().length;
375
+ },
376
+ configurable: true
377
+ });
378
+ /**
379
+ * Every map of `m`'s layers is tracked (an `AnnotationMap` or a `LayerMap`, whose writes count in
380
+ * `metadataWrites`), so a flattened view of `m` stays right until the next write.
381
+ */ function tracked(m, seen) {
382
+ const p = Object.getPrototypeOf(m);
383
+ if (p !== AnnotationMap.prototype && p !== LayerMap.prototype) return false;
384
+ const b = m.b;
385
+ if (b !== void 0 && !seen.has(m)) {
386
+ seen.add(m);
387
+ for (const n of b) if (!tracked(n.metadata, seen)) return false;
388
+ }
389
+ return true;
390
+ }
391
+ /** `key`'s intrinsic value in `m` or its bases (see {@link INTRINSIC}), or `MISS`. */ function intrinsicLookup(m, key) {
392
+ if (INTRINSIC.get(m)?.has(key)) {
393
+ if (m instanceof LayerMap ? mapHas.call(m, key) : m.has(key)) return m instanceof LayerMap ? mapGet.call(m, key) : m.get(key);
394
+ }
395
+ const b = m.b;
396
+ if (b !== void 0) for (const n of b) {
397
+ const x = intrinsicLookup(n.metadata, key);
398
+ if (x !== MISS) return x;
399
+ }
400
+ return MISS;
401
+ }
402
+ /**
403
+ * Whether a layer walk visits `m` (reached `filtered` or not): each map once, except that a map
404
+ * first reached `filtered` (through a reference layer) is visited again when reached unfiltered
405
+ * (a diamond: a direct base over the same node), as the layered `get` reads it. `seen`: the maps
406
+ * visited, `true` while only filtered.
407
+ */ function visit(m, filtered, seen) {
408
+ const was = seen.get(m);
409
+ if (was !== void 0 && (filtered || !was)) return false;
410
+ seen.set(m, filtered);
411
+ return true;
412
+ }
413
+ /**
414
+ * The values of `key` of `m` and its bases (lowest priority first), each map once (see
415
+ * {@link visit}). `filtered`: reached through a reference layer with a `passedWhenReferred: false`
416
+ * key — only intrinsic entries count (see {@link INTRINSIC}), down to the bottom.
417
+ */ function collect(m, key, acc, filtered) {
418
+ const was = acc.seen.get(m);
419
+ if (!visit(m, filtered, acc.seen)) return;
420
+ const layer = m instanceof LayerMap ? m : void 0;
421
+ if (layer) {
422
+ const below = filtered || layer.r && notReferred(key);
423
+ for (let i = layer.b.length - 1; i >= 0; i--) collect(layer.b[i].metadata, key, acc, below);
424
+ }
425
+ const intrinsic = INTRINSIC.get(m)?.has(key) === true;
426
+ if ((filtered ? intrinsic : !(was === true && intrinsic)) && (layer ? mapHas.call(m, key) : m.has(key))) acc.out.push(layer ? mapGet.call(m, key) : m.get(key));
427
+ }
428
+ /**
429
+ * The keys of `m` (own first, then its bases'), each map once (see {@link visit}). `filtered`:
430
+ * reached through a reference layer.
431
+ */ function keysOf(m, filtered, out, seen) {
432
+ if (!visit(m, filtered, seen)) return;
433
+ const layer = m instanceof LayerMap ? m : void 0;
434
+ const own = layer ? Map.prototype.keys.call(m) : m.keys();
435
+ const intrinsic = INTRINSIC.get(m);
436
+ for (const k of own) if (!filtered || !notReferred(k) || intrinsic?.has(k)) out.add(k);
437
+ if (layer) for (const n of layer.b) keysOf(n.metadata, filtered || layer.r, out, seen);
438
+ }
439
+ /**
440
+ * `m` has no entry (own or through its bases): the validators' `metadata.size === 0` fast path,
441
+ * without computing a layered map's effective size. May answer `false` for a map whose only base
442
+ * entries are filtered out (`passedWhenReferred: false`): the slow path then finds nothing.
443
+ */ function metaEmpty(m) {
444
+ const b = m.b;
445
+ if (b === void 0) return m.size === 0;
446
+ const view = m.view();
447
+ if (view !== void 0) return view.size === 0;
448
+ if (ownSize.call(m) !== 0) return false;
449
+ for (const n of b) if (!metaEmpty(n.metadata)) return false;
450
+ return true;
451
+ }
452
+ /**
453
+ * `m` for reading: a layered map's flattened view (see `LayerMap.view`), else `m` itself.
454
+ * The validators read builtin maps this way (never write: a view is shared).
455
+ */ function readable(m) {
456
+ return m.b === void 0 ? m : m.view() ?? m;
457
+ }
458
+ /**
459
+ * {@link readable}`(m)`, or `undefined` when `m` has no entry: the validators' "no constraint"
460
+ * fast path and their reads in one (a plain map costs what `metaEmpty` did).
461
+ */ function filledMeta(m) {
462
+ if (m.b === void 0) return m.size === 0 ? void 0 : m;
463
+ const view = m.view();
464
+ if (view !== void 0) return view.size === 0 ? void 0 : view;
465
+ return metaEmpty(m) ? void 0 : m;
466
+ }
467
+ /**
468
+ * Watches `m` and every base (node and map, transitively) for a compiled check's bind (see
469
+ * `compiled-check/tracking.ts`): a tracked write to any of them re-binds the check. `false` when
470
+ * one of the maps is untracked (a plain `Map`): such a tree stays interpreted.
471
+ */ function watchLayer(m, seen) {
472
+ watch(m);
473
+ const b = m.b;
474
+ if (b === void 0) return m instanceof AnnotationMap;
475
+ let ok = true;
476
+ for (const n of b) {
477
+ const nm = n.metadata;
478
+ if (seen?.has(nm)) continue;
479
+ (seen ?? (seen = /* @__PURE__ */ new Set())).add(nm);
480
+ watch(n);
481
+ ok = watchLayer(nm, seen) && ok;
482
+ }
483
+ return ok;
484
+ }
485
+ /** The own entries of `m` (a layered map's, not read through its bases). */ function ownEntries(m) {
486
+ return m instanceof LayerMap ? [...Map.prototype.entries.call(m)] : m;
487
+ }
488
+ /** The own value of `key` of `m` (not read through its bases). */ function ownValue(m, key) {
489
+ return m instanceof LayerMap ? mapGet.call(m, key) : m.get(key);
490
+ }
491
+ /**
492
+ * `annotate(map, key, value, true)` on a layered map: appends to the own list. For an append
493
+ * key that is the own part of the concatenation; for another list key the own list starts as
494
+ * the value read (as when the node held a copy).
495
+ */ function annotateLayer(m, key, value) {
496
+ if (mapHas.call(m, key)) {
497
+ appendOwn(m, key, mapGet.call(m, key), value);
498
+ return;
499
+ }
500
+ const read = isAppendKey(key) ? void 0 : m.get(key);
501
+ m.set(key, read === void 0 ? [value] : Array.isArray(read) ? [...read, value] : [read, value]);
502
+ }
503
+
504
+ //#endregion
505
+ //#region packages/typescript/src/runtime/stateless-regex.ts
506
+ /**
507
+ * The regex a validator tests with: one whose `test` keeps no state between calls.
508
+ *
509
+ * With the `g` or `y` flag, `RegExp.prototype.test` starts at `lastIndex` and moves it
510
+ * (past a match, or back to 0 after a miss), so one regex object shared by every check of a
511
+ * pattern would accept and reject the same value on alternate calls. The flags are dropped
512
+ * when the regex is compiled, which costs nothing per test: `g` does not change what `test`
513
+ * finds from `lastIndex` 0, and `y` matches only at `lastIndex` 0 — at the start of the
514
+ * value — so it becomes an anchor at the start of the input (`^`, or a look-behind under
515
+ * `m`, where `^` also matches after a line break). Other regexes are returned as they are.
516
+ */ function statelessRegExp(re) {
517
+ if (!re.global && !re.sticky) return re;
518
+ const flags = re.flags.replace(/[gy]/g, "");
519
+ if (!re.sticky) return new RegExp(re.source, flags);
520
+ return new RegExp(`${re.multiline ? "(?<![\\s\\S])" : "^"}(?:${re.source})`, flags);
521
+ }
522
+ /**
523
+ * The source of a pattern written with `flags` as a JSON Schema `pattern` (which has no flags),
524
+ * matching the same strings as the validator's regex:
525
+ *
526
+ * - `s`: every `.` outside a character class becomes `[\s\S]`;
527
+ * - `i`: every character that has case variants becomes a class of them (`a` → `[aA]`,
528
+ * `[a-f]` → `[a-fA-F]`, with `u` also `s` → `[sSſ]`, `\w` → `[\wſK]`); a pattern
529
+ * using what has no flag-free form — a backreference, a Unicode property escape or (with `u`)
530
+ * `\b` / `\B` / `\W` in a class, a range of more than 1024 characters with non-ASCII ones — is
531
+ * also wrapped in a modifier group `(?i:…)`;
532
+ * - `m`: the pattern is wrapped in a modifier group `(?m:…)` (`^` / `$` at line breaks have no
533
+ * flag-free form without look-behinds);
534
+ * - `y`: matches at the start of the value only (see {@link statelessRegExp}): `^(?:…)`;
535
+ * - `g` changes nothing; `u` is the dialect of the pattern (JSON Schema validators commonly compile
536
+ * patterns with it — ajv does).
537
+ *
538
+ * Modifier groups (ES2025) are understood by JavaScript engines from 2024 on (Node.js 23+, V8 12.5+)
539
+ * and by some other regex dialects (.NET, PCRE2, Python 3.6+), not by all.
540
+ */ function jsonSchemaPattern(pattern, flags) {
541
+ if (!flags) return pattern;
542
+ const unicode = flags.includes("u");
543
+ const modifiers = /* @__PURE__ */ new Set();
544
+ let body = pattern;
545
+ if (flags.includes("i") || flags.includes("s")) {
546
+ const translated = translateFlags(pattern, unicode, flags.includes("i"), flags.includes("s"));
547
+ if (translated) {
548
+ body = translated.source;
549
+ if (translated.modifier) modifiers.add("i");
550
+ } else for (const flag of "is") if (flags.includes(flag)) modifiers.add(flag);
551
+ }
552
+ if (flags.includes("m")) modifiers.add("m");
553
+ if (modifiers.size > 0) body = `(?${[...modifiers].sort().join("")}:${body})`;
554
+ return flags.includes("y") ? `^(?:${body})` : body;
555
+ }
556
+ /**
557
+ * Characters case-insensitive matching relates to characters that case mapping does not lead to
558
+ * from them (`k` → `K`, but `K` (U+212A) only folds to `k`): groups closing the search of
559
+ * {@link caseVariants} (the regex engine then keeps those that match).
560
+ */ const FOLD_GROUPS = [
561
+ "kKK",
562
+ "sSſ",
563
+ "ÅåÅ",
564
+ "ßẞ",
565
+ "DŽDždž",
566
+ "LJLjlj",
567
+ "NJNjnj",
568
+ "DZDzdz",
569
+ "ͅΙιι",
570
+ "ΐΐ",
571
+ "Ββϐ",
572
+ "Εεϵ",
573
+ "Θθϑϴ",
574
+ "Κκϰ",
575
+ "µΜμ",
576
+ "Ππϖ",
577
+ "Ρρϱ",
578
+ "Σςσ",
579
+ "Φφϕ",
580
+ "ΩωΩ",
581
+ "ΰΰ",
582
+ "Ввᲀ",
583
+ "Ддᲁ",
584
+ "Ооᲂ",
585
+ "Ссᲃ",
586
+ "Ттᲄᲅ",
587
+ "Ъъᲆ",
588
+ "Ѣѣᲇ",
589
+ "Ṡṡẛ",
590
+ "ᲈꙊꙋ",
591
+ "ſtst",
592
+ ...[
593
+ 8064,
594
+ 8080,
595
+ 8096
596
+ ].flatMap((base) => Array.from({ length: 8 }, (_, k) => String.fromCodePoint(base + k, base + k + 8))),
597
+ "ᾳᾼ",
598
+ "ῃῌ",
599
+ "ῳῼ"
600
+ ];
601
+ let foldGroupOf;
602
+ /** The characters matching `ch` under `i` (with `u`: case folding), `ch` first. */ const variantCache = /* @__PURE__ */ new Map();
603
+ function caseVariants(ch, unicode) {
604
+ const key = `${unicode ? "u" : ""}${ch}`;
605
+ let out = variantCache.get(key);
606
+ if (!out) {
607
+ if (!foldGroupOf) {
608
+ foldGroupOf = /* @__PURE__ */ new Map();
609
+ for (const group of FOLD_GROUPS) for (const member of group) foldGroupOf.set(member, group);
610
+ }
611
+ const single = (x) => unicode ? x.length === String.fromCodePoint(x.codePointAt(0)).length : x.length === 1;
612
+ const found = new Set([ch]);
613
+ const queue = [ch];
614
+ while (queue.length > 0) {
615
+ const x = queue.pop();
616
+ for (const y of [
617
+ x.toLowerCase(),
618
+ x.toUpperCase(),
619
+ ...foldGroupOf.get(x) ?? ""
620
+ ]) if (single(y) && !found.has(y)) {
621
+ found.add(y);
622
+ queue.push(y);
623
+ }
624
+ }
625
+ const re = new RegExp(`^${escapeChar(ch, unicode)}$`, unicode ? "iu" : "i");
626
+ out = [...found].filter((x) => x === ch || re.test(x));
627
+ variantCache.set(key, out);
628
+ }
629
+ return out;
630
+ }
631
+ /** A character as a regex escape (`\uXXXX`, or `\u{…}` with `u` outside the BMP). */ function escapeChar(ch, unicode) {
632
+ const cp = ch.codePointAt(0);
633
+ return cp > 65535 && unicode ? `\\u{${cp.toString(16).toUpperCase()}}` : `\\u${cp.toString(16).toUpperCase().padStart(4, "0")}`;
634
+ }
635
+ /** A character as a member of a character class (escaped where needed). */ function classChar(ch, unicode) {
636
+ const cp = ch.codePointAt(0);
637
+ if (/[\\\][\-^]/.test(ch)) return `\\${ch}`;
638
+ if (cp < 32 || cp > 126) return escapeChar(ch, unicode);
639
+ return ch;
640
+ }
641
+ /** `ch` outside a class, as it matches under `i` (a class of its case variants). */ function caseLiteral(ch, raw, unicode) {
642
+ const variants = caseVariants(ch, unicode);
643
+ return variants.length === 1 ? raw : `[${variants.map((v) => classChar(v, unicode)).join("")}]`;
644
+ }
645
+ /** The ranges of a sorted list of code points, as class members. */ function classRanges(points, unicode) {
646
+ let out = "";
647
+ for (let k = 0; k < points.length;) {
648
+ let end = k;
649
+ while (end + 1 < points.length && points[end + 1] === points[end] + 1) end++;
650
+ const lo = String.fromCodePoint(points[k]);
651
+ const hi = String.fromCodePoint(points[end]);
652
+ out += end === k ? classChar(lo, unicode) : `${classChar(lo, unicode)}-${classChar(hi, unicode)}`;
653
+ k = end + 1;
654
+ }
655
+ return out;
656
+ }
657
+ /** The largest range of non-ASCII characters whose case variants are spelled out. */ const MAX_RANGE = 1024;
658
+ /** What `\w` also matches under `iu` (characters folding to a word character). */ const WORD_FOLDS = "\\u017F\\u212A";
659
+ /**
660
+ * `pattern` with `i` (characters → classes of their case variants) and `s` (`.` → `[\s\S]`)
661
+ * applied (`modifier`: what has no flag-free form, see {@link jsonSchemaPattern}), or
662
+ * `undefined` when it is not parsed.
663
+ */ function translateFlags(pattern, unicode, ignoreCase, dotAll) {
664
+ let out = "";
665
+ let i = 0;
666
+ let modifier = false;
667
+ const n = pattern.length;
668
+ /** The character at `i` (a code point with `u`). */ const charAt = (at) => unicode ? String.fromCodePoint(pattern.codePointAt(at)) : pattern[at];
669
+ /**
670
+ * Reads an escape at `i` (after the backslash): its character (`ch`), or as written (`raw`)
671
+ * with what it needs (`modifier`: no flag-free form under `i`), or `undefined` (not parsed).
672
+ */ const readEscape = (inClass) => {
673
+ const start = i - 1;
674
+ const c = pattern[i];
675
+ if (c === void 0) return;
676
+ i++;
677
+ const raw = () => pattern.slice(start, i);
678
+ switch (c) {
679
+ case "d":
680
+ case "D":
681
+ case "s":
682
+ case "S": return { raw: raw() };
683
+ case "w": return {
684
+ raw: raw(),
685
+ word: true
686
+ };
687
+ case "W": return {
688
+ raw: raw(),
689
+ word: true,
690
+ modifier: inClass && unicode
691
+ };
692
+ case "b": return inClass ? {
693
+ ch: "\b",
694
+ raw: raw()
695
+ } : {
696
+ raw: raw(),
697
+ modifier: unicode
698
+ };
699
+ case "B": return inClass ? void 0 : {
700
+ raw: raw(),
701
+ modifier: unicode
702
+ };
703
+ case "p":
704
+ case "P": {
705
+ if (!unicode) return {
706
+ ch: c,
707
+ raw: raw()
708
+ };
709
+ const end = pattern.indexOf("}", i);
710
+ if (pattern[i] !== "{" || end < 0) return;
711
+ i = end + 1;
712
+ return {
713
+ raw: raw(),
714
+ modifier: true
715
+ };
716
+ }
717
+ case "k": {
718
+ const name = /^<[^>]*>/.exec(pattern.slice(i));
719
+ if (name) {
720
+ i += name[0].length;
721
+ return {
722
+ raw: raw(),
723
+ modifier: true
724
+ };
725
+ }
726
+ return unicode ? void 0 : {
727
+ ch: "k",
728
+ raw: raw()
729
+ };
730
+ }
731
+ case "c": {
732
+ const next = pattern[i];
733
+ if (next && /[A-Za-z]/.test(next)) {
734
+ i++;
735
+ return {
736
+ ch: String.fromCodePoint(next.codePointAt(0) % 32),
737
+ raw: raw()
738
+ };
739
+ }
740
+ return;
741
+ }
742
+ case "x": {
743
+ const hex = pattern.slice(i, i + 2);
744
+ if (!/^[\da-fA-F]{2}$/.test(hex)) return;
745
+ i += 2;
746
+ return {
747
+ ch: String.fromCodePoint(Number.parseInt(hex, 16)),
748
+ raw: raw()
749
+ };
750
+ }
751
+ case "u": {
752
+ if (unicode && pattern[i] === "{") {
753
+ const end = pattern.indexOf("}", i);
754
+ if (end < 0) return;
755
+ const cp = Number.parseInt(pattern.slice(i + 1, end), 16);
756
+ i = end + 1;
757
+ return {
758
+ ch: String.fromCodePoint(cp),
759
+ raw: raw()
760
+ };
761
+ }
762
+ const hex = pattern.slice(i, i + 4);
763
+ if (!/^[\da-fA-F]{4}$/.test(hex)) return;
764
+ i += 4;
765
+ let code = Number.parseInt(hex, 16);
766
+ if (unicode && code >= 55296 && code <= 56319) {
767
+ const low = /^\\u([dD][c-fC-F][\da-fA-F]{2})/.exec(pattern.slice(i));
768
+ if (low) {
769
+ i += 6;
770
+ code = 65536 + (code - 55296 << 10) + (Number.parseInt(low[1], 16) - 56320);
771
+ }
772
+ }
773
+ return {
774
+ ch: String.fromCodePoint(code),
775
+ raw: raw()
776
+ };
777
+ }
778
+ case "0": return /\d/.test(pattern[i] ?? "") ? void 0 : {
779
+ ch: "\0",
780
+ raw: raw()
781
+ };
782
+ case "f":
783
+ case "n":
784
+ case "r":
785
+ case "t":
786
+ case "v": return {
787
+ ch: {
788
+ f: "\f",
789
+ n: "\n",
790
+ r: "\r",
791
+ t: " ",
792
+ v: "\v"
793
+ }[c],
794
+ raw: raw()
795
+ };
796
+ default: {
797
+ if (/[1-9]/.test(c)) {
798
+ if (unicode || !inClass) {
799
+ while (/\d/.test(pattern[i] ?? "")) i++;
800
+ return inClass ? void 0 : {
801
+ raw: raw(),
802
+ modifier: true
803
+ };
804
+ }
805
+ return;
806
+ }
807
+ i = start + 1;
808
+ const ch = charAt(i);
809
+ i += ch.length;
810
+ return {
811
+ ch,
812
+ raw: raw()
813
+ };
814
+ }
815
+ }
816
+ };
817
+ /** Reads a character class at `i` (`[…]`), its characters with their case variants. */ const readClass = () => {
818
+ const start = i;
819
+ i++;
820
+ let negated = "";
821
+ if (pattern[i] === "^") {
822
+ negated = "^";
823
+ i++;
824
+ }
825
+ const items = [];
826
+ while (i < n && pattern[i] !== "]") {
827
+ if (pattern[i] === "\\") {
828
+ i++;
829
+ const esc = readEscape(true);
830
+ if (!esc) return;
831
+ modifier || (modifier = !!esc.modifier && ignoreCase);
832
+ items.push(esc.ch === void 0 ? {
833
+ raw: esc.raw,
834
+ word: esc.word
835
+ } : { ch: esc.ch });
836
+ continue;
837
+ }
838
+ const ch = charAt(i);
839
+ i += ch.length;
840
+ items.push(ch === "-" ? { dash: true } : { ch });
841
+ }
842
+ if (i >= n) return;
843
+ i++;
844
+ if (!ignoreCase) return pattern.slice(start, i);
845
+ const points = /* @__PURE__ */ new Set();
846
+ let body = "";
847
+ const addChar = (ch) => {
848
+ for (const v of caseVariants(ch, unicode)) points.add(v.codePointAt(0));
849
+ };
850
+ for (let k = 0; k < items.length; k++) {
851
+ const item = items[k];
852
+ const dash = items[k + 1];
853
+ const hi = items[k + 2];
854
+ if ("ch" in item && dash && "dash" in dash && hi && "ch" in hi) {
855
+ const lo = item.ch.codePointAt(0);
856
+ const top = hi.ch.codePointAt(0);
857
+ if (top > 127 && top - lo >= MAX_RANGE) {
858
+ modifier = true;
859
+ body += `${classChar(item.ch, unicode)}-${classChar(hi.ch, unicode)}`;
860
+ } else for (let cp = lo; cp <= top; cp++) addChar(String.fromCodePoint(cp));
861
+ k += 2;
862
+ continue;
863
+ }
864
+ if ("dash" in item) points.add(45);
865
+ else if ("raw" in item) {
866
+ body += item.raw;
867
+ if (item.word && unicode && item.raw === "\\w") body += WORD_FOLDS;
868
+ } else addChar(item.ch);
869
+ }
870
+ body += classRanges([...points].sort((a, b) => a - b), unicode);
871
+ return `[${negated}${body}]`;
872
+ };
873
+ while (i < n) {
874
+ const c = pattern[i];
875
+ if (c === "\\") {
876
+ i++;
877
+ const esc = readEscape(false);
878
+ if (!esc) return;
879
+ if (!ignoreCase) out += esc.raw;
880
+ else if (esc.ch !== void 0) out += caseLiteral(esc.ch, esc.raw, unicode);
881
+ else {
882
+ modifier || (modifier = !!esc.modifier);
883
+ out += esc.word && unicode ? esc.raw === "\\w" ? `[\\w${WORD_FOLDS}]` : `[^\\w${WORD_FOLDS}]` : esc.raw;
884
+ }
885
+ continue;
886
+ }
887
+ if (c === "[") {
888
+ const cls = readClass();
889
+ if (cls === void 0) return;
890
+ out += cls;
891
+ continue;
892
+ }
893
+ if (c === "(") {
894
+ if (pattern[i + 1] === "?") {
895
+ const header = /^\(\?(?::|=|!|<=|<!|<[^>]+>)/.exec(pattern.slice(i));
896
+ if (!header) return;
897
+ out += header[0];
898
+ i += header[0].length;
899
+ continue;
900
+ }
901
+ out += c;
902
+ i++;
903
+ continue;
904
+ }
905
+ if (c === "{") {
906
+ const quantifier = /^\{\d+(?:,\d*)?\}/.exec(pattern.slice(i));
907
+ if (quantifier) {
908
+ out += quantifier[0];
909
+ i += quantifier[0].length;
910
+ continue;
911
+ }
912
+ }
913
+ if (c === "." && dotAll) {
914
+ out += "[\\s\\S]";
915
+ i++;
916
+ continue;
917
+ }
918
+ const ch = charAt(i);
919
+ i += ch.length;
920
+ out += ignoreCase && !"^$|)*+?.]}{".includes(ch) ? caseLiteral(ch, ch, unicode) : ch;
921
+ }
922
+ return {
923
+ source: out,
924
+ modifier
925
+ };
926
+ }
927
+
928
+ //#endregion
929
+ //#region packages/typescript/src/runtime/compiled-check/layout.ts
930
+ /**
931
+ * Layout of a compiled validator check: the structure a check was compiled for, as plain
932
+ * data. `buildLayout` (build-layout.ts) derives it from a type tree (the build-time model
933
+ * of a generated module, or a live tree in tests); the binder (registry.ts) verifies a
934
+ * live tree against it and collects the constraint values the compiled code reads into
935
+ * the K slots.
936
+ *
937
+ * ```
938
+ * Layout = [defs: Def[], root: Site, slotCount]
939
+ * Site = [optional: 0|1, keyMask, def: number | EXT | INTERP, patternShape, slot]
940
+ * Def = [FINAL, designType] | [FINAL, designType, literal]
941
+ * | [OBJECT, keys, sites] | [OBJECT_PATTERNS]
942
+ * | [ARRAY, of] | [UNION | INTERSECTION | TUPLE, items] | [UNKNOWN, kind]
943
+ * ```
944
+ * - A site is one annotated-type node (a class root, prop, array element, union / tuple /
945
+ * intersection item). A def is one type-def object: sites sharing a def index share the
946
+ * def object (by identity) at runtime, which is how shared and recursive types are
947
+ * compiled once.
948
+ * - `keyMask` has a bit (by {@link VALIDATOR_KEYS} index) per validator annotation that is
949
+ * *effective* on the node and relevant to its def (present; flags: truthy).
950
+ * `patternShape` has one char per `@expect.pattern` entry: `e` (empty, skipped),
951
+ * `n` (checked).
952
+ * - `slot`: the site's first K slot (see {@link siteSlotCount}); `slotCount` is the total.
953
+ * - `EXT`: an anonymous reference into another module's type; bound to that type's own
954
+ * compiled check (as a template, against the referring node) when it has one, else
955
+ * checked by the interpreted pre-check.
956
+ * - `INTERP`: a node only known at runtime (e.g. a chained reference into another module's
957
+ * type): always checked by the interpreted pre-check.
958
+ */
959
+ /**
960
+ * Layout format version, also of the emitted checks' contract with the runtime (5: 'strip'
961
+ * records `object, key` pairs at every depth); checks of another version are ignored
962
+ * (interpreted).
963
+ */ const LAYOUT_VERSION = 5;
964
+ const EXT = -1;
965
+ const INTERP = -2;
966
+ const D_FINAL = 0;
967
+ const D_OBJECT = 1;
968
+ const D_ARRAY = 2;
969
+ const D_UNION = 3;
970
+ const D_INTERSECTION = 4;
971
+ const D_TUPLE = 5;
972
+ const D_UNKNOWN = 6;
973
+ const D_OBJECT_PATTERNS = 7;
974
+ /** Kind names of the def codes with `items`. */ const ITEMS_KIND_NAMES = {
975
+ [D_UNION]: "union",
976
+ [D_INTERSECTION]: "intersection",
977
+ [D_TUPLE]: "tuple"
978
+ };
979
+ const F_ERROR = 4;
980
+ const F_STRIP = 8;
981
+ const F_PARTIAL_DEEP = 16;
982
+ const F_PARTIAL_TOP = 32;
983
+ /** Key mask bit of a validator annotation. */ function bit(key) {
984
+ return 1 << VALIDATOR_KEYS.indexOf(key);
985
+ }
986
+ function bitsOf(keys) {
987
+ let bits = 0;
988
+ for (const key of keys) bits |= bit(key);
989
+ return bits;
990
+ }
991
+ const B_REQUIRED = bit("meta.required");
992
+ const B_MIN_LENGTH = bit("expect.minLength");
993
+ const B_MAX_LENGTH = bit("expect.maxLength");
994
+ const B_PATTERN = bit("expect.pattern");
995
+ const B_INT = bit("expect.int");
996
+ const B_MIN = bit("expect.min");
997
+ const B_MAX = bit("expect.max");
998
+ const B_EX_MIN = bit("expect.exclusiveMin");
999
+ const B_EX_MAX = bit("expect.exclusiveMax");
1000
+ const B_UNIQUE = bit("expect.array.uniqueItems");
1001
+ /** Annotations the pre-check reads per kind of value (see validator-keys.ts). */ const STRING_BITS = bitsOf(STRING_KEYS);
1002
+ const NUMBER_BITS = bitsOf(NUMBER_KEYS);
1003
+ const ARRAY_BITS = bitsOf(ARRAY_KEYS);
1004
+ const BOOLEAN_BITS = bitsOf(BOOLEAN_KEYS);
1005
+ /** Keys whose value the compiled code reads (one K slot each). */ const VALUE_BITS = B_MIN_LENGTH | B_MAX_LENGTH | B_MIN | B_MAX | B_EX_MIN | B_EX_MAX;
1006
+ const FLAG_BITS = B_REQUIRED | B_INT | B_UNIQUE;
1007
+ const ALL_BITS = (1 << VALIDATOR_KEYS.length) - 1;
1008
+ /** The field holding the bound of each value key's object form. */ const BOUND_FIELDS = {
1009
+ [B_MIN_LENGTH]: "length",
1010
+ [B_MAX_LENGTH]: "length",
1011
+ [B_MIN]: "minValue",
1012
+ [B_MAX]: "maxValue",
1013
+ [B_EX_MIN]: "exclusiveMinValue",
1014
+ [B_EX_MAX]: "exclusiveMaxValue"
1015
+ };
1016
+ /**
1017
+ * Validator annotations the pre-check reads for a node of this type def (the rest of the
1018
+ * node's annotations cannot change its outcome, so they are not part of the layout).
1019
+ */ function relevantBits(type) {
1020
+ switch (type.kind) {
1021
+ case "":
1022
+ if (type.designType === "phantom" || type.value !== void 0) return 0;
1023
+ switch (type.designType) {
1024
+ case "string": return STRING_BITS;
1025
+ case "number": return NUMBER_BITS;
1026
+ case "boolean": return BOOLEAN_BITS;
1027
+ default: return 0;
1028
+ }
1029
+ case "array": return ARRAY_BITS;
1030
+ case "union": return ALL_BITS;
1031
+ default: return 0;
1032
+ }
1033
+ }
1034
+ /**
1035
+ * {@link relevantBits} of a site (`undefined`: a type only known at runtime);
1036
+ * `meta.required` also matters on any optional node.
1037
+ */ function siteBits(type, optional) {
1038
+ return (type === void 0 ? 0 : relevantBits(type)) | (optional ? B_REQUIRED : 0);
1039
+ }
1040
+ /** An optional node with `@meta.required`: `null` fails unless its type accepts `null`. */ function hasRejectSlot(site) {
1041
+ return site[0] === 1 && (site[1] & B_REQUIRED) !== 0;
1042
+ }
1043
+ /**
1044
+ * Computes a node's key mask and pattern shape over `relevant` bits, and — when `out` is
1045
+ * given — writes the normalised annotation values from `out[at]` on (the K slots).
1046
+ * Throws on annotation values the pre-check itself would throw on (the bind then fails
1047
+ * and the interpreted pre-check runs, which reproduces that behaviour).
1048
+ */ function readKeys(metadata, relevant, reader, out, at = 0) {
1049
+ let mask = 0;
1050
+ let shape = "";
1051
+ let k = at;
1052
+ const meta = filledMeta(metadata);
1053
+ if (meta === void 0) return {
1054
+ mask,
1055
+ shape
1056
+ };
1057
+ for (let i = 0; i < VALIDATOR_KEYS.length; i++) {
1058
+ const b = 1 << i;
1059
+ if ((relevant & b) === 0) continue;
1060
+ const raw = meta.get(VALIDATOR_KEYS[i]);
1061
+ if ((b & FLAG_BITS) !== 0) {
1062
+ if (raw) mask |= b;
1063
+ continue;
1064
+ }
1065
+ if (b === B_PATTERN) {
1066
+ if (!raw) continue;
1067
+ if (!Array.isArray(raw)) throw new TypeError("expect.pattern is not an array");
1068
+ mask |= b;
1069
+ for (const entry of raw) {
1070
+ const { pattern, flags } = entry;
1071
+ if (!pattern) {
1072
+ shape += "e";
1073
+ continue;
1074
+ }
1075
+ const re = reader.regex(pattern, flags);
1076
+ shape += "n";
1077
+ if (out) out[k] = re;
1078
+ k++;
1079
+ }
1080
+ continue;
1081
+ }
1082
+ if (raw === void 0) continue;
1083
+ mask |= b;
1084
+ if (out) out[k] = boundOf(raw, BOUND_FIELDS[b]);
1085
+ k++;
1086
+ }
1087
+ return {
1088
+ mask,
1089
+ shape
1090
+ };
1091
+ }
1092
+
1093
+ //#endregion
1094
+ //#region packages/typescript/src/runtime/compiled-check/registry.ts
1095
+ /**
1096
+ * Runtime registry and binder of build-time compiled validator checks.
1097
+ *
1098
+ * Generated `.as.js` modules (built with `tsPlugin({ compileValidators: true })`) call
1099
+ * {@link registerCompiledCheck} once per class with the class's layout and a factory of
1100
+ * its check. On first use, and again after each mutation epoch (see tracking.ts), the
1101
+ * entry is bound: `bindLayout` verifies the live type tree against the layout and collects
1102
+ * the constraint values into `K`; the factory turns `K` into the check function. A tree
1103
+ * that no longer matches leaves the entry unbound for that epoch, so the interpreted
1104
+ * pre-check runs instead — always correct, never stale.
1105
+ *
1106
+ * A registered entry is also a template: a node referencing a class of another module
1107
+ * (an `EXT` site) binds that class's layout against itself — its own annotations feed `K`
1108
+ * — so cross-module references, aliases of imported types and their derived props run
1109
+ * compiled code whenever their tree matches the referenced type's structure.
1110
+ *
1111
+ * The registry is module-local: classes registered with another copy of this runtime
1112
+ * (dual ESM / CJS loads, duplicate installs) and subclasses of registered classes are
1113
+ * simply validated by the interpreted pre-check.
1114
+ */
1115
+ /** Entries by class (own registrations only: a subclass is not registered). */ const entries = /* @__PURE__ */ new WeakMap();
1116
+ /** Template bindings by referring node. */ const templates = /* @__PURE__ */ new WeakMap();
1117
+ /** Some compiled check is registered (until then lookups return at once). */ let anyCompiled = false;
1118
+ /** The option bits of `opts` for a compiled check's `flags` argument. */ function optionFlags(opts) {
1119
+ const unknownProps = opts.unknownProps;
1120
+ const partial = opts.partial;
1121
+ return (unknownProps === "error" ? F_ERROR : unknownProps === "strip" ? F_STRIP : 0) | (partial === "deep" ? F_PARTIAL_DEEP : partial === true ? F_PARTIAL_TOP : 0);
1122
+ }
1123
+ /**
1124
+ * Registers the build-time compiled validator check of a generated class (emitted into
1125
+ * `.as.js` by `tsPlugin({ compileValidators: true })`; not meant to be called by hand).
1126
+ * A layout of another format version is ignored, so the class stays interpreted.
1127
+ */ function registerCompiledCheck(cls, version, layout, factory) {
1128
+ if (version !== LAYOUT_VERSION) return;
1129
+ entries.set(cls, {
1130
+ layout,
1131
+ factory,
1132
+ epoch: -1,
1133
+ fn: null,
1134
+ binding: false
1135
+ });
1136
+ anyCompiled = true;
1137
+ }
1138
+ let autoCompile = null;
1139
+ /** The compiled check to run for `def` in this call, or `null` (interpreted). */ function compiledCheckFor(def, env) {
1140
+ if (!anyCompiled) return null;
1141
+ let entry = entries.get(def);
1142
+ if (entry === void 0) {
1143
+ if (autoCompile === null) return null;
1144
+ autoCompile(def);
1145
+ entry = entries.get(def);
1146
+ if (entry === void 0) return null;
1147
+ }
1148
+ return entry.epoch === currentEpoch() ? entry.fn : bind(entry, entry, def, env, false);
1149
+ }
1150
+ /** (Re)binds `entry`'s layout against `node` for the current epoch. */ function bind(binding, entry, node, env, template) {
1151
+ binding.epoch = currentEpoch();
1152
+ binding.fn = null;
1153
+ binding.binding = true;
1154
+ try {
1155
+ const K = bindLayout(entry.layout, node, env, template);
1156
+ if (K !== void 0) binding.fn = entry.factory(K, env);
1157
+ } catch {} finally {
1158
+ binding.binding = false;
1159
+ }
1160
+ return binding.fn;
1161
+ }
1162
+ /**
1163
+ * Verifies the live tree of `node` against `layout` and collects the K slots; `undefined`
1164
+ * when anything differs. A `template` bind (a node referring to the layout's class) leaves
1165
+ * the root's `optional` to the referring site.
1166
+ */ function bindLayout(layout, node, env, template) {
1167
+ const [defs, root, slotCount] = layout;
1168
+ const bound = [];
1169
+ const K = [];
1170
+ K.length = slotCount;
1171
+ /** An EXT / INTERP site: its check, then whether its type is a literal. */ const bindRuntimeSite = (n, at, ext) => {
1172
+ const type = n.type;
1173
+ if (typeof type !== "object" || type === null || isPhantomType(n)) return false;
1174
+ watch(n);
1175
+ watch(type);
1176
+ K[at] = ext ? externalCheck(n, env) : interpreted(n, env);
1177
+ K[at + 1] = type.value !== void 0;
1178
+ return true;
1179
+ };
1180
+ const bindSite = (site, n) => {
1181
+ const [optional, mask, d, shape, at] = site;
1182
+ if (d === INTERP) return bindRuntimeSite(n, at, false);
1183
+ if (template && site === root ? optional !== 0 : !!n.optional !== (optional === 1)) return false;
1184
+ watch(n);
1185
+ const metadata = n.metadata;
1186
+ if (!(metadata instanceof AnnotationMap)) return false;
1187
+ if (!watchLayer(metadata)) return false;
1188
+ let k = at;
1189
+ if (hasRejectSlot(site)) K[k++] = n;
1190
+ if (d === EXT) return readKeys(metadata, siteBits(void 0, optional === 1), env).mask === mask && bindRuntimeSite(n, k, true);
1191
+ const type = n.type;
1192
+ if (bound[d] === void 0) {
1193
+ if (typeof type !== "object" || type === null) return false;
1194
+ bound[d] = type;
1195
+ if (!bindDef(defs[d], type)) return false;
1196
+ } else if (bound[d] !== type) return false;
1197
+ const read = readKeys(metadata, siteBits(type, optional === 1), env, K, k);
1198
+ return read.mask === mask && read.shape === shape;
1199
+ };
1200
+ const bindSites = (sites, nodes) => {
1201
+ if (!Array.isArray(nodes) || nodes.length !== sites.length) return false;
1202
+ for (let i = 0; i < sites.length; i++) if (!bindSite(sites[i], nodes[i])) return false;
1203
+ return true;
1204
+ };
1205
+ const bindDef = (def, type) => {
1206
+ watch(type);
1207
+ switch (def[0]) {
1208
+ case D_FINAL: return type.kind === "" && type.designType === def[1] && (def.length === 2 ? type.value === void 0 : type.value === def[2]);
1209
+ case D_OBJECT: {
1210
+ const props = type.props;
1211
+ if (type.kind !== "object" || !(props instanceof PropsMap) || !Array.isArray(type.propsPatterns) || type.propsPatterns.length > 0) return false;
1212
+ watch(props);
1213
+ const keys = def[1];
1214
+ const sites = def[2];
1215
+ if (props.size !== keys.length) return false;
1216
+ let i = 0;
1217
+ for (const [key, prop] of props) {
1218
+ if (key !== keys[i] || !bindSite(sites[i], prop)) return false;
1219
+ i++;
1220
+ }
1221
+ return true;
1222
+ }
1223
+ case D_OBJECT_PATTERNS: return type.kind === "object" && Array.isArray(type.propsPatterns) && type.propsPatterns.length > 0;
1224
+ case D_ARRAY: return type.kind === "array" && bindSite(def[1], type.of);
1225
+ case D_UNION:
1226
+ case D_INTERSECTION:
1227
+ case D_TUPLE: return type.kind === ITEMS_KIND_NAMES[def[0]] && bindSites(def[1], type.items);
1228
+ case D_UNKNOWN: return type.kind === def[1];
1229
+ default: return false;
1230
+ }
1231
+ };
1232
+ return bindSite(root, node) ? K : void 0;
1233
+ }
1234
+ /** The interpreted pre-check of `node` (its subtree is read live on every call). */ function interpreted(node, env) {
1235
+ const interp = env.interp;
1236
+ return (value, flags, opts) => interp(node, value, flags, opts);
1237
+ }
1238
+ /**
1239
+ * The check of a node referencing another module's type (called for a non-nullish value
1240
+ * when the node is optional; the referring site handles `optional`): the referenced class's
1241
+ * layout bound against the node when it matches, else the interpreted pre-check.
1242
+ */ function externalCheck(node, env) {
1243
+ const own = entries.get(node);
1244
+ if (own !== void 0) {
1245
+ if (own.binding) {
1246
+ const fallback = interpreted(node, env);
1247
+ return (value, flags, opts) => (own.fn ?? fallback)(value, flags, opts);
1248
+ }
1249
+ const fn = own.epoch === currentEpoch() ? own.fn : bind(own, own, node, env, false);
1250
+ if (fn !== null) return fn;
1251
+ return interpreted(node, env);
1252
+ }
1253
+ const entry = templateOf(node);
1254
+ if (entry !== void 0) {
1255
+ let binding = templates.get(node);
1256
+ if (binding === void 0 || binding.entry !== entry) {
1257
+ binding = {
1258
+ entry,
1259
+ epoch: -1,
1260
+ fn: null,
1261
+ binding: false
1262
+ };
1263
+ templates.set(node, binding);
1264
+ }
1265
+ if (binding.binding) {
1266
+ const pending = binding;
1267
+ const fallback = interpreted(node, env);
1268
+ return (value, flags, opts) => (pending.fn ?? fallback)(value, flags, opts);
1269
+ }
1270
+ const fn = binding.epoch === currentEpoch() ? binding.fn : bind(binding, entry, node, env, true);
1271
+ if (fn !== null) return fn;
1272
+ }
1273
+ return interpreted(node, env);
1274
+ }
1275
+ /**
1276
+ * The registered class whose layout a referring node binds against: the target of its
1277
+ * (unchained) reference, through aliases of other modules' types.
1278
+ */ function templateOf(node) {
1279
+ let ref = node.ref;
1280
+ for (const seen = /* @__PURE__ */ new Set(); ref !== void 0 && ref.field === "" && !seen.has(ref);) {
1281
+ seen.add(ref);
1282
+ let target;
1283
+ try {
1284
+ target = ref.type();
1285
+ } catch {
1286
+ return;
1287
+ }
1288
+ const entry = entries.get(target);
1289
+ if (entry === void 0 || entry.layout[1][2] !== EXT) return entry;
1290
+ ref = target.ref;
1291
+ }
1292
+ }
1293
+
1294
+ //#endregion
1295
+ //#region packages/typescript/src/runtime/validator-fast-check.ts
1296
+ function _define_property$1(obj, key, value) {
1297
+ if (key in obj) Object.defineProperty(obj, key, {
1298
+ value,
1299
+ enumerable: true,
1300
+ configurable: true,
1301
+ writable: true
1302
+ });
1303
+ else obj[key] = value;
1304
+ return obj;
1305
+ }
1306
+ /**
1307
+ * Allocation-free boolean pre-check used by {@link Validator.validate} before the
1308
+ * error-collecting walk.
1309
+ *
1310
+ * Nodes are checked by the generic functions below, which read the type tree and metadata
1311
+ * LIVE on every visit. Array items — the same type visited many times per call — go
1312
+ * through a compiled {@link Plan} of the item type instead (cached per node, shared by every
1313
+ * validator and option set). A plan snapshots what its node's check reads and re-verifies
1314
+ * every snapshot against the live node lazily, once per call, right before first using it
1315
+ * (rebuilding it when anything differs); constraint objects and pattern arrays are read
1316
+ * live on every visit. Either way `annotate()` / `metadata.set()` / prop mutations made
1317
+ * after a validator was created are always honoured — the same as the full walk.
1318
+ *
1319
+ * Result contract (relative to the full walk over the same node and value):
1320
+ * - `PASS` — the walk returns `true`, collects no errors and records the strips recorded
1321
+ * here (see below).
1322
+ * - `FAIL` — the walk returns `false`. Inside a union, every node the walk would visit
1323
+ * was visited here too (so a walk that would throw makes this throw first). Outside unions
1324
+ * a `FAIL` always ends in the walk, so it may be returned early.
1325
+ * - `BAIL` — not decidable here; the caller must run the full walk.
1326
+ *
1327
+ * Union branches are tried in declared order, continuing past `FAIL` and stopping
1328
+ * at `BAIL`, which keeps union results identical to the walk.
1329
+ *
1330
+ * `unknownProps: 'strip'`: like the walk, this check records the unknown keys of each object
1331
+ * that passes (`pendingStrips`, in the order the objects complete), drops what a rejected union
1332
+ * branch recorded, and deletes the keys only when the whole value passes. Neither reads a
1333
+ * stripped input, so a `PASS` performs exactly the walk's deletions and `FAIL` / `BAIL` leave
1334
+ * the value untouched for the walk.
1335
+ */ const FAIL = 0;
1336
+ const PASS = 1;
1337
+ const BAIL = 2;
1338
+ /** Node is at walk depth 0 (only object props / array & tuple items increase depth). */ const TOP = 1;
1339
+ /** Node is inside a union branch — failures must be exhaustive (see contract). */ const IN_UNION = 2;
1340
+ /**
1341
+ * Wasted union branches (see {@link unionWaste}) after which a call memoizes nested unions: a
1342
+ * union nested in its own branches, many branches each, is checked again from every branch of
1343
+ * every union above it — (branches)^(depth) work. Ordinary unions waste a few branches at most;
1344
+ * the memo would cost them more than it saves.
1345
+ */ const WASTE_BEFORE_MEMO = 16;
1346
+ /** Incremented per {@link fastCheckPasses} call; snapshots verified in older calls re-verify. */ let stamp = 0;
1347
+ /** A 'strip' {@link fastCheckPasses} call is in progress (the pending strips below are its own). */ let stripping = false;
1348
+ /**
1349
+ * The unknown keys the walk would delete (`unknownProps: 'strip'`): `object, key, …` in the
1350
+ * walk's deletion order. Deleted when the call passes, dropped otherwise.
1351
+ */ const pendingStrips = [];
1352
+ /**
1353
+ * `true` only when the full walk over `value` is guaranteed to pass with no errors and
1354
+ * no side effects other than its 'strip' deletions, which are then performed here, as the
1355
+ * walk would. Any other outcome (including a throw) leaves `value` untouched and means
1356
+ * "run the walk".
1357
+ */ function fastCheckPasses(def, value, opts) {
1358
+ if (opts.unknownProps === "strip") return fastCheckStripping(def, value, opts);
1359
+ stamp++;
1360
+ if (COMPILED_ENV.m !== void 0) COMPILED_ENV.m = void 0;
1361
+ let passed;
1362
+ try {
1363
+ passed = check(def, value, opts) === PASS;
1364
+ } catch {
1365
+ passed = false;
1366
+ }
1367
+ if (COMPILED_ENV.m !== void 0) COMPILED_ENV.m = void 0;
1368
+ return passed;
1369
+ }
1370
+ /** {@link fastCheckPasses} for `unknownProps: 'strip'`: performs the recorded strips on a pass. */ function fastCheckStripping(def, value, opts) {
1371
+ if (stripping) return false;
1372
+ stamp++;
1373
+ stripping = true;
1374
+ if (COMPILED_ENV.m !== void 0) COMPILED_ENV.m = void 0;
1375
+ let passed;
1376
+ try {
1377
+ passed = check(def, value, opts) === PASS;
1378
+ } catch {
1379
+ passed = false;
1380
+ } finally {
1381
+ stripping = false;
1382
+ }
1383
+ if (COMPILED_ENV.m !== void 0) COMPILED_ENV.m = void 0;
1384
+ performStrips(pendingStrips, passed);
1385
+ return passed;
1386
+ }
1387
+ /**
1388
+ * Deletes the recorded unknown keys (`unknownProps: 'strip'`; `object, key, …` in deletion order)
1389
+ * when the call `passed`, and empties the list either way. Shared by the walk and the pre-check:
1390
+ * the same deletes in the same order (a failing `delete`, e.g. of a frozen object's key, throws
1391
+ * at the same key).
1392
+ */ function performStrips(strips, passed) {
1393
+ try {
1394
+ if (passed) for (let i = 0; i < strips.length; i += 2) delete strips[i][strips[i + 1]];
1395
+ } finally {
1396
+ strips.length = 0;
1397
+ }
1398
+ }
1399
+ /** The strips `list` recorded after its first `kept` entries (a union's own), or `undefined`. */ function stripsSince(list, kept) {
1400
+ return list.length > kept ? list.slice(kept) : void 0;
1401
+ }
1402
+ /** Records in `target` again the strips a memoized union recorded (see {@link stripsSince}). */ function stripAgain(target, strips) {
1403
+ if (strips !== void 0) for (const entry of strips) target.push(entry);
1404
+ }
1405
+ /**
1406
+ * The pre-check of the root: the type's build-time compiled check when it has one bound to
1407
+ * the live tree (see compiled-check/registry.ts), else the interpreted one. Both share the
1408
+ * contract above and the strip state.
1409
+ */ function check(def, value, opts) {
1410
+ const compiled = compiledCheckFor(def, COMPILED_ENV);
1411
+ return compiled === null ? fastCheck(def, value, TOP, opts) : compiled(value, TOP | optionFlags(opts), opts);
1412
+ }
1413
+ const regexCache = /* @__PURE__ */ new Map();
1414
+ /**
1415
+ * Compiled `@expect.pattern` regex, cached per (pattern, flags). Compiled without the
1416
+ * stateful `g` / `y` flags (see {@link statelessRegExp}): every engine tests with it, and
1417
+ * gets the same result on every call.
1418
+ */ function getRegex(pattern, flags) {
1419
+ let byFlags = regexCache.get(pattern);
1420
+ if (!byFlags) {
1421
+ byFlags = /* @__PURE__ */ new Map();
1422
+ regexCache.set(pattern, byFlags);
1423
+ }
1424
+ const flagsKey = flags || "";
1425
+ let regex = byFlags.get(flagsKey);
1426
+ if (!regex) {
1427
+ regex = statelessRegExp(new RegExp(pattern, flags));
1428
+ byFlags.set(flagsKey, regex);
1429
+ }
1430
+ return regex;
1431
+ }
1432
+ /**
1433
+ * `true` when `def` (an optional field holding `null`) carries `@meta.required` and its
1434
+ * type does not itself accept `null`. Shared by the walk and the fast pre-check.
1435
+ */ function rejectsNullAsRequired(def) {
1436
+ const metadata = filledMeta(def.metadata);
1437
+ return metadata !== void 0 && !!metadata.get("meta.required") && !acceptsNull(def);
1438
+ }
1439
+ function acceptsNull(def) {
1440
+ const type = def.type;
1441
+ if (type.kind === "") {
1442
+ const designType = type.designType;
1443
+ return designType === "null" || designType === "any";
1444
+ }
1445
+ if (type.kind === "union") {
1446
+ for (const item of type.items) if (item.optional || acceptsNull(item)) return true;
1447
+ }
1448
+ return false;
1449
+ }
1450
+ /** What compiled checks share with the interpreted pre-check. */ const COMPILED_ENV = {
1451
+ pk: pendingStrips,
1452
+ ho: Object.prototype.hasOwnProperty,
1453
+ dec: DECIMAL_RE,
1454
+ regex: getRegex,
1455
+ interp: fastCheck,
1456
+ rn: rejectsNullAsRequired,
1457
+ m: void 0,
1458
+ n: 0,
1459
+ w: 0,
1460
+ wa: unionWaste,
1461
+ mg: memoGet,
1462
+ ms: memoSet
1463
+ };
1464
+ /**
1465
+ * A union branch failed after branches of nested unions over objects did (`COMPILED_ENV.n`, the
1466
+ * failed branches of unions over objects inside union branches, moved): work
1467
+ * a later branch of the same outermost union may do again. Past {@link WASTE_BEFORE_MEMO} wasted
1468
+ * branches since the outermost union was entered, the call memoizes the unions over objects it
1469
+ * checks inside union branches (`memoGet` / `memoSet`): each such union is then decided once per
1470
+ * value, flags and options — the same result (a pre-check outcome depends on nothing else: the
1471
+ * input is not changed during the call, see the contract above) and the same strips, recorded
1472
+ * again on a reuse.
1473
+ */ function unionWaste() {
1474
+ if (++COMPILED_ENV.w === WASTE_BEFORE_MEMO && COMPILED_ENV.m === void 0) COMPILED_ENV.m = /* @__PURE__ */ new Map();
1475
+ }
1476
+ /**
1477
+ * The outcome memoized for union `key` (a node, or a compiled union's key) over `value`, or -1;
1478
+ * records the strips the union recorded when it was decided.
1479
+ */ function memoGet(key, value, flags, opts) {
1480
+ const entries = COMPILED_ENV.m.get(value);
1481
+ if (entries !== void 0) {
1482
+ for (let i = 0; i < entries.length; i += 5) if (entries[i] === key && entries[i + 1] === flags && entries[i + 2] === opts) {
1483
+ stripAgain(pendingStrips, entries[i + 4]);
1484
+ return entries[i + 3];
1485
+ }
1486
+ }
1487
+ return -1;
1488
+ }
1489
+ /**
1490
+ * Memoizes the outcome of union `key` over `value` (see {@link memoGet}), entered with `kept`
1491
+ * pending strips (the ones after them are its own).
1492
+ */ function memoSet(key, value, flags, opts, result, kept) {
1493
+ const memo = COMPILED_ENV.m;
1494
+ const strips = stripsSince(pendingStrips, kept);
1495
+ const entries = memo.get(value);
1496
+ if (entries === void 0) memo.set(value, [
1497
+ key,
1498
+ flags,
1499
+ opts,
1500
+ result,
1501
+ strips
1502
+ ]);
1503
+ else entries.push(key, flags, opts, result, strips);
1504
+ }
1505
+ /**
1506
+ * The `fastCheck` union case: branches in declared order (see the contract above). A union over
1507
+ * an object inside a union branch counts its failed branches and, once the call made the memo,
1508
+ * is decided once (see `unionWaste`).
1509
+ */ function fastCheckUnion(def, value, flags, opts) {
1510
+ let nested = false;
1511
+ if ((flags & IN_UNION) === 0) COMPILED_ENV.w = 0;
1512
+ else if (typeof value === "object" && value !== null) {
1513
+ if (COMPILED_ENV.m !== void 0) return memoizedUnion(def, value, flags, opts);
1514
+ nested = true;
1515
+ }
1516
+ const branchFlags = flags | IN_UNION;
1517
+ const kept = pendingStrips.length;
1518
+ for (const item of def.type.items) {
1519
+ const failures = COMPILED_ENV.n;
1520
+ const result = fastCheck(item, value, branchFlags, opts);
1521
+ if (result !== FAIL) return unionMatchResult(result, item, def.metadata, value);
1522
+ if (COMPILED_ENV.n !== failures) unionWaste();
1523
+ if (nested) COMPILED_ENV.n++;
1524
+ if (pendingStrips.length !== kept) pendingStrips.length = kept;
1525
+ }
1526
+ return FAIL;
1527
+ }
1528
+ /** {@link fastCheckUnion} of a union plan (the same memo entries: keyed by the node). */ function checkPlanUnion(plan, value, flags, opts) {
1529
+ let nested = false;
1530
+ if ((flags & IN_UNION) === 0) COMPILED_ENV.w = 0;
1531
+ else if (typeof value === "object" && value !== null) {
1532
+ if (COMPILED_ENV.m !== void 0) return memoizedUnion(plan.def, value, flags, opts, plan);
1533
+ nested = true;
1534
+ }
1535
+ const branchFlags = flags | IN_UNION;
1536
+ const kept = pendingStrips.length;
1537
+ for (const child of plan.children) {
1538
+ const failures = COMPILED_ENV.n;
1539
+ const result = checkPlan(child, value, branchFlags, opts);
1540
+ if (result !== FAIL) return unionMatchResult(result, child.def, plan.metadata, value);
1541
+ if (COMPILED_ENV.n !== failures) unionWaste();
1542
+ if (nested) COMPILED_ENV.n++;
1543
+ if (pendingStrips.length !== kept) pendingStrips.length = kept;
1544
+ }
1545
+ return FAIL;
1546
+ }
1547
+ /** The branches of a union (see {@link fastCheckUnion}); `nested`: its failed branches count. */ function unionBranches(def, value, flags, opts, nested) {
1548
+ const branchFlags = flags | IN_UNION;
1549
+ const kept = pendingStrips.length;
1550
+ for (const item of def.type.items) {
1551
+ const failures = COMPILED_ENV.n;
1552
+ const result = fastCheck(item, value, branchFlags, opts);
1553
+ if (result !== FAIL) return unionMatchResult(result, item, def.metadata, value);
1554
+ if (COMPILED_ENV.n !== failures) unionWaste();
1555
+ if (nested) COMPILED_ENV.n++;
1556
+ if (pendingStrips.length !== kept) pendingStrips.length = kept;
1557
+ }
1558
+ return FAIL;
1559
+ }
1560
+ /** {@link unionBranches} of a union plan. */ function planUnionBranches(plan, value, flags, opts, nested) {
1561
+ const branchFlags = flags | IN_UNION;
1562
+ const kept = pendingStrips.length;
1563
+ for (const child of plan.children) {
1564
+ const failures = COMPILED_ENV.n;
1565
+ const result = checkPlan(child, value, branchFlags, opts);
1566
+ if (result !== FAIL) return unionMatchResult(result, child.def, plan.metadata, value);
1567
+ if (COMPILED_ENV.n !== failures) unionWaste();
1568
+ if (nested) COMPILED_ENV.n++;
1569
+ if (pendingStrips.length !== kept) pendingStrips.length = kept;
1570
+ }
1571
+ return FAIL;
1572
+ }
1573
+ /** A union over object `value` inside a union branch, once the call made the memo. */ function memoizedUnion(def, value, flags, opts, plan) {
1574
+ const known = memoGet(def, value, flags, opts);
1575
+ if (known >= 0) return known;
1576
+ const kept = pendingStrips.length;
1577
+ const result = plan === void 0 ? unionBranches(def, value, flags, opts, true) : planUnionBranches(plan, value, flags, opts, true);
1578
+ if (result !== BAIL) memoSet(def, value, flags, opts, result, kept);
1579
+ return result;
1580
+ }
1581
+ function fastCheck(def, value, flags, opts) {
1582
+ if (def.optional && (value === void 0 || value === null)) return value === null && rejectsNullAsRequired(def) ? FAIL : PASS;
1583
+ const type = def.type;
1584
+ switch (type.kind) {
1585
+ case "": return fastCheckFinal(def, value);
1586
+ case "object": return fastCheckObject(def, value, flags, opts);
1587
+ case "array": return fastCheckArray(def, value, flags, opts);
1588
+ case "union": return fastCheckUnion(def, value, flags, opts);
1589
+ case "intersection": return fastCheckIntersection(type, value, flags, opts);
1590
+ case "tuple": {
1591
+ const items = type.items;
1592
+ if (!Array.isArray(value) || value.length !== items.length) return FAIL;
1593
+ const itemFlags = flags & IN_UNION;
1594
+ for (let i = 0; i < items.length; i++) {
1595
+ const result = fastCheck(items[i], value[i], itemFlags, opts);
1596
+ if (result !== PASS) return result;
1597
+ }
1598
+ return PASS;
1599
+ }
1600
+ default: return BAIL;
1601
+ }
1602
+ }
1603
+ function fastCheckFinal(def, value) {
1604
+ const type = def.type;
1605
+ const designType = type.designType;
1606
+ if (designType === "phantom") return PASS;
1607
+ if (type.value !== void 0) return value === type.value ? PASS : FAIL;
1608
+ switch (designType) {
1609
+ case "string": return typeof value === "string" ? fastCheckString(def.metadata, value) : FAIL;
1610
+ case "number": return typeof value === "number" && Number.isFinite(value) ? fastCheckNumber(def.metadata, value) : FAIL;
1611
+ case "boolean": return typeof value === "boolean" ? fastCheckBoolean(def.metadata, value) : FAIL;
1612
+ case "any": return PASS;
1613
+ case "never": return FAIL;
1614
+ case "undefined": return value === void 0 ? PASS : FAIL;
1615
+ case "null": return value === null ? PASS : FAIL;
1616
+ case "decimal": return typeof value === "string" && DECIMAL_RE.test(value) ? PASS : FAIL;
1617
+ default: return BAIL;
1618
+ }
1619
+ }
1620
+ /** Result of a union whose branch `item` did not fail (`PASS` or `BAIL`). */ function unionMatchResult(result, item, metadata, value) {
1621
+ return result === PASS && item.type.value === void 0 ? fastCheckUnionConstraints(metadata, value) : result;
1622
+ }
1623
+ /**
1624
+ * Mirrors Validator.validateUnionConstraints: union-level constraints on the matched value
1625
+ * (`null` / objects pass; the caller skips literal branches).
1626
+ */ function fastCheckUnionConstraints(meta, value) {
1627
+ const metadata = filledMeta(meta);
1628
+ if (metadata === void 0) return PASS;
1629
+ switch (typeof value) {
1630
+ case "string": return fastCheckString(metadata, value);
1631
+ case "number": return fastCheckNumber(metadata, value);
1632
+ case "boolean": return fastCheckBoolean(metadata, value);
1633
+ case "object": return Array.isArray(value) ? fastCheckArrayConstraints(metadata, value) : PASS;
1634
+ default: return PASS;
1635
+ }
1636
+ }
1637
+ function fastCheckBoolean(meta, value) {
1638
+ const metadata = filledMeta(meta);
1639
+ return metadata === void 0 ? PASS : booleanConstraints(value, metadata.get("meta.required"));
1640
+ }
1641
+ function fastCheckString(meta, value) {
1642
+ const metadata = filledMeta(meta);
1643
+ if (metadata === void 0) return PASS;
1644
+ if (metadata.get("meta.required") && value.trim().length === 0) return FAIL;
1645
+ const minLength = metadata.get("expect.minLength");
1646
+ if (minLength !== void 0 && value.length < (typeof minLength === "number" ? minLength : minLength.length)) return FAIL;
1647
+ const maxLength = metadata.get("expect.maxLength");
1648
+ if (maxLength !== void 0 && value.length > (typeof maxLength === "number" ? maxLength : maxLength.length)) return FAIL;
1649
+ const patterns = metadata.get("expect.pattern");
1650
+ if (patterns) for (const { pattern, flags } of patterns) {
1651
+ if (!pattern) continue;
1652
+ if (!getRegex(pattern, flags).test(value)) return FAIL;
1653
+ }
1654
+ return PASS;
1655
+ }
1656
+ function fastCheckNumber(meta, value) {
1657
+ const metadata = filledMeta(meta);
1658
+ if (metadata === void 0) return PASS;
1659
+ return numberConstraints(value, metadata.get("expect.int"), metadata.get("expect.min"), metadata.get("expect.max"), metadata.get("expect.exclusiveMin"), metadata.get("expect.exclusiveMax"));
1660
+ }
1661
+ function booleanConstraints(value, required) {
1662
+ return required && value !== true ? FAIL : PASS;
1663
+ }
1664
+ function numberConstraints(value, int, min, max, exMin, exMax) {
1665
+ if (int && value % 1 !== 0) return FAIL;
1666
+ if (min !== void 0 && value < (typeof min === "number" ? min : min.minValue)) return FAIL;
1667
+ if (max !== void 0 && value > (typeof max === "number" ? max : max.maxValue)) return FAIL;
1668
+ if (exMin !== void 0 && value <= (typeof exMin === "number" ? exMin : exMin.exclusiveMinValue)) return FAIL;
1669
+ if (exMax !== void 0 && value >= (typeof exMax === "number" ? exMax : exMax.exclusiveMaxValue)) return FAIL;
1670
+ return PASS;
1671
+ }
1672
+ /** `@expect.minLength` / `@expect.maxLength` (strings and arrays). */ function lengthFails(length, minLength, maxLength) {
1673
+ return minLength !== void 0 && length < (typeof minLength === "number" ? minLength : minLength.length) || maxLength !== void 0 && length > (typeof maxLength === "number" ? maxLength : maxLength.length);
1674
+ }
1675
+ /**
1676
+ * {@link fastCheck} of an intersection (a function of its own: `fastCheck` stays small, so the
1677
+ * engine inlines it in the hot object and prop checks).
1678
+ */ function fastCheckIntersection(type, value, flags, opts) {
1679
+ for (const item of type.items) {
1680
+ const result = fastCheck(item, value, flags, opts);
1681
+ if (result !== PASS) return result;
1682
+ }
1683
+ return PASS;
1684
+ }
1685
+ /** Array constraints; duplicate detection (`uniqueItems`) is left to the walk. */ function arrayConstraints(length, minLength, maxLength, uniqueItems) {
1686
+ if (lengthFails(length, minLength, maxLength)) return FAIL;
1687
+ return uniqueItems ? BAIL : PASS;
1688
+ }
1689
+ function fastCheckObject(def, value, flags, opts) {
1690
+ if (typeof value !== "object" || value === null || Array.isArray(value)) return FAIL;
1691
+ const type = def.type;
1692
+ if (type.propsPatterns.length > 0) return BAIL;
1693
+ const unknownProps = opts.unknownProps;
1694
+ const inUnion = (flags & IN_UNION) !== 0;
1695
+ if (unknownProps === "error" && !inUnion && hasUnknownKey(type.props, value)) return FAIL;
1696
+ const partial = opts.partial;
1697
+ const skipUndefined = partial === "deep" || partial === true && (flags & TOP) !== 0;
1698
+ const propFlags = flags & IN_UNION;
1699
+ let result = PASS;
1700
+ for (const [key, item] of type.props) {
1701
+ if (isPhantomType(item)) continue;
1702
+ const propValue = value[key];
1703
+ if (propValue === void 0 && skipUndefined) continue;
1704
+ const propResult = fastCheck(item, propValue, propFlags, opts);
1705
+ if (propResult !== PASS) {
1706
+ if (propResult === BAIL || !inUnion) return propResult;
1707
+ result = FAIL;
1708
+ }
1709
+ }
1710
+ if (result !== PASS) return result;
1711
+ if (unknownProps === "strip") {
1712
+ pendStrips(type.props, value);
1713
+ return PASS;
1714
+ }
1715
+ return unknownProps === "error" && inUnion && hasUnknownKey(type.props, value) ? FAIL : PASS;
1716
+ }
1717
+ /** Records the unknown keys of a passing object (see `pendingStrips`). */ function pendStrips(props, value) {
1718
+ for (const key of Object.keys(value)) if (isUnknownKey(props, key)) pendingStrips.push(value, key);
1719
+ }
1720
+ /** `true` when `value` has a key the walk treats as unknown. */ function hasUnknownKey(props, value) {
1721
+ for (const key of Object.keys(value)) if (isUnknownKey(props, key)) return true;
1722
+ return false;
1723
+ }
1724
+ /** `true` when the walk treats `key` as unknown (no prop, or a phantom one). */ function isUnknownKey(props, key) {
1725
+ const known = props.get(key);
1726
+ return known === void 0 || isPhantomType(known);
1727
+ }
1728
+ function fastCheckArray(def, value, flags, opts) {
1729
+ if (!Array.isArray(value)) return FAIL;
1730
+ const metadata = filledMeta(def.metadata);
1731
+ if (metadata !== void 0) {
1732
+ const result = fastCheckArrayConstraints(metadata, value);
1733
+ if (result !== PASS) return result;
1734
+ }
1735
+ return checkItems(planFor(def.type.of), value, flags, opts);
1736
+ }
1737
+ /** Checks every array item against the item type's plan. */ function checkItems(of, value, flags, opts) {
1738
+ const inUnion = (flags & IN_UNION) !== 0;
1739
+ const itemFlags = flags & IN_UNION;
1740
+ let result = PASS;
1741
+ for (const item of value) {
1742
+ const itemResult = checkPlan(of, item, itemFlags, opts);
1743
+ if (itemResult !== PASS) {
1744
+ if (itemResult === BAIL || !inUnion) return itemResult;
1745
+ result = FAIL;
1746
+ }
1747
+ }
1748
+ return result;
1749
+ }
1750
+ function fastCheckArrayConstraints(metadata, value) {
1751
+ return arrayConstraints(value.length, metadata.get("expect.minLength"), metadata.get("expect.maxLength"), metadata.get("expect.array.uniqueItems"));
1752
+ }
1753
+ const OP_GENERIC = 0;
1754
+ const OP_PHANTOM = 1;
1755
+ const OP_STRING = 2;
1756
+ const OP_NUMBER = 3;
1757
+ const OP_BOOLEAN = 4;
1758
+ /** Any other final node: checked by {@link fastCheckFinal}. */ const OP_FINAL = 5;
1759
+ const OP_OBJECT = 6;
1760
+ const OP_ARRAY = 7;
1761
+ const OP_UNION = 8;
1762
+ function isFinalOp(op) {
1763
+ return op !== OP_GENERIC && op <= OP_FINAL;
1764
+ }
1765
+ /** Shared placeholder for the per-kind arrays of plans that don't use them. */ const EMPTY = Object.freeze([]);
1766
+ const plans = /* @__PURE__ */ new WeakMap();
1767
+ /** One shape for every plan, so plan field access stays monomorphic. */ let Plan = class Plan {
1768
+ constructor(def) {
1769
+ _define_property$1(this, "def", void 0);
1770
+ /** Call in which the node structure was last verified (`-1`: must rebuild). */ _define_property$1(this, "stamp", void 0);
1771
+ /** Call in which the annotation values (`m0`–`m4`) were last verified. */ _define_property$1(this, "metaStamp", void 0);
1772
+ _define_property$1(this, "op", void 0);
1773
+ _define_property$1(this, "type", void 0);
1774
+ _define_property$1(this, "optional", void 0);
1775
+ _define_property$1(this, "metadata", void 0);
1776
+ _define_property$1(this, "kind", void 0);
1777
+ _define_property$1(this, "designType", void 0);
1778
+ _define_property$1(this, "literal", void 0);
1779
+ /** String plans: compiled `@expect.pattern` regexes by position (checked against the live entry). */ _define_property$1(this, "regexes", void 0);
1780
+ /**
1781
+ * Annotation keys the node's check reads, and their values (`undefined` when absent):
1782
+ * string `meta.required, expect.minLength, maxLength, pattern`; number `expect.int, min,
1783
+ * max, exclusiveMin, exclusiveMax`; boolean `meta.required`; array `expect.minLength, maxLength, array.uniqueItems`.
1784
+ */ _define_property$1(this, "k0", void 0);
1785
+ _define_property$1(this, "k1", void 0);
1786
+ _define_property$1(this, "k2", void 0);
1787
+ _define_property$1(this, "k3", void 0);
1788
+ _define_property$1(this, "k4", void 0);
1789
+ _define_property$1(this, "m0", void 0);
1790
+ _define_property$1(this, "m1", void 0);
1791
+ _define_property$1(this, "m2", void 0);
1792
+ _define_property$1(this, "m3", void 0);
1793
+ _define_property$1(this, "m4", void 0);
1794
+ _define_property$1(this, "props", void 0);
1795
+ _define_property$1(this, "propsPatterns", void 0);
1796
+ _define_property$1(this, "keys", void 0);
1797
+ /** Call in which `props.get(keys[i]) === nodes[i]` was last verified. */ _define_property$1(this, "edges", void 0);
1798
+ /** Prop plans by key (the entries of `props`, verified per visit via `edges`). */ _define_property$1(this, "byKey", void 0);
1799
+ _define_property$1(this, "nodes", void 0);
1800
+ _define_property$1(this, "children", void 0);
1801
+ _define_property$1(this, "of", void 0);
1802
+ _define_property$1(this, "ofPlan", void 0);
1803
+ _define_property$1(this, "items", void 0);
1804
+ this.def = def;
1805
+ this.stamp = -1;
1806
+ this.metaStamp = -1;
1807
+ this.op = OP_GENERIC;
1808
+ this.type = void 0;
1809
+ this.optional = void 0;
1810
+ this.metadata = void 0;
1811
+ this.kind = void 0;
1812
+ this.designType = void 0;
1813
+ this.literal = void 0;
1814
+ this.regexes = EMPTY;
1815
+ this.k0 = void 0;
1816
+ this.k1 = void 0;
1817
+ this.k2 = void 0;
1818
+ this.k3 = void 0;
1819
+ this.k4 = void 0;
1820
+ this.m0 = void 0;
1821
+ this.m1 = void 0;
1822
+ this.m2 = void 0;
1823
+ this.m3 = void 0;
1824
+ this.m4 = void 0;
1825
+ this.props = void 0;
1826
+ this.propsPatterns = void 0;
1827
+ this.keys = EMPTY;
1828
+ this.edges = EMPTY;
1829
+ this.byKey = void 0;
1830
+ this.nodes = EMPTY;
1831
+ this.children = EMPTY;
1832
+ this.of = void 0;
1833
+ this.ofPlan = void 0;
1834
+ this.items = void 0;
1835
+ }
1836
+ };
1837
+ function planFor(def) {
1838
+ let plan = plans.get(def);
1839
+ if (plan === void 0) {
1840
+ plan = new Plan(def);
1841
+ plans.set(def, plan);
1842
+ }
1843
+ return plan;
1844
+ }
1845
+ /** Brings the plan's structure up to date with its live node (once per call). */ function refresh(plan) {
1846
+ if (!(isFinalOp(plan.op) ? verifyFinal(plan) : verify(plan))) build(plan);
1847
+ plan.stamp = stamp;
1848
+ }
1849
+ /** Structure check for final ops; small enough to be inlined into the hot loops. */ function verifyFinal(plan) {
1850
+ const def = plan.def;
1851
+ const type = def.type;
1852
+ return plan.stamp !== -1 && type === plan.type && def.optional === plan.optional && def.metadata === plan.metadata && type.kind === "" && type.designType === plan.designType && type.value === plan.literal;
1853
+ }
1854
+ /** Structure check for objects, arrays, unions and generic nodes. */ function verify(plan) {
1855
+ if (plan.stamp === -1) return false;
1856
+ const def = plan.def;
1857
+ const type = def.type;
1858
+ if (type !== plan.type || def.optional !== plan.optional || def.metadata !== plan.metadata || type.kind !== plan.kind) return false;
1859
+ switch (plan.op) {
1860
+ case OP_OBJECT: return type.props === plan.props && plan.props.size === plan.keys.length && type.propsPatterns === plan.propsPatterns && plan.propsPatterns.length === 0;
1861
+ case OP_ARRAY: return type.of === plan.of;
1862
+ case OP_UNION: {
1863
+ const items = plan.items;
1864
+ const nodes = plan.nodes;
1865
+ if (type.items !== items || items.length !== nodes.length) return false;
1866
+ for (let i = 0; i < nodes.length; i++) if (items[i] !== nodes[i]) return false;
1867
+ return true;
1868
+ }
1869
+ default: return type.kind !== "object" || type.propsPatterns.length > 0;
1870
+ }
1871
+ }
1872
+ /** Brings the annotation values up to date (once per call, when a constraint is read). */ function refreshMeta(plan) {
1873
+ const metadata = filledMeta(plan.metadata);
1874
+ if (!(metadata === void 0 ? plan.m0 === void 0 && plan.m1 === void 0 && plan.m2 === void 0 && plan.m3 === void 0 && plan.m4 === void 0 : metadata.get(plan.k0) === plan.m0 && (plan.k1 === void 0 || metadata.get(plan.k1) === plan.m1) && (plan.k2 === void 0 || metadata.get(plan.k2) === plan.m2) && (plan.k3 === void 0 || metadata.get(plan.k3) === plan.m3) && (plan.k4 === void 0 || metadata.get(plan.k4) === plan.m4))) snapshotMeta(plan);
1875
+ plan.metaStamp = stamp;
1876
+ }
1877
+ function snapshotMeta(plan) {
1878
+ const metadata = readable(plan.metadata);
1879
+ plan.m0 = metadata.get(plan.k0);
1880
+ plan.m1 = metadata.get(plan.k1);
1881
+ plan.m2 = metadata.get(plan.k2);
1882
+ plan.m3 = metadata.get(plan.k3);
1883
+ plan.m4 = metadata.get(plan.k4);
1884
+ }
1885
+ function setMetaKeys(plan, k0, k1, k2, k3, k4) {
1886
+ plan.k0 = k0;
1887
+ plan.k1 = k1;
1888
+ plan.k2 = k2;
1889
+ plan.k3 = k3;
1890
+ plan.k4 = k4;
1891
+ snapshotMeta(plan);
1892
+ plan.metaStamp = stamp;
1893
+ }
1894
+ /** (Re)compiles `plan` from its live node. */ function build(plan) {
1895
+ plan.stamp = -1;
1896
+ plan.op = OP_GENERIC;
1897
+ const def = plan.def;
1898
+ const type = def.type;
1899
+ plan.type = type;
1900
+ plan.optional = def.optional;
1901
+ plan.metadata = def.metadata;
1902
+ plan.kind = type.kind;
1903
+ plan.designType = type.designType;
1904
+ plan.literal = type.value;
1905
+ plan.regexes = EMPTY;
1906
+ plan.props = void 0;
1907
+ plan.propsPatterns = void 0;
1908
+ plan.keys = EMPTY;
1909
+ plan.edges = EMPTY;
1910
+ plan.byKey = void 0;
1911
+ plan.nodes = EMPTY;
1912
+ plan.children = EMPTY;
1913
+ plan.of = void 0;
1914
+ plan.ofPlan = void 0;
1915
+ plan.items = void 0;
1916
+ setMetaKeys(plan);
1917
+ switch (type.kind) {
1918
+ case "":
1919
+ if (type.designType === "phantom") plan.op = OP_PHANTOM;
1920
+ else if (type.value !== void 0) plan.op = OP_FINAL;
1921
+ else if (type.designType === "string") {
1922
+ setMetaKeys(plan, ...STRING_KEYS);
1923
+ plan.regexes = [];
1924
+ plan.op = OP_STRING;
1925
+ } else if (type.designType === "number") {
1926
+ setMetaKeys(plan, ...NUMBER_KEYS);
1927
+ plan.op = OP_NUMBER;
1928
+ } else if (type.designType === "boolean") {
1929
+ setMetaKeys(plan, ...BOOLEAN_KEYS);
1930
+ plan.op = OP_BOOLEAN;
1931
+ } else plan.op = OP_FINAL;
1932
+ break;
1933
+ case "object": {
1934
+ if (type.propsPatterns.length > 0) break;
1935
+ const byKey = /* @__PURE__ */ new Map();
1936
+ plan.keys = [];
1937
+ plan.edges = [];
1938
+ plan.nodes = [];
1939
+ plan.children = [];
1940
+ for (const [key, node] of type.props) {
1941
+ const child = planFor(node);
1942
+ plan.keys.push(key);
1943
+ plan.edges.push(stamp);
1944
+ plan.nodes.push(node);
1945
+ plan.children.push(child);
1946
+ byKey.set(key, child);
1947
+ }
1948
+ plan.byKey = byKey;
1949
+ plan.props = type.props;
1950
+ plan.propsPatterns = type.propsPatterns;
1951
+ plan.op = OP_OBJECT;
1952
+ break;
1953
+ }
1954
+ case "array":
1955
+ setMetaKeys(plan, ...ARRAY_KEYS);
1956
+ plan.of = type.of;
1957
+ plan.ofPlan = planFor(type.of);
1958
+ plan.op = OP_ARRAY;
1959
+ break;
1960
+ case "union":
1961
+ plan.nodes = [];
1962
+ plan.children = [];
1963
+ for (const node of type.items) {
1964
+ plan.nodes.push(node);
1965
+ plan.children.push(planFor(node));
1966
+ }
1967
+ plan.items = type.items;
1968
+ plan.op = OP_UNION;
1969
+ break;
1970
+ default:
1971
+ }
1972
+ }
1973
+ /** Plan counterpart of {@link fastCheck}. */ function checkPlan(plan, value, flags, opts) {
1974
+ if (plan.stamp !== stamp) refresh(plan);
1975
+ if (plan.optional && (value === void 0 || value === null)) return value === null && rejectsNullAsRequired(plan.def) ? FAIL : PASS;
1976
+ switch (plan.op) {
1977
+ case OP_STRING: return typeof value === "string" ? checkString(plan, value) : FAIL;
1978
+ case OP_NUMBER: return typeof value === "number" && Number.isFinite(value) ? checkNumber(plan, value) : FAIL;
1979
+ case OP_OBJECT: return checkObject(plan, value, flags, opts);
1980
+ case OP_ARRAY: return checkArray(plan, value, flags, opts);
1981
+ case OP_UNION: return checkPlanUnion(plan, value, flags, opts);
1982
+ case OP_BOOLEAN:
1983
+ if (typeof value !== "boolean") return FAIL;
1984
+ if (plan.metaStamp !== stamp) refreshMeta(plan);
1985
+ return booleanConstraints(value, plan.m0);
1986
+ case OP_PHANTOM:
1987
+ case OP_FINAL: return fastCheckFinal(plan.def, value);
1988
+ default: return fastCheck(plan.def, value, flags, opts);
1989
+ }
1990
+ }
1991
+ /** Plan counterpart of {@link fastCheckString}; constraint objects are read live. */ function checkString(plan, value) {
1992
+ if (plan.metaStamp !== stamp) refreshMeta(plan);
1993
+ if (plan.m0 && value.trim().length === 0) return FAIL;
1994
+ if (lengthFails(value.length, plan.m1, plan.m2)) return FAIL;
1995
+ const patterns = plan.m3;
1996
+ if (patterns) {
1997
+ if (!Array.isArray(patterns)) return fastCheckString(plan.metadata, value);
1998
+ for (let i = 0; i < patterns.length; i++) {
1999
+ const { pattern, flags } = patterns[i];
2000
+ if (!pattern) continue;
2001
+ let entry = plan.regexes[i];
2002
+ if (entry === void 0 || entry.pattern !== pattern || entry.flags !== flags) {
2003
+ entry = {
2004
+ pattern,
2005
+ flags,
2006
+ re: getRegex(pattern, flags)
2007
+ };
2008
+ plan.regexes[i] = entry;
2009
+ }
2010
+ if (!entry.re.test(value)) return FAIL;
2011
+ }
2012
+ }
2013
+ return PASS;
2014
+ }
2015
+ /** Plan counterpart of {@link fastCheckNumber}; constraint objects are read live. */ function checkNumber(plan, value) {
2016
+ if (plan.metaStamp !== stamp) refreshMeta(plan);
2017
+ return numberConstraints(value, plan.m0, plan.m1, plan.m2, plan.m3, plan.m4);
2018
+ }
2019
+ /** Plan counterpart of {@link fastCheckObject}. */ function checkObject(plan, value, flags, opts) {
2020
+ if (typeof value !== "object" || value === null || Array.isArray(value)) return FAIL;
2021
+ const partial = opts.partial;
2022
+ const skipUndefined = partial === "deep" || partial === true && (flags & TOP) !== 0;
2023
+ const inUnion = (flags & IN_UNION) !== 0;
2024
+ const propFlags = flags & IN_UNION;
2025
+ const keys = plan.keys;
2026
+ const children = plan.children;
2027
+ const edges = plan.edges;
2028
+ let result = PASS;
2029
+ for (let i = 0; i < keys.length; i++) {
2030
+ if (edges[i] !== stamp) {
2031
+ if (plan.props.get(keys[i]) !== plan.nodes[i]) {
2032
+ plan.stamp = -1;
2033
+ return BAIL;
2034
+ }
2035
+ edges[i] = stamp;
2036
+ }
2037
+ const child = children[i];
2038
+ if (child.stamp !== stamp) refresh(child);
2039
+ const op = child.op;
2040
+ if (op === OP_PHANTOM) continue;
2041
+ const propValue = value[keys[i]];
2042
+ if (propValue === void 0 && skipUndefined) continue;
2043
+ if (typeof propValue === "string" && op === OP_STRING) {
2044
+ const r = checkString(child, propValue);
2045
+ if (r === PASS) continue;
2046
+ if (r === BAIL || !inUnion) return r;
2047
+ result = FAIL;
2048
+ continue;
2049
+ }
2050
+ if (typeof propValue === "number" && op === OP_NUMBER) {
2051
+ if (Number.isFinite(propValue) && checkNumber(child, propValue) === PASS) continue;
2052
+ if (!inUnion) return FAIL;
2053
+ result = FAIL;
2054
+ continue;
2055
+ }
2056
+ const propResult = checkPlan(child, propValue, propFlags, opts);
2057
+ if (propResult !== PASS) {
2058
+ if (propResult === BAIL || !inUnion) return propResult;
2059
+ result = FAIL;
2060
+ }
2061
+ }
2062
+ if (result !== PASS) return result;
2063
+ const unknownProps = opts.unknownProps;
2064
+ if (unknownProps === "error" || unknownProps === "strip") {
2065
+ const byKey = plan.byKey;
2066
+ for (const key of Object.keys(value)) {
2067
+ const known = byKey.get(key);
2068
+ if (known !== void 0 && known.op !== OP_PHANTOM) continue;
2069
+ if (unknownProps === "error") return FAIL;
2070
+ pendingStrips.push(value, key);
2071
+ }
2072
+ }
2073
+ return PASS;
2074
+ }
2075
+ /** Plan counterpart of {@link fastCheckArray}. */ function checkArray(plan, value, flags, opts) {
2076
+ if (!Array.isArray(value)) return FAIL;
2077
+ if (plan.metaStamp !== stamp) refreshMeta(plan);
2078
+ const result = arrayConstraints(value.length, plan.m0, plan.m1, plan.m2);
2079
+ if (result !== PASS) return result;
2080
+ return checkItems(plan.ofPlan, value, flags, opts);
2081
+ }
2082
+
2083
+ //#endregion
2084
+ //#region packages/typescript/src/runtime/validator.ts
2085
+ function _define_property(obj, key, value) {
2086
+ if (key in obj) Object.defineProperty(obj, key, {
2087
+ value,
2088
+ enumerable: true,
2089
+ configurable: true,
2090
+ writable: true
2091
+ });
2092
+ else obj[key] = value;
2093
+ return obj;
2094
+ }
2095
+ /**
2096
+ * Validates values against an {@link TAtscriptAnnotatedType} definition.
2097
+ *
2098
+ * `DataType` is automatically inferred from the type definition's phantom generic,
2099
+ * enabling the {@link validate} method to act as a type guard.
2100
+ *
2101
+ * @example
2102
+ * ```ts
2103
+ * // From a generated interface class:
2104
+ * const validator = new Validator(MyInterface)
2105
+ * if (validator.validate(data, true)) {
2106
+ * data // narrowed to MyInterface
2107
+ * }
2108
+ *
2109
+ * // Or use the built-in factory:
2110
+ * MyInterface.validator().validate(data)
2111
+ * ```
2112
+ *
2113
+ * @typeParam T - The annotated type definition.
2114
+ * @typeParam DataType - The TypeScript type that `validate` narrows to (auto-inferred).
2115
+ */ var Validator = class Validator {
2116
+ buildPath() {
2117
+ if (this.depth <= 0) return "";
2118
+ let path = this.pathSegments[0];
2119
+ for (let i = 1; i < this.depth; i++) path += `.${this.pathSegments[i]}`;
2120
+ return path;
2121
+ }
2122
+ push(name) {
2123
+ this.pathSegments[this.depth] = name;
2124
+ this.depth++;
2125
+ this.stackErrors.push(null);
2126
+ }
2127
+ pop(saveErrors) {
2128
+ this.depth--;
2129
+ const popped = this.stackErrors.pop();
2130
+ if (saveErrors && popped !== null && popped !== void 0 && popped.length > 0) for (const err of popped) this.error(err.message, err.path, err.details);
2131
+ return popped;
2132
+ }
2133
+ clear() {
2134
+ this.stackErrors[this.stackErrors.length - 1] = null;
2135
+ if (this.limitExceeded) this.limitExceeded = false;
2136
+ }
2137
+ error(message, path, details) {
2138
+ let errors = this.stackErrors[this.stackErrors.length - 1];
2139
+ if (!errors) if (this.stackErrors.length > 0) {
2140
+ errors = [];
2141
+ this.stackErrors[this.stackErrors.length - 1] = errors;
2142
+ } else errors = this.errors;
2143
+ const error = {
2144
+ path: path || this.buildPath(),
2145
+ message
2146
+ };
2147
+ if (details?.length) error.details = details;
2148
+ errors.push(error);
2149
+ if (errors.length >= this.opts.errorLimit) this.limitExceeded = true;
2150
+ return error;
2151
+ }
2152
+ /** Adds `error`, already made, to the errors of the current level (as {@link error} does). */ report(error) {
2153
+ let errors = this.stackErrors[this.stackErrors.length - 1];
2154
+ if (!errors) if (this.stackErrors.length > 0) {
2155
+ errors = [];
2156
+ this.stackErrors[this.stackErrors.length - 1] = errors;
2157
+ } else errors = this.errors;
2158
+ errors.push(error);
2159
+ if (errors.length >= this.opts.errorLimit) this.limitExceeded = true;
2160
+ }
2161
+ throw() {
2162
+ throw new ValidatorError(this.errors);
2163
+ }
2164
+ /**
2165
+ * Validates a value against the type definition.
2166
+ *
2167
+ * Acts as a TypeScript type guard — when it returns `true`, the value
2168
+ * is narrowed to `DataType`.
2169
+ *
2170
+ * @param value - The value to validate.
2171
+ * @param safe - If `true`, returns `false` on failure instead of throwing.
2172
+ * @returns `true` if the value matches the type definition.
2173
+ * @throws {ValidatorError} When validation fails and `safe` is not `true`.
2174
+ */ validate(value, safe, context) {
2175
+ this.errors = [];
2176
+ this.stackErrors.length = 0;
2177
+ this.depth = 0;
2178
+ this.limitExceeded = false;
2179
+ if (this.shortcuts && !this.opts.skipList && typeof this.opts.partial !== "function" && fastCheckPasses(this.def, value, this.opts)) return true;
2180
+ this.context = context;
2181
+ this.unionDepth = 0;
2182
+ this.unionMemo = void 0;
2183
+ if (this.strips.length > 0) this.strips.length = 0;
2184
+ const passed = this.validateSafe(this.def, value);
2185
+ this.context = void 0;
2186
+ if (this.unionMemo !== void 0) this.unionMemo = void 0;
2187
+ if (this.strips.length > 0) performStrips(this.strips, passed);
2188
+ if (!passed) {
2189
+ if (safe) return false;
2190
+ this.throw();
2191
+ }
2192
+ return true;
2193
+ }
2194
+ /**
2195
+ * Plain `Validator` without plugins / `replace`: eligible for the allocation-free
2196
+ * shortcuts. Subclasses may override the protected `validate*` hooks, so they
2197
+ * always take the full walk. (A getter, not a constructor-set field: validators are
2198
+ * often built per call, so construction stays as cheap as before.)
2199
+ */ get shortcuts() {
2200
+ return this.constructor === Validator && !this.hasPlugins && !this.hasReplace;
2201
+ }
2202
+ /** Validates `value` against `def` (after `replace`, `optional` and the plugins). */ validateSafe(def, value) {
2203
+ if (this.limitExceeded) return false;
2204
+ if (this.hasReplace) def = this.replaced(def);
2205
+ if (def.optional && (value === void 0 || value === null)) {
2206
+ if (value === null && rejectsNullAsRequired(def)) {
2207
+ this.error(requiredMessage(def));
2208
+ return false;
2209
+ }
2210
+ return true;
2211
+ }
2212
+ if (this.hasPlugins) {
2213
+ const decided = this.preCheck(def, value);
2214
+ if (decided !== void 0) return decided;
2215
+ }
2216
+ return this.validateAnnotatedType(def, value);
2217
+ }
2218
+ /**
2219
+ * What {@link validateSafe} decides of `def` (replaced) before its own validation: an
2220
+ * optional `def` passes `undefined` / `null`, a plugin may decide — `undefined` to go on.
2221
+ */ preCheck(def, value) {
2222
+ if (def.optional && (value === void 0 || value === null)) {
2223
+ if (value === null && rejectsNullAsRequired(def)) {
2224
+ this.error(requiredMessage(def));
2225
+ return false;
2226
+ }
2227
+ return true;
2228
+ }
2229
+ if (this.hasPlugins) {
2230
+ const ctx = this.pluginCtx ?? (this.pluginCtx = this.pluginContext());
2231
+ for (const plugin of this.opts.plugins) {
2232
+ const result = plugin(ctx, def, value);
2233
+ if (result === false || result === true) return result;
2234
+ }
2235
+ }
2236
+ }
2237
+ /**
2238
+ * The plugins' view of this validator: its state read live; `validateAnnotatedType` drops the
2239
+ * strips a failed call recorded (a failed validation at any level strips nothing).
2240
+ */ pluginContext() {
2241
+ return Object.defineProperties({
2242
+ validateAnnotatedType: (def, value) => {
2243
+ const kept = this.strips.length;
2244
+ const passed = this.validateAnnotatedType(def, value);
2245
+ if (!passed && this.strips.length !== kept) this.strips.length = kept;
2246
+ return passed;
2247
+ },
2248
+ error: (message, path, details) => this.error(message, path, details)
2249
+ }, {
2250
+ opts: {
2251
+ get: () => this.opts,
2252
+ enumerable: true
2253
+ },
2254
+ path: {
2255
+ get: () => this.path,
2256
+ enumerable: true
2257
+ },
2258
+ root: {
2259
+ get: () => this.root,
2260
+ enumerable: true
2261
+ },
2262
+ context: {
2263
+ get: () => this.context,
2264
+ set: (context) => {
2265
+ this.context = context;
2266
+ },
2267
+ enumerable: true
2268
+ }
2269
+ });
2270
+ }
2271
+ /** `def` as the `replace` option replaces it at the current path (memoized per node). */ replaced(def) {
2272
+ let replaced = this.replaceCache.get(def);
2273
+ if (replaced === void 0) {
2274
+ replaced = this.opts.replace(def, this.buildPath());
2275
+ this.replaceCache.set(def, replaced);
2276
+ }
2277
+ return replaced;
2278
+ }
2279
+ get path() {
2280
+ return this.buildPath();
2281
+ }
2282
+ /** The type this validator was created for (see {@link TValidatorPluginContext.root}). */ get root() {
2283
+ return this.def;
2284
+ }
2285
+ validateAnnotatedType(def, value) {
2286
+ switch (def.type.kind) {
2287
+ case "":
2288
+ if (def.type.designType === "phantom") return true;
2289
+ return this.validatePrimitive(def, value);
2290
+ case "object": return this.validateObject(def, value);
2291
+ case "array": return this.validateArray(def, value);
2292
+ case "union": return this.validateUnion(def, value);
2293
+ case "intersection": return this.validateIntersection(def, value);
2294
+ case "tuple": return this.validateTuple(def, value);
2295
+ default: throw new Error(`Unknown type kind "${def.type.kind}"`);
2296
+ }
2297
+ }
2298
+ validateUnion(def, value) {
2299
+ const items = def.type.items;
2300
+ if (this.shortcuts) for (const item of items) {
2301
+ const type = item.type;
2302
+ if (item.optional || type.kind !== "" || type.value === void 0 || type.designType === "phantom") break;
2303
+ if (type.value === value) return true;
2304
+ }
2305
+ let nested = false;
2306
+ let path;
2307
+ if (this.unionDepth > 0) {
2308
+ if (typeof value === "object" && value !== null) {
2309
+ if (this.unionMemo !== void 0) {
2310
+ path = this.buildPath();
2311
+ const known = this.decided(def, value, path);
2312
+ if (known !== void 0) {
2313
+ if (known.error === void 0) {
2314
+ stripAgain(this.strips, known.strips);
2315
+ return this.validateUnionConstraints(def, known.item, value);
2316
+ }
2317
+ this.report(known.error);
2318
+ return false;
2319
+ }
2320
+ }
2321
+ nested = true;
2322
+ }
2323
+ } else this.wasted = 0;
2324
+ const kept = this.strips.length;
2325
+ let details;
2326
+ for (const item of items) {
2327
+ this.stackErrors.push(null);
2328
+ const failures = this.nestedFailures;
2329
+ this.unionDepth++;
2330
+ const passed = this.validateSafe(item, value);
2331
+ this.unionDepth--;
2332
+ if (passed) {
2333
+ this.stackErrors.pop();
2334
+ if (path !== void 0) this.decide(def, value, path, kept, item, void 0);
2335
+ return this.validateUnionConstraints(def, item, value);
2336
+ }
2337
+ if (this.strips.length !== kept) this.strips.length = kept;
2338
+ const branchErrors = this.stackErrors.pop();
2339
+ if (this.limitExceeded) this.limitExceeded = false;
2340
+ if (this.nestedFailures !== failures) this.wasteBranch();
2341
+ if (nested) this.nestedFailures++;
2342
+ if (branchErrors) if (details) for (const err of branchErrors) details.push(err);
2343
+ else details = branchErrors;
2344
+ }
2345
+ const expected = items.map((item, i) => `[${item.type.kind || item.type.designType}(${i})]`).join(", ");
2346
+ const error = this.error(`Value does not match any of the allowed types: ${expected}`, void 0, details);
2347
+ if (path !== void 0) this.decide(def, value, path, kept, void 0, error);
2348
+ return false;
2349
+ }
2350
+ /** A union branch failed after branches of nested unions over objects did (see `unionMemo`). */ wasteBranch() {
2351
+ if (++this.wasted === WASTE_BEFORE_MEMO && this.unionMemo === void 0) this.unionMemo = /* @__PURE__ */ new Map();
2352
+ }
2353
+ /** The outcome this call recorded for union `def` over `value` at `path` (see `unionMemo`). */ decided(def, value, path) {
2354
+ const outcomes = this.unionMemo.get(value);
2355
+ if (outcomes !== void 0) {
2356
+ const { unknownProps } = this.opts;
2357
+ for (const outcome of outcomes) if (outcome.def === def && outcome.path === path && outcome.unknownProps === unknownProps) return outcome;
2358
+ }
2359
+ }
2360
+ /**
2361
+ * Records the outcome of union `def` over `value` at `path`, entered with `kept` strips (the
2362
+ * ones after them are its own).
2363
+ */ decide(def, value, path, kept, item, error) {
2364
+ const outcome = {
2365
+ def,
2366
+ path,
2367
+ unknownProps: this.opts.unknownProps,
2368
+ item,
2369
+ error,
2370
+ strips: stripsSince(this.strips, kept)
2371
+ };
2372
+ const outcomes = this.unionMemo.get(value);
2373
+ if (outcomes === void 0) this.unionMemo.set(value, [outcome]);
2374
+ else outcomes.push(outcome);
2375
+ }
2376
+ /**
2377
+ * Constraints annotated on the union itself (`@expect.min 0` on `number | null`)
2378
+ * apply to the non-null value that matched `branch`, on top of the branch's own.
2379
+ * A literal branch (an enum value) is exempt: its value is fixed.
2380
+ */ validateUnionConstraints(def, branch, value) {
2381
+ const metadata = def.metadata;
2382
+ if (metaEmpty(metadata) || branch.type.value !== void 0) return true;
2383
+ switch (typeof value) {
2384
+ case "string": return this.validateStringConstraints(metadata, value);
2385
+ case "number": return this.validateNumberConstraints(metadata, value);
2386
+ case "boolean": return this.validateBooleanConstraints(metadata, value);
2387
+ case "object":
2388
+ if (Array.isArray(value)) return this.validateArrayConstraints(metadata, value, arrayElementType(branch));
2389
+ return true;
2390
+ default: return true;
2391
+ }
2392
+ }
2393
+ /** Every member must pass, each on its own (JSON Schema `allOf`). */ validateIntersection(def, value) {
2394
+ for (const item of def.type.items) if (!this.validateSafe(item, value)) return false;
2395
+ return true;
2396
+ }
2397
+ /**
2398
+ * An unknown key (`unknownProps`): 'error' reports it, 'strip' adds it to the keys to strip
2399
+ * (returned; recorded in `strips` once the object passed).
2400
+ */ unknownKey(key, keysToStrip) {
2401
+ if (this.opts.unknownProps === "error") {
2402
+ this.push(key);
2403
+ this.error(`Unexpected property`);
2404
+ this.pop(true);
2405
+ } else if (this.opts.unknownProps === "strip") (keysToStrip ?? (keysToStrip = [])).push(key);
2406
+ return keysToStrip;
2407
+ }
2408
+ /** The `skipList` keys of the object at the current path. */ skipListHere() {
2409
+ if (!this.opts.skipList) return;
2410
+ let skipList;
2411
+ const path = this.depth > 0 ? `${this.buildPath()}.` : "";
2412
+ for (const item of this.opts.skipList) if (item.startsWith(path)) (skipList ?? (skipList = /* @__PURE__ */ new Set())).add(item.slice(path.length));
2413
+ return skipList;
2414
+ }
2415
+ validateTuple(def, value) {
2416
+ if (!Array.isArray(value) || value.length !== def.type.items.length) {
2417
+ this.error(`Expected array of length ${def.type.items.length}`);
2418
+ return false;
2419
+ }
2420
+ let i = 0;
2421
+ for (const item of def.type.items) {
2422
+ this.push(String(i));
2423
+ if (!this.validateSafe(item, value[i])) {
2424
+ this.pop(true);
2425
+ return false;
2426
+ }
2427
+ this.pop(false);
2428
+ i++;
2429
+ }
2430
+ return true;
2431
+ }
2432
+ validateArray(def, value) {
2433
+ if (!Array.isArray(value)) {
2434
+ this.error("Expected array");
2435
+ return false;
2436
+ }
2437
+ if (!metaEmpty(def.metadata) && !this.validateArrayConstraints(def.metadata, value, def.type.of)) return false;
2438
+ let i = 0;
2439
+ let passed = true;
2440
+ for (const item of value) {
2441
+ this.push(String(i));
2442
+ if (!this.validateSafe(def.type.of, item)) {
2443
+ passed = false;
2444
+ this.pop(true);
2445
+ if (this.limitExceeded) return false;
2446
+ } else this.pop(false);
2447
+ i++;
2448
+ }
2449
+ return passed;
2450
+ }
2451
+ /** `@expect.minLength` / `maxLength` / `array.uniqueItems` checks for an array value. */ validateArrayConstraints(meta, value, of) {
2452
+ const metadata = readable(meta);
2453
+ const minLength = metadata.get("expect.minLength");
2454
+ if (minLength !== void 0) {
2455
+ const length = typeof minLength === "number" ? minLength : minLength.length;
2456
+ if (value.length < length) {
2457
+ const message = typeof minLength === "object" && minLength.message ? minLength.message : `Expected minimum length of ${length} items, got ${value.length} items`;
2458
+ this.error(message);
2459
+ return false;
2460
+ }
2461
+ }
2462
+ const maxLength = metadata.get("expect.maxLength");
2463
+ if (maxLength !== void 0) {
2464
+ const length = typeof maxLength === "number" ? maxLength : maxLength.length;
2465
+ if (value.length > length) {
2466
+ const message = typeof maxLength === "object" && maxLength.message ? maxLength.message : `Expected maximum length of ${length} items, got ${value.length} items`;
2467
+ this.error(message);
2468
+ return false;
2469
+ }
2470
+ }
2471
+ const uniqueItems = metadata.get("expect.array.uniqueItems");
2472
+ if (uniqueItems) {
2473
+ const separator = "▼↩";
2474
+ const seen = /* @__PURE__ */ new Set();
2475
+ const keyProps = arrayKeyProps(of);
2476
+ for (let idx = 0; idx < value.length; idx++) {
2477
+ const item = value[idx];
2478
+ let key;
2479
+ if (keyProps.length > 0) {
2480
+ key = "";
2481
+ for (const prop of keyProps) key += JSON.stringify(item[prop]) + separator;
2482
+ } else key = JSON.stringify(item);
2483
+ if (seen.has(key)) {
2484
+ this.push(String(idx));
2485
+ this.error(uniqueItems.message || "Duplicate items are not allowed");
2486
+ this.pop(true);
2487
+ return false;
2488
+ }
2489
+ seen.add(key);
2490
+ }
2491
+ }
2492
+ return true;
2493
+ }
2494
+ validateObject(def, value) {
2495
+ if (typeof value !== "object" || value === null || Array.isArray(value)) {
2496
+ this.error("Expected object");
2497
+ return false;
2498
+ }
2499
+ let passed = true;
2500
+ let keysToStrip;
2501
+ const skipList = this.opts.skipList ? this.skipListHere() : void 0;
2502
+ let partialFunctionMatched = false;
2503
+ if (typeof this.opts.partial === "function") partialFunctionMatched = this.opts.partial(def, this.buildPath());
2504
+ for (const [key, item] of def.type.props.entries()) {
2505
+ if (skipList && skipList.has(key) || isPhantomType(item)) continue;
2506
+ if (value[key] === void 0) {
2507
+ if (partialFunctionMatched || this.opts.partial === "deep" || this.opts.partial === true && this.depth === 0) continue;
2508
+ }
2509
+ this.push(key);
2510
+ if (this.validateSafe(item, value[key])) this.pop(false);
2511
+ else {
2512
+ passed = false;
2513
+ this.pop(true);
2514
+ if (this.limitExceeded) return false;
2515
+ }
2516
+ }
2517
+ const hasPatterns = def.type.propsPatterns.length > 0;
2518
+ if (this.opts.unknownProps !== "ignore" || hasPatterns) {
2519
+ const keys = Object.keys(value);
2520
+ for (const key of keys) {
2521
+ if (skipList && skipList.has(key)) continue;
2522
+ const knownProp = def.type.props.get(key);
2523
+ if (knownProp && !isPhantomType(knownProp)) continue;
2524
+ const matched = [];
2525
+ for (const { pattern, def: propDef } of def.type.propsPatterns) if (pattern.test(key)) matched.push({
2526
+ pattern,
2527
+ def: propDef
2528
+ });
2529
+ if (matched.length > 0) {
2530
+ this.push(key);
2531
+ let keyPassed = false;
2532
+ const kept = this.strips.length;
2533
+ for (const { def: propDef } of matched) {
2534
+ if (this.validateSafe(propDef, value[key])) {
2535
+ keyPassed = true;
2536
+ break;
2537
+ }
2538
+ if (this.strips.length !== kept) this.strips.length = kept;
2539
+ this.clear();
2540
+ }
2541
+ if (!keyPassed) {
2542
+ this.validateSafe(matched[0].def, value[key]);
2543
+ this.pop(true);
2544
+ passed = false;
2545
+ if (this.limitExceeded) return false;
2546
+ } else this.pop(false);
2547
+ } else {
2548
+ keysToStrip = this.unknownKey(key, keysToStrip);
2549
+ if (this.opts.unknownProps === "error") {
2550
+ if (this.limitExceeded) return false;
2551
+ passed = false;
2552
+ }
2553
+ }
2554
+ }
2555
+ }
2556
+ if (passed && keysToStrip !== void 0) for (const key of keysToStrip) this.strips.push(value, key);
2557
+ return passed;
2558
+ }
2559
+ validatePrimitive(def, value) {
2560
+ if (def.type.value !== void 0) {
2561
+ if (value !== def.type.value) {
2562
+ this.error(`Expected ${def.type.value}, got ${printValue(value)}`);
2563
+ return false;
2564
+ }
2565
+ return true;
2566
+ }
2567
+ const typeOfValue = Array.isArray(value) ? "array" : typeof value;
2568
+ switch (def.type.designType) {
2569
+ case "never":
2570
+ this.error(`This type is impossible, must be an internal problem`);
2571
+ return false;
2572
+ case "any": return true;
2573
+ case "string":
2574
+ if (typeOfValue !== def.type.designType) {
2575
+ this.error(`Expected ${def.type.designType}, got ${typeOfValue}`);
2576
+ return false;
2577
+ }
2578
+ return this.validateString(def, value);
2579
+ case "number":
2580
+ if (typeOfValue !== def.type.designType) {
2581
+ this.error(`Expected ${def.type.designType}, got ${typeOfValue}`);
2582
+ return false;
2583
+ }
2584
+ if (!Number.isFinite(value)) {
2585
+ this.error(`Expected finite number, got ${value}`);
2586
+ return false;
2587
+ }
2588
+ return this.validateNumber(def, value);
2589
+ case "boolean":
2590
+ if (typeOfValue !== def.type.designType) {
2591
+ this.error(`Expected ${def.type.designType}, got ${typeOfValue}`);
2592
+ return false;
2593
+ }
2594
+ return this.validateBoolean(def, value);
2595
+ case "undefined":
2596
+ if (value !== void 0) {
2597
+ this.error(`Expected ${def.type.designType}, got ${typeOfValue}`);
2598
+ return false;
2599
+ }
2600
+ return true;
2601
+ case "null":
2602
+ if (value !== null) {
2603
+ this.error(`Expected ${def.type.designType}, got ${typeOfValue}`);
2604
+ return false;
2605
+ }
2606
+ return true;
2607
+ case "decimal":
2608
+ if (typeOfValue !== "string") {
2609
+ this.error(`Expected string (decimal), got ${typeOfValue}`);
2610
+ return false;
2611
+ }
2612
+ if (!DECIMAL_RE.test(value)) {
2613
+ this.error(`Invalid decimal format: ${JSON.stringify(value)}`);
2614
+ return false;
2615
+ }
2616
+ return true;
2617
+ default: throw new Error(`Unknown type "${def.type.designType}"`);
2618
+ }
2619
+ }
2620
+ validateString(def, value) {
2621
+ return this.validateStringConstraints(def.metadata, value);
2622
+ }
2623
+ /** `@meta.required` / `@expect.minLength` / `maxLength` / `pattern` checks for a string value. */ validateStringConstraints(meta, value) {
2624
+ const metadata = filledMeta(meta);
2625
+ if (metadata === void 0) return true;
2626
+ const filled = metadata.get("meta.required");
2627
+ if (filled) {
2628
+ if (value.trim().length === 0) {
2629
+ const message = typeof filled === "object" && filled.message ? filled.message : `Must not be empty`;
2630
+ this.error(message);
2631
+ return false;
2632
+ }
2633
+ }
2634
+ const minLength = metadata.get("expect.minLength");
2635
+ if (minLength !== void 0) {
2636
+ const length = typeof minLength === "number" ? minLength : minLength.length;
2637
+ if (value.length < length) {
2638
+ const message = typeof minLength === "object" && minLength.message ? minLength.message : `Expected minimum length of ${length} characters, got ${value.length} characters`;
2639
+ this.error(message);
2640
+ return false;
2641
+ }
2642
+ }
2643
+ const maxLength = metadata.get("expect.maxLength");
2644
+ if (maxLength !== void 0) {
2645
+ const length = typeof maxLength === "number" ? maxLength : maxLength.length;
2646
+ if (value.length > length) {
2647
+ const message = typeof maxLength === "object" && maxLength.message ? maxLength.message : `Expected maximum length of ${length} characters, got ${value.length} characters`;
2648
+ this.error(message);
2649
+ return false;
2650
+ }
2651
+ }
2652
+ const patterns = metadata.get("expect.pattern");
2653
+ for (const { pattern, flags, message } of patterns || []) {
2654
+ if (!pattern) continue;
2655
+ if (!getRegex(pattern, flags).test(value)) {
2656
+ this.error(message || `Value is expected to match pattern "${pattern}"`);
2657
+ return false;
2658
+ }
2659
+ }
2660
+ return true;
2661
+ }
2662
+ validateNumber(def, value) {
2663
+ return this.validateNumberConstraints(def.metadata, value);
2664
+ }
2665
+ /** `@expect.int` / `min` / `max` / `exclusiveMin` / `exclusiveMax` checks for a number value. */ validateNumberConstraints(meta, value) {
2666
+ const metadata = filledMeta(meta);
2667
+ if (metadata === void 0) return true;
2668
+ const int = metadata.get("expect.int");
2669
+ if (int && value % 1 !== 0) {
2670
+ const message = typeof int === "object" && int.message ? int.message : `Expected integer, got ${value}`;
2671
+ this.error(message);
2672
+ return false;
2673
+ }
2674
+ const min = metadata.get("expect.min");
2675
+ if (min !== void 0) {
2676
+ const minValue = typeof min === "number" ? min : min.minValue;
2677
+ if (value < minValue) return this.numberBoundFailed(min, "minimum", minValue, value);
2678
+ }
2679
+ const max = metadata.get("expect.max");
2680
+ if (max !== void 0) {
2681
+ const maxValue = typeof max === "number" ? max : max.maxValue;
2682
+ if (value > maxValue) return this.numberBoundFailed(max, "maximum", maxValue, value);
2683
+ }
2684
+ const exMin = metadata.get("expect.exclusiveMin");
2685
+ if (exMin !== void 0) {
2686
+ const bound = typeof exMin === "number" ? exMin : exMin.exclusiveMinValue;
2687
+ if (value <= bound) return this.numberBoundFailed(exMin, "greater than", bound, value);
2688
+ }
2689
+ const exMax = metadata.get("expect.exclusiveMax");
2690
+ if (exMax !== void 0) {
2691
+ const bound = typeof exMax === "number" ? exMax : exMax.exclusiveMaxValue;
2692
+ if (value >= bound) return this.numberBoundFailed(exMax, "less than", bound, value);
2693
+ }
2694
+ return true;
2695
+ }
2696
+ /** Reports a failed number bound: its custom message, else `Expected <label> <bound>, got <value>`. */ numberBoundFailed(annotation, label, bound, value) {
2697
+ const message = typeof annotation === "object" && annotation.message ? annotation.message : `Expected ${label} ${bound}, got ${value}`;
2698
+ this.error(message);
2699
+ return false;
2700
+ }
2701
+ validateBoolean(def, value) {
2702
+ return this.validateBooleanConstraints(def.metadata, value);
2703
+ }
2704
+ /** `@meta.required` check for a boolean value (must be `true`). */ validateBooleanConstraints(meta, value) {
2705
+ const metadata = filledMeta(meta);
2706
+ if (metadata === void 0) return true;
2707
+ const filled = metadata.get("meta.required");
2708
+ if (filled) {
2709
+ if (value !== true) {
2710
+ const message = typeof filled === "object" && filled.message ? filled.message : `Must be checked`;
2711
+ this.error(message);
2712
+ return false;
2713
+ }
2714
+ }
2715
+ return true;
2716
+ }
2717
+ constructor(def, opts) {
2718
+ _define_property(this, "def", void 0);
2719
+ _define_property(this, "opts", void 0);
2720
+ _define_property(this, "hasPlugins", void 0);
2721
+ _define_property(this, "hasReplace", void 0);
2722
+ _define_property(this, "replaceCache", void 0);
2723
+ /** Validation errors collected during the last {@link validate} call. */ _define_property(this, "errors", void 0);
2724
+ _define_property(this, "stackErrors", void 0);
2725
+ _define_property(this, "pathSegments", void 0);
2726
+ _define_property(this, "depth", void 0);
2727
+ _define_property(this, "limitExceeded", void 0);
2728
+ _define_property(this, "context", void 0);
2729
+ /**
2730
+ * The unions over objects this call decided inside union branches (value → outcomes). A union
2731
+ * nested in its own branches, many branches each, is reached again with the same value and path
2732
+ * from every branch of every union above it — (branches)^(depth) work. The memo is made once
2733
+ * the call has wasted {@link WASTE_BEFORE_MEMO} union branches (failed after branches of nested
2734
+ * unions over objects failed) since the outermost union, as in the pre-check — ordinary walks
2735
+ * never make it. It decides each such union once, with the same result and the same error object
2736
+ * (both depend only on these, the options and the input, which the walk never changes), and
2737
+ * records the same strips again.
2738
+ */ _define_property(this, "unionMemo", void 0);
2739
+ /** Union branches being checked (`> 0`: inside a union branch). */ _define_property(this, "unionDepth", void 0);
2740
+ /** Failed branches of unions over objects inside union branches (see `unionMemo`). */ _define_property(this, "nestedFailures", void 0);
2741
+ /** Wasted union branches since the outermost union was entered (see `unionMemo`). */ _define_property(this, "wasted", void 0);
2742
+ /**
2743
+ * `unknownProps: 'strip'`: the unknown keys of the objects that passed (`object, key, …`), in the
2744
+ * order the objects completed, then in key order. A rejected union branch, pattern property
2745
+ * attempt or plugin sub-validation drops what it recorded; the keys are deleted once the whole
2746
+ * call passes (`performStrips`).
2747
+ */ _define_property(this, "strips", void 0);
2748
+ /** The context the plugins get (see {@link pluginContext}), made on the first plugin call. */ _define_property(this, "pluginCtx", void 0);
2749
+ this.def = def;
2750
+ this.errors = [];
2751
+ this.stackErrors = [];
2752
+ this.pathSegments = [];
2753
+ this.depth = 0;
2754
+ this.limitExceeded = false;
2755
+ this.unionDepth = 0;
2756
+ this.nestedFailures = 0;
2757
+ this.wasted = 0;
2758
+ this.strips = [];
2759
+ this.opts = {
2760
+ partial: false,
2761
+ unknownProps: "error",
2762
+ errorLimit: 10,
2763
+ ...opts,
2764
+ plugins: opts?.plugins || []
2765
+ };
2766
+ this.hasPlugins = this.opts.plugins.length > 0;
2767
+ this.hasReplace = typeof this.opts.replace === "function";
2768
+ if (this.hasReplace) this.replaceCache = /* @__PURE__ */ new WeakMap();
2769
+ }
2770
+ };
2771
+ /** The `@meta.required` error message for `def` (custom message or the type's default). */ function requiredMessage(def) {
2772
+ const filled = def.metadata.get("meta.required");
2773
+ if (typeof filled === "object" && filled.message) return filled.message;
2774
+ return def.type.kind === "" && def.type.designType === "boolean" ? "Must be checked" : "Must not be empty";
2775
+ }
2776
+ /**
2777
+ * Element type of the array a union branch holds — through nested unions too
2778
+ * (`Items | undefined` with `type Items = Item[] | null`), so `@expect.array.key`
2779
+ * fields of the elements are found.
2780
+ */ function arrayElementType(branch) {
2781
+ const type = branch.type;
2782
+ if (type.kind === "array") return type.of;
2783
+ if (type.kind === "union") for (const item of type.items) {
2784
+ const of = arrayElementType(item);
2785
+ if (of) return of;
2786
+ }
2787
+ }
2788
+ /** `${value}` throws for symbols and null-prototype objects: `String()` handles symbols, the tag the rest. */ function printValue(value) {
2789
+ try {
2790
+ return String(value);
2791
+ } catch {
2792
+ return Object.prototype.toString.call(value);
2793
+ }
2794
+ }
2795
+ /** Error thrown by {@link Validator.validate} when validation fails. Contains structured error details. */ var ValidatorError = class extends Error {
2796
+ constructor(errors) {
2797
+ super(`${errors[0].path ? errors[0].path + ": " : ""}${errors[0].message}`), _define_property(this, "errors", void 0), _define_property(this, "name", void 0), this.errors = errors, this.name = "Validation Error";
2798
+ }
2799
+ };
2800
+
2801
+ //#endregion
2802
+ //#region packages/typescript/src/runtime/annotated-type.ts
2803
+ const COMPLEX_KINDS = new Set([
2804
+ "union",
2805
+ "intersection",
2806
+ "tuple"
2807
+ ]);
2808
+ const NON_PRIMITIVE_KINDS = new Set(["array", "object"]);
2809
+ /** Shared validator method reused by all annotated type nodes. */ function validatorMethod(opts) {
2810
+ return new Validator(this, opts);
2811
+ }
2812
+ /**
2813
+ * Creates a minimal annotated type node from a type def and metadata map.
2814
+ * Centralises the shape so callers never duplicate the boilerplate.
2815
+ *
2816
+ * `metadata` is used as-is (the node keeps the caller's map, so later writes through it
2817
+ * apply). When omitted, the node gets a new, tracked metadata map. Compiled validator
2818
+ * checks only bind to nodes whose metadata is tracked; nodes built over a caller-supplied
2819
+ * `Map` are always validated by the interpreted validator.
2820
+ */ function createAnnotatedTypeNode(type, metadata = new AnnotationMap(), opts) {
2821
+ return {
2822
+ __is_atscript_annotated_type: true,
2823
+ metadata,
2824
+ type,
2825
+ validator: validatorMethod,
2826
+ ref: opts?.ref,
2827
+ id: opts?.id,
2828
+ optional: opts?.optional
2829
+ };
2830
+ }
2831
+ /** A new tracked metadata map holding `entries` (see {@link createAnnotatedTypeNode}). */ function createMetadataMap(entries) {
2832
+ return new AnnotationMap(entries);
2833
+ }
2834
+ /**
2835
+ * The metadata map `defineAnnotatedType()` installs on `base`: `base.metadata` itself, except
2836
+ * that an absent map or an empty plain `Map` (what a generated class starts with:
2837
+ * `static metadata = new Map()`) is replaced by a new tracked map, so the node can bind to a
2838
+ * compiled validator check. A non-empty map or a `Map` subclass is always kept as-is (its
2839
+ * identity and overrides preserved; such a node stays interpreted).
2840
+ */ function baseMetadata(metadata) {
2841
+ return !metadata || Object.getPrototypeOf(metadata) === Map.prototype && metadata.size === 0 ? createMetadataMap() : metadata;
2842
+ }
2843
+ /** A new object type def (its props map is tracked, see {@link createAnnotatedTypeNode}). */ function createObjectTypeDef(tags = /* @__PURE__ */ new Set(), propsPatterns = []) {
2844
+ return {
2845
+ kind: "object",
2846
+ props: new PropsMap(),
2847
+ propsPatterns,
2848
+ tags
2849
+ };
2850
+ }
2851
+ /**
2852
+ * Type Guard to check if a type is atscript-annotated
2853
+ */ function isAnnotatedType(type) {
2854
+ return type && type.__is_atscript_annotated_type;
2855
+ }
2856
+ /**
2857
+ * Standalone annotate function that handles both replace and append (array) strategies.
2858
+ * Used by the handle's .annotate() method and by generated mutation statements.
2859
+ *
2860
+ * A layered map (a reference, an override, a merged field: see `layers.ts`) appends after the
2861
+ * values its bases give.
2862
+ */ function annotate(metadata, key, value, asArray) {
2863
+ if (!metadata) return;
2864
+ if (asArray && metadata instanceof LayerMap) {
2865
+ annotateLayer(metadata, key, value);
2866
+ return;
2867
+ }
2868
+ if (asArray) if (metadata.has(key)) appendOwn(metadata, key, metadata.get(key), value);
2869
+ else metadata.set(key, [value]);
2870
+ else metadata.set(key, value);
2871
+ }
2872
+ /** The node at prop path `chain` below `type` (through objects), `undefined` when none. */ function propAtChain(type, chain) {
2873
+ let node = type;
2874
+ for (const key of chain) node = node?.type?.kind === "object" ? node.type.props.get(key) : void 0;
2875
+ return node;
2876
+ }
2877
+ /**
2878
+ * Creates a builder handle for constructing a {@link TAtscriptAnnotatedType} at runtime.
2879
+ *
2880
+ * This is primarily used by generated `.as.js` code. The returned handle provides
2881
+ * a fluent API for setting the type definition, metadata, and properties.
2882
+ *
2883
+ * @example
2884
+ * ```ts
2885
+ * const handle = defineAnnotatedType('object')
2886
+ * .prop('name', defineAnnotatedType().designType('string').$type)
2887
+ * .prop('age', defineAnnotatedType().designType('number').$type)
2888
+ *
2889
+ * handle.$type // the resulting TAtscriptAnnotatedType
2890
+ * ```
2891
+ *
2892
+ * @param _kind - The kind of type to create (e.g. `'object'`, `'array'`, `'union'`). Defaults to `''` (primitive/final).
2893
+ * @param base - Optional existing object to augment with annotated type fields.
2894
+ * @returns A builder handle for fluent type construction.
2895
+ */ function defineAnnotatedType(_kind, base) {
2896
+ const kind = _kind || "";
2897
+ const type = base?.type || {};
2898
+ touched(type);
2899
+ type.kind = kind;
2900
+ type.tags = /* @__PURE__ */ new Set();
2901
+ if (COMPLEX_KINDS.has(kind)) type.items = [];
2902
+ if (kind === "object") {
2903
+ type.props = new PropsMap();
2904
+ type.propsPatterns = [];
2905
+ }
2906
+ const metadata = baseMetadata(base?.metadata);
2907
+ if (base && base.metadata !== metadata) metadataReplaced();
2908
+ base = base ? Object.assign(base, {
2909
+ __is_atscript_annotated_type: true,
2910
+ metadata,
2911
+ type,
2912
+ validator: validatorMethod
2913
+ }) : createAnnotatedTypeNode(type, metadata);
2914
+ return {
2915
+ $type: base,
2916
+ $def: type,
2917
+ $metadata: metadata,
2918
+ tags(...tags) {
2919
+ for (const tag of tags) this.$def.tags.add(tag);
2920
+ return this;
2921
+ },
2922
+ designType(value) {
2923
+ this.$def.designType = value;
2924
+ touched(this.$def);
2925
+ return this;
2926
+ },
2927
+ value(value) {
2928
+ this.$def.value = value;
2929
+ touched(this.$def);
2930
+ return this;
2931
+ },
2932
+ of(value) {
2933
+ this.$def.of = value;
2934
+ touched(this.$def);
2935
+ return this;
2936
+ },
2937
+ item(value) {
2938
+ this.$def.items.push(value);
2939
+ touched(this.$def);
2940
+ return this;
2941
+ },
2942
+ prop(name, value) {
2943
+ this.$def.props.set(name, value);
2944
+ return this;
2945
+ },
2946
+ propPattern(pattern, def) {
2947
+ this.$def.propsPatterns.push({
2948
+ pattern: statelessRegExp(pattern),
2949
+ def
2950
+ });
2951
+ touched(this.$def);
2952
+ return this;
2953
+ },
2954
+ optional(value = true) {
2955
+ this.$type.optional = value;
2956
+ touched(this.$type);
2957
+ return this;
2958
+ },
2959
+ copyMetadata(fromMetadata, ignore) {
2960
+ for (const [key, value] of fromMetadata.entries()) if (!ignore || !ignore.has(key)) this.$metadata.set(key, value);
2961
+ return this;
2962
+ },
2963
+ ref(target, chain) {
2964
+ var _node;
2965
+ const at = $ft(target, ...chain ?? []);
2966
+ const node = this.$type;
2967
+ touched(node);
2968
+ node.type = at.type;
2969
+ node.ref = {
2970
+ type: () => target,
2971
+ field: chain ? fieldOf(chain) : ""
2972
+ };
2973
+ (_node = node).id ?? (_node.id = at.id);
2974
+ return this.over([at], true);
2975
+ },
2976
+ over(bases, reference) {
2977
+ for (const b of bases) readyNode(b);
2978
+ const node = this.$type;
2979
+ touched(node);
2980
+ const metadata = new LayerMap(bases, reference, ownEntries(this.$metadata));
2981
+ moveIntrinsic(this.$metadata, metadata);
2982
+ node.metadata = metadata;
2983
+ this.$metadata = metadata;
2984
+ metadataReplaced();
2985
+ return this;
2986
+ },
2987
+ type(of) {
2988
+ const node = this.$type;
2989
+ touched(node);
2990
+ node.type = readyNode(of).type;
2991
+ return this;
2992
+ },
2993
+ annotate(key, value, asArray) {
2994
+ annotate(this.$metadata, key, value, asArray);
2995
+ return this;
2996
+ },
2997
+ intrinsic(...keys) {
2998
+ markIntrinsic(this.$metadata, keys);
2999
+ return this;
3000
+ },
3001
+ id(value) {
3002
+ this.$type.id = value;
3003
+ return this;
3004
+ }
3005
+ };
3006
+ }
3007
+ /**
3008
+ * Checks whether an annotated type is a phantom type.
3009
+ *
3010
+ * Phantom types do not affect the data type, validation, or schema,
3011
+ * but are discoverable via runtime type traversal.
3012
+ */ function isPhantomType(def) {
3013
+ return def.type.kind === "" && def.type.designType === "phantom";
3014
+ }
3015
+ /**
3016
+ * Checks whether an annotated type resolves to a primitive (non-object, non-array) shape.
3017
+ *
3018
+ * Returns `true` for final types and for unions/intersections/tuples
3019
+ * whose members are all primitives.
3020
+ */ function isAnnotatedTypeOfPrimitive(t) {
3021
+ if (NON_PRIMITIVE_KINDS.has(t.type.kind)) return false;
3022
+ if (!t.type.kind) return true;
3023
+ if (COMPLEX_KINDS.has(t.type.kind)) {
3024
+ for (const item of t.type.items) if (!isAnnotatedTypeOfPrimitive(item)) return false;
3025
+ return true;
3026
+ }
3027
+ return false;
3028
+ }
3029
+
3030
+ //#endregion
3031
+ //#region packages/typescript/src/runtime/cut.ts
3032
+ var _globalThis, _Symbol_for;
3033
+ /**
3034
+ * Defs standing for another one to the cut (a shell's def → the def it shells; a deserialized
3035
+ * def → its payload tag's token). Shared by every copy of the runtime (types built by one, read
3036
+ * by another).
3037
+ */ const origins = (_globalThis = globalThis)[_Symbol_for = Symbol.for("@atscript/typescript:cut-origins:1")] ?? (_globalThis[_Symbol_for] = /* @__PURE__ */ new WeakMap());
3038
+ /** Def `copy` stands for def `of` to the cut (for what `of` stands for). */ function cutAs(copy, of) {
3039
+ origins.set(copy, typeof of === "object" && of !== null && origins.get(of) || of);
3040
+ }
3041
+ /** The cut key of `node` (see above). */ function cutKey(node) {
3042
+ const def = node.type;
3043
+ return node.id ?? origins.get(def) ?? def;
3044
+ }
3045
+ /** Whether `key` is expanded on `path`. */ function onPath(path, key) {
3046
+ for (let p = path; p; p = p.up) if (p.key === key) return true;
3047
+ return false;
3048
+ }
3049
+ /** The path below `node` reached on `path`; `false` where `node` is cut. */ function enterCut(path, node) {
3050
+ if (node.type.kind === "") return path;
3051
+ const key = cutKey(node);
3052
+ return onPath(path, key) ? false : {
3053
+ key,
3054
+ up: path
3055
+ };
3056
+ }
3057
+
3058
+ //#endregion
3059
+ //#region packages/typescript/src/runtime/blocks.ts
3060
+ /**
3061
+ * The runtime helpers of the generated structure: node lookup (`$f`),
3062
+ * annotated aliases and `as` copies (`$alias`), shells (`$sh`), blocks with static ranks
3063
+ * (`$blk`) and the import-cycle queue (`$q` / `$end`). Merges are not computed here: the
3064
+ * generated code prints their final structure (hidden classes, `.over` layers).
3065
+ */
3066
+ /**
3067
+ * Thrown when a statement reads what is not built yet (a class of an import cycle's module still
3068
+ * evaluating, a CommonJS cycle's `undefined` import, a def without its props): `$q` queues it.
3069
+ */ const NOT_READY = /* @__PURE__ */ new Error("atscript: type not built yet");
3070
+ /**
3071
+ * `x` as an annotated type whose def can be read, else `NOT_READY`: a class of an import cycle's
3072
+ * module not evaluated yet (CommonJS: `undefined`), or an alias class (declared with
3073
+ * `type = null`) before its `$alias` ran.
3074
+ */ function readyNode(x) {
3075
+ if (!isAnnotatedType(x) || x.type === null || x.type === void 0) throw NOT_READY;
3076
+ return x;
3077
+ }
3078
+ /** `x` as a built class (its builder ran: its def has a kind), else `NOT_READY`. */ function builtNode(x) {
3079
+ const n = readyNode(x);
3080
+ if (n.type.kind === void 0) throw NOT_READY;
3081
+ return n;
3082
+ }
3083
+ /** The child of `n` at step `s`: a prop, `[]` (array element) or `|i` (union / tuple item i). */ function child(n, s) {
3084
+ const t = n.type;
3085
+ if (!t?.kind) return;
3086
+ if (s === "[]") return t.of;
3087
+ if (s[0] === "|") return t.items?.[Number(s.slice(1))];
3088
+ return t.props?.get(s) ?? t.propsPatterns?.find((p) => patternStep(p.pattern) === s)?.def;
3089
+ }
3090
+ /** The step naming prop pattern `re` (`*` is `/./`). */ function patternStep(re) {
3091
+ return re.source === "." && re.flags === "" ? "*" : `/${re.source}/${re.flags}`;
3092
+ }
3093
+ /** A chain's `ref.field`: its props (`a.b`), without the union steps a nullable one takes. */ function fieldOf(chain) {
3094
+ return chain.filter((s) => s[0] !== "|").join(".");
3095
+ }
3096
+ /**
3097
+ * The node at `path` below `root` (see {@link child}); `NOT_READY` while it is not built, or
3098
+ * while a pending shell (an import cycle's, see {@link $ps}) would replace it.
3099
+ */ function $f(root, ...path) {
3100
+ return nodeAt(root, path, PLAIN);
3101
+ }
3102
+ /** {@link $f} for a reader of the node's def (`.ref(T, chain)`, `$alias`): its final def. */ function $ft(root, ...path) {
3103
+ return nodeAt(root, path, TYPED);
3104
+ }
3105
+ /** {@link $f} for a shell that clones the node's def: once every shell put into it (a guard). */ function $fc(root, ...path) {
3106
+ return nodeAt(root, path, CLONED);
3107
+ }
3108
+ /** How a read uses the node (see {@link changedBy}). */ const PLAIN = 0;
3109
+ const TYPED = 1;
3110
+ const CLONED = 2;
3111
+ function nodeAt(root, path, typed) {
3112
+ let n = readyNode(root);
3113
+ const shells = pendingShells.get(n);
3114
+ if (shells && changedBy(shells, path, typed)) throw NOT_READY;
3115
+ for (const s of path) {
3116
+ const c = child(n, s);
3117
+ if (!c) throw NOT_READY;
3118
+ n = c;
3119
+ }
3120
+ const t = n.type;
3121
+ if (typed !== PLAIN && t.kind === "" && t.designType === void 0) throw NOT_READY;
3122
+ return n;
3123
+ }
3124
+ /**
3125
+ * Class `P` is `T` with annotations of its own (an annotated alias, an `annotate T as P` copy;
3126
+ * `chain`: `type P = T.a.b`, a chain ref): T's def (at `chain`), and metadata layered over it
3127
+ * (P's own entries kept; a chain ref is a reference layer).
3128
+ */ function $alias(P, T, chain) {
3129
+ var _node, _node1;
3130
+ const root = readyNode(T);
3131
+ const target = readyNode($ft(root, ...chain ?? []));
3132
+ const node = P;
3133
+ touched(node);
3134
+ node.type = target.type;
3135
+ const own = node.metadata;
3136
+ node.metadata = new LayerMap([target], !!chain, ownEntries(node.metadata));
3137
+ moveIntrinsic(own, node.metadata);
3138
+ metadataReplaced();
3139
+ const recs = records.get(own);
3140
+ if (recs) records.set(node.metadata, recs);
3141
+ node.ref = {
3142
+ type: () => root,
3143
+ field: chain ? fieldOf(chain) : ""
3144
+ };
3145
+ (_node = node).id ?? (_node.id = target.id);
3146
+ (_node1 = node).validator ?? (_node1.validator = validatorMethod);
3147
+ return node;
3148
+ }
3149
+ /** Shell nodes → the def they were put in (a shell is its position's: the exact path). */ const shellIn = /* @__PURE__ */ new WeakMap();
3150
+ /**
3151
+ * Shell defs → the node they were made for: a shell node over a node with a shell def starts
3152
+ * with that def, and gets its own on its first step of kind 2 (the exact path).
3153
+ */ const shellDefOf = /* @__PURE__ */ new WeakMap();
3154
+ /**
3155
+ * A shell node over `base`: metadata layered over base; its def IS base's def (a reference, read
3156
+ * when used: a def base gets later — a clone a shell of another class puts in — is the shell's
3157
+ * too) until a step below it gives the shell a def of its own (kind 2: `type` is assigned).
3158
+ */ function shellNode(base) {
3159
+ const node = {
3160
+ __is_atscript_annotated_type: true,
3161
+ metadata: new LayerMap([base])
3162
+ };
3163
+ Object.defineProperty(node, SHELL, { value: {
3164
+ b: base,
3165
+ t: void 0,
3166
+ id: void 0,
3167
+ ref: void 0
3168
+ } });
3169
+ Object.defineProperty(node, "type", SHELL_TYPE);
3170
+ node.validator = validatorMethod;
3171
+ Object.defineProperty(node, "ref", SHELL_REF);
3172
+ Object.defineProperty(node, "id", SHELL_ID);
3173
+ node.optional = base.optional;
3174
+ return node;
3175
+ }
3176
+ /** A shell node's own state: its base, and the def / ref / id it was given (`undefined`: base's). */ const SHELL = Symbol("shell");
3177
+ const SHELL_TYPE = {
3178
+ get() {
3179
+ const s = this[SHELL];
3180
+ return s.t ?? s.b.type;
3181
+ },
3182
+ set(d) {
3183
+ this[SHELL].t = d;
3184
+ },
3185
+ enumerable: true,
3186
+ configurable: true
3187
+ };
3188
+ const SHELL_REF = {
3189
+ get() {
3190
+ const s = this[SHELL];
3191
+ return s.ref ? s.ref.v : s.b.ref;
3192
+ },
3193
+ set(v) {
3194
+ this[SHELL].ref = { v };
3195
+ },
3196
+ enumerable: true,
3197
+ configurable: true
3198
+ };
3199
+ const SHELL_ID = {
3200
+ get() {
3201
+ const s = this[SHELL];
3202
+ return s.id ? s.id.v : s.b.id;
3203
+ },
3204
+ set(v) {
3205
+ this[SHELL].id = { v };
3206
+ },
3207
+ enumerable: true,
3208
+ configurable: true
3209
+ };
3210
+ /** A def of node `holder`'s with the same entries as `d` (its children replaceable by shells). */ function shellDef(d, holder) {
3211
+ const c = { ...d };
3212
+ if (d.tags) c.tags = new Set(d.tags);
3213
+ if (d.props) {
3214
+ c.props = new PropsMap(d.props);
3215
+ c.propsPatterns = [...d.propsPatterns ?? []];
3216
+ }
3217
+ if (d.items) c.items = [...d.items];
3218
+ shellDefOf.set(c, holder);
3219
+ cutAs(c, d);
3220
+ return c;
3221
+ }
3222
+ /** Puts `node` at step `s` of def `d`. */ function put(d, s, node) {
3223
+ if (s === "[]") {
3224
+ d.of = node;
3225
+ touched(d);
3226
+ } else if (s[0] === "|") {
3227
+ d.items[Number(s.slice(1))] = node;
3228
+ touched(d);
3229
+ } else d.props.set(s, node);
3230
+ }
3231
+ /**
3232
+ * The node of `T` at `path`, with T's own shells along it (idempotent). Step kinds:
3233
+ * 0 — the def and the child are T's own (descend); 1 — the def is T's, the child is not (a shell
3234
+ * node replaces it); 2 — the def is not T's (the node gets a shell def first, then as 1).
3235
+ */ function ensure(T, path) {
3236
+ let cur = T;
3237
+ for (const [s, kind] of path) {
3238
+ let c = child(cur, s);
3239
+ if (!c) throw NOT_READY;
3240
+ if (kind === 2 && shellDefOf.get(cur.type) !== cur) {
3241
+ touched(cur);
3242
+ cur.type = shellDef(cur.type, cur);
3243
+ }
3244
+ if (kind !== 0 && shellIn.get(c) !== cur.type) {
3245
+ c = shellNode(c);
3246
+ put(cur.type, s, c);
3247
+ shellIn.set(c, cur.type);
3248
+ }
3249
+ cur = c;
3250
+ }
3251
+ return cur;
3252
+ }
3253
+ /** Ensures T's shells along each path (see {@link ensure}). */ function $sh(T, paths) {
3254
+ const target = builtNode(T);
3255
+ for (const path of paths) ensure(target, path);
3256
+ const pending = pendingShells.get(target);
3257
+ if (pending) {
3258
+ const done = new Set(paths.flatMap(stagesOf).map((p) => JSON.stringify(p)));
3259
+ const rest = pending.filter((p) => !done.has(JSON.stringify(p)));
3260
+ if (rest.length > 0) pendingShells.set(target, rest);
3261
+ else pendingShells.delete(target);
3262
+ }
3263
+ }
3264
+ /**
3265
+ * The shells a class of an import cycle's module will get (`$sh` runs once what they shell is
3266
+ * built): a read through a node they replace, or into a def they clone, waits for them.
3267
+ */ const pendingShells = /* @__PURE__ */ new WeakMap();
3268
+ /** Registers class `T`'s shells as pending (see {@link $sh}): first statement of its module. */ function $ps(T, paths) {
3269
+ const seen = /* @__PURE__ */ new Set();
3270
+ pendingShells.set(T, paths.flatMap(stagesOf).filter((p) => {
3271
+ const k = JSON.stringify(p);
3272
+ return !seen.has(k) && !!seen.add(k);
3273
+ }));
3274
+ }
3275
+ /**
3276
+ * The last step index of each stage of shell path `path` (see {@link stagesOf}): every step that
3277
+ * shells, and the path's last (the build's stage index walks them too, `js-next.ts`
3278
+ * `shellPathsOf`).
3279
+ */ function stageEnds(path) {
3280
+ return path.flatMap(([, kind], j) => kind !== 0 || j === path.length - 1 ? [j] : []);
3281
+ }
3282
+ /** The stages of shell path `path`: each prefix ending at a step that shells, and the path. */ function stagesOf(path) {
3283
+ return stageEnds(path).map((j) => path.slice(0, j + 1));
3284
+ }
3285
+ /**
3286
+ * Whether a read at `path` meets what pending shell stages change: a stage (a shell path up to a
3287
+ * step of kind 1 / 2) replaces the node at its end in the def above it (kind 2: in a clone of
3288
+ * that def). A read through that node waits; a read of the def above it waits for a clone
3289
+ * (`TYPED`: it captures the def) or for any stage (`CLONED`: it copies the def's entries).
3290
+ */ function changedBy(shells, path, typed) {
3291
+ for (const s of shells) {
3292
+ const n = s.length;
3293
+ let i = 0;
3294
+ while (i < n && i < path.length && path[i] === s[i][0]) i++;
3295
+ if (i === n || typed !== PLAIN && i === n - 1 && path.length === n - 1 && (typed === CLONED || s[n - 1][1] === 2)) return true;
3296
+ }
3297
+ return false;
3298
+ }
3299
+ function compare(a, b) {
3300
+ return a[0] - b[0] || (a[1] < b[1] ? -1 : a[1] > b[1] ? 1 : 0) || a[2] - b[2] || a[3] - b[3];
3301
+ }
3302
+ const records = /* @__PURE__ */ new WeakMap();
3303
+ function recordsOf(m) {
3304
+ let r = records.get(m);
3305
+ if (!r) records.set(m, r = /* @__PURE__ */ new Map());
3306
+ return r;
3307
+ }
3308
+ /**
3309
+ * A block write of a replace key: ignored when the own value is one a higher-ranked block wrote
3310
+ * (a raw write since makes it nobody's: the block applies).
3311
+ */ function writeKey(m, key, value, rank) {
3312
+ const recs = recordsOf(m);
3313
+ const r = recs.get(key);
3314
+ if (r && ownValue(m, key) === r.value && compare(r.rank, rank) > 0) return;
3315
+ m.set(key, value);
3316
+ recs.set(key, {
3317
+ rank,
3318
+ value
3319
+ });
3320
+ }
3321
+ /**
3322
+ * A block write of an append key: the own list is the elements written before any block (by
3323
+ * the builder, or a raw write since), then every block's part by rank.
3324
+ */ function appendKey(m, key, values, rank) {
3325
+ const recs = recordsOf(m);
3326
+ let r = recs.get(key);
3327
+ const own = ownValue(m, key);
3328
+ if (!r || own !== r.value || r.value.length !== r.length) {
3329
+ const before = own === void 0 ? [] : Array.isArray(own) ? [...own] : [own];
3330
+ r = {
3331
+ before,
3332
+ parts: [],
3333
+ value: before,
3334
+ length: 0
3335
+ };
3336
+ }
3337
+ const { parts } = r;
3338
+ let at = 0;
3339
+ while (at < parts.length && compare(parts[at].rank, rank) < 0) at++;
3340
+ if (at < parts.length && compare(parts[at].rank, rank) === 0) parts[at].values = values;
3341
+ else parts.splice(at, 0, {
3342
+ rank,
3343
+ values
3344
+ });
3345
+ const value = [...r.before];
3346
+ for (const p of parts) value.push(...p.values);
3347
+ m.set(key, value);
3348
+ r.value = value;
3349
+ r.length = value.length;
3350
+ recs.set(key, r);
3351
+ }
3352
+ function writeEntry(m, anns, rank) {
3353
+ const values = /* @__PURE__ */ new Map();
3354
+ for (const [key, value, list] of anns) if (list) {
3355
+ const xs = values.get(key);
3356
+ values.set(key, xs ? [...xs, value] : [value]);
3357
+ } else values.set(key, value);
3358
+ for (const [key, value] of values) if (isAppendKey(key)) appendKey(m, key, Array.isArray(value) ? value : [value], rank);
3359
+ else writeKey(m, key, value, rank);
3360
+ }
3361
+ /** The module ids of the blocks applied (the bundled-schema guard reads them). */ const applied = /* @__PURE__ */ new Set();
3362
+ /** The module ids of every block applied so far. */ function appliedBlockModules() {
3363
+ return applied;
3364
+ }
3365
+ /**
3366
+ * Block `index` of a module of rank `R` (`[import depth, module id]`; `null`: an `as` copy's
3367
+ * entries, below every block) on `T`: ensures each entry's shells, then writes its annotations
3368
+ * with rank (R, index, entry index). Re-applying a block is idempotent.
3369
+ */ function $blk(R, index, T, entries) {
3370
+ const target = builtNode(T);
3371
+ const nodes = entries.map(([, ...paths]) => paths.map((path) => ensure(target, path)));
3372
+ entries.forEach(([anns], e) => {
3373
+ const rank = R ? [
3374
+ R[0],
3375
+ R[1],
3376
+ index,
3377
+ e
3378
+ ] : [
3379
+ -1,
3380
+ "",
3381
+ index,
3382
+ e
3383
+ ];
3384
+ for (const node of nodes[e]) writeEntry(node.metadata, anns, rank);
3385
+ });
3386
+ if (R) applied.add(R[1]);
3387
+ }
3388
+ const queue = [];
3389
+ /**
3390
+ * Whether `e` is a statement's wait — a class not built yet (`NOT_READY`), a binding in its
3391
+ * temporal dead zone — rather than its failure.
3392
+ */ const isWait = (e) => e === NOT_READY || e instanceof ReferenceError;
3393
+ /**
3394
+ * Runs `fn` (a statement reading a class of another module of its import cycle), or queues it
3395
+ * when that class is not built yet (ESM: its temporal dead zone; CommonJS: `undefined`). `own`:
3396
+ * the module's own list of queued statements (a module in no import cycle, see {@link $end}).
3397
+ */ function $q(fn, own) {
3398
+ try {
3399
+ fn();
3400
+ } catch (error) {
3401
+ if (!isWait(error)) throw error;
3402
+ queue.push(fn);
3403
+ own?.push(fn);
3404
+ }
3405
+ }
3406
+ /**
3407
+ * The last statement of a module: runs the queued statements that can run now, in order. A module
3408
+ * in no import cycle passes its own queued statements (`own`, see {@link $q}) and throws when one
3409
+ * of them still waits: nothing it waits for can come later. (A module of an import cycle is
3410
+ * checked when the build loads the cycle from each of its modules.)
3411
+ */ function $end(own) {
3412
+ let progress = true;
3413
+ while (progress && queue.length > 0) {
3414
+ progress = false;
3415
+ for (let i = 0; i < queue.length;) {
3416
+ try {
3417
+ queue[i]();
3418
+ } catch (error) {
3419
+ if (isWait(error)) {
3420
+ i++;
3421
+ continue;
3422
+ }
3423
+ queue.splice(i, 1);
3424
+ throw error;
3425
+ }
3426
+ queue.splice(i, 1);
3427
+ progress = true;
3428
+ }
3429
+ }
3430
+ const left = own?.filter((fn) => queue.includes(fn)) ?? [];
3431
+ if (left.length > 0) {
3432
+ for (const fn of left) queue.splice(queue.indexOf(fn), 1);
3433
+ throw new Error(`atscript: ${left.length} statement(s) of this module never ran: they wait for each other (an internal code generation error: please report it)`);
3434
+ }
3435
+ }
3436
+ /** How many statements wait for a class of an import cycle (0 once every module loaded). */ function pendingStatements() {
3437
+ return queue.length;
3438
+ }
3439
+
3440
+ //#endregion
3441
+ //#region packages/typescript/src/runtime/unique-name.ts
3442
+ /**
3443
+ * `base`, or — when `taken` reports it taken — the first `<base><sep><n>` (n = 1, 2, …) it
3444
+ * does not.
3445
+ */ function uniqueName(base, taken, sep) {
3446
+ let name = base;
3447
+ for (let n = 1; taken(name); n++) name = `${base}${sep}${n}`;
3448
+ return name;
3449
+ }
3450
+
3451
+ //#endregion
3452
+ Object.defineProperty(exports, '$ak', {
3453
+ enumerable: true,
3454
+ get: function () {
3455
+ return $ak;
3456
+ }
3457
+ });
3458
+ Object.defineProperty(exports, '$alias', {
3459
+ enumerable: true,
3460
+ get: function () {
3461
+ return $alias;
3462
+ }
3463
+ });
3464
+ Object.defineProperty(exports, '$blk', {
3465
+ enumerable: true,
3466
+ get: function () {
3467
+ return $blk;
3468
+ }
3469
+ });
3470
+ Object.defineProperty(exports, '$end', {
3471
+ enumerable: true,
3472
+ get: function () {
3473
+ return $end;
3474
+ }
3475
+ });
3476
+ Object.defineProperty(exports, '$f', {
3477
+ enumerable: true,
3478
+ get: function () {
3479
+ return $f;
3480
+ }
3481
+ });
3482
+ Object.defineProperty(exports, '$fc', {
3483
+ enumerable: true,
3484
+ get: function () {
3485
+ return $fc;
3486
+ }
3487
+ });
3488
+ Object.defineProperty(exports, '$ft', {
3489
+ enumerable: true,
3490
+ get: function () {
3491
+ return $ft;
3492
+ }
3493
+ });
3494
+ Object.defineProperty(exports, '$nr', {
3495
+ enumerable: true,
3496
+ get: function () {
3497
+ return $nr;
3498
+ }
3499
+ });
3500
+ Object.defineProperty(exports, '$ps', {
3501
+ enumerable: true,
3502
+ get: function () {
3503
+ return $ps;
3504
+ }
3505
+ });
3506
+ Object.defineProperty(exports, '$q', {
3507
+ enumerable: true,
3508
+ get: function () {
3509
+ return $q;
3510
+ }
3511
+ });
3512
+ Object.defineProperty(exports, '$sh', {
3513
+ enumerable: true,
3514
+ get: function () {
3515
+ return $sh;
3516
+ }
3517
+ });
3518
+ Object.defineProperty(exports, 'DECIMAL_RE', {
3519
+ enumerable: true,
3520
+ get: function () {
3521
+ return DECIMAL_RE;
3522
+ }
3523
+ });
3524
+ Object.defineProperty(exports, 'LayerMap', {
3525
+ enumerable: true,
3526
+ get: function () {
3527
+ return LayerMap;
3528
+ }
3529
+ });
3530
+ Object.defineProperty(exports, 'VALIDATOR_KEYS', {
3531
+ enumerable: true,
3532
+ get: function () {
3533
+ return VALIDATOR_KEYS;
3534
+ }
3535
+ });
3536
+ Object.defineProperty(exports, 'Validator', {
3537
+ enumerable: true,
3538
+ get: function () {
3539
+ return Validator;
3540
+ }
3541
+ });
3542
+ Object.defineProperty(exports, 'ValidatorError', {
3543
+ enumerable: true,
3544
+ get: function () {
3545
+ return ValidatorError;
3546
+ }
3547
+ });
3548
+ Object.defineProperty(exports, 'annotate', {
3549
+ enumerable: true,
3550
+ get: function () {
3551
+ return annotate;
3552
+ }
3553
+ });
3554
+ Object.defineProperty(exports, 'appliedBlockModules', {
3555
+ enumerable: true,
3556
+ get: function () {
3557
+ return appliedBlockModules;
3558
+ }
3559
+ });
3560
+ Object.defineProperty(exports, 'arrayKeyProps', {
3561
+ enumerable: true,
3562
+ get: function () {
3563
+ return arrayKeyProps;
3564
+ }
3565
+ });
3566
+ Object.defineProperty(exports, 'boundOf', {
3567
+ enumerable: true,
3568
+ get: function () {
3569
+ return boundOf;
3570
+ }
3571
+ });
3572
+ Object.defineProperty(exports, 'createAnnotatedTypeNode', {
3573
+ enumerable: true,
3574
+ get: function () {
3575
+ return createAnnotatedTypeNode;
3576
+ }
3577
+ });
3578
+ Object.defineProperty(exports, 'createMetadataMap', {
3579
+ enumerable: true,
3580
+ get: function () {
3581
+ return createMetadataMap;
3582
+ }
3583
+ });
3584
+ Object.defineProperty(exports, 'createObjectTypeDef', {
3585
+ enumerable: true,
3586
+ get: function () {
3587
+ return createObjectTypeDef;
3588
+ }
3589
+ });
3590
+ Object.defineProperty(exports, 'cutAs', {
3591
+ enumerable: true,
3592
+ get: function () {
3593
+ return cutAs;
3594
+ }
3595
+ });
3596
+ Object.defineProperty(exports, 'cutKey', {
3597
+ enumerable: true,
3598
+ get: function () {
3599
+ return cutKey;
3600
+ }
3601
+ });
3602
+ Object.defineProperty(exports, 'defineAnnotatedType', {
3603
+ enumerable: true,
3604
+ get: function () {
3605
+ return defineAnnotatedType;
3606
+ }
3607
+ });
3608
+ Object.defineProperty(exports, 'enterCut', {
3609
+ enumerable: true,
3610
+ get: function () {
3611
+ return enterCut;
3612
+ }
3613
+ });
3614
+ Object.defineProperty(exports, 'invalidateCompiledValidators', {
3615
+ enumerable: true,
3616
+ get: function () {
3617
+ return invalidateCompiledValidators;
3618
+ }
3619
+ });
3620
+ Object.defineProperty(exports, 'isAnnotatedType', {
3621
+ enumerable: true,
3622
+ get: function () {
3623
+ return isAnnotatedType;
3624
+ }
3625
+ });
3626
+ Object.defineProperty(exports, 'isAnnotatedTypeOfPrimitive', {
3627
+ enumerable: true,
3628
+ get: function () {
3629
+ return isAnnotatedTypeOfPrimitive;
3630
+ }
3631
+ });
3632
+ Object.defineProperty(exports, 'isPhantomType', {
3633
+ enumerable: true,
3634
+ get: function () {
3635
+ return isPhantomType;
3636
+ }
3637
+ });
3638
+ Object.defineProperty(exports, 'jsonSchemaPattern', {
3639
+ enumerable: true,
3640
+ get: function () {
3641
+ return jsonSchemaPattern;
3642
+ }
3643
+ });
3644
+ Object.defineProperty(exports, 'metaEmpty', {
3645
+ enumerable: true,
3646
+ get: function () {
3647
+ return metaEmpty;
3648
+ }
3649
+ });
3650
+ Object.defineProperty(exports, 'metadataWriteCount', {
3651
+ enumerable: true,
3652
+ get: function () {
3653
+ return metadataWriteCount;
3654
+ }
3655
+ });
3656
+ Object.defineProperty(exports, 'pendingStatements', {
3657
+ enumerable: true,
3658
+ get: function () {
3659
+ return pendingStatements;
3660
+ }
3661
+ });
3662
+ Object.defineProperty(exports, 'propAtChain', {
3663
+ enumerable: true,
3664
+ get: function () {
3665
+ return propAtChain;
3666
+ }
3667
+ });
3668
+ Object.defineProperty(exports, 'registerCompiledCheck', {
3669
+ enumerable: true,
3670
+ get: function () {
3671
+ return registerCompiledCheck;
3672
+ }
3673
+ });
3674
+ Object.defineProperty(exports, 'stageEnds', {
3675
+ enumerable: true,
3676
+ get: function () {
3677
+ return stageEnds;
3678
+ }
3679
+ });
3680
+ Object.defineProperty(exports, 'statelessRegExp', {
3681
+ enumerable: true,
3682
+ get: function () {
3683
+ return statelessRegExp;
3684
+ }
3685
+ });
3686
+ Object.defineProperty(exports, 'touched', {
3687
+ enumerable: true,
3688
+ get: function () {
3689
+ return touched;
3690
+ }
3691
+ });
3692
+ Object.defineProperty(exports, 'uniqueName', {
3693
+ enumerable: true,
3694
+ get: function () {
3695
+ return uniqueName;
3696
+ }
3697
+ });
3698
+ Object.defineProperty(exports, 'watchLayer', {
3699
+ enumerable: true,
3700
+ get: function () {
3701
+ return watchLayer;
3702
+ }
3703
+ });