@orkestrel/contract 0.0.23 → 0.0.25
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 +5335 -3588
- package/dist/src/core/index.cjs.map +1 -1
- package/dist/src/core/index.d.cts +1061 -224
- package/dist/src/core/index.d.ts +1061 -224
- package/dist/src/core/index.js +5312 -3589
- package/dist/src/core/index.js.map +1 -1
- package/package.json +8 -8
package/dist/src/core/index.d.ts
CHANGED
|
@@ -18,24 +18,22 @@
|
|
|
18
18
|
export declare function admitMember(members: Set<unknown>, value: unknown): void;
|
|
19
19
|
|
|
20
20
|
/**
|
|
21
|
-
* Admits a
|
|
21
|
+
* Admits a readable value exactly where `is` holds and returns the parser's value.
|
|
22
22
|
*
|
|
23
23
|
* @remarks
|
|
24
|
-
*
|
|
25
|
-
*
|
|
26
|
-
*
|
|
27
|
-
*
|
|
28
|
-
*
|
|
29
|
-
* Snapshot a foreign object before admission, as Tool.execute does. A getter changing between
|
|
30
|
-
* is and parse can publish a value that no recorded repair describes. A shallow snapshot only
|
|
31
|
-
* stabilizes its own level; nested foreign values must also provide stable reads.
|
|
24
|
+
* Guard-valid input parses once. Any other input refuses with every fault `audit` reports
|
|
25
|
+
* after {@link filterUncoveredFaults} prunes the faults a union fault covers, bounded at
|
|
26
|
+
* {@link FAULT_LIMIT}. A parse that returns `undefined` for a value other than `undefined`
|
|
27
|
+
* refuses with no fault, and a read failure refuses with its cause rather than throwing.
|
|
28
|
+
* Repair a lossless leaf through {@link repairValue}.
|
|
32
29
|
*
|
|
33
30
|
* @example
|
|
34
31
|
* ```ts
|
|
35
|
-
* admitValue(createContract(numberShape()),
|
|
32
|
+
* admitValue(createContract(numberShape()), 3) // success carrying 3
|
|
33
|
+
* admitValue(createContract(numberShape()), '3') // refusal carrying the type fault
|
|
36
34
|
* ```
|
|
37
35
|
*/
|
|
38
|
-
export declare function admitValue<T>(contract: ContractInterface<T>, value: unknown): Result<
|
|
36
|
+
export declare function admitValue<T>(contract: ContractInterface<T>, value: unknown): Result<T, ContractRefusal>;
|
|
39
37
|
|
|
40
38
|
/**
|
|
41
39
|
* Records an object as entered on a traversal's active path.
|
|
@@ -147,17 +145,20 @@ export declare function arrayOf(elementGuard: (value: unknown) => boolean): Guar
|
|
|
147
145
|
* Represents the owned result of reading one array through its reflected own-index lens.
|
|
148
146
|
*
|
|
149
147
|
* @remarks
|
|
150
|
-
* {@link entries} is a
|
|
148
|
+
* {@link entries} is a native array with actual holes: reading a hole
|
|
151
149
|
* yields `undefined`, while own membership remains absent. A length-driven
|
|
152
150
|
* consumer must first require {@link dense} or carry an independent work bound.
|
|
153
151
|
*
|
|
154
|
-
* {@link
|
|
152
|
+
* {@link collectArrayEntries} returns a fresh unfrozen read on every call, and
|
|
153
|
+
* {@link readArrayEntries} freezes the read and its entries.
|
|
155
154
|
*/
|
|
156
155
|
export declare interface ArrayRead<T = unknown> {
|
|
157
|
-
/** Holds the
|
|
156
|
+
/** Holds the native entries in index order, retaining sparse positions as holes. */
|
|
158
157
|
readonly entries: ReadonlyArray<T | undefined>;
|
|
159
158
|
/** Reports whether every index from zero through length minus one was reflected. */
|
|
160
159
|
readonly dense: boolean;
|
|
160
|
+
/** Reports whether every own key is a canonical index or `length`, symbols included. */
|
|
161
|
+
readonly exact: boolean;
|
|
161
162
|
}
|
|
162
163
|
|
|
163
164
|
/** Describes an array with an element shape and optional length bounds. */
|
|
@@ -224,8 +225,8 @@ export declare interface ArrayShapeOptions {
|
|
|
224
225
|
*/
|
|
225
226
|
export declare function attempt<T>(callback: () => T): Result<T>;
|
|
226
227
|
|
|
227
|
-
/** Covers every fault an audit reports — the parse faults plus undeclared keys. */
|
|
228
|
-
export declare type AuditFault = Fault | ExtraFault;
|
|
228
|
+
/** Covers every fault an audit reports — the parse faults plus undeclared and hidden keys. */
|
|
229
|
+
export declare type AuditFault = Fault | ExtraFault | HiddenFault;
|
|
229
230
|
|
|
230
231
|
/** Describes the closed shape built for audit faults, including paired discriminator hints. */
|
|
231
232
|
export declare type AuditFaultShape = ReturnType<FaultShaper['build']>;
|
|
@@ -352,6 +353,25 @@ export declare interface BoundsRead {
|
|
|
352
353
|
*/
|
|
353
354
|
export declare function buildArrayFaults(shape: ArrayShape, length: number, path: readonly string[]): readonly Fault[];
|
|
354
355
|
|
|
356
|
+
/**
|
|
357
|
+
* Builds the key plan that answers one key order from the declared member guards.
|
|
358
|
+
*
|
|
359
|
+
* @remarks
|
|
360
|
+
* One {@link KeyStep} per key, in the order given, each holding the key and its declared guard.
|
|
361
|
+
* The plan and its steps are fresh and unfrozen.
|
|
362
|
+
*
|
|
363
|
+
* @param keys - The key order the plan answers
|
|
364
|
+
* @param guards - The declared member guards, keyed by own string key
|
|
365
|
+
* @returns The plan, or `undefined` when any key is undeclared
|
|
366
|
+
*
|
|
367
|
+
* @example
|
|
368
|
+
* ```ts
|
|
369
|
+
* buildKeyPlan(['id'], { id: isString }) // [{ key: 'id', guard: isString }]
|
|
370
|
+
* buildKeyPlan(['other'], { id: isString }) // undefined
|
|
371
|
+
* ```
|
|
372
|
+
*/
|
|
373
|
+
export declare function buildKeyPlan(keys: readonly string[], guards: Readonly<Record<string, Guard<unknown> | undefined>>): readonly KeyStep[] | undefined;
|
|
374
|
+
|
|
355
375
|
/**
|
|
356
376
|
* Builds the refinement faults a number value has against a {@link NumberShape}.
|
|
357
377
|
*
|
|
@@ -360,7 +380,7 @@ export declare function buildArrayFaults(shape: ArrayShape, length: number, path
|
|
|
360
380
|
* doors for the same reason. `expected` is the shape's own kind — `'integer'`
|
|
361
381
|
* when `integer: true`, otherwise `'number'` — so a caller reading the report
|
|
362
382
|
* sees the declaration's vocabulary rather than the value's. Order is
|
|
363
|
-
* `integer`,
|
|
383
|
+
* `integer`, `min`, `over`, `max`, then `under`. It refuses an unreadable shape through the
|
|
364
384
|
* same boundary and for the same reason {@link buildStringFaults} does.
|
|
365
385
|
*
|
|
366
386
|
* @param shape - The number shape whose refinements are checked
|
|
@@ -377,6 +397,24 @@ export declare function buildArrayFaults(shape: ArrayShape, length: number, path
|
|
|
377
397
|
*/
|
|
378
398
|
export declare function buildNumberFaults(shape: NumberShape, value: number, path: readonly string[]): readonly Fault[];
|
|
379
399
|
|
|
400
|
+
/**
|
|
401
|
+
* Builds a map key from the leading segments of a path, without dispatching through array serialization.
|
|
402
|
+
*
|
|
403
|
+
* @remarks
|
|
404
|
+
* Each segment is encoded as a quoted string and the encodings are joined by a captured `join`,
|
|
405
|
+
* so a caller-installed `Array.prototype.toJSON` cannot reach the key and two paths never share one.
|
|
406
|
+
*
|
|
407
|
+
* @param path - The path whose leading segments form the key
|
|
408
|
+
* @param length - The number of leading segments to keep; default: every segment
|
|
409
|
+
* @returns The key text, empty for no segment
|
|
410
|
+
*
|
|
411
|
+
* @example
|
|
412
|
+
* ```ts
|
|
413
|
+
* buildPathKey(['a', 'b'], 1) // '"a"'
|
|
414
|
+
* ```
|
|
415
|
+
*/
|
|
416
|
+
export declare function buildPathKey(path: readonly string[], length?: number): string;
|
|
417
|
+
|
|
380
418
|
/**
|
|
381
419
|
* Builds a null-prototype lookup from names to their last index.
|
|
382
420
|
*
|
|
@@ -488,8 +526,8 @@ export declare function buildStringFaults(shape: StringShape, value: string, pat
|
|
|
488
526
|
* - cyclic input, tracked with the same ancestor-{@link WeakSet} discipline
|
|
489
527
|
* the container branches of value inference use, so a shared (non-cyclic)
|
|
490
528
|
* reference reached twice through different paths still encodes;
|
|
491
|
-
*
|
|
492
|
-
*
|
|
529
|
+
* An untrusted traversal is categorically different: a throwing own-getter,
|
|
530
|
+
* untrusted `ownKeys` trap, or revoked `Proxy` throws a `structure`
|
|
493
531
|
* {@link ContractError} through {@link readValue}. A caller can therefore
|
|
494
532
|
* distinguish "not JSON-encodable" from "could not be read".
|
|
495
533
|
*
|
|
@@ -515,6 +553,33 @@ export declare function buildStringFaults(shape: StringShape, value: string, pat
|
|
|
515
553
|
*/
|
|
516
554
|
export declare function canonicalStringify(value: unknown): string | undefined;
|
|
517
555
|
|
|
556
|
+
/**
|
|
557
|
+
* Represents where an owned snapshot holds a value by identity instead of copying it.
|
|
558
|
+
*
|
|
559
|
+
* @remarks
|
|
560
|
+
* A compiler derives one plan per declaration node below which an interface sits; absence means
|
|
561
|
+
* that no interface sits below the position, so every plain record and array there is copied.
|
|
562
|
+
* `held` marks an interface position. `properties` holds every declared object key, each with
|
|
563
|
+
* its plan or `undefined`, `tail` the plan of an undeclared key, and `items` the plan of an array
|
|
564
|
+
* element.
|
|
565
|
+
*
|
|
566
|
+
* @example
|
|
567
|
+
* ```ts
|
|
568
|
+
* const plan: CapturePlan = {
|
|
569
|
+
* held: false,
|
|
570
|
+
* properties: { store: { held: true, properties: {}, tail: undefined, items: undefined } },
|
|
571
|
+
* tail: undefined,
|
|
572
|
+
* items: undefined,
|
|
573
|
+
* }
|
|
574
|
+
* ```
|
|
575
|
+
*/
|
|
576
|
+
export declare interface CapturePlan {
|
|
577
|
+
readonly held: boolean;
|
|
578
|
+
readonly properties: Readonly<Record<string, CapturePlan | undefined>>;
|
|
579
|
+
readonly tail: CapturePlan | undefined;
|
|
580
|
+
readonly items: CapturePlan | undefined;
|
|
581
|
+
}
|
|
582
|
+
|
|
518
583
|
/**
|
|
519
584
|
* Caps at `1024` the number of choices one schema field may offer, frozen.
|
|
520
585
|
*
|
|
@@ -588,7 +653,9 @@ export declare const CLONE_NODE_LIMIT = 262144;
|
|
|
588
653
|
*
|
|
589
654
|
* @param value - The unknown record value to validate and snapshot
|
|
590
655
|
* @returns A deeply cloned and frozen JSON record
|
|
591
|
-
* @throws {ContractError} When the root is not a record, nested data is inexact, or traversal
|
|
656
|
+
* @throws {ContractError} When the root is not a record, nested data is inexact, or traversal
|
|
657
|
+
* fails; a nested refusal is the one {@link cloneJSONValue} raises, `cloneJSONValue:` prefix and path
|
|
658
|
+
* included
|
|
592
659
|
*
|
|
593
660
|
* @example
|
|
594
661
|
* ```ts
|
|
@@ -609,14 +676,17 @@ export declare function cloneJSONRecord(value: unknown): JSONRecord;
|
|
|
609
676
|
* wired. Array keys must be exactly `length` plus every canonical index.
|
|
610
677
|
* Writable and configurable index flags are normalized rather than treated as
|
|
611
678
|
* JSON data, so frozen arrays remain valid. Property descriptors are inspected
|
|
612
|
-
* without reading values through accessors, and every
|
|
679
|
+
* without reading values through accessors, and every untrusted reflective
|
|
613
680
|
* operation is contained before a new clone-coded error is exposed.
|
|
614
681
|
* Each call creates a fresh {@link JSONCloner}; use the class directly when
|
|
615
682
|
* terminal success or failure identity must be replayed without another read.
|
|
616
683
|
*
|
|
617
684
|
* @param value - The unknown value to validate and snapshot
|
|
618
685
|
* @returns The primitive unchanged, or a deeply cloned and frozen JSON graph
|
|
619
|
-
* @throws {ContractError} When the value is not exact acyclic JSON data or traversal fails
|
|
686
|
+
* @throws {ContractError} When the value is not exact acyclic JSON data or traversal fails; a
|
|
687
|
+
* refusal that names a member or a container carries its `path` and `received`, and its message
|
|
688
|
+
* ends with ` at ` and the rendered path, except at the root, where the path is `[]` and the
|
|
689
|
+
* message has no suffix
|
|
620
690
|
*
|
|
621
691
|
* @example
|
|
622
692
|
* ```ts
|
|
@@ -636,14 +706,14 @@ export declare function cloneJSONValue(value: unknown): JSONValue;
|
|
|
636
706
|
* references and closing cyclic edges onto their cloned nodes. Primitive
|
|
637
707
|
* values and own enumerable string-keyed edges are copied; record nodes use
|
|
638
708
|
* null prototypes, arrays retain only their intrinsic array prototype, and
|
|
639
|
-
* every produced object is frozen after its edges are wired.
|
|
709
|
+
* every produced object is frozen after its edges are wired. Untrusted traversal
|
|
640
710
|
* throws a clone-coded {@link ContractError}, never a caller-owned raw error.
|
|
641
711
|
* Each call creates a fresh {@link SchemaCloner}; use the class directly when
|
|
642
712
|
* terminal success or failure identity must be replayed without another read.
|
|
643
713
|
*
|
|
644
714
|
* @param schema - The JSON Schema graph to snapshot
|
|
645
715
|
* @returns A deeply cloned and frozen JSON Schema graph
|
|
646
|
-
* @throws {ContractError} When
|
|
716
|
+
* @throws {ContractError} When untrusted schema traversal prevents ownership
|
|
647
717
|
*
|
|
648
718
|
* @example
|
|
649
719
|
* ```ts
|
|
@@ -660,7 +730,7 @@ export declare function cloneSchema(schema: JSONSchema): JSONSchema;
|
|
|
660
730
|
* @remarks
|
|
661
731
|
* A fresh public {@link ShapeCloner} preserves shared-child identity while
|
|
662
732
|
* building the candidate snapshot, owns raw schemas, validates the exact
|
|
663
|
-
* completed root, applies deferred fidelity, and translates unexpected
|
|
733
|
+
* completed root, applies deferred fidelity, and translates unexpected untrusted
|
|
664
734
|
* failures. Inside the engine, each node's own data discriminant and every
|
|
665
735
|
* declared field are captured descriptor-first from two agreeing reads, and the
|
|
666
736
|
* carried population alone supplies its shallow shell, semantic checks, child
|
|
@@ -676,12 +746,12 @@ export declare function cloneSchema(schema: JSONSchema): JSONSchema;
|
|
|
676
746
|
* {@link cloneSchema}. Before return, a fresh {@link ShapeValidator} independently
|
|
677
747
|
* validates the exact cloned root. Ownership never erases a structural edge or
|
|
678
748
|
* normalizes an invalid scalar/bound into a plausible declaration: those
|
|
679
|
-
* inputs throw their coded structure/bound error.
|
|
749
|
+
* inputs throw their coded structure/bound error. Untrusted traversal remains
|
|
680
750
|
* distinct and throws a clone-coded {@link ContractError}.
|
|
681
751
|
*
|
|
682
752
|
* @param shape - The contract shape graph to snapshot
|
|
683
753
|
* @returns A deeply cloned and frozen shape graph
|
|
684
|
-
* @throws {ContractError} When the declaration cannot be copied faithfully or
|
|
754
|
+
* @throws {ContractError} When the declaration cannot be copied faithfully or untrusted shape or raw-schema traversal prevents ownership
|
|
685
755
|
*
|
|
686
756
|
* @example
|
|
687
757
|
* ```ts
|
|
@@ -694,6 +764,38 @@ export declare function cloneShape(shape: StringShape): StringShape;
|
|
|
694
764
|
|
|
695
765
|
export declare function cloneShape(shape: ContractShape): ContractShape;
|
|
696
766
|
|
|
767
|
+
/**
|
|
768
|
+
* Collects an array's entries through its reflected own-index population.
|
|
769
|
+
*
|
|
770
|
+
* @remarks
|
|
771
|
+
* Reads `length` once and one reflected own-key population, then corroborates
|
|
772
|
+
* and reads only those reflected canonical indices in ascending order. The
|
|
773
|
+
* native entries retain actual holes: reading one yields `undefined`, while
|
|
774
|
+
* own membership remains absent. Its work is proportional to the reflected
|
|
775
|
+
* population, so a length-driven consumer must require `dense` or carry an
|
|
776
|
+
* independent bound. `exact` is false when the population holds any key other
|
|
777
|
+
* than a canonical index or `length`, a symbol key included. A population that
|
|
778
|
+
* is exactly the canonical indices in ascending order followed by `length` is
|
|
779
|
+
* copied straight by index under the same per-index corroboration, and answers
|
|
780
|
+
* with the same entries, the same `dense` and `exact` facts, and the same
|
|
781
|
+
* refusals as the walk. Caller-defined iteration is ignored. A descriptor-only
|
|
782
|
+
* index omitted from reflection is deliberately outside this lens and remains a
|
|
783
|
+
* hole. `4294967295` is metadata rather than an array index. Every call returns
|
|
784
|
+
* a fresh unfrozen read; {@link readArrayEntries} freezes it.
|
|
785
|
+
*
|
|
786
|
+
* @param value - The array whose reflected indexed entries to collect
|
|
787
|
+
* @returns The entries with their `dense` and `exact` facts
|
|
788
|
+
* @throws The exact thrown value when length, reflection, membership, or
|
|
789
|
+
* indexed value observation throws, and an `Error` on a non-native
|
|
790
|
+
* length or a view disagreement
|
|
791
|
+
*
|
|
792
|
+
* @example
|
|
793
|
+
* ```ts
|
|
794
|
+
* collectArrayEntries([1, 2]) // { entries: [1, 2], dense: true, exact: true }
|
|
795
|
+
* ```
|
|
796
|
+
*/
|
|
797
|
+
export declare function collectArrayEntries<T>(value: readonly T[]): ArrayRead<T>;
|
|
798
|
+
|
|
697
799
|
/**
|
|
698
800
|
* Builds the collector a captured `forEach` sweep appends through.
|
|
699
801
|
*
|
|
@@ -816,7 +918,7 @@ export declare const COMPILE_DEPTH_LIMIT = 512;
|
|
|
816
918
|
*
|
|
817
919
|
* This cap does not bound compilation, because the compilers do not expand a
|
|
818
920
|
* DAG. Every artifact family is one entry per unique node, so the boundary
|
|
819
|
-
* declaration
|
|
921
|
+
* preceding declaration compiles its unique nodes in about a millisecond.
|
|
820
922
|
* What does expand is what a CONSUMER materializes from the artifacts: the
|
|
821
923
|
* value `generate` builds, and the document a compiled schema serializes to,
|
|
822
924
|
* are trees of exactly this size. The cap survives as a bound on what a caller
|
|
@@ -845,7 +947,7 @@ export declare const COMPILE_NODE_LIMIT = 16384;
|
|
|
845
947
|
* evaluated for a valid declaration. The invariant relates two
|
|
846
948
|
* separate calls, so it holds for a value whose reads are stable across calls;
|
|
847
949
|
* see the read-stability precondition on {@link ContractInterface}. Every
|
|
848
|
-
* recursive call returns at most {@link FAULT_LIMIT} entries.
|
|
950
|
+
* recursive call returns at most {@link FAULT_LIMIT} entries. Untrusted property
|
|
849
951
|
* access raises the shared coded read refusal with the current container path
|
|
850
952
|
* and shape, so unreadability never masquerades as a type mismatch.
|
|
851
953
|
* It requests exactly the `auditor` root of a fresh {@link ContractCompiler}
|
|
@@ -909,7 +1011,12 @@ export declare function compileGenerator(shape: ContractShape, random?: RandomFu
|
|
|
909
1011
|
* observe own enumerable string keys through {@link enumerableKeys}, the same
|
|
910
1012
|
* key view their parser, reporter, auditor, and inference use for both open and
|
|
911
1013
|
* closed objects — the view is shared, the verdict on an undeclared key is not
|
|
912
|
-
* (this guard rejects the object; the parser drops the key).
|
|
1014
|
+
* (this guard rejects the object; the parser drops the key). A closed or
|
|
1015
|
+
* tail-shaped object also refuses an own member outside that view, a
|
|
1016
|
+
* non-enumerable string key or a symbol key. An object with
|
|
1017
|
+
* `additionalProperties: true` runs no own-key count: it admits an undeclared
|
|
1018
|
+
* non-enumerable or symbol member, while a declared member outside the enumerable
|
|
1019
|
+
* view still reads as absent.
|
|
913
1020
|
* Like every guard it is total — it never throws, as `.claude/rules/patterns.md`
|
|
914
1021
|
* § Validation and contracts requires. It requests
|
|
915
1022
|
* exactly the `guard` root of a fresh {@link ContractCompiler}, which owns the
|
|
@@ -995,12 +1102,12 @@ export declare function compileParser(shape: ContractShape): Parser<unknown>;
|
|
|
995
1102
|
* match" / "no consensus" summary fault prepended to its closest variant's
|
|
996
1103
|
* faults — slices its return to at most {@link FAULT_LIMIT} entries, so the
|
|
997
1104
|
* bound holds at every level of nesting rather than at the outermost container alone, on
|
|
998
|
-
*
|
|
1105
|
+
* untrusted input (a huge array, a wide record, a wide union of wide
|
|
999
1106
|
* records). A closed object's extra keys never
|
|
1000
1107
|
* fault — `parse` silently drops them, so `explain` mirrors that leniency, and
|
|
1001
1108
|
* {@link compileAuditor} is where they do fault; an open object with a
|
|
1002
1109
|
* constraining `additionalProperties` shape recurses extras against it instead.
|
|
1003
|
-
*
|
|
1110
|
+
* An untrusted getter or throwing `Proxy` trap is contained through {@link attempt}
|
|
1004
1111
|
* and surfaces as a single top-level type fault, never a throw, as
|
|
1005
1112
|
* `.claude/rules/patterns.md` § Validation and contracts requires.
|
|
1006
1113
|
* It requests exactly the `reporter` root of a fresh {@link ContractCompiler}
|
|
@@ -1202,22 +1309,6 @@ export declare const CONTRACT_CODES: readonly ContractCode[];
|
|
|
1202
1309
|
*/
|
|
1203
1310
|
export declare const CONTRACT_ERROR_BRAND: unique symbol;
|
|
1204
1311
|
|
|
1205
|
-
/**
|
|
1206
|
-
* Carries an admitted value and the lossless repairs made while parsing it.
|
|
1207
|
-
*
|
|
1208
|
-
* @remarks
|
|
1209
|
-
* The value keeps the parser's ownership: a union may return the caller's input by identity.
|
|
1210
|
-
*
|
|
1211
|
-
* @example
|
|
1212
|
-
* ```ts
|
|
1213
|
-
* const admitted: ContractAdmission<number> = { value: 3, repairs: [] }
|
|
1214
|
-
* ```
|
|
1215
|
-
*/
|
|
1216
|
-
export declare interface ContractAdmission<T> {
|
|
1217
|
-
readonly value: T;
|
|
1218
|
-
readonly repairs: readonly AuditFault[];
|
|
1219
|
-
}
|
|
1220
|
-
|
|
1221
1312
|
/**
|
|
1222
1313
|
* Names the machine-readable category carried by a {@link ContractError}.
|
|
1223
1314
|
*
|
|
@@ -1285,14 +1376,16 @@ export declare type ContractCode =
|
|
|
1285
1376
|
* holds a union, because a union's membership question IS a guard question in
|
|
1286
1377
|
* all three, and every getter builds it when the graph holds a default, because
|
|
1287
1378
|
* a default that its inner shape refuses refuses at whichever artifact is read
|
|
1288
|
-
* first.
|
|
1379
|
+
* first. The `guard`, `parser` and `reporter` plan the audits when the graph holds
|
|
1380
|
+
* an interface, because an interface node answers each of the three from its audit.
|
|
1381
|
+
* The `owner` builds the guard, the auditor, and the parser, because it judges with all three.
|
|
1289
1382
|
*
|
|
1290
1383
|
* One terminal lifecycle covers preparation and every family. A failure settles
|
|
1291
1384
|
* the compiler: later getters rethrow that exact error, while an artifact
|
|
1292
1385
|
* already handed out keeps working, because each compiled artifact is
|
|
1293
1386
|
* self-contained. Reentry — reachable only through a caller accessor the
|
|
1294
|
-
* declaration itself exposes,
|
|
1295
|
-
* ownership invokes —
|
|
1387
|
+
* declaration itself exposes, because a `pattern` getter is the one accessor
|
|
1388
|
+
* ownership invokes — invalidates the nested read, the interrupted outer read, and
|
|
1296
1389
|
* every later read with one shared cause-free error.
|
|
1297
1390
|
*
|
|
1298
1391
|
* @typeParam S - The declaration's shape type, which types the published artifacts
|
|
@@ -1331,13 +1424,15 @@ export declare class ContractCompiler<S extends ContractShape = ContractShape> i
|
|
|
1331
1424
|
get reporter(): ReporterFunction;
|
|
1332
1425
|
/** Returns the compiled seed-data source for the owned declaration. */
|
|
1333
1426
|
get generator(): SeederFunction<Infer<S>>;
|
|
1427
|
+
/** Returns the compiled owning admission for the owned declaration. */
|
|
1428
|
+
get owner(): OwnerFunction<Infer<S>>;
|
|
1334
1429
|
/**
|
|
1335
1430
|
* Returns the frozen bundle of this compiler's artifacts.
|
|
1336
1431
|
*
|
|
1337
1432
|
* @remarks
|
|
1338
1433
|
* Own enumerable keys `schema`, `is`, `parse`, `audit`, `explain`,
|
|
1339
|
-
* `generate`, in that order, each holding the exact value the
|
|
1340
|
-
* getter publishes.
|
|
1434
|
+
* `generate`, `own`, in that order, each holding the exact value the
|
|
1435
|
+
* corresponding getter publishes.
|
|
1341
1436
|
*/
|
|
1342
1437
|
get contract(): ContractInterface<Infer<S>>;
|
|
1343
1438
|
}
|
|
@@ -1351,9 +1446,12 @@ export declare class ContractCompiler<S extends ContractShape = ContractShape> i
|
|
|
1351
1446
|
* structural edge once into children-before-parent order; every artifact family
|
|
1352
1447
|
* is then one postorder pass over that index, so a shared child costs its
|
|
1353
1448
|
* authored nodes rather than its paths. A getter builds its own family and no
|
|
1354
|
-
* other, except where an artifact genuinely consumes
|
|
1355
|
-
* `
|
|
1356
|
-
* they build it too
|
|
1449
|
+
* other, except where an artifact genuinely consumes another — `parser`,
|
|
1450
|
+
* `reporter` and `generator` resolve union membership through the compiled
|
|
1451
|
+
* guard, so they build it too, and `guard`, `parser` and `reporter` answer an
|
|
1452
|
+
* interface node from its audit, so they plan the audits when the graph holds
|
|
1453
|
+
* one, and `owner` builds the guard, the auditor, and the parser it judges with. `contract`
|
|
1454
|
+
* requests every root in getter order.
|
|
1357
1455
|
*
|
|
1358
1456
|
* Every getter REPLAYS its exact artifact: reading one twice returns the same
|
|
1359
1457
|
* function or graph by identity, and {@link contract}'s members are those
|
|
@@ -1361,7 +1459,7 @@ export declare class ContractCompiler<S extends ContractShape = ContractShape> i
|
|
|
1361
1459
|
* a failure anywhere settles the compiler permanently — later getters rethrow
|
|
1362
1460
|
* that exact error while an artifact already handed out stays usable, because
|
|
1363
1461
|
* each one is self-contained. Cross-getter reentry (only reachable through a
|
|
1364
|
-
* caller accessor the declaration exposes)
|
|
1462
|
+
* caller accessor the declaration exposes) invalidates the nested read, the
|
|
1365
1463
|
* interrupted outer read, and every later read with one shared cause-free
|
|
1366
1464
|
* error.
|
|
1367
1465
|
*
|
|
@@ -1376,11 +1474,11 @@ export declare class ContractCompiler<S extends ContractShape = ContractShape> i
|
|
|
1376
1474
|
* It declares no call-signature member, so its whole surface is the readonly data
|
|
1377
1475
|
* properties: `schema` (a {@link JSONSchema}), `guard` (a `Guard<Infer<S>>`), `parser`
|
|
1378
1476
|
* (a `Parser<Infer<S>>`), `auditor` (an {@link AuditorFunction}), `reporter` (a {@link
|
|
1379
|
-
* ReporterFunction}), `generator` (a `SeederFunction<Infer<S>>`),
|
|
1380
|
-
* `ContractInterface<Infer<S>>`). `contract` is the frozen
|
|
1381
|
-
* keys are `schema`, `is`, `parse`, `audit`, `explain`,
|
|
1382
|
-
* each holding the exact value the corresponding getter
|
|
1383
|
-
* exactly `compiler.guard`, by identity rather than as a copy.
|
|
1477
|
+
* ReporterFunction}), `generator` (a `SeederFunction<Infer<S>>`), `owner` (an {@link
|
|
1478
|
+
* OwnerFunction}), and `contract` (a `ContractInterface<Infer<S>>`). `contract` is the frozen
|
|
1479
|
+
* bundle whose own enumerable keys are `schema`, `is`, `parse`, `audit`, `explain`,
|
|
1480
|
+
* `generate`, and `own` in that order, each holding the exact value the corresponding getter
|
|
1481
|
+
* publishes — `contract.is` is exactly `compiler.guard`, by identity rather than as a copy.
|
|
1384
1482
|
*
|
|
1385
1483
|
* @example
|
|
1386
1484
|
* ```ts
|
|
@@ -1401,6 +1499,8 @@ export declare interface ContractCompilerInterface<S extends ContractShape> {
|
|
|
1401
1499
|
readonly reporter: ReporterFunction;
|
|
1402
1500
|
/** Returns the compiled seed-data source. */
|
|
1403
1501
|
readonly generator: SeederFunction<Infer<S>>;
|
|
1502
|
+
/** Returns the compiled owning admission. */
|
|
1503
|
+
readonly owner: OwnerFunction<Infer<S>>;
|
|
1404
1504
|
/** Returns the frozen bundle whose values are the artifacts declared earlier. */
|
|
1405
1505
|
readonly contract: ContractInterface<Infer<S>>;
|
|
1406
1506
|
}
|
|
@@ -1453,6 +1553,13 @@ export declare interface ContractErrorContext {
|
|
|
1453
1553
|
readonly limit?: number | string;
|
|
1454
1554
|
/** Holds the received-value description associated with the error. */
|
|
1455
1555
|
readonly received?: string;
|
|
1556
|
+
/**
|
|
1557
|
+
* Holds the audit faults of the refused value, each located by its own path.
|
|
1558
|
+
*
|
|
1559
|
+
* @remarks
|
|
1560
|
+
* A refusal that carries `faults` reports every fault it found, where `path` locates the first.
|
|
1561
|
+
*/
|
|
1562
|
+
readonly faults?: readonly AuditFault[];
|
|
1456
1563
|
}
|
|
1457
1564
|
|
|
1458
1565
|
/**
|
|
@@ -1478,9 +1585,9 @@ export declare interface ContractErrorOptions {
|
|
|
1478
1585
|
* Built by `createContract`: `is` narrows, `audit` diagnoses strict rejection,
|
|
1479
1586
|
* `parse` coerces (returning the typed value or `undefined`), `schema` is an
|
|
1480
1587
|
* owned deeply frozen emitted JSON Schema, `explain` reports the structured
|
|
1481
|
-
* faults behind a failed `parse`,
|
|
1588
|
+
* faults behind a failed `parse`, `generate` produces deterministic seed
|
|
1482
1589
|
* data from a {@link RandomFunction} (defaulting to a wall-clock-seeded source
|
|
1483
|
-
* when none is supplied).
|
|
1590
|
+
* when none is supplied), and `own` admits an owned snapshot of a value.
|
|
1484
1591
|
*
|
|
1485
1592
|
* LOCKSTEP means derived from one owned snapshot of the shape, not agreeing on
|
|
1486
1593
|
* which values to accept: `is` and `schema` describe the contract's canonical
|
|
@@ -1511,8 +1618,8 @@ export declare interface ContractInterface<T> {
|
|
|
1511
1618
|
* Coercion (`'36'` → `36`) and every leaf refinement (`min` / `max` /
|
|
1512
1619
|
* `pattern`) both apply, so every non-`undefined` result satisfies `is`.
|
|
1513
1620
|
* Honest invalidity answers `undefined`, while a failed required object,
|
|
1514
|
-
* JSON, or dense-array index read throws the shared coded
|
|
1515
|
-
* outcomes stay distinguishable.
|
|
1621
|
+
* interface member, JSON, or dense-array index read throws the shared coded
|
|
1622
|
+
* refusal — the two outcomes stay distinguishable.
|
|
1516
1623
|
*
|
|
1517
1624
|
* @param value - The value to coerce
|
|
1518
1625
|
* @returns The typed value, or `undefined` when the value is readable and invalid
|
|
@@ -1528,7 +1635,10 @@ export declare interface ContractInterface<T> {
|
|
|
1528
1635
|
* stable across calls (see the read-stability precondition on
|
|
1529
1636
|
* {@link ContractInterface}). It is the report for the stricter of the two
|
|
1530
1637
|
* domains, so a coercible leaf and a closed object's undeclared key both
|
|
1531
|
-
* fault here and neither faults in `explain`.
|
|
1638
|
+
* fault here and neither faults in `explain`. An own member outside the
|
|
1639
|
+
* enumerable view of a closed or tail-shaped object faults here as `'hidden'`
|
|
1640
|
+
* or `'extra'`, while `explain` reads the enumerable view and reports a
|
|
1641
|
+
* declared such member as `'missing'`.
|
|
1532
1642
|
*
|
|
1533
1643
|
* @param value - The value to check
|
|
1534
1644
|
* @returns The faults found, empty when the value is strictly valid
|
|
@@ -1543,7 +1653,8 @@ export declare interface ContractInterface<T> {
|
|
|
1543
1653
|
* value whose reads are stable across calls (see the read-stability
|
|
1544
1654
|
* precondition on {@link ContractInterface}) — explain mirrors `parse`'s
|
|
1545
1655
|
* coercion, not the stricter `is`, and `audit` is the report that mirrors
|
|
1546
|
-
* `is`.
|
|
1656
|
+
* `is`. An `undefined` that `is` admits parses to itself, so its report is
|
|
1657
|
+
* empty. Faults are listed in stable pre-order (declared key/index order).
|
|
1547
1658
|
*
|
|
1548
1659
|
* @param value - The value to check
|
|
1549
1660
|
* @returns The faults found, empty when the value parses successfully
|
|
@@ -1562,6 +1673,19 @@ export declare interface ContractInterface<T> {
|
|
|
1562
1673
|
* @throws {ContractError} When the declaration cannot be satisfied, or when the sample source fails
|
|
1563
1674
|
*/
|
|
1564
1675
|
generate(random?: RandomFunction): T;
|
|
1676
|
+
/**
|
|
1677
|
+
* Admits an owned snapshot of a value and returns the parser's value, at the argument's static type.
|
|
1678
|
+
*
|
|
1679
|
+
* @remarks
|
|
1680
|
+
* Reads each own enumerable string member and each present index of a plain record or array one
|
|
1681
|
+
* time, into a frozen copy, and admits that copy as {@link admitValue} would. A value at an
|
|
1682
|
+
* interface position, any other object, and every function are held by identity.
|
|
1683
|
+
*
|
|
1684
|
+
* @param value - The value to own
|
|
1685
|
+
* @returns The parser's value over the snapshot, or the refusal
|
|
1686
|
+
*/
|
|
1687
|
+
own<V extends T>(value: V): Result<V, ContractRefusal>;
|
|
1688
|
+
own(value: unknown): Result<T, ContractRefusal>;
|
|
1565
1689
|
}
|
|
1566
1690
|
|
|
1567
1691
|
/**
|
|
@@ -1577,6 +1701,22 @@ export declare interface ContractRefusal {
|
|
|
1577
1701
|
readonly cause?: unknown;
|
|
1578
1702
|
}
|
|
1579
1703
|
|
|
1704
|
+
/**
|
|
1705
|
+
* Carries a repaired value and the lossless repairs made while parsing it.
|
|
1706
|
+
*
|
|
1707
|
+
* @remarks
|
|
1708
|
+
* The value keeps the parser's ownership: a union may return the caller's input by identity.
|
|
1709
|
+
*
|
|
1710
|
+
* @example
|
|
1711
|
+
* ```ts
|
|
1712
|
+
* const repaired: ContractRepair<number> = { value: 3, repairs: [] }
|
|
1713
|
+
* ```
|
|
1714
|
+
*/
|
|
1715
|
+
export declare interface ContractRepair<T> {
|
|
1716
|
+
readonly value: T;
|
|
1717
|
+
readonly repairs: readonly AuditFault[];
|
|
1718
|
+
}
|
|
1719
|
+
|
|
1580
1720
|
/**
|
|
1581
1721
|
* Describes a value declaratively — a declaration the shape builders build and
|
|
1582
1722
|
* the compilers turn into a guard, a parser, a JSON Schema, and a generator.
|
|
@@ -1586,7 +1726,7 @@ export declare interface ContractRefusal {
|
|
|
1586
1726
|
* element shape, an `ObjectShape` a map of them). {@link validateShape}
|
|
1587
1727
|
* enforces an acyclic graph within {@link COMPILE_DEPTH_LIMIT}.
|
|
1588
1728
|
*/
|
|
1589
|
-
export declare type ContractShape = StringShape | NumberShape | BooleanShape | NullShape | LiteralShape | ArrayShape | ObjectShape | UnionShape | OptionalShape | NullableShape | JSONShape | ShapeShape | RawShape;
|
|
1729
|
+
export declare type ContractShape = StringShape | NumberShape | BooleanShape | NullShape | LiteralShape | ArrayShape | ObjectShape | UnionShape | OptionalShape | NullableShape | JSONShape | ShapeShape | FunctionShape | UndefinedShape | InterfaceShape | RawShape;
|
|
1590
1730
|
|
|
1591
1731
|
/**
|
|
1592
1732
|
* Compiles a {@link ContractShape} into a {@link ContractInterface} — the
|
|
@@ -1618,7 +1758,7 @@ export declare type ContractShape = StringShape | NumberShape | BooleanShape | N
|
|
|
1618
1758
|
* to touch, so the failure arrives at the call the caller made — carrying the
|
|
1619
1759
|
* authoring door's own diagnosis, which this door adopts rather than rewraps.
|
|
1620
1760
|
* Every compiled member is self-contained, and the compiler this call builds
|
|
1621
|
-
* releases its working set
|
|
1761
|
+
* releases its working set after every member has compiled. The contract keeps
|
|
1622
1762
|
* part of the declaration even so: the auditor and reporter plans close over the
|
|
1623
1763
|
* leaf and array nodes they read their bounds from, and a contract with deferred
|
|
1624
1764
|
* members retains its declaration. Nothing the caller keeps reaches back into the
|
|
@@ -1628,7 +1768,7 @@ export declare type ContractShape = StringShape | NumberShape | BooleanShape | N
|
|
|
1628
1768
|
* diagnostics and generator refuse.
|
|
1629
1769
|
*
|
|
1630
1770
|
* @param shape - The shape to compile
|
|
1631
|
-
* @returns A contract bundling `schema` / `is` / `parse` / `audit` / `explain` / `generate`
|
|
1771
|
+
* @returns A contract bundling `schema` / `is` / `parse` / `audit` / `explain` / `generate` / `own`
|
|
1632
1772
|
*
|
|
1633
1773
|
* @example Compiling a contract
|
|
1634
1774
|
* ```ts
|
|
@@ -1740,8 +1880,10 @@ export declare function deriveRangeBounds(min: unknown, max: unknown): BoundsRea
|
|
|
1740
1880
|
* says.
|
|
1741
1881
|
*
|
|
1742
1882
|
* @remarks
|
|
1743
|
-
* Each line opens with the fault's path (or `value` at the root) and reason.
|
|
1744
|
-
*
|
|
1883
|
+
* Each line opens with the fault's path (or `value` at the root) and reason. A `hidden` fault says
|
|
1884
|
+
* the member is not enumerable and to send it as a plain data member. An `extra` fault carrying
|
|
1885
|
+
* `symbol` names the symbol key and lists no declared key; another `extra` fault lists its
|
|
1886
|
+
* parent's keys only when no array form sits at the parent and the declaring arms agree. A literal names candidates only where
|
|
1745
1887
|
* the declarations agree; lists are deduplicated and bounded. A received preview stays as written
|
|
1746
1888
|
* within PREVIEW_LIMIT and without control or line-separator characters; otherwise it is encoded
|
|
1747
1889
|
* through preview. Received, constraint, and limit details read only own fields. A `variant` or
|
|
@@ -1786,7 +1928,7 @@ export declare function describeFaults(faults: readonly AuditFault[], schema?: J
|
|
|
1786
1928
|
* carries code `random` and never the `generate` code, and {@link compileGenerator}
|
|
1787
1929
|
* rethrows it at whatever draw depth it happened instead of rotating to the next union
|
|
1788
1930
|
* variant. The diagnostic names the consuming shape category, the `[0, 1)` limit, and a
|
|
1789
|
-
* total non-coercing {@link preview} of the offending sample (or `threw`), so
|
|
1931
|
+
* total non-coercing {@link preview} of the offending sample (or `threw`), so an untrusted
|
|
1790
1932
|
* object runs no conversion hook while the diagnostic is built and a primitive symbol
|
|
1791
1933
|
* renders without consulting mutable `Symbol.prototype.toString`.
|
|
1792
1934
|
*
|
|
@@ -1859,7 +2001,7 @@ export declare type EntryCollectorFunction = (value: unknown, key: unknown) => v
|
|
|
1859
2001
|
* This is the package-wide runtime property view used by compiled object
|
|
1860
2002
|
* guards, parsers, reporters, schema inference, and owned schema cloning. It
|
|
1861
2003
|
* matches the object-key view serialized by `JSON.stringify`: inherited,
|
|
1862
|
-
* symbol, and non-enumerable properties are excluded.
|
|
2004
|
+
* symbol, and non-enumerable properties are excluded. An untrusted Proxy trap
|
|
1863
2005
|
* returns `undefined` rather than escaping.
|
|
1864
2006
|
*
|
|
1865
2007
|
* @param value - The object whose keys to snapshot
|
|
@@ -1942,6 +2084,19 @@ export declare function enumOf<const E extends Record<string, string | number>>(
|
|
|
1942
2084
|
*/
|
|
1943
2085
|
export declare function errorToMessage(error: unknown): string;
|
|
1944
2086
|
|
|
2087
|
+
/**
|
|
2088
|
+
* Replaces each DEL, C1 control, U+2028, and U+2029 in a text with its `\u` sequence.
|
|
2089
|
+
*
|
|
2090
|
+
* @param text - The text to rewrite
|
|
2091
|
+
* @returns The text with those characters as lowercase `\u` sequences
|
|
2092
|
+
*
|
|
2093
|
+
* @example
|
|
2094
|
+
* ```ts
|
|
2095
|
+
* escapeControls('a\u2028b') // 'a\\u2028b'
|
|
2096
|
+
* ```
|
|
2097
|
+
*/
|
|
2098
|
+
export declare function escapeControls(text: string): string;
|
|
2099
|
+
|
|
1945
2100
|
/**
|
|
1946
2101
|
* Escapes every regular-expression metacharacter in a text, so the text
|
|
1947
2102
|
* matches literally inside a larger `RegExp` source.
|
|
@@ -2024,15 +2179,18 @@ export declare function extractPath(fault: AuditFault): readonly string[];
|
|
|
2024
2179
|
export declare function extractSchema(schema: JSONSchema, path: readonly string[]): JSONSchema | undefined;
|
|
2025
2180
|
|
|
2026
2181
|
/**
|
|
2027
|
-
* Represents a key present on a value that its closed object shape does not declare
|
|
2182
|
+
* Represents a key present on a value that its closed object shape does not declare, or an own
|
|
2183
|
+
* key other than an index or `length` on a value its array shape describes.
|
|
2028
2184
|
*
|
|
2029
2185
|
* @remarks
|
|
2030
|
-
* The final path segment is the offending key,
|
|
2031
|
-
*
|
|
2186
|
+
* The final path segment is the offending key, or `symbol` names it: a symbol key adds no
|
|
2187
|
+
* segment, so its fault sits at the object or the array and `symbol` holds the key's preview. No value is
|
|
2188
|
+
* read or carried — an undeclared key faults on its presence alone.
|
|
2032
2189
|
*/
|
|
2033
2190
|
export declare interface ExtraFault {
|
|
2034
2191
|
readonly reason: 'extra';
|
|
2035
2192
|
readonly path: FieldPath;
|
|
2193
|
+
readonly symbol?: string;
|
|
2036
2194
|
}
|
|
2037
2195
|
|
|
2038
2196
|
/**
|
|
@@ -2066,7 +2224,8 @@ export declare function failure<E>(error: E): Failure<E>;
|
|
|
2066
2224
|
* @remarks
|
|
2067
2225
|
* A discriminated union on `reason`:
|
|
2068
2226
|
* - `'type'` — the value could not coerce to `expected` at all.
|
|
2069
|
-
* - `'missing'` — a required object property was absent
|
|
2227
|
+
* - `'missing'` — a required object property was absent, a required interface member
|
|
2228
|
+
* read `undefined`, or an array held a hole where its element shape admits `undefined`.
|
|
2070
2229
|
* - `'constraint'` — the value coerced to `expected` but violated one
|
|
2071
2230
|
* refinement (`min` / `max` / `pattern` / `date` / `integer`); `limit` carries the
|
|
2072
2231
|
* violated bound/pattern when applicable.
|
|
@@ -2140,9 +2299,9 @@ export declare const FAULT_KINDS: readonly FaultKind[];
|
|
|
2140
2299
|
* `explain` or `audit` report ever returns, frozen.
|
|
2141
2300
|
*
|
|
2142
2301
|
* @remarks
|
|
2143
|
-
* Bounds BOTH reports against
|
|
2302
|
+
* Bounds BOTH reports against untrusted input (a giant array, a wide record)
|
|
2144
2303
|
* — `compileReporter` and `compileAuditor` each collect faults in stable
|
|
2145
|
-
* pre-order and stop
|
|
2304
|
+
* pre-order and stop after this cap is reached, and every recursive call slices
|
|
2146
2305
|
* to it, so the report size (and the work to build it) stays finite and
|
|
2147
2306
|
* deterministic at every nesting level regardless of the input's size. Size a
|
|
2148
2307
|
* diagnostic surface off this constant and it bounds `audit` exactly as it
|
|
@@ -2163,9 +2322,9 @@ export declare const FAULT_TEXT_LIMIT = 2048;
|
|
|
2163
2322
|
* Names the refinement a {@link Fault} of reason `'constraint'` violates.
|
|
2164
2323
|
*
|
|
2165
2324
|
* @remarks
|
|
2166
|
-
* The vocabulary is `'min'`, `'max'`, `'pattern'`, `'date'`, and `'integer'`.
|
|
2325
|
+
* The vocabulary is `'min'`, `'over'`, `'max'`, `'under'`, `'pattern'`, `'date'`, and `'integer'`.
|
|
2167
2326
|
*/
|
|
2168
|
-
export declare type FaultConstraint = 'min' | 'max' | 'pattern' | 'date' | 'integer';
|
|
2327
|
+
export declare type FaultConstraint = 'min' | 'over' | 'max' | 'under' | 'pattern' | 'date' | 'integer';
|
|
2169
2328
|
|
|
2170
2329
|
/**
|
|
2171
2330
|
* Names the kind of value a {@link Fault} expected — the shape-projected counterpart of
|
|
@@ -2173,9 +2332,10 @@ export declare type FaultConstraint = 'min' | 'max' | 'pattern' | 'date' | 'inte
|
|
|
2173
2332
|
*
|
|
2174
2333
|
* @remarks
|
|
2175
2334
|
* The vocabulary is `'string'`, `'date'`, `'number'`, `'integer'`, `'boolean'`, `'null'`,
|
|
2176
|
-
* `'literal'`, `'array'`, `'object'`, `'union'`, `'json'`,
|
|
2335
|
+
* `'literal'`, `'array'`, `'object'`, `'union'`, `'json'`, `'shape'`, `'function'`, and
|
|
2336
|
+
* `'undefined'`.
|
|
2177
2337
|
*/
|
|
2178
|
-
export declare type FaultKind = 'string' | 'date' | 'number' | 'integer' | 'boolean' | 'null' | 'literal' | 'array' | 'object' | 'union' | 'json' | 'shape';
|
|
2338
|
+
export declare type FaultKind = 'string' | 'date' | 'number' | 'integer' | 'boolean' | 'null' | 'literal' | 'array' | 'object' | 'union' | 'json' | 'shape' | 'function' | 'undefined';
|
|
2179
2339
|
|
|
2180
2340
|
/**
|
|
2181
2341
|
* Retains a lazily built fault declaration without building shapes during module evaluation.
|
|
@@ -2236,6 +2396,13 @@ declare class FaultShaper {
|
|
|
2236
2396
|
}, false>, ObjectShape< {
|
|
2237
2397
|
reason: LiteralShape<readonly ["extra"]>;
|
|
2238
2398
|
path: UnionShape<readonly [StringShape, ArrayShape<StringShape>]>;
|
|
2399
|
+
}, false>, ObjectShape< {
|
|
2400
|
+
reason: LiteralShape<readonly ["extra"]>;
|
|
2401
|
+
path: UnionShape<readonly [StringShape, ArrayShape<StringShape>]>;
|
|
2402
|
+
symbol: StringShape;
|
|
2403
|
+
}, false>, ObjectShape< {
|
|
2404
|
+
reason: LiteralShape<readonly ["hidden"]>;
|
|
2405
|
+
path: UnionShape<readonly [StringShape, ArrayShape<StringShape>]>;
|
|
2239
2406
|
}, false>]>;
|
|
2240
2407
|
}
|
|
2241
2408
|
|
|
@@ -2266,6 +2433,28 @@ export declare interface FaultTextOptions {
|
|
|
2266
2433
|
*/
|
|
2267
2434
|
export declare type FieldPath = string | readonly string[];
|
|
2268
2435
|
|
|
2436
|
+
/**
|
|
2437
|
+
* Filters out the faults a union fault covers, keeping every fault that states a fact no form shows.
|
|
2438
|
+
*
|
|
2439
|
+
* @remarks
|
|
2440
|
+
* A `variant` or `oneOf` fault covers every fault beneath its path and every non-union fault at
|
|
2441
|
+
* its path, and never itself. A `hidden` fault and an `extra` fault carrying `symbol` are kept
|
|
2442
|
+
* whatever covers them, because each reports a member outside the enumerable view that no
|
|
2443
|
+
* form summary names.
|
|
2444
|
+
*
|
|
2445
|
+
* @param faults - The faults an audit reported
|
|
2446
|
+
* @returns The faults no cover prunes, in their order
|
|
2447
|
+
*
|
|
2448
|
+
* @example
|
|
2449
|
+
* ```ts
|
|
2450
|
+
* filterUncoveredFaults([
|
|
2451
|
+
* { reason: 'variant', path: [], variants: 2 },
|
|
2452
|
+
* { reason: 'extra', path: ['typo'] },
|
|
2453
|
+
* ]) // [{ reason: 'variant', path: [], variants: 2 }]
|
|
2454
|
+
* ```
|
|
2455
|
+
*/
|
|
2456
|
+
export declare function filterUncoveredFaults(faults: readonly AuditFault[]): readonly AuditFault[];
|
|
2457
|
+
|
|
2269
2458
|
/**
|
|
2270
2459
|
* Caps at `128` the string length {@link stringToFormat} attempts to classify, frozen.
|
|
2271
2460
|
*
|
|
@@ -2295,6 +2484,60 @@ export declare type FromGuards<G extends GuardsShape> = Readonly<{
|
|
|
2295
2484
|
[K in keyof G]: GuardType<G[K]>;
|
|
2296
2485
|
}>;
|
|
2297
2486
|
|
|
2487
|
+
/**
|
|
2488
|
+
* Describes a callable value — accepts every function, a class constructor included.
|
|
2489
|
+
*
|
|
2490
|
+
* @remarks
|
|
2491
|
+
* The compiled guard is `isFunction` and the parser returns the value by identity. JSON
|
|
2492
|
+
* carries no function, so the emitted schema `{ not: {}, format: 'function' }` admits no
|
|
2493
|
+
* JSON instance; `format` names the member for a reader, and `description` appears only
|
|
2494
|
+
* when one is authored. The generator returns one frozen function that returns
|
|
2495
|
+
* `undefined`. {@link Infer} resolves the shape to `(...args: never[]) => unknown`, which
|
|
2496
|
+
* accepts every function and refuses a call that passes an argument; a call with no
|
|
2497
|
+
* argument still typechecks.
|
|
2498
|
+
*
|
|
2499
|
+
* @example
|
|
2500
|
+
* ```ts
|
|
2501
|
+
* const declaration: FunctionShape = { category: 'function' }
|
|
2502
|
+
* createContract(declaration).is(encodeURI) // true
|
|
2503
|
+
* ```
|
|
2504
|
+
*/
|
|
2505
|
+
export declare interface FunctionShape {
|
|
2506
|
+
readonly category: 'function';
|
|
2507
|
+
readonly description?: string;
|
|
2508
|
+
}
|
|
2509
|
+
|
|
2510
|
+
/**
|
|
2511
|
+
* Builds a {@link FunctionShape}.
|
|
2512
|
+
*
|
|
2513
|
+
* @remarks
|
|
2514
|
+
* The guard accepts every callable and checks no arity: TypeScript admits a callback that
|
|
2515
|
+
* declares fewer parameters than its type, and `Function.length` undercounts rest and
|
|
2516
|
+
* defaulted parameters.
|
|
2517
|
+
*
|
|
2518
|
+
* @param options - Optional description
|
|
2519
|
+
* @returns A function-valued declaration
|
|
2520
|
+
*
|
|
2521
|
+
* @example
|
|
2522
|
+
* ```ts
|
|
2523
|
+
* const options = objectShape({ upgrade: optionalShape(functionShape()) })
|
|
2524
|
+
* ```
|
|
2525
|
+
*/
|
|
2526
|
+
export declare function functionShape(options?: FunctionShapeOptions): FunctionShape;
|
|
2527
|
+
|
|
2528
|
+
/**
|
|
2529
|
+
* Configures the description of a function-valued declaration.
|
|
2530
|
+
*
|
|
2531
|
+
* @example
|
|
2532
|
+
* ```ts
|
|
2533
|
+
* const options: FunctionShapeOptions = { description: 'Runs the schema migration' }
|
|
2534
|
+
* functionShape(options).description // 'Runs the schema migration'
|
|
2535
|
+
* ```
|
|
2536
|
+
*/
|
|
2537
|
+
export declare interface FunctionShapeOptions {
|
|
2538
|
+
readonly description?: string;
|
|
2539
|
+
}
|
|
2540
|
+
|
|
2298
2541
|
/**
|
|
2299
2542
|
* Caps at `32` the number of candidate-generation attempts for a constrained generated
|
|
2300
2543
|
* value, frozen.
|
|
@@ -2362,6 +2605,20 @@ export declare type GuardsShape = Readonly<Record<string, Guard<unknown>>>;
|
|
|
2362
2605
|
/** Extracts the guarded type `T` from a `Guard<T>`. */
|
|
2363
2606
|
export declare type GuardType<G> = G extends Guard<infer T> ? T : never;
|
|
2364
2607
|
|
|
2608
|
+
/**
|
|
2609
|
+
* Represents an own member outside the enumerable view that a closed or tail-shaped object
|
|
2610
|
+
* refuses.
|
|
2611
|
+
*
|
|
2612
|
+
* @remarks
|
|
2613
|
+
* The final path segment is the non-enumerable string key. A declared member reports this
|
|
2614
|
+
* fault in place of `missing`, and a tail-shaped object reports it for an undeclared one. The
|
|
2615
|
+
* correction is always to send the member as plain data; no value is read or carried.
|
|
2616
|
+
*/
|
|
2617
|
+
export declare interface HiddenFault {
|
|
2618
|
+
readonly reason: 'hidden';
|
|
2619
|
+
readonly path: FieldPath;
|
|
2620
|
+
}
|
|
2621
|
+
|
|
2365
2622
|
/**
|
|
2366
2623
|
* Invokes a predicate through the sanctioned never-throw boundary.
|
|
2367
2624
|
*
|
|
@@ -2394,7 +2651,7 @@ export declare function holds(callback: () => boolean): boolean;
|
|
|
2394
2651
|
* full union is a fixed point that can never shrink — the compiler would fan
|
|
2395
2652
|
* out until it aborts with TS2589. Bailing out lazily short-circuits that
|
|
2396
2653
|
* fixed point (the untaken branch is never instantiated) while every narrow
|
|
2397
|
-
* shape and every partial union still flows through the exact chain
|
|
2654
|
+
* shape and every partial union still flows through the exact following chain.
|
|
2398
2655
|
*
|
|
2399
2656
|
* The `ObjectShape` branch's `additionalProperties` guard (`[A] extends
|
|
2400
2657
|
* [boolean | ContractShape]`) is likewise wrapped in a tuple to stay
|
|
@@ -2405,7 +2662,7 @@ export declare function holds(callback: () => boolean): boolean;
|
|
|
2405
2662
|
* nesting. {@link InferIndex} and {@link InferOpenIndex} apply the identical
|
|
2406
2663
|
* tuple guard to their own `A` parameter for the same reason.
|
|
2407
2664
|
*/
|
|
2408
|
-
export declare type Infer<S extends ContractShape> = [ContractShape] extends [S] ? unknown : S extends ShapeShape ? ContractShape : S extends StringShape ? string : S extends NumberShape ? number : S extends BooleanShape ? boolean : S extends NullShape ? null : S extends {
|
|
2665
|
+
export declare type Infer<S extends ContractShape> = [ContractShape] extends [S] ? unknown : S extends ShapeShape ? ContractShape : S extends FunctionShape ? (...args: never[]) => unknown : S extends StringShape ? string : S extends NumberShape ? number : S extends BooleanShape ? boolean : S extends NullShape ? null : S extends {
|
|
2409
2666
|
readonly category: 'literal';
|
|
2410
2667
|
readonly values: infer V;
|
|
2411
2668
|
} ? V extends ReadonlyArray<infer L> ? L : never : S extends {
|
|
@@ -2420,7 +2677,18 @@ export declare type Infer<S extends ContractShape> = [ContractShape] extends [S]
|
|
|
2420
2677
|
} ? I extends ContractShape ? Infer<I> | undefined : never : S extends {
|
|
2421
2678
|
readonly category: 'nullable';
|
|
2422
2679
|
readonly inner: infer I;
|
|
2423
|
-
} ? I extends ContractShape ? Infer<I> | null : never : S extends JSONShape ? JSONValue :
|
|
2680
|
+
} ? I extends ContractShape ? Infer<I> | null : never : S extends JSONShape ? JSONValue : S extends UndefinedShape ? undefined : S extends InterfaceShape<infer P> ? Readonly<{
|
|
2681
|
+
[K in keyof P as P[K] extends {
|
|
2682
|
+
readonly category: 'optional';
|
|
2683
|
+
} ? never : K]: Infer<P[K]>;
|
|
2684
|
+
} & {
|
|
2685
|
+
[K in keyof P as P[K] extends {
|
|
2686
|
+
readonly category: 'optional';
|
|
2687
|
+
} ? K : never]?: P[K] extends {
|
|
2688
|
+
readonly category: 'optional';
|
|
2689
|
+
readonly inner: infer I;
|
|
2690
|
+
} ? I extends ContractShape ? Infer<I> | undefined : never : never;
|
|
2691
|
+
}> : unknown;
|
|
2424
2692
|
|
|
2425
2693
|
/**
|
|
2426
2694
|
* Caps by default at `256` the number of object properties / array elements {@link
|
|
@@ -2437,7 +2705,7 @@ export declare const INFER_BREADTH_LIMIT = 256;
|
|
|
2437
2705
|
* Caps at `32` the object/array nesting depth {@link valueToSchema} walks, frozen.
|
|
2438
2706
|
*
|
|
2439
2707
|
* @remarks
|
|
2440
|
-
* Bounds inference against
|
|
2708
|
+
* Bounds inference against untrusted or cyclic runtime input — after the
|
|
2441
2709
|
* remaining depth budget reaches zero, inference stops descending and emits
|
|
2442
2710
|
* the empty accept-anything schema `{}` for that branch instead of recursing
|
|
2443
2711
|
* further. LOWERABLE per call through {@link ValueToSchemaLimits.depth}; a
|
|
@@ -2557,7 +2825,7 @@ export declare type InferOpenIndex<A extends boolean | ContractShape> = [A] exte
|
|
|
2557
2825
|
* Fires only when ALL of: every value is the same primitive kind (all string
|
|
2558
2826
|
* or all FINITE number through {@link isFiniteNumber} — any `null`/boolean/mixed
|
|
2559
2827
|
* slot never qualifies, and a slot containing `NaN` / `±Infinity` never
|
|
2560
|
-
* qualifies either,
|
|
2828
|
+
* qualifies either, because {@link canonicalStringify} collapses `NaN` to
|
|
2561
2829
|
* `'null'` and would otherwise risk an invalid-JSON `enum`); at least 2
|
|
2562
2830
|
* values are given; the distinct-by-{@link canonicalStringify} count is LESS
|
|
2563
2831
|
* than the value count (repetition required — separates a categorical column
|
|
@@ -2621,10 +2889,76 @@ export declare function instanceOf<C extends abstract new (...args: never) => ob
|
|
|
2621
2889
|
*
|
|
2622
2890
|
* @param options - Optional bounds and `description` (no `integer` key)
|
|
2623
2891
|
* @returns An integer number shape
|
|
2624
|
-
* @throws {ContractError} When a present bound is not finite
|
|
2892
|
+
* @throws {ContractError} When an option key is unknown, a present bound is not finite, or no whole number satisfies the bounds
|
|
2625
2893
|
*/
|
|
2626
2894
|
export declare function integerShape(options?: Omit<NumberShapeOptions, 'integer'>): NumberShape;
|
|
2627
2895
|
|
|
2896
|
+
/**
|
|
2897
|
+
* Describes an implementation — a non-array object or a function that carries each declared member.
|
|
2898
|
+
*
|
|
2899
|
+
* @remarks
|
|
2900
|
+
* The compiled walk reads each declared member one time through `Reflect.get`, so an inherited
|
|
2901
|
+
* member and a prototype accessor satisfy the shape, and it never enumerates an undeclared
|
|
2902
|
+
* member. A member wrapped in {@link OptionalShape} passes when it reads `undefined`; every
|
|
2903
|
+
* other member that reads `undefined` faults `'missing'` unless its shape admits `undefined`.
|
|
2904
|
+
* The guard is the audit returning no fault, and the parser returns the value by identity when
|
|
2905
|
+
* the guard holds, so no member is copied, coerced, or filled. The emitted schema is
|
|
2906
|
+
* `{ type: 'object', format: 'interface', properties, required, additionalProperties: true }`.
|
|
2907
|
+
* The generator returns a frozen plain record of generated members. A member may not carry a
|
|
2908
|
+
* `default`, and the shape may not sit under a union at any depth; both refuse with code
|
|
2909
|
+
* `placement`.
|
|
2910
|
+
*
|
|
2911
|
+
* @example
|
|
2912
|
+
* ```ts
|
|
2913
|
+
* const declaration: InterfaceShape = {
|
|
2914
|
+
* category: 'interface',
|
|
2915
|
+
* members: { get: { category: 'function' } },
|
|
2916
|
+
* }
|
|
2917
|
+
* createContract(declaration).is(new Map()) // true
|
|
2918
|
+
* ```
|
|
2919
|
+
*/
|
|
2920
|
+
export declare interface InterfaceShape<P extends Readonly<Record<string, ContractShape>> = Readonly<Record<string, ContractShape>>> {
|
|
2921
|
+
readonly category: 'interface';
|
|
2922
|
+
readonly members: P;
|
|
2923
|
+
readonly description?: string;
|
|
2924
|
+
}
|
|
2925
|
+
|
|
2926
|
+
/**
|
|
2927
|
+
* Builds an {@link InterfaceShape} from a member map.
|
|
2928
|
+
*
|
|
2929
|
+
* @remarks
|
|
2930
|
+
* Declare the members a consumer calls or reads on an implementation it does not own, such as a
|
|
2931
|
+
* store or a signal: a class instance, a function, or an object whose prototype carries the
|
|
2932
|
+
* members passes, and an undeclared member is never read. Wrap a member in
|
|
2933
|
+
* {@link optionalShape} to let it read `undefined`. Take {@link objectShape} for a plain data
|
|
2934
|
+
* record.
|
|
2935
|
+
*
|
|
2936
|
+
* @param members - Map of member names to child shapes
|
|
2937
|
+
* @param options - Optional description
|
|
2938
|
+
* @returns An interface shape
|
|
2939
|
+
* @throws {ContractError} When `members` is not a plain record, a member carries a default, or an option key is unread
|
|
2940
|
+
*
|
|
2941
|
+
* @example
|
|
2942
|
+
* ```ts
|
|
2943
|
+
* const store = interfaceShape({ get: functionShape(), set: functionShape(), delete: functionShape() })
|
|
2944
|
+
* createContract(store).is(new Map()) // true
|
|
2945
|
+
* ```
|
|
2946
|
+
*/
|
|
2947
|
+
export declare function interfaceShape<P extends Readonly<Record<string, ContractShape>>>(members: P, options?: InterfaceShapeOptions): InterfaceShape<P>;
|
|
2948
|
+
|
|
2949
|
+
/**
|
|
2950
|
+
* Configures the description of an implementation declaration.
|
|
2951
|
+
*
|
|
2952
|
+
* @example
|
|
2953
|
+
* ```ts
|
|
2954
|
+
* const options: InterfaceShapeOptions = { description: 'The session store' }
|
|
2955
|
+
* interfaceShape({}, options).description // 'The session store'
|
|
2956
|
+
* ```
|
|
2957
|
+
*/
|
|
2958
|
+
export declare interface InterfaceShapeOptions {
|
|
2959
|
+
readonly description?: string;
|
|
2960
|
+
}
|
|
2961
|
+
|
|
2628
2962
|
/** Intersects the types guarded by a tuple of guards — backs `intersectionOf`. */
|
|
2629
2963
|
export declare type IntersectionFromGuards<Gs extends ReadonlyArray<Guard<unknown>>> = UnionToIntersection<GuardType<Gs[number]>>;
|
|
2630
2964
|
|
|
@@ -2667,7 +3001,7 @@ export declare function intersectionOf(...predicates: ReadonlyArray<(value: unkn
|
|
|
2667
3001
|
* installed at the moment THIS module evaluated, and reading it later, at the
|
|
2668
3002
|
* call site, is reading whatever the caller most recently installed. "Before any
|
|
2669
3003
|
* caller code runs" is the tempting phrasing and it is false in exactly the case
|
|
2670
|
-
* the limit
|
|
3004
|
+
* the following limit names, so it is not used.
|
|
2671
3005
|
*
|
|
2672
3006
|
* The limit that follows, stated as a limit rather than as a guarantee: capture
|
|
2673
3007
|
* is only as early as this package's own evaluation. A consumer module that
|
|
@@ -2678,7 +3012,7 @@ export declare function intersectionOf(...predicates: ReadonlyArray<(value: unkn
|
|
|
2678
3012
|
* package wholesale rather than bother with the table, so it is named here
|
|
2679
3013
|
* instead of defended.
|
|
2680
3014
|
*
|
|
2681
|
-
* Membership rule, stated so a reviewer can apply it and
|
|
3015
|
+
* Membership rule, stated so a reviewer can apply it and an added call site knows
|
|
2682
3016
|
* where to go: **every host operation this package dispatches by name whose
|
|
2683
3017
|
* result a published answer depends on.** That admits statics, constructors and
|
|
2684
3018
|
* namespaces, and — this is the part the earlier wording got wrong by writing
|
|
@@ -2758,11 +3092,13 @@ export declare const INTRINSICS: Readonly<{
|
|
|
2758
3092
|
prototype: (o: any) => any;
|
|
2759
3093
|
/** Captures `Object.getOwnPropertySymbols` — the own-symbol population. */
|
|
2760
3094
|
symbols: (o: any) => symbol[];
|
|
3095
|
+
/** Captures `Object.getOwnPropertyNames` — the own string-key population, enumerable or not. */
|
|
3096
|
+
names: (o: any) => string[];
|
|
2761
3097
|
/** Captures `Object.prototype` — the realm-local plain-record prototype identity. */
|
|
2762
3098
|
base: Object;
|
|
2763
3099
|
/**
|
|
2764
3100
|
* Captures the proxy-visible operations, grouped because that is what separates them:
|
|
2765
|
-
* each reports the trap's exact answer where `Object`'s flat peer
|
|
3101
|
+
* each reports the trap's exact answer where `Object`'s preceding flat peer
|
|
2766
3102
|
* reports the target's.
|
|
2767
3103
|
*
|
|
2768
3104
|
* @remarks
|
|
@@ -2848,6 +3184,11 @@ export declare const INTRINSICS: Readonly<{
|
|
|
2848
3184
|
order: (compareFn?: ((a: any, b: any) => number) | undefined) => any[];
|
|
2849
3185
|
/** Captures `Array.prototype.some` for short-circuit membership checks. */
|
|
2850
3186
|
some: (predicate: (value: any, index: number, array: any[]) => unknown, thisArg?: any) => boolean;
|
|
3187
|
+
/** Captures `Array.prototype.every` for short-circuit checks that every entry passes. */
|
|
3188
|
+
every: {
|
|
3189
|
+
<S extends any>(predicate: (value: any, index: number, array: any[]) => value is S, thisArg?: any): this is S[];
|
|
3190
|
+
(predicate: (value: any, index: number, array: any[]) => unknown, thisArg?: any): boolean;
|
|
3191
|
+
};
|
|
2851
3192
|
/** Captures `Array.prototype.findIndex`, including reads of sparse positions. */
|
|
2852
3193
|
find: (predicate: (value: any, index: number, obj: any[]) => unknown, thisArg?: any) => number;
|
|
2853
3194
|
/** Captures `Array.prototype.forEach` for indexed visits of owned arrays. */
|
|
@@ -2888,6 +3229,8 @@ export declare const INTRINSICS: Readonly<{
|
|
|
2888
3229
|
indices: () => ArrayIterator<number>;
|
|
2889
3230
|
/** Captures the native array iterator advance operation. */
|
|
2890
3231
|
advance: any;
|
|
3232
|
+
/** Captures `String.prototype.slice` — the window a preview encodes, dispatched through `apply`. */
|
|
3233
|
+
slice: (start?: number, end?: number) => string;
|
|
2891
3234
|
/** Captures `Array.prototype.join` — text assembly from derived parts. */
|
|
2892
3235
|
join: (separator?: string) => string;
|
|
2893
3236
|
/** Captures `Function.prototype.bind` for a receiver-bound host operation. */
|
|
@@ -3040,15 +3383,19 @@ export declare function isAsyncIterable<T = unknown>(value: unknown): value is A
|
|
|
3040
3383
|
* Determines whether a value is exactly one {@link AuditFault}.
|
|
3041
3384
|
*
|
|
3042
3385
|
* @remarks
|
|
3043
|
-
* Every {@link Fault}, and the undeclared-key
|
|
3386
|
+
* Every {@link Fault}, and the undeclared-key and hidden-key faults an audit adds: `extra` with
|
|
3387
|
+
* exactly `reason` and `path`, or with a string `symbol` beside them, and `hidden` with exactly
|
|
3388
|
+
* `reason` and `path`.
|
|
3044
3389
|
*
|
|
3045
3390
|
* @param value - The value to inspect
|
|
3046
3391
|
* @returns True if the value is a well-formed audit fault; false otherwise
|
|
3047
3392
|
*
|
|
3048
3393
|
* @example
|
|
3049
3394
|
* ```ts
|
|
3050
|
-
* isAuditFault({ reason: 'extra', path: ['a'] })
|
|
3051
|
-
* isAuditFault({})
|
|
3395
|
+
* isAuditFault({ reason: 'extra', path: ['a'] }) // true
|
|
3396
|
+
* isAuditFault({ reason: 'extra', path: [], symbol: 'Symbol(tag)' }) // true
|
|
3397
|
+
* isAuditFault({ reason: 'hidden', path: ['note'] }) // true
|
|
3398
|
+
* isAuditFault({}) // false
|
|
3052
3399
|
* ```
|
|
3053
3400
|
*/
|
|
3054
3401
|
export declare function isAuditFault(value: unknown): value is AuditFault;
|
|
@@ -3152,6 +3499,26 @@ export declare function isBoundedJSONRecord(value: unknown): value is JSONRecord
|
|
|
3152
3499
|
*/
|
|
3153
3500
|
export declare function isBoundedJSONValue(value: unknown): value is JSONValue;
|
|
3154
3501
|
|
|
3502
|
+
/**
|
|
3503
|
+
* Determines whether a value is an `Error` whose `code` is a string.
|
|
3504
|
+
*
|
|
3505
|
+
* @remarks
|
|
3506
|
+
* Reads `code` through one `Reflect.get` call inside {@link holds}, so a throwing getter answers
|
|
3507
|
+
* false and no member is read twice.
|
|
3508
|
+
*
|
|
3509
|
+
* @param value - The value to inspect
|
|
3510
|
+
* @returns True if the value is an `Error` and its `code` reads as a string; false otherwise
|
|
3511
|
+
*
|
|
3512
|
+
* @example
|
|
3513
|
+
* ```ts
|
|
3514
|
+
* isCodedError(Object.assign(new Error('missing'), { code: 'ENOENT' })) // true
|
|
3515
|
+
* isCodedError(new Error('plain')) // false
|
|
3516
|
+
* ```
|
|
3517
|
+
*/
|
|
3518
|
+
export declare function isCodedError(value: unknown): value is Error & {
|
|
3519
|
+
readonly code: string;
|
|
3520
|
+
};
|
|
3521
|
+
|
|
3155
3522
|
/**
|
|
3156
3523
|
* Determines whether a value can be used as a `new`-target constructor.
|
|
3157
3524
|
*
|
|
@@ -3599,7 +3966,7 @@ export declare function isJSONPrimitive(value: unknown): value is JSONPrimitive;
|
|
|
3599
3966
|
* instances, class instances, `NaN`, and `±Infinity`. Arrays and plain records
|
|
3600
3967
|
* are walked with an ancestor set so recursive input fails instead of hanging.
|
|
3601
3968
|
* The whole walk runs inside `holds`, as `.claude/rules/patterns.md`
|
|
3602
|
-
* § Validation and contracts requires:
|
|
3969
|
+
* § Validation and contracts requires: an untrusted getter on a
|
|
3603
3970
|
* record property, or a revoked `Proxy` anywhere in the structure, is caught
|
|
3604
3971
|
* and yields `false` instead of escaping as a thrown error.
|
|
3605
3972
|
*
|
|
@@ -3890,12 +4257,14 @@ export declare function isPromiseLike<T = unknown>(value: unknown): value is Pro
|
|
|
3890
4257
|
* The total form of the shared {@link matchesRecordBrand} rule, and the only
|
|
3891
4258
|
* one a guard may use: the whole brand runs inside `holds`, as
|
|
3892
4259
|
* `.claude/rules/patterns.md` § Validation and contracts requires, so a
|
|
3893
|
-
* revoked `Proxy` or
|
|
4260
|
+
* revoked `Proxy` or an untrusted `getPrototypeOf` trap answers `false` instead of
|
|
3894
4261
|
* escaping as a thrown error. Use instead of {@link isObject} to distinguish a
|
|
3895
4262
|
* plain `{}` / `Object.create(null)` — or a plain object from another realm,
|
|
3896
4263
|
* whose prototype is that realm's `Object.prototype` — from arrays, `Date`,
|
|
3897
4264
|
* `Map`, and class instances, including a class whose prototype a caller
|
|
3898
|
-
* reparented to `null`.
|
|
4265
|
+
* reparented to `null`. For a value another package or the host returns, such as a
|
|
4266
|
+
* socket or a store, guard the members you read with {@link objectOf} or declare them
|
|
4267
|
+
* with {@link interfaceShape}.
|
|
3899
4268
|
*
|
|
3900
4269
|
* @param value - The value to inspect
|
|
3901
4270
|
* @returns True if the value is a plain record; false otherwise
|
|
@@ -3915,7 +4284,7 @@ export declare function isRecord(value: unknown): value is Record<string, unknow
|
|
|
3915
4284
|
* @remarks
|
|
3916
4285
|
* A total native internal-slot brand check rather than a property read: it accepts a
|
|
3917
4286
|
* genuine pattern from this realm and from another, and refuses a proxy or a hand-built
|
|
3918
|
-
*
|
|
4287
|
+
* fake without reading an advertised field.
|
|
3919
4288
|
*
|
|
3920
4289
|
* @param value - The value to inspect
|
|
3921
4290
|
* @returns True if the value is a `RegExp`; false otherwise
|
|
@@ -3928,6 +4297,23 @@ export declare function isRecord(value: unknown): value is Record<string, unknow
|
|
|
3928
4297
|
*/
|
|
3929
4298
|
export declare function isRegExp(value: unknown): value is RegExp;
|
|
3930
4299
|
|
|
4300
|
+
/**
|
|
4301
|
+
* Determines whether a value is a primitive number that is an integer within the safe range.
|
|
4302
|
+
*
|
|
4303
|
+
* @remarks
|
|
4304
|
+
* Answers `Number.isSafeInteger`: `-0` passes, and no value is coerced.
|
|
4305
|
+
*
|
|
4306
|
+
* @param value - The value to inspect
|
|
4307
|
+
* @returns True if the value is an integer from `Number.MIN_SAFE_INTEGER` to `Number.MAX_SAFE_INTEGER`; false otherwise
|
|
4308
|
+
*
|
|
4309
|
+
* @example
|
|
4310
|
+
* ```ts
|
|
4311
|
+
* isSafeInteger(42) // true
|
|
4312
|
+
* isSafeInteger(Number.MAX_SAFE_INTEGER + 1) // false
|
|
4313
|
+
* ```
|
|
4314
|
+
*/
|
|
4315
|
+
export declare function isSafeInteger(value: unknown): value is number;
|
|
4316
|
+
|
|
3931
4317
|
/** Determines whether a value is a `Set`.
|
|
3932
4318
|
*
|
|
3933
4319
|
* @param value - The value to inspect
|
|
@@ -4200,7 +4586,7 @@ export declare const JSON_SCHEMA_TYPES: readonly JSONSchemaType[];
|
|
|
4200
4586
|
* permanently. Success replays the exact frozen root; failure rethrows the
|
|
4201
4587
|
* exact class-owned error. Nonredirectable terminal failure releases partial
|
|
4202
4588
|
* traversal working state while retaining the source and exact error. Reentry
|
|
4203
|
-
*
|
|
4589
|
+
* invalidates the active operation and every later call with one shared cause-free
|
|
4204
4590
|
* error.
|
|
4205
4591
|
*
|
|
4206
4592
|
* @param value - The unknown value to retain for cloning
|
|
@@ -4250,7 +4636,7 @@ export declare interface JSONClonerInterface {
|
|
|
4250
4636
|
* loaded and read every diagnostic option as an own property, so terminal settlement
|
|
4251
4637
|
* stays nonredirectable against a replaced intrinsic and against a polluted prototype
|
|
4252
4638
|
* alike. Active reentry permanently settles the instance with one exact cause-free
|
|
4253
|
-
* `clone`
|
|
4639
|
+
* `clone` refusal shared by the nested call, the outer call, and every later call.
|
|
4254
4640
|
*
|
|
4255
4641
|
* @param budget - Remaining nodes shared with an enclosing ownership operation; omitted for an independent snapshot
|
|
4256
4642
|
* @returns The settled JSON snapshot
|
|
@@ -4296,9 +4682,11 @@ export declare type JSONRecord = {
|
|
|
4296
4682
|
*
|
|
4297
4683
|
* @remarks
|
|
4298
4684
|
* Intentionally lean (not the full ~50-keyword vocabulary): it carries only the
|
|
4299
|
-
* keywords
|
|
4300
|
-
*
|
|
4301
|
-
*
|
|
4685
|
+
* keywords `compileSchema` emits and the `format` the {@link stringToFormat} /
|
|
4686
|
+
* {@link samplesToFormat} inference heuristics (`valueToSchema` / `samplesToSchema`)
|
|
4687
|
+
* emit. `compileSchema` emits `format` for a date string (`'date'`) and a function
|
|
4688
|
+
* shape (`'function'`), and `not` only as the empty schema `{}`, which no JSON
|
|
4689
|
+
* instance satisfies; {@link RawShape} admits `not` in that form alone.
|
|
4302
4690
|
* Recursive through `items` / `properties` / `additionalProperties` / `anyOf` /
|
|
4303
4691
|
* `oneOf`. {@link createContract} owns and validates developer-authored shape
|
|
4304
4692
|
* graphs; cycles and nesting past {@link COMPILE_DEPTH_LIMIT} fail with a coded
|
|
@@ -4315,6 +4703,8 @@ export declare interface JSONSchema {
|
|
|
4315
4703
|
readonly format?: string;
|
|
4316
4704
|
readonly minimum?: number;
|
|
4317
4705
|
readonly maximum?: number;
|
|
4706
|
+
readonly exclusiveMinimum?: number;
|
|
4707
|
+
readonly exclusiveMaximum?: number;
|
|
4318
4708
|
readonly minItems?: number;
|
|
4319
4709
|
readonly maxItems?: number;
|
|
4320
4710
|
readonly items?: JSONSchema;
|
|
@@ -4323,6 +4713,7 @@ export declare interface JSONSchema {
|
|
|
4323
4713
|
readonly additionalProperties?: boolean | JSONSchema;
|
|
4324
4714
|
readonly anyOf?: readonly JSONSchema[];
|
|
4325
4715
|
readonly oneOf?: readonly JSONSchema[];
|
|
4716
|
+
readonly not?: JSONSchema;
|
|
4326
4717
|
}
|
|
4327
4718
|
|
|
4328
4719
|
/** Lists the seven standard JSON Schema `type` names. */
|
|
@@ -4377,7 +4768,7 @@ export declare interface JSONShapeOptions {
|
|
|
4377
4768
|
*
|
|
4378
4769
|
* @remarks
|
|
4379
4770
|
* The static type admits any `number` because TypeScript cannot express
|
|
4380
|
-
* finiteness. The {@link isJSONValue} guard rejects `NaN` and `±Infinity`
|
|
4771
|
+
* finiteness. The {@link isJSONValue} guard rejects `NaN` and `±Infinity` because
|
|
4381
4772
|
* they have no JSON representation.
|
|
4382
4773
|
*
|
|
4383
4774
|
* @example
|
|
@@ -4387,6 +4778,26 @@ export declare interface JSONShapeOptions {
|
|
|
4387
4778
|
*/
|
|
4388
4779
|
export declare type JSONValue = JSONPrimitive | readonly JSONValue[] | JSONRecord;
|
|
4389
4780
|
|
|
4781
|
+
/**
|
|
4782
|
+
* Caps at `4` the number of key plans one compiled closed-object guard keeps, frozen.
|
|
4783
|
+
*
|
|
4784
|
+
* @remarks
|
|
4785
|
+
* A compiled closed-object guard answers a value through the full key walk and,
|
|
4786
|
+
* after a walk that accepts, keeps that value's key order as a plan: one
|
|
4787
|
+
* {@link KeyStep} entry per key, in order. A later value whose own enumerable keys
|
|
4788
|
+
* arrive in a kept order is answered by asking each step's guard in turn, with
|
|
4789
|
+
* no presence or vocabulary question. The guard learns only from an accepted
|
|
4790
|
+
* walk, never evicts, and stops learning at this count, so the plans it keeps
|
|
4791
|
+
* are those of the earliest accepted key orders. Every other key order takes the
|
|
4792
|
+
* full walk. Both paths answer identically; only the cost differs.
|
|
4793
|
+
*
|
|
4794
|
+
* @example
|
|
4795
|
+
* ```ts
|
|
4796
|
+
* KEY_PLAN_LIMIT // 4
|
|
4797
|
+
* ```
|
|
4798
|
+
*/
|
|
4799
|
+
export declare const KEY_PLAN_LIMIT = 4;
|
|
4800
|
+
|
|
4390
4801
|
/**
|
|
4391
4802
|
* Builds a guard that accepts values that are own keys of the provided object.
|
|
4392
4803
|
*
|
|
@@ -4409,6 +4820,22 @@ export declare type JSONValue = JSONPrimitive | readonly JSONValue[] | JSONRecor
|
|
|
4409
4820
|
*/
|
|
4410
4821
|
export declare function keyOf<const O extends Readonly<Record<PropertyKey, unknown>>>(value: O): Guard<keyof O>;
|
|
4411
4822
|
|
|
4823
|
+
/**
|
|
4824
|
+
* Represents one step of a key plan: a declared key and the compiled guard its member answers to.
|
|
4825
|
+
*
|
|
4826
|
+
* @remarks
|
|
4827
|
+
* A compiled closed-object guard keeps one plan per accepted key order, one step per key in that
|
|
4828
|
+
* order, and answers a later value in the same order by asking each step's guard.
|
|
4829
|
+
*
|
|
4830
|
+
* {@link buildKeyPlan} returns a plan of these.
|
|
4831
|
+
*/
|
|
4832
|
+
export declare interface KeyStep {
|
|
4833
|
+
/** Holds the declared key the step reads. */
|
|
4834
|
+
readonly key: string;
|
|
4835
|
+
/** Holds the compiled guard the member under the key must satisfy. */
|
|
4836
|
+
readonly guard: Guard<unknown>;
|
|
4837
|
+
}
|
|
4838
|
+
|
|
4412
4839
|
/**
|
|
4413
4840
|
* Defers guard creation until first use by calling `thunk()` on every
|
|
4414
4841
|
* invocation.
|
|
@@ -4423,7 +4850,7 @@ export declare function keyOf<const O extends Readonly<Record<PropertyKey, unkno
|
|
|
4423
4850
|
* Each lazy guard tracks its active invocation depth. An invocation that would
|
|
4424
4851
|
* exceed {@link GUARD_DEPTH_LIMIT} returns `false` before resolving `thunk`; the
|
|
4425
4852
|
* counter always unwinds after the contained call, so one deep or cyclic input
|
|
4426
|
-
* cannot
|
|
4853
|
+
* cannot corrupt later guard calls.
|
|
4427
4854
|
*
|
|
4428
4855
|
* @param thunk - The factory producing the guard to apply, called on every invocation
|
|
4429
4856
|
* @returns A guard deferring each call to the thunk's guard
|
|
@@ -4570,6 +4997,47 @@ export declare function mapOf(keyPredicate: (value: unknown) => boolean, valuePr
|
|
|
4570
4997
|
*/
|
|
4571
4998
|
export declare function matchesCalendarDate(value: string): boolean;
|
|
4572
4999
|
|
|
5000
|
+
/**
|
|
5001
|
+
* Checks whether no number satisfies a set of number bounds.
|
|
5002
|
+
*
|
|
5003
|
+
* @remarks
|
|
5004
|
+
* Compares the bounds as real numbers: `min` and `max` admit their own value, and `over` and
|
|
5005
|
+
* `under` admit only a value beyond theirs. With `integer: true` a whole number must also lie
|
|
5006
|
+
* between them. An absent bound constrains nothing.
|
|
5007
|
+
*
|
|
5008
|
+
* @param bounds - The bounds to check
|
|
5009
|
+
* @returns True if no number satisfies the bounds; false otherwise
|
|
5010
|
+
*
|
|
5011
|
+
* @example
|
|
5012
|
+
* ```ts
|
|
5013
|
+
* matchesEmptyRange({ over: 1, under: 1 }) // true
|
|
5014
|
+
* matchesEmptyRange({ min: 1, max: 1 }) // false
|
|
5015
|
+
* matchesEmptyRange({ over: 0, under: 1, integer: true }) // true
|
|
5016
|
+
* ```
|
|
5017
|
+
*/
|
|
5018
|
+
export declare function matchesEmptyRange(bounds: NumberShapeOptions): boolean;
|
|
5019
|
+
|
|
5020
|
+
/**
|
|
5021
|
+
* Checks whether an object owns no key outside the enumerable string keys already read from it.
|
|
5022
|
+
*
|
|
5023
|
+
* @remarks
|
|
5024
|
+
* Counts the own string keys, enumerable or not, against the key list and requires no own
|
|
5025
|
+
* symbol key. A key a `Proxy` lists among its own keys with no descriptor counts as own.
|
|
5026
|
+
* Thrown when the object's own-key reflection throws, so call it inside a boundary.
|
|
5027
|
+
*
|
|
5028
|
+
* @param value - The object whose own keys to count
|
|
5029
|
+
* @param keys - The object's own enumerable string keys, as `Object.keys` returned them
|
|
5030
|
+
* @returns True if the object owns no other key; false otherwise
|
|
5031
|
+
*
|
|
5032
|
+
* @example
|
|
5033
|
+
* ```ts
|
|
5034
|
+
* const value = { id: 'a' }
|
|
5035
|
+
* matchesEnumerableKeys(value, Object.keys(value)) // true
|
|
5036
|
+
* matchesEnumerableKeys(Object.defineProperty(value, 'secret', { value: 1 }), ['id']) // false
|
|
5037
|
+
* ```
|
|
5038
|
+
*/
|
|
5039
|
+
export declare function matchesEnumerableKeys(value: object, keys: readonly string[]): boolean;
|
|
5040
|
+
|
|
4573
5041
|
/**
|
|
4574
5042
|
* Determines whether an object holds exactly the named own keys.
|
|
4575
5043
|
*
|
|
@@ -4623,7 +5091,7 @@ export declare function matchesISOInstant(value: string): boolean;
|
|
|
4623
5091
|
* the alias already fit. Arrays are traversed through their reflected
|
|
4624
5092
|
* own-index population, so sparse work is proportional to populated entries
|
|
4625
5093
|
* rather than advertised length. Every observable operation is contained;
|
|
4626
|
-
*
|
|
5094
|
+
* untrusted or contradictory reads return `false`.
|
|
4627
5095
|
*
|
|
4628
5096
|
* The walk carries a settled-depth memo beside its active-path set: a
|
|
4629
5097
|
* container that fit at depth `d` also fits at any depth `<= d`, because every
|
|
@@ -4686,6 +5154,24 @@ export declare function matchesJSONValue(entry: unknown, ancestors: WeakSet<obje
|
|
|
4686
5154
|
left: number;
|
|
4687
5155
|
}): entry is JSONValue;
|
|
4688
5156
|
|
|
5157
|
+
/**
|
|
5158
|
+
* Checks whether a key plan answers the key list bound as `this`.
|
|
5159
|
+
*
|
|
5160
|
+
* @remarks
|
|
5161
|
+
* Passed with the key list as the `thisArg` argument to the captured `findIndex` member over a list of
|
|
5162
|
+
* plans. A plan answers a key list holding the same keys in the same order, so a prefix and a
|
|
5163
|
+
* reordering both miss.
|
|
5164
|
+
*
|
|
5165
|
+
* @param plan - The key plan to compare
|
|
5166
|
+
* @returns True if the plan's keys equal the bound list in order; false otherwise
|
|
5167
|
+
*
|
|
5168
|
+
* @example
|
|
5169
|
+
* ```ts
|
|
5170
|
+
* matchesKeyPlan.call(['id'], [{ key: 'id', guard: isString }]) // true
|
|
5171
|
+
* ```
|
|
5172
|
+
*/
|
|
5173
|
+
export declare function matchesKeyPlan(this: readonly string[], plan: readonly KeyStep[]): boolean;
|
|
5174
|
+
|
|
4689
5175
|
/**
|
|
4690
5176
|
* Determines whether a repair `parse` made kept everything the value said.
|
|
4691
5177
|
*
|
|
@@ -4693,12 +5179,12 @@ export declare function matchesJSONValue(entry: unknown, ancestors: WeakSet<obje
|
|
|
4693
5179
|
* `parse`'s coercions are published and form input relies on them, but some change what
|
|
4694
5180
|
* a value means: `1` to `true`, `'9007199254740993'` to `...992`, `'1e-400'` to `0`,
|
|
4695
5181
|
* `'0x10'` to `16`. A door that must not guess asks this about each fault `audit` reported,
|
|
4696
|
-
*
|
|
5182
|
+
* because `audit` already names every nested repair with its path and the kind it wanted.
|
|
4697
5183
|
*
|
|
4698
5184
|
* Only a `type` fault is a repair. A number needs a string whose trim is the number's own
|
|
4699
5185
|
* text, so `'30'` and `' 30 '` pass while `'30.0'`, `'007'`, `'0x10'`, `'1e3'`, `'+5'`,
|
|
4700
5186
|
* `'.5'`, `'-0'`, and `'9007199254740993'` do not. A boolean needs `'true'` or `'false'`,
|
|
4701
|
-
* a literal its trimmed text, and a string a finite number
|
|
5187
|
+
* a literal its trimmed text, and a string a finite number other than `-0`. Anything else refuses.
|
|
4702
5188
|
*
|
|
4703
5189
|
* @param fault - A fault `audit` reported
|
|
4704
5190
|
* @param input - The value as it arrived
|
|
@@ -4761,7 +5247,7 @@ export declare function matchesMember(members: ReadonlySet<unknown>, value: unkn
|
|
|
4761
5247
|
export declare function matchesPattern(pattern: RegExp, value: string): boolean;
|
|
4762
5248
|
|
|
4763
5249
|
/**
|
|
4764
|
-
* Determines whether a value carries the plain-record brand, raising
|
|
5250
|
+
* Determines whether a value carries the plain-record brand, raising an untrusted
|
|
4765
5251
|
* prototype observation instead of answering it.
|
|
4766
5252
|
*
|
|
4767
5253
|
* @remarks
|
|
@@ -4777,14 +5263,14 @@ export declare function matchesPattern(pattern: RegExp, value: string): boolean;
|
|
|
4777
5263
|
* therefore identified by the own members ECMAScript requires every realm to
|
|
4778
5264
|
* put on it (`constructor`, `hasOwnProperty`, `isPrototypeOf`,
|
|
4779
5265
|
* `propertyIsEnumerable`, `toLocaleString`, `toString`, `valueOf`), each read
|
|
4780
|
-
* through its own DESCRIPTOR so no accessor on
|
|
5266
|
+
* through its own DESCRIPTOR so no accessor on an untrusted prototype ever runs.
|
|
4781
5267
|
* Each must be an own DATA property whose value is a FUNCTION — true of every
|
|
4782
5268
|
* conformant realm, so the requirement costs a genuine foreign record nothing,
|
|
4783
|
-
* and it refuses the cheapest
|
|
5269
|
+
* and it refuses the cheapest fake (stamping the mandated names with
|
|
4784
5270
|
* `undefined`) for free.
|
|
4785
5271
|
*
|
|
4786
5272
|
* That is a structural test, not a provenance one, and the residual is stated
|
|
4787
|
-
* as exactly what it is: a FUNCTION-VALUED
|
|
5273
|
+
* as exactly what it is: a FUNCTION-VALUED fake passes, and this realm's own
|
|
4788
5274
|
* `Object.prototype` supplies those functions to stamp, so the price is a
|
|
4789
5275
|
* few lines rather than nothing. Reparenting a class prototype to `null` and
|
|
4790
5276
|
* stamping the mandated names with real functions passes; so does leaving the
|
|
@@ -4792,31 +5278,31 @@ export declare function matchesPattern(pattern: RegExp, value: string): boolean;
|
|
|
4792
5278
|
* `null` as its own prototype and answers those descriptor reads with
|
|
4793
5279
|
* functions. In both cases the value is a live class instance whose methods are
|
|
4794
5280
|
* still reachable on it. A further own-key SUBSET rule buys even less: it
|
|
4795
|
-
* refuses a
|
|
5281
|
+
* refuses a fake that left methods on its prototype and accepts the same
|
|
4796
5282
|
* class with those methods moved onto the instance, where they are
|
|
4797
5283
|
* indistinguishable from a plain record's function
|
|
4798
|
-
* properties — so it raises the
|
|
5284
|
+
* properties — so it raises the fake's price and narrows the realm-agnostic
|
|
4799
5285
|
* arm this rule exists to keep open. What the pass buys is acceptance at
|
|
4800
5286
|
* brand-governed doors and nothing after it: every ownership engine publishes a
|
|
4801
5287
|
* frozen plain record built only from captured data, so no class instance,
|
|
4802
|
-
* class behavior, or
|
|
5288
|
+
* class behavior, or fabricated prototype survives into a snapshot.
|
|
4803
5289
|
*
|
|
4804
5290
|
* `Object.create(<null-prototype object>)` is refused, and NOT because it is
|
|
4805
|
-
* structurally identical to a reparented class instance — it is not,
|
|
5291
|
+
* structurally identical to a reparented class instance — it is not, because a
|
|
4806
5292
|
* class prototype always owns `constructor` and a bare `Object.create(null)`
|
|
4807
5293
|
* owns nothing. It is refused as policy: no realm produces that chain for a
|
|
4808
5294
|
* plain object, no consumer of it has been named, and a caller erases the
|
|
4809
5295
|
* difference by deleting `constructor`.
|
|
4810
5296
|
*
|
|
4811
5297
|
* This is the diagnosing form, deliberately NOT total: a revoked `Proxy` or a
|
|
4812
|
-
*
|
|
5298
|
+
* untrusted `getPrototypeOf` trap throws out of it, so an ownership engine can
|
|
4813
5299
|
* report an unreadable value as a failed read with the exact cause rather than
|
|
4814
5300
|
* as a well-formed structural refusal. {@link isRecord} is the total form for
|
|
4815
5301
|
* every guard consumer and contains that throw as `false`.
|
|
4816
5302
|
*
|
|
4817
5303
|
* @param value - The value whose record brand to inspect
|
|
4818
5304
|
* @returns True if the value is a plain record; false otherwise
|
|
4819
|
-
* @throws The exact value thrown by
|
|
5305
|
+
* @throws The exact value thrown by an untrusted brand observation
|
|
4820
5306
|
*
|
|
4821
5307
|
* @example
|
|
4822
5308
|
* ```ts
|
|
@@ -4827,6 +5313,40 @@ export declare function matchesPattern(pattern: RegExp, value: string): boolean;
|
|
|
4827
5313
|
*/
|
|
4828
5314
|
export declare function matchesRecordBrand(value: unknown): boolean;
|
|
4829
5315
|
|
|
5316
|
+
/**
|
|
5317
|
+
* Checks whether the member of the record bound as `this` passes a key-plan step's guard.
|
|
5318
|
+
*
|
|
5319
|
+
* @remarks
|
|
5320
|
+
* Passed with the record as the `thisArg` argument to the captured `every` member over a key plan, so the
|
|
5321
|
+
* walk reads each member once, in the plan's order, and stops at the first refusal.
|
|
5322
|
+
*
|
|
5323
|
+
* @param step - The step whose member to read and guard
|
|
5324
|
+
* @returns True if the member under the step's key passes its guard; false otherwise
|
|
5325
|
+
*
|
|
5326
|
+
* @example
|
|
5327
|
+
* ```ts
|
|
5328
|
+
* matchesStepGuard.call({ id: 'a' }, { key: 'id', guard: isString }) // true
|
|
5329
|
+
* ```
|
|
5330
|
+
*/
|
|
5331
|
+
export declare function matchesStepGuard(this: Readonly<Record<string, unknown>>, step: KeyStep): boolean;
|
|
5332
|
+
|
|
5333
|
+
/**
|
|
5334
|
+
* Checks whether a key-plan step names the key at its index in the list bound as `this`.
|
|
5335
|
+
*
|
|
5336
|
+
* @remarks
|
|
5337
|
+
* Passed with the key list as the `thisArg` argument to the captured `every` member over a key plan.
|
|
5338
|
+
*
|
|
5339
|
+
* @param step - The step to compare
|
|
5340
|
+
* @param index - The step's position in its plan
|
|
5341
|
+
* @returns True if the step's key equals the bound list's key at that index; false otherwise
|
|
5342
|
+
*
|
|
5343
|
+
* @example
|
|
5344
|
+
* ```ts
|
|
5345
|
+
* matchesStepKey.call(['id'], { key: 'id', guard: isString }, 0) // true
|
|
5346
|
+
* ```
|
|
5347
|
+
*/
|
|
5348
|
+
export declare function matchesStepKey(this: readonly string[], step: KeyStep, index: number): boolean;
|
|
5349
|
+
|
|
4830
5350
|
/**
|
|
4831
5351
|
* Checks whether a string's length in code points falls within optional bounds.
|
|
4832
5352
|
*
|
|
@@ -4865,6 +5385,30 @@ export declare function matchesStringLength(value: string, min: number | undefin
|
|
|
4865
5385
|
*/
|
|
4866
5386
|
export declare function matchesUndefinedField(fault: AuditFault, value: unknown, parsed: unknown): boolean;
|
|
4867
5387
|
|
|
5388
|
+
/**
|
|
5389
|
+
* Checks whether a shape node admits `undefined`, from its category, its union mode, and its
|
|
5390
|
+
* children's answers.
|
|
5391
|
+
*
|
|
5392
|
+
* @remarks
|
|
5393
|
+
* The `undefined` leaf admits it. A nullable node admits it when its inner shape does, an
|
|
5394
|
+
* `anyOf` union when an arm does, and a `oneOf` union when exactly one arm does. Every other
|
|
5395
|
+
* node refuses it. For a node a contract compiles at its root, the answer equals what that
|
|
5396
|
+
* contract's `is` answers for `undefined`.
|
|
5397
|
+
*
|
|
5398
|
+
* @param category - The node's category
|
|
5399
|
+
* @param mode - The node's union mode, `'oneOf'` or anything else for `anyOf`
|
|
5400
|
+
* @param children - Each structural child's answer, in slot order
|
|
5401
|
+
* @returns True if the node admits `undefined`; false otherwise
|
|
5402
|
+
*
|
|
5403
|
+
* @example
|
|
5404
|
+
* ```ts
|
|
5405
|
+
* matchesUndefinedNode('undefined', undefined, []) // true
|
|
5406
|
+
* matchesUndefinedNode('union', 'anyOf', [false, true]) // true
|
|
5407
|
+
* matchesUndefinedNode('union', 'oneOf', [true, true]) // false
|
|
5408
|
+
* ```
|
|
5409
|
+
*/
|
|
5410
|
+
export declare function matchesUndefinedNode(category: unknown, mode: unknown, children: readonly boolean[]): boolean;
|
|
5411
|
+
|
|
4868
5412
|
/**
|
|
4869
5413
|
* Determines whether an object is already on a traversal's active path.
|
|
4870
5414
|
*
|
|
@@ -4946,7 +5490,7 @@ export declare const NODE_LIMIT = 16384;
|
|
|
4946
5490
|
*
|
|
4947
5491
|
* The negation applies to the contained verdict, so a throwing guard is a non-match and
|
|
4948
5492
|
* its negation passes. Containing the negation instead made a guard and its `notOf`
|
|
4949
|
-
* both reject the same value, which
|
|
5493
|
+
* both reject the same value, which falsified `orOf(g, notOf(g))` as a tautology.
|
|
4950
5494
|
*
|
|
4951
5495
|
* @param guard - The guard or predicate to negate
|
|
4952
5496
|
* @returns A guard accepting exactly the values `guard` rejects
|
|
@@ -5018,11 +5562,20 @@ export declare interface NullShapeOptions {
|
|
|
5018
5562
|
readonly description?: string;
|
|
5019
5563
|
}
|
|
5020
5564
|
|
|
5021
|
-
/**
|
|
5565
|
+
/**
|
|
5566
|
+
* Describes a number with optional bounds; `integer` restricts to whole numbers.
|
|
5567
|
+
*
|
|
5568
|
+
* @remarks
|
|
5569
|
+
* `min` and `max` are inclusive and emit `minimum` and `maximum`; `over` and `under` are
|
|
5570
|
+
* exclusive and emit `exclusiveMinimum` and `exclusiveMaximum`. Every bound is finite, and
|
|
5571
|
+
* bounds that no number satisfies refuse with code `range`.
|
|
5572
|
+
*/
|
|
5022
5573
|
export declare interface NumberShape {
|
|
5023
5574
|
readonly category: 'number';
|
|
5024
5575
|
readonly min?: number;
|
|
5576
|
+
readonly over?: number;
|
|
5025
5577
|
readonly max?: number;
|
|
5578
|
+
readonly under?: number;
|
|
5026
5579
|
readonly integer?: boolean;
|
|
5027
5580
|
readonly description?: string;
|
|
5028
5581
|
}
|
|
@@ -5031,13 +5584,13 @@ export declare interface NumberShape {
|
|
|
5031
5584
|
* Builds a numeric {@link NumberShape}.
|
|
5032
5585
|
*
|
|
5033
5586
|
* @remarks
|
|
5034
|
-
*
|
|
5035
|
-
*
|
|
5036
|
-
* Schema keyword expresses them.
|
|
5587
|
+
* `min` and `max` are inclusive; `over` and `under` are exclusive. A present bound must be
|
|
5588
|
+
* finite. `NaN` and `±Infinity` throw a `bound` {@link ContractError} at construction,
|
|
5589
|
+
* because no finite value satisfies them and no JSON Schema keyword expresses them.
|
|
5037
5590
|
*
|
|
5038
|
-
* @param options - Optional bounds (`min` / `max`), `integer`, and `description`
|
|
5591
|
+
* @param options - Optional bounds (`min` / `over` / `max` / `under`), `integer`, and `description`
|
|
5039
5592
|
* @returns A number shape
|
|
5040
|
-
* @throws {ContractError} When a present bound is not finite
|
|
5593
|
+
* @throws {ContractError} When an option key is unknown, a present bound is not finite, or no number satisfies the bounds
|
|
5041
5594
|
*
|
|
5042
5595
|
* @example
|
|
5043
5596
|
* ```ts
|
|
@@ -5046,10 +5599,18 @@ export declare interface NumberShape {
|
|
|
5046
5599
|
*/
|
|
5047
5600
|
export declare function numberShape(options?: NumberShapeOptions): NumberShape;
|
|
5048
5601
|
|
|
5049
|
-
/**
|
|
5602
|
+
/**
|
|
5603
|
+
* Groups the options for {@link NumberShape} (through `numberShape` / `integerShape`).
|
|
5604
|
+
*
|
|
5605
|
+
* @remarks
|
|
5606
|
+
* `min` and `max` admit their own value; `over` admits a value greater than it and `under` a
|
|
5607
|
+
* value less than it.
|
|
5608
|
+
*/
|
|
5050
5609
|
export declare interface NumberShapeOptions {
|
|
5051
5610
|
readonly min?: number;
|
|
5611
|
+
readonly over?: number;
|
|
5052
5612
|
readonly max?: number;
|
|
5613
|
+
readonly under?: number;
|
|
5053
5614
|
readonly integer?: boolean;
|
|
5054
5615
|
readonly description?: string;
|
|
5055
5616
|
}
|
|
@@ -5067,7 +5628,7 @@ export declare interface NumberShapeOptions {
|
|
|
5067
5628
|
* prototype accessors can satisfy the shape. An optional member passes when its
|
|
5068
5629
|
* read value is `undefined`; otherwise its guard must accept the value. Unknown
|
|
5069
5630
|
* members are never enumerated or inspected. Member-carrying functions are
|
|
5070
|
-
* accepted. Arrays, `null`, and primitives are rejected.
|
|
5631
|
+
* accepted. Arrays, `null`, and primitives are rejected. Untrusted reads return
|
|
5071
5632
|
* `false` rather than throwing.
|
|
5072
5633
|
*
|
|
5073
5634
|
* @param shape - The guard shape whose declared members the object must satisfy
|
|
@@ -5102,6 +5663,18 @@ export declare function objectOf<S extends GuardsShape>(shape: S, optional: true
|
|
|
5102
5663
|
* the compiled reporter stays silent, mirroring that parser. `true` accepts
|
|
5103
5664
|
* unknown keys as-is, and a `ContractShape` validates them, in every artifact.
|
|
5104
5665
|
*
|
|
5666
|
+
* A closed object, and one whose `additionalProperties` is a `ContractShape`, also
|
|
5667
|
+
* refuses an own member outside the enumerable view: a non-enumerable string key or
|
|
5668
|
+
* a symbol key. The guard answers `false`; the auditor reports a declared such member
|
|
5669
|
+
* as `'hidden'` in place of `'missing'`, an undeclared one as `'extra'` when closed and
|
|
5670
|
+
* `'hidden'` under a tail shape, and each symbol key as `'extra'` at the object with
|
|
5671
|
+
* its preview in `symbol`. The parser and the reporter keep the enumerable view, so
|
|
5672
|
+
* `explain` reports `'missing'` where `audit` reports `'hidden'`. An object with
|
|
5673
|
+
* `additionalProperties: true` runs no own-key count: it admits an undeclared
|
|
5674
|
+
* non-enumerable or symbol member, while a declared member outside the enumerable
|
|
5675
|
+
* view still reads as absent, so `is` answers `false` for a required one and `audit`
|
|
5676
|
+
* and `explain` report it `'missing'`.
|
|
5677
|
+
*
|
|
5105
5678
|
* The `A` parameter carries the open-value shape into {@link Infer}, so a constrained
|
|
5106
5679
|
* tail keeps its type in the inferred index signature.
|
|
5107
5680
|
*/
|
|
@@ -5196,7 +5769,8 @@ export declare function omitVisited(visited: WeakSet<object>, value: object): vo
|
|
|
5196
5769
|
* - **Guard**: accepts the value only when exactly one variant's guard
|
|
5197
5770
|
* accepts it. A value matching two-or-more variants — which would violate
|
|
5198
5771
|
* the emitted `oneOf` schema — is rejected, even though it would pass
|
|
5199
|
-
* {@link unionShape}'s guard.
|
|
5772
|
+
* {@link unionShape}'s guard. A value that names one arm through a required
|
|
5773
|
+
* literal is answered by that arm's guard alone.
|
|
5200
5774
|
* - **Parser**: judged on the RAW input's guard matches only, with NO
|
|
5201
5775
|
* coercion fallback for an ambiguous input. When exactly one variant's
|
|
5202
5776
|
* guard accepts the raw value, the input itself is returned. Zero matches or
|
|
@@ -5264,7 +5838,8 @@ export declare function optionalOf<T>(guard: Guard<T>): Guard<T | undefined>;
|
|
|
5264
5838
|
* `default` holds the JSON value the compiled parser fills when the property is
|
|
5265
5839
|
* absent or `undefined`. It leaves `is`, `audit`, `explain`, and `generate`
|
|
5266
5840
|
* unchanged, because an absent optional stays canonical. It must satisfy `inner`,
|
|
5267
|
-
* and it may sit only on a property of a closed object with no union
|
|
5841
|
+
* and it may sit only on a property of a closed object with no union or interface
|
|
5842
|
+
* ancestor, over an `inner` that refuses `undefined`.
|
|
5268
5843
|
*/
|
|
5269
5844
|
export declare interface OptionalShape<S extends ContractShape = ContractShape> {
|
|
5270
5845
|
readonly category: 'optional';
|
|
@@ -5277,11 +5852,12 @@ export declare interface OptionalShape<S extends ContractShape = ContractShape>
|
|
|
5277
5852
|
*
|
|
5278
5853
|
* @remarks
|
|
5279
5854
|
* As an {@link objectShape} property, the field becomes a true optional property
|
|
5280
|
-
* in the inferred type
|
|
5855
|
+
* in the inferred type, and as an {@link interfaceShape} member, one that may read
|
|
5856
|
+
* `undefined`. A `default` is captured as an owned frozen copy, and the
|
|
5281
5857
|
* compiled parser fills it where the property is absent or `undefined`; the guard,
|
|
5282
5858
|
* the audit, the report, and the generator keep treating the property as optional.
|
|
5283
|
-
* The compilers refuse a default `inner` refuses, a default under a union
|
|
5284
|
-
* default on a property of an open object.
|
|
5859
|
+
* The compilers refuse a default `inner` refuses, a default under a union or below
|
|
5860
|
+
* an interface, and a default on a property of an open object.
|
|
5285
5861
|
*
|
|
5286
5862
|
* @param inner - The wrapped shape
|
|
5287
5863
|
* @param options - Optional `default`, a JSON value
|
|
@@ -5322,6 +5898,18 @@ export declare function orOf<A, B>(left: Guard<A>, right: Guard<B>): Guard<A | B
|
|
|
5322
5898
|
|
|
5323
5899
|
export declare function orOf(left: (value: unknown) => boolean, right: (value: unknown) => boolean): Guard<unknown>;
|
|
5324
5900
|
|
|
5901
|
+
/**
|
|
5902
|
+
* Represents a compiled owning admission — the `own` member of a {@link ContractInterface}.
|
|
5903
|
+
*
|
|
5904
|
+
* @remarks
|
|
5905
|
+
* The generic call returns the owned value at the argument's static type, because `Infer` types a
|
|
5906
|
+
* function member as `(...args: never[]) => unknown`; the unannotated call returns the contract's type.
|
|
5907
|
+
*/
|
|
5908
|
+
export declare interface OwnerFunction<T> {
|
|
5909
|
+
<V extends T>(value: V): Result<V, ContractRefusal>;
|
|
5910
|
+
(value: unknown): Result<T, ContractRefusal>;
|
|
5911
|
+
}
|
|
5912
|
+
|
|
5325
5913
|
/**
|
|
5326
5914
|
* Rebuilds a declaration's regular expression as a stateless pattern this
|
|
5327
5915
|
* package owns, and refuses an unreadable one under the reader's own name.
|
|
@@ -5366,7 +5954,7 @@ export declare function ownPattern(pattern: RegExp, reader: string): RegExp;
|
|
|
5366
5954
|
*
|
|
5367
5955
|
* @param shape - The contract shape to own
|
|
5368
5956
|
* @returns A deeply cloned frozen snapshot
|
|
5369
|
-
* @throws {ContractError} When the declaration cannot be copied faithfully, when
|
|
5957
|
+
* @throws {ContractError} When the declaration cannot be copied faithfully, when untrusted shape or raw-schema traversal prevents ownership, or when a frozen root fails validation
|
|
5370
5958
|
*
|
|
5371
5959
|
* @example
|
|
5372
5960
|
* ```ts
|
|
@@ -5456,9 +6044,11 @@ export declare function parseBooleanField(record: Record<string, unknown>, path:
|
|
|
5456
6044
|
* `parseEnum ↔ literalOf(...allowed)` pairing covers every literal primitive
|
|
5457
6045
|
* (string, number, or boolean), not only strings. Matching is identity, never
|
|
5458
6046
|
* cross-type coercion: `parseEnum('1', [1])` stays `undefined`. The allowed
|
|
5459
|
-
* values are captured through their dense own-index view
|
|
5460
|
-
*
|
|
5461
|
-
* `undefined` rather than escaping.
|
|
6047
|
+
* values are captured through their dense own-index view into a frozen snapshot
|
|
6048
|
+
* that one SameValueZero pass reads; caller-defined iteration is ignored and
|
|
6049
|
+
* unreadability returns `undefined` rather than escaping. A call costs one
|
|
6050
|
+
* snapshot and one pass over it, so a vocabulary checked often is cheaper
|
|
6051
|
+
* through a `literalOf` guard built once.
|
|
5462
6052
|
*
|
|
5463
6053
|
* @param value - The value to parse
|
|
5464
6054
|
* @param allowed - The permitted literal values
|
|
@@ -5695,7 +6285,7 @@ export declare type Parser<T> = (value: unknown) => T | undefined;
|
|
|
5695
6285
|
*
|
|
5696
6286
|
* @remarks
|
|
5697
6287
|
* Probes the record's own enumerable values before returning the reference, so a
|
|
5698
|
-
*
|
|
6288
|
+
* untrusted getter is met here rather than at the caller. A failed probe throws
|
|
5699
6289
|
* `ContractError { code: 'structure' }` carrying `parseRecord: value could not be
|
|
5700
6290
|
* read`; a readable non-record answers `undefined`.
|
|
5701
6291
|
*
|
|
@@ -5862,41 +6452,51 @@ export declare function pinMembers(prototype: object, owner: string): void;
|
|
|
5862
6452
|
export declare const PRESENCE_MASK_LIMIT = 31;
|
|
5863
6453
|
|
|
5864
6454
|
/**
|
|
5865
|
-
* Renders
|
|
5866
|
-
* `
|
|
5867
|
-
*
|
|
5868
|
-
* @remarks
|
|
5869
|
-
*
|
|
5870
|
-
*
|
|
5871
|
-
* and
|
|
5872
|
-
*
|
|
5873
|
-
*
|
|
5874
|
-
*
|
|
5875
|
-
*
|
|
5876
|
-
*
|
|
5877
|
-
*
|
|
5878
|
-
*
|
|
5879
|
-
*
|
|
5880
|
-
*
|
|
5881
|
-
* `
|
|
5882
|
-
*
|
|
5883
|
-
*
|
|
5884
|
-
*
|
|
5885
|
-
*
|
|
5886
|
-
*
|
|
5887
|
-
*
|
|
5888
|
-
*
|
|
5889
|
-
*
|
|
5890
|
-
*
|
|
5891
|
-
*
|
|
5892
|
-
*
|
|
5893
|
-
*
|
|
5894
|
-
*
|
|
5895
|
-
*
|
|
5896
|
-
*
|
|
6455
|
+
* Renders a value as a bounded single-line string for a {@link Fault}'s `received` field, running
|
|
6456
|
+
* a `Proxy` object's `getPrototypeOf` trap.
|
|
6457
|
+
*
|
|
6458
|
+
* @remarks
|
|
6459
|
+
* Every preview, its quotes and its `…` included, is at most
|
|
6460
|
+
* {@link PREVIEW_LIMIT} UTF-16 code units long and holds no control character
|
|
6461
|
+
* and no line terminator.
|
|
6462
|
+
*
|
|
6463
|
+
* A string renders as its quoted JSON representation, and a narrowed symbol
|
|
6464
|
+
* through intrinsic `String` with the same escaping and no outer quotes. DEL
|
|
6465
|
+
* (U+007F), the C1 controls (U+0080 to U+009F), U+2028, and U+2029, which a
|
|
6466
|
+
* `JSON.stringify` call leaves raw, render as `\u` sequences. A string of at
|
|
6467
|
+
* most {@link PREVIEW_LIMIT} UTF-16 code units that holds none of those raw
|
|
6468
|
+
* characters takes its answer from one whole-string encode when that encode
|
|
6469
|
+
* fits the same limit. Every other string and every symbol renders through one
|
|
6470
|
+
* bounded indexed encoder that appends only complete escaped code-point tokens,
|
|
6471
|
+
* at most `PREVIEW_LIMIT - 2` UTF-16 code units between a string's quotes and
|
|
6472
|
+
* `PREVIEW_LIMIT - 1` of a symbol, and then closes with the quote when every
|
|
6473
|
+
* token fit and with `…` otherwise. Clipping therefore never retrieves the
|
|
6474
|
+
* mutable string iterator or splits an escape or a surrogate pair, and
|
|
6475
|
+
* enormous primitive text is not fully traversed. The two paths agree: one
|
|
6476
|
+
* `JSON.stringify` call fits the limit exactly when the escaped inner length
|
|
6477
|
+
* is at most `PREVIEW_LIMIT - 2`, which is when the indexed encoder closes
|
|
6478
|
+
* with the quote.
|
|
6479
|
+
*
|
|
6480
|
+
* A number or a boolean renders through `String`. A bigint renders through
|
|
6481
|
+
* `String` with a trailing `n`; when its text reaches {@link PREVIEW_LIMIT}
|
|
6482
|
+
* UTF-16 code units, the preview keeps the leading `PREVIEW_LIMIT - 2`, then
|
|
6483
|
+
* `…`, then `n`. `null` and `undefined` render as their own name.
|
|
6484
|
+
*
|
|
6485
|
+
* An array renders as `'array'`, a function as `'function'`, a plain or
|
|
6486
|
+
* null-prototype record as `'object'`, and every other object, such as a class
|
|
6487
|
+
* instance, a `Map`, a `Date`, or a revoked `Proxy`, as `'instance'`. To tell a
|
|
6488
|
+
* record from an instance, the {@link isRecord} guard reads the object's
|
|
6489
|
+
* prototype, that prototype's prototype, and, when the second is `null`, the
|
|
6490
|
+
* first one's own property descriptors. A `Proxy` object's `getPrototypeOf`
|
|
6491
|
+
* trap therefore runs, and so do the `getPrototypeOf` and
|
|
6492
|
+
* `getOwnPropertyDescriptor` traps of a `Proxy` object that stands as the
|
|
6493
|
+
* prototype; a trap that throws yields `'instance'`. Every read is a prototype
|
|
6494
|
+
* or descriptor read, so no accessor on the object or its prototype runs, and
|
|
6495
|
+
* no object is stringified.
|
|
5897
6496
|
*
|
|
5898
6497
|
* @param value - The value to preview
|
|
5899
|
-
* @returns A
|
|
6498
|
+
* @returns A string of at most {@link PREVIEW_LIMIT} UTF-16 code units with no
|
|
6499
|
+
* control character and no line terminator
|
|
5900
6500
|
*
|
|
5901
6501
|
* @example
|
|
5902
6502
|
* ```ts
|
|
@@ -5904,27 +6504,35 @@ export declare const PRESENCE_MASK_LIMIT = 31;
|
|
|
5904
6504
|
* preview(42) // '42'
|
|
5905
6505
|
* preview(null) // 'null'
|
|
5906
6506
|
* preview({ a: 1 }) // 'object'
|
|
6507
|
+
* preview(new Map()) // 'instance'
|
|
5907
6508
|
* preview([1, 2, 3]) // 'array'
|
|
5908
6509
|
* ```
|
|
5909
6510
|
*/
|
|
5910
6511
|
export declare function preview(value: unknown): string;
|
|
5911
6512
|
|
|
5912
6513
|
/**
|
|
5913
|
-
* Caps at `64` the
|
|
6514
|
+
* Caps at `64` the length in UTF-16 code units of every {@link preview} result, frozen.
|
|
5914
6515
|
*
|
|
5915
6516
|
* @remarks
|
|
5916
|
-
*
|
|
6517
|
+
* The cap covers the whole preview, its quotes, its trailing `…`, and a
|
|
6518
|
+
* bigint's `n` included, for every input. A longer rendering is clipped with `…`, so a
|
|
5917
6519
|
* {@link Fault}'s `received` field never embeds an unbounded amount of
|
|
5918
|
-
* untrusted text
|
|
6520
|
+
* untrusted text, and the {@link describeFaultLine} function prints it as
|
|
6521
|
+
* written.
|
|
5919
6522
|
*/
|
|
5920
6523
|
export declare const PREVIEW_LIMIT = 64;
|
|
5921
6524
|
|
|
5922
6525
|
/**
|
|
5923
6526
|
* Builds bounded escaped preview parts without splitting a surrogate pair.
|
|
5924
6527
|
*
|
|
6528
|
+
* @remarks
|
|
6529
|
+
* Each token is one code point's escape: its `JSON.stringify` form, or a `\u` sequence for DEL
|
|
6530
|
+
* (U+007F), a C1 control (U+0080 to U+009F), U+2028, or U+2029. The parts end with `…` when a
|
|
6531
|
+
* token does not fit, and otherwise with the closing quote of a quoted source.
|
|
6532
|
+
*
|
|
5925
6533
|
* @param source - The source text
|
|
5926
6534
|
* @param index - The next UTF-16 offset
|
|
5927
|
-
* @param capacity - The
|
|
6535
|
+
* @param capacity - The UTF-16 code units left for tokens; the closing quote or `…` takes one more
|
|
5928
6536
|
* @param quoted - Whether the final part closes a string quote
|
|
5929
6537
|
* @returns The escaped parts with their closing quote or truncation mark
|
|
5930
6538
|
*
|
|
@@ -5935,6 +6543,29 @@ export declare const PREVIEW_LIMIT = 64;
|
|
|
5935
6543
|
*/
|
|
5936
6544
|
export declare function previewParts(source: string, index: number, capacity: number, quoted: boolean): readonly string[];
|
|
5937
6545
|
|
|
6546
|
+
/**
|
|
6547
|
+
* Encodes a bounded window of a source text as preview tokens in one pass.
|
|
6548
|
+
*
|
|
6549
|
+
* @remarks
|
|
6550
|
+
* Gives the answer `previewParts` gives, joined, with a quoted source's opening quote: the first
|
|
6551
|
+
* `capacity` UTF-16 code units are encoded through one `JSON.stringify` call, DEL, the C1
|
|
6552
|
+
* controls, U+2028, and U+2029 take their `\u` sequences, and the encoded text is cut at
|
|
6553
|
+
* `capacity` to its longest prefix of complete tokens. No token the recursion keeps lies outside
|
|
6554
|
+
* the window, and a surrogate pair the window splits encodes as a 6-unit sequence that cannot fit.
|
|
6555
|
+
*
|
|
6556
|
+
* @param source - The source text
|
|
6557
|
+
* @param capacity - The UTF-16 code units left for tokens; the closing quote or `…` takes one more
|
|
6558
|
+
* @param quoted - If `true`, the text opens with a string quote and closes with one when the
|
|
6559
|
+
* source fits; if `false`, the text carries no quote
|
|
6560
|
+
* @returns The encoded text, closed by `…` when the source does not fit
|
|
6561
|
+
*
|
|
6562
|
+
* @example
|
|
6563
|
+
* ```ts
|
|
6564
|
+
* previewText('abc', 2, false) // 'ab…'
|
|
6565
|
+
* ```
|
|
6566
|
+
*/
|
|
6567
|
+
export declare function previewText(source: string, capacity: number, quoted: boolean): string;
|
|
6568
|
+
|
|
5938
6569
|
/**
|
|
5939
6570
|
* Represents a deterministic random source returning a value in `[0, 1)`.
|
|
5940
6571
|
*
|
|
@@ -5985,7 +6616,7 @@ export declare interface RawShape {
|
|
|
5985
6616
|
* structurally verbatim, so here the schema claims LESS than the compiled guard
|
|
5986
6617
|
* accepts — `rawShape({ type: 'string' })` emits `{ type: 'string' }` and its
|
|
5987
6618
|
* guard still accepts `42`, the mirror of {@link jsonShape}'s looseness.
|
|
5988
|
-
* `compileGenerator` throws,
|
|
6619
|
+
* `compileGenerator` throws, because an arbitrary embedded schema has no
|
|
5989
6620
|
* auto-generatable sample.
|
|
5990
6621
|
*
|
|
5991
6622
|
* @param schema - The JSON Schema fragment to embed
|
|
@@ -6002,28 +6633,18 @@ export declare function rawShape(schema: JSONSchema): RawShape;
|
|
|
6002
6633
|
* Snapshots an array through its reflected own-index population.
|
|
6003
6634
|
*
|
|
6004
6635
|
* @remarks
|
|
6005
|
-
*
|
|
6006
|
-
*
|
|
6007
|
-
*
|
|
6008
|
-
*
|
|
6009
|
-
* reflected population, so a length-driven consumer must require `dense` or
|
|
6010
|
-
* carry an independent bound. A population that is exactly the canonical
|
|
6011
|
-
* indices in ascending order followed by `length` is copied straight by index
|
|
6012
|
-
* under the same per-index corroboration, and answers with the same entries,
|
|
6013
|
-
* the same `dense` fact, and the same refusals as the walk. Caller-defined
|
|
6014
|
-
* iteration is ignored. A descriptor-only index omitted from reflection is
|
|
6015
|
-
* deliberately outside this lens and remains a hole. Failure retains the exact
|
|
6016
|
-
* thrown value when length, reflection, membership, or indexed value
|
|
6017
|
-
* observation throws; a non-native length or view disagreement is also
|
|
6018
|
-
* failure. `4294967295` is metadata rather than an array index.
|
|
6636
|
+
* Answers what {@link collectArrayEntries} answers, as a frozen read whose
|
|
6637
|
+
* entries are frozen too. Failure retains the exact thrown value when length,
|
|
6638
|
+
* reflection, membership, or indexed value observation throws; a non-native
|
|
6639
|
+
* length or view disagreement is also failure.
|
|
6019
6640
|
*
|
|
6020
6641
|
* @param value - The array whose reflected indexed entries to read
|
|
6021
|
-
* @returns A successful frozen entry snapshot with its dense
|
|
6022
|
-
* failure carrying the exact thrown value as `unknown`
|
|
6642
|
+
* @returns A successful frozen entry snapshot with its `dense` and `exact`
|
|
6643
|
+
* facts, or a failure carrying the exact thrown value as `unknown`
|
|
6023
6644
|
*
|
|
6024
6645
|
* @example
|
|
6025
6646
|
* ```ts
|
|
6026
|
-
* readArrayEntries([1, 2]) // { success: true, value: { entries: [1, 2], dense: true } }
|
|
6647
|
+
* readArrayEntries([1, 2]) // { success: true, value: { entries: [1, 2], dense: true, exact: true } }
|
|
6027
6648
|
* ```
|
|
6028
6649
|
*/
|
|
6029
6650
|
export declare function readArrayEntries<T>(value: readonly T[]): Result<ArrayRead<T>>;
|
|
@@ -6103,7 +6724,7 @@ export declare function readMapEntries(value: ReadonlyMap<unknown, unknown>): Re
|
|
|
6103
6724
|
* consumed key is read exactly once, checked for presence, and inspected for an
|
|
6104
6725
|
* own descriptor while the container is enumerated once. Every successfully
|
|
6105
6726
|
* read non-`undefined` consumed value enters the fresh own-enumerable snapshot,
|
|
6106
|
-
* including an inherited or non-enumerable option.
|
|
6727
|
+
* including an inherited or non-enumerable option. An untrusted host is reported
|
|
6107
6728
|
* uniformly as an unreadable options record, while a readable array or class
|
|
6108
6729
|
* instance retains the plain-record diagnostic.
|
|
6109
6730
|
*
|
|
@@ -6186,6 +6807,11 @@ export declare function readPatternSource(pattern: unknown): string | undefined;
|
|
|
6186
6807
|
/**
|
|
6187
6808
|
* Derives the bit mask of names present in an indexed lookup.
|
|
6188
6809
|
*
|
|
6810
|
+
* @remarks
|
|
6811
|
+
* Takes `names` as the array it declares and reads each present index once, in order,
|
|
6812
|
+
* through the captured fold, so a hole adds no bit. An array-like that is not an array
|
|
6813
|
+
* is outside this contract.
|
|
6814
|
+
*
|
|
6189
6815
|
* @param names - Names to observe in order
|
|
6190
6816
|
* @param positions - The bit position of each declared name
|
|
6191
6817
|
* @returns The combined signed 32-bit mask
|
|
@@ -6243,6 +6869,28 @@ export declare function readSampleMemo(memo: SampleMemo, reader: string): Sample
|
|
|
6243
6869
|
*/
|
|
6244
6870
|
export declare function readSetEntries(value: ReadonlySet<unknown>): Result<readonly unknown[]>;
|
|
6245
6871
|
|
|
6872
|
+
/**
|
|
6873
|
+
* Reads a shape builder's map of child shapes into a frozen null-prototype snapshot.
|
|
6874
|
+
*
|
|
6875
|
+
* @remarks
|
|
6876
|
+
* Reads each own enumerable string key one time, so a key named `__proto__` lands as an own
|
|
6877
|
+
* member and a later edit to the caller's map cannot reach the snapshot. The children are kept
|
|
6878
|
+
* by identity.
|
|
6879
|
+
*
|
|
6880
|
+
* @param map - The caller's map of child shapes
|
|
6881
|
+
* @param door - The builder the refusal names
|
|
6882
|
+
* @param field - The builder field that holds the map
|
|
6883
|
+
* @param shape - The shape category the refusal names
|
|
6884
|
+
* @returns The frozen snapshot
|
|
6885
|
+
* @throws {ContractError} When a read fails, or when the map is not a plain record
|
|
6886
|
+
*
|
|
6887
|
+
* @example
|
|
6888
|
+
* ```ts
|
|
6889
|
+
* readShapeMap({ city: stringShape() }, 'objectShape', 'properties', 'object').city // the same string shape
|
|
6890
|
+
* ```
|
|
6891
|
+
*/
|
|
6892
|
+
export declare function readShapeMap<P extends Readonly<Record<string, ContractShape>>>(map: P, door: string, field: string, shape: string): P;
|
|
6893
|
+
|
|
6246
6894
|
/**
|
|
6247
6895
|
* Reads a value through the shared containment boundary or refuses it with the
|
|
6248
6896
|
* contract module's uniform read diagnostic.
|
|
@@ -6340,6 +6988,27 @@ export declare interface RecordShapeOptions {
|
|
|
6340
6988
|
readonly description?: string;
|
|
6341
6989
|
}
|
|
6342
6990
|
|
|
6991
|
+
/**
|
|
6992
|
+
* Builds the {@link ContractError} that reports an admission refusal.
|
|
6993
|
+
*
|
|
6994
|
+
* @remarks
|
|
6995
|
+
* The message is `<door>: ` followed by {@link describeFaults} over the refusal's faults with the
|
|
6996
|
+
* optional schema, or `<door>: value could not be read` when the refusal holds no fault. The code
|
|
6997
|
+
* is `structure`, the context carries the first fault's path and every fault, and the cause is the
|
|
6998
|
+
* refusal's own `cause` when it has one.
|
|
6999
|
+
*
|
|
7000
|
+
* @param refusal - The refusal an admission door answered
|
|
7001
|
+
* @param door - The public door name used in the diagnostic
|
|
7002
|
+
* @param schema - The optional schema whose keys the summary names
|
|
7003
|
+
* @returns The error, ready to throw
|
|
7004
|
+
*
|
|
7005
|
+
* @example
|
|
7006
|
+
* ```ts
|
|
7007
|
+
* throw refusalToError({ faults: [{ reason: 'extra', path: ['typo'] }] }, 'openStore')
|
|
7008
|
+
* ```
|
|
7009
|
+
*/
|
|
7010
|
+
export declare function refusalToError(refusal: ContractRefusal, door: string, schema?: JSONSchema): ContractError;
|
|
7011
|
+
|
|
6343
7012
|
/**
|
|
6344
7013
|
* Refuses a validated declaration whose compiled expansion exceeds
|
|
6345
7014
|
* {@link COMPILE_NODE_LIMIT}.
|
|
@@ -6390,6 +7059,41 @@ export declare function refuseExpansion(expansion: number | undefined): void;
|
|
|
6390
7059
|
*/
|
|
6391
7060
|
export declare function refuseOptionKeys(source: object | undefined, keys: readonly string[], builder: string, shape: string): void;
|
|
6392
7061
|
|
|
7062
|
+
/**
|
|
7063
|
+
* Refuses a value that fails a guard with a located, uniform diagnostic, and narrows it when the
|
|
7064
|
+
* guard holds.
|
|
7065
|
+
*
|
|
7066
|
+
* @remarks
|
|
7067
|
+
* Runs the guard inside {@link holds}, so a guard that throws refuses. The refusal reads
|
|
7068
|
+
* `<door>: <path> must be <limit>` and carries `path`, `limit`, and the {@link preview} of the
|
|
7069
|
+
* value as context. The code defaults to `bound`.
|
|
7070
|
+
*
|
|
7071
|
+
* @param value - The value to check
|
|
7072
|
+
* @param guard - The predicate that decides whether the value is acceptable
|
|
7073
|
+
* @param door - The public door name used in the diagnostic
|
|
7074
|
+
* @param options - The location, the limit text, and an optional code
|
|
7075
|
+
* @throws {ContractError} When the guard refuses or throws
|
|
7076
|
+
*
|
|
7077
|
+
* @example
|
|
7078
|
+
* ```ts
|
|
7079
|
+
* refuseValue(options.size, isSafeInteger, 'openStore', { path: ['size'], limit: 'a safe integer' })
|
|
7080
|
+
* ```
|
|
7081
|
+
*/
|
|
7082
|
+
export declare function refuseValue<T>(value: unknown, guard: Guard<T>, door: string, options: RefuseValueOptions): asserts value is T;
|
|
7083
|
+
|
|
7084
|
+
/**
|
|
7085
|
+
* Groups the options for `refuseValue`.
|
|
7086
|
+
*
|
|
7087
|
+
* @remarks
|
|
7088
|
+
* `path` locates the refused value, `limit` states what the value must be, and `code` names the
|
|
7089
|
+
* error category and defaults to `bound`.
|
|
7090
|
+
*/
|
|
7091
|
+
export declare interface RefuseValueOptions {
|
|
7092
|
+
readonly path: FieldPath;
|
|
7093
|
+
readonly limit: string;
|
|
7094
|
+
readonly code?: ContractCode;
|
|
7095
|
+
}
|
|
7096
|
+
|
|
6393
7097
|
/**
|
|
6394
7098
|
* Renders a schema as a short summary of what to send, such as `{"city": string, "note"?: string}`.
|
|
6395
7099
|
*
|
|
@@ -6399,6 +7103,8 @@ export declare function refuseOptionKeys(source: object | undefined, keys: reado
|
|
|
6399
7103
|
* and a schema that says nothing reads `any`. Each nested form takes half the room of its parent, and
|
|
6400
7104
|
* below 16 characters a form stops at its type, so a schema that holds itself still ends. Text past
|
|
6401
7105
|
* `room` is cut and closes with `…`. A type word outside JSON Schema's vocabulary is encoded.
|
|
7106
|
+
* A schema with an own `not` reads `function` when its `format` is `'function'`, `undefined`
|
|
7107
|
+
* when its `format` is `'undefined'`, and `never` otherwise.
|
|
6402
7108
|
*
|
|
6403
7109
|
* @param schema - The schema to summarize
|
|
6404
7110
|
* @param room - The characters the summary can take. Default: `FAULT_SCHEMA_LIMIT`
|
|
@@ -6449,6 +7155,28 @@ export declare function renderList(entries: readonly string[]): string;
|
|
|
6449
7155
|
*/
|
|
6450
7156
|
export declare function renderPath(path: readonly string[]): string;
|
|
6451
7157
|
|
|
7158
|
+
/**
|
|
7159
|
+
* Repairs a stable readable value with only lossless repairs and returns the parser's value.
|
|
7160
|
+
*
|
|
7161
|
+
* @remarks
|
|
7162
|
+
* Reads must remain stable across artifacts. Guard-valid input skips both reports and parses
|
|
7163
|
+
* once. Repairs use audit, parse once, and explain only on parse failure. Unresolved unions,
|
|
7164
|
+
* extras, lossy repairs, and a capped audit refuse. An own optional undefined field omitted or
|
|
7165
|
+
* filled by its declared default is not a repair. The merge of explain and audit faults keys on
|
|
7166
|
+
* reason and path, and keeps every `extra` fault carrying `symbol`, so two symbol keys of
|
|
7167
|
+
* one description stay two faults. The result preserves parser ownership, including union input identity.
|
|
7168
|
+
* A read failure returns its cause rather than throwing.
|
|
7169
|
+
* Snapshot a foreign object before repair, as Tool.execute does. A getter changing between
|
|
7170
|
+
* is and parse can publish a value that no recorded repair describes. A shallow snapshot only
|
|
7171
|
+
* stabilizes its own level; nested foreign values must also provide stable reads.
|
|
7172
|
+
*
|
|
7173
|
+
* @example
|
|
7174
|
+
* ```ts
|
|
7175
|
+
* repairValue(createContract(numberShape()), '3') // success carrying 3 and its type repair
|
|
7176
|
+
* ```
|
|
7177
|
+
*/
|
|
7178
|
+
export declare function repairValue<T>(contract: ContractInterface<T>, value: unknown): Result<ContractRepair<T>, ContractRefusal>;
|
|
7179
|
+
|
|
6452
7180
|
/**
|
|
6453
7181
|
* Represents a compiled coercive-domain diagnostic — the shape of
|
|
6454
7182
|
* `compileReporter` bound to one shape.
|
|
@@ -6469,7 +7197,7 @@ export declare type ReporterFunction = (value: unknown, path?: readonly string[]
|
|
|
6469
7197
|
* The root must satisfy {@link isRecord}; inherited properties are never fields.
|
|
6470
7198
|
* Intermediates may be objects or arrays indexed by string. Returns `undefined`
|
|
6471
7199
|
* the moment a segment is missing or lands on a non-object, so the lookup is
|
|
6472
|
-
* total — even against
|
|
7200
|
+
* total — even against an untrusted getter or Proxy trap that throws on read,
|
|
6473
7201
|
* contained through {@link attempt} so the throw never escapes.
|
|
6474
7202
|
*
|
|
6475
7203
|
* @param record - The source record
|
|
@@ -6585,7 +7313,10 @@ export declare function samplesToFormat(values: readonly unknown[]): SchemaForma
|
|
|
6585
7313
|
* An empty `samples` array infers the empty accept-anything schema `{}`.
|
|
6586
7314
|
* When every sample is a plain record, properties/required are unified
|
|
6587
7315
|
* per-key across all samples — a key
|
|
6588
|
-
* required iff present and non-`undefined` in every sample.
|
|
7316
|
+
* required iff present and non-`undefined` in every sample. The unified object
|
|
7317
|
+
* stays open whatever `closed` says when the key union is truncated, or when any
|
|
7318
|
+
* sample holds a member that is `undefined`, a non-enumerable string key, or a
|
|
7319
|
+
* symbol key. When any sample is not a plain record, the
|
|
6589
7320
|
* slot is inferred one value at a time (independent {@link valueToSchema}
|
|
6590
7321
|
* per sample, unified with {@link unifySchemas} — the same de-duplication and
|
|
6591
7322
|
* `anyOf` ordering an array's element schemas receive). `format`
|
|
@@ -6617,13 +7348,13 @@ export declare function samplesToSchema(samples: readonly unknown[], options?: V
|
|
|
6617
7348
|
* a finite non-negative integer, selecting a valid fallback for anything else.
|
|
6618
7349
|
*
|
|
6619
7350
|
* @remarks
|
|
6620
|
-
* Guards {@link valueToSchema} / {@link samplesToSchema} against
|
|
7351
|
+
* Guards {@link valueToSchema} / {@link samplesToSchema} against an untrusted or
|
|
6621
7352
|
* malformed budget: an unclamped `NaN` defeats every `depth <= 0` guard
|
|
6622
7353
|
* (`NaN <= 0` is `false`, so recursion never halts), and a negative
|
|
6623
7354
|
* `limits.properties` makes `slice(0, -1)` silently drop the LAST sorted key
|
|
6624
7355
|
* instead of capping the list (a fractional value has a similarly undefined
|
|
6625
7356
|
* `slice` bound). `Infinity` is rejected too — `Number.isInteger(Infinity)`
|
|
6626
|
-
* is `false` —
|
|
7357
|
+
* is `false` — because an unbounded budget is exactly the untrusted case the
|
|
6627
7358
|
* caps exist to prevent. A valid candidate passes through unchanged without
|
|
6628
7359
|
* inspecting the fallback. When the candidate is invalid, the fallback must
|
|
6629
7360
|
* satisfy the same finite non-negative-integer contract or this boundary
|
|
@@ -6651,7 +7382,7 @@ export declare function sanitizeBudget(value: number | undefined, fallback: numb
|
|
|
6651
7382
|
* @remarks
|
|
6652
7383
|
* {@link sanitizeBudget} decides the SHAPE of a budget and deliberately lets any
|
|
6653
7384
|
* finite non-negative integer through, because it must never read a fallback a
|
|
6654
|
-
*
|
|
7385
|
+
* untrusted caller supplied. That left the depth axis unbounded from above, and
|
|
6655
7386
|
* depth is the axis that recurses: `1e9` is a valid integer, so the walk descended
|
|
6656
7387
|
* until the call STACK failed, at a depth that varied between runs, and the
|
|
6657
7388
|
* refusal surfaced as an unreadable value rather than as the exhaustion the guard
|
|
@@ -6673,6 +7404,23 @@ export declare function sanitizeBudget(value: number | undefined, fallback: numb
|
|
|
6673
7404
|
*/
|
|
6674
7405
|
export declare function sanitizeDepth(value: number | undefined): number;
|
|
6675
7406
|
|
|
7407
|
+
/**
|
|
7408
|
+
* Lists the JSON Schema annotations a strict `schemaToShape` conversion admits on any node, frozen.
|
|
7409
|
+
*
|
|
7410
|
+
* @remarks
|
|
7411
|
+
* Each asserts nothing about a value, so a converted shape drops it without loss, except
|
|
7412
|
+
* `description`, which the shape keeps. A strict conversion admits them beside every
|
|
7413
|
+
* keyword it reads, the function leaf `{ not: {}, format: 'function' }` and the undefined
|
|
7414
|
+
* leaf `{ not: {}, format: 'undefined' }` included.
|
|
7415
|
+
*
|
|
7416
|
+
* @example
|
|
7417
|
+
* ```ts
|
|
7418
|
+
* SCHEMA_ANNOTATIONS.includes('title') // true
|
|
7419
|
+
* SCHEMA_ANNOTATIONS.at(-1) // 'examples'
|
|
7420
|
+
* ```
|
|
7421
|
+
*/
|
|
7422
|
+
export declare const SCHEMA_ANNOTATIONS: readonly ["title", "description", "$schema", "$id", "$comment", "deprecated", "readOnly", "writeOnly", "examples"];
|
|
7423
|
+
|
|
6676
7424
|
/**
|
|
6677
7425
|
* Owns the state of one JSON Schema snapshot operation.
|
|
6678
7426
|
*
|
|
@@ -6682,7 +7430,7 @@ export declare function sanitizeDepth(value: number | undefined): number;
|
|
|
6682
7430
|
* permanently. Success replays the exact frozen root; failure rethrows the
|
|
6683
7431
|
* exact class-owned error. Nonredirectable terminal settlement releases
|
|
6684
7432
|
* populated traversal state before publishing that result, while retaining
|
|
6685
|
-
* the source and exact result afterward. Reentry
|
|
7433
|
+
* the source and exact result afterward. Reentry invalidates the active operation
|
|
6686
7434
|
* and every later call with one shared cause-free error.
|
|
6687
7435
|
*
|
|
6688
7436
|
* @param schema - The JSON Schema graph to retain for cloning
|
|
@@ -6728,7 +7476,7 @@ export declare interface SchemaClonerInterface {
|
|
|
6728
7476
|
* Success and failure both release traversal frames and the active memo through
|
|
6729
7477
|
* preconstructed references before nonredirectable terminal publication, while
|
|
6730
7478
|
* retaining the source and the exact root or class-owned error. Active reentry
|
|
6731
|
-
* permanently settles the instance with one exact cause-free `clone`
|
|
7479
|
+
* permanently settles the instance with one exact cause-free `clone` refusal shared by
|
|
6732
7480
|
* the nested call, the outer call, and every later call, and a property-read cause
|
|
6733
7481
|
* stays exact.
|
|
6734
7482
|
*
|
|
@@ -6837,7 +7585,7 @@ export declare function schemaToParameters(schema: JSONSchema): Readonly<Record<
|
|
|
6837
7585
|
* `Set`, a class instance, a function, a symbol, a bigint, and readable cyclic
|
|
6838
7586
|
* hosts), which infer `{}` and widen back to an accept-anything
|
|
6839
7587
|
* {@link rawShape}. An unreadable host is refused by {@link valueToSchema}
|
|
6840
|
-
* before this law produces a schema; direct
|
|
7588
|
+
* before this law produces a schema; direct untrusted input to
|
|
6841
7589
|
* {@link schemaToShape} receives the same coded refusal.
|
|
6842
7590
|
* Widening is the only source of looseness. The law has three explicit host
|
|
6843
7591
|
* limits:
|
|
@@ -6879,7 +7627,9 @@ export declare function schemaToParameters(schema: JSONSchema): Readonly<Record<
|
|
|
6879
7627
|
*
|
|
6880
7628
|
* STRICT: `{ strict: true }` is the door for a foreign schema. It refuses, with
|
|
6881
7629
|
* code `structure`, every node the lenient walk would widen, every keyword it
|
|
6882
|
-
* would ignore (`pattern`, every `format` but `'date'` on a string node, `
|
|
7630
|
+
* would ignore (`pattern`, every `format` but `'date'` on a string node, `'interface'` on an
|
|
7631
|
+
* object node, and `'function'` or `'undefined'` in its leaf, every `not` outside those two
|
|
7632
|
+
* leaves, `nullable`,
|
|
6883
7633
|
* `patternProperties`, `propertyNames`, `prefixItems`, and anything else outside
|
|
6884
7634
|
* {@link STRICT_SCHEMA_KEYWORDS}), a malformed keyword or annotation, a boolean schema, an `enum` entry
|
|
6885
7635
|
* that is neither a finite primitive nor `null`, a contradictory bound, a date format whose
|
|
@@ -6888,9 +7638,16 @@ export declare function schemaToParameters(schema: JSONSchema): Readonly<Record<
|
|
|
6888
7638
|
* optional property to fill. An object with no `additionalProperties` closes
|
|
6889
7639
|
* rather than opens, and `oneOf` keeps exactly-one, because a strict walk reads
|
|
6890
7640
|
* every keyword that could keep two arms apart. Below a `oneOf` that object refuses
|
|
6891
|
-
* instead,
|
|
7641
|
+
* instead, because closing it could change which arms match. A strict conversion is the
|
|
6892
7642
|
* one walk that asserts a `format`: it reads `format: 'date'` on a string node as a
|
|
6893
|
-
* date string shape, so a compiled {@link dateShape} round-trips
|
|
7643
|
+
* date string shape, so a compiled {@link dateShape} round-trips, and it reads the function
|
|
7644
|
+
* leaf `{ not: {}, format: 'function' }` back as {@link functionShape} and the undefined
|
|
7645
|
+
* leaf `{ not: {}, format: 'undefined' }` back as {@link undefinedShape}, so a compiled
|
|
7646
|
+
* function or undefined shape round-trips too. It reads an object node with
|
|
7647
|
+
* `format: 'interface'` back as {@link interfaceShape}, each property outside `required` an
|
|
7648
|
+
* optional member, and refuses one without `additionalProperties: true` with code
|
|
7649
|
+
* `structure`, and one under a union or with a member `default` with code `placement`. A
|
|
7650
|
+
* lenient conversion reads that node as an open object.
|
|
6894
7651
|
*
|
|
6895
7652
|
* @param schema - The JSON Schema value to convert
|
|
6896
7653
|
* @param options - Optional `strict`, default `false`
|
|
@@ -7005,6 +7762,24 @@ export declare function setOf<T>(elementGuard: Guard<T>): Guard<ReadonlySet<T>>;
|
|
|
7005
7762
|
|
|
7006
7763
|
export declare function setOf(elementGuard: (value: unknown) => boolean): Guard<ReadonlySet<unknown>>;
|
|
7007
7764
|
|
|
7765
|
+
/**
|
|
7766
|
+
* Settles a callback's outcome, synchronous or awaited, as a {@link Result}.
|
|
7767
|
+
*
|
|
7768
|
+
* @remarks
|
|
7769
|
+
* Runs the callback one time. A synchronous throw, a rejection, and a thenable whose `then`
|
|
7770
|
+
* throws each answer a `Failure` carrying the exact thrown value, and the returned promise never
|
|
7771
|
+
* rejects. Use {@link attempt} where the callback is synchronous.
|
|
7772
|
+
*
|
|
7773
|
+
* @param callback - The callback to invoke with no arguments
|
|
7774
|
+
* @returns A `Success` carrying the awaited value, or a `Failure` carrying the exact thrown value
|
|
7775
|
+
*
|
|
7776
|
+
* @example
|
|
7777
|
+
* ```ts
|
|
7778
|
+
* const outcome = await settle(async () => readFile(path))
|
|
7779
|
+
* ```
|
|
7780
|
+
*/
|
|
7781
|
+
export declare function settle<T>(callback: () => T | PromiseLike<T>): Promise<Result<T>>;
|
|
7782
|
+
|
|
7008
7783
|
/**
|
|
7009
7784
|
* Lists the fields recognized for every contract declaration category, frozen.
|
|
7010
7785
|
*
|
|
@@ -7024,7 +7799,7 @@ export declare const SHAPE_FIELDS: Readonly<Record<string, readonly string[]>>;
|
|
|
7024
7799
|
* permanently. Success replays the exact frozen root; failure rethrows the
|
|
7025
7800
|
* exact class-owned or directly adopted error. Nonredirectable settlement
|
|
7026
7801
|
* releases populated traversal state before publishing that result. Reentry
|
|
7027
|
-
*
|
|
7802
|
+
* invalidates the active operation and every later call with one shared cause-free
|
|
7028
7803
|
* error.
|
|
7029
7804
|
*
|
|
7030
7805
|
* @param shape - The contract-shape graph to retain for cloning
|
|
@@ -7057,7 +7832,7 @@ export declare class ShapeCloner implements ShapeClonerInterface {
|
|
|
7057
7832
|
* shape or exact same owned {@link ContractError}. Nonredirectable terminal
|
|
7058
7833
|
* settlement releases populated traversal state before publishing that exact
|
|
7059
7834
|
* result, while retaining the source and result afterward.
|
|
7060
|
-
* Reentry permanently
|
|
7835
|
+
* Reentry permanently invalidates the active operation with one shared error.
|
|
7061
7836
|
*/
|
|
7062
7837
|
export declare interface ShapeClonerInterface {
|
|
7063
7838
|
/**
|
|
@@ -7072,7 +7847,7 @@ export declare interface ShapeClonerInterface {
|
|
|
7072
7847
|
* failure rethrows the exact class-owned or adopted {@link ContractError}. Both
|
|
7073
7848
|
* release graph-working state through preconstructed references before nonredirectable
|
|
7074
7849
|
* terminal publication. Active reentry permanently settles the instance with one exact
|
|
7075
|
-
* cause-free
|
|
7850
|
+
* cause-free refusal shared by the nested call, the outer call, and every later call.
|
|
7076
7851
|
*
|
|
7077
7852
|
* @returns The settled contract-shape snapshot
|
|
7078
7853
|
* @throws {ContractError} When the declaration is malformed, unreadable, cyclic, too deep, or cloning is reentered
|
|
@@ -7160,6 +7935,8 @@ export declare interface ShapeShapeOptions {
|
|
|
7160
7935
|
* `'date'` when `date: true`, else `'string'`); `optionalShape` /
|
|
7161
7936
|
* `nullableShape` project through to their inner shape's kind, and `rawShape`
|
|
7162
7937
|
* (an arbitrary embedded schema with no fixed kind) projects to `'json'`.
|
|
7938
|
+
* `functionShape` projects to `'function'`, `undefinedShape` to `'undefined'`, and
|
|
7939
|
+
* `interfaceShape` to `'object'`.
|
|
7163
7940
|
*
|
|
7164
7941
|
* A hand-authored node carrying an unrecognized discriminant is REFUSED rather
|
|
7165
7942
|
* than answered out of type, which keeps the declared non-optional
|
|
@@ -7185,7 +7962,7 @@ export declare function shapeToKind(shape: ContractShape): FaultKind;
|
|
|
7185
7962
|
* @remarks
|
|
7186
7963
|
* Construction performs no source observation. Every non-overlapping
|
|
7187
7964
|
* {@link validate} call starts a fresh pass over the source's current state.
|
|
7188
|
-
* Reentry
|
|
7965
|
+
* Reentry invalidates the active pass with one shared cause-free structure error;
|
|
7189
7966
|
* cleanup always restores an idle validator for the next independent call.
|
|
7190
7967
|
*
|
|
7191
7968
|
* @example
|
|
@@ -7296,13 +8073,14 @@ export declare function sortValues<T extends string | number>(values: readonly T
|
|
|
7296
8073
|
* Lists the JSON Schema keywords a strict `schemaToShape` conversion reads, frozen.
|
|
7297
8074
|
*
|
|
7298
8075
|
* @remarks
|
|
7299
|
-
* The keywords a shape can honour, plus
|
|
7300
|
-
*
|
|
7301
|
-
*
|
|
7302
|
-
*
|
|
7303
|
-
*
|
|
7304
|
-
*
|
|
7305
|
-
* as a
|
|
8076
|
+
* The keywords a shape can honour, plus {@link SCHEMA_ANNOTATIONS}. Every other keyword
|
|
8077
|
+
* refuses. `pattern`, `format`, and `not` are absent because no compiled shape asserts
|
|
8078
|
+
* them, so a schema holding one would convert to a shape wider than the schema it came
|
|
8079
|
+
* from. The exceptions are `format: 'date'` on a string node, which a strict conversion
|
|
8080
|
+
* reads as a date string shape, `format: 'interface'` on an object node, which it reads
|
|
8081
|
+
* as an interface shape, the function leaf `{ not: {}, format: 'function' }`,
|
|
8082
|
+
* which it reads as a function shape, and the undefined leaf
|
|
8083
|
+
* `{ not: {}, format: 'undefined' }`, which it reads as an undefined shape.
|
|
7306
8084
|
*
|
|
7307
8085
|
* @example
|
|
7308
8086
|
* ```ts
|
|
@@ -7553,6 +8331,58 @@ export declare function tupleOf<const Gs extends ReadonlyArray<Guard<unknown>>>(
|
|
|
7553
8331
|
|
|
7554
8332
|
export declare function tupleOf(...predicates: ReadonlyArray<(value: unknown) => boolean>): Guard<readonly unknown[]>;
|
|
7555
8333
|
|
|
8334
|
+
/**
|
|
8335
|
+
* Describes the `undefined` value — accepts only `undefined`.
|
|
8336
|
+
*
|
|
8337
|
+
* @remarks
|
|
8338
|
+
* The compiled guard is `isUndefined`. A container keeps a present `undefined` member wherever
|
|
8339
|
+
* its child admits `undefined`: this leaf, a union with such an arm, or a nullable over such an
|
|
8340
|
+
* inner. An object property present as `undefined` keeps its key in the parsed record, and an
|
|
8341
|
+
* absent one stays absent. JSON carries no `undefined`, so the emitted schema
|
|
8342
|
+
* `{ not: {}, format: 'undefined' }` admits no JSON instance. The generator returns `undefined`.
|
|
8343
|
+
*
|
|
8344
|
+
* @example
|
|
8345
|
+
* ```ts
|
|
8346
|
+
* const declaration: UndefinedShape = { category: 'undefined' }
|
|
8347
|
+
* createContract(declaration).is(undefined) // true
|
|
8348
|
+
* ```
|
|
8349
|
+
*/
|
|
8350
|
+
export declare interface UndefinedShape {
|
|
8351
|
+
readonly category: 'undefined';
|
|
8352
|
+
readonly description?: string;
|
|
8353
|
+
}
|
|
8354
|
+
|
|
8355
|
+
/**
|
|
8356
|
+
* Builds an {@link UndefinedShape}.
|
|
8357
|
+
*
|
|
8358
|
+
* @remarks
|
|
8359
|
+
* Compose it as a union arm to declare a member that may be `undefined`: an object property
|
|
8360
|
+
* present as `undefined` keeps its key, while `optionalShape` keeps declaring a property that may
|
|
8361
|
+
* be absent.
|
|
8362
|
+
*
|
|
8363
|
+
* @param options - Optional description
|
|
8364
|
+
* @returns An `undefined`-valued declaration
|
|
8365
|
+
*
|
|
8366
|
+
* @example
|
|
8367
|
+
* ```ts
|
|
8368
|
+
* const limits = objectShape({ max: unionShape(numberShape(), undefinedShape()) })
|
|
8369
|
+
* ```
|
|
8370
|
+
*/
|
|
8371
|
+
export declare function undefinedShape(options?: UndefinedShapeOptions): UndefinedShape;
|
|
8372
|
+
|
|
8373
|
+
/**
|
|
8374
|
+
* Configures the description of an `undefined`-valued declaration.
|
|
8375
|
+
*
|
|
8376
|
+
* @example
|
|
8377
|
+
* ```ts
|
|
8378
|
+
* const options: UndefinedShapeOptions = { description: 'No limit set' }
|
|
8379
|
+
* undefinedShape(options).description // 'No limit set'
|
|
8380
|
+
* ```
|
|
8381
|
+
*/
|
|
8382
|
+
export declare interface UndefinedShapeOptions {
|
|
8383
|
+
readonly description?: string;
|
|
8384
|
+
}
|
|
8385
|
+
|
|
7556
8386
|
/**
|
|
7557
8387
|
* Unifies a list of inferred `JSONSchema` fragments into one schema.
|
|
7558
8388
|
*
|
|
@@ -7571,7 +8401,7 @@ export declare function tupleOf(...predicates: ReadonlyArray<(value: unknown) =>
|
|
|
7571
8401
|
*
|
|
7572
8402
|
* A readable member {@link canonicalStringify} cannot key — a cyclic or
|
|
7573
8403
|
* otherwise JSON-inexpressible fragment, which only a direct caller can supply
|
|
7574
|
-
*
|
|
8404
|
+
* because the inferers always build plain encodable fragments — has NO
|
|
7575
8405
|
* de-duplication key, so it can participate in neither de-duplication nor the
|
|
7576
8406
|
* canonical-key ordering. It is KEPT (dropping a variant would narrow the
|
|
7577
8407
|
* union, and unification only ever widens), appended in input order after the
|
|
@@ -7617,7 +8447,10 @@ export declare function unionOf(...predicates: ReadonlyArray<(value: unknown) =>
|
|
|
7617
8447
|
* @remarks
|
|
7618
8448
|
* `mode` selects the emitted JSON Schema keyword and runtime matching rule:
|
|
7619
8449
|
* `'anyOf'` (default) accepts the first matching variant, while `'oneOf'`
|
|
7620
|
-
* requires exactly one variant to match.
|
|
8450
|
+
* requires exactly one variant to match. When every variant is an object
|
|
8451
|
+
* declaring one required literal property and a value's own data property
|
|
8452
|
+
* equals a literal only one variant holds, that variant answers alone in both
|
|
8453
|
+
* modes, at the guard as at the parser, the auditor, and the reporter.
|
|
7621
8454
|
*/
|
|
7622
8455
|
export declare interface UnionShape<V extends readonly ContractShape[] = readonly ContractShape[]> {
|
|
7623
8456
|
readonly category: 'union';
|
|
@@ -7632,9 +8465,9 @@ export declare interface UnionShape<V extends readonly ContractShape[] = readonl
|
|
|
7632
8465
|
* @remarks
|
|
7633
8466
|
* When every arm is an object declaring one required literal property, and a value's
|
|
7634
8467
|
* own property exactly equals a literal only one arm holds, that arm answers: `explain`
|
|
7635
|
-
* and `audit` report its faults at their real paths,
|
|
7636
|
-
* alone. Any other value reports `variant`, with `key`
|
|
7637
|
-
* have named an arm.
|
|
8468
|
+
* and `audit` report its faults at their real paths, `parse` repairs through it
|
|
8469
|
+
* alone, and `is` answers from it alone. Any other value reports `variant`, with `key`
|
|
8470
|
+
* and `expected` saying what would have named an arm.
|
|
7638
8471
|
*
|
|
7639
8472
|
* @param variants - The candidate shapes; the first match wins at runtime
|
|
7640
8473
|
* @returns A union shape whose `Infer` is the union of the variants
|
|
@@ -7712,7 +8545,11 @@ export declare function validateShape(shape: unknown): void;
|
|
|
7712
8545
|
* throws a `structure`
|
|
7713
8546
|
* {@link ContractError}; it never becomes `{}` or another permissive schema. Nested
|
|
7714
8547
|
* objects close to unknown keys (`additionalProperties: false`) by default;
|
|
7715
|
-
* pass `closed: false` to open them.
|
|
8548
|
+
* pass `closed: false` to open them. A record whose sampled keys are not every
|
|
8549
|
+
* key it owns stays open whatever `closed` says: one truncated by the breadth
|
|
8550
|
+
* budget, one holding a member that is `undefined`, and one holding a
|
|
8551
|
+
* non-enumerable string key or a symbol key, because a closed schema would refuse
|
|
8552
|
+
* the record it was inferred from. `format` (default `false`) opts a
|
|
7716
8553
|
* string/`Date` leaf into the `format` keyword. Structurally-equal inputs
|
|
7717
8554
|
* infer byte-identical schemas (object keys and `anyOf` members are sorted).
|
|
7718
8555
|
*
|