@orkestrel/contract 0.0.12 → 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 +44 -98
- package/dist/src/core/index.cjs.map +1 -1
- package/dist/src/core/index.d.cts +23 -73
- package/dist/src/core/index.d.ts +23 -73
- package/dist/src/core/index.js +44 -99
- package/dist/src/core/index.js.map +1 -1
- package/package.json +11 -9
|
@@ -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}. */
|
|
@@ -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
|
package/dist/src/core/index.d.ts
CHANGED
|
@@ -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}. */
|
|
@@ -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
|
package/dist/src/core/index.js
CHANGED
|
@@ -1,5 +1,16 @@
|
|
|
1
1
|
//#region src/core/constants.ts
|
|
2
2
|
/**
|
|
3
|
+
* The registry-global key used to recognize {@link ContractError} values across
|
|
4
|
+
* package copies.
|
|
5
|
+
*
|
|
6
|
+
* @remarks
|
|
7
|
+
* The descriptor stores the branded value itself. Recognition compares that
|
|
8
|
+
* identity, so a transparent proxy cannot forward its target's brand as its
|
|
9
|
+
* own. The registry makes the key discoverable; it is a recognition mechanism,
|
|
10
|
+
* not an unforgeable provenance marker.
|
|
11
|
+
*/
|
|
12
|
+
var CONTRACT_ERROR_BRAND = Symbol.for("@orkestrel/contract.error");
|
|
13
|
+
/**
|
|
3
14
|
* Every host operation this package dispatches through, captured while this
|
|
4
15
|
* module evaluates.
|
|
5
16
|
*
|
|
@@ -446,11 +457,9 @@ var FORMAT_PATTERNS = Object.freeze({
|
|
|
446
457
|
* ```
|
|
447
458
|
*/
|
|
448
459
|
var ContractError = class ContractError extends Error {
|
|
449
|
-
static #hasOwn = Object.hasOwn;
|
|
450
460
|
name = "ContractError";
|
|
451
461
|
code;
|
|
452
462
|
context;
|
|
453
|
-
#brand = true;
|
|
454
463
|
/**
|
|
455
464
|
* Create a contract error.
|
|
456
465
|
*
|
|
@@ -458,117 +467,44 @@ var ContractError = class ContractError extends Error {
|
|
|
458
467
|
* @param options - Machine-readable category, optional context, and optional cause
|
|
459
468
|
*/
|
|
460
469
|
constructor(message, options) {
|
|
461
|
-
super(message,
|
|
470
|
+
super(message, INTRINSICS.own(options, "cause") ? { cause: options.cause } : void 0);
|
|
471
|
+
INTRINSICS.define(this, CONTRACT_ERROR_BRAND, {
|
|
472
|
+
value: this,
|
|
473
|
+
configurable: true
|
|
474
|
+
});
|
|
462
475
|
this.code = options.code;
|
|
463
|
-
this.context =
|
|
464
|
-
}
|
|
465
|
-
/**
|
|
466
|
-
* Hand the module the branded recognition test.
|
|
467
|
-
*
|
|
468
|
-
* @remarks
|
|
469
|
-
* The bootstrap seam, and deliberately NOT a spelling of the recognition
|
|
470
|
-
* question. Private-name membership is legal only inside this class body, so
|
|
471
|
-
* something must bridge the class to the module — and the previous bridge was
|
|
472
|
-
* a static that ANSWERED the question, `ContractError.owns(value)`. That
|
|
473
|
-
* reintroduced, verbatim, the poisonable surface the private brand was chosen
|
|
474
|
-
* to remove: one assignment made the package fail to recognize its own errors,
|
|
475
|
-
* so an engine rewrapped an error it had authored as an unreadable failure,
|
|
476
|
-
* and a throwing assignment put the caller's raw value through fifteen public
|
|
477
|
-
* doors.
|
|
478
|
-
*
|
|
479
|
-
* This hands over the CLOSURE instead: {@link isContractError} calls it and
|
|
480
|
-
* applies the result, so the only member on the recognition path hands the
|
|
481
|
-
* test over rather than answering with it. That per-call read is not a seam,
|
|
482
|
-
* because the static block below pins this member as a non-writable,
|
|
483
|
-
* non-configurable own data property.
|
|
484
|
-
*
|
|
485
|
-
* An earlier round argued the pin needed no further defence, because a static
|
|
486
|
-
* block runs during class definition and no order — this module's, an
|
|
487
|
-
* importer's, or a module that evaluated first — reaches `ContractError.guard`
|
|
488
|
-
* before the block runs. That is true and it answers the wrong question.
|
|
489
|
-
* INSTALLING IS NOT READING. The concern was never that something reads the
|
|
490
|
-
* member unpinned; it was whether the pin installs at all, and the pin is one
|
|
491
|
-
* live dispatch through `Object.defineProperty`. A module that evaluated
|
|
492
|
-
* first can replace it with a selective no-op, after which the block runs,
|
|
493
|
-
* returns, installs nothing, and every later read finds a writable member
|
|
494
|
-
* again — the whole `owns` defect restored, invisibly, in a realm where every
|
|
495
|
-
* shipped test still passes.
|
|
496
|
-
*
|
|
497
|
-
* So the block VERIFIES its own work and refuses to define the class when the
|
|
498
|
-
* pin did not take. A silent failure becomes a loud one at import. The
|
|
499
|
-
* residual is named rather than denied: an adversary who also answers the
|
|
500
|
-
* verifying descriptor read defeats it, and that adversary already chose what
|
|
501
|
-
* every capture in this package holds.
|
|
502
|
-
*
|
|
503
|
-
* @returns The total recognition guard `isContractError` publishes
|
|
504
|
-
*
|
|
505
|
-
* @example
|
|
506
|
-
* ```ts
|
|
507
|
-
* ContractError.guard()(new ContractError('x', { code: 'clone' })) // true
|
|
508
|
-
* ```
|
|
509
|
-
*/
|
|
510
|
-
static guard() {
|
|
511
|
-
return ContractError.#recognizes;
|
|
512
|
-
}
|
|
513
|
-
static #recognizes(value) {
|
|
514
|
-
if (typeof value !== "object" || value === null) return false;
|
|
515
|
-
try {
|
|
516
|
-
return #brand in value && value.#brand === true;
|
|
517
|
-
} catch {
|
|
518
|
-
return false;
|
|
519
|
-
}
|
|
476
|
+
this.context = INTRINSICS.own(options, "context") ? options.context : void 0;
|
|
520
477
|
}
|
|
521
478
|
static {
|
|
522
|
-
|
|
523
|
-
writable: false,
|
|
524
|
-
configurable: false
|
|
525
|
-
});
|
|
526
|
-
const guard = Object.getOwnPropertyDescriptor(this, "guard");
|
|
527
|
-
if (guard?.writable !== false || guard.configurable !== false) throw new ContractError("ContractError: the recognition pin could not be installed", { code: "structure" });
|
|
528
|
-
const members = Reflect.ownKeys(this.prototype);
|
|
479
|
+
const members = INTRINSICS.members(this.prototype);
|
|
529
480
|
for (let index = 0; index < members.length; index += 1) {
|
|
530
481
|
const key = members[index];
|
|
531
482
|
if (key === void 0) continue;
|
|
532
|
-
|
|
483
|
+
INTRINSICS.define(this.prototype, key, {
|
|
533
484
|
writable: false,
|
|
534
485
|
configurable: false
|
|
535
486
|
});
|
|
536
|
-
const pinned =
|
|
487
|
+
const pinned = INTRINSICS.describe(this.prototype, key);
|
|
537
488
|
if (pinned?.writable !== false || pinned.configurable !== false) throw new ContractError("ContractError: a prototype member could not be pinned", { code: "structure" });
|
|
538
489
|
}
|
|
539
490
|
}
|
|
540
491
|
};
|
|
541
492
|
/**
|
|
542
|
-
*
|
|
543
|
-
*
|
|
544
|
-
* @remarks
|
|
545
|
-
*
|
|
546
|
-
*
|
|
547
|
-
*
|
|
548
|
-
*
|
|
549
|
-
*
|
|
550
|
-
*
|
|
551
|
-
*
|
|
552
|
-
*
|
|
553
|
-
*
|
|
554
|
-
* The retrieved form was tried and was wrong twice over: a module-scope binding
|
|
555
|
-
* bound to a computed value is module DATA, which belongs in a data kind file
|
|
556
|
-
* and not in the file that owns the error classes and their guards; and the
|
|
557
|
-
* single read it bought guarded a window that does not exist, since the pin is
|
|
558
|
-
* installed during class definition and no code can observe this member before
|
|
559
|
-
* it. Reading a permanently pinned own data property per call buys the caller
|
|
560
|
-
* nothing, so the guard is spelled as what it is.
|
|
561
|
-
*
|
|
562
|
-
* Recognition is realm-local and identity-based: a value from another copy of
|
|
563
|
-
* this module is not this class's error, exactly as `instanceof` reported; a
|
|
564
|
-
* `Proxy` over a genuine error is refused, because a proxy holds no private
|
|
565
|
-
* field of its target; and `Reflect.construct(ContractError, args, Foreign)` IS
|
|
566
|
-
* recognized, because that construction genuinely ran this constructor and only
|
|
567
|
-
* the prototype was the caller's choice. That last consequence is a widening
|
|
568
|
-
* rather than a narrowing, and it is named rather than left to be discovered.
|
|
493
|
+
* Checks whether an unknown value is a {@link ContractError}.
|
|
494
|
+
*
|
|
495
|
+
* @remarks
|
|
496
|
+
* Recognition combines a global own-property brand with the native `Error`
|
|
497
|
+
* base, a subclass prototype, the fixed name, and a declared contract code.
|
|
498
|
+
* The brand stores the error itself and recognition requires that exact
|
|
499
|
+
* identity. A transparent proxy is therefore refused because its forwarded
|
|
500
|
+
* descriptor still stores the target, not the proxy.
|
|
501
|
+
* The brand is recognized across duplicate installations and ESM/CommonJS
|
|
502
|
+
* module copies at 0.0.13 or later. A copy earlier than 0.0.13 stamps no brand,
|
|
503
|
+
* so an error it throws stays outside the type, and so does a plain or
|
|
504
|
+
* property-only lookalike.
|
|
569
505
|
*
|
|
570
506
|
* @param value - The value to inspect
|
|
571
|
-
* @returns
|
|
507
|
+
* @returns True only for a `ContractError` instance; false otherwise
|
|
572
508
|
*
|
|
573
509
|
* @example
|
|
574
510
|
* ```ts
|
|
@@ -577,7 +513,16 @@ var ContractError = class ContractError extends Error {
|
|
|
577
513
|
* ```
|
|
578
514
|
*/
|
|
579
515
|
function isContractError(value) {
|
|
580
|
-
|
|
516
|
+
if (typeof value !== "object" || value === null) return false;
|
|
517
|
+
try {
|
|
518
|
+
if (!(value instanceof INTRINSICS.error) || INTRINSICS.prototype(value) === INTRINSICS.error.prototype) return false;
|
|
519
|
+
if (value.name !== "ContractError" || !("code" in value)) return false;
|
|
520
|
+
if (INTRINSICS.describe(value, CONTRACT_ERROR_BRAND)?.value !== value) return false;
|
|
521
|
+
const code = value.code;
|
|
522
|
+
return code === "bound" || code === "range" || code === "empty" || code === "placement" || code === "structure" || code === "literal" || code === "cycle" || code === "pattern" || code === "generate" || code === "random" || code === "clone" || code === "depth" || code === "expansion";
|
|
523
|
+
} catch {
|
|
524
|
+
return false;
|
|
525
|
+
}
|
|
581
526
|
}
|
|
582
527
|
//#endregion
|
|
583
528
|
//#region src/core/validators.ts
|
|
@@ -10412,6 +10357,6 @@ function schemaToShape(schema) {
|
|
|
10412
10357
|
}, "schemaToShape");
|
|
10413
10358
|
}
|
|
10414
10359
|
//#endregion
|
|
10415
|
-
export { CLONE_NODE_LIMIT, COMPILE_DEPTH_LIMIT, COMPILE_NODE_LIMIT, ContractCompiler, ContractError, FAULT_LIMIT, FORMAT_MAX_LENGTH, FORMAT_PATTERNS, GENERATION_ATTEMPT_LIMIT, GUARD_DEPTH_LIMIT, INFER_BREADTH_LIMIT, INFER_DEPTH_LIMIT, INFER_ENUM_LIMIT, INTRINSICS, JSONCloner, JSON_SCHEMA_TYPES, PREVIEW_LIMIT, SchemaCloner, ShapeCloner, ShapeValidator, admitMember, admitVisited, andOf, appendEntries, arrayOf, arrayShape, attempt, booleanShape, boundsOf, buildObjectShape, buildSampleMemo, buildShapeFromNode, canonicalStringify, canonicalizeValue, classifyFormat, cloneJSONRecord, cloneJSONValue, cloneSchema, cloneShape, collectEntries, collectMembers, compareValues, compileAuditor, compileGenerator, compileGuard, compileParser, compileReporter, compileSchema, complementOf, contain, createArrayFaults, createContract, createNumberFaults, createStringFaults, deriveLengthBounds, deriveRangeBounds, drawRandom, encodeLeaf, enumOf, enumerableKeys, enumerableSymbolCount, holds, inferArray, inferObject, inferPrimitiveEnum, inferRecordSamples, inferSamples, inferValue, instanceOf, integerShape, intersectionOf, isArray, isArrayBuffer, isArrayBufferView, isAsyncFunction, isAsyncGeneratorFunction, isAsyncIterable, isBigInt, isBigInt64Array, isBigUint64Array, isBoolean, isBoundedJSONRecord, isBoundedJSONValue, isConstructor, isContractError, isDataView, isDate, isDefined, isEmptyArray, isEmptyMap, isEmptyObject, isEmptySet, isEmptyString, isError, isFalse, isFiniteNumber, isFloat32Array, isFloat64Array, isFunction, isGeneratorFunction, isInstance, isInt16Array, isInt32Array, isInt8Array, isInteger, isIterable, isJSONPrimitive, isJSONValue, isLiteralValue, isMap, isNonEmptyArray, isNonEmptyMap, isNonEmptyObject, isNonEmptySet, isNonEmptyString, isNonNegativeInteger, isNonNegativeNumber, isNull, isNullableBoolean, isNullableNumber, isNullableString, isNumber, isObject, isPromise, isPromiseLike, isRecord, isRegExp, isSet, isSharedArrayBuffer, isString, isSymbol, isTrue, isUint16Array, isUint32Array, isUint8Array, isUint8ClampedArray, isUndefined, isValidISOInstant, isWeakMap, isWeakSet, isZeroArg, isZeroArgAsync, isZeroArgAsyncGenerator, isZeroArgGenerator, jsonShape, keyOf, lazyOf, limitEntries, literalOf, literalShape, mapOf, matchOf, matchesJSONDepth, matchesJSONValue, matchesMember, matchesPattern, matchesRecordBrand, matchesVisited, notOf, nullShape, nullableOf, nullableShape, numberShape, objectOf, objectShape, omitOf, omitVisited, oneOfShape, optionalOf, optionalShape, orOf, ownShape, parseArray, parseArrayField, parseBoolean, parseBooleanField, parseEnum, parseEnumField, parseInteger, parseIntegerField, parseJSON, parseJSONAs, parseJSONValue, parseJSONValueField, parseNull, parseNullField, parseNumber, parseNumberField, parseRecord, parseRecordField, parseString, parseStringField, pathOf, pickOf, pinMembers, preview, rawShape, readArrayEntries, readGuardShape, readMapEntries, readOptions, readPattern, readPatternFlags, readPatternSource, readSampleMemo, readSetEntries, readValue, recordOf, recordShape, refuseExpansion, resolveField, retainDepth, samplesToFormat, samplesToSchema, sanitizeBudget, sanitizeDepth, schemaNodeToShape, schemaToObject, schemaToParameters, schemaToShape, seededRandom, selectClosestFaults, setOf, shapeToKind, sortValues, stringOf, stringShape, stringToFormat, transformOf, tupleOf, unifySchemas, unionOf, unionShape, validateShapeDepth, valueToSchema, whereOf };
|
|
10360
|
+
export { CLONE_NODE_LIMIT, COMPILE_DEPTH_LIMIT, COMPILE_NODE_LIMIT, CONTRACT_ERROR_BRAND, ContractCompiler, ContractError, FAULT_LIMIT, FORMAT_MAX_LENGTH, FORMAT_PATTERNS, GENERATION_ATTEMPT_LIMIT, GUARD_DEPTH_LIMIT, INFER_BREADTH_LIMIT, INFER_DEPTH_LIMIT, INFER_ENUM_LIMIT, INTRINSICS, JSONCloner, JSON_SCHEMA_TYPES, PREVIEW_LIMIT, SchemaCloner, ShapeCloner, ShapeValidator, admitMember, admitVisited, andOf, appendEntries, arrayOf, arrayShape, attempt, booleanShape, boundsOf, buildObjectShape, buildSampleMemo, buildShapeFromNode, canonicalStringify, canonicalizeValue, classifyFormat, cloneJSONRecord, cloneJSONValue, cloneSchema, cloneShape, collectEntries, collectMembers, compareValues, compileAuditor, compileGenerator, compileGuard, compileParser, compileReporter, compileSchema, complementOf, contain, createArrayFaults, createContract, createNumberFaults, createStringFaults, deriveLengthBounds, deriveRangeBounds, drawRandom, encodeLeaf, enumOf, enumerableKeys, enumerableSymbolCount, holds, inferArray, inferObject, inferPrimitiveEnum, inferRecordSamples, inferSamples, inferValue, instanceOf, integerShape, intersectionOf, isArray, isArrayBuffer, isArrayBufferView, isAsyncFunction, isAsyncGeneratorFunction, isAsyncIterable, isBigInt, isBigInt64Array, isBigUint64Array, isBoolean, isBoundedJSONRecord, isBoundedJSONValue, isConstructor, isContractError, isDataView, isDate, isDefined, isEmptyArray, isEmptyMap, isEmptyObject, isEmptySet, isEmptyString, isError, isFalse, isFiniteNumber, isFloat32Array, isFloat64Array, isFunction, isGeneratorFunction, isInstance, isInt16Array, isInt32Array, isInt8Array, isInteger, isIterable, isJSONPrimitive, isJSONValue, isLiteralValue, isMap, isNonEmptyArray, isNonEmptyMap, isNonEmptyObject, isNonEmptySet, isNonEmptyString, isNonNegativeInteger, isNonNegativeNumber, isNull, isNullableBoolean, isNullableNumber, isNullableString, isNumber, isObject, isPromise, isPromiseLike, isRecord, isRegExp, isSet, isSharedArrayBuffer, isString, isSymbol, isTrue, isUint16Array, isUint32Array, isUint8Array, isUint8ClampedArray, isUndefined, isValidISOInstant, isWeakMap, isWeakSet, isZeroArg, isZeroArgAsync, isZeroArgAsyncGenerator, isZeroArgGenerator, jsonShape, keyOf, lazyOf, limitEntries, literalOf, literalShape, mapOf, matchOf, matchesJSONDepth, matchesJSONValue, matchesMember, matchesPattern, matchesRecordBrand, matchesVisited, notOf, nullShape, nullableOf, nullableShape, numberShape, objectOf, objectShape, omitOf, omitVisited, oneOfShape, optionalOf, optionalShape, orOf, ownShape, parseArray, parseArrayField, parseBoolean, parseBooleanField, parseEnum, parseEnumField, parseInteger, parseIntegerField, parseJSON, parseJSONAs, parseJSONValue, parseJSONValueField, parseNull, parseNullField, parseNumber, parseNumberField, parseRecord, parseRecordField, parseString, parseStringField, pathOf, pickOf, pinMembers, preview, rawShape, readArrayEntries, readGuardShape, readMapEntries, readOptions, readPattern, readPatternFlags, readPatternSource, readSampleMemo, readSetEntries, readValue, recordOf, recordShape, refuseExpansion, resolveField, retainDepth, samplesToFormat, samplesToSchema, sanitizeBudget, sanitizeDepth, schemaNodeToShape, schemaToObject, schemaToParameters, schemaToShape, seededRandom, selectClosestFaults, setOf, shapeToKind, sortValues, stringOf, stringShape, stringToFormat, transformOf, tupleOf, unifySchemas, unionOf, unionShape, validateShapeDepth, valueToSchema, whereOf };
|
|
10416
10361
|
|
|
10417
10362
|
//# sourceMappingURL=index.js.map
|