awaitly 2.0.0 → 3.0.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.
Files changed (88) hide show
  1. package/dist/di-Biw_plBn.d.cts +15 -0
  2. package/dist/di-DxyH2N3i.d.ts +15 -0
  3. package/dist/durable.cjs +4670 -0
  4. package/dist/durable.cjs.map +1 -0
  5. package/dist/durable.d.cts +9 -0
  6. package/dist/durable.d.ts +9 -0
  7. package/dist/durable.js +4610 -0
  8. package/dist/durable.js.map +1 -0
  9. package/dist/{di-BbFFfO8y.d.ts → duration-BjVn3QpB.d.cts} +1 -15
  10. package/dist/{di-BDlT7InM.d.cts → duration-BjVn3QpB.d.ts} +1 -15
  11. package/dist/engine.cjs +4501 -0
  12. package/dist/engine.cjs.map +1 -0
  13. package/dist/engine.d.cts +113 -0
  14. package/dist/engine.d.ts +113 -0
  15. package/dist/engine.js +4474 -0
  16. package/dist/engine.js.map +1 -0
  17. package/dist/{errors-DtXvrCiO.d.cts → errors-sDSeaZBO.d.cts} +1 -1
  18. package/dist/{errors-DtXvrCiO.d.ts → errors-sDSeaZBO.d.ts} +1 -1
  19. package/dist/guards-CwQZro1F.d.ts +72 -0
  20. package/dist/guards-DhhOJZda.d.cts +72 -0
  21. package/dist/hitl-BnnnLzh2.d.cts +468 -0
  22. package/dist/hitl-pYfkQMv_.d.ts +468 -0
  23. package/dist/hitl.cjs +646 -0
  24. package/dist/hitl.cjs.map +1 -0
  25. package/dist/hitl.d.cts +440 -0
  26. package/dist/hitl.d.ts +440 -0
  27. package/dist/hitl.js +605 -0
  28. package/dist/hitl.js.map +1 -0
  29. package/dist/index-Bew12SZ8.d.ts +417 -0
  30. package/dist/index-Bwt-iz50.d.cts +417 -0
  31. package/dist/{types-B8NfNRGX.d.ts → index-Cv4K_3sZ.d.ts} +2 -1162
  32. package/dist/{types-BZ2f4MRR.d.cts → index-ICmfQi08.d.cts} +2 -1162
  33. package/dist/index.cjs.map +1 -1
  34. package/dist/index.d.cts +11 -1527
  35. package/dist/index.d.ts +11 -1527
  36. package/dist/persistence.cjs +552 -0
  37. package/dist/persistence.cjs.map +1 -0
  38. package/dist/persistence.d.cts +254 -0
  39. package/dist/persistence.d.ts +254 -0
  40. package/dist/persistence.js +499 -0
  41. package/dist/persistence.js.map +1 -0
  42. package/dist/reliability.cjs +1651 -0
  43. package/dist/reliability.cjs.map +1 -0
  44. package/dist/reliability.d.cts +1442 -0
  45. package/dist/reliability.d.ts +1442 -0
  46. package/dist/reliability.js +1589 -0
  47. package/dist/reliability.js.map +1 -0
  48. package/dist/result.d.cts +1 -1
  49. package/dist/result.d.ts +1 -1
  50. package/dist/run.cjs +2283 -0
  51. package/dist/run.cjs.map +1 -0
  52. package/dist/run.d.cts +90 -0
  53. package/dist/run.d.ts +90 -0
  54. package/dist/run.js +2247 -0
  55. package/dist/run.js.map +1 -0
  56. package/dist/saga.cjs +3699 -0
  57. package/dist/saga.cjs.map +1 -0
  58. package/dist/saga.d.cts +162 -0
  59. package/dist/saga.d.ts +162 -0
  60. package/dist/saga.js +3670 -0
  61. package/dist/saga.js.map +1 -0
  62. package/dist/store-contract-BI98VYmX.d.ts +66 -0
  63. package/dist/store-contract-C2HyR_o6.d.cts +66 -0
  64. package/dist/streaming.cjs +895 -0
  65. package/dist/streaming.cjs.map +1 -0
  66. package/dist/streaming.d.cts +594 -0
  67. package/dist/streaming.d.ts +594 -0
  68. package/dist/streaming.js +832 -0
  69. package/dist/streaming.js.map +1 -0
  70. package/dist/testing.d.cts +4 -2
  71. package/dist/testing.d.ts +4 -2
  72. package/dist/types-BDTxgKKc.d.ts +845 -0
  73. package/dist/types-C9Y71dua.d.cts +845 -0
  74. package/dist/types-d8q8iQlk.d.cts +323 -0
  75. package/dist/types-sObbY4mX.d.ts +323 -0
  76. package/dist/webhook.cjs +461 -0
  77. package/dist/webhook.cjs.map +1 -0
  78. package/dist/webhook.d.cts +497 -0
  79. package/dist/webhook.d.ts +497 -0
  80. package/dist/webhook.js +422 -0
  81. package/dist/webhook.js.map +1 -0
  82. package/dist/workflow.cjs +2 -2614
  83. package/dist/workflow.cjs.map +1 -1
  84. package/dist/workflow.d.cts +12 -3023
  85. package/dist/workflow.d.ts +12 -3023
  86. package/dist/workflow.js +2 -2535
  87. package/dist/workflow.js.map +1 -1
  88. package/package.json +46 -1
@@ -0,0 +1,594 @@
1
+ import { S as StreamStore, a as StreamReader } from './types-d8q8iQlk.cjs';
2
+ export { b as STREAM_BACKPRESSURE_ERROR, c as STREAM_CLOSE_ERROR, d as STREAM_ENDED, e as STREAM_READ_ERROR, f as STREAM_STORE_ERROR, g as STREAM_WRITE_ERROR, h as StreamBackpressureError, i as StreamCloseError, j as StreamEndedMarker, k as StreamError, l as StreamForEachOptions, m as StreamForEachResult, n as StreamItem, o as StreamMetadata, p as StreamOptions, q as StreamReadError, r as StreamReadOptions, s as StreamStoreError, t as StreamWriteError, u as StreamWriter, U as Unsubscribe, v as isStreamBackpressureError, w as isStreamEnded, x as isStreamReadError, y as isStreamStoreError, z as isStreamWriteError, A as streamBackpressureError, B as streamCloseError, C as streamEnded, D as streamReadError, E as streamStoreError, F as streamWriteError } from './types-d8q8iQlk.cjs';
3
+ import { A as AsyncResult, R as Result } from './index-ICmfQi08.cjs';
4
+ import './errors-sDSeaZBO.cjs';
5
+
6
+ /**
7
+ * awaitly/streaming - Backpressure Controller
8
+ *
9
+ * Implements flow control for streams using high-water mark.
10
+ * When buffered items exceed the threshold, writers are paused
11
+ * until consumers catch up.
12
+ */
13
+ /**
14
+ * State of the backpressure controller.
15
+ */
16
+ type BackpressureState = "flowing" | "paused";
17
+ /**
18
+ * Callback invoked when backpressure state changes.
19
+ */
20
+ type BackpressureCallback = (state: BackpressureState) => void;
21
+ /**
22
+ * Options for creating a BackpressureController.
23
+ */
24
+ interface BackpressureOptions {
25
+ /** High-water mark threshold (default: 16) */
26
+ highWaterMark?: number;
27
+ /** Low-water mark to resume (default: highWaterMark / 2) */
28
+ lowWaterMark?: number;
29
+ /** Callback when state changes */
30
+ onStateChange?: BackpressureCallback;
31
+ }
32
+ /**
33
+ * Controller for managing stream backpressure.
34
+ *
35
+ * When the number of buffered items exceeds the high-water mark,
36
+ * the controller enters "paused" state. It returns to "flowing"
37
+ * when items are consumed and the buffer drops below the low-water mark.
38
+ *
39
+ * @example
40
+ * ```typescript
41
+ * const controller = createBackpressureController({ highWaterMark: 16 });
42
+ *
43
+ * // Track writes
44
+ * controller.increment();
45
+ * if (controller.state === 'paused') {
46
+ * await controller.waitForDrain();
47
+ * }
48
+ *
49
+ * // Track reads (consumer)
50
+ * controller.decrement();
51
+ * ```
52
+ */
53
+ interface BackpressureController {
54
+ /** Current state */
55
+ readonly state: BackpressureState;
56
+ /** Current number of buffered items */
57
+ readonly bufferedCount: number;
58
+ /** High-water mark threshold */
59
+ readonly highWaterMark: number;
60
+ /** Low-water mark threshold */
61
+ readonly lowWaterMark: number;
62
+ /** Increment buffered count (called on write) */
63
+ increment(): void;
64
+ /** Decrement buffered count (called on read/consume) */
65
+ decrement(): void;
66
+ /** Set buffered count directly (for resuming) */
67
+ setCount(count: number): void;
68
+ /**
69
+ * Wait for the buffer to drain below low-water mark.
70
+ * Resolves immediately if already flowing.
71
+ */
72
+ waitForDrain(): Promise<void>;
73
+ /** Reset the controller to initial state */
74
+ reset(): void;
75
+ }
76
+ /**
77
+ * Create a backpressure controller.
78
+ *
79
+ * @param options - Configuration options
80
+ * @returns BackpressureController instance
81
+ */
82
+ declare function createBackpressureController(options?: BackpressureOptions): BackpressureController;
83
+ /**
84
+ * Check if backpressure should be applied.
85
+ */
86
+ declare function shouldApplyBackpressure(controller: BackpressureController): boolean;
87
+
88
+ /**
89
+ * awaitly/streaming - Memory Stream Store
90
+ *
91
+ * In-memory implementation of StreamStore for development and testing.
92
+ * Data is not persisted across process restarts.
93
+ */
94
+
95
+ /**
96
+ * Options for creating a memory stream store.
97
+ */
98
+ interface MemoryStreamStoreOptions {
99
+ /** Maximum items per stream (default: Infinity) */
100
+ maxItemsPerStream?: number;
101
+ }
102
+ /**
103
+ * Create an in-memory StreamStore.
104
+ *
105
+ * @param options - Configuration options
106
+ * @returns StreamStore implementation
107
+ *
108
+ * @example
109
+ * ```typescript
110
+ * const store = createMemoryStreamStore();
111
+ *
112
+ * // Use with workflow
113
+ * const workflow = createWorkflow(deps, { streamStore: store });
114
+ * ```
115
+ */
116
+ declare function createMemoryStreamStore(options?: MemoryStreamStoreOptions): StreamStore;
117
+ /**
118
+ * Create a memory stream store with a Map-like interface for testing.
119
+ * Exposes additional methods for inspection.
120
+ */
121
+ interface TestableMemoryStreamStore extends StreamStore {
122
+ /** Clear all streams */
123
+ clear(): void;
124
+ /** Get all stream keys */
125
+ keys(): string[];
126
+ /** Check if a stream exists */
127
+ has(workflowId: string, namespace: string): boolean;
128
+ /** Delete a stream */
129
+ delete(workflowId: string, namespace: string): boolean;
130
+ }
131
+ /**
132
+ * Create a testable memory stream store with additional inspection methods.
133
+ */
134
+ declare function createTestableMemoryStreamStore(options?: MemoryStreamStoreOptions): TestableMemoryStreamStore;
135
+
136
+ /**
137
+ * awaitly/streaming - File Stream Store
138
+ *
139
+ * File-based implementation of StreamStore for persistent storage.
140
+ * Follows the patterns from persistence.ts.
141
+ */
142
+
143
+ /**
144
+ * Minimal file system interface for stream operations.
145
+ * Same as FileSystemInterface in persistence.ts.
146
+ */
147
+ interface FileSystemInterface {
148
+ readFile(path: string): Promise<string>;
149
+ writeFile(path: string, data: string): Promise<void>;
150
+ unlink(path: string): Promise<void>;
151
+ exists(path: string): Promise<boolean>;
152
+ readdir(path: string): Promise<string[]>;
153
+ mkdir(path: string, options?: {
154
+ recursive?: boolean;
155
+ }): Promise<void>;
156
+ }
157
+ /**
158
+ * Options for creating a file stream store.
159
+ */
160
+ interface FileStreamStoreOptions {
161
+ /** Directory to store stream files */
162
+ directory: string;
163
+ /** File system implementation */
164
+ fs: FileSystemInterface;
165
+ }
166
+ /**
167
+ * Create a file-based StreamStore.
168
+ *
169
+ * Each stream is stored in a directory structure:
170
+ * - `{directory}/{workflowId}/{namespace}/metadata.json` - stream metadata
171
+ * - `{directory}/{workflowId}/{namespace}/items.jsonl` - items in JSON lines format
172
+ *
173
+ * @param options - Configuration options
174
+ * @returns StreamStore implementation
175
+ *
176
+ * @example
177
+ * ```typescript
178
+ * import * as fs from 'fs/promises';
179
+ *
180
+ * const store = createFileStreamStore({
181
+ * directory: './streams',
182
+ * fs: {
183
+ * readFile: (path) => fs.readFile(path, 'utf-8'),
184
+ * writeFile: (path, data) => fs.writeFile(path, data, 'utf-8'),
185
+ * unlink: (path) => fs.unlink(path),
186
+ * exists: async (path) => {
187
+ * try { await fs.access(path); return true; }
188
+ * catch { return false; }
189
+ * },
190
+ * readdir: (path) => fs.readdir(path),
191
+ * mkdir: (path, options) => fs.mkdir(path, options),
192
+ * },
193
+ * });
194
+ * ```
195
+ */
196
+ declare function createFileStreamStore(options: FileStreamStoreOptions): StreamStore;
197
+
198
+ /**
199
+ * awaitly/streaming - Stream Transformers
200
+ *
201
+ * Utilities for transforming streams: map, filter, chunk, flatMapAsync.
202
+ * All transformers work with both StreamReader and AsyncIterable sources.
203
+ */
204
+
205
+ /**
206
+ * A transform function that can be applied to stream items.
207
+ */
208
+ type TransformFn<T, U> = (item: T, index: number) => U | Promise<U>;
209
+ /**
210
+ * A filter predicate for stream items.
211
+ */
212
+ type FilterFn<T> = (item: T, index: number) => boolean | Promise<boolean>;
213
+ /**
214
+ * An async transform function that returns a Result.
215
+ */
216
+ type AsyncTransformFn<T, U, E> = (item: T, index: number) => AsyncResult<U, E>;
217
+ /**
218
+ * Convert a StreamReader to an AsyncIterable.
219
+ *
220
+ * This allows using for-await-of with StreamReaders.
221
+ *
222
+ * @param reader - StreamReader to convert
223
+ * @returns AsyncIterable that yields stream values
224
+ *
225
+ * @example
226
+ * ```typescript
227
+ * const reader = step.getReadable<string>({ namespace: 'tokens' });
228
+ *
229
+ * for await (const token of toAsyncIterable(reader)) {
230
+ * process.stdout.write(token);
231
+ * }
232
+ * ```
233
+ */
234
+ declare function toAsyncIterable<T>(reader: StreamReader<T>): AsyncIterable<T>;
235
+ /**
236
+ * Transform each item in a stream.
237
+ *
238
+ * @param source - StreamReader or AsyncIterable to transform
239
+ * @param fn - Transform function applied to each item
240
+ * @returns AsyncIterable of transformed values
241
+ *
242
+ * @example
243
+ * ```typescript
244
+ * const reader = step.getReadable<number>({ namespace: 'numbers' });
245
+ *
246
+ * for await (const doubled of map(reader, (n) => n * 2)) {
247
+ * console.log(doubled);
248
+ * }
249
+ * ```
250
+ */
251
+ declare function map<T, U>(source: StreamReader<T> | AsyncIterable<T>, fn: TransformFn<T, U>): AsyncIterable<U>;
252
+ /**
253
+ * Filter items in a stream.
254
+ *
255
+ * @param source - StreamReader or AsyncIterable to filter
256
+ * @param predicate - Filter function that returns true to keep item
257
+ * @returns AsyncIterable of filtered values
258
+ *
259
+ * @example
260
+ * ```typescript
261
+ * const reader = step.getReadable<number>({ namespace: 'numbers' });
262
+ *
263
+ * for await (const even of filter(reader, (n) => n % 2 === 0)) {
264
+ * console.log(even);
265
+ * }
266
+ * ```
267
+ */
268
+ declare function filter<T>(source: StreamReader<T> | AsyncIterable<T>, predicate: FilterFn<T>): AsyncIterable<T>;
269
+ /**
270
+ * Group stream items into fixed-size chunks.
271
+ *
272
+ * @param source - StreamReader or AsyncIterable to chunk
273
+ * @param size - Maximum number of items per chunk
274
+ * @returns AsyncIterable of item arrays
275
+ *
276
+ * @example
277
+ * ```typescript
278
+ * const reader = step.getReadable<string>({ namespace: 'messages' });
279
+ *
280
+ * for await (const batch of chunk(reader, 10)) {
281
+ * await processBatch(batch);
282
+ * }
283
+ * ```
284
+ */
285
+ declare function chunk<T>(source: StreamReader<T> | AsyncIterable<T>, size: number): AsyncIterable<T[]>;
286
+ /**
287
+ * Transform each item to multiple items and flatten.
288
+ *
289
+ * @param source - StreamReader or AsyncIterable to transform
290
+ * @param fn - Transform function that returns an iterable
291
+ * @returns AsyncIterable of flattened values
292
+ *
293
+ * @example
294
+ * ```typescript
295
+ * const reader = step.getReadable<string>({ namespace: 'lines' });
296
+ *
297
+ * for await (const word of flatMap(reader, (line) => line.split(' '))) {
298
+ * console.log(word);
299
+ * }
300
+ * ```
301
+ */
302
+ declare function flatMap<T, U>(source: StreamReader<T> | AsyncIterable<T>, fn: (item: T, index: number) => Iterable<U> | AsyncIterable<U>): AsyncIterable<U>;
303
+ /**
304
+ * Transform each item with a Result-returning async function.
305
+ *
306
+ * This is the Result-aware version of flatMap. If the transform function
307
+ * returns an error Result, the stream is terminated with that error.
308
+ *
309
+ * @param source - StreamReader or AsyncIterable to transform
310
+ * @param fn - Transform function returning AsyncResult
311
+ * @returns AsyncIterable of transformed values wrapped in Results
312
+ *
313
+ * @example
314
+ * ```typescript
315
+ * const reader = step.getReadable<Message>({ namespace: 'messages' });
316
+ *
317
+ * for await (const result of flatMapAsync(reader, async (msg) => {
318
+ * const processed = await processMessage(msg);
319
+ * return ok(processed);
320
+ * })) {
321
+ * if (!result.ok) {
322
+ * console.error('Processing failed:', result.error);
323
+ * break;
324
+ * }
325
+ * console.log('Processed:', result.value);
326
+ * }
327
+ * ```
328
+ */
329
+ declare function flatMapAsync<T, U, E>(source: StreamReader<T> | AsyncIterable<T>, fn: AsyncTransformFn<T, Iterable<U> | AsyncIterable<U>, E>): AsyncIterable<Result<U, E>>;
330
+ /**
331
+ * Transform each item with a Result-returning async function.
332
+ *
333
+ * @param source - StreamReader or AsyncIterable to transform
334
+ * @param fn - Transform function returning AsyncResult
335
+ * @returns AsyncIterable of Results
336
+ *
337
+ * @example
338
+ * ```typescript
339
+ * const reader = step.getReadable<number>({ namespace: 'numbers' });
340
+ *
341
+ * for await (const result of mapAsync(reader, async (n) => {
342
+ * if (n < 0) return err('NEGATIVE_NUMBER');
343
+ * return ok(Math.sqrt(n));
344
+ * })) {
345
+ * if (result.ok) {
346
+ * console.log('Sqrt:', result.value);
347
+ * }
348
+ * }
349
+ * ```
350
+ */
351
+ declare function mapAsync<T, U, E>(source: StreamReader<T> | AsyncIterable<T>, fn: AsyncTransformFn<T, U, E>): AsyncIterable<Result<U, E>>;
352
+ /**
353
+ * Take the first N items from a stream.
354
+ *
355
+ * @param source - StreamReader or AsyncIterable to take from
356
+ * @param count - Maximum number of items to take
357
+ * @returns AsyncIterable of up to N items
358
+ *
359
+ * @example
360
+ * ```typescript
361
+ * const reader = step.getReadable<string>({ namespace: 'messages' });
362
+ *
363
+ * for await (const message of take(reader, 10)) {
364
+ * console.log(message);
365
+ * }
366
+ * ```
367
+ */
368
+ declare function take<T>(source: StreamReader<T> | AsyncIterable<T>, count: number): AsyncIterable<T>;
369
+ /**
370
+ * Skip the first N items from a stream.
371
+ *
372
+ * @param source - StreamReader or AsyncIterable to skip from
373
+ * @param count - Number of items to skip
374
+ * @returns AsyncIterable starting after N items
375
+ *
376
+ * @example
377
+ * ```typescript
378
+ * const reader = step.getReadable<string>({ namespace: 'messages' });
379
+ *
380
+ * for await (const message of skip(reader, 100)) {
381
+ * console.log(message); // Messages 101+
382
+ * }
383
+ * ```
384
+ */
385
+ declare function skip<T>(source: StreamReader<T> | AsyncIterable<T>, count: number): AsyncIterable<T>;
386
+ /**
387
+ * Take items while predicate returns true.
388
+ *
389
+ * @param source - StreamReader or AsyncIterable
390
+ * @param predicate - Predicate function
391
+ * @returns AsyncIterable of items while predicate is true
392
+ *
393
+ * @example
394
+ * ```typescript
395
+ * const reader = step.getReadable<number>({ namespace: 'numbers' });
396
+ *
397
+ * for await (const n of takeWhile(reader, (n) => n < 100)) {
398
+ * console.log(n);
399
+ * }
400
+ * ```
401
+ */
402
+ declare function takeWhile<T>(source: StreamReader<T> | AsyncIterable<T>, predicate: FilterFn<T>): AsyncIterable<T>;
403
+ /**
404
+ * Skip items while predicate returns true.
405
+ *
406
+ * @param source - StreamReader or AsyncIterable
407
+ * @param predicate - Predicate function
408
+ * @returns AsyncIterable of items after predicate becomes false
409
+ *
410
+ * @example
411
+ * ```typescript
412
+ * const reader = step.getReadable<number>({ namespace: 'numbers' });
413
+ *
414
+ * for await (const n of skipWhile(reader, (n) => n < 100)) {
415
+ * console.log(n); // First n >= 100 and all after
416
+ * }
417
+ * ```
418
+ */
419
+ declare function skipWhile<T>(source: StreamReader<T> | AsyncIterable<T>, predicate: FilterFn<T>): AsyncIterable<T>;
420
+ /**
421
+ * Collect all stream items into an array.
422
+ *
423
+ * Warning: This loads all items into memory. Only use when you know
424
+ * the stream is bounded.
425
+ *
426
+ * @param source - StreamReader or AsyncIterable
427
+ * @returns Promise resolving to array of all items
428
+ *
429
+ * @example
430
+ * ```typescript
431
+ * const reader = step.getReadable<string>({ namespace: 'small-data' });
432
+ * const items = await collect(reader);
433
+ * console.log('Got', items.length, 'items');
434
+ * ```
435
+ */
436
+ declare function collect<T>(source: StreamReader<T> | AsyncIterable<T>): Promise<T[]>;
437
+ /**
438
+ * Reduce stream items to a single value.
439
+ *
440
+ * @param source - StreamReader or AsyncIterable
441
+ * @param reducer - Reducer function
442
+ * @param initial - Initial accumulator value
443
+ * @returns Promise resolving to final accumulated value
444
+ *
445
+ * @example
446
+ * ```typescript
447
+ * const reader = step.getReadable<number>({ namespace: 'numbers' });
448
+ * const sum = await reduce(reader, (acc, n) => acc + n, 0);
449
+ * console.log('Sum:', sum);
450
+ * ```
451
+ */
452
+ declare function reduce<T, U>(source: StreamReader<T> | AsyncIterable<T>, reducer: (accumulator: U, item: T, index: number) => U | Promise<U>, initial: U): Promise<U>;
453
+ /**
454
+ * Pipe a source through multiple transformers.
455
+ *
456
+ * @param source - Initial source
457
+ * @param transformers - Array of transformer functions
458
+ * @returns Final transformed AsyncIterable
459
+ *
460
+ * @example
461
+ * ```typescript
462
+ * const reader = step.getReadable<number>({ namespace: 'numbers' });
463
+ *
464
+ * const result = pipe(
465
+ * reader,
466
+ * (s) => filter(s, (n) => n > 0),
467
+ * (s) => map(s, (n) => n * 2),
468
+ * (s) => take(s, 10)
469
+ * );
470
+ *
471
+ * for await (const n of result) {
472
+ * console.log(n);
473
+ * }
474
+ * ```
475
+ */
476
+ declare function pipe<T>(source: StreamReader<T> | AsyncIterable<T>): AsyncIterable<T>;
477
+ declare function pipe<T, A>(source: StreamReader<T> | AsyncIterable<T>, t1: (s: AsyncIterable<T>) => AsyncIterable<A>): AsyncIterable<A>;
478
+ declare function pipe<T, A, B>(source: StreamReader<T> | AsyncIterable<T>, t1: (s: AsyncIterable<T>) => AsyncIterable<A>, t2: (s: AsyncIterable<A>) => AsyncIterable<B>): AsyncIterable<B>;
479
+ declare function pipe<T, A, B, C>(source: StreamReader<T> | AsyncIterable<T>, t1: (s: AsyncIterable<T>) => AsyncIterable<A>, t2: (s: AsyncIterable<A>) => AsyncIterable<B>, t3: (s: AsyncIterable<B>) => AsyncIterable<C>): AsyncIterable<C>;
480
+ declare function pipe<T, A, B, C, D>(source: StreamReader<T> | AsyncIterable<T>, t1: (s: AsyncIterable<T>) => AsyncIterable<A>, t2: (s: AsyncIterable<A>) => AsyncIterable<B>, t3: (s: AsyncIterable<B>) => AsyncIterable<C>, t4: (s: AsyncIterable<C>) => AsyncIterable<D>): AsyncIterable<D>;
481
+
482
+ /**
483
+ * awaitly/streaming
484
+ *
485
+ * Result-aware streaming for workflows.
486
+ * All stream operations return Result types, enabling typed error handling
487
+ * throughout the streaming pipeline.
488
+ *
489
+ * @example Basic usage
490
+ * ```typescript
491
+ * import { createWorkflow } from 'awaitly/workflow';
492
+ * import { createMemoryStreamStore } from 'awaitly/streaming';
493
+ *
494
+ * const streamStore = createMemoryStreamStore();
495
+ * const workflow = createWorkflow(deps, { streamStore });
496
+ *
497
+ * const result = await workflow(async ({ step }) => {
498
+ * const writer = step.getWritable<string>({ namespace: 'tokens' });
499
+ *
500
+ * await step(() => generateAI({
501
+ * prompt: 'Hello',
502
+ * onToken: async (token) => { await writer.write(token); }
503
+ * }), { key: 'generate' });
504
+ *
505
+ * await writer.close();
506
+ * });
507
+ * ```
508
+ *
509
+ * @example Consuming a stream
510
+ * ```typescript
511
+ * import { toAsyncIterable } from 'awaitly/streaming';
512
+ *
513
+ * const reader = step.getReadable<string>({ namespace: 'tokens' });
514
+ *
515
+ * for await (const token of toAsyncIterable(reader)) {
516
+ * process.stdout.write(token);
517
+ * }
518
+ * ```
519
+ *
520
+ * @example Stream transformations
521
+ * ```typescript
522
+ * import { map, filter, chunk, collect } from 'awaitly/streaming';
523
+ *
524
+ * const reader = step.getReadable<number>({ namespace: 'numbers' });
525
+ *
526
+ * // Transform pipeline
527
+ * const evens = filter(reader, n => n % 2 === 0);
528
+ * const doubled = map(evens, n => n * 2);
529
+ * const batches = chunk(doubled, 10);
530
+ *
531
+ * for await (const batch of batches) {
532
+ * await processBatch(batch);
533
+ * }
534
+ * ```
535
+ */
536
+
537
+ /**
538
+ * Options for creating an external stream reader.
539
+ */
540
+ interface ExternalReaderOptions {
541
+ /** Stream store instance */
542
+ store: StreamStore;
543
+ /** Workflow ID that owns the stream */
544
+ workflowId: string;
545
+ /** Stream namespace (default: 'default') */
546
+ namespace?: string;
547
+ /** Start reading from this position (default: 0) */
548
+ startIndex?: number;
549
+ /** Poll interval in ms when waiting for new items (default: 100) */
550
+ pollInterval?: number;
551
+ /** Stop polling after this many ms with no new items (default: 30000) */
552
+ pollTimeout?: number;
553
+ }
554
+ /**
555
+ * Create a stream reader for external consumption (outside workflows).
556
+ *
557
+ * Use this in HTTP handlers, WebSocket handlers, or other contexts
558
+ * where you need to consume a stream created by a workflow.
559
+ *
560
+ * @param options - Reader configuration
561
+ * @returns StreamReader that can be used with toAsyncIterable()
562
+ *
563
+ * @example HTTP streaming response
564
+ * ```typescript
565
+ * app.get('/stream/:workflowId', async (req, res) => {
566
+ * const reader = getStreamReader({
567
+ * store: streamStore,
568
+ * workflowId: req.params.workflowId,
569
+ * namespace: 'ai-response',
570
+ * });
571
+ *
572
+ * res.setHeader('Content-Type', 'text/event-stream');
573
+ *
574
+ * for await (const chunk of toAsyncIterable(reader)) {
575
+ * res.write(`data: ${chunk}\n\n`);
576
+ * }
577
+ *
578
+ * res.end();
579
+ * });
580
+ * ```
581
+ *
582
+ * @example Resume from last position
583
+ * ```typescript
584
+ * const reader = getStreamReader({
585
+ * store: streamStore,
586
+ * workflowId: runId,
587
+ * namespace: 'tokens',
588
+ * startIndex: lastReceivedPosition + 1,
589
+ * });
590
+ * ```
591
+ */
592
+ declare function getStreamReader<T>(options: ExternalReaderOptions): StreamReader<T>;
593
+
594
+ export { type AsyncTransformFn, type BackpressureCallback, type BackpressureController, type BackpressureOptions, type BackpressureState, type ExternalReaderOptions, type FileStreamStoreOptions, type FileSystemInterface, type FilterFn, type MemoryStreamStoreOptions, StreamReader, StreamStore, type TestableMemoryStreamStore, type TransformFn, chunk, collect, createBackpressureController, createFileStreamStore, createMemoryStreamStore, createTestableMemoryStreamStore, filter, flatMap, flatMapAsync, getStreamReader, map, mapAsync, pipe, reduce, shouldApplyBackpressure, skip, skipWhile, take, takeWhile, toAsyncIterable };