brass-runtime 1.12.1 → 1.13.3

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/index.d.ts CHANGED
@@ -1,46 +1,123 @@
1
- import { A as Async, S as Scope, E as Exit, F as Fiber, O as Option } from './effect-NSaHksNl.js';
2
- export { a as AsyncWithPromise, C as CancelToken, b as Canceler, c as Cause, d as FiberId, e as FiberStatus, I as Interrupted, N as None, R as Runtime, f as RuntimeFiber, g as Scheduler, h as ScopeId, i as Some, T as Task, Z as ZIO, j as acquireRelease, k as async, l as asyncCatchAll, m as asyncFail, n as asyncFlatMap, o as asyncFold, p as asyncInterruptible, q as asyncMap, r as asyncMapError, s as asyncSucceed, t as asyncSync, u as asyncTotal, v as catchAll, w as end, x as fail, y as flatMap, z as fork, B as fromPromiseAbortable, D as getCurrentFiber, G as globalScheduler, H as linkAbortController, J as makeCancelToken, K as map, L as mapAsync, M as mapError, P as mapTryAsync, Q as none, U as orElseOptional, V as some, W as succeed, X as sync, Y as toPromise, _ as unit, $ as unsafeGetCurrentRuntime, a0 as unsafeRunAsync, a1 as unsafeRunFoldWithEnv, a2 as withAsyncPromise, a3 as withCurrentFiber, a4 as withScope, a5 as withScopeAsync } from './effect-NSaHksNl.js';
3
- import { Z as ZStream } from './stream-DNTGNv-G.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-DNTGNv-G.js';
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';
5
5
 
6
- type Node<T> = {
7
- value: T;
8
- next: Node<T> | null;
9
- prev: Node<T> | null;
10
- removed: boolean;
11
- };
12
- declare class LinkedQueue<T> {
13
- private head;
14
- private tail;
15
- private len;
16
- get length(): number;
17
- isEmpty(): boolean;
18
- push(value: T): Node<T>;
19
- shift(): T | undefined;
20
- remove(node: Node<T>): void;
21
- private unlink;
6
+ declare class JsFiberEngine<R> implements FiberEngine<R> {
7
+ private readonly runtime;
8
+ readonly kind: "js";
9
+ private startedFibers;
10
+ constructor(runtime: WasmEngineRuntime<R> & any);
11
+ fork<E, A>(effect: Async<R, E, A>, scopeId?: number): RuntimeFiber<R, E, A>;
12
+ stats(): FiberEngineStats;
22
13
  }
23
14
 
24
- declare const enum PushStatus {
25
- Ok = 0,
26
- Grew = 1,
27
- Dropped = 2
15
+ type InternalFiberStatus = "queued" | "running" | "suspended" | "done" | "failed" | "interrupted";
16
+ declare class EngineFiberHandle<R, E, A> implements Fiber<E, A> {
17
+ private readonly onScheduledStep;
18
+ private readonly onInterrupt;
19
+ private readonly onJoiner?;
20
+ private readonly onQueued?;
21
+ readonly id: FiberId;
22
+ readonly runtime: WasmEngineRuntime<R> & any;
23
+ fiberContext: any;
24
+ name?: string;
25
+ scopeId?: number;
26
+ parentFiberId?: number;
27
+ private result;
28
+ private readonly joiners;
29
+ private readonly finalizers;
30
+ private finalizersDrained;
31
+ private internalStatus;
32
+ 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);
34
+ status(): FiberStatus;
35
+ engineStatus(): InternalFiberStatus;
36
+ setEngineStatus(status: InternalFiberStatus): void;
37
+ join(cb: (exit: Exit<E, A>) => void): void;
38
+ interrupt(): void;
39
+ addFinalizer(f: (exit: Exit<E, A>) => void): void;
40
+ schedule(tag?: string): void;
41
+ emit(ev: RuntimeEvent): void;
42
+ succeed(value: A): void;
43
+ fail(error: E): void;
44
+ die(defect: unknown): void;
45
+ interrupted(): void;
46
+ complete(exit: Exit<E, A>): void;
47
+ private runFinalizersOnce;
28
48
  }
29
- declare class RingBuffer<T> {
30
- private buf;
31
- private head;
32
- private tail;
33
- private size_;
34
- private readonly maxCap;
35
- constructor(initialCapacity?: number, maxCapacity?: number);
36
- get length(): number;
37
- get capacity(): number;
38
- isEmpty(): boolean;
39
- push(value: T): PushStatus;
40
- shift(): T | undefined;
41
- clear(): void;
42
- private grow;
43
- private nextPow2;
49
+
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
+ declare class WasmPackFiberBridge implements WasmBridge {
76
+ readonly kind: "wasm";
77
+ private readonly vm;
78
+ constructor(modulePath?: string);
79
+ createFiber(program: OpcodeProgram): FiberId$1;
80
+ poll(fiberId: FiberId$1): EngineEvent;
81
+ provideValue(fiberId: FiberId$1, valueRef: RefId): EngineEvent;
82
+ provideError(fiberId: FiberId$1, errorRef: RefId): EngineEvent;
83
+ provideEffect(fiberId: FiberId$1, root: NodeId, nodes: OpcodeNode[]): EngineEvent;
84
+ interrupt(fiberId: FiberId$1, reasonRef: RefId): EngineEvent;
85
+ dropFiber(fiberId: FiberId$1): void;
86
+ stats(): unknown;
87
+ }
88
+
89
+ type WasmFiberRegistryStats = {
90
+ readonly live: number;
91
+ readonly queued: number;
92
+ readonly running: number;
93
+ readonly suspended: number;
94
+ readonly done: number;
95
+ readonly failed: number;
96
+ readonly interrupted: number;
97
+ readonly wakeQueueLen: number;
98
+ readonly registered: number;
99
+ readonly completed: number;
100
+ readonly wakeups: number;
101
+ readonly duplicateWakeups: number;
102
+ readonly joins: number;
103
+ };
104
+ type FiberRegistryStatus = "queued" | "running" | "suspended" | "done" | "failed" | "interrupted";
105
+ declare class WasmFiberRegistryBridge {
106
+ private readonly registry;
107
+ constructor();
108
+ registerFiber(fiberId: FiberId$1, parentId?: number, scopeId?: number): void;
109
+ markQueued(fiberId: FiberId$1): void;
110
+ markRunning(fiberId: FiberId$1): void;
111
+ markSuspended(fiberId: FiberId$1): void;
112
+ markDone(fiberId: FiberId$1, status: Exclude<FiberRegistryStatus, "queued" | "running" | "suspended">): number;
113
+ dropFiber(fiberId: FiberId$1): void;
114
+ addJoiner(fiberId: FiberId$1): void;
115
+ wake(fiberId: FiberId$1): boolean;
116
+ drainWakeup(): FiberId$1 | undefined;
117
+ drainWakeups(): FiberId$1[];
118
+ wakeQueueLength(): number;
119
+ stateOf(fiberId: FiberId$1): FiberRegistryStatus | "missing";
120
+ stats(): WasmFiberRegistryStats;
44
121
  }
45
122
 
46
123
  declare function buffer<R, E, A>(stream: ZStream<{} & R, E, A>, capacity: number, strategy?: "backpressure" | "dropping" | "sliding"): ZStream<{} & R, E, A>;
@@ -78,7 +155,8 @@ type Queue<A> = {
78
155
  size: () => number;
79
156
  shutdown: () => void;
80
157
  };
81
- declare function bounded<A>(capacity: number, strategy?: Strategy): Async<unknown, unknown, Queue<A>>;
158
+ type QueueOptions = RingBufferOptions;
159
+ declare function bounded<A>(capacity: number, strategy?: Strategy, options?: QueueOptions): Async<unknown, unknown, Queue<A>>;
82
160
 
83
161
  type HubStrategy = "BackPressure" | "Dropping" | "Sliding";
84
162
  type HubClosed = {
@@ -98,6 +176,42 @@ declare const broadcast: typeof makeHub;
98
176
  declare function broadcastToHub<R, E, A>(stream: ZStream<R, E, A>, hub: Hub<A>): Async<R, E, void>;
99
177
  declare function fromHub<A>(hub: Hub<A>): ZStream<unknown, HubClosed, A>;
100
178
 
179
+ type StreamChunkEngine = "auto" | "js" | "wasm";
180
+ type StreamChunkOptions = {
181
+ /**
182
+ * auto: use WASM when wasm/pkg is available, otherwise JS.
183
+ * js: always use the JS array chunker.
184
+ * wasm: require BrassWasmChunkBuffer from wasm/pkg.
185
+ */
186
+ engine?: StreamChunkEngine;
187
+ };
188
+ type StreamChunkStats = {
189
+ len: number;
190
+ maxChunkSize: number;
191
+ emittedChunks: number;
192
+ emittedItems: number;
193
+ flushes: number;
194
+ };
195
+ type Chunker<A> = {
196
+ readonly length: number;
197
+ readonly maxChunkSize: number;
198
+ push(value: A): boolean;
199
+ isFull(): boolean;
200
+ isEmpty(): boolean;
201
+ takeChunk(): readonly A[];
202
+ clear(): void;
203
+ stats(): EngineStats<StreamChunkStats>;
204
+ };
205
+ declare function makeStreamChunker<A>(chunkSize: number, options?: StreamChunkOptions): Chunker<A>;
206
+ /**
207
+ * Re-chunk a stream so downstream operators receive arrays instead of single
208
+ * items. This is the intended WASM boundary: pay the JS↔WASM crossing while
209
+ * assembling chunks, then process bigger batches downstream.
210
+ */
211
+ declare function chunks<R, E, A>(input: ZStream<R, E, A>, chunkSize: number, options?: StreamChunkOptions): ZStream<R, E, readonly A[]>;
212
+ declare function mapChunks<R, E, A, B>(input: ZStream<R, E, A>, chunkSize: number, f: (chunk: readonly A[]) => readonly B[], options?: StreamChunkOptions): ZStream<R, E, B>;
213
+ declare function mapChunksEffect<Rp, Ep, A, B>(chunkSize: number, f: (chunk: readonly A[]) => Async<Rp, Ep, readonly B[]>, options?: StreamChunkOptions): <R, E>(input: ZStream<R, E, A>) => ZStream<R & Rp, E | Ep, B>;
214
+
101
215
  /**
102
216
  * ZPipeline-style transformer.
103
217
  *
@@ -129,6 +243,10 @@ declare function dropP<A>(n: number): ZPipeline<unknown, never, A, A>;
129
243
  declare function mapEffectP<Rp, Ep, A, B>(f: (a: A) => Async<Rp, Ep, B>): ZPipeline<Rp, Ep, A, B>;
130
244
  /** Tap each element with an effect, preserving the element. */
131
245
  declare function tapEffectP<Rp, Ep, A>(f: (a: A) => Async<Rp, Ep, any>): ZPipeline<Rp, Ep, A, A>;
246
+ /** Re-chunk a stream into arrays of up to `chunkSize` elements. */
247
+ declare function chunksP<A>(chunkSize: number, options?: StreamChunkOptions): ZPipeline<unknown, never, A, readonly A[]>;
248
+ /** Apply one effect per chunk and flatten the returned chunk back to elements. */
249
+ declare function mapChunksEffectP<Rp, Ep, A, B>(chunkSize: number, f: (chunk: readonly A[]) => Async<Rp, Ep, readonly B[]>, options?: StreamChunkOptions): ZPipeline<Rp, Ep, A, B>;
132
250
  /** Buffer upstream using your existing queue-based buffer implementation. */
133
251
  declare function bufferP<A>(capacity: number, strategy?: "backpressure" | "dropping" | "sliding"): ZPipeline<unknown, never, A, A>;
134
252
  /**
@@ -137,4 +255,4 @@ declare function bufferP<A>(capacity: number, strategy?: "backpressure" | "dropp
137
255
  */
138
256
  declare function groupedP<A>(n: number): ZPipeline<unknown, never, A, A[]>;
139
257
 
140
- export { Async, Exit, Fiber, type Hub, type HubClosed, type HubStrategy, LinkedQueue, type Node, Option, PushStatus, type Queue, type QueueClosed, RingBuffer, Scope, type Strategy, type Subscription, type ZPipeline, ZStream, andThen, bounded, broadcast, broadcastToHub, buffer, bufferP, collectAllPar, compose, dropP, filterMapP, filterP, fromHub, groupedP, identity, makeHub, mapEffectP, mapP, race, raceWith, takeP, tapEffectP, via, zipPar };
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 };