brass-runtime 1.12.0 → 1.13.2

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.
@@ -1,430 +0,0 @@
1
- type Canceler = () => void;
2
- type CancelToken = {
3
- /** true si ya fue cancelado */
4
- readonly isCancelled: () => boolean;
5
- /**
6
- * Registra un callback que se ejecuta cuando se cancela.
7
- * Si ya estaba cancelado, lo ejecuta inmediatamente.
8
- * Devuelve un "unsubscribe" para desregistrar.
9
- */
10
- readonly onCancel: (f: Canceler) => Canceler;
11
- };
12
- /** Implementación simple de CancelToken */
13
- declare function makeCancelToken(): CancelToken & {
14
- cancel: Canceler;
15
- };
16
- /**
17
- * Helper: conecta un AbortController a un CancelToken.
18
- * Devuelve una función para desenganchar (unsubscribe).
19
- */
20
- declare function linkAbortController(token: CancelToken, ac: AbortController): Canceler;
21
-
22
- type Task = () => void;
23
- declare class Scheduler {
24
- private queue;
25
- private flushing;
26
- private scheduled;
27
- schedule(task: Task, tag?: string): void;
28
- private requestFlush;
29
- private flush;
30
- }
31
- declare const globalScheduler: Scheduler;
32
-
33
- type RuntimeEvent = {
34
- type: "fiber.start";
35
- fiberId: number;
36
- parentFiberId?: number;
37
- scopeId?: number;
38
- name?: string;
39
- } | {
40
- type: "fiber.end";
41
- fiberId: number;
42
- status: "success" | "failure" | "interrupted";
43
- error?: unknown;
44
- } | {
45
- type: "fiber.suspend";
46
- fiberId: number;
47
- reason?: string;
48
- } | {
49
- type: "fiber.resume";
50
- fiberId: number;
51
- } | {
52
- type: "scope.open";
53
- scopeId: number;
54
- parentScopeId?: number;
55
- } | {
56
- type: "scope.close";
57
- scopeId: number;
58
- status: "success" | "failure" | "interrupted";
59
- error?: unknown;
60
- } | {
61
- type: "log";
62
- level: "debug" | "info" | "warn" | "error";
63
- message: string;
64
- fields?: Record<string, unknown>;
65
- };
66
- type RuntimeEmitContext = {
67
- fiberId?: number;
68
- scopeId?: number;
69
- traceId?: string;
70
- spanId?: string;
71
- };
72
- interface RuntimeHooks {
73
- emit(ev: RuntimeEvent, ctx: RuntimeEmitContext): void;
74
- }
75
- type RuntimeEventRecord = RuntimeEvent & RuntimeEmitContext & {
76
- seq: number;
77
- wallTs: number;
78
- ts: number;
79
- };
80
-
81
- type FiberRunState = "Queued" | "Running" | "Suspended" | "Done";
82
- type FiberInfo = {
83
- fiberId: number;
84
- parentFiberId?: number;
85
- name?: string;
86
- runState: FiberRunState;
87
- status: "Running" | "Done" | "Interrupted";
88
- createdAt: number;
89
- lastActiveAt: number;
90
- scopeId?: number;
91
- traceId?: string;
92
- spanId?: string;
93
- awaiting?: {
94
- reason: string;
95
- detail?: string;
96
- };
97
- lastEnd?: {
98
- status: string;
99
- error?: string;
100
- };
101
- };
102
- type ScopeInfo = {
103
- scopeId: number;
104
- parentScopeId?: number;
105
- ownerFiberId?: number;
106
- openAt: number;
107
- closedAt?: number;
108
- finalizers: Array<{
109
- id: number;
110
- label?: string;
111
- status: "added" | "running" | "done";
112
- }>;
113
- };
114
- declare class RuntimeRegistry implements RuntimeHooks {
115
- fibers: Map<number, FiberInfo>;
116
- scopes: Map<number, ScopeInfo>;
117
- private seq;
118
- private recent;
119
- private recentCap;
120
- emit(ev: RuntimeEvent, ctx: RuntimeEmitContext): void;
121
- getRecentEvents(): RuntimeEventRecord[];
122
- }
123
-
124
- /**
125
- * --- Runtime como objeto único (ZIO-style) ---
126
- * Un valor que representa "cómo" se ejecutan los efectos: scheduler + environment + hooks.
127
- */
128
- declare class Runtime<R> {
129
- readonly env: R;
130
- readonly scheduler: Scheduler;
131
- readonly hooks: RuntimeHooks;
132
- readonly forkPolicy: {
133
- initChild(fiber: RuntimeFiber<any, any, any> & any, parent?: (RuntimeFiber<any, any, any> & any) | null, scopeId?: number): void;
134
- };
135
- registry?: RuntimeRegistry;
136
- constructor(args: {
137
- env: R;
138
- scheduler?: Scheduler;
139
- hooks?: RuntimeHooks;
140
- });
141
- /** Deriva un runtime con env extendido (estilo provide/locally) */
142
- provide<R2>(env: R2): Runtime<R & R2>;
143
- emit(ev: RuntimeEvent): void;
144
- /**
145
- * ✅ CAMBIO: fork(effect, scopeId?) y pasa scopeId a forkPolicy
146
- */
147
- fork<E, A>(effect: Async<R, E, A>, scopeId?: number): Fiber<E, A>;
148
- unsafeRunAsync<E, A>(effect: Async<R, E, A>, cb: (exit: Exit<E, A>) => void): void;
149
- toPromise<E, A>(effect: Async<R, E, A>): Promise<A>;
150
- unsafeRun<E, A>(effect: Async<R, E, A>): void;
151
- delay<E, A>(ms: number, eff: Async<R, E, A>): Async<R, E, A>;
152
- static make<R>(env: R, scheduler?: Scheduler): Runtime<R>;
153
- /** Convenience logger: emits a RuntimeEvent of type "log". */
154
- log(level: "debug" | "info" | "warn" | "error", message: string, fields?: Record<string, unknown>): void;
155
- }
156
- /** Create a runtime from `env` and fork the given effect. */
157
- declare function fork<R, E, A>(effect: Async<R, E, A>, env?: R): Fiber<E, A>;
158
- /** Run an effect with `env` and invoke `cb` with the final Exit. */
159
- declare function unsafeRunAsync<R, E, A>(effect: Async<R, E, A>, env: R | undefined, cb: (exit: Exit<E, A>) => void): void;
160
- /** Run an effect with `env` and return a Promise of its success value. */
161
- declare function toPromise<R, E, A>(effect: Async<R, E, A>, env?: R): Promise<A>;
162
- /**
163
- * Create an Async from an abortable Promise.
164
- * Type params are ordered as `<E, A, R = unknown>` to match call-sites.
165
- */
166
- declare function fromPromiseAbortable<E, A, R = unknown>(make: (signal: AbortSignal, env: R) => Promise<A>, onReject: (u: unknown) => E): Async<R, E, A>;
167
- declare function unsafeRunFoldWithEnv<R, E, A>(eff: Async<R, E, A>, env: R, onFailure: (cause: Cause<E>) => void, onSuccess: (value: A) => void): void;
168
-
169
- type JSONValue = null | boolean | number | string | JSONValue[] | {
170
- [k: string]: JSONValue;
171
- };
172
- type ContextNode = {
173
- parent: ContextNode | null;
174
- patch: Record<string, JSONValue>;
175
- };
176
- type TraceContext = {
177
- traceId: string;
178
- spanId: string;
179
- parentSpanId?: string;
180
- sampled?: boolean;
181
- };
182
- type FiberContext = {
183
- log: ContextNode;
184
- trace: TraceContext | null;
185
- };
186
-
187
- type FiberId = number;
188
- type FiberStatus = "Running" | "Done" | "Interrupted";
189
- type Interrupted = {
190
- readonly _tag: "Interrupt";
191
- };
192
- type Fiber<E, A> = {
193
- readonly id: FiberId;
194
- readonly status: () => FiberStatus;
195
- readonly join: (cb: (exit: Exit<E, A>) => void) => void;
196
- readonly interrupt: () => void;
197
- readonly addFinalizer: (f: (exit: Exit<E, A>) => void) => void;
198
- };
199
- declare class RuntimeFiber<R, E, A> implements Fiber<E, A> {
200
- readonly id: FiberId;
201
- readonly runtime: Runtime<R>;
202
- private closing;
203
- private finishing;
204
- private runState;
205
- private interrupted;
206
- private result;
207
- private readonly joiners;
208
- private current;
209
- private readonly stack;
210
- private readonly fiberFinalizers;
211
- private finalizersDrained;
212
- fiberContext: FiberContext;
213
- name?: string;
214
- scopeId?: number;
215
- constructor(runtime: Runtime<R>, effect: Async<R, E, A>);
216
- private get env();
217
- private get scheduler();
218
- private emit;
219
- addFinalizer(f: (exit: Exit<E, A>) => void): void;
220
- status(): FiberStatus;
221
- join(cb: (exit: Exit<E, A>) => void): void;
222
- interrupt(): void;
223
- schedule(tag?: string): void;
224
- private runFinalizersOnce;
225
- private notify;
226
- private onSuccess;
227
- private onFailure;
228
- private budget;
229
- private step;
230
- }
231
- declare function getCurrentFiber(): RuntimeFiber<any, any, any> | null;
232
- /**
233
- * Unsafe (but convenient) access to the runtime that is currently executing.
234
- * Throws if called outside of a running fiber.
235
- */
236
- declare function unsafeGetCurrentRuntime<R>(): Runtime<R>;
237
- declare function withCurrentFiber<T>(fiber: RuntimeFiber<any, any, any>, f: () => T): T;
238
-
239
- type ScopeId = number;
240
- type CloseOptions = {
241
- awaitChildren?: boolean;
242
- };
243
- declare class Scope<R> {
244
- private readonly runtime;
245
- private readonly parentScopeId?;
246
- readonly id: ScopeId;
247
- private closed;
248
- private readonly children;
249
- private readonly subScopes;
250
- private readonly finalizers;
251
- constructor(runtime: Runtime<R>, parentScopeId?: ScopeId | undefined);
252
- /** registra un finalizer (LIFO) */
253
- addFinalizer(f: (exit: Exit<any, any>) => Async<R, any, any>): void;
254
- /** crea un sub scope (mismo runtime) */
255
- subScope(): Scope<R>;
256
- /** ✅ fork en este scope */
257
- fork<E, A>(eff: Async<R, E, A>): Fiber<E, A>;
258
- /** close fire-and-forget (no bloquea) */
259
- close(exit?: Exit<any, any>): void;
260
- closeAsync(exit?: Exit<any, any>, opts?: CloseOptions): Async<R, any, void>;
261
- }
262
- declare function withScopeAsync<R, E, A>(runtime: Runtime<R>, f: (scope: Scope<R>) => Async<R, E, A>): Async<R, E, A>;
263
-
264
- declare function withScope<R>(runtime: Runtime<R>, f: (scope: Scope<R>) => void): Async<R, never, void>;
265
- declare function withScope<R, E, A>(runtime: Runtime<R>, f: (scope: Scope<R>) => Async<R, E, A>): Async<R, E, A>;
266
-
267
- type Async<R, E, A> = {
268
- readonly _tag: "Succeed";
269
- readonly value: A;
270
- } | {
271
- readonly _tag: "Fail";
272
- readonly error: E;
273
- } | {
274
- readonly _tag: "Sync";
275
- readonly thunk: (env: R) => A;
276
- } | {
277
- readonly _tag: "Async";
278
- readonly register: (env: R, cb: (exit: Exit<E, A>) => void) => void | (() => void);
279
- } | {
280
- readonly _tag: "FlatMap";
281
- readonly first: Async<R, E, any>;
282
- readonly andThen: (a: any) => Async<R, E, A>;
283
- } | {
284
- readonly _tag: "Fold";
285
- readonly first: Async<R, E, any>;
286
- readonly onFailure: (e: any) => Async<R, E, A>;
287
- readonly onSuccess: (a: any) => Async<R, E, A>;
288
- } | {
289
- readonly _tag: "Fork";
290
- readonly effect: Async<R, E, any>;
291
- readonly scopeId?: number;
292
- };
293
- declare const Async: {
294
- succeed: <R, E, A>(value: A) => Async<R, E, A>;
295
- fail: <R, E, A = never>(error: E) => Async<R, E, A>;
296
- sync: <R, E, A>(thunk: (env: R) => A) => Async<R, E, A>;
297
- async: <R, E, A>(register: (env: R, cb: (exit: Exit<E, A>) => void) => void | (() => void)) => Async<R, E, A>;
298
- };
299
- declare function asyncFold<R, E, A, B>(fa: Async<R, E, A>, onFailure: (e: E) => Async<R, E, B>, onSuccess: (a: A) => Async<R, E, B>): Async<R, E, B>;
300
- declare function asyncCatchAll<R, E, A, R2, E2, B>(fa: Async<R, E, A>, handler: (e: E) => Async<R2, E2, B>): Async<R & R2, E2, A | B>;
301
- declare function asyncMapError<R, E, E2, A>(fa: Async<R, E, A>, f: (e: E) => E2): Async<R, E2, A>;
302
- declare const unit: <R>() => Async<R, never, void>;
303
- declare const asyncSucceed: <A>(value: A) => Async<unknown, never, A>;
304
- declare const asyncFail: <E>(error: E) => Async<unknown, E, never>;
305
- declare const asyncSync: <R, A>(thunk: (env: R) => A) => Async<R, unknown, A>;
306
- declare const asyncTotal: <A>(thunk: () => A) => Async<unknown, unknown, A>;
307
- declare const async: <R, E, A>(register: (env: R, cb: (exit: Exit<E, A>) => void) => void | Canceler) => Async<R, E, A>;
308
- declare function asyncMap<R, E, A, B>(fa: Async<R, E, A>, f: (a: A) => B): Async<R, E, B>;
309
- declare function asyncFlatMap<R, E, A, B>(fa: Async<R, E, A>, f: (a: A) => Async<R, E, B>): Async<R, E, B>;
310
- declare function acquireRelease<R, E, A>(acquire: Async<R, E, A>, release: (res: A, exit: Exit<E, any>) => Async<R, any, any>, scope: Scope<R>): Async<R, E, A>;
311
- declare function asyncInterruptible<R, E, A>(register: (env: R, cb: (exit: Exit<E, A>) => void) => void | Canceler): Async<R, E, A>;
312
- type AsyncWithPromise<R, E, A> = Async<R, E, A> & {
313
- toPromise: (env: R) => Promise<A>;
314
- unsafeRunPromise: () => Promise<A>;
315
- };
316
- declare const withAsyncPromise: <R, E, A>(run: (eff: Async<R, E, A>, env: R) => Promise<A>) => (eff: Async<R, E, A>) => AsyncWithPromise<R, E, A>;
317
- declare const mapAsync: <R, E, A, B>(fa: Async<R, E, A>, f: (a: A) => B) => Async<R, E, B>;
318
- declare const mapTryAsync: <R, E, A, B>(fa: Async<R, E, A>, f: (a: A) => B) => Async<R, E, B>;
319
-
320
- type None = {
321
- readonly _tag: "None";
322
- };
323
- type Some<A> = {
324
- readonly _tag: "Some";
325
- readonly value: A;
326
- };
327
- type Option<A> = None | Some<A>;
328
- declare const none: Option<never>;
329
- declare const some: <A>(value: A) => Option<A>;
330
-
331
- type Cause<E> = {
332
- readonly _tag: "Fail";
333
- readonly error: E;
334
- } | {
335
- readonly _tag: "Interrupt";
336
- } | {
337
- readonly _tag: "Die";
338
- readonly defect: unknown;
339
- };
340
- declare const Cause: {
341
- fail: <E>(error: E) => Cause<E>;
342
- interrupt: <E = never>() => Cause<E>;
343
- die: <E = never>(defect: unknown) => Cause<E>;
344
- };
345
- type Exit<E, A> = {
346
- _tag: "Success";
347
- value: A;
348
- } | {
349
- _tag: "Failure";
350
- cause: Cause<E>;
351
- };
352
- declare const Exit: {
353
- succeed: <E = never, A = never>(value: A) => Exit<E, A>;
354
- failCause: <E = never, A = never>(cause: Cause<E>) => Exit<E, A>;
355
- };
356
- type ZIO<R, E, A> = Async<R, E, A>;
357
- declare const succeed: <A>(value: A) => ZIO<unknown, never, A>;
358
- declare const fail: <E>(error: E) => ZIO<unknown, E, never>;
359
- declare const sync: <R, A>(thunk: (env: R) => A) => ZIO<R, unknown, A>;
360
- declare const map: <R, E, A, B>(fa: ZIO<R, E, A>, f: (a: A) => B) => Async<R, E, B>;
361
- declare const flatMap: <R, E, A, R2, E2, B>(fa: ZIO<R, E, A>, f: (a: A) => ZIO<R2, E2, B>) => ZIO<R & R2, E | E2, B>;
362
- declare const mapError: <R, E, E2, A>(fa: ZIO<R, E, A>, f: (e: E) => E2) => any;
363
- declare const catchAll: <R, E, A, R2, E2, B>(fa: ZIO<R, E, A>, handler: (e: E) => ZIO<R2, E2, B>) => ZIO<R & R2, E2, A | B>;
364
- declare function orElseOptional<R, E, A, R2, A2>(fa: ZIO<R, Option<E>, A>, that: () => ZIO<R2, Option<E>, A2>): ZIO<R & R2, Option<E>, A | A2>;
365
- declare const end: <E>() => ZIO<unknown, Option<E>, never>;
366
-
367
- type Empty<R, E, A> = {
368
- readonly _tag: "Empty";
369
- };
370
- type Emit<R, E, A> = {
371
- readonly _tag: "Emit";
372
- readonly value: ZIO<R, E, A>;
373
- };
374
- type Concat<R, E, A> = {
375
- readonly _tag: "Concat";
376
- readonly left: ZStream<R, E, A>;
377
- readonly right: ZStream<R, E, A>;
378
- };
379
- type Flatten<R, E, A> = {
380
- readonly _tag: "Flatten";
381
- readonly stream: ZStream<R, E, ZStream<R, E, A>>;
382
- };
383
- type FromPull<R, E, A> = {
384
- readonly _tag: "FromPull";
385
- readonly pull: ZIO<R, Option<E>, [A, ZStream<R, E, A>]>;
386
- };
387
- type Merge<R, E, A> = {
388
- readonly _tag: "Merge";
389
- readonly left: ZStream<R, E, A>;
390
- readonly right: ZStream<R, E, A>;
391
- readonly flip: boolean;
392
- };
393
- type Scoped<R, E, A> = {
394
- readonly _tag: "Scoped";
395
- readonly acquire: ZIO<R, E, ZStream<R, E, A>>;
396
- readonly release: (exit: Exit<any, any>) => Async<R, any, void>;
397
- };
398
- type Managed<R, E, A> = {
399
- readonly _tag: "Managed";
400
- readonly acquire: ZIO<R, E, {
401
- stream: ZStream<R, E, A>;
402
- release: (exit: Exit<any, any>) => Async<R, any, void>;
403
- }>;
404
- };
405
- type ZStream<R, E, A> = Empty<R, E, A> | Emit<R, E, A> | Concat<R, E, A> | FromPull<R, E, A> | Flatten<R, E, A> | Merge<R, E, A> | Scoped<R, E, A> | Managed<R, E, A>;
406
- type Normalize<E> = (u: unknown) => E;
407
- declare const widenOpt: <E1, E2>(opt: Option<E1>) => Option<E1 | E2>;
408
- declare const fromPull: <R, E, A>(pull: ZIO<R, Option<E>, [A, ZStream<R, E, A>]>) => ZStream<R, E, A>;
409
- declare const unwrapScoped: <R, E, A>(acquire: ZIO<R, E, ZStream<R, E, A>>, release: (exit: Exit<any, any>) => Async<R, any, void>) => ZStream<R, E, A>;
410
- declare const managedStream: <R, E, A>(acquire: ZIO<R, E, {
411
- stream: ZStream<R, E, A>;
412
- release: (exit: Exit<any, any>) => Async<R, any, void>;
413
- }>) => ZStream<R, E, A>;
414
- declare const mergeStream: <R, E, A>(left: ZStream<R, E, A>, right: ZStream<R, E, A>, flip?: boolean) => ZStream<R, E, A>;
415
- declare const emptyStream: <R, E, A>() => ZStream<R, E, A>;
416
- declare const emitStream: <R, E, A>(value: ZIO<R, E, A>) => ZStream<R, E, A>;
417
- declare const concatStream: <R, E, A>(left: ZStream<R, E, A>, right: ZStream<R, E, A>) => ZStream<R, E, A>;
418
- declare const flattenStream: <R, E, A>(stream: ZStream<R, E, ZStream<R, E, A>>) => ZStream<R, E, A>;
419
- declare function merge<R, E, A>(left: ZStream<R, E, A>, right: ZStream<R, E, A>): ZStream<R, E, A>;
420
- declare function uncons<R, E, A>(self: ZStream<R, E, A>): ZIO<R, Option<E>, [A, ZStream<R, E, A>]>;
421
- declare function assertNever(x: never, msg?: string): never;
422
- declare function mapStream<R, E, A, B>(self: ZStream<R, E, A>, f: (a: A) => B): ZStream<R, E, B>;
423
- declare function rangeStream(start: number, end: number): ZStream<unknown, never, number>;
424
- declare function zip<R, E1, A, E2, B>(left: ZStream<R, E1, A>, right: ZStream<R, E2, B>): ZStream<R, E1 | E2, [A, B]>;
425
- declare function foreachStream<R, E, A, R2, E2>(stream: ZStream<R, E, A>, f: (a: A) => Async<R2, E2, void>): Async<R & R2, E | E2, void>;
426
- declare function fromArray<A>(values: readonly A[]): ZStream<unknown, never, A>;
427
- declare function collectStream<R, E, A>(stream: ZStream<R, E, A>): ZIO<R, E, A[]>;
428
- declare function streamFromReadableStream<E>(body: ReadableStream<Uint8Array> | null | undefined, normalizeError: Normalize<E>): ZStream<unknown, E, Uint8Array>;
429
-
430
- export { unsafeGetCurrentRuntime as $, Async as A, mapTryAsync as B, Cause as C, type Some as D, Exit as E, type Fiber as F, none as G, some as H, type Canceler as I, type CancelToken as J, makeCancelToken as K, linkAbortController as L, fork as M, type None as N, type Option as O, unsafeRunAsync as P, toPromise as Q, Runtime as R, Scope as S, fromPromiseAbortable as T, unsafeRunFoldWithEnv as U, type FiberId as V, type FiberStatus as W, type Interrupted as X, RuntimeFiber as Y, type ZStream as Z, getCurrentFiber as _, type ZIO as a, withCurrentFiber as a0, type ScopeId as a1, withScopeAsync as a2, withScope as a3, type Task as a4, Scheduler as a5, globalScheduler as a6, type Empty as a7, type Emit as a8, type Concat as a9, type Flatten as aa, type FromPull as ab, type Merge as ac, type Scoped as ad, type Managed as ae, type Normalize as af, widenOpt as ag, fromPull as ah, unwrapScoped as ai, managedStream as aj, mergeStream as ak, emptyStream as al, emitStream as am, concatStream as an, flattenStream as ao, merge as ap, uncons as aq, assertNever as ar, mapStream as as, rangeStream as at, zip as au, foreachStream as av, fromArray as aw, collectStream as ax, streamFromReadableStream as ay, sync as b, flatMap as c, mapError as d, catchAll as e, fail as f, end as g, asyncFold as h, asyncCatchAll as i, asyncMapError as j, asyncSucceed as k, asyncFail as l, map as m, asyncSync as n, orElseOptional as o, asyncTotal as p, async as q, asyncMap as r, succeed as s, asyncFlatMap as t, unit as u, acquireRelease as v, asyncInterruptible as w, type AsyncWithPromise as x, withAsyncPromise as y, mapAsync as z };