brass-runtime 1.6.0 → 1.6.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.
- package/dist/chunk-BQ3I6L5Z.js +1 -0
- package/dist/chunk-SMCQ6GGV.mjs +1 -0
- package/dist/{effect-Dt7h2Ttr.d.mts → effect-BTR2nIXd.d.mts} +6 -3
- package/dist/{effect-Dt7h2Ttr.d.ts → effect-BTR2nIXd.d.ts} +6 -3
- package/dist/http/index.d.mts +61 -2
- package/dist/http/index.d.ts +61 -2
- package/dist/http/index.js +1 -1
- package/dist/http/index.mjs +1 -1
- package/dist/index.d.mts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +1 -1
- package/dist/index.mjs +1 -1
- package/package.json +1 -1
- package/dist/chunk-JKG47VM5.js +0 -1
- package/dist/chunk-Z2JVOS2Q.mjs +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
'use strict';function E(n,e,t){return {_tag:"Fold",first:n,onFailure:e,onSuccess:t}}function D(n,e){return E(n,t=>e(t),t=>A(t))}function P(n,e){return E(n,t=>m(e(t)),t=>A(t))}var T=()=>A(void 0),A=n=>({_tag:"Succeed",value:n}),m=n=>({_tag:"Fail",error:n}),S=n=>({_tag:"Sync",thunk:n}),I=n=>S(()=>n()),l=n=>({_tag:"Async",register:n});function C(n,e){return p(n,t=>A(e(t)))}function p(n,e){return {_tag:"FlatMap",first:n,andThen:e}}function z(n,e,t){return p(n,r=>(t.addFinalizer(i=>e(r,i)),A(r)))}function U(n){return l(n)}var d=class{buf;head=0;tail=0;size_=0;constructor(e=1024){let t=Math.max(2,this.nextPow2(e));this.buf=new Array(t);}get length(){return this.size_}get capacity(){return this.buf.length}isEmpty(){return this.size_===0}push(e){this.size_===this.buf.length&&this.grow(),this.buf[this.tail]=e,this.tail=this.tail+1&this.buf.length-1,this.size_++;}shift(){if(this.size_===0)return;let e=this.buf[this.head];return this.buf[this.head]=void 0,this.head=this.head+1&this.buf.length-1,this.size_--,e}clear(){this.buf.fill(void 0),this.head=0,this.tail=0,this.size_=0;}grow(){let e=this.buf,t=new Array(e.length*2);for(let r=0;r<this.size_;r++)t[r]=e[this.head+r&e.length-1];this.buf=t,this.head=0,this.tail=this.size_;}nextPow2(e){let t=1;for(;t<e;)t<<=1;return t}};var g=2048,R=4096,x=(()=>{if(typeof globalThis.setImmediate=="function")return n=>globalThis.setImmediate(n);if(typeof globalThis.MessageChannel=="function"){let n=new globalThis.MessageChannel,e=null;return n.port1.onmessage=()=>{let t=e;e=null,t?.();},t=>{e=t,n.port2.postMessage(0);}}return n=>setTimeout(n,0)})(),y=class{queue=new d(1024);flushing=false;scheduled=false;schedule(e,t="anonymous"){if(typeof e=="function"&&(this.queue.push({tag:t,task:e}),!this.flushing&&!this.scheduled)){this.scheduled=true;let r=this.queue.length>R?"macro":"micro";this.requestFlush(r);}}requestFlush(e){e==="micro"?queueMicrotask(()=>this.flush()):x(()=>this.flush());}flush(){if(this.flushing)return;this.flushing=true,this.scheduled=false;let e=0;try{for(;e<g;){let t=this.queue.shift();if(!t)break;e++;try{t.task();}catch(r){console.error(`[Scheduler] task threw (tag=${t.tag})`,r);}}}finally{if(this.flushing=false,this.queue.length>0&&!this.scheduled){this.scheduled=true;let t=e>=g||this.queue.length>R?"macro":"micro";this.requestFlush(t);}}}},b=new y;var u={CONTINUE:"Continue",SUSPEND:"Suspend",DONE:"Done"},c={QUEUED:"Queued",RUNNING:"Running",SUSPENDED:"Suspended",DONE:"Done"},F=1,_=1024;function k(n){let e=n;for(;e._tag==="FlatMap"&&e.first._tag==="FlatMap";){let t=e.first,r=e.andThen;e={_tag:"FlatMap",first:t.first,andThen:i=>({_tag:"FlatMap",first:t.andThen(i),andThen:r})};}return e}var f=class{constructor(e,t,r){this.scheduler=r;this.id=F++,this.current=e,this.env=t;}id;closing=null;finishing=false;runState=c.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"){this.runState===c.DONE||this.runState===c.QUEUED||(this.runState=c.QUEUED,this.scheduler.schedule(()=>{if(this.runState===c.DONE)return;switch(this.runState=c.RUNNING,this.step()){case u.CONTINUE:this.schedule("continue");return;case u.SUSPEND:this.runState=c.SUSPENDED;return;case u.DONE:this.runState=c.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(){let e=_;for(;e-- >0;){if(this.result!=null)return u.DONE;if(this.interrupted&&this.closing==null)return this.notify({_tag:"Failure",error:{_tag:"Interrupted"}}),u.DONE;let t=k(this.current);switch(t._tag){case "Succeed":{this.onSuccess(t.value);break}case "Fail":{this.onFailure(t.error);break}case "Sync":{try{let r=t.thunk(this.env);this.onSuccess(r);}catch(r){this.onFailure(r);}break}case "FlatMap":{this.stack.push({_tag:"SuccessCont",k:t.andThen}),this.current=t.first;break}case "Fold":{this.stack.push({_tag:"FoldCont",onFailure:t.onFailure,onSuccess:t.onSuccess}),this.current=t.first;break}case "Async":{if(this.finishing)return this.result!=null?u.DONE:u.CONTINUE;let r=false,i=o=>{r||(r=true,!(this.result!=null||this.closing!=null)&&(this.current=o._tag==="Success"?{_tag:"Succeed",value:o.value}:{_tag:"Fail",error:o.error},this.schedule("async-resume")));},s=t.register(this.env,i);return typeof s=="function"&&this.addFinalizer(()=>{r=true;try{s();}catch{}}),u.SUSPEND}}}return this.result!=null?u.DONE:u.CONTINUE}};function V(n){return l((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,h)=>a?s(a):o(h)):n().then(o,s);}catch(a){s(a);}})}function v(n,e,t=b){let r=new f(n,e,t);return r.schedule("initial-step"),r}function W(n,e,t){v(n,e).join(t);}function X(n,e){return new Promise((t,r)=>{v(n,e).join(s=>{let o=s;o._tag==="Success"?t(o.value):r(o.error);});})}function Y(n,e){return l((t,r)=>{n(t).then(i=>r({_tag:"Success",value:i})).catch(i=>r({_tag:"Failure",error:e(i)}));})}function Z(n){return l((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))});}})}function ee(n){return w((t,r)=>n.length===1?n(r):n(t,r),t=>N(t)?{_tag:"Abort"}:{_tag:"PromiseRejected",reason:t})}function w(n,e){return l((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(h=>o({_tag:"Success",value:h})).catch(h=>o({_tag:"Failure",error:e(h)}));}catch(a){o({_tag:"Failure",error:e(a)});}return ()=>{s=true,i.abort();}})}var N=n=>typeof n=="object"&&n!==null&&"name"in n&&n.name==="AbortError";exports.a=E;exports.b=D;exports.c=P;exports.d=T;exports.e=A;exports.f=m;exports.g=S;exports.h=I;exports.i=l;exports.j=C;exports.k=p;exports.l=z;exports.m=U;exports.n=y;exports.o=b;exports.p=f;exports.q=V;exports.r=v;exports.s=W;exports.t=X;exports.u=Y;exports.v=Z;exports.w=ee;exports.x=w;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
function E(n,e,t){return {_tag:"Fold",first:n,onFailure:e,onSuccess:t}}function D(n,e){return E(n,t=>e(t),t=>A(t))}function P(n,e){return E(n,t=>m(e(t)),t=>A(t))}var T=()=>A(void 0),A=n=>({_tag:"Succeed",value:n}),m=n=>({_tag:"Fail",error:n}),S=n=>({_tag:"Sync",thunk:n}),I=n=>S(()=>n()),l=n=>({_tag:"Async",register:n});function C(n,e){return p(n,t=>A(e(t)))}function p(n,e){return {_tag:"FlatMap",first:n,andThen:e}}function z(n,e,t){return p(n,r=>(t.addFinalizer(i=>e(r,i)),A(r)))}function U(n){return l(n)}var d=class{buf;head=0;tail=0;size_=0;constructor(e=1024){let t=Math.max(2,this.nextPow2(e));this.buf=new Array(t);}get length(){return this.size_}get capacity(){return this.buf.length}isEmpty(){return this.size_===0}push(e){this.size_===this.buf.length&&this.grow(),this.buf[this.tail]=e,this.tail=this.tail+1&this.buf.length-1,this.size_++;}shift(){if(this.size_===0)return;let e=this.buf[this.head];return this.buf[this.head]=void 0,this.head=this.head+1&this.buf.length-1,this.size_--,e}clear(){this.buf.fill(void 0),this.head=0,this.tail=0,this.size_=0;}grow(){let e=this.buf,t=new Array(e.length*2);for(let r=0;r<this.size_;r++)t[r]=e[this.head+r&e.length-1];this.buf=t,this.head=0,this.tail=this.size_;}nextPow2(e){let t=1;for(;t<e;)t<<=1;return t}};var g=2048,R=4096,x=(()=>{if(typeof globalThis.setImmediate=="function")return n=>globalThis.setImmediate(n);if(typeof globalThis.MessageChannel=="function"){let n=new globalThis.MessageChannel,e=null;return n.port1.onmessage=()=>{let t=e;e=null,t?.();},t=>{e=t,n.port2.postMessage(0);}}return n=>setTimeout(n,0)})(),y=class{queue=new d(1024);flushing=false;scheduled=false;schedule(e,t="anonymous"){if(typeof e=="function"&&(this.queue.push({tag:t,task:e}),!this.flushing&&!this.scheduled)){this.scheduled=true;let r=this.queue.length>R?"macro":"micro";this.requestFlush(r);}}requestFlush(e){e==="micro"?queueMicrotask(()=>this.flush()):x(()=>this.flush());}flush(){if(this.flushing)return;this.flushing=true,this.scheduled=false;let e=0;try{for(;e<g;){let t=this.queue.shift();if(!t)break;e++;try{t.task();}catch(r){console.error(`[Scheduler] task threw (tag=${t.tag})`,r);}}}finally{if(this.flushing=false,this.queue.length>0&&!this.scheduled){this.scheduled=true;let t=e>=g||this.queue.length>R?"macro":"micro";this.requestFlush(t);}}}},b=new y;var u={CONTINUE:"Continue",SUSPEND:"Suspend",DONE:"Done"},c={QUEUED:"Queued",RUNNING:"Running",SUSPENDED:"Suspended",DONE:"Done"},F=1,_=1024;function k(n){let e=n;for(;e._tag==="FlatMap"&&e.first._tag==="FlatMap";){let t=e.first,r=e.andThen;e={_tag:"FlatMap",first:t.first,andThen:i=>({_tag:"FlatMap",first:t.andThen(i),andThen:r})};}return e}var f=class{constructor(e,t,r){this.scheduler=r;this.id=F++,this.current=e,this.env=t;}id;closing=null;finishing=false;runState=c.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"){this.runState===c.DONE||this.runState===c.QUEUED||(this.runState=c.QUEUED,this.scheduler.schedule(()=>{if(this.runState===c.DONE)return;switch(this.runState=c.RUNNING,this.step()){case u.CONTINUE:this.schedule("continue");return;case u.SUSPEND:this.runState=c.SUSPENDED;return;case u.DONE:this.runState=c.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(){let e=_;for(;e-- >0;){if(this.result!=null)return u.DONE;if(this.interrupted&&this.closing==null)return this.notify({_tag:"Failure",error:{_tag:"Interrupted"}}),u.DONE;let t=k(this.current);switch(t._tag){case "Succeed":{this.onSuccess(t.value);break}case "Fail":{this.onFailure(t.error);break}case "Sync":{try{let r=t.thunk(this.env);this.onSuccess(r);}catch(r){this.onFailure(r);}break}case "FlatMap":{this.stack.push({_tag:"SuccessCont",k:t.andThen}),this.current=t.first;break}case "Fold":{this.stack.push({_tag:"FoldCont",onFailure:t.onFailure,onSuccess:t.onSuccess}),this.current=t.first;break}case "Async":{if(this.finishing)return this.result!=null?u.DONE:u.CONTINUE;let r=false,i=o=>{r||(r=true,!(this.result!=null||this.closing!=null)&&(this.current=o._tag==="Success"?{_tag:"Succeed",value:o.value}:{_tag:"Fail",error:o.error},this.schedule("async-resume")));},s=t.register(this.env,i);return typeof s=="function"&&this.addFinalizer(()=>{r=true;try{s();}catch{}}),u.SUSPEND}}}return this.result!=null?u.DONE:u.CONTINUE}};function V(n){return l((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,h)=>a?s(a):o(h)):n().then(o,s);}catch(a){s(a);}})}function v(n,e,t=b){let r=new f(n,e,t);return r.schedule("initial-step"),r}function W(n,e,t){v(n,e).join(t);}function X(n,e){return new Promise((t,r)=>{v(n,e).join(s=>{let o=s;o._tag==="Success"?t(o.value):r(o.error);});})}function Y(n,e){return l((t,r)=>{n(t).then(i=>r({_tag:"Success",value:i})).catch(i=>r({_tag:"Failure",error:e(i)}));})}function Z(n){return l((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))});}})}function ee(n){return w((t,r)=>n.length===1?n(r):n(t,r),t=>N(t)?{_tag:"Abort"}:{_tag:"PromiseRejected",reason:t})}function w(n,e){return l((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(h=>o({_tag:"Success",value:h})).catch(h=>o({_tag:"Failure",error:e(h)}));}catch(a){o({_tag:"Failure",error:e(a)});}return ()=>{s=true,i.abort();}})}var N=n=>typeof n=="object"&&n!==null&&"name"in n&&n.name==="AbortError";export{E as a,D as b,P as c,T as d,A as e,m as f,S as g,I as h,l as i,C as j,p as k,z as l,U as m,y as n,b as o,f as p,V as q,v as r,W as s,X as t,Y as u,Z as v,ee as w,w as x};
|
|
@@ -23,7 +23,7 @@ type Task = () => void;
|
|
|
23
23
|
declare class Scheduler {
|
|
24
24
|
private queue;
|
|
25
25
|
private flushing;
|
|
26
|
-
private
|
|
26
|
+
private scheduled;
|
|
27
27
|
schedule(task: Task, tag?: string): void;
|
|
28
28
|
private requestFlush;
|
|
29
29
|
private flush;
|
|
@@ -71,6 +71,9 @@ declare class RuntimeFiber<R, E, A> implements Fiber<E, A> {
|
|
|
71
71
|
}
|
|
72
72
|
|
|
73
73
|
type ScopeId = number;
|
|
74
|
+
type CloseOptions = {
|
|
75
|
+
awaitChildren?: boolean;
|
|
76
|
+
};
|
|
74
77
|
declare class Scope<R> {
|
|
75
78
|
private readonly env;
|
|
76
79
|
readonly id: ScopeId;
|
|
@@ -86,7 +89,7 @@ declare class Scope<R> {
|
|
|
86
89
|
/** fork en este scope */
|
|
87
90
|
fork<E, A>(eff: Async<R, E, A>, env: R): Fiber<E | Interrupted, A>;
|
|
88
91
|
close(exit?: Exit<any, any>): void;
|
|
89
|
-
|
|
92
|
+
closeAsync(exit?: Exit<any, any>, options?: CloseOptions): Async<R, never, void>;
|
|
90
93
|
}
|
|
91
94
|
/**
|
|
92
95
|
* Ejecuta una función dentro de un scope estructurado.
|
|
@@ -119,7 +122,7 @@ type Async<R, E, A> = {
|
|
|
119
122
|
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>;
|
|
120
123
|
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>;
|
|
121
124
|
declare function asyncMapError<R, E, E2, A>(fa: Async<R, E, A>, f: (e: E) => E2): Async<R, E2, A>;
|
|
122
|
-
declare
|
|
125
|
+
declare const unit: <R>() => Async<R, never, void>;
|
|
123
126
|
declare const asyncSucceed: <A>(value: A) => Async<unknown, never, A>;
|
|
124
127
|
declare const asyncFail: <E>(error: E) => Async<unknown, E, never>;
|
|
125
128
|
declare const asyncSync: <R, A>(thunk: (env: R) => A) => Async<R, unknown, A>;
|
|
@@ -23,7 +23,7 @@ type Task = () => void;
|
|
|
23
23
|
declare class Scheduler {
|
|
24
24
|
private queue;
|
|
25
25
|
private flushing;
|
|
26
|
-
private
|
|
26
|
+
private scheduled;
|
|
27
27
|
schedule(task: Task, tag?: string): void;
|
|
28
28
|
private requestFlush;
|
|
29
29
|
private flush;
|
|
@@ -71,6 +71,9 @@ declare class RuntimeFiber<R, E, A> implements Fiber<E, A> {
|
|
|
71
71
|
}
|
|
72
72
|
|
|
73
73
|
type ScopeId = number;
|
|
74
|
+
type CloseOptions = {
|
|
75
|
+
awaitChildren?: boolean;
|
|
76
|
+
};
|
|
74
77
|
declare class Scope<R> {
|
|
75
78
|
private readonly env;
|
|
76
79
|
readonly id: ScopeId;
|
|
@@ -86,7 +89,7 @@ declare class Scope<R> {
|
|
|
86
89
|
/** fork en este scope */
|
|
87
90
|
fork<E, A>(eff: Async<R, E, A>, env: R): Fiber<E | Interrupted, A>;
|
|
88
91
|
close(exit?: Exit<any, any>): void;
|
|
89
|
-
|
|
92
|
+
closeAsync(exit?: Exit<any, any>, options?: CloseOptions): Async<R, never, void>;
|
|
90
93
|
}
|
|
91
94
|
/**
|
|
92
95
|
* Ejecuta una función dentro de un scope estructurado.
|
|
@@ -119,7 +122,7 @@ type Async<R, E, A> = {
|
|
|
119
122
|
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>;
|
|
120
123
|
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>;
|
|
121
124
|
declare function asyncMapError<R, E, E2, A>(fa: Async<R, E, A>, f: (e: E) => E2): Async<R, E2, A>;
|
|
122
|
-
declare
|
|
125
|
+
declare const unit: <R>() => Async<R, never, void>;
|
|
123
126
|
declare const asyncSucceed: <A>(value: A) => Async<unknown, never, A>;
|
|
124
127
|
declare const asyncFail: <E>(error: E) => Async<unknown, E, never>;
|
|
125
128
|
declare const asyncSync: <R, A>(thunk: (env: R) => A) => Async<R, unknown, A>;
|
package/dist/http/index.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { A as Async } from '../effect-
|
|
1
|
+
import { A as Async } from '../effect-BTR2nIXd.mjs';
|
|
2
2
|
|
|
3
3
|
type HttpError = {
|
|
4
4
|
_tag: "Abort";
|
|
@@ -33,4 +33,63 @@ declare function makeHttp(cfg?: MakeHttpConfig): HttpClient;
|
|
|
33
33
|
declare const mapAsync: <R, E, A, B>(fa: Async<R, E, A>, f: (a: A) => B) => Async<R, E, B>;
|
|
34
34
|
declare const mapTryAsync: <R, E, A, B>(fa: Async<R, E, A>, f: (a: A) => B) => Async<R, E, B>;
|
|
35
35
|
|
|
36
|
-
|
|
36
|
+
/**
|
|
37
|
+
* “Contenido” (sin meta). Esto es lo que querés que sea el default.
|
|
38
|
+
*/
|
|
39
|
+
type HttpResponse<A> = {
|
|
40
|
+
status: number;
|
|
41
|
+
headers: Record<string, string>;
|
|
42
|
+
body: A;
|
|
43
|
+
};
|
|
44
|
+
/**
|
|
45
|
+
* Meta (opcional / inyectable por middleware).
|
|
46
|
+
*/
|
|
47
|
+
type HttpMeta = {
|
|
48
|
+
statusText: string;
|
|
49
|
+
ms: number;
|
|
50
|
+
};
|
|
51
|
+
/**
|
|
52
|
+
* “Contenido + meta” (resultado de aplicar withMeta).
|
|
53
|
+
*/
|
|
54
|
+
type HttpResponseWithMeta<A> = HttpResponse<A> & {
|
|
55
|
+
meta: HttpMeta;
|
|
56
|
+
};
|
|
57
|
+
/**
|
|
58
|
+
* Client “DX” base:
|
|
59
|
+
* - expone wire (request/get/post/postJson)
|
|
60
|
+
* - expone contenido (getText/getJson) SIN meta
|
|
61
|
+
*/
|
|
62
|
+
type HttpClientDx = {
|
|
63
|
+
request: (req: HttpRequest) => Async<unknown, HttpError, HttpWireResponse>;
|
|
64
|
+
get: (url: string, init?: Omit<RequestInit, "method">) => Async<unknown, HttpError, HttpWireResponse>;
|
|
65
|
+
post: (url: string, body?: string, init?: Omit<RequestInit, "method" | "body">) => Async<unknown, HttpError, HttpWireResponse>;
|
|
66
|
+
postJson: <A extends object>(url: string, body: A, init?: Omit<RequestInit, "method" | "body">) => Async<unknown, HttpError, HttpWireResponse>;
|
|
67
|
+
getText: (url: string, init?: Omit<RequestInit, "method">) => Async<unknown, HttpError, HttpResponse<string>>;
|
|
68
|
+
getJson: <A>(url: string, init?: Omit<RequestInit, "method">) => Async<unknown, HttpError, HttpResponse<A>>;
|
|
69
|
+
};
|
|
70
|
+
/**
|
|
71
|
+
* Client “DX” con meta:
|
|
72
|
+
* misma API, pero getText/getJson devuelven HttpResponseWithMeta.
|
|
73
|
+
*/
|
|
74
|
+
type HttpClientDxWithMeta = Omit<HttpClientDx, "getText" | "getJson"> & {
|
|
75
|
+
getText: (url: string, init?: Omit<RequestInit, "method">) => Async<unknown, HttpError, HttpResponseWithMeta<string>>;
|
|
76
|
+
getJson: <A>(url: string, init?: Omit<RequestInit, "method">) => Async<unknown, HttpError, HttpResponseWithMeta<A>>;
|
|
77
|
+
};
|
|
78
|
+
/**
|
|
79
|
+
* Builder base: por default NO mete meta.
|
|
80
|
+
* Internamente crea makeHttp(cfg) y te expone una API usable.
|
|
81
|
+
*/
|
|
82
|
+
declare function httpClient(cfg?: MakeHttpConfig): HttpClientDx;
|
|
83
|
+
/**
|
|
84
|
+
* Middleware “zio-like”: recibe un client base y devuelve uno “enriquecido”.
|
|
85
|
+
* Nota: NO toca el wire; sólo cambia cómo “renderizás” contenido.
|
|
86
|
+
*/
|
|
87
|
+
declare function withMeta(client: HttpClientDx): HttpClientDxWithMeta;
|
|
88
|
+
/**
|
|
89
|
+
* Convenience: “todo transparente”
|
|
90
|
+
* - crea el client base
|
|
91
|
+
* - le aplica withMeta
|
|
92
|
+
*/
|
|
93
|
+
declare function httpClientWithMeta(cfg?: MakeHttpConfig): HttpClientDxWithMeta;
|
|
94
|
+
|
|
95
|
+
export { type HttpClient, type HttpClientDx, type HttpClientDxWithMeta, type HttpError, type HttpMeta, type HttpMethod, type HttpRequest, type HttpResponse, type HttpResponseWithMeta, type HttpWireResponse, type MakeHttpConfig, httpClient, httpClientWithMeta, makeHttp, mapAsync, mapTryAsync, withMeta };
|
package/dist/http/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { A as Async } from '../effect-
|
|
1
|
+
import { A as Async } from '../effect-BTR2nIXd.js';
|
|
2
2
|
|
|
3
3
|
type HttpError = {
|
|
4
4
|
_tag: "Abort";
|
|
@@ -33,4 +33,63 @@ declare function makeHttp(cfg?: MakeHttpConfig): HttpClient;
|
|
|
33
33
|
declare const mapAsync: <R, E, A, B>(fa: Async<R, E, A>, f: (a: A) => B) => Async<R, E, B>;
|
|
34
34
|
declare const mapTryAsync: <R, E, A, B>(fa: Async<R, E, A>, f: (a: A) => B) => Async<R, E, B>;
|
|
35
35
|
|
|
36
|
-
|
|
36
|
+
/**
|
|
37
|
+
* “Contenido” (sin meta). Esto es lo que querés que sea el default.
|
|
38
|
+
*/
|
|
39
|
+
type HttpResponse<A> = {
|
|
40
|
+
status: number;
|
|
41
|
+
headers: Record<string, string>;
|
|
42
|
+
body: A;
|
|
43
|
+
};
|
|
44
|
+
/**
|
|
45
|
+
* Meta (opcional / inyectable por middleware).
|
|
46
|
+
*/
|
|
47
|
+
type HttpMeta = {
|
|
48
|
+
statusText: string;
|
|
49
|
+
ms: number;
|
|
50
|
+
};
|
|
51
|
+
/**
|
|
52
|
+
* “Contenido + meta” (resultado de aplicar withMeta).
|
|
53
|
+
*/
|
|
54
|
+
type HttpResponseWithMeta<A> = HttpResponse<A> & {
|
|
55
|
+
meta: HttpMeta;
|
|
56
|
+
};
|
|
57
|
+
/**
|
|
58
|
+
* Client “DX” base:
|
|
59
|
+
* - expone wire (request/get/post/postJson)
|
|
60
|
+
* - expone contenido (getText/getJson) SIN meta
|
|
61
|
+
*/
|
|
62
|
+
type HttpClientDx = {
|
|
63
|
+
request: (req: HttpRequest) => Async<unknown, HttpError, HttpWireResponse>;
|
|
64
|
+
get: (url: string, init?: Omit<RequestInit, "method">) => Async<unknown, HttpError, HttpWireResponse>;
|
|
65
|
+
post: (url: string, body?: string, init?: Omit<RequestInit, "method" | "body">) => Async<unknown, HttpError, HttpWireResponse>;
|
|
66
|
+
postJson: <A extends object>(url: string, body: A, init?: Omit<RequestInit, "method" | "body">) => Async<unknown, HttpError, HttpWireResponse>;
|
|
67
|
+
getText: (url: string, init?: Omit<RequestInit, "method">) => Async<unknown, HttpError, HttpResponse<string>>;
|
|
68
|
+
getJson: <A>(url: string, init?: Omit<RequestInit, "method">) => Async<unknown, HttpError, HttpResponse<A>>;
|
|
69
|
+
};
|
|
70
|
+
/**
|
|
71
|
+
* Client “DX” con meta:
|
|
72
|
+
* misma API, pero getText/getJson devuelven HttpResponseWithMeta.
|
|
73
|
+
*/
|
|
74
|
+
type HttpClientDxWithMeta = Omit<HttpClientDx, "getText" | "getJson"> & {
|
|
75
|
+
getText: (url: string, init?: Omit<RequestInit, "method">) => Async<unknown, HttpError, HttpResponseWithMeta<string>>;
|
|
76
|
+
getJson: <A>(url: string, init?: Omit<RequestInit, "method">) => Async<unknown, HttpError, HttpResponseWithMeta<A>>;
|
|
77
|
+
};
|
|
78
|
+
/**
|
|
79
|
+
* Builder base: por default NO mete meta.
|
|
80
|
+
* Internamente crea makeHttp(cfg) y te expone una API usable.
|
|
81
|
+
*/
|
|
82
|
+
declare function httpClient(cfg?: MakeHttpConfig): HttpClientDx;
|
|
83
|
+
/**
|
|
84
|
+
* Middleware “zio-like”: recibe un client base y devuelve uno “enriquecido”.
|
|
85
|
+
* Nota: NO toca el wire; sólo cambia cómo “renderizás” contenido.
|
|
86
|
+
*/
|
|
87
|
+
declare function withMeta(client: HttpClientDx): HttpClientDxWithMeta;
|
|
88
|
+
/**
|
|
89
|
+
* Convenience: “todo transparente”
|
|
90
|
+
* - crea el client base
|
|
91
|
+
* - le aplica withMeta
|
|
92
|
+
*/
|
|
93
|
+
declare function httpClientWithMeta(cfg?: MakeHttpConfig): HttpClientDxWithMeta;
|
|
94
|
+
|
|
95
|
+
export { type HttpClient, type HttpClientDx, type HttpClientDxWithMeta, type HttpError, type HttpMeta, type HttpMethod, type HttpRequest, type HttpResponse, type HttpResponseWithMeta, type HttpWireResponse, type MakeHttpConfig, httpClient, httpClientWithMeta, makeHttp, mapAsync, mapTryAsync, withMeta };
|
package/dist/http/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
'use strict';var
|
|
1
|
+
'use strict';var chunkBQ3I6L5Z_js=require('../chunk-BQ3I6L5Z.js');var x=t=>t instanceof DOMException&&t.name==="AbortError"?{_tag:"Abort"}:typeof t=="object"&&t&&"_tag"in t?t:{_tag:"FetchError",message:String(t)};function R(t={}){let o=t.baseUrl??"",r=t.headers??{};return e=>chunkBQ3I6L5Z_js.x(async i=>{let u;try{u=new URL(e.url,o);}catch{throw {_tag:"BadUrl",message:`URL inv\xE1lida: ${e.url}`}}let H=performance.now(),a=await fetch(u,{...e.init??{},method:e.method,headers:{...r,...e.headers??{}},body:e.body,signal:i}),n=await a.text(),s={};return a.headers.forEach((p,A)=>s[A]=p),{status:a.status,statusText:a.statusText,headers:s,bodyText:n,ms:Math.round(performance.now()-H)}},x)}var m=(t,o)=>chunkBQ3I6L5Z_js.k(t,r=>chunkBQ3I6L5Z_js.e(o(r))),g=(t,o)=>chunkBQ3I6L5Z_js.k(t,r=>chunkBQ3I6L5Z_js.g(()=>o(r)));var b=t=>({status:t.status,headers:t.headers,body:t.bodyText}),E=t=>({status:t.status,headers:t.headers,body:JSON.parse(t.bodyText)}),T=t=>({status:t.status,headers:t.headers,body:t.bodyText,meta:{statusText:t.statusText,ms:t.ms}}),l=t=>({status:t.status,headers:t.headers,body:JSON.parse(t.bodyText),meta:{statusText:t.statusText,ms:t.ms}});function f(t={}){let o=R(t),r=n=>o(n),e=(n,s)=>r({method:"GET",url:n,init:s});return {request:r,get:e,post:(n,s,p)=>r({method:"POST",url:n,body:s&&s.length>0?s:void 0,init:p}),postJson:(n,s,p)=>r({method:"POST",url:n,body:JSON.stringify(s),headers:{"content-type":"application/json",...p?.headers},init:{...p??{}}}),getText:(n,s)=>m(e(n,s),b),getJson:(n,s)=>g(e(n,s),E)}}function O(t){let o=(e,i)=>m(t.get(e,i),T),r=(e,i)=>g(t.get(e,i),l);return {request:t.request,get:t.get,post:t.post,postJson:t.postJson,getText:o,getJson:r}}function B(t={}){return O(f(t))}exports.httpClient=f;exports.httpClientWithMeta=B;exports.makeHttp=R;exports.mapAsync=m;exports.mapTryAsync=g;exports.withMeta=O;
|
package/dist/http/index.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import {k,x as x$1,e,g}from'../chunk-
|
|
1
|
+
import {k,x as x$1,e,g as g$1}from'../chunk-SMCQ6GGV.mjs';var x=t=>t instanceof DOMException&&t.name==="AbortError"?{_tag:"Abort"}:typeof t=="object"&&t&&"_tag"in t?t:{_tag:"FetchError",message:String(t)};function R(t={}){let o=t.baseUrl??"",r=t.headers??{};return e=>x$1(async i=>{let u;try{u=new URL(e.url,o);}catch{throw {_tag:"BadUrl",message:`URL inv\xE1lida: ${e.url}`}}let H=performance.now(),a=await fetch(u,{...e.init??{},method:e.method,headers:{...r,...e.headers??{}},body:e.body,signal:i}),n=await a.text(),s={};return a.headers.forEach((p,A)=>s[A]=p),{status:a.status,statusText:a.statusText,headers:s,bodyText:n,ms:Math.round(performance.now()-H)}},x)}var m=(t,o)=>k(t,r=>e(o(r))),g=(t,o)=>k(t,r=>g$1(()=>o(r)));var b=t=>({status:t.status,headers:t.headers,body:t.bodyText}),E=t=>({status:t.status,headers:t.headers,body:JSON.parse(t.bodyText)}),T=t=>({status:t.status,headers:t.headers,body:t.bodyText,meta:{statusText:t.statusText,ms:t.ms}}),l=t=>({status:t.status,headers:t.headers,body:JSON.parse(t.bodyText),meta:{statusText:t.statusText,ms:t.ms}});function f(t={}){let o=R(t),r=n=>o(n),e=(n,s)=>r({method:"GET",url:n,init:s});return {request:r,get:e,post:(n,s,p)=>r({method:"POST",url:n,body:s&&s.length>0?s:void 0,init:p}),postJson:(n,s,p)=>r({method:"POST",url:n,body:JSON.stringify(s),headers:{"content-type":"application/json",...p?.headers},init:{...p??{}}}),getText:(n,s)=>m(e(n,s),b),getJson:(n,s)=>g(e(n,s),E)}}function O(t){let o=(e,i)=>m(t.get(e,i),T),r=(e,i)=>g(t.get(e,i),l);return {request:t.request,get:t.get,post:t.post,postJson:t.postJson,getText:o,getJson:r}}function B(t={}){return O(f(t))}export{f as httpClient,B as httpClientWithMeta,R as makeHttp,m as mapAsync,g as mapTryAsync,O as withMeta};
|
package/dist/index.d.mts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { Z as ZIO, O as Option, E as Exit, A as Async, S as Scheduler, F as Fiber, I as Interrupted } from './effect-
|
|
2
|
-
export { z as CancelToken, C as Canceler, G as FiberId, H as FiberStatus, N as None, R as RuntimeFiber, K as Scope, J as ScopeId, w as Some, T as Task, 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, M as globalScheduler, D as linkAbortController, B as makeCancelToken, m as map, c as mapError, x as none, o as orElseOptional, y as some, s as succeed, a as sync, u as unit, L as withScope } from './effect-
|
|
1
|
+
import { Z as ZIO, O as Option, E as Exit, A as Async, S as Scheduler, F as Fiber, I as Interrupted } from './effect-BTR2nIXd.mjs';
|
|
2
|
+
export { z as CancelToken, C as Canceler, G as FiberId, H as FiberStatus, N as None, R as RuntimeFiber, K as Scope, J as ScopeId, w as Some, T as Task, 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, M as globalScheduler, D as linkAbortController, B as makeCancelToken, m as map, c as mapError, x as none, o as orElseOptional, y as some, s as succeed, a as sync, u as unit, L as withScope } from './effect-BTR2nIXd.mjs';
|
|
3
3
|
|
|
4
4
|
type Empty<R, E, A> = {
|
|
5
5
|
readonly _tag: "Empty";
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { Z as ZIO, O as Option, E as Exit, A as Async, S as Scheduler, F as Fiber, I as Interrupted } from './effect-
|
|
2
|
-
export { z as CancelToken, C as Canceler, G as FiberId, H as FiberStatus, N as None, R as RuntimeFiber, K as Scope, J as ScopeId, w as Some, T as Task, 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, M as globalScheduler, D as linkAbortController, B as makeCancelToken, m as map, c as mapError, x as none, o as orElseOptional, y as some, s as succeed, a as sync, u as unit, L as withScope } from './effect-
|
|
1
|
+
import { Z as ZIO, O as Option, E as Exit, A as Async, S as Scheduler, F as Fiber, I as Interrupted } from './effect-BTR2nIXd.js';
|
|
2
|
+
export { z as CancelToken, C as Canceler, G as FiberId, H as FiberStatus, N as None, R as RuntimeFiber, K as Scope, J as ScopeId, w as Some, T as Task, 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, M as globalScheduler, D as linkAbortController, B as makeCancelToken, m as map, c as mapError, x as none, o as orElseOptional, y as some, s as succeed, a as sync, u as unit, L as withScope } from './effect-BTR2nIXd.js';
|
|
3
3
|
|
|
4
4
|
type Empty<R, E, A> = {
|
|
5
5
|
readonly _tag: "Empty";
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
'use strict';var
|
|
1
|
+
'use strict';var chunkBQ3I6L5Z_js=require('./chunk-BQ3I6L5Z.js');var Z={_tag:"None"},I=e=>({_tag:"Some",value:e});var k=e=>chunkBQ3I6L5Z_js.e(e),b=e=>chunkBQ3I6L5Z_js.f(e),pe=e=>chunkBQ3I6L5Z_js.g(t=>e(t)),g=(e,t)=>chunkBQ3I6L5Z_js.j(e,t),L=(e,t)=>chunkBQ3I6L5Z_js.k(e,r=>t(r)),C=(e,t)=>chunkBQ3I6L5Z_js.c(e,t),ue=(e,t)=>chunkBQ3I6L5Z_js.a(e,r=>t(r),r=>chunkBQ3I6L5Z_js.e(r));function j(e,t){return chunkBQ3I6L5Z_js.a(e,r=>r._tag==="Some"?chunkBQ3I6L5Z_js.f(r):t(),r=>chunkBQ3I6L5Z_js.e(r))}var Ae=()=>b(Z);function ye(){let e=false,t=new Set;return {isCancelled:()=>e,onCancel:n=>{if(e){try{n();}catch{}return ()=>{}}return t.add(n),()=>{t.delete(n);}},cancel:()=>{e||(e=true,t.forEach(n=>n()),t.clear());}}}function me(e,t){return e.onCancel(()=>t.abort())}var D=1;function G(e){return chunkBQ3I6L5Z_js.i((t,r)=>{let n=e.length;if(n===0){r({_tag:"Success",value:void 0});return}for(let o of e)o.join(()=>{n-=1,n===0&&r({_tag:"Success",value:void 0});});})}function J(e){return chunkBQ3I6L5Z_js.a(e,()=>chunkBQ3I6L5Z_js.d,()=>chunkBQ3I6L5Z_js.d)}var x=class e{constructor(t){this.env=t;this.id=D++;}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,r){if(this.closed)throw new Error("Scope closed");let n=chunkBQ3I6L5Z_js.r(t,r);return this.children.add(n),n.join(()=>{this.children.delete(n);}),n}close(t={_tag:"Success",value:void 0}){chunkBQ3I6L5Z_js.r(this.closeAsync(t),this.env);}closeAsync(t={_tag:"Success",value:void 0},r={}){return chunkBQ3I6L5Z_js.i((n,o)=>{if(this.closed){o({_tag:"Success",value:void 0});return}this.closed=true;let a=Array.from(this.children),i=Array.from(this.subScopes);this.children.clear(),this.subScopes.clear();for(let l of a)try{l.interrupt();}catch{}let c=chunkBQ3I6L5Z_js.d();for(let l of i)c=chunkBQ3I6L5Z_js.k(c,()=>l.closeAsync(t,r));for(;this.finalizers.length>0;){let l=this.finalizers.pop();c=chunkBQ3I6L5Z_js.k(c,()=>J(l(t)));}r.awaitChildren&&(c=chunkBQ3I6L5Z_js.k(c,()=>G(a))),chunkBQ3I6L5Z_js.r(c,this.env).join(()=>o({_tag:"Success",value:void 0}));})}};function ge(e){let t=new x({});try{return e(t)}finally{t.close();}}function W(e,t,r,n,o){return chunkBQ3I6L5Z_js.i((a,i)=>{let c=r.subScope(),E=false,l=c.fork(e,a),S=c.fork(t,a),d=y=>{c.fork(y,a).join(O=>{c.close(O),i(O);});};l.join(y=>{E||(E=true,d(n(y,S,c)));}),S.join(y=>{E||(E=true,d(o(y,l,c)));});})}var M=e=>e._tag==="None"?Z:I(e.value),h=e=>({_tag:"FromPull",pull:e}),Pe=(e,t)=>({_tag:"Scoped",acquire:e,release:t}),ze=e=>({_tag:"Scoped",acquire:chunkBQ3I6L5Z_js.k(e,t=>chunkBQ3I6L5Z_js.e(t.stream)),release:t=>chunkBQ3I6L5Z_js.k(e,r=>r.release(t))}),Ne=(e,t,r=true)=>({_tag:"Merge",left:e,right:t,flip:r}),z=()=>({_tag:"Empty"}),q=e=>({_tag:"Emit",value:e}),w=(e,t)=>({_tag:"Concat",left:e,right:t}),P=e=>({_tag:"Flatten",stream:e});function H(e,t,r,n,o){return (a,i,c)=>{if(a._tag,a._tag,a._tag==="Success"){let[S,d]=a.value;i.interrupt();let y=h(e==="L"?B(d,r):B(t,d));return chunkBQ3I6L5Z_js.e([S,y])}let E=a.error;if(typeof E=="object"&&E!==null&&E._tag==="Interrupted")return chunkBQ3I6L5Z_js.f(E);let l=E;return l._tag==="None"?s(e==="L"?r:t):chunkBQ3I6L5Z_js.f(l)}}function B(e,t,r,n){return chunkBQ3I6L5Z_js.i((o,a)=>{let c=new x(o),E=s(e),l=s(t),S=H("L",e,t),d=H("R",e,t),y=W(E,l,c,S,d);c.fork(y,o).join(O=>{c.close(O),a(O);});})}function Te(e,t){return h(B(e,t))}function s(e){switch(e._tag){case "Empty":return b(Z);case "Emit":return g(C(e.value,t=>I(t)),t=>[t,z()]);case "FromPull":return e.pull;case "Concat":return j(g(s(e.left),([t,r])=>[t,w(r,e.right)]),()=>s(e.right));case "Flatten":return L(s(e.stream),([t,r])=>j(g(s(t),([n,o])=>[n,w(o,P(r))]),()=>s(P(r))));case "Merge":return B(e.left,e.right,e.flip);case "Scoped":return chunkBQ3I6L5Z_js.i((t,r)=>{let n=new x(t);n.addFinalizer(o=>e.release(o)),n.fork(e.acquire,t).join(o=>{if(o._tag==="Failure"){n.close(o),r({_tag:"Failure",error:I(o.error)});return}let a=o.value;s(a)(t,c=>{n.close(c),r(c);});});})}}function v(e,t){switch(e._tag){case "Empty":return z();case "Emit":return q(g(e.value,t));case "FromPull":return h(g(e.pull,([r,n])=>[t(r),v(n,t)]));case "Concat":return w(v(e.left,t),v(e.right,t));case "Flatten":{let r=v(e.stream,n=>v(n,t));return P(r)}}}function Le(e,t){let r=n=>h(n>t?chunkBQ3I6L5Z_js.f(Z):chunkBQ3I6L5Z_js.e([n,r(n+1)]));return r(e)}function K(e,t){let r=chunkBQ3I6L5Z_js.a(chunkBQ3I6L5Z_js.c(s(e),n=>M(n)),n=>chunkBQ3I6L5Z_js.f(n),([n,o])=>chunkBQ3I6L5Z_js.a(chunkBQ3I6L5Z_js.c(s(t),a=>M(a)),a=>chunkBQ3I6L5Z_js.f(a),([a,i])=>chunkBQ3I6L5Z_js.e([[n,a],K(o,i)])));return h(r)}function We(e,t){let r=n=>chunkBQ3I6L5Z_js.a(chunkBQ3I6L5Z_js.c(s(n),o=>M(o)),o=>o._tag==="None"?chunkBQ3I6L5Z_js.e(void 0):chunkBQ3I6L5Z_js.f(o),([o,a])=>chunkBQ3I6L5Z_js.k(chunkBQ3I6L5Z_js.c(t(o),i=>I(i)),()=>r(a)));return chunkBQ3I6L5Z_js.a(r(e),n=>n._tag==="None"?chunkBQ3I6L5Z_js.e(void 0):chunkBQ3I6L5Z_js.f(n.value),()=>chunkBQ3I6L5Z_js.e(void 0))}function He(e){let t=z();for(let r=e.length-1;r>=0;r--){let n=q(k(e[r]));t=w(n,t);}return t}function qe(e){let t=(r,n)=>chunkBQ3I6L5Z_js.a(s(r),o=>o._tag==="None"?k(n):b(o),([o,a])=>t(a,[...n,o]));return C(t(e,[]),r=>{if(r._tag==="Some")return r.value;throw new Error("unreachable: stream end handled as success")})}Object.defineProperty(exports,"RuntimeFiber",{enumerable:true,get:function(){return chunkBQ3I6L5Z_js.p}});Object.defineProperty(exports,"Scheduler",{enumerable:true,get:function(){return chunkBQ3I6L5Z_js.n}});Object.defineProperty(exports,"acquireRelease",{enumerable:true,get:function(){return chunkBQ3I6L5Z_js.l}});Object.defineProperty(exports,"async",{enumerable:true,get:function(){return chunkBQ3I6L5Z_js.i}});Object.defineProperty(exports,"asyncCatchAll",{enumerable:true,get:function(){return chunkBQ3I6L5Z_js.b}});Object.defineProperty(exports,"asyncFail",{enumerable:true,get:function(){return chunkBQ3I6L5Z_js.f}});Object.defineProperty(exports,"asyncFlatMap",{enumerable:true,get:function(){return chunkBQ3I6L5Z_js.k}});Object.defineProperty(exports,"asyncFold",{enumerable:true,get:function(){return chunkBQ3I6L5Z_js.a}});Object.defineProperty(exports,"asyncInterruptible",{enumerable:true,get:function(){return chunkBQ3I6L5Z_js.m}});Object.defineProperty(exports,"asyncMap",{enumerable:true,get:function(){return chunkBQ3I6L5Z_js.j}});Object.defineProperty(exports,"asyncMapError",{enumerable:true,get:function(){return chunkBQ3I6L5Z_js.c}});Object.defineProperty(exports,"asyncSucceed",{enumerable:true,get:function(){return chunkBQ3I6L5Z_js.e}});Object.defineProperty(exports,"asyncSync",{enumerable:true,get:function(){return chunkBQ3I6L5Z_js.g}});Object.defineProperty(exports,"asyncTotal",{enumerable:true,get:function(){return chunkBQ3I6L5Z_js.h}});Object.defineProperty(exports,"fork",{enumerable:true,get:function(){return chunkBQ3I6L5Z_js.r}});Object.defineProperty(exports,"from",{enumerable:true,get:function(){return chunkBQ3I6L5Z_js.q}});Object.defineProperty(exports,"fromCallback",{enumerable:true,get:function(){return chunkBQ3I6L5Z_js.v}});Object.defineProperty(exports,"fromPromise",{enumerable:true,get:function(){return chunkBQ3I6L5Z_js.u}});Object.defineProperty(exports,"fromPromiseAbortable",{enumerable:true,get:function(){return chunkBQ3I6L5Z_js.x}});Object.defineProperty(exports,"globalScheduler",{enumerable:true,get:function(){return chunkBQ3I6L5Z_js.o}});Object.defineProperty(exports,"toPromise",{enumerable:true,get:function(){return chunkBQ3I6L5Z_js.t}});Object.defineProperty(exports,"tryPromiseAbortable",{enumerable:true,get:function(){return chunkBQ3I6L5Z_js.w}});Object.defineProperty(exports,"unit",{enumerable:true,get:function(){return chunkBQ3I6L5Z_js.d}});Object.defineProperty(exports,"unsafeRunAsync",{enumerable:true,get:function(){return chunkBQ3I6L5Z_js.s}});exports.Scope=x;exports.catchAll=ue;exports.collectStream=qe;exports.concatStream=w;exports.emitStream=q;exports.emptyStream=z;exports.end=Ae;exports.fail=b;exports.flatMap=L;exports.flattenStream=P;exports.foreachStream=We;exports.fromArray=He;exports.fromPull=h;exports.linkAbortController=me;exports.makeCancelToken=ye;exports.managedStream=ze;exports.map=g;exports.mapError=C;exports.mapStream=v;exports.merge=Te;exports.mergeStream=Ne;exports.none=Z;exports.orElseOptional=j;exports.rangeStream=Le;exports.some=I;exports.succeed=k;exports.sync=pe;exports.uncons=s;exports.unwrapScoped=Pe;exports.withScope=ge;exports.zip=K;
|
package/dist/index.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import {a,f,k as k$1,j,c,e,g as g$1,r,i}from'./chunk-
|
|
1
|
+
import {a,f,k as k$1,j as j$1,c,e,g as g$1,r,i,d}from'./chunk-SMCQ6GGV.mjs';export{p as RuntimeFiber,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,r as fork,q as from,v as fromCallback,u as fromPromise,x as fromPromiseAbortable,o as globalScheduler,t as toPromise,w as tryPromiseAbortable,d as unit,s as unsafeRunAsync}from'./chunk-SMCQ6GGV.mjs';var Z={_tag:"None"},I=e=>({_tag:"Some",value:e});var k=e$1=>e(e$1),b=e=>f(e),pe=e=>g$1(t=>e(t)),g=(e,t)=>j$1(e,t),L=(e,t)=>k$1(e,r=>t(r)),C=(e,t)=>c(e,t),ue=(e$1,t)=>a(e$1,r=>t(r),r=>e(r));function j(e$1,t){return a(e$1,r=>r._tag==="Some"?f(r):t(),r=>e(r))}var Ae=()=>b(Z);function ye(){let e=false,t=new Set;return {isCancelled:()=>e,onCancel:n=>{if(e){try{n();}catch{}return ()=>{}}return t.add(n),()=>{t.delete(n);}},cancel:()=>{e||(e=true,t.forEach(n=>n()),t.clear());}}}function me(e,t){return e.onCancel(()=>t.abort())}var D=1;function G(e){return i((t,r)=>{let n=e.length;if(n===0){r({_tag:"Success",value:void 0});return}for(let o of e)o.join(()=>{n-=1,n===0&&r({_tag:"Success",value:void 0});});})}function J(e){return a(e,()=>d,()=>d)}var x=class e{constructor(t){this.env=t;this.id=D++;}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,r$1){if(this.closed)throw new Error("Scope closed");let n=r(t,r$1);return this.children.add(n),n.join(()=>{this.children.delete(n);}),n}close(t={_tag:"Success",value:void 0}){r(this.closeAsync(t),this.env);}closeAsync(t={_tag:"Success",value:void 0},r$1={}){return i((n,o)=>{if(this.closed){o({_tag:"Success",value:void 0});return}this.closed=true;let a=Array.from(this.children),i=Array.from(this.subScopes);this.children.clear(),this.subScopes.clear();for(let l of a)try{l.interrupt();}catch{}let c=d();for(let l of i)c=k$1(c,()=>l.closeAsync(t,r$1));for(;this.finalizers.length>0;){let l=this.finalizers.pop();c=k$1(c,()=>J(l(t)));}r$1.awaitChildren&&(c=k$1(c,()=>G(a))),r(c,this.env).join(()=>o({_tag:"Success",value:void 0}));})}};function ge(e){let t=new x({});try{return e(t)}finally{t.close();}}function W(e,t,r,n,o){return i((a,i)=>{let c=r.subScope(),E=false,l=c.fork(e,a),S=c.fork(t,a),d=y=>{c.fork(y,a).join(O=>{c.close(O),i(O);});};l.join(y=>{E||(E=true,d(n(y,S,c)));}),S.join(y=>{E||(E=true,d(o(y,l,c)));});})}var M=e=>e._tag==="None"?Z:I(e.value),h=e=>({_tag:"FromPull",pull:e}),Pe=(e,t)=>({_tag:"Scoped",acquire:e,release:t}),ze=e$1=>({_tag:"Scoped",acquire:k$1(e$1,t=>e(t.stream)),release:t=>k$1(e$1,r=>r.release(t))}),Ne=(e,t,r=true)=>({_tag:"Merge",left:e,right:t,flip:r}),z=()=>({_tag:"Empty"}),q=e=>({_tag:"Emit",value:e}),w=(e,t)=>({_tag:"Concat",left:e,right:t}),P=e=>({_tag:"Flatten",stream:e});function H(e$1,t,r,n,o){return (a,i,c)=>{if(a._tag,a._tag,a._tag==="Success"){let[S,d]=a.value;i.interrupt();let y=h(e$1==="L"?B(d,r):B(t,d));return e([S,y])}let E=a.error;if(typeof E=="object"&&E!==null&&E._tag==="Interrupted")return f(E);let l=E;return l._tag==="None"?s(e$1==="L"?r:t):f(l)}}function B(e,t,r,n){return i((o,a)=>{let c=new x(o),E=s(e),l=s(t),S=H("L",e,t),d=H("R",e,t),y=W(E,l,c,S,d);c.fork(y,o).join(O=>{c.close(O),a(O);});})}function Te(e,t){return h(B(e,t))}function s(e){switch(e._tag){case "Empty":return b(Z);case "Emit":return g(C(e.value,t=>I(t)),t=>[t,z()]);case "FromPull":return e.pull;case "Concat":return j(g(s(e.left),([t,r])=>[t,w(r,e.right)]),()=>s(e.right));case "Flatten":return L(s(e.stream),([t,r])=>j(g(s(t),([n,o])=>[n,w(o,P(r))]),()=>s(P(r))));case "Merge":return B(e.left,e.right,e.flip);case "Scoped":return i((t,r)=>{let n=new x(t);n.addFinalizer(o=>e.release(o)),n.fork(e.acquire,t).join(o=>{if(o._tag==="Failure"){n.close(o),r({_tag:"Failure",error:I(o.error)});return}let a=o.value;s(a)(t,c=>{n.close(c),r(c);});});})}}function v(e,t){switch(e._tag){case "Empty":return z();case "Emit":return q(g(e.value,t));case "FromPull":return h(g(e.pull,([r,n])=>[t(r),v(n,t)]));case "Concat":return w(v(e.left,t),v(e.right,t));case "Flatten":{let r=v(e.stream,n=>v(n,t));return P(r)}}}function Le(e$1,t){let r=n=>h(n>t?f(Z):e([n,r(n+1)]));return r(e$1)}function K(e$1,t){let r=a(c(s(e$1),n=>M(n)),n=>f(n),([n,o])=>a(c(s(t),a=>M(a)),a=>f(a),([a,i])=>e([[n,a],K(o,i)])));return h(r)}function We(e$1,t){let r=n=>a(c(s(n),o=>M(o)),o=>o._tag==="None"?e(void 0):f(o),([o,a])=>k$1(c(t(o),i=>I(i)),()=>r(a)));return a(r(e$1),n=>n._tag==="None"?e(void 0):f(n.value),()=>e(void 0))}function He(e){let t=z();for(let r=e.length-1;r>=0;r--){let n=q(k(e[r]));t=w(n,t);}return t}function qe(e){let t=(r,n)=>a(s(r),o=>o._tag==="None"?k(n):b(o),([o,a])=>t(a,[...n,o]));return C(t(e,[]),r=>{if(r._tag==="Some")return r.value;throw new Error("unreachable: stream end handled as success")})}export{x as Scope,ue as catchAll,qe as collectStream,w as concatStream,q as emitStream,z as emptyStream,Ae as end,b as fail,L as flatMap,P as flattenStream,We as foreachStream,He as fromArray,h as fromPull,me as linkAbortController,ye as makeCancelToken,ze as managedStream,g as map,C as mapError,v as mapStream,Te as merge,Ne as mergeStream,Z as none,j as orElseOptional,Le as rangeStream,I as some,k as succeed,pe as sync,s as uncons,Pe as unwrapScoped,ge as withScope,K as zip};
|
package/package.json
CHANGED
package/dist/chunk-JKG47VM5.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
'use strict';function p(n,e,t){return {_tag:"Fold",first:n,onFailure:e,onSuccess:t}}function x(n,e){return p(n,t=>e(t),t=>d(t))}function F(n,e){return p(n,t=>S(e(t)),t=>d(t))}function k(){return y(()=>{})}var d=n=>({_tag:"Succeed",value:n}),S=n=>({_tag:"Fail",error:n}),y=n=>({_tag:"Sync",thunk:n}),_=n=>y(()=>n()),l=n=>({_tag:"Async",register:n});function N(n,e){return E(n,t=>d(e(t)))}function E(n,e){return {_tag:"FlatMap",first:n,andThen:e}}function q(n,e,t){return E(n,r=>(t.addFinalizer(o=>e(r,o)),d(r)))}function w(n){return l(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 u={CONTINUE:"Continue",SUSPEND:"Suspend",DONE:"Done"},c={QUEUED:"Queued",RUNNING:"Running",SUSPENDED:"Suspended",DONE:"Done"},R=1,A=class{constructor(e,t,r){this.scheduler=r;this.id=R++,this.current=e,this.env=t;}id;closing=null;finishing=false;runState=c.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===c.DONE||this.runState===c.QUEUED)&&(this.runState=c.QUEUED,this.scheduler.schedule(()=>{if(console.log("[fiber.task] running",this.id),this.runState===c.DONE)return;switch(this.runState=c.RUNNING,this.step()){case u.CONTINUE:this.schedule("continue");return;case u.SUSPEND:this.runState=c.SUSPENDED;return;case u.DONE:this.runState=c.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=u.CONTINUE;if(this.result!=null)return e=u.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=u.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,i=s=>{r||(r=true,this.scheduler.schedule(()=>{this.result!=null||this.closing!=null||(this.current=s._tag==="Success"?{_tag:"Succeed",value:s.value}:{_tag:"Fail",error:s.error},this.schedule("async-resume"));},`fiber#${this.id}.async-wakeup`));},a=t.register(this.env,i);typeof a=="function"&&this.addFinalizer(()=>{r=true;try{a();}catch{}}),e=u.SUSPEND;break}}return this.result!=null&&(e=u.DONE),e}};function M(n){return l((e,t)=>{let r=false,o=s=>{r||(r=true,t(s));},i=s=>o({_tag:"Failure",error:s instanceof Error?s:new Error(String(s))}),a=s=>o({_tag:"Success",value:s});try{typeof n=="function"&&n.length>=1?n((s,h)=>s?i(s):a(h)):n().then(a,i);}catch(s){i(s);}})}function b(n,e,t=g){let r=new A(n,e,t);return r.schedule("initial-step"),r}function Q(n,e,t){b(n,e).join(t);}function G(n,e){return new Promise((t,r)=>{b(n,e).join(i=>{let a=i;a._tag==="Success"?t(a.value):r(a.error);});})}function H(n,e){return l((t,r)=>{n(t).then(o=>r({_tag:"Success",value:o})).catch(o=>r({_tag:"Failure",error:e(o)}));})}function L(n){return l((e,t)=>{let r=false,o=i=>{r||(r=true,t(i));};try{n((i,a)=>{o(i?{_tag:"Failure",error:i}:{_tag:"Success",value:a});});}catch(i){o({_tag:"Failure",error:i instanceof Error?i:new Error(String(i))});}})}function $(n){return v((t,r)=>n.length===1?n(r):n(t,r),t=>m(t)?{_tag:"Abort"}:{_tag:"PromiseRejected",reason:t})}function v(n,e){return l((t,r)=>{let o=new AbortController,i=false,a=s=>{i||(i=true,r(s));};try{(n.length===1?n(o.signal):n(t,o.signal)).then(h=>a({_tag:"Success",value:h})).catch(h=>a({_tag:"Failure",error:e(h)}));}catch(s){a({_tag:"Failure",error:e(s)});}return ()=>{i=true,o.abort();}})}var m=n=>typeof n=="object"&&n!==null&&"name"in n&&n.name==="AbortError";exports.a=p;exports.b=x;exports.c=F;exports.d=k;exports.e=d;exports.f=S;exports.g=y;exports.h=_;exports.i=l;exports.j=N;exports.k=E;exports.l=q;exports.m=w;exports.n=f;exports.o=g;exports.p=A;exports.q=M;exports.r=b;exports.s=Q;exports.t=G;exports.u=H;exports.v=L;exports.w=$;exports.x=v;
|
package/dist/chunk-Z2JVOS2Q.mjs
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
function p(n,e,t){return {_tag:"Fold",first:n,onFailure:e,onSuccess:t}}function x(n,e){return p(n,t=>e(t),t=>d(t))}function F(n,e){return p(n,t=>S(e(t)),t=>d(t))}function k(){return y(()=>{})}var d=n=>({_tag:"Succeed",value:n}),S=n=>({_tag:"Fail",error:n}),y=n=>({_tag:"Sync",thunk:n}),_=n=>y(()=>n()),l=n=>({_tag:"Async",register:n});function N(n,e){return E(n,t=>d(e(t)))}function E(n,e){return {_tag:"FlatMap",first:n,andThen:e}}function q(n,e,t){return E(n,r=>(t.addFinalizer(o=>e(r,o)),d(r)))}function w(n){return l(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 u={CONTINUE:"Continue",SUSPEND:"Suspend",DONE:"Done"},c={QUEUED:"Queued",RUNNING:"Running",SUSPENDED:"Suspended",DONE:"Done"},R=1,A=class{constructor(e,t,r){this.scheduler=r;this.id=R++,this.current=e,this.env=t;}id;closing=null;finishing=false;runState=c.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===c.DONE||this.runState===c.QUEUED)&&(this.runState=c.QUEUED,this.scheduler.schedule(()=>{if(console.log("[fiber.task] running",this.id),this.runState===c.DONE)return;switch(this.runState=c.RUNNING,this.step()){case u.CONTINUE:this.schedule("continue");return;case u.SUSPEND:this.runState=c.SUSPENDED;return;case u.DONE:this.runState=c.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=u.CONTINUE;if(this.result!=null)return e=u.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=u.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,i=s=>{r||(r=true,this.scheduler.schedule(()=>{this.result!=null||this.closing!=null||(this.current=s._tag==="Success"?{_tag:"Succeed",value:s.value}:{_tag:"Fail",error:s.error},this.schedule("async-resume"));},`fiber#${this.id}.async-wakeup`));},a=t.register(this.env,i);typeof a=="function"&&this.addFinalizer(()=>{r=true;try{a();}catch{}}),e=u.SUSPEND;break}}return this.result!=null&&(e=u.DONE),e}};function M(n){return l((e,t)=>{let r=false,o=s=>{r||(r=true,t(s));},i=s=>o({_tag:"Failure",error:s instanceof Error?s:new Error(String(s))}),a=s=>o({_tag:"Success",value:s});try{typeof n=="function"&&n.length>=1?n((s,h)=>s?i(s):a(h)):n().then(a,i);}catch(s){i(s);}})}function b(n,e,t=g){let r=new A(n,e,t);return r.schedule("initial-step"),r}function Q(n,e,t){b(n,e).join(t);}function G(n,e){return new Promise((t,r)=>{b(n,e).join(i=>{let a=i;a._tag==="Success"?t(a.value):r(a.error);});})}function H(n,e){return l((t,r)=>{n(t).then(o=>r({_tag:"Success",value:o})).catch(o=>r({_tag:"Failure",error:e(o)}));})}function L(n){return l((e,t)=>{let r=false,o=i=>{r||(r=true,t(i));};try{n((i,a)=>{o(i?{_tag:"Failure",error:i}:{_tag:"Success",value:a});});}catch(i){o({_tag:"Failure",error:i instanceof Error?i:new Error(String(i))});}})}function $(n){return v((t,r)=>n.length===1?n(r):n(t,r),t=>m(t)?{_tag:"Abort"}:{_tag:"PromiseRejected",reason:t})}function v(n,e){return l((t,r)=>{let o=new AbortController,i=false,a=s=>{i||(i=true,r(s));};try{(n.length===1?n(o.signal):n(t,o.signal)).then(h=>a({_tag:"Success",value:h})).catch(h=>a({_tag:"Failure",error:e(h)}));}catch(s){a({_tag:"Failure",error:e(s)});}return ()=>{i=true,o.abort();}})}var m=n=>typeof n=="object"&&n!==null&&"name"in n&&n.name==="AbortError";export{p as a,x as b,F as c,k as d,d as e,S as f,y as g,_ as h,l as i,N as j,E as k,q as l,w as m,f as n,g as o,A as p,M as q,b as r,Q as s,G as t,H as u,L as v,$ as w,v as x};
|