@orkestrel/contract 0.0.24 → 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 +4856 -3698
- package/dist/src/core/index.cjs.map +1 -1
- package/dist/src/core/index.d.cts +560 -112
- package/dist/src/core/index.d.ts +560 -112
- package/dist/src/core/index.js +4845 -3699
- package/dist/src/core/index.js.map +1 -1
- package/package.json +7 -7
|
@@ -380,7 +380,7 @@ export declare function buildKeyPlan(keys: readonly string[], guards: Readonly<R
|
|
|
380
380
|
* doors for the same reason. `expected` is the shape's own kind — `'integer'`
|
|
381
381
|
* when `integer: true`, otherwise `'number'` — so a caller reading the report
|
|
382
382
|
* sees the declaration's vocabulary rather than the value's. Order is
|
|
383
|
-
* `integer`,
|
|
383
|
+
* `integer`, `min`, `over`, `max`, then `under`. It refuses an unreadable shape through the
|
|
384
384
|
* same boundary and for the same reason {@link buildStringFaults} does.
|
|
385
385
|
*
|
|
386
386
|
* @param shape - The number shape whose refinements are checked
|
|
@@ -526,8 +526,8 @@ export declare function buildStringFaults(shape: StringShape, value: string, pat
|
|
|
526
526
|
* - cyclic input, tracked with the same ancestor-{@link WeakSet} discipline
|
|
527
527
|
* the container branches of value inference use, so a shared (non-cyclic)
|
|
528
528
|
* reference reached twice through different paths still encodes;
|
|
529
|
-
*
|
|
530
|
-
*
|
|
529
|
+
* An untrusted traversal is categorically different: a throwing own-getter,
|
|
530
|
+
* untrusted `ownKeys` trap, or revoked `Proxy` throws a `structure`
|
|
531
531
|
* {@link ContractError} through {@link readValue}. A caller can therefore
|
|
532
532
|
* distinguish "not JSON-encodable" from "could not be read".
|
|
533
533
|
*
|
|
@@ -553,6 +553,33 @@ export declare function buildStringFaults(shape: StringShape, value: string, pat
|
|
|
553
553
|
*/
|
|
554
554
|
export declare function canonicalStringify(value: unknown): string | undefined;
|
|
555
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
|
+
|
|
556
583
|
/**
|
|
557
584
|
* Caps at `1024` the number of choices one schema field may offer, frozen.
|
|
558
585
|
*
|
|
@@ -649,7 +676,7 @@ export declare function cloneJSONRecord(value: unknown): JSONRecord;
|
|
|
649
676
|
* wired. Array keys must be exactly `length` plus every canonical index.
|
|
650
677
|
* Writable and configurable index flags are normalized rather than treated as
|
|
651
678
|
* JSON data, so frozen arrays remain valid. Property descriptors are inspected
|
|
652
|
-
* without reading values through accessors, and every
|
|
679
|
+
* without reading values through accessors, and every untrusted reflective
|
|
653
680
|
* operation is contained before a new clone-coded error is exposed.
|
|
654
681
|
* Each call creates a fresh {@link JSONCloner}; use the class directly when
|
|
655
682
|
* terminal success or failure identity must be replayed without another read.
|
|
@@ -679,14 +706,14 @@ export declare function cloneJSONValue(value: unknown): JSONValue;
|
|
|
679
706
|
* references and closing cyclic edges onto their cloned nodes. Primitive
|
|
680
707
|
* values and own enumerable string-keyed edges are copied; record nodes use
|
|
681
708
|
* null prototypes, arrays retain only their intrinsic array prototype, and
|
|
682
|
-
* every produced object is frozen after its edges are wired.
|
|
709
|
+
* every produced object is frozen after its edges are wired. Untrusted traversal
|
|
683
710
|
* throws a clone-coded {@link ContractError}, never a caller-owned raw error.
|
|
684
711
|
* Each call creates a fresh {@link SchemaCloner}; use the class directly when
|
|
685
712
|
* terminal success or failure identity must be replayed without another read.
|
|
686
713
|
*
|
|
687
714
|
* @param schema - The JSON Schema graph to snapshot
|
|
688
715
|
* @returns A deeply cloned and frozen JSON Schema graph
|
|
689
|
-
* @throws {ContractError} When
|
|
716
|
+
* @throws {ContractError} When untrusted schema traversal prevents ownership
|
|
690
717
|
*
|
|
691
718
|
* @example
|
|
692
719
|
* ```ts
|
|
@@ -703,7 +730,7 @@ export declare function cloneSchema(schema: JSONSchema): JSONSchema;
|
|
|
703
730
|
* @remarks
|
|
704
731
|
* A fresh public {@link ShapeCloner} preserves shared-child identity while
|
|
705
732
|
* building the candidate snapshot, owns raw schemas, validates the exact
|
|
706
|
-
* completed root, applies deferred fidelity, and translates unexpected
|
|
733
|
+
* completed root, applies deferred fidelity, and translates unexpected untrusted
|
|
707
734
|
* failures. Inside the engine, each node's own data discriminant and every
|
|
708
735
|
* declared field are captured descriptor-first from two agreeing reads, and the
|
|
709
736
|
* carried population alone supplies its shallow shell, semantic checks, child
|
|
@@ -719,12 +746,12 @@ export declare function cloneSchema(schema: JSONSchema): JSONSchema;
|
|
|
719
746
|
* {@link cloneSchema}. Before return, a fresh {@link ShapeValidator} independently
|
|
720
747
|
* validates the exact cloned root. Ownership never erases a structural edge or
|
|
721
748
|
* normalizes an invalid scalar/bound into a plausible declaration: those
|
|
722
|
-
* inputs throw their coded structure/bound error.
|
|
749
|
+
* inputs throw their coded structure/bound error. Untrusted traversal remains
|
|
723
750
|
* distinct and throws a clone-coded {@link ContractError}.
|
|
724
751
|
*
|
|
725
752
|
* @param shape - The contract shape graph to snapshot
|
|
726
753
|
* @returns A deeply cloned and frozen shape graph
|
|
727
|
-
* @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
|
|
728
755
|
*
|
|
729
756
|
* @example
|
|
730
757
|
* ```ts
|
|
@@ -891,7 +918,7 @@ export declare const COMPILE_DEPTH_LIMIT = 512;
|
|
|
891
918
|
*
|
|
892
919
|
* This cap does not bound compilation, because the compilers do not expand a
|
|
893
920
|
* DAG. Every artifact family is one entry per unique node, so the boundary
|
|
894
|
-
* declaration
|
|
921
|
+
* preceding declaration compiles its unique nodes in about a millisecond.
|
|
895
922
|
* What does expand is what a CONSUMER materializes from the artifacts: the
|
|
896
923
|
* value `generate` builds, and the document a compiled schema serializes to,
|
|
897
924
|
* are trees of exactly this size. The cap survives as a bound on what a caller
|
|
@@ -920,7 +947,7 @@ export declare const COMPILE_NODE_LIMIT = 16384;
|
|
|
920
947
|
* evaluated for a valid declaration. The invariant relates two
|
|
921
948
|
* separate calls, so it holds for a value whose reads are stable across calls;
|
|
922
949
|
* see the read-stability precondition on {@link ContractInterface}. Every
|
|
923
|
-
* recursive call returns at most {@link FAULT_LIMIT} entries.
|
|
950
|
+
* recursive call returns at most {@link FAULT_LIMIT} entries. Untrusted property
|
|
924
951
|
* access raises the shared coded read refusal with the current container path
|
|
925
952
|
* and shape, so unreadability never masquerades as a type mismatch.
|
|
926
953
|
* It requests exactly the `auditor` root of a fresh {@link ContractCompiler}
|
|
@@ -1075,12 +1102,12 @@ export declare function compileParser(shape: ContractShape): Parser<unknown>;
|
|
|
1075
1102
|
* match" / "no consensus" summary fault prepended to its closest variant's
|
|
1076
1103
|
* faults — slices its return to at most {@link FAULT_LIMIT} entries, so the
|
|
1077
1104
|
* bound holds at every level of nesting rather than at the outermost container alone, on
|
|
1078
|
-
*
|
|
1105
|
+
* untrusted input (a huge array, a wide record, a wide union of wide
|
|
1079
1106
|
* records). A closed object's extra keys never
|
|
1080
1107
|
* fault — `parse` silently drops them, so `explain` mirrors that leniency, and
|
|
1081
1108
|
* {@link compileAuditor} is where they do fault; an open object with a
|
|
1082
1109
|
* constraining `additionalProperties` shape recurses extras against it instead.
|
|
1083
|
-
*
|
|
1110
|
+
* An untrusted getter or throwing `Proxy` trap is contained through {@link attempt}
|
|
1084
1111
|
* and surfaces as a single top-level type fault, never a throw, as
|
|
1085
1112
|
* `.claude/rules/patterns.md` § Validation and contracts requires.
|
|
1086
1113
|
* It requests exactly the `reporter` root of a fresh {@link ContractCompiler}
|
|
@@ -1349,14 +1376,16 @@ export declare type ContractCode =
|
|
|
1349
1376
|
* holds a union, because a union's membership question IS a guard question in
|
|
1350
1377
|
* all three, and every getter builds it when the graph holds a default, because
|
|
1351
1378
|
* a default that its inner shape refuses refuses at whichever artifact is read
|
|
1352
|
-
* 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.
|
|
1353
1382
|
*
|
|
1354
1383
|
* One terminal lifecycle covers preparation and every family. A failure settles
|
|
1355
1384
|
* the compiler: later getters rethrow that exact error, while an artifact
|
|
1356
1385
|
* already handed out keeps working, because each compiled artifact is
|
|
1357
1386
|
* self-contained. Reentry — reachable only through a caller accessor the
|
|
1358
|
-
* declaration itself exposes,
|
|
1359
|
-
* 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
|
|
1360
1389
|
* every later read with one shared cause-free error.
|
|
1361
1390
|
*
|
|
1362
1391
|
* @typeParam S - The declaration's shape type, which types the published artifacts
|
|
@@ -1395,13 +1424,15 @@ export declare class ContractCompiler<S extends ContractShape = ContractShape> i
|
|
|
1395
1424
|
get reporter(): ReporterFunction;
|
|
1396
1425
|
/** Returns the compiled seed-data source for the owned declaration. */
|
|
1397
1426
|
get generator(): SeederFunction<Infer<S>>;
|
|
1427
|
+
/** Returns the compiled owning admission for the owned declaration. */
|
|
1428
|
+
get owner(): OwnerFunction<Infer<S>>;
|
|
1398
1429
|
/**
|
|
1399
1430
|
* Returns the frozen bundle of this compiler's artifacts.
|
|
1400
1431
|
*
|
|
1401
1432
|
* @remarks
|
|
1402
1433
|
* Own enumerable keys `schema`, `is`, `parse`, `audit`, `explain`,
|
|
1403
|
-
* `generate`, in that order, each holding the exact value the
|
|
1404
|
-
* getter publishes.
|
|
1434
|
+
* `generate`, `own`, in that order, each holding the exact value the
|
|
1435
|
+
* corresponding getter publishes.
|
|
1405
1436
|
*/
|
|
1406
1437
|
get contract(): ContractInterface<Infer<S>>;
|
|
1407
1438
|
}
|
|
@@ -1415,9 +1446,12 @@ export declare class ContractCompiler<S extends ContractShape = ContractShape> i
|
|
|
1415
1446
|
* structural edge once into children-before-parent order; every artifact family
|
|
1416
1447
|
* is then one postorder pass over that index, so a shared child costs its
|
|
1417
1448
|
* authored nodes rather than its paths. A getter builds its own family and no
|
|
1418
|
-
* other, except where an artifact genuinely consumes
|
|
1419
|
-
* `
|
|
1420
|
-
* 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.
|
|
1421
1455
|
*
|
|
1422
1456
|
* Every getter REPLAYS its exact artifact: reading one twice returns the same
|
|
1423
1457
|
* function or graph by identity, and {@link contract}'s members are those
|
|
@@ -1425,7 +1459,7 @@ export declare class ContractCompiler<S extends ContractShape = ContractShape> i
|
|
|
1425
1459
|
* a failure anywhere settles the compiler permanently — later getters rethrow
|
|
1426
1460
|
* that exact error while an artifact already handed out stays usable, because
|
|
1427
1461
|
* each one is self-contained. Cross-getter reentry (only reachable through a
|
|
1428
|
-
* caller accessor the declaration exposes)
|
|
1462
|
+
* caller accessor the declaration exposes) invalidates the nested read, the
|
|
1429
1463
|
* interrupted outer read, and every later read with one shared cause-free
|
|
1430
1464
|
* error.
|
|
1431
1465
|
*
|
|
@@ -1440,11 +1474,11 @@ export declare class ContractCompiler<S extends ContractShape = ContractShape> i
|
|
|
1440
1474
|
* It declares no call-signature member, so its whole surface is the readonly data
|
|
1441
1475
|
* properties: `schema` (a {@link JSONSchema}), `guard` (a `Guard<Infer<S>>`), `parser`
|
|
1442
1476
|
* (a `Parser<Infer<S>>`), `auditor` (an {@link AuditorFunction}), `reporter` (a {@link
|
|
1443
|
-
* ReporterFunction}), `generator` (a `SeederFunction<Infer<S>>`),
|
|
1444
|
-
* `ContractInterface<Infer<S>>`). `contract` is the frozen
|
|
1445
|
-
* keys are `schema`, `is`, `parse`, `audit`, `explain`,
|
|
1446
|
-
* each holding the exact value the corresponding getter
|
|
1447
|
-
* 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.
|
|
1448
1482
|
*
|
|
1449
1483
|
* @example
|
|
1450
1484
|
* ```ts
|
|
@@ -1465,6 +1499,8 @@ export declare interface ContractCompilerInterface<S extends ContractShape> {
|
|
|
1465
1499
|
readonly reporter: ReporterFunction;
|
|
1466
1500
|
/** Returns the compiled seed-data source. */
|
|
1467
1501
|
readonly generator: SeederFunction<Infer<S>>;
|
|
1502
|
+
/** Returns the compiled owning admission. */
|
|
1503
|
+
readonly owner: OwnerFunction<Infer<S>>;
|
|
1468
1504
|
/** Returns the frozen bundle whose values are the artifacts declared earlier. */
|
|
1469
1505
|
readonly contract: ContractInterface<Infer<S>>;
|
|
1470
1506
|
}
|
|
@@ -1517,6 +1553,13 @@ export declare interface ContractErrorContext {
|
|
|
1517
1553
|
readonly limit?: number | string;
|
|
1518
1554
|
/** Holds the received-value description associated with the error. */
|
|
1519
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[];
|
|
1520
1563
|
}
|
|
1521
1564
|
|
|
1522
1565
|
/**
|
|
@@ -1542,9 +1585,9 @@ export declare interface ContractErrorOptions {
|
|
|
1542
1585
|
* Built by `createContract`: `is` narrows, `audit` diagnoses strict rejection,
|
|
1543
1586
|
* `parse` coerces (returning the typed value or `undefined`), `schema` is an
|
|
1544
1587
|
* owned deeply frozen emitted JSON Schema, `explain` reports the structured
|
|
1545
|
-
* faults behind a failed `parse`,
|
|
1588
|
+
* faults behind a failed `parse`, `generate` produces deterministic seed
|
|
1546
1589
|
* data from a {@link RandomFunction} (defaulting to a wall-clock-seeded source
|
|
1547
|
-
* when none is supplied).
|
|
1590
|
+
* when none is supplied), and `own` admits an owned snapshot of a value.
|
|
1548
1591
|
*
|
|
1549
1592
|
* LOCKSTEP means derived from one owned snapshot of the shape, not agreeing on
|
|
1550
1593
|
* which values to accept: `is` and `schema` describe the contract's canonical
|
|
@@ -1575,8 +1618,8 @@ export declare interface ContractInterface<T> {
|
|
|
1575
1618
|
* Coercion (`'36'` → `36`) and every leaf refinement (`min` / `max` /
|
|
1576
1619
|
* `pattern`) both apply, so every non-`undefined` result satisfies `is`.
|
|
1577
1620
|
* Honest invalidity answers `undefined`, while a failed required object,
|
|
1578
|
-
* JSON, or dense-array index read throws the shared coded
|
|
1579
|
-
* outcomes stay distinguishable.
|
|
1621
|
+
* interface member, JSON, or dense-array index read throws the shared coded
|
|
1622
|
+
* refusal — the two outcomes stay distinguishable.
|
|
1580
1623
|
*
|
|
1581
1624
|
* @param value - The value to coerce
|
|
1582
1625
|
* @returns The typed value, or `undefined` when the value is readable and invalid
|
|
@@ -1610,7 +1653,8 @@ export declare interface ContractInterface<T> {
|
|
|
1610
1653
|
* value whose reads are stable across calls (see the read-stability
|
|
1611
1654
|
* precondition on {@link ContractInterface}) — explain mirrors `parse`'s
|
|
1612
1655
|
* coercion, not the stricter `is`, and `audit` is the report that mirrors
|
|
1613
|
-
* `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).
|
|
1614
1658
|
*
|
|
1615
1659
|
* @param value - The value to check
|
|
1616
1660
|
* @returns The faults found, empty when the value parses successfully
|
|
@@ -1629,6 +1673,19 @@ export declare interface ContractInterface<T> {
|
|
|
1629
1673
|
* @throws {ContractError} When the declaration cannot be satisfied, or when the sample source fails
|
|
1630
1674
|
*/
|
|
1631
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>;
|
|
1632
1689
|
}
|
|
1633
1690
|
|
|
1634
1691
|
/**
|
|
@@ -1669,7 +1726,7 @@ export declare interface ContractRepair<T> {
|
|
|
1669
1726
|
* element shape, an `ObjectShape` a map of them). {@link validateShape}
|
|
1670
1727
|
* enforces an acyclic graph within {@link COMPILE_DEPTH_LIMIT}.
|
|
1671
1728
|
*/
|
|
1672
|
-
export declare type ContractShape = StringShape | NumberShape | BooleanShape | NullShape | LiteralShape | ArrayShape | ObjectShape | UnionShape | OptionalShape | NullableShape | JSONShape | ShapeShape | FunctionShape | RawShape;
|
|
1729
|
+
export declare type ContractShape = StringShape | NumberShape | BooleanShape | NullShape | LiteralShape | ArrayShape | ObjectShape | UnionShape | OptionalShape | NullableShape | JSONShape | ShapeShape | FunctionShape | UndefinedShape | InterfaceShape | RawShape;
|
|
1673
1730
|
|
|
1674
1731
|
/**
|
|
1675
1732
|
* Compiles a {@link ContractShape} into a {@link ContractInterface} — the
|
|
@@ -1701,7 +1758,7 @@ export declare type ContractShape = StringShape | NumberShape | BooleanShape | N
|
|
|
1701
1758
|
* to touch, so the failure arrives at the call the caller made — carrying the
|
|
1702
1759
|
* authoring door's own diagnosis, which this door adopts rather than rewraps.
|
|
1703
1760
|
* Every compiled member is self-contained, and the compiler this call builds
|
|
1704
|
-
* releases its working set
|
|
1761
|
+
* releases its working set after every member has compiled. The contract keeps
|
|
1705
1762
|
* part of the declaration even so: the auditor and reporter plans close over the
|
|
1706
1763
|
* leaf and array nodes they read their bounds from, and a contract with deferred
|
|
1707
1764
|
* members retains its declaration. Nothing the caller keeps reaches back into the
|
|
@@ -1711,7 +1768,7 @@ export declare type ContractShape = StringShape | NumberShape | BooleanShape | N
|
|
|
1711
1768
|
* diagnostics and generator refuse.
|
|
1712
1769
|
*
|
|
1713
1770
|
* @param shape - The shape to compile
|
|
1714
|
-
* @returns A contract bundling `schema` / `is` / `parse` / `audit` / `explain` / `generate`
|
|
1771
|
+
* @returns A contract bundling `schema` / `is` / `parse` / `audit` / `explain` / `generate` / `own`
|
|
1715
1772
|
*
|
|
1716
1773
|
* @example Compiling a contract
|
|
1717
1774
|
* ```ts
|
|
@@ -1871,7 +1928,7 @@ export declare function describeFaults(faults: readonly AuditFault[], schema?: J
|
|
|
1871
1928
|
* carries code `random` and never the `generate` code, and {@link compileGenerator}
|
|
1872
1929
|
* rethrows it at whatever draw depth it happened instead of rotating to the next union
|
|
1873
1930
|
* variant. The diagnostic names the consuming shape category, the `[0, 1)` limit, and a
|
|
1874
|
-
* 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
|
|
1875
1932
|
* object runs no conversion hook while the diagnostic is built and a primitive symbol
|
|
1876
1933
|
* renders without consulting mutable `Symbol.prototype.toString`.
|
|
1877
1934
|
*
|
|
@@ -1944,7 +2001,7 @@ export declare type EntryCollectorFunction = (value: unknown, key: unknown) => v
|
|
|
1944
2001
|
* This is the package-wide runtime property view used by compiled object
|
|
1945
2002
|
* guards, parsers, reporters, schema inference, and owned schema cloning. It
|
|
1946
2003
|
* matches the object-key view serialized by `JSON.stringify`: inherited,
|
|
1947
|
-
* symbol, and non-enumerable properties are excluded.
|
|
2004
|
+
* symbol, and non-enumerable properties are excluded. An untrusted Proxy trap
|
|
1948
2005
|
* returns `undefined` rather than escaping.
|
|
1949
2006
|
*
|
|
1950
2007
|
* @param value - The object whose keys to snapshot
|
|
@@ -2027,6 +2084,19 @@ export declare function enumOf<const E extends Record<string, string | number>>(
|
|
|
2027
2084
|
*/
|
|
2028
2085
|
export declare function errorToMessage(error: unknown): string;
|
|
2029
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
|
+
|
|
2030
2100
|
/**
|
|
2031
2101
|
* Escapes every regular-expression metacharacter in a text, so the text
|
|
2032
2102
|
* matches literally inside a larger `RegExp` source.
|
|
@@ -2154,7 +2224,8 @@ export declare function failure<E>(error: E): Failure<E>;
|
|
|
2154
2224
|
* @remarks
|
|
2155
2225
|
* A discriminated union on `reason`:
|
|
2156
2226
|
* - `'type'` — the value could not coerce to `expected` at all.
|
|
2157
|
-
* - `'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`.
|
|
2158
2229
|
* - `'constraint'` — the value coerced to `expected` but violated one
|
|
2159
2230
|
* refinement (`min` / `max` / `pattern` / `date` / `integer`); `limit` carries the
|
|
2160
2231
|
* violated bound/pattern when applicable.
|
|
@@ -2228,9 +2299,9 @@ export declare const FAULT_KINDS: readonly FaultKind[];
|
|
|
2228
2299
|
* `explain` or `audit` report ever returns, frozen.
|
|
2229
2300
|
*
|
|
2230
2301
|
* @remarks
|
|
2231
|
-
* Bounds BOTH reports against
|
|
2302
|
+
* Bounds BOTH reports against untrusted input (a giant array, a wide record)
|
|
2232
2303
|
* — `compileReporter` and `compileAuditor` each collect faults in stable
|
|
2233
|
-
* pre-order and stop
|
|
2304
|
+
* pre-order and stop after this cap is reached, and every recursive call slices
|
|
2234
2305
|
* to it, so the report size (and the work to build it) stays finite and
|
|
2235
2306
|
* deterministic at every nesting level regardless of the input's size. Size a
|
|
2236
2307
|
* diagnostic surface off this constant and it bounds `audit` exactly as it
|
|
@@ -2251,9 +2322,9 @@ export declare const FAULT_TEXT_LIMIT = 2048;
|
|
|
2251
2322
|
* Names the refinement a {@link Fault} of reason `'constraint'` violates.
|
|
2252
2323
|
*
|
|
2253
2324
|
* @remarks
|
|
2254
|
-
* The vocabulary is `'min'`, `'max'`, `'pattern'`, `'date'`, and `'integer'`.
|
|
2325
|
+
* The vocabulary is `'min'`, `'over'`, `'max'`, `'under'`, `'pattern'`, `'date'`, and `'integer'`.
|
|
2255
2326
|
*/
|
|
2256
|
-
export declare type FaultConstraint = 'min' | 'max' | 'pattern' | 'date' | 'integer';
|
|
2327
|
+
export declare type FaultConstraint = 'min' | 'over' | 'max' | 'under' | 'pattern' | 'date' | 'integer';
|
|
2257
2328
|
|
|
2258
2329
|
/**
|
|
2259
2330
|
* Names the kind of value a {@link Fault} expected — the shape-projected counterpart of
|
|
@@ -2261,9 +2332,10 @@ export declare type FaultConstraint = 'min' | 'max' | 'pattern' | 'date' | 'inte
|
|
|
2261
2332
|
*
|
|
2262
2333
|
* @remarks
|
|
2263
2334
|
* The vocabulary is `'string'`, `'date'`, `'number'`, `'integer'`, `'boolean'`, `'null'`,
|
|
2264
|
-
* `'literal'`, `'array'`, `'object'`, `'union'`, `'json'`, `'shape'`,
|
|
2335
|
+
* `'literal'`, `'array'`, `'object'`, `'union'`, `'json'`, `'shape'`, `'function'`, and
|
|
2336
|
+
* `'undefined'`.
|
|
2265
2337
|
*/
|
|
2266
|
-
export declare type FaultKind = 'string' | 'date' | 'number' | 'integer' | 'boolean' | 'null' | 'literal' | 'array' | 'object' | 'union' | 'json' | 'shape' | 'function';
|
|
2338
|
+
export declare type FaultKind = 'string' | 'date' | 'number' | 'integer' | 'boolean' | 'null' | 'literal' | 'array' | 'object' | 'union' | 'json' | 'shape' | 'function' | 'undefined';
|
|
2267
2339
|
|
|
2268
2340
|
/**
|
|
2269
2341
|
* Retains a lazily built fault declaration without building shapes during module evaluation.
|
|
@@ -2579,7 +2651,7 @@ export declare function holds(callback: () => boolean): boolean;
|
|
|
2579
2651
|
* full union is a fixed point that can never shrink — the compiler would fan
|
|
2580
2652
|
* out until it aborts with TS2589. Bailing out lazily short-circuits that
|
|
2581
2653
|
* fixed point (the untaken branch is never instantiated) while every narrow
|
|
2582
|
-
* shape and every partial union still flows through the exact chain
|
|
2654
|
+
* shape and every partial union still flows through the exact following chain.
|
|
2583
2655
|
*
|
|
2584
2656
|
* The `ObjectShape` branch's `additionalProperties` guard (`[A] extends
|
|
2585
2657
|
* [boolean | ContractShape]`) is likewise wrapped in a tuple to stay
|
|
@@ -2605,7 +2677,18 @@ export declare type Infer<S extends ContractShape> = [ContractShape] extends [S]
|
|
|
2605
2677
|
} ? I extends ContractShape ? Infer<I> | undefined : never : S extends {
|
|
2606
2678
|
readonly category: 'nullable';
|
|
2607
2679
|
readonly inner: infer I;
|
|
2608
|
-
} ? 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;
|
|
2609
2692
|
|
|
2610
2693
|
/**
|
|
2611
2694
|
* Caps by default at `256` the number of object properties / array elements {@link
|
|
@@ -2622,7 +2705,7 @@ export declare const INFER_BREADTH_LIMIT = 256;
|
|
|
2622
2705
|
* Caps at `32` the object/array nesting depth {@link valueToSchema} walks, frozen.
|
|
2623
2706
|
*
|
|
2624
2707
|
* @remarks
|
|
2625
|
-
* Bounds inference against
|
|
2708
|
+
* Bounds inference against untrusted or cyclic runtime input — after the
|
|
2626
2709
|
* remaining depth budget reaches zero, inference stops descending and emits
|
|
2627
2710
|
* the empty accept-anything schema `{}` for that branch instead of recursing
|
|
2628
2711
|
* further. LOWERABLE per call through {@link ValueToSchemaLimits.depth}; a
|
|
@@ -2742,7 +2825,7 @@ export declare type InferOpenIndex<A extends boolean | ContractShape> = [A] exte
|
|
|
2742
2825
|
* Fires only when ALL of: every value is the same primitive kind (all string
|
|
2743
2826
|
* or all FINITE number through {@link isFiniteNumber} — any `null`/boolean/mixed
|
|
2744
2827
|
* slot never qualifies, and a slot containing `NaN` / `±Infinity` never
|
|
2745
|
-
* qualifies either,
|
|
2828
|
+
* qualifies either, because {@link canonicalStringify} collapses `NaN` to
|
|
2746
2829
|
* `'null'` and would otherwise risk an invalid-JSON `enum`); at least 2
|
|
2747
2830
|
* values are given; the distinct-by-{@link canonicalStringify} count is LESS
|
|
2748
2831
|
* than the value count (repetition required — separates a categorical column
|
|
@@ -2806,10 +2889,76 @@ export declare function instanceOf<C extends abstract new (...args: never) => ob
|
|
|
2806
2889
|
*
|
|
2807
2890
|
* @param options - Optional bounds and `description` (no `integer` key)
|
|
2808
2891
|
* @returns An integer number shape
|
|
2809
|
-
* @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
|
|
2810
2893
|
*/
|
|
2811
2894
|
export declare function integerShape(options?: Omit<NumberShapeOptions, 'integer'>): NumberShape;
|
|
2812
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
|
+
|
|
2813
2962
|
/** Intersects the types guarded by a tuple of guards — backs `intersectionOf`. */
|
|
2814
2963
|
export declare type IntersectionFromGuards<Gs extends ReadonlyArray<Guard<unknown>>> = UnionToIntersection<GuardType<Gs[number]>>;
|
|
2815
2964
|
|
|
@@ -2852,7 +3001,7 @@ export declare function intersectionOf(...predicates: ReadonlyArray<(value: unkn
|
|
|
2852
3001
|
* installed at the moment THIS module evaluated, and reading it later, at the
|
|
2853
3002
|
* call site, is reading whatever the caller most recently installed. "Before any
|
|
2854
3003
|
* caller code runs" is the tempting phrasing and it is false in exactly the case
|
|
2855
|
-
* the limit
|
|
3004
|
+
* the following limit names, so it is not used.
|
|
2856
3005
|
*
|
|
2857
3006
|
* The limit that follows, stated as a limit rather than as a guarantee: capture
|
|
2858
3007
|
* is only as early as this package's own evaluation. A consumer module that
|
|
@@ -2863,7 +3012,7 @@ export declare function intersectionOf(...predicates: ReadonlyArray<(value: unkn
|
|
|
2863
3012
|
* package wholesale rather than bother with the table, so it is named here
|
|
2864
3013
|
* instead of defended.
|
|
2865
3014
|
*
|
|
2866
|
-
* 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
|
|
2867
3016
|
* where to go: **every host operation this package dispatches by name whose
|
|
2868
3017
|
* result a published answer depends on.** That admits statics, constructors and
|
|
2869
3018
|
* namespaces, and — this is the part the earlier wording got wrong by writing
|
|
@@ -2949,7 +3098,7 @@ export declare const INTRINSICS: Readonly<{
|
|
|
2949
3098
|
base: Object;
|
|
2950
3099
|
/**
|
|
2951
3100
|
* Captures the proxy-visible operations, grouped because that is what separates them:
|
|
2952
|
-
* 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
|
|
2953
3102
|
* reports the target's.
|
|
2954
3103
|
*
|
|
2955
3104
|
* @remarks
|
|
@@ -3080,6 +3229,8 @@ export declare const INTRINSICS: Readonly<{
|
|
|
3080
3229
|
indices: () => ArrayIterator<number>;
|
|
3081
3230
|
/** Captures the native array iterator advance operation. */
|
|
3082
3231
|
advance: any;
|
|
3232
|
+
/** Captures `String.prototype.slice` — the window a preview encodes, dispatched through `apply`. */
|
|
3233
|
+
slice: (start?: number, end?: number) => string;
|
|
3083
3234
|
/** Captures `Array.prototype.join` — text assembly from derived parts. */
|
|
3084
3235
|
join: (separator?: string) => string;
|
|
3085
3236
|
/** Captures `Function.prototype.bind` for a receiver-bound host operation. */
|
|
@@ -3348,6 +3499,26 @@ export declare function isBoundedJSONRecord(value: unknown): value is JSONRecord
|
|
|
3348
3499
|
*/
|
|
3349
3500
|
export declare function isBoundedJSONValue(value: unknown): value is JSONValue;
|
|
3350
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
|
+
|
|
3351
3522
|
/**
|
|
3352
3523
|
* Determines whether a value can be used as a `new`-target constructor.
|
|
3353
3524
|
*
|
|
@@ -3795,7 +3966,7 @@ export declare function isJSONPrimitive(value: unknown): value is JSONPrimitive;
|
|
|
3795
3966
|
* instances, class instances, `NaN`, and `±Infinity`. Arrays and plain records
|
|
3796
3967
|
* are walked with an ancestor set so recursive input fails instead of hanging.
|
|
3797
3968
|
* The whole walk runs inside `holds`, as `.claude/rules/patterns.md`
|
|
3798
|
-
* § Validation and contracts requires:
|
|
3969
|
+
* § Validation and contracts requires: an untrusted getter on a
|
|
3799
3970
|
* record property, or a revoked `Proxy` anywhere in the structure, is caught
|
|
3800
3971
|
* and yields `false` instead of escaping as a thrown error.
|
|
3801
3972
|
*
|
|
@@ -4086,12 +4257,14 @@ export declare function isPromiseLike<T = unknown>(value: unknown): value is Pro
|
|
|
4086
4257
|
* The total form of the shared {@link matchesRecordBrand} rule, and the only
|
|
4087
4258
|
* one a guard may use: the whole brand runs inside `holds`, as
|
|
4088
4259
|
* `.claude/rules/patterns.md` § Validation and contracts requires, so a
|
|
4089
|
-
* revoked `Proxy` or
|
|
4260
|
+
* revoked `Proxy` or an untrusted `getPrototypeOf` trap answers `false` instead of
|
|
4090
4261
|
* escaping as a thrown error. Use instead of {@link isObject} to distinguish a
|
|
4091
4262
|
* plain `{}` / `Object.create(null)` — or a plain object from another realm,
|
|
4092
4263
|
* whose prototype is that realm's `Object.prototype` — from arrays, `Date`,
|
|
4093
4264
|
* `Map`, and class instances, including a class whose prototype a caller
|
|
4094
|
-
* 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}.
|
|
4095
4268
|
*
|
|
4096
4269
|
* @param value - The value to inspect
|
|
4097
4270
|
* @returns True if the value is a plain record; false otherwise
|
|
@@ -4111,7 +4284,7 @@ export declare function isRecord(value: unknown): value is Record<string, unknow
|
|
|
4111
4284
|
* @remarks
|
|
4112
4285
|
* A total native internal-slot brand check rather than a property read: it accepts a
|
|
4113
4286
|
* genuine pattern from this realm and from another, and refuses a proxy or a hand-built
|
|
4114
|
-
*
|
|
4287
|
+
* fake without reading an advertised field.
|
|
4115
4288
|
*
|
|
4116
4289
|
* @param value - The value to inspect
|
|
4117
4290
|
* @returns True if the value is a `RegExp`; false otherwise
|
|
@@ -4124,6 +4297,23 @@ export declare function isRecord(value: unknown): value is Record<string, unknow
|
|
|
4124
4297
|
*/
|
|
4125
4298
|
export declare function isRegExp(value: unknown): value is RegExp;
|
|
4126
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
|
+
|
|
4127
4317
|
/** Determines whether a value is a `Set`.
|
|
4128
4318
|
*
|
|
4129
4319
|
* @param value - The value to inspect
|
|
@@ -4396,7 +4586,7 @@ export declare const JSON_SCHEMA_TYPES: readonly JSONSchemaType[];
|
|
|
4396
4586
|
* permanently. Success replays the exact frozen root; failure rethrows the
|
|
4397
4587
|
* exact class-owned error. Nonredirectable terminal failure releases partial
|
|
4398
4588
|
* traversal working state while retaining the source and exact error. Reentry
|
|
4399
|
-
*
|
|
4589
|
+
* invalidates the active operation and every later call with one shared cause-free
|
|
4400
4590
|
* error.
|
|
4401
4591
|
*
|
|
4402
4592
|
* @param value - The unknown value to retain for cloning
|
|
@@ -4446,7 +4636,7 @@ export declare interface JSONClonerInterface {
|
|
|
4446
4636
|
* loaded and read every diagnostic option as an own property, so terminal settlement
|
|
4447
4637
|
* stays nonredirectable against a replaced intrinsic and against a polluted prototype
|
|
4448
4638
|
* alike. Active reentry permanently settles the instance with one exact cause-free
|
|
4449
|
-
* `clone`
|
|
4639
|
+
* `clone` refusal shared by the nested call, the outer call, and every later call.
|
|
4450
4640
|
*
|
|
4451
4641
|
* @param budget - Remaining nodes shared with an enclosing ownership operation; omitted for an independent snapshot
|
|
4452
4642
|
* @returns The settled JSON snapshot
|
|
@@ -4513,6 +4703,8 @@ export declare interface JSONSchema {
|
|
|
4513
4703
|
readonly format?: string;
|
|
4514
4704
|
readonly minimum?: number;
|
|
4515
4705
|
readonly maximum?: number;
|
|
4706
|
+
readonly exclusiveMinimum?: number;
|
|
4707
|
+
readonly exclusiveMaximum?: number;
|
|
4516
4708
|
readonly minItems?: number;
|
|
4517
4709
|
readonly maxItems?: number;
|
|
4518
4710
|
readonly items?: JSONSchema;
|
|
@@ -4576,7 +4768,7 @@ export declare interface JSONShapeOptions {
|
|
|
4576
4768
|
*
|
|
4577
4769
|
* @remarks
|
|
4578
4770
|
* The static type admits any `number` because TypeScript cannot express
|
|
4579
|
-
* finiteness. The {@link isJSONValue} guard rejects `NaN` and `±Infinity`
|
|
4771
|
+
* finiteness. The {@link isJSONValue} guard rejects `NaN` and `±Infinity` because
|
|
4580
4772
|
* they have no JSON representation.
|
|
4581
4773
|
*
|
|
4582
4774
|
* @example
|
|
@@ -4658,7 +4850,7 @@ export declare interface KeyStep {
|
|
|
4658
4850
|
* Each lazy guard tracks its active invocation depth. An invocation that would
|
|
4659
4851
|
* exceed {@link GUARD_DEPTH_LIMIT} returns `false` before resolving `thunk`; the
|
|
4660
4852
|
* counter always unwinds after the contained call, so one deep or cyclic input
|
|
4661
|
-
* cannot
|
|
4853
|
+
* cannot corrupt later guard calls.
|
|
4662
4854
|
*
|
|
4663
4855
|
* @param thunk - The factory producing the guard to apply, called on every invocation
|
|
4664
4856
|
* @returns A guard deferring each call to the thunk's guard
|
|
@@ -4805,6 +4997,26 @@ export declare function mapOf(keyPredicate: (value: unknown) => boolean, valuePr
|
|
|
4805
4997
|
*/
|
|
4806
4998
|
export declare function matchesCalendarDate(value: string): boolean;
|
|
4807
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
|
+
|
|
4808
5020
|
/**
|
|
4809
5021
|
* Checks whether an object owns no key outside the enumerable string keys already read from it.
|
|
4810
5022
|
*
|
|
@@ -4879,7 +5091,7 @@ export declare function matchesISOInstant(value: string): boolean;
|
|
|
4879
5091
|
* the alias already fit. Arrays are traversed through their reflected
|
|
4880
5092
|
* own-index population, so sparse work is proportional to populated entries
|
|
4881
5093
|
* rather than advertised length. Every observable operation is contained;
|
|
4882
|
-
*
|
|
5094
|
+
* untrusted or contradictory reads return `false`.
|
|
4883
5095
|
*
|
|
4884
5096
|
* The walk carries a settled-depth memo beside its active-path set: a
|
|
4885
5097
|
* container that fit at depth `d` also fits at any depth `<= d`, because every
|
|
@@ -4967,7 +5179,7 @@ export declare function matchesKeyPlan(this: readonly string[], plan: readonly K
|
|
|
4967
5179
|
* `parse`'s coercions are published and form input relies on them, but some change what
|
|
4968
5180
|
* a value means: `1` to `true`, `'9007199254740993'` to `...992`, `'1e-400'` to `0`,
|
|
4969
5181
|
* `'0x10'` to `16`. A door that must not guess asks this about each fault `audit` reported,
|
|
4970
|
-
*
|
|
5182
|
+
* because `audit` already names every nested repair with its path and the kind it wanted.
|
|
4971
5183
|
*
|
|
4972
5184
|
* Only a `type` fault is a repair. A number needs a string whose trim is the number's own
|
|
4973
5185
|
* text, so `'30'` and `' 30 '` pass while `'30.0'`, `'007'`, `'0x10'`, `'1e3'`, `'+5'`,
|
|
@@ -5035,7 +5247,7 @@ export declare function matchesMember(members: ReadonlySet<unknown>, value: unkn
|
|
|
5035
5247
|
export declare function matchesPattern(pattern: RegExp, value: string): boolean;
|
|
5036
5248
|
|
|
5037
5249
|
/**
|
|
5038
|
-
* Determines whether a value carries the plain-record brand, raising
|
|
5250
|
+
* Determines whether a value carries the plain-record brand, raising an untrusted
|
|
5039
5251
|
* prototype observation instead of answering it.
|
|
5040
5252
|
*
|
|
5041
5253
|
* @remarks
|
|
@@ -5051,14 +5263,14 @@ export declare function matchesPattern(pattern: RegExp, value: string): boolean;
|
|
|
5051
5263
|
* therefore identified by the own members ECMAScript requires every realm to
|
|
5052
5264
|
* put on it (`constructor`, `hasOwnProperty`, `isPrototypeOf`,
|
|
5053
5265
|
* `propertyIsEnumerable`, `toLocaleString`, `toString`, `valueOf`), each read
|
|
5054
|
-
* through its own DESCRIPTOR so no accessor on
|
|
5266
|
+
* through its own DESCRIPTOR so no accessor on an untrusted prototype ever runs.
|
|
5055
5267
|
* Each must be an own DATA property whose value is a FUNCTION — true of every
|
|
5056
5268
|
* conformant realm, so the requirement costs a genuine foreign record nothing,
|
|
5057
|
-
* and it refuses the cheapest
|
|
5269
|
+
* and it refuses the cheapest fake (stamping the mandated names with
|
|
5058
5270
|
* `undefined`) for free.
|
|
5059
5271
|
*
|
|
5060
5272
|
* That is a structural test, not a provenance one, and the residual is stated
|
|
5061
|
-
* as exactly what it is: a FUNCTION-VALUED
|
|
5273
|
+
* as exactly what it is: a FUNCTION-VALUED fake passes, and this realm's own
|
|
5062
5274
|
* `Object.prototype` supplies those functions to stamp, so the price is a
|
|
5063
5275
|
* few lines rather than nothing. Reparenting a class prototype to `null` and
|
|
5064
5276
|
* stamping the mandated names with real functions passes; so does leaving the
|
|
@@ -5066,31 +5278,31 @@ export declare function matchesPattern(pattern: RegExp, value: string): boolean;
|
|
|
5066
5278
|
* `null` as its own prototype and answers those descriptor reads with
|
|
5067
5279
|
* functions. In both cases the value is a live class instance whose methods are
|
|
5068
5280
|
* still reachable on it. A further own-key SUBSET rule buys even less: it
|
|
5069
|
-
* refuses a
|
|
5281
|
+
* refuses a fake that left methods on its prototype and accepts the same
|
|
5070
5282
|
* class with those methods moved onto the instance, where they are
|
|
5071
5283
|
* indistinguishable from a plain record's function
|
|
5072
|
-
* properties — so it raises the
|
|
5284
|
+
* properties — so it raises the fake's price and narrows the realm-agnostic
|
|
5073
5285
|
* arm this rule exists to keep open. What the pass buys is acceptance at
|
|
5074
5286
|
* brand-governed doors and nothing after it: every ownership engine publishes a
|
|
5075
5287
|
* frozen plain record built only from captured data, so no class instance,
|
|
5076
|
-
* class behavior, or
|
|
5288
|
+
* class behavior, or fabricated prototype survives into a snapshot.
|
|
5077
5289
|
*
|
|
5078
5290
|
* `Object.create(<null-prototype object>)` is refused, and NOT because it is
|
|
5079
|
-
* structurally identical to a reparented class instance — it is not,
|
|
5291
|
+
* structurally identical to a reparented class instance — it is not, because a
|
|
5080
5292
|
* class prototype always owns `constructor` and a bare `Object.create(null)`
|
|
5081
5293
|
* owns nothing. It is refused as policy: no realm produces that chain for a
|
|
5082
5294
|
* plain object, no consumer of it has been named, and a caller erases the
|
|
5083
5295
|
* difference by deleting `constructor`.
|
|
5084
5296
|
*
|
|
5085
5297
|
* This is the diagnosing form, deliberately NOT total: a revoked `Proxy` or a
|
|
5086
|
-
*
|
|
5298
|
+
* untrusted `getPrototypeOf` trap throws out of it, so an ownership engine can
|
|
5087
5299
|
* report an unreadable value as a failed read with the exact cause rather than
|
|
5088
5300
|
* as a well-formed structural refusal. {@link isRecord} is the total form for
|
|
5089
5301
|
* every guard consumer and contains that throw as `false`.
|
|
5090
5302
|
*
|
|
5091
5303
|
* @param value - The value whose record brand to inspect
|
|
5092
5304
|
* @returns True if the value is a plain record; false otherwise
|
|
5093
|
-
* @throws The exact value thrown by
|
|
5305
|
+
* @throws The exact value thrown by an untrusted brand observation
|
|
5094
5306
|
*
|
|
5095
5307
|
* @example
|
|
5096
5308
|
* ```ts
|
|
@@ -5173,6 +5385,30 @@ export declare function matchesStringLength(value: string, min: number | undefin
|
|
|
5173
5385
|
*/
|
|
5174
5386
|
export declare function matchesUndefinedField(fault: AuditFault, value: unknown, parsed: unknown): boolean;
|
|
5175
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
|
+
|
|
5176
5412
|
/**
|
|
5177
5413
|
* Determines whether an object is already on a traversal's active path.
|
|
5178
5414
|
*
|
|
@@ -5254,7 +5490,7 @@ export declare const NODE_LIMIT = 16384;
|
|
|
5254
5490
|
*
|
|
5255
5491
|
* The negation applies to the contained verdict, so a throwing guard is a non-match and
|
|
5256
5492
|
* its negation passes. Containing the negation instead made a guard and its `notOf`
|
|
5257
|
-
* both reject the same value, which
|
|
5493
|
+
* both reject the same value, which falsified `orOf(g, notOf(g))` as a tautology.
|
|
5258
5494
|
*
|
|
5259
5495
|
* @param guard - The guard or predicate to negate
|
|
5260
5496
|
* @returns A guard accepting exactly the values `guard` rejects
|
|
@@ -5326,11 +5562,20 @@ export declare interface NullShapeOptions {
|
|
|
5326
5562
|
readonly description?: string;
|
|
5327
5563
|
}
|
|
5328
5564
|
|
|
5329
|
-
/**
|
|
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
|
+
*/
|
|
5330
5573
|
export declare interface NumberShape {
|
|
5331
5574
|
readonly category: 'number';
|
|
5332
5575
|
readonly min?: number;
|
|
5576
|
+
readonly over?: number;
|
|
5333
5577
|
readonly max?: number;
|
|
5578
|
+
readonly under?: number;
|
|
5334
5579
|
readonly integer?: boolean;
|
|
5335
5580
|
readonly description?: string;
|
|
5336
5581
|
}
|
|
@@ -5339,13 +5584,13 @@ export declare interface NumberShape {
|
|
|
5339
5584
|
* Builds a numeric {@link NumberShape}.
|
|
5340
5585
|
*
|
|
5341
5586
|
* @remarks
|
|
5342
|
-
*
|
|
5343
|
-
*
|
|
5344
|
-
* 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.
|
|
5345
5590
|
*
|
|
5346
|
-
* @param options - Optional bounds (`min` / `max`), `integer`, and `description`
|
|
5591
|
+
* @param options - Optional bounds (`min` / `over` / `max` / `under`), `integer`, and `description`
|
|
5347
5592
|
* @returns A number shape
|
|
5348
|
-
* @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
|
|
5349
5594
|
*
|
|
5350
5595
|
* @example
|
|
5351
5596
|
* ```ts
|
|
@@ -5354,10 +5599,18 @@ export declare interface NumberShape {
|
|
|
5354
5599
|
*/
|
|
5355
5600
|
export declare function numberShape(options?: NumberShapeOptions): NumberShape;
|
|
5356
5601
|
|
|
5357
|
-
/**
|
|
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
|
+
*/
|
|
5358
5609
|
export declare interface NumberShapeOptions {
|
|
5359
5610
|
readonly min?: number;
|
|
5611
|
+
readonly over?: number;
|
|
5360
5612
|
readonly max?: number;
|
|
5613
|
+
readonly under?: number;
|
|
5361
5614
|
readonly integer?: boolean;
|
|
5362
5615
|
readonly description?: string;
|
|
5363
5616
|
}
|
|
@@ -5375,7 +5628,7 @@ export declare interface NumberShapeOptions {
|
|
|
5375
5628
|
* prototype accessors can satisfy the shape. An optional member passes when its
|
|
5376
5629
|
* read value is `undefined`; otherwise its guard must accept the value. Unknown
|
|
5377
5630
|
* members are never enumerated or inspected. Member-carrying functions are
|
|
5378
|
-
* accepted. Arrays, `null`, and primitives are rejected.
|
|
5631
|
+
* accepted. Arrays, `null`, and primitives are rejected. Untrusted reads return
|
|
5379
5632
|
* `false` rather than throwing.
|
|
5380
5633
|
*
|
|
5381
5634
|
* @param shape - The guard shape whose declared members the object must satisfy
|
|
@@ -5585,7 +5838,8 @@ export declare function optionalOf<T>(guard: Guard<T>): Guard<T | undefined>;
|
|
|
5585
5838
|
* `default` holds the JSON value the compiled parser fills when the property is
|
|
5586
5839
|
* absent or `undefined`. It leaves `is`, `audit`, `explain`, and `generate`
|
|
5587
5840
|
* unchanged, because an absent optional stays canonical. It must satisfy `inner`,
|
|
5588
|
-
* 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`.
|
|
5589
5843
|
*/
|
|
5590
5844
|
export declare interface OptionalShape<S extends ContractShape = ContractShape> {
|
|
5591
5845
|
readonly category: 'optional';
|
|
@@ -5598,11 +5852,12 @@ export declare interface OptionalShape<S extends ContractShape = ContractShape>
|
|
|
5598
5852
|
*
|
|
5599
5853
|
* @remarks
|
|
5600
5854
|
* As an {@link objectShape} property, the field becomes a true optional property
|
|
5601
|
-
* 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
|
|
5602
5857
|
* compiled parser fills it where the property is absent or `undefined`; the guard,
|
|
5603
5858
|
* the audit, the report, and the generator keep treating the property as optional.
|
|
5604
|
-
* The compilers refuse a default `inner` refuses, a default under a union
|
|
5605
|
-
* 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.
|
|
5606
5861
|
*
|
|
5607
5862
|
* @param inner - The wrapped shape
|
|
5608
5863
|
* @param options - Optional `default`, a JSON value
|
|
@@ -5643,6 +5898,18 @@ export declare function orOf<A, B>(left: Guard<A>, right: Guard<B>): Guard<A | B
|
|
|
5643
5898
|
|
|
5644
5899
|
export declare function orOf(left: (value: unknown) => boolean, right: (value: unknown) => boolean): Guard<unknown>;
|
|
5645
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
|
+
|
|
5646
5913
|
/**
|
|
5647
5914
|
* Rebuilds a declaration's regular expression as a stateless pattern this
|
|
5648
5915
|
* package owns, and refuses an unreadable one under the reader's own name.
|
|
@@ -5687,7 +5954,7 @@ export declare function ownPattern(pattern: RegExp, reader: string): RegExp;
|
|
|
5687
5954
|
*
|
|
5688
5955
|
* @param shape - The contract shape to own
|
|
5689
5956
|
* @returns A deeply cloned frozen snapshot
|
|
5690
|
-
* @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
|
|
5691
5958
|
*
|
|
5692
5959
|
* @example
|
|
5693
5960
|
* ```ts
|
|
@@ -6018,7 +6285,7 @@ export declare type Parser<T> = (value: unknown) => T | undefined;
|
|
|
6018
6285
|
*
|
|
6019
6286
|
* @remarks
|
|
6020
6287
|
* Probes the record's own enumerable values before returning the reference, so a
|
|
6021
|
-
*
|
|
6288
|
+
* untrusted getter is met here rather than at the caller. A failed probe throws
|
|
6022
6289
|
* `ContractError { code: 'structure' }` carrying `parseRecord: value could not be
|
|
6023
6290
|
* read`; a readable non-record answers `undefined`.
|
|
6024
6291
|
*
|
|
@@ -6276,6 +6543,29 @@ export declare const PREVIEW_LIMIT = 64;
|
|
|
6276
6543
|
*/
|
|
6277
6544
|
export declare function previewParts(source: string, index: number, capacity: number, quoted: boolean): readonly string[];
|
|
6278
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
|
+
|
|
6279
6569
|
/**
|
|
6280
6570
|
* Represents a deterministic random source returning a value in `[0, 1)`.
|
|
6281
6571
|
*
|
|
@@ -6326,7 +6616,7 @@ export declare interface RawShape {
|
|
|
6326
6616
|
* structurally verbatim, so here the schema claims LESS than the compiled guard
|
|
6327
6617
|
* accepts — `rawShape({ type: 'string' })` emits `{ type: 'string' }` and its
|
|
6328
6618
|
* guard still accepts `42`, the mirror of {@link jsonShape}'s looseness.
|
|
6329
|
-
* `compileGenerator` throws,
|
|
6619
|
+
* `compileGenerator` throws, because an arbitrary embedded schema has no
|
|
6330
6620
|
* auto-generatable sample.
|
|
6331
6621
|
*
|
|
6332
6622
|
* @param schema - The JSON Schema fragment to embed
|
|
@@ -6434,7 +6724,7 @@ export declare function readMapEntries(value: ReadonlyMap<unknown, unknown>): Re
|
|
|
6434
6724
|
* consumed key is read exactly once, checked for presence, and inspected for an
|
|
6435
6725
|
* own descriptor while the container is enumerated once. Every successfully
|
|
6436
6726
|
* read non-`undefined` consumed value enters the fresh own-enumerable snapshot,
|
|
6437
|
-
* including an inherited or non-enumerable option.
|
|
6727
|
+
* including an inherited or non-enumerable option. An untrusted host is reported
|
|
6438
6728
|
* uniformly as an unreadable options record, while a readable array or class
|
|
6439
6729
|
* instance retains the plain-record diagnostic.
|
|
6440
6730
|
*
|
|
@@ -6579,6 +6869,28 @@ export declare function readSampleMemo(memo: SampleMemo, reader: string): Sample
|
|
|
6579
6869
|
*/
|
|
6580
6870
|
export declare function readSetEntries(value: ReadonlySet<unknown>): Result<readonly unknown[]>;
|
|
6581
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
|
+
|
|
6582
6894
|
/**
|
|
6583
6895
|
* Reads a value through the shared containment boundary or refuses it with the
|
|
6584
6896
|
* contract module's uniform read diagnostic.
|
|
@@ -6676,6 +6988,27 @@ export declare interface RecordShapeOptions {
|
|
|
6676
6988
|
readonly description?: string;
|
|
6677
6989
|
}
|
|
6678
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
|
+
|
|
6679
7012
|
/**
|
|
6680
7013
|
* Refuses a validated declaration whose compiled expansion exceeds
|
|
6681
7014
|
* {@link COMPILE_NODE_LIMIT}.
|
|
@@ -6726,6 +7059,41 @@ export declare function refuseExpansion(expansion: number | undefined): void;
|
|
|
6726
7059
|
*/
|
|
6727
7060
|
export declare function refuseOptionKeys(source: object | undefined, keys: readonly string[], builder: string, shape: string): void;
|
|
6728
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
|
+
|
|
6729
7097
|
/**
|
|
6730
7098
|
* Renders a schema as a short summary of what to send, such as `{"city": string, "note"?: string}`.
|
|
6731
7099
|
*
|
|
@@ -6735,8 +7103,8 @@ export declare function refuseOptionKeys(source: object | undefined, keys: reado
|
|
|
6735
7103
|
* and a schema that says nothing reads `any`. Each nested form takes half the room of its parent, and
|
|
6736
7104
|
* below 16 characters a form stops at its type, so a schema that holds itself still ends. Text past
|
|
6737
7105
|
* `room` is cut and closes with `…`. A type word outside JSON Schema's vocabulary is encoded.
|
|
6738
|
-
* A schema with an own `not` reads `function` when its `format` is `'function'
|
|
6739
|
-
* otherwise.
|
|
7106
|
+
* A schema with an own `not` reads `function` when its `format` is `'function'`, `undefined`
|
|
7107
|
+
* when its `format` is `'undefined'`, and `never` otherwise.
|
|
6740
7108
|
*
|
|
6741
7109
|
* @param schema - The schema to summarize
|
|
6742
7110
|
* @param room - The characters the summary can take. Default: `FAULT_SCHEMA_LIMIT`
|
|
@@ -6829,7 +7197,7 @@ export declare type ReporterFunction = (value: unknown, path?: readonly string[]
|
|
|
6829
7197
|
* The root must satisfy {@link isRecord}; inherited properties are never fields.
|
|
6830
7198
|
* Intermediates may be objects or arrays indexed by string. Returns `undefined`
|
|
6831
7199
|
* the moment a segment is missing or lands on a non-object, so the lookup is
|
|
6832
|
-
* total — even against
|
|
7200
|
+
* total — even against an untrusted getter or Proxy trap that throws on read,
|
|
6833
7201
|
* contained through {@link attempt} so the throw never escapes.
|
|
6834
7202
|
*
|
|
6835
7203
|
* @param record - The source record
|
|
@@ -6980,13 +7348,13 @@ export declare function samplesToSchema(samples: readonly unknown[], options?: V
|
|
|
6980
7348
|
* a finite non-negative integer, selecting a valid fallback for anything else.
|
|
6981
7349
|
*
|
|
6982
7350
|
* @remarks
|
|
6983
|
-
* Guards {@link valueToSchema} / {@link samplesToSchema} against
|
|
7351
|
+
* Guards {@link valueToSchema} / {@link samplesToSchema} against an untrusted or
|
|
6984
7352
|
* malformed budget: an unclamped `NaN` defeats every `depth <= 0` guard
|
|
6985
7353
|
* (`NaN <= 0` is `false`, so recursion never halts), and a negative
|
|
6986
7354
|
* `limits.properties` makes `slice(0, -1)` silently drop the LAST sorted key
|
|
6987
7355
|
* instead of capping the list (a fractional value has a similarly undefined
|
|
6988
7356
|
* `slice` bound). `Infinity` is rejected too — `Number.isInteger(Infinity)`
|
|
6989
|
-
* is `false` —
|
|
7357
|
+
* is `false` — because an unbounded budget is exactly the untrusted case the
|
|
6990
7358
|
* caps exist to prevent. A valid candidate passes through unchanged without
|
|
6991
7359
|
* inspecting the fallback. When the candidate is invalid, the fallback must
|
|
6992
7360
|
* satisfy the same finite non-negative-integer contract or this boundary
|
|
@@ -7014,7 +7382,7 @@ export declare function sanitizeBudget(value: number | undefined, fallback: numb
|
|
|
7014
7382
|
* @remarks
|
|
7015
7383
|
* {@link sanitizeBudget} decides the SHAPE of a budget and deliberately lets any
|
|
7016
7384
|
* finite non-negative integer through, because it must never read a fallback a
|
|
7017
|
-
*
|
|
7385
|
+
* untrusted caller supplied. That left the depth axis unbounded from above, and
|
|
7018
7386
|
* depth is the axis that recurses: `1e9` is a valid integer, so the walk descended
|
|
7019
7387
|
* until the call STACK failed, at a depth that varied between runs, and the
|
|
7020
7388
|
* refusal surfaced as an unreadable value rather than as the exhaustion the guard
|
|
@@ -7042,7 +7410,8 @@ export declare function sanitizeDepth(value: number | undefined): number;
|
|
|
7042
7410
|
* @remarks
|
|
7043
7411
|
* Each asserts nothing about a value, so a converted shape drops it without loss, except
|
|
7044
7412
|
* `description`, which the shape keeps. A strict conversion admits them beside every
|
|
7045
|
-
* keyword it reads, the function leaf `{ not: {}, format: 'function' }`
|
|
7413
|
+
* keyword it reads, the function leaf `{ not: {}, format: 'function' }` and the undefined
|
|
7414
|
+
* leaf `{ not: {}, format: 'undefined' }` included.
|
|
7046
7415
|
*
|
|
7047
7416
|
* @example
|
|
7048
7417
|
* ```ts
|
|
@@ -7061,7 +7430,7 @@ export declare const SCHEMA_ANNOTATIONS: readonly ["title", "description", "$sch
|
|
|
7061
7430
|
* permanently. Success replays the exact frozen root; failure rethrows the
|
|
7062
7431
|
* exact class-owned error. Nonredirectable terminal settlement releases
|
|
7063
7432
|
* populated traversal state before publishing that result, while retaining
|
|
7064
|
-
* the source and exact result afterward. Reentry
|
|
7433
|
+
* the source and exact result afterward. Reentry invalidates the active operation
|
|
7065
7434
|
* and every later call with one shared cause-free error.
|
|
7066
7435
|
*
|
|
7067
7436
|
* @param schema - The JSON Schema graph to retain for cloning
|
|
@@ -7107,7 +7476,7 @@ export declare interface SchemaClonerInterface {
|
|
|
7107
7476
|
* Success and failure both release traversal frames and the active memo through
|
|
7108
7477
|
* preconstructed references before nonredirectable terminal publication, while
|
|
7109
7478
|
* retaining the source and the exact root or class-owned error. Active reentry
|
|
7110
|
-
* permanently settles the instance with one exact cause-free `clone`
|
|
7479
|
+
* permanently settles the instance with one exact cause-free `clone` refusal shared by
|
|
7111
7480
|
* the nested call, the outer call, and every later call, and a property-read cause
|
|
7112
7481
|
* stays exact.
|
|
7113
7482
|
*
|
|
@@ -7216,7 +7585,7 @@ export declare function schemaToParameters(schema: JSONSchema): Readonly<Record<
|
|
|
7216
7585
|
* `Set`, a class instance, a function, a symbol, a bigint, and readable cyclic
|
|
7217
7586
|
* hosts), which infer `{}` and widen back to an accept-anything
|
|
7218
7587
|
* {@link rawShape}. An unreadable host is refused by {@link valueToSchema}
|
|
7219
|
-
* before this law produces a schema; direct
|
|
7588
|
+
* before this law produces a schema; direct untrusted input to
|
|
7220
7589
|
* {@link schemaToShape} receives the same coded refusal.
|
|
7221
7590
|
* Widening is the only source of looseness. The law has three explicit host
|
|
7222
7591
|
* limits:
|
|
@@ -7258,8 +7627,9 @@ export declare function schemaToParameters(schema: JSONSchema): Readonly<Record<
|
|
|
7258
7627
|
*
|
|
7259
7628
|
* STRICT: `{ strict: true }` is the door for a foreign schema. It refuses, with
|
|
7260
7629
|
* code `structure`, every node the lenient walk would widen, every keyword it
|
|
7261
|
-
* would ignore (`pattern`, every `format` but `'date'` on a string node
|
|
7262
|
-
*
|
|
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`,
|
|
7263
7633
|
* `patternProperties`, `propertyNames`, `prefixItems`, and anything else outside
|
|
7264
7634
|
* {@link STRICT_SCHEMA_KEYWORDS}), a malformed keyword or annotation, a boolean schema, an `enum` entry
|
|
7265
7635
|
* that is neither a finite primitive nor `null`, a contradictory bound, a date format whose
|
|
@@ -7268,11 +7638,16 @@ export declare function schemaToParameters(schema: JSONSchema): Readonly<Record<
|
|
|
7268
7638
|
* optional property to fill. An object with no `additionalProperties` closes
|
|
7269
7639
|
* rather than opens, and `oneOf` keeps exactly-one, because a strict walk reads
|
|
7270
7640
|
* every keyword that could keep two arms apart. Below a `oneOf` that object refuses
|
|
7271
|
-
* instead,
|
|
7641
|
+
* instead, because closing it could change which arms match. A strict conversion is the
|
|
7272
7642
|
* one walk that asserts a `format`: it reads `format: 'date'` on a string node as a
|
|
7273
7643
|
* date string shape, so a compiled {@link dateShape} round-trips, and it reads the function
|
|
7274
|
-
* leaf `{ not: {}, format: 'function' }` back as {@link functionShape}
|
|
7275
|
-
*
|
|
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.
|
|
7276
7651
|
*
|
|
7277
7652
|
* @param schema - The JSON Schema value to convert
|
|
7278
7653
|
* @param options - Optional `strict`, default `false`
|
|
@@ -7387,6 +7762,24 @@ export declare function setOf<T>(elementGuard: Guard<T>): Guard<ReadonlySet<T>>;
|
|
|
7387
7762
|
|
|
7388
7763
|
export declare function setOf(elementGuard: (value: unknown) => boolean): Guard<ReadonlySet<unknown>>;
|
|
7389
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
|
+
|
|
7390
7783
|
/**
|
|
7391
7784
|
* Lists the fields recognized for every contract declaration category, frozen.
|
|
7392
7785
|
*
|
|
@@ -7406,7 +7799,7 @@ export declare const SHAPE_FIELDS: Readonly<Record<string, readonly string[]>>;
|
|
|
7406
7799
|
* permanently. Success replays the exact frozen root; failure rethrows the
|
|
7407
7800
|
* exact class-owned or directly adopted error. Nonredirectable settlement
|
|
7408
7801
|
* releases populated traversal state before publishing that result. Reentry
|
|
7409
|
-
*
|
|
7802
|
+
* invalidates the active operation and every later call with one shared cause-free
|
|
7410
7803
|
* error.
|
|
7411
7804
|
*
|
|
7412
7805
|
* @param shape - The contract-shape graph to retain for cloning
|
|
@@ -7439,7 +7832,7 @@ export declare class ShapeCloner implements ShapeClonerInterface {
|
|
|
7439
7832
|
* shape or exact same owned {@link ContractError}. Nonredirectable terminal
|
|
7440
7833
|
* settlement releases populated traversal state before publishing that exact
|
|
7441
7834
|
* result, while retaining the source and result afterward.
|
|
7442
|
-
* Reentry permanently
|
|
7835
|
+
* Reentry permanently invalidates the active operation with one shared error.
|
|
7443
7836
|
*/
|
|
7444
7837
|
export declare interface ShapeClonerInterface {
|
|
7445
7838
|
/**
|
|
@@ -7454,7 +7847,7 @@ export declare interface ShapeClonerInterface {
|
|
|
7454
7847
|
* failure rethrows the exact class-owned or adopted {@link ContractError}. Both
|
|
7455
7848
|
* release graph-working state through preconstructed references before nonredirectable
|
|
7456
7849
|
* terminal publication. Active reentry permanently settles the instance with one exact
|
|
7457
|
-
* cause-free
|
|
7850
|
+
* cause-free refusal shared by the nested call, the outer call, and every later call.
|
|
7458
7851
|
*
|
|
7459
7852
|
* @returns The settled contract-shape snapshot
|
|
7460
7853
|
* @throws {ContractError} When the declaration is malformed, unreadable, cyclic, too deep, or cloning is reentered
|
|
@@ -7542,7 +7935,8 @@ export declare interface ShapeShapeOptions {
|
|
|
7542
7935
|
* `'date'` when `date: true`, else `'string'`); `optionalShape` /
|
|
7543
7936
|
* `nullableShape` project through to their inner shape's kind, and `rawShape`
|
|
7544
7937
|
* (an arbitrary embedded schema with no fixed kind) projects to `'json'`.
|
|
7545
|
-
* `functionShape` projects to `'function'
|
|
7938
|
+
* `functionShape` projects to `'function'`, `undefinedShape` to `'undefined'`, and
|
|
7939
|
+
* `interfaceShape` to `'object'`.
|
|
7546
7940
|
*
|
|
7547
7941
|
* A hand-authored node carrying an unrecognized discriminant is REFUSED rather
|
|
7548
7942
|
* than answered out of type, which keeps the declared non-optional
|
|
@@ -7568,7 +7962,7 @@ export declare function shapeToKind(shape: ContractShape): FaultKind;
|
|
|
7568
7962
|
* @remarks
|
|
7569
7963
|
* Construction performs no source observation. Every non-overlapping
|
|
7570
7964
|
* {@link validate} call starts a fresh pass over the source's current state.
|
|
7571
|
-
* Reentry
|
|
7965
|
+
* Reentry invalidates the active pass with one shared cause-free structure error;
|
|
7572
7966
|
* cleanup always restores an idle validator for the next independent call.
|
|
7573
7967
|
*
|
|
7574
7968
|
* @example
|
|
@@ -7683,8 +8077,10 @@ export declare function sortValues<T extends string | number>(values: readonly T
|
|
|
7683
8077
|
* refuses. `pattern`, `format`, and `not` are absent because no compiled shape asserts
|
|
7684
8078
|
* them, so a schema holding one would convert to a shape wider than the schema it came
|
|
7685
8079
|
* from. The exceptions are `format: 'date'` on a string node, which a strict conversion
|
|
7686
|
-
* reads as a date string shape,
|
|
7687
|
-
*
|
|
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.
|
|
7688
8084
|
*
|
|
7689
8085
|
* @example
|
|
7690
8086
|
* ```ts
|
|
@@ -7935,6 +8331,58 @@ export declare function tupleOf<const Gs extends ReadonlyArray<Guard<unknown>>>(
|
|
|
7935
8331
|
|
|
7936
8332
|
export declare function tupleOf(...predicates: ReadonlyArray<(value: unknown) => boolean>): Guard<readonly unknown[]>;
|
|
7937
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
|
+
|
|
7938
8386
|
/**
|
|
7939
8387
|
* Unifies a list of inferred `JSONSchema` fragments into one schema.
|
|
7940
8388
|
*
|
|
@@ -7953,7 +8401,7 @@ export declare function tupleOf(...predicates: ReadonlyArray<(value: unknown) =>
|
|
|
7953
8401
|
*
|
|
7954
8402
|
* A readable member {@link canonicalStringify} cannot key — a cyclic or
|
|
7955
8403
|
* otherwise JSON-inexpressible fragment, which only a direct caller can supply
|
|
7956
|
-
*
|
|
8404
|
+
* because the inferers always build plain encodable fragments — has NO
|
|
7957
8405
|
* de-duplication key, so it can participate in neither de-duplication nor the
|
|
7958
8406
|
* canonical-key ordering. It is KEPT (dropping a variant would narrow the
|
|
7959
8407
|
* union, and unification only ever widens), appended in input order after the
|