@nlozgachev/pipelined 0.44.0 → 0.46.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 CHANGED
@@ -20,6 +20,11 @@ runtime states into simple, transparent data structures that compose. By represe
20
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
+ To support these patterns without introducing bloat, the library is designed to be lightweight,
24
+ zero-dependency, and fully tree-shakeable. The core module (`/core`) is under 14 KB gzipped, and the
25
+ entire toolkit is under 21 KB gzipped, making it equally suitable for client and server
26
+ environments.
27
+
23
28
  ## Documentation
24
29
 
25
30
  Full guides and API reference at **[pipelined.lozgachev.dev](https://pipelined.lozgachev.dev)**.
@@ -103,7 +108,7 @@ const controller = new AbortController();
103
108
  const fetchUserWithPosts = userWithPosts("42"); // build the lazy task
104
109
  const result = await fetchUserWithPosts(controller.signal); // run it — signal controls cancellation
105
110
 
106
- if (Result.isOk(result)) {
111
+ if (Result.is.ok(result)) {
107
112
  render(result.value); // { ...User, posts: Post[] }
108
113
  } else {
109
114
  showError(result.error); // ApiError — typed, not unknown
@@ -140,7 +145,7 @@ const cheapestByCategory = (items: RawItem[]) =>
140
145
  items,
141
146
  Arr.filterMap(normalise), // parse + drop unparseable prices in one pass
142
147
  Arr.sortBy((a, b) => a.price - b.price), // ascending price
143
- Arr.groupBy((item) => item.category), // Record<string, NonEmptyList<Item>>
148
+ Arr.groupBy((item) => item.category), // Record<string, Arr.NonEmpty<Item>>
144
149
  Rec.map((group) => Arr.head(group)), // cheapest per category — Maybe<Item>
145
150
  );
146
151
  ```
@@ -342,11 +347,12 @@ Functions are composed using `pipe` and `flow`, which are enriched with high-lev
342
347
  helpers like `when`, `unless`, `either`, `safe`, and `async` to support robust, expressive
343
348
  pipelines.
344
349
 
345
- ### Nominal branding, durations, and non-empty lists
350
+ ### Nominal branding, durations, and non-empty collections
346
351
 
347
- Compile-time nominal typing with zero runtime overhead is provided by `Brand`, `Duration` safely
348
- models and converts time durations (seconds, milliseconds, etc.), and `NonEmptyList` guarantees that
349
- a list is never empty, eliminating defensive array length checks.
352
+ Compile-time nominal typing with zero runtime overhead is provided by `Brand`. `Duration` safely
353
+ models and converts time durations (seconds, milliseconds, etc.). `Arr.NonEmpty` and `Rec.NonEmpty`
354
+ guarantee that an array or record is never empty, eliminating defensive length/emptiness checks at
355
+ runtime.
350
356
 
351
357
  Every utility in the library is benchmarked against its native equivalent. The data-last currying
352
358
  adds a small function call overhead, which is the expected cost of composability. For operations
@@ -7,7 +7,7 @@ declare const _deferred: unique symbol;
7
7
  * Two design choices work together to make the guarantee structural rather than documentary:
8
8
  *
9
9
  * - The phantom `[_deferred]` symbol makes the type **nominal**: only values produced by
10
- * `Deferred.fromPromise` satisfy it. A plain object `{ then: ... }` does not.
10
+ * `Deferred.from.Promise` satisfy it. A plain object `{ then: ... }` does not.
11
11
  * - The single-parameter `.then()` **excludes rejection handlers** by construction. There is
12
12
  * no second argument to pass, so chaining and `.catch()` are impossible.
13
13
  *
@@ -16,7 +16,7 @@ declare const _deferred: unique symbol;
16
16
  *
17
17
  * @example
18
18
  * ```ts
19
- * const value = await Deferred.fromPromise(Promise.resolve(42));
19
+ * const value = await Deferred.from.Promise(Promise.resolve(42));
20
20
  * // value === 42
21
21
  * ```
22
22
  */
@@ -25,31 +25,35 @@ type Deferred<A> = {
25
25
  readonly then: (onfulfilled: (value: A) => unknown) => void;
26
26
  };
27
27
  declare namespace Deferred {
28
- /**
29
- * Wraps a `Promise` or `Deferred` into a `Deferred`, structurally excluding rejection handlers,
30
- * `.catch()`, `.finally()`, and chainable `.then()`.
31
- *
32
- * **Precondition**: `p` must never reject. If `p` rejects, the returned `Deferred` will
33
- * never resolve `await`-ing it will hang indefinitely. Use `Task.Result.tryCatch` to
34
- * handle operations that may fail before converting to a `Deferred`.
35
- *
36
- * @example
37
- * ```ts
38
- * const d = Deferred.fromPromise(Promise.resolve("hello"));
39
- * const value = await d; // "hello"
40
- * ```
41
- */
42
- const fromPromise: <A>(p: Thenable<A>) => Deferred<A>;
43
- /**
44
- * Converts a `Deferred` back into a `Promise`.
45
- *
46
- * @example
47
- * ```ts
48
- * const p = Deferred.toPromise(Deferred.fromPromise(Promise.resolve(42)));
49
- * // p is Promise<42>
50
- * ```
51
- */
52
- const toPromise: <A>(d: Deferred<A>) => Promise<A>;
28
+ namespace from {
29
+ /**
30
+ * Wraps a `Promise` or `Deferred` into a `Deferred`, structurally excluding rejection handlers,
31
+ * `.catch()`, `.finally()`, and chainable `.then()`.
32
+ *
33
+ * **Precondition**: `p` must never reject. If `p` rejects, the returned `Deferred` will
34
+ * never resolve `await`-ing it will hang indefinitely. Use `Task.Result.tryCatch` to
35
+ * handle operations that may fail before converting to a `Deferred`.
36
+ *
37
+ * @example
38
+ * ```ts
39
+ * const d = Deferred.from.Promise(Promise.resolve("hello"));
40
+ * const value = await d; // "hello"
41
+ * ```
42
+ */
43
+ const Promise: <A>(p: Thenable<A>) => Deferred<A>;
44
+ }
45
+ namespace to {
46
+ /**
47
+ * Converts a `Deferred` back into a `Promise`.
48
+ *
49
+ * @example
50
+ * ```ts
51
+ * const p = Deferred.to.Promise(Deferred.from.Promise(Promise.resolve(42)));
52
+ * // p is Promise<42>
53
+ * ```
54
+ */
55
+ const Promise: <A>(d: Deferred<A>) => globalThis.Promise<A>;
56
+ }
53
57
  }
54
58
 
55
59
  /**
@@ -114,5 +118,6 @@ type WithCooldown = {
114
118
  type WithMinInterval = {
115
119
  readonly minInterval?: Duration;
116
120
  };
121
+ type NonEmpty<T extends string> = `NonEmpty${T}`;
117
122
 
118
- export { type Awaitable as A, Deferred as D, type NonEmptyArr as N, type RetryOptions as R, type Thenable as T, type WithConcurrency as W, type TimeoutOptions as a, type WithCooldown as b, type WithDuration as c, type WithError as d, type WithErrors as e, type WithFirst as f, type WithKind as g, type WithLog as h, type WithMinInterval as i, type WithN as j, type WithSecond as k, type WithSize as l, type WithTimeout as m, type WithValue as n };
123
+ export { type Awaitable as A, Deferred as D, type NonEmpty as N, type RetryOptions as R, type Thenable as T, type WithConcurrency as W, type NonEmptyArr as a, type TimeoutOptions as b, type WithCooldown as c, type WithDuration as d, type WithError as e, type WithErrors as f, type WithFirst as g, type WithKind as h, type WithLog as i, type WithMinInterval as j, type WithN as k, type WithSecond as l, type WithSize as m, type WithTimeout as n, type WithValue as o };
@@ -7,7 +7,7 @@ declare const _deferred: unique symbol;
7
7
  * Two design choices work together to make the guarantee structural rather than documentary:
8
8
  *
9
9
  * - The phantom `[_deferred]` symbol makes the type **nominal**: only values produced by
10
- * `Deferred.fromPromise` satisfy it. A plain object `{ then: ... }` does not.
10
+ * `Deferred.from.Promise` satisfy it. A plain object `{ then: ... }` does not.
11
11
  * - The single-parameter `.then()` **excludes rejection handlers** by construction. There is
12
12
  * no second argument to pass, so chaining and `.catch()` are impossible.
13
13
  *
@@ -16,7 +16,7 @@ declare const _deferred: unique symbol;
16
16
  *
17
17
  * @example
18
18
  * ```ts
19
- * const value = await Deferred.fromPromise(Promise.resolve(42));
19
+ * const value = await Deferred.from.Promise(Promise.resolve(42));
20
20
  * // value === 42
21
21
  * ```
22
22
  */
@@ -25,31 +25,35 @@ type Deferred<A> = {
25
25
  readonly then: (onfulfilled: (value: A) => unknown) => void;
26
26
  };
27
27
  declare namespace Deferred {
28
- /**
29
- * Wraps a `Promise` or `Deferred` into a `Deferred`, structurally excluding rejection handlers,
30
- * `.catch()`, `.finally()`, and chainable `.then()`.
31
- *
32
- * **Precondition**: `p` must never reject. If `p` rejects, the returned `Deferred` will
33
- * never resolve `await`-ing it will hang indefinitely. Use `Task.Result.tryCatch` to
34
- * handle operations that may fail before converting to a `Deferred`.
35
- *
36
- * @example
37
- * ```ts
38
- * const d = Deferred.fromPromise(Promise.resolve("hello"));
39
- * const value = await d; // "hello"
40
- * ```
41
- */
42
- const fromPromise: <A>(p: Thenable<A>) => Deferred<A>;
43
- /**
44
- * Converts a `Deferred` back into a `Promise`.
45
- *
46
- * @example
47
- * ```ts
48
- * const p = Deferred.toPromise(Deferred.fromPromise(Promise.resolve(42)));
49
- * // p is Promise<42>
50
- * ```
51
- */
52
- const toPromise: <A>(d: Deferred<A>) => Promise<A>;
28
+ namespace from {
29
+ /**
30
+ * Wraps a `Promise` or `Deferred` into a `Deferred`, structurally excluding rejection handlers,
31
+ * `.catch()`, `.finally()`, and chainable `.then()`.
32
+ *
33
+ * **Precondition**: `p` must never reject. If `p` rejects, the returned `Deferred` will
34
+ * never resolve `await`-ing it will hang indefinitely. Use `Task.Result.tryCatch` to
35
+ * handle operations that may fail before converting to a `Deferred`.
36
+ *
37
+ * @example
38
+ * ```ts
39
+ * const d = Deferred.from.Promise(Promise.resolve("hello"));
40
+ * const value = await d; // "hello"
41
+ * ```
42
+ */
43
+ const Promise: <A>(p: Thenable<A>) => Deferred<A>;
44
+ }
45
+ namespace to {
46
+ /**
47
+ * Converts a `Deferred` back into a `Promise`.
48
+ *
49
+ * @example
50
+ * ```ts
51
+ * const p = Deferred.to.Promise(Deferred.from.Promise(Promise.resolve(42)));
52
+ * // p is Promise<42>
53
+ * ```
54
+ */
55
+ const Promise: <A>(d: Deferred<A>) => globalThis.Promise<A>;
56
+ }
53
57
  }
54
58
 
55
59
  /**
@@ -114,5 +118,6 @@ type WithCooldown = {
114
118
  type WithMinInterval = {
115
119
  readonly minInterval?: Duration;
116
120
  };
121
+ type NonEmpty<T extends string> = `NonEmpty${T}`;
117
122
 
118
- export { type Awaitable as A, Deferred as D, type NonEmptyArr as N, type RetryOptions as R, type Thenable as T, type WithConcurrency as W, type TimeoutOptions as a, type WithCooldown as b, type WithDuration as c, type WithError as d, type WithErrors as e, type WithFirst as f, type WithKind as g, type WithLog as h, type WithMinInterval as i, type WithN as j, type WithSecond as k, type WithSize as l, type WithTimeout as m, type WithValue as n };
123
+ export { type Awaitable as A, Deferred as D, type NonEmpty as N, type RetryOptions as R, type Thenable as T, type WithConcurrency as W, type NonEmptyArr as a, type TimeoutOptions as b, type WithCooldown as c, type WithDuration as d, type WithError as e, type WithErrors as f, type WithFirst as g, type WithKind as h, type WithLog as i, type WithMinInterval as j, type WithN as k, type WithSecond as l, type WithSize as m, type WithTimeout as n, type WithValue as o };