brass-runtime 1.9.0 → 1.9.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-2NVQIUW5.js +1 -0
- package/dist/chunk-JTRM4ZSS.mjs +1 -0
- package/dist/http/index.d.mts +2 -2
- package/dist/http/index.d.ts +2 -2
- package/dist/http/index.js +1 -1
- package/dist/http/index.mjs +1 -1
- package/dist/index.d.mts +139 -3
- package/dist/index.d.ts +139 -3
- package/dist/index.js +1 -1
- package/dist/index.mjs +1 -1
- package/dist/{stream-Byv3iEEs.d.mts → stream-CPScJVP0.d.mts} +1 -1
- package/dist/{stream-Byv3iEEs.d.ts → stream-CPScJVP0.d.ts} +1 -1
- package/package.json +1 -1
- package/dist/chunk-3NPW2C22.js +0 -1
- package/dist/chunk-SNH7DUUJ.mjs +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
'use strict';function R(t,e,n){return {_tag:"Fold",first:t,onFailure:e,onSuccess:n}}function Ae(t,e){return R(t,n=>e(n),n=>A(n))}function x(t,e){return R(t,n=>h(e(n)),n=>A(n))}var w=()=>A(void 0),A=t=>({_tag:"Succeed",value:t}),h=t=>({_tag:"Fail",error:t}),_=t=>({_tag:"Sync",thunk:t}),Ee=t=>_(()=>t()),E=t=>({_tag:"Async",register:t});function W(t,e){return p(t,n=>A(e(n)))}function p(t,e){return {_tag:"FlatMap",first:t,andThen:e}}function pe(t,e,n){return p(t,r=>(n.addFinalizer(a=>e(r,a)),A(r)))}function ye(t){return E(t)}var de=t=>e=>{let n=e;return n.toPromise||(n.toPromise=r=>t(e,r),n.unsafeRunPromise=()=>t(e,{})),n},Re=(t,e)=>p(t,n=>A(e(n))),fe=(t,e)=>p(t,n=>_(()=>e(n)));var b={_tag:"None"},F=t=>({_tag:"Some",value:t});var z=t=>A(t),B=t=>h(t),H=t=>_(e=>t(e)),I=(t,e)=>W(t,e),G=(t,e)=>p(t,n=>e(n)),M=(t,e)=>x(t,e),ve=(t,e)=>R(t,n=>e(n),n=>A(n));function U(t,e){return R(t,n=>n._tag==="Some"?h(n):e(),n=>A(n))}var xe=()=>B(b);var P=class{buf;head=0;tail=0;size_=0;constructor(e=1024){let n=Math.max(2,this.nextPow2(e));this.buf=new Array(n);}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,n=new Array(e.length*2);for(let r=0;r<this.size_;r++)n[r]=e[this.head+r&e.length-1];this.buf=n,this.head=0,this.tail=this.size_;}nextPow2(e){let n=1;for(;n<e;)n<<=1;return n}};var Q=2048,$=4096,Y=(()=>{if(typeof globalThis.setImmediate=="function")return t=>globalThis.setImmediate(t);if(typeof globalThis.MessageChannel=="function"){let t=new globalThis.MessageChannel,e=null;return t.port1.onmessage=()=>{let n=e;e=null,n?.();},n=>{e=n,t.port2.postMessage(0);}}return t=>setTimeout(t,0)})(),j=class{queue=new P(1024);flushing=false;scheduled=false;schedule(e,n="anonymous"){if(typeof e=="function"&&(this.queue.push({tag:n,task:e}),!this.flushing&&!this.scheduled)){this.scheduled=true;let r=this.queue.length>$?"macro":"micro";this.requestFlush(r);}}requestFlush(e){e==="micro"?queueMicrotask(()=>this.flush()):Y(()=>this.flush());}flush(){if(this.flushing)return;this.flushing=true,this.scheduled=false;let e=0;try{for(;e<Q;){let n=this.queue.shift();if(!n)break;e++;try{n.task();}catch(r){console.error(`[Scheduler] task threw (tag=${n.tag})`,r);}}}finally{if(this.flushing=false,this.queue.length>0&&!this.scheduled){this.scheduled=true;let n=e>=Q||this.queue.length>$?"macro":"micro";this.requestFlush(n);}}}},J=new j;var m={CONTINUE:"Continue",SUSPEND:"Suspend",DONE:"Done"},S={QUEUED:"Queued",RUNNING:"Running",SUSPENDED:"Suspended",DONE:"Done"},ee=1,te=1024;function ne(t){let e=t;for(;e._tag==="FlatMap"&&e.first._tag==="FlatMap";){let n=e.first,r=e.andThen;e={_tag:"FlatMap",first:n.first,andThen:a=>({_tag:"FlatMap",first:n.andThen(a),andThen:r})};}return e}var N=class{constructor(e,n,r){this.scheduler=r;this.id=ee++,this.current=e,this.env=n;}id;closing=null;finishing=false;runState=S.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===S.DONE||this.runState===S.QUEUED||(this.runState=S.QUEUED,this.scheduler.schedule(()=>{if(this.runState===S.DONE)return;switch(this.runState=S.RUNNING,this.step()){case m.CONTINUE:this.schedule("continue");return;case m.SUSPEND:this.runState=S.SUSPENDED;return;case m.DONE:this.runState=S.DONE;return}},`fiber#${this.id}.${e}`));}runFinalizersOnce(e){if(!this.finalizersDrained)for(this.finalizersDrained=true;this.fiberFinalizers.length>0;){let n=this.fiberFinalizers.pop();try{n(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 n of this.joiners)n(e);this.joiners.length=0;}}onSuccess(e){let n=this.stack.pop();if(!n){this.notify({_tag:"Success",value:e});return}this.current=n._tag==="SuccessCont"?n.k(e):n.onSuccess(e);}onFailure(e){for(;this.stack.length>0;){let n=this.stack.pop();if(n._tag==="FoldCont"){this.current=n.onFailure(e);return}}this.notify({_tag:"Failure",error:e});}step(){let e=te;for(;e-- >0;){if(this.result!=null)return m.DONE;if(this.interrupted&&this.closing==null)return this.notify({_tag:"Failure",error:{_tag:"Interrupted"}}),m.DONE;let n=ne(this.current);switch(n._tag){case "Succeed":{this.onSuccess(n.value);break}case "Fail":{this.onFailure(n.error);break}case "Sync":{try{let r=n.thunk(this.env);this.onSuccess(r);}catch(r){this.onFailure(r);}break}case "FlatMap":{this.stack.push({_tag:"SuccessCont",k:n.andThen}),this.current=n.first;break}case "Fold":{this.stack.push({_tag:"FoldCont",onFailure:n.onFailure,onSuccess:n.onSuccess}),this.current=n.first;break}case "Async":{if(this.finishing)return this.result!=null?m.DONE:m.CONTINUE;let r=false,a=i=>{r||(r=true,!(this.result!=null||this.closing!=null)&&(this.current=i._tag==="Success"?{_tag:"Succeed",value:i.value}:{_tag:"Fail",error:i.error},this.schedule("async-resume")));},o=n.register(this.env,a);return typeof o=="function"&&this.addFinalizer(()=>{r=true;try{o();}catch{}}),m.SUSPEND}}}return this.result!=null?m.DONE:m.CONTINUE}};function De(t){return E((e,n)=>{let r=false,a=s=>{r||(r=true,n(s));},o=s=>a({_tag:"Failure",error:s instanceof Error?s:new Error(String(s))}),i=s=>a({_tag:"Success",value:s});try{typeof t=="function"&&t.length>=1?t((s,c)=>s?o(s):i(c)):t().then(i,o);}catch(s){o(s);}})}function Z(t,e,n=J){let r=new N(t,e,n);return r.schedule("initial-step"),r}function Te(t,e,n){Z(t,e).join(n);}function ze(t,e){return new Promise((n,r)=>{Z(t,e).join(o=>{let i=o;i._tag==="Success"?n(i.value):r(i.error);});})}function Me(t,e){return E((n,r)=>{t(n).then(a=>r({_tag:"Success",value:a})).catch(a=>r({_tag:"Failure",error:e(a)}));})}function Ue(t){return E((e,n)=>{let r=false,a=o=>{r||(r=true,n(o));};try{t((o,i)=>{a(o?{_tag:"Failure",error:o}:{_tag:"Success",value:i});});}catch(o){a({_tag:"Failure",error:o instanceof Error?o:new Error(String(o))});}})}function je(t){return re((n,r)=>t.length===1?t(r):t(n,r),n=>ae(n)?{_tag:"Abort"}:{_tag:"PromiseRejected",reason:n})}function re(t,e){return E((n,r)=>{let a=new AbortController,o=false,i=s=>{o||(o=true,r(s));};try{(t.length===1?t(a.signal):t(n,a.signal)).then(c=>i({_tag:"Success",value:c})).catch(c=>i({_tag:"Failure",error:e(c)}));}catch(s){i({_tag:"Failure",error:e(s)});}return ()=>{o=true,a.abort();}})}var ae=t=>typeof t=="object"&&t!==null&&"name"in t&&t.name==="AbortError";var oe=1;function se(t){return E((e,n)=>{let r=t.length;if(r===0){n({_tag:"Success",value:void 0});return}for(let a of t)a.join(()=>{r-=1,r===0&&n({_tag:"Success",value:void 0});});})}function ie(t){return R(t,()=>w(),()=>w())}var O=class t{constructor(e){this.env=e;this.id=oe++;}id;closed=false;children=new Set;subScopes=new Set;finalizers=[];addFinalizer(e){if(this.closed)throw new Error("Trying to add finalizer to closed scope");this.finalizers.push(e);}subScope(){if(this.closed)throw new Error("Scope closed");let e=new t(this.env);return this.subScopes.add(e),e}fork(e,n){if(this.closed)throw new Error("Scope closed");let r=Z(e,n);return this.children.add(r),r.join(()=>{this.children.delete(r);}),r}close(e={_tag:"Success",value:void 0}){Z(this.closeAsync(e),this.env);}closeAsync(e={_tag:"Success",value:void 0},n={}){return E((r,a)=>{if(this.closed){a({_tag:"Success",value:void 0});return}this.closed=true;let o=Array.from(this.children),i=Array.from(this.subScopes);this.children.clear(),this.subScopes.clear();for(let l of o)try{l.interrupt();}catch{}let s=w();for(let l of i)s=p(s,()=>l.closeAsync(e,n));for(;this.finalizers.length>0;){let l=this.finalizers.pop();s=p(s,()=>ie(l(e)));}n.awaitChildren&&(s=p(s,()=>se(o))),Z(s,this.env).join(()=>a({_tag:"Success",value:void 0}));})}};function Ge(t){let e=new O({});try{return t(e)}finally{e.close();}}function Ke(t,e,n){return E((r,a)=>{let o=n.subScope(),i=false,s=f=>{i||(i=true,o.close(f),a(f));},c=o.fork(t,r),l=o.fork(e,r);c.join(s),l.join(s);})}function Ve(t,e,n){return E((r,a)=>{let o=n.subScope(),i=null,s=null,c=false,l=()=>{if(!i||!s||c)return;if(c=true,i._tag==="Success"&&s._tag==="Success"){o.close({_tag:"Success",value:void 0}),a({_tag:"Success",value:[i.value,s.value]});return}let u;if(i._tag==="Failure")u=i.error;else if(s._tag==="Failure")u=s.error;else throw new Error("zipPar: unreachable state (no Failure exit)");let g={_tag:"Failure",error:u};o.close(g),a(g);},f=o.fork(t,r),d=o.fork(e,r);f.join(u=>{i=u,l();}),d.join(u=>{s=u,l();});})}function Xe(t,e){return E((n,r)=>{let a=e.subScope(),o=new Array(t.length),i=0,s=false;t.forEach((c,l)=>{a.fork(c,n).join(d=>{if(!s){if(d._tag==="Failure"){s=true;let u={_tag:"Failure",error:d.error};a.close(u),r(u);return}if(o[l]=d.value,i++,i===t.length){s=true;let u={_tag:"Success",value:o};a.close({_tag:"Success",value:void 0}),r(u);}}});});})}function K(t,e,n,r,a){return E((o,i)=>{let s=n.subScope(),c=false,l=s.fork(t,o),f=s.fork(e,o),d=u=>{s.fork(u,o).join(g=>{s.close(g),i(g);});};l.join(u=>{c||(c=true,d(r(u,f,s)));}),f.join(u=>{c||(c=true,d(a(u,l,s)));});})}var q=t=>t._tag==="None"?b:F(t.value),v=t=>({_tag:"FromPull",pull:t}),ce=(t,e)=>({_tag:"Scoped",acquire:t,release:e}),lt=t=>({_tag:"Scoped",acquire:p(t,e=>A(e.stream)),release:e=>p(t,n=>n.release(e))}),At=(t,e,n=true)=>({_tag:"Merge",left:t,right:e,flip:n}),T=()=>({_tag:"Empty"}),X=t=>({_tag:"Emit",value:t}),C=(t,e)=>({_tag:"Concat",left:t,right:e}),L=t=>({_tag:"Flatten",stream:t});function V(t,e,n,r,a){return (o,i,s)=>{if(o._tag,o._tag,o._tag==="Success"){let[f,d]=o.value;i.interrupt();let u=v(t==="L"?D(d,n):D(e,d));return A([f,u])}let c=o.error;if(typeof c=="object"&&c!==null&&c._tag==="Interrupted")return h(c);let l=c;return l._tag==="None"?y(t==="L"?n:e):h(l)}}function D(t,e,n,r){return E((a,o)=>{let s=new O(a),c=y(t),l=y(e),f=V("L",t,e),d=V("R",t,e),u=K(c,l,s,f,d);s.fork(u,a).join(g=>{s.close(g),o(g);});})}function Et(t,e){return v(D(t,e))}function y(t){switch(t._tag){case "Empty":return B(b);case "Emit":return I(M(t.value,e=>F(e)),e=>[e,T()]);case "FromPull":return t.pull;case "Concat":return U(I(y(t.left),([e,n])=>[e,C(n,t.right)]),()=>y(t.right));case "Flatten":return G(y(t.stream),([e,n])=>U(I(y(e),([r,a])=>[r,C(a,L(n))]),()=>y(L(n))));case "Merge":return D(t.left,t.right,t.flip);case "Scoped":return E((e,n)=>{let r=new O(e);r.addFinalizer(a=>t.release(a)),r.fork(t.acquire,e).join(a=>{if(a._tag==="Failure"){r.close(a),n({_tag:"Failure",error:F(a.error)});return}let o=a.value;y(o)(e,s=>{r.close(s),n(s);});});})}}function k(t,e){switch(t._tag){case "Empty":return T();case "Emit":return X(I(t.value,e));case "FromPull":return v(I(t.pull,([n,r])=>[e(n),k(r,e)]));case "Concat":return C(k(t.left,e),k(t.right,e));case "Flatten":{let n=k(t.stream,r=>k(r,e));return L(n)}}}function pt(t,e){let n=r=>v(r>e?h(b):A([r,n(r+1)]));return n(t)}function ue(t,e){let n=R(x(y(t),r=>q(r)),r=>h(r),([r,a])=>R(x(y(e),o=>q(o)),o=>h(o),([o,i])=>A([[r,o],ue(a,i)])));return v(n)}function yt(t,e){let n=r=>R(x(y(r),a=>q(a)),a=>a._tag==="None"?A(void 0):h(a),([a,o])=>p(x(e(a),i=>F(i)),()=>n(o)));return R(n(t),r=>r._tag==="None"?A(void 0):h(r.value),()=>A(void 0))}function dt(t){let e=T();for(let n=t.length-1;n>=0;n--){let r=X(z(t[n]));e=C(r,e);}return e}function Rt(t){let e=(n,r)=>R(y(n),a=>a._tag==="None"?z(r):B(a),([a,o])=>e(o,[...r,a]));return M(e(t,[]),n=>{if(n._tag==="Some")return n.value;throw new Error("unreachable: stream end handled as success")})}function le(t,e){let n=E((r,a)=>{t.read().then(({done:o,value:i})=>{if(o){a({_tag:"Failure",error:b});return}a({_tag:"Success",value:[i,v(n)]});}).catch(o=>{a({_tag:"Failure",error:F(e(o))});});});return v(n)}function ft(t,e){if(!t)return T();let n;return ce(H(()=>(n=t.getReader(),le(n,e))),()=>_(()=>{try{n?.cancel();}catch{}}))}exports.$=L;exports.A=xe;exports.B=P;exports.C=j;exports.D=J;exports.E=N;exports.F=De;exports.G=Z;exports.H=Te;exports.I=ze;exports.J=Me;exports.K=Ue;exports.L=je;exports.M=re;exports.N=O;exports.O=Ge;exports.P=Ke;exports.Q=Ve;exports.R=Xe;exports.S=K;exports.T=q;exports.U=v;exports.V=ce;exports.W=lt;exports.X=At;exports.Y=T;exports.Z=X;exports._=C;exports.a=R;exports.aa=Et;exports.b=Ae;exports.ba=y;exports.c=x;exports.ca=k;exports.d=w;exports.da=pt;exports.e=A;exports.ea=ue;exports.f=h;exports.fa=yt;exports.g=_;exports.ga=dt;exports.h=Ee;exports.ha=Rt;exports.i=E;exports.ia=ft;exports.j=W;exports.k=p;exports.l=pe;exports.m=ye;exports.n=de;exports.o=Re;exports.p=fe;exports.q=b;exports.r=F;exports.s=z;exports.t=B;exports.u=H;exports.v=I;exports.w=G;exports.x=M;exports.y=ve;exports.z=U;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
function R(t,e,n){return {_tag:"Fold",first:t,onFailure:e,onSuccess:n}}function Ae(t,e){return R(t,n=>e(n),n=>A(n))}function x(t,e){return R(t,n=>h(e(n)),n=>A(n))}var w=()=>A(void 0),A=t=>({_tag:"Succeed",value:t}),h=t=>({_tag:"Fail",error:t}),_=t=>({_tag:"Sync",thunk:t}),Ee=t=>_(()=>t()),E=t=>({_tag:"Async",register:t});function W(t,e){return p(t,n=>A(e(n)))}function p(t,e){return {_tag:"FlatMap",first:t,andThen:e}}function pe(t,e,n){return p(t,r=>(n.addFinalizer(a=>e(r,a)),A(r)))}function ye(t){return E(t)}var de=t=>e=>{let n=e;return n.toPromise||(n.toPromise=r=>t(e,r),n.unsafeRunPromise=()=>t(e,{})),n},Re=(t,e)=>p(t,n=>A(e(n))),fe=(t,e)=>p(t,n=>_(()=>e(n)));var b={_tag:"None"},F=t=>({_tag:"Some",value:t});var z=t=>A(t),B=t=>h(t),H=t=>_(e=>t(e)),I=(t,e)=>W(t,e),G=(t,e)=>p(t,n=>e(n)),M=(t,e)=>x(t,e),ve=(t,e)=>R(t,n=>e(n),n=>A(n));function U(t,e){return R(t,n=>n._tag==="Some"?h(n):e(),n=>A(n))}var xe=()=>B(b);var P=class{buf;head=0;tail=0;size_=0;constructor(e=1024){let n=Math.max(2,this.nextPow2(e));this.buf=new Array(n);}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,n=new Array(e.length*2);for(let r=0;r<this.size_;r++)n[r]=e[this.head+r&e.length-1];this.buf=n,this.head=0,this.tail=this.size_;}nextPow2(e){let n=1;for(;n<e;)n<<=1;return n}};var Q=2048,$=4096,Y=(()=>{if(typeof globalThis.setImmediate=="function")return t=>globalThis.setImmediate(t);if(typeof globalThis.MessageChannel=="function"){let t=new globalThis.MessageChannel,e=null;return t.port1.onmessage=()=>{let n=e;e=null,n?.();},n=>{e=n,t.port2.postMessage(0);}}return t=>setTimeout(t,0)})(),j=class{queue=new P(1024);flushing=false;scheduled=false;schedule(e,n="anonymous"){if(typeof e=="function"&&(this.queue.push({tag:n,task:e}),!this.flushing&&!this.scheduled)){this.scheduled=true;let r=this.queue.length>$?"macro":"micro";this.requestFlush(r);}}requestFlush(e){e==="micro"?queueMicrotask(()=>this.flush()):Y(()=>this.flush());}flush(){if(this.flushing)return;this.flushing=true,this.scheduled=false;let e=0;try{for(;e<Q;){let n=this.queue.shift();if(!n)break;e++;try{n.task();}catch(r){console.error(`[Scheduler] task threw (tag=${n.tag})`,r);}}}finally{if(this.flushing=false,this.queue.length>0&&!this.scheduled){this.scheduled=true;let n=e>=Q||this.queue.length>$?"macro":"micro";this.requestFlush(n);}}}},J=new j;var m={CONTINUE:"Continue",SUSPEND:"Suspend",DONE:"Done"},S={QUEUED:"Queued",RUNNING:"Running",SUSPENDED:"Suspended",DONE:"Done"},ee=1,te=1024;function ne(t){let e=t;for(;e._tag==="FlatMap"&&e.first._tag==="FlatMap";){let n=e.first,r=e.andThen;e={_tag:"FlatMap",first:n.first,andThen:a=>({_tag:"FlatMap",first:n.andThen(a),andThen:r})};}return e}var N=class{constructor(e,n,r){this.scheduler=r;this.id=ee++,this.current=e,this.env=n;}id;closing=null;finishing=false;runState=S.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===S.DONE||this.runState===S.QUEUED||(this.runState=S.QUEUED,this.scheduler.schedule(()=>{if(this.runState===S.DONE)return;switch(this.runState=S.RUNNING,this.step()){case m.CONTINUE:this.schedule("continue");return;case m.SUSPEND:this.runState=S.SUSPENDED;return;case m.DONE:this.runState=S.DONE;return}},`fiber#${this.id}.${e}`));}runFinalizersOnce(e){if(!this.finalizersDrained)for(this.finalizersDrained=true;this.fiberFinalizers.length>0;){let n=this.fiberFinalizers.pop();try{n(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 n of this.joiners)n(e);this.joiners.length=0;}}onSuccess(e){let n=this.stack.pop();if(!n){this.notify({_tag:"Success",value:e});return}this.current=n._tag==="SuccessCont"?n.k(e):n.onSuccess(e);}onFailure(e){for(;this.stack.length>0;){let n=this.stack.pop();if(n._tag==="FoldCont"){this.current=n.onFailure(e);return}}this.notify({_tag:"Failure",error:e});}step(){let e=te;for(;e-- >0;){if(this.result!=null)return m.DONE;if(this.interrupted&&this.closing==null)return this.notify({_tag:"Failure",error:{_tag:"Interrupted"}}),m.DONE;let n=ne(this.current);switch(n._tag){case "Succeed":{this.onSuccess(n.value);break}case "Fail":{this.onFailure(n.error);break}case "Sync":{try{let r=n.thunk(this.env);this.onSuccess(r);}catch(r){this.onFailure(r);}break}case "FlatMap":{this.stack.push({_tag:"SuccessCont",k:n.andThen}),this.current=n.first;break}case "Fold":{this.stack.push({_tag:"FoldCont",onFailure:n.onFailure,onSuccess:n.onSuccess}),this.current=n.first;break}case "Async":{if(this.finishing)return this.result!=null?m.DONE:m.CONTINUE;let r=false,a=i=>{r||(r=true,!(this.result!=null||this.closing!=null)&&(this.current=i._tag==="Success"?{_tag:"Succeed",value:i.value}:{_tag:"Fail",error:i.error},this.schedule("async-resume")));},o=n.register(this.env,a);return typeof o=="function"&&this.addFinalizer(()=>{r=true;try{o();}catch{}}),m.SUSPEND}}}return this.result!=null?m.DONE:m.CONTINUE}};function De(t){return E((e,n)=>{let r=false,a=s=>{r||(r=true,n(s));},o=s=>a({_tag:"Failure",error:s instanceof Error?s:new Error(String(s))}),i=s=>a({_tag:"Success",value:s});try{typeof t=="function"&&t.length>=1?t((s,c)=>s?o(s):i(c)):t().then(i,o);}catch(s){o(s);}})}function Z(t,e,n=J){let r=new N(t,e,n);return r.schedule("initial-step"),r}function Te(t,e,n){Z(t,e).join(n);}function ze(t,e){return new Promise((n,r)=>{Z(t,e).join(o=>{let i=o;i._tag==="Success"?n(i.value):r(i.error);});})}function Me(t,e){return E((n,r)=>{t(n).then(a=>r({_tag:"Success",value:a})).catch(a=>r({_tag:"Failure",error:e(a)}));})}function Ue(t){return E((e,n)=>{let r=false,a=o=>{r||(r=true,n(o));};try{t((o,i)=>{a(o?{_tag:"Failure",error:o}:{_tag:"Success",value:i});});}catch(o){a({_tag:"Failure",error:o instanceof Error?o:new Error(String(o))});}})}function je(t){return re((n,r)=>t.length===1?t(r):t(n,r),n=>ae(n)?{_tag:"Abort"}:{_tag:"PromiseRejected",reason:n})}function re(t,e){return E((n,r)=>{let a=new AbortController,o=false,i=s=>{o||(o=true,r(s));};try{(t.length===1?t(a.signal):t(n,a.signal)).then(c=>i({_tag:"Success",value:c})).catch(c=>i({_tag:"Failure",error:e(c)}));}catch(s){i({_tag:"Failure",error:e(s)});}return ()=>{o=true,a.abort();}})}var ae=t=>typeof t=="object"&&t!==null&&"name"in t&&t.name==="AbortError";var oe=1;function se(t){return E((e,n)=>{let r=t.length;if(r===0){n({_tag:"Success",value:void 0});return}for(let a of t)a.join(()=>{r-=1,r===0&&n({_tag:"Success",value:void 0});});})}function ie(t){return R(t,()=>w(),()=>w())}var O=class t{constructor(e){this.env=e;this.id=oe++;}id;closed=false;children=new Set;subScopes=new Set;finalizers=[];addFinalizer(e){if(this.closed)throw new Error("Trying to add finalizer to closed scope");this.finalizers.push(e);}subScope(){if(this.closed)throw new Error("Scope closed");let e=new t(this.env);return this.subScopes.add(e),e}fork(e,n){if(this.closed)throw new Error("Scope closed");let r=Z(e,n);return this.children.add(r),r.join(()=>{this.children.delete(r);}),r}close(e={_tag:"Success",value:void 0}){Z(this.closeAsync(e),this.env);}closeAsync(e={_tag:"Success",value:void 0},n={}){return E((r,a)=>{if(this.closed){a({_tag:"Success",value:void 0});return}this.closed=true;let o=Array.from(this.children),i=Array.from(this.subScopes);this.children.clear(),this.subScopes.clear();for(let l of o)try{l.interrupt();}catch{}let s=w();for(let l of i)s=p(s,()=>l.closeAsync(e,n));for(;this.finalizers.length>0;){let l=this.finalizers.pop();s=p(s,()=>ie(l(e)));}n.awaitChildren&&(s=p(s,()=>se(o))),Z(s,this.env).join(()=>a({_tag:"Success",value:void 0}));})}};function Ge(t){let e=new O({});try{return t(e)}finally{e.close();}}function Ke(t,e,n){return E((r,a)=>{let o=n.subScope(),i=false,s=f=>{i||(i=true,o.close(f),a(f));},c=o.fork(t,r),l=o.fork(e,r);c.join(s),l.join(s);})}function Ve(t,e,n){return E((r,a)=>{let o=n.subScope(),i=null,s=null,c=false,l=()=>{if(!i||!s||c)return;if(c=true,i._tag==="Success"&&s._tag==="Success"){o.close({_tag:"Success",value:void 0}),a({_tag:"Success",value:[i.value,s.value]});return}let u;if(i._tag==="Failure")u=i.error;else if(s._tag==="Failure")u=s.error;else throw new Error("zipPar: unreachable state (no Failure exit)");let g={_tag:"Failure",error:u};o.close(g),a(g);},f=o.fork(t,r),d=o.fork(e,r);f.join(u=>{i=u,l();}),d.join(u=>{s=u,l();});})}function Xe(t,e){return E((n,r)=>{let a=e.subScope(),o=new Array(t.length),i=0,s=false;t.forEach((c,l)=>{a.fork(c,n).join(d=>{if(!s){if(d._tag==="Failure"){s=true;let u={_tag:"Failure",error:d.error};a.close(u),r(u);return}if(o[l]=d.value,i++,i===t.length){s=true;let u={_tag:"Success",value:o};a.close({_tag:"Success",value:void 0}),r(u);}}});});})}function K(t,e,n,r,a){return E((o,i)=>{let s=n.subScope(),c=false,l=s.fork(t,o),f=s.fork(e,o),d=u=>{s.fork(u,o).join(g=>{s.close(g),i(g);});};l.join(u=>{c||(c=true,d(r(u,f,s)));}),f.join(u=>{c||(c=true,d(a(u,l,s)));});})}var q=t=>t._tag==="None"?b:F(t.value),v=t=>({_tag:"FromPull",pull:t}),ce=(t,e)=>({_tag:"Scoped",acquire:t,release:e}),lt=t=>({_tag:"Scoped",acquire:p(t,e=>A(e.stream)),release:e=>p(t,n=>n.release(e))}),At=(t,e,n=true)=>({_tag:"Merge",left:t,right:e,flip:n}),T=()=>({_tag:"Empty"}),X=t=>({_tag:"Emit",value:t}),C=(t,e)=>({_tag:"Concat",left:t,right:e}),L=t=>({_tag:"Flatten",stream:t});function V(t,e,n,r,a){return (o,i,s)=>{if(o._tag,o._tag,o._tag==="Success"){let[f,d]=o.value;i.interrupt();let u=v(t==="L"?D(d,n):D(e,d));return A([f,u])}let c=o.error;if(typeof c=="object"&&c!==null&&c._tag==="Interrupted")return h(c);let l=c;return l._tag==="None"?y(t==="L"?n:e):h(l)}}function D(t,e,n,r){return E((a,o)=>{let s=new O(a),c=y(t),l=y(e),f=V("L",t,e),d=V("R",t,e),u=K(c,l,s,f,d);s.fork(u,a).join(g=>{s.close(g),o(g);});})}function Et(t,e){return v(D(t,e))}function y(t){switch(t._tag){case "Empty":return B(b);case "Emit":return I(M(t.value,e=>F(e)),e=>[e,T()]);case "FromPull":return t.pull;case "Concat":return U(I(y(t.left),([e,n])=>[e,C(n,t.right)]),()=>y(t.right));case "Flatten":return G(y(t.stream),([e,n])=>U(I(y(e),([r,a])=>[r,C(a,L(n))]),()=>y(L(n))));case "Merge":return D(t.left,t.right,t.flip);case "Scoped":return E((e,n)=>{let r=new O(e);r.addFinalizer(a=>t.release(a)),r.fork(t.acquire,e).join(a=>{if(a._tag==="Failure"){r.close(a),n({_tag:"Failure",error:F(a.error)});return}let o=a.value;y(o)(e,s=>{r.close(s),n(s);});});})}}function k(t,e){switch(t._tag){case "Empty":return T();case "Emit":return X(I(t.value,e));case "FromPull":return v(I(t.pull,([n,r])=>[e(n),k(r,e)]));case "Concat":return C(k(t.left,e),k(t.right,e));case "Flatten":{let n=k(t.stream,r=>k(r,e));return L(n)}}}function pt(t,e){let n=r=>v(r>e?h(b):A([r,n(r+1)]));return n(t)}function ue(t,e){let n=R(x(y(t),r=>q(r)),r=>h(r),([r,a])=>R(x(y(e),o=>q(o)),o=>h(o),([o,i])=>A([[r,o],ue(a,i)])));return v(n)}function yt(t,e){let n=r=>R(x(y(r),a=>q(a)),a=>a._tag==="None"?A(void 0):h(a),([a,o])=>p(x(e(a),i=>F(i)),()=>n(o)));return R(n(t),r=>r._tag==="None"?A(void 0):h(r.value),()=>A(void 0))}function dt(t){let e=T();for(let n=t.length-1;n>=0;n--){let r=X(z(t[n]));e=C(r,e);}return e}function Rt(t){let e=(n,r)=>R(y(n),a=>a._tag==="None"?z(r):B(a),([a,o])=>e(o,[...r,a]));return M(e(t,[]),n=>{if(n._tag==="Some")return n.value;throw new Error("unreachable: stream end handled as success")})}function le(t,e){let n=E((r,a)=>{t.read().then(({done:o,value:i})=>{if(o){a({_tag:"Failure",error:b});return}a({_tag:"Success",value:[i,v(n)]});}).catch(o=>{a({_tag:"Failure",error:F(e(o))});});});return v(n)}function ft(t,e){if(!t)return T();let n;return ce(H(()=>(n=t.getReader(),le(n,e))),()=>_(()=>{try{n?.cancel();}catch{}}))}export{L as $,xe as A,P as B,j as C,J as D,N as E,De as F,Z as G,Te as H,ze as I,Me as J,Ue as K,je as L,re as M,O as N,Ge as O,Ke as P,Ve as Q,Xe as R,K as S,q as T,v as U,ce as V,lt as W,At as X,T as Y,X as Z,C as _,R as a,Et as aa,Ae as b,y as ba,x as c,k as ca,w as d,pt as da,A as e,ue as ea,h as f,yt as fa,_ as g,dt as ga,Ee as h,Rt as ha,E as i,ft as ia,W as j,p as k,pe as l,ye as m,de as n,Re as o,fe as p,b as q,F as r,z as s,B as t,H as u,I as v,G as w,M as x,ve as y,U as z};
|
package/dist/http/index.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Z as ZStream, A as Async, y as AsyncWithPromise } from '../stream-CPScJVP0.mjs';
|
|
2
2
|
|
|
3
3
|
type RetryPolicy = {
|
|
4
4
|
maxRetries: number;
|
|
@@ -86,7 +86,7 @@ type Dx = {
|
|
|
86
86
|
post: (url: string, body?: string, init?: any) => any;
|
|
87
87
|
getText: (url: string, init?: any) => any;
|
|
88
88
|
getJson: <A>(url: string, init?: any) => any;
|
|
89
|
-
postJson: (url: string, body?: any, init?: any) => any;
|
|
89
|
+
postJson: <A>(url: string, body?: any, init?: any) => any;
|
|
90
90
|
with: (mw: HttpMiddleware) => Dx;
|
|
91
91
|
withRetry: (p: RetryPolicy) => Dx;
|
|
92
92
|
wire: HttpClient;
|
package/dist/http/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Z as ZStream, A as Async, y as AsyncWithPromise } from '../stream-CPScJVP0.js';
|
|
2
2
|
|
|
3
3
|
type RetryPolicy = {
|
|
4
4
|
maxRetries: number;
|
|
@@ -86,7 +86,7 @@ type Dx = {
|
|
|
86
86
|
post: (url: string, body?: string, init?: any) => any;
|
|
87
87
|
getText: (url: string, init?: any) => any;
|
|
88
88
|
getJson: <A>(url: string, init?: any) => any;
|
|
89
|
-
postJson: (url: string, body?: any, init?: any) => any;
|
|
89
|
+
postJson: <A>(url: string, body?: any, init?: any) => any;
|
|
90
90
|
with: (mw: HttpMiddleware) => Dx;
|
|
91
91
|
withRetry: (p: RetryPolicy) => Dx;
|
|
92
92
|
wire: HttpClient;
|
package/dist/http/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
'use strict';var
|
|
1
|
+
'use strict';var chunk2NVQIUW5_js=require('../chunk-2NVQIUW5.js');var b={make(t,e){return {get:t,set:e}},over(t,e){return r=>t.set(e(t.get(r)))(r)},compose(t,e){return b.make(r=>t.get(e.get(r)),r=>n=>e.set(t.set(r)(e.get(n)))(n))}};var f={headers:b.make(t=>t.headers??{},t=>e=>({...e,headers:t}))};var k=t=>e=>b.over(f.headers,r=>({...r,...t}))(e),w=t=>e=>b.over(f.headers,r=>({...t,...r}))(e),M=(t,e)=>r=>b.over(f.headers,n=>n[t]?n:{...n,[t]:e})(r);var dt=t=>e=>T(t(e)),T=t=>Object.assign((e=>t(e)),{with:e=>T(e(t))}),S=t=>t instanceof DOMException&&t.name==="AbortError"?{_tag:"Abort"}:typeof t=="object"&&t&&"_tag"in t?t:{_tag:"FetchError",message:String(t)},C=t=>{if(t){if(typeof Headers<"u"&&t instanceof Headers){let e={};return t.forEach((r,n)=>e[n]=r),e}if(Array.isArray(t))return Object.fromEntries(t);if(typeof t=="object")return {...t}}},I=t=>e=>{let r=Object.keys(t).length?w(t)(e):e,n=C(e.init?.headers);return n&&Object.keys(n).length&&(r=w(n)(r)),r};function W(t={}){let e=t.baseUrl??"",r=t.headers??{},n=I(r);return c=>chunk2NVQIUW5_js.M(async a=>{let y=n(c),i;try{i=new URL(y.url,e);}catch{throw {_tag:"BadUrl",message:`URL inv\xE1lida: ${y.url}`}}let p=performance.now(),s=await fetch(i,{...y.init??{},method:y.method,headers:f.headers.get(y),body:y.body,signal:a}),u={};s.headers.forEach((d,m)=>u[m]=d);let o=chunk2NVQIUW5_js.ia(s.body,S);return {status:s.status,statusText:s.statusText,headers:u,body:o,ms:Math.round(performance.now()-p)}},S)}function U(t={}){let e=t.baseUrl??"",r=t.headers??{},n=I(r);return T(a=>chunk2NVQIUW5_js.M(async y=>{let i=n(a),p;try{p=new URL(i.url,e);}catch{throw {_tag:"BadUrl",message:`URL inv\xE1lida: ${i.url}`}}let s=performance.now(),u=await fetch(p,{...i.init??{},method:i.method,headers:f.headers.get(i),body:i.body,signal:y}),o=await u.text(),d={};return u.headers.forEach((m,H)=>d[H]=m),{status:u.status,statusText:u.statusText,headers:d,bodyText:o,ms:Math.round(performance.now()-s)}},S))}var j=(t,e,r)=>Math.max(e,Math.min(r,t)),J=t=>t._tag==="FetchError",G=t=>t===408||t===429||t===500||t===502||t===503||t===504,F=(t,e,r)=>{let n=e*Math.pow(2,t),c=j(n,0,r);return Math.floor(Math.random()*c)},D=t=>chunk2NVQIUW5_js.M(e=>new Promise((r,n)=>{if(e.aborted)return n({_tag:"Abort"});let c=setTimeout(r,t);e.addEventListener("abort",()=>{clearTimeout(c),n({_tag:"Abort"});},{once:true});}),e=>typeof e=="object"&&e&&"_tag"in e?e:{_tag:"FetchError",message:String(e)}),z=t=>{let e=Object.keys(t).find(a=>a.toLowerCase()==="retry-after");if(!e)return;let r=t[e]?.trim();if(!r)return;let n=Number(r);if(Number.isFinite(n))return Math.max(0,Math.floor(n*1e3));let c=Date.parse(r);if(Number.isFinite(c))return Math.max(0,c-Date.now())},_=t=>e=>(r=>{let n=c=>chunk2NVQIUW5_js.a(e(r),a=>{if(a._tag==="Abort"||a._tag==="BadUrl")return chunk2NVQIUW5_js.f(a);if(!(c<t.maxRetries&&(t.retryOnError??J)(a)))return chunk2NVQIUW5_js.f(a);let i=F(c,t.baseDelayMs,t.maxDelayMs);return chunk2NVQIUW5_js.k(D(i),()=>n(c+1))},a=>{if(!(c<t.maxRetries&&(t.retryOnStatus??G)(a.status)))return chunk2NVQIUW5_js.e(a);let p=z(a.headers)??F(c,t.baseDelayMs,t.maxDelayMs);return chunk2NVQIUW5_js.k(D(p),()=>n(c+1))});return n(0)});var Z=["GET","HEAD","OPTIONS"],$=t=>t===408||t===429||t===500||t===502||t===503||t===504,K=t=>t._tag==="FetchError",Q=t=>typeof t=="object"&&t!==null&&"name"in t&&t.name==="AbortError"?{_tag:"Abort"}:typeof t=="object"&&t&&"_tag"in t?t:{_tag:"FetchError",message:String(t)},L=t=>chunk2NVQIUW5_js.M(e=>new Promise((r,n)=>{let c=setTimeout(r,t),a=()=>{clearTimeout(c);let y=typeof globalThis.DOMException=="function"?new globalThis.DOMException("Aborted","AbortError"):{name:"AbortError"};n(y);};if(e.aborted)return a();e.addEventListener("abort",a,{once:true});}),Q),V=(t,e,r)=>Math.max(e,Math.min(r,t)),N=(t,e,r)=>{let n=Math.max(0,e),c=Math.max(0,r),a=n*Math.pow(2,t),y=V(a,0,c);return Math.floor(Math.random()*y)},X=(t,e)=>{let r=Object.keys(t).find(n=>n.toLowerCase()===e.toLowerCase());return r?t[r]:void 0},Y=t=>{let e=X(t,"retry-after")?.trim();if(!e)return;let r=Number(e);if(Number.isFinite(r))return Math.max(0,Math.floor(r*1e3));let n=Date.parse(e);if(Number.isFinite(n))return Math.max(0,n-Date.now())},v=t=>e=>{let r=t.retryOnMethods??Z,n=t.retryOnStatus??$,c=t.retryOnError??K,a=i=>r.includes(i.method),y=(i,p)=>a(i)?chunk2NVQIUW5_js.a(e(i),s=>{if(s._tag==="Abort"||s._tag==="BadUrl")return chunk2NVQIUW5_js.f(s);if(!(p<t.maxRetries&&c(s)))return chunk2NVQIUW5_js.f(s);let o=N(p,t.baseDelayMs,t.maxDelayMs);return chunk2NVQIUW5_js.k(L(o),()=>y(i,p+1))},s=>{if(!(p<t.maxRetries&&n(s.status)))return chunk2NVQIUW5_js.e(s);let d=Y(s.headers)??N(p,t.baseDelayMs,t.maxDelayMs);return chunk2NVQIUW5_js.k(L(d),()=>y(i,p+1))}):e(i);return i=>y(i,0)};var tt=(t,e)=>{try{return new URL(e,t??"").toString()}catch{return (t??"")+e}},B=(t={})=>{let e=U(t),r=p=>chunk2NVQIUW5_js.n((s,u)=>chunk2NVQIUW5_js.I(s,u))(p),n=p=>e(p),c=p=>{let{headers:s,...u}=p??{};return {headers:C(s),init:u}},a=p=>s=>p?k(p)(s):s;return {cfg:t,wire:e,withPromise:r,requestRaw:n,splitInit:c,applyInitHeaders:a,buildReq:(p,s,u,o)=>{let d=c(u),m={method:p,url:s,...o&&o.length>0?{body:o}:{},init:d.init};return a(d.headers)(m)},toResponse:(p,s)=>({status:p.status,statusText:p.statusText,headers:p.headers,body:s})}};function Ft(t={}){let e=B(t),r=n=>{let c=o=>n(o),a=o=>e.withPromise(c(o));return {request:a,get:(o,d)=>a(e.buildReq("GET",o,d)),post:(o,d,m)=>a(e.buildReq("POST",o,m,d)),getText:(o,d)=>{let m=e.buildReq("GET",o,d);return e.withPromise(chunk2NVQIUW5_js.p(c(m),H=>e.toResponse(H,H.bodyText)))},getJson:(o,d)=>{let m=e.buildReq("GET",o,d),H=M("accept","application/json")(m);return e.withPromise(chunk2NVQIUW5_js.p(c(H),O=>e.toResponse(O,JSON.parse(O.bodyText))))},postJson:(o,d,m)=>a(e.buildReq("POST",o,m,JSON.stringify(d??{}))),with:o=>r(n.with(o)),withRetry:o=>r(n.with(v(o))),wire:n}};return r(e.wire)}function Dt(t={}){let e=B(t),r=(s,u,o)=>({request:s,urlFinal:tt(e.cfg.baseUrl,s.url),startedAt:o,durationMs:u.ms}),n=s=>{let u=Date.now();return e.withPromise(chunk2NVQIUW5_js.p(e.requestRaw(s),o=>({wire:o,meta:r(s,o,u)})))};return {request:n,get:(s,u)=>{let o=e.buildReq("GET",s,u);return n(o)},getText:(s,u)=>{let o=e.buildReq("GET",s,u),d=Date.now();return e.withPromise(chunk2NVQIUW5_js.p(e.requestRaw(o),m=>({wire:m,response:e.toResponse(m,m.bodyText),meta:r(o,m,d)})))},getJson:(s,u)=>{let o=e.buildReq("GET",s,u),d=M("accept","application/json")(o),m=Date.now();return e.withPromise(chunk2NVQIUW5_js.p(e.requestRaw(d),H=>({wire:H,response:e.toResponse(H,JSON.parse(H.bodyText)),meta:r(d,H,m)})))},post:(s,u,o)=>{let d=e.buildReq("POST",s,o,u);return n(d)},postJson:(s,u,o)=>{let d=e.buildReq("POST",s,o,JSON.stringify(u)),m=M("content-type","application/json")(M("accept","application/json")(d));return n(m)}}}function It(t={}){let e=W(t),r=n=>{let c=i=>chunk2NVQIUW5_js.n((p,s)=>chunk2NVQIUW5_js.I(p,s))(i),a=i=>c(n(i)),y=(i,p)=>{let s={method:"GET",url:i,init:p},u=M("accept","*/*")(s);return a(u)};return {request:a,getStream:y,get:y,with:i=>r(i(n)),withRetry:i=>r(_(i)(n)),wire:n}};return r(e)}exports.decorate=T;exports.httpClient=Ft;exports.httpClientStream=It;exports.httpClientWithMeta=Dt;exports.makeHttp=U;exports.makeHttpStream=W;exports.normalizeHeadersInit=C;exports.withMiddleware=dt;exports.withRetryStream=_;
|
package/dist/http/index.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {M as M$1,ia,a,p,n,f as f$1,k as k$1,e,I as I$1}from'../chunk-JTRM4ZSS.mjs';var b={make(t,e){return {get:t,set:e}},over(t,e){return r=>t.set(e(t.get(r)))(r)},compose(t,e){return b.make(r=>t.get(e.get(r)),r=>n=>e.set(t.set(r)(e.get(n)))(n))}};var f={headers:b.make(t=>t.headers??{},t=>e=>({...e,headers:t}))};var k=t=>e=>b.over(f.headers,r=>({...r,...t}))(e),w=t=>e=>b.over(f.headers,r=>({...t,...r}))(e),M=(t,e)=>r=>b.over(f.headers,n=>n[t]?n:{...n,[t]:e})(r);var dt=t=>e=>T(t(e)),T=t=>Object.assign((e=>t(e)),{with:e=>T(e(t))}),S=t=>t instanceof DOMException&&t.name==="AbortError"?{_tag:"Abort"}:typeof t=="object"&&t&&"_tag"in t?t:{_tag:"FetchError",message:String(t)},C=t=>{if(t){if(typeof Headers<"u"&&t instanceof Headers){let e={};return t.forEach((r,n)=>e[n]=r),e}if(Array.isArray(t))return Object.fromEntries(t);if(typeof t=="object")return {...t}}},I=t=>e=>{let r=Object.keys(t).length?w(t)(e):e,n=C(e.init?.headers);return n&&Object.keys(n).length&&(r=w(n)(r)),r};function W(t={}){let e=t.baseUrl??"",r=t.headers??{},n=I(r);return c=>M$1(async a=>{let y=n(c),i;try{i=new URL(y.url,e);}catch{throw {_tag:"BadUrl",message:`URL inv\xE1lida: ${y.url}`}}let p=performance.now(),s=await fetch(i,{...y.init??{},method:y.method,headers:f.headers.get(y),body:y.body,signal:a}),u={};s.headers.forEach((d,m)=>u[m]=d);let o=ia(s.body,S);return {status:s.status,statusText:s.statusText,headers:u,body:o,ms:Math.round(performance.now()-p)}},S)}function U(t={}){let e=t.baseUrl??"",r=t.headers??{},n=I(r);return T(a=>M$1(async y=>{let i=n(a),p;try{p=new URL(i.url,e);}catch{throw {_tag:"BadUrl",message:`URL inv\xE1lida: ${i.url}`}}let s=performance.now(),u=await fetch(p,{...i.init??{},method:i.method,headers:f.headers.get(i),body:i.body,signal:y}),o=await u.text(),d={};return u.headers.forEach((m,H)=>d[H]=m),{status:u.status,statusText:u.statusText,headers:d,bodyText:o,ms:Math.round(performance.now()-s)}},S))}var j=(t,e,r)=>Math.max(e,Math.min(r,t)),J=t=>t._tag==="FetchError",G=t=>t===408||t===429||t===500||t===502||t===503||t===504,F=(t,e,r)=>{let n=e*Math.pow(2,t),c=j(n,0,r);return Math.floor(Math.random()*c)},D=t=>M$1(e=>new Promise((r,n)=>{if(e.aborted)return n({_tag:"Abort"});let c=setTimeout(r,t);e.addEventListener("abort",()=>{clearTimeout(c),n({_tag:"Abort"});},{once:true});}),e=>typeof e=="object"&&e&&"_tag"in e?e:{_tag:"FetchError",message:String(e)}),z=t=>{let e=Object.keys(t).find(a=>a.toLowerCase()==="retry-after");if(!e)return;let r=t[e]?.trim();if(!r)return;let n=Number(r);if(Number.isFinite(n))return Math.max(0,Math.floor(n*1e3));let c=Date.parse(r);if(Number.isFinite(c))return Math.max(0,c-Date.now())},_=t=>e$1=>(r=>{let n=c=>a(e$1(r),a=>{if(a._tag==="Abort"||a._tag==="BadUrl")return f$1(a);if(!(c<t.maxRetries&&(t.retryOnError??J)(a)))return f$1(a);let i=F(c,t.baseDelayMs,t.maxDelayMs);return k$1(D(i),()=>n(c+1))},a=>{if(!(c<t.maxRetries&&(t.retryOnStatus??G)(a.status)))return e(a);let p=z(a.headers)??F(c,t.baseDelayMs,t.maxDelayMs);return k$1(D(p),()=>n(c+1))});return n(0)});var Z=["GET","HEAD","OPTIONS"],$=t=>t===408||t===429||t===500||t===502||t===503||t===504,K=t=>t._tag==="FetchError",Q=t=>typeof t=="object"&&t!==null&&"name"in t&&t.name==="AbortError"?{_tag:"Abort"}:typeof t=="object"&&t&&"_tag"in t?t:{_tag:"FetchError",message:String(t)},L=t=>M$1(e=>new Promise((r,n)=>{let c=setTimeout(r,t),a=()=>{clearTimeout(c);let y=typeof globalThis.DOMException=="function"?new globalThis.DOMException("Aborted","AbortError"):{name:"AbortError"};n(y);};if(e.aborted)return a();e.addEventListener("abort",a,{once:true});}),Q),V=(t,e,r)=>Math.max(e,Math.min(r,t)),N=(t,e,r)=>{let n=Math.max(0,e),c=Math.max(0,r),a=n*Math.pow(2,t),y=V(a,0,c);return Math.floor(Math.random()*y)},X=(t,e)=>{let r=Object.keys(t).find(n=>n.toLowerCase()===e.toLowerCase());return r?t[r]:void 0},Y=t=>{let e=X(t,"retry-after")?.trim();if(!e)return;let r=Number(e);if(Number.isFinite(r))return Math.max(0,Math.floor(r*1e3));let n=Date.parse(e);if(Number.isFinite(n))return Math.max(0,n-Date.now())},v=t=>e$1=>{let r=t.retryOnMethods??Z,n=t.retryOnStatus??$,c=t.retryOnError??K,a$1=i=>r.includes(i.method),y=(i,p)=>a$1(i)?a(e$1(i),s=>{if(s._tag==="Abort"||s._tag==="BadUrl")return f$1(s);if(!(p<t.maxRetries&&c(s)))return f$1(s);let o=N(p,t.baseDelayMs,t.maxDelayMs);return k$1(L(o),()=>y(i,p+1))},s=>{if(!(p<t.maxRetries&&n(s.status)))return e(s);let d=Y(s.headers)??N(p,t.baseDelayMs,t.maxDelayMs);return k$1(L(d),()=>y(i,p+1))}):e$1(i);return i=>y(i,0)};var tt=(t,e)=>{try{return new URL(e,t??"").toString()}catch{return (t??"")+e}},B=(t={})=>{let e=U(t),r=p=>n((s,u)=>I$1(s,u))(p),n$1=p=>e(p),c=p=>{let{headers:s,...u}=p??{};return {headers:C(s),init:u}},a=p=>s=>p?k(p)(s):s;return {cfg:t,wire:e,withPromise:r,requestRaw:n$1,splitInit:c,applyInitHeaders:a,buildReq:(p,s,u,o)=>{let d=c(u),m={method:p,url:s,...o&&o.length>0?{body:o}:{},init:d.init};return a(d.headers)(m)},toResponse:(p,s)=>({status:p.status,statusText:p.statusText,headers:p.headers,body:s})}};function Ft(t={}){let e=B(t),r=n=>{let c=o=>n(o),a=o=>e.withPromise(c(o));return {request:a,get:(o,d)=>a(e.buildReq("GET",o,d)),post:(o,d,m)=>a(e.buildReq("POST",o,m,d)),getText:(o,d)=>{let m=e.buildReq("GET",o,d);return e.withPromise(p(c(m),H=>e.toResponse(H,H.bodyText)))},getJson:(o,d)=>{let m=e.buildReq("GET",o,d),H=M("accept","application/json")(m);return e.withPromise(p(c(H),O=>e.toResponse(O,JSON.parse(O.bodyText))))},postJson:(o,d,m)=>a(e.buildReq("POST",o,m,JSON.stringify(d??{}))),with:o=>r(n.with(o)),withRetry:o=>r(n.with(v(o))),wire:n}};return r(e.wire)}function Dt(t={}){let e=B(t),r=(s,u,o)=>({request:s,urlFinal:tt(e.cfg.baseUrl,s.url),startedAt:o,durationMs:u.ms}),n=s=>{let u=Date.now();return e.withPromise(p(e.requestRaw(s),o=>({wire:o,meta:r(s,o,u)})))};return {request:n,get:(s,u)=>{let o=e.buildReq("GET",s,u);return n(o)},getText:(s,u)=>{let o=e.buildReq("GET",s,u),d=Date.now();return e.withPromise(p(e.requestRaw(o),m=>({wire:m,response:e.toResponse(m,m.bodyText),meta:r(o,m,d)})))},getJson:(s,u)=>{let o=e.buildReq("GET",s,u),d=M("accept","application/json")(o),m=Date.now();return e.withPromise(p(e.requestRaw(d),H=>({wire:H,response:e.toResponse(H,JSON.parse(H.bodyText)),meta:r(d,H,m)})))},post:(s,u,o)=>{let d=e.buildReq("POST",s,o,u);return n(d)},postJson:(s,u,o)=>{let d=e.buildReq("POST",s,o,JSON.stringify(u)),m=M("content-type","application/json")(M("accept","application/json")(d));return n(m)}}}function It(t={}){let e=W(t),r=n$1=>{let c=i=>n((p,s)=>I$1(p,s))(i),a=i=>c(n$1(i)),y=(i,p)=>{let s={method:"GET",url:i,init:p},u=M("accept","*/*")(s);return a(u)};return {request:a,getStream:y,get:y,with:i=>r(i(n$1)),withRetry:i=>r(_(i)(n$1)),wire:n$1}};return r(e)}export{T as decorate,Ft as httpClient,It as httpClientStream,Dt as httpClientWithMeta,U as makeHttp,W as makeHttpStream,C as normalizeHeadersInit,dt as withMiddleware,_ as withRetryStream};
|
package/dist/index.d.mts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { A as Async, S as Scheduler, F as Fiber, E as Exit, I as Interrupted } from './stream-
|
|
2
|
-
export {
|
|
1
|
+
import { A as Async, S as Scheduler, F as Fiber, E as Exit, I as Interrupted, Z as ZStream, a as Scope, O as Option } from './stream-CPScJVP0.mjs';
|
|
2
|
+
export { y as AsyncWithPromise, K as CancelToken, J as Canceler, _ as Concat, Y as Emit, X as Empty, P as FiberId, Q as FiberStatus, $ as Flatten, a0 as FromPull, a1 as Merge, N as None, a3 as Normalize, R as RuntimeFiber, T as ScopeId, a2 as Scoped, D as Some, V as Task, b as ZIO, w as acquireRelease, r as async, j as asyncCatchAll, n as asyncFail, v as asyncFlatMap, i as asyncFold, x as asyncInterruptible, t as asyncMap, k as asyncMapError, l as asyncSucceed, p as asyncSync, q as asyncTotal, g as catchAll, ak as collectStream, ab as concatStream, aa as emitStream, a9 as emptyStream, h as end, f as fail, d as flatMap, ac as flattenStream, ai as foreachStream, aj as fromArray, a5 as fromPull, W as globalScheduler, M as linkAbortController, L as makeCancelToken, a7 as managedStream, m as map, B as mapAsync, e as mapError, af as mapStream, C as mapTryAsync, ad as merge, a8 as mergeStream, G as none, o as orElseOptional, ag as rangeStream, H as some, al as streamFromReadableStream, s as succeed, c as sync, ae as uncons, u as unit, a6 as unwrapScoped, a4 as widenOpt, z as withAsyncPromise, U as withScope, ah as zip } from './stream-CPScJVP0.mjs';
|
|
3
3
|
|
|
4
4
|
type NodeCallback<A> = (err: Error | null, result: A) => void;
|
|
5
5
|
declare function from<A>(f: (cb: NodeCallback<A>) => void): Async<{}, Error, A>;
|
|
@@ -20,4 +20,140 @@ declare function tryPromiseAbortable<R, A>(thunk: (env: R, signal: AbortSignal)
|
|
|
20
20
|
declare function fromPromiseAbortable<E, A>(thunk: (signal: AbortSignal) => Promise<A>, onError: (e: unknown) => E): Async<unknown, E, A>;
|
|
21
21
|
declare function fromPromiseAbortable<R, E, A>(thunk: (env: R, signal: AbortSignal) => Promise<A>, onError: (e: unknown) => E): Async<R, E, A>;
|
|
22
22
|
|
|
23
|
-
|
|
23
|
+
type Node<T> = {
|
|
24
|
+
value: T;
|
|
25
|
+
next: Node<T> | null;
|
|
26
|
+
prev: Node<T> | null;
|
|
27
|
+
removed: boolean;
|
|
28
|
+
};
|
|
29
|
+
declare class LinkedQueue<T> {
|
|
30
|
+
private head;
|
|
31
|
+
private tail;
|
|
32
|
+
private len;
|
|
33
|
+
get length(): number;
|
|
34
|
+
isEmpty(): boolean;
|
|
35
|
+
push(value: T): Node<T>;
|
|
36
|
+
shift(): T | undefined;
|
|
37
|
+
remove(node: Node<T>): void;
|
|
38
|
+
private unlink;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
declare class RingBuffer<T> {
|
|
42
|
+
private buf;
|
|
43
|
+
private head;
|
|
44
|
+
private tail;
|
|
45
|
+
private size_;
|
|
46
|
+
constructor(initialCapacity?: number);
|
|
47
|
+
get length(): number;
|
|
48
|
+
get capacity(): number;
|
|
49
|
+
isEmpty(): boolean;
|
|
50
|
+
push(value: T): void;
|
|
51
|
+
shift(): T | undefined;
|
|
52
|
+
clear(): void;
|
|
53
|
+
private grow;
|
|
54
|
+
private nextPow2;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
declare function buffer<R, E, A>(stream: ZStream<{} & R, E, A>, capacity: number, strategy?: "backpressure" | "dropping" | "sliding"): ZStream<{} & R, E, A>;
|
|
58
|
+
|
|
59
|
+
type AnyFiber<R, E, A> = ReturnType<Scope<R>["fork"]>;
|
|
60
|
+
/**
|
|
61
|
+
* race(A, B):
|
|
62
|
+
* - corre A y B en paralelo
|
|
63
|
+
* - el primero que termine gana
|
|
64
|
+
* - el otro es cancelado
|
|
65
|
+
*/
|
|
66
|
+
declare function race<R, E, A>(left: Async<R, E, A>, right: Async<R, E, A>, parentScope: Scope<R>): Async<R, E | Interrupted, A>;
|
|
67
|
+
/**
|
|
68
|
+
* zipPar(A, B):
|
|
69
|
+
* - corre A y B en paralelo
|
|
70
|
+
* - si ambas terminan bien → éxito con (A, B)
|
|
71
|
+
* - si una falla → cancelar todo y devolver fallo
|
|
72
|
+
*/
|
|
73
|
+
declare function zipPar<R, E, A, B>(left: Async<R, E, A>, right: Async<R, E, B>, parentScope: Scope<R>): Async<R, E | Interrupted, [A, B]>;
|
|
74
|
+
/**
|
|
75
|
+
* collectAllPar:
|
|
76
|
+
* - corre todos en paralelo
|
|
77
|
+
* - si uno falla → cancela todos
|
|
78
|
+
* - si todos terminan bien → devuelve array de resultados
|
|
79
|
+
*/
|
|
80
|
+
declare function collectAllPar<R, E, A>(effects: ReadonlyArray<Async<R, E, A>>, parentScope: Scope<R>): Async<R, E | Interrupted, A[]>;
|
|
81
|
+
declare function raceWith<R, E, A, B, C>(left: Async<R, E, A>, right: Async<R, E, B>, parentScope: Scope<R>, onLeft: (exit: Exit<E | Interrupted, A>, rightFiber: AnyFiber<R, E | Interrupted, B>, scope: Scope<R>) => Async<R, E | Interrupted, C>, onRight: (exit: Exit<E | Interrupted, B>, leftFiber: AnyFiber<R, E | Interrupted, A>, scope: Scope<R>) => Async<R, E | Interrupted, C>): Async<R, E | Interrupted, C>;
|
|
82
|
+
|
|
83
|
+
type Strategy = "backpressure" | "dropping" | "sliding";
|
|
84
|
+
type QueueClosed = {
|
|
85
|
+
_tag: "QueueClosed";
|
|
86
|
+
};
|
|
87
|
+
type Queue<A> = {
|
|
88
|
+
offer: (a: A) => Async<unknown, never, boolean>;
|
|
89
|
+
take: () => Async<unknown, QueueClosed, A>;
|
|
90
|
+
size: () => number;
|
|
91
|
+
shutdown: () => void;
|
|
92
|
+
};
|
|
93
|
+
declare function bounded<A>(capacity: number, strategy?: Strategy): Async<unknown, unknown, Queue<A>>;
|
|
94
|
+
|
|
95
|
+
type HubStrategy = "BackPressure" | "Dropping" | "Sliding";
|
|
96
|
+
type HubClosed = {
|
|
97
|
+
_tag: "HubClosed";
|
|
98
|
+
};
|
|
99
|
+
type Subscription<A> = Queue<A> & {
|
|
100
|
+
unsubscribe: () => void;
|
|
101
|
+
};
|
|
102
|
+
type Hub<A> = {
|
|
103
|
+
publish: (a: A) => Async<unknown, never, boolean>;
|
|
104
|
+
publishAll: (as: Iterable<A>) => Async<unknown, never, boolean>;
|
|
105
|
+
subscribe: () => Async<unknown, HubClosed, Subscription<A>>;
|
|
106
|
+
shutdown: () => Async<unknown, any, any>;
|
|
107
|
+
};
|
|
108
|
+
declare function makeHub<A>(capacity: number, strategy?: HubStrategy): Hub<A>;
|
|
109
|
+
declare const broadcast: typeof makeHub;
|
|
110
|
+
declare function broadcastToHub<R, E, A>(stream: ZStream<R, E, A>, hub: Hub<A>): Async<R, E, void>;
|
|
111
|
+
declare function fromHub<A>(hub: Hub<A>): ZStream<unknown, HubClosed, A>;
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* ZPipeline-style transformer.
|
|
115
|
+
*
|
|
116
|
+
* A pipeline that consumes `In` and produces `Out`, potentially requiring `Rp` and failing with `Ep`.
|
|
117
|
+
* When applied to a stream `ZStream<R, E, In>`, the result is `ZStream<R & Rp, E | Ep, Out>`.
|
|
118
|
+
*/
|
|
119
|
+
type ZPipeline<Rp, Ep, In, Out> = <R, E>(input: ZStream<R, E, In>) => ZStream<R & Rp, E | Ep, Out>;
|
|
120
|
+
/** Apply a pipeline to a stream (alias of `pipeline(stream)`). */
|
|
121
|
+
declare function via<R, E, A, Rp, Ep, B>(stream: ZStream<R, E, A>, pipeline: ZPipeline<Rp, Ep, A, B>): ZStream<R & Rp, E | Ep, B>;
|
|
122
|
+
/** Compose pipelines left-to-right (p1 >>> p2). */
|
|
123
|
+
declare function andThen<R1, E1, In, Mid, R2, E2, Out>(p1: ZPipeline<R1, E1, In, Mid>, p2: ZPipeline<R2, E2, Mid, Out>): ZPipeline<R1 & R2, E1 | E2, In, Out>;
|
|
124
|
+
/** Compose pipelines right-to-left (p2 <<< p1). */
|
|
125
|
+
declare function compose<R1, E1, In, Mid, R2, E2, Out>(p2: ZPipeline<R2, E2, Mid, Out>, p1: ZPipeline<R1, E1, In, Mid>): ZPipeline<R1 & R2, E1 | E2, In, Out>;
|
|
126
|
+
/** Identity pipeline. */
|
|
127
|
+
declare function identity<A>(): ZPipeline<unknown, never, A, A>;
|
|
128
|
+
/** Map elements. */
|
|
129
|
+
declare function mapP<A, B>(f: (a: A) => B): ZPipeline<unknown, never, A, B>;
|
|
130
|
+
/** Filter elements, preserving end/error. */
|
|
131
|
+
declare function filterP<A>(pred: (a: A) => boolean): ZPipeline<unknown, never, A, A>;
|
|
132
|
+
/**
|
|
133
|
+
* Filter-map (aka collectSome).
|
|
134
|
+
* If `f(a)` returns None, the element is dropped.
|
|
135
|
+
*/
|
|
136
|
+
declare function filterMapP<A, B>(f: (a: A) => Option<B>): ZPipeline<unknown, never, A, B>;
|
|
137
|
+
/** Take at most N elements. */
|
|
138
|
+
declare function takeP<A>(n: number): ZPipeline<unknown, never, A, A>;
|
|
139
|
+
/** Drop the first N elements. */
|
|
140
|
+
declare function dropP<A>(n: number): ZPipeline<unknown, never, A, A>;
|
|
141
|
+
/**
|
|
142
|
+
* Map elements with an effect (sequential).
|
|
143
|
+
*
|
|
144
|
+
* - Upstream end => end
|
|
145
|
+
* - Upstream error E => fail(E)
|
|
146
|
+
* - f(a) fails with Ep => fail(Ep)
|
|
147
|
+
*/
|
|
148
|
+
declare function mapEffectP<Rp, Ep, A, B>(f: (a: A) => Async<Rp, Ep, B>): ZPipeline<Rp, Ep, A, B>;
|
|
149
|
+
/** Tap each element with an effect, preserving the element. */
|
|
150
|
+
declare function tapEffectP<Rp, Ep, A>(f: (a: A) => Async<Rp, Ep, any>): ZPipeline<Rp, Ep, A, A>;
|
|
151
|
+
/** Buffer upstream using your existing queue-based buffer implementation. */
|
|
152
|
+
declare function bufferP<A>(capacity: number, strategy?: "backpressure" | "dropping" | "sliding"): ZPipeline<unknown, never, A, A>;
|
|
153
|
+
/**
|
|
154
|
+
* Group elements into arrays of size `n` (last chunk may be smaller).
|
|
155
|
+
* Example: [1,2,3,4,5].grouped(2) => [1,2],[3,4],[5]
|
|
156
|
+
*/
|
|
157
|
+
declare function groupedP<A>(n: number): ZPipeline<unknown, never, A, A[]>;
|
|
158
|
+
|
|
159
|
+
export { Async, type BrassError, Exit, Fiber, type Hub, type HubClosed, type HubStrategy, Interrupted, LinkedQueue, type Node, Option, type Queue, type QueueClosed, RingBuffer, Scheduler, Scope, type Strategy, type Subscription, type ZPipeline, ZStream, andThen, bounded, broadcast, broadcastToHub, buffer, bufferP, collectAllPar, compose, dropP, filterMapP, filterP, fork, from, fromCallback, fromHub, fromPromise, fromPromiseAbortable, groupedP, identity, makeHub, mapEffectP, mapP, race, raceWith, takeP, tapEffectP, toPromise, tryPromiseAbortable, unsafeRunAsync, via, zipPar };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { A as Async, S as Scheduler, F as Fiber, E as Exit, I as Interrupted } from './stream-
|
|
2
|
-
export {
|
|
1
|
+
import { A as Async, S as Scheduler, F as Fiber, E as Exit, I as Interrupted, Z as ZStream, a as Scope, O as Option } from './stream-CPScJVP0.js';
|
|
2
|
+
export { y as AsyncWithPromise, K as CancelToken, J as Canceler, _ as Concat, Y as Emit, X as Empty, P as FiberId, Q as FiberStatus, $ as Flatten, a0 as FromPull, a1 as Merge, N as None, a3 as Normalize, R as RuntimeFiber, T as ScopeId, a2 as Scoped, D as Some, V as Task, b as ZIO, w as acquireRelease, r as async, j as asyncCatchAll, n as asyncFail, v as asyncFlatMap, i as asyncFold, x as asyncInterruptible, t as asyncMap, k as asyncMapError, l as asyncSucceed, p as asyncSync, q as asyncTotal, g as catchAll, ak as collectStream, ab as concatStream, aa as emitStream, a9 as emptyStream, h as end, f as fail, d as flatMap, ac as flattenStream, ai as foreachStream, aj as fromArray, a5 as fromPull, W as globalScheduler, M as linkAbortController, L as makeCancelToken, a7 as managedStream, m as map, B as mapAsync, e as mapError, af as mapStream, C as mapTryAsync, ad as merge, a8 as mergeStream, G as none, o as orElseOptional, ag as rangeStream, H as some, al as streamFromReadableStream, s as succeed, c as sync, ae as uncons, u as unit, a6 as unwrapScoped, a4 as widenOpt, z as withAsyncPromise, U as withScope, ah as zip } from './stream-CPScJVP0.js';
|
|
3
3
|
|
|
4
4
|
type NodeCallback<A> = (err: Error | null, result: A) => void;
|
|
5
5
|
declare function from<A>(f: (cb: NodeCallback<A>) => void): Async<{}, Error, A>;
|
|
@@ -20,4 +20,140 @@ declare function tryPromiseAbortable<R, A>(thunk: (env: R, signal: AbortSignal)
|
|
|
20
20
|
declare function fromPromiseAbortable<E, A>(thunk: (signal: AbortSignal) => Promise<A>, onError: (e: unknown) => E): Async<unknown, E, A>;
|
|
21
21
|
declare function fromPromiseAbortable<R, E, A>(thunk: (env: R, signal: AbortSignal) => Promise<A>, onError: (e: unknown) => E): Async<R, E, A>;
|
|
22
22
|
|
|
23
|
-
|
|
23
|
+
type Node<T> = {
|
|
24
|
+
value: T;
|
|
25
|
+
next: Node<T> | null;
|
|
26
|
+
prev: Node<T> | null;
|
|
27
|
+
removed: boolean;
|
|
28
|
+
};
|
|
29
|
+
declare class LinkedQueue<T> {
|
|
30
|
+
private head;
|
|
31
|
+
private tail;
|
|
32
|
+
private len;
|
|
33
|
+
get length(): number;
|
|
34
|
+
isEmpty(): boolean;
|
|
35
|
+
push(value: T): Node<T>;
|
|
36
|
+
shift(): T | undefined;
|
|
37
|
+
remove(node: Node<T>): void;
|
|
38
|
+
private unlink;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
declare class RingBuffer<T> {
|
|
42
|
+
private buf;
|
|
43
|
+
private head;
|
|
44
|
+
private tail;
|
|
45
|
+
private size_;
|
|
46
|
+
constructor(initialCapacity?: number);
|
|
47
|
+
get length(): number;
|
|
48
|
+
get capacity(): number;
|
|
49
|
+
isEmpty(): boolean;
|
|
50
|
+
push(value: T): void;
|
|
51
|
+
shift(): T | undefined;
|
|
52
|
+
clear(): void;
|
|
53
|
+
private grow;
|
|
54
|
+
private nextPow2;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
declare function buffer<R, E, A>(stream: ZStream<{} & R, E, A>, capacity: number, strategy?: "backpressure" | "dropping" | "sliding"): ZStream<{} & R, E, A>;
|
|
58
|
+
|
|
59
|
+
type AnyFiber<R, E, A> = ReturnType<Scope<R>["fork"]>;
|
|
60
|
+
/**
|
|
61
|
+
* race(A, B):
|
|
62
|
+
* - corre A y B en paralelo
|
|
63
|
+
* - el primero que termine gana
|
|
64
|
+
* - el otro es cancelado
|
|
65
|
+
*/
|
|
66
|
+
declare function race<R, E, A>(left: Async<R, E, A>, right: Async<R, E, A>, parentScope: Scope<R>): Async<R, E | Interrupted, A>;
|
|
67
|
+
/**
|
|
68
|
+
* zipPar(A, B):
|
|
69
|
+
* - corre A y B en paralelo
|
|
70
|
+
* - si ambas terminan bien → éxito con (A, B)
|
|
71
|
+
* - si una falla → cancelar todo y devolver fallo
|
|
72
|
+
*/
|
|
73
|
+
declare function zipPar<R, E, A, B>(left: Async<R, E, A>, right: Async<R, E, B>, parentScope: Scope<R>): Async<R, E | Interrupted, [A, B]>;
|
|
74
|
+
/**
|
|
75
|
+
* collectAllPar:
|
|
76
|
+
* - corre todos en paralelo
|
|
77
|
+
* - si uno falla → cancela todos
|
|
78
|
+
* - si todos terminan bien → devuelve array de resultados
|
|
79
|
+
*/
|
|
80
|
+
declare function collectAllPar<R, E, A>(effects: ReadonlyArray<Async<R, E, A>>, parentScope: Scope<R>): Async<R, E | Interrupted, A[]>;
|
|
81
|
+
declare function raceWith<R, E, A, B, C>(left: Async<R, E, A>, right: Async<R, E, B>, parentScope: Scope<R>, onLeft: (exit: Exit<E | Interrupted, A>, rightFiber: AnyFiber<R, E | Interrupted, B>, scope: Scope<R>) => Async<R, E | Interrupted, C>, onRight: (exit: Exit<E | Interrupted, B>, leftFiber: AnyFiber<R, E | Interrupted, A>, scope: Scope<R>) => Async<R, E | Interrupted, C>): Async<R, E | Interrupted, C>;
|
|
82
|
+
|
|
83
|
+
type Strategy = "backpressure" | "dropping" | "sliding";
|
|
84
|
+
type QueueClosed = {
|
|
85
|
+
_tag: "QueueClosed";
|
|
86
|
+
};
|
|
87
|
+
type Queue<A> = {
|
|
88
|
+
offer: (a: A) => Async<unknown, never, boolean>;
|
|
89
|
+
take: () => Async<unknown, QueueClosed, A>;
|
|
90
|
+
size: () => number;
|
|
91
|
+
shutdown: () => void;
|
|
92
|
+
};
|
|
93
|
+
declare function bounded<A>(capacity: number, strategy?: Strategy): Async<unknown, unknown, Queue<A>>;
|
|
94
|
+
|
|
95
|
+
type HubStrategy = "BackPressure" | "Dropping" | "Sliding";
|
|
96
|
+
type HubClosed = {
|
|
97
|
+
_tag: "HubClosed";
|
|
98
|
+
};
|
|
99
|
+
type Subscription<A> = Queue<A> & {
|
|
100
|
+
unsubscribe: () => void;
|
|
101
|
+
};
|
|
102
|
+
type Hub<A> = {
|
|
103
|
+
publish: (a: A) => Async<unknown, never, boolean>;
|
|
104
|
+
publishAll: (as: Iterable<A>) => Async<unknown, never, boolean>;
|
|
105
|
+
subscribe: () => Async<unknown, HubClosed, Subscription<A>>;
|
|
106
|
+
shutdown: () => Async<unknown, any, any>;
|
|
107
|
+
};
|
|
108
|
+
declare function makeHub<A>(capacity: number, strategy?: HubStrategy): Hub<A>;
|
|
109
|
+
declare const broadcast: typeof makeHub;
|
|
110
|
+
declare function broadcastToHub<R, E, A>(stream: ZStream<R, E, A>, hub: Hub<A>): Async<R, E, void>;
|
|
111
|
+
declare function fromHub<A>(hub: Hub<A>): ZStream<unknown, HubClosed, A>;
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* ZPipeline-style transformer.
|
|
115
|
+
*
|
|
116
|
+
* A pipeline that consumes `In` and produces `Out`, potentially requiring `Rp` and failing with `Ep`.
|
|
117
|
+
* When applied to a stream `ZStream<R, E, In>`, the result is `ZStream<R & Rp, E | Ep, Out>`.
|
|
118
|
+
*/
|
|
119
|
+
type ZPipeline<Rp, Ep, In, Out> = <R, E>(input: ZStream<R, E, In>) => ZStream<R & Rp, E | Ep, Out>;
|
|
120
|
+
/** Apply a pipeline to a stream (alias of `pipeline(stream)`). */
|
|
121
|
+
declare function via<R, E, A, Rp, Ep, B>(stream: ZStream<R, E, A>, pipeline: ZPipeline<Rp, Ep, A, B>): ZStream<R & Rp, E | Ep, B>;
|
|
122
|
+
/** Compose pipelines left-to-right (p1 >>> p2). */
|
|
123
|
+
declare function andThen<R1, E1, In, Mid, R2, E2, Out>(p1: ZPipeline<R1, E1, In, Mid>, p2: ZPipeline<R2, E2, Mid, Out>): ZPipeline<R1 & R2, E1 | E2, In, Out>;
|
|
124
|
+
/** Compose pipelines right-to-left (p2 <<< p1). */
|
|
125
|
+
declare function compose<R1, E1, In, Mid, R2, E2, Out>(p2: ZPipeline<R2, E2, Mid, Out>, p1: ZPipeline<R1, E1, In, Mid>): ZPipeline<R1 & R2, E1 | E2, In, Out>;
|
|
126
|
+
/** Identity pipeline. */
|
|
127
|
+
declare function identity<A>(): ZPipeline<unknown, never, A, A>;
|
|
128
|
+
/** Map elements. */
|
|
129
|
+
declare function mapP<A, B>(f: (a: A) => B): ZPipeline<unknown, never, A, B>;
|
|
130
|
+
/** Filter elements, preserving end/error. */
|
|
131
|
+
declare function filterP<A>(pred: (a: A) => boolean): ZPipeline<unknown, never, A, A>;
|
|
132
|
+
/**
|
|
133
|
+
* Filter-map (aka collectSome).
|
|
134
|
+
* If `f(a)` returns None, the element is dropped.
|
|
135
|
+
*/
|
|
136
|
+
declare function filterMapP<A, B>(f: (a: A) => Option<B>): ZPipeline<unknown, never, A, B>;
|
|
137
|
+
/** Take at most N elements. */
|
|
138
|
+
declare function takeP<A>(n: number): ZPipeline<unknown, never, A, A>;
|
|
139
|
+
/** Drop the first N elements. */
|
|
140
|
+
declare function dropP<A>(n: number): ZPipeline<unknown, never, A, A>;
|
|
141
|
+
/**
|
|
142
|
+
* Map elements with an effect (sequential).
|
|
143
|
+
*
|
|
144
|
+
* - Upstream end => end
|
|
145
|
+
* - Upstream error E => fail(E)
|
|
146
|
+
* - f(a) fails with Ep => fail(Ep)
|
|
147
|
+
*/
|
|
148
|
+
declare function mapEffectP<Rp, Ep, A, B>(f: (a: A) => Async<Rp, Ep, B>): ZPipeline<Rp, Ep, A, B>;
|
|
149
|
+
/** Tap each element with an effect, preserving the element. */
|
|
150
|
+
declare function tapEffectP<Rp, Ep, A>(f: (a: A) => Async<Rp, Ep, any>): ZPipeline<Rp, Ep, A, A>;
|
|
151
|
+
/** Buffer upstream using your existing queue-based buffer implementation. */
|
|
152
|
+
declare function bufferP<A>(capacity: number, strategy?: "backpressure" | "dropping" | "sliding"): ZPipeline<unknown, never, A, A>;
|
|
153
|
+
/**
|
|
154
|
+
* Group elements into arrays of size `n` (last chunk may be smaller).
|
|
155
|
+
* Example: [1,2,3,4,5].grouped(2) => [1,2],[3,4],[5]
|
|
156
|
+
*/
|
|
157
|
+
declare function groupedP<A>(n: number): ZPipeline<unknown, never, A, A[]>;
|
|
158
|
+
|
|
159
|
+
export { Async, type BrassError, Exit, Fiber, type Hub, type HubClosed, type HubStrategy, Interrupted, LinkedQueue, type Node, Option, type Queue, type QueueClosed, RingBuffer, Scheduler, Scope, type Strategy, type Subscription, type ZPipeline, ZStream, andThen, bounded, broadcast, broadcastToHub, buffer, bufferP, collectAllPar, compose, dropP, filterMapP, filterP, fork, from, fromCallback, fromHub, fromPromise, fromPromiseAbortable, groupedP, identity, makeHub, mapEffectP, mapP, race, raceWith, takeP, tapEffectP, toPromise, tryPromiseAbortable, unsafeRunAsync, via, zipPar };
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
'use strict';var chunk3NPW2C22_js=require('./chunk-3NPW2C22.js');function Ce(){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:()=>{e||(e=true,r.forEach(n=>n()),r.clear());}}}function pe(e,r){return e.onCancel(()=>r.abort())}Object.defineProperty(exports,"RuntimeFiber",{enumerable:true,get:function(){return chunk3NPW2C22_js.D}});Object.defineProperty(exports,"Scheduler",{enumerable:true,get:function(){return chunk3NPW2C22_js.B}});Object.defineProperty(exports,"Scope",{enumerable:true,get:function(){return chunk3NPW2C22_js.M}});Object.defineProperty(exports,"acquireRelease",{enumerable:true,get:function(){return chunk3NPW2C22_js.l}});Object.defineProperty(exports,"async",{enumerable:true,get:function(){return chunk3NPW2C22_js.i}});Object.defineProperty(exports,"asyncCatchAll",{enumerable:true,get:function(){return chunk3NPW2C22_js.b}});Object.defineProperty(exports,"asyncFail",{enumerable:true,get:function(){return chunk3NPW2C22_js.f}});Object.defineProperty(exports,"asyncFlatMap",{enumerable:true,get:function(){return chunk3NPW2C22_js.k}});Object.defineProperty(exports,"asyncFold",{enumerable:true,get:function(){return chunk3NPW2C22_js.a}});Object.defineProperty(exports,"asyncInterruptible",{enumerable:true,get:function(){return chunk3NPW2C22_js.m}});Object.defineProperty(exports,"asyncMap",{enumerable:true,get:function(){return chunk3NPW2C22_js.j}});Object.defineProperty(exports,"asyncMapError",{enumerable:true,get:function(){return chunk3NPW2C22_js.c}});Object.defineProperty(exports,"asyncSucceed",{enumerable:true,get:function(){return chunk3NPW2C22_js.e}});Object.defineProperty(exports,"asyncSync",{enumerable:true,get:function(){return chunk3NPW2C22_js.g}});Object.defineProperty(exports,"asyncTotal",{enumerable:true,get:function(){return chunk3NPW2C22_js.h}});Object.defineProperty(exports,"catchAll",{enumerable:true,get:function(){return chunk3NPW2C22_js.y}});Object.defineProperty(exports,"collectStream",{enumerable:true,get:function(){return chunk3NPW2C22_js.ca}});Object.defineProperty(exports,"concatStream",{enumerable:true,get:function(){return chunk3NPW2C22_js.V}});Object.defineProperty(exports,"emitStream",{enumerable:true,get:function(){return chunk3NPW2C22_js.U}});Object.defineProperty(exports,"emptyStream",{enumerable:true,get:function(){return chunk3NPW2C22_js.T}});Object.defineProperty(exports,"end",{enumerable:true,get:function(){return chunk3NPW2C22_js.A}});Object.defineProperty(exports,"fail",{enumerable:true,get:function(){return chunk3NPW2C22_js.t}});Object.defineProperty(exports,"flatMap",{enumerable:true,get:function(){return chunk3NPW2C22_js.w}});Object.defineProperty(exports,"flattenStream",{enumerable:true,get:function(){return chunk3NPW2C22_js.W}});Object.defineProperty(exports,"foreachStream",{enumerable:true,get:function(){return chunk3NPW2C22_js.aa}});Object.defineProperty(exports,"fork",{enumerable:true,get:function(){return chunk3NPW2C22_js.F}});Object.defineProperty(exports,"from",{enumerable:true,get:function(){return chunk3NPW2C22_js.E}});Object.defineProperty(exports,"fromArray",{enumerable:true,get:function(){return chunk3NPW2C22_js.ba}});Object.defineProperty(exports,"fromCallback",{enumerable:true,get:function(){return chunk3NPW2C22_js.J}});Object.defineProperty(exports,"fromPromise",{enumerable:true,get:function(){return chunk3NPW2C22_js.I}});Object.defineProperty(exports,"fromPromiseAbortable",{enumerable:true,get:function(){return chunk3NPW2C22_js.L}});Object.defineProperty(exports,"fromPull",{enumerable:true,get:function(){return chunk3NPW2C22_js.P}});Object.defineProperty(exports,"globalScheduler",{enumerable:true,get:function(){return chunk3NPW2C22_js.C}});Object.defineProperty(exports,"managedStream",{enumerable:true,get:function(){return chunk3NPW2C22_js.R}});Object.defineProperty(exports,"map",{enumerable:true,get:function(){return chunk3NPW2C22_js.v}});Object.defineProperty(exports,"mapAsync",{enumerable:true,get:function(){return chunk3NPW2C22_js.o}});Object.defineProperty(exports,"mapError",{enumerable:true,get:function(){return chunk3NPW2C22_js.x}});Object.defineProperty(exports,"mapStream",{enumerable:true,get:function(){return chunk3NPW2C22_js.Z}});Object.defineProperty(exports,"mapTryAsync",{enumerable:true,get:function(){return chunk3NPW2C22_js.p}});Object.defineProperty(exports,"merge",{enumerable:true,get:function(){return chunk3NPW2C22_js.X}});Object.defineProperty(exports,"mergeStream",{enumerable:true,get:function(){return chunk3NPW2C22_js.S}});Object.defineProperty(exports,"none",{enumerable:true,get:function(){return chunk3NPW2C22_js.q}});Object.defineProperty(exports,"orElseOptional",{enumerable:true,get:function(){return chunk3NPW2C22_js.z}});Object.defineProperty(exports,"rangeStream",{enumerable:true,get:function(){return chunk3NPW2C22_js._}});Object.defineProperty(exports,"some",{enumerable:true,get:function(){return chunk3NPW2C22_js.r}});Object.defineProperty(exports,"streamFromReadableStream",{enumerable:true,get:function(){return chunk3NPW2C22_js.da}});Object.defineProperty(exports,"succeed",{enumerable:true,get:function(){return chunk3NPW2C22_js.s}});Object.defineProperty(exports,"sync",{enumerable:true,get:function(){return chunk3NPW2C22_js.u}});Object.defineProperty(exports,"toPromise",{enumerable:true,get:function(){return chunk3NPW2C22_js.H}});Object.defineProperty(exports,"tryPromiseAbortable",{enumerable:true,get:function(){return chunk3NPW2C22_js.K}});Object.defineProperty(exports,"uncons",{enumerable:true,get:function(){return chunk3NPW2C22_js.Y}});Object.defineProperty(exports,"unit",{enumerable:true,get:function(){return chunk3NPW2C22_js.d}});Object.defineProperty(exports,"unsafeRunAsync",{enumerable:true,get:function(){return chunk3NPW2C22_js.G}});Object.defineProperty(exports,"unwrapScoped",{enumerable:true,get:function(){return chunk3NPW2C22_js.Q}});Object.defineProperty(exports,"widenOpt",{enumerable:true,get:function(){return chunk3NPW2C22_js.O}});Object.defineProperty(exports,"withAsyncPromise",{enumerable:true,get:function(){return chunk3NPW2C22_js.n}});Object.defineProperty(exports,"withScope",{enumerable:true,get:function(){return chunk3NPW2C22_js.N}});Object.defineProperty(exports,"zip",{enumerable:true,get:function(){return chunk3NPW2C22_js.$}});exports.linkAbortController=pe;exports.makeCancelToken=Ce;
|
|
1
|
+
'use strict';var chunk2NVQIUW5_js=require('./chunk-2NVQIUW5.js');function Be(){let t=false,e=new Set;return {isCancelled:()=>t,onCancel:r=>{if(t){try{r();}catch{}return ()=>{}}return e.add(r),()=>{e.delete(r);}},cancel:()=>{t||(t=true,e.forEach(r=>r()),e.clear());}}}function He(t,e){return t.onCancel(()=>e.abort())}var v=class{head=null;tail=null;len=0;get length(){return this.len}isEmpty(){return this.len===0}push(e){let n={value:e,next:null,prev:this.tail,removed:false};return this.tail?this.tail.next=n:this.head=n,this.tail=n,this.len++,n}shift(){let e=this.head;if(e)return this.unlink(e),e.value}remove(e){e.removed||this.unlink(e);}unlink(e){e.removed=true;let{prev:n,next:r}=e;n?n.next=r:this.head=r,r?r.prev=n:this.tail=n,e.next=null,e.prev=null,this.len--;}};function w(t,e="backpressure"){return chunk2NVQIUW5_js.g(()=>M(t,e))}function M(t,e){let n=new chunk2NVQIUW5_js.B(t),r=false,s={_tag:"QueueClosed"},a=new v,o=new v,p=()=>{for(;o.length>0&&n.length>0;){let u=o.shift(),f=n.shift();u({_tag:"Success",value:f});}for(;a.length>0&&n.length<t&&o.length===0;){let u=a.shift();n.push(u.a),u.cb(true);}for(;o.length>0&&a.length>0;){let u=o.shift(),f=a.shift();f.cb(true),u({_tag:"Success",value:f.a});}};return {size:()=>n.length,shutdown:()=>{if(!r){for(r=true;o.length>0;)o.shift()({_tag:"Failure",error:s});for(;a.length>0;)a.shift().cb(false);n.clear();}},offer:u=>chunk2NVQIUW5_js.i((f,i)=>{if(r){i({_tag:"Success",value:false});return}if(o.length>0){o.shift()({_tag:"Success",value:u}),i({_tag:"Success",value:true});return}if(n.length<t){n.push(u),i({_tag:"Success",value:true}),p();return}if(e==="dropping"){i({_tag:"Success",value:false});return}if(e==="sliding"){n.shift(),n.push(u),i({_tag:"Success",value:true}),p();return}let m=a.push({a:u,cb:A=>i({_tag:"Success",value:A})});return ()=>{a.remove(m);}}),take:()=>chunk2NVQIUW5_js.i((u,f)=>{if(n.length>0){let A=n.shift();f({_tag:"Success",value:A}),p();return}if(a.length>0){let A=a.shift();A.cb(true),f({_tag:"Success",value:A.a});return}if(r){f({_tag:"Failure",error:s});return}let i=A=>f(A),m=o.push(i);return ()=>{o.remove(m);}})}}function F(t,e,n="backpressure"){let r=false,s=null,a=null,o=t,p=()=>chunk2NVQIUW5_js.a(chunk2NVQIUW5_js.ba(o),i=>chunk2NVQIUW5_js.e(i._tag==="None"?{_tag:"End"}:{_tag:"Fail",error:i.value}),([i,m])=>chunk2NVQIUW5_js.g(()=>(o=m,{_tag:"Elem",value:i}))),c=i=>chunk2NVQIUW5_js.k(w(e,n),m=>{s=m;let S=()=>chunk2NVQIUW5_js.k(p(),A=>chunk2NVQIUW5_js.k(s.offer(A),()=>A._tag==="End"||A._tag==="Fail"?chunk2NVQIUW5_js.e(void 0):S()));return a=chunk2NVQIUW5_js.G(S(),i),r=true,chunk2NVQIUW5_js.e(void 0)}),u={_tag:"Async",register:(i,m)=>{(()=>{if(!r){chunk2NVQIUW5_js.G(c(i),i).join(()=>{f(i,m);});return}f(i,m);})();}};function f(i,m){let S=s.take();chunk2NVQIUW5_js.G(S,i).join(A=>{if(A._tag!=="Success")return;let _=A.value;switch(_._tag){case "Elem":m({_tag:"Success",value:[_.value,chunk2NVQIUW5_js.U(u)]});return;case "End":a?.interrupt?.(),m({_tag:"Failure",error:chunk2NVQIUW5_js.q});return;case "Fail":a?.interrupt?.(),m({_tag:"Failure",error:chunk2NVQIUW5_js.r(_.error)});return}});}return chunk2NVQIUW5_js.U(u)}var I=t=>t==="BackPressure"?"backpressure":t==="Dropping"?"dropping":"sliding";function N(t,e="BackPressure"){let n=new Set,r=false,s=c=>{if(r)return chunk2NVQIUW5_js.e(false);let u=Array.from(n),f=chunk2NVQIUW5_js.e(true);return u.forEach(i=>{f=chunk2NVQIUW5_js.k(f,m=>chunk2NVQIUW5_js.k(i.offer(c),S=>chunk2NVQIUW5_js.e(m&&S)));}),f};return {publish:s,publishAll:c=>{let u=chunk2NVQIUW5_js.e(true),f=c[Symbol.iterator]();for(;;){let i=f.next();if(i.done)break;let m=i.value;u=chunk2NVQIUW5_js.k(u,S=>chunk2NVQIUW5_js.k(s(m),A=>chunk2NVQIUW5_js.e(S&&A)));}return u},subscribe:()=>r?chunk2NVQIUW5_js.h(()=>{throw {_tag:"HubClosed"}}):chunk2NVQIUW5_js.k(w(t,I(e)),c=>chunk2NVQIUW5_js.g(()=>(n.add(c),{...c,unsubscribe:()=>{n.has(c)&&(n.delete(c),c.shutdown());}}))),shutdown:()=>chunk2NVQIUW5_js.g(()=>{r||(r=true,Array.from(n).forEach(c=>c.shutdown()),n.clear());})}}var ln=N;function cn(t,e){return chunk2NVQIUW5_js.fa(t,n=>chunk2NVQIUW5_js.k(e.publish(n),()=>chunk2NVQIUW5_js.e(void 0)))}function pn(t){return chunk2NVQIUW5_js.W(chunk2NVQIUW5_js.k(t.subscribe(),e=>{let n=chunk2NVQIUW5_js.U(chunk2NVQIUW5_js.k(chunk2NVQIUW5_js.c(e.take(),r=>chunk2NVQIUW5_js.q),r=>chunk2NVQIUW5_js.e([r,n])));return chunk2NVQIUW5_js.e({stream:n,release:r=>chunk2NVQIUW5_js.g(()=>e.unsubscribe())})}))}function bn(t,e){return e(t)}function z(t,e){return(n=>e(t(n)))}function gn(t,e){return z(e,t)}function vn(){return(t=>t)}function xn(t){return(e=>{let n=r=>chunk2NVQIUW5_js.U(chunk2NVQIUW5_js.a(chunk2NVQIUW5_js.ba(r),s=>chunk2NVQIUW5_js.f(s),([s,a])=>chunk2NVQIUW5_js.e([t(s),n(a)])));return n(e)})}function kn(t){return(e=>{let n=s=>chunk2NVQIUW5_js.a(chunk2NVQIUW5_js.ba(s),a=>chunk2NVQIUW5_js.f(a),([a,o])=>t(a)?chunk2NVQIUW5_js.e([a,r(o)]):n(o)),r=s=>chunk2NVQIUW5_js.U(n(s));return r(e)})}function Zn(t){return(e=>{let n=s=>chunk2NVQIUW5_js.a(chunk2NVQIUW5_js.ba(s),a=>chunk2NVQIUW5_js.f(a),([a,o])=>{let p=t(a);return p._tag==="Some"?chunk2NVQIUW5_js.e([p.value,r(o)]):n(o)}),r=s=>chunk2NVQIUW5_js.U(n(s));return r(e)})}function wn(t){let e=Math.max(0,t|0);return(n=>{let r=(s,a)=>a<=0?chunk2NVQIUW5_js.Y():chunk2NVQIUW5_js.U(chunk2NVQIUW5_js.a(chunk2NVQIUW5_js.ba(s),o=>chunk2NVQIUW5_js.f(o),([o,p])=>chunk2NVQIUW5_js.e([o,r(p,a-1)])));return r(n,e)})}function _n(t){let e=Math.max(0,t|0);return(n=>{let r=(s,a)=>a<=0?s:chunk2NVQIUW5_js.U(chunk2NVQIUW5_js.a(chunk2NVQIUW5_js.ba(s),o=>chunk2NVQIUW5_js.f(o),([o,p])=>chunk2NVQIUW5_js.ba(r(p,a-1))));return r(n,e)})}function D(t){return(e=>{let n=r=>chunk2NVQIUW5_js.U(chunk2NVQIUW5_js.a(chunk2NVQIUW5_js.c(chunk2NVQIUW5_js.ba(r),s=>chunk2NVQIUW5_js.T(s)),s=>chunk2NVQIUW5_js.f(s),([s,a])=>chunk2NVQIUW5_js.a(chunk2NVQIUW5_js.c(t(s),o=>chunk2NVQIUW5_js.r(o)),o=>chunk2NVQIUW5_js.f(o),o=>chunk2NVQIUW5_js.e([o,n(a)]))));return n(e)})}function Cn(t){return D(e=>chunk2NVQIUW5_js.k(t(e),()=>chunk2NVQIUW5_js.e(e)))}function Pn(t,e="backpressure"){return(n=>F(n,t,e))}function On(t){let e=Math.max(1,t|0);return(n=>{let r=(a,o,p)=>o<=0?chunk2NVQIUW5_js.e({chunk:p,rest:a}):chunk2NVQIUW5_js.a(chunk2NVQIUW5_js.ba(a),c=>c._tag==="None"?chunk2NVQIUW5_js.e({chunk:p,rest:chunk2NVQIUW5_js.Y()}):chunk2NVQIUW5_js.f(c),([c,u])=>r(u,o-1,[...p,c])),s=a=>chunk2NVQIUW5_js.U(chunk2NVQIUW5_js.a(chunk2NVQIUW5_js.ba(a),o=>chunk2NVQIUW5_js.f(o),([o,p])=>chunk2NVQIUW5_js.k(r(p,e-1,[o]),({chunk:c,rest:u})=>chunk2NVQIUW5_js.e([c,s(u)]))));return s(n)})}Object.defineProperty(exports,"RingBuffer",{enumerable:true,get:function(){return chunk2NVQIUW5_js.B}});Object.defineProperty(exports,"RuntimeFiber",{enumerable:true,get:function(){return chunk2NVQIUW5_js.E}});Object.defineProperty(exports,"Scheduler",{enumerable:true,get:function(){return chunk2NVQIUW5_js.C}});Object.defineProperty(exports,"Scope",{enumerable:true,get:function(){return chunk2NVQIUW5_js.N}});Object.defineProperty(exports,"acquireRelease",{enumerable:true,get:function(){return chunk2NVQIUW5_js.l}});Object.defineProperty(exports,"async",{enumerable:true,get:function(){return chunk2NVQIUW5_js.i}});Object.defineProperty(exports,"asyncCatchAll",{enumerable:true,get:function(){return chunk2NVQIUW5_js.b}});Object.defineProperty(exports,"asyncFail",{enumerable:true,get:function(){return chunk2NVQIUW5_js.f}});Object.defineProperty(exports,"asyncFlatMap",{enumerable:true,get:function(){return chunk2NVQIUW5_js.k}});Object.defineProperty(exports,"asyncFold",{enumerable:true,get:function(){return chunk2NVQIUW5_js.a}});Object.defineProperty(exports,"asyncInterruptible",{enumerable:true,get:function(){return chunk2NVQIUW5_js.m}});Object.defineProperty(exports,"asyncMap",{enumerable:true,get:function(){return chunk2NVQIUW5_js.j}});Object.defineProperty(exports,"asyncMapError",{enumerable:true,get:function(){return chunk2NVQIUW5_js.c}});Object.defineProperty(exports,"asyncSucceed",{enumerable:true,get:function(){return chunk2NVQIUW5_js.e}});Object.defineProperty(exports,"asyncSync",{enumerable:true,get:function(){return chunk2NVQIUW5_js.g}});Object.defineProperty(exports,"asyncTotal",{enumerable:true,get:function(){return chunk2NVQIUW5_js.h}});Object.defineProperty(exports,"catchAll",{enumerable:true,get:function(){return chunk2NVQIUW5_js.y}});Object.defineProperty(exports,"collectAllPar",{enumerable:true,get:function(){return chunk2NVQIUW5_js.R}});Object.defineProperty(exports,"collectStream",{enumerable:true,get:function(){return chunk2NVQIUW5_js.ha}});Object.defineProperty(exports,"concatStream",{enumerable:true,get:function(){return chunk2NVQIUW5_js._}});Object.defineProperty(exports,"emitStream",{enumerable:true,get:function(){return chunk2NVQIUW5_js.Z}});Object.defineProperty(exports,"emptyStream",{enumerable:true,get:function(){return chunk2NVQIUW5_js.Y}});Object.defineProperty(exports,"end",{enumerable:true,get:function(){return chunk2NVQIUW5_js.A}});Object.defineProperty(exports,"fail",{enumerable:true,get:function(){return chunk2NVQIUW5_js.t}});Object.defineProperty(exports,"flatMap",{enumerable:true,get:function(){return chunk2NVQIUW5_js.w}});Object.defineProperty(exports,"flattenStream",{enumerable:true,get:function(){return chunk2NVQIUW5_js.$}});Object.defineProperty(exports,"foreachStream",{enumerable:true,get:function(){return chunk2NVQIUW5_js.fa}});Object.defineProperty(exports,"fork",{enumerable:true,get:function(){return chunk2NVQIUW5_js.G}});Object.defineProperty(exports,"from",{enumerable:true,get:function(){return chunk2NVQIUW5_js.F}});Object.defineProperty(exports,"fromArray",{enumerable:true,get:function(){return chunk2NVQIUW5_js.ga}});Object.defineProperty(exports,"fromCallback",{enumerable:true,get:function(){return chunk2NVQIUW5_js.K}});Object.defineProperty(exports,"fromPromise",{enumerable:true,get:function(){return chunk2NVQIUW5_js.J}});Object.defineProperty(exports,"fromPromiseAbortable",{enumerable:true,get:function(){return chunk2NVQIUW5_js.M}});Object.defineProperty(exports,"fromPull",{enumerable:true,get:function(){return chunk2NVQIUW5_js.U}});Object.defineProperty(exports,"globalScheduler",{enumerable:true,get:function(){return chunk2NVQIUW5_js.D}});Object.defineProperty(exports,"managedStream",{enumerable:true,get:function(){return chunk2NVQIUW5_js.W}});Object.defineProperty(exports,"map",{enumerable:true,get:function(){return chunk2NVQIUW5_js.v}});Object.defineProperty(exports,"mapAsync",{enumerable:true,get:function(){return chunk2NVQIUW5_js.o}});Object.defineProperty(exports,"mapError",{enumerable:true,get:function(){return chunk2NVQIUW5_js.x}});Object.defineProperty(exports,"mapStream",{enumerable:true,get:function(){return chunk2NVQIUW5_js.ca}});Object.defineProperty(exports,"mapTryAsync",{enumerable:true,get:function(){return chunk2NVQIUW5_js.p}});Object.defineProperty(exports,"merge",{enumerable:true,get:function(){return chunk2NVQIUW5_js.aa}});Object.defineProperty(exports,"mergeStream",{enumerable:true,get:function(){return chunk2NVQIUW5_js.X}});Object.defineProperty(exports,"none",{enumerable:true,get:function(){return chunk2NVQIUW5_js.q}});Object.defineProperty(exports,"orElseOptional",{enumerable:true,get:function(){return chunk2NVQIUW5_js.z}});Object.defineProperty(exports,"race",{enumerable:true,get:function(){return chunk2NVQIUW5_js.P}});Object.defineProperty(exports,"raceWith",{enumerable:true,get:function(){return chunk2NVQIUW5_js.S}});Object.defineProperty(exports,"rangeStream",{enumerable:true,get:function(){return chunk2NVQIUW5_js.da}});Object.defineProperty(exports,"some",{enumerable:true,get:function(){return chunk2NVQIUW5_js.r}});Object.defineProperty(exports,"streamFromReadableStream",{enumerable:true,get:function(){return chunk2NVQIUW5_js.ia}});Object.defineProperty(exports,"succeed",{enumerable:true,get:function(){return chunk2NVQIUW5_js.s}});Object.defineProperty(exports,"sync",{enumerable:true,get:function(){return chunk2NVQIUW5_js.u}});Object.defineProperty(exports,"toPromise",{enumerable:true,get:function(){return chunk2NVQIUW5_js.I}});Object.defineProperty(exports,"tryPromiseAbortable",{enumerable:true,get:function(){return chunk2NVQIUW5_js.L}});Object.defineProperty(exports,"uncons",{enumerable:true,get:function(){return chunk2NVQIUW5_js.ba}});Object.defineProperty(exports,"unit",{enumerable:true,get:function(){return chunk2NVQIUW5_js.d}});Object.defineProperty(exports,"unsafeRunAsync",{enumerable:true,get:function(){return chunk2NVQIUW5_js.H}});Object.defineProperty(exports,"unwrapScoped",{enumerable:true,get:function(){return chunk2NVQIUW5_js.V}});Object.defineProperty(exports,"widenOpt",{enumerable:true,get:function(){return chunk2NVQIUW5_js.T}});Object.defineProperty(exports,"withAsyncPromise",{enumerable:true,get:function(){return chunk2NVQIUW5_js.n}});Object.defineProperty(exports,"withScope",{enumerable:true,get:function(){return chunk2NVQIUW5_js.O}});Object.defineProperty(exports,"zip",{enumerable:true,get:function(){return chunk2NVQIUW5_js.ea}});Object.defineProperty(exports,"zipPar",{enumerable:true,get:function(){return chunk2NVQIUW5_js.Q}});exports.LinkedQueue=v;exports.andThen=z;exports.bounded=w;exports.broadcast=ln;exports.broadcastToHub=cn;exports.buffer=F;exports.bufferP=Pn;exports.compose=gn;exports.dropP=_n;exports.filterMapP=Zn;exports.filterP=kn;exports.fromHub=pn;exports.groupedP=On;exports.identity=vn;exports.linkAbortController=He;exports.makeCancelToken=Be;exports.makeHub=N;exports.mapEffectP=D;exports.mapP=xn;exports.takeP=wn;exports.tapEffectP=Cn;exports.via=bn;
|
package/dist/index.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export{
|
|
1
|
+
import {g,B,i,U,h,k,e,fa,W,c,q,Y,G,r,a,ba,f,T}from'./chunk-JTRM4ZSS.mjs';export{B as RingBuffer,E as RuntimeFiber,C as Scheduler,N as Scope,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,y as catchAll,R as collectAllPar,ha as collectStream,_ as concatStream,Z as emitStream,Y as emptyStream,A as end,t as fail,w as flatMap,$ as flattenStream,fa as foreachStream,G as fork,F as from,ga as fromArray,K as fromCallback,J as fromPromise,M as fromPromiseAbortable,U as fromPull,D as globalScheduler,W as managedStream,v as map,o as mapAsync,x as mapError,ca as mapStream,p as mapTryAsync,aa as merge,X as mergeStream,q as none,z as orElseOptional,P as race,S as raceWith,da as rangeStream,r as some,ia as streamFromReadableStream,s as succeed,u as sync,I as toPromise,L as tryPromiseAbortable,ba as uncons,d as unit,H as unsafeRunAsync,V as unwrapScoped,T as widenOpt,n as withAsyncPromise,O as withScope,ea as zip,Q as zipPar}from'./chunk-JTRM4ZSS.mjs';function Be(){let t=false,e=new Set;return {isCancelled:()=>t,onCancel:r=>{if(t){try{r();}catch{}return ()=>{}}return e.add(r),()=>{e.delete(r);}},cancel:()=>{t||(t=true,e.forEach(r=>r()),e.clear());}}}function He(t,e){return t.onCancel(()=>e.abort())}var v=class{head=null;tail=null;len=0;get length(){return this.len}isEmpty(){return this.len===0}push(e){let n={value:e,next:null,prev:this.tail,removed:false};return this.tail?this.tail.next=n:this.head=n,this.tail=n,this.len++,n}shift(){let e=this.head;if(e)return this.unlink(e),e.value}remove(e){e.removed||this.unlink(e);}unlink(e){e.removed=true;let{prev:n,next:r}=e;n?n.next=r:this.head=r,r?r.prev=n:this.tail=n,e.next=null,e.prev=null,this.len--;}};function w(t,e="backpressure"){return g(()=>M(t,e))}function M(t,e){let n=new B(t),r=false,s={_tag:"QueueClosed"},a=new v,o=new v,p=()=>{for(;o.length>0&&n.length>0;){let u=o.shift(),f=n.shift();u({_tag:"Success",value:f});}for(;a.length>0&&n.length<t&&o.length===0;){let u=a.shift();n.push(u.a),u.cb(true);}for(;o.length>0&&a.length>0;){let u=o.shift(),f=a.shift();f.cb(true),u({_tag:"Success",value:f.a});}};return {size:()=>n.length,shutdown:()=>{if(!r){for(r=true;o.length>0;)o.shift()({_tag:"Failure",error:s});for(;a.length>0;)a.shift().cb(false);n.clear();}},offer:u=>i((f,i)=>{if(r){i({_tag:"Success",value:false});return}if(o.length>0){o.shift()({_tag:"Success",value:u}),i({_tag:"Success",value:true});return}if(n.length<t){n.push(u),i({_tag:"Success",value:true}),p();return}if(e==="dropping"){i({_tag:"Success",value:false});return}if(e==="sliding"){n.shift(),n.push(u),i({_tag:"Success",value:true}),p();return}let m=a.push({a:u,cb:A=>i({_tag:"Success",value:A})});return ()=>{a.remove(m);}}),take:()=>i((u,f)=>{if(n.length>0){let A=n.shift();f({_tag:"Success",value:A}),p();return}if(a.length>0){let A=a.shift();A.cb(true),f({_tag:"Success",value:A.a});return}if(r){f({_tag:"Failure",error:s});return}let i=A=>f(A),m=o.push(i);return ()=>{o.remove(m);}})}}function F(t,e$1,n="backpressure"){let r$1=false,s=null,a$1=null,o=t,p=()=>a(ba(o),i=>e(i._tag==="None"?{_tag:"End"}:{_tag:"Fail",error:i.value}),([i,m])=>g(()=>(o=m,{_tag:"Elem",value:i}))),c=i=>k(w(e$1,n),m=>{s=m;let S=()=>k(p(),A=>k(s.offer(A),()=>A._tag==="End"||A._tag==="Fail"?e(void 0):S()));return a$1=G(S(),i),r$1=true,e(void 0)}),u={_tag:"Async",register:(i,m)=>{(()=>{if(!r$1){G(c(i),i).join(()=>{f(i,m);});return}f(i,m);})();}};function f(i,m){let S=s.take();G(S,i).join(A=>{if(A._tag!=="Success")return;let _=A.value;switch(_._tag){case "Elem":m({_tag:"Success",value:[_.value,U(u)]});return;case "End":a$1?.interrupt?.(),m({_tag:"Failure",error:q});return;case "Fail":a$1?.interrupt?.(),m({_tag:"Failure",error:r(_.error)});return}});}return U(u)}var I=t=>t==="BackPressure"?"backpressure":t==="Dropping"?"dropping":"sliding";function N(t,e$1="BackPressure"){let n=new Set,r=false,s=c=>{if(r)return e(false);let u=Array.from(n),f=e(true);return u.forEach(i=>{f=k(f,m=>k(i.offer(c),S=>e(m&&S)));}),f};return {publish:s,publishAll:c=>{let u=e(true),f=c[Symbol.iterator]();for(;;){let i=f.next();if(i.done)break;let m=i.value;u=k(u,S=>k(s(m),A=>e(S&&A)));}return u},subscribe:()=>r?h(()=>{throw {_tag:"HubClosed"}}):k(w(t,I(e$1)),c=>g(()=>(n.add(c),{...c,unsubscribe:()=>{n.has(c)&&(n.delete(c),c.shutdown());}}))),shutdown:()=>g(()=>{r||(r=true,Array.from(n).forEach(c=>c.shutdown()),n.clear());})}}var ln=N;function cn(t,e$1){return fa(t,n=>k(e$1.publish(n),()=>e(void 0)))}function pn(t){return W(k(t.subscribe(),e$1=>{let n=U(k(c(e$1.take(),r=>q),r=>e([r,n])));return e({stream:n,release:r=>g(()=>e$1.unsubscribe())})}))}function bn(t,e){return e(t)}function z(t,e){return(n=>e(t(n)))}function gn(t,e){return z(e,t)}function vn(){return(t=>t)}function xn(t){return(e$1=>{let n=r=>U(a(ba(r),s=>f(s),([s,a])=>e([t(s),n(a)])));return n(e$1)})}function kn(t){return(e$1=>{let n=s=>a(ba(s),a=>f(a),([a,o])=>t(a)?e([a,r(o)]):n(o)),r=s=>U(n(s));return r(e$1)})}function Zn(t){return(e$1=>{let n=s=>a(ba(s),a=>f(a),([a,o])=>{let p=t(a);return p._tag==="Some"?e([p.value,r(o)]):n(o)}),r=s=>U(n(s));return r(e$1)})}function wn(t){let e$1=Math.max(0,t|0);return(n=>{let r=(s,a$1)=>a$1<=0?Y():U(a(ba(s),o=>f(o),([o,p])=>e([o,r(p,a$1-1)])));return r(n,e$1)})}function _n(t){let e=Math.max(0,t|0);return(n=>{let r=(s,a$1)=>a$1<=0?s:U(a(ba(s),o=>f(o),([o,p])=>ba(r(p,a$1-1))));return r(n,e)})}function D(t){return(e$1=>{let n=r$1=>U(a(c(ba(r$1),s=>T(s)),s=>f(s),([s,a$1])=>a(c(t(s),o=>r(o)),o=>f(o),o=>e([o,n(a$1)]))));return n(e$1)})}function Cn(t){return D(e$1=>k(t(e$1),()=>e(e$1)))}function Pn(t,e="backpressure"){return(n=>F(n,t,e))}function On(t){let e$1=Math.max(1,t|0);return(n=>{let r=(a$1,o,p)=>o<=0?e({chunk:p,rest:a$1}):a(ba(a$1),c=>c._tag==="None"?e({chunk:p,rest:Y()}):f(c),([c,u])=>r(u,o-1,[...p,c])),s=a$1=>U(a(ba(a$1),o=>f(o),([o,p])=>k(r(p,e$1-1,[o]),({chunk:c,rest:u})=>e([c,s(u)]))));return s(n)})}export{v as LinkedQueue,z as andThen,w as bounded,ln as broadcast,cn as broadcastToHub,F as buffer,Pn as bufferP,gn as compose,_n as dropP,Zn as filterMapP,kn as filterP,pn as fromHub,On as groupedP,vn as identity,He as linkAbortController,Be as makeCancelToken,N as makeHub,D as mapEffectP,xn as mapP,wn as takeP,Cn as tapEffectP,bn as via};
|
|
@@ -224,4 +224,4 @@ declare function fromArray<A>(values: readonly A[]): ZStream<unknown, never, A>;
|
|
|
224
224
|
declare function collectStream<R, E, A>(stream: ZStream<R, E, A>): ZIO<R, E, A[]>;
|
|
225
225
|
declare function streamFromReadableStream<E>(body: ReadableStream<Uint8Array> | null | undefined, normalizeError: Normalize<E>): ZStream<unknown, E, Uint8Array>;
|
|
226
226
|
|
|
227
|
-
export {
|
|
227
|
+
export { type Flatten as $, type Async as A, mapAsync as B, mapTryAsync as C, type Some as D, type Exit as E, type Fiber as F, none as G, some as H, type Interrupted 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 FiberId as P, type FiberStatus as Q, RuntimeFiber as R, Scheduler as S, type ScopeId as T, withScope as U, type Task as V, globalScheduler as W, type Empty as X, type Emit as Y, type ZStream as Z, type Concat as _, Scope as a, type FromPull as a0, type Merge as a1, type Scoped as a2, type Normalize as a3, widenOpt as a4, fromPull as a5, unwrapScoped as a6, managedStream as a7, mergeStream as a8, emptyStream as a9, emitStream as aa, concatStream as ab, flattenStream as ac, merge as ad, uncons as ae, mapStream as af, rangeStream as ag, zip as ah, foreachStream as ai, fromArray as aj, collectStream as ak, streamFromReadableStream as al, type ZIO as b, sync as c, flatMap as d, mapError as e, fail as f, catchAll as g, end as h, asyncFold as i, asyncCatchAll as j, asyncMapError as k, asyncSucceed as l, map as m, asyncFail as n, orElseOptional as o, asyncSync as p, asyncTotal as q, async as r, succeed as s, asyncMap as t, unit as u, asyncFlatMap as v, acquireRelease as w, asyncInterruptible as x, type AsyncWithPromise as y, withAsyncPromise as z };
|
|
@@ -224,4 +224,4 @@ declare function fromArray<A>(values: readonly A[]): ZStream<unknown, never, A>;
|
|
|
224
224
|
declare function collectStream<R, E, A>(stream: ZStream<R, E, A>): ZIO<R, E, A[]>;
|
|
225
225
|
declare function streamFromReadableStream<E>(body: ReadableStream<Uint8Array> | null | undefined, normalizeError: Normalize<E>): ZStream<unknown, E, Uint8Array>;
|
|
226
226
|
|
|
227
|
-
export {
|
|
227
|
+
export { type Flatten as $, type Async as A, mapAsync as B, mapTryAsync as C, type Some as D, type Exit as E, type Fiber as F, none as G, some as H, type Interrupted 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 FiberId as P, type FiberStatus as Q, RuntimeFiber as R, Scheduler as S, type ScopeId as T, withScope as U, type Task as V, globalScheduler as W, type Empty as X, type Emit as Y, type ZStream as Z, type Concat as _, Scope as a, type FromPull as a0, type Merge as a1, type Scoped as a2, type Normalize as a3, widenOpt as a4, fromPull as a5, unwrapScoped as a6, managedStream as a7, mergeStream as a8, emptyStream as a9, emitStream as aa, concatStream as ab, flattenStream as ac, merge as ad, uncons as ae, mapStream as af, rangeStream as ag, zip as ah, foreachStream as ai, fromArray as aj, collectStream as ak, streamFromReadableStream as al, type ZIO as b, sync as c, flatMap as d, mapError as e, fail as f, catchAll as g, end as h, asyncFold as i, asyncCatchAll as j, asyncMapError as k, asyncSucceed as l, map as m, asyncFail as n, orElseOptional as o, asyncSync as p, asyncTotal as q, async as r, succeed as s, asyncMap as t, unit as u, asyncFlatMap as v, acquireRelease as w, asyncInterruptible as x, type AsyncWithPromise as y, withAsyncPromise as z };
|
package/package.json
CHANGED
package/dist/chunk-3NPW2C22.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
'use strict';function y(t,e,n){return {_tag:"Fold",first:t,onFailure:e,onSuccess:n}}function Ae(t,e){return y(t,n=>e(n),n=>u(n))}function S(t,e){return y(t,n=>d(e(n)),n=>u(n))}var w=()=>u(void 0),u=t=>({_tag:"Succeed",value:t}),d=t=>({_tag:"Fail",error:t}),b=t=>({_tag:"Sync",thunk:t}),Ee=t=>b(()=>t()),l=t=>({_tag:"Async",register:t});function W(t,e){return A(t,n=>u(e(n)))}function A(t,e){return {_tag:"FlatMap",first:t,andThen:e}}function pe(t,e,n){return A(t,r=>(n.addFinalizer(a=>e(r,a)),u(r)))}function ye(t){return l(t)}var de=t=>e=>{let n=e;return n.toPromise||(n.toPromise=r=>t(e,r),n.unsafeRunPromise=()=>t(e,{})),n},Re=(t,e)=>A(t,n=>u(e(n))),fe=(t,e)=>A(t,n=>b(()=>e(n)));var v={_tag:"None"},_=t=>({_tag:"Some",value:t});var z=t=>u(t),B=t=>d(t),H=t=>b(e=>t(e)),F=(t,e)=>W(t,e),G=(t,e)=>A(t,n=>e(n)),M=(t,e)=>S(t,e),ve=(t,e)=>y(t,n=>e(n),n=>u(n));function U(t,e){return y(t,n=>n._tag==="Some"?d(n):e(),n=>u(n))}var xe=()=>B(v);var P=class{buf;head=0;tail=0;size_=0;constructor(e=1024){let n=Math.max(2,this.nextPow2(e));this.buf=new Array(n);}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,n=new Array(e.length*2);for(let r=0;r<this.size_;r++)n[r]=e[this.head+r&e.length-1];this.buf=n,this.head=0,this.tail=this.size_;}nextPow2(e){let n=1;for(;n<e;)n<<=1;return n}};var Q=2048,$=4096,Y=(()=>{if(typeof globalThis.setImmediate=="function")return t=>globalThis.setImmediate(t);if(typeof globalThis.MessageChannel=="function"){let t=new globalThis.MessageChannel,e=null;return t.port1.onmessage=()=>{let n=e;e=null,n?.();},n=>{e=n,t.port2.postMessage(0);}}return t=>setTimeout(t,0)})(),j=class{queue=new P(1024);flushing=false;scheduled=false;schedule(e,n="anonymous"){if(typeof e=="function"&&(this.queue.push({tag:n,task:e}),!this.flushing&&!this.scheduled)){this.scheduled=true;let r=this.queue.length>$?"macro":"micro";this.requestFlush(r);}}requestFlush(e){e==="micro"?queueMicrotask(()=>this.flush()):Y(()=>this.flush());}flush(){if(this.flushing)return;this.flushing=true,this.scheduled=false;let e=0;try{for(;e<Q;){let n=this.queue.shift();if(!n)break;e++;try{n.task();}catch(r){console.error(`[Scheduler] task threw (tag=${n.tag})`,r);}}}finally{if(this.flushing=false,this.queue.length>0&&!this.scheduled){this.scheduled=true;let n=e>=Q||this.queue.length>$?"macro":"micro";this.requestFlush(n);}}}},J=new j;var R={CONTINUE:"Continue",SUSPEND:"Suspend",DONE:"Done"},h={QUEUED:"Queued",RUNNING:"Running",SUSPENDED:"Suspended",DONE:"Done"},ee=1,te=1024;function ne(t){let e=t;for(;e._tag==="FlatMap"&&e.first._tag==="FlatMap";){let n=e.first,r=e.andThen;e={_tag:"FlatMap",first:n.first,andThen:a=>({_tag:"FlatMap",first:n.andThen(a),andThen:r})};}return e}var N=class{constructor(e,n,r){this.scheduler=r;this.id=ee++,this.current=e,this.env=n;}id;closing=null;finishing=false;runState=h.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===h.DONE||this.runState===h.QUEUED||(this.runState=h.QUEUED,this.scheduler.schedule(()=>{if(this.runState===h.DONE)return;switch(this.runState=h.RUNNING,this.step()){case R.CONTINUE:this.schedule("continue");return;case R.SUSPEND:this.runState=h.SUSPENDED;return;case R.DONE:this.runState=h.DONE;return}},`fiber#${this.id}.${e}`));}runFinalizersOnce(e){if(!this.finalizersDrained)for(this.finalizersDrained=true;this.fiberFinalizers.length>0;){let n=this.fiberFinalizers.pop();try{n(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 n of this.joiners)n(e);this.joiners.length=0;}}onSuccess(e){let n=this.stack.pop();if(!n){this.notify({_tag:"Success",value:e});return}this.current=n._tag==="SuccessCont"?n.k(e):n.onSuccess(e);}onFailure(e){for(;this.stack.length>0;){let n=this.stack.pop();if(n._tag==="FoldCont"){this.current=n.onFailure(e);return}}this.notify({_tag:"Failure",error:e});}step(){let e=te;for(;e-- >0;){if(this.result!=null)return R.DONE;if(this.interrupted&&this.closing==null)return this.notify({_tag:"Failure",error:{_tag:"Interrupted"}}),R.DONE;let n=ne(this.current);switch(n._tag){case "Succeed":{this.onSuccess(n.value);break}case "Fail":{this.onFailure(n.error);break}case "Sync":{try{let r=n.thunk(this.env);this.onSuccess(r);}catch(r){this.onFailure(r);}break}case "FlatMap":{this.stack.push({_tag:"SuccessCont",k:n.andThen}),this.current=n.first;break}case "Fold":{this.stack.push({_tag:"FoldCont",onFailure:n.onFailure,onSuccess:n.onSuccess}),this.current=n.first;break}case "Async":{if(this.finishing)return this.result!=null?R.DONE:R.CONTINUE;let r=false,a=i=>{r||(r=true,!(this.result!=null||this.closing!=null)&&(this.current=i._tag==="Success"?{_tag:"Succeed",value:i.value}:{_tag:"Fail",error:i.error},this.schedule("async-resume")));},o=n.register(this.env,a);return typeof o=="function"&&this.addFinalizer(()=>{r=true;try{o();}catch{}}),R.SUSPEND}}}return this.result!=null?R.DONE:R.CONTINUE}};function De(t){return l((e,n)=>{let r=false,a=s=>{r||(r=true,n(s));},o=s=>a({_tag:"Failure",error:s instanceof Error?s:new Error(String(s))}),i=s=>a({_tag:"Success",value:s});try{typeof t=="function"&&t.length>=1?t((s,c)=>s?o(s):i(c)):t().then(i,o);}catch(s){o(s);}})}function I(t,e,n=J){let r=new N(t,e,n);return r.schedule("initial-step"),r}function Te(t,e,n){I(t,e).join(n);}function ze(t,e){return new Promise((n,r)=>{I(t,e).join(o=>{let i=o;i._tag==="Success"?n(i.value):r(i.error);});})}function Me(t,e){return l((n,r)=>{t(n).then(a=>r({_tag:"Success",value:a})).catch(a=>r({_tag:"Failure",error:e(a)}));})}function Ue(t){return l((e,n)=>{let r=false,a=o=>{r||(r=true,n(o));};try{t((o,i)=>{a(o?{_tag:"Failure",error:o}:{_tag:"Success",value:i});});}catch(o){a({_tag:"Failure",error:o instanceof Error?o:new Error(String(o))});}})}function je(t){return re((n,r)=>t.length===1?t(r):t(n,r),n=>ae(n)?{_tag:"Abort"}:{_tag:"PromiseRejected",reason:n})}function re(t,e){return l((n,r)=>{let a=new AbortController,o=false,i=s=>{o||(o=true,r(s));};try{(t.length===1?t(a.signal):t(n,a.signal)).then(c=>i({_tag:"Success",value:c})).catch(c=>i({_tag:"Failure",error:e(c)}));}catch(s){i({_tag:"Failure",error:e(s)});}return ()=>{o=true,a.abort();}})}var ae=t=>typeof t=="object"&&t!==null&&"name"in t&&t.name==="AbortError";var oe=1;function se(t){return l((e,n)=>{let r=t.length;if(r===0){n({_tag:"Success",value:void 0});return}for(let a of t)a.join(()=>{r-=1,r===0&&n({_tag:"Success",value:void 0});});})}function ie(t){return y(t,()=>w(),()=>w())}var Z=class t{constructor(e){this.env=e;this.id=oe++;}id;closed=false;children=new Set;subScopes=new Set;finalizers=[];addFinalizer(e){if(this.closed)throw new Error("Trying to add finalizer to closed scope");this.finalizers.push(e);}subScope(){if(this.closed)throw new Error("Scope closed");let e=new t(this.env);return this.subScopes.add(e),e}fork(e,n){if(this.closed)throw new Error("Scope closed");let r=I(e,n);return this.children.add(r),r.join(()=>{this.children.delete(r);}),r}close(e={_tag:"Success",value:void 0}){I(this.closeAsync(e),this.env);}closeAsync(e={_tag:"Success",value:void 0},n={}){return l((r,a)=>{if(this.closed){a({_tag:"Success",value:void 0});return}this.closed=true;let o=Array.from(this.children),i=Array.from(this.subScopes);this.children.clear(),this.subScopes.clear();for(let p of o)try{p.interrupt();}catch{}let s=w();for(let p of i)s=A(s,()=>p.closeAsync(e,n));for(;this.finalizers.length>0;){let p=this.finalizers.pop();s=A(s,()=>ie(p(e)));}n.awaitChildren&&(s=A(s,()=>se(o))),I(s,this.env).join(()=>a({_tag:"Success",value:void 0}));})}};function Ge(t){let e=new Z({});try{return t(e)}finally{e.close();}}function K(t,e,n,r,a){return l((o,i)=>{let s=n.subScope(),c=false,p=s.fork(t,o),x=s.fork(e,o),g=f=>{s.fork(f,o).join(O=>{s.close(O),i(O);});};p.join(f=>{c||(c=true,g(r(f,x,s)));}),x.join(f=>{c||(c=true,g(a(f,p,s)));});})}var q=t=>t._tag==="None"?v:_(t.value),m=t=>({_tag:"FromPull",pull:t}),ce=(t,e)=>({_tag:"Scoped",acquire:t,release:e}),it=t=>({_tag:"Scoped",acquire:A(t,e=>u(e.stream)),release:e=>A(t,n=>n.release(e))}),ct=(t,e,n=true)=>({_tag:"Merge",left:t,right:e,flip:n}),T=()=>({_tag:"Empty"}),X=t=>({_tag:"Emit",value:t}),C=(t,e)=>({_tag:"Concat",left:t,right:e}),L=t=>({_tag:"Flatten",stream:t});function V(t,e,n,r,a){return (o,i,s)=>{if(o._tag,o._tag,o._tag==="Success"){let[x,g]=o.value;i.interrupt();let f=m(t==="L"?D(g,n):D(e,g));return u([x,f])}let c=o.error;if(typeof c=="object"&&c!==null&&c._tag==="Interrupted")return d(c);let p=c;return p._tag==="None"?E(t==="L"?n:e):d(p)}}function D(t,e,n,r){return l((a,o)=>{let s=new Z(a),c=E(t),p=E(e),x=V("L",t,e),g=V("R",t,e),f=K(c,p,s,x,g);s.fork(f,a).join(O=>{s.close(O),o(O);});})}function ut(t,e){return m(D(t,e))}function E(t){switch(t._tag){case "Empty":return B(v);case "Emit":return F(M(t.value,e=>_(e)),e=>[e,T()]);case "FromPull":return t.pull;case "Concat":return U(F(E(t.left),([e,n])=>[e,C(n,t.right)]),()=>E(t.right));case "Flatten":return G(E(t.stream),([e,n])=>U(F(E(e),([r,a])=>[r,C(a,L(n))]),()=>E(L(n))));case "Merge":return D(t.left,t.right,t.flip);case "Scoped":return l((e,n)=>{let r=new Z(e);r.addFinalizer(a=>t.release(a)),r.fork(t.acquire,e).join(a=>{if(a._tag==="Failure"){r.close(a),n({_tag:"Failure",error:_(a.error)});return}let o=a.value;E(o)(e,s=>{r.close(s),n(s);});});})}}function k(t,e){switch(t._tag){case "Empty":return T();case "Emit":return X(F(t.value,e));case "FromPull":return m(F(t.pull,([n,r])=>[e(n),k(r,e)]));case "Concat":return C(k(t.left,e),k(t.right,e));case "Flatten":{let n=k(t.stream,r=>k(r,e));return L(n)}}}function lt(t,e){let n=r=>m(r>e?d(v):u([r,n(r+1)]));return n(t)}function ue(t,e){let n=y(S(E(t),r=>q(r)),r=>d(r),([r,a])=>y(S(E(e),o=>q(o)),o=>d(o),([o,i])=>u([[r,o],ue(a,i)])));return m(n)}function At(t,e){let n=r=>y(S(E(r),a=>q(a)),a=>a._tag==="None"?u(void 0):d(a),([a,o])=>A(S(e(a),i=>_(i)),()=>n(o)));return y(n(t),r=>r._tag==="None"?u(void 0):d(r.value),()=>u(void 0))}function Et(t){let e=T();for(let n=t.length-1;n>=0;n--){let r=X(z(t[n]));e=C(r,e);}return e}function pt(t){let e=(n,r)=>y(E(n),a=>a._tag==="None"?z(r):B(a),([a,o])=>e(o,[...r,a]));return M(e(t,[]),n=>{if(n._tag==="Some")return n.value;throw new Error("unreachable: stream end handled as success")})}function le(t,e){let n=l((r,a)=>{t.read().then(({done:o,value:i})=>{if(o){a({_tag:"Failure",error:v});return}a({_tag:"Success",value:[i,m(n)]});}).catch(o=>{a({_tag:"Failure",error:_(e(o))});});});return m(n)}function yt(t,e){if(!t)return T();let n;return ce(H(()=>(n=t.getReader(),le(n,e))),()=>b(()=>{try{n?.cancel();}catch{}}))}exports.$=ue;exports.A=xe;exports.B=j;exports.C=J;exports.D=N;exports.E=De;exports.F=I;exports.G=Te;exports.H=ze;exports.I=Me;exports.J=Ue;exports.K=je;exports.L=re;exports.M=Z;exports.N=Ge;exports.O=q;exports.P=m;exports.Q=ce;exports.R=it;exports.S=ct;exports.T=T;exports.U=X;exports.V=C;exports.W=L;exports.X=ut;exports.Y=E;exports.Z=k;exports._=lt;exports.a=y;exports.aa=At;exports.b=Ae;exports.ba=Et;exports.c=S;exports.ca=pt;exports.d=w;exports.da=yt;exports.e=u;exports.f=d;exports.g=b;exports.h=Ee;exports.i=l;exports.j=W;exports.k=A;exports.l=pe;exports.m=ye;exports.n=de;exports.o=Re;exports.p=fe;exports.q=v;exports.r=_;exports.s=z;exports.t=B;exports.u=H;exports.v=F;exports.w=G;exports.x=M;exports.y=ve;exports.z=U;
|
package/dist/chunk-SNH7DUUJ.mjs
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
function y(t,e,n){return {_tag:"Fold",first:t,onFailure:e,onSuccess:n}}function Ae(t,e){return y(t,n=>e(n),n=>u(n))}function S(t,e){return y(t,n=>d(e(n)),n=>u(n))}var w=()=>u(void 0),u=t=>({_tag:"Succeed",value:t}),d=t=>({_tag:"Fail",error:t}),b=t=>({_tag:"Sync",thunk:t}),Ee=t=>b(()=>t()),l=t=>({_tag:"Async",register:t});function W(t,e){return A(t,n=>u(e(n)))}function A(t,e){return {_tag:"FlatMap",first:t,andThen:e}}function pe(t,e,n){return A(t,r=>(n.addFinalizer(a=>e(r,a)),u(r)))}function ye(t){return l(t)}var de=t=>e=>{let n=e;return n.toPromise||(n.toPromise=r=>t(e,r),n.unsafeRunPromise=()=>t(e,{})),n},Re=(t,e)=>A(t,n=>u(e(n))),fe=(t,e)=>A(t,n=>b(()=>e(n)));var v={_tag:"None"},_=t=>({_tag:"Some",value:t});var z=t=>u(t),B=t=>d(t),H=t=>b(e=>t(e)),F=(t,e)=>W(t,e),G=(t,e)=>A(t,n=>e(n)),M=(t,e)=>S(t,e),ve=(t,e)=>y(t,n=>e(n),n=>u(n));function U(t,e){return y(t,n=>n._tag==="Some"?d(n):e(),n=>u(n))}var xe=()=>B(v);var P=class{buf;head=0;tail=0;size_=0;constructor(e=1024){let n=Math.max(2,this.nextPow2(e));this.buf=new Array(n);}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,n=new Array(e.length*2);for(let r=0;r<this.size_;r++)n[r]=e[this.head+r&e.length-1];this.buf=n,this.head=0,this.tail=this.size_;}nextPow2(e){let n=1;for(;n<e;)n<<=1;return n}};var Q=2048,$=4096,Y=(()=>{if(typeof globalThis.setImmediate=="function")return t=>globalThis.setImmediate(t);if(typeof globalThis.MessageChannel=="function"){let t=new globalThis.MessageChannel,e=null;return t.port1.onmessage=()=>{let n=e;e=null,n?.();},n=>{e=n,t.port2.postMessage(0);}}return t=>setTimeout(t,0)})(),j=class{queue=new P(1024);flushing=false;scheduled=false;schedule(e,n="anonymous"){if(typeof e=="function"&&(this.queue.push({tag:n,task:e}),!this.flushing&&!this.scheduled)){this.scheduled=true;let r=this.queue.length>$?"macro":"micro";this.requestFlush(r);}}requestFlush(e){e==="micro"?queueMicrotask(()=>this.flush()):Y(()=>this.flush());}flush(){if(this.flushing)return;this.flushing=true,this.scheduled=false;let e=0;try{for(;e<Q;){let n=this.queue.shift();if(!n)break;e++;try{n.task();}catch(r){console.error(`[Scheduler] task threw (tag=${n.tag})`,r);}}}finally{if(this.flushing=false,this.queue.length>0&&!this.scheduled){this.scheduled=true;let n=e>=Q||this.queue.length>$?"macro":"micro";this.requestFlush(n);}}}},J=new j;var R={CONTINUE:"Continue",SUSPEND:"Suspend",DONE:"Done"},h={QUEUED:"Queued",RUNNING:"Running",SUSPENDED:"Suspended",DONE:"Done"},ee=1,te=1024;function ne(t){let e=t;for(;e._tag==="FlatMap"&&e.first._tag==="FlatMap";){let n=e.first,r=e.andThen;e={_tag:"FlatMap",first:n.first,andThen:a=>({_tag:"FlatMap",first:n.andThen(a),andThen:r})};}return e}var N=class{constructor(e,n,r){this.scheduler=r;this.id=ee++,this.current=e,this.env=n;}id;closing=null;finishing=false;runState=h.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===h.DONE||this.runState===h.QUEUED||(this.runState=h.QUEUED,this.scheduler.schedule(()=>{if(this.runState===h.DONE)return;switch(this.runState=h.RUNNING,this.step()){case R.CONTINUE:this.schedule("continue");return;case R.SUSPEND:this.runState=h.SUSPENDED;return;case R.DONE:this.runState=h.DONE;return}},`fiber#${this.id}.${e}`));}runFinalizersOnce(e){if(!this.finalizersDrained)for(this.finalizersDrained=true;this.fiberFinalizers.length>0;){let n=this.fiberFinalizers.pop();try{n(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 n of this.joiners)n(e);this.joiners.length=0;}}onSuccess(e){let n=this.stack.pop();if(!n){this.notify({_tag:"Success",value:e});return}this.current=n._tag==="SuccessCont"?n.k(e):n.onSuccess(e);}onFailure(e){for(;this.stack.length>0;){let n=this.stack.pop();if(n._tag==="FoldCont"){this.current=n.onFailure(e);return}}this.notify({_tag:"Failure",error:e});}step(){let e=te;for(;e-- >0;){if(this.result!=null)return R.DONE;if(this.interrupted&&this.closing==null)return this.notify({_tag:"Failure",error:{_tag:"Interrupted"}}),R.DONE;let n=ne(this.current);switch(n._tag){case "Succeed":{this.onSuccess(n.value);break}case "Fail":{this.onFailure(n.error);break}case "Sync":{try{let r=n.thunk(this.env);this.onSuccess(r);}catch(r){this.onFailure(r);}break}case "FlatMap":{this.stack.push({_tag:"SuccessCont",k:n.andThen}),this.current=n.first;break}case "Fold":{this.stack.push({_tag:"FoldCont",onFailure:n.onFailure,onSuccess:n.onSuccess}),this.current=n.first;break}case "Async":{if(this.finishing)return this.result!=null?R.DONE:R.CONTINUE;let r=false,a=i=>{r||(r=true,!(this.result!=null||this.closing!=null)&&(this.current=i._tag==="Success"?{_tag:"Succeed",value:i.value}:{_tag:"Fail",error:i.error},this.schedule("async-resume")));},o=n.register(this.env,a);return typeof o=="function"&&this.addFinalizer(()=>{r=true;try{o();}catch{}}),R.SUSPEND}}}return this.result!=null?R.DONE:R.CONTINUE}};function De(t){return l((e,n)=>{let r=false,a=s=>{r||(r=true,n(s));},o=s=>a({_tag:"Failure",error:s instanceof Error?s:new Error(String(s))}),i=s=>a({_tag:"Success",value:s});try{typeof t=="function"&&t.length>=1?t((s,c)=>s?o(s):i(c)):t().then(i,o);}catch(s){o(s);}})}function I(t,e,n=J){let r=new N(t,e,n);return r.schedule("initial-step"),r}function Te(t,e,n){I(t,e).join(n);}function ze(t,e){return new Promise((n,r)=>{I(t,e).join(o=>{let i=o;i._tag==="Success"?n(i.value):r(i.error);});})}function Me(t,e){return l((n,r)=>{t(n).then(a=>r({_tag:"Success",value:a})).catch(a=>r({_tag:"Failure",error:e(a)}));})}function Ue(t){return l((e,n)=>{let r=false,a=o=>{r||(r=true,n(o));};try{t((o,i)=>{a(o?{_tag:"Failure",error:o}:{_tag:"Success",value:i});});}catch(o){a({_tag:"Failure",error:o instanceof Error?o:new Error(String(o))});}})}function je(t){return re((n,r)=>t.length===1?t(r):t(n,r),n=>ae(n)?{_tag:"Abort"}:{_tag:"PromiseRejected",reason:n})}function re(t,e){return l((n,r)=>{let a=new AbortController,o=false,i=s=>{o||(o=true,r(s));};try{(t.length===1?t(a.signal):t(n,a.signal)).then(c=>i({_tag:"Success",value:c})).catch(c=>i({_tag:"Failure",error:e(c)}));}catch(s){i({_tag:"Failure",error:e(s)});}return ()=>{o=true,a.abort();}})}var ae=t=>typeof t=="object"&&t!==null&&"name"in t&&t.name==="AbortError";var oe=1;function se(t){return l((e,n)=>{let r=t.length;if(r===0){n({_tag:"Success",value:void 0});return}for(let a of t)a.join(()=>{r-=1,r===0&&n({_tag:"Success",value:void 0});});})}function ie(t){return y(t,()=>w(),()=>w())}var Z=class t{constructor(e){this.env=e;this.id=oe++;}id;closed=false;children=new Set;subScopes=new Set;finalizers=[];addFinalizer(e){if(this.closed)throw new Error("Trying to add finalizer to closed scope");this.finalizers.push(e);}subScope(){if(this.closed)throw new Error("Scope closed");let e=new t(this.env);return this.subScopes.add(e),e}fork(e,n){if(this.closed)throw new Error("Scope closed");let r=I(e,n);return this.children.add(r),r.join(()=>{this.children.delete(r);}),r}close(e={_tag:"Success",value:void 0}){I(this.closeAsync(e),this.env);}closeAsync(e={_tag:"Success",value:void 0},n={}){return l((r,a)=>{if(this.closed){a({_tag:"Success",value:void 0});return}this.closed=true;let o=Array.from(this.children),i=Array.from(this.subScopes);this.children.clear(),this.subScopes.clear();for(let p of o)try{p.interrupt();}catch{}let s=w();for(let p of i)s=A(s,()=>p.closeAsync(e,n));for(;this.finalizers.length>0;){let p=this.finalizers.pop();s=A(s,()=>ie(p(e)));}n.awaitChildren&&(s=A(s,()=>se(o))),I(s,this.env).join(()=>a({_tag:"Success",value:void 0}));})}};function Ge(t){let e=new Z({});try{return t(e)}finally{e.close();}}function K(t,e,n,r,a){return l((o,i)=>{let s=n.subScope(),c=false,p=s.fork(t,o),x=s.fork(e,o),g=f=>{s.fork(f,o).join(O=>{s.close(O),i(O);});};p.join(f=>{c||(c=true,g(r(f,x,s)));}),x.join(f=>{c||(c=true,g(a(f,p,s)));});})}var q=t=>t._tag==="None"?v:_(t.value),m=t=>({_tag:"FromPull",pull:t}),ce=(t,e)=>({_tag:"Scoped",acquire:t,release:e}),it=t=>({_tag:"Scoped",acquire:A(t,e=>u(e.stream)),release:e=>A(t,n=>n.release(e))}),ct=(t,e,n=true)=>({_tag:"Merge",left:t,right:e,flip:n}),T=()=>({_tag:"Empty"}),X=t=>({_tag:"Emit",value:t}),C=(t,e)=>({_tag:"Concat",left:t,right:e}),L=t=>({_tag:"Flatten",stream:t});function V(t,e,n,r,a){return (o,i,s)=>{if(o._tag,o._tag,o._tag==="Success"){let[x,g]=o.value;i.interrupt();let f=m(t==="L"?D(g,n):D(e,g));return u([x,f])}let c=o.error;if(typeof c=="object"&&c!==null&&c._tag==="Interrupted")return d(c);let p=c;return p._tag==="None"?E(t==="L"?n:e):d(p)}}function D(t,e,n,r){return l((a,o)=>{let s=new Z(a),c=E(t),p=E(e),x=V("L",t,e),g=V("R",t,e),f=K(c,p,s,x,g);s.fork(f,a).join(O=>{s.close(O),o(O);});})}function ut(t,e){return m(D(t,e))}function E(t){switch(t._tag){case "Empty":return B(v);case "Emit":return F(M(t.value,e=>_(e)),e=>[e,T()]);case "FromPull":return t.pull;case "Concat":return U(F(E(t.left),([e,n])=>[e,C(n,t.right)]),()=>E(t.right));case "Flatten":return G(E(t.stream),([e,n])=>U(F(E(e),([r,a])=>[r,C(a,L(n))]),()=>E(L(n))));case "Merge":return D(t.left,t.right,t.flip);case "Scoped":return l((e,n)=>{let r=new Z(e);r.addFinalizer(a=>t.release(a)),r.fork(t.acquire,e).join(a=>{if(a._tag==="Failure"){r.close(a),n({_tag:"Failure",error:_(a.error)});return}let o=a.value;E(o)(e,s=>{r.close(s),n(s);});});})}}function k(t,e){switch(t._tag){case "Empty":return T();case "Emit":return X(F(t.value,e));case "FromPull":return m(F(t.pull,([n,r])=>[e(n),k(r,e)]));case "Concat":return C(k(t.left,e),k(t.right,e));case "Flatten":{let n=k(t.stream,r=>k(r,e));return L(n)}}}function lt(t,e){let n=r=>m(r>e?d(v):u([r,n(r+1)]));return n(t)}function ue(t,e){let n=y(S(E(t),r=>q(r)),r=>d(r),([r,a])=>y(S(E(e),o=>q(o)),o=>d(o),([o,i])=>u([[r,o],ue(a,i)])));return m(n)}function At(t,e){let n=r=>y(S(E(r),a=>q(a)),a=>a._tag==="None"?u(void 0):d(a),([a,o])=>A(S(e(a),i=>_(i)),()=>n(o)));return y(n(t),r=>r._tag==="None"?u(void 0):d(r.value),()=>u(void 0))}function Et(t){let e=T();for(let n=t.length-1;n>=0;n--){let r=X(z(t[n]));e=C(r,e);}return e}function pt(t){let e=(n,r)=>y(E(n),a=>a._tag==="None"?z(r):B(a),([a,o])=>e(o,[...r,a]));return M(e(t,[]),n=>{if(n._tag==="Some")return n.value;throw new Error("unreachable: stream end handled as success")})}function le(t,e){let n=l((r,a)=>{t.read().then(({done:o,value:i})=>{if(o){a({_tag:"Failure",error:v});return}a({_tag:"Success",value:[i,m(n)]});}).catch(o=>{a({_tag:"Failure",error:_(e(o))});});});return m(n)}function yt(t,e){if(!t)return T();let n;return ce(H(()=>(n=t.getReader(),le(n,e))),()=>b(()=>{try{n?.cancel();}catch{}}))}export{ue as $,xe as A,j as B,J as C,N as D,De as E,I as F,Te as G,ze as H,Me as I,Ue as J,je as K,re as L,Z as M,Ge as N,q as O,m as P,ce as Q,it as R,ct as S,T,X as U,C as V,L as W,ut as X,E as Y,k as Z,lt as _,y as a,At as aa,Ae as b,Et as ba,S as c,pt as ca,w as d,yt as da,u as e,d as f,b as g,Ee as h,l as i,W as j,A as k,pe as l,ye as m,de as n,Re as o,fe as p,v as q,_ as r,z as s,B as t,H as u,F as v,G as w,M as x,ve as y,U as z};
|