unthrown 4.3.0 → 5.0.0-beta.1
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 +5 -4
- package/dist/index.cjs +316 -167
- package/dist/index.d.cts +322 -291
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +322 -291
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +302 -166
- package/dist/index.mjs.map +1 -1
- package/package.json +7 -4
package/README.md
CHANGED
|
@@ -11,7 +11,7 @@ pnpm add unthrown
|
|
|
11
11
|
```
|
|
12
12
|
|
|
13
13
|
```ts
|
|
14
|
-
import { fromPromise, TaggedError } from "unthrown";
|
|
14
|
+
import { fromPromise, P, TaggedError } from "unthrown";
|
|
15
15
|
|
|
16
16
|
class NotFound extends TaggedError("NotFound") {} // our modeled domain failure
|
|
17
17
|
class NotFoundError extends Error {} // what `fetchUser` rejects with on a 404
|
|
@@ -22,7 +22,7 @@ const user = fromPromise(fetchUser(id), (cause, defect) =>
|
|
|
22
22
|
|
|
23
23
|
const status = await user.match({
|
|
24
24
|
ok: () => 200,
|
|
25
|
-
err: () => 404,
|
|
25
|
+
err: (matcher) => matcher.with(P._, () => 404), // `err` takes the exhaustive matcher
|
|
26
26
|
defect: () => 500,
|
|
27
27
|
});
|
|
28
28
|
```
|
|
@@ -32,8 +32,9 @@ const status = await user.match({
|
|
|
32
32
|
observable only via `match` / `recoverDefect`.
|
|
33
33
|
- **Qualification at every boundary** — `fromPromise` / `fromThrowable` force you
|
|
34
34
|
to triage each failure into a modeled error or a defect.
|
|
35
|
-
- **Tagged errors** — `TaggedError(tag)` +
|
|
36
|
-
|
|
35
|
+
- **Tagged errors** — `TaggedError(tag)` + `tag(t)`, folded exhaustively through
|
|
36
|
+
`match`'s ts-pattern error matcher.
|
|
37
|
+
- One tiny runtime dependency (`ts-pattern`), ESM-first, dual CJS/ESM.
|
|
37
38
|
|
|
38
39
|
See the [full documentation](https://btravstack.github.io/unthrown/) for the guide
|
|
39
40
|
and complete API.
|