brass-runtime 1.11.1 → 1.12.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/dist/chunk-5PIZGM6Q.js +1 -0
- package/dist/chunk-CNA5AQHG.mjs +1 -0
- package/dist/http/index.d.mts +1 -1
- package/dist/http/index.d.ts +1 -1
- package/dist/http/index.js +1 -1
- package/dist/http/index.mjs +1 -1
- package/dist/index.d.mts +7 -7
- package/dist/index.d.ts +7 -7
- package/dist/index.js +1 -1
- package/dist/index.mjs +1 -1
- package/dist/{stream-hTHRKq88.d.mts → stream-DVfZWtYZ.d.mts} +154 -79
- package/dist/{stream-hTHRKq88.d.ts → stream-DVfZWtYZ.d.ts} +154 -79
- package/package.json +1 -1
- package/dist/chunk-Q2H2CAII.js +0 -1
- package/dist/chunk-ZXK3XM2Q.mjs +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
'use strict';var W={succeed:t=>({_tag:"Succeed",value:t}),fail:t=>({_tag:"Fail",error:t}),sync:t=>({_tag:"Sync",thunk:t}),async:t=>({_tag:"Async",register:t})};function m(t,e,n){return {_tag:"Fold",first:t,onFailure:e,onSuccess:n}}function Oe(t,e){return m(t,n=>e(n),n=>A(n))}function O(t,e){return m(t,n=>S(e(n)),n=>A(n))}var k=()=>A(void 0),A=t=>({_tag:"Succeed",value:t}),S=t=>({_tag:"Fail",error:t}),N=t=>({_tag:"Sync",thunk:t}),Ce=t=>N(()=>t()),d=t=>({_tag:"Async",register:t});function Y(t,e){return h(t,n=>A(e(n)))}function h(t,e){return {_tag:"FlatMap",first:t,andThen:e}}function we(t,e,n){return h(t,r=>(n.addFinalizer(a=>e(r,a)),A(r)))}function Ze(t){return d(t)}var Ne=t=>e=>{let n=e;return n.toPromise||(n.toPromise=r=>t(e,r),n.unsafeRunPromise=()=>t(e,{})),n},Be=(t,e)=>h(t,n=>A(e(n))),Te=(t,e)=>h(t,n=>N(()=>e(n)));var C={_tag:"None"},w=t=>({_tag:"Some",value:t});var g={fail:t=>({_tag:"Fail",error:t}),interrupt:()=>({_tag:"Interrupt"}),die:t=>({_tag:"Die",defect:t})},R={succeed:t=>({_tag:"Success",value:t}),failCause:t=>({_tag:"Failure",cause:t})},G=t=>A(t),U=t=>S(t),ee=t=>N(e=>t(e)),I=(t,e)=>Y(t,e),te=(t,e)=>h(t,n=>e(n)),L=(t,e)=>O(t,e),ze=(t,e)=>m(t,n=>e(n),n=>A(n));function J(t,e){return m(t,n=>n._tag==="Some"?S(n):e(),n=>A(n))}var je=()=>U(C);var de=(r=>(r[r.Ok=0]="Ok",r[r.Grew=1]="Grew",r[r.Dropped=2]="Dropped",r))(de||{}),M=class{buf;head=0;tail=0;size_=0;maxCap;constructor(e=1024,n=e){let r=Math.max(2,this.nextPow2(e)),a=Math.max(r,this.nextPow2(n));this.buf=new Array(r),this.maxCap=a;}get length(){return this.size_}get capacity(){return this.buf.length}isEmpty(){return this.size_===0}push(e){return this.size_===this.buf.length?this.buf.length>=this.maxCap?2:(this.grow(),this.buf[this.tail]=e,this.tail=this.tail+1&this.buf.length-1,this.size_++,1):(this.buf[this.tail]=e,this.tail=this.tail+1&this.buf.length-1,this.size_++,0)}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=Math.min(e.length*2,this.maxCap),r=new Array(n);for(let a=0;a<this.size_;a++)r[a]=e[this.head+a&e.length-1];this.buf=r,this.head=0,this.tail=this.size_;}nextPow2(e){let n=1;for(;n<e;)n<<=1;return n}};var ne=2048,re=4096,pe=(()=>{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)})(),$=class{queue=new M(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>re?"macro":"micro";this.requestFlush(r);}}requestFlush(e){e==="micro"?queueMicrotask(()=>this.flush()):pe(()=>this.flush());}flush(){if(this.flushing)return;this.flushing=true,this.scheduled=false;let e=0;try{for(;e<ne;){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>=ne||this.queue.length>re?"macro":"micro";this.requestFlush(n);}}}},T=new $;var ae={parent:null,patch:Object.create(null)};function se(t,e){let n=Ae(t);return {initChild(r,a,s){let i=a?.fiberContext,o=Re(n,i?.trace??null);r.fiberContext={log:i?.log??ae,trace:o},r.parentFiberId=a?.id,r.name=n.childName(a?.name),s!==void 0&&(r.scopeId=s),e.emit({type:"fiber.start",fiberId:r.id,parentFiberId:a?.id,scopeId:r.scopeId,name:r.name},{fiberId:a?.id,traceId:i?.trace?.traceId,spanId:i?.trace?.spanId});}}}function Ae(t){let e={newTraceId:()=>crypto.randomUUID(),newSpanId:()=>crypto.randomUUID()},n=t?.brass,r=n?.tracer??e,a=n?.traceSeed,s=n?.childName??(i=>i?`${i}/child`:void 0);return {tracer:r,seed:a,childName:s}}function Re(t,e){return e?{traceId:e.traceId,spanId:t.tracer.newSpanId(),parentSpanId:e.spanId,sampled:e.sampled}:t.seed?{...t.seed}:{traceId:t.tracer.newTraceId(),spanId:t.tracer.newSpanId(),sampled:true}}var fe={emit(){}},P=class t{env;scheduler;hooks;forkPolicy;registry;constructor(e){this.env=e.env,this.scheduler=e.scheduler??T,this.hooks=e.hooks??fe,this.forkPolicy=se(this.env,this.hooks);}provide(e){return new t({env:Object.assign({},this.env,e),scheduler:this.scheduler,hooks:this.hooks})}emit(e){let n=b(),r={fiberId:n?.id,scopeId:n?.scopeId,traceId:n?.fiberContext?.trace?.traceId,spanId:n?.fiberContext?.trace?.spanId};this.hooks.emit(e,r);}fork(e,n){let r=b(),a=new z(this,e);return n!==void 0&&(a.scopeId=n),this.forkPolicy.initChild(a,r,n),a.schedule("initial-step"),a}unsafeRunAsync(e,n){this.fork(e).join(n);}toPromise(e){return new Promise((n,r)=>{this.fork(e).join(s=>{if(s._tag==="Success")n(s.value);else {let i=s.cause;i?._tag==="Fail"?r(i.error):r(new Error("Interrupted"));}});})}unsafeRun(e){this.unsafeRunAsync(e,()=>{});}delay(e,n){return d((r,a)=>{let s=setTimeout(()=>{this.unsafeRunAsync(n,a);},e);return ()=>clearTimeout(s)})}static make(e,n=T){return new t({env:e,scheduler:n})}log(e,n,r){this.emit({type:"log",level:e,message:n,fields:r});}};function rt(t,e){return P.make(e??{}).fork(t)}function Q(t,e,n){P.make(e??{}).unsafeRunAsync(t,n);}function at(t,e){return P.make(e??{}).toPromise(t)}function st(t,e){return {_tag:"Async",register:(n,r)=>{let a=new AbortController,s=false;return t(a.signal,n).then(i=>{s||(s=true,r(R.succeed(i)));}).catch(i=>{s||(s=true,r(R.failCause(g.fail(e(i)))));}),()=>{s||(s=true,a.abort(),r(R.failCause(g.interrupt())));}}}}function ie(t,e,n,r){Q(t,e,a=>{a._tag==="Failure"?n(a.cause):r(a.value);});}var j=null,v={CONTINUE:"Continue",SUSPEND:"Suspend",DONE:"Done"},F={QUEUED:"Queued",RUNNING:"Running",SUSPENDED:"Suspended",DONE:"Done"},he=1,oe=1024;function me(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 z=class{id;runtime;closing=null;finishing=false;runState=F.RUNNING;interrupted=false;result=null;joiners=[];current;stack=[];fiberFinalizers=[];finalizersDrained=false;fiberContext;name;scopeId;constructor(e,n){this.id=he++,this.runtime=e,this.current=n;}get env(){return this.runtime.env}get scheduler(){return this.runtime.scheduler??T}emit(e){this.runtime.hooks.emit(e,{fiberId:this.id,scopeId:this.scopeId,traceId:this.fiberContext?.trace?.traceId,spanId:this.fiberContext?.trace?.spanId});}addFinalizer(e){this.fiberFinalizers.push(e);}status(){return this.result==null?"Running":this.result._tag==="Failure"&&this.result.cause._tag==="Interrupt"?"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===F.DONE||this.runState===F.QUEUED||(this.runState===F.SUSPENDED&&this.emit({type:"fiber.resume",fiberId:this.id}),this.runState=F.QUEUED,this.scheduler.schedule(()=>{ge(this,()=>{if(this.runState===F.DONE)return;switch(this.runState=F.RUNNING,this.step()){case v.CONTINUE:this.schedule("continue");return;case v.SUSPEND:this.runState=F.SUSPENDED,this.emit({type:"fiber.suspend",fiberId:this.id});return;case v.DONE:this.runState=F.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{let r=n(e);r&&typeof r=="object"&&"_tag"in r&&Q(r,this.env,()=>{});}catch{}}}notify(e){if(this.result!=null||this.closing!=null)return;this.finishing=true,this.closing=e,this.runFinalizersOnce(e),this.result=e;let n=e._tag==="Success"?"success":e.cause._tag==="Interrupt"?"interrupted":"failure";this.emit({type:"fiber.end",fiberId:this.id,status:n,error:e._tag==="Failure"?e.cause:void 0});for(let r of this.joiners)r(e);this.joiners.length=0;}onSuccess(e){let n=this.stack.pop();if(!n){this.notify(R.succeed(e));return}if(n._tag==="SuccessCont"){try{this.current=n.k(e);}catch(r){this.notify(R.failCause(g.die(r)));}return}try{this.current=n.onSuccess(e);}catch(r){this.notify(R.failCause(g.die(r)));}}onFailure(e){for(;this.stack.length>0;){let n=this.stack.pop();if(n._tag==="FoldCont")try{this.current=n.onFailure(e);return}catch(r){e=r;continue}}this.notify(R.failCause(g.fail(e)));}budget=oe;step(){if(this.result!=null)return v.DONE;if(this.interrupted)return this.notify(R.failCause(g.interrupt())),v.DONE;for(this.budget=oe;this.budget-- >0;){this.current=me(this.current);let e=this.current;switch(e._tag){case "Succeed":{this.onSuccess(e.value);break}case "Fail":{this.onFailure(e.error);break}case "FlatMap":{this.stack.push({_tag:"SuccessCont",k:e.andThen}),this.current=e.first;break}case "Fold":{this.stack.push({_tag:"FoldCont",onFailure:e.onFailure,onSuccess:e.onSuccess}),this.current=e.first;break}case "Async":{if(this.finishing)return this.result!=null?v.DONE:v.CONTINUE;let n=false,r=s=>{if(n||(n=true,this.result!=null||this.closing!=null))return;if(s._tag==="Success"){this.current=W.succeed(s.value),this.schedule("async-resume");return}let i=s.cause;if(i._tag==="Interrupt"){this.notify(R.failCause(g.interrupt()));return}if(i._tag==="Fail"){this.current=W.fail(i.error),this.schedule("async-resume");return}this.notify(R.failCause(g.die(i.defect)));},a=e.register(this.env,r);return typeof a=="function"&&this.addFinalizer(()=>{n=true;try{a();}catch{}}),v.SUSPEND}case "Fork":{let n=this.runtime.fork(e.effect,e.scopeId);this.onSuccess(n);break}case "Sync":{try{let n=e.thunk(this.env);this.onSuccess(n);}catch(n){this.onFailure(n);}break}default:return this.onFailure(new Error(`Unknown opcode: ${e._tag}`)),v.CONTINUE}if(this.result!=null)return v.DONE}return v.CONTINUE}};function b(){return j}function B(){let t=b();if(!t?.runtime)throw new Error("unsafeGetCurrentRuntime: no current fiber/runtime");return t.runtime}function ge(t,e){let n=j;j=t;try{return e()}finally{j=n;}}var Se=1;function ve(t){return d((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});});})}var Z=class t{constructor(e,n){this.runtime=e;this.parentScopeId=n;this.id=Se++;let r=this.parentScopeId??b()?.scopeId;this.runtime.emit({type:"scope.open",scopeId:this.id,parentScopeId:r});}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.runtime,this.id);return this.subScopes.add(e),e}fork(e){if(this.closed)throw new Error("Scope closed");let n=this.runtime.fork(e,this.id);return this.children.add(n),n.join(()=>this.children.delete(n)),n}close(e={_tag:"Success",value:void 0}){this.runtime.fork(this.closeAsync(e));}closeAsync(e={_tag:"Success",value:void 0},n={awaitChildren:true}){return h(k(),()=>d((r,a)=>{if(this.closed){a({_tag:"Success",value:void 0});return}this.closed=true;let s=Array.from(this.children),o=Array.from(this.subScopes).reduceRight((y,u)=>h(y,()=>u.closeAsync(e,n)),k()),c=this.finalizers.reduceRight((y,u)=>h(y,()=>m(u(e),()=>k(),()=>k())),k()),l=n.awaitChildren?ve(s):k(),E=h(o,()=>h(l,()=>c));this.runtime.fork(E).join(()=>{let y=e._tag==="Success"?"success":e.cause._tag==="Interrupt"?"interrupted":"failure";this.runtime.emit({type:"scope.close",scopeId:this.id,status:y,error:e._tag==="Failure"&&e.cause._tag==="Fail"?e.cause.error:void 0}),a({_tag:"Success",value:void 0});});}))}};function xe(t,e){return d((n,r)=>{let a=new Z(t);t.fork(e(a)).join(s=>{t.fork(a.closeAsync(s)),r(s);});})}function ht(t,e){return xe(t,n=>{let r=e(n);return r&&typeof r=="object"&&"_tag"in r?r:k()})}function vt(t,e,n){return d((r,a)=>{let s=n.subScope(),i=false,o=E=>{i||(i=true,s.close(E),a(E));},c=s.fork(t),l=s.fork(e);c.join(o),l.join(o);})}function xt(t,e,n){return d((r,a)=>{let s=n.subScope(),i=null,o=null,c=false,l=()=>{if(!i||!o||c)return;if(c=true,i._tag==="Success"&&o._tag==="Success"){s.close({_tag:"Success",value:void 0}),a({_tag:"Success",value:[i.value,o.value]});return}let u;if(i._tag==="Failure")u=i.cause;else if(o._tag==="Failure")u=o.cause;else throw new Error("zipPar: unreachable state (no Failure exit)");let p={_tag:"Failure",cause:u};s.close(p),a(p);},E=s.fork(t),y=s.fork(e);E.join(u=>{i=u,l();}),y.join(u=>{o=u,l();});})}function bt(t,e){return d((n,r)=>{let a=e.subScope(),s=new Array(t.length),i=0,o=false;t.forEach((c,l)=>{a.fork(c).join(y=>{if(!o){if(y._tag==="Failure"){o=true;let u={_tag:"Failure",cause:y.cause};a.close(u),r(u);return}if(s[l]=y.value,i++,i===t.length){o=true;let u={_tag:"Success",value:s};a.close({_tag:"Success",value:void 0}),r(u);}}});});})}function ce(t,e,n,r,a){return d((s,i)=>{let o=n.subScope(),c=false,l=o.fork(t),E=o.fork(e),y=u=>{o.fork(u).join(p=>{o.close(p),i(p);});};l.join(u=>{c||(c=true,y(r(u,E,o)));}),E.join(u=>{c||(c=true,y(a(u,l,o)));});})}var K=t=>t._tag==="None"?C:w(t.value),x=t=>({_tag:"FromPull",pull:t}),le=(t,e)=>({_tag:"Scoped",acquire:t,release:e}),be=t=>({_tag:"Managed",acquire:t}),Fe=(t,e,n=true)=>({_tag:"Merge",left:t,right:e,flip:n}),V=()=>({_tag:"Empty"}),Ee=t=>({_tag:"Emit",value:t}),q=(t,e)=>({_tag:"Concat",left:t,right:e}),X=t=>({_tag:"Flatten",stream:t});function ue(t,e,n,r,a){return (s,i,o)=>{if(s._tag,s._tag,s._tag==="Success"){let[l,E]=s.value;i.interrupt();let y=x(t==="L"?H(E,n):H(e,E));return A([l,y])}if(s.cause._tag==="Interrupt")return d((l,E)=>{E(R.failCause(g.interrupt()));});let c=s.cause.error;return c._tag==="None"?f(t==="L"?n:e):S(c)}}function H(t,e,n,r){return d((a,s)=>{let o=B(),c=new Z(o),l=f(t),E=f(e),y=ue("L",t,e),u=ue("R",t,e),p=ce(l,E,c,y,u);c.fork(p).join(D=>{c.close(D),s(D);});})}function Dt(t,e){return x(H(t,e))}function f(t){switch(t._tag){case "Empty":return U(C);case "Emit":return I(L(t.value,e=>w(e)),e=>[e,V()]);case "FromPull":return t.pull;case "Concat":return J(I(f(t.left),([e,n])=>[e,q(n,t.right)]),()=>f(t.right));case "Flatten":return te(f(t.stream),([e,n])=>J(I(f(e),([r,a])=>[r,q(a,X(n))]),()=>f(X(n))));case "Merge":return H(t.left,t.right,t.flip);case "Scoped":return d((e,n)=>{let r=B(),a=new Z(r);b()?.addFinalizer(c=>{try{a.close(c);}catch{}});let i=c=>{if(c._tag==="Failure"){let l=c.cause.error;if(l&&typeof l=="object"&&l._tag==="None"){a.close({_tag:"Success",value:void 0});return}}a.close(c);},o=c=>x(d((l,E)=>{let y=f(c);ie(y,l,u=>{let p=R.failCause(u);i(p),E(p);},([u,p])=>{E(R.succeed([u,o(p)]));});}));a.fork(t.acquire).join(c=>{if(c._tag==="Failure"){i(c),n({_tag:"Failure",cause:{_tag:"Fail",error:w(c.cause.error)}});return}a.addFinalizer(E=>t.release(E));let l=c.value;B().fork(f(o(l))).join(n);});});case "Managed":return d((e,n)=>{let r=B(),a=new Z(r);b()?.addFinalizer(i=>{try{a.close(i);}catch{}});let s=i=>{if(i._tag==="Failure"){let o=i.cause.error;if(o&&typeof o=="object"&&o._tag==="None"){a.close({_tag:"Success",value:void 0});return}}a.close(i);};a.fork(t.acquire).join(i=>{if(i._tag==="Failure"){a.close(i),n({_tag:"Failure",cause:{_tag:"Fail",error:w(i.cause.error)}});return}let{stream:o,release:c}=i.value;a.addFinalizer(E=>c(E));let l=E=>x(d((y,u)=>{f(E)(y,p=>{if(p._tag==="Failure"){s(p),u(p);return}let[D,ye]=p.value;u(R.succeed([D,l(ye)]));});}));B().fork(f(l(o))).join(n);});})}}function _e(t,e){throw new Error(e??`Unexpected value: ${String(t)}`)}function _(t,e){switch(t._tag){case "Empty":return V();case "Emit":return Ee(I(t.value,e));case "FromPull":return x(I(t.pull,([n,r])=>[e(n),_(r,e)]));case "Concat":return q(_(t.left,e),_(t.right,e));case "Flatten":{let n=_(t.stream,r=>_(r,e));return X(n)}case "Merge":return Fe(_(t.left,e),_(t.right,e),t.flip);case "Scoped":return le(I(t.acquire,n=>_(n,e)),t.release);case "Managed":return be(I(t.acquire,({stream:n,release:r})=>({stream:_(n,e),release:r})));default:return _e(t)}}function Ut(t,e){let n=r=>x(r>e?S(C):A([r,n(r+1)]));return n(t)}function ke(t,e){let n=m(O(f(t),r=>K(r)),r=>S(r),([r,a])=>m(O(f(e),s=>K(s)),s=>S(s),([s,i])=>A([[r,s],ke(a,i)])));return x(n)}function Mt(t,e){let n=r=>m(O(f(r),a=>K(a)),a=>a._tag==="None"?A(void 0):S(a),([a,s])=>h(O(e(a),i=>w(i)),()=>n(s)));return m(n(t),r=>r._tag==="None"?A(void 0):S(r.value),()=>A(void 0))}function zt(t){let e=V();for(let n=t.length-1;n>=0;n--){let r=Ee(G(t[n]));e=q(r,e);}return e}function jt(t){let e=(n,r)=>m(f(n),a=>a._tag==="None"?G(r):U(a),([a,s])=>e(s,[...r,a]));return L(e(t,[]),n=>{if(n._tag==="Some")return n.value;throw new Error("unreachable: stream end handled as success")})}function Ie(t,e){let n=d((r,a)=>{t.read().then(({done:s,value:i})=>{if(s){a({_tag:"Failure",cause:{_tag:"Fail",error:C}});return}a({_tag:"Success",value:[i,x(n)]});}).catch(s=>{a({_tag:"Failure",cause:{_tag:"Fail",error:w(e(s))}});});});return x(n)}function qt(t,e){if(!t)return V();let n;return le(ee(()=>(n=t.getReader(),Ie(n,e))),()=>N(()=>{try{n?.cancel();}catch{}}))}exports.$=le;exports.A=L;exports.B=ze;exports.C=J;exports.D=je;exports.E=de;exports.F=M;exports.G=$;exports.H=T;exports.I=z;exports.J=b;exports.K=B;exports.L=ge;exports.M=P;exports.N=rt;exports.O=Q;exports.P=at;exports.Q=st;exports.R=ie;exports.S=Z;exports.T=xe;exports.U=ht;exports.V=vt;exports.W=xt;exports.X=bt;exports.Y=ce;exports.Z=K;exports._=x;exports.a=W;exports.aa=be;exports.b=m;exports.ba=Fe;exports.c=Oe;exports.ca=V;exports.d=O;exports.da=Ee;exports.e=k;exports.ea=q;exports.f=A;exports.fa=X;exports.g=S;exports.ga=Dt;exports.h=N;exports.ha=f;exports.i=Ce;exports.ia=_e;exports.j=d;exports.ja=_;exports.k=Y;exports.ka=Ut;exports.l=h;exports.la=ke;exports.m=we;exports.ma=Mt;exports.n=Ze;exports.na=zt;exports.o=Ne;exports.oa=jt;exports.p=Be;exports.pa=qt;exports.q=Te;exports.r=C;exports.s=w;exports.t=g;exports.u=R;exports.v=G;exports.w=U;exports.x=ee;exports.y=I;exports.z=te;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var W={succeed:t=>({_tag:"Succeed",value:t}),fail:t=>({_tag:"Fail",error:t}),sync:t=>({_tag:"Sync",thunk:t}),async:t=>({_tag:"Async",register:t})};function m(t,e,n){return {_tag:"Fold",first:t,onFailure:e,onSuccess:n}}function Oe(t,e){return m(t,n=>e(n),n=>A(n))}function O(t,e){return m(t,n=>S(e(n)),n=>A(n))}var k=()=>A(void 0),A=t=>({_tag:"Succeed",value:t}),S=t=>({_tag:"Fail",error:t}),N=t=>({_tag:"Sync",thunk:t}),Ce=t=>N(()=>t()),d=t=>({_tag:"Async",register:t});function Y(t,e){return h(t,n=>A(e(n)))}function h(t,e){return {_tag:"FlatMap",first:t,andThen:e}}function we(t,e,n){return h(t,r=>(n.addFinalizer(a=>e(r,a)),A(r)))}function Ze(t){return d(t)}var Ne=t=>e=>{let n=e;return n.toPromise||(n.toPromise=r=>t(e,r),n.unsafeRunPromise=()=>t(e,{})),n},Be=(t,e)=>h(t,n=>A(e(n))),Te=(t,e)=>h(t,n=>N(()=>e(n)));var C={_tag:"None"},w=t=>({_tag:"Some",value:t});var g={fail:t=>({_tag:"Fail",error:t}),interrupt:()=>({_tag:"Interrupt"}),die:t=>({_tag:"Die",defect:t})},R={succeed:t=>({_tag:"Success",value:t}),failCause:t=>({_tag:"Failure",cause:t})},G=t=>A(t),U=t=>S(t),ee=t=>N(e=>t(e)),I=(t,e)=>Y(t,e),te=(t,e)=>h(t,n=>e(n)),L=(t,e)=>O(t,e),ze=(t,e)=>m(t,n=>e(n),n=>A(n));function J(t,e){return m(t,n=>n._tag==="Some"?S(n):e(),n=>A(n))}var je=()=>U(C);var de=(r=>(r[r.Ok=0]="Ok",r[r.Grew=1]="Grew",r[r.Dropped=2]="Dropped",r))(de||{}),M=class{buf;head=0;tail=0;size_=0;maxCap;constructor(e=1024,n=e){let r=Math.max(2,this.nextPow2(e)),a=Math.max(r,this.nextPow2(n));this.buf=new Array(r),this.maxCap=a;}get length(){return this.size_}get capacity(){return this.buf.length}isEmpty(){return this.size_===0}push(e){return this.size_===this.buf.length?this.buf.length>=this.maxCap?2:(this.grow(),this.buf[this.tail]=e,this.tail=this.tail+1&this.buf.length-1,this.size_++,1):(this.buf[this.tail]=e,this.tail=this.tail+1&this.buf.length-1,this.size_++,0)}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=Math.min(e.length*2,this.maxCap),r=new Array(n);for(let a=0;a<this.size_;a++)r[a]=e[this.head+a&e.length-1];this.buf=r,this.head=0,this.tail=this.size_;}nextPow2(e){let n=1;for(;n<e;)n<<=1;return n}};var ne=2048,re=4096,pe=(()=>{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)})(),$=class{queue=new M(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>re?"macro":"micro";this.requestFlush(r);}}requestFlush(e){e==="micro"?queueMicrotask(()=>this.flush()):pe(()=>this.flush());}flush(){if(this.flushing)return;this.flushing=true,this.scheduled=false;let e=0;try{for(;e<ne;){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>=ne||this.queue.length>re?"macro":"micro";this.requestFlush(n);}}}},T=new $;var ae={parent:null,patch:Object.create(null)};function se(t,e){let n=Ae(t);return {initChild(r,a,s){let i=a?.fiberContext,o=Re(n,i?.trace??null);r.fiberContext={log:i?.log??ae,trace:o},r.parentFiberId=a?.id,r.name=n.childName(a?.name),s!==void 0&&(r.scopeId=s),e.emit({type:"fiber.start",fiberId:r.id,parentFiberId:a?.id,scopeId:r.scopeId,name:r.name},{fiberId:a?.id,traceId:i?.trace?.traceId,spanId:i?.trace?.spanId});}}}function Ae(t){let e={newTraceId:()=>crypto.randomUUID(),newSpanId:()=>crypto.randomUUID()},n=t?.brass,r=n?.tracer??e,a=n?.traceSeed,s=n?.childName??(i=>i?`${i}/child`:void 0);return {tracer:r,seed:a,childName:s}}function Re(t,e){return e?{traceId:e.traceId,spanId:t.tracer.newSpanId(),parentSpanId:e.spanId,sampled:e.sampled}:t.seed?{...t.seed}:{traceId:t.tracer.newTraceId(),spanId:t.tracer.newSpanId(),sampled:true}}var fe={emit(){}},P=class t{env;scheduler;hooks;forkPolicy;registry;constructor(e){this.env=e.env,this.scheduler=e.scheduler??T,this.hooks=e.hooks??fe,this.forkPolicy=se(this.env,this.hooks);}provide(e){return new t({env:Object.assign({},this.env,e),scheduler:this.scheduler,hooks:this.hooks})}emit(e){let n=b(),r={fiberId:n?.id,scopeId:n?.scopeId,traceId:n?.fiberContext?.trace?.traceId,spanId:n?.fiberContext?.trace?.spanId};this.hooks.emit(e,r);}fork(e,n){let r=b(),a=new z(this,e);return n!==void 0&&(a.scopeId=n),this.forkPolicy.initChild(a,r,n),a.schedule("initial-step"),a}unsafeRunAsync(e,n){this.fork(e).join(n);}toPromise(e){return new Promise((n,r)=>{this.fork(e).join(s=>{if(s._tag==="Success")n(s.value);else {let i=s.cause;i?._tag==="Fail"?r(i.error):r(new Error("Interrupted"));}});})}unsafeRun(e){this.unsafeRunAsync(e,()=>{});}delay(e,n){return d((r,a)=>{let s=setTimeout(()=>{this.unsafeRunAsync(n,a);},e);return ()=>clearTimeout(s)})}static make(e,n=T){return new t({env:e,scheduler:n})}log(e,n,r){this.emit({type:"log",level:e,message:n,fields:r});}};function rt(t,e){return P.make(e??{}).fork(t)}function Q(t,e,n){P.make(e??{}).unsafeRunAsync(t,n);}function at(t,e){return P.make(e??{}).toPromise(t)}function st(t,e){return {_tag:"Async",register:(n,r)=>{let a=new AbortController,s=false;return t(a.signal,n).then(i=>{s||(s=true,r(R.succeed(i)));}).catch(i=>{s||(s=true,r(R.failCause(g.fail(e(i)))));}),()=>{s||(s=true,a.abort(),r(R.failCause(g.interrupt())));}}}}function ie(t,e,n,r){Q(t,e,a=>{a._tag==="Failure"?n(a.cause):r(a.value);});}var j=null,v={CONTINUE:"Continue",SUSPEND:"Suspend",DONE:"Done"},F={QUEUED:"Queued",RUNNING:"Running",SUSPENDED:"Suspended",DONE:"Done"},he=1,oe=1024;function me(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 z=class{id;runtime;closing=null;finishing=false;runState=F.RUNNING;interrupted=false;result=null;joiners=[];current;stack=[];fiberFinalizers=[];finalizersDrained=false;fiberContext;name;scopeId;constructor(e,n){this.id=he++,this.runtime=e,this.current=n;}get env(){return this.runtime.env}get scheduler(){return this.runtime.scheduler??T}emit(e){this.runtime.hooks.emit(e,{fiberId:this.id,scopeId:this.scopeId,traceId:this.fiberContext?.trace?.traceId,spanId:this.fiberContext?.trace?.spanId});}addFinalizer(e){this.fiberFinalizers.push(e);}status(){return this.result==null?"Running":this.result._tag==="Failure"&&this.result.cause._tag==="Interrupt"?"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===F.DONE||this.runState===F.QUEUED||(this.runState===F.SUSPENDED&&this.emit({type:"fiber.resume",fiberId:this.id}),this.runState=F.QUEUED,this.scheduler.schedule(()=>{ge(this,()=>{if(this.runState===F.DONE)return;switch(this.runState=F.RUNNING,this.step()){case v.CONTINUE:this.schedule("continue");return;case v.SUSPEND:this.runState=F.SUSPENDED,this.emit({type:"fiber.suspend",fiberId:this.id});return;case v.DONE:this.runState=F.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{let r=n(e);r&&typeof r=="object"&&"_tag"in r&&Q(r,this.env,()=>{});}catch{}}}notify(e){if(this.result!=null||this.closing!=null)return;this.finishing=true,this.closing=e,this.runFinalizersOnce(e),this.result=e;let n=e._tag==="Success"?"success":e.cause._tag==="Interrupt"?"interrupted":"failure";this.emit({type:"fiber.end",fiberId:this.id,status:n,error:e._tag==="Failure"?e.cause:void 0});for(let r of this.joiners)r(e);this.joiners.length=0;}onSuccess(e){let n=this.stack.pop();if(!n){this.notify(R.succeed(e));return}if(n._tag==="SuccessCont"){try{this.current=n.k(e);}catch(r){this.notify(R.failCause(g.die(r)));}return}try{this.current=n.onSuccess(e);}catch(r){this.notify(R.failCause(g.die(r)));}}onFailure(e){for(;this.stack.length>0;){let n=this.stack.pop();if(n._tag==="FoldCont")try{this.current=n.onFailure(e);return}catch(r){e=r;continue}}this.notify(R.failCause(g.fail(e)));}budget=oe;step(){if(this.result!=null)return v.DONE;if(this.interrupted)return this.notify(R.failCause(g.interrupt())),v.DONE;for(this.budget=oe;this.budget-- >0;){this.current=me(this.current);let e=this.current;switch(e._tag){case "Succeed":{this.onSuccess(e.value);break}case "Fail":{this.onFailure(e.error);break}case "FlatMap":{this.stack.push({_tag:"SuccessCont",k:e.andThen}),this.current=e.first;break}case "Fold":{this.stack.push({_tag:"FoldCont",onFailure:e.onFailure,onSuccess:e.onSuccess}),this.current=e.first;break}case "Async":{if(this.finishing)return this.result!=null?v.DONE:v.CONTINUE;let n=false,r=s=>{if(n||(n=true,this.result!=null||this.closing!=null))return;if(s._tag==="Success"){this.current=W.succeed(s.value),this.schedule("async-resume");return}let i=s.cause;if(i._tag==="Interrupt"){this.notify(R.failCause(g.interrupt()));return}if(i._tag==="Fail"){this.current=W.fail(i.error),this.schedule("async-resume");return}this.notify(R.failCause(g.die(i.defect)));},a=e.register(this.env,r);return typeof a=="function"&&this.addFinalizer(()=>{n=true;try{a();}catch{}}),v.SUSPEND}case "Fork":{let n=this.runtime.fork(e.effect,e.scopeId);this.onSuccess(n);break}case "Sync":{try{let n=e.thunk(this.env);this.onSuccess(n);}catch(n){this.onFailure(n);}break}default:return this.onFailure(new Error(`Unknown opcode: ${e._tag}`)),v.CONTINUE}if(this.result!=null)return v.DONE}return v.CONTINUE}};function b(){return j}function B(){let t=b();if(!t?.runtime)throw new Error("unsafeGetCurrentRuntime: no current fiber/runtime");return t.runtime}function ge(t,e){let n=j;j=t;try{return e()}finally{j=n;}}var Se=1;function ve(t){return d((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});});})}var Z=class t{constructor(e,n){this.runtime=e;this.parentScopeId=n;this.id=Se++;let r=this.parentScopeId??b()?.scopeId;this.runtime.emit({type:"scope.open",scopeId:this.id,parentScopeId:r});}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.runtime,this.id);return this.subScopes.add(e),e}fork(e){if(this.closed)throw new Error("Scope closed");let n=this.runtime.fork(e,this.id);return this.children.add(n),n.join(()=>this.children.delete(n)),n}close(e={_tag:"Success",value:void 0}){this.runtime.fork(this.closeAsync(e));}closeAsync(e={_tag:"Success",value:void 0},n={awaitChildren:true}){return h(k(),()=>d((r,a)=>{if(this.closed){a({_tag:"Success",value:void 0});return}this.closed=true;let s=Array.from(this.children),o=Array.from(this.subScopes).reduceRight((y,u)=>h(y,()=>u.closeAsync(e,n)),k()),c=this.finalizers.reduceRight((y,u)=>h(y,()=>m(u(e),()=>k(),()=>k())),k()),l=n.awaitChildren?ve(s):k(),E=h(o,()=>h(l,()=>c));this.runtime.fork(E).join(()=>{let y=e._tag==="Success"?"success":e.cause._tag==="Interrupt"?"interrupted":"failure";this.runtime.emit({type:"scope.close",scopeId:this.id,status:y,error:e._tag==="Failure"&&e.cause._tag==="Fail"?e.cause.error:void 0}),a({_tag:"Success",value:void 0});});}))}};function xe(t,e){return d((n,r)=>{let a=new Z(t);t.fork(e(a)).join(s=>{t.fork(a.closeAsync(s)),r(s);});})}function ht(t,e){return xe(t,n=>{let r=e(n);return r&&typeof r=="object"&&"_tag"in r?r:k()})}function vt(t,e,n){return d((r,a)=>{let s=n.subScope(),i=false,o=E=>{i||(i=true,s.close(E),a(E));},c=s.fork(t),l=s.fork(e);c.join(o),l.join(o);})}function xt(t,e,n){return d((r,a)=>{let s=n.subScope(),i=null,o=null,c=false,l=()=>{if(!i||!o||c)return;if(c=true,i._tag==="Success"&&o._tag==="Success"){s.close({_tag:"Success",value:void 0}),a({_tag:"Success",value:[i.value,o.value]});return}let u;if(i._tag==="Failure")u=i.cause;else if(o._tag==="Failure")u=o.cause;else throw new Error("zipPar: unreachable state (no Failure exit)");let p={_tag:"Failure",cause:u};s.close(p),a(p);},E=s.fork(t),y=s.fork(e);E.join(u=>{i=u,l();}),y.join(u=>{o=u,l();});})}function bt(t,e){return d((n,r)=>{let a=e.subScope(),s=new Array(t.length),i=0,o=false;t.forEach((c,l)=>{a.fork(c).join(y=>{if(!o){if(y._tag==="Failure"){o=true;let u={_tag:"Failure",cause:y.cause};a.close(u),r(u);return}if(s[l]=y.value,i++,i===t.length){o=true;let u={_tag:"Success",value:s};a.close({_tag:"Success",value:void 0}),r(u);}}});});})}function ce(t,e,n,r,a){return d((s,i)=>{let o=n.subScope(),c=false,l=o.fork(t),E=o.fork(e),y=u=>{o.fork(u).join(p=>{o.close(p),i(p);});};l.join(u=>{c||(c=true,y(r(u,E,o)));}),E.join(u=>{c||(c=true,y(a(u,l,o)));});})}var K=t=>t._tag==="None"?C:w(t.value),x=t=>({_tag:"FromPull",pull:t}),le=(t,e)=>({_tag:"Scoped",acquire:t,release:e}),be=t=>({_tag:"Managed",acquire:t}),Fe=(t,e,n=true)=>({_tag:"Merge",left:t,right:e,flip:n}),V=()=>({_tag:"Empty"}),Ee=t=>({_tag:"Emit",value:t}),q=(t,e)=>({_tag:"Concat",left:t,right:e}),X=t=>({_tag:"Flatten",stream:t});function ue(t,e,n,r,a){return (s,i,o)=>{if(s._tag,s._tag,s._tag==="Success"){let[l,E]=s.value;i.interrupt();let y=x(t==="L"?H(E,n):H(e,E));return A([l,y])}if(s.cause._tag==="Interrupt")return d((l,E)=>{E(R.failCause(g.interrupt()));});let c=s.cause.error;return c._tag==="None"?f(t==="L"?n:e):S(c)}}function H(t,e,n,r){return d((a,s)=>{let o=B(),c=new Z(o),l=f(t),E=f(e),y=ue("L",t,e),u=ue("R",t,e),p=ce(l,E,c,y,u);c.fork(p).join(D=>{c.close(D),s(D);});})}function Dt(t,e){return x(H(t,e))}function f(t){switch(t._tag){case "Empty":return U(C);case "Emit":return I(L(t.value,e=>w(e)),e=>[e,V()]);case "FromPull":return t.pull;case "Concat":return J(I(f(t.left),([e,n])=>[e,q(n,t.right)]),()=>f(t.right));case "Flatten":return te(f(t.stream),([e,n])=>J(I(f(e),([r,a])=>[r,q(a,X(n))]),()=>f(X(n))));case "Merge":return H(t.left,t.right,t.flip);case "Scoped":return d((e,n)=>{let r=B(),a=new Z(r);b()?.addFinalizer(c=>{try{a.close(c);}catch{}});let i=c=>{if(c._tag==="Failure"){let l=c.cause.error;if(l&&typeof l=="object"&&l._tag==="None"){a.close({_tag:"Success",value:void 0});return}}a.close(c);},o=c=>x(d((l,E)=>{let y=f(c);ie(y,l,u=>{let p=R.failCause(u);i(p),E(p);},([u,p])=>{E(R.succeed([u,o(p)]));});}));a.fork(t.acquire).join(c=>{if(c._tag==="Failure"){i(c),n({_tag:"Failure",cause:{_tag:"Fail",error:w(c.cause.error)}});return}a.addFinalizer(E=>t.release(E));let l=c.value;B().fork(f(o(l))).join(n);});});case "Managed":return d((e,n)=>{let r=B(),a=new Z(r);b()?.addFinalizer(i=>{try{a.close(i);}catch{}});let s=i=>{if(i._tag==="Failure"){let o=i.cause.error;if(o&&typeof o=="object"&&o._tag==="None"){a.close({_tag:"Success",value:void 0});return}}a.close(i);};a.fork(t.acquire).join(i=>{if(i._tag==="Failure"){a.close(i),n({_tag:"Failure",cause:{_tag:"Fail",error:w(i.cause.error)}});return}let{stream:o,release:c}=i.value;a.addFinalizer(E=>c(E));let l=E=>x(d((y,u)=>{f(E)(y,p=>{if(p._tag==="Failure"){s(p),u(p);return}let[D,ye]=p.value;u(R.succeed([D,l(ye)]));});}));B().fork(f(l(o))).join(n);});})}}function _e(t,e){throw new Error(e??`Unexpected value: ${String(t)}`)}function _(t,e){switch(t._tag){case "Empty":return V();case "Emit":return Ee(I(t.value,e));case "FromPull":return x(I(t.pull,([n,r])=>[e(n),_(r,e)]));case "Concat":return q(_(t.left,e),_(t.right,e));case "Flatten":{let n=_(t.stream,r=>_(r,e));return X(n)}case "Merge":return Fe(_(t.left,e),_(t.right,e),t.flip);case "Scoped":return le(I(t.acquire,n=>_(n,e)),t.release);case "Managed":return be(I(t.acquire,({stream:n,release:r})=>({stream:_(n,e),release:r})));default:return _e(t)}}function Ut(t,e){let n=r=>x(r>e?S(C):A([r,n(r+1)]));return n(t)}function ke(t,e){let n=m(O(f(t),r=>K(r)),r=>S(r),([r,a])=>m(O(f(e),s=>K(s)),s=>S(s),([s,i])=>A([[r,s],ke(a,i)])));return x(n)}function Mt(t,e){let n=r=>m(O(f(r),a=>K(a)),a=>a._tag==="None"?A(void 0):S(a),([a,s])=>h(O(e(a),i=>w(i)),()=>n(s)));return m(n(t),r=>r._tag==="None"?A(void 0):S(r.value),()=>A(void 0))}function zt(t){let e=V();for(let n=t.length-1;n>=0;n--){let r=Ee(G(t[n]));e=q(r,e);}return e}function jt(t){let e=(n,r)=>m(f(n),a=>a._tag==="None"?G(r):U(a),([a,s])=>e(s,[...r,a]));return L(e(t,[]),n=>{if(n._tag==="Some")return n.value;throw new Error("unreachable: stream end handled as success")})}function Ie(t,e){let n=d((r,a)=>{t.read().then(({done:s,value:i})=>{if(s){a({_tag:"Failure",cause:{_tag:"Fail",error:C}});return}a({_tag:"Success",value:[i,x(n)]});}).catch(s=>{a({_tag:"Failure",cause:{_tag:"Fail",error:w(e(s))}});});});return x(n)}function qt(t,e){if(!t)return V();let n;return le(ee(()=>(n=t.getReader(),Ie(n,e))),()=>N(()=>{try{n?.cancel();}catch{}}))}export{le as $,L as A,ze as B,J as C,je as D,de as E,M as F,$ as G,T as H,z as I,b as J,B as K,ge as L,P as M,rt as N,Q as O,at as P,st as Q,ie as R,Z as S,xe as T,ht as U,vt as V,xt as W,bt as X,ce as Y,K as Z,x as _,W as a,be as aa,m as b,Fe as ba,Oe as c,V as ca,O as d,Ee as da,k as e,q as ea,A as f,X as fa,S as g,Dt as ga,N as h,f as ha,Ce as i,_e as ia,d as j,_ as ja,Y as k,Ut as ka,h as l,ke as la,we as m,Mt as ma,Ze as n,zt as na,Ne as o,jt as oa,Be as p,qt as pa,Te as q,C as r,w as s,g as t,R as u,G as v,U as w,ee as x,I as y,te as z};
|
package/dist/http/index.d.mts
CHANGED
package/dist/http/index.d.ts
CHANGED
package/dist/http/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
'use strict';var
|
|
1
|
+
'use strict';var chunk5PIZGM6Q_js=require('../chunk-5PIZGM6Q.js');var b={make(t,e){return {get:t,set:e}},over(t,e){return r=>t.set(e(t.get(r)))(r)},compose(t,e){return b.make(r=>t.get(e.get(r)),r=>n=>e.set(t.set(r)(e.get(n)))(n))}};var A={headers:b.make(t=>t.headers??{},t=>e=>({...e,headers:t}))};var I=t=>e=>b.over(A.headers,r=>({...r,...t}))(e),C=t=>e=>b.over(A.headers,r=>({...t,...r}))(e),g=(t,e)=>r=>b.over(A.headers,n=>n[t]?n:{...n,[t]:e})(r);var v=t=>typeof t=="object"&&t!==null&&"_tag"in t,J=t=>v(t)?t:typeof t=="object"&&t!==null&&t.name==="AbortError"?{_tag:"Abort"}:{_tag:"FetchError",message:String(t)},M=t=>chunk5PIZGM6Q_js.Q(e=>new Promise((r,n)=>{if(e.aborted)return n({_tag:"Abort"});let u=setTimeout(r,t),p=()=>{clearTimeout(u),n({_tag:"Abort"});};e.addEventListener("abort",p,{once:true});}),J);var lt=t=>e=>T(t(e)),T=t=>Object.assign((e=>t(e)),{with:e=>T(e(t))}),O=t=>t instanceof DOMException&&t.name==="AbortError"?{_tag:"Abort"}:typeof t=="object"&&t&&"_tag"in t?t:{_tag:"FetchError",message:String(t)},k=t=>{if(t){if(typeof Headers<"u"&&t instanceof Headers){let e={};return t.forEach((r,n)=>e[n]=r),e}if(Array.isArray(t))return Object.fromEntries(t);if(typeof t=="object")return {...t}}},D=t=>e=>{let r=Object.keys(t).length?C(t)(e):e,n=k(e.init?.headers);return n&&Object.keys(n).length&&(r=C(n)(r)),r};function N(t={}){let e=t.baseUrl??"",r=t.headers??{},n=D(r);return u=>chunk5PIZGM6Q_js.Q(async p=>{let y=n(u),i;try{i=new URL(y.url,e);}catch{throw {_tag:"BadUrl",message:`URL inv\xE1lida: ${y.url}`}}let a=performance.now(),s=await fetch(i,{...y.init??{},method:y.method,headers:A.headers.get(y),body:y.body,signal:p}),c={};s.headers.forEach((d,m)=>c[m]=d);let o=chunk5PIZGM6Q_js.pa(s.body,O);return {status:s.status,statusText:s.statusText,headers:c,body:o,ms:Math.round(performance.now()-a)}},O)}function _(t={}){let e=t.baseUrl??"",r=t.headers??{},n=D(r);return T(p=>chunk5PIZGM6Q_js.Q(async y=>{let i=n(p),a;try{a=new URL(i.url,e);}catch{throw {_tag:"BadUrl",message:`URL inv\xE1lida: ${i.url}`}}let s=performance.now(),c=await fetch(a,{...i.init??{},method:i.method,headers:A.headers.get(i),body:i.body,signal:y}),o=await c.text(),d={};return c.headers.forEach((m,H)=>d[H]=m),{status:c.status,statusText:c.statusText,headers:d,bodyText:o,ms:Math.round(performance.now()-s)}},O))}var G=(t,e,r)=>Math.max(e,Math.min(r,t)),z=t=>t._tag==="FetchError",Z=t=>t===408||t===429||t===500||t===502||t===503||t===504,F=(t,e,r)=>{let n=e*Math.pow(2,t),u=G(n,0,r);return Math.floor(Math.random()*u)},$=t=>{let e=Object.keys(t).find(p=>p.toLowerCase()==="retry-after");if(!e)return;let r=t[e]?.trim();if(!r)return;let n=Number(r);if(Number.isFinite(n))return Math.max(0,Math.floor(n*1e3));let u=Date.parse(r);if(Number.isFinite(u))return Math.max(0,u-Date.now())},U=t=>e=>(r=>{let n=u=>chunk5PIZGM6Q_js.b(e(r),p=>{if(p._tag==="Abort"||p._tag==="BadUrl")return chunk5PIZGM6Q_js.g(p);if(!(u<t.maxRetries&&(t.retryOnError??z)(p)))return chunk5PIZGM6Q_js.g(p);let i=F(u,t.baseDelayMs,t.maxDelayMs);return chunk5PIZGM6Q_js.l(M(i),()=>n(u+1))},p=>{if(!(u<t.maxRetries&&(t.retryOnStatus??Z)(p.status)))return chunk5PIZGM6Q_js.f(p);let a=$(p.headers)??F(u,t.baseDelayMs,t.maxDelayMs);return chunk5PIZGM6Q_js.l(M(a),()=>n(u+1))});return n(0)});var K=["GET","HEAD","OPTIONS"],Q=t=>t===408||t===429||t===500||t===502||t===503||t===504,V=t=>t._tag==="FetchError";var X=(t,e,r)=>Math.max(e,Math.min(r,t)),L=(t,e,r)=>{let n=Math.max(0,e),u=Math.max(0,r),p=n*Math.pow(2,t),y=X(p,0,u);return Math.floor(Math.random()*y)},Y=(t,e)=>{let r=Object.keys(t).find(n=>n.toLowerCase()===e.toLowerCase());return r?t[r]:void 0},tt=t=>{let e=Y(t,"retry-after")?.trim();if(!e)return;let r=Number(e);if(Number.isFinite(r))return Math.max(0,Math.floor(r*1e3));let n=Date.parse(e);if(Number.isFinite(n))return Math.max(0,n-Date.now())},j=t=>e=>{let r=t.retryOnMethods??K,n=t.retryOnStatus??Q,u=t.retryOnError??V,p=i=>r.includes(i.method),y=(i,a)=>p(i)?chunk5PIZGM6Q_js.b(e(i),s=>{if(s._tag==="Abort"||s._tag==="BadUrl")return chunk5PIZGM6Q_js.g(s);if(!(a<t.maxRetries&&u(s)))return chunk5PIZGM6Q_js.g(s);let o=L(a,t.baseDelayMs,t.maxDelayMs);return chunk5PIZGM6Q_js.l(M(o),()=>y(i,a+1))},s=>{if(!(a<t.maxRetries&&n(s.status)))return chunk5PIZGM6Q_js.f(s);let d=tt(s.headers)??L(a,t.baseDelayMs,t.maxDelayMs);return chunk5PIZGM6Q_js.l(M(d),()=>y(i,a+1))}):e(i);return i=>y(i,0)};var et=(t,e)=>{try{return new URL(e,t??"").toString()}catch{return (t??"")+e}},B=(t={})=>{let e=_(t),r=a=>chunk5PIZGM6Q_js.o((s,c)=>chunk5PIZGM6Q_js.P(s,c))(a),n=a=>e(a),u=a=>{let{headers:s,...c}=a??{};return {headers:k(s),init:c}},p=a=>s=>a?I(a)(s):s;return {cfg:t,wire:e,withPromise:r,requestRaw:n,splitInit:u,applyInitHeaders:p,buildReq:(a,s,c,o)=>{let d=u(c),m={method:a,url:s,...o&&o.length>0?{body:o}:{},init:d.init};return p(d.headers)(m)},toResponse:(a,s)=>({status:a.status,statusText:a.statusText,headers:a.headers,body:s})}};function _t(t={}){let e=B(t),r=n=>{let u=o=>n(o),p=o=>e.withPromise(u(o));return {request:p,get:(o,d)=>p(e.buildReq("GET",o,d)),post:(o,d,m)=>p(e.buildReq("POST",o,m,d)),getText:(o,d)=>{let m=e.buildReq("GET",o,d);return e.withPromise(chunk5PIZGM6Q_js.q(u(m),H=>e.toResponse(H,H.bodyText)))},getJson:(o,d)=>{let m=e.buildReq("GET",o,d),H=g("accept","application/json")(m);return e.withPromise(chunk5PIZGM6Q_js.q(u(H),l=>e.toResponse(l,JSON.parse(l.bodyText))))},postJson:(o,d,m)=>{let H=e.buildReq("POST",o,m,JSON.stringify(d??{})),l=g("content-type","application/json")(g("accept","application/json")(H));return e.withPromise(chunk5PIZGM6Q_js.q(u(l),P=>e.toResponse(P,JSON.parse(P.bodyText))))},with:o=>r(n.with(o)),withRetry:o=>r(n.with(j(o))),wire:n}};return r(e.wire)}function Ut(t={}){let e=B(t),r=(s,c,o)=>({request:s,urlFinal:et(e.cfg.baseUrl,s.url),startedAt:o,durationMs:c.ms}),n=s=>{let c=Date.now();return e.withPromise(chunk5PIZGM6Q_js.q(e.requestRaw(s),o=>({wire:o,meta:r(s,o,c)})))};return {request:n,get:(s,c)=>{let o=e.buildReq("GET",s,c);return n(o)},getText:(s,c)=>{let o=e.buildReq("GET",s,c),d=Date.now();return e.withPromise(chunk5PIZGM6Q_js.q(e.requestRaw(o),m=>({wire:m,response:e.toResponse(m,m.bodyText),meta:r(o,m,d)})))},getJson:(s,c)=>{let o=e.buildReq("GET",s,c),d=g("accept","application/json")(o),m=Date.now();return e.withPromise(chunk5PIZGM6Q_js.q(e.requestRaw(d),H=>({wire:H,response:e.toResponse(H,JSON.parse(H.bodyText)),meta:r(d,H,m)})))},post:(s,c,o)=>{let d=e.buildReq("POST",s,o,c);return n(d)},postJson:(s,c,o)=>{let d=e.buildReq("POST",s,o,JSON.stringify(c??{})),m=g("content-type","application/json")(g("accept","application/json")(d)),H=Date.now();return e.withPromise(chunk5PIZGM6Q_js.q(e.requestRaw(m),l=>({wire:l,response:e.toResponse(l,JSON.parse(l.bodyText)),meta:r(m,l,H)})))}}}function Lt(t={}){let e=N(t),r=n=>{let u=i=>chunk5PIZGM6Q_js.o((a,s)=>chunk5PIZGM6Q_js.P(a,s))(i),p=i=>u(n(i)),y=(i,a)=>{let s={method:"GET",url:i,init:a},c=g("accept","*/*")(s);return p(c)};return {request:p,getStream:y,get:y,with:i=>r(i(n)),withRetry:i=>r(U(i)(n)),wire:n}};return r(e)}exports.decorate=T;exports.httpClient=_t;exports.httpClientStream=Lt;exports.httpClientWithMeta=Ut;exports.makeHttp=_;exports.makeHttpStream=N;exports.normalizeHeadersInit=k;exports.withMiddleware=lt;exports.withRetryStream=U;
|
package/dist/http/index.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import {Q as Q$1,pa,
|
|
1
|
+
import {Q as Q$1,pa,b as b$1,q,o,g as g$1,l,f,P}from'../chunk-CNA5AQHG.mjs';var b={make(t,e){return {get:t,set:e}},over(t,e){return r=>t.set(e(t.get(r)))(r)},compose(t,e){return b.make(r=>t.get(e.get(r)),r=>n=>e.set(t.set(r)(e.get(n)))(n))}};var A={headers:b.make(t=>t.headers??{},t=>e=>({...e,headers:t}))};var I=t=>e=>b.over(A.headers,r=>({...r,...t}))(e),C=t=>e=>b.over(A.headers,r=>({...t,...r}))(e),g=(t,e)=>r=>b.over(A.headers,n=>n[t]?n:{...n,[t]:e})(r);var v=t=>typeof t=="object"&&t!==null&&"_tag"in t,J=t=>v(t)?t:typeof t=="object"&&t!==null&&t.name==="AbortError"?{_tag:"Abort"}:{_tag:"FetchError",message:String(t)},M=t=>Q$1(e=>new Promise((r,n)=>{if(e.aborted)return n({_tag:"Abort"});let u=setTimeout(r,t),p=()=>{clearTimeout(u),n({_tag:"Abort"});};e.addEventListener("abort",p,{once:true});}),J);var lt=t=>e=>T(t(e)),T=t=>Object.assign((e=>t(e)),{with:e=>T(e(t))}),O=t=>t instanceof DOMException&&t.name==="AbortError"?{_tag:"Abort"}:typeof t=="object"&&t&&"_tag"in t?t:{_tag:"FetchError",message:String(t)},k=t=>{if(t){if(typeof Headers<"u"&&t instanceof Headers){let e={};return t.forEach((r,n)=>e[n]=r),e}if(Array.isArray(t))return Object.fromEntries(t);if(typeof t=="object")return {...t}}},D=t=>e=>{let r=Object.keys(t).length?C(t)(e):e,n=k(e.init?.headers);return n&&Object.keys(n).length&&(r=C(n)(r)),r};function N(t={}){let e=t.baseUrl??"",r=t.headers??{},n=D(r);return u=>Q$1(async p=>{let y=n(u),i;try{i=new URL(y.url,e);}catch{throw {_tag:"BadUrl",message:`URL inv\xE1lida: ${y.url}`}}let a=performance.now(),s=await fetch(i,{...y.init??{},method:y.method,headers:A.headers.get(y),body:y.body,signal:p}),c={};s.headers.forEach((d,m)=>c[m]=d);let o=pa(s.body,O);return {status:s.status,statusText:s.statusText,headers:c,body:o,ms:Math.round(performance.now()-a)}},O)}function _(t={}){let e=t.baseUrl??"",r=t.headers??{},n=D(r);return T(p=>Q$1(async y=>{let i=n(p),a;try{a=new URL(i.url,e);}catch{throw {_tag:"BadUrl",message:`URL inv\xE1lida: ${i.url}`}}let s=performance.now(),c=await fetch(a,{...i.init??{},method:i.method,headers:A.headers.get(i),body:i.body,signal:y}),o=await c.text(),d={};return c.headers.forEach((m,H)=>d[H]=m),{status:c.status,statusText:c.statusText,headers:d,bodyText:o,ms:Math.round(performance.now()-s)}},O))}var G=(t,e,r)=>Math.max(e,Math.min(r,t)),z=t=>t._tag==="FetchError",Z=t=>t===408||t===429||t===500||t===502||t===503||t===504,F=(t,e,r)=>{let n=e*Math.pow(2,t),u=G(n,0,r);return Math.floor(Math.random()*u)},$=t=>{let e=Object.keys(t).find(p=>p.toLowerCase()==="retry-after");if(!e)return;let r=t[e]?.trim();if(!r)return;let n=Number(r);if(Number.isFinite(n))return Math.max(0,Math.floor(n*1e3));let u=Date.parse(r);if(Number.isFinite(u))return Math.max(0,u-Date.now())},U=t=>e=>(r=>{let n=u=>b$1(e(r),p=>{if(p._tag==="Abort"||p._tag==="BadUrl")return g$1(p);if(!(u<t.maxRetries&&(t.retryOnError??z)(p)))return g$1(p);let i=F(u,t.baseDelayMs,t.maxDelayMs);return l(M(i),()=>n(u+1))},p=>{if(!(u<t.maxRetries&&(t.retryOnStatus??Z)(p.status)))return f(p);let a=$(p.headers)??F(u,t.baseDelayMs,t.maxDelayMs);return l(M(a),()=>n(u+1))});return n(0)});var K=["GET","HEAD","OPTIONS"],Q=t=>t===408||t===429||t===500||t===502||t===503||t===504,V=t=>t._tag==="FetchError";var X=(t,e,r)=>Math.max(e,Math.min(r,t)),L=(t,e,r)=>{let n=Math.max(0,e),u=Math.max(0,r),p=n*Math.pow(2,t),y=X(p,0,u);return Math.floor(Math.random()*y)},Y=(t,e)=>{let r=Object.keys(t).find(n=>n.toLowerCase()===e.toLowerCase());return r?t[r]:void 0},tt=t=>{let e=Y(t,"retry-after")?.trim();if(!e)return;let r=Number(e);if(Number.isFinite(r))return Math.max(0,Math.floor(r*1e3));let n=Date.parse(e);if(Number.isFinite(n))return Math.max(0,n-Date.now())},j=t=>e=>{let r=t.retryOnMethods??K,n=t.retryOnStatus??Q,u=t.retryOnError??V,p=i=>r.includes(i.method),y=(i,a)=>p(i)?b$1(e(i),s=>{if(s._tag==="Abort"||s._tag==="BadUrl")return g$1(s);if(!(a<t.maxRetries&&u(s)))return g$1(s);let o=L(a,t.baseDelayMs,t.maxDelayMs);return l(M(o),()=>y(i,a+1))},s=>{if(!(a<t.maxRetries&&n(s.status)))return f(s);let d=tt(s.headers)??L(a,t.baseDelayMs,t.maxDelayMs);return l(M(d),()=>y(i,a+1))}):e(i);return i=>y(i,0)};var et=(t,e)=>{try{return new URL(e,t??"").toString()}catch{return (t??"")+e}},B=(t={})=>{let e=_(t),r=a=>o((s,c)=>P(s,c))(a),n=a=>e(a),u=a=>{let{headers:s,...c}=a??{};return {headers:k(s),init:c}},p=a=>s=>a?I(a)(s):s;return {cfg:t,wire:e,withPromise:r,requestRaw:n,splitInit:u,applyInitHeaders:p,buildReq:(a,s,c,o)=>{let d=u(c),m={method:a,url:s,...o&&o.length>0?{body:o}:{},init:d.init};return p(d.headers)(m)},toResponse:(a,s)=>({status:a.status,statusText:a.statusText,headers:a.headers,body:s})}};function _t(t={}){let e=B(t),r=n=>{let u=o=>n(o),p=o=>e.withPromise(u(o));return {request:p,get:(o,d)=>p(e.buildReq("GET",o,d)),post:(o,d,m)=>p(e.buildReq("POST",o,m,d)),getText:(o,d)=>{let m=e.buildReq("GET",o,d);return e.withPromise(q(u(m),H=>e.toResponse(H,H.bodyText)))},getJson:(o,d)=>{let m=e.buildReq("GET",o,d),H=g("accept","application/json")(m);return e.withPromise(q(u(H),l=>e.toResponse(l,JSON.parse(l.bodyText))))},postJson:(o,d,m)=>{let H=e.buildReq("POST",o,m,JSON.stringify(d??{})),l=g("content-type","application/json")(g("accept","application/json")(H));return e.withPromise(q(u(l),P=>e.toResponse(P,JSON.parse(P.bodyText))))},with:o=>r(n.with(o)),withRetry:o=>r(n.with(j(o))),wire:n}};return r(e.wire)}function Ut(t={}){let e=B(t),r=(s,c,o)=>({request:s,urlFinal:et(e.cfg.baseUrl,s.url),startedAt:o,durationMs:c.ms}),n=s=>{let c=Date.now();return e.withPromise(q(e.requestRaw(s),o=>({wire:o,meta:r(s,o,c)})))};return {request:n,get:(s,c)=>{let o=e.buildReq("GET",s,c);return n(o)},getText:(s,c)=>{let o=e.buildReq("GET",s,c),d=Date.now();return e.withPromise(q(e.requestRaw(o),m=>({wire:m,response:e.toResponse(m,m.bodyText),meta:r(o,m,d)})))},getJson:(s,c)=>{let o=e.buildReq("GET",s,c),d=g("accept","application/json")(o),m=Date.now();return e.withPromise(q(e.requestRaw(d),H=>({wire:H,response:e.toResponse(H,JSON.parse(H.bodyText)),meta:r(d,H,m)})))},post:(s,c,o)=>{let d=e.buildReq("POST",s,o,c);return n(d)},postJson:(s,c,o)=>{let d=e.buildReq("POST",s,o,JSON.stringify(c??{})),m=g("content-type","application/json")(g("accept","application/json")(d)),H=Date.now();return e.withPromise(q(e.requestRaw(m),l=>({wire:l,response:e.toResponse(l,JSON.parse(l.bodyText)),meta:r(m,l,H)})))}}}function Lt(t={}){let e=N(t),r=n=>{let u=i=>o((a,s)=>P(a,s))(i),p=i=>u(n(i)),y=(i,a)=>{let s={method:"GET",url:i,init:a},c=g("accept","*/*")(s);return p(c)};return {request:p,getStream:y,get:y,with:i=>r(i(n)),withRetry:i=>r(U(i)(n)),wire:n}};return r(e)}export{T as decorate,_t as httpClient,Lt as httpClientStream,Ut as httpClientWithMeta,_ as makeHttp,N as makeHttpStream,k as normalizeHeadersInit,lt as withMiddleware,U as withRetryStream};
|
package/dist/index.d.mts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { Z as ZStream, A as Async, S as Scope,
|
|
2
|
-
export { x as AsyncWithPromise,
|
|
1
|
+
import { Z as ZStream, A as Async, S as Scope, E as Exit, F as Fiber, O as Option } from './stream-DVfZWtYZ.mjs';
|
|
2
|
+
export { x as AsyncWithPromise, J as CancelToken, I as Canceler, C as Cause, a9 as Concat, a8 as Emit, a7 as Empty, V as FiberId, W as FiberStatus, aa as Flatten, ab as FromPull, X as Interrupted, ae as Managed, ac as Merge, N as None, af as Normalize, R as Runtime, Y as RuntimeFiber, a5 as Scheduler, a1 as ScopeId, ad as Scoped, D as Some, a4 as Task, a as ZIO, v as acquireRelease, ar as assertNever, q as async, i as asyncCatchAll, l as asyncFail, t as asyncFlatMap, h as asyncFold, w as asyncInterruptible, r as asyncMap, j as asyncMapError, k as asyncSucceed, n as asyncSync, p as asyncTotal, e as catchAll, ax as collectStream, an as concatStream, am as emitStream, al as emptyStream, g as end, f as fail, c as flatMap, ao as flattenStream, av as foreachStream, M as fork, aw as fromArray, T as fromPromiseAbortable, ah as fromPull, _ as getCurrentFiber, a6 as globalScheduler, L as linkAbortController, K as makeCancelToken, aj as managedStream, m as map, z as mapAsync, d as mapError, as as mapStream, B as mapTryAsync, ap as merge, ak as mergeStream, G as none, o as orElseOptional, at as rangeStream, H as some, ay as streamFromReadableStream, s as succeed, b as sync, Q as toPromise, aq as uncons, u as unit, $ as unsafeGetCurrentRuntime, P as unsafeRunAsync, U as unsafeRunFoldWithEnv, ai as unwrapScoped, ag as widenOpt, y as withAsyncPromise, a0 as withCurrentFiber, a3 as withScope, a2 as withScopeAsync, au as zip } from './stream-DVfZWtYZ.mjs';
|
|
3
3
|
|
|
4
4
|
type Node<T> = {
|
|
5
5
|
value: T;
|
|
@@ -49,22 +49,22 @@ declare function buffer<R, E, A>(stream: ZStream<{} & R, E, A>, capacity: number
|
|
|
49
49
|
* - el primero que termine gana
|
|
50
50
|
* - el otro es cancelado
|
|
51
51
|
*/
|
|
52
|
-
declare function race<R, E, A>(left: Async<R, E, A>, right: Async<R, E, A>, parentScope: Scope<R>): Async<R, E
|
|
52
|
+
declare function race<R, E, A>(left: Async<R, E, A>, right: Async<R, E, A>, parentScope: Scope<R>): Async<R, E, A>;
|
|
53
53
|
/**
|
|
54
54
|
* zipPar(A, B):
|
|
55
55
|
* - corre A y B en paralelo
|
|
56
56
|
* - si ambas terminan bien → éxito con (A, B)
|
|
57
57
|
* - si una falla → cancelar todo y devolver fallo
|
|
58
58
|
*/
|
|
59
|
-
declare function zipPar<R, E, A, B>(left: Async<R, E, A>, right: Async<R, E, B>, parentScope: Scope<R>): Async<R, E
|
|
59
|
+
declare function zipPar<R, E, A, B>(left: Async<R, E, A>, right: Async<R, E, B>, parentScope: Scope<R>): Async<R, E, [A, B]>;
|
|
60
60
|
/**
|
|
61
61
|
* collectAllPar:
|
|
62
62
|
* - corre todos en paralelo
|
|
63
63
|
* - si uno falla → cancela todos
|
|
64
64
|
* - si todos terminan bien → devuelve array de resultados
|
|
65
65
|
*/
|
|
66
|
-
declare function collectAllPar<R, E, A>(effects: ReadonlyArray<Async<R, E, A>>, parentScope: Scope<R>): Async<R, E
|
|
67
|
-
declare function raceWith<R, E, A, B, C>(left: Async<R, E, A>, right: Async<R, E, B>, parentScope: Scope<R>, onLeft: (exit: Exit<E
|
|
66
|
+
declare function collectAllPar<R, E, A>(effects: ReadonlyArray<Async<R, E, A>>, parentScope: Scope<R>): Async<R, E, A[]>;
|
|
67
|
+
declare function raceWith<R, E, A, B, C>(left: Async<R, E, A>, right: Async<R, E, B>, parentScope: Scope<R>, onLeft: (exit: Exit<E, A>, rightFiber: Fiber<E, B>, scope: Scope<R>) => Async<R, E, C>, onRight: (exit: Exit<E, B>, leftFiber: Fiber<E, A>, scope: Scope<R>) => Async<R, E, C>): Async<R, E, C>;
|
|
68
68
|
|
|
69
69
|
type Strategy = "backpressure" | "dropping" | "sliding";
|
|
70
70
|
type QueueClosed = {
|
|
@@ -135,4 +135,4 @@ declare function bufferP<A>(capacity: number, strategy?: "backpressure" | "dropp
|
|
|
135
135
|
*/
|
|
136
136
|
declare function groupedP<A>(n: number): ZPipeline<unknown, never, A, A[]>;
|
|
137
137
|
|
|
138
|
-
export { Async, Exit, Fiber, type Hub, type HubClosed, type HubStrategy,
|
|
138
|
+
export { Async, Exit, Fiber, type Hub, type HubClosed, type HubStrategy, LinkedQueue, type Node, Option, PushStatus, type Queue, type QueueClosed, RingBuffer, Scope, type Strategy, type Subscription, type ZPipeline, ZStream, andThen, bounded, broadcast, broadcastToHub, buffer, bufferP, collectAllPar, compose, dropP, filterMapP, filterP, fromHub, groupedP, identity, makeHub, mapEffectP, mapP, race, raceWith, takeP, tapEffectP, via, zipPar };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { Z as ZStream, A as Async, S as Scope,
|
|
2
|
-
export { x as AsyncWithPromise,
|
|
1
|
+
import { Z as ZStream, A as Async, S as Scope, E as Exit, F as Fiber, O as Option } from './stream-DVfZWtYZ.js';
|
|
2
|
+
export { x as AsyncWithPromise, J as CancelToken, I as Canceler, C as Cause, a9 as Concat, a8 as Emit, a7 as Empty, V as FiberId, W as FiberStatus, aa as Flatten, ab as FromPull, X as Interrupted, ae as Managed, ac as Merge, N as None, af as Normalize, R as Runtime, Y as RuntimeFiber, a5 as Scheduler, a1 as ScopeId, ad as Scoped, D as Some, a4 as Task, a as ZIO, v as acquireRelease, ar as assertNever, q as async, i as asyncCatchAll, l as asyncFail, t as asyncFlatMap, h as asyncFold, w as asyncInterruptible, r as asyncMap, j as asyncMapError, k as asyncSucceed, n as asyncSync, p as asyncTotal, e as catchAll, ax as collectStream, an as concatStream, am as emitStream, al as emptyStream, g as end, f as fail, c as flatMap, ao as flattenStream, av as foreachStream, M as fork, aw as fromArray, T as fromPromiseAbortable, ah as fromPull, _ as getCurrentFiber, a6 as globalScheduler, L as linkAbortController, K as makeCancelToken, aj as managedStream, m as map, z as mapAsync, d as mapError, as as mapStream, B as mapTryAsync, ap as merge, ak as mergeStream, G as none, o as orElseOptional, at as rangeStream, H as some, ay as streamFromReadableStream, s as succeed, b as sync, Q as toPromise, aq as uncons, u as unit, $ as unsafeGetCurrentRuntime, P as unsafeRunAsync, U as unsafeRunFoldWithEnv, ai as unwrapScoped, ag as widenOpt, y as withAsyncPromise, a0 as withCurrentFiber, a3 as withScope, a2 as withScopeAsync, au as zip } from './stream-DVfZWtYZ.js';
|
|
3
3
|
|
|
4
4
|
type Node<T> = {
|
|
5
5
|
value: T;
|
|
@@ -49,22 +49,22 @@ declare function buffer<R, E, A>(stream: ZStream<{} & R, E, A>, capacity: number
|
|
|
49
49
|
* - el primero que termine gana
|
|
50
50
|
* - el otro es cancelado
|
|
51
51
|
*/
|
|
52
|
-
declare function race<R, E, A>(left: Async<R, E, A>, right: Async<R, E, A>, parentScope: Scope<R>): Async<R, E
|
|
52
|
+
declare function race<R, E, A>(left: Async<R, E, A>, right: Async<R, E, A>, parentScope: Scope<R>): Async<R, E, A>;
|
|
53
53
|
/**
|
|
54
54
|
* zipPar(A, B):
|
|
55
55
|
* - corre A y B en paralelo
|
|
56
56
|
* - si ambas terminan bien → éxito con (A, B)
|
|
57
57
|
* - si una falla → cancelar todo y devolver fallo
|
|
58
58
|
*/
|
|
59
|
-
declare function zipPar<R, E, A, B>(left: Async<R, E, A>, right: Async<R, E, B>, parentScope: Scope<R>): Async<R, E
|
|
59
|
+
declare function zipPar<R, E, A, B>(left: Async<R, E, A>, right: Async<R, E, B>, parentScope: Scope<R>): Async<R, E, [A, B]>;
|
|
60
60
|
/**
|
|
61
61
|
* collectAllPar:
|
|
62
62
|
* - corre todos en paralelo
|
|
63
63
|
* - si uno falla → cancela todos
|
|
64
64
|
* - si todos terminan bien → devuelve array de resultados
|
|
65
65
|
*/
|
|
66
|
-
declare function collectAllPar<R, E, A>(effects: ReadonlyArray<Async<R, E, A>>, parentScope: Scope<R>): Async<R, E
|
|
67
|
-
declare function raceWith<R, E, A, B, C>(left: Async<R, E, A>, right: Async<R, E, B>, parentScope: Scope<R>, onLeft: (exit: Exit<E
|
|
66
|
+
declare function collectAllPar<R, E, A>(effects: ReadonlyArray<Async<R, E, A>>, parentScope: Scope<R>): Async<R, E, A[]>;
|
|
67
|
+
declare function raceWith<R, E, A, B, C>(left: Async<R, E, A>, right: Async<R, E, B>, parentScope: Scope<R>, onLeft: (exit: Exit<E, A>, rightFiber: Fiber<E, B>, scope: Scope<R>) => Async<R, E, C>, onRight: (exit: Exit<E, B>, leftFiber: Fiber<E, A>, scope: Scope<R>) => Async<R, E, C>): Async<R, E, C>;
|
|
68
68
|
|
|
69
69
|
type Strategy = "backpressure" | "dropping" | "sliding";
|
|
70
70
|
type QueueClosed = {
|
|
@@ -135,4 +135,4 @@ declare function bufferP<A>(capacity: number, strategy?: "backpressure" | "dropp
|
|
|
135
135
|
*/
|
|
136
136
|
declare function groupedP<A>(n: number): ZPipeline<unknown, never, A, A[]>;
|
|
137
137
|
|
|
138
|
-
export { Async, Exit, Fiber, type Hub, type HubClosed, type HubStrategy,
|
|
138
|
+
export { Async, Exit, Fiber, type Hub, type HubClosed, type HubStrategy, LinkedQueue, type Node, Option, PushStatus, type Queue, type QueueClosed, RingBuffer, Scope, type Strategy, type Subscription, type ZPipeline, ZStream, andThen, bounded, broadcast, broadcastToHub, buffer, bufferP, collectAllPar, compose, dropP, filterMapP, filterP, fromHub, groupedP, identity, makeHub, mapEffectP, mapP, race, raceWith, takeP, tapEffectP, via, zipPar };
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
'use strict';var chunkQ2H2CAII_js=require('./chunk-Q2H2CAII.js');function ze(){let t=false,e=new Set;return {isCancelled:()=>t,onCancel:r=>{if(t){try{r();}catch{}return ()=>{}}return e.add(r),()=>{e.delete(r);}},cancel:()=>{t||(t=true,e.forEach(r=>r()),e.clear());}}}function De(t,e){return t.onCancel(()=>e.abort())}var v=class{head=null;tail=null;len=0;get length(){return this.len}isEmpty(){return this.len===0}push(e){let n={value:e,next:null,prev:this.tail,removed:false};return this.tail?this.tail.next=n:this.head=n,this.tail=n,this.len++,n}shift(){let e=this.head;if(e)return this.unlink(e),e.value}remove(e){e.removed||this.unlink(e);}unlink(e){e.removed=true;let{prev:n,next:r}=e;n?n.next=r:this.head=r,r?r.prev=n:this.tail=n,e.next=null,e.prev=null,this.len--;}};function w(t,e="backpressure"){return chunkQ2H2CAII_js.g(()=>M(t,e))}function M(t,e){let n=new chunkQ2H2CAII_js.C(t),r=false,s={_tag:"QueueClosed"},o=new v,a=new v,l=()=>{for(;a.length>0&&n.length>0;){let u=a.shift(),f=n.shift();u({_tag:"Success",value:f});}for(;o.length>0&&n.length<t&&a.length===0;){let u=o.shift();n.push(u.a),u.cb(true);}for(;a.length>0&&o.length>0;){let u=a.shift(),f=o.shift();f.cb(true),u({_tag:"Success",value:f.a});}};return {size:()=>n.length,shutdown:()=>{if(!r){for(r=true;a.length>0;)a.shift()({_tag:"Failure",error:s});for(;o.length>0;)o.shift().cb(false);n.clear();}},offer:u=>chunkQ2H2CAII_js.i((f,i)=>{if(r){i({_tag:"Success",value:false});return}if(a.length>0){a.shift()({_tag:"Success",value:u}),i({_tag:"Success",value:true});return}if(n.length<t){n.push(u),i({_tag:"Success",value:true}),l();return}if(e==="dropping"){i({_tag:"Success",value:false});return}if(e==="sliding"){n.shift(),n.push(u),i({_tag:"Success",value:true}),l();return}let A=o.push({a:u,cb:m=>i({_tag:"Success",value:m})});return ()=>{o.remove(A);}}),take:()=>chunkQ2H2CAII_js.i((u,f)=>{if(n.length>0){let m=n.shift();f({_tag:"Success",value:m}),l();return}if(o.length>0){let m=o.shift();m.cb(true),f({_tag:"Success",value:m.a});return}if(r){f({_tag:"Failure",error:s});return}let i=m=>f(m),A=a.push(i);return ()=>{a.remove(A);}})}}function F(t,e,n="backpressure"){let r=false,s=null,o=null,a=t,l=()=>chunkQ2H2CAII_js.a(chunkQ2H2CAII_js.ha(a),i=>chunkQ2H2CAII_js.e(i._tag==="None"?{_tag:"End"}:{_tag:"Fail",error:i.value}),([i,A])=>chunkQ2H2CAII_js.g(()=>(a=A,{_tag:"Elem",value:i}))),p=i=>chunkQ2H2CAII_js.k(w(e,n),A=>{s=A;let S=()=>chunkQ2H2CAII_js.k(l(),m=>chunkQ2H2CAII_js.k(s.offer(m),()=>m._tag==="End"||m._tag==="Fail"?chunkQ2H2CAII_js.e(void 0):S()));return o=chunkQ2H2CAII_js.K(S(),i),r=true,chunkQ2H2CAII_js.e(void 0)}),u={_tag:"Async",register:(i,A)=>{(()=>{if(!r){chunkQ2H2CAII_js.K(p(i),i).join(()=>{f(i,A);});return}f(i,A);})();}};function f(i,A){let S=s.take();chunkQ2H2CAII_js.K(S,i).join(m=>{if(m._tag!=="Success")return;let _=m.value;switch(_._tag){case "Elem":A({_tag:"Success",value:[_.value,chunkQ2H2CAII_js._(u)]});return;case "End":o?.interrupt?.(),A({_tag:"Failure",error:chunkQ2H2CAII_js.q});return;case "Fail":o?.interrupt?.(),A({_tag:"Failure",error:chunkQ2H2CAII_js.r(_.error)});return}});}return chunkQ2H2CAII_js._(u)}var I=t=>t==="BackPressure"?"backpressure":t==="Dropping"?"dropping":"sliding";function N(t,e="BackPressure"){let n=new Set,r=false,s=p=>{if(r)return chunkQ2H2CAII_js.e(false);let u=Array.from(n),f=chunkQ2H2CAII_js.e(true);return u.forEach(i=>{f=chunkQ2H2CAII_js.k(f,A=>chunkQ2H2CAII_js.k(i.offer(p),S=>chunkQ2H2CAII_js.e(A&&S)));}),f};return {publish:s,publishAll:p=>{let u=chunkQ2H2CAII_js.e(true),f=p[Symbol.iterator]();for(;;){let i=f.next();if(i.done)break;let A=i.value;u=chunkQ2H2CAII_js.k(u,S=>chunkQ2H2CAII_js.k(s(A),m=>chunkQ2H2CAII_js.e(S&&m)));}return u},subscribe:()=>r?chunkQ2H2CAII_js.h(()=>{throw {_tag:"HubClosed"}}):chunkQ2H2CAII_js.k(w(t,I(e)),p=>chunkQ2H2CAII_js.g(()=>(n.add(p),{...p,unsubscribe:()=>{n.has(p)&&(n.delete(p),p.shutdown());}}))),shutdown:()=>chunkQ2H2CAII_js.g(()=>{r||(r=true,Array.from(n).forEach(p=>p.shutdown()),n.clear());})}}var yn=N;function dn(t,e){return chunkQ2H2CAII_js.ma(t,n=>chunkQ2H2CAII_js.k(e.publish(n),()=>chunkQ2H2CAII_js.e(void 0)))}function Rn(t){return chunkQ2H2CAII_js.aa(chunkQ2H2CAII_js.k(t.subscribe(),e=>{let n=chunkQ2H2CAII_js._(chunkQ2H2CAII_js.k(chunkQ2H2CAII_js.c(e.take(),r=>chunkQ2H2CAII_js.q),r=>chunkQ2H2CAII_js.e([r,n])));return chunkQ2H2CAII_js.e({stream:n,release:r=>chunkQ2H2CAII_js.g(()=>e.unsubscribe())})}))}function _n(t,e){return e(t)}function z(t,e){return(n=>e(t(n)))}function Cn(t,e){return z(e,t)}function On(){return(t=>t)}function Pn(t){return(e=>{let n=r=>chunkQ2H2CAII_js._(chunkQ2H2CAII_js.a(chunkQ2H2CAII_js.ha(r),s=>chunkQ2H2CAII_js.f(s),([s,o])=>chunkQ2H2CAII_js.e([t(s),n(o)])));return n(e)})}function Bn(t){return(e=>{let n=s=>chunkQ2H2CAII_js.a(chunkQ2H2CAII_js.ha(s),o=>chunkQ2H2CAII_js.f(o),([o,a])=>t(o)?chunkQ2H2CAII_js.e([o,r(a)]):n(a)),r=s=>chunkQ2H2CAII_js._(n(s));return r(e)})}function Tn(t){return(e=>{let n=s=>chunkQ2H2CAII_js.a(chunkQ2H2CAII_js.ha(s),o=>chunkQ2H2CAII_js.f(o),([o,a])=>{let l=t(o);return l._tag==="Some"?chunkQ2H2CAII_js.e([l.value,r(a)]):n(a)}),r=s=>chunkQ2H2CAII_js._(n(s));return r(e)})}function Hn(t){let e=Math.max(0,t|0);return(n=>{let r=(s,o)=>o<=0?chunkQ2H2CAII_js.ca():chunkQ2H2CAII_js._(chunkQ2H2CAII_js.a(chunkQ2H2CAII_js.ha(s),a=>chunkQ2H2CAII_js.f(a),([a,l])=>chunkQ2H2CAII_js.e([a,r(l,o-1)])));return r(n,e)})}function Qn(t){let e=Math.max(0,t|0);return(n=>{let r=(s,o)=>o<=0?s:chunkQ2H2CAII_js._(chunkQ2H2CAII_js.a(chunkQ2H2CAII_js.ha(s),a=>chunkQ2H2CAII_js.f(a),([a,l])=>chunkQ2H2CAII_js.ha(r(l,o-1))));return r(n,e)})}function D(t){return(e=>{let n=s=>chunkQ2H2CAII_js.c(s,o=>chunkQ2H2CAII_js.r(o)),r=s=>chunkQ2H2CAII_js._(chunkQ2H2CAII_js.a(chunkQ2H2CAII_js.c(chunkQ2H2CAII_js.ha(s),o=>chunkQ2H2CAII_js.Z(o)),o=>chunkQ2H2CAII_js.f(o),([o,a])=>chunkQ2H2CAII_js.a(n(t(o)),l=>chunkQ2H2CAII_js.f(l),l=>chunkQ2H2CAII_js.e([l,r(a)]))));return r(e)})}function Fn(t){return D(e=>chunkQ2H2CAII_js.k(t(e),()=>chunkQ2H2CAII_js.e(e)))}function Mn(t,e="backpressure"){return(n=>F(n,t,e))}function In(t){let e=Math.max(1,t|0);return(n=>{let r=(o,a,l)=>a<=0?chunkQ2H2CAII_js.e({chunk:l,rest:o}):chunkQ2H2CAII_js.a(chunkQ2H2CAII_js.ha(o),p=>p._tag==="None"?chunkQ2H2CAII_js.e({chunk:l,rest:chunkQ2H2CAII_js.ca()}):chunkQ2H2CAII_js.f(p),([p,u])=>r(u,a-1,[...l,p])),s=o=>chunkQ2H2CAII_js._(chunkQ2H2CAII_js.a(chunkQ2H2CAII_js.ha(o),a=>chunkQ2H2CAII_js.f(a),([a,l])=>chunkQ2H2CAII_js.k(r(l,e-1,[a]),({chunk:p,rest:u})=>chunkQ2H2CAII_js.e([p,s(u)]))));return s(n)})}Object.defineProperty(exports,"PushStatus",{enumerable:true,get:function(){return chunkQ2H2CAII_js.B}});Object.defineProperty(exports,"RingBuffer",{enumerable:true,get:function(){return chunkQ2H2CAII_js.C}});Object.defineProperty(exports,"Runtime",{enumerable:true,get:function(){return chunkQ2H2CAII_js.I}});Object.defineProperty(exports,"RuntimeFiber",{enumerable:true,get:function(){return chunkQ2H2CAII_js.F}});Object.defineProperty(exports,"Scheduler",{enumerable:true,get:function(){return chunkQ2H2CAII_js.D}});Object.defineProperty(exports,"Scope",{enumerable:true,get:function(){return chunkQ2H2CAII_js.S}});Object.defineProperty(exports,"acquireRelease",{enumerable:true,get:function(){return chunkQ2H2CAII_js.l}});Object.defineProperty(exports,"assertNever",{enumerable:true,get:function(){return chunkQ2H2CAII_js.ia}});Object.defineProperty(exports,"async",{enumerable:true,get:function(){return chunkQ2H2CAII_js.i}});Object.defineProperty(exports,"asyncCatchAll",{enumerable:true,get:function(){return chunkQ2H2CAII_js.b}});Object.defineProperty(exports,"asyncFail",{enumerable:true,get:function(){return chunkQ2H2CAII_js.f}});Object.defineProperty(exports,"asyncFlatMap",{enumerable:true,get:function(){return chunkQ2H2CAII_js.k}});Object.defineProperty(exports,"asyncFold",{enumerable:true,get:function(){return chunkQ2H2CAII_js.a}});Object.defineProperty(exports,"asyncInterruptible",{enumerable:true,get:function(){return chunkQ2H2CAII_js.m}});Object.defineProperty(exports,"asyncMap",{enumerable:true,get:function(){return chunkQ2H2CAII_js.j}});Object.defineProperty(exports,"asyncMapError",{enumerable:true,get:function(){return chunkQ2H2CAII_js.c}});Object.defineProperty(exports,"asyncSucceed",{enumerable:true,get:function(){return chunkQ2H2CAII_js.e}});Object.defineProperty(exports,"asyncSync",{enumerable:true,get:function(){return chunkQ2H2CAII_js.g}});Object.defineProperty(exports,"asyncTotal",{enumerable:true,get:function(){return chunkQ2H2CAII_js.h}});Object.defineProperty(exports,"catchAll",{enumerable:true,get:function(){return chunkQ2H2CAII_js.y}});Object.defineProperty(exports,"collectAllPar",{enumerable:true,get:function(){return chunkQ2H2CAII_js.X}});Object.defineProperty(exports,"collectStream",{enumerable:true,get:function(){return chunkQ2H2CAII_js.oa}});Object.defineProperty(exports,"concatStream",{enumerable:true,get:function(){return chunkQ2H2CAII_js.ea}});Object.defineProperty(exports,"emitStream",{enumerable:true,get:function(){return chunkQ2H2CAII_js.da}});Object.defineProperty(exports,"emptyStream",{enumerable:true,get:function(){return chunkQ2H2CAII_js.ca}});Object.defineProperty(exports,"end",{enumerable:true,get:function(){return chunkQ2H2CAII_js.A}});Object.defineProperty(exports,"fail",{enumerable:true,get:function(){return chunkQ2H2CAII_js.t}});Object.defineProperty(exports,"flatMap",{enumerable:true,get:function(){return chunkQ2H2CAII_js.w}});Object.defineProperty(exports,"flattenStream",{enumerable:true,get:function(){return chunkQ2H2CAII_js.fa}});Object.defineProperty(exports,"foreachStream",{enumerable:true,get:function(){return chunkQ2H2CAII_js.ma}});Object.defineProperty(exports,"fork",{enumerable:true,get:function(){return chunkQ2H2CAII_js.K}});Object.defineProperty(exports,"from",{enumerable:true,get:function(){return chunkQ2H2CAII_js.J}});Object.defineProperty(exports,"fromArray",{enumerable:true,get:function(){return chunkQ2H2CAII_js.na}});Object.defineProperty(exports,"fromCallback",{enumerable:true,get:function(){return chunkQ2H2CAII_js.O}});Object.defineProperty(exports,"fromPromise",{enumerable:true,get:function(){return chunkQ2H2CAII_js.N}});Object.defineProperty(exports,"fromPromiseAbortable",{enumerable:true,get:function(){return chunkQ2H2CAII_js.Q}});Object.defineProperty(exports,"fromPull",{enumerable:true,get:function(){return chunkQ2H2CAII_js._}});Object.defineProperty(exports,"getCurrentFiber",{enumerable:true,get:function(){return chunkQ2H2CAII_js.G}});Object.defineProperty(exports,"getCurrentRuntime",{enumerable:true,get:function(){return chunkQ2H2CAII_js.R}});Object.defineProperty(exports,"globalScheduler",{enumerable:true,get:function(){return chunkQ2H2CAII_js.E}});Object.defineProperty(exports,"managedStream",{enumerable:true,get:function(){return chunkQ2H2CAII_js.aa}});Object.defineProperty(exports,"map",{enumerable:true,get:function(){return chunkQ2H2CAII_js.v}});Object.defineProperty(exports,"mapAsync",{enumerable:true,get:function(){return chunkQ2H2CAII_js.o}});Object.defineProperty(exports,"mapError",{enumerable:true,get:function(){return chunkQ2H2CAII_js.x}});Object.defineProperty(exports,"mapStream",{enumerable:true,get:function(){return chunkQ2H2CAII_js.ja}});Object.defineProperty(exports,"mapTryAsync",{enumerable:true,get:function(){return chunkQ2H2CAII_js.p}});Object.defineProperty(exports,"merge",{enumerable:true,get:function(){return chunkQ2H2CAII_js.ga}});Object.defineProperty(exports,"mergeStream",{enumerable:true,get:function(){return chunkQ2H2CAII_js.ba}});Object.defineProperty(exports,"none",{enumerable:true,get:function(){return chunkQ2H2CAII_js.q}});Object.defineProperty(exports,"orElseOptional",{enumerable:true,get:function(){return chunkQ2H2CAII_js.z}});Object.defineProperty(exports,"race",{enumerable:true,get:function(){return chunkQ2H2CAII_js.V}});Object.defineProperty(exports,"raceWith",{enumerable:true,get:function(){return chunkQ2H2CAII_js.Y}});Object.defineProperty(exports,"rangeStream",{enumerable:true,get:function(){return chunkQ2H2CAII_js.ka}});Object.defineProperty(exports,"some",{enumerable:true,get:function(){return chunkQ2H2CAII_js.r}});Object.defineProperty(exports,"streamFromReadableStream",{enumerable:true,get:function(){return chunkQ2H2CAII_js.pa}});Object.defineProperty(exports,"succeed",{enumerable:true,get:function(){return chunkQ2H2CAII_js.s}});Object.defineProperty(exports,"sync",{enumerable:true,get:function(){return chunkQ2H2CAII_js.u}});Object.defineProperty(exports,"toPromise",{enumerable:true,get:function(){return chunkQ2H2CAII_js.M}});Object.defineProperty(exports,"tryPromiseAbortable",{enumerable:true,get:function(){return chunkQ2H2CAII_js.P}});Object.defineProperty(exports,"uncons",{enumerable:true,get:function(){return chunkQ2H2CAII_js.ha}});Object.defineProperty(exports,"unit",{enumerable:true,get:function(){return chunkQ2H2CAII_js.d}});Object.defineProperty(exports,"unsafeRunAsync",{enumerable:true,get:function(){return chunkQ2H2CAII_js.L}});Object.defineProperty(exports,"unwrapScoped",{enumerable:true,get:function(){return chunkQ2H2CAII_js.$}});Object.defineProperty(exports,"widenOpt",{enumerable:true,get:function(){return chunkQ2H2CAII_js.Z}});Object.defineProperty(exports,"withAsyncPromise",{enumerable:true,get:function(){return chunkQ2H2CAII_js.n}});Object.defineProperty(exports,"withCurrentFiber",{enumerable:true,get:function(){return chunkQ2H2CAII_js.H}});Object.defineProperty(exports,"withScope",{enumerable:true,get:function(){return chunkQ2H2CAII_js.T}});Object.defineProperty(exports,"withScopeAsync",{enumerable:true,get:function(){return chunkQ2H2CAII_js.U}});Object.defineProperty(exports,"zip",{enumerable:true,get:function(){return chunkQ2H2CAII_js.la}});Object.defineProperty(exports,"zipPar",{enumerable:true,get:function(){return chunkQ2H2CAII_js.W}});exports.LinkedQueue=v;exports.andThen=z;exports.bounded=w;exports.broadcast=yn;exports.broadcastToHub=dn;exports.buffer=F;exports.bufferP=Mn;exports.compose=Cn;exports.dropP=Qn;exports.filterMapP=Tn;exports.filterP=Bn;exports.fromHub=Rn;exports.groupedP=In;exports.identity=On;exports.linkAbortController=De;exports.makeCancelToken=ze;exports.makeHub=N;exports.mapEffectP=D;exports.mapP=Pn;exports.takeP=Hn;exports.tapEffectP=Fn;exports.via=_n;
|
|
1
|
+
'use strict';var chunk5PIZGM6Q_js=require('./chunk-5PIZGM6Q.js');function ze(){let t=false,e=new Set;return {isCancelled:()=>t,onCancel:r=>{if(t){try{r();}catch{}return ()=>{}}return e.add(r),()=>{e.delete(r);}},cancel:()=>{t||(t=true,e.forEach(r=>r()),e.clear());}}}function De(t,e){return t.onCancel(()=>e.abort())}var v=class{head=null;tail=null;len=0;get length(){return this.len}isEmpty(){return this.len===0}push(e){let n={value:e,next:null,prev:this.tail,removed:false};return this.tail?this.tail.next=n:this.head=n,this.tail=n,this.len++,n}shift(){let e=this.head;if(e)return this.unlink(e),e.value}remove(e){e.removed||this.unlink(e);}unlink(e){e.removed=true;let{prev:n,next:r}=e;n?n.next=r:this.head=r,r?r.prev=n:this.tail=n,e.next=null,e.prev=null,this.len--;}};function Z(t,e="backpressure"){return chunk5PIZGM6Q_js.h(()=>I(t,e))}function I(t,e){let n=new chunk5PIZGM6Q_js.F(t),r=false,s={_tag:"QueueClosed"},o=new v,a=new v,l=()=>{for(;a.length>0&&n.length>0;){let u=a.shift(),f=n.shift();u({_tag:"Success",value:f});}for(;o.length>0&&n.length<t&&a.length===0;){let u=o.shift();n.push(u.a),u.cb(true);}for(;a.length>0&&o.length>0;){let u=a.shift(),f=o.shift();f.cb(true),u({_tag:"Success",value:f.a});}};return {size:()=>n.length,shutdown:()=>{if(!r){for(r=true;a.length>0;)a.shift()({_tag:"Failure",cause:{_tag:"Fail",error:s}});for(;o.length>0;)o.shift().cb(false);n.clear();}},offer:u=>chunk5PIZGM6Q_js.j((f,i)=>{if(r){i({_tag:"Success",value:false});return}if(a.length>0){a.shift()({_tag:"Success",value:u}),i({_tag:"Success",value:true});return}if(n.length<t){n.push(u),i({_tag:"Success",value:true}),l();return}if(e==="dropping"){i({_tag:"Success",value:false});return}if(e==="sliding"){n.shift(),n.push(u),i({_tag:"Success",value:true}),l();return}let m=o.push({a:u,cb:A=>i({_tag:"Success",value:A})});return ()=>{o.remove(m);}}),take:()=>chunk5PIZGM6Q_js.j((u,f)=>{if(n.length>0){let A=n.shift();f({_tag:"Success",value:A}),l();return}if(o.length>0){let A=o.shift();A.cb(true),f({_tag:"Success",value:A.a});return}if(r){f({_tag:"Failure",cause:{_tag:"Fail",error:s}});return}let i=A=>f(A),m=a.push(i);return ()=>{a.remove(m);}})}}function M(t,e,n="backpressure"){let r=false,s=null,o=null,a=t,l=()=>chunk5PIZGM6Q_js.b(chunk5PIZGM6Q_js.ha(a),i=>chunk5PIZGM6Q_js.f(i._tag==="None"?{_tag:"End"}:{_tag:"Fail",error:i.value}),([i,m])=>chunk5PIZGM6Q_js.h(()=>(a=m,{_tag:"Elem",value:i}))),p=i=>chunk5PIZGM6Q_js.l(Z(e,n),m=>{s=m;let S=()=>chunk5PIZGM6Q_js.l(l(),A=>chunk5PIZGM6Q_js.l(s.offer(A),()=>A._tag==="End"||A._tag==="Fail"?chunk5PIZGM6Q_js.f(void 0):S()));return o=chunk5PIZGM6Q_js.N(S(),i),r=true,chunk5PIZGM6Q_js.f(void 0)}),u={_tag:"Async",register:(i,m)=>{(()=>{if(!r){chunk5PIZGM6Q_js.K().fork(p(i)).join(()=>{f(i,m);});return}f(i,m);})();}};function f(i,m){let S=s.take();chunk5PIZGM6Q_js.K().fork(S).join(A=>{if(A._tag!=="Success")return;let w=A.value;switch(w._tag){case "Elem":m({_tag:"Success",value:[w.value,chunk5PIZGM6Q_js._(u)]});return;case "End":o?.interrupt?.(),m({_tag:"Failure",cause:{_tag:"Fail",error:chunk5PIZGM6Q_js.r}});return;case "Fail":o?.interrupt?.(),m({_tag:"Failure",cause:{_tag:"Fail",error:chunk5PIZGM6Q_js.s(w.error)}});return}});}return chunk5PIZGM6Q_js._(u)}var N=t=>t==="BackPressure"?"backpressure":t==="Dropping"?"dropping":"sliding";function z(t,e="BackPressure"){let n=new Set,r=false,s=p=>{if(r)return chunk5PIZGM6Q_js.f(false);let u=Array.from(n),f=chunk5PIZGM6Q_js.f(true);return u.forEach(i=>{f=chunk5PIZGM6Q_js.l(f,m=>chunk5PIZGM6Q_js.l(i.offer(p),S=>chunk5PIZGM6Q_js.f(m&&S)));}),f};return {publish:s,publishAll:p=>{let u=chunk5PIZGM6Q_js.f(true),f=p[Symbol.iterator]();for(;;){let i=f.next();if(i.done)break;let m=i.value;u=chunk5PIZGM6Q_js.l(u,S=>chunk5PIZGM6Q_js.l(s(m),A=>chunk5PIZGM6Q_js.f(S&&A)));}return u},subscribe:()=>r?chunk5PIZGM6Q_js.i(()=>{throw {_tag:"HubClosed"}}):chunk5PIZGM6Q_js.l(Z(t,N(e)),p=>chunk5PIZGM6Q_js.h(()=>(n.add(p),{...p,unsubscribe:()=>{n.has(p)&&(n.delete(p),p.shutdown());}}))),shutdown:()=>chunk5PIZGM6Q_js.h(()=>{r||(r=true,Array.from(n).forEach(p=>p.shutdown()),n.clear());})}}var dn=z;function Rn(t,e){return chunk5PIZGM6Q_js.ma(t,n=>chunk5PIZGM6Q_js.l(e.publish(n),()=>chunk5PIZGM6Q_js.f(void 0)))}function Sn(t){return chunk5PIZGM6Q_js.aa(chunk5PIZGM6Q_js.l(t.subscribe(),e=>{let n=chunk5PIZGM6Q_js._(chunk5PIZGM6Q_js.l(chunk5PIZGM6Q_js.d(e.take(),r=>chunk5PIZGM6Q_js.r),r=>chunk5PIZGM6Q_js.f([r,n])));return chunk5PIZGM6Q_js.f({stream:n,release:r=>chunk5PIZGM6Q_js.h(()=>e.unsubscribe())})}))}function Cn(t,e){return e(t)}function D(t,e){return(n=>e(t(n)))}function On(t,e){return D(e,t)}function Pn(){return(t=>t)}function Bn(t){return(e=>{let n=r=>chunk5PIZGM6Q_js._(chunk5PIZGM6Q_js.b(chunk5PIZGM6Q_js.ha(r),s=>chunk5PIZGM6Q_js.g(s),([s,o])=>chunk5PIZGM6Q_js.f([t(s),n(o)])));return n(e)})}function Tn(t){return(e=>{let n=s=>chunk5PIZGM6Q_js.b(chunk5PIZGM6Q_js.ha(s),o=>chunk5PIZGM6Q_js.g(o),([o,a])=>t(o)?chunk5PIZGM6Q_js.f([o,r(a)]):n(a)),r=s=>chunk5PIZGM6Q_js._(n(s));return r(e)})}function Fn(t){return(e=>{let n=s=>chunk5PIZGM6Q_js.b(chunk5PIZGM6Q_js.ha(s),o=>chunk5PIZGM6Q_js.g(o),([o,a])=>{let l=t(o);return l._tag==="Some"?chunk5PIZGM6Q_js.f([l.value,r(a)]):n(a)}),r=s=>chunk5PIZGM6Q_js._(n(s));return r(e)})}function Hn(t){let e=Math.max(0,t|0);return(n=>{let r=(s,o)=>o<=0?chunk5PIZGM6Q_js.ca():chunk5PIZGM6Q_js._(chunk5PIZGM6Q_js.b(chunk5PIZGM6Q_js.ha(s),a=>chunk5PIZGM6Q_js.g(a),([a,l])=>chunk5PIZGM6Q_js.f([a,r(l,o-1)])));return r(n,e)})}function Qn(t){let e=Math.max(0,t|0);return(n=>{let r=(s,o)=>o<=0?s:chunk5PIZGM6Q_js._(chunk5PIZGM6Q_js.b(chunk5PIZGM6Q_js.ha(s),a=>chunk5PIZGM6Q_js.g(a),([a,l])=>chunk5PIZGM6Q_js.ha(r(l,o-1))));return r(n,e)})}function W(t){return(e=>{let n=s=>chunk5PIZGM6Q_js.d(s,o=>chunk5PIZGM6Q_js.s(o)),r=s=>chunk5PIZGM6Q_js._(chunk5PIZGM6Q_js.b(chunk5PIZGM6Q_js.d(chunk5PIZGM6Q_js.ha(s),o=>chunk5PIZGM6Q_js.Z(o)),o=>chunk5PIZGM6Q_js.g(o),([o,a])=>chunk5PIZGM6Q_js.b(n(t(o)),l=>chunk5PIZGM6Q_js.g(l),l=>chunk5PIZGM6Q_js.f([l,r(a)]))));return r(e)})}function Mn(t){return W(e=>chunk5PIZGM6Q_js.l(t(e),()=>chunk5PIZGM6Q_js.f(e)))}function In(t,e="backpressure"){return(n=>M(n,t,e))}function Nn(t){let e=Math.max(1,t|0);return(n=>{let r=(o,a,l)=>a<=0?chunk5PIZGM6Q_js.f({chunk:l,rest:o}):chunk5PIZGM6Q_js.b(chunk5PIZGM6Q_js.ha(o),p=>p._tag==="None"?chunk5PIZGM6Q_js.f({chunk:l,rest:chunk5PIZGM6Q_js.ca()}):chunk5PIZGM6Q_js.g(p),([p,u])=>r(u,a-1,[...l,p])),s=o=>chunk5PIZGM6Q_js._(chunk5PIZGM6Q_js.b(chunk5PIZGM6Q_js.ha(o),a=>chunk5PIZGM6Q_js.g(a),([a,l])=>chunk5PIZGM6Q_js.l(r(l,e-1,[a]),({chunk:p,rest:u})=>chunk5PIZGM6Q_js.f([p,s(u)]))));return s(n)})}Object.defineProperty(exports,"Async",{enumerable:true,get:function(){return chunk5PIZGM6Q_js.a}});Object.defineProperty(exports,"Cause",{enumerable:true,get:function(){return chunk5PIZGM6Q_js.t}});Object.defineProperty(exports,"Exit",{enumerable:true,get:function(){return chunk5PIZGM6Q_js.u}});Object.defineProperty(exports,"PushStatus",{enumerable:true,get:function(){return chunk5PIZGM6Q_js.E}});Object.defineProperty(exports,"RingBuffer",{enumerable:true,get:function(){return chunk5PIZGM6Q_js.F}});Object.defineProperty(exports,"Runtime",{enumerable:true,get:function(){return chunk5PIZGM6Q_js.M}});Object.defineProperty(exports,"RuntimeFiber",{enumerable:true,get:function(){return chunk5PIZGM6Q_js.I}});Object.defineProperty(exports,"Scheduler",{enumerable:true,get:function(){return chunk5PIZGM6Q_js.G}});Object.defineProperty(exports,"Scope",{enumerable:true,get:function(){return chunk5PIZGM6Q_js.S}});Object.defineProperty(exports,"acquireRelease",{enumerable:true,get:function(){return chunk5PIZGM6Q_js.m}});Object.defineProperty(exports,"assertNever",{enumerable:true,get:function(){return chunk5PIZGM6Q_js.ia}});Object.defineProperty(exports,"async",{enumerable:true,get:function(){return chunk5PIZGM6Q_js.j}});Object.defineProperty(exports,"asyncCatchAll",{enumerable:true,get:function(){return chunk5PIZGM6Q_js.c}});Object.defineProperty(exports,"asyncFail",{enumerable:true,get:function(){return chunk5PIZGM6Q_js.g}});Object.defineProperty(exports,"asyncFlatMap",{enumerable:true,get:function(){return chunk5PIZGM6Q_js.l}});Object.defineProperty(exports,"asyncFold",{enumerable:true,get:function(){return chunk5PIZGM6Q_js.b}});Object.defineProperty(exports,"asyncInterruptible",{enumerable:true,get:function(){return chunk5PIZGM6Q_js.n}});Object.defineProperty(exports,"asyncMap",{enumerable:true,get:function(){return chunk5PIZGM6Q_js.k}});Object.defineProperty(exports,"asyncMapError",{enumerable:true,get:function(){return chunk5PIZGM6Q_js.d}});Object.defineProperty(exports,"asyncSucceed",{enumerable:true,get:function(){return chunk5PIZGM6Q_js.f}});Object.defineProperty(exports,"asyncSync",{enumerable:true,get:function(){return chunk5PIZGM6Q_js.h}});Object.defineProperty(exports,"asyncTotal",{enumerable:true,get:function(){return chunk5PIZGM6Q_js.i}});Object.defineProperty(exports,"catchAll",{enumerable:true,get:function(){return chunk5PIZGM6Q_js.B}});Object.defineProperty(exports,"collectAllPar",{enumerable:true,get:function(){return chunk5PIZGM6Q_js.X}});Object.defineProperty(exports,"collectStream",{enumerable:true,get:function(){return chunk5PIZGM6Q_js.oa}});Object.defineProperty(exports,"concatStream",{enumerable:true,get:function(){return chunk5PIZGM6Q_js.ea}});Object.defineProperty(exports,"emitStream",{enumerable:true,get:function(){return chunk5PIZGM6Q_js.da}});Object.defineProperty(exports,"emptyStream",{enumerable:true,get:function(){return chunk5PIZGM6Q_js.ca}});Object.defineProperty(exports,"end",{enumerable:true,get:function(){return chunk5PIZGM6Q_js.D}});Object.defineProperty(exports,"fail",{enumerable:true,get:function(){return chunk5PIZGM6Q_js.w}});Object.defineProperty(exports,"flatMap",{enumerable:true,get:function(){return chunk5PIZGM6Q_js.z}});Object.defineProperty(exports,"flattenStream",{enumerable:true,get:function(){return chunk5PIZGM6Q_js.fa}});Object.defineProperty(exports,"foreachStream",{enumerable:true,get:function(){return chunk5PIZGM6Q_js.ma}});Object.defineProperty(exports,"fork",{enumerable:true,get:function(){return chunk5PIZGM6Q_js.N}});Object.defineProperty(exports,"fromArray",{enumerable:true,get:function(){return chunk5PIZGM6Q_js.na}});Object.defineProperty(exports,"fromPromiseAbortable",{enumerable:true,get:function(){return chunk5PIZGM6Q_js.Q}});Object.defineProperty(exports,"fromPull",{enumerable:true,get:function(){return chunk5PIZGM6Q_js._}});Object.defineProperty(exports,"getCurrentFiber",{enumerable:true,get:function(){return chunk5PIZGM6Q_js.J}});Object.defineProperty(exports,"globalScheduler",{enumerable:true,get:function(){return chunk5PIZGM6Q_js.H}});Object.defineProperty(exports,"managedStream",{enumerable:true,get:function(){return chunk5PIZGM6Q_js.aa}});Object.defineProperty(exports,"map",{enumerable:true,get:function(){return chunk5PIZGM6Q_js.y}});Object.defineProperty(exports,"mapAsync",{enumerable:true,get:function(){return chunk5PIZGM6Q_js.p}});Object.defineProperty(exports,"mapError",{enumerable:true,get:function(){return chunk5PIZGM6Q_js.A}});Object.defineProperty(exports,"mapStream",{enumerable:true,get:function(){return chunk5PIZGM6Q_js.ja}});Object.defineProperty(exports,"mapTryAsync",{enumerable:true,get:function(){return chunk5PIZGM6Q_js.q}});Object.defineProperty(exports,"merge",{enumerable:true,get:function(){return chunk5PIZGM6Q_js.ga}});Object.defineProperty(exports,"mergeStream",{enumerable:true,get:function(){return chunk5PIZGM6Q_js.ba}});Object.defineProperty(exports,"none",{enumerable:true,get:function(){return chunk5PIZGM6Q_js.r}});Object.defineProperty(exports,"orElseOptional",{enumerable:true,get:function(){return chunk5PIZGM6Q_js.C}});Object.defineProperty(exports,"race",{enumerable:true,get:function(){return chunk5PIZGM6Q_js.V}});Object.defineProperty(exports,"raceWith",{enumerable:true,get:function(){return chunk5PIZGM6Q_js.Y}});Object.defineProperty(exports,"rangeStream",{enumerable:true,get:function(){return chunk5PIZGM6Q_js.ka}});Object.defineProperty(exports,"some",{enumerable:true,get:function(){return chunk5PIZGM6Q_js.s}});Object.defineProperty(exports,"streamFromReadableStream",{enumerable:true,get:function(){return chunk5PIZGM6Q_js.pa}});Object.defineProperty(exports,"succeed",{enumerable:true,get:function(){return chunk5PIZGM6Q_js.v}});Object.defineProperty(exports,"sync",{enumerable:true,get:function(){return chunk5PIZGM6Q_js.x}});Object.defineProperty(exports,"toPromise",{enumerable:true,get:function(){return chunk5PIZGM6Q_js.P}});Object.defineProperty(exports,"uncons",{enumerable:true,get:function(){return chunk5PIZGM6Q_js.ha}});Object.defineProperty(exports,"unit",{enumerable:true,get:function(){return chunk5PIZGM6Q_js.e}});Object.defineProperty(exports,"unsafeGetCurrentRuntime",{enumerable:true,get:function(){return chunk5PIZGM6Q_js.K}});Object.defineProperty(exports,"unsafeRunAsync",{enumerable:true,get:function(){return chunk5PIZGM6Q_js.O}});Object.defineProperty(exports,"unsafeRunFoldWithEnv",{enumerable:true,get:function(){return chunk5PIZGM6Q_js.R}});Object.defineProperty(exports,"unwrapScoped",{enumerable:true,get:function(){return chunk5PIZGM6Q_js.$}});Object.defineProperty(exports,"widenOpt",{enumerable:true,get:function(){return chunk5PIZGM6Q_js.Z}});Object.defineProperty(exports,"withAsyncPromise",{enumerable:true,get:function(){return chunk5PIZGM6Q_js.o}});Object.defineProperty(exports,"withCurrentFiber",{enumerable:true,get:function(){return chunk5PIZGM6Q_js.L}});Object.defineProperty(exports,"withScope",{enumerable:true,get:function(){return chunk5PIZGM6Q_js.U}});Object.defineProperty(exports,"withScopeAsync",{enumerable:true,get:function(){return chunk5PIZGM6Q_js.T}});Object.defineProperty(exports,"zip",{enumerable:true,get:function(){return chunk5PIZGM6Q_js.la}});Object.defineProperty(exports,"zipPar",{enumerable:true,get:function(){return chunk5PIZGM6Q_js.W}});exports.LinkedQueue=v;exports.andThen=D;exports.bounded=Z;exports.broadcast=dn;exports.broadcastToHub=Rn;exports.buffer=M;exports.bufferP=In;exports.compose=On;exports.dropP=Qn;exports.filterMapP=Fn;exports.filterP=Tn;exports.fromHub=Sn;exports.groupedP=Nn;exports.identity=Pn;exports.linkAbortController=De;exports.makeCancelToken=ze;exports.makeHub=z;exports.mapEffectP=W;exports.mapP=Bn;exports.takeP=Hn;exports.tapEffectP=Mn;exports.via=Cn;
|
package/dist/index.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {h,F,j,_,i,l,f,ma,aa,d,r,ca,K,s,b,ha,g,Z as Z$1,N as N$1}from'./chunk-CNA5AQHG.mjs';export{a as Async,t as Cause,u as Exit,E as PushStatus,F as RingBuffer,M as Runtime,I as RuntimeFiber,G as Scheduler,S as Scope,m as acquireRelease,ia as assertNever,j as async,c as asyncCatchAll,g as asyncFail,l as asyncFlatMap,b as asyncFold,n as asyncInterruptible,k as asyncMap,d as asyncMapError,f as asyncSucceed,h as asyncSync,i as asyncTotal,B as catchAll,X as collectAllPar,oa as collectStream,ea as concatStream,da as emitStream,ca as emptyStream,D as end,w as fail,z as flatMap,fa as flattenStream,ma as foreachStream,N as fork,na as fromArray,Q as fromPromiseAbortable,_ as fromPull,J as getCurrentFiber,H as globalScheduler,aa as managedStream,y as map,p as mapAsync,A as mapError,ja as mapStream,q as mapTryAsync,ga as merge,ba as mergeStream,r as none,C as orElseOptional,V as race,Y as raceWith,ka as rangeStream,s as some,pa as streamFromReadableStream,v as succeed,x as sync,P as toPromise,ha as uncons,e as unit,K as unsafeGetCurrentRuntime,O as unsafeRunAsync,R as unsafeRunFoldWithEnv,$ as unwrapScoped,Z as widenOpt,o as withAsyncPromise,L as withCurrentFiber,U as withScope,T as withScopeAsync,la as zip,W as zipPar}from'./chunk-CNA5AQHG.mjs';function ze(){let t=false,e=new Set;return {isCancelled:()=>t,onCancel:r=>{if(t){try{r();}catch{}return ()=>{}}return e.add(r),()=>{e.delete(r);}},cancel:()=>{t||(t=true,e.forEach(r=>r()),e.clear());}}}function De(t,e){return t.onCancel(()=>e.abort())}var v=class{head=null;tail=null;len=0;get length(){return this.len}isEmpty(){return this.len===0}push(e){let n={value:e,next:null,prev:this.tail,removed:false};return this.tail?this.tail.next=n:this.head=n,this.tail=n,this.len++,n}shift(){let e=this.head;if(e)return this.unlink(e),e.value}remove(e){e.removed||this.unlink(e);}unlink(e){e.removed=true;let{prev:n,next:r}=e;n?n.next=r:this.head=r,r?r.prev=n:this.tail=n,e.next=null,e.prev=null,this.len--;}};function Z(t,e="backpressure"){return h(()=>I(t,e))}function I(t,e){let n=new F(t),r=false,s={_tag:"QueueClosed"},o=new v,a=new v,l=()=>{for(;a.length>0&&n.length>0;){let u=a.shift(),f=n.shift();u({_tag:"Success",value:f});}for(;o.length>0&&n.length<t&&a.length===0;){let u=o.shift();n.push(u.a),u.cb(true);}for(;a.length>0&&o.length>0;){let u=a.shift(),f=o.shift();f.cb(true),u({_tag:"Success",value:f.a});}};return {size:()=>n.length,shutdown:()=>{if(!r){for(r=true;a.length>0;)a.shift()({_tag:"Failure",cause:{_tag:"Fail",error:s}});for(;o.length>0;)o.shift().cb(false);n.clear();}},offer:u=>j((f,i)=>{if(r){i({_tag:"Success",value:false});return}if(a.length>0){a.shift()({_tag:"Success",value:u}),i({_tag:"Success",value:true});return}if(n.length<t){n.push(u),i({_tag:"Success",value:true}),l();return}if(e==="dropping"){i({_tag:"Success",value:false});return}if(e==="sliding"){n.shift(),n.push(u),i({_tag:"Success",value:true}),l();return}let m=o.push({a:u,cb:A=>i({_tag:"Success",value:A})});return ()=>{o.remove(m);}}),take:()=>j((u,f)=>{if(n.length>0){let A=n.shift();f({_tag:"Success",value:A}),l();return}if(o.length>0){let A=o.shift();A.cb(true),f({_tag:"Success",value:A.a});return}if(r){f({_tag:"Failure",cause:{_tag:"Fail",error:s}});return}let i=A=>f(A),m=a.push(i);return ()=>{a.remove(m);}})}}function M(t,e,n="backpressure"){let r$1=false,s$1=null,o=null,a=t,l$1=()=>b(ha(a),i=>f(i._tag==="None"?{_tag:"End"}:{_tag:"Fail",error:i.value}),([i,m])=>h(()=>(a=m,{_tag:"Elem",value:i}))),p=i=>l(Z(e,n),m=>{s$1=m;let S=()=>l(l$1(),A=>l(s$1.offer(A),()=>A._tag==="End"||A._tag==="Fail"?f(void 0):S()));return o=N$1(S(),i),r$1=true,f(void 0)}),u={_tag:"Async",register:(i,m)=>{(()=>{if(!r$1){K().fork(p(i)).join(()=>{f$1(i,m);});return}f$1(i,m);})();}};function f$1(i,m){let S=s$1.take();K().fork(S).join(A=>{if(A._tag!=="Success")return;let w=A.value;switch(w._tag){case "Elem":m({_tag:"Success",value:[w.value,_(u)]});return;case "End":o?.interrupt?.(),m({_tag:"Failure",cause:{_tag:"Fail",error:r}});return;case "Fail":o?.interrupt?.(),m({_tag:"Failure",cause:{_tag:"Fail",error:s(w.error)}});return}});}return _(u)}var N=t=>t==="BackPressure"?"backpressure":t==="Dropping"?"dropping":"sliding";function z(t,e="BackPressure"){let n=new Set,r=false,s=p=>{if(r)return f(false);let u=Array.from(n),f$1=f(true);return u.forEach(i=>{f$1=l(f$1,m=>l(i.offer(p),S=>f(m&&S)));}),f$1};return {publish:s,publishAll:p=>{let u=f(true),f$1=p[Symbol.iterator]();for(;;){let i=f$1.next();if(i.done)break;let m=i.value;u=l(u,S=>l(s(m),A=>f(S&&A)));}return u},subscribe:()=>r?i(()=>{throw {_tag:"HubClosed"}}):l(Z(t,N(e)),p=>h(()=>(n.add(p),{...p,unsubscribe:()=>{n.has(p)&&(n.delete(p),p.shutdown());}}))),shutdown:()=>h(()=>{r||(r=true,Array.from(n).forEach(p=>p.shutdown()),n.clear());})}}var dn=z;function Rn(t,e){return ma(t,n=>l(e.publish(n),()=>f(void 0)))}function Sn(t){return aa(l(t.subscribe(),e=>{let n=_(l(d(e.take(),r$1=>r),r=>f([r,n])));return f({stream:n,release:r=>h(()=>e.unsubscribe())})}))}function Cn(t,e){return e(t)}function D(t,e){return(n=>e(t(n)))}function On(t,e){return D(e,t)}function Pn(){return(t=>t)}function Bn(t){return(e=>{let n=r=>_(b(ha(r),s=>g(s),([s,o])=>f([t(s),n(o)])));return n(e)})}function Tn(t){return(e=>{let n=s=>b(ha(s),o=>g(o),([o,a])=>t(o)?f([o,r(a)]):n(a)),r=s=>_(n(s));return r(e)})}function Fn(t){return(e=>{let n=s=>b(ha(s),o=>g(o),([o,a])=>{let l=t(o);return l._tag==="Some"?f([l.value,r(a)]):n(a)}),r=s=>_(n(s));return r(e)})}function Hn(t){let e=Math.max(0,t|0);return(n=>{let r=(s,o)=>o<=0?ca():_(b(ha(s),a=>g(a),([a,l])=>f([a,r(l,o-1)])));return r(n,e)})}function Qn(t){let e=Math.max(0,t|0);return(n=>{let r=(s,o)=>o<=0?s:_(b(ha(s),a=>g(a),([a,l])=>ha(r(l,o-1))));return r(n,e)})}function W(t){return(e=>{let n=s$1=>d(s$1,o=>s(o)),r=s=>_(b(d(ha(s),o=>Z$1(o)),o=>g(o),([o,a])=>b(n(t(o)),l=>g(l),l=>f([l,r(a)]))));return r(e)})}function Mn(t){return W(e=>l(t(e),()=>f(e)))}function In(t,e="backpressure"){return(n=>M(n,t,e))}function Nn(t){let e=Math.max(1,t|0);return(n=>{let r=(o,a,l)=>a<=0?f({chunk:l,rest:o}):b(ha(o),p=>p._tag==="None"?f({chunk:l,rest:ca()}):g(p),([p,u])=>r(u,a-1,[...l,p])),s=o=>_(b(ha(o),a=>g(a),([a,l$1])=>l(r(l$1,e-1,[a]),({chunk:p,rest:u})=>f([p,s(u)]))));return s(n)})}export{v as LinkedQueue,D as andThen,Z as bounded,dn as broadcast,Rn as broadcastToHub,M as buffer,In as bufferP,On as compose,Qn as dropP,Fn as filterMapP,Tn as filterP,Sn as fromHub,Nn as groupedP,Pn as identity,De as linkAbortController,ze as makeCancelToken,z as makeHub,W as mapEffectP,Bn as mapP,Hn as takeP,Mn as tapEffectP,Cn as via};
|
|
@@ -63,17 +63,64 @@ type RuntimeEvent = {
|
|
|
63
63
|
message: string;
|
|
64
64
|
fields?: Record<string, unknown>;
|
|
65
65
|
};
|
|
66
|
+
type RuntimeEmitContext = {
|
|
67
|
+
fiberId?: number;
|
|
68
|
+
scopeId?: number;
|
|
69
|
+
traceId?: string;
|
|
70
|
+
spanId?: string;
|
|
71
|
+
};
|
|
66
72
|
interface RuntimeHooks {
|
|
67
73
|
emit(ev: RuntimeEvent, ctx: RuntimeEmitContext): void;
|
|
68
74
|
}
|
|
69
|
-
type
|
|
70
|
-
|
|
75
|
+
type RuntimeEventRecord = RuntimeEvent & RuntimeEmitContext & {
|
|
76
|
+
seq: number;
|
|
77
|
+
wallTs: number;
|
|
78
|
+
ts: number;
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
type FiberRunState = "Queued" | "Running" | "Suspended" | "Done";
|
|
82
|
+
type FiberInfo = {
|
|
83
|
+
fiberId: number;
|
|
84
|
+
parentFiberId?: number;
|
|
85
|
+
name?: string;
|
|
86
|
+
runState: FiberRunState;
|
|
87
|
+
status: "Running" | "Done" | "Interrupted";
|
|
88
|
+
createdAt: number;
|
|
89
|
+
lastActiveAt: number;
|
|
71
90
|
scopeId?: number;
|
|
72
91
|
traceId?: string;
|
|
73
92
|
spanId?: string;
|
|
93
|
+
awaiting?: {
|
|
94
|
+
reason: string;
|
|
95
|
+
detail?: string;
|
|
96
|
+
};
|
|
97
|
+
lastEnd?: {
|
|
98
|
+
status: string;
|
|
99
|
+
error?: string;
|
|
100
|
+
};
|
|
101
|
+
};
|
|
102
|
+
type ScopeInfo = {
|
|
103
|
+
scopeId: number;
|
|
104
|
+
parentScopeId?: number;
|
|
105
|
+
ownerFiberId?: number;
|
|
106
|
+
openAt: number;
|
|
107
|
+
closedAt?: number;
|
|
108
|
+
finalizers: Array<{
|
|
109
|
+
id: number;
|
|
110
|
+
label?: string;
|
|
111
|
+
status: "added" | "running" | "done";
|
|
112
|
+
}>;
|
|
74
113
|
};
|
|
114
|
+
declare class RuntimeRegistry implements RuntimeHooks {
|
|
115
|
+
fibers: Map<number, FiberInfo>;
|
|
116
|
+
scopes: Map<number, ScopeInfo>;
|
|
117
|
+
private seq;
|
|
118
|
+
private recent;
|
|
119
|
+
private recentCap;
|
|
120
|
+
emit(ev: RuntimeEvent, ctx: RuntimeEmitContext): void;
|
|
121
|
+
getRecentEvents(): RuntimeEventRecord[];
|
|
122
|
+
}
|
|
75
123
|
|
|
76
|
-
type NodeCallback<A> = (err: Error | null, result: A) => void;
|
|
77
124
|
/**
|
|
78
125
|
* --- Runtime como objeto único (ZIO-style) ---
|
|
79
126
|
* Un valor que representa "cómo" se ejecutan los efectos: scheduler + environment + hooks.
|
|
@@ -83,48 +130,41 @@ declare class Runtime<R> {
|
|
|
83
130
|
readonly scheduler: Scheduler;
|
|
84
131
|
readonly hooks: RuntimeHooks;
|
|
85
132
|
readonly forkPolicy: {
|
|
86
|
-
initChild(fiber: RuntimeFiber<any, any, any> & any, parent?: (RuntimeFiber<any, any, any> & any) | null): void;
|
|
133
|
+
initChild(fiber: RuntimeFiber<any, any, any> & any, parent?: (RuntimeFiber<any, any, any> & any) | null, scopeId?: number): void;
|
|
87
134
|
};
|
|
135
|
+
registry?: RuntimeRegistry;
|
|
88
136
|
constructor(args: {
|
|
89
137
|
env: R;
|
|
90
138
|
scheduler?: Scheduler;
|
|
91
139
|
hooks?: RuntimeHooks;
|
|
92
140
|
});
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
toPromise<E, A>(effect: Async<R, E, A>): Promise<A>;
|
|
96
|
-
log(level: "debug" | "info" | "warn" | "error", message: string, fields?: Record<string, unknown>): void;
|
|
97
|
-
withHooks(hooks: RuntimeHooks): Runtime<R>;
|
|
141
|
+
/** Deriva un runtime con env extendido (estilo provide/locally) */
|
|
142
|
+
provide<R2>(env: R2): Runtime<R & R2>;
|
|
98
143
|
emit(ev: RuntimeEvent): void;
|
|
144
|
+
/**
|
|
145
|
+
* ✅ CAMBIO: fork(effect, scopeId?) y pasa scopeId a forkPolicy
|
|
146
|
+
*/
|
|
147
|
+
fork<E, A>(effect: Async<R, E, A>, scopeId?: number): Fiber<E, A>;
|
|
148
|
+
unsafeRunAsync<E, A>(effect: Async<R, E, A>, cb: (exit: Exit<E, A>) => void): void;
|
|
149
|
+
toPromise<E, A>(effect: Async<R, E, A>): Promise<A>;
|
|
150
|
+
unsafeRun<E, A>(effect: Async<R, E, A>): void;
|
|
151
|
+
delay<E, A>(ms: number, eff: Async<R, E, A>): Async<R, E, A>;
|
|
99
152
|
static make<R>(env: R, scheduler?: Scheduler): Runtime<R>;
|
|
153
|
+
/** Convenience logger: emits a RuntimeEvent of type "log". */
|
|
154
|
+
log(level: "debug" | "info" | "warn" | "error", message: string, fields?: Record<string, unknown>): void;
|
|
100
155
|
}
|
|
156
|
+
/** Create a runtime from `env` and fork the given effect. */
|
|
157
|
+
declare function fork<R, E, A>(effect: Async<R, E, A>, env?: R): Fiber<E, A>;
|
|
158
|
+
/** Run an effect with `env` and invoke `cb` with the final Exit. */
|
|
159
|
+
declare function unsafeRunAsync<R, E, A>(effect: Async<R, E, A>, env: R | undefined, cb: (exit: Exit<E, A>) => void): void;
|
|
160
|
+
/** Run an effect with `env` and return a Promise of its success value. */
|
|
161
|
+
declare function toPromise<R, E, A>(effect: Async<R, E, A>, env?: R): Promise<A>;
|
|
101
162
|
/**
|
|
102
|
-
*
|
|
103
|
-
*
|
|
104
|
-
* ---------------------------------------------------------------------------
|
|
163
|
+
* Create an Async from an abortable Promise.
|
|
164
|
+
* Type params are ordered as `<E, A, R = unknown>` to match call-sites.
|
|
105
165
|
*/
|
|
106
|
-
declare function
|
|
107
|
-
declare function
|
|
108
|
-
type BrassError = {
|
|
109
|
-
_tag: "Abort";
|
|
110
|
-
} | {
|
|
111
|
-
_tag: "PromiseRejected";
|
|
112
|
-
reason: unknown;
|
|
113
|
-
};
|
|
114
|
-
/**
|
|
115
|
-
* --- Wrappers legacy (mantienen tu API actual) ---
|
|
116
|
-
* Internamente crean un Runtime ad-hoc con env + scheduler.
|
|
117
|
-
*/
|
|
118
|
-
declare function fork<R, E, A>(effect: Async<R, E, A>, env: R, scheduler?: Scheduler): Fiber<E, A>;
|
|
119
|
-
declare function unsafeRunAsync<R, E, A>(effect: Async<R, E, A>, env: R, cb: (exit: Exit<E | Interrupted, A>) => void): void;
|
|
120
|
-
declare function toPromise<R, E, A>(eff: Async<R, E, A>, env: R): Promise<A>;
|
|
121
|
-
declare function fromPromise<R, E, A>(thunk: (env: R) => Promise<A>, onError: (e: unknown) => E): Async<R, E, A>;
|
|
122
|
-
declare function fromCallback<A>(f: (cb: NodeCallback<A>) => void): Async<{}, Error, A>;
|
|
123
|
-
declare function tryPromiseAbortable<A>(thunk: (signal: AbortSignal) => Promise<A>): Async<unknown, BrassError, A>;
|
|
124
|
-
declare function tryPromiseAbortable<R, A>(thunk: (env: R, signal: AbortSignal) => Promise<A>): Async<R, BrassError, A>;
|
|
125
|
-
declare function fromPromiseAbortable<E, A>(thunk: (signal: AbortSignal) => Promise<A>, onError: (e: unknown) => E): Async<unknown, E, A>;
|
|
126
|
-
declare function fromPromiseAbortable<R, E, A>(thunk: (env: R, signal: AbortSignal) => Promise<A>, onError: (e: unknown) => E): Async<R, E, A>;
|
|
127
|
-
declare function getCurrentRuntime<R>(): Runtime<R>;
|
|
166
|
+
declare function fromPromiseAbortable<E, A, R = unknown>(make: (signal: AbortSignal, env: R) => Promise<A>, onReject: (u: unknown) => E): Async<R, E, A>;
|
|
167
|
+
declare function unsafeRunFoldWithEnv<R, E, A>(eff: Async<R, E, A>, env: R, onFailure: (cause: Cause<E>) => void, onSuccess: (value: A) => void): void;
|
|
128
168
|
|
|
129
169
|
type JSONValue = null | boolean | number | string | JSONValue[] | {
|
|
130
170
|
[k: string]: JSONValue;
|
|
@@ -145,17 +185,16 @@ type FiberContext = {
|
|
|
145
185
|
};
|
|
146
186
|
|
|
147
187
|
type FiberId = number;
|
|
188
|
+
type FiberStatus = "Running" | "Done" | "Interrupted";
|
|
148
189
|
type Interrupted = {
|
|
149
|
-
readonly _tag: "
|
|
190
|
+
readonly _tag: "Interrupt";
|
|
150
191
|
};
|
|
151
|
-
type FiberStatus = "Running" | "Done" | "Interrupted";
|
|
152
|
-
type StepDecision = "Continue" | "Suspend" | "Done";
|
|
153
192
|
type Fiber<E, A> = {
|
|
154
193
|
readonly id: FiberId;
|
|
155
194
|
readonly status: () => FiberStatus;
|
|
156
|
-
readonly join: (cb: (exit: Exit<E
|
|
195
|
+
readonly join: (cb: (exit: Exit<E, A>) => void) => void;
|
|
157
196
|
readonly interrupt: () => void;
|
|
158
|
-
readonly addFinalizer: (f: (exit: Exit<E
|
|
197
|
+
readonly addFinalizer: (f: (exit: Exit<E, A>) => void) => void;
|
|
159
198
|
};
|
|
160
199
|
declare class RuntimeFiber<R, E, A> implements Fiber<E, A> {
|
|
161
200
|
readonly id: FiberId;
|
|
@@ -176,18 +215,25 @@ declare class RuntimeFiber<R, E, A> implements Fiber<E, A> {
|
|
|
176
215
|
constructor(runtime: Runtime<R>, effect: Async<R, E, A>);
|
|
177
216
|
private get env();
|
|
178
217
|
private get scheduler();
|
|
179
|
-
|
|
218
|
+
private emit;
|
|
219
|
+
addFinalizer(f: (exit: Exit<E, A>) => void): void;
|
|
180
220
|
status(): FiberStatus;
|
|
181
|
-
join(cb: (exit: Exit<E
|
|
221
|
+
join(cb: (exit: Exit<E, A>) => void): void;
|
|
182
222
|
interrupt(): void;
|
|
183
223
|
schedule(tag?: string): void;
|
|
184
224
|
private runFinalizersOnce;
|
|
185
225
|
private notify;
|
|
186
226
|
private onSuccess;
|
|
187
227
|
private onFailure;
|
|
188
|
-
|
|
228
|
+
private budget;
|
|
229
|
+
private step;
|
|
189
230
|
}
|
|
190
231
|
declare function getCurrentFiber(): RuntimeFiber<any, any, any> | null;
|
|
232
|
+
/**
|
|
233
|
+
* Unsafe (but convenient) access to the runtime that is currently executing.
|
|
234
|
+
* Throws if called outside of a running fiber.
|
|
235
|
+
*/
|
|
236
|
+
declare function unsafeGetCurrentRuntime<R>(): Runtime<R>;
|
|
191
237
|
declare function withCurrentFiber<T>(fiber: RuntimeFiber<any, any, any>, f: () => T): T;
|
|
192
238
|
|
|
193
239
|
type ScopeId = number;
|
|
@@ -196,55 +242,59 @@ type CloseOptions = {
|
|
|
196
242
|
};
|
|
197
243
|
declare class Scope<R> {
|
|
198
244
|
private readonly runtime;
|
|
245
|
+
private readonly parentScopeId?;
|
|
199
246
|
readonly id: ScopeId;
|
|
200
247
|
private closed;
|
|
201
248
|
private readonly children;
|
|
202
249
|
private readonly subScopes;
|
|
203
250
|
private readonly finalizers;
|
|
204
|
-
constructor(runtime: Runtime<R
|
|
205
|
-
/** Acceso al env del runtime (conserva tu modelo actual) */
|
|
206
|
-
private get env();
|
|
251
|
+
constructor(runtime: Runtime<R>, parentScopeId?: ScopeId | undefined);
|
|
207
252
|
/** registra un finalizer (LIFO) */
|
|
208
253
|
addFinalizer(f: (exit: Exit<any, any>) => Async<R, any, any>): void;
|
|
209
254
|
/** crea un sub scope (mismo runtime) */
|
|
210
255
|
subScope(): Scope<R>;
|
|
211
|
-
/** fork en este scope */
|
|
212
|
-
fork<E, A>(eff: Async<R, E, A>): Fiber<E
|
|
256
|
+
/** ✅ fork en este scope */
|
|
257
|
+
fork<E, A>(eff: Async<R, E, A>): Fiber<E, A>;
|
|
213
258
|
/** close fire-and-forget (no bloquea) */
|
|
214
259
|
close(exit?: Exit<any, any>): void;
|
|
215
|
-
closeAsync(exit?: Exit<any, any>,
|
|
260
|
+
closeAsync(exit?: Exit<any, any>, opts?: CloseOptions): Async<R, any, void>;
|
|
216
261
|
}
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
declare function withScope<R, A>(runtime: Runtime<R>, body: (scope: Scope<R>) => A): A;
|
|
222
|
-
/**
|
|
223
|
-
* Versión async: crea scope, corre el efecto, cierra el scope con el Exit.
|
|
224
|
-
*/
|
|
225
|
-
declare function withScopeAsync<R, E, A>(runtime: Runtime<R>, use: (scope: Scope<R>) => Async<R, E, A>): Async<R, E | Interrupted, A>;
|
|
262
|
+
declare function withScopeAsync<R, E, A>(runtime: Runtime<R>, f: (scope: Scope<R>) => Async<R, E, A>): Async<R, E, A>;
|
|
263
|
+
|
|
264
|
+
declare function withScope<R>(runtime: Runtime<R>, f: (scope: Scope<R>) => void): Async<R, never, void>;
|
|
265
|
+
declare function withScope<R, E, A>(runtime: Runtime<R>, f: (scope: Scope<R>) => Async<R, E, A>): Async<R, E, A>;
|
|
226
266
|
|
|
227
267
|
type Async<R, E, A> = {
|
|
228
|
-
_tag: "Succeed";
|
|
229
|
-
value: A;
|
|
268
|
+
readonly _tag: "Succeed";
|
|
269
|
+
readonly value: A;
|
|
230
270
|
} | {
|
|
231
|
-
_tag: "Fail";
|
|
232
|
-
error: E;
|
|
271
|
+
readonly _tag: "Fail";
|
|
272
|
+
readonly error: E;
|
|
273
|
+
} | {
|
|
274
|
+
readonly _tag: "Sync";
|
|
275
|
+
readonly thunk: (env: R) => A;
|
|
233
276
|
} | {
|
|
234
|
-
_tag: "
|
|
235
|
-
|
|
277
|
+
readonly _tag: "Async";
|
|
278
|
+
readonly register: (env: R, cb: (exit: Exit<E, A>) => void) => void | (() => void);
|
|
236
279
|
} | {
|
|
237
|
-
_tag: "
|
|
238
|
-
|
|
280
|
+
readonly _tag: "FlatMap";
|
|
281
|
+
readonly first: Async<R, E, any>;
|
|
282
|
+
readonly andThen: (a: any) => Async<R, E, A>;
|
|
239
283
|
} | {
|
|
240
|
-
_tag: "
|
|
241
|
-
first: Async<R, E, any>;
|
|
242
|
-
|
|
284
|
+
readonly _tag: "Fold";
|
|
285
|
+
readonly first: Async<R, E, any>;
|
|
286
|
+
readonly onFailure: (e: any) => Async<R, E, A>;
|
|
287
|
+
readonly onSuccess: (a: any) => Async<R, E, A>;
|
|
243
288
|
} | {
|
|
244
|
-
_tag: "
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
289
|
+
readonly _tag: "Fork";
|
|
290
|
+
readonly effect: Async<R, E, any>;
|
|
291
|
+
readonly scopeId?: number;
|
|
292
|
+
};
|
|
293
|
+
declare const Async: {
|
|
294
|
+
succeed: <R, E, A>(value: A) => Async<R, E, A>;
|
|
295
|
+
fail: <R, E, A = never>(error: E) => Async<R, E, A>;
|
|
296
|
+
sync: <R, E, A>(thunk: (env: R) => A) => Async<R, E, A>;
|
|
297
|
+
async: <R, E, A>(register: (env: R, cb: (exit: Exit<E, A>) => void) => void | (() => void)) => Async<R, E, A>;
|
|
248
298
|
};
|
|
249
299
|
declare function asyncFold<R, E, A, B>(fa: Async<R, E, A>, onFailure: (e: E) => Async<R, E, B>, onSuccess: (a: A) => Async<R, E, B>): Async<R, E, B>;
|
|
250
300
|
declare function asyncCatchAll<R, E, A, R2, E2, B>(fa: Async<R, E, A>, handler: (e: E) => Async<R2, E2, B>): Async<R & R2, E2, A | B>;
|
|
@@ -278,12 +328,30 @@ type Option<A> = None | Some<A>;
|
|
|
278
328
|
declare const none: Option<never>;
|
|
279
329
|
declare const some: <A>(value: A) => Option<A>;
|
|
280
330
|
|
|
331
|
+
type Cause<E> = {
|
|
332
|
+
readonly _tag: "Fail";
|
|
333
|
+
readonly error: E;
|
|
334
|
+
} | {
|
|
335
|
+
readonly _tag: "Interrupt";
|
|
336
|
+
} | {
|
|
337
|
+
readonly _tag: "Die";
|
|
338
|
+
readonly defect: unknown;
|
|
339
|
+
};
|
|
340
|
+
declare const Cause: {
|
|
341
|
+
fail: <E>(error: E) => Cause<E>;
|
|
342
|
+
interrupt: <E = never>() => Cause<E>;
|
|
343
|
+
die: <E = never>(defect: unknown) => Cause<E>;
|
|
344
|
+
};
|
|
281
345
|
type Exit<E, A> = {
|
|
282
|
-
|
|
283
|
-
|
|
346
|
+
_tag: "Success";
|
|
347
|
+
value: A;
|
|
284
348
|
} | {
|
|
285
|
-
|
|
286
|
-
|
|
349
|
+
_tag: "Failure";
|
|
350
|
+
cause: Cause<E>;
|
|
351
|
+
};
|
|
352
|
+
declare const Exit: {
|
|
353
|
+
succeed: <E = never, A = never>(value: A) => Exit<E, A>;
|
|
354
|
+
failCause: <E = never, A = never>(cause: Cause<E>) => Exit<E, A>;
|
|
287
355
|
};
|
|
288
356
|
type ZIO<R, E, A> = Async<R, E, A>;
|
|
289
357
|
declare const succeed: <A>(value: A) => ZIO<unknown, never, A>;
|
|
@@ -327,12 +395,19 @@ type Scoped<R, E, A> = {
|
|
|
327
395
|
readonly acquire: ZIO<R, E, ZStream<R, E, A>>;
|
|
328
396
|
readonly release: (exit: Exit<any, any>) => Async<R, any, void>;
|
|
329
397
|
};
|
|
330
|
-
type
|
|
398
|
+
type Managed<R, E, A> = {
|
|
399
|
+
readonly _tag: "Managed";
|
|
400
|
+
readonly acquire: ZIO<R, E, {
|
|
401
|
+
stream: ZStream<R, E, A>;
|
|
402
|
+
release: (exit: Exit<any, any>) => Async<R, any, void>;
|
|
403
|
+
}>;
|
|
404
|
+
};
|
|
405
|
+
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> | Managed<R, E, A>;
|
|
331
406
|
type Normalize<E> = (u: unknown) => E;
|
|
332
407
|
declare const widenOpt: <E1, E2>(opt: Option<E1>) => Option<E1 | E2>;
|
|
333
408
|
declare const fromPull: <R, E, A>(pull: ZIO<R, Option<E>, [A, ZStream<R, E, A>]>) => ZStream<R, E, A>;
|
|
334
409
|
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>;
|
|
335
|
-
declare const managedStream: <R, E, A>(acquire:
|
|
410
|
+
declare const managedStream: <R, E, A>(acquire: ZIO<R, E, {
|
|
336
411
|
stream: ZStream<R, E, A>;
|
|
337
412
|
release: (exit: Exit<any, any>) => Async<R, any, void>;
|
|
338
413
|
}>) => ZStream<R, E, A>;
|
|
@@ -352,4 +427,4 @@ declare function fromArray<A>(values: readonly A[]): ZStream<unknown, never, A>;
|
|
|
352
427
|
declare function collectStream<R, E, A>(stream: ZStream<R, E, A>): ZIO<R, E, A[]>;
|
|
353
428
|
declare function streamFromReadableStream<E>(body: ReadableStream<Uint8Array> | null | undefined, normalizeError: Normalize<E>): ZStream<unknown, E, Uint8Array>;
|
|
354
429
|
|
|
355
|
-
export {
|
|
430
|
+
export { unsafeGetCurrentRuntime as $, Async as A, mapTryAsync as B, Cause as C, type Some as D, Exit as E, type Fiber as F, none as G, some as H, type Canceler as I, type CancelToken as J, makeCancelToken as K, linkAbortController as L, fork as M, type None as N, type Option as O, unsafeRunAsync as P, toPromise as Q, Runtime as R, Scope as S, fromPromiseAbortable as T, unsafeRunFoldWithEnv as U, type FiberId as V, type FiberStatus as W, type Interrupted as X, RuntimeFiber as Y, type ZStream as Z, getCurrentFiber as _, type ZIO as a, withCurrentFiber as a0, type ScopeId as a1, withScopeAsync as a2, withScope as a3, type Task as a4, Scheduler as a5, globalScheduler as a6, type Empty as a7, type Emit as a8, type Concat as a9, type Flatten as aa, type FromPull as ab, type Merge as ac, type Scoped as ad, type Managed as ae, type Normalize as af, widenOpt as ag, fromPull as ah, unwrapScoped as ai, managedStream as aj, mergeStream as ak, emptyStream as al, emitStream as am, concatStream as an, flattenStream as ao, merge as ap, uncons as aq, assertNever as ar, mapStream as as, rangeStream as at, zip as au, foreachStream as av, fromArray as aw, collectStream as ax, streamFromReadableStream as ay, sync as b, flatMap as c, mapError as d, catchAll as e, fail as f, end as g, asyncFold as h, asyncCatchAll as i, asyncMapError as j, asyncSucceed as k, asyncFail as l, map as m, asyncSync as n, orElseOptional as o, asyncTotal as p, async as q, asyncMap as r, succeed as s, asyncFlatMap as t, unit as u, acquireRelease as v, asyncInterruptible as w, type AsyncWithPromise as x, withAsyncPromise as y, mapAsync as z };
|
|
@@ -63,17 +63,64 @@ type RuntimeEvent = {
|
|
|
63
63
|
message: string;
|
|
64
64
|
fields?: Record<string, unknown>;
|
|
65
65
|
};
|
|
66
|
+
type RuntimeEmitContext = {
|
|
67
|
+
fiberId?: number;
|
|
68
|
+
scopeId?: number;
|
|
69
|
+
traceId?: string;
|
|
70
|
+
spanId?: string;
|
|
71
|
+
};
|
|
66
72
|
interface RuntimeHooks {
|
|
67
73
|
emit(ev: RuntimeEvent, ctx: RuntimeEmitContext): void;
|
|
68
74
|
}
|
|
69
|
-
type
|
|
70
|
-
|
|
75
|
+
type RuntimeEventRecord = RuntimeEvent & RuntimeEmitContext & {
|
|
76
|
+
seq: number;
|
|
77
|
+
wallTs: number;
|
|
78
|
+
ts: number;
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
type FiberRunState = "Queued" | "Running" | "Suspended" | "Done";
|
|
82
|
+
type FiberInfo = {
|
|
83
|
+
fiberId: number;
|
|
84
|
+
parentFiberId?: number;
|
|
85
|
+
name?: string;
|
|
86
|
+
runState: FiberRunState;
|
|
87
|
+
status: "Running" | "Done" | "Interrupted";
|
|
88
|
+
createdAt: number;
|
|
89
|
+
lastActiveAt: number;
|
|
71
90
|
scopeId?: number;
|
|
72
91
|
traceId?: string;
|
|
73
92
|
spanId?: string;
|
|
93
|
+
awaiting?: {
|
|
94
|
+
reason: string;
|
|
95
|
+
detail?: string;
|
|
96
|
+
};
|
|
97
|
+
lastEnd?: {
|
|
98
|
+
status: string;
|
|
99
|
+
error?: string;
|
|
100
|
+
};
|
|
101
|
+
};
|
|
102
|
+
type ScopeInfo = {
|
|
103
|
+
scopeId: number;
|
|
104
|
+
parentScopeId?: number;
|
|
105
|
+
ownerFiberId?: number;
|
|
106
|
+
openAt: number;
|
|
107
|
+
closedAt?: number;
|
|
108
|
+
finalizers: Array<{
|
|
109
|
+
id: number;
|
|
110
|
+
label?: string;
|
|
111
|
+
status: "added" | "running" | "done";
|
|
112
|
+
}>;
|
|
74
113
|
};
|
|
114
|
+
declare class RuntimeRegistry implements RuntimeHooks {
|
|
115
|
+
fibers: Map<number, FiberInfo>;
|
|
116
|
+
scopes: Map<number, ScopeInfo>;
|
|
117
|
+
private seq;
|
|
118
|
+
private recent;
|
|
119
|
+
private recentCap;
|
|
120
|
+
emit(ev: RuntimeEvent, ctx: RuntimeEmitContext): void;
|
|
121
|
+
getRecentEvents(): RuntimeEventRecord[];
|
|
122
|
+
}
|
|
75
123
|
|
|
76
|
-
type NodeCallback<A> = (err: Error | null, result: A) => void;
|
|
77
124
|
/**
|
|
78
125
|
* --- Runtime como objeto único (ZIO-style) ---
|
|
79
126
|
* Un valor que representa "cómo" se ejecutan los efectos: scheduler + environment + hooks.
|
|
@@ -83,48 +130,41 @@ declare class Runtime<R> {
|
|
|
83
130
|
readonly scheduler: Scheduler;
|
|
84
131
|
readonly hooks: RuntimeHooks;
|
|
85
132
|
readonly forkPolicy: {
|
|
86
|
-
initChild(fiber: RuntimeFiber<any, any, any> & any, parent?: (RuntimeFiber<any, any, any> & any) | null): void;
|
|
133
|
+
initChild(fiber: RuntimeFiber<any, any, any> & any, parent?: (RuntimeFiber<any, any, any> & any) | null, scopeId?: number): void;
|
|
87
134
|
};
|
|
135
|
+
registry?: RuntimeRegistry;
|
|
88
136
|
constructor(args: {
|
|
89
137
|
env: R;
|
|
90
138
|
scheduler?: Scheduler;
|
|
91
139
|
hooks?: RuntimeHooks;
|
|
92
140
|
});
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
toPromise<E, A>(effect: Async<R, E, A>): Promise<A>;
|
|
96
|
-
log(level: "debug" | "info" | "warn" | "error", message: string, fields?: Record<string, unknown>): void;
|
|
97
|
-
withHooks(hooks: RuntimeHooks): Runtime<R>;
|
|
141
|
+
/** Deriva un runtime con env extendido (estilo provide/locally) */
|
|
142
|
+
provide<R2>(env: R2): Runtime<R & R2>;
|
|
98
143
|
emit(ev: RuntimeEvent): void;
|
|
144
|
+
/**
|
|
145
|
+
* ✅ CAMBIO: fork(effect, scopeId?) y pasa scopeId a forkPolicy
|
|
146
|
+
*/
|
|
147
|
+
fork<E, A>(effect: Async<R, E, A>, scopeId?: number): Fiber<E, A>;
|
|
148
|
+
unsafeRunAsync<E, A>(effect: Async<R, E, A>, cb: (exit: Exit<E, A>) => void): void;
|
|
149
|
+
toPromise<E, A>(effect: Async<R, E, A>): Promise<A>;
|
|
150
|
+
unsafeRun<E, A>(effect: Async<R, E, A>): void;
|
|
151
|
+
delay<E, A>(ms: number, eff: Async<R, E, A>): Async<R, E, A>;
|
|
99
152
|
static make<R>(env: R, scheduler?: Scheduler): Runtime<R>;
|
|
153
|
+
/** Convenience logger: emits a RuntimeEvent of type "log". */
|
|
154
|
+
log(level: "debug" | "info" | "warn" | "error", message: string, fields?: Record<string, unknown>): void;
|
|
100
155
|
}
|
|
156
|
+
/** Create a runtime from `env` and fork the given effect. */
|
|
157
|
+
declare function fork<R, E, A>(effect: Async<R, E, A>, env?: R): Fiber<E, A>;
|
|
158
|
+
/** Run an effect with `env` and invoke `cb` with the final Exit. */
|
|
159
|
+
declare function unsafeRunAsync<R, E, A>(effect: Async<R, E, A>, env: R | undefined, cb: (exit: Exit<E, A>) => void): void;
|
|
160
|
+
/** Run an effect with `env` and return a Promise of its success value. */
|
|
161
|
+
declare function toPromise<R, E, A>(effect: Async<R, E, A>, env?: R): Promise<A>;
|
|
101
162
|
/**
|
|
102
|
-
*
|
|
103
|
-
*
|
|
104
|
-
* ---------------------------------------------------------------------------
|
|
163
|
+
* Create an Async from an abortable Promise.
|
|
164
|
+
* Type params are ordered as `<E, A, R = unknown>` to match call-sites.
|
|
105
165
|
*/
|
|
106
|
-
declare function
|
|
107
|
-
declare function
|
|
108
|
-
type BrassError = {
|
|
109
|
-
_tag: "Abort";
|
|
110
|
-
} | {
|
|
111
|
-
_tag: "PromiseRejected";
|
|
112
|
-
reason: unknown;
|
|
113
|
-
};
|
|
114
|
-
/**
|
|
115
|
-
* --- Wrappers legacy (mantienen tu API actual) ---
|
|
116
|
-
* Internamente crean un Runtime ad-hoc con env + scheduler.
|
|
117
|
-
*/
|
|
118
|
-
declare function fork<R, E, A>(effect: Async<R, E, A>, env: R, scheduler?: Scheduler): Fiber<E, A>;
|
|
119
|
-
declare function unsafeRunAsync<R, E, A>(effect: Async<R, E, A>, env: R, cb: (exit: Exit<E | Interrupted, A>) => void): void;
|
|
120
|
-
declare function toPromise<R, E, A>(eff: Async<R, E, A>, env: R): Promise<A>;
|
|
121
|
-
declare function fromPromise<R, E, A>(thunk: (env: R) => Promise<A>, onError: (e: unknown) => E): Async<R, E, A>;
|
|
122
|
-
declare function fromCallback<A>(f: (cb: NodeCallback<A>) => void): Async<{}, Error, A>;
|
|
123
|
-
declare function tryPromiseAbortable<A>(thunk: (signal: AbortSignal) => Promise<A>): Async<unknown, BrassError, A>;
|
|
124
|
-
declare function tryPromiseAbortable<R, A>(thunk: (env: R, signal: AbortSignal) => Promise<A>): Async<R, BrassError, A>;
|
|
125
|
-
declare function fromPromiseAbortable<E, A>(thunk: (signal: AbortSignal) => Promise<A>, onError: (e: unknown) => E): Async<unknown, E, A>;
|
|
126
|
-
declare function fromPromiseAbortable<R, E, A>(thunk: (env: R, signal: AbortSignal) => Promise<A>, onError: (e: unknown) => E): Async<R, E, A>;
|
|
127
|
-
declare function getCurrentRuntime<R>(): Runtime<R>;
|
|
166
|
+
declare function fromPromiseAbortable<E, A, R = unknown>(make: (signal: AbortSignal, env: R) => Promise<A>, onReject: (u: unknown) => E): Async<R, E, A>;
|
|
167
|
+
declare function unsafeRunFoldWithEnv<R, E, A>(eff: Async<R, E, A>, env: R, onFailure: (cause: Cause<E>) => void, onSuccess: (value: A) => void): void;
|
|
128
168
|
|
|
129
169
|
type JSONValue = null | boolean | number | string | JSONValue[] | {
|
|
130
170
|
[k: string]: JSONValue;
|
|
@@ -145,17 +185,16 @@ type FiberContext = {
|
|
|
145
185
|
};
|
|
146
186
|
|
|
147
187
|
type FiberId = number;
|
|
188
|
+
type FiberStatus = "Running" | "Done" | "Interrupted";
|
|
148
189
|
type Interrupted = {
|
|
149
|
-
readonly _tag: "
|
|
190
|
+
readonly _tag: "Interrupt";
|
|
150
191
|
};
|
|
151
|
-
type FiberStatus = "Running" | "Done" | "Interrupted";
|
|
152
|
-
type StepDecision = "Continue" | "Suspend" | "Done";
|
|
153
192
|
type Fiber<E, A> = {
|
|
154
193
|
readonly id: FiberId;
|
|
155
194
|
readonly status: () => FiberStatus;
|
|
156
|
-
readonly join: (cb: (exit: Exit<E
|
|
195
|
+
readonly join: (cb: (exit: Exit<E, A>) => void) => void;
|
|
157
196
|
readonly interrupt: () => void;
|
|
158
|
-
readonly addFinalizer: (f: (exit: Exit<E
|
|
197
|
+
readonly addFinalizer: (f: (exit: Exit<E, A>) => void) => void;
|
|
159
198
|
};
|
|
160
199
|
declare class RuntimeFiber<R, E, A> implements Fiber<E, A> {
|
|
161
200
|
readonly id: FiberId;
|
|
@@ -176,18 +215,25 @@ declare class RuntimeFiber<R, E, A> implements Fiber<E, A> {
|
|
|
176
215
|
constructor(runtime: Runtime<R>, effect: Async<R, E, A>);
|
|
177
216
|
private get env();
|
|
178
217
|
private get scheduler();
|
|
179
|
-
|
|
218
|
+
private emit;
|
|
219
|
+
addFinalizer(f: (exit: Exit<E, A>) => void): void;
|
|
180
220
|
status(): FiberStatus;
|
|
181
|
-
join(cb: (exit: Exit<E
|
|
221
|
+
join(cb: (exit: Exit<E, A>) => void): void;
|
|
182
222
|
interrupt(): void;
|
|
183
223
|
schedule(tag?: string): void;
|
|
184
224
|
private runFinalizersOnce;
|
|
185
225
|
private notify;
|
|
186
226
|
private onSuccess;
|
|
187
227
|
private onFailure;
|
|
188
|
-
|
|
228
|
+
private budget;
|
|
229
|
+
private step;
|
|
189
230
|
}
|
|
190
231
|
declare function getCurrentFiber(): RuntimeFiber<any, any, any> | null;
|
|
232
|
+
/**
|
|
233
|
+
* Unsafe (but convenient) access to the runtime that is currently executing.
|
|
234
|
+
* Throws if called outside of a running fiber.
|
|
235
|
+
*/
|
|
236
|
+
declare function unsafeGetCurrentRuntime<R>(): Runtime<R>;
|
|
191
237
|
declare function withCurrentFiber<T>(fiber: RuntimeFiber<any, any, any>, f: () => T): T;
|
|
192
238
|
|
|
193
239
|
type ScopeId = number;
|
|
@@ -196,55 +242,59 @@ type CloseOptions = {
|
|
|
196
242
|
};
|
|
197
243
|
declare class Scope<R> {
|
|
198
244
|
private readonly runtime;
|
|
245
|
+
private readonly parentScopeId?;
|
|
199
246
|
readonly id: ScopeId;
|
|
200
247
|
private closed;
|
|
201
248
|
private readonly children;
|
|
202
249
|
private readonly subScopes;
|
|
203
250
|
private readonly finalizers;
|
|
204
|
-
constructor(runtime: Runtime<R
|
|
205
|
-
/** Acceso al env del runtime (conserva tu modelo actual) */
|
|
206
|
-
private get env();
|
|
251
|
+
constructor(runtime: Runtime<R>, parentScopeId?: ScopeId | undefined);
|
|
207
252
|
/** registra un finalizer (LIFO) */
|
|
208
253
|
addFinalizer(f: (exit: Exit<any, any>) => Async<R, any, any>): void;
|
|
209
254
|
/** crea un sub scope (mismo runtime) */
|
|
210
255
|
subScope(): Scope<R>;
|
|
211
|
-
/** fork en este scope */
|
|
212
|
-
fork<E, A>(eff: Async<R, E, A>): Fiber<E
|
|
256
|
+
/** ✅ fork en este scope */
|
|
257
|
+
fork<E, A>(eff: Async<R, E, A>): Fiber<E, A>;
|
|
213
258
|
/** close fire-and-forget (no bloquea) */
|
|
214
259
|
close(exit?: Exit<any, any>): void;
|
|
215
|
-
closeAsync(exit?: Exit<any, any>,
|
|
260
|
+
closeAsync(exit?: Exit<any, any>, opts?: CloseOptions): Async<R, any, void>;
|
|
216
261
|
}
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
declare function withScope<R, A>(runtime: Runtime<R>, body: (scope: Scope<R>) => A): A;
|
|
222
|
-
/**
|
|
223
|
-
* Versión async: crea scope, corre el efecto, cierra el scope con el Exit.
|
|
224
|
-
*/
|
|
225
|
-
declare function withScopeAsync<R, E, A>(runtime: Runtime<R>, use: (scope: Scope<R>) => Async<R, E, A>): Async<R, E | Interrupted, A>;
|
|
262
|
+
declare function withScopeAsync<R, E, A>(runtime: Runtime<R>, f: (scope: Scope<R>) => Async<R, E, A>): Async<R, E, A>;
|
|
263
|
+
|
|
264
|
+
declare function withScope<R>(runtime: Runtime<R>, f: (scope: Scope<R>) => void): Async<R, never, void>;
|
|
265
|
+
declare function withScope<R, E, A>(runtime: Runtime<R>, f: (scope: Scope<R>) => Async<R, E, A>): Async<R, E, A>;
|
|
226
266
|
|
|
227
267
|
type Async<R, E, A> = {
|
|
228
|
-
_tag: "Succeed";
|
|
229
|
-
value: A;
|
|
268
|
+
readonly _tag: "Succeed";
|
|
269
|
+
readonly value: A;
|
|
230
270
|
} | {
|
|
231
|
-
_tag: "Fail";
|
|
232
|
-
error: E;
|
|
271
|
+
readonly _tag: "Fail";
|
|
272
|
+
readonly error: E;
|
|
273
|
+
} | {
|
|
274
|
+
readonly _tag: "Sync";
|
|
275
|
+
readonly thunk: (env: R) => A;
|
|
233
276
|
} | {
|
|
234
|
-
_tag: "
|
|
235
|
-
|
|
277
|
+
readonly _tag: "Async";
|
|
278
|
+
readonly register: (env: R, cb: (exit: Exit<E, A>) => void) => void | (() => void);
|
|
236
279
|
} | {
|
|
237
|
-
_tag: "
|
|
238
|
-
|
|
280
|
+
readonly _tag: "FlatMap";
|
|
281
|
+
readonly first: Async<R, E, any>;
|
|
282
|
+
readonly andThen: (a: any) => Async<R, E, A>;
|
|
239
283
|
} | {
|
|
240
|
-
_tag: "
|
|
241
|
-
first: Async<R, E, any>;
|
|
242
|
-
|
|
284
|
+
readonly _tag: "Fold";
|
|
285
|
+
readonly first: Async<R, E, any>;
|
|
286
|
+
readonly onFailure: (e: any) => Async<R, E, A>;
|
|
287
|
+
readonly onSuccess: (a: any) => Async<R, E, A>;
|
|
243
288
|
} | {
|
|
244
|
-
_tag: "
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
289
|
+
readonly _tag: "Fork";
|
|
290
|
+
readonly effect: Async<R, E, any>;
|
|
291
|
+
readonly scopeId?: number;
|
|
292
|
+
};
|
|
293
|
+
declare const Async: {
|
|
294
|
+
succeed: <R, E, A>(value: A) => Async<R, E, A>;
|
|
295
|
+
fail: <R, E, A = never>(error: E) => Async<R, E, A>;
|
|
296
|
+
sync: <R, E, A>(thunk: (env: R) => A) => Async<R, E, A>;
|
|
297
|
+
async: <R, E, A>(register: (env: R, cb: (exit: Exit<E, A>) => void) => void | (() => void)) => Async<R, E, A>;
|
|
248
298
|
};
|
|
249
299
|
declare function asyncFold<R, E, A, B>(fa: Async<R, E, A>, onFailure: (e: E) => Async<R, E, B>, onSuccess: (a: A) => Async<R, E, B>): Async<R, E, B>;
|
|
250
300
|
declare function asyncCatchAll<R, E, A, R2, E2, B>(fa: Async<R, E, A>, handler: (e: E) => Async<R2, E2, B>): Async<R & R2, E2, A | B>;
|
|
@@ -278,12 +328,30 @@ type Option<A> = None | Some<A>;
|
|
|
278
328
|
declare const none: Option<never>;
|
|
279
329
|
declare const some: <A>(value: A) => Option<A>;
|
|
280
330
|
|
|
331
|
+
type Cause<E> = {
|
|
332
|
+
readonly _tag: "Fail";
|
|
333
|
+
readonly error: E;
|
|
334
|
+
} | {
|
|
335
|
+
readonly _tag: "Interrupt";
|
|
336
|
+
} | {
|
|
337
|
+
readonly _tag: "Die";
|
|
338
|
+
readonly defect: unknown;
|
|
339
|
+
};
|
|
340
|
+
declare const Cause: {
|
|
341
|
+
fail: <E>(error: E) => Cause<E>;
|
|
342
|
+
interrupt: <E = never>() => Cause<E>;
|
|
343
|
+
die: <E = never>(defect: unknown) => Cause<E>;
|
|
344
|
+
};
|
|
281
345
|
type Exit<E, A> = {
|
|
282
|
-
|
|
283
|
-
|
|
346
|
+
_tag: "Success";
|
|
347
|
+
value: A;
|
|
284
348
|
} | {
|
|
285
|
-
|
|
286
|
-
|
|
349
|
+
_tag: "Failure";
|
|
350
|
+
cause: Cause<E>;
|
|
351
|
+
};
|
|
352
|
+
declare const Exit: {
|
|
353
|
+
succeed: <E = never, A = never>(value: A) => Exit<E, A>;
|
|
354
|
+
failCause: <E = never, A = never>(cause: Cause<E>) => Exit<E, A>;
|
|
287
355
|
};
|
|
288
356
|
type ZIO<R, E, A> = Async<R, E, A>;
|
|
289
357
|
declare const succeed: <A>(value: A) => ZIO<unknown, never, A>;
|
|
@@ -327,12 +395,19 @@ type Scoped<R, E, A> = {
|
|
|
327
395
|
readonly acquire: ZIO<R, E, ZStream<R, E, A>>;
|
|
328
396
|
readonly release: (exit: Exit<any, any>) => Async<R, any, void>;
|
|
329
397
|
};
|
|
330
|
-
type
|
|
398
|
+
type Managed<R, E, A> = {
|
|
399
|
+
readonly _tag: "Managed";
|
|
400
|
+
readonly acquire: ZIO<R, E, {
|
|
401
|
+
stream: ZStream<R, E, A>;
|
|
402
|
+
release: (exit: Exit<any, any>) => Async<R, any, void>;
|
|
403
|
+
}>;
|
|
404
|
+
};
|
|
405
|
+
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> | Managed<R, E, A>;
|
|
331
406
|
type Normalize<E> = (u: unknown) => E;
|
|
332
407
|
declare const widenOpt: <E1, E2>(opt: Option<E1>) => Option<E1 | E2>;
|
|
333
408
|
declare const fromPull: <R, E, A>(pull: ZIO<R, Option<E>, [A, ZStream<R, E, A>]>) => ZStream<R, E, A>;
|
|
334
409
|
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>;
|
|
335
|
-
declare const managedStream: <R, E, A>(acquire:
|
|
410
|
+
declare const managedStream: <R, E, A>(acquire: ZIO<R, E, {
|
|
336
411
|
stream: ZStream<R, E, A>;
|
|
337
412
|
release: (exit: Exit<any, any>) => Async<R, any, void>;
|
|
338
413
|
}>) => ZStream<R, E, A>;
|
|
@@ -352,4 +427,4 @@ declare function fromArray<A>(values: readonly A[]): ZStream<unknown, never, A>;
|
|
|
352
427
|
declare function collectStream<R, E, A>(stream: ZStream<R, E, A>): ZIO<R, E, A[]>;
|
|
353
428
|
declare function streamFromReadableStream<E>(body: ReadableStream<Uint8Array> | null | undefined, normalizeError: Normalize<E>): ZStream<unknown, E, Uint8Array>;
|
|
354
429
|
|
|
355
|
-
export {
|
|
430
|
+
export { unsafeGetCurrentRuntime as $, Async as A, mapTryAsync as B, Cause as C, type Some as D, Exit as E, type Fiber as F, none as G, some as H, type Canceler as I, type CancelToken as J, makeCancelToken as K, linkAbortController as L, fork as M, type None as N, type Option as O, unsafeRunAsync as P, toPromise as Q, Runtime as R, Scope as S, fromPromiseAbortable as T, unsafeRunFoldWithEnv as U, type FiberId as V, type FiberStatus as W, type Interrupted as X, RuntimeFiber as Y, type ZStream as Z, getCurrentFiber as _, type ZIO as a, withCurrentFiber as a0, type ScopeId as a1, withScopeAsync as a2, withScope as a3, type Task as a4, Scheduler as a5, globalScheduler as a6, type Empty as a7, type Emit as a8, type Concat as a9, type Flatten as aa, type FromPull as ab, type Merge as ac, type Scoped as ad, type Managed as ae, type Normalize as af, widenOpt as ag, fromPull as ah, unwrapScoped as ai, managedStream as aj, mergeStream as ak, emptyStream as al, emitStream as am, concatStream as an, flattenStream as ao, merge as ap, uncons as aq, assertNever as ar, mapStream as as, rangeStream as at, zip as au, foreachStream as av, fromArray as aw, collectStream as ax, streamFromReadableStream as ay, sync as b, flatMap as c, mapError as d, catchAll as e, fail as f, end as g, asyncFold as h, asyncCatchAll as i, asyncMapError as j, asyncSucceed as k, asyncFail as l, map as m, asyncSync as n, orElseOptional as o, asyncTotal as p, async as q, asyncMap as r, succeed as s, asyncFlatMap as t, unit as u, acquireRelease as v, asyncInterruptible as w, type AsyncWithPromise as x, withAsyncPromise as y, mapAsync as z };
|
package/package.json
CHANGED
package/dist/chunk-Q2H2CAII.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
'use strict';function R(t,e,n){return {_tag:"Fold",first:t,onFailure:e,onSuccess:n}}function be(t,e){return R(t,n=>e(n),n=>E(n))}function b(t,e){return R(t,n=>f(e(n)),n=>E(n))}var Z=()=>E(void 0),E=t=>({_tag:"Succeed",value:t}),f=t=>({_tag:"Fail",error:t}),_=t=>({_tag:"Sync",thunk:t}),Fe=t=>_(()=>t()),p=t=>({_tag:"Async",register:t});function Q(t,e){return A(t,n=>E(e(n)))}function A(t,e){return {_tag:"FlatMap",first:t,andThen:e}}function ke(t,e,n){return A(t,r=>(n.addFinalizer(o=>e(r,o)),E(r)))}function Ie(t){return p(t)}var _e=t=>e=>{let n=e;return n.toPromise||(n.toPromise=r=>t(e,r),n.unsafeRunPromise=()=>t(e,{})),n},we=(t,e)=>A(t,n=>E(e(n))),Oe=(t,e)=>A(t,n=>_(()=>e(n)));var F={_tag:"None"},w=t=>({_tag:"Some",value:t});var j=t=>E(t),C=t=>f(t),$=t=>_(e=>t(e)),k=(t,e)=>Q(t,e),K=(t,e)=>A(t,n=>e(n)),H=(t,e)=>b(t,e),Pe=(t,e)=>R(t,n=>e(n),n=>E(n));function q(t,e){return R(t,n=>n._tag==="Some"?f(n):e(),n=>E(n))}var Te=()=>C(F);var ie=(r=>(r[r.Ok=0]="Ok",r[r.Grew=1]="Grew",r[r.Dropped=2]="Dropped",r))(ie||{}),N=class{buf;head=0;tail=0;size_=0;maxCap;constructor(e=1024,n=e){let r=Math.max(2,this.nextPow2(e)),o=Math.max(r,this.nextPow2(n));this.buf=new Array(r),this.maxCap=o;}get length(){return this.size_}get capacity(){return this.buf.length}isEmpty(){return this.size_===0}push(e){return this.size_===this.buf.length?this.buf.length>=this.maxCap?2:(this.grow(),this.buf[this.tail]=e,this.tail=this.tail+1&this.buf.length-1,this.size_++,1):(this.buf[this.tail]=e,this.tail=this.tail+1&this.buf.length-1,this.size_++,0)}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=Math.min(e.length*2,this.maxCap),r=new Array(n);for(let o=0;o<this.size_;o++)r[o]=e[this.head+o&e.length-1];this.buf=r,this.head=0,this.tail=this.size_;}nextPow2(e){let n=1;for(;n<e;)n<<=1;return n}};var X=2048,Y=4096,se=(()=>{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)})(),L=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>Y?"macro":"micro";this.requestFlush(r);}}requestFlush(e){e==="micro"?queueMicrotask(()=>this.flush()):se(()=>this.flush());}flush(){if(this.flushing)return;this.flushing=true,this.scheduled=false;let e=0;try{for(;e<X;){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>=X||this.queue.length>Y?"macro":"micro";this.requestFlush(n);}}}},B=new L;var P=null,h={CONTINUE:"Continue",SUSPEND:"Suspend",DONE:"Done"},g={QUEUED:"Queued",RUNNING:"Running",SUSPENDED:"Suspended",DONE:"Done"},ce=1,ue=1024;function le(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:o=>({_tag:"FlatMap",first:n.andThen(o),andThen:r})};}return e}var T=class{id;runtime;closing=null;finishing=false;runState=g.RUNNING;interrupted=false;result=null;joiners=[];current;stack=[];fiberFinalizers=[];finalizersDrained=false;fiberContext;name;scopeId;constructor(e,n){this.id=ce++,this.runtime=e,this.current=n;}get env(){return this.runtime.env}get scheduler(){return this.runtime.scheduler}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===g.DONE||this.runState===g.QUEUED||(this.runState=g.QUEUED,this.scheduler.schedule(()=>{pe(this,()=>{if(this.runState===g.DONE)return;switch(this.runState=g.RUNNING,this.step()){case h.CONTINUE:this.schedule("continue");return;case h.SUSPEND:this.runState=g.SUSPENDED;return;case h.DONE:this.runState=g.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=ue;for(;e-- >0;){if(this.result!=null)return h.DONE;if(this.interrupted&&this.closing==null)return this.notify({_tag:"Failure",error:{_tag:"Interrupted"}}),h.DONE;let n=le(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?h.DONE:h.CONTINUE;let r=false,o=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")));},a=n.register(this.env,o);return typeof a=="function"&&this.addFinalizer(()=>{r=true;try{a();}catch{}}),h.SUSPEND}}}return this.result!=null?h.DONE:h.CONTINUE}};function D(){return P}function pe(t,e){let n=P;P=t;try{return e()}finally{P=n;}}var ee={parent:null,patch:Object.create(null)};function te(t,e){let n=Ee(t);return {initChild(r,o){let a=o?.fiberContext,i=Ae(n,a?.trace??null);r.fiberContext={log:a?.log??ee,trace:i},r.parentFiberId=o?.id,r.name=n.childName(o?.name),e.emit({type:"fiber.start",fiberId:r.id,parentFiberId:o?.id,name:r.name},{fiberId:o?.id,traceId:a?.trace?.traceId,spanId:a?.trace?.spanId});}}}function Ee(t){let e={newTraceId:()=>crypto.randomUUID(),newSpanId:()=>crypto.randomUUID()},n=t?.brass,r=n?.tracer??e,o=n?.traceSeed,a=n?.childName??(i=>i?`${i}/child`:void 0);return {tracer:r,seed:o,childName:a}}function Ae(t,e){return e?{traceId:e.traceId,spanId:t.tracer.newSpanId(),parentSpanId:e.spanId,sampled:e.sampled}:t.seed?{...t.seed}:{traceId:t.tracer.newTraceId(),spanId:t.tracer.newSpanId(),sampled:true}}var de={emit(){}},O=class t{env;scheduler;hooks;forkPolicy;constructor(e){this.env=e.env,this.scheduler=e.scheduler??B,this.hooks=e.hooks??de,this.forkPolicy=te(this.env,this.hooks);}fork(e){let n=D(),r=new T(this,e);return this.forkPolicy.initChild(r,n),r.schedule("initial-step"),r}unsafeRunAsync(e,n){this.fork(e).join(n);}toPromise(e){return new Promise((n,r)=>{this.fork(e).join(a=>{let i=a;i._tag==="Success"?n(i.value):r(i.error);});})}log(e,n,r){this.emit({type:"log",level:e,message:n,fields:r});}withHooks(e){return new t({env:this.env,scheduler:this.scheduler,hooks:e})}emit(e){let n=D(),r={fiberId:n?.id,scopeId:n?.scope?.id,traceId:n?.fiberContext?.trace?.traceId,spanId:n?.fiberContext?.trace?.spanId};this.hooks.emit(e,r);}static make(e,n=B){return new t({env:e,scheduler:n})}};function Ye(t){return p((e,n)=>{let r=false,o=s=>{r||(r=true,n(s));},a=s=>o({_tag:"Failure",error:s instanceof Error?s:new Error(String(s))}),i=s=>o({_tag:"Success",value:s});try{typeof t=="function"&&t.length>=1?t((s,c)=>s?a(s):i(c)):t().then(i,a);}catch(s){a(s);}})}function et(t,e,n=B){return new O({env:e,scheduler:n}).fork(t)}function tt(t,e,n){return new O({env:e}).unsafeRunAsync(t,n)}function nt(t,e){return new O({env:e}).toPromise(t)}function rt(t,e){return p((n,r)=>{t(n).then(o=>r({_tag:"Success",value:o})).catch(o=>r({_tag:"Failure",error:e(o)}));})}function ot(t){return p((e,n)=>{let r=false,o=a=>{r||(r=true,n(a));};try{t((a,i)=>{o(a?{_tag:"Failure",error:a}:{_tag:"Success",value:i});});}catch(a){o({_tag:"Failure",error:a instanceof Error?a:new Error(String(a))});}})}function at(t){return ye((n,r)=>t.length===1?t(r):t(n,r),n=>Re(n)?{_tag:"Abort"}:{_tag:"PromiseRejected",reason:n})}function ye(t,e){return p((n,r)=>{let o=new AbortController,a=false,i=s=>{a||(a=true,r(s));};try{(t.length===1?t(o.signal):t(n,o.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 ()=>{a=true,o.abort();}})}var Re=t=>typeof t=="object"&&t!==null&&"name"in t&&t.name==="AbortError";function G(){let t=D();if(!t)throw new Error("No current runtime: est\xE1s llamando esto fuera de un fiber (fuera del runtime).");return t.runtime}var me=1;function fe(t){return p((e,n)=>{let r=t.length;if(r===0){n({_tag:"Success",value:void 0});return}for(let o of t)o.join(()=>{r-=1,r===0&&n({_tag:"Success",value:void 0});});})}function he(t){return R(t,()=>Z(),()=>Z())}var I=class t{constructor(e){this.runtime=e;this.id=me++;}id;closed=false;children=new Set;subScopes=new Set;finalizers=[];get env(){return this.runtime.env}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.runtime);return this.subScopes.add(e),e}fork(e){if(this.closed)throw new Error("Scope closed");let n=this.runtime.fork(e);return this.children.add(n),n.join(()=>{this.children.delete(n);}),n}close(e={_tag:"Success",value:void 0}){this.runtime.fork(this.closeAsync(e));}closeAsync(e={_tag:"Success",value:void 0},n={}){return p((r,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 s=Z();for(let l of i)s=A(s,()=>l.closeAsync(e,n));for(;this.finalizers.length>0;){let l=this.finalizers.pop();s=A(s,()=>he(l(e)));}n.awaitChildren&&(s=A(s,()=>fe(a))),this.runtime.fork(s).join(()=>o({_tag:"Success",value:void 0}));})}};function ut(t,e){let n=new I(t);try{return e(n)}finally{n.close();}}function lt(t,e){return p((n,r)=>{let o=new I(t);o.fork(e(o)).join(i=>{try{o.close(i);}catch(s){r({_tag:"Failure",error:s});return}r(i);});})}function dt(t,e,n){return p((r,o)=>{let a=n.subScope(),i=false,s=m=>{i||(i=true,a.close(m),o(m));},c=a.fork(t),l=a.fork(e);c.join(s),l.join(s);})}function yt(t,e,n){return p((r,o)=>{let a=n.subScope(),i=null,s=null,c=false,l=()=>{if(!i||!s||c)return;if(c=true,i._tag==="Success"&&s._tag==="Success"){a.close({_tag:"Success",value:void 0}),o({_tag:"Success",value:[i.value,s.value]});return}let u;if(i._tag==="Failure")u=i.error;else if(s._tag==="Failure")u=s.error;else throw new Error("zipPar: unreachable state (no Failure exit)");let v={_tag:"Failure",error:u};a.close(v),o(v);},m=a.fork(t),y=a.fork(e);m.join(u=>{i=u,l();}),y.join(u=>{s=u,l();});})}function Rt(t,e){return p((n,r)=>{let o=e.subScope(),a=new Array(t.length),i=0,s=false;t.forEach((c,l)=>{o.fork(c).join(y=>{if(!s){if(y._tag==="Failure"){s=true;let u={_tag:"Failure",error:y.error};o.close(u),r(u);return}if(a[l]=y.value,i++,i===t.length){s=true;let u={_tag:"Success",value:a};o.close({_tag:"Success",value:void 0}),r(u);}}});});})}function ne(t,e,n,r,o){return p((a,i)=>{let s=n.subScope(),c=false,l=s.fork(t),m=s.fork(e),y=u=>{s.fork(u).join(v=>{s.close(v),i(v);});};l.join(u=>{c||(c=true,y(r(u,m,s)));}),m.join(u=>{c||(c=true,y(o(u,l,s)));});})}var J=t=>t._tag==="None"?F:w(t.value),x=t=>({_tag:"FromPull",pull:t}),oe=(t,e)=>({_tag:"Scoped",acquire:t,release:e}),Ot=t=>({_tag:"Scoped",acquire:A(t,e=>E(e.stream)),release:e=>A(t,n=>n.release(e))}),ge=(t,e,n=true)=>({_tag:"Merge",left:t,right:e,flip:n}),M=()=>({_tag:"Empty"}),ae=t=>({_tag:"Emit",value:t}),z=(t,e)=>({_tag:"Concat",left:t,right:e}),V=t=>({_tag:"Flatten",stream:t});function re(t,e,n,r,o){return (a,i,s)=>{if(a._tag,a._tag,a._tag==="Success"){let[m,y]=a.value;i.interrupt();let u=x(t==="L"?U(y,n):U(e,y));return E([m,u])}let c=a.error;if(typeof c=="object"&&c!==null&&c._tag==="Interrupted")return f(c);let l=c;return l._tag==="None"?d(t==="L"?n:e):f(l)}}function U(t,e,n,r){return p((o,a)=>{let s=G(),c=new I(s),l=d(t),m=d(e),y=re("L",t,e),u=re("R",t,e),v=ne(l,m,c,y,u);c.fork(v).join(W=>{c.close(W),a(W);});})}function Zt(t,e){return x(U(t,e))}function d(t){switch(t._tag){case "Empty":return C(F);case "Emit":return k(H(t.value,e=>w(e)),e=>[e,M()]);case "FromPull":return t.pull;case "Concat":return q(k(d(t.left),([e,n])=>[e,z(n,t.right)]),()=>d(t.right));case "Flatten":return K(d(t.stream),([e,n])=>q(k(d(e),([r,o])=>[r,z(o,V(n))]),()=>d(V(n))));case "Merge":return U(t.left,t.right,t.flip);case "Scoped":return p((e,n)=>{let r=G(),o=new I(r);o.addFinalizer(a=>t.release(a)),o.fork(t.acquire).join(a=>{if(a._tag==="Failure"){o.close(a),n({_tag:"Failure",error:w(a.error)});return}let i=a.value;d(i)(e,c=>{o.close(c),n(c);});});})}}function Se(t,e){throw new Error(e??`Unexpected value: ${String(t)}`)}function S(t,e){switch(t._tag){case "Empty":return M();case "Emit":return ae(k(t.value,e));case "FromPull":return x(k(t.pull,([n,r])=>[e(n),S(r,e)]));case "Concat":return z(S(t.left,e),S(t.right,e));case "Flatten":{let n=S(t.stream,r=>S(r,e));return V(n)}case "Merge":return ge(S(t.left,e),S(t.right,e),t.flip);case "Scoped":return oe(k(t.acquire,n=>S(n,e)),t.release);default:return Se(t)}}function Ct(t,e){let n=r=>x(r>e?f(F):E([r,n(r+1)]));return n(t)}function xe(t,e){let n=R(b(d(t),r=>J(r)),r=>f(r),([r,o])=>R(b(d(e),a=>J(a)),a=>f(a),([a,i])=>E([[r,a],xe(o,i)])));return x(n)}function Nt(t,e){let n=r=>R(b(d(r),o=>J(o)),o=>o._tag==="None"?E(void 0):f(o),([o,a])=>A(b(e(o),i=>w(i)),()=>n(a)));return R(n(t),r=>r._tag==="None"?E(void 0):f(r.value),()=>E(void 0))}function Bt(t){let e=M();for(let n=t.length-1;n>=0;n--){let r=ae(j(t[n]));e=z(r,e);}return e}function Pt(t){let e=(n,r)=>R(d(n),o=>o._tag==="None"?j(r):C(o),([o,a])=>e(a,[...r,o]));return H(e(t,[]),n=>{if(n._tag==="Some")return n.value;throw new Error("unreachable: stream end handled as success")})}function ve(t,e){let n=p((r,o)=>{t.read().then(({done:a,value:i})=>{if(a){o({_tag:"Failure",error:F});return}o({_tag:"Success",value:[i,x(n)]});}).catch(a=>{o({_tag:"Failure",error:w(e(a))});});});return x(n)}function Tt(t,e){if(!t)return M();let n;return oe($(()=>(n=t.getReader(),ve(n,e))),()=>_(()=>{try{n?.cancel();}catch{}}))}exports.$=oe;exports.A=Te;exports.B=ie;exports.C=N;exports.D=L;exports.E=B;exports.F=T;exports.G=D;exports.H=pe;exports.I=O;exports.J=Ye;exports.K=et;exports.L=tt;exports.M=nt;exports.N=rt;exports.O=ot;exports.P=at;exports.Q=ye;exports.R=G;exports.S=I;exports.T=ut;exports.U=lt;exports.V=dt;exports.W=yt;exports.X=Rt;exports.Y=ne;exports.Z=J;exports._=x;exports.a=R;exports.aa=Ot;exports.b=be;exports.ba=ge;exports.c=b;exports.ca=M;exports.d=Z;exports.da=ae;exports.e=E;exports.ea=z;exports.f=f;exports.fa=V;exports.g=_;exports.ga=Zt;exports.h=Fe;exports.ha=d;exports.i=p;exports.ia=Se;exports.j=Q;exports.ja=S;exports.k=A;exports.ka=Ct;exports.l=ke;exports.la=xe;exports.m=Ie;exports.ma=Nt;exports.n=_e;exports.na=Bt;exports.o=we;exports.oa=Pt;exports.p=Oe;exports.pa=Tt;exports.q=F;exports.r=w;exports.s=j;exports.t=C;exports.u=$;exports.v=k;exports.w=K;exports.x=H;exports.y=Pe;exports.z=q;
|
package/dist/chunk-ZXK3XM2Q.mjs
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
function R(t,e,n){return {_tag:"Fold",first:t,onFailure:e,onSuccess:n}}function be(t,e){return R(t,n=>e(n),n=>E(n))}function b(t,e){return R(t,n=>f(e(n)),n=>E(n))}var Z=()=>E(void 0),E=t=>({_tag:"Succeed",value:t}),f=t=>({_tag:"Fail",error:t}),_=t=>({_tag:"Sync",thunk:t}),Fe=t=>_(()=>t()),p=t=>({_tag:"Async",register:t});function Q(t,e){return A(t,n=>E(e(n)))}function A(t,e){return {_tag:"FlatMap",first:t,andThen:e}}function ke(t,e,n){return A(t,r=>(n.addFinalizer(o=>e(r,o)),E(r)))}function Ie(t){return p(t)}var _e=t=>e=>{let n=e;return n.toPromise||(n.toPromise=r=>t(e,r),n.unsafeRunPromise=()=>t(e,{})),n},we=(t,e)=>A(t,n=>E(e(n))),Oe=(t,e)=>A(t,n=>_(()=>e(n)));var F={_tag:"None"},w=t=>({_tag:"Some",value:t});var j=t=>E(t),C=t=>f(t),$=t=>_(e=>t(e)),k=(t,e)=>Q(t,e),K=(t,e)=>A(t,n=>e(n)),H=(t,e)=>b(t,e),Pe=(t,e)=>R(t,n=>e(n),n=>E(n));function q(t,e){return R(t,n=>n._tag==="Some"?f(n):e(),n=>E(n))}var Te=()=>C(F);var ie=(r=>(r[r.Ok=0]="Ok",r[r.Grew=1]="Grew",r[r.Dropped=2]="Dropped",r))(ie||{}),N=class{buf;head=0;tail=0;size_=0;maxCap;constructor(e=1024,n=e){let r=Math.max(2,this.nextPow2(e)),o=Math.max(r,this.nextPow2(n));this.buf=new Array(r),this.maxCap=o;}get length(){return this.size_}get capacity(){return this.buf.length}isEmpty(){return this.size_===0}push(e){return this.size_===this.buf.length?this.buf.length>=this.maxCap?2:(this.grow(),this.buf[this.tail]=e,this.tail=this.tail+1&this.buf.length-1,this.size_++,1):(this.buf[this.tail]=e,this.tail=this.tail+1&this.buf.length-1,this.size_++,0)}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=Math.min(e.length*2,this.maxCap),r=new Array(n);for(let o=0;o<this.size_;o++)r[o]=e[this.head+o&e.length-1];this.buf=r,this.head=0,this.tail=this.size_;}nextPow2(e){let n=1;for(;n<e;)n<<=1;return n}};var X=2048,Y=4096,se=(()=>{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)})(),L=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>Y?"macro":"micro";this.requestFlush(r);}}requestFlush(e){e==="micro"?queueMicrotask(()=>this.flush()):se(()=>this.flush());}flush(){if(this.flushing)return;this.flushing=true,this.scheduled=false;let e=0;try{for(;e<X;){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>=X||this.queue.length>Y?"macro":"micro";this.requestFlush(n);}}}},B=new L;var P=null,h={CONTINUE:"Continue",SUSPEND:"Suspend",DONE:"Done"},g={QUEUED:"Queued",RUNNING:"Running",SUSPENDED:"Suspended",DONE:"Done"},ce=1,ue=1024;function le(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:o=>({_tag:"FlatMap",first:n.andThen(o),andThen:r})};}return e}var T=class{id;runtime;closing=null;finishing=false;runState=g.RUNNING;interrupted=false;result=null;joiners=[];current;stack=[];fiberFinalizers=[];finalizersDrained=false;fiberContext;name;scopeId;constructor(e,n){this.id=ce++,this.runtime=e,this.current=n;}get env(){return this.runtime.env}get scheduler(){return this.runtime.scheduler}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===g.DONE||this.runState===g.QUEUED||(this.runState=g.QUEUED,this.scheduler.schedule(()=>{pe(this,()=>{if(this.runState===g.DONE)return;switch(this.runState=g.RUNNING,this.step()){case h.CONTINUE:this.schedule("continue");return;case h.SUSPEND:this.runState=g.SUSPENDED;return;case h.DONE:this.runState=g.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=ue;for(;e-- >0;){if(this.result!=null)return h.DONE;if(this.interrupted&&this.closing==null)return this.notify({_tag:"Failure",error:{_tag:"Interrupted"}}),h.DONE;let n=le(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?h.DONE:h.CONTINUE;let r=false,o=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")));},a=n.register(this.env,o);return typeof a=="function"&&this.addFinalizer(()=>{r=true;try{a();}catch{}}),h.SUSPEND}}}return this.result!=null?h.DONE:h.CONTINUE}};function D(){return P}function pe(t,e){let n=P;P=t;try{return e()}finally{P=n;}}var ee={parent:null,patch:Object.create(null)};function te(t,e){let n=Ee(t);return {initChild(r,o){let a=o?.fiberContext,i=Ae(n,a?.trace??null);r.fiberContext={log:a?.log??ee,trace:i},r.parentFiberId=o?.id,r.name=n.childName(o?.name),e.emit({type:"fiber.start",fiberId:r.id,parentFiberId:o?.id,name:r.name},{fiberId:o?.id,traceId:a?.trace?.traceId,spanId:a?.trace?.spanId});}}}function Ee(t){let e={newTraceId:()=>crypto.randomUUID(),newSpanId:()=>crypto.randomUUID()},n=t?.brass,r=n?.tracer??e,o=n?.traceSeed,a=n?.childName??(i=>i?`${i}/child`:void 0);return {tracer:r,seed:o,childName:a}}function Ae(t,e){return e?{traceId:e.traceId,spanId:t.tracer.newSpanId(),parentSpanId:e.spanId,sampled:e.sampled}:t.seed?{...t.seed}:{traceId:t.tracer.newTraceId(),spanId:t.tracer.newSpanId(),sampled:true}}var de={emit(){}},O=class t{env;scheduler;hooks;forkPolicy;constructor(e){this.env=e.env,this.scheduler=e.scheduler??B,this.hooks=e.hooks??de,this.forkPolicy=te(this.env,this.hooks);}fork(e){let n=D(),r=new T(this,e);return this.forkPolicy.initChild(r,n),r.schedule("initial-step"),r}unsafeRunAsync(e,n){this.fork(e).join(n);}toPromise(e){return new Promise((n,r)=>{this.fork(e).join(a=>{let i=a;i._tag==="Success"?n(i.value):r(i.error);});})}log(e,n,r){this.emit({type:"log",level:e,message:n,fields:r});}withHooks(e){return new t({env:this.env,scheduler:this.scheduler,hooks:e})}emit(e){let n=D(),r={fiberId:n?.id,scopeId:n?.scope?.id,traceId:n?.fiberContext?.trace?.traceId,spanId:n?.fiberContext?.trace?.spanId};this.hooks.emit(e,r);}static make(e,n=B){return new t({env:e,scheduler:n})}};function Ye(t){return p((e,n)=>{let r=false,o=s=>{r||(r=true,n(s));},a=s=>o({_tag:"Failure",error:s instanceof Error?s:new Error(String(s))}),i=s=>o({_tag:"Success",value:s});try{typeof t=="function"&&t.length>=1?t((s,c)=>s?a(s):i(c)):t().then(i,a);}catch(s){a(s);}})}function et(t,e,n=B){return new O({env:e,scheduler:n}).fork(t)}function tt(t,e,n){return new O({env:e}).unsafeRunAsync(t,n)}function nt(t,e){return new O({env:e}).toPromise(t)}function rt(t,e){return p((n,r)=>{t(n).then(o=>r({_tag:"Success",value:o})).catch(o=>r({_tag:"Failure",error:e(o)}));})}function ot(t){return p((e,n)=>{let r=false,o=a=>{r||(r=true,n(a));};try{t((a,i)=>{o(a?{_tag:"Failure",error:a}:{_tag:"Success",value:i});});}catch(a){o({_tag:"Failure",error:a instanceof Error?a:new Error(String(a))});}})}function at(t){return ye((n,r)=>t.length===1?t(r):t(n,r),n=>Re(n)?{_tag:"Abort"}:{_tag:"PromiseRejected",reason:n})}function ye(t,e){return p((n,r)=>{let o=new AbortController,a=false,i=s=>{a||(a=true,r(s));};try{(t.length===1?t(o.signal):t(n,o.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 ()=>{a=true,o.abort();}})}var Re=t=>typeof t=="object"&&t!==null&&"name"in t&&t.name==="AbortError";function G(){let t=D();if(!t)throw new Error("No current runtime: est\xE1s llamando esto fuera de un fiber (fuera del runtime).");return t.runtime}var me=1;function fe(t){return p((e,n)=>{let r=t.length;if(r===0){n({_tag:"Success",value:void 0});return}for(let o of t)o.join(()=>{r-=1,r===0&&n({_tag:"Success",value:void 0});});})}function he(t){return R(t,()=>Z(),()=>Z())}var I=class t{constructor(e){this.runtime=e;this.id=me++;}id;closed=false;children=new Set;subScopes=new Set;finalizers=[];get env(){return this.runtime.env}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.runtime);return this.subScopes.add(e),e}fork(e){if(this.closed)throw new Error("Scope closed");let n=this.runtime.fork(e);return this.children.add(n),n.join(()=>{this.children.delete(n);}),n}close(e={_tag:"Success",value:void 0}){this.runtime.fork(this.closeAsync(e));}closeAsync(e={_tag:"Success",value:void 0},n={}){return p((r,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 s=Z();for(let l of i)s=A(s,()=>l.closeAsync(e,n));for(;this.finalizers.length>0;){let l=this.finalizers.pop();s=A(s,()=>he(l(e)));}n.awaitChildren&&(s=A(s,()=>fe(a))),this.runtime.fork(s).join(()=>o({_tag:"Success",value:void 0}));})}};function ut(t,e){let n=new I(t);try{return e(n)}finally{n.close();}}function lt(t,e){return p((n,r)=>{let o=new I(t);o.fork(e(o)).join(i=>{try{o.close(i);}catch(s){r({_tag:"Failure",error:s});return}r(i);});})}function dt(t,e,n){return p((r,o)=>{let a=n.subScope(),i=false,s=m=>{i||(i=true,a.close(m),o(m));},c=a.fork(t),l=a.fork(e);c.join(s),l.join(s);})}function yt(t,e,n){return p((r,o)=>{let a=n.subScope(),i=null,s=null,c=false,l=()=>{if(!i||!s||c)return;if(c=true,i._tag==="Success"&&s._tag==="Success"){a.close({_tag:"Success",value:void 0}),o({_tag:"Success",value:[i.value,s.value]});return}let u;if(i._tag==="Failure")u=i.error;else if(s._tag==="Failure")u=s.error;else throw new Error("zipPar: unreachable state (no Failure exit)");let v={_tag:"Failure",error:u};a.close(v),o(v);},m=a.fork(t),y=a.fork(e);m.join(u=>{i=u,l();}),y.join(u=>{s=u,l();});})}function Rt(t,e){return p((n,r)=>{let o=e.subScope(),a=new Array(t.length),i=0,s=false;t.forEach((c,l)=>{o.fork(c).join(y=>{if(!s){if(y._tag==="Failure"){s=true;let u={_tag:"Failure",error:y.error};o.close(u),r(u);return}if(a[l]=y.value,i++,i===t.length){s=true;let u={_tag:"Success",value:a};o.close({_tag:"Success",value:void 0}),r(u);}}});});})}function ne(t,e,n,r,o){return p((a,i)=>{let s=n.subScope(),c=false,l=s.fork(t),m=s.fork(e),y=u=>{s.fork(u).join(v=>{s.close(v),i(v);});};l.join(u=>{c||(c=true,y(r(u,m,s)));}),m.join(u=>{c||(c=true,y(o(u,l,s)));});})}var J=t=>t._tag==="None"?F:w(t.value),x=t=>({_tag:"FromPull",pull:t}),oe=(t,e)=>({_tag:"Scoped",acquire:t,release:e}),Ot=t=>({_tag:"Scoped",acquire:A(t,e=>E(e.stream)),release:e=>A(t,n=>n.release(e))}),ge=(t,e,n=true)=>({_tag:"Merge",left:t,right:e,flip:n}),M=()=>({_tag:"Empty"}),ae=t=>({_tag:"Emit",value:t}),z=(t,e)=>({_tag:"Concat",left:t,right:e}),V=t=>({_tag:"Flatten",stream:t});function re(t,e,n,r,o){return (a,i,s)=>{if(a._tag,a._tag,a._tag==="Success"){let[m,y]=a.value;i.interrupt();let u=x(t==="L"?U(y,n):U(e,y));return E([m,u])}let c=a.error;if(typeof c=="object"&&c!==null&&c._tag==="Interrupted")return f(c);let l=c;return l._tag==="None"?d(t==="L"?n:e):f(l)}}function U(t,e,n,r){return p((o,a)=>{let s=G(),c=new I(s),l=d(t),m=d(e),y=re("L",t,e),u=re("R",t,e),v=ne(l,m,c,y,u);c.fork(v).join(W=>{c.close(W),a(W);});})}function Zt(t,e){return x(U(t,e))}function d(t){switch(t._tag){case "Empty":return C(F);case "Emit":return k(H(t.value,e=>w(e)),e=>[e,M()]);case "FromPull":return t.pull;case "Concat":return q(k(d(t.left),([e,n])=>[e,z(n,t.right)]),()=>d(t.right));case "Flatten":return K(d(t.stream),([e,n])=>q(k(d(e),([r,o])=>[r,z(o,V(n))]),()=>d(V(n))));case "Merge":return U(t.left,t.right,t.flip);case "Scoped":return p((e,n)=>{let r=G(),o=new I(r);o.addFinalizer(a=>t.release(a)),o.fork(t.acquire).join(a=>{if(a._tag==="Failure"){o.close(a),n({_tag:"Failure",error:w(a.error)});return}let i=a.value;d(i)(e,c=>{o.close(c),n(c);});});})}}function Se(t,e){throw new Error(e??`Unexpected value: ${String(t)}`)}function S(t,e){switch(t._tag){case "Empty":return M();case "Emit":return ae(k(t.value,e));case "FromPull":return x(k(t.pull,([n,r])=>[e(n),S(r,e)]));case "Concat":return z(S(t.left,e),S(t.right,e));case "Flatten":{let n=S(t.stream,r=>S(r,e));return V(n)}case "Merge":return ge(S(t.left,e),S(t.right,e),t.flip);case "Scoped":return oe(k(t.acquire,n=>S(n,e)),t.release);default:return Se(t)}}function Ct(t,e){let n=r=>x(r>e?f(F):E([r,n(r+1)]));return n(t)}function xe(t,e){let n=R(b(d(t),r=>J(r)),r=>f(r),([r,o])=>R(b(d(e),a=>J(a)),a=>f(a),([a,i])=>E([[r,a],xe(o,i)])));return x(n)}function Nt(t,e){let n=r=>R(b(d(r),o=>J(o)),o=>o._tag==="None"?E(void 0):f(o),([o,a])=>A(b(e(o),i=>w(i)),()=>n(a)));return R(n(t),r=>r._tag==="None"?E(void 0):f(r.value),()=>E(void 0))}function Bt(t){let e=M();for(let n=t.length-1;n>=0;n--){let r=ae(j(t[n]));e=z(r,e);}return e}function Pt(t){let e=(n,r)=>R(d(n),o=>o._tag==="None"?j(r):C(o),([o,a])=>e(a,[...r,o]));return H(e(t,[]),n=>{if(n._tag==="Some")return n.value;throw new Error("unreachable: stream end handled as success")})}function ve(t,e){let n=p((r,o)=>{t.read().then(({done:a,value:i})=>{if(a){o({_tag:"Failure",error:F});return}o({_tag:"Success",value:[i,x(n)]});}).catch(a=>{o({_tag:"Failure",error:w(e(a))});});});return x(n)}function Tt(t,e){if(!t)return M();let n;return oe($(()=>(n=t.getReader(),ve(n,e))),()=>_(()=>{try{n?.cancel();}catch{}}))}export{oe as $,Te as A,ie as B,N as C,L as D,B as E,T as F,D as G,pe as H,O as I,Ye as J,et as K,tt as L,nt as M,rt as N,ot as O,at as P,ye as Q,G as R,I as S,ut as T,lt as U,dt as V,yt as W,Rt as X,ne as Y,J as Z,x as _,R as a,Ot as aa,be as b,ge as ba,b as c,M as ca,Z as d,ae as da,E as e,z as ea,f,V as fa,_ as g,Zt as ga,Fe as h,d as ha,p as i,Se as ia,Q as j,S as ja,A as k,Ct as ka,ke as l,xe as la,Ie as m,Nt as ma,_e as n,Bt as na,we as o,Pt as oa,Oe as p,Tt as pa,F as q,w as r,j as s,C as t,$ as u,k as v,K as w,H as x,Pe as y,q as z};
|