@orkestrel/contract 0.0.19 → 0.0.21

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.
@@ -1,4 +1,4 @@
1
- //#region src/core/constants.ts
1
+ // src/core/constants.ts
2
2
  /**
3
3
  * Holds the registry-global key used to recognize {@link ContractError} values
4
4
  * across package copies.
@@ -9,7 +9,7 @@
9
9
  * own. The registry makes the key discoverable; it is a recognition mechanism,
10
10
  * not an unforgeable provenance marker.
11
11
  */
12
- var CONTRACT_ERROR_BRAND = Symbol.for("@orkestrel/contract.error");
12
+ var CONTRACT_ERROR_BRAND = Symbol.for("@orkestrel/contract.ContractError");
13
13
  /**
14
14
  * Captures every host operation this package dispatches through, while this
15
15
  * module evaluates.
@@ -91,10 +91,14 @@ var INTRINSICS = Object.freeze({
91
91
  same: Object.is,
92
92
  /** Captures `Object.create` — the null-prototype and prototype-pinned accumulators. */
93
93
  create: Object.create,
94
+ /** Captures `Proxy` for non-array indexed views. */
95
+ proxy: Proxy,
94
96
  /** Captures `Object.getOwnPropertyDescriptor` — value observation that runs no accessor. */
95
97
  describe: Object.getOwnPropertyDescriptor,
96
98
  /** Captures `Object.defineProperty` — exact placement of an own data property. */
97
99
  define: Object.defineProperty,
100
+ /** Captures `Object.defineProperties` — sparse snapshot construction. */
101
+ definitions: Object.defineProperties,
98
102
  /** Captures `Object.getPrototypeOf` — the record-brand observation. */
99
103
  prototype: Object.getPrototypeOf,
100
104
  /** Captures `Object.getOwnPropertySymbols` — the own-symbol population. */
@@ -184,6 +188,40 @@ var INTRINSICS = Object.freeze({
184
188
  list: Array,
185
189
  /** Captures `Array.prototype.sort` — the deterministic ordering every published schema is emitted in, dispatched through `apply`. */
186
190
  order: Array.prototype.sort,
191
+ /** Captures `Array.prototype.some` for short-circuit membership checks. */
192
+ some: Array.prototype.some,
193
+ /** Captures `Array.prototype.findIndex`, including reads of sparse positions. */
194
+ find: Array.prototype.findIndex,
195
+ /** Captures `Array.prototype.forEach` for indexed visits of owned arrays. */
196
+ each: Array.prototype.forEach,
197
+ /** Captures `Array.from` for ordered array construction. */
198
+ from: Array.from,
199
+ /** Captures `Array.prototype.reduce` for derived aggregate values. */
200
+ fold: Array.prototype.reduce,
201
+ /** Captures `Iterator.prototype.reduce` — ordered lazy reduction. */
202
+ reduce: Iterator.prototype.reduce,
203
+ /** Captures `Array.prototype.filter` for derived selections. */
204
+ select: Array.prototype.filter,
205
+ /** Captures `Array.prototype.map` for derived projections. */
206
+ project: Array.prototype.map,
207
+ /** Captures `Array.prototype.flatMap` — ordered list expansion. */
208
+ expand: Array.prototype.flatMap,
209
+ /** Captures `Array.prototype.toReversed` — reverse-order derivation. */
210
+ flip: Array.prototype.toReversed,
211
+ /** Captures `Array.prototype.values` for owned iterable construction. */
212
+ iterator: Array.prototype.values,
213
+ /** Captures `Array.prototype.keys` — an indexed cursor that reads length per step. */
214
+ indices: Array.prototype.keys,
215
+ /** Captures the native array iterator advance operation. */
216
+ advance: Object.getPrototypeOf([][Symbol.iterator]()).next,
217
+ /** Captures `Array.prototype.join` — text assembly from derived parts. */
218
+ join: Array.prototype.join,
219
+ /** Captures `Function.prototype.bind` for a receiver-bound host operation. */
220
+ bind: Function.prototype.bind,
221
+ /** Captures `Object.fromEntries` for derived records. */
222
+ record: Object.fromEntries,
223
+ /** Captures `Object.setPrototypeOf` for owned record prototypes. */
224
+ rebase: Object.setPrototypeOf,
187
225
  /** Captures `Map` — keyed working state. */
188
226
  map: Map,
189
227
  /** Captures `Map.prototype.get` — a memo read whose answer a published graph embeds, dispatched through `apply`. */
@@ -196,12 +234,16 @@ var INTRINSICS = Object.freeze({
196
234
  pairs: Map.prototype.forEach,
197
235
  /** Captures `Set` — membership working state. */
198
236
  set: Set,
237
+ /** Captures `Set.prototype.union` — construction without a live `add` dispatch. */
238
+ union: Set.prototype.union,
199
239
  /** Captures `Set.prototype.has` — THE membership answer every published verdict rests on, dispatched through `apply`. */
200
240
  member: Set.prototype.has,
201
241
  /** Captures `Set.prototype.add` — collection of one more member, dispatched through `apply`. */
202
242
  admit: Set.prototype.add,
203
243
  /** Captures `Set.prototype.forEach` — the only full view of a caller's `Set` that runs no iterator, dispatched through `apply`. */
204
244
  sweep: Set.prototype.forEach,
245
+ /** Captures `Set.prototype.delete` — settlement of an active operation. */
246
+ remove: Set.prototype.delete,
205
247
  /** Captures `WeakMap` — object-keyed working state. */
206
248
  weakMap: WeakMap,
207
249
  /** Captures `WeakMap.prototype.get` — an object-keyed memo read a published graph embeds, dispatched through `apply`. */
@@ -505,8 +547,72 @@ var FORMAT_PATTERNS = Object.freeze({
505
547
  email: /^[^\s@]+@[^\s@]+\.[^\s@]+$/,
506
548
  uri: /^[a-z][a-z0-9+.-]*:\/\//i
507
549
  });
508
- //#endregion
509
- //#region src/core/errors.ts
550
+ /**
551
+ * Caps at `1024` the number of choices one schema field may offer, frozen.
552
+ *
553
+ * @remarks
554
+ * A retention limit that a declaring package, such as a form or table schema
555
+ * package, enforces; this package enforces none of the retention limits itself.
556
+ *
557
+ * @example
558
+ * ```ts
559
+ * CHOICE_LIMIT // 1024
560
+ * ```
561
+ */
562
+ var CHOICE_LIMIT = 1024;
563
+ /**
564
+ * Caps at `128` the length, in UTF-16 code units, of one name a schema declares, frozen:
565
+ * a schema, group, or field name, or a column key.
566
+ *
567
+ * @remarks
568
+ * A retention limit that a declaring package enforces, as {@link CHOICE_LIMIT} states.
569
+ *
570
+ * @example
571
+ * ```ts
572
+ * NAME_LIMIT // 128
573
+ * ```
574
+ */
575
+ var NAME_LIMIT = 128;
576
+ /**
577
+ * Caps at `65536` the length, in UTF-16 code units, of any single string one schema
578
+ * retains, frozen.
579
+ *
580
+ * @remarks
581
+ * A retention limit that a declaring package enforces, as {@link CHOICE_LIMIT} states.
582
+ *
583
+ * @example
584
+ * ```ts
585
+ * STRING_LIMIT // 65536
586
+ * ```
587
+ */
588
+ var STRING_LIMIT = 65536;
589
+ /**
590
+ * Caps at `1048576` the total length, in UTF-16 code units, of every string one schema
591
+ * retains, frozen.
592
+ *
593
+ * @remarks
594
+ * A retention limit that a declaring package enforces, as {@link CHOICE_LIMIT} states.
595
+ *
596
+ * @example
597
+ * ```ts
598
+ * TEXT_LIMIT // 1048576
599
+ * ```
600
+ */
601
+ var TEXT_LIMIT = 1048576;
602
+ /**
603
+ * Caps at `16384` the total number of records, arrays, and leaves one schema retains,
604
+ * frozen.
605
+ *
606
+ * @remarks
607
+ * A retention limit that a declaring package enforces, as {@link CHOICE_LIMIT} states.
608
+ *
609
+ * @example
610
+ * ```ts
611
+ * NODE_LIMIT // 16384
612
+ * ```
613
+ */
614
+ var NODE_LIMIT = 16384;
615
+ // src/core/errors.ts
510
616
  /**
511
617
  * Carries a machine-readable contract category, optional context, and an exact optional
512
618
  * cause.
@@ -546,8 +652,7 @@ var ContractError = class ContractError extends Error {
546
652
  }
547
653
  static {
548
654
  const members = INTRINSICS.reflect.members(this.prototype);
549
- for (let index = 0; index < members.length; index += 1) {
550
- const key = members[index];
655
+ for (const key of members) {
551
656
  if (key === void 0) continue;
552
657
  const declared = INTRINSICS.describe(this.prototype, key);
553
658
  const accessor = declared !== void 0 && !INTRINSICS.own(declared, "value");
@@ -565,7 +670,10 @@ var ContractError = class ContractError extends Error {
565
670
  *
566
671
  * @remarks
567
672
  * Recognition combines a global own-property brand with the native `Error`
568
- * base, a subclass prototype, the fixed name, and a declared contract code.
673
+ * base, a subclass prototype, an own declared contract code, and valid context.
674
+ * Context may be a class instance or callable object; paths are checked by index.
675
+ * Optional context fields are read only when owned; inherited fields are ignored.
676
+ * A subclass may replace its name without changing recognition.
569
677
  * The brand stores the error itself and recognition requires that exact
570
678
  * identity. A transparent proxy is therefore refused because its forwarded
571
679
  * descriptor still stores the target, not the proxy.
@@ -587,17 +695,29 @@ function isContractError(value) {
587
695
  if (typeof value !== "object" || value === null) return false;
588
696
  try {
589
697
  if (!(value instanceof INTRINSICS.error) || INTRINSICS.prototype(value) === INTRINSICS.error.prototype) return false;
590
- if (value.name !== "ContractError" || !("code" in value)) return false;
698
+ if (!INTRINSICS.own(value, "code")) return false;
591
699
  if (INTRINSICS.describe(value, CONTRACT_ERROR_BRAND)?.value !== value) return false;
592
- const code = value.code;
593
- for (let index = 0; index < CONTRACT_CODES.length; index += 1) if (code === CONTRACT_CODES[index]) return true;
594
- return false;
700
+ const code = INTRINSICS.reflect.read(value, "code");
701
+ if (!INTRINSICS.reflect.apply(INTRINSICS.some, CONTRACT_CODES, [(candidate) => candidate === code])) return false;
702
+ const context = INTRINSICS.own(value, "context") ? INTRINSICS.reflect.read(value, "context") : void 0;
703
+ if (context === void 0) return true;
704
+ if ((typeof context !== "object" || context === null) && typeof context !== "function") return false;
705
+ const path = INTRINSICS.own(context, "path") ? INTRINSICS.reflect.read(context, "path") : void 0;
706
+ if (path !== void 0 && typeof path !== "string") {
707
+ if (!INTRINSICS.array(path)) return false;
708
+ if (INTRINSICS.reflect.apply(INTRINSICS.find, path, [(segment) => typeof segment !== "string"]) !== -1) return false;
709
+ }
710
+ const shape = INTRINSICS.own(context, "shape") ? INTRINSICS.reflect.read(context, "shape") : void 0;
711
+ if (shape !== void 0 && typeof shape !== "string") return false;
712
+ const limit = INTRINSICS.own(context, "limit") ? INTRINSICS.reflect.read(context, "limit") : void 0;
713
+ if (limit !== void 0 && typeof limit !== "number" && typeof limit !== "string") return false;
714
+ const received = INTRINSICS.own(context, "received") ? INTRINSICS.reflect.read(context, "received") : void 0;
715
+ return received === void 0 || typeof received === "string";
595
716
  } catch {
596
717
  return false;
597
718
  }
598
719
  }
599
- //#endregion
600
- //#region src/core/validators.ts
720
+ // src/core/validators.ts
601
721
  /** Determines whether a value is `null`.
602
722
  *
603
723
  * @param value - The value to inspect
@@ -1783,8 +1903,62 @@ function isBoundedJSONRecord(value) {
1783
1903
  function isJSONPrimitive(value) {
1784
1904
  return isNull(value) || isString(value) || isFiniteNumber(value) || isBoolean(value);
1785
1905
  }
1786
- //#endregion
1787
- //#region src/core/helpers.ts
1906
+ // src/core/helpers.ts
1907
+ /**
1908
+ * Iterates indices while rereading the upper bound before every step.
1909
+ *
1910
+ * @remarks
1911
+ * Uses a captured native cursor and never reads an element or a caller's
1912
+ * iterator. Fractional bounds include the last index below the bound.
1913
+ *
1914
+ * @param read - Reads the current upper bound
1915
+ * @returns The indices below each observed bound
1916
+ *
1917
+ * @example
1918
+ * ```ts
1919
+ * Array.from(iterateIndices(() => 3)) // [0, 1, 2]
1920
+ * ```
1921
+ */
1922
+ function* iterateIndices(read) {
1923
+ const cursor = INTRINSICS.reflect.apply(INTRINSICS.indices, { get length() {
1924
+ const length = read();
1925
+ return length > 0 ? INTRINSICS.ceil(length) : 0;
1926
+ } }, []);
1927
+ while (true) {
1928
+ const step = INTRINSICS.reflect.apply(INTRINSICS.advance, cursor, []);
1929
+ if (step.done) return;
1930
+ yield step.value;
1931
+ }
1932
+ }
1933
+ /**
1934
+ * Exposes indexed reads through a non-array receiver without species dispatch.
1935
+ *
1936
+ * @remarks
1937
+ * Captured array methods read length, membership, and elements lazily through
1938
+ * the source receiver. The view is not an array, so native map, filter, and
1939
+ * flatMap never consult its constructor or species. Their callback's collection
1940
+ * argument is this view. No source element is observed while constructing it.
1941
+ *
1942
+ * @param values - The array whose live indexed reads and membership are forwarded
1943
+ * @returns A non-array receiver for captured array methods
1944
+ *
1945
+ * @example
1946
+ * ```ts
1947
+ * INTRINSICS.reflect.apply(INTRINSICS.project, readIndexView([1, 2]), [
1948
+ * (value: number) => value * 2,
1949
+ * ]) // [2, 4]
1950
+ * ```
1951
+ */
1952
+ function readIndexView(values) {
1953
+ return new INTRINSICS.proxy({ __proto__: null }, {
1954
+ get(_target, key) {
1955
+ return INTRINSICS.reflect.read(values, key);
1956
+ },
1957
+ has(_target, key) {
1958
+ return INTRINSICS.reflect.present(values, key);
1959
+ }
1960
+ });
1961
+ }
1788
1962
  /**
1789
1963
  * Builds a diagnostic path from an existing path and further segments, without
1790
1964
  * dispatching through array iteration.
@@ -1812,18 +1986,10 @@ function isJSONPrimitive(value) {
1812
1986
  * ```
1813
1987
  */
1814
1988
  function pathOf(path, ...segments) {
1815
- const extended = [];
1816
- for (let index = 0; index < path.length; index += 1) {
1817
- const existing = path[index];
1818
- if (existing === void 0) continue;
1819
- extended[extended.length] = existing;
1820
- }
1821
- for (let index = 0; index < segments.length; index += 1) {
1822
- const segment = segments[index];
1823
- if (segment === void 0) continue;
1824
- extended[extended.length] = segment;
1825
- }
1826
- return extended;
1989
+ const existing = INTRINSICS.from(iterateIndices(() => path.length), (index) => path[index]);
1990
+ const added = INTRINSICS.from(iterateIndices(() => segments.length), (index) => segments[index]);
1991
+ const combined = INTRINSICS.from(iterateIndices(() => existing.length + added.length), (index) => index < existing.length ? existing[index] : added[index - existing.length]);
1992
+ return INTRINSICS.reflect.apply(INTRINSICS.select, readIndexView(combined), [(segment) => segment !== void 0]);
1827
1993
  }
1828
1994
  /**
1829
1995
  * Appends every element of one array onto another, by index.
@@ -1846,7 +2012,7 @@ function pathOf(path, ...segments) {
1846
2012
  * ```
1847
2013
  */
1848
2014
  function appendEntries(target, source) {
1849
- for (let index = 0; index < source.length; index += 1) {
2015
+ for (const index of iterateIndices(() => source.length)) {
1850
2016
  const entry = source[index];
1851
2017
  if (entry === void 0) continue;
1852
2018
  target[target.length] = entry;
@@ -1872,13 +2038,8 @@ function appendEntries(target, source) {
1872
2038
  */
1873
2039
  function limitEntries(entries, limit) {
1874
2040
  if (entries.length <= limit) return entries;
1875
- const bounded = [];
1876
- for (let index = 0; index < limit; index += 1) {
1877
- const entry = entries[index];
1878
- if (entry === void 0) continue;
1879
- bounded[bounded.length] = entry;
1880
- }
1881
- return bounded;
2041
+ const selected = INTRINSICS.from(iterateIndices(() => limit), (index) => entries[index]);
2042
+ return INTRINSICS.reflect.apply(INTRINSICS.select, readIndexView(selected), [(entry) => entry !== void 0]);
1882
2043
  }
1883
2044
  /**
1884
2045
  * Orders two primitive keys or indices ascending.
@@ -1901,10 +2062,10 @@ function limitEntries(entries, limit) {
1901
2062
  *
1902
2063
  * @example
1903
2064
  * ```ts
1904
- * compareValues('a', 'b') // -1
2065
+ * comparePrimitives('a', 'b') // -1
1905
2066
  * ```
1906
2067
  */
1907
- function compareValues(left, right) {
2068
+ function comparePrimitives(left, right) {
1908
2069
  return left < right ? -1 : left > right ? 1 : 0;
1909
2070
  }
1910
2071
  /**
@@ -1918,7 +2079,7 @@ function compareValues(left, right) {
1918
2079
  * `valueToSchema({ b: 1, a: 2 })` publish `{"type":"object","additionalProperties":false}`
1919
2080
  * — a successful answer with the caller's properties silently gone. The copy is
1920
2081
  * taken first so a caller-owned array is never reordered in place, and the order
1921
- * is decided by {@link compareValues}, whose `<` / `>` comparison dispatches
2082
+ * is decided by {@link comparePrimitives}, whose `<` / `>` comparison dispatches
1922
2083
  * through nothing.
1923
2084
  *
1924
2085
  * @param values - The keys or indices to order
@@ -1930,13 +2091,9 @@ function compareValues(left, right) {
1930
2091
  * ```
1931
2092
  */
1932
2093
  function sortValues(values) {
1933
- const owned = [];
1934
- for (let index = 0; index < values.length; index += 1) {
1935
- const value = values[index];
1936
- if (value === void 0) continue;
1937
- owned[owned.length] = value;
1938
- }
1939
- INTRINSICS.reflect.apply(INTRINSICS.order, owned, [compareValues]);
2094
+ const observed = INTRINSICS.from(iterateIndices(() => values.length), (index) => values[index]);
2095
+ const owned = INTRINSICS.reflect.apply(INTRINSICS.select, readIndexView(observed), [(value) => value !== void 0]);
2096
+ INTRINSICS.reflect.apply(INTRINSICS.order, owned, [comparePrimitives]);
1940
2097
  return owned;
1941
2098
  }
1942
2099
  /**
@@ -1958,6 +2115,8 @@ function sortValues(values) {
1958
2115
  * `new Set(values)` reads `Symbol.iterator` off the argument and `add` off the
1959
2116
  * instance, so building from an iterable would reintroduce two replaceable
1960
2117
  * dispatches to remove one.
2118
+ * A captured native union consumes the owned indexed snapshot through a cursor
2119
+ * whose `next` is bound to the captured array advance operation.
1961
2120
  *
1962
2121
  * @param values - The members to collect, read by index
1963
2122
  * @returns A collection no caller holds a reference to
@@ -1969,9 +2128,18 @@ function sortValues(values) {
1969
2128
  * ```
1970
2129
  */
1971
2130
  function collectMembers(values) {
1972
- const members = new INTRINSICS.set();
1973
- for (let index = 0; index < values.length; index += 1) INTRINSICS.reflect.apply(INTRINSICS.admit, members, [values[index]]);
1974
- return members;
2131
+ const indices = iterateIndices(() => values.length);
2132
+ const entries = INTRINSICS.from(indices, (index) => values[index]);
2133
+ return INTRINSICS.reflect.apply(INTRINSICS.union, new INTRINSICS.set(), [{
2134
+ size: entries.length,
2135
+ has(value) {
2136
+ return INTRINSICS.reflect.apply(INTRINSICS.some, entries, [(entry) => entry === value || INTRINSICS.same(entry, value)]);
2137
+ },
2138
+ keys() {
2139
+ const cursor = INTRINSICS.reflect.apply(INTRINSICS.iterator, entries, []);
2140
+ return { next: INTRINSICS.reflect.apply(INTRINSICS.bind, INTRINSICS.advance, [cursor]) };
2141
+ }
2142
+ }]);
1975
2143
  }
1976
2144
  /**
1977
2145
  * Determines whether a value is a member of a collected vocabulary, by
@@ -2169,7 +2337,7 @@ function readSampleMemo(memo, reader) {
2169
2337
  *
2170
2338
  * @remarks
2171
2339
  * Extracted rather than written inline for the same reason
2172
- * {@link compareValues} is: `Reflect.apply` takes its arguments as a LIST, so an
2340
+ * {@link comparePrimitives} is: `Reflect.apply` takes its arguments as a LIST, so an
2173
2341
  * inline collector is a function expression inside an array literal rather than
2174
2342
  * one passed directly as an argument — a hidden function assignment this
2175
2343
  * repository forbids wherever it appears. Returned directly from a factory it is
@@ -2215,12 +2383,7 @@ function readSetEntries(value) {
2215
2383
  return attempt(() => {
2216
2384
  const collected = [];
2217
2385
  INTRINSICS.reflect.apply(INTRINSICS.sweep, value, [collectEntries(collected)]);
2218
- const entries = [];
2219
- for (let index = 0; index < collected.length; index += 1) {
2220
- const pair = collected[index];
2221
- if (pair === void 0) continue;
2222
- entries[entries.length] = pair[1];
2223
- }
2386
+ const entries = INTRINSICS.reflect.apply(INTRINSICS.project, readIndexView(collected), [(pair) => pair[1]]);
2224
2387
  return INTRINSICS.freeze(entries);
2225
2388
  });
2226
2389
  }
@@ -2324,6 +2487,46 @@ function matchesPattern(pattern, value) {
2324
2487
  return INTRINSICS.reflect.apply(INTRINSICS.captures, pattern, [value]) !== null;
2325
2488
  }
2326
2489
  /**
2490
+ * Escapes every regular-expression metacharacter in a text, so the text
2491
+ * matches literally inside a larger `RegExp` source.
2492
+ *
2493
+ * @remarks
2494
+ * Prefixes each of `\ ^ $ . * + ? ( ) [ ] { } |` with a backslash and leaves
2495
+ * every other character, `-` and `/` included, unchanged; the empty string
2496
+ * returns unchanged. The escape is an INDEXED character map rather than
2497
+ * `String.prototype.replace`, which dispatches through the caller-writable
2498
+ * `RegExp.prototype[Symbol.replace]` and `exec` members.
2499
+ *
2500
+ * @param value - The literal text to escape
2501
+ * @returns The text with every metacharacter backslash-escaped
2502
+ *
2503
+ * @example
2504
+ * ```ts
2505
+ * escapeRegExp('a.b*c') // 'a\\.b\\*c'
2506
+ * new RegExp(`^${escapeRegExp('a.b')}$`).test('axb') // false
2507
+ * ```
2508
+ */
2509
+ function escapeRegExp(value) {
2510
+ const metacharacters = collectMembers([
2511
+ "\\",
2512
+ "^",
2513
+ "$",
2514
+ ".",
2515
+ "*",
2516
+ "+",
2517
+ "?",
2518
+ "(",
2519
+ ")",
2520
+ "[",
2521
+ "]",
2522
+ "{",
2523
+ "}",
2524
+ "|"
2525
+ ]);
2526
+ const characters = INTRINSICS.from(iterateIndices(() => value.length), (index) => matchesMember(metacharacters, value[index]) ? `\\${value[index]}` : value[index]);
2527
+ return INTRINSICS.reflect.apply(INTRINSICS.join, characters, [""]);
2528
+ }
2529
+ /**
2327
2530
  * Rebuilds a caller's regular expression as a stateless pattern this package
2328
2531
  * owns.
2329
2532
  *
@@ -2347,12 +2550,9 @@ function readPattern(pattern) {
2347
2550
  const source = readPatternSource(pattern);
2348
2551
  const flags = readPatternFlags(pattern);
2349
2552
  if (source === void 0 || flags === void 0) throw new INTRINSICS.error("Pattern source and flags could not be read");
2350
- let stateless = "";
2351
- for (let index = 0; index < flags.length; index += 1) {
2352
- const flag = flags[index];
2353
- if (flag === void 0 || flag === "g" || flag === "y") continue;
2354
- stateless += flag;
2355
- }
2553
+ const characters = INTRINSICS.from(iterateIndices(() => flags.length), (index) => flags[index]);
2554
+ const selected = INTRINSICS.reflect.apply(INTRINSICS.select, readIndexView(characters), [(flag) => flag !== void 0 && flag !== "g" && flag !== "y"]);
2555
+ const stateless = INTRINSICS.reflect.apply(INTRINSICS.join, selected, [""]);
2356
2556
  return new INTRINSICS.pattern(source, stateless);
2357
2557
  }
2358
2558
  /**
@@ -2432,7 +2632,7 @@ function ownPattern(pattern, reader) {
2432
2632
  */
2433
2633
  function pinMembers(prototype, owner) {
2434
2634
  const members = INTRINSICS.reflect.members(prototype);
2435
- for (let index = 0; index < members.length; index += 1) {
2635
+ for (const index of iterateIndices(() => members.length)) {
2436
2636
  const key = members[index];
2437
2637
  if (key === void 0) continue;
2438
2638
  const declared = INTRINSICS.describe(prototype, key);
@@ -2452,6 +2652,68 @@ function pinMembers(prototype, owner) {
2452
2652
  }
2453
2653
  }
2454
2654
  /**
2655
+ * Boxes a value as the {@link Success} branch of a {@link Result}.
2656
+ *
2657
+ * @param value - The value to box, retained exactly
2658
+ * @returns A fresh `{ success: true, value }` record
2659
+ *
2660
+ * @example
2661
+ * ```ts
2662
+ * success(42) // { success: true, value: 42 }
2663
+ * ```
2664
+ */
2665
+ function success(value) {
2666
+ return {
2667
+ success: true,
2668
+ value
2669
+ };
2670
+ }
2671
+ /**
2672
+ * Boxes an error as the {@link Failure} branch of a {@link Result}.
2673
+ *
2674
+ * @param error - The error to box, retained exactly
2675
+ * @returns A fresh `{ success: false, error }` record
2676
+ *
2677
+ * @example
2678
+ * ```ts
2679
+ * failure('offline') // { success: false, error: 'offline' }
2680
+ * ```
2681
+ */
2682
+ function failure(error) {
2683
+ return {
2684
+ success: false,
2685
+ error
2686
+ };
2687
+ }
2688
+ /**
2689
+ * Narrows a {@link Result} to its {@link Success} branch.
2690
+ *
2691
+ * @param result - The result to narrow
2692
+ * @returns True if the result succeeded; false otherwise
2693
+ *
2694
+ * @example
2695
+ * ```ts
2696
+ * isSuccess(success(1)) // true
2697
+ * ```
2698
+ */
2699
+ function isSuccess(result) {
2700
+ return result.success;
2701
+ }
2702
+ /**
2703
+ * Narrows a {@link Result} to its {@link Failure} branch.
2704
+ *
2705
+ * @param result - The result to narrow
2706
+ * @returns True if the result failed; false otherwise
2707
+ *
2708
+ * @example
2709
+ * ```ts
2710
+ * isFailure(failure('offline')) // true
2711
+ * ```
2712
+ */
2713
+ function isFailure(result) {
2714
+ return !result.success;
2715
+ }
2716
+ /**
2455
2717
  * Invokes a callback once and synchronously captures its exact outcome as a
2456
2718
  * {@link Result}.
2457
2719
  *
@@ -2479,23 +2741,42 @@ function pinMembers(prototype, owner) {
2479
2741
  * @example
2480
2742
  * ```ts
2481
2743
  * const outcome = attempt(() => predicate(value))
2482
- * return outcome.success && outcome.value
2744
+ * return isSuccess(outcome) && outcome.value
2483
2745
  * ```
2484
2746
  */
2485
2747
  function attempt(callback) {
2486
2748
  try {
2487
- return {
2488
- success: true,
2489
- value: callback()
2490
- };
2749
+ return success(callback());
2491
2750
  } catch (error) {
2492
- return {
2493
- success: false,
2494
- error
2495
- };
2751
+ return failure(error);
2496
2752
  }
2497
2753
  }
2498
2754
  /**
2755
+ * Renders a thrown value as a non-empty message.
2756
+ *
2757
+ * @remarks
2758
+ * Reads an `Error`'s `message` and converts any other value with the `String`
2759
+ * function {@link INTRINSICS} captured at load, so a symbol renders as
2760
+ * `Symbol(description)` and a caller that replaces the global `String` does not
2761
+ * change the result. Returns `'unknown failure'` when
2762
+ * that read throws, as a throwing `message` getter or `toString` method does,
2763
+ * when an `Error`'s `message` is not a string, and when the rendered text is
2764
+ * empty. Never throws.
2765
+ *
2766
+ * @param error - The caught value, of any shape
2767
+ * @returns The rendered message, never empty
2768
+ *
2769
+ * @example
2770
+ * ```ts
2771
+ * errorToMessage(new Error('boom')) // 'boom'
2772
+ * errorToMessage('') // 'unknown failure'
2773
+ * ```
2774
+ */
2775
+ function errorToMessage(error) {
2776
+ const read = attempt(() => isError(error) ? error.message : INTRINSICS.text(error));
2777
+ return isSuccess(read) && isString(read.value) && read.value.length > 0 ? read.value : "unknown failure";
2778
+ }
2779
+ /**
2499
2780
  * Reads a value through the shared containment boundary or refuses it with the
2500
2781
  * contract module's uniform read diagnostic.
2501
2782
  *
@@ -2539,12 +2820,12 @@ function readValue(callback, reader, options) {
2539
2820
  owned
2540
2821
  };
2541
2822
  });
2542
- if (!diagnostics.success) throw new ContractError("readValue: options could not be read", {
2823
+ if (isFailure(diagnostics)) throw new ContractError("readValue: options could not be read", {
2543
2824
  code: "structure",
2544
2825
  cause: diagnostics.error
2545
2826
  });
2546
2827
  const outcome = attempt(callback);
2547
- if (!outcome.success) {
2828
+ if (isFailure(outcome)) {
2548
2829
  const owned = diagnostics.value.owned;
2549
2830
  const context = owned === void 0 ? void 0 : {
2550
2831
  ...owned.path === void 0 ? {} : { path: owned.path },
@@ -2606,7 +2887,7 @@ function readValue(callback, reader, options) {
2606
2887
  */
2607
2888
  function contain(callback, door, options) {
2608
2889
  const outcome = attempt(callback);
2609
- if (outcome.success) return outcome.value;
2890
+ if (isSuccess(outcome)) return outcome.value;
2610
2891
  if (isContractError(outcome.error)) throw outcome.error;
2611
2892
  throw new ContractError(`${door}: a host operation this door depends on failed`, {
2612
2893
  code: options?.code ?? "structure",
@@ -2632,7 +2913,7 @@ function contain(callback, door, options) {
2632
2913
  */
2633
2914
  function holds(callback) {
2634
2915
  const outcome = attempt(callback);
2635
- return outcome.success && outcome.value === true;
2916
+ return isSuccess(outcome) && outcome.value === true;
2636
2917
  }
2637
2918
  /**
2638
2919
  * Determines whether a value carries the plain-record brand, raising a hostile
@@ -2713,7 +2994,7 @@ function matchesRecordBrand(value) {
2713
2994
  "toString",
2714
2995
  "valueOf"
2715
2996
  ];
2716
- for (let index = 0; index < mandated.length; index += 1) {
2997
+ for (const index of iterateIndices(() => mandated.length)) {
2717
2998
  const member = mandated[index];
2718
2999
  if (member === void 0) return false;
2719
3000
  const descriptor = INTRINSICS.describe(prototype, member);
@@ -2755,45 +3036,44 @@ function readArrayEntries(value) {
2755
3036
  const length = value.length;
2756
3037
  if (!INTRINSICS.safe(length) || length < 0 || length > 2 ** 32 - 1) throw new INTRINSICS.error("Array length is outside the native array domain");
2757
3038
  const members = INTRINSICS.reflect.members(value);
2758
- let matched = 0;
2759
- while (matched < length && members[matched] === INTRINSICS.text(matched)) matched += 1;
2760
- if (matched === length && members.length === length + 1 && members[length] === "length") {
2761
- const packed = new INTRINSICS.list(length);
2762
- for (let index = 0; index < length; index += 1) {
3039
+ if (members.length === length + 1 && members[length] === "length" && !INTRINSICS.reflect.apply(INTRINSICS.some, members, [(key, index) => index < length && key !== INTRINSICS.text(index)])) {
3040
+ const packed = INTRINSICS.from(iterateIndices(() => length), (index) => {
2763
3041
  const key = members[index];
2764
3042
  if (key === void 0 || !INTRINSICS.own(value, key)) throw new INTRINSICS.error("Array index views disagree");
2765
- packed[index] = value[index];
2766
- }
3043
+ return value[index];
3044
+ });
2767
3045
  return INTRINSICS.freeze({
2768
3046
  entries: INTRINSICS.freeze(packed),
2769
3047
  dense: true
2770
3048
  });
2771
3049
  }
2772
- const collected = [];
2773
- const keys = [];
2774
- let ascending = true;
2775
- let previous = -1;
2776
- for (let position = 0; position < members.length; position += 1) {
2777
- const key = members[position];
2778
- if (!isString(key)) continue;
3050
+ const selected = INTRINSICS.reflect.apply(INTRINSICS.expand, readIndexView(members), [(key) => {
3051
+ if (!isString(key)) return [];
2779
3052
  const index = INTRINSICS.numeric(key);
2780
- if (INTRINSICS.integer(index) && index >= 0 && index < 2 ** 32 - 1 && INTRINSICS.text(index) === key) {
2781
- if (index >= length) throw new INTRINSICS.error("Array index views disagree");
2782
- if (index <= previous) ascending = false;
2783
- previous = index;
2784
- collected[collected.length] = index;
2785
- keys[keys.length] = key;
2786
- }
2787
- }
3053
+ if (!INTRINSICS.integer(index) || index < 0 || index >= 2 ** 32 - 1 || INTRINSICS.text(index) !== key) return [];
3054
+ if (index >= length) throw new INTRINSICS.error("Array index views disagree");
3055
+ return [{
3056
+ index,
3057
+ key
3058
+ }];
3059
+ }]);
3060
+ const collected = INTRINSICS.reflect.apply(INTRINSICS.project, readIndexView(selected), [(entry) => entry.index]);
3061
+ const keys = INTRINSICS.reflect.apply(INTRINSICS.project, readIndexView(selected), [(entry) => entry.key]);
3062
+ const ascending = !INTRINSICS.reflect.apply(INTRINSICS.some, collected, [(index, position) => index <= (collected[position - 1] ?? -1)]);
2788
3063
  const indices = ascending ? collected : sortValues(collected);
2789
- const entries = new INTRINSICS.list(length);
2790
- for (let position = 0; position < indices.length; position += 1) {
3064
+ const pairs = INTRINSICS.from(iterateIndices(() => indices.length), (position) => {
2791
3065
  const index = indices[position];
2792
- if (index === void 0) continue;
2793
3066
  const key = ascending ? keys[position] : INTRINSICS.text(index);
2794
- if (key === void 0 || !INTRINSICS.own(value, key)) throw new INTRINSICS.error("Array index views disagree");
2795
- entries[index] = value[index];
2796
- }
3067
+ if (index === void 0 || key === void 0 || !INTRINSICS.own(value, key)) throw new INTRINSICS.error("Array index views disagree");
3068
+ return [key, {
3069
+ value: value[index],
3070
+ enumerable: true,
3071
+ configurable: true,
3072
+ writable: true
3073
+ }];
3074
+ });
3075
+ const descriptors = INTRINSICS.record({ [Symbol.iterator]: INTRINSICS.reflect.apply(INTRINSICS.bind, INTRINSICS.iterator, [pairs]) });
3076
+ const entries = INTRINSICS.definitions(new INTRINSICS.list(length), descriptors);
2797
3077
  return INTRINSICS.freeze({
2798
3078
  entries: INTRINSICS.freeze(entries),
2799
3079
  dense: indices.length === length
@@ -2824,16 +3104,13 @@ function readArrayEntries(value) {
2824
3104
  function readGuardShape(shape, optional, reader) {
2825
3105
  const declared = readValue(() => {
2826
3106
  const members = INTRINSICS.reflect.members(shape);
2827
- const guards = INTRINSICS.create(null);
2828
- const names = [];
2829
- for (let index = 0; index < members.length; index += 1) {
2830
- const key = members[index];
2831
- if (!isString(key)) continue;
2832
- if (!INTRINSICS.own(guards, key)) names[names.length] = key;
2833
- guards[key] = shape[key];
2834
- }
3107
+ const names = INTRINSICS.reflect.apply(INTRINSICS.select, readIndexView(members), [(key) => isString(key)]);
3108
+ const pairs = INTRINSICS.from(iterateIndices(() => names.length), (index) => {
3109
+ const key = names[index];
3110
+ return [key, key === void 0 ? void 0 : shape[key]];
3111
+ });
2835
3112
  return {
2836
- guards,
3113
+ guards: INTRINSICS.rebase(INTRINSICS.record({ [Symbol.iterator]: INTRINSICS.reflect.apply(INTRINSICS.bind, INTRINSICS.iterator, [pairs]) }), null),
2837
3114
  names,
2838
3115
  vocabulary: collectMembers(names)
2839
3116
  };
@@ -2842,11 +3119,9 @@ function readGuardShape(shape, optional, reader) {
2842
3119
  if (optional === true) return collectMembers(declared.names);
2843
3120
  if (!INTRINSICS.array(optional)) return collectMembers([]);
2844
3121
  const entries = readArrayEntries(optional);
2845
- if (!entries.success) throw entries.error;
3122
+ if (isFailure(entries)) throw entries.error;
2846
3123
  if (!entries.value.dense) throw new INTRINSICS.error("Optional key list must be dense");
2847
- const keys = collectMembers([]);
2848
- for (let index = 0; index < entries.value.entries.length; index += 1) admitMember(keys, INTRINSICS.text(entries.value.entries[index]));
2849
- return keys;
3124
+ return collectMembers(INTRINSICS.from(iterateIndices(() => entries.value.entries.length), (index) => INTRINSICS.text(entries.value.entries[index])));
2850
3125
  }, reader, { subject: "optional" });
2851
3126
  return {
2852
3127
  guards: declared.guards,
@@ -2875,7 +3150,7 @@ function readGuardShape(shape, optional, reader) {
2875
3150
  */
2876
3151
  function enumerableKeys(value) {
2877
3152
  const outcome = attempt(() => INTRINSICS.freeze(INTRINSICS.keys(value)));
2878
- return outcome.success ? outcome.value : void 0;
3153
+ return isSuccess(outcome) ? outcome.value : void 0;
2879
3154
  }
2880
3155
  /**
2881
3156
  * Validates and snapshots a shape-builder options record through every reflective
@@ -2912,31 +3187,27 @@ function readOptions(source, keys, builder, shape) {
2912
3187
  context: { shape }
2913
3188
  });
2914
3189
  const result = readValue(() => {
2915
- const values = INTRINSICS.create(null);
2916
- for (let index = 0; index < keys.length; index += 1) {
3190
+ const observed = INTRINSICS.from(iterateIndices(() => keys.length), (index) => {
2917
3191
  const key = keys[index];
2918
- if (key === void 0) continue;
2919
- values[key] = INTRINSICS.reflect.read(input, key);
3192
+ if (key === void 0) return void 0;
3193
+ const value = INTRINSICS.reflect.read(input, key);
2920
3194
  INTRINSICS.reflect.present(input, key);
2921
3195
  INTRINSICS.reflect.describe(input, key);
2922
- }
3196
+ return [key, value];
3197
+ });
3198
+ const pairs = INTRINSICS.reflect.apply(INTRINSICS.select, readIndexView(observed), [(entry) => entry !== void 0]);
3199
+ const values = INTRINSICS.rebase(INTRINSICS.record({ [Symbol.iterator]: INTRINSICS.reflect.apply(INTRINSICS.bind, INTRINSICS.iterator, [pairs]) }), null);
2923
3200
  INTRINSICS.reflect.members(input);
2924
3201
  const record = matchesRecordBrand(input);
2925
- const snapshot = INTRINSICS.create(INTRINSICS.base);
2926
- for (let index = 0; index < keys.length; index += 1) {
2927
- const key = keys[index];
2928
- if (key === void 0) continue;
2929
- const value = values[key];
2930
- if (value === void 0) continue;
2931
- INTRINSICS.reflect.define(snapshot, key, {
2932
- value,
2933
- enumerable: true,
2934
- configurable: true,
2935
- writable: true
2936
- });
2937
- }
3202
+ const names = INTRINSICS.reflect.apply(INTRINSICS.select, readIndexView(INTRINSICS.from(iterateIndices(() => keys.length), (index) => keys[index])), [(key) => key !== void 0 && values[key] !== void 0]);
3203
+ const descriptors = INTRINSICS.reflect.apply(INTRINSICS.project, readIndexView(names), [(key) => [key, {
3204
+ value: values[key],
3205
+ enumerable: true,
3206
+ configurable: true,
3207
+ writable: true
3208
+ }]]);
2938
3209
  return {
2939
- snapshot,
3210
+ snapshot: INTRINSICS.create(INTRINSICS.base, INTRINSICS.record({ [Symbol.iterator]: INTRINSICS.reflect.apply(INTRINSICS.bind, INTRINSICS.iterator, [descriptors]) })),
2940
3211
  record
2941
3212
  };
2942
3213
  }, builder, {
@@ -2976,7 +3247,7 @@ function readOptions(source, keys, builder, shape) {
2976
3247
  function drawRandom(random, shape) {
2977
3248
  return contain(() => {
2978
3249
  const outcome = attempt(random);
2979
- if (!outcome.success) throw new ContractError("drawRandom: the random source threw", {
3250
+ if (isFailure(outcome)) throw new ContractError("drawRandom: the random source threw", {
2980
3251
  code: "random",
2981
3252
  context: {
2982
3253
  shape,
@@ -3024,16 +3295,17 @@ function resolveField(record, path) {
3024
3295
  const outcome = attempt(() => {
3025
3296
  if (!isRecord(record)) return void 0;
3026
3297
  const keys = isString(path) ? [path] : path;
3027
- let current = record;
3028
- for (let index = 0; index < keys.length; index += 1) {
3298
+ const indices = iterateIndices(() => keys.length);
3299
+ return INTRINSICS.reflect.apply(INTRINSICS.reduce, indices, [(current, index) => {
3029
3300
  const key = keys[index];
3030
- if (key === void 0) return void 0;
3031
- if (!isObject(current) || !INTRINSICS.own(current, key)) return void 0;
3032
- current = INTRINSICS.reflect.read(current, key);
3033
- }
3034
- return current;
3301
+ if (key === void 0 || !isObject(current) || !INTRINSICS.own(current, key)) {
3302
+ indices.return();
3303
+ return;
3304
+ }
3305
+ return INTRINSICS.reflect.read(current, key);
3306
+ }, record]);
3035
3307
  });
3036
- return outcome.success ? outcome.value : void 0;
3308
+ return isSuccess(outcome) ? outcome.value : void 0;
3037
3309
  }
3038
3310
  /**
3039
3311
  * Determines whether a readable value stays within the fixed JSON container-depth limit.
@@ -3096,9 +3368,9 @@ function matchesJSONDepth(value) {
3096
3368
  };
3097
3369
  if (array) {
3098
3370
  const snapshot = readArrayEntries(entry);
3099
- if (!snapshot.success) return false;
3371
+ if (isFailure(snapshot)) return false;
3100
3372
  const children = INTRINSICS.values(snapshot.value.entries);
3101
- for (let index = 0; index < children.length; index += 1) stack[stack.length] = {
3373
+ for (const index of iterateIndices(() => children.length)) stack[stack.length] = {
3102
3374
  operation: "enter",
3103
3375
  value: children[index],
3104
3376
  depth
@@ -3107,7 +3379,7 @@ function matchesJSONDepth(value) {
3107
3379
  }
3108
3380
  const keys = enumerableKeys(entry);
3109
3381
  if (keys === void 0) return false;
3110
- for (let index = 0; index < keys.length; index += 1) {
3382
+ for (const index of iterateIndices(() => keys.length)) {
3111
3383
  const key = keys[index];
3112
3384
  if (key === void 0) return false;
3113
3385
  if (!INTRINSICS.own(entry, key)) return false;
@@ -3179,7 +3451,7 @@ function matchesJSONValue(entry, ancestors) {
3179
3451
  if (matchesVisited(ancestors, node)) return false;
3180
3452
  if (matchesVisited(proved, node)) continue;
3181
3453
  const snapshot = readArrayEntries(node);
3182
- if (!snapshot.success) throw snapshot.error;
3454
+ if (isFailure(snapshot)) throw snapshot.error;
3183
3455
  if (!snapshot.value.dense) return false;
3184
3456
  admitVisited(ancestors, node);
3185
3457
  stack[stack.length] = {
@@ -3187,10 +3459,13 @@ function matchesJSONValue(entry, ancestors) {
3187
3459
  value: node
3188
3460
  };
3189
3461
  const entries = snapshot.value.entries;
3190
- for (let index = entries.length - 1; index >= 0; index -= 1) stack[stack.length] = {
3191
- operation: "enter",
3192
- value: entries[index]
3193
- };
3462
+ for (const offset of iterateIndices(() => entries.length)) {
3463
+ const index = entries.length - 1 - offset;
3464
+ stack[stack.length] = {
3465
+ operation: "enter",
3466
+ value: entries[index]
3467
+ };
3468
+ }
3194
3469
  continue;
3195
3470
  }
3196
3471
  if (!isRecord(node)) return false;
@@ -3202,50 +3477,18 @@ function matchesJSONValue(entry, ancestors) {
3202
3477
  value: node
3203
3478
  };
3204
3479
  const members = INTRINSICS.values(node);
3205
- for (let index = members.length - 1; index >= 0; index -= 1) stack[stack.length] = {
3206
- operation: "enter",
3207
- value: members[index]
3208
- };
3480
+ for (const offset of iterateIndices(() => members.length)) {
3481
+ const index = members.length - 1 - offset;
3482
+ stack[stack.length] = {
3483
+ operation: "enter",
3484
+ value: members[index]
3485
+ };
3486
+ }
3209
3487
  }
3210
3488
  return true;
3211
3489
  }, "matchesJSONValue", { context: { shape: "json" } });
3212
3490
  }
3213
3491
  /**
3214
- * Builds a deterministic pseudo-random source seeded from a single number.
3215
- *
3216
- * @remarks
3217
- * A mulberry32 generator — the same seed always yields the same sequence, so
3218
- * generated seed data is reproducible across runs. Used as the default random
3219
- * source for {@link compileGenerator}, seeded from the wall clock so casual
3220
- * callers still get varied output without passing a source themselves.
3221
- *
3222
- * @param seed - The seed for the sequence
3223
- * @returns A {@link RandomFunction} returning values in `[0, 1)`
3224
- *
3225
- * @example
3226
- * ```ts
3227
- * const random = seededRandom(42)
3228
- * random() // always the same first value for seed 42
3229
- * ```
3230
- */
3231
- function seededRandom(seed) {
3232
- if (!isNumber(seed)) throw new ContractError("seededRandom: seed must be a number", {
3233
- code: "random",
3234
- context: {
3235
- limit: "number",
3236
- received: preview(seed)
3237
- }
3238
- });
3239
- let state = seed >>> 0;
3240
- return () => {
3241
- state = state + 1831565813 >>> 0;
3242
- let t = state;
3243
- t = INTRINSICS.imul(t ^ t >>> 15, t | 1);
3244
- t ^= t + INTRINSICS.imul(t ^ t >>> 7, t | 61);
3245
- return ((t ^ t >>> 14) >>> 0) / 4294967296;
3246
- };
3247
- }
3248
- /**
3249
3492
  * Counts the enumerable own-symbol keys on a value.
3250
3493
  *
3251
3494
  * @remarks
@@ -3270,14 +3513,8 @@ function seededRandom(seed) {
3270
3513
  */
3271
3514
  function enumerableSymbolCount(value) {
3272
3515
  return readValue(() => {
3273
- let count = 0;
3274
3516
  const symbols = INTRINSICS.symbols(value);
3275
- for (let index = 0; index < symbols.length; index += 1) {
3276
- const symbol = symbols[index];
3277
- if (symbol === void 0) continue;
3278
- if (INTRINSICS.describe(value, symbol)?.enumerable) count += 1;
3279
- }
3280
- return count;
3517
+ return INTRINSICS.reflect.apply(INTRINSICS.fold, symbols, [(total, symbol) => total + (INTRINSICS.describe(value, symbol)?.enumerable ? 1 : 0), 0]);
3281
3518
  }, "enumerableSymbolCount");
3282
3519
  }
3283
3520
  /**
@@ -3437,15 +3674,9 @@ function canonicalStringify(value) {
3437
3674
  const frame = stack.pop();
3438
3675
  if (frame === void 0) return void 0;
3439
3676
  if (frame.operation === "exit") {
3440
- let encoded = "";
3441
- for (let index = 0; index < frame.members.length; index += 1) {
3442
- const member = frame.members[index];
3443
- const part = isObject(member) ? INTRINSICS.reflect.apply(INTRINSICS.recall, encodings, [member]) ?? encodeLeaf(member) : encodeLeaf(member);
3444
- if (part === void 0) return void 0;
3445
- const key = frame.keys?.[index];
3446
- const text = key === void 0 ? part : `${INTRINSICS.stringify(key)}:${part}`;
3447
- encoded += index === 0 ? text : `,${text}`;
3448
- }
3677
+ const parts = INTRINSICS.from(encodeParts(frame.members, frame.keys, encodings));
3678
+ if (parts.length !== frame.members.length) return void 0;
3679
+ const encoded = INTRINSICS.reflect.apply(INTRINSICS.join, parts, [","]);
3449
3680
  const text = frame.keys === void 0 ? `[${encoded}]` : `{${encoded}}`;
3450
3681
  INTRINSICS.reflect.apply(INTRINSICS.retain, encodings, [frame.value, text]);
3451
3682
  omitVisited(ancestors, frame.value);
@@ -3454,25 +3685,14 @@ function canonicalStringify(value) {
3454
3685
  const container = frame.value;
3455
3686
  if (matchesVisited(ancestors, container)) return void 0;
3456
3687
  if (INTRINSICS.reflect.apply(INTRINSICS.recall, encodings, [container]) !== void 0) continue;
3457
- const members = [];
3458
- const selected = [];
3459
- let keys;
3460
- if (isArray(container)) {
3461
- const snapshot = readArrayEntries(container);
3462
- if (!snapshot.success) throw snapshot.error;
3463
- if (!snapshot.value.dense) return void 0;
3464
- const entries = snapshot.value.entries;
3465
- for (let index = 0; index < entries.length; index += 1) members[members.length] = entries[index];
3466
- } else {
3467
- const names = sortValues(INTRINSICS.keys(container));
3468
- for (let index = 0; index < names.length; index += 1) {
3469
- const key = names[index];
3470
- if (key === void 0) continue;
3471
- selected[selected.length] = key;
3472
- members[members.length] = INTRINSICS.reflect.read(container, key);
3473
- }
3474
- keys = selected;
3475
- }
3688
+ const snapshot = isArray(container) ? readArrayEntries(container) : void 0;
3689
+ if (snapshot !== void 0 && isFailure(snapshot)) throw snapshot.error;
3690
+ if (snapshot !== void 0 && !snapshot.value.dense) return void 0;
3691
+ const keys = snapshot === void 0 ? sortValues(INTRINSICS.keys(container)) : void 0;
3692
+ const members = snapshot === void 0 ? INTRINSICS.from(iterateIndices(() => keys?.length ?? 0), (index) => {
3693
+ const key = keys?.[index];
3694
+ return key === void 0 ? void 0 : INTRINSICS.reflect.read(container, key);
3695
+ }) : snapshot.value.entries;
3476
3696
  admitVisited(ancestors, container);
3477
3697
  stack[stack.length] = {
3478
3698
  operation: "exit",
@@ -3480,8 +3700,8 @@ function canonicalStringify(value) {
3480
3700
  members,
3481
3701
  keys
3482
3702
  };
3483
- for (let index = members.length - 1; index >= 0; index -= 1) {
3484
- const member = members[index];
3703
+ for (const offset of iterateIndices(() => members.length)) {
3704
+ const member = members[members.length - 1 - offset];
3485
3705
  if (isObject(member) && (isArray(member) || matchesRecordBrand(member))) stack[stack.length] = {
3486
3706
  operation: "enter",
3487
3707
  value: member
@@ -3539,7 +3759,7 @@ function matchesISOInstant(value) {
3539
3759
  const date = new INTRINSICS.date(value);
3540
3760
  return !INTRINSICS.nan(INTRINSICS.reflect.apply(INTRINSICS.instant, date, []));
3541
3761
  });
3542
- return outcome.success && outcome.value;
3762
+ return isSuccess(outcome) && outcome.value;
3543
3763
  }
3544
3764
  /**
3545
3765
  * Classifies an already-bounded string against the pattern-only and
@@ -3762,27 +3982,9 @@ function preview(value) {
3762
3982
  const whole = INTRINSICS.stringify(source);
3763
3983
  if (whole.length <= 64) return whole;
3764
3984
  }
3765
- let text = quoted ? "\"" : "";
3766
- let index = 0;
3767
- while (index < source.length) {
3768
- const first = source[index];
3769
- if (first === void 0) break;
3770
- const second = index + 1 < source.length ? source[index + 1] : void 0;
3771
- const paired = first >= "\ud800" && first <= "\udbff" && second !== void 0 && second >= "\udc00" && second <= "\udfff";
3772
- const character = paired ? `${first}${second}` : first;
3773
- const encoded = INTRINSICS.stringify(character);
3774
- const tokenLength = encoded.length - 2;
3775
- if (text.length + tokenLength > 64) return `${text}…`;
3776
- let tokenIndex = 1;
3777
- while (tokenIndex <= tokenLength) {
3778
- const token = encoded[tokenIndex];
3779
- if (token !== void 0) text += token;
3780
- tokenIndex += 1;
3781
- }
3782
- index += paired ? 2 : 1;
3783
- }
3784
- if (!quoted) return text;
3785
- return text.length < 64 ? `${text}"` : `${text}…`;
3985
+ const parts = previewParts(source, 0, 64 - (quoted ? 1 : 0), quoted);
3986
+ const body = INTRINSICS.reflect.apply(INTRINSICS.join, parts, [""]);
3987
+ return quoted ? `"${body}` : body;
3786
3988
  }
3787
3989
  if (isNumber(value) || isBoolean(value)) return INTRINSICS.text(value);
3788
3990
  if (isBigInt(value)) return `${value}n`;
@@ -4004,13 +4206,10 @@ function buildArrayFaults(shape, length, path) {
4004
4206
  * ```
4005
4207
  */
4006
4208
  function selectClosestFaults(reports) {
4007
- let closest;
4008
- for (let index = 0; index < reports.length; index += 1) {
4209
+ return INTRINSICS.reflect.apply(INTRINSICS.reduce, iterateIndices(() => reports.length), [(best, index) => {
4009
4210
  const report = reports[index];
4010
- if (report === void 0) continue;
4011
- if (closest === void 0 || report.length < closest.length) closest = report;
4012
- }
4013
- return closest ?? INTRINSICS.freeze([]);
4211
+ return report !== void 0 && (best === void 0 || report.length < best.length) ? report : best;
4212
+ }, void 0]) ?? INTRINSICS.freeze([]);
4014
4213
  }
4015
4214
  /**
4016
4215
  * Projects a {@link ContractShape} to the {@link FaultKind} it describes.
@@ -4099,8 +4298,103 @@ function refuseExpansion(expansion) {
4099
4298
  }
4100
4299
  });
4101
4300
  }
4102
- //#endregion
4103
- //#region src/core/JSONCloner.ts
4301
+ /**
4302
+ * Encodes ordered members, stopping before the first unencodable member.
4303
+ *
4304
+ * @param members - The owned members in source order
4305
+ * @param keys - Object keys, or undefined for an array
4306
+ * @param encodings - Encodings already computed for child containers
4307
+ * @returns The encoded prefix
4308
+ *
4309
+ * @example
4310
+ * ```ts
4311
+ * Array.from(encodeParts([1, undefined, 2], undefined, new WeakMap())) // ['1']
4312
+ * ```
4313
+ */
4314
+ function* encodeParts(members, keys, encodings) {
4315
+ for (const index of iterateIndices(() => members.length)) {
4316
+ const member = members[index];
4317
+ const part = isObject(member) ? INTRINSICS.reflect.apply(INTRINSICS.recall, encodings, [member]) ?? encodeLeaf(member) : encodeLeaf(member);
4318
+ if (part === void 0) return;
4319
+ const key = keys?.[index];
4320
+ yield key === void 0 ? part : `${INTRINSICS.stringify(key)}:${part}`;
4321
+ }
4322
+ }
4323
+ /**
4324
+ * Builds bounded escaped preview parts without splitting a surrogate pair.
4325
+ *
4326
+ * @param source - The source text
4327
+ * @param index - The next UTF-16 offset
4328
+ * @param capacity - The unused preview width
4329
+ * @param quoted - Whether the final part closes a string quote
4330
+ * @returns The escaped parts with their closing quote or truncation mark
4331
+ *
4332
+ * @example
4333
+ * ```ts
4334
+ * previewParts('abc', 0, 2, false) // ['a', 'b', '…']
4335
+ * ```
4336
+ */
4337
+ function previewParts(source, index, capacity, quoted) {
4338
+ const available = INTRINSICS.min(capacity, 64);
4339
+ const first = source[index];
4340
+ if (index >= source.length || first === void 0) return quoted ? [available > 0 ? "\"" : "…"] : [];
4341
+ const second = index + 1 < source.length ? source[index + 1] : void 0;
4342
+ const paired = first >= "\ud800" && first <= "\udbff" && second !== void 0 && second >= "\udc00" && second <= "\udfff";
4343
+ const character = paired ? `${first}${second}` : first;
4344
+ const encoded = INTRINSICS.stringify(character);
4345
+ const length = encoded.length - 2;
4346
+ if (length > available) return ["…"];
4347
+ const characters = INTRINSICS.from(iterateIndices(() => length), (offset) => encoded[offset + 1]);
4348
+ const token = INTRINSICS.reflect.apply(INTRINSICS.join, characters, [""]);
4349
+ const tail = previewParts(source, index + (paired ? 2 : 1), available - length, quoted);
4350
+ return INTRINSICS.from(iterateIndices(() => tail.length + 1), (offset) => offset === 0 ? token : tail[offset - 1] ?? "");
4351
+ }
4352
+ /**
4353
+ * Builds a null-prototype lookup from names to their last index.
4354
+ *
4355
+ * @param names - Names in declaration order
4356
+ * @returns The indexed lookup
4357
+ *
4358
+ * @example
4359
+ * ```ts
4360
+ * buildPositions(['id', '__proto__']).id // 0
4361
+ * ```
4362
+ */
4363
+ function buildPositions(names) {
4364
+ const pairs = INTRINSICS.from(iterateIndices(() => names.length), (index) => [names[index], index]);
4365
+ return INTRINSICS.rebase(INTRINSICS.record({ [Symbol.iterator]: INTRINSICS.reflect.apply(INTRINSICS.bind, INTRINSICS.iterator, [pairs]) }), null);
4366
+ }
4367
+ /**
4368
+ * Derives the bit mask of names present in an indexed lookup.
4369
+ *
4370
+ * @param names - Names to observe in order
4371
+ * @param positions - The bit position of each declared name
4372
+ * @returns The combined signed 32-bit mask
4373
+ *
4374
+ * @example
4375
+ * ```ts
4376
+ * readPresence(['id'], buildPositions(['id', 'name'])) // 1
4377
+ * ```
4378
+ */
4379
+ function readPresence(names, positions) {
4380
+ return INTRINSICS.reflect.apply(INTRINSICS.reduce, iterateIndices(() => names.length), [(mask, index) => {
4381
+ const name = names[index];
4382
+ if (name === void 0 || !INTRINSICS.own(positions, name)) return mask;
4383
+ const position = positions[name];
4384
+ return position === void 0 ? mask : mask | 1 << position;
4385
+ }, 0]);
4386
+ }
4387
+ for (const generator of [iterateIndices, encodeParts]) {
4388
+ for (const key of [
4389
+ "next",
4390
+ "return",
4391
+ "throw",
4392
+ Symbol.iterator
4393
+ ]) INTRINSICS.define(generator.prototype, key, { value: INTRINSICS.reflect.read(generator.prototype, key) });
4394
+ INTRINSICS.freeze(generator.prototype);
4395
+ INTRINSICS.freeze(generator);
4396
+ }
4397
+ // src/core/JSONCloner.ts
4104
4398
  /**
4105
4399
  * Owns the state of one exact JSON snapshot operation.
4106
4400
  *
@@ -4152,25 +4446,22 @@ var JSONCloner = class JSONCloner {
4152
4446
  clone() {
4153
4447
  const terminal = this.#terminal;
4154
4448
  if (terminal !== void 0) {
4155
- if (terminal.success) return terminal.value;
4449
+ if (isSuccess(terminal)) return terminal.value;
4156
4450
  throw terminal.error;
4157
4451
  }
4158
4452
  const poison = this.#poison;
4159
4453
  if (poison !== void 0) {
4160
- this.#terminal = {
4161
- success: false,
4162
- error: poison
4163
- };
4454
+ this.#terminal = failure(poison);
4164
4455
  throw poison;
4165
4456
  }
4166
4457
  this.#poison = this.#create("JSONCloner.clone: JSON cloning may not be reentered");
4167
4458
  const outcome = attempt(() => this.#execute());
4168
4459
  const interruption = this.#terminal;
4169
4460
  if (interruption !== void 0) {
4170
- if (interruption.success) return interruption.value;
4461
+ if (isSuccess(interruption)) return interruption.value;
4171
4462
  this.#fail(interruption.error);
4172
4463
  }
4173
- if (outcome.success) {
4464
+ if (isSuccess(outcome)) {
4174
4465
  this.#terminal = outcome;
4175
4466
  return outcome.value;
4176
4467
  }
@@ -4178,10 +4469,7 @@ var JSONCloner = class JSONCloner {
4178
4469
  this.#fail(error);
4179
4470
  }
4180
4471
  #fail(error) {
4181
- this.#terminal = {
4182
- success: false,
4183
- error
4184
- };
4472
+ this.#terminal = failure(error);
4185
4473
  this.#pending = JSONCloner.#emptyPending;
4186
4474
  throw error;
4187
4475
  }
@@ -4226,7 +4514,7 @@ var JSONCloner = class JSONCloner {
4226
4514
  #captureObject(source) {
4227
4515
  if (matchesVisited(this.#active, source)) this.#refuse("cloneJSONValue: cycle detected");
4228
4516
  const arrayOutcome = attempt(() => INTRINSICS.array(source));
4229
- if (!arrayOutcome.success) this.#refuse("cloneJSONValue: value brand could not be inspected");
4517
+ if (isFailure(arrayOutcome)) this.#refuse("cloneJSONValue: value brand could not be inspected");
4230
4518
  if (arrayOutcome.value) return this.#schedule(source, true);
4231
4519
  if (isRecord(source)) return this.#schedule(source, false);
4232
4520
  this.#refuse("cloneJSONValue: object is not a plain record");
@@ -4245,41 +4533,37 @@ var JSONCloner = class JSONCloner {
4245
4533
  }
4246
4534
  #captureArray(source) {
4247
4535
  const keysOutcome = attempt(() => INTRINSICS.reflect.members(source));
4248
- if (!keysOutcome.success) this.#refuse("cloneJSONValue: own keys could not be inspected");
4536
+ if (isFailure(keysOutcome)) this.#refuse("cloneJSONValue: own keys could not be inspected");
4249
4537
  const lengthOutcome = attempt(() => INTRINSICS.reflect.describe(source, "length"));
4250
- if (!lengthOutcome.success) this.#refuse("cloneJSONValue: array length could not be inspected");
4538
+ if (isFailure(lengthOutcome)) this.#refuse("cloneJSONValue: array length could not be inspected");
4251
4539
  const lengthDescriptor = lengthOutcome.value;
4252
4540
  if (lengthDescriptor === void 0 || !("value" in lengthDescriptor) || typeof lengthDescriptor.value !== "number" || !INTRINSICS.integer(lengthDescriptor.value) || lengthDescriptor.value < 0 || lengthDescriptor.value > 4294967295 || lengthDescriptor.enumerable !== false || lengthDescriptor.configurable !== false) this.#refuse("cloneJSONValue: array is not intrinsic and dense");
4253
4541
  const owned = collectMembers(keysOutcome.value);
4254
4542
  if (!matchesMember(owned, "length")) this.#refuse("cloneJSONValue: array own keys are not exact");
4255
4543
  if (keysOutcome.value.length !== lengthDescriptor.value + 1) this.#refuse("cloneJSONValue: array own keys are not exact");
4256
- const entries = [];
4257
- for (let index = 0; index < lengthDescriptor.value; index += 1) {
4544
+ return INTRINSICS.from(iterateIndices(() => lengthDescriptor.value), (index) => {
4258
4545
  const key = INTRINSICS.text(index);
4259
4546
  if (!matchesMember(owned, key)) this.#refuse("cloneJSONValue: array own keys are not exact");
4260
4547
  const descriptorOutcome = attempt(() => INTRINSICS.reflect.describe(source, key));
4261
- if (!descriptorOutcome.success) this.#refuse("cloneJSONValue: array index could not be inspected");
4548
+ if (isFailure(descriptorOutcome)) this.#refuse("cloneJSONValue: array index could not be inspected");
4262
4549
  const descriptor = descriptorOutcome.value;
4263
4550
  if (descriptor === void 0 || !("value" in descriptor) || descriptor.enumerable !== true) this.#refuse("cloneJSONValue: array index is not enumerable data");
4264
- entries[entries.length] = [key, descriptor.value];
4265
- }
4266
- return entries;
4551
+ return [key, descriptor.value];
4552
+ });
4267
4553
  }
4268
4554
  #captureRecord(source) {
4269
4555
  const keysOutcome = attempt(() => INTRINSICS.reflect.members(source));
4270
- if (!keysOutcome.success) this.#refuse("cloneJSONValue: own keys could not be inspected");
4271
- const entries = [];
4556
+ if (isFailure(keysOutcome)) this.#refuse("cloneJSONValue: own keys could not be inspected");
4272
4557
  const names = keysOutcome.value;
4273
- for (let index = 0; index < names.length; index += 1) {
4558
+ return INTRINSICS.from(iterateIndices(() => names.length), (index) => {
4274
4559
  const key = names[index];
4275
4560
  if (typeof key !== "string") this.#refuse("cloneJSONValue: record has a symbol property");
4276
4561
  const descriptorOutcome = attempt(() => INTRINSICS.reflect.describe(source, key));
4277
- if (!descriptorOutcome.success) this.#refuse("cloneJSONValue: record property could not be inspected");
4562
+ if (isFailure(descriptorOutcome)) this.#refuse("cloneJSONValue: record property could not be inspected");
4278
4563
  const descriptor = descriptorOutcome.value;
4279
4564
  if (descriptor === void 0 || !("value" in descriptor) || descriptor.enumerable !== true) this.#refuse("cloneJSONValue: record property is not enumerable data");
4280
- entries[entries.length] = [key, descriptor.value];
4281
- }
4282
- return entries;
4565
+ return [key, descriptor.value];
4566
+ });
4283
4567
  }
4284
4568
  #create(message) {
4285
4569
  const error = new ContractError(message, {
@@ -4294,7 +4578,7 @@ var JSONCloner = class JSONCloner {
4294
4578
  }
4295
4579
  #refuse(message) {
4296
4580
  const terminal = this.#terminal;
4297
- if (terminal !== void 0 && !terminal.success) throw terminal.error;
4581
+ if (terminal !== void 0 && isFailure(terminal)) throw terminal.error;
4298
4582
  throw this.#create(message);
4299
4583
  }
4300
4584
  static {
@@ -4302,8 +4586,7 @@ var JSONCloner = class JSONCloner {
4302
4586
  pinMembers(JSONCloner.prototype, "JSONCloner");
4303
4587
  }
4304
4588
  };
4305
- //#endregion
4306
- //#region src/core/SchemaCloner.ts
4589
+ // src/core/SchemaCloner.ts
4307
4590
  /**
4308
4591
  * Owns the state of one JSON Schema snapshot operation.
4309
4592
  *
@@ -4354,7 +4637,7 @@ var SchemaCloner = class SchemaCloner {
4354
4637
  const state = this.#state;
4355
4638
  switch (state.phase) {
4356
4639
  case "settled":
4357
- if (state.result.success) return state.result.value;
4640
+ if (isSuccess(state.result)) return state.result.value;
4358
4641
  throw state.result.error;
4359
4642
  case "running":
4360
4643
  case "interrupted":
@@ -4373,16 +4656,10 @@ var SchemaCloner = class SchemaCloner {
4373
4656
  }
4374
4657
  #complete(outcome) {
4375
4658
  const state = this.#state;
4376
- if (state.phase === "interrupted") return this.#settle({
4377
- success: false,
4378
- error: state.poison
4379
- });
4380
- if (outcome.success) return this.#settle(outcome);
4659
+ if (state.phase === "interrupted") return this.#settle(failure(state.poison));
4660
+ if (isSuccess(outcome)) return this.#settle(outcome);
4381
4661
  const error = this.#owns(outcome.error) ? outcome.error : this.#create("cloneSchema: failed to create an owned schema snapshot", { cause: outcome.error });
4382
- return this.#settle({
4383
- success: false,
4384
- error
4385
- });
4662
+ return this.#settle(failure(error));
4386
4663
  }
4387
4664
  #execute() {
4388
4665
  if (INTRINSICS.array(this.#source)) this.#refuse("cloneSchema: a schema root must be a record, not an array", "structure", []);
@@ -4406,9 +4683,8 @@ var SchemaCloner = class SchemaCloner {
4406
4683
  if (frame.depth > 512) this.#refuse("cloneSchema: schema exceeds the compilation depth limit", "depth", frame.path);
4407
4684
  const keys = enumerableKeys(frame.source);
4408
4685
  if (keys === void 0) throw this.#create("cloneSchema: property enumeration failed", { path: frame.path });
4409
- for (let index = 0; index < keys.length; index += 1) {
4410
- const key = keys[index];
4411
- if (key === void 0) continue;
4686
+ INTRINSICS.reflect.apply(INTRINSICS.each, keys, [(key) => {
4687
+ if (key === void 0) return;
4412
4688
  const path = pathOf(frame.path, key);
4413
4689
  const source = this.#read(frame.source, key, path);
4414
4690
  const clone = this.#capture(source, path, frame.depth + 1);
@@ -4418,7 +4694,7 @@ var SchemaCloner = class SchemaCloner {
4418
4694
  configurable: true,
4419
4695
  writable: true
4420
4696
  });
4421
- }
4697
+ }]);
4422
4698
  INTRINSICS.freeze(frame.clone);
4423
4699
  }
4424
4700
  }
@@ -4445,7 +4721,7 @@ var SchemaCloner = class SchemaCloner {
4445
4721
  }
4446
4722
  #read(source, key, path) {
4447
4723
  const outcome = attempt(() => INTRINSICS.reflect.read(source, key));
4448
- if (outcome.success) return outcome.value;
4724
+ if (isSuccess(outcome)) return outcome.value;
4449
4725
  throw this.#create("cloneSchema: property access failed", {
4450
4726
  path,
4451
4727
  cause: outcome.error
@@ -4496,7 +4772,7 @@ var SchemaCloner = class SchemaCloner {
4496
4772
  phase: "settled",
4497
4773
  result
4498
4774
  };
4499
- if (result.success) return result.value;
4775
+ if (isSuccess(result)) return result.value;
4500
4776
  throw result.error;
4501
4777
  }
4502
4778
  static {
@@ -4504,105 +4780,49 @@ var SchemaCloner = class SchemaCloner {
4504
4780
  pinMembers(SchemaCloner.prototype, "SchemaCloner");
4505
4781
  }
4506
4782
  };
4507
- //#endregion
4508
- //#region src/core/ShapeValidator.ts
4509
- /**
4510
- * Validates one retained contract-shape source live on every call.
4511
- *
4512
- * @remarks
4513
- * Construction performs no source observation. Every non-overlapping
4514
- * {@link validate} call starts a fresh pass over the source's current state.
4515
- * Reentry poisons the active pass with one shared cause-free structure error;
4516
- * cleanup always restores an idle validator for the next independent call.
4517
- *
4518
- * @example
4519
- * ```ts
4520
- * const validator = new ShapeValidator({ category: 'string', min: 1 })
4521
- * validator.validate()
4522
- * ```
4523
- */
4524
- var ShapeValidator = class ShapeValidator {
4783
+ // src/core/ShapePass.ts
4784
+ /** Owns the traversal and reentry poison of one validation call. */
4785
+ var ShapePass = class ShapePass {
4525
4786
  static #weakSet = WeakSet;
4526
4787
  static #weakMap = WeakMap;
4527
4788
  #source;
4528
- #state = { phase: "idle" };
4529
4789
  #stack = [];
4530
4790
  #path = [];
4531
- #active = new ShapeValidator.#weakSet();
4532
- #index = new ShapeValidator.#weakMap();
4791
+ #active = new ShapePass.#weakSet();
4792
+ #index = new ShapePass.#weakMap();
4533
4793
  #captures = [];
4534
4794
  #post = [];
4535
4795
  #height = [];
4536
4796
  #reach = [];
4537
4797
  #via = [];
4538
4798
  #counts = [];
4539
- #schemas = new ShapeValidator.#weakMap();
4540
- #expansion = void 0;
4799
+ #schemas = new ShapePass.#weakMap();
4541
4800
  #children = [];
4542
4801
  #category;
4543
4802
  #raw = 0;
4544
4803
  #structure;
4545
4804
  #cycle;
4546
4805
  #domain;
4547
- /**
4548
- * Retains a shape source without observing it.
4549
- *
4550
- * @param shape - The live shape source validated by each call
4551
- */
4806
+ #clock = 0;
4807
+ #oldest = 0;
4808
+ #trail = [];
4809
+ #poison;
4552
4810
  constructor(shape) {
4553
4811
  this.#source = shape;
4554
4812
  }
4555
- /**
4556
- * Reports the number of nodes the last successful {@link validate} found the
4557
- * source expands into.
4558
- *
4559
- * @remarks
4560
- * One per node per INCOMING EDGE, summed bottom-up — the size of the tree a
4561
- * compiler would build from this DAG, which a node count of the declaration
4562
- * itself does not describe. `undefined` before the first successful pass and
4563
- * after a failed one, because a failed pass has no expansion to report and
4564
- * `0` is a measurement no declaration produces.
4565
- */
4566
- get expansion() {
4567
- return this.#expansion;
4813
+ /** Poisons this pass and throws the same refusal on every reentry. */
4814
+ interrupt() {
4815
+ this.#poison ??= new ContractError("ShapeValidator.validate: shape validation may not be reentered", {
4816
+ code: "structure",
4817
+ context: { path: [] }
4818
+ });
4819
+ throw this.#poison;
4568
4820
  }
4569
- /**
4570
- * Validates the retained source's current declaration.
4571
- *
4572
- * @remarks
4573
- * The whole traversal is contained, and a failure this class did not author
4574
- * is translated into `validateShape: shape reflection failed` carrying
4575
- * the exact thrown value. Containment is what makes that claim hold for
4576
- * dispatch nobody enumerated — including the recognition of an authored error,
4577
- * which is why that recognition is no longer answerable by any member a caller
4578
- * can write. The sentence this replaces asserted the same conclusion from the
4579
- * absence of reachable dispatch, and the absence was not established.
4580
- *
4581
- * @returns Nothing when the declaration is valid
4582
- * @throws {ContractError} When the declaration is malformed, cyclic, too deep, unreadable, or reentered
4583
- */
4821
+ /** Validates the captured source and returns its expansion. */
4584
4822
  validate() {
4585
- if (this.#state.phase === "active") {
4586
- const poison = this.#state.poison ?? new ContractError("ShapeValidator.validate: shape validation may not be reentered", {
4587
- code: "structure",
4588
- context: { path: [] }
4589
- });
4590
- this.#state = {
4591
- phase: "active",
4592
- poison
4593
- };
4594
- throw poison;
4595
- }
4596
- this.#clear();
4597
- this.#state = { phase: "active" };
4598
4823
  const outcome = attempt(() => this.#execute());
4599
- const poison = this.#state.phase === "active" ? this.#state.poison : void 0;
4600
- this.#clear();
4601
- if (poison !== void 0) {
4602
- this.#expansion = void 0;
4603
- throw poison;
4604
- }
4605
- if (outcome.success) return;
4824
+ if (this.#poison !== void 0) throw this.#poison;
4825
+ if (isSuccess(outcome)) return this.#counts[0] ?? 1;
4606
4826
  if (isContractError(outcome.error)) throw outcome.error;
4607
4827
  throw new ContractError("validateShape: shape reflection failed", {
4608
4828
  code: "structure",
@@ -4610,28 +4830,7 @@ var ShapeValidator = class ShapeValidator {
4610
4830
  cause: outcome.error
4611
4831
  });
4612
4832
  }
4613
- #clear() {
4614
- this.#state = { phase: "idle" };
4615
- this.#stack = [];
4616
- this.#path = [];
4617
- this.#active = new ShapeValidator.#weakSet();
4618
- this.#index = new ShapeValidator.#weakMap();
4619
- this.#captures = [];
4620
- this.#post = [];
4621
- this.#height = [];
4622
- this.#reach = [];
4623
- this.#via = [];
4624
- this.#counts = [];
4625
- this.#schemas = new ShapeValidator.#weakMap();
4626
- this.#children = [];
4627
- this.#category = void 0;
4628
- this.#raw = 0;
4629
- this.#structure = void 0;
4630
- this.#cycle = void 0;
4631
- this.#domain = void 0;
4632
- }
4633
4833
  #execute() {
4634
- this.#expansion = void 0;
4635
4834
  this.#stack[this.#stack.length] = {
4636
4835
  operation: "enter",
4637
4836
  shape: this.#source,
@@ -4641,7 +4840,6 @@ var ShapeValidator = class ShapeValidator {
4641
4840
  while (this.#stack.length > 0) this.#visit();
4642
4841
  this.#measure();
4643
4842
  this.#finish();
4644
- this.#expansion = this.#counts[0] ?? 1;
4645
4843
  }
4646
4844
  #visit() {
4647
4845
  const frame = this.#stack.pop();
@@ -4653,15 +4851,9 @@ var ShapeValidator = class ShapeValidator {
4653
4851
  this.#path.length -= frame.segments;
4654
4852
  return;
4655
4853
  }
4656
- let segments = 0;
4657
- if (frame.first !== void 0) {
4658
- this.#path[this.#path.length] = frame.first;
4659
- segments += 1;
4660
- }
4661
- if (frame.second !== void 0) {
4662
- this.#path[this.#path.length] = frame.second;
4663
- segments += 1;
4664
- }
4854
+ const segments = (frame.first === void 0 ? 0 : 1) + (frame.second === void 0 ? 0 : 1);
4855
+ if (frame.first !== void 0) this.#path[this.#path.length] = frame.first;
4856
+ if (frame.second !== void 0) this.#path[this.#path.length] = frame.second;
4665
4857
  const current = frame.shape;
4666
4858
  if (typeof current !== "object" || current === null || !isRecord(current)) {
4667
4859
  this.#structure ??= new ContractError("validateShape: every structural child must be a shape", {
@@ -4689,7 +4881,7 @@ var ShapeValidator = class ShapeValidator {
4689
4881
  this.#category = void 0;
4690
4882
  this.#raw = 0;
4691
4883
  const outcome = attempt(() => this.#observe(current, frame.depth));
4692
- if (!outcome.success || !outcome.value) {
4884
+ if (isFailure(outcome) || !outcome.value) {
4693
4885
  this.#structure ??= new ContractError("validateShape: every node must be a recognized shape", {
4694
4886
  code: "structure",
4695
4887
  context: { path: pathOf(this.#path) }
@@ -4713,23 +4905,23 @@ var ShapeValidator = class ShapeValidator {
4713
4905
  if (category === "raw") {
4714
4906
  const schema = current.schema;
4715
4907
  const outcome = attempt(() => this.#inspect(schema));
4716
- if (!outcome.success) return this.#refuse("validateShape: every node must be a recognized shape", "schema");
4908
+ if (isFailure(outcome)) return this.#refuse("validateShape: every node must be a recognized shape", "schema");
4717
4909
  if (!outcome.value) return false;
4718
4910
  if (depth + this.#raw > 512) return this.#refuse("validateShape: raw schema exceeds the compilation depth limit", "schema");
4719
4911
  }
4720
4912
  if (category === "object") {
4721
4913
  const outcome = attempt(() => this.#populate(current));
4722
- if (!outcome.success) return this.#refuse("validateShape: every node must be a recognized shape", "properties");
4914
+ if (isFailure(outcome)) return this.#refuse("validateShape: every node must be a recognized shape", "properties");
4723
4915
  return outcome.value;
4724
4916
  }
4725
4917
  if (category === "union") {
4726
4918
  const outcome = attempt(() => this.#populate(current));
4727
- if (!outcome.success) return this.#refuse("validateShape: every node must be a recognized shape", "variants");
4919
+ if (isFailure(outcome)) return this.#refuse("validateShape: every node must be a recognized shape", "variants");
4728
4920
  return outcome.value;
4729
4921
  }
4730
4922
  if (category === "literal") {
4731
4923
  const outcome = attempt(() => this.#populate(current));
4732
- if (!outcome.success) return this.#refuse("validateShape: every node must be a recognized shape", "values");
4924
+ if (isFailure(outcome)) return this.#refuse("validateShape: every node must be a recognized shape", "values");
4733
4925
  return outcome.value;
4734
4926
  }
4735
4927
  return this.#populate(current);
@@ -4774,7 +4966,7 @@ var ShapeValidator = class ShapeValidator {
4774
4966
  }
4775
4967
  }
4776
4968
  #scan(current, fields) {
4777
- for (let fieldIndex = 0; fieldIndex < fields.length; fieldIndex += 1) {
4969
+ for (const fieldIndex of iterateIndices(() => fields.length)) {
4778
4970
  const field = fields[fieldIndex];
4779
4971
  if (field === void 0) continue;
4780
4972
  const outcome = attempt(() => {
@@ -4789,7 +4981,7 @@ var ShapeValidator = class ShapeValidator {
4789
4981
  }
4790
4982
  return field === "pattern" && isRegExp(first) && isRegExp(second) && readPatternSource(first) === readPatternSource(second) && readPatternFlags(first) === readPatternFlags(second) && INTRINSICS.frozen(first) && INTRINSICS.frozen(second);
4791
4983
  });
4792
- if (!outcome.success || !outcome.value) return this.#refuse("validateShape: every node must be a recognized shape", field);
4984
+ if (isFailure(outcome) || !outcome.value) return this.#refuse("validateShape: every node must be a recognized shape", field);
4793
4985
  }
4794
4986
  return true;
4795
4987
  }
@@ -4925,7 +5117,7 @@ var ShapeValidator = class ShapeValidator {
4925
5117
  }
4926
5118
  #inspect(source) {
4927
5119
  if (!isRecord(source)) return this.#refuse("validateShape: raw schema must be a plain record", "schema");
4928
- const active = new ShapeValidator.#weakSet();
5120
+ const active = new ShapePass.#weakSet();
4929
5121
  const stack = [{
4930
5122
  operation: "enter",
4931
5123
  schema: source
@@ -4944,7 +5136,7 @@ var ShapeValidator = class ShapeValidator {
4944
5136
  if (INTRINSICS.reflect.apply(INTRINSICS.recall, this.#schemas, [schema]) !== void 0) continue;
4945
5137
  admitVisited(active, schema);
4946
5138
  const keyList = INTRINSICS.keys(schema);
4947
- for (let keyIndex = 0; keyIndex < keyList.length; keyIndex += 1) {
5139
+ for (const keyIndex of iterateIndices(() => keyList.length)) {
4948
5140
  const key = keyList[keyIndex];
4949
5141
  if (key === void 0) continue;
4950
5142
  if (key !== "type" && key !== "description" && key !== "enum" && key !== "minLength" && key !== "maxLength" && key !== "pattern" && key !== "format" && key !== "minimum" && key !== "maximum" && key !== "minItems" && key !== "maxItems" && key !== "items" && key !== "properties" && key !== "required" && key !== "additionalProperties" && key !== "anyOf" && key !== "oneOf") return this.#refuse("validateShape: raw schema contains an unsupported keyword", "schema");
@@ -4955,7 +5147,7 @@ var ShapeValidator = class ShapeValidator {
4955
5147
  if (schema.format !== void 0 && typeof schema.format !== "string") return this.#refuse("validateShape: raw schema format must be a string", "schema");
4956
5148
  if (schema.pattern !== void 0) {
4957
5149
  if (typeof schema.pattern !== "string") return this.#refuse("validateShape: raw schema pattern must be a string", "schema");
4958
- if (!attempt(() => INTRINSICS.reflect.apply(INTRINSICS.pattern, void 0, [schema.pattern])).success) return this.#refuse("validateShape: raw schema pattern must be valid", "schema");
5150
+ if (isFailure(attempt(() => INTRINSICS.reflect.apply(INTRINSICS.pattern, void 0, [schema.pattern])))) return this.#refuse("validateShape: raw schema pattern must be valid", "schema");
4959
5151
  }
4960
5152
  const lengthList = [
4961
5153
  "minLength",
@@ -4963,14 +5155,14 @@ var ShapeValidator = class ShapeValidator {
4963
5155
  "minItems",
4964
5156
  "maxItems"
4965
5157
  ];
4966
- for (let lengthIndex = 0; lengthIndex < lengthList.length; lengthIndex += 1) {
5158
+ for (const lengthIndex of iterateIndices(() => lengthList.length)) {
4967
5159
  const key = lengthList[lengthIndex];
4968
5160
  if (key === void 0) continue;
4969
5161
  const value = schema[key];
4970
5162
  if (value !== void 0 && (!INTRINSICS.safe(value) || INTRINSICS.numeric(value) < 0)) return this.#refuse("validateShape: raw schema length bounds must be non-negative safe integers", "schema");
4971
5163
  }
4972
5164
  const rangeList = ["minimum", "maximum"];
4973
- for (let rangeIndex = 0; rangeIndex < rangeList.length; rangeIndex += 1) {
5165
+ for (const rangeIndex of iterateIndices(() => rangeList.length)) {
4974
5166
  const key = rangeList[rangeIndex];
4975
5167
  if (key === void 0) continue;
4976
5168
  const value = schema[key];
@@ -4980,10 +5172,10 @@ var ShapeValidator = class ShapeValidator {
4980
5172
  if (population !== void 0) {
4981
5173
  if (!INTRINSICS.array(population)) return this.#refuse("validateShape: raw schema enum must be a non-empty array", "schema");
4982
5174
  const snapshot = readArrayEntries(population);
4983
- if (!snapshot.success || snapshot.value.entries.length === 0) return this.#refuse("validateShape: raw schema enum must be a non-empty array", "schema");
5175
+ if (isFailure(snapshot) || snapshot.value.entries.length === 0) return this.#refuse("validateShape: raw schema enum must be a non-empty array", "schema");
4984
5176
  if (!snapshot.value.dense) return this.#refuse("validateShape: raw schema enum must be dense", "schema");
4985
5177
  const values = collectMembers([]);
4986
- for (let valueIndex = 0; valueIndex < snapshot.value.entries.length; valueIndex += 1) {
5178
+ for (const valueIndex of iterateIndices(() => snapshot.value.entries.length)) {
4987
5179
  const value = snapshot.value.entries[valueIndex];
4988
5180
  if (!isLiteralValue(value) || typeof value === "number" && !INTRINSICS.finite(value) || matchesMember(values, value)) return this.#refuse("validateShape: raw schema enum values must be finite unique primitives", "schema");
4989
5181
  admitMember(values, value);
@@ -4993,10 +5185,10 @@ var ShapeValidator = class ShapeValidator {
4993
5185
  if (names !== void 0) {
4994
5186
  if (!INTRINSICS.array(names)) return this.#refuse("validateShape: raw schema required must be an array", "schema");
4995
5187
  const snapshot = readArrayEntries(names);
4996
- if (!snapshot.success) return this.#refuse("validateShape: raw schema required must be an array", "schema");
5188
+ if (isFailure(snapshot)) return this.#refuse("validateShape: raw schema required must be an array", "schema");
4997
5189
  if (!snapshot.value.dense) return this.#refuse("validateShape: raw schema required must be dense", "schema");
4998
5190
  const required = collectMembers([]);
4999
- for (let valueIndex = 0; valueIndex < snapshot.value.entries.length; valueIndex += 1) {
5191
+ for (const valueIndex of iterateIndices(() => snapshot.value.entries.length)) {
5000
5192
  const value = snapshot.value.entries[valueIndex];
5001
5193
  if (value === void 0) continue;
5002
5194
  if (typeof value !== "string" || matchesMember(required, value)) return this.#refuse("validateShape: raw schema required values must be unique strings", "schema");
@@ -5008,7 +5200,7 @@ var ShapeValidator = class ShapeValidator {
5008
5200
  if (schema.properties !== void 0) {
5009
5201
  if (!isRecord(schema.properties)) return this.#refuse("validateShape: raw schema properties must be a plain record", "schema");
5010
5202
  const propertyList = INTRINSICS.keys(schema.properties);
5011
- for (let propertyIndex = 0; propertyIndex < propertyList.length; propertyIndex += 1) {
5203
+ for (const propertyIndex of iterateIndices(() => propertyList.length)) {
5012
5204
  const key = propertyList[propertyIndex];
5013
5205
  if (key === void 0) continue;
5014
5206
  nested[nested.length] = schema.properties[key];
@@ -5016,37 +5208,38 @@ var ShapeValidator = class ShapeValidator {
5016
5208
  }
5017
5209
  if (schema.additionalProperties !== void 0 && schema.additionalProperties !== true && schema.additionalProperties !== false) nested[nested.length] = schema.additionalProperties;
5018
5210
  const unionList = ["anyOf", "oneOf"];
5019
- for (let unionIndex = 0; unionIndex < unionList.length; unionIndex += 1) {
5211
+ for (const unionIndex of iterateIndices(() => unionList.length)) {
5020
5212
  const key = unionList[unionIndex];
5021
5213
  if (key === void 0) continue;
5022
5214
  const variants = schema[key];
5023
5215
  if (variants === void 0) continue;
5024
5216
  if (!INTRINSICS.array(variants)) return this.#refuse("validateShape: raw schema unions must be non-empty arrays", "schema");
5025
5217
  const snapshot = readArrayEntries(variants);
5026
- if (!snapshot.success || snapshot.value.entries.length === 0) return this.#refuse("validateShape: raw schema unions must be non-empty arrays", "schema");
5218
+ if (isFailure(snapshot) || snapshot.value.entries.length === 0) return this.#refuse("validateShape: raw schema unions must be non-empty arrays", "schema");
5027
5219
  if (!snapshot.value.dense) return this.#refuse("validateShape: raw schema unions must be dense arrays", "schema");
5028
- for (let variantIndex = 0; variantIndex < snapshot.value.entries.length; variantIndex += 1) nested[nested.length] = snapshot.value.entries[variantIndex];
5220
+ for (const variantIndex of iterateIndices(() => snapshot.value.entries.length)) nested[nested.length] = snapshot.value.entries[variantIndex];
5029
5221
  }
5030
5222
  stack[stack.length] = {
5031
5223
  operation: "exit",
5032
5224
  schema,
5033
5225
  nested
5034
5226
  };
5035
- for (let index = nested.length - 1; index >= 0; index -= 1) stack[stack.length] = {
5036
- operation: "enter",
5037
- schema: nested[index]
5038
- };
5227
+ for (const offset of iterateIndices(() => nested.length)) {
5228
+ const index = nested.length - 1 - offset;
5229
+ stack[stack.length] = {
5230
+ operation: "enter",
5231
+ schema: nested[index]
5232
+ };
5233
+ }
5039
5234
  }
5040
5235
  this.#raw = INTRINSICS.reflect.apply(INTRINSICS.recall, this.#schemas, [source]) ?? 0;
5041
5236
  return true;
5042
5237
  }
5043
5238
  #settleSchema(schema, nested) {
5044
- let height = 0;
5045
- for (let index = 0; index < nested.length; index += 1) {
5046
- const child = nested[index];
5239
+ const height = INTRINSICS.reflect.apply(INTRINSICS.fold, nested, [(highest, child) => {
5047
5240
  const recorded = typeof child !== "object" || child === null ? 0 : INTRINSICS.reflect.apply(INTRINSICS.recall, this.#schemas, [child]) ?? 0;
5048
- if (recorded + 1 > height) height = recorded + 1;
5049
- }
5241
+ return INTRINSICS.max(highest, recorded + 1);
5242
+ }, 0]);
5050
5243
  INTRINSICS.reflect.apply(INTRINSICS.retain, this.#schemas, [schema, height]);
5051
5244
  }
5052
5245
  #populate(current) {
@@ -5062,11 +5255,11 @@ var ShapeValidator = class ShapeValidator {
5062
5255
  const properties = current.properties;
5063
5256
  if (!isRecord(properties)) return this.#refuse("validateShape: properties must be a plain property map", "properties");
5064
5257
  const keys = INTRINSICS.keys(properties);
5065
- for (let keyIndex = 0; keyIndex < keys.length; keyIndex += 1) {
5258
+ for (const keyIndex of iterateIndices(() => keys.length)) {
5066
5259
  const key = keys[keyIndex];
5067
5260
  if (key === void 0) continue;
5068
5261
  const descriptorOutcome = attempt(() => INTRINSICS.describe(properties, key));
5069
- if (!descriptorOutcome.success) return this.#refuse("validateShape: every node must be a recognized shape", "properties", key);
5262
+ if (isFailure(descriptorOutcome)) return this.#refuse("validateShape: every node must be a recognized shape", "properties", key);
5070
5263
  const descriptor = descriptorOutcome.value;
5071
5264
  if (descriptor === void 0 || !INTRINSICS.own(descriptor, "value")) {
5072
5265
  this.#children[this.#children.length] = {
@@ -5078,10 +5271,10 @@ var ShapeValidator = class ShapeValidator {
5078
5271
  continue;
5079
5272
  }
5080
5273
  const childOutcome = attempt(() => current.properties[key]);
5081
- if (!childOutcome.success) return this.#refuse("validateShape: every node must be a recognized shape", "properties", key);
5274
+ if (isFailure(childOutcome)) return this.#refuse("validateShape: every node must be a recognized shape", "properties", key);
5082
5275
  const child = childOutcome.value;
5083
5276
  const stable = attempt(() => INTRINSICS.same(current.properties[key], child) && INTRINSICS.same(descriptor.value, child));
5084
- if (!stable.success) return this.#refuse("validateShape: every node must be a recognized shape", "properties", key);
5277
+ if (isFailure(stable)) return this.#refuse("validateShape: every node must be a recognized shape", "properties", key);
5085
5278
  if (!stable.value) {
5086
5279
  this.#children[this.#children.length] = {
5087
5280
  shape: void 0,
@@ -5109,7 +5302,7 @@ var ShapeValidator = class ShapeValidator {
5109
5302
  case "union": {
5110
5303
  if (!INTRINSICS.array(current.variants)) return this.#refuse("validateShape: variants must be a finite array", "variants");
5111
5304
  const snapshot = readArrayEntries(current.variants);
5112
- if (!snapshot.success) return this.#refuse("validateShape: variants must be a finite array", "variants");
5305
+ if (isFailure(snapshot)) return this.#refuse("validateShape: variants must be a finite array", "variants");
5113
5306
  if (!snapshot.value.dense) return this.#refuse("validateShape: variants must be a dense data array", "variants");
5114
5307
  const variants = snapshot.value.entries;
5115
5308
  const length = variants.length;
@@ -5120,10 +5313,10 @@ var ShapeValidator = class ShapeValidator {
5120
5313
  shape: "union"
5121
5314
  }
5122
5315
  });
5123
- for (let index = 0; index < length; index += 1) {
5316
+ for (const index of iterateIndices(() => length)) {
5124
5317
  const key = INTRINSICS.text(index);
5125
5318
  const descriptorOutcome = attempt(() => INTRINSICS.describe(current.variants, key));
5126
- if (!descriptorOutcome.success) return this.#refuse("validateShape: every node must be a recognized shape", "variants", key);
5319
+ if (isFailure(descriptorOutcome)) return this.#refuse("validateShape: every node must be a recognized shape", "variants", key);
5127
5320
  const descriptor = descriptorOutcome.value;
5128
5321
  if (descriptor === void 0 || !INTRINSICS.own(descriptor, "value")) {
5129
5322
  this.#children[this.#children.length] = {
@@ -5136,7 +5329,7 @@ var ShapeValidator = class ShapeValidator {
5136
5329
  }
5137
5330
  const variant = variants[index];
5138
5331
  const stable = attempt(() => INTRINSICS.same(current.variants[index], variant) && INTRINSICS.same(descriptor.value, variant));
5139
- if (!stable.success) return this.#refuse("validateShape: every node must be a recognized shape", "variants", key);
5332
+ if (isFailure(stable)) return this.#refuse("validateShape: every node must be a recognized shape", "variants", key);
5140
5333
  if (!stable.value) {
5141
5334
  this.#children[this.#children.length] = {
5142
5335
  shape: void 0,
@@ -5158,7 +5351,7 @@ var ShapeValidator = class ShapeValidator {
5158
5351
  case "literal": {
5159
5352
  if (!INTRINSICS.array(current.values)) return this.#refuse("validateShape: values must be a finite literal array", "values");
5160
5353
  const snapshot = readArrayEntries(current.values);
5161
- if (!snapshot.success) return this.#refuse("validateShape: values must be a finite literal array", "values");
5354
+ if (isFailure(snapshot)) return this.#refuse("validateShape: values must be a finite literal array", "values");
5162
5355
  if (!snapshot.value.dense) return this.#refuse("validateShape: values must be a dense data array", "values");
5163
5356
  const literals = snapshot.value.entries;
5164
5357
  const length = literals.length;
@@ -5170,15 +5363,15 @@ var ShapeValidator = class ShapeValidator {
5170
5363
  }
5171
5364
  });
5172
5365
  const values = collectMembers([]);
5173
- for (let index = 0; index < length; index += 1) {
5366
+ for (const index of iterateIndices(() => length)) {
5174
5367
  const key = INTRINSICS.text(index);
5175
5368
  const descriptorOutcome = attempt(() => INTRINSICS.describe(current.values, key));
5176
- if (!descriptorOutcome.success) return this.#refuse("validateShape: every node must be a recognized shape", "values", key);
5369
+ if (isFailure(descriptorOutcome)) return this.#refuse("validateShape: every node must be a recognized shape", "values", key);
5177
5370
  const descriptor = descriptorOutcome.value;
5178
5371
  if (descriptor === void 0 || !INTRINSICS.own(descriptor, "value")) return this.#refuse("validateShape: values must be a dense data array", "values", key);
5179
5372
  const value = literals[index];
5180
5373
  const stable = attempt(() => INTRINSICS.same(current.values[index], value) && INTRINSICS.same(descriptor.value, value));
5181
- if (!stable.success) return this.#refuse("validateShape: every node must be a recognized shape", "values", key);
5374
+ if (isFailure(stable)) return this.#refuse("validateShape: every node must be a recognized shape", "values", key);
5182
5375
  if (!stable.value) return this.#refuse("validateShape: values must be a stable data array", "values", key);
5183
5376
  if (!isLiteralValue(value)) return this.#refuse("validateShape: every literal value must be a string, number, or boolean", "values", key);
5184
5377
  if (matchesMember(values, value)) return this.#refuse("validateShape: literal values must be unique", "values", key);
@@ -5205,20 +5398,15 @@ var ShapeValidator = class ShapeValidator {
5205
5398
  }
5206
5399
  #schedule(current, depth, segments) {
5207
5400
  admitVisited(this.#active, current);
5208
- const children = [];
5209
- for (let index = 0; index < this.#children.length; index += 1) {
5210
- const child = this.#children[index];
5211
- if (child === void 0) continue;
5212
- children[children.length] = child;
5213
- }
5401
+ const children = INTRINSICS.reflect.apply(INTRINSICS.select, readIndexView(this.#children), [(child) => child !== void 0]);
5214
5402
  const captured = this.#capture(current, children);
5215
5403
  this.#stack[this.#stack.length] = {
5216
5404
  operation: "exit",
5217
5405
  index: captured,
5218
5406
  segments
5219
5407
  };
5220
- for (let index = children.length - 1; index >= 0; index -= 1) {
5221
- const child = children[index];
5408
+ for (const offset of iterateIndices(() => children.length)) {
5409
+ const child = children[children.length - 1 - offset];
5222
5410
  if (child === void 0) continue;
5223
5411
  this.#stack[this.#stack.length] = {
5224
5412
  operation: "enter",
@@ -5247,7 +5435,7 @@ var ShapeValidator = class ShapeValidator {
5247
5435
  return INTRINSICS.reflect.apply(INTRINSICS.recall, this.#index, [shape]);
5248
5436
  }
5249
5437
  #measure() {
5250
- for (let index = 0; index < this.#captures.length; index += 1) {
5438
+ for (const index of iterateIndices(() => this.#captures.length)) {
5251
5439
  this.#height[index] = 0;
5252
5440
  this.#reach[index] = 0;
5253
5441
  this.#counts[index] = 1;
@@ -5256,32 +5444,34 @@ var ShapeValidator = class ShapeValidator {
5256
5444
  this.#trace();
5257
5445
  return;
5258
5446
  }
5259
- for (let step = 0; step < this.#post.length; step += 1) {
5447
+ for (const step of iterateIndices(() => this.#post.length)) {
5260
5448
  const index = this.#post[step];
5261
5449
  if (index === void 0) continue;
5262
5450
  const capture = this.#captures[index];
5263
5451
  if (capture === void 0) continue;
5264
- let height = 0;
5265
- let count = 1;
5266
- for (let edge = 0; edge < capture.children.length; edge += 1) {
5267
- const child = capture.children[edge];
5268
- if (child === void 0) continue;
5452
+ const totals = INTRINSICS.reflect.apply(INTRINSICS.fold, capture.children, [(current, child) => {
5269
5453
  const located = this.#locate(child.shape);
5270
5454
  const reached = located === void 0 ? 0 : this.#height[located] ?? 0;
5271
- if (reached + 1 > height) height = reached + 1;
5272
- count += located === void 0 ? 1 : this.#counts[located] ?? 1;
5273
- }
5274
- this.#height[index] = height;
5275
- this.#counts[index] = count;
5455
+ return {
5456
+ height: INTRINSICS.max(current.height, reached + 1),
5457
+ count: current.count + (located === void 0 ? 1 : this.#counts[located] ?? 1)
5458
+ };
5459
+ }, {
5460
+ height: 0,
5461
+ count: 1
5462
+ }]);
5463
+ this.#height[index] = totals.height;
5464
+ this.#counts[index] = totals.count;
5276
5465
  }
5277
- if ((this.#height[0] ?? 0) > 512) this.#witness();
5278
- for (let step = this.#post.length - 1; step >= 0; step -= 1) {
5466
+ if ((this.#height[0] ?? 0) > 512) this.#witness(0, 0, []);
5467
+ for (const offset of iterateIndices(() => this.#post.length)) {
5468
+ const step = this.#post.length - 1 - offset;
5279
5469
  const index = this.#post[step];
5280
5470
  if (index === void 0) continue;
5281
5471
  const capture = this.#captures[index];
5282
5472
  if (capture === void 0) continue;
5283
5473
  const base = this.#reach[index] ?? 0;
5284
- for (let edge = 0; edge < capture.children.length; edge += 1) {
5474
+ for (const edge of iterateIndices(() => capture.children.length)) {
5285
5475
  const child = capture.children[edge];
5286
5476
  if (child === void 0) continue;
5287
5477
  const located = this.#locate(child.shape);
@@ -5295,7 +5485,7 @@ var ShapeValidator = class ShapeValidator {
5295
5485
  };
5296
5486
  }
5297
5487
  }
5298
- for (let index = 0; index < this.#captures.length; index += 1) {
5488
+ for (const index of iterateIndices(() => this.#captures.length)) {
5299
5489
  const capture = this.#captures[index];
5300
5490
  if (capture === void 0 || capture.raw === 0) continue;
5301
5491
  if ((this.#reach[index] ?? 0) + capture.raw <= 512) continue;
@@ -5306,46 +5496,20 @@ var ShapeValidator = class ShapeValidator {
5306
5496
  }
5307
5497
  }
5308
5498
  #ascend(index) {
5309
- const reversed = [];
5310
- let current = index;
5311
- while (current !== 0) {
5312
- const edge = this.#via[current];
5313
- if (edge === void 0) break;
5314
- if (edge.second !== void 0) reversed[reversed.length] = edge.second;
5315
- reversed[reversed.length] = edge.first;
5316
- current = edge.parent;
5317
- }
5318
- const path = [];
5319
- for (let step = reversed.length - 1; step >= 0; step -= 1) {
5320
- const segment = reversed[step];
5321
- if (segment === void 0) continue;
5322
- path[path.length] = segment;
5323
- }
5324
- return path;
5499
+ if (index === 0) return [];
5500
+ const edge = this.#via[index];
5501
+ return edge === void 0 ? [] : pathOf(this.#ascend(edge.parent), edge.first, edge.second);
5325
5502
  }
5326
- #witness() {
5327
- const path = [];
5328
- let index = 0;
5329
- let depth = 0;
5330
- while (depth <= 512) {
5503
+ #witness(index, depth, path) {
5504
+ if (depth <= 512) {
5331
5505
  const capture = index === void 0 ? void 0 : this.#captures[index];
5332
5506
  const children = capture === void 0 ? [] : capture.children;
5333
- let chosen;
5334
- for (let edge = 0; edge < children.length; edge += 1) {
5335
- const child = children[edge];
5336
- if (child === void 0) continue;
5507
+ const chosen = children[INTRINSICS.reflect.apply(INTRINSICS.find, children, [(child) => {
5337
5508
  const located = this.#locate(child.shape);
5338
5509
  const reached = located === void 0 ? 0 : this.#height[located] ?? 0;
5339
- if (depth + 1 + reached > 512) {
5340
- chosen = child;
5341
- index = located;
5342
- break;
5343
- }
5344
- }
5345
- if (chosen === void 0) break;
5346
- path[path.length] = chosen.first;
5347
- if (chosen.second !== void 0) path[path.length] = chosen.second;
5348
- depth += 1;
5510
+ return depth + 1 + reached > 512;
5511
+ }])];
5512
+ if (chosen !== void 0) return this.#witness(this.#locate(chosen.shape), depth + 1, pathOf(path, chosen.first, chosen.second));
5349
5513
  }
5350
5514
  throw new ContractError("validateShape: a shape exceeds the compilation depth limit", {
5351
5515
  code: "depth",
@@ -5358,10 +5522,7 @@ var ShapeValidator = class ShapeValidator {
5358
5522
  #trace() {
5359
5523
  const settled = [];
5360
5524
  const order = [];
5361
- let clock = 0;
5362
- let oldest = 0;
5363
- const active = new ShapeValidator.#weakSet();
5364
- const path = [];
5525
+ const active = new ShapePass.#weakSet();
5365
5526
  const stack = [{
5366
5527
  operation: "enter",
5367
5528
  index: 0,
@@ -5373,56 +5534,51 @@ var ShapeValidator = class ShapeValidator {
5373
5534
  if (frame.operation === "exit") {
5374
5535
  const capture = this.#captures[frame.index];
5375
5536
  if (capture !== void 0) omitVisited(active, capture.shape);
5376
- if (oldest >= (order[frame.index] ?? 0) && (settled[frame.index] ?? -1) < frame.depth) settled[frame.index] = frame.depth;
5377
- if (frame.outer < oldest) oldest = frame.outer;
5378
- path.length -= frame.segments;
5537
+ if (this.#oldest >= (order[frame.index] ?? 0) && (settled[frame.index] ?? -1) < frame.depth) settled[frame.index] = frame.depth;
5538
+ if (frame.outer < this.#oldest) this.#oldest = frame.outer;
5539
+ this.#trail.length -= frame.segments;
5379
5540
  continue;
5380
5541
  }
5381
- let segments = 0;
5382
- if (frame.first !== void 0) {
5383
- path[path.length] = frame.first;
5384
- segments += 1;
5385
- }
5386
- if (frame.second !== void 0) {
5387
- path[path.length] = frame.second;
5388
- segments += 1;
5389
- }
5542
+ const segments = (frame.first === void 0 ? 0 : 1) + (frame.second === void 0 ? 0 : 1);
5543
+ if (frame.first !== void 0) this.#trail[this.#trail.length] = frame.first;
5544
+ if (frame.second !== void 0) this.#trail[this.#trail.length] = frame.second;
5390
5545
  if (frame.depth > 512) throw new ContractError("validateShape: a shape exceeds the compilation depth limit", {
5391
5546
  code: "depth",
5392
5547
  context: {
5393
- path: pathOf(path),
5548
+ path: pathOf(this.#trail),
5394
5549
  limit: 512
5395
5550
  }
5396
5551
  });
5397
5552
  const index = frame.index;
5398
5553
  const capture = index === void 0 ? void 0 : this.#captures[index];
5399
5554
  if (index === void 0 || capture === void 0) {
5400
- path.length -= segments;
5555
+ this.#trail.length -= segments;
5401
5556
  continue;
5402
5557
  }
5403
5558
  if (matchesVisited(active, capture.shape)) {
5404
5559
  const blocker = order[index] ?? 0;
5405
- if (blocker < oldest) oldest = blocker;
5406
- path.length -= segments;
5560
+ if (blocker < this.#oldest) this.#oldest = blocker;
5561
+ this.#trail.length -= segments;
5407
5562
  continue;
5408
5563
  }
5409
5564
  const recorded = settled[index];
5410
5565
  if (recorded !== void 0 && frame.depth <= recorded) {
5411
- path.length -= segments;
5566
+ this.#trail.length -= segments;
5412
5567
  continue;
5413
5568
  }
5414
5569
  admitVisited(active, capture.shape);
5415
- order[index] = clock;
5416
- clock += 1;
5570
+ order[index] = this.#clock;
5571
+ this.#clock += 1;
5417
5572
  stack[stack.length] = {
5418
5573
  operation: "exit",
5419
5574
  index,
5420
5575
  depth: frame.depth,
5421
5576
  segments,
5422
- outer: oldest
5577
+ outer: this.#oldest
5423
5578
  };
5424
- oldest = clock;
5425
- for (let edge = capture.children.length - 1; edge >= 0; edge -= 1) {
5579
+ this.#oldest = this.#clock;
5580
+ for (const offset of iterateIndices(() => capture.children.length)) {
5581
+ const edge = capture.children.length - 1 - offset;
5426
5582
  const child = capture.children[edge];
5427
5583
  if (child === void 0) continue;
5428
5584
  stack[stack.length] = {
@@ -5448,14 +5604,82 @@ var ShapeValidator = class ShapeValidator {
5448
5604
  context: { path }
5449
5605
  });
5450
5606
  }
5451
- return false;
5607
+ return false;
5608
+ }
5609
+ };
5610
+ // src/core/ShapeValidator.ts
5611
+ /**
5612
+ * Validates one retained contract-shape source live on every call.
5613
+ *
5614
+ * @remarks
5615
+ * Construction performs no source observation. Every non-overlapping
5616
+ * {@link validate} call starts a fresh pass over the source's current state.
5617
+ * Reentry poisons the active pass with one shared cause-free structure error;
5618
+ * cleanup always restores an idle validator for the next independent call.
5619
+ *
5620
+ * @example
5621
+ * ```ts
5622
+ * const validator = new ShapeValidator({ category: 'string', min: 1 })
5623
+ * validator.validate()
5624
+ * ```
5625
+ */
5626
+ var ShapeValidator = class ShapeValidator {
5627
+ #source;
5628
+ #passes = new INTRINSICS.set();
5629
+ #expansion;
5630
+ /**
5631
+ * Retains a shape source without observing it.
5632
+ *
5633
+ * @param shape - The live shape source validated by each call
5634
+ */
5635
+ constructor(shape) {
5636
+ this.#source = shape;
5637
+ }
5638
+ /**
5639
+ * Reports the number of nodes the last successful {@link validate} found the
5640
+ * source expands into.
5641
+ *
5642
+ * @remarks
5643
+ * One per node per INCOMING EDGE, summed bottom-up — the size of the tree a
5644
+ * compiler would build from this DAG, which a node count of the declaration
5645
+ * itself does not describe. `undefined` before the first successful pass and
5646
+ * after a failed one, because a failed pass has no expansion to report and
5647
+ * `0` is a measurement no declaration produces.
5648
+ */
5649
+ get expansion() {
5650
+ return this.#expansion;
5651
+ }
5652
+ /**
5653
+ * Validates the retained source's current declaration.
5654
+ *
5655
+ * @remarks
5656
+ * The whole traversal is contained, and a failure this class did not author
5657
+ * is translated into `validateShape: shape reflection failed` carrying
5658
+ * the exact thrown value. Containment is what makes that claim hold for
5659
+ * dispatch nobody enumerated — including the recognition of an authored error,
5660
+ * which is why that recognition is no longer answerable by any member a caller
5661
+ * can write. The sentence this replaces asserted the same conclusion from the
5662
+ * absence of reachable dispatch, and the absence was not established.
5663
+ *
5664
+ * @returns Nothing when the declaration is valid
5665
+ * @throws {ContractError} When the declaration is malformed, cyclic, too deep, unreadable, or reentered
5666
+ */
5667
+ validate() {
5668
+ INTRINSICS.reflect.apply(INTRINSICS.sweep, this.#passes, [(pass) => pass.interrupt()]);
5669
+ const pass = new ShapePass(this.#source);
5670
+ INTRINSICS.reflect.apply(INTRINSICS.admit, this.#passes, [pass]);
5671
+ this.#expansion = void 0;
5672
+ try {
5673
+ this.#expansion = pass.validate();
5674
+ } finally {
5675
+ INTRINSICS.reflect.apply(INTRINSICS.remove, this.#passes, [pass]);
5676
+ }
5452
5677
  }
5453
5678
  static {
5454
5679
  pinMembers(ShapeValidator.prototype, "ShapeValidator");
5455
5680
  }
5456
5681
  };
5457
- //#endregion
5458
- //#region src/core/ShapeCloner.ts
5682
+ // src/core/ShapeCloner.ts
5459
5683
  /**
5460
5684
  * Owns the state of one contract-shape snapshot operation.
5461
5685
  *
@@ -5513,7 +5737,7 @@ var ShapeCloner = class ShapeCloner {
5513
5737
  clone() {
5514
5738
  const state = this.#state;
5515
5739
  if (state.phase === "settled") {
5516
- if (state.result.success) return state.result.value;
5740
+ if (isSuccess(state.result)) return state.result.value;
5517
5741
  throw state.result.error;
5518
5742
  }
5519
5743
  if (state.phase === "running" || state.phase === "interrupted") {
@@ -5535,20 +5759,14 @@ var ShapeCloner = class ShapeCloner {
5535
5759
  }
5536
5760
  #complete(outcome) {
5537
5761
  const state = this.#state;
5538
- if (state.phase === "interrupted") return this.#settle({
5539
- success: false,
5540
- error: state.poison
5541
- });
5542
- if (outcome.success) return this.#settle(outcome);
5762
+ if (state.phase === "interrupted") return this.#settle(failure(state.poison));
5763
+ if (isSuccess(outcome)) return this.#settle(outcome);
5543
5764
  const error = this.#owns(outcome.error) ? outcome.error : this.#create("cloneShape: failed to create an owned shape snapshot", {
5544
5765
  code: "clone",
5545
5766
  context: { shape: "shape" },
5546
5767
  cause: outcome.error
5547
5768
  });
5548
- return this.#settle({
5549
- success: false,
5550
- error
5551
- });
5769
+ return this.#settle(failure(error));
5552
5770
  }
5553
5771
  #execute() {
5554
5772
  const paths = this.#paths;
@@ -5574,10 +5792,8 @@ var ShapeCloner = class ShapeCloner {
5574
5792
  #drain() {
5575
5793
  const memo = this.#memo;
5576
5794
  if (memo === void 0) throw this.#unavailable();
5577
- let cursor = 0;
5578
- while (cursor < this.#pending.length) {
5795
+ for (const cursor of iterateIndices(() => this.#pending.length)) {
5579
5796
  const entry = this.#pending[cursor];
5580
- cursor += 1;
5581
5797
  if (entry === void 0) continue;
5582
5798
  if (INTRINSICS.reflect.apply(INTRINSICS.keyed, memo, [entry.shape])) continue;
5583
5799
  if (entry.depth > 512) this.#refuseDepth();
@@ -5698,7 +5914,7 @@ var ShapeCloner = class ShapeCloner {
5698
5914
  source: readPatternSource(pattern)
5699
5915
  };
5700
5916
  });
5701
- if (typeof sourceText !== "string" || typeof flags !== "string" || !repeated.success || typeof repeated.value.source !== "string" || typeof repeated.value.flags !== "string" || repeated.value.source !== sourceText || repeated.value.flags !== flags) {
5917
+ if (typeof sourceText !== "string" || typeof flags !== "string" || isFailure(repeated) || typeof repeated.value.source !== "string" || typeof repeated.value.flags !== "string" || repeated.value.source !== sourceText || repeated.value.flags !== flags) {
5702
5918
  this.#fidelity ??= this.#create("validateShape: string pattern must be stable", {
5703
5919
  code: "structure",
5704
5920
  context: { path: pathOf(path, "pattern") }
@@ -5848,7 +6064,7 @@ var ShapeCloner = class ShapeCloner {
5848
6064
  schema
5849
6065
  });
5850
6066
  const outcome = attempt(() => new SchemaCloner(schema).clone());
5851
- if (!outcome.success) {
6067
+ if (isFailure(outcome)) {
5852
6068
  if (isContractError(outcome.error)) admitVisited(this.#owned, outcome.error);
5853
6069
  throw outcome.error;
5854
6070
  }
@@ -5863,7 +6079,7 @@ var ShapeCloner = class ShapeCloner {
5863
6079
  context: { path: pathOf(path, "values") }
5864
6080
  });
5865
6081
  const snapshot = readArrayEntries(values);
5866
- if (!snapshot.success) throw this.#create("validateShape: values must be a finite literal array", {
6082
+ if (isFailure(snapshot)) throw this.#create("validateShape: values must be a finite literal array", {
5867
6083
  code: "structure",
5868
6084
  context: { path: pathOf(path, "values") }
5869
6085
  });
@@ -5871,19 +6087,18 @@ var ShapeCloner = class ShapeCloner {
5871
6087
  code: "structure",
5872
6088
  context: { path: pathOf(path, "values") }
5873
6089
  });
5874
- const entries = [];
5875
- for (let index = 0; index < snapshot.value.entries.length; index += 1) entries[entries.length] = this.#literal(values, snapshot.value.entries[index], index, path);
6090
+ const entries = INTRINSICS.from(iterateIndices(() => snapshot.value.entries.length), (index) => this.#literal(values, snapshot.value.entries[index], index, path));
5876
6091
  return INTRINSICS.freeze(entries);
5877
6092
  }
5878
6093
  #literal(values, value, index, path) {
5879
6094
  const key = INTRINSICS.text(index);
5880
6095
  const descriptor = attempt(() => INTRINSICS.describe(values, key));
5881
6096
  const repeated = attempt(() => values[index]);
5882
- if (!descriptor.success || descriptor.value === void 0 || !INTRINSICS.own(descriptor.value, "value")) this.#fidelity ??= this.#create("validateShape: values must be a dense data array", {
6097
+ if (isFailure(descriptor) || descriptor.value === void 0 || !INTRINSICS.own(descriptor.value, "value")) this.#fidelity ??= this.#create("validateShape: values must be a dense data array", {
5883
6098
  code: "structure",
5884
6099
  context: { path: pathOf(path, "values", key) }
5885
6100
  });
5886
- else if (!repeated.success || !INTRINSICS.same(repeated.value, value) || !INTRINSICS.same(descriptor.value.value, value)) this.#fidelity ??= this.#create("validateShape: values must be a stable data array", {
6101
+ else if (isFailure(repeated) || !INTRINSICS.same(repeated.value, value) || !INTRINSICS.same(descriptor.value.value, value)) this.#fidelity ??= this.#create("validateShape: values must be a stable data array", {
5887
6102
  code: "structure",
5888
6103
  context: { path: pathOf(path, "values", key) }
5889
6104
  });
@@ -5895,10 +6110,7 @@ var ShapeCloner = class ShapeCloner {
5895
6110
  }
5896
6111
  #captureProperties(source, properties, path) {
5897
6112
  const keys = INTRINSICS.keys(properties);
5898
- const snapshot = [];
5899
- for (let index = 0; index < keys.length; index += 1) {
5900
- const key = keys[index];
5901
- if (key === void 0) continue;
6113
+ const snapshot = INTRINSICS.reflect.apply(INTRINSICS.project, readIndexView(keys), [(key) => {
5902
6114
  const descriptor = INTRINSICS.describe(properties, key);
5903
6115
  if (descriptor === void 0 || !INTRINSICS.own(descriptor, "value")) throw this.#create("validateShape: every structural child must be a shape", {
5904
6116
  code: "structure",
@@ -5911,15 +6123,13 @@ var ShapeCloner = class ShapeCloner {
5911
6123
  code: "structure",
5912
6124
  context: { path: pathOf(path, "properties", key) }
5913
6125
  });
5914
- snapshot[snapshot.length] = {
6126
+ return {
5915
6127
  key,
5916
6128
  child
5917
6129
  };
5918
- }
6130
+ }]);
5919
6131
  const repeated = INTRINSICS.keys(properties);
5920
- let drifted = repeated.length !== keys.length;
5921
- for (let index = 0; index < repeated.length; index += 1) if (repeated[index] !== keys[index]) drifted = true;
5922
- if (drifted) throw this.#create("cloneShape: property keys must be stable data", {
6132
+ if (repeated.length !== keys.length || INTRINSICS.reflect.apply(INTRINSICS.some, repeated, [(key, index) => key !== keys[index]])) throw this.#create("cloneShape: property keys must be stable data", {
5923
6133
  code: "structure",
5924
6134
  context: { path: pathOf(path, "properties") }
5925
6135
  });
@@ -5933,7 +6143,7 @@ var ShapeCloner = class ShapeCloner {
5933
6143
  context: { path: pathOf(path, "variants") }
5934
6144
  });
5935
6145
  const snapshot = readArrayEntries(variants);
5936
- if (!snapshot.success) throw this.#create("validateShape: variants must be a finite array", {
6146
+ if (isFailure(snapshot)) throw this.#create("validateShape: variants must be a finite array", {
5937
6147
  code: "structure",
5938
6148
  context: { path: pathOf(path, "variants") }
5939
6149
  });
@@ -5945,12 +6155,12 @@ var ShapeCloner = class ShapeCloner {
5945
6155
  const captured = this.#variants;
5946
6156
  if (captured === void 0) throw this.#unavailable();
5947
6157
  INTRINSICS.reflect.apply(INTRINSICS.store, captured, [source, entries]);
5948
- for (let index = 0; index < entries.length; index += 1) {
6158
+ for (const index of iterateIndices(() => entries.length)) {
5949
6159
  const variant = entries[index];
5950
6160
  const key = INTRINSICS.text(index);
5951
6161
  const descriptor = attempt(() => INTRINSICS.describe(variants, key));
5952
6162
  const repeated = attempt(() => variants[index]);
5953
- if (!descriptor.success || descriptor.value === void 0 || !INTRINSICS.own(descriptor.value, "value") || !repeated.success || !INTRINSICS.same(repeated.value, variant) || !INTRINSICS.same(descriptor.value.value, variant)) this.#fidelity ??= this.#create("validateShape: every structural child must be a shape", {
6163
+ if (isFailure(descriptor) || descriptor.value === void 0 || !INTRINSICS.own(descriptor.value, "value") || isFailure(repeated) || !INTRINSICS.same(repeated.value, variant) || !INTRINSICS.same(descriptor.value.value, variant)) this.#fidelity ??= this.#create("validateShape: every structural child must be a shape", {
5954
6164
  code: "structure",
5955
6165
  context: { path: pathOf(path, "variants", key) }
5956
6166
  });
@@ -5972,7 +6182,7 @@ var ShapeCloner = class ShapeCloner {
5972
6182
  shape: "object"
5973
6183
  }
5974
6184
  });
5975
- for (let index = 0; index < properties.length; index += 1) {
6185
+ for (const index of iterateIndices(() => properties.length)) {
5976
6186
  const entry = properties[index];
5977
6187
  if (entry === void 0 || entry.child === void 0) continue;
5978
6188
  this.#registerChild(entry.child, pathOf(path, "properties", entry.key), depth);
@@ -5989,7 +6199,7 @@ var ShapeCloner = class ShapeCloner {
5989
6199
  code: "structure",
5990
6200
  context: { path: pathOf(path, "variants") }
5991
6201
  });
5992
- for (let index = 0; index < variants.length; index += 1) {
6202
+ for (const index of iterateIndices(() => variants.length)) {
5993
6203
  const variant = variants[index];
5994
6204
  if (variant !== void 0) this.#registerChild(variant, pathOf(path, "variants", INTRINSICS.text(index)), depth);
5995
6205
  }
@@ -6012,7 +6222,7 @@ var ShapeCloner = class ShapeCloner {
6012
6222
  const memo = this.#memo;
6013
6223
  const paths = this.#paths;
6014
6224
  if (memo === void 0 || paths === void 0) throw this.#unavailable();
6015
- for (let sourceIndex = 0; sourceIndex < this.#sources.length; sourceIndex += 1) {
6225
+ for (const sourceIndex of iterateIndices(() => this.#sources.length)) {
6016
6226
  const source = this.#sources[sourceIndex];
6017
6227
  if (source === void 0) continue;
6018
6228
  const clone = INTRINSICS.reflect.apply(INTRINSICS.fetch, memo, [source]);
@@ -6055,10 +6265,8 @@ var ShapeCloner = class ShapeCloner {
6055
6265
  shape: "object"
6056
6266
  }
6057
6267
  });
6058
- const properties = INTRINSICS.create(null);
6059
- for (let index = 0; index < snapshot.length; index += 1) {
6060
- const entry = snapshot[index];
6061
- if (entry === void 0) continue;
6268
+ const pairs = INTRINSICS.reflect.apply(INTRINSICS.expand, readIndexView(snapshot), [(entry) => {
6269
+ if (entry === void 0) return [];
6062
6270
  const { key, child } = entry;
6063
6271
  if (child === void 0) throw this.#create("validateShape: every structural child must be a shape", {
6064
6272
  code: "structure",
@@ -6069,8 +6277,9 @@ var ShapeCloner = class ShapeCloner {
6069
6277
  code: "structure",
6070
6278
  context: { path: pathOf(path, "properties", key) }
6071
6279
  });
6072
- properties[key] = cloned;
6073
- }
6280
+ return [[key, cloned]];
6281
+ }]);
6282
+ const properties = INTRINSICS.rebase(INTRINSICS.record({ [Symbol.iterator]: INTRINSICS.reflect.apply(INTRINSICS.bind, INTRINSICS.iterator, [pairs]) }), null);
6074
6283
  INTRINSICS.reflect.write(clone, "properties", INTRINSICS.freeze(properties));
6075
6284
  const additional = clone.additionalProperties;
6076
6285
  if (additional !== void 0 && additional !== true && additional !== false) {
@@ -6091,8 +6300,7 @@ var ShapeCloner = class ShapeCloner {
6091
6300
  code: "structure",
6092
6301
  context: { path: pathOf(path, "variants") }
6093
6302
  });
6094
- const variants = [];
6095
- for (let index = 0; index < snapshot.length; index += 1) {
6303
+ const variants = INTRINSICS.from(iterateIndices(() => snapshot.length), (index) => {
6096
6304
  const variant = snapshot[index];
6097
6305
  if (variant === void 0) throw this.#create("validateShape: every structural child must be a shape", {
6098
6306
  code: "structure",
@@ -6103,8 +6311,8 @@ var ShapeCloner = class ShapeCloner {
6103
6311
  code: "structure",
6104
6312
  context: { path: pathOf(path, "variants", INTRINSICS.text(index)) }
6105
6313
  });
6106
- variants[variants.length] = cloned;
6107
- }
6314
+ return cloned;
6315
+ });
6108
6316
  INTRINSICS.reflect.write(clone, "variants", INTRINSICS.freeze(variants));
6109
6317
  }
6110
6318
  #wireWrapper(clone, path) {
@@ -6120,7 +6328,7 @@ var ShapeCloner = class ShapeCloner {
6120
6328
  #freezeNodes() {
6121
6329
  const memo = this.#memo;
6122
6330
  if (memo === void 0) throw this.#unavailable();
6123
- for (let sourceIndex = 0; sourceIndex < this.#sources.length; sourceIndex += 1) {
6331
+ for (const sourceIndex of iterateIndices(() => this.#sources.length)) {
6124
6332
  const source = this.#sources[sourceIndex];
6125
6333
  if (source === void 0) continue;
6126
6334
  const clone = INTRINSICS.reflect.apply(INTRINSICS.fetch, memo, [source]);
@@ -6129,7 +6337,7 @@ var ShapeCloner = class ShapeCloner {
6129
6337
  }
6130
6338
  #validateShape(shape) {
6131
6339
  const outcome = attempt(() => new ShapeValidator(shape).validate());
6132
- if (outcome.success) return;
6340
+ if (isSuccess(outcome)) return;
6133
6341
  if (isContractError(outcome.error)) admitVisited(this.#owned, outcome.error);
6134
6342
  throw outcome.error;
6135
6343
  }
@@ -6159,7 +6367,7 @@ var ShapeCloner = class ShapeCloner {
6159
6367
  phase: "settled",
6160
6368
  result
6161
6369
  };
6162
- if (result.success) return result.value;
6370
+ if (isSuccess(result)) return result.value;
6163
6371
  throw result.error;
6164
6372
  }
6165
6373
  static {
@@ -6168,8 +6376,7 @@ var ShapeCloner = class ShapeCloner {
6168
6376
  pinMembers(ShapeCloner.prototype, "ShapeCloner");
6169
6377
  }
6170
6378
  };
6171
- //#endregion
6172
- //#region src/core/cloners.ts
6379
+ // src/core/cloners.ts
6173
6380
  /**
6174
6381
  * Deep-clones exact JSON data into an owned frozen snapshot.
6175
6382
  *
@@ -6298,22 +6505,40 @@ function ownShape(shape) {
6298
6505
  return contain(() => {
6299
6506
  const frozen = holds(() => INTRINSICS.frozen(shape));
6300
6507
  const fidelity = attempt(() => cloneShape(shape));
6301
- if (fidelity.success) return fidelity.value;
6508
+ if (isSuccess(fidelity)) return fidelity.value;
6302
6509
  if (isContractError(fidelity.error) && fidelity.error.code !== "clone") throw fidelity.error;
6303
6510
  if (!frozen) throw fidelity.error;
6304
6511
  const validation = attempt(() => new ShapeValidator(shape).validate());
6305
- if (!validation.success && isContractError(validation.error)) throw validation.error;
6512
+ if (isFailure(validation) && isContractError(validation.error)) throw validation.error;
6306
6513
  throw fidelity.error;
6307
6514
  }, "ownShape");
6308
6515
  }
6309
- //#endregion
6310
- //#region src/core/combinators.ts
6516
+ // src/core/LazyGuard.ts
6517
+ /** Owns the active depth shared by calls to one deferred guard. */
6518
+ var LazyGuard = class {
6519
+ #thunk;
6520
+ #depth = 0;
6521
+ constructor(thunk) {
6522
+ this.#thunk = thunk;
6523
+ }
6524
+ /** Tests one value within the guard's shared recursion allowance. */
6525
+ test(value) {
6526
+ if (this.#depth >= 512) return false;
6527
+ this.#depth += 1;
6528
+ try {
6529
+ return holds(() => this.#thunk()(value));
6530
+ } finally {
6531
+ this.#depth -= 1;
6532
+ }
6533
+ }
6534
+ };
6535
+ // src/core/combinators.ts
6311
6536
  function arrayOf(elementGuard) {
6312
6537
  return (value) => holds(() => {
6313
6538
  if (!isArray(value)) return false;
6314
6539
  const entries = readArrayEntries(value);
6315
- if (!entries.success || !entries.value.dense) return false;
6316
- for (let index = 0; index < entries.value.entries.length; index += 1) if (!elementGuard(entries.value.entries[index])) return false;
6540
+ if (isFailure(entries) || !entries.value.dense) return false;
6541
+ for (const index of iterateIndices(() => entries.value.entries.length)) if (!elementGuard(entries.value.entries[index])) return false;
6317
6542
  return true;
6318
6543
  });
6319
6544
  }
@@ -6321,9 +6546,9 @@ function tupleOf(...guards) {
6321
6546
  return (value) => holds(() => {
6322
6547
  if (!isArray(value)) return false;
6323
6548
  const entries = readArrayEntries(value);
6324
- if (!entries.success || !entries.value.dense) return false;
6549
+ if (isFailure(entries) || !entries.value.dense) return false;
6325
6550
  if (entries.value.entries.length !== guards.length) return false;
6326
- for (let index = 0; index < guards.length; index += 1) {
6551
+ for (const index of iterateIndices(() => guards.length)) {
6327
6552
  const guard = guards[index];
6328
6553
  if (guard === void 0 || !guard(entries.value.entries[index])) return false;
6329
6554
  }
@@ -6341,7 +6566,7 @@ function literalOf(...literals) {
6341
6566
  }
6342
6567
  }) : false) && isArray(first) ? readValue(() => {
6343
6568
  const entries = readArrayEntries(first);
6344
- if (!entries.success) throw entries.error;
6569
+ if (isFailure(entries)) throw entries.error;
6345
6570
  if (!entries.value.dense) throw new INTRINSICS.error("Literal vocabulary must be dense");
6346
6571
  return entries.value.entries;
6347
6572
  }, "literalOf", {
@@ -6351,9 +6576,7 @@ function literalOf(...literals) {
6351
6576
  shape: "literal"
6352
6577
  }
6353
6578
  }) : literals;
6354
- let literal = true;
6355
- for (let index = 0; index < snapshot.length; index += 1) if (!isLiteralValue(snapshot[index])) literal = false;
6356
- if (!literal) throw new ContractError("literalOf: literals must contain only string, number, or boolean values", {
6579
+ if (!!INTRINSICS.reflect.apply(INTRINSICS.some, snapshot, [(value) => !isLiteralValue(value)])) throw new ContractError("literalOf: literals must contain only string, number, or boolean values", {
6357
6580
  code: "literal",
6358
6581
  context: {
6359
6582
  path: ["literals"],
@@ -6425,8 +6648,8 @@ function setOf(elementGuard) {
6425
6648
  return (value) => holds(() => {
6426
6649
  if (!isSet(value)) return false;
6427
6650
  const entries = readSetEntries(value);
6428
- if (!entries.success) return false;
6429
- for (let index = 0; index < entries.value.length; index += 1) if (!elementGuard(entries.value[index])) return false;
6651
+ if (isFailure(entries)) return false;
6652
+ for (const index of iterateIndices(() => entries.value.length)) if (!elementGuard(entries.value[index])) return false;
6430
6653
  return true;
6431
6654
  });
6432
6655
  }
@@ -6434,8 +6657,8 @@ function mapOf(keyGuard, valueGuard) {
6434
6657
  return (value) => holds(() => {
6435
6658
  if (!isMap(value)) return false;
6436
6659
  const entries = readMapEntries(value);
6437
- if (!entries.success) return false;
6438
- for (let index = 0; index < entries.value.length; index += 1) {
6660
+ if (isFailure(entries)) return false;
6661
+ for (const index of iterateIndices(() => entries.value.length)) {
6439
6662
  const entry = entries.value[index];
6440
6663
  if (entry === void 0) return false;
6441
6664
  if (!keyGuard(entry[0]) || !valueGuard(entry[1])) return false;
@@ -6449,11 +6672,11 @@ function recordOf(shape, optional) {
6449
6672
  return (value) => holds(() => {
6450
6673
  if (!isRecord(value)) return false;
6451
6674
  const members = INTRINSICS.reflect.members(value);
6452
- for (let index = 0; index < members.length; index += 1) {
6675
+ for (const index of iterateIndices(() => members.length)) {
6453
6676
  const key = members[index];
6454
6677
  if (isString(key) && !matchesMember(declared.vocabulary, key)) return false;
6455
6678
  }
6456
- for (let index = 0; index < declared.names.length; index += 1) {
6679
+ for (const index of iterateIndices(() => declared.names.length)) {
6457
6680
  const key = declared.names[index];
6458
6681
  if (key === void 0) continue;
6459
6682
  const guard = declared.guards[key];
@@ -6472,7 +6695,7 @@ function objectOf(shape, optional) {
6472
6695
  const declared = readGuardShape(shape, optional, "objectOf");
6473
6696
  return (value) => holds(() => {
6474
6697
  if (!isObject(value) && !isFunction(value) || INTRINSICS.array(value)) return false;
6475
- for (let index = 0; index < declared.names.length; index += 1) {
6698
+ for (const index of iterateIndices(() => declared.names.length)) {
6476
6699
  const key = declared.names[index];
6477
6700
  if (key === void 0) continue;
6478
6701
  const guard = declared.guards[key];
@@ -6534,23 +6757,19 @@ function pickOf(shape, keys) {
6534
6757
  return contain(() => {
6535
6758
  const selected = readValue(() => {
6536
6759
  const entries = readArrayEntries(keys);
6537
- if (!entries.success) throw entries.error;
6760
+ if (isFailure(entries)) throw entries.error;
6538
6761
  if (!entries.value.dense) throw new INTRINSICS.error("Picked key list must be dense");
6539
6762
  return collectMembers(entries.value.entries);
6540
6763
  }, "pickOf", { subject: "keys" });
6541
6764
  return readValue(() => {
6542
- const result = INTRINSICS.create(null);
6543
6765
  const members = INTRINSICS.reflect.members(shape);
6544
- for (let index = 0; index < members.length; index += 1) {
6545
- const key = members[index];
6546
- if (isString(key) && matchesMember(selected, key)) INTRINSICS.define(result, key, {
6547
- value: shape[key],
6548
- enumerable: true,
6549
- configurable: true,
6550
- writable: true
6551
- });
6552
- }
6553
- return result;
6766
+ const descriptors = INTRINSICS.reflect.apply(INTRINSICS.expand, readIndexView(members), [(key) => isString(key) && matchesMember(selected, key) ? [[key, {
6767
+ value: shape[key],
6768
+ enumerable: true,
6769
+ configurable: true,
6770
+ writable: true
6771
+ }]] : []]);
6772
+ return INTRINSICS.create(null, INTRINSICS.record({ [Symbol.iterator]: INTRINSICS.reflect.apply(INTRINSICS.bind, INTRINSICS.iterator, [descriptors]) }));
6554
6773
  }, "pickOf", { subject: "shape" });
6555
6774
  }, "pickOf");
6556
6775
  }
@@ -6577,23 +6796,19 @@ function omitOf(shape, keys) {
6577
6796
  return contain(() => {
6578
6797
  const skipped = readValue(() => {
6579
6798
  const entries = readArrayEntries(keys);
6580
- if (!entries.success) throw entries.error;
6799
+ if (isFailure(entries)) throw entries.error;
6581
6800
  if (!entries.value.dense) throw new INTRINSICS.error("Omitted key list must be dense");
6582
6801
  return collectMembers(entries.value.entries);
6583
6802
  }, "omitOf", { subject: "keys" });
6584
6803
  return readValue(() => {
6585
- const result = INTRINSICS.create(null);
6586
6804
  const members = INTRINSICS.reflect.members(shape);
6587
- for (let index = 0; index < members.length; index += 1) {
6588
- const key = members[index];
6589
- if (isString(key) && !matchesMember(skipped, key)) INTRINSICS.define(result, key, {
6590
- value: shape[key],
6591
- enumerable: true,
6592
- configurable: true,
6593
- writable: true
6594
- });
6595
- }
6596
- return result;
6805
+ const descriptors = INTRINSICS.reflect.apply(INTRINSICS.expand, readIndexView(members), [(key) => isString(key) && !matchesMember(skipped, key) ? [[key, {
6806
+ value: shape[key],
6807
+ enumerable: true,
6808
+ configurable: true,
6809
+ writable: true
6810
+ }]] : []]);
6811
+ return INTRINSICS.create(null, INTRINSICS.record({ [Symbol.iterator]: INTRINSICS.reflect.apply(INTRINSICS.bind, INTRINSICS.iterator, [descriptors]) }));
6597
6812
  }, "omitOf", { subject: "shape" });
6598
6813
  }, "omitOf");
6599
6814
  }
@@ -6653,7 +6868,7 @@ function complementOf(base, excluded) {
6653
6868
  }
6654
6869
  function unionOf(...guards) {
6655
6870
  return (value) => {
6656
- for (let index = 0; index < guards.length; index += 1) {
6871
+ for (const index of iterateIndices(() => guards.length)) {
6657
6872
  const guard = guards[index];
6658
6873
  if (guard !== void 0 && holds(() => guard(value))) return true;
6659
6874
  }
@@ -6662,7 +6877,7 @@ function unionOf(...guards) {
6662
6877
  }
6663
6878
  function intersectionOf(...guards) {
6664
6879
  return (value) => holds(() => {
6665
- for (let index = 0; index < guards.length; index += 1) {
6880
+ for (const index of iterateIndices(() => guards.length)) {
6666
6881
  const guard = guards[index];
6667
6882
  if (guard === void 0 || !guard(value)) return false;
6668
6883
  }
@@ -6693,22 +6908,16 @@ function whereOf(base, predicate) {
6693
6908
  *
6694
6909
  * @example
6695
6910
  * ```ts
6696
- * type Tree = { value: number; children: Tree[] }
6697
- * let isTree: Guard<Tree>
6698
- * isTree = recordOf({ value: isNumber, children: arrayOf(lazyOf(() => isTree)) })
6911
+ * type Tree = { readonly value: number; readonly children: readonly Tree[] }
6912
+ * const isTree: Guard<Tree> = recordOf({
6913
+ * value: isNumber,
6914
+ * children: arrayOf(lazyOf(() => isTree)),
6915
+ * })
6699
6916
  * ```
6700
6917
  */
6701
6918
  function lazyOf(thunk) {
6702
- let depth = 0;
6703
- return (value) => {
6704
- if (depth >= 512) return false;
6705
- depth += 1;
6706
- try {
6707
- return holds(() => thunk()(value));
6708
- } finally {
6709
- depth -= 1;
6710
- }
6711
- };
6919
+ const deferred = new LazyGuard(thunk);
6920
+ return (value) => deferred.test(value);
6712
6921
  }
6713
6922
  function transformOf(base, project, target) {
6714
6923
  return (value) => holds(() => base(value) && target(project(value)));
@@ -6847,8 +7056,7 @@ function nullableOf(guard) {
6847
7056
  function optionalOf(guard) {
6848
7057
  return (value) => holds(() => value === void 0 || guard(value));
6849
7058
  }
6850
- //#endregion
6851
- //#region src/core/parsers.ts
7059
+ // src/core/parsers.ts
6852
7060
  /**
6853
7061
  * Parses an unknown value to a string.
6854
7062
  *
@@ -6896,7 +7104,7 @@ function parseNumber(value) {
6896
7104
  const parsed = INTRINSICS.numeric(value);
6897
7105
  return INTRINSICS.finite(parsed) ? parsed : void 0;
6898
7106
  });
6899
- return outcome.success ? outcome.value : void 0;
7107
+ return isSuccess(outcome) ? outcome.value : void 0;
6900
7108
  }
6901
7109
  /**
6902
7110
  * Parses an unknown value to a finite integer.
@@ -7003,12 +7211,8 @@ function parseArray(value, guard) {
7003
7211
  if (!isArray(value)) return void 0;
7004
7212
  if (guard === void 0) return value;
7005
7213
  const entries = readArrayEntries(value);
7006
- if (!entries.success || !entries.value.dense) return void 0;
7007
- if (!holds(() => {
7008
- const collected = entries.value.entries;
7009
- for (let index = 0; index < collected.length; index += 1) if (!guard(collected[index])) return false;
7010
- return true;
7011
- })) return;
7214
+ if (isFailure(entries) || !entries.value.dense) return void 0;
7215
+ if (!holds(() => INTRINSICS.reflect.apply(INTRINSICS.find, entries.value.entries, [(entry) => !guard(entry)]) === -1)) return;
7012
7216
  return value;
7013
7217
  }
7014
7218
  /**
@@ -7040,11 +7244,38 @@ function parseJSONValue(value) {
7040
7244
  }
7041
7245
  function parseEnum(value, allowed) {
7042
7246
  const outcome = readArrayEntries(allowed);
7043
- if (!outcome.success || !outcome.value.dense) return void 0;
7247
+ if (isFailure(outcome) || !outcome.value.dense) return void 0;
7044
7248
  if (!holds(() => matchesMember(collectMembers(outcome.value.entries), value))) return void 0;
7045
7249
  return isLiteralValue(value) ? value : void 0;
7046
7250
  }
7047
7251
  /**
7252
+ * Parses indexed enum members, ending after the first undefined result.
7253
+ *
7254
+ * @param values - The source array, read by index
7255
+ * @param allowed - The accepted literal vocabulary
7256
+ * @returns Parsed members, including the first invalid member's undefined result
7257
+ *
7258
+ * @example
7259
+ * ```ts
7260
+ * Array.from(parseEnumValues(['a', 'x', 'b'], ['a', 'b'])) // ['a', undefined]
7261
+ * ```
7262
+ */
7263
+ function* parseEnumValues(values, allowed) {
7264
+ for (const index of iterateIndices(() => values.length)) {
7265
+ const member = parseEnum(values[index], allowed);
7266
+ yield member;
7267
+ if (member === void 0) return;
7268
+ }
7269
+ }
7270
+ for (const key of [
7271
+ "next",
7272
+ "return",
7273
+ "throw",
7274
+ Symbol.iterator
7275
+ ]) INTRINSICS.define(parseEnumValues.prototype, key, { value: INTRINSICS.reflect.read(parseEnumValues.prototype, key) });
7276
+ INTRINSICS.freeze(parseEnumValues.prototype);
7277
+ INTRINSICS.freeze(parseEnumValues);
7278
+ /**
7048
7279
  * Reads and parses a string field from a record by key or nested key path.
7049
7280
  *
7050
7281
  * @param record - The source record
@@ -7221,10 +7452,87 @@ function parseJSONAs(value, guard) {
7221
7452
  const parsed = parseJSON(value);
7222
7453
  if (parsed === void 0) return void 0;
7223
7454
  const checked = attempt(() => guard(parsed) ? parsed : void 0);
7224
- return checked.success ? checked.value : void 0;
7455
+ return isSuccess(checked) ? checked.value : void 0;
7456
+ }
7457
+ // src/core/EvaluationScope.ts
7458
+ /** Owns compiled-node memo entries for one synchronous evaluation. */
7459
+ var EvaluationScope = class EvaluationScope {
7460
+ static #active = new INTRINSICS.set();
7461
+ static #path = INTRINSICS.freeze([]);
7462
+ #answers = new INTRINSICS.weakMap();
7463
+ /** Evaluates a node within the active call, disposing a newly opened scope on settlement. */
7464
+ static run(plan, value, path = EvaluationScope.#path, clean = false) {
7465
+ if (!isObject(value)) return plan(value, path);
7466
+ const entries = readSetEntries(EvaluationScope.#active);
7467
+ if (isFailure(entries)) throw entries.error;
7468
+ const active = entries.value[0];
7469
+ if (active instanceof EvaluationScope) return active.#evaluate(plan, value, path, clean);
7470
+ if (active !== void 0) throw new INTRINSICS.error("Evaluation scope is unavailable");
7471
+ const scope = new EvaluationScope();
7472
+ INTRINSICS.reflect.apply(INTRINSICS.admit, EvaluationScope.#active, [scope]);
7473
+ try {
7474
+ return scope.#evaluate(plan, value, path, clean);
7475
+ } finally {
7476
+ INTRINSICS.reflect.apply(INTRINSICS.remove, EvaluationScope.#active, [scope]);
7477
+ }
7478
+ }
7479
+ #evaluate(plan, value, path, clean) {
7480
+ const cached = INTRINSICS.reflect.apply(INTRINSICS.recall, this.#answers, [plan]);
7481
+ const memo = cached ?? new INTRINSICS.weakMap();
7482
+ if (cached === void 0) INTRINSICS.reflect.apply(INTRINSICS.retain, this.#answers, [plan, memo]);
7483
+ const recalled = INTRINSICS.reflect.apply(INTRINSICS.recall, memo, [value]);
7484
+ if (recalled !== void 0) return recalled;
7485
+ const answer = plan(value, path);
7486
+ if (!clean || INTRINSICS.array(answer) && answer.length === 0) INTRINSICS.reflect.apply(INTRINSICS.retain, memo, [value, answer]);
7487
+ return answer;
7488
+ }
7489
+ };
7490
+ // src/core/RandomSource.ts
7491
+ /** Owns the changing state projected by one seeded random function. */
7492
+ var RandomSource = class {
7493
+ #state;
7494
+ constructor(seed) {
7495
+ this.#state = seed >>> 0;
7496
+ }
7497
+ /** Advances the generator and returns its next unit-interval value. */
7498
+ next() {
7499
+ this.#state = this.#state + 1831565813 >>> 0;
7500
+ const mixed = INTRINSICS.imul(this.#state ^ this.#state >>> 15, this.#state | 1);
7501
+ const final = mixed ^ mixed + INTRINSICS.imul(mixed ^ mixed >>> 7, mixed | 61);
7502
+ return ((final ^ final >>> 14) >>> 0) / 4294967296;
7503
+ }
7504
+ };
7505
+ // src/core/seeders.ts
7506
+ /**
7507
+ * Builds a deterministic pseudo-random source seeded from a single number.
7508
+ *
7509
+ * @remarks
7510
+ * A mulberry32 generator — the same seed always yields the same sequence, so
7511
+ * generated seed data is reproducible across runs. Used as the default random
7512
+ * source for {@link compileGenerator}, seeded from the wall clock so casual
7513
+ * callers still get varied output without passing a source themselves.
7514
+ *
7515
+ * @param seed - The seed for the sequence
7516
+ * @returns A {@link RandomFunction} returning values in `[0, 1)`
7517
+ *
7518
+ * @example
7519
+ * ```ts
7520
+ * const random = seededRandom(42)
7521
+ * random() // always the same first value for seed 42
7522
+ * ```
7523
+ */
7524
+ function seededRandom(seed) {
7525
+ if (!isNumber(seed)) throw new ContractError("seededRandom: seed must be a number", {
7526
+ code: "random",
7527
+ context: {
7528
+ limit: "number",
7529
+ received: preview(seed)
7530
+ }
7531
+ });
7532
+ const source = new RandomSource(seed);
7533
+ return () => source.next();
7225
7534
  }
7226
- //#endregion
7227
- //#region src/core/ContractCompiler.ts
7535
+ // src/core/ContractCompiler.ts
7228
7536
  /**
7229
7537
  * Owns one contract shape's artifacts and their bundle, compiled lazily.
7230
7538
  *
@@ -7268,8 +7576,6 @@ function parseJSONAs(value, guard) {
7268
7576
  */
7269
7577
  var ContractCompiler = class ContractCompiler {
7270
7578
  static #weakMap = WeakMap;
7271
- static #visits = 0;
7272
- static #scope = 0;
7273
7579
  static #emptyStack = [];
7274
7580
  static #emptyNodes = [];
7275
7581
  static #emptyOrder = [];
@@ -7420,7 +7726,7 @@ var ContractCompiler = class ContractCompiler {
7420
7726
  #leave(outcome) {
7421
7727
  const state = this.#state;
7422
7728
  if (state.phase === "interrupted") return this.#fail(state.poison);
7423
- if (!outcome.success) return this.#fail(isContractError(outcome.error) ? outcome.error : new ContractError("ContractCompiler: contract compilation failed", {
7729
+ if (isFailure(outcome)) return this.#fail(isContractError(outcome.error) ? outcome.error : new ContractError("ContractCompiler: contract compilation failed", {
7424
7730
  code: "structure",
7425
7731
  context: {
7426
7732
  path: [],
@@ -7526,7 +7832,8 @@ var ContractCompiler = class ContractCompiler {
7526
7832
  };
7527
7833
  return;
7528
7834
  case "union":
7529
- for (let index = shape.variants.length - 1; index >= 0; index -= 1) {
7835
+ for (const offset of iterateIndices(() => shape.variants.length)) {
7836
+ const index = shape.variants.length - 1 - offset;
7530
7837
  const variant = shape.variants[index];
7531
7838
  if (variant === void 0) continue;
7532
7839
  this.#stack[this.#stack.length] = {
@@ -7542,8 +7849,8 @@ var ContractCompiler = class ContractCompiler {
7542
7849
  shape: extra
7543
7850
  };
7544
7851
  const keys = INTRINSICS.keys(shape.properties);
7545
- for (let index = keys.length - 1; index >= 0; index -= 1) {
7546
- const key = keys[index];
7852
+ for (const offset of iterateIndices(() => keys.length)) {
7853
+ const key = keys[keys.length - 1 - offset];
7547
7854
  if (key === void 0) continue;
7548
7855
  const child = shape.properties[key];
7549
7856
  if (child === void 0) continue;
@@ -7588,7 +7895,7 @@ var ContractCompiler = class ContractCompiler {
7588
7895
  return shape;
7589
7896
  }
7590
7897
  #unions() {
7591
- for (let index = 0; index < this.#nodes.length; index += 1) if (this.#nodes[index]?.category === "union") return true;
7898
+ for (const index of iterateIndices(() => this.#nodes.length)) if (this.#nodes[index]?.category === "union") return true;
7592
7899
  return false;
7593
7900
  }
7594
7901
  #repeats(index) {
@@ -7597,94 +7904,16 @@ var ContractCompiler = class ContractCompiler {
7597
7904
  return category === "optional" || category === "nullable";
7598
7905
  }
7599
7906
  #trackGuard(plan) {
7600
- let filled = 0;
7601
- let memo;
7602
- let slot;
7603
- let kept = false;
7604
- return (value) => {
7605
- if (!isObject(value)) return plan(value);
7606
- const opened = ContractCompiler.#scope === 0;
7607
- if (opened) {
7608
- ContractCompiler.#visits += 1;
7609
- ContractCompiler.#scope = ContractCompiler.#visits;
7610
- }
7611
- try {
7612
- const scope = ContractCompiler.#scope;
7613
- if (filled !== scope) {
7614
- memo = void 0;
7615
- slot = void 0;
7616
- kept = false;
7617
- filled = scope;
7618
- }
7619
- if (slot === value) return kept;
7620
- if (memo !== void 0) {
7621
- const recalled = INTRINSICS.reflect.apply(INTRINSICS.recall, memo, [value]);
7622
- if (recalled !== void 0) return recalled;
7623
- }
7624
- const answer = plan(value);
7625
- if (slot === void 0) {
7626
- slot = value;
7627
- kept = answer;
7628
- } else {
7629
- if (memo === void 0) {
7630
- memo = new ContractCompiler.#weakMap();
7631
- INTRINSICS.reflect.apply(INTRINSICS.retain, memo, [slot, kept]);
7632
- }
7633
- INTRINSICS.reflect.apply(INTRINSICS.retain, memo, [value, answer]);
7634
- }
7635
- return answer;
7636
- } finally {
7637
- if (opened) ContractCompiler.#scope = 0;
7638
- }
7639
- };
7907
+ return (value) => EvaluationScope.run(plan, value);
7640
7908
  }
7641
7909
  #trackFaults(plan) {
7642
- let filled = 0;
7643
- let memo;
7644
- let slot;
7645
- let kept;
7646
- return (value, path) => {
7647
- if (!isObject(value)) return plan(value, path);
7648
- const opened = ContractCompiler.#scope === 0;
7649
- if (opened) {
7650
- ContractCompiler.#visits += 1;
7651
- ContractCompiler.#scope = ContractCompiler.#visits;
7652
- }
7653
- try {
7654
- const scope = ContractCompiler.#scope;
7655
- if (filled !== scope) {
7656
- memo = void 0;
7657
- slot = void 0;
7658
- kept = void 0;
7659
- filled = scope;
7660
- }
7661
- if (slot === value && kept !== void 0) return kept;
7662
- if (memo !== void 0) {
7663
- const recalled = INTRINSICS.reflect.apply(INTRINSICS.recall, memo, [value]);
7664
- if (recalled !== void 0) return recalled;
7665
- }
7666
- const answer = plan(value, path);
7667
- if (slot === void 0) {
7668
- slot = value;
7669
- kept = answer.length === 0 ? answer : void 0;
7670
- } else if (answer.length === 0) {
7671
- if (memo === void 0) {
7672
- memo = new ContractCompiler.#weakMap();
7673
- if (kept !== void 0) INTRINSICS.reflect.apply(INTRINSICS.retain, memo, [slot, kept]);
7674
- }
7675
- INTRINSICS.reflect.apply(INTRINSICS.retain, memo, [value, answer]);
7676
- }
7677
- return answer;
7678
- } finally {
7679
- if (opened) ContractCompiler.#scope = 0;
7680
- }
7681
- };
7910
+ return (value, path) => EvaluationScope.run(plan, value, path, true);
7682
7911
  }
7683
7912
  #buildSchema() {
7684
7913
  const ready = this.#schema;
7685
7914
  if (ready !== void 0) return ready;
7686
7915
  this.#prepare();
7687
- for (let step = 0; step < this.#order.length; step += 1) {
7916
+ for (const step of iterateIndices(() => this.#order.length)) {
7688
7917
  const index = this.#order[step];
7689
7918
  if (index === void 0) continue;
7690
7919
  this.#schemas[index] = this.#schemaOf(index);
@@ -7737,12 +7966,7 @@ var ContractCompiler = class ContractCompiler {
7737
7966
  });
7738
7967
  case "json": return INTRINSICS.freeze({ ...owned.description !== void 0 ? { description: owned.description } : {} });
7739
7968
  case "literal": {
7740
- const vocabulary = [];
7741
- for (let index2 = 0; index2 < owned.values.length; index2 += 1) {
7742
- const value = owned.values[index2];
7743
- if (value === void 0) continue;
7744
- vocabulary[vocabulary.length] = value;
7745
- }
7969
+ const vocabulary = INTRINSICS.reflect.apply(INTRINSICS.select, readIndexView(owned.values), [(value) => value !== void 0]);
7746
7970
  return INTRINSICS.freeze({
7747
7971
  enum: INTRINSICS.freeze(vocabulary),
7748
7972
  ...owned.description !== void 0 ? { description: owned.description } : {}
@@ -7756,17 +7980,18 @@ var ContractCompiler = class ContractCompiler {
7756
7980
  ...owned.description !== void 0 ? { description: owned.description } : {}
7757
7981
  });
7758
7982
  case "object": {
7759
- const properties = INTRINSICS.create(null);
7760
- const required = [];
7761
- const keyList = INTRINSICS.keys(owned.properties);
7762
- for (let keyIndex = 0; keyIndex < keyList.length; keyIndex += 1) {
7763
- const key = keyList[keyIndex];
7764
- if (key === void 0) continue;
7983
+ const entries = INTRINSICS.reflect.apply(INTRINSICS.expand, readIndexView(INTRINSICS.keys(owned.properties)), [(key) => {
7765
7984
  const child = owned.properties[key];
7766
- if (child === void 0) continue;
7767
- properties[key] = this.#schemaAt(child.category === "optional" ? child.inner : child);
7768
- if (child.category !== "optional") required[required.length] = key;
7769
- }
7985
+ if (child === void 0) return [];
7986
+ return [{
7987
+ key,
7988
+ schema: this.#schemaAt(child.category === "optional" ? child.inner : child),
7989
+ required: child.category !== "optional"
7990
+ }];
7991
+ }]);
7992
+ const pairs = INTRINSICS.reflect.apply(INTRINSICS.project, readIndexView(entries), [(entry) => [entry.key, entry.schema]]);
7993
+ const properties = INTRINSICS.rebase(INTRINSICS.record({ [Symbol.iterator]: INTRINSICS.reflect.apply(INTRINSICS.bind, INTRINSICS.iterator, [pairs]) }), null);
7994
+ const required = INTRINSICS.reflect.apply(INTRINSICS.expand, readIndexView(entries), [(entry) => entry.required ? [entry.key] : []]);
7770
7995
  const extra = owned.additionalProperties;
7771
7996
  const additionalProperties = extra === true ? true : extra !== void 0 && extra !== false ? this.#schemaAt(extra) : false;
7772
7997
  return INTRINSICS.freeze({
@@ -7778,12 +8003,7 @@ var ContractCompiler = class ContractCompiler {
7778
8003
  });
7779
8004
  }
7780
8005
  case "union": {
7781
- const variants = [];
7782
- for (let index2 = 0; index2 < owned.variants.length; index2 += 1) {
7783
- const variant = owned.variants[index2];
7784
- if (variant === void 0) continue;
7785
- variants[variants.length] = this.#schemaAt(variant);
7786
- }
8006
+ const variants = INTRINSICS.reflect.apply(INTRINSICS.expand, readIndexView(owned.variants), [(variant) => variant === void 0 ? [] : [this.#schemaAt(variant)]]);
7787
8007
  return INTRINSICS.freeze({
7788
8008
  ...owned.mode === "oneOf" ? { oneOf: INTRINSICS.freeze(variants) } : { anyOf: INTRINSICS.freeze(variants) },
7789
8009
  ...owned.description !== void 0 ? { description: owned.description } : {}
@@ -7798,7 +8018,7 @@ var ContractCompiler = class ContractCompiler {
7798
8018
  const ready = this.#guard;
7799
8019
  if (ready !== void 0) return ready;
7800
8020
  this.#prepare();
7801
- for (let step = 0; step < this.#order.length; step += 1) {
8021
+ for (const step of iterateIndices(() => this.#order.length)) {
7802
8022
  const index = this.#order[step];
7803
8023
  if (index === void 0) continue;
7804
8024
  const plan = this.#guardOf(index);
@@ -7843,64 +8063,42 @@ var ContractCompiler = class ContractCompiler {
7843
8063
  return whereOf(base, (value) => withinLength(value.length));
7844
8064
  }
7845
8065
  case "object": {
7846
- const map = INTRINSICS.create(null);
7847
- const optionalKeys = [];
7848
- const keyList = INTRINSICS.keys(owned.properties);
7849
- for (let keyIndex = 0; keyIndex < keyList.length; keyIndex += 1) {
7850
- const key = keyList[keyIndex];
7851
- if (key === void 0) continue;
8066
+ const entries = INTRINSICS.reflect.apply(INTRINSICS.expand, readIndexView(INTRINSICS.keys(owned.properties)), [(key) => {
7852
8067
  const child = owned.properties[key];
7853
- if (child === void 0) continue;
7854
- if (child.category === "optional") {
7855
- map[key] = this.#guardAt(child.inner);
7856
- optionalKeys[optionalKeys.length] = key;
7857
- } else map[key] = this.#guardAt(child);
7858
- }
8068
+ if (child === void 0) return [];
8069
+ const optional = child.category === "optional";
8070
+ return [{
8071
+ key,
8072
+ guard: this.#guardAt(optional ? child.inner : child),
8073
+ optional
8074
+ }];
8075
+ }]);
8076
+ const pairs = INTRINSICS.reflect.apply(INTRINSICS.project, readIndexView(entries), [(entry) => [entry.key, entry.guard]]);
8077
+ const map = INTRINSICS.rebase(INTRINSICS.record({ [Symbol.iterator]: INTRINSICS.reflect.apply(INTRINSICS.bind, INTRINSICS.iterator, [pairs]) }), null);
8078
+ const optionalKeys = INTRINSICS.reflect.apply(INTRINSICS.expand, readIndexView(entries), [(entry) => entry.optional ? [entry.key] : []]);
7859
8079
  const extra = owned.additionalProperties;
7860
8080
  const closed = extra === void 0 || extra === false;
7861
8081
  const additional = closed || extra === true ? void 0 : this.#guardAt(extra);
7862
- const required = [];
7863
- const declared = INTRINSICS.keys(map);
7864
- for (let keyIndex = 0; keyIndex < declared.length; keyIndex += 1) {
7865
- const key = declared[keyIndex];
7866
- if (key === void 0) continue;
7867
- let optional = false;
7868
- for (let optionalIndex = 0; optionalIndex < optionalKeys.length; optionalIndex += 1) if (optionalKeys[optionalIndex] === key) optional = true;
7869
- if (!optional) required[required.length] = key;
7870
- }
8082
+ const required = INTRINSICS.reflect.apply(INTRINSICS.select, readIndexView(INTRINSICS.keys(map)), [(key) => !INTRINSICS.reflect.apply(INTRINSICS.some, optionalKeys, [(optional) => optional === key])]);
7871
8083
  const maskable = required.length <= 31;
7872
- const positions = INTRINSICS.create(null);
7873
- let full = 0;
7874
- if (maskable) for (let keyIndex = 0; keyIndex < required.length; keyIndex += 1) {
7875
- const key = required[keyIndex];
7876
- if (key === void 0) continue;
7877
- positions[key] = keyIndex;
7878
- full |= 1 << keyIndex;
7879
- }
8084
+ const positions = buildPositions(maskable ? required : []);
8085
+ const full = maskable ? readPresence(required, positions) : 0;
7880
8086
  return (value) => {
7881
8087
  if (!isRecord(value)) return false;
7882
8088
  const keys = enumerableKeys(value);
7883
8089
  if (keys === void 0) return false;
7884
8090
  const outcome = attempt(() => {
7885
8091
  if (maskable) {
7886
- let seen = 0;
7887
- for (let keyIndex = 0; keyIndex < keys.length; keyIndex += 1) {
7888
- const key = keys[keyIndex];
7889
- if (key === void 0) continue;
7890
- if (!INTRINSICS.own(positions, key)) continue;
7891
- const position = positions[key];
7892
- if (position !== void 0) seen |= 1 << position;
7893
- }
7894
- if (seen !== full) return false;
8092
+ if (readPresence(keys, positions) !== full) return false;
7895
8093
  } else {
7896
8094
  const present = collectMembers(keys);
7897
- for (let keyIndex = 0; keyIndex < required.length; keyIndex += 1) {
8095
+ for (const keyIndex of iterateIndices(() => required.length)) {
7898
8096
  const key = required[keyIndex];
7899
8097
  if (key === void 0) continue;
7900
8098
  if (!matchesMember(present, key)) return false;
7901
8099
  }
7902
8100
  }
7903
- for (let keyIndex = 0; keyIndex < keys.length; keyIndex += 1) {
8101
+ for (const keyIndex of iterateIndices(() => keys.length)) {
7904
8102
  const key = keys[keyIndex];
7905
8103
  if (key === void 0) continue;
7906
8104
  const guard = INTRINSICS.own(map, key) ? map[key] : void 0;
@@ -7914,23 +8112,13 @@ var ContractCompiler = class ContractCompiler {
7914
8112
  }
7915
8113
  return true;
7916
8114
  });
7917
- return outcome.success && outcome.value;
8115
+ return isSuccess(outcome) && outcome.value;
7918
8116
  };
7919
8117
  }
7920
8118
  case "union": {
7921
- const guards = [];
7922
- for (let index2 = 0; index2 < owned.variants.length; index2 += 1) {
7923
- const variant = owned.variants[index2];
7924
- if (variant === void 0) continue;
7925
- guards[guards.length] = this.#guardAt(variant);
7926
- }
8119
+ const guards = INTRINSICS.reflect.apply(INTRINSICS.expand, readIndexView(owned.variants), [(variant) => variant === void 0 ? [] : [this.#guardAt(variant)]]);
7927
8120
  if (owned.mode === "oneOf") return (value) => {
7928
- let matched = 0;
7929
- for (let index2 = 0; index2 < guards.length; index2 += 1) {
7930
- const guard = guards[index2];
7931
- if (guard !== void 0 && guard(value)) matched += 1;
7932
- }
7933
- return matched === 1;
8121
+ return INTRINSICS.reflect.apply(INTRINSICS.fold, guards, [(total, guard) => total + (guard(value) ? 1 : 0), 0]) === 1;
7934
8122
  };
7935
8123
  return INTRINSICS.reflect.apply(unionOf, void 0, guards);
7936
8124
  }
@@ -7944,7 +8132,7 @@ var ContractCompiler = class ContractCompiler {
7944
8132
  if (ready !== void 0) return ready;
7945
8133
  this.#prepare();
7946
8134
  if (this.#unions()) this.#buildGuard();
7947
- for (let step = 0; step < this.#order.length; step += 1) {
8135
+ for (const step of iterateIndices(() => this.#order.length)) {
7948
8136
  const index = this.#order[step];
7949
8137
  if (index === void 0) continue;
7950
8138
  this.#parsers[index] = this.#parserOf(index);
@@ -8012,7 +8200,7 @@ var ContractCompiler = class ContractCompiler {
8012
8200
  });
8013
8201
  if (!isArray(value)) return void 0;
8014
8202
  const entries = readArrayEntries(value);
8015
- if (!entries.success) return readValue(() => {
8203
+ if (isFailure(entries)) return readValue(() => {
8016
8204
  throw entries.error;
8017
8205
  }, "compileParser", {
8018
8206
  subject: "array",
@@ -8020,7 +8208,7 @@ var ContractCompiler = class ContractCompiler {
8020
8208
  });
8021
8209
  if (!entries.value.dense) return void 0;
8022
8210
  const result = [];
8023
- for (let entryIndex = 0; entryIndex < entries.value.entries.length; entryIndex += 1) {
8211
+ for (const entryIndex of iterateIndices(() => entries.value.entries.length)) {
8024
8212
  const parsed = item(entries.value.entries[entryIndex]);
8025
8213
  if (parsed === void 0) return void 0;
8026
8214
  result[result.length] = parsed;
@@ -8029,39 +8217,24 @@ var ContractCompiler = class ContractCompiler {
8029
8217
  };
8030
8218
  }
8031
8219
  case "object": {
8032
- const entries = [];
8033
8220
  const keyList = INTRINSICS.keys(owned.properties);
8034
- for (let keyIndex = 0; keyIndex < keyList.length; keyIndex += 1) {
8035
- const key = keyList[keyIndex];
8036
- if (key === void 0) continue;
8221
+ const entries = INTRINSICS.reflect.apply(INTRINSICS.expand, readIndexView(keyList), [(key) => {
8037
8222
  const child = owned.properties[key];
8038
- if (child === void 0) continue;
8223
+ if (child === void 0) return [];
8039
8224
  const optional = child.category === "optional";
8040
- entries[entries.length] = {
8225
+ const inner = optional ? child.inner : child;
8226
+ return [{
8041
8227
  key,
8042
- parse: this.#parserAt(optional ? child.inner : child),
8228
+ parse: this.#parserAt(inner),
8043
8229
  optional
8044
- };
8045
- }
8046
- const known = readValue(() => {
8047
- const declared = collectMembers([]);
8048
- for (let entryIndex = 0; entryIndex < entries.length; entryIndex += 1) {
8049
- const entry = entries[entryIndex];
8050
- if (entry === void 0) continue;
8051
- admitMember(declared, entry.key);
8052
- }
8053
- return declared;
8054
- }, "compileParser", {
8230
+ }];
8231
+ }]);
8232
+ const known = readValue(() => collectMembers(INTRINSICS.reflect.apply(INTRINSICS.project, readIndexView(entries), [(entry) => entry.key])), "compileParser", {
8055
8233
  subject: "object",
8056
8234
  context: { shape: "object" }
8057
8235
  });
8058
8236
  const maskable = entries.length <= 31;
8059
- const positions = INTRINSICS.create(null);
8060
- if (maskable) for (let entryIndex = 0; entryIndex < entries.length; entryIndex += 1) {
8061
- const entry = entries[entryIndex];
8062
- if (entry === void 0) continue;
8063
- positions[entry.key] = entryIndex;
8064
- }
8237
+ const positions = buildPositions(maskable ? INTRINSICS.reflect.apply(INTRINSICS.project, readIndexView(entries), [(entry) => entry.key]) : []);
8065
8238
  const extra = owned.additionalProperties;
8066
8239
  const additional = extra === void 0 || extra === false || extra === true ? void 0 : this.#parserAt(extra);
8067
8240
  const open = extra === true || additional !== void 0;
@@ -8072,16 +8245,9 @@ var ContractCompiler = class ContractCompiler {
8072
8245
  if (keys === void 0) return void 0;
8073
8246
  const outcome = attempt(() => {
8074
8247
  const present = maskable ? void 0 : collectMembers(keys);
8075
- let seen = 0;
8076
- if (present === void 0) for (let keyIndex = 0; keyIndex < keys.length; keyIndex += 1) {
8077
- const key = keys[keyIndex];
8078
- if (key === void 0) continue;
8079
- if (!INTRINSICS.own(positions, key)) continue;
8080
- const position = positions[key];
8081
- if (position !== void 0) seen |= 1 << position;
8082
- }
8083
- const result = INTRINSICS.create(null);
8084
- for (let entryIndex = 0; entryIndex < entries.length; entryIndex += 1) {
8248
+ const seen = present === void 0 ? readPresence(keys, positions) : 0;
8249
+ const selected = [];
8250
+ for (const entryIndex of iterateIndices(() => entries.length)) {
8085
8251
  const entry = entries[entryIndex];
8086
8252
  if (entry === void 0) continue;
8087
8253
  if (present === void 0 ? (seen & 1 << entryIndex) === 0 : !matchesMember(present, entry.key)) {
@@ -8095,22 +8261,22 @@ var ContractCompiler = class ContractCompiler {
8095
8261
  }
8096
8262
  const parsed = entry.parse(raw);
8097
8263
  if (parsed === void 0) return void 0;
8098
- result[entry.key] = parsed;
8264
+ selected[selected.length] = [entry.key, parsed];
8099
8265
  }
8100
- if (open) for (let keyIndex = 0; keyIndex < keys.length; keyIndex += 1) {
8266
+ if (open) for (const keyIndex of iterateIndices(() => keys.length)) {
8101
8267
  const key = keys[keyIndex];
8102
8268
  if (key === void 0) continue;
8103
8269
  if (matchesMember(known, key)) continue;
8104
- if (additional === void 0) result[key] = record[key];
8270
+ if (additional === void 0) selected[selected.length] = [key, record[key]];
8105
8271
  else {
8106
8272
  const parsed = additional(record[key]);
8107
8273
  if (parsed === void 0) return void 0;
8108
- result[key] = parsed;
8274
+ selected[selected.length] = [key, parsed];
8109
8275
  }
8110
8276
  }
8111
- return result;
8277
+ return INTRINSICS.rebase(INTRINSICS.record({ [Symbol.iterator]: INTRINSICS.reflect.apply(INTRINSICS.bind, INTRINSICS.iterator, [selected]) }), null);
8112
8278
  });
8113
- if (outcome.success) return outcome.value;
8279
+ if (isSuccess(outcome)) return outcome.value;
8114
8280
  if (isContractError(outcome.error)) throw outcome.error;
8115
8281
  return readValue(() => {
8116
8282
  throw outcome.error;
@@ -8121,33 +8287,22 @@ var ContractCompiler = class ContractCompiler {
8121
8287
  };
8122
8288
  }
8123
8289
  case "union": {
8124
- const variants = [];
8125
- for (let index2 = 0; index2 < owned.variants.length; index2 += 1) {
8126
- const variant = owned.variants[index2];
8127
- if (variant === void 0) continue;
8128
- variants[variants.length] = {
8129
- parse: this.#parserAt(variant),
8130
- guard: this.#guardAt(variant)
8131
- };
8132
- }
8290
+ const variants = INTRINSICS.reflect.apply(INTRINSICS.expand, readIndexView(owned.variants), [(variant) => variant === void 0 ? [] : [{
8291
+ parse: this.#parserAt(variant),
8292
+ guard: this.#guardAt(variant)
8293
+ }]]);
8133
8294
  if (owned.mode === "oneOf") return (value) => {
8134
- let matched = 0;
8135
- let only;
8136
- for (let index2 = 0; index2 < variants.length; index2 += 1) {
8137
- const variant = variants[index2];
8138
- if (variant === void 0 || !variant.guard(value)) continue;
8139
- matched += 1;
8140
- if (matched === 1) only = variant;
8141
- }
8142
- return matched === 1 && only !== void 0 ? only.parse(value) : void 0;
8295
+ const matching = INTRINSICS.reflect.apply(INTRINSICS.select, readIndexView(variants), [(variant) => variant.guard(value)]);
8296
+ const only = matching[0];
8297
+ return matching.length === 1 && only !== void 0 ? only.parse(value) : void 0;
8143
8298
  };
8144
8299
  return (value) => {
8145
- for (let variantIndex = 0; variantIndex < variants.length; variantIndex += 1) {
8300
+ for (const variantIndex of iterateIndices(() => variants.length)) {
8146
8301
  const variant = variants[variantIndex];
8147
8302
  if (variant === void 0) continue;
8148
8303
  if (variant.guard(value)) return value;
8149
8304
  }
8150
- for (let variantIndex = 0; variantIndex < variants.length; variantIndex += 1) {
8305
+ for (const variantIndex of iterateIndices(() => variants.length)) {
8151
8306
  const variant = variants[variantIndex];
8152
8307
  if (variant === void 0) continue;
8153
8308
  const parsed = variant.parse(value);
@@ -8170,7 +8325,7 @@ var ContractCompiler = class ContractCompiler {
8170
8325
  const ready = this.#auditor;
8171
8326
  if (ready !== void 0) return ready;
8172
8327
  this.#prepare();
8173
- for (let step = 0; step < this.#order.length; step += 1) {
8328
+ for (const step of iterateIndices(() => this.#order.length)) {
8174
8329
  const index = this.#order[step];
8175
8330
  if (index === void 0) continue;
8176
8331
  const plan = this.#auditOf(index);
@@ -8271,7 +8426,7 @@ var ContractCompiler = class ContractCompiler {
8271
8426
  received: preview(value)
8272
8427
  }];
8273
8428
  const entries = readArrayEntries(value);
8274
- if (!entries.success) return readValue(() => {
8429
+ if (isFailure(entries)) return readValue(() => {
8275
8430
  throw entries.error;
8276
8431
  }, "compileAuditor", {
8277
8432
  subject: "array",
@@ -8281,7 +8436,7 @@ var ContractCompiler = class ContractCompiler {
8281
8436
  }
8282
8437
  });
8283
8438
  const faults = [];
8284
- for (let entryIndex = 0; entryIndex < entries.value.entries.length; entryIndex += 1) {
8439
+ for (const entryIndex of iterateIndices(() => entries.value.entries.length)) {
8285
8440
  if (faults.length >= 64) break;
8286
8441
  appendEntries(faults, item(entries.value.entries[entryIndex], pathOf(path, INTRINSICS.text(entryIndex))));
8287
8442
  }
@@ -8290,34 +8445,26 @@ var ContractCompiler = class ContractCompiler {
8290
8445
  };
8291
8446
  }
8292
8447
  case "object": {
8293
- const entries = [];
8294
8448
  const declaredKeys = INTRINSICS.keys(owned.properties);
8295
- for (let keyIndex = 0; keyIndex < declaredKeys.length; keyIndex += 1) {
8296
- const key = declaredKeys[keyIndex];
8297
- if (key === void 0) continue;
8449
+ const entries = INTRINSICS.reflect.apply(INTRINSICS.expand, readIndexView(declaredKeys), [(key) => {
8298
8450
  const child = owned.properties[key];
8299
- if (child === void 0) continue;
8451
+ if (child === void 0) return [];
8300
8452
  const optional = child.category === "optional";
8301
8453
  const inner = optional ? child.inner : child;
8302
- entries[entries.length] = {
8454
+ return [{
8303
8455
  key,
8304
8456
  audit: this.#auditAt(inner),
8305
8457
  optional,
8306
8458
  kind: shapeToKind(inner)
8307
- };
8308
- }
8459
+ }];
8460
+ }]);
8309
8461
  const extra = owned.additionalProperties;
8310
8462
  const closed = extra === void 0 || extra === false;
8311
8463
  const additional = closed || extra === true ? void 0 : this.#auditAt(extra);
8312
8464
  const planned = attempt(() => collectMembers(declaredKeys));
8313
- const declared = planned.success ? planned.value : void 0;
8465
+ const declared = isSuccess(planned) ? planned.value : void 0;
8314
8466
  const maskable = entries.length <= 31;
8315
- const positions = INTRINSICS.create(null);
8316
- if (maskable) for (let entryIndex = 0; entryIndex < entries.length; entryIndex += 1) {
8317
- const entry = entries[entryIndex];
8318
- if (entry === void 0) continue;
8319
- positions[entry.key] = entryIndex;
8320
- }
8467
+ const positions = buildPositions(maskable ? INTRINSICS.reflect.apply(INTRINSICS.project, readIndexView(entries), [(entry) => entry.key]) : []);
8321
8468
  return (value, path) => {
8322
8469
  if (isObject(value)) readValue(() => INTRINSICS.reflect.prototype(value), "compileAuditor", {
8323
8470
  subject: "object",
@@ -8344,15 +8491,8 @@ var ContractCompiler = class ContractCompiler {
8344
8491
  const outcome = attempt(() => {
8345
8492
  const present = maskable ? void 0 : collectMembers(keys);
8346
8493
  const vocabulary = declared ?? collectMembers(declaredKeys);
8347
- let seen = 0;
8348
- if (present === void 0) for (let keyIndex = 0; keyIndex < keys.length; keyIndex += 1) {
8349
- const key = keys[keyIndex];
8350
- if (key === void 0) continue;
8351
- if (!INTRINSICS.own(positions, key)) continue;
8352
- const position = positions[key];
8353
- if (position !== void 0) seen |= 1 << position;
8354
- }
8355
- for (let entryIndex = 0; entryIndex < entries.length; entryIndex += 1) {
8494
+ const seen = present === void 0 ? readPresence(keys, positions) : 0;
8495
+ for (const entryIndex of iterateIndices(() => entries.length)) {
8356
8496
  const entry = entries[entryIndex];
8357
8497
  if (entry === void 0) continue;
8358
8498
  if (faults.length >= 64) return;
@@ -8366,7 +8506,7 @@ var ContractCompiler = class ContractCompiler {
8366
8506
  }
8367
8507
  appendEntries(faults, entry.audit(record[entry.key], pathOf(path, entry.key)));
8368
8508
  }
8369
- for (let keyIndex = 0; keyIndex < keys.length; keyIndex += 1) {
8509
+ for (const keyIndex of iterateIndices(() => keys.length)) {
8370
8510
  const key = keys[keyIndex];
8371
8511
  if (key === void 0) continue;
8372
8512
  if (faults.length >= 64) return;
@@ -8382,7 +8522,7 @@ var ContractCompiler = class ContractCompiler {
8382
8522
  if (additional !== void 0) appendEntries(faults, additional(observed, pathOf(path, key)));
8383
8523
  }
8384
8524
  });
8385
- if (!outcome.success) {
8525
+ if (isFailure(outcome)) {
8386
8526
  if (isContractError(outcome.error)) throw outcome.error;
8387
8527
  return readValue(() => {
8388
8528
  throw outcome.error;
@@ -8398,27 +8538,21 @@ var ContractCompiler = class ContractCompiler {
8398
8538
  };
8399
8539
  }
8400
8540
  case "union": {
8401
- const plans = [];
8402
- for (let index2 = 0; index2 < owned.variants.length; index2 += 1) {
8403
- const variant = owned.variants[index2];
8404
- if (variant === void 0) continue;
8405
- plans[plans.length] = this.#auditAt(variant);
8406
- }
8541
+ const plans = INTRINSICS.reflect.apply(INTRINSICS.expand, readIndexView(owned.variants), [(variant) => variant === void 0 ? [] : [this.#auditAt(variant)]]);
8407
8542
  const exclusive = owned.mode === "oneOf";
8408
8543
  const count = owned.variants.length;
8409
8544
  return (value, path) => {
8410
8545
  const perVariant = [];
8411
- let matched = 0;
8412
- for (let index2 = 0; index2 < plans.length; index2 += 1) {
8546
+ for (const index2 of iterateIndices(() => plans.length)) {
8413
8547
  const plan = plans[index2];
8414
8548
  if (plan === void 0) continue;
8415
8549
  const variantFaults = plan(value, path);
8416
8550
  if (variantFaults.length === 0) {
8417
8551
  if (!exclusive) return [];
8418
- matched += 1;
8419
8552
  }
8420
8553
  perVariant[perVariant.length] = variantFaults;
8421
8554
  }
8555
+ const matched = INTRINSICS.reflect.apply(INTRINSICS.fold, perVariant, [(total, faults) => total + (faults.length === 0 ? 1 : 0), 0]);
8422
8556
  if (exclusive) {
8423
8557
  if (matched === 1) return [];
8424
8558
  if (matched > 1) return [{
@@ -8462,7 +8596,7 @@ var ContractCompiler = class ContractCompiler {
8462
8596
  if (ready !== void 0) return ready;
8463
8597
  this.#prepare();
8464
8598
  if (this.#unions()) this.#buildGuard();
8465
- for (let step = 0; step < this.#order.length; step += 1) {
8599
+ for (const step of iterateIndices(() => this.#order.length)) {
8466
8600
  const index = this.#order[step];
8467
8601
  if (index === void 0) continue;
8468
8602
  const plan = this.#reportOf(index);
@@ -8558,14 +8692,14 @@ var ContractCompiler = class ContractCompiler {
8558
8692
  received: preview(value)
8559
8693
  }];
8560
8694
  const entries = readArrayEntries(value);
8561
- if (!entries.success) return [{
8695
+ if (isFailure(entries)) return [{
8562
8696
  reason: "type",
8563
8697
  path,
8564
8698
  expected: "array",
8565
8699
  received: preview(value)
8566
8700
  }];
8567
8701
  const faults = [];
8568
- for (let entryIndex = 0; entryIndex < entries.value.entries.length; entryIndex += 1) {
8702
+ for (const entryIndex of iterateIndices(() => entries.value.entries.length)) {
8569
8703
  if (faults.length >= 64) break;
8570
8704
  appendEntries(faults, item(entries.value.entries[entryIndex], pathOf(path, INTRINSICS.text(entryIndex))));
8571
8705
  }
@@ -8574,36 +8708,27 @@ var ContractCompiler = class ContractCompiler {
8574
8708
  };
8575
8709
  }
8576
8710
  case "object": {
8577
- const entries = [];
8578
- const names = [];
8579
8711
  const keyList = INTRINSICS.keys(owned.properties);
8580
- for (let keyIndex = 0; keyIndex < keyList.length; keyIndex += 1) {
8581
- const key = keyList[keyIndex];
8582
- if (key === void 0) continue;
8712
+ const entries = INTRINSICS.reflect.apply(INTRINSICS.expand, readIndexView(keyList), [(key) => {
8583
8713
  const child = owned.properties[key];
8584
- if (child === void 0) continue;
8714
+ if (child === void 0) return [];
8585
8715
  const optional = child.category === "optional";
8586
8716
  const inner = optional ? child.inner : child;
8587
- entries[entries.length] = {
8717
+ return [{
8588
8718
  key,
8589
8719
  report: this.#reportAt(inner),
8590
8720
  optional,
8591
8721
  kind: shapeToKind(inner)
8592
- };
8593
- names[names.length] = key;
8594
- }
8722
+ }];
8723
+ }]);
8724
+ const names = INTRINSICS.reflect.apply(INTRINSICS.project, readIndexView(entries), [(entry) => entry.key]);
8595
8725
  const extra = owned.additionalProperties;
8596
8726
  const tail = extra === void 0 || extra === true || extra === false ? void 0 : this.#reportAt(extra);
8597
8727
  const open = extra === true || tail !== void 0;
8598
8728
  const planned = attempt(() => collectMembers(names));
8599
- const known = planned.success ? planned.value : void 0;
8729
+ const known = isSuccess(planned) ? planned.value : void 0;
8600
8730
  const maskable = entries.length <= 31;
8601
- const positions = INTRINSICS.create(null);
8602
- if (maskable) for (let entryIndex = 0; entryIndex < entries.length; entryIndex += 1) {
8603
- const entry = entries[entryIndex];
8604
- if (entry === void 0) continue;
8605
- positions[entry.key] = entryIndex;
8606
- }
8731
+ const positions = buildPositions(maskable ? INTRINSICS.reflect.apply(INTRINSICS.project, readIndexView(entries), [(entry) => entry.key]) : []);
8607
8732
  return (value, path) => {
8608
8733
  if (!isRecord(value)) return [{
8609
8734
  reason: "type",
@@ -8620,18 +8745,11 @@ var ContractCompiler = class ContractCompiler {
8620
8745
  received: preview(value)
8621
8746
  }];
8622
8747
  const faults = [];
8623
- if (!attempt(() => {
8748
+ if (isFailure(attempt(() => {
8624
8749
  const present = maskable ? void 0 : collectMembers(keys);
8625
8750
  const vocabulary = known ?? collectMembers(names);
8626
- let seen = 0;
8627
- if (present === void 0) for (let keyIndex = 0; keyIndex < keys.length; keyIndex += 1) {
8628
- const key = keys[keyIndex];
8629
- if (key === void 0) continue;
8630
- if (!INTRINSICS.own(positions, key)) continue;
8631
- const position = positions[key];
8632
- if (position !== void 0) seen |= 1 << position;
8633
- }
8634
- for (let entryIndex = 0; entryIndex < entries.length; entryIndex += 1) {
8751
+ const seen = present === void 0 ? readPresence(keys, positions) : 0;
8752
+ for (const entryIndex of iterateIndices(() => entries.length)) {
8635
8753
  const entry = entries[entryIndex];
8636
8754
  if (entry === void 0) continue;
8637
8755
  if (faults.length >= 64) return;
@@ -8654,7 +8772,7 @@ var ContractCompiler = class ContractCompiler {
8654
8772
  }
8655
8773
  appendEntries(faults, entry.report(raw, pathOf(path, entry.key)));
8656
8774
  }
8657
- if (open) for (let keyIndex = 0; keyIndex < keys.length; keyIndex += 1) {
8775
+ if (open) for (const keyIndex of iterateIndices(() => keys.length)) {
8658
8776
  const key = keys[keyIndex];
8659
8777
  if (key === void 0) continue;
8660
8778
  if (faults.length >= 64) return;
@@ -8662,7 +8780,7 @@ var ContractCompiler = class ContractCompiler {
8662
8780
  const observed = record[key];
8663
8781
  if (tail !== void 0) appendEntries(faults, tail(observed, pathOf(path, key)));
8664
8782
  }
8665
- }).success) return [{
8783
+ }))) return [{
8666
8784
  reason: "type",
8667
8785
  path,
8668
8786
  expected: "object",
@@ -8672,19 +8790,17 @@ var ContractCompiler = class ContractCompiler {
8672
8790
  };
8673
8791
  }
8674
8792
  case "union": {
8675
- const plans = [];
8676
- const guards = [];
8677
- for (let index2 = 0; index2 < owned.variants.length; index2 += 1) {
8678
- const variant = owned.variants[index2];
8679
- if (variant === void 0) continue;
8680
- plans[plans.length] = this.#reportAt(variant);
8681
- guards[guards.length] = this.#guardAt(variant);
8682
- }
8793
+ const variants = INTRINSICS.reflect.apply(INTRINSICS.expand, readIndexView(owned.variants), [(variant) => variant === void 0 ? [] : [{
8794
+ report: this.#reportAt(variant),
8795
+ guard: this.#guardAt(variant)
8796
+ }]]);
8797
+ const plans = INTRINSICS.reflect.apply(INTRINSICS.project, readIndexView(variants), [(variant) => variant.report]);
8798
+ const guards = INTRINSICS.reflect.apply(INTRINSICS.project, readIndexView(variants), [(variant) => variant.guard]);
8683
8799
  const exclusive = owned.mode === "oneOf";
8684
8800
  const count = owned.variants.length;
8685
8801
  return (value, path) => {
8686
8802
  const perVariant = [];
8687
- for (let index2 = 0; index2 < plans.length; index2 += 1) {
8803
+ for (const index2 of iterateIndices(() => plans.length)) {
8688
8804
  const plan = plans[index2];
8689
8805
  if (plan === void 0) continue;
8690
8806
  const variantFaults = plan(value, path);
@@ -8693,11 +8809,7 @@ var ContractCompiler = class ContractCompiler {
8693
8809
  }
8694
8810
  const closest = selectClosestFaults(perVariant);
8695
8811
  if (exclusive) {
8696
- let matched = 0;
8697
- for (let index2 = 0; index2 < guards.length; index2 += 1) {
8698
- const guard = guards[index2];
8699
- if (guard !== void 0 && guard(value)) matched += 1;
8700
- }
8812
+ const matched = INTRINSICS.reflect.apply(INTRINSICS.fold, guards, [(total, guard) => total + (guard(value) ? 1 : 0), 0]);
8701
8813
  if (matched === 1) return [];
8702
8814
  if (matched === 0) {
8703
8815
  const report = [{
@@ -8744,7 +8856,7 @@ var ContractCompiler = class ContractCompiler {
8744
8856
  if (ready !== void 0) return ready;
8745
8857
  this.#prepare();
8746
8858
  if (this.#unions()) this.#buildGuard();
8747
- for (let step = 0; step < this.#order.length; step += 1) {
8859
+ for (const step of iterateIndices(() => this.#order.length)) {
8748
8860
  const index = this.#order[step];
8749
8861
  if (index === void 0) continue;
8750
8862
  this.#seeds[index] = this.#seedOf(index);
@@ -8777,8 +8889,8 @@ var ContractCompiler = class ContractCompiler {
8777
8889
  const pattern = owned.pattern;
8778
8890
  return (random) => {
8779
8891
  const alphabet = "abcdefghijklmnopqrstuvwxyz0123456789";
8780
- let value = "";
8781
- for (let step = 0; step < length; step += 1) value += alphabet[INTRINSICS.floor(drawRandom(random, "string") * 36)];
8892
+ const characters = INTRINSICS.from(iterateIndices(() => length), () => INTRINSICS.text(alphabet[INTRINSICS.floor(drawRandom(random, "string") * 36)]));
8893
+ const value = INTRINSICS.reflect.apply(INTRINSICS.join, characters, [""]);
8782
8894
  if (pattern !== void 0 && !matchOf(pattern)(value)) {
8783
8895
  const limit = readPatternSource(pattern);
8784
8896
  throw new ContractError("compileGenerator: a pattern-constrained string shape cannot be auto-generated — supply or verify values another way", {
@@ -8817,9 +8929,8 @@ var ContractCompiler = class ContractCompiler {
8817
8929
  if (pick === 2) return INTRINSICS.floor(drawRandom(random, "json") * 1e3);
8818
8930
  if (pick === 3) {
8819
8931
  const alphabet = "abcdefghijklmnopqrstuvwxyz";
8820
- let value = "";
8821
- for (let step = 0; step < 6; step += 1) value += alphabet[INTRINSICS.floor(drawRandom(random, "json") * 26)];
8822
- return value;
8932
+ const characters = INTRINSICS.from(iterateIndices(() => 6), () => INTRINSICS.text(alphabet[INTRINSICS.floor(drawRandom(random, "json") * 26)]));
8933
+ return INTRINSICS.reflect.apply(INTRINSICS.join, characters, [""]);
8823
8934
  }
8824
8935
  return { value: INTRINSICS.floor(drawRandom(random, "json") * 1e3) };
8825
8936
  };
@@ -8842,64 +8953,42 @@ var ContractCompiler = class ContractCompiler {
8842
8953
  const hi = owned.max ?? INTRINSICS.max(lo, 3);
8843
8954
  return (random) => {
8844
8955
  const length = INTRINSICS.floor(drawRandom(random, "array") * (hi - lo + 1)) + lo;
8845
- const result = [];
8846
- for (let step = 0; step < length; step += 1) result[result.length] = item(random);
8847
- return result;
8956
+ return INTRINSICS.from(iterateIndices(() => length), () => item(random));
8848
8957
  };
8849
8958
  }
8850
8959
  case "object": {
8851
- const entries = [];
8852
8960
  const keyList = INTRINSICS.keys(owned.properties);
8853
- for (let keyIndex = 0; keyIndex < keyList.length; keyIndex += 1) {
8854
- const key = keyList[keyIndex];
8855
- if (key === void 0) continue;
8961
+ const entries = INTRINSICS.reflect.apply(INTRINSICS.expand, readIndexView(keyList), [(key) => {
8856
8962
  const child = owned.properties[key];
8857
- if (child === void 0) continue;
8963
+ if (child === void 0) return [];
8858
8964
  const optional = child.category === "optional";
8859
- entries[entries.length] = {
8965
+ const inner = optional ? child.inner : child;
8966
+ return [{
8860
8967
  key,
8861
- seed: this.#seedAt(optional ? child.inner : child),
8968
+ seed: this.#seedAt(inner),
8862
8969
  optional
8863
- };
8864
- }
8970
+ }];
8971
+ }]);
8865
8972
  const extra = owned.additionalProperties;
8866
8973
  const tail = extra === void 0 || extra === true || extra === false ? void 0 : this.#seedAt(extra);
8867
8974
  return (random) => {
8868
- const result = {};
8869
- for (let entryIndex = 0; entryIndex < entries.length; entryIndex += 1) {
8870
- const entry = entries[entryIndex];
8871
- if (entry === void 0) continue;
8872
- if (entry.optional && drawRandom(random, "object") < .3) continue;
8873
- INTRINSICS.define(result, entry.key, {
8874
- value: entry.seed(random),
8875
- enumerable: true,
8876
- configurable: true,
8877
- writable: true
8878
- });
8879
- }
8880
- if (tail !== void 0) {
8881
- const count = 1 + INTRINSICS.floor(drawRandom(random, "object") * 2);
8882
- for (let step = 0; step < count; step += 1) {
8883
- const key = `key${step}`;
8884
- if (INTRINSICS.own(result, key)) continue;
8885
- INTRINSICS.define(result, key, {
8886
- value: tail(random),
8887
- enumerable: true,
8888
- configurable: true,
8889
- writable: true
8890
- });
8891
- }
8892
- }
8893
- return result;
8975
+ const pairs = INTRINSICS.reflect.apply(INTRINSICS.expand, readIndexView(entries), [(entry) => entry.optional && drawRandom(random, "object") < .3 ? [] : [[entry.key, entry.seed(random)]]]);
8976
+ const declared = INTRINSICS.record({ [Symbol.iterator]: INTRINSICS.reflect.apply(INTRINSICS.bind, INTRINSICS.iterator, [pairs]) });
8977
+ const count = tail === void 0 ? 0 : 1 + INTRINSICS.floor(drawRandom(random, "object") * 2);
8978
+ const extras = INTRINSICS.from(iterateIndices(() => count), (step) => {
8979
+ const key = `key${step}`;
8980
+ return INTRINSICS.own(declared, key) || tail === void 0 ? void 0 : [key, tail(random)];
8981
+ });
8982
+ const selected = INTRINSICS.reflect.apply(INTRINSICS.select, readIndexView(extras), [(entry) => entry !== void 0]);
8983
+ const additional = INTRINSICS.record({ [Symbol.iterator]: INTRINSICS.reflect.apply(INTRINSICS.bind, INTRINSICS.iterator, [selected]) });
8984
+ return {
8985
+ ...declared,
8986
+ ...additional
8987
+ };
8894
8988
  };
8895
8989
  }
8896
8990
  case "union": {
8897
- const plans = [];
8898
- for (let index2 = 0; index2 < owned.variants.length; index2 += 1) {
8899
- const variant = owned.variants[index2];
8900
- if (variant === void 0) continue;
8901
- plans[plans.length] = this.#seedAt(variant);
8902
- }
8991
+ const plans = INTRINSICS.reflect.apply(INTRINSICS.expand, readIndexView(owned.variants), [(variant) => variant === void 0 ? [] : [this.#seedAt(variant)]]);
8903
8992
  const count = owned.variants.length;
8904
8993
  const guard = count === 0 ? void 0 : this.#guardAt(owned);
8905
8994
  const attempts = INTRINSICS.max(32, count);
@@ -8912,12 +9001,12 @@ var ContractCompiler = class ContractCompiler {
8912
9001
  }
8913
9002
  });
8914
9003
  const start = INTRINSICS.floor(drawRandom(random, "union") * count);
8915
- for (let attemptIndex = 0; attemptIndex < attempts; attemptIndex += 1) {
9004
+ for (const attemptIndex of iterateIndices(() => attempts)) {
8916
9005
  const plan = plans[(start + attemptIndex) % count];
8917
9006
  if (plan === void 0) continue;
8918
9007
  const outcome = attempt(() => plan(random));
8919
- if (!outcome.success && isContractError(outcome.error) && outcome.error.code === "random") throw outcome.error;
8920
- if (outcome.success && guard(outcome.value)) return outcome.value;
9008
+ if (isFailure(outcome) && isContractError(outcome.error) && outcome.error.code === "random") throw outcome.error;
9009
+ if (isSuccess(outcome) && guard(outcome.value)) return outcome.value;
8921
9010
  }
8922
9011
  throw new ContractError("compileGenerator: no union candidate satisfied the compiled guard", {
8923
9012
  code: "generate",
@@ -8968,8 +9057,7 @@ var ContractCompiler = class ContractCompiler {
8968
9057
  pinMembers(ContractCompiler.prototype, "ContractCompiler");
8969
9058
  }
8970
9059
  };
8971
- //#endregion
8972
- //#region src/core/compilers.ts
9060
+ // src/core/compilers.ts
8973
9061
  /**
8974
9062
  * Gates recursive compiler work on shape structure, depth, and cycles.
8975
9063
  *
@@ -9149,13 +9237,11 @@ function compileReporter(shape, value, path = []) {
9149
9237
  function compileAuditor(shape, value, path = []) {
9150
9238
  return contain(() => new ContractCompiler(shape).auditor(value, path), "compileAuditor");
9151
9239
  }
9152
- //#endregion
9153
- //#region src/core/factories.ts
9240
+ // src/core/factories.ts
9154
9241
  function createContract(shape) {
9155
9242
  return contain(() => new ContractCompiler(shape).contract, "createContract");
9156
9243
  }
9157
- //#endregion
9158
- //#region src/core/ValueInferer.ts
9244
+ // src/core/ValueInferer.ts
9159
9245
  /**
9160
9246
  * Owns the state of one single-value inference walk.
9161
9247
  *
@@ -9234,16 +9320,14 @@ var ValueInferer = class ValueInferer {
9234
9320
  admitVisited(this.#visited, value);
9235
9321
  const outcome = attempt(() => {
9236
9322
  const snapshot = readArrayEntries(value);
9237
- if (!snapshot.success) throw snapshot.error;
9323
+ if (isFailure(snapshot)) throw snapshot.error;
9238
9324
  if (!snapshot.value.dense) return void 0;
9239
9325
  const entries = snapshot.value.entries;
9240
- const sampled = [];
9241
- const length = INTRINSICS.min(entries.length, this.#breadth);
9242
- for (let index = 0; index < length; index += 1) sampled[sampled.length] = this.#infer(entries[index], depth - 1);
9243
- return sampled;
9326
+ const length = INTRINSICS.ceil(INTRINSICS.min(entries.length, this.#breadth));
9327
+ return INTRINSICS.from(iterateIndices(() => length), (index) => this.#infer(entries[index], depth - 1));
9244
9328
  });
9245
9329
  omitVisited(this.#visited, value);
9246
- if (!outcome.success) throw outcome.error;
9330
+ if (isFailure(outcome)) throw outcome.error;
9247
9331
  const sampled = outcome.value;
9248
9332
  const schema = sampled === void 0 ? {} : sampled.length > 0 ? {
9249
9333
  type: "array",
@@ -9263,20 +9347,23 @@ var ValueInferer = class ValueInferer {
9263
9347
  const allKeys = sortValues(snapshot);
9264
9348
  const keys = limitEntries(allKeys, this.#breadth);
9265
9349
  const truncated = allKeys.length > this.#breadth;
9266
- const properties = INTRINSICS.create(null);
9267
- const required = [];
9268
- let dropped = false;
9269
- for (let index = 0; index < keys.length; index += 1) {
9350
+ const observed = INTRINSICS.from(iterateIndices(() => keys.length), (index) => {
9270
9351
  const key = keys[index];
9271
- if (key === void 0) continue;
9352
+ if (key === void 0) return {
9353
+ key,
9354
+ schema: void 0
9355
+ };
9272
9356
  const propertyValue = value[key];
9273
- if (propertyValue === void 0) {
9274
- dropped = true;
9275
- continue;
9276
- }
9277
- properties[key] = this.#infer(propertyValue, depth - 1);
9278
- required[required.length] = key;
9279
- }
9357
+ return {
9358
+ key,
9359
+ schema: propertyValue === void 0 ? void 0 : this.#infer(propertyValue, depth - 1)
9360
+ };
9361
+ });
9362
+ const selected = INTRINSICS.reflect.apply(INTRINSICS.select, readIndexView(observed), [(entry) => entry.key !== void 0 && entry.schema !== void 0]);
9363
+ const pairs = INTRINSICS.reflect.apply(INTRINSICS.project, readIndexView(selected), [(entry) => [entry.key, entry.schema]]);
9364
+ const properties = INTRINSICS.rebase(INTRINSICS.record({ [Symbol.iterator]: INTRINSICS.reflect.apply(INTRINSICS.bind, INTRINSICS.iterator, [pairs]) }), null);
9365
+ const required = INTRINSICS.reflect.apply(INTRINSICS.project, readIndexView(selected), [(entry) => entry.key]);
9366
+ const dropped = INTRINSICS.reflect.apply(INTRINSICS.some, observed, [(entry) => entry.key !== void 0 && entry.schema === void 0]);
9280
9367
  return {
9281
9368
  properties,
9282
9369
  required,
@@ -9284,7 +9371,7 @@ var ValueInferer = class ValueInferer {
9284
9371
  };
9285
9372
  });
9286
9373
  omitVisited(this.#visited, value);
9287
- if (!outcome.success) throw outcome.error;
9374
+ if (isFailure(outcome)) throw outcome.error;
9288
9375
  const { properties, required, partial } = outcome.value;
9289
9376
  const schema = {
9290
9377
  type: "object",
@@ -9296,8 +9383,7 @@ var ValueInferer = class ValueInferer {
9296
9383
  return schema;
9297
9384
  }
9298
9385
  };
9299
- //#endregion
9300
- //#region src/core/SampleInferer.ts
9386
+ // src/core/SampleInferer.ts
9301
9387
  /**
9302
9388
  * Owns the state of one multi-sample inference walk.
9303
9389
  *
@@ -9346,19 +9432,17 @@ var SampleInferer = class {
9346
9432
  }
9347
9433
  #infer(samples, depth, memo) {
9348
9434
  if (samples.length === 0) return {};
9349
- const records = [];
9350
- for (let index = 0; index < samples.length; index += 1) {
9435
+ const observed = INTRINSICS.from(iterateIndices(() => samples.length), (index) => {
9351
9436
  const sample = samples[index];
9352
- if (isRecord(sample)) records[records.length] = sample;
9353
- }
9437
+ return isRecord(sample) ? sample : void 0;
9438
+ });
9439
+ const records = INTRINSICS.reflect.apply(INTRINSICS.select, readIndexView(observed), [(sample) => sample !== void 0]);
9354
9440
  if (records.length === samples.length) return this.#walkRecords(records, depth, memo);
9355
9441
  if (this.#enumerated) {
9356
9442
  const enumSchema = inferPrimitiveEnum(samples, 12);
9357
9443
  if (enumSchema) return enumSchema;
9358
9444
  }
9359
- const schemas = [];
9360
- for (let index = 0; index < samples.length; index += 1) schemas[schemas.length] = new ValueInferer(samples[index], depth, this.#breadth, this.#closed, false).infer();
9361
- const unified = unifySchemas(schemas);
9445
+ const unified = unifySchemas(INTRINSICS.from(iterateIndices(() => samples.length), (index) => new ValueInferer(samples[index], depth, this.#breadth, this.#closed, false).infer()));
9362
9446
  if (this.#format && unified.type === "string" && INTRINSICS.keys(unified).length === 1) {
9363
9447
  const detected = samplesToFormat(samples);
9364
9448
  if (detected) return {
@@ -9370,69 +9454,63 @@ var SampleInferer = class {
9370
9454
  }
9371
9455
  #walkRecords(samples, depth, memo) {
9372
9456
  if (!(depth > 0)) return {};
9373
- let node = memo;
9374
- for (let index = 0; index < samples.length; index += 1) {
9375
- const row = samples[index];
9376
- if (row === void 0) break;
9377
- const next = INTRINSICS.reflect.apply(INTRINSICS.recall, node.rows, [row]);
9378
- if (next !== void 0) {
9379
- node = readSampleMemo(next, "samplesToSchema");
9380
- continue;
9381
- }
9457
+ const node = INTRINSICS.reflect.apply(INTRINSICS.fold, samples, [(current, row) => {
9458
+ const next = INTRINSICS.reflect.apply(INTRINSICS.recall, current.rows, [row]);
9459
+ if (next !== void 0) return readSampleMemo(next, "samplesToSchema");
9382
9460
  const fresh = buildSampleMemo();
9383
- INTRINSICS.reflect.apply(INTRINSICS.retain, node.rows, [row, fresh]);
9384
- node = fresh;
9385
- }
9461
+ INTRINSICS.reflect.apply(INTRINSICS.retain, current.rows, [row, fresh]);
9462
+ return fresh;
9463
+ }, memo]);
9386
9464
  const signature = `${depth}|${this.#breadth}|${this.#closed}|${this.#format}|${this.#enumerated}`;
9387
9465
  const cached = INTRINSICS.reflect.apply(INTRINSICS.fetch, node.schemas, [signature]);
9388
9466
  if (cached !== void 0) return cached;
9389
- const seen = collectMembers([]);
9390
- const collected = [];
9391
- for (let sampleIndex = 0; sampleIndex < samples.length; sampleIndex += 1) {
9392
- const sample = samples[sampleIndex];
9467
+ const keyPairs = INTRINSICS.reflect.apply(INTRINSICS.expand, readIndexView(samples), [(sample) => {
9393
9468
  if (sample === void 0) throw new INTRINSICS.error("samplesToSchema: every sample must be a record");
9394
9469
  const sampleKeys = enumerableKeys(sample);
9395
9470
  if (sampleKeys === void 0) throw new INTRINSICS.error("samplesToSchema: property enumeration failed");
9396
- for (let keyIndex = 0; keyIndex < sampleKeys.length; keyIndex += 1) {
9397
- const key = sampleKeys[keyIndex];
9398
- if (key === void 0 || matchesMember(seen, key)) continue;
9399
- admitMember(seen, key);
9400
- collected[collected.length] = key;
9401
- }
9402
- }
9403
- const allKeys = sortValues(collected);
9471
+ return INTRINSICS.reflect.apply(INTRINSICS.project, readIndexView(sampleKeys), [(key) => [key, true]]);
9472
+ }]);
9473
+ const keySet = INTRINSICS.record({ [Symbol.iterator]: INTRINSICS.reflect.apply(INTRINSICS.bind, INTRINSICS.iterator, [keyPairs]) });
9474
+ const allKeys = sortValues(INTRINSICS.keys(keySet));
9404
9475
  const keys = limitEntries(allKeys, this.#breadth);
9405
9476
  const truncated = allKeys.length > this.#breadth;
9406
- const properties = INTRINSICS.create(null);
9407
- const required = [];
9408
- let partial = truncated;
9409
- for (let keyIndex = 0; keyIndex < keys.length; keyIndex += 1) {
9410
- const key = keys[keyIndex];
9411
- if (key === void 0) continue;
9477
+ const columns = INTRINSICS.from(iterateIndices(() => keys.length), (index) => {
9478
+ const key = keys[index];
9479
+ if (key === void 0) return {
9480
+ key,
9481
+ schema: void 0,
9482
+ dropped: false,
9483
+ required: false
9484
+ };
9412
9485
  const valuesOutcome = attempt(() => {
9413
- const values = [];
9414
- let dropped = false;
9415
- for (let sampleIndex = 0; sampleIndex < samples.length; sampleIndex += 1) {
9486
+ const observed = INTRINSICS.from(iterateIndices(() => samples.length), (sampleIndex) => {
9416
9487
  const sample = samples[sampleIndex];
9417
9488
  if (sample === void 0) throw new INTRINSICS.error("samplesToSchema: every sample must be a record");
9418
- const propertyValue = sample[key];
9419
- if (propertyValue === void 0) {
9420
- if (INTRINSICS.own(sample, key)) dropped = true;
9421
- continue;
9422
- }
9423
- values[values.length] = propertyValue;
9424
- }
9489
+ const value = sample[key];
9490
+ return {
9491
+ value,
9492
+ dropped: value === void 0 && INTRINSICS.own(sample, key)
9493
+ };
9494
+ });
9495
+ const present = INTRINSICS.reflect.apply(INTRINSICS.select, readIndexView(observed), [(entry) => entry.value !== void 0]);
9425
9496
  return {
9426
- values,
9427
- dropped
9497
+ values: INTRINSICS.reflect.apply(INTRINSICS.project, readIndexView(present), [(entry) => entry.value]),
9498
+ dropped: INTRINSICS.reflect.apply(INTRINSICS.some, observed, [(entry) => entry.dropped])
9428
9499
  };
9429
9500
  });
9430
- if (!valuesOutcome.success) throw valuesOutcome.error;
9501
+ if (isFailure(valuesOutcome)) throw valuesOutcome.error;
9431
9502
  const { values, dropped } = valuesOutcome.value;
9432
- if (dropped) partial = true;
9433
- if (values.length > 0) properties[key] = this.#infer(values, depth - 1, memo);
9434
- if (!dropped && values.length === samples.length) required[required.length] = key;
9435
- }
9503
+ return {
9504
+ key,
9505
+ schema: values.length > 0 ? this.#infer(values, depth - 1, memo) : void 0,
9506
+ dropped,
9507
+ required: !dropped && values.length === samples.length
9508
+ };
9509
+ });
9510
+ const pairs = INTRINSICS.reflect.apply(INTRINSICS.expand, readIndexView(columns), [(column) => column.key === void 0 || column.schema === void 0 ? [] : [[column.key, column.schema]]]);
9511
+ const properties = INTRINSICS.rebase(INTRINSICS.record({ [Symbol.iterator]: INTRINSICS.reflect.apply(INTRINSICS.bind, INTRINSICS.iterator, [pairs]) }), null);
9512
+ const required = INTRINSICS.reflect.apply(INTRINSICS.expand, readIndexView(columns), [(column) => column.required && column.key !== void 0 ? [column.key] : []]);
9513
+ const partial = truncated || INTRINSICS.reflect.apply(INTRINSICS.some, columns, [(column) => column.dropped]);
9436
9514
  const schema = {
9437
9515
  type: "object",
9438
9516
  ...INTRINSICS.keys(properties).length > 0 ? { properties } : {},
@@ -9443,8 +9521,7 @@ var SampleInferer = class {
9443
9521
  return schema;
9444
9522
  }
9445
9523
  };
9446
- //#endregion
9447
- //#region src/core/inferers.ts
9524
+ // src/core/inferers.ts
9448
9525
  /**
9449
9526
  * Unifies a list of inferred `JSONSchema` fragments into one schema.
9450
9527
  *
@@ -9484,42 +9561,33 @@ function unifySchemas(schemas) {
9484
9561
  return contain(() => {
9485
9562
  return readValue(() => {
9486
9563
  const snapshot = readArrayEntries(schemas);
9487
- if (!snapshot.success) throw snapshot.error;
9564
+ if (isFailure(snapshot)) throw snapshot.error;
9488
9565
  if (!snapshot.value.dense) throw new INTRINSICS.error("unifySchemas: schemas must be dense");
9489
9566
  const owned = snapshot.value.entries;
9490
9567
  if (owned.length === 0) return {};
9491
- const keys = [];
9492
- const collected = collectMembers([]);
9493
- const byKey = INTRINSICS.create(null);
9494
- const unkeyed = [];
9495
- for (let index = 0; index < owned.length; index += 1) {
9568
+ const keyed = INTRINSICS.from(iterateIndices(() => owned.length), (index) => {
9496
9569
  const schema = owned[index];
9497
9570
  if (schema === void 0 || !isRecord(schema)) throw new INTRINSICS.error("unifySchemas: schemas must be records");
9498
- const key = canonicalStringify(schema);
9499
- if (key === void 0) {
9500
- unkeyed[unkeyed.length] = schema;
9501
- continue;
9502
- }
9503
- if (matchesMember(collected, key)) continue;
9504
- admitMember(collected, key);
9505
- keys[keys.length] = key;
9506
- byKey[key] = schema;
9507
- }
9571
+ return {
9572
+ key: canonicalStringify(schema),
9573
+ schema
9574
+ };
9575
+ });
9576
+ const encodable = INTRINSICS.reflect.apply(INTRINSICS.select, readIndexView(keyed), [(entry) => entry.key !== void 0]);
9577
+ const pairs = INTRINSICS.reflect.apply(INTRINSICS.project, readIndexView(encodable), [(entry) => [entry.key, entry.schema]]);
9578
+ const reversed = INTRINSICS.reflect.apply(INTRINSICS.flip, pairs, []);
9579
+ const byKey = INTRINSICS.record({ [Symbol.iterator]: INTRINSICS.reflect.apply(INTRINSICS.bind, INTRINSICS.iterator, [reversed]) });
9508
9580
  const integerKey = canonicalStringify({ type: "integer" });
9509
9581
  const numberKey = canonicalStringify({ type: "number" });
9510
- const subsumed = integerKey !== void 0 && numberKey !== void 0 && matchesMember(collected, integerKey) && matchesMember(collected, numberKey) ? integerKey : void 0;
9511
- const ordered = sortValues(keys);
9512
- const members = [];
9513
- for (let index = 0; index < ordered.length; index += 1) {
9582
+ const subsumed = integerKey !== void 0 && numberKey !== void 0 && INTRINSICS.own(byKey, integerKey) && INTRINSICS.own(byKey, numberKey) ? integerKey : void 0;
9583
+ const ordered = sortValues(INTRINSICS.reflect.apply(INTRINSICS.select, readIndexView(INTRINSICS.keys(byKey)), [(key) => key !== subsumed]));
9584
+ const unkeyed = INTRINSICS.reflect.apply(INTRINSICS.select, readIndexView(keyed), [(entry) => entry.key === void 0]);
9585
+ const members = INTRINSICS.from(iterateIndices(() => ordered.length + unkeyed.length), (index) => {
9514
9586
  const key = ordered[index];
9515
- if (key === void 0 || key === subsumed) continue;
9516
- const schema = byKey[key];
9517
- if (schema === void 0) continue;
9518
- members[members.length] = schema;
9519
- }
9520
- appendEntries(members, unkeyed);
9587
+ return key === void 0 ? unkeyed[index - ordered.length]?.schema : byKey[key];
9588
+ });
9521
9589
  if (members.length <= 1) return members[0] ?? {};
9522
- return { anyOf: members };
9590
+ return { anyOf: INTRINSICS.reflect.apply(INTRINSICS.select, readIndexView(members), [(schema) => schema !== void 0]) };
9523
9591
  }, "unifySchemas", { subject: "schemas" });
9524
9592
  }, "unifySchemas");
9525
9593
  }
@@ -9551,7 +9619,7 @@ function stringToFormat(value) {
9551
9619
  if (!isString(value)) return void 0;
9552
9620
  if (value.length > 128) return void 0;
9553
9621
  const outcome = attempt(() => classifyFormat(value));
9554
- return outcome.success ? outcome.value : void 0;
9622
+ return isSuccess(outcome) ? outcome.value : void 0;
9555
9623
  }
9556
9624
  /**
9557
9625
  * Classifies a list of sample values against the {@link SchemaFormat}
@@ -9580,19 +9648,14 @@ function samplesToFormat(values) {
9580
9648
  return contain(() => {
9581
9649
  return readValue(() => {
9582
9650
  const snapshot = readArrayEntries(values);
9583
- if (!snapshot.success) throw snapshot.error;
9651
+ if (isFailure(snapshot)) throw snapshot.error;
9584
9652
  if (!snapshot.value.dense) throw new INTRINSICS.error("samplesToFormat: values must be dense");
9585
9653
  const owned = snapshot.value.entries;
9586
9654
  if (owned.length === 0) return void 0;
9587
- let first;
9588
- for (let index = 0; index < owned.length; index += 1) {
9589
- const value = owned[index];
9590
- if (!isString(value)) return void 0;
9591
- const format = stringToFormat(value);
9592
- if (format === void 0) return void 0;
9593
- if (index === 0) first = format;
9594
- else if (format !== first) return void 0;
9595
- }
9655
+ const initial = owned[0];
9656
+ const first = isString(initial) ? stringToFormat(initial) : void 0;
9657
+ if (first === void 0) return void 0;
9658
+ if (INTRINSICS.reflect.apply(INTRINSICS.some, owned, [(value, index) => index > 0 && (!isString(value) || stringToFormat(value) !== first)])) return void 0;
9596
9659
  return first;
9597
9660
  }, "samplesToFormat", { subject: "values" });
9598
9661
  }, "samplesToFormat");
@@ -9636,45 +9699,23 @@ function inferPrimitiveEnum(values, limit) {
9636
9699
  return contain(() => {
9637
9700
  return readValue(() => {
9638
9701
  const snapshot = readArrayEntries(values);
9639
- if (!snapshot.success) throw snapshot.error;
9702
+ if (isFailure(snapshot)) throw snapshot.error;
9640
9703
  if (!snapshot.value.dense) throw new INTRINSICS.error("inferPrimitiveEnum: values must be dense");
9641
9704
  const owned = snapshot.value.entries;
9642
9705
  if (owned.length < 2) return void 0;
9643
- let strings = 0;
9644
- let numbers = 0;
9645
- for (let index = 0; index < owned.length; index += 1) {
9646
- const value = owned[index];
9647
- if (isString(value)) strings += 1;
9648
- else if (isFiniteNumber(value)) numbers += 1;
9649
- }
9650
- const allString = strings === owned.length;
9651
- const allNumber = !allString && numbers === owned.length;
9706
+ const allString = !INTRINSICS.reflect.apply(INTRINSICS.some, owned, [(value) => !isString(value)]);
9707
+ const allNumber = !allString && !INTRINSICS.reflect.apply(INTRINSICS.some, owned, [(value) => !isFiniteNumber(value)]);
9652
9708
  if (!allString && !allNumber) return void 0;
9653
- const keys = [];
9654
- const collected = collectMembers([]);
9655
- const byKey = INTRINSICS.create(null);
9656
- for (let index = 0; index < owned.length; index += 1) {
9709
+ const pairs = INTRINSICS.from(iterateIndices(() => owned.length), (index) => {
9657
9710
  const value = owned[index];
9658
- if (!isString(value) && !isFiniteNumber(value)) continue;
9659
- const key = canonicalStringify(value);
9660
- if (key === void 0) return void 0;
9661
- if (!matchesMember(collected, key)) {
9662
- admitMember(collected, key);
9663
- keys[keys.length] = key;
9664
- }
9665
- byKey[key] = value;
9666
- }
9711
+ return [canonicalStringify(value), value];
9712
+ });
9713
+ if (INTRINSICS.reflect.apply(INTRINSICS.some, pairs, [(pair) => pair[0] === void 0])) return;
9714
+ const byKey = INTRINSICS.record({ [Symbol.iterator]: INTRINSICS.reflect.apply(INTRINSICS.bind, INTRINSICS.iterator, [pairs]) });
9715
+ const keys = INTRINSICS.keys(byKey);
9667
9716
  if (keys.length >= owned.length || keys.length > limit) return void 0;
9668
9717
  const ordered = sortValues(keys);
9669
- const population = [];
9670
- for (let index = 0; index < ordered.length; index += 1) {
9671
- const key = ordered[index];
9672
- if (key === void 0) continue;
9673
- const value = byKey[key];
9674
- if (value === void 0) continue;
9675
- population[population.length] = value;
9676
- }
9677
- return { enum: population };
9718
+ return { enum: INTRINSICS.reflect.apply(INTRINSICS.project, readIndexView(ordered), [(key) => byKey[key]]) };
9678
9719
  }, "inferPrimitiveEnum", { subject: "values" });
9679
9720
  }, "inferPrimitiveEnum");
9680
9721
  }
@@ -9788,15 +9829,14 @@ function samplesToSchema(samples, options) {
9788
9829
  const enumOn = optionsSnapshot?.enum ?? false;
9789
9830
  const read = readValue(() => {
9790
9831
  const snapshot = readArrayEntries(samples);
9791
- if (!snapshot.success) throw snapshot.error;
9832
+ if (isFailure(snapshot)) throw snapshot.error;
9792
9833
  return snapshot.value;
9793
9834
  }, "samplesToSchema", { subject: "samples" });
9794
9835
  if (!read.dense) throw new ContractError("samplesToSchema: samples must be a dense array", { code: "structure" });
9795
9836
  return readValue(() => new SampleInferer(read.entries, depth, properties, closed, format, enumOn).infer(), "samplesToSchema", { subject: "samples" });
9796
9837
  }, "samplesToSchema");
9797
9838
  }
9798
- //#endregion
9799
- //#region src/core/SchemaShaper.ts
9839
+ // src/core/SchemaShaper.ts
9800
9840
  /**
9801
9841
  * Owns the state of one schema-inversion walk.
9802
9842
  *
@@ -9857,69 +9897,38 @@ var SchemaShaper = class SchemaShaper {
9857
9897
  #build(schema, depth) {
9858
9898
  const description = isString(schema.description) ? schema.description : void 0;
9859
9899
  if (isArray(schema.enum)) {
9860
- const literals = [];
9861
- const seen = collectMembers([]);
9862
- for (let index = 0; index < schema.enum.length; index += 1) {
9863
- const entry = schema.enum[index];
9864
- if (isLiteralValue(entry) && (typeof entry !== "number" || isFiniteNumber(entry))) {
9865
- if (matchesMember(seen, entry)) continue;
9866
- admitMember(seen, entry);
9867
- literals[literals.length] = entry;
9868
- }
9869
- }
9900
+ const observed = INTRINSICS.from(iterateIndices(() => INTRINSICS.reflect.apply(INTRINSICS.reflect.read, void 0, [schema, "enum"]).length), (index) => INTRINSICS.reflect.apply(INTRINSICS.reflect.read, void 0, [schema, "enum"])[index]);
9901
+ const valid = INTRINSICS.reflect.apply(INTRINSICS.select, readIndexView(observed), [(entry) => isLiteralValue(entry) && (typeof entry !== "number" || isFiniteNumber(entry))]);
9902
+ const pairs = INTRINSICS.reflect.apply(INTRINSICS.project, readIndexView(valid), [(entry, index) => [`${typeof entry}:${INTRINSICS.text(entry)}`, index]]);
9903
+ const reversed = INTRINSICS.reflect.apply(INTRINSICS.flip, pairs, []);
9904
+ const first = INTRINSICS.record({ [Symbol.iterator]: INTRINSICS.reflect.apply(INTRINSICS.bind, INTRINSICS.iterator, [reversed]) });
9905
+ const literals = INTRINSICS.reflect.apply(INTRINSICS.select, readIndexView(valid), [(entry, index) => first[`${typeof entry}:${INTRINSICS.text(entry)}`] === index]);
9870
9906
  if (literals.length > 0) return literalShape(literals, description === void 0 ? void 0 : { description });
9871
9907
  }
9872
9908
  if (isArray(schema.oneOf)) {
9873
- const records = [];
9874
- for (let index = 0; index < schema.oneOf.length; index += 1) {
9875
- const entry = schema.oneOf[index];
9876
- if (isRecord(entry)) records[records.length] = entry;
9877
- }
9909
+ const observed = INTRINSICS.from(iterateIndices(() => INTRINSICS.reflect.apply(INTRINSICS.reflect.read, void 0, [schema, "oneOf"]).length), (index) => INTRINSICS.reflect.apply(INTRINSICS.reflect.read, void 0, [schema, "oneOf"])[index]);
9910
+ const records = INTRINSICS.reflect.apply(INTRINSICS.select, readIndexView(observed), [isRecord]);
9878
9911
  if (records.length > 256) return rawShape(description === void 0 ? {} : { description });
9879
- const variants = [];
9880
- for (let index = 0; index < records.length; index += 1) {
9881
- const entry = records[index];
9882
- if (entry === void 0) continue;
9883
- variants[variants.length] = this.#convert(entry, depth - 1);
9884
- }
9912
+ const variants = INTRINSICS.reflect.apply(INTRINSICS.project, readIndexView(records), [(entry) => this.#convert(entry, depth - 1)]);
9885
9913
  if (variants.length > 0) return INTRINSICS.reflect.apply(oneOfShape, void 0, variants);
9886
9914
  }
9887
9915
  if (isArray(schema.anyOf)) {
9888
- const records = [];
9889
- for (let index = 0; index < schema.anyOf.length; index += 1) {
9890
- const entry = schema.anyOf[index];
9891
- if (isRecord(entry)) records[records.length] = entry;
9892
- }
9916
+ const observed = INTRINSICS.from(iterateIndices(() => INTRINSICS.reflect.apply(INTRINSICS.reflect.read, void 0, [schema, "anyOf"]).length), (index) => INTRINSICS.reflect.apply(INTRINSICS.reflect.read, void 0, [schema, "anyOf"])[index]);
9917
+ const records = INTRINSICS.reflect.apply(INTRINSICS.select, readIndexView(observed), [isRecord]);
9893
9918
  if (records.length > 256) return rawShape(description === void 0 ? {} : { description });
9894
- const variants = [];
9895
- for (let index = 0; index < records.length; index += 1) {
9896
- const entry = records[index];
9897
- if (entry === void 0) continue;
9898
- variants[variants.length] = this.#convert(entry, depth - 1);
9899
- }
9919
+ const variants = INTRINSICS.reflect.apply(INTRINSICS.project, readIndexView(records), [(entry) => this.#convert(entry, depth - 1)]);
9900
9920
  if (variants.length > 0) return INTRINSICS.reflect.apply(unionShape, void 0, variants);
9901
9921
  }
9902
9922
  const category = schema.type;
9903
9923
  if (isArray(category)) {
9904
- const members = [];
9905
- const seen = collectMembers([]);
9906
- for (let index = 0; index < category.length; index += 1) {
9907
- const member = parseEnum(category[index], JSON_SCHEMA_TYPES);
9908
- if (member === void 0) return rawShape(description === void 0 ? {} : { description });
9909
- if (matchesMember(seen, member)) continue;
9910
- admitMember(seen, member);
9911
- members[members.length] = member;
9912
- }
9924
+ const observed = INTRINSICS.from(parseEnumValues(category, JSON_SCHEMA_TYPES));
9925
+ if (INTRINSICS.reflect.apply(INTRINSICS.some, observed, [(entry) => entry === void 0])) return rawShape(description === void 0 ? {} : { description });
9926
+ const members = INTRINSICS.reflect.apply(INTRINSICS.select, readIndexView(observed), [(member, index) => INTRINSICS.reflect.apply(INTRINSICS.find, observed, [(entry) => entry === member]) === index]);
9913
9927
  if (members.length === 0 || members.length > 256) return rawShape(description === void 0 ? {} : { description });
9914
- const variants = [];
9915
- for (let index = 0; index < members.length; index += 1) {
9916
- const member = members[index];
9917
- if (member === void 0) continue;
9918
- variants[variants.length] = this.#build({
9919
- ...schema,
9920
- type: member
9921
- }, depth);
9922
- }
9928
+ const variants = INTRINSICS.reflect.apply(INTRINSICS.project, readIndexView(members), [(member) => this.#build({
9929
+ ...schema,
9930
+ type: member
9931
+ }, depth)]);
9923
9932
  const first = variants[0];
9924
9933
  if (variants.length === 1 && first !== void 0) return first;
9925
9934
  const union = INTRINSICS.reflect.apply(unionShape, void 0, variants);
@@ -9955,25 +9964,16 @@ var SchemaShaper = class SchemaShaper {
9955
9964
  }
9956
9965
  #buildObject(schema, depth, description) {
9957
9966
  const propertiesSource = isRecord(schema.properties) ? schema.properties : void 0;
9958
- const requiredSource = collectMembers([]);
9959
- if (isArray(schema.required)) for (let index = 0; index < schema.required.length; index += 1) {
9960
- const entry = schema.required[index];
9961
- if (isString(entry)) admitMember(requiredSource, entry);
9962
- }
9963
- const properties = INTRINSICS.create(null);
9964
- let truncated = false;
9965
- if (propertiesSource) {
9966
- const allKeys = INTRINSICS.keys(propertiesSource);
9967
- truncated = allKeys.length > 256;
9968
- const keys = limitEntries(allKeys, 256);
9969
- for (let keyIndex = 0; keyIndex < keys.length; keyIndex += 1) {
9970
- const key = keys[keyIndex];
9971
- if (key === void 0) continue;
9972
- const child = propertiesSource[key];
9973
- const childShape = isRecord(child) ? this.#convert(child, depth - 1) : rawShape({});
9974
- properties[key] = matchesMember(requiredSource, key) ? childShape : optionalShape(childShape);
9975
- }
9976
- }
9967
+ const requiredSource = isArray(schema.required) ? INTRINSICS.from(iterateIndices(() => INTRINSICS.reflect.apply(INTRINSICS.reflect.read, void 0, [schema, "required"]).length), (index) => INTRINSICS.reflect.apply(INTRINSICS.reflect.read, void 0, [schema, "required"])[index]) : [];
9968
+ const allKeys = propertiesSource === void 0 ? [] : INTRINSICS.keys(propertiesSource);
9969
+ const truncated = allKeys.length > 256;
9970
+ const keys = limitEntries(allKeys, 256);
9971
+ const pairs = INTRINSICS.reflect.apply(INTRINSICS.project, readIndexView(keys), [(key) => {
9972
+ const child = propertiesSource?.[key];
9973
+ const childShape = isRecord(child) ? this.#convert(child, depth - 1) : rawShape({});
9974
+ return [key, INTRINSICS.reflect.apply(INTRINSICS.some, requiredSource, [(entry) => isString(entry) && entry === key]) ? childShape : optionalShape(childShape)];
9975
+ }]);
9976
+ const properties = INTRINSICS.rebase(INTRINSICS.record({ [Symbol.iterator]: INTRINSICS.reflect.apply(INTRINSICS.bind, INTRINSICS.iterator, [pairs]) }), null);
9977
9977
  const extra = schema.additionalProperties;
9978
9978
  const additionalProperties = truncated ? true : extra === false ? false : isRecord(extra) ? this.#convert(extra, depth - 1) : true;
9979
9979
  return INTRINSICS.freeze({
@@ -9984,8 +9984,7 @@ var SchemaShaper = class SchemaShaper {
9984
9984
  });
9985
9985
  }
9986
9986
  };
9987
- //#endregion
9988
- //#region src/core/shapers.ts
9987
+ // src/core/shapers.ts
9989
9988
  /**
9990
9989
  * Builds a string {@link StringShape}.
9991
9990
  *
@@ -10191,17 +10190,17 @@ function literalShape(values, options) {
10191
10190
  return contain(() => {
10192
10191
  const input = values;
10193
10192
  const array = attempt(() => INTRINSICS.array(input));
10194
- if (!array.success || !array.value) throw new ContractError("literalShape: values must be an array", {
10193
+ if (isFailure(array) || !array.value) throw new ContractError("literalShape: values must be an array", {
10195
10194
  code: "structure",
10196
10195
  context: {
10197
10196
  path: ["values"],
10198
10197
  shape: "literal"
10199
10198
  },
10200
- ...!array.success ? { cause: array.error } : {}
10199
+ ...isFailure(array) ? { cause: array.error } : {}
10201
10200
  });
10202
10201
  const safe = readOptions(options, ["description"], "literalShape", "literal");
10203
10202
  const snapshot = readArrayEntries(values);
10204
- if (!snapshot.success) throw new ContractError("literalShape: values could not be copied", {
10203
+ if (isFailure(snapshot)) throw new ContractError("literalShape: values could not be copied", {
10205
10204
  code: "structure",
10206
10205
  context: {
10207
10206
  path: ["values"],
@@ -10216,8 +10215,7 @@ function literalShape(values, options) {
10216
10215
  shape: "literal"
10217
10216
  }
10218
10217
  });
10219
- const literals = [];
10220
- for (let index = 0; index < snapshot.value.entries.length; index += 1) {
10218
+ const literals = INTRINSICS.from(iterateIndices(() => snapshot.value.entries.length), (index) => {
10221
10219
  const value = snapshot.value.entries[index];
10222
10220
  if (!isLiteralValue(value)) throw new ContractError("validateShape: every literal value must be a string, number, or boolean", {
10223
10221
  code: "structure",
@@ -10226,8 +10224,8 @@ function literalShape(values, options) {
10226
10224
  shape: "literal"
10227
10225
  }
10228
10226
  });
10229
- literals[literals.length] = value;
10230
- }
10227
+ return value;
10228
+ });
10231
10229
  const shape = {
10232
10230
  category: "literal",
10233
10231
  values: INTRINSICS.freeze(literals),
@@ -10318,18 +10316,15 @@ function objectShape(properties, options) {
10318
10316
  const safe = readOptions(options, ["additionalProperties", "description"], "objectShape", "object");
10319
10317
  const copied = readValue(() => {
10320
10318
  const record = matchesRecordBrand(input);
10321
- const snapshot = INTRINSICS.create(null);
10322
10319
  const keyList = INTRINSICS.keys(input);
10323
- for (let keyIndex = 0; keyIndex < keyList.length; keyIndex += 1) {
10324
- const key = keyList[keyIndex];
10325
- if (key === void 0) continue;
10326
- INTRINSICS.reflect.define(snapshot, key, {
10327
- value: INTRINSICS.reflect.read(input, key),
10328
- enumerable: true,
10329
- configurable: true,
10330
- writable: true
10331
- });
10332
- }
10320
+ const entries = INTRINSICS.reflect.apply(INTRINSICS.project, readIndexView(keyList), [(key) => [key, {
10321
+ value: INTRINSICS.reflect.read(input, key),
10322
+ enumerable: true,
10323
+ configurable: true,
10324
+ writable: true
10325
+ }]]);
10326
+ const descriptors = INTRINSICS.record({ [Symbol.iterator]: INTRINSICS.reflect.apply(INTRINSICS.bind, INTRINSICS.iterator, [entries]) });
10327
+ const snapshot = INTRINSICS.create(null, descriptors);
10333
10328
  return {
10334
10329
  record,
10335
10330
  snapshot: INTRINSICS.freeze(snapshot)
@@ -10664,7 +10659,6 @@ function schemaToShape(schema) {
10664
10659
  });
10665
10660
  }, "schemaToShape");
10666
10661
  }
10667
- //#endregion
10668
- export { CLONE_NODE_LIMIT, COMPILE_DEPTH_LIMIT, COMPILE_NODE_LIMIT, CONTRACT_CODES, CONTRACT_ERROR_BRAND, ContractCompiler, ContractError, FAULT_LIMIT, FORMAT_MAX_LENGTH, FORMAT_PATTERNS, GENERATION_ATTEMPT_LIMIT, GUARD_DEPTH_LIMIT, INFER_BREADTH_LIMIT, INFER_DEPTH_LIMIT, INFER_ENUM_LIMIT, INTRINSICS, JSONCloner, JSON_SCHEMA_TYPES, PRESENCE_MASK_LIMIT, PREVIEW_LIMIT, SchemaCloner, ShapeCloner, ShapeValidator, admitMember, admitVisited, andOf, appendEntries, arrayOf, arrayShape, attempt, booleanShape, boundsOf, buildArrayFaults, buildNumberFaults, buildSampleMemo, buildStringFaults, canonicalStringify, classifyFormat, cloneJSONRecord, cloneJSONValue, cloneSchema, cloneShape, collectEntries, collectMembers, compareValues, compileAuditor, compileGenerator, compileGuard, compileParser, compileReporter, compileSchema, complementOf, contain, createContract, deriveLengthBounds, deriveRangeBounds, drawRandom, encodeLeaf, enumOf, enumerableKeys, enumerableSymbolCount, holds, inferPrimitiveEnum, instanceOf, integerShape, intersectionOf, isArray, isArrayBuffer, isArrayBufferView, isAsyncFunction, isAsyncGeneratorFunction, isAsyncIterable, isBigInt, isBigInt64Array, isBigUint64Array, isBoolean, isBoundedJSONRecord, isBoundedJSONValue, isConstructor, isContractError, isDataView, isDate, isDefined, isEmptyArray, isEmptyMap, isEmptyObject, isEmptySet, isEmptyString, isError, isFalse, isFiniteNumber, isFloat32Array, isFloat64Array, isFunction, isGeneratorFunction, isInstance, isInt16Array, isInt32Array, isInt8Array, isInteger, isIterable, isJSONPrimitive, isJSONValue, isLiteralValue, isMap, isNonEmptyArray, isNonEmptyMap, isNonEmptyObject, isNonEmptySet, isNonEmptyString, isNonNegativeInteger, isNonNegativeNumber, isNull, isNullableBoolean, isNullableNumber, isNullableString, isNumber, isObject, isPromise, isPromiseLike, isRecord, isRegExp, isSet, isSharedArrayBuffer, isString, isSymbol, isTrue, isUint16Array, isUint32Array, isUint8Array, isUint8ClampedArray, isUndefined, isWeakMap, isWeakSet, isZeroArg, isZeroArgAsync, isZeroArgAsyncGenerator, isZeroArgGenerator, jsonShape, keyOf, lazyOf, limitEntries, literalOf, literalShape, mapOf, matchOf, matchesISOInstant, matchesJSONDepth, matchesJSONValue, matchesMember, matchesPattern, matchesRecordBrand, matchesVisited, notOf, nullShape, nullableOf, nullableShape, numberShape, objectOf, objectShape, omitOf, omitVisited, oneOfShape, optionalOf, optionalShape, orOf, ownPattern, ownShape, parseArray, parseArrayField, parseBoolean, parseBooleanField, parseEnum, parseEnumField, parseInteger, parseIntegerField, parseJSON, parseJSONAs, parseJSONValue, parseJSONValueField, parseNull, parseNullField, parseNumber, parseNumberField, parseRecord, parseRecordField, parseString, parseStringField, pathOf, pickOf, pinMembers, preview, rawShape, readArrayEntries, readGuardShape, readMapEntries, readOptions, readPattern, readPatternFlags, readPatternSource, readSampleMemo, readSetEntries, readValue, recordOf, recordShape, refuseExpansion, resolveField, retainDepth, samplesToFormat, samplesToSchema, sanitizeBudget, sanitizeDepth, schemaToObject, schemaToParameters, schemaToShape, seededRandom, selectClosestFaults, setOf, shapeToKind, sortValues, stringOf, stringShape, stringToFormat, transformOf, tupleOf, unifySchemas, unionOf, unionShape, validateShape, valueToSchema, whereOf };
10662
+ export { CHOICE_LIMIT, CLONE_NODE_LIMIT, COMPILE_DEPTH_LIMIT, COMPILE_NODE_LIMIT, CONTRACT_CODES, CONTRACT_ERROR_BRAND, ContractCompiler, ContractError, FAULT_LIMIT, FORMAT_MAX_LENGTH, FORMAT_PATTERNS, GENERATION_ATTEMPT_LIMIT, GUARD_DEPTH_LIMIT, INFER_BREADTH_LIMIT, INFER_DEPTH_LIMIT, INFER_ENUM_LIMIT, INTRINSICS, JSONCloner, JSON_SCHEMA_TYPES, NAME_LIMIT, NODE_LIMIT, PRESENCE_MASK_LIMIT, PREVIEW_LIMIT, STRING_LIMIT, SchemaCloner, ShapeCloner, ShapeValidator, TEXT_LIMIT, admitMember, admitVisited, andOf, appendEntries, arrayOf, arrayShape, attempt, booleanShape, boundsOf, buildArrayFaults, buildNumberFaults, buildPositions, buildSampleMemo, buildStringFaults, canonicalStringify, classifyFormat, cloneJSONRecord, cloneJSONValue, cloneSchema, cloneShape, collectEntries, collectMembers, comparePrimitives, compileAuditor, compileGenerator, compileGuard, compileParser, compileReporter, compileSchema, complementOf, contain, createContract, deriveLengthBounds, deriveRangeBounds, drawRandom, encodeLeaf, encodeParts, enumOf, enumerableKeys, enumerableSymbolCount, errorToMessage, escapeRegExp, failure, holds, inferPrimitiveEnum, instanceOf, integerShape, intersectionOf, isArray, isArrayBuffer, isArrayBufferView, isAsyncFunction, isAsyncGeneratorFunction, isAsyncIterable, isBigInt, isBigInt64Array, isBigUint64Array, isBoolean, isBoundedJSONRecord, isBoundedJSONValue, isConstructor, isContractError, isDataView, isDate, isDefined, isEmptyArray, isEmptyMap, isEmptyObject, isEmptySet, isEmptyString, isError, isFailure, isFalse, isFiniteNumber, isFloat32Array, isFloat64Array, isFunction, isGeneratorFunction, isInstance, isInt16Array, isInt32Array, isInt8Array, isInteger, isIterable, isJSONPrimitive, isJSONValue, isLiteralValue, isMap, isNonEmptyArray, isNonEmptyMap, isNonEmptyObject, isNonEmptySet, isNonEmptyString, isNonNegativeInteger, isNonNegativeNumber, isNull, isNullableBoolean, isNullableNumber, isNullableString, isNumber, isObject, isPromise, isPromiseLike, isRecord, isRegExp, isSet, isSharedArrayBuffer, isString, isSuccess, isSymbol, isTrue, isUint16Array, isUint32Array, isUint8Array, isUint8ClampedArray, isUndefined, isWeakMap, isWeakSet, isZeroArg, isZeroArgAsync, isZeroArgAsyncGenerator, isZeroArgGenerator, iterateIndices, jsonShape, keyOf, lazyOf, limitEntries, literalOf, literalShape, mapOf, matchOf, matchesISOInstant, matchesJSONDepth, matchesJSONValue, matchesMember, matchesPattern, matchesRecordBrand, matchesVisited, notOf, nullShape, nullableOf, nullableShape, numberShape, objectOf, objectShape, omitOf, omitVisited, oneOfShape, optionalOf, optionalShape, orOf, ownPattern, ownShape, parseArray, parseArrayField, parseBoolean, parseBooleanField, parseEnum, parseEnumField, parseEnumValues, parseInteger, parseIntegerField, parseJSON, parseJSONAs, parseJSONValue, parseJSONValueField, parseNull, parseNullField, parseNumber, parseNumberField, parseRecord, parseRecordField, parseString, parseStringField, pathOf, pickOf, pinMembers, preview, previewParts, rawShape, readArrayEntries, readGuardShape, readIndexView, readMapEntries, readOptions, readPattern, readPatternFlags, readPatternSource, readPresence, readSampleMemo, readSetEntries, readValue, recordOf, recordShape, refuseExpansion, resolveField, retainDepth, samplesToFormat, samplesToSchema, sanitizeBudget, sanitizeDepth, schemaToObject, schemaToParameters, schemaToShape, seededRandom, selectClosestFaults, setOf, shapeToKind, sortValues, stringOf, stringShape, stringToFormat, success, transformOf, tupleOf, unifySchemas, unionOf, unionShape, validateShape, valueToSchema, whereOf };
10669
10663
 
10670
10664
  //# sourceMappingURL=index.js.map