@orkestrel/contract 0.0.20 → 0.0.21

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.
@@ -10,7 +10,7 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
10
10
  * own. The registry makes the key discoverable; it is a recognition mechanism,
11
11
  * not an unforgeable provenance marker.
12
12
  */
13
- var CONTRACT_ERROR_BRAND = Symbol.for("@orkestrel/contract.error");
13
+ var CONTRACT_ERROR_BRAND = Symbol.for("@orkestrel/contract.ContractError");
14
14
  /**
15
15
  * Captures every host operation this package dispatches through, while this
16
16
  * module evaluates.
@@ -548,6 +548,71 @@ var FORMAT_PATTERNS = Object.freeze({
548
548
  email: /^[^\s@]+@[^\s@]+\.[^\s@]+$/,
549
549
  uri: /^[a-z][a-z0-9+.-]*:\/\//i
550
550
  });
551
+ /**
552
+ * Caps at `1024` the number of choices one schema field may offer, frozen.
553
+ *
554
+ * @remarks
555
+ * A retention limit that a declaring package, such as a form or table schema
556
+ * package, enforces; this package enforces none of the retention limits itself.
557
+ *
558
+ * @example
559
+ * ```ts
560
+ * CHOICE_LIMIT // 1024
561
+ * ```
562
+ */
563
+ var CHOICE_LIMIT = 1024;
564
+ /**
565
+ * Caps at `128` the length, in UTF-16 code units, of one name a schema declares, frozen:
566
+ * a schema, group, or field name, or a column key.
567
+ *
568
+ * @remarks
569
+ * A retention limit that a declaring package enforces, as {@link CHOICE_LIMIT} states.
570
+ *
571
+ * @example
572
+ * ```ts
573
+ * NAME_LIMIT // 128
574
+ * ```
575
+ */
576
+ var NAME_LIMIT = 128;
577
+ /**
578
+ * Caps at `65536` the length, in UTF-16 code units, of any single string one schema
579
+ * retains, frozen.
580
+ *
581
+ * @remarks
582
+ * A retention limit that a declaring package enforces, as {@link CHOICE_LIMIT} states.
583
+ *
584
+ * @example
585
+ * ```ts
586
+ * STRING_LIMIT // 65536
587
+ * ```
588
+ */
589
+ var STRING_LIMIT = 65536;
590
+ /**
591
+ * Caps at `1048576` the total length, in UTF-16 code units, of every string one schema
592
+ * retains, frozen.
593
+ *
594
+ * @remarks
595
+ * A retention limit that a declaring package enforces, as {@link CHOICE_LIMIT} states.
596
+ *
597
+ * @example
598
+ * ```ts
599
+ * TEXT_LIMIT // 1048576
600
+ * ```
601
+ */
602
+ var TEXT_LIMIT = 1048576;
603
+ /**
604
+ * Caps at `16384` the total number of records, arrays, and leaves one schema retains,
605
+ * frozen.
606
+ *
607
+ * @remarks
608
+ * A retention limit that a declaring package enforces, as {@link CHOICE_LIMIT} states.
609
+ *
610
+ * @example
611
+ * ```ts
612
+ * NODE_LIMIT // 16384
613
+ * ```
614
+ */
615
+ var NODE_LIMIT = 16384;
551
616
  // src/core/errors.ts
552
617
  /**
553
618
  * Carries a machine-readable contract category, optional context, and an exact optional
@@ -1998,10 +2063,10 @@ function limitEntries(entries, limit) {
1998
2063
  *
1999
2064
  * @example
2000
2065
  * ```ts
2001
- * compareValues('a', 'b') // -1
2066
+ * comparePrimitives('a', 'b') // -1
2002
2067
  * ```
2003
2068
  */
2004
- function compareValues(left, right) {
2069
+ function comparePrimitives(left, right) {
2005
2070
  return left < right ? -1 : left > right ? 1 : 0;
2006
2071
  }
2007
2072
  /**
@@ -2015,7 +2080,7 @@ function compareValues(left, right) {
2015
2080
  * `valueToSchema({ b: 1, a: 2 })` publish `{"type":"object","additionalProperties":false}`
2016
2081
  * — a successful answer with the caller's properties silently gone. The copy is
2017
2082
  * taken first so a caller-owned array is never reordered in place, and the order
2018
- * is decided by {@link compareValues}, whose `<` / `>` comparison dispatches
2083
+ * is decided by {@link comparePrimitives}, whose `<` / `>` comparison dispatches
2019
2084
  * through nothing.
2020
2085
  *
2021
2086
  * @param values - The keys or indices to order
@@ -2029,7 +2094,7 @@ function compareValues(left, right) {
2029
2094
  function sortValues(values) {
2030
2095
  const observed = INTRINSICS.from(iterateIndices(() => values.length), (index) => values[index]);
2031
2096
  const owned = INTRINSICS.reflect.apply(INTRINSICS.select, readIndexView(observed), [(value) => value !== void 0]);
2032
- INTRINSICS.reflect.apply(INTRINSICS.order, owned, [compareValues]);
2097
+ INTRINSICS.reflect.apply(INTRINSICS.order, owned, [comparePrimitives]);
2033
2098
  return owned;
2034
2099
  }
2035
2100
  /**
@@ -2273,7 +2338,7 @@ function readSampleMemo(memo, reader) {
2273
2338
  *
2274
2339
  * @remarks
2275
2340
  * Extracted rather than written inline for the same reason
2276
- * {@link compareValues} is: `Reflect.apply` takes its arguments as a LIST, so an
2341
+ * {@link comparePrimitives} is: `Reflect.apply` takes its arguments as a LIST, so an
2277
2342
  * inline collector is a function expression inside an array literal rather than
2278
2343
  * one passed directly as an argument — a hidden function assignment this
2279
2344
  * repository forbids wherever it appears. Returned directly from a factory it is
@@ -2423,6 +2488,46 @@ function matchesPattern(pattern, value) {
2423
2488
  return INTRINSICS.reflect.apply(INTRINSICS.captures, pattern, [value]) !== null;
2424
2489
  }
2425
2490
  /**
2491
+ * Escapes every regular-expression metacharacter in a text, so the text
2492
+ * matches literally inside a larger `RegExp` source.
2493
+ *
2494
+ * @remarks
2495
+ * Prefixes each of `\ ^ $ . * + ? ( ) [ ] { } |` with a backslash and leaves
2496
+ * every other character, `-` and `/` included, unchanged; the empty string
2497
+ * returns unchanged. The escape is an INDEXED character map rather than
2498
+ * `String.prototype.replace`, which dispatches through the caller-writable
2499
+ * `RegExp.prototype[Symbol.replace]` and `exec` members.
2500
+ *
2501
+ * @param value - The literal text to escape
2502
+ * @returns The text with every metacharacter backslash-escaped
2503
+ *
2504
+ * @example
2505
+ * ```ts
2506
+ * escapeRegExp('a.b*c') // 'a\\.b\\*c'
2507
+ * new RegExp(`^${escapeRegExp('a.b')}$`).test('axb') // false
2508
+ * ```
2509
+ */
2510
+ function escapeRegExp(value) {
2511
+ const metacharacters = collectMembers([
2512
+ "\\",
2513
+ "^",
2514
+ "$",
2515
+ ".",
2516
+ "*",
2517
+ "+",
2518
+ "?",
2519
+ "(",
2520
+ ")",
2521
+ "[",
2522
+ "]",
2523
+ "{",
2524
+ "}",
2525
+ "|"
2526
+ ]);
2527
+ const characters = INTRINSICS.from(iterateIndices(() => value.length), (index) => matchesMember(metacharacters, value[index]) ? `\\${value[index]}` : value[index]);
2528
+ return INTRINSICS.reflect.apply(INTRINSICS.join, characters, [""]);
2529
+ }
2530
+ /**
2426
2531
  * Rebuilds a caller's regular expression as a stateless pattern this package
2427
2532
  * owns.
2428
2533
  *
@@ -2548,6 +2653,68 @@ function pinMembers(prototype, owner) {
2548
2653
  }
2549
2654
  }
2550
2655
  /**
2656
+ * Boxes a value as the {@link Success} branch of a {@link Result}.
2657
+ *
2658
+ * @param value - The value to box, retained exactly
2659
+ * @returns A fresh `{ success: true, value }` record
2660
+ *
2661
+ * @example
2662
+ * ```ts
2663
+ * success(42) // { success: true, value: 42 }
2664
+ * ```
2665
+ */
2666
+ function success(value) {
2667
+ return {
2668
+ success: true,
2669
+ value
2670
+ };
2671
+ }
2672
+ /**
2673
+ * Boxes an error as the {@link Failure} branch of a {@link Result}.
2674
+ *
2675
+ * @param error - The error to box, retained exactly
2676
+ * @returns A fresh `{ success: false, error }` record
2677
+ *
2678
+ * @example
2679
+ * ```ts
2680
+ * failure('offline') // { success: false, error: 'offline' }
2681
+ * ```
2682
+ */
2683
+ function failure(error) {
2684
+ return {
2685
+ success: false,
2686
+ error
2687
+ };
2688
+ }
2689
+ /**
2690
+ * Narrows a {@link Result} to its {@link Success} branch.
2691
+ *
2692
+ * @param result - The result to narrow
2693
+ * @returns True if the result succeeded; false otherwise
2694
+ *
2695
+ * @example
2696
+ * ```ts
2697
+ * isSuccess(success(1)) // true
2698
+ * ```
2699
+ */
2700
+ function isSuccess(result) {
2701
+ return result.success;
2702
+ }
2703
+ /**
2704
+ * Narrows a {@link Result} to its {@link Failure} branch.
2705
+ *
2706
+ * @param result - The result to narrow
2707
+ * @returns True if the result failed; false otherwise
2708
+ *
2709
+ * @example
2710
+ * ```ts
2711
+ * isFailure(failure('offline')) // true
2712
+ * ```
2713
+ */
2714
+ function isFailure(result) {
2715
+ return !result.success;
2716
+ }
2717
+ /**
2551
2718
  * Invokes a callback once and synchronously captures its exact outcome as a
2552
2719
  * {@link Result}.
2553
2720
  *
@@ -2575,23 +2742,42 @@ function pinMembers(prototype, owner) {
2575
2742
  * @example
2576
2743
  * ```ts
2577
2744
  * const outcome = attempt(() => predicate(value))
2578
- * return outcome.success && outcome.value
2745
+ * return isSuccess(outcome) && outcome.value
2579
2746
  * ```
2580
2747
  */
2581
2748
  function attempt(callback) {
2582
2749
  try {
2583
- return {
2584
- success: true,
2585
- value: callback()
2586
- };
2750
+ return success(callback());
2587
2751
  } catch (error) {
2588
- return {
2589
- success: false,
2590
- error
2591
- };
2752
+ return failure(error);
2592
2753
  }
2593
2754
  }
2594
2755
  /**
2756
+ * Renders a thrown value as a non-empty message.
2757
+ *
2758
+ * @remarks
2759
+ * Reads an `Error`'s `message` and converts any other value with the `String`
2760
+ * function {@link INTRINSICS} captured at load, so a symbol renders as
2761
+ * `Symbol(description)` and a caller that replaces the global `String` does not
2762
+ * change the result. Returns `'unknown failure'` when
2763
+ * that read throws, as a throwing `message` getter or `toString` method does,
2764
+ * when an `Error`'s `message` is not a string, and when the rendered text is
2765
+ * empty. Never throws.
2766
+ *
2767
+ * @param error - The caught value, of any shape
2768
+ * @returns The rendered message, never empty
2769
+ *
2770
+ * @example
2771
+ * ```ts
2772
+ * errorToMessage(new Error('boom')) // 'boom'
2773
+ * errorToMessage('') // 'unknown failure'
2774
+ * ```
2775
+ */
2776
+ function errorToMessage(error) {
2777
+ const read = attempt(() => isError(error) ? error.message : INTRINSICS.text(error));
2778
+ return isSuccess(read) && isString(read.value) && read.value.length > 0 ? read.value : "unknown failure";
2779
+ }
2780
+ /**
2595
2781
  * Reads a value through the shared containment boundary or refuses it with the
2596
2782
  * contract module's uniform read diagnostic.
2597
2783
  *
@@ -2635,12 +2821,12 @@ function readValue(callback, reader, options) {
2635
2821
  owned
2636
2822
  };
2637
2823
  });
2638
- if (!diagnostics.success) throw new ContractError("readValue: options could not be read", {
2824
+ if (isFailure(diagnostics)) throw new ContractError("readValue: options could not be read", {
2639
2825
  code: "structure",
2640
2826
  cause: diagnostics.error
2641
2827
  });
2642
2828
  const outcome = attempt(callback);
2643
- if (!outcome.success) {
2829
+ if (isFailure(outcome)) {
2644
2830
  const owned = diagnostics.value.owned;
2645
2831
  const context = owned === void 0 ? void 0 : {
2646
2832
  ...owned.path === void 0 ? {} : { path: owned.path },
@@ -2702,7 +2888,7 @@ function readValue(callback, reader, options) {
2702
2888
  */
2703
2889
  function contain(callback, door, options) {
2704
2890
  const outcome = attempt(callback);
2705
- if (outcome.success) return outcome.value;
2891
+ if (isSuccess(outcome)) return outcome.value;
2706
2892
  if (isContractError(outcome.error)) throw outcome.error;
2707
2893
  throw new ContractError(`${door}: a host operation this door depends on failed`, {
2708
2894
  code: options?.code ?? "structure",
@@ -2728,7 +2914,7 @@ function contain(callback, door, options) {
2728
2914
  */
2729
2915
  function holds(callback) {
2730
2916
  const outcome = attempt(callback);
2731
- return outcome.success && outcome.value === true;
2917
+ return isSuccess(outcome) && outcome.value === true;
2732
2918
  }
2733
2919
  /**
2734
2920
  * Determines whether a value carries the plain-record brand, raising a hostile
@@ -2934,7 +3120,7 @@ function readGuardShape(shape, optional, reader) {
2934
3120
  if (optional === true) return collectMembers(declared.names);
2935
3121
  if (!INTRINSICS.array(optional)) return collectMembers([]);
2936
3122
  const entries = readArrayEntries(optional);
2937
- if (!entries.success) throw entries.error;
3123
+ if (isFailure(entries)) throw entries.error;
2938
3124
  if (!entries.value.dense) throw new INTRINSICS.error("Optional key list must be dense");
2939
3125
  return collectMembers(INTRINSICS.from(iterateIndices(() => entries.value.entries.length), (index) => INTRINSICS.text(entries.value.entries[index])));
2940
3126
  }, reader, { subject: "optional" });
@@ -2965,7 +3151,7 @@ function readGuardShape(shape, optional, reader) {
2965
3151
  */
2966
3152
  function enumerableKeys(value) {
2967
3153
  const outcome = attempt(() => INTRINSICS.freeze(INTRINSICS.keys(value)));
2968
- return outcome.success ? outcome.value : void 0;
3154
+ return isSuccess(outcome) ? outcome.value : void 0;
2969
3155
  }
2970
3156
  /**
2971
3157
  * Validates and snapshots a shape-builder options record through every reflective
@@ -3062,7 +3248,7 @@ function readOptions(source, keys, builder, shape) {
3062
3248
  function drawRandom(random, shape) {
3063
3249
  return contain(() => {
3064
3250
  const outcome = attempt(random);
3065
- if (!outcome.success) throw new ContractError("drawRandom: the random source threw", {
3251
+ if (isFailure(outcome)) throw new ContractError("drawRandom: the random source threw", {
3066
3252
  code: "random",
3067
3253
  context: {
3068
3254
  shape,
@@ -3120,7 +3306,7 @@ function resolveField(record, path) {
3120
3306
  return INTRINSICS.reflect.read(current, key);
3121
3307
  }, record]);
3122
3308
  });
3123
- return outcome.success ? outcome.value : void 0;
3309
+ return isSuccess(outcome) ? outcome.value : void 0;
3124
3310
  }
3125
3311
  /**
3126
3312
  * Determines whether a readable value stays within the fixed JSON container-depth limit.
@@ -3183,7 +3369,7 @@ function matchesJSONDepth(value) {
3183
3369
  };
3184
3370
  if (array) {
3185
3371
  const snapshot = readArrayEntries(entry);
3186
- if (!snapshot.success) return false;
3372
+ if (isFailure(snapshot)) return false;
3187
3373
  const children = INTRINSICS.values(snapshot.value.entries);
3188
3374
  for (const index of iterateIndices(() => children.length)) stack[stack.length] = {
3189
3375
  operation: "enter",
@@ -3266,7 +3452,7 @@ function matchesJSONValue(entry, ancestors) {
3266
3452
  if (matchesVisited(ancestors, node)) return false;
3267
3453
  if (matchesVisited(proved, node)) continue;
3268
3454
  const snapshot = readArrayEntries(node);
3269
- if (!snapshot.success) throw snapshot.error;
3455
+ if (isFailure(snapshot)) throw snapshot.error;
3270
3456
  if (!snapshot.value.dense) return false;
3271
3457
  admitVisited(ancestors, node);
3272
3458
  stack[stack.length] = {
@@ -3501,7 +3687,7 @@ function canonicalStringify(value) {
3501
3687
  if (matchesVisited(ancestors, container)) return void 0;
3502
3688
  if (INTRINSICS.reflect.apply(INTRINSICS.recall, encodings, [container]) !== void 0) continue;
3503
3689
  const snapshot = isArray(container) ? readArrayEntries(container) : void 0;
3504
- if (snapshot !== void 0 && !snapshot.success) throw snapshot.error;
3690
+ if (snapshot !== void 0 && isFailure(snapshot)) throw snapshot.error;
3505
3691
  if (snapshot !== void 0 && !snapshot.value.dense) return void 0;
3506
3692
  const keys = snapshot === void 0 ? sortValues(INTRINSICS.keys(container)) : void 0;
3507
3693
  const members = snapshot === void 0 ? INTRINSICS.from(iterateIndices(() => keys?.length ?? 0), (index) => {
@@ -3574,7 +3760,7 @@ function matchesISOInstant(value) {
3574
3760
  const date = new INTRINSICS.date(value);
3575
3761
  return !INTRINSICS.nan(INTRINSICS.reflect.apply(INTRINSICS.instant, date, []));
3576
3762
  });
3577
- return outcome.success && outcome.value;
3763
+ return isSuccess(outcome) && outcome.value;
3578
3764
  }
3579
3765
  /**
3580
3766
  * Classifies an already-bounded string against the pattern-only and
@@ -4261,25 +4447,22 @@ var JSONCloner = class JSONCloner {
4261
4447
  clone() {
4262
4448
  const terminal = this.#terminal;
4263
4449
  if (terminal !== void 0) {
4264
- if (terminal.success) return terminal.value;
4450
+ if (isSuccess(terminal)) return terminal.value;
4265
4451
  throw terminal.error;
4266
4452
  }
4267
4453
  const poison = this.#poison;
4268
4454
  if (poison !== void 0) {
4269
- this.#terminal = {
4270
- success: false,
4271
- error: poison
4272
- };
4455
+ this.#terminal = failure(poison);
4273
4456
  throw poison;
4274
4457
  }
4275
4458
  this.#poison = this.#create("JSONCloner.clone: JSON cloning may not be reentered");
4276
4459
  const outcome = attempt(() => this.#execute());
4277
4460
  const interruption = this.#terminal;
4278
4461
  if (interruption !== void 0) {
4279
- if (interruption.success) return interruption.value;
4462
+ if (isSuccess(interruption)) return interruption.value;
4280
4463
  this.#fail(interruption.error);
4281
4464
  }
4282
- if (outcome.success) {
4465
+ if (isSuccess(outcome)) {
4283
4466
  this.#terminal = outcome;
4284
4467
  return outcome.value;
4285
4468
  }
@@ -4287,10 +4470,7 @@ var JSONCloner = class JSONCloner {
4287
4470
  this.#fail(error);
4288
4471
  }
4289
4472
  #fail(error) {
4290
- this.#terminal = {
4291
- success: false,
4292
- error
4293
- };
4473
+ this.#terminal = failure(error);
4294
4474
  this.#pending = JSONCloner.#emptyPending;
4295
4475
  throw error;
4296
4476
  }
@@ -4335,7 +4515,7 @@ var JSONCloner = class JSONCloner {
4335
4515
  #captureObject(source) {
4336
4516
  if (matchesVisited(this.#active, source)) this.#refuse("cloneJSONValue: cycle detected");
4337
4517
  const arrayOutcome = attempt(() => INTRINSICS.array(source));
4338
- if (!arrayOutcome.success) this.#refuse("cloneJSONValue: value brand could not be inspected");
4518
+ if (isFailure(arrayOutcome)) this.#refuse("cloneJSONValue: value brand could not be inspected");
4339
4519
  if (arrayOutcome.value) return this.#schedule(source, true);
4340
4520
  if (isRecord(source)) return this.#schedule(source, false);
4341
4521
  this.#refuse("cloneJSONValue: object is not a plain record");
@@ -4354,9 +4534,9 @@ var JSONCloner = class JSONCloner {
4354
4534
  }
4355
4535
  #captureArray(source) {
4356
4536
  const keysOutcome = attempt(() => INTRINSICS.reflect.members(source));
4357
- if (!keysOutcome.success) this.#refuse("cloneJSONValue: own keys could not be inspected");
4537
+ if (isFailure(keysOutcome)) this.#refuse("cloneJSONValue: own keys could not be inspected");
4358
4538
  const lengthOutcome = attempt(() => INTRINSICS.reflect.describe(source, "length"));
4359
- if (!lengthOutcome.success) this.#refuse("cloneJSONValue: array length could not be inspected");
4539
+ if (isFailure(lengthOutcome)) this.#refuse("cloneJSONValue: array length could not be inspected");
4360
4540
  const lengthDescriptor = lengthOutcome.value;
4361
4541
  if (lengthDescriptor === void 0 || !("value" in lengthDescriptor) || typeof lengthDescriptor.value !== "number" || !INTRINSICS.integer(lengthDescriptor.value) || lengthDescriptor.value < 0 || lengthDescriptor.value > 4294967295 || lengthDescriptor.enumerable !== false || lengthDescriptor.configurable !== false) this.#refuse("cloneJSONValue: array is not intrinsic and dense");
4362
4542
  const owned = collectMembers(keysOutcome.value);
@@ -4366,7 +4546,7 @@ var JSONCloner = class JSONCloner {
4366
4546
  const key = INTRINSICS.text(index);
4367
4547
  if (!matchesMember(owned, key)) this.#refuse("cloneJSONValue: array own keys are not exact");
4368
4548
  const descriptorOutcome = attempt(() => INTRINSICS.reflect.describe(source, key));
4369
- if (!descriptorOutcome.success) this.#refuse("cloneJSONValue: array index could not be inspected");
4549
+ if (isFailure(descriptorOutcome)) this.#refuse("cloneJSONValue: array index could not be inspected");
4370
4550
  const descriptor = descriptorOutcome.value;
4371
4551
  if (descriptor === void 0 || !("value" in descriptor) || descriptor.enumerable !== true) this.#refuse("cloneJSONValue: array index is not enumerable data");
4372
4552
  return [key, descriptor.value];
@@ -4374,13 +4554,13 @@ var JSONCloner = class JSONCloner {
4374
4554
  }
4375
4555
  #captureRecord(source) {
4376
4556
  const keysOutcome = attempt(() => INTRINSICS.reflect.members(source));
4377
- if (!keysOutcome.success) this.#refuse("cloneJSONValue: own keys could not be inspected");
4557
+ if (isFailure(keysOutcome)) this.#refuse("cloneJSONValue: own keys could not be inspected");
4378
4558
  const names = keysOutcome.value;
4379
4559
  return INTRINSICS.from(iterateIndices(() => names.length), (index) => {
4380
4560
  const key = names[index];
4381
4561
  if (typeof key !== "string") this.#refuse("cloneJSONValue: record has a symbol property");
4382
4562
  const descriptorOutcome = attempt(() => INTRINSICS.reflect.describe(source, key));
4383
- if (!descriptorOutcome.success) this.#refuse("cloneJSONValue: record property could not be inspected");
4563
+ if (isFailure(descriptorOutcome)) this.#refuse("cloneJSONValue: record property could not be inspected");
4384
4564
  const descriptor = descriptorOutcome.value;
4385
4565
  if (descriptor === void 0 || !("value" in descriptor) || descriptor.enumerable !== true) this.#refuse("cloneJSONValue: record property is not enumerable data");
4386
4566
  return [key, descriptor.value];
@@ -4399,7 +4579,7 @@ var JSONCloner = class JSONCloner {
4399
4579
  }
4400
4580
  #refuse(message) {
4401
4581
  const terminal = this.#terminal;
4402
- if (terminal !== void 0 && !terminal.success) throw terminal.error;
4582
+ if (terminal !== void 0 && isFailure(terminal)) throw terminal.error;
4403
4583
  throw this.#create(message);
4404
4584
  }
4405
4585
  static {
@@ -4458,7 +4638,7 @@ var SchemaCloner = class SchemaCloner {
4458
4638
  const state = this.#state;
4459
4639
  switch (state.phase) {
4460
4640
  case "settled":
4461
- if (state.result.success) return state.result.value;
4641
+ if (isSuccess(state.result)) return state.result.value;
4462
4642
  throw state.result.error;
4463
4643
  case "running":
4464
4644
  case "interrupted":
@@ -4477,16 +4657,10 @@ var SchemaCloner = class SchemaCloner {
4477
4657
  }
4478
4658
  #complete(outcome) {
4479
4659
  const state = this.#state;
4480
- if (state.phase === "interrupted") return this.#settle({
4481
- success: false,
4482
- error: state.poison
4483
- });
4484
- if (outcome.success) return this.#settle(outcome);
4660
+ if (state.phase === "interrupted") return this.#settle(failure(state.poison));
4661
+ if (isSuccess(outcome)) return this.#settle(outcome);
4485
4662
  const error = this.#owns(outcome.error) ? outcome.error : this.#create("cloneSchema: failed to create an owned schema snapshot", { cause: outcome.error });
4486
- return this.#settle({
4487
- success: false,
4488
- error
4489
- });
4663
+ return this.#settle(failure(error));
4490
4664
  }
4491
4665
  #execute() {
4492
4666
  if (INTRINSICS.array(this.#source)) this.#refuse("cloneSchema: a schema root must be a record, not an array", "structure", []);
@@ -4548,7 +4722,7 @@ var SchemaCloner = class SchemaCloner {
4548
4722
  }
4549
4723
  #read(source, key, path) {
4550
4724
  const outcome = attempt(() => INTRINSICS.reflect.read(source, key));
4551
- if (outcome.success) return outcome.value;
4725
+ if (isSuccess(outcome)) return outcome.value;
4552
4726
  throw this.#create("cloneSchema: property access failed", {
4553
4727
  path,
4554
4728
  cause: outcome.error
@@ -4599,7 +4773,7 @@ var SchemaCloner = class SchemaCloner {
4599
4773
  phase: "settled",
4600
4774
  result
4601
4775
  };
4602
- if (result.success) return result.value;
4776
+ if (isSuccess(result)) return result.value;
4603
4777
  throw result.error;
4604
4778
  }
4605
4779
  static {
@@ -4649,7 +4823,7 @@ var ShapePass = class ShapePass {
4649
4823
  validate() {
4650
4824
  const outcome = attempt(() => this.#execute());
4651
4825
  if (this.#poison !== void 0) throw this.#poison;
4652
- if (outcome.success) return this.#counts[0] ?? 1;
4826
+ if (isSuccess(outcome)) return this.#counts[0] ?? 1;
4653
4827
  if (isContractError(outcome.error)) throw outcome.error;
4654
4828
  throw new ContractError("validateShape: shape reflection failed", {
4655
4829
  code: "structure",
@@ -4708,7 +4882,7 @@ var ShapePass = class ShapePass {
4708
4882
  this.#category = void 0;
4709
4883
  this.#raw = 0;
4710
4884
  const outcome = attempt(() => this.#observe(current, frame.depth));
4711
- if (!outcome.success || !outcome.value) {
4885
+ if (isFailure(outcome) || !outcome.value) {
4712
4886
  this.#structure ??= new ContractError("validateShape: every node must be a recognized shape", {
4713
4887
  code: "structure",
4714
4888
  context: { path: pathOf(this.#path) }
@@ -4732,23 +4906,23 @@ var ShapePass = class ShapePass {
4732
4906
  if (category === "raw") {
4733
4907
  const schema = current.schema;
4734
4908
  const outcome = attempt(() => this.#inspect(schema));
4735
- if (!outcome.success) return this.#refuse("validateShape: every node must be a recognized shape", "schema");
4909
+ if (isFailure(outcome)) return this.#refuse("validateShape: every node must be a recognized shape", "schema");
4736
4910
  if (!outcome.value) return false;
4737
4911
  if (depth + this.#raw > 512) return this.#refuse("validateShape: raw schema exceeds the compilation depth limit", "schema");
4738
4912
  }
4739
4913
  if (category === "object") {
4740
4914
  const outcome = attempt(() => this.#populate(current));
4741
- if (!outcome.success) return this.#refuse("validateShape: every node must be a recognized shape", "properties");
4915
+ if (isFailure(outcome)) return this.#refuse("validateShape: every node must be a recognized shape", "properties");
4742
4916
  return outcome.value;
4743
4917
  }
4744
4918
  if (category === "union") {
4745
4919
  const outcome = attempt(() => this.#populate(current));
4746
- if (!outcome.success) return this.#refuse("validateShape: every node must be a recognized shape", "variants");
4920
+ if (isFailure(outcome)) return this.#refuse("validateShape: every node must be a recognized shape", "variants");
4747
4921
  return outcome.value;
4748
4922
  }
4749
4923
  if (category === "literal") {
4750
4924
  const outcome = attempt(() => this.#populate(current));
4751
- if (!outcome.success) return this.#refuse("validateShape: every node must be a recognized shape", "values");
4925
+ if (isFailure(outcome)) return this.#refuse("validateShape: every node must be a recognized shape", "values");
4752
4926
  return outcome.value;
4753
4927
  }
4754
4928
  return this.#populate(current);
@@ -4808,7 +4982,7 @@ var ShapePass = class ShapePass {
4808
4982
  }
4809
4983
  return field === "pattern" && isRegExp(first) && isRegExp(second) && readPatternSource(first) === readPatternSource(second) && readPatternFlags(first) === readPatternFlags(second) && INTRINSICS.frozen(first) && INTRINSICS.frozen(second);
4810
4984
  });
4811
- if (!outcome.success || !outcome.value) return this.#refuse("validateShape: every node must be a recognized shape", field);
4985
+ if (isFailure(outcome) || !outcome.value) return this.#refuse("validateShape: every node must be a recognized shape", field);
4812
4986
  }
4813
4987
  return true;
4814
4988
  }
@@ -4974,7 +5148,7 @@ var ShapePass = class ShapePass {
4974
5148
  if (schema.format !== void 0 && typeof schema.format !== "string") return this.#refuse("validateShape: raw schema format must be a string", "schema");
4975
5149
  if (schema.pattern !== void 0) {
4976
5150
  if (typeof schema.pattern !== "string") return this.#refuse("validateShape: raw schema pattern must be a string", "schema");
4977
- if (!attempt(() => INTRINSICS.reflect.apply(INTRINSICS.pattern, void 0, [schema.pattern])).success) return this.#refuse("validateShape: raw schema pattern must be valid", "schema");
5151
+ if (isFailure(attempt(() => INTRINSICS.reflect.apply(INTRINSICS.pattern, void 0, [schema.pattern])))) return this.#refuse("validateShape: raw schema pattern must be valid", "schema");
4978
5152
  }
4979
5153
  const lengthList = [
4980
5154
  "minLength",
@@ -4999,7 +5173,7 @@ var ShapePass = class ShapePass {
4999
5173
  if (population !== void 0) {
5000
5174
  if (!INTRINSICS.array(population)) return this.#refuse("validateShape: raw schema enum must be a non-empty array", "schema");
5001
5175
  const snapshot = readArrayEntries(population);
5002
- if (!snapshot.success || snapshot.value.entries.length === 0) return this.#refuse("validateShape: raw schema enum must be a non-empty array", "schema");
5176
+ if (isFailure(snapshot) || snapshot.value.entries.length === 0) return this.#refuse("validateShape: raw schema enum must be a non-empty array", "schema");
5003
5177
  if (!snapshot.value.dense) return this.#refuse("validateShape: raw schema enum must be dense", "schema");
5004
5178
  const values = collectMembers([]);
5005
5179
  for (const valueIndex of iterateIndices(() => snapshot.value.entries.length)) {
@@ -5012,7 +5186,7 @@ var ShapePass = class ShapePass {
5012
5186
  if (names !== void 0) {
5013
5187
  if (!INTRINSICS.array(names)) return this.#refuse("validateShape: raw schema required must be an array", "schema");
5014
5188
  const snapshot = readArrayEntries(names);
5015
- if (!snapshot.success) return this.#refuse("validateShape: raw schema required must be an array", "schema");
5189
+ if (isFailure(snapshot)) return this.#refuse("validateShape: raw schema required must be an array", "schema");
5016
5190
  if (!snapshot.value.dense) return this.#refuse("validateShape: raw schema required must be dense", "schema");
5017
5191
  const required = collectMembers([]);
5018
5192
  for (const valueIndex of iterateIndices(() => snapshot.value.entries.length)) {
@@ -5042,7 +5216,7 @@ var ShapePass = class ShapePass {
5042
5216
  if (variants === void 0) continue;
5043
5217
  if (!INTRINSICS.array(variants)) return this.#refuse("validateShape: raw schema unions must be non-empty arrays", "schema");
5044
5218
  const snapshot = readArrayEntries(variants);
5045
- if (!snapshot.success || snapshot.value.entries.length === 0) return this.#refuse("validateShape: raw schema unions must be non-empty arrays", "schema");
5219
+ if (isFailure(snapshot) || snapshot.value.entries.length === 0) return this.#refuse("validateShape: raw schema unions must be non-empty arrays", "schema");
5046
5220
  if (!snapshot.value.dense) return this.#refuse("validateShape: raw schema unions must be dense arrays", "schema");
5047
5221
  for (const variantIndex of iterateIndices(() => snapshot.value.entries.length)) nested[nested.length] = snapshot.value.entries[variantIndex];
5048
5222
  }
@@ -5086,7 +5260,7 @@ var ShapePass = class ShapePass {
5086
5260
  const key = keys[keyIndex];
5087
5261
  if (key === void 0) continue;
5088
5262
  const descriptorOutcome = attempt(() => INTRINSICS.describe(properties, key));
5089
- if (!descriptorOutcome.success) return this.#refuse("validateShape: every node must be a recognized shape", "properties", key);
5263
+ if (isFailure(descriptorOutcome)) return this.#refuse("validateShape: every node must be a recognized shape", "properties", key);
5090
5264
  const descriptor = descriptorOutcome.value;
5091
5265
  if (descriptor === void 0 || !INTRINSICS.own(descriptor, "value")) {
5092
5266
  this.#children[this.#children.length] = {
@@ -5098,10 +5272,10 @@ var ShapePass = class ShapePass {
5098
5272
  continue;
5099
5273
  }
5100
5274
  const childOutcome = attempt(() => current.properties[key]);
5101
- if (!childOutcome.success) return this.#refuse("validateShape: every node must be a recognized shape", "properties", key);
5275
+ if (isFailure(childOutcome)) return this.#refuse("validateShape: every node must be a recognized shape", "properties", key);
5102
5276
  const child = childOutcome.value;
5103
5277
  const stable = attempt(() => INTRINSICS.same(current.properties[key], child) && INTRINSICS.same(descriptor.value, child));
5104
- if (!stable.success) return this.#refuse("validateShape: every node must be a recognized shape", "properties", key);
5278
+ if (isFailure(stable)) return this.#refuse("validateShape: every node must be a recognized shape", "properties", key);
5105
5279
  if (!stable.value) {
5106
5280
  this.#children[this.#children.length] = {
5107
5281
  shape: void 0,
@@ -5129,7 +5303,7 @@ var ShapePass = class ShapePass {
5129
5303
  case "union": {
5130
5304
  if (!INTRINSICS.array(current.variants)) return this.#refuse("validateShape: variants must be a finite array", "variants");
5131
5305
  const snapshot = readArrayEntries(current.variants);
5132
- if (!snapshot.success) return this.#refuse("validateShape: variants must be a finite array", "variants");
5306
+ if (isFailure(snapshot)) return this.#refuse("validateShape: variants must be a finite array", "variants");
5133
5307
  if (!snapshot.value.dense) return this.#refuse("validateShape: variants must be a dense data array", "variants");
5134
5308
  const variants = snapshot.value.entries;
5135
5309
  const length = variants.length;
@@ -5143,7 +5317,7 @@ var ShapePass = class ShapePass {
5143
5317
  for (const index of iterateIndices(() => length)) {
5144
5318
  const key = INTRINSICS.text(index);
5145
5319
  const descriptorOutcome = attempt(() => INTRINSICS.describe(current.variants, key));
5146
- if (!descriptorOutcome.success) return this.#refuse("validateShape: every node must be a recognized shape", "variants", key);
5320
+ if (isFailure(descriptorOutcome)) return this.#refuse("validateShape: every node must be a recognized shape", "variants", key);
5147
5321
  const descriptor = descriptorOutcome.value;
5148
5322
  if (descriptor === void 0 || !INTRINSICS.own(descriptor, "value")) {
5149
5323
  this.#children[this.#children.length] = {
@@ -5156,7 +5330,7 @@ var ShapePass = class ShapePass {
5156
5330
  }
5157
5331
  const variant = variants[index];
5158
5332
  const stable = attempt(() => INTRINSICS.same(current.variants[index], variant) && INTRINSICS.same(descriptor.value, variant));
5159
- if (!stable.success) return this.#refuse("validateShape: every node must be a recognized shape", "variants", key);
5333
+ if (isFailure(stable)) return this.#refuse("validateShape: every node must be a recognized shape", "variants", key);
5160
5334
  if (!stable.value) {
5161
5335
  this.#children[this.#children.length] = {
5162
5336
  shape: void 0,
@@ -5178,7 +5352,7 @@ var ShapePass = class ShapePass {
5178
5352
  case "literal": {
5179
5353
  if (!INTRINSICS.array(current.values)) return this.#refuse("validateShape: values must be a finite literal array", "values");
5180
5354
  const snapshot = readArrayEntries(current.values);
5181
- if (!snapshot.success) return this.#refuse("validateShape: values must be a finite literal array", "values");
5355
+ if (isFailure(snapshot)) return this.#refuse("validateShape: values must be a finite literal array", "values");
5182
5356
  if (!snapshot.value.dense) return this.#refuse("validateShape: values must be a dense data array", "values");
5183
5357
  const literals = snapshot.value.entries;
5184
5358
  const length = literals.length;
@@ -5193,12 +5367,12 @@ var ShapePass = class ShapePass {
5193
5367
  for (const index of iterateIndices(() => length)) {
5194
5368
  const key = INTRINSICS.text(index);
5195
5369
  const descriptorOutcome = attempt(() => INTRINSICS.describe(current.values, key));
5196
- if (!descriptorOutcome.success) return this.#refuse("validateShape: every node must be a recognized shape", "values", key);
5370
+ if (isFailure(descriptorOutcome)) return this.#refuse("validateShape: every node must be a recognized shape", "values", key);
5197
5371
  const descriptor = descriptorOutcome.value;
5198
5372
  if (descriptor === void 0 || !INTRINSICS.own(descriptor, "value")) return this.#refuse("validateShape: values must be a dense data array", "values", key);
5199
5373
  const value = literals[index];
5200
5374
  const stable = attempt(() => INTRINSICS.same(current.values[index], value) && INTRINSICS.same(descriptor.value, value));
5201
- if (!stable.success) return this.#refuse("validateShape: every node must be a recognized shape", "values", key);
5375
+ if (isFailure(stable)) return this.#refuse("validateShape: every node must be a recognized shape", "values", key);
5202
5376
  if (!stable.value) return this.#refuse("validateShape: values must be a stable data array", "values", key);
5203
5377
  if (!isLiteralValue(value)) return this.#refuse("validateShape: every literal value must be a string, number, or boolean", "values", key);
5204
5378
  if (matchesMember(values, value)) return this.#refuse("validateShape: literal values must be unique", "values", key);
@@ -5564,7 +5738,7 @@ var ShapeCloner = class ShapeCloner {
5564
5738
  clone() {
5565
5739
  const state = this.#state;
5566
5740
  if (state.phase === "settled") {
5567
- if (state.result.success) return state.result.value;
5741
+ if (isSuccess(state.result)) return state.result.value;
5568
5742
  throw state.result.error;
5569
5743
  }
5570
5744
  if (state.phase === "running" || state.phase === "interrupted") {
@@ -5586,20 +5760,14 @@ var ShapeCloner = class ShapeCloner {
5586
5760
  }
5587
5761
  #complete(outcome) {
5588
5762
  const state = this.#state;
5589
- if (state.phase === "interrupted") return this.#settle({
5590
- success: false,
5591
- error: state.poison
5592
- });
5593
- if (outcome.success) return this.#settle(outcome);
5763
+ if (state.phase === "interrupted") return this.#settle(failure(state.poison));
5764
+ if (isSuccess(outcome)) return this.#settle(outcome);
5594
5765
  const error = this.#owns(outcome.error) ? outcome.error : this.#create("cloneShape: failed to create an owned shape snapshot", {
5595
5766
  code: "clone",
5596
5767
  context: { shape: "shape" },
5597
5768
  cause: outcome.error
5598
5769
  });
5599
- return this.#settle({
5600
- success: false,
5601
- error
5602
- });
5770
+ return this.#settle(failure(error));
5603
5771
  }
5604
5772
  #execute() {
5605
5773
  const paths = this.#paths;
@@ -5747,7 +5915,7 @@ var ShapeCloner = class ShapeCloner {
5747
5915
  source: readPatternSource(pattern)
5748
5916
  };
5749
5917
  });
5750
- if (typeof sourceText !== "string" || typeof flags !== "string" || !repeated.success || typeof repeated.value.source !== "string" || typeof repeated.value.flags !== "string" || repeated.value.source !== sourceText || repeated.value.flags !== flags) {
5918
+ if (typeof sourceText !== "string" || typeof flags !== "string" || isFailure(repeated) || typeof repeated.value.source !== "string" || typeof repeated.value.flags !== "string" || repeated.value.source !== sourceText || repeated.value.flags !== flags) {
5751
5919
  this.#fidelity ??= this.#create("validateShape: string pattern must be stable", {
5752
5920
  code: "structure",
5753
5921
  context: { path: pathOf(path, "pattern") }
@@ -5897,7 +6065,7 @@ var ShapeCloner = class ShapeCloner {
5897
6065
  schema
5898
6066
  });
5899
6067
  const outcome = attempt(() => new SchemaCloner(schema).clone());
5900
- if (!outcome.success) {
6068
+ if (isFailure(outcome)) {
5901
6069
  if (isContractError(outcome.error)) admitVisited(this.#owned, outcome.error);
5902
6070
  throw outcome.error;
5903
6071
  }
@@ -5912,7 +6080,7 @@ var ShapeCloner = class ShapeCloner {
5912
6080
  context: { path: pathOf(path, "values") }
5913
6081
  });
5914
6082
  const snapshot = readArrayEntries(values);
5915
- if (!snapshot.success) throw this.#create("validateShape: values must be a finite literal array", {
6083
+ if (isFailure(snapshot)) throw this.#create("validateShape: values must be a finite literal array", {
5916
6084
  code: "structure",
5917
6085
  context: { path: pathOf(path, "values") }
5918
6086
  });
@@ -5927,11 +6095,11 @@ var ShapeCloner = class ShapeCloner {
5927
6095
  const key = INTRINSICS.text(index);
5928
6096
  const descriptor = attempt(() => INTRINSICS.describe(values, key));
5929
6097
  const repeated = attempt(() => values[index]);
5930
- if (!descriptor.success || descriptor.value === void 0 || !INTRINSICS.own(descriptor.value, "value")) this.#fidelity ??= this.#create("validateShape: values must be a dense data array", {
6098
+ if (isFailure(descriptor) || descriptor.value === void 0 || !INTRINSICS.own(descriptor.value, "value")) this.#fidelity ??= this.#create("validateShape: values must be a dense data array", {
5931
6099
  code: "structure",
5932
6100
  context: { path: pathOf(path, "values", key) }
5933
6101
  });
5934
- else if (!repeated.success || !INTRINSICS.same(repeated.value, value) || !INTRINSICS.same(descriptor.value.value, value)) this.#fidelity ??= this.#create("validateShape: values must be a stable data array", {
6102
+ else if (isFailure(repeated) || !INTRINSICS.same(repeated.value, value) || !INTRINSICS.same(descriptor.value.value, value)) this.#fidelity ??= this.#create("validateShape: values must be a stable data array", {
5935
6103
  code: "structure",
5936
6104
  context: { path: pathOf(path, "values", key) }
5937
6105
  });
@@ -5976,7 +6144,7 @@ var ShapeCloner = class ShapeCloner {
5976
6144
  context: { path: pathOf(path, "variants") }
5977
6145
  });
5978
6146
  const snapshot = readArrayEntries(variants);
5979
- if (!snapshot.success) throw this.#create("validateShape: variants must be a finite array", {
6147
+ if (isFailure(snapshot)) throw this.#create("validateShape: variants must be a finite array", {
5980
6148
  code: "structure",
5981
6149
  context: { path: pathOf(path, "variants") }
5982
6150
  });
@@ -5993,7 +6161,7 @@ var ShapeCloner = class ShapeCloner {
5993
6161
  const key = INTRINSICS.text(index);
5994
6162
  const descriptor = attempt(() => INTRINSICS.describe(variants, key));
5995
6163
  const repeated = attempt(() => variants[index]);
5996
- if (!descriptor.success || descriptor.value === void 0 || !INTRINSICS.own(descriptor.value, "value") || !repeated.success || !INTRINSICS.same(repeated.value, variant) || !INTRINSICS.same(descriptor.value.value, variant)) this.#fidelity ??= this.#create("validateShape: every structural child must be a shape", {
6164
+ if (isFailure(descriptor) || descriptor.value === void 0 || !INTRINSICS.own(descriptor.value, "value") || isFailure(repeated) || !INTRINSICS.same(repeated.value, variant) || !INTRINSICS.same(descriptor.value.value, variant)) this.#fidelity ??= this.#create("validateShape: every structural child must be a shape", {
5997
6165
  code: "structure",
5998
6166
  context: { path: pathOf(path, "variants", key) }
5999
6167
  });
@@ -6170,7 +6338,7 @@ var ShapeCloner = class ShapeCloner {
6170
6338
  }
6171
6339
  #validateShape(shape) {
6172
6340
  const outcome = attempt(() => new ShapeValidator(shape).validate());
6173
- if (outcome.success) return;
6341
+ if (isSuccess(outcome)) return;
6174
6342
  if (isContractError(outcome.error)) admitVisited(this.#owned, outcome.error);
6175
6343
  throw outcome.error;
6176
6344
  }
@@ -6200,7 +6368,7 @@ var ShapeCloner = class ShapeCloner {
6200
6368
  phase: "settled",
6201
6369
  result
6202
6370
  };
6203
- if (result.success) return result.value;
6371
+ if (isSuccess(result)) return result.value;
6204
6372
  throw result.error;
6205
6373
  }
6206
6374
  static {
@@ -6338,11 +6506,11 @@ function ownShape(shape) {
6338
6506
  return contain(() => {
6339
6507
  const frozen = holds(() => INTRINSICS.frozen(shape));
6340
6508
  const fidelity = attempt(() => cloneShape(shape));
6341
- if (fidelity.success) return fidelity.value;
6509
+ if (isSuccess(fidelity)) return fidelity.value;
6342
6510
  if (isContractError(fidelity.error) && fidelity.error.code !== "clone") throw fidelity.error;
6343
6511
  if (!frozen) throw fidelity.error;
6344
6512
  const validation = attempt(() => new ShapeValidator(shape).validate());
6345
- if (!validation.success && isContractError(validation.error)) throw validation.error;
6513
+ if (isFailure(validation) && isContractError(validation.error)) throw validation.error;
6346
6514
  throw fidelity.error;
6347
6515
  }, "ownShape");
6348
6516
  }
@@ -6370,7 +6538,7 @@ function arrayOf(elementGuard) {
6370
6538
  return (value) => holds(() => {
6371
6539
  if (!isArray(value)) return false;
6372
6540
  const entries = readArrayEntries(value);
6373
- if (!entries.success || !entries.value.dense) return false;
6541
+ if (isFailure(entries) || !entries.value.dense) return false;
6374
6542
  for (const index of iterateIndices(() => entries.value.entries.length)) if (!elementGuard(entries.value.entries[index])) return false;
6375
6543
  return true;
6376
6544
  });
@@ -6379,7 +6547,7 @@ function tupleOf(...guards) {
6379
6547
  return (value) => holds(() => {
6380
6548
  if (!isArray(value)) return false;
6381
6549
  const entries = readArrayEntries(value);
6382
- if (!entries.success || !entries.value.dense) return false;
6550
+ if (isFailure(entries) || !entries.value.dense) return false;
6383
6551
  if (entries.value.entries.length !== guards.length) return false;
6384
6552
  for (const index of iterateIndices(() => guards.length)) {
6385
6553
  const guard = guards[index];
@@ -6399,7 +6567,7 @@ function literalOf(...literals) {
6399
6567
  }
6400
6568
  }) : false) && isArray(first) ? readValue(() => {
6401
6569
  const entries = readArrayEntries(first);
6402
- if (!entries.success) throw entries.error;
6570
+ if (isFailure(entries)) throw entries.error;
6403
6571
  if (!entries.value.dense) throw new INTRINSICS.error("Literal vocabulary must be dense");
6404
6572
  return entries.value.entries;
6405
6573
  }, "literalOf", {
@@ -6481,7 +6649,7 @@ function setOf(elementGuard) {
6481
6649
  return (value) => holds(() => {
6482
6650
  if (!isSet(value)) return false;
6483
6651
  const entries = readSetEntries(value);
6484
- if (!entries.success) return false;
6652
+ if (isFailure(entries)) return false;
6485
6653
  for (const index of iterateIndices(() => entries.value.length)) if (!elementGuard(entries.value[index])) return false;
6486
6654
  return true;
6487
6655
  });
@@ -6490,7 +6658,7 @@ function mapOf(keyGuard, valueGuard) {
6490
6658
  return (value) => holds(() => {
6491
6659
  if (!isMap(value)) return false;
6492
6660
  const entries = readMapEntries(value);
6493
- if (!entries.success) return false;
6661
+ if (isFailure(entries)) return false;
6494
6662
  for (const index of iterateIndices(() => entries.value.length)) {
6495
6663
  const entry = entries.value[index];
6496
6664
  if (entry === void 0) return false;
@@ -6590,7 +6758,7 @@ function pickOf(shape, keys) {
6590
6758
  return contain(() => {
6591
6759
  const selected = readValue(() => {
6592
6760
  const entries = readArrayEntries(keys);
6593
- if (!entries.success) throw entries.error;
6761
+ if (isFailure(entries)) throw entries.error;
6594
6762
  if (!entries.value.dense) throw new INTRINSICS.error("Picked key list must be dense");
6595
6763
  return collectMembers(entries.value.entries);
6596
6764
  }, "pickOf", { subject: "keys" });
@@ -6629,7 +6797,7 @@ function omitOf(shape, keys) {
6629
6797
  return contain(() => {
6630
6798
  const skipped = readValue(() => {
6631
6799
  const entries = readArrayEntries(keys);
6632
- if (!entries.success) throw entries.error;
6800
+ if (isFailure(entries)) throw entries.error;
6633
6801
  if (!entries.value.dense) throw new INTRINSICS.error("Omitted key list must be dense");
6634
6802
  return collectMembers(entries.value.entries);
6635
6803
  }, "omitOf", { subject: "keys" });
@@ -6937,7 +7105,7 @@ function parseNumber(value) {
6937
7105
  const parsed = INTRINSICS.numeric(value);
6938
7106
  return INTRINSICS.finite(parsed) ? parsed : void 0;
6939
7107
  });
6940
- return outcome.success ? outcome.value : void 0;
7108
+ return isSuccess(outcome) ? outcome.value : void 0;
6941
7109
  }
6942
7110
  /**
6943
7111
  * Parses an unknown value to a finite integer.
@@ -7044,7 +7212,7 @@ function parseArray(value, guard) {
7044
7212
  if (!isArray(value)) return void 0;
7045
7213
  if (guard === void 0) return value;
7046
7214
  const entries = readArrayEntries(value);
7047
- if (!entries.success || !entries.value.dense) return void 0;
7215
+ if (isFailure(entries) || !entries.value.dense) return void 0;
7048
7216
  if (!holds(() => INTRINSICS.reflect.apply(INTRINSICS.find, entries.value.entries, [(entry) => !guard(entry)]) === -1)) return;
7049
7217
  return value;
7050
7218
  }
@@ -7077,7 +7245,7 @@ function parseJSONValue(value) {
7077
7245
  }
7078
7246
  function parseEnum(value, allowed) {
7079
7247
  const outcome = readArrayEntries(allowed);
7080
- if (!outcome.success || !outcome.value.dense) return void 0;
7248
+ if (isFailure(outcome) || !outcome.value.dense) return void 0;
7081
7249
  if (!holds(() => matchesMember(collectMembers(outcome.value.entries), value))) return void 0;
7082
7250
  return isLiteralValue(value) ? value : void 0;
7083
7251
  }
@@ -7285,7 +7453,7 @@ function parseJSONAs(value, guard) {
7285
7453
  const parsed = parseJSON(value);
7286
7454
  if (parsed === void 0) return void 0;
7287
7455
  const checked = attempt(() => guard(parsed) ? parsed : void 0);
7288
- return checked.success ? checked.value : void 0;
7456
+ return isSuccess(checked) ? checked.value : void 0;
7289
7457
  }
7290
7458
  // src/core/EvaluationScope.ts
7291
7459
  /** Owns compiled-node memo entries for one synchronous evaluation. */
@@ -7297,7 +7465,7 @@ var EvaluationScope = class EvaluationScope {
7297
7465
  static run(plan, value, path = EvaluationScope.#path, clean = false) {
7298
7466
  if (!isObject(value)) return plan(value, path);
7299
7467
  const entries = readSetEntries(EvaluationScope.#active);
7300
- if (!entries.success) throw entries.error;
7468
+ if (isFailure(entries)) throw entries.error;
7301
7469
  const active = entries.value[0];
7302
7470
  if (active instanceof EvaluationScope) return active.#evaluate(plan, value, path, clean);
7303
7471
  if (active !== void 0) throw new INTRINSICS.error("Evaluation scope is unavailable");
@@ -7559,7 +7727,7 @@ var ContractCompiler = class ContractCompiler {
7559
7727
  #leave(outcome) {
7560
7728
  const state = this.#state;
7561
7729
  if (state.phase === "interrupted") return this.#fail(state.poison);
7562
- if (!outcome.success) return this.#fail(isContractError(outcome.error) ? outcome.error : new ContractError("ContractCompiler: contract compilation failed", {
7730
+ if (isFailure(outcome)) return this.#fail(isContractError(outcome.error) ? outcome.error : new ContractError("ContractCompiler: contract compilation failed", {
7563
7731
  code: "structure",
7564
7732
  context: {
7565
7733
  path: [],
@@ -7945,7 +8113,7 @@ var ContractCompiler = class ContractCompiler {
7945
8113
  }
7946
8114
  return true;
7947
8115
  });
7948
- return outcome.success && outcome.value;
8116
+ return isSuccess(outcome) && outcome.value;
7949
8117
  };
7950
8118
  }
7951
8119
  case "union": {
@@ -8033,7 +8201,7 @@ var ContractCompiler = class ContractCompiler {
8033
8201
  });
8034
8202
  if (!isArray(value)) return void 0;
8035
8203
  const entries = readArrayEntries(value);
8036
- if (!entries.success) return readValue(() => {
8204
+ if (isFailure(entries)) return readValue(() => {
8037
8205
  throw entries.error;
8038
8206
  }, "compileParser", {
8039
8207
  subject: "array",
@@ -8109,7 +8277,7 @@ var ContractCompiler = class ContractCompiler {
8109
8277
  }
8110
8278
  return INTRINSICS.rebase(INTRINSICS.record({ [Symbol.iterator]: INTRINSICS.reflect.apply(INTRINSICS.bind, INTRINSICS.iterator, [selected]) }), null);
8111
8279
  });
8112
- if (outcome.success) return outcome.value;
8280
+ if (isSuccess(outcome)) return outcome.value;
8113
8281
  if (isContractError(outcome.error)) throw outcome.error;
8114
8282
  return readValue(() => {
8115
8283
  throw outcome.error;
@@ -8259,7 +8427,7 @@ var ContractCompiler = class ContractCompiler {
8259
8427
  received: preview(value)
8260
8428
  }];
8261
8429
  const entries = readArrayEntries(value);
8262
- if (!entries.success) return readValue(() => {
8430
+ if (isFailure(entries)) return readValue(() => {
8263
8431
  throw entries.error;
8264
8432
  }, "compileAuditor", {
8265
8433
  subject: "array",
@@ -8295,7 +8463,7 @@ var ContractCompiler = class ContractCompiler {
8295
8463
  const closed = extra === void 0 || extra === false;
8296
8464
  const additional = closed || extra === true ? void 0 : this.#auditAt(extra);
8297
8465
  const planned = attempt(() => collectMembers(declaredKeys));
8298
- const declared = planned.success ? planned.value : void 0;
8466
+ const declared = isSuccess(planned) ? planned.value : void 0;
8299
8467
  const maskable = entries.length <= 31;
8300
8468
  const positions = buildPositions(maskable ? INTRINSICS.reflect.apply(INTRINSICS.project, readIndexView(entries), [(entry) => entry.key]) : []);
8301
8469
  return (value, path) => {
@@ -8355,7 +8523,7 @@ var ContractCompiler = class ContractCompiler {
8355
8523
  if (additional !== void 0) appendEntries(faults, additional(observed, pathOf(path, key)));
8356
8524
  }
8357
8525
  });
8358
- if (!outcome.success) {
8526
+ if (isFailure(outcome)) {
8359
8527
  if (isContractError(outcome.error)) throw outcome.error;
8360
8528
  return readValue(() => {
8361
8529
  throw outcome.error;
@@ -8525,7 +8693,7 @@ var ContractCompiler = class ContractCompiler {
8525
8693
  received: preview(value)
8526
8694
  }];
8527
8695
  const entries = readArrayEntries(value);
8528
- if (!entries.success) return [{
8696
+ if (isFailure(entries)) return [{
8529
8697
  reason: "type",
8530
8698
  path,
8531
8699
  expected: "array",
@@ -8559,7 +8727,7 @@ var ContractCompiler = class ContractCompiler {
8559
8727
  const tail = extra === void 0 || extra === true || extra === false ? void 0 : this.#reportAt(extra);
8560
8728
  const open = extra === true || tail !== void 0;
8561
8729
  const planned = attempt(() => collectMembers(names));
8562
- const known = planned.success ? planned.value : void 0;
8730
+ const known = isSuccess(planned) ? planned.value : void 0;
8563
8731
  const maskable = entries.length <= 31;
8564
8732
  const positions = buildPositions(maskable ? INTRINSICS.reflect.apply(INTRINSICS.project, readIndexView(entries), [(entry) => entry.key]) : []);
8565
8733
  return (value, path) => {
@@ -8578,7 +8746,7 @@ var ContractCompiler = class ContractCompiler {
8578
8746
  received: preview(value)
8579
8747
  }];
8580
8748
  const faults = [];
8581
- if (!attempt(() => {
8749
+ if (isFailure(attempt(() => {
8582
8750
  const present = maskable ? void 0 : collectMembers(keys);
8583
8751
  const vocabulary = known ?? collectMembers(names);
8584
8752
  const seen = present === void 0 ? readPresence(keys, positions) : 0;
@@ -8613,7 +8781,7 @@ var ContractCompiler = class ContractCompiler {
8613
8781
  const observed = record[key];
8614
8782
  if (tail !== void 0) appendEntries(faults, tail(observed, pathOf(path, key)));
8615
8783
  }
8616
- }).success) return [{
8784
+ }))) return [{
8617
8785
  reason: "type",
8618
8786
  path,
8619
8787
  expected: "object",
@@ -8838,8 +9006,8 @@ var ContractCompiler = class ContractCompiler {
8838
9006
  const plan = plans[(start + attemptIndex) % count];
8839
9007
  if (plan === void 0) continue;
8840
9008
  const outcome = attempt(() => plan(random));
8841
- if (!outcome.success && isContractError(outcome.error) && outcome.error.code === "random") throw outcome.error;
8842
- if (outcome.success && guard(outcome.value)) return outcome.value;
9009
+ if (isFailure(outcome) && isContractError(outcome.error) && outcome.error.code === "random") throw outcome.error;
9010
+ if (isSuccess(outcome) && guard(outcome.value)) return outcome.value;
8843
9011
  }
8844
9012
  throw new ContractError("compileGenerator: no union candidate satisfied the compiled guard", {
8845
9013
  code: "generate",
@@ -9153,14 +9321,14 @@ var ValueInferer = class ValueInferer {
9153
9321
  admitVisited(this.#visited, value);
9154
9322
  const outcome = attempt(() => {
9155
9323
  const snapshot = readArrayEntries(value);
9156
- if (!snapshot.success) throw snapshot.error;
9324
+ if (isFailure(snapshot)) throw snapshot.error;
9157
9325
  if (!snapshot.value.dense) return void 0;
9158
9326
  const entries = snapshot.value.entries;
9159
9327
  const length = INTRINSICS.ceil(INTRINSICS.min(entries.length, this.#breadth));
9160
9328
  return INTRINSICS.from(iterateIndices(() => length), (index) => this.#infer(entries[index], depth - 1));
9161
9329
  });
9162
9330
  omitVisited(this.#visited, value);
9163
- if (!outcome.success) throw outcome.error;
9331
+ if (isFailure(outcome)) throw outcome.error;
9164
9332
  const sampled = outcome.value;
9165
9333
  const schema = sampled === void 0 ? {} : sampled.length > 0 ? {
9166
9334
  type: "array",
@@ -9204,7 +9372,7 @@ var ValueInferer = class ValueInferer {
9204
9372
  };
9205
9373
  });
9206
9374
  omitVisited(this.#visited, value);
9207
- if (!outcome.success) throw outcome.error;
9375
+ if (isFailure(outcome)) throw outcome.error;
9208
9376
  const { properties, required, partial } = outcome.value;
9209
9377
  const schema = {
9210
9378
  type: "object",
@@ -9331,7 +9499,7 @@ var SampleInferer = class {
9331
9499
  dropped: INTRINSICS.reflect.apply(INTRINSICS.some, observed, [(entry) => entry.dropped])
9332
9500
  };
9333
9501
  });
9334
- if (!valuesOutcome.success) throw valuesOutcome.error;
9502
+ if (isFailure(valuesOutcome)) throw valuesOutcome.error;
9335
9503
  const { values, dropped } = valuesOutcome.value;
9336
9504
  return {
9337
9505
  key,
@@ -9394,7 +9562,7 @@ function unifySchemas(schemas) {
9394
9562
  return contain(() => {
9395
9563
  return readValue(() => {
9396
9564
  const snapshot = readArrayEntries(schemas);
9397
- if (!snapshot.success) throw snapshot.error;
9565
+ if (isFailure(snapshot)) throw snapshot.error;
9398
9566
  if (!snapshot.value.dense) throw new INTRINSICS.error("unifySchemas: schemas must be dense");
9399
9567
  const owned = snapshot.value.entries;
9400
9568
  if (owned.length === 0) return {};
@@ -9452,7 +9620,7 @@ function stringToFormat(value) {
9452
9620
  if (!isString(value)) return void 0;
9453
9621
  if (value.length > 128) return void 0;
9454
9622
  const outcome = attempt(() => classifyFormat(value));
9455
- return outcome.success ? outcome.value : void 0;
9623
+ return isSuccess(outcome) ? outcome.value : void 0;
9456
9624
  }
9457
9625
  /**
9458
9626
  * Classifies a list of sample values against the {@link SchemaFormat}
@@ -9481,7 +9649,7 @@ function samplesToFormat(values) {
9481
9649
  return contain(() => {
9482
9650
  return readValue(() => {
9483
9651
  const snapshot = readArrayEntries(values);
9484
- if (!snapshot.success) throw snapshot.error;
9652
+ if (isFailure(snapshot)) throw snapshot.error;
9485
9653
  if (!snapshot.value.dense) throw new INTRINSICS.error("samplesToFormat: values must be dense");
9486
9654
  const owned = snapshot.value.entries;
9487
9655
  if (owned.length === 0) return void 0;
@@ -9532,7 +9700,7 @@ function inferPrimitiveEnum(values, limit) {
9532
9700
  return contain(() => {
9533
9701
  return readValue(() => {
9534
9702
  const snapshot = readArrayEntries(values);
9535
- if (!snapshot.success) throw snapshot.error;
9703
+ if (isFailure(snapshot)) throw snapshot.error;
9536
9704
  if (!snapshot.value.dense) throw new INTRINSICS.error("inferPrimitiveEnum: values must be dense");
9537
9705
  const owned = snapshot.value.entries;
9538
9706
  if (owned.length < 2) return void 0;
@@ -9662,7 +9830,7 @@ function samplesToSchema(samples, options) {
9662
9830
  const enumOn = optionsSnapshot?.enum ?? false;
9663
9831
  const read = readValue(() => {
9664
9832
  const snapshot = readArrayEntries(samples);
9665
- if (!snapshot.success) throw snapshot.error;
9833
+ if (isFailure(snapshot)) throw snapshot.error;
9666
9834
  return snapshot.value;
9667
9835
  }, "samplesToSchema", { subject: "samples" });
9668
9836
  if (!read.dense) throw new ContractError("samplesToSchema: samples must be a dense array", { code: "structure" });
@@ -10023,17 +10191,17 @@ function literalShape(values, options) {
10023
10191
  return contain(() => {
10024
10192
  const input = values;
10025
10193
  const array = attempt(() => INTRINSICS.array(input));
10026
- if (!array.success || !array.value) throw new ContractError("literalShape: values must be an array", {
10194
+ if (isFailure(array) || !array.value) throw new ContractError("literalShape: values must be an array", {
10027
10195
  code: "structure",
10028
10196
  context: {
10029
10197
  path: ["values"],
10030
10198
  shape: "literal"
10031
10199
  },
10032
- ...!array.success ? { cause: array.error } : {}
10200
+ ...isFailure(array) ? { cause: array.error } : {}
10033
10201
  });
10034
10202
  const safe = readOptions(options, ["description"], "literalShape", "literal");
10035
10203
  const snapshot = readArrayEntries(values);
10036
- if (!snapshot.success) throw new ContractError("literalShape: values could not be copied", {
10204
+ if (isFailure(snapshot)) throw new ContractError("literalShape: values could not be copied", {
10037
10205
  code: "structure",
10038
10206
  context: {
10039
10207
  path: ["values"],
@@ -10492,6 +10660,7 @@ function schemaToShape(schema) {
10492
10660
  });
10493
10661
  }, "schemaToShape");
10494
10662
  }
10663
+ exports.CHOICE_LIMIT = CHOICE_LIMIT;
10495
10664
  exports.CLONE_NODE_LIMIT = CLONE_NODE_LIMIT;
10496
10665
  exports.COMPILE_DEPTH_LIMIT = COMPILE_DEPTH_LIMIT;
10497
10666
  exports.COMPILE_NODE_LIMIT = COMPILE_NODE_LIMIT;
@@ -10510,11 +10679,15 @@ exports.INFER_ENUM_LIMIT = INFER_ENUM_LIMIT;
10510
10679
  exports.INTRINSICS = INTRINSICS;
10511
10680
  exports.JSONCloner = JSONCloner;
10512
10681
  exports.JSON_SCHEMA_TYPES = JSON_SCHEMA_TYPES;
10682
+ exports.NAME_LIMIT = NAME_LIMIT;
10683
+ exports.NODE_LIMIT = NODE_LIMIT;
10513
10684
  exports.PRESENCE_MASK_LIMIT = PRESENCE_MASK_LIMIT;
10514
10685
  exports.PREVIEW_LIMIT = PREVIEW_LIMIT;
10686
+ exports.STRING_LIMIT = STRING_LIMIT;
10515
10687
  exports.SchemaCloner = SchemaCloner;
10516
10688
  exports.ShapeCloner = ShapeCloner;
10517
10689
  exports.ShapeValidator = ShapeValidator;
10690
+ exports.TEXT_LIMIT = TEXT_LIMIT;
10518
10691
  exports.admitMember = admitMember;
10519
10692
  exports.admitVisited = admitVisited;
10520
10693
  exports.andOf = andOf;
@@ -10537,7 +10710,7 @@ exports.cloneSchema = cloneSchema;
10537
10710
  exports.cloneShape = cloneShape;
10538
10711
  exports.collectEntries = collectEntries;
10539
10712
  exports.collectMembers = collectMembers;
10540
- exports.compareValues = compareValues;
10713
+ exports.comparePrimitives = comparePrimitives;
10541
10714
  exports.compileAuditor = compileAuditor;
10542
10715
  exports.compileGenerator = compileGenerator;
10543
10716
  exports.compileGuard = compileGuard;
@@ -10555,6 +10728,9 @@ exports.encodeParts = encodeParts;
10555
10728
  exports.enumOf = enumOf;
10556
10729
  exports.enumerableKeys = enumerableKeys;
10557
10730
  exports.enumerableSymbolCount = enumerableSymbolCount;
10731
+ exports.errorToMessage = errorToMessage;
10732
+ exports.escapeRegExp = escapeRegExp;
10733
+ exports.failure = failure;
10558
10734
  exports.holds = holds;
10559
10735
  exports.inferPrimitiveEnum = inferPrimitiveEnum;
10560
10736
  exports.instanceOf = instanceOf;
@@ -10583,6 +10759,7 @@ exports.isEmptyObject = isEmptyObject;
10583
10759
  exports.isEmptySet = isEmptySet;
10584
10760
  exports.isEmptyString = isEmptyString;
10585
10761
  exports.isError = isError;
10762
+ exports.isFailure = isFailure;
10586
10763
  exports.isFalse = isFalse;
10587
10764
  exports.isFiniteNumber = isFiniteNumber;
10588
10765
  exports.isFloat32Array = isFloat32Array;
@@ -10619,6 +10796,7 @@ exports.isRegExp = isRegExp;
10619
10796
  exports.isSet = isSet;
10620
10797
  exports.isSharedArrayBuffer = isSharedArrayBuffer;
10621
10798
  exports.isString = isString;
10799
+ exports.isSuccess = isSuccess;
10622
10800
  exports.isSymbol = isSymbol;
10623
10801
  exports.isTrue = isTrue;
10624
10802
  exports.isUint16Array = isUint16Array;
@@ -10722,6 +10900,7 @@ exports.sortValues = sortValues;
10722
10900
  exports.stringOf = stringOf;
10723
10901
  exports.stringShape = stringShape;
10724
10902
  exports.stringToFormat = stringToFormat;
10903
+ exports.success = success;
10725
10904
  exports.transformOf = transformOf;
10726
10905
  exports.tupleOf = tupleOf;
10727
10906
  exports.unifySchemas = unifySchemas;