@orkestrel/contract 0.0.16 → 0.0.18

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.
@@ -286,7 +286,7 @@ var CONTRACT_CODES = Object.freeze([
286
286
  "expansion"
287
287
  ]);
288
288
  /**
289
- * Caps the number of {@link Fault} / {@link AuditFault} entries a single
289
+ * Caps at `64` the number of {@link Fault} / {@link AuditFault} entries a single
290
290
  * `explain` or `audit` report ever returns, frozen.
291
291
  *
292
292
  * @remarks
@@ -300,7 +300,7 @@ var CONTRACT_CODES = Object.freeze([
300
300
  */
301
301
  var FAULT_LIMIT = 64;
302
302
  /**
303
- * Caps the character length of a {@link preview}-rendered string, frozen.
303
+ * Caps at `64` the character length of a {@link preview}-rendered string, frozen.
304
304
  *
305
305
  * @remarks
306
306
  * A previewed string longer than this is clipped with a trailing `…` so a
@@ -325,7 +325,7 @@ var PREVIEW_LIMIT = 64;
325
325
  */
326
326
  var GUARD_DEPTH_LIMIT = 512;
327
327
  /**
328
- * Caps the supported nesting depth of a compiled contract shape, frozen.
328
+ * Caps at `512` the supported nesting depth of a compiled contract shape, frozen.
329
329
  *
330
330
  * @remarks
331
331
  * {@link validateShape} rejects the next level
@@ -340,7 +340,8 @@ var GUARD_DEPTH_LIMIT = 512;
340
340
  */
341
341
  var COMPILE_DEPTH_LIMIT = 512;
342
342
  /**
343
- * Caps the number of nodes a compiled artifact may expand a shape into, frozen.
343
+ * Caps at `16384` the number of nodes a compiled artifact may expand a shape into,
344
+ * frozen.
344
345
  *
345
346
  * @remarks
346
347
  * A shape graph is a DAG; every compiled artifact is a TREE. A declaration may
@@ -375,7 +376,7 @@ var COMPILE_DEPTH_LIMIT = 512;
375
376
  */
376
377
  var COMPILE_NODE_LIMIT = 16384;
377
378
  /**
378
- * Caps the number of object keys one compiled presence mask carries, frozen.
379
+ * Caps at `31` the number of object keys one compiled presence mask carries, frozen.
379
380
  *
380
381
  * @remarks
381
382
  * A compiled object plan decides which declared keys a value carries. The keys
@@ -399,7 +400,7 @@ var COMPILE_NODE_LIMIT = 16384;
399
400
  */
400
401
  var PRESENCE_MASK_LIMIT = 31;
401
402
  /**
402
- * Caps the number of nodes one JSON snapshot may produce, frozen.
403
+ * Caps at `262144` the number of nodes one JSON snapshot may produce, frozen.
403
404
  *
404
405
  * @remarks
405
406
  * JSON persistence is a TREE, so `cloneJSONValue` / `cloneJSONRecord`
@@ -426,8 +427,8 @@ var PRESENCE_MASK_LIMIT = 31;
426
427
  */
427
428
  var CLONE_NODE_LIMIT = 262144;
428
429
  /**
429
- * Caps the number of candidate-generation attempts for a constrained
430
- * generated value, frozen.
430
+ * Caps at `32` the number of candidate-generation attempts for a constrained generated
431
+ * value, frozen.
431
432
  *
432
433
  * @remarks
433
434
  * Provides one deterministic work bound for generators that must retry a
@@ -440,7 +441,7 @@ var CLONE_NODE_LIMIT = 262144;
440
441
  */
441
442
  var GENERATION_ATTEMPT_LIMIT = 32;
442
443
  /**
443
- * Caps the object/array nesting depth {@link valueToSchema} walks, frozen.
444
+ * Caps at `32` the object/array nesting depth {@link valueToSchema} walks, frozen.
444
445
  *
445
446
  * @remarks
446
447
  * Bounds inference against adversarial or cyclic runtime input — once the
@@ -458,8 +459,8 @@ var GENERATION_ATTEMPT_LIMIT = 32;
458
459
  */
459
460
  var INFER_DEPTH_LIMIT = 32;
460
461
  /**
461
- * Caps by default the number of object properties / array elements
462
- * {@link valueToSchema} samples per container, frozen.
462
+ * Caps by default at `256` the number of object properties / array elements {@link
463
+ * valueToSchema} samples per container, frozen.
463
464
  *
464
465
  * @remarks
465
466
  * Bounds the work (and the emitted schema's size) against a wide record or a
@@ -468,7 +469,7 @@ var INFER_DEPTH_LIMIT = 32;
468
469
  */
469
470
  var INFER_BREADTH_LIMIT = 256;
470
471
  /**
471
- * Caps by default the number of distinct values a multi-sample slot may hold
472
+ * Caps by default at `12` the number of distinct values a multi-sample slot may hold
472
473
  * before enum inference gives up and falls back to a bare `type`, frozen.
473
474
  *
474
475
  * @remarks
@@ -479,7 +480,7 @@ var INFER_BREADTH_LIMIT = 256;
479
480
  */
480
481
  var INFER_ENUM_LIMIT = 12;
481
482
  /**
482
- * Caps the string length {@link stringToFormat} attempts to classify, frozen.
483
+ * Caps at `128` the string length {@link stringToFormat} attempts to classify, frozen.
483
484
  *
484
485
  * @remarks
485
486
  * Bounds per-string format-detection work: a value longer than this returns
@@ -507,11 +508,14 @@ var FORMAT_PATTERNS = Object.freeze({
507
508
  //#endregion
508
509
  //#region src/core/errors.ts
509
510
  /**
510
- * Carries a machine-readable contract category, optional context, and an exact
511
- * optional cause. Omitting `cause` omits the own property; explicitly
512
- * supplying `cause: undefined` retains an own property with that value. Both
513
- * optional options are read as OWN properties, so a construction never consults
514
- * the caller-writable prototype chain of the container it was handed.
511
+ * Carries a machine-readable contract category, optional context, and an exact optional
512
+ * cause.
513
+ *
514
+ * @remarks
515
+ * Omitting `cause` omits the own property; explicitly supplying `cause: undefined`
516
+ * retains an own property with that value. Both optional options are read as OWN
517
+ * properties, so a construction never consults the caller-writable prototype chain of
518
+ * the container it was handed.
515
519
  *
516
520
  * @example
517
521
  * ```ts
@@ -901,6 +905,20 @@ function isNullableBoolean(value) {
901
905
  * wraps the check in {@link holds} (see ./helpers.js) so any such throw
902
906
  * yields `false` instead of escaping.
903
907
  *
908
+ * Narrows `value` to `InstanceType<C>`, which reads the constructor's last
909
+ * construct signature. Accepts the same constructors as `instanceOf`: a public
910
+ * or abstract construct signature returning an object (or `any`). A class with a
911
+ * private or protected constructor and the bare `AnyConstructor` are refused at the call.
912
+ * A value typed `Function` cannot be passed because the `Function` interface has
913
+ * no construct signature. The constructor `Function` can be passed through
914
+ * `FunctionConstructor`'s construct signature and narrows to `Function`.
915
+ * The false branch drops each member of the declared union that is a subtype
916
+ * of the instance type and keeps the rest, so a subclass that adds no member
917
+ * narrows its base out as well (and a subclass that adds only an optional member
918
+ * does not). A constructor whose instance type admits
919
+ * primitives structurally, such as `Object`, makes the false branch unsound;
920
+ * use `isObject` for that check.
921
+ *
904
922
  * @param value - The value to test
905
923
  * @param ctor - The constructor to test against
906
924
  * @returns True if `value instanceof ctor`; false otherwise, including on a
@@ -932,6 +950,11 @@ function isDate(value) {
932
950
  }
933
951
  /** Determines whether a value is a `RegExp`.
934
952
  *
953
+ * @remarks
954
+ * A total native internal-slot brand check rather than a property read: it accepts a
955
+ * genuine pattern from this realm and from another, and refuses a proxy or a hand-built
956
+ * forgery without reading an advertised field.
957
+ *
935
958
  * @param value - The value to inspect
936
959
  * @returns True if the value is a `RegExp`; false otherwise
937
960
  *
@@ -1177,6 +1200,10 @@ function isWeakSet(value) {
1177
1200
  }
1178
1201
  /** Determines whether a value is an array.
1179
1202
  *
1203
+ * @remarks
1204
+ * Checks the container alone — no element is inspected. Use {@link arrayOf} to check
1205
+ * every element against a guard.
1206
+ *
1180
1207
  * @param value - The value to inspect
1181
1208
  * @returns True if the value is an array; false otherwise
1182
1209
  *
@@ -1950,6 +1977,13 @@ function collectMembers(values) {
1950
1977
  * Determines whether a value is a member of a collected vocabulary, by
1951
1978
  * SameValueZero.
1952
1979
  *
1980
+ * @remarks
1981
+ * Dispatched through the captured `Set.prototype.has` onto a collection no caller
1982
+ * holds, and asked as a module binding rather than as a property: `set.has(value)` asks
1983
+ * a member every caller can rewrite, and moving that read onto an exported class's
1984
+ * `has` method reproduced the identical defect one prototype higher, because every
1985
+ * public class method is dispatched through a reachable prototype.
1986
+ *
1953
1987
  * @param members - The vocabulary to ask, built by {@link collectMembers}
1954
1988
  * @param value - The value to test for membership
1955
1989
  * @returns True if the value was collected; false otherwise
@@ -1965,6 +1999,10 @@ function matchesMember(members, value) {
1965
1999
  /**
1966
2000
  * Collects one more member into a vocabulary that grows as a walk proceeds.
1967
2001
  *
2002
+ * @remarks
2003
+ * Collects through the captured adder, for a vocabulary that grows as a walk proceeds —
2004
+ * a uniqueness gate, a de-duplicating key population.
2005
+ *
1968
2006
  * @param members - The vocabulary to extend
1969
2007
  * @param value - The value to admit
1970
2008
  *
@@ -2007,6 +2045,10 @@ function matchesVisited(visited, value) {
2007
2045
  /**
2008
2046
  * Records an object as entered on a traversal's active path.
2009
2047
  *
2048
+ * @remarks
2049
+ * Records through the captured `WeakSet.prototype.add`, on the same terms {@link
2050
+ * matchesVisited} states for the membership answer.
2051
+ *
2010
2052
  * @param visited - The active-path set this traversal owns
2011
2053
  * @param value - The object being entered
2012
2054
  *
@@ -2021,6 +2063,10 @@ function admitVisited(visited, value) {
2021
2063
  /**
2022
2064
  * Records an object as exited from a traversal's active path.
2023
2065
  *
2066
+ * @remarks
2067
+ * Records through the captured `WeakSet.prototype.delete`, on the same terms {@link
2068
+ * matchesVisited} states for the membership answer.
2069
+ *
2024
2070
  * @param visited - The active-path set this traversal owns
2025
2071
  * @param value - The object being exited
2026
2072
  *
@@ -2233,6 +2279,10 @@ function readPatternSource(pattern) {
2233
2279
  /**
2234
2280
  * Reads a regular expression's flag text through the captured accessor.
2235
2281
  *
2282
+ * @remarks
2283
+ * The flags half of {@link readPatternSource}, on the same captured-accessor terms and
2284
+ * for the same reason.
2285
+ *
2236
2286
  * @param pattern - The candidate regular expression to read
2237
2287
  * @returns The pattern's flag text, or `undefined` when it cannot be read as a string
2238
2288
  * @throws The exact value the captured accessor throws for a receiver that is not a pattern
@@ -2567,6 +2617,11 @@ function contain(callback, door, options) {
2567
2617
  /**
2568
2618
  * Invokes a predicate through the sanctioned never-throw boundary.
2569
2619
  *
2620
+ * @remarks
2621
+ * Backs the `instanceof`-based validators and every container combinator's element
2622
+ * walk. The answer is `true` only for the boolean literal `true`; a throw and every
2623
+ * other return are `false`.
2624
+ *
2570
2625
  * @param callback - The predicate to invoke with no arguments
2571
2626
  * @returns True if the callback returns the boolean value `true`; false otherwise
2572
2627
  *
@@ -2898,6 +2953,15 @@ function readOptions(source, keys, builder, shape) {
2898
2953
  /**
2899
2954
  * Draws and validates one generator random sample.
2900
2955
  *
2956
+ * @remarks
2957
+ * A broken source is the source's fault rather than the shape's, so the refusal
2958
+ * carries code `random` and never the `generate` code, and {@link compileGenerator}
2959
+ * rethrows it at whatever draw depth it happened instead of rotating to the next union
2960
+ * variant. The diagnostic names the consuming shape category, the `[0, 1)` limit, and a
2961
+ * total non-coercing {@link preview} of the offending sample (or `threw`), so a hostile
2962
+ * object runs no conversion hook while the diagnostic is built and a primitive symbol
2963
+ * renders without consulting mutable `Symbol.prototype.toString`.
2964
+ *
2901
2965
  * @param random - The caller-supplied random source
2902
2966
  * @param shape - The shape category consuming the sample
2903
2967
  * @returns A finite sample in `[0, 1)`
@@ -3643,7 +3707,7 @@ function sanitizeDepth(value) {
3643
3707
  return INTRINSICS.min(sanitizeBudget(value, 32), 32);
3644
3708
  }
3645
3709
  /**
3646
- * Renders a short, safe, TOTAL preview of an unknown value for a {@link Fault}'s
3710
+ * Renders an unknown value as a short, safe, TOTAL string for a {@link Fault}'s
3647
3711
  * `received` field.
3648
3712
  *
3649
3713
  * @remarks
@@ -4534,7 +4598,10 @@ var ShapeValidator = class ShapeValidator {
4534
4598
  const outcome = attempt(() => this.#execute());
4535
4599
  const poison = this.#state.phase === "active" ? this.#state.poison : void 0;
4536
4600
  this.#clear();
4537
- if (poison !== void 0) throw poison;
4601
+ if (poison !== void 0) {
4602
+ this.#expansion = void 0;
4603
+ throw poison;
4604
+ }
4538
4605
  if (outcome.success) return;
4539
4606
  if (isContractError(outcome.error)) throw outcome.error;
4540
4607
  throw new ContractError("validateShape: shape reflection failed", {
@@ -6310,6 +6377,11 @@ function literalOf(...literals) {
6310
6377
  * Verifies that `ctor` is a real constructor (through {@link isConstructor}) first,
6311
6378
  * so passing an arrow function does not silently produce a broken guard.
6312
6379
  *
6380
+ * A callable instance passes. The exclusion is a bad constructor, never a callable
6381
+ * value: an `isObject` pre-filter made `instanceOf(Function)(() => {})` answer `false`
6382
+ * while {@link isInstance}, the helper this is built on, answered `true` for the same
6383
+ * pair.
6384
+ *
6313
6385
  * @param ctor - The constructor whose instances the guard accepts
6314
6386
  * @returns A guard narrowing to that constructor's instance type
6315
6387
  *
@@ -6327,6 +6399,10 @@ function instanceOf(ctor) {
6327
6399
  * Builds a guard from a native `enum` or any object whose values are strings or
6328
6400
  * numbers.
6329
6401
  *
6402
+ * @remarks
6403
+ * An unreadable enumeration is refused at factory time with the shared `structure` read
6404
+ * refusal; the returned guard stays total.
6405
+ *
6330
6406
  * @param enumeration - The readable enumeration whose values the guard accepts
6331
6407
  * @returns A guard accepting one enumeration value
6332
6408
  * @throws {ContractError} When the enumeration cannot be read
@@ -6439,6 +6515,10 @@ function keyOf(value) {
6439
6515
  * Builds a new guard shape by keeping only the listed keys — the structural
6440
6516
  * equivalent of `Pick<T, K>`. Produces a shape for {@link recordOf}, not a guard.
6441
6517
  *
6518
+ * @remarks
6519
+ * An unreadable `keys` list and an unreadable `shape` are refused separately, each
6520
+ * under its own name, so a caller reads which argument failed.
6521
+ *
6442
6522
  * @param shape - The guard shape to narrow
6443
6523
  * @param keys - The keys to keep
6444
6524
  * @returns A guard shape carrying only the kept keys
@@ -6478,6 +6558,10 @@ function pickOf(shape, keys) {
6478
6558
  * Builds a new guard shape by removing the listed keys — the structural
6479
6559
  * equivalent of `Omit<T, K>`. Produces a shape for {@link recordOf}, not a guard.
6480
6560
  *
6561
+ * @remarks
6562
+ * An unreadable `keys` list and an unreadable `shape` are refused separately, each
6563
+ * under its own name, for the reason {@link pickOf} states.
6564
+ *
6481
6565
  * @param shape - The guard shape to narrow
6482
6566
  * @param keys - The keys to remove
6483
6567
  * @returns A guard shape carrying every key except the removed ones
@@ -6526,6 +6610,10 @@ function orOf(left, right) {
6526
6610
  * Typed as `Guard<unknown>` because `Exclude<unknown, T>` is not useful; use
6527
6611
  * {@link complementOf} when you need the narrowed `Exclude<TBase, TExcluded>`.
6528
6612
  *
6613
+ * The negation applies to the contained verdict, so a throwing guard is a non-match and
6614
+ * its negation passes. Containing the negation instead made a guard and its `notOf`
6615
+ * both reject the same value, which broke `orOf(g, notOf(g))` as a tautology.
6616
+ *
6529
6617
  * @param guard - The guard or predicate to negate
6530
6618
  * @returns A guard accepting exactly the values `guard` rejects
6531
6619
  *
@@ -6541,6 +6629,10 @@ function notOf(guard) {
6541
6629
  * Builds a guard for `Exclude<TBase, TExcluded>` — accepts values that pass
6542
6630
  * `base` but not `excluded`.
6543
6631
  *
6632
+ * @remarks
6633
+ * The base and the exclusion are contained separately, for the reason {@link notOf}
6634
+ * states: a throwing exclusion is a non-match, so the complement passes.
6635
+ *
6544
6636
  * @param base - The guard establishing the accepted domain
6545
6637
  * @param excluded - The guard whose accepted values are removed from that domain
6546
6638
  * @returns A guard accepting a value `base` accepts and `excluded` rejects
@@ -6873,6 +6965,12 @@ function parseNull(value) {
6873
6965
  /**
6874
6966
  * Parses an unknown value to a plain record — the input reference, never cloned.
6875
6967
  *
6968
+ * @remarks
6969
+ * Probes the record's own enumerable values before returning the reference, so a
6970
+ * hostile getter is met here rather than at the caller. A failed probe throws
6971
+ * `ContractError { code: 'structure' }` carrying `parseRecord: value could not be
6972
+ * read`; a readable non-record answers `undefined`.
6973
+ *
6876
6974
  * @param value - The value to parse
6877
6975
  * @returns The record, or `undefined`
6878
6976
  * @throws {ContractError} When an object value cannot be read
@@ -9943,6 +10041,11 @@ function stringShape(options) {
9943
10041
  /**
9944
10042
  * Builds a numeric {@link NumberShape}.
9945
10043
  *
10044
+ * @remarks
10045
+ * A present `min` or `max` must be finite. `NaN` and `±Infinity` throw a `bound` {@link
10046
+ * ContractError} at construction, because no finite value satisfies them and no JSON
10047
+ * Schema keyword expresses them.
10048
+ *
9946
10049
  * @param options - Optional bounds (`min` / `max`), `integer`, and `description`
9947
10050
  * @returns A number shape
9948
10051
  * @throws {ContractError} When a present bound is not finite
@@ -10390,6 +10493,9 @@ function nullableShape(inner) {
10390
10493
  * the compiled guard accepts — `NaN`, a `Map`, and a class instance all satisfy
10391
10494
  * `{}` and all fail `isJSONValue`.
10392
10495
  *
10496
+ * This is the shape an author writes to mean "any JSON value". Inference never produces
10497
+ * it: {@link schemaToShape} widening always lands on {@link RawShape} instead.
10498
+ *
10393
10499
  * @param options - Optional `description`
10394
10500
  * @returns A JSON passthrough shape
10395
10501
  *