@orkestrel/contract 0.0.11 → 0.0.13
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 +145 -126
- package/dist/src/core/index.cjs.map +1 -1
- package/dist/src/core/index.d.cts +71 -85
- package/dist/src/core/index.d.ts +71 -85
- package/dist/src/core/index.js +143 -127
- package/dist/src/core/index.js.map +1 -1
- package/package.json +14 -11
|
@@ -118,7 +118,7 @@ export declare function arrayOf(elementGuard: (value: unknown) => boolean): Guar
|
|
|
118
118
|
*/
|
|
119
119
|
export declare interface ArrayRead<T = unknown> {
|
|
120
120
|
/** Frozen native entries in index order, retaining sparse positions as holes. */
|
|
121
|
-
readonly entries:
|
|
121
|
+
readonly entries: ReadonlyArray<T | undefined>;
|
|
122
122
|
/** Whether every index from zero through length minus one was reflected. */
|
|
123
123
|
readonly dense: boolean;
|
|
124
124
|
}
|
|
@@ -1070,6 +1070,18 @@ export declare interface ContainOptions {
|
|
|
1070
1070
|
readonly context?: ContractErrorContext;
|
|
1071
1071
|
}
|
|
1072
1072
|
|
|
1073
|
+
/**
|
|
1074
|
+
* The registry-global key used to recognize {@link ContractError} values across
|
|
1075
|
+
* package copies.
|
|
1076
|
+
*
|
|
1077
|
+
* @remarks
|
|
1078
|
+
* The descriptor stores the branded value itself. Recognition compares that
|
|
1079
|
+
* identity, so a transparent proxy cannot forward its target's brand as its
|
|
1080
|
+
* own. The registry makes the key discoverable; it is a recognition mechanism,
|
|
1081
|
+
* not an unforgeable provenance marker.
|
|
1082
|
+
*/
|
|
1083
|
+
export declare const CONTRACT_ERROR_BRAND: unique symbol;
|
|
1084
|
+
|
|
1073
1085
|
/** Machine-readable category carried by a {@link ContractError}. */
|
|
1074
1086
|
export declare type ContractCode =
|
|
1075
1087
|
/** Identifies a bound contract error. */
|
|
@@ -1241,7 +1253,6 @@ export declare interface ContractCompilerInterface<S extends ContractShape> {
|
|
|
1241
1253
|
* ```
|
|
1242
1254
|
*/
|
|
1243
1255
|
export declare class ContractError extends Error {
|
|
1244
|
-
#private;
|
|
1245
1256
|
readonly name = "ContractError";
|
|
1246
1257
|
readonly code: ContractCode;
|
|
1247
1258
|
readonly context: ContractErrorContext | undefined;
|
|
@@ -1252,52 +1263,6 @@ export declare class ContractError extends Error {
|
|
|
1252
1263
|
* @param options - Machine-readable category, optional context, and optional cause
|
|
1253
1264
|
*/
|
|
1254
1265
|
constructor(message: string, options: ContractErrorOptions);
|
|
1255
|
-
/**
|
|
1256
|
-
* Hand the module the branded recognition test.
|
|
1257
|
-
*
|
|
1258
|
-
* @remarks
|
|
1259
|
-
* The bootstrap seam, and deliberately NOT a spelling of the recognition
|
|
1260
|
-
* question. Private-name membership is legal only inside this class body, so
|
|
1261
|
-
* something must bridge the class to the module — and the previous bridge was
|
|
1262
|
-
* a static that ANSWERED the question, `ContractError.owns(value)`. That
|
|
1263
|
-
* reintroduced, verbatim, the poisonable surface the private brand was chosen
|
|
1264
|
-
* to remove: one assignment made the package fail to recognize its own errors,
|
|
1265
|
-
* so an engine rewrapped an error it had authored as an unreadable failure,
|
|
1266
|
-
* and a throwing assignment put the caller's raw value through fifteen public
|
|
1267
|
-
* doors.
|
|
1268
|
-
*
|
|
1269
|
-
* This hands over the CLOSURE instead: {@link isContractError} calls it and
|
|
1270
|
-
* applies the result, so the only member on the recognition path hands the
|
|
1271
|
-
* test over rather than answering with it. That per-call read is not a seam,
|
|
1272
|
-
* because the static block below pins this member as a non-writable,
|
|
1273
|
-
* non-configurable own data property.
|
|
1274
|
-
*
|
|
1275
|
-
* An earlier round argued the pin needed no further defence, because a static
|
|
1276
|
-
* block runs during class definition and no order — this module's, an
|
|
1277
|
-
* importer's, or a module that evaluated first — reaches `ContractError.guard`
|
|
1278
|
-
* before the block runs. That is true and it answers the wrong question.
|
|
1279
|
-
* INSTALLING IS NOT READING. The concern was never that something reads the
|
|
1280
|
-
* member unpinned; it was whether the pin installs at all, and the pin is one
|
|
1281
|
-
* live dispatch through `Object.defineProperty`. A module that evaluated
|
|
1282
|
-
* first can replace it with a selective no-op, after which the block runs,
|
|
1283
|
-
* returns, installs nothing, and every later read finds a writable member
|
|
1284
|
-
* again — the whole `owns` defect restored, invisibly, in a realm where every
|
|
1285
|
-
* shipped test still passes.
|
|
1286
|
-
*
|
|
1287
|
-
* So the block VERIFIES its own work and refuses to define the class when the
|
|
1288
|
-
* pin did not take. A silent failure becomes a loud one at import. The
|
|
1289
|
-
* residual is named rather than denied: an adversary who also answers the
|
|
1290
|
-
* verifying descriptor read defeats it, and that adversary already chose what
|
|
1291
|
-
* every capture in this package holds.
|
|
1292
|
-
*
|
|
1293
|
-
* @returns The total recognition guard `isContractError` publishes
|
|
1294
|
-
*
|
|
1295
|
-
* @example
|
|
1296
|
-
* ```ts
|
|
1297
|
-
* ContractError.guard()(new ContractError('x', { code: 'clone' })) // true
|
|
1298
|
-
* ```
|
|
1299
|
-
*/
|
|
1300
|
-
static guard(): Guard<ContractError>;
|
|
1301
1266
|
}
|
|
1302
1267
|
|
|
1303
1268
|
/** Optional structured details carried by a {@link ContractError}. */
|
|
@@ -1890,10 +1855,10 @@ export declare function holds(callback: () => boolean): boolean;
|
|
|
1890
1855
|
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 {
|
|
1891
1856
|
readonly type: 'literal';
|
|
1892
1857
|
readonly values: infer V;
|
|
1893
|
-
} ? V extends
|
|
1858
|
+
} ? V extends ReadonlyArray<infer L> ? L : never : S extends {
|
|
1894
1859
|
readonly type: 'array';
|
|
1895
1860
|
readonly items: infer I;
|
|
1896
|
-
} ? I extends ContractShape ?
|
|
1861
|
+
} ? I extends ContractShape ? ReadonlyArray<Infer<I>> : never : S extends ObjectShape<infer P, infer A> ? P extends Readonly<Record<string, ContractShape>> ? [A] extends [boolean | ContractShape] ? InferObject<P, A> : never : never : S extends {
|
|
1897
1862
|
readonly type: 'union';
|
|
1898
1863
|
readonly variants: infer V;
|
|
1899
1864
|
} ? V extends readonly ContractShape[] ? InferUnion<V> : never : S extends {
|
|
@@ -2211,7 +2176,7 @@ export declare function inferPrimitiveEnum(values: readonly unknown[], limit: nu
|
|
|
2211
2176
|
* // required: ['id'], additionalProperties: false }
|
|
2212
2177
|
* ```
|
|
2213
2178
|
*/
|
|
2214
|
-
export declare function inferRecordSamples(samples:
|
|
2179
|
+
export declare function inferRecordSamples(samples: ReadonlyArray<Record<string, unknown>>, depth: number, breadth: number, closed: boolean, format: boolean, enumOn: boolean, memo: SampleMemo): JSONSchema;
|
|
2215
2180
|
|
|
2216
2181
|
/**
|
|
2217
2182
|
* Infer a `JSONSchema` for a collected slot of sample values — the shared
|
|
@@ -2252,7 +2217,7 @@ export declare function inferRecordSamples(samples: readonly Record<string, unkn
|
|
|
2252
2217
|
export declare function inferSamples(samples: readonly unknown[], depth: number, breadth: number, closed: boolean, format: boolean, enumOn: boolean, memo: SampleMemo): JSONSchema;
|
|
2253
2218
|
|
|
2254
2219
|
/** {@link Infer} of a union shape's `variants` — the union of each variant's inferred type. */
|
|
2255
|
-
export declare type InferUnion<V extends readonly ContractShape[]> = V extends
|
|
2220
|
+
export declare type InferUnion<V extends readonly ContractShape[]> = V extends ReadonlyArray<infer U> ? (U extends ContractShape ? Infer<U> : never) : never;
|
|
2256
2221
|
|
|
2257
2222
|
/**
|
|
2258
2223
|
* Infer a `JSONSchema` fragment for one runtime value — the recursive spine
|
|
@@ -2735,36 +2700,21 @@ export declare function isBoundedJSONValue(value: unknown): value is JSONValue;
|
|
|
2735
2700
|
export declare function isConstructor(value: unknown): value is AnyConstructor<object>;
|
|
2736
2701
|
|
|
2737
2702
|
/**
|
|
2738
|
-
*
|
|
2703
|
+
* Checks whether an unknown value is a {@link ContractError}.
|
|
2739
2704
|
*
|
|
2740
2705
|
* @remarks
|
|
2741
|
-
*
|
|
2742
|
-
*
|
|
2743
|
-
*
|
|
2744
|
-
*
|
|
2745
|
-
*
|
|
2746
|
-
*
|
|
2747
|
-
*
|
|
2748
|
-
*
|
|
2749
|
-
*
|
|
2750
|
-
* The retrieved form was tried and was wrong twice over: a module-scope binding
|
|
2751
|
-
* bound to a computed value is module DATA, which belongs in a data kind file
|
|
2752
|
-
* and not in the file that owns the error classes and their guards; and the
|
|
2753
|
-
* single read it bought guarded a window that does not exist, since the pin is
|
|
2754
|
-
* installed during class definition and no code can observe this member before
|
|
2755
|
-
* it. Reading a permanently pinned own data property per call buys the caller
|
|
2756
|
-
* nothing, so the guard is spelled as what it is.
|
|
2757
|
-
*
|
|
2758
|
-
* Recognition is realm-local and identity-based: a value from another copy of
|
|
2759
|
-
* this module is not this class's error, exactly as `instanceof` reported; a
|
|
2760
|
-
* `Proxy` over a genuine error is refused, because a proxy holds no private
|
|
2761
|
-
* field of its target; and `Reflect.construct(ContractError, args, Foreign)` IS
|
|
2762
|
-
* recognized, because that construction genuinely ran this constructor and only
|
|
2763
|
-
* the prototype was the caller's choice. That last consequence is a widening
|
|
2764
|
-
* rather than a narrowing, and it is named rather than left to be discovered.
|
|
2706
|
+
* Recognition combines a global own-property brand with the native `Error`
|
|
2707
|
+
* base, a subclass prototype, the fixed name, and a declared contract code.
|
|
2708
|
+
* The brand stores the error itself and recognition requires that exact
|
|
2709
|
+
* identity. A transparent proxy is therefore refused because its forwarded
|
|
2710
|
+
* descriptor still stores the target, not the proxy.
|
|
2711
|
+
* The brand is recognized across duplicate installations and ESM/CommonJS
|
|
2712
|
+
* module copies at 0.0.13 or later. A copy earlier than 0.0.13 stamps no brand,
|
|
2713
|
+
* so an error it throws stays outside the type, and so does a plain or
|
|
2714
|
+
* property-only lookalike.
|
|
2765
2715
|
*
|
|
2766
2716
|
* @param value - The value to inspect
|
|
2767
|
-
* @returns
|
|
2717
|
+
* @returns True only for a `ContractError` instance; false otherwise
|
|
2768
2718
|
*
|
|
2769
2719
|
* @example
|
|
2770
2720
|
* ```ts
|
|
@@ -3796,9 +3746,9 @@ export declare function limitEntries<T>(entries: readonly T[], limit: number): r
|
|
|
3796
3746
|
* const isSameRole = literalOf(['admin', 'member', 'guest']) // the same guard, from an array
|
|
3797
3747
|
* ```
|
|
3798
3748
|
*/
|
|
3799
|
-
export declare function literalOf<const Literals extends
|
|
3749
|
+
export declare function literalOf<const Literals extends readonly LiteralValue[]>(literals: Literals): Guard<Literals[number]>;
|
|
3800
3750
|
|
|
3801
|
-
export declare function literalOf<const Literals extends
|
|
3751
|
+
export declare function literalOf<const Literals extends readonly LiteralValue[]>(...literals: Literals): Guard<Literals[number]>;
|
|
3802
3752
|
|
|
3803
3753
|
/** A literal shape — accepts exactly one of a fixed set of primitive values. */
|
|
3804
3754
|
export declare interface LiteralShape<T extends readonly LiteralValue[] = readonly LiteralValue[]> {
|
|
@@ -3931,7 +3881,7 @@ export declare function matchesJSONValue(entry: unknown, ancestors: WeakSet<obje
|
|
|
3931
3881
|
* matchesMember(collectMembers([Number.NaN]), Number.NaN) // true — SameValueZero
|
|
3932
3882
|
* ```
|
|
3933
3883
|
*/
|
|
3934
|
-
export declare function matchesMember(members:
|
|
3884
|
+
export declare function matchesMember(members: ReadonlySet<unknown>, value: unknown): boolean;
|
|
3935
3885
|
|
|
3936
3886
|
/**
|
|
3937
3887
|
* Determine whether a string is in the language of a pattern this package owns.
|
|
@@ -4170,6 +4120,14 @@ export declare interface NumberShapeOptions {
|
|
|
4170
4120
|
readonly description?: string;
|
|
4171
4121
|
}
|
|
4172
4122
|
|
|
4123
|
+
export declare function objectOf<S extends GuardsShape>(shape: S): Guard<FromGuards<S>>;
|
|
4124
|
+
|
|
4125
|
+
export declare function objectOf<S extends GuardsShape, K extends ReadonlyArray<keyof S & string>>(shape: S, optional: K): Guard<OptionalFromGuards<S, K>>;
|
|
4126
|
+
|
|
4127
|
+
export declare function objectOf<S extends GuardsShape>(shape: S, optional: true): Guard<Readonly<{
|
|
4128
|
+
[P in keyof S]?: FromGuards<S>[P];
|
|
4129
|
+
}>>;
|
|
4130
|
+
|
|
4173
4131
|
/**
|
|
4174
4132
|
* An object shape — a map of property names to child shapes.
|
|
4175
4133
|
*
|
|
@@ -4740,7 +4698,7 @@ export declare function parseStringField(record: Record<string, unknown>, path:
|
|
|
4740
4698
|
* pathOf(path) // an owned copy
|
|
4741
4699
|
* ```
|
|
4742
4700
|
*/
|
|
4743
|
-
export declare function pathOf(path: readonly string[], ...segments:
|
|
4701
|
+
export declare function pathOf(path: readonly string[], ...segments: ReadonlyArray<string | undefined>): readonly string[];
|
|
4744
4702
|
|
|
4745
4703
|
/**
|
|
4746
4704
|
* Build a new guard shape by keeping only the listed keys — the structural
|
|
@@ -4916,6 +4874,34 @@ export declare function rawShape(schema: JSONSchema): RawShape;
|
|
|
4916
4874
|
*/
|
|
4917
4875
|
export declare function readArrayEntries<T>(value: readonly T[]): Result<ArrayRead<T>>;
|
|
4918
4876
|
|
|
4877
|
+
/**
|
|
4878
|
+
* Snapshot a guard shape and its optional-key mode for a shape combinator.
|
|
4879
|
+
*
|
|
4880
|
+
* @remarks
|
|
4881
|
+
* A null-prototype record plus its own key list is used instead of a `Map`.
|
|
4882
|
+
* The declared-key population decides the guard's answer, and
|
|
4883
|
+
* `Map.prototype.has`, `Map.prototype.get`, and map iteration are three
|
|
4884
|
+
* caller-writable members on that path. An own data key read by index
|
|
4885
|
+
* dispatches through nothing.
|
|
4886
|
+
*
|
|
4887
|
+
* @param shape - The guard shape whose own string declarations to snapshot
|
|
4888
|
+
* @param optional - The optional-key list, `true` for every key, or `undefined`
|
|
4889
|
+
* @param reader - The public combinator name used in read refusals
|
|
4890
|
+
* @returns The owned guards and names plus the collected optional-key membership
|
|
4891
|
+
* @throws {ContractError} When the shape or optional-key list cannot be read
|
|
4892
|
+
*
|
|
4893
|
+
* @example
|
|
4894
|
+
* ```ts
|
|
4895
|
+
* readGuardShape({ id: isString }, undefined, 'recordOf')
|
|
4896
|
+
* ```
|
|
4897
|
+
*/
|
|
4898
|
+
export declare function readGuardShape(shape: GuardsShape, optional: readonly string[] | true | undefined, reader: string): Readonly<{
|
|
4899
|
+
readonly guards: Readonly<Record<string, Guard<unknown> | undefined>>;
|
|
4900
|
+
readonly names: readonly string[];
|
|
4901
|
+
readonly optional: ReadonlySet<unknown>;
|
|
4902
|
+
readonly vocabulary: ReadonlySet<unknown>;
|
|
4903
|
+
}>;
|
|
4904
|
+
|
|
4919
4905
|
/**
|
|
4920
4906
|
* Snapshot the genuine entries of a caller's `Map` without running an iterator.
|
|
4921
4907
|
*
|
|
@@ -4935,7 +4921,7 @@ export declare function readArrayEntries<T>(value: readonly T[]): Result<ArrayRe
|
|
|
4935
4921
|
* readMapEntries(new Map([['a', 1]])) // { success: true, value: [['a', 1]] }
|
|
4936
4922
|
* ```
|
|
4937
4923
|
*/
|
|
4938
|
-
export declare function readMapEntries(value: ReadonlyMap<unknown, unknown>): Result<readonly
|
|
4924
|
+
export declare function readMapEntries(value: ReadonlyMap<unknown, unknown>): Result<ReadonlyArray<readonly unknown[]>>;
|
|
4939
4925
|
|
|
4940
4926
|
/**
|
|
4941
4927
|
* Validate and snapshot a shape-builder options record through every reflective
|
|
@@ -4963,7 +4949,7 @@ export declare function readMapEntries(value: ReadonlyMap<unknown, unknown>): Re
|
|
|
4963
4949
|
* const options = readOptions(source, ['min', 'max'], 'numberShape', 'number')
|
|
4964
4950
|
* ```
|
|
4965
4951
|
*/
|
|
4966
|
-
export declare function readOptions<T extends object>(source: T | undefined, keys:
|
|
4952
|
+
export declare function readOptions<T extends object>(source: T | undefined, keys: ReadonlyArray<keyof T & string>, builder: string, shape: string): T | undefined;
|
|
4967
4953
|
|
|
4968
4954
|
/**
|
|
4969
4955
|
* Rebuild a caller's regular expression as a stateless pattern this package
|
|
@@ -5685,7 +5671,7 @@ export declare type SeederFunction<T> = (random?: RandomFunction) => T;
|
|
|
5685
5671
|
* selectClosestFaults([]) // []
|
|
5686
5672
|
* ```
|
|
5687
5673
|
*/
|
|
5688
|
-
export declare function selectClosestFaults<T extends AuditFault>(reports: readonly
|
|
5674
|
+
export declare function selectClosestFaults<T extends AuditFault>(reports: ReadonlyArray<readonly T[]>): readonly T[];
|
|
5689
5675
|
|
|
5690
5676
|
/**
|
|
5691
5677
|
* Build a guard that accepts `Set` instances whose every element satisfies
|
package/dist/src/core/index.d.ts
CHANGED
|
@@ -118,7 +118,7 @@ export declare function arrayOf(elementGuard: (value: unknown) => boolean): Guar
|
|
|
118
118
|
*/
|
|
119
119
|
export declare interface ArrayRead<T = unknown> {
|
|
120
120
|
/** Frozen native entries in index order, retaining sparse positions as holes. */
|
|
121
|
-
readonly entries:
|
|
121
|
+
readonly entries: ReadonlyArray<T | undefined>;
|
|
122
122
|
/** Whether every index from zero through length minus one was reflected. */
|
|
123
123
|
readonly dense: boolean;
|
|
124
124
|
}
|
|
@@ -1070,6 +1070,18 @@ export declare interface ContainOptions {
|
|
|
1070
1070
|
readonly context?: ContractErrorContext;
|
|
1071
1071
|
}
|
|
1072
1072
|
|
|
1073
|
+
/**
|
|
1074
|
+
* The registry-global key used to recognize {@link ContractError} values across
|
|
1075
|
+
* package copies.
|
|
1076
|
+
*
|
|
1077
|
+
* @remarks
|
|
1078
|
+
* The descriptor stores the branded value itself. Recognition compares that
|
|
1079
|
+
* identity, so a transparent proxy cannot forward its target's brand as its
|
|
1080
|
+
* own. The registry makes the key discoverable; it is a recognition mechanism,
|
|
1081
|
+
* not an unforgeable provenance marker.
|
|
1082
|
+
*/
|
|
1083
|
+
export declare const CONTRACT_ERROR_BRAND: unique symbol;
|
|
1084
|
+
|
|
1073
1085
|
/** Machine-readable category carried by a {@link ContractError}. */
|
|
1074
1086
|
export declare type ContractCode =
|
|
1075
1087
|
/** Identifies a bound contract error. */
|
|
@@ -1241,7 +1253,6 @@ export declare interface ContractCompilerInterface<S extends ContractShape> {
|
|
|
1241
1253
|
* ```
|
|
1242
1254
|
*/
|
|
1243
1255
|
export declare class ContractError extends Error {
|
|
1244
|
-
#private;
|
|
1245
1256
|
readonly name = "ContractError";
|
|
1246
1257
|
readonly code: ContractCode;
|
|
1247
1258
|
readonly context: ContractErrorContext | undefined;
|
|
@@ -1252,52 +1263,6 @@ export declare class ContractError extends Error {
|
|
|
1252
1263
|
* @param options - Machine-readable category, optional context, and optional cause
|
|
1253
1264
|
*/
|
|
1254
1265
|
constructor(message: string, options: ContractErrorOptions);
|
|
1255
|
-
/**
|
|
1256
|
-
* Hand the module the branded recognition test.
|
|
1257
|
-
*
|
|
1258
|
-
* @remarks
|
|
1259
|
-
* The bootstrap seam, and deliberately NOT a spelling of the recognition
|
|
1260
|
-
* question. Private-name membership is legal only inside this class body, so
|
|
1261
|
-
* something must bridge the class to the module — and the previous bridge was
|
|
1262
|
-
* a static that ANSWERED the question, `ContractError.owns(value)`. That
|
|
1263
|
-
* reintroduced, verbatim, the poisonable surface the private brand was chosen
|
|
1264
|
-
* to remove: one assignment made the package fail to recognize its own errors,
|
|
1265
|
-
* so an engine rewrapped an error it had authored as an unreadable failure,
|
|
1266
|
-
* and a throwing assignment put the caller's raw value through fifteen public
|
|
1267
|
-
* doors.
|
|
1268
|
-
*
|
|
1269
|
-
* This hands over the CLOSURE instead: {@link isContractError} calls it and
|
|
1270
|
-
* applies the result, so the only member on the recognition path hands the
|
|
1271
|
-
* test over rather than answering with it. That per-call read is not a seam,
|
|
1272
|
-
* because the static block below pins this member as a non-writable,
|
|
1273
|
-
* non-configurable own data property.
|
|
1274
|
-
*
|
|
1275
|
-
* An earlier round argued the pin needed no further defence, because a static
|
|
1276
|
-
* block runs during class definition and no order — this module's, an
|
|
1277
|
-
* importer's, or a module that evaluated first — reaches `ContractError.guard`
|
|
1278
|
-
* before the block runs. That is true and it answers the wrong question.
|
|
1279
|
-
* INSTALLING IS NOT READING. The concern was never that something reads the
|
|
1280
|
-
* member unpinned; it was whether the pin installs at all, and the pin is one
|
|
1281
|
-
* live dispatch through `Object.defineProperty`. A module that evaluated
|
|
1282
|
-
* first can replace it with a selective no-op, after which the block runs,
|
|
1283
|
-
* returns, installs nothing, and every later read finds a writable member
|
|
1284
|
-
* again — the whole `owns` defect restored, invisibly, in a realm where every
|
|
1285
|
-
* shipped test still passes.
|
|
1286
|
-
*
|
|
1287
|
-
* So the block VERIFIES its own work and refuses to define the class when the
|
|
1288
|
-
* pin did not take. A silent failure becomes a loud one at import. The
|
|
1289
|
-
* residual is named rather than denied: an adversary who also answers the
|
|
1290
|
-
* verifying descriptor read defeats it, and that adversary already chose what
|
|
1291
|
-
* every capture in this package holds.
|
|
1292
|
-
*
|
|
1293
|
-
* @returns The total recognition guard `isContractError` publishes
|
|
1294
|
-
*
|
|
1295
|
-
* @example
|
|
1296
|
-
* ```ts
|
|
1297
|
-
* ContractError.guard()(new ContractError('x', { code: 'clone' })) // true
|
|
1298
|
-
* ```
|
|
1299
|
-
*/
|
|
1300
|
-
static guard(): Guard<ContractError>;
|
|
1301
1266
|
}
|
|
1302
1267
|
|
|
1303
1268
|
/** Optional structured details carried by a {@link ContractError}. */
|
|
@@ -1890,10 +1855,10 @@ export declare function holds(callback: () => boolean): boolean;
|
|
|
1890
1855
|
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 {
|
|
1891
1856
|
readonly type: 'literal';
|
|
1892
1857
|
readonly values: infer V;
|
|
1893
|
-
} ? V extends
|
|
1858
|
+
} ? V extends ReadonlyArray<infer L> ? L : never : S extends {
|
|
1894
1859
|
readonly type: 'array';
|
|
1895
1860
|
readonly items: infer I;
|
|
1896
|
-
} ? I extends ContractShape ?
|
|
1861
|
+
} ? I extends ContractShape ? ReadonlyArray<Infer<I>> : never : S extends ObjectShape<infer P, infer A> ? P extends Readonly<Record<string, ContractShape>> ? [A] extends [boolean | ContractShape] ? InferObject<P, A> : never : never : S extends {
|
|
1897
1862
|
readonly type: 'union';
|
|
1898
1863
|
readonly variants: infer V;
|
|
1899
1864
|
} ? V extends readonly ContractShape[] ? InferUnion<V> : never : S extends {
|
|
@@ -2211,7 +2176,7 @@ export declare function inferPrimitiveEnum(values: readonly unknown[], limit: nu
|
|
|
2211
2176
|
* // required: ['id'], additionalProperties: false }
|
|
2212
2177
|
* ```
|
|
2213
2178
|
*/
|
|
2214
|
-
export declare function inferRecordSamples(samples:
|
|
2179
|
+
export declare function inferRecordSamples(samples: ReadonlyArray<Record<string, unknown>>, depth: number, breadth: number, closed: boolean, format: boolean, enumOn: boolean, memo: SampleMemo): JSONSchema;
|
|
2215
2180
|
|
|
2216
2181
|
/**
|
|
2217
2182
|
* Infer a `JSONSchema` for a collected slot of sample values — the shared
|
|
@@ -2252,7 +2217,7 @@ export declare function inferRecordSamples(samples: readonly Record<string, unkn
|
|
|
2252
2217
|
export declare function inferSamples(samples: readonly unknown[], depth: number, breadth: number, closed: boolean, format: boolean, enumOn: boolean, memo: SampleMemo): JSONSchema;
|
|
2253
2218
|
|
|
2254
2219
|
/** {@link Infer} of a union shape's `variants` — the union of each variant's inferred type. */
|
|
2255
|
-
export declare type InferUnion<V extends readonly ContractShape[]> = V extends
|
|
2220
|
+
export declare type InferUnion<V extends readonly ContractShape[]> = V extends ReadonlyArray<infer U> ? (U extends ContractShape ? Infer<U> : never) : never;
|
|
2256
2221
|
|
|
2257
2222
|
/**
|
|
2258
2223
|
* Infer a `JSONSchema` fragment for one runtime value — the recursive spine
|
|
@@ -2735,36 +2700,21 @@ export declare function isBoundedJSONValue(value: unknown): value is JSONValue;
|
|
|
2735
2700
|
export declare function isConstructor(value: unknown): value is AnyConstructor<object>;
|
|
2736
2701
|
|
|
2737
2702
|
/**
|
|
2738
|
-
*
|
|
2703
|
+
* Checks whether an unknown value is a {@link ContractError}.
|
|
2739
2704
|
*
|
|
2740
2705
|
* @remarks
|
|
2741
|
-
*
|
|
2742
|
-
*
|
|
2743
|
-
*
|
|
2744
|
-
*
|
|
2745
|
-
*
|
|
2746
|
-
*
|
|
2747
|
-
*
|
|
2748
|
-
*
|
|
2749
|
-
*
|
|
2750
|
-
* The retrieved form was tried and was wrong twice over: a module-scope binding
|
|
2751
|
-
* bound to a computed value is module DATA, which belongs in a data kind file
|
|
2752
|
-
* and not in the file that owns the error classes and their guards; and the
|
|
2753
|
-
* single read it bought guarded a window that does not exist, since the pin is
|
|
2754
|
-
* installed during class definition and no code can observe this member before
|
|
2755
|
-
* it. Reading a permanently pinned own data property per call buys the caller
|
|
2756
|
-
* nothing, so the guard is spelled as what it is.
|
|
2757
|
-
*
|
|
2758
|
-
* Recognition is realm-local and identity-based: a value from another copy of
|
|
2759
|
-
* this module is not this class's error, exactly as `instanceof` reported; a
|
|
2760
|
-
* `Proxy` over a genuine error is refused, because a proxy holds no private
|
|
2761
|
-
* field of its target; and `Reflect.construct(ContractError, args, Foreign)` IS
|
|
2762
|
-
* recognized, because that construction genuinely ran this constructor and only
|
|
2763
|
-
* the prototype was the caller's choice. That last consequence is a widening
|
|
2764
|
-
* rather than a narrowing, and it is named rather than left to be discovered.
|
|
2706
|
+
* Recognition combines a global own-property brand with the native `Error`
|
|
2707
|
+
* base, a subclass prototype, the fixed name, and a declared contract code.
|
|
2708
|
+
* The brand stores the error itself and recognition requires that exact
|
|
2709
|
+
* identity. A transparent proxy is therefore refused because its forwarded
|
|
2710
|
+
* descriptor still stores the target, not the proxy.
|
|
2711
|
+
* The brand is recognized across duplicate installations and ESM/CommonJS
|
|
2712
|
+
* module copies at 0.0.13 or later. A copy earlier than 0.0.13 stamps no brand,
|
|
2713
|
+
* so an error it throws stays outside the type, and so does a plain or
|
|
2714
|
+
* property-only lookalike.
|
|
2765
2715
|
*
|
|
2766
2716
|
* @param value - The value to inspect
|
|
2767
|
-
* @returns
|
|
2717
|
+
* @returns True only for a `ContractError` instance; false otherwise
|
|
2768
2718
|
*
|
|
2769
2719
|
* @example
|
|
2770
2720
|
* ```ts
|
|
@@ -3796,9 +3746,9 @@ export declare function limitEntries<T>(entries: readonly T[], limit: number): r
|
|
|
3796
3746
|
* const isSameRole = literalOf(['admin', 'member', 'guest']) // the same guard, from an array
|
|
3797
3747
|
* ```
|
|
3798
3748
|
*/
|
|
3799
|
-
export declare function literalOf<const Literals extends
|
|
3749
|
+
export declare function literalOf<const Literals extends readonly LiteralValue[]>(literals: Literals): Guard<Literals[number]>;
|
|
3800
3750
|
|
|
3801
|
-
export declare function literalOf<const Literals extends
|
|
3751
|
+
export declare function literalOf<const Literals extends readonly LiteralValue[]>(...literals: Literals): Guard<Literals[number]>;
|
|
3802
3752
|
|
|
3803
3753
|
/** A literal shape — accepts exactly one of a fixed set of primitive values. */
|
|
3804
3754
|
export declare interface LiteralShape<T extends readonly LiteralValue[] = readonly LiteralValue[]> {
|
|
@@ -3931,7 +3881,7 @@ export declare function matchesJSONValue(entry: unknown, ancestors: WeakSet<obje
|
|
|
3931
3881
|
* matchesMember(collectMembers([Number.NaN]), Number.NaN) // true — SameValueZero
|
|
3932
3882
|
* ```
|
|
3933
3883
|
*/
|
|
3934
|
-
export declare function matchesMember(members:
|
|
3884
|
+
export declare function matchesMember(members: ReadonlySet<unknown>, value: unknown): boolean;
|
|
3935
3885
|
|
|
3936
3886
|
/**
|
|
3937
3887
|
* Determine whether a string is in the language of a pattern this package owns.
|
|
@@ -4170,6 +4120,14 @@ export declare interface NumberShapeOptions {
|
|
|
4170
4120
|
readonly description?: string;
|
|
4171
4121
|
}
|
|
4172
4122
|
|
|
4123
|
+
export declare function objectOf<S extends GuardsShape>(shape: S): Guard<FromGuards<S>>;
|
|
4124
|
+
|
|
4125
|
+
export declare function objectOf<S extends GuardsShape, K extends ReadonlyArray<keyof S & string>>(shape: S, optional: K): Guard<OptionalFromGuards<S, K>>;
|
|
4126
|
+
|
|
4127
|
+
export declare function objectOf<S extends GuardsShape>(shape: S, optional: true): Guard<Readonly<{
|
|
4128
|
+
[P in keyof S]?: FromGuards<S>[P];
|
|
4129
|
+
}>>;
|
|
4130
|
+
|
|
4173
4131
|
/**
|
|
4174
4132
|
* An object shape — a map of property names to child shapes.
|
|
4175
4133
|
*
|
|
@@ -4740,7 +4698,7 @@ export declare function parseStringField(record: Record<string, unknown>, path:
|
|
|
4740
4698
|
* pathOf(path) // an owned copy
|
|
4741
4699
|
* ```
|
|
4742
4700
|
*/
|
|
4743
|
-
export declare function pathOf(path: readonly string[], ...segments:
|
|
4701
|
+
export declare function pathOf(path: readonly string[], ...segments: ReadonlyArray<string | undefined>): readonly string[];
|
|
4744
4702
|
|
|
4745
4703
|
/**
|
|
4746
4704
|
* Build a new guard shape by keeping only the listed keys — the structural
|
|
@@ -4916,6 +4874,34 @@ export declare function rawShape(schema: JSONSchema): RawShape;
|
|
|
4916
4874
|
*/
|
|
4917
4875
|
export declare function readArrayEntries<T>(value: readonly T[]): Result<ArrayRead<T>>;
|
|
4918
4876
|
|
|
4877
|
+
/**
|
|
4878
|
+
* Snapshot a guard shape and its optional-key mode for a shape combinator.
|
|
4879
|
+
*
|
|
4880
|
+
* @remarks
|
|
4881
|
+
* A null-prototype record plus its own key list is used instead of a `Map`.
|
|
4882
|
+
* The declared-key population decides the guard's answer, and
|
|
4883
|
+
* `Map.prototype.has`, `Map.prototype.get`, and map iteration are three
|
|
4884
|
+
* caller-writable members on that path. An own data key read by index
|
|
4885
|
+
* dispatches through nothing.
|
|
4886
|
+
*
|
|
4887
|
+
* @param shape - The guard shape whose own string declarations to snapshot
|
|
4888
|
+
* @param optional - The optional-key list, `true` for every key, or `undefined`
|
|
4889
|
+
* @param reader - The public combinator name used in read refusals
|
|
4890
|
+
* @returns The owned guards and names plus the collected optional-key membership
|
|
4891
|
+
* @throws {ContractError} When the shape or optional-key list cannot be read
|
|
4892
|
+
*
|
|
4893
|
+
* @example
|
|
4894
|
+
* ```ts
|
|
4895
|
+
* readGuardShape({ id: isString }, undefined, 'recordOf')
|
|
4896
|
+
* ```
|
|
4897
|
+
*/
|
|
4898
|
+
export declare function readGuardShape(shape: GuardsShape, optional: readonly string[] | true | undefined, reader: string): Readonly<{
|
|
4899
|
+
readonly guards: Readonly<Record<string, Guard<unknown> | undefined>>;
|
|
4900
|
+
readonly names: readonly string[];
|
|
4901
|
+
readonly optional: ReadonlySet<unknown>;
|
|
4902
|
+
readonly vocabulary: ReadonlySet<unknown>;
|
|
4903
|
+
}>;
|
|
4904
|
+
|
|
4919
4905
|
/**
|
|
4920
4906
|
* Snapshot the genuine entries of a caller's `Map` without running an iterator.
|
|
4921
4907
|
*
|
|
@@ -4935,7 +4921,7 @@ export declare function readArrayEntries<T>(value: readonly T[]): Result<ArrayRe
|
|
|
4935
4921
|
* readMapEntries(new Map([['a', 1]])) // { success: true, value: [['a', 1]] }
|
|
4936
4922
|
* ```
|
|
4937
4923
|
*/
|
|
4938
|
-
export declare function readMapEntries(value: ReadonlyMap<unknown, unknown>): Result<readonly
|
|
4924
|
+
export declare function readMapEntries(value: ReadonlyMap<unknown, unknown>): Result<ReadonlyArray<readonly unknown[]>>;
|
|
4939
4925
|
|
|
4940
4926
|
/**
|
|
4941
4927
|
* Validate and snapshot a shape-builder options record through every reflective
|
|
@@ -4963,7 +4949,7 @@ export declare function readMapEntries(value: ReadonlyMap<unknown, unknown>): Re
|
|
|
4963
4949
|
* const options = readOptions(source, ['min', 'max'], 'numberShape', 'number')
|
|
4964
4950
|
* ```
|
|
4965
4951
|
*/
|
|
4966
|
-
export declare function readOptions<T extends object>(source: T | undefined, keys:
|
|
4952
|
+
export declare function readOptions<T extends object>(source: T | undefined, keys: ReadonlyArray<keyof T & string>, builder: string, shape: string): T | undefined;
|
|
4967
4953
|
|
|
4968
4954
|
/**
|
|
4969
4955
|
* Rebuild a caller's regular expression as a stateless pattern this package
|
|
@@ -5685,7 +5671,7 @@ export declare type SeederFunction<T> = (random?: RandomFunction) => T;
|
|
|
5685
5671
|
* selectClosestFaults([]) // []
|
|
5686
5672
|
* ```
|
|
5687
5673
|
*/
|
|
5688
|
-
export declare function selectClosestFaults<T extends AuditFault>(reports: readonly
|
|
5674
|
+
export declare function selectClosestFaults<T extends AuditFault>(reports: ReadonlyArray<readonly T[]>): readonly T[];
|
|
5689
5675
|
|
|
5690
5676
|
/**
|
|
5691
5677
|
* Build a guard that accepts `Set` instances whose every element satisfies
|