@nlozgachev/pipelined 0.27.0 → 0.29.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 +157 -35
- package/dist/{Task-vQb3-puQ.d.mts → Task-BDcKwFAj.d.mts} +52 -30
- package/dist/{Task-C8Pgm7EX.d.ts → Task-CnF22Q2o.d.ts} +52 -30
- package/dist/{chunk-SBTMTAZF.mjs → chunk-FWYOEWJ2.mjs} +12 -4
- package/dist/{chunk-YYVONF5X.mjs → chunk-PV7JOUKL.mjs} +127 -39
- package/dist/{chunk-HHCRWQYN.mjs → chunk-SDGDJ7CU.mjs} +25 -20
- package/dist/core.d.mts +305 -72
- package/dist/core.d.ts +305 -72
- package/dist/core.js +151 -58
- package/dist/core.mjs +2 -2
- package/dist/index.d.mts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +162 -61
- package/dist/index.mjs +3 -3
- package/dist/utils.d.mts +28 -10
- package/dist/utils.d.ts +28 -10
- package/dist/utils.js +36 -23
- package/dist/utils.mjs +2 -2
- package/package.json +3 -3
|
@@ -107,15 +107,15 @@ type WithMinInterval = {
|
|
|
107
107
|
};
|
|
108
108
|
|
|
109
109
|
type Ok<A> = WithKind<"Ok"> & WithValue<A>;
|
|
110
|
-
type
|
|
110
|
+
type Error<E> = WithKind<"Error"> & WithError<E>;
|
|
111
111
|
/**
|
|
112
|
-
* Result represents a value that can be one of two types: a success (Ok) or a failure (
|
|
112
|
+
* Result represents a value that can be one of two types: a success (Ok) or a failure (Error).
|
|
113
113
|
* Use Result when an operation can fail with a meaningful error value.
|
|
114
114
|
*
|
|
115
115
|
* @example
|
|
116
116
|
* ```ts
|
|
117
117
|
* const divide = (a: number, b: number): Result<string, number> =>
|
|
118
|
-
* b === 0 ? Result.
|
|
118
|
+
* b === 0 ? Result.error("Division by zero") : Result.ok(a / b);
|
|
119
119
|
*
|
|
120
120
|
* pipe(
|
|
121
121
|
* divide(10, 2),
|
|
@@ -124,7 +124,7 @@ type Err<E> = WithKind<"Error"> & WithError<E>;
|
|
|
124
124
|
* ); // 10
|
|
125
125
|
* ```
|
|
126
126
|
*/
|
|
127
|
-
type Result<E, A> = Ok<A> |
|
|
127
|
+
type Result<E, A> = Ok<A> | Error<E>;
|
|
128
128
|
declare namespace Result {
|
|
129
129
|
/**
|
|
130
130
|
* Creates a successful Result with the given value.
|
|
@@ -133,15 +133,15 @@ declare namespace Result {
|
|
|
133
133
|
/**
|
|
134
134
|
* Creates a failed Result with the given error.
|
|
135
135
|
*/
|
|
136
|
-
const
|
|
136
|
+
const error: <E>(e: E) => Error<E>;
|
|
137
137
|
/**
|
|
138
138
|
* Type guard that checks if an Result is Ok.
|
|
139
139
|
*/
|
|
140
140
|
const isOk: <E, A>(data: Result<E, A>) => data is Ok<A>;
|
|
141
141
|
/**
|
|
142
|
-
* Type guard that checks if an Result is
|
|
142
|
+
* Type guard that checks if an Result is Error.
|
|
143
143
|
*/
|
|
144
|
-
const
|
|
144
|
+
const isError: <E, A>(data: Result<E, A>) => data is Error<E>;
|
|
145
145
|
/**
|
|
146
146
|
* Creates an Result from a function that may throw.
|
|
147
147
|
* Catches any errors and transforms them using the onError function.
|
|
@@ -162,7 +162,7 @@ declare namespace Result {
|
|
|
162
162
|
* @example
|
|
163
163
|
* ```ts
|
|
164
164
|
* pipe(Result.ok(5), Result.map(n => n * 2)); // Ok(10)
|
|
165
|
-
* pipe(Result.
|
|
165
|
+
* pipe(Result.error("error"), Result.map(n => n * 2)); // Error("error")
|
|
166
166
|
* ```
|
|
167
167
|
*/
|
|
168
168
|
const map: <E, A, B>(f: (a: A) => B) => (data: Result<E, A>) => Result<E, B>;
|
|
@@ -171,7 +171,7 @@ declare namespace Result {
|
|
|
171
171
|
*
|
|
172
172
|
* @example
|
|
173
173
|
* ```ts
|
|
174
|
-
* pipe(Result.
|
|
174
|
+
* pipe(Result.error("oops"), Result.mapError(e => e.toUpperCase())); // Error("OOPS")
|
|
175
175
|
* ```
|
|
176
176
|
*/
|
|
177
177
|
const mapError: <E, F, A>(f: (e: E) => F) => (data: Result<E, A>) => Result<F, A>;
|
|
@@ -182,10 +182,10 @@ declare namespace Result {
|
|
|
182
182
|
* @example
|
|
183
183
|
* ```ts
|
|
184
184
|
* const validatePositive = (n: number): Result<string, number> =>
|
|
185
|
-
* n > 0 ? Result.ok(n) : Result.
|
|
185
|
+
* n > 0 ? Result.ok(n) : Result.error("Must be positive");
|
|
186
186
|
*
|
|
187
187
|
* pipe(Result.ok(5), Result.chain(validatePositive)); // Ok(5)
|
|
188
|
-
* pipe(Result.ok(-1), Result.chain(validatePositive)); //
|
|
188
|
+
* pipe(Result.ok(-1), Result.chain(validatePositive)); // Error("Must be positive")
|
|
189
189
|
* ```
|
|
190
190
|
*/
|
|
191
191
|
const chain: <E, A, B>(f: (a: A) => Result<E, B>) => (data: Result<E, A>) => Result<E, B>;
|
|
@@ -230,8 +230,8 @@ declare namespace Result {
|
|
|
230
230
|
* @example
|
|
231
231
|
* ```ts
|
|
232
232
|
* pipe(Result.ok(5), Result.getOrElse(() => 0)); // 5
|
|
233
|
-
* pipe(Result.
|
|
234
|
-
* pipe(Result.
|
|
233
|
+
* pipe(Result.error("error"), Result.getOrElse(() => 0)); // 0
|
|
234
|
+
* pipe(Result.error("error"), Result.getOrElse(() => null)); // null — typed as number | null
|
|
235
235
|
* ```
|
|
236
236
|
*/
|
|
237
237
|
const getOrElse: <E, A, B>(defaultValue: () => B) => (data: Result<E, A>) => A | B;
|
|
@@ -256,7 +256,7 @@ declare namespace Result {
|
|
|
256
256
|
* @example
|
|
257
257
|
* ```ts
|
|
258
258
|
* pipe(
|
|
259
|
-
* Result.
|
|
259
|
+
* Result.error("not found"),
|
|
260
260
|
* Result.tapError(e => console.error("validation failed:", e)),
|
|
261
261
|
* Result.chain(save),
|
|
262
262
|
* )
|
|
@@ -270,8 +270,8 @@ declare namespace Result {
|
|
|
270
270
|
* @example
|
|
271
271
|
* ```ts
|
|
272
272
|
* pipe(5, Result.fromPredicate(n => n > 0, n => `${n} is not positive`)); // Ok(5)
|
|
273
|
-
* pipe(-1, Result.fromPredicate(n => n > 0, n => `${n} is not positive`)); //
|
|
274
|
-
* pipe("", Result.fromPredicate(s => s.length > 0, () => "empty string")); //
|
|
273
|
+
* pipe(-1, Result.fromPredicate(n => n > 0, n => `${n} is not positive`)); // Error("-1 is not positive")
|
|
274
|
+
* pipe("", Result.fromPredicate(s => s.length > 0, () => "empty string")); // Error("empty string")
|
|
275
275
|
* ```
|
|
276
276
|
*/
|
|
277
277
|
const fromPredicate: <E, A>(pred: (a: A) => boolean, onFalse: (a: A) => E) => (a: A) => Result<E, A>;
|
|
@@ -281,10 +281,18 @@ declare namespace Result {
|
|
|
281
281
|
*/
|
|
282
282
|
const recover: <E, A, B>(fallback: (e: E) => Result<E, B>) => (data: Result<E, A>) => Result<E, A | B>;
|
|
283
283
|
/**
|
|
284
|
-
* Recovers from an error unless
|
|
284
|
+
* Recovers from an error unless the predicate `isBlocked` returns true for that error.
|
|
285
285
|
* The fallback can produce a different success type, widening the result to `Result<E, A | B>`.
|
|
286
|
+
*
|
|
287
|
+
* @example
|
|
288
|
+
* ```ts
|
|
289
|
+
* pipe(
|
|
290
|
+
* Result.error(new Error("not found")),
|
|
291
|
+
* Result.recoverUnless(e => e.message === "fatal", () => Result.ok(0))
|
|
292
|
+
* ); // Ok(0)
|
|
293
|
+
* ```
|
|
286
294
|
*/
|
|
287
|
-
const recoverUnless: <E, A, B>(
|
|
295
|
+
const recoverUnless: <E, A, B>(isBlocked: (e: E) => boolean, fallback: () => Result<E, B>) => (data: Result<E, A>) => Result<E, A | B>;
|
|
288
296
|
/**
|
|
289
297
|
* Converts a Result to an Maybe.
|
|
290
298
|
* Ok becomes Some, Err becomes None (the error is discarded).
|
|
@@ -292,7 +300,7 @@ declare namespace Result {
|
|
|
292
300
|
* @example
|
|
293
301
|
* ```ts
|
|
294
302
|
* Result.toMaybe(Result.ok(42)); // Some(42)
|
|
295
|
-
* Result.toMaybe(Result.
|
|
303
|
+
* Result.toMaybe(Result.error("oops")); // None
|
|
296
304
|
* ```
|
|
297
305
|
*/
|
|
298
306
|
const toMaybe: <E, A>(data: Result<E, A>) => Maybe<A>;
|
|
@@ -367,11 +375,6 @@ declare namespace Maybe {
|
|
|
367
375
|
* Extracts the value from a Maybe, returning undefined if None.
|
|
368
376
|
*/
|
|
369
377
|
const toUndefined: <A>(data: Maybe<A>) => A | undefined;
|
|
370
|
-
/**
|
|
371
|
-
* Creates a Maybe from a possibly undefined value.
|
|
372
|
-
* Returns None if undefined, Some otherwise.
|
|
373
|
-
*/
|
|
374
|
-
const fromUndefined: <A>(value: A | undefined) => Maybe<A>;
|
|
375
378
|
/**
|
|
376
379
|
* Creates a Maybe from a predicate applied to a value.
|
|
377
380
|
* Returns Some if the predicate passes, None otherwise.
|
|
@@ -411,7 +414,7 @@ declare namespace Maybe {
|
|
|
411
414
|
* @example
|
|
412
415
|
* ```ts
|
|
413
416
|
* Maybe.fromResult(Result.ok(42)); // Some(42)
|
|
414
|
-
* Maybe.fromResult(Result.
|
|
417
|
+
* Maybe.fromResult(Result.error("oops")); // None
|
|
415
418
|
* ```
|
|
416
419
|
*/
|
|
417
420
|
const fromResult: <E, A>(data: Result<E, A>) => Maybe<A>;
|
|
@@ -703,10 +706,12 @@ declare namespace Task {
|
|
|
703
706
|
const repeat: (options: {
|
|
704
707
|
times: number;
|
|
705
708
|
delay?: number;
|
|
706
|
-
}) => <A>(task: Task<A>) => Task<A[]>;
|
|
709
|
+
}) => <A>(task: Task<A>) => Task<readonly A[]>;
|
|
707
710
|
/**
|
|
708
711
|
* Runs a Task repeatedly until the result satisfies a predicate, returning that result.
|
|
709
712
|
* An optional delay (ms) can be inserted between runs.
|
|
713
|
+
* An optional `maxAttempts` cap stops the loop after N calls — the last value is returned
|
|
714
|
+
* regardless of whether the predicate was satisfied.
|
|
710
715
|
*
|
|
711
716
|
* @example
|
|
712
717
|
* ```ts
|
|
@@ -719,6 +724,7 @@ declare namespace Task {
|
|
|
719
724
|
const repeatUntil: <A>(options: {
|
|
720
725
|
when: (a: A) => boolean;
|
|
721
726
|
delay?: number;
|
|
727
|
+
maxAttempts?: number;
|
|
722
728
|
}) => (task: Task<A>) => Task<A>;
|
|
723
729
|
/**
|
|
724
730
|
* Resolves with the value of the first Task to complete. All Tasks start
|
|
@@ -767,9 +773,12 @@ declare namespace Task {
|
|
|
767
773
|
*/
|
|
768
774
|
const timeout: <E>(ms: number, onTimeout: () => E) => <A>(task: Task<A>) => Task<Result<E, A>>;
|
|
769
775
|
/**
|
|
770
|
-
* Creates a Task paired with an `abort` handle.
|
|
771
|
-
*
|
|
772
|
-
*
|
|
776
|
+
* Creates a Task paired with an `abort` handle. Calling `abort()` cancels the
|
|
777
|
+
* current in-flight call immediately. Unlike a one-shot abort, calling `task()`
|
|
778
|
+
* again after `abort()` starts a fresh call with a new signal.
|
|
779
|
+
*
|
|
780
|
+
* Each invocation of `task()` automatically cancels the previous in-flight call,
|
|
781
|
+
* making it safe to call repeatedly (e.g. on user input) without leaking promises.
|
|
773
782
|
*
|
|
774
783
|
* If an outer signal is also present (passed at the call site), aborting it
|
|
775
784
|
* propagates into the internal controller.
|
|
@@ -788,6 +797,19 @@ declare namespace Task {
|
|
|
788
797
|
task: Task<A>;
|
|
789
798
|
abort: () => void;
|
|
790
799
|
};
|
|
800
|
+
/**
|
|
801
|
+
* Executes a task with an optional signal. Use as a terminal step in a `pipe` chain.
|
|
802
|
+
*
|
|
803
|
+
* @example
|
|
804
|
+
* ```ts
|
|
805
|
+
* const name = await pipe(
|
|
806
|
+
* fetchConfig,
|
|
807
|
+
* Task.map(config => config.name),
|
|
808
|
+
* Task.run(),
|
|
809
|
+
* );
|
|
810
|
+
* ```
|
|
811
|
+
*/
|
|
812
|
+
const run: (signal?: AbortSignal) => <A>(task: Task<A>) => Promise<A>;
|
|
791
813
|
}
|
|
792
814
|
|
|
793
|
-
export { Deferred as D, type
|
|
815
|
+
export { Deferred as D, type Error as E, Maybe as M, type None as N, type Ok as O, Result as R, type Some as S, Task as T, type WithValue as W, type WithLog as a, type WithKind as b, type WithError as c, type RetryOptions as d, type TimeoutOptions as e, type WithTimeout as f, type WithMinInterval as g, type WithCooldown as h, type WithConcurrency as i, type WithSize as j, type WithMs as k, type WithN as l, type WithErrors as m, type WithFirst as n, type WithSecond as o };
|
|
@@ -3,7 +3,7 @@ import {
|
|
|
3
3
|
Maybe,
|
|
4
4
|
Result,
|
|
5
5
|
Task
|
|
6
|
-
} from "./chunk-
|
|
6
|
+
} from "./chunk-SDGDJ7CU.mjs";
|
|
7
7
|
import {
|
|
8
8
|
isNonEmptyList
|
|
9
9
|
} from "./chunk-DBIC62UV.mjs";
|
|
@@ -166,7 +166,7 @@ var Arr;
|
|
|
166
166
|
const result = [];
|
|
167
167
|
for (const a of data) {
|
|
168
168
|
const r = await Deferred.toPromise(f(a)());
|
|
169
|
-
if (Result.
|
|
169
|
+
if (Result.isError(r)) return r;
|
|
170
170
|
result.push(r.value);
|
|
171
171
|
}
|
|
172
172
|
return Result.ok(result);
|
|
@@ -307,6 +307,14 @@ var Dict;
|
|
|
307
307
|
}
|
|
308
308
|
return result;
|
|
309
309
|
};
|
|
310
|
+
Dict2.filterMap = (f) => (m) => {
|
|
311
|
+
const result = new globalThis.Map();
|
|
312
|
+
for (const [key, value] of m) {
|
|
313
|
+
const mapped = f(value);
|
|
314
|
+
if (mapped.kind === "Some") result.set(key, mapped.value);
|
|
315
|
+
}
|
|
316
|
+
return result;
|
|
317
|
+
};
|
|
310
318
|
Dict2.union = (other) => (m) => {
|
|
311
319
|
const result = new globalThis.Map(m);
|
|
312
320
|
for (const [k, v] of other) {
|
|
@@ -367,13 +375,13 @@ var Num;
|
|
|
367
375
|
Num2.add = (b) => (a) => a + b;
|
|
368
376
|
Num2.subtract = (b) => (a) => a - b;
|
|
369
377
|
Num2.multiply = (b) => (a) => a * b;
|
|
370
|
-
Num2.divide = (b) => (a) => a / b;
|
|
378
|
+
Num2.divide = (b) => (a) => b === 0 ? Maybe.none() : Maybe.some(a / b);
|
|
371
379
|
Num2.abs = (n) => Math.abs(n);
|
|
372
380
|
Num2.negate = (n) => -n;
|
|
373
381
|
Num2.round = (n) => Math.round(n);
|
|
374
382
|
Num2.floor = (n) => Math.floor(n);
|
|
375
383
|
Num2.ceil = (n) => Math.ceil(n);
|
|
376
|
-
Num2.remainder = (divisor) => (n) => n % divisor;
|
|
384
|
+
Num2.remainder = (divisor) => (n) => divisor === 0 ? Maybe.none() : Maybe.some(n % divisor);
|
|
377
385
|
})(Num || (Num = {}));
|
|
378
386
|
|
|
379
387
|
// src/Utils/Rec.ts
|
|
@@ -3,7 +3,7 @@ import {
|
|
|
3
3
|
Maybe,
|
|
4
4
|
Result,
|
|
5
5
|
Task
|
|
6
|
-
} from "./chunk-
|
|
6
|
+
} from "./chunk-SDGDJ7CU.mjs";
|
|
7
7
|
|
|
8
8
|
// src/Core/Lens.ts
|
|
9
9
|
var Lens;
|
|
@@ -55,14 +55,14 @@ var Logged;
|
|
|
55
55
|
})(Logged || (Logged = {}));
|
|
56
56
|
|
|
57
57
|
// src/internal/Op.util.ts
|
|
58
|
-
var _abortedNil = { kind: "
|
|
59
|
-
var _droppedNil = { kind: "
|
|
60
|
-
var _replacedNil = { kind: "
|
|
61
|
-
var _evictedNil = { kind: "
|
|
58
|
+
var _abortedNil = { kind: "OpNil", reason: "aborted" };
|
|
59
|
+
var _droppedNil = { kind: "OpNil", reason: "dropped" };
|
|
60
|
+
var _replacedNil = { kind: "OpNil", reason: "replaced" };
|
|
61
|
+
var _evictedNil = { kind: "OpNil", reason: "evicted" };
|
|
62
62
|
var _idle = { kind: "Idle" };
|
|
63
63
|
var _pending = { kind: "Pending" };
|
|
64
|
-
var ok = (value) => ({ kind: "
|
|
65
|
-
var err = (error) => ({ kind: "
|
|
64
|
+
var ok = (value) => ({ kind: "OpOk", value });
|
|
65
|
+
var err = (error) => ({ kind: "OpError", error });
|
|
66
66
|
var cancellableWait = (ms, signal) => {
|
|
67
67
|
if (ms <= 0) return Promise.resolve();
|
|
68
68
|
return new Promise((resolve) => {
|
|
@@ -185,6 +185,12 @@ var makeRestartable = (op, minInterval, retryOptions, timeoutOptions) => {
|
|
|
185
185
|
subscribers.add(cb);
|
|
186
186
|
if (currentState.kind !== "Idle") cb(currentState);
|
|
187
187
|
return () => subscribers.delete(cb);
|
|
188
|
+
},
|
|
189
|
+
reset: () => emit(_idle),
|
|
190
|
+
poll: (input, { interval }) => {
|
|
191
|
+
void run(input);
|
|
192
|
+
const id = setInterval(() => void run(input), interval);
|
|
193
|
+
return () => clearInterval(id);
|
|
188
194
|
}
|
|
189
195
|
};
|
|
190
196
|
};
|
|
@@ -249,6 +255,12 @@ var makeExclusive = (op, cooldown, retryOptions, timeoutOptions) => {
|
|
|
249
255
|
subscribers.add(cb);
|
|
250
256
|
if (currentState.kind !== "Idle") cb(currentState);
|
|
251
257
|
return () => subscribers.delete(cb);
|
|
258
|
+
},
|
|
259
|
+
reset: () => emit(_idle),
|
|
260
|
+
poll: (input, { interval }) => {
|
|
261
|
+
void run(input);
|
|
262
|
+
const id = setInterval(() => void run(input), interval);
|
|
263
|
+
return () => clearInterval(id);
|
|
252
264
|
}
|
|
253
265
|
};
|
|
254
266
|
};
|
|
@@ -348,6 +360,12 @@ var makeQueue = (op, maxSize, overflow, concurrency, dedupe, retryOptions, timeo
|
|
|
348
360
|
subscribers.add(cb);
|
|
349
361
|
if (currentState.kind !== "Idle") cb(currentState);
|
|
350
362
|
return () => subscribers.delete(cb);
|
|
363
|
+
},
|
|
364
|
+
reset: () => emit(_idle),
|
|
365
|
+
poll: (input, { interval }) => {
|
|
366
|
+
void run(input);
|
|
367
|
+
const id = setInterval(() => void run(input), interval);
|
|
368
|
+
return () => clearInterval(id);
|
|
351
369
|
}
|
|
352
370
|
};
|
|
353
371
|
};
|
|
@@ -418,6 +436,12 @@ var makeBuffered = (op, size, retryOptions, timeoutOptions) => {
|
|
|
418
436
|
subscribers.add(cb);
|
|
419
437
|
if (currentState.kind !== "Idle") cb(currentState);
|
|
420
438
|
return () => subscribers.delete(cb);
|
|
439
|
+
},
|
|
440
|
+
reset: () => emit(_idle),
|
|
441
|
+
poll: (input, { interval }) => {
|
|
442
|
+
void run(input);
|
|
443
|
+
const id = setInterval(() => void run(input), interval);
|
|
444
|
+
return () => clearInterval(id);
|
|
421
445
|
}
|
|
422
446
|
};
|
|
423
447
|
};
|
|
@@ -540,6 +564,12 @@ var makeDebounced = (op, ms, leading, maxWait, retryOptions, timeoutOptions) =>
|
|
|
540
564
|
subscribers.add(cb);
|
|
541
565
|
if (currentState.kind !== "Idle") cb(currentState);
|
|
542
566
|
return () => subscribers.delete(cb);
|
|
567
|
+
},
|
|
568
|
+
reset: () => emit(_idle),
|
|
569
|
+
poll: (input, { interval }) => {
|
|
570
|
+
void run(input);
|
|
571
|
+
const id = setInterval(() => void run(input), interval);
|
|
572
|
+
return () => clearInterval(id);
|
|
543
573
|
}
|
|
544
574
|
};
|
|
545
575
|
};
|
|
@@ -632,6 +662,12 @@ var makeThrottled = (op, ms, trailing, retryOptions, timeoutOptions) => {
|
|
|
632
662
|
subscribers.add(cb);
|
|
633
663
|
if (currentState.kind !== "Idle") cb(currentState);
|
|
634
664
|
return () => subscribers.delete(cb);
|
|
665
|
+
},
|
|
666
|
+
reset: () => emit(_idle),
|
|
667
|
+
poll: (input, { interval }) => {
|
|
668
|
+
void run(input);
|
|
669
|
+
const id = setInterval(() => void run(input), interval);
|
|
670
|
+
return () => clearInterval(id);
|
|
635
671
|
}
|
|
636
672
|
};
|
|
637
673
|
};
|
|
@@ -713,6 +749,12 @@ var makeConcurrent = (op, n, overflow, retryOptions, timeoutOptions) => {
|
|
|
713
749
|
subscribers.add(cb);
|
|
714
750
|
if (currentState.kind !== "Idle") cb(currentState);
|
|
715
751
|
return () => subscribers.delete(cb);
|
|
752
|
+
},
|
|
753
|
+
reset: () => emit(_idle),
|
|
754
|
+
poll: (input, { interval }) => {
|
|
755
|
+
void run(input);
|
|
756
|
+
const id = setInterval(() => void run(input), interval);
|
|
757
|
+
return () => clearInterval(id);
|
|
716
758
|
}
|
|
717
759
|
};
|
|
718
760
|
};
|
|
@@ -789,6 +831,15 @@ var makeKeyed = (op, keyFn, perKey, timeoutOptions) => {
|
|
|
789
831
|
subscribers.add(cb);
|
|
790
832
|
if (stateMap.size > 0) cb(new Map(stateMap));
|
|
791
833
|
return () => subscribers.delete(cb);
|
|
834
|
+
},
|
|
835
|
+
reset: () => {
|
|
836
|
+
stateMap.clear();
|
|
837
|
+
emitSnapshot();
|
|
838
|
+
},
|
|
839
|
+
poll: (input, { interval }) => {
|
|
840
|
+
void run(input);
|
|
841
|
+
const id = setInterval(() => void run(input), interval);
|
|
842
|
+
return () => clearInterval(id);
|
|
792
843
|
}
|
|
793
844
|
};
|
|
794
845
|
};
|
|
@@ -843,6 +894,12 @@ var makeOnce = (op, retryOptions, timeoutOptions) => {
|
|
|
843
894
|
subscribers.add(cb);
|
|
844
895
|
if (currentState.kind !== "Idle") cb(currentState);
|
|
845
896
|
return () => subscribers.delete(cb);
|
|
897
|
+
},
|
|
898
|
+
reset: () => emit(_idle),
|
|
899
|
+
poll: (input, { interval }) => {
|
|
900
|
+
void run(input);
|
|
901
|
+
const id = setInterval(() => void run(input), interval);
|
|
902
|
+
return () => clearInterval(id);
|
|
846
903
|
}
|
|
847
904
|
};
|
|
848
905
|
};
|
|
@@ -850,44 +907,59 @@ var makeOnce = (op, retryOptions, timeoutOptions) => {
|
|
|
850
907
|
// src/Core/Op.ts
|
|
851
908
|
var Op;
|
|
852
909
|
((Op2) => {
|
|
853
|
-
Op2.nil = (reason) => ({ kind: "
|
|
910
|
+
Op2.nil = (reason) => ({ kind: "OpNil", reason });
|
|
854
911
|
Op2.create = (factory, onError) => ({
|
|
855
912
|
_factory: (input, signal) => Deferred.fromPromise(
|
|
856
|
-
factory(signal)(input).then((value) => Result.ok(value)).catch((e) => signal.aborted ? null : Result.
|
|
913
|
+
factory(signal)(input).then((value) => Result.ok(value)).catch((e) => signal.aborted ? null : Result.error(onError(e)))
|
|
857
914
|
)
|
|
858
915
|
});
|
|
859
|
-
Op2.
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
Op2.
|
|
916
|
+
Op2.lift = (f) => (0, Op2.create)(
|
|
917
|
+
(signal) => (input) => f(input, signal),
|
|
918
|
+
(e) => e
|
|
919
|
+
);
|
|
920
|
+
Op2.ok = (value) => ({ kind: "OpOk", value });
|
|
921
|
+
Op2.error = (error2) => ({ kind: "OpError", error: error2 });
|
|
922
|
+
Op2.isIdle = (state) => state.kind === "Idle";
|
|
923
|
+
Op2.isPending = (state) => state.kind === "Pending";
|
|
924
|
+
Op2.isQueued = (state) => state.kind === "Queued";
|
|
925
|
+
Op2.isRetrying = (state) => state.kind === "Retrying";
|
|
926
|
+
Op2.isOk = (state) => state.kind === "OpOk";
|
|
927
|
+
Op2.isError = (state) => state.kind === "OpError";
|
|
928
|
+
Op2.isNil = (state) => state.kind === "OpNil";
|
|
864
929
|
Op2.match = (cases) => (outcome) => {
|
|
865
|
-
if (outcome.kind === "
|
|
866
|
-
if (outcome.kind === "
|
|
930
|
+
if (outcome.kind === "OpOk") return cases.ok(outcome.value);
|
|
931
|
+
if (outcome.kind === "OpError") return cases.error(outcome.error);
|
|
867
932
|
return cases.nil();
|
|
868
933
|
};
|
|
869
|
-
Op2.fold = (
|
|
870
|
-
if (outcome.kind === "
|
|
871
|
-
if (outcome.kind === "
|
|
934
|
+
Op2.fold = (onError, onOk, onNil) => (outcome) => {
|
|
935
|
+
if (outcome.kind === "OpOk") return onOk(outcome.value);
|
|
936
|
+
if (outcome.kind === "OpError") return onError(outcome.error);
|
|
872
937
|
return onNil();
|
|
873
938
|
};
|
|
874
|
-
Op2.getOrElse = (defaultValue) => (outcome) => outcome.kind === "
|
|
875
|
-
Op2.map = (f) => (outcome) => outcome.kind === "
|
|
876
|
-
Op2.mapError = (f) => (outcome) => outcome.kind === "
|
|
877
|
-
Op2.chain = (f) => (outcome) => outcome.kind === "
|
|
939
|
+
Op2.getOrElse = (defaultValue) => (outcome) => outcome.kind === "OpOk" ? outcome.value : defaultValue();
|
|
940
|
+
Op2.map = (f) => (outcome) => outcome.kind === "OpOk" ? (0, Op2.ok)(f(outcome.value)) : outcome;
|
|
941
|
+
Op2.mapError = (f) => (outcome) => outcome.kind === "OpError" ? (0, Op2.error)(f(outcome.error)) : outcome;
|
|
942
|
+
Op2.chain = (f) => (outcome) => outcome.kind === "OpOk" ? f(outcome.value) : outcome;
|
|
878
943
|
Op2.tap = (f) => (outcome) => {
|
|
879
|
-
if (outcome.kind === "
|
|
944
|
+
if (outcome.kind === "OpOk") f(outcome.value);
|
|
880
945
|
return outcome;
|
|
881
946
|
};
|
|
882
|
-
Op2.recover = (f) => (outcome) => outcome.kind === "
|
|
947
|
+
Op2.recover = (f) => (outcome) => outcome.kind === "OpError" ? f(outcome.error) : outcome;
|
|
883
948
|
Op2.toResult = (onNil) => (outcome) => {
|
|
884
|
-
if (outcome.kind === "
|
|
885
|
-
if (outcome.kind === "
|
|
886
|
-
return Result.
|
|
949
|
+
if (outcome.kind === "OpOk") return Result.ok(outcome.value);
|
|
950
|
+
if (outcome.kind === "OpError") return Result.error(outcome.error);
|
|
951
|
+
return Result.error(onNil());
|
|
887
952
|
};
|
|
888
|
-
Op2.toMaybe = (outcome) => outcome.kind === "
|
|
953
|
+
Op2.toMaybe = (outcome) => outcome.kind === "OpOk" ? Maybe.some(outcome.value) : Maybe.none();
|
|
889
954
|
Op2.all = (invocations) => Deferred.fromPromise(Promise.all(invocations.map(Deferred.toPromise)));
|
|
890
955
|
Op2.race = (invocations) => Deferred.fromPromise(Promise.race(invocations.map(Deferred.toPromise)));
|
|
956
|
+
Op2.wire = (source, f) => source.subscribe((state) => {
|
|
957
|
+
if ((0, Op2.isOk)(state)) f(state.value);
|
|
958
|
+
});
|
|
959
|
+
Op2.wireAll = (...pairs) => {
|
|
960
|
+
const cleanups = pairs.map(([source, f]) => (0, Op2.wire)(source, f));
|
|
961
|
+
return () => cleanups.forEach((c) => c());
|
|
962
|
+
};
|
|
891
963
|
function interpret(op, options) {
|
|
892
964
|
const { strategy, retry: retryOptions, timeout: timeoutOptions } = options;
|
|
893
965
|
switch (strategy) {
|
|
@@ -1026,7 +1098,7 @@ var Refinement;
|
|
|
1026
1098
|
Refinement2.and = (second) => (first) => (a) => first(a) && second(a);
|
|
1027
1099
|
Refinement2.or = (second) => (first) => (a) => first(a) || second(a);
|
|
1028
1100
|
Refinement2.toFilter = (r) => (a) => r(a) ? Maybe.some(a) : Maybe.none();
|
|
1029
|
-
Refinement2.toResult = (r, onFail) => (a) => r(a) ? Result.ok(a) : Result.
|
|
1101
|
+
Refinement2.toResult = (r, onFail) => (a) => r(a) ? Result.ok(a) : Result.error(onFail(a));
|
|
1030
1102
|
})(Refinement || (Refinement = {}));
|
|
1031
1103
|
|
|
1032
1104
|
// src/Core/RemoteData.ts
|
|
@@ -1089,11 +1161,16 @@ var RemoteData;
|
|
|
1089
1161
|
if ((0, RemoteData2.isSuccess)(data)) f(data.value);
|
|
1090
1162
|
return data;
|
|
1091
1163
|
};
|
|
1164
|
+
RemoteData2.tapError = (f) => (data) => {
|
|
1165
|
+
if ((0, RemoteData2.isFailure)(data)) f(data.error);
|
|
1166
|
+
return data;
|
|
1167
|
+
};
|
|
1092
1168
|
RemoteData2.recover = (fallback) => (data) => (0, RemoteData2.isFailure)(data) ? fallback(data.error) : data;
|
|
1093
1169
|
RemoteData2.toMaybe = (data) => (0, RemoteData2.isSuccess)(data) ? Maybe.some(data.value) : Maybe.none();
|
|
1094
|
-
RemoteData2.toResult = (onNotReady) => (data) => (0, RemoteData2.isSuccess)(data) ? Result.ok(data.value) : Result.
|
|
1170
|
+
RemoteData2.toResult = (onNotReady) => (data) => (0, RemoteData2.isSuccess)(data) ? Result.ok(data.value) : Result.error((0, RemoteData2.isFailure)(data) ? data.error : onNotReady());
|
|
1095
1171
|
RemoteData2.fromResult = (data) => Result.isOk(data) ? (0, RemoteData2.success)(data.value) : (0, RemoteData2.failure)(data.error);
|
|
1096
1172
|
RemoteData2.fromMaybe = (onNone) => (data) => Maybe.isSome(data) ? (0, RemoteData2.success)(data.value) : (0, RemoteData2.failure)(onNone());
|
|
1173
|
+
RemoteData2.filter = (pred, onFalse) => (data) => (0, RemoteData2.isSuccess)(data) ? pred(data.value) ? data : (0, RemoteData2.failure)(onFalse(data.value)) : data;
|
|
1097
1174
|
})(RemoteData || (RemoteData = {}));
|
|
1098
1175
|
|
|
1099
1176
|
// src/Core/Resource.ts
|
|
@@ -1106,7 +1183,7 @@ var Resource;
|
|
|
1106
1183
|
});
|
|
1107
1184
|
Resource2.use = (f) => (resource) => Task.from(
|
|
1108
1185
|
() => Deferred.toPromise(resource.acquire()).then(async (acquired) => {
|
|
1109
|
-
if (Result.
|
|
1186
|
+
if (Result.isError(acquired)) return acquired;
|
|
1110
1187
|
const a = acquired.value;
|
|
1111
1188
|
const usageResult = await Deferred.toPromise(f(a)());
|
|
1112
1189
|
await Deferred.toPromise(resource.release(a)());
|
|
@@ -1116,10 +1193,10 @@ var Resource;
|
|
|
1116
1193
|
Resource2.combine = (resourceA, resourceB) => ({
|
|
1117
1194
|
acquire: Task.from(
|
|
1118
1195
|
() => Deferred.toPromise(resourceA.acquire()).then(async (acquiredA) => {
|
|
1119
|
-
if (Result.
|
|
1196
|
+
if (Result.isError(acquiredA)) return acquiredA;
|
|
1120
1197
|
const a = acquiredA.value;
|
|
1121
1198
|
const acquiredB = await Deferred.toPromise(resourceB.acquire());
|
|
1122
|
-
if (Result.
|
|
1199
|
+
if (Result.isError(acquiredB)) {
|
|
1123
1200
|
await Deferred.toPromise(resourceA.release(a)());
|
|
1124
1201
|
return acquiredB;
|
|
1125
1202
|
}
|
|
@@ -1191,23 +1268,26 @@ var TaskMaybe;
|
|
|
1191
1268
|
var TaskResult;
|
|
1192
1269
|
((TaskResult2) => {
|
|
1193
1270
|
TaskResult2.ok = (value) => Task.resolve(Result.ok(value));
|
|
1194
|
-
TaskResult2.err = (error) => Task.resolve(Result.
|
|
1271
|
+
TaskResult2.err = (error) => Task.resolve(Result.error(error));
|
|
1195
1272
|
TaskResult2.tryCatch = (f, onError) => Task.from(
|
|
1196
|
-
(signal) => f(signal).then(Result.ok).catch((e) => Result.
|
|
1273
|
+
(signal) => f(signal).then(Result.ok).catch((e) => Result.error(onError(e)))
|
|
1197
1274
|
);
|
|
1198
1275
|
TaskResult2.map = (f) => (data) => Task.map(Result.map(f))(data);
|
|
1199
1276
|
TaskResult2.mapError = (f) => (data) => Task.map(Result.mapError(f))(data);
|
|
1200
|
-
TaskResult2.chain = (f) => (data) => Task.chain(
|
|
1277
|
+
TaskResult2.chain = (f) => (data) => Task.chain(
|
|
1278
|
+
(result) => Result.isOk(result) ? f(result.value) : Task.resolve(Result.error(result.error))
|
|
1279
|
+
)(
|
|
1201
1280
|
data
|
|
1202
1281
|
);
|
|
1203
1282
|
TaskResult2.fold = (onErr, onOk) => (data) => Task.map(Result.fold(onErr, onOk))(data);
|
|
1204
1283
|
TaskResult2.match = (cases) => (data) => Task.map(Result.match(cases))(data);
|
|
1205
1284
|
TaskResult2.recover = (fallback) => (data) => Task.chain(
|
|
1206
|
-
(result) => Result.
|
|
1285
|
+
(result) => Result.isError(result) ? fallback(result.error) : Task.resolve(result)
|
|
1207
1286
|
)(data);
|
|
1208
1287
|
TaskResult2.getOrElse = (defaultValue) => (data) => Task.map(Result.getOrElse(defaultValue))(data);
|
|
1209
1288
|
TaskResult2.tap = (f) => (data) => Task.map(Result.tap(f))(data);
|
|
1210
1289
|
TaskResult2.tapError = (f) => (data) => Task.map(Result.tapError(f))(data);
|
|
1290
|
+
TaskResult2.run = (signal) => (task) => Deferred.toPromise(task(signal));
|
|
1211
1291
|
})(TaskResult || (TaskResult = {}));
|
|
1212
1292
|
|
|
1213
1293
|
// src/Core/Validation.ts
|
|
@@ -1227,6 +1307,7 @@ var Validation;
|
|
|
1227
1307
|
});
|
|
1228
1308
|
Validation2.isValid = (data) => data.kind === "Valid";
|
|
1229
1309
|
Validation2.isInvalid = (data) => data.kind === "Invalid";
|
|
1310
|
+
Validation2.fromPredicate = (pred, onFalse) => (a) => pred(a) ? (0, Validation2.valid)(a) : (0, Validation2.invalid)(onFalse(a));
|
|
1230
1311
|
Validation2.map = (f) => (data) => (0, Validation2.isValid)(data) ? (0, Validation2.valid)(f(data.value)) : data;
|
|
1231
1312
|
Validation2.ap = (arg) => (data) => {
|
|
1232
1313
|
if ((0, Validation2.isValid)(data) && (0, Validation2.isValid)(arg)) return (0, Validation2.valid)(data.value(arg.value));
|
|
@@ -1243,8 +1324,15 @@ var Validation;
|
|
|
1243
1324
|
if ((0, Validation2.isValid)(data)) f(data.value);
|
|
1244
1325
|
return data;
|
|
1245
1326
|
};
|
|
1327
|
+
Validation2.tapError = (f) => (data) => {
|
|
1328
|
+
if ((0, Validation2.isInvalid)(data)) f(data.errors);
|
|
1329
|
+
return data;
|
|
1330
|
+
};
|
|
1246
1331
|
Validation2.recover = (fallback) => (data) => (0, Validation2.isValid)(data) ? data : fallback(data.errors);
|
|
1247
|
-
Validation2.recoverUnless = (
|
|
1332
|
+
Validation2.recoverUnless = (isBlocked, fallback) => (data) => (0, Validation2.isInvalid)(data) && !data.errors.some(isBlocked) ? fallback() : data;
|
|
1333
|
+
Validation2.toResult = (data) => (0, Validation2.isValid)(data) ? Result.ok(data.value) : Result.error(data.errors);
|
|
1334
|
+
Validation2.toMaybe = (data) => (0, Validation2.isValid)(data) ? Maybe.some(data.value) : Maybe.none();
|
|
1335
|
+
Validation2.fromResult = (data) => data.kind === "Ok" ? (0, Validation2.valid)(data.value) : (0, Validation2.invalid)(data.error);
|
|
1248
1336
|
Validation2.product = (first, second) => {
|
|
1249
1337
|
if ((0, Validation2.isValid)(first) && (0, Validation2.isValid)(second)) return (0, Validation2.valid)([first.value, second.value]);
|
|
1250
1338
|
const errors = [
|