@nlozgachev/pipelined 0.41.0 → 0.43.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/InternalTypes-DsCqxWZm.d.mts +118 -0
- package/dist/InternalTypes-DuzMFAfJ.d.ts +118 -0
- package/dist/{Task-BprUabHP.d.mts → Validation-BOPLiDqa.d.ts} +875 -111
- package/dist/{Task-Dt3ZMen6.d.ts → Validation-Do6uWLLZ.d.mts} +875 -111
- package/dist/{chunk-GBB6LVLI.mjs → chunk-74JKKJ4R.mjs} +0 -4
- package/dist/{chunk-COGQKPIP.mjs → chunk-CHRXZIJU.mjs} +204 -180
- package/dist/{chunk-V37OUM35.mjs → chunk-W6RWKBDX.mjs} +157 -69
- package/dist/{chunk-TCE2UETM.mjs → chunk-X6XQX3OZ.mjs} +4 -4
- package/dist/composition.d.mts +45 -44
- package/dist/composition.d.ts +45 -44
- package/dist/composition.js +3 -3
- package/dist/composition.mjs +2 -2
- package/dist/core.d.mts +10 -812
- package/dist/core.d.ts +10 -812
- package/dist/core.js +202 -182
- package/dist/core.mjs +2 -8
- package/dist/index.d.mts +5 -5
- package/dist/index.d.ts +5 -5
- package/dist/index.js +359 -254
- package/dist/index.mjs +5 -13
- package/dist/types.d.mts +112 -17
- package/dist/types.d.ts +112 -17
- package/dist/types.js +2 -7
- package/dist/types.mjs +3 -5
- package/dist/utils.d.mts +345 -89
- package/dist/utils.d.ts +345 -89
- package/dist/utils.js +456 -152
- package/dist/utils.mjs +3 -3
- package/package.json +2 -2
- package/dist/Duration-BTeT9D-q.d.mts +0 -127
- package/dist/Duration-BTeT9D-q.d.ts +0 -127
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
import { Duration } from './types.mjs';
|
|
2
|
+
|
|
3
|
+
declare const _deferred: unique symbol;
|
|
4
|
+
/**
|
|
5
|
+
* A nominally typed, one-shot async value that supports `await` but enforces infallibility.
|
|
6
|
+
*
|
|
7
|
+
* Two design choices work together to make the guarantee structural rather than documentary:
|
|
8
|
+
*
|
|
9
|
+
* - The phantom `[_deferred]` symbol makes the type **nominal**: only values produced by
|
|
10
|
+
* `Deferred.fromPromise` satisfy it. A plain object `{ then: ... }` does not.
|
|
11
|
+
* - The single-parameter `.then()` **excludes rejection handlers** by construction. There is
|
|
12
|
+
* no second argument to pass, so chaining and `.catch()` are impossible.
|
|
13
|
+
*
|
|
14
|
+
* This makes `Deferred<A>` the natural return type for `Task<A>`, which is guaranteed to
|
|
15
|
+
* never reject.
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* ```ts
|
|
19
|
+
* const value = await Deferred.fromPromise(Promise.resolve(42));
|
|
20
|
+
* // value === 42
|
|
21
|
+
* ```
|
|
22
|
+
*/
|
|
23
|
+
type Deferred<A> = {
|
|
24
|
+
readonly [_deferred]: A;
|
|
25
|
+
readonly then: (onfulfilled: (value: A) => unknown) => void;
|
|
26
|
+
};
|
|
27
|
+
declare namespace Deferred {
|
|
28
|
+
/**
|
|
29
|
+
* Wraps a `Promise` or `Deferred` into a `Deferred`, structurally excluding rejection handlers,
|
|
30
|
+
* `.catch()`, `.finally()`, and chainable `.then()`.
|
|
31
|
+
*
|
|
32
|
+
* **Precondition**: `p` must never reject. If `p` rejects, the returned `Deferred` will
|
|
33
|
+
* never resolve — `await`-ing it will hang indefinitely. Use `TaskResult.tryCatch` to
|
|
34
|
+
* handle operations that may fail before converting to a `Deferred`.
|
|
35
|
+
*
|
|
36
|
+
* @example
|
|
37
|
+
* ```ts
|
|
38
|
+
* const d = Deferred.fromPromise(Promise.resolve("hello"));
|
|
39
|
+
* const value = await d; // "hello"
|
|
40
|
+
* ```
|
|
41
|
+
*/
|
|
42
|
+
const fromPromise: <A>(p: Thenable<A>) => Deferred<A>;
|
|
43
|
+
/**
|
|
44
|
+
* Converts a `Deferred` back into a `Promise`.
|
|
45
|
+
*
|
|
46
|
+
* @example
|
|
47
|
+
* ```ts
|
|
48
|
+
* const p = Deferred.toPromise(Deferred.fromPromise(Promise.resolve(42)));
|
|
49
|
+
* // p is Promise<42>
|
|
50
|
+
* ```
|
|
51
|
+
*/
|
|
52
|
+
const toPromise: <A>(d: Deferred<A>) => Promise<A>;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Represents a promise-like object or a deferred value that can be resolved with `.then()`.
|
|
57
|
+
*/
|
|
58
|
+
type Thenable<A> = PromiseLike<A> | Deferred<A>;
|
|
59
|
+
/**
|
|
60
|
+
* Represents a value that can be either a synchronous value or a Thenable.
|
|
61
|
+
*/
|
|
62
|
+
type Awaitable<A> = A | Thenable<A>;
|
|
63
|
+
type NonEmptyArr<A> = readonly [A, ...A[]];
|
|
64
|
+
type WithKind<K extends string> = {
|
|
65
|
+
readonly kind: K;
|
|
66
|
+
};
|
|
67
|
+
type WithValue<T> = {
|
|
68
|
+
readonly value: T;
|
|
69
|
+
};
|
|
70
|
+
type WithError<T> = {
|
|
71
|
+
readonly error: T;
|
|
72
|
+
};
|
|
73
|
+
type WithErrors<T> = {
|
|
74
|
+
readonly errors: NonEmptyArr<T>;
|
|
75
|
+
};
|
|
76
|
+
type WithFirst<T> = {
|
|
77
|
+
readonly first: T;
|
|
78
|
+
};
|
|
79
|
+
type WithSecond<T> = {
|
|
80
|
+
readonly second: T;
|
|
81
|
+
};
|
|
82
|
+
type WithLog<T> = {
|
|
83
|
+
readonly log: ReadonlyArray<T>;
|
|
84
|
+
};
|
|
85
|
+
/** Retry policy for `Op.interpret`. */
|
|
86
|
+
type RetryOptions<E> = {
|
|
87
|
+
readonly attempts: number;
|
|
88
|
+
readonly backoff?: Duration | ((attempt: number) => Duration);
|
|
89
|
+
readonly when?: (error: E) => boolean;
|
|
90
|
+
};
|
|
91
|
+
/** Timeout policy for `Op.interpret`. Wraps the entire retry sequence. */
|
|
92
|
+
type TimeoutOptions<E> = {
|
|
93
|
+
readonly duration: Duration;
|
|
94
|
+
readonly onTimeout: () => E;
|
|
95
|
+
};
|
|
96
|
+
type WithTimeout<E> = {
|
|
97
|
+
readonly timeout?: TimeoutOptions<E>;
|
|
98
|
+
};
|
|
99
|
+
type WithDuration = {
|
|
100
|
+
readonly duration: Duration;
|
|
101
|
+
};
|
|
102
|
+
type WithN = {
|
|
103
|
+
readonly n: number;
|
|
104
|
+
};
|
|
105
|
+
type WithConcurrency = {
|
|
106
|
+
readonly concurrency?: number;
|
|
107
|
+
};
|
|
108
|
+
type WithSize = {
|
|
109
|
+
readonly size?: number;
|
|
110
|
+
};
|
|
111
|
+
type WithCooldown = {
|
|
112
|
+
readonly cooldown?: Duration;
|
|
113
|
+
};
|
|
114
|
+
type WithMinInterval = {
|
|
115
|
+
readonly minInterval?: Duration;
|
|
116
|
+
};
|
|
117
|
+
|
|
118
|
+
export { type Awaitable as A, Deferred as D, type NonEmptyArr as N, type RetryOptions as R, type Thenable as T, type WithConcurrency as W, type TimeoutOptions as a, type WithCooldown as b, type WithDuration as c, type WithError as d, type WithErrors as e, type WithFirst as f, type WithKind as g, type WithLog as h, type WithMinInterval as i, type WithN as j, type WithSecond as k, type WithSize as l, type WithTimeout as m, type WithValue as n };
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
import { Duration } from './types.js';
|
|
2
|
+
|
|
3
|
+
declare const _deferred: unique symbol;
|
|
4
|
+
/**
|
|
5
|
+
* A nominally typed, one-shot async value that supports `await` but enforces infallibility.
|
|
6
|
+
*
|
|
7
|
+
* Two design choices work together to make the guarantee structural rather than documentary:
|
|
8
|
+
*
|
|
9
|
+
* - The phantom `[_deferred]` symbol makes the type **nominal**: only values produced by
|
|
10
|
+
* `Deferred.fromPromise` satisfy it. A plain object `{ then: ... }` does not.
|
|
11
|
+
* - The single-parameter `.then()` **excludes rejection handlers** by construction. There is
|
|
12
|
+
* no second argument to pass, so chaining and `.catch()` are impossible.
|
|
13
|
+
*
|
|
14
|
+
* This makes `Deferred<A>` the natural return type for `Task<A>`, which is guaranteed to
|
|
15
|
+
* never reject.
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* ```ts
|
|
19
|
+
* const value = await Deferred.fromPromise(Promise.resolve(42));
|
|
20
|
+
* // value === 42
|
|
21
|
+
* ```
|
|
22
|
+
*/
|
|
23
|
+
type Deferred<A> = {
|
|
24
|
+
readonly [_deferred]: A;
|
|
25
|
+
readonly then: (onfulfilled: (value: A) => unknown) => void;
|
|
26
|
+
};
|
|
27
|
+
declare namespace Deferred {
|
|
28
|
+
/**
|
|
29
|
+
* Wraps a `Promise` or `Deferred` into a `Deferred`, structurally excluding rejection handlers,
|
|
30
|
+
* `.catch()`, `.finally()`, and chainable `.then()`.
|
|
31
|
+
*
|
|
32
|
+
* **Precondition**: `p` must never reject. If `p` rejects, the returned `Deferred` will
|
|
33
|
+
* never resolve — `await`-ing it will hang indefinitely. Use `TaskResult.tryCatch` to
|
|
34
|
+
* handle operations that may fail before converting to a `Deferred`.
|
|
35
|
+
*
|
|
36
|
+
* @example
|
|
37
|
+
* ```ts
|
|
38
|
+
* const d = Deferred.fromPromise(Promise.resolve("hello"));
|
|
39
|
+
* const value = await d; // "hello"
|
|
40
|
+
* ```
|
|
41
|
+
*/
|
|
42
|
+
const fromPromise: <A>(p: Thenable<A>) => Deferred<A>;
|
|
43
|
+
/**
|
|
44
|
+
* Converts a `Deferred` back into a `Promise`.
|
|
45
|
+
*
|
|
46
|
+
* @example
|
|
47
|
+
* ```ts
|
|
48
|
+
* const p = Deferred.toPromise(Deferred.fromPromise(Promise.resolve(42)));
|
|
49
|
+
* // p is Promise<42>
|
|
50
|
+
* ```
|
|
51
|
+
*/
|
|
52
|
+
const toPromise: <A>(d: Deferred<A>) => Promise<A>;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Represents a promise-like object or a deferred value that can be resolved with `.then()`.
|
|
57
|
+
*/
|
|
58
|
+
type Thenable<A> = PromiseLike<A> | Deferred<A>;
|
|
59
|
+
/**
|
|
60
|
+
* Represents a value that can be either a synchronous value or a Thenable.
|
|
61
|
+
*/
|
|
62
|
+
type Awaitable<A> = A | Thenable<A>;
|
|
63
|
+
type NonEmptyArr<A> = readonly [A, ...A[]];
|
|
64
|
+
type WithKind<K extends string> = {
|
|
65
|
+
readonly kind: K;
|
|
66
|
+
};
|
|
67
|
+
type WithValue<T> = {
|
|
68
|
+
readonly value: T;
|
|
69
|
+
};
|
|
70
|
+
type WithError<T> = {
|
|
71
|
+
readonly error: T;
|
|
72
|
+
};
|
|
73
|
+
type WithErrors<T> = {
|
|
74
|
+
readonly errors: NonEmptyArr<T>;
|
|
75
|
+
};
|
|
76
|
+
type WithFirst<T> = {
|
|
77
|
+
readonly first: T;
|
|
78
|
+
};
|
|
79
|
+
type WithSecond<T> = {
|
|
80
|
+
readonly second: T;
|
|
81
|
+
};
|
|
82
|
+
type WithLog<T> = {
|
|
83
|
+
readonly log: ReadonlyArray<T>;
|
|
84
|
+
};
|
|
85
|
+
/** Retry policy for `Op.interpret`. */
|
|
86
|
+
type RetryOptions<E> = {
|
|
87
|
+
readonly attempts: number;
|
|
88
|
+
readonly backoff?: Duration | ((attempt: number) => Duration);
|
|
89
|
+
readonly when?: (error: E) => boolean;
|
|
90
|
+
};
|
|
91
|
+
/** Timeout policy for `Op.interpret`. Wraps the entire retry sequence. */
|
|
92
|
+
type TimeoutOptions<E> = {
|
|
93
|
+
readonly duration: Duration;
|
|
94
|
+
readonly onTimeout: () => E;
|
|
95
|
+
};
|
|
96
|
+
type WithTimeout<E> = {
|
|
97
|
+
readonly timeout?: TimeoutOptions<E>;
|
|
98
|
+
};
|
|
99
|
+
type WithDuration = {
|
|
100
|
+
readonly duration: Duration;
|
|
101
|
+
};
|
|
102
|
+
type WithN = {
|
|
103
|
+
readonly n: number;
|
|
104
|
+
};
|
|
105
|
+
type WithConcurrency = {
|
|
106
|
+
readonly concurrency?: number;
|
|
107
|
+
};
|
|
108
|
+
type WithSize = {
|
|
109
|
+
readonly size?: number;
|
|
110
|
+
};
|
|
111
|
+
type WithCooldown = {
|
|
112
|
+
readonly cooldown?: Duration;
|
|
113
|
+
};
|
|
114
|
+
type WithMinInterval = {
|
|
115
|
+
readonly minInterval?: Duration;
|
|
116
|
+
};
|
|
117
|
+
|
|
118
|
+
export { type Awaitable as A, Deferred as D, type NonEmptyArr as N, type RetryOptions as R, type Thenable as T, type WithConcurrency as W, type TimeoutOptions as a, type WithCooldown as b, type WithDuration as c, type WithError as d, type WithErrors as e, type WithFirst as f, type WithKind as g, type WithLog as h, type WithMinInterval as i, type WithN as j, type WithSecond as k, type WithSize as l, type WithTimeout as m, type WithValue as n };
|