@nlozgachev/pipelined 0.63.0 → 0.65.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,238 @@
1
+ //#region src/Types/Brand.d.ts
2
+ declare const _brand: unique symbol;
3
+ /**
4
+ * Brand<K, T> creates a nominal type by tagging T with a phantom brand K.
5
+ * Prevents accidentally mixing up values that share the same underlying type.
6
+ *
7
+ * @example
8
+ * ```ts
9
+ * type UserId = Brand<"UserId", string>;
10
+ * type ProductId = Brand<"ProductId", string>;
11
+ *
12
+ * const toUserId = Brand.wrap<"UserId", string>();
13
+ * const toProductId = Brand.wrap<"ProductId", string>();
14
+ *
15
+ * const userId: UserId = toUserId("user-123");
16
+ * const productId: ProductId = toProductId("prod-456");
17
+ *
18
+ * // Type error: ProductId is not assignable to UserId
19
+ * // const wrong: UserId = productId;
20
+ * ```
21
+ */
22
+ type Brand<K extends string, T> = T & {
23
+ readonly [_brand]: K;
24
+ };
25
+ declare const Brand: {
26
+ /**
27
+ * Returns a constructor that wraps a value of type T in brand K.
28
+ * The resulting function performs an unchecked cast — only use when the raw
29
+ * value is known to satisfy the brand's invariants.
30
+ *
31
+ * @example
32
+ * ```ts
33
+ * type PositiveNumber = Brand<"PositiveNumber", number>;
34
+ * const toPositiveNumber = Brand.wrap<"PositiveNumber", number>();
35
+ *
36
+ * const n: PositiveNumber = toPositiveNumber(42);
37
+ * ```
38
+ */
39
+ wrap: <K extends string, T>() => (value: T) => Brand<K, T>;
40
+ /**
41
+ * Strips the brand and returns the underlying value.
42
+ * Since Brand<K, T> extends T this is rarely needed, but can improve readability.
43
+ *
44
+ * @example
45
+ * ```ts
46
+ * type UserId = Brand<"UserId", string>;
47
+ * const toUserId = Brand.wrap<"UserId", string>();
48
+ * const userId: UserId = toUserId("user-123");
49
+ * const raw: string = Brand.unwrap(userId); // "user-123"
50
+ * ```
51
+ */
52
+ unwrap: <K extends string, T>(branded: Brand<K, T>) => T;
53
+ };
54
+ //#endregion
55
+ //#region src/Types/Duration.d.ts
56
+ /**
57
+ * A branded nominal type representing a duration of time in milliseconds.
58
+ * Use Duration to ensure safe time-based operators and clear unit conversions.
59
+ *
60
+ * @example
61
+ * ```ts
62
+ * const halfSecond = Duration.milliseconds(500);
63
+ * const twoSeconds = Duration.seconds(2);
64
+ * const total = pipe(halfSecond, Duration.add(twoSeconds));
65
+ *
66
+ * Duration.to.seconds(total); // 2.5
67
+ * ```
68
+ */
69
+ type Duration = Brand<"Duration", number>;
70
+ declare const Duration: {
71
+ /**
72
+ * Creates a Duration from milliseconds.
73
+ *
74
+ * @example
75
+ * ```ts
76
+ * Duration.milliseconds(500); // 500ms Duration
77
+ * ```
78
+ */
79
+ milliseconds: (ms: number) => Duration;
80
+ /**
81
+ * Creates a Duration from seconds.
82
+ *
83
+ * @example
84
+ * ```ts
85
+ * Duration.seconds(2); // 2000ms Duration
86
+ * ```
87
+ */
88
+ seconds: (s: number) => Duration;
89
+ /**
90
+ * Creates a Duration from minutes.
91
+ *
92
+ * @example
93
+ * ```ts
94
+ * Duration.minutes(5); // 300000ms Duration
95
+ * ```
96
+ */
97
+ minutes: (m: number) => Duration;
98
+ /**
99
+ * Creates a Duration from hours.
100
+ *
101
+ * @example
102
+ * ```ts
103
+ * Duration.hours(1); // 3600000ms Duration
104
+ * ```
105
+ */
106
+ hours: (h: number) => Duration;
107
+ /**
108
+ * Creates a Duration from days.
109
+ *
110
+ * @example
111
+ * ```ts
112
+ * Duration.days(1); // 86400000ms Duration
113
+ * ```
114
+ */
115
+ days: (d: number) => Duration;
116
+ to: {
117
+ /**
118
+ * Converts a Duration back to raw milliseconds.
119
+ *
120
+ * @example
121
+ * ```ts
122
+ * Duration.to.milliseconds(Duration.seconds(2)); // 2000
123
+ * ```
124
+ */
125
+ milliseconds: (d: Duration) => number;
126
+ /**
127
+ * Converts a Duration to seconds.
128
+ *
129
+ * @example
130
+ * ```ts
131
+ * Duration.to.seconds(Duration.milliseconds(2500)); // 2.5
132
+ * ```
133
+ */
134
+ seconds: (d: Duration) => number;
135
+ /**
136
+ * Converts a Duration to minutes.
137
+ *
138
+ * @example
139
+ * ```ts
140
+ * Duration.to.minutes(Duration.seconds(120)); // 2
141
+ * ```
142
+ */
143
+ minutes: (d: Duration) => number;
144
+ /**
145
+ * Converts a Duration to hours.
146
+ *
147
+ * @example
148
+ * ```ts
149
+ * Duration.to.hours(Duration.minutes(90)); // 1.5
150
+ * ```
151
+ */
152
+ hours: (d: Duration) => number;
153
+ /**
154
+ * Converts a Duration to days.
155
+ *
156
+ * @example
157
+ * ```ts
158
+ * Duration.to.days(Duration.hours(36)); // 1.5
159
+ * ```
160
+ */
161
+ days: (d: Duration) => number;
162
+ };
163
+ /**
164
+ * Adds two Durations together.
165
+ *
166
+ * @example
167
+ * ```ts
168
+ * pipe(Duration.seconds(1), Duration.add(Duration.milliseconds(500))); // 1500ms
169
+ * ```
170
+ */
171
+ add: (other: Duration) => (self: Duration) => Duration;
172
+ /**
173
+ * Subtracts the other Duration from this one.
174
+ *
175
+ * @example
176
+ * ```ts
177
+ * pipe(Duration.seconds(1), Duration.subtract(Duration.milliseconds(500))); // 500ms
178
+ * ```
179
+ */
180
+ subtract: (other: Duration) => (self: Duration) => Duration;
181
+ };
182
+ //#endregion
183
+ //#region src/Types/RetryPolicy.d.ts
184
+ /**
185
+ * An immutable policy describing retry limits and backoff delay strategies.
186
+ *
187
+ * @example
188
+ * ```ts
189
+ * const policy: RetryPolicy = RetryPolicy.constant({
190
+ * attempts: 3,
191
+ * delay: Duration.seconds(1),
192
+ * });
193
+ * ```
194
+ */
195
+ type RetryPolicy = {
196
+ readonly attempts: number;
197
+ readonly getDelay: (attempt: number) => Duration;
198
+ };
199
+ declare const RetryPolicy: {
200
+ /**
201
+ * Creates a RetryPolicy with a constant delay between retry attempts.
202
+ *
203
+ * @example
204
+ * ```ts
205
+ * const policy = RetryPolicy.constant({
206
+ * attempts: 3,
207
+ * delay: Duration.seconds(1),
208
+ * });
209
+ * ```
210
+ */
211
+ constant: (options: {
212
+ attempts: number;
213
+ delay: Duration;
214
+ }) => RetryPolicy;
215
+ /**
216
+ * Creates a RetryPolicy with exponential backoff delays between attempts.
217
+ * An optional `factor` (default 2) controls the growth rate.
218
+ * An optional `jitter` (default false) adds randomized variance to prevent thundering herd problems.
219
+ *
220
+ * @example
221
+ * ```ts
222
+ * const policy = RetryPolicy.exponential({
223
+ * attempts: 5,
224
+ * initial: Duration.milliseconds(100),
225
+ * factor: 2,
226
+ * jitter: true,
227
+ * });
228
+ * ```
229
+ */
230
+ exponential: (options: {
231
+ attempts: number;
232
+ initial: Duration;
233
+ factor?: number;
234
+ jitter?: boolean;
235
+ }) => RetryPolicy;
236
+ };
237
+ //#endregion
238
+ export { Duration as n, Brand as r, RetryPolicy as t };
@@ -0,0 +1,238 @@
1
+ //#region src/Types/Brand.d.ts
2
+ declare const _brand: unique symbol;
3
+ /**
4
+ * Brand<K, T> creates a nominal type by tagging T with a phantom brand K.
5
+ * Prevents accidentally mixing up values that share the same underlying type.
6
+ *
7
+ * @example
8
+ * ```ts
9
+ * type UserId = Brand<"UserId", string>;
10
+ * type ProductId = Brand<"ProductId", string>;
11
+ *
12
+ * const toUserId = Brand.wrap<"UserId", string>();
13
+ * const toProductId = Brand.wrap<"ProductId", string>();
14
+ *
15
+ * const userId: UserId = toUserId("user-123");
16
+ * const productId: ProductId = toProductId("prod-456");
17
+ *
18
+ * // Type error: ProductId is not assignable to UserId
19
+ * // const wrong: UserId = productId;
20
+ * ```
21
+ */
22
+ type Brand<K extends string, T> = T & {
23
+ readonly [_brand]: K;
24
+ };
25
+ declare const Brand: {
26
+ /**
27
+ * Returns a constructor that wraps a value of type T in brand K.
28
+ * The resulting function performs an unchecked cast — only use when the raw
29
+ * value is known to satisfy the brand's invariants.
30
+ *
31
+ * @example
32
+ * ```ts
33
+ * type PositiveNumber = Brand<"PositiveNumber", number>;
34
+ * const toPositiveNumber = Brand.wrap<"PositiveNumber", number>();
35
+ *
36
+ * const n: PositiveNumber = toPositiveNumber(42);
37
+ * ```
38
+ */
39
+ wrap: <K extends string, T>() => (value: T) => Brand<K, T>;
40
+ /**
41
+ * Strips the brand and returns the underlying value.
42
+ * Since Brand<K, T> extends T this is rarely needed, but can improve readability.
43
+ *
44
+ * @example
45
+ * ```ts
46
+ * type UserId = Brand<"UserId", string>;
47
+ * const toUserId = Brand.wrap<"UserId", string>();
48
+ * const userId: UserId = toUserId("user-123");
49
+ * const raw: string = Brand.unwrap(userId); // "user-123"
50
+ * ```
51
+ */
52
+ unwrap: <K extends string, T>(branded: Brand<K, T>) => T;
53
+ };
54
+ //#endregion
55
+ //#region src/Types/Duration.d.ts
56
+ /**
57
+ * A branded nominal type representing a duration of time in milliseconds.
58
+ * Use Duration to ensure safe time-based operators and clear unit conversions.
59
+ *
60
+ * @example
61
+ * ```ts
62
+ * const halfSecond = Duration.milliseconds(500);
63
+ * const twoSeconds = Duration.seconds(2);
64
+ * const total = pipe(halfSecond, Duration.add(twoSeconds));
65
+ *
66
+ * Duration.to.seconds(total); // 2.5
67
+ * ```
68
+ */
69
+ type Duration = Brand<"Duration", number>;
70
+ declare const Duration: {
71
+ /**
72
+ * Creates a Duration from milliseconds.
73
+ *
74
+ * @example
75
+ * ```ts
76
+ * Duration.milliseconds(500); // 500ms Duration
77
+ * ```
78
+ */
79
+ milliseconds: (ms: number) => Duration;
80
+ /**
81
+ * Creates a Duration from seconds.
82
+ *
83
+ * @example
84
+ * ```ts
85
+ * Duration.seconds(2); // 2000ms Duration
86
+ * ```
87
+ */
88
+ seconds: (s: number) => Duration;
89
+ /**
90
+ * Creates a Duration from minutes.
91
+ *
92
+ * @example
93
+ * ```ts
94
+ * Duration.minutes(5); // 300000ms Duration
95
+ * ```
96
+ */
97
+ minutes: (m: number) => Duration;
98
+ /**
99
+ * Creates a Duration from hours.
100
+ *
101
+ * @example
102
+ * ```ts
103
+ * Duration.hours(1); // 3600000ms Duration
104
+ * ```
105
+ */
106
+ hours: (h: number) => Duration;
107
+ /**
108
+ * Creates a Duration from days.
109
+ *
110
+ * @example
111
+ * ```ts
112
+ * Duration.days(1); // 86400000ms Duration
113
+ * ```
114
+ */
115
+ days: (d: number) => Duration;
116
+ to: {
117
+ /**
118
+ * Converts a Duration back to raw milliseconds.
119
+ *
120
+ * @example
121
+ * ```ts
122
+ * Duration.to.milliseconds(Duration.seconds(2)); // 2000
123
+ * ```
124
+ */
125
+ milliseconds: (d: Duration) => number;
126
+ /**
127
+ * Converts a Duration to seconds.
128
+ *
129
+ * @example
130
+ * ```ts
131
+ * Duration.to.seconds(Duration.milliseconds(2500)); // 2.5
132
+ * ```
133
+ */
134
+ seconds: (d: Duration) => number;
135
+ /**
136
+ * Converts a Duration to minutes.
137
+ *
138
+ * @example
139
+ * ```ts
140
+ * Duration.to.minutes(Duration.seconds(120)); // 2
141
+ * ```
142
+ */
143
+ minutes: (d: Duration) => number;
144
+ /**
145
+ * Converts a Duration to hours.
146
+ *
147
+ * @example
148
+ * ```ts
149
+ * Duration.to.hours(Duration.minutes(90)); // 1.5
150
+ * ```
151
+ */
152
+ hours: (d: Duration) => number;
153
+ /**
154
+ * Converts a Duration to days.
155
+ *
156
+ * @example
157
+ * ```ts
158
+ * Duration.to.days(Duration.hours(36)); // 1.5
159
+ * ```
160
+ */
161
+ days: (d: Duration) => number;
162
+ };
163
+ /**
164
+ * Adds two Durations together.
165
+ *
166
+ * @example
167
+ * ```ts
168
+ * pipe(Duration.seconds(1), Duration.add(Duration.milliseconds(500))); // 1500ms
169
+ * ```
170
+ */
171
+ add: (other: Duration) => (self: Duration) => Duration;
172
+ /**
173
+ * Subtracts the other Duration from this one.
174
+ *
175
+ * @example
176
+ * ```ts
177
+ * pipe(Duration.seconds(1), Duration.subtract(Duration.milliseconds(500))); // 500ms
178
+ * ```
179
+ */
180
+ subtract: (other: Duration) => (self: Duration) => Duration;
181
+ };
182
+ //#endregion
183
+ //#region src/Types/RetryPolicy.d.ts
184
+ /**
185
+ * An immutable policy describing retry limits and backoff delay strategies.
186
+ *
187
+ * @example
188
+ * ```ts
189
+ * const policy: RetryPolicy = RetryPolicy.constant({
190
+ * attempts: 3,
191
+ * delay: Duration.seconds(1),
192
+ * });
193
+ * ```
194
+ */
195
+ type RetryPolicy = {
196
+ readonly attempts: number;
197
+ readonly getDelay: (attempt: number) => Duration;
198
+ };
199
+ declare const RetryPolicy: {
200
+ /**
201
+ * Creates a RetryPolicy with a constant delay between retry attempts.
202
+ *
203
+ * @example
204
+ * ```ts
205
+ * const policy = RetryPolicy.constant({
206
+ * attempts: 3,
207
+ * delay: Duration.seconds(1),
208
+ * });
209
+ * ```
210
+ */
211
+ constant: (options: {
212
+ attempts: number;
213
+ delay: Duration;
214
+ }) => RetryPolicy;
215
+ /**
216
+ * Creates a RetryPolicy with exponential backoff delays between attempts.
217
+ * An optional `factor` (default 2) controls the growth rate.
218
+ * An optional `jitter` (default false) adds randomized variance to prevent thundering herd problems.
219
+ *
220
+ * @example
221
+ * ```ts
222
+ * const policy = RetryPolicy.exponential({
223
+ * attempts: 5,
224
+ * initial: Duration.milliseconds(100),
225
+ * factor: 2,
226
+ * jitter: true,
227
+ * });
228
+ * ```
229
+ */
230
+ exponential: (options: {
231
+ attempts: number;
232
+ initial: Duration;
233
+ factor?: number;
234
+ jitter?: boolean;
235
+ }) => RetryPolicy;
236
+ };
237
+ //#endregion
238
+ export { Duration as n, Brand as r, RetryPolicy as t };