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