unthrown 5.0.0-beta.0 → 5.0.0-beta.10
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/README.md +14 -5
- package/dist/index.cjs +406 -112
- package/dist/index.d.cts +498 -130
- package/dist/index.d.mts +498 -130
- package/dist/index.mjs +403 -102
- package/package.json +2 -5
- package/dist/index.d.cts.map +0 -1
- package/dist/index.d.mts.map +0 -1
- package/dist/index.mjs.map +0 -1
package/README.md
CHANGED
|
@@ -10,6 +10,9 @@
|
|
|
10
10
|
pnpm add unthrown
|
|
11
11
|
```
|
|
12
12
|
|
|
13
|
+
No peer dependencies — the exhaustive error matcher is built-in and exported as
|
|
14
|
+
`match` / `P`.
|
|
15
|
+
|
|
13
16
|
```ts
|
|
14
17
|
import { fromPromise, P, TaggedError } from "unthrown";
|
|
15
18
|
|
|
@@ -22,23 +25,29 @@ const user = fromPromise(fetchUser(id), (cause, defect) =>
|
|
|
22
25
|
|
|
23
26
|
const status = await user.match({
|
|
24
27
|
ok: () => 200,
|
|
25
|
-
|
|
28
|
+
// `errCases` takes the exhaustive matcher — every case of E named:
|
|
29
|
+
errCases: (matcher) => matcher.with(P.tag("NotFound"), () => 404),
|
|
26
30
|
defect: () => 500,
|
|
27
31
|
});
|
|
28
32
|
```
|
|
29
33
|
|
|
30
34
|
- **Errors as values** via `Result<T, E>` / `AsyncResult<T, E>`.
|
|
31
35
|
- **A separate defect channel** for the unexpected — invisible to the type,
|
|
32
|
-
observable only via `match` / `recoverDefect
|
|
36
|
+
observable only via `match` / `recoverDefect` and the `tapDefect` /
|
|
37
|
+
`tapFailure` observers.
|
|
33
38
|
- **Qualification at every boundary** — `fromPromise` / `fromThrowable` force you
|
|
34
39
|
to triage each failure into a modeled error or a defect.
|
|
35
|
-
- **Tagged errors** — `TaggedError(tag)` + `tag(t)`, folded exhaustively through
|
|
36
|
-
`match`'s
|
|
37
|
-
-
|
|
40
|
+
- **Tagged errors** — `TaggedError(tag)` + `P.tag(t)`, folded exhaustively through
|
|
41
|
+
`match`'s built-in error matcher.
|
|
42
|
+
- **Zero runtime dependencies** (the matcher is built-in), ESM-first, dual
|
|
43
|
+
CJS/ESM.
|
|
38
44
|
|
|
39
45
|
See the [full documentation](https://btravstack.github.io/unthrown/) for the guide
|
|
40
46
|
and complete API.
|
|
41
47
|
|
|
48
|
+
**Upgrading from 4.x?** See
|
|
49
|
+
[Upgrade from 4.x to 5.0](https://btravstack.github.io/unthrown/how-to/upgrade-to-v5).
|
|
50
|
+
|
|
42
51
|
## License
|
|
43
52
|
|
|
44
53
|
[MIT](https://github.com/btravstack/unthrown/blob/main/LICENSE) © Benoit TRAVERS
|