brass-runtime 1.6.2 → 1.7.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.
package/README.md CHANGED
@@ -108,7 +108,7 @@ Examples:
108
108
  - [x] Bounded buffers & backpressure
109
109
  - [x] Stream merge / zip
110
110
  - [x] Hubs / Broadcast
111
- - [ ] Pipelines (`ZPipeline`-style)
111
+ - [x] Pipelines (`ZPipeline`-style)
112
112
 
113
113
  ### Libraries
114
114
  - [x] HTTP client (`brass-http`)
@@ -0,0 +1 @@
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};
@@ -0,0 +1 @@
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,4 +1,4 @@
1
- import { A as Async } from '../effect-BTR2nIXd.mjs';
1
+ import { Q as ZStream, A as Async } from '../stream-wtsKMh6j.mjs';
2
2
 
3
3
  type HttpError = {
4
4
  _tag: "Abort";
@@ -28,68 +28,53 @@ type MakeHttpConfig = {
28
28
  baseUrl?: string;
29
29
  headers?: Record<string, string>;
30
30
  };
31
+ type HttpWireResponseStream = {
32
+ status: number;
33
+ statusText: string;
34
+ headers: Record<string, string>;
35
+ body: ZStream<unknown, HttpError, Uint8Array>;
36
+ ms: number;
37
+ };
38
+ type HttpClientStream = (req: HttpRequest) => Async<unknown, HttpError, HttpWireResponseStream>;
31
39
  type HttpClient = (req: HttpRequest) => Async<unknown, HttpError, HttpWireResponse>;
40
+ declare function makeHttpStream(cfg?: MakeHttpConfig): HttpClientStream;
32
41
  declare function makeHttp(cfg?: MakeHttpConfig): HttpClient;
33
42
  declare const mapAsync: <R, E, A, B>(fa: Async<R, E, A>, f: (a: A) => B) => Async<R, E, B>;
34
43
  declare const mapTryAsync: <R, E, A, B>(fa: Async<R, E, A>, f: (a: A) => B) => Async<R, E, B>;
35
44
 
36
- /**
37
- * “Contenido” (sin meta). Esto es lo que querés que sea el default.
38
- */
39
45
  type HttpResponse<A> = {
40
46
  status: number;
41
47
  headers: Record<string, string>;
42
48
  body: A;
43
49
  };
44
- /**
45
- * Meta (opcional / inyectable por middleware).
46
- */
47
50
  type HttpMeta = {
48
51
  statusText: string;
49
52
  ms: number;
50
53
  };
51
- /**
52
- * “Contenido + meta” (resultado de aplicar withMeta).
53
- */
54
54
  type HttpResponseWithMeta<A> = HttpResponse<A> & {
55
55
  meta: HttpMeta;
56
56
  };
57
- /**
58
- * Client “DX” base:
59
- * - expone wire (request/get/post/postJson)
60
- * - expone contenido (getText/getJson) SIN meta
61
- */
62
- type HttpClientDx = {
57
+ type HttpResponseStream = {
58
+ status: number;
59
+ headers: Record<string, string>;
60
+ body: ZStream<unknown, HttpError, Uint8Array>;
61
+ };
62
+ declare function httpClient(cfg?: MakeHttpConfig): {
63
63
  request: (req: HttpRequest) => Async<unknown, HttpError, HttpWireResponse>;
64
- get: (url: string, init?: Omit<RequestInit, "method">) => Async<unknown, HttpError, HttpWireResponse>;
65
- post: (url: string, body?: string, init?: Omit<RequestInit, "method" | "body">) => Async<unknown, HttpError, HttpWireResponse>;
66
- postJson: <A extends object>(url: string, body: A, init?: Omit<RequestInit, "method" | "body">) => Async<unknown, HttpError, HttpWireResponse>;
67
64
  getText: (url: string, init?: Omit<RequestInit, "method">) => Async<unknown, HttpError, HttpResponse<string>>;
68
65
  getJson: <A>(url: string, init?: Omit<RequestInit, "method">) => Async<unknown, HttpError, HttpResponse<A>>;
69
66
  };
70
- /**
71
- * Client “DX” con meta:
72
- * misma API, pero getText/getJson devuelven HttpResponseWithMeta.
73
- */
74
- type HttpClientDxWithMeta = Omit<HttpClientDx, "getText" | "getJson"> & {
67
+ declare function httpClientWithMeta(cfg?: MakeHttpConfig): {
68
+ request: (req: HttpRequest) => Async<unknown, HttpError, HttpWireResponse>;
75
69
  getText: (url: string, init?: Omit<RequestInit, "method">) => Async<unknown, HttpError, HttpResponseWithMeta<string>>;
76
70
  getJson: <A>(url: string, init?: Omit<RequestInit, "method">) => Async<unknown, HttpError, HttpResponseWithMeta<A>>;
77
71
  };
78
- /**
79
- * Builder base: por default NO mete meta.
80
- * Internamente crea makeHttp(cfg) y te expone una API usable.
81
- */
82
- declare function httpClient(cfg?: MakeHttpConfig): HttpClientDx;
83
- /**
84
- * Middleware “zio-like”: recibe un client base y devuelve uno “enriquecido”.
85
- * Nota: NO toca el wire; sólo cambia cómo “renderizás” contenido.
86
- */
87
- declare function withMeta(client: HttpClientDx): HttpClientDxWithMeta;
88
- /**
89
- * Convenience: “todo transparente”
90
- * - crea el client base
91
- * - le aplica withMeta
92
- */
93
- declare function httpClientWithMeta(cfg?: MakeHttpConfig): HttpClientDxWithMeta;
72
+ type HttpClientDxStream = {
73
+ request: (req: HttpRequest) => Async<unknown, HttpError, HttpResponseStream>;
74
+ get: (url: string, init?: Omit<RequestInit, "method">) => Async<unknown, HttpError, HttpResponseStream>;
75
+ post: (url: string, body?: string, init?: Omit<RequestInit, "method" | "body">) => Async<unknown, HttpError, HttpResponseStream>;
76
+ postJson: <A extends object>(url: string, body: A, init?: Omit<RequestInit, "method" | "body">) => Async<unknown, HttpError, HttpResponseStream>;
77
+ };
78
+ declare function httpClientStream(cfg?: MakeHttpConfig): HttpClientDxStream;
94
79
 
95
- export { type HttpClient, type HttpClientDx, type HttpClientDxWithMeta, type HttpError, type HttpMeta, type HttpMethod, type HttpRequest, type HttpResponse, type HttpResponseWithMeta, type HttpWireResponse, type MakeHttpConfig, httpClient, httpClientWithMeta, makeHttp, mapAsync, mapTryAsync, withMeta };
80
+ export { type HttpClient, type HttpClientDxStream, type HttpClientStream, type HttpError, 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 };
@@ -1,4 +1,4 @@
1
- import { A as Async } from '../effect-BTR2nIXd.js';
1
+ import { Q as ZStream, A as Async } from '../stream-wtsKMh6j.js';
2
2
 
3
3
  type HttpError = {
4
4
  _tag: "Abort";
@@ -28,68 +28,53 @@ type MakeHttpConfig = {
28
28
  baseUrl?: string;
29
29
  headers?: Record<string, string>;
30
30
  };
31
+ type HttpWireResponseStream = {
32
+ status: number;
33
+ statusText: string;
34
+ headers: Record<string, string>;
35
+ body: ZStream<unknown, HttpError, Uint8Array>;
36
+ ms: number;
37
+ };
38
+ type HttpClientStream = (req: HttpRequest) => Async<unknown, HttpError, HttpWireResponseStream>;
31
39
  type HttpClient = (req: HttpRequest) => Async<unknown, HttpError, HttpWireResponse>;
40
+ declare function makeHttpStream(cfg?: MakeHttpConfig): HttpClientStream;
32
41
  declare function makeHttp(cfg?: MakeHttpConfig): HttpClient;
33
42
  declare const mapAsync: <R, E, A, B>(fa: Async<R, E, A>, f: (a: A) => B) => Async<R, E, B>;
34
43
  declare const mapTryAsync: <R, E, A, B>(fa: Async<R, E, A>, f: (a: A) => B) => Async<R, E, B>;
35
44
 
36
- /**
37
- * “Contenido” (sin meta). Esto es lo que querés que sea el default.
38
- */
39
45
  type HttpResponse<A> = {
40
46
  status: number;
41
47
  headers: Record<string, string>;
42
48
  body: A;
43
49
  };
44
- /**
45
- * Meta (opcional / inyectable por middleware).
46
- */
47
50
  type HttpMeta = {
48
51
  statusText: string;
49
52
  ms: number;
50
53
  };
51
- /**
52
- * “Contenido + meta” (resultado de aplicar withMeta).
53
- */
54
54
  type HttpResponseWithMeta<A> = HttpResponse<A> & {
55
55
  meta: HttpMeta;
56
56
  };
57
- /**
58
- * Client “DX” base:
59
- * - expone wire (request/get/post/postJson)
60
- * - expone contenido (getText/getJson) SIN meta
61
- */
62
- type HttpClientDx = {
57
+ type HttpResponseStream = {
58
+ status: number;
59
+ headers: Record<string, string>;
60
+ body: ZStream<unknown, HttpError, Uint8Array>;
61
+ };
62
+ declare function httpClient(cfg?: MakeHttpConfig): {
63
63
  request: (req: HttpRequest) => Async<unknown, HttpError, HttpWireResponse>;
64
- get: (url: string, init?: Omit<RequestInit, "method">) => Async<unknown, HttpError, HttpWireResponse>;
65
- post: (url: string, body?: string, init?: Omit<RequestInit, "method" | "body">) => Async<unknown, HttpError, HttpWireResponse>;
66
- postJson: <A extends object>(url: string, body: A, init?: Omit<RequestInit, "method" | "body">) => Async<unknown, HttpError, HttpWireResponse>;
67
64
  getText: (url: string, init?: Omit<RequestInit, "method">) => Async<unknown, HttpError, HttpResponse<string>>;
68
65
  getJson: <A>(url: string, init?: Omit<RequestInit, "method">) => Async<unknown, HttpError, HttpResponse<A>>;
69
66
  };
70
- /**
71
- * Client “DX” con meta:
72
- * misma API, pero getText/getJson devuelven HttpResponseWithMeta.
73
- */
74
- type HttpClientDxWithMeta = Omit<HttpClientDx, "getText" | "getJson"> & {
67
+ declare function httpClientWithMeta(cfg?: MakeHttpConfig): {
68
+ request: (req: HttpRequest) => Async<unknown, HttpError, HttpWireResponse>;
75
69
  getText: (url: string, init?: Omit<RequestInit, "method">) => Async<unknown, HttpError, HttpResponseWithMeta<string>>;
76
70
  getJson: <A>(url: string, init?: Omit<RequestInit, "method">) => Async<unknown, HttpError, HttpResponseWithMeta<A>>;
77
71
  };
78
- /**
79
- * Builder base: por default NO mete meta.
80
- * Internamente crea makeHttp(cfg) y te expone una API usable.
81
- */
82
- declare function httpClient(cfg?: MakeHttpConfig): HttpClientDx;
83
- /**
84
- * Middleware “zio-like”: recibe un client base y devuelve uno “enriquecido”.
85
- * Nota: NO toca el wire; sólo cambia cómo “renderizás” contenido.
86
- */
87
- declare function withMeta(client: HttpClientDx): HttpClientDxWithMeta;
88
- /**
89
- * Convenience: “todo transparente”
90
- * - crea el client base
91
- * - le aplica withMeta
92
- */
93
- declare function httpClientWithMeta(cfg?: MakeHttpConfig): HttpClientDxWithMeta;
72
+ type HttpClientDxStream = {
73
+ request: (req: HttpRequest) => Async<unknown, HttpError, HttpResponseStream>;
74
+ get: (url: string, init?: Omit<RequestInit, "method">) => Async<unknown, HttpError, HttpResponseStream>;
75
+ post: (url: string, body?: string, init?: Omit<RequestInit, "method" | "body">) => Async<unknown, HttpError, HttpResponseStream>;
76
+ postJson: <A extends object>(url: string, body: A, init?: Omit<RequestInit, "method" | "body">) => Async<unknown, HttpError, HttpResponseStream>;
77
+ };
78
+ declare function httpClientStream(cfg?: MakeHttpConfig): HttpClientDxStream;
94
79
 
95
- export { type HttpClient, type HttpClientDx, type HttpClientDxWithMeta, type HttpError, type HttpMeta, type HttpMethod, type HttpRequest, type HttpResponse, type HttpResponseWithMeta, type HttpWireResponse, type MakeHttpConfig, httpClient, httpClientWithMeta, makeHttp, mapAsync, mapTryAsync, withMeta };
80
+ export { type HttpClient, type HttpClientDxStream, type HttpClientStream, type HttpError, 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 };
@@ -1 +1 @@
1
- 'use strict';var chunkBQ3I6L5Z_js=require('../chunk-BQ3I6L5Z.js');var x=t=>t instanceof DOMException&&t.name==="AbortError"?{_tag:"Abort"}:typeof t=="object"&&t&&"_tag"in t?t:{_tag:"FetchError",message:String(t)};function R(t={}){let o=t.baseUrl??"",r=t.headers??{};return e=>chunkBQ3I6L5Z_js.x(async i=>{let u;try{u=new URL(e.url,o);}catch{throw {_tag:"BadUrl",message:`URL inv\xE1lida: ${e.url}`}}let H=performance.now(),a=await fetch(u,{...e.init??{},method:e.method,headers:{...r,...e.headers??{}},body:e.body,signal:i}),n=await a.text(),s={};return a.headers.forEach((p,A)=>s[A]=p),{status:a.status,statusText:a.statusText,headers:s,bodyText:n,ms:Math.round(performance.now()-H)}},x)}var m=(t,o)=>chunkBQ3I6L5Z_js.k(t,r=>chunkBQ3I6L5Z_js.e(o(r))),g=(t,o)=>chunkBQ3I6L5Z_js.k(t,r=>chunkBQ3I6L5Z_js.g(()=>o(r)));var b=t=>({status:t.status,headers:t.headers,body:t.bodyText}),E=t=>({status:t.status,headers:t.headers,body:JSON.parse(t.bodyText)}),T=t=>({status:t.status,headers:t.headers,body:t.bodyText,meta:{statusText:t.statusText,ms:t.ms}}),l=t=>({status:t.status,headers:t.headers,body:JSON.parse(t.bodyText),meta:{statusText:t.statusText,ms:t.ms}});function f(t={}){let o=R(t),r=n=>o(n),e=(n,s)=>r({method:"GET",url:n,init:s});return {request:r,get:e,post:(n,s,p)=>r({method:"POST",url:n,body:s&&s.length>0?s:void 0,init:p}),postJson:(n,s,p)=>r({method:"POST",url:n,body:JSON.stringify(s),headers:{"content-type":"application/json",...p?.headers},init:{...p??{}}}),getText:(n,s)=>m(e(n,s),b),getJson:(n,s)=>g(e(n,s),E)}}function O(t){let o=(e,i)=>m(t.get(e,i),T),r=(e,i)=>g(t.get(e,i),l);return {request:t.request,get:t.get,post:t.post,postJson:t.postJson,getText:o,getJson:r}}function B(t={}){return O(f(t))}exports.httpClient=f;exports.httpClientWithMeta=B;exports.makeHttp=R;exports.mapAsync=m;exports.mapTryAsync=g;exports.withMeta=O;
1
+ 'use strict';var chunkLRGO34YG_js=require('../chunk-LRGO34YG.js');function b(t={}){let n=t.baseUrl??"",s=t.headers??{};return a=>chunkLRGO34YG_js.I(async i=>{let o=new URL(a.url,n),r=performance.now(),e=await fetch(o,{...a.init??{},method:a.method,headers:{...s,...a.headers??{}},body:a.body,signal:i}),p={};e.headers.forEach((u,c)=>p[c]=u);let d=chunkLRGO34YG_js.aa(e.body,h);return {status:e.status,statusText:e.statusText,headers:p,body:d,ms:Math.round(performance.now()-r)}},h)}var h=t=>t instanceof DOMException&&t.name==="AbortError"?{_tag:"Abort"}:typeof t=="object"&&t&&"_tag"in t?t:{_tag:"FetchError",message:String(t)};function g(t={}){let n=t.baseUrl??"",s=t.headers??{};return a=>chunkLRGO34YG_js.I(async i=>{let o;try{o=new URL(a.url,n);}catch{throw {_tag:"BadUrl",message:`URL inv\xE1lida: ${a.url}`}}let r=performance.now(),e=await fetch(o,{...a.init??{},method:a.method,headers:{...s,...a.headers??{}},body:a.body,signal:i}),p=await e.text(),d={};return e.headers.forEach((u,c)=>d[c]=u),{status:e.status,statusText:e.statusText,headers:d,bodyText:p,ms:Math.round(performance.now()-r)}},h)}var q=(t,n)=>chunkLRGO34YG_js.k(t,s=>chunkLRGO34YG_js.e(n(s))),m=(t,n)=>chunkLRGO34YG_js.k(t,s=>chunkLRGO34YG_js.g(()=>n(s)));var l=(t,n)=>({status:t.status,headers:t.headers,body:n}),f=(t,n)=>({status:t.status,headers:t.headers,body:n,meta:{statusText:t.statusText,ms:t.ms}});function L(t={}){let n=g(t),s=o=>n(o);return {request:s,getText:(o,r)=>m(s({method:"GET",url:o,init:r}),e=>l(e,e.bodyText)),getJson:(o,r)=>m(s({method:"GET",url:o,init:r}),e=>l(e,JSON.parse(e.bodyText)))}}function Z(t={}){let n=g(t),s=o=>n(o);return {request:s,getText:(o,r)=>m(s({method:"GET",url:o,init:r}),e=>f(e,e.bodyText)),getJson:(o,r)=>m(s({method:"GET",url:o,init:r}),e=>f(e,JSON.parse(e.bodyText)))}}var E=t=>({status:t.status,headers:t.headers,body:t.body});function j(t={}){let n=b(t),s=r=>m(n(r),E);return {request:s,get:(r,e)=>s({method:"GET",url:r,init:e}),post:(r,e,p)=>s({method:"POST",url:r,body:e&&e.length>0?e:void 0,init:p}),postJson:(r,e,p)=>s({method:"POST",url:r,body:JSON.stringify(e),headers:{"content-type":"application/json",...p?.headers},init:{...p??{}}})}}exports.httpClient=L;exports.httpClientStream=j;exports.httpClientWithMeta=Z;exports.makeHttp=g;exports.makeHttpStream=b;exports.mapAsync=q;exports.mapTryAsync=m;
@@ -1 +1 @@
1
- import {k,x as x$1,e,g as g$1}from'../chunk-SMCQ6GGV.mjs';var x=t=>t instanceof DOMException&&t.name==="AbortError"?{_tag:"Abort"}:typeof t=="object"&&t&&"_tag"in t?t:{_tag:"FetchError",message:String(t)};function R(t={}){let o=t.baseUrl??"",r=t.headers??{};return e=>x$1(async i=>{let u;try{u=new URL(e.url,o);}catch{throw {_tag:"BadUrl",message:`URL inv\xE1lida: ${e.url}`}}let H=performance.now(),a=await fetch(u,{...e.init??{},method:e.method,headers:{...r,...e.headers??{}},body:e.body,signal:i}),n=await a.text(),s={};return a.headers.forEach((p,A)=>s[A]=p),{status:a.status,statusText:a.statusText,headers:s,bodyText:n,ms:Math.round(performance.now()-H)}},x)}var m=(t,o)=>k(t,r=>e(o(r))),g=(t,o)=>k(t,r=>g$1(()=>o(r)));var b=t=>({status:t.status,headers:t.headers,body:t.bodyText}),E=t=>({status:t.status,headers:t.headers,body:JSON.parse(t.bodyText)}),T=t=>({status:t.status,headers:t.headers,body:t.bodyText,meta:{statusText:t.statusText,ms:t.ms}}),l=t=>({status:t.status,headers:t.headers,body:JSON.parse(t.bodyText),meta:{statusText:t.statusText,ms:t.ms}});function f(t={}){let o=R(t),r=n=>o(n),e=(n,s)=>r({method:"GET",url:n,init:s});return {request:r,get:e,post:(n,s,p)=>r({method:"POST",url:n,body:s&&s.length>0?s:void 0,init:p}),postJson:(n,s,p)=>r({method:"POST",url:n,body:JSON.stringify(s),headers:{"content-type":"application/json",...p?.headers},init:{...p??{}}}),getText:(n,s)=>m(e(n,s),b),getJson:(n,s)=>g(e(n,s),E)}}function O(t){let o=(e,i)=>m(t.get(e,i),T),r=(e,i)=>g(t.get(e,i),l);return {request:t.request,get:t.get,post:t.post,postJson:t.postJson,getText:o,getJson:r}}function B(t={}){return O(f(t))}export{f as httpClient,B as httpClientWithMeta,R as makeHttp,m as mapAsync,g as mapTryAsync,O as withMeta};
1
+ import {k,I,aa,e,g as g$1}from'../chunk-7M74PYBY.mjs';function b(t={}){let n=t.baseUrl??"",s=t.headers??{};return a=>I(async i=>{let o=new URL(a.url,n),r=performance.now(),e=await fetch(o,{...a.init??{},method:a.method,headers:{...s,...a.headers??{}},body:a.body,signal:i}),p={};e.headers.forEach((u,c)=>p[c]=u);let d=aa(e.body,h);return {status:e.status,statusText:e.statusText,headers:p,body:d,ms:Math.round(performance.now()-r)}},h)}var h=t=>t instanceof DOMException&&t.name==="AbortError"?{_tag:"Abort"}:typeof t=="object"&&t&&"_tag"in t?t:{_tag:"FetchError",message:String(t)};function g(t={}){let n=t.baseUrl??"",s=t.headers??{};return a=>I(async i=>{let o;try{o=new URL(a.url,n);}catch{throw {_tag:"BadUrl",message:`URL inv\xE1lida: ${a.url}`}}let r=performance.now(),e=await fetch(o,{...a.init??{},method:a.method,headers:{...s,...a.headers??{}},body:a.body,signal:i}),p=await e.text(),d={};return e.headers.forEach((u,c)=>d[c]=u),{status:e.status,statusText:e.statusText,headers:d,bodyText:p,ms:Math.round(performance.now()-r)}},h)}var q=(t,n)=>k(t,s=>e(n(s))),m=(t,n)=>k(t,s=>g$1(()=>n(s)));var l=(t,n)=>({status:t.status,headers:t.headers,body:n}),f=(t,n)=>({status:t.status,headers:t.headers,body:n,meta:{statusText:t.statusText,ms:t.ms}});function L(t={}){let n=g(t),s=o=>n(o);return {request:s,getText:(o,r)=>m(s({method:"GET",url:o,init:r}),e=>l(e,e.bodyText)),getJson:(o,r)=>m(s({method:"GET",url:o,init:r}),e=>l(e,JSON.parse(e.bodyText)))}}function Z(t={}){let n=g(t),s=o=>n(o);return {request:s,getText:(o,r)=>m(s({method:"GET",url:o,init:r}),e=>f(e,e.bodyText)),getJson:(o,r)=>m(s({method:"GET",url:o,init:r}),e=>f(e,JSON.parse(e.bodyText)))}}var E=t=>({status:t.status,headers:t.headers,body:t.body});function j(t={}){let n=b(t),s=r=>m(n(r),E);return {request:s,get:(r,e)=>s({method:"GET",url:r,init:e}),post:(r,e,p)=>s({method:"POST",url:r,body:e&&e.length>0?e:void 0,init:p}),postJson:(r,e,p)=>s({method:"POST",url:r,body:JSON.stringify(e),headers:{"content-type":"application/json",...p?.headers},init:{...p??{}}})}}export{L as httpClient,j as httpClientStream,Z as httpClientWithMeta,g as makeHttp,b as makeHttpStream,q as mapAsync,m as mapTryAsync};
package/dist/index.d.mts CHANGED
@@ -1,57 +1,5 @@
1
- import { Z as ZIO, O as Option, E as Exit, A as Async, S as Scheduler, F as Fiber, I as Interrupted } from './effect-BTR2nIXd.mjs';
2
- export { z as CancelToken, C as Canceler, G as FiberId, H as FiberStatus, N as None, R as RuntimeFiber, K as Scope, J as ScopeId, w as Some, T as Task, t as acquireRelease, p as async, h as asyncCatchAll, k as asyncFail, r as asyncFlatMap, g as asyncFold, v as asyncInterruptible, q as asyncMap, i as asyncMapError, j as asyncSucceed, l as asyncSync, n as asyncTotal, d as catchAll, e as end, f as fail, b as flatMap, M as globalScheduler, D as linkAbortController, B as makeCancelToken, m as map, c as mapError, x as none, o as orElseOptional, y as some, s as succeed, a as sync, u as unit, L as withScope } from './effect-BTR2nIXd.mjs';
3
-
4
- type Empty<R, E, A> = {
5
- readonly _tag: "Empty";
6
- };
7
- type Emit<R, E, A> = {
8
- readonly _tag: "Emit";
9
- readonly value: ZIO<R, E, A>;
10
- };
11
- type Concat<R, E, A> = {
12
- readonly _tag: "Concat";
13
- readonly left: ZStream<R, E, A>;
14
- readonly right: ZStream<R, E, A>;
15
- };
16
- type Flatten<R, E, A> = {
17
- readonly _tag: "Flatten";
18
- readonly stream: ZStream<R, E, ZStream<R, E, A>>;
19
- };
20
- type FromPull<R, E, A> = {
21
- readonly _tag: "FromPull";
22
- readonly pull: ZIO<R, Option<E>, [A, ZStream<R, E, A>]>;
23
- };
24
- type Merge<R, E, A> = {
25
- readonly _tag: "Merge";
26
- readonly left: ZStream<R, E, A>;
27
- readonly right: ZStream<R, E, A>;
28
- readonly flip: boolean;
29
- };
30
- type Scoped<R, E, A> = {
31
- readonly _tag: "Scoped";
32
- readonly acquire: ZIO<R, E, ZStream<R, E, A>>;
33
- readonly release: (exit: Exit<any, any>) => Async<R, any, void>;
34
- };
35
- type ZStream<R, E, A> = Empty<R, E, A> | Emit<R, E, A> | Concat<R, E, A> | FromPull<R, E, A> | Flatten<R, E, A> | Merge<R, E, A> | Scoped<R, E, A>;
36
- declare const fromPull: <R, E, A>(pull: ZIO<R, Option<E>, [A, ZStream<R, E, A>]>) => ZStream<R, E, A>;
37
- declare const unwrapScoped: <R, E, A>(acquire: ZIO<R, E, ZStream<R, E, A>>, release: (exit: Exit<any, any>) => Async<R, any, void>) => ZStream<R, E, A>;
38
- declare const managedStream: <R, E, A>(acquire: Async<R, E, {
39
- stream: ZStream<R, E, A>;
40
- release: (exit: Exit<any, any>) => Async<R, any, void>;
41
- }>) => ZStream<R, E, A>;
42
- declare const mergeStream: <R, E, A>(left: ZStream<R, E, A>, right: ZStream<R, E, A>, flip?: boolean) => ZStream<R, E, A>;
43
- declare const emptyStream: <R, E, A>() => ZStream<R, E, A>;
44
- declare const emitStream: <R, E, A>(value: ZIO<R, E, A>) => ZStream<R, E, A>;
45
- declare const concatStream: <R, E, A>(left: ZStream<R, E, A>, right: ZStream<R, E, A>) => ZStream<R, E, A>;
46
- declare const flattenStream: <R, E, A>(stream: ZStream<R, E, ZStream<R, E, A>>) => ZStream<R, E, A>;
47
- declare function merge<R, E, A>(left: ZStream<R, E, A>, right: ZStream<R, E, A>): ZStream<R, E, A>;
48
- declare function uncons<R, E, A>(self: ZStream<R, E, A>): ZIO<R, Option<E>, [A, ZStream<R, E, A>]>;
49
- declare function mapStream<R, E, A, B>(self: ZStream<R, E, A>, f: (a: A) => B): ZStream<R, E, B>;
50
- declare function rangeStream(start: number, end: number): ZStream<unknown, never, number>;
51
- declare function zip<R, E1, A, E2, B>(left: ZStream<R, E1, A>, right: ZStream<R, E2, B>): ZStream<R, E1 | E2, [A, B]>;
52
- declare function foreachStream<R, E, A, R2, E2>(stream: ZStream<R, E, A>, f: (a: A) => Async<R2, E2, void>): Async<R & R2, E | E2, void>;
53
- declare function fromArray<A>(values: readonly A[]): ZStream<unknown, never, A>;
54
- declare function collectStream<R, E, A>(stream: ZStream<R, E, A>): ZIO<R, E, A[]>;
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';
55
3
 
56
4
  type NodeCallback<A> = (err: Error | null, result: A) => void;
57
5
  declare function from<A>(f: (cb: NodeCallback<A>) => void): Async<{}, Error, A>;
@@ -72,4 +20,4 @@ declare function tryPromiseAbortable<R, A>(thunk: (env: R, signal: AbortSignal)
72
20
  declare function fromPromiseAbortable<E, A>(thunk: (signal: AbortSignal) => Promise<A>, onError: (e: unknown) => E): Async<unknown, E, A>;
73
21
  declare function fromPromiseAbortable<R, E, A>(thunk: (env: R, signal: AbortSignal) => Promise<A>, onError: (e: unknown) => E): Async<R, E, A>;
74
22
 
75
- export { Async, type BrassError, type Concat, type Emit, type Empty, Exit, Fiber, type Flatten, type FromPull, Interrupted, type Merge, Option, Scheduler, type Scoped, ZIO, type ZStream, collectStream, concatStream, emitStream, emptyStream, flattenStream, foreachStream, fork, from, fromArray, fromCallback, fromPromise, fromPromiseAbortable, fromPull, managedStream, mapStream, merge, mergeStream, rangeStream, toPromise, tryPromiseAbortable, uncons, unsafeRunAsync, unwrapScoped, zip };
23
+ export { Async, type BrassError, Exit, Fiber, Interrupted, Scheduler, fork, from, fromCallback, fromPromise, fromPromiseAbortable, toPromise, tryPromiseAbortable, unsafeRunAsync };
package/dist/index.d.ts CHANGED
@@ -1,57 +1,5 @@
1
- import { Z as ZIO, O as Option, E as Exit, A as Async, S as Scheduler, F as Fiber, I as Interrupted } from './effect-BTR2nIXd.js';
2
- export { z as CancelToken, C as Canceler, G as FiberId, H as FiberStatus, N as None, R as RuntimeFiber, K as Scope, J as ScopeId, w as Some, T as Task, t as acquireRelease, p as async, h as asyncCatchAll, k as asyncFail, r as asyncFlatMap, g as asyncFold, v as asyncInterruptible, q as asyncMap, i as asyncMapError, j as asyncSucceed, l as asyncSync, n as asyncTotal, d as catchAll, e as end, f as fail, b as flatMap, M as globalScheduler, D as linkAbortController, B as makeCancelToken, m as map, c as mapError, x as none, o as orElseOptional, y as some, s as succeed, a as sync, u as unit, L as withScope } from './effect-BTR2nIXd.js';
3
-
4
- type Empty<R, E, A> = {
5
- readonly _tag: "Empty";
6
- };
7
- type Emit<R, E, A> = {
8
- readonly _tag: "Emit";
9
- readonly value: ZIO<R, E, A>;
10
- };
11
- type Concat<R, E, A> = {
12
- readonly _tag: "Concat";
13
- readonly left: ZStream<R, E, A>;
14
- readonly right: ZStream<R, E, A>;
15
- };
16
- type Flatten<R, E, A> = {
17
- readonly _tag: "Flatten";
18
- readonly stream: ZStream<R, E, ZStream<R, E, A>>;
19
- };
20
- type FromPull<R, E, A> = {
21
- readonly _tag: "FromPull";
22
- readonly pull: ZIO<R, Option<E>, [A, ZStream<R, E, A>]>;
23
- };
24
- type Merge<R, E, A> = {
25
- readonly _tag: "Merge";
26
- readonly left: ZStream<R, E, A>;
27
- readonly right: ZStream<R, E, A>;
28
- readonly flip: boolean;
29
- };
30
- type Scoped<R, E, A> = {
31
- readonly _tag: "Scoped";
32
- readonly acquire: ZIO<R, E, ZStream<R, E, A>>;
33
- readonly release: (exit: Exit<any, any>) => Async<R, any, void>;
34
- };
35
- type ZStream<R, E, A> = Empty<R, E, A> | Emit<R, E, A> | Concat<R, E, A> | FromPull<R, E, A> | Flatten<R, E, A> | Merge<R, E, A> | Scoped<R, E, A>;
36
- declare const fromPull: <R, E, A>(pull: ZIO<R, Option<E>, [A, ZStream<R, E, A>]>) => ZStream<R, E, A>;
37
- declare const unwrapScoped: <R, E, A>(acquire: ZIO<R, E, ZStream<R, E, A>>, release: (exit: Exit<any, any>) => Async<R, any, void>) => ZStream<R, E, A>;
38
- declare const managedStream: <R, E, A>(acquire: Async<R, E, {
39
- stream: ZStream<R, E, A>;
40
- release: (exit: Exit<any, any>) => Async<R, any, void>;
41
- }>) => ZStream<R, E, A>;
42
- declare const mergeStream: <R, E, A>(left: ZStream<R, E, A>, right: ZStream<R, E, A>, flip?: boolean) => ZStream<R, E, A>;
43
- declare const emptyStream: <R, E, A>() => ZStream<R, E, A>;
44
- declare const emitStream: <R, E, A>(value: ZIO<R, E, A>) => ZStream<R, E, A>;
45
- declare const concatStream: <R, E, A>(left: ZStream<R, E, A>, right: ZStream<R, E, A>) => ZStream<R, E, A>;
46
- declare const flattenStream: <R, E, A>(stream: ZStream<R, E, ZStream<R, E, A>>) => ZStream<R, E, A>;
47
- declare function merge<R, E, A>(left: ZStream<R, E, A>, right: ZStream<R, E, A>): ZStream<R, E, A>;
48
- declare function uncons<R, E, A>(self: ZStream<R, E, A>): ZIO<R, Option<E>, [A, ZStream<R, E, A>]>;
49
- declare function mapStream<R, E, A, B>(self: ZStream<R, E, A>, f: (a: A) => B): ZStream<R, E, B>;
50
- declare function rangeStream(start: number, end: number): ZStream<unknown, never, number>;
51
- declare function zip<R, E1, A, E2, B>(left: ZStream<R, E1, A>, right: ZStream<R, E2, B>): ZStream<R, E1 | E2, [A, B]>;
52
- declare function foreachStream<R, E, A, R2, E2>(stream: ZStream<R, E, A>, f: (a: A) => Async<R2, E2, void>): Async<R & R2, E | E2, void>;
53
- declare function fromArray<A>(values: readonly A[]): ZStream<unknown, never, A>;
54
- declare function collectStream<R, E, A>(stream: ZStream<R, E, A>): ZIO<R, E, A[]>;
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';
55
3
 
56
4
  type NodeCallback<A> = (err: Error | null, result: A) => void;
57
5
  declare function from<A>(f: (cb: NodeCallback<A>) => void): Async<{}, Error, A>;
@@ -72,4 +20,4 @@ declare function tryPromiseAbortable<R, A>(thunk: (env: R, signal: AbortSignal)
72
20
  declare function fromPromiseAbortable<E, A>(thunk: (signal: AbortSignal) => Promise<A>, onError: (e: unknown) => E): Async<unknown, E, A>;
73
21
  declare function fromPromiseAbortable<R, E, A>(thunk: (env: R, signal: AbortSignal) => Promise<A>, onError: (e: unknown) => E): Async<R, E, A>;
74
22
 
75
- export { Async, type BrassError, type Concat, type Emit, type Empty, Exit, Fiber, type Flatten, type FromPull, Interrupted, type Merge, Option, Scheduler, type Scoped, ZIO, type ZStream, collectStream, concatStream, emitStream, emptyStream, flattenStream, foreachStream, fork, from, fromArray, fromCallback, fromPromise, fromPromiseAbortable, fromPull, managedStream, mapStream, merge, mergeStream, rangeStream, toPromise, tryPromiseAbortable, uncons, unsafeRunAsync, unwrapScoped, zip };
23
+ export { Async, type BrassError, Exit, Fiber, Interrupted, Scheduler, fork, from, fromCallback, fromPromise, fromPromiseAbortable, toPromise, tryPromiseAbortable, unsafeRunAsync };
package/dist/index.js CHANGED
@@ -1 +1 @@
1
- 'use strict';var chunkBQ3I6L5Z_js=require('./chunk-BQ3I6L5Z.js');var Z={_tag:"None"},I=e=>({_tag:"Some",value:e});var k=e=>chunkBQ3I6L5Z_js.e(e),b=e=>chunkBQ3I6L5Z_js.f(e),pe=e=>chunkBQ3I6L5Z_js.g(t=>e(t)),g=(e,t)=>chunkBQ3I6L5Z_js.j(e,t),L=(e,t)=>chunkBQ3I6L5Z_js.k(e,r=>t(r)),C=(e,t)=>chunkBQ3I6L5Z_js.c(e,t),ue=(e,t)=>chunkBQ3I6L5Z_js.a(e,r=>t(r),r=>chunkBQ3I6L5Z_js.e(r));function j(e,t){return chunkBQ3I6L5Z_js.a(e,r=>r._tag==="Some"?chunkBQ3I6L5Z_js.f(r):t(),r=>chunkBQ3I6L5Z_js.e(r))}var Ae=()=>b(Z);function ye(){let e=false,t=new Set;return {isCancelled:()=>e,onCancel:n=>{if(e){try{n();}catch{}return ()=>{}}return t.add(n),()=>{t.delete(n);}},cancel:()=>{e||(e=true,t.forEach(n=>n()),t.clear());}}}function me(e,t){return e.onCancel(()=>t.abort())}var D=1;function G(e){return chunkBQ3I6L5Z_js.i((t,r)=>{let n=e.length;if(n===0){r({_tag:"Success",value:void 0});return}for(let o of e)o.join(()=>{n-=1,n===0&&r({_tag:"Success",value:void 0});});})}function J(e){return chunkBQ3I6L5Z_js.a(e,()=>chunkBQ3I6L5Z_js.d,()=>chunkBQ3I6L5Z_js.d)}var x=class e{constructor(t){this.env=t;this.id=D++;}id;closed=false;children=new Set;subScopes=new Set;finalizers=[];addFinalizer(t){if(this.closed)throw new Error("Trying to add finalizer to closed scope");this.finalizers.push(t);}subScope(){if(this.closed)throw new Error("Scope closed");let t=new e(this.env);return this.subScopes.add(t),t}fork(t,r){if(this.closed)throw new Error("Scope closed");let n=chunkBQ3I6L5Z_js.r(t,r);return this.children.add(n),n.join(()=>{this.children.delete(n);}),n}close(t={_tag:"Success",value:void 0}){chunkBQ3I6L5Z_js.r(this.closeAsync(t),this.env);}closeAsync(t={_tag:"Success",value:void 0},r={}){return chunkBQ3I6L5Z_js.i((n,o)=>{if(this.closed){o({_tag:"Success",value:void 0});return}this.closed=true;let a=Array.from(this.children),i=Array.from(this.subScopes);this.children.clear(),this.subScopes.clear();for(let l of a)try{l.interrupt();}catch{}let c=chunkBQ3I6L5Z_js.d();for(let l of i)c=chunkBQ3I6L5Z_js.k(c,()=>l.closeAsync(t,r));for(;this.finalizers.length>0;){let l=this.finalizers.pop();c=chunkBQ3I6L5Z_js.k(c,()=>J(l(t)));}r.awaitChildren&&(c=chunkBQ3I6L5Z_js.k(c,()=>G(a))),chunkBQ3I6L5Z_js.r(c,this.env).join(()=>o({_tag:"Success",value:void 0}));})}};function ge(e){let t=new x({});try{return e(t)}finally{t.close();}}function W(e,t,r,n,o){return chunkBQ3I6L5Z_js.i((a,i)=>{let c=r.subScope(),E=false,l=c.fork(e,a),S=c.fork(t,a),d=y=>{c.fork(y,a).join(O=>{c.close(O),i(O);});};l.join(y=>{E||(E=true,d(n(y,S,c)));}),S.join(y=>{E||(E=true,d(o(y,l,c)));});})}var M=e=>e._tag==="None"?Z:I(e.value),h=e=>({_tag:"FromPull",pull:e}),Pe=(e,t)=>({_tag:"Scoped",acquire:e,release:t}),ze=e=>({_tag:"Scoped",acquire:chunkBQ3I6L5Z_js.k(e,t=>chunkBQ3I6L5Z_js.e(t.stream)),release:t=>chunkBQ3I6L5Z_js.k(e,r=>r.release(t))}),Ne=(e,t,r=true)=>({_tag:"Merge",left:e,right:t,flip:r}),z=()=>({_tag:"Empty"}),q=e=>({_tag:"Emit",value:e}),w=(e,t)=>({_tag:"Concat",left:e,right:t}),P=e=>({_tag:"Flatten",stream:e});function H(e,t,r,n,o){return (a,i,c)=>{if(a._tag,a._tag,a._tag==="Success"){let[S,d]=a.value;i.interrupt();let y=h(e==="L"?B(d,r):B(t,d));return chunkBQ3I6L5Z_js.e([S,y])}let E=a.error;if(typeof E=="object"&&E!==null&&E._tag==="Interrupted")return chunkBQ3I6L5Z_js.f(E);let l=E;return l._tag==="None"?s(e==="L"?r:t):chunkBQ3I6L5Z_js.f(l)}}function B(e,t,r,n){return chunkBQ3I6L5Z_js.i((o,a)=>{let c=new x(o),E=s(e),l=s(t),S=H("L",e,t),d=H("R",e,t),y=W(E,l,c,S,d);c.fork(y,o).join(O=>{c.close(O),a(O);});})}function Te(e,t){return h(B(e,t))}function s(e){switch(e._tag){case "Empty":return b(Z);case "Emit":return g(C(e.value,t=>I(t)),t=>[t,z()]);case "FromPull":return e.pull;case "Concat":return j(g(s(e.left),([t,r])=>[t,w(r,e.right)]),()=>s(e.right));case "Flatten":return L(s(e.stream),([t,r])=>j(g(s(t),([n,o])=>[n,w(o,P(r))]),()=>s(P(r))));case "Merge":return B(e.left,e.right,e.flip);case "Scoped":return chunkBQ3I6L5Z_js.i((t,r)=>{let n=new x(t);n.addFinalizer(o=>e.release(o)),n.fork(e.acquire,t).join(o=>{if(o._tag==="Failure"){n.close(o),r({_tag:"Failure",error:I(o.error)});return}let a=o.value;s(a)(t,c=>{n.close(c),r(c);});});})}}function v(e,t){switch(e._tag){case "Empty":return z();case "Emit":return q(g(e.value,t));case "FromPull":return h(g(e.pull,([r,n])=>[t(r),v(n,t)]));case "Concat":return w(v(e.left,t),v(e.right,t));case "Flatten":{let r=v(e.stream,n=>v(n,t));return P(r)}}}function Le(e,t){let r=n=>h(n>t?chunkBQ3I6L5Z_js.f(Z):chunkBQ3I6L5Z_js.e([n,r(n+1)]));return r(e)}function K(e,t){let r=chunkBQ3I6L5Z_js.a(chunkBQ3I6L5Z_js.c(s(e),n=>M(n)),n=>chunkBQ3I6L5Z_js.f(n),([n,o])=>chunkBQ3I6L5Z_js.a(chunkBQ3I6L5Z_js.c(s(t),a=>M(a)),a=>chunkBQ3I6L5Z_js.f(a),([a,i])=>chunkBQ3I6L5Z_js.e([[n,a],K(o,i)])));return h(r)}function We(e,t){let r=n=>chunkBQ3I6L5Z_js.a(chunkBQ3I6L5Z_js.c(s(n),o=>M(o)),o=>o._tag==="None"?chunkBQ3I6L5Z_js.e(void 0):chunkBQ3I6L5Z_js.f(o),([o,a])=>chunkBQ3I6L5Z_js.k(chunkBQ3I6L5Z_js.c(t(o),i=>I(i)),()=>r(a)));return chunkBQ3I6L5Z_js.a(r(e),n=>n._tag==="None"?chunkBQ3I6L5Z_js.e(void 0):chunkBQ3I6L5Z_js.f(n.value),()=>chunkBQ3I6L5Z_js.e(void 0))}function He(e){let t=z();for(let r=e.length-1;r>=0;r--){let n=q(k(e[r]));t=w(n,t);}return t}function qe(e){let t=(r,n)=>chunkBQ3I6L5Z_js.a(s(r),o=>o._tag==="None"?k(n):b(o),([o,a])=>t(a,[...n,o]));return C(t(e,[]),r=>{if(r._tag==="Some")return r.value;throw new Error("unreachable: stream end handled as success")})}Object.defineProperty(exports,"RuntimeFiber",{enumerable:true,get:function(){return chunkBQ3I6L5Z_js.p}});Object.defineProperty(exports,"Scheduler",{enumerable:true,get:function(){return chunkBQ3I6L5Z_js.n}});Object.defineProperty(exports,"acquireRelease",{enumerable:true,get:function(){return chunkBQ3I6L5Z_js.l}});Object.defineProperty(exports,"async",{enumerable:true,get:function(){return chunkBQ3I6L5Z_js.i}});Object.defineProperty(exports,"asyncCatchAll",{enumerable:true,get:function(){return chunkBQ3I6L5Z_js.b}});Object.defineProperty(exports,"asyncFail",{enumerable:true,get:function(){return chunkBQ3I6L5Z_js.f}});Object.defineProperty(exports,"asyncFlatMap",{enumerable:true,get:function(){return chunkBQ3I6L5Z_js.k}});Object.defineProperty(exports,"asyncFold",{enumerable:true,get:function(){return chunkBQ3I6L5Z_js.a}});Object.defineProperty(exports,"asyncInterruptible",{enumerable:true,get:function(){return chunkBQ3I6L5Z_js.m}});Object.defineProperty(exports,"asyncMap",{enumerable:true,get:function(){return chunkBQ3I6L5Z_js.j}});Object.defineProperty(exports,"asyncMapError",{enumerable:true,get:function(){return chunkBQ3I6L5Z_js.c}});Object.defineProperty(exports,"asyncSucceed",{enumerable:true,get:function(){return chunkBQ3I6L5Z_js.e}});Object.defineProperty(exports,"asyncSync",{enumerable:true,get:function(){return chunkBQ3I6L5Z_js.g}});Object.defineProperty(exports,"asyncTotal",{enumerable:true,get:function(){return chunkBQ3I6L5Z_js.h}});Object.defineProperty(exports,"fork",{enumerable:true,get:function(){return chunkBQ3I6L5Z_js.r}});Object.defineProperty(exports,"from",{enumerable:true,get:function(){return chunkBQ3I6L5Z_js.q}});Object.defineProperty(exports,"fromCallback",{enumerable:true,get:function(){return chunkBQ3I6L5Z_js.v}});Object.defineProperty(exports,"fromPromise",{enumerable:true,get:function(){return chunkBQ3I6L5Z_js.u}});Object.defineProperty(exports,"fromPromiseAbortable",{enumerable:true,get:function(){return chunkBQ3I6L5Z_js.x}});Object.defineProperty(exports,"globalScheduler",{enumerable:true,get:function(){return chunkBQ3I6L5Z_js.o}});Object.defineProperty(exports,"toPromise",{enumerable:true,get:function(){return chunkBQ3I6L5Z_js.t}});Object.defineProperty(exports,"tryPromiseAbortable",{enumerable:true,get:function(){return chunkBQ3I6L5Z_js.w}});Object.defineProperty(exports,"unit",{enumerable:true,get:function(){return chunkBQ3I6L5Z_js.d}});Object.defineProperty(exports,"unsafeRunAsync",{enumerable:true,get:function(){return chunkBQ3I6L5Z_js.s}});exports.Scope=x;exports.catchAll=ue;exports.collectStream=qe;exports.concatStream=w;exports.emitStream=q;exports.emptyStream=z;exports.end=Ae;exports.fail=b;exports.flatMap=L;exports.flattenStream=P;exports.foreachStream=We;exports.fromArray=He;exports.fromPull=h;exports.linkAbortController=me;exports.makeCancelToken=ye;exports.managedStream=ze;exports.map=g;exports.mapError=C;exports.mapStream=v;exports.merge=Te;exports.mergeStream=Ne;exports.none=Z;exports.orElseOptional=j;exports.rangeStream=Le;exports.some=I;exports.succeed=k;exports.sync=pe;exports.uncons=s;exports.unwrapScoped=Pe;exports.withScope=ge;exports.zip=K;
1
+ 'use strict';var chunkLRGO34YG_js=require('./chunk-LRGO34YG.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 chunkLRGO34YG_js.A}});Object.defineProperty(exports,"Scheduler",{enumerable:true,get:function(){return chunkLRGO34YG_js.y}});Object.defineProperty(exports,"Scope",{enumerable:true,get:function(){return chunkLRGO34YG_js.J}});Object.defineProperty(exports,"acquireRelease",{enumerable:true,get:function(){return chunkLRGO34YG_js.l}});Object.defineProperty(exports,"async",{enumerable:true,get:function(){return chunkLRGO34YG_js.i}});Object.defineProperty(exports,"asyncCatchAll",{enumerable:true,get:function(){return chunkLRGO34YG_js.b}});Object.defineProperty(exports,"asyncFail",{enumerable:true,get:function(){return chunkLRGO34YG_js.f}});Object.defineProperty(exports,"asyncFlatMap",{enumerable:true,get:function(){return chunkLRGO34YG_js.k}});Object.defineProperty(exports,"asyncFold",{enumerable:true,get:function(){return chunkLRGO34YG_js.a}});Object.defineProperty(exports,"asyncInterruptible",{enumerable:true,get:function(){return chunkLRGO34YG_js.m}});Object.defineProperty(exports,"asyncMap",{enumerable:true,get:function(){return chunkLRGO34YG_js.j}});Object.defineProperty(exports,"asyncMapError",{enumerable:true,get:function(){return chunkLRGO34YG_js.c}});Object.defineProperty(exports,"asyncSucceed",{enumerable:true,get:function(){return chunkLRGO34YG_js.e}});Object.defineProperty(exports,"asyncSync",{enumerable:true,get:function(){return chunkLRGO34YG_js.g}});Object.defineProperty(exports,"asyncTotal",{enumerable:true,get:function(){return chunkLRGO34YG_js.h}});Object.defineProperty(exports,"catchAll",{enumerable:true,get:function(){return chunkLRGO34YG_js.v}});Object.defineProperty(exports,"collectStream",{enumerable:true,get:function(){return chunkLRGO34YG_js.$}});Object.defineProperty(exports,"concatStream",{enumerable:true,get:function(){return chunkLRGO34YG_js.S}});Object.defineProperty(exports,"emitStream",{enumerable:true,get:function(){return chunkLRGO34YG_js.R}});Object.defineProperty(exports,"emptyStream",{enumerable:true,get:function(){return chunkLRGO34YG_js.Q}});Object.defineProperty(exports,"end",{enumerable:true,get:function(){return chunkLRGO34YG_js.x}});Object.defineProperty(exports,"fail",{enumerable:true,get:function(){return chunkLRGO34YG_js.q}});Object.defineProperty(exports,"flatMap",{enumerable:true,get:function(){return chunkLRGO34YG_js.t}});Object.defineProperty(exports,"flattenStream",{enumerable:true,get:function(){return chunkLRGO34YG_js.T}});Object.defineProperty(exports,"foreachStream",{enumerable:true,get:function(){return chunkLRGO34YG_js.Z}});Object.defineProperty(exports,"fork",{enumerable:true,get:function(){return chunkLRGO34YG_js.C}});Object.defineProperty(exports,"from",{enumerable:true,get:function(){return chunkLRGO34YG_js.B}});Object.defineProperty(exports,"fromArray",{enumerable:true,get:function(){return chunkLRGO34YG_js._}});Object.defineProperty(exports,"fromCallback",{enumerable:true,get:function(){return chunkLRGO34YG_js.G}});Object.defineProperty(exports,"fromPromise",{enumerable:true,get:function(){return chunkLRGO34YG_js.F}});Object.defineProperty(exports,"fromPromiseAbortable",{enumerable:true,get:function(){return chunkLRGO34YG_js.I}});Object.defineProperty(exports,"fromPull",{enumerable:true,get:function(){return chunkLRGO34YG_js.M}});Object.defineProperty(exports,"globalScheduler",{enumerable:true,get:function(){return chunkLRGO34YG_js.z}});Object.defineProperty(exports,"managedStream",{enumerable:true,get:function(){return chunkLRGO34YG_js.O}});Object.defineProperty(exports,"map",{enumerable:true,get:function(){return chunkLRGO34YG_js.s}});Object.defineProperty(exports,"mapError",{enumerable:true,get:function(){return chunkLRGO34YG_js.u}});Object.defineProperty(exports,"mapStream",{enumerable:true,get:function(){return chunkLRGO34YG_js.W}});Object.defineProperty(exports,"merge",{enumerable:true,get:function(){return chunkLRGO34YG_js.U}});Object.defineProperty(exports,"mergeStream",{enumerable:true,get:function(){return chunkLRGO34YG_js.P}});Object.defineProperty(exports,"none",{enumerable:true,get:function(){return chunkLRGO34YG_js.n}});Object.defineProperty(exports,"orElseOptional",{enumerable:true,get:function(){return chunkLRGO34YG_js.w}});Object.defineProperty(exports,"rangeStream",{enumerable:true,get:function(){return chunkLRGO34YG_js.X}});Object.defineProperty(exports,"some",{enumerable:true,get:function(){return chunkLRGO34YG_js.o}});Object.defineProperty(exports,"streamFromReadableStream",{enumerable:true,get:function(){return chunkLRGO34YG_js.aa}});Object.defineProperty(exports,"succeed",{enumerable:true,get:function(){return chunkLRGO34YG_js.p}});Object.defineProperty(exports,"sync",{enumerable:true,get:function(){return chunkLRGO34YG_js.r}});Object.defineProperty(exports,"toPromise",{enumerable:true,get:function(){return chunkLRGO34YG_js.E}});Object.defineProperty(exports,"tryPromiseAbortable",{enumerable:true,get:function(){return chunkLRGO34YG_js.H}});Object.defineProperty(exports,"uncons",{enumerable:true,get:function(){return chunkLRGO34YG_js.V}});Object.defineProperty(exports,"unit",{enumerable:true,get:function(){return chunkLRGO34YG_js.d}});Object.defineProperty(exports,"unsafeRunAsync",{enumerable:true,get:function(){return chunkLRGO34YG_js.D}});Object.defineProperty(exports,"unwrapScoped",{enumerable:true,get:function(){return chunkLRGO34YG_js.N}});Object.defineProperty(exports,"widenOpt",{enumerable:true,get:function(){return chunkLRGO34YG_js.L}});Object.defineProperty(exports,"withScope",{enumerable:true,get:function(){return chunkLRGO34YG_js.K}});Object.defineProperty(exports,"zip",{enumerable:true,get:function(){return chunkLRGO34YG_js.Y}});exports.linkAbortController=ce;exports.makeCancelToken=te;
package/dist/index.mjs CHANGED
@@ -1 +1 @@
1
- import {a,f,k as k$1,j as j$1,c,e,g as g$1,r,i,d}from'./chunk-SMCQ6GGV.mjs';export{p as RuntimeFiber,n as Scheduler,l as acquireRelease,i as async,b as asyncCatchAll,f as asyncFail,k as asyncFlatMap,a as asyncFold,m as asyncInterruptible,j as asyncMap,c as asyncMapError,e as asyncSucceed,g as asyncSync,h as asyncTotal,r as fork,q as from,v as fromCallback,u as fromPromise,x as fromPromiseAbortable,o as globalScheduler,t as toPromise,w as tryPromiseAbortable,d as unit,s as unsafeRunAsync}from'./chunk-SMCQ6GGV.mjs';var Z={_tag:"None"},I=e=>({_tag:"Some",value:e});var k=e$1=>e(e$1),b=e=>f(e),pe=e=>g$1(t=>e(t)),g=(e,t)=>j$1(e,t),L=(e,t)=>k$1(e,r=>t(r)),C=(e,t)=>c(e,t),ue=(e$1,t)=>a(e$1,r=>t(r),r=>e(r));function j(e$1,t){return a(e$1,r=>r._tag==="Some"?f(r):t(),r=>e(r))}var Ae=()=>b(Z);function ye(){let e=false,t=new Set;return {isCancelled:()=>e,onCancel:n=>{if(e){try{n();}catch{}return ()=>{}}return t.add(n),()=>{t.delete(n);}},cancel:()=>{e||(e=true,t.forEach(n=>n()),t.clear());}}}function me(e,t){return e.onCancel(()=>t.abort())}var D=1;function G(e){return i((t,r)=>{let n=e.length;if(n===0){r({_tag:"Success",value:void 0});return}for(let o of e)o.join(()=>{n-=1,n===0&&r({_tag:"Success",value:void 0});});})}function J(e){return a(e,()=>d,()=>d)}var x=class e{constructor(t){this.env=t;this.id=D++;}id;closed=false;children=new Set;subScopes=new Set;finalizers=[];addFinalizer(t){if(this.closed)throw new Error("Trying to add finalizer to closed scope");this.finalizers.push(t);}subScope(){if(this.closed)throw new Error("Scope closed");let t=new e(this.env);return this.subScopes.add(t),t}fork(t,r$1){if(this.closed)throw new Error("Scope closed");let n=r(t,r$1);return this.children.add(n),n.join(()=>{this.children.delete(n);}),n}close(t={_tag:"Success",value:void 0}){r(this.closeAsync(t),this.env);}closeAsync(t={_tag:"Success",value:void 0},r$1={}){return i((n,o)=>{if(this.closed){o({_tag:"Success",value:void 0});return}this.closed=true;let a=Array.from(this.children),i=Array.from(this.subScopes);this.children.clear(),this.subScopes.clear();for(let l of a)try{l.interrupt();}catch{}let c=d();for(let l of i)c=k$1(c,()=>l.closeAsync(t,r$1));for(;this.finalizers.length>0;){let l=this.finalizers.pop();c=k$1(c,()=>J(l(t)));}r$1.awaitChildren&&(c=k$1(c,()=>G(a))),r(c,this.env).join(()=>o({_tag:"Success",value:void 0}));})}};function ge(e){let t=new x({});try{return e(t)}finally{t.close();}}function W(e,t,r,n,o){return i((a,i)=>{let c=r.subScope(),E=false,l=c.fork(e,a),S=c.fork(t,a),d=y=>{c.fork(y,a).join(O=>{c.close(O),i(O);});};l.join(y=>{E||(E=true,d(n(y,S,c)));}),S.join(y=>{E||(E=true,d(o(y,l,c)));});})}var M=e=>e._tag==="None"?Z:I(e.value),h=e=>({_tag:"FromPull",pull:e}),Pe=(e,t)=>({_tag:"Scoped",acquire:e,release:t}),ze=e$1=>({_tag:"Scoped",acquire:k$1(e$1,t=>e(t.stream)),release:t=>k$1(e$1,r=>r.release(t))}),Ne=(e,t,r=true)=>({_tag:"Merge",left:e,right:t,flip:r}),z=()=>({_tag:"Empty"}),q=e=>({_tag:"Emit",value:e}),w=(e,t)=>({_tag:"Concat",left:e,right:t}),P=e=>({_tag:"Flatten",stream:e});function H(e$1,t,r,n,o){return (a,i,c)=>{if(a._tag,a._tag,a._tag==="Success"){let[S,d]=a.value;i.interrupt();let y=h(e$1==="L"?B(d,r):B(t,d));return e([S,y])}let E=a.error;if(typeof E=="object"&&E!==null&&E._tag==="Interrupted")return f(E);let l=E;return l._tag==="None"?s(e$1==="L"?r:t):f(l)}}function B(e,t,r,n){return i((o,a)=>{let c=new x(o),E=s(e),l=s(t),S=H("L",e,t),d=H("R",e,t),y=W(E,l,c,S,d);c.fork(y,o).join(O=>{c.close(O),a(O);});})}function Te(e,t){return h(B(e,t))}function s(e){switch(e._tag){case "Empty":return b(Z);case "Emit":return g(C(e.value,t=>I(t)),t=>[t,z()]);case "FromPull":return e.pull;case "Concat":return j(g(s(e.left),([t,r])=>[t,w(r,e.right)]),()=>s(e.right));case "Flatten":return L(s(e.stream),([t,r])=>j(g(s(t),([n,o])=>[n,w(o,P(r))]),()=>s(P(r))));case "Merge":return B(e.left,e.right,e.flip);case "Scoped":return i((t,r)=>{let n=new x(t);n.addFinalizer(o=>e.release(o)),n.fork(e.acquire,t).join(o=>{if(o._tag==="Failure"){n.close(o),r({_tag:"Failure",error:I(o.error)});return}let a=o.value;s(a)(t,c=>{n.close(c),r(c);});});})}}function v(e,t){switch(e._tag){case "Empty":return z();case "Emit":return q(g(e.value,t));case "FromPull":return h(g(e.pull,([r,n])=>[t(r),v(n,t)]));case "Concat":return w(v(e.left,t),v(e.right,t));case "Flatten":{let r=v(e.stream,n=>v(n,t));return P(r)}}}function Le(e$1,t){let r=n=>h(n>t?f(Z):e([n,r(n+1)]));return r(e$1)}function K(e$1,t){let r=a(c(s(e$1),n=>M(n)),n=>f(n),([n,o])=>a(c(s(t),a=>M(a)),a=>f(a),([a,i])=>e([[n,a],K(o,i)])));return h(r)}function We(e$1,t){let r=n=>a(c(s(n),o=>M(o)),o=>o._tag==="None"?e(void 0):f(o),([o,a])=>k$1(c(t(o),i=>I(i)),()=>r(a)));return a(r(e$1),n=>n._tag==="None"?e(void 0):f(n.value),()=>e(void 0))}function He(e){let t=z();for(let r=e.length-1;r>=0;r--){let n=q(k(e[r]));t=w(n,t);}return t}function qe(e){let t=(r,n)=>a(s(r),o=>o._tag==="None"?k(n):b(o),([o,a])=>t(a,[...n,o]));return C(t(e,[]),r=>{if(r._tag==="Some")return r.value;throw new Error("unreachable: stream end handled as success")})}export{x as Scope,ue as catchAll,qe as collectStream,w as concatStream,q as emitStream,z as emptyStream,Ae as end,b as fail,L as flatMap,P as flattenStream,We as foreachStream,He as fromArray,h as fromPull,me as linkAbortController,ye as makeCancelToken,ze as managedStream,g as map,C as mapError,v as mapStream,Te as merge,Ne as mergeStream,Z as none,j as orElseOptional,Le as rangeStream,I as some,k as succeed,pe as sync,s as uncons,Pe as unwrapScoped,ge as withScope,K as zip};
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-7M74PYBY.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};
@@ -162,4 +162,59 @@ declare const catchAll: <R, E, A, R2, E2, B>(fa: ZIO<R, E, A>, handler: (e: E) =
162
162
  declare function orElseOptional<R, E, A, R2, A2>(fa: ZIO<R, Option<E>, A>, that: () => ZIO<R2, Option<E>, A2>): ZIO<R & R2, Option<E>, A | A2>;
163
163
  declare const end: <E>() => ZIO<unknown, Option<E>, never>;
164
164
 
165
- export { type Async as A, makeCancelToken as B, type Canceler as C, linkAbortController as D, type Exit as E, type Fiber as F, type FiberId as G, type FiberStatus as H, type Interrupted as I, type ScopeId as J, Scope as K, withScope as L, globalScheduler as M, type None as N, type Option as O, RuntimeFiber as R, Scheduler as S, type Task as T, type ZIO as Z, sync as a, flatMap as b, mapError as c, catchAll as d, end as e, fail as f, asyncFold as g, asyncCatchAll as h, asyncMapError as i, asyncSucceed as j, asyncFail as k, asyncSync as l, map as m, asyncTotal as n, orElseOptional as o, async as p, asyncMap as q, asyncFlatMap as r, succeed as s, acquireRelease as t, unit as u, asyncInterruptible as v, type Some as w, none as x, some as y, type CancelToken as z };
165
+ type Empty<R, E, A> = {
166
+ readonly _tag: "Empty";
167
+ };
168
+ type Emit<R, E, A> = {
169
+ readonly _tag: "Emit";
170
+ readonly value: ZIO<R, E, A>;
171
+ };
172
+ type Concat<R, E, A> = {
173
+ readonly _tag: "Concat";
174
+ readonly left: ZStream<R, E, A>;
175
+ readonly right: ZStream<R, E, A>;
176
+ };
177
+ type Flatten<R, E, A> = {
178
+ readonly _tag: "Flatten";
179
+ readonly stream: ZStream<R, E, ZStream<R, E, A>>;
180
+ };
181
+ type FromPull<R, E, A> = {
182
+ readonly _tag: "FromPull";
183
+ readonly pull: ZIO<R, Option<E>, [A, ZStream<R, E, A>]>;
184
+ };
185
+ type Merge<R, E, A> = {
186
+ readonly _tag: "Merge";
187
+ readonly left: ZStream<R, E, A>;
188
+ readonly right: ZStream<R, E, A>;
189
+ readonly flip: boolean;
190
+ };
191
+ type Scoped<R, E, A> = {
192
+ readonly _tag: "Scoped";
193
+ readonly acquire: ZIO<R, E, ZStream<R, E, A>>;
194
+ readonly release: (exit: Exit<any, any>) => Async<R, any, void>;
195
+ };
196
+ type ZStream<R, E, A> = Empty<R, E, A> | Emit<R, E, A> | Concat<R, E, A> | FromPull<R, E, A> | Flatten<R, E, A> | Merge<R, E, A> | Scoped<R, E, A>;
197
+ type Normalize<E> = (u: unknown) => E;
198
+ declare const widenOpt: <E1, E2>(opt: Option<E1>) => Option<E1 | E2>;
199
+ declare const fromPull: <R, E, A>(pull: ZIO<R, Option<E>, [A, ZStream<R, E, A>]>) => ZStream<R, E, A>;
200
+ declare const unwrapScoped: <R, E, A>(acquire: ZIO<R, E, ZStream<R, E, A>>, release: (exit: Exit<any, any>) => Async<R, any, void>) => ZStream<R, E, A>;
201
+ declare const managedStream: <R, E, A>(acquire: Async<R, E, {
202
+ stream: ZStream<R, E, A>;
203
+ release: (exit: Exit<any, any>) => Async<R, any, void>;
204
+ }>) => ZStream<R, E, A>;
205
+ declare const mergeStream: <R, E, A>(left: ZStream<R, E, A>, right: ZStream<R, E, A>, flip?: boolean) => ZStream<R, E, A>;
206
+ declare const emptyStream: <R, E, A>() => ZStream<R, E, A>;
207
+ declare const emitStream: <R, E, A>(value: ZIO<R, E, A>) => ZStream<R, E, A>;
208
+ declare const concatStream: <R, E, A>(left: ZStream<R, E, A>, right: ZStream<R, E, A>) => ZStream<R, E, A>;
209
+ declare const flattenStream: <R, E, A>(stream: ZStream<R, E, ZStream<R, E, A>>) => ZStream<R, E, A>;
210
+ declare function merge<R, E, A>(left: ZStream<R, E, A>, right: ZStream<R, E, A>): ZStream<R, E, A>;
211
+ declare function uncons<R, E, A>(self: ZStream<R, E, A>): ZIO<R, Option<E>, [A, ZStream<R, E, A>]>;
212
+ declare function mapStream<R, E, A, B>(self: ZStream<R, E, A>, f: (a: A) => B): ZStream<R, E, B>;
213
+ declare function rangeStream(start: number, end: number): ZStream<unknown, never, number>;
214
+ declare function zip<R, E1, A, E2, B>(left: ZStream<R, E1, A>, right: ZStream<R, E2, B>): ZStream<R, E1 | E2, [A, B]>;
215
+ declare function foreachStream<R, E, A, R2, E2>(stream: ZStream<R, E, A>, f: (a: A) => Async<R2, E2, void>): Async<R & R2, E | E2, void>;
216
+ declare function fromArray<A>(values: readonly A[]): ZStream<unknown, never, A>;
217
+ declare function collectStream<R, E, A>(stream: ZStream<R, E, A>): ZIO<R, E, A[]>;
218
+ declare function streamFromReadableStream<E>(body: ReadableStream<Uint8Array> | null | undefined, normalizeError: Normalize<E>): ZStream<unknown, E, Uint8Array>;
219
+
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 };
@@ -162,4 +162,59 @@ declare const catchAll: <R, E, A, R2, E2, B>(fa: ZIO<R, E, A>, handler: (e: E) =
162
162
  declare function orElseOptional<R, E, A, R2, A2>(fa: ZIO<R, Option<E>, A>, that: () => ZIO<R2, Option<E>, A2>): ZIO<R & R2, Option<E>, A | A2>;
163
163
  declare const end: <E>() => ZIO<unknown, Option<E>, never>;
164
164
 
165
- export { type Async as A, makeCancelToken as B, type Canceler as C, linkAbortController as D, type Exit as E, type Fiber as F, type FiberId as G, type FiberStatus as H, type Interrupted as I, type ScopeId as J, Scope as K, withScope as L, globalScheduler as M, type None as N, type Option as O, RuntimeFiber as R, Scheduler as S, type Task as T, type ZIO as Z, sync as a, flatMap as b, mapError as c, catchAll as d, end as e, fail as f, asyncFold as g, asyncCatchAll as h, asyncMapError as i, asyncSucceed as j, asyncFail as k, asyncSync as l, map as m, asyncTotal as n, orElseOptional as o, async as p, asyncMap as q, asyncFlatMap as r, succeed as s, acquireRelease as t, unit as u, asyncInterruptible as v, type Some as w, none as x, some as y, type CancelToken as z };
165
+ type Empty<R, E, A> = {
166
+ readonly _tag: "Empty";
167
+ };
168
+ type Emit<R, E, A> = {
169
+ readonly _tag: "Emit";
170
+ readonly value: ZIO<R, E, A>;
171
+ };
172
+ type Concat<R, E, A> = {
173
+ readonly _tag: "Concat";
174
+ readonly left: ZStream<R, E, A>;
175
+ readonly right: ZStream<R, E, A>;
176
+ };
177
+ type Flatten<R, E, A> = {
178
+ readonly _tag: "Flatten";
179
+ readonly stream: ZStream<R, E, ZStream<R, E, A>>;
180
+ };
181
+ type FromPull<R, E, A> = {
182
+ readonly _tag: "FromPull";
183
+ readonly pull: ZIO<R, Option<E>, [A, ZStream<R, E, A>]>;
184
+ };
185
+ type Merge<R, E, A> = {
186
+ readonly _tag: "Merge";
187
+ readonly left: ZStream<R, E, A>;
188
+ readonly right: ZStream<R, E, A>;
189
+ readonly flip: boolean;
190
+ };
191
+ type Scoped<R, E, A> = {
192
+ readonly _tag: "Scoped";
193
+ readonly acquire: ZIO<R, E, ZStream<R, E, A>>;
194
+ readonly release: (exit: Exit<any, any>) => Async<R, any, void>;
195
+ };
196
+ type ZStream<R, E, A> = Empty<R, E, A> | Emit<R, E, A> | Concat<R, E, A> | FromPull<R, E, A> | Flatten<R, E, A> | Merge<R, E, A> | Scoped<R, E, A>;
197
+ type Normalize<E> = (u: unknown) => E;
198
+ declare const widenOpt: <E1, E2>(opt: Option<E1>) => Option<E1 | E2>;
199
+ declare const fromPull: <R, E, A>(pull: ZIO<R, Option<E>, [A, ZStream<R, E, A>]>) => ZStream<R, E, A>;
200
+ declare const unwrapScoped: <R, E, A>(acquire: ZIO<R, E, ZStream<R, E, A>>, release: (exit: Exit<any, any>) => Async<R, any, void>) => ZStream<R, E, A>;
201
+ declare const managedStream: <R, E, A>(acquire: Async<R, E, {
202
+ stream: ZStream<R, E, A>;
203
+ release: (exit: Exit<any, any>) => Async<R, any, void>;
204
+ }>) => ZStream<R, E, A>;
205
+ declare const mergeStream: <R, E, A>(left: ZStream<R, E, A>, right: ZStream<R, E, A>, flip?: boolean) => ZStream<R, E, A>;
206
+ declare const emptyStream: <R, E, A>() => ZStream<R, E, A>;
207
+ declare const emitStream: <R, E, A>(value: ZIO<R, E, A>) => ZStream<R, E, A>;
208
+ declare const concatStream: <R, E, A>(left: ZStream<R, E, A>, right: ZStream<R, E, A>) => ZStream<R, E, A>;
209
+ declare const flattenStream: <R, E, A>(stream: ZStream<R, E, ZStream<R, E, A>>) => ZStream<R, E, A>;
210
+ declare function merge<R, E, A>(left: ZStream<R, E, A>, right: ZStream<R, E, A>): ZStream<R, E, A>;
211
+ declare function uncons<R, E, A>(self: ZStream<R, E, A>): ZIO<R, Option<E>, [A, ZStream<R, E, A>]>;
212
+ declare function mapStream<R, E, A, B>(self: ZStream<R, E, A>, f: (a: A) => B): ZStream<R, E, B>;
213
+ declare function rangeStream(start: number, end: number): ZStream<unknown, never, number>;
214
+ declare function zip<R, E1, A, E2, B>(left: ZStream<R, E1, A>, right: ZStream<R, E2, B>): ZStream<R, E1 | E2, [A, B]>;
215
+ declare function foreachStream<R, E, A, R2, E2>(stream: ZStream<R, E, A>, f: (a: A) => Async<R2, E2, void>): Async<R & R2, E | E2, void>;
216
+ declare function fromArray<A>(values: readonly A[]): ZStream<unknown, never, A>;
217
+ declare function collectStream<R, E, A>(stream: ZStream<R, E, A>): ZIO<R, E, A[]>;
218
+ declare function streamFromReadableStream<E>(body: ReadableStream<Uint8Array> | null | undefined, normalizeError: Normalize<E>): ZStream<unknown, E, Uint8Array>;
219
+
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 };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "brass-runtime",
3
- "version": "1.6.2",
3
+ "version": "1.7.0",
4
4
  "description": "Effect runtime utilities for TypeScript",
5
5
  "license": "ISC",
6
6
  "author": "",
@@ -1 +0,0 @@
1
- 'use strict';function E(n,e,t){return {_tag:"Fold",first:n,onFailure:e,onSuccess:t}}function D(n,e){return E(n,t=>e(t),t=>A(t))}function P(n,e){return E(n,t=>m(e(t)),t=>A(t))}var T=()=>A(void 0),A=n=>({_tag:"Succeed",value:n}),m=n=>({_tag:"Fail",error:n}),S=n=>({_tag:"Sync",thunk:n}),I=n=>S(()=>n()),l=n=>({_tag:"Async",register:n});function C(n,e){return p(n,t=>A(e(t)))}function p(n,e){return {_tag:"FlatMap",first:n,andThen:e}}function z(n,e,t){return p(n,r=>(t.addFinalizer(i=>e(r,i)),A(r)))}function U(n){return l(n)}var d=class{buf;head=0;tail=0;size_=0;constructor(e=1024){let t=Math.max(2,this.nextPow2(e));this.buf=new Array(t);}get length(){return this.size_}get capacity(){return this.buf.length}isEmpty(){return this.size_===0}push(e){this.size_===this.buf.length&&this.grow(),this.buf[this.tail]=e,this.tail=this.tail+1&this.buf.length-1,this.size_++;}shift(){if(this.size_===0)return;let e=this.buf[this.head];return this.buf[this.head]=void 0,this.head=this.head+1&this.buf.length-1,this.size_--,e}clear(){this.buf.fill(void 0),this.head=0,this.tail=0,this.size_=0;}grow(){let e=this.buf,t=new Array(e.length*2);for(let r=0;r<this.size_;r++)t[r]=e[this.head+r&e.length-1];this.buf=t,this.head=0,this.tail=this.size_;}nextPow2(e){let t=1;for(;t<e;)t<<=1;return t}};var g=2048,R=4096,x=(()=>{if(typeof globalThis.setImmediate=="function")return n=>globalThis.setImmediate(n);if(typeof globalThis.MessageChannel=="function"){let n=new globalThis.MessageChannel,e=null;return n.port1.onmessage=()=>{let t=e;e=null,t?.();},t=>{e=t,n.port2.postMessage(0);}}return n=>setTimeout(n,0)})(),y=class{queue=new d(1024);flushing=false;scheduled=false;schedule(e,t="anonymous"){if(typeof e=="function"&&(this.queue.push({tag:t,task:e}),!this.flushing&&!this.scheduled)){this.scheduled=true;let r=this.queue.length>R?"macro":"micro";this.requestFlush(r);}}requestFlush(e){e==="micro"?queueMicrotask(()=>this.flush()):x(()=>this.flush());}flush(){if(this.flushing)return;this.flushing=true,this.scheduled=false;let e=0;try{for(;e<g;){let t=this.queue.shift();if(!t)break;e++;try{t.task();}catch(r){console.error(`[Scheduler] task threw (tag=${t.tag})`,r);}}}finally{if(this.flushing=false,this.queue.length>0&&!this.scheduled){this.scheduled=true;let t=e>=g||this.queue.length>R?"macro":"micro";this.requestFlush(t);}}}},b=new y;var u={CONTINUE:"Continue",SUSPEND:"Suspend",DONE:"Done"},c={QUEUED:"Queued",RUNNING:"Running",SUSPENDED:"Suspended",DONE:"Done"},F=1,_=1024;function k(n){let e=n;for(;e._tag==="FlatMap"&&e.first._tag==="FlatMap";){let t=e.first,r=e.andThen;e={_tag:"FlatMap",first:t.first,andThen:i=>({_tag:"FlatMap",first:t.andThen(i),andThen:r})};}return e}var f=class{constructor(e,t,r){this.scheduler=r;this.id=F++,this.current=e,this.env=t;}id;closing=null;finishing=false;runState=c.RUNNING;interrupted=false;result=null;joiners=[];current;env;stack=[];fiberFinalizers=[];finalizersDrained=false;addFinalizer(e){this.fiberFinalizers.push(e);}status(){return this.result==null?"Running":this.interrupted?"Interrupted":"Done"}join(e){this.result!=null?e(this.result):this.joiners.push(e);}interrupt(){this.result==null&&(this.interrupted||(this.interrupted=true,this.schedule("interrupt-step")));}schedule(e="step"){this.runState===c.DONE||this.runState===c.QUEUED||(this.runState=c.QUEUED,this.scheduler.schedule(()=>{if(this.runState===c.DONE)return;switch(this.runState=c.RUNNING,this.step()){case u.CONTINUE:this.schedule("continue");return;case u.SUSPEND:this.runState=c.SUSPENDED;return;case u.DONE:this.runState=c.DONE;return}},`fiber#${this.id}.${e}`));}runFinalizersOnce(e){if(!this.finalizersDrained)for(this.finalizersDrained=true;this.fiberFinalizers.length>0;){let t=this.fiberFinalizers.pop();try{t(e);}catch{}}}notify(e){if(this.result==null&&this.closing==null){this.finishing=true,this.closing=e,this.runFinalizersOnce(e),this.result=e;for(let t of this.joiners)t(e);this.joiners.length=0;}}onSuccess(e){let t=this.stack.pop();if(!t){this.notify({_tag:"Success",value:e});return}this.current=t._tag==="SuccessCont"?t.k(e):t.onSuccess(e);}onFailure(e){for(;this.stack.length>0;){let t=this.stack.pop();if(t._tag==="FoldCont"){this.current=t.onFailure(e);return}}this.notify({_tag:"Failure",error:e});}step(){let e=_;for(;e-- >0;){if(this.result!=null)return u.DONE;if(this.interrupted&&this.closing==null)return this.notify({_tag:"Failure",error:{_tag:"Interrupted"}}),u.DONE;let t=k(this.current);switch(t._tag){case "Succeed":{this.onSuccess(t.value);break}case "Fail":{this.onFailure(t.error);break}case "Sync":{try{let r=t.thunk(this.env);this.onSuccess(r);}catch(r){this.onFailure(r);}break}case "FlatMap":{this.stack.push({_tag:"SuccessCont",k:t.andThen}),this.current=t.first;break}case "Fold":{this.stack.push({_tag:"FoldCont",onFailure:t.onFailure,onSuccess:t.onSuccess}),this.current=t.first;break}case "Async":{if(this.finishing)return this.result!=null?u.DONE:u.CONTINUE;let r=false,i=o=>{r||(r=true,!(this.result!=null||this.closing!=null)&&(this.current=o._tag==="Success"?{_tag:"Succeed",value:o.value}:{_tag:"Fail",error:o.error},this.schedule("async-resume")));},s=t.register(this.env,i);return typeof s=="function"&&this.addFinalizer(()=>{r=true;try{s();}catch{}}),u.SUSPEND}}}return this.result!=null?u.DONE:u.CONTINUE}};function V(n){return l((e,t)=>{let r=false,i=a=>{r||(r=true,t(a));},s=a=>i({_tag:"Failure",error:a instanceof Error?a:new Error(String(a))}),o=a=>i({_tag:"Success",value:a});try{typeof n=="function"&&n.length>=1?n((a,h)=>a?s(a):o(h)):n().then(o,s);}catch(a){s(a);}})}function v(n,e,t=b){let r=new f(n,e,t);return r.schedule("initial-step"),r}function W(n,e,t){v(n,e).join(t);}function X(n,e){return new Promise((t,r)=>{v(n,e).join(s=>{let o=s;o._tag==="Success"?t(o.value):r(o.error);});})}function Y(n,e){return l((t,r)=>{n(t).then(i=>r({_tag:"Success",value:i})).catch(i=>r({_tag:"Failure",error:e(i)}));})}function Z(n){return l((e,t)=>{let r=false,i=s=>{r||(r=true,t(s));};try{n((s,o)=>{i(s?{_tag:"Failure",error:s}:{_tag:"Success",value:o});});}catch(s){i({_tag:"Failure",error:s instanceof Error?s:new Error(String(s))});}})}function ee(n){return w((t,r)=>n.length===1?n(r):n(t,r),t=>N(t)?{_tag:"Abort"}:{_tag:"PromiseRejected",reason:t})}function w(n,e){return l((t,r)=>{let i=new AbortController,s=false,o=a=>{s||(s=true,r(a));};try{(n.length===1?n(i.signal):n(t,i.signal)).then(h=>o({_tag:"Success",value:h})).catch(h=>o({_tag:"Failure",error:e(h)}));}catch(a){o({_tag:"Failure",error:e(a)});}return ()=>{s=true,i.abort();}})}var N=n=>typeof n=="object"&&n!==null&&"name"in n&&n.name==="AbortError";exports.a=E;exports.b=D;exports.c=P;exports.d=T;exports.e=A;exports.f=m;exports.g=S;exports.h=I;exports.i=l;exports.j=C;exports.k=p;exports.l=z;exports.m=U;exports.n=y;exports.o=b;exports.p=f;exports.q=V;exports.r=v;exports.s=W;exports.t=X;exports.u=Y;exports.v=Z;exports.w=ee;exports.x=w;
@@ -1 +0,0 @@
1
- function E(n,e,t){return {_tag:"Fold",first:n,onFailure:e,onSuccess:t}}function D(n,e){return E(n,t=>e(t),t=>A(t))}function P(n,e){return E(n,t=>m(e(t)),t=>A(t))}var T=()=>A(void 0),A=n=>({_tag:"Succeed",value:n}),m=n=>({_tag:"Fail",error:n}),S=n=>({_tag:"Sync",thunk:n}),I=n=>S(()=>n()),l=n=>({_tag:"Async",register:n});function C(n,e){return p(n,t=>A(e(t)))}function p(n,e){return {_tag:"FlatMap",first:n,andThen:e}}function z(n,e,t){return p(n,r=>(t.addFinalizer(i=>e(r,i)),A(r)))}function U(n){return l(n)}var d=class{buf;head=0;tail=0;size_=0;constructor(e=1024){let t=Math.max(2,this.nextPow2(e));this.buf=new Array(t);}get length(){return this.size_}get capacity(){return this.buf.length}isEmpty(){return this.size_===0}push(e){this.size_===this.buf.length&&this.grow(),this.buf[this.tail]=e,this.tail=this.tail+1&this.buf.length-1,this.size_++;}shift(){if(this.size_===0)return;let e=this.buf[this.head];return this.buf[this.head]=void 0,this.head=this.head+1&this.buf.length-1,this.size_--,e}clear(){this.buf.fill(void 0),this.head=0,this.tail=0,this.size_=0;}grow(){let e=this.buf,t=new Array(e.length*2);for(let r=0;r<this.size_;r++)t[r]=e[this.head+r&e.length-1];this.buf=t,this.head=0,this.tail=this.size_;}nextPow2(e){let t=1;for(;t<e;)t<<=1;return t}};var g=2048,R=4096,x=(()=>{if(typeof globalThis.setImmediate=="function")return n=>globalThis.setImmediate(n);if(typeof globalThis.MessageChannel=="function"){let n=new globalThis.MessageChannel,e=null;return n.port1.onmessage=()=>{let t=e;e=null,t?.();},t=>{e=t,n.port2.postMessage(0);}}return n=>setTimeout(n,0)})(),y=class{queue=new d(1024);flushing=false;scheduled=false;schedule(e,t="anonymous"){if(typeof e=="function"&&(this.queue.push({tag:t,task:e}),!this.flushing&&!this.scheduled)){this.scheduled=true;let r=this.queue.length>R?"macro":"micro";this.requestFlush(r);}}requestFlush(e){e==="micro"?queueMicrotask(()=>this.flush()):x(()=>this.flush());}flush(){if(this.flushing)return;this.flushing=true,this.scheduled=false;let e=0;try{for(;e<g;){let t=this.queue.shift();if(!t)break;e++;try{t.task();}catch(r){console.error(`[Scheduler] task threw (tag=${t.tag})`,r);}}}finally{if(this.flushing=false,this.queue.length>0&&!this.scheduled){this.scheduled=true;let t=e>=g||this.queue.length>R?"macro":"micro";this.requestFlush(t);}}}},b=new y;var u={CONTINUE:"Continue",SUSPEND:"Suspend",DONE:"Done"},c={QUEUED:"Queued",RUNNING:"Running",SUSPENDED:"Suspended",DONE:"Done"},F=1,_=1024;function k(n){let e=n;for(;e._tag==="FlatMap"&&e.first._tag==="FlatMap";){let t=e.first,r=e.andThen;e={_tag:"FlatMap",first:t.first,andThen:i=>({_tag:"FlatMap",first:t.andThen(i),andThen:r})};}return e}var f=class{constructor(e,t,r){this.scheduler=r;this.id=F++,this.current=e,this.env=t;}id;closing=null;finishing=false;runState=c.RUNNING;interrupted=false;result=null;joiners=[];current;env;stack=[];fiberFinalizers=[];finalizersDrained=false;addFinalizer(e){this.fiberFinalizers.push(e);}status(){return this.result==null?"Running":this.interrupted?"Interrupted":"Done"}join(e){this.result!=null?e(this.result):this.joiners.push(e);}interrupt(){this.result==null&&(this.interrupted||(this.interrupted=true,this.schedule("interrupt-step")));}schedule(e="step"){this.runState===c.DONE||this.runState===c.QUEUED||(this.runState=c.QUEUED,this.scheduler.schedule(()=>{if(this.runState===c.DONE)return;switch(this.runState=c.RUNNING,this.step()){case u.CONTINUE:this.schedule("continue");return;case u.SUSPEND:this.runState=c.SUSPENDED;return;case u.DONE:this.runState=c.DONE;return}},`fiber#${this.id}.${e}`));}runFinalizersOnce(e){if(!this.finalizersDrained)for(this.finalizersDrained=true;this.fiberFinalizers.length>0;){let t=this.fiberFinalizers.pop();try{t(e);}catch{}}}notify(e){if(this.result==null&&this.closing==null){this.finishing=true,this.closing=e,this.runFinalizersOnce(e),this.result=e;for(let t of this.joiners)t(e);this.joiners.length=0;}}onSuccess(e){let t=this.stack.pop();if(!t){this.notify({_tag:"Success",value:e});return}this.current=t._tag==="SuccessCont"?t.k(e):t.onSuccess(e);}onFailure(e){for(;this.stack.length>0;){let t=this.stack.pop();if(t._tag==="FoldCont"){this.current=t.onFailure(e);return}}this.notify({_tag:"Failure",error:e});}step(){let e=_;for(;e-- >0;){if(this.result!=null)return u.DONE;if(this.interrupted&&this.closing==null)return this.notify({_tag:"Failure",error:{_tag:"Interrupted"}}),u.DONE;let t=k(this.current);switch(t._tag){case "Succeed":{this.onSuccess(t.value);break}case "Fail":{this.onFailure(t.error);break}case "Sync":{try{let r=t.thunk(this.env);this.onSuccess(r);}catch(r){this.onFailure(r);}break}case "FlatMap":{this.stack.push({_tag:"SuccessCont",k:t.andThen}),this.current=t.first;break}case "Fold":{this.stack.push({_tag:"FoldCont",onFailure:t.onFailure,onSuccess:t.onSuccess}),this.current=t.first;break}case "Async":{if(this.finishing)return this.result!=null?u.DONE:u.CONTINUE;let r=false,i=o=>{r||(r=true,!(this.result!=null||this.closing!=null)&&(this.current=o._tag==="Success"?{_tag:"Succeed",value:o.value}:{_tag:"Fail",error:o.error},this.schedule("async-resume")));},s=t.register(this.env,i);return typeof s=="function"&&this.addFinalizer(()=>{r=true;try{s();}catch{}}),u.SUSPEND}}}return this.result!=null?u.DONE:u.CONTINUE}};function V(n){return l((e,t)=>{let r=false,i=a=>{r||(r=true,t(a));},s=a=>i({_tag:"Failure",error:a instanceof Error?a:new Error(String(a))}),o=a=>i({_tag:"Success",value:a});try{typeof n=="function"&&n.length>=1?n((a,h)=>a?s(a):o(h)):n().then(o,s);}catch(a){s(a);}})}function v(n,e,t=b){let r=new f(n,e,t);return r.schedule("initial-step"),r}function W(n,e,t){v(n,e).join(t);}function X(n,e){return new Promise((t,r)=>{v(n,e).join(s=>{let o=s;o._tag==="Success"?t(o.value):r(o.error);});})}function Y(n,e){return l((t,r)=>{n(t).then(i=>r({_tag:"Success",value:i})).catch(i=>r({_tag:"Failure",error:e(i)}));})}function Z(n){return l((e,t)=>{let r=false,i=s=>{r||(r=true,t(s));};try{n((s,o)=>{i(s?{_tag:"Failure",error:s}:{_tag:"Success",value:o});});}catch(s){i({_tag:"Failure",error:s instanceof Error?s:new Error(String(s))});}})}function ee(n){return w((t,r)=>n.length===1?n(r):n(t,r),t=>N(t)?{_tag:"Abort"}:{_tag:"PromiseRejected",reason:t})}function w(n,e){return l((t,r)=>{let i=new AbortController,s=false,o=a=>{s||(s=true,r(a));};try{(n.length===1?n(i.signal):n(t,i.signal)).then(h=>o({_tag:"Success",value:h})).catch(h=>o({_tag:"Failure",error:e(h)}));}catch(a){o({_tag:"Failure",error:e(a)});}return ()=>{s=true,i.abort();}})}var N=n=>typeof n=="object"&&n!==null&&"name"in n&&n.name==="AbortError";export{E as a,D as b,P as c,T as d,A as e,m as f,S as g,I as h,l as i,C as j,p as k,z as l,U as m,y as n,b as o,f as p,V as q,v as r,W as s,X as t,Y as u,Z as v,ee as w,w as x};