@anabranch/fs 0.1.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/LICENSE +21 -0
- package/README.md +45 -0
- package/esm/_dnt.polyfills.d.ts +7 -0
- package/esm/_dnt.polyfills.d.ts.map +1 -0
- package/esm/_dnt.polyfills.js +1 -0
- package/esm/anabranch/index.d.ts +44 -0
- package/esm/anabranch/index.d.ts.map +1 -0
- package/esm/anabranch/index.js +41 -0
- package/esm/anabranch/streams/channel.d.ts +15 -0
- package/esm/anabranch/streams/channel.d.ts.map +1 -0
- package/esm/anabranch/streams/channel.js +122 -0
- package/esm/anabranch/streams/source.d.ts +68 -0
- package/esm/anabranch/streams/source.d.ts.map +1 -0
- package/esm/anabranch/streams/source.js +72 -0
- package/esm/anabranch/streams/stream.d.ts +431 -0
- package/esm/anabranch/streams/stream.d.ts.map +1 -0
- package/esm/anabranch/streams/stream.js +625 -0
- package/esm/anabranch/streams/task.d.ts +117 -0
- package/esm/anabranch/streams/task.d.ts.map +1 -0
- package/esm/anabranch/streams/task.js +416 -0
- package/esm/anabranch/streams/util.d.ts +33 -0
- package/esm/anabranch/streams/util.d.ts.map +1 -0
- package/esm/anabranch/streams/util.js +18 -0
- package/esm/fs/dir.d.ts +17 -0
- package/esm/fs/dir.d.ts.map +1 -0
- package/esm/fs/dir.js +90 -0
- package/esm/fs/errors.d.ts +64 -0
- package/esm/fs/errors.d.ts.map +1 -0
- package/esm/fs/errors.js +125 -0
- package/esm/fs/glob_match.d.ts +15 -0
- package/esm/fs/glob_match.d.ts.map +1 -0
- package/esm/fs/glob_match.js +73 -0
- package/esm/fs/index.d.ts +38 -0
- package/esm/fs/index.d.ts.map +1 -0
- package/esm/fs/index.js +31 -0
- package/esm/fs/read.d.ts +22 -0
- package/esm/fs/read.d.ts.map +1 -0
- package/esm/fs/read.js +75 -0
- package/esm/fs/types.d.ts +67 -0
- package/esm/fs/types.d.ts.map +1 -0
- package/esm/fs/types.js +1 -0
- package/esm/fs/watch.d.ts +17 -0
- package/esm/fs/watch.d.ts.map +1 -0
- package/esm/fs/watch.js +37 -0
- package/esm/fs/write.d.ts +16 -0
- package/esm/fs/write.d.ts.map +1 -0
- package/esm/fs/write.js +42 -0
- package/esm/package.json +3 -0
- package/package.json +24 -0
|
@@ -0,0 +1,431 @@
|
|
|
1
|
+
import { type Promisable, type Result } from "./util.js";
|
|
2
|
+
/**
|
|
3
|
+
* A TypeScript library that provides a powerful and flexible way to handle
|
|
4
|
+
* errors in asynchronous streams. It allows you to collect and manage errors
|
|
5
|
+
* alongside successful values in a stream, enabling you to process data while
|
|
6
|
+
* gracefully handling any issues that may arise.
|
|
7
|
+
*
|
|
8
|
+
* The core concept is the `Stream`, which is an asynchronous iterable that
|
|
9
|
+
* emits results as either successful values or errors. You can use various
|
|
10
|
+
* methods on the `Stream` to transform, filter, and reduce both successful
|
|
11
|
+
* values and errors in a way that suits your application's needs.
|
|
12
|
+
*/
|
|
13
|
+
export interface Stream<T, E> extends AsyncIterable<Result<T, E>> {
|
|
14
|
+
/**
|
|
15
|
+
* Similar to `Array.prototype.map`, but works on the stream of results. If the provided function throws an error or returns a rejected promise, the error will be collected and emitted as an error result in the stream.
|
|
16
|
+
*
|
|
17
|
+
* When concurrency is greater than 1, results may be emitted out of order.
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* ```ts
|
|
21
|
+
* import { Stream } from "anabranch";
|
|
22
|
+
*
|
|
23
|
+
* const stream = Source.from<number, string>(async function* () {
|
|
24
|
+
* yield 1;
|
|
25
|
+
* yield 2;
|
|
26
|
+
* });
|
|
27
|
+
*
|
|
28
|
+
* const mappedStream = stream.map(async (value) => {
|
|
29
|
+
* if (value === 2) {
|
|
30
|
+
* throw new Error("Value cannot be 2");
|
|
31
|
+
* }
|
|
32
|
+
* return value * 2;
|
|
33
|
+
* });
|
|
34
|
+
* ```
|
|
35
|
+
* @see {@link Stream.mapErr}
|
|
36
|
+
*/
|
|
37
|
+
map<U>(fn: (value: T) => Promisable<U>): Stream<U, E>;
|
|
38
|
+
/**
|
|
39
|
+
* Maps successful values with `fn` and transforms errors with `errFn`. Both
|
|
40
|
+
* receive the original value so you can contextualize the mapping.
|
|
41
|
+
*
|
|
42
|
+
* @example
|
|
43
|
+
* ```ts
|
|
44
|
+
* import { Source } from "anabranch";
|
|
45
|
+
*
|
|
46
|
+
* const stream = Source.from<number, Error>(async function* () {
|
|
47
|
+
* yield 1;
|
|
48
|
+
* throw new Error("failed");
|
|
49
|
+
* yield 3;
|
|
50
|
+
* });
|
|
51
|
+
*
|
|
52
|
+
* const result = stream.tryMap(
|
|
53
|
+
* (value) => value * 2,
|
|
54
|
+
* (err, value) => new Error(`Failed on ${value}: ${err.message}`),
|
|
55
|
+
* );
|
|
56
|
+
* ```
|
|
57
|
+
*
|
|
58
|
+
* @see {@link Stream.map}
|
|
59
|
+
* @see {@link Stream.mapErr}
|
|
60
|
+
*/
|
|
61
|
+
tryMap<U, F = never>(fn: (value: T) => Promisable<U>, errFn: (error: unknown, value: T) => Promisable<F>): Stream<U, E | F>;
|
|
62
|
+
/**
|
|
63
|
+
* Similar to `Array.prototype.flatMap`, but works on the stream of results. If the provided function throws an error or returns a rejected promise, the error will be collected and emitted as an error result in the stream.
|
|
64
|
+
*
|
|
65
|
+
* When concurrency is greater than 1, results may be emitted out of order.
|
|
66
|
+
*
|
|
67
|
+
* @example
|
|
68
|
+
* ```ts
|
|
69
|
+
* import { Source } from "anabranch";
|
|
70
|
+
*
|
|
71
|
+
* const stream = Source.from<number, string>(async function* () {
|
|
72
|
+
* yield 1;
|
|
73
|
+
* yield 2;
|
|
74
|
+
* });
|
|
75
|
+
*
|
|
76
|
+
* const flattened = stream.flatMap((value) => [value, value * 10]);
|
|
77
|
+
* ```
|
|
78
|
+
*/
|
|
79
|
+
flatMap<U>(fn: (value: T) => Promisable<AsyncIterable<U> | Iterable<U>>): Stream<U, E>;
|
|
80
|
+
/**
|
|
81
|
+
* Similar to `Array.prototype.filter`, but works on the stream of results. If the provided function throws an error or returns a rejected promise, the error will be collected and emitted as an error result in the stream.
|
|
82
|
+
*
|
|
83
|
+
* @example
|
|
84
|
+
* ```ts
|
|
85
|
+
* import { Stream } from "anabranch";
|
|
86
|
+
*
|
|
87
|
+
* const stream = Source.from<number, string>(async function* () {
|
|
88
|
+
* yield 1;
|
|
89
|
+
* yield 2;
|
|
90
|
+
* });
|
|
91
|
+
*
|
|
92
|
+
* const filteredStream = stream.filter(async (value) => {
|
|
93
|
+
* if (value === 2) {
|
|
94
|
+
* throw new Error("Value cannot be 2");
|
|
95
|
+
* }
|
|
96
|
+
* return value % 2 === 1;
|
|
97
|
+
* });
|
|
98
|
+
* ```
|
|
99
|
+
*
|
|
100
|
+
* @see {@link Stream.filterErr}
|
|
101
|
+
*/
|
|
102
|
+
filter<U extends T>(fn: (value: T) => value is U): Stream<U, E>;
|
|
103
|
+
filter(fn: (value: T) => Promisable<boolean>): Stream<T, E>;
|
|
104
|
+
/**
|
|
105
|
+
* Runs a side-effect function on each successful value without transforming it. If the provided function throws an error or returns a rejected promise, the error will be collected and emitted as an error result in place of the original value.
|
|
106
|
+
*
|
|
107
|
+
* @example
|
|
108
|
+
* ```ts
|
|
109
|
+
* const stream = source.tap((value) => console.log("Got:", value));
|
|
110
|
+
* ```
|
|
111
|
+
*/
|
|
112
|
+
tap(fn: (value: T) => Promisable<void>): Stream<T, E>;
|
|
113
|
+
/**
|
|
114
|
+
* Runs a side-effect function on each error without transforming it. If the provided function throws an error or returns a rejected promise, the new error replaces the original.
|
|
115
|
+
*
|
|
116
|
+
* @example
|
|
117
|
+
* ```ts
|
|
118
|
+
* const stream = source.tapErr((error) => console.error("Error:", error));
|
|
119
|
+
* ```
|
|
120
|
+
*/
|
|
121
|
+
tapErr(fn: (error: E) => Promisable<void>): Stream<T, E>;
|
|
122
|
+
/**
|
|
123
|
+
* Limits the stream to at most `n` successful values. Errors pass through
|
|
124
|
+
* without counting against the limit. After `n` successes are yielded, the
|
|
125
|
+
* stream stops immediately (any pending errors from earlier in the pipeline
|
|
126
|
+
* may still be yielded before stopping).
|
|
127
|
+
*
|
|
128
|
+
* @example
|
|
129
|
+
* ```ts
|
|
130
|
+
* const first3 = source.take(3);
|
|
131
|
+
* ```
|
|
132
|
+
*/
|
|
133
|
+
take(n: number): Stream<T, E>;
|
|
134
|
+
/**
|
|
135
|
+
* Yields successful values while the predicate returns true. Once the predicate returns false, iteration stops. Errors pass through until the stream is stopped. If the predicate throws, an error result is emitted and iteration stops.
|
|
136
|
+
*
|
|
137
|
+
* @example
|
|
138
|
+
* ```ts
|
|
139
|
+
* const belowTen = source.takeWhile((value) => value < 10);
|
|
140
|
+
* ```
|
|
141
|
+
*/
|
|
142
|
+
takeWhile(fn: (value: T) => Promisable<boolean>): Stream<T, E>;
|
|
143
|
+
/**
|
|
144
|
+
* Similar to `Array.prototype.reduce`, but works on the stream of results. If the provided function throws an error or returns a rejected promise, the error will be collected and emitted as an error result in the stream.
|
|
145
|
+
*
|
|
146
|
+
* If any error results are present in the stream, they will be thrown as an
|
|
147
|
+
* `AggregateError` after the stream is exhausted. Use `filterErr(() => false)`
|
|
148
|
+
* upstream to explicitly drop errors if you want to fold only the successes.
|
|
149
|
+
*
|
|
150
|
+
* @example
|
|
151
|
+
* ```ts
|
|
152
|
+
* import { Stream } from "anabranch";
|
|
153
|
+
*
|
|
154
|
+
* const stream = Source.from<number, string>(async function* () {
|
|
155
|
+
* yield 1;
|
|
156
|
+
* yield 2;
|
|
157
|
+
* });
|
|
158
|
+
*
|
|
159
|
+
* const sum = await stream.fold(async (acc, value) => {
|
|
160
|
+
* if (value === 2) {
|
|
161
|
+
* throw new Error("Value cannot be 2");
|
|
162
|
+
* }
|
|
163
|
+
* return acc + value;
|
|
164
|
+
* }, 0);
|
|
165
|
+
*
|
|
166
|
+
* console.log("Sum:", sum);
|
|
167
|
+
* ```
|
|
168
|
+
*
|
|
169
|
+
* @throws {AggregateError} If any error results were present in the stream.
|
|
170
|
+
* @see {@link Stream.foldErr}
|
|
171
|
+
*/
|
|
172
|
+
fold<U>(fn: (acc: U, value: T) => Promisable<U>, initialValue: U): Promise<U>;
|
|
173
|
+
/**
|
|
174
|
+
* Like `fold` but emits the running accumulator after each successful value,
|
|
175
|
+
* allowing downstream operations to react to intermediate states.
|
|
176
|
+
*
|
|
177
|
+
* @example
|
|
178
|
+
* ```ts
|
|
179
|
+
* import { Source } from "anabranch";
|
|
180
|
+
*
|
|
181
|
+
* const stream = Source.from<number, Error>(async function* () {
|
|
182
|
+
* yield 1;
|
|
183
|
+
* yield 2;
|
|
184
|
+
* yield 3;
|
|
185
|
+
* });
|
|
186
|
+
*
|
|
187
|
+
* const scanned = stream.scan((sum, n) => sum + n, 0);
|
|
188
|
+
* // Emits: { type: "success", value: 1 }, { type: "success", value: 3 }, { type: "success", value: 6 }
|
|
189
|
+
* ```
|
|
190
|
+
* @see {@link Stream.fold}
|
|
191
|
+
*/
|
|
192
|
+
scan<U>(fn: (acc: U, value: T) => Promisable<U>, initialValue: U): Stream<U, E>;
|
|
193
|
+
/**
|
|
194
|
+
* Similar to `Array.prototype.map`, but works on the stream of errors. If the provided function throws an error or returns a rejected promise, the new error will be collected and emitted as an error result in the stream.
|
|
195
|
+
*
|
|
196
|
+
* @example
|
|
197
|
+
* ```ts
|
|
198
|
+
* import { Stream } from "anabranch";
|
|
199
|
+
*
|
|
200
|
+
* const stream = Source.from<number, string>(async function* () {
|
|
201
|
+
* yield 1;
|
|
202
|
+
* yield 2;
|
|
203
|
+
* });
|
|
204
|
+
*
|
|
205
|
+
* const mappedErrorStream = stream.mapErr(async (error) => {
|
|
206
|
+
* return `Mapped error: ${error}`;
|
|
207
|
+
* });
|
|
208
|
+
* ```
|
|
209
|
+
*
|
|
210
|
+
* @see {@link Stream.map}
|
|
211
|
+
*/
|
|
212
|
+
mapErr<F>(fn: (error: E) => Promisable<F>): Stream<T, F>;
|
|
213
|
+
/**
|
|
214
|
+
* Similar to `Array.prototype.filter`, but works on the stream of errors. If the provided function throws an error or returns a rejected promise, the error will be collected and emitted as an error result in the stream.
|
|
215
|
+
*
|
|
216
|
+
* @example
|
|
217
|
+
* ```ts
|
|
218
|
+
* import { Stream } from "anabranch";
|
|
219
|
+
*
|
|
220
|
+
* const stream = Source.from<number, string>(async function* () {
|
|
221
|
+
* yield 1;
|
|
222
|
+
* yield 2;
|
|
223
|
+
* });
|
|
224
|
+
*
|
|
225
|
+
* const filteredErrorStream = stream.filterErr(async (error) => {
|
|
226
|
+
* return error.includes("Value cannot be 2");
|
|
227
|
+
* });
|
|
228
|
+
* ```
|
|
229
|
+
* @see {@link Stream.filter}
|
|
230
|
+
*/
|
|
231
|
+
filterErr<F extends E>(fn: (error: E) => error is F): Stream<T, F>;
|
|
232
|
+
filterErr(fn: (error: E) => Promisable<boolean>): Stream<T, E>;
|
|
233
|
+
/**
|
|
234
|
+
* Similar to `Array.prototype.reduce`, but works on the stream of errors. If the provided function throws an error or returns a rejected promise, the new error will be collected and emitted as an error result in the stream.
|
|
235
|
+
*
|
|
236
|
+
* @example
|
|
237
|
+
* ```ts
|
|
238
|
+
* import { Stream } from "anabranch";
|
|
239
|
+
*
|
|
240
|
+
* const stream = Source.from<number, string>(async function* () {
|
|
241
|
+
* yield 1;
|
|
242
|
+
* yield 2;
|
|
243
|
+
* });
|
|
244
|
+
*
|
|
245
|
+
* const concatenatedErrors = await stream.foldErr(async (acc, error) => {
|
|
246
|
+
* return `${acc}; ${error}`;
|
|
247
|
+
* }, "");
|
|
248
|
+
*
|
|
249
|
+
* console.log("Concatenated Errors:", concatenatedErrors);
|
|
250
|
+
* ```
|
|
251
|
+
* @see {@link Stream.fold}
|
|
252
|
+
*/
|
|
253
|
+
foldErr<F>(fn: (acc: F, error: E) => Promisable<F>, initialValue: F): Promise<F>;
|
|
254
|
+
/**
|
|
255
|
+
* Recovers from specific error types by applying the provided function to transform them into successful values. This allows you to handle specific errors gracefully while still collecting other errors in the stream.
|
|
256
|
+
* @example
|
|
257
|
+
* ```ts
|
|
258
|
+
* import { Stream } from "anabranch";
|
|
259
|
+
*
|
|
260
|
+
* const stream = Source.from<number, "aaaah!" | "eeeek!">(async function* () {
|
|
261
|
+
* yield 1;
|
|
262
|
+
* yield 2;
|
|
263
|
+
* });
|
|
264
|
+
*
|
|
265
|
+
* const recoveredStream = stream.recoverWhen(e => e === "aaaah!" as const, e => 42);
|
|
266
|
+
* ```
|
|
267
|
+
*/
|
|
268
|
+
recoverWhen<E2 extends E, U>(guard: (error: E) => error is E2, fn: (error: E2) => Promisable<U>): Stream<T | U, Exclude<E, E2>>;
|
|
269
|
+
/**
|
|
270
|
+
* Recovers from all errors by applying the provided function to transform them into successful values. This allows you to handle all errors gracefully while still collecting successful values in the stream.
|
|
271
|
+
* @example
|
|
272
|
+
* ```ts
|
|
273
|
+
* import { Stream } from "anabranch";
|
|
274
|
+
*
|
|
275
|
+
* const stream = Source.from<number, string>(async function* () {
|
|
276
|
+
* yield 1;
|
|
277
|
+
* yield 2;
|
|
278
|
+
* });
|
|
279
|
+
*
|
|
280
|
+
* const recoveredStream = stream.recover(e => 0);
|
|
281
|
+
* ```
|
|
282
|
+
*/
|
|
283
|
+
recover<U>(fn: (error: E) => Promisable<U>): Stream<T | U, never>;
|
|
284
|
+
/**
|
|
285
|
+
* Throws the specified error types if they are encountered in the stream. This allows you to handle specific errors immediately while continuing to process other errors.
|
|
286
|
+
* @example
|
|
287
|
+
* ```ts
|
|
288
|
+
* import { Stream } from "anabranch";
|
|
289
|
+
*
|
|
290
|
+
* const stream = Source.from<number, "aaaah!" | "eeeek!">(async function* () {
|
|
291
|
+
* yield 1;
|
|
292
|
+
* yield 2;
|
|
293
|
+
* });
|
|
294
|
+
*
|
|
295
|
+
* const streamWithThrownErrors = stream.throwOn(e => e === "eeeek!");
|
|
296
|
+
*
|
|
297
|
+
* try {
|
|
298
|
+
* for await (const value of streamWithThrownErrors.successes()) {
|
|
299
|
+
* console.log("Value:", value);
|
|
300
|
+
* }
|
|
301
|
+
* } catch (error) {
|
|
302
|
+
* console.error("Caught error:", error); // This will catch "eeeek!" errors thrown by throwOn
|
|
303
|
+
* }
|
|
304
|
+
* ```
|
|
305
|
+
*/
|
|
306
|
+
throwOn<E2 extends E>(guard: (error: E) => error is E2): Stream<T, Exclude<E, E2>>;
|
|
307
|
+
/**
|
|
308
|
+
* Returns an async iterable of all successful values emitted by the stream. If any errors were collected during the stream processing, they will be ignored in this iterable.
|
|
309
|
+
*
|
|
310
|
+
* @example
|
|
311
|
+
* ```ts
|
|
312
|
+
* import { Stream } from "anabranch";
|
|
313
|
+
*
|
|
314
|
+
* const stream = Source.from<number, string>(async function* () {
|
|
315
|
+
* yield 1;
|
|
316
|
+
* yield 2;
|
|
317
|
+
* });
|
|
318
|
+
*
|
|
319
|
+
* for await (const value of stream.successes()) {
|
|
320
|
+
* console.log("Success:", value);
|
|
321
|
+
* }
|
|
322
|
+
* ```
|
|
323
|
+
*/
|
|
324
|
+
successes(): AsyncIterable<T>;
|
|
325
|
+
/**
|
|
326
|
+
* Returns an async iterable of all errors collected during the stream processing. If any successful values were emitted during the stream processing, they will be ignored in this iterable.
|
|
327
|
+
*
|
|
328
|
+
* @example
|
|
329
|
+
* ```ts
|
|
330
|
+
* import { Stream } from "anabranch";
|
|
331
|
+
*
|
|
332
|
+
* const stream = Source.from<number, string>(async function* () {
|
|
333
|
+
* yield 1;
|
|
334
|
+
* yield 2;
|
|
335
|
+
* });
|
|
336
|
+
*
|
|
337
|
+
* for await (const error of stream.errors()) {
|
|
338
|
+
* console.error("Error:", error);
|
|
339
|
+
* }
|
|
340
|
+
* ```
|
|
341
|
+
*/
|
|
342
|
+
errors(): AsyncIterable<E>;
|
|
343
|
+
/**
|
|
344
|
+
* Collects all successful values emitted by the stream into an array. If any
|
|
345
|
+
* errors were collected during the stream processing, they will be thrown as
|
|
346
|
+
* an `AggregateError` containing all collected errors.
|
|
347
|
+
*
|
|
348
|
+
* @throws {AggregateError} If any errors were collected during the stream processing.
|
|
349
|
+
*/
|
|
350
|
+
collect(): Promise<T[]>;
|
|
351
|
+
/**
|
|
352
|
+
* Collects all results into separate `successes` and `errors` arrays. Unlike `collect()`, this never throws.
|
|
353
|
+
*
|
|
354
|
+
* @example
|
|
355
|
+
* ```ts
|
|
356
|
+
* const { successes, errors } = await source.partition();
|
|
357
|
+
* ```
|
|
358
|
+
*/
|
|
359
|
+
partition(): Promise<{
|
|
360
|
+
successes: T[];
|
|
361
|
+
errors: E[];
|
|
362
|
+
}>;
|
|
363
|
+
/**
|
|
364
|
+
* Collects all results emitted by the stream into an array of `Result`
|
|
365
|
+
* objects, which can represent either successful values or errors. This
|
|
366
|
+
* method allows you to see the full outcome of the stream processing,
|
|
367
|
+
* including both successes and errors, without throwing an aggregate error.
|
|
368
|
+
*/
|
|
369
|
+
toArray(): Promise<Result<T, E>[]>;
|
|
370
|
+
/**
|
|
371
|
+
* Collects consecutive successful values into fixed-size arrays. Errors pass
|
|
372
|
+
* through without breaking the current chunk.
|
|
373
|
+
*
|
|
374
|
+
* @example
|
|
375
|
+
* ```ts
|
|
376
|
+
* import { Source } from "anabranch";
|
|
377
|
+
*
|
|
378
|
+
* const stream = Source.from<number, Error>(async function* () {
|
|
379
|
+
* yield 1;
|
|
380
|
+
* yield 2;
|
|
381
|
+
* yield 3;
|
|
382
|
+
* yield 4;
|
|
383
|
+
* yield 5;
|
|
384
|
+
* });
|
|
385
|
+
*
|
|
386
|
+
* const chunked = stream.chunks(2);
|
|
387
|
+
* // Emits: { type: "success", value: [1, 2] }, { type: "success", value: [3, 4] }, { type: "success", value: [5] }
|
|
388
|
+
* ```
|
|
389
|
+
*/
|
|
390
|
+
chunks(size: number): Stream<T[], E>;
|
|
391
|
+
[Symbol.asyncIterator](): AsyncIterator<Result<T, E>>;
|
|
392
|
+
}
|
|
393
|
+
export declare class _StreamImpl<T, E> implements Stream<T, E> {
|
|
394
|
+
protected readonly source: () => AsyncGenerator<Result<T, E>>;
|
|
395
|
+
protected readonly concurrency: number;
|
|
396
|
+
protected readonly bufferSize: number;
|
|
397
|
+
constructor(source: () => AsyncGenerator<Result<T, E>>, concurrency?: number, bufferSize?: number);
|
|
398
|
+
toArray(): Promise<Result<T, E>[]>;
|
|
399
|
+
collect(): Promise<T[]>;
|
|
400
|
+
successes(): AsyncIterable<T>;
|
|
401
|
+
errors(): AsyncIterable<E>;
|
|
402
|
+
[Symbol.asyncIterator](): AsyncIterator<Result<T, E>>;
|
|
403
|
+
private transform;
|
|
404
|
+
private concurrentMap;
|
|
405
|
+
private concurrentTransform;
|
|
406
|
+
private sequentialMap;
|
|
407
|
+
private concurrentTryMap;
|
|
408
|
+
private concurrentFlatMap;
|
|
409
|
+
map<U>(fn: (value: T) => Promisable<U>): Stream<U, E>;
|
|
410
|
+
tryMap<U, F>(fn: (value: T) => Promisable<U>, errFn: (error: unknown, value: T) => Promisable<F>): Stream<U, E | F>;
|
|
411
|
+
flatMap<U>(fn: (value: T) => Promisable<AsyncIterable<U> | Iterable<U>>): Stream<U, E>;
|
|
412
|
+
filter(fn: (value: T) => Promisable<boolean>): Stream<T, E>;
|
|
413
|
+
tap(fn: (value: T) => Promisable<void>): Stream<T, E>;
|
|
414
|
+
tapErr(fn: (error: E) => Promisable<void>): Stream<T, E>;
|
|
415
|
+
take(n: number): Stream<T, E>;
|
|
416
|
+
takeWhile(fn: (value: T) => Promisable<boolean>): Stream<T, E>;
|
|
417
|
+
partition(): Promise<{
|
|
418
|
+
successes: T[];
|
|
419
|
+
errors: E[];
|
|
420
|
+
}>;
|
|
421
|
+
fold<U>(fn: (acc: U, value: T) => Promisable<U>, initialValue: U): Promise<U>;
|
|
422
|
+
scan<U>(fn: (acc: U, value: T) => Promisable<U>, initialValue: U): Stream<U, E>;
|
|
423
|
+
chunks(size: number): Stream<T[], E>;
|
|
424
|
+
mapErr<F>(fn: (error: E) => Promisable<F>): Stream<T, F>;
|
|
425
|
+
filterErr(fn: (error: E) => Promisable<boolean>): Stream<T, E>;
|
|
426
|
+
foldErr<F>(fn: (acc: F, error: E) => Promisable<F>, initialValue: F): Promise<F>;
|
|
427
|
+
recoverWhen<E2 extends E, U = T>(guard: (error: E) => error is E2, fn: (error: E2) => Promisable<U>): Stream<T | U, Exclude<E, E2>>;
|
|
428
|
+
recover<U>(fn: (error: E) => Promisable<U>): Stream<T | U, never>;
|
|
429
|
+
throwOn<E2 extends E>(guard: (error: E) => error is E2): Stream<T, Exclude<E, E2>>;
|
|
430
|
+
}
|
|
431
|
+
//# sourceMappingURL=stream.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"stream.d.ts","sourceRoot":"","sources":["../../../src/anabranch/streams/stream.ts"],"names":[],"mappings":"AAAA,OAAO,EAAkB,KAAK,UAAU,EAAE,KAAK,MAAM,EAAE,MAAM,WAAW,CAAC;AAiCzE;;;;;;;;;;GAUG;AACH,MAAM,WAAW,MAAM,CAAC,CAAC,EAAE,CAAC,CAAE,SAAQ,aAAa,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;IAC/D;;;;;;;;;;;;;;;;;;;;;;OAsBG;IACH,GAAG,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,KAAK,EAAE,CAAC,KAAK,UAAU,CAAC,CAAC,CAAC,GAAG,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;IACtD;;;;;;;;;;;;;;;;;;;;;;OAsBG;IACH,MAAM,CAAC,CAAC,EAAE,CAAC,GAAG,KAAK,EACjB,EAAE,EAAE,CAAC,KAAK,EAAE,CAAC,KAAK,UAAU,CAAC,CAAC,CAAC,EAC/B,KAAK,EAAE,CAAC,KAAK,EAAE,OAAO,EAAE,KAAK,EAAE,CAAC,KAAK,UAAU,CAAC,CAAC,CAAC,GACjD,MAAM,CAAC,CAAC,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC;IACpB;;;;;;;;;;;;;;;;OAgBG;IACH,OAAO,CAAC,CAAC,EACP,EAAE,EAAE,CAAC,KA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