unthrown 0.2.0 → 0.3.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 +117 -27
- package/dist/index.d.cts +77 -20
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +77 -20
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +116 -28
- package/dist/index.mjs.map +1 -1
- package/docs/index.md +190 -100
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -56,6 +56,15 @@ var Res = class {
|
|
|
56
56
|
return defectRes(cause);
|
|
57
57
|
}
|
|
58
58
|
}
|
|
59
|
+
flatTap(f) {
|
|
60
|
+
if (this.tag !== "Ok") return this;
|
|
61
|
+
try {
|
|
62
|
+
const r = f(this.value);
|
|
63
|
+
return r.tag === "Ok" ? this : r;
|
|
64
|
+
} catch (cause) {
|
|
65
|
+
return defectRes(cause);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
59
68
|
as(value) {
|
|
60
69
|
if (this.tag !== "Ok") return this;
|
|
61
70
|
return okRes(value);
|
|
@@ -243,6 +252,17 @@ var AsyncRes = class AsyncRes {
|
|
|
243
252
|
}
|
|
244
253
|
}));
|
|
245
254
|
}
|
|
255
|
+
flatTap(f) {
|
|
256
|
+
return new AsyncRes(this.promise.then(async (r) => {
|
|
257
|
+
if (r.tag !== "Ok") return r;
|
|
258
|
+
try {
|
|
259
|
+
const inner = await f(r.value);
|
|
260
|
+
return inner.tag === "Ok" ? r : inner;
|
|
261
|
+
} catch (cause) {
|
|
262
|
+
return defectRes(cause);
|
|
263
|
+
}
|
|
264
|
+
}));
|
|
265
|
+
}
|
|
246
266
|
as(value) {
|
|
247
267
|
return new AsyncRes(this.promise.then((r) => r.tag === "Ok" ? okRes(value) : r));
|
|
248
268
|
}
|
|
@@ -553,17 +573,52 @@ function qualifyToResult(cause, qualify) {
|
|
|
553
573
|
}
|
|
554
574
|
}
|
|
555
575
|
/**
|
|
556
|
-
*
|
|
576
|
+
* Fold an array of settled `Result`s: first `Err` wins, any `Defect` dominates,
|
|
577
|
+
* else `Ok` of the values array.
|
|
578
|
+
*
|
|
579
|
+
* @internal
|
|
580
|
+
*/
|
|
581
|
+
function foldArray(results) {
|
|
582
|
+
let firstErr;
|
|
583
|
+
let firstDefect;
|
|
584
|
+
const values = [];
|
|
585
|
+
for (const r of results) if (r.tag === "Defect") firstDefect ??= r;
|
|
586
|
+
else if (r.tag === "Err") firstErr ??= r;
|
|
587
|
+
else values.push(r.value);
|
|
588
|
+
return firstDefect ?? firstErr ?? ok(values);
|
|
589
|
+
}
|
|
590
|
+
/**
|
|
591
|
+
* Fold a record of settled `Result`s with the same rules, else `Ok` of the
|
|
592
|
+
* record of values. Keys are written with `Object.defineProperty` so a
|
|
593
|
+
* caller-supplied `"__proto__"` key cannot pollute the prototype.
|
|
594
|
+
*
|
|
595
|
+
* @internal
|
|
596
|
+
*/
|
|
597
|
+
function foldRecord(results) {
|
|
598
|
+
let firstErr;
|
|
599
|
+
let firstDefect;
|
|
600
|
+
const values = {};
|
|
601
|
+
for (const [key, r] of Object.entries(results)) if (r.tag === "Defect") firstDefect ??= r;
|
|
602
|
+
else if (r.tag === "Err") firstErr ??= r;
|
|
603
|
+
else Object.defineProperty(values, key, {
|
|
604
|
+
value: r.value,
|
|
605
|
+
enumerable: true,
|
|
606
|
+
writable: true,
|
|
607
|
+
configurable: true
|
|
608
|
+
});
|
|
609
|
+
return firstDefect ?? firstErr ?? ok(values);
|
|
610
|
+
}
|
|
611
|
+
/**
|
|
612
|
+
* Collect a tuple/array of {@link Result}s into a single `Result` of all their
|
|
613
|
+
* success values.
|
|
557
614
|
*
|
|
558
615
|
* @remarks
|
|
559
616
|
* Short-circuits on the **first** `Err` (later entries are not inspected for
|
|
560
617
|
* their error); any `Defect` present **dominates**, winning even over an earlier
|
|
561
618
|
* `Err`. A **fixed tuple** keeps its positional types — `all([ok(1), ok("a")])`
|
|
562
619
|
* is `Result<[number, string], …>` — while a **dynamic array** `Result<T, E>[]`
|
|
563
|
-
* collapses to `Result<T[], E>` with no cast.
|
|
564
|
-
*
|
|
565
|
-
* @typeParam Rs - the tuple/array of input `Result` types.
|
|
566
|
-
* @param results - the results to combine.
|
|
620
|
+
* collapses to `Result<T[], E>` with no cast. For a **record** keyed by name,
|
|
621
|
+
* use {@link allFromDict}.
|
|
567
622
|
*
|
|
568
623
|
* @example
|
|
569
624
|
* ```ts
|
|
@@ -573,39 +628,69 @@ function qualifyToResult(cause, qualify) {
|
|
|
573
628
|
* ```
|
|
574
629
|
*/
|
|
575
630
|
function all(results) {
|
|
576
|
-
|
|
577
|
-
let firstErr;
|
|
578
|
-
let firstDefect;
|
|
579
|
-
for (const r of results) if (r.tag === "Defect") firstDefect ??= r;
|
|
580
|
-
else if (r.tag === "Err") firstErr ??= r;
|
|
581
|
-
else values.push(r.value);
|
|
582
|
-
if (firstDefect) return firstDefect;
|
|
583
|
-
if (firstErr) return firstErr;
|
|
584
|
-
return ok(values);
|
|
631
|
+
return foldArray(results);
|
|
585
632
|
}
|
|
586
633
|
/**
|
|
587
|
-
*
|
|
588
|
-
*
|
|
634
|
+
* Collect a **record** of {@link Result}s into a single `Result` of a record of
|
|
635
|
+
* their success values — `allFromDict({ a: Result<A, E>, b: Result<B, E> })` is
|
|
636
|
+
* `Result<{ a: A; b: B }, E>`. The named counterpart of {@link all}, for
|
|
637
|
+
* parallel work you'd rather not tuple.
|
|
589
638
|
*
|
|
590
639
|
* @remarks
|
|
591
|
-
*
|
|
592
|
-
*
|
|
593
|
-
* first `Err` short-circuits, any `Defect` dominates. As ever, the returned
|
|
594
|
-
* `AsyncResult`'s internal promise never rejects. A **fixed tuple** keeps its
|
|
595
|
-
* positional types; a **dynamic array** `AsyncResult<T, E>[]` collapses to
|
|
596
|
-
* `AsyncResult<T[], E>`.
|
|
640
|
+
* Same folding rules as {@link all}: first `Err` short-circuits, any `Defect`
|
|
641
|
+
* dominates. This is **not** error accumulation.
|
|
597
642
|
*
|
|
598
|
-
* @
|
|
599
|
-
*
|
|
643
|
+
* @example
|
|
644
|
+
* ```ts
|
|
645
|
+
* import { allFromDict, ok } from "unthrown";
|
|
646
|
+
* allFromDict({ id: ok(1), name: ok("ada") }).unwrap(); // { id: 1, name: "ada" }
|
|
647
|
+
* ```
|
|
648
|
+
*/
|
|
649
|
+
function allFromDict(results) {
|
|
650
|
+
return foldRecord(results);
|
|
651
|
+
}
|
|
652
|
+
/**
|
|
653
|
+
* The asynchronous counterpart of {@link all}: combine a tuple/array of
|
|
654
|
+
* {@link AsyncResult}s into one `AsyncResult` of all their success values.
|
|
655
|
+
*
|
|
656
|
+
* @remarks
|
|
657
|
+
* The inputs are resolved **concurrently** (order preserved); the resolved
|
|
658
|
+
* `Result`s are then folded with the same rules as {@link all} — first `Err`
|
|
659
|
+
* short-circuits, any `Defect` dominates. As ever, the returned `AsyncResult`'s
|
|
660
|
+
* internal promise never rejects. For a **record**, use {@link allFromDictAsync}.
|
|
600
661
|
*
|
|
601
662
|
* @example
|
|
602
663
|
* ```ts
|
|
603
664
|
* import { allAsync, fromSafePromise } from "unthrown";
|
|
604
|
-
*
|
|
665
|
+
* await allAsync([fromSafePromise(a()), fromSafePromise(b())]);
|
|
605
666
|
* ```
|
|
606
667
|
*/
|
|
607
668
|
function allAsync(results) {
|
|
608
|
-
return new AsyncRes(Promise.all(results).then((resolved) =>
|
|
669
|
+
return new AsyncRes(Promise.all(results).then((resolved) => foldArray(resolved)));
|
|
670
|
+
}
|
|
671
|
+
/**
|
|
672
|
+
* The asynchronous counterpart of {@link allFromDict}: combine a record of
|
|
673
|
+
* {@link AsyncResult}s into one `AsyncResult` of a record of their values.
|
|
674
|
+
*
|
|
675
|
+
* @remarks
|
|
676
|
+
* Resolved concurrently (order preserved), folded with the {@link all} rules,
|
|
677
|
+
* and the internal promise never rejects.
|
|
678
|
+
*
|
|
679
|
+
* @example
|
|
680
|
+
* ```ts
|
|
681
|
+
* import { allFromDictAsync, fromSafePromise } from "unthrown";
|
|
682
|
+
* await allFromDictAsync({ a: fromSafePromise(a()), b: fromSafePromise(b()) });
|
|
683
|
+
* ```
|
|
684
|
+
*/
|
|
685
|
+
function allFromDictAsync(results) {
|
|
686
|
+
const entries = Object.entries(results);
|
|
687
|
+
return new AsyncRes(Promise.all(entries.map(([, ar]) => ar)).then((resolved) => {
|
|
688
|
+
const byKey = Object.create(null);
|
|
689
|
+
entries.forEach(([key], i) => {
|
|
690
|
+
byKey[key] = resolved[i];
|
|
691
|
+
});
|
|
692
|
+
return foldRecord(byKey);
|
|
693
|
+
}));
|
|
609
694
|
}
|
|
610
695
|
//#endregion
|
|
611
696
|
//#region src/facade.ts
|
|
@@ -614,7 +699,8 @@ function allAsync(results) {
|
|
|
614
699
|
* discoverable namespace: {@link Result.ok}, {@link Result.err},
|
|
615
700
|
* {@link Result.defect}, {@link Result.fromNullable}, {@link Result.fromThrowable},
|
|
616
701
|
* {@link Result.fromPromise}, {@link Result.fromSafePromise}, {@link Result.all},
|
|
617
|
-
* {@link Result.allAsync}, {@link Result.
|
|
702
|
+
* {@link Result.allAsync}, {@link Result.allFromDict},
|
|
703
|
+
* {@link Result.allFromDictAsync}, {@link Result.isOk}, {@link Result.isErr},
|
|
618
704
|
* {@link Result.isDefect}.
|
|
619
705
|
*
|
|
620
706
|
* @remarks
|
|
@@ -639,6 +725,8 @@ const Result = {
|
|
|
639
725
|
fromSafePromise,
|
|
640
726
|
all,
|
|
641
727
|
allAsync,
|
|
728
|
+
allFromDict,
|
|
729
|
+
allFromDictAsync,
|
|
642
730
|
isOk,
|
|
643
731
|
isErr,
|
|
644
732
|
isDefect
|
|
@@ -711,6 +799,6 @@ function matchTags(result, handlers) {
|
|
|
711
799
|
});
|
|
712
800
|
}
|
|
713
801
|
//#endregion
|
|
714
|
-
export { Result, TaggedError, UnwrapError, all, allAsync, defect, err, fromNullable, fromPromise, fromSafePromise, fromThrowable, isDefect, isErr, isOk, matchTags, ok };
|
|
802
|
+
export { Result, TaggedError, UnwrapError, all, allAsync, allFromDict, allFromDictAsync, defect, err, fromNullable, fromPromise, fromSafePromise, fromThrowable, isDefect, isErr, isOk, matchTags, ok };
|
|
715
803
|
|
|
716
804
|
//# sourceMappingURL=index.mjs.map
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","names":[],"sources":["../src/core.ts","../src/constructors.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// The only casts left are the inherent type-changing pass-throughs (e.g. `map`\n// reusing an `Err` as a differently-typed `Result`) — the same `as unknown as`\n// boxed uses, sound because the passed-through variant carries no value of the\n// changed type.\n\nimport type { AsyncResult, DefectView, ErrView, OkView, Result } 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 * 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 */\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\");\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): Result<U, E> {\n if (this.tag !== \"Ok\") return this as unknown as Result<U, E>;\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 this as unknown as Result<U, E | E2>;\n try {\n return f(this.value) as Result<U, E | E2>;\n } catch (cause) {\n return defectRes(cause);\n }\n }\n\n tap(this: Result<T, E>, f: (value: T) => void): 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 as<U>(this: Result<T, E>, value: U): Result<U, E> {\n if (this.tag !== \"Ok\") return this as unknown as Result<U, E>;\n return okRes(value);\n }\n\n mapErr<E2>(this: Result<T, E>, f: (error: E) => E2): Result<T, E2> {\n if (this.tag !== \"Err\") return this as unknown as Result<T, E2>;\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 this as unknown as Result<T | U, E2>;\n try {\n return f(this.error) as Result<T | U, E2>;\n } catch (cause) {\n return defectRes(cause);\n }\n }\n\n recover<U>(this: Result<T, E>, f: (error: E) => U): Result<T | U, never> {\n if (this.tag !== \"Err\") return this as unknown as Result<T | U, never>;\n try {\n return okRes(f(this.error));\n } catch (cause) {\n return defectRes(cause);\n }\n }\n\n tapErr(this: Result<T, E>, f: (error: E) => void): Result<T, E> {\n if (this.tag !== \"Err\") return this;\n try {\n f(this.error);\n return this;\n } catch (cause) {\n return defectRes(cause);\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 as unknown as Result<T | U, E | E2>;\n try {\n return f(this.cause) as Result<T | U, E | E2>;\n } catch (cause) {\n return defectRes(cause);\n }\n }\n\n tapDefect(this: Result<T, E>, f: (cause: unknown) => void): Result<T, E> {\n if (this.tag !== \"Defect\") return this;\n try {\n f(this.cause);\n return this;\n } catch (cause) {\n return defectRes(cause);\n }\n }\n\n match<R>(\n this: Result<T, E>,\n cases: { ok: (value: T) => R; err: (error: E) => R; defect: (cause: unknown) => R },\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(this: Result<T, E>, fallback: T): T {\n if (this.tag === \"Ok\") return this.value;\n if (this.tag === \"Defect\") throw this.cause;\n return fallback;\n }\n\n unwrapOrElse(this: Result<T, E>, f: (error: E) => T): T {\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 isErr(this: Result<T, E>): this is ErrView<E, T> {\n return this.tag === \"Err\";\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 return Object.assign(Object.create(RESULT_PROTO), { tag: \"Ok\" as const, value }) 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.assign(Object.create(RESULT_PROTO), { tag: \"Err\" as const, error }) as ErrView<\n E,\n T\n >;\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.assign(Object.create(RESULT_PROTO), {\n tag: \"Defect\" as const,\n cause,\n }) as DefectView<T, E>;\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): AsyncResult<U, E> {\n return new AsyncRes<U, E>(\n this.promise.then((r) => {\n if (r.tag !== \"Ok\") return r as unknown as Result<U, E>;\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 r as unknown as Result<U, E | E2>;\n try {\n return (await f(r.value)) as Result<U, E | E2>;\n } catch (cause) {\n return defectRes(cause);\n }\n }),\n );\n }\n\n tap(f: (value: T) => void): 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 as<U>(value: U): AsyncResult<U, E> {\n return new AsyncRes<U, E>(\n this.promise.then((r) =>\n r.tag === \"Ok\" ? okRes<U, E>(value) : (r as unknown as Result<U, E>),\n ),\n );\n }\n\n mapErr<E2>(f: (error: E) => E2): AsyncResult<T, E2> {\n return new AsyncRes<T, E2>(\n this.promise.then((r) => {\n if (r.tag !== \"Err\") return r as unknown as Result<T, E2>;\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 r as unknown as Result<T | U, E2>;\n try {\n return (await f(r.error)) as Result<T | U, E2>;\n } catch (cause) {\n return defectRes(cause);\n }\n }),\n );\n }\n\n recover<U>(f: (error: E) => U): AsyncResult<T | U, never> {\n return new AsyncRes<T | U, never>(\n this.promise.then((r) => {\n if (r.tag !== \"Err\") return r as unknown as Result<T | U, never>;\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(f: (error: E) => void): 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 defectRes<T, E>(cause);\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 as unknown as Result<T | U, E | E2>;\n try {\n return (await f(r.cause)) as Result<T | U, E | E2>;\n } catch (cause) {\n return defectRes(cause);\n }\n }),\n );\n }\n\n tapDefect(f: (cause: unknown) => void): 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 defectRes<T, E>(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(fallback: T): Promise<T> {\n return this.promise.then((r) => r.unwrapOr(fallback));\n }\n unwrapOrElse(f: (error: E) => T): Promise<T> {\n return this.promise.then((r) => {\n if (r.tag === \"Ok\") return r.value;\n if (r.tag === \"Defect\") throw r.cause;\n return f(r.error);\n });\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 * ok(42).unwrap(); // 42\n * ```\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 * err(\"not_found\").unwrapErr(); // \"not_found\"\n * ```\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, type Result } from \"unthrown\";\n * declare const r: Result<number, string>;\n * if (isOk(r)) r.value; // number, narrowed\n * ```\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 */\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 * @returns `true` when `r` is a `Defect`.\n */\nexport function isDefect<T, E>(r: Result<T, E>): r is DefectView<T, E> {\n return r.tag === \"Defect\";\n}\n","// Defect marker plumbing.\n\nconst DEFECT: unique symbol = Symbol(\"unthrown/defect\");\n\n/**\n * The marker a `qualify` function returns to triage a cause as **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\n * {@link defect} to say \"this failure is not modeled\". A `Defect` is opaque —\n * it carries the original cause for the boundary to convert into the third\n * runtime state of a `Result`.\n */\nexport type Defect = {\n readonly [DEFECT]: true;\n readonly cause: unknown;\n};\n\n/**\n * Wrap a cause as a {@link Defect} — the value you return from a `qualify`\n * function when a failure is **not** a modeled domain error.\n *\n * @param cause - the original thrown/rejected value.\n * @returns an opaque defect marker carrying `cause`.\n *\n * @example\n * ```ts\n * import { fromPromise, defect } from \"unthrown\";\n *\n * const user = fromPromise(fetchUser(id), (cause) =>\n * cause instanceof NotFoundError ? cause : defect(cause),\n * );\n * ```\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, 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 * @example\n * ```ts\n * import { fromNullable } from \"unthrown\";\n * fromNullable(map.get(key), () => \"missing\").unwrap();\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 * {@link Defect} (via {@link defect}) — there is no path that leaves `unknown`\n * in `E`. A throw inside `qualify` itself is treated 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 `E` or a `Defect`.\n * @returns a function with the same arguments returning `Result<T, E>`.\n *\n * @example\n * ```ts\n * import { fromThrowable, defect } from \"unthrown\";\n * const parse = fromThrowable(JSON.parse, (cause) => defect(cause));\n * parse(\"{}\").unwrap();\n * ```\n */\nexport function fromThrowable<A extends unknown[], T, R>(\n fn: (...args: A) => T,\n qualify: (cause: unknown) => R,\n): (...args: A) => Result<T, Exclude<R, Defect>> {\n type E = Exclude<R, Defect>;\n const triage = qualify as (cause: unknown) => 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 * {@link Defect}. The returned `AsyncResult`'s internal promise never rejects;\n * `await`-ing it always yields a `Result`. A throw inside `qualify` is itself a\n * `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 `E` or a `Defect`.\n *\n * @example\n * ```ts\n * import { fromPromise, defect } from \"unthrown\";\n * const user = await fromPromise(fetchUser(id), (cause) =>\n * cause instanceof NotFoundError ? (\"not_found\" as const) : defect(cause),\n * );\n * ```\n */\nexport function fromPromise<T, R>(\n promise: Promise<T> | (() => Promise<T>),\n qualify: (cause: unknown) => R,\n): AsyncResult<T, Exclude<R, Defect>> {\n type E = Exclude<R, Defect>;\n const triage = qualify as (cause: unknown) => E | Defect;\n const p = typeof promise === \"function\" ? Promise.resolve().then(promise) : 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 */\nexport function fromSafePromise<T>(\n promise: Promise<T> | (() => Promise<T>),\n): AsyncResult<T, never> {\n const p = typeof promise === \"function\" ? Promise.resolve().then(promise) : 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) => E | Defect,\n): Result<T, E> {\n try {\n const q = qualify(cause);\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/**\n * Collect {@link Result}s into a single `Result` of all their 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.\n *\n * @typeParam Rs - the tuple/array of input `Result` types.\n * @param results - the results to combine.\n *\n * @example\n * ```ts\n * import { all, ok } from \"unthrown\";\n * all([ok(1), ok(\"a\"), ok(true)]).unwrap(); // [1, \"a\", true] (typed [number, string, boolean])\n * all([ok(1), ok(2)] as Result<number, never>[]).unwrap(); // number[]\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 type Out = Result<AllOk<Rs, { [K in keyof Rs]: OkOf<Rs[K]> }>, ErrOf<Rs[number]>>;\n const values: unknown[] = [];\n let firstErr: Result<unknown, unknown> | undefined;\n let firstDefect: Result<unknown, unknown> | undefined;\n\n for (const r of results) {\n if (r.tag === \"Defect\") firstDefect ??= r;\n else if (r.tag === \"Err\") firstErr ??= r;\n else values.push(r.value);\n }\n\n if (firstDefect) return firstDefect as Out;\n if (firstErr) return firstErr as Out;\n return ok(values) as Out;\n}\n\n/**\n * The asynchronous counterpart of {@link all}: combine {@link AsyncResult}s into\n * one `AsyncResult` of all their success values.\n *\n * @remarks\n * The inputs are resolved **concurrently** (their order is preserved); the\n * resolved `Result`s are then folded with the same rules as {@link all} —\n * first `Err` short-circuits, any `Defect` dominates. As ever, the returned\n * `AsyncResult`'s internal promise never rejects. A **fixed tuple** keeps its\n * positional types; a **dynamic array** `AsyncResult<T, E>[]` collapses to\n * `AsyncResult<T[], E>`.\n *\n * @typeParam Rs - the tuple/array of input `AsyncResult` types.\n * @param results - the async results to combine.\n *\n * @example\n * ```ts\n * import { allAsync, fromSafePromise } from \"unthrown\";\n * const both = await allAsync([fromSafePromise(a()), fromSafePromise(b())]);\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 type Out = 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 // and resolves to the ordered Results; `all` then folds them. The internal\n // promise still never rejects.\n const settled = Promise.all(results).then((resolved) =>\n all(resolved as readonly Result<unknown, unknown>[]),\n );\n return new AsyncRes(settled) as unknown as Out;\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 { defect } from \"./defect.js\";\nimport {\n all,\n allAsync,\n fromNullable,\n fromPromise,\n fromSafePromise,\n fromThrowable,\n} from \"./interop.js\";\nimport type { Result as ResultType } from \"./types.js\";\n\n/**\n * Companion object grouping the standalone entry points under a single,\n * discoverable namespace: {@link Result.ok}, {@link Result.err},\n * {@link Result.defect}, {@link Result.fromNullable}, {@link Result.fromThrowable},\n * {@link Result.fromPromise}, {@link Result.fromSafePromise}, {@link Result.all},\n * {@link Result.allAsync}, {@link Result.isOk}, {@link Result.isErr},\n * {@link Result.isDefect}.\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 * @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 defect,\n fromNullable,\n fromThrowable,\n fromPromise,\n fromSafePromise,\n all,\n allAsync,\n isOk,\n isErr,\n isDefect,\n} as const;\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","// 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 */\nexport type TaggedErrorInstance<Tag extends string, A extends Props> = Error &\n Readonly<A> & { 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.\n *\n * @typeParam Tag - the string literal discriminant.\n */\nexport type TaggedErrorConstructor<Tag extends string> = {\n new <A extends Props = {}>(args: keyof A extends never ? void : A): 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.\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 * @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 */\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 * 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>`.\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 * @example\n * ```ts\n * class NotFound extends TaggedError(\"NotFound\") {}\n * class Forbidden extends TaggedError(\"Forbidden\")<{ user: string }> {}\n *\n * declare const 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 */\nexport function matchTags<T, E extends { _tag: string }, R>(\n result: Result<T, E>,\n handlers: TagHandlers<T, E, R>,\n): R;\nexport function matchTags<T, E extends { _tag: string }, R>(\n result: AsyncResult<T, E>,\n handlers: TagHandlers<T, E, R>,\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 handler = handlers[error._tag as E[\"_tag\"]] as unknown as (e: E) => R;\n return handler(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":";;;;;;;;;;;;AA4BA,IAAa,cAAb,cAA8C,MAAM;;;;;CAKlD;CACA,YAAY,OAAU;EACpB,MAAM,kDAAkD;EACxD,KAAK,OAAO;EACZ,KAAK,QAAQ;EACb,OAAO,eAAe,MAAM,IAAI,OAAO,SAAS;CAClD;AACF;;;;;;;;AASA,IAAM,MAAN,MAAgB;CACd,IAA2B,GAAkC;EAC3D,IAAI,KAAK,QAAQ,MAAM,OAAO;EAC9B,IAAI;GACF,OAAO,MAAM,EAAE,KAAK,KAAK,CAAC;EAC5B,SAAS,OAAO;GACd,OAAO,UAAU,KAAK;EACxB;CACF;CAEA,QAAmC,GAAmD;EACpF,IAAI,KAAK,QAAQ,MAAM,OAAO;EAC9B,IAAI;GACF,OAAO,EAAE,KAAK,KAAK;EACrB,SAAS,OAAO;GACd,OAAO,UAAU,KAAK;EACxB;CACF;CAEA,IAAwB,GAAqC;EAC3D,IAAI,KAAK,QAAQ,MAAM,OAAO;EAC9B,IAAI;GACF,EAAE,KAAK,KAAK;GACZ,OAAO;EACT,SAAS,OAAO;GACd,OAAO,UAAU,KAAK;EACxB;CACF;CAEA,GAA0B,OAAwB;EAChD,IAAI,KAAK,QAAQ,MAAM,OAAO;EAC9B,OAAO,MAAM,KAAK;CACpB;CAEA,OAA+B,GAAoC;EACjE,IAAI,KAAK,QAAQ,OAAO,OAAO;EAC/B,IAAI;GACF,OAAO,OAAO,EAAE,KAAK,KAAK,CAAC;EAC7B,SAAS,OAAO;GACd,OAAO,UAAU,KAAK;EACxB;CACF;CAEA,OAAkC,GAAmD;EACnF,IAAI,KAAK,QAAQ,OAAO,OAAO;EAC/B,IAAI;GACF,OAAO,EAA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CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;ACoBA,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;AAsDA,SAAgB,UACd,QACA,UACgB;CAChB,MAAM,SAAS,UAAgB;EAC7B,MAAM,UAAU,SAAS,MAAM;EAC/B,OAAO,QAAQ,KAAK;CACtB;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/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// The only casts left are the inherent type-changing pass-throughs (e.g. `map`\n// reusing an `Err` as a differently-typed `Result`) — the same `as unknown as`\n// boxed uses, sound because the passed-through variant carries no value of the\n// changed type.\n\nimport type { AsyncResult, DefectView, ErrView, OkView, Result } 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 * 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 */\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\");\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): Result<U, E> {\n if (this.tag !== \"Ok\") return this as unknown as Result<U, E>;\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 this as unknown as Result<U, E | E2>;\n try {\n return f(this.value) as Result<U, E | E2>;\n } catch (cause) {\n return defectRes(cause);\n }\n }\n\n tap(this: Result<T, E>, f: (value: T) => void): 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 as unknown as Result<T, E | E2>;\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 : r) as unknown as Result<T, E | E2>;\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 this as unknown as Result<U, E>;\n return okRes(value);\n }\n\n mapErr<E2>(this: Result<T, E>, f: (error: E) => E2): Result<T, E2> {\n if (this.tag !== \"Err\") return this as unknown as Result<T, E2>;\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 this as unknown as Result<T | U, E2>;\n try {\n return f(this.error) as Result<T | U, E2>;\n } catch (cause) {\n return defectRes(cause);\n }\n }\n\n recover<U>(this: Result<T, E>, f: (error: E) => U): Result<T | U, never> {\n if (this.tag !== \"Err\") return this as unknown as Result<T | U, never>;\n try {\n return okRes(f(this.error));\n } catch (cause) {\n return defectRes(cause);\n }\n }\n\n tapErr(this: Result<T, E>, f: (error: E) => void): Result<T, E> {\n if (this.tag !== \"Err\") return this;\n try {\n f(this.error);\n return this;\n } catch (cause) {\n return defectRes(cause);\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 as unknown as Result<T | U, E | E2>;\n try {\n return f(this.cause) as Result<T | U, E | E2>;\n } catch (cause) {\n return defectRes(cause);\n }\n }\n\n tapDefect(this: Result<T, E>, f: (cause: unknown) => void): Result<T, E> {\n if (this.tag !== \"Defect\") return this;\n try {\n f(this.cause);\n return this;\n } catch (cause) {\n return defectRes(cause);\n }\n }\n\n match<R>(\n this: Result<T, E>,\n cases: { ok: (value: T) => R; err: (error: E) => R; defect: (cause: unknown) => R },\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(this: Result<T, E>, fallback: T): T {\n if (this.tag === \"Ok\") return this.value;\n if (this.tag === \"Defect\") throw this.cause;\n return fallback;\n }\n\n unwrapOrElse(this: Result<T, E>, f: (error: E) => T): T {\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 isErr(this: Result<T, E>): this is ErrView<E, T> {\n return this.tag === \"Err\";\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 return Object.assign(Object.create(RESULT_PROTO), { tag: \"Ok\" as const, value }) 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.assign(Object.create(RESULT_PROTO), { tag: \"Err\" as const, error }) as ErrView<\n E,\n T\n >;\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.assign(Object.create(RESULT_PROTO), {\n tag: \"Defect\" as const,\n cause,\n }) as DefectView<T, E>;\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): AsyncResult<U, E> {\n return new AsyncRes<U, E>(\n this.promise.then((r) => {\n if (r.tag !== \"Ok\") return r as unknown as Result<U, E>;\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 r as unknown as Result<U, E | E2>;\n try {\n return (await f(r.value)) as Result<U, E | E2>;\n } catch (cause) {\n return defectRes(cause);\n }\n }),\n );\n }\n\n tap(f: (value: T) => void): 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 r as unknown as Result<T, E | E2>;\n try {\n const inner = (await f(r.value)) as Result<unknown, E2>;\n // Keep the original value on success; an Err/Defect from `f` wins.\n return (inner.tag === \"Ok\" ? r : inner) as unknown as Result<T, E | E2>;\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) =>\n r.tag === \"Ok\" ? okRes<U, E>(value) : (r as unknown as Result<U, E>),\n ),\n );\n }\n\n mapErr<E2>(f: (error: E) => E2): AsyncResult<T, E2> {\n return new AsyncRes<T, E2>(\n this.promise.then((r) => {\n if (r.tag !== \"Err\") return r as unknown as Result<T, E2>;\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 r as unknown as Result<T | U, E2>;\n try {\n return (await f(r.error)) as Result<T | U, E2>;\n } catch (cause) {\n return defectRes(cause);\n }\n }),\n );\n }\n\n recover<U>(f: (error: E) => U): AsyncResult<T | U, never> {\n return new AsyncRes<T | U, never>(\n this.promise.then((r) => {\n if (r.tag !== \"Err\") return r as unknown as Result<T | U, never>;\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(f: (error: E) => void): 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 defectRes<T, E>(cause);\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 as unknown as Result<T | U, E | E2>;\n try {\n return (await f(r.cause)) as Result<T | U, E | E2>;\n } catch (cause) {\n return defectRes(cause);\n }\n }),\n );\n }\n\n tapDefect(f: (cause: unknown) => void): 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 defectRes<T, E>(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(fallback: T): Promise<T> {\n return this.promise.then((r) => r.unwrapOr(fallback));\n }\n unwrapOrElse(f: (error: E) => T): Promise<T> {\n return this.promise.then((r) => {\n if (r.tag === \"Ok\") return r.value;\n if (r.tag === \"Defect\") throw r.cause;\n return f(r.error);\n });\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 * ok(42).unwrap(); // 42\n * ```\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 * err(\"not_found\").unwrapErr(); // \"not_found\"\n * ```\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, type Result } from \"unthrown\";\n * declare const r: Result<number, string>;\n * if (isOk(r)) r.value; // number, narrowed\n * ```\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 */\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 * @returns `true` when `r` is a `Defect`.\n */\nexport function isDefect<T, E>(r: Result<T, E>): r is DefectView<T, E> {\n return r.tag === \"Defect\";\n}\n","// Defect marker plumbing.\n\nconst DEFECT: unique symbol = Symbol(\"unthrown/defect\");\n\n/**\n * The marker a `qualify` function returns to triage a cause as **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\n * {@link defect} to say \"this failure is not modeled\". A `Defect` is opaque —\n * it carries the original cause for the boundary to convert into the third\n * runtime state of a `Result`.\n */\nexport type Defect = {\n readonly [DEFECT]: true;\n readonly cause: unknown;\n};\n\n/**\n * Wrap a cause as a {@link Defect} — the value you return from a `qualify`\n * function when a failure is **not** a modeled domain error.\n *\n * @param cause - the original thrown/rejected value.\n * @returns an opaque defect marker carrying `cause`.\n *\n * @example\n * ```ts\n * import { fromPromise, defect } from \"unthrown\";\n *\n * const user = fromPromise(fetchUser(id), (cause) =>\n * cause instanceof NotFoundError ? cause : defect(cause),\n * );\n * ```\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, 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 * @example\n * ```ts\n * import { fromNullable } from \"unthrown\";\n * fromNullable(map.get(key), () => \"missing\").unwrap();\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 * {@link Defect} (via {@link defect}) — there is no path that leaves `unknown`\n * in `E`. A throw inside `qualify` itself is treated 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 `E` or a `Defect`.\n * @returns a function with the same arguments returning `Result<T, E>`.\n *\n * @example\n * ```ts\n * import { fromThrowable, defect } from \"unthrown\";\n * const parse = fromThrowable(JSON.parse, (cause) => defect(cause));\n * parse(\"{}\").unwrap();\n * ```\n */\nexport function fromThrowable<A extends unknown[], T, R>(\n fn: (...args: A) => T,\n qualify: (cause: unknown) => R,\n): (...args: A) => Result<T, Exclude<R, Defect>> {\n type E = Exclude<R, Defect>;\n const triage = qualify as (cause: unknown) => 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 * {@link Defect}. The returned `AsyncResult`'s internal promise never rejects;\n * `await`-ing it always yields a `Result`. A throw inside `qualify` is itself a\n * `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 `E` or a `Defect`.\n *\n * @example\n * ```ts\n * import { fromPromise, defect } from \"unthrown\";\n * const user = await fromPromise(fetchUser(id), (cause) =>\n * cause instanceof NotFoundError ? (\"not_found\" as const) : defect(cause),\n * );\n * ```\n */\nexport function fromPromise<T, R>(\n promise: Promise<T> | (() => Promise<T>),\n qualify: (cause: unknown) => R,\n): AsyncResult<T, Exclude<R, Defect>> {\n type E = Exclude<R, Defect>;\n const triage = qualify as (cause: unknown) => E | Defect;\n const p = typeof promise === \"function\" ? Promise.resolve().then(promise) : 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 */\nexport function fromSafePromise<T>(\n promise: Promise<T> | (() => Promise<T>),\n): AsyncResult<T, never> {\n const p = typeof promise === \"function\" ? Promise.resolve().then(promise) : 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) => E | Defect,\n): Result<T, E> {\n try {\n const q = qualify(cause);\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\") firstDefect ??= r;\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\") firstDefect ??= r;\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 * @example\n * ```ts\n * import { all, ok } from \"unthrown\";\n * all([ok(1), ok(\"a\"), ok(true)]).unwrap(); // [1, \"a\", true] (typed [number, string, boolean])\n * all([ok(1), ok(2)] as Result<number, never>[]).unwrap(); // number[]\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 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 * @example\n * ```ts\n * import { allFromDict, ok } from \"unthrown\";\n * allFromDict({ id: ok(1), name: ok(\"ada\") }).unwrap(); // { id: 1, name: \"ada\" }\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 Result<{ [K in keyof R]: OkOf<R[K]> }, ErrOf<R[keyof R]>>;\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 * @example\n * ```ts\n * import { allAsync, fromSafePromise } from \"unthrown\";\n * await allAsync([fromSafePromise(a()), fromSafePromise(b())]);\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 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 * @example\n * ```ts\n * import { allFromDictAsync, fromSafePromise } from \"unthrown\";\n * await allFromDictAsync({ a: fromSafePromise(a()), b: fromSafePromise(b()) });\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] as Result<unknown, unknown>;\n });\n return foldRecord(byKey);\n });\n return new AsyncRes(settled) 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 { defect } from \"./defect.js\";\nimport {\n all,\n allAsync,\n allFromDict,\n allFromDictAsync,\n fromNullable,\n fromPromise,\n fromSafePromise,\n fromThrowable,\n} from \"./interop.js\";\nimport type { Result as ResultType } from \"./types.js\";\n\n/**\n * Companion object grouping the standalone entry points under a single,\n * discoverable namespace: {@link Result.ok}, {@link Result.err},\n * {@link Result.defect}, {@link Result.fromNullable}, {@link Result.fromThrowable},\n * {@link Result.fromPromise}, {@link Result.fromSafePromise}, {@link Result.all},\n * {@link Result.allAsync}, {@link Result.allFromDict},\n * {@link Result.allFromDictAsync}, {@link Result.isOk}, {@link Result.isErr},\n * {@link Result.isDefect}.\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 * @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 defect,\n fromNullable,\n fromThrowable,\n fromPromise,\n fromSafePromise,\n all,\n allAsync,\n allFromDict,\n allFromDictAsync,\n isOk,\n isErr,\n isDefect,\n} as const;\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","// 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 */\nexport type TaggedErrorInstance<Tag extends string, A extends Props> = Error &\n Readonly<A> & { 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.\n *\n * @typeParam Tag - the string literal discriminant.\n */\nexport type TaggedErrorConstructor<Tag extends string> = {\n new <A extends Props = {}>(args: keyof A extends never ? void : A): 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.\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 * @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 */\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 * 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>`.\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 * @example\n * ```ts\n * class NotFound extends TaggedError(\"NotFound\") {}\n * class Forbidden extends TaggedError(\"Forbidden\")<{ user: string }> {}\n *\n * declare const 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 */\nexport function matchTags<T, E extends { _tag: string }, R>(\n result: Result<T, E>,\n handlers: TagHandlers<T, E, R>,\n): R;\nexport function matchTags<T, E extends { _tag: string }, R>(\n result: AsyncResult<T, E>,\n handlers: TagHandlers<T, E, R>,\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 handler = handlers[error._tag as E[\"_tag\"]] as unknown as (e: E) => R;\n return handler(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":";;;;;;;;;;;;AA4BA,IAAa,cAAb,cAA8C,MAAM;;;;;CAKlD;CACA,YAAY,OAAU;EACpB,MAAM,kDAAkD;EACxD,KAAK,OAAO;EACZ,KAAK,QAAQ;EACb,OAAO,eAAe,MAAM,IAAI,OAAO,SAAS;CAClD;AACF;;;;;;;;AASA,IAAM,MAAN,MAAgB;CACd,IAA2B,GAAkC;EAC3D,IAAI,KAAK,QAAQ,MAAM,OAAO;EAC9B,IAAI;GACF,OAAO,MAAM,EAAE,KAAK,KAAK,CAAC;EAC5B,SAAS,OAAO;GACd,OAAO,UAAU,KAAK;EACxB;CACF;CAEA,QAAmC,GAAmD;EACpF,IAAI,KAAK,QAAQ,MAAM,OAAO;EAC9B,IAAI;GACF,OAAO,EAAE,KAAK,KAAK;EACrB,SAAS,OAAO;GACd,OAAO,UAAU,KAAK;EACxB;CACF;CAEA,IAAwB,GAAqC;EAC3D,IAAI,KAAK,QAAQ,MAAM,OAAO;EAC9B,IAAI;GACF,EAAE,KAAK,KAAK;GACZ,OAAO;EACT,SAAS,OAAO;GACd,OAAO,UAAU,KAAK;EACxB;C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