@nlozgachev/pipelined 0.43.0 → 0.44.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/README.md +10 -10
- package/dist/{InternalTypes-DuzMFAfJ.d.ts → InternalTypes-7o9-yrHq.d.ts} +1 -1
- package/dist/{InternalTypes-DsCqxWZm.d.mts → InternalTypes-BL23H8Qr.d.mts} +1 -1
- package/dist/{Validation-BOPLiDqa.d.ts → Validation-DM2eh6wj.d.ts} +126 -126
- package/dist/{Validation-Do6uWLLZ.d.mts → Validation-Dz70wtcG.d.mts} +126 -126
- package/dist/{chunk-W6RWKBDX.mjs → chunk-LKTOK5IT.mjs} +1 -1
- package/dist/{chunk-CHRXZIJU.mjs → chunk-ND476266.mjs} +3 -0
- package/dist/composition.d.mts +1 -1
- package/dist/composition.d.ts +1 -1
- package/dist/core.d.mts +4 -4
- package/dist/core.d.ts +4 -4
- package/dist/core.js +6 -0
- package/dist/core.mjs +7 -1
- package/dist/index.d.mts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +6 -0
- package/dist/index.mjs +8 -2
- package/dist/utils.d.mts +4 -4
- package/dist/utils.d.ts +4 -4
- package/dist/utils.mjs +2 -2
- package/package.json +5 -5
package/README.md
CHANGED
|
@@ -17,7 +17,7 @@ npm add @nlozgachev/pipelined
|
|
|
17
17
|
In mainstream TypeScript, code is often burdened by implicit control flow: unchecked exceptions,
|
|
18
18
|
manual null propagation, and unhandled asynchronous failures. `pipelined` turns these complex
|
|
19
19
|
runtime states into simple, transparent data structures that compose. By representing optionality as
|
|
20
|
-
`Maybe`, failures as `Result`, lazy asynchronous pipelines as `
|
|
20
|
+
`Maybe`, failures as `Result`, lazy asynchronous pipelines as `Task.Result`, and repeated stateful
|
|
21
21
|
interactions as `Op`, the library helps disentangle business logic from control mechanics.
|
|
22
22
|
|
|
23
23
|
## Documentation
|
|
@@ -55,18 +55,18 @@ Every step that sees `None` is skipped. The fallback runs once, at the end.
|
|
|
55
55
|
## Example: typed async errors
|
|
56
56
|
|
|
57
57
|
In JavaScript, asynchronous exceptions bypass the static type system, leaving unhandled rejections
|
|
58
|
-
as invisible runtime risks. `
|
|
58
|
+
as invisible runtime risks. `Task.Result<E, A>` represents fallible asynchronous computations as
|
|
59
59
|
lazy, infallible tasks that resolve to a typed `Result`. The error type is explicitly tracked in the
|
|
60
60
|
function signature, ensuring that failures are handled before compile time:
|
|
61
61
|
|
|
62
62
|
```ts
|
|
63
63
|
import { pipe } from "@nlozgachev/pipelined/composition";
|
|
64
|
-
import { Result,
|
|
64
|
+
import { Result, Task } from "@nlozgachev/pipelined/core";
|
|
65
65
|
|
|
66
66
|
type ApiError = { status: number; message: string };
|
|
67
67
|
|
|
68
|
-
const fetchUser = (id: string):
|
|
69
|
-
|
|
68
|
+
const fetchUser = (id: string): Task.Result<ApiError, User> =>
|
|
69
|
+
Task.Result.tryCatch(
|
|
70
70
|
(signal) =>
|
|
71
71
|
fetch(`/users/${id}`, { signal }).then((r) => {
|
|
72
72
|
if (!r.ok) throw { status: r.status, message: r.statusText };
|
|
@@ -75,8 +75,8 @@ const fetchUser = (id: string): TaskResult<ApiError, User> =>
|
|
|
75
75
|
(e) => e as ApiError,
|
|
76
76
|
);
|
|
77
77
|
|
|
78
|
-
const fetchPosts = (userId: string):
|
|
79
|
-
|
|
78
|
+
const fetchPosts = (userId: string): Task.Result<ApiError, Post[]> =>
|
|
79
|
+
Task.Result.tryCatch(
|
|
80
80
|
(signal) =>
|
|
81
81
|
fetch(`/users/${userId}/posts`, { signal }).then((r) => r.json()),
|
|
82
82
|
(e) => e as ApiError,
|
|
@@ -86,10 +86,10 @@ const fetchPosts = (userId: string): TaskResult<ApiError, Post[]> =>
|
|
|
86
86
|
const userWithPosts = (id: string) =>
|
|
87
87
|
pipe(
|
|
88
88
|
fetchUser(id),
|
|
89
|
-
|
|
89
|
+
Task.Result.chain((user) =>
|
|
90
90
|
pipe(
|
|
91
91
|
fetchPosts(user.id),
|
|
92
|
-
|
|
92
|
+
Task.Result.map((posts) => ({ ...user, posts })),
|
|
93
93
|
)
|
|
94
94
|
),
|
|
95
95
|
);
|
|
@@ -314,7 +314,7 @@ provides a strongly-typed, immutable two-element pair.
|
|
|
314
314
|
### Asynchronous operations
|
|
315
315
|
|
|
316
316
|
`Task` represents a lazy, infallible asynchronous computation. Fallible asynchronous workflows are
|
|
317
|
-
handled by `
|
|
317
|
+
handled by `Task.Result`, `Task.Maybe`, and `Task.Validation`. For managing stateful, recurring
|
|
318
318
|
asynchronous operations with complex scheduling, `Op` implements named concurrency strategies such
|
|
319
319
|
as `restartable`, `exclusive`, `debounced`, `throttled`, and `queue`, handling retries, timeouts,
|
|
320
320
|
and signal propagation automatically. `Deferred` represents a lightweight, infallible asynchronous
|
|
@@ -30,7 +30,7 @@ declare namespace Deferred {
|
|
|
30
30
|
* `.catch()`, `.finally()`, and chainable `.then()`.
|
|
31
31
|
*
|
|
32
32
|
* **Precondition**: `p` must never reject. If `p` rejects, the returned `Deferred` will
|
|
33
|
-
* never resolve — `await`-ing it will hang indefinitely. Use `
|
|
33
|
+
* never resolve — `await`-ing it will hang indefinitely. Use `Task.Result.tryCatch` to
|
|
34
34
|
* handle operations that may fail before converting to a `Deferred`.
|
|
35
35
|
*
|
|
36
36
|
* @example
|
|
@@ -30,7 +30,7 @@ declare namespace Deferred {
|
|
|
30
30
|
* `.catch()`, `.finally()`, and chainable `.then()`.
|
|
31
31
|
*
|
|
32
32
|
* **Precondition**: `p` must never reject. If `p` rejects, the returned `Deferred` will
|
|
33
|
-
* never resolve — `await`-ing it will hang indefinitely. Use `
|
|
33
|
+
* never resolve — `await`-ing it will hang indefinitely. Use `Task.Result.tryCatch` to
|
|
34
34
|
* handle operations that may fail before converting to a `Deferred`.
|
|
35
35
|
*
|
|
36
36
|
* @example
|