unthrown 3.1.0 → 4.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -14,6 +14,11 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
14
14
  * A `Defect` is never wrapped in an `UnwrapError`: its original cause is
15
15
  * re-thrown (with its original stack) instead.
16
16
  *
17
+ * `unwrap()` and `unwrapErr()` are type-gated (`this: Result<T, never>` /
18
+ * `Result<never, E>`), so the wrong-variant branch that throws this is
19
+ * unreachable through well-typed code — it remains only as a defensive guard
20
+ * against unsound runtime misuse (e.g. an `as` cast past the gate).
21
+ *
17
22
  * @typeParam E - the type of the {@link UnwrapError.error} it carries.
18
23
  *
19
24
  * @category Errors
@@ -713,9 +718,9 @@ function isDefectMarker(x) {
713
718
  * import { fromNullable } from "unthrown";
714
719
  *
715
720
  * const map = new Map([["a", 1]]);
716
- * fromNullable(map.get("a"), () => "absent").unwrap(); // => 1
721
+ * fromNullable(map.get("a"), () => "absent").unwrapOr(0); // => 1
717
722
  * fromNullable(map.get("z"), () => "absent"); // => Err("absent")
718
- * fromNullable(0, () => "absent").unwrap(); // => 0 (falsy but present)
723
+ * fromNullable(0, () => "absent").unwrapOr(-1); // => 0 (falsy but present)
719
724
  * ```
720
725
  */
721
726
  function fromNullable(value, onAbsent) {
@@ -759,7 +764,7 @@ function fromNullable(value, onAbsent) {
759
764
  * cause instanceof SyntaxError ? ("invalid_json" as const) : defect(cause),
760
765
  * );
761
766
  *
762
- * parse('{"ok":true}').unwrap(); // => { ok: true }
767
+ * parse('{"ok":true}').unwrapOr(null); // => { ok: true }
763
768
  * parse("nope"); // => Err("invalid_json")
764
769
  * ```
765
770
  */
@@ -806,8 +811,8 @@ function fromThrowable(fn, qualify) {
806
811
  * cause instanceof NotFoundError ? ("not_found" as const) : defect(cause),
807
812
  * );
808
813
  *
809
- * user.unwrap(); // => the fetched user (on success)
810
- * // when fetchUser rejects with NotFoundError: => Err("not_found")
814
+ * if (user.isOk()) user.value; // => the fetched user
815
+ * // when fetchUser rejects with NotFoundError: user is Err("not_found")
811
816
  * ```
812
817
  */
813
818
  function fromPromise(promise, qualify) {
@@ -1068,8 +1073,13 @@ const AsyncResult = {
1068
1073
  *
1069
1074
  * @remarks
1070
1075
  * Extend the returned class to declare a concrete error. Supply the payload with
1071
- * an instantiation expression; omit it for a payload-less error. A `message`
1072
- * field in the payload is forwarded to `Error`. The `_tag` always reflects
1076
+ * an instantiation expression; omit it for a payload-less error. The `message`
1077
+ * is **not** a payload field — it is the human string owned by `Error`, not
1078
+ * structured data, so it is reserved. Define it once per subclass the standard
1079
+ * way, `override message = "…"` (it may interpolate the payload via `this`,
1080
+ * which the base populates before the subclass field initialiser runs); a
1081
+ * payload `message` is rejected at compile time, so contextual detail lives in
1082
+ * typed fields, never baked into per-call prose. The `_tag` always reflects
1073
1083
  * `tag` and cannot be overridden by the payload. `name` is likewise reserved —
1074
1084
  * it is the display label (set it with `options.name`); a payload `name` is
1075
1085
  * rejected at compile time (and excluded from the instance type), so it can't
@@ -1084,11 +1094,14 @@ const AsyncResult = {
1084
1094
  * ```ts
1085
1095
  * class RetryableError extends TaggedError("@my-lib/RetryableError", {
1086
1096
  * name: "RetryableError",
1087
- * })<{ message: string }> {}
1088
- *
1089
- * const e = new RetryableError({ message: "boom" });
1090
- * e._tag; // "@my-lib/RetryableError" — namespaced discriminant
1091
- * e.name; // "RetryableError" — clean display name
1097
+ * }) {
1098
+ * override message = "operation failed; safe to retry";
1099
+ * }
1100
+ *
1101
+ * const e = new RetryableError();
1102
+ * e._tag; // "@my-lib/RetryableError" — namespaced discriminant
1103
+ * e.name; // "RetryableError" — clean display name
1104
+ * e.message; // "operation failed; safe to retry" — the standard Error.message
1092
1105
  * ```
1093
1106
  *
1094
1107
  * @typeParam Tag - the string literal discriminant.
@@ -1112,10 +1125,11 @@ function TaggedError(tag, options) {
1112
1125
  class TaggedErrorBase extends Error {
1113
1126
  _tag;
1114
1127
  constructor(props) {
1115
- super(typeof props?.["message"] === "string" ? props["message"] : void 0);
1128
+ super();
1116
1129
  if (props) Object.assign(this, props);
1117
1130
  this._tag = tag;
1118
1131
  this.name = displayName;
1132
+ delete this.message;
1119
1133
  Object.setPrototypeOf(this, new.target.prototype);
1120
1134
  }
1121
1135
  }
package/dist/index.d.cts CHANGED
@@ -254,20 +254,34 @@ type ResultMethods<T, E> = {
254
254
  /**
255
255
  * Extract the success value.
256
256
  *
257
+ * @remarks
258
+ * Compiles only when the error channel is empty (`E = never`) — eliminate
259
+ * modeled errors first (`match` / `recover` / `orElse`), or reach for the
260
+ * `unwrapOr` / `unwrapOrElse` / `getOrNull` / `getOrUndefined` family (which
261
+ * recover an `Err`). If you get a `'this' context` type error here, that is
262
+ * the gate: the receiver still has a non-`never` error channel.
263
+ *
264
+ * `E = never` empties only the **modeled** error channel — a `Defect` can
265
+ * still be present, and `unwrap()` **rethrows its original cause** (it
266
+ * _panics_); `Result<T, never>` does not mean `unwrap()` cannot throw.
267
+ *
257
268
  * @returns the `Ok` value.
258
- * @throws On `Err`, an {@link UnwrapError} carrying the error. On a `Defect`,
259
- * re-throws the **original cause** with its original stack, so an unhandled
260
- * Defect surfaces at the global handler as the real failure.
261
269
  */
262
- unwrap(): T;
270
+ unwrap(this: Result$1<T, never>): T;
263
271
  /**
264
272
  * Extract the modeled error.
265
273
  *
274
+ * @remarks
275
+ * Compiles only when the success channel is empty (`T = never`) — eliminate
276
+ * the success case first. `T = never` is rarely the case in practice (a
277
+ * `Result` you hold usually still has a success type), so to inspect an
278
+ * error prefer an `isErr()` guard or, in tests, `@unthrown/vitest`'s
279
+ * `toBeErrWith`. A `Defect` still **rethrows its original cause** (a defect is
280
+ * a bug, not an absent value), so this does not mean `unwrapErr()` can't throw.
281
+ *
266
282
  * @returns the `Err` value.
267
- * @throws On `Ok`, an {@link UnwrapError} carrying the value. On a `Defect`,
268
- * re-throws the original cause.
269
283
  */
270
- unwrapErr(): E;
284
+ unwrapErr(this: Result$1<never, E>): E;
271
285
  /**
272
286
  * The success value, or `fallback` on `Err`.
273
287
  *
@@ -531,11 +545,17 @@ type AsyncResultMethods<T, E> = {
531
545
  defect: (cause: unknown) => R;
532
546
  }): Promise<R>;
533
547
  /**
534
- * Asynchronous {@link ResultMethods.unwrap | unwrap}. The returned promise
535
- * rejects on `Err`/`Defect`.
548
+ * Asynchronous {@link ResultMethods.unwrap | unwrap}. Compiles only when the
549
+ * error channel is empty (`this: AsyncResult<T, never>`); the returned promise
550
+ * rejects on a `Defect` (rethrowing its cause).
536
551
  */
537
- unwrap(): Promise<T>; /** Asynchronous {@link ResultMethods.unwrapErr | unwrapErr}. */
538
- unwrapErr(): Promise<E>; /** Asynchronous {@link ResultMethods.unwrapOr | unwrapOr}. */
552
+ unwrap(this: AsyncResult$1<T, never>): Promise<T>;
553
+ /**
554
+ * Asynchronous {@link ResultMethods.unwrapErr | unwrapErr}. Compiles only when
555
+ * the success channel is empty (`this: AsyncResult<never, E>`); the returned
556
+ * promise rejects on a `Defect` (rethrowing its cause).
557
+ */
558
+ unwrapErr(this: AsyncResult$1<never, E>): Promise<E>; /** Asynchronous {@link ResultMethods.unwrapOr | unwrapOr}. */
539
559
  unwrapOr<U>(fallback: U): Promise<T | U>; /** Asynchronous {@link ResultMethods.unwrapOrElse | unwrapOrElse}. */
540
560
  unwrapOrElse<U>(f: (error: E) => U): Promise<T | U>; /** Asynchronous {@link ResultMethods.getOrNull | getOrNull}. */
541
561
  getOrNull(): Promise<T | null>; /** Asynchronous {@link ResultMethods.getOrUndefined | getOrUndefined}. */
@@ -743,6 +763,11 @@ declare function isDefect<T, E>(r: Result$1<T, E>): r is DefectView<T, E>;
743
763
  * A `Defect` is never wrapped in an `UnwrapError`: its original cause is
744
764
  * re-thrown (with its original stack) instead.
745
765
  *
766
+ * `unwrap()` and `unwrapErr()` are type-gated (`this: Result<T, never>` /
767
+ * `Result<never, E>`), so the wrong-variant branch that throws this is
768
+ * unreachable through well-typed code — it remains only as a defensive guard
769
+ * against unsound runtime misuse (e.g. an `as` cast past the gate).
770
+ *
746
771
  * @typeParam E - the type of the {@link UnwrapError.error} it carries.
747
772
  *
748
773
  * @category Errors
@@ -868,9 +893,9 @@ type Defect = {
868
893
  * import { fromNullable } from "unthrown";
869
894
  *
870
895
  * const map = new Map([["a", 1]]);
871
- * fromNullable(map.get("a"), () => "absent").unwrap(); // => 1
896
+ * fromNullable(map.get("a"), () => "absent").unwrapOr(0); // => 1
872
897
  * fromNullable(map.get("z"), () => "absent"); // => Err("absent")
873
- * fromNullable(0, () => "absent").unwrap(); // => 0 (falsy but present)
898
+ * fromNullable(0, () => "absent").unwrapOr(-1); // => 0 (falsy but present)
874
899
  * ```
875
900
  */
876
901
  declare function fromNullable<T, E>(value: T | null | undefined, onAbsent: () => E): Result$1<NonNullable<T>, E>;
@@ -912,7 +937,7 @@ declare function fromNullable<T, E>(value: T | null | undefined, onAbsent: () =>
912
937
  * cause instanceof SyntaxError ? ("invalid_json" as const) : defect(cause),
913
938
  * );
914
939
  *
915
- * parse('{"ok":true}').unwrap(); // => { ok: true }
940
+ * parse('{"ok":true}').unwrapOr(null); // => { ok: true }
916
941
  * parse("nope"); // => Err("invalid_json")
917
942
  * ```
918
943
  */
@@ -950,8 +975,8 @@ declare function fromThrowable<A extends unknown[], T, R>(fn: (...args: A) => T,
950
975
  * cause instanceof NotFoundError ? ("not_found" as const) : defect(cause),
951
976
  * );
952
977
  *
953
- * user.unwrap(); // => the fetched user (on success)
954
- * // when fetchUser rejects with NotFoundError: => Err("not_found")
978
+ * if (user.isOk()) user.value; // => the fetched user
979
+ * // when fetchUser rejects with NotFoundError: user is Err("not_found")
955
980
  * ```
956
981
  */
957
982
  declare function fromPromise<T, R>(promise: Promise<T> | (() => Promise<T>), qualify: (cause: unknown, defect: (cause: unknown) => Defect) => R): AsyncResult$1<T, Exclude<R, Defect>>;
@@ -1199,7 +1224,7 @@ type Props = Record<string, unknown>;
1199
1224
  *
1200
1225
  * @category Types
1201
1226
  */
1202
- type TaggedErrorInstance<Tag extends string, A extends Props> = Error & Readonly<Omit<A, "name">> & {
1227
+ type TaggedErrorInstance<Tag extends string, A extends Props> = Error & Readonly<Omit<A, "name" | "message">> & {
1203
1228
  readonly _tag: Tag;
1204
1229
  };
1205
1230
  /**
@@ -1208,10 +1233,13 @@ type TaggedErrorInstance<Tag extends string, A extends Props> = Error & Readonly
1208
1233
  *
1209
1234
  * @remarks
1210
1235
  * When the payload is empty, the constructor takes **no** arguments (the
1211
- * `keyof A extends never ? void : A` trick); otherwise it takes the payload. A
1212
- * `name` key is **rejected** (`name?: never`) because it is reserved for the
1213
- * display label — mirroring how {@link TaggedErrorInstance} excludes it — so the
1214
- * reservation is enforced at the call site, not just ignored at runtime.
1236
+ * `keyof A extends never ? void : A` trick); otherwise it takes the payload. The
1237
+ * `name` and `message` keys are both **rejected** (`name?: never` /
1238
+ * `message?: never`) because both are reserved: `name` is the display label, and
1239
+ * `message` is the human string owned by `Error`. Set the message the standard
1240
+ * way — `override message = "…"` (or a constructor override) on the subclass —
1241
+ * never as a free-form per-call payload field. The reservations are enforced at
1242
+ * the call site, mirroring how {@link TaggedErrorInstance} excludes both.
1215
1243
  *
1216
1244
  * @typeParam Tag - the string literal discriminant.
1217
1245
  *
@@ -1220,6 +1248,7 @@ type TaggedErrorInstance<Tag extends string, A extends Props> = Error & Readonly
1220
1248
  type TaggedErrorConstructor<Tag extends string> = {
1221
1249
  new <A extends Props = {}>(args: keyof A extends never ? void : A & {
1222
1250
  readonly name?: never;
1251
+ readonly message?: never;
1223
1252
  }): TaggedErrorInstance<Tag, A>;
1224
1253
  };
1225
1254
  /**
@@ -1228,8 +1257,13 @@ type TaggedErrorConstructor<Tag extends string> = {
1228
1257
  *
1229
1258
  * @remarks
1230
1259
  * Extend the returned class to declare a concrete error. Supply the payload with
1231
- * an instantiation expression; omit it for a payload-less error. A `message`
1232
- * field in the payload is forwarded to `Error`. The `_tag` always reflects
1260
+ * an instantiation expression; omit it for a payload-less error. The `message`
1261
+ * is **not** a payload field — it is the human string owned by `Error`, not
1262
+ * structured data, so it is reserved. Define it once per subclass the standard
1263
+ * way, `override message = "…"` (it may interpolate the payload via `this`,
1264
+ * which the base populates before the subclass field initialiser runs); a
1265
+ * payload `message` is rejected at compile time, so contextual detail lives in
1266
+ * typed fields, never baked into per-call prose. The `_tag` always reflects
1233
1267
  * `tag` and cannot be overridden by the payload. `name` is likewise reserved —
1234
1268
  * it is the display label (set it with `options.name`); a payload `name` is
1235
1269
  * rejected at compile time (and excluded from the instance type), so it can't
@@ -1244,11 +1278,14 @@ type TaggedErrorConstructor<Tag extends string> = {
1244
1278
  * ```ts
1245
1279
  * class RetryableError extends TaggedError("@my-lib/RetryableError", {
1246
1280
  * name: "RetryableError",
1247
- * })<{ message: string }> {}
1281
+ * }) {
1282
+ * override message = "operation failed; safe to retry";
1283
+ * }
1248
1284
  *
1249
- * const e = new RetryableError({ message: "boom" });
1250
- * e._tag; // "@my-lib/RetryableError" — namespaced discriminant
1251
- * e.name; // "RetryableError" — clean display name
1285
+ * const e = new RetryableError();
1286
+ * e._tag; // "@my-lib/RetryableError" — namespaced discriminant
1287
+ * e.name; // "RetryableError" — clean display name
1288
+ * e.message; // "operation failed; safe to retry" — the standard Error.message
1252
1289
  * ```
1253
1290
  *
1254
1291
  * @typeParam Tag - the string literal discriminant.
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.cts","names":[],"sources":["../src/types.ts","../src/constructors.ts","../src/core.ts","../src/do.ts","../src/defect.ts","../src/interop.ts","../src/facade.ts","../src/tagged.ts"],"mappings":";;AAQA;;;;;KAAY,QAAA,oBAA4B,CAAA,GAAI,CAAA,CAAE,CAAA;;;;;;;AAAC;AAU/C;KAAY,KAAA,2BAAgC,QAAA,CAAS,IAAA,CAAK,CAAA,EAAG,CAAA,qBAAsB,CAAA,GAAI,CAAA;;;;;;;;;;;;;;;;;KAkB3E,WAAA,OAAkB,CAAA,WAAY,WA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A,wDAAyD,gBAAA,IACpE,CAAA;AAAA,iBACa,SAAA;EAAyB,IAAA;AAAA,MACvC,MAAA,EAAQ,aAAA,CAAY,CAAA,EAAG,CAAA,GACvB,QAAA,EAAU,WAAA,CAAY,CAAA,EAAG,CAAA,EAAG,CAAA,MACxB,OAAA,CAAQ,CAAA,wDAAyD,gBAAA,IACpE,OAAA,CAAQ,CAAA"}
1
+ {"version":3,"file":"index.d.cts","names":[],"sources":["../src/types.ts","../src/constructors.ts","../src/core.ts","../src/do.ts","../src/defect.ts","../src/interop.ts","../src/facade.ts","../src/tagged.ts"],"mappings":";;AAQA;;;;;KAAY,QAAA,oBAA4B,CAAA,GAAI,CAAA,CAAE,CAAA;;;;;;;AAAC;AAU/C;KAAY,KAAA,2BAAgC,QAAA,CAAS,IAAA,CAAK,CAAA,EAAG,CAAA,qBAAsB,CAAA,GAAI,CAAA;;;;;;;;;;;;;;;;;KAkB3E,WAAA,OAAkB,CAAA,WAAY,WAAW;;AAlBmC;AAkBxF;;;;;;;;AAAqD;AAoBrD;;;;;KAAY,aAAA;EAYkB;;;;;;;;;;;EAA5B,GAAA,IAAO,CAAA,GAAI,KAAA,EAAO,CAAA,KAAM,CAAA,GAAI,WAAA,CAAY,CAAA,IAAK,QAAA,CAAO,CAAA,EAAG,CAAA;EAqBrC;;;;;;;;;;EAVlB,OAAA,QAAe,CAAA,GAAI,KAAA,EAAO,CAAA,KAAM,QAAA,CAAO,CAAA,EAAG,EAAA,IAAM,QAAA,CAAO,CAAA,EAAG,CAAA,GAAI,EAAA;EA2BD;;;;;;;;;EAjB7D,GAAA,IAAO,CAAA,GAAI,KAAA,EAAO,CAAA,KAAM,CAAA,GAAI,WAAA,CAAY,CAAA,IAAK,QAAA,CAAO,CAAA,EAAG,CAAA;EAwCjC;;;;;;;;;;;;;;;;EAvBtB,OAAA,KAAY,CAAA,GAAI,KAAA,EAAO,CAAA,KAAM,QAAA,UAAgB,EAAA,IAAM,QAAA,CAAO,CAAA,EAAG,C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AAA,QAAY,CAAA,wBAAyB,CAAA;IAAA,SAAe,IAAA;IAAA,SAAuB,OAAA;EAAA,IAC1E,mBAAA,CAAoB,GAAA,EAAK,CAAA;AAAA;APtB0D;AAkBxF;;;;;;;;AAAqD;AAoBrD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAtCwF,iBO8ExE,WAAA,qBACd,GAAA,EAAK,GAAA,EACL,OAAA;EAAA,SAAqB,IAAA;AAAA,IACpB,sBAAA,CAAuB,GAAA;;;;;;;;;;;;KAkCd,WAAA;EAA2B,IAAA;AAAA;EACrC,EAAA,GAAK,KAAA,EAAO,CAAA,KAAM,CAAA;EAClB,MAAA,GAAS,KAAA,cAAmB,CAAA;AAAA,YAClB,CAAA,YAAa,KAAA,EAAO,OAAA,CAAQ,CAAA;EAAK,IAAA,EAAM,CAAA;AAAA,OAAS,CAAA;;;;;;;;KASvD,gBAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBA2CW,SAAA;EAAyB,IAAA;AAAA,MACvC,MAAA,EAAQ,QAAA,CAAO,CAAA,EAAG,CAAA,GAClB,QAAA,EAAU,WAAA,CAAY,CAAA,EAAG,CAAA,EAAG,CAAA,MACxB,OAAA,CAAQ,CAAA,wDAAyD,gBAAA,IACpE,CAAA;AAAA,iBACa,SAAA;EAAyB,IAAA;AAAA,MACvC,MAAA,EAAQ,aAAA,CAAY,CAAA,EAAG,CAAA,GACvB,QAAA,EAAU,WAAA,CAAY,CAAA,EAAG,CAAA,EAAG,CAAA,MACxB,OAAA,CAAQ,CAAA,wDAAyD,gBAAA,IACpE,OAAA,CAAQ,CAAA"}
package/dist/index.d.mts CHANGED
@@ -254,20 +254,34 @@ type ResultMethods<T, E> = {
254
254
  /**
255
255
  * Extract the success value.
256
256
  *
257
+ * @remarks
258
+ * Compiles only when the error channel is empty (`E = never`) — eliminate
259
+ * modeled errors first (`match` / `recover` / `orElse`), or reach for the
260
+ * `unwrapOr` / `unwrapOrElse` / `getOrNull` / `getOrUndefined` family (which
261
+ * recover an `Err`). If you get a `'this' context` type error here, that is
262
+ * the gate: the receiver still has a non-`never` error channel.
263
+ *
264
+ * `E = never` empties only the **modeled** error channel — a `Defect` can
265
+ * still be present, and `unwrap()` **rethrows its original cause** (it
266
+ * _panics_); `Result<T, never>` does not mean `unwrap()` cannot throw.
267
+ *
257
268
  * @returns the `Ok` value.
258
- * @throws On `Err`, an {@link UnwrapError} carrying the error. On a `Defect`,
259
- * re-throws the **original cause** with its original stack, so an unhandled
260
- * Defect surfaces at the global handler as the real failure.
261
269
  */
262
- unwrap(): T;
270
+ unwrap(this: Result$1<T, never>): T;
263
271
  /**
264
272
  * Extract the modeled error.
265
273
  *
274
+ * @remarks
275
+ * Compiles only when the success channel is empty (`T = never`) — eliminate
276
+ * the success case first. `T = never` is rarely the case in practice (a
277
+ * `Result` you hold usually still has a success type), so to inspect an
278
+ * error prefer an `isErr()` guard or, in tests, `@unthrown/vitest`'s
279
+ * `toBeErrWith`. A `Defect` still **rethrows its original cause** (a defect is
280
+ * a bug, not an absent value), so this does not mean `unwrapErr()` can't throw.
281
+ *
266
282
  * @returns the `Err` value.
267
- * @throws On `Ok`, an {@link UnwrapError} carrying the value. On a `Defect`,
268
- * re-throws the original cause.
269
283
  */
270
- unwrapErr(): E;
284
+ unwrapErr(this: Result$1<never, E>): E;
271
285
  /**
272
286
  * The success value, or `fallback` on `Err`.
273
287
  *
@@ -531,11 +545,17 @@ type AsyncResultMethods<T, E> = {
531
545
  defect: (cause: unknown) => R;
532
546
  }): Promise<R>;
533
547
  /**
534
- * Asynchronous {@link ResultMethods.unwrap | unwrap}. The returned promise
535
- * rejects on `Err`/`Defect`.
548
+ * Asynchronous {@link ResultMethods.unwrap | unwrap}. Compiles only when the
549
+ * error channel is empty (`this: AsyncResult<T, never>`); the returned promise
550
+ * rejects on a `Defect` (rethrowing its cause).
536
551
  */
537
- unwrap(): Promise<T>; /** Asynchronous {@link ResultMethods.unwrapErr | unwrapErr}. */
538
- unwrapErr(): Promise<E>; /** Asynchronous {@link ResultMethods.unwrapOr | unwrapOr}. */
552
+ unwrap(this: AsyncResult$1<T, never>): Promise<T>;
553
+ /**
554
+ * Asynchronous {@link ResultMethods.unwrapErr | unwrapErr}. Compiles only when
555
+ * the success channel is empty (`this: AsyncResult<never, E>`); the returned
556
+ * promise rejects on a `Defect` (rethrowing its cause).
557
+ */
558
+ unwrapErr(this: AsyncResult$1<never, E>): Promise<E>; /** Asynchronous {@link ResultMethods.unwrapOr | unwrapOr}. */
539
559
  unwrapOr<U>(fallback: U): Promise<T | U>; /** Asynchronous {@link ResultMethods.unwrapOrElse | unwrapOrElse}. */
540
560
  unwrapOrElse<U>(f: (error: E) => U): Promise<T | U>; /** Asynchronous {@link ResultMethods.getOrNull | getOrNull}. */
541
561
  getOrNull(): Promise<T | null>; /** Asynchronous {@link ResultMethods.getOrUndefined | getOrUndefined}. */
@@ -743,6 +763,11 @@ declare function isDefect<T, E>(r: Result$1<T, E>): r is DefectView<T, E>;
743
763
  * A `Defect` is never wrapped in an `UnwrapError`: its original cause is
744
764
  * re-thrown (with its original stack) instead.
745
765
  *
766
+ * `unwrap()` and `unwrapErr()` are type-gated (`this: Result<T, never>` /
767
+ * `Result<never, E>`), so the wrong-variant branch that throws this is
768
+ * unreachable through well-typed code — it remains only as a defensive guard
769
+ * against unsound runtime misuse (e.g. an `as` cast past the gate).
770
+ *
746
771
  * @typeParam E - the type of the {@link UnwrapError.error} it carries.
747
772
  *
748
773
  * @category Errors
@@ -868,9 +893,9 @@ type Defect = {
868
893
  * import { fromNullable } from "unthrown";
869
894
  *
870
895
  * const map = new Map([["a", 1]]);
871
- * fromNullable(map.get("a"), () => "absent").unwrap(); // => 1
896
+ * fromNullable(map.get("a"), () => "absent").unwrapOr(0); // => 1
872
897
  * fromNullable(map.get("z"), () => "absent"); // => Err("absent")
873
- * fromNullable(0, () => "absent").unwrap(); // => 0 (falsy but present)
898
+ * fromNullable(0, () => "absent").unwrapOr(-1); // => 0 (falsy but present)
874
899
  * ```
875
900
  */
876
901
  declare function fromNullable<T, E>(value: T | null | undefined, onAbsent: () => E): Result$1<NonNullable<T>, E>;
@@ -912,7 +937,7 @@ declare function fromNullable<T, E>(value: T | null | undefined, onAbsent: () =>
912
937
  * cause instanceof SyntaxError ? ("invalid_json" as const) : defect(cause),
913
938
  * );
914
939
  *
915
- * parse('{"ok":true}').unwrap(); // => { ok: true }
940
+ * parse('{"ok":true}').unwrapOr(null); // => { ok: true }
916
941
  * parse("nope"); // => Err("invalid_json")
917
942
  * ```
918
943
  */
@@ -950,8 +975,8 @@ declare function fromThrowable<A extends unknown[], T, R>(fn: (...args: A) => T,
950
975
  * cause instanceof NotFoundError ? ("not_found" as const) : defect(cause),
951
976
  * );
952
977
  *
953
- * user.unwrap(); // => the fetched user (on success)
954
- * // when fetchUser rejects with NotFoundError: => Err("not_found")
978
+ * if (user.isOk()) user.value; // => the fetched user
979
+ * // when fetchUser rejects with NotFoundError: user is Err("not_found")
955
980
  * ```
956
981
  */
957
982
  declare function fromPromise<T, R>(promise: Promise<T> | (() => Promise<T>), qualify: (cause: unknown, defect: (cause: unknown) => Defect) => R): AsyncResult$1<T, Exclude<R, Defect>>;
@@ -1199,7 +1224,7 @@ type Props = Record<string, unknown>;
1199
1224
  *
1200
1225
  * @category Types
1201
1226
  */
1202
- type TaggedErrorInstance<Tag extends string, A extends Props> = Error & Readonly<Omit<A, "name">> & {
1227
+ type TaggedErrorInstance<Tag extends string, A extends Props> = Error & Readonly<Omit<A, "name" | "message">> & {
1203
1228
  readonly _tag: Tag;
1204
1229
  };
1205
1230
  /**
@@ -1208,10 +1233,13 @@ type TaggedErrorInstance<Tag extends string, A extends Props> = Error & Readonly
1208
1233
  *
1209
1234
  * @remarks
1210
1235
  * When the payload is empty, the constructor takes **no** arguments (the
1211
- * `keyof A extends never ? void : A` trick); otherwise it takes the payload. A
1212
- * `name` key is **rejected** (`name?: never`) because it is reserved for the
1213
- * display label — mirroring how {@link TaggedErrorInstance} excludes it — so the
1214
- * reservation is enforced at the call site, not just ignored at runtime.
1236
+ * `keyof A extends never ? void : A` trick); otherwise it takes the payload. The
1237
+ * `name` and `message` keys are both **rejected** (`name?: never` /
1238
+ * `message?: never`) because both are reserved: `name` is the display label, and
1239
+ * `message` is the human string owned by `Error`. Set the message the standard
1240
+ * way — `override message = "…"` (or a constructor override) on the subclass —
1241
+ * never as a free-form per-call payload field. The reservations are enforced at
1242
+ * the call site, mirroring how {@link TaggedErrorInstance} excludes both.
1215
1243
  *
1216
1244
  * @typeParam Tag - the string literal discriminant.
1217
1245
  *
@@ -1220,6 +1248,7 @@ type TaggedErrorInstance<Tag extends string, A extends Props> = Error & Readonly
1220
1248
  type TaggedErrorConstructor<Tag extends string> = {
1221
1249
  new <A extends Props = {}>(args: keyof A extends never ? void : A & {
1222
1250
  readonly name?: never;
1251
+ readonly message?: never;
1223
1252
  }): TaggedErrorInstance<Tag, A>;
1224
1253
  };
1225
1254
  /**
@@ -1228,8 +1257,13 @@ type TaggedErrorConstructor<Tag extends string> = {
1228
1257
  *
1229
1258
  * @remarks
1230
1259
  * Extend the returned class to declare a concrete error. Supply the payload with
1231
- * an instantiation expression; omit it for a payload-less error. A `message`
1232
- * field in the payload is forwarded to `Error`. The `_tag` always reflects
1260
+ * an instantiation expression; omit it for a payload-less error. The `message`
1261
+ * is **not** a payload field — it is the human string owned by `Error`, not
1262
+ * structured data, so it is reserved. Define it once per subclass the standard
1263
+ * way, `override message = "…"` (it may interpolate the payload via `this`,
1264
+ * which the base populates before the subclass field initialiser runs); a
1265
+ * payload `message` is rejected at compile time, so contextual detail lives in
1266
+ * typed fields, never baked into per-call prose. The `_tag` always reflects
1233
1267
  * `tag` and cannot be overridden by the payload. `name` is likewise reserved —
1234
1268
  * it is the display label (set it with `options.name`); a payload `name` is
1235
1269
  * rejected at compile time (and excluded from the instance type), so it can't
@@ -1244,11 +1278,14 @@ type TaggedErrorConstructor<Tag extends string> = {
1244
1278
  * ```ts
1245
1279
  * class RetryableError extends TaggedError("@my-lib/RetryableError", {
1246
1280
  * name: "RetryableError",
1247
- * })<{ message: string }> {}
1281
+ * }) {
1282
+ * override message = "operation failed; safe to retry";
1283
+ * }
1248
1284
  *
1249
- * const e = new RetryableError({ message: "boom" });
1250
- * e._tag; // "@my-lib/RetryableError" — namespaced discriminant
1251
- * e.name; // "RetryableError" — clean display name
1285
+ * const e = new RetryableError();
1286
+ * e._tag; // "@my-lib/RetryableError" — namespaced discriminant
1287
+ * e.name; // "RetryableError" — clean display name
1288
+ * e.message; // "operation failed; safe to retry" — the standard Error.message
1252
1289
  * ```
1253
1290
  *
1254
1291
  * @typeParam Tag - the string literal discriminant.
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.mts","names":[],"sources":["../src/types.ts","../src/constructors.ts","../src/core.ts","../src/do.ts","../src/defect.ts","../src/interop.ts","../src/facade.ts","../src/tagged.ts"],"mappings":";;AAQA;;;;;KAAY,QAAA,oBAA4B,CAAA,GAAI,CAAA,CAAE,CAAA;;;;;;;AAAC;AAU/C;KAAY,KAAA,2BAAgC,QAAA,CAAS,IAAA,CAAK,CAAA,EAAG,CAAA,qBAAsB,CAAA,GAAI,CAAA;;;;;;;;;;;;;;;;;KAkB3E,WAAA,OAAkB,CAAA,WAAY,WAAW;;AAlBmC;AAkBxF;;;;;;;;AAAqD;AAoBrD;;;;;KAAY,aAAA;EAYkB;;;;;;;;;;;EAA5B,GAAA,IAAO,CAAA,GAAI,KAAA,EAAO,CAAA,KAAM,CAAA,GAAI,WAAA,CAAY,CAAA,IAAK,QAAA,CAAO,CAAA,EAAG,CAAA;EAqBrC;;;;;;;;;;EAVlB,OAAA,QAAe,CAAA,GAAI,KAAA,EAAO,CAAA,KAAM,QAAA,CAAO,CAAA,EAAG,EAAA,IAAM,QAAA,CAAO,CAAA,EAAG,CAAA,GAAI,EAAA;EA2BD;;;;;;;;;EAjB7D,GAAA,IAAO,CAAA,GAAI,KAAA,EAAO,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;;APTA;AAU/C;;;;;;;;;;;;;KOgBY,sBAAA;EAAA,eACK,KAAA,OACb,IAAA,QAAY,CAAA,wBAAyB,CAAA;IAAA,SAAe,IAAA;EAAA,IACnD,mBAAA,CAAoB,GAAA,EAAK,CAAA;AAAA;;;;;APnB0D;AAkBxF;;;;;;;;AAAqD;AAoBrD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBO6BgB,WAAA,qBACd,GAAA,EAAK,GAAA,EACL,OAAA;EAAA,SAAqB,IAAA;AAAA,IACpB,sBAAA,CAAuB,GAAA;;;;;;;;;;;;KA8Bd,WAAA;EAA2B,IAAA;AAAA;EACrC,EAAA,GAAK,KAAA,EAAO,CAAA,KAAM,CAAA;EAClB,MAAA,GAAS,KAAA,cAAmB,CAAA;AAAA,YAClB,CAAA,YAAa,KAAA,EAAO,OAAA,CAAQ,CAAA;EAAK,IAAA,EAAM,CAAA;AAAA,OAAS,CAAA;;;;;;;;KASvD,gBAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBA2CW,SAAA;EAAyB,IAAA;AAAA,MACvC,MAAA,EAAQ,QAAA,CAAO,CAAA,EAAG,CAAA,GAClB,QAAA,EAAU,WAAA,CAAY,CAAA,EAAG,CAAA,EAAG,CAAA,MACxB,OAAA,CAAQ,CAAA,wDAAyD,gBAAA,IACpE,CAAA;AAAA,iBACa,SAAA;EAAyB,IAAA;AAAA,MACvC,MAAA,EAAQ,aAAA,CAAY,CAAA,EAAG,CAAA,GACvB,QAAA,EAAU,WAAA,CAAY,CAAA,EAAG,CAAA,EAAG,CAAA,MACxB,OAAA,CAAQ,CAAA,wDAAyD,gBAAA,IACpE,OAAA,CAAQ,CAAA"}
1
+ {"version":3,"file":"index.d.mts","names":[],"sources":["../src/types.ts","../src/constructors.ts","../src/core.ts","../src/do.ts","../src/defect.ts","../src/interop.ts","../src/facade.ts","../src/tagged.ts"],"mappings":";;AAQA;;;;;KAAY,QAAA,oBAA4B,CAAA,GAA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ClB,MAAA,GAAS,KAAA,cAAmB,CAAA;AAAA,YAClB,CAAA,YAAa,KAAA,EAAO,OAAA,CAAQ,CAAA;EAAK,IAAA,EAAM,CAAA;AAAA,OAAS,CAAA;;;;;;;;KASvD,gBAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBA2CW,SAAA;EAAyB,IAAA;AAAA,MACvC,MAAA,EAAQ,QAAA,CAAO,CAAA,EAAG,CAAA,GAClB,QAAA,EAAU,WAAA,CAAY,CAAA,EAAG,CAAA,EAAG,CAAA,MACxB,OAAA,CAAQ,CAAA,wDAAyD,gBAAA,IACpE,CAAA;AAAA,iBACa,SAAA;EAAyB,IAAA;AAAA,MACvC,MAAA,EAAQ,aAAA,CAAY,CAAA,EAAG,CAAA,GACvB,QAAA,EAAU,WAAA,CAAY,CAAA,EAAG,CAAA,EAAG,CAAA,MACxB,OAAA,CAAQ,CAAA,wDAAyD,gBAAA,IACpE,OAAA,CAAQ,CAAA"}
package/dist/index.mjs CHANGED
@@ -13,6 +13,11 @@
13
13
  * A `Defect` is never wrapped in an `UnwrapError`: its original cause is
14
14
  * re-thrown (with its original stack) instead.
15
15
  *
16
+ * `unwrap()` and `unwrapErr()` are type-gated (`this: Result<T, never>` /
17
+ * `Result<never, E>`), so the wrong-variant branch that throws this is
18
+ * unreachable through well-typed code — it remains only as a defensive guard
19
+ * against unsound runtime misuse (e.g. an `as` cast past the gate).
20
+ *
16
21
  * @typeParam E - the type of the {@link UnwrapError.error} it carries.
17
22
  *
18
23
  * @category Errors
@@ -712,9 +717,9 @@ function isDefectMarker(x) {
712
717
  * import { fromNullable } from "unthrown";
713
718
  *
714
719
  * const map = new Map([["a", 1]]);
715
- * fromNullable(map.get("a"), () => "absent").unwrap(); // => 1
720
+ * fromNullable(map.get("a"), () => "absent").unwrapOr(0); // => 1
716
721
  * fromNullable(map.get("z"), () => "absent"); // => Err("absent")
717
- * fromNullable(0, () => "absent").unwrap(); // => 0 (falsy but present)
722
+ * fromNullable(0, () => "absent").unwrapOr(-1); // => 0 (falsy but present)
718
723
  * ```
719
724
  */
720
725
  function fromNullable(value, onAbsent) {
@@ -758,7 +763,7 @@ function fromNullable(value, onAbsent) {
758
763
  * cause instanceof SyntaxError ? ("invalid_json" as const) : defect(cause),
759
764
  * );
760
765
  *
761
- * parse('{"ok":true}').unwrap(); // => { ok: true }
766
+ * parse('{"ok":true}').unwrapOr(null); // => { ok: true }
762
767
  * parse("nope"); // => Err("invalid_json")
763
768
  * ```
764
769
  */
@@ -805,8 +810,8 @@ function fromThrowable(fn, qualify) {
805
810
  * cause instanceof NotFoundError ? ("not_found" as const) : defect(cause),
806
811
  * );
807
812
  *
808
- * user.unwrap(); // => the fetched user (on success)
809
- * // when fetchUser rejects with NotFoundError: => Err("not_found")
813
+ * if (user.isOk()) user.value; // => the fetched user
814
+ * // when fetchUser rejects with NotFoundError: user is Err("not_found")
810
815
  * ```
811
816
  */
812
817
  function fromPromise(promise, qualify) {
@@ -1067,8 +1072,13 @@ const AsyncResult = {
1067
1072
  *
1068
1073
  * @remarks
1069
1074
  * Extend the returned class to declare a concrete error. Supply the payload with
1070
- * an instantiation expression; omit it for a payload-less error. A `message`
1071
- * field in the payload is forwarded to `Error`. The `_tag` always reflects
1075
+ * an instantiation expression; omit it for a payload-less error. The `message`
1076
+ * is **not** a payload field — it is the human string owned by `Error`, not
1077
+ * structured data, so it is reserved. Define it once per subclass the standard
1078
+ * way, `override message = "…"` (it may interpolate the payload via `this`,
1079
+ * which the base populates before the subclass field initialiser runs); a
1080
+ * payload `message` is rejected at compile time, so contextual detail lives in
1081
+ * typed fields, never baked into per-call prose. The `_tag` always reflects
1072
1082
  * `tag` and cannot be overridden by the payload. `name` is likewise reserved —
1073
1083
  * it is the display label (set it with `options.name`); a payload `name` is
1074
1084
  * rejected at compile time (and excluded from the instance type), so it can't
@@ -1083,11 +1093,14 @@ const AsyncResult = {
1083
1093
  * ```ts
1084
1094
  * class RetryableError extends TaggedError("@my-lib/RetryableError", {
1085
1095
  * name: "RetryableError",
1086
- * })<{ message: string }> {}
1087
- *
1088
- * const e = new RetryableError({ message: "boom" });
1089
- * e._tag; // "@my-lib/RetryableError" — namespaced discriminant
1090
- * e.name; // "RetryableError" — clean display name
1096
+ * }) {
1097
+ * override message = "operation failed; safe to retry";
1098
+ * }
1099
+ *
1100
+ * const e = new RetryableError();
1101
+ * e._tag; // "@my-lib/RetryableError" — namespaced discriminant
1102
+ * e.name; // "RetryableError" — clean display name
1103
+ * e.message; // "operation failed; safe to retry" — the standard Error.message
1091
1104
  * ```
1092
1105
  *
1093
1106
  * @typeParam Tag - the string literal discriminant.
@@ -1111,10 +1124,11 @@ function TaggedError(tag, options) {
1111
1124
  class TaggedErrorBase extends Error {
1112
1125
  _tag;
1113
1126
  constructor(props) {
1114
- super(typeof props?.["message"] === "string" ? props["message"] : void 0);
1127
+ super();
1115
1128
  if (props) Object.assign(this, props);
1116
1129
  this._tag = tag;
1117
1130
  this.name = displayName;
1131
+ delete this.message;
1118
1132
  Object.setPrototypeOf(this, new.target.prototype);
1119
1133
  }
1120
1134
  }
@@ -1 +1 @@
1
- {"version":3,"file":"index.mjs","names":[],"sources":["../src/core.ts","../src/constructors.ts","../src/do.ts","../src/defect.ts","../src/interop.ts","../src/facade.ts","../src/tagged.ts"],"sourcesContent":["// unthrown — the runtime engine.\n//\n// `Result` is the PUBLIC discriminated union (tag/value/error/cause + methods).\n// `Res` is a method holder only: its prototype carries the implementations, and\n// instances are built by `okRes`/`errRes`/`defectRes` with `Object.create` +\n// the variant type — so a builder returns a value that already *is* a union\n// member (no `as unknown as`). `Res` is never exported from `index.ts`.\n// `AsyncRes` wraps a `Promise<Result>` constructed never to reject and operates\n// purely on the public union (via `r.tag`). See CLAUDE.md → \"Internal design\".\n//\n// Type-changing pass-throughs (e.g. `map` reusing an `Err` as a differently-typed\n// `Result`) all funnel through the single `passThrough` helper — one sound\n// `as unknown as` in one place, rather than boxed's inline cast at every branch.\n// The only other casts are the builders' construction (`as OkView`/…) and the\n// `bind`/`let` scope merge (a computed key can't be spelled at the type level).\n\nimport type {\n AsyncResult,\n Bound,\n DefectView,\n ErrView,\n NotThenable,\n OkView,\n Result,\n} from \"./types.js\";\n\n/**\n * Thrown by a {@link Result}'s `unwrap` / `unwrapErr` when the assertion is\n * wrong on a *modeled* result — `unwrap()` on an `Err`, or `unwrapErr()` on an\n * `Ok`.\n *\n * @remarks\n * The offending value is exposed two ways: the typed {@link UnwrapError.error}\n * property for programmatic access, and the standard `Error.cause` for the\n * runtime and devtools to chain — when `E` is an `Error` (e.g. a `TaggedError`)\n * its original stack is printed under \"caused by\".\n *\n * A `Defect` is never wrapped in an `UnwrapError`: its original cause is\n * re-thrown (with its original stack) instead.\n *\n * @typeParam E - the type of the {@link UnwrapError.error} it carries.\n *\n * @category Errors\n */\nexport class UnwrapError<E = unknown> extends Error {\n /**\n * The offending value: the `Err` error for `unwrap()`, or the `Ok` value for\n * `unwrapErr()`.\n */\n readonly error: E;\n constructor(error: E) {\n super(\"unthrown: called unwrap on a non-matching Result\", { cause: error });\n this.name = \"UnwrapError\";\n this.error = error;\n Object.setPrototypeOf(this, new.target.prototype);\n }\n}\n\n/**\n * Method holder for {@link Result}. Never instantiated with `new` and never\n * exported; the builders below attach its prototype to plain objects. Every\n * method types `this` as the public `Result` union, so it narrows on `tag`.\n *\n * @internal\n */\nclass Res<T, E> {\n map<U>(this: Result<T, E>, f: (value: T) => U & NotThenable<U>): Result<U, E> {\n if (this.tag !== \"Ok\") return passThrough(this);\n try {\n return okRes(f(this.value));\n } catch (cause) {\n return defectRes(cause);\n }\n }\n\n flatMap<U, E2>(this: Result<T, E>, f: (value: T) => Result<U, E2>): Result<U, E | E2> {\n if (this.tag !== \"Ok\") return passThrough(this);\n try {\n return f(this.value);\n } catch (cause) {\n return defectRes(cause);\n }\n }\n\n tap<R>(this: Result<T, E>, f: (value: T) => R & NotThenable<R>): Result<T, E> {\n if (this.tag !== \"Ok\") return this;\n try {\n f(this.value);\n return this;\n } catch (cause) {\n return defectRes(cause);\n }\n }\n\n flatTap<E2>(this: Result<T, E>, f: (value: T) => Result<unknown, E2>): Result<T, E | E2> {\n if (this.tag !== \"Ok\") return this;\n try {\n const r = f(this.value);\n // Keep the original value on success; an Err/Defect from `f` short-circuits.\n return r.tag === \"Ok\" ? this : passThrough(r);\n } catch (cause) {\n return defectRes(cause);\n }\n }\n\n bind<K extends string, U, E2>(\n this: Result<T, E>,\n name: K,\n f: (scope: T) => Result<U, E2>,\n ): Result<Bound<T, K, U>, E | E2> {\n if (this.tag !== \"Ok\") return passThrough(this);\n try {\n const r = f(this.value);\n if (r.tag !== \"Ok\") return passThrough(r);\n // The merged scope can't be spelled at the type level (a computed key\n // widens to an index signature), so the constructed Ok is cast to `Bound`.\n return okRes({ ...scopeOf(this.value), [name]: r.value }) as unknown as Result<\n Bound<T, K, U>,\n E | E2\n >;\n } catch (cause) {\n return defectRes(cause);\n }\n }\n\n let<K extends string, U>(\n this: Result<T, E>,\n name: K,\n f: (scope: T) => U & NotThenable<U>,\n ): Result<Bound<T, K, U>, E> {\n if (this.tag !== \"Ok\") return passThrough(this);\n try {\n return okRes({ ...scopeOf(this.value), [name]: f(this.value) }) as unknown as Result<\n Bound<T, K, U>,\n E\n >;\n } catch (cause) {\n return defectRes(cause);\n }\n }\n\n as<U>(this: Result<T, E>, value: U): Result<U, E> {\n if (this.tag !== \"Ok\") return passThrough(this);\n return okRes(value);\n }\n\n mapErr<E2>(this: Result<T, E>, f: (error: E) => E2 & NotThenable<E2>): Result<T, E2> {\n if (this.tag !== \"Err\") return passThrough(this);\n try {\n return errRes(f(this.error));\n } catch (cause) {\n return defectRes(cause);\n }\n }\n\n orElse<U, E2>(this: Result<T, E>, f: (error: E) => Result<U, E2>): Result<T | U, E2> {\n if (this.tag !== \"Err\") return passThrough(this);\n try {\n return f(this.error);\n } catch (cause) {\n return defectRes(cause);\n }\n }\n\n recover<U>(this: Result<T, E>, f: (error: E) => U & NotThenable<U>): Result<T | U, never> {\n if (this.tag !== \"Err\") return passThrough(this);\n try {\n return okRes(f(this.error));\n } catch (cause) {\n return defectRes(cause);\n }\n }\n\n tapErr<R>(this: Result<T, E>, f: (error: E) => R & NotThenable<R>): Result<T, E> {\n if (this.tag !== \"Err\") return this;\n try {\n f(this.error);\n return this;\n } catch (cause) {\n return observerThrowToDefect(cause, this.error);\n }\n }\n\n flatTapErr<E2>(this: Result<T, E>, f: (error: E) => Result<unknown, E2>): Result<T, E | E2> {\n if (this.tag !== \"Err\") return this;\n try {\n const r = f(this.error);\n // Keep the original error on the effect's success; an Err/Defect threads through.\n return r.tag === \"Ok\" ? this : passThrough(r);\n } catch (cause) {\n return observerThrowToDefect(cause, this.error);\n }\n }\n\n recoverDefect<U, E2>(\n this: Result<T, E>,\n f: (cause: unknown) => Result<U, E2>,\n ): Result<T | U, E | E2> {\n if (this.tag !== \"Defect\") return this;\n try {\n return f(this.cause);\n } catch (cause) {\n return defectRes(cause);\n }\n }\n\n tapDefect<R>(this: Result<T, E>, f: (cause: unknown) => R & NotThenable<R>): Result<T, E> {\n if (this.tag !== \"Defect\") return this;\n try {\n f(this.cause);\n return this;\n } catch (cause) {\n return observerThrowToDefect(cause, this.cause);\n }\n }\n\n match<R>(\n this: Result<T, E>,\n cases: {\n ok: (value: T) => R;\n err: (error: E) => R;\n defect: (cause: unknown) => R;\n },\n ): R {\n switch (this.tag) {\n case \"Ok\":\n return cases.ok(this.value);\n case \"Err\":\n return cases.err(this.error);\n case \"Defect\":\n return cases.defect(this.cause);\n }\n }\n\n unwrap(this: Result<T, E>): T {\n switch (this.tag) {\n case \"Ok\":\n return this.value;\n case \"Err\":\n throw new UnwrapError(this.error);\n case \"Defect\":\n throw this.cause; // rethrow original cause, original stack\n }\n }\n\n unwrapErr(this: Result<T, E>): E {\n switch (this.tag) {\n case \"Err\":\n return this.error;\n case \"Ok\":\n throw new UnwrapError(this.value);\n case \"Defect\":\n throw this.cause;\n }\n }\n\n unwrapOr<U>(this: Result<T, E>, fallback: U): T | U {\n if (this.tag === \"Ok\") return this.value;\n if (this.tag === \"Defect\") throw this.cause;\n return fallback;\n }\n\n unwrapOrElse<U>(this: Result<T, E>, f: (error: E) => U): T | U {\n if (this.tag === \"Ok\") return this.value;\n if (this.tag === \"Defect\") throw this.cause;\n return f(this.error);\n }\n\n getOrNull(this: Result<T, E>): T | null {\n if (this.tag === \"Ok\") return this.value;\n if (this.tag === \"Defect\") throw this.cause;\n return null;\n }\n\n getOrUndefined(this: Result<T, E>): T | undefined {\n if (this.tag === \"Ok\") return this.value;\n if (this.tag === \"Defect\") throw this.cause;\n return undefined;\n }\n\n isOk(this: Result<T, E>): this is OkView<T, E> {\n return this.tag === \"Ok\";\n }\n\n isErr(this: Result<T, E>): this is ErrView<E, T> {\n return this.tag === \"Err\";\n }\n\n isDefect(this: Result<T, E>): this is DefectView<T, E> {\n return this.tag === \"Defect\";\n }\n\n toAsync(this: Result<T, E>): AsyncResult<T, E> {\n return new AsyncRes<T, E>(Promise.resolve(this));\n }\n}\n\nconst RESULT_PROTO = Res.prototype;\n\n/**\n * Construct an `Ok` result — a plain object on the {@link Res} prototype.\n *\n * @internal\n */\nexport function okRes<T, E>(value: T): Result<T, E> {\n // Frozen so the `readonly` surface is real at runtime: a variant cannot be\n // forged by mutating `tag`/payload after construction.\n return Object.freeze(\n Object.assign(Object.create(RESULT_PROTO), {\n tag: \"Ok\" as const,\n value,\n }),\n ) as OkView<T, E>;\n}\n\n/**\n * Construct an `Err` result.\n *\n * @internal\n */\nexport function errRes<T, E>(error: E): Result<T, E> {\n return Object.freeze(\n Object.assign(Object.create(RESULT_PROTO), {\n tag: \"Err\" as const,\n error,\n }),\n ) as ErrView<E, T>;\n}\n\n/**\n * Construct a `Defect` result.\n *\n * @internal\n */\nexport function defectRes<T, E>(cause: unknown): Result<T, E> {\n return Object.freeze(\n Object.assign(Object.create(RESULT_PROTO), {\n tag: \"Defect\" as const,\n cause,\n }),\n ) as DefectView<T, E>;\n}\n\n/**\n * Type guard: is `x` a {@link Result} (any of `Ok` / `Err` / `Defect`)?\n *\n * @remarks\n * Unlike {@link isOk} / {@link isErr} / {@link isDefect}, which narrow a value\n * already known to be a `Result`, this narrows from `unknown` — useful at an\n * untyped boundary. It checks the value carries the `Result` prototype, so a\n * look-alike plain object (`{ tag: \"Ok\" }`) is **not** matched. An `AsyncResult`\n * is not a `Result` and returns `false`.\n *\n * @returns `true` when `x` is a `Result` produced by this library.\n *\n * @example\n * ```ts\n * import { isResult, Ok } from \"unthrown\";\n *\n * isResult(Ok(1)); // => true\n * isResult({ tag: \"Ok\" }); // => false (look-alike, wrong prototype)\n * isResult(Ok(1).toAsync()); // => false (an AsyncResult is not a Result)\n *\n * const x: unknown = Ok(1);\n * if (isResult(x)) x.match({ ok: () => 1, err: () => 0, defect: () => -1 });\n * ```\n *\n * @category Guards\n */\nexport function isResult(x: unknown): x is Result<unknown, unknown> {\n return x instanceof Res;\n}\n\n/**\n * Reuse a non-matching variant (an `Err` or `Defect`) as a differently-typed\n * `Result`, with no runtime work. Sound because the passed-through variant\n * carries no value of the changed success type, so retyping it is a no-op — only\n * the phantom type parameter moves. This is the single sanctioned home for that\n * assertion (the same one boxed applies inline at every pass-through); every\n * combinator's short-circuit branch funnels through here instead of casting.\n *\n * @internal\n */\nfunction passThrough<T, E>(self: Result<unknown, unknown>): Result<T, E> {\n return self as unknown as Result<T, E>;\n}\n\n/**\n * A throw inside a *failure observer* (`tapErr` / `tapDefect` / `flatTapErr`)\n * must not destroy the failure being observed — that is the exact place (e.g. a\n * failing error-logger) where losing the underlying failure hurts most. The\n * resulting Defect aggregates both: `errors[0]` is the observer's throw,\n * `errors[1]` the original failure.\n *\n * @internal\n */\nfunction observerThrowToDefect<T, E>(thrown: unknown, original: unknown): Result<T, E> {\n return defectRes(\n new AggregateError(\n [thrown, original],\n \"unthrown: a failure-observer callback threw; errors[0] is the callback's throw, errors[1] the original failure\",\n ),\n );\n}\n\n/**\n * Validate that a `bind`/`let` scope is a real (non-null) object before merging a\n * key into it.\n *\n * @remarks\n * Do-notation accumulates an **object** scope: a chain starts at `Do()` (an\n * empty object) and every `bind`/`let` returns an object, so in typed code the\n * scope is always an object. The method lives on the general `Result` surface,\n * though, so a primitive `Ok` (e.g. `Ok(5).bind(...)`, or a chain whose value was\n * `map`-ped away from its scope) could reach it. Rather than let `{ ...5 }`\n * silently collapse to `{}` and drop the prior scope, we throw here — the\n * surrounding `try` turns it into a `Defect`, surfacing the misuse as the\n * bug it is (a defect is a bug, not an absent value). A `this: object` constraint\n * was rejected: TypeScript does not hard-enforce a constraint inferred solely\n * from `this`, and it breaks `AsyncRes implements AsyncResult`.\n *\n * @internal\n */\nfunction scopeOf(value: unknown): object {\n if (typeof value !== \"object\" || value === null || Array.isArray(value)) {\n throw new TypeError(\"bind/let requires an object scope — start a do-chain with Do()\");\n }\n return value;\n}\n\n/**\n * The sole runtime implementation of {@link AsyncResult}: wraps a\n * `Promise<Result>` constructed never to reject. Operates on the public `Result`\n * union (via `tag`), never on `Res` internals. Never re-exported from `index.ts`.\n *\n * @internal\n */\nexport class AsyncRes<T, E> implements AsyncResult<T, E> {\n constructor(private readonly promise: Promise<Result<T, E>>) {}\n\n // oxlint-disable-next-line no-thenable -- AsyncResult is an intentional (success-only) thenable so `await` collapses it to a Result; see the Awaitable type. onrejected is still forwarded so a hypothetical internal rejection settles the await instead of hanging — though the internal promise never rejects.\n then<R1 = Result<T, E>, R2 = never>(\n onfulfilled?: ((value: Result<T, E>) => R1 | PromiseLike<R1>) | null,\n onrejected?: ((reason: unknown) => R2 | PromiseLike<R2>) | null,\n ): PromiseLike<R1 | R2> {\n return this.promise.then(onfulfilled, onrejected);\n }\n\n map<U>(f: (value: T) => U & NotThenable<U>): AsyncResult<U, E> {\n return new AsyncRes<U, E>(\n this.promise.then((r) => {\n if (r.tag !== \"Ok\") return passThrough(r);\n try {\n return okRes(f(r.value));\n } catch (cause) {\n return defectRes(cause);\n }\n }),\n );\n }\n\n flatMap<U, E2>(f: (value: T) => Result<U, E2> | AsyncResult<U, E2>): AsyncResult<U, E | E2> {\n return new AsyncRes<U, E | E2>(\n this.promise.then(async (r) => {\n if (r.tag !== \"Ok\") return passThrough(r);\n try {\n return await f(r.value);\n } catch (cause) {\n return defectRes(cause);\n }\n }),\n );\n }\n\n tap<R>(f: (value: T) => R & NotThenable<R>): AsyncResult<T, E> {\n return new AsyncRes<T, E>(\n this.promise.then((r) => {\n if (r.tag !== \"Ok\") return r;\n try {\n f(r.value);\n return r;\n } catch (cause) {\n return defectRes<T, E>(cause);\n }\n }),\n );\n }\n\n flatTap<E2>(\n f: (value: T) => Result<unknown, E2> | AsyncResult<unknown, E2>,\n ): AsyncResult<T, E | E2> {\n return new AsyncRes<T, E | E2>(\n this.promise.then(async (r) => {\n if (r.tag !== \"Ok\") return passThrough(r);\n try {\n const inner = await f(r.value);\n // Keep the original value on success; an Err/Defect from `f` wins.\n return inner.tag === \"Ok\" ? r : passThrough(inner);\n } catch (cause) {\n return defectRes(cause);\n }\n }),\n );\n }\n\n bind<K extends string, U, E2>(\n name: K,\n f: (scope: T) => Result<U, E2> | AsyncResult<U, E2>,\n ): AsyncResult<Bound<T, K, U>, E | E2> {\n return new AsyncRes<Bound<T, K, U>, E | E2>(\n this.promise.then(async (r) => {\n if (r.tag !== \"Ok\") return passThrough(r);\n try {\n const inner = await f(r.value);\n if (inner.tag !== \"Ok\") return passThrough(inner);\n return okRes({ ...scopeOf(r.value), [name]: inner.value }) as unknown as Result<\n Bound<T, K, U>,\n E | E2\n >;\n } catch (cause) {\n return defectRes(cause);\n }\n }),\n );\n }\n\n let<K extends string, U>(\n name: K,\n f: (scope: T) => U & NotThenable<U>,\n ): AsyncResult<Bound<T, K, U>, E> {\n return new AsyncRes<Bound<T, K, U>, E>(\n this.promise.then((r) => {\n if (r.tag !== \"Ok\") return passThrough(r);\n try {\n return okRes({ ...scopeOf(r.value), [name]: f(r.value) }) as unknown as Result<\n Bound<T, K, U>,\n E\n >;\n } catch (cause) {\n return defectRes(cause);\n }\n }),\n );\n }\n\n as<U>(value: U): AsyncResult<U, E> {\n return new AsyncRes<U, E>(\n this.promise.then((r) => (r.tag === \"Ok\" ? okRes<U, E>(value) : passThrough(r))),\n );\n }\n\n mapErr<E2>(f: (error: E) => E2 & NotThenable<E2>): AsyncResult<T, E2> {\n return new AsyncRes<T, E2>(\n this.promise.then((r) => {\n if (r.tag !== \"Err\") return passThrough(r);\n try {\n return errRes(f(r.error));\n } catch (cause) {\n return defectRes(cause);\n }\n }),\n );\n }\n\n orElse<U, E2>(f: (error: E) => Result<U, E2> | AsyncResult<U, E2>): AsyncResult<T | U, E2> {\n return new AsyncRes<T | U, E2>(\n this.promise.then(async (r) => {\n if (r.tag !== \"Err\") return passThrough(r);\n try {\n return await f(r.error);\n } catch (cause) {\n return defectRes(cause);\n }\n }),\n );\n }\n\n recover<U>(f: (error: E) => U & NotThenable<U>): AsyncResult<T | U, never> {\n return new AsyncRes<T | U, never>(\n this.promise.then((r) => {\n if (r.tag !== \"Err\") return passThrough(r);\n try {\n return okRes<T | U, never>(f(r.error));\n } catch (cause) {\n return defectRes(cause);\n }\n }),\n );\n }\n\n tapErr<R>(f: (error: E) => R & NotThenable<R>): AsyncResult<T, E> {\n return new AsyncRes<T, E>(\n this.promise.then((r) => {\n if (r.tag !== \"Err\") return r;\n try {\n f(r.error);\n return r;\n } catch (cause) {\n return observerThrowToDefect<T, E>(cause, r.error);\n }\n }),\n );\n }\n\n flatTapErr<E2>(\n f: (error: E) => Result<unknown, E2> | AsyncResult<unknown, E2>,\n ): AsyncResult<T, E | E2> {\n return new AsyncRes<T, E | E2>(\n this.promise.then(async (r) => {\n if (r.tag !== \"Err\") return passThrough(r);\n try {\n const inner = await f(r.error);\n // Keep the original error on success; an Err/Defect from `f` wins.\n return inner.tag === \"Ok\" ? passThrough(r) : passThrough(inner);\n } catch (cause) {\n return observerThrowToDefect(cause, r.error);\n }\n }),\n );\n }\n\n recoverDefect<U, E2>(\n f: (cause: unknown) => Result<U, E2> | AsyncResult<U, E2>,\n ): AsyncResult<T | U, E | E2> {\n return new AsyncRes<T | U, E | E2>(\n this.promise.then(async (r) => {\n if (r.tag !== \"Defect\") return r;\n try {\n return await f(r.cause);\n } catch (cause) {\n return defectRes(cause);\n }\n }),\n );\n }\n\n tapDefect<R>(f: (cause: unknown) => R & NotThenable<R>): AsyncResult<T, E> {\n return new AsyncRes<T, E>(\n this.promise.then((r) => {\n if (r.tag !== \"Defect\") return r;\n try {\n f(r.cause);\n return r;\n } catch (cause) {\n return observerThrowToDefect<T, E>(cause, r.cause);\n }\n }),\n );\n }\n\n match<R>(cases: {\n ok: (value: T) => R;\n err: (error: E) => R;\n defect: (cause: unknown) => R;\n }): Promise<R> {\n return this.promise.then((r) => r.match(cases));\n }\n\n unwrap(): Promise<T> {\n return this.promise.then((r) => r.unwrap());\n }\n unwrapErr(): Promise<E> {\n return this.promise.then((r) => r.unwrapErr());\n }\n unwrapOr<U>(fallback: U): Promise<T | U> {\n return this.promise.then((r) => r.unwrapOr(fallback));\n }\n unwrapOrElse<U>(f: (error: E) => U): Promise<T | U> {\n return this.promise.then((r) => r.unwrapOrElse(f));\n }\n getOrNull(): Promise<T | null> {\n return this.promise.then((r) => r.getOrNull());\n }\n getOrUndefined(): Promise<T | undefined> {\n return this.promise.then((r) => r.getOrUndefined());\n }\n}\n","// Result constructors and the standalone narrowing guards.\n\nimport { errRes, okRes } from \"./core.js\";\nimport type { DefectView, ErrView, OkView, Result } from \"./types.js\";\n\n/**\n * Construct a successful {@link Result}.\n *\n * @typeParam T - the success value type.\n * @param value - the success value to wrap.\n *\n * @example\n * ```ts\n * import { Ok } from \"unthrown\";\n *\n * Ok(2).map((n) => n + 1); // => Ok(3)\n * Ok(42).unwrap(); // => 42\n * ```\n *\n * @category Constructors\n */\nexport function Ok<T>(value: T): Result<T, never> {\n return okRes(value);\n}\n\n/**\n * Construct a failed {@link Result} carrying a **modeled** error.\n *\n * @typeParam E - the modeled error type.\n * @param error - the domain error to wrap.\n *\n * @example\n * ```ts\n * import { Err } from \"unthrown\";\n *\n * Err(\"not_found\").map((n) => n + 1); // => Err(\"not_found\") (map skipped)\n * Err(\"not_found\").unwrapErr(); // => \"not_found\"\n * ```\n *\n * @category Constructors\n */\nexport function Err<E>(error: E): Result<never, E> {\n return errRes(error);\n}\n\n/**\n * Type guard: narrow a {@link Result} to its `Ok` variant, exposing `.value`.\n *\n * @returns `true` when `r` is `Ok`.\n *\n * @example\n * ```ts\n * import { isOk, Ok, Err, type Result } from \"unthrown\";\n *\n * isOk(Ok(1)); // => true\n * isOk(Err(\"boom\")); // => false\n *\n * declare const r: Result<number, string>;\n * if (isOk(r)) r.value; // number, narrowed\n * ```\n *\n * @category Guards\n */\nexport function isOk<T, E>(r: Result<T, E>): r is OkView<T, E> {\n return r.tag === \"Ok\";\n}\n/**\n * Type guard: narrow a {@link Result} to its `Err` variant, exposing `.error`.\n *\n * @returns `true` when `r` is `Err`.\n *\n * @example\n * ```ts\n * import { isErr, Ok, Err, type Result } from \"unthrown\";\n *\n * isErr(Err(\"boom\")); // => true\n * isErr(Ok(1)); // => false\n *\n * declare const r: Result<number, string>;\n * if (isErr(r)) r.error; // string, narrowed\n * ```\n *\n * @category Guards\n */\nexport function isErr<T, E>(r: Result<T, E>): r is ErrView<E, T> {\n return r.tag === \"Err\";\n}\n/**\n * Type guard: narrow a {@link Result} to its `Defect` variant, exposing `.cause`.\n *\n * @remarks\n * A `Defect` has no public constructor — it only arises at a boundary (e.g. a\n * callback throwing inside a combinator). This guard is how you detect one.\n *\n * @returns `true` when `r` is a `Defect`.\n *\n * @example\n * ```ts\n * import { isDefect, Ok } from \"unthrown\";\n *\n * // A throw inside a combinator is captured as a Defect:\n * const r = Ok(1).map(() => {\n * throw new Error(\"boom\");\n * });\n * isDefect(r); // => true\n * isDefect(Ok(1)); // => false\n *\n * if (isDefect(r)) r.cause; // unknown, narrowed\n * ```\n *\n * @category Guards\n */\nexport function isDefect<T, E>(r: Result<T, E>): r is DefectView<T, E> {\n return r.tag === \"Defect\";\n}\n","// Do-notation entry point. The `bind` / `let` steps live on the `Result` /\n// `AsyncResult` method surface (core.ts); `Do()` just seeds an empty object\n// scope to grow.\n\nimport { Ok } from \"./constructors.js\";\nimport type { Result } from \"./types.js\";\n\n/**\n * Start a do-notation chain with an empty object scope, grown step by step with\n * `bind` (for `Result`-returning steps) and `let` (for pure values).\n *\n * @remarks\n * Capitalised because `do` is a reserved word. Each step receives the scope\n * accumulated so far; the error types union across `bind`s, and a throw in any\n * step becomes a `Defect`. To go asynchronous, lift the chain with `toAsync()`\n * (then a `bind` may return an `AsyncResult`).\n *\n * @example\n * ```ts\n * import { Do, Ok } from \"unthrown\";\n *\n * const result = Do()\n * .bind(\"user\", () => findUser(id)) // Result<User, NotFound>\n * .bind(\"org\", ({ user }) => findOrg(user.orgId)) // Result<Org, NotFound>\n * .let(\"label\", ({ user, org }) => `${user.name} @ ${org.name}`)\n * .map(({ user, org, label }) => render(user, org, label));\n * // Result<View, NotFound>\n * ```\n *\n * @example\n * ```ts\n * import { Do, Ok, Err } from \"unthrown\";\n *\n * // Ok path — the scope accumulates:\n * Do()\n * .bind(\"a\", () => Ok(2))\n * .let(\"b\", ({ a }) => a * 10)\n * .map(({ a, b }) => a + b); // => Ok(22)\n *\n * // Err path — the first Err short-circuits the rest:\n * Do()\n * .bind(\"a\", () => Err(\"boom\"))\n * .let(\"b\", ({ a }) => a); // => Err(\"boom\")\n * ```\n *\n * @category Do-notation\n */\nexport function Do(): Result<{}, never> {\n return Ok({});\n}\n","// Defect marker plumbing.\n\nconst DEFECT: unique symbol = Symbol(\"unthrown/Defect\");\n\n/**\n * The opaque marker a `qualify` function returns to triage a cause as\n * **unexpected**.\n *\n * @remarks\n * `qualify` (passed to {@link fromPromise} / {@link fromThrowable}) returns\n * `E | Defect`: either a modeled domain error, or a `Defect` produced by the\n * injected `defect` helper to say \"this failure is not modeled\". A `Defect` is\n * opaque — it carries the original cause for the boundary to convert into the\n * third runtime state of a `Result`. It is **not** a public value; the only way\n * to mint one is the `defect` helper the boundary passes to `qualify`.\n *\n * @internal\n */\nexport type Defect = {\n readonly [DEFECT]: true;\n readonly cause: unknown;\n};\n\n/**\n * Wrap a cause as a `Defect` marker — the value returned from a `qualify`\n * function when a failure is **not** a modeled domain error. The boundary\n * (`fromPromise` / `fromThrowable`) passes this in as `qualify`'s second\n * argument, so domain code never imports it.\n *\n * @param cause - the original thrown/rejected value.\n * @returns an opaque Defect marker carrying `cause`.\n *\n * @internal\n */\nexport function defect(cause: unknown): Defect {\n return { [DEFECT]: true, cause };\n}\n\n/**\n * Internal guard for the qualify-time marker. Distinct from the public\n * {@link isDefect} state guard — this one narrows the `E | Defect` union a\n * `qualify` function returns, not a `Result`.\n *\n * @internal\n */\nexport function isDefectMarker(x: unknown): x is Defect {\n return (\n typeof x === \"object\" && x !== null && (x as Record<PropertyKey, unknown>)[DEFECT] === true\n );\n}\n","// Boundary interop and aggregation. Every throwing/rejecting boundary is forced\n// through `qualify`, which triages each cause into a modeled `E` or a `Defect`;\n// there is no path that yields `unknown` in `E`.\n\nimport { AsyncRes, defectRes, errRes, okRes } from \"./core.js\";\nimport { type Defect, defect, isDefectMarker } from \"./defect.js\";\nimport { Err, Ok } from \"./constructors.js\";\nimport type { AsyncErrOf, AsyncOkOf, AsyncResult, ErrOf, OkOf, Result } from \"./types.js\";\n\n/**\n * Bridge a nullable value into a {@link Result}: absence becomes a **modeled**\n * `Err`. The sanctioned alternative to an `Option` type.\n *\n * @remarks\n * `null` and `undefined` map to `Err(onAbsent())`; any other value (including\n * falsy ones like `0`, `\"\"`, `false`) maps to `Ok`.\n *\n * @typeParam T - the (nullable) value type.\n * @typeParam E - the error produced when the value is absent.\n * @param value - the possibly-absent value.\n * @param onAbsent - lazily produces the error for the absent case.\n *\n * @category Interop\n *\n * @example\n * ```ts\n * import { fromNullable } from \"unthrown\";\n *\n * const map = new Map([[\"a\", 1]]);\n * fromNullable(map.get(\"a\"), () => \"absent\").unwrap(); // => 1\n * fromNullable(map.get(\"z\"), () => \"absent\"); // => Err(\"absent\")\n * fromNullable(0, () => \"absent\").unwrap(); // => 0 (falsy but present)\n * ```\n */\nexport function fromNullable<T, E>(\n value: T | null | undefined,\n onAbsent: () => E,\n): Result<NonNullable<T>, E> {\n return value === null || value === undefined ? Err(onAbsent()) : Ok(value as NonNullable<T>);\n}\n\n/**\n * Wrap a throwing synchronous function so it returns a {@link Result} instead of\n * throwing.\n *\n * @remarks\n * `qualify` **must** triage every thrown cause into a modeled error `E` or a\n * `Defect` (via the injected `defect` helper, its second argument) — there is no\n * path that leaves `unknown` in `E`. A throw inside `qualify` itself is treated\n * as a `Defect`.\n *\n * The modeled error type is `Exclude<R, Defect>` — the `Defect` arm of\n * `qualify`'s return is **subtracted** from `E`, never inferred into it. So a\n * `qualify` that returns *only* `defect(cause)` yields `E = never` (a Defect is\n * out-of-band and must not pollute the error channel); reach for\n * {@link fromSafePromise} when every failure is a Defect.\n *\n * @typeParam A - the wrapped function's argument tuple.\n * @typeParam T - the wrapped function's return type.\n * @typeParam R - `qualify`'s return type; the modeled error `E` is\n * `Exclude<R, Defect>` (its `Defect` arm, if any, is subtracted).\n * @param fn - the throwing function to wrap.\n * @param qualify - triages a thrown `cause` into a modeled `E`, or marks it\n * unmodeled by returning `defect(cause)` (the helper passed as its second arg).\n * @returns a function with the same arguments returning `Result<T, E>`.\n *\n * @category Interop\n *\n * @example\n * ```ts\n * import { fromThrowable } from \"unthrown\";\n *\n * // Model the parse failure as an `Err`, everything unexpected as a `Defect`.\n * const parse = fromThrowable(\n * (text: string) => JSON.parse(text) as unknown,\n * (cause, defect) =>\n * cause instanceof SyntaxError ? (\"invalid_json\" as const) : defect(cause),\n * );\n *\n * parse('{\"ok\":true}').unwrap(); // => { ok: true }\n * parse(\"nope\"); // => Err(\"invalid_json\")\n * ```\n */\nexport function fromThrowable<A extends unknown[], T, R>(\n fn: (...args: A) => T,\n qualify: (cause: unknown, defect: (cause: unknown) => Defect) => R,\n): (...args: A) => Result<T, Exclude<R, Defect>> {\n type E = Exclude<R, Defect>;\n const triage = qualify as (cause: unknown, defect: (cause: unknown) => Defect) => E | Defect;\n return (...args: A): Result<T, E> => {\n try {\n return Ok(fn(...args)) as Result<T, E>;\n } catch (cause) {\n return qualifyToResult<T, E>(cause, triage);\n }\n };\n}\n\n/**\n * Wrap a `Promise` (or a thunk producing one) as an {@link AsyncResult}, forcing\n * every rejection to be triaged.\n *\n * @remarks\n * `qualify` **must** map each rejection cause into a modeled error `E` or a\n * `Defect` (via the injected `defect` helper, its second argument). The returned\n * `AsyncResult`'s internal promise never rejects; `await`-ing it always yields a\n * `Result`. A throw inside `qualify` is itself a `Defect`.\n *\n * The modeled error type is `Exclude<R, Defect>` — the `Defect` arm of\n * `qualify`'s return is **subtracted** from `E`, never inferred into it. So a\n * `qualify` that returns *only* `defect(cause)` yields `E = never`; when every\n * rejection is a Defect, prefer {@link fromSafePromise}.\n *\n * @typeParam T - the resolved value type.\n * @typeParam R - `qualify`'s return type; the modeled error `E` is\n * `Exclude<R, Defect>` (its `Defect` arm, if any, is subtracted).\n * @param promise - the promise, or a thunk returning one.\n * @param qualify - triages a rejection `cause` into a modeled `E`, or marks it\n * unmodeled by returning `defect(cause)` (the helper passed as its second arg).\n *\n * @category Interop\n *\n * @example\n * ```ts\n * import { fromPromise } from \"unthrown\";\n *\n * // A rejection with a NotFoundError becomes a modeled `Err`; anything else a Defect.\n * const user = await fromPromise(fetchUser(id), (cause, defect) =>\n * cause instanceof NotFoundError ? (\"not_found\" as const) : defect(cause),\n * );\n *\n * user.unwrap(); // => the fetched user (on success)\n * // when fetchUser rejects with NotFoundError: => Err(\"not_found\")\n * ```\n */\nexport function fromPromise<T, R>(\n promise: Promise<T> | (() => Promise<T>),\n qualify: (cause: unknown, defect: (cause: unknown) => Defect) => R,\n): AsyncResult<T, Exclude<R, Defect>> {\n type E = Exclude<R, Defect>;\n const triage = qualify as (cause: unknown, defect: (cause: unknown) => Defect) => E | Defect;\n // Promise.resolve() also absorbs a non-thenable passed from untyped code, so\n // this boundary never throws synchronously — it exists to prevent throws.\n const p =\n typeof promise === \"function\" ? Promise.resolve().then(promise) : Promise.resolve(promise);\n const settled: Promise<Result<T, E>> = p.then(\n (value) => okRes<T, E>(value),\n (cause) => qualifyToResult<T, E>(cause, triage),\n );\n return new AsyncRes<T, E>(settled);\n}\n\n/**\n * Wrap a `Promise` asserted **not** to fail in any modeled way: any rejection\n * becomes a `Defect`.\n *\n * @remarks\n * Use this only when a rejection genuinely indicates a bug rather than an\n * anticipated outcome — the error channel is `never`, so there is nothing to\n * triage. (`await`-ing still yields a `Result`; it never throws.)\n *\n * @typeParam T - the resolved value type.\n * @param promise - the promise, or a thunk returning one.\n *\n * @category Interop\n *\n * @example\n * ```ts\n * import { fromSafePromise } from \"unthrown\";\n *\n * (await fromSafePromise(Promise.resolve(3))).unwrap(); // => 3\n * // a rejection becomes a Defect (never a modeled Err):\n * await fromSafePromise(Promise.reject(new Error(\"boom\"))); // => Defect(Error(\"boom\"))\n * ```\n */\nexport function fromSafePromise<T>(\n promise: Promise<T> | (() => Promise<T>),\n): AsyncResult<T, never> {\n // Promise.resolve() also absorbs a non-thenable passed from untyped code, so\n // this boundary never throws synchronously — it exists to prevent throws.\n const p =\n typeof promise === \"function\" ? Promise.resolve().then(promise) : Promise.resolve(promise);\n const settled: Promise<Result<T, never>> = p.then(\n (value) => okRes<T, never>(value),\n (cause) => defectRes<T, never>(cause),\n );\n return new AsyncRes<T, never>(settled);\n}\n\nfunction qualifyToResult<T, E>(\n cause: unknown,\n qualify: (cause: unknown, defect: (cause: unknown) => Defect) => E | Defect,\n): Result<T, E> {\n try {\n const q = qualify(cause, defect);\n return isDefectMarker(q) ? defectRes<T, E>(q.cause) : errRes<T, E>(q);\n } catch (qErr) {\n // a throw inside qualify is itself a Defect\n return defectRes<T, E>(qErr);\n }\n}\n\n/**\n * The success channel of {@link all} / {@link allAsync}: a **positional tuple**\n * for a fixed-length input (including the empty tuple), or a homogeneous\n * **array** for a dynamic one.\n *\n * @remarks\n * The split keys off the input's `length`: a fixed tuple has a literal length\n * (`number extends Rs[\"length\"]` is false → keep the positional `Ts`), while a\n * general array has `length: number` (→ collapse to `Ts[number][]`). Checking\n * length rather than `Rs extends [unknown, ...unknown[]]` keeps `all([])` typed\n * as `Result<[], …>` instead of `Result<never[], …>`.\n *\n * @typeParam Rs - the tuple/array of input `Result` types.\n * @typeParam Ts - per-element extracted success types (`OkOf` for `all`,\n * `AsyncOkOf` for `allAsync`).\n * @internal\n */\ntype AllOk<\n Rs extends readonly unknown[],\n Ts extends readonly unknown[],\n> = number extends Rs[\"length\"] ? Ts[number][] : Ts;\n\n/** A record of `Result`s — the input to {@link allFromDict}. */\ntype ResultRecord = Record<string, Result<unknown, unknown>>;\n/** A record of `AsyncResult`s — the input to {@link allFromDictAsync}. */\ntype AsyncResultRecord = Record<string, AsyncResult<unknown, unknown>>;\n\n/**\n * Fold an array of settled `Result`s: first `Err` wins, any `Defect` dominates,\n * else `Ok` of the values array.\n *\n * @internal\n */\nfunction foldArray(results: readonly Result<unknown, unknown>[]): Result<unknown, unknown> {\n let firstErr: Result<unknown, unknown> | undefined;\n let firstDefect: Result<unknown, unknown> | undefined;\n const values: unknown[] = [];\n for (const r of results) {\n if (r.tag === \"Defect\") {\n firstDefect ??= r;\n break; // any Defect dominates — nothing later can change the outcome\n } else if (r.tag === \"Err\") firstErr ??= r;\n else values.push(r.value);\n }\n return firstDefect ?? firstErr ?? Ok(values);\n}\n\n/**\n * Fold a record of settled `Result`s with the same rules, else `Ok` of the\n * record of values. Keys are written with `Object.defineProperty` so a\n * caller-supplied `\"__proto__\"` key cannot pollute the prototype.\n *\n * @internal\n */\nfunction foldRecord(results: ResultRecord): Result<unknown, unknown> {\n let firstErr: Result<unknown, unknown> | undefined;\n let firstDefect: Result<unknown, unknown> | undefined;\n const values: Record<string, unknown> = {};\n for (const [key, r] of Object.entries(results)) {\n if (r.tag === \"Defect\") {\n firstDefect ??= r;\n break; // any Defect dominates — nothing later can change the outcome\n } else if (r.tag === \"Err\") firstErr ??= r;\n else\n Object.defineProperty(values, key, {\n value: r.value,\n enumerable: true,\n writable: true,\n configurable: true,\n });\n }\n return firstDefect ?? firstErr ?? Ok(values);\n}\n\n/**\n * Collect a tuple/array of {@link Result}s into a single `Result` of all their\n * success values.\n *\n * @remarks\n * Short-circuits on the **first** `Err` (later entries are not inspected for\n * their error); any `Defect` present **dominates**, winning even over an earlier\n * `Err`. A **fixed tuple** keeps its positional types — `all([Ok(1), Ok(\"a\")])`\n * is `Result<[number, string], …>` — while a **dynamic array** `Result<T, E>[]`\n * collapses to `Result<T[], E>` with no cast. For a **record** keyed by name,\n * use {@link allFromDict}.\n *\n * @category Aggregate\n *\n * @example\n * ```ts\n * import { all, Ok, Err } from \"unthrown\";\n *\n * all([Ok(1), Ok(\"a\"), Ok(true)]).unwrap(); // => [1, \"a\", true] (typed [number, string, boolean])\n * all([Ok(1), Err(\"e\"), Ok(3)]); // => Err(\"e\") (short-circuits on the first Err)\n * ```\n */\nexport function all<Rs extends readonly Result<unknown, unknown>[]>(\n results: readonly [...Rs],\n): Result<AllOk<Rs, { [K in keyof Rs]: OkOf<Rs[K]> }>, ErrOf<Rs[number]>> {\n return foldArray(results) as unknown as Result<\n AllOk<Rs, { [K in keyof Rs]: OkOf<Rs[K]> }>,\n ErrOf<Rs[number]>\n >;\n}\n\n/**\n * Collect a **record** of {@link Result}s into a single `Result` of a record of\n * their success values — `allFromDict({ a: Result<A, E>, b: Result<B, E> })` is\n * `Result<{ a: A; b: B }, E>`. The named counterpart of {@link all}, for\n * parallel work you'd rather not tuple.\n *\n * @remarks\n * Same folding rules as {@link all}: first `Err` short-circuits, any `Defect`\n * dominates. This is **not** error accumulation.\n *\n * @category Aggregate\n *\n * @example\n * ```ts\n * import { allFromDict, Ok, Err } from \"unthrown\";\n *\n * allFromDict({ id: Ok(1), name: Ok(\"ada\") }).unwrap(); // => { id: 1, name: \"ada\" }\n * allFromDict({ id: Ok(1), name: Err(\"missing\") }); // => Err(\"missing\")\n * ```\n */\nexport function allFromDict<R extends ResultRecord>(\n results: R,\n): Result<{ [K in keyof R]: OkOf<R[K]> }, ErrOf<R[keyof R]>> {\n return foldRecord(results) as unknown as Result<\n { [K in keyof R]: OkOf<R[K]> },\n ErrOf<R[keyof R]>\n >;\n}\n\n/**\n * The asynchronous counterpart of {@link all}: combine a tuple/array of\n * {@link AsyncResult}s into one `AsyncResult` of all their success values.\n *\n * @remarks\n * The inputs are resolved **concurrently** (order preserved); the resolved\n * `Result`s are then folded with the same rules as {@link all} — first `Err`\n * short-circuits, any `Defect` dominates. As ever, the returned `AsyncResult`'s\n * internal promise never rejects. For a **record**, use {@link allFromDictAsync}.\n *\n * @category Aggregate\n *\n * @example\n * ```ts\n * import { allAsync, fromSafePromise } from \"unthrown\";\n *\n * const both = allAsync([fromSafePromise(Promise.resolve(1)), fromSafePromise(Promise.resolve(2))]);\n * (await both).unwrap(); // => [1, 2]\n * ```\n */\nexport function allAsync<Rs extends readonly AsyncResult<unknown, unknown>[]>(\n results: readonly [...Rs],\n): AsyncResult<AllOk<Rs, { [K in keyof Rs]: AsyncOkOf<Rs[K]> }>, AsyncErrOf<Rs[number]>> {\n // Each AsyncResult is a (never-rejecting) thenable, so Promise.all adopts them;\n // `foldArray` then applies the all() rules. The internal promise never rejects.\n const settled = Promise.all(results).then((resolved) =>\n foldArray(resolved as readonly Result<unknown, unknown>[]),\n );\n return new AsyncRes(settled) as unknown as AsyncResult<\n AllOk<Rs, { [K in keyof Rs]: AsyncOkOf<Rs[K]> }>,\n AsyncErrOf<Rs[number]>\n >;\n}\n\n/**\n * The asynchronous counterpart of {@link allFromDict}: combine a record of\n * {@link AsyncResult}s into one `AsyncResult` of a record of their values.\n *\n * @remarks\n * Resolved concurrently (order preserved), folded with the {@link all} rules,\n * and the internal promise never rejects.\n *\n * @category Aggregate\n *\n * @example\n * ```ts\n * import { allFromDictAsync, fromSafePromise } from \"unthrown\";\n *\n * const both = allFromDictAsync({\n * a: fromSafePromise(Promise.resolve(1)),\n * b: fromSafePromise(Promise.resolve(\"x\")),\n * });\n * (await both).unwrap(); // => { a: 1, b: \"x\" }\n * ```\n */\nexport function allFromDictAsync<R extends AsyncResultRecord>(\n results: R,\n): AsyncResult<{ [K in keyof R]: AsyncOkOf<R[K]> }, AsyncErrOf<R[keyof R]>> {\n const entries = Object.entries(results);\n const settled = Promise.all(entries.map(([, ar]) => ar)).then((resolved) => {\n // Null-proto accumulator: pairing resolved values back to keys can't pollute.\n const byKey: ResultRecord = Object.create(null) as ResultRecord;\n entries.forEach(([key], i) => {\n byKey[key] = resolved[i]!;\n });\n return foldRecord(byKey);\n });\n return new AsyncRes(settled) as unknown as AsyncResult<\n { [K in keyof R]: AsyncOkOf<R[K]> },\n AsyncErrOf<R[keyof R]>\n >;\n}\n","// Result facade — a discoverable namespace alias for the standalone entry\n// points. The free functions remain the primary, tree-shakeable API; this\n// object is a separate export, so `import { Ok }` never pulls it in. The value\n// `Result` and the type `Result<T, E>` (types.ts) share a name — the\n// companion-object pattern. See CLAUDE.md → \"Internal design\".\n\nimport { Err, isDefect, isErr, isOk, Ok } from \"./constructors.js\";\nimport { isResult } from \"./core.js\";\nimport { Do } from \"./do.js\";\nimport {\n all,\n allAsync,\n allFromDict,\n allFromDictAsync,\n fromNullable,\n fromPromise,\n fromSafePromise,\n fromThrowable,\n} from \"./interop.js\";\nimport type { AsyncResult as AsyncResultType, Result as ResultType } from \"./types.js\";\n\n/**\n * Companion object grouping the **`Result`-producing** entry points under a\n * single, discoverable namespace: {@link Result.Ok}, {@link Result.Err},\n * {@link Result.Do}, {@link Result.fromNullable}, {@link Result.fromThrowable},\n * {@link Result.all}, {@link Result.allFromDict}, {@link Result.isOk},\n * {@link Result.isErr}, {@link Result.isDefect}, {@link Result.isResult}.\n *\n * @remarks\n * Purely additive sugar — each member **is** the corresponding free function.\n * The free functions remain the primary, tree-shakeable API; importing only\n * `{ Ok }` never pulls this object in. The value `Result` and the type\n * {@link Result} share one name (the companion-object pattern).\n *\n * The **async** entry points live on the sibling {@link AsyncResult} companion\n * (`AsyncResult.fromPromise`, `AsyncResult.all`, …), grouped by what they\n * return — a static lives in exactly one namespace.\n *\n * @category Facade\n *\n * @example\n * ```ts\n * import { Result } from \"unthrown\";\n * Result.Ok(1).flatMap((n) => Result.Ok(n + 1)).unwrap(); // => 2\n * ```\n */\nexport const Result = {\n Ok,\n Err,\n Do,\n fromNullable,\n fromThrowable,\n all,\n allFromDict,\n isOk,\n isErr,\n isDefect,\n isResult,\n} as const;\n\n/**\n * `Result<T, E>` — the core discriminated union. Shares its name with the\n * {@link Result | companion object} above (the value and type are one name); this\n * is the type half.\n *\n * @remarks\n * A `Result` is a discriminated union, so TypeDoc can't list its methods on this\n * alias. Its fluent combinators (`map`, `flatMap`, `match`, `unwrap`, …) are\n * documented one per entry on {@link ResultMethods} — the shared method surface\n * every variant carries. For \"which one do I reach for?\", see the\n * [Choosing a combinator](/guide/choosing-a-combinator) guide.\n *\n * @category Facade\n */\n// Re-alias the Result type into this module so a single `export { Result }`\n// (from index.ts) carries BOTH the companion object above and the type — value\n// and type sharing one name, declaration-merged in one place.\nexport type Result<T, E> = ResultType<T, E>;\n\n/**\n * Companion object grouping the **`AsyncResult`-producing** entry points under\n * the matching namespace: {@link AsyncResult.fromPromise},\n * {@link AsyncResult.fromSafePromise}, {@link AsyncResult.all},\n * {@link AsyncResult.allFromDict}.\n *\n * @remarks\n * The async sibling of {@link Result}. Statics are grouped by what they\n * **return**, so `fromPromise`/`fromSafePromise` and the async aggregates sit\n * here rather than on {@link Result}; the namespace already conveys \"async\", so\n * the aggregates drop the `Async` suffix (`AsyncResult.all` is the free function\n * `allAsync`; `AsyncResult.allFromDict` is `allFromDictAsync`). Like\n * {@link Result}, the free functions remain the primary, tree-shakeable API; the\n * value `AsyncResult` and the type {@link AsyncResult} share one name.\n *\n * @category Facade\n *\n * @example\n * ```ts\n * import { AsyncResult } from \"unthrown\";\n * const user = await AsyncResult.fromPromise(fetchUser(id), (c, defect) => defect(c));\n * user.unwrap(); // => the fetched user (on success)\n * ```\n */\nexport const AsyncResult = {\n fromPromise,\n fromSafePromise,\n all: allAsync,\n allFromDict: allFromDictAsync,\n} as const;\n\n/**\n * `AsyncResult<T, E>` — the async counterpart of {@link Result}. Shares its name\n * with the {@link AsyncResult | companion object} above (value and type are one\n * name); this is the type half.\n *\n * @remarks\n * `AsyncResult` carries the async fluent surface; its combinators (`map`,\n * `flatMap`, `match`, `unwrap`, …) are documented one per entry — with their\n * async signatures — on {@link AsyncResultMethods}. For \"which one do I reach\n * for?\", see the [Choosing a combinator](/guide/choosing-a-combinator) guide.\n *\n * @category Facade\n */\n// Re-alias the AsyncResult type into this module (same companion-object pattern\n// as Result above) so one `export { AsyncResult }` carries value + type.\nexport type AsyncResult<T, E> = AsyncResultType<T, E>;\n","// The TaggedError convention (à la Effect's `Data.TaggedError`) and an\n// exhaustive, zero-dependency fold over a tagged error union.\n\nimport type { AsyncResult, Result } from \"./types.js\";\n\ntype Props = Record<string, unknown>;\n\n/**\n * The instance shape produced by a {@link TaggedError} class: an `Error` plus a\n * `_tag` discriminant and the (readonly) payload fields.\n *\n * @typeParam Tag - the string literal discriminant.\n * @typeParam A - the payload object type.\n *\n * @category Types\n */\nexport type TaggedErrorInstance<Tag extends string, A extends Props> = Error &\n Readonly<Omit<A, \"name\">> & { readonly _tag: Tag };\n\n/**\n * The class constructor returned by {@link TaggedError}. Generic in its payload:\n * apply it with an instantiation expression at the `extends` site.\n *\n * @remarks\n * When the payload is empty, the constructor takes **no** arguments (the\n * `keyof A extends never ? void : A` trick); otherwise it takes the payload. A\n * `name` key is **rejected** (`name?: never`) because it is reserved for the\n * display label — mirroring how {@link TaggedErrorInstance} excludes it — so the\n * reservation is enforced at the call site, not just ignored at runtime.\n *\n * @typeParam Tag - the string literal discriminant.\n *\n * @category Types\n */\nexport type TaggedErrorConstructor<Tag extends string> = {\n new <A extends Props = {}>(\n args: keyof A extends never ? void : A & { readonly name?: never },\n ): TaggedErrorInstance<Tag, A>;\n};\n\n/**\n * Build a base class for a tagged error — a class extending `Error` with a\n * `_tag` string discriminant, in the style of Effect's `Data.TaggedError`.\n *\n * @remarks\n * Extend the returned class to declare a concrete error. Supply the payload with\n * an instantiation expression; omit it for a payload-less error. A `message`\n * field in the payload is forwarded to `Error`. The `_tag` always reflects\n * `tag` and cannot be overridden by the payload. `name` is likewise reserved —\n * it is the display label (set it with `options.name`); a payload `name` is\n * rejected at compile time (and excluded from the instance type), so it can't\n * shadow `Error.name`.\n *\n * `_tag` is the discriminant used by {@link matchTags}; `Error.name` is the\n * human-facing label in stack traces and logs. By default they coincide, but\n * they can be **decoupled** with `options.name` — so a tag can be namespaced for\n * collision-safety (`\"@my-lib/RetryableError\"`) without that slash-prefixed\n * string leaking into `Error.name`:\n *\n * ```ts\n * class RetryableError extends TaggedError(\"@my-lib/RetryableError\", {\n * name: \"RetryableError\",\n * })<{ message: string }> {}\n *\n * const e = new RetryableError({ message: \"boom\" });\n * e._tag; // \"@my-lib/RetryableError\" — namespaced discriminant\n * e.name; // \"RetryableError\" — clean display name\n * ```\n *\n * @typeParam Tag - the string literal discriminant.\n * @param tag - the discriminant value; also the default error `name`.\n * @param options - optional overrides. `options.name` sets `Error.name`\n * independently of `tag` (defaults to `tag`).\n *\n * @category Tagged errors\n *\n * @example\n * ```ts\n * class NotFound extends TaggedError(\"NotFound\") {}\n * class HttpError extends TaggedError(\"HttpError\")<{ status: number }> {}\n *\n * new NotFound()._tag; // => \"NotFound\"\n * new HttpError({ status: 500 }).status; // => 500\n * ```\n */\nexport function TaggedError<Tag extends string>(\n tag: Tag,\n options?: { readonly name?: string },\n): TaggedErrorConstructor<Tag> {\n const displayName = options?.name ?? tag;\n class TaggedErrorBase extends Error {\n readonly _tag!: Tag;\n\n constructor(props?: Props) {\n super(typeof props?.[\"message\"] === \"string\" ? (props[\"message\"] as string) : undefined);\n if (props) Object.assign(this, props);\n // The tag is authoritative — assign it after the payload so it can't be\n // clobbered. `name` is the display label, independent of the discriminant.\n (this as { _tag: Tag })._tag = tag;\n this.name = displayName;\n Object.setPrototypeOf(this, new.target.prototype);\n }\n }\n\n return TaggedErrorBase as unknown as TaggedErrorConstructor<Tag>;\n}\n\n/**\n * The handler object {@link matchTags} requires: a branch per error tag, plus\n * `Ok` and `Defect`. Miss a tag and it will not compile — the exhaustiveness is\n * enforced by the type, with no `.exhaustive()` to forget.\n *\n * @typeParam T - the success value type.\n * @typeParam E - the tagged error union.\n * @typeParam R - the folded result type.\n *\n * @category Types\n */\nexport type TagHandlers<T, E extends { _tag: string }, R> = {\n Ok: (value: T) => R;\n Defect: (cause: unknown) => R;\n} & { [K in E[\"_tag\"]]: (error: Extract<E, { _tag: K }>) => R };\n\n/**\n * The channel-handler names are reserved: an error tag named `\"Ok\"` or\n * `\"Defect\"` would collide with them inside {@link TagHandlers}, so\n * {@link matchTags} rejects such unions at the call site.\n *\n * @internal\n */\ntype ReservedTagError =\n 'unthrown: error tags \"Ok\" and \"Defect\" are reserved by matchTags — rename the colliding tag (TaggedError\\'s options.name can keep the display name)';\n\n/**\n * Exhaustively fold a {@link Result} (or {@link AsyncResult}) whose error type is\n * a tagged union, dispatching each error to the handler matching its `_tag`.\n *\n * @remarks\n * The `handlers` object must provide `Ok`, `Defect`, and exactly one function\n * per error tag; each tag's handler receives the narrowed error variant. A\n * missing tag is a compile error. For an `AsyncResult`, the fold resolves to a\n * `Promise<R>`. At runtime, an error whose `_tag` has no handler (possible only\n * outside the typed contract) is routed to the `Defect` handler — an unmodeled\n * tag is an unmodeled failure. Tags named `\"Ok\"` or `\"Defect\"` are rejected at\n * compile time.\n *\n * @typeParam T - the success value type.\n * @typeParam E - the tagged error union (`E extends { _tag: string }`).\n * @typeParam R - the folded result type.\n * @param result - the result to fold.\n * @param handlers - one branch per channel/tag.\n *\n * @category Tagged errors\n *\n * @example\n * ```ts\n * import { Ok, Err, matchTags, TaggedError, type Result } from \"unthrown\";\n *\n * class NotFound extends TaggedError(\"NotFound\") {}\n * class Forbidden extends TaggedError(\"Forbidden\")<{ user: string }> {}\n *\n * const fold = (r: Result<number, NotFound | Forbidden>) =>\n * matchTags(r, {\n * Ok: (n) => `got ${n}`,\n * Defect: (cause) => `bug: ${String(cause)}`,\n * NotFound: () => \"404\",\n * Forbidden: (e) => `403 for ${e.user}`,\n * });\n *\n * fold(Ok(1)); // => \"got 1\"\n * fold(Err(new Forbidden({ user: \"ada\" }))); // => \"403 for ada\"\n * ```\n */\nexport function matchTags<T, E extends { _tag: string }, R>(\n result: Result<T, E>,\n handlers: TagHandlers<T, E, R> &\n ([Extract<E[\"_tag\"], \"Ok\" | \"Defect\">] extends [never] ? unknown : ReservedTagError),\n): R;\nexport function matchTags<T, E extends { _tag: string }, R>(\n result: AsyncResult<T, E>,\n handlers: TagHandlers<T, E, R> &\n ([Extract<E[\"_tag\"], \"Ok\" | \"Defect\">] extends [never] ? unknown : ReservedTagError),\n): Promise<R>;\nexport function matchTags<T, E extends { _tag: string }, R>(\n result: Result<T, E> | AsyncResult<T, E>,\n handlers: TagHandlers<T, E, R>,\n): R | Promise<R> {\n const onErr = (error: E): R => {\n const tag = error._tag as E[\"_tag\"];\n // `Object.hasOwn` guards against a rogue tag (e.g. \"constructor\") resolving\n // through the prototype chain to an unrelated `Object.prototype` member —\n // only an own property of `handlers` counts as a real handler.\n const handler =\n tag === \"Ok\" || tag === \"Defect\" || !Object.hasOwn(handlers, tag)\n ? undefined\n : (handlers[tag] as unknown as ((e: E) => R) | undefined);\n // An unhandled or reserved tag can only arise outside the typed contract (a\n // widened cast, a JS caller). That is an unmodeled failure — route it to the\n // Defect handler rather than crashing on `undefined(error)`.\n return handler ? handler(error) : handlers.Defect(error);\n };\n // Both Result and AsyncResult share `match`; the cast picks one signature for\n // the call while the public overloads keep the return type correct.\n return (result as Result<T, E>).match({ ok: handlers.Ok, err: onErr, defect: handlers.Defect });\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;;;;;;;;;;;;;;;;;ACzWA,MAAa,SAAS;CACpB;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF;;;;;;;;;;;;;;;;;;;;;;;;;AA6CA,MAAa,cAAc;CACzB;CACA;CACA,KAAK;CACL,aAAa;AACf;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;ACvBA,SAAgB,YACd,KACA,SAC6B;CAC7B,MAAM,cAAc,SAAS,QAAQ;CACrC,MAAM,wBAAwB,MAAM;EAClC;EAEA,YAAY,OAAe;GACzB,MAAM,OAAO,QAAQ,eAAe,WAAY,MAAM,aAAwB,KAAA,CAAS;GACvF,IAAI,OAAO,OAAO,OAAO,MAAM,KAAK;GAGpC,KAAwB,OAAO;GAC/B,KAAK,OAAO;GACZ,OAAO,eAAe,MAAM,IAAI,OAAO,SAAS;EAClD;CACF;CAEA,OAAO;AACT;AA8EA,SAAgB,UACd,QACA,UACgB;CAChB,MAAM,SAAS,UAAgB;EAC7B,MAAM,MAAM,MAAM;EAIlB,MAAM,UACJ,QAAQ,QAAQ,QAAQ,YAAY,CAAC,OAAO,OAAO,UAAU,GAAG,IAC5D,KAAA,IACC,SAAS;EAIhB,OAAO,UAAU,QAAQ,KAAK,IAAI,SAAS,OAAO,KAAK;CACzD;CAGA,OAAQ,OAAwB,MAAM;EAAE,IAAI,SAAS;EAAI,KAAK;EAAO,QAAQ,SAAS;CAAO,CAAC;AAChG"}
1
+ {"version":3,"file":"index.mjs","names":[],"sources":["../src/core.ts","../src/constructors.ts","../src/do.ts","../src/defect.ts","../src/interop.ts","../src/facade.ts","../src/tagged.ts"],"sourcesContent":["// unthrown — the runtime engine.\n//\n// `Result` is the PUBLIC discriminated union (tag/value/error/cause + methods).\n// `Res` is a method holder only: its prototype carries the implementations, and\n// instances are built by `okRes`/`errRes`/`defectRes` with `Object.create` +\n// the variant type — so a builder returns a value that already *is* a union\n// member (no `as unknown as`). `Res` is never exported from `index.ts`.\n// `AsyncRes` wraps a `Promise<Result>` constructed never to reject and operates\n// purely on the public union (via `r.tag`). See CLAUDE.md → \"Internal design\".\n//\n// Type-changing pass-throughs (e.g. `map` reusing an `Err` as a differently-typed\n// `Result`) all funnel through the single `passThrough` helper — one sound\n// `as unknown as` in one place, rather than boxed's inline cast at every branch.\n// The only other casts are the builders' construction (`as OkView`/…) and the\n// `bind`/`let` scope merge (a computed key can't be spelled at the type level).\n\nimport type {\n AsyncResult,\n Bound,\n DefectView,\n ErrView,\n NotThenable,\n OkView,\n Result,\n} from \"./types.js\";\n\n/**\n * Thrown by a {@link Result}'s `unwrap` / `unwrapErr` when the assertion is\n * wrong on a *modeled* result — `unwrap()` on an `Err`, or `unwrapErr()` on an\n * `Ok`.\n *\n * @remarks\n * The offending value is exposed two ways: the typed {@link UnwrapError.error}\n * property for programmatic access, and the standard `Error.cause` for the\n * runtime and devtools to chain — when `E` is an `Error` (e.g. a `TaggedError`)\n * its original stack is printed under \"caused by\".\n *\n * A `Defect` is never wrapped in an `UnwrapError`: its original cause is\n * re-thrown (with its original stack) instead.\n *\n * `unwrap()` and `unwrapErr()` are type-gated (`this: Result<T, never>` /\n * `Result<never, E>`), so the wrong-variant branch that throws this is\n * unreachable through well-typed code — it remains only as a defensive guard\n * against unsound runtime misuse (e.g. an `as` cast past the gate).\n *\n * @typeParam E - the type of the {@link UnwrapError.error} it carries.\n *\n * @category Errors\n */\nexport class UnwrapError<E = unknown> extends Error {\n /**\n * The offending value: the `Err` error for `unwrap()`, or the `Ok` value for\n * `unwrapErr()`.\n */\n readonly error: E;\n constructor(error: E) {\n super(\"unthrown: called unwrap on a non-matching Result\", { cause: error });\n this.name = \"UnwrapError\";\n this.error = error;\n Object.setPrototypeOf(this, new.target.prototype);\n }\n}\n\n/**\n * Method holder for {@link Result}. Never instantiated with `new` and never\n * exported; the builders below attach its prototype to plain objects. Every\n * method types `this` as the public `Result` union, so it narrows on `tag`.\n *\n * @internal\n */\nclass Res<T, E> {\n map<U>(this: Result<T, E>, f: (value: T) => U & NotThenable<U>): Result<U, E> {\n if (this.tag !== \"Ok\") return passThrough(this);\n try {\n return okRes(f(this.value));\n } catch (cause) {\n return defectRes(cause);\n }\n }\n\n flatMap<U, E2>(this: Result<T, E>, f: (value: T) => Result<U, E2>): Result<U, E | E2> {\n if (this.tag !== \"Ok\") return passThrough(this);\n try {\n return f(this.value);\n } catch (cause) {\n return defectRes(cause);\n }\n }\n\n tap<R>(this: Result<T, E>, f: (value: T) => R & NotThenable<R>): Result<T, E> {\n if (this.tag !== \"Ok\") return this;\n try {\n f(this.value);\n return this;\n } catch (cause) {\n return defectRes(cause);\n }\n }\n\n flatTap<E2>(this: Result<T, E>, f: (value: T) => Result<unknown, E2>): Result<T, E | E2> {\n if (this.tag !== \"Ok\") return this;\n try {\n const r = f(this.value);\n // Keep the original value on success; an Err/Defect from `f` short-circuits.\n return r.tag === \"Ok\" ? this : passThrough(r);\n } catch (cause) {\n return defectRes(cause);\n }\n }\n\n bind<K extends string, U, E2>(\n this: Result<T, E>,\n name: K,\n f: (scope: T) => Result<U, E2>,\n ): Result<Bound<T, K, U>, E | E2> {\n if (this.tag !== \"Ok\") return passThrough(this);\n try {\n const r = f(this.value);\n if (r.tag !== \"Ok\") return passThrough(r);\n // The merged scope can't be spelled at the type level (a computed key\n // widens to an index signature), so the constructed Ok is cast to `Bound`.\n return okRes({ ...scopeOf(this.value), [name]: r.value }) as unknown as Result<\n Bound<T, K, U>,\n E | E2\n >;\n } catch (cause) {\n return defectRes(cause);\n }\n }\n\n let<K extends string, U>(\n this: Result<T, E>,\n name: K,\n f: (scope: T) => U & NotThenable<U>,\n ): Result<Bound<T, K, U>, E> {\n if (this.tag !== \"Ok\") return passThrough(this);\n try {\n return okRes({ ...scopeOf(this.value), [name]: f(this.value) }) as unknown as Result<\n Bound<T, K, U>,\n E\n >;\n } catch (cause) {\n return defectRes(cause);\n }\n }\n\n as<U>(this: Result<T, E>, value: U): Result<U, E> {\n if (this.tag !== \"Ok\") return passThrough(this);\n return okRes(value);\n }\n\n mapErr<E2>(this: Result<T, E>, f: (error: E) => E2 & NotThenable<E2>): Result<T, E2> {\n if (this.tag !== \"Err\") return passThrough(this);\n try {\n return errRes(f(this.error));\n } catch (cause) {\n return defectRes(cause);\n }\n }\n\n orElse<U, E2>(this: Result<T, E>, f: (error: E) => Result<U, E2>): Result<T | U, E2> {\n if (this.tag !== \"Err\") return passThrough(this);\n try {\n return f(this.error);\n } catch (cause) {\n return defectRes(cause);\n }\n }\n\n recover<U>(this: Result<T, E>, f: (error: E) => U & NotThenable<U>): Result<T | U, never> {\n if (this.tag !== \"Err\") return passThrough(this);\n try {\n return okRes(f(this.error));\n } catch (cause) {\n return defectRes(cause);\n }\n }\n\n tapErr<R>(this: Result<T, E>, f: (error: E) => R & NotThenable<R>): Result<T, E> {\n if (this.tag !== \"Err\") return this;\n try {\n f(this.error);\n return this;\n } catch (cause) {\n return observerThrowToDefect(cause, this.error);\n }\n }\n\n flatTapErr<E2>(this: Result<T, E>, f: (error: E) => Result<unknown, E2>): Result<T, E | E2> {\n if (this.tag !== \"Err\") return this;\n try {\n const r = f(this.error);\n // Keep the original error on the effect's success; an Err/Defect threads through.\n return r.tag === \"Ok\" ? this : passThrough(r);\n } catch (cause) {\n return observerThrowToDefect(cause, this.error);\n }\n }\n\n recoverDefect<U, E2>(\n this: Result<T, E>,\n f: (cause: unknown) => Result<U, E2>,\n ): Result<T | U, E | E2> {\n if (this.tag !== \"Defect\") return this;\n try {\n return f(this.cause);\n } catch (cause) {\n return defectRes(cause);\n }\n }\n\n tapDefect<R>(this: Result<T, E>, f: (cause: unknown) => R & NotThenable<R>): Result<T, E> {\n if (this.tag !== \"Defect\") return this;\n try {\n f(this.cause);\n return this;\n } catch (cause) {\n return observerThrowToDefect(cause, this.cause);\n }\n }\n\n match<R>(\n this: Result<T, E>,\n cases: {\n ok: (value: T) => R;\n err: (error: E) => R;\n defect: (cause: unknown) => R;\n },\n ): R {\n switch (this.tag) {\n case \"Ok\":\n return cases.ok(this.value);\n case \"Err\":\n return cases.err(this.error);\n case \"Defect\":\n return cases.defect(this.cause);\n }\n }\n\n unwrap(this: Result<T, E>): T {\n switch (this.tag) {\n case \"Ok\":\n return this.value;\n case \"Err\":\n throw new UnwrapError(this.error);\n case \"Defect\":\n throw this.cause; // rethrow original cause, original stack\n }\n }\n\n unwrapErr(this: Result<T, E>): E {\n switch (this.tag) {\n case \"Err\":\n return this.error;\n case \"Ok\":\n throw new UnwrapError(this.value);\n case \"Defect\":\n throw this.cause;\n }\n }\n\n unwrapOr<U>(this: Result<T, E>, fallback: U): T | U {\n if (this.tag === \"Ok\") return this.value;\n if (this.tag === \"Defect\") throw this.cause;\n return fallback;\n }\n\n unwrapOrElse<U>(this: Result<T, E>, f: (error: E) => U): T | U {\n if (this.tag === \"Ok\") return this.value;\n if (this.tag === \"Defect\") throw this.cause;\n return f(this.error);\n }\n\n getOrNull(this: Result<T, E>): T | null {\n if (this.tag === \"Ok\") return this.value;\n if (this.tag === \"Defect\") throw this.cause;\n return null;\n }\n\n getOrUndefined(this: Result<T, E>): T | undefined {\n if (this.tag === \"Ok\") return this.value;\n if (this.tag === \"Defect\") throw this.cause;\n return undefined;\n }\n\n isOk(this: Result<T, E>): this is OkView<T, E> {\n return this.tag === \"Ok\";\n }\n\n isErr(this: Result<T, E>): this is ErrView<E, T> {\n return this.tag === \"Err\";\n }\n\n isDefect(this: Result<T, E>): this is DefectView<T, E> {\n return this.tag === \"Defect\";\n }\n\n toAsync(this: Result<T, E>): AsyncResult<T, E> {\n return new AsyncRes<T, E>(Promise.resolve(this));\n }\n}\n\nconst RESULT_PROTO = Res.prototype;\n\n/**\n * Construct an `Ok` result — a plain object on the {@link Res} prototype.\n *\n * @internal\n */\nexport function okRes<T, E>(value: T): Result<T, E> {\n // Frozen so the `readonly` surface is real at runtime: a variant cannot be\n // forged by mutating `tag`/payload after construction.\n return Object.freeze(\n Object.assign(Object.create(RESULT_PROTO), {\n tag: \"Ok\" as const,\n value,\n }),\n ) as OkView<T, E>;\n}\n\n/**\n * Construct an `Err` result.\n *\n * @internal\n */\nexport function errRes<T, E>(error: E): Result<T, E> {\n return Object.freeze(\n Object.assign(Object.create(RESULT_PROTO), {\n tag: \"Err\" as const,\n error,\n }),\n ) as ErrView<E, T>;\n}\n\n/**\n * Construct a `Defect` result.\n *\n * @internal\n */\nexport function defectRes<T, E>(cause: unknown): Result<T, E> {\n return Object.freeze(\n Object.assign(Object.create(RESULT_PROTO), {\n tag: \"Defect\" as const,\n cause,\n }),\n ) as DefectView<T, E>;\n}\n\n/**\n * Type guard: is `x` a {@link Result} (any of `Ok` / `Err` / `Defect`)?\n *\n * @remarks\n * Unlike {@link isOk} / {@link isErr} / {@link isDefect}, which narrow a value\n * already known to be a `Result`, this narrows from `unknown` — useful at an\n * untyped boundary. It checks the value carries the `Result` prototype, so a\n * look-alike plain object (`{ tag: \"Ok\" }`) is **not** matched. An `AsyncResult`\n * is not a `Result` and returns `false`.\n *\n * @returns `true` when `x` is a `Result` produced by this library.\n *\n * @example\n * ```ts\n * import { isResult, Ok } from \"unthrown\";\n *\n * isResult(Ok(1)); // => true\n * isResult({ tag: \"Ok\" }); // => false (look-alike, wrong prototype)\n * isResult(Ok(1).toAsync()); // => false (an AsyncResult is not a Result)\n *\n * const x: unknown = Ok(1);\n * if (isResult(x)) x.match({ ok: () => 1, err: () => 0, defect: () => -1 });\n * ```\n *\n * @category Guards\n */\nexport function isResult(x: unknown): x is Result<unknown, unknown> {\n return x instanceof Res;\n}\n\n/**\n * Reuse a non-matching variant (an `Err` or `Defect`) as a differently-typed\n * `Result`, with no runtime work. Sound because the passed-through variant\n * carries no value of the changed success type, so retyping it is a no-op — only\n * the phantom type parameter moves. This is the single sanctioned home for that\n * assertion (the same one boxed applies inline at every pass-through); every\n * combinator's short-circuit branch funnels through here instead of casting.\n *\n * @internal\n */\nfunction passThrough<T, E>(self: Result<unknown, unknown>): Result<T, E> {\n return self as unknown as Result<T, E>;\n}\n\n/**\n * A throw inside a *failure observer* (`tapErr` / `tapDefect` / `flatTapErr`)\n * must not destroy the failure being observed — that is the exact place (e.g. a\n * failing error-logger) where losing the underlying failure hurts most. The\n * resulting Defect aggregates both: `errors[0]` is the observer's throw,\n * `errors[1]` the original failure.\n *\n * @internal\n */\nfunction observerThrowToDefect<T, E>(thrown: unknown, original: unknown): Result<T, E> {\n return defectRes(\n new AggregateError(\n [thrown, original],\n \"unthrown: a failure-observer callback threw; errors[0] is the callback's throw, errors[1] the original failure\",\n ),\n );\n}\n\n/**\n * Validate that a `bind`/`let` scope is a real (non-null) object before merging a\n * key into it.\n *\n * @remarks\n * Do-notation accumulates an **object** scope: a chain starts at `Do()` (an\n * empty object) and every `bind`/`let` returns an object, so in typed code the\n * scope is always an object. The method lives on the general `Result` surface,\n * though, so a primitive `Ok` (e.g. `Ok(5).bind(...)`, or a chain whose value was\n * `map`-ped away from its scope) could reach it. Rather than let `{ ...5 }`\n * silently collapse to `{}` and drop the prior scope, we throw here — the\n * surrounding `try` turns it into a `Defect`, surfacing the misuse as the\n * bug it is (a defect is a bug, not an absent value). A `this: object` constraint\n * was rejected: TypeScript does not hard-enforce a constraint inferred solely\n * from `this`, and it breaks `AsyncRes implements AsyncResult`.\n *\n * @internal\n */\nfunction scopeOf(value: unknown): object {\n if (typeof value !== \"object\" || value === null || Array.isArray(value)) {\n throw new TypeError(\"bind/let requires an object scope — start a do-chain with Do()\");\n }\n return value;\n}\n\n/**\n * The sole runtime implementation of {@link AsyncResult}: wraps a\n * `Promise<Result>` constructed never to reject. Operates on the public `Result`\n * union (via `tag`), never on `Res` internals. Never re-exported from `index.ts`.\n *\n * @internal\n */\nexport class AsyncRes<T, E> implements AsyncResult<T, E> {\n constructor(private readonly promise: Promise<Result<T, E>>) {}\n\n // oxlint-disable-next-line no-thenable -- AsyncResult is an intentional (success-only) thenable so `await` collapses it to a Result; see the Awaitable type. onrejected is still forwarded so a hypothetical internal rejection settles the await instead of hanging — though the internal promise never rejects.\n then<R1 = Result<T, E>, R2 = never>(\n onfulfilled?: ((value: Result<T, E>) => R1 | PromiseLike<R1>) | null,\n onrejected?: ((reason: unknown) => R2 | PromiseLike<R2>) | null,\n ): PromiseLike<R1 | R2> {\n return this.promise.then(onfulfilled, onrejected);\n }\n\n map<U>(f: (value: T) => U & NotThenable<U>): AsyncResult<U, E> {\n return new AsyncRes<U, E>(\n this.promise.then((r) => {\n if (r.tag !== \"Ok\") return passThrough(r);\n try {\n return okRes(f(r.value));\n } catch (cause) {\n return defectRes(cause);\n }\n }),\n );\n }\n\n flatMap<U, E2>(f: (value: T) => Result<U, E2> | AsyncResult<U, E2>): AsyncResult<U, E | E2> {\n return new AsyncRes<U, E | E2>(\n this.promise.then(async (r) => {\n if (r.tag !== \"Ok\") return passThrough(r);\n try {\n return await f(r.value);\n } catch (cause) {\n return defectRes(cause);\n }\n }),\n );\n }\n\n tap<R>(f: (value: T) => R & NotThenable<R>): AsyncResult<T, E> {\n return new AsyncRes<T, E>(\n this.promise.then((r) => {\n if (r.tag !== \"Ok\") return r;\n try {\n f(r.value);\n return r;\n } catch (cause) {\n return defectRes<T, E>(cause);\n }\n }),\n );\n }\n\n flatTap<E2>(\n f: (value: T) => Result<unknown, E2> | AsyncResult<unknown, E2>,\n ): AsyncResult<T, E | E2> {\n return new AsyncRes<T, E | E2>(\n this.promise.then(async (r) => {\n if (r.tag !== \"Ok\") return passThrough(r);\n try {\n const inner = await f(r.value);\n // Keep the original value on success; an Err/Defect from `f` wins.\n return inner.tag === \"Ok\" ? r : passThrough(inner);\n } catch (cause) {\n return defectRes(cause);\n }\n }),\n );\n }\n\n bind<K extends string, U, E2>(\n name: K,\n f: (scope: T) => Result<U, E2> | AsyncResult<U, E2>,\n ): AsyncResult<Bound<T, K, U>, E | E2> {\n return new AsyncRes<Bound<T, K, U>, E | E2>(\n this.promise.then(async (r) => {\n if (r.tag !== \"Ok\") return passThrough(r);\n try {\n const inner = await f(r.value);\n if (inner.tag !== \"Ok\") return passThrough(inner);\n return okRes({ ...scopeOf(r.value), [name]: inner.value }) as unknown as Result<\n Bound<T, K, U>,\n E | E2\n >;\n } catch (cause) {\n return defectRes(cause);\n }\n }),\n );\n }\n\n let<K extends string, U>(\n name: K,\n f: (scope: T) => U & NotThenable<U>,\n ): AsyncResult<Bound<T, K, U>, E> {\n return new AsyncRes<Bound<T, K, U>, E>(\n this.promise.then((r) => {\n if (r.tag !== \"Ok\") return passThrough(r);\n try {\n return okRes({ ...scopeOf(r.value), [name]: f(r.value) }) as unknown as Result<\n Bound<T, K, U>,\n E\n >;\n } catch (cause) {\n return defectRes(cause);\n }\n }),\n );\n }\n\n as<U>(value: U): AsyncResult<U, E> {\n return new AsyncRes<U, E>(\n this.promise.then((r) => (r.tag === \"Ok\" ? okRes<U, E>(value) : passThrough(r))),\n );\n }\n\n mapErr<E2>(f: (error: E) => E2 & NotThenable<E2>): AsyncResult<T, E2> {\n return new AsyncRes<T, E2>(\n this.promise.then((r) => {\n if (r.tag !== \"Err\") return passThrough(r);\n try {\n return errRes(f(r.error));\n } catch (cause) {\n return defectRes(cause);\n }\n }),\n );\n }\n\n orElse<U, E2>(f: (error: E) => Result<U, E2> | AsyncResult<U, E2>): AsyncResult<T | U, E2> {\n return new AsyncRes<T | U, E2>(\n this.promise.then(async (r) => {\n if (r.tag !== \"Err\") return passThrough(r);\n try {\n return await f(r.error);\n } catch (cause) {\n return defectRes(cause);\n }\n }),\n );\n }\n\n recover<U>(f: (error: E) => U & NotThenable<U>): AsyncResult<T | U, never> {\n return new AsyncRes<T | U, never>(\n this.promise.then((r) => {\n if (r.tag !== \"Err\") return passThrough(r);\n try {\n return okRes<T | U, never>(f(r.error));\n } catch (cause) {\n return defectRes(cause);\n }\n }),\n );\n }\n\n tapErr<R>(f: (error: E) => R & NotThenable<R>): AsyncResult<T, E> {\n return new AsyncRes<T, E>(\n this.promise.then((r) => {\n if (r.tag !== \"Err\") return r;\n try {\n f(r.error);\n return r;\n } catch (cause) {\n return observerThrowToDefect<T, E>(cause, r.error);\n }\n }),\n );\n }\n\n flatTapErr<E2>(\n f: (error: E) => Result<unknown, E2> | AsyncResult<unknown, E2>,\n ): AsyncResult<T, E | E2> {\n return new AsyncRes<T, E | E2>(\n this.promise.then(async (r) => {\n if (r.tag !== \"Err\") return passThrough(r);\n try {\n const inner = await f(r.error);\n // Keep the original error on success; an Err/Defect from `f` wins.\n return inner.tag === \"Ok\" ? passThrough(r) : passThrough(inner);\n } catch (cause) {\n return observerThrowToDefect(cause, r.error);\n }\n }),\n );\n }\n\n recoverDefect<U, E2>(\n f: (cause: unknown) => Result<U, E2> | AsyncResult<U, E2>,\n ): AsyncResult<T | U, E | E2> {\n return new AsyncRes<T | U, E | E2>(\n this.promise.then(async (r) => {\n if (r.tag !== \"Defect\") return r;\n try {\n return await f(r.cause);\n } catch (cause) {\n return defectRes(cause);\n }\n }),\n );\n }\n\n tapDefect<R>(f: (cause: unknown) => R & NotThenable<R>): AsyncResult<T, E> {\n return new AsyncRes<T, E>(\n this.promise.then((r) => {\n if (r.tag !== \"Defect\") return r;\n try {\n f(r.cause);\n return r;\n } catch (cause) {\n return observerThrowToDefect<T, E>(cause, r.cause);\n }\n }),\n );\n }\n\n match<R>(cases: {\n ok: (value: T) => R;\n err: (error: E) => R;\n defect: (cause: unknown) => R;\n }): Promise<R> {\n return this.promise.then((r) => r.match(cases));\n }\n\n unwrap(): Promise<T> {\n return this.promise.then((r) => (r as Result<T, never>).unwrap());\n }\n unwrapErr(): Promise<E> {\n return this.promise.then((r) => (r as Result<never, E>).unwrapErr());\n }\n unwrapOr<U>(fallback: U): Promise<T | U> {\n return this.promise.then((r) => r.unwrapOr(fallback));\n }\n unwrapOrElse<U>(f: (error: E) => U): Promise<T | U> {\n return this.promise.then((r) => r.unwrapOrElse(f));\n }\n getOrNull(): Promise<T | null> {\n return this.promise.then((r) => r.getOrNull());\n }\n getOrUndefined(): Promise<T | undefined> {\n return this.promise.then((r) => r.getOrUndefined());\n }\n}\n","// Result constructors and the standalone narrowing guards.\n\nimport { errRes, okRes } from \"./core.js\";\nimport type { DefectView, ErrView, OkView, Result } from \"./types.js\";\n\n/**\n * Construct a successful {@link Result}.\n *\n * @typeParam T - the success value type.\n * @param value - the success value to wrap.\n *\n * @example\n * ```ts\n * import { Ok } from \"unthrown\";\n *\n * Ok(2).map((n) => n + 1); // => Ok(3)\n * Ok(42).unwrap(); // => 42\n * ```\n *\n * @category Constructors\n */\nexport function Ok<T>(value: T): Result<T, never> {\n return okRes(value);\n}\n\n/**\n * Construct a failed {@link Result} carrying a **modeled** error.\n *\n * @typeParam E - the modeled error type.\n * @param error - the domain error to wrap.\n *\n * @example\n * ```ts\n * import { Err } from \"unthrown\";\n *\n * Err(\"not_found\").map((n) => n + 1); // => Err(\"not_found\") (map skipped)\n * Err(\"not_found\").unwrapErr(); // => \"not_found\"\n * ```\n *\n * @category Constructors\n */\nexport function Err<E>(error: E): Result<never, E> {\n return errRes(error);\n}\n\n/**\n * Type guard: narrow a {@link Result} to its `Ok` variant, exposing `.value`.\n *\n * @returns `true` when `r` is `Ok`.\n *\n * @example\n * ```ts\n * import { isOk, Ok, Err, type Result } from \"unthrown\";\n *\n * isOk(Ok(1)); // => true\n * isOk(Err(\"boom\")); // => false\n *\n * declare const r: Result<number, string>;\n * if (isOk(r)) r.value; // number, narrowed\n * ```\n *\n * @category Guards\n */\nexport function isOk<T, E>(r: Result<T, E>): r is OkView<T, E> {\n return r.tag === \"Ok\";\n}\n/**\n * Type guard: narrow a {@link Result} to its `Err` variant, exposing `.error`.\n *\n * @returns `true` when `r` is `Err`.\n *\n * @example\n * ```ts\n * import { isErr, Ok, Err, type Result } from \"unthrown\";\n *\n * isErr(Err(\"boom\")); // => true\n * isErr(Ok(1)); // => false\n *\n * declare const r: Result<number, string>;\n * if (isErr(r)) r.error; // string, narrowed\n * ```\n *\n * @category Guards\n */\nexport function isErr<T, E>(r: Result<T, E>): r is ErrView<E, T> {\n return r.tag === \"Err\";\n}\n/**\n * Type guard: narrow a {@link Result} to its `Defect` variant, exposing `.cause`.\n *\n * @remarks\n * A `Defect` has no public constructor — it only arises at a boundary (e.g. a\n * callback throwing inside a combinator). This guard is how you detect one.\n *\n * @returns `true` when `r` is a `Defect`.\n *\n * @example\n * ```ts\n * import { isDefect, Ok } from \"unthrown\";\n *\n * // A throw inside a combinator is captured as a Defect:\n * const r = Ok(1).map(() => {\n * throw new Error(\"boom\");\n * });\n * isDefect(r); // => true\n * isDefect(Ok(1)); // => false\n *\n * if (isDefect(r)) r.cause; // unknown, narrowed\n * ```\n *\n * @category Guards\n */\nexport function isDefect<T, E>(r: Result<T, E>): r is DefectView<T, E> {\n return r.tag === \"Defect\";\n}\n","// Do-notation entry point. The `bind` / `let` steps live on the `Result` /\n// `AsyncResult` method surface (core.ts); `Do()` just seeds an empty object\n// scope to grow.\n\nimport { Ok } from \"./constructors.js\";\nimport type { Result } from \"./types.js\";\n\n/**\n * Start a do-notation chain with an empty object scope, grown step by step with\n * `bind` (for `Result`-returning steps) and `let` (for pure values).\n *\n * @remarks\n * Capitalised because `do` is a reserved word. Each step receives the scope\n * accumulated so far; the error types union across `bind`s, and a throw in any\n * step becomes a `Defect`. To go asynchronous, lift the chain with `toAsync()`\n * (then a `bind` may return an `AsyncResult`).\n *\n * @example\n * ```ts\n * import { Do, Ok } from \"unthrown\";\n *\n * const result = Do()\n * .bind(\"user\", () => findUser(id)) // Result<User, NotFound>\n * .bind(\"org\", ({ user }) => findOrg(user.orgId)) // Result<Org, NotFound>\n * .let(\"label\", ({ user, org }) => `${user.name} @ ${org.name}`)\n * .map(({ user, org, label }) => render(user, org, label));\n * // Result<View, NotFound>\n * ```\n *\n * @example\n * ```ts\n * import { Do, Ok, Err } from \"unthrown\";\n *\n * // Ok path — the scope accumulates:\n * Do()\n * .bind(\"a\", () => Ok(2))\n * .let(\"b\", ({ a }) => a * 10)\n * .map(({ a, b }) => a + b); // => Ok(22)\n *\n * // Err path — the first Err short-circuits the rest:\n * Do()\n * .bind(\"a\", () => Err(\"boom\"))\n * .let(\"b\", ({ a }) => a); // => Err(\"boom\")\n * ```\n *\n * @category Do-notation\n */\nexport function Do(): Result<{}, never> {\n return Ok({});\n}\n","// Defect marker plumbing.\n\nconst DEFECT: unique symbol = Symbol(\"unthrown/Defect\");\n\n/**\n * The opaque marker a `qualify` function returns to triage a cause as\n * **unexpected**.\n *\n * @remarks\n * `qualify` (passed to {@link fromPromise} / {@link fromThrowable}) returns\n * `E | Defect`: either a modeled domain error, or a `Defect` produced by the\n * injected `defect` helper to say \"this failure is not modeled\". A `Defect` is\n * opaque — it carries the original cause for the boundary to convert into the\n * third runtime state of a `Result`. It is **not** a public value; the only way\n * to mint one is the `defect` helper the boundary passes to `qualify`.\n *\n * @internal\n */\nexport type Defect = {\n readonly [DEFECT]: true;\n readonly cause: unknown;\n};\n\n/**\n * Wrap a cause as a `Defect` marker — the value returned from a `qualify`\n * function when a failure is **not** a modeled domain error. The boundary\n * (`fromPromise` / `fromThrowable`) passes this in as `qualify`'s second\n * argument, so domain code never imports it.\n *\n * @param cause - the original thrown/rejected value.\n * @returns an opaque Defect marker carrying `cause`.\n *\n * @internal\n */\nexport function defect(cause: unknown): Defect {\n return { [DEFECT]: true, cause };\n}\n\n/**\n * Internal guard for the qualify-time marker. Distinct from the public\n * {@link isDefect} state guard — this one narrows the `E | Defect` union a\n * `qualify` function returns, not a `Result`.\n *\n * @internal\n */\nexport function isDefectMarker(x: unknown): x is Defect {\n return (\n typeof x === \"object\" && x !== null && (x as Record<PropertyKey, unknown>)[DEFECT] === true\n );\n}\n","// Boundary interop and aggregation. Every throwing/rejecting boundary is forced\n// through `qualify`, which triages each cause into a modeled `E` or a `Defect`;\n// there is no path that yields `unknown` in `E`.\n\nimport { AsyncRes, defectRes, errRes, okRes } from \"./core.js\";\nimport { type Defect, defect, isDefectMarker } from \"./defect.js\";\nimport { Err, Ok } from \"./constructors.js\";\nimport type { AsyncErrOf, AsyncOkOf, AsyncResult, ErrOf, OkOf, Result } from \"./types.js\";\n\n/**\n * Bridge a nullable value into a {@link Result}: absence becomes a **modeled**\n * `Err`. The sanctioned alternative to an `Option` type.\n *\n * @remarks\n * `null` and `undefined` map to `Err(onAbsent())`; any other value (including\n * falsy ones like `0`, `\"\"`, `false`) maps to `Ok`.\n *\n * @typeParam T - the (nullable) value type.\n * @typeParam E - the error produced when the value is absent.\n * @param value - the possibly-absent value.\n * @param onAbsent - lazily produces the error for the absent case.\n *\n * @category Interop\n *\n * @example\n * ```ts\n * import { fromNullable } from \"unthrown\";\n *\n * const map = new Map([[\"a\", 1]]);\n * fromNullable(map.get(\"a\"), () => \"absent\").unwrapOr(0); // => 1\n * fromNullable(map.get(\"z\"), () => \"absent\"); // => Err(\"absent\")\n * fromNullable(0, () => \"absent\").unwrapOr(-1); // => 0 (falsy but present)\n * ```\n */\nexport function fromNullable<T, E>(\n value: T | null | undefined,\n onAbsent: () => E,\n): Result<NonNullable<T>, E> {\n return value === null || value === undefined ? Err(onAbsent()) : Ok(value as NonNullable<T>);\n}\n\n/**\n * Wrap a throwing synchronous function so it returns a {@link Result} instead of\n * throwing.\n *\n * @remarks\n * `qualify` **must** triage every thrown cause into a modeled error `E` or a\n * `Defect` (via the injected `defect` helper, its second argument) — there is no\n * path that leaves `unknown` in `E`. A throw inside `qualify` itself is treated\n * as a `Defect`.\n *\n * The modeled error type is `Exclude<R, Defect>` — the `Defect` arm of\n * `qualify`'s return is **subtracted** from `E`, never inferred into it. So a\n * `qualify` that returns *only* `defect(cause)` yields `E = never` (a Defect is\n * out-of-band and must not pollute the error channel); reach for\n * {@link fromSafePromise} when every failure is a Defect.\n *\n * @typeParam A - the wrapped function's argument tuple.\n * @typeParam T - the wrapped function's return type.\n * @typeParam R - `qualify`'s return type; the modeled error `E` is\n * `Exclude<R, Defect>` (its `Defect` arm, if any, is subtracted).\n * @param fn - the throwing function to wrap.\n * @param qualify - triages a thrown `cause` into a modeled `E`, or marks it\n * unmodeled by returning `defect(cause)` (the helper passed as its second arg).\n * @returns a function with the same arguments returning `Result<T, E>`.\n *\n * @category Interop\n *\n * @example\n * ```ts\n * import { fromThrowable } from \"unthrown\";\n *\n * // Model the parse failure as an `Err`, everything unexpected as a `Defect`.\n * const parse = fromThrowable(\n * (text: string) => JSON.parse(text) as unknown,\n * (cause, defect) =>\n * cause instanceof SyntaxError ? (\"invalid_json\" as const) : defect(cause),\n * );\n *\n * parse('{\"ok\":true}').unwrapOr(null); // => { ok: true }\n * parse(\"nope\"); // => Err(\"invalid_json\")\n * ```\n */\nexport function fromThrowable<A extends unknown[], T, R>(\n fn: (...args: A) => T,\n qualify: (cause: unknown, defect: (cause: unknown) => Defect) => R,\n): (...args: A) => Result<T, Exclude<R, Defect>> {\n type E = Exclude<R, Defect>;\n const triage = qualify as (cause: unknown, defect: (cause: unknown) => Defect) => E | Defect;\n return (...args: A): Result<T, E> => {\n try {\n return Ok(fn(...args)) as Result<T, E>;\n } catch (cause) {\n return qualifyToResult<T, E>(cause, triage);\n }\n };\n}\n\n/**\n * Wrap a `Promise` (or a thunk producing one) as an {@link AsyncResult}, forcing\n * every rejection to be triaged.\n *\n * @remarks\n * `qualify` **must** map each rejection cause into a modeled error `E` or a\n * `Defect` (via the injected `defect` helper, its second argument). The returned\n * `AsyncResult`'s internal promise never rejects; `await`-ing it always yields a\n * `Result`. A throw inside `qualify` is itself a `Defect`.\n *\n * The modeled error type is `Exclude<R, Defect>` — the `Defect` arm of\n * `qualify`'s return is **subtracted** from `E`, never inferred into it. So a\n * `qualify` that returns *only* `defect(cause)` yields `E = never`; when every\n * rejection is a Defect, prefer {@link fromSafePromise}.\n *\n * @typeParam T - the resolved value type.\n * @typeParam R - `qualify`'s return type; the modeled error `E` is\n * `Exclude<R, Defect>` (its `Defect` arm, if any, is subtracted).\n * @param promise - the promise, or a thunk returning one.\n * @param qualify - triages a rejection `cause` into a modeled `E`, or marks it\n * unmodeled by returning `defect(cause)` (the helper passed as its second arg).\n *\n * @category Interop\n *\n * @example\n * ```ts\n * import { fromPromise } from \"unthrown\";\n *\n * // A rejection with a NotFoundError becomes a modeled `Err`; anything else a Defect.\n * const user = await fromPromise(fetchUser(id), (cause, defect) =>\n * cause instanceof NotFoundError ? (\"not_found\" as const) : defect(cause),\n * );\n *\n * if (user.isOk()) user.value; // => the fetched user\n * // when fetchUser rejects with NotFoundError: user is Err(\"not_found\")\n * ```\n */\nexport function fromPromise<T, R>(\n promise: Promise<T> | (() => Promise<T>),\n qualify: (cause: unknown, defect: (cause: unknown) => Defect) => R,\n): AsyncResult<T, Exclude<R, Defect>> {\n type E = Exclude<R, Defect>;\n const triage = qualify as (cause: unknown, defect: (cause: unknown) => Defect) => E | Defect;\n // Promise.resolve() also absorbs a non-thenable passed from untyped code, so\n // this boundary never throws synchronously — it exists to prevent throws.\n const p =\n typeof promise === \"function\" ? Promise.resolve().then(promise) : Promise.resolve(promise);\n const settled: Promise<Result<T, E>> = p.then(\n (value) => okRes<T, E>(value),\n (cause) => qualifyToResult<T, E>(cause, triage),\n );\n return new AsyncRes<T, E>(settled);\n}\n\n/**\n * Wrap a `Promise` asserted **not** to fail in any modeled way: any rejection\n * becomes a `Defect`.\n *\n * @remarks\n * Use this only when a rejection genuinely indicates a bug rather than an\n * anticipated outcome — the error channel is `never`, so there is nothing to\n * triage. (`await`-ing still yields a `Result`; it never throws.)\n *\n * @typeParam T - the resolved value type.\n * @param promise - the promise, or a thunk returning one.\n *\n * @category Interop\n *\n * @example\n * ```ts\n * import { fromSafePromise } from \"unthrown\";\n *\n * (await fromSafePromise(Promise.resolve(3))).unwrap(); // => 3\n * // a rejection becomes a Defect (never a modeled Err):\n * await fromSafePromise(Promise.reject(new Error(\"boom\"))); // => Defect(Error(\"boom\"))\n * ```\n */\nexport function fromSafePromise<T>(\n promise: Promise<T> | (() => Promise<T>),\n): AsyncResult<T, never> {\n // Promise.resolve() also absorbs a non-thenable passed from untyped code, so\n // this boundary never throws synchronously — it exists to prevent throws.\n const p =\n typeof promise === \"function\" ? Promise.resolve().then(promise) : Promise.resolve(promise);\n const settled: Promise<Result<T, never>> = p.then(\n (value) => okRes<T, never>(value),\n (cause) => defectRes<T, never>(cause),\n );\n return new AsyncRes<T, never>(settled);\n}\n\nfunction qualifyToResult<T, E>(\n cause: unknown,\n qualify: (cause: unknown, defect: (cause: unknown) => Defect) => E | Defect,\n): Result<T, E> {\n try {\n const q = qualify(cause, defect);\n return isDefectMarker(q) ? defectRes<T, E>(q.cause) : errRes<T, E>(q);\n } catch (qErr) {\n // a throw inside qualify is itself a Defect\n return defectRes<T, E>(qErr);\n }\n}\n\n/**\n * The success channel of {@link all} / {@link allAsync}: a **positional tuple**\n * for a fixed-length input (including the empty tuple), or a homogeneous\n * **array** for a dynamic one.\n *\n * @remarks\n * The split keys off the input's `length`: a fixed tuple has a literal length\n * (`number extends Rs[\"length\"]` is false → keep the positional `Ts`), while a\n * general array has `length: number` (→ collapse to `Ts[number][]`). Checking\n * length rather than `Rs extends [unknown, ...unknown[]]` keeps `all([])` typed\n * as `Result<[], …>` instead of `Result<never[], …>`.\n *\n * @typeParam Rs - the tuple/array of input `Result` types.\n * @typeParam Ts - per-element extracted success types (`OkOf` for `all`,\n * `AsyncOkOf` for `allAsync`).\n * @internal\n */\ntype AllOk<\n Rs extends readonly unknown[],\n Ts extends readonly unknown[],\n> = number extends Rs[\"length\"] ? Ts[number][] : Ts;\n\n/** A record of `Result`s — the input to {@link allFromDict}. */\ntype ResultRecord = Record<string, Result<unknown, unknown>>;\n/** A record of `AsyncResult`s — the input to {@link allFromDictAsync}. */\ntype AsyncResultRecord = Record<string, AsyncResult<unknown, unknown>>;\n\n/**\n * Fold an array of settled `Result`s: first `Err` wins, any `Defect` dominates,\n * else `Ok` of the values array.\n *\n * @internal\n */\nfunction foldArray(results: readonly Result<unknown, unknown>[]): Result<unknown, unknown> {\n let firstErr: Result<unknown, unknown> | undefined;\n let firstDefect: Result<unknown, unknown> | undefined;\n const values: unknown[] = [];\n for (const r of results) {\n if (r.tag === \"Defect\") {\n firstDefect ??= r;\n break; // any Defect dominates — nothing later can change the outcome\n } else if (r.tag === \"Err\") firstErr ??= r;\n else values.push(r.value);\n }\n return firstDefect ?? firstErr ?? Ok(values);\n}\n\n/**\n * Fold a record of settled `Result`s with the same rules, else `Ok` of the\n * record of values. Keys are written with `Object.defineProperty` so a\n * caller-supplied `\"__proto__\"` key cannot pollute the prototype.\n *\n * @internal\n */\nfunction foldRecord(results: ResultRecord): Result<unknown, unknown> {\n let firstErr: Result<unknown, unknown> | undefined;\n let firstDefect: Result<unknown, unknown> | undefined;\n const values: Record<string, unknown> = {};\n for (const [key, r] of Object.entries(results)) {\n if (r.tag === \"Defect\") {\n firstDefect ??= r;\n break; // any Defect dominates — nothing later can change the outcome\n } else if (r.tag === \"Err\") firstErr ??= r;\n else\n Object.defineProperty(values, key, {\n value: r.value,\n enumerable: true,\n writable: true,\n configurable: true,\n });\n }\n return firstDefect ?? firstErr ?? Ok(values);\n}\n\n/**\n * Collect a tuple/array of {@link Result}s into a single `Result` of all their\n * success values.\n *\n * @remarks\n * Short-circuits on the **first** `Err` (later entries are not inspected for\n * their error); any `Defect` present **dominates**, winning even over an earlier\n * `Err`. A **fixed tuple** keeps its positional types — `all([Ok(1), Ok(\"a\")])`\n * is `Result<[number, string], …>` — while a **dynamic array** `Result<T, E>[]`\n * collapses to `Result<T[], E>` with no cast. For a **record** keyed by name,\n * use {@link allFromDict}.\n *\n * @category Aggregate\n *\n * @example\n * ```ts\n * import { all, Ok, Err } from \"unthrown\";\n *\n * all([Ok(1), Ok(\"a\"), Ok(true)]).unwrap(); // => [1, \"a\", true] (typed [number, string, boolean])\n * all([Ok(1), Err(\"e\"), Ok(3)]); // => Err(\"e\") (short-circuits on the first Err)\n * ```\n */\nexport function all<Rs extends readonly Result<unknown, unknown>[]>(\n results: readonly [...Rs],\n): Result<AllOk<Rs, { [K in keyof Rs]: OkOf<Rs[K]> }>, ErrOf<Rs[number]>> {\n return foldArray(results) as unknown as Result<\n AllOk<Rs, { [K in keyof Rs]: OkOf<Rs[K]> }>,\n ErrOf<Rs[number]>\n >;\n}\n\n/**\n * Collect a **record** of {@link Result}s into a single `Result` of a record of\n * their success values — `allFromDict({ a: Result<A, E>, b: Result<B, E> })` is\n * `Result<{ a: A; b: B }, E>`. The named counterpart of {@link all}, for\n * parallel work you'd rather not tuple.\n *\n * @remarks\n * Same folding rules as {@link all}: first `Err` short-circuits, any `Defect`\n * dominates. This is **not** error accumulation.\n *\n * @category Aggregate\n *\n * @example\n * ```ts\n * import { allFromDict, Ok, Err } from \"unthrown\";\n *\n * allFromDict({ id: Ok(1), name: Ok(\"ada\") }).unwrap(); // => { id: 1, name: \"ada\" }\n * allFromDict({ id: Ok(1), name: Err(\"missing\") }); // => Err(\"missing\")\n * ```\n */\nexport function allFromDict<R extends ResultRecord>(\n results: R,\n): Result<{ [K in keyof R]: OkOf<R[K]> }, ErrOf<R[keyof R]>> {\n return foldRecord(results) as unknown as Result<\n { [K in keyof R]: OkOf<R[K]> },\n ErrOf<R[keyof R]>\n >;\n}\n\n/**\n * The asynchronous counterpart of {@link all}: combine a tuple/array of\n * {@link AsyncResult}s into one `AsyncResult` of all their success values.\n *\n * @remarks\n * The inputs are resolved **concurrently** (order preserved); the resolved\n * `Result`s are then folded with the same rules as {@link all} — first `Err`\n * short-circuits, any `Defect` dominates. As ever, the returned `AsyncResult`'s\n * internal promise never rejects. For a **record**, use {@link allFromDictAsync}.\n *\n * @category Aggregate\n *\n * @example\n * ```ts\n * import { allAsync, fromSafePromise } from \"unthrown\";\n *\n * const both = allAsync([fromSafePromise(Promise.resolve(1)), fromSafePromise(Promise.resolve(2))]);\n * (await both).unwrap(); // => [1, 2]\n * ```\n */\nexport function allAsync<Rs extends readonly AsyncResult<unknown, unknown>[]>(\n results: readonly [...Rs],\n): AsyncResult<AllOk<Rs, { [K in keyof Rs]: AsyncOkOf<Rs[K]> }>, AsyncErrOf<Rs[number]>> {\n // Each AsyncResult is a (never-rejecting) thenable, so Promise.all adopts them;\n // `foldArray` then applies the all() rules. The internal promise never rejects.\n const settled = Promise.all(results).then((resolved) =>\n foldArray(resolved as readonly Result<unknown, unknown>[]),\n );\n return new AsyncRes(settled) as unknown as AsyncResult<\n AllOk<Rs, { [K in keyof Rs]: AsyncOkOf<Rs[K]> }>,\n AsyncErrOf<Rs[number]>\n >;\n}\n\n/**\n * The asynchronous counterpart of {@link allFromDict}: combine a record of\n * {@link AsyncResult}s into one `AsyncResult` of a record of their values.\n *\n * @remarks\n * Resolved concurrently (order preserved), folded with the {@link all} rules,\n * and the internal promise never rejects.\n *\n * @category Aggregate\n *\n * @example\n * ```ts\n * import { allFromDictAsync, fromSafePromise } from \"unthrown\";\n *\n * const both = allFromDictAsync({\n * a: fromSafePromise(Promise.resolve(1)),\n * b: fromSafePromise(Promise.resolve(\"x\")),\n * });\n * (await both).unwrap(); // => { a: 1, b: \"x\" }\n * ```\n */\nexport function allFromDictAsync<R extends AsyncResultRecord>(\n results: R,\n): AsyncResult<{ [K in keyof R]: AsyncOkOf<R[K]> }, AsyncErrOf<R[keyof R]>> {\n const entries = Object.entries(results);\n const settled = Promise.all(entries.map(([, ar]) => ar)).then((resolved) => {\n // Null-proto accumulator: pairing resolved values back to keys can't pollute.\n const byKey: ResultRecord = Object.create(null) as ResultRecord;\n entries.forEach(([key], i) => {\n byKey[key] = resolved[i]!;\n });\n return foldRecord(byKey);\n });\n return new AsyncRes(settled) as unknown as AsyncResult<\n { [K in keyof R]: AsyncOkOf<R[K]> },\n AsyncErrOf<R[keyof R]>\n >;\n}\n","// Result facade — a discoverable namespace alias for the standalone entry\n// points. The free functions remain the primary, tree-shakeable API; this\n// object is a separate export, so `import { Ok }` never pulls it in. The value\n// `Result` and the type `Result<T, E>` (types.ts) share a name — the\n// companion-object pattern. See CLAUDE.md → \"Internal design\".\n\nimport { Err, isDefect, isErr, isOk, Ok } from \"./constructors.js\";\nimport { isResult } from \"./core.js\";\nimport { Do } from \"./do.js\";\nimport {\n all,\n allAsync,\n allFromDict,\n allFromDictAsync,\n fromNullable,\n fromPromise,\n fromSafePromise,\n fromThrowable,\n} from \"./interop.js\";\nimport type { AsyncResult as AsyncResultType, Result as ResultType } from \"./types.js\";\n\n/**\n * Companion object grouping the **`Result`-producing** entry points under a\n * single, discoverable namespace: {@link Result.Ok}, {@link Result.Err},\n * {@link Result.Do}, {@link Result.fromNullable}, {@link Result.fromThrowable},\n * {@link Result.all}, {@link Result.allFromDict}, {@link Result.isOk},\n * {@link Result.isErr}, {@link Result.isDefect}, {@link Result.isResult}.\n *\n * @remarks\n * Purely additive sugar — each member **is** the corresponding free function.\n * The free functions remain the primary, tree-shakeable API; importing only\n * `{ Ok }` never pulls this object in. The value `Result` and the type\n * {@link Result} share one name (the companion-object pattern).\n *\n * The **async** entry points live on the sibling {@link AsyncResult} companion\n * (`AsyncResult.fromPromise`, `AsyncResult.all`, …), grouped by what they\n * return — a static lives in exactly one namespace.\n *\n * @category Facade\n *\n * @example\n * ```ts\n * import { Result } from \"unthrown\";\n * Result.Ok(1).flatMap((n) => Result.Ok(n + 1)).unwrap(); // => 2\n * ```\n */\nexport const Result = {\n Ok,\n Err,\n Do,\n fromNullable,\n fromThrowable,\n all,\n allFromDict,\n isOk,\n isErr,\n isDefect,\n isResult,\n} as const;\n\n/**\n * `Result<T, E>` — the core discriminated union. Shares its name with the\n * {@link Result | companion object} above (the value and type are one name); this\n * is the type half.\n *\n * @remarks\n * A `Result` is a discriminated union, so TypeDoc can't list its methods on this\n * alias. Its fluent combinators (`map`, `flatMap`, `match`, `unwrap`, …) are\n * documented one per entry on {@link ResultMethods} — the shared method surface\n * every variant carries. For \"which one do I reach for?\", see the\n * [Choosing a combinator](/guide/choosing-a-combinator) guide.\n *\n * @category Facade\n */\n// Re-alias the Result type into this module so a single `export { Result }`\n// (from index.ts) carries BOTH the companion object above and the type — value\n// and type sharing one name, declaration-merged in one place.\nexport type Result<T, E> = ResultType<T, E>;\n\n/**\n * Companion object grouping the **`AsyncResult`-producing** entry points under\n * the matching namespace: {@link AsyncResult.fromPromise},\n * {@link AsyncResult.fromSafePromise}, {@link AsyncResult.all},\n * {@link AsyncResult.allFromDict}.\n *\n * @remarks\n * The async sibling of {@link Result}. Statics are grouped by what they\n * **return**, so `fromPromise`/`fromSafePromise` and the async aggregates sit\n * here rather than on {@link Result}; the namespace already conveys \"async\", so\n * the aggregates drop the `Async` suffix (`AsyncResult.all` is the free function\n * `allAsync`; `AsyncResult.allFromDict` is `allFromDictAsync`). Like\n * {@link Result}, the free functions remain the primary, tree-shakeable API; the\n * value `AsyncResult` and the type {@link AsyncResult} share one name.\n *\n * @category Facade\n *\n * @example\n * ```ts\n * import { AsyncResult } from \"unthrown\";\n * const user = await AsyncResult.fromPromise(fetchUser(id), (c, defect) => defect(c));\n * user.unwrap(); // => the fetched user (on success)\n * ```\n */\nexport const AsyncResult = {\n fromPromise,\n fromSafePromise,\n all: allAsync,\n allFromDict: allFromDictAsync,\n} as const;\n\n/**\n * `AsyncResult<T, E>` — the async counterpart of {@link Result}. Shares its name\n * with the {@link AsyncResult | companion object} above (value and type are one\n * name); this is the type half.\n *\n * @remarks\n * `AsyncResult` carries the async fluent surface; its combinators (`map`,\n * `flatMap`, `match`, `unwrap`, …) are documented one per entry — with their\n * async signatures — on {@link AsyncResultMethods}. For \"which one do I reach\n * for?\", see the [Choosing a combinator](/guide/choosing-a-combinator) guide.\n *\n * @category Facade\n */\n// Re-alias the AsyncResult type into this module (same companion-object pattern\n// as Result above) so one `export { AsyncResult }` carries value + type.\nexport type AsyncResult<T, E> = AsyncResultType<T, E>;\n","// The TaggedError convention (à la Effect's `Data.TaggedError`) and an\n// exhaustive, zero-dependency fold over a tagged error union.\n\nimport type { AsyncResult, Result } from \"./types.js\";\n\ntype Props = Record<string, unknown>;\n\n/**\n * The instance shape produced by a {@link TaggedError} class: an `Error` plus a\n * `_tag` discriminant and the (readonly) payload fields.\n *\n * @typeParam Tag - the string literal discriminant.\n * @typeParam A - the payload object type.\n *\n * @category Types\n */\nexport type TaggedErrorInstance<Tag extends string, A extends Props> = Error &\n Readonly<Omit<A, \"name\" | \"message\">> & { readonly _tag: Tag };\n\n/**\n * The class constructor returned by {@link TaggedError}. Generic in its payload:\n * apply it with an instantiation expression at the `extends` site.\n *\n * @remarks\n * When the payload is empty, the constructor takes **no** arguments (the\n * `keyof A extends never ? void : A` trick); otherwise it takes the payload. The\n * `name` and `message` keys are both **rejected** (`name?: never` /\n * `message?: never`) because both are reserved: `name` is the display label, and\n * `message` is the human string owned by `Error`. Set the message the standard\n * way — `override message = \"…\"` (or a constructor override) on the subclass —\n * never as a free-form per-call payload field. The reservations are enforced at\n * the call site, mirroring how {@link TaggedErrorInstance} excludes both.\n *\n * @typeParam Tag - the string literal discriminant.\n *\n * @category Types\n */\nexport type TaggedErrorConstructor<Tag extends string> = {\n new <A extends Props = {}>(\n args: keyof A extends never ? void : A & { readonly name?: never; readonly message?: never },\n ): TaggedErrorInstance<Tag, A>;\n};\n\n/**\n * Build a base class for a tagged error — a class extending `Error` with a\n * `_tag` string discriminant, in the style of Effect's `Data.TaggedError`.\n *\n * @remarks\n * Extend the returned class to declare a concrete error. Supply the payload with\n * an instantiation expression; omit it for a payload-less error. The `message`\n * is **not** a payload field — it is the human string owned by `Error`, not\n * structured data, so it is reserved. Define it once per subclass the standard\n * way, `override message = \"…\"` (it may interpolate the payload via `this`,\n * which the base populates before the subclass field initialiser runs); a\n * payload `message` is rejected at compile time, so contextual detail lives in\n * typed fields, never baked into per-call prose. The `_tag` always reflects\n * `tag` and cannot be overridden by the payload. `name` is likewise reserved —\n * it is the display label (set it with `options.name`); a payload `name` is\n * rejected at compile time (and excluded from the instance type), so it can't\n * shadow `Error.name`.\n *\n * `_tag` is the discriminant used by {@link matchTags}; `Error.name` is the\n * human-facing label in stack traces and logs. By default they coincide, but\n * they can be **decoupled** with `options.name` — so a tag can be namespaced for\n * collision-safety (`\"@my-lib/RetryableError\"`) without that slash-prefixed\n * string leaking into `Error.name`:\n *\n * ```ts\n * class RetryableError extends TaggedError(\"@my-lib/RetryableError\", {\n * name: \"RetryableError\",\n * }) {\n * override message = \"operation failed; safe to retry\";\n * }\n *\n * const e = new RetryableError();\n * e._tag; // \"@my-lib/RetryableError\" — namespaced discriminant\n * e.name; // \"RetryableError\" — clean display name\n * e.message; // \"operation failed; safe to retry\" — the standard Error.message\n * ```\n *\n * @typeParam Tag - the string literal discriminant.\n * @param tag - the discriminant value; also the default error `name`.\n * @param options - optional overrides. `options.name` sets `Error.name`\n * independently of `tag` (defaults to `tag`).\n *\n * @category Tagged errors\n *\n * @example\n * ```ts\n * class NotFound extends TaggedError(\"NotFound\") {}\n * class HttpError extends TaggedError(\"HttpError\")<{ status: number }> {}\n *\n * new NotFound()._tag; // => \"NotFound\"\n * new HttpError({ status: 500 }).status; // => 500\n * ```\n */\nexport function TaggedError<Tag extends string>(\n tag: Tag,\n options?: { readonly name?: string },\n): TaggedErrorConstructor<Tag> {\n const displayName = options?.name ?? tag;\n class TaggedErrorBase extends Error {\n readonly _tag!: Tag;\n\n constructor(props?: Props) {\n super();\n if (props) Object.assign(this, props);\n // `_tag`, `name`, and `message` are authoritative — an untyped caller\n // can't set them via the payload. `_tag`/`name` are re-assigned to their\n // canonical values; `message` is `Error`'s channel (set per subclass via\n // `override message = …`, whose field initialiser runs after this\n // constructor returns), so any payload-supplied `message` is dropped here.\n (this as { _tag: Tag })._tag = tag;\n this.name = displayName;\n delete (this as { message?: unknown }).message;\n Object.setPrototypeOf(this, new.target.prototype);\n }\n }\n\n return TaggedErrorBase as unknown as TaggedErrorConstructor<Tag>;\n}\n\n/**\n * The handler object {@link matchTags} requires: a branch per error tag, plus\n * `Ok` and `Defect`. Miss a tag and it will not compile — the exhaustiveness is\n * enforced by the type, with no `.exhaustive()` to forget.\n *\n * @typeParam T - the success value type.\n * @typeParam E - the tagged error union.\n * @typeParam R - the folded result type.\n *\n * @category Types\n */\nexport type TagHandlers<T, E extends { _tag: string }, R> = {\n Ok: (value: T) => R;\n Defect: (cause: unknown) => R;\n} & { [K in E[\"_tag\"]]: (error: Extract<E, { _tag: K }>) => R };\n\n/**\n * The channel-handler names are reserved: an error tag named `\"Ok\"` or\n * `\"Defect\"` would collide with them inside {@link TagHandlers}, so\n * {@link matchTags} rejects such unions at the call site.\n *\n * @internal\n */\ntype ReservedTagError =\n 'unthrown: error tags \"Ok\" and \"Defect\" are reserved by matchTags — rename the colliding tag (TaggedError\\'s options.name can keep the display name)';\n\n/**\n * Exhaustively fold a {@link Result} (or {@link AsyncResult}) whose error type is\n * a tagged union, dispatching each error to the handler matching its `_tag`.\n *\n * @remarks\n * The `handlers` object must provide `Ok`, `Defect`, and exactly one function\n * per error tag; each tag's handler receives the narrowed error variant. A\n * missing tag is a compile error. For an `AsyncResult`, the fold resolves to a\n * `Promise<R>`. At runtime, an error whose `_tag` has no handler (possible only\n * outside the typed contract) is routed to the `Defect` handler — an unmodeled\n * tag is an unmodeled failure. Tags named `\"Ok\"` or `\"Defect\"` are rejected at\n * compile time.\n *\n * @typeParam T - the success value type.\n * @typeParam E - the tagged error union (`E extends { _tag: string }`).\n * @typeParam R - the folded result type.\n * @param result - the result to fold.\n * @param handlers - one branch per channel/tag.\n *\n * @category Tagged errors\n *\n * @example\n * ```ts\n * import { Ok, Err, matchTags, TaggedError, type Result } from \"unthrown\";\n *\n * class NotFound extends TaggedError(\"NotFound\") {}\n * class Forbidden extends TaggedError(\"Forbidden\")<{ user: string }> {}\n *\n * const fold = (r: Result<number, NotFound | Forbidden>) =>\n * matchTags(r, {\n * Ok: (n) => `got ${n}`,\n * Defect: (cause) => `bug: ${String(cause)}`,\n * NotFound: () => \"404\",\n * Forbidden: (e) => `403 for ${e.user}`,\n * });\n *\n * fold(Ok(1)); // => \"got 1\"\n * fold(Err(new Forbidden({ user: \"ada\" }))); // => \"403 for ada\"\n * ```\n */\nexport function matchTags<T, E extends { _tag: string }, R>(\n result: Result<T, E>,\n handlers: TagHandlers<T, E, R> &\n ([Extract<E[\"_tag\"], \"Ok\" | \"Defect\">] extends [never] ? unknown : ReservedTagError),\n): R;\nexport function matchTags<T, E extends { _tag: string }, R>(\n result: AsyncResult<T, E>,\n handlers: TagHandlers<T, E, R> &\n ([Extract<E[\"_tag\"], \"Ok\" | \"Defect\">] extends [never] ? unknown : ReservedTagError),\n): Promise<R>;\nexport function matchTags<T, E extends { _tag: string }, R>(\n result: Result<T, E> | AsyncResult<T, E>,\n handlers: TagHandlers<T, E, R>,\n): R | Promise<R> {\n const onErr = (error: E): R => {\n const tag = error._tag as E[\"_tag\"];\n // `Object.hasOwn` guards against a rogue tag (e.g. \"constructor\") resolving\n // through the prototype chain to an unrelated `Object.prototype` member —\n // only an own property of `handlers` counts as a real handler.\n const handler =\n tag === \"Ok\" || tag === \"Defect\" || !Object.hasOwn(handlers, tag)\n ? undefined\n : (handlers[tag] as unknown as ((e: E) => R) | undefined);\n // An unhandled or reserved tag can only arise outside the typed contract (a\n // widened cast, a JS caller). That is an unmodeled failure — route it to the\n // Defect handler rather than crashing on `undefined(error)`.\n return handler ? handler(error) : handlers.Defect(error);\n };\n // Both Result and AsyncResult share `match`; the cast picks one signature for\n // the call while the public overloads keep the return type correct.\n return (result as Result<T, E>).match({ ok: handlers.Ok, err: onErr, defect: handlers.Defect });\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAiDA,IAAa,cAAb,cAA8C,MAAM;;;;;CAKlD;CACA,YAAY,OAAU;EACpB,MAAM,oDAAoD,EAAE,OAAO,MAAM,CAAC;EAC1E,KAAK,OAAO;EACZ,KAAK,QAAQ;EACb,OAAO,eAAe,MAAM,IAAI,OAAO,SAAS;CAClD;AACF;;;;;;;;AASA,IAAM,MAAN,MAAgB;CACd,IAA2B,GAAmD;EAC5E,IAAI,KAAK,QAAQ,MAAM,OAAO,YAAY,IAAI;EAC9C,IAAI;GACF,OAAO,MAAM,EAAE,KAAK,KAAK,CAAC;EAC5B,SAAS,OAAO;GACd,OAAO,UAAU,KAAK;EACxB;CACF;CAEA,Q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OAAO;GACZ,OAAQ,KAA+B;GACvC,OAAO,eAAe,MAAM,IAAI,OAAO,SAAS;EAClD;CACF;CAEA,OAAO;AACT;AA8EA,SAAgB,UACd,QACA,UACgB;CAChB,MAAM,SAAS,UAAgB;EAC7B,MAAM,MAAM,MAAM;EAIlB,MAAM,UACJ,QAAQ,QAAQ,QAAQ,YAAY,CAAC,OAAO,OAAO,UAAU,GAAG,IAC5D,KAAA,IACC,SAAS;EAIhB,OAAO,UAAU,QAAQ,KAAK,IAAI,SAAS,OAAO,KAAK;CACzD;CAGA,OAAQ,OAAwB,MAAM;EAAE,IAAI,SAAS;EAAI,KAAK;EAAO,QAAQ,SAAS;CAAO,CAAC;AAChG"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "unthrown",
3
- "version": "3.1.0",
3
+ "version": "4.0.0",
4
4
  "description": "Explicit errors as values, with a separate defect (panic) channel",
5
5
  "keywords": [
6
6
  "defect",