brass-runtime 1.13.8 → 1.15.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (49) hide show
  1. package/README.md +6 -3
  2. package/dist/agent/cli/main.cjs +44 -43
  3. package/dist/agent/cli/main.js +5 -4
  4. package/dist/agent/cli/main.mjs +5 -4
  5. package/dist/agent/index.cjs +4 -3
  6. package/dist/agent/index.d.ts +1 -1
  7. package/dist/agent/index.js +3 -2
  8. package/dist/agent/index.mjs +3 -2
  9. package/dist/{chunk-3R7ZYRK2.mjs → chunk-3QMOKAS5.js} +9 -7
  10. package/dist/{chunk-ATHSSDUF.js → chunk-4NHES7VK.mjs} +113 -31
  11. package/dist/chunk-AR22SXML.js +1043 -0
  12. package/dist/chunk-BDF4AMWX.mjs +3773 -0
  13. package/dist/chunk-BDYEENHT.js +224 -0
  14. package/dist/chunk-BMH5AV44.js +3773 -0
  15. package/dist/chunk-ELOOF35R.mjs +131 -0
  16. package/dist/chunk-JFPU5GQI.mjs +1043 -0
  17. package/dist/{chunk-INZBKOHY.js → chunk-K6M7MDZ4.mjs} +9 -7
  18. package/dist/chunk-MS34J5LY.cjs +224 -0
  19. package/dist/{chunk-XNOTJSMZ.mjs → chunk-PPUXIH5R.js} +113 -31
  20. package/dist/chunk-R3R2FVLG.cjs +131 -0
  21. package/dist/{chunk-ZTDK2DLG.cjs → chunk-STVLQ3XD.cjs} +169 -87
  22. package/dist/chunk-TGIFUAK4.cjs +3773 -0
  23. package/dist/chunk-TO7IKXYT.js +131 -0
  24. package/dist/chunk-UMAZLXAB.mjs +224 -0
  25. package/dist/{chunk-XDINDYNA.cjs → chunk-VEZNF5GZ.cjs} +136 -134
  26. package/dist/chunk-XPZNXSVN.cjs +1043 -0
  27. package/dist/core/index.cjs +216 -0
  28. package/dist/core/index.d.ts +673 -0
  29. package/dist/core/index.js +216 -0
  30. package/dist/core/index.mjs +216 -0
  31. package/dist/{effect-ISvXPLgc.d.ts → effect-CMOQKX8y.d.ts} +202 -31
  32. package/dist/http/index.cjs +3177 -187
  33. package/dist/http/index.d.ts +1692 -9
  34. package/dist/http/index.js +3164 -174
  35. package/dist/http/index.mjs +3164 -174
  36. package/dist/index.cjs +936 -219
  37. package/dist/index.d.ts +313 -36
  38. package/dist/index.js +830 -113
  39. package/dist/index.mjs +830 -113
  40. package/dist/{stream-BvukHxCv.d.ts → stream-FQm9h4Mg.d.ts} +12 -4
  41. package/dist/tracing-DNT9jEbr.d.ts +106 -0
  42. package/package.json +11 -3
  43. package/wasm/pkg/brass_runtime_wasm_engine.d.ts +95 -16
  44. package/wasm/pkg/brass_runtime_wasm_engine.js +715 -15
  45. package/wasm/pkg/brass_runtime_wasm_engine_bg.wasm +0 -0
  46. package/wasm/pkg/brass_runtime_wasm_engine_bg.wasm.d.ts +78 -7
  47. package/dist/chunk-2P4PD6D7.cjs +0 -2557
  48. package/dist/chunk-7F2R7A2V.mjs +0 -2557
  49. package/dist/chunk-L6KKKM66.js +0 -2557
package/dist/index.d.ts CHANGED
@@ -1,11 +1,13 @@
1
- import { F as FiberEngine, W as WasmEngineRuntime, A as Async, R as RuntimeFiber, b as FiberEngineStats, c as Fiber, d as FiberId, e as FiberStatus, E as Exit, f as RuntimeEvent, g as WasmBridge, h as OpcodeProgram, i as FiberId$1, j as EngineEvent, k as RefId, N as NodeId, l as OpcodeNode, S as Scope, m as RingBufferOptions, n as EngineStats, O as Option } from './effect-ISvXPLgc.js';
2
- export { o as AsyncRegisterRef, a as AsyncWithPromise, p as BoundedRingBuffer, C as CancelToken, q as Canceler, r as Cause, s as CustomHostAction, D as DbHostAction, t as DecodeRef, u as DefaultHostExecutor, v as EngineKind, w as EngineSelection, x as EngineSelectionMode, y as FiberEngineKind, z as FlatMapRef, B as FoldFailureRef, G as FoldSuccessRef, H as HostAction, I as HostActionKind, J as HostActionResult, K as HostExecutionContext, L as HostExecutor, M as HostRegistry, P as HttpHostAction, Q as Interrupted, T as Joiner, U as None, V as NoopHooks, X as ProgramBuilder, Y as ProgramPatch, _ as PushStatus, $ as QueueHostAction, a0 as RingBuffer, a1 as RingBufferEngine, a2 as RingBufferStatsData, a3 as Runtime, a4 as RuntimeCapabilities, a5 as RuntimeEngineMode, a6 as RuntimeOptions, a7 as Scheduler, a8 as SchedulerEngine, a9 as SchedulerOptions, aa as SchedulerStats, ab as SchedulerStatsData, ac as ScopeId, ad as Some, ae as SyncRef, af as Task, ag as WasmFiberEngine, ah as WasmFiberEngineOptions, Z as ZIO, ai as acquireRelease, aj as async, ak as asyncCatchAll, al as asyncFail, am as asyncFlatMap, an as asyncFold, ao as asyncInterruptible, ap as asyncMap, aq as asyncMapError, ar as asyncSucceed, as as asyncSync, at as asyncTotal, au as catchAll, av as end, aw as engineStats, ax as fail, ay as flatMap, az as fork, aA as fromPromiseAbortable, aB as getBenchmarkBudget, aC as getCurrentFiber, aD as globalScheduler, aE as linkAbortController, aF as makeBoundedRingBuffer, aG as makeCancelToken, aH as map, aI as mapAsync, aJ as mapError, aK as mapTryAsync, aL as none, aM as orElseOptional, aN as runtimeCapabilities, aO as selectedEngineStats, aP as setBenchmarkBudget, aQ as some, aR as succeed, aS as sync, aT as toPromise, aU as unit, aV as unsafeGetCurrentRuntime, aW as unsafeRunAsync, aX as unsafeRunFoldWithEnv, aY as withAsyncPromise, aZ as withCurrentFiber, a_ as withScope, a$ as withScopeAsync } from './effect-ISvXPLgc.js';
3
- import { Z as ZStream } from './stream-BvukHxCv.js';
4
- export { C as Concat, E as Emit, a as Empty, F as Flatten, b as FromPull, M as Managed, c as Merge, N as Normalize, S as Scoped, d as assertNever, e as collectStream, f as concatStream, g as emitStream, h as emptyStream, i as flattenStream, j as foreachStream, k as fromArray, l as fromPull, m as managedStream, n as mapStream, o as merge, p as mergeStream, r as rangeStream, s as streamFromReadableStream, u as uncons, q as unwrapScoped, w as widenOpt, z as zip } from './stream-BvukHxCv.js';
1
+ import { F as FiberEngine, W as WasmEngineRuntime, A as Async, R as RuntimeFiber, a as FiberEngineStats, b as Fiber, c as FiberId, d as FiberStatus, E as Exit, e as RuntimeEvent, f as WasmBridge, g as OpcodeProgram, h as FiberId$1, i as EngineEvent, j as RefId, N as NodeId, k as OpcodeNode, S as Scope, l as RingBufferOptions, m as EngineStats, O as Option } from './effect-CMOQKX8y.js';
2
+ export { n as AbortablePromiseFinish, o as AbortablePromiseLabelStats, p as AbortablePromiseOptions, q as AbortablePromiseOutcome, r as AbortablePromiseStats, s as AsyncRegisterRef, t as AsyncWithPromise, u as BoundedRingBuffer, C as CancelToken, v as Canceler, w as Cause, x as CustomHostAction, D as DbHostAction, y as DecodeRef, z as DefaultHostExecutor, B as EngineKind, G as EngineSelection, H as EngineSelectionMode, I as FiberEngineKind, J as FlatMapRef, K as FoldFailureRef, L as FoldSuccessRef, M as HostAction, P as HostActionKind, Q as HostActionResult, T as HostExecutionContext, U as HostExecutor, V as HostRegistry, X as HostRegistryStats, Y as HttpHostAction, _ as Interrupted, $ as Joiner, a0 as LaneStatsData, a1 as None, a2 as NoopHooks, a3 as ProgramBuilder, a4 as ProgramPatch, a5 as PushStatus, a6 as QueueHostAction, a7 as RingBuffer, a8 as RingBufferEngine, a9 as RingBufferStatsData, aa as Runtime, 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-CMOQKX8y.js';
3
+ export { Counter, Gauge, Histogram, HistogramBuckets, Layer, ManagedResource, MetricSnapshot, MetricType, MetricValue, MetricsRegistry, Ref, RetryPolicy, RetryState, Schedule, ScheduleDecision, Semaphore, SemaphoreStats, ShutdownConfig, ShutdownStats, TaggedError, TestRuntimeOptions, TimeoutError, WorkerPool, WorkerPoolConfig, WorkerPoolError, WorkerPoolStats, andThenSchedule, assertCompletesWithin, assertFails, assertFailsWith, assertSucceeds, bracket, catchTag, catchTags, composeLayer, delayedEffect, derivedRef, elapsed, ensuring, exponential, fixed, flakyEffect, gracefulShutdown, intersect, jittered, layer, layerFail, layerFrom, layerSucceed, makeMetrics, makeRef, makeSemaphore, makeTestRuntime, makeWorkerPool, managed, managedAll, mapErrorTyped, mapLayer, mergeLayer, neverEffect, orElse, provideLayer, recurs, registerShutdownHooks, repeatWithSchedule, retry, retryN, retryWithBackoff, retryWithSchedule, sleep, tagError, takeSchedule, timeout, union, useManaged, whileInput } from './core/index.js';
4
+ export { C as CircuitBreaker, a as CircuitBreakerConfig, b as CircuitBreakerError, c as CircuitBreakerState, d as CircuitBreakerStats, S as Span, e as SpanContext, f as SpanEvent, g as SpanStatus, T as Tracer, h as TracerConfig, m as makeCircuitBreaker, i as makeTracer } from './tracing-DNT9jEbr.js';
5
+ import { Z as ZStream } from './stream-FQm9h4Mg.js';
6
+ export { C as Concat, E as Emit, a as Empty, F as Flatten, b as FromArray, c as FromPull, M as Managed, d as Merge, N as Normalize, R as ReadableStreamOptions, S as Scoped, e as assertNever, f as collectStream, g as concatStream, h as emitStream, i as emptyStream, j as flattenStream, k as foreachStream, l as fromArray, m as fromPull, n as managedStream, o as mapStream, p as merge, q as mergeStream, r as rangeStream, s as streamFromReadableStream, u as uncons, t as unwrapScoped, w as widenOpt, z as zip } from './stream-FQm9h4Mg.js';
5
7
 
6
8
  declare class JsFiberEngine<R> implements FiberEngine<R> {
7
9
  private readonly runtime;
8
- readonly kind: "js";
10
+ readonly kind: "ts";
9
11
  private startedFibers;
10
12
  constructor(runtime: WasmEngineRuntime<R> & any);
11
13
  fork<E, A>(effect: Async<R, E, A>, scopeId?: number): RuntimeFiber<R, E, A>;
@@ -18,26 +20,31 @@ declare class EngineFiberHandle<R, E, A> implements Fiber<E, A> {
18
20
  private readonly onInterrupt;
19
21
  private readonly onJoiner?;
20
22
  private readonly onQueued?;
23
+ private readonly onScheduleDropped?;
24
+ private readonly onScheduleRequest?;
21
25
  readonly id: FiberId;
22
26
  readonly runtime: WasmEngineRuntime<R> & any;
23
27
  fiberContext: any;
24
28
  name?: string;
25
29
  scopeId?: number;
26
30
  parentFiberId?: number;
31
+ lane?: string;
27
32
  private result;
28
33
  private readonly joiners;
29
34
  private readonly finalizers;
30
35
  private finalizersDrained;
31
36
  private internalStatus;
32
37
  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);
38
+ 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
39
  status(): FiberStatus;
35
40
  engineStatus(): InternalFiberStatus;
36
41
  setEngineStatus(status: InternalFiberStatus): void;
42
+ markDequeued(): void;
37
43
  join(cb: (exit: Exit<E, A>) => void): void;
38
44
  interrupt(): void;
39
45
  addFinalizer(f: (exit: Exit<E, A>) => void): void;
40
46
  schedule(tag?: string): void;
47
+ private scheduleWithRuntime;
41
48
  emit(ev: RuntimeEvent): void;
42
49
  succeed(value: A): void;
43
50
  fail(error: E): void;
@@ -47,43 +54,46 @@ declare class EngineFiberHandle<R, E, A> implements Fiber<E, A> {
47
54
  private runFinalizersOnce;
48
55
  }
49
56
 
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
57
  declare class WasmPackFiberBridge implements WasmBridge {
76
58
  readonly kind: "wasm";
59
+ readonly supportsBinary: boolean;
60
+ readonly supportsZeroCopy: boolean;
61
+ readonly supportsNoJsonMetrics: boolean;
77
62
  private readonly vm;
63
+ private jsonEventCalls;
64
+ private binaryEventCalls;
65
+ private zeroCopyEventCalls;
66
+ private eventsReceived;
67
+ private maxEventsPerCall;
68
+ private jsonPrograms;
69
+ private binaryPrograms;
70
+ private zeroCopyPrograms;
71
+ private jsonPatches;
72
+ private binaryPatches;
73
+ private zeroCopyPatches;
78
74
  constructor(modulePath?: string);
79
75
  createFiber(program: OpcodeProgram): FiberId$1;
80
76
  poll(fiberId: FiberId$1): EngineEvent;
77
+ driveBatch(fiberId: FiberId$1, budget: number): readonly EngineEvent[];
81
78
  provideValue(fiberId: FiberId$1, valueRef: RefId): EngineEvent;
79
+ provideValueBatch(fiberId: FiberId$1, valueRef: RefId, budget: number): readonly EngineEvent[];
82
80
  provideError(fiberId: FiberId$1, errorRef: RefId): EngineEvent;
81
+ provideErrorBatch(fiberId: FiberId$1, errorRef: RefId, budget: number): readonly EngineEvent[];
83
82
  provideEffect(fiberId: FiberId$1, root: NodeId, nodes: OpcodeNode[]): EngineEvent;
83
+ provideEffectBatch(fiberId: FiberId$1, root: NodeId, nodes: OpcodeNode[], budget: number): readonly EngineEvent[];
84
84
  interrupt(fiberId: FiberId$1, reasonRef: RefId): EngineEvent;
85
+ interruptBatch(fiberId: FiberId$1, reasonRef: RefId, budget: number): readonly EngineEvent[];
85
86
  dropFiber(fiberId: FiberId$1): void;
86
87
  stats(): unknown;
88
+ private assertStrictWasmHotPath;
89
+ private decodeZeroCopy;
90
+ private decodeBinary;
91
+ private decodeJson;
92
+ private memory;
93
+ private readU32;
94
+ private readF64;
95
+ private writeWords;
96
+ private readMetricsSnapshot;
87
97
  }
88
98
 
89
99
  type WasmFiberRegistryStats = {
@@ -120,6 +130,63 @@ declare class WasmFiberRegistryBridge {
120
130
  stats(): WasmFiberRegistryStats;
121
131
  }
122
132
 
133
+ type ReadyQueueScheduleKind = "micro" | "macro" | "none" | "dropped";
134
+ type FiberReadyQueueStats = {
135
+ readonly engine: "ts" | "wasm";
136
+ readonly fallbackUsed: boolean;
137
+ readonly data: unknown;
138
+ };
139
+ interface FiberReadyQueue {
140
+ readonly engine: "ts" | "wasm";
141
+ enqueue(fiberId: FiberId$1, tag: string): ReadyQueueScheduleKind;
142
+ beginFlush(): number;
143
+ shift(): FiberId$1 | undefined;
144
+ endFlush(ran: number): ReadyQueueScheduleKind;
145
+ len(): number;
146
+ clear(): void;
147
+ stats(): FiberReadyQueueStats;
148
+ }
149
+ type FiberReadyQueueOptions = {
150
+ readonly engine?: "ts" | "wasm";
151
+ readonly flushBudget?: number;
152
+ readonly microThreshold?: number;
153
+ readonly laneCapacity?: number;
154
+ readonly laneBudget?: number;
155
+ readonly maxLanes?: number;
156
+ };
157
+ declare function makeFiberReadyQueue(options?: FiberReadyQueueOptions): FiberReadyQueue;
158
+
159
+ declare const ABI_VERSION = 1;
160
+ declare const EVENT_WORDS = 5;
161
+ declare const NONE_U32 = 4294967295;
162
+ declare const enum OpcodeTagCode {
163
+ Succeed = 0,
164
+ Fail = 1,
165
+ Sync = 2,
166
+ Async = 3,
167
+ FlatMap = 4,
168
+ Fold = 5,
169
+ Fork = 6,
170
+ HostAction = 7
171
+ }
172
+ declare const enum EventKindCode {
173
+ Continue = 0,
174
+ Done = 1,
175
+ Failed = 2,
176
+ Interrupted = 3,
177
+ InvokeSync = 4,
178
+ InvokeAsync = 5,
179
+ InvokeFlatMap = 6,
180
+ InvokeFoldFailure = 7,
181
+ InvokeFoldSuccess = 8,
182
+ InvokeFork = 9,
183
+ InvokeHostAction = 10
184
+ }
185
+ declare function encodeOpcodeProgram(program: OpcodeProgram): Uint32Array;
186
+ declare function encodeOpcodeNodes(nodes: readonly OpcodeNode[]): Uint32Array;
187
+ declare function decodeEvent(words: ArrayLike<number>, offset?: number): EngineEvent;
188
+ declare function decodeEventBatch(words: ArrayLike<number> | null | undefined): EngineEvent[];
189
+
123
190
  declare function buffer<R, E, A>(stream: ZStream<{} & R, E, A>, capacity: number, strategy?: "backpressure" | "dropping" | "sliding"): ZStream<{} & R, E, A>;
124
191
 
125
192
  /**
@@ -152,6 +219,10 @@ type QueueClosed = {
152
219
  type Queue<A> = {
153
220
  offer: (a: A) => Async<unknown, never, boolean>;
154
221
  take: () => Async<unknown, QueueClosed, A>;
222
+ /** Offer multiple values in a single effect. Returns array of success flags. */
223
+ offerBatch: (values: readonly A[]) => Async<unknown, never, boolean[]>;
224
+ /** Take up to N values in a single effect. Returns available values (may be fewer than N). */
225
+ takeBatch: (n: number) => Async<unknown, QueueClosed, A[]>;
155
226
  size: () => number;
156
227
  shutdown: () => void;
157
228
  };
@@ -176,12 +247,13 @@ declare const broadcast: typeof makeHub;
176
247
  declare function broadcastToHub<R, E, A>(stream: ZStream<R, E, A>, hub: Hub<A>): Async<R, E, void>;
177
248
  declare function fromHub<A>(hub: Hub<A>): ZStream<unknown, HubClosed, A>;
178
249
 
179
- type StreamChunkEngine = "auto" | "js" | "wasm";
250
+ type StreamChunkEngine = "ts" | "wasm";
180
251
  type StreamChunkOptions = {
181
252
  /**
182
- * auto: use WASM when wasm/pkg is available, otherwise JS.
183
- * js: always use the JS array chunker.
253
+ * ts: always use the TypeScript array chunker.
184
254
  * wasm: require BrassWasmChunkBuffer from wasm/pkg.
255
+ *
256
+ * Strict mode never falls back between engines.
185
257
  */
186
258
  engine?: StreamChunkEngine;
187
259
  };
@@ -219,7 +291,12 @@ declare function mapChunksEffect<Rp, Ep, A, B>(chunkSize: number, f: (chunk: rea
219
291
  * When applied to a stream `ZStream<R, E, In>`, the result is `ZStream<R & Rp, E | Ep, Out>`.
220
292
  */
221
293
  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)`). */
294
+ /** Apply a pipeline to a stream (alias of `pipeline(stream)`).
295
+ *
296
+ * OPTIMIZATION: When the pipeline is a single pure operator (has PURE_PIPELINE_TAG)
297
+ * and the stream can be drained synchronously, uses the fast fused path.
298
+ * The FusedPipelineRepr is cached on the pipeline to avoid recalculation.
299
+ */
223
300
  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
301
  /** Compose pipelines left-to-right (p1 >>> p2). */
225
302
  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 +332,204 @@ declare function bufferP<A>(capacity: number, strategy?: "backpressure" | "dropp
255
332
  */
256
333
  declare function groupedP<A>(n: number): ZPipeline<unknown, never, A, A[]>;
257
334
 
258
- export { Async, EngineEvent, EngineFiberHandle, EngineStats, Exit, Fiber, FiberEngine, FiberEngineStats, FiberId, FiberStatus, type Hub, type HubClosed, type HubStrategy, type InternalFiberStatus, JsFiberEngine, NodeId, OpcodeNode, OpcodeProgram, Option, type Queue, type QueueClosed, type QueueOptions, RefId, ReferenceWasmBridge, RingBufferOptions, RuntimeFiber, Scope, type Strategy, type StreamChunkEngine, type StreamChunkOptions, type StreamChunkStats, type Subscription, WasmBridge, WasmEngineRuntime, WasmFiberRegistryBridge, type WasmFiberRegistryStats, WasmPackFiberBridge, type ZPipeline, ZStream, andThen, bounded, broadcast, broadcastToHub, buffer, bufferP, chunks, chunksP, collectAllPar, compose, dropP, filterMapP, filterP, fromHub, groupedP, identity, makeHub, makeStreamChunker, mapChunks, mapChunksEffect, mapChunksEffectP, mapEffectP, mapP, race, raceWith, takeP, tapEffectP, via, zipPar };
335
+ /** Serialized representation of a single step in a fused pipeline */
336
+ type SerializedStep = {
337
+ kind: "map";
338
+ fnSource: string;
339
+ } | {
340
+ kind: "filter";
341
+ predSource: string;
342
+ } | {
343
+ kind: "take";
344
+ n: number;
345
+ } | {
346
+ kind: "drop";
347
+ n: number;
348
+ };
349
+ /** JSON-safe serialized representation of a fused pipeline */
350
+ type SerializedFusedPipeline = {
351
+ readonly version: 1;
352
+ readonly steps: SerializedStep[];
353
+ };
354
+ /** Enable or disable fusion globally. When disabled, andThen will not attempt fusion. */
355
+ declare function setFusionEnabled(enabled: boolean): void;
356
+ /** Check if fusion is globally enabled. */
357
+ declare function isFusionEnabled(): boolean;
358
+ /** Set verbose mode globally. When enabled, fusion decisions are logged to console. */
359
+ declare function setFusionVerbose(verbose: boolean): void;
360
+ /** Check if verbose mode is globally enabled. */
361
+ declare function isFusionVerbose(): boolean;
362
+ /**
363
+ * Get stats from a fused pipeline, or null if the pipeline is not fused.
364
+ * Works with pipelines that have been fused via `andThen` (have `_fusedSteps`)
365
+ * or with `FusedPipelineRepr` objects directly.
366
+ */
367
+ declare function getStats<In, Out>(pipeline: ZPipeline<unknown, never, In, Out>): FusedPipelineStats | null;
368
+ declare const PURE_PIPELINE_TAG: unique symbol;
369
+ /** Result of a fused step for an element */
370
+ type FuseResult<A> = {
371
+ readonly tag: "emit";
372
+ readonly value: A;
373
+ } | {
374
+ readonly tag: "skip";
375
+ } | {
376
+ readonly tag: "halt";
377
+ };
378
+ /** Metadata of a step in the original pipeline */
379
+ type FusedStep = {
380
+ readonly kind: "map";
381
+ } | {
382
+ readonly kind: "filter";
383
+ } | {
384
+ readonly kind: "take";
385
+ readonly n: number;
386
+ } | {
387
+ readonly kind: "drop";
388
+ readonly n: number;
389
+ };
390
+ /** Stats of a fused pipeline */
391
+ type FusedPipelineStats = {
392
+ readonly fusedSteps: number;
393
+ readonly steps: readonly FusedStep[];
394
+ readonly hasTake: boolean;
395
+ readonly hasDrop: boolean;
396
+ };
397
+ /** Internal representation of a fused pipeline */
398
+ type FusedPipelineRepr<In, Out> = {
399
+ readonly _tag: "FusedPipeline";
400
+ readonly step: (a: In, state: FuseState) => FuseResult<Out>;
401
+ readonly initState: () => FuseState;
402
+ readonly stats: FusedPipelineStats;
403
+ };
404
+ /** Mutable state during execution (per-step counters for take/drop) */
405
+ type FuseState = {
406
+ /** Per-step counters: each take/drop step gets its own independent counter */
407
+ counters: number[];
408
+ };
409
+ /** Fusion options */
410
+ type FusionOptions = {
411
+ readonly enabled?: boolean;
412
+ readonly verbose?: boolean;
413
+ };
414
+ type PurePipelineMetadata<In, Out> = {
415
+ readonly kind: "map" | "filter" | "take" | "drop";
416
+ readonly fn?: (a: In) => Out;
417
+ readonly pred?: (a: In) => boolean;
418
+ readonly n?: number;
419
+ };
420
+ type PurePipelineTag<In, Out> = {
421
+ readonly [PURE_PIPELINE_TAG]: PurePipelineMetadata<In, Out>;
422
+ };
423
+ /** Creates a FuseState with per-step counters (one for each take/drop step) */
424
+ declare function initState(counterCount: number): () => FuseState;
425
+ /**
426
+ * Detects if a pipeline is fusable and returns the fused representation.
427
+ * Returns null if the pipeline is not fusable (not pure or fusion disabled).
428
+ */
429
+ declare function fuse<In, Out>(pipeline: ZPipeline<unknown, never, In, Out>, options?: FusionOptions): FusedPipelineRepr<In, Out> | null;
430
+ /**
431
+ * Applies a fused pipeline to an array of inputs synchronously.
432
+ * This is the fastest execution path — a pure `for` loop with no effects,
433
+ * no fibers, no scheduling overhead. O(n) with minimal constant factor.
434
+ */
435
+ declare function runFusedArray<In, Out>(input: readonly In[], fused: FusedPipelineRepr<In, Out>): Out[];
436
+ /**
437
+ * Applies a fused pipeline to a stream using a single pull loop.
438
+ * No intermediate fibers are created between fused operators.
439
+ *
440
+ * OPTIMIZATION: If the input stream can be drained synchronously (e.g., fromArray),
441
+ * the entire pipeline is executed as a pure synchronous loop — no effects at all.
442
+ */
443
+ declare function applyFused<R, E, In, Out>(stream: ZStream<R, E, In>, fused: FusedPipelineRepr<In, Out>): ZStream<R, E, Out>;
444
+ /**
445
+ * Serialize a fused pipeline to a JSON-safe representation.
446
+ * Returns null if the pipeline is not fused (no _fusedSteps metadata).
447
+ *
448
+ * For map/filter steps, the function/predicate source is captured via `.toString()`.
449
+ * Note: toString() has limitations with closures and minification, but is sufficient
450
+ * for debugging/observability use cases.
451
+ */
452
+ declare function serializeFusedPipeline<In, Out>(pipeline: ZPipeline<unknown, never, In, Out>): SerializedFusedPipeline | null;
453
+ /**
454
+ * Deserialize a serialized pipeline back to a functional pipeline.
455
+ * Returns null if deserialization fails (e.g., invalid version, malformed fnSource).
456
+ *
457
+ * Reconstructs functions using `new Function(...)` with appropriate wrapping.
458
+ * The resulting pipeline is functionally equivalent to the original for pure
459
+ * (non-closure) functions.
460
+ *
461
+ * WARNING: Uses `new Function()` which has security implications similar to `eval`.
462
+ * Only deserialize trusted serialized pipelines.
463
+ */
464
+ declare function deserializeFusedPipeline<In, Out>(serialized: SerializedFusedPipeline): ZPipeline<unknown, never, In, Out> | null;
465
+
466
+ /**
467
+ * Throttles a stream to emit at most one element per `intervalMs`.
468
+ * Elements arriving during the cooldown period are dropped.
469
+ *
470
+ * ```ts
471
+ * const throttled = throttle(clickStream, 1000); // max 1 click per second
472
+ * ```
473
+ */
474
+ declare function throttle<R, E, A>(stream: ZStream<R, E, A>, intervalMs: number): ZStream<R, E, A>;
475
+ /**
476
+ * Debounces a stream: only emits an element after `delayMs` of silence.
477
+ * If a new element arrives before the delay expires, the previous is dropped.
478
+ *
479
+ * Note: This is a simplified debounce that works by buffering the last element
480
+ * and emitting it after a delay. For real-time use cases, consider using
481
+ * the Hub-based approach with timers.
482
+ *
483
+ * ```ts
484
+ * const debounced = debounce(inputStream, 300); // wait 300ms of silence
485
+ * ```
486
+ */
487
+ declare function debounce<R, E, A>(stream: ZStream<R, E, A>, delayMs: number): ZStream<R, E, A>;
488
+ /**
489
+ * Zips two streams together, pairing elements by position.
490
+ * The resulting stream ends when either input stream ends.
491
+ *
492
+ * ```ts
493
+ * const zipped = zip(numbersStream, lettersStream);
494
+ * // [1, "a"], [2, "b"], [3, "c"], ...
495
+ * ```
496
+ */
497
+ declare function zip<R, E, A, B>(left: ZStream<R, E, A>, right: ZStream<R, E, B>): ZStream<R, E, [A, B]>;
498
+ /**
499
+ * Zips two streams with a custom combiner function.
500
+ *
501
+ * ```ts
502
+ * const summed = zipWith(xs, ys, (x, y) => x + y);
503
+ * ```
504
+ */
505
+ 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>;
506
+ /**
507
+ * Produces a stream of accumulated values using a reducer function.
508
+ * Emits the initial value first, then each accumulated result.
509
+ *
510
+ * ```ts
511
+ * const running = scan(numbersStream, 0, (acc, n) => acc + n);
512
+ * // 0, 1, 3, 6, 10, ... (running sum)
513
+ * ```
514
+ */
515
+ declare function scan<R, E, A, B>(stream: ZStream<R, E, A>, initial: B, f: (acc: B, a: A) => B): ZStream<R, E, B>;
516
+ /**
517
+ * Interleaves two streams, alternating elements from each.
518
+ * When one stream ends, remaining elements from the other are emitted.
519
+ *
520
+ * ```ts
521
+ * const mixed = interleave(evens, odds);
522
+ * // 0, 1, 2, 3, 4, 5, ...
523
+ * ```
524
+ */
525
+ declare function interleave<R, E, A>(left: ZStream<R, E, A>, right: ZStream<R, E, A>): ZStream<R, E, A>;
526
+ /**
527
+ * Takes the first N elements from a stream.
528
+ */
529
+ declare function take<R, E, A>(stream: ZStream<R, E, A>, n: number): ZStream<R, E, A>;
530
+ /**
531
+ * Drops the first N elements from a stream.
532
+ */
533
+ declare function drop<R, E, A>(stream: ZStream<R, E, A>, n: number): ZStream<R, E, A>;
534
+
535
+ export { ABI_VERSION, Async, 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 Hub, type HubClosed, type HubStrategy, type InternalFiberStatus, JsFiberEngine, NONE_U32, NodeId, OpcodeNode, OpcodeProgram, OpcodeTagCode, Option, PURE_PIPELINE_TAG, type PurePipelineMetadata, type PurePipelineTag, type Queue, type QueueClosed, type QueueOptions, type ReadyQueueScheduleKind, RefId, RingBufferOptions, RuntimeFiber, Scope, type SerializedFusedPipeline, type SerializedStep, type Strategy, type StreamChunkEngine, type StreamChunkOptions, type StreamChunkStats, type Subscription, WasmBridge, WasmEngineRuntime, WasmFiberRegistryBridge, type WasmFiberRegistryStats, WasmPackFiberBridge, type ZPipeline, ZStream, andThen, applyFused, bounded, broadcast, broadcastToHub, buffer, bufferP, chunks, chunksP, collectAllPar, compose, debounce, decodeEvent, decodeEventBatch, deserializeFusedPipeline, dropP, drop as dropStream, encodeOpcodeNodes, encodeOpcodeProgram, filterMapP, filterP, fromHub, fuse, getStats, groupedP, identity, initState, interleave, isFusionEnabled, isFusionVerbose, makeFiberReadyQueue, makeHub, makeStreamChunker, mapChunks, mapChunksEffect, mapChunksEffectP, mapEffectP, mapP, race, raceWith, runFusedArray, scan, serializeFusedPipeline, setFusionEnabled, setFusionVerbose, takeP, take as takeStream, tapEffectP, throttle, via, zipPar, zip as zipStream, zipWith };