brass-runtime 1.7.2 → 1.9.0

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.
@@ -0,0 +1 @@
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;
@@ -0,0 +1 @@
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};
@@ -1,4 +1,13 @@
1
- import { Q as ZStream, A as Async } from '../stream-wtsKMh6j.mjs';
1
+ import { V as ZStream, A as Async, w as AsyncWithPromise } from '../stream-Byv3iEEs.mjs';
2
+
3
+ type RetryPolicy = {
4
+ maxRetries: number;
5
+ baseDelayMs: number;
6
+ maxDelayMs: number;
7
+ retryOnMethods?: HttpMethod[];
8
+ retryOnStatus?: (status: number) => boolean;
9
+ retryOnError?: (e: HttpError) => boolean;
10
+ };
2
11
 
3
12
  type HttpError = {
4
13
  _tag: "Abort";
@@ -37,55 +46,99 @@ type HttpWireResponseStream = {
37
46
  ms: number;
38
47
  };
39
48
  type HttpClientStream = (req: HttpRequest) => Async<unknown, HttpError, HttpWireResponseStream>;
40
- type HttpClient = (req: HttpRequest) => Async<unknown, HttpError, HttpWireResponse>;
49
+ type HttpClient = HttpClientFn & {
50
+ with: (mw: HttpMiddleware) => HttpClient;
51
+ };
52
+ declare const withMiddleware: (mw: HttpMiddleware) => (c: HttpClient) => HttpClient;
53
+ declare const decorate: (run: HttpClientFn) => HttpClient;
54
+ type HttpClientFn = (req: HttpRequest) => Async<unknown, HttpError, HttpWireResponse>;
55
+ type HttpMiddleware = (next: HttpClientFn) => HttpClientFn;
56
+ declare const normalizeHeadersInit: (h: any) => Record<string, string> | undefined;
41
57
  declare function makeHttpStream(cfg?: MakeHttpConfig): HttpClientStream;
42
58
  declare function makeHttp(cfg?: MakeHttpConfig): HttpClient;
43
- declare const mapAsync: <R, E, A, B>(fa: Async<R, E, A>, f: (a: A) => B) => Async<R, E, B>;
44
- declare const mapTryAsync: <R, E, A, B>(fa: Async<R, E, A>, f: (a: A) => B) => Async<R, E, B>;
59
+ declare const withRetryStream: (p: RetryPolicy) => (next: HttpClientStream) => HttpClientStream;
45
60
 
61
+ type InitNoMethodBody = Omit<RequestInit, "method" | "body">;
62
+ type HttpMeta = {
63
+ request: HttpRequest;
64
+ urlFinal: string;
65
+ startedAt: number;
66
+ durationMs: number;
67
+ };
46
68
  type HttpResponse<A> = {
47
69
  status: number;
70
+ statusText: string;
48
71
  headers: Record<string, string>;
49
72
  body: A;
50
73
  };
51
- type HttpMeta = {
52
- statusText: string;
53
- ms: number;
54
- };
55
- type HttpResponseWithMeta<A> = HttpResponse<A> & {
74
+ type HttpWireWithMeta = {
75
+ wire: HttpWireResponse;
56
76
  meta: HttpMeta;
57
77
  };
58
- type HttpResponseStream = {
59
- status: number;
60
- headers: Record<string, string>;
61
- body: ZStream<unknown, HttpError, Uint8Array>;
78
+ type HttpResponseWithMeta<A> = {
79
+ wire: HttpWireResponse;
80
+ response: HttpResponse<A>;
81
+ meta: HttpMeta;
62
82
  };
63
- declare function httpClient(cfg?: MakeHttpConfig): {
64
- request: (req: HttpRequest) => Async<unknown, HttpError, HttpWireResponse>;
65
- getText: (url: string, init?: Omit<RequestInit, "method">) => Async<unknown, HttpError, HttpResponse<string>>;
66
- getJson: <A>(url: string, init?: Omit<RequestInit, "method">) => Async<unknown, HttpError, HttpResponse<A>>;
67
- post: (url: string, body?: string, init?: Omit<RequestInit, "method" | "body">) => Async<unknown, HttpError, HttpWireResponse>;
68
- postJson: <A>(url: string, bodyObj: A, init?: HttpInit & {
69
- headers?: Record<string, string>;
70
- }) => Async<unknown, HttpError, HttpWireResponse>;
83
+ type Dx = {
84
+ request: (req: HttpRequest) => any;
85
+ get: (url: string, init?: any) => any;
86
+ post: (url: string, body?: string, init?: any) => any;
87
+ getText: (url: string, init?: any) => any;
88
+ getJson: <A>(url: string, init?: any) => any;
89
+ postJson: (url: string, body?: any, init?: any) => any;
90
+ with: (mw: HttpMiddleware) => Dx;
91
+ withRetry: (p: RetryPolicy) => Dx;
92
+ wire: HttpClient;
71
93
  };
94
+ declare function httpClient(cfg?: MakeHttpConfig): Dx;
72
95
  declare function httpClientWithMeta(cfg?: MakeHttpConfig): {
73
- request: (req: HttpRequest) => Async<unknown, HttpError, HttpWireResponse>;
74
- getText: (url: string, init?: Omit<RequestInit, "method">) => Async<unknown, HttpError, HttpResponseWithMeta<string>>;
75
- getJson: <A>(url: string, init?: Omit<RequestInit, "method">) => Async<unknown, HttpError, HttpResponseWithMeta<A>>;
76
- post: (url: string, body?: string, init?: HttpInit & {
77
- headers?: Record<string, string>;
78
- }) => Async<unknown, HttpError, HttpResponseWithMeta<string>>;
96
+ request: (req: HttpRequest) => AsyncWithPromise<unknown, HttpError, {
97
+ wire: HttpWireResponse;
98
+ meta: HttpMeta;
99
+ }>;
100
+ get: (url: string, init?: InitNoMethodBody) => AsyncWithPromise<unknown, HttpError, {
101
+ wire: HttpWireResponse;
102
+ meta: HttpMeta;
103
+ }>;
104
+ getText: (url: string, init?: InitNoMethodBody) => AsyncWithPromise<unknown, HttpError, {
105
+ wire: HttpWireResponse;
106
+ response: {
107
+ status: number;
108
+ statusText: string;
109
+ headers: Record<string, string>;
110
+ body: string;
111
+ };
112
+ meta: HttpMeta;
113
+ }>;
114
+ getJson: <A>(url: string, init?: InitNoMethodBody) => AsyncWithPromise<unknown, HttpError, {
115
+ wire: HttpWireResponse;
116
+ response: {
117
+ status: number;
118
+ statusText: string;
119
+ headers: Record<string, string>;
120
+ body: A;
121
+ };
122
+ meta: HttpMeta;
123
+ }>;
124
+ post: (url: string, body?: string, init?: InitNoMethodBody) => AsyncWithPromise<unknown, HttpError, {
125
+ wire: HttpWireResponse;
126
+ meta: HttpMeta;
127
+ }>;
79
128
  postJson: <A>(url: string, bodyObj: A, init?: HttpInit & {
80
129
  headers?: Record<string, string>;
81
- }) => Async<unknown, HttpError, HttpResponseWithMeta<string>>;
130
+ }) => AsyncWithPromise<unknown, HttpError, {
131
+ wire: HttpWireResponse;
132
+ meta: HttpMeta;
133
+ }>;
82
134
  };
83
- type HttpClientDxStream = {
84
- request: (req: HttpRequest) => Async<unknown, HttpError, HttpResponseStream>;
85
- get: (url: string, init?: Omit<RequestInit, "method">) => Async<unknown, HttpError, HttpResponseStream>;
86
- post: (url: string, body?: string, init?: Omit<RequestInit, "method" | "body">) => Async<unknown, HttpError, HttpResponseStream>;
87
- postJson: <A extends object>(url: string, body: A, init?: Omit<RequestInit, "method" | "body">) => Async<unknown, HttpError, HttpResponseStream>;
135
+ declare function httpClientStream(cfg?: MakeHttpConfig): {
136
+ request: (req: HttpRequest) => AsyncWithPromise<unknown, HttpError, HttpWireResponseStream>;
137
+ getStream: (url: string, init?: InitNoMethodBody) => AsyncWithPromise<unknown, HttpError, HttpWireResponseStream>;
138
+ get: (url: string, init?: InitNoMethodBody) => AsyncWithPromise<unknown, HttpError, HttpWireResponseStream>;
139
+ with: (mw: (n: HttpClientStream) => HttpClientStream) => /*elided*/ any;
140
+ withRetry: (p: RetryPolicy) => /*elided*/ any;
141
+ wire: HttpClientStream;
88
142
  };
89
- declare function httpClientStream(cfg?: MakeHttpConfig): HttpClientDxStream;
90
143
 
91
- export { type HttpClient, type HttpClientDxStream, type HttpClientStream, type HttpError, type HttpInit, type HttpMeta, type HttpMethod, type HttpRequest, type HttpResponse, type HttpResponseStream, type HttpResponseWithMeta, type HttpWireResponse, type HttpWireResponseStream, type MakeHttpConfig, httpClient, httpClientStream, httpClientWithMeta, makeHttp, makeHttpStream, mapAsync, mapTryAsync };
144
+ export { type Dx, type HttpClient, type HttpClientFn, type HttpClientStream, type HttpError, type HttpInit, type HttpMeta, type HttpMethod, type HttpMiddleware, type HttpRequest, type HttpResponse, type HttpResponseWithMeta, type HttpWireResponse, type HttpWireResponseStream, type HttpWireWithMeta, type MakeHttpConfig, decorate, httpClient, httpClientStream, httpClientWithMeta, makeHttp, makeHttpStream, normalizeHeadersInit, withMiddleware, withRetryStream };
@@ -1,4 +1,13 @@
1
- import { Q as ZStream, A as Async } from '../stream-wtsKMh6j.js';
1
+ import { V as ZStream, A as Async, w as AsyncWithPromise } from '../stream-Byv3iEEs.js';
2
+
3
+ type RetryPolicy = {
4
+ maxRetries: number;
5
+ baseDelayMs: number;
6
+ maxDelayMs: number;
7
+ retryOnMethods?: HttpMethod[];
8
+ retryOnStatus?: (status: number) => boolean;
9
+ retryOnError?: (e: HttpError) => boolean;
10
+ };
2
11
 
3
12
  type HttpError = {
4
13
  _tag: "Abort";
@@ -37,55 +46,99 @@ type HttpWireResponseStream = {
37
46
  ms: number;
38
47
  };
39
48
  type HttpClientStream = (req: HttpRequest) => Async<unknown, HttpError, HttpWireResponseStream>;
40
- type HttpClient = (req: HttpRequest) => Async<unknown, HttpError, HttpWireResponse>;
49
+ type HttpClient = HttpClientFn & {
50
+ with: (mw: HttpMiddleware) => HttpClient;
51
+ };
52
+ declare const withMiddleware: (mw: HttpMiddleware) => (c: HttpClient) => HttpClient;
53
+ declare const decorate: (run: HttpClientFn) => HttpClient;
54
+ type HttpClientFn = (req: HttpRequest) => Async<unknown, HttpError, HttpWireResponse>;
55
+ type HttpMiddleware = (next: HttpClientFn) => HttpClientFn;
56
+ declare const normalizeHeadersInit: (h: any) => Record<string, string> | undefined;
41
57
  declare function makeHttpStream(cfg?: MakeHttpConfig): HttpClientStream;
42
58
  declare function makeHttp(cfg?: MakeHttpConfig): HttpClient;
43
- declare const mapAsync: <R, E, A, B>(fa: Async<R, E, A>, f: (a: A) => B) => Async<R, E, B>;
44
- declare const mapTryAsync: <R, E, A, B>(fa: Async<R, E, A>, f: (a: A) => B) => Async<R, E, B>;
59
+ declare const withRetryStream: (p: RetryPolicy) => (next: HttpClientStream) => HttpClientStream;
45
60
 
61
+ type InitNoMethodBody = Omit<RequestInit, "method" | "body">;
62
+ type HttpMeta = {
63
+ request: HttpRequest;
64
+ urlFinal: string;
65
+ startedAt: number;
66
+ durationMs: number;
67
+ };
46
68
  type HttpResponse<A> = {
47
69
  status: number;
70
+ statusText: string;
48
71
  headers: Record<string, string>;
49
72
  body: A;
50
73
  };
51
- type HttpMeta = {
52
- statusText: string;
53
- ms: number;
54
- };
55
- type HttpResponseWithMeta<A> = HttpResponse<A> & {
74
+ type HttpWireWithMeta = {
75
+ wire: HttpWireResponse;
56
76
  meta: HttpMeta;
57
77
  };
58
- type HttpResponseStream = {
59
- status: number;
60
- headers: Record<string, string>;
61
- body: ZStream<unknown, HttpError, Uint8Array>;
78
+ type HttpResponseWithMeta<A> = {
79
+ wire: HttpWireResponse;
80
+ response: HttpResponse<A>;
81
+ meta: HttpMeta;
62
82
  };
63
- declare function httpClient(cfg?: MakeHttpConfig): {
64
- request: (req: HttpRequest) => Async<unknown, HttpError, HttpWireResponse>;
65
- getText: (url: string, init?: Omit<RequestInit, "method">) => Async<unknown, HttpError, HttpResponse<string>>;
66
- getJson: <A>(url: string, init?: Omit<RequestInit, "method">) => Async<unknown, HttpError, HttpResponse<A>>;
67
- post: (url: string, body?: string, init?: Omit<RequestInit, "method" | "body">) => Async<unknown, HttpError, HttpWireResponse>;
68
- postJson: <A>(url: string, bodyObj: A, init?: HttpInit & {
69
- headers?: Record<string, string>;
70
- }) => Async<unknown, HttpError, HttpWireResponse>;
83
+ type Dx = {
84
+ request: (req: HttpRequest) => any;
85
+ get: (url: string, init?: any) => any;
86
+ post: (url: string, body?: string, init?: any) => any;
87
+ getText: (url: string, init?: any) => any;
88
+ getJson: <A>(url: string, init?: any) => any;
89
+ postJson: (url: string, body?: any, init?: any) => any;
90
+ with: (mw: HttpMiddleware) => Dx;
91
+ withRetry: (p: RetryPolicy) => Dx;
92
+ wire: HttpClient;
71
93
  };
94
+ declare function httpClient(cfg?: MakeHttpConfig): Dx;
72
95
  declare function httpClientWithMeta(cfg?: MakeHttpConfig): {
73
- request: (req: HttpRequest) => Async<unknown, HttpError, HttpWireResponse>;
74
- getText: (url: string, init?: Omit<RequestInit, "method">) => Async<unknown, HttpError, HttpResponseWithMeta<string>>;
75
- getJson: <A>(url: string, init?: Omit<RequestInit, "method">) => Async<unknown, HttpError, HttpResponseWithMeta<A>>;
76
- post: (url: string, body?: string, init?: HttpInit & {
77
- headers?: Record<string, string>;
78
- }) => Async<unknown, HttpError, HttpResponseWithMeta<string>>;
96
+ request: (req: HttpRequest) => AsyncWithPromise<unknown, HttpError, {
97
+ wire: HttpWireResponse;
98
+ meta: HttpMeta;
99
+ }>;
100
+ get: (url: string, init?: InitNoMethodBody) => AsyncWithPromise<unknown, HttpError, {
101
+ wire: HttpWireResponse;
102
+ meta: HttpMeta;
103
+ }>;
104
+ getText: (url: string, init?: InitNoMethodBody) => AsyncWithPromise<unknown, HttpError, {
105
+ wire: HttpWireResponse;
106
+ response: {
107
+ status: number;
108
+ statusText: string;
109
+ headers: Record<string, string>;
110
+ body: string;
111
+ };
112
+ meta: HttpMeta;
113
+ }>;
114
+ getJson: <A>(url: string, init?: InitNoMethodBody) => AsyncWithPromise<unknown, HttpError, {
115
+ wire: HttpWireResponse;
116
+ response: {
117
+ status: number;
118
+ statusText: string;
119
+ headers: Record<string, string>;
120
+ body: A;
121
+ };
122
+ meta: HttpMeta;
123
+ }>;
124
+ post: (url: string, body?: string, init?: InitNoMethodBody) => AsyncWithPromise<unknown, HttpError, {
125
+ wire: HttpWireResponse;
126
+ meta: HttpMeta;
127
+ }>;
79
128
  postJson: <A>(url: string, bodyObj: A, init?: HttpInit & {
80
129
  headers?: Record<string, string>;
81
- }) => Async<unknown, HttpError, HttpResponseWithMeta<string>>;
130
+ }) => AsyncWithPromise<unknown, HttpError, {
131
+ wire: HttpWireResponse;
132
+ meta: HttpMeta;
133
+ }>;
82
134
  };
83
- type HttpClientDxStream = {
84
- request: (req: HttpRequest) => Async<unknown, HttpError, HttpResponseStream>;
85
- get: (url: string, init?: Omit<RequestInit, "method">) => Async<unknown, HttpError, HttpResponseStream>;
86
- post: (url: string, body?: string, init?: Omit<RequestInit, "method" | "body">) => Async<unknown, HttpError, HttpResponseStream>;
87
- postJson: <A extends object>(url: string, body: A, init?: Omit<RequestInit, "method" | "body">) => Async<unknown, HttpError, HttpResponseStream>;
135
+ declare function httpClientStream(cfg?: MakeHttpConfig): {
136
+ request: (req: HttpRequest) => AsyncWithPromise<unknown, HttpError, HttpWireResponseStream>;
137
+ getStream: (url: string, init?: InitNoMethodBody) => AsyncWithPromise<unknown, HttpError, HttpWireResponseStream>;
138
+ get: (url: string, init?: InitNoMethodBody) => AsyncWithPromise<unknown, HttpError, HttpWireResponseStream>;
139
+ with: (mw: (n: HttpClientStream) => HttpClientStream) => /*elided*/ any;
140
+ withRetry: (p: RetryPolicy) => /*elided*/ any;
141
+ wire: HttpClientStream;
88
142
  };
89
- declare function httpClientStream(cfg?: MakeHttpConfig): HttpClientDxStream;
90
143
 
91
- export { type HttpClient, type HttpClientDxStream, type HttpClientStream, type HttpError, type HttpInit, type HttpMeta, type HttpMethod, type HttpRequest, type HttpResponse, type HttpResponseStream, type HttpResponseWithMeta, type HttpWireResponse, type HttpWireResponseStream, type MakeHttpConfig, httpClient, httpClientStream, httpClientWithMeta, makeHttp, makeHttpStream, mapAsync, mapTryAsync };
144
+ export { type Dx, type HttpClient, type HttpClientFn, type HttpClientStream, type HttpError, type HttpInit, type HttpMeta, type HttpMethod, type HttpMiddleware, type HttpRequest, type HttpResponse, type HttpResponseWithMeta, type HttpWireResponse, type HttpWireResponseStream, type HttpWireWithMeta, type MakeHttpConfig, decorate, httpClient, httpClientStream, httpClientWithMeta, makeHttp, makeHttpStream, normalizeHeadersInit, withMiddleware, withRetryStream };
@@ -1 +1 @@
1
- 'use strict';var chunkM3UFQBVT_js=require('../chunk-M3UFQBVT.js');function f(e={}){let o=e.baseUrl??"",n=e.headers??{};return p=>chunkM3UFQBVT_js.I(async i=>{let u=new URL(p.url,o),a=performance.now(),t=await fetch(u,{...p.init??{},method:p.method,headers:{...n,...p.headers??{}},body:p.body,signal:i}),s={};t.headers.forEach((d,m)=>s[m]=d);let r=chunkM3UFQBVT_js.aa(t.body,R);return {status:t.status,statusText:t.statusText,headers:s,body:r,ms:Math.round(performance.now()-a)}},R)}var R=e=>e instanceof DOMException&&e.name==="AbortError"?{_tag:"Abort"}:typeof e=="object"&&e&&"_tag"in e?e:{_tag:"FetchError",message:String(e)};function A(e={}){let o=e.baseUrl??"",n=e.headers??{};return p=>chunkM3UFQBVT_js.I(async i=>{let u;try{u=new URL(p.url,o);}catch{throw {_tag:"BadUrl",message:`URL inv\xE1lida: ${p.url}`}}let a=performance.now(),t=await fetch(u,{...p.init??{},method:p.method,headers:{...n,...p.headers??{}},body:p.body,signal:i}),s=await t.text(),r={};return t.headers.forEach((d,m)=>r[m]=d),{status:t.status,statusText:t.statusText,headers:r,bodyText:s,ms:Math.round(performance.now()-a)}},R)}var q=(e,o)=>chunkM3UFQBVT_js.k(e,n=>chunkM3UFQBVT_js.e(o(n))),c=(e,o)=>chunkM3UFQBVT_js.k(e,n=>chunkM3UFQBVT_js.g(()=>o(n)));var S=(e,o)=>({status:e.status,headers:e.headers,body:o}),h=(e,o)=>({status:e.status,headers:e.headers,body:o,meta:{statusText:e.statusText,ms:e.ms}});function L(e={}){let o=A(e),n=(t,s,r)=>i({method:"POST",url:t,body:s&&s.length>0?s:void 0,init:r}),p=(t,s,r)=>{let{headers:d,...m}=r??{};return i({method:"POST",url:t,body:JSON.stringify(s),headers:{"content-type":"application/json",...d??{}},init:m})},i=t=>o(t);return {request:i,getText:(t,s)=>c(i({method:"GET",url:t,init:s}),r=>S(r,r.bodyText)),getJson:(t,s)=>c(i({method:"GET",url:t,init:s}),r=>S(r,JSON.parse(r.bodyText))),post:n,postJson:p}}function Z(e={}){let o=A(e),n=t=>o(t);return {request:n,getText:(t,s)=>c(n({method:"GET",url:t,init:s}),r=>h(r,r.bodyText)),getJson:(t,s)=>c(n({method:"GET",url:t,init:s}),r=>h(r,JSON.parse(r.bodyText))),post:(t,s,r)=>{let{headers:d,...m}=r??{};return c(n({method:"POST",url:t,body:s&&s.length>0?s:void 0,headers:d,init:m}),g=>h(g,g.bodyText))},postJson:(t,s,r)=>{let{headers:d,...m}=r??{};return c(n({method:"POST",url:t,body:JSON.stringify(s),headers:{"content-type":"application/json",...d??{}},init:m}),g=>h(g,g.bodyText))}}}var T=e=>({status:e.status,headers:e.headers,body:e.body});function F(e={}){let o=f(e),n=a=>c(o(a),T);return {request:n,get:(a,t)=>n({method:"GET",url:a,init:t}),post:(a,t,s)=>n({method:"POST",url:a,body:t&&t.length>0?t:void 0,init:s}),postJson:(a,t,s)=>n({method:"POST",url:a,body:JSON.stringify(t),headers:{"content-type":"application/json",...s?.headers},init:{...s??{}}})}}exports.httpClient=L;exports.httpClientStream=F;exports.httpClientWithMeta=Z;exports.makeHttp=A;exports.makeHttpStream=f;exports.mapAsync=q;exports.mapTryAsync=c;
1
+ 'use strict';var chunk3NPW2C22_js=require('../chunk-3NPW2C22.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=>chunk3NPW2C22_js.L(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=chunk3NPW2C22_js.da(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=>chunk3NPW2C22_js.L(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=>chunk3NPW2C22_js.L(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=>chunk3NPW2C22_js.a(e(r),a=>{if(a._tag==="Abort"||a._tag==="BadUrl")return chunk3NPW2C22_js.f(a);if(!(c<t.maxRetries&&(t.retryOnError??J)(a)))return chunk3NPW2C22_js.f(a);let i=F(c,t.baseDelayMs,t.maxDelayMs);return chunk3NPW2C22_js.k(D(i),()=>n(c+1))},a=>{if(!(c<t.maxRetries&&(t.retryOnStatus??G)(a.status)))return chunk3NPW2C22_js.e(a);let p=z(a.headers)??F(c,t.baseDelayMs,t.maxDelayMs);return chunk3NPW2C22_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=>chunk3NPW2C22_js.L(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)?chunk3NPW2C22_js.a(e(i),s=>{if(s._tag==="Abort"||s._tag==="BadUrl")return chunk3NPW2C22_js.f(s);if(!(p<t.maxRetries&&c(s)))return chunk3NPW2C22_js.f(s);let o=N(p,t.baseDelayMs,t.maxDelayMs);return chunk3NPW2C22_js.k(L(o),()=>y(i,p+1))},s=>{if(!(p<t.maxRetries&&n(s.status)))return chunk3NPW2C22_js.e(s);let d=Y(s.headers)??N(p,t.baseDelayMs,t.maxDelayMs);return chunk3NPW2C22_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=>chunk3NPW2C22_js.n((s,u)=>chunk3NPW2C22_js.H(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(chunk3NPW2C22_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(chunk3NPW2C22_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(chunk3NPW2C22_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(chunk3NPW2C22_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(chunk3NPW2C22_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=>chunk3NPW2C22_js.n((p,s)=>chunk3NPW2C22_js.H(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=_;
@@ -1 +1 @@
1
- import {k,I,aa,e,g}from'../chunk-MOD6OFUQ.mjs';function f(e={}){let o=e.baseUrl??"",n=e.headers??{};return p=>I(async i=>{let u=new URL(p.url,o),a=performance.now(),t=await fetch(u,{...p.init??{},method:p.method,headers:{...n,...p.headers??{}},body:p.body,signal:i}),s={};t.headers.forEach((d,m)=>s[m]=d);let r=aa(t.body,R);return {status:t.status,statusText:t.statusText,headers:s,body:r,ms:Math.round(performance.now()-a)}},R)}var R=e=>e instanceof DOMException&&e.name==="AbortError"?{_tag:"Abort"}:typeof e=="object"&&e&&"_tag"in e?e:{_tag:"FetchError",message:String(e)};function A(e={}){let o=e.baseUrl??"",n=e.headers??{};return p=>I(async i=>{let u;try{u=new URL(p.url,o);}catch{throw {_tag:"BadUrl",message:`URL inv\xE1lida: ${p.url}`}}let a=performance.now(),t=await fetch(u,{...p.init??{},method:p.method,headers:{...n,...p.headers??{}},body:p.body,signal:i}),s=await t.text(),r={};return t.headers.forEach((d,m)=>r[m]=d),{status:t.status,statusText:t.statusText,headers:r,bodyText:s,ms:Math.round(performance.now()-a)}},R)}var q=(e$1,o)=>k(e$1,n=>e(o(n))),c=(e,o)=>k(e,n=>g(()=>o(n)));var S=(e,o)=>({status:e.status,headers:e.headers,body:o}),h=(e,o)=>({status:e.status,headers:e.headers,body:o,meta:{statusText:e.statusText,ms:e.ms}});function L(e={}){let o=A(e),n=(t,s,r)=>i({method:"POST",url:t,body:s&&s.length>0?s:void 0,init:r}),p=(t,s,r)=>{let{headers:d,...m}=r??{};return i({method:"POST",url:t,body:JSON.stringify(s),headers:{"content-type":"application/json",...d??{}},init:m})},i=t=>o(t);return {request:i,getText:(t,s)=>c(i({method:"GET",url:t,init:s}),r=>S(r,r.bodyText)),getJson:(t,s)=>c(i({method:"GET",url:t,init:s}),r=>S(r,JSON.parse(r.bodyText))),post:n,postJson:p}}function Z(e={}){let o=A(e),n=t=>o(t);return {request:n,getText:(t,s)=>c(n({method:"GET",url:t,init:s}),r=>h(r,r.bodyText)),getJson:(t,s)=>c(n({method:"GET",url:t,init:s}),r=>h(r,JSON.parse(r.bodyText))),post:(t,s,r)=>{let{headers:d,...m}=r??{};return c(n({method:"POST",url:t,body:s&&s.length>0?s:void 0,headers:d,init:m}),g=>h(g,g.bodyText))},postJson:(t,s,r)=>{let{headers:d,...m}=r??{};return c(n({method:"POST",url:t,body:JSON.stringify(s),headers:{"content-type":"application/json",...d??{}},init:m}),g=>h(g,g.bodyText))}}}var T=e=>({status:e.status,headers:e.headers,body:e.body});function F(e={}){let o=f(e),n=a=>c(o(a),T);return {request:n,get:(a,t)=>n({method:"GET",url:a,init:t}),post:(a,t,s)=>n({method:"POST",url:a,body:t&&t.length>0?t:void 0,init:s}),postJson:(a,t,s)=>n({method:"POST",url:a,body:JSON.stringify(t),headers:{"content-type":"application/json",...s?.headers},init:{...s??{}}})}}export{L as httpClient,F as httpClientStream,Z as httpClientWithMeta,A as makeHttp,f as makeHttpStream,q as mapAsync,c as mapTryAsync};
1
+ import {L as L$1,da,a,p,n,f as f$1,k as k$1,e,H}from'../chunk-SNH7DUUJ.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=>L$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=da(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=>L$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=>L$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=>L$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)=>H(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)=>H(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-wtsKMh6j.mjs';
2
- export { z as CancelToken, C as Canceler, J as Concat, H as Emit, G as Empty, aa as FiberId, ab as FiberStatus, K as Flatten, L as FromPull, M as Merge, N as None, R as Normalize, O as Option, ac as RuntimeFiber, ae as Scope, ad as ScopeId, P as Scoped, w as Some, ag as Task, Z as ZIO, Q as ZStream, t as acquireRelease, p as async, h as asyncCatchAll, k as asyncFail, r as asyncFlatMap, g as asyncFold, v as asyncInterruptible, q as asyncMap, i as asyncMapError, j as asyncSucceed, l as asyncSync, n as asyncTotal, d as catchAll, a8 as collectStream, $ as concatStream, _ as emitStream, Y as emptyStream, e as end, f as fail, b as flatMap, a0 as flattenStream, a6 as foreachStream, a7 as fromArray, U as fromPull, ah as globalScheduler, D as linkAbortController, B as makeCancelToken, W as managedStream, m as map, c as mapError, a3 as mapStream, a1 as merge, X as mergeStream, x as none, o as orElseOptional, a4 as rangeStream, y as some, a9 as streamFromReadableStream, s as succeed, a as sync, a2 as uncons, u as unit, V as unwrapScoped, T as widenOpt, af as withScope, a5 as zip } from './stream-wtsKMh6j.mjs';
1
+ import { A as Async, S as Scheduler, F as Fiber, E as Exit, I as Interrupted } from './stream-Byv3iEEs.mjs';
2
+ export { w as AsyncWithPromise, H as CancelToken, G as Canceler, P as Concat, M as Emit, L as Empty, ae as FiberId, af as FiberStatus, Q as Flatten, R as FromPull, T as Merge, N as None, W as Normalize, O as Option, ag as RuntimeFiber, ai as Scope, ah as ScopeId, U as Scoped, B as Some, ak as Task, Z as ZIO, V as ZStream, t as acquireRelease, p as async, h as asyncCatchAll, k as asyncFail, r as asyncFlatMap, g as asyncFold, v as asyncInterruptible, q as asyncMap, i as asyncMapError, j as asyncSucceed, l as asyncSync, n as asyncTotal, d as catchAll, ac as collectStream, a3 as concatStream, a2 as emitStream, a1 as emptyStream, e as end, f as fail, b as flatMap, a4 as flattenStream, aa as foreachStream, ab as fromArray, Y as fromPull, al as globalScheduler, K as linkAbortController, J as makeCancelToken, $ as managedStream, m as map, y as mapAsync, c as mapError, a7 as mapStream, z as mapTryAsync, a5 as merge, a0 as mergeStream, C as none, o as orElseOptional, a8 as rangeStream, D as some, ad as streamFromReadableStream, s as succeed, a as sync, a6 as uncons, u as unit, _ as unwrapScoped, X as widenOpt, x as withAsyncPromise, aj as withScope, a9 as zip } from './stream-Byv3iEEs.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>;
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-wtsKMh6j.js';
2
- export { z as CancelToken, C as Canceler, J as Concat, H as Emit, G as Empty, aa as FiberId, ab as FiberStatus, K as Flatten, L as FromPull, M as Merge, N as None, R as Normalize, O as Option, ac as RuntimeFiber, ae as Scope, ad as ScopeId, P as Scoped, w as Some, ag as Task, Z as ZIO, Q as ZStream, t as acquireRelease, p as async, h as asyncCatchAll, k as asyncFail, r as asyncFlatMap, g as asyncFold, v as asyncInterruptible, q as asyncMap, i as asyncMapError, j as asyncSucceed, l as asyncSync, n as asyncTotal, d as catchAll, a8 as collectStream, $ as concatStream, _ as emitStream, Y as emptyStream, e as end, f as fail, b as flatMap, a0 as flattenStream, a6 as foreachStream, a7 as fromArray, U as fromPull, ah as globalScheduler, D as linkAbortController, B as makeCancelToken, W as managedStream, m as map, c as mapError, a3 as mapStream, a1 as merge, X as mergeStream, x as none, o as orElseOptional, a4 as rangeStream, y as some, a9 as streamFromReadableStream, s as succeed, a as sync, a2 as uncons, u as unit, V as unwrapScoped, T as widenOpt, af as withScope, a5 as zip } from './stream-wtsKMh6j.js';
1
+ import { A as Async, S as Scheduler, F as Fiber, E as Exit, I as Interrupted } from './stream-Byv3iEEs.js';
2
+ export { w as AsyncWithPromise, H as CancelToken, G as Canceler, P as Concat, M as Emit, L as Empty, ae as FiberId, af as FiberStatus, Q as Flatten, R as FromPull, T as Merge, N as None, W as Normalize, O as Option, ag as RuntimeFiber, ai as Scope, ah as ScopeId, U as Scoped, B as Some, ak as Task, Z as ZIO, V as ZStream, t as acquireRelease, p as async, h as asyncCatchAll, k as asyncFail, r as asyncFlatMap, g as asyncFold, v as asyncInterruptible, q as asyncMap, i as asyncMapError, j as asyncSucceed, l as asyncSync, n as asyncTotal, d as catchAll, ac as collectStream, a3 as concatStream, a2 as emitStream, a1 as emptyStream, e as end, f as fail, b as flatMap, a4 as flattenStream, aa as foreachStream, ab as fromArray, Y as fromPull, al as globalScheduler, K as linkAbortController, J as makeCancelToken, $ as managedStream, m as map, y as mapAsync, c as mapError, a7 as mapStream, z as mapTryAsync, a5 as merge, a0 as mergeStream, C as none, o as orElseOptional, a8 as rangeStream, D as some, ad as streamFromReadableStream, s as succeed, a as sync, a6 as uncons, u as unit, _ as unwrapScoped, X as widenOpt, x as withAsyncPromise, aj as withScope, a9 as zip } from './stream-Byv3iEEs.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>;
package/dist/index.js CHANGED
@@ -1 +1 @@
1
- 'use strict';var chunkM3UFQBVT_js=require('./chunk-M3UFQBVT.js');function te(){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 ce(e,r){return e.onCancel(()=>r.abort())}Object.defineProperty(exports,"RuntimeFiber",{enumerable:true,get:function(){return chunkM3UFQBVT_js.A}});Object.defineProperty(exports,"Scheduler",{enumerable:true,get:function(){return chunkM3UFQBVT_js.y}});Object.defineProperty(exports,"Scope",{enumerable:true,get:function(){return chunkM3UFQBVT_js.J}});Object.defineProperty(exports,"acquireRelease",{enumerable:true,get:function(){return chunkM3UFQBVT_js.l}});Object.defineProperty(exports,"async",{enumerable:true,get:function(){return chunkM3UFQBVT_js.i}});Object.defineProperty(exports,"asyncCatchAll",{enumerable:true,get:function(){return chunkM3UFQBVT_js.b}});Object.defineProperty(exports,"asyncFail",{enumerable:true,get:function(){return chunkM3UFQBVT_js.f}});Object.defineProperty(exports,"asyncFlatMap",{enumerable:true,get:function(){return chunkM3UFQBVT_js.k}});Object.defineProperty(exports,"asyncFold",{enumerable:true,get:function(){return chunkM3UFQBVT_js.a}});Object.defineProperty(exports,"asyncInterruptible",{enumerable:true,get:function(){return chunkM3UFQBVT_js.m}});Object.defineProperty(exports,"asyncMap",{enumerable:true,get:function(){return chunkM3UFQBVT_js.j}});Object.defineProperty(exports,"asyncMapError",{enumerable:true,get:function(){return chunkM3UFQBVT_js.c}});Object.defineProperty(exports,"asyncSucceed",{enumerable:true,get:function(){return chunkM3UFQBVT_js.e}});Object.defineProperty(exports,"asyncSync",{enumerable:true,get:function(){return chunkM3UFQBVT_js.g}});Object.defineProperty(exports,"asyncTotal",{enumerable:true,get:function(){return chunkM3UFQBVT_js.h}});Object.defineProperty(exports,"catchAll",{enumerable:true,get:function(){return chunkM3UFQBVT_js.v}});Object.defineProperty(exports,"collectStream",{enumerable:true,get:function(){return chunkM3UFQBVT_js.$}});Object.defineProperty(exports,"concatStream",{enumerable:true,get:function(){return chunkM3UFQBVT_js.S}});Object.defineProperty(exports,"emitStream",{enumerable:true,get:function(){return chunkM3UFQBVT_js.R}});Object.defineProperty(exports,"emptyStream",{enumerable:true,get:function(){return chunkM3UFQBVT_js.Q}});Object.defineProperty(exports,"end",{enumerable:true,get:function(){return chunkM3UFQBVT_js.x}});Object.defineProperty(exports,"fail",{enumerable:true,get:function(){return chunkM3UFQBVT_js.q}});Object.defineProperty(exports,"flatMap",{enumerable:true,get:function(){return chunkM3UFQBVT_js.t}});Object.defineProperty(exports,"flattenStream",{enumerable:true,get:function(){return chunkM3UFQBVT_js.T}});Object.defineProperty(exports,"foreachStream",{enumerable:true,get:function(){return chunkM3UFQBVT_js.Z}});Object.defineProperty(exports,"fork",{enumerable:true,get:function(){return chunkM3UFQBVT_js.C}});Object.defineProperty(exports,"from",{enumerable:true,get:function(){return chunkM3UFQBVT_js.B}});Object.defineProperty(exports,"fromArray",{enumerable:true,get:function(){return chunkM3UFQBVT_js._}});Object.defineProperty(exports,"fromCallback",{enumerable:true,get:function(){return chunkM3UFQBVT_js.G}});Object.defineProperty(exports,"fromPromise",{enumerable:true,get:function(){return chunkM3UFQBVT_js.F}});Object.defineProperty(exports,"fromPromiseAbortable",{enumerable:true,get:function(){return chunkM3UFQBVT_js.I}});Object.defineProperty(exports,"fromPull",{enumerable:true,get:function(){return chunkM3UFQBVT_js.M}});Object.defineProperty(exports,"globalScheduler",{enumerable:true,get:function(){return chunkM3UFQBVT_js.z}});Object.defineProperty(exports,"managedStream",{enumerable:true,get:function(){return chunkM3UFQBVT_js.O}});Object.defineProperty(exports,"map",{enumerable:true,get:function(){return chunkM3UFQBVT_js.s}});Object.defineProperty(exports,"mapError",{enumerable:true,get:function(){return chunkM3UFQBVT_js.u}});Object.defineProperty(exports,"mapStream",{enumerable:true,get:function(){return chunkM3UFQBVT_js.W}});Object.defineProperty(exports,"merge",{enumerable:true,get:function(){return chunkM3UFQBVT_js.U}});Object.defineProperty(exports,"mergeStream",{enumerable:true,get:function(){return chunkM3UFQBVT_js.P}});Object.defineProperty(exports,"none",{enumerable:true,get:function(){return chunkM3UFQBVT_js.n}});Object.defineProperty(exports,"orElseOptional",{enumerable:true,get:function(){return chunkM3UFQBVT_js.w}});Object.defineProperty(exports,"rangeStream",{enumerable:true,get:function(){return chunkM3UFQBVT_js.X}});Object.defineProperty(exports,"some",{enumerable:true,get:function(){return chunkM3UFQBVT_js.o}});Object.defineProperty(exports,"streamFromReadableStream",{enumerable:true,get:function(){return chunkM3UFQBVT_js.aa}});Object.defineProperty(exports,"succeed",{enumerable:true,get:function(){return chunkM3UFQBVT_js.p}});Object.defineProperty(exports,"sync",{enumerable:true,get:function(){return chunkM3UFQBVT_js.r}});Object.defineProperty(exports,"toPromise",{enumerable:true,get:function(){return chunkM3UFQBVT_js.E}});Object.defineProperty(exports,"tryPromiseAbortable",{enumerable:true,get:function(){return chunkM3UFQBVT_js.H}});Object.defineProperty(exports,"uncons",{enumerable:true,get:function(){return chunkM3UFQBVT_js.V}});Object.defineProperty(exports,"unit",{enumerable:true,get:function(){return chunkM3UFQBVT_js.d}});Object.defineProperty(exports,"unsafeRunAsync",{enumerable:true,get:function(){return chunkM3UFQBVT_js.D}});Object.defineProperty(exports,"unwrapScoped",{enumerable:true,get:function(){return chunkM3UFQBVT_js.N}});Object.defineProperty(exports,"widenOpt",{enumerable:true,get:function(){return chunkM3UFQBVT_js.L}});Object.defineProperty(exports,"withScope",{enumerable:true,get:function(){return chunkM3UFQBVT_js.K}});Object.defineProperty(exports,"zip",{enumerable:true,get:function(){return chunkM3UFQBVT_js.Y}});exports.linkAbortController=ce;exports.makeCancelToken=te;
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;
package/dist/index.mjs CHANGED
@@ -1 +1 @@
1
- export{A as RuntimeFiber,y as Scheduler,J 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,v as catchAll,$ as collectStream,S as concatStream,R as emitStream,Q as emptyStream,x as end,q as fail,t as flatMap,T as flattenStream,Z as foreachStream,C as fork,B as from,_ as fromArray,G as fromCallback,F as fromPromise,I as fromPromiseAbortable,M as fromPull,z as globalScheduler,O as managedStream,s as map,u as mapError,W as mapStream,U as merge,P as mergeStream,n as none,w as orElseOptional,X as rangeStream,o as some,aa as streamFromReadableStream,p as succeed,r as sync,E as toPromise,H as tryPromiseAbortable,V as uncons,d as unit,D as unsafeRunAsync,N as unwrapScoped,L as widenOpt,K as withScope,Y as zip}from'./chunk-MOD6OFUQ.mjs';function te(){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 ce(e,r){return e.onCancel(()=>r.abort())}export{ce as linkAbortController,te as makeCancelToken};
1
+ export{D as RuntimeFiber,B as Scheduler,M 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,ca as collectStream,V as concatStream,U as emitStream,T as emptyStream,A as end,t as fail,w as flatMap,W as flattenStream,aa as foreachStream,F as fork,E as from,ba as fromArray,J as fromCallback,I as fromPromise,L as fromPromiseAbortable,P as fromPull,C as globalScheduler,R as managedStream,v as map,o as mapAsync,x as mapError,Z as mapStream,p as mapTryAsync,X as merge,S as mergeStream,q as none,z as orElseOptional,_ as rangeStream,r as some,da as streamFromReadableStream,s as succeed,u as sync,H as toPromise,K as tryPromiseAbortable,Y as uncons,d as unit,G as unsafeRunAsync,Q as unwrapScoped,O as widenOpt,n as withAsyncPromise,N as withScope,$ as zip}from'./chunk-SNH7DUUJ.mjs';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())}export{pe as linkAbortController,Ce as makeCancelToken};
@@ -132,6 +132,13 @@ declare function asyncMap<R, E, A, B>(fa: Async<R, E, A>, f: (a: A) => B): Async
132
132
  declare function asyncFlatMap<R, E, A, B>(fa: Async<R, E, A>, f: (a: A) => Async<R, E, B>): Async<R, E, B>;
133
133
  declare function acquireRelease<R, E, A>(acquire: Async<R, E, A>, release: (res: A, exit: Exit<E, any>) => Async<R, any, any>, scope: Scope<R>): Async<R, E, A>;
134
134
  declare function asyncInterruptible<R, E, A>(register: (env: R, cb: (exit: Exit<E, A>) => void) => void | Canceler): Async<R, E, A>;
135
+ type AsyncWithPromise<R, E, A> = Async<R, E, A> & {
136
+ toPromise: (env: R) => Promise<A>;
137
+ unsafeRunPromise: () => Promise<A>;
138
+ };
139
+ declare const withAsyncPromise: <R, E, A>(run: (eff: Async<R, E, A>, env: R) => Promise<A>) => (eff: Async<R, E, A>) => AsyncWithPromise<R, E, A>;
140
+ declare const mapAsync: <R, E, A, B>(fa: Async<R, E, A>, f: (a: A) => B) => Async<R, E, B>;
141
+ declare const mapTryAsync: <R, E, A, B>(fa: Async<R, E, A>, f: (a: A) => B) => Async<R, E, B>;
135
142
 
136
143
  type None = {
137
144
  readonly _tag: "None";
@@ -217,4 +224,4 @@ declare function fromArray<A>(values: readonly A[]): ZStream<unknown, never, A>;
217
224
  declare function collectStream<R, E, A>(stream: ZStream<R, E, A>): ZIO<R, E, A[]>;
218
225
  declare function streamFromReadableStream<E>(body: ReadableStream<Uint8Array> | null | undefined, normalizeError: Normalize<E>): ZStream<unknown, E, Uint8Array>;
219
226
 
220
- export { concatStream as $, type Async as A, makeCancelToken as B, type Canceler as C, linkAbortController as D, type Exit as E, type Fiber as F, type Empty as G, type Emit as H, type Interrupted as I, type Concat as J, type Flatten as K, type FromPull as L, type Merge as M, type None as N, type Option as O, type Scoped as P, type ZStream as Q, type Normalize as R, Scheduler as S, widenOpt as T, fromPull as U, unwrapScoped as V, managedStream as W, mergeStream as X, emptyStream as Y, type ZIO as Z, emitStream as _, sync as a, flattenStream as a0, merge as a1, uncons as a2, mapStream as a3, rangeStream as a4, zip as a5, foreachStream as a6, fromArray as a7, collectStream as a8, streamFromReadableStream as a9, type FiberId as aa, type FiberStatus as ab, RuntimeFiber as ac, type ScopeId as ad, Scope as ae, withScope as af, type Task as ag, globalScheduler as ah, flatMap as b, mapError as c, catchAll as d, end as e, fail as f, asyncFold as g, asyncCatchAll as h, asyncMapError as i, asyncSucceed as j, asyncFail as k, asyncSync as l, map as m, asyncTotal as n, orElseOptional as o, async as p, asyncMap as q, asyncFlatMap as r, succeed as s, acquireRelease as t, unit as u, asyncInterruptible as v, type Some as w, none as x, some as y, type CancelToken as z };
227
+ export { managedStream as $, type Async as A, type Some as B, none as C, some as D, type Exit as E, type Fiber as F, type Canceler as G, type CancelToken as H, type Interrupted as I, makeCancelToken as J, linkAbortController as K, type Empty as L, type Emit as M, type None as N, type Option as O, type Concat as P, type Flatten as Q, type FromPull as R, Scheduler as S, type Merge as T, type Scoped as U, type ZStream as V, type Normalize as W, widenOpt as X, fromPull as Y, type ZIO as Z, unwrapScoped as _, sync as a, mergeStream as a0, emptyStream as a1, emitStream as a2, concatStream as a3, flattenStream as a4, merge as a5, uncons as a6, mapStream as a7, rangeStream as a8, zip as a9, foreachStream as aa, fromArray as ab, collectStream as ac, streamFromReadableStream as ad, type FiberId as ae, type FiberStatus as af, RuntimeFiber as ag, type ScopeId as ah, Scope as ai, withScope as aj, type Task as ak, globalScheduler as al, flatMap as b, mapError as c, catchAll as d, end as e, fail as f, asyncFold as g, asyncCatchAll as h, asyncMapError as i, asyncSucceed as j, asyncFail as k, asyncSync as l, map as m, asyncTotal as n, orElseOptional as o, async as p, asyncMap as q, asyncFlatMap as r, succeed as s, acquireRelease as t, unit as u, asyncInterruptible as v, type AsyncWithPromise as w, withAsyncPromise as x, mapAsync as y, mapTryAsync as z };
@@ -132,6 +132,13 @@ declare function asyncMap<R, E, A, B>(fa: Async<R, E, A>, f: (a: A) => B): Async
132
132
  declare function asyncFlatMap<R, E, A, B>(fa: Async<R, E, A>, f: (a: A) => Async<R, E, B>): Async<R, E, B>;
133
133
  declare function acquireRelease<R, E, A>(acquire: Async<R, E, A>, release: (res: A, exit: Exit<E, any>) => Async<R, any, any>, scope: Scope<R>): Async<R, E, A>;
134
134
  declare function asyncInterruptible<R, E, A>(register: (env: R, cb: (exit: Exit<E, A>) => void) => void | Canceler): Async<R, E, A>;
135
+ type AsyncWithPromise<R, E, A> = Async<R, E, A> & {
136
+ toPromise: (env: R) => Promise<A>;
137
+ unsafeRunPromise: () => Promise<A>;
138
+ };
139
+ declare const withAsyncPromise: <R, E, A>(run: (eff: Async<R, E, A>, env: R) => Promise<A>) => (eff: Async<R, E, A>) => AsyncWithPromise<R, E, A>;
140
+ declare const mapAsync: <R, E, A, B>(fa: Async<R, E, A>, f: (a: A) => B) => Async<R, E, B>;
141
+ declare const mapTryAsync: <R, E, A, B>(fa: Async<R, E, A>, f: (a: A) => B) => Async<R, E, B>;
135
142
 
136
143
  type None = {
137
144
  readonly _tag: "None";
@@ -217,4 +224,4 @@ declare function fromArray<A>(values: readonly A[]): ZStream<unknown, never, A>;
217
224
  declare function collectStream<R, E, A>(stream: ZStream<R, E, A>): ZIO<R, E, A[]>;
218
225
  declare function streamFromReadableStream<E>(body: ReadableStream<Uint8Array> | null | undefined, normalizeError: Normalize<E>): ZStream<unknown, E, Uint8Array>;
219
226
 
220
- export { concatStream as $, type Async as A, makeCancelToken as B, type Canceler as C, linkAbortController as D, type Exit as E, type Fiber as F, type Empty as G, type Emit as H, type Interrupted as I, type Concat as J, type Flatten as K, type FromPull as L, type Merge as M, type None as N, type Option as O, type Scoped as P, type ZStream as Q, type Normalize as R, Scheduler as S, widenOpt as T, fromPull as U, unwrapScoped as V, managedStream as W, mergeStream as X, emptyStream as Y, type ZIO as Z, emitStream as _, sync as a, flattenStream as a0, merge as a1, uncons as a2, mapStream as a3, rangeStream as a4, zip as a5, foreachStream as a6, fromArray as a7, collectStream as a8, streamFromReadableStream as a9, type FiberId as aa, type FiberStatus as ab, RuntimeFiber as ac, type ScopeId as ad, Scope as ae, withScope as af, type Task as ag, globalScheduler as ah, flatMap as b, mapError as c, catchAll as d, end as e, fail as f, asyncFold as g, asyncCatchAll as h, asyncMapError as i, asyncSucceed as j, asyncFail as k, asyncSync as l, map as m, asyncTotal as n, orElseOptional as o, async as p, asyncMap as q, asyncFlatMap as r, succeed as s, acquireRelease as t, unit as u, asyncInterruptible as v, type Some as w, none as x, some as y, type CancelToken as z };
227
+ export { managedStream as $, type Async as A, type Some as B, none as C, some as D, type Exit as E, type Fiber as F, type Canceler as G, type CancelToken as H, type Interrupted as I, makeCancelToken as J, linkAbortController as K, type Empty as L, type Emit as M, type None as N, type Option as O, type Concat as P, type Flatten as Q, type FromPull as R, Scheduler as S, type Merge as T, type Scoped as U, type ZStream as V, type Normalize as W, widenOpt as X, fromPull as Y, type ZIO as Z, unwrapScoped as _, sync as a, mergeStream as a0, emptyStream as a1, emitStream as a2, concatStream as a3, flattenStream as a4, merge as a5, uncons as a6, mapStream as a7, rangeStream as a8, zip as a9, foreachStream as aa, fromArray as ab, collectStream as ac, streamFromReadableStream as ad, type FiberId as ae, type FiberStatus as af, RuntimeFiber as ag, type ScopeId as ah, Scope as ai, withScope as aj, type Task as ak, globalScheduler as al, flatMap as b, mapError as c, catchAll as d, end as e, fail as f, asyncFold as g, asyncCatchAll as h, asyncMapError as i, asyncSucceed as j, asyncFail as k, asyncSync as l, map as m, asyncTotal as n, orElseOptional as o, async as p, asyncMap as q, asyncFlatMap as r, succeed as s, acquireRelease as t, unit as u, asyncInterruptible as v, type AsyncWithPromise as w, withAsyncPromise as x, mapAsync as y, mapTryAsync as z };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "brass-runtime",
3
- "version": "1.7.2",
3
+ "version": "1.9.0",
4
4
  "description": "Effect runtime utilities for TypeScript",
5
5
  "license": "ISC",
6
6
  "author": "",
@@ -1 +0,0 @@
1
- 'use strict';function p(t,e,n){return {_tag:"Fold",first:t,onFailure:e,onSuccess:n}}function Ee(t,e){return p(t,n=>e(n),n=>u(n))}function S(t,e){return p(t,n=>y(e(n)),n=>u(n))}var w=()=>u(void 0),u=t=>({_tag:"Succeed",value:t}),y=t=>({_tag:"Fail",error:t}),O=t=>({_tag:"Sync",thunk:t}),Ae=t=>O(()=>t()),l=t=>({_tag:"Async",register:t});function H(t,e){return d(t,n=>u(e(n)))}function d(t,e){return {_tag:"FlatMap",first:t,andThen:e}}function pe(t,e,n){return d(t,r=>(n.addFinalizer(a=>e(r,a)),u(r)))}function ye(t){return l(t)}var v={_tag:"None"},b=t=>({_tag:"Some",value:t});var z=t=>u(t),B=t=>y(t),G=t=>O(e=>t(e)),_=(t,e)=>H(t,e),Q=(t,e)=>d(t,n=>e(n)),M=(t,e)=>S(t,e),me=(t,e)=>p(t,n=>e(n),n=>u(n));function U(t,e){return p(t,n=>n._tag==="Some"?y(n):e(),n=>u(n))}var ge=()=>B(v);var N=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 W=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 N(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<W;){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>=W||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 P=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 Ne(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 F(t,e,n=J){let r=new P(t,e,n);return r.schedule("initial-step"),r}function Pe(t,e,n){F(t,e).join(n);}function Ce(t,e){return new Promise((n,r)=>{F(t,e).join(o=>{let i=o;i._tag==="Success"?n(i.value):r(i.error);});})}function De(t,e){return l((n,r)=>{t(n).then(a=>r({_tag:"Success",value:a})).catch(a=>r({_tag:"Failure",error:e(a)}));})}function Te(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 ze(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 p(t,()=>w(),()=>w())}var I=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=F(e,n);return this.children.add(r),r.join(()=>{this.children.delete(r);}),r}close(e={_tag:"Success",value:void 0}){F(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 A of o)try{A.interrupt();}catch{}let s=w();for(let A of i)s=d(s,()=>A.closeAsync(e,n));for(;this.finalizers.length>0;){let A=this.finalizers.pop();s=d(s,()=>ie(A(e)));}n.awaitChildren&&(s=d(s,()=>se(o))),F(s,this.env).join(()=>a({_tag:"Success",value:void 0}));})}};function Le(t){let e=new I({});try{return t(e)}finally{e.close();}}function K(t,e,n,r,a){return l((o,i)=>{let s=n.subScope(),c=false,A=s.fork(t,o),x=s.fork(e,o),g=f=>{s.fork(f,o).join(Z=>{s.close(Z),i(Z);});};A.join(f=>{c||(c=true,g(r(f,x,s)));}),x.join(f=>{c||(c=true,g(a(f,A,s)));});})}var q=t=>t._tag==="None"?v:b(t.value),m=t=>({_tag:"FromPull",pull:t}),ce=(t,e)=>({_tag:"Scoped",acquire:t,release:e}),at=t=>({_tag:"Scoped",acquire:d(t,e=>u(e.stream)),release:e=>d(t,n=>n.release(e))}),ot=(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 y(c);let A=c;return A._tag==="None"?E(t==="L"?n:e):y(A)}}function D(t,e,n,r){return l((a,o)=>{let s=new I(a),c=E(t),A=E(e),x=V("L",t,e),g=V("R",t,e),f=K(c,A,s,x,g);s.fork(f,a).join(Z=>{s.close(Z),o(Z);});})}function st(t,e){return m(D(t,e))}function E(t){switch(t._tag){case "Empty":return B(v);case "Emit":return _(M(t.value,e=>b(e)),e=>[e,T()]);case "FromPull":return t.pull;case "Concat":return U(_(E(t.left),([e,n])=>[e,C(n,t.right)]),()=>E(t.right));case "Flatten":return Q(E(t.stream),([e,n])=>U(_(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 I(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:b(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(_(t.value,e));case "FromPull":return m(_(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 it(t,e){let n=r=>m(r>e?y(v):u([r,n(r+1)]));return n(t)}function ue(t,e){let n=p(S(E(t),r=>q(r)),r=>y(r),([r,a])=>p(S(E(e),o=>q(o)),o=>y(o),([o,i])=>u([[r,o],ue(a,i)])));return m(n)}function ct(t,e){let n=r=>p(S(E(r),a=>q(a)),a=>a._tag==="None"?u(void 0):y(a),([a,o])=>d(S(e(a),i=>b(i)),()=>n(o)));return p(n(t),r=>r._tag==="None"?u(void 0):y(r.value),()=>u(void 0))}function ut(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 lt(t){let e=(n,r)=>p(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:b(e(o))});});});return m(n)}function Et(t,e){if(!t)return T();let n;return ce(G(()=>(n=t.getReader(),le(n,e))),()=>O(()=>{try{n?.cancel();}catch{}}))}exports.$=lt;exports.A=P;exports.B=Ne;exports.C=F;exports.D=Pe;exports.E=Ce;exports.F=De;exports.G=Te;exports.H=ze;exports.I=re;exports.J=I;exports.K=Le;exports.L=q;exports.M=m;exports.N=ce;exports.O=at;exports.P=ot;exports.Q=T;exports.R=X;exports.S=C;exports.T=L;exports.U=st;exports.V=E;exports.W=k;exports.X=it;exports.Y=ue;exports.Z=ct;exports._=ut;exports.a=p;exports.aa=Et;exports.b=Ee;exports.c=S;exports.d=w;exports.e=u;exports.f=y;exports.g=O;exports.h=Ae;exports.i=l;exports.j=H;exports.k=d;exports.l=pe;exports.m=ye;exports.n=v;exports.o=b;exports.p=z;exports.q=B;exports.r=G;exports.s=_;exports.t=Q;exports.u=M;exports.v=me;exports.w=U;exports.x=ge;exports.y=j;exports.z=J;
@@ -1 +0,0 @@
1
- function p(t,e,n){return {_tag:"Fold",first:t,onFailure:e,onSuccess:n}}function Ee(t,e){return p(t,n=>e(n),n=>u(n))}function S(t,e){return p(t,n=>y(e(n)),n=>u(n))}var w=()=>u(void 0),u=t=>({_tag:"Succeed",value:t}),y=t=>({_tag:"Fail",error:t}),O=t=>({_tag:"Sync",thunk:t}),Ae=t=>O(()=>t()),l=t=>({_tag:"Async",register:t});function H(t,e){return d(t,n=>u(e(n)))}function d(t,e){return {_tag:"FlatMap",first:t,andThen:e}}function pe(t,e,n){return d(t,r=>(n.addFinalizer(a=>e(r,a)),u(r)))}function ye(t){return l(t)}var v={_tag:"None"},b=t=>({_tag:"Some",value:t});var z=t=>u(t),B=t=>y(t),G=t=>O(e=>t(e)),_=(t,e)=>H(t,e),Q=(t,e)=>d(t,n=>e(n)),M=(t,e)=>S(t,e),me=(t,e)=>p(t,n=>e(n),n=>u(n));function U(t,e){return p(t,n=>n._tag==="Some"?y(n):e(),n=>u(n))}var ge=()=>B(v);var N=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 W=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 N(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<W;){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>=W||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 P=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 Ne(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 F(t,e,n=J){let r=new P(t,e,n);return r.schedule("initial-step"),r}function Pe(t,e,n){F(t,e).join(n);}function Ce(t,e){return new Promise((n,r)=>{F(t,e).join(o=>{let i=o;i._tag==="Success"?n(i.value):r(i.error);});})}function De(t,e){return l((n,r)=>{t(n).then(a=>r({_tag:"Success",value:a})).catch(a=>r({_tag:"Failure",error:e(a)}));})}function Te(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 ze(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 p(t,()=>w(),()=>w())}var I=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=F(e,n);return this.children.add(r),r.join(()=>{this.children.delete(r);}),r}close(e={_tag:"Success",value:void 0}){F(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 A of o)try{A.interrupt();}catch{}let s=w();for(let A of i)s=d(s,()=>A.closeAsync(e,n));for(;this.finalizers.length>0;){let A=this.finalizers.pop();s=d(s,()=>ie(A(e)));}n.awaitChildren&&(s=d(s,()=>se(o))),F(s,this.env).join(()=>a({_tag:"Success",value:void 0}));})}};function Le(t){let e=new I({});try{return t(e)}finally{e.close();}}function K(t,e,n,r,a){return l((o,i)=>{let s=n.subScope(),c=false,A=s.fork(t,o),x=s.fork(e,o),g=f=>{s.fork(f,o).join(Z=>{s.close(Z),i(Z);});};A.join(f=>{c||(c=true,g(r(f,x,s)));}),x.join(f=>{c||(c=true,g(a(f,A,s)));});})}var q=t=>t._tag==="None"?v:b(t.value),m=t=>({_tag:"FromPull",pull:t}),ce=(t,e)=>({_tag:"Scoped",acquire:t,release:e}),at=t=>({_tag:"Scoped",acquire:d(t,e=>u(e.stream)),release:e=>d(t,n=>n.release(e))}),ot=(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 y(c);let A=c;return A._tag==="None"?E(t==="L"?n:e):y(A)}}function D(t,e,n,r){return l((a,o)=>{let s=new I(a),c=E(t),A=E(e),x=V("L",t,e),g=V("R",t,e),f=K(c,A,s,x,g);s.fork(f,a).join(Z=>{s.close(Z),o(Z);});})}function st(t,e){return m(D(t,e))}function E(t){switch(t._tag){case "Empty":return B(v);case "Emit":return _(M(t.value,e=>b(e)),e=>[e,T()]);case "FromPull":return t.pull;case "Concat":return U(_(E(t.left),([e,n])=>[e,C(n,t.right)]),()=>E(t.right));case "Flatten":return Q(E(t.stream),([e,n])=>U(_(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 I(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:b(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(_(t.value,e));case "FromPull":return m(_(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 it(t,e){let n=r=>m(r>e?y(v):u([r,n(r+1)]));return n(t)}function ue(t,e){let n=p(S(E(t),r=>q(r)),r=>y(r),([r,a])=>p(S(E(e),o=>q(o)),o=>y(o),([o,i])=>u([[r,o],ue(a,i)])));return m(n)}function ct(t,e){let n=r=>p(S(E(r),a=>q(a)),a=>a._tag==="None"?u(void 0):y(a),([a,o])=>d(S(e(a),i=>b(i)),()=>n(o)));return p(n(t),r=>r._tag==="None"?u(void 0):y(r.value),()=>u(void 0))}function ut(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 lt(t){let e=(n,r)=>p(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:b(e(o))});});});return m(n)}function Et(t,e){if(!t)return T();let n;return ce(G(()=>(n=t.getReader(),le(n,e))),()=>O(()=>{try{n?.cancel();}catch{}}))}export{lt as $,P as A,Ne as B,F as C,Pe as D,Ce as E,De as F,Te as G,ze as H,re as I,I as J,Le as K,q as L,m as M,ce as N,at as O,ot as P,T as Q,X as R,C as S,L as T,st as U,E as V,k as W,it as X,ue as Y,ct as Z,ut as _,p as a,Et as aa,Ee as b,S as c,w as d,u as e,y as f,O as g,Ae as h,l as i,H as j,d as k,pe as l,ye as m,v as n,b as o,z as p,B as q,G as r,_ as s,Q as t,M as u,me as v,U as w,ge as x,j as y,J as z};