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