@nlozgachev/pipelined 0.61.0 → 0.63.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 +13 -16
- package/dist/{Duration-B8joKzro.d.cts → Duration-DeyxG6VQ.d.cts} +20 -20
- package/dist/{Duration-B8joKzro.d.ts → Duration-DeyxG6VQ.d.ts} +20 -20
- package/dist/{InternalTypes-LdhLQx3N.d.ts → InternalTypes-CCXa8Kvr.d.ts} +11 -11
- package/dist/{InternalTypes-DuK_XpTi.d.cts → InternalTypes-GFn4RTwD.d.cts} +11 -11
- package/dist/{Validation-DZLizBZ0.d.ts → Validation-C5RGZUXy.d.ts} +384 -280
- package/dist/{Validation-DC3uUizM.d.cts → Validation-KFUpea_k.d.cts} +384 -280
- package/dist/composition.cjs +216 -95
- package/dist/composition.d.cts +8 -76
- package/dist/composition.d.ts +8 -76
- package/dist/composition.mjs +216 -95
- package/dist/core.cjs +4784 -996
- package/dist/core.d.cts +269 -769
- package/dist/core.d.ts +269 -769
- package/dist/core.mjs +4784 -996
- package/dist/data.cjs +2916 -1240
- package/dist/data.d.cts +479 -1967
- package/dist/data.d.ts +479 -1967
- package/dist/data.mjs +2916 -1240
- package/dist/index.cjs +6739 -2169
- package/dist/index.d.cts +3 -3
- package/dist/index.d.ts +3 -3
- package/dist/index.mjs +6718 -2148
- package/dist/types.cjs +175 -31
- package/dist/types.d.cts +6 -6
- package/dist/types.d.ts +6 -6
- package/dist/types.mjs +175 -31
- package/package.json +24 -13
package/dist/core.d.cts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { M as Maybe, R as Result, T as Task } from './Validation-
|
|
2
|
-
export { E as Equality, a as Err, F as Failed, N as None, O as Ok, b as Ordering, P as Passed, S as Some, V as Validation } from './Validation-
|
|
3
|
-
import { o as WithValue, i as WithLog, D as Deferred,
|
|
4
|
-
import { D as Duration } from './Duration-
|
|
1
|
+
import { M as Maybe, R as Result, T as Task } from './Validation-KFUpea_k.cjs';
|
|
2
|
+
export { E as Equality, a as Err, F as Failed, N as None, O as Ok, b as Ordering, P as Passed, S as Some, V as Validation } from './Validation-KFUpea_k.cjs';
|
|
3
|
+
import { o as WithValue, i as WithLog, D as Deferred, R as RetryOptions, n as WithTimeout, j as WithMinInterval, c as WithCooldown, W as WithConcurrency, m as WithSize, d as WithDuration, k as WithN, h as WithKind, e as WithError, b as TimeoutOptions, g as WithFirst, l as WithSecond } from './InternalTypes-GFn4RTwD.cjs';
|
|
4
|
+
import { D as Duration } from './Duration-DeyxG6VQ.cjs';
|
|
5
5
|
import './types.cjs';
|
|
6
6
|
|
|
7
7
|
/**
|
|
@@ -19,7 +19,7 @@ type Combinable<A> = {
|
|
|
19
19
|
readonly empty: A;
|
|
20
20
|
readonly combine: (b: A) => (a: A) => A;
|
|
21
21
|
};
|
|
22
|
-
declare
|
|
22
|
+
declare const Combinable: {
|
|
23
23
|
/**
|
|
24
24
|
* Combines strings by concatenation. Empty string is the neutral element.
|
|
25
25
|
*
|
|
@@ -28,7 +28,7 @@ declare namespace Combinable {
|
|
|
28
28
|
* pipe(["a", "b", "c"], Combinable.fold(Combinable.string)); // "abc"
|
|
29
29
|
* ```
|
|
30
30
|
*/
|
|
31
|
-
|
|
31
|
+
string: Combinable<string>;
|
|
32
32
|
/**
|
|
33
33
|
* Combines numbers by addition. `0` is the neutral element.
|
|
34
34
|
*
|
|
@@ -37,7 +37,7 @@ declare namespace Combinable {
|
|
|
37
37
|
* pipe([1, 2, 3], Combinable.fold(Combinable.sum)); // 6
|
|
38
38
|
* ```
|
|
39
39
|
*/
|
|
40
|
-
|
|
40
|
+
sum: Combinable<number>;
|
|
41
41
|
/**
|
|
42
42
|
* Combines numbers by multiplication. `1` is the neutral element.
|
|
43
43
|
*
|
|
@@ -46,7 +46,7 @@ declare namespace Combinable {
|
|
|
46
46
|
* pipe([2, 3, 4], Combinable.fold(Combinable.product)); // 24
|
|
47
47
|
* ```
|
|
48
48
|
*/
|
|
49
|
-
|
|
49
|
+
product: Combinable<number>;
|
|
50
50
|
/**
|
|
51
51
|
* Combines booleans with logical AND. `true` is the neutral element.
|
|
52
52
|
*
|
|
@@ -55,7 +55,7 @@ declare namespace Combinable {
|
|
|
55
55
|
* pipe([true, true, false], Combinable.fold(Combinable.all)); // false
|
|
56
56
|
* ```
|
|
57
57
|
*/
|
|
58
|
-
|
|
58
|
+
all: Combinable<boolean>;
|
|
59
59
|
/**
|
|
60
60
|
* Combines booleans with logical OR. `false` is the neutral element.
|
|
61
61
|
*
|
|
@@ -64,7 +64,7 @@ declare namespace Combinable {
|
|
|
64
64
|
* pipe([false, false, true], Combinable.fold(Combinable.any)); // true
|
|
65
65
|
* ```
|
|
66
66
|
*/
|
|
67
|
-
|
|
67
|
+
any: Combinable<boolean>;
|
|
68
68
|
/**
|
|
69
69
|
* Combines arrays by concatenation. Empty array is the neutral element.
|
|
70
70
|
*
|
|
@@ -73,7 +73,7 @@ declare namespace Combinable {
|
|
|
73
73
|
* pipe([[1, 2], [3], [4, 5]], Combinable.fold(Combinable.array<number>())); // [1, 2, 3, 4, 5]
|
|
74
74
|
* ```
|
|
75
75
|
*/
|
|
76
|
-
|
|
76
|
+
array: <A>() => Combinable<readonly A[]>;
|
|
77
77
|
/**
|
|
78
78
|
* Lifts a `Combinable<A>` to `Combinable<Maybe<A>>`. `None` is the neutral element —
|
|
79
79
|
* combining with `None` on either side returns the other value unchanged.
|
|
@@ -86,7 +86,7 @@ declare namespace Combinable {
|
|
|
86
86
|
* c.combine(Maybe.make.none())(Maybe.make.some(5)); // Some(5)
|
|
87
87
|
* ```
|
|
88
88
|
*/
|
|
89
|
-
|
|
89
|
+
maybe: <A>(inner: Combinable<A>) => Combinable<Maybe<A>>;
|
|
90
90
|
/**
|
|
91
91
|
* Folds an array into a single value using the `Combinable`'s `empty` as the starting point.
|
|
92
92
|
*
|
|
@@ -96,7 +96,7 @@ declare namespace Combinable {
|
|
|
96
96
|
* pipe([], Combinable.fold(Combinable.sum)); // 0
|
|
97
97
|
* ```
|
|
98
98
|
*/
|
|
99
|
-
|
|
99
|
+
fold: <A>(c: Combinable<A>) => (data: readonly A[]) => A;
|
|
100
100
|
/**
|
|
101
101
|
* Derives a `Combinable` for a record of fields from field-level `Combinable` instances.
|
|
102
102
|
*
|
|
@@ -108,8 +108,8 @@ declare namespace Combinable {
|
|
|
108
108
|
* });
|
|
109
109
|
* ```
|
|
110
110
|
*/
|
|
111
|
-
|
|
112
|
-
}
|
|
111
|
+
struct: <R extends Record<string, unknown>>(fields: { [K in keyof R]: Combinable<R[K]>; }) => Combinable<R>;
|
|
112
|
+
};
|
|
113
113
|
|
|
114
114
|
/**
|
|
115
115
|
* A synchronous memoized computation. The factory function runs exactly once —
|
|
@@ -129,7 +129,7 @@ declare namespace Combinable {
|
|
|
129
129
|
type Lazy<A> = {
|
|
130
130
|
readonly get: () => A;
|
|
131
131
|
};
|
|
132
|
-
declare
|
|
132
|
+
declare const Lazy: {
|
|
133
133
|
/**
|
|
134
134
|
* Wraps a thunk in a `Lazy`. The thunk runs exactly once, on first `evaluate`.
|
|
135
135
|
*
|
|
@@ -138,7 +138,7 @@ declare namespace Lazy {
|
|
|
138
138
|
* const expensive = Lazy.from(() => computeExpensiveValue(input));
|
|
139
139
|
* ```
|
|
140
140
|
*/
|
|
141
|
-
|
|
141
|
+
from: <A>(f: () => A) => Lazy<A>;
|
|
142
142
|
/**
|
|
143
143
|
* Forces evaluation and returns the cached result. Safe to call multiple times.
|
|
144
144
|
*
|
|
@@ -147,7 +147,7 @@ declare namespace Lazy {
|
|
|
147
147
|
* const value = Lazy.evaluate(Lazy.from(() => 42)); // 42
|
|
148
148
|
* ```
|
|
149
149
|
*/
|
|
150
|
-
|
|
150
|
+
evaluate: <A>(lazy: Lazy<A>) => A;
|
|
151
151
|
/**
|
|
152
152
|
* Transforms the result of a `Lazy` without triggering evaluation.
|
|
153
153
|
*
|
|
@@ -156,7 +156,7 @@ declare namespace Lazy {
|
|
|
156
156
|
* pipe(Lazy.from(() => loadConfig()), Lazy.map(cfg => cfg.port));
|
|
157
157
|
* ```
|
|
158
158
|
*/
|
|
159
|
-
|
|
159
|
+
map: <A, B>(f: (a: A) => B) => (lazy: Lazy<A>) => Lazy<B>;
|
|
160
160
|
/**
|
|
161
161
|
* Chains a `Lazy`-returning transformation without triggering evaluation.
|
|
162
162
|
*
|
|
@@ -168,7 +168,7 @@ declare namespace Lazy {
|
|
|
168
168
|
* );
|
|
169
169
|
* ```
|
|
170
170
|
*/
|
|
171
|
-
|
|
171
|
+
chain: <A, B>(f: (a: A) => Lazy<B>) => (lazy: Lazy<A>) => Lazy<B>;
|
|
172
172
|
/**
|
|
173
173
|
* Runs a side effect on the value without changing it. Fires once, on first `evaluate`.
|
|
174
174
|
*
|
|
@@ -177,8 +177,8 @@ declare namespace Lazy {
|
|
|
177
177
|
* pipe(Lazy.from(() => compute()), Lazy.tap(v => console.log("computed:", v)));
|
|
178
178
|
* ```
|
|
179
179
|
*/
|
|
180
|
-
|
|
181
|
-
}
|
|
180
|
+
tap: <A>(f: (a: A) => void) => (lazy: Lazy<A>) => Lazy<A>;
|
|
181
|
+
};
|
|
182
182
|
|
|
183
183
|
/**
|
|
184
184
|
* Lens<S, A> focuses on a single value A inside a structure S, providing
|
|
@@ -205,8 +205,8 @@ type Lens<S, A> = {
|
|
|
205
205
|
readonly get: (s: S) => A;
|
|
206
206
|
readonly set: (a: A) => (s: S) => S;
|
|
207
207
|
};
|
|
208
|
-
declare
|
|
209
|
-
|
|
208
|
+
declare const Lens: {
|
|
209
|
+
from: {
|
|
210
210
|
/**
|
|
211
211
|
* Constructs a Lens from a getter and a setter.
|
|
212
212
|
*
|
|
@@ -218,7 +218,7 @@ declare namespace Lens {
|
|
|
218
218
|
* );
|
|
219
219
|
* ```
|
|
220
220
|
*/
|
|
221
|
-
|
|
221
|
+
accessors: <S, A>(get: (s: S) => A, set: (a: A) => (s: S) => S) => Lens<S, A>;
|
|
222
222
|
/**
|
|
223
223
|
* Creates a Lens that focuses on a property of an object.
|
|
224
224
|
* Call with the structure type first, then the key.
|
|
@@ -228,8 +228,8 @@ declare namespace Lens {
|
|
|
228
228
|
* const nameLens = Lens.from.property<User>()("name");
|
|
229
229
|
* ```
|
|
230
230
|
*/
|
|
231
|
-
|
|
232
|
-
}
|
|
231
|
+
property: <S>() => <K extends keyof S>(key: K) => Lens<S, S[K]>;
|
|
232
|
+
};
|
|
233
233
|
/**
|
|
234
234
|
* Reads the focused value from a structure.
|
|
235
235
|
*
|
|
@@ -238,7 +238,7 @@ declare namespace Lens {
|
|
|
238
238
|
* pipe(user, Lens.get(nameLens)); // "Alice"
|
|
239
239
|
* ```
|
|
240
240
|
*/
|
|
241
|
-
|
|
241
|
+
get: <S, A>(lens: Lens<S, A>) => (s: S) => A;
|
|
242
242
|
/**
|
|
243
243
|
* Replaces the focused value within a structure, returning a new structure.
|
|
244
244
|
*
|
|
@@ -247,7 +247,7 @@ declare namespace Lens {
|
|
|
247
247
|
* pipe(user, Lens.set(nameLens)("Bob")); // new User with name "Bob"
|
|
248
248
|
* ```
|
|
249
249
|
*/
|
|
250
|
-
|
|
250
|
+
set: <S, A>(lens: Lens<S, A>) => (a: A) => (s: S) => S;
|
|
251
251
|
/**
|
|
252
252
|
* Applies a function to the focused value, returning a new structure.
|
|
253
253
|
*
|
|
@@ -256,7 +256,7 @@ declare namespace Lens {
|
|
|
256
256
|
* pipe(user, Lens.modify(nameLens)(n => n.toUpperCase())); // "ALICE"
|
|
257
257
|
* ```
|
|
258
258
|
*/
|
|
259
|
-
|
|
259
|
+
modify: <S, A>(lens: Lens<S, A>) => (f: (a: A) => A) => (s: S) => S;
|
|
260
260
|
/**
|
|
261
261
|
* Composes two Lenses: focuses through the outer, then through the inner.
|
|
262
262
|
* Use in a pipe chain to build up a deep focus step by step.
|
|
@@ -269,7 +269,7 @@ declare namespace Lens {
|
|
|
269
269
|
* );
|
|
270
270
|
* ```
|
|
271
271
|
*/
|
|
272
|
-
|
|
272
|
+
andThen: <A, B>(inner: Lens<A, B>) => <S>(outer: Lens<S, A>) => Lens<S, B>;
|
|
273
273
|
/**
|
|
274
274
|
* Composes a Lens with an Optional, producing an Optional.
|
|
275
275
|
* Use when the next step in the focus is optional (may be absent).
|
|
@@ -282,7 +282,7 @@ declare namespace Lens {
|
|
|
282
282
|
* );
|
|
283
283
|
* ```
|
|
284
284
|
*/
|
|
285
|
-
|
|
285
|
+
andThenOptional: <A, B>(inner: Optional<A, B>) => <S>(outer: Lens<S, A>) => Optional<S, B>;
|
|
286
286
|
/**
|
|
287
287
|
* Converts a Lens to an Optional. Every Lens is a valid Optional
|
|
288
288
|
* whose get always returns Some.
|
|
@@ -296,8 +296,8 @@ declare namespace Lens {
|
|
|
296
296
|
* );
|
|
297
297
|
* ```
|
|
298
298
|
*/
|
|
299
|
-
|
|
300
|
-
}
|
|
299
|
+
toOptional: <S, A>(lens: Lens<S, A>) => Optional<S, A>;
|
|
300
|
+
};
|
|
301
301
|
|
|
302
302
|
/**
|
|
303
303
|
* A value paired with an accumulated log.
|
|
@@ -325,8 +325,8 @@ declare namespace Lens {
|
|
|
325
325
|
* ```
|
|
326
326
|
*/
|
|
327
327
|
type Logged<L, A> = WithValue<A> & WithLog<L>;
|
|
328
|
-
declare
|
|
329
|
-
|
|
328
|
+
declare const Logged: {
|
|
329
|
+
from: {
|
|
330
330
|
/**
|
|
331
331
|
* Wraps a pure value into a `Logged` with an empty log.
|
|
332
332
|
*
|
|
@@ -335,7 +335,7 @@ declare namespace Logged {
|
|
|
335
335
|
* Logged.from.value<string, number>(42); // { value: 42, log: [] }
|
|
336
336
|
* ```
|
|
337
337
|
*/
|
|
338
|
-
|
|
338
|
+
value: <W, A>(val: A) => Logged<W, A>;
|
|
339
339
|
/**
|
|
340
340
|
* Creates a `Logged` that records a single log entry and produces no
|
|
341
341
|
* meaningful value. Use this to append to the log inside a `chain`.
|
|
@@ -345,8 +345,8 @@ declare namespace Logged {
|
|
|
345
345
|
* Logged.from.entry("operation completed"); // { value: undefined, log: ["operation completed"] }
|
|
346
346
|
* ```
|
|
347
347
|
*/
|
|
348
|
-
|
|
349
|
-
}
|
|
348
|
+
entry: <W>(logEntry: W) => Logged<W, undefined>;
|
|
349
|
+
};
|
|
350
350
|
/**
|
|
351
351
|
* Transforms the value inside a `Logged` without affecting the log.
|
|
352
352
|
*
|
|
@@ -358,7 +358,7 @@ declare namespace Logged {
|
|
|
358
358
|
* ); // { value: 10, log: [] }
|
|
359
359
|
* ```
|
|
360
360
|
*/
|
|
361
|
-
|
|
361
|
+
map: <W, A, B>(f: (a: A) => B) => (data: Logged<W, A>) => Logged<W, B>;
|
|
362
362
|
/**
|
|
363
363
|
* Sequences two `Logged` computations, concatenating their logs.
|
|
364
364
|
* The value from the first is passed to `f`; the resulting log entries are
|
|
@@ -377,7 +377,7 @@ declare namespace Logged {
|
|
|
377
377
|
* Logged.run(result); // [20, ["step", "done"]]
|
|
378
378
|
* ```
|
|
379
379
|
*/
|
|
380
|
-
|
|
380
|
+
chain: <W, A, B>(f: (a: A) => Logged<W, B>) => (data: Logged<W, A>) => Logged<W, B>;
|
|
381
381
|
/**
|
|
382
382
|
* Applies a function wrapped in a `Logged` to a value wrapped in a `Logged`,
|
|
383
383
|
* concatenating both logs.
|
|
@@ -394,7 +394,7 @@ declare namespace Logged {
|
|
|
394
394
|
* Logged.run(result); // [10, ["fn-loaded", "arg-loaded"]]
|
|
395
395
|
* ```
|
|
396
396
|
*/
|
|
397
|
-
|
|
397
|
+
ap: <W, A>(arg: Logged<W, A>) => <B>(data: Logged<W, (a: A) => B>) => Logged<W, B>;
|
|
398
398
|
/**
|
|
399
399
|
* Runs a side effect on the value without changing the `Logged`.
|
|
400
400
|
* Useful for debugging or inspecting intermediate values.
|
|
@@ -407,7 +407,7 @@ declare namespace Logged {
|
|
|
407
407
|
* );
|
|
408
408
|
* ```
|
|
409
409
|
*/
|
|
410
|
-
|
|
410
|
+
tap: <W, A>(f: (a: A) => void) => (data: Logged<W, A>) => Logged<W, A>;
|
|
411
411
|
/**
|
|
412
412
|
* Extracts the value and log as a `readonly [A, ReadonlyArray<W>]` tuple.
|
|
413
413
|
* Use this at the boundary where you need to consume both.
|
|
@@ -423,7 +423,7 @@ declare namespace Logged {
|
|
|
423
423
|
* // value = 2, log = ["incremented"]
|
|
424
424
|
* ```
|
|
425
425
|
*/
|
|
426
|
-
|
|
426
|
+
run: <W, A>(data: Logged<W, A>) => readonly [A, ReadonlyArray<W>];
|
|
427
427
|
/**
|
|
428
428
|
* Lifts a Logged value into an accumulator object.
|
|
429
429
|
*
|
|
@@ -432,7 +432,7 @@ declare namespace Logged {
|
|
|
432
432
|
* pipe(Logged.from.value<string, number>(42), Logged.bindTo("value")); // Logged({ value: 42 })
|
|
433
433
|
* ```
|
|
434
434
|
*/
|
|
435
|
-
|
|
435
|
+
bindTo: <K extends string>(key: K) => <W, A>(data: Logged<W, A>) => Logged<W, { [P in K]: A; }>;
|
|
436
436
|
/**
|
|
437
437
|
* Evaluates a new Logged using the current accumulator and attaches the output to a new key.
|
|
438
438
|
*
|
|
@@ -444,7 +444,7 @@ declare namespace Logged {
|
|
|
444
444
|
* ); // Logged({ value: { a: 1, b: 2 } })
|
|
445
445
|
* ```
|
|
446
446
|
*/
|
|
447
|
-
|
|
447
|
+
bind: <K extends string, W, A, B>(key: K, f: (a: A) => Logged<W, B>) => (data: Logged<W, A>) => Logged<W, A & { [P in K]: B; }>;
|
|
448
448
|
/**
|
|
449
449
|
* Focuses a Logged computation's value transformation using a Lens.
|
|
450
450
|
*
|
|
@@ -455,8 +455,8 @@ declare namespace Logged {
|
|
|
455
455
|
* pipe(logged, Logged.focus(nameLens)(s => s.toUpperCase()));
|
|
456
456
|
* ```
|
|
457
457
|
*/
|
|
458
|
-
|
|
459
|
-
}
|
|
458
|
+
focus: <S, A>(lens: Lens<S, A>) => <W>(f: (a: A) => A) => (data: Logged<W, S>) => Logged<W, S>;
|
|
459
|
+
};
|
|
460
460
|
|
|
461
461
|
type MaybeRetry<E, O> = O extends {
|
|
462
462
|
retry: RetryOptions<E>;
|
|
@@ -541,6 +541,7 @@ type InterpretResult<I, E, A, O> = [O] extends [{
|
|
|
541
541
|
}] ? Op.Manager<I, E, A, Op.QueueState<E, A> | MaybeRetry<E, O>> : [O] extends [{
|
|
542
542
|
strategy: "buffered";
|
|
543
543
|
}] ? Op.Manager<I, E, A, Op.BufferedState<E, A> | MaybeRetry<E, O>> : never;
|
|
544
|
+
declare function interpretFn<I, E, A, O extends AllInterpretOptions<I, E>>(op: Op<I, E, A>, options: O): InterpretResult<I, E, A, O>;
|
|
544
545
|
/**
|
|
545
546
|
* A reusable description of async work — decoupled from execution strategy and lifetime.
|
|
546
547
|
*
|
|
@@ -579,595 +580,121 @@ type Op<I, E, A> = {
|
|
|
579
580
|
*/
|
|
580
581
|
readonly _factory: (input: I, signal: AbortSignal) => Deferred<Result<E, A> | null>;
|
|
581
582
|
};
|
|
583
|
+
declare const Op: {
|
|
584
|
+
nil: (reason: Op.NilReason) => Op.Nil;
|
|
585
|
+
create: <E, A, I = void>(factory: (signal: AbortSignal) => (input: I) => Promise<A>, onError: (e: unknown) => E) => Op<I, E, A>;
|
|
586
|
+
lift: <I, A>(f: (input: I, signal: AbortSignal) => Promise<A>) => Op<I, unknown, A>;
|
|
587
|
+
ok: <A>(value: A) => Op.Ok<A>;
|
|
588
|
+
err: <E>(error: E) => Op.Err<E>;
|
|
589
|
+
isIdle: <E, A>(state: Op.State<E, A>) => state is Op.Idle;
|
|
590
|
+
isPending: <E, A>(state: Op.State<E, A>) => state is Op.Pending;
|
|
591
|
+
isQueued: <E, A>(state: Op.State<E, A>) => state is Op.Queued;
|
|
592
|
+
isRetrying: <E, A>(state: Op.State<E, A>) => state is Op.Retrying<E>;
|
|
593
|
+
isOk: <E, A>(state: Op.State<E, A>) => state is Op.Ok<A>;
|
|
594
|
+
isErr: <E, A>(state: Op.State<E, A>) => state is Op.Err<E>;
|
|
595
|
+
isNil: <E, A>(state: Op.State<E, A>) => state is Op.Nil;
|
|
596
|
+
match: <E, A, B>(cases: {
|
|
597
|
+
ok: (a: A) => B;
|
|
598
|
+
err: (e: E) => B;
|
|
599
|
+
nil: () => B;
|
|
600
|
+
}) => (outcome: Op.Outcome<E, A>) => B;
|
|
601
|
+
fold: <E, A, B>(onErr: (e: E) => B, onNil: () => B, onOk: (a: A) => B) => (outcome: Op.Outcome<E, A>) => B;
|
|
602
|
+
getOrElse: <E, A, B>(defaultValue: () => B) => (outcome: Op.Outcome<E, A>) => A | B;
|
|
603
|
+
map: <E, A, B>(f: (a: A) => B) => (outcome: Op.Outcome<E, A>) => Op.Outcome<E, B>;
|
|
604
|
+
mapError: <E, F, A>(f: (e: E) => F) => (outcome: Op.Outcome<E, A>) => Op.Outcome<F, A>;
|
|
605
|
+
chain: <E, A, B>(f: (a: A) => Op.Outcome<E, B>) => (outcome: Op.Outcome<E, A>) => Op.Outcome<E, B>;
|
|
606
|
+
tap: <E, A>(f: (a: A) => void) => (outcome: Op.Outcome<E, A>) => Op.Outcome<E, A>;
|
|
607
|
+
recover: <E, A, B>(f: (e: E) => Op.Outcome<E, B>) => (outcome: Op.Outcome<E, A>) => Op.Outcome<E, A | B>;
|
|
608
|
+
to: {
|
|
609
|
+
Result: <E, A>(onNil: () => E) => (outcome: Op.Outcome<E, A>) => Result<E, A>;
|
|
610
|
+
Maybe: <E, A>(outcome: Op.Outcome<E, A>) => Maybe<A>;
|
|
611
|
+
};
|
|
612
|
+
all: <E, A>(invocations: ReadonlyArray<Deferred<Op.Outcome<E, A>>>) => Deferred<ReadonlyArray<Op.Outcome<E, A>>>;
|
|
613
|
+
race: <E, A>(invocations: ReadonlyArray<Deferred<Op.Outcome<E, A>>>) => Deferred<Op.Outcome<E, A>>;
|
|
614
|
+
wire: <I, E, A, S extends Op.State<E, A>>(source: Op.Manager<I, E, A, S>, f: (a: A) => void) => () => void;
|
|
615
|
+
interpret: typeof interpretFn;
|
|
616
|
+
};
|
|
582
617
|
declare namespace Op {
|
|
583
|
-
/**
|
|
584
|
-
* The three terminal states of a completed async operation.
|
|
585
|
-
*
|
|
586
|
-
* - `Ok` — produced a value.
|
|
587
|
-
* - `Err` — produced a typed error.
|
|
588
|
-
* - `Nil` — completed without a value or error. The `reason` field says why:
|
|
589
|
-
* `"aborted"` — `abort()` was called; `"dropped"` — a new `run()` was ignored
|
|
590
|
-
* because the strategy was already busy; `"replaced"` — a newer `run()` took
|
|
591
|
-
* over a call that was already running; `"evicted"` — a newer `run()` took over
|
|
592
|
-
* a call that was waiting and had not yet started.
|
|
593
|
-
*/
|
|
594
618
|
type Outcome<E, A> = Ok<A> | Err<E> | Nil;
|
|
595
|
-
/** A successful outcome with a value. */
|
|
596
619
|
type Ok<A> = WithKind<"OpOk"> & WithValue<A>;
|
|
597
|
-
/** A failed outcome with a typed error. */
|
|
598
620
|
type Err<E> = WithKind<"OpErr"> & WithError<E>;
|
|
599
|
-
/**
|
|
600
|
-
* An outcome that produced nothing. `reason` identifies why:
|
|
601
|
-
* - `"aborted"` — `abort()` was called explicitly.
|
|
602
|
-
* - `"dropped"` — the invocation was ignored because the strategy was busy.
|
|
603
|
-
* - `"replaced"` — a newer invocation took over a call that was already running.
|
|
604
|
-
* - `"evicted"` — a newer invocation took a slot from a call that was waiting and
|
|
605
|
-
* had not yet started (buffered slot, debounce timer, throttle trailing slot).
|
|
606
|
-
*/
|
|
607
621
|
type Nil = WithKind<"OpNil"> & {
|
|
608
622
|
readonly reason: NilReason;
|
|
609
623
|
};
|
|
610
|
-
/** The reason a `Nil` outcome was produced. */
|
|
611
624
|
type NilReason = "aborted" | "dropped" | "replaced" | "evicted";
|
|
612
|
-
/** A `Nil` produced by an explicit `abort()` call. */
|
|
613
625
|
type AbortedNil = Nil & {
|
|
614
626
|
readonly reason: "aborted";
|
|
615
627
|
};
|
|
616
|
-
/** A `Nil` produced when an invocation was silently ignored (strategy was busy). */
|
|
617
628
|
type DroppedNil = Nil & {
|
|
618
629
|
readonly reason: "dropped";
|
|
619
630
|
};
|
|
620
|
-
/** A `Nil` produced when a newer invocation took over a call that was already running. */
|
|
621
631
|
type ReplacedNil = Nil & {
|
|
622
632
|
readonly reason: "replaced";
|
|
623
633
|
};
|
|
624
|
-
/** A `Nil` produced when a newer invocation took a slot from a call that was waiting and had not yet started. */
|
|
625
634
|
type EvictedNil = Nil & {
|
|
626
635
|
readonly reason: "evicted";
|
|
627
636
|
};
|
|
628
|
-
/** The full set of states a manager can emit, including transient states. */
|
|
629
637
|
type State<E, A> = Idle | Pending | Queued | Retrying<E> | Outcome<E, A>;
|
|
630
|
-
/** The manager has not been run yet (initial state). */
|
|
631
638
|
type Idle = WithKind<"Idle">;
|
|
632
|
-
/** An operation is in-flight. */
|
|
633
639
|
type Pending = WithKind<"Pending">;
|
|
634
|
-
/** An operation is waiting in a queue. `position` is 0-indexed (0 = next to run). */
|
|
635
640
|
type Queued = WithKind<"Queued"> & {
|
|
636
641
|
readonly position: number;
|
|
637
642
|
};
|
|
638
|
-
/** A retry attempt is about to start. */
|
|
639
643
|
type Retrying<E> = WithKind<"Retrying"> & {
|
|
640
644
|
readonly attempt: number;
|
|
641
645
|
readonly lastError: E;
|
|
642
646
|
readonly nextRetryIn?: number;
|
|
643
647
|
};
|
|
644
|
-
/**
|
|
645
|
-
* A stateful execution manager. `run()` both emits state transitions through
|
|
646
|
-
* subscribers and returns a `Deferred` tied to that specific invocation.
|
|
647
|
-
* `S` is narrowed to only the states reachable for this manager's strategy
|
|
648
|
-
* and configuration.
|
|
649
|
-
*
|
|
650
|
-
* @example
|
|
651
|
-
* ```ts
|
|
652
|
-
* const manager = Op.interpret(saveConfig, { strategy: "exclusive" });
|
|
653
|
-
*
|
|
654
|
-
* manager.subscribe(state => {
|
|
655
|
-
* if (Op.isPending(state)) lockForm();
|
|
656
|
-
* if (Op.isOk(state)) toast("Saved");
|
|
657
|
-
* if (Op.isErr(state)) toast(`Error: ${state.error.message}`);
|
|
658
|
-
* });
|
|
659
|
-
*
|
|
660
|
-
* // Fire and subscribe (subscriber pattern)
|
|
661
|
-
* manager.run(formData);
|
|
662
|
-
*
|
|
663
|
-
* // Or await the specific invocation's outcome
|
|
664
|
-
* const result = await manager.run(formData);
|
|
665
|
-
* if (Op.isNil(result)) return; // dropped — another save was in-flight
|
|
666
|
-
* ```
|
|
667
|
-
*/
|
|
668
648
|
type Manager<I, E, A, S extends State<E, A>> = {
|
|
669
|
-
/** The current state. Useful for synchronous reads (e.g., `useSyncExternalStore`). */
|
|
670
649
|
readonly state: S;
|
|
671
|
-
/**
|
|
672
|
-
* Submits an invocation. Emits state transitions via subscribers and returns a
|
|
673
|
-
* `Deferred` that resolves to the terminal outcome for this specific invocation.
|
|
674
|
-
* `Nil` means this invocation was not executed (dropped, replaced, or aborted).
|
|
675
|
-
*/
|
|
676
650
|
run: (input: I) => Deferred<Exclude<S, Idle | Pending | Queued | Retrying<E>>>;
|
|
677
|
-
/**
|
|
678
|
-
* Cancels any in-flight operation and clears the queue.
|
|
679
|
-
* Every pending `run()` Deferred — including queued invocations — settles to `AbortedNil`.
|
|
680
|
-
* Resolution is asynchronous; no Deferred hangs indefinitely.
|
|
681
|
-
*/
|
|
682
651
|
abort: () => void;
|
|
683
|
-
/**
|
|
684
|
-
* Registers a subscriber for state transitions. Returns an unsubscribe function.
|
|
685
|
-
* The callback fires immediately with the current state if the manager is not idle.
|
|
686
|
-
*/
|
|
687
652
|
subscribe: (cb: (state: S) => void) => () => void;
|
|
688
|
-
/** Returns state to Idle. Does not cancel any in-flight operation. */
|
|
689
653
|
reset: () => void;
|
|
690
|
-
/**
|
|
691
|
-
* Runs the input immediately, then every `interval` milliseconds.
|
|
692
|
-
* Returns a stop handle — call it to cancel future runs.
|
|
693
|
-
*/
|
|
694
654
|
poll: (input: I, options: {
|
|
695
655
|
interval: Duration;
|
|
696
656
|
}) => () => void;
|
|
697
657
|
};
|
|
698
|
-
/**
|
|
699
|
-
* A stateful manager that maintains independent per-key execution slots.
|
|
700
|
-
* Different keys run in parallel; the same key follows the `perKey` sub-strategy.
|
|
701
|
-
* `abort(key)` cancels a specific key; `abort()` cancels all.
|
|
702
|
-
* `state` is a map of each key's last known state — updated on every transition.
|
|
703
|
-
*
|
|
704
|
-
* @example
|
|
705
|
-
* ```ts
|
|
706
|
-
* const getUser = Op.interpret(fetchUser, {
|
|
707
|
-
* strategy: "keyed",
|
|
708
|
-
* key: (input) => input.id,
|
|
709
|
-
* perKey: "exclusive",
|
|
710
|
-
* });
|
|
711
|
-
*
|
|
712
|
-
* getUser.subscribe((map) => {
|
|
713
|
-
* for (const [id, state] of map) {
|
|
714
|
-
* if (Op.isPending(state)) showSpinner(id);
|
|
715
|
-
* if (Op.isOk(state)) render(id, state.value);
|
|
716
|
-
* }
|
|
717
|
-
* });
|
|
718
|
-
*
|
|
719
|
-
* getUser.run({ id: "user-1" }); // starts key "user-1"
|
|
720
|
-
* getUser.run({ id: "user-2" }); // starts key "user-2" in parallel
|
|
721
|
-
* ```
|
|
722
|
-
*/
|
|
723
658
|
type KeyedManager<I, K, E, PerKeyS> = {
|
|
724
|
-
/** Current state map. Keys are present from first `run()` through their last terminal state. */
|
|
725
659
|
readonly state: ReadonlyMap<K, PerKeyS>;
|
|
726
|
-
/**
|
|
727
|
-
* Submits an invocation for the key derived from the input. Returns a `Deferred` tied
|
|
728
|
-
* to this specific invocation. Same-key behaviour is controlled by `perKey`.
|
|
729
|
-
*/
|
|
730
660
|
run: (input: I) => Deferred<Exclude<PerKeyS, Pending | Retrying<E>>>;
|
|
731
|
-
/** Cancels the in-flight operation for a specific key, or all keys if omitted. */
|
|
732
661
|
abort: (key?: K) => void;
|
|
733
|
-
/**
|
|
734
|
-
* Registers a subscriber. The callback receives a fresh snapshot of the state map
|
|
735
|
-
* on every transition. Returns an unsubscribe function.
|
|
736
|
-
* Fires immediately with the current map if any key is active.
|
|
737
|
-
*/
|
|
738
662
|
subscribe: (cb: (state: ReadonlyMap<K, PerKeyS>) => void) => () => void;
|
|
739
|
-
/** Clears all per-key state and notifies subscribers. Does not cancel in-flight operations. */
|
|
740
663
|
reset: () => void;
|
|
741
|
-
/**
|
|
742
|
-
* Runs the input immediately, then every `interval` milliseconds.
|
|
743
|
-
* Returns a stop handle — call it to cancel future runs.
|
|
744
|
-
*/
|
|
745
664
|
poll: (input: I, options: {
|
|
746
665
|
interval: Duration;
|
|
747
666
|
}) => () => void;
|
|
748
667
|
};
|
|
749
|
-
/** States reachable by a `once` manager (no retry). */
|
|
750
668
|
type OnceState<E, A> = Idle | Pending | Ok<A> | Err<E> | AbortedNil | DroppedNil;
|
|
751
|
-
/** States reachable by a `once` manager with retry configured. */
|
|
752
669
|
type RetryableOnceState<E, A> = Idle | Pending | Retrying<E> | Ok<A> | Err<E> | AbortedNil | DroppedNil;
|
|
753
|
-
/** States reachable by a `restartable` manager (no retry). */
|
|
754
670
|
type RestartableState<E, A> = Idle | Pending | Ok<A> | Err<E> | AbortedNil | ReplacedNil;
|
|
755
|
-
/** States reachable by a `restartable` manager with retry configured. */
|
|
756
671
|
type RetryableRestartableState<E, A> = Idle | Pending | Retrying<E> | Ok<A> | Err<E> | AbortedNil | ReplacedNil;
|
|
757
|
-
/** States reachable by an `exclusive` manager (no retry). */
|
|
758
672
|
type ExclusiveState<E, A> = Idle | Pending | Ok<A> | Err<E> | AbortedNil | DroppedNil;
|
|
759
|
-
/** States reachable by an `exclusive` manager with retry configured. */
|
|
760
673
|
type RetryableExclusiveState<E, A> = Idle | Pending | Retrying<E> | Ok<A> | Err<E> | AbortedNil | DroppedNil;
|
|
761
|
-
/** States reachable by a `queue` manager (no retry, no overflow, no dedupe). */
|
|
762
674
|
type QueueState<E, A> = Idle | Pending | Queued | Ok<A> | Err<E> | AbortedNil;
|
|
763
|
-
/** States reachable by a `queue` manager with retry (no overflow, no dedupe). */
|
|
764
675
|
type RetryableQueueState<E, A> = Idle | Pending | Queued | Retrying<E> | Ok<A> | Err<E> | AbortedNil;
|
|
765
|
-
/** States reachable by a `queue` manager with `overflow:"drop"` or `dedupe` (no retry). */
|
|
766
676
|
type QueueDropState<E, A> = Idle | Pending | Queued | Ok<A> | Err<E> | AbortedNil | DroppedNil;
|
|
767
|
-
/** States reachable by a `queue` manager with `overflow:"drop"` or `dedupe`, with retry. */
|
|
768
677
|
type RetryableQueueDropState<E, A> = Idle | Pending | Queued | Retrying<E> | Ok<A> | Err<E> | AbortedNil | DroppedNil;
|
|
769
|
-
/** States reachable by a `queue` manager with `overflow:"replace-last"` and no `dedupe` (no retry). */
|
|
770
678
|
type QueueReplaceState<E, A> = Idle | Pending | Queued | Ok<A> | Err<E> | AbortedNil | EvictedNil;
|
|
771
|
-
/** States reachable by a `queue` manager with `overflow:"replace-last"` and no `dedupe`, with retry. */
|
|
772
679
|
type RetryableQueueReplaceState<E, A> = Idle | Pending | Queued | Retrying<E> | Ok<A> | Err<E> | AbortedNil | EvictedNil;
|
|
773
|
-
/** States reachable by a `queue` manager with `overflow:"replace-last"` AND `dedupe` (no retry). */
|
|
774
680
|
type QueueDropAndReplaceState<E, A> = Idle | Pending | Queued | Ok<A> | Err<E> | AbortedNil | DroppedNil | EvictedNil;
|
|
775
|
-
/** States reachable by a `queue` manager with `overflow:"replace-last"` AND `dedupe`, with retry. */
|
|
776
681
|
type RetryableQueueDropAndReplaceState<E, A> = Idle | Pending | Queued | Retrying<E> | Ok<A> | Err<E> | AbortedNil | DroppedNil | EvictedNil;
|
|
777
|
-
/** States reachable by a `buffered` manager (no retry). */
|
|
778
682
|
type BufferedState<E, A> = Idle | Pending | Queued | Ok<A> | Err<E> | AbortedNil | EvictedNil;
|
|
779
|
-
/** States reachable by a `buffered` manager with retry configured. */
|
|
780
683
|
type RetryableBufferedState<E, A> = Idle | Pending | Queued | Retrying<E> | Ok<A> | Err<E> | AbortedNil | EvictedNil;
|
|
781
|
-
/** States reachable by a `debounced` manager (no retry). */
|
|
782
684
|
type DebouncedState<E, A> = Idle | Pending | Ok<A> | Err<E> | AbortedNil | EvictedNil;
|
|
783
|
-
/** States reachable by a `debounced` manager with retry configured. */
|
|
784
685
|
type RetryableDebouncedState<E, A> = Idle | Pending | Retrying<E> | Ok<A> | Err<E> | AbortedNil | EvictedNil;
|
|
785
|
-
/** States reachable by a `throttled` manager (leading-only, no retry). */
|
|
786
686
|
type ThrottledState<E, A> = Idle | Pending | Ok<A> | Err<E> | AbortedNil | DroppedNil;
|
|
787
|
-
/** States reachable by a `throttled` manager (leading-only, with retry). */
|
|
788
687
|
type RetryableThrottledState<E, A> = Idle | Pending | Retrying<E> | Ok<A> | Err<E> | AbortedNil | DroppedNil;
|
|
789
|
-
/** States reachable by a `throttled` manager with `trailing: true` (no retry). */
|
|
790
688
|
type ThrottledTrailingState<E, A> = Idle | Pending | Ok<A> | Err<E> | AbortedNil | EvictedNil;
|
|
791
|
-
/** States reachable by a `throttled` manager with `trailing: true` and retry. */
|
|
792
689
|
type RetryableThrottledTrailingState<E, A> = Idle | Pending | Retrying<E> | Ok<A> | Err<E> | AbortedNil | EvictedNil;
|
|
793
|
-
/** States reachable by a `concurrent` manager with `overflow: "queue"` (no retry). */
|
|
794
690
|
type ConcurrentQueueState<E, A> = Idle | Pending | Queued | Ok<A> | Err<E> | AbortedNil;
|
|
795
|
-
/** States reachable by a `concurrent` manager with `overflow: "queue"` and retry. */
|
|
796
691
|
type RetryableConcurrentQueueState<E, A> = Idle | Pending | Queued | Retrying<E> | Ok<A> | Err<E> | AbortedNil;
|
|
797
|
-
/** States reachable by a `concurrent` manager with `overflow: "drop"` (no retry). */
|
|
798
692
|
type ConcurrentDropState<E, A> = Idle | Pending | Ok<A> | Err<E> | AbortedNil | DroppedNil;
|
|
799
|
-
/** States reachable by a `concurrent` manager with `overflow: "drop"` and retry. */
|
|
800
693
|
type RetryableConcurrentDropState<E, A> = Idle | Pending | Retrying<E> | Ok<A> | Err<E> | AbortedNil | DroppedNil;
|
|
801
|
-
/** Per-key state union for a `keyed` manager with `perKey: "exclusive"`. */
|
|
802
694
|
type KeyedExclusivePerKey<E, A> = Pending | Ok<A> | Err<E> | AbortedNil | DroppedNil;
|
|
803
|
-
/** Per-key state union for a `keyed` manager with `perKey: "restartable"`. */
|
|
804
695
|
type KeyedRestartablePerKey<E, A> = Pending | Ok<A> | Err<E> | AbortedNil | ReplacedNil;
|
|
805
696
|
type RetryOptions<E> = RetryOptions<E>;
|
|
806
697
|
type TimeoutOptions<E> = TimeoutOptions<E>;
|
|
807
|
-
/**
|
|
808
|
-
* Creates a `Nil` outcome with a reason.
|
|
809
|
-
*
|
|
810
|
-
* @example
|
|
811
|
-
* ```ts
|
|
812
|
-
* Op.nil("aborted"); // { kind: "OpNil", reason: "aborted" }
|
|
813
|
-
* Op.nil("dropped"); // { kind: "OpNil", reason: "dropped" }
|
|
814
|
-
* Op.nil("replaced"); // { kind: "OpNil", reason: "replaced" }
|
|
815
|
-
* Op.nil("evicted"); // { kind: "OpNil", reason: "evicted" }
|
|
816
|
-
* ```
|
|
817
|
-
*/
|
|
818
|
-
const nil: (reason: NilReason) => Nil;
|
|
819
|
-
/**
|
|
820
|
-
* Creates an `Op` from an async factory and an error mapper.
|
|
821
|
-
*
|
|
822
|
-
* The factory receives an `AbortSignal` and returns a function that takes the input. Capture
|
|
823
|
-
* the signal in the outer closure and pass it to cancellable APIs like `fetch`. The error
|
|
824
|
-
* mapper converts any thrown value into a typed error; it is never called for aborts.
|
|
825
|
-
*
|
|
826
|
-
* **If the factory ignores the signal**, cancellation silently stops working: the operation
|
|
827
|
-
* runs to completion and emits `Ok` even after the strategy has aborted it. This is harmless
|
|
828
|
-
* for `exclusive` and `once` (which do not abort in-flight work), but causes stale `Ok`
|
|
829
|
-
* emissions on `restartable`, `debounced`, `throttled`, `buffered`, and `queue` strategies
|
|
830
|
-
* where in-flight runs are regularly replaced or dropped.
|
|
831
|
-
*
|
|
832
|
-
* @example
|
|
833
|
-
* ```ts
|
|
834
|
-
* // With cancellation — fetch is aborted when the Op is replaced or aborted
|
|
835
|
-
* const saveProfile = Op.create(
|
|
836
|
-
* (signal) => (data: ProfileData) =>
|
|
837
|
-
* fetch("/profile", { method: "POST", body: JSON.stringify(data), signal })
|
|
838
|
-
* .then(r => {
|
|
839
|
-
* if (!r.ok) throw new Error(`${r.status} ${r.statusText}`);
|
|
840
|
-
* return r.json() as Promise<ProfileData>;
|
|
841
|
-
* }),
|
|
842
|
-
* (e) => new ApiError(e),
|
|
843
|
-
* );
|
|
844
|
-
*
|
|
845
|
-
* // No input — fetches the current user; manager.run() takes no arguments
|
|
846
|
-
* const fetchCurrentUser = Op.create(
|
|
847
|
-
* (signal) => () => fetch("/me", { signal }).then(r => {
|
|
848
|
-
* if (!r.ok) throw new Error(`${r.status} ${r.statusText}`);
|
|
849
|
-
* return r.json() as Promise<User>;
|
|
850
|
-
* }),
|
|
851
|
-
* (e) => new ApiError(e),
|
|
852
|
-
* );
|
|
853
|
-
* const manager = Op.interpret(fetchCurrentUser, { strategy: "once" });
|
|
854
|
-
* manager.run(); // no argument needed
|
|
855
|
-
* ```
|
|
856
|
-
*/
|
|
857
|
-
const create: <E, A, I = void>(factory: (signal: AbortSignal) => (input: I) => Promise<A>, onError: (e: unknown) => E) => Op<I, E, A>;
|
|
858
|
-
/**
|
|
859
|
-
* Lifts a plain async function into an Op, treating all errors as `unknown`.
|
|
860
|
-
*
|
|
861
|
-
* Use this when you have a simple async function that doesn't need custom error mapping.
|
|
862
|
-
* The signal is passed so the operation can respect cancellation.
|
|
863
|
-
*
|
|
864
|
-
* @example
|
|
865
|
-
* ```ts
|
|
866
|
-
* const fetchUser = Op.lift((id: number, signal: AbortSignal) =>
|
|
867
|
-
* fetch(`/api/users/${id}`, { signal }).then(r => r.json())
|
|
868
|
-
* );
|
|
869
|
-
* const manager = Op.interpret(fetchUser, { strategy: "restartable" });
|
|
870
|
-
* const outcome = await manager.run(42);
|
|
871
|
-
* if (Op.isOk(outcome)) console.log(outcome.value);
|
|
872
|
-
* ```
|
|
873
|
-
*/
|
|
874
|
-
const lift: <I, A>(f: (input: I, signal: AbortSignal) => Promise<A>) => Op<I, unknown, A>;
|
|
875
|
-
/**
|
|
876
|
-
* Creates a successful Outcome.
|
|
877
|
-
*
|
|
878
|
-
* @example
|
|
879
|
-
* ```ts
|
|
880
|
-
* Op.ok(42); // { kind: "OpOk", value: 42 }
|
|
881
|
-
* ```
|
|
882
|
-
*/
|
|
883
|
-
const ok: <A>(value: A) => Ok<A>;
|
|
884
|
-
/**
|
|
885
|
-
* Creates a failed Outcome with a typed error.
|
|
886
|
-
*
|
|
887
|
-
* @example
|
|
888
|
-
* ```ts
|
|
889
|
-
* Op.err(new ApiError("not found")); // { kind: "OpErr", error: ApiError }
|
|
890
|
-
* ```
|
|
891
|
-
*/
|
|
892
|
-
const err: <E>(error: E) => Err<E>;
|
|
893
|
-
/**
|
|
894
|
-
* Returns `true` if the state is `Idle`.
|
|
895
|
-
*
|
|
896
|
-
* @example
|
|
897
|
-
* ```ts
|
|
898
|
-
* manager.subscribe(state => {
|
|
899
|
-
* if (Op.isIdle(state)) hideSpinner();
|
|
900
|
-
* });
|
|
901
|
-
* ```
|
|
902
|
-
*/
|
|
903
|
-
const isIdle: <E, A>(state: State<E, A>) => state is Idle;
|
|
904
|
-
/**
|
|
905
|
-
* Returns `true` if the state is `Pending` (an operation is in-flight).
|
|
906
|
-
*
|
|
907
|
-
* @example
|
|
908
|
-
* ```ts
|
|
909
|
-
* manager.subscribe(state => {
|
|
910
|
-
* if (Op.isPending(state)) showSpinner();
|
|
911
|
-
* });
|
|
912
|
-
* ```
|
|
913
|
-
*/
|
|
914
|
-
const isPending: <E, A>(state: State<E, A>) => state is Pending;
|
|
915
|
-
/**
|
|
916
|
-
* Returns `true` if the state is `Queued` (an invocation is waiting to run).
|
|
917
|
-
*
|
|
918
|
-
* @example
|
|
919
|
-
* ```ts
|
|
920
|
-
* manager.subscribe(state => {
|
|
921
|
-
* if (Op.isQueued(state)) showQueuePosition(state.position);
|
|
922
|
-
* });
|
|
923
|
-
* ```
|
|
924
|
-
*/
|
|
925
|
-
const isQueued: <E, A>(state: State<E, A>) => state is Queued;
|
|
926
|
-
/**
|
|
927
|
-
* Returns `true` if the state is `Retrying`.
|
|
928
|
-
*
|
|
929
|
-
* @example
|
|
930
|
-
* ```ts
|
|
931
|
-
* manager.subscribe(state => {
|
|
932
|
-
* if (Op.isRetrying(state)) showRetryBadge(state.attempt);
|
|
933
|
-
* });
|
|
934
|
-
* ```
|
|
935
|
-
*/
|
|
936
|
-
const isRetrying: <E, A>(state: State<E, A>) => state is Retrying<E>;
|
|
937
|
-
/**
|
|
938
|
-
* Returns `true` if the state is `Ok` (the operation produced a value).
|
|
939
|
-
*
|
|
940
|
-
* @example
|
|
941
|
-
* ```ts
|
|
942
|
-
* manager.subscribe(state => {
|
|
943
|
-
* if (Op.isOk(state)) render(state.value);
|
|
944
|
-
* });
|
|
945
|
-
* ```
|
|
946
|
-
*/
|
|
947
|
-
const isOk: <E, A>(state: State<E, A>) => state is Ok<A>;
|
|
948
|
-
/**
|
|
949
|
-
* Returns `true` if the state is `Err` (the operation failed with a typed error).
|
|
950
|
-
*
|
|
951
|
-
* @example
|
|
952
|
-
* ```ts
|
|
953
|
-
* manager.subscribe(state => {
|
|
954
|
-
* if (Op.isErr(state)) showError(state.error);
|
|
955
|
-
* });
|
|
956
|
-
* ```
|
|
957
|
-
*/
|
|
958
|
-
const isErr: <E, A>(state: State<E, A>) => state is Err<E>;
|
|
959
|
-
/**
|
|
960
|
-
* Returns `true` if the state is `Nil` (the operation completed without a value or error).
|
|
961
|
-
*
|
|
962
|
-
* @example
|
|
963
|
-
* ```ts
|
|
964
|
-
* manager.subscribe(state => {
|
|
965
|
-
* if (Op.isNil(state)) resetUI();
|
|
966
|
-
* });
|
|
967
|
-
* ```
|
|
968
|
-
*/
|
|
969
|
-
const isNil: <E, A>(state: State<E, A>) => state is Nil;
|
|
970
|
-
/**
|
|
971
|
-
* Pattern matches on an Outcome using named case handlers.
|
|
972
|
-
*
|
|
973
|
-
* @example
|
|
974
|
-
* ```ts
|
|
975
|
-
* Op.match({
|
|
976
|
-
* ok: (user) => render(user),
|
|
977
|
-
* err: (e) => showError(e.message),
|
|
978
|
-
* nil: () => resetUI(),
|
|
979
|
-
* })(outcome);
|
|
980
|
-
* ```
|
|
981
|
-
*/
|
|
982
|
-
const match: <E, A, B>(cases: {
|
|
983
|
-
ok: (a: A) => B;
|
|
984
|
-
err: (e: E) => B;
|
|
985
|
-
nil: () => B;
|
|
986
|
-
}) => (outcome: Outcome<E, A>) => B;
|
|
987
|
-
/**
|
|
988
|
-
* Eliminates an Outcome with positional handlers.
|
|
989
|
-
* Order: `onErr`, `onNil`, `onOk` — mirrors `Result.fold` for the first and last cases.
|
|
990
|
-
*
|
|
991
|
-
* @example
|
|
992
|
-
* ```ts
|
|
993
|
-
* Op.fold(
|
|
994
|
-
* (e) => `error: ${e.message}`,
|
|
995
|
-
* () => "nothing",
|
|
996
|
-
* (v) => `value: ${v}`,
|
|
997
|
-
* )(outcome);
|
|
998
|
-
* ```
|
|
999
|
-
*/
|
|
1000
|
-
const fold: <E, A, B>(onErr: (e: E) => B, onNil: () => B, onOk: (a: A) => B) => (outcome: Outcome<E, A>) => B;
|
|
1001
|
-
/**
|
|
1002
|
-
* Returns the success value, or the result of `defaultValue()` for `Err` or `Nil`.
|
|
1003
|
-
*
|
|
1004
|
-
* @example
|
|
1005
|
-
* ```ts
|
|
1006
|
-
* Op.getOrElse(() => [] as User[])(outcome);
|
|
1007
|
-
* ```
|
|
1008
|
-
*/
|
|
1009
|
-
const getOrElse: <E, A, B>(defaultValue: () => B) => (outcome: Outcome<E, A>) => A | B;
|
|
1010
|
-
/**
|
|
1011
|
-
* Transforms the success value. `Err` and `Nil` pass through unchanged.
|
|
1012
|
-
*
|
|
1013
|
-
* @example
|
|
1014
|
-
* ```ts
|
|
1015
|
-
* pipe(outcome, Op.map(user => user.name));
|
|
1016
|
-
* ```
|
|
1017
|
-
*/
|
|
1018
|
-
const map: <E, A, B>(f: (a: A) => B) => (outcome: Outcome<E, A>) => Outcome<E, B>;
|
|
1019
|
-
/**
|
|
1020
|
-
* Transforms the error value. `Ok` and `Nil` pass through unchanged.
|
|
1021
|
-
*
|
|
1022
|
-
* @example
|
|
1023
|
-
* ```ts
|
|
1024
|
-
* pipe(outcome, Op.mapError(e => e.message));
|
|
1025
|
-
* ```
|
|
1026
|
-
*/
|
|
1027
|
-
const mapError: <E, F, A>(f: (e: E) => F) => (outcome: Outcome<E, A>) => Outcome<F, A>;
|
|
1028
|
-
/**
|
|
1029
|
-
* Chains Outcome computations. Runs `f` on `Ok`; `Err` and `Nil` pass through.
|
|
1030
|
-
*
|
|
1031
|
-
* @example
|
|
1032
|
-
* ```ts
|
|
1033
|
-
* pipe(
|
|
1034
|
-
* outcome,
|
|
1035
|
-
* Op.chain(user => user.active ? Op.ok(user) : Op.err(new Error("inactive"))),
|
|
1036
|
-
* );
|
|
1037
|
-
* ```
|
|
1038
|
-
*/
|
|
1039
|
-
const chain: <E, A, B>(f: (a: A) => Outcome<E, B>) => (outcome: Outcome<E, A>) => Outcome<E, B>;
|
|
1040
|
-
/**
|
|
1041
|
-
* Runs a side effect on the success value without changing the Outcome.
|
|
1042
|
-
*
|
|
1043
|
-
* @example
|
|
1044
|
-
* ```ts
|
|
1045
|
-
* pipe(outcome, Op.tap(user => console.log("loaded", user.id)));
|
|
1046
|
-
* ```
|
|
1047
|
-
*/
|
|
1048
|
-
const tap: <E, A>(f: (a: A) => void) => (outcome: Outcome<E, A>) => Outcome<E, A>;
|
|
1049
|
-
/**
|
|
1050
|
-
* Provides a fallback Outcome when the result is `Err`. `Ok` and `Nil` pass through.
|
|
1051
|
-
*
|
|
1052
|
-
* @example
|
|
1053
|
-
* ```ts
|
|
1054
|
-
* pipe(
|
|
1055
|
-
* outcome,
|
|
1056
|
-
* Op.recover(e => e.isRetryable ? Op.ok(cachedValue) : Op.err(e)),
|
|
1057
|
-
* );
|
|
1058
|
-
* ```
|
|
1059
|
-
*/
|
|
1060
|
-
const recover: <E, A, B>(f: (e: E) => Outcome<E, B>) => (outcome: Outcome<E, A>) => Outcome<E, A | B>;
|
|
1061
|
-
/**
|
|
1062
|
-
* Converts an Outcome to a `Result`. `Nil` becomes `Err(onNil())`.
|
|
1063
|
-
*
|
|
1064
|
-
* @example
|
|
1065
|
-
* ```ts
|
|
1066
|
-
* Op.to.Result(() => new ApiError("no result"))(outcome);
|
|
1067
|
-
* ```
|
|
1068
|
-
*/
|
|
1069
|
-
namespace to {
|
|
1070
|
-
/**
|
|
1071
|
-
* Converts an Outcome to a `Result`. `Nil` becomes `Err(onNil())`.
|
|
1072
|
-
*
|
|
1073
|
-
* @example
|
|
1074
|
-
* ```ts
|
|
1075
|
-
* Op.to.Result(() => new ApiError("no result"))(outcome);
|
|
1076
|
-
* ```
|
|
1077
|
-
*/
|
|
1078
|
-
const Result: <E, A>(onNil: () => E) => (outcome: Outcome<E, A>) => Result<E, A>;
|
|
1079
|
-
/**
|
|
1080
|
-
* Converts an Outcome to a `Maybe`. `Ok` becomes `Some`; `Err` and `Nil` become `None`.
|
|
1081
|
-
*
|
|
1082
|
-
* @example
|
|
1083
|
-
* ```ts
|
|
1084
|
-
* Op.to.Maybe(outcome); // Maybe<User>
|
|
1085
|
-
* ```
|
|
1086
|
-
*/
|
|
1087
|
-
const Maybe: <E, A>(outcome: Outcome<E, A>) => Maybe<A>;
|
|
1088
|
-
}
|
|
1089
|
-
/**
|
|
1090
|
-
* Resolves when all invocations settle, returning their outcomes in order.
|
|
1091
|
-
* An alternative to `Promise.all` that stays within the `Op` type system.
|
|
1092
|
-
*
|
|
1093
|
-
* @example
|
|
1094
|
-
* ```ts
|
|
1095
|
-
* const [a, b] = await Op.all([manager.run(inputA), manager.run(inputB)]);
|
|
1096
|
-
* ```
|
|
1097
|
-
*/
|
|
1098
|
-
const all: <E, A>(invocations: ReadonlyArray<Deferred<Outcome<E, A>>>) => Deferred<ReadonlyArray<Outcome<E, A>>>;
|
|
1099
|
-
/**
|
|
1100
|
-
* Resolves to the outcome of whichever invocation settles first.
|
|
1101
|
-
* An alternative to `Promise.race` that stays within the `Op` type system.
|
|
1102
|
-
*
|
|
1103
|
-
* @example
|
|
1104
|
-
* ```ts
|
|
1105
|
-
* const winner = await Op.race([manager.run(inputA), manager.run(inputB)]);
|
|
1106
|
-
* ```
|
|
1107
|
-
*/
|
|
1108
|
-
const race: <E, A>(invocations: ReadonlyArray<Deferred<Outcome<E, A>>>) => Deferred<Outcome<E, A>>;
|
|
1109
|
-
/**
|
|
1110
|
-
* Subscribes to a manager and calls a handler when the state reaches `OpOk`.
|
|
1111
|
-
* Returns an unsubscribe function.
|
|
1112
|
-
*
|
|
1113
|
-
* @example
|
|
1114
|
-
* ```ts
|
|
1115
|
-
* const manager = Op.interpret(fetchUser, { strategy: "restartable" });
|
|
1116
|
-
* const stop = Op.wire(manager, (user) => {
|
|
1117
|
-
* console.log("User loaded:", user.name);
|
|
1118
|
-
* });
|
|
1119
|
-
* manager.run(userId);
|
|
1120
|
-
* // ... later
|
|
1121
|
-
* stop(); // removes the subscription
|
|
1122
|
-
* ```
|
|
1123
|
-
*/
|
|
1124
|
-
const wire: <I, E, A, S extends State<E, A>>(source: Manager<I, E, A, S>, f: (a: A) => void) => () => void;
|
|
1125
|
-
/**
|
|
1126
|
-
* Attaches a concurrency strategy to an `Op`, returning a `Manager`.
|
|
1127
|
-
*
|
|
1128
|
-
* Strategy is data, not a method name. The `S` type parameter is narrowed to only
|
|
1129
|
-
* the states reachable for the chosen strategy and options — subscribers cannot
|
|
1130
|
-
* reference states that cannot occur.
|
|
1131
|
-
*
|
|
1132
|
-
* **Strategies:**
|
|
1133
|
-
* - `once` — fires once. Only the first `run()` executes; subsequent calls
|
|
1134
|
-
* return `DroppedNil` immediately. State is permanent after completion.
|
|
1135
|
-
* - `restartable` — new call cancels the previous (`ReplacedNil`). Only the latest result matters.
|
|
1136
|
-
* - `exclusive` — new calls while in-flight return `DroppedNil` immediately.
|
|
1137
|
-
* - `queue` — calls run in submission order. `Queued` state shows position.
|
|
1138
|
-
* - `buffered` — 1 in-flight + 1 waiting slot. Newer calls evict the slot (`EvictedNil`).
|
|
1139
|
-
* - `debounced` — waits `ms` ms of quiet before starting. Earlier calls get `EvictedNil`.
|
|
1140
|
-
*
|
|
1141
|
-
* **`retry` and `timeout`** can be combined with any strategy. Both are applied
|
|
1142
|
-
* internally per `run()` call — set the policy once, not at every call site.
|
|
1143
|
-
* The timeout wraps the entire retry sequence (one deadline for all attempts).
|
|
1144
|
-
* When `retry` is present, `Retrying` is added to the subscriber type.
|
|
1145
|
-
*
|
|
1146
|
-
* @example
|
|
1147
|
-
* ```ts
|
|
1148
|
-
* // Load once on mount — further calls are no-ops
|
|
1149
|
-
* const getUser = Op.interpret(fetchUser, { strategy: "once" });
|
|
1150
|
-
* getUser.subscribe(state => {
|
|
1151
|
-
* if (state.kind === "Pending") showSpinner();
|
|
1152
|
-
* if (state.kind === "OpOk") render(state.value);
|
|
1153
|
-
* });
|
|
1154
|
-
* getUser.run(userId);
|
|
1155
|
-
*
|
|
1156
|
-
* // Search: cancel the previous query when a new one starts
|
|
1157
|
-
* const search = Op.interpret(searchOp, { strategy: "restartable" });
|
|
1158
|
-
*
|
|
1159
|
-
* // Form submit: ignore double-clicks while in-flight
|
|
1160
|
-
* const submit = Op.interpret(submitOp, {
|
|
1161
|
-
* strategy: "exclusive",
|
|
1162
|
-
* retry: { attempts: 3, backoff: n => n * 500 },
|
|
1163
|
-
* timeout: { ms: 10_000, onTimeout: () => new ApiError("timed out") },
|
|
1164
|
-
* });
|
|
1165
|
-
*
|
|
1166
|
-
* // Auto-save: current save commits fully; latest pending edit saves next
|
|
1167
|
-
* const save = Op.interpret(saveOp, { strategy: "buffered" });
|
|
1168
|
-
* ```
|
|
1169
|
-
*/
|
|
1170
|
-
function interpret<I, E, A, O extends AllInterpretOptions<I, E>>(op: Op<I, E, A>, options: O): InterpretResult<I, E, A, O>;
|
|
1171
698
|
}
|
|
1172
699
|
|
|
1173
700
|
/** Keys of T for which undefined is assignable (i.e. optional fields). */
|
|
@@ -1196,8 +723,8 @@ type Optional<S, A> = {
|
|
|
1196
723
|
readonly get: (s: S) => Maybe<A>;
|
|
1197
724
|
readonly set: (a: A) => (s: S) => S;
|
|
1198
725
|
};
|
|
1199
|
-
declare
|
|
1200
|
-
|
|
726
|
+
declare const Optional: {
|
|
727
|
+
from: {
|
|
1201
728
|
/**
|
|
1202
729
|
* Constructs an Optional from a getter (returning Maybe<A>) and a setter.
|
|
1203
730
|
*
|
|
@@ -1209,7 +736,7 @@ declare namespace Optional {
|
|
|
1209
736
|
* );
|
|
1210
737
|
* ```
|
|
1211
738
|
*/
|
|
1212
|
-
|
|
739
|
+
accessors: <S, A>(get: (s: S) => Maybe<A>, set: (a: A) => (s: S) => S) => Optional<S, A>;
|
|
1213
740
|
/**
|
|
1214
741
|
* Creates an Optional that focuses on an optional property of an object.
|
|
1215
742
|
* Only keys whose type includes undefined (i.e. `field?: T`) are accepted.
|
|
@@ -1221,8 +748,8 @@ declare namespace Optional {
|
|
|
1221
748
|
* const bioOpt = Optional.from.property<Profile>()("bio");
|
|
1222
749
|
* ```
|
|
1223
750
|
*/
|
|
1224
|
-
|
|
1225
|
-
}
|
|
751
|
+
property: <S>() => <K extends OptionalKeys<S>>(key: K) => Optional<S, NonNullable<S[K]>>;
|
|
752
|
+
};
|
|
1226
753
|
/**
|
|
1227
754
|
* Creates an Optional that focuses on an element at a given index in an array.
|
|
1228
755
|
* Returns None when the index is out of bounds; set is a no-op when out of bounds.
|
|
@@ -1235,7 +762,7 @@ declare namespace Optional {
|
|
|
1235
762
|
* pipe([], Optional.get(firstItem)); // None
|
|
1236
763
|
* ```
|
|
1237
764
|
*/
|
|
1238
|
-
|
|
765
|
+
index: <A>(i: number) => Optional<A[], A>;
|
|
1239
766
|
/**
|
|
1240
767
|
* Reads the focused value from a structure, returning Maybe<A>.
|
|
1241
768
|
*
|
|
@@ -1244,7 +771,7 @@ declare namespace Optional {
|
|
|
1244
771
|
* pipe(profile, Optional.get(bioOpt)); // Some("...") or None
|
|
1245
772
|
* ```
|
|
1246
773
|
*/
|
|
1247
|
-
|
|
774
|
+
get: <S, A>(opt: Optional<S, A>) => (s: S) => Maybe<A>;
|
|
1248
775
|
/**
|
|
1249
776
|
* Replaces the focused value within a structure.
|
|
1250
777
|
* For indexed focuses, this is a no-op when the index is out of bounds.
|
|
@@ -1254,7 +781,7 @@ declare namespace Optional {
|
|
|
1254
781
|
* pipe(profile, Optional.set(bioOpt)("hello"));
|
|
1255
782
|
* ```
|
|
1256
783
|
*/
|
|
1257
|
-
|
|
784
|
+
set: <S, A>(opt: Optional<S, A>) => (a: A) => (s: S) => S;
|
|
1258
785
|
/**
|
|
1259
786
|
* Applies a function to the focused value if it is present; returns the
|
|
1260
787
|
* structure unchanged if the focus is absent.
|
|
@@ -1264,7 +791,7 @@ declare namespace Optional {
|
|
|
1264
791
|
* pipe(profile, Optional.modify(bioOpt)(s => s.toUpperCase()));
|
|
1265
792
|
* ```
|
|
1266
793
|
*/
|
|
1267
|
-
|
|
794
|
+
modify: <S, A>(opt: Optional<S, A>) => (f: (a: A) => A) => (s: S) => S;
|
|
1268
795
|
/**
|
|
1269
796
|
* Returns the focused value or a default when the focus is absent.
|
|
1270
797
|
*
|
|
@@ -1273,7 +800,7 @@ declare namespace Optional {
|
|
|
1273
800
|
* pipe(profile, Optional.getOrElse(bioOpt)(() => "no bio"));
|
|
1274
801
|
* ```
|
|
1275
802
|
*/
|
|
1276
|
-
|
|
803
|
+
getOrElse: <S, A>(opt: Optional<S, A>) => (defaultValue: () => A) => (s: S) => A;
|
|
1277
804
|
/**
|
|
1278
805
|
* Extracts a value from an Optional focus using handlers for the present
|
|
1279
806
|
* and absent cases.
|
|
@@ -1283,7 +810,7 @@ declare namespace Optional {
|
|
|
1283
810
|
* pipe(profile, Optional.fold(bioOpt)(() => "no bio", (bio) => bio.toUpperCase()));
|
|
1284
811
|
* ```
|
|
1285
812
|
*/
|
|
1286
|
-
|
|
813
|
+
fold: <S, A>(opt: Optional<S, A>) => <B>(onNone: () => B, onSome: (a: A) => B) => (s: S) => B;
|
|
1287
814
|
/**
|
|
1288
815
|
* Pattern matches on an Optional focus using a named-case object.
|
|
1289
816
|
*
|
|
@@ -1295,7 +822,7 @@ declare namespace Optional {
|
|
|
1295
822
|
* );
|
|
1296
823
|
* ```
|
|
1297
824
|
*/
|
|
1298
|
-
|
|
825
|
+
match: <S, A>(opt: Optional<S, A>) => <B>(cases: {
|
|
1299
826
|
none: () => B;
|
|
1300
827
|
some: (a: A) => B;
|
|
1301
828
|
}) => (s: S) => B;
|
|
@@ -1311,7 +838,7 @@ declare namespace Optional {
|
|
|
1311
838
|
* );
|
|
1312
839
|
* ```
|
|
1313
840
|
*/
|
|
1314
|
-
|
|
841
|
+
andThen: <A, B>(inner: Optional<A, B>) => <S>(outer: Optional<S, A>) => Optional<S, B>;
|
|
1315
842
|
/**
|
|
1316
843
|
* Composes an Optional with a Lens, producing an Optional.
|
|
1317
844
|
* The Lens focuses within the value found by the Optional.
|
|
@@ -1324,8 +851,8 @@ declare namespace Optional {
|
|
|
1324
851
|
* );
|
|
1325
852
|
* ```
|
|
1326
853
|
*/
|
|
1327
|
-
|
|
1328
|
-
}
|
|
854
|
+
andThenLens: <A, B>(inner: Lens<A, B>) => <S>(outer: Optional<S, A>) => Optional<S, B>;
|
|
855
|
+
};
|
|
1329
856
|
|
|
1330
857
|
/**
|
|
1331
858
|
* Pair<A, B> represents a pair of two values that are always both present.
|
|
@@ -1350,8 +877,8 @@ declare namespace Optional {
|
|
|
1350
877
|
* ```
|
|
1351
878
|
*/
|
|
1352
879
|
type Pair<A, B> = readonly [A, B];
|
|
1353
|
-
declare
|
|
1354
|
-
|
|
880
|
+
declare const Pair: {
|
|
881
|
+
from: {
|
|
1355
882
|
/**
|
|
1356
883
|
* Creates a Pair from two values.
|
|
1357
884
|
*
|
|
@@ -1360,7 +887,7 @@ declare namespace Pair {
|
|
|
1360
887
|
* Pair.from.pair("Paris", 2_161_000); // ["Paris", 2161000]
|
|
1361
888
|
* ```
|
|
1362
889
|
*/
|
|
1363
|
-
|
|
890
|
+
pair: <A, B>(first: A, second: B) => Pair<A, B>;
|
|
1364
891
|
/**
|
|
1365
892
|
* Creates a Pair from a two-element array.
|
|
1366
893
|
*
|
|
@@ -1369,8 +896,8 @@ declare namespace Pair {
|
|
|
1369
896
|
* Pair.from.array(["Paris", 2_161_000] as const); // ["Paris", 2161000]
|
|
1370
897
|
* ```
|
|
1371
898
|
*/
|
|
1372
|
-
|
|
1373
|
-
}
|
|
899
|
+
array: <A, B>(arr: readonly [A, B]) => Pair<A, B>;
|
|
900
|
+
};
|
|
1374
901
|
/**
|
|
1375
902
|
* Returns the first value from the pair.
|
|
1376
903
|
*
|
|
@@ -1379,7 +906,7 @@ declare namespace Pair {
|
|
|
1379
906
|
* Pair.first(Pair.from.pair("Paris", 2_161_000)); // "Paris"
|
|
1380
907
|
* ```
|
|
1381
908
|
*/
|
|
1382
|
-
|
|
909
|
+
first: <A, B>(p: Pair<A, B>) => A;
|
|
1383
910
|
/**
|
|
1384
911
|
* Returns the second value from the pair.
|
|
1385
912
|
*
|
|
@@ -1388,7 +915,7 @@ declare namespace Pair {
|
|
|
1388
915
|
* Pair.second(Pair.from.pair("Paris", 2_161_000)); // 2161000
|
|
1389
916
|
* ```
|
|
1390
917
|
*/
|
|
1391
|
-
|
|
918
|
+
second: <A, B>(p: Pair<A, B>) => B;
|
|
1392
919
|
/**
|
|
1393
920
|
* Transforms the first value, leaving the second unchanged.
|
|
1394
921
|
*
|
|
@@ -1397,7 +924,7 @@ declare namespace Pair {
|
|
|
1397
924
|
* pipe(Pair.from.pair("alice", 42), Pair.mapFirst((s) => s.toUpperCase())); // ["ALICE", 42]
|
|
1398
925
|
* ```
|
|
1399
926
|
*/
|
|
1400
|
-
|
|
927
|
+
mapFirst: <A, C>(f: (a: A) => C) => <B>(p: Pair<A, B>) => Pair<C, B>;
|
|
1401
928
|
/**
|
|
1402
929
|
* Transforms the second value, leaving the first unchanged.
|
|
1403
930
|
*
|
|
@@ -1406,7 +933,7 @@ declare namespace Pair {
|
|
|
1406
933
|
* pipe(Pair.from.pair("alice", 42), Pair.mapSecond((n) => n * 2)); // ["alice", 84]
|
|
1407
934
|
* ```
|
|
1408
935
|
*/
|
|
1409
|
-
|
|
936
|
+
mapSecond: <B, D>(f: (b: B) => D) => <A>(p: Pair<A, B>) => Pair<A, D>;
|
|
1410
937
|
/**
|
|
1411
938
|
* Transforms both values independently in a single step.
|
|
1412
939
|
*
|
|
@@ -1421,7 +948,7 @@ declare namespace Pair {
|
|
|
1421
948
|
* ); // ["ALICE", 84]
|
|
1422
949
|
* ```
|
|
1423
950
|
*/
|
|
1424
|
-
|
|
951
|
+
mapBoth: <A, C, B, D>(onFirst: (a: A) => C, onSecond: (b: B) => D) => (p: Pair<A, B>) => Pair<C, D>;
|
|
1425
952
|
/**
|
|
1426
953
|
* Applies a binary function to both values, collapsing the pair into a single value.
|
|
1427
954
|
* Useful as the final step when consuming a pair in a pipeline.
|
|
@@ -1432,7 +959,7 @@ declare namespace Pair {
|
|
|
1432
959
|
* // "Alice: 100"
|
|
1433
960
|
* ```
|
|
1434
961
|
*/
|
|
1435
|
-
|
|
962
|
+
fold: <A, B, C>(f: (a: A, b: B) => C) => (p: Pair<A, B>) => C;
|
|
1436
963
|
/**
|
|
1437
964
|
* Swaps the two values: `[A, B]` becomes `[B, A]`.
|
|
1438
965
|
*
|
|
@@ -1441,8 +968,8 @@ declare namespace Pair {
|
|
|
1441
968
|
* Pair.swap(Pair.from.pair("key", 1)); // [1, "key"]
|
|
1442
969
|
* ```
|
|
1443
970
|
*/
|
|
1444
|
-
|
|
1445
|
-
|
|
971
|
+
swap: <A, B>(p: Pair<A, B>) => Pair<B, A>;
|
|
972
|
+
to: {
|
|
1446
973
|
/**
|
|
1447
974
|
* Converts the pair to a heterogeneous readonly array `readonly (A | B)[]`.
|
|
1448
975
|
*
|
|
@@ -1451,8 +978,8 @@ declare namespace Pair {
|
|
|
1451
978
|
* Pair.to.Array(Pair.from.pair("hello", 42)); // ["hello", 42]
|
|
1452
979
|
* ```
|
|
1453
980
|
*/
|
|
1454
|
-
|
|
1455
|
-
}
|
|
981
|
+
Array: <A, B>(p: Pair<A, B>) => readonly (A | B)[];
|
|
982
|
+
};
|
|
1456
983
|
/**
|
|
1457
984
|
* Runs a side effect with both values without changing the pair.
|
|
1458
985
|
* Useful for logging or debugging in the middle of a pipeline.
|
|
@@ -1466,8 +993,8 @@ declare namespace Pair {
|
|
|
1466
993
|
* ); // logs "Paris: 2161000", returns ["Paris", 2.161]
|
|
1467
994
|
* ```
|
|
1468
995
|
*/
|
|
1469
|
-
|
|
1470
|
-
}
|
|
996
|
+
tap: <A, B>(f: (a: A, b: B) => void) => (p: Pair<A, B>) => Pair<A, B>;
|
|
997
|
+
};
|
|
1471
998
|
|
|
1472
999
|
/**
|
|
1473
1000
|
* A boolean-valued function over a type `A`.
|
|
@@ -1496,7 +1023,7 @@ declare namespace Pair {
|
|
|
1496
1023
|
* ```
|
|
1497
1024
|
*/
|
|
1498
1025
|
type Predicate<A> = (a: A) => boolean;
|
|
1499
|
-
declare
|
|
1026
|
+
declare const Predicate: {
|
|
1500
1027
|
/**
|
|
1501
1028
|
* Negates a predicate: the result passes exactly when the original fails.
|
|
1502
1029
|
*
|
|
@@ -1509,7 +1036,7 @@ declare namespace Predicate {
|
|
|
1509
1036
|
* isNotBlank(" "); // false
|
|
1510
1037
|
* ```
|
|
1511
1038
|
*/
|
|
1512
|
-
|
|
1039
|
+
not: <A>(p: Predicate<A>) => Predicate<A>;
|
|
1513
1040
|
/**
|
|
1514
1041
|
* Combines two predicates with logical AND: passes only when both hold.
|
|
1515
1042
|
*
|
|
@@ -1527,7 +1054,7 @@ declare namespace Predicate {
|
|
|
1527
1054
|
* isPositiveEven(-2); // false — even but not positive
|
|
1528
1055
|
* ```
|
|
1529
1056
|
*/
|
|
1530
|
-
|
|
1057
|
+
and: <A>(second: Predicate<A>) => (first: Predicate<A>) => Predicate<A>;
|
|
1531
1058
|
/**
|
|
1532
1059
|
* Combines two predicates with logical OR: passes when either holds.
|
|
1533
1060
|
*
|
|
@@ -1545,7 +1072,7 @@ declare namespace Predicate {
|
|
|
1545
1072
|
* getsDiscount(30); // false
|
|
1546
1073
|
* ```
|
|
1547
1074
|
*/
|
|
1548
|
-
|
|
1075
|
+
or: <A>(second: Predicate<A>) => (first: Predicate<A>) => Predicate<A>;
|
|
1549
1076
|
/**
|
|
1550
1077
|
* Adapts a `Predicate<A>` to work on a different input type `B` by applying `f`
|
|
1551
1078
|
* to extract the relevant `A` from a `B` before running the check.
|
|
@@ -1568,7 +1095,7 @@ declare namespace Predicate {
|
|
|
1568
1095
|
* isAdultUser({ name: "Bob", age: 15 }); // false
|
|
1569
1096
|
* ```
|
|
1570
1097
|
*/
|
|
1571
|
-
|
|
1098
|
+
using: <A, B>(f: (b: B) => A) => (p: Predicate<A>) => Predicate<B>;
|
|
1572
1099
|
/**
|
|
1573
1100
|
* Combines an array of predicates with AND: passes only when every predicate holds.
|
|
1574
1101
|
* Returns `true` for an empty array (vacuous truth).
|
|
@@ -1587,7 +1114,7 @@ declare namespace Predicate {
|
|
|
1587
1114
|
* Predicate.all([])("anything"); // true
|
|
1588
1115
|
* ```
|
|
1589
1116
|
*/
|
|
1590
|
-
|
|
1117
|
+
all: <A>(predicates: ReadonlyArray<Predicate<A>>) => Predicate<A>;
|
|
1591
1118
|
/**
|
|
1592
1119
|
* Combines an array of predicates with OR: passes when at least one holds.
|
|
1593
1120
|
* Returns `false` for an empty array.
|
|
@@ -1605,8 +1132,8 @@ declare namespace Predicate {
|
|
|
1605
1132
|
* Predicate.any([])("anything"); // false
|
|
1606
1133
|
* ```
|
|
1607
1134
|
*/
|
|
1608
|
-
|
|
1609
|
-
|
|
1135
|
+
any: <A>(predicates: ReadonlyArray<Predicate<A>>) => Predicate<A>;
|
|
1136
|
+
from: {
|
|
1610
1137
|
/**
|
|
1611
1138
|
* Converts a `Refinement<A, B>` into a `Predicate<A>`, discarding the compile-time
|
|
1612
1139
|
* narrowing. Use this when you want to combine a type guard with plain predicates
|
|
@@ -1629,8 +1156,8 @@ declare namespace Predicate {
|
|
|
1629
1156
|
* isShortString(42); // false
|
|
1630
1157
|
* ```
|
|
1631
1158
|
*/
|
|
1632
|
-
|
|
1633
|
-
}
|
|
1159
|
+
Refinement: <A, B extends A>(r: Refinement<A, B>) => Predicate<A>;
|
|
1160
|
+
};
|
|
1634
1161
|
/**
|
|
1635
1162
|
* Performs declarative conditional branching over `[predicate, handler]` pairs,
|
|
1636
1163
|
* returning the handler result of the first matching predicate or evaluating the fallback.
|
|
@@ -1647,8 +1174,8 @@ declare namespace Predicate {
|
|
|
1647
1174
|
* classifyNumber(-5); // "negative"
|
|
1648
1175
|
* ```
|
|
1649
1176
|
*/
|
|
1650
|
-
|
|
1651
|
-
}
|
|
1177
|
+
match: <A, B>(branches: ReadonlyArray<readonly [Predicate<A>, (a: A) => B]>, fallback: (a: A) => B) => (a: A) => B;
|
|
1178
|
+
};
|
|
1652
1179
|
|
|
1653
1180
|
/**
|
|
1654
1181
|
* A computation that reads from a shared environment `R` and produces a value `A`.
|
|
@@ -1676,7 +1203,7 @@ declare namespace Predicate {
|
|
|
1676
1203
|
* ```
|
|
1677
1204
|
*/
|
|
1678
1205
|
type Reader<R, A> = (env: R) => A;
|
|
1679
|
-
declare
|
|
1206
|
+
declare const Reader: {
|
|
1680
1207
|
/**
|
|
1681
1208
|
* Lifts a pure value into a Reader. The environment is ignored.
|
|
1682
1209
|
*
|
|
@@ -1686,7 +1213,7 @@ declare namespace Reader {
|
|
|
1686
1213
|
* always42(anyConfig); // 42
|
|
1687
1214
|
* ```
|
|
1688
1215
|
*/
|
|
1689
|
-
|
|
1216
|
+
resolve: <R, A>(value: A) => Reader<R, A>;
|
|
1690
1217
|
/**
|
|
1691
1218
|
* Returns the full environment as the result.
|
|
1692
1219
|
* The fundamental way to access the environment in a pipeline.
|
|
@@ -1699,7 +1226,7 @@ declare namespace Reader {
|
|
|
1699
1226
|
* )(appConfig); // "https://api.example.com"
|
|
1700
1227
|
* ```
|
|
1701
1228
|
*/
|
|
1702
|
-
|
|
1229
|
+
ask: <R>() => Reader<R, R>;
|
|
1703
1230
|
/**
|
|
1704
1231
|
* Projects a value from the environment using a selector function.
|
|
1705
1232
|
* Equivalent to `pipe(Reader.ask(), Reader.map(f))` but more direct.
|
|
@@ -1710,7 +1237,7 @@ declare namespace Reader {
|
|
|
1710
1237
|
* getBaseUrl(appConfig); // "https://api.example.com"
|
|
1711
1238
|
* ```
|
|
1712
1239
|
*/
|
|
1713
|
-
|
|
1240
|
+
asks: <R, A>(f: (env: R) => A) => Reader<R, A>;
|
|
1714
1241
|
/**
|
|
1715
1242
|
* Transforms the value produced by a Reader.
|
|
1716
1243
|
*
|
|
@@ -1722,7 +1249,7 @@ declare namespace Reader {
|
|
|
1722
1249
|
* )(appConfig); // "HTTPS://API.EXAMPLE.COM"
|
|
1723
1250
|
* ```
|
|
1724
1251
|
*/
|
|
1725
|
-
|
|
1252
|
+
map: <R, A, B>(f: (a: A) => B) => (data: Reader<R, A>) => Reader<R, B>;
|
|
1726
1253
|
/**
|
|
1727
1254
|
* Sequences two Readers. Both see the same environment.
|
|
1728
1255
|
* The output of the first is passed to `f`, which returns the next Reader.
|
|
@@ -1741,7 +1268,7 @@ declare namespace Reader {
|
|
|
1741
1268
|
* )(appConfig); // "https://api.example.com/items?key=secret"
|
|
1742
1269
|
* ```
|
|
1743
1270
|
*/
|
|
1744
|
-
|
|
1271
|
+
chain: <R, A, B>(f: (a: A) => Reader<R, B>) => (data: Reader<R, A>) => Reader<R, B>;
|
|
1745
1272
|
/**
|
|
1746
1273
|
* Applies a function wrapped in a Reader to a value wrapped in a Reader.
|
|
1747
1274
|
* Both Readers see the same environment.
|
|
@@ -1756,7 +1283,7 @@ declare namespace Reader {
|
|
|
1756
1283
|
* )(appConfig);
|
|
1757
1284
|
* ```
|
|
1758
1285
|
*/
|
|
1759
|
-
|
|
1286
|
+
ap: <R, A>(arg: Reader<R, A>) => <B>(data: Reader<R, (a: A) => B>) => Reader<R, B>;
|
|
1760
1287
|
/**
|
|
1761
1288
|
* Executes a side effect on the produced value without changing the Reader.
|
|
1762
1289
|
* Useful for logging or debugging inside a pipeline.
|
|
@@ -1770,7 +1297,7 @@ declare namespace Reader {
|
|
|
1770
1297
|
* )(appConfig);
|
|
1771
1298
|
* ```
|
|
1772
1299
|
*/
|
|
1773
|
-
|
|
1300
|
+
tap: <R, A>(f: (a: A) => void) => (data: Reader<R, A>) => Reader<R, A>;
|
|
1774
1301
|
/**
|
|
1775
1302
|
* Adapts a Reader to work with a different (typically wider) environment
|
|
1776
1303
|
* by transforming the environment before passing it to the Reader.
|
|
@@ -1790,7 +1317,7 @@ declare namespace Reader {
|
|
|
1790
1317
|
* buildUrlFromApp(appEnv); // works with the full AppEnv
|
|
1791
1318
|
* ```
|
|
1792
1319
|
*/
|
|
1793
|
-
|
|
1320
|
+
local: <R2, R>(f: (env: R2) => R) => <A>(data: Reader<R, A>) => Reader<R2, A>;
|
|
1794
1321
|
/**
|
|
1795
1322
|
* Runs a Reader by supplying the environment. Use this at the edge of your
|
|
1796
1323
|
* program where the environment is available.
|
|
@@ -1803,7 +1330,7 @@ declare namespace Reader {
|
|
|
1803
1330
|
* ); // "https://api.example.com/users?key=secret"
|
|
1804
1331
|
* ```
|
|
1805
1332
|
*/
|
|
1806
|
-
|
|
1333
|
+
run: <R>(env: R) => <A>(data: Reader<R, A>) => A;
|
|
1807
1334
|
/**
|
|
1808
1335
|
* Lifts a Reader value into an accumulator object.
|
|
1809
1336
|
*
|
|
@@ -1812,7 +1339,7 @@ declare namespace Reader {
|
|
|
1812
1339
|
* pipe(Reader.resolve(42), Reader.bindTo("value")); // Reader({ value: 42 })
|
|
1813
1340
|
* ```
|
|
1814
1341
|
*/
|
|
1815
|
-
|
|
1342
|
+
bindTo: <K extends string>(key: K) => <R, A>(data: Reader<R, A>) => Reader<R, { [P in K]: A; }>;
|
|
1816
1343
|
/**
|
|
1817
1344
|
* Evaluates a new Reader using the current accumulator and attaches the output to a new key.
|
|
1818
1345
|
*
|
|
@@ -1824,8 +1351,8 @@ declare namespace Reader {
|
|
|
1824
1351
|
* ); // Reader({ a: 1, b: 2 })
|
|
1825
1352
|
* ```
|
|
1826
1353
|
*/
|
|
1827
|
-
|
|
1828
|
-
}
|
|
1354
|
+
bind: <K extends string, R, A, B>(key: K, f: (a: A) => Reader<R, B>) => (data: Reader<R, A>) => Reader<R, A & { [P in K]: B; }>;
|
|
1355
|
+
};
|
|
1829
1356
|
|
|
1830
1357
|
/**
|
|
1831
1358
|
* A function from `A` to `A is B` — a type predicate paired with a runtime check.
|
|
@@ -1850,8 +1377,8 @@ declare namespace Reader {
|
|
|
1850
1377
|
* ```
|
|
1851
1378
|
*/
|
|
1852
1379
|
type Refinement<A, B extends A> = (a: A) => a is B;
|
|
1853
|
-
declare
|
|
1854
|
-
|
|
1380
|
+
declare const Refinement: {
|
|
1381
|
+
from: {
|
|
1855
1382
|
/**
|
|
1856
1383
|
* Creates a `Refinement<A, B>` from a plain boolean predicate.
|
|
1857
1384
|
*
|
|
@@ -1868,8 +1395,8 @@ declare namespace Refinement {
|
|
|
1868
1395
|
* Refinement.from.predicate(n => n > 0);
|
|
1869
1396
|
* ```
|
|
1870
1397
|
*/
|
|
1871
|
-
|
|
1872
|
-
}
|
|
1398
|
+
predicate: <A, B extends A>(f: (a: A) => boolean) => Refinement<A, B>;
|
|
1399
|
+
};
|
|
1873
1400
|
/**
|
|
1874
1401
|
* Chains two refinements: if `ab` narrows `A` to `B` and `bc` narrows `B` to `C`,
|
|
1875
1402
|
* the result narrows `A` directly to `C`.
|
|
@@ -1892,7 +1419,7 @@ declare namespace Refinement {
|
|
|
1892
1419
|
* );
|
|
1893
1420
|
* ```
|
|
1894
1421
|
*/
|
|
1895
|
-
|
|
1422
|
+
compose: <A, B extends A, C extends B>(bc: Refinement<B, C>) => (ab: Refinement<A, B>) => Refinement<A, C>;
|
|
1896
1423
|
/**
|
|
1897
1424
|
* Intersects two refinements: the result narrows `A` to `B & C`, passing only
|
|
1898
1425
|
* when both refinements hold simultaneously.
|
|
@@ -1910,7 +1437,7 @@ declare namespace Refinement {
|
|
|
1910
1437
|
* isNonEmptyString(""); // false
|
|
1911
1438
|
* ```
|
|
1912
1439
|
*/
|
|
1913
|
-
|
|
1440
|
+
and: <A, C extends A>(second: Refinement<A, C>) => <B extends A>(first: Refinement<A, B>) => Refinement<A, B & C>;
|
|
1914
1441
|
/**
|
|
1915
1442
|
* Unions two refinements: the result narrows `A` to `B | C`, passing when either
|
|
1916
1443
|
* refinement holds.
|
|
@@ -1928,8 +1455,8 @@ declare namespace Refinement {
|
|
|
1928
1455
|
* isStringOrNumber(true); // false
|
|
1929
1456
|
* ```
|
|
1930
1457
|
*/
|
|
1931
|
-
|
|
1932
|
-
|
|
1458
|
+
or: <A, C extends A>(second: Refinement<A, C>) => <B extends A>(first: Refinement<A, B>) => Refinement<A, B | C>;
|
|
1459
|
+
to: {
|
|
1933
1460
|
/**
|
|
1934
1461
|
* Converts a `Refinement<A, B>` into a function `(a: A) => Maybe<B>`.
|
|
1935
1462
|
*
|
|
@@ -1946,7 +1473,7 @@ declare namespace Refinement {
|
|
|
1946
1473
|
* pipe(42, Refinement.to.Maybe(isPositive)); // Some(42)
|
|
1947
1474
|
* ```
|
|
1948
1475
|
*/
|
|
1949
|
-
|
|
1476
|
+
Maybe: <A, B extends A>(r: Refinement<A, B>) => (a: A) => Maybe<B>;
|
|
1950
1477
|
/**
|
|
1951
1478
|
* Converts a `Refinement<A, B>` into a function `(a: A) => Result<E, B>`.
|
|
1952
1479
|
*
|
|
@@ -1963,9 +1490,9 @@ declare namespace Refinement {
|
|
|
1963
1490
|
* pipe("hi", Refinement.to.Result(isNonEmpty, () => "must not be empty")); // Ok("hi")
|
|
1964
1491
|
* ```
|
|
1965
1492
|
*/
|
|
1966
|
-
|
|
1967
|
-
}
|
|
1968
|
-
}
|
|
1493
|
+
Result: <A, B extends A, E>(r: Refinement<A, B>, onFail: (a: A) => E) => (a: A) => Result<E, B>;
|
|
1494
|
+
};
|
|
1495
|
+
};
|
|
1969
1496
|
|
|
1970
1497
|
type NotAsked = WithKind<"NotAsked">;
|
|
1971
1498
|
type Loading = WithKind<"Loading">;
|
|
@@ -1992,8 +1519,8 @@ type Success<A> = WithKind<"Success"> & WithValue<A>;
|
|
|
1992
1519
|
* ```
|
|
1993
1520
|
*/
|
|
1994
1521
|
type RemoteData<E, A> = NotAsked | Loading | Failure<E> | Success<A>;
|
|
1995
|
-
declare
|
|
1996
|
-
|
|
1522
|
+
declare const RemoteData: {
|
|
1523
|
+
make: {
|
|
1997
1524
|
/**
|
|
1998
1525
|
* Creates a NotAsked RemoteData.
|
|
1999
1526
|
*
|
|
@@ -2002,7 +1529,7 @@ declare namespace RemoteData {
|
|
|
2002
1529
|
* RemoteData.make.notAsked(); // NotAsked
|
|
2003
1530
|
* ```
|
|
2004
1531
|
*/
|
|
2005
|
-
|
|
1532
|
+
notAsked: () => NotAsked;
|
|
2006
1533
|
/**
|
|
2007
1534
|
* Creates a Loading RemoteData.
|
|
2008
1535
|
*
|
|
@@ -2011,7 +1538,7 @@ declare namespace RemoteData {
|
|
|
2011
1538
|
* RemoteData.make.loading(); // Loading
|
|
2012
1539
|
* ```
|
|
2013
1540
|
*/
|
|
2014
|
-
|
|
1541
|
+
loading: () => Loading;
|
|
2015
1542
|
/**
|
|
2016
1543
|
* Creates a Failure RemoteData with the given error.
|
|
2017
1544
|
*
|
|
@@ -2020,7 +1547,7 @@ declare namespace RemoteData {
|
|
|
2020
1547
|
* RemoteData.make.failure("Network error"); // Failure("Network error")
|
|
2021
1548
|
* ```
|
|
2022
1549
|
*/
|
|
2023
|
-
|
|
1550
|
+
failure: <E>(error: E) => Failure<E>;
|
|
2024
1551
|
/**
|
|
2025
1552
|
* Creates a Success RemoteData with the given value.
|
|
2026
1553
|
*
|
|
@@ -2029,9 +1556,9 @@ declare namespace RemoteData {
|
|
|
2029
1556
|
* RemoteData.make.success(42); // Success(42)
|
|
2030
1557
|
* ```
|
|
2031
1558
|
*/
|
|
2032
|
-
|
|
2033
|
-
}
|
|
2034
|
-
|
|
1559
|
+
success: <A>(value: A) => Success<A>;
|
|
1560
|
+
};
|
|
1561
|
+
is: {
|
|
2035
1562
|
/**
|
|
2036
1563
|
* Type guard that checks if a RemoteData is NotAsked.
|
|
2037
1564
|
*
|
|
@@ -2043,7 +1570,7 @@ declare namespace RemoteData {
|
|
|
2043
1570
|
* }
|
|
2044
1571
|
* ```
|
|
2045
1572
|
*/
|
|
2046
|
-
|
|
1573
|
+
notAsked: <E, A>(data: RemoteData<E, A>) => data is NotAsked;
|
|
2047
1574
|
/**
|
|
2048
1575
|
* Type guard that checks if a RemoteData is Loading.
|
|
2049
1576
|
*
|
|
@@ -2055,7 +1582,7 @@ declare namespace RemoteData {
|
|
|
2055
1582
|
* }
|
|
2056
1583
|
* ```
|
|
2057
1584
|
*/
|
|
2058
|
-
|
|
1585
|
+
loading: <E, A>(data: RemoteData<E, A>) => data is Loading;
|
|
2059
1586
|
/**
|
|
2060
1587
|
* Type guard that checks if a RemoteData is Failure.
|
|
2061
1588
|
*
|
|
@@ -2067,7 +1594,7 @@ declare namespace RemoteData {
|
|
|
2067
1594
|
* }
|
|
2068
1595
|
* ```
|
|
2069
1596
|
*/
|
|
2070
|
-
|
|
1597
|
+
failure: <E, A>(data: RemoteData<E, A>) => data is Failure<E>;
|
|
2071
1598
|
/**
|
|
2072
1599
|
* Type guard that checks if a RemoteData is Success.
|
|
2073
1600
|
*
|
|
@@ -2079,8 +1606,8 @@ declare namespace RemoteData {
|
|
|
2079
1606
|
* }
|
|
2080
1607
|
* ```
|
|
2081
1608
|
*/
|
|
2082
|
-
|
|
2083
|
-
}
|
|
1609
|
+
success: <E, A>(data: RemoteData<E, A>) => data is Success<A>;
|
|
1610
|
+
};
|
|
2084
1611
|
/**
|
|
2085
1612
|
* Transforms the success value inside a RemoteData.
|
|
2086
1613
|
*
|
|
@@ -2090,7 +1617,7 @@ declare namespace RemoteData {
|
|
|
2090
1617
|
* pipe(RemoteData.make.loading(), RemoteData.map(n => n * 2)); // Loading
|
|
2091
1618
|
* ```
|
|
2092
1619
|
*/
|
|
2093
|
-
|
|
1620
|
+
map: <A, B>(f: (a: A) => B) => <E>(data: RemoteData<E, A>) => RemoteData<E, B>;
|
|
2094
1621
|
/**
|
|
2095
1622
|
* Transforms the error value inside a RemoteData.
|
|
2096
1623
|
*
|
|
@@ -2099,7 +1626,7 @@ declare namespace RemoteData {
|
|
|
2099
1626
|
* pipe(RemoteData.make.failure("oops"), RemoteData.mapError(e => e.toUpperCase())); // Failure("OOPS")
|
|
2100
1627
|
* ```
|
|
2101
1628
|
*/
|
|
2102
|
-
|
|
1629
|
+
mapError: <E, F>(f: (e: E) => F) => <A>(data: RemoteData<E, A>) => RemoteData<F, A>;
|
|
2103
1630
|
/**
|
|
2104
1631
|
* Chains RemoteData computations. If the input is Success, passes the value to f.
|
|
2105
1632
|
* Otherwise, propagates the current state.
|
|
@@ -2112,7 +1639,7 @@ declare namespace RemoteData {
|
|
|
2112
1639
|
* );
|
|
2113
1640
|
* ```
|
|
2114
1641
|
*/
|
|
2115
|
-
|
|
1642
|
+
chain: <E2, A, B>(f: (a: A) => RemoteData<E2, B>) => <E1 = never>(data: RemoteData<E1, A>) => RemoteData<E1 | E2, B>;
|
|
2116
1643
|
/**
|
|
2117
1644
|
* Applies a function wrapped in a RemoteData to a value wrapped in a RemoteData.
|
|
2118
1645
|
*
|
|
@@ -2126,7 +1653,7 @@ declare namespace RemoteData {
|
|
|
2126
1653
|
* ); // Success(8)
|
|
2127
1654
|
* ```
|
|
2128
1655
|
*/
|
|
2129
|
-
|
|
1656
|
+
ap: <E, A>(arg: RemoteData<E, A>) => <B>(data: RemoteData<E, (a: A) => B>) => RemoteData<E, B>;
|
|
2130
1657
|
/**
|
|
2131
1658
|
* Extracts the value from a RemoteData by providing handlers for all four cases.
|
|
2132
1659
|
*
|
|
@@ -2143,7 +1670,7 @@ declare namespace RemoteData {
|
|
|
2143
1670
|
* );
|
|
2144
1671
|
* ```
|
|
2145
1672
|
*/
|
|
2146
|
-
|
|
1673
|
+
fold: <E, A, B>(onFailure: (e: E) => B, onNotAsked: () => B, onLoading: () => B, onSuccess: (a: A) => B) => (data: RemoteData<E, A>) => B;
|
|
2147
1674
|
/**
|
|
2148
1675
|
* Pattern matches on a RemoteData, returning the result of the matching case.
|
|
2149
1676
|
*
|
|
@@ -2160,7 +1687,7 @@ declare namespace RemoteData {
|
|
|
2160
1687
|
* );
|
|
2161
1688
|
* ```
|
|
2162
1689
|
*/
|
|
2163
|
-
|
|
1690
|
+
match: <E, A, B>(cases: {
|
|
2164
1691
|
notAsked: () => B;
|
|
2165
1692
|
loading: () => B;
|
|
2166
1693
|
failure: (e: E) => B;
|
|
@@ -2177,7 +1704,7 @@ declare namespace RemoteData {
|
|
|
2177
1704
|
* pipe(RemoteData.make.loading<string, number>(), RemoteData.getOrElse(() => null)); // null — typed as number | null
|
|
2178
1705
|
* ```
|
|
2179
1706
|
*/
|
|
2180
|
-
|
|
1707
|
+
getOrElse: <B>(defaultValue: () => B) => <E, A>(data: RemoteData<E, A>) => A | B;
|
|
2181
1708
|
/**
|
|
2182
1709
|
* Executes a side effect on the success value without changing the RemoteData.
|
|
2183
1710
|
*
|
|
@@ -2190,7 +1717,7 @@ declare namespace RemoteData {
|
|
|
2190
1717
|
* );
|
|
2191
1718
|
* ```
|
|
2192
1719
|
*/
|
|
2193
|
-
|
|
1720
|
+
tap: <E, A>(f: (a: A) => void) => (data: RemoteData<E, A>) => RemoteData<E, A>;
|
|
2194
1721
|
/**
|
|
2195
1722
|
* Executes a side effect on the failure error without changing the RemoteData.
|
|
2196
1723
|
* Useful for logging errors.
|
|
@@ -2204,18 +1731,18 @@ declare namespace RemoteData {
|
|
|
2204
1731
|
* );
|
|
2205
1732
|
* ```
|
|
2206
1733
|
*/
|
|
2207
|
-
|
|
1734
|
+
tapError: <E, A>(f: (e: E) => void) => (data: RemoteData<E, A>) => RemoteData<E, A>;
|
|
2208
1735
|
/**
|
|
2209
1736
|
* Recovers from a Failure state by providing a fallback RemoteData.
|
|
2210
1737
|
* The fallback can produce a different success type, widening the result to `RemoteData<E, A | B>`.
|
|
2211
1738
|
*/
|
|
2212
|
-
|
|
2213
|
-
|
|
1739
|
+
recover: <E, B>(fallback: (e: E) => RemoteData<E, B>) => <A>(data: RemoteData<E, A>) => RemoteData<E, A | B>;
|
|
1740
|
+
to: {
|
|
2214
1741
|
/**
|
|
2215
1742
|
* Converts a RemoteData to a Maybe.
|
|
2216
1743
|
* Success becomes Some, all other states become None.
|
|
2217
1744
|
*/
|
|
2218
|
-
|
|
1745
|
+
Maybe: <E, A>(data: RemoteData<E, A>) => Maybe<A>;
|
|
2219
1746
|
/**
|
|
2220
1747
|
* Converts a RemoteData to a Result.
|
|
2221
1748
|
* Success becomes Ok, Failure becomes Err.
|
|
@@ -2229,9 +1756,9 @@ declare namespace RemoteData {
|
|
|
2229
1756
|
* ); // Ok(42)
|
|
2230
1757
|
* ```
|
|
2231
1758
|
*/
|
|
2232
|
-
|
|
2233
|
-
}
|
|
2234
|
-
|
|
1759
|
+
Result: <E>(onNotReady: () => E) => <A>(data: RemoteData<E, A>) => Result<E, A>;
|
|
1760
|
+
};
|
|
1761
|
+
from: {
|
|
2235
1762
|
/**
|
|
2236
1763
|
* Converts a Result to a RemoteData.
|
|
2237
1764
|
* Ok becomes Success, Err becomes Failure.
|
|
@@ -2242,7 +1769,7 @@ declare namespace RemoteData {
|
|
|
2242
1769
|
* setState(RemoteData.from.Result(result)); // Success(user) or Failure(msg)
|
|
2243
1770
|
* ```
|
|
2244
1771
|
*/
|
|
2245
|
-
|
|
1772
|
+
Result: <E, A>(data: Result<E, A>) => RemoteData<E, A>;
|
|
2246
1773
|
/**
|
|
2247
1774
|
* Converts a Maybe to a RemoteData.
|
|
2248
1775
|
* Some becomes Success, None becomes Failure using the onNone error producer.
|
|
@@ -2253,8 +1780,8 @@ declare namespace RemoteData {
|
|
|
2253
1780
|
* pipe(Maybe.make.none(), RemoteData.from.Maybe(() => "not found")); // Failure("not found")
|
|
2254
1781
|
* ```
|
|
2255
1782
|
*/
|
|
2256
|
-
|
|
2257
|
-
}
|
|
1783
|
+
Maybe: <E>(onNone: () => E) => <A>(data: Maybe<A>) => RemoteData<E, A>;
|
|
1784
|
+
};
|
|
2258
1785
|
/**
|
|
2259
1786
|
* Filters a `Success` value. When the predicate passes, the value is kept. When it fails,
|
|
2260
1787
|
* `Success` becomes `Failure` using the error produced by `onFalse`. All other states pass through unchanged.
|
|
@@ -2268,8 +1795,8 @@ declare namespace RemoteData {
|
|
|
2268
1795
|
* RemoteData.filter(n => n > 0, () => "error")(RemoteData.make.loading()); // Loading
|
|
2269
1796
|
* ```
|
|
2270
1797
|
*/
|
|
2271
|
-
|
|
2272
|
-
}
|
|
1798
|
+
filter: <E, A>(pred: (a: A) => boolean, onFalse: (a: A) => E) => (data: RemoteData<E, A>) => RemoteData<E, A>;
|
|
1799
|
+
};
|
|
2273
1800
|
|
|
2274
1801
|
/**
|
|
2275
1802
|
* A Resource pairs an async acquisition step with a guaranteed cleanup step.
|
|
@@ -2303,8 +1830,8 @@ type Resource<E, A> = {
|
|
|
2303
1830
|
readonly acquire: Task.Result<E, A>;
|
|
2304
1831
|
readonly release: (a: A) => Task<void>;
|
|
2305
1832
|
};
|
|
2306
|
-
declare
|
|
2307
|
-
|
|
1833
|
+
declare const Resource: {
|
|
1834
|
+
from: {
|
|
2308
1835
|
/**
|
|
2309
1836
|
* Creates a Resource from an acquire operation that may fail and a release function.
|
|
2310
1837
|
*
|
|
@@ -2316,7 +1843,7 @@ declare namespace Resource {
|
|
|
2316
1843
|
* );
|
|
2317
1844
|
* ```
|
|
2318
1845
|
*/
|
|
2319
|
-
|
|
1846
|
+
handlers: <E, A>(acquire: Task.Result<E, A>, release: (a: A) => Task<void>) => Resource<E, A>;
|
|
2320
1847
|
/**
|
|
2321
1848
|
* Creates a Resource from an acquire operation that cannot fail.
|
|
2322
1849
|
* Use this when opening the resource is guaranteed to succeed, such as
|
|
@@ -2330,8 +1857,8 @@ declare namespace Resource {
|
|
|
2330
1857
|
* );
|
|
2331
1858
|
* ```
|
|
2332
1859
|
*/
|
|
2333
|
-
|
|
2334
|
-
}
|
|
1860
|
+
Task: <E, A>(acquire: Task<A>, release: (a: A) => Task<void>) => Resource<E, A>;
|
|
1861
|
+
};
|
|
2335
1862
|
/**
|
|
2336
1863
|
* Acquires the resource, runs `f` with it, then releases it.
|
|
2337
1864
|
*
|
|
@@ -2347,7 +1874,7 @@ declare namespace Resource {
|
|
|
2347
1874
|
* // conn is closed whether the query succeeds or fails
|
|
2348
1875
|
* ```
|
|
2349
1876
|
*/
|
|
2350
|
-
|
|
1877
|
+
use: <E, A, B>(f: (a: A) => Task.Result<E, B>) => (resource: Resource<E, A>) => Task.Result<E, B>;
|
|
2351
1878
|
/**
|
|
2352
1879
|
* Acquires two resources in sequence and presents them as a tuple.
|
|
2353
1880
|
* Resources are released in reverse order: the second is released before the first.
|
|
@@ -2365,8 +1892,8 @@ declare namespace Resource {
|
|
|
2365
1892
|
* )();
|
|
2366
1893
|
* ```
|
|
2367
1894
|
*/
|
|
2368
|
-
|
|
2369
|
-
}
|
|
1895
|
+
combine: <E, A, B>(resourceA: Resource<E, A>, resourceB: Resource<E, B>) => Resource<E, readonly [A, B]>;
|
|
1896
|
+
};
|
|
2370
1897
|
|
|
2371
1898
|
/**
|
|
2372
1899
|
* A synchronous computation that threads a piece of mutable state `S` through
|
|
@@ -2393,7 +1920,7 @@ declare namespace Resource {
|
|
|
2393
1920
|
* ```
|
|
2394
1921
|
*/
|
|
2395
1922
|
type State<S, A> = (s: S) => readonly [A, S];
|
|
2396
|
-
declare
|
|
1923
|
+
declare const State: {
|
|
2397
1924
|
/**
|
|
2398
1925
|
* Lifts a pure value into a State computation. The state passes through unchanged.
|
|
2399
1926
|
*
|
|
@@ -2402,7 +1929,7 @@ declare namespace State {
|
|
|
2402
1929
|
* State.run(10)(State.resolve(42)); // [42, 10] — value 42, state unchanged
|
|
2403
1930
|
* ```
|
|
2404
1931
|
*/
|
|
2405
|
-
|
|
1932
|
+
resolve: <S, A>(value: A) => State<S, A>;
|
|
2406
1933
|
/**
|
|
2407
1934
|
* Produces the current state as the value, without modifying it.
|
|
2408
1935
|
*
|
|
@@ -2412,7 +1939,7 @@ declare namespace State {
|
|
|
2412
1939
|
* State.run(["a", "b"])(readStack); // [["a", "b"], ["a", "b"]]
|
|
2413
1940
|
* ```
|
|
2414
1941
|
*/
|
|
2415
|
-
|
|
1942
|
+
get: <S>() => State<S, S>;
|
|
2416
1943
|
/**
|
|
2417
1944
|
* Reads a projection of the state without modifying it.
|
|
2418
1945
|
* Equivalent to `pipe(State.get(), State.map(f))` but more direct.
|
|
@@ -2424,7 +1951,7 @@ declare namespace State {
|
|
|
2424
1951
|
* State.run({ count: 5, label: "x" })(readCount); // [5, { count: 5, label: "x" }]
|
|
2425
1952
|
* ```
|
|
2426
1953
|
*/
|
|
2427
|
-
|
|
1954
|
+
gets: <S, A>(f: (s: S) => A) => State<S, A>;
|
|
2428
1955
|
/**
|
|
2429
1956
|
* Replaces the current state with a new value. Produces no meaningful value.
|
|
2430
1957
|
*
|
|
@@ -2434,7 +1961,7 @@ declare namespace State {
|
|
|
2434
1961
|
* State.run(99)(reset); // [undefined, 0]
|
|
2435
1962
|
* ```
|
|
2436
1963
|
*/
|
|
2437
|
-
|
|
1964
|
+
put: <S>(newState: S) => State<S, undefined>;
|
|
2438
1965
|
/**
|
|
2439
1966
|
* Applies a function to the current state to produce the next state.
|
|
2440
1967
|
* Produces no meaningful value.
|
|
@@ -2447,7 +1974,7 @@ declare namespace State {
|
|
|
2447
1974
|
* State.run(["a"])(push("b")); // [undefined, ["a", "b"]]
|
|
2448
1975
|
* ```
|
|
2449
1976
|
*/
|
|
2450
|
-
|
|
1977
|
+
modify: <S>(f: (s: S) => S) => State<S, undefined>;
|
|
2451
1978
|
/**
|
|
2452
1979
|
* Transforms the value produced by a State computation.
|
|
2453
1980
|
* The state transformation is unchanged.
|
|
@@ -2462,7 +1989,7 @@ declare namespace State {
|
|
|
2462
1989
|
* State.run(["a", "b", "c"])(readLength); // [3, ["a", "b", "c"]]
|
|
2463
1990
|
* ```
|
|
2464
1991
|
*/
|
|
2465
|
-
|
|
1992
|
+
map: <S, A, B>(f: (a: A) => B) => (st: State<S, A>) => State<S, B>;
|
|
2466
1993
|
/**
|
|
2467
1994
|
* Sequences two State computations. The state output of the first is passed
|
|
2468
1995
|
* as the state input to the second.
|
|
@@ -2483,7 +2010,7 @@ declare namespace State {
|
|
|
2483
2010
|
* State.evaluate([])(program); // ["a", "b"]
|
|
2484
2011
|
* ```
|
|
2485
2012
|
*/
|
|
2486
|
-
|
|
2013
|
+
chain: <S, A, B>(f: (a: A) => State<S, B>) => (st: State<S, A>) => State<S, B>;
|
|
2487
2014
|
/**
|
|
2488
2015
|
* Applies a function wrapped in a State to a value wrapped in a State.
|
|
2489
2016
|
* The function computation runs first; its output state is the input to the
|
|
@@ -2501,7 +2028,7 @@ declare namespace State {
|
|
|
2501
2028
|
* State.evaluate(3)(program); // 6 + 3 = 9
|
|
2502
2029
|
* ```
|
|
2503
2030
|
*/
|
|
2504
|
-
|
|
2031
|
+
ap: <S, A>(arg: State<S, A>) => <B>(fn: State<S, (a: A) => B>) => State<S, B>;
|
|
2505
2032
|
/**
|
|
2506
2033
|
* Runs a side effect on the produced value without changing the State computation.
|
|
2507
2034
|
*
|
|
@@ -2514,7 +2041,7 @@ declare namespace State {
|
|
|
2514
2041
|
* );
|
|
2515
2042
|
* ```
|
|
2516
2043
|
*/
|
|
2517
|
-
|
|
2044
|
+
tap: <S, A>(f: (a: A) => void) => (st: State<S, A>) => State<S, A>;
|
|
2518
2045
|
/**
|
|
2519
2046
|
* Runs a State computation with an initial state, returning both the
|
|
2520
2047
|
* produced value and the final state as a pair.
|
|
@@ -2531,7 +2058,7 @@ declare namespace State {
|
|
|
2531
2058
|
* State.run(0)(program); // [1, 1]
|
|
2532
2059
|
* ```
|
|
2533
2060
|
*/
|
|
2534
|
-
|
|
2061
|
+
run: <S>(initialState: S) => <A>(st: State<S, A>) => readonly [A, S];
|
|
2535
2062
|
/**
|
|
2536
2063
|
* Runs a State computation with an initial state, returning only the
|
|
2537
2064
|
* produced value (discarding the final state).
|
|
@@ -2544,7 +2071,7 @@ declare namespace State {
|
|
|
2544
2071
|
* )); // ["x"]
|
|
2545
2072
|
* ```
|
|
2546
2073
|
*/
|
|
2547
|
-
|
|
2074
|
+
evaluate: <S>(initialState: S) => <A>(st: State<S, A>) => A;
|
|
2548
2075
|
/**
|
|
2549
2076
|
* Runs a State computation with an initial state, returning only the
|
|
2550
2077
|
* final state (discarding the produced value).
|
|
@@ -2557,7 +2084,7 @@ declare namespace State {
|
|
|
2557
2084
|
* )); // 20
|
|
2558
2085
|
* ```
|
|
2559
2086
|
*/
|
|
2560
|
-
|
|
2087
|
+
execute: <S>(initialState: S) => <A>(st: State<S, A>) => S;
|
|
2561
2088
|
/**
|
|
2562
2089
|
* Lifts a State value into an accumulator object.
|
|
2563
2090
|
*
|
|
@@ -2566,7 +2093,7 @@ declare namespace State {
|
|
|
2566
2093
|
* pipe(State.resolve(42), State.bindTo("value")); // State({ value: 42 })
|
|
2567
2094
|
* ```
|
|
2568
2095
|
*/
|
|
2569
|
-
|
|
2096
|
+
bindTo: <K extends string>(key: K) => <S, A>(data: State<S, A>) => State<S, { [P in K]: A; }>;
|
|
2570
2097
|
/**
|
|
2571
2098
|
* Evaluates a new State using the current accumulator and attaches the output to a new key.
|
|
2572
2099
|
*
|
|
@@ -2578,7 +2105,7 @@ declare namespace State {
|
|
|
2578
2105
|
* ); // State({ a: 1, b: 2 })
|
|
2579
2106
|
* ```
|
|
2580
2107
|
*/
|
|
2581
|
-
|
|
2108
|
+
bind: <K extends string, S, A, B>(key: K, f: (a: A) => State<S, B>) => (data: State<S, A>) => State<S, A & { [P in K]: B; }>;
|
|
2582
2109
|
/**
|
|
2583
2110
|
* Focuses a State computation on a sub-state using a Lens.
|
|
2584
2111
|
*
|
|
@@ -2590,8 +2117,8 @@ declare namespace State {
|
|
|
2590
2117
|
* const focusedProgram = pipe(increment, State.focus(countLens));
|
|
2591
2118
|
* ```
|
|
2592
2119
|
*/
|
|
2593
|
-
|
|
2594
|
-
}
|
|
2120
|
+
focus: <S, A>(lens: Lens<S, A>) => <B>(stateOp: State<A, B>) => State<S, B>;
|
|
2121
|
+
};
|
|
2595
2122
|
|
|
2596
2123
|
/**
|
|
2597
2124
|
* An event stream pipeline for a typed message schema `S`.
|
|
@@ -2644,63 +2171,7 @@ type Stream<S extends Record<string, unknown>> = {
|
|
|
2644
2171
|
/** @internal */
|
|
2645
2172
|
_isEmitting: boolean;
|
|
2646
2173
|
};
|
|
2647
|
-
declare
|
|
2648
|
-
/**
|
|
2649
|
-
* Message payload emitted across a Stream.
|
|
2650
|
-
*/
|
|
2651
|
-
type Message<S extends Record<string, unknown>> = {
|
|
2652
|
-
[K in keyof S & string]: WithKind<K> & WithValue<S[K]>;
|
|
2653
|
-
}[keyof S & string];
|
|
2654
|
-
/**
|
|
2655
|
-
* Options for constructing a `Stream` instance.
|
|
2656
|
-
*/
|
|
2657
|
-
type Options = {
|
|
2658
|
-
readonly name?: string;
|
|
2659
|
-
readonly onError?: (error: unknown) => void;
|
|
2660
|
-
};
|
|
2661
|
-
/**
|
|
2662
|
-
* Options for sequence matching and listener execution.
|
|
2663
|
-
*/
|
|
2664
|
-
type SequenceOptions<S extends Record<string, unknown>> = {
|
|
2665
|
-
/** Match events in exact array sequence order (default: false). */
|
|
2666
|
-
readonly ordered?: boolean;
|
|
2667
|
-
/** Match sequence strictly consecutively without intermediary events (default: false). */
|
|
2668
|
-
readonly strict?: boolean;
|
|
2669
|
-
/** Automatically unsubscribe after the first match/cycle completes (default: false). */
|
|
2670
|
-
readonly once?: boolean;
|
|
2671
|
-
/** Event kind(s) that reset sequence tracking to index 0. */
|
|
2672
|
-
readonly reset?: (keyof S & string) | ReadonlyArray<keyof S & string>;
|
|
2673
|
-
/** Event kind(s) in the sequence that may be present or skipped. */
|
|
2674
|
-
readonly optional?: (keyof S & string) | ReadonlyArray<keyof S & string>;
|
|
2675
|
-
};
|
|
2676
|
-
/**
|
|
2677
|
-
* Handle for an active stateful subscription.
|
|
2678
|
-
*/
|
|
2679
|
-
type Subscription<State> = {
|
|
2680
|
-
readonly unsubscribe: () => void;
|
|
2681
|
-
readonly getState: () => State;
|
|
2682
|
-
};
|
|
2683
|
-
/**
|
|
2684
|
-
* Options for structural stream forwarding.
|
|
2685
|
-
*/
|
|
2686
|
-
type ForwardOptions<S extends Record<string, unknown>> = {
|
|
2687
|
-
readonly from: Stream<S>;
|
|
2688
|
-
readonly to: Stream<S> | ReadonlyArray<Stream<S>>;
|
|
2689
|
-
readonly only?: ReadonlyArray<keyof S & string>;
|
|
2690
|
-
};
|
|
2691
|
-
/**
|
|
2692
|
-
* Builder handle returned by `Stream.listen`.
|
|
2693
|
-
*/
|
|
2694
|
-
type ListenerBuilder<S extends Record<string, unknown>> = {
|
|
2695
|
-
/**
|
|
2696
|
-
* Stateful reduction over events/sequences.
|
|
2697
|
-
*/
|
|
2698
|
-
readonly reduce: <State>(reducer: (msg: Message<S>, state: State) => State, initialState: State) => Subscription<State>;
|
|
2699
|
-
/**
|
|
2700
|
-
* Stateless side-effect execution.
|
|
2701
|
-
*/
|
|
2702
|
-
readonly tap: (effect: (msg: Message<S>) => void) => () => void;
|
|
2703
|
-
};
|
|
2174
|
+
declare const Stream: {
|
|
2704
2175
|
/**
|
|
2705
2176
|
* Constructs a new `Stream` instance.
|
|
2706
2177
|
*
|
|
@@ -2709,7 +2180,7 @@ declare namespace Stream {
|
|
|
2709
2180
|
* const stream = Stream.make<AppMessages>({ name: "app" });
|
|
2710
2181
|
* ```
|
|
2711
2182
|
*/
|
|
2712
|
-
|
|
2183
|
+
make: <S extends Record<string, unknown>>(options?: Stream.Options) => Stream<S>;
|
|
2713
2184
|
/**
|
|
2714
2185
|
* Emits a message payload to one or more target streams.
|
|
2715
2186
|
*
|
|
@@ -2728,7 +2199,7 @@ declare namespace Stream {
|
|
|
2728
2199
|
* });
|
|
2729
2200
|
* ```
|
|
2730
2201
|
*/
|
|
2731
|
-
|
|
2202
|
+
emit: <S extends Record<string, unknown>, K extends keyof S & string>(target: Stream<S> | ReadonlyArray<Stream<S>>, message: WithKind<K> & WithValue<S[K]>) => void;
|
|
2732
2203
|
/**
|
|
2733
2204
|
* Forwards messages from one stream to another (or multiple).
|
|
2734
2205
|
*
|
|
@@ -2741,7 +2212,7 @@ declare namespace Stream {
|
|
|
2741
2212
|
* });
|
|
2742
2213
|
* ```
|
|
2743
2214
|
*/
|
|
2744
|
-
|
|
2215
|
+
forward: <S extends Record<string, unknown>>(options: Stream.ForwardOptions<S>) => () => void;
|
|
2745
2216
|
/**
|
|
2746
2217
|
* Initiates listener registration on a stream for specific event kind(s) or sequence.
|
|
2747
2218
|
*
|
|
@@ -2757,7 +2228,36 @@ declare namespace Stream {
|
|
|
2757
2228
|
* );
|
|
2758
2229
|
* ```
|
|
2759
2230
|
*/
|
|
2760
|
-
|
|
2231
|
+
listen: <S extends Record<string, unknown>, K extends keyof S & string>(stream: Stream<S>, events: K | ReadonlyArray<K>, options?: Stream.SequenceOptions<S>) => Stream.ListenerBuilder<S>;
|
|
2232
|
+
};
|
|
2233
|
+
declare namespace Stream {
|
|
2234
|
+
type Message<S extends Record<string, unknown>> = {
|
|
2235
|
+
[K in keyof S & string]: WithKind<K> & WithValue<S[K]>;
|
|
2236
|
+
}[keyof S & string];
|
|
2237
|
+
type Options = {
|
|
2238
|
+
readonly name?: string;
|
|
2239
|
+
readonly onError?: (error: unknown) => void;
|
|
2240
|
+
};
|
|
2241
|
+
type SequenceOptions<S extends Record<string, unknown>> = {
|
|
2242
|
+
readonly ordered?: boolean;
|
|
2243
|
+
readonly strict?: boolean;
|
|
2244
|
+
readonly once?: boolean;
|
|
2245
|
+
readonly reset?: (keyof S & string) | ReadonlyArray<keyof S & string>;
|
|
2246
|
+
readonly optional?: (keyof S & string) | ReadonlyArray<keyof S & string>;
|
|
2247
|
+
};
|
|
2248
|
+
type Subscription<State> = {
|
|
2249
|
+
readonly unsubscribe: () => void;
|
|
2250
|
+
readonly getState: () => State;
|
|
2251
|
+
};
|
|
2252
|
+
type ForwardOptions<S extends Record<string, unknown>> = {
|
|
2253
|
+
readonly from: Stream<S>;
|
|
2254
|
+
readonly to: Stream<S> | ReadonlyArray<Stream<S>>;
|
|
2255
|
+
readonly only?: ReadonlyArray<keyof S & string>;
|
|
2256
|
+
};
|
|
2257
|
+
type ListenerBuilder<S extends Record<string, unknown>> = {
|
|
2258
|
+
readonly reduce: <State>(reducer: (msg: Message<S>, state: State) => State, initialState: State) => Subscription<State>;
|
|
2259
|
+
readonly tap: (effect: (msg: Message<S>) => void) => () => void;
|
|
2260
|
+
};
|
|
2761
2261
|
}
|
|
2762
2262
|
|
|
2763
2263
|
type TheseFirst<T> = WithKind<"First"> & WithFirst<T>;
|
|
@@ -2787,8 +2287,8 @@ type TheseBoth<First, Second> = WithKind<"Both"> & WithFirst<First> & WithSecond
|
|
|
2787
2287
|
* ```
|
|
2788
2288
|
*/
|
|
2789
2289
|
type These<A, B> = TheseFirst<A> | TheseSecond<B> | TheseBoth<A, B>;
|
|
2790
|
-
declare
|
|
2791
|
-
|
|
2290
|
+
declare const These: {
|
|
2291
|
+
make: {
|
|
2792
2292
|
/**
|
|
2793
2293
|
* Creates a These holding only a first value.
|
|
2794
2294
|
*
|
|
@@ -2797,7 +2297,7 @@ declare namespace These {
|
|
|
2797
2297
|
* These.make.first(42); // { kind: "First", first: 42 }
|
|
2798
2298
|
* ```
|
|
2799
2299
|
*/
|
|
2800
|
-
|
|
2300
|
+
first: <A>(value: A) => TheseFirst<A>;
|
|
2801
2301
|
/**
|
|
2802
2302
|
* Creates a These holding only a second value.
|
|
2803
2303
|
*
|
|
@@ -2806,7 +2306,7 @@ declare namespace These {
|
|
|
2806
2306
|
* These.make.second("warning"); // { kind: "Second", second: "warning" }
|
|
2807
2307
|
* ```
|
|
2808
2308
|
*/
|
|
2809
|
-
|
|
2309
|
+
second: <B>(value: B) => TheseSecond<B>;
|
|
2810
2310
|
/**
|
|
2811
2311
|
* Creates a These holding both a first and a second value simultaneously.
|
|
2812
2312
|
*
|
|
@@ -2815,9 +2315,9 @@ declare namespace These {
|
|
|
2815
2315
|
* These.make.both(42, "Deprecated API used"); // { kind: "Both", first: 42, second: "Deprecated API used" }
|
|
2816
2316
|
* ```
|
|
2817
2317
|
*/
|
|
2818
|
-
|
|
2819
|
-
}
|
|
2820
|
-
|
|
2318
|
+
both: <A, B>(f: A, s: B) => TheseBoth<A, B>;
|
|
2319
|
+
};
|
|
2320
|
+
is: {
|
|
2821
2321
|
/**
|
|
2822
2322
|
* Type guard — checks if a These holds only a first value.
|
|
2823
2323
|
*
|
|
@@ -2829,7 +2329,7 @@ declare namespace These {
|
|
|
2829
2329
|
* }
|
|
2830
2330
|
* ```
|
|
2831
2331
|
*/
|
|
2832
|
-
|
|
2332
|
+
first: <A, B>(data: These<A, B>) => data is TheseFirst<A>;
|
|
2833
2333
|
/**
|
|
2834
2334
|
* Type guard — checks if a These holds only a second value.
|
|
2835
2335
|
*
|
|
@@ -2841,7 +2341,7 @@ declare namespace These {
|
|
|
2841
2341
|
* }
|
|
2842
2342
|
* ```
|
|
2843
2343
|
*/
|
|
2844
|
-
|
|
2344
|
+
second: <A, B>(data: These<A, B>) => data is TheseSecond<B>;
|
|
2845
2345
|
/**
|
|
2846
2346
|
* Type guard — checks if a These holds both values simultaneously.
|
|
2847
2347
|
*
|
|
@@ -2853,8 +2353,8 @@ declare namespace These {
|
|
|
2853
2353
|
* }
|
|
2854
2354
|
* ```
|
|
2855
2355
|
*/
|
|
2856
|
-
|
|
2857
|
-
}
|
|
2356
|
+
both: <A, B>(data: These<A, B>) => data is TheseBoth<A, B>;
|
|
2357
|
+
};
|
|
2858
2358
|
/**
|
|
2859
2359
|
* Returns true if the These contains a first value (First or Both).
|
|
2860
2360
|
*
|
|
@@ -2865,7 +2365,7 @@ declare namespace These {
|
|
|
2865
2365
|
* These.hasFirst(These.make.second("warn")); // false
|
|
2866
2366
|
* ```
|
|
2867
2367
|
*/
|
|
2868
|
-
|
|
2368
|
+
hasFirst: <A, B>(data: These<A, B>) => data is TheseFirst<A> | TheseBoth<A, B>;
|
|
2869
2369
|
/**
|
|
2870
2370
|
* Returns true if the These contains a second value (Second or Both).
|
|
2871
2371
|
*
|
|
@@ -2876,7 +2376,7 @@ declare namespace These {
|
|
|
2876
2376
|
* These.hasSecond(These.make.first(42)); // false
|
|
2877
2377
|
* ```
|
|
2878
2378
|
*/
|
|
2879
|
-
|
|
2379
|
+
hasSecond: <A, B>(data: These<A, B>) => data is TheseSecond<B> | TheseBoth<A, B>;
|
|
2880
2380
|
/**
|
|
2881
2381
|
* Transforms the first value, leaving the second unchanged.
|
|
2882
2382
|
*
|
|
@@ -2887,7 +2387,7 @@ declare namespace These {
|
|
|
2887
2387
|
* pipe(These.make.second("warn"), These.mapFirst(n => n * 2)); // Second("warn")
|
|
2888
2388
|
* ```
|
|
2889
2389
|
*/
|
|
2890
|
-
|
|
2390
|
+
mapFirst: <A, C>(f: (a: A) => C) => <B>(data: These<A, B>) => These<C, B>;
|
|
2891
2391
|
/**
|
|
2892
2392
|
* Transforms the second value, leaving the first unchanged.
|
|
2893
2393
|
*
|
|
@@ -2897,7 +2397,7 @@ declare namespace These {
|
|
|
2897
2397
|
* pipe(These.make.both(5, "warn"), These.mapSecond(e => e.toUpperCase())); // Both(5, "WARN")
|
|
2898
2398
|
* ```
|
|
2899
2399
|
*/
|
|
2900
|
-
|
|
2400
|
+
mapSecond: <B, D>(f: (b: B) => D) => <A>(data: These<A, B>) => These<A, D>;
|
|
2901
2401
|
/**
|
|
2902
2402
|
* Transforms both the first and second values independently.
|
|
2903
2403
|
*
|
|
@@ -2909,7 +2409,7 @@ declare namespace These {
|
|
|
2909
2409
|
* ); // Both(10, "WARN")
|
|
2910
2410
|
* ```
|
|
2911
2411
|
*/
|
|
2912
|
-
|
|
2412
|
+
mapBoth: <A, C, B, D>(onFirst: (a: A) => C, onSecond: (b: B) => D) => (data: These<A, B>) => These<C, D>;
|
|
2913
2413
|
/**
|
|
2914
2414
|
* Chains These computations by passing the first value to f.
|
|
2915
2415
|
* Second propagates unchanged; First and Both apply f to the first value.
|
|
@@ -2923,7 +2423,7 @@ declare namespace These {
|
|
|
2923
2423
|
* pipe(These.make.second("warn"), These.chainFirst(double)); // Second("warn")
|
|
2924
2424
|
* ```
|
|
2925
2425
|
*/
|
|
2926
|
-
|
|
2426
|
+
chainFirst: <A, B, C>(f: (a: A) => These<C, B>) => (data: These<A, B>) => These<C, B>;
|
|
2927
2427
|
/**
|
|
2928
2428
|
* Chains These computations by passing the second value to f.
|
|
2929
2429
|
* First propagates unchanged; Second and Both apply f to the second value.
|
|
@@ -2937,7 +2437,7 @@ declare namespace These {
|
|
|
2937
2437
|
* pipe(These.make.first(5), These.chainSecond(shout)); // First(5)
|
|
2938
2438
|
* ```
|
|
2939
2439
|
*/
|
|
2940
|
-
|
|
2440
|
+
chainSecond: <A, B, D>(f: (b: B) => These<A, D>) => (data: These<A, B>) => These<A, D>;
|
|
2941
2441
|
/**
|
|
2942
2442
|
* Extracts a value from a These by providing handlers for all three cases.
|
|
2943
2443
|
*
|
|
@@ -2953,7 +2453,7 @@ declare namespace These {
|
|
|
2953
2453
|
* );
|
|
2954
2454
|
* ```
|
|
2955
2455
|
*/
|
|
2956
|
-
|
|
2456
|
+
fold: <A, B, C>(onFirst: (a: A) => C, onSecond: (b: B) => C, onBoth: (a: A, b: B) => C) => (data: These<A, B>) => C;
|
|
2957
2457
|
/**
|
|
2958
2458
|
* Pattern matches on a These, returning the result of the matching case.
|
|
2959
2459
|
*
|
|
@@ -2969,7 +2469,7 @@ declare namespace These {
|
|
|
2969
2469
|
* );
|
|
2970
2470
|
* ```
|
|
2971
2471
|
*/
|
|
2972
|
-
|
|
2472
|
+
match: <A, B, C>(cases: {
|
|
2973
2473
|
first: (a: A) => C;
|
|
2974
2474
|
second: (b: B) => C;
|
|
2975
2475
|
both: (a: A, b: B) => C;
|
|
@@ -2986,7 +2486,7 @@ declare namespace These {
|
|
|
2986
2486
|
* pipe(These.make.second("warn"), These.getFirstOrElse(() => null)); // null — typed as number | null
|
|
2987
2487
|
* ```
|
|
2988
2488
|
*/
|
|
2989
|
-
|
|
2489
|
+
getFirstOrElse: <A, C>(defaultValue: () => C) => <B>(data: These<A, B>) => A | C;
|
|
2990
2490
|
/**
|
|
2991
2491
|
* Returns the second value, or a default if the These has no second value.
|
|
2992
2492
|
* The default can be a different type, widening the result to `B | D`.
|
|
@@ -2999,7 +2499,7 @@ declare namespace These {
|
|
|
2999
2499
|
* pipe(These.make.first(5), These.getSecondOrElse(() => null)); // null — typed as string | null
|
|
3000
2500
|
* ```
|
|
3001
2501
|
*/
|
|
3002
|
-
|
|
2502
|
+
getSecondOrElse: <B, D>(defaultValue: () => D) => <A>(data: These<A, B>) => B | D;
|
|
3003
2503
|
/**
|
|
3004
2504
|
* Runs a side effect on the first value without changing the These.
|
|
3005
2505
|
* Useful for logging or debugging.
|
|
@@ -3009,7 +2509,7 @@ declare namespace These {
|
|
|
3009
2509
|
* pipe(These.make.first(5), These.tap(console.log)); // logs 5, returns First(5)
|
|
3010
2510
|
* ```
|
|
3011
2511
|
*/
|
|
3012
|
-
|
|
2512
|
+
tap: <A>(f: (a: A) => void) => <B>(data: These<A, B>) => These<A, B>;
|
|
3013
2513
|
/**
|
|
3014
2514
|
* Swaps the roles of first and second values.
|
|
3015
2515
|
* - First(a) → Second(a)
|
|
@@ -3023,7 +2523,7 @@ declare namespace These {
|
|
|
3023
2523
|
* These.swap(These.make.both(5, "warn")); // Both("warn", 5)
|
|
3024
2524
|
* ```
|
|
3025
2525
|
*/
|
|
3026
|
-
|
|
3027
|
-
}
|
|
2526
|
+
swap: <A, B>(data: These<A, B>) => These<B, A>;
|
|
2527
|
+
};
|
|
3028
2528
|
|
|
3029
2529
|
export { Combinable, Deferred, type Failure, Lazy, Lens, type Loading, Logged, Maybe, type NotAsked, Op, Optional, Pair, Predicate, Reader, Refinement, RemoteData, Resource, Result, State, Stream, type Success, Task, These, type TheseBoth, type TheseFirst, type TheseSecond };
|