brass-runtime 1.4.2 → 1.4.4

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 CHANGED
@@ -17,6 +17,14 @@ Goals: explore typed effects, structured concurrency, fibers, cooperative schedu
17
17
  - Structured concurrency combinators: `race`, `zipPar`, `collectAllPar`.
18
18
  - ZStream-style streams with backpressure, `Pull` semantics and resource safety.
19
19
 
20
+
21
+
22
+ ---
23
+
24
+ ## Getting Started
25
+
26
+ 👉 [Read the Getting Started guide](./docs/getting-started.md)
27
+
20
28
  ---
21
29
 
22
30
  ## What's new (recent changes)
@@ -0,0 +1 @@
1
+ function p(n,e,t){return {_tag:"Fold",first:n,onFailure:e,onSuccess:t}}function S(n,e){return p(n,t=>e(t),t=>l(t))}function v(n,e){return p(n,t=>b(e(t)),t=>l(t))}function m(){return y(()=>{})}var l=n=>({_tag:"Succeed",value:n}),b=n=>({_tag:"Fail",error:n}),y=n=>({_tag:"Sync",thunk:n}),x=n=>y(()=>n()),A=n=>({_tag:"Async",register:n});function F(n,e){return E(n,t=>l(e(t)))}function E(n,e){return {_tag:"FlatMap",first:n,andThen:e}}function k(n,e,t){return E(n,r=>(t.addFinalizer(a=>e(r,a)),l(r)))}function _(n){return A(n)}var f=class{queue=[];flushing=false;requested=false;schedule(e,t="anonymous"){if(console.log("[Scheduler.schedule] typeof task =",typeof e,"tag=",t),typeof e!="function"){console.error("[Scheduler.schedule] NON-FUNCTION TASK!",{tag:t,task:e});return}this.queue.push({tag:t,task:e}),this.requestFlush(),console.log("SCHEDULER",{flushing:this.flushing,q:this.queue.length,next:this.queue[0]?.tag,head:this.queue.slice(0,5).map(r=>r.tag)});}requestFlush(){console.log("requestFlush",{flushing:this.flushing,requested:this.requested,q:this.queue.length}),!this.flushing&&(this.requested||(this.requested=true,queueMicrotask(()=>{console.log(">> microtask fired",{flushing:this.flushing,requested:this.requested,q:this.queue.length}),this.flush();})));}flush(){if(console.log("FLUSH enter",{flushing:this.flushing,requested:this.requested,q:this.queue.length}),!this.flushing){this.flushing=true,this.requested=false;try{for(;this.queue.length>0;){let e=this.queue.shift();console.log("[flush] dequeued",{tag:e.tag,typeofTask:typeof e.task});try{console.log("TASK typeof",typeof e.task),e.task();}catch(t){console.error("[flush] task threw",t);}}}finally{this.flushing=false,console.log("FLUSH exit",{requested:this.requested,q:this.queue.length}),this.queue.length>0&&this.requestFlush();}}}},g=new f;var i={CONTINUE:"Continue",SUSPEND:"Suspend",DONE:"Done"},o={QUEUED:"Queued",RUNNING:"Running",SUSPENDED:"Suspended",DONE:"Done"},R=1,h=class{constructor(e,t,r){this.scheduler=r;this.id=R++,this.current=e,this.env=t;}id;closing=null;finishing=false;runState=o.RUNNING;interrupted=false;result=null;joiners=[];current;env;stack=[];fiberFinalizers=[];finalizersDrained=false;addFinalizer(e){this.fiberFinalizers.push(e);}status(){return this.result==null?"Running":this.interrupted?"Interrupted":"Done"}join(e){this.result!=null?e(this.result):this.joiners.push(e);}interrupt(){this.result==null&&(this.interrupted||(this.interrupted=true,this.schedule("interrupt-step")));}schedule(e="step"){console.log("[fiber.schedule]",{fiber:this.id,tag:e,runState:this.runState,schedulerCtor:this.scheduler?.constructor?.name,schedulerScheduleType:typeof this.scheduler?.schedule}),!(this.runState===o.DONE||this.runState===o.QUEUED)&&(this.runState=o.QUEUED,this.scheduler.schedule(()=>{if(console.log("[fiber.task] running",this.id),this.runState===o.DONE)return;switch(this.runState=o.RUNNING,this.step()){case i.CONTINUE:this.schedule("continue");return;case i.SUSPEND:this.runState=o.SUSPENDED;return;case i.DONE:this.runState=o.DONE;return}},`fiber#${this.id}.${e}`));}runFinalizersOnce(e){if(!this.finalizersDrained)for(this.finalizersDrained=true;this.fiberFinalizers.length>0;){let t=this.fiberFinalizers.pop();try{t(e);}catch{}}}notify(e){if(this.result==null&&this.closing==null){this.finishing=true,this.closing=e,this.runFinalizersOnce(e),this.result=e;for(let t of this.joiners)t(e);this.joiners.length=0;}}onSuccess(e){let t=this.stack.pop();if(!t){this.notify({_tag:"Success",value:e});return}this.current=t._tag==="SuccessCont"?t.k(e):t.onSuccess(e);}onFailure(e){for(;this.stack.length>0;){let t=this.stack.pop();if(t._tag==="FoldCont"){this.current=t.onFailure(e);return}}this.notify({_tag:"Failure",error:e});}step(){console.log("[fiber.step] enter",{fiber:this.id,current:this.current?._tag,result:this.result!=null,interrupted:this.interrupted,closing:this.closing!=null,finishing:this.finishing,stack:this.stack.length});let e=i.CONTINUE;if(this.result!=null)return e=i.DONE,e;if(this.interrupted&&this.closing==null)return console.log("[fiber.step] interrupted: failing now",{fiber:this.id}),this.notify({_tag:"Failure",error:{_tag:"Interrupted"}}),e=i.DONE,e;let t=this.current;switch(t._tag){case "Succeed":{console.log("[fiber.step] Succeed",{fiber:this.id}),this.onSuccess(t.value);break}case "Fail":{console.log("[fiber.step] Fail",{fiber:this.id}),this.onFailure(t.error);break}case "Sync":{console.log("[fiber.step] Sync",{fiber:this.id});try{let r=t.thunk(this.env);console.log("[fiber.step] Sync success",{fiber:this.id}),this.onSuccess(r);}catch(r){console.log("[fiber.step] Sync threw",{fiber:this.id,e:r}),this.onFailure(r);}break}case "FlatMap":{console.log("[fiber.step] FlatMap push cont",{fiber:this.id}),this.stack.push({_tag:"SuccessCont",k:t.andThen}),this.current=t.first;break}case "Fold":{console.log("[fiber.step] Fold push cont",{fiber:this.id}),this.stack.push({_tag:"FoldCont",onFailure:t.onFailure,onSuccess:t.onSuccess}),this.current=t.first;break}case "Async":{if(this.finishing)break;let r=false,a=s=>{if(!(this.result!=null||this.closing!=null)){if(this.interrupted){this.onFailure({_tag:"Interrupted"});return}s._tag==="Success"?this.onSuccess(s.value):this.onFailure(s.error),this.schedule("async-resume");}},c=s=>{r||(r=true,this.scheduler.schedule(()=>a(s),`fiber#${this.id}.async-resume`));},u=t.register(this.env,c);typeof u=="function"&&this.addFinalizer(()=>{r=true;try{u();}catch{}}),e=i.SUSPEND;break}}return this.result!=null&&(e=i.DONE),e}};function O(n,e,t=g){let r=new h(n,e,t);return r.schedule("initial-step"),r}function z(n,e){return A((t,r)=>{let a=new AbortController,c=false,u=s=>{c||(c=true,r(s));};try{(n.length===1?n(a.signal):n(t,a.signal)).then(d=>u({_tag:"Success",value:d})).catch(d=>u({_tag:"Failure",error:e(d)}));}catch(s){u({_tag:"Failure",error:e(s)});}return ()=>{c=true,a.abort();}})}export{p as a,S as b,v as c,m as d,l as e,b as f,y as g,x as h,A as i,F as j,E as k,k as l,_ as m,f as n,g as o,O as p,z as q};
@@ -0,0 +1 @@
1
+ 'use strict';function p(n,e,t){return {_tag:"Fold",first:n,onFailure:e,onSuccess:t}}function S(n,e){return p(n,t=>e(t),t=>l(t))}function v(n,e){return p(n,t=>b(e(t)),t=>l(t))}function m(){return y(()=>{})}var l=n=>({_tag:"Succeed",value:n}),b=n=>({_tag:"Fail",error:n}),y=n=>({_tag:"Sync",thunk:n}),x=n=>y(()=>n()),A=n=>({_tag:"Async",register:n});function F(n,e){return E(n,t=>l(e(t)))}function E(n,e){return {_tag:"FlatMap",first:n,andThen:e}}function k(n,e,t){return E(n,r=>(t.addFinalizer(a=>e(r,a)),l(r)))}function _(n){return A(n)}var f=class{queue=[];flushing=false;requested=false;schedule(e,t="anonymous"){if(console.log("[Scheduler.schedule] typeof task =",typeof e,"tag=",t),typeof e!="function"){console.error("[Scheduler.schedule] NON-FUNCTION TASK!",{tag:t,task:e});return}this.queue.push({tag:t,task:e}),this.requestFlush(),console.log("SCHEDULER",{flushing:this.flushing,q:this.queue.length,next:this.queue[0]?.tag,head:this.queue.slice(0,5).map(r=>r.tag)});}requestFlush(){console.log("requestFlush",{flushing:this.flushing,requested:this.requested,q:this.queue.length}),!this.flushing&&(this.requested||(this.requested=true,queueMicrotask(()=>{console.log(">> microtask fired",{flushing:this.flushing,requested:this.requested,q:this.queue.length}),this.flush();})));}flush(){if(console.log("FLUSH enter",{flushing:this.flushing,requested:this.requested,q:this.queue.length}),!this.flushing){this.flushing=true,this.requested=false;try{for(;this.queue.length>0;){let e=this.queue.shift();console.log("[flush] dequeued",{tag:e.tag,typeofTask:typeof e.task});try{console.log("TASK typeof",typeof e.task),e.task();}catch(t){console.error("[flush] task threw",t);}}}finally{this.flushing=false,console.log("FLUSH exit",{requested:this.requested,q:this.queue.length}),this.queue.length>0&&this.requestFlush();}}}},g=new f;var i={CONTINUE:"Continue",SUSPEND:"Suspend",DONE:"Done"},o={QUEUED:"Queued",RUNNING:"Running",SUSPENDED:"Suspended",DONE:"Done"},R=1,h=class{constructor(e,t,r){this.scheduler=r;this.id=R++,this.current=e,this.env=t;}id;closing=null;finishing=false;runState=o.RUNNING;interrupted=false;result=null;joiners=[];current;env;stack=[];fiberFinalizers=[];finalizersDrained=false;addFinalizer(e){this.fiberFinalizers.push(e);}status(){return this.result==null?"Running":this.interrupted?"Interrupted":"Done"}join(e){this.result!=null?e(this.result):this.joiners.push(e);}interrupt(){this.result==null&&(this.interrupted||(this.interrupted=true,this.schedule("interrupt-step")));}schedule(e="step"){console.log("[fiber.schedule]",{fiber:this.id,tag:e,runState:this.runState,schedulerCtor:this.scheduler?.constructor?.name,schedulerScheduleType:typeof this.scheduler?.schedule}),!(this.runState===o.DONE||this.runState===o.QUEUED)&&(this.runState=o.QUEUED,this.scheduler.schedule(()=>{if(console.log("[fiber.task] running",this.id),this.runState===o.DONE)return;switch(this.runState=o.RUNNING,this.step()){case i.CONTINUE:this.schedule("continue");return;case i.SUSPEND:this.runState=o.SUSPENDED;return;case i.DONE:this.runState=o.DONE;return}},`fiber#${this.id}.${e}`));}runFinalizersOnce(e){if(!this.finalizersDrained)for(this.finalizersDrained=true;this.fiberFinalizers.length>0;){let t=this.fiberFinalizers.pop();try{t(e);}catch{}}}notify(e){if(this.result==null&&this.closing==null){this.finishing=true,this.closing=e,this.runFinalizersOnce(e),this.result=e;for(let t of this.joiners)t(e);this.joiners.length=0;}}onSuccess(e){let t=this.stack.pop();if(!t){this.notify({_tag:"Success",value:e});return}this.current=t._tag==="SuccessCont"?t.k(e):t.onSuccess(e);}onFailure(e){for(;this.stack.length>0;){let t=this.stack.pop();if(t._tag==="FoldCont"){this.current=t.onFailure(e);return}}this.notify({_tag:"Failure",error:e});}step(){console.log("[fiber.step] enter",{fiber:this.id,current:this.current?._tag,result:this.result!=null,interrupted:this.interrupted,closing:this.closing!=null,finishing:this.finishing,stack:this.stack.length});let e=i.CONTINUE;if(this.result!=null)return e=i.DONE,e;if(this.interrupted&&this.closing==null)return console.log("[fiber.step] interrupted: failing now",{fiber:this.id}),this.notify({_tag:"Failure",error:{_tag:"Interrupted"}}),e=i.DONE,e;let t=this.current;switch(t._tag){case "Succeed":{console.log("[fiber.step] Succeed",{fiber:this.id}),this.onSuccess(t.value);break}case "Fail":{console.log("[fiber.step] Fail",{fiber:this.id}),this.onFailure(t.error);break}case "Sync":{console.log("[fiber.step] Sync",{fiber:this.id});try{let r=t.thunk(this.env);console.log("[fiber.step] Sync success",{fiber:this.id}),this.onSuccess(r);}catch(r){console.log("[fiber.step] Sync threw",{fiber:this.id,e:r}),this.onFailure(r);}break}case "FlatMap":{console.log("[fiber.step] FlatMap push cont",{fiber:this.id}),this.stack.push({_tag:"SuccessCont",k:t.andThen}),this.current=t.first;break}case "Fold":{console.log("[fiber.step] Fold push cont",{fiber:this.id}),this.stack.push({_tag:"FoldCont",onFailure:t.onFailure,onSuccess:t.onSuccess}),this.current=t.first;break}case "Async":{if(this.finishing)break;let r=false,a=s=>{if(!(this.result!=null||this.closing!=null)){if(this.interrupted){this.onFailure({_tag:"Interrupted"});return}s._tag==="Success"?this.onSuccess(s.value):this.onFailure(s.error),this.schedule("async-resume");}},c=s=>{r||(r=true,this.scheduler.schedule(()=>a(s),`fiber#${this.id}.async-resume`));},u=t.register(this.env,c);typeof u=="function"&&this.addFinalizer(()=>{r=true;try{u();}catch{}}),e=i.SUSPEND;break}}return this.result!=null&&(e=i.DONE),e}};function O(n,e,t=g){let r=new h(n,e,t);return r.schedule("initial-step"),r}function z(n,e){return A((t,r)=>{let a=new AbortController,c=false,u=s=>{c||(c=true,r(s));};try{(n.length===1?n(a.signal):n(t,a.signal)).then(d=>u({_tag:"Success",value:d})).catch(d=>u({_tag:"Failure",error:e(d)}));}catch(s){u({_tag:"Failure",error:e(s)});}return ()=>{c=true,a.abort();}})}exports.a=p;exports.b=S;exports.c=v;exports.d=m;exports.e=l;exports.f=b;exports.g=y;exports.h=x;exports.i=A;exports.j=F;exports.k=E;exports.l=k;exports.m=_;exports.n=f;exports.o=g;exports.p=O;exports.q=z;
@@ -20,10 +20,10 @@ declare function makeCancelToken(): CancelToken & {
20
20
  declare function linkAbortController(token: CancelToken, ac: AbortController): Canceler;
21
21
 
22
22
  type FiberId = number;
23
- type FiberStatus = "Running" | "Done" | "Interrupted";
24
23
  type Interrupted = {
25
24
  readonly _tag: "Interrupted";
26
25
  };
26
+ type FiberStatus = "Running" | "Done" | "Interrupted";
27
27
  type Fiber<E, A> = {
28
28
  readonly id: FiberId;
29
29
  readonly status: () => FiberStatus;
@@ -31,12 +31,6 @@ type Fiber<E, A> = {
31
31
  readonly interrupt: () => void;
32
32
  readonly addFinalizer: (f: (exit: Exit<E | Interrupted, A>) => void) => void;
33
33
  };
34
- type BrassError = {
35
- _tag: "Abort";
36
- } | {
37
- _tag: "PromiseRejected";
38
- reason: unknown;
39
- };
40
34
 
41
35
  type ScopeId = number;
42
36
  declare class Scope<R> {
@@ -53,7 +47,6 @@ declare class Scope<R> {
53
47
  subScope(): Scope<R>;
54
48
  /** fork en este scope */
55
49
  fork<E, A>(eff: Async<R, E, A>, env: R): Fiber<E | Interrupted, A>;
56
- /** Cierre estructurado */
57
50
  close(exit?: Exit<any, any>): void;
58
51
  isClosed(): boolean;
59
52
  }
@@ -63,7 +56,6 @@ declare class Scope<R> {
63
56
  */
64
57
  declare function withScope<R, A>(body: (scope: Scope<R>) => A): A;
65
58
 
66
- type NodeCallback<A> = (err: Error | null, result: A) => void;
67
59
  type Async<R, E, A> = {
68
60
  _tag: "Succeed";
69
61
  value: A;
@@ -89,8 +81,6 @@ type Async<R, E, A> = {
89
81
  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>;
90
82
  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>;
91
83
  declare function asyncMapError<R, E, E2, A>(fa: Async<R, E, A>, f: (e: E) => E2): Async<R, E2, A>;
92
- declare function from<A>(f: (cb: NodeCallback<A>) => void): Async<{}, Error, A>;
93
- declare function from<A>(thunk: () => Promise<A>): Async<{}, Error, A>;
94
84
  declare function unit(): Async<unknown, unknown, undefined>;
95
85
  declare const asyncSucceed: <A>(value: A) => Async<unknown, never, A>;
96
86
  declare const asyncFail: <E>(error: E) => Async<unknown, E, never>;
@@ -99,13 +89,6 @@ declare const asyncTotal: <A>(thunk: () => A) => Async<unknown, unknown, A>;
99
89
  declare const async: <R, E, A>(register: (env: R, cb: (exit: Exit<E, A>) => void) => void | Canceler) => Async<R, E, A>;
100
90
  declare function asyncMap<R, E, A, B>(fa: Async<R, E, A>, f: (a: A) => B): Async<R, E, B>;
101
91
  declare function asyncFlatMap<R, E, A, B>(fa: Async<R, E, A>, f: (a: A) => Async<R, E, B>): Async<R, E, B>;
102
- declare function toPromise<R, E, A>(eff: Async<R, E, A>, env: R): Promise<A>;
103
- declare function fromPromise<R, E, A>(thunk: (env: R) => Promise<A>, onError: (e: unknown) => E): Async<R, E, A>;
104
- declare function fromCallback<A>(f: (cb: NodeCallback<A>) => void): Async<{}, Error, A>;
105
- declare function tryPromiseAbortable<A>(thunk: (signal: AbortSignal) => Promise<A>): Async<unknown, BrassError, A>;
106
- declare function tryPromiseAbortable<R, A>(thunk: (env: R, signal: AbortSignal) => Promise<A>): Async<R, BrassError, A>;
107
- declare function fromPromiseAbortable<E, A>(thunk: (signal: AbortSignal) => Promise<A>, onError: (e: unknown) => E): Async<unknown, E, A>;
108
- declare function fromPromiseAbortable<R, E, A>(thunk: (env: R, signal: AbortSignal) => Promise<A>, onError: (e: unknown) => E): Async<R, E, A>;
109
92
  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>;
110
93
  declare function asyncInterruptible<R, E, A>(register: (env: R, cb: (exit: Exit<E, A>) => void) => void | Canceler): Async<R, E, A>;
111
94
 
@@ -138,4 +121,4 @@ declare const catchAll: <R, E, A, R2, E2, B>(fa: ZIO<R, E, A>, handler: (e: E) =
138
121
  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>;
139
122
  declare const end: <E>() => ZIO<unknown, Option<E>, never>;
140
123
 
141
- export { type Async as A, acquireRelease as B, asyncInterruptible as C, none as D, type Exit as E, some as F, type ScopeId as G, Scope as H, withScope as I, type Canceler as J, type CancelToken as K, makeCancelToken as L, linkAbortController as M, type None as N, type Option as O, type Some as S, type ZIO as Z, sync as a, flatMap as b, mapError as c, catchAll as d, end as e, fail as f, asyncFold as g, asyncCatchAll as h, asyncMapError as i, from 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, toPromise as v, fromPromise as w, fromCallback as x, tryPromiseAbortable as y, fromPromiseAbortable as z };
124
+ export { type Async as A, withScope as B, type Canceler as C, type CancelToken as D, type Exit as E, makeCancelToken as F, linkAbortController as G, type None as N, type Option as O, type Some as S, type ZIO as Z, sync as a, flatMap as b, mapError as c, catchAll as d, end as e, fail as f, asyncFold as g, asyncCatchAll as h, asyncMapError as i, asyncSucceed as j, asyncFail as k, asyncSync as l, map as m, asyncTotal as n, orElseOptional as o, async as p, asyncMap as q, asyncFlatMap as r, succeed as s, acquireRelease as t, unit as u, asyncInterruptible as v, none as w, some as x, type ScopeId as y, Scope as z };
@@ -20,10 +20,10 @@ declare function makeCancelToken(): CancelToken & {
20
20
  declare function linkAbortController(token: CancelToken, ac: AbortController): Canceler;
21
21
 
22
22
  type FiberId = number;
23
- type FiberStatus = "Running" | "Done" | "Interrupted";
24
23
  type Interrupted = {
25
24
  readonly _tag: "Interrupted";
26
25
  };
26
+ type FiberStatus = "Running" | "Done" | "Interrupted";
27
27
  type Fiber<E, A> = {
28
28
  readonly id: FiberId;
29
29
  readonly status: () => FiberStatus;
@@ -31,12 +31,6 @@ type Fiber<E, A> = {
31
31
  readonly interrupt: () => void;
32
32
  readonly addFinalizer: (f: (exit: Exit<E | Interrupted, A>) => void) => void;
33
33
  };
34
- type BrassError = {
35
- _tag: "Abort";
36
- } | {
37
- _tag: "PromiseRejected";
38
- reason: unknown;
39
- };
40
34
 
41
35
  type ScopeId = number;
42
36
  declare class Scope<R> {
@@ -53,7 +47,6 @@ declare class Scope<R> {
53
47
  subScope(): Scope<R>;
54
48
  /** fork en este scope */
55
49
  fork<E, A>(eff: Async<R, E, A>, env: R): Fiber<E | Interrupted, A>;
56
- /** Cierre estructurado */
57
50
  close(exit?: Exit<any, any>): void;
58
51
  isClosed(): boolean;
59
52
  }
@@ -63,7 +56,6 @@ declare class Scope<R> {
63
56
  */
64
57
  declare function withScope<R, A>(body: (scope: Scope<R>) => A): A;
65
58
 
66
- type NodeCallback<A> = (err: Error | null, result: A) => void;
67
59
  type Async<R, E, A> = {
68
60
  _tag: "Succeed";
69
61
  value: A;
@@ -89,8 +81,6 @@ type Async<R, E, A> = {
89
81
  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>;
90
82
  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>;
91
83
  declare function asyncMapError<R, E, E2, A>(fa: Async<R, E, A>, f: (e: E) => E2): Async<R, E2, A>;
92
- declare function from<A>(f: (cb: NodeCallback<A>) => void): Async<{}, Error, A>;
93
- declare function from<A>(thunk: () => Promise<A>): Async<{}, Error, A>;
94
84
  declare function unit(): Async<unknown, unknown, undefined>;
95
85
  declare const asyncSucceed: <A>(value: A) => Async<unknown, never, A>;
96
86
  declare const asyncFail: <E>(error: E) => Async<unknown, E, never>;
@@ -99,13 +89,6 @@ declare const asyncTotal: <A>(thunk: () => A) => Async<unknown, unknown, A>;
99
89
  declare const async: <R, E, A>(register: (env: R, cb: (exit: Exit<E, A>) => void) => void | Canceler) => Async<R, E, A>;
100
90
  declare function asyncMap<R, E, A, B>(fa: Async<R, E, A>, f: (a: A) => B): Async<R, E, B>;
101
91
  declare function asyncFlatMap<R, E, A, B>(fa: Async<R, E, A>, f: (a: A) => Async<R, E, B>): Async<R, E, B>;
102
- declare function toPromise<R, E, A>(eff: Async<R, E, A>, env: R): Promise<A>;
103
- declare function fromPromise<R, E, A>(thunk: (env: R) => Promise<A>, onError: (e: unknown) => E): Async<R, E, A>;
104
- declare function fromCallback<A>(f: (cb: NodeCallback<A>) => void): Async<{}, Error, A>;
105
- declare function tryPromiseAbortable<A>(thunk: (signal: AbortSignal) => Promise<A>): Async<unknown, BrassError, A>;
106
- declare function tryPromiseAbortable<R, A>(thunk: (env: R, signal: AbortSignal) => Promise<A>): Async<R, BrassError, A>;
107
- declare function fromPromiseAbortable<E, A>(thunk: (signal: AbortSignal) => Promise<A>, onError: (e: unknown) => E): Async<unknown, E, A>;
108
- declare function fromPromiseAbortable<R, E, A>(thunk: (env: R, signal: AbortSignal) => Promise<A>, onError: (e: unknown) => E): Async<R, E, A>;
109
92
  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>;
110
93
  declare function asyncInterruptible<R, E, A>(register: (env: R, cb: (exit: Exit<E, A>) => void) => void | Canceler): Async<R, E, A>;
111
94
 
@@ -138,4 +121,4 @@ declare const catchAll: <R, E, A, R2, E2, B>(fa: ZIO<R, E, A>, handler: (e: E) =
138
121
  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>;
139
122
  declare const end: <E>() => ZIO<unknown, Option<E>, never>;
140
123
 
141
- export { type Async as A, acquireRelease as B, asyncInterruptible as C, none as D, type Exit as E, some as F, type ScopeId as G, Scope as H, withScope as I, type Canceler as J, type CancelToken as K, makeCancelToken as L, linkAbortController as M, type None as N, type Option as O, type Some as S, type ZIO as Z, sync as a, flatMap as b, mapError as c, catchAll as d, end as e, fail as f, asyncFold as g, asyncCatchAll as h, asyncMapError as i, from 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, toPromise as v, fromPromise as w, fromCallback as x, tryPromiseAbortable as y, fromPromiseAbortable as z };
124
+ export { type Async as A, withScope as B, type Canceler as C, type CancelToken as D, type Exit as E, makeCancelToken as F, linkAbortController as G, type None as N, type Option as O, type Some as S, type ZIO as Z, sync as a, flatMap as b, mapError as c, catchAll as d, end as e, fail as f, asyncFold as g, asyncCatchAll as h, asyncMapError as i, asyncSucceed as j, asyncFail as k, asyncSync as l, map as m, asyncTotal as n, orElseOptional as o, async as p, asyncMap as q, asyncFlatMap as r, succeed as s, acquireRelease as t, unit as u, asyncInterruptible as v, none as w, some as x, type ScopeId as y, Scope as z };
@@ -1,4 +1,4 @@
1
- import { A as Async } from '../effect-D4h--Rys.mjs';
1
+ import { A as Async } from '../effect-DAU04-Ha.mjs';
2
2
 
3
3
  type HttpError = {
4
4
  _tag: "Abort";
@@ -1,4 +1,4 @@
1
- import { A as Async } from '../effect-D4h--Rys.js';
1
+ import { A as Async } from '../effect-DAU04-Ha.js';
2
2
 
3
3
  type HttpError = {
4
4
  _tag: "Abort";
@@ -1 +1 @@
1
- 'use strict';var chunk77P3VCG2_js=require('../chunk-77P3VCG2.js');var h=s=>s instanceof DOMException&&s.name==="AbortError"?{_tag:"Abort"}:typeof s=="object"&&s&&"_tag"in s?s:{_tag:"FetchError",message:String(s)};function b(s={}){let p=s.baseUrl??"",d=s.headers??{},n=t=>chunk77P3VCG2_js.t(async e=>{let r;try{r=new URL(t.url,p);}catch{throw {_tag:"BadUrl",message:`URL inv\xE1lida: ${t.url}`}}let g=performance.now(),o=await fetch(r,{...t,headers:{...d,...t.headers??{}},signal:e}),c=await o.text(),i={};return o.headers.forEach((u,m)=>i[m]=u),{status:o.status,statusText:o.statusText,headers:i,bodyText:c,ms:Math.round(performance.now()-g)}},h);return {get:(t,e)=>n({url:t,method:"GET",...e??{}}),post:(t,e,r)=>n({url:t,method:"POST",body:e&&e.length>0?e:void 0,...r??{}}),getText:(t,e)=>n({url:t,method:"GET",...e??{}}).map(r=>r.bodyText),getJson:(t,e)=>n({url:t,method:"GET",...e??{}}).map(r=>JSON.parse(r.bodyText)),postJson:(t,e,r)=>n({url:t,method:"POST",headers:{"content-type":"application/json",...r?.headers??{}},body:JSON.stringify(e),...r??{}})}}exports.makeHttp=b;
1
+ 'use strict';var chunkT2C7LOTT_js=require('../chunk-T2C7LOTT.js');var h=s=>s instanceof DOMException&&s.name==="AbortError"?{_tag:"Abort"}:typeof s=="object"&&s&&"_tag"in s?s:{_tag:"FetchError",message:String(s)};function y(s={}){let p=s.baseUrl??"",d=s.headers??{},n=t=>chunkT2C7LOTT_js.q(async e=>{let r;try{r=new URL(t.url,p);}catch{throw {_tag:"BadUrl",message:`URL inv\xE1lida: ${t.url}`}}let g=performance.now(),o=await fetch(r,{...t,headers:{...d,...t.headers??{}},signal:e}),c=await o.text(),i={};return o.headers.forEach((m,u)=>i[u]=m),{status:o.status,statusText:o.statusText,headers:i,bodyText:c,ms:Math.round(performance.now()-g)}},h);return {get:(t,e)=>n({url:t,method:"GET",...e??{}}),post:(t,e,r)=>n({url:t,method:"POST",body:e&&e.length>0?e:void 0,...r??{}}),getText:(t,e)=>n({url:t,method:"GET",...e??{}}).map(r=>r.bodyText),getJson:(t,e)=>n({url:t,method:"GET",...e??{}}).map(r=>JSON.parse(r.bodyText)),postJson:(t,e,r)=>n({url:t,method:"POST",headers:{"content-type":"application/json",...r?.headers??{}},body:JSON.stringify(e),...r??{}})}}exports.makeHttp=y;
@@ -1 +1 @@
1
- import {t}from'../chunk-EZTDSZ4Y.mjs';var h=s=>s instanceof DOMException&&s.name==="AbortError"?{_tag:"Abort"}:typeof s=="object"&&s&&"_tag"in s?s:{_tag:"FetchError",message:String(s)};function b(s={}){let p=s.baseUrl??"",d=s.headers??{},n=t$1=>t(async e=>{let r;try{r=new URL(t$1.url,p);}catch{throw {_tag:"BadUrl",message:`URL inv\xE1lida: ${t$1.url}`}}let g=performance.now(),o=await fetch(r,{...t$1,headers:{...d,...t$1.headers??{}},signal:e}),c=await o.text(),i={};return o.headers.forEach((u,m)=>i[m]=u),{status:o.status,statusText:o.statusText,headers:i,bodyText:c,ms:Math.round(performance.now()-g)}},h);return {get:(t,e)=>n({url:t,method:"GET",...e??{}}),post:(t,e,r)=>n({url:t,method:"POST",body:e&&e.length>0?e:void 0,...r??{}}),getText:(t,e)=>n({url:t,method:"GET",...e??{}}).map(r=>r.bodyText),getJson:(t,e)=>n({url:t,method:"GET",...e??{}}).map(r=>JSON.parse(r.bodyText)),postJson:(t,e,r)=>n({url:t,method:"POST",headers:{"content-type":"application/json",...r?.headers??{}},body:JSON.stringify(e),...r??{}})}}export{b as makeHttp};
1
+ import {q}from'../chunk-LNOZOVUL.mjs';var h=s=>s instanceof DOMException&&s.name==="AbortError"?{_tag:"Abort"}:typeof s=="object"&&s&&"_tag"in s?s:{_tag:"FetchError",message:String(s)};function y(s={}){let p=s.baseUrl??"",d=s.headers??{},n=t=>q(async e=>{let r;try{r=new URL(t.url,p);}catch{throw {_tag:"BadUrl",message:`URL inv\xE1lida: ${t.url}`}}let g=performance.now(),o=await fetch(r,{...t,headers:{...d,...t.headers??{}},signal:e}),c=await o.text(),i={};return o.headers.forEach((m,u)=>i[u]=m),{status:o.status,statusText:o.statusText,headers:i,bodyText:c,ms:Math.round(performance.now()-g)}},h);return {get:(t,e)=>n({url:t,method:"GET",...e??{}}),post:(t,e,r)=>n({url:t,method:"POST",body:e&&e.length>0?e:void 0,...r??{}}),getText:(t,e)=>n({url:t,method:"GET",...e??{}}).map(r=>r.bodyText),getJson:(t,e)=>n({url:t,method:"GET",...e??{}}).map(r=>JSON.parse(r.bodyText)),postJson:(t,e,r)=>n({url:t,method:"POST",headers:{"content-type":"application/json",...r?.headers??{}},body:JSON.stringify(e),...r??{}})}}export{y as makeHttp};
package/dist/index.d.mts CHANGED
@@ -1,5 +1,5 @@
1
- import { Z as ZIO, O as Option, A as Async } from './effect-D4h--Rys.mjs';
2
- export { K as CancelToken, J as Canceler, E as Exit, N as None, H as Scope, G as ScopeId, S as Some, B as acquireRelease, q as async, h as asyncCatchAll, l as asyncFail, t as asyncFlatMap, g as asyncFold, C as asyncInterruptible, r as asyncMap, i as asyncMapError, k as asyncSucceed, n as asyncSync, p as asyncTotal, d as catchAll, e as end, f as fail, b as flatMap, j as from, x as fromCallback, w as fromPromise, z as fromPromiseAbortable, M as linkAbortController, L as makeCancelToken, m as map, c as mapError, D as none, o as orElseOptional, F as some, s as succeed, a as sync, v as toPromise, y as tryPromiseAbortable, u as unit, I as withScope } from './effect-D4h--Rys.mjs';
1
+ import { Z as ZIO, O as Option, A as Async } from './effect-DAU04-Ha.mjs';
2
+ export { D as CancelToken, C as Canceler, E as Exit, N as None, z as Scope, y as ScopeId, S as Some, t as acquireRelease, p as async, h as asyncCatchAll, k as asyncFail, r as asyncFlatMap, g as asyncFold, v as asyncInterruptible, q as asyncMap, i as asyncMapError, j as asyncSucceed, l as asyncSync, n as asyncTotal, d as catchAll, e as end, f as fail, b as flatMap, G as linkAbortController, F as makeCancelToken, m as map, c as mapError, w as none, o as orElseOptional, x as some, s as succeed, a as sync, u as unit, B as withScope } from './effect-DAU04-Ha.mjs';
3
3
 
4
4
  type Task = () => void;
5
5
  declare class Scheduler {
@@ -32,12 +32,20 @@ type FromPull<R, E, A> = {
32
32
  readonly _tag: "FromPull";
33
33
  readonly pull: ZIO<R, Option<E>, [A, ZStream<R, E, A>]>;
34
34
  };
35
- 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>;
35
+ type Merge<R, E, A> = {
36
+ readonly _tag: "Merge";
37
+ readonly left: ZStream<R, E, A>;
38
+ readonly right: ZStream<R, E, A>;
39
+ readonly flip: boolean;
40
+ };
41
+ 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>;
36
42
  declare const fromPull: <R, E, A>(pull: ZIO<R, Option<E>, [A, ZStream<R, E, A>]>) => ZStream<R, E, A>;
43
+ declare const mergeStream: <R, E, A>(left: ZStream<R, E, A>, right: ZStream<R, E, A>, flip?: boolean) => ZStream<R, E, A>;
37
44
  declare const emptyStream: <R, E, A>() => ZStream<R, E, A>;
38
45
  declare const emitStream: <R, E, A>(value: ZIO<R, E, A>) => ZStream<R, E, A>;
39
46
  declare const concatStream: <R, E, A>(left: ZStream<R, E, A>, right: ZStream<R, E, A>) => ZStream<R, E, A>;
40
47
  declare const flattenStream: <R, E, A>(stream: ZStream<R, E, ZStream<R, E, A>>) => ZStream<R, E, A>;
48
+ declare function merge<R, E, A>(left: ZStream<R, E, A>, right: ZStream<R, E, A>): ZStream<R, E, A>;
41
49
  declare function uncons<R, E, A>(self: ZStream<R, E, A>): ZIO<R, Option<E>, [A, ZStream<R, E, A>]>;
42
50
  declare function mapStream<R, E, A, B>(self: ZStream<R, E, A>, f: (a: A) => B): ZStream<R, E, B>;
43
51
  declare function rangeStream(start: number, end: number): ZStream<unknown, never, number>;
@@ -46,4 +54,4 @@ declare function foreachStream<R, E, A, R2, E2>(stream: ZStream<R, E, A>, f: (a:
46
54
  declare function fromArray<A>(values: readonly A[]): ZStream<unknown, never, A>;
47
55
  declare function collectStream<R, E, A>(stream: ZStream<R, E, A>): ZIO<R, E, A[]>;
48
56
 
49
- export { Async, type Concat, type Emit, type Empty, type Flatten, type FromPull, Option, Scheduler, type Task, ZIO, type ZStream, collectStream, concatStream, emitStream, emptyStream, flattenStream, foreachStream, fromArray, fromPull, globalScheduler, mapStream, rangeStream, uncons, zip };
57
+ export { Async, type Concat, type Emit, type Empty, type Flatten, type FromPull, type Merge, Option, Scheduler, type Task, ZIO, type ZStream, collectStream, concatStream, emitStream, emptyStream, flattenStream, foreachStream, fromArray, fromPull, globalScheduler, mapStream, merge, mergeStream, rangeStream, uncons, zip };
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { Z as ZIO, O as Option, A as Async } from './effect-D4h--Rys.js';
2
- export { K as CancelToken, J as Canceler, E as Exit, N as None, H as Scope, G as ScopeId, S as Some, B as acquireRelease, q as async, h as asyncCatchAll, l as asyncFail, t as asyncFlatMap, g as asyncFold, C as asyncInterruptible, r as asyncMap, i as asyncMapError, k as asyncSucceed, n as asyncSync, p as asyncTotal, d as catchAll, e as end, f as fail, b as flatMap, j as from, x as fromCallback, w as fromPromise, z as fromPromiseAbortable, M as linkAbortController, L as makeCancelToken, m as map, c as mapError, D as none, o as orElseOptional, F as some, s as succeed, a as sync, v as toPromise, y as tryPromiseAbortable, u as unit, I as withScope } from './effect-D4h--Rys.js';
1
+ import { Z as ZIO, O as Option, A as Async } from './effect-DAU04-Ha.js';
2
+ export { D as CancelToken, C as Canceler, E as Exit, N as None, z as Scope, y as ScopeId, S as Some, t as acquireRelease, p as async, h as asyncCatchAll, k as asyncFail, r as asyncFlatMap, g as asyncFold, v as asyncInterruptible, q as asyncMap, i as asyncMapError, j as asyncSucceed, l as asyncSync, n as asyncTotal, d as catchAll, e as end, f as fail, b as flatMap, G as linkAbortController, F as makeCancelToken, m as map, c as mapError, w as none, o as orElseOptional, x as some, s as succeed, a as sync, u as unit, B as withScope } from './effect-DAU04-Ha.js';
3
3
 
4
4
  type Task = () => void;
5
5
  declare class Scheduler {
@@ -32,12 +32,20 @@ type FromPull<R, E, A> = {
32
32
  readonly _tag: "FromPull";
33
33
  readonly pull: ZIO<R, Option<E>, [A, ZStream<R, E, A>]>;
34
34
  };
35
- 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>;
35
+ type Merge<R, E, A> = {
36
+ readonly _tag: "Merge";
37
+ readonly left: ZStream<R, E, A>;
38
+ readonly right: ZStream<R, E, A>;
39
+ readonly flip: boolean;
40
+ };
41
+ 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>;
36
42
  declare const fromPull: <R, E, A>(pull: ZIO<R, Option<E>, [A, ZStream<R, E, A>]>) => ZStream<R, E, A>;
43
+ declare const mergeStream: <R, E, A>(left: ZStream<R, E, A>, right: ZStream<R, E, A>, flip?: boolean) => ZStream<R, E, A>;
37
44
  declare const emptyStream: <R, E, A>() => ZStream<R, E, A>;
38
45
  declare const emitStream: <R, E, A>(value: ZIO<R, E, A>) => ZStream<R, E, A>;
39
46
  declare const concatStream: <R, E, A>(left: ZStream<R, E, A>, right: ZStream<R, E, A>) => ZStream<R, E, A>;
40
47
  declare const flattenStream: <R, E, A>(stream: ZStream<R, E, ZStream<R, E, A>>) => ZStream<R, E, A>;
48
+ declare function merge<R, E, A>(left: ZStream<R, E, A>, right: ZStream<R, E, A>): ZStream<R, E, A>;
41
49
  declare function uncons<R, E, A>(self: ZStream<R, E, A>): ZIO<R, Option<E>, [A, ZStream<R, E, A>]>;
42
50
  declare function mapStream<R, E, A, B>(self: ZStream<R, E, A>, f: (a: A) => B): ZStream<R, E, B>;
43
51
  declare function rangeStream(start: number, end: number): ZStream<unknown, never, number>;
@@ -46,4 +54,4 @@ declare function foreachStream<R, E, A, R2, E2>(stream: ZStream<R, E, A>, f: (a:
46
54
  declare function fromArray<A>(values: readonly A[]): ZStream<unknown, never, A>;
47
55
  declare function collectStream<R, E, A>(stream: ZStream<R, E, A>): ZIO<R, E, A[]>;
48
56
 
49
- export { Async, type Concat, type Emit, type Empty, type Flatten, type FromPull, Option, Scheduler, type Task, ZIO, type ZStream, collectStream, concatStream, emitStream, emptyStream, flattenStream, foreachStream, fromArray, fromPull, globalScheduler, mapStream, rangeStream, uncons, zip };
57
+ export { Async, type Concat, type Emit, type Empty, type Flatten, type FromPull, type Merge, Option, Scheduler, type Task, ZIO, type ZStream, collectStream, concatStream, emitStream, emptyStream, flattenStream, foreachStream, fromArray, fromPull, globalScheduler, mapStream, merge, mergeStream, rangeStream, uncons, zip };
package/dist/index.js CHANGED
@@ -1 +1 @@
1
- 'use strict';var chunk77P3VCG2_js=require('./chunk-77P3VCG2.js');var l={_tag:"None"},y=e=>({_tag:"Some",value:e});var Z=e=>chunk77P3VCG2_js.i(e),u=e=>chunk77P3VCG2_js.j(e),X=e=>chunk77P3VCG2_js.k(t=>e(t)),A=(e,t)=>chunk77P3VCG2_js.n(e,t),_=(e,t)=>chunk77P3VCG2_js.o(e,n=>t(n)),O=(e,t)=>chunk77P3VCG2_js.f(e,t),Y=(e,t)=>chunk77P3VCG2_js.d(e,n=>t(n),n=>chunk77P3VCG2_js.i(n));function x(e,t){return chunk77P3VCG2_js.d(e,n=>n._tag==="Some"?chunk77P3VCG2_js.j(n):t(),n=>chunk77P3VCG2_js.i(n))}var $=()=>u(l);var h=e=>e._tag==="None"?l:y(e.value),g=e=>({_tag:"FromPull",pull:e}),w=()=>({_tag:"Empty"}),F=e=>({_tag:"Emit",value:e}),d=(e,t)=>({_tag:"Concat",left:e,right:t}),v=e=>({_tag:"Flatten",stream:e});function i(e){switch(e._tag){case "Empty":return u(l);case "Emit":return A(O(e.value,t=>y(t)),t=>[t,w()]);case "FromPull":return e.pull;case "Concat":return x(A(i(e.left),([t,n])=>[t,d(n,e.right)]),()=>i(e.right));case "Flatten":return _(i(e.stream),([t,n])=>x(A(i(t),([r,o])=>[r,d(o,v(n))]),()=>i(v(n))))}}function m(e,t){switch(e._tag){case "Empty":return w();case "Emit":return F(A(e.value,t));case "FromPull":return g(A(e.pull,([n,r])=>[t(n),m(r,t)]));case "Concat":return d(m(e.left,t),m(e.right,t));case "Flatten":{let n=m(e.stream,r=>m(r,t));return v(n)}}}function se(e,t){let n=r=>g(r>t?chunk77P3VCG2_js.j(l):chunk77P3VCG2_js.i([r,n(r+1)]));return n(e)}function b(e,t){let n=chunk77P3VCG2_js.d(chunk77P3VCG2_js.f(i(e),r=>h(r)),r=>chunk77P3VCG2_js.j(r),([r,o])=>chunk77P3VCG2_js.d(chunk77P3VCG2_js.f(i(t),E=>h(E)),E=>chunk77P3VCG2_js.j(E),([E,S])=>chunk77P3VCG2_js.i([[r,E],b(o,S)])));return g(n)}function ie(e,t){let n=r=>chunk77P3VCG2_js.d(chunk77P3VCG2_js.f(i(r),o=>h(o)),o=>o._tag==="None"?chunk77P3VCG2_js.i(void 0):chunk77P3VCG2_js.j(o),([o,E])=>chunk77P3VCG2_js.o(chunk77P3VCG2_js.f(t(o),S=>y(S)),()=>n(E)));return chunk77P3VCG2_js.d(n(e),r=>r._tag==="None"?chunk77P3VCG2_js.i(void 0):chunk77P3VCG2_js.j(r.value),()=>chunk77P3VCG2_js.i(void 0))}function pe(e){let t=w();for(let n=e.length-1;n>=0;n--){let r=F(Z(e[n]));t=d(r,t);}return t}function le(e){let t=(n,r)=>chunk77P3VCG2_js.d(i(n),o=>o._tag==="None"?Z(r):u(o),([o,E])=>t(E,[...r,o]));return O(t(e,[]),n=>{if(n._tag==="Some")return n.value;throw new Error("unreachable: stream end handled as success")})}var k=1,I=class e{constructor(t){this.env=t;this.id=k++;}id;closed=false;children=new Set;subScopes=new Set;finalizers=[];addFinalizer(t){if(this.closed)throw new Error("Trying to add finalizer to closed scope");this.finalizers.push(t);}subScope(){if(this.closed)throw new Error("Scope closed");let t=new e(this.env);return this.subScopes.add(t),t}fork(t,n){if(this.closed)throw new Error("Scope closed");let r=chunk77P3VCG2_js.c(t,n);return this.children.add(r),r.join(()=>{this.children.delete(r);}),r}close(t={_tag:"Success",value:void 0}){if(!this.closed){this.closed=true;for(let n of this.children)n.interrupt();for(let n of this.subScopes)n.close(t);for(;this.finalizers.length>0;){let r=this.finalizers.pop()(t);chunk77P3VCG2_js.c(r,this.env);}this.children.clear(),this.subScopes.clear();}}isClosed(){return this.closed}};function ue(e){let t=new I({});try{return e(t)}finally{t.close();}}function Se(){let e=false,t=new Set;return {isCancelled:()=>e,onCancel:r=>{if(e){try{r();}catch{}return ()=>{}}return t.add(r),()=>{t.delete(r);}},cancel:()=>{if(!e){e=true;for(let r of t)try{r();}catch{}t.clear();}}}}function fe(e,t){return e.onCancel(()=>t.abort())}Object.defineProperty(exports,"Scheduler",{enumerable:true,get:function(){return chunk77P3VCG2_js.a}});Object.defineProperty(exports,"acquireRelease",{enumerable:true,get:function(){return chunk77P3VCG2_js.u}});Object.defineProperty(exports,"async",{enumerable:true,get:function(){return chunk77P3VCG2_js.m}});Object.defineProperty(exports,"asyncCatchAll",{enumerable:true,get:function(){return chunk77P3VCG2_js.e}});Object.defineProperty(exports,"asyncFail",{enumerable:true,get:function(){return chunk77P3VCG2_js.j}});Object.defineProperty(exports,"asyncFlatMap",{enumerable:true,get:function(){return chunk77P3VCG2_js.o}});Object.defineProperty(exports,"asyncFold",{enumerable:true,get:function(){return chunk77P3VCG2_js.d}});Object.defineProperty(exports,"asyncInterruptible",{enumerable:true,get:function(){return chunk77P3VCG2_js.v}});Object.defineProperty(exports,"asyncMap",{enumerable:true,get:function(){return chunk77P3VCG2_js.n}});Object.defineProperty(exports,"asyncMapError",{enumerable:true,get:function(){return chunk77P3VCG2_js.f}});Object.defineProperty(exports,"asyncSucceed",{enumerable:true,get:function(){return chunk77P3VCG2_js.i}});Object.defineProperty(exports,"asyncSync",{enumerable:true,get:function(){return chunk77P3VCG2_js.k}});Object.defineProperty(exports,"asyncTotal",{enumerable:true,get:function(){return chunk77P3VCG2_js.l}});Object.defineProperty(exports,"from",{enumerable:true,get:function(){return chunk77P3VCG2_js.g}});Object.defineProperty(exports,"fromCallback",{enumerable:true,get:function(){return chunk77P3VCG2_js.r}});Object.defineProperty(exports,"fromPromise",{enumerable:true,get:function(){return chunk77P3VCG2_js.q}});Object.defineProperty(exports,"fromPromiseAbortable",{enumerable:true,get:function(){return chunk77P3VCG2_js.t}});Object.defineProperty(exports,"globalScheduler",{enumerable:true,get:function(){return chunk77P3VCG2_js.b}});Object.defineProperty(exports,"toPromise",{enumerable:true,get:function(){return chunk77P3VCG2_js.p}});Object.defineProperty(exports,"tryPromiseAbortable",{enumerable:true,get:function(){return chunk77P3VCG2_js.s}});Object.defineProperty(exports,"unit",{enumerable:true,get:function(){return chunk77P3VCG2_js.h}});exports.Scope=I;exports.catchAll=Y;exports.collectStream=le;exports.concatStream=d;exports.emitStream=F;exports.emptyStream=w;exports.end=$;exports.fail=u;exports.flatMap=_;exports.flattenStream=v;exports.foreachStream=ie;exports.fromArray=pe;exports.fromPull=g;exports.linkAbortController=fe;exports.makeCancelToken=Se;exports.map=A;exports.mapError=O;exports.mapStream=m;exports.none=l;exports.orElseOptional=x;exports.rangeStream=se;exports.some=y;exports.succeed=Z;exports.sync=X;exports.uncons=i;exports.withScope=ue;exports.zip=b;
1
+ 'use strict';var chunkT2C7LOTT_js=require('./chunk-T2C7LOTT.js');var S={_tag:"None"},b=e=>({_tag:"Some",value:e});var k=e=>chunkT2C7LOTT_js.e(e),_=e=>chunkT2C7LOTT_js.f(e),re=e=>chunkT2C7LOTT_js.g(r=>e(r)),g=(e,r)=>chunkT2C7LOTT_js.j(e,r),N=(e,r)=>chunkT2C7LOTT_js.k(e,t=>r(t)),w=(e,r)=>chunkT2C7LOTT_js.c(e,r),te=(e,r)=>chunkT2C7LOTT_js.a(e,t=>r(t),t=>chunkT2C7LOTT_js.e(t));function C(e,r){return chunkT2C7LOTT_js.a(e,t=>t._tag==="Some"?chunkT2C7LOTT_js.f(t):r(),t=>chunkT2C7LOTT_js.e(t))}var ne=()=>_(S);var H=1,x=class e{constructor(r){this.env=r;this.id=H++;}id;closed=false;children=new Set;subScopes=new Set;finalizers=[];addFinalizer(r){if(this.closed)throw new Error("Trying to add finalizer to closed scope");this.finalizers.push(r);}subScope(){if(this.closed)throw new Error("Scope closed");let r=new e(this.env);return this.subScopes.add(r),r}fork(r,t){if(this.closed)throw new Error("Scope closed");let n=chunkT2C7LOTT_js.p(r,t);return this.children.add(n),n.join(()=>{this.children.delete(n);}),n}close(r={_tag:"Success",value:void 0}){if(!this.closed){for(this.closed=true,this.children.forEach(t=>t.interrupt()),this.subScopes.forEach(t=>t.close(r));this.finalizers.length>0;){let n=this.finalizers.pop()(r);chunkT2C7LOTT_js.p(n,this.env);}this.children.clear(),this.subScopes.clear();}}isClosed(){return this.closed}};function ce(e){let r=new x({});try{return e(r)}finally{r.close();}}function T(e,r,t,n,o){return chunkT2C7LOTT_js.i((a,c)=>{let E=t.subScope(),s=false,R=E.fork(e,a),d=E.fork(r,a),m=u=>{E.fork(u,a).join(f=>{E.close(f),c(f);});};R.join(u=>{s||(s=true,m(n(u,d,E)));}),d.join(u=>{s||(s=true,m(o(u,R,E)));});})}var P=e=>e._tag==="None"?S:b(e.value),Z=e=>({_tag:"FromPull",pull:e}),Ze=(e,r,t=true)=>({_tag:"Merge",left:e,right:r,flip:t}),$=()=>({_tag:"Empty"}),W=e=>({_tag:"Emit",value:e}),F=(e,r)=>({_tag:"Concat",left:e,right:r}),M=e=>({_tag:"Flatten",stream:e});function L(e,r,t,n,o){return (a,c,E)=>{if(console.log(`[mergePull#${o}] winner=${e} exit=${a._tag}`),a._tag==="Failure"&&console.log(`[mergePull#${o}] failure error=`,a.error),a._tag==="Success"&&console.log(`[mergePull#${o}] success -> interrupt other`),a._tag==="Success"){let[d,m]=a.value;c.interrupt();let u=Z(e==="L"?v(m,t,!n,o):v(r,m,!n,o));return chunkT2C7LOTT_js.e([d,u])}let s=a.error;if(typeof s=="object"&&s!==null&&s._tag==="Interrupted")return chunkT2C7LOTT_js.f(s);let R=s;return R._tag==="None"?l(e==="L"?t:r):chunkT2C7LOTT_js.f(R)}}function v(e,r,t,n){return chunkT2C7LOTT_js.i((o,a)=>{let c=++n;console.log(`[mergePull#${c}] start flip=${t}`);let E=new x(o);console.log(`[mergePull#${c}] built pulls`);let s=l(e),R=l(r);console.log(`[mergePull#${c}] built pulls`);let d=L("L",e,r,t,c),m=L("R",e,r,t,c);console.log(`[mergePull#${c}] calling raceWith`);let u=T(s,R,E,d,m);console.log(`[mergePull#${c}] forking handler`),E.fork(u,o).join(f=>{console.log(`[mergePull#${c}] handler joined exit=${f._tag}`),E.close(f),console.log(`[mergePull#${c}] scope closed, calling cb`),a(f);});})}function xe(e,r){return Z(v(e,r,true,0))}function l(e){switch(e._tag){case "Empty":return _(S);case "Emit":return g(w(e.value,r=>b(r)),r=>[r,$()]);case "FromPull":return console.log("[uncons] FromPull"),e.pull;case "Concat":return C(g(l(e.left),([r,t])=>[r,F(t,e.right)]),()=>l(e.right));case "Flatten":return N(l(e.stream),([r,t])=>C(g(l(r),([n,o])=>[n,F(o,M(t))]),()=>l(M(t))));case "Merge":return console.log("[makeMergePull] defined"),v(e.left,e.right,e.flip,0)}}function h(e,r){switch(e._tag){case "Empty":return $();case "Emit":return W(g(e.value,r));case "FromPull":return Z(g(e.pull,([t,n])=>[r(t),h(n,r)]));case "Concat":return F(h(e.left,r),h(e.right,r));case "Flatten":{let t=h(e.stream,n=>h(n,r));return M(t)}}}function he(e,r){let t=n=>Z(n>r?chunkT2C7LOTT_js.f(S):chunkT2C7LOTT_js.e([n,t(n+1)]));return t(e)}function D(e,r){let t=chunkT2C7LOTT_js.a(chunkT2C7LOTT_js.c(l(e),n=>P(n)),n=>chunkT2C7LOTT_js.f(n),([n,o])=>chunkT2C7LOTT_js.a(chunkT2C7LOTT_js.c(l(r),a=>P(a)),a=>chunkT2C7LOTT_js.f(a),([a,c])=>chunkT2C7LOTT_js.e([[n,a],D(o,c)])));return Z(t)}function Oe(e,r){let t=n=>chunkT2C7LOTT_js.a(chunkT2C7LOTT_js.c(l(n),o=>P(o)),o=>o._tag==="None"?chunkT2C7LOTT_js.e(void 0):chunkT2C7LOTT_js.f(o),([o,a])=>chunkT2C7LOTT_js.k(chunkT2C7LOTT_js.c(r(o),c=>b(c)),()=>t(a)));return chunkT2C7LOTT_js.a(t(e),n=>n._tag==="None"?chunkT2C7LOTT_js.e(void 0):chunkT2C7LOTT_js.f(n.value),()=>chunkT2C7LOTT_js.e(void 0))}function Ie(e){let r=$();for(let t=e.length-1;t>=0;t--){let n=W(k(e[t]));r=F(n,r);}return r}function be(e){let r=(t,n)=>chunkT2C7LOTT_js.a(l(t),o=>o._tag==="None"?k(n):_(o),([o,a])=>r(a,[...n,o]));return w(r(e,[]),t=>{if(t._tag==="Some")return t.value;throw new Error("unreachable: stream end handled as success")})}function Fe(){let e=false,r=new Set;return {isCancelled:()=>e,onCancel:n=>{if(e){try{n();}catch{}return ()=>{}}return r.add(n),()=>{r.delete(n);}},cancel:()=>{if(!e){e=true;for(let n of r)try{n();}catch{}r.clear();}}}}function ve(e,r){return e.onCancel(()=>r.abort())}Object.defineProperty(exports,"Scheduler",{enumerable:true,get:function(){return chunkT2C7LOTT_js.n}});Object.defineProperty(exports,"acquireRelease",{enumerable:true,get:function(){return chunkT2C7LOTT_js.l}});Object.defineProperty(exports,"async",{enumerable:true,get:function(){return chunkT2C7LOTT_js.i}});Object.defineProperty(exports,"asyncCatchAll",{enumerable:true,get:function(){return chunkT2C7LOTT_js.b}});Object.defineProperty(exports,"asyncFail",{enumerable:true,get:function(){return chunkT2C7LOTT_js.f}});Object.defineProperty(exports,"asyncFlatMap",{enumerable:true,get:function(){return chunkT2C7LOTT_js.k}});Object.defineProperty(exports,"asyncFold",{enumerable:true,get:function(){return chunkT2C7LOTT_js.a}});Object.defineProperty(exports,"asyncInterruptible",{enumerable:true,get:function(){return chunkT2C7LOTT_js.m}});Object.defineProperty(exports,"asyncMap",{enumerable:true,get:function(){return chunkT2C7LOTT_js.j}});Object.defineProperty(exports,"asyncMapError",{enumerable:true,get:function(){return chunkT2C7LOTT_js.c}});Object.defineProperty(exports,"asyncSucceed",{enumerable:true,get:function(){return chunkT2C7LOTT_js.e}});Object.defineProperty(exports,"asyncSync",{enumerable:true,get:function(){return chunkT2C7LOTT_js.g}});Object.defineProperty(exports,"asyncTotal",{enumerable:true,get:function(){return chunkT2C7LOTT_js.h}});Object.defineProperty(exports,"globalScheduler",{enumerable:true,get:function(){return chunkT2C7LOTT_js.o}});Object.defineProperty(exports,"unit",{enumerable:true,get:function(){return chunkT2C7LOTT_js.d}});exports.Scope=x;exports.catchAll=te;exports.collectStream=be;exports.concatStream=F;exports.emitStream=W;exports.emptyStream=$;exports.end=ne;exports.fail=_;exports.flatMap=N;exports.flattenStream=M;exports.foreachStream=Oe;exports.fromArray=Ie;exports.fromPull=Z;exports.linkAbortController=ve;exports.makeCancelToken=Fe;exports.map=g;exports.mapError=w;exports.mapStream=h;exports.merge=xe;exports.mergeStream=Ze;exports.none=S;exports.orElseOptional=C;exports.rangeStream=he;exports.some=b;exports.succeed=k;exports.sync=re;exports.uncons=l;exports.withScope=ce;exports.zip=D;
package/dist/index.mjs CHANGED
@@ -1 +1 @@
1
- import {d as d$1,j,o,n,f,i as i$1,k as k$1,c}from'./chunk-EZTDSZ4Y.mjs';export{a as Scheduler,u as acquireRelease,m as async,e as asyncCatchAll,j as asyncFail,o as asyncFlatMap,d as asyncFold,v as asyncInterruptible,n as asyncMap,f as asyncMapError,i as asyncSucceed,k as asyncSync,l as asyncTotal,g as from,r as fromCallback,q as fromPromise,t as fromPromiseAbortable,b as globalScheduler,p as toPromise,s as tryPromiseAbortable,h as unit}from'./chunk-EZTDSZ4Y.mjs';var l={_tag:"None"},y=e=>({_tag:"Some",value:e});var Z=e=>i$1(e),u=e=>j(e),X=e=>k$1(t=>e(t)),A=(e,t)=>n(e,t),_=(e,t)=>o(e,n=>t(n)),O=(e,t)=>f(e,t),Y=(e,t)=>d$1(e,n=>t(n),n=>i$1(n));function x(e,t){return d$1(e,n=>n._tag==="Some"?j(n):t(),n=>i$1(n))}var $=()=>u(l);var h=e=>e._tag==="None"?l:y(e.value),g=e=>({_tag:"FromPull",pull:e}),w=()=>({_tag:"Empty"}),F=e=>({_tag:"Emit",value:e}),d=(e,t)=>({_tag:"Concat",left:e,right:t}),v=e=>({_tag:"Flatten",stream:e});function i(e){switch(e._tag){case "Empty":return u(l);case "Emit":return A(O(e.value,t=>y(t)),t=>[t,w()]);case "FromPull":return e.pull;case "Concat":return x(A(i(e.left),([t,n])=>[t,d(n,e.right)]),()=>i(e.right));case "Flatten":return _(i(e.stream),([t,n])=>x(A(i(t),([r,o])=>[r,d(o,v(n))]),()=>i(v(n))))}}function m(e,t){switch(e._tag){case "Empty":return w();case "Emit":return F(A(e.value,t));case "FromPull":return g(A(e.pull,([n,r])=>[t(n),m(r,t)]));case "Concat":return d(m(e.left,t),m(e.right,t));case "Flatten":{let n=m(e.stream,r=>m(r,t));return v(n)}}}function se(e,t){let n=r=>g(r>t?j(l):i$1([r,n(r+1)]));return n(e)}function b(e,t){let n=d$1(f(i(e),r=>h(r)),r=>j(r),([r,o])=>d$1(f(i(t),E=>h(E)),E=>j(E),([E,S])=>i$1([[r,E],b(o,S)])));return g(n)}function ie(e,t){let n=r=>d$1(f(i(r),o=>h(o)),o=>o._tag==="None"?i$1(void 0):j(o),([o$1,E])=>o(f(t(o$1),S=>y(S)),()=>n(E)));return d$1(n(e),r=>r._tag==="None"?i$1(void 0):j(r.value),()=>i$1(void 0))}function pe(e){let t=w();for(let n=e.length-1;n>=0;n--){let r=F(Z(e[n]));t=d(r,t);}return t}function le(e){let t=(n,r)=>d$1(i(n),o=>o._tag==="None"?Z(r):u(o),([o,E])=>t(E,[...r,o]));return O(t(e,[]),n=>{if(n._tag==="Some")return n.value;throw new Error("unreachable: stream end handled as success")})}var k=1,I=class e{constructor(t){this.env=t;this.id=k++;}id;closed=false;children=new Set;subScopes=new Set;finalizers=[];addFinalizer(t){if(this.closed)throw new Error("Trying to add finalizer to closed scope");this.finalizers.push(t);}subScope(){if(this.closed)throw new Error("Scope closed");let t=new e(this.env);return this.subScopes.add(t),t}fork(t,n){if(this.closed)throw new Error("Scope closed");let r=c(t,n);return this.children.add(r),r.join(()=>{this.children.delete(r);}),r}close(t={_tag:"Success",value:void 0}){if(!this.closed){this.closed=true;for(let n of this.children)n.interrupt();for(let n of this.subScopes)n.close(t);for(;this.finalizers.length>0;){let r=this.finalizers.pop()(t);c(r,this.env);}this.children.clear(),this.subScopes.clear();}}isClosed(){return this.closed}};function ue(e){let t=new I({});try{return e(t)}finally{t.close();}}function Se(){let e=false,t=new Set;return {isCancelled:()=>e,onCancel:r=>{if(e){try{r();}catch{}return ()=>{}}return t.add(r),()=>{t.delete(r);}},cancel:()=>{if(!e){e=true;for(let r of t)try{r();}catch{}t.clear();}}}}function fe(e,t){return e.onCancel(()=>t.abort())}export{I as Scope,Y as catchAll,le as collectStream,d as concatStream,F as emitStream,w as emptyStream,$ as end,u as fail,_ as flatMap,v as flattenStream,ie as foreachStream,pe as fromArray,g as fromPull,fe as linkAbortController,Se as makeCancelToken,A as map,O as mapError,m as mapStream,l as none,x as orElseOptional,se as rangeStream,y as some,Z as succeed,X as sync,i as uncons,ue as withScope,b as zip};
1
+ import {a,f,k as k$1,j,c,e,g as g$1,p,i}from'./chunk-LNOZOVUL.mjs';export{n as Scheduler,l as acquireRelease,i as async,b as asyncCatchAll,f as asyncFail,k as asyncFlatMap,a as asyncFold,m as asyncInterruptible,j as asyncMap,c as asyncMapError,e as asyncSucceed,g as asyncSync,h as asyncTotal,o as globalScheduler,d as unit}from'./chunk-LNOZOVUL.mjs';var S={_tag:"None"},b=e=>({_tag:"Some",value:e});var k=e$1=>e(e$1),_=e=>f(e),re=e=>g$1(r=>e(r)),g=(e,r)=>j(e,r),N=(e,r)=>k$1(e,t=>r(t)),w=(e,r)=>c(e,r),te=(e$1,r)=>a(e$1,t=>r(t),t=>e(t));function C(e$1,r){return a(e$1,t=>t._tag==="Some"?f(t):r(),t=>e(t))}var ne=()=>_(S);var H=1,x=class e{constructor(r){this.env=r;this.id=H++;}id;closed=false;children=new Set;subScopes=new Set;finalizers=[];addFinalizer(r){if(this.closed)throw new Error("Trying to add finalizer to closed scope");this.finalizers.push(r);}subScope(){if(this.closed)throw new Error("Scope closed");let r=new e(this.env);return this.subScopes.add(r),r}fork(r,t){if(this.closed)throw new Error("Scope closed");let n=p(r,t);return this.children.add(n),n.join(()=>{this.children.delete(n);}),n}close(r={_tag:"Success",value:void 0}){if(!this.closed){for(this.closed=true,this.children.forEach(t=>t.interrupt()),this.subScopes.forEach(t=>t.close(r));this.finalizers.length>0;){let n=this.finalizers.pop()(r);p(n,this.env);}this.children.clear(),this.subScopes.clear();}}isClosed(){return this.closed}};function ce(e){let r=new x({});try{return e(r)}finally{r.close();}}function T(e,r,t,n,o){return i((a,c)=>{let E=t.subScope(),s=false,R=E.fork(e,a),d=E.fork(r,a),m=u=>{E.fork(u,a).join(f=>{E.close(f),c(f);});};R.join(u=>{s||(s=true,m(n(u,d,E)));}),d.join(u=>{s||(s=true,m(o(u,R,E)));});})}var P=e=>e._tag==="None"?S:b(e.value),Z=e=>({_tag:"FromPull",pull:e}),Ze=(e,r,t=true)=>({_tag:"Merge",left:e,right:r,flip:t}),$=()=>({_tag:"Empty"}),W=e=>({_tag:"Emit",value:e}),F=(e,r)=>({_tag:"Concat",left:e,right:r}),M=e=>({_tag:"Flatten",stream:e});function L(e$1,r,t,n,o){return (a,c,E)=>{if(console.log(`[mergePull#${o}] winner=${e$1} exit=${a._tag}`),a._tag==="Failure"&&console.log(`[mergePull#${o}] failure error=`,a.error),a._tag==="Success"&&console.log(`[mergePull#${o}] success -> interrupt other`),a._tag==="Success"){let[d,m]=a.value;c.interrupt();let u=Z(e$1==="L"?v(m,t,!n,o):v(r,m,!n,o));return e([d,u])}let s=a.error;if(typeof s=="object"&&s!==null&&s._tag==="Interrupted")return f(s);let R=s;return R._tag==="None"?l(e$1==="L"?t:r):f(R)}}function v(e,r,t,n){return i((o,a)=>{let c=++n;console.log(`[mergePull#${c}] start flip=${t}`);let E=new x(o);console.log(`[mergePull#${c}] built pulls`);let s=l(e),R=l(r);console.log(`[mergePull#${c}] built pulls`);let d=L("L",e,r,t,c),m=L("R",e,r,t,c);console.log(`[mergePull#${c}] calling raceWith`);let u=T(s,R,E,d,m);console.log(`[mergePull#${c}] forking handler`),E.fork(u,o).join(f=>{console.log(`[mergePull#${c}] handler joined exit=${f._tag}`),E.close(f),console.log(`[mergePull#${c}] scope closed, calling cb`),a(f);});})}function xe(e,r){return Z(v(e,r,true,0))}function l(e){switch(e._tag){case "Empty":return _(S);case "Emit":return g(w(e.value,r=>b(r)),r=>[r,$()]);case "FromPull":return console.log("[uncons] FromPull"),e.pull;case "Concat":return C(g(l(e.left),([r,t])=>[r,F(t,e.right)]),()=>l(e.right));case "Flatten":return N(l(e.stream),([r,t])=>C(g(l(r),([n,o])=>[n,F(o,M(t))]),()=>l(M(t))));case "Merge":return console.log("[makeMergePull] defined"),v(e.left,e.right,e.flip,0)}}function h(e,r){switch(e._tag){case "Empty":return $();case "Emit":return W(g(e.value,r));case "FromPull":return Z(g(e.pull,([t,n])=>[r(t),h(n,r)]));case "Concat":return F(h(e.left,r),h(e.right,r));case "Flatten":{let t=h(e.stream,n=>h(n,r));return M(t)}}}function he(e$1,r){let t=n=>Z(n>r?f(S):e([n,t(n+1)]));return t(e$1)}function D(e$1,r){let t=a(c(l(e$1),n=>P(n)),n=>f(n),([n,o])=>a(c(l(r),a=>P(a)),a=>f(a),([a,c])=>e([[n,a],D(o,c)])));return Z(t)}function Oe(e$1,r){let t=n=>a(c(l(n),o=>P(o)),o=>o._tag==="None"?e(void 0):f(o),([o,a])=>k$1(c(r(o),c=>b(c)),()=>t(a)));return a(t(e$1),n=>n._tag==="None"?e(void 0):f(n.value),()=>e(void 0))}function Ie(e){let r=$();for(let t=e.length-1;t>=0;t--){let n=W(k(e[t]));r=F(n,r);}return r}function be(e){let r=(t,n)=>a(l(t),o=>o._tag==="None"?k(n):_(o),([o,a])=>r(a,[...n,o]));return w(r(e,[]),t=>{if(t._tag==="Some")return t.value;throw new Error("unreachable: stream end handled as success")})}function Fe(){let e=false,r=new Set;return {isCancelled:()=>e,onCancel:n=>{if(e){try{n();}catch{}return ()=>{}}return r.add(n),()=>{r.delete(n);}},cancel:()=>{if(!e){e=true;for(let n of r)try{n();}catch{}r.clear();}}}}function ve(e,r){return e.onCancel(()=>r.abort())}export{x as Scope,te as catchAll,be as collectStream,F as concatStream,W as emitStream,$ as emptyStream,ne as end,_ as fail,N as flatMap,M as flattenStream,Oe as foreachStream,Ie as fromArray,Z as fromPull,ve as linkAbortController,Fe as makeCancelToken,g as map,w as mapError,h as mapStream,xe as merge,Ze as mergeStream,S as none,C as orElseOptional,he as rangeStream,b as some,k as succeed,re as sync,l as uncons,ce as withScope,D as zip};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "brass-runtime",
3
- "version": "1.4.2",
3
+ "version": "1.4.4",
4
4
  "description": "Effect runtime utilities for TypeScript",
5
5
  "license": "ISC",
6
6
  "author": "",
@@ -1 +0,0 @@
1
- 'use strict';var h=class{queue=[];flushing=false;requested=false;schedule(e,t="anonymous"){if(console.log("[Scheduler.schedule] typeof task =",typeof e,"tag=",t),typeof e!="function"){console.error("[Scheduler.schedule] NON-FUNCTION TASK!",{tag:t,task:e});return}this.queue.push({tag:t,task:e}),this.requestFlush(),console.log("SCHEDULER",{flushing:this.flushing,q:this.queue.length,next:this.queue[0]?.tag,head:this.queue.slice(0,5).map(r=>r.tag)});}requestFlush(){console.log("requestFlush",{flushing:this.flushing,requested:this.requested,q:this.queue.length}),!this.flushing&&(this.requested||(this.requested=true,queueMicrotask(()=>{console.log(">> microtask fired",{flushing:this.flushing,requested:this.requested,q:this.queue.length}),this.flush();})));}flush(){if(console.log("FLUSH enter",{flushing:this.flushing,requested:this.requested,q:this.queue.length}),!this.flushing){this.flushing=true,this.requested=false;try{for(;this.queue.length>0;){let e=this.queue.shift();console.log("[flush] dequeued",{tag:e.tag,typeofTask:typeof e.task});try{console.log("TASK typeof",typeof e.task),e.task();}catch(t){console.error("[flush] task threw",t);}}}finally{this.flushing=false,console.log("FLUSH exit",{requested:this.requested,q:this.queue.length}),this.queue.length>0&&this.requestFlush();}}}},d=new h;var E=1,A=class{constructor(e,t,r){this.scheduler=r;this.id=E++,this.current=e,this.env=t;}id;closing=null;finishing=false;statusValue="Running";interrupted=false;result=null;joiners=[];current;env;stack=[];fiberFinalizers=[];scheduled=false;finalizersDrained=false;blockedOnAsync=false;addFinalizer(e){this.fiberFinalizers.push(e);}status(){return this.statusValue}join(e){this.result!=null?e(this.result):this.joiners.push(e);}interrupt(){this.result==null&&(this.interrupted||(this.interrupted=true,this.blockedOnAsync=false,this.schedule("interrupt-step")));}schedule(e="step"){console.log("[fiber.schedule]",{fiber:this.id,tag:e,schedulerCtor:this.scheduler?.constructor?.name,schedulerScheduleType:typeof this.scheduler?.schedule}),this.result==null&&(this.scheduled||(this.scheduled=true,this.scheduler.schedule(()=>{console.log("[fiber.task] running",this.id),this.scheduled=false,this.step();},`fiber#${this.id}.${e}`)));}runFinalizersOnce(e){if(!this.finalizersDrained)for(this.finalizersDrained=true;this.fiberFinalizers.length>0;){let t=this.fiberFinalizers.pop();try{t(e);}catch{}}}notify(e){if(this.result==null&&this.closing==null){this.finishing=true,this.closing=e,this.runFinalizersOnce(e),this.statusValue=this.interrupted?"Interrupted":"Done",this.result=e;for(let t of this.joiners)t(e);this.joiners.length=0;}}onSuccess(e){let t=this.stack.pop();if(!t){this.notify({_tag:"Success",value:e});return}this.current=t._tag==="SuccessCont"?t.k(e):t.onSuccess(e);}onFailure(e){for(;this.stack.length>0;){let t=this.stack.pop();if(t._tag==="FoldCont"){this.current=t.onFailure(e);return}}this.notify({_tag:"Failure",error:e});}step(){if(console.log("[fiber.step] enter",{fiber:this.id,current:this.current?._tag,result:this.result!=null,blockedOnAsync:this.blockedOnAsync,interrupted:this.interrupted,closing:this.closing!=null,finishing:this.finishing,stack:this.stack.length}),this.result!=null){console.log("[fiber.step] early-exit: already has result",{fiber:this.id});return}if(this.blockedOnAsync){console.log("[fiber.step] early-exit: blockedOnAsync",{fiber:this.id});return}if(this.interrupted&&this.closing==null){console.log("[fiber.step] interrupted: failing now",{fiber:this.id}),this.notify({_tag:"Failure",error:{_tag:"Interrupted"}});return}let e=this.current;switch(e._tag){case "Succeed":{console.log("[fiber.step] Succeed",{fiber:this.id}),this.onSuccess(e.value);return}case "Fail":{console.log("[fiber.step] Fail",{fiber:this.id}),this.onFailure(e.error);return}case "Sync":{console.log("[fiber.step] Sync",{fiber:this.id});try{let t=e.thunk(this.env);console.log("[fiber.step] Sync success",{fiber:this.id}),this.onSuccess(t);}catch(t){console.log("[fiber.step] Sync threw",{fiber:this.id,e:t}),this.onFailure(t);}return}case "FlatMap":{console.log("[fiber.step] FlatMap push cont",{fiber:this.id}),this.stack.push({_tag:"SuccessCont",k:e.andThen}),this.current=e.first;return}case "Fold":{console.log("[fiber.step] Fold push cont",{fiber:this.id}),this.stack.push({_tag:"FoldCont",onFailure:e.onFailure,onSuccess:e.onSuccess}),this.current=e.first;return}case "Async":{if(this.finishing)return;this.blockedOnAsync=true;let t=false,r=o=>{if(this.blockedOnAsync=false,!(this.result!=null||this.closing!=null)){if(this.interrupted){this.onFailure({_tag:"Interrupted"});return}o._tag==="Success"?this.onSuccess(o.value):this.onFailure(o.error),this.schedule("async-resume");}},i=o=>{t||(t=true,this.scheduler.schedule(()=>r(o),`fiber#${this.id}.async-resume`));},s=e.register(this.env,i);typeof s=="function"&&this.addFinalizer(()=>{t=true;try{s();}catch{}});return}}}};function f(n,e,t=d){let r=new A(n,e,t);return r.schedule("initial-step"),r}function y(n,e,t){return {_tag:"Fold",first:n,onFailure:e,onSuccess:t}}function q(n,e){return y(n,t=>e(t),t=>l(t))}function w(n,e){return y(n,t=>b(e(t)),t=>l(t))}function P(n){return c((e,t)=>{let r=false,i=a=>{r||(r=true,t(a));},s=a=>i({_tag:"Failure",error:a instanceof Error?a:new Error(String(a))}),o=a=>i({_tag:"Success",value:a});try{typeof n=="function"&&n.length>=1?n((a,u)=>a?s(a):o(u)):n().then(o,s);}catch(a){s(a);}})}function I(){return p(()=>{})}var l=n=>({_tag:"Succeed",value:n}),b=n=>({_tag:"Fail",error:n}),p=n=>({_tag:"Sync",thunk:n}),C=n=>p(()=>n()),c=n=>({_tag:"Async",register:n});function B(n,e){return g(n,t=>l(e(t)))}function g(n,e){return {_tag:"FlatMap",first:n,andThen:e}}function T(n,e){return new Promise((t,r)=>{f(n,e).join(s=>{let o=s;o._tag==="Success"?t(o.value):r(o.error);});})}function z(n,e){return c((t,r)=>{n(t).then(i=>r({_tag:"Success",value:i})).catch(i=>r({_tag:"Failure",error:e(i)}));})}function j(n){return c((e,t)=>{let r=false,i=s=>{r||(r=true,t(s));};try{n((s,o)=>{i(s?{_tag:"Failure",error:s}:{_tag:"Success",value:o});});}catch(s){i({_tag:"Failure",error:s instanceof Error?s:new Error(String(s))});}})}var v=n=>typeof n=="object"&&n!==null&&"name"in n&&n.name==="AbortError";function O(n){return R((t,r)=>n.length===1?n(r):n(t,r),t=>v(t)?{_tag:"Abort"}:{_tag:"PromiseRejected",reason:t})}function R(n,e){return c((t,r)=>{let i=new AbortController,s=false,o=a=>{s||(s=true,r(a));};try{(n.length===1?n(i.signal):n(t,i.signal)).then(u=>o({_tag:"Success",value:u})).catch(u=>o({_tag:"Failure",error:e(u)}));}catch(a){o({_tag:"Failure",error:e(a)});}return ()=>{s=true,i.abort();}})}function M(n,e,t){return g(n,r=>(t.addFinalizer(i=>e(r,i)),l(r)))}function N(n){return c(n)}exports.a=h;exports.b=d;exports.c=f;exports.d=y;exports.e=q;exports.f=w;exports.g=P;exports.h=I;exports.i=l;exports.j=b;exports.k=p;exports.l=C;exports.m=c;exports.n=B;exports.o=g;exports.p=T;exports.q=z;exports.r=j;exports.s=O;exports.t=R;exports.u=M;exports.v=N;
@@ -1 +0,0 @@
1
- var h=class{queue=[];flushing=false;requested=false;schedule(e,t="anonymous"){if(console.log("[Scheduler.schedule] typeof task =",typeof e,"tag=",t),typeof e!="function"){console.error("[Scheduler.schedule] NON-FUNCTION TASK!",{tag:t,task:e});return}this.queue.push({tag:t,task:e}),this.requestFlush(),console.log("SCHEDULER",{flushing:this.flushing,q:this.queue.length,next:this.queue[0]?.tag,head:this.queue.slice(0,5).map(r=>r.tag)});}requestFlush(){console.log("requestFlush",{flushing:this.flushing,requested:this.requested,q:this.queue.length}),!this.flushing&&(this.requested||(this.requested=true,queueMicrotask(()=>{console.log(">> microtask fired",{flushing:this.flushing,requested:this.requested,q:this.queue.length}),this.flush();})));}flush(){if(console.log("FLUSH enter",{flushing:this.flushing,requested:this.requested,q:this.queue.length}),!this.flushing){this.flushing=true,this.requested=false;try{for(;this.queue.length>0;){let e=this.queue.shift();console.log("[flush] dequeued",{tag:e.tag,typeofTask:typeof e.task});try{console.log("TASK typeof",typeof e.task),e.task();}catch(t){console.error("[flush] task threw",t);}}}finally{this.flushing=false,console.log("FLUSH exit",{requested:this.requested,q:this.queue.length}),this.queue.length>0&&this.requestFlush();}}}},d=new h;var E=1,A=class{constructor(e,t,r){this.scheduler=r;this.id=E++,this.current=e,this.env=t;}id;closing=null;finishing=false;statusValue="Running";interrupted=false;result=null;joiners=[];current;env;stack=[];fiberFinalizers=[];scheduled=false;finalizersDrained=false;blockedOnAsync=false;addFinalizer(e){this.fiberFinalizers.push(e);}status(){return this.statusValue}join(e){this.result!=null?e(this.result):this.joiners.push(e);}interrupt(){this.result==null&&(this.interrupted||(this.interrupted=true,this.blockedOnAsync=false,this.schedule("interrupt-step")));}schedule(e="step"){console.log("[fiber.schedule]",{fiber:this.id,tag:e,schedulerCtor:this.scheduler?.constructor?.name,schedulerScheduleType:typeof this.scheduler?.schedule}),this.result==null&&(this.scheduled||(this.scheduled=true,this.scheduler.schedule(()=>{console.log("[fiber.task] running",this.id),this.scheduled=false,this.step();},`fiber#${this.id}.${e}`)));}runFinalizersOnce(e){if(!this.finalizersDrained)for(this.finalizersDrained=true;this.fiberFinalizers.length>0;){let t=this.fiberFinalizers.pop();try{t(e);}catch{}}}notify(e){if(this.result==null&&this.closing==null){this.finishing=true,this.closing=e,this.runFinalizersOnce(e),this.statusValue=this.interrupted?"Interrupted":"Done",this.result=e;for(let t of this.joiners)t(e);this.joiners.length=0;}}onSuccess(e){let t=this.stack.pop();if(!t){this.notify({_tag:"Success",value:e});return}this.current=t._tag==="SuccessCont"?t.k(e):t.onSuccess(e);}onFailure(e){for(;this.stack.length>0;){let t=this.stack.pop();if(t._tag==="FoldCont"){this.current=t.onFailure(e);return}}this.notify({_tag:"Failure",error:e});}step(){if(console.log("[fiber.step] enter",{fiber:this.id,current:this.current?._tag,result:this.result!=null,blockedOnAsync:this.blockedOnAsync,interrupted:this.interrupted,closing:this.closing!=null,finishing:this.finishing,stack:this.stack.length}),this.result!=null){console.log("[fiber.step] early-exit: already has result",{fiber:this.id});return}if(this.blockedOnAsync){console.log("[fiber.step] early-exit: blockedOnAsync",{fiber:this.id});return}if(this.interrupted&&this.closing==null){console.log("[fiber.step] interrupted: failing now",{fiber:this.id}),this.notify({_tag:"Failure",error:{_tag:"Interrupted"}});return}let e=this.current;switch(e._tag){case "Succeed":{console.log("[fiber.step] Succeed",{fiber:this.id}),this.onSuccess(e.value);return}case "Fail":{console.log("[fiber.step] Fail",{fiber:this.id}),this.onFailure(e.error);return}case "Sync":{console.log("[fiber.step] Sync",{fiber:this.id});try{let t=e.thunk(this.env);console.log("[fiber.step] Sync success",{fiber:this.id}),this.onSuccess(t);}catch(t){console.log("[fiber.step] Sync threw",{fiber:this.id,e:t}),this.onFailure(t);}return}case "FlatMap":{console.log("[fiber.step] FlatMap push cont",{fiber:this.id}),this.stack.push({_tag:"SuccessCont",k:e.andThen}),this.current=e.first;return}case "Fold":{console.log("[fiber.step] Fold push cont",{fiber:this.id}),this.stack.push({_tag:"FoldCont",onFailure:e.onFailure,onSuccess:e.onSuccess}),this.current=e.first;return}case "Async":{if(this.finishing)return;this.blockedOnAsync=true;let t=false,r=o=>{if(this.blockedOnAsync=false,!(this.result!=null||this.closing!=null)){if(this.interrupted){this.onFailure({_tag:"Interrupted"});return}o._tag==="Success"?this.onSuccess(o.value):this.onFailure(o.error),this.schedule("async-resume");}},i=o=>{t||(t=true,this.scheduler.schedule(()=>r(o),`fiber#${this.id}.async-resume`));},s=e.register(this.env,i);typeof s=="function"&&this.addFinalizer(()=>{t=true;try{s();}catch{}});return}}}};function f(n,e,t=d){let r=new A(n,e,t);return r.schedule("initial-step"),r}function y(n,e,t){return {_tag:"Fold",first:n,onFailure:e,onSuccess:t}}function q(n,e){return y(n,t=>e(t),t=>l(t))}function w(n,e){return y(n,t=>b(e(t)),t=>l(t))}function P(n){return c((e,t)=>{let r=false,i=a=>{r||(r=true,t(a));},s=a=>i({_tag:"Failure",error:a instanceof Error?a:new Error(String(a))}),o=a=>i({_tag:"Success",value:a});try{typeof n=="function"&&n.length>=1?n((a,u)=>a?s(a):o(u)):n().then(o,s);}catch(a){s(a);}})}function I(){return p(()=>{})}var l=n=>({_tag:"Succeed",value:n}),b=n=>({_tag:"Fail",error:n}),p=n=>({_tag:"Sync",thunk:n}),C=n=>p(()=>n()),c=n=>({_tag:"Async",register:n});function B(n,e){return g(n,t=>l(e(t)))}function g(n,e){return {_tag:"FlatMap",first:n,andThen:e}}function T(n,e){return new Promise((t,r)=>{f(n,e).join(s=>{let o=s;o._tag==="Success"?t(o.value):r(o.error);});})}function z(n,e){return c((t,r)=>{n(t).then(i=>r({_tag:"Success",value:i})).catch(i=>r({_tag:"Failure",error:e(i)}));})}function j(n){return c((e,t)=>{let r=false,i=s=>{r||(r=true,t(s));};try{n((s,o)=>{i(s?{_tag:"Failure",error:s}:{_tag:"Success",value:o});});}catch(s){i({_tag:"Failure",error:s instanceof Error?s:new Error(String(s))});}})}var v=n=>typeof n=="object"&&n!==null&&"name"in n&&n.name==="AbortError";function O(n){return R((t,r)=>n.length===1?n(r):n(t,r),t=>v(t)?{_tag:"Abort"}:{_tag:"PromiseRejected",reason:t})}function R(n,e){return c((t,r)=>{let i=new AbortController,s=false,o=a=>{s||(s=true,r(a));};try{(n.length===1?n(i.signal):n(t,i.signal)).then(u=>o({_tag:"Success",value:u})).catch(u=>o({_tag:"Failure",error:e(u)}));}catch(a){o({_tag:"Failure",error:e(a)});}return ()=>{s=true,i.abort();}})}function M(n,e,t){return g(n,r=>(t.addFinalizer(i=>e(r,i)),l(r)))}function N(n){return c(n)}export{h as a,d as b,f as c,y as d,q as e,w as f,P as g,I as h,l as i,b as j,p as k,C as l,c as m,B as n,g as o,T as p,z as q,j as r,O as s,R as t,M as u,N as v};