@orkestrel/contract 0.0.12 → 0.0.14

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.
@@ -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. */
@@ -1202,6 +1214,14 @@ export declare class ContractCompiler<S extends ContractShape = ContractShape> i
1202
1214
  * interrupted outer read, and every later read with one shared cause-free
1203
1215
  * error.
1204
1216
  *
1217
+ * After every family exists, the compiler releases its working set — the owned
1218
+ * graph, the node index, the order, and every family plan. A compiler read for
1219
+ * one artifact and then kept holds that whole set for as long as you keep the
1220
+ * compiler. A compiled artifact is the opposite: each one closes over the child
1221
+ * entries its family needed while that family was built, so it answers on its
1222
+ * own and outlives the compiler that produced it. When one artifact is what you
1223
+ * want, keep the artifact and let the compiler go.
1224
+ *
1205
1225
  * @example
1206
1226
  * ```ts
1207
1227
  * const compiler = new ContractCompiler(stringShape({ min: 1 }))
@@ -1241,7 +1261,6 @@ export declare interface ContractCompilerInterface<S extends ContractShape> {
1241
1261
  * ```
1242
1262
  */
1243
1263
  export declare class ContractError extends Error {
1244
- #private;
1245
1264
  readonly name = "ContractError";
1246
1265
  readonly code: ContractCode;
1247
1266
  readonly context: ContractErrorContext | undefined;
@@ -1252,52 +1271,6 @@ export declare class ContractError extends Error {
1252
1271
  * @param options - Machine-readable category, optional context, and optional cause
1253
1272
  */
1254
1273
  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
1274
  }
1302
1275
 
1303
1276
  /** Optional structured details carried by a {@link ContractError}. */
@@ -1445,6 +1418,20 @@ export declare function createArrayFaults(shape: ArrayShape, length: number, pat
1445
1418
  * longer re-walk and re-gate the declaration on every call the way they used
1446
1419
  * to; `contract.audit` and `compileAuditor` are the same compiled function
1447
1420
  * reached two ways.
1421
+ * The bundle is eager by intent. Its members are plain data properties holding
1422
+ * the compiled artifacts, so `const { is, parse } = createContract(shape)`
1423
+ * destructures those exact values and a spread of the result copies them; a
1424
+ * lazily compiled member would compile on either, which spends the laziness
1425
+ * rather than saving it. A malformed declaration refuses at this call rather
1426
+ * than at the first read of whichever member a caller happens to touch, so the
1427
+ * failure arrives at the call the caller made — carrying the authoring door's
1428
+ * own diagnosis, which this door adopts rather than rewraps. Every member is
1429
+ * self-contained, and the compiler this call builds releases its working set
1430
+ * before the call returns. The contract keeps part of the declaration even so:
1431
+ * the auditor and reporter plans close over the owned leaf and array nodes they
1432
+ * read their bounds from, so a kept contract retains those nodes and, through
1433
+ * an array node's `items` field, the subgraph beneath them. Nothing the caller
1434
+ * keeps reaches back into the compiler.
1448
1435
  *
1449
1436
  * @param shape - The shape to compile
1450
1437
  * @returns A contract bundling `schema` / `is` / `parse` / `audit` / `explain` / `generate`
@@ -2735,36 +2722,21 @@ export declare function isBoundedJSONValue(value: unknown): value is JSONValue;
2735
2722
  export declare function isConstructor(value: unknown): value is AnyConstructor<object>;
2736
2723
 
2737
2724
  /**
2738
- * Determine whether an unknown value is a {@link ContractError}.
2725
+ * Checks whether an unknown value is a {@link ContractError}.
2739
2726
  *
2740
2727
  * @remarks
2741
- * The ONLY spelling of the recognition question this package publishes. The test
2742
- * itself is a private static of the class, because private-name membership is
2743
- * legal only inside a class body; the one member on the path,
2744
- * {@link ContractError.guard}, hands that test over and is pinned non-writable
2745
- * and non-configurable while the class is defined. So there is no property a
2746
- * caller can point somewhere else, and no member that ANSWERS the recognition
2747
- * question — which is exactly what the static that preceded it did.
2748
- *
2749
- * A function declaration rather than a `const` holding the retrieved closure.
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.
2728
+ * Recognition combines a global own-property brand with the native `Error`
2729
+ * base, a subclass prototype, the fixed name, and a declared contract code.
2730
+ * The brand stores the error itself and recognition requires that exact
2731
+ * identity. A transparent proxy is therefore refused because its forwarded
2732
+ * descriptor still stores the target, not the proxy.
2733
+ * The brand is recognized across duplicate installations and ESM/CommonJS
2734
+ * module copies at 0.0.13 or later. A copy earlier than 0.0.13 stamps no brand,
2735
+ * so an error it throws stays outside the type, and so does a plain or
2736
+ * property-only lookalike.
2765
2737
  *
2766
2738
  * @param value - The value to inspect
2767
- * @returns `true` only for a value this class's constructor branded
2739
+ * @returns True only for a `ContractError` instance; false otherwise
2768
2740
  *
2769
2741
  * @example
2770
2742
  * ```ts
@@ -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. */
@@ -1202,6 +1214,14 @@ export declare class ContractCompiler<S extends ContractShape = ContractShape> i
1202
1214
  * interrupted outer read, and every later read with one shared cause-free
1203
1215
  * error.
1204
1216
  *
1217
+ * After every family exists, the compiler releases its working set — the owned
1218
+ * graph, the node index, the order, and every family plan. A compiler read for
1219
+ * one artifact and then kept holds that whole set for as long as you keep the
1220
+ * compiler. A compiled artifact is the opposite: each one closes over the child
1221
+ * entries its family needed while that family was built, so it answers on its
1222
+ * own and outlives the compiler that produced it. When one artifact is what you
1223
+ * want, keep the artifact and let the compiler go.
1224
+ *
1205
1225
  * @example
1206
1226
  * ```ts
1207
1227
  * const compiler = new ContractCompiler(stringShape({ min: 1 }))
@@ -1241,7 +1261,6 @@ export declare interface ContractCompilerInterface<S extends ContractShape> {
1241
1261
  * ```
1242
1262
  */
1243
1263
  export declare class ContractError extends Error {
1244
- #private;
1245
1264
  readonly name = "ContractError";
1246
1265
  readonly code: ContractCode;
1247
1266
  readonly context: ContractErrorContext | undefined;
@@ -1252,52 +1271,6 @@ export declare class ContractError extends Error {
1252
1271
  * @param options - Machine-readable category, optional context, and optional cause
1253
1272
  */
1254
1273
  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
1274
  }
1302
1275
 
1303
1276
  /** Optional structured details carried by a {@link ContractError}. */
@@ -1445,6 +1418,20 @@ export declare function createArrayFaults(shape: ArrayShape, length: number, pat
1445
1418
  * longer re-walk and re-gate the declaration on every call the way they used
1446
1419
  * to; `contract.audit` and `compileAuditor` are the same compiled function
1447
1420
  * reached two ways.
1421
+ * The bundle is eager by intent. Its members are plain data properties holding
1422
+ * the compiled artifacts, so `const { is, parse } = createContract(shape)`
1423
+ * destructures those exact values and a spread of the result copies them; a
1424
+ * lazily compiled member would compile on either, which spends the laziness
1425
+ * rather than saving it. A malformed declaration refuses at this call rather
1426
+ * than at the first read of whichever member a caller happens to touch, so the
1427
+ * failure arrives at the call the caller made — carrying the authoring door's
1428
+ * own diagnosis, which this door adopts rather than rewraps. Every member is
1429
+ * self-contained, and the compiler this call builds releases its working set
1430
+ * before the call returns. The contract keeps part of the declaration even so:
1431
+ * the auditor and reporter plans close over the owned leaf and array nodes they
1432
+ * read their bounds from, so a kept contract retains those nodes and, through
1433
+ * an array node's `items` field, the subgraph beneath them. Nothing the caller
1434
+ * keeps reaches back into the compiler.
1448
1435
  *
1449
1436
  * @param shape - The shape to compile
1450
1437
  * @returns A contract bundling `schema` / `is` / `parse` / `audit` / `explain` / `generate`
@@ -2735,36 +2722,21 @@ export declare function isBoundedJSONValue(value: unknown): value is JSONValue;
2735
2722
  export declare function isConstructor(value: unknown): value is AnyConstructor<object>;
2736
2723
 
2737
2724
  /**
2738
- * Determine whether an unknown value is a {@link ContractError}.
2725
+ * Checks whether an unknown value is a {@link ContractError}.
2739
2726
  *
2740
2727
  * @remarks
2741
- * The ONLY spelling of the recognition question this package publishes. The test
2742
- * itself is a private static of the class, because private-name membership is
2743
- * legal only inside a class body; the one member on the path,
2744
- * {@link ContractError.guard}, hands that test over and is pinned non-writable
2745
- * and non-configurable while the class is defined. So there is no property a
2746
- * caller can point somewhere else, and no member that ANSWERS the recognition
2747
- * question — which is exactly what the static that preceded it did.
2748
- *
2749
- * A function declaration rather than a `const` holding the retrieved closure.
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.
2728
+ * Recognition combines a global own-property brand with the native `Error`
2729
+ * base, a subclass prototype, the fixed name, and a declared contract code.
2730
+ * The brand stores the error itself and recognition requires that exact
2731
+ * identity. A transparent proxy is therefore refused because its forwarded
2732
+ * descriptor still stores the target, not the proxy.
2733
+ * The brand is recognized across duplicate installations and ESM/CommonJS
2734
+ * module copies at 0.0.13 or later. A copy earlier than 0.0.13 stamps no brand,
2735
+ * so an error it throws stays outside the type, and so does a plain or
2736
+ * property-only lookalike.
2765
2737
  *
2766
2738
  * @param value - The value to inspect
2767
- * @returns `true` only for a value this class's constructor branded
2739
+ * @returns True only for a `ContractError` instance; false otherwise
2768
2740
  *
2769
2741
  * @example
2770
2742
  * ```ts