awaitly 1.34.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.
- package/dist/{duration.d.ts → di-BDlT7InM.d.cts} +15 -1
- package/dist/{duration.d.cts → di-BbFFfO8y.d.ts} +15 -1
- package/dist/errors-DtXvrCiO.d.cts +708 -0
- package/dist/errors-DtXvrCiO.d.ts +708 -0
- package/dist/index.cjs +4594 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1970 -141
- package/dist/index.d.ts +1970 -141
- package/dist/index.js +4398 -1
- package/dist/index.js.map +1 -1
- package/dist/result.cjs +641 -1
- package/dist/result.cjs.map +1 -1
- package/dist/result.d.cts +35 -5
- package/dist/result.d.ts +35 -5
- package/dist/result.js +561 -1
- package/dist/result.js.map +1 -1
- package/dist/testing.cjs +4202 -8
- package/dist/testing.cjs.map +1 -1
- package/dist/testing.d.cts +2 -6
- package/dist/testing.d.ts +2 -6
- package/dist/testing.js +4154 -8
- package/dist/testing.js.map +1 -1
- package/dist/{run-entry-D2MmJFj9.d.cts → types-B8NfNRGX.d.ts} +1152 -1499
- package/dist/{run-entry-Dduz-is2.d.ts → types-BZ2f4MRR.d.cts} +1152 -1499
- package/dist/workflow.cjs +7096 -6
- package/dist/workflow.cjs.map +1 -1
- package/dist/workflow.d.cts +3346 -22
- package/dist/workflow.d.ts +3346 -22
- package/dist/workflow.js +6929 -6
- package/dist/workflow.js.map +1 -1
- package/package.json +13 -178
- package/dist/adapters.cjs +0 -7
- package/dist/adapters.cjs.map +0 -1
- package/dist/adapters.d.cts +0 -179
- package/dist/adapters.d.ts +0 -179
- package/dist/adapters.js +0 -7
- package/dist/adapters.js.map +0 -1
- package/dist/batch.cjs +0 -7
- package/dist/batch.cjs.map +0 -1
- package/dist/batch.d.cts +0 -200
- package/dist/batch.d.ts +0 -200
- package/dist/batch.js +0 -7
- package/dist/batch.js.map +0 -1
- package/dist/bind-deps.cjs +0 -2
- package/dist/bind-deps.cjs.map +0 -1
- package/dist/bind-deps.d.cts +0 -28
- package/dist/bind-deps.d.ts +0 -28
- package/dist/bind-deps.js +0 -2
- package/dist/bind-deps.js.map +0 -1
- package/dist/cache.cjs +0 -2
- package/dist/cache.cjs.map +0 -1
- package/dist/cache.d.cts +0 -269
- package/dist/cache.d.ts +0 -269
- package/dist/cache.js +0 -2
- package/dist/cache.js.map +0 -1
- package/dist/circuit-breaker.cjs +0 -7
- package/dist/circuit-breaker.cjs.map +0 -1
- package/dist/circuit-breaker.d.cts +0 -211
- package/dist/circuit-breaker.d.ts +0 -211
- package/dist/circuit-breaker.js +0 -7
- package/dist/circuit-breaker.js.map +0 -1
- package/dist/conditional.cjs +0 -2
- package/dist/conditional.cjs.map +0 -1
- package/dist/conditional.d.cts +0 -252
- package/dist/conditional.d.ts +0 -252
- package/dist/conditional.js +0 -2
- package/dist/conditional.js.map +0 -1
- package/dist/core.cjs +0 -7
- package/dist/core.cjs.map +0 -1
- package/dist/core.d.cts +0 -5
- package/dist/core.d.ts +0 -5
- package/dist/core.js +0 -7
- package/dist/core.js.map +0 -1
- package/dist/di-COl5oFnR.d.cts +0 -15
- package/dist/di-CyDj_JyZ.d.ts +0 -15
- package/dist/diagnostics.cjs +0 -8
- package/dist/diagnostics.cjs.map +0 -1
- package/dist/diagnostics.d.cts +0 -68
- package/dist/diagnostics.d.ts +0 -68
- package/dist/diagnostics.js +0 -8
- package/dist/diagnostics.js.map +0 -1
- package/dist/durable.cjs +0 -11
- package/dist/durable.cjs.map +0 -1
- package/dist/durable.d.cts +0 -9
- package/dist/durable.d.ts +0 -9
- package/dist/durable.js +0 -11
- package/dist/durable.js.map +0 -1
- package/dist/duration.cjs +0 -2
- package/dist/duration.cjs.map +0 -1
- package/dist/duration.js +0 -2
- package/dist/duration.js.map +0 -1
- package/dist/engine.cjs +0 -11
- package/dist/engine.cjs.map +0 -1
- package/dist/engine.d.cts +0 -115
- package/dist/engine.d.ts +0 -115
- package/dist/engine.js +0 -11
- package/dist/engine.js.map +0 -1
- package/dist/errors.cjs +0 -2
- package/dist/errors.cjs.map +0 -1
- package/dist/errors.d.cts +0 -361
- package/dist/errors.d.ts +0 -361
- package/dist/errors.js +0 -2
- package/dist/errors.js.map +0 -1
- package/dist/fetch.cjs +0 -7
- package/dist/fetch.cjs.map +0 -1
- package/dist/fetch.d.cts +0 -86
- package/dist/fetch.d.ts +0 -86
- package/dist/fetch.js +0 -7
- package/dist/fetch.js.map +0 -1
- package/dist/flow.cjs +0 -7
- package/dist/flow.cjs.map +0 -1
- package/dist/flow.d.cts +0 -163
- package/dist/flow.d.ts +0 -163
- package/dist/flow.js +0 -7
- package/dist/flow.js.map +0 -1
- package/dist/functional.cjs +0 -2
- package/dist/functional.cjs.map +0 -1
- package/dist/functional.d.cts +0 -444
- package/dist/functional.d.ts +0 -444
- package/dist/functional.js +0 -2
- package/dist/functional.js.map +0 -1
- package/dist/guards-BodHXLzX.d.cts +0 -72
- package/dist/guards-CeWoQ8fn.d.ts +0 -72
- package/dist/hitl-BPE_1UiM.d.cts +0 -468
- package/dist/hitl-byp570uC.d.ts +0 -468
- package/dist/hitl.cjs +0 -7
- package/dist/hitl.cjs.map +0 -1
- package/dist/hitl.d.cts +0 -442
- package/dist/hitl.d.ts +0 -442
- package/dist/hitl.js +0 -7
- package/dist/hitl.js.map +0 -1
- package/dist/index-BYT3amEz.d.ts +0 -417
- package/dist/index-C_ak66jy.d.cts +0 -417
- package/dist/match-entry-DjI2bLpD.d.cts +0 -209
- package/dist/match-entry-DjI2bLpD.d.ts +0 -209
- package/dist/match.cjs +0 -2
- package/dist/match.cjs.map +0 -1
- package/dist/match.d.cts +0 -1
- package/dist/match.d.ts +0 -1
- package/dist/match.js +0 -2
- package/dist/match.js.map +0 -1
- package/dist/otel.cjs +0 -2
- package/dist/otel.cjs.map +0 -1
- package/dist/otel.d.cts +0 -188
- package/dist/otel.d.ts +0 -188
- package/dist/otel.js +0 -2
- package/dist/otel.js.map +0 -1
- package/dist/persistence-entry-DOMx3woy.d.ts +0 -822
- package/dist/persistence-entry-ymCA4iDu.d.cts +0 -822
- package/dist/persistence.cjs +0 -2
- package/dist/persistence.cjs.map +0 -1
- package/dist/persistence.d.cts +0 -7
- package/dist/persistence.d.ts +0 -7
- package/dist/persistence.js +0 -2
- package/dist/persistence.js.map +0 -1
- package/dist/policies.cjs +0 -2
- package/dist/policies.cjs.map +0 -1
- package/dist/policies.d.cts +0 -379
- package/dist/policies.d.ts +0 -379
- package/dist/policies.js +0 -2
- package/dist/policies.js.map +0 -1
- package/dist/ratelimit.cjs +0 -7
- package/dist/ratelimit.cjs.map +0 -1
- package/dist/ratelimit.d.cts +0 -458
- package/dist/ratelimit.d.ts +0 -458
- package/dist/ratelimit.js +0 -7
- package/dist/ratelimit.js.map +0 -1
- package/dist/reliability.cjs +0 -11
- package/dist/reliability.cjs.map +0 -1
- package/dist/reliability.d.cts +0 -11
- package/dist/reliability.d.ts +0 -11
- package/dist/reliability.js +0 -11
- package/dist/reliability.js.map +0 -1
- package/dist/resolver.cjs +0 -7
- package/dist/resolver.cjs.map +0 -1
- package/dist/resolver.d.cts +0 -68
- package/dist/resolver.d.ts +0 -68
- package/dist/resolver.js +0 -7
- package/dist/resolver.js.map +0 -1
- package/dist/resource.cjs +0 -7
- package/dist/resource.cjs.map +0 -1
- package/dist/resource.d.cts +0 -174
- package/dist/resource.d.ts +0 -174
- package/dist/resource.js +0 -7
- package/dist/resource.js.map +0 -1
- package/dist/result/retry.cjs +0 -2
- package/dist/result/retry.cjs.map +0 -1
- package/dist/result/retry.d.cts +0 -70
- package/dist/result/retry.d.ts +0 -70
- package/dist/result/retry.js +0 -2
- package/dist/result/retry.js.map +0 -1
- package/dist/retry.cjs +0 -2
- package/dist/retry.cjs.map +0 -1
- package/dist/retry.d.cts +0 -388
- package/dist/retry.d.ts +0 -388
- package/dist/retry.js +0 -2
- package/dist/retry.js.map +0 -1
- package/dist/run.cjs +0 -7
- package/dist/run.cjs.map +0 -1
- package/dist/run.d.cts +0 -4
- package/dist/run.d.ts +0 -4
- package/dist/run.js +0 -7
- package/dist/run.js.map +0 -1
- package/dist/saga.cjs +0 -11
- package/dist/saga.cjs.map +0 -1
- package/dist/saga.d.cts +0 -164
- package/dist/saga.d.ts +0 -164
- package/dist/saga.js +0 -11
- package/dist/saga.js.map +0 -1
- package/dist/singleflight.cjs +0 -2
- package/dist/singleflight.cjs.map +0 -1
- package/dist/singleflight.d.cts +0 -145
- package/dist/singleflight.d.ts +0 -145
- package/dist/singleflight.js +0 -2
- package/dist/singleflight.js.map +0 -1
- package/dist/slugs.cjs +0 -2
- package/dist/slugs.cjs.map +0 -1
- package/dist/slugs.d.cts +0 -67
- package/dist/slugs.d.ts +0 -67
- package/dist/slugs.js +0 -2
- package/dist/slugs.js.map +0 -1
- package/dist/streaming.cjs +0 -9
- package/dist/streaming.cjs.map +0 -1
- package/dist/streaming.d.cts +0 -596
- package/dist/streaming.d.ts +0 -596
- package/dist/streaming.js +0 -9
- package/dist/streaming.js.map +0 -1
- package/dist/tagged-error.cjs +0 -2
- package/dist/tagged-error.cjs.map +0 -1
- package/dist/tagged-error.d.cts +0 -275
- package/dist/tagged-error.d.ts +0 -275
- package/dist/tagged-error.js +0 -2
- package/dist/tagged-error.js.map +0 -1
- package/dist/types-DQmzO9f4.d.ts +0 -323
- package/dist/types-qBUOYi-4.d.cts +0 -323
- package/dist/webhook.cjs +0 -7
- package/dist/webhook.cjs.map +0 -1
- package/dist/webhook.d.cts +0 -499
- package/dist/webhook.d.ts +0 -499
- package/dist/webhook.js +0 -7
- package/dist/webhook.js.map +0 -1
package/dist/streaming.d.cts
DELETED
|
@@ -1,596 +0,0 @@
|
|
|
1
|
-
import { S as StreamStore, a as StreamReader } from './types-qBUOYi-4.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-qBUOYi-4.cjs';
|
|
3
|
-
import { c as AsyncResult, R as Result } from './run-entry-D2MmJFj9.cjs';
|
|
4
|
-
import './errors.cjs';
|
|
5
|
-
import './tagged-error.cjs';
|
|
6
|
-
import './slugs.cjs';
|
|
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 };
|