@nlozgachev/pipelined 0.30.0 → 0.32.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/core.d.ts CHANGED
@@ -1,7 +1,171 @@
1
- import { M as Maybe, W as WithValue, a as WithLog, D as Deferred, R as Result, b as WithKind, c as WithError, d as RetryOptions, e as TimeoutOptions, f as WithTimeout, g as WithMinInterval, h as WithCooldown, i as WithConcurrency, j as WithSize, k as WithMs, l as WithN, T as Task, m as WithErrors, n as WithFirst, o as WithSecond } from './Task-CnF22Q2o.js';
2
- export { E as Error, N as None, O as Ok, S as Some } from './Task-CnF22Q2o.js';
1
+ import { M as Maybe, W as WithValue, c as WithLog, D as Deferred, R as Result, d as WithKind, e as WithError, f as RetryOptions, g as TimeoutOptions, h as WithTimeout, i as WithMinInterval, j as WithCooldown, k as WithConcurrency, l as WithSize, m as WithMs, n as WithN, T as Task, o as WithErrors, p as WithFirst, q as WithSecond } from './Task-CjYKLeTY.js';
2
+ export { E as Equality, a as Error, N as None, O as Ok, b as Ordering, S as Some } from './Task-CjYKLeTY.js';
3
3
  import { N as NonEmptyList } from './NonEmptyList-BlGFjor5.js';
4
4
 
5
+ /**
6
+ * A type that can combine two values of type `A` into one, with a neutral starting value.
7
+ * `empty` is the identity: `combine(empty)(a) === a` and `combine(a)(empty) === a`.
8
+ * `combine(b)(a)` appends `b` onto `a` — `a` is the accumulated value, `b` is the new element.
9
+ *
10
+ * @example
11
+ * ```ts
12
+ * pipe(["hello", ", ", "world"], Combinable.fold(Combinable.string)); // "hello, world"
13
+ * pipe([1, 2, 3, 4, 5], Combinable.fold(Combinable.sum)); // 15
14
+ * ```
15
+ */
16
+ type Combinable<A> = {
17
+ readonly empty: A;
18
+ readonly combine: (b: A) => (a: A) => A;
19
+ };
20
+ declare namespace Combinable {
21
+ /**
22
+ * Combines strings by concatenation. Empty string is the neutral element.
23
+ *
24
+ * @example
25
+ * ```ts
26
+ * pipe(["a", "b", "c"], Combinable.fold(Combinable.string)); // "abc"
27
+ * ```
28
+ */
29
+ const string: Combinable<string>;
30
+ /**
31
+ * Combines numbers by addition. `0` is the neutral element.
32
+ *
33
+ * @example
34
+ * ```ts
35
+ * pipe([1, 2, 3], Combinable.fold(Combinable.sum)); // 6
36
+ * ```
37
+ */
38
+ const sum: Combinable<number>;
39
+ /**
40
+ * Combines numbers by multiplication. `1` is the neutral element.
41
+ *
42
+ * @example
43
+ * ```ts
44
+ * pipe([2, 3, 4], Combinable.fold(Combinable.product)); // 24
45
+ * ```
46
+ */
47
+ const product: Combinable<number>;
48
+ /**
49
+ * Combines booleans with logical AND. `true` is the neutral element.
50
+ *
51
+ * @example
52
+ * ```ts
53
+ * pipe([true, true, false], Combinable.fold(Combinable.all)); // false
54
+ * ```
55
+ */
56
+ const all: Combinable<boolean>;
57
+ /**
58
+ * Combines booleans with logical OR. `false` is the neutral element.
59
+ *
60
+ * @example
61
+ * ```ts
62
+ * pipe([false, false, true], Combinable.fold(Combinable.any)); // true
63
+ * ```
64
+ */
65
+ const any: Combinable<boolean>;
66
+ /**
67
+ * Combines arrays by concatenation. Empty array is the neutral element.
68
+ *
69
+ * @example
70
+ * ```ts
71
+ * pipe([[1, 2], [3], [4, 5]], Combinable.fold(Combinable.array<number>())); // [1, 2, 3, 4, 5]
72
+ * ```
73
+ */
74
+ const array: <A>() => Combinable<readonly A[]>;
75
+ /**
76
+ * Lifts a `Combinable<A>` to `Combinable<Maybe<A>>`. `None` is the neutral element —
77
+ * combining with `None` on either side returns the other value unchanged.
78
+ * Two `Some` values combine their inner values using the inner `Combinable`.
79
+ *
80
+ * @example
81
+ * ```ts
82
+ * const c = Combinable.maybe(Combinable.sum);
83
+ * c.combine(Maybe.some(3))(Maybe.some(2)); // Some(5)
84
+ * c.combine(Maybe.none())(Maybe.some(5)); // Some(5)
85
+ * ```
86
+ */
87
+ const maybe: <A>(inner: Combinable<A>) => Combinable<Maybe<A>>;
88
+ /**
89
+ * Folds an array into a single value using the `Combinable`'s `empty` as the starting point.
90
+ *
91
+ * @example
92
+ * ```ts
93
+ * pipe([1, 2, 3, 4, 5], Combinable.fold(Combinable.sum)); // 15
94
+ * pipe([], Combinable.fold(Combinable.sum)); // 0
95
+ * ```
96
+ */
97
+ const fold: <A>(c: Combinable<A>) => (data: readonly A[]) => A;
98
+ }
99
+
100
+ /**
101
+ * A synchronous memoized computation. The factory function runs exactly once —
102
+ * on the first call to `Lazy.evaluate` — and the result is cached for all subsequent calls.
103
+ *
104
+ * @example
105
+ * ```ts
106
+ * const config = Lazy.from(() => parseConfig(rawInput));
107
+ *
108
+ * pipe(
109
+ * config,
110
+ * Lazy.map(cfg => cfg.port),
111
+ * Lazy.evaluate,
112
+ * ); // parseConfig ran once; cfg.port returned
113
+ * ```
114
+ */
115
+ type Lazy<A> = {
116
+ readonly get: () => A;
117
+ };
118
+ declare namespace Lazy {
119
+ /**
120
+ * Wraps a thunk in a `Lazy`. The thunk runs exactly once, on first `evaluate`.
121
+ *
122
+ * @example
123
+ * ```ts
124
+ * const expensive = Lazy.from(() => computeExpensiveValue(input));
125
+ * ```
126
+ */
127
+ const from: <A>(f: () => A) => Lazy<A>;
128
+ /**
129
+ * Forces evaluation and returns the cached result. Safe to call multiple times.
130
+ *
131
+ * @example
132
+ * ```ts
133
+ * const value = Lazy.evaluate(Lazy.from(() => 42)); // 42
134
+ * ```
135
+ */
136
+ const evaluate: <A>(lazy: Lazy<A>) => A;
137
+ /**
138
+ * Transforms the result of a `Lazy` without triggering evaluation.
139
+ *
140
+ * @example
141
+ * ```ts
142
+ * pipe(Lazy.from(() => loadConfig()), Lazy.map(cfg => cfg.port));
143
+ * ```
144
+ */
145
+ const map: <A, B>(f: (a: A) => B) => (lazy: Lazy<A>) => Lazy<B>;
146
+ /**
147
+ * Chains a `Lazy`-returning transformation without triggering evaluation.
148
+ *
149
+ * @example
150
+ * ```ts
151
+ * pipe(
152
+ * Lazy.from(() => loadConfig()),
153
+ * Lazy.chain(cfg => Lazy.from(() => openConnection(cfg.dbUrl))),
154
+ * );
155
+ * ```
156
+ */
157
+ const chain: <A, B>(f: (a: A) => Lazy<B>) => (lazy: Lazy<A>) => Lazy<B>;
158
+ /**
159
+ * Runs a side effect on the value without changing it. Fires once, on first `evaluate`.
160
+ *
161
+ * @example
162
+ * ```ts
163
+ * pipe(Lazy.from(() => compute()), Lazy.tap(v => console.log("computed:", v)));
164
+ * ```
165
+ */
166
+ const tap: <A>(f: (a: A) => void) => (lazy: Lazy<A>) => Lazy<A>;
167
+ }
168
+
5
169
  /** Keys of T for which undefined is assignable (i.e. optional fields). */
6
170
  type OptionalKeys<T> = {
7
171
  [K in keyof T]-?: undefined extends T[K] ? K : never;
@@ -1053,21 +1217,6 @@ declare namespace Op {
1053
1217
  * ```
1054
1218
  */
1055
1219
  const wire: <I, E, A, S extends State<E, A>>(source: Manager<I, E, A, S>, f: (a: A) => void) => () => void;
1056
- /**
1057
- * Wires multiple source-handler pairs, returning a combined cleanup function.
1058
- * When any source reaches `OpOk`, its corresponding handler is called.
1059
- *
1060
- * @example
1061
- * ```ts
1062
- * const stop = Op.wireAll(
1063
- * [userManager, (u) => render(u)],
1064
- * [settingsManager, (s) => applySettings(s)],
1065
- * );
1066
- * // ... later
1067
- * stop(); // removes all subscriptions
1068
- * ```
1069
- */
1070
- const wireAll: <I, E, A, S extends State<E, A>>(...pairs: Array<[Manager<I, E, A, S>, (a: A) => void]>) => () => void;
1071
1220
  /**
1072
1221
  * Attaches a concurrency strategy to an `Op`, returning a `Manager`.
1073
1222
  *
@@ -1903,6 +2052,11 @@ declare namespace TaskResult {
1903
2052
  * ```
1904
2053
  */
1905
2054
  const tapError: <E, A>(f: (e: E) => void) => (data: TaskResult<E, A>) => TaskResult<E, A>;
2055
+ /**
2056
+ * Applies a function wrapped in a TaskResult to a value wrapped in a TaskResult.
2057
+ * Both Tasks run in parallel.
2058
+ */
2059
+ const ap: <E, A>(arg: TaskResult<E, A>) => <B>(data: TaskResult<E, (a: A) => B>) => TaskResult<E, B>;
1906
2060
  /**
1907
2061
  * Executes a `TaskResult` with an optional signal, returning `Promise<Result<E, A>>`.
1908
2062
  * Use as a terminal step in a `pipe` chain.
@@ -2245,15 +2399,16 @@ declare namespace TaskMaybe {
2245
2399
  /**
2246
2400
  * Creates a TaskMaybe from a Promise-returning function.
2247
2401
  * Returns Some if the promise resolves, None if it rejects.
2402
+ * The factory optionally receives an `AbortSignal` forwarded from the call site.
2248
2403
  *
2249
2404
  * @example
2250
2405
  * ```ts
2251
- * const fetchUser = TaskMaybe.tryCatch(() =>
2252
- * fetch("/user/1").then(r => r.json())
2406
+ * const fetchUser = TaskMaybe.tryCatch((signal) =>
2407
+ * fetch("/user/1", { signal }).then(r => r.json())
2253
2408
  * );
2254
2409
  * ```
2255
2410
  */
2256
- const tryCatch: <A>(f: () => Promise<A>) => TaskMaybe<A>;
2411
+ const tryCatch: <A>(f: (signal?: AbortSignal) => Promise<A>) => TaskMaybe<A>;
2257
2412
  /**
2258
2413
  * Transforms the value inside a TaskMaybe.
2259
2414
  */
@@ -2642,17 +2797,18 @@ declare namespace TaskValidation {
2642
2797
  /**
2643
2798
  * Creates a TaskValidation from a Promise-returning function.
2644
2799
  * Catches any errors and transforms them using the onError function.
2800
+ * The factory optionally receives an `AbortSignal` forwarded from the call site.
2645
2801
  *
2646
2802
  * @example
2647
2803
  * ```ts
2648
2804
  * const fetchUser = (id: string): TaskValidation<string, User> =>
2649
2805
  * TaskValidation.tryCatch(
2650
- * () => fetch(`/users/${id}`).then(r => r.json()),
2806
+ * (signal) => fetch(`/users/${id}`, { signal }).then(r => r.json()),
2651
2807
  * e => `Failed to fetch user: ${e}`
2652
2808
  * );
2653
2809
  * ```
2654
2810
  */
2655
- const tryCatch: <E, A>(f: () => Promise<A>, onError: (e: unknown) => E) => TaskValidation<E, A>;
2811
+ const tryCatch: <E, A>(f: (signal?: AbortSignal) => Promise<A>, onError: (e: unknown) => E) => TaskValidation<E, A>;
2656
2812
  /**
2657
2813
  * Transforms the success value inside a TaskValidation.
2658
2814
  */
@@ -3094,4 +3250,4 @@ declare namespace Tuple {
3094
3250
  const tap: <A, B>(f: (a: A, b: B) => void) => (tuple: Tuple<A, B>) => Tuple<A, B>;
3095
3251
  }
3096
3252
 
3097
- export { Deferred, type Failure, type Invalid, Lens, type Loading, Logged, Maybe, type NotAsked, Op, Optional, Predicate, Reader, Refinement, RemoteData, Resource, Result, State, type Success, Task, TaskMaybe, TaskResult, TaskValidation, These, type TheseBoth, type TheseFirst, type TheseSecond, Tuple, type Valid, Validation };
3253
+ export { Combinable, Deferred, type Failure, type Invalid, Lazy, Lens, type Loading, Logged, Maybe, type NotAsked, Op, Optional, Predicate, Reader, Refinement, RemoteData, Resource, Result, State, type Success, Task, TaskMaybe, TaskResult, TaskValidation, These, type TheseBoth, type TheseFirst, type TheseSecond, Tuple, type Valid, Validation };