unthrown 5.1.0 → 5.2.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 +13 -3
- package/dist/index.d.cts +27 -9
- package/dist/index.d.mts +27 -9
- package/dist/index.mjs +13 -3
- package/package.json +4 -8
package/dist/index.cjs
CHANGED
|
@@ -538,7 +538,11 @@ function defectRes(cause) {
|
|
|
538
538
|
* // `E` is `unknown` here — an untyped boundary has no cases to enumerate,
|
|
539
539
|
* // so the `P._` escape hatch is the only arm that can terminate the match:
|
|
540
540
|
* // oxlint-disable-next-line unthrown/no-catch-all-pattern -- untyped boundary: `E` is `unknown`
|
|
541
|
-
* x.match({
|
|
541
|
+
* x.match({
|
|
542
|
+
* ok: () => 1,
|
|
543
|
+
* errCases: (m) => m.with(P._, () => 0),
|
|
544
|
+
* defect: () => -1,
|
|
545
|
+
* });
|
|
542
546
|
* ```
|
|
543
547
|
*
|
|
544
548
|
* @category Guards
|
|
@@ -1452,7 +1456,10 @@ function allFromDict(results) {
|
|
|
1452
1456
|
* ```ts
|
|
1453
1457
|
* import { allAsync, fromSafePromise } from "unthrown";
|
|
1454
1458
|
*
|
|
1455
|
-
* const both = allAsync([
|
|
1459
|
+
* const both = allAsync([
|
|
1460
|
+
* fromSafePromise(Promise.resolve(1)),
|
|
1461
|
+
* fromSafePromise(Promise.resolve(2)),
|
|
1462
|
+
* ]);
|
|
1456
1463
|
* (await both).get(); // => [1, 2]
|
|
1457
1464
|
* ```
|
|
1458
1465
|
*/
|
|
@@ -1556,7 +1563,10 @@ const Result = {
|
|
|
1556
1563
|
* @example
|
|
1557
1564
|
* ```ts
|
|
1558
1565
|
* import { AsyncResult } from "unthrown";
|
|
1559
|
-
* const user = await AsyncResult.fromPromise(
|
|
1566
|
+
* const user = await AsyncResult.fromPromise(
|
|
1567
|
+
* fetchUser(id),
|
|
1568
|
+
* (c, defect) => defect(c),
|
|
1569
|
+
* );
|
|
1560
1570
|
* user.get(); // => the fetched user (on success)
|
|
1561
1571
|
* ```
|
|
1562
1572
|
*/
|
package/dist/index.d.cts
CHANGED
|
@@ -766,12 +766,20 @@ type ResultMethods<out T, out E> = {
|
|
|
766
766
|
*
|
|
767
767
|
* @remarks
|
|
768
768
|
* A deliberate escape hatch off the errors-as-values model — it **throws the
|
|
769
|
-
* `Err` value as-is** at the call site
|
|
770
|
-
*
|
|
771
|
-
* this
|
|
772
|
-
*
|
|
773
|
-
*
|
|
774
|
-
*
|
|
769
|
+
* `Err` value as-is** at the call site, so a caller of the enclosing function
|
|
770
|
+
* sees a throw rather than a channel. Its home is **tests and scripts**,
|
|
771
|
+
* where "this `Result` had better be `Ok`" is the assertion and a throw is
|
|
772
|
+
* the correct failure mode.
|
|
773
|
+
*
|
|
774
|
+
* In production code, fold the error channel instead:
|
|
775
|
+
* {@link ResultMethods.recoverErrCases | recoverErrCases} empties `E`, so
|
|
776
|
+
* {@link ResultMethods.get | get} compiles and a case routed to the injected
|
|
777
|
+
* `defect(...)` panics with its original cause — with every case still named.
|
|
778
|
+
* {@link ResultMethods.match | match} and
|
|
779
|
+
* {@link ResultMethods.flatMapErrCases | flatMapErrCases} are the other two
|
|
780
|
+
* ways to keep the error a value. `@unthrown/oxlint`'s opt-in
|
|
781
|
+
* `no-get-or-throw` rule enforces this, exempting test files through an
|
|
782
|
+
* oxlint `overrides` entry.
|
|
775
783
|
*
|
|
776
784
|
* Type-gated as the **complement** of {@link ResultMethods.get | get}: it
|
|
777
785
|
* compiles only when the error channel is **non-empty** (`E` is not `never`) —
|
|
@@ -1450,7 +1458,11 @@ declare class GetError<E = unknown> extends Error {
|
|
|
1450
1458
|
* // `E` is `unknown` here — an untyped boundary has no cases to enumerate,
|
|
1451
1459
|
* // so the `P._` escape hatch is the only arm that can terminate the match:
|
|
1452
1460
|
* // oxlint-disable-next-line unthrown/no-catch-all-pattern -- untyped boundary: `E` is `unknown`
|
|
1453
|
-
* x.match({
|
|
1461
|
+
* x.match({
|
|
1462
|
+
* ok: () => 1,
|
|
1463
|
+
* errCases: (m) => m.with(P._, () => 0),
|
|
1464
|
+
* defect: () => -1,
|
|
1465
|
+
* });
|
|
1454
1466
|
* ```
|
|
1455
1467
|
*
|
|
1456
1468
|
* @category Guards
|
|
@@ -1790,7 +1802,10 @@ declare function allFromDict<R extends ResultRecord>(results: R): Result$1<{ [K
|
|
|
1790
1802
|
* ```ts
|
|
1791
1803
|
* import { allAsync, fromSafePromise } from "unthrown";
|
|
1792
1804
|
*
|
|
1793
|
-
* const both = allAsync([
|
|
1805
|
+
* const both = allAsync([
|
|
1806
|
+
* fromSafePromise(Promise.resolve(1)),
|
|
1807
|
+
* fromSafePromise(Promise.resolve(2)),
|
|
1808
|
+
* ]);
|
|
1794
1809
|
* (await both).get(); // => [1, 2]
|
|
1795
1810
|
* ```
|
|
1796
1811
|
*/
|
|
@@ -1898,7 +1913,10 @@ type Result<T, E> = Result$1<T, E>;
|
|
|
1898
1913
|
* @example
|
|
1899
1914
|
* ```ts
|
|
1900
1915
|
* import { AsyncResult } from "unthrown";
|
|
1901
|
-
* const user = await AsyncResult.fromPromise(
|
|
1916
|
+
* const user = await AsyncResult.fromPromise(
|
|
1917
|
+
* fetchUser(id),
|
|
1918
|
+
* (c, defect) => defect(c),
|
|
1919
|
+
* );
|
|
1902
1920
|
* user.get(); // => the fetched user (on success)
|
|
1903
1921
|
* ```
|
|
1904
1922
|
*/
|
package/dist/index.d.mts
CHANGED
|
@@ -766,12 +766,20 @@ type ResultMethods<out T, out E> = {
|
|
|
766
766
|
*
|
|
767
767
|
* @remarks
|
|
768
768
|
* A deliberate escape hatch off the errors-as-values model — it **throws the
|
|
769
|
-
* `Err` value as-is** at the call site
|
|
770
|
-
*
|
|
771
|
-
* this
|
|
772
|
-
*
|
|
773
|
-
*
|
|
774
|
-
*
|
|
769
|
+
* `Err` value as-is** at the call site, so a caller of the enclosing function
|
|
770
|
+
* sees a throw rather than a channel. Its home is **tests and scripts**,
|
|
771
|
+
* where "this `Result` had better be `Ok`" is the assertion and a throw is
|
|
772
|
+
* the correct failure mode.
|
|
773
|
+
*
|
|
774
|
+
* In production code, fold the error channel instead:
|
|
775
|
+
* {@link ResultMethods.recoverErrCases | recoverErrCases} empties `E`, so
|
|
776
|
+
* {@link ResultMethods.get | get} compiles and a case routed to the injected
|
|
777
|
+
* `defect(...)` panics with its original cause — with every case still named.
|
|
778
|
+
* {@link ResultMethods.match | match} and
|
|
779
|
+
* {@link ResultMethods.flatMapErrCases | flatMapErrCases} are the other two
|
|
780
|
+
* ways to keep the error a value. `@unthrown/oxlint`'s opt-in
|
|
781
|
+
* `no-get-or-throw` rule enforces this, exempting test files through an
|
|
782
|
+
* oxlint `overrides` entry.
|
|
775
783
|
*
|
|
776
784
|
* Type-gated as the **complement** of {@link ResultMethods.get | get}: it
|
|
777
785
|
* compiles only when the error channel is **non-empty** (`E` is not `never`) —
|
|
@@ -1450,7 +1458,11 @@ declare class GetError<E = unknown> extends Error {
|
|
|
1450
1458
|
* // `E` is `unknown` here — an untyped boundary has no cases to enumerate,
|
|
1451
1459
|
* // so the `P._` escape hatch is the only arm that can terminate the match:
|
|
1452
1460
|
* // oxlint-disable-next-line unthrown/no-catch-all-pattern -- untyped boundary: `E` is `unknown`
|
|
1453
|
-
* x.match({
|
|
1461
|
+
* x.match({
|
|
1462
|
+
* ok: () => 1,
|
|
1463
|
+
* errCases: (m) => m.with(P._, () => 0),
|
|
1464
|
+
* defect: () => -1,
|
|
1465
|
+
* });
|
|
1454
1466
|
* ```
|
|
1455
1467
|
*
|
|
1456
1468
|
* @category Guards
|
|
@@ -1790,7 +1802,10 @@ declare function allFromDict<R extends ResultRecord>(results: R): Result$1<{ [K
|
|
|
1790
1802
|
* ```ts
|
|
1791
1803
|
* import { allAsync, fromSafePromise } from "unthrown";
|
|
1792
1804
|
*
|
|
1793
|
-
* const both = allAsync([
|
|
1805
|
+
* const both = allAsync([
|
|
1806
|
+
* fromSafePromise(Promise.resolve(1)),
|
|
1807
|
+
* fromSafePromise(Promise.resolve(2)),
|
|
1808
|
+
* ]);
|
|
1794
1809
|
* (await both).get(); // => [1, 2]
|
|
1795
1810
|
* ```
|
|
1796
1811
|
*/
|
|
@@ -1898,7 +1913,10 @@ type Result<T, E> = Result$1<T, E>;
|
|
|
1898
1913
|
* @example
|
|
1899
1914
|
* ```ts
|
|
1900
1915
|
* import { AsyncResult } from "unthrown";
|
|
1901
|
-
* const user = await AsyncResult.fromPromise(
|
|
1916
|
+
* const user = await AsyncResult.fromPromise(
|
|
1917
|
+
* fetchUser(id),
|
|
1918
|
+
* (c, defect) => defect(c),
|
|
1919
|
+
* );
|
|
1902
1920
|
* user.get(); // => the fetched user (on success)
|
|
1903
1921
|
* ```
|
|
1904
1922
|
*/
|
package/dist/index.mjs
CHANGED
|
@@ -537,7 +537,11 @@ function defectRes(cause) {
|
|
|
537
537
|
* // `E` is `unknown` here — an untyped boundary has no cases to enumerate,
|
|
538
538
|
* // so the `P._` escape hatch is the only arm that can terminate the match:
|
|
539
539
|
* // oxlint-disable-next-line unthrown/no-catch-all-pattern -- untyped boundary: `E` is `unknown`
|
|
540
|
-
* x.match({
|
|
540
|
+
* x.match({
|
|
541
|
+
* ok: () => 1,
|
|
542
|
+
* errCases: (m) => m.with(P._, () => 0),
|
|
543
|
+
* defect: () => -1,
|
|
544
|
+
* });
|
|
541
545
|
* ```
|
|
542
546
|
*
|
|
543
547
|
* @category Guards
|
|
@@ -1451,7 +1455,10 @@ function allFromDict(results) {
|
|
|
1451
1455
|
* ```ts
|
|
1452
1456
|
* import { allAsync, fromSafePromise } from "unthrown";
|
|
1453
1457
|
*
|
|
1454
|
-
* const both = allAsync([
|
|
1458
|
+
* const both = allAsync([
|
|
1459
|
+
* fromSafePromise(Promise.resolve(1)),
|
|
1460
|
+
* fromSafePromise(Promise.resolve(2)),
|
|
1461
|
+
* ]);
|
|
1455
1462
|
* (await both).get(); // => [1, 2]
|
|
1456
1463
|
* ```
|
|
1457
1464
|
*/
|
|
@@ -1555,7 +1562,10 @@ const Result = {
|
|
|
1555
1562
|
* @example
|
|
1556
1563
|
* ```ts
|
|
1557
1564
|
* import { AsyncResult } from "unthrown";
|
|
1558
|
-
* const user = await AsyncResult.fromPromise(
|
|
1565
|
+
* const user = await AsyncResult.fromPromise(
|
|
1566
|
+
* fetchUser(id),
|
|
1567
|
+
* (c, defect) => defect(c),
|
|
1568
|
+
* );
|
|
1559
1569
|
* user.get(); // => the fetched user (on success)
|
|
1560
1570
|
* ```
|
|
1561
1571
|
*/
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "unthrown",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.2.0",
|
|
4
4
|
"description": "Explicit errors as values, with a separate defect (panic) channel",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"defect",
|
|
@@ -47,13 +47,10 @@
|
|
|
47
47
|
},
|
|
48
48
|
"devDependencies": {
|
|
49
49
|
"@btravstack/tsconfig": "0.2.0",
|
|
50
|
-
"@
|
|
51
|
-
"@types/node": "26.1.1",
|
|
50
|
+
"@types/node": "26.1.2",
|
|
52
51
|
"@vitest/coverage-v8": "4.1.10",
|
|
53
|
-
"tsdown": "0.22.
|
|
54
|
-
"
|
|
55
|
-
"typedoc-plugin-markdown": "4.12.0",
|
|
56
|
-
"typescript": "6.0.3",
|
|
52
|
+
"tsdown": "0.22.14",
|
|
53
|
+
"typescript": "7.0.2",
|
|
57
54
|
"vitest": "4.1.10"
|
|
58
55
|
},
|
|
59
56
|
"engines": {
|
|
@@ -61,7 +58,6 @@
|
|
|
61
58
|
},
|
|
62
59
|
"scripts": {
|
|
63
60
|
"build": "tsdown src/index.ts --format cjs,esm --dts --clean",
|
|
64
|
-
"build:docs": "typedoc",
|
|
65
61
|
"dev": "tsdown src/index.ts --format cjs,esm --dts --watch",
|
|
66
62
|
"test": "vitest run",
|
|
67
63
|
"test:types": "tsc --noEmit -p tsconfig.test-d.json",
|