@orkestrel/contract 0.0.21 → 0.0.22
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 +2135 -423
- package/dist/src/core/index.cjs.map +1 -1
- package/dist/src/core/index.d.cts +766 -48
- package/dist/src/core/index.d.ts +766 -48
- package/dist/src/core/index.js +2108 -424
- package/dist/src/core/index.js.map +1 -1
- package/package.json +9 -9
package/dist/src/core/index.d.ts
CHANGED
|
@@ -17,6 +17,26 @@
|
|
|
17
17
|
*/
|
|
18
18
|
export declare function admitMember(members: Set<unknown>, value: unknown): void;
|
|
19
19
|
|
|
20
|
+
/**
|
|
21
|
+
* Admits a stable readable value with only lossless repairs and returns the parser's value.
|
|
22
|
+
*
|
|
23
|
+
* @remarks
|
|
24
|
+
* Reads must remain stable across artifacts. Guard-valid input skips both reports and parses
|
|
25
|
+
* once. Repairs use audit, parse once, and explain only on parse failure. Unresolved unions,
|
|
26
|
+
* extras, lossy repairs, and a capped audit refuse. An own optional undefined field omitted or
|
|
27
|
+
* filled by its declared default is not a repair. The result preserves parser ownership, including union input identity.
|
|
28
|
+
* A read failure returns its cause rather than throwing.
|
|
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.
|
|
32
|
+
*
|
|
33
|
+
* @example
|
|
34
|
+
* ```ts
|
|
35
|
+
* admitValue(createContract(numberShape()), '3') // success carrying 3 and its type repair
|
|
36
|
+
* ```
|
|
37
|
+
*/
|
|
38
|
+
export declare function admitValue<T>(contract: ContractInterface<T>, value: unknown): Result<ContractAdmission<T>, ContractRefusal>;
|
|
39
|
+
|
|
20
40
|
/**
|
|
21
41
|
* Records an object as entered on a traversal's active path.
|
|
22
42
|
*
|
|
@@ -207,6 +227,23 @@ export declare function attempt<T>(callback: () => T): Result<T>;
|
|
|
207
227
|
/** Covers every fault an audit reports — the parse faults plus undeclared keys. */
|
|
208
228
|
export declare type AuditFault = Fault | ExtraFault;
|
|
209
229
|
|
|
230
|
+
/** Describes the closed shape built for audit faults, including paired discriminator hints. */
|
|
231
|
+
export declare type AuditFaultShape = ReturnType<FaultShaper['build']>;
|
|
232
|
+
|
|
233
|
+
/**
|
|
234
|
+
* Returns the shared closed audit-fault shape, building it on the first call.
|
|
235
|
+
*
|
|
236
|
+
* @remarks
|
|
237
|
+
* Numeric bounds, counts, and discriminator literals must be finite. Discriminator hints
|
|
238
|
+
* carry both key and expected together. The inferred union is assignable to AuditFault.
|
|
239
|
+
*
|
|
240
|
+
* @example
|
|
241
|
+
* ```ts
|
|
242
|
+
* createContract(auditFaultShape()).is({ reason: 'extra', path: ['typo'] }) // true
|
|
243
|
+
* ```
|
|
244
|
+
*/
|
|
245
|
+
export declare function auditFaultShape(): AuditFaultShape;
|
|
246
|
+
|
|
210
247
|
/**
|
|
211
248
|
* Represents a compiled strict-domain diagnostic — the shape of `compileAuditor`
|
|
212
249
|
* bound to one shape.
|
|
@@ -875,7 +912,8 @@ export declare function compileGenerator(shape: ContractShape, random?: RandomFu
|
|
|
875
912
|
* § Validation and contracts requires. It requests
|
|
876
913
|
* exactly the `guard` root of a fresh {@link ContractCompiler}, which owns the
|
|
877
914
|
* declaration once through {@link ownShape} and validates that snapshot once,
|
|
878
|
-
* so an unfrozen caller-owned graph compiles
|
|
915
|
+
* unless the builders already did, so an unfrozen caller-owned graph compiles
|
|
916
|
+
* from a snapshot and excessive
|
|
879
917
|
* nesting, cycles, and excessive expansion are rejected before any guard is
|
|
880
918
|
* built.
|
|
881
919
|
*
|
|
@@ -1028,6 +1066,27 @@ export declare function compileSchema(shape: ContractShape): JSONSchema;
|
|
|
1028
1066
|
*/
|
|
1029
1067
|
export declare function complementOf<TBase, TExcluded extends TBase>(base: Guard<TBase>, excluded: Guard<TExcluded> | ((value: TBase) => value is TExcluded)): Guard<Exclude<TBase, TExcluded>>;
|
|
1030
1068
|
|
|
1069
|
+
/**
|
|
1070
|
+
* Counts the surrogate pairs in a string, stopping at a limit.
|
|
1071
|
+
*
|
|
1072
|
+
* @remarks
|
|
1073
|
+
* A regular-expression literal builds a fresh `RegExp` per evaluation, so this call
|
|
1074
|
+
* owns the `lastIndex` that is its cursor, and the captured `exec` reads the internal
|
|
1075
|
+
* slots and no member a caller can replace. Text with no surrogate costs one native
|
|
1076
|
+
* scan, and a string of pairs costs one `exec` per pair up to the limit.
|
|
1077
|
+
*
|
|
1078
|
+
* @param value - The string to scan
|
|
1079
|
+
* @param limit - The count to stop at
|
|
1080
|
+
* @returns The number of surrogate pairs, or `limit` when the string holds at least that many
|
|
1081
|
+
*
|
|
1082
|
+
* @example
|
|
1083
|
+
* ```ts
|
|
1084
|
+
* computeSurrogatePairs('😀a😀', 8) // 2
|
|
1085
|
+
* computeSurrogatePairs('😀😀😀', 2) // 2
|
|
1086
|
+
* ```
|
|
1087
|
+
*/
|
|
1088
|
+
export declare function computeSurrogatePairs(value: string, limit: number): number;
|
|
1089
|
+
|
|
1031
1090
|
/**
|
|
1032
1091
|
* Runs a public door's whole body and publishes only this package's error class.
|
|
1033
1092
|
*
|
|
@@ -1122,6 +1181,22 @@ export declare const CONTRACT_CODES: readonly ContractCode[];
|
|
|
1122
1181
|
*/
|
|
1123
1182
|
export declare const CONTRACT_ERROR_BRAND: unique symbol;
|
|
1124
1183
|
|
|
1184
|
+
/**
|
|
1185
|
+
* Carries an admitted value and the lossless repairs made while parsing it.
|
|
1186
|
+
*
|
|
1187
|
+
* @remarks
|
|
1188
|
+
* The value keeps the parser's ownership: a union may return the caller's input by identity.
|
|
1189
|
+
*
|
|
1190
|
+
* @example
|
|
1191
|
+
* ```ts
|
|
1192
|
+
* const admitted: ContractAdmission<number> = { value: 3, repairs: [] }
|
|
1193
|
+
* ```
|
|
1194
|
+
*/
|
|
1195
|
+
export declare interface ContractAdmission<T> {
|
|
1196
|
+
readonly value: T;
|
|
1197
|
+
readonly repairs: readonly AuditFault[];
|
|
1198
|
+
}
|
|
1199
|
+
|
|
1125
1200
|
/**
|
|
1126
1201
|
* Names the machine-readable category carried by a {@link ContractError}.
|
|
1127
1202
|
*
|
|
@@ -1173,7 +1248,9 @@ export declare type ContractCode =
|
|
|
1173
1248
|
* chain pays a hundred clones of shrinking graphs and a hundred validations —
|
|
1174
1249
|
* quadratic work for a linear declaration. Here ownership runs once, validation runs once over
|
|
1175
1250
|
* that owned result, and each unique node and structural edge is indexed once
|
|
1176
|
-
* into children-before-parent order.
|
|
1251
|
+
* into children-before-parent order. A declaration a builder sealed is frozen and
|
|
1252
|
+
* validated all the way down already, so it takes neither and is indexed as it
|
|
1253
|
+
* stands. Every artifact family is then a single
|
|
1177
1254
|
* postorder pass whose entries are keyed by node identity, so a shared child is
|
|
1178
1255
|
* compiled once however many parents point at it. The same asymmetry exists on
|
|
1179
1256
|
* the VALUE side and is answered the same way: `guard`, `auditor` and `reporter`
|
|
@@ -1185,7 +1262,9 @@ export declare type ContractCode =
|
|
|
1185
1262
|
* getters after it replay. A getter builds its own family and no other, except
|
|
1186
1263
|
* that `parser`, `reporter` and `generator` build the guard plan when the graph
|
|
1187
1264
|
* holds a union, because a union's membership question IS a guard question in
|
|
1188
|
-
* all three
|
|
1265
|
+
* all three, and every getter builds it when the graph holds a default, because
|
|
1266
|
+
* a default that its inner shape refuses refuses at whichever artifact is read
|
|
1267
|
+
* first.
|
|
1189
1268
|
*
|
|
1190
1269
|
* One terminal lifecycle covers preparation and every family. A failure settles
|
|
1191
1270
|
* the compiler: later getters rethrow that exact error, while an artifact
|
|
@@ -1464,6 +1543,19 @@ export declare interface ContractInterface<T> {
|
|
|
1464
1543
|
generate(random?: RandomFunction): T;
|
|
1465
1544
|
}
|
|
1466
1545
|
|
|
1546
|
+
/**
|
|
1547
|
+
* Carries bounded admission faults and the cause of an unreadable value when present.
|
|
1548
|
+
*
|
|
1549
|
+
* @example
|
|
1550
|
+
* ```ts
|
|
1551
|
+
* const refused: ContractRefusal = { faults: [{ reason: 'extra', path: ['typo'] }] }
|
|
1552
|
+
* ```
|
|
1553
|
+
*/
|
|
1554
|
+
export declare interface ContractRefusal {
|
|
1555
|
+
readonly faults: readonly AuditFault[];
|
|
1556
|
+
readonly cause?: unknown;
|
|
1557
|
+
}
|
|
1558
|
+
|
|
1467
1559
|
/**
|
|
1468
1560
|
* Describes a value declaratively — a declaration the shape builders build and
|
|
1469
1561
|
* the compilers turn into a guard, a parser, a JSON Schema, and a generator.
|
|
@@ -1473,7 +1565,7 @@ export declare interface ContractInterface<T> {
|
|
|
1473
1565
|
* element shape, an `ObjectShape` a map of them). {@link validateShape}
|
|
1474
1566
|
* enforces an acyclic graph within {@link COMPILE_DEPTH_LIMIT}.
|
|
1475
1567
|
*/
|
|
1476
|
-
export declare type ContractShape = StringShape | NumberShape | BooleanShape | NullShape | LiteralShape | ArrayShape | ObjectShape | UnionShape | OptionalShape | NullableShape | JSONShape | RawShape;
|
|
1568
|
+
export declare type ContractShape = StringShape | NumberShape | BooleanShape | NullShape | LiteralShape | ArrayShape | ObjectShape | UnionShape | OptionalShape | NullableShape | JSONShape | ShapeShape | RawShape;
|
|
1477
1569
|
|
|
1478
1570
|
/**
|
|
1479
1571
|
* Compiles a {@link ContractShape} into a {@link ContractInterface} — the
|
|
@@ -1489,24 +1581,30 @@ export declare type ContractShape = StringShape | NumberShape | BooleanShape | N
|
|
|
1489
1581
|
* snapshot — ownership already refuses a malformed structural slot, scalar
|
|
1490
1582
|
* field, or bound rather than normalizing it, so a second walk of the caller's
|
|
1491
1583
|
* live source only added a population that could disagree with the one the
|
|
1492
|
-
* artifacts actually use.
|
|
1493
|
-
*
|
|
1494
|
-
*
|
|
1495
|
-
*
|
|
1496
|
-
*
|
|
1497
|
-
*
|
|
1498
|
-
*
|
|
1499
|
-
*
|
|
1500
|
-
*
|
|
1501
|
-
*
|
|
1502
|
-
*
|
|
1503
|
-
*
|
|
1504
|
-
*
|
|
1505
|
-
*
|
|
1506
|
-
*
|
|
1507
|
-
*
|
|
1508
|
-
*
|
|
1509
|
-
*
|
|
1584
|
+
* artifacts actually use. A declaration made entirely by this package's builders
|
|
1585
|
+
* is frozen and validated all the way down already, so it is that owned graph.
|
|
1586
|
+
* Every artifact compiles once, so `audit`, `explain` and `generate` re-walk and
|
|
1587
|
+
* re-gate nothing on a later call; `contract.audit` and `compileAuditor` run the
|
|
1588
|
+
* same compiled plan reached by different names.
|
|
1589
|
+
* A declaration made entirely by builders compiles its schema at this call and
|
|
1590
|
+
* its function members together on the first call to any of them, so a module
|
|
1591
|
+
* can declare contracts as data and pay only for the ones it uses. Any other
|
|
1592
|
+
* declaration, and a bare leaf, compiles every member at this call. Either way
|
|
1593
|
+
* the members are plain data properties, so `const { is, parse } =
|
|
1594
|
+
* createContract(shape)` destructures those exact values, a spread of the result
|
|
1595
|
+
* copies them, and neither compiles anything. A malformed declaration refuses at
|
|
1596
|
+
* this call rather than at the first read of whichever member a caller happens
|
|
1597
|
+
* to touch, so the failure arrives at the call the caller made — carrying the
|
|
1598
|
+
* authoring door's own diagnosis, which this door adopts rather than rewraps.
|
|
1599
|
+
* Every compiled member is self-contained, and the compiler this call builds
|
|
1600
|
+
* releases its working set once every member has compiled. The contract keeps
|
|
1601
|
+
* part of the declaration even so: the auditor and reporter plans close over the
|
|
1602
|
+
* leaf and array nodes they read their bounds from, and a contract with deferred
|
|
1603
|
+
* members retains its declaration. Nothing the caller keeps reaches back into the
|
|
1604
|
+
* compiler. A deferred member compiled on a host whose members were replaced after
|
|
1605
|
+
* this call would outlive the replacement, so it refuses to compile until they are
|
|
1606
|
+
* restored: until then its guard answers `false`, its parser `undefined`, and its
|
|
1607
|
+
* diagnostics and generator refuse.
|
|
1510
1608
|
*
|
|
1511
1609
|
* @param shape - The shape to compile
|
|
1512
1610
|
* @returns A contract bundling `schema` / `is` / `parse` / `audit` / `explain` / `generate`
|
|
@@ -1582,6 +1680,49 @@ export declare function deriveLengthBounds(min: unknown, max: unknown): BoundsRe
|
|
|
1582
1680
|
*/
|
|
1583
1681
|
export declare function deriveRangeBounds(min: unknown, max: unknown): BoundsRead;
|
|
1584
1682
|
|
|
1683
|
+
/**
|
|
1684
|
+
* Describes one fault as the line a caller corrects from, naming what to send where the schema
|
|
1685
|
+
* says.
|
|
1686
|
+
*
|
|
1687
|
+
* @remarks
|
|
1688
|
+
* Each line opens with the fault's path (or `value` at the root) and reason. An `extra` fault lists
|
|
1689
|
+
* its parent's keys only when the declaring arms agree. A literal names candidates only where
|
|
1690
|
+
* the declarations agree; lists are deduplicated and bounded. A received preview stays as written
|
|
1691
|
+
* within PREVIEW_LIMIT and without control or line-separator characters; otherwise it is encoded
|
|
1692
|
+
* through preview. Received, constraint, and limit details read only own fields. A `variant` or
|
|
1693
|
+
* `oneOf` fault says that the value matches none of the declared forms, or several where one must
|
|
1694
|
+
* match, and summarizes each form through `renderForm`. It names no fault of any one form, because
|
|
1695
|
+
* none of them holds for the others. Those summaries share half of `FAULT_TEXT_LIMIT`.
|
|
1696
|
+
*
|
|
1697
|
+
* @param fault - The fault to describe
|
|
1698
|
+
* @param schema - The compiled schema the fault's path reads
|
|
1699
|
+
* @returns The line, with no line break
|
|
1700
|
+
*
|
|
1701
|
+
* @example
|
|
1702
|
+
* ```ts
|
|
1703
|
+
* import { describeFaultLine } from '@orkestrel/contract'
|
|
1704
|
+
*
|
|
1705
|
+
* describeFaultLine({ reason: 'missing', path: ['left'], expected: 'number' }, {}) // 'left: missing; expected number'
|
|
1706
|
+
* ```
|
|
1707
|
+
*/
|
|
1708
|
+
export declare function describeFaultLine(fault: AuditFault, schema: JSONSchema): string;
|
|
1709
|
+
|
|
1710
|
+
/**
|
|
1711
|
+
* Describes bounded faults with encoded values and a schema-derived correction summary.
|
|
1712
|
+
*
|
|
1713
|
+
* @remarks
|
|
1714
|
+
* Default: 2048 UTF-16 code units. A smaller non-negative integer limit reserves a caller's
|
|
1715
|
+
* heading budget. The report reserves room for omitted-fault and cap notices, and ends with a
|
|
1716
|
+
* send summary when a schema is supplied. Untrusted names, descriptions, and strings use preview.
|
|
1717
|
+
*
|
|
1718
|
+
* @example
|
|
1719
|
+
* ```ts
|
|
1720
|
+
* describeFaults([{ reason: 'missing', path: ['age'], expected: 'number' }])
|
|
1721
|
+
* // 'age: missing; expected number'
|
|
1722
|
+
* ```
|
|
1723
|
+
*/
|
|
1724
|
+
export declare function describeFaults(faults: readonly AuditFault[], schema?: JSONSchema, options?: FaultTextOptions): string;
|
|
1725
|
+
|
|
1585
1726
|
/**
|
|
1586
1727
|
* Draws and validates one generator random sample.
|
|
1587
1728
|
*
|
|
@@ -1771,6 +1912,62 @@ export declare function escapeRegExp(value: string): string;
|
|
|
1771
1912
|
/** Evaluates a compiled node at one diagnostic path. */
|
|
1772
1913
|
export declare type EvaluationFunction<T> = (value: unknown, path: readonly string[]) => T;
|
|
1773
1914
|
|
|
1915
|
+
/**
|
|
1916
|
+
* Extracts a schema's forms: the schema itself, then its union arms, so a read looks
|
|
1917
|
+
* through a nullable the same way everywhere.
|
|
1918
|
+
*
|
|
1919
|
+
* @param schema - The schema to read, or `undefined` where none was found
|
|
1920
|
+
* @returns The forms, empty when there is no schema
|
|
1921
|
+
*
|
|
1922
|
+
* @example
|
|
1923
|
+
* ```ts
|
|
1924
|
+
* import { extractForms } from '@orkestrel/contract'
|
|
1925
|
+
*
|
|
1926
|
+
* const object = { type: 'object' } as const
|
|
1927
|
+
* extractForms({ anyOf: [object] }) // [{ anyOf: [object] }, object]
|
|
1928
|
+
* ```
|
|
1929
|
+
*/
|
|
1930
|
+
export declare function extractForms(schema: JSONSchema | undefined): readonly JSONSchema[];
|
|
1931
|
+
|
|
1932
|
+
/**
|
|
1933
|
+
* Extracts a fault's path as its segments, reading a string path as one segment.
|
|
1934
|
+
*
|
|
1935
|
+
* @param fault - The fault to read
|
|
1936
|
+
* @returns The path's segments, empty at the root
|
|
1937
|
+
*
|
|
1938
|
+
* @example
|
|
1939
|
+
* ```ts
|
|
1940
|
+
* import { extractPath } from '@orkestrel/contract'
|
|
1941
|
+
*
|
|
1942
|
+
* extractPath({ reason: 'extra', path: ['page', 'typo'] }) // ['page', 'typo']
|
|
1943
|
+
* ```
|
|
1944
|
+
*/
|
|
1945
|
+
export declare function extractPath(fault: AuditFault): readonly string[];
|
|
1946
|
+
|
|
1947
|
+
/**
|
|
1948
|
+
* Extracts the part of a schema a path reaches, through properties, array items, record values,
|
|
1949
|
+
* and the arms of a union.
|
|
1950
|
+
*
|
|
1951
|
+
* @remarks
|
|
1952
|
+
* Each path segment takes one step, so a union that nests itself cannot hold the walk. Only a
|
|
1953
|
+
* schema's own `properties` keys match, so `constructor` reaches nothing. The walk keeps every
|
|
1954
|
+
* matching union declaration until the end; differing declarations yield no schema. Independently
|
|
1955
|
+
* built declarations agree when their canonical JSON encodings agree.
|
|
1956
|
+
*
|
|
1957
|
+
* @param schema - The schema to walk
|
|
1958
|
+
* @param path - The segments to follow
|
|
1959
|
+
* @returns The schema at that path, or `undefined` where no declaration or no agreement exists
|
|
1960
|
+
*
|
|
1961
|
+
* @example
|
|
1962
|
+
* ```ts
|
|
1963
|
+
* import { extractSchema } from '@orkestrel/contract'
|
|
1964
|
+
*
|
|
1965
|
+
* const schema = { type: 'object', properties: { limit: { type: 'number' } } } as const
|
|
1966
|
+
* extractSchema(schema, ['limit']) // { type: 'number' }
|
|
1967
|
+
* ```
|
|
1968
|
+
*/
|
|
1969
|
+
export declare function extractSchema(schema: JSONSchema, path: readonly string[]): JSONSchema | undefined;
|
|
1970
|
+
|
|
1774
1971
|
/**
|
|
1775
1972
|
* Represents a key present on a value that its closed object shape does not declare.
|
|
1776
1973
|
*
|
|
@@ -1822,6 +2019,10 @@ export declare function failure<E>(error: E): Failure<E>;
|
|
|
1822
2019
|
* variant count, followed (in the report) by the closest variant's own faults.
|
|
1823
2020
|
* - `'oneOf'` — a `oneOf`-mode union matched zero or two-or-more variants;
|
|
1824
2021
|
* `matched` is the raw match count.
|
|
2022
|
+
*
|
|
2023
|
+
* A union whose arms a required literal property can tell apart reports the named
|
|
2024
|
+
* arm's own faults in place of either, and when the value names no one arm, `key`
|
|
2025
|
+
* and `expected` on these two say which property would and what it may hold.
|
|
1825
2026
|
*/
|
|
1826
2027
|
export declare type Fault = {
|
|
1827
2028
|
readonly reason: 'type';
|
|
@@ -1843,12 +2044,42 @@ export declare type Fault = {
|
|
|
1843
2044
|
readonly reason: 'variant';
|
|
1844
2045
|
readonly path: FieldPath;
|
|
1845
2046
|
readonly variants: number;
|
|
2047
|
+
readonly key?: string;
|
|
2048
|
+
readonly expected?: readonly LiteralValue[];
|
|
1846
2049
|
} | {
|
|
1847
2050
|
readonly reason: 'oneOf';
|
|
1848
2051
|
readonly path: FieldPath;
|
|
1849
2052
|
readonly matched: number;
|
|
2053
|
+
readonly key?: string;
|
|
2054
|
+
readonly expected?: readonly LiteralValue[];
|
|
1850
2055
|
};
|
|
1851
2056
|
|
|
2057
|
+
/**
|
|
2058
|
+
* Lists every {@link FaultConstraint}, frozen.
|
|
2059
|
+
*
|
|
2060
|
+
* @remarks
|
|
2061
|
+
* The runtime source of truth for the vocabulary, which {@link isFault} reads.
|
|
2062
|
+
*
|
|
2063
|
+
* @example
|
|
2064
|
+
* ```ts
|
|
2065
|
+
* FAULT_CONSTRAINTS.includes('min') // true
|
|
2066
|
+
* ```
|
|
2067
|
+
*/
|
|
2068
|
+
export declare const FAULT_CONSTRAINTS: readonly FaultConstraint[];
|
|
2069
|
+
|
|
2070
|
+
/**
|
|
2071
|
+
* Lists every {@link FaultKind}, frozen.
|
|
2072
|
+
*
|
|
2073
|
+
* @remarks
|
|
2074
|
+
* The runtime source of truth for the vocabulary, which {@link isFault} reads.
|
|
2075
|
+
*
|
|
2076
|
+
* @example
|
|
2077
|
+
* ```ts
|
|
2078
|
+
* FAULT_KINDS.includes('string') // true
|
|
2079
|
+
* ```
|
|
2080
|
+
*/
|
|
2081
|
+
export declare const FAULT_KINDS: readonly FaultKind[];
|
|
2082
|
+
|
|
1852
2083
|
/**
|
|
1853
2084
|
* Caps at `64` the number of {@link Fault} / {@link AuditFault} entries a single
|
|
1854
2085
|
* `explain` or `audit` report ever returns, frozen.
|
|
@@ -1864,6 +2095,15 @@ export declare type Fault = {
|
|
|
1864
2095
|
*/
|
|
1865
2096
|
export declare const FAULT_LIMIT = 64;
|
|
1866
2097
|
|
|
2098
|
+
/** Caps the keys or literal candidates named in a fault line. */
|
|
2099
|
+
export declare const FAULT_LIST_LIMIT = 12;
|
|
2100
|
+
|
|
2101
|
+
/** Caps a schema summary's UTF-16 code units. */
|
|
2102
|
+
export declare const FAULT_SCHEMA_LIMIT = 160;
|
|
2103
|
+
|
|
2104
|
+
/** Caps a fault message at 2048 UTF-16 code units. */
|
|
2105
|
+
export declare const FAULT_TEXT_LIMIT = 2048;
|
|
2106
|
+
|
|
1867
2107
|
/**
|
|
1868
2108
|
* Names the refinement a {@link Fault} of reason `'constraint'` violates.
|
|
1869
2109
|
*
|
|
@@ -1878,9 +2118,86 @@ export declare type FaultConstraint = 'min' | 'max' | 'pattern' | 'integer';
|
|
|
1878
2118
|
*
|
|
1879
2119
|
* @remarks
|
|
1880
2120
|
* The vocabulary is `'string'`, `'number'`, `'integer'`, `'boolean'`, `'null'`,
|
|
1881
|
-
* `'literal'`, `'array'`, `'object'`, `'union'`, and `'
|
|
2121
|
+
* `'literal'`, `'array'`, `'object'`, `'union'`, `'json'`, and `'shape'`.
|
|
1882
2122
|
*/
|
|
1883
|
-
export declare type FaultKind = 'string' | 'number' | 'integer' | 'boolean' | 'null' | 'literal' | 'array' | 'object' | 'union' | 'json';
|
|
2123
|
+
export declare type FaultKind = 'string' | 'number' | 'integer' | 'boolean' | 'null' | 'literal' | 'array' | 'object' | 'union' | 'json' | 'shape';
|
|
2124
|
+
|
|
2125
|
+
/**
|
|
2126
|
+
* Retains a lazily built fault declaration without building shapes during module evaluation.
|
|
2127
|
+
*
|
|
2128
|
+
* @example
|
|
2129
|
+
* ```ts
|
|
2130
|
+
* FaultShaper.shape === FaultShaper.shape // true
|
|
2131
|
+
* ```
|
|
2132
|
+
*/
|
|
2133
|
+
declare class FaultShaper {
|
|
2134
|
+
#private;
|
|
2135
|
+
/** Returns the shared fault declaration, building it on the first read. */
|
|
2136
|
+
static get shape(): AuditFaultShape;
|
|
2137
|
+
/**
|
|
2138
|
+
* Builds a closed fault union whose inferred values satisfy the audit fault contract.
|
|
2139
|
+
*
|
|
2140
|
+
* @example
|
|
2141
|
+
* ```ts
|
|
2142
|
+
* createContract(new FaultShaper().build()).is({ reason: 'extra', path: [] }) // true
|
|
2143
|
+
* ```
|
|
2144
|
+
*/
|
|
2145
|
+
build(): UnionShape<readonly [ObjectShape< {
|
|
2146
|
+
reason: LiteralShape<readonly ["type"]>;
|
|
2147
|
+
path: UnionShape<readonly [StringShape, ArrayShape<StringShape>]>;
|
|
2148
|
+
expected: LiteralShape<readonly FaultKind[]>;
|
|
2149
|
+
received: StringShape;
|
|
2150
|
+
}, false>, ObjectShape< {
|
|
2151
|
+
reason: LiteralShape<readonly ["missing"]>;
|
|
2152
|
+
path: UnionShape<readonly [StringShape, ArrayShape<StringShape>]>;
|
|
2153
|
+
expected: LiteralShape<readonly FaultKind[]>;
|
|
2154
|
+
}, false>, ObjectShape< {
|
|
2155
|
+
reason: LiteralShape<readonly ["constraint"]>;
|
|
2156
|
+
path: UnionShape<readonly [StringShape, ArrayShape<StringShape>]>;
|
|
2157
|
+
expected: LiteralShape<readonly FaultKind[]>;
|
|
2158
|
+
constraint: LiteralShape<readonly FaultConstraint[]>;
|
|
2159
|
+
limit: OptionalShape<UnionShape<readonly [NumberShape, StringShape]>>;
|
|
2160
|
+
received: StringShape;
|
|
2161
|
+
}, false>, ObjectShape< {
|
|
2162
|
+
reason: LiteralShape<readonly ["variant"]>;
|
|
2163
|
+
path: UnionShape<readonly [StringShape, ArrayShape<StringShape>]>;
|
|
2164
|
+
variants: NumberShape;
|
|
2165
|
+
}, false>, ObjectShape< {
|
|
2166
|
+
reason: LiteralShape<readonly ["variant"]>;
|
|
2167
|
+
path: UnionShape<readonly [StringShape, ArrayShape<StringShape>]>;
|
|
2168
|
+
variants: NumberShape;
|
|
2169
|
+
key: StringShape;
|
|
2170
|
+
expected: ArrayShape<UnionShape<readonly [StringShape, NumberShape, BooleanShape]>>;
|
|
2171
|
+
}, false>, ObjectShape< {
|
|
2172
|
+
reason: LiteralShape<readonly ["oneOf"]>;
|
|
2173
|
+
path: UnionShape<readonly [StringShape, ArrayShape<StringShape>]>;
|
|
2174
|
+
matched: NumberShape;
|
|
2175
|
+
}, false>, ObjectShape< {
|
|
2176
|
+
reason: LiteralShape<readonly ["oneOf"]>;
|
|
2177
|
+
path: UnionShape<readonly [StringShape, ArrayShape<StringShape>]>;
|
|
2178
|
+
matched: NumberShape;
|
|
2179
|
+
key: StringShape;
|
|
2180
|
+
expected: ArrayShape<UnionShape<readonly [StringShape, NumberShape, BooleanShape]>>;
|
|
2181
|
+
}, false>, ObjectShape< {
|
|
2182
|
+
reason: LiteralShape<readonly ["extra"]>;
|
|
2183
|
+
path: UnionShape<readonly [StringShape, ArrayShape<StringShape>]>;
|
|
2184
|
+
}, false>]>;
|
|
2185
|
+
}
|
|
2186
|
+
|
|
2187
|
+
/**
|
|
2188
|
+
* Reserves a caller's text budget for a bounded fault report.
|
|
2189
|
+
*
|
|
2190
|
+
* @remarks
|
|
2191
|
+
* The limit is a non-negative integer of UTF-16 code units, at most 2048. Default: 2048.
|
|
2192
|
+
*
|
|
2193
|
+
* @example
|
|
2194
|
+
* ```ts
|
|
2195
|
+
* const options: FaultTextOptions = { limit: 1024 }
|
|
2196
|
+
* ```
|
|
2197
|
+
*/
|
|
2198
|
+
export declare interface FaultTextOptions {
|
|
2199
|
+
readonly limit?: number;
|
|
2200
|
+
}
|
|
1884
2201
|
|
|
1885
2202
|
/**
|
|
1886
2203
|
* Addresses one field in a record: a single key, or an ordered list of keys to
|
|
@@ -2033,7 +2350,7 @@ export declare function holds(callback: () => boolean): boolean;
|
|
|
2033
2350
|
* nesting. {@link InferIndex} and {@link InferOpenIndex} apply the identical
|
|
2034
2351
|
* tuple guard to their own `A` parameter for the same reason.
|
|
2035
2352
|
*/
|
|
2036
|
-
export declare type Infer<S extends ContractShape> = [ContractShape] extends [S] ? unknown : S extends StringShape ? string : S extends NumberShape ? number : S extends BooleanShape ? boolean : S extends NullShape ? null : S extends {
|
|
2353
|
+
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 {
|
|
2037
2354
|
readonly category: 'literal';
|
|
2038
2355
|
readonly values: infer V;
|
|
2039
2356
|
} ? V extends ReadonlyArray<infer L> ? L : never : S extends {
|
|
@@ -2664,6 +2981,23 @@ export declare function isAsyncGeneratorFunction(value: unknown): value is (...a
|
|
|
2664
2981
|
*/
|
|
2665
2982
|
export declare function isAsyncIterable<T = unknown>(value: unknown): value is AsyncIterable<T>;
|
|
2666
2983
|
|
|
2984
|
+
/**
|
|
2985
|
+
* Determines whether a value is exactly one {@link AuditFault}.
|
|
2986
|
+
*
|
|
2987
|
+
* @remarks
|
|
2988
|
+
* Every {@link Fault}, and the undeclared-key fault an audit adds.
|
|
2989
|
+
*
|
|
2990
|
+
* @param value - The value to inspect
|
|
2991
|
+
* @returns True if the value is a well-formed audit fault; false otherwise
|
|
2992
|
+
*
|
|
2993
|
+
* @example
|
|
2994
|
+
* ```ts
|
|
2995
|
+
* isAuditFault({ reason: 'extra', path: ['a'] }) // true
|
|
2996
|
+
* isAuditFault({}) // false
|
|
2997
|
+
* ```
|
|
2998
|
+
*/
|
|
2999
|
+
export declare function isAuditFault(value: unknown): value is AuditFault;
|
|
3000
|
+
|
|
2667
3001
|
/** Determines whether a value is a bigint.
|
|
2668
3002
|
*
|
|
2669
3003
|
* @param value - The value to inspect
|
|
@@ -2964,6 +3298,39 @@ export declare function isFailure<T, E>(result: Result<T, E>): result is Failure
|
|
|
2964
3298
|
*/
|
|
2965
3299
|
export declare function isFalse(value: unknown): value is false;
|
|
2966
3300
|
|
|
3301
|
+
/**
|
|
3302
|
+
* Determines whether a value is exactly one {@link Fault}.
|
|
3303
|
+
*
|
|
3304
|
+
* @remarks
|
|
3305
|
+
* A closed reading of the union: each reason's required fields, each with its own
|
|
3306
|
+
* vocabulary, and no other key, so `{}` and a fault carrying a stray field both answer
|
|
3307
|
+
* `false`. An undeclared-key fault is an {@link AuditFault} and answers `false` here.
|
|
3308
|
+
*
|
|
3309
|
+
* @param value - The value to inspect
|
|
3310
|
+
* @returns True if the value is a well-formed fault; false otherwise
|
|
3311
|
+
*
|
|
3312
|
+
* @example
|
|
3313
|
+
* ```ts
|
|
3314
|
+
* isFault({ reason: 'missing', path: ['a'], expected: 'string' }) // true
|
|
3315
|
+
* isFault({}) // false
|
|
3316
|
+
* ```
|
|
3317
|
+
*/
|
|
3318
|
+
export declare function isFault(value: unknown): value is Fault;
|
|
3319
|
+
|
|
3320
|
+
/**
|
|
3321
|
+
* Determines whether a value is the {@link FieldPath} a fault carries: a key, or a dense list of keys.
|
|
3322
|
+
*
|
|
3323
|
+
* @param value - The value to inspect
|
|
3324
|
+
* @returns True if the value is a string or a dense array of strings; false otherwise
|
|
3325
|
+
*
|
|
3326
|
+
* @example
|
|
3327
|
+
* ```ts
|
|
3328
|
+
* isFaultPath(['user', 'name']) // true
|
|
3329
|
+
* isFaultPath([1]) // false
|
|
3330
|
+
* ```
|
|
3331
|
+
*/
|
|
3332
|
+
export declare function isFaultPath(value: unknown): value is FieldPath;
|
|
3333
|
+
|
|
2967
3334
|
/** Determines whether a value is a finite number (excludes `NaN` and `±Infinity`).
|
|
2968
3335
|
*
|
|
2969
3336
|
* @param value - The value to inspect
|
|
@@ -3798,10 +4165,13 @@ export declare class JSONCloner implements JSONClonerInterface {
|
|
|
3798
4165
|
/**
|
|
3799
4166
|
* Clones the retained source into exact, deeply frozen JSON data.
|
|
3800
4167
|
*
|
|
4168
|
+
* @param budget - Remaining nodes shared with an enclosing ownership operation
|
|
3801
4169
|
* @returns The settled JSON snapshot
|
|
3802
4170
|
* @throws {ContractError} When the source is inexact, cyclic, unreadable, or cloning is reentered
|
|
3803
4171
|
*/
|
|
3804
|
-
clone(
|
|
4172
|
+
clone(budget?: {
|
|
4173
|
+
left: number;
|
|
4174
|
+
}): JSONValue;
|
|
3805
4175
|
}
|
|
3806
4176
|
|
|
3807
4177
|
/**
|
|
@@ -3827,10 +4197,13 @@ export declare interface JSONClonerInterface {
|
|
|
3827
4197
|
* alike. Active reentry permanently settles the instance with one exact cause-free
|
|
3828
4198
|
* `clone` poison shared by the nested call, the outer call, and every later call.
|
|
3829
4199
|
*
|
|
4200
|
+
* @param budget - Remaining nodes shared with an enclosing ownership operation; omitted for an independent snapshot
|
|
3830
4201
|
* @returns The settled JSON snapshot
|
|
3831
4202
|
* @throws {ContractError} When the source is inexact, cyclic, unreadable, or cloning is reentered
|
|
3832
4203
|
*/
|
|
3833
|
-
clone(
|
|
4204
|
+
clone(budget?: {
|
|
4205
|
+
left: number;
|
|
4206
|
+
}): JSONValue;
|
|
3834
4207
|
}
|
|
3835
4208
|
|
|
3836
4209
|
/**
|
|
@@ -3879,6 +4252,7 @@ export declare type JSONRecord = {
|
|
|
3879
4252
|
export declare interface JSONSchema {
|
|
3880
4253
|
readonly type?: JSONSchemaType;
|
|
3881
4254
|
readonly description?: string;
|
|
4255
|
+
readonly default?: JSONValue;
|
|
3882
4256
|
readonly enum?: readonly LiteralValue[];
|
|
3883
4257
|
readonly minLength?: number;
|
|
3884
4258
|
readonly maxLength?: number;
|
|
@@ -4121,6 +4495,27 @@ export declare function mapOf<K, V>(keyGuard: Guard<K>, valueGuard: Guard<V>): G
|
|
|
4121
4495
|
|
|
4122
4496
|
export declare function mapOf(keyPredicate: (value: unknown) => boolean, valuePredicate: (value: unknown) => boolean): Guard<ReadonlyMap<unknown, unknown>>;
|
|
4123
4497
|
|
|
4498
|
+
/**
|
|
4499
|
+
* Determines whether an object holds exactly the named own keys.
|
|
4500
|
+
*
|
|
4501
|
+
* @remarks
|
|
4502
|
+
* Every required key must be own, and every own key, symbols and non-enumerable ones
|
|
4503
|
+
* included, must be named, so an inherited field and a stray one both answer `false`.
|
|
4504
|
+
*
|
|
4505
|
+
* @param value - The object to inspect
|
|
4506
|
+
* @param required - The keys it must own
|
|
4507
|
+
* @param optional - The keys it may own
|
|
4508
|
+
* @returns True if its own keys are exactly those; false otherwise
|
|
4509
|
+
*
|
|
4510
|
+
* @example
|
|
4511
|
+
* ```ts
|
|
4512
|
+
* matchesExactKeys({ a: 1 }, ['a']) // true
|
|
4513
|
+
* matchesExactKeys({ a: 1, b: 2 }, ['a']) // false
|
|
4514
|
+
* matchesExactKeys({ a: 1, b: 2 }, ['a'], ['b']) // true
|
|
4515
|
+
* ```
|
|
4516
|
+
*/
|
|
4517
|
+
export declare function matchesExactKeys(value: object, required: readonly string[], optional?: readonly string[]): boolean;
|
|
4518
|
+
|
|
4124
4519
|
/**
|
|
4125
4520
|
* Checks whether a supported ISO-8601 date or date-time names a real instant.
|
|
4126
4521
|
*
|
|
@@ -4194,13 +4589,16 @@ export declare function matchesJSONDepth(value: unknown): boolean;
|
|
|
4194
4589
|
*
|
|
4195
4590
|
* Beside the ancestor set the walk keeps a walk-local PROVED set, so a node
|
|
4196
4591
|
* whose whole subtree already matched is not re-walked when a second path
|
|
4197
|
-
* reaches it.
|
|
4592
|
+
* reaches it. A supplied capture budget instead charges each occurrence that
|
|
4593
|
+
* ownership would copy; exhaustion throws `structure` with a `clone` cause.
|
|
4594
|
+
* Removing the recursion alone left the work exponential in shared
|
|
4198
4595
|
* aliases: thirty aliases — thirty-one ordinary records — cost `2^30` visits
|
|
4199
4596
|
* through `isJSONValue`, `parseJSONValue`, `canonicalStringify` and every
|
|
4200
4597
|
* `jsonShape` contract.
|
|
4201
4598
|
*
|
|
4202
4599
|
* @param entry - The value to inspect
|
|
4203
4600
|
* @param ancestors - Objects on the active traversal path
|
|
4601
|
+
* @param budget - Remaining capture nodes; aliases are charged for each copied occurrence when supplied
|
|
4204
4602
|
* @returns True if the value is a cycle-free JSON value; false otherwise
|
|
4205
4603
|
*
|
|
4206
4604
|
* @example
|
|
@@ -4209,7 +4607,37 @@ export declare function matchesJSONDepth(value: unknown): boolean;
|
|
|
4209
4607
|
* matchesJSONValue(Number.NaN, new WeakSet()) // false
|
|
4210
4608
|
* ```
|
|
4211
4609
|
*/
|
|
4212
|
-
export declare function matchesJSONValue(entry: unknown, ancestors: WeakSet<object
|
|
4610
|
+
export declare function matchesJSONValue(entry: unknown, ancestors: WeakSet<object>, budget?: {
|
|
4611
|
+
left: number;
|
|
4612
|
+
}): entry is JSONValue;
|
|
4613
|
+
|
|
4614
|
+
/**
|
|
4615
|
+
* Determines whether a repair `parse` made kept everything the value said.
|
|
4616
|
+
*
|
|
4617
|
+
* @remarks
|
|
4618
|
+
* `parse`'s coercions are published and form input relies on them, but some change what
|
|
4619
|
+
* a value means: `1` to `true`, `'9007199254740993'` to `...992`, `'1e-400'` to `0`,
|
|
4620
|
+
* `'0x10'` to `16`. A door that must not guess asks this about each fault `audit` reported,
|
|
4621
|
+
* since `audit` already names every nested repair with its path and the kind it wanted.
|
|
4622
|
+
*
|
|
4623
|
+
* Only a `type` fault is a repair. A number needs a string whose trim is the number's own
|
|
4624
|
+
* text, so `'30'` and `' 30 '` pass while `'30.0'`, `'007'`, `'0x10'`, `'1e3'`, `'+5'`,
|
|
4625
|
+
* `'.5'`, `'-0'`, and `'9007199254740993'` do not. A boolean needs `'true'` or `'false'`,
|
|
4626
|
+
* a literal its trimmed text, and a string a finite number. Anything else refuses.
|
|
4627
|
+
*
|
|
4628
|
+
* @param fault - A fault `audit` reported
|
|
4629
|
+
* @param input - The value as it arrived
|
|
4630
|
+
* @param parsed - What `parse` made of it
|
|
4631
|
+
* @returns True if the repair loses nothing; false otherwise
|
|
4632
|
+
*
|
|
4633
|
+
* @example
|
|
4634
|
+
* ```ts
|
|
4635
|
+
* const fault = { reason: 'type', path: ['a'], expected: 'number', received: '' } as const
|
|
4636
|
+
* matchesLosslessRepair(fault, { a: ' 30 ' }, { a: 30 }) // true
|
|
4637
|
+
* matchesLosslessRepair(fault, { a: '30.0' }, { a: 30 }) // false
|
|
4638
|
+
* ```
|
|
4639
|
+
*/
|
|
4640
|
+
export declare function matchesLosslessRepair(fault: AuditFault, input: unknown, parsed: unknown): boolean;
|
|
4213
4641
|
|
|
4214
4642
|
/**
|
|
4215
4643
|
* Determines whether a value is a member of a collected vocabulary, by
|
|
@@ -4324,6 +4752,44 @@ export declare function matchesPattern(pattern: RegExp, value: string): boolean;
|
|
|
4324
4752
|
*/
|
|
4325
4753
|
export declare function matchesRecordBrand(value: unknown): boolean;
|
|
4326
4754
|
|
|
4755
|
+
/**
|
|
4756
|
+
* Checks whether a string's length in code points falls within optional bounds.
|
|
4757
|
+
*
|
|
4758
|
+
* @remarks
|
|
4759
|
+
* Counts what JSON Schema's `minLength` and `maxLength` count: a surrogate pair is
|
|
4760
|
+
* one, and a lone surrogate is one. A string holds at most `.length` code points and
|
|
4761
|
+
* at least half that, so `.length` decides every bound it can with no count. The
|
|
4762
|
+
* count runs only where a bound sits between those two figures, which limits its
|
|
4763
|
+
* work to about twice the bound rather than to the size of the string.
|
|
4764
|
+
*
|
|
4765
|
+
* @param value - The string to measure
|
|
4766
|
+
* @param min - The inclusive lower bound, when there is one
|
|
4767
|
+
* @param max - The inclusive upper bound, when there is one
|
|
4768
|
+
* @returns True if the code-point count is within every present bound; false otherwise
|
|
4769
|
+
*
|
|
4770
|
+
* @example
|
|
4771
|
+
* ```ts
|
|
4772
|
+
* matchesStringLength('😀😀', undefined, 2) // true
|
|
4773
|
+
* matchesStringLength('😀', 2, undefined) // false
|
|
4774
|
+
* ```
|
|
4775
|
+
*/
|
|
4776
|
+
export declare function matchesStringLength(value: string, min: number | undefined, max: number | undefined): boolean;
|
|
4777
|
+
|
|
4778
|
+
/**
|
|
4779
|
+
* Checks whether a type fault describes an own undefined field omitted or defaulted by a successful parse.
|
|
4780
|
+
*
|
|
4781
|
+
* @remarks
|
|
4782
|
+
* Reads own members directly so absence and an unreadable member cannot stand for undefined.
|
|
4783
|
+
* A compiled parser fills an undefined field only through its declared default; it never coerces it.
|
|
4784
|
+
* Required reads propagate their cause to the admission boundary.
|
|
4785
|
+
*
|
|
4786
|
+
* @example
|
|
4787
|
+
* ```ts
|
|
4788
|
+
* matchesUndefinedField({ reason: 'type', path: ['note'], expected: 'string', received: 'undefined' }, { note: undefined }, {}) // true
|
|
4789
|
+
* ```
|
|
4790
|
+
*/
|
|
4791
|
+
export declare function matchesUndefinedField(fault: AuditFault, value: unknown, parsed: unknown): boolean;
|
|
4792
|
+
|
|
4327
4793
|
/**
|
|
4328
4794
|
* Determines whether an object is already on a traversal's active path.
|
|
4329
4795
|
*
|
|
@@ -4658,9 +5124,11 @@ export declare function omitVisited(visited: WeakSet<object>, value: object): vo
|
|
|
4658
5124
|
* {@link unionShape}'s guard.
|
|
4659
5125
|
* - **Parser**: judged on the RAW input's guard matches only, with NO
|
|
4660
5126
|
* coercion fallback for an ambiguous input. When exactly one variant's
|
|
4661
|
-
* guard accepts the raw value,
|
|
5127
|
+
* guard accepts the raw value, the input itself is returned. Zero matches or
|
|
4662
5128
|
* two-or-more matches both parse to `undefined` — a value ambiguous
|
|
4663
|
-
* between variants has no well-defined coercion target.
|
|
5129
|
+
* between variants has no well-defined coercion target. A value that names one
|
|
5130
|
+
* arm through a required literal is not ambiguous, so as in {@link unionShape}
|
|
5131
|
+
* that arm answers alone, and its parser may coerce.
|
|
4664
5132
|
*
|
|
4665
5133
|
* Prefer {@link unionShape} when a value may legitimately satisfy more than
|
|
4666
5134
|
* one variant (for example overlapping shapes) and any match is acceptable. Prefer
|
|
@@ -4714,10 +5182,19 @@ export declare type OptionalFromGuards<S extends GuardsShape, K extends Readonly
|
|
|
4714
5182
|
*/
|
|
4715
5183
|
export declare function optionalOf<T>(guard: Guard<T>): Guard<T | undefined>;
|
|
4716
5184
|
|
|
4717
|
-
/**
|
|
5185
|
+
/**
|
|
5186
|
+
* Wraps an inner shape that may be absent (`undefined`).
|
|
5187
|
+
*
|
|
5188
|
+
* @remarks
|
|
5189
|
+
* `default` holds the JSON value the compiled parser fills when the property is
|
|
5190
|
+
* absent or `undefined`. It leaves `is`, `audit`, `explain`, and `generate`
|
|
5191
|
+
* unchanged, because an absent optional stays canonical. It must satisfy `inner`,
|
|
5192
|
+
* and it may sit only on a property of a closed object with no union ancestor.
|
|
5193
|
+
*/
|
|
4718
5194
|
export declare interface OptionalShape<S extends ContractShape = ContractShape> {
|
|
4719
5195
|
readonly category: 'optional';
|
|
4720
5196
|
readonly inner: S;
|
|
5197
|
+
readonly default?: JSONValue;
|
|
4721
5198
|
}
|
|
4722
5199
|
|
|
4723
5200
|
/**
|
|
@@ -4725,12 +5202,28 @@ export declare interface OptionalShape<S extends ContractShape = ContractShape>
|
|
|
4725
5202
|
*
|
|
4726
5203
|
* @remarks
|
|
4727
5204
|
* As an {@link objectShape} property, the field becomes a true optional property
|
|
4728
|
-
* in the inferred type.
|
|
5205
|
+
* in the inferred type. A `default` is captured as an owned frozen copy, and the
|
|
5206
|
+
* compiled parser fills it where the property is absent or `undefined`; the guard,
|
|
5207
|
+
* the audit, the report, and the generator keep treating the property as optional.
|
|
5208
|
+
* The compilers refuse a default `inner` refuses, a default under a union, and a
|
|
5209
|
+
* default on a property of an open object.
|
|
4729
5210
|
*
|
|
4730
5211
|
* @param inner - The wrapped shape
|
|
5212
|
+
* @param options - Optional `default`, a JSON value
|
|
4731
5213
|
* @returns An optional shape
|
|
5214
|
+
* @throws {ContractError} When a present `default` is not a JSON value, `undefined` included
|
|
5215
|
+
*
|
|
5216
|
+
* @example
|
|
5217
|
+
* ```ts
|
|
5218
|
+
* const retries = optionalShape(integerShape({ min: 0 }), { default: 3 })
|
|
5219
|
+
* ```
|
|
4732
5220
|
*/
|
|
4733
|
-
export declare function optionalShape<S extends ContractShape>(inner: S): OptionalShape<S>;
|
|
5221
|
+
export declare function optionalShape<S extends ContractShape>(inner: S, options?: OptionalShapeOptions): OptionalShape<S>;
|
|
5222
|
+
|
|
5223
|
+
/** Groups the options for {@link OptionalShape} (through `optionalShape`). */
|
|
5224
|
+
export declare interface OptionalShapeOptions {
|
|
5225
|
+
readonly default?: JSONValue;
|
|
5226
|
+
}
|
|
4734
5227
|
|
|
4735
5228
|
/**
|
|
4736
5229
|
* Combines `left` and `right` with logical OR — passes when at least one passes.
|
|
@@ -5405,6 +5898,8 @@ export declare interface RawShape {
|
|
|
5405
5898
|
* For values the shape DSL can't express. The fragment is recursively checked
|
|
5406
5899
|
* against the lean {@link JSONSchema} vocabulary before ownership is taken;
|
|
5407
5900
|
* malformed or unsupported keywords throw a coded {@link ContractError}. The
|
|
5901
|
+
* refusal path starts at `schema` and names the nested keyword or member.
|
|
5902
|
+
* A non-record root is refused at `schema` itself. The
|
|
5408
5903
|
* compiled guard accepts every
|
|
5409
5904
|
* DEFINED value — `undefined` alone fails, because it is the parser's failure
|
|
5410
5905
|
* sentinel; wrap the shape in {@link optionalShape} to admit absence. The
|
|
@@ -5798,6 +6293,87 @@ export declare interface RecordShapeOptions {
|
|
|
5798
6293
|
*/
|
|
5799
6294
|
export declare function refuseExpansion(expansion: number | undefined): void;
|
|
5800
6295
|
|
|
6296
|
+
/**
|
|
6297
|
+
* Refuses an options record that holds a key its builder does not read.
|
|
6298
|
+
*
|
|
6299
|
+
* @remarks
|
|
6300
|
+
* The door for an option that decides what a contract accepts, where a misspelled key
|
|
6301
|
+
* would otherwise read as an absent option and fail open. It looks at own enumerable
|
|
6302
|
+
* string keys, so an inherited or symbol-keyed member is not a misspelling.
|
|
6303
|
+
*
|
|
6304
|
+
* @param source - The builder options, when there are any
|
|
6305
|
+
* @param keys - The keys that builder reads
|
|
6306
|
+
* @param builder - The builder name used in the refusal
|
|
6307
|
+
* @param shape - The shape category used in structured error context
|
|
6308
|
+
* @throws {ContractError} When the record holds any other key
|
|
6309
|
+
*
|
|
6310
|
+
* @example
|
|
6311
|
+
* ```ts
|
|
6312
|
+
* refuseOptionKeys({ strict: true }, ['strict'], 'schemaToShape', 'schema') // returns
|
|
6313
|
+
* refuseOptionKeys({ strct: true }, ['strict'], 'schemaToShape', 'schema') // throws
|
|
6314
|
+
* ```
|
|
6315
|
+
*/
|
|
6316
|
+
export declare function refuseOptionKeys(source: object | undefined, keys: readonly string[], builder: string, shape: string): void;
|
|
6317
|
+
|
|
6318
|
+
/**
|
|
6319
|
+
* Renders a schema as a short summary of what to send, such as `{"city": string, "note"?: string}`.
|
|
6320
|
+
*
|
|
6321
|
+
* @remarks
|
|
6322
|
+
* An object lists its required keys first and marks the rest with `?`, at most `FAULT_LIST_LIMIT`
|
|
6323
|
+
* of them. A leaf or array keeps its numeric bounds and pattern, a union joins its forms with ` | `,
|
|
6324
|
+
* and a schema that says nothing reads `any`. Each nested form takes half the room of its parent, and
|
|
6325
|
+
* below 16 characters a form stops at its type, so a schema that holds itself still ends. Text past
|
|
6326
|
+
* `room` is cut and closes with `…`. A type word outside JSON Schema's vocabulary is encoded.
|
|
6327
|
+
*
|
|
6328
|
+
* @param schema - The schema to summarize
|
|
6329
|
+
* @param room - The characters the summary can take. Default: `FAULT_SCHEMA_LIMIT`
|
|
6330
|
+
* @returns The summary
|
|
6331
|
+
*
|
|
6332
|
+
* @example
|
|
6333
|
+
* ```ts
|
|
6334
|
+
* import { renderForm } from '@orkestrel/contract'
|
|
6335
|
+
*
|
|
6336
|
+
* renderForm({ type: 'object', properties: { zip: { type: 'number' } }, required: ['zip'] }) // '{"zip": number}'
|
|
6337
|
+
* ```
|
|
6338
|
+
*/
|
|
6339
|
+
export declare function renderForm(schema: JSONSchema, room?: number): string;
|
|
6340
|
+
|
|
6341
|
+
/**
|
|
6342
|
+
* Renders a list as text, naming at most `FAULT_LIST_LIMIT` of its entries and counting the rest.
|
|
6343
|
+
*
|
|
6344
|
+
* @param entries - The rendered entries
|
|
6345
|
+
* @returns The entries joined with `, `
|
|
6346
|
+
*
|
|
6347
|
+
* @example
|
|
6348
|
+
* ```ts
|
|
6349
|
+
* import { renderList } from '@orkestrel/contract'
|
|
6350
|
+
*
|
|
6351
|
+
* renderList(['city', 'units']) // 'city, units'
|
|
6352
|
+
* ```
|
|
6353
|
+
*/
|
|
6354
|
+
export declare function renderList(entries: readonly string[]): string;
|
|
6355
|
+
|
|
6356
|
+
/**
|
|
6357
|
+
* Renders a path as text, encoding what a caller could have sent and eliding the middle of a long
|
|
6358
|
+
* one.
|
|
6359
|
+
*
|
|
6360
|
+
* @remarks
|
|
6361
|
+
* A segment that is not a plain identifier is JSON-encoded and length-capped, because a key the
|
|
6362
|
+
* caller sent is untrusted text. A path of more than four segments past 120 characters keeps its
|
|
6363
|
+
* first segment and its last three.
|
|
6364
|
+
*
|
|
6365
|
+
* @param path - The segments to render
|
|
6366
|
+
* @returns The segments joined with `.`, empty at the root
|
|
6367
|
+
*
|
|
6368
|
+
* @example
|
|
6369
|
+
* ```ts
|
|
6370
|
+
* import { renderPath } from '@orkestrel/contract'
|
|
6371
|
+
*
|
|
6372
|
+
* renderPath(['rows', '0', 'a b']) // 'rows.0."a b"'
|
|
6373
|
+
* ```
|
|
6374
|
+
*/
|
|
6375
|
+
export declare function renderPath(path: readonly string[]): string;
|
|
6376
|
+
|
|
5801
6377
|
/**
|
|
5802
6378
|
* Represents a compiled coercive-domain diagnostic — the shape of
|
|
5803
6379
|
* `compileReporter` bound to one shape.
|
|
@@ -6159,8 +6735,9 @@ export declare function schemaToParameters(schema: JSONSchema): Readonly<Record<
|
|
|
6159
6735
|
/**
|
|
6160
6736
|
* Converts a runtime `JSONSchema` value into a validating {@link ContractShape}
|
|
6161
6737
|
* — the inverse of {@link compileSchema}. Unlike direct {@link rawShape}
|
|
6162
|
-
* construction, which rejects malformed supported-vocabulary keywords,
|
|
6163
|
-
* conversion is total and widens an inexpressible input to a valid raw
|
|
6738
|
+
* construction, which rejects malformed supported-vocabulary keywords, the
|
|
6739
|
+
* lenient conversion is total and widens an inexpressible input to a valid raw
|
|
6740
|
+
* `{}`, and a strict conversion refuses that input.
|
|
6164
6741
|
*
|
|
6165
6742
|
* @remarks
|
|
6166
6743
|
* Readable malformed, cyclic, or deeply nested schema nodes widen to
|
|
@@ -6211,9 +6788,36 @@ export declare function schemaToParameters(schema: JSONSchema): Readonly<Record<
|
|
|
6211
6788
|
* when the conversion widened anywhere — `schema` / `is` / `parse` / `explain`
|
|
6212
6789
|
* stay total.
|
|
6213
6790
|
*
|
|
6791
|
+
* LENIENT LAW: a value a JSON Schema accepts is never refused by the shape a
|
|
6792
|
+
* lenient conversion builds from it, because the walk widens what it cannot read.
|
|
6793
|
+
* So `oneOf` builds an inclusive union, a `true` arm is a raw variant and a `false`
|
|
6794
|
+
* arm is dropped, an `enum` holding `null` admits it, `nullable: true` wraps the
|
|
6795
|
+
* node, a present `patternProperties` opens the object, a present `prefixItems`
|
|
6796
|
+
* widens the elements, and a `$ref` widens the node before anything beside it is read.
|
|
6797
|
+
* A schema past the compile limit keeps only its root's type, an array's bounds, and an
|
|
6798
|
+
* object's required keys and closure, with every value below them raw.
|
|
6799
|
+
*
|
|
6800
|
+
* DEFAULTS: a lenient conversion carries a property's `default` when the key is
|
|
6801
|
+
* not `required`, its object is closed with no union ancestor, and the value is
|
|
6802
|
+
* one the property's primitive or literal guard accepts. It drops every other
|
|
6803
|
+
* `default`, because carrying it would make the shape refuse to compile.
|
|
6804
|
+
*
|
|
6805
|
+
* STRICT: `{ strict: true }` is the door for a foreign schema. It refuses, with
|
|
6806
|
+
* code `structure`, every node the lenient walk would widen, every keyword it
|
|
6807
|
+
* would ignore (`pattern`, `format`, `nullable`, `patternProperties`,
|
|
6808
|
+
* `propertyNames`, `prefixItems`, and anything else outside
|
|
6809
|
+
* {@link STRICT_SCHEMA_KEYWORDS}), a malformed keyword or annotation, a boolean schema, an `enum` entry
|
|
6810
|
+
* that is neither a finite primitive nor `null`, a contradictory bound, a `required` name not in
|
|
6811
|
+
* `properties`, breadth past {@link INFER_BREADTH_LIMIT}, and a `default` with no
|
|
6812
|
+
* optional property to fill. An object with no `additionalProperties` closes
|
|
6813
|
+
* rather than opens, and `oneOf` keeps exactly-one, because a strict walk reads
|
|
6814
|
+
* every keyword that could keep two arms apart. Below a `oneOf` that object refuses
|
|
6815
|
+
* instead, since closing it could change which arms match.
|
|
6816
|
+
*
|
|
6214
6817
|
* @param schema - The JSON Schema value to convert
|
|
6818
|
+
* @param options - Optional `strict`, default `false`
|
|
6215
6819
|
* @returns The built {@link ContractShape}
|
|
6216
|
-
* @throws {ContractError} When schema traversal fails
|
|
6820
|
+
* @throws {ContractError} When schema traversal fails, or when a strict conversion refuses
|
|
6217
6821
|
*
|
|
6218
6822
|
* @example
|
|
6219
6823
|
* ```ts
|
|
@@ -6223,7 +6827,18 @@ export declare function schemaToParameters(schema: JSONSchema): Readonly<Record<
|
|
|
6223
6827
|
* contract.parse({ id: 'nope' }) // undefined
|
|
6224
6828
|
* ```
|
|
6225
6829
|
*/
|
|
6226
|
-
export declare function schemaToShape(schema: JSONSchema): ContractShape;
|
|
6830
|
+
export declare function schemaToShape(schema: JSONSchema, options?: SchemaToShapeOptions): ContractShape;
|
|
6831
|
+
|
|
6832
|
+
/**
|
|
6833
|
+
* Groups the options for converting a JSON Schema (through `schemaToShape`).
|
|
6834
|
+
*
|
|
6835
|
+
* @remarks
|
|
6836
|
+
* `strict` (default `false`) refuses what the lenient conversion widens or
|
|
6837
|
+
* ignores, and closes an object with no `additionalProperties`.
|
|
6838
|
+
*/
|
|
6839
|
+
export declare interface SchemaToShapeOptions {
|
|
6840
|
+
readonly strict?: boolean;
|
|
6841
|
+
}
|
|
6227
6842
|
|
|
6228
6843
|
/**
|
|
6229
6844
|
* Builds a deterministic pseudo-random source seeded from a single number.
|
|
@@ -6312,6 +6927,16 @@ export declare function setOf<T>(elementGuard: Guard<T>): Guard<ReadonlySet<T>>;
|
|
|
6312
6927
|
|
|
6313
6928
|
export declare function setOf(elementGuard: (value: unknown) => boolean): Guard<ReadonlySet<unknown>>;
|
|
6314
6929
|
|
|
6930
|
+
/**
|
|
6931
|
+
* Lists the fields recognized for every contract declaration category, frozen.
|
|
6932
|
+
*
|
|
6933
|
+
* @example
|
|
6934
|
+
* ```ts
|
|
6935
|
+
* SHAPE_FIELDS.shape // ['description']
|
|
6936
|
+
* ```
|
|
6937
|
+
*/
|
|
6938
|
+
export declare const SHAPE_FIELDS: Readonly<Record<string, readonly string[]>>;
|
|
6939
|
+
|
|
6315
6940
|
/**
|
|
6316
6941
|
* Owns the state of one contract-shape snapshot operation.
|
|
6317
6942
|
*
|
|
@@ -6396,6 +7021,56 @@ export declare interface ShapeProperty {
|
|
|
6396
7021
|
readonly child: ContractShape | undefined;
|
|
6397
7022
|
}
|
|
6398
7023
|
|
|
7024
|
+
/**
|
|
7025
|
+
* Describes a value that is a structurally valid contract declaration.
|
|
7026
|
+
*
|
|
7027
|
+
* @remarks
|
|
7028
|
+
* Acceptance is a successful {@link validateShape}, including its expansion bound.
|
|
7029
|
+
* Parsing preserves identity and never compiles the value or fills its defaults.
|
|
7030
|
+
* The shallow schema over-approximates declarations whose JSON projection preserves
|
|
7031
|
+
* their own enumerable data. Values with a different projection or no JSON projection
|
|
7032
|
+
* fall outside this schema, including custom `toJSON`, hidden keys, proxy omissions,
|
|
7033
|
+
* and extra members containing a BigInt or a cycle. Structural acceptance is unchanged.
|
|
7034
|
+
* It describes only the category and cannot
|
|
7035
|
+
* teach a language model to author a complete nested declaration. The guard decides.
|
|
7036
|
+
*
|
|
7037
|
+
* @example
|
|
7038
|
+
* ```ts
|
|
7039
|
+
* const declaration: ShapeShape = { category: 'shape' }
|
|
7040
|
+
* createContract(declaration).is(numberShape()) // true
|
|
7041
|
+
* ```
|
|
7042
|
+
*/
|
|
7043
|
+
export declare interface ShapeShape {
|
|
7044
|
+
readonly category: 'shape';
|
|
7045
|
+
readonly description?: string;
|
|
7046
|
+
}
|
|
7047
|
+
|
|
7048
|
+
/**
|
|
7049
|
+
* Builds a {@link ShapeShape}.
|
|
7050
|
+
*
|
|
7051
|
+
* @param options - Optional description
|
|
7052
|
+
* @returns A shape-valued declaration
|
|
7053
|
+
*
|
|
7054
|
+
* @example
|
|
7055
|
+
* ```ts
|
|
7056
|
+
* const definition = objectShape({ shape: shapeShape() })
|
|
7057
|
+
* ```
|
|
7058
|
+
*/
|
|
7059
|
+
export declare function shapeShape(options?: ShapeShapeOptions): ShapeShape;
|
|
7060
|
+
|
|
7061
|
+
/**
|
|
7062
|
+
* Configures the description of a shape-valued declaration.
|
|
7063
|
+
*
|
|
7064
|
+
* @example
|
|
7065
|
+
* ```ts
|
|
7066
|
+
* const options: ShapeShapeOptions = { description: 'A question declaration' }
|
|
7067
|
+
* shapeShape(options).description // 'A question declaration'
|
|
7068
|
+
* ```
|
|
7069
|
+
*/
|
|
7070
|
+
export declare interface ShapeShapeOptions {
|
|
7071
|
+
readonly description?: string;
|
|
7072
|
+
}
|
|
7073
|
+
|
|
6399
7074
|
/**
|
|
6400
7075
|
* Projects a {@link ContractShape} to the {@link FaultKind} it describes.
|
|
6401
7076
|
*
|
|
@@ -6447,7 +7122,7 @@ export declare class ShapeValidator implements ShapeValidatorInterface {
|
|
|
6447
7122
|
*
|
|
6448
7123
|
* @param shape - The live shape source validated by each call
|
|
6449
7124
|
*/
|
|
6450
|
-
constructor(shape:
|
|
7125
|
+
constructor(shape: unknown);
|
|
6451
7126
|
/**
|
|
6452
7127
|
* Reports the number of nodes the last successful {@link validate} found the
|
|
6453
7128
|
* source expands into.
|
|
@@ -6538,6 +7213,24 @@ export declare interface ShapeValidatorInterface {
|
|
|
6538
7213
|
*/
|
|
6539
7214
|
export declare function sortValues<T extends string | number>(values: readonly T[]): readonly T[];
|
|
6540
7215
|
|
|
7216
|
+
/**
|
|
7217
|
+
* Lists the JSON Schema keywords a strict `schemaToShape` conversion reads, frozen.
|
|
7218
|
+
*
|
|
7219
|
+
* @remarks
|
|
7220
|
+
* The keywords a shape can honour, plus the annotations that assert nothing and so
|
|
7221
|
+
* lose nothing when a shape drops them: `title`, `$schema`, `$id`, `$comment`,
|
|
7222
|
+
* `examples`, `deprecated`, `readOnly`, and `writeOnly`. Every other keyword refuses.
|
|
7223
|
+
* `pattern` and `format` are absent because no compiled shape asserts them, so a
|
|
7224
|
+
* schema holding one would convert to a shape wider than the schema it came from.
|
|
7225
|
+
*
|
|
7226
|
+
* @example
|
|
7227
|
+
* ```ts
|
|
7228
|
+
* STRICT_SCHEMA_KEYWORDS.includes('title') // true
|
|
7229
|
+
* STRICT_SCHEMA_KEYWORDS.includes('pattern') // false
|
|
7230
|
+
* ```
|
|
7231
|
+
*/
|
|
7232
|
+
export declare const STRICT_SCHEMA_KEYWORDS: readonly string[];
|
|
7233
|
+
|
|
6541
7234
|
/**
|
|
6542
7235
|
* Caps at `65536` the length, in UTF-16 code units, of any single string one schema
|
|
6543
7236
|
* retains, frozen.
|
|
@@ -6572,8 +7265,9 @@ export declare interface StringGuardOptions {
|
|
|
6572
7265
|
* refinements — `min` / `max` length and a `pattern`.
|
|
6573
7266
|
*
|
|
6574
7267
|
* @remarks
|
|
6575
|
-
* Composes {@link isString} with {@link
|
|
6576
|
-
*
|
|
7268
|
+
* Composes {@link isString} with {@link matchesStringLength}, which counts code
|
|
7269
|
+
* points as the `minLength` and `maxLength` a string shape emits do, and an owned
|
|
7270
|
+
* stateless pattern (the same refinement {@link matchOf} performs).
|
|
6577
7271
|
* When `min`, `max`, and `pattern` are all absent it returns the bare {@link isString} guard
|
|
6578
7272
|
* (the unconstrained fast path), so an unrefined string leaf pays no wrapping
|
|
6579
7273
|
* cost. The single source of the string refinement shared by the compiled guard
|
|
@@ -6595,7 +7289,13 @@ export declare interface StringGuardOptions {
|
|
|
6595
7289
|
*/
|
|
6596
7290
|
export declare function stringOf(options?: StringGuardOptions): Guard<string>;
|
|
6597
7291
|
|
|
6598
|
-
/**
|
|
7292
|
+
/**
|
|
7293
|
+
* Describes a string with optional length and pattern constraints.
|
|
7294
|
+
*
|
|
7295
|
+
* @remarks
|
|
7296
|
+
* `min` and `max` count code points, as the `minLength` and `maxLength` the shape
|
|
7297
|
+
* emits do, so one astral character has a length of one.
|
|
7298
|
+
*/
|
|
6599
7299
|
export declare interface StringShape {
|
|
6600
7300
|
readonly category: 'string';
|
|
6601
7301
|
readonly min?: number;
|
|
@@ -6732,6 +7432,16 @@ export declare function transformOf<T, U>(base: Guard<T>, project: (value: T) =>
|
|
|
6732
7432
|
|
|
6733
7433
|
export declare function transformOf<T>(base: Guard<T>, project: (value: T) => unknown, target: (value: unknown) => boolean): Guard<T>;
|
|
6734
7434
|
|
|
7435
|
+
/**
|
|
7436
|
+
* Truncates text to a UTF-16 budget without splitting a surrogate pair.
|
|
7437
|
+
*
|
|
7438
|
+
* @example
|
|
7439
|
+
* ```ts
|
|
7440
|
+
* truncateFaultText('abcdef', 4) // 'abc…'
|
|
7441
|
+
* ```
|
|
7442
|
+
*/
|
|
7443
|
+
export declare function truncateFaultText(text: string, limit: number): string;
|
|
7444
|
+
|
|
6735
7445
|
/** Maps a tuple of element guards to a readonly tuple of their guarded types. */
|
|
6736
7446
|
export declare type TupleFromGuards<Ts extends ReadonlyArray<Guard<unknown>>> = Readonly<{
|
|
6737
7447
|
[K in keyof Ts]: GuardType<Ts[K]>;
|
|
@@ -6832,6 +7542,13 @@ export declare interface UnionShape<V extends readonly ContractShape[] = readonl
|
|
|
6832
7542
|
/**
|
|
6833
7543
|
* Builds a {@link UnionShape} from a list of variant shapes (`anyOf` in JSON Schema).
|
|
6834
7544
|
*
|
|
7545
|
+
* @remarks
|
|
7546
|
+
* When every arm is an object declaring one required literal property, and a value's
|
|
7547
|
+
* own property exactly equals a literal only one arm holds, that arm answers: `explain`
|
|
7548
|
+
* and `audit` report its faults at their real paths, and `parse` repairs through it
|
|
7549
|
+
* alone. Any other value reports `variant`, with `key` and `expected` saying what would
|
|
7550
|
+
* have named an arm. `is` does not change.
|
|
7551
|
+
*
|
|
6835
7552
|
* @param variants - The candidate shapes; the first match wins at runtime
|
|
6836
7553
|
* @returns A union shape whose `Infer` is the union of the variants
|
|
6837
7554
|
*
|
|
@@ -6876,14 +7593,15 @@ export declare type UnionToIntersection<U> = (U extends unknown ? (k: U) => void
|
|
|
6876
7593
|
* eager well-formedness pass — there is no second prepass and no alias for it:
|
|
6877
7594
|
* it enforces every bound domain and range used by the artifacts, including
|
|
6878
7595
|
* non-empty literal/union vocabularies, finite literal numbers, integer-range
|
|
6879
|
-
* satisfiability, unflagged string patterns, optional-shape
|
|
6880
|
-
* recursively supported raw-schema vocabulary where every
|
|
6881
|
-
* dense union member is a record.
|
|
7596
|
+
* satisfiability, unflagged string patterns, optional-shape and default
|
|
7597
|
+
* placement, and the recursively supported raw-schema vocabulary where every
|
|
7598
|
+
* present property or dense union member is a record. It judges a default's
|
|
7599
|
+
* structure only; each compiler refuses a default its inner guard refuses.
|
|
6882
7600
|
* Active ancestors are tracked so shared children remain legal. Every
|
|
6883
7601
|
* standalone compiler reaches this same validation once, over its owned
|
|
6884
7602
|
* snapshot, through {@link ContractCompiler} preparation.
|
|
6885
|
-
*
|
|
6886
|
-
*
|
|
7603
|
+
* Cyclic graphs refuse before depth measurement, with structure before cycle.
|
|
7604
|
+
* Acyclic graphs report depth before structure, then field and vocabulary policy.
|
|
6887
7605
|
*
|
|
6888
7606
|
* @param shape - The shape graph to gate
|
|
6889
7607
|
* @returns Nothing; successful return means recursive compilation is structurally safe, depth-safe, and bounded in emitted nodes
|
|
@@ -6894,7 +7612,7 @@ export declare type UnionToIntersection<U> = (U extends unknown ? (k: U) => void
|
|
|
6894
7612
|
* validateShape(stringShape({ min: 1 })) // returns; the declaration is compilable
|
|
6895
7613
|
* ```
|
|
6896
7614
|
*/
|
|
6897
|
-
export declare function validateShape(shape:
|
|
7615
|
+
export declare function validateShape(shape: unknown): void;
|
|
6898
7616
|
|
|
6899
7617
|
/**
|
|
6900
7618
|
* Infers a `JSONSchema` for one unknown value — the reverse direction of
|