@orkestrel/contract 0.0.20 → 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 +315 -136
- package/dist/src/core/index.cjs.map +1 -1
- package/dist/src/core/index.d.cts +172 -5
- package/dist/src/core/index.d.ts +172 -5
- package/dist/src/core/index.js +304 -136
- package/dist/src/core/index.js.map +1 -1
- package/package.json +6 -6
package/dist/src/core/index.js
CHANGED
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
* own. The registry makes the key discoverable; it is a recognition mechanism,
|
|
10
10
|
* not an unforgeable provenance marker.
|
|
11
11
|
*/
|
|
12
|
-
var CONTRACT_ERROR_BRAND = Symbol.for("@orkestrel/contract.
|
|
12
|
+
var CONTRACT_ERROR_BRAND = Symbol.for("@orkestrel/contract.ContractError");
|
|
13
13
|
/**
|
|
14
14
|
* Captures every host operation this package dispatches through, while this
|
|
15
15
|
* module evaluates.
|
|
@@ -547,6 +547,71 @@ var FORMAT_PATTERNS = Object.freeze({
|
|
|
547
547
|
email: /^[^\s@]+@[^\s@]+\.[^\s@]+$/,
|
|
548
548
|
uri: /^[a-z][a-z0-9+.-]*:\/\//i
|
|
549
549
|
});
|
|
550
|
+
/**
|
|
551
|
+
* Caps at `1024` the number of choices one schema field may offer, frozen.
|
|
552
|
+
*
|
|
553
|
+
* @remarks
|
|
554
|
+
* A retention limit that a declaring package, such as a form or table schema
|
|
555
|
+
* package, enforces; this package enforces none of the retention limits itself.
|
|
556
|
+
*
|
|
557
|
+
* @example
|
|
558
|
+
* ```ts
|
|
559
|
+
* CHOICE_LIMIT // 1024
|
|
560
|
+
* ```
|
|
561
|
+
*/
|
|
562
|
+
var CHOICE_LIMIT = 1024;
|
|
563
|
+
/**
|
|
564
|
+
* Caps at `128` the length, in UTF-16 code units, of one name a schema declares, frozen:
|
|
565
|
+
* a schema, group, or field name, or a column key.
|
|
566
|
+
*
|
|
567
|
+
* @remarks
|
|
568
|
+
* A retention limit that a declaring package enforces, as {@link CHOICE_LIMIT} states.
|
|
569
|
+
*
|
|
570
|
+
* @example
|
|
571
|
+
* ```ts
|
|
572
|
+
* NAME_LIMIT // 128
|
|
573
|
+
* ```
|
|
574
|
+
*/
|
|
575
|
+
var NAME_LIMIT = 128;
|
|
576
|
+
/**
|
|
577
|
+
* Caps at `65536` the length, in UTF-16 code units, of any single string one schema
|
|
578
|
+
* retains, frozen.
|
|
579
|
+
*
|
|
580
|
+
* @remarks
|
|
581
|
+
* A retention limit that a declaring package enforces, as {@link CHOICE_LIMIT} states.
|
|
582
|
+
*
|
|
583
|
+
* @example
|
|
584
|
+
* ```ts
|
|
585
|
+
* STRING_LIMIT // 65536
|
|
586
|
+
* ```
|
|
587
|
+
*/
|
|
588
|
+
var STRING_LIMIT = 65536;
|
|
589
|
+
/**
|
|
590
|
+
* Caps at `1048576` the total length, in UTF-16 code units, of every string one schema
|
|
591
|
+
* retains, frozen.
|
|
592
|
+
*
|
|
593
|
+
* @remarks
|
|
594
|
+
* A retention limit that a declaring package enforces, as {@link CHOICE_LIMIT} states.
|
|
595
|
+
*
|
|
596
|
+
* @example
|
|
597
|
+
* ```ts
|
|
598
|
+
* TEXT_LIMIT // 1048576
|
|
599
|
+
* ```
|
|
600
|
+
*/
|
|
601
|
+
var TEXT_LIMIT = 1048576;
|
|
602
|
+
/**
|
|
603
|
+
* Caps at `16384` the total number of records, arrays, and leaves one schema retains,
|
|
604
|
+
* frozen.
|
|
605
|
+
*
|
|
606
|
+
* @remarks
|
|
607
|
+
* A retention limit that a declaring package enforces, as {@link CHOICE_LIMIT} states.
|
|
608
|
+
*
|
|
609
|
+
* @example
|
|
610
|
+
* ```ts
|
|
611
|
+
* NODE_LIMIT // 16384
|
|
612
|
+
* ```
|
|
613
|
+
*/
|
|
614
|
+
var NODE_LIMIT = 16384;
|
|
550
615
|
// src/core/errors.ts
|
|
551
616
|
/**
|
|
552
617
|
* Carries a machine-readable contract category, optional context, and an exact optional
|
|
@@ -1997,10 +2062,10 @@ function limitEntries(entries, limit) {
|
|
|
1997
2062
|
*
|
|
1998
2063
|
* @example
|
|
1999
2064
|
* ```ts
|
|
2000
|
-
*
|
|
2065
|
+
* comparePrimitives('a', 'b') // -1
|
|
2001
2066
|
* ```
|
|
2002
2067
|
*/
|
|
2003
|
-
function
|
|
2068
|
+
function comparePrimitives(left, right) {
|
|
2004
2069
|
return left < right ? -1 : left > right ? 1 : 0;
|
|
2005
2070
|
}
|
|
2006
2071
|
/**
|
|
@@ -2014,7 +2079,7 @@ function compareValues(left, right) {
|
|
|
2014
2079
|
* `valueToSchema({ b: 1, a: 2 })` publish `{"type":"object","additionalProperties":false}`
|
|
2015
2080
|
* — a successful answer with the caller's properties silently gone. The copy is
|
|
2016
2081
|
* taken first so a caller-owned array is never reordered in place, and the order
|
|
2017
|
-
* is decided by {@link
|
|
2082
|
+
* is decided by {@link comparePrimitives}, whose `<` / `>` comparison dispatches
|
|
2018
2083
|
* through nothing.
|
|
2019
2084
|
*
|
|
2020
2085
|
* @param values - The keys or indices to order
|
|
@@ -2028,7 +2093,7 @@ function compareValues(left, right) {
|
|
|
2028
2093
|
function sortValues(values) {
|
|
2029
2094
|
const observed = INTRINSICS.from(iterateIndices(() => values.length), (index) => values[index]);
|
|
2030
2095
|
const owned = INTRINSICS.reflect.apply(INTRINSICS.select, readIndexView(observed), [(value) => value !== void 0]);
|
|
2031
|
-
INTRINSICS.reflect.apply(INTRINSICS.order, owned, [
|
|
2096
|
+
INTRINSICS.reflect.apply(INTRINSICS.order, owned, [comparePrimitives]);
|
|
2032
2097
|
return owned;
|
|
2033
2098
|
}
|
|
2034
2099
|
/**
|
|
@@ -2272,7 +2337,7 @@ function readSampleMemo(memo, reader) {
|
|
|
2272
2337
|
*
|
|
2273
2338
|
* @remarks
|
|
2274
2339
|
* Extracted rather than written inline for the same reason
|
|
2275
|
-
* {@link
|
|
2340
|
+
* {@link comparePrimitives} is: `Reflect.apply` takes its arguments as a LIST, so an
|
|
2276
2341
|
* inline collector is a function expression inside an array literal rather than
|
|
2277
2342
|
* one passed directly as an argument — a hidden function assignment this
|
|
2278
2343
|
* repository forbids wherever it appears. Returned directly from a factory it is
|
|
@@ -2422,6 +2487,46 @@ function matchesPattern(pattern, value) {
|
|
|
2422
2487
|
return INTRINSICS.reflect.apply(INTRINSICS.captures, pattern, [value]) !== null;
|
|
2423
2488
|
}
|
|
2424
2489
|
/**
|
|
2490
|
+
* Escapes every regular-expression metacharacter in a text, so the text
|
|
2491
|
+
* matches literally inside a larger `RegExp` source.
|
|
2492
|
+
*
|
|
2493
|
+
* @remarks
|
|
2494
|
+
* Prefixes each of `\ ^ $ . * + ? ( ) [ ] { } |` with a backslash and leaves
|
|
2495
|
+
* every other character, `-` and `/` included, unchanged; the empty string
|
|
2496
|
+
* returns unchanged. The escape is an INDEXED character map rather than
|
|
2497
|
+
* `String.prototype.replace`, which dispatches through the caller-writable
|
|
2498
|
+
* `RegExp.prototype[Symbol.replace]` and `exec` members.
|
|
2499
|
+
*
|
|
2500
|
+
* @param value - The literal text to escape
|
|
2501
|
+
* @returns The text with every metacharacter backslash-escaped
|
|
2502
|
+
*
|
|
2503
|
+
* @example
|
|
2504
|
+
* ```ts
|
|
2505
|
+
* escapeRegExp('a.b*c') // 'a\\.b\\*c'
|
|
2506
|
+
* new RegExp(`^${escapeRegExp('a.b')}$`).test('axb') // false
|
|
2507
|
+
* ```
|
|
2508
|
+
*/
|
|
2509
|
+
function escapeRegExp(value) {
|
|
2510
|
+
const metacharacters = collectMembers([
|
|
2511
|
+
"\\",
|
|
2512
|
+
"^",
|
|
2513
|
+
"$",
|
|
2514
|
+
".",
|
|
2515
|
+
"*",
|
|
2516
|
+
"+",
|
|
2517
|
+
"?",
|
|
2518
|
+
"(",
|
|
2519
|
+
")",
|
|
2520
|
+
"[",
|
|
2521
|
+
"]",
|
|
2522
|
+
"{",
|
|
2523
|
+
"}",
|
|
2524
|
+
"|"
|
|
2525
|
+
]);
|
|
2526
|
+
const characters = INTRINSICS.from(iterateIndices(() => value.length), (index) => matchesMember(metacharacters, value[index]) ? `\\${value[index]}` : value[index]);
|
|
2527
|
+
return INTRINSICS.reflect.apply(INTRINSICS.join, characters, [""]);
|
|
2528
|
+
}
|
|
2529
|
+
/**
|
|
2425
2530
|
* Rebuilds a caller's regular expression as a stateless pattern this package
|
|
2426
2531
|
* owns.
|
|
2427
2532
|
*
|
|
@@ -2547,6 +2652,68 @@ function pinMembers(prototype, owner) {
|
|
|
2547
2652
|
}
|
|
2548
2653
|
}
|
|
2549
2654
|
/**
|
|
2655
|
+
* Boxes a value as the {@link Success} branch of a {@link Result}.
|
|
2656
|
+
*
|
|
2657
|
+
* @param value - The value to box, retained exactly
|
|
2658
|
+
* @returns A fresh `{ success: true, value }` record
|
|
2659
|
+
*
|
|
2660
|
+
* @example
|
|
2661
|
+
* ```ts
|
|
2662
|
+
* success(42) // { success: true, value: 42 }
|
|
2663
|
+
* ```
|
|
2664
|
+
*/
|
|
2665
|
+
function success(value) {
|
|
2666
|
+
return {
|
|
2667
|
+
success: true,
|
|
2668
|
+
value
|
|
2669
|
+
};
|
|
2670
|
+
}
|
|
2671
|
+
/**
|
|
2672
|
+
* Boxes an error as the {@link Failure} branch of a {@link Result}.
|
|
2673
|
+
*
|
|
2674
|
+
* @param error - The error to box, retained exactly
|
|
2675
|
+
* @returns A fresh `{ success: false, error }` record
|
|
2676
|
+
*
|
|
2677
|
+
* @example
|
|
2678
|
+
* ```ts
|
|
2679
|
+
* failure('offline') // { success: false, error: 'offline' }
|
|
2680
|
+
* ```
|
|
2681
|
+
*/
|
|
2682
|
+
function failure(error) {
|
|
2683
|
+
return {
|
|
2684
|
+
success: false,
|
|
2685
|
+
error
|
|
2686
|
+
};
|
|
2687
|
+
}
|
|
2688
|
+
/**
|
|
2689
|
+
* Narrows a {@link Result} to its {@link Success} branch.
|
|
2690
|
+
*
|
|
2691
|
+
* @param result - The result to narrow
|
|
2692
|
+
* @returns True if the result succeeded; false otherwise
|
|
2693
|
+
*
|
|
2694
|
+
* @example
|
|
2695
|
+
* ```ts
|
|
2696
|
+
* isSuccess(success(1)) // true
|
|
2697
|
+
* ```
|
|
2698
|
+
*/
|
|
2699
|
+
function isSuccess(result) {
|
|
2700
|
+
return result.success;
|
|
2701
|
+
}
|
|
2702
|
+
/**
|
|
2703
|
+
* Narrows a {@link Result} to its {@link Failure} branch.
|
|
2704
|
+
*
|
|
2705
|
+
* @param result - The result to narrow
|
|
2706
|
+
* @returns True if the result failed; false otherwise
|
|
2707
|
+
*
|
|
2708
|
+
* @example
|
|
2709
|
+
* ```ts
|
|
2710
|
+
* isFailure(failure('offline')) // true
|
|
2711
|
+
* ```
|
|
2712
|
+
*/
|
|
2713
|
+
function isFailure(result) {
|
|
2714
|
+
return !result.success;
|
|
2715
|
+
}
|
|
2716
|
+
/**
|
|
2550
2717
|
* Invokes a callback once and synchronously captures its exact outcome as a
|
|
2551
2718
|
* {@link Result}.
|
|
2552
2719
|
*
|
|
@@ -2574,23 +2741,42 @@ function pinMembers(prototype, owner) {
|
|
|
2574
2741
|
* @example
|
|
2575
2742
|
* ```ts
|
|
2576
2743
|
* const outcome = attempt(() => predicate(value))
|
|
2577
|
-
* return outcome
|
|
2744
|
+
* return isSuccess(outcome) && outcome.value
|
|
2578
2745
|
* ```
|
|
2579
2746
|
*/
|
|
2580
2747
|
function attempt(callback) {
|
|
2581
2748
|
try {
|
|
2582
|
-
return
|
|
2583
|
-
success: true,
|
|
2584
|
-
value: callback()
|
|
2585
|
-
};
|
|
2749
|
+
return success(callback());
|
|
2586
2750
|
} catch (error) {
|
|
2587
|
-
return
|
|
2588
|
-
success: false,
|
|
2589
|
-
error
|
|
2590
|
-
};
|
|
2751
|
+
return failure(error);
|
|
2591
2752
|
}
|
|
2592
2753
|
}
|
|
2593
2754
|
/**
|
|
2755
|
+
* Renders a thrown value as a non-empty message.
|
|
2756
|
+
*
|
|
2757
|
+
* @remarks
|
|
2758
|
+
* Reads an `Error`'s `message` and converts any other value with the `String`
|
|
2759
|
+
* function {@link INTRINSICS} captured at load, so a symbol renders as
|
|
2760
|
+
* `Symbol(description)` and a caller that replaces the global `String` does not
|
|
2761
|
+
* change the result. Returns `'unknown failure'` when
|
|
2762
|
+
* that read throws, as a throwing `message` getter or `toString` method does,
|
|
2763
|
+
* when an `Error`'s `message` is not a string, and when the rendered text is
|
|
2764
|
+
* empty. Never throws.
|
|
2765
|
+
*
|
|
2766
|
+
* @param error - The caught value, of any shape
|
|
2767
|
+
* @returns The rendered message, never empty
|
|
2768
|
+
*
|
|
2769
|
+
* @example
|
|
2770
|
+
* ```ts
|
|
2771
|
+
* errorToMessage(new Error('boom')) // 'boom'
|
|
2772
|
+
* errorToMessage('') // 'unknown failure'
|
|
2773
|
+
* ```
|
|
2774
|
+
*/
|
|
2775
|
+
function errorToMessage(error) {
|
|
2776
|
+
const read = attempt(() => isError(error) ? error.message : INTRINSICS.text(error));
|
|
2777
|
+
return isSuccess(read) && isString(read.value) && read.value.length > 0 ? read.value : "unknown failure";
|
|
2778
|
+
}
|
|
2779
|
+
/**
|
|
2594
2780
|
* Reads a value through the shared containment boundary or refuses it with the
|
|
2595
2781
|
* contract module's uniform read diagnostic.
|
|
2596
2782
|
*
|
|
@@ -2634,12 +2820,12 @@ function readValue(callback, reader, options) {
|
|
|
2634
2820
|
owned
|
|
2635
2821
|
};
|
|
2636
2822
|
});
|
|
2637
|
-
if (
|
|
2823
|
+
if (isFailure(diagnostics)) throw new ContractError("readValue: options could not be read", {
|
|
2638
2824
|
code: "structure",
|
|
2639
2825
|
cause: diagnostics.error
|
|
2640
2826
|
});
|
|
2641
2827
|
const outcome = attempt(callback);
|
|
2642
|
-
if (
|
|
2828
|
+
if (isFailure(outcome)) {
|
|
2643
2829
|
const owned = diagnostics.value.owned;
|
|
2644
2830
|
const context = owned === void 0 ? void 0 : {
|
|
2645
2831
|
...owned.path === void 0 ? {} : { path: owned.path },
|
|
@@ -2701,7 +2887,7 @@ function readValue(callback, reader, options) {
|
|
|
2701
2887
|
*/
|
|
2702
2888
|
function contain(callback, door, options) {
|
|
2703
2889
|
const outcome = attempt(callback);
|
|
2704
|
-
if (outcome
|
|
2890
|
+
if (isSuccess(outcome)) return outcome.value;
|
|
2705
2891
|
if (isContractError(outcome.error)) throw outcome.error;
|
|
2706
2892
|
throw new ContractError(`${door}: a host operation this door depends on failed`, {
|
|
2707
2893
|
code: options?.code ?? "structure",
|
|
@@ -2727,7 +2913,7 @@ function contain(callback, door, options) {
|
|
|
2727
2913
|
*/
|
|
2728
2914
|
function holds(callback) {
|
|
2729
2915
|
const outcome = attempt(callback);
|
|
2730
|
-
return outcome
|
|
2916
|
+
return isSuccess(outcome) && outcome.value === true;
|
|
2731
2917
|
}
|
|
2732
2918
|
/**
|
|
2733
2919
|
* Determines whether a value carries the plain-record brand, raising a hostile
|
|
@@ -2933,7 +3119,7 @@ function readGuardShape(shape, optional, reader) {
|
|
|
2933
3119
|
if (optional === true) return collectMembers(declared.names);
|
|
2934
3120
|
if (!INTRINSICS.array(optional)) return collectMembers([]);
|
|
2935
3121
|
const entries = readArrayEntries(optional);
|
|
2936
|
-
if (
|
|
3122
|
+
if (isFailure(entries)) throw entries.error;
|
|
2937
3123
|
if (!entries.value.dense) throw new INTRINSICS.error("Optional key list must be dense");
|
|
2938
3124
|
return collectMembers(INTRINSICS.from(iterateIndices(() => entries.value.entries.length), (index) => INTRINSICS.text(entries.value.entries[index])));
|
|
2939
3125
|
}, reader, { subject: "optional" });
|
|
@@ -2964,7 +3150,7 @@ function readGuardShape(shape, optional, reader) {
|
|
|
2964
3150
|
*/
|
|
2965
3151
|
function enumerableKeys(value) {
|
|
2966
3152
|
const outcome = attempt(() => INTRINSICS.freeze(INTRINSICS.keys(value)));
|
|
2967
|
-
return outcome
|
|
3153
|
+
return isSuccess(outcome) ? outcome.value : void 0;
|
|
2968
3154
|
}
|
|
2969
3155
|
/**
|
|
2970
3156
|
* Validates and snapshots a shape-builder options record through every reflective
|
|
@@ -3061,7 +3247,7 @@ function readOptions(source, keys, builder, shape) {
|
|
|
3061
3247
|
function drawRandom(random, shape) {
|
|
3062
3248
|
return contain(() => {
|
|
3063
3249
|
const outcome = attempt(random);
|
|
3064
|
-
if (
|
|
3250
|
+
if (isFailure(outcome)) throw new ContractError("drawRandom: the random source threw", {
|
|
3065
3251
|
code: "random",
|
|
3066
3252
|
context: {
|
|
3067
3253
|
shape,
|
|
@@ -3119,7 +3305,7 @@ function resolveField(record, path) {
|
|
|
3119
3305
|
return INTRINSICS.reflect.read(current, key);
|
|
3120
3306
|
}, record]);
|
|
3121
3307
|
});
|
|
3122
|
-
return outcome
|
|
3308
|
+
return isSuccess(outcome) ? outcome.value : void 0;
|
|
3123
3309
|
}
|
|
3124
3310
|
/**
|
|
3125
3311
|
* Determines whether a readable value stays within the fixed JSON container-depth limit.
|
|
@@ -3182,7 +3368,7 @@ function matchesJSONDepth(value) {
|
|
|
3182
3368
|
};
|
|
3183
3369
|
if (array) {
|
|
3184
3370
|
const snapshot = readArrayEntries(entry);
|
|
3185
|
-
if (
|
|
3371
|
+
if (isFailure(snapshot)) return false;
|
|
3186
3372
|
const children = INTRINSICS.values(snapshot.value.entries);
|
|
3187
3373
|
for (const index of iterateIndices(() => children.length)) stack[stack.length] = {
|
|
3188
3374
|
operation: "enter",
|
|
@@ -3265,7 +3451,7 @@ function matchesJSONValue(entry, ancestors) {
|
|
|
3265
3451
|
if (matchesVisited(ancestors, node)) return false;
|
|
3266
3452
|
if (matchesVisited(proved, node)) continue;
|
|
3267
3453
|
const snapshot = readArrayEntries(node);
|
|
3268
|
-
if (
|
|
3454
|
+
if (isFailure(snapshot)) throw snapshot.error;
|
|
3269
3455
|
if (!snapshot.value.dense) return false;
|
|
3270
3456
|
admitVisited(ancestors, node);
|
|
3271
3457
|
stack[stack.length] = {
|
|
@@ -3500,7 +3686,7 @@ function canonicalStringify(value) {
|
|
|
3500
3686
|
if (matchesVisited(ancestors, container)) return void 0;
|
|
3501
3687
|
if (INTRINSICS.reflect.apply(INTRINSICS.recall, encodings, [container]) !== void 0) continue;
|
|
3502
3688
|
const snapshot = isArray(container) ? readArrayEntries(container) : void 0;
|
|
3503
|
-
if (snapshot !== void 0 &&
|
|
3689
|
+
if (snapshot !== void 0 && isFailure(snapshot)) throw snapshot.error;
|
|
3504
3690
|
if (snapshot !== void 0 && !snapshot.value.dense) return void 0;
|
|
3505
3691
|
const keys = snapshot === void 0 ? sortValues(INTRINSICS.keys(container)) : void 0;
|
|
3506
3692
|
const members = snapshot === void 0 ? INTRINSICS.from(iterateIndices(() => keys?.length ?? 0), (index) => {
|
|
@@ -3573,7 +3759,7 @@ function matchesISOInstant(value) {
|
|
|
3573
3759
|
const date = new INTRINSICS.date(value);
|
|
3574
3760
|
return !INTRINSICS.nan(INTRINSICS.reflect.apply(INTRINSICS.instant, date, []));
|
|
3575
3761
|
});
|
|
3576
|
-
return outcome
|
|
3762
|
+
return isSuccess(outcome) && outcome.value;
|
|
3577
3763
|
}
|
|
3578
3764
|
/**
|
|
3579
3765
|
* Classifies an already-bounded string against the pattern-only and
|
|
@@ -4260,25 +4446,22 @@ var JSONCloner = class JSONCloner {
|
|
|
4260
4446
|
clone() {
|
|
4261
4447
|
const terminal = this.#terminal;
|
|
4262
4448
|
if (terminal !== void 0) {
|
|
4263
|
-
if (terminal
|
|
4449
|
+
if (isSuccess(terminal)) return terminal.value;
|
|
4264
4450
|
throw terminal.error;
|
|
4265
4451
|
}
|
|
4266
4452
|
const poison = this.#poison;
|
|
4267
4453
|
if (poison !== void 0) {
|
|
4268
|
-
this.#terminal =
|
|
4269
|
-
success: false,
|
|
4270
|
-
error: poison
|
|
4271
|
-
};
|
|
4454
|
+
this.#terminal = failure(poison);
|
|
4272
4455
|
throw poison;
|
|
4273
4456
|
}
|
|
4274
4457
|
this.#poison = this.#create("JSONCloner.clone: JSON cloning may not be reentered");
|
|
4275
4458
|
const outcome = attempt(() => this.#execute());
|
|
4276
4459
|
const interruption = this.#terminal;
|
|
4277
4460
|
if (interruption !== void 0) {
|
|
4278
|
-
if (interruption
|
|
4461
|
+
if (isSuccess(interruption)) return interruption.value;
|
|
4279
4462
|
this.#fail(interruption.error);
|
|
4280
4463
|
}
|
|
4281
|
-
if (outcome
|
|
4464
|
+
if (isSuccess(outcome)) {
|
|
4282
4465
|
this.#terminal = outcome;
|
|
4283
4466
|
return outcome.value;
|
|
4284
4467
|
}
|
|
@@ -4286,10 +4469,7 @@ var JSONCloner = class JSONCloner {
|
|
|
4286
4469
|
this.#fail(error);
|
|
4287
4470
|
}
|
|
4288
4471
|
#fail(error) {
|
|
4289
|
-
this.#terminal =
|
|
4290
|
-
success: false,
|
|
4291
|
-
error
|
|
4292
|
-
};
|
|
4472
|
+
this.#terminal = failure(error);
|
|
4293
4473
|
this.#pending = JSONCloner.#emptyPending;
|
|
4294
4474
|
throw error;
|
|
4295
4475
|
}
|
|
@@ -4334,7 +4514,7 @@ var JSONCloner = class JSONCloner {
|
|
|
4334
4514
|
#captureObject(source) {
|
|
4335
4515
|
if (matchesVisited(this.#active, source)) this.#refuse("cloneJSONValue: cycle detected");
|
|
4336
4516
|
const arrayOutcome = attempt(() => INTRINSICS.array(source));
|
|
4337
|
-
if (
|
|
4517
|
+
if (isFailure(arrayOutcome)) this.#refuse("cloneJSONValue: value brand could not be inspected");
|
|
4338
4518
|
if (arrayOutcome.value) return this.#schedule(source, true);
|
|
4339
4519
|
if (isRecord(source)) return this.#schedule(source, false);
|
|
4340
4520
|
this.#refuse("cloneJSONValue: object is not a plain record");
|
|
@@ -4353,9 +4533,9 @@ var JSONCloner = class JSONCloner {
|
|
|
4353
4533
|
}
|
|
4354
4534
|
#captureArray(source) {
|
|
4355
4535
|
const keysOutcome = attempt(() => INTRINSICS.reflect.members(source));
|
|
4356
|
-
if (
|
|
4536
|
+
if (isFailure(keysOutcome)) this.#refuse("cloneJSONValue: own keys could not be inspected");
|
|
4357
4537
|
const lengthOutcome = attempt(() => INTRINSICS.reflect.describe(source, "length"));
|
|
4358
|
-
if (
|
|
4538
|
+
if (isFailure(lengthOutcome)) this.#refuse("cloneJSONValue: array length could not be inspected");
|
|
4359
4539
|
const lengthDescriptor = lengthOutcome.value;
|
|
4360
4540
|
if (lengthDescriptor === void 0 || !("value" in lengthDescriptor) || typeof lengthDescriptor.value !== "number" || !INTRINSICS.integer(lengthDescriptor.value) || lengthDescriptor.value < 0 || lengthDescriptor.value > 4294967295 || lengthDescriptor.enumerable !== false || lengthDescriptor.configurable !== false) this.#refuse("cloneJSONValue: array is not intrinsic and dense");
|
|
4361
4541
|
const owned = collectMembers(keysOutcome.value);
|
|
@@ -4365,7 +4545,7 @@ var JSONCloner = class JSONCloner {
|
|
|
4365
4545
|
const key = INTRINSICS.text(index);
|
|
4366
4546
|
if (!matchesMember(owned, key)) this.#refuse("cloneJSONValue: array own keys are not exact");
|
|
4367
4547
|
const descriptorOutcome = attempt(() => INTRINSICS.reflect.describe(source, key));
|
|
4368
|
-
if (
|
|
4548
|
+
if (isFailure(descriptorOutcome)) this.#refuse("cloneJSONValue: array index could not be inspected");
|
|
4369
4549
|
const descriptor = descriptorOutcome.value;
|
|
4370
4550
|
if (descriptor === void 0 || !("value" in descriptor) || descriptor.enumerable !== true) this.#refuse("cloneJSONValue: array index is not enumerable data");
|
|
4371
4551
|
return [key, descriptor.value];
|
|
@@ -4373,13 +4553,13 @@ var JSONCloner = class JSONCloner {
|
|
|
4373
4553
|
}
|
|
4374
4554
|
#captureRecord(source) {
|
|
4375
4555
|
const keysOutcome = attempt(() => INTRINSICS.reflect.members(source));
|
|
4376
|
-
if (
|
|
4556
|
+
if (isFailure(keysOutcome)) this.#refuse("cloneJSONValue: own keys could not be inspected");
|
|
4377
4557
|
const names = keysOutcome.value;
|
|
4378
4558
|
return INTRINSICS.from(iterateIndices(() => names.length), (index) => {
|
|
4379
4559
|
const key = names[index];
|
|
4380
4560
|
if (typeof key !== "string") this.#refuse("cloneJSONValue: record has a symbol property");
|
|
4381
4561
|
const descriptorOutcome = attempt(() => INTRINSICS.reflect.describe(source, key));
|
|
4382
|
-
if (
|
|
4562
|
+
if (isFailure(descriptorOutcome)) this.#refuse("cloneJSONValue: record property could not be inspected");
|
|
4383
4563
|
const descriptor = descriptorOutcome.value;
|
|
4384
4564
|
if (descriptor === void 0 || !("value" in descriptor) || descriptor.enumerable !== true) this.#refuse("cloneJSONValue: record property is not enumerable data");
|
|
4385
4565
|
return [key, descriptor.value];
|
|
@@ -4398,7 +4578,7 @@ var JSONCloner = class JSONCloner {
|
|
|
4398
4578
|
}
|
|
4399
4579
|
#refuse(message) {
|
|
4400
4580
|
const terminal = this.#terminal;
|
|
4401
|
-
if (terminal !== void 0 &&
|
|
4581
|
+
if (terminal !== void 0 && isFailure(terminal)) throw terminal.error;
|
|
4402
4582
|
throw this.#create(message);
|
|
4403
4583
|
}
|
|
4404
4584
|
static {
|
|
@@ -4457,7 +4637,7 @@ var SchemaCloner = class SchemaCloner {
|
|
|
4457
4637
|
const state = this.#state;
|
|
4458
4638
|
switch (state.phase) {
|
|
4459
4639
|
case "settled":
|
|
4460
|
-
if (state.result
|
|
4640
|
+
if (isSuccess(state.result)) return state.result.value;
|
|
4461
4641
|
throw state.result.error;
|
|
4462
4642
|
case "running":
|
|
4463
4643
|
case "interrupted":
|
|
@@ -4476,16 +4656,10 @@ var SchemaCloner = class SchemaCloner {
|
|
|
4476
4656
|
}
|
|
4477
4657
|
#complete(outcome) {
|
|
4478
4658
|
const state = this.#state;
|
|
4479
|
-
if (state.phase === "interrupted") return this.#settle(
|
|
4480
|
-
|
|
4481
|
-
error: state.poison
|
|
4482
|
-
});
|
|
4483
|
-
if (outcome.success) return this.#settle(outcome);
|
|
4659
|
+
if (state.phase === "interrupted") return this.#settle(failure(state.poison));
|
|
4660
|
+
if (isSuccess(outcome)) return this.#settle(outcome);
|
|
4484
4661
|
const error = this.#owns(outcome.error) ? outcome.error : this.#create("cloneSchema: failed to create an owned schema snapshot", { cause: outcome.error });
|
|
4485
|
-
return this.#settle(
|
|
4486
|
-
success: false,
|
|
4487
|
-
error
|
|
4488
|
-
});
|
|
4662
|
+
return this.#settle(failure(error));
|
|
4489
4663
|
}
|
|
4490
4664
|
#execute() {
|
|
4491
4665
|
if (INTRINSICS.array(this.#source)) this.#refuse("cloneSchema: a schema root must be a record, not an array", "structure", []);
|
|
@@ -4547,7 +4721,7 @@ var SchemaCloner = class SchemaCloner {
|
|
|
4547
4721
|
}
|
|
4548
4722
|
#read(source, key, path) {
|
|
4549
4723
|
const outcome = attempt(() => INTRINSICS.reflect.read(source, key));
|
|
4550
|
-
if (outcome
|
|
4724
|
+
if (isSuccess(outcome)) return outcome.value;
|
|
4551
4725
|
throw this.#create("cloneSchema: property access failed", {
|
|
4552
4726
|
path,
|
|
4553
4727
|
cause: outcome.error
|
|
@@ -4598,7 +4772,7 @@ var SchemaCloner = class SchemaCloner {
|
|
|
4598
4772
|
phase: "settled",
|
|
4599
4773
|
result
|
|
4600
4774
|
};
|
|
4601
|
-
if (result
|
|
4775
|
+
if (isSuccess(result)) return result.value;
|
|
4602
4776
|
throw result.error;
|
|
4603
4777
|
}
|
|
4604
4778
|
static {
|
|
@@ -4648,7 +4822,7 @@ var ShapePass = class ShapePass {
|
|
|
4648
4822
|
validate() {
|
|
4649
4823
|
const outcome = attempt(() => this.#execute());
|
|
4650
4824
|
if (this.#poison !== void 0) throw this.#poison;
|
|
4651
|
-
if (outcome
|
|
4825
|
+
if (isSuccess(outcome)) return this.#counts[0] ?? 1;
|
|
4652
4826
|
if (isContractError(outcome.error)) throw outcome.error;
|
|
4653
4827
|
throw new ContractError("validateShape: shape reflection failed", {
|
|
4654
4828
|
code: "structure",
|
|
@@ -4707,7 +4881,7 @@ var ShapePass = class ShapePass {
|
|
|
4707
4881
|
this.#category = void 0;
|
|
4708
4882
|
this.#raw = 0;
|
|
4709
4883
|
const outcome = attempt(() => this.#observe(current, frame.depth));
|
|
4710
|
-
if (
|
|
4884
|
+
if (isFailure(outcome) || !outcome.value) {
|
|
4711
4885
|
this.#structure ??= new ContractError("validateShape: every node must be a recognized shape", {
|
|
4712
4886
|
code: "structure",
|
|
4713
4887
|
context: { path: pathOf(this.#path) }
|
|
@@ -4731,23 +4905,23 @@ var ShapePass = class ShapePass {
|
|
|
4731
4905
|
if (category === "raw") {
|
|
4732
4906
|
const schema = current.schema;
|
|
4733
4907
|
const outcome = attempt(() => this.#inspect(schema));
|
|
4734
|
-
if (
|
|
4908
|
+
if (isFailure(outcome)) return this.#refuse("validateShape: every node must be a recognized shape", "schema");
|
|
4735
4909
|
if (!outcome.value) return false;
|
|
4736
4910
|
if (depth + this.#raw > 512) return this.#refuse("validateShape: raw schema exceeds the compilation depth limit", "schema");
|
|
4737
4911
|
}
|
|
4738
4912
|
if (category === "object") {
|
|
4739
4913
|
const outcome = attempt(() => this.#populate(current));
|
|
4740
|
-
if (
|
|
4914
|
+
if (isFailure(outcome)) return this.#refuse("validateShape: every node must be a recognized shape", "properties");
|
|
4741
4915
|
return outcome.value;
|
|
4742
4916
|
}
|
|
4743
4917
|
if (category === "union") {
|
|
4744
4918
|
const outcome = attempt(() => this.#populate(current));
|
|
4745
|
-
if (
|
|
4919
|
+
if (isFailure(outcome)) return this.#refuse("validateShape: every node must be a recognized shape", "variants");
|
|
4746
4920
|
return outcome.value;
|
|
4747
4921
|
}
|
|
4748
4922
|
if (category === "literal") {
|
|
4749
4923
|
const outcome = attempt(() => this.#populate(current));
|
|
4750
|
-
if (
|
|
4924
|
+
if (isFailure(outcome)) return this.#refuse("validateShape: every node must be a recognized shape", "values");
|
|
4751
4925
|
return outcome.value;
|
|
4752
4926
|
}
|
|
4753
4927
|
return this.#populate(current);
|
|
@@ -4807,7 +4981,7 @@ var ShapePass = class ShapePass {
|
|
|
4807
4981
|
}
|
|
4808
4982
|
return field === "pattern" && isRegExp(first) && isRegExp(second) && readPatternSource(first) === readPatternSource(second) && readPatternFlags(first) === readPatternFlags(second) && INTRINSICS.frozen(first) && INTRINSICS.frozen(second);
|
|
4809
4983
|
});
|
|
4810
|
-
if (
|
|
4984
|
+
if (isFailure(outcome) || !outcome.value) return this.#refuse("validateShape: every node must be a recognized shape", field);
|
|
4811
4985
|
}
|
|
4812
4986
|
return true;
|
|
4813
4987
|
}
|
|
@@ -4973,7 +5147,7 @@ var ShapePass = class ShapePass {
|
|
|
4973
5147
|
if (schema.format !== void 0 && typeof schema.format !== "string") return this.#refuse("validateShape: raw schema format must be a string", "schema");
|
|
4974
5148
|
if (schema.pattern !== void 0) {
|
|
4975
5149
|
if (typeof schema.pattern !== "string") return this.#refuse("validateShape: raw schema pattern must be a string", "schema");
|
|
4976
|
-
if (
|
|
5150
|
+
if (isFailure(attempt(() => INTRINSICS.reflect.apply(INTRINSICS.pattern, void 0, [schema.pattern])))) return this.#refuse("validateShape: raw schema pattern must be valid", "schema");
|
|
4977
5151
|
}
|
|
4978
5152
|
const lengthList = [
|
|
4979
5153
|
"minLength",
|
|
@@ -4998,7 +5172,7 @@ var ShapePass = class ShapePass {
|
|
|
4998
5172
|
if (population !== void 0) {
|
|
4999
5173
|
if (!INTRINSICS.array(population)) return this.#refuse("validateShape: raw schema enum must be a non-empty array", "schema");
|
|
5000
5174
|
const snapshot = readArrayEntries(population);
|
|
5001
|
-
if (
|
|
5175
|
+
if (isFailure(snapshot) || snapshot.value.entries.length === 0) return this.#refuse("validateShape: raw schema enum must be a non-empty array", "schema");
|
|
5002
5176
|
if (!snapshot.value.dense) return this.#refuse("validateShape: raw schema enum must be dense", "schema");
|
|
5003
5177
|
const values = collectMembers([]);
|
|
5004
5178
|
for (const valueIndex of iterateIndices(() => snapshot.value.entries.length)) {
|
|
@@ -5011,7 +5185,7 @@ var ShapePass = class ShapePass {
|
|
|
5011
5185
|
if (names !== void 0) {
|
|
5012
5186
|
if (!INTRINSICS.array(names)) return this.#refuse("validateShape: raw schema required must be an array", "schema");
|
|
5013
5187
|
const snapshot = readArrayEntries(names);
|
|
5014
|
-
if (
|
|
5188
|
+
if (isFailure(snapshot)) return this.#refuse("validateShape: raw schema required must be an array", "schema");
|
|
5015
5189
|
if (!snapshot.value.dense) return this.#refuse("validateShape: raw schema required must be dense", "schema");
|
|
5016
5190
|
const required = collectMembers([]);
|
|
5017
5191
|
for (const valueIndex of iterateIndices(() => snapshot.value.entries.length)) {
|
|
@@ -5041,7 +5215,7 @@ var ShapePass = class ShapePass {
|
|
|
5041
5215
|
if (variants === void 0) continue;
|
|
5042
5216
|
if (!INTRINSICS.array(variants)) return this.#refuse("validateShape: raw schema unions must be non-empty arrays", "schema");
|
|
5043
5217
|
const snapshot = readArrayEntries(variants);
|
|
5044
|
-
if (
|
|
5218
|
+
if (isFailure(snapshot) || snapshot.value.entries.length === 0) return this.#refuse("validateShape: raw schema unions must be non-empty arrays", "schema");
|
|
5045
5219
|
if (!snapshot.value.dense) return this.#refuse("validateShape: raw schema unions must be dense arrays", "schema");
|
|
5046
5220
|
for (const variantIndex of iterateIndices(() => snapshot.value.entries.length)) nested[nested.length] = snapshot.value.entries[variantIndex];
|
|
5047
5221
|
}
|
|
@@ -5085,7 +5259,7 @@ var ShapePass = class ShapePass {
|
|
|
5085
5259
|
const key = keys[keyIndex];
|
|
5086
5260
|
if (key === void 0) continue;
|
|
5087
5261
|
const descriptorOutcome = attempt(() => INTRINSICS.describe(properties, key));
|
|
5088
|
-
if (
|
|
5262
|
+
if (isFailure(descriptorOutcome)) return this.#refuse("validateShape: every node must be a recognized shape", "properties", key);
|
|
5089
5263
|
const descriptor = descriptorOutcome.value;
|
|
5090
5264
|
if (descriptor === void 0 || !INTRINSICS.own(descriptor, "value")) {
|
|
5091
5265
|
this.#children[this.#children.length] = {
|
|
@@ -5097,10 +5271,10 @@ var ShapePass = class ShapePass {
|
|
|
5097
5271
|
continue;
|
|
5098
5272
|
}
|
|
5099
5273
|
const childOutcome = attempt(() => current.properties[key]);
|
|
5100
|
-
if (
|
|
5274
|
+
if (isFailure(childOutcome)) return this.#refuse("validateShape: every node must be a recognized shape", "properties", key);
|
|
5101
5275
|
const child = childOutcome.value;
|
|
5102
5276
|
const stable = attempt(() => INTRINSICS.same(current.properties[key], child) && INTRINSICS.same(descriptor.value, child));
|
|
5103
|
-
if (
|
|
5277
|
+
if (isFailure(stable)) return this.#refuse("validateShape: every node must be a recognized shape", "properties", key);
|
|
5104
5278
|
if (!stable.value) {
|
|
5105
5279
|
this.#children[this.#children.length] = {
|
|
5106
5280
|
shape: void 0,
|
|
@@ -5128,7 +5302,7 @@ var ShapePass = class ShapePass {
|
|
|
5128
5302
|
case "union": {
|
|
5129
5303
|
if (!INTRINSICS.array(current.variants)) return this.#refuse("validateShape: variants must be a finite array", "variants");
|
|
5130
5304
|
const snapshot = readArrayEntries(current.variants);
|
|
5131
|
-
if (
|
|
5305
|
+
if (isFailure(snapshot)) return this.#refuse("validateShape: variants must be a finite array", "variants");
|
|
5132
5306
|
if (!snapshot.value.dense) return this.#refuse("validateShape: variants must be a dense data array", "variants");
|
|
5133
5307
|
const variants = snapshot.value.entries;
|
|
5134
5308
|
const length = variants.length;
|
|
@@ -5142,7 +5316,7 @@ var ShapePass = class ShapePass {
|
|
|
5142
5316
|
for (const index of iterateIndices(() => length)) {
|
|
5143
5317
|
const key = INTRINSICS.text(index);
|
|
5144
5318
|
const descriptorOutcome = attempt(() => INTRINSICS.describe(current.variants, key));
|
|
5145
|
-
if (
|
|
5319
|
+
if (isFailure(descriptorOutcome)) return this.#refuse("validateShape: every node must be a recognized shape", "variants", key);
|
|
5146
5320
|
const descriptor = descriptorOutcome.value;
|
|
5147
5321
|
if (descriptor === void 0 || !INTRINSICS.own(descriptor, "value")) {
|
|
5148
5322
|
this.#children[this.#children.length] = {
|
|
@@ -5155,7 +5329,7 @@ var ShapePass = class ShapePass {
|
|
|
5155
5329
|
}
|
|
5156
5330
|
const variant = variants[index];
|
|
5157
5331
|
const stable = attempt(() => INTRINSICS.same(current.variants[index], variant) && INTRINSICS.same(descriptor.value, variant));
|
|
5158
|
-
if (
|
|
5332
|
+
if (isFailure(stable)) return this.#refuse("validateShape: every node must be a recognized shape", "variants", key);
|
|
5159
5333
|
if (!stable.value) {
|
|
5160
5334
|
this.#children[this.#children.length] = {
|
|
5161
5335
|
shape: void 0,
|
|
@@ -5177,7 +5351,7 @@ var ShapePass = class ShapePass {
|
|
|
5177
5351
|
case "literal": {
|
|
5178
5352
|
if (!INTRINSICS.array(current.values)) return this.#refuse("validateShape: values must be a finite literal array", "values");
|
|
5179
5353
|
const snapshot = readArrayEntries(current.values);
|
|
5180
|
-
if (
|
|
5354
|
+
if (isFailure(snapshot)) return this.#refuse("validateShape: values must be a finite literal array", "values");
|
|
5181
5355
|
if (!snapshot.value.dense) return this.#refuse("validateShape: values must be a dense data array", "values");
|
|
5182
5356
|
const literals = snapshot.value.entries;
|
|
5183
5357
|
const length = literals.length;
|
|
@@ -5192,12 +5366,12 @@ var ShapePass = class ShapePass {
|
|
|
5192
5366
|
for (const index of iterateIndices(() => length)) {
|
|
5193
5367
|
const key = INTRINSICS.text(index);
|
|
5194
5368
|
const descriptorOutcome = attempt(() => INTRINSICS.describe(current.values, key));
|
|
5195
|
-
if (
|
|
5369
|
+
if (isFailure(descriptorOutcome)) return this.#refuse("validateShape: every node must be a recognized shape", "values", key);
|
|
5196
5370
|
const descriptor = descriptorOutcome.value;
|
|
5197
5371
|
if (descriptor === void 0 || !INTRINSICS.own(descriptor, "value")) return this.#refuse("validateShape: values must be a dense data array", "values", key);
|
|
5198
5372
|
const value = literals[index];
|
|
5199
5373
|
const stable = attempt(() => INTRINSICS.same(current.values[index], value) && INTRINSICS.same(descriptor.value, value));
|
|
5200
|
-
if (
|
|
5374
|
+
if (isFailure(stable)) return this.#refuse("validateShape: every node must be a recognized shape", "values", key);
|
|
5201
5375
|
if (!stable.value) return this.#refuse("validateShape: values must be a stable data array", "values", key);
|
|
5202
5376
|
if (!isLiteralValue(value)) return this.#refuse("validateShape: every literal value must be a string, number, or boolean", "values", key);
|
|
5203
5377
|
if (matchesMember(values, value)) return this.#refuse("validateShape: literal values must be unique", "values", key);
|
|
@@ -5563,7 +5737,7 @@ var ShapeCloner = class ShapeCloner {
|
|
|
5563
5737
|
clone() {
|
|
5564
5738
|
const state = this.#state;
|
|
5565
5739
|
if (state.phase === "settled") {
|
|
5566
|
-
if (state.result
|
|
5740
|
+
if (isSuccess(state.result)) return state.result.value;
|
|
5567
5741
|
throw state.result.error;
|
|
5568
5742
|
}
|
|
5569
5743
|
if (state.phase === "running" || state.phase === "interrupted") {
|
|
@@ -5585,20 +5759,14 @@ var ShapeCloner = class ShapeCloner {
|
|
|
5585
5759
|
}
|
|
5586
5760
|
#complete(outcome) {
|
|
5587
5761
|
const state = this.#state;
|
|
5588
|
-
if (state.phase === "interrupted") return this.#settle(
|
|
5589
|
-
|
|
5590
|
-
error: state.poison
|
|
5591
|
-
});
|
|
5592
|
-
if (outcome.success) return this.#settle(outcome);
|
|
5762
|
+
if (state.phase === "interrupted") return this.#settle(failure(state.poison));
|
|
5763
|
+
if (isSuccess(outcome)) return this.#settle(outcome);
|
|
5593
5764
|
const error = this.#owns(outcome.error) ? outcome.error : this.#create("cloneShape: failed to create an owned shape snapshot", {
|
|
5594
5765
|
code: "clone",
|
|
5595
5766
|
context: { shape: "shape" },
|
|
5596
5767
|
cause: outcome.error
|
|
5597
5768
|
});
|
|
5598
|
-
return this.#settle(
|
|
5599
|
-
success: false,
|
|
5600
|
-
error
|
|
5601
|
-
});
|
|
5769
|
+
return this.#settle(failure(error));
|
|
5602
5770
|
}
|
|
5603
5771
|
#execute() {
|
|
5604
5772
|
const paths = this.#paths;
|
|
@@ -5746,7 +5914,7 @@ var ShapeCloner = class ShapeCloner {
|
|
|
5746
5914
|
source: readPatternSource(pattern)
|
|
5747
5915
|
};
|
|
5748
5916
|
});
|
|
5749
|
-
if (typeof sourceText !== "string" || typeof flags !== "string" ||
|
|
5917
|
+
if (typeof sourceText !== "string" || typeof flags !== "string" || isFailure(repeated) || typeof repeated.value.source !== "string" || typeof repeated.value.flags !== "string" || repeated.value.source !== sourceText || repeated.value.flags !== flags) {
|
|
5750
5918
|
this.#fidelity ??= this.#create("validateShape: string pattern must be stable", {
|
|
5751
5919
|
code: "structure",
|
|
5752
5920
|
context: { path: pathOf(path, "pattern") }
|
|
@@ -5896,7 +6064,7 @@ var ShapeCloner = class ShapeCloner {
|
|
|
5896
6064
|
schema
|
|
5897
6065
|
});
|
|
5898
6066
|
const outcome = attempt(() => new SchemaCloner(schema).clone());
|
|
5899
|
-
if (
|
|
6067
|
+
if (isFailure(outcome)) {
|
|
5900
6068
|
if (isContractError(outcome.error)) admitVisited(this.#owned, outcome.error);
|
|
5901
6069
|
throw outcome.error;
|
|
5902
6070
|
}
|
|
@@ -5911,7 +6079,7 @@ var ShapeCloner = class ShapeCloner {
|
|
|
5911
6079
|
context: { path: pathOf(path, "values") }
|
|
5912
6080
|
});
|
|
5913
6081
|
const snapshot = readArrayEntries(values);
|
|
5914
|
-
if (
|
|
6082
|
+
if (isFailure(snapshot)) throw this.#create("validateShape: values must be a finite literal array", {
|
|
5915
6083
|
code: "structure",
|
|
5916
6084
|
context: { path: pathOf(path, "values") }
|
|
5917
6085
|
});
|
|
@@ -5926,11 +6094,11 @@ var ShapeCloner = class ShapeCloner {
|
|
|
5926
6094
|
const key = INTRINSICS.text(index);
|
|
5927
6095
|
const descriptor = attempt(() => INTRINSICS.describe(values, key));
|
|
5928
6096
|
const repeated = attempt(() => values[index]);
|
|
5929
|
-
if (
|
|
6097
|
+
if (isFailure(descriptor) || descriptor.value === void 0 || !INTRINSICS.own(descriptor.value, "value")) this.#fidelity ??= this.#create("validateShape: values must be a dense data array", {
|
|
5930
6098
|
code: "structure",
|
|
5931
6099
|
context: { path: pathOf(path, "values", key) }
|
|
5932
6100
|
});
|
|
5933
|
-
else if (
|
|
6101
|
+
else if (isFailure(repeated) || !INTRINSICS.same(repeated.value, value) || !INTRINSICS.same(descriptor.value.value, value)) this.#fidelity ??= this.#create("validateShape: values must be a stable data array", {
|
|
5934
6102
|
code: "structure",
|
|
5935
6103
|
context: { path: pathOf(path, "values", key) }
|
|
5936
6104
|
});
|
|
@@ -5975,7 +6143,7 @@ var ShapeCloner = class ShapeCloner {
|
|
|
5975
6143
|
context: { path: pathOf(path, "variants") }
|
|
5976
6144
|
});
|
|
5977
6145
|
const snapshot = readArrayEntries(variants);
|
|
5978
|
-
if (
|
|
6146
|
+
if (isFailure(snapshot)) throw this.#create("validateShape: variants must be a finite array", {
|
|
5979
6147
|
code: "structure",
|
|
5980
6148
|
context: { path: pathOf(path, "variants") }
|
|
5981
6149
|
});
|
|
@@ -5992,7 +6160,7 @@ var ShapeCloner = class ShapeCloner {
|
|
|
5992
6160
|
const key = INTRINSICS.text(index);
|
|
5993
6161
|
const descriptor = attempt(() => INTRINSICS.describe(variants, key));
|
|
5994
6162
|
const repeated = attempt(() => variants[index]);
|
|
5995
|
-
if (
|
|
6163
|
+
if (isFailure(descriptor) || descriptor.value === void 0 || !INTRINSICS.own(descriptor.value, "value") || isFailure(repeated) || !INTRINSICS.same(repeated.value, variant) || !INTRINSICS.same(descriptor.value.value, variant)) this.#fidelity ??= this.#create("validateShape: every structural child must be a shape", {
|
|
5996
6164
|
code: "structure",
|
|
5997
6165
|
context: { path: pathOf(path, "variants", key) }
|
|
5998
6166
|
});
|
|
@@ -6169,7 +6337,7 @@ var ShapeCloner = class ShapeCloner {
|
|
|
6169
6337
|
}
|
|
6170
6338
|
#validateShape(shape) {
|
|
6171
6339
|
const outcome = attempt(() => new ShapeValidator(shape).validate());
|
|
6172
|
-
if (outcome
|
|
6340
|
+
if (isSuccess(outcome)) return;
|
|
6173
6341
|
if (isContractError(outcome.error)) admitVisited(this.#owned, outcome.error);
|
|
6174
6342
|
throw outcome.error;
|
|
6175
6343
|
}
|
|
@@ -6199,7 +6367,7 @@ var ShapeCloner = class ShapeCloner {
|
|
|
6199
6367
|
phase: "settled",
|
|
6200
6368
|
result
|
|
6201
6369
|
};
|
|
6202
|
-
if (result
|
|
6370
|
+
if (isSuccess(result)) return result.value;
|
|
6203
6371
|
throw result.error;
|
|
6204
6372
|
}
|
|
6205
6373
|
static {
|
|
@@ -6337,11 +6505,11 @@ function ownShape(shape) {
|
|
|
6337
6505
|
return contain(() => {
|
|
6338
6506
|
const frozen = holds(() => INTRINSICS.frozen(shape));
|
|
6339
6507
|
const fidelity = attempt(() => cloneShape(shape));
|
|
6340
|
-
if (fidelity
|
|
6508
|
+
if (isSuccess(fidelity)) return fidelity.value;
|
|
6341
6509
|
if (isContractError(fidelity.error) && fidelity.error.code !== "clone") throw fidelity.error;
|
|
6342
6510
|
if (!frozen) throw fidelity.error;
|
|
6343
6511
|
const validation = attempt(() => new ShapeValidator(shape).validate());
|
|
6344
|
-
if (
|
|
6512
|
+
if (isFailure(validation) && isContractError(validation.error)) throw validation.error;
|
|
6345
6513
|
throw fidelity.error;
|
|
6346
6514
|
}, "ownShape");
|
|
6347
6515
|
}
|
|
@@ -6369,7 +6537,7 @@ function arrayOf(elementGuard) {
|
|
|
6369
6537
|
return (value) => holds(() => {
|
|
6370
6538
|
if (!isArray(value)) return false;
|
|
6371
6539
|
const entries = readArrayEntries(value);
|
|
6372
|
-
if (
|
|
6540
|
+
if (isFailure(entries) || !entries.value.dense) return false;
|
|
6373
6541
|
for (const index of iterateIndices(() => entries.value.entries.length)) if (!elementGuard(entries.value.entries[index])) return false;
|
|
6374
6542
|
return true;
|
|
6375
6543
|
});
|
|
@@ -6378,7 +6546,7 @@ function tupleOf(...guards) {
|
|
|
6378
6546
|
return (value) => holds(() => {
|
|
6379
6547
|
if (!isArray(value)) return false;
|
|
6380
6548
|
const entries = readArrayEntries(value);
|
|
6381
|
-
if (
|
|
6549
|
+
if (isFailure(entries) || !entries.value.dense) return false;
|
|
6382
6550
|
if (entries.value.entries.length !== guards.length) return false;
|
|
6383
6551
|
for (const index of iterateIndices(() => guards.length)) {
|
|
6384
6552
|
const guard = guards[index];
|
|
@@ -6398,7 +6566,7 @@ function literalOf(...literals) {
|
|
|
6398
6566
|
}
|
|
6399
6567
|
}) : false) && isArray(first) ? readValue(() => {
|
|
6400
6568
|
const entries = readArrayEntries(first);
|
|
6401
|
-
if (
|
|
6569
|
+
if (isFailure(entries)) throw entries.error;
|
|
6402
6570
|
if (!entries.value.dense) throw new INTRINSICS.error("Literal vocabulary must be dense");
|
|
6403
6571
|
return entries.value.entries;
|
|
6404
6572
|
}, "literalOf", {
|
|
@@ -6480,7 +6648,7 @@ function setOf(elementGuard) {
|
|
|
6480
6648
|
return (value) => holds(() => {
|
|
6481
6649
|
if (!isSet(value)) return false;
|
|
6482
6650
|
const entries = readSetEntries(value);
|
|
6483
|
-
if (
|
|
6651
|
+
if (isFailure(entries)) return false;
|
|
6484
6652
|
for (const index of iterateIndices(() => entries.value.length)) if (!elementGuard(entries.value[index])) return false;
|
|
6485
6653
|
return true;
|
|
6486
6654
|
});
|
|
@@ -6489,7 +6657,7 @@ function mapOf(keyGuard, valueGuard) {
|
|
|
6489
6657
|
return (value) => holds(() => {
|
|
6490
6658
|
if (!isMap(value)) return false;
|
|
6491
6659
|
const entries = readMapEntries(value);
|
|
6492
|
-
if (
|
|
6660
|
+
if (isFailure(entries)) return false;
|
|
6493
6661
|
for (const index of iterateIndices(() => entries.value.length)) {
|
|
6494
6662
|
const entry = entries.value[index];
|
|
6495
6663
|
if (entry === void 0) return false;
|
|
@@ -6589,7 +6757,7 @@ function pickOf(shape, keys) {
|
|
|
6589
6757
|
return contain(() => {
|
|
6590
6758
|
const selected = readValue(() => {
|
|
6591
6759
|
const entries = readArrayEntries(keys);
|
|
6592
|
-
if (
|
|
6760
|
+
if (isFailure(entries)) throw entries.error;
|
|
6593
6761
|
if (!entries.value.dense) throw new INTRINSICS.error("Picked key list must be dense");
|
|
6594
6762
|
return collectMembers(entries.value.entries);
|
|
6595
6763
|
}, "pickOf", { subject: "keys" });
|
|
@@ -6628,7 +6796,7 @@ function omitOf(shape, keys) {
|
|
|
6628
6796
|
return contain(() => {
|
|
6629
6797
|
const skipped = readValue(() => {
|
|
6630
6798
|
const entries = readArrayEntries(keys);
|
|
6631
|
-
if (
|
|
6799
|
+
if (isFailure(entries)) throw entries.error;
|
|
6632
6800
|
if (!entries.value.dense) throw new INTRINSICS.error("Omitted key list must be dense");
|
|
6633
6801
|
return collectMembers(entries.value.entries);
|
|
6634
6802
|
}, "omitOf", { subject: "keys" });
|
|
@@ -6936,7 +7104,7 @@ function parseNumber(value) {
|
|
|
6936
7104
|
const parsed = INTRINSICS.numeric(value);
|
|
6937
7105
|
return INTRINSICS.finite(parsed) ? parsed : void 0;
|
|
6938
7106
|
});
|
|
6939
|
-
return outcome
|
|
7107
|
+
return isSuccess(outcome) ? outcome.value : void 0;
|
|
6940
7108
|
}
|
|
6941
7109
|
/**
|
|
6942
7110
|
* Parses an unknown value to a finite integer.
|
|
@@ -7043,7 +7211,7 @@ function parseArray(value, guard) {
|
|
|
7043
7211
|
if (!isArray(value)) return void 0;
|
|
7044
7212
|
if (guard === void 0) return value;
|
|
7045
7213
|
const entries = readArrayEntries(value);
|
|
7046
|
-
if (
|
|
7214
|
+
if (isFailure(entries) || !entries.value.dense) return void 0;
|
|
7047
7215
|
if (!holds(() => INTRINSICS.reflect.apply(INTRINSICS.find, entries.value.entries, [(entry) => !guard(entry)]) === -1)) return;
|
|
7048
7216
|
return value;
|
|
7049
7217
|
}
|
|
@@ -7076,7 +7244,7 @@ function parseJSONValue(value) {
|
|
|
7076
7244
|
}
|
|
7077
7245
|
function parseEnum(value, allowed) {
|
|
7078
7246
|
const outcome = readArrayEntries(allowed);
|
|
7079
|
-
if (
|
|
7247
|
+
if (isFailure(outcome) || !outcome.value.dense) return void 0;
|
|
7080
7248
|
if (!holds(() => matchesMember(collectMembers(outcome.value.entries), value))) return void 0;
|
|
7081
7249
|
return isLiteralValue(value) ? value : void 0;
|
|
7082
7250
|
}
|
|
@@ -7284,7 +7452,7 @@ function parseJSONAs(value, guard) {
|
|
|
7284
7452
|
const parsed = parseJSON(value);
|
|
7285
7453
|
if (parsed === void 0) return void 0;
|
|
7286
7454
|
const checked = attempt(() => guard(parsed) ? parsed : void 0);
|
|
7287
|
-
return checked
|
|
7455
|
+
return isSuccess(checked) ? checked.value : void 0;
|
|
7288
7456
|
}
|
|
7289
7457
|
// src/core/EvaluationScope.ts
|
|
7290
7458
|
/** Owns compiled-node memo entries for one synchronous evaluation. */
|
|
@@ -7296,7 +7464,7 @@ var EvaluationScope = class EvaluationScope {
|
|
|
7296
7464
|
static run(plan, value, path = EvaluationScope.#path, clean = false) {
|
|
7297
7465
|
if (!isObject(value)) return plan(value, path);
|
|
7298
7466
|
const entries = readSetEntries(EvaluationScope.#active);
|
|
7299
|
-
if (
|
|
7467
|
+
if (isFailure(entries)) throw entries.error;
|
|
7300
7468
|
const active = entries.value[0];
|
|
7301
7469
|
if (active instanceof EvaluationScope) return active.#evaluate(plan, value, path, clean);
|
|
7302
7470
|
if (active !== void 0) throw new INTRINSICS.error("Evaluation scope is unavailable");
|
|
@@ -7558,7 +7726,7 @@ var ContractCompiler = class ContractCompiler {
|
|
|
7558
7726
|
#leave(outcome) {
|
|
7559
7727
|
const state = this.#state;
|
|
7560
7728
|
if (state.phase === "interrupted") return this.#fail(state.poison);
|
|
7561
|
-
if (
|
|
7729
|
+
if (isFailure(outcome)) return this.#fail(isContractError(outcome.error) ? outcome.error : new ContractError("ContractCompiler: contract compilation failed", {
|
|
7562
7730
|
code: "structure",
|
|
7563
7731
|
context: {
|
|
7564
7732
|
path: [],
|
|
@@ -7944,7 +8112,7 @@ var ContractCompiler = class ContractCompiler {
|
|
|
7944
8112
|
}
|
|
7945
8113
|
return true;
|
|
7946
8114
|
});
|
|
7947
|
-
return outcome
|
|
8115
|
+
return isSuccess(outcome) && outcome.value;
|
|
7948
8116
|
};
|
|
7949
8117
|
}
|
|
7950
8118
|
case "union": {
|
|
@@ -8032,7 +8200,7 @@ var ContractCompiler = class ContractCompiler {
|
|
|
8032
8200
|
});
|
|
8033
8201
|
if (!isArray(value)) return void 0;
|
|
8034
8202
|
const entries = readArrayEntries(value);
|
|
8035
|
-
if (
|
|
8203
|
+
if (isFailure(entries)) return readValue(() => {
|
|
8036
8204
|
throw entries.error;
|
|
8037
8205
|
}, "compileParser", {
|
|
8038
8206
|
subject: "array",
|
|
@@ -8108,7 +8276,7 @@ var ContractCompiler = class ContractCompiler {
|
|
|
8108
8276
|
}
|
|
8109
8277
|
return INTRINSICS.rebase(INTRINSICS.record({ [Symbol.iterator]: INTRINSICS.reflect.apply(INTRINSICS.bind, INTRINSICS.iterator, [selected]) }), null);
|
|
8110
8278
|
});
|
|
8111
|
-
if (outcome
|
|
8279
|
+
if (isSuccess(outcome)) return outcome.value;
|
|
8112
8280
|
if (isContractError(outcome.error)) throw outcome.error;
|
|
8113
8281
|
return readValue(() => {
|
|
8114
8282
|
throw outcome.error;
|
|
@@ -8258,7 +8426,7 @@ var ContractCompiler = class ContractCompiler {
|
|
|
8258
8426
|
received: preview(value)
|
|
8259
8427
|
}];
|
|
8260
8428
|
const entries = readArrayEntries(value);
|
|
8261
|
-
if (
|
|
8429
|
+
if (isFailure(entries)) return readValue(() => {
|
|
8262
8430
|
throw entries.error;
|
|
8263
8431
|
}, "compileAuditor", {
|
|
8264
8432
|
subject: "array",
|
|
@@ -8294,7 +8462,7 @@ var ContractCompiler = class ContractCompiler {
|
|
|
8294
8462
|
const closed = extra === void 0 || extra === false;
|
|
8295
8463
|
const additional = closed || extra === true ? void 0 : this.#auditAt(extra);
|
|
8296
8464
|
const planned = attempt(() => collectMembers(declaredKeys));
|
|
8297
|
-
const declared = planned
|
|
8465
|
+
const declared = isSuccess(planned) ? planned.value : void 0;
|
|
8298
8466
|
const maskable = entries.length <= 31;
|
|
8299
8467
|
const positions = buildPositions(maskable ? INTRINSICS.reflect.apply(INTRINSICS.project, readIndexView(entries), [(entry) => entry.key]) : []);
|
|
8300
8468
|
return (value, path) => {
|
|
@@ -8354,7 +8522,7 @@ var ContractCompiler = class ContractCompiler {
|
|
|
8354
8522
|
if (additional !== void 0) appendEntries(faults, additional(observed, pathOf(path, key)));
|
|
8355
8523
|
}
|
|
8356
8524
|
});
|
|
8357
|
-
if (
|
|
8525
|
+
if (isFailure(outcome)) {
|
|
8358
8526
|
if (isContractError(outcome.error)) throw outcome.error;
|
|
8359
8527
|
return readValue(() => {
|
|
8360
8528
|
throw outcome.error;
|
|
@@ -8524,7 +8692,7 @@ var ContractCompiler = class ContractCompiler {
|
|
|
8524
8692
|
received: preview(value)
|
|
8525
8693
|
}];
|
|
8526
8694
|
const entries = readArrayEntries(value);
|
|
8527
|
-
if (
|
|
8695
|
+
if (isFailure(entries)) return [{
|
|
8528
8696
|
reason: "type",
|
|
8529
8697
|
path,
|
|
8530
8698
|
expected: "array",
|
|
@@ -8558,7 +8726,7 @@ var ContractCompiler = class ContractCompiler {
|
|
|
8558
8726
|
const tail = extra === void 0 || extra === true || extra === false ? void 0 : this.#reportAt(extra);
|
|
8559
8727
|
const open = extra === true || tail !== void 0;
|
|
8560
8728
|
const planned = attempt(() => collectMembers(names));
|
|
8561
|
-
const known = planned
|
|
8729
|
+
const known = isSuccess(planned) ? planned.value : void 0;
|
|
8562
8730
|
const maskable = entries.length <= 31;
|
|
8563
8731
|
const positions = buildPositions(maskable ? INTRINSICS.reflect.apply(INTRINSICS.project, readIndexView(entries), [(entry) => entry.key]) : []);
|
|
8564
8732
|
return (value, path) => {
|
|
@@ -8577,7 +8745,7 @@ var ContractCompiler = class ContractCompiler {
|
|
|
8577
8745
|
received: preview(value)
|
|
8578
8746
|
}];
|
|
8579
8747
|
const faults = [];
|
|
8580
|
-
if (
|
|
8748
|
+
if (isFailure(attempt(() => {
|
|
8581
8749
|
const present = maskable ? void 0 : collectMembers(keys);
|
|
8582
8750
|
const vocabulary = known ?? collectMembers(names);
|
|
8583
8751
|
const seen = present === void 0 ? readPresence(keys, positions) : 0;
|
|
@@ -8612,7 +8780,7 @@ var ContractCompiler = class ContractCompiler {
|
|
|
8612
8780
|
const observed = record[key];
|
|
8613
8781
|
if (tail !== void 0) appendEntries(faults, tail(observed, pathOf(path, key)));
|
|
8614
8782
|
}
|
|
8615
|
-
})
|
|
8783
|
+
}))) return [{
|
|
8616
8784
|
reason: "type",
|
|
8617
8785
|
path,
|
|
8618
8786
|
expected: "object",
|
|
@@ -8837,8 +9005,8 @@ var ContractCompiler = class ContractCompiler {
|
|
|
8837
9005
|
const plan = plans[(start + attemptIndex) % count];
|
|
8838
9006
|
if (plan === void 0) continue;
|
|
8839
9007
|
const outcome = attempt(() => plan(random));
|
|
8840
|
-
if (
|
|
8841
|
-
if (outcome
|
|
9008
|
+
if (isFailure(outcome) && isContractError(outcome.error) && outcome.error.code === "random") throw outcome.error;
|
|
9009
|
+
if (isSuccess(outcome) && guard(outcome.value)) return outcome.value;
|
|
8842
9010
|
}
|
|
8843
9011
|
throw new ContractError("compileGenerator: no union candidate satisfied the compiled guard", {
|
|
8844
9012
|
code: "generate",
|
|
@@ -9152,14 +9320,14 @@ var ValueInferer = class ValueInferer {
|
|
|
9152
9320
|
admitVisited(this.#visited, value);
|
|
9153
9321
|
const outcome = attempt(() => {
|
|
9154
9322
|
const snapshot = readArrayEntries(value);
|
|
9155
|
-
if (
|
|
9323
|
+
if (isFailure(snapshot)) throw snapshot.error;
|
|
9156
9324
|
if (!snapshot.value.dense) return void 0;
|
|
9157
9325
|
const entries = snapshot.value.entries;
|
|
9158
9326
|
const length = INTRINSICS.ceil(INTRINSICS.min(entries.length, this.#breadth));
|
|
9159
9327
|
return INTRINSICS.from(iterateIndices(() => length), (index) => this.#infer(entries[index], depth - 1));
|
|
9160
9328
|
});
|
|
9161
9329
|
omitVisited(this.#visited, value);
|
|
9162
|
-
if (
|
|
9330
|
+
if (isFailure(outcome)) throw outcome.error;
|
|
9163
9331
|
const sampled = outcome.value;
|
|
9164
9332
|
const schema = sampled === void 0 ? {} : sampled.length > 0 ? {
|
|
9165
9333
|
type: "array",
|
|
@@ -9203,7 +9371,7 @@ var ValueInferer = class ValueInferer {
|
|
|
9203
9371
|
};
|
|
9204
9372
|
});
|
|
9205
9373
|
omitVisited(this.#visited, value);
|
|
9206
|
-
if (
|
|
9374
|
+
if (isFailure(outcome)) throw outcome.error;
|
|
9207
9375
|
const { properties, required, partial } = outcome.value;
|
|
9208
9376
|
const schema = {
|
|
9209
9377
|
type: "object",
|
|
@@ -9330,7 +9498,7 @@ var SampleInferer = class {
|
|
|
9330
9498
|
dropped: INTRINSICS.reflect.apply(INTRINSICS.some, observed, [(entry) => entry.dropped])
|
|
9331
9499
|
};
|
|
9332
9500
|
});
|
|
9333
|
-
if (
|
|
9501
|
+
if (isFailure(valuesOutcome)) throw valuesOutcome.error;
|
|
9334
9502
|
const { values, dropped } = valuesOutcome.value;
|
|
9335
9503
|
return {
|
|
9336
9504
|
key,
|
|
@@ -9393,7 +9561,7 @@ function unifySchemas(schemas) {
|
|
|
9393
9561
|
return contain(() => {
|
|
9394
9562
|
return readValue(() => {
|
|
9395
9563
|
const snapshot = readArrayEntries(schemas);
|
|
9396
|
-
if (
|
|
9564
|
+
if (isFailure(snapshot)) throw snapshot.error;
|
|
9397
9565
|
if (!snapshot.value.dense) throw new INTRINSICS.error("unifySchemas: schemas must be dense");
|
|
9398
9566
|
const owned = snapshot.value.entries;
|
|
9399
9567
|
if (owned.length === 0) return {};
|
|
@@ -9451,7 +9619,7 @@ function stringToFormat(value) {
|
|
|
9451
9619
|
if (!isString(value)) return void 0;
|
|
9452
9620
|
if (value.length > 128) return void 0;
|
|
9453
9621
|
const outcome = attempt(() => classifyFormat(value));
|
|
9454
|
-
return outcome
|
|
9622
|
+
return isSuccess(outcome) ? outcome.value : void 0;
|
|
9455
9623
|
}
|
|
9456
9624
|
/**
|
|
9457
9625
|
* Classifies a list of sample values against the {@link SchemaFormat}
|
|
@@ -9480,7 +9648,7 @@ function samplesToFormat(values) {
|
|
|
9480
9648
|
return contain(() => {
|
|
9481
9649
|
return readValue(() => {
|
|
9482
9650
|
const snapshot = readArrayEntries(values);
|
|
9483
|
-
if (
|
|
9651
|
+
if (isFailure(snapshot)) throw snapshot.error;
|
|
9484
9652
|
if (!snapshot.value.dense) throw new INTRINSICS.error("samplesToFormat: values must be dense");
|
|
9485
9653
|
const owned = snapshot.value.entries;
|
|
9486
9654
|
if (owned.length === 0) return void 0;
|
|
@@ -9531,7 +9699,7 @@ function inferPrimitiveEnum(values, limit) {
|
|
|
9531
9699
|
return contain(() => {
|
|
9532
9700
|
return readValue(() => {
|
|
9533
9701
|
const snapshot = readArrayEntries(values);
|
|
9534
|
-
if (
|
|
9702
|
+
if (isFailure(snapshot)) throw snapshot.error;
|
|
9535
9703
|
if (!snapshot.value.dense) throw new INTRINSICS.error("inferPrimitiveEnum: values must be dense");
|
|
9536
9704
|
const owned = snapshot.value.entries;
|
|
9537
9705
|
if (owned.length < 2) return void 0;
|
|
@@ -9661,7 +9829,7 @@ function samplesToSchema(samples, options) {
|
|
|
9661
9829
|
const enumOn = optionsSnapshot?.enum ?? false;
|
|
9662
9830
|
const read = readValue(() => {
|
|
9663
9831
|
const snapshot = readArrayEntries(samples);
|
|
9664
|
-
if (
|
|
9832
|
+
if (isFailure(snapshot)) throw snapshot.error;
|
|
9665
9833
|
return snapshot.value;
|
|
9666
9834
|
}, "samplesToSchema", { subject: "samples" });
|
|
9667
9835
|
if (!read.dense) throw new ContractError("samplesToSchema: samples must be a dense array", { code: "structure" });
|
|
@@ -10022,17 +10190,17 @@ function literalShape(values, options) {
|
|
|
10022
10190
|
return contain(() => {
|
|
10023
10191
|
const input = values;
|
|
10024
10192
|
const array = attempt(() => INTRINSICS.array(input));
|
|
10025
|
-
if (
|
|
10193
|
+
if (isFailure(array) || !array.value) throw new ContractError("literalShape: values must be an array", {
|
|
10026
10194
|
code: "structure",
|
|
10027
10195
|
context: {
|
|
10028
10196
|
path: ["values"],
|
|
10029
10197
|
shape: "literal"
|
|
10030
10198
|
},
|
|
10031
|
-
|
|
10199
|
+
...isFailure(array) ? { cause: array.error } : {}
|
|
10032
10200
|
});
|
|
10033
10201
|
const safe = readOptions(options, ["description"], "literalShape", "literal");
|
|
10034
10202
|
const snapshot = readArrayEntries(values);
|
|
10035
|
-
if (
|
|
10203
|
+
if (isFailure(snapshot)) throw new ContractError("literalShape: values could not be copied", {
|
|
10036
10204
|
code: "structure",
|
|
10037
10205
|
context: {
|
|
10038
10206
|
path: ["values"],
|
|
@@ -10491,6 +10659,6 @@ function schemaToShape(schema) {
|
|
|
10491
10659
|
});
|
|
10492
10660
|
}, "schemaToShape");
|
|
10493
10661
|
}
|
|
10494
|
-
export { CLONE_NODE_LIMIT, COMPILE_DEPTH_LIMIT, COMPILE_NODE_LIMIT, CONTRACT_CODES, CONTRACT_ERROR_BRAND, ContractCompiler, ContractError, FAULT_LIMIT, FORMAT_MAX_LENGTH, FORMAT_PATTERNS, GENERATION_ATTEMPT_LIMIT, GUARD_DEPTH_LIMIT, INFER_BREADTH_LIMIT, INFER_DEPTH_LIMIT, INFER_ENUM_LIMIT, INTRINSICS, JSONCloner, JSON_SCHEMA_TYPES, PRESENCE_MASK_LIMIT, PREVIEW_LIMIT, SchemaCloner, ShapeCloner, ShapeValidator, admitMember, admitVisited, andOf, appendEntries, arrayOf, arrayShape, attempt, booleanShape, boundsOf, buildArrayFaults, buildNumberFaults, buildPositions, buildSampleMemo, buildStringFaults, canonicalStringify, classifyFormat, cloneJSONRecord, cloneJSONValue, cloneSchema, cloneShape, collectEntries, collectMembers,
|
|
10662
|
+
export { CHOICE_LIMIT, CLONE_NODE_LIMIT, COMPILE_DEPTH_LIMIT, COMPILE_NODE_LIMIT, CONTRACT_CODES, CONTRACT_ERROR_BRAND, ContractCompiler, ContractError, FAULT_LIMIT, FORMAT_MAX_LENGTH, FORMAT_PATTERNS, GENERATION_ATTEMPT_LIMIT, GUARD_DEPTH_LIMIT, INFER_BREADTH_LIMIT, INFER_DEPTH_LIMIT, INFER_ENUM_LIMIT, INTRINSICS, JSONCloner, JSON_SCHEMA_TYPES, NAME_LIMIT, NODE_LIMIT, PRESENCE_MASK_LIMIT, PREVIEW_LIMIT, STRING_LIMIT, SchemaCloner, ShapeCloner, ShapeValidator, TEXT_LIMIT, admitMember, admitVisited, andOf, appendEntries, arrayOf, arrayShape, attempt, booleanShape, boundsOf, buildArrayFaults, buildNumberFaults, buildPositions, buildSampleMemo, buildStringFaults, canonicalStringify, classifyFormat, cloneJSONRecord, cloneJSONValue, cloneSchema, cloneShape, collectEntries, collectMembers, comparePrimitives, compileAuditor, compileGenerator, compileGuard, compileParser, compileReporter, compileSchema, complementOf, contain, createContract, deriveLengthBounds, deriveRangeBounds, drawRandom, encodeLeaf, encodeParts, enumOf, enumerableKeys, enumerableSymbolCount, errorToMessage, escapeRegExp, failure, holds, inferPrimitiveEnum, instanceOf, integerShape, intersectionOf, isArray, isArrayBuffer, isArrayBufferView, isAsyncFunction, isAsyncGeneratorFunction, isAsyncIterable, isBigInt, isBigInt64Array, isBigUint64Array, isBoolean, isBoundedJSONRecord, isBoundedJSONValue, isConstructor, isContractError, isDataView, isDate, isDefined, isEmptyArray, isEmptyMap, isEmptyObject, isEmptySet, isEmptyString, isError, isFailure, isFalse, isFiniteNumber, isFloat32Array, isFloat64Array, isFunction, isGeneratorFunction, isInstance, isInt16Array, isInt32Array, isInt8Array, isInteger, isIterable, isJSONPrimitive, isJSONValue, isLiteralValue, isMap, isNonEmptyArray, isNonEmptyMap, isNonEmptyObject, isNonEmptySet, isNonEmptyString, isNonNegativeInteger, isNonNegativeNumber, isNull, isNullableBoolean, isNullableNumber, isNullableString, isNumber, isObject, isPromise, isPromiseLike, isRecord, isRegExp, isSet, isSharedArrayBuffer, isString, isSuccess, isSymbol, isTrue, isUint16Array, isUint32Array, isUint8Array, isUint8ClampedArray, isUndefined, isWeakMap, isWeakSet, isZeroArg, isZeroArgAsync, isZeroArgAsyncGenerator, isZeroArgGenerator, iterateIndices, jsonShape, keyOf, lazyOf, limitEntries, literalOf, literalShape, mapOf, matchOf, matchesISOInstant, matchesJSONDepth, matchesJSONValue, matchesMember, matchesPattern, matchesRecordBrand, matchesVisited, notOf, nullShape, nullableOf, nullableShape, numberShape, objectOf, objectShape, omitOf, omitVisited, oneOfShape, optionalOf, optionalShape, orOf, ownPattern, ownShape, parseArray, parseArrayField, parseBoolean, parseBooleanField, parseEnum, parseEnumField, parseEnumValues, parseInteger, parseIntegerField, parseJSON, parseJSONAs, parseJSONValue, parseJSONValueField, parseNull, parseNullField, parseNumber, parseNumberField, parseRecord, parseRecordField, parseString, parseStringField, pathOf, pickOf, pinMembers, preview, previewParts, rawShape, readArrayEntries, readGuardShape, readIndexView, readMapEntries, readOptions, readPattern, readPatternFlags, readPatternSource, readPresence, readSampleMemo, readSetEntries, readValue, recordOf, recordShape, refuseExpansion, resolveField, retainDepth, samplesToFormat, samplesToSchema, sanitizeBudget, sanitizeDepth, schemaToObject, schemaToParameters, schemaToShape, seededRandom, selectClosestFaults, setOf, shapeToKind, sortValues, stringOf, stringShape, stringToFormat, success, transformOf, tupleOf, unifySchemas, unionOf, unionShape, validateShape, valueToSchema, whereOf };
|
|
10495
10663
|
|
|
10496
10664
|
//# sourceMappingURL=index.js.map
|