@nlozgachev/pipelined 0.33.0 → 0.34.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 +67 -37
- package/dist/{Task-5na0QzS4.d.mts → Task-DXsuurnc.d.mts} +54 -55
- package/dist/{Task-DeiWgoeJ.d.ts → Task-zAY4kSVB.d.ts} +54 -55
- package/dist/{chunk-FZX4MTRI.mjs → chunk-5AWUAG7G.mjs} +445 -308
- package/dist/{chunk-NRF2FVPZ.mjs → chunk-AHEZFTMT.mjs} +64 -32
- package/dist/{chunk-GSTKY7MF.mjs → chunk-DLBHVYII.mjs} +69 -52
- package/dist/{chunk-W53ZYTLX.mjs → chunk-IJFFWBKW.mjs} +184 -64
- package/dist/composition.d.mts +8 -7
- package/dist/composition.d.ts +8 -7
- package/dist/composition.js +64 -32
- package/dist/composition.mjs +1 -1
- package/dist/core.d.mts +172 -163
- package/dist/core.d.ts +172 -163
- package/dist/core.js +535 -384
- package/dist/core.mjs +2 -2
- package/dist/index.d.mts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +783 -480
- package/dist/index.mjs +4 -4
- package/dist/utils.d.mts +8 -7
- package/dist/utils.d.ts +8 -7
- package/dist/utils.js +252 -115
- package/dist/utils.mjs +2 -2
- package/package.json +9 -9
|
@@ -24,19 +24,19 @@ type WithLog<T> = {
|
|
|
24
24
|
/** Retry policy for `Op.interpret`. */
|
|
25
25
|
type RetryOptions<E> = {
|
|
26
26
|
readonly attempts: number;
|
|
27
|
-
readonly backoff?:
|
|
27
|
+
readonly backoff?: Duration | ((attempt: number) => Duration);
|
|
28
28
|
readonly when?: (error: E) => boolean;
|
|
29
29
|
};
|
|
30
30
|
/** Timeout policy for `Op.interpret`. Wraps the entire retry sequence. */
|
|
31
31
|
type TimeoutOptions<E> = {
|
|
32
|
-
readonly
|
|
32
|
+
readonly duration: Duration;
|
|
33
33
|
readonly onTimeout: () => E;
|
|
34
34
|
};
|
|
35
35
|
type WithTimeout<E> = {
|
|
36
36
|
readonly timeout?: TimeoutOptions<E>;
|
|
37
37
|
};
|
|
38
|
-
type
|
|
39
|
-
readonly
|
|
38
|
+
type WithDuration = {
|
|
39
|
+
readonly duration: Duration;
|
|
40
40
|
};
|
|
41
41
|
type WithN = {
|
|
42
42
|
readonly n: number;
|
|
@@ -48,22 +48,22 @@ type WithSize = {
|
|
|
48
48
|
readonly size?: number;
|
|
49
49
|
};
|
|
50
50
|
type WithCooldown = {
|
|
51
|
-
readonly cooldown?:
|
|
51
|
+
readonly cooldown?: Duration;
|
|
52
52
|
};
|
|
53
53
|
type WithMinInterval = {
|
|
54
|
-
readonly minInterval?:
|
|
54
|
+
readonly minInterval?: Duration;
|
|
55
55
|
};
|
|
56
56
|
|
|
57
57
|
type Ok<A> = WithKind<"Ok"> & WithValue<A>;
|
|
58
|
-
type
|
|
58
|
+
type Err<E> = WithKind<"Err"> & WithError<E>;
|
|
59
59
|
/**
|
|
60
|
-
* Result represents a value that can be one of two types: a success (Ok) or a failure (
|
|
60
|
+
* Result represents a value that can be one of two types: a success (Ok) or a failure (Err).
|
|
61
61
|
* Use Result when an operation can fail with a meaningful error value.
|
|
62
62
|
*
|
|
63
63
|
* @example
|
|
64
64
|
* ```ts
|
|
65
65
|
* const divide = (a: number, b: number): Result<string, number> =>
|
|
66
|
-
* b === 0 ? Result.
|
|
66
|
+
* b === 0 ? Result.err("Division by zero") : Result.ok(a / b);
|
|
67
67
|
*
|
|
68
68
|
* pipe(
|
|
69
69
|
* divide(10, 2),
|
|
@@ -72,7 +72,7 @@ type Error<E> = WithKind<"Error"> & WithError<E>;
|
|
|
72
72
|
* ); // 10
|
|
73
73
|
* ```
|
|
74
74
|
*/
|
|
75
|
-
type Result<E, A> = Ok<A> |
|
|
75
|
+
type Result<E, A> = Ok<A> | Err<E>;
|
|
76
76
|
declare namespace Result {
|
|
77
77
|
/**
|
|
78
78
|
* Creates a successful Result with the given value.
|
|
@@ -81,17 +81,17 @@ declare namespace Result {
|
|
|
81
81
|
/**
|
|
82
82
|
* Creates a failed Result with the given error.
|
|
83
83
|
*/
|
|
84
|
-
const
|
|
84
|
+
const err: <E>(e: E) => Err<E>;
|
|
85
85
|
/**
|
|
86
|
-
* Type guard that checks if
|
|
86
|
+
* Type guard that checks if a Result is Ok.
|
|
87
87
|
*/
|
|
88
88
|
const isOk: <E, A>(data: Result<E, A>) => data is Ok<A>;
|
|
89
89
|
/**
|
|
90
|
-
* Type guard that checks if
|
|
90
|
+
* Type guard that checks if a Result is Err.
|
|
91
91
|
*/
|
|
92
|
-
const
|
|
92
|
+
const isErr: <E, A>(data: Result<E, A>) => data is Err<E>;
|
|
93
93
|
/**
|
|
94
|
-
* Creates
|
|
94
|
+
* Creates a Result from a function that may throw.
|
|
95
95
|
* Catches any errors and transforms them using the onError function.
|
|
96
96
|
*
|
|
97
97
|
* @example
|
|
@@ -105,21 +105,21 @@ declare namespace Result {
|
|
|
105
105
|
*/
|
|
106
106
|
const tryCatch: <E, A>(f: () => A, onError: (e: unknown) => E) => Result<E, A>;
|
|
107
107
|
/**
|
|
108
|
-
* Transforms the success value inside
|
|
108
|
+
* Transforms the success value inside a Result.
|
|
109
109
|
*
|
|
110
110
|
* @example
|
|
111
111
|
* ```ts
|
|
112
112
|
* pipe(Result.ok(5), Result.map(n => n * 2)); // Ok(10)
|
|
113
|
-
* pipe(Result.
|
|
113
|
+
* pipe(Result.err("error"), Result.map(n => n * 2)); // Err("error")
|
|
114
114
|
* ```
|
|
115
115
|
*/
|
|
116
116
|
const map: <E, A, B>(f: (a: A) => B) => (data: Result<E, A>) => Result<E, B>;
|
|
117
117
|
/**
|
|
118
|
-
* Transforms the error value inside
|
|
118
|
+
* Transforms the error value inside a Result.
|
|
119
119
|
*
|
|
120
120
|
* @example
|
|
121
121
|
* ```ts
|
|
122
|
-
* pipe(Result.
|
|
122
|
+
* pipe(Result.err("oops"), Result.mapError(e => e.toUpperCase())); // Err("OOPS")
|
|
123
123
|
* ```
|
|
124
124
|
*/
|
|
125
125
|
const mapError: <E, F, A>(f: (e: E) => F) => (data: Result<E, A>) => Result<F, A>;
|
|
@@ -130,15 +130,15 @@ declare namespace Result {
|
|
|
130
130
|
* @example
|
|
131
131
|
* ```ts
|
|
132
132
|
* const validatePositive = (n: number): Result<string, number> =>
|
|
133
|
-
* n > 0 ? Result.ok(n) : Result.
|
|
133
|
+
* n > 0 ? Result.ok(n) : Result.err("Must be positive");
|
|
134
134
|
*
|
|
135
135
|
* pipe(Result.ok(5), Result.chain(validatePositive)); // Ok(5)
|
|
136
|
-
* pipe(Result.ok(-1), Result.chain(validatePositive)); //
|
|
136
|
+
* pipe(Result.ok(-1), Result.chain(validatePositive)); // Err("Must be positive")
|
|
137
137
|
* ```
|
|
138
138
|
*/
|
|
139
139
|
const chain: <E, A, B>(f: (a: A) => Result<E, B>) => (data: Result<E, A>) => Result<E, B>;
|
|
140
140
|
/**
|
|
141
|
-
* Extracts the value from
|
|
141
|
+
* Extracts the value from a Result by providing handlers for both cases.
|
|
142
142
|
*
|
|
143
143
|
* @example
|
|
144
144
|
* ```ts
|
|
@@ -178,8 +178,8 @@ declare namespace Result {
|
|
|
178
178
|
* @example
|
|
179
179
|
* ```ts
|
|
180
180
|
* pipe(Result.ok(5), Result.getOrElse(() => 0)); // 5
|
|
181
|
-
* pipe(Result.
|
|
182
|
-
* pipe(Result.
|
|
181
|
+
* pipe(Result.err("error"), Result.getOrElse(() => 0)); // 0
|
|
182
|
+
* pipe(Result.err("error"), Result.getOrElse(() => null)); // null — typed as number | null
|
|
183
183
|
* ```
|
|
184
184
|
*/
|
|
185
185
|
const getOrElse: <E, A, B>(defaultValue: () => B) => (data: Result<E, A>) => A | B;
|
|
@@ -204,7 +204,7 @@ declare namespace Result {
|
|
|
204
204
|
* @example
|
|
205
205
|
* ```ts
|
|
206
206
|
* pipe(
|
|
207
|
-
* Result.
|
|
207
|
+
* Result.err("not found"),
|
|
208
208
|
* Result.tapError(e => console.error("validation failed:", e)),
|
|
209
209
|
* Result.chain(save),
|
|
210
210
|
* )
|
|
@@ -218,8 +218,8 @@ declare namespace Result {
|
|
|
218
218
|
* @example
|
|
219
219
|
* ```ts
|
|
220
220
|
* pipe(5, Result.fromPredicate(n => n > 0, n => `${n} is not positive`)); // Ok(5)
|
|
221
|
-
* pipe(-1, Result.fromPredicate(n => n > 0, n => `${n} is not positive`)); //
|
|
222
|
-
* pipe("", Result.fromPredicate(s => s.length > 0, () => "empty string")); //
|
|
221
|
+
* pipe(-1, Result.fromPredicate(n => n > 0, n => `${n} is not positive`)); // Err("-1 is not positive")
|
|
222
|
+
* pipe("", Result.fromPredicate(s => s.length > 0, () => "empty string")); // Err("empty string")
|
|
223
223
|
* ```
|
|
224
224
|
*/
|
|
225
225
|
const fromPredicate: <E, A>(pred: (a: A) => boolean, onFalse: (a: A) => E) => (a: A) => Result<E, A>;
|
|
@@ -229,7 +229,7 @@ declare namespace Result {
|
|
|
229
229
|
*
|
|
230
230
|
* @example
|
|
231
231
|
* ```ts
|
|
232
|
-
* pipe(null, Result.fromNullable(() => "is null")); //
|
|
232
|
+
* pipe(null, Result.fromNullable(() => "is null")); // Err("is null")
|
|
233
233
|
* pipe(42, Result.fromNullable(() => "is null")); // Ok(42)
|
|
234
234
|
* ```
|
|
235
235
|
*/
|
|
@@ -240,7 +240,7 @@ declare namespace Result {
|
|
|
240
240
|
*
|
|
241
241
|
* @example
|
|
242
242
|
* ```ts
|
|
243
|
-
* pipe(Maybe.none(), Result.fromMaybe(() => "is none")); //
|
|
243
|
+
* pipe(Maybe.none(), Result.fromMaybe(() => "is none")); // Err("is none")
|
|
244
244
|
* pipe(Maybe.some(42), Result.fromMaybe(() => "is none")); // Ok(42)
|
|
245
245
|
* ```
|
|
246
246
|
*/
|
|
@@ -257,7 +257,7 @@ declare namespace Result {
|
|
|
257
257
|
* );
|
|
258
258
|
*
|
|
259
259
|
* safeParse('{"a":1}'); // Ok({ a: 1 })
|
|
260
|
-
* safeParse('invalid'); //
|
|
260
|
+
* safeParse('invalid'); // Err(Error)
|
|
261
261
|
* ```
|
|
262
262
|
*/
|
|
263
263
|
const fromThrowable: <Args extends readonly unknown[], A, E>(f: (...args: Args) => A, onError: (e: unknown) => E) => (...args: Args) => Result<E, A>;
|
|
@@ -273,25 +273,25 @@ declare namespace Result {
|
|
|
273
273
|
* @example
|
|
274
274
|
* ```ts
|
|
275
275
|
* pipe(
|
|
276
|
-
* Result.
|
|
276
|
+
* Result.err(new Error("not found")),
|
|
277
277
|
* Result.recoverUnless(e => e.message === "fatal", () => Result.ok(0))
|
|
278
278
|
* ); // Ok(0)
|
|
279
279
|
* ```
|
|
280
280
|
*/
|
|
281
281
|
const recoverUnless: <E, A, B>(isBlocked: (e: E) => boolean, fallback: () => Result<E, B>) => (data: Result<E, A>) => Result<E, A | B>;
|
|
282
282
|
/**
|
|
283
|
-
* Converts a Result to
|
|
283
|
+
* Converts a Result to a Maybe.
|
|
284
284
|
* Ok becomes Some, Err becomes None (the error is discarded).
|
|
285
285
|
*
|
|
286
286
|
* @example
|
|
287
287
|
* ```ts
|
|
288
288
|
* Result.toMaybe(Result.ok(42)); // Some(42)
|
|
289
|
-
* Result.toMaybe(Result.
|
|
289
|
+
* Result.toMaybe(Result.err("oops")); // None
|
|
290
290
|
* ```
|
|
291
291
|
*/
|
|
292
292
|
const toMaybe: <E, A>(data: Result<E, A>) => Maybe<A>;
|
|
293
293
|
/**
|
|
294
|
-
* Applies a function wrapped in
|
|
294
|
+
* Applies a function wrapped in a Result to a value wrapped in a Result.
|
|
295
295
|
*
|
|
296
296
|
* @example
|
|
297
297
|
* ```ts
|
|
@@ -314,14 +314,13 @@ type None = WithKind<"None">;
|
|
|
314
314
|
*
|
|
315
315
|
* @example
|
|
316
316
|
* ```ts
|
|
317
|
-
* const
|
|
318
|
-
* users.has(id) ? Maybe.some(users.get(id)!) : Maybe.none();
|
|
317
|
+
* const user = { name: "Alice", email: Maybe.some("alice@example.com") };
|
|
319
318
|
*
|
|
320
319
|
* pipe(
|
|
321
|
-
*
|
|
322
|
-
* Maybe.map(
|
|
323
|
-
* Maybe.getOrElse(() => "
|
|
324
|
-
* );
|
|
320
|
+
* user.email,
|
|
321
|
+
* Maybe.map(email => email.toUpperCase()),
|
|
322
|
+
* Maybe.getOrElse(() => "NO EMAIL")
|
|
323
|
+
* ); // "ALICE@EXAMPLE.COM"
|
|
325
324
|
* ```
|
|
326
325
|
*/
|
|
327
326
|
type Maybe<T> = Some<T> | None;
|
|
@@ -376,7 +375,7 @@ declare namespace Maybe {
|
|
|
376
375
|
*/
|
|
377
376
|
const fromPredicate: <A>(pred: (a: A) => boolean) => (a: A) => Maybe<A>;
|
|
378
377
|
/**
|
|
379
|
-
* Converts
|
|
378
|
+
* Converts a Maybe to a Result.
|
|
380
379
|
* Some becomes Ok, None becomes Err with the provided error.
|
|
381
380
|
*
|
|
382
381
|
* @example
|
|
@@ -394,13 +393,13 @@ declare namespace Maybe {
|
|
|
394
393
|
*/
|
|
395
394
|
const toResult: <E>(onNone: () => E) => <A>(data: Maybe<A>) => Result<E, A>;
|
|
396
395
|
/**
|
|
397
|
-
* Creates
|
|
396
|
+
* Creates a Maybe from a Result.
|
|
398
397
|
* Ok becomes Some, Err becomes None (the error is discarded).
|
|
399
398
|
*
|
|
400
399
|
* @example
|
|
401
400
|
* ```ts
|
|
402
401
|
* Maybe.fromResult(Result.ok(42)); // Some(42)
|
|
403
|
-
* Maybe.fromResult(Result.
|
|
402
|
+
* Maybe.fromResult(Result.err("oops")); // None
|
|
404
403
|
* ```
|
|
405
404
|
*/
|
|
406
405
|
const fromResult: <E, A>(data: Result<E, A>) => Maybe<A>;
|
|
@@ -464,7 +463,7 @@ declare namespace Maybe {
|
|
|
464
463
|
some: (a: A) => B;
|
|
465
464
|
}) => (data: Maybe<A>) => B;
|
|
466
465
|
/**
|
|
467
|
-
* Returns the value inside
|
|
466
|
+
* Returns the value inside a Maybe, or a default value if None.
|
|
468
467
|
* The default is a thunk `() => B` — evaluated only when the Maybe is None.
|
|
469
468
|
* The default can be a different type, widening the result to `A | B`.
|
|
470
469
|
*
|
|
@@ -882,7 +881,7 @@ declare namespace Task {
|
|
|
882
881
|
*/
|
|
883
882
|
const all: <T extends readonly Task<unknown>[]>(tasks: T) => Task<{ [K in keyof T]: T[K] extends Task<infer A> ? A : never; }>;
|
|
884
883
|
/**
|
|
885
|
-
* Delays the execution of a Task by the specified
|
|
884
|
+
* Delays the execution of a Task by the specified duration.
|
|
886
885
|
* Useful for debouncing or rate limiting.
|
|
887
886
|
*
|
|
888
887
|
* @example
|
|
@@ -893,10 +892,10 @@ declare namespace Task {
|
|
|
893
892
|
* )(); // Resolves after 1 second
|
|
894
893
|
* ```
|
|
895
894
|
*/
|
|
896
|
-
const delay: (
|
|
895
|
+
const delay: (duration: Duration) => <A>(data: Task<A>) => Task<A>;
|
|
897
896
|
/**
|
|
898
897
|
* Runs a Task a fixed number of times sequentially, collecting all results into an array.
|
|
899
|
-
* An optional delay
|
|
898
|
+
* An optional delay duration can be inserted between runs.
|
|
900
899
|
*
|
|
901
900
|
* @example
|
|
902
901
|
* ```ts
|
|
@@ -908,11 +907,11 @@ declare namespace Task {
|
|
|
908
907
|
*/
|
|
909
908
|
const repeat: (options: {
|
|
910
909
|
times: number;
|
|
911
|
-
delay?:
|
|
910
|
+
delay?: Duration;
|
|
912
911
|
}) => <A>(task: Task<A>) => Task<readonly A[]>;
|
|
913
912
|
/**
|
|
914
913
|
* Runs a Task repeatedly until the result satisfies a predicate, returning that result.
|
|
915
|
-
* An optional delay
|
|
914
|
+
* An optional delay duration can be inserted between runs.
|
|
916
915
|
* An optional `maxAttempts` cap stops the loop after N calls — the last value is returned
|
|
917
916
|
* regardless of whether the predicate was satisfied.
|
|
918
917
|
*
|
|
@@ -926,7 +925,7 @@ declare namespace Task {
|
|
|
926
925
|
*/
|
|
927
926
|
const repeatUntil: <A>(options: {
|
|
928
927
|
when: (a: A) => boolean;
|
|
929
|
-
delay?:
|
|
928
|
+
delay?: Duration;
|
|
930
929
|
maxAttempts?: number;
|
|
931
930
|
}) => (task: Task<A>) => Task<A>;
|
|
932
931
|
/**
|
|
@@ -973,8 +972,8 @@ declare namespace Task {
|
|
|
973
972
|
const sequential: <A>(tasks: ReadonlyArray<Task<A>>) => Task<ReadonlyArray<A>>;
|
|
974
973
|
/**
|
|
975
974
|
* Converts a `Task<A>` into a `Task<Result<E, A>>`, resolving to `Err` if the
|
|
976
|
-
* Task does not complete within the given
|
|
977
|
-
* `AbortSignal` that fires when the deadline passes, so operations
|
|
975
|
+
* Task does not complete within the given duration. The inner Task receives an
|
|
976
|
+
* `AbortSignal` that fires when the deadline passes, so asynchronous operations
|
|
978
977
|
* that accept a signal are cancelled rather than left dangling.
|
|
979
978
|
*
|
|
980
979
|
* @example
|
|
@@ -986,7 +985,7 @@ declare namespace Task {
|
|
|
986
985
|
* );
|
|
987
986
|
* ```
|
|
988
987
|
*/
|
|
989
|
-
const timeout: <E>(
|
|
988
|
+
const timeout: <E>(duration: Duration, onTimeout: () => E) => <A>(task: Task<A>) => Task<Result<E, A>>;
|
|
990
989
|
/**
|
|
991
990
|
* Creates a Task paired with an `abort` handle. Calling `abort()` cancels the
|
|
992
991
|
* current in-flight call immediately. Unlike a one-shot abort, calling `task()`
|
|
@@ -1018,7 +1017,7 @@ declare namespace Task {
|
|
|
1018
1017
|
* @example
|
|
1019
1018
|
* ```ts
|
|
1020
1019
|
* const name = await pipe(
|
|
1021
|
-
*
|
|
1020
|
+
* loadConfig,
|
|
1022
1021
|
* Task.map(config => config.name),
|
|
1023
1022
|
* Task.run(),
|
|
1024
1023
|
* );
|
|
@@ -1027,4 +1026,4 @@ declare namespace Task {
|
|
|
1027
1026
|
const run: (signal?: AbortSignal) => <A>(task: Task<A>) => Promise<A>;
|
|
1028
1027
|
}
|
|
1029
1028
|
|
|
1030
|
-
export { Deferred as D, Equality 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
|
|
1029
|
+
export { Deferred as D, Equality 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 Err as a, Ordering as b, type WithLog as c, type WithKind as d, type WithError as e, type RetryOptions as f, type TimeoutOptions as g, type WithTimeout as h, type WithMinInterval as i, type WithCooldown as j, type WithConcurrency as k, type WithSize as l, type WithDuration as m, type WithN as n, type WithErrors as o, type WithFirst as p, type WithSecond as q };
|