brass-runtime 1.13.7 → 1.14.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/README.md +231 -55
- package/dist/agent/cli/main.cjs +43 -43
- package/dist/agent/cli/main.js +2 -2
- package/dist/agent/cli/main.mjs +2 -2
- package/dist/agent/index.cjs +3 -3
- package/dist/agent/index.d.ts +1 -1
- package/dist/agent/index.js +2 -2
- package/dist/agent/index.mjs +2 -2
- package/dist/chunk-4N2JEK4H.mjs +3897 -0
- package/dist/chunk-BKBFSOGT.cjs +3897 -0
- package/dist/{chunk-XNOTJSMZ.mjs → chunk-BMRF4FN6.js} +268 -8
- package/dist/chunk-JT7D6M5H.js +3897 -0
- package/dist/{chunk-3R7ZYRK2.mjs → chunk-MQF7HZ7Y.mjs} +1 -1
- package/dist/chunk-SKVY72E5.cjs +667 -0
- package/dist/{chunk-ATHSSDUF.js → chunk-UWMMYKVK.mjs} +268 -8
- package/dist/{chunk-INZBKOHY.js → chunk-WJESVBWN.js} +1 -1
- package/dist/{chunk-XDINDYNA.cjs → chunk-XTMZTVIT.cjs} +134 -134
- package/dist/{effect-ISvXPLgc.d.ts → effect-DM56H743.d.ts} +191 -21
- package/dist/http/index.cjs +808 -140
- package/dist/http/index.d.ts +181 -8
- package/dist/http/index.js +793 -125
- package/dist/http/index.mjs +793 -125
- package/dist/index.cjs +1785 -137
- package/dist/index.d.ts +979 -36
- package/dist/index.js +1675 -27
- package/dist/index.mjs +1675 -27
- package/dist/stream-Oqe6WeLE.d.ts +173 -0
- package/package.json +1 -1
- package/wasm/pkg/brass_runtime_wasm_engine.d.ts +95 -16
- package/wasm/pkg/brass_runtime_wasm_engine.js +715 -15
- package/wasm/pkg/brass_runtime_wasm_engine_bg.wasm +0 -0
- package/wasm/pkg/brass_runtime_wasm_engine_bg.wasm.d.ts +78 -7
- package/dist/chunk-2P4PD6D7.cjs +0 -2557
- package/dist/chunk-7F2R7A2V.mjs +0 -2557
- package/dist/chunk-L6KKKM66.js +0 -2557
- package/dist/chunk-ZTDK2DLG.cjs +0 -407
- package/dist/stream-BvukHxCv.d.ts +0 -66
package/dist/index.d.ts
CHANGED
|
@@ -1,11 +1,679 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export {
|
|
3
|
-
import { Z as ZStream } from './stream-
|
|
4
|
-
export { C as Concat, E as Emit,
|
|
1
|
+
import { A as Async, E as Exit, R as Runtime, F as FiberEngine, W as WasmEngineRuntime, b as RuntimeFiber, c as FiberEngineStats, d as Fiber, e as FiberId, f as FiberStatus, g as RuntimeEvent, h as WasmBridge, i as OpcodeProgram, j as FiberId$1, k as EngineEvent, l as RefId, N as NodeId, m as OpcodeNode, S as Scope, n as RingBufferOptions, o as EngineStats, O as Option } from './effect-DM56H743.js';
|
|
2
|
+
export { p as AbortablePromiseFinish, q as AbortablePromiseLabelStats, r as AbortablePromiseOptions, s as AbortablePromiseOutcome, t as AbortablePromiseStats, u as AsyncRegisterRef, a as AsyncWithPromise, v as BoundedRingBuffer, C as CancelToken, w as Canceler, x as Cause, y as CustomHostAction, D as DbHostAction, z as DecodeRef, B as DefaultHostExecutor, G as EngineKind, H as EngineSelection, I as EngineSelectionMode, J as FiberEngineKind, K as FlatMapRef, L as FoldFailureRef, M as FoldSuccessRef, P as HostAction, Q as HostActionKind, T as HostActionResult, U as HostExecutionContext, V as HostExecutor, X as HostRegistry, Y as HostRegistryStats, _ as HttpHostAction, $ as Interrupted, a0 as Joiner, a1 as LaneStatsData, a2 as None, a3 as NoopHooks, a4 as ProgramBuilder, a5 as ProgramPatch, a6 as PushStatus, a7 as QueueHostAction, a8 as RingBuffer, a9 as RingBufferEngine, aa as RingBufferStatsData, ab as RuntimeCapabilities, ac as RuntimeEngineMode, ad as RuntimeOptions, ae as ScheduleResult, af as Scheduler, ag as SchedulerEngine, ah as SchedulerOptions, ai as SchedulerStats, aj as SchedulerStatsData, ak as ScopeId, al as Some, am as SyncRef, an as Task, ao as WasmFiberEngine, ap as WasmFiberEngineOptions, Z as ZIO, aq as abortablePromiseStats, ar as acquireRelease, as as async, at as asyncCatchAll, au as asyncFail, av as asyncFlatMap, aw as asyncFold, ax as asyncInterruptible, ay as asyncMap, az as asyncMapError, aA as asyncSucceed, aB as asyncSync, aC as asyncTotal, aD as catchAll, aE as end, aF as engineStats, aG as fail, aH as flatMap, aI as fork, aJ as fromPromiseAbortable, aK as getBenchmarkBudget, aL as getCurrentFiber, aM as globalScheduler, aN as inferCallerLaneFromStack, aO as laneTag, aP as linkAbortController, aQ as makeBoundedRingBuffer, aR as makeCancelToken, aS as map, aT as mapAsync, aU as mapError, aV as mapTryAsync, aW as none, aX as orElseOptional, aY as resetAbortablePromiseStats, aZ as runtimeCapabilities, a_ as runtimeForCaller, a$ as sanitizeLaneKey, b0 as selectedEngineStats, b1 as setBenchmarkBudget, b2 as some, b3 as succeed, b4 as sync, b5 as toPromise, b6 as toPromiseByCaller, b7 as unit, b8 as unsafeGetCurrentRuntime, b9 as unsafeRunAsync, ba as unsafeRunFoldWithEnv, bb as withAsyncPromise, bc as withCurrentFiber, bd as withScope, be as withScopeAsync } from './effect-DM56H743.js';
|
|
3
|
+
import { Z as ZStream } from './stream-Oqe6WeLE.js';
|
|
4
|
+
export { a as CircuitBreaker, C as CircuitBreakerConfig, b as CircuitBreakerError, c as CircuitBreakerState, d as CircuitBreakerStats, e as Concat, E as Emit, f as Empty, F as Flatten, g as FromArray, h as FromPull, M as Managed, i as Merge, N as Normalize, S as Scoped, j as Span, k as SpanContext, l as SpanEvent, m as SpanStatus, T as Tracer, n as TracerConfig, o as assertNever, p as collectStream, q as concatStream, r as emitStream, s as emptyStream, t as flattenStream, u as foreachStream, v as fromArray, w as fromPull, x as makeCircuitBreaker, y as makeTracer, z as managedStream, A as mapStream, B as merge, D as mergeStream, G as rangeStream, H as streamFromReadableStream, I as uncons, J as unwrapScoped, K as widenOpt, L as zip } from './stream-Oqe6WeLE.js';
|
|
5
|
+
|
|
6
|
+
type TimeoutError = {
|
|
7
|
+
readonly _tag: "TimeoutError";
|
|
8
|
+
readonly ms: number;
|
|
9
|
+
};
|
|
10
|
+
/**
|
|
11
|
+
* Suspends the fiber for `ms` milliseconds. Cancellable via fiber interruption.
|
|
12
|
+
*/
|
|
13
|
+
declare function sleep(ms: number): Async<unknown, never, void>;
|
|
14
|
+
/**
|
|
15
|
+
* Runs `effect` with a timeout of `ms` milliseconds.
|
|
16
|
+
* - If the effect completes before the timeout, returns its result.
|
|
17
|
+
* - If the timeout fires first, the effect is cancelled and a TimeoutError is returned.
|
|
18
|
+
*
|
|
19
|
+
* Works with ANY effect type (Async, FlatMap, Fold, etc.) by forking
|
|
20
|
+
* the effect into a child fiber and interrupting it on timeout.
|
|
21
|
+
*/
|
|
22
|
+
declare function timeout<R, E, A>(effect: Async<R, E, A>, ms: number): Async<R, E | TimeoutError, A>;
|
|
23
|
+
type RetryPolicy = {
|
|
24
|
+
/** Maximum number of retry attempts (0 = no retries, just the initial attempt) */
|
|
25
|
+
readonly maxRetries: number;
|
|
26
|
+
/** Base delay in ms for exponential backoff */
|
|
27
|
+
readonly baseDelayMs: number;
|
|
28
|
+
/** Maximum delay cap in ms */
|
|
29
|
+
readonly maxDelayMs: number;
|
|
30
|
+
/** Total time budget in ms (optional). Retries stop if elapsed time exceeds this. */
|
|
31
|
+
readonly maxElapsedMs?: number;
|
|
32
|
+
/** Custom predicate: should this error trigger a retry? Default: always retry. */
|
|
33
|
+
readonly shouldRetry?: (error: unknown, attempt: number) => boolean;
|
|
34
|
+
/** Jitter strategy. Default: "full" (random 0..delay). "none" = no jitter. */
|
|
35
|
+
readonly jitter?: "full" | "none";
|
|
36
|
+
};
|
|
37
|
+
type RetryState = {
|
|
38
|
+
readonly attempt: number;
|
|
39
|
+
readonly elapsedMs: number;
|
|
40
|
+
readonly lastError: unknown;
|
|
41
|
+
};
|
|
42
|
+
/**
|
|
43
|
+
* Retries an effect according to the given policy.
|
|
44
|
+
* Uses exponential backoff with full jitter by default.
|
|
45
|
+
*
|
|
46
|
+
* ```ts
|
|
47
|
+
* const result = retry(
|
|
48
|
+
* fetchData(),
|
|
49
|
+
* { maxRetries: 3, baseDelayMs: 100, maxDelayMs: 5000 }
|
|
50
|
+
* );
|
|
51
|
+
* ```
|
|
52
|
+
*/
|
|
53
|
+
declare function retry<R, E, A>(effect: Async<R, E, A>, policy: RetryPolicy): Async<R, E, A>;
|
|
54
|
+
/**
|
|
55
|
+
* Retry with a simple count (no backoff, immediate retry).
|
|
56
|
+
* Useful for flaky operations that just need a few attempts.
|
|
57
|
+
*/
|
|
58
|
+
declare function retryN<R, E, A>(effect: Async<R, E, A>, n: number): Async<R, E, A>;
|
|
59
|
+
/**
|
|
60
|
+
* Retry with exponential backoff and full jitter.
|
|
61
|
+
* Convenience wrapper with sensible defaults.
|
|
62
|
+
*/
|
|
63
|
+
declare function retryWithBackoff<R, E, A>(effect: Async<R, E, A>, opts?: {
|
|
64
|
+
maxRetries?: number;
|
|
65
|
+
baseDelayMs?: number;
|
|
66
|
+
maxDelayMs?: number;
|
|
67
|
+
maxElapsedMs?: number;
|
|
68
|
+
shouldRetry?: (error: unknown, attempt: number) => boolean;
|
|
69
|
+
}): Async<R, E, A>;
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* Acquires a resource, uses it, and guarantees release regardless of outcome.
|
|
73
|
+
*
|
|
74
|
+
* - `acquire` runs uninterruptibly (once started, it completes)
|
|
75
|
+
* - `use` runs with the acquired resource
|
|
76
|
+
* - `release` runs after `use` completes (success, failure, or interruption)
|
|
77
|
+
*
|
|
78
|
+
* ```ts
|
|
79
|
+
* const result = bracket(
|
|
80
|
+
* openConnection(), // acquire
|
|
81
|
+
* (conn) => queryDatabase(conn), // use
|
|
82
|
+
* (conn, exit) => conn.close() // release (always runs)
|
|
83
|
+
* );
|
|
84
|
+
* ```
|
|
85
|
+
*/
|
|
86
|
+
declare function bracket<R, E, A, B>(acquire: Async<R, E, A>, use: (resource: A) => Async<R, E, B>, release: (resource: A, exit: Exit<E, B>) => Async<R, any, void>): Async<R, E, B>;
|
|
87
|
+
/**
|
|
88
|
+
* Runs `effect` and then runs `finalizer` regardless of the outcome.
|
|
89
|
+
* The finalizer receives the exit value for inspection.
|
|
90
|
+
*
|
|
91
|
+
* ```ts
|
|
92
|
+
* const result = ensuring(
|
|
93
|
+
* doWork(),
|
|
94
|
+
* (exit) => logCompletion(exit)
|
|
95
|
+
* );
|
|
96
|
+
* ```
|
|
97
|
+
*/
|
|
98
|
+
declare function ensuring<R, E, A>(effect: Async<R, E, A>, finalizer: (exit: Exit<E, A>) => Async<R, any, void>): Async<R, E, A>;
|
|
99
|
+
/**
|
|
100
|
+
* A Managed resource describes how to acquire and release a resource.
|
|
101
|
+
* It can be used multiple times — each `use` call acquires a fresh instance.
|
|
102
|
+
*
|
|
103
|
+
* ```ts
|
|
104
|
+
* const dbPool = managed(
|
|
105
|
+
* createPool({ max: 10 }),
|
|
106
|
+
* (pool) => pool.close()
|
|
107
|
+
* );
|
|
108
|
+
*
|
|
109
|
+
* // Use it:
|
|
110
|
+
* const result = useManaged(dbPool, (pool) => pool.query("SELECT 1"));
|
|
111
|
+
* ```
|
|
112
|
+
*/
|
|
113
|
+
type Managed<R, E, A> = {
|
|
114
|
+
readonly _tag: "Managed";
|
|
115
|
+
readonly acquire: Async<R, E, A>;
|
|
116
|
+
readonly release: (resource: A, exit: Exit<any, any>) => Async<R, any, void>;
|
|
117
|
+
};
|
|
118
|
+
/**
|
|
119
|
+
* Creates a Managed resource descriptor.
|
|
120
|
+
*/
|
|
121
|
+
declare function managed<R, E, A>(acquire: Async<R, E, A>, release: (resource: A, exit?: Exit<any, any>) => Async<R, any, void>): Managed<R, E, A>;
|
|
122
|
+
/**
|
|
123
|
+
* Uses a Managed resource: acquires, runs the body, and releases.
|
|
124
|
+
*/
|
|
125
|
+
declare function useManaged<R, E, A, B>(m: Managed<R, E, A>, body: (resource: A) => Async<R, E, B>): Async<R, E, B>;
|
|
126
|
+
/**
|
|
127
|
+
* Combines multiple Managed resources. All are acquired in order,
|
|
128
|
+
* and released in reverse order (LIFO).
|
|
129
|
+
*
|
|
130
|
+
* ```ts
|
|
131
|
+
* const resources = managedAll([dbPool, cacheConn, fileHandle]);
|
|
132
|
+
* const result = useManaged(resources, ([db, cache, file]) => ...);
|
|
133
|
+
* ```
|
|
134
|
+
*/
|
|
135
|
+
declare function managedAll<R, E, Resources extends readonly any[]>(manageds: {
|
|
136
|
+
[K in keyof Resources]: Managed<R, E, Resources[K]>;
|
|
137
|
+
}): Managed<R, E, Resources>;
|
|
138
|
+
|
|
139
|
+
type Semaphore = {
|
|
140
|
+
/** Current number of available permits. */
|
|
141
|
+
readonly available: () => number;
|
|
142
|
+
/** Total number of permits (capacity). */
|
|
143
|
+
readonly capacity: number;
|
|
144
|
+
/** Number of effects waiting for a permit. */
|
|
145
|
+
readonly waiting: () => number;
|
|
146
|
+
/** Acquire a permit, run the effect, and release the permit. */
|
|
147
|
+
readonly withPermit: <R, E, A>(effect: Async<R, E, A>) => Async<R, E, A>;
|
|
148
|
+
/** Acquire a permit (manual). Must call release() when done. */
|
|
149
|
+
readonly acquire: () => Async<unknown, never, void>;
|
|
150
|
+
/** Release a permit (manual). */
|
|
151
|
+
readonly release: () => void;
|
|
152
|
+
};
|
|
153
|
+
type SemaphoreStats = {
|
|
154
|
+
readonly capacity: number;
|
|
155
|
+
readonly available: number;
|
|
156
|
+
readonly waiting: number;
|
|
157
|
+
readonly acquired: number;
|
|
158
|
+
readonly released: number;
|
|
159
|
+
};
|
|
160
|
+
/**
|
|
161
|
+
* Creates a counting semaphore with `n` permits.
|
|
162
|
+
*
|
|
163
|
+
* ```ts
|
|
164
|
+
* const sem = makeSemaphore(5); // max 5 concurrent
|
|
165
|
+
*
|
|
166
|
+
* // Automatic acquire/release:
|
|
167
|
+
* const result = await run(sem.withPermit(fetchData()));
|
|
168
|
+
*
|
|
169
|
+
* // Manual acquire/release:
|
|
170
|
+
* await run(sem.acquire());
|
|
171
|
+
* try { ... } finally { sem.release(); }
|
|
172
|
+
* ```
|
|
173
|
+
*/
|
|
174
|
+
declare function makeSemaphore(n: number): Semaphore;
|
|
175
|
+
|
|
176
|
+
type Ref<A> = {
|
|
177
|
+
/** Get the current value. */
|
|
178
|
+
readonly get: () => Async<unknown, never, A>;
|
|
179
|
+
/** Set a new value. */
|
|
180
|
+
readonly set: (value: A) => Async<unknown, never, void>;
|
|
181
|
+
/** Modify the value with a function and return the new value. */
|
|
182
|
+
readonly update: (f: (current: A) => A) => Async<unknown, never, A>;
|
|
183
|
+
/** Modify the value and return a derived result. */
|
|
184
|
+
readonly modify: <B>(f: (current: A) => [B, A]) => Async<unknown, never, B>;
|
|
185
|
+
/** Get the current value synchronously (for non-effect contexts). */
|
|
186
|
+
readonly unsafeGet: () => A;
|
|
187
|
+
};
|
|
188
|
+
/**
|
|
189
|
+
* Creates a mutable reference with an initial value.
|
|
190
|
+
*
|
|
191
|
+
* ```ts
|
|
192
|
+
* const counter = makeRef(0);
|
|
193
|
+
*
|
|
194
|
+
* // In effects:
|
|
195
|
+
* await run(counter.update(n => n + 1));
|
|
196
|
+
* const value = await run(counter.get());
|
|
197
|
+
*
|
|
198
|
+
* // Synchronous access (outside effects):
|
|
199
|
+
* counter.unsafeGet();
|
|
200
|
+
* ```
|
|
201
|
+
*/
|
|
202
|
+
declare function makeRef<A>(initial: A): Ref<A>;
|
|
203
|
+
/**
|
|
204
|
+
* Creates a derived Ref that applies a lens to a parent Ref.
|
|
205
|
+
*
|
|
206
|
+
* ```ts
|
|
207
|
+
* const state = makeRef({ count: 0, name: "test" });
|
|
208
|
+
* const countRef = derivedRef(state, s => s.count, (s, c) => ({ ...s, count: c }));
|
|
209
|
+
* ```
|
|
210
|
+
*/
|
|
211
|
+
declare function derivedRef<A, B>(parent: Ref<A>, get: (a: A) => B, set: (a: A, b: B) => A): Ref<B>;
|
|
212
|
+
|
|
213
|
+
type ScheduleDecision = {
|
|
214
|
+
readonly continue: boolean;
|
|
215
|
+
readonly delayMs: number;
|
|
216
|
+
};
|
|
217
|
+
/**
|
|
218
|
+
* A Schedule<I, O> takes an input I (typically the error or output of an effect)
|
|
219
|
+
* and decides whether to continue and with what delay.
|
|
220
|
+
*/
|
|
221
|
+
type Schedule<I, O> = {
|
|
222
|
+
readonly _tag: "Schedule";
|
|
223
|
+
/** Initial state */
|
|
224
|
+
readonly initial: () => any;
|
|
225
|
+
/** Given current state and input, produce a decision and next state */
|
|
226
|
+
readonly step: (state: any, input: I) => [ScheduleDecision, any, O];
|
|
227
|
+
};
|
|
228
|
+
/** Retry/repeat up to N times with no delay. */
|
|
229
|
+
declare function recurs(n: number): Schedule<unknown, number>;
|
|
230
|
+
/** Fixed delay between each retry/repeat. */
|
|
231
|
+
declare function fixed(delayMs: number): Schedule<unknown, number>;
|
|
232
|
+
/** Exponential backoff: delay doubles each time, capped at maxDelayMs. */
|
|
233
|
+
declare function exponential(baseMs: number, maxMs?: number): Schedule<unknown, number>;
|
|
234
|
+
/** Exponential backoff with full jitter (random in [0, delay]). */
|
|
235
|
+
declare function jittered(baseMs: number, maxMs?: number): Schedule<unknown, number>;
|
|
236
|
+
/** Stop after a total elapsed time. */
|
|
237
|
+
declare function elapsed(maxMs: number): Schedule<unknown, number>;
|
|
238
|
+
/** Only continue while a predicate holds on the input. */
|
|
239
|
+
declare function whileInput<I>(pred: (input: I) => boolean): Schedule<I, I>;
|
|
240
|
+
/** Limit a schedule to N repetitions. */
|
|
241
|
+
declare function take$1<I, O>(schedule: Schedule<I, O>, n: number): Schedule<I, O>;
|
|
242
|
+
/** Compose two schedules: use the first, then switch to the second. */
|
|
243
|
+
declare function andThen$1<I, O1, O2>(first: Schedule<I, O1>, second: Schedule<I, O2>): Schedule<I, O1 | O2>;
|
|
244
|
+
/** Run both schedules and continue while BOTH say continue. Use max delay. */
|
|
245
|
+
declare function intersect<I, O1, O2>(left: Schedule<I, O1>, right: Schedule<I, O2>): Schedule<I, [O1, O2]>;
|
|
246
|
+
/** Run both schedules and continue while EITHER says continue. Use min delay. */
|
|
247
|
+
declare function union<I, O1, O2>(left: Schedule<I, O1>, right: Schedule<I, O2>): Schedule<I, [O1, O2]>;
|
|
248
|
+
/**
|
|
249
|
+
* Retry an effect according to a schedule.
|
|
250
|
+
* The schedule receives the error as input on each failure.
|
|
251
|
+
*/
|
|
252
|
+
declare function retryWithSchedule<R, E, A, O>(effect: Async<R, E, A>, schedule: Schedule<E, O>): Async<R, E, A>;
|
|
253
|
+
/**
|
|
254
|
+
* Repeat an effect according to a schedule.
|
|
255
|
+
* The schedule receives the success value as input on each iteration.
|
|
256
|
+
* Returns the last successful value.
|
|
257
|
+
*/
|
|
258
|
+
declare function repeatWithSchedule<R, E, A, O>(effect: Async<R, E, A>, schedule: Schedule<A, O>): Async<R, E, A>;
|
|
259
|
+
|
|
260
|
+
type ShutdownConfig = {
|
|
261
|
+
/** Max time to wait for in-flight work to complete. Default: 30000ms */
|
|
262
|
+
readonly timeoutMs?: number;
|
|
263
|
+
/** Called when shutdown starts. */
|
|
264
|
+
readonly onStart?: () => void;
|
|
265
|
+
/** Called when shutdown completes. */
|
|
266
|
+
readonly onComplete?: (stats: ShutdownStats) => void;
|
|
267
|
+
/** Called if shutdown times out. */
|
|
268
|
+
readonly onTimeout?: (stats: ShutdownStats) => void;
|
|
269
|
+
};
|
|
270
|
+
type ShutdownStats = {
|
|
271
|
+
readonly startedAt: number;
|
|
272
|
+
readonly completedAt: number;
|
|
273
|
+
readonly elapsedMs: number;
|
|
274
|
+
readonly timedOut: boolean;
|
|
275
|
+
};
|
|
276
|
+
/**
|
|
277
|
+
* Performs a graceful shutdown of the runtime.
|
|
278
|
+
*
|
|
279
|
+
* 1. Signals the scheduler to stop accepting new work
|
|
280
|
+
* 2. Waits for in-flight fibers to complete (up to timeoutMs)
|
|
281
|
+
* 3. Calls the runtime's shutdown hook
|
|
282
|
+
* 4. Reports stats
|
|
283
|
+
*
|
|
284
|
+
* ```ts
|
|
285
|
+
* await gracefulShutdown(runtime, {
|
|
286
|
+
* timeoutMs: 5000,
|
|
287
|
+
* onStart: () => console.log("Shutting down..."),
|
|
288
|
+
* onComplete: (stats) => console.log(`Done in ${stats.elapsedMs}ms`),
|
|
289
|
+
* });
|
|
290
|
+
* ```
|
|
291
|
+
*/
|
|
292
|
+
declare function gracefulShutdown<R>(runtime: Runtime<R>, config?: ShutdownConfig): Promise<ShutdownStats>;
|
|
293
|
+
/**
|
|
294
|
+
* Registers process signal handlers for graceful shutdown.
|
|
295
|
+
* Handles SIGTERM and SIGINT (Ctrl+C).
|
|
296
|
+
*
|
|
297
|
+
* ```ts
|
|
298
|
+
* registerShutdownHooks(runtime, {
|
|
299
|
+
* timeoutMs: 10000,
|
|
300
|
+
* onComplete: () => process.exit(0),
|
|
301
|
+
* onTimeout: () => process.exit(1),
|
|
302
|
+
* });
|
|
303
|
+
* ```
|
|
304
|
+
*/
|
|
305
|
+
declare function registerShutdownHooks<R>(runtime: Runtime<R>, config?: ShutdownConfig): () => void;
|
|
306
|
+
|
|
307
|
+
type TestRuntimeOptions = {
|
|
308
|
+
/** If true, effects run synchronously where possible. Default: true */
|
|
309
|
+
readonly synchronous?: boolean;
|
|
310
|
+
};
|
|
311
|
+
/**
|
|
312
|
+
* Creates a test runtime that provides controlled execution.
|
|
313
|
+
*
|
|
314
|
+
* ```ts
|
|
315
|
+
* const { runtime, run, runExit } = makeTestRuntime();
|
|
316
|
+
*
|
|
317
|
+
* const result = await run(myEffect);
|
|
318
|
+
* const exit = await runExit(myEffect); // get full Exit (success or failure)
|
|
319
|
+
* ```
|
|
320
|
+
*/
|
|
321
|
+
declare function makeTestRuntime<R = {}>(env?: R, options?: TestRuntimeOptions): {
|
|
322
|
+
runtime: Runtime<R>;
|
|
323
|
+
run: <E, A>(effect: Async<R, E, A>) => Promise<A>;
|
|
324
|
+
runExit: <E, A>(effect: Async<R, E, A>) => Promise<Exit<E, A>>;
|
|
325
|
+
};
|
|
326
|
+
/**
|
|
327
|
+
* Asserts that an effect succeeds with a specific value.
|
|
328
|
+
*
|
|
329
|
+
* ```ts
|
|
330
|
+
* await assertSucceeds(myEffect, 42);
|
|
331
|
+
* ```
|
|
332
|
+
*/
|
|
333
|
+
declare function assertSucceeds<R, E, A>(effect: Async<R, E, A>, expected: A, runtime?: Runtime<R>): Promise<void>;
|
|
334
|
+
/**
|
|
335
|
+
* Asserts that an effect fails with a specific error.
|
|
336
|
+
*
|
|
337
|
+
* ```ts
|
|
338
|
+
* await assertFails(myEffect, "not found");
|
|
339
|
+
* ```
|
|
340
|
+
*/
|
|
341
|
+
declare function assertFails<R, E, A>(effect: Async<R, E, A>, expectedError: E, runtime?: Runtime<R>): Promise<void>;
|
|
342
|
+
/**
|
|
343
|
+
* Asserts that an effect fails with an error matching a predicate.
|
|
344
|
+
*
|
|
345
|
+
* ```ts
|
|
346
|
+
* await assertFailsWith(myEffect, (e) => e._tag === "NotFound");
|
|
347
|
+
* ```
|
|
348
|
+
*/
|
|
349
|
+
declare function assertFailsWith<R, E, A>(effect: Async<R, E, A>, predicate: (error: E) => boolean, runtime?: Runtime<R>): Promise<void>;
|
|
350
|
+
/**
|
|
351
|
+
* Asserts that an effect completes within a time limit.
|
|
352
|
+
*
|
|
353
|
+
* ```ts
|
|
354
|
+
* await assertCompletesWithin(myEffect, 100); // must finish in 100ms
|
|
355
|
+
* ```
|
|
356
|
+
*/
|
|
357
|
+
declare function assertCompletesWithin<R, E, A>(effect: Async<R, E, A>, maxMs: number, runtime?: Runtime<R>): Promise<A>;
|
|
358
|
+
/**
|
|
359
|
+
* Creates an effect that fails on the first N calls, then succeeds.
|
|
360
|
+
* Useful for testing retry logic.
|
|
361
|
+
*
|
|
362
|
+
* ```ts
|
|
363
|
+
* const flaky = flakyEffect(3, "success!", "temporary error");
|
|
364
|
+
* // Fails 3 times, then returns "success!"
|
|
365
|
+
* ```
|
|
366
|
+
*/
|
|
367
|
+
declare function flakyEffect<E, A>(failCount: number, successValue: A, errorValue: E): Async<unknown, E, A>;
|
|
368
|
+
/**
|
|
369
|
+
* Creates an effect that takes a specific amount of time to complete.
|
|
370
|
+
* Useful for testing timeouts and concurrency.
|
|
371
|
+
*
|
|
372
|
+
* ```ts
|
|
373
|
+
* const slow = delayedEffect(100, "done"); // completes after 100ms
|
|
374
|
+
* ```
|
|
375
|
+
*/
|
|
376
|
+
declare function delayedEffect<A>(ms: number, value: A): Async<unknown, never, A>;
|
|
377
|
+
/**
|
|
378
|
+
* Creates an effect that never completes (hangs forever).
|
|
379
|
+
* Useful for testing timeouts and interruption.
|
|
380
|
+
*/
|
|
381
|
+
declare function neverEffect<A = never>(): Async<unknown, never, A>;
|
|
382
|
+
|
|
383
|
+
/**
|
|
384
|
+
* A Layer describes how to build a service.
|
|
385
|
+
*
|
|
386
|
+
* - RIn: dependencies required to build this service
|
|
387
|
+
* - E: possible failure during construction
|
|
388
|
+
* - ROut: the service produced
|
|
389
|
+
*/
|
|
390
|
+
type Layer<RIn, E, ROut> = {
|
|
391
|
+
readonly _tag: "Layer";
|
|
392
|
+
readonly build: (deps: RIn) => Async<unknown, E, {
|
|
393
|
+
service: ROut;
|
|
394
|
+
release: () => Async<unknown, never, void>;
|
|
395
|
+
}>;
|
|
396
|
+
};
|
|
397
|
+
/**
|
|
398
|
+
* Creates a Layer from an acquire/release pair.
|
|
399
|
+
*
|
|
400
|
+
* ```ts
|
|
401
|
+
* const DbLayer = layer(
|
|
402
|
+
* () => createPool({ max: 10 }),
|
|
403
|
+
* (pool) => pool.close()
|
|
404
|
+
* );
|
|
405
|
+
* ```
|
|
406
|
+
*/
|
|
407
|
+
declare function layer<ROut, E = never>(acquire: () => Async<unknown, E, ROut>, release?: (service: ROut) => Async<unknown, never, void>): Layer<unknown, E, ROut>;
|
|
408
|
+
/**
|
|
409
|
+
* Creates a Layer that depends on another service.
|
|
410
|
+
*
|
|
411
|
+
* ```ts
|
|
412
|
+
* const RepoLayer = layerFrom<DbPool>()(
|
|
413
|
+
* (pool) => createRepo(pool),
|
|
414
|
+
* (repo) => repo.close()
|
|
415
|
+
* );
|
|
416
|
+
* ```
|
|
417
|
+
*/
|
|
418
|
+
declare function layerFrom<RIn>(): <ROut, E = never>(acquire: (deps: RIn) => Async<unknown, E, ROut>, release?: (service: ROut) => Async<unknown, never, void>) => Layer<RIn, E, ROut>;
|
|
419
|
+
/**
|
|
420
|
+
* Creates a Layer from a pure value (no lifecycle).
|
|
421
|
+
*
|
|
422
|
+
* ```ts
|
|
423
|
+
* const ConfigLayer = layerSucceed({ port: 3000, host: "localhost" });
|
|
424
|
+
* ```
|
|
425
|
+
*/
|
|
426
|
+
declare function layerSucceed<ROut>(value: ROut): Layer<unknown, never, ROut>;
|
|
427
|
+
/**
|
|
428
|
+
* Creates a Layer that always fails.
|
|
429
|
+
*/
|
|
430
|
+
declare function layerFail<E>(error: E): Layer<unknown, E, never>;
|
|
431
|
+
/**
|
|
432
|
+
* Compose two layers: the output of `from` feeds into `to`.
|
|
433
|
+
*
|
|
434
|
+
* ```ts
|
|
435
|
+
* const AppLayer = compose(DbLayer, RepoLayer);
|
|
436
|
+
* // DbLayer produces DbPool → RepoLayer consumes DbPool → produces Repo
|
|
437
|
+
* ```
|
|
438
|
+
*/
|
|
439
|
+
declare function compose$1<R1, E1, Mid, E2, ROut>(from: Layer<R1, E1, Mid>, to: Layer<Mid, E2, ROut>): Layer<R1, E1 | E2, ROut>;
|
|
440
|
+
/**
|
|
441
|
+
* Merge two independent layers into one that produces both services.
|
|
442
|
+
*
|
|
443
|
+
* ```ts
|
|
444
|
+
* const AppLayer = merge(DbLayer, CacheLayer);
|
|
445
|
+
* // Produces { db: DbPool, cache: CacheClient }
|
|
446
|
+
* ```
|
|
447
|
+
*/
|
|
448
|
+
declare function merge<R1, E1, A, R2, E2, B>(left: Layer<R1, E1, A>, right: Layer<R2, E2, B>): Layer<R1 & R2, E1 | E2, A & B>;
|
|
449
|
+
/**
|
|
450
|
+
* Map the output of a layer.
|
|
451
|
+
*/
|
|
452
|
+
declare function mapLayer<RIn, E, A, B>(l: Layer<RIn, E, A>, f: (a: A) => B): Layer<RIn, E, B>;
|
|
453
|
+
/**
|
|
454
|
+
* Builds a layer, runs an effect with the produced service, and releases.
|
|
455
|
+
*
|
|
456
|
+
* ```ts
|
|
457
|
+
* const result = await run(
|
|
458
|
+
* provideLayer(AppLayer, (services) => services.db.query("SELECT 1"))
|
|
459
|
+
* );
|
|
460
|
+
* ```
|
|
461
|
+
*/
|
|
462
|
+
declare function provideLayer<RIn, E, ROut, E2, A>(l: Layer<RIn, E, ROut>, use: (service: ROut) => Async<unknown, E2, A>, deps?: RIn): Async<unknown, E | E2, A>;
|
|
463
|
+
|
|
464
|
+
type WorkerPoolConfig = {
|
|
465
|
+
/** Number of worker threads. Default: number of CPUs - 1 */
|
|
466
|
+
readonly size?: number;
|
|
467
|
+
/** Max queued tasks. Tasks beyond this are rejected. Default: 1000 */
|
|
468
|
+
readonly maxQueue?: number;
|
|
469
|
+
/** Task timeout in ms. Default: 30000 */
|
|
470
|
+
readonly taskTimeoutMs?: number;
|
|
471
|
+
};
|
|
472
|
+
type WorkerPoolError = {
|
|
473
|
+
readonly _tag: "WorkerPoolFull";
|
|
474
|
+
readonly queued: number;
|
|
475
|
+
} | {
|
|
476
|
+
readonly _tag: "WorkerTaskTimeout";
|
|
477
|
+
readonly ms: number;
|
|
478
|
+
} | {
|
|
479
|
+
readonly _tag: "WorkerTaskError";
|
|
480
|
+
readonly message: string;
|
|
481
|
+
} | {
|
|
482
|
+
readonly _tag: "WorkerPoolClosed";
|
|
483
|
+
};
|
|
484
|
+
type WorkerPool = {
|
|
485
|
+
/** Execute a function in a worker thread. */
|
|
486
|
+
readonly execute: <A>(fn: () => A) => Async<unknown, WorkerPoolError, A>;
|
|
487
|
+
/** Execute a serializable task (function source + args). */
|
|
488
|
+
readonly run: <A>(taskSource: string, args?: any[]) => Async<unknown, WorkerPoolError, A>;
|
|
489
|
+
/** Current pool stats. */
|
|
490
|
+
readonly stats: () => WorkerPoolStats;
|
|
491
|
+
/** Shutdown the pool (terminate all workers). */
|
|
492
|
+
readonly shutdown: () => Promise<void>;
|
|
493
|
+
};
|
|
494
|
+
type WorkerPoolStats = {
|
|
495
|
+
readonly size: number;
|
|
496
|
+
readonly busy: number;
|
|
497
|
+
readonly idle: number;
|
|
498
|
+
readonly queued: number;
|
|
499
|
+
readonly completed: number;
|
|
500
|
+
readonly failed: number;
|
|
501
|
+
readonly timedOut: number;
|
|
502
|
+
};
|
|
503
|
+
/**
|
|
504
|
+
* Creates a worker pool for CPU-intensive tasks.
|
|
505
|
+
*
|
|
506
|
+
* NOTE: This is a simplified implementation that uses setTimeout to simulate
|
|
507
|
+
* async execution. For real worker_threads support, the pool would need to
|
|
508
|
+
* spawn actual Worker instances. This provides the API contract and can be
|
|
509
|
+
* upgraded to real threads when needed.
|
|
510
|
+
*
|
|
511
|
+
* ```ts
|
|
512
|
+
* const pool = makeWorkerPool({ size: 4 });
|
|
513
|
+
*
|
|
514
|
+
* const result = await run(pool.execute(() => heavyComputation()));
|
|
515
|
+
*
|
|
516
|
+
* await pool.shutdown();
|
|
517
|
+
* ```
|
|
518
|
+
*/
|
|
519
|
+
declare function makeWorkerPool(config?: WorkerPoolConfig): WorkerPool;
|
|
520
|
+
|
|
521
|
+
type MetricType = "counter" | "gauge" | "histogram";
|
|
522
|
+
type MetricValue = {
|
|
523
|
+
readonly name: string;
|
|
524
|
+
readonly type: MetricType;
|
|
525
|
+
readonly value: number;
|
|
526
|
+
readonly labels: Record<string, string>;
|
|
527
|
+
readonly timestamp: number;
|
|
528
|
+
};
|
|
529
|
+
type HistogramBuckets = {
|
|
530
|
+
readonly boundaries: readonly number[];
|
|
531
|
+
counts: number[];
|
|
532
|
+
sum: number;
|
|
533
|
+
count: number;
|
|
534
|
+
min: number;
|
|
535
|
+
max: number;
|
|
536
|
+
};
|
|
537
|
+
type MetricsRegistry = {
|
|
538
|
+
/** Create or get a counter. */
|
|
539
|
+
readonly counter: (name: string, labels?: Record<string, string>) => Counter;
|
|
540
|
+
/** Create or get a gauge. */
|
|
541
|
+
readonly gauge: (name: string, labels?: Record<string, string>) => Gauge;
|
|
542
|
+
/** Create or get a histogram. */
|
|
543
|
+
readonly histogram: (name: string, boundaries?: number[], labels?: Record<string, string>) => Histogram;
|
|
544
|
+
/** Get all current metric values. */
|
|
545
|
+
readonly snapshot: () => MetricSnapshot;
|
|
546
|
+
/** Reset all metrics. */
|
|
547
|
+
readonly reset: () => void;
|
|
548
|
+
};
|
|
549
|
+
type Counter = {
|
|
550
|
+
readonly increment: (n?: number) => void;
|
|
551
|
+
readonly value: () => number;
|
|
552
|
+
};
|
|
553
|
+
type Gauge = {
|
|
554
|
+
readonly set: (value: number) => void;
|
|
555
|
+
readonly increment: (n?: number) => void;
|
|
556
|
+
readonly decrement: (n?: number) => void;
|
|
557
|
+
readonly value: () => number;
|
|
558
|
+
};
|
|
559
|
+
type Histogram = {
|
|
560
|
+
readonly observe: (value: number) => void;
|
|
561
|
+
readonly buckets: () => HistogramBuckets;
|
|
562
|
+
readonly percentile: (p: number) => number;
|
|
563
|
+
};
|
|
564
|
+
type MetricSnapshot = {
|
|
565
|
+
readonly counters: Array<{
|
|
566
|
+
name: string;
|
|
567
|
+
labels: Record<string, string>;
|
|
568
|
+
value: number;
|
|
569
|
+
}>;
|
|
570
|
+
readonly gauges: Array<{
|
|
571
|
+
name: string;
|
|
572
|
+
labels: Record<string, string>;
|
|
573
|
+
value: number;
|
|
574
|
+
}>;
|
|
575
|
+
readonly histograms: Array<{
|
|
576
|
+
name: string;
|
|
577
|
+
labels: Record<string, string>;
|
|
578
|
+
buckets: HistogramBuckets;
|
|
579
|
+
}>;
|
|
580
|
+
};
|
|
581
|
+
/**
|
|
582
|
+
* Creates a metrics registry.
|
|
583
|
+
*
|
|
584
|
+
* ```ts
|
|
585
|
+
* const metrics = makeMetrics();
|
|
586
|
+
*
|
|
587
|
+
* const requestCount = metrics.counter("http_requests_total", { method: "GET" });
|
|
588
|
+
* requestCount.increment();
|
|
589
|
+
*
|
|
590
|
+
* const latency = metrics.histogram("http_request_duration_ms");
|
|
591
|
+
* latency.observe(42.5);
|
|
592
|
+
*
|
|
593
|
+
* const activeConns = metrics.gauge("active_connections");
|
|
594
|
+
* activeConns.set(10);
|
|
595
|
+
*
|
|
596
|
+
* console.log(metrics.snapshot());
|
|
597
|
+
* ```
|
|
598
|
+
*/
|
|
599
|
+
declare function makeMetrics(): MetricsRegistry;
|
|
600
|
+
|
|
601
|
+
/**
|
|
602
|
+
* Base type for tagged errors. All errors should extend this pattern:
|
|
603
|
+
*
|
|
604
|
+
* ```ts
|
|
605
|
+
* type NetworkError = { _tag: "NetworkError"; url: string; status: number };
|
|
606
|
+
* type TimeoutError = { _tag: "TimeoutError"; ms: number };
|
|
607
|
+
* type AppError = NetworkError | TimeoutError;
|
|
608
|
+
* ```
|
|
609
|
+
*/
|
|
610
|
+
type TaggedError = {
|
|
611
|
+
readonly _tag: string;
|
|
612
|
+
};
|
|
613
|
+
/**
|
|
614
|
+
* Catches a specific error by its `_tag` field and handles it.
|
|
615
|
+
* Other errors pass through unchanged.
|
|
616
|
+
*
|
|
617
|
+
* ```ts
|
|
618
|
+
* const result = catchTag(effect, "NetworkError", (e) => fallbackValue);
|
|
619
|
+
* // e is narrowed to NetworkError
|
|
620
|
+
* ```
|
|
621
|
+
*/
|
|
622
|
+
declare function catchTag<R, E extends TaggedError, A, Tag extends E["_tag"], B>(effect: Async<R, E, A>, tag: Tag, handler: (error: Extract<E, {
|
|
623
|
+
_tag: Tag;
|
|
624
|
+
}>) => Async<R, Exclude<E, {
|
|
625
|
+
_tag: Tag;
|
|
626
|
+
}>, A | B>): Async<R, Exclude<E, {
|
|
627
|
+
_tag: Tag;
|
|
628
|
+
}>, A | B>;
|
|
629
|
+
/**
|
|
630
|
+
* Catches multiple error tags with a single handler map.
|
|
631
|
+
*
|
|
632
|
+
* ```ts
|
|
633
|
+
* const result = catchTags(effect, {
|
|
634
|
+
* NetworkError: (e) => asyncSucceed(defaultValue),
|
|
635
|
+
* TimeoutError: (e) => retry(effect),
|
|
636
|
+
* });
|
|
637
|
+
* ```
|
|
638
|
+
*/
|
|
639
|
+
declare function catchTags<R, E extends TaggedError, A, Handlers extends Partial<{
|
|
640
|
+
[K in E["_tag"]]: (error: Extract<E, {
|
|
641
|
+
_tag: K;
|
|
642
|
+
}>) => Async<R, any, any>;
|
|
643
|
+
}>>(effect: Async<R, E, A>, handlers: Handlers): Async<R, Exclude<E, {
|
|
644
|
+
_tag: keyof Handlers & string;
|
|
645
|
+
}>, A>;
|
|
646
|
+
/**
|
|
647
|
+
* Maps the error channel of an effect.
|
|
648
|
+
*
|
|
649
|
+
* ```ts
|
|
650
|
+
* const result = mapError(effect, (e) => ({ _tag: "Wrapped", cause: e }));
|
|
651
|
+
* ```
|
|
652
|
+
*/
|
|
653
|
+
declare function mapError<R, E, E2, A>(effect: Async<R, E, A>, f: (error: E) => E2): Async<R, E2, A>;
|
|
654
|
+
/**
|
|
655
|
+
* Wraps any error with a tag, making it part of a discriminated union.
|
|
656
|
+
*
|
|
657
|
+
* ```ts
|
|
658
|
+
* const typed = tagError(fetchData(), "NetworkError", (e) => ({ url, cause: e }));
|
|
659
|
+
* // Error type becomes { _tag: "NetworkError"; url: string; cause: unknown }
|
|
660
|
+
* ```
|
|
661
|
+
*/
|
|
662
|
+
declare function tagError<R, E, A, Tag extends string, Fields extends Record<string, unknown>>(effect: Async<R, E, A>, tag: Tag, enrich?: (error: E) => Fields): Async<R, {
|
|
663
|
+
_tag: Tag;
|
|
664
|
+
} & Fields, A>;
|
|
665
|
+
/**
|
|
666
|
+
* If the effect fails, run the fallback instead.
|
|
667
|
+
*
|
|
668
|
+
* ```ts
|
|
669
|
+
* const result = orElse(primary(), () => fallback());
|
|
670
|
+
* ```
|
|
671
|
+
*/
|
|
672
|
+
declare function orElse<R, E, A, R2, E2, B>(effect: Async<R, E, A>, fallback: (error: E) => Async<R2, E2, B>): Async<R & R2, E2, A | B>;
|
|
5
673
|
|
|
6
674
|
declare class JsFiberEngine<R> implements FiberEngine<R> {
|
|
7
675
|
private readonly runtime;
|
|
8
|
-
readonly kind: "
|
|
676
|
+
readonly kind: "ts";
|
|
9
677
|
private startedFibers;
|
|
10
678
|
constructor(runtime: WasmEngineRuntime<R> & any);
|
|
11
679
|
fork<E, A>(effect: Async<R, E, A>, scopeId?: number): RuntimeFiber<R, E, A>;
|
|
@@ -18,26 +686,31 @@ declare class EngineFiberHandle<R, E, A> implements Fiber<E, A> {
|
|
|
18
686
|
private readonly onInterrupt;
|
|
19
687
|
private readonly onJoiner?;
|
|
20
688
|
private readonly onQueued?;
|
|
689
|
+
private readonly onScheduleDropped?;
|
|
690
|
+
private readonly onScheduleRequest?;
|
|
21
691
|
readonly id: FiberId;
|
|
22
692
|
readonly runtime: WasmEngineRuntime<R> & any;
|
|
23
693
|
fiberContext: any;
|
|
24
694
|
name?: string;
|
|
25
695
|
scopeId?: number;
|
|
26
696
|
parentFiberId?: number;
|
|
697
|
+
lane?: string;
|
|
27
698
|
private result;
|
|
28
699
|
private readonly joiners;
|
|
29
700
|
private readonly finalizers;
|
|
30
701
|
private finalizersDrained;
|
|
31
702
|
private internalStatus;
|
|
32
703
|
private queued;
|
|
33
|
-
constructor(id: FiberId, runtime: WasmEngineRuntime<R> & any, onScheduledStep: (fiberId: FiberId) => void, onInterrupt: (fiberId: FiberId, reason: unknown) => void, onJoiner?: ((fiberId: FiberId) => void) | undefined, onQueued?: ((fiberId: FiberId) => void) | undefined);
|
|
704
|
+
constructor(id: FiberId, runtime: WasmEngineRuntime<R> & any, onScheduledStep: (fiberId: FiberId) => void, onInterrupt: (fiberId: FiberId, reason: unknown) => void, onJoiner?: ((fiberId: FiberId) => void) | undefined, onQueued?: ((fiberId: FiberId) => void) | undefined, onScheduleDropped?: ((fiberId: FiberId, label: string) => void) | undefined, onScheduleRequest?: ((fiberId: FiberId, label: string) => "accepted" | "dropped") | undefined);
|
|
34
705
|
status(): FiberStatus;
|
|
35
706
|
engineStatus(): InternalFiberStatus;
|
|
36
707
|
setEngineStatus(status: InternalFiberStatus): void;
|
|
708
|
+
markDequeued(): void;
|
|
37
709
|
join(cb: (exit: Exit<E, A>) => void): void;
|
|
38
710
|
interrupt(): void;
|
|
39
711
|
addFinalizer(f: (exit: Exit<E, A>) => void): void;
|
|
40
712
|
schedule(tag?: string): void;
|
|
713
|
+
private scheduleWithRuntime;
|
|
41
714
|
emit(ev: RuntimeEvent): void;
|
|
42
715
|
succeed(value: A): void;
|
|
43
716
|
fail(error: E): void;
|
|
@@ -47,43 +720,46 @@ declare class EngineFiberHandle<R, E, A> implements Fiber<E, A> {
|
|
|
47
720
|
private runFinalizersOnce;
|
|
48
721
|
}
|
|
49
722
|
|
|
50
|
-
declare class ReferenceWasmBridge implements WasmBridge {
|
|
51
|
-
readonly kind: "wasm-reference";
|
|
52
|
-
private nextFiberId;
|
|
53
|
-
private readonly fibers;
|
|
54
|
-
private started;
|
|
55
|
-
private completed;
|
|
56
|
-
private failed;
|
|
57
|
-
private interrupted;
|
|
58
|
-
createFiber(program: OpcodeProgram): FiberId$1;
|
|
59
|
-
poll(fiberId: FiberId$1): EngineEvent;
|
|
60
|
-
provideValue(fiberId: FiberId$1, valueRef: RefId): EngineEvent;
|
|
61
|
-
provideError(fiberId: FiberId$1, errorRef: RefId): EngineEvent;
|
|
62
|
-
provideEffect(fiberId: FiberId$1, root: NodeId, nodes: OpcodeNode[]): EngineEvent;
|
|
63
|
-
interrupt(fiberId: FiberId$1, reasonRef: RefId): EngineEvent;
|
|
64
|
-
dropFiber(fiberId: FiberId$1): void;
|
|
65
|
-
stats(): unknown;
|
|
66
|
-
private mustFiber;
|
|
67
|
-
private step;
|
|
68
|
-
private success;
|
|
69
|
-
private failure;
|
|
70
|
-
private suspend;
|
|
71
|
-
private markDone;
|
|
72
|
-
private markFailed;
|
|
73
|
-
}
|
|
74
|
-
|
|
75
723
|
declare class WasmPackFiberBridge implements WasmBridge {
|
|
76
724
|
readonly kind: "wasm";
|
|
725
|
+
readonly supportsBinary: boolean;
|
|
726
|
+
readonly supportsZeroCopy: boolean;
|
|
727
|
+
readonly supportsNoJsonMetrics: boolean;
|
|
77
728
|
private readonly vm;
|
|
729
|
+
private jsonEventCalls;
|
|
730
|
+
private binaryEventCalls;
|
|
731
|
+
private zeroCopyEventCalls;
|
|
732
|
+
private eventsReceived;
|
|
733
|
+
private maxEventsPerCall;
|
|
734
|
+
private jsonPrograms;
|
|
735
|
+
private binaryPrograms;
|
|
736
|
+
private zeroCopyPrograms;
|
|
737
|
+
private jsonPatches;
|
|
738
|
+
private binaryPatches;
|
|
739
|
+
private zeroCopyPatches;
|
|
78
740
|
constructor(modulePath?: string);
|
|
79
741
|
createFiber(program: OpcodeProgram): FiberId$1;
|
|
80
742
|
poll(fiberId: FiberId$1): EngineEvent;
|
|
743
|
+
driveBatch(fiberId: FiberId$1, budget: number): readonly EngineEvent[];
|
|
81
744
|
provideValue(fiberId: FiberId$1, valueRef: RefId): EngineEvent;
|
|
745
|
+
provideValueBatch(fiberId: FiberId$1, valueRef: RefId, budget: number): readonly EngineEvent[];
|
|
82
746
|
provideError(fiberId: FiberId$1, errorRef: RefId): EngineEvent;
|
|
747
|
+
provideErrorBatch(fiberId: FiberId$1, errorRef: RefId, budget: number): readonly EngineEvent[];
|
|
83
748
|
provideEffect(fiberId: FiberId$1, root: NodeId, nodes: OpcodeNode[]): EngineEvent;
|
|
749
|
+
provideEffectBatch(fiberId: FiberId$1, root: NodeId, nodes: OpcodeNode[], budget: number): readonly EngineEvent[];
|
|
84
750
|
interrupt(fiberId: FiberId$1, reasonRef: RefId): EngineEvent;
|
|
751
|
+
interruptBatch(fiberId: FiberId$1, reasonRef: RefId, budget: number): readonly EngineEvent[];
|
|
85
752
|
dropFiber(fiberId: FiberId$1): void;
|
|
86
753
|
stats(): unknown;
|
|
754
|
+
private assertStrictWasmHotPath;
|
|
755
|
+
private decodeZeroCopy;
|
|
756
|
+
private decodeBinary;
|
|
757
|
+
private decodeJson;
|
|
758
|
+
private memory;
|
|
759
|
+
private readU32;
|
|
760
|
+
private readF64;
|
|
761
|
+
private writeWords;
|
|
762
|
+
private readMetricsSnapshot;
|
|
87
763
|
}
|
|
88
764
|
|
|
89
765
|
type WasmFiberRegistryStats = {
|
|
@@ -120,6 +796,63 @@ declare class WasmFiberRegistryBridge {
|
|
|
120
796
|
stats(): WasmFiberRegistryStats;
|
|
121
797
|
}
|
|
122
798
|
|
|
799
|
+
type ReadyQueueScheduleKind = "micro" | "macro" | "none" | "dropped";
|
|
800
|
+
type FiberReadyQueueStats = {
|
|
801
|
+
readonly engine: "ts" | "wasm";
|
|
802
|
+
readonly fallbackUsed: boolean;
|
|
803
|
+
readonly data: unknown;
|
|
804
|
+
};
|
|
805
|
+
interface FiberReadyQueue {
|
|
806
|
+
readonly engine: "ts" | "wasm";
|
|
807
|
+
enqueue(fiberId: FiberId$1, tag: string): ReadyQueueScheduleKind;
|
|
808
|
+
beginFlush(): number;
|
|
809
|
+
shift(): FiberId$1 | undefined;
|
|
810
|
+
endFlush(ran: number): ReadyQueueScheduleKind;
|
|
811
|
+
len(): number;
|
|
812
|
+
clear(): void;
|
|
813
|
+
stats(): FiberReadyQueueStats;
|
|
814
|
+
}
|
|
815
|
+
type FiberReadyQueueOptions = {
|
|
816
|
+
readonly engine?: "ts" | "wasm";
|
|
817
|
+
readonly flushBudget?: number;
|
|
818
|
+
readonly microThreshold?: number;
|
|
819
|
+
readonly laneCapacity?: number;
|
|
820
|
+
readonly laneBudget?: number;
|
|
821
|
+
readonly maxLanes?: number;
|
|
822
|
+
};
|
|
823
|
+
declare function makeFiberReadyQueue(options?: FiberReadyQueueOptions): FiberReadyQueue;
|
|
824
|
+
|
|
825
|
+
declare const ABI_VERSION = 1;
|
|
826
|
+
declare const EVENT_WORDS = 5;
|
|
827
|
+
declare const NONE_U32 = 4294967295;
|
|
828
|
+
declare const enum OpcodeTagCode {
|
|
829
|
+
Succeed = 0,
|
|
830
|
+
Fail = 1,
|
|
831
|
+
Sync = 2,
|
|
832
|
+
Async = 3,
|
|
833
|
+
FlatMap = 4,
|
|
834
|
+
Fold = 5,
|
|
835
|
+
Fork = 6,
|
|
836
|
+
HostAction = 7
|
|
837
|
+
}
|
|
838
|
+
declare const enum EventKindCode {
|
|
839
|
+
Continue = 0,
|
|
840
|
+
Done = 1,
|
|
841
|
+
Failed = 2,
|
|
842
|
+
Interrupted = 3,
|
|
843
|
+
InvokeSync = 4,
|
|
844
|
+
InvokeAsync = 5,
|
|
845
|
+
InvokeFlatMap = 6,
|
|
846
|
+
InvokeFoldFailure = 7,
|
|
847
|
+
InvokeFoldSuccess = 8,
|
|
848
|
+
InvokeFork = 9,
|
|
849
|
+
InvokeHostAction = 10
|
|
850
|
+
}
|
|
851
|
+
declare function encodeOpcodeProgram(program: OpcodeProgram): Uint32Array;
|
|
852
|
+
declare function encodeOpcodeNodes(nodes: readonly OpcodeNode[]): Uint32Array;
|
|
853
|
+
declare function decodeEvent(words: ArrayLike<number>, offset?: number): EngineEvent;
|
|
854
|
+
declare function decodeEventBatch(words: ArrayLike<number> | null | undefined): EngineEvent[];
|
|
855
|
+
|
|
123
856
|
declare function buffer<R, E, A>(stream: ZStream<{} & R, E, A>, capacity: number, strategy?: "backpressure" | "dropping" | "sliding"): ZStream<{} & R, E, A>;
|
|
124
857
|
|
|
125
858
|
/**
|
|
@@ -152,6 +885,10 @@ type QueueClosed = {
|
|
|
152
885
|
type Queue<A> = {
|
|
153
886
|
offer: (a: A) => Async<unknown, never, boolean>;
|
|
154
887
|
take: () => Async<unknown, QueueClosed, A>;
|
|
888
|
+
/** Offer multiple values in a single effect. Returns array of success flags. */
|
|
889
|
+
offerBatch: (values: readonly A[]) => Async<unknown, never, boolean[]>;
|
|
890
|
+
/** Take up to N values in a single effect. Returns available values (may be fewer than N). */
|
|
891
|
+
takeBatch: (n: number) => Async<unknown, QueueClosed, A[]>;
|
|
155
892
|
size: () => number;
|
|
156
893
|
shutdown: () => void;
|
|
157
894
|
};
|
|
@@ -176,12 +913,13 @@ declare const broadcast: typeof makeHub;
|
|
|
176
913
|
declare function broadcastToHub<R, E, A>(stream: ZStream<R, E, A>, hub: Hub<A>): Async<R, E, void>;
|
|
177
914
|
declare function fromHub<A>(hub: Hub<A>): ZStream<unknown, HubClosed, A>;
|
|
178
915
|
|
|
179
|
-
type StreamChunkEngine = "
|
|
916
|
+
type StreamChunkEngine = "ts" | "wasm";
|
|
180
917
|
type StreamChunkOptions = {
|
|
181
918
|
/**
|
|
182
|
-
*
|
|
183
|
-
* js: always use the JS array chunker.
|
|
919
|
+
* ts: always use the TypeScript array chunker.
|
|
184
920
|
* wasm: require BrassWasmChunkBuffer from wasm/pkg.
|
|
921
|
+
*
|
|
922
|
+
* Strict mode never falls back between engines.
|
|
185
923
|
*/
|
|
186
924
|
engine?: StreamChunkEngine;
|
|
187
925
|
};
|
|
@@ -219,7 +957,12 @@ declare function mapChunksEffect<Rp, Ep, A, B>(chunkSize: number, f: (chunk: rea
|
|
|
219
957
|
* When applied to a stream `ZStream<R, E, In>`, the result is `ZStream<R & Rp, E | Ep, Out>`.
|
|
220
958
|
*/
|
|
221
959
|
type ZPipeline<Rp, Ep, In, Out> = <R, E>(input: ZStream<R, E, In>) => ZStream<R & Rp, E | Ep, Out>;
|
|
222
|
-
/** Apply a pipeline to a stream (alias of `pipeline(stream)`).
|
|
960
|
+
/** Apply a pipeline to a stream (alias of `pipeline(stream)`).
|
|
961
|
+
*
|
|
962
|
+
* OPTIMIZATION: When the pipeline is a single pure operator (has PURE_PIPELINE_TAG)
|
|
963
|
+
* and the stream can be drained synchronously, uses the fast fused path.
|
|
964
|
+
* The FusedPipelineRepr is cached on the pipeline to avoid recalculation.
|
|
965
|
+
*/
|
|
223
966
|
declare function via<R, E, A, Rp, Ep, B>(stream: ZStream<R, E, A>, pipeline: ZPipeline<Rp, Ep, A, B>): ZStream<R & Rp, E | Ep, B>;
|
|
224
967
|
/** Compose pipelines left-to-right (p1 >>> p2). */
|
|
225
968
|
declare function andThen<R1, E1, In, Mid, R2, E2, Out>(p1: ZPipeline<R1, E1, In, Mid>, p2: ZPipeline<R2, E2, Mid, Out>): ZPipeline<R1 & R2, E1 | E2, In, Out>;
|
|
@@ -255,4 +998,204 @@ declare function bufferP<A>(capacity: number, strategy?: "backpressure" | "dropp
|
|
|
255
998
|
*/
|
|
256
999
|
declare function groupedP<A>(n: number): ZPipeline<unknown, never, A, A[]>;
|
|
257
1000
|
|
|
258
|
-
|
|
1001
|
+
/** Serialized representation of a single step in a fused pipeline */
|
|
1002
|
+
type SerializedStep = {
|
|
1003
|
+
kind: "map";
|
|
1004
|
+
fnSource: string;
|
|
1005
|
+
} | {
|
|
1006
|
+
kind: "filter";
|
|
1007
|
+
predSource: string;
|
|
1008
|
+
} | {
|
|
1009
|
+
kind: "take";
|
|
1010
|
+
n: number;
|
|
1011
|
+
} | {
|
|
1012
|
+
kind: "drop";
|
|
1013
|
+
n: number;
|
|
1014
|
+
};
|
|
1015
|
+
/** JSON-safe serialized representation of a fused pipeline */
|
|
1016
|
+
type SerializedFusedPipeline = {
|
|
1017
|
+
readonly version: 1;
|
|
1018
|
+
readonly steps: SerializedStep[];
|
|
1019
|
+
};
|
|
1020
|
+
/** Enable or disable fusion globally. When disabled, andThen will not attempt fusion. */
|
|
1021
|
+
declare function setFusionEnabled(enabled: boolean): void;
|
|
1022
|
+
/** Check if fusion is globally enabled. */
|
|
1023
|
+
declare function isFusionEnabled(): boolean;
|
|
1024
|
+
/** Set verbose mode globally. When enabled, fusion decisions are logged to console. */
|
|
1025
|
+
declare function setFusionVerbose(verbose: boolean): void;
|
|
1026
|
+
/** Check if verbose mode is globally enabled. */
|
|
1027
|
+
declare function isFusionVerbose(): boolean;
|
|
1028
|
+
/**
|
|
1029
|
+
* Get stats from a fused pipeline, or null if the pipeline is not fused.
|
|
1030
|
+
* Works with pipelines that have been fused via `andThen` (have `_fusedSteps`)
|
|
1031
|
+
* or with `FusedPipelineRepr` objects directly.
|
|
1032
|
+
*/
|
|
1033
|
+
declare function getStats<In, Out>(pipeline: ZPipeline<unknown, never, In, Out>): FusedPipelineStats | null;
|
|
1034
|
+
declare const PURE_PIPELINE_TAG: unique symbol;
|
|
1035
|
+
/** Result of a fused step for an element */
|
|
1036
|
+
type FuseResult<A> = {
|
|
1037
|
+
readonly tag: "emit";
|
|
1038
|
+
readonly value: A;
|
|
1039
|
+
} | {
|
|
1040
|
+
readonly tag: "skip";
|
|
1041
|
+
} | {
|
|
1042
|
+
readonly tag: "halt";
|
|
1043
|
+
};
|
|
1044
|
+
/** Metadata of a step in the original pipeline */
|
|
1045
|
+
type FusedStep = {
|
|
1046
|
+
readonly kind: "map";
|
|
1047
|
+
} | {
|
|
1048
|
+
readonly kind: "filter";
|
|
1049
|
+
} | {
|
|
1050
|
+
readonly kind: "take";
|
|
1051
|
+
readonly n: number;
|
|
1052
|
+
} | {
|
|
1053
|
+
readonly kind: "drop";
|
|
1054
|
+
readonly n: number;
|
|
1055
|
+
};
|
|
1056
|
+
/** Stats of a fused pipeline */
|
|
1057
|
+
type FusedPipelineStats = {
|
|
1058
|
+
readonly fusedSteps: number;
|
|
1059
|
+
readonly steps: readonly FusedStep[];
|
|
1060
|
+
readonly hasTake: boolean;
|
|
1061
|
+
readonly hasDrop: boolean;
|
|
1062
|
+
};
|
|
1063
|
+
/** Internal representation of a fused pipeline */
|
|
1064
|
+
type FusedPipelineRepr<In, Out> = {
|
|
1065
|
+
readonly _tag: "FusedPipeline";
|
|
1066
|
+
readonly step: (a: In, state: FuseState) => FuseResult<Out>;
|
|
1067
|
+
readonly initState: () => FuseState;
|
|
1068
|
+
readonly stats: FusedPipelineStats;
|
|
1069
|
+
};
|
|
1070
|
+
/** Mutable state during execution (per-step counters for take/drop) */
|
|
1071
|
+
type FuseState = {
|
|
1072
|
+
/** Per-step counters: each take/drop step gets its own independent counter */
|
|
1073
|
+
counters: number[];
|
|
1074
|
+
};
|
|
1075
|
+
/** Fusion options */
|
|
1076
|
+
type FusionOptions = {
|
|
1077
|
+
readonly enabled?: boolean;
|
|
1078
|
+
readonly verbose?: boolean;
|
|
1079
|
+
};
|
|
1080
|
+
type PurePipelineMetadata<In, Out> = {
|
|
1081
|
+
readonly kind: "map" | "filter" | "take" | "drop";
|
|
1082
|
+
readonly fn?: (a: In) => Out;
|
|
1083
|
+
readonly pred?: (a: In) => boolean;
|
|
1084
|
+
readonly n?: number;
|
|
1085
|
+
};
|
|
1086
|
+
type PurePipelineTag<In, Out> = {
|
|
1087
|
+
readonly [PURE_PIPELINE_TAG]: PurePipelineMetadata<In, Out>;
|
|
1088
|
+
};
|
|
1089
|
+
/** Creates a FuseState with per-step counters (one for each take/drop step) */
|
|
1090
|
+
declare function initState(counterCount: number): () => FuseState;
|
|
1091
|
+
/**
|
|
1092
|
+
* Detects if a pipeline is fusable and returns the fused representation.
|
|
1093
|
+
* Returns null if the pipeline is not fusable (not pure or fusion disabled).
|
|
1094
|
+
*/
|
|
1095
|
+
declare function fuse<In, Out>(pipeline: ZPipeline<unknown, never, In, Out>, options?: FusionOptions): FusedPipelineRepr<In, Out> | null;
|
|
1096
|
+
/**
|
|
1097
|
+
* Applies a fused pipeline to an array of inputs synchronously.
|
|
1098
|
+
* This is the fastest execution path — a pure `for` loop with no effects,
|
|
1099
|
+
* no fibers, no scheduling overhead. O(n) with minimal constant factor.
|
|
1100
|
+
*/
|
|
1101
|
+
declare function runFusedArray<In, Out>(input: readonly In[], fused: FusedPipelineRepr<In, Out>): Out[];
|
|
1102
|
+
/**
|
|
1103
|
+
* Applies a fused pipeline to a stream using a single pull loop.
|
|
1104
|
+
* No intermediate fibers are created between fused operators.
|
|
1105
|
+
*
|
|
1106
|
+
* OPTIMIZATION: If the input stream can be drained synchronously (e.g., fromArray),
|
|
1107
|
+
* the entire pipeline is executed as a pure synchronous loop — no effects at all.
|
|
1108
|
+
*/
|
|
1109
|
+
declare function applyFused<R, E, In, Out>(stream: ZStream<R, E, In>, fused: FusedPipelineRepr<In, Out>): ZStream<R, E, Out>;
|
|
1110
|
+
/**
|
|
1111
|
+
* Serialize a fused pipeline to a JSON-safe representation.
|
|
1112
|
+
* Returns null if the pipeline is not fused (no _fusedSteps metadata).
|
|
1113
|
+
*
|
|
1114
|
+
* For map/filter steps, the function/predicate source is captured via `.toString()`.
|
|
1115
|
+
* Note: toString() has limitations with closures and minification, but is sufficient
|
|
1116
|
+
* for debugging/observability use cases.
|
|
1117
|
+
*/
|
|
1118
|
+
declare function serializeFusedPipeline<In, Out>(pipeline: ZPipeline<unknown, never, In, Out>): SerializedFusedPipeline | null;
|
|
1119
|
+
/**
|
|
1120
|
+
* Deserialize a serialized pipeline back to a functional pipeline.
|
|
1121
|
+
* Returns null if deserialization fails (e.g., invalid version, malformed fnSource).
|
|
1122
|
+
*
|
|
1123
|
+
* Reconstructs functions using `new Function(...)` with appropriate wrapping.
|
|
1124
|
+
* The resulting pipeline is functionally equivalent to the original for pure
|
|
1125
|
+
* (non-closure) functions.
|
|
1126
|
+
*
|
|
1127
|
+
* WARNING: Uses `new Function()` which has security implications similar to `eval`.
|
|
1128
|
+
* Only deserialize trusted serialized pipelines.
|
|
1129
|
+
*/
|
|
1130
|
+
declare function deserializeFusedPipeline<In, Out>(serialized: SerializedFusedPipeline): ZPipeline<unknown, never, In, Out> | null;
|
|
1131
|
+
|
|
1132
|
+
/**
|
|
1133
|
+
* Throttles a stream to emit at most one element per `intervalMs`.
|
|
1134
|
+
* Elements arriving during the cooldown period are dropped.
|
|
1135
|
+
*
|
|
1136
|
+
* ```ts
|
|
1137
|
+
* const throttled = throttle(clickStream, 1000); // max 1 click per second
|
|
1138
|
+
* ```
|
|
1139
|
+
*/
|
|
1140
|
+
declare function throttle<R, E, A>(stream: ZStream<R, E, A>, intervalMs: number): ZStream<R, E, A>;
|
|
1141
|
+
/**
|
|
1142
|
+
* Debounces a stream: only emits an element after `delayMs` of silence.
|
|
1143
|
+
* If a new element arrives before the delay expires, the previous is dropped.
|
|
1144
|
+
*
|
|
1145
|
+
* Note: This is a simplified debounce that works by buffering the last element
|
|
1146
|
+
* and emitting it after a delay. For real-time use cases, consider using
|
|
1147
|
+
* the Hub-based approach with timers.
|
|
1148
|
+
*
|
|
1149
|
+
* ```ts
|
|
1150
|
+
* const debounced = debounce(inputStream, 300); // wait 300ms of silence
|
|
1151
|
+
* ```
|
|
1152
|
+
*/
|
|
1153
|
+
declare function debounce<R, E, A>(stream: ZStream<R, E, A>, delayMs: number): ZStream<R, E, A>;
|
|
1154
|
+
/**
|
|
1155
|
+
* Zips two streams together, pairing elements by position.
|
|
1156
|
+
* The resulting stream ends when either input stream ends.
|
|
1157
|
+
*
|
|
1158
|
+
* ```ts
|
|
1159
|
+
* const zipped = zip(numbersStream, lettersStream);
|
|
1160
|
+
* // [1, "a"], [2, "b"], [3, "c"], ...
|
|
1161
|
+
* ```
|
|
1162
|
+
*/
|
|
1163
|
+
declare function zip<R, E, A, B>(left: ZStream<R, E, A>, right: ZStream<R, E, B>): ZStream<R, E, [A, B]>;
|
|
1164
|
+
/**
|
|
1165
|
+
* Zips two streams with a custom combiner function.
|
|
1166
|
+
*
|
|
1167
|
+
* ```ts
|
|
1168
|
+
* const summed = zipWith(xs, ys, (x, y) => x + y);
|
|
1169
|
+
* ```
|
|
1170
|
+
*/
|
|
1171
|
+
declare function zipWith<R, E, A, B, C>(left: ZStream<R, E, A>, right: ZStream<R, E, B>, f: (a: A, b: B) => C): ZStream<R, E, C>;
|
|
1172
|
+
/**
|
|
1173
|
+
* Produces a stream of accumulated values using a reducer function.
|
|
1174
|
+
* Emits the initial value first, then each accumulated result.
|
|
1175
|
+
*
|
|
1176
|
+
* ```ts
|
|
1177
|
+
* const running = scan(numbersStream, 0, (acc, n) => acc + n);
|
|
1178
|
+
* // 0, 1, 3, 6, 10, ... (running sum)
|
|
1179
|
+
* ```
|
|
1180
|
+
*/
|
|
1181
|
+
declare function scan<R, E, A, B>(stream: ZStream<R, E, A>, initial: B, f: (acc: B, a: A) => B): ZStream<R, E, B>;
|
|
1182
|
+
/**
|
|
1183
|
+
* Interleaves two streams, alternating elements from each.
|
|
1184
|
+
* When one stream ends, remaining elements from the other are emitted.
|
|
1185
|
+
*
|
|
1186
|
+
* ```ts
|
|
1187
|
+
* const mixed = interleave(evens, odds);
|
|
1188
|
+
* // 0, 1, 2, 3, 4, 5, ...
|
|
1189
|
+
* ```
|
|
1190
|
+
*/
|
|
1191
|
+
declare function interleave<R, E, A>(left: ZStream<R, E, A>, right: ZStream<R, E, A>): ZStream<R, E, A>;
|
|
1192
|
+
/**
|
|
1193
|
+
* Takes the first N elements from a stream.
|
|
1194
|
+
*/
|
|
1195
|
+
declare function take<R, E, A>(stream: ZStream<R, E, A>, n: number): ZStream<R, E, A>;
|
|
1196
|
+
/**
|
|
1197
|
+
* Drops the first N elements from a stream.
|
|
1198
|
+
*/
|
|
1199
|
+
declare function drop<R, E, A>(stream: ZStream<R, E, A>, n: number): ZStream<R, E, A>;
|
|
1200
|
+
|
|
1201
|
+
export { ABI_VERSION, Async, type Counter, EVENT_WORDS, EngineEvent, EngineFiberHandle, EngineStats, EventKindCode, Exit, Fiber, FiberEngine, FiberEngineStats, FiberId, type FiberReadyQueue, type FiberReadyQueueOptions, type FiberReadyQueueStats, FiberStatus, type FuseResult, type FuseState, type FusedPipelineRepr, type FusedPipelineStats, type FusedStep, type FusionOptions, type Gauge, type Histogram, type HistogramBuckets, type Hub, type HubClosed, type HubStrategy, type InternalFiberStatus, JsFiberEngine, type Layer, type Managed as ManagedResource, type MetricSnapshot, type MetricType, type MetricValue, type MetricsRegistry, NONE_U32, NodeId, OpcodeNode, OpcodeProgram, OpcodeTagCode, Option, PURE_PIPELINE_TAG, type PurePipelineMetadata, type PurePipelineTag, type Queue, type QueueClosed, type QueueOptions, type ReadyQueueScheduleKind, type Ref, RefId, type RetryPolicy, type RetryState, RingBufferOptions, Runtime, RuntimeFiber, type Schedule, type ScheduleDecision, Scope, type Semaphore, type SemaphoreStats, type SerializedFusedPipeline, type SerializedStep, type ShutdownConfig, type ShutdownStats, type Strategy, type StreamChunkEngine, type StreamChunkOptions, type StreamChunkStats, type Subscription, type TaggedError, type TestRuntimeOptions, type TimeoutError, WasmBridge, WasmEngineRuntime, WasmFiberRegistryBridge, type WasmFiberRegistryStats, WasmPackFiberBridge, type WorkerPool, type WorkerPoolConfig, type WorkerPoolError, type WorkerPoolStats, type ZPipeline, ZStream, andThen, andThen$1 as andThenSchedule, applyFused, assertCompletesWithin, assertFails, assertFailsWith, assertSucceeds, bounded, bracket, broadcast, broadcastToHub, buffer, bufferP, catchTag, catchTags, chunks, chunksP, collectAllPar, compose, compose$1 as composeLayer, debounce, decodeEvent, decodeEventBatch, delayedEffect, derivedRef, deserializeFusedPipeline, dropP, drop as dropStream, elapsed, encodeOpcodeNodes, encodeOpcodeProgram, ensuring, exponential, filterMapP, filterP, fixed, flakyEffect, fromHub, fuse, getStats, gracefulShutdown, groupedP, identity, initState, interleave, intersect, isFusionEnabled, isFusionVerbose, jittered, layer, layerFail, layerFrom, layerSucceed, makeFiberReadyQueue, makeHub, makeMetrics, makeRef, makeSemaphore, makeStreamChunker, makeTestRuntime, makeWorkerPool, managed, managedAll, mapChunks, mapChunksEffect, mapChunksEffectP, mapEffectP, mapError as mapErrorTyped, mapLayer, mapP, merge as mergeLayer, neverEffect, orElse, provideLayer, race, raceWith, recurs, registerShutdownHooks, repeatWithSchedule, retry, retryN, retryWithBackoff, retryWithSchedule, runFusedArray, scan, serializeFusedPipeline, setFusionEnabled, setFusionVerbose, sleep, tagError, takeP, take$1 as takeSchedule, take as takeStream, tapEffectP, throttle, timeout, union, useManaged, via, whileInput, zipPar, zip as zipStream, zipWith };
|