@nlozgachev/pipelined 0.64.0 → 0.66.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.
@@ -0,0 +1,143 @@
1
+ import { n as Duration } from "./index-Bs8En5LJ.cjs";
2
+ //#region src/Core/Deferred.d.ts
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.from.Promise` 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.from.Promise(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 const Deferred: {
28
+ from: {
29
+ /**
30
+ * Wraps a `Promise` or `Deferred` into a `Deferred`, structurally excluding rejection handlers,
31
+ * `.catch()`, `.finally()`, and chainable `.then()`.
32
+ *
33
+ * **Precondition**: `p` must never reject. If `p` rejects, the returned `Deferred` will
34
+ * never resolve — `await`-ing it will hang indefinitely. Use `Task.Result.tryCatch` to
35
+ * handle operations that may fail before converting to a `Deferred`.
36
+ *
37
+ * @example
38
+ * ```ts
39
+ * const d = Deferred.from.Promise(Promise.resolve("hello"));
40
+ * const value = await d; // "hello"
41
+ * ```
42
+ */
43
+ Promise: <A>(p: Thenable<A>) => Deferred<A>;
44
+ };
45
+ to: {
46
+ /**
47
+ * Converts a `Deferred` back into a `Promise`.
48
+ *
49
+ * @example
50
+ * ```ts
51
+ * const p = Deferred.to.Promise(Deferred.from.Promise(Promise.resolve(42)));
52
+ * // p is Promise<42>
53
+ * ```
54
+ */
55
+ Promise: <A>(d: Deferred<A>) => globalThis.Promise<A>;
56
+ };
57
+ /**
58
+ * Combines an array or tuple of `Deferred` values into a single `Deferred` of a tuple.
59
+ * Resolves when all input `Deferred`s resolve.
60
+ *
61
+ * @example
62
+ * ```ts
63
+ * const [a, b] = await Deferred.all([d1, d2]);
64
+ * ```
65
+ */
66
+ all: <T extends readonly Deferred<unknown>[]>(deferreds: T) => Deferred<{ [K in keyof T]: T[K] extends Deferred<infer A> ? A : never; }>;
67
+ /**
68
+ * Races multiple `Deferred` values and resolves with the first one to settle.
69
+ *
70
+ * @example
71
+ * ```ts
72
+ * const winner = await Deferred.race([d1, d2]);
73
+ * ```
74
+ */
75
+ race: <A>(deferreds: ReadonlyArray<Deferred<A>>) => Deferred<A>;
76
+ };
77
+ //#endregion
78
+ //#region src/internal/InternalTypes.d.ts
79
+ /**
80
+ * Represents a promise-like object or a deferred value that can be resolved with `.then()`.
81
+ */
82
+ type Thenable<A> = PromiseLike<A> | Deferred<A>;
83
+ /**
84
+ * Represents a value that can be either a synchronous value or a Thenable.
85
+ */
86
+ type Awaitable<A> = A | Thenable<A>;
87
+ type NonEmptyArr<A> = readonly [A, ...A[]];
88
+ type WithKind<K extends string> = {
89
+ readonly kind: K;
90
+ };
91
+ type WithValue<T> = {
92
+ readonly value: T;
93
+ };
94
+ type WithError<T> = {
95
+ readonly error: T;
96
+ };
97
+ type WithErrors<T> = {
98
+ readonly errors: NonEmptyArr<T>;
99
+ };
100
+ type WithFirst<T> = {
101
+ readonly first: T;
102
+ };
103
+ type WithSecond<T> = {
104
+ readonly second: T;
105
+ };
106
+ type WithLog<T> = {
107
+ readonly log: ReadonlyArray<T>;
108
+ };
109
+ /** Retry policy for `Op.interpret`. */
110
+ type RetryOptions<E> = {
111
+ readonly attempts: number;
112
+ readonly backoff?: Duration | ((attempt: number) => Duration);
113
+ readonly when?: (error: E) => boolean;
114
+ };
115
+ /** Timeout policy for `Op.interpret`. Wraps the entire retry sequence. */
116
+ type TimeoutOptions<E> = {
117
+ readonly duration: Duration;
118
+ readonly onTimeout: () => E;
119
+ };
120
+ type WithTimeout<E> = {
121
+ readonly timeout?: TimeoutOptions<E>;
122
+ };
123
+ type WithDuration = {
124
+ readonly duration: Duration;
125
+ };
126
+ type WithN = {
127
+ readonly n: number;
128
+ };
129
+ type WithConcurrency = {
130
+ readonly concurrency?: number;
131
+ };
132
+ type WithSize = {
133
+ readonly size?: number;
134
+ };
135
+ type WithCooldown = {
136
+ readonly cooldown?: Duration;
137
+ };
138
+ type WithMinInterval = {
139
+ readonly minInterval?: Duration;
140
+ };
141
+ type NonEmpty<T extends string> = `NonEmpty${T}`;
142
+ //#endregion
143
+ export { WithSecond as _, Thenable as a, WithValue as b, WithCooldown as c, WithErrors as d, WithFirst as f, WithN as g, WithMinInterval as h, RetryOptions as i, WithDuration as l, WithLog as m, NonEmpty as n, TimeoutOptions as o, WithKind as p, NonEmptyArr as r, WithConcurrency as s, Awaitable as t, WithError as u, WithSize as v, Deferred as x, WithTimeout as y };
@@ -0,0 +1,143 @@
1
+ import { n as Duration } from "./index-Bs8En5LJ.js";
2
+ //#region src/Core/Deferred.d.ts
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.from.Promise` 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.from.Promise(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 const Deferred: {
28
+ from: {
29
+ /**
30
+ * Wraps a `Promise` or `Deferred` into a `Deferred`, structurally excluding rejection handlers,
31
+ * `.catch()`, `.finally()`, and chainable `.then()`.
32
+ *
33
+ * **Precondition**: `p` must never reject. If `p` rejects, the returned `Deferred` will
34
+ * never resolve — `await`-ing it will hang indefinitely. Use `Task.Result.tryCatch` to
35
+ * handle operations that may fail before converting to a `Deferred`.
36
+ *
37
+ * @example
38
+ * ```ts
39
+ * const d = Deferred.from.Promise(Promise.resolve("hello"));
40
+ * const value = await d; // "hello"
41
+ * ```
42
+ */
43
+ Promise: <A>(p: Thenable<A>) => Deferred<A>;
44
+ };
45
+ to: {
46
+ /**
47
+ * Converts a `Deferred` back into a `Promise`.
48
+ *
49
+ * @example
50
+ * ```ts
51
+ * const p = Deferred.to.Promise(Deferred.from.Promise(Promise.resolve(42)));
52
+ * // p is Promise<42>
53
+ * ```
54
+ */
55
+ Promise: <A>(d: Deferred<A>) => globalThis.Promise<A>;
56
+ };
57
+ /**
58
+ * Combines an array or tuple of `Deferred` values into a single `Deferred` of a tuple.
59
+ * Resolves when all input `Deferred`s resolve.
60
+ *
61
+ * @example
62
+ * ```ts
63
+ * const [a, b] = await Deferred.all([d1, d2]);
64
+ * ```
65
+ */
66
+ all: <T extends readonly Deferred<unknown>[]>(deferreds: T) => Deferred<{ [K in keyof T]: T[K] extends Deferred<infer A> ? A : never; }>;
67
+ /**
68
+ * Races multiple `Deferred` values and resolves with the first one to settle.
69
+ *
70
+ * @example
71
+ * ```ts
72
+ * const winner = await Deferred.race([d1, d2]);
73
+ * ```
74
+ */
75
+ race: <A>(deferreds: ReadonlyArray<Deferred<A>>) => Deferred<A>;
76
+ };
77
+ //#endregion
78
+ //#region src/internal/InternalTypes.d.ts
79
+ /**
80
+ * Represents a promise-like object or a deferred value that can be resolved with `.then()`.
81
+ */
82
+ type Thenable<A> = PromiseLike<A> | Deferred<A>;
83
+ /**
84
+ * Represents a value that can be either a synchronous value or a Thenable.
85
+ */
86
+ type Awaitable<A> = A | Thenable<A>;
87
+ type NonEmptyArr<A> = readonly [A, ...A[]];
88
+ type WithKind<K extends string> = {
89
+ readonly kind: K;
90
+ };
91
+ type WithValue<T> = {
92
+ readonly value: T;
93
+ };
94
+ type WithError<T> = {
95
+ readonly error: T;
96
+ };
97
+ type WithErrors<T> = {
98
+ readonly errors: NonEmptyArr<T>;
99
+ };
100
+ type WithFirst<T> = {
101
+ readonly first: T;
102
+ };
103
+ type WithSecond<T> = {
104
+ readonly second: T;
105
+ };
106
+ type WithLog<T> = {
107
+ readonly log: ReadonlyArray<T>;
108
+ };
109
+ /** Retry policy for `Op.interpret`. */
110
+ type RetryOptions<E> = {
111
+ readonly attempts: number;
112
+ readonly backoff?: Duration | ((attempt: number) => Duration);
113
+ readonly when?: (error: E) => boolean;
114
+ };
115
+ /** Timeout policy for `Op.interpret`. Wraps the entire retry sequence. */
116
+ type TimeoutOptions<E> = {
117
+ readonly duration: Duration;
118
+ readonly onTimeout: () => E;
119
+ };
120
+ type WithTimeout<E> = {
121
+ readonly timeout?: TimeoutOptions<E>;
122
+ };
123
+ type WithDuration = {
124
+ readonly duration: Duration;
125
+ };
126
+ type WithN = {
127
+ readonly n: number;
128
+ };
129
+ type WithConcurrency = {
130
+ readonly concurrency?: number;
131
+ };
132
+ type WithSize = {
133
+ readonly size?: number;
134
+ };
135
+ type WithCooldown = {
136
+ readonly cooldown?: Duration;
137
+ };
138
+ type WithMinInterval = {
139
+ readonly minInterval?: Duration;
140
+ };
141
+ type NonEmpty<T extends string> = `NonEmpty${T}`;
142
+ //#endregion
143
+ export { WithSecond as _, Thenable as a, WithValue as b, WithCooldown as c, WithErrors as d, WithFirst as f, WithN as g, WithMinInterval as h, RetryOptions as i, WithDuration as l, WithLog as m, NonEmpty as n, TimeoutOptions as o, WithKind as p, NonEmptyArr as r, WithConcurrency as s, Awaitable as t, WithError as u, WithSize as v, Deferred as x, WithTimeout as y };