@graphrefly/graphrefly 0.36.0 → 0.37.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-PYEIPRSZ.js → chunk-2C4NESZE.js} +1 -1
- package/dist/{chunk-44QWWUA3.js → chunk-4EATTNAE.js} +1 -1
- package/dist/{chunk-5RTZ6DXG.js → chunk-6SVKZ7VI.js} +1 -1
- package/dist/chunk-B4L5X2QO.js +7 -0
- package/dist/{chunk-TQSTS3BY.js → chunk-C5CBVOCB.js} +1 -1
- package/dist/{chunk-J6TGRQUP.js → chunk-CZIQ6JCE.js} +1 -1
- package/dist/chunk-FJ6IEMOS.js +1 -0
- package/dist/{chunk-5Z3AFBN7.js → chunk-FMI4CWFL.js} +1 -1
- package/dist/{chunk-DBPFMCVH.js → chunk-G6Q3DUMJ.js} +1 -1
- package/dist/{chunk-3U7IIQB2.js → chunk-GDDPCDLG.js} +1 -1
- package/dist/{chunk-5CZ3KIRJ.js → chunk-GFOT6UBB.js} +1 -1
- package/dist/{chunk-KL7CILPL.js → chunk-K2WYIVHM.js} +1 -1
- package/dist/{chunk-I57VSGRB.js → chunk-K6ZFJ473.js} +1 -1
- package/dist/{chunk-YBA5N4XY.js → chunk-KTWBUJO5.js} +1 -1
- package/dist/{chunk-7LYIKMW5.js → chunk-LOQRPP4Y.js} +1 -1
- package/dist/{chunk-KCE6WWJE.js → chunk-MC5LZG3U.js} +1 -1
- package/dist/{chunk-N2GCKKKH.js → chunk-NKKUUKPD.js} +1 -1
- package/dist/{chunk-GWOKTENT.js → chunk-QKBCTKH7.js} +1 -1
- package/dist/{chunk-YOUAVGHJ.js → chunk-QP5TH523.js} +1 -1
- package/dist/{chunk-T6RPUERH.js → chunk-QWVQIL3T.js} +1 -1
- package/dist/{chunk-6G5YD37E.js → chunk-T4U24DXX.js} +1 -1
- package/dist/{chunk-AACJX2L7.js → chunk-TFK4P4CX.js} +1 -1
- package/dist/{chunk-K5ZXJPWU.js → chunk-TLS7M7H4.js} +1 -1
- package/dist/{chunk-AQC53OWG.js → chunk-U3COB5WU.js} +1 -1
- package/dist/{chunk-F36TA3ET.js → chunk-UODQF4EY.js} +1 -1
- package/dist/{chunk-QKUWS7CO.js → chunk-WGST56ZH.js} +1 -1
- package/dist/{chunk-XINLP35X.js → chunk-WSLN4JFO.js} +1 -1
- package/dist/{chunk-LO3LO2TO.js → chunk-XIJKEXWR.js} +1 -1
- package/dist/{chunk-JUJEPZOI.js → chunk-YVYSO5CW.js} +1 -1
- package/dist/compat/index.cjs +9 -9
- package/dist/compat/index.d.cts +5 -5
- package/dist/compat/index.d.ts +5 -5
- package/dist/compat/index.js +1 -1
- package/dist/compat/nestjs/index.cjs +11 -11
- package/dist/compat/nestjs/index.d.cts +3 -3
- package/dist/compat/nestjs/index.d.ts +3 -3
- package/dist/compat/nestjs/index.js +1 -1
- package/dist/compat/zustand/index.cjs +7 -7
- package/dist/compat/zustand/index.d.cts +2 -2
- package/dist/compat/zustand/index.d.ts +2 -2
- package/dist/compat/zustand/index.js +1 -1
- package/dist/extra/index.cjs +15 -15
- package/dist/extra/index.d.cts +2 -2
- package/dist/extra/index.d.ts +2 -2
- package/dist/extra/index.js +1 -1
- package/dist/graph/index.cjs +7 -7
- package/dist/graph/index.d.cts +3 -3
- package/dist/graph/index.d.ts +3 -3
- package/dist/graph/index.js +1 -1
- package/dist/{graph-kTltt95s.d.cts → graph-CaNXUc3c.d.cts} +26 -1
- package/dist/{graph-Cv-8x0ZI.d.ts → graph-YQXDndFy.d.ts} +26 -1
- package/dist/{index-CVhBdCMf.d.ts → index-0qOD-421.d.ts} +2 -2
- package/dist/{index-BC-xjOrd.d.cts → index-4IwO4mH2.d.cts} +5 -5
- package/dist/{index-kBUQj-rT.d.ts → index-9mbs_PIG.d.ts} +1 -1
- package/dist/{index-DSSsxS7B.d.ts → index-Ae6L8liv.d.ts} +2 -2
- package/dist/{index-BhkPzu-Z.d.cts → index-B1IcU--K.d.cts} +2 -2
- package/dist/{index-jA_OwwNg.d.ts → index-B46GWgk3.d.ts} +1 -1
- package/dist/{index-EfPb77rT.d.cts → index-B9qJmmv3.d.cts} +1 -1
- package/dist/{index-CI_yjtua.d.ts → index-BCq12BqB.d.ts} +1 -1
- package/dist/{index-2URa-V4S.d.cts → index-BECJ8M0T.d.cts} +1 -1
- package/dist/{index-DFe2Pk2u.d.ts → index-BOfHwQc1.d.ts} +1 -1
- package/dist/{index-BTJxM-wZ.d.ts → index-BhLA9feT.d.ts} +1 -1
- package/dist/{index-Pu1Wa7en.d.ts → index-BmLkcDlj.d.ts} +5 -5
- package/dist/{index-XxSeddWP.d.cts → index-BokynmA4.d.cts} +1 -1
- package/dist/{index-DtSVSKnd.d.ts → index-Bpzw8hx3.d.ts} +1 -1
- package/dist/{index-PluovH45.d.cts → index-BwtIbzSV.d.cts} +2 -2
- package/dist/{index-BZ1V5GzX.d.ts → index-C-pFD_FV.d.ts} +2 -2
- package/dist/{index-Cot94_82.d.ts → index-C0tga1_x.d.ts} +2 -2
- package/dist/{index-BlRVj-7Q.d.cts → index-C4N-dg5U.d.cts} +2 -2
- package/dist/{index-B4s70vYf.d.ts → index-CKcnuQ2c.d.ts} +2 -2
- package/dist/{index-HCp5ua_i.d.cts → index-CLPQyYY5.d.cts} +3 -3
- package/dist/{index-BuMzxRO2.d.ts → index-CRycrNfn.d.ts} +1 -1
- package/dist/{index-CvUrRb4m.d.cts → index-CU3z8Cel.d.cts} +2 -2
- package/dist/{index-CZAixNU3.d.ts → index-CUTHDZ7Q.d.ts} +3 -3
- package/dist/{index-DzCQt2FJ.d.cts → index-C_qi0WlF.d.cts} +1 -1
- package/dist/{index-BBdwz2BW.d.ts → index-CajEOoAN.d.ts} +2 -2
- package/dist/{index-BVNGEX7d.d.cts → index-Ci358GSC.d.cts} +2 -2
- package/dist/{index-DHv2M7s8.d.cts → index-CkN8CZlT.d.cts} +5 -5
- package/dist/{index-ZhKyR8co.d.cts → index-CrpjECS6.d.cts} +2 -2
- package/dist/{index-isdlyeeO.d.ts → index-CzIWlnPp.d.ts} +5 -5
- package/dist/{index-DxxvGTXp.d.ts → index-D0ZxFXYl.d.ts} +1 -1
- package/dist/{index-k67aNfqC.d.cts → index-D11pGlaI.d.cts} +2 -2
- package/dist/{index-DlccEIi3.d.ts → index-D1E1tqHT.d.ts} +1 -1
- package/dist/{index-Cjrpx2Mg.d.cts → index-D6pwWiOc.d.cts} +1 -1
- package/dist/{index-BsZlbHM5.d.cts → index-D6tRNEKz.d.cts} +1 -1
- package/dist/{index-33mF4XyU.d.cts → index-DAKm44My.d.cts} +1 -1
- package/dist/{index-BWH17rK_.d.cts → index-DCAuN9u5.d.cts} +1 -1
- package/dist/{index-CsD0fqnO.d.ts → index-DPqR3wdW.d.ts} +2 -2
- package/dist/{index-GaW6Welt.d.cts → index-DTYIRT_v.d.cts} +2 -2
- package/dist/{index-DXSLMoma.d.ts → index-DXz9uwcs.d.ts} +1 -1
- package/dist/{index-DmtWMP0X.d.cts → index-D_DThl_J.d.cts} +1 -1
- package/dist/{index-BwYGLgmI.d.ts → index-D_d1erkR.d.ts} +2 -2
- package/dist/{index-D9qoEOj_.d.cts → index-DbWwMWiB.d.cts} +1 -1
- package/dist/{index-C4ig7whw.d.cts → index-DcWbx58m.d.cts} +2 -2
- package/dist/{index-DzYTXMBz.d.ts → index-DfAo9WKr.d.ts} +1 -1
- package/dist/{index-RJIY7QVW.d.cts → index-DqtXA3yX.d.cts} +1 -1
- package/dist/{index-KeBhbNg3.d.ts → index-DuhOdNyg.d.ts} +1 -1
- package/dist/{index-DKp1CIbG.d.cts → index-e1m3ZHgc.d.cts} +1 -1
- package/dist/{index-DLyQC5Ww.d.ts → index-fHKHdAso.d.ts} +2 -2
- package/dist/index.cjs +41 -41
- package/dist/index.d.cts +28 -28
- package/dist/index.d.ts +28 -28
- package/dist/index.js +1 -1
- package/dist/patterns/ai/index.cjs +19 -19
- package/dist/patterns/ai/index.d.cts +6 -6
- package/dist/patterns/ai/index.d.ts +6 -6
- package/dist/patterns/ai/index.js +1 -1
- package/dist/patterns/audit/index.cjs +7 -7
- package/dist/patterns/audit/index.d.cts +3 -3
- package/dist/patterns/audit/index.d.ts +3 -3
- package/dist/patterns/audit/index.js +1 -1
- package/dist/patterns/cqrs/index.cjs +7 -7
- package/dist/patterns/cqrs/index.d.cts +2 -2
- package/dist/patterns/cqrs/index.d.ts +2 -2
- package/dist/patterns/cqrs/index.js +1 -1
- package/dist/patterns/demo-shell/index.cjs +8 -8
- package/dist/patterns/demo-shell/index.d.cts +3 -3
- package/dist/patterns/demo-shell/index.d.ts +3 -3
- package/dist/patterns/demo-shell/index.js +1 -1
- package/dist/patterns/domain-templates/index.cjs +7 -7
- package/dist/patterns/domain-templates/index.d.cts +2 -2
- package/dist/patterns/domain-templates/index.d.ts +2 -2
- package/dist/patterns/domain-templates/index.js +1 -1
- package/dist/patterns/graphspec/index.cjs +17 -17
- package/dist/patterns/graphspec/index.d.cts +2 -2
- package/dist/patterns/graphspec/index.d.ts +2 -2
- package/dist/patterns/graphspec/index.js +1 -1
- package/dist/patterns/guarded-execution/index.cjs +7 -7
- package/dist/patterns/guarded-execution/index.d.cts +4 -4
- package/dist/patterns/guarded-execution/index.d.ts +4 -4
- package/dist/patterns/guarded-execution/index.js +1 -1
- package/dist/patterns/harness/index.cjs +10 -10
- package/dist/patterns/harness/index.d.cts +6 -6
- package/dist/patterns/harness/index.d.ts +6 -6
- package/dist/patterns/harness/index.js +1 -1
- package/dist/patterns/job-queue/index.cjs +7 -7
- package/dist/patterns/job-queue/index.d.cts +2 -2
- package/dist/patterns/job-queue/index.d.ts +2 -2
- package/dist/patterns/job-queue/index.js +1 -1
- package/dist/patterns/lens/index.cjs +7 -7
- package/dist/patterns/lens/index.d.cts +3 -3
- package/dist/patterns/lens/index.d.ts +3 -3
- package/dist/patterns/lens/index.js +1 -1
- package/dist/patterns/memory/index.cjs +7 -7
- package/dist/patterns/memory/index.d.cts +2 -2
- package/dist/patterns/memory/index.d.ts +2 -2
- package/dist/patterns/memory/index.js +1 -1
- package/dist/patterns/messaging/index.cjs +7 -7
- package/dist/patterns/messaging/index.d.cts +2 -2
- package/dist/patterns/messaging/index.d.ts +2 -2
- package/dist/patterns/messaging/index.js +1 -1
- package/dist/patterns/orchestration/index.cjs +7 -7
- package/dist/patterns/orchestration/index.d.cts +2 -2
- package/dist/patterns/orchestration/index.d.ts +2 -2
- package/dist/patterns/orchestration/index.js +1 -1
- package/dist/patterns/process/index.cjs +1 -1
- package/dist/patterns/process/index.d.cts +3 -3
- package/dist/patterns/process/index.d.ts +3 -3
- package/dist/patterns/process/index.js +1 -1
- package/dist/patterns/reactive-layout/index.cjs +8 -8
- package/dist/patterns/reactive-layout/index.d.cts +3 -3
- package/dist/patterns/reactive-layout/index.d.ts +3 -3
- package/dist/patterns/reactive-layout/index.js +1 -1
- package/dist/patterns/reduction/index.cjs +7 -7
- package/dist/patterns/reduction/index.d.cts +2 -2
- package/dist/patterns/reduction/index.d.ts +2 -2
- package/dist/patterns/reduction/index.js +1 -1
- package/dist/patterns/refine-loop/index.cjs +8 -8
- package/dist/patterns/refine-loop/index.d.cts +3 -3
- package/dist/patterns/refine-loop/index.d.ts +3 -3
- package/dist/patterns/refine-loop/index.js +1 -1
- package/dist/patterns/resilient-pipeline/index.d.cts +3 -3
- package/dist/patterns/resilient-pipeline/index.d.ts +3 -3
- package/dist/patterns/resilient-pipeline/index.js +1 -1
- package/dist/patterns/surface/index.cjs +10 -10
- package/dist/patterns/surface/index.d.cts +3 -3
- package/dist/patterns/surface/index.d.ts +3 -3
- package/dist/patterns/surface/index.js +1 -1
- package/dist/{pipeline-graph-BlLBWSZ2.d.cts → pipeline-graph-BrrYGjuZ.d.cts} +1 -1
- package/dist/{pipeline-graph-DdBoRu37.d.ts → pipeline-graph-DX2Twdj-.d.ts} +1 -1
- package/dist/{reactive-layout-Btv0-efV.d.ts → reactive-layout-BDdngW56.d.ts} +1 -1
- package/dist/{reactive-layout-D9zqqaqK.d.cts → reactive-layout-DrGjuwyC.d.cts} +1 -1
- package/dist/{topology-tree-CJsT24DP.d.ts → topology-tree-BI665P0L.d.ts} +1 -1
- package/dist/{topology-tree-C50l9ARE.d.cts → topology-tree-BkhmMg2a.d.cts} +1 -1
- package/package.json +1 -1
- package/dist/chunk-5KPIYVCC.js +0 -7
- package/dist/chunk-CGA5RXO6.js +0 -1
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import{g as he}from"./chunk-
|
|
1
|
+
import{g as he}from"./chunk-U3COB5WU.js";import{j as fe}from"./chunk-B4L5X2QO.js";import{x as ye}from"./chunk-JJTF75VS.js";import{D as be,E as T,G as v,H as q,m as ee,o as z}from"./chunk-LYCLF26R.js";import{b as P,j as Z}from"./chunk-CK2E7BTU.js";import{b as Ne}from"./chunk-QYADASLV.js";var we={};Ne(we,{blindVariation:()=>De,errorCritique:()=>Re,refineLoop:()=>Se});function Ie(n){if(typeof n!="object"||n===null)return!1;let l=n;return typeof l.subscribe=="function"&&typeof l.down=="function"&&typeof l.emit=="function"}function pe(n,l){if(n.length===0)return{best:null,bestScore:Number.NEGATIVE_INFINITY};if(n.length===1){let e=ne(l);return{best:n[0],bestScore:e}}if(l.some(e=>typeof e.candidateIndex=="number")){let e=new Array(n.length);for(let i=0;i<n.length;i++)e[i]={sum:0,count:0};for(let i of l){let d=i.candidateIndex;typeof d=="number"&&d>=0&&d<n.length&&(e[d].sum+=i.score,e[d].count+=1)}let s=n[0],o=e[0].count>0?e[0].sum/e[0].count:Number.NEGATIVE_INFINITY;for(let i=1;i<n.length;i++){let d=e[i].count>0?e[i].sum/e[i].count:Number.NEGATIVE_INFINITY;d>o&&(o=d,s=n[i])}return{best:s,bestScore:o}}let t=n[0],m=l[0]?.score??Number.NEGATIVE_INFINITY;for(let e=1;e<n.length;e++){let s=l[e]?.score??Number.NEGATIVE_INFINITY;s>m&&(m=s,t=n[e])}return{best:t,bestScore:m}}function ne(n){if(n.length===0)return Number.NEGATIVE_INFINITY;let l=0;for(let x of n)l+=x.score;return l/n.length}function Se(n,l,x,t){let m=t.name??"refine-loop",e=new fe(m,t.graph),s=Ie(t.dataset)?t.dataset:T(t.dataset,{name:"dataset"});e.add(s,{name:"dataset"});let o=T(0,{name:"iteration"});e.add(o,{name:"iteration"});let i=T(x,{name:"strategy",equals:()=>!1});e.add(i,{name:"strategy"});let d=T(null,{name:"lastFeedback"});e.add(d,{name:"lastFeedback"});let k=T([],{name:"prevCandidates"});e.add(k,{name:"prevCandidates"});let y=T(!1,{name:"paused"});e.add(y,{name:"paused"});let b=T("running",{name:"status"});e.add(b,{name:"status"});let E=T([],{name:"history",equals:()=>!1});e.add(E,{name:"history"});let h=T(null,{name:"best"});e.add(h,{name:"best"});let N=T(Number.NEGATIVE_INFINITY,{name:"score"});e.add(N,{name:"score"});let C=T(0,{name:"budget-used"});e.add(C,{name:"budget-used"});let R=he("stages");e.mount("stages",R);let A=R.topic("generate"),p=R.topic("evaluate"),G=R.topic("analyze"),te=R.topic("decide"),$=x,B=null,re=[];e.addDisposer(i.subscribe(r=>{for(let a of r)a[0]===P&&($=a[1])})),e.addDisposer(d.subscribe(r=>{for(let a of r)a[0]===P&&(B=a[1])})),e.addDisposer(k.subscribe(r=>{for(let a of r)a[0]===P&&(re=a[1])}));let I=ye(o,r=>{let a=$,c=r===0||B==null;return be([],(u,f)=>{let S=!1;try{let D=c?a.seed(n):a.generate(B,re);if(D instanceof Promise)return D.then(_=>{S||f.emit(_)},_=>{S||f.down([[Z,_]])}),()=>{S=!0};f.emit(D)}catch(D){S=!0,f.down([[Z,D]])}},{describeKind:"producer"})},{name:"candidates"});e.add(I,{name:"candidates"});let ae=q([I],(r,a,c)=>{let u=c.terminalDeps[0];u!==void 0&&u!==!0&&b.emit("errored")},{name:"error-watcher",errorWhenDepsError:!1});e.add(ae,{name:"error-watcher"}),e.addDisposer(ae.subscribe(()=>{}));let Y=v([I,o],([r,a])=>({iteration:a,candidates:r,timestamp_ns:z()}),{name:"generate-event"});e.add(Y,{name:"generate-event"}),e.addDisposer(Y.subscribe(()=>{}));let oe=q([Y],([r])=>{A.publish(r)},{name:"generate-publish"});e.add(oe,{name:"generate-publish"}),e.addDisposer(oe.subscribe(()=>{}));let ie=q([I],([r])=>{k.emit(r)},{name:"generate-mirror"});e.add(ie,{name:"generate-mirror"}),e.addDisposer(ie.subscribe(()=>{}));let V=l(I,s);e.add(V,{name:"scores"});let j=v([V,I,o],([r,a,c])=>({iteration:c,candidates:a,scores:r,timestamp_ns:z()}),{name:"evaluate-event"});e.add(j,{name:"evaluate-event"}),e.addDisposer(j.subscribe(()=>{}));let se=q([j],([r])=>{p.publish(r)},{name:"evaluate-publish"});e.add(se,{name:"evaluate-publish"}),e.addDisposer(se.subscribe(()=>{}));let L=v([V,I],([r,a])=>$.analyze(r,a),{name:"feedback"});e.add(L,{name:"feedback"});let M=v([L,I,o],([r,a,c])=>({iteration:c,candidates:a,feedback:r,timestamp_ns:z()}),{name:"analyze-event"});e.add(M,{name:"analyze-event"}),e.addDisposer(M.subscribe(()=>{}));let de=q([M],([r])=>{G.publish(r)},{name:"analyze-publish"});e.add(de,{name:"analyze-publish"}),e.addDisposer(de.subscribe(()=>{}));let H=v([E],([r])=>{let a=r;if(t.patience==null||a.length<=t.patience)return!1;let c=a.slice(-(t.patience+1)),u=c[0].bestScore;return c.slice(1).every(f=>f.bestScore<=u)},{name:"patience-check"});e.add(H,{name:"patience-check"});let W=v([N],([r])=>t.minScore!=null&&r>=t.minScore,{name:"min-score-check"});e.add(W,{name:"min-score-check"});let K=v([E],([r])=>{let a=r;if(t.minDelta==null||a.length<2)return!1;let c=a[a.length-2].bestScore,u=a[a.length-1].bestScore;return Math.abs(u-c)<t.minDelta},{name:"min-delta-check"});e.add(K,{name:"min-delta-check"});let U=v([C],([r])=>t.maxEvaluations!=null&&r>=t.maxEvaluations,{name:"max-evaluations-check"});e.add(U,{name:"max-evaluations-check"});let J=v([o],([r])=>t.maxIterations!=null&&r>=t.maxIterations,{name:"max-iterations-check"});e.add(J,{name:"max-iterations-check"});let le=v([C],([r])=>t.budget!=null&&r>=t.budget,{name:"budget-exhausted-check"});e.add(le,{name:"budget-exhausted-check"}),e.addDisposer(H.subscribe(()=>{})),e.addDisposer(W.subscribe(()=>{})),e.addDisposer(K.subscribe(()=>{})),e.addDisposer(U.subscribe(()=>{})),e.addDisposer(J.subscribe(()=>{})),e.addDisposer(le.subscribe(()=>{}));let ce=v([H,W,K,U,J],([r,a,c,u,f])=>r?{converged:!0,reason:"patience"}:a?{converged:!0,reason:"min-score"}:c?{converged:!0,reason:"min-delta"}:u?{converged:!0,reason:"max-evaluations"}:f?{converged:!0,reason:"max-iterations"}:{converged:!1},{name:"converged"});e.add(ce,{name:"converged"}),e.addDisposer(ce.subscribe(()=>{}));let ue=-1,me=q([L,V,I],([r,a,c])=>{let u=o.cache,f=r,S=c,D=a;if(u<=ue)return;ue=u;let{best:_,bestScore:ge}=pe(S,D),Te=E.cache,ve={n:u,candidates:S,scores:D,feedback:f,best:_,bestScore:ge,timestamp_ns:z()},F=[...Te,ve],Q=C.cache+S.length,g="continue",w,Ee=t.budget!=null&&Q>=t.budget,ke=y.cache;if(Ee)g="budget",w="budget";else if(t.minScore!=null&&f.score>=t.minScore)g="converged",w="min-score";else if(t.maxIterations!=null&&u>=t.maxIterations)g="converged",w="max-iterations";else if(t.maxEvaluations!=null&&Q>=t.maxEvaluations)g="converged",w="max-evaluations";else if(t.minDelta!=null&&F.length>=2){let O=F[F.length-2].bestScore,X=F[F.length-1].bestScore;Math.abs(X-O)<t.minDelta&&(g="converged",w="min-delta")}else if(t.patience!=null&&F.length>t.patience){let O=F.slice(-(t.patience+1)),X=O[0].bestScore;O.slice(1).every(xe=>xe.bestScore<=X)&&(g="converged",w="patience")}g==="continue"&&ke&&(g="paused"),ee(()=>{h.emit(_),N.emit(f.score),E.emit(F),C.emit(Q),d.emit(f),te.publish({iteration:u,decision:g,reason:w,timestamp_ns:z()}),g==="continue"?o.emit(u+1):b.emit(g==="converged"?"converged":g==="budget"?"budget":"paused")})},{name:"decide-bridge"});return e.add(me,{name:"decide-bridge"}),e.addDisposer(me.subscribe(()=>{})),Object.assign(e,{best:h,score:N,status:b,history:E,strategy:i,iteration:o,generate:A,evaluate:p,analyze:G,decide:te,setStrategy(r){i.emit(r)},pause(){y.emit(!0)},resume(){b.cache==="paused"&&ee(()=>{y.emit(!1),b.emit("running"),o.emit(o.cache+1)})}})}function De(n){let l=n.width??4;return{name:n.name??"blindVariation",seed(t){return[t]},analyze(t,m){let e=ne(t),s=null;for(let o of t)(!s||o.score<s.score)&&(s=o);return{summary:`blindVariation iteration: mean=${e.toFixed(3)}, n=${t.length}`,score:e,weakTasks:s?[s.taskId]:[]}},async generate(t,m){if(m.length===0)throw new Error("blindVariation.generate: empty candidate batch \u2014 cannot derive prior for teacher");let e=m[m.length-1],s=0,i={prior:e,reportCost:d=>{s+=d}};try{if(n.parallel!==!1)return await Promise.all(Array.from({length:l},()=>n.teacher(i)));let d=[];for(let k=0;k<l;k++)d.push(await n.teacher(i));return d}finally{if(n.tokens!=null&&s>0){let d=n.tokens.cache??0;n.tokens.emit(d+s)}}}}}function Fe(n){return typeof n=="object"&&n!==null&&n.kind==="errorCritique"}function Ce(n,l){return n.length===0?`No task scored below the batch mean (${l.score.toFixed(3)}). Reinforce the current direction.`:`Failures below threshold:
|
|
2
2
|
${n.map(t=>{let m=t.error!=null?` | error: ${t.error}`:"";return`- ${t.taskId} (score=${t.score.toFixed(3)})${m}`}).join(`
|
|
3
3
|
`)}`}function Re(n){let l=n.width??4,x=n.name??"errorCritique",t=n.maxFailureSamples??5,m=n.formatCritique??Ce;return{name:x,seed(e){return[e]},analyze(e,s){let o=ne(e),i=typeof n.failureThreshold=="function"?n.failureThreshold(e):n.failureThreshold,d=i===void 0&&!Number.isFinite(o),k=i??o,y=d?[...e].sort((p,G)=>p.score-G.score):e.filter(p=>p.score<k).slice().sort((p,G)=>p.score-G.score),b=y.slice(0,t),{best:E,bestScore:h}=pe(s,e),N={summary:"",score:o,weakTasks:b.map(p=>p.taskId)},C=m(b,N),R={kind:"errorCritique",best:E,failures:b,critiqueText:C},A=y.length>b.length?` (top ${b.length} retained)`:"";return{summary:`errorCritique iteration: mean=${o.toFixed(3)}, failures=${y.length}${A}/${e.length}, bestScore=${h.toFixed(3)}`,critique:R,weakTasks:b.map(p=>p.taskId),score:o}},async generate(e,s){if(s.length===0)throw new Error("errorCritique.generate: empty candidate batch \u2014 cannot derive prior for teacher");let o=Fe(e.critique)?e.critique:void 0,i=o!==void 0?o.best:s[s.length-1],d=o?.critiqueText??e.summary,k=o?.failures??[],y=0,E={prior:i,critique:d,failures:k,reportCost:h=>{y+=h}};try{if(n.parallel!==!1)return await Promise.all(Array.from({length:l},()=>n.teacher(E)));let h=[];for(let N=0;N<l;N++)h.push(await n.teacher(E));return h}finally{if(n.tokens!=null&&y>0){let h=n.tokens.cache??0;n.tokens.emit(h+y)}}}}}export{Se as a,De as b,Re as c,we as d};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{a as $}from"./chunk-
|
|
1
|
+
import{a as $}from"./chunk-U3COB5WU.js";import{c as O}from"./chunk-O32GJOUJ.js";import{a as C}from"./chunk-QWVQIL3T.js";import{j as A}from"./chunk-B4L5X2QO.js";import{b as x}from"./chunk-KUVDFOJH.js";import{C as R}from"./chunk-MQZWA3DF.js";import{C as T,E as N,G as E,o as b,p as w,u as P,w as S}from"./chunk-LYCLF26R.js";import{b as v}from"./chunk-CK2E7BTU.js";import{b as M}from"./chunk-QYADASLV.js";var J={};M(J,{AuditTrailGraph:()=>k,PolicyEnforcerGraph:()=>G,auditTrail:()=>z,complianceSnapshot:()=>F,policyEnforcer:()=>K,reactiveExplainPath:()=>q});function V(i,t){return O("audit",i,t)}var L=new Set(["data","error","complete","teardown"]),k=class extends A{entries;count;_log;_target;constructor(t,n){super(n.name??`${t.name}_audit`,n.graph),this._target=t,this._log=x([],{name:"entries",...n.maxSize!=null?{maxSize:n.maxSize}:{}}),this.entries=this._log.entries,this.add(this.entries,{name:"entries"}),this.count=E([this.entries],([c])=>c.length,{name:"count",describeKind:"derived",meta:V("count")}),this.add(this.count,{name:"count"}),this.addDisposer(R(this.count));let o=n.includeTypes!=null?new Set(n.includeTypes):L,u=n.filter,a=0,h=t.observe({timeline:!0,structured:!0}),m=h.onEvent(c=>{if(c.type==="derived")return;let e=c.type;if(!o.has(e))return;let d=c.path??"",r={seq:a++,timestamp_ns:c.timestamp_ns??b(),wall_clock_ns:w(),path:d,type:e},f=(d?D(t,d):void 0)?.lastMutation;f!=null&&(r.actor=f.actor),e==="data"&&(r.value=c.data),e==="error"&&(r.error=c.data);let l=d?U(t,d):void 0;l!=null&&(r.annotation=l),!(u!=null&&!u(r))&&this._log.append(r)});this.addDisposer(()=>{m(),h.dispose()}),this.addDisposer(()=>this._log.disposeAllViews())}all(){return this.entries.cache??[]}byNode(t){return this.all().filter(n=>n.path===t)}byActor(t){return this.all().filter(n=>n.actor?.id===t)}byActorType(t){return this.all().filter(n=>n.actor?.type===t)}byTimeRange(t,n){return this.all().filter(o=>!(o.timestamp_ns<t||n!=null&&o.timestamp_ns>=n))}get target(){return this._target}};function z(i,t={}){return new k(i,t)}var G=class extends A{policies;violations;violationCount;_target;_mode;_currentGuard;constructor(t,n,o){super(o.name??`${t.name}_policy`,o.graph),this._target=t,this._mode=o.mode??"audit";let u=I(n)?n:N(n,{name:"policies"});this.policies=u,this.add(this.policies,{name:"policies"}),this.violations=new $("violations",{retainedLimit:o.violationsLimit??1e3}),this.mount("violations",this.violations),this.violationCount=E([this.violations.events],([e])=>e.length,{name:"violationCount",describeKind:"derived",meta:V("policy_violation_count")}),this.add(this.violationCount,{name:"violationCount"}),this.addDisposer(R(this.violationCount));let h=u.cache??[];this._currentGuard=P(h);let m=u.subscribe(e=>{for(let d of e)d[0]===v&&(h=d[1]??[],this._currentGuard=P(h))});this.addDisposer(m);let c=o.paths!=null?[...o.paths]:j(t);if(this._mode==="enforce"){let e=new Map,d=r=>{if(e.has(r))return;let s=D(t,r);if(!(s instanceof T))return;let f=(l,p)=>{let y=this._currentGuard(l,p);return y||this._publishViolation(l,p,r,"blocked"),y};e.set(r,s._pushGuard(f))};for(let r of c)d(r);if(o.paths==null){let r=C(t,(s,f,l)=>{if(s.kind==="added")if(s.nodeKind==="node")d(`${l}${s.name}`);else{let p=f._mounts.get(s.name);if(!(p instanceof A))return;let y=`${l}${s.name}::`,_=j(p);for(let g of _)d(g===""?`${l}${s.name}`:`${y}${g}`)}else if(s.kind==="removed")if(s.nodeKind==="node"){let p=`${l}${s.name}`,y=e.get(p);y!=null&&(y(),e.delete(p))}else{let p=`${l}${s.name}`,y=`${p}::`;for(let[_,g]of e)(_===p||_.startsWith(y))&&(g(),e.delete(_))}});this.addDisposer(r)}else{let r=t.topology.subscribe(s=>{for(let f of s){if(f[0]!==v)continue;let l=f[1];if(l.kind!=="removed"||l.nodeKind!=="node")continue;let p=e.get(l.name);p!=null&&(p(),e.delete(l.name))}});this.addDisposer(r)}this.addDisposer(()=>{for(let r of e.values())r();e.clear()})}else{let e=t.observe({timeline:!0,structured:!0}),d=e.onEvent(r=>{if(r.type!=="data"&&r.type!=="error")return;let s=r.path??"";if(!s||o.paths!=null&&!o.paths.includes(s))return;let f=r.actor??D(t,s)?.lastMutation?.actor;if(f==null)return;let l="write";this._currentGuard(f,l)||this._publishViolation(f,l,s,"observed")});this.addDisposer(()=>{d(),e.dispose()})}}_publishViolation(t,n,o,u){this.violations.publish({timestamp_ns:b(),wall_clock_ns:w(),path:o,actor:t,action:n,mode:this._mode,result:u})}all(){return this.violations.retained()}get mode(){return this._mode}get target(){return this._target}};function K(i,t,n={}){return new G(i,t,n)}function q(i,t,n,o){return i.explain(t,n,{reactive:!0,...o})}function F(i,t={}){let n={format_version:1,timestamp_ns:b(),wall_clock_ns:w(),graph:i.snapshot()};if(t.actor!=null&&(n.actor=t.actor),t.audit!=null){let u=[...t.audit.all()];n.audit={count:u.length,entries:u}}if(t.policies!=null){let u=t.policies.policies.cache??[];n.policies={mode:t.policies.mode,rules:u,violations:[...t.policies.all()]}}let o=B(n);return{...n,fingerprint:o}}function I(i){return typeof i=="object"&&i!==null&&"subscribe"in i}function D(i,t){try{return i.node(t)}catch{return}}function U(i,t){try{return i.annotation(t)}catch{return}}function j(i){let t=i.describe({detail:"minimal"});return Object.keys(t.nodes)}function B(i){return S(JSON.stringify(H(i)))}function H(i){let t=new Set,n=o=>{if(o===void 0)return{__undefined:!0};if(o===null)return null;let u=typeof o;if(u==="bigint")return{__bigint:o.toString()};if(u!=="object")return o;let a=o;if(t.has(a))return{__circular:!0};t.add(a);try{if(Array.isArray(a))return a.map(n);if(a instanceof Date)return{__date:a.toISOString()};if(a instanceof RegExp)return{__regexp:{source:a.source,flags:a.flags}};if(a instanceof Map)return{__map:[...a.entries()].map(([c,e])=>[n(c),n(e)])};if(a instanceof Set)return{__set:[...a].map(n)};if(ArrayBuffer.isView(a)){let m=a,c=new Array(m.length);for(let e=0;e<m.length;e++)c[e]=m[e]??0;return{__typed_array:{ctor:a.constructor.name,data:c}}}let h={};for(let m of Object.keys(a).sort())h[m]=n(a[m]);return h}finally{t.delete(a)}};return n(i)}export{k as a,z as b,G as c,K as d,q as e,F as f,J as g};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{t as A,x as v}from"./chunk-JJTF75VS.js";import{b as I}from"./chunk-TZQPPQEQ.js";import{m as p,s as y}from"./chunk-MQZWA3DF.js";import{E as R,G as w,m as h}from"./chunk-LYCLF26R.js";import{b}from"./chunk-CK2E7BTU.js";function z(t){return typeof t=="object"&&t!==null&&"cache"in t&&typeof t.subscribe=="function"}function F(t,a,e){let r=p(t),i=r.v!=null,g=R(e?.initialVerified??null,{...i?{meta:{sourceVersion:null}}:{}}),x=e?.trigger!==void 0&&e.trigger!==null,s=null;if(x&&e?.autoVerify?s=A(p(e.trigger),r):x?s=p(e.trigger):e?.autoVerify&&(s=r),s!==null){let d;if(s===r)d=v(r,c=>a(c));else{let c=r.cache;r.subscribe(f=>{for(let M of f)M[0]===b&&(c=M[1])}),d=v(s,()=>a(c))}y(d,c=>{h(()=>{if(g.down([[b,c]]),i){let f=r.v;f!=null&&g.meta.sourceVersion.down([[b,{id:f.id,version:f.version}]])}})})}return{node:r,verified:g,trigger:s}}function E(t){t.subscribe(()=>{})}function k(t){return t instanceof Map?t:new Map}function B(t,a){if(!Array.isArray(a.upsert))throw new TypeError("distill extraction requires upsert: Array<{ key, value }>");h(()=>{for(let{key:e,value:r}of a.upsert)t.set(e,r);for(let e of a.remove??[])t.delete(e)})}function G(t,a,e){let r=p(t),i=I(e.mapOptions??{}),g=e.budget??2e3,s=e.context!==void 0&&e.context!==null?p(e.context):R(null),d=k(i.entries.cache);i.entries.subscribe(o=>{for(let u of o)u[0]===b&&(d=k(u[1]))});let c=v(r,o=>a(o,d));if(y(c,o=>{B(i,o)}),e.evict){let o=new Map,u=w([i.entries],([l])=>{let m=[],N=k(l);for(let n of o.keys())N.has(n)||(o.get(n)(),o.delete(n));for(let[n,T]of N){let V=e.evict(n,T);if(z(V)){if(!o.has(n)){let S=y(V,D=>{D===!0&&i.has(n)&&i.delete(n)});o.set(n,S)}continue}if(typeof V=="boolean"){V&&m.push(n);continue}throw new TypeError("distill evict() must return boolean or Node<boolean>")}return m});y(u,l=>{for(let m of l)i.delete(m)})}let f=e.consolidateTrigger!==void 0&&e.consolidateTrigger!==null;if(e.consolidate&&f){let o=p(e.consolidateTrigger),u=v(o,()=>e.consolidate(d));y(u,l=>{B(i,l)})}let M=w([i.entries,s],([o,u])=>{let l=[...k(o).entries()].map(([n,T])=>({key:n,value:T,score:e.score(T,u),cost:e.cost(T)}));l.sort((n,T)=>T.score-n.score);let m=[],N=g;for(let n of l)n.cost<=N&&(m.push({key:n.key,value:n.value,score:n.score}),N-=n.cost);return m}),O=w([i.entries],([o])=>k(o).size);return E(M),E(O),{store:i,compact:M,size:O}}export{F as a,G as b};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import{a as Se}from"./chunk-SGS4OJGS.js";import{a as Le}from"./chunk-ESMPEKEV.js";import{a as re,b as _e}from"./chunk-533RQFF6.js";import{C as Ee}from"./chunk-MQZWA3DF.js";import{A as we,C as L,E as ne,F as Me,G as Oe,e as $e,f as Ne,i as Z,k as Te,l as xe,m as Ae,o as K,p as Pe,s as W}from"./chunk-LYCLF26R.js";import{b as Y,c as me,d as be,e as te,f as ye,g as ve,h as z,i as X,j as Q}from"./chunk-CK2E7BTU.js";function Ie(e,t,r,n={}){let s=t in e.nodes,o=r in e.nodes;if(!s)return oe(t,r,"no-such-from");if(!o)return oe(t,r,"no-such-to");let i=n.maxDepth;if(i!=null&&(!Number.isInteger(i)||i<0))throw new Error("explainPath: maxDepth must be an integer >= 0");if(t===r){if(n.findCycle===!0){let u=ct(e,t,n);if(u!=null)return u}let l=se(t,e.nodes[t],0,n);return ie(t,r,[l])}if(i===0)return oe(t,r,"no-path");let a=je(e,t,r,i);return a.found?ie(t,r,Be(e,a.pathOrder,n)):oe(t,r,a.truncated?"max-depth-exceeded":"no-path")}function je(e,t,r,n){let s=new Map,o=[{path:r,depth:0}],i=new Set([r]),a=0,l=!1;for(;a<o.length;){let h=o[a++];if(h.path===t)break;if(n!=null&&h.depth>=n){let g=e.nodes[h.path];g?.deps&&g.deps.length>0&&(l=!0);continue}let p=e.nodes[h.path];if(p==null)continue;let f=p.deps??[],c=new Map;for(let g=0;g<f.length;g++){let O=f[g];if(!O)continue;let S=c.get(O);S==null&&(S=[],c.set(O,S)),S.push(g)}for(let[g,O]of c)i.has(g)||(i.add(g),s.set(g,{from:h.path,depIndices:O}),o.push({path:g,depth:h.depth+1}))}if(!s.has(t))return{found:!1,pathOrder:[],truncated:l};let u=[{path:t}],d=t;for(;d!==r;){let h=s.get(d);if(h==null)return{found:!1,pathOrder:[],truncated:!1};u[u.length-1].depIndices=h.depIndices,u.push({path:h.from}),d=h.from}return{found:!0,pathOrder:u,truncated:!1}}function ct(e,t,r){let n=e.nodes[t];if(n==null)return null;let s=n.deps??[],o=[];for(let a=0;a<s.length;a++)s[a]===t&&o.push(a);if(o.length>0){let a=se(t,n,0,r);a.dep_index=o[0];let l=se(t,n,1,r);return ie(t,t,[a,l])}let i=null;for(let a=0;a<s.length;a++){let l=s[a];if(!l||l===t)continue;let u=je(e,l,t,r.maxDepth);u.found&&(i==null||u.pathOrder.length<i.pathOrder.length)&&(i=u,i={found:!0,pathOrder:[{path:t,depIndices:[a]},...u.pathOrder],truncated:!1})}return i==null?null:ie(t,t,Be(e,i.pathOrder,r))}function Be(e,t,r){return t.map((n,s)=>{let o=e.nodes[n.path],i=se(n.path,o,s,r);return n.depIndices!=null&&n.depIndices.length>0&&(i.dep_index=n.depIndices[0],n.depIndices.length>1&&(i.dep_indices=[...n.depIndices])),i})}function se(e,t,r,n){let s={path:e,type:t.type,hop:r};t.status!==void 0&&(s.status=t.status),"value"in t&&(s.value=t.value),t.v!=null&&(s.v=t.v);let o=n.annotations?.get(e)??t.annotation;o!=null&&(s.annotation=o);let i=n.lastMutations?.get(e)??t.lastMutation;return i!=null&&(s.lastMutation=i),s}function ie(e,t,r){return Fe(e,t,!0,"ok",r)}function oe(e,t,r){return Fe(e,t,!1,r,[])}function Fe(e,t,r,n,s){let o=dt(e,t,r,n,s);return{from:e,to:t,found:r,reason:n,steps:s,text:o,toJSON(){return{from:e,to:t,found:r,reason:n,steps:s}}}}function dt(e,t,r,n,s){if(!r)switch(n){case"no-such-from":return`explainPath: no node named "${e}"`;case"no-such-to":return`explainPath: no node named "${t}"`;case"max-depth-exceeded":return`explainPath: no path from "${e}" to "${t}" within maxDepth`;default:return`explainPath: no path from "${e}" to "${t}"`}let o=[`Causal path: ${e} \u2192 ${t} (${s.length} step(s))`];for(let i of s){let l=` ${i.hop===0?"\xB7":"\u2193"} ${i.path} (${i.type}${i.status?`/${i.status}`:""})`;if(o.push(l),"value"in i&&o.push(` value: ${ft(i.value)}`),i.annotation!=null&&o.push(` annotation: ${i.annotation}`),i.lastMutation!=null){let u=i.lastMutation.actor;o.push(` actor: ${u.type}${u.id?`:${u.id}`:""}`)}}return o.join(`
|
|
2
|
+
`)}function ft(e){if(e===void 0)return"<sentinel>";if(e===null)return"null";if(typeof e=="string")return JSON.stringify(e);if(typeof e=="number"||typeof e=="boolean"||typeof e=="bigint")return String(e);try{let t=JSON.stringify(e);return t.length>80?`${t.slice(0,77)}...`:t}catch{return String(e)}}var A={object:56,array:64,string:40,number:8,boolean:4,null:0,undefined:0,symbol:40,bigint:16,function:120,map:72,set:72,mapEntry:40,setEntry:24,date:24,regexp:48,error:64,url:80,promise:48,weakmap:40,weakset:40},pt=Symbol.for("sizeof");function He(e){let t=new WeakSet,r=new WeakSet,n=[e],s=0;for(;n.length>0;){let o=n.pop();s+=ht(o,t,r,n)}return s}function ht(e,t,r,n){if(e==null)return 0;switch(typeof e){case"number":return A.number;case"boolean":return A.boolean;case"string":return A.string+e.length*2;case"bigint":return A.bigint+gt(e);case"symbol":return A.symbol;case"function":return t.has(e)?0:(t.add(e),A.function);case"undefined":return 0}let o=e;if(t.has(o))return 0;t.add(o);let i=o[pt];if(typeof i=="function")try{let u=i.call(o);if(typeof u=="number"&&Number.isFinite(u))return u}catch{}if(o instanceof Date)return A.date;if(o instanceof RegExp)return A.regexp+o.source.length*2;if(o instanceof Error){let u=o.message?o.message.length*2:0,d=o.stack?o.stack.length*2:0;return A.error+u+d}if(typeof URL<"u"&&o instanceof URL)return A.url+o.href.length*2;if(typeof Promise<"u"&&o instanceof Promise)return A.promise;if(o instanceof WeakMap)return A.weakmap;if(o instanceof WeakSet)return A.weakset;if(o instanceof Map){let u=A.map;for(let[d,h]of o)u+=A.mapEntry,n.push(d),n.push(h);return u}if(o instanceof Set){let u=A.set;for(let d of o)u+=A.setEntry,n.push(d);return u}if(Array.isArray(o)){let u=A.array+o.length*8;for(let d of o)n.push(d);return u}if(o instanceof ArrayBuffer)return r.has(o)?0:(r.add(o),o.byteLength);if(ArrayBuffer.isView(o)){let u=o;return r.has(u.buffer)?48:(r.add(u.buffer),u.buffer.byteLength+48)}let a=A.object,l=Object.keys(o);for(let u of l){a+=A.string+u.length*2;try{n.push(o[u])}catch{}}return a}function gt(e){let t=e<0n?-e:e;if(t===0n)return 0;let r=t.toString(2).length;return Math.ceil(r/32)*8}function Ve(e,t){let r=t?.topN??10,n=e.describe({detail:"standard"}),s=[],o=e._collectObserveTargets;typeof o=="function"&&o.call(e,"",s);let i=new Map;for(let[p,f]of s)i.set(p,f);let a=[];for(let[p,f]of Object.entries(n.nodes)){let c=i.get(p),g=c instanceof L?c:null,O=g?He(g.cache):0,S=g?g._sinkCount:0,b=f.deps?.length??0,m=f.type==="effect"&&S===0,y=S===0?f.type==="effect"?"orphan-effect":f.type==="derived"?"idle-derived":f.type==="producer"?"idle-producer":null:null;a.push({path:p,type:f.type,status:f.status??"unknown",valueSizeBytes:O,subscriberCount:S,depCount:b,isOrphanEffect:m,orphanKind:y})}let l=a.reduce((p,f)=>p+f.valueSizeBytes,0),u=(p,f)=>[...a].sort(f??((c,g)=>g[p]-c[p])).slice(0,r),d=a.filter(p=>p.orphanKind!=null),h=a.filter(p=>p.isOrphanEffect);return{nodeCount:a.length,edgeCount:n.edges.length,subgraphCount:n.subgraphs.length,nodes:a,totalValueSizeBytes:l,hotspots:{byValueSize:u("valueSizeBytes"),bySubscriberCount:u("subscriberCount"),byDepCount:u("depCount")},orphans:d,orphanEffects:h}}function Re(e){return e>=768&&e<=879||e>=1155&&e<=1161||e>=1425&&e<=1469||e>=1552&&e<=1562||e>=1611&&e<=1631||e>=1648&&e===1648||e>=1750&&e<=1756||e>=1759&&e<=1764||e>=1767&&e<=1768||e>=1770&&e<=1773||e>=1840&&e<=1866||e>=1958&&e<=1968||e>=2304&&e<=2307||e>=2362&&e<=2383||e>=2385&&e<=2391||e>=2402&&e<=2403||e>=2433&&e<=2435||e>=2492&&e<=2509||e>=2561&&e<=2563||e>=2620&&e<=2641||e>=2672&&e<=2673||e>=2677&&e===2677||e>=3633&&e===3633||e>=3636&&e<=3642||e>=3655&&e<=3662||e>=3761&&e===3761||e>=3764&&e<=3772||e>=3784&&e<=3790||e>=7616&&e<=7679||e>=8400&&e<=8447||e>=65024&&e<=65039||e>=65056&&e<=65071||e===8205?0:e>=4352&&e<=4447||e>=8986&&e<=8987||e>=9001&&e<=9002||e>=9193&&e<=9203||e>=9208&&e<=9210||e>=9725&&e<=9726||e>=9748&&e<=9749||e>=9800&&e<=9811||e===9855||e===9875||e===9889||e>=9898&&e<=9899||e>=9917&&e<=9918||e>=9924&&e<=9925||e===9934||e===9940||e===9962||e>=9970&&e<=9971||e===9973||e===9978||e===9981||e===9986||e===9989||e>=9992&&e<=9997||e===9999||e>=10067&&e<=10069||e===10071||e>=10133&&e<=10135||e===10160||e===10175||e>=10548&&e<=10549||e>=11013&&e<=11015||e>=11035&&e<=11036||e===11088||e===11093||e>=11904&&e<=12350||e>=12352&&e<=12447||e>=12448&&e<=12543||e>=12549&&e<=12591||e>=12593&&e<=12686||e>=12688&&e<=12771||e>=12784&&e<=12830||e>=12832&&e<=12871||e>=12880&&e<=19903||e>=19968&&e<=40959||e>=43360&&e<=43388||e>=44032&&e<=55203||e>=63744&&e<=64255||e>=65040&&e<=65049||e>=65072&&e<=65131||e>=65281&&e<=65376||e>=65504&&e<=65510||e>=126980&&e===126980||e===127183||e>=127344&&e<=127345||e===127358||e===127359||e===127374||e>=127377&&e<=127386||e>=127456&&e<=127487||e>=127488&&e<=127490||e===127514||e===127535||e>=127538&&e<=127546||e>=127568&&e<=127569||e>=127744&&e<=129535||e>=129536&&e<=129791||e>=129792&&e<=130047||e>=131072&&e<=196605||e>=196608&&e<=262141?2:1}function ae(e){let t=0;for(let r of e)t+=Re(r.codePointAt(0));return t}function ze(e,t){if(t<=0)return"";let r=0,n="";for(let s of e){let o=Re(s.codePointAt(0));if(r+o>t){if(t<=1)return"\u2026";for(;r+1>t&&n.length>0;){let i=[...n].pop();n=n.slice(0,-i.length),r-=Re(i.codePointAt(0))}return`${n}\u2026`}n+=s,r+=o}return n}var mt={horizontal:"\u2500",vertical:"\u2502",cornerTL:"\u250C",cornerTR:"\u2510",cornerBL:"\u2514",cornerBR:"\u2518",tDown:"\u252C",tUp:"\u2534",tRight:"\u251C",tLeft:"\u2524",cross:"\u253C",arrowRight:"\u25B6",arrowDown:"\u25BC",arrowLeft:"\u25C0",arrowUp:"\u25B2",boxTL:"\u250C",boxTR:"\u2510",boxBL:"\u2514",boxBR:"\u2518",boxH:"\u2500",boxV:"\u2502"},bt={horizontal:"-",vertical:"|",cornerTL:"+",cornerTR:"+",cornerBL:"+",cornerBR:"+",tDown:"+",tUp:"+",tRight:"+",tLeft:"+",cross:"+",arrowRight:">",arrowDown:"v",arrowLeft:"<",arrowUp:"^",boxTL:"+",boxTR:"+",boxBL:"+",boxBR:"+",boxH:"-",boxV:"|"};function Ue(e,t){let r=t.charset==="ascii"?bt:mt,n=e.width,s=e.height,o=Array.from({length:s},()=>Array.from({length:n},()=>" ")),i=Array.from({length:s},()=>Array.from({length:n},()=>"empty"));for(let a of e.edges)vt(o,i,r,a);for(let a of e.boxes)yt(o,i,r,a,t.labelOf(a.id));return o.map(a=>Et(a.join(""))).join(`
|
|
3
|
+
`)}function yt(e,t,r,n,s){let{x:o,y:i,w:a,h:l}=n;if(a<2||l<2){l>0&&Ke(e,t,o,i,a,s);return}V(e,t,o,i,r.boxTL);for(let d=o+1;d<o+a-1;d+=1)V(e,t,d,i,r.boxH);V(e,t,o+a-1,i,r.boxTR);for(let d=i+1;d<i+l-1;d+=1){V(e,t,o,d,r.boxV);for(let h=o+1;h<o+a-1;h+=1)Je(e,t,h,d," ","empty");V(e,t,o+a-1,d,r.boxV)}V(e,t,o,i+l-1,r.boxBL);for(let d=o+1;d<o+a-1;d+=1)V(e,t,d,i+l-1,r.boxH);V(e,t,o+a-1,i+l-1,r.boxBR);let u=i+Math.floor(l/2);Ke(e,t,o+1,u,a-2,s)}function V(e,t,r,n,s){Je(e,t,r,n,s,s===" "?"empty":s==="\u2500"||s==="-"?"boxH":s==="\u2502"||s==="|"?"boxV":"boxCorner")}function Je(e,t,r,n,s,o){if(n<0||n>=e.length)return;let i=e[n];r<0||r>=i.length||(i[r]=s,t[n][r]=o)}function Ke(e,t,r,n,s,o){if(n<0||n>=e.length)return;let i=r,a=s;for(let l of o){let u=ae(l);if(u!==0){if(a<u)break;i>=0&&i<e[n].length&&(e[n][i]=l,t[n][i]="label",u===2&&i+1<e[n].length&&(e[n][i+1]="",t[n][i+1]="label")),i+=u,a-=u}}for(;a>0;)i>=0&&i<e[n].length&&(e[n][i]=" ",t[n][i]="empty"),i+=1,a-=1}function vt(e,t,r,n){let s=n.points;if(s.length<2)return;for(let l=0;l+1<s.length;l+=1)xt(e,t,r,s[l],s[l+1]);for(let l=1;l+1<s.length;l+=1){let u=s[l-1],d=s[l],h=s[l+1],p=wt(u,d,h,r);p&&qe(e,t,d.x,d.y,p,"edgeCorner")}let o=s[s.length-1],i=s[s.length-2],a=Ot(i,o,r);a&&qe(e,t,o.x,o.y,a,"arrow")}function xt(e,t,r,n,s){if(!(n.x===s.x&&n.y===s.y)){if(n.y===s.y){let o=n.y,i=Math.min(n.x,s.x),a=Math.max(n.x,s.x);for(let l=i;l<=a;l+=1)We(e,t,l,o,r,"h")}else if(n.x===s.x){let o=n.x,i=Math.min(n.y,s.y),a=Math.max(n.y,s.y);for(let l=i;l<=a;l+=1)We(e,t,o,l,r,"v")}}}function We(e,t,r,n,s,o){if(n<0||n>=e.length)return;let i=e[n];if(r<0||r>=i.length)return;let a=t[n][r];if(!(a==="boxH"||a==="boxV"||a==="boxCorner"||a==="label")){if(a==="empty"){i[r]=o==="h"?s.horizontal:s.vertical,t[n][r]=o==="h"?"edgeH":"edgeV";return}if(a==="edgeH"&&o==="v"){i[r]=s.cross,t[n][r]="edgeCorner";return}if(a==="edgeV"&&o==="h"){i[r]=s.cross,t[n][r]="edgeCorner";return}}}function qe(e,t,r,n,s,o){if(n<0||n>=e.length)return;let i=e[n];if(r<0||r>=i.length)return;let a=t[n][r];a==="boxH"||a==="boxV"||a==="boxCorner"||a==="label"||(i[r]=s,t[n][r]=o)}function wt(e,t,r,n){let s=e.y===t.y,o=t.y===r.y;if(s===o)return;if(s){let l=e.x<t.x,u=r.y>t.y;return l&&u?n.cornerTR:l&&!u?n.cornerBR:!l&&u?n.cornerTL:n.cornerBL}let i=e.y<t.y,a=r.x>t.x;return i&&a?n.cornerBL:i&&!a?n.cornerBR:!i&&a?n.cornerTL:n.cornerTR}function Ot(e,t,r){if(t.x>e.x)return r.arrowRight;if(t.x<e.x)return r.arrowLeft;if(t.y>e.y)return r.arrowDown;if(t.y<e.y)return r.arrowUp}function Et(e){let t=e.length;for(;t>0&&e.charCodeAt(t-1)===32;)t-=1;return e.slice(0,t)}function Qe(e){let t=_t(e);St(t),Rt(t),Gt(t),Dt(t,e);let r=$t(t,e),{width:n,height:s}=Tt(t),o=[];for(let i of t.layers)for(let a of i)a.isVirtual||o.push({id:a.id,layer:a.layer,order:a.order,x:a.x,y:a.y,w:a.w,h:a.h});return{boxes:o,edges:r,width:n,height:s}}function _t(e){let t=new Map;for(let s of e.nodes)t.set(s,{id:s,isVirtual:!1,layer:-1,order:0,x:0,y:0,w:e.widthCells(s),h:e.heightCells(s),in:[],out:[]});let r=[],n=0;for(let s of e.edges){if(s.from===s.to)continue;let o=t.get(s.from),i=t.get(s.to);if(!o||!i)continue;let a={chainId:n++,chainFrom:s.from,chainTo:s.to,fromId:s.from,toId:s.to,hopIndex:0,chainLen:1};o.out.push(a),i.in.push(a),r.push(a)}return{nodes:t,layers:[],hops:r}}function St(e){let t=new Map;for(let o of e.nodes.values())t.set(o.id,o.in.length);let r=[];for(let o of e.nodes.values())(t.get(o.id)??0)===0&&(o.layer=0,r.push(o));let n=new Set,s=0;for(;s<r.length;){let o=r[s++];if(!n.has(o.id)){n.add(o.id);for(let i of o.out){let a=e.nodes.get(i.toId);a.layer=Math.max(a.layer,o.layer+1);let l=(t.get(a.id)??0)-1;t.set(a.id,l),l<=0&&r.push(a)}}}for(let o of e.nodes.values())o.layer<0&&(o.layer=0)}function Rt(e){let t=Math.max(0,...Array.from(e.nodes.values(),o=>o.layer)),r=Array.from({length:t+1},()=>[]);for(let o of e.nodes.values())r[o.layer].push(o);let n=[],s=0;for(let o of e.hops){let i=e.nodes.get(o.fromId),a=e.nodes.get(o.toId),l=a.layer-i.layer;if(l<=0){i.out=i.out.filter(h=>h!==o),a.in=a.in.filter(h=>h!==o);continue}if(l===1){o.hopIndex=0,o.chainLen=1,n.push(o);continue}i.out=i.out.filter(h=>h!==o),a.in=a.in.filter(h=>h!==o);let u=i;for(let h=1;h<l;h+=1){let p=`__virt_${s++}__`,f={id:p,isVirtual:!0,layer:i.layer+h,order:0,x:0,y:0,w:0,h:1,in:[],out:[]};e.nodes.set(p,f),r[f.layer].push(f);let c={chainId:o.chainId,chainFrom:o.chainFrom,chainTo:o.chainTo,fromId:u.id,toId:p,hopIndex:h-1,chainLen:l};u.out.push(c),f.in.push(c),n.push(c),u=f}let d={chainId:o.chainId,chainFrom:o.chainFrom,chainTo:o.chainTo,fromId:u.id,toId:a.id,hopIndex:l-1,chainLen:l};u.out.push(d),a.in.push(d),n.push(d)}for(let o of r)for(let i=0;i<o.length;i+=1)o[i].order=i;e.layers=r,e.hops=n}function Gt(e){for(let r=0;r<4;r+=1){for(let n=1;n<e.layers.length;n+=1)Ye(e,e.layers[n],"in"),ue(e.layers[n]);for(let n=e.layers.length-2;n>=0;n-=1)Ye(e,e.layers[n],"out"),ue(e.layers[n])}for(let r=0;r<2;r+=1){let n=!1;for(let s=1;s<e.layers.length;s+=1){let o=e.layers[s];for(let i=0;i+1<o.length;i+=1){let a=Xe(e,o[i],o[i+1],"in");[o[i],o[i+1]]=[o[i+1],o[i]],ue(o),Xe(e,o[i],o[i+1],"in")<a?n=!0:([o[i],o[i+1]]=[o[i+1],o[i]],ue(o))}}if(!n)break}}function Ye(e,t,r){let n=new Map;for(let s of t){let o=r==="in"?s.in:s.out;if(o.length===0){n.set(s.id,s.order);continue}let i=0,a=0;for(let l of o){let u=e.nodes.get(r==="in"?l.fromId:l.toId);u&&(i+=u.order,a+=1)}n.set(s.id,a===0?s.order:i/a)}t.sort((s,o)=>{let i=n.get(s.id),a=n.get(o.id);return i!==a?i-a:s.order-o.order})}function ue(e){for(let t=0;t<e.length;t+=1)e[t].order=t}function Xe(e,t,r,n){let s=n==="in"?t.in:t.out,o=n==="in"?r.in:r.out,i=0;for(let a of s)for(let l of o){let u=e.nodes.get(n==="in"?a.fromId:a.toId)?.order??0,d=e.nodes.get(n==="in"?l.fromId:l.toId)?.order??0;(t.order<r.order&&u>d||t.order>r.order&&u<d)&&(i+=1)}return i}function Dt(e,t){t.direction==="LR"?Ct(e,t):kt(e,t)}function Ct(e,t){let r=[],n=0;for(let s=0;s<e.layers.length;s+=1){r.push(n);let o=0;for(let i of e.layers[s])o=Math.max(o,i.w);n+=o+t.layerGap}for(let s=0;s<e.layers.length;s+=1)for(let o of e.layers[s])o.x=r[s];for(let s of e.layers){let o=0;for(let i of s)i.y=o,o+=i.h+t.nodeGap}Ze(e,t,"y")}function kt(e,t){let r=[],n=0;for(let s=0;s<e.layers.length;s+=1){r.push(n);let o=0;for(let i of e.layers[s])o=Math.max(o,i.h);n+=o+t.layerGap}for(let s=0;s<e.layers.length;s+=1)for(let o of e.layers[s])o.y=r[s];for(let s of e.layers){let o=0;for(let i of s)i.x=o,o+=i.w+t.nodeGap}Ze(e,t,"x")}function Ze(e,t,r){let n=o=>r==="y"?o.h:o.w,s=t.nodeGap;for(let o=0;o<2;o+=1){let i=o===0?e.layers.slice(1):e.layers.slice(0,-1).reverse();for(let a of i){let l=new Map;for(let d of a){let h=o===0?d.in:d.out;if(h.length===0)continue;let p=[];for(let c of h){let g=e.nodes.get(o===0?c.fromId:c.toId);if(!g)continue;let O=r==="y"?g.y:g.x;p.push(O+Math.floor(n(g)/2))}if(p.length===0)continue;p.sort((c,g)=>c-g);let f=p[Math.floor(p.length/2)];l.set(d.id,f-Math.floor(n(d)/2))}let u=0;for(let d of a){let h=l.get(d.id),p=r==="y"?d.y:d.x,c=Math.max(h??p,u);r==="y"?d.y=c:d.x=c,u=c+n(d)+s}}}}function $t(e,t){let r=new Map;for(let u of e.hops){let d=r.get(u.chainId);d?d.push(u):r.set(u.chainId,[u])}for(let u of r.values())u.sort((d,h)=>d.hopIndex-h.hopIndex);let n=t.direction==="LR",s=u=>n?u.x:u.y,o=u=>n?u.w:u.h,i=u=>n?u.y+Math.floor(u.h/2):u.x+Math.floor(u.w/2),a=new Map;for(let u=0;u+1<e.layers.length;u+=1){let d=e.layers[u],h=e.layers[u+1],p=0;for(let _ of d)p=Math.max(p,s(_)+o(_));let f=Number.POSITIVE_INFINITY;for(let _ of h)f=Math.min(f,s(_));let c=Number.isFinite(f)?f-1:p,g=Math.max(1,c-p+1),O=[];for(let _ of d)for(let R of _.out)O.push(R);O.sort((_,R)=>{let k=i(e.nodes.get(_.fromId)),$=i(e.nodes.get(R.fromId));if(k!==$)return k-$;let D=i(e.nodes.get(_.toId)),G=i(e.nodes.get(R.toId));return D-G});let S=[],b=new Map;for(let _ of O){let R=i(e.nodes.get(_.fromId)),k=i(e.nodes.get(_.toId)),$=Math.min(R,k),D=Math.max(R,k),G=-1;for(let P=0;P<S.length;P+=1){let F=S[P],H=!0;for(let U of F)if(U.lo<=D&&$<=U.hi){H=!1;break}if(H){F.push({lo:$,hi:D}),G=P;break}}G<0&&(S.push([{lo:$,hi:D}]),G=S.length-1),b.set(_,G)}let m=S.length,y=g>=Math.max(3,m+2),x=y?p+1:p,v=y?c-1:c,w=Math.max(1,v-x+1);for(let _ of O){let R=b.get(_),k;if(m<=1)k=x+Math.floor(w/2);else{let $=(w-1)/(m-1);k=x+Math.floor(R*$)}a.set(_,Math.max(p,Math.min(c,k)))}}let l=[];for(let[,u]of r){let d=[];for(let p=0;p<u.length;p+=1){let f=u[p],c=e.nodes.get(f.fromId),g=e.nodes.get(f.toId),O=a.get(f),S=c.isVirtual?s(c):s(c)+o(c),b=g.isVirtual?s(g):s(g)-1,m=i(c),y=i(g);p===0&&le(d,n,S,m),m!==y&&(le(d,n,O,m),le(d,n,O,y)),le(d,n,b,y)}let h=u[0];l.push({from:h.chainFrom,to:h.chainTo,points:Nt(d)})}return l}function le(e,t,r,n){e.push(t?{x:r,y:n}:{x:n,y:r})}function Nt(e){let t=[];for(let r of e){let n=t[t.length-1];(!n||n.x!==r.x||n.y!==r.y)&&t.push(r)}return t}function Tt(e){let t=0,r=0;for(let n of e.layers)for(let s of n)t=Math.max(t,s.x+s.w),r=Math.max(r,s.y+s.h);return{width:t,height:r}}var At=24,Pt=4,Mt=1,Lt=3;function et(e,t){let r=It(t.direction),n=Math.max(3,t.maxLabelWidth??At),s=t.asciiCharset??"unicode",o=Object.keys(e.nodes).sort(),i=new Set(o),a=e.edges.filter(f=>i.has(f.from)&&i.has(f.to)),l=new Map,u=new Map;for(let f of o){let c=ze(f,n);l.set(f,c),u.set(f,ae(c)+4)}let d=Qe({nodes:o,edges:a,widthCells:f=>u.get(f)??3,heightCells:()=>Lt,layerGap:Pt,nodeGap:Mt,direction:r}),h=Ue(d,{charset:s,labelOf:f=>l.get(f)??f}),p=t.logger;return p&&p(h),h}function It(e){if(e===void 0||e==="LR")return"LR";if(e==="TD")return"TD";throw new Error(`ascii describe supports direction "LR" or "TD" only; got ${String(e)}`)}var T="::",B="__meta__",q=1;function tt(e,t){let r=Math.max(16,e.size*4),n=0;for(;e.size>0;){if(n++>=r){console.error(`[Graph "${t}".destroy] disposer drain exceeded cap (${r}); ${e.size} disposer(s) discarded`),e.clear();return}let s=e.values().next();if(s.done)return;let o=s.value;e.delete(o);try{o()}catch(i){console.error(`[Graph "${t}".destroy] disposer threw:`,i)}}}function st(e){return e!=null&&typeof e=="object"&&"cache"in e&&typeof e.subscribe=="function"&&typeof e.down=="function"}function jt(e){if(e!=null)return st(e)?e.cache:e}function Bt(e){let t=[];for(let r of Object.keys(e).sort()){let n=e[r].v;n!=null&&t.push(`${r} ${n.id} ${n.version}`)}return t.join(`
|
|
4
|
+
`)}function nt(e){if(e.version!==q)throw new Error(`unsupported snapshot version ${String(e.version)} (expected ${q})`);for(let t of["name","nodes","edges","subgraphs"])if(!(t in e))throw new Error(`snapshot missing required key "${t}"`);if(typeof e.name!="string")throw new TypeError("snapshot 'name' must be a string");if(typeof e.nodes!="object"||e.nodes===null||Array.isArray(e.nodes))throw new TypeError("snapshot 'nodes' must be an object");if(!Array.isArray(e.edges))throw new TypeError("snapshot 'edges' must be an array");if(!Array.isArray(e.subgraphs))throw new TypeError("snapshot 'subgraphs' must be an array")}function Ft(e,t){let r=new WeakMap,n=(s,o)=>{if(Object.is(s,o))return!0;if(s==null||o==null||typeof s!="object"||typeof o!="object")return!1;let i=r.get(s);if(i==null&&(i=new WeakSet,r.set(s,i)),i.has(o))return!0;i.add(o);let a=s.constructor,l=o.constructor;if(a!==l)return!1;if(s instanceof Date)return s.getTime()===o.getTime();if(s instanceof RegExp)return s.source===o.source&&s.flags===o.flags;if(Array.isArray(s)){let p=o;if(s.length!==p.length)return!1;for(let f=0;f<s.length;f++)if(!n(s[f],p[f]))return!1;return!0}if(s instanceof Map){let p=o;if(s.size!==p.size)return!1;for(let[f,c]of s)if(!p.has(f)||!n(c,p.get(f)))return!1;return!0}if(s instanceof Set){let p=o;if(s.size!==p.size)return!1;for(let f of s){let c=!1;for(let g of p)if(n(f,g)){c=!0;break}if(!c)return!1}return!0}if(ArrayBuffer.isView(s)){let p=s,f=o;if(p.length!==f.length)return!1;for(let c=0;c<p.length;c++)if(p[c]!==f[c])return!1;return!0}let u=Object.keys(s),d=Object.keys(o);if(u.length!==d.length)return!1;let h=new Set(d);for(let p of u)if(!h.has(p)||!n(s[p],o[p]))return!1;return!0};return n(e,t)}function De(e){if(e===null||typeof e!="object")return e;if(Array.isArray(e))return e.map(De);let t=e,r=Object.keys(t).sort(),n={};for(let s of r)n[s]=De(t[s]);return n}function Ht(e){return e.replaceAll("\\","\\\\").replaceAll('"','\\"')}function Vt(e){return e.replaceAll("\\","\\\\").replaceAll('"','\\"')}function zt(e){return e==="TD"?"down":e==="BT"?"up":e==="RL"?"left":"right"}function it(e){let t=new Set,r=[];function n(s,o){let i=`${s}\0${o}`;t.has(i)||(t.add(i),r.push([s,o]))}for(let[s,o]of Object.entries(e.nodes)){let i=o.deps;if(i)for(let a of i)n(a,s)}for(let s of e.edges)n(s.from,s.to);return r}function at(e){if(e===void 0)return"LR";if(e==="TD"||e==="LR"||e==="BT"||e==="RL")return e;throw new Error(`invalid diagram direction ${String(e)}; expected one of: TD, LR, BT, RL`)}function Kt(e,t){let r=t.includeEdges??!0,n=t.includeSubgraphs??!0,{expand:s,...o}=e,i={...o,edges:r?e.edges:[],subgraphs:n?e.subgraphs:[]},a=JSON.stringify(De(i),null,t.indent??2);return t.logger?.(a),a}function Wt(e,t){let r=t.includeEdges??!0,n=t.includeSubgraphs??!0,s=[];s.push(`Graph ${e.name}`),s.push("Nodes:");for(let i of Object.keys(e.nodes).sort()){let a=e.nodes[i];s.push(`- ${i} (${a.type}/${a.status}): ${de(a.value)}`)}if(r){s.push("Edges:");for(let i of e.edges)s.push(`- ${i.from} -> ${i.to}`)}if(n){s.push("Subgraphs:");for(let i of e.subgraphs)s.push(`- ${i}`)}let o=s.join(`
|
|
5
|
+
`);return t.logger?.(o),o}function ut(e,t){let r=at(t.direction),n=Object.keys(e.nodes).sort(),s=new Map;for(let i=0;i<n.length;i+=1)s.set(n[i],`n${i}`);let o=[`flowchart ${r}`];for(let i of n){let a=s.get(i);o.push(` ${a}["${Ht(i)}"]`)}for(let[i,a]of it(e)){let l=s.get(i),u=s.get(a);!l||!u||o.push(` ${l} --> ${u}`)}return o.join(`
|
|
6
|
+
`)}function qt(e,t){let r=ut(e,t);return Ut(r)}function Ut(e,t){let r=t?.theme??"default",n=t?.autoSync??!0,o=JSON.stringify({code:e,mermaid:{theme:r},autoSync:n}),i=new TextEncoder().encode(o),a="";for(let u=0;u<i.length;u++)a+=String.fromCharCode(i[u]);return`https://mermaid.live/edit#base64:${globalThis.btoa(a).replace(/\+/g,"-").replace(/\//g,"_").replace(/=+$/,"")}`}function Jt(e,t){let r=at(t.direction),n=Object.keys(e.nodes).sort(),s=new Map;for(let i=0;i<n.length;i+=1)s.set(n[i],`n${i}`);let o=[`direction: ${zt(r)}`];for(let i of n){let a=s.get(i);o.push(`${a}: "${Vt(i)}"`)}for(let[i,a]of it(e)){let l=s.get(i),u=s.get(a);!l||!u||o.push(`${l} -> ${u}`)}return o.join(`
|
|
7
|
+
`)}function Yt(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function ce(e){let t="^";for(let r=0;r<e.length;r+=1){let n=e[r];if(n==="*"){t+=".*";continue}if(n==="?"){t+=".";continue}if(n==="["){let s=e.indexOf("]",r+1);if(s<=r+1){t+="\\[";continue}let o=e.slice(r+1,s);o.startsWith("!")&&(o=`^${o.slice(1)}`),o=o.replace(/\\/g,"\\\\"),t+=`[${o}]`,r=s;continue}t+=Yt(n)}return t+="$",new RegExp(t)}var Xt={data:"\x1B[32m",dirty:"\x1B[33m",resolved:"\x1B[36m",invalidate:"\x1B[93m",pause:"\x1B[90m",resume:"\x1B[96m",complete:"\x1B[34m",error:"\x1B[31m",teardown:"\x1B[91m",derived:"\x1B[35m",path:"\x1B[90m",reset:"\x1B[0m"},Qt={data:"",dirty:"",resolved:"",invalidate:"",pause:"",resume:"",complete:"",error:"",teardown:"",derived:"",path:"",reset:""};function de(e){if(typeof e=="string")return JSON.stringify(e);if(typeof e=="number"||typeof e=="boolean"||e==null)return String(e);try{return JSON.stringify(e)}catch{return"[unserializable]"}}function Zt(e){return e==="none"?Qt:e==="ansi"||e==null?Xt:{data:e.data??"",dirty:e.dirty??"",resolved:e.resolved??"",invalidate:e.invalidate??"",pause:e.pause??"",resume:e.resume??"",complete:e.complete??"",error:e.error??"",teardown:e.teardown??"",derived:e.derived??"",path:e.path??"",reset:e.reset??""}}function rt(e){if(e==null)return{};let t=e.detail;return t==="full"?{...e,structured:e.structured??!0,timeline:e.timeline??!0,causal:e.causal??!0,derived:e.derived??!0}:t==="minimal"?{...e,structured:e.structured??!0}:e.format==="stage-log"?{...e,structured:e.structured??!0,timeline:e.timeline??!0}:e}function en(e,t,r){for(let n=0;n<e.length;n++){let s=e.charCodeAt(n);if(s<32||s===127)throw new Error(`Graph "${t}": ${r} "${e}" must not contain control character (U+${s.toString(16).padStart(4,"0").toUpperCase()} at index ${n})`)}}function Ge(e,t,r){if(e==="")throw new Error(`Graph "${t}": ${r} name must be non-empty`);if(e.includes(T))throw new Error(`Graph "${t}": ${r} "${e}" must not contain '${T}' (path separator)`);if(e===B)throw new Error(`Graph "${t}": ${r} name "${B}" is reserved for meta companion paths`);en(e,t,r)}function tn(e,t){if(e==="")throw new Error(`Graph "${t}": resolve path must be non-empty`);let r=e.split(T);for(let n of r)if(n==="")throw new Error(`Graph "${t}": resolve path has empty segment`);return r}function nn(e,t){let r=!1;for(let s of e)if(!t.isMetaPassthrough(s[0])){r=!0;break}return r?e.filter(s=>t.isMetaPassthrough(s[0])):e}function lt(e){for(let t of e._mounts.values())lt(t);for(let t of e._nodes.values())try{t.down([[z]],{internal:!0})}catch{}}var Ce=class e{name;opts;config;_nodes=new Map;_nodeToName=new WeakMap;_mounts=new Map;_parent=void 0;_storageDisposers=new Set;_disposers=new Set;_destroyed=!1;_topology;_topologyEmitters=new Set;constructor(t,r){if(t==="")throw new Error("Graph name must be non-empty");if(t.includes(T))throw new Error(`Graph name must not contain '${T}' (got "${t}")`);if(t===B)throw new Error(`Graph name "${B}" is reserved for meta companion paths`);this.name=t,this.opts=Object.freeze({...r??{}}),this.config=r?.config??we,this._traceRing=new Se(r?.traceCapacity??1e3),r?.versioning!=null&&this.setVersioning(r.versioning)}ancestors(t=!0){let r=[],n=t?this:this._parent;for(;n!=null;)r.push(n),n=n._parent;return r}get topology(){return this._topology==null&&(this._topology=Me(t=>{let r=n=>{t.emit(n)};return this._topologyEmitters.add(r),()=>{this._topologyEmitters.delete(r)}},{name:`${this.name}_topology`})),this._topology}_emitTopology(t){if(!(this._topology==null||this._topologyEmitters.size===0))for(let r of this._topologyEmitters)r(t)}nameOf(t){return this._nodeToName.get(t)}add(t,r){let n=t.name,s=r?.name??n;if(s==null||s==="")throw new Error(`Graph "${this.name}": graph.add requires a non-empty name \u2014 pass via opts.name or set it on the node (e.g. state(0, { name: "x" }))`);let o=s,i=r?.annotation;if(Ge(o,this.name,"add"),this._mounts.has(o))throw new Error(`Graph "${this.name}": name "${o}" is already a mount point`);if(this._nodes.has(o))throw new Error(`Graph "${this.name}": node "${o}" already exists`);let a=this._nodeToName.get(t);if(a!==void 0)throw new Error(`Graph "${this.name}": node instance already registered as "${a}"`);return this._nodes.set(o,t),this._nodeToName.set(t,o),this._emitTopology({kind:"added",name:o,nodeKind:"node"}),i!=null&&(this._annotations.set(o,i),this.config.inspectorEnabled&&this._traceRing.push({path:o,annotation:i,timestamp_ns:K()})),t}setVersioning(t){if(t!=null)for(let r of this._nodes.values())r instanceof L&&r._applyVersioning(t)}remove(t){Ge(t,this.name,"remove");let r=this._mounts.get(t);if(r){let o={kind:"mount",nodes:[],mounts:[]},i=[];r._collectObserveTargets("",i);for(let[a,l]of i)a.includes(`${T}${B}${T}`)||o.nodes.push(a);return o.nodes.sort(),o.mounts.push(t),o.mounts.push(...r._collectSubgraphs(`${t}${T}`)),this._mounts.delete(t),r._parent=void 0,lt(r),this._emitTopology({kind:"removed",name:t,nodeKind:"mount",audit:o}),o}let n=this._nodes.get(t);if(!n)throw new Error(`Graph "${this.name}": unknown node or mount "${t}"`);this._nodes.delete(t),this._nodeToName.delete(n),n.down([[z]],{internal:!0});let s={kind:"node",nodes:[t],mounts:[]};return this._emitTopology({kind:"removed",name:t,nodeKind:"node",audit:s}),s}removeAll(t){let r=typeof t=="function"?t:(()=>{let o=ce(t);return i=>o.test(i)})(),n={kind:"mount",nodes:[],mounts:[]},s=[...this._nodes.keys(),...this._mounts.keys()].filter(o=>r(o));for(let o of s){let i=this.remove(o);n.nodes.push(...i.nodes),n.mounts.push(...i.mounts)}return n.nodes.sort(),n.mounts.sort(),n}[Symbol.iterator](){let t=[...this._nodes.keys()].sort(),r=this._nodes,n=0;return{[Symbol.iterator](){return this},next(){if(n>=t.length)return{value:void 0,done:!0};let s=t[n++];return{value:[s,r.get(s)],done:!1}}}}node(t){if(t==="")throw new Error(`Graph "${this.name}": node name must be non-empty`);if(t.includes(T))return this.resolve(t);let r=this._nodes.get(t);if(!r)throw new Error(`Graph "${this.name}": unknown node "${t}"`);return r}get(t){return this.node(t).cache}set(t,r,n){let s=n?.internal===!0;this.node(t).down([[Y,r]],{actor:n?.actor,internal:s,delivery:"write"})}setAll(t,r){let n=Symbol.iterator in t?t:Object.entries(t);Ae(()=>{for(let[s,o]of n)this.set(s,o,r)})}invalidate(t,r){let n=r?.internal===!0;this.node(t).down([[te]],{actor:r?.actor,internal:n,delivery:"write"})}error(t,r,n){let s=n?.internal===!0;this.node(t).down([[Q,r]],{actor:n?.actor,internal:s,delivery:"write"})}complete(t,r){let n=r?.internal===!0;this.node(t).down([[X]],{actor:r?.actor,internal:n,delivery:"write"})}edges(t){let r=t?.recursive===!0,n=new Map;if(!r){for(let[l,u]of this._nodes)n.set(u,l);let a=[];for(let[l,u]of this._nodes)if(u instanceof L)for(let d of u._deps){let h=n.get(d.node);h!=null&&a.push([h,l])}return a.sort((l,u)=>l[0]<u[0]?-1:l[0]>u[0]?1:l[1]<u[1]?-1:l[1]>u[1]?1:0),a}let s=[];this._collectObserveTargets("",s);let o=new Map;for(let[a,l]of s)o.set(l,a);let i=[];for(let[a,l]of s)if(l instanceof L)for(let u of l._deps){let d=o.get(u.node);d!=null&&i.push([d,a])}return i.sort((a,l)=>a[0]<l[0]?-1:a[0]>l[0]?1:a[1]<l[1]?-1:a[1]>l[1]?1:0),i}mount(t,r){if(r===void 0){let s=new e(t);return this.mount(t,s)}if(typeof r=="function"){let s=new e(t);return r(s),this.mount(t,s)}let n=r;if(Ge(t,this.name,"mount"),this._nodes.has(t))throw new Error(`Graph "${this.name}": cannot mount at "${t}" \u2014 node with that name exists`);if(this._mounts.has(t))throw new Error(`Graph "${this.name}": mount "${t}" already exists`);if(n===this)throw new Error(`Graph "${this.name}": cannot mount a graph into itself`);if(n._parent!=null)throw new Error(`Graph "${this.name}": this child graph is already mounted on "${n._parent.name}"`);for(let s=this;s!=null;s=s._parent)if(s===n)throw new Error(`Graph "${this.name}": mount("${t}", \u2026) would create a mount cycle`);return this._mounts.set(t,n),n._parent=this,this._emitTopology({kind:"added",name:t,nodeKind:"mount"}),n}resolve(t){let r=tn(t,this.name);return this._resolveFromSegments(r)}tryResolve(t){try{return this.resolve(t)}catch{return}}_resolveFromSegments(t){let r=t;if(r[0]===this.name&&(r=r.slice(1),r.length===0))throw new Error(`Graph "${this.name}": resolve path ends at graph name only`);let n=r[0],s=r.slice(1);if(s.length===0){let a=this._nodes.get(n);if(a)return a;throw this._mounts.has(n)?new Error(`Graph "${this.name}": path ends at subgraph "${n}" \u2014 not a node (GRAPHREFLY-SPEC \xA73.5)`):new Error(`Graph "${this.name}": unknown name "${n}"`)}let o=this._nodes.get(n);if(o&&s.length>0&&s[0]===B)return this._resolveMetaChainFromNode(o,s,r.join(T));let i=this._mounts.get(n);if(!i)throw this._nodes.has(n)?new Error(`Graph "${this.name}": "${n}" is a node; trailing path "${s.join(T)}" is invalid`):new Error(`Graph "${this.name}": unknown mount or node "${n}"`);return i.resolve(s.join(T))}_resolveMetaChainFromNode(t,r,n){let s=t,o=0,i=[...r];for(;o<i.length;){if(i[o]!==B)throw new Error(`Graph "${this.name}": expected ${B} segment in meta path "${n}"`);if(o+1>=i.length)throw new Error(`Graph "${this.name}": meta path requires a key after ${B} in "${n}"`);let a=i[o+1],l=s.meta[a];if(!l)throw new Error(`Graph "${this.name}": unknown meta "${a}" in path "${n}"`);s=l,o+=2}return s}signal(t,r){if(r?.internal!==!0){for(let s of t)if(this.config.messageTier(s[0])===3)throw new Error(`Graph "${this.name}": Graph.signal() rejects tier-3 messages (DATA / RESOLVED). Broadcast is for control-plane tiers (START / DIRTY / INVALIDATE / PAUSE / RESUME / COMPLETE / ERROR / TEARDOWN). For per-node value writes, use Graph.set or graph.node(name).down(...).`)}let n=[];if(this._signalDeliver(t,r??{},new Set,n),n.length>0)throw n[0]}_signalDeliver(t,r,n,s){for(let l of this._mounts.values())l._signalDeliver(t,r,n,s);let i=r.internal===!0?{internal:!0}:{actor:r.actor,delivery:"signal"},a=nn(t,this.config);for(let l of[...this._nodes.keys()].sort()){let u=this._nodes.get(l);if(!n.has(u)){n.add(u);try{u.down(t,i)}catch(d){if(d instanceof W)throw d;s.push(d)}a.length!==0&&this._signalMetaSubtree(u,a,n,i,s)}}}_signalMetaSubtree(t,r,n,s,o){for(let i of Object.keys(t.meta).sort()){let a=t.meta[i];if(!n.has(a)){n.add(a);try{a.down(r,s)}catch(l){if(l instanceof W)throw l;o.push(l)}this._signalMetaSubtree(a,r,n,s,o)}}}describe(t){if(t?.reactive===!0)return this._describeReactive(t);let r=jt(t?.actor),n=t?.filter,s=re(t?.detail,t?.fields),o=t?.format==="spec",i=o?re("minimal"):s,a=[];this._collectObserveTargets("",a);let l=new Map;for(let[v,w]of a)l.set(w,v);let u=[];{let v=a.map(([,R])=>R),w=new Set(l.values()),_=0;for(;v.length>0;){let R=v.shift();if(R instanceof L)for(let k of R._deps){let $=k.node;if(l.has($))continue;let D=$.name??"",G=D;if(!G||w.has(G))if(D){let P=2;for(;w.has(`${D}#${P}`);)P++;G=`${D}#${P}`}else for(G=`__internal__/${_++}`;w.has(G);)G=`__internal__/${_++}`;l.set($,G),w.add(G),u.push([G,$]),v.push($)}}}let d=[...a,...u],h={};for(let[v,w]of d){if(r!=null&&!w.allowsObserve(r))continue;let _=_e(w,i),R=w instanceof L?w._deps.map(G=>l.get(G.node)??G.node.name??""):[],{name:k,...$}=_,D={...$,deps:R};if(!o){let G=this._annotations.get(v);G!=null&&(D.annotation=G)}if(n!=null)if(typeof n=="function"){let G=n;if(!(G.length>=2?G(v,D):G(D)))continue}else{let G=!0;for(let[P,F]of Object.entries(n)){let H=P==="deps_includes"?"depsIncludes":P==="meta_has"?"metaHas":P;if(H==="depsIncludes"){if(!D.deps.includes(String(F))){G=!1;break}continue}if(H==="metaHas"){if(!Object.hasOwn(D.meta??{},String(F))){G=!1;break}continue}if(D[H]!==F){G=!1;break}}if(!G)continue}h[v]=D}let p=new Set(Object.keys(h)),f=[];for(let[v,w]of d)if(w instanceof L)for(let _ of w._deps){let R=l.get(_.node);R!=null&&f.push([R,v])}f.sort((v,w)=>v[0]<w[0]?-1:v[0]>w[0]?1:v[1]<w[1]?-1:v[1]>w[1]?1:0);let c=f.map(([v,w])=>({from:v,to:w}));(r!=null||n!=null)&&(c=c.filter(v=>p.has(v.from)&&p.has(v.to)));let g=this._collectSubgraphs(""),O=r!=null||n!=null?g.filter(v=>{let w=`${v}${T}`;return[...p].some(_=>_===v||_.startsWith(w))}):g,S=this,b=t,m={name:this.name,nodes:h,edges:c,subgraphs:O,expand(v){let w={...b,format:void 0};return Array.isArray(v)?(w.fields=v,w.detail=void 0):(w.detail=v,w.fields=void 0),S.describe(w)}},y=t??{},x=y.format;return x==="json"?Kt(m,y):x==="pretty"?Wt(m,y):x==="mermaid"?ut(m,y):x==="mermaid-url"?qt(m,y):x==="d2"?Jt(m,y):x==="ascii"?et(m,y):m}_collectSubgraphs(t){let r=[];for(let n of[...this._mounts.keys()].sort()){let s=t===""?n:`${t}${n}`;r.push(s),r.push(...this._mounts.get(n)._collectSubgraphs(`${s}${T}`))}return r}resourceProfile(t){return Ve(this,t)}reachable(t,r,n={}){return n.withDetail===!0?ot(this.describe(),t,r,{...n,withDetail:!0}):ot(this.describe(),t,r,n)}explain(t,r,n){return n?.reactive===!0?this._explainReactive(t,r,n):this._explainStatic(t,r,n)}_explainStatic(t,r,n){let s=this.describe({detail:"full"}),o=new Map(this._annotations),i=new Map;for(let[a,l]of Object.entries(s.nodes))l.lastMutation!=null&&i.set(a,l.lastMutation);return Ie(s,t,r,{...n?.maxDepth!=null?{maxDepth:n.maxDepth}:{},...n?.findCycle===!0?{findCycle:!0}:{},annotations:o,lastMutations:i})}_describeReactive(t){let r={...t,reactive:!1},n=t.reactiveName??"describe",s=0,o=ne(s,{name:`${n}_version`}),i=this.observe({timeline:!0,structured:!0}),a=!1,l=!1,u=()=>{a||l||(a=!0,xe(()=>{a=!1,!l&&(s+=1,o.emit(s))}))},d=i.onEvent(b=>{let m=b.type;m!=="data"&&m!=="error"&&m!=="complete"&&m!=="teardown"||u()}),h=[],p=new WeakSet,f=b=>{if(p.has(b)||l)return;p.add(b);let m=b.topology.subscribe(y=>{for(let x of y){if(x[0]!==Y)continue;let v=x[1];if(u(),v.kind==="added"&&v.nodeKind==="mount"){let w=b._mounts.get(v.name);w!=null&&f(w)}}});h.push(m);for(let y of b._mounts.keys()){let x=b._mounts.get(y);x!=null&&f(x)}};f(this);let c,g=t.actor;st(g)&&(c=g.subscribe(b=>{let m=!1,y=!1;for(let x of b){let v=x[0];v===Y?m=!0:(v===X||v===Q||v===z)&&(y=!0)}m&&u(),y&&(c?.(),c=void 0,u())}));let O;try{O=Oe([o],()=>this.describe(r),{name:n,describeKind:"derived",meta:{domain:"audit",kind:"describe"},equals:(b,m)=>b===m})}catch(b){d(),c?.();for(let m of h)m();throw i.dispose(),b}let S=Ee(O);return{node:O,dispose(){l=!0,d(),c?.();for(let b of h)b();h.length=0,i.dispose(),S()}}}_explainReactive(t,r,n){let s=0,o=ne(s,{name:"explain_version"}),i=this.observe({timeline:!0,structured:!0}),a=!1,l=!1,u=i.onEvent(f=>{let c=f.type;c!=="data"&&c!=="error"&&c!=="complete"&&c!=="teardown"||a||l||(a=!0,xe(()=>{a=!1,!l&&(s+=1,o.emit(s))}))}),d={...n?.maxDepth!=null?{maxDepth:n.maxDepth}:{},...n?.findCycle===!0?{findCycle:!0}:{}},h;try{h=Oe([o],()=>this._explainStatic(t,r,d),{name:n?.name??"explain",describeKind:"derived",meta:{domain:"audit",kind:"explain_path",from:t,to:r},equals:(f,c)=>f.found===c.found&&f.reason===c.reason&&f.steps.length===c.steps.length&&on(f.steps,c.steps)})}catch(f){throw u(),i.dispose(),f}let p=Ee(h);return{node:h,dispose(){l=!0,u(),i.dispose(),p()}}}_pathsMatching(t){let r=ce(t),n=[];return this._collectObserveTargets("",n),n.map(([s])=>s).filter(s=>r.test(s))}_collectObserveTargets(t,r){for(let n of[...this._mounts.keys()].sort()){let s=t===""?n:`${t}${T}${n}`;this._mounts.get(n)._collectObserveTargets(s,r)}for(let n of[...this._nodes.keys()].sort()){let s=this._nodes.get(n),o=t===""?n:`${t}${T}${n}`;r.push([o,s]),this._appendMetaObserveTargets(o,s,r)}}_appendMetaObserveTargets(t,r,n){for(let s of Object.keys(r.meta).sort()){let o=r.meta[s],i=`${t}${T}${B}${T}${s}`;n.push([i,o]),this._appendMetaObserveTargets(i,o,n)}}observe(t,r){let n=typeof t=="string",o=rt(n?r:t),i=o.structured===!0||o.timeline===!0||o.causal===!0||o.derived===!0||o.detail==="minimal"||o.detail==="full"||o.format!=null,a=o.actor;if(n){let d=t,h=this.resolve(d);if(a!=null&&!h.allowsObserve(a))throw new W({actor:a,action:"observe",nodeName:d});return i?this._buildStructuredObserver([[d,h]],o,"one"):{subscribe(p){return h.subscribe(p)},up(p){try{h.up?.(p)}catch(f){if(f instanceof W)return;throw f}}}}let l=[];this._collectObserveTargets("",l),l.sort((d,h)=>d[0]<h[0]?-1:d[0]>h[0]?1:0);let u=a==null?l:l.filter(([,d])=>d.allowsObserve(a));return i?this._buildStructuredObserver(u,o,"all"):{subscribe:d=>{let h=u.map(([p,f])=>f.subscribe(c=>{d(p,c)}));return()=>{for(let p of h)p()}},up:(d,h)=>{try{this.resolve(d).up?.(h)}catch(p){if(p instanceof W)return;throw p}}}}_buildStructuredObserver(t,r,n){let s=n==="one"?t[0]?.[0]:void 0,o=i=>{if(n==="one"&&s!=null){let d=this.resolve(s);return this._buildStructuredObserver([[s,d]],i,"one")}let a=[];this._collectObserveTargets("",a),a.sort((d,h)=>d[0]<h[0]?-1:d[0]>h[0]?1:0);let l=i.actor,u=l==null?a:a.filter(([,d])=>d.allowsObserve(l));return this._buildStructuredObserver(u,i,"all")};return this._createObserveResult(t,r,o)}_createObserveResult(t,r,n){let s=r.timeline===!0,o=r.causal===!0,i=r.derived===!0,a=r.detail==="minimal",l=this.config.inspectorEnabled,u=(o||i)&&l,d=r.maxEvents,h=d!=null&&d>0?new Se(d):null,p=[],f=new Set,c={},g=new Set,O=0,S=0,b=0,m=0,y=0,x=0,v=!1,w=!1,_=0,R=new Map,k=new Map,$=new Map,D=E=>{h?h.push(E):p.push(E);for(let N of f)N(E)},G=()=>s?{timestamp_ns:K(),in_batch:Te(),batch_id:_}:{},P=(E,N)=>{if(!(!u||!(E instanceof L)))return E._setInspectorHook(I=>{if(I.kind==="dep_message")R.set(E,I.depIndex);else if(I.kind==="run"){let J=I.batchData.map((C,M)=>C!=null&&C.length>0?C.at(-1):I.prevData[M]);k.set(E,J);let j=I.batchData.map(C=>C!=null?[...C]:void 0);$.set(E,j),i&&D({type:"derived",path:N,dep_values:J,dep_batches:j,...G()})}})},F=E=>{let N=R.get(E),I=k.get(E);if(!o||I==null)return{};let j=(N!=null&&N>=0&&E instanceof L?E._deps[N]:void 0)?.node,C=j?.v,M=$.get(E);return{trigger_dep_index:N,trigger_dep_name:j?.name,...C!=null?{trigger_version:{id:C.id,version:C.version}}:{},dep_values:[...I],...M!=null?{dep_batches:M}:{}}},H=[],U=[];for(let[E,N]of t){let I=P(N,E);I&&H.push(I),U.push(N.subscribe(J=>{_++;for(let j of J){let C=j[0],M=G();if(C===Y){c[E]=j[1];let ge=N instanceof L?N.lastMutation?.actor??Z:Z;D({type:"data",path:E,data:j[1],actor:ge,...M,...F(N)})}else if(a)C===me?O++:C===be?S++:C===te?b++:C===ye?m++:C===ve?y++:C===z?x++:C===X&&!g.has(E)?v=!0:C===Q&&(w=!0,g.add(E));else if(C===me)O++,D({type:"dirty",path:E,...M});else if(C===be)S++,D({type:"resolved",path:E,...M,...F(N)});else if(C===te)b++,D({type:"invalidate",path:E,...M});else if(C===ye)m++,D({type:"pause",path:E,lockId:j[1],...M});else if(C===ve)y++,D({type:"resume",path:E,lockId:j[1],...M});else if(C===X)g.has(E)||(v=!0),D({type:"complete",path:E,...M});else if(C===Q){w=!0,g.add(E);let ge=N instanceof L?N.lastMutation?.actor??Z:Z;D({type:"error",path:E,data:j[1],actor:ge,...M})}else C===z&&(x++,D({type:"teardown",path:E,...M}))}}))}let fe=!1,pe=()=>{if(!fe){fe=!0;for(let E of U)E();for(let E of H)E();for(let E of ee)E({value:void 0,done:!0});ee.length=0}},he=[],ee=[];f.add(E=>{let N=ee.shift();N?N({value:E,done:!1}):he.push(E)});let ke={get values(){return c},get dirtyCount(){return O},get resolvedCount(){return S},get invalidateCount(){return b},get pauseCount(){return m},get resumeCount(){return y},get teardownCount(){return x},get events(){return h?h.toArray():[...p]},get anyCompletedCleanly(){return v},get anyErrored(){return w},get completedWithoutErrors(){return v&&!w},onEvent(E){return f.add(E),()=>f.delete(E)},dispose:pe,expand(E){pe();let N={...r};return typeof E=="string"?N.detail=E:Object.assign(N,E),n(rt(N))},[Symbol.asyncIterator](){return{next(){return he.length>0?Promise.resolve({value:he.shift(),done:!1}):fe?Promise.resolve({value:void 0,done:!0}):new Promise(E=>ee.push(E))},return(){return pe(),Promise.resolve({value:void 0,done:!0})}}}};return r.format!=null&&this._attachFormatLogger(ke,r),ke}_attachFormatLogger(t,r){let n=r.format;if(n==null)return;let s=r.logger??(c=>console.log(c)),o=r.includeTypes?new Set(r.includeTypes):null,i=r.excludeTypes?new Set(r.excludeTypes):null,a=o==null&&i==null?()=>!0:c=>(o==null||o.has(c))&&(i==null||!i.has(c)),l=Zt(r.theme),u=n==="stage-log"?K():0,d=c=>c==null?"":r.stageLabels?.[c]??c,h=(c,g)=>c.length>g?`${c.slice(0,g-1)}\u2026`:c,p=c=>c.type==="data"||c.type==="error"?h(de(c.data),120):"",f=c=>{if(n==="stage-log"){let w=(K()-u)/1e9,_=d(c.path).padEnd(9);if(c.type==="data"){let R=p(c);return`[${w.toFixed(3)}s] ${_} \u2190${R?` ${R}`:""}`}if(c.type==="error"){let R=p(c);return`[${w.toFixed(3)}s] ${_} \u2717${R?` ${R}`:""}`}return c.type==="complete"?`[${w.toFixed(3)}s] ${_} \u25A0 complete`:`[${w.toFixed(3)}s] ${_} ${c.type}`}if(n==="json")try{return JSON.stringify(c)}catch{return JSON.stringify({type:c.type,path:c.path,data:"[unserializable]"})}let g=l[c.type]??"",O=c.path?`${l.path}${c.path}${l.reset} `:"",S=c.type==="data"||c.type==="error",b=c.type==="pause"||c.type==="resume",m=S?` ${de(c.data)}`:b?` ${de(c.lockId)}`:"",y=c.type==="data"||c.type==="resolved"||c.type==="derived"?c:void 0,x=y?.trigger_dep_name!=null?` <- ${y.trigger_dep_name}`:y?.trigger_dep_index!=null?` <- #${y.trigger_dep_index}`:"",v=c.in_batch?" [batch]":"";return`${O}${g}${c.type.toUpperCase()}${l.reset}${m}${x}${v}`};t.onEvent(c=>{a(c.type)&&s(f(c),c)})}addDisposer(t){return this._disposers.add(t),()=>{this._disposers.delete(t)}}destroy(){tt(this._disposers,this.name),this.signal([[z]],{internal:!0}),tt(this._storageDisposers,this.name);for(let t of[...this._mounts.values()])t._parent=void 0,t._destroyClearOnly();this._mounts.clear(),this._nodes.clear(),this._parent=void 0,this._destroyed=!0}get destroyed(){return this._destroyed}_destroyClearOnly(){for(let t of[...this._mounts.values()])t._parent=void 0,t._destroyClearOnly();this._mounts.clear(),this._nodes.clear(),this._parent=void 0,this._destroyed=!0}snapshot(t){let{expand:r,...n}=this.describe({detail:"full"}),s={};for(let a of Object.keys(n.nodes).sort()){let{lastMutation:l,guard:u,...d}=n.nodes[a];s[a]=d}let o=[...n.subgraphs].sort(),i={...n,version:1,nodes:s,subgraphs:o};if(t?.format==null)return i;if(t.format==="json-string")return JSON.stringify(i);if(t.format==="bytes"){if(t.codec==null)throw new Error("snapshot({format: 'bytes'}) requires a `codec` name");let a=this.config.lookupCodec(t.codec);if(a==null)throw new Error(`snapshot: codec "${t.codec}" is not registered on this graph's config. Call config.registerCodec(...) before creating nodes.`);return $e(a,a.encode(i))}throw new Error(`snapshot: unknown format "${String(t.format)}"`)}static decode(t,r){let n=r?.config??we,{codec:s,codecVersion:o,payload:i}=Ne(t,n);return s.decode(i,o)}restore(t,r){if(nt(t),t.name!==this.name)throw new Error(`Graph "${this.name}": restore snapshot name "${t.name}" does not match this graph`);let n=r?.only==null?null:(Array.isArray(r.only)?r.only:[r.only]).map(o=>ce(o)),s=r?.includeProducers===!0;for(let o of Object.keys(t.nodes).sort()){if(n!==null&&!n.some(a=>a.test(o)))continue;let i=t.nodes[o];if(i!==void 0){if(!("value"in i)||i.value===void 0){"value"in i&&i.value===void 0&&r?.onError?.(o,new Error(`restore: slice.value is undefined for "${o}" (undefined is the global SENTINEL; not valid DATA)`));continue}if(!(i.type==="derived"||i.type==="effect")&&!(i.type==="producer"&&!s)){if(i.v!=null){let l=this.tryResolve(o)?.v;if(l!=null&&l.id===i.v.id&&l.version===i.v.version)continue}try{this.set(o,i.value)}catch(a){r?.onError?.(o,a)}}}}}static fromSnapshot(t,r){nt(t);let n=typeof r=="function"?r:r?.build,s=typeof r=="function"?void 0:r?.factories,o=new e(t.name);if(n)return n(o),o.restore(t),o;for(let f of[...t.subgraphs].sort((c,g)=>{let O=c.split(T).length,S=g.split(T).length;return O!==S?O-S:c<g?-1:c>g?1:0})){let c=f.split(T),g=o;for(let O of c)g._mounts.has(O)||g.mount(O,new e(O)),g=g._mounts.get(O)}let i=s?Object.entries(s).map(([f,c])=>({re:ce(f),factory:c})):[],a=f=>{for(let c of i)if(c.re.test(f))return c.factory},l=f=>{let c=f.split(T),g=c.pop();if(g==null||g.length===0)throw new Error(`invalid snapshot path "${f}"`);let O=o;for(let S of c){let b=O._mounts.get(S);if(!b)throw new Error(`unknown mount "${S}" in path "${f}"`);O=b}return[O,g]},u=Object.entries(t.nodes).filter(([f])=>!f.includes(`${T}${B}${T}`)).sort((f,c)=>f[0]<c[0]?-1:f[0]>c[0]?1:0),d=new Map(u),h=new Map,p=!0;for(;d.size>0&&p;){p=!1;for(let[f,c]of[...d.entries()]){let g=c?.deps??[];if(!g.every(x=>h.has(x)))continue;let[O,S]=l(f),b={...c?.meta??{}},m=a(f),y;if(c?.type==="state")y=ne(c.value,{meta:b});else{if(m==null)continue;y=m(S,{path:f,type:c.type,value:c.value,meta:b,deps:g,resolvedDeps:g.map(x=>h.get(x))})}O.add(y,{name:S}),h.set(f,y),d.delete(f),p=!0}}if(d.size>0){let f=[...d.keys()].sort().join(", ");throw new Error(`Graph.fromSnapshot could not reconstruct nodes without build callback: ${f}. Pass matching factories via fromSnapshot(data, { factories: { pattern: factoryFn } }).`)}return o.restore(t),o}toJSON(){return this.snapshot()}attachSnapshotStorage(t,r={}){let n=t.map(u=>({tier:u,debounceMs:Math.max(0,u.debounceMs??0),compactEvery:Math.max(1,u.compactEvery??10),timer:void 0,seq:0,lastSnapshot:void 0,lastFingerprint:"",disposed:!1,savePending:void 0}));r.autoRestore===!0&&this._cascadeRestore(t,r.onError);let s=(u,d)=>{if(u.disposed)return;let h=Bt(d.nodes);if(u.lastSnapshot!=null&&h!==""&&h===u.lastFingerprint)return;let p=u.seq+1,f=Pe(),O=u.lastSnapshot==null||p%u.compactEvery===0?{name:this.name,mode:"full",snapshot:d,seq:p,timestamp_ns:f,format_version:q}:{name:this.name,mode:"diff",diff:rn(u.lastSnapshot,d),seq:p,timestamp_ns:f,format_version:q};if(u.tier.filter&&!u.tier.filter(O))return;let S;try{S=u.tier.save(O)}catch(b){r.onError?.(b,u.tier);return}if(S&&typeof S.then=="function"){let y=(u.savePending??Promise.resolve()).then(()=>S,()=>S).then(()=>{u.disposed||(u.seq=p,u.lastSnapshot=d,u.lastFingerprint=h)},x=>{r.onError?.(x,u.tier)});u.savePending=y.finally(()=>{u.savePending===y&&(u.savePending=void 0)})}else u.seq=p,u.lastSnapshot=d,u.lastFingerprint=h},o=(u,d)=>{try{s(u,d)}catch(h){r.onError?.(h,u.tier)}},i=(u,d)=>{if(!d.some(c=>{let g=this.config.messageTier(c[0]);return g>=3&&g<5}))return;if(r.filter){let c=this.tryResolve(u);if(c==null)return;let g=_e(c,re("standard"));if(!r.filter(u,g))return}let p,f=()=>(p==null&&(p=this.snapshot()),p);for(let c of n)c.disposed||(c.debounceMs===0?o(c,f()):(c.timer==null&&(c.timer=new Le),c.timer.start(c.debounceMs,()=>{c.disposed||o(c,this.snapshot())})))},a;if(r.paths!=null){let d=(typeof r.paths=="string"?this._pathsMatching(r.paths):r.paths).map(h=>{let p=this.tryResolve(h);return p==null?()=>{}:p.subscribe(f=>i(h,f))});a=()=>{for(let h of d)h()}}else a=this.observe().subscribe((u,d)=>i(u,d));let l=()=>{a();for(let u of n)u.disposed=!0,u.timer?.cancel();this._storageDisposers.delete(l)};return this._storageDisposers.add(l),{dispose:l}}async _cascadeRestore(t,r){for(let n of t){let s;try{s=await n.load?.()}catch(i){r?.(i,n);continue}if(s==null||typeof s!="object"||Array.isArray(s))continue;let o=s;try{if(o.mode==="full"&&o.snapshot!=null)return this.restore(o.snapshot),!0;if(o.version===q&&o.nodes!=null)return this.restore(o),!0}catch(i){r?.(i,n)}}return!1}static async fromStorage(t,r,n){for(let s of r){let o;try{o=await s.load?.()}catch(l){n?.onError?.(l,s);continue}if(o==null||typeof o!="object"||Array.isArray(o))continue;let i=o,a=i.mode==="full"&&i.snapshot!=null?i.snapshot:i.version===q&&i.nodes!=null?i:void 0;if(a!=null)try{return e.fromSnapshot(a,n)}catch(l){n?.onError?.(l,s)}}throw new Error(`Graph.fromStorage: no tier held a restorable record for "${t}" across ${r.length} tier(s)`)}_annotations=new Map;_traceRing;trace(t,r,n){if(t!=null&&r!=null){if(this.tryResolve(t)==null)return;if(this._annotations.set(t,r),this.config.inspectorEnabled){let s={path:t,annotation:r,timestamp_ns:K(),...n?.actor!=null?{actor:n.actor}:{}};this._traceRing.push(s)}return}return t!=null?this.config.inspectorEnabled?this._annotations.get(t):void 0:this.config.inspectorEnabled?this._traceRing.toArray():[]}annotation(t){return this._annotations.get(t)}clearTrace(){this._annotations.clear(),this._traceRing.clear()}pruneTrace(t){let r=this._traceRing.toArray().filter(s=>!t(s)),n=this._traceRing.size-r.length;this._traceRing.clear();for(let s of r)this._traceRing.push(s);return n}static diff(t,r){let n=new Set(Object.keys(t.nodes)),s=new Set(Object.keys(r.nodes)),o=[...s].filter(b=>!n.has(b)).sort(),i=[...n].filter(b=>!s.has(b)).sort(),a=[],l=[];for(let b of n){if(!s.has(b))continue;let m=t.nodes[b],y=r.nodes[b],x=m.v,v=y.v;x!=null&&v!=null&&x.id===v.id&&x.version!==v.version&&l.push({path:b,id:x.id,from:x.version,to:v.version});let w=x!=null&&v!=null&&x.id===v.id&&x.version===v.version;for(let _ of["type","status","sentinel"]){let R=m[_],k=y[_];R!==k&&a.push({path:b,field:_,from:R,to:k})}if(!w)for(let _ of["value","meta"]){let R=m[_],k=y[_];Ft(R,k)||a.push({path:b,field:_,from:R,to:k})}}let u=b=>`${b.from} ${b.to}`,d=new Set(t.edges.map(u)),h=new Set(r.edges.map(u)),p=r.edges.filter(b=>!d.has(u(b))),f=t.edges.filter(b=>!h.has(u(b))),c=new Set(t.subgraphs),g=new Set(r.subgraphs),O=[...g].filter(b=>!c.has(b)).sort(),S=[...c].filter(b=>!g.has(b)).sort();return{nodesAdded:o,nodesRemoved:i,nodesChanged:a,versionChanges:l,edgesAdded:p,edgesRemoved:f,subgraphsAdded:O,subgraphsRemoved:S}}};function rn(e,t){let r=Ce.diff(e,t),n={};for(let s of r.nodesAdded){let o=t.nodes[s];o!=null&&(n[s]=o)}return{...r,nodesAddedFull:n}}function ot(e,t,r,n={}){let s={paths:[],depths:new Map,truncated:!1};if(!t)return n.withDetail?s:[];if(!n.both&&r!=="upstream"&&r!=="downstream")throw new Error('reachable: direction must be "upstream" or "downstream"');let o=n.maxDepth;if(o!=null&&(!Number.isInteger(o)||o<0))throw new Error("reachable: maxDepth must be an integer >= 0");if(o===0)return n.withDetail?s:[];let i=new Map,a=new Map,l=new Map,u=new Map,d=new Set;for(let[m,y]of Object.entries(e.nodes)){if(!m)continue;d.add(m);let x=y.deps??[];i.set(m,x);for(let v of x)v&&(d.add(v),a.has(v)||a.set(v,new Set),a.get(v).add(m))}for(let m of e.edges){if(m==null||typeof m!="object")continue;let y=typeof m.from=="string"?m.from:"",x=typeof m.to=="string"?m.to:"";!y||!x||(d.add(y),d.add(x),u.has(y)||u.set(y,new Set),u.get(y).add(x),l.has(x)||l.set(x,new Set),l.get(x).add(y))}if(!d.has(t))return n.withDetail?s:[];let h=n.both===!0,p=m=>{if(h){let w=i.get(m)??[],_=l.get(m),R=a.get(m),k=u.get(m),$=[...w];return _&&$.push(..._),R&&$.push(...R),k&&$.push(...k),$}if(r==="upstream"){let w=i.get(m)??[],_=l.get(m);return _?[...w,..._]:w}let y=a.get(m),x=u.get(m),v=y?[...y]:[];return x&&v.push(...x),v},f=new Set([t]),c=new Map,g=[{path:t,depth:0}],O=0,S=!1;for(;O<g.length;){let m=g[O++];if(o!=null&&m.depth>=o){p(m.path).length>0&&(S=!0);continue}for(let y of p(m.path))!y||f.has(y)||(f.add(y),c.set(y,m.depth+1),g.push({path:y,depth:m.depth+1}))}let b=[...c.keys()].sort((m,y)=>m<y?-1:m>y?1:0);return n.withDetail?{paths:b,depths:c,truncated:S}:b}function on(e,t){if(e.length!==t.length)return!1;for(let r=0;r<e.length;r++){let n=e[r],s=t[r];if(n.path!==s.path||n.type!==s.type||n.status!==s.status||n.hop!==s.hop||n.dep_index!==s.dep_index||n.annotation!==s.annotation||n.value!==s.value||n.lastMutation!==s.lastMutation)return!1;let o=n.v,i=s.v;if(o!==i&&(o==null||i==null||o.id!==i.id||o.version!==i.version))return!1}return!0}export{ae as a,Ie as b,A as c,pt as d,He as e,Ve as f,B as g,q as h,Ut as i,Ce as j,rn as k,ot as l};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{c as f}from"./chunk-
|
|
1
|
+
import{c as f}from"./chunk-XIJKEXWR.js";import{a as l,c as o,d,g as s,h as m,j as b,k as c}from"./chunk-A5HZZYRK.js";import{a as r,b as u}from"./chunk-4VVTGLXJ.js";import{b as y}from"./chunk-QYADASLV.js";var R={};y(R,{NS_PER_MS:()=>r,NS_PER_SEC:()=>u,resilientPipeline:()=>O});function O(p,e={}){let t=p;e.rateLimit!=null&&(t=s(t,e.rateLimit)),e.budget!=null&&e.budget.length>0&&(t=f(t,e.budget));let n;if(e.breaker!=null){let k=o(e.breaker),S=e.breakerOnOpen??"skip",a=d(k,{onOpen:S})(t);t=a.node,n=a.breakerState}if(e.timeoutMs!=null){if(e.timeoutMs<=0)throw new RangeError("timeoutMs must be > 0");if(e.timeoutMs>9e6)throw new RangeError("timeoutMs must be <= 9_000_000 (\u22482.5h) to stay within safe ns arithmetic");t=c(t,e.timeoutMs*1e6)}e.retry!=null&&(t=l(t,e.retry)),e.fallback!==void 0&&(t=b(t,e.fallback));let i=m(t,{initialStatus:e.initialStatus??"pending"});return{node:i.node,status:i.status,error:i.error,breakerState:n}}export{O as a,R as b};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{a as O,b as H,c as j,d as E,e as W,f as ne}from"./chunk-
|
|
1
|
+
import{a as O,b as H,c as j,d as E,e as W,f as ne}from"./chunk-QP5TH523.js";import{a as N}from"./chunk-O32GJOUJ.js";import{a as X,j as T}from"./chunk-B4L5X2QO.js";import{D as I,E as y,G as L,o as S}from"./chunk-LYCLF26R.js";import{b as te}from"./chunk-QYADASLV.js";var ie={};te(ie,{CanvasMeasureAdapter:()=>$,CliMeasureAdapter:()=>D,ImageSizeAdapter:()=>J,NodeCanvasMeasureAdapter:()=>q,PrecomputedAdapter:()=>V,SvgBoundsAdapter:()=>z,analyzeAndMeasure:()=>O,carveTextLineSlots:()=>E,circleIntervalForBand:()=>Q,computeBlockFlow:()=>_,computeCharPositions:()=>W,computeFlowLines:()=>ee,computeLineBreaks:()=>H,computeTotalHeight:()=>U,layoutNextLine:()=>j,measureBlock:()=>Y,measureBlocks:()=>K,reactiveBlockLayout:()=>re,reactiveFlowLayout:()=>se,reactiveLayout:()=>ne,rectIntervalForBand:()=>Z});var D=class{cellPx;constructor(t){this.cellPx=t?.cellPx??8}measureSegment(t,n){return{width:X(t)*this.cellPx}}},G=class extends Error{name="KeyError"},V=class{metrics;fallback;constructor(t){this.metrics=t.metrics;let n=t.fallback??"per-char";if(n!=="per-char"&&n!=="error")throw new Error(`fallback must be 'per-char' or 'error', got ${JSON.stringify(t.fallback)}`);this.fallback=n}measureSegment(t,n){let i=this.metrics[n];if(i){let o=i[t];if(o!==void 0)return{width:o}}if(this.fallback==="error")throw new G(`PrecomputedAdapter: no metrics for segment ${JSON.stringify(t)} in font ${JSON.stringify(n)}`);let r=0;if(i)for(let o of t){let l=i[o];l!==void 0&&(r+=l)}return{width:r}}},$=class{ctx=null;currentFont="";emojiCorrection;constructor(t){this.emojiCorrection=t?.emojiCorrection??1}getContext(){if(!this.ctx){if(typeof OffscreenCanvas>"u")throw new Error("CanvasMeasureAdapter requires a browser environment with OffscreenCanvas support. Use CliMeasureAdapter or NodeCanvasMeasureAdapter for Node.js.");let n=new OffscreenCanvas(0,0).getContext("2d");if(!n)throw new Error("CanvasMeasureAdapter: failed to get 2d context");this.ctx=n}return this.ctx}measureSegment(t,n){let i=this.getContext();n!==this.currentFont&&(i.font=n,this.currentFont=n);let r=i.measureText(t).width;return this.emojiCorrection!==1&&new RegExp("\\p{Emoji_Presentation}","u").test(t)&&(r*=this.emojiCorrection),{width:r}}clearCache(){this.currentFont=""}},q=class{ctx=null;currentFont="";canvasModule;constructor(t){this.canvasModule=t}getContext(){if(!this.ctx){let n=this.canvasModule.createCanvas(0,0).getContext("2d");if(!n)throw new Error("NodeCanvasMeasureAdapter: failed to get 2d context");this.ctx=n}return this.ctx}measureSegment(t,n){let i=this.getContext();return n!==this.currentFont&&(i.font=n,this.currentFont=n),{width:i.measureText(t).width}}clearCache(){this.currentFont=""}},z=class{measureSvg(t){let n=t.match(/viewBox\s*=\s*["']([^"']+)["']/);if(n){let o=n[1].trim().split(/[\s,]+/);if(o.length>=4){let l=Number.parseFloat(o[2]),a=Number.parseFloat(o[3]);if(Number.isFinite(l)&&Number.isFinite(a)&&l>0&&a>0)return{width:l,height:a};throw new Error("SvgBoundsAdapter: viewBox width/height are missing, non-finite, or not positive")}}let i=t.match(/<svg[^>]*\bwidth\s*=\s*["']?([\d.]+)/),r=t.match(/<svg[^>]*\bheight\s*=\s*["']?([\d.]+)/);if(i&&r){let o=Number.parseFloat(i[1]),l=Number.parseFloat(r[1]);if(Number.isFinite(o)&&Number.isFinite(l)&&o>0&&l>0)return{width:o,height:l};throw new Error("SvgBoundsAdapter: svg width/height attributes are non-finite or not positive")}throw new Error("SvgBoundsAdapter: cannot determine dimensions \u2014 SVG has no viewBox or width/height attributes")}},J=class{sizes;constructor(t){this.sizes=new Map(Object.entries(t))}measureImage(t){let n=this.sizes.get(t);if(!n)throw new Error(`ImageSizeAdapter: no dimensions registered for ${JSON.stringify(t)}`);return{width:n.width,height:n.height}}};function Y(e,t,n,i,r,o,l){switch(e.type){case"text":{let a=e.font??r,m=e.lineHeight??o,d=O(e.text,a,n.text,i),w=H(d,t,n.text,a,i),v=W(w,d,m),B=w.lineCount*m,c=0;for(let x of w.lines)x.width>c&&(c=x.width);return{index:l,type:"text",width:Math.min(c,t),height:B,textSegments:d,textLineBreaks:w,textCharPositions:v}}case"image":{let a,m;if(e.naturalWidth!=null&&e.naturalHeight!=null)a=e.naturalWidth,m=e.naturalHeight;else if(n.image){let d=n.image.measureImage(e.src);a=d.width,m=d.height}else throw new Error(`Image block at index ${l} has no naturalWidth/naturalHeight and no ImageMeasurer adapter`);return a>t&&(m=m*t/a,a=t),{index:l,type:"image",width:a,height:m}}case"svg":{let a,m;if(e.viewBox)a=e.viewBox.width,m=e.viewBox.height;else if(n.svg){let d=n.svg.measureSvg(e.content);a=d.width,m=d.height}else throw new Error(`SVG block at index ${l} has no viewBox and no SvgMeasurer adapter`);return a>t&&(m=m*t/a,a=t),{index:l,type:"svg",width:a,height:m}}}}function K(e,t,n,i,r,o){return e.map((l,a)=>Y(l,t,n,i,r,o,a))}function _(e,t){let n=[],i=0;for(let r=0;r<e.length;r++){let o=e[r];n.push({...o,x:0,y:i}),i+=o.height+(r<e.length-1?t:0)}return n}function U(e){if(e.length===0)return 0;let t=e[e.length-1];return t.y+t.height}function re(e){let{adapters:t,name:n="reactive-block-layout",defaultFont:i="16px sans-serif",defaultLineHeight:r=20}=e,o=new T(n),l=new Map,a=y(e.blocks??[],{name:"blocks"}),m=y(Math.max(0,e.maxWidth??800),{name:"max-width"}),d=y(e.gap??0,{name:"gap"}),w=I([a,m],(c,x,s)=>{let p=c[0]!=null&&c[0].length>0?c[0].at(-1):s.prevData[0],h=c[1]!=null&&c[1].length>0?c[1].at(-1):s.prevData[1],g=S(),u=K(p,h,t,l,i,r),f=S()-g,b=w.meta;b&&(N(b["block-count"],u.length),N(b["layout-time-ns"],f)),x.emit(u);let C=()=>{l.clear(),t.text.clearCache?.()};return{deactivate:C,invalidate:C}},{name:"measured-blocks",describeKind:"derived",meta:{"block-count":0,"layout-time-ns":0},equals:(c,x)=>{let s=c,p=x;if(s==null||p==null)return s===p;if(s.length!==p.length)return!1;for(let h=0;h<s.length;h++){let g=s[h],u=p[h];if(g.type!==u.type||g.width!==u.width||g.height!==u.height||g.index!==u.index)return!1}return!0}}),v=L([w,d],([c,x])=>_(c,x),{name:"block-flow",equals:(c,x)=>{let s=c,p=x;if(s==null||p==null)return s===p;if(s.length!==p.length)return!1;for(let h=0;h<s.length;h++){let g=s[h],u=p[h];if(g.x!==u.x||g.y!==u.y||g.width!==u.width||g.height!==u.height)return!1}return!0}}),B=L([v],([c])=>U(c),{name:"total-height"});return o.add(a,{name:"blocks"}),o.add(m,{name:"max-width"}),o.add(d,{name:"gap"}),o.add(w,{name:"measured-blocks"}),o.add(v,{name:"block-flow"}),o.add(B,{name:"total-height"}),{graph:o,setBlocks:c=>o.set("blocks",c),setMaxWidth:c=>o.set("max-width",Math.max(0,c)),setGap:c=>o.set("gap",c),measuredBlocks:w,blockFlow:v,totalHeight:B}}function Q(e,t,n){let i=e.hPad??0,r=e.vPad??0,o=t-r,l=n+r;if(o>=e.cy+e.r||l<=e.cy-e.r)return null;let a=e.cy>=o&&e.cy<=l?0:e.cy<o?o-e.cy:e.cy-l;if(a>=e.r)return null;let m=Math.sqrt(e.r*e.r-a*a);return{left:e.cx-m-i,right:e.cx+m+i}}function Z(e,t,n){let i=e.hPad??0,r=e.vPad??0;return n<=e.y-r||t>=e.y+e.h+r?null:{left:e.x-i,right:e.x+e.w+i}}function oe(e,t,n){return e.kind==="circle"?Q(e,t,n):Z(e,t,n)}function ee(e,t,n,i,r,o,l){let a=l?.paragraphSpacing??r,m=[],d={segmentIndex:0,graphemeIndex:0};if(e.length===0||n.count<=0||r<=0)return{lines:m,cursor:d};let w=t.paddingX??0,v=t.paddingY??0,B=Math.max(0,t.width-w*2),c=Math.max(0,t.height-v*2),x=n.gap*Math.max(0,n.count-1),s=Math.max(0,(B-x)/n.count);if(s<=0)return{lines:m,cursor:d};e:for(let p=0;p<n.count;p++){let h=w+p*(s+n.gap),g=h+s,u=v;for(;u+r<=v+c;){let f=u+r,b=[];for(let k=0;k<i.length;k++){let M=oe(i[k],u,f);M!==null&&b.push(M)}let C=E({left:h,right:g},b,o);if(C.length===0){u+=r;continue}let P=!1;for(let k=0;k<C.length;k++){let M=C[k],R=M.right-M.left,F=j(e,d,R);if(F===null)return{lines:m,cursor:d};if(F.text.length===0&&F.width===0){d=F.end,P=!0;break}m.push({x:M.left,y:u,width:F.width,slotWidth:R,text:F.text,columnIndex:p,flushToRight:M.right<g-.5}),d=F.end}if(P){u+=a;continue}if(u+=r,d.segmentIndex>=e.length)break e}if(d.segmentIndex>=e.length)break}return{lines:m,cursor:d}}function se(e){let{adapter:t,name:n="reactive-flow-layout",minSlotWidth:i=20}=e,r=new T(n),o=new Map,l=y(e.text??"",{name:"text"}),a=y(e.font??"16px sans-serif",{name:"font"}),m=y(e.lineHeight??20,{name:"line-height"}),d=y(e.container??{width:800,height:600,paddingX:0,paddingY:0},{name:"container"}),w=y(e.columns??{count:1,gap:0},{name:"columns"}),v=y(e.obstacles??[],{name:"obstacles"}),B=y(e.paragraphSpacing??null,{name:"paragraph-spacing"}),c=I([l,a],(s,p,h)=>{let g=s[0],u=g!=null&&g.length>0?g.at(-1):h.prevData[0],f=s[1],b=f!=null&&f.length>0?f.at(-1):h.prevData[1],C=O(u,b,t,o);p.emit(C);let P=()=>{o.clear(),t.clearCache?.()};return{deactivate:P,invalidate:P}},{name:"segments",describeKind:"derived"}),x=L([c,d,w,v,m,B],([s,p,h,g,u,f])=>{let b=s,C=S(),P=f??u,{lines:k,cursor:M}=ee(b,p,h,g,u,i,{paragraphSpacing:P}),R=S()-C,F=Math.max(0,b.length-M.segmentIndex),A=x.meta;return A&&(N(A["line-count"],k.length),N(A["layout-time-ns"],R),N(A["overflow-segments"],F)),k},{name:"flow-lines",meta:{"line-count":0,"layout-time-ns":0,"overflow-segments":0},equals:(s,p)=>{let h=s,g=p;if(h.length!==g.length)return!1;for(let u=0;u<h.length;u++){let f=h[u],b=g[u];if(f.x!==b.x||f.y!==b.y||f.width!==b.width||f.slotWidth!==b.slotWidth||f.text!==b.text||f.columnIndex!==b.columnIndex||f.flushToRight!==b.flushToRight)return!1}return!0}});return r.add(l,{name:"text"}),r.add(a,{name:"font"}),r.add(m,{name:"line-height"}),r.add(d,{name:"container"}),r.add(w,{name:"columns"}),r.add(v,{name:"obstacles"}),r.add(B,{name:"paragraph-spacing"}),r.add(c,{name:"segments"}),r.add(x,{name:"flow-lines"}),{graph:r,setText:s=>r.set("text",s),setFont:s=>r.set("font",s),setLineHeight:s=>r.set("line-height",s),setContainer:s=>r.set("container",s),setColumns:s=>r.set("columns",s),setObstacles:s=>r.set("obstacles",s),setParagraphSpacing:s=>r.set("paragraph-spacing",s),segments:c,flowLines:x}}export{D as a,V as b,$ as c,q as d,z as e,J as f,Y as g,K as h,_ as i,U as j,re as k,Q as l,Z as m,ee as n,se as o,ie as p};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{j as A}from"./chunk-B4L5X2QO.js";import{b as x}from"./chunk-KUVDFOJH.js";import{E as l,m as T,p as f,t as p}from"./chunk-LYCLF26R.js";import{b as R,c as m}from"./chunk-CK2E7BTU.js";var M=p((r,e)=>{r("observe"),r("signal"),e("write")});function N(r){let e=x([],{name:r.name,maxSize:r.retainedLimit??1024,guard:r.guard??M,...r.versioning!=null?{versioning:r.versioning}:{}});return e.withLatest(),r.graph&&r.graph.add(e.entries,{name:r.name}),e}function b(r){if(r===null||typeof r!="object"||Object.isFrozen(r))return r;for(let e of Object.keys(r))b(r[e]);return Object.freeze(r)}function h(r){let e=r.cache,n=(typeof e=="number"&&Number.isFinite(e)?e:0)+1;return r.down([[m],[R,n]]),n}function y(r,e,o,n,a,s){let t=e(o,n,a);if(t===void 0)return;let u=s!=null?{...t,handlerVersion:s}:t;r.append(u)}function q(r,e){let o=e.freeze??!0;return function(...a){let s=o?a.map(b):a,t=f(),u,i,c=!1,g;try{T(()=>{e.seq&&(g=h(e.seq));try{u=r(...s),e.onSuccess&&y(e.audit,e.onSuccess,s,u,{t_ns:t,seq:g},e.handlerVersion)}catch(d){throw i=d,c=!0,d}})}catch(d){if(c&&e.onFailure){let w=i instanceof Error?i.name:typeof i;y(e.audit,e.onFailure,s,i,{t_ns:t,seq:g,errorType:w},e.handlerVersion)}throw c?i:d}return u}}function z(r,e,o=0){let n=l(o,{name:e,describeKind:"state"});return r.add(n,{name:e}),n}function G(r,e,o,n=0){let a={},s=new A(e);for(let t of o){let u=l(n,{name:t,describeKind:"state"});s.add(u,{name:t}),a[t]=u}return r.mount(e,s),a}export{N as a,q as b,z as c,G as d};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{e as P}from"./chunk-
|
|
1
|
+
import{e as P}from"./chunk-4EATTNAE.js";import{c as S}from"./chunk-O32GJOUJ.js";import{a as w}from"./chunk-QWVQIL3T.js";import{j as O,l as R}from"./chunk-B4L5X2QO.js";import{b as _}from"./chunk-TZQPPQEQ.js";import{C as T}from"./chunk-MQZWA3DF.js";import{E as k,G as x,o as H}from"./chunk-LYCLF26R.js";import{b as M}from"./chunk-QYADASLV.js";var B={};M(B,{LensGraph:()=>C,graphLens:()=>N,watchTopologyTree:()=>w});function v(e){return S("lens",e)}function E(e){let t=Object.keys(e.nodes),o=new Map,n=new Map;for(let s of t){let a=e.nodes[s]?.deps??[];o.set(s,a);for(let h of a)n.has(h)||n.set(h,new Set),n.get(h).add(s)}let r=[],c=[];for(let s of t)(o.get(s)??[]).length===0&&r.push(s),n.has(s)||c.push(s);r.sort(),c.sort();let p=e.edges.length,f=0,m=1,g=2,d=new Map;for(let s of t)d.set(s,f);let y=!1,l=new Map,u=s=>{let a=d.get(s)??f;if(a===m)return y=!0,0;if(a===g)return l.get(s)??0;d.set(s,m);let h=0,b=n.get(s);if(b!=null)for(let F of b){let G=u(F);G+1>h&&(h=G+1)}return d.set(s,g),l.set(s,h),h},i=0;for(let s of r){let a=u(s);a>i&&(i=a)}for(let s of t)d.get(s)===f&&u(s);return{nodeCount:t.length,edgeCount:p,subgraphCount:e.subgraphs.length,sources:r,sinks:c,depth:i,hasCycles:y}}function $(e){let t=[];for(let[o,n]of Object.entries(e.nodes)){if(n.status!=="errored")continue;let r={path:o,status:"errored"},c=R(e,o,"upstream",{});for(let p of c)if(p!==o&&e.nodes[p]?.status==="errored"){r.upstreamCause=p;break}t.push(r)}return t.sort((o,n)=>o.path<n.path?-1:o.path>n.path?1:0),{ok:t.length===0,problems:t}}function q(e,t){return e.nodeCount===t.nodeCount&&e.edgeCount===t.edgeCount&&e.subgraphCount===t.subgraphCount&&e.depth===t.depth&&e.hasCycles===t.hasCycles&&D(e.sources,t.sources)&&D(e.sinks,t.sinks)}function L(e,t){if(e.ok!==t.ok||e.problems.length!==t.problems.length)return!1;for(let o=0;o<e.problems.length;o++){let n=e.problems[o],r=t.problems[o];if(n.path!==r.path||n.status!==r.status||n.upstreamCause!==r.upstreamCause)return!1}return!0}function D(e,t){if(e.length!==t.length)return!1;for(let o=0;o<e.length;o++)if(e[o]!==t[o])return!1;return!0}var C=class extends O{stats;health;flow;_target;constructor(t,o={}){super(o.name??`${t.name}_lens`,o.graph),this._target=t;let n=0,r=0,c=k(0,{name:"stats_tick"}),p=k(0,{name:"health_tick"});this.add(c,{name:"stats_tick"}),this.add(p,{name:"health_tick"});let f={name:"flow"};o.maxFlowPaths!=null&&(f.maxSize=o.maxFlowPaths),this.flow=_(f),this.add(this.flow.entries,{name:"flow"});let m=o.pathFilter,g=w(t,(l,u,i)=>{if(n+=1,c.emit(n),r+=1,p.emit(r),l.kind==="removed")if(l.nodeKind==="node"){let s=`${i}${l.name}`;this.flow.delete(s)}else{let s=`${i}${l.name}::`,a=[];for(let h of l.audit.nodes){let b=h===""?`${i}${l.name}`:`${s}${h}`;a.push(b)}a.length>0&&this.flow.deleteMany(a)}});this.addDisposer(g);let d=t.observe({timeline:!0,structured:!0}),y=d.onEvent(l=>{let u=l.type;if((u==="error"||u==="complete"||u==="data"||u==="teardown")&&(r+=1,p.emit(r)),u==="data"){let i=l.path??"";if(!i||m!=null&&!m(i))return;let s=this.flow.get(i),a=s!=null?s.count+1:1;this.flow.set(i,{path:i,count:a,lastUpdate_ns:H()})}});this.addDisposer(()=>{y(),d.dispose()}),this.stats=x([c],()=>E(t.describe({detail:"minimal"})),{name:"stats",describeKind:"derived",equals:q,meta:v("stats")}),this.add(this.stats,{name:"stats"}),this.addDisposer(T(this.stats)),this.health=x([p],()=>$(t.describe({detail:"standard"})),{name:"health",describeKind:"derived",equals:L,meta:v("health")}),this.add(this.health,{name:"health"}),this.addDisposer(T(this.health))}why(t,o,n){let r=P(this._target,t,o,n);return this.addDisposer(r.dispose),r}get target(){return this._target}};function N(e,t){return new C(e,t)}export{C as a,N as b,B as c};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{a as Qr,b as Xr}from"./chunk-5RTZ6DXG.js";import{$ as Hr,A as hr,B as vr,C as xr,D as Tr,E as wr,F as Er,G as Nr,H as Mr,I as Sr,J as Rr,K as Wr,L as Or,M as Br,N as Ir,O as Lr,P as jr,Q as Cr,R as Vr,S as Pr,T as Ar,U as zr,V as Kr,W as Dr,X as Ur,Y as _r,Z as $r,_ as Fr,a as rn,aa as qr,b as tn,ba as nt,c as Jn,d as Qn,e as Xn,f as Yn,g as Zn,h as er,i as nr,j as rr,k as tr,l as or,m as sr,n as ir,o as ar,p as cr,q as dr,r as fr,s as ur,t as pr,u as lr,v as mr,w as gr,x as br,y as yr,z as kr}from"./chunk-MYFR67PY.js";import{a as Z,b as ee,c as ne,d as re,e as te,f as oe,g as se,h as ie,i as ae,j as ce,k as de}from"./chunk-A5HZZYRK.js";import{b as Yr,c as Zr,d as et,e as it,f as at}from"./chunk-Q7EUZ6NN.js";import{a as xt}from"./chunk-JUJEPZOI.js";import{a as rt,b as tt}from"./chunk-NNKJUORL.js";import{a as ot,b as st}from"./chunk-KGKJCHEK.js";import{a as Gr,b as Jr}from"./chunk-TZQPPQEQ.js";import{a as ge,b as Ye}from"./chunk-5QDBSZBV.js";import{a as Ze,b as en,c as nn}from"./chunk-KUVDFOJH.js";import{a as Y}from"./chunk-ESMPEKEV.js";import{a as ft,b as ut,c as pt,d as lt,e as mt,f as gt,g as bt,h as yt,i as kt,j as ht,k as vt}from"./chunk-D5RFJOZ2.js";import{a as ct,b as dt}from"./chunk-CE72X3WO.js";import{A as Sn,B as Rn,C as Wn,D as On,E as Bn,F as In,G as Ln,I as jn,J as Cn,K as Vn,L as Pn,M as An,N as zn,O as Kn,P as Dn,Q as Un,R as _n,S as $n,T as Fn,U as Hn,V as qn,W as Gn,a as U,b as J,c as on,d as sn,e as an,f as cn,g as dn,h as fn,i as Q,j as un,k as pn,l as ln,m as mn,n as gn,o as bn,p as yn,q as kn,r as hn,s as vn,t as X,u as xn,v as Tn,w as wn,x as En,y as Nn,z as Mn}from"./chunk-JJTF75VS.js";import{c as ke,d as he,e as ve,f as xe,g as Te,h as we,i as Ee}from"./chunk-4VVTGLXJ.js";import{A as Ge,B as Je,C as Qe,D as Xe,a as be,b as ye,c as Ne,d as Me,e as Se,f as G,g as Re,h as We,i as Oe,j as Be,k as Ie,l as Le,m as je,n as Ce,o as Ve,p as Pe,q as Ae,r as ze,s as Ke,t as De,u as Ue,v as _e,w as $e,x as Fe,y as He,z as qe}from"./chunk-MQZWA3DF.js";import{A as K,D as j,E as O,H as D,m as B}from"./chunk-LYCLF26R.js";import{b as h,e as $,f as F,g as H,h as S,i as q,j as W}from"./chunk-CK2E7BTU.js";import{b as me}from"./chunk-QYADASLV.js";var Rt={};me(Rt,{CircuitOpenError:()=>ee,ContentAddressedMissError:()=>Yr,NS_PER_MS:()=>NS_PER_MS,NS_PER_SEC:()=>NS_PER_SEC,NativeIndexBackend:()=>rt,NativeListBackend:()=>ot,NativeLogBackend:()=>Ze,NativeMapBackend:()=>Gr,NativePubSubBackend:()=>_,RateLimiterOverflowError:()=>oe,ResettableTimer:()=>Y,TimeoutError:()=>ae,appendLogStorage:()=>mt,audit:()=>Ln,awaitSettled:()=>qe,buffer:()=>jn,bufferCount:()=>Cn,bufferTime:()=>Pn,cached:()=>$e,canonicalJson:()=>Zr,cascadingCache:()=>Tt,catchError:()=>Gn,checkpointToRedis:()=>Dr,checkpointToS3:()=>Kr,circuitBreaker:()=>ne,combine:()=>hn,combineLatest:()=>Fn,concat:()=>Tn,concatMap:()=>Mn,constant:()=>ke,contentAddressedStorage:()=>et,createTransport:()=>L,createWatermarkController:()=>Ye,csvRows:()=>Tr,debounce:()=>On,debounceTime:()=>Hn,decorrelatedJitter:()=>Te,defer:()=>ze,delay:()=>Wn,deserializeError:()=>A,dictKv:()=>ht,dictSnapshot:()=>vt,distill:()=>Xr,distinctUntilChanged:()=>yn,elementAt:()=>ln,empty:()=>Ve,escapeRegexChar:()=>Ne,exhaustMap:()=>Nn,exponential:()=>ve,externalBundle:()=>tn,externalProducer:()=>rn,fallback:()=>ce,fibonacci:()=>xe,filter:()=>J,find:()=>pn,first:()=>Q,firstValueFrom:()=>Fe,firstWhere:()=>He,flatMap:()=>Rn,forEach:()=>Ke,fromAny:()=>je,fromAsyncIter:()=>Le,fromCSV:()=>xr,fromClickHouseWatch:()=>Nr,fromCron:()=>We,fromDrizzle:()=>Hr,fromEvent:()=>Oe,fromHTTP:()=>Yn,fromHTTPPoll:()=>ir,fromHTTPStream:()=>sr,fromIter:()=>Be,fromKafka:()=>yr,fromKysely:()=>qr,fromMCP:()=>dr,fromNATS:()=>Rr,fromNDJSON:()=>Er,fromOTel:()=>fr,fromPrisma:()=>Fr,fromPrometheus:()=>gr,fromPromise:()=>Ie,fromPulsar:()=>Mr,fromRabbitMQ:()=>Or,fromRaf:()=>Re,fromRedisStream:()=>hr,fromSSE:()=>or,fromSqlite:()=>Ur,fromSqliteCursor:()=>_r,fromStatsD:()=>lr,fromSyslog:()=>ur,fromTimer:()=>G,fromWebSocket:()=>Qn,fromWebSocketReconnect:()=>cr,fromWebhook:()=>Xn,globToRegExp:()=>Me,interval:()=>Kn,jsonCodec:()=>ft,jsonCodecFor:()=>ut,keepalive:()=>Qe,kvStorage:()=>gt,last:()=>un,linear:()=>he,lru:()=>fe,makeHttpError:()=>nt,map:()=>U,matchesAnyPattern:()=>Se,matchesCron:()=>ye,memoryAppendLog:()=>yt,memoryBackend:()=>pt,memoryKv:()=>kt,memorySnapshot:()=>bt,merge:()=>X,mergeMap:()=>Sn,mergeReactiveLogs:()=>nn,nameToSignal:()=>V,ndjsonRows:()=>wr,never:()=>Pe,nodeSignal:()=>Ge,of:()=>Ce,onFirstData:()=>gn,pairwise:()=>kn,parseCron:()=>be,parsePrometheusText:()=>br,parseSSEStream:()=>tr,parseStatsD:()=>mr,parseSyslog:()=>pr,pausable:()=>Un,pubsub:()=>wt,race:()=>wn,rateLimiter:()=>se,reactiveCounter:()=>Xe,reactiveIndex:()=>tt,reactiveList:()=>st,reactiveLog:()=>en,reactiveMap:()=>Jr,reactiveSink:()=>Jn,reduce:()=>sn,repeat:()=>Dn,replay:()=>_e,rescue:()=>_n,resolveBackoffPreset:()=>Ee,retry:()=>Z,sample:()=>In,scan:()=>on,serializeError:()=>P,share:()=>Ue,shareReplay:()=>Je,signalToName:()=>I,singleFromAny:()=>it,singleNodeFromAny:()=>at,skip:()=>cn,snapshotStorage:()=>lt,sortJsonValue:()=>ct,stableJsonString:()=>dt,stratify:()=>xt,switchMap:()=>En,take:()=>an,takeUntil:()=>fn,takeWhile:()=>dn,tap:()=>mn,tapFirst:()=>bn,throttle:()=>Bn,throttleTime:()=>qn,throwError:()=>Ae,timeout:()=>de,toArray:()=>De,toCSV:()=>Lr,toClickHouse:()=>jr,toFile:()=>Ir,toHTTP:()=>Zn,toKafka:()=>kr,toLoki:()=>Ar,toMongo:()=>Pr,toNATS:()=>Wr,toObservable:()=>ge,toPostgres:()=>Vr,toPulsar:()=>Sr,toRabbitMQ:()=>Br,toReadableStream:()=>rr,toRedisStream:()=>vr,toS3:()=>Cr,toSSE:()=>er,toSSEBytes:()=>nr,toSqlite:()=>$r,toTempo:()=>zr,toWebSocket:()=>ar,tokenBucket:()=>te,valve:()=>$n,verifiable:()=>Qr,window:()=>zn,windowCount:()=>Vn,windowTime:()=>An,withBreaker:()=>re,withLatestFrom:()=>vn,withMaxAttempts:()=>we,withStatus:()=>ie,workerBridge:()=>pe,workerSelf:()=>le,zip:()=>xn});function fe(){let e=new Map,t=null,n=null;function p(r){r.prev?r.prev.next=r.next:t=r.next,r.next?r.next.prev=r.prev:n=r.prev,r.prev=null,r.next=null}function l(r){r.next=t,r.prev=null,t&&(t.prev=r),t=r,n===null&&(n=r)}return{insert(r){if(e.has(r)){this.touch(r);return}let f={key:r,prev:null,next:null};e.set(r,f),l(f)},touch(r){let f=e.get(r);f&&(p(f),l(f))},delete(r){let f=e.get(r);f&&(p(f),e.delete(r))},evict(r){let f=[];for(let v=0;v<r&&n!==null;v++){let N=n;f.push(N.key),p(N),e.delete(N.key)}return f},size(){return e.size}}}function ue(e){return e!=null&&typeof e.then=="function"}function C(e){ue(e)&&e.catch(()=>{})}function Tt(e,t){let n=new Map,p=t?.maxSize??0,l=p>0?t?.eviction??fe():null,r=t?.writeThrough??!1;function f(o,u,m){for(let g=0;g<m;g++)try{C(e[g].save(o,u))}catch{}}function v(o,u,m=0){for(let g=m;g<e.length;g++){let w;try{w=e[g].load(o)}catch{continue}if(ue(w)){let T=g;w.then(M=>{M!==void 0?(u.down([[h,M]]),f(o,M,T)):v(o,u,T+1)},()=>{v(o,u,T+1)});return}if(w!==void 0){u.down([[h,w]]),f(o,w,g);return}}}function N(){if(!(!l||p<=0))for(;l.size()>=p;){let o=l.evict(1);if(o.length===0)break;for(let u of o){let m=n.get(u);if(m){let g=m.cache;if(m.status!=="sentinel"&&e.length>0){let w=e.length-1;try{C(e[w].save(u,g))}catch{}for(let T=0;T<w;T++)try{let M=e[T].delete;M&&C(M.call(e[T],u))}catch{}}m.down([[S]])}n.delete(u)}}}return{load(o){let u=n.get(o);if(u)return l?.touch(o),u;l&&p>0&&l.size()>=p&&N();let m=O(void 0);return n.set(o,m),l?.insert(o),v(o,m),m},save(o,u){if(r)for(let g of e)try{C(g.save(o,u))}catch{}else if(e[0])try{C(e[0].save(o,u))}catch{}let m=n.get(o);if(m)m.down([[h,u]]),l?.touch(o);else{l&&p>0&&l.size()>=p&&N();let g=O(u);n.set(o,g),l?.insert(o)}},invalidate(o){let u=n.get(o);u&&v(o,u)},delete(o){l?.delete(o);let u=n.get(o);u&&u.down([[S]]),n.delete(o);for(let m of e)try{let g=m.delete;g&&C(g.call(m,o))}catch{}},has(o){return n.has(o)},get size(){return n.size}}}var _=class{_version=0;_topics=new Set;get version(){return this._version}get topicCount(){return this._topics.size}hasTopic(t){return this._topics.has(t)}topicNames(){return this._topics.values()}createTopic(t){return this._topics.has(t)?!1:(this._topics.add(t),this._version+=1,!0)}removeTopic(t){let n=this._topics.delete(t);return n&&(this._version+=1),n}};function wt(e={}){let{backend:t}=e,n=t??new _,p=new Map;function l(r){let f=p.get(r);return f===void 0&&(f=j({describeKind:"state"}),p.set(r,f),n.createTopic(r)),f}return{topic(r){return l(r)},publish(r,f){l(r).emit(f)},publishMany(r){B(()=>{for(let[f,v]of r)l(f).emit(v)})},removeTopic(r){let f=p.get(r);return f===void 0?!1:(p.delete(r),n.removeTopic(r),f.down([[S]]),!0)},has(r){return n.hasTopic(r)},get size(){return n.topicCount},topicNames(){return n.topicNames()}}}var Et=new Map([[$,"INVALIDATE"],[F,"PAUSE"],[H,"RESUME"],[S,"TEARDOWN"],[q,"COMPLETE"],[W,"ERROR"]]),Nt=new Map([["INVALIDATE",$],["PAUSE",F],["RESUME",H],["TEARDOWN",S],["COMPLETE",q],["ERROR",W]]);function I(e){let t=Et.get(e);return t||(Symbol.keyFor(e)??"UNKNOWN")}function V(e){let t=Nt.get(e);if(t)return t;if(e&&e!=="UNKNOWN")return Symbol.for(e)}function P(e){return e instanceof Error?{message:e.message,name:e.name,stack:e.stack}:{message:String(e),name:"Error"}}function A(e){let t=new Error(e.message);return t.name=e.name,e.stack&&(t.stack=e.stack),t}function L(e){if(typeof MessagePort<"u"&&e instanceof MessagePort)return{post(t,n){e.postMessage(t,n??[])},listen(t){let n=p=>t(p.data);return e.addEventListener("message",n),e.start(),()=>e.removeEventListener("message",n)},terminate(){e.close()}};if(typeof SharedWorker<"u"&&e instanceof SharedWorker)return L(e.port);if(typeof Worker<"u"&&e instanceof Worker)return{post(t,n){e.postMessage(t,n??[])},listen(t){let n=p=>t(p.data);return e.addEventListener("message",n),()=>e.removeEventListener("message",n)},terminate(){e.terminate()}};if(typeof BroadcastChannel<"u"&&e instanceof BroadcastChannel)return{post(t,n){n&&n.length>0&&console.warn("[graphrefly] WorkerTransport: BroadcastChannel does not support Transferable objects. The transfer argument is ignored and objects will be cloned instead."),e.postMessage(t)},listen(t){let n=p=>t(p.data);return e.addEventListener("message",n),()=>e.removeEventListener("message",n)},terminate(){e.close()}};if(typeof ServiceWorker<"u"&&e instanceof ServiceWorker)return{post(t,n){e.postMessage(t,n??[])},listen(t){let n=p=>{p.source===e&&t(p.data)};return navigator.serviceWorker.addEventListener("message",n),()=>navigator.serviceWorker.removeEventListener("message",n)}};throw new Error("createTransport: unsupported target type. Expected Worker, SharedWorker, ServiceWorker, BroadcastChannel, or MessagePort.")}function Mt(e){return typeof e=="object"&&e!==null&&typeof e.post=="function"&&typeof e.listen=="function"}function pe(e,t){let n=Mt(e)?e:L(e),p=t.name??"workerBridge",l=Object.entries(t.expose??{}),r=t.import??[],f=t.transfer??{},v=O("connecting",{name:`${p}::meta::status`}),N=O(null,{name:`${p}::meta::error`}),o=new Map,u=new Map;for(let c of r){let a=O(void 0,{name:`${p}::${c}`});o.set(c,a)}let m;if(l.length>0){let c=l.map(([,d])=>d),a=j(c,(d,i)=>{let k={};for(let y=0;y<l.length;y++){let[R]=l[y],E=d[y];E!=null&&E.length>0&&(k[R]=E.at(-1))}Object.keys(k).length!==0&&i.emit(k)},{name:`${p}::aggregated`,partial:!0});m=D([a],d=>{let i=d[0];if(i==null||Object.keys(i).length===0)return;let k=[];for(let E of Object.keys(i)){let z=f[E];z&&k.push(...z(i[E]))}let y;for(let[E,z]of l)E in i&&z.v!=null&&(y==null&&(y={}),y[E]=z.v.version);let R={t:"b",u:i,...y?{v:y}:{}};try{n.post(R,k.length>0?k:void 0)}catch(E){N.down([[h,E instanceof Error?E:new Error(String(E))]])}}).subscribe(()=>{})}let g=!1,w=n.listen(c=>{if(g)return;let a=c;switch(a.t){case"r":{B(()=>{for(let[d,i]of Object.entries(a.stores)){let k=o.get(d);k&&k.down([[h,i]])}}),v.down([[h,"connected"]]);let s={};for(let[d,i]of l)s[d]=i.cache;n.post({t:"i",stores:s});break}case"v":{let s=o.get(a.s);s&&s.down([[h,a.d]]);break}case"b":{B(()=>{for(let[s,d]of Object.entries(a.u)){let i=a.v?.[s];if(i!=null){let y=u.get(s);if(y!=null&&i<=y)continue;u.set(s,i)}let k=o.get(s);k&&k.down([[h,d]])}});break}case"e":{let s=o.get(a.s);s&&s.down([[W,A(a.err)]]);break}case"s":{let s=V(a.sig);if(!s)break;let d=a.s==="*"?[...o.values()]:o.has(a.s)?[o.get(a.s)]:[];for(let i of d)i.down(a.d===void 0?[[s]]:[[s,a.d]]);break}}}),T=[];for(let[c,a]of l){let s=a.subscribe((d=>{if(!g)for(let i of d){let k=i[0];k!==h&&(K.isLocalOnly(k)||(k===W?n.post({t:"e",s:c,err:P(i[1])}):n.post({t:"s",s:c,sig:I(k),d:i.length>1?i[1]:void 0})))}}));T.push(s)}let M;if(t.timeoutMs!=null&&t.timeoutMs>0){let c=G(t.timeoutMs),a=J(v,d=>d==="connected");M=Q(X(U(c,()=>"timeout"),U(a,()=>"ready"))).subscribe(d=>{for(let i of d)i[0]===h&&i[1]==="timeout"&&(N.down([[h,new Error("Worker bridge handshake timeout")]]),x())})}function x(){if(!g){g=!0,M?.(),n.post({t:"s",s:"*",sig:I(S)}),m&&m();for(let c of T)c();T.length=0,w(),v.down([[h,"closed"]]),u.clear(),o.clear()}}let b={meta:{status:v,error:N},destroy:x};for(let[c,a]of o)b[c]=a;return b}function St(e){return typeof e=="object"&&e!==null&&typeof e.post=="function"&&typeof e.listen=="function"}function le(e,t){let n=St(e)?e:L(e),p=t.import??[],l=t.transfer??{},r=new Map,f=new Map,v={};for(let x of p){let b=O(void 0,{name:`worker::${x}`});r.set(x,b),v[x]=b}let N=t.expose(v),o=Object.entries(N),u,m=!1;if(o.length>0){let x=o.map(([,a])=>a),b=j(x,(a,s)=>{let d={};for(let i=0;i<o.length;i++){let[k]=o[i],y=a[i];y!=null&&y.length>0&&(d[k]=y.at(-1))}Object.keys(d).length!==0&&s.emit(d)},{name:"workerSelf::aggregated",partial:!0});u=D([b],a=>{if(m)return;let s=a[0];if(s==null||Object.keys(s).length===0)return;let d=[];for(let y of Object.keys(s)){let R=l[y];R&&d.push(...R(s[y]))}let i;for(let[y,R]of o)y in s&&R.v!=null&&(i==null&&(i={}),i[y]=R.v.version);let k={t:"b",u:s,...i?{v:i}:{}};try{n.post(k,d.length>0?d:void 0)}catch{}}).subscribe(()=>{})}let g=[];for(let[x,b]of o){let c=b.subscribe((a=>{if(!m)for(let s of a){let d=s[0];d!==h&&(K.isLocalOnly(d)||(d===W?n.post({t:"e",s:x,err:P(s[1])}):n.post({t:"s",s:x,sig:I(d),d:s.length>1?s[1]:void 0})))}}));g.push(c)}let w=n.listen(x=>{if(m)return;let b=x;switch(b.t){case"i":{B(()=>{for(let[c,a]of Object.entries(b.stores)){let s=r.get(c);s&&s.down([[h,a]])}});break}case"v":{let c=r.get(b.s);c&&c.down([[h,b.d]]);break}case"b":{B(()=>{for(let[c,a]of Object.entries(b.u)){let s=b.v?.[c];if(s!=null){let i=f.get(c);if(i!=null&&s<=i)continue;f.set(c,s)}let d=r.get(c);d&&d.down([[h,a]])}});break}case"e":{let c=r.get(b.s);c&&c.down([[W,A(b.err)]]);break}case"s":{let c=V(b.sig);if(!c)break;if(c===S&&b.s==="*"){M();return}let a=b.s==="*"?[...r.values()]:r.has(b.s)?[r.get(b.s)]:[];for(let s of a)s.down(b.d===void 0?[[c]]:[[c,b.d]]);break}}}),T={};for(let[x,b]of o)T[x]=b.cache;n.post({t:"r",stores:T});function M(){if(!m){m=!0,u&&u();for(let x of g)x();g.length=0,w(),n.terminate?.(),f.clear(),r.clear()}}return{destroy:M}}export{fe as a,Tt as b,_ as c,wt as d,I as e,V as f,P as g,A as h,L as i,pe as j,le as k,Rt as l};
|
|
1
|
+
import{a as Qr,b as Xr}from"./chunk-6SVKZ7VI.js";import{$ as Hr,A as hr,B as vr,C as xr,D as Tr,E as wr,F as Er,G as Nr,H as Mr,I as Sr,J as Rr,K as Wr,L as Or,M as Br,N as Ir,O as Lr,P as jr,Q as Cr,R as Vr,S as Pr,T as Ar,U as zr,V as Kr,W as Dr,X as Ur,Y as _r,Z as $r,_ as Fr,a as rn,aa as qr,b as tn,ba as nt,c as Jn,d as Qn,e as Xn,f as Yn,g as Zn,h as er,i as nr,j as rr,k as tr,l as or,m as sr,n as ir,o as ar,p as cr,q as dr,r as fr,s as ur,t as pr,u as lr,v as mr,w as gr,x as br,y as yr,z as kr}from"./chunk-MYFR67PY.js";import{a as Z,b as ee,c as ne,d as re,e as te,f as oe,g as se,h as ie,i as ae,j as ce,k as de}from"./chunk-A5HZZYRK.js";import{b as Yr,c as Zr,d as et,e as it,f as at}from"./chunk-Q7EUZ6NN.js";import{a as xt}from"./chunk-YVYSO5CW.js";import{a as ge,b as Ye}from"./chunk-5QDBSZBV.js";import{a as Y}from"./chunk-ESMPEKEV.js";import{a as ft,b as ut,c as pt,d as lt,e as mt,f as gt,g as bt,h as yt,i as kt,j as ht,k as vt}from"./chunk-D5RFJOZ2.js";import{a as ct,b as dt}from"./chunk-CE72X3WO.js";import{A as Sn,B as Rn,C as Wn,D as On,E as Bn,F as In,G as Ln,I as jn,J as Cn,K as Vn,L as Pn,M as An,N as zn,O as Kn,P as Dn,Q as Un,R as _n,S as $n,T as Fn,U as Hn,V as qn,W as Gn,a as U,b as J,c as on,d as sn,e as an,f as cn,g as dn,h as fn,i as Q,j as un,k as pn,l as ln,m as mn,n as gn,o as bn,p as yn,q as kn,r as hn,s as vn,t as X,u as xn,v as Tn,w as wn,x as En,y as Nn,z as Mn}from"./chunk-JJTF75VS.js";import{c as ke,d as he,e as ve,f as xe,g as Te,h as we,i as Ee}from"./chunk-4VVTGLXJ.js";import{a as rt,b as tt}from"./chunk-NNKJUORL.js";import{a as ot,b as st}from"./chunk-KGKJCHEK.js";import{a as Gr,b as Jr}from"./chunk-TZQPPQEQ.js";import{a as Ze,b as en,c as nn}from"./chunk-KUVDFOJH.js";import{A as Ge,B as Je,C as Qe,D as Xe,a as be,b as ye,c as Ne,d as Me,e as Se,f as G,g as Re,h as We,i as Oe,j as Be,k as Ie,l as Le,m as je,n as Ce,o as Ve,p as Pe,q as Ae,r as ze,s as Ke,t as De,u as Ue,v as _e,w as $e,x as Fe,y as He,z as qe}from"./chunk-MQZWA3DF.js";import{A as K,D as j,E as O,H as D,m as B}from"./chunk-LYCLF26R.js";import{b as h,e as $,f as F,g as H,h as S,i as q,j as W}from"./chunk-CK2E7BTU.js";import{b as me}from"./chunk-QYADASLV.js";var Rt={};me(Rt,{CircuitOpenError:()=>ee,ContentAddressedMissError:()=>Yr,NS_PER_MS:()=>NS_PER_MS,NS_PER_SEC:()=>NS_PER_SEC,NativeIndexBackend:()=>rt,NativeListBackend:()=>ot,NativeLogBackend:()=>Ze,NativeMapBackend:()=>Gr,NativePubSubBackend:()=>_,RateLimiterOverflowError:()=>oe,ResettableTimer:()=>Y,TimeoutError:()=>ae,appendLogStorage:()=>mt,audit:()=>Ln,awaitSettled:()=>qe,buffer:()=>jn,bufferCount:()=>Cn,bufferTime:()=>Pn,cached:()=>$e,canonicalJson:()=>Zr,cascadingCache:()=>Tt,catchError:()=>Gn,checkpointToRedis:()=>Dr,checkpointToS3:()=>Kr,circuitBreaker:()=>ne,combine:()=>hn,combineLatest:()=>Fn,concat:()=>Tn,concatMap:()=>Mn,constant:()=>ke,contentAddressedStorage:()=>et,createTransport:()=>L,createWatermarkController:()=>Ye,csvRows:()=>Tr,debounce:()=>On,debounceTime:()=>Hn,decorrelatedJitter:()=>Te,defer:()=>ze,delay:()=>Wn,deserializeError:()=>A,dictKv:()=>ht,dictSnapshot:()=>vt,distill:()=>Xr,distinctUntilChanged:()=>yn,elementAt:()=>ln,empty:()=>Ve,escapeRegexChar:()=>Ne,exhaustMap:()=>Nn,exponential:()=>ve,externalBundle:()=>tn,externalProducer:()=>rn,fallback:()=>ce,fibonacci:()=>xe,filter:()=>J,find:()=>pn,first:()=>Q,firstValueFrom:()=>Fe,firstWhere:()=>He,flatMap:()=>Rn,forEach:()=>Ke,fromAny:()=>je,fromAsyncIter:()=>Le,fromCSV:()=>xr,fromClickHouseWatch:()=>Nr,fromCron:()=>We,fromDrizzle:()=>Hr,fromEvent:()=>Oe,fromHTTP:()=>Yn,fromHTTPPoll:()=>ir,fromHTTPStream:()=>sr,fromIter:()=>Be,fromKafka:()=>yr,fromKysely:()=>qr,fromMCP:()=>dr,fromNATS:()=>Rr,fromNDJSON:()=>Er,fromOTel:()=>fr,fromPrisma:()=>Fr,fromPrometheus:()=>gr,fromPromise:()=>Ie,fromPulsar:()=>Mr,fromRabbitMQ:()=>Or,fromRaf:()=>Re,fromRedisStream:()=>hr,fromSSE:()=>or,fromSqlite:()=>Ur,fromSqliteCursor:()=>_r,fromStatsD:()=>lr,fromSyslog:()=>ur,fromTimer:()=>G,fromWebSocket:()=>Qn,fromWebSocketReconnect:()=>cr,fromWebhook:()=>Xn,globToRegExp:()=>Me,interval:()=>Kn,jsonCodec:()=>ft,jsonCodecFor:()=>ut,keepalive:()=>Qe,kvStorage:()=>gt,last:()=>un,linear:()=>he,lru:()=>fe,makeHttpError:()=>nt,map:()=>U,matchesAnyPattern:()=>Se,matchesCron:()=>ye,memoryAppendLog:()=>yt,memoryBackend:()=>pt,memoryKv:()=>kt,memorySnapshot:()=>bt,merge:()=>X,mergeMap:()=>Sn,mergeReactiveLogs:()=>nn,nameToSignal:()=>V,ndjsonRows:()=>wr,never:()=>Pe,nodeSignal:()=>Ge,of:()=>Ce,onFirstData:()=>gn,pairwise:()=>kn,parseCron:()=>be,parsePrometheusText:()=>br,parseSSEStream:()=>tr,parseStatsD:()=>mr,parseSyslog:()=>pr,pausable:()=>Un,pubsub:()=>wt,race:()=>wn,rateLimiter:()=>se,reactiveCounter:()=>Xe,reactiveIndex:()=>tt,reactiveList:()=>st,reactiveLog:()=>en,reactiveMap:()=>Jr,reactiveSink:()=>Jn,reduce:()=>sn,repeat:()=>Dn,replay:()=>_e,rescue:()=>_n,resolveBackoffPreset:()=>Ee,retry:()=>Z,sample:()=>In,scan:()=>on,serializeError:()=>P,share:()=>Ue,shareReplay:()=>Je,signalToName:()=>I,singleFromAny:()=>it,singleNodeFromAny:()=>at,skip:()=>cn,snapshotStorage:()=>lt,sortJsonValue:()=>ct,stableJsonString:()=>dt,stratify:()=>xt,switchMap:()=>En,take:()=>an,takeUntil:()=>fn,takeWhile:()=>dn,tap:()=>mn,tapFirst:()=>bn,throttle:()=>Bn,throttleTime:()=>qn,throwError:()=>Ae,timeout:()=>de,toArray:()=>De,toCSV:()=>Lr,toClickHouse:()=>jr,toFile:()=>Ir,toHTTP:()=>Zn,toKafka:()=>kr,toLoki:()=>Ar,toMongo:()=>Pr,toNATS:()=>Wr,toObservable:()=>ge,toPostgres:()=>Vr,toPulsar:()=>Sr,toRabbitMQ:()=>Br,toReadableStream:()=>rr,toRedisStream:()=>vr,toS3:()=>Cr,toSSE:()=>er,toSSEBytes:()=>nr,toSqlite:()=>$r,toTempo:()=>zr,toWebSocket:()=>ar,tokenBucket:()=>te,valve:()=>$n,verifiable:()=>Qr,window:()=>zn,windowCount:()=>Vn,windowTime:()=>An,withBreaker:()=>re,withLatestFrom:()=>vn,withMaxAttempts:()=>we,withStatus:()=>ie,workerBridge:()=>pe,workerSelf:()=>le,zip:()=>xn});function fe(){let e=new Map,t=null,n=null;function p(r){r.prev?r.prev.next=r.next:t=r.next,r.next?r.next.prev=r.prev:n=r.prev,r.prev=null,r.next=null}function l(r){r.next=t,r.prev=null,t&&(t.prev=r),t=r,n===null&&(n=r)}return{insert(r){if(e.has(r)){this.touch(r);return}let f={key:r,prev:null,next:null};e.set(r,f),l(f)},touch(r){let f=e.get(r);f&&(p(f),l(f))},delete(r){let f=e.get(r);f&&(p(f),e.delete(r))},evict(r){let f=[];for(let v=0;v<r&&n!==null;v++){let N=n;f.push(N.key),p(N),e.delete(N.key)}return f},size(){return e.size}}}function ue(e){return e!=null&&typeof e.then=="function"}function C(e){ue(e)&&e.catch(()=>{})}function Tt(e,t){let n=new Map,p=t?.maxSize??0,l=p>0?t?.eviction??fe():null,r=t?.writeThrough??!1;function f(o,u,m){for(let g=0;g<m;g++)try{C(e[g].save(o,u))}catch{}}function v(o,u,m=0){for(let g=m;g<e.length;g++){let w;try{w=e[g].load(o)}catch{continue}if(ue(w)){let T=g;w.then(M=>{M!==void 0?(u.down([[h,M]]),f(o,M,T)):v(o,u,T+1)},()=>{v(o,u,T+1)});return}if(w!==void 0){u.down([[h,w]]),f(o,w,g);return}}}function N(){if(!(!l||p<=0))for(;l.size()>=p;){let o=l.evict(1);if(o.length===0)break;for(let u of o){let m=n.get(u);if(m){let g=m.cache;if(m.status!=="sentinel"&&e.length>0){let w=e.length-1;try{C(e[w].save(u,g))}catch{}for(let T=0;T<w;T++)try{let M=e[T].delete;M&&C(M.call(e[T],u))}catch{}}m.down([[S]])}n.delete(u)}}}return{load(o){let u=n.get(o);if(u)return l?.touch(o),u;l&&p>0&&l.size()>=p&&N();let m=O(void 0);return n.set(o,m),l?.insert(o),v(o,m),m},save(o,u){if(r)for(let g of e)try{C(g.save(o,u))}catch{}else if(e[0])try{C(e[0].save(o,u))}catch{}let m=n.get(o);if(m)m.down([[h,u]]),l?.touch(o);else{l&&p>0&&l.size()>=p&&N();let g=O(u);n.set(o,g),l?.insert(o)}},invalidate(o){let u=n.get(o);u&&v(o,u)},delete(o){l?.delete(o);let u=n.get(o);u&&u.down([[S]]),n.delete(o);for(let m of e)try{let g=m.delete;g&&C(g.call(m,o))}catch{}},has(o){return n.has(o)},get size(){return n.size}}}var _=class{_version=0;_topics=new Set;get version(){return this._version}get topicCount(){return this._topics.size}hasTopic(t){return this._topics.has(t)}topicNames(){return this._topics.values()}createTopic(t){return this._topics.has(t)?!1:(this._topics.add(t),this._version+=1,!0)}removeTopic(t){let n=this._topics.delete(t);return n&&(this._version+=1),n}};function wt(e={}){let{backend:t}=e,n=t??new _,p=new Map;function l(r){let f=p.get(r);return f===void 0&&(f=j({describeKind:"state"}),p.set(r,f),n.createTopic(r)),f}return{topic(r){return l(r)},publish(r,f){l(r).emit(f)},publishMany(r){B(()=>{for(let[f,v]of r)l(f).emit(v)})},removeTopic(r){let f=p.get(r);return f===void 0?!1:(p.delete(r),n.removeTopic(r),f.down([[S]]),!0)},has(r){return n.hasTopic(r)},get size(){return n.topicCount},topicNames(){return n.topicNames()}}}var Et=new Map([[$,"INVALIDATE"],[F,"PAUSE"],[H,"RESUME"],[S,"TEARDOWN"],[q,"COMPLETE"],[W,"ERROR"]]),Nt=new Map([["INVALIDATE",$],["PAUSE",F],["RESUME",H],["TEARDOWN",S],["COMPLETE",q],["ERROR",W]]);function I(e){let t=Et.get(e);return t||(Symbol.keyFor(e)??"UNKNOWN")}function V(e){let t=Nt.get(e);if(t)return t;if(e&&e!=="UNKNOWN")return Symbol.for(e)}function P(e){return e instanceof Error?{message:e.message,name:e.name,stack:e.stack}:{message:String(e),name:"Error"}}function A(e){let t=new Error(e.message);return t.name=e.name,e.stack&&(t.stack=e.stack),t}function L(e){if(typeof MessagePort<"u"&&e instanceof MessagePort)return{post(t,n){e.postMessage(t,n??[])},listen(t){let n=p=>t(p.data);return e.addEventListener("message",n),e.start(),()=>e.removeEventListener("message",n)},terminate(){e.close()}};if(typeof SharedWorker<"u"&&e instanceof SharedWorker)return L(e.port);if(typeof Worker<"u"&&e instanceof Worker)return{post(t,n){e.postMessage(t,n??[])},listen(t){let n=p=>t(p.data);return e.addEventListener("message",n),()=>e.removeEventListener("message",n)},terminate(){e.terminate()}};if(typeof BroadcastChannel<"u"&&e instanceof BroadcastChannel)return{post(t,n){n&&n.length>0&&console.warn("[graphrefly] WorkerTransport: BroadcastChannel does not support Transferable objects. The transfer argument is ignored and objects will be cloned instead."),e.postMessage(t)},listen(t){let n=p=>t(p.data);return e.addEventListener("message",n),()=>e.removeEventListener("message",n)},terminate(){e.close()}};if(typeof ServiceWorker<"u"&&e instanceof ServiceWorker)return{post(t,n){e.postMessage(t,n??[])},listen(t){let n=p=>{p.source===e&&t(p.data)};return navigator.serviceWorker.addEventListener("message",n),()=>navigator.serviceWorker.removeEventListener("message",n)}};throw new Error("createTransport: unsupported target type. Expected Worker, SharedWorker, ServiceWorker, BroadcastChannel, or MessagePort.")}function Mt(e){return typeof e=="object"&&e!==null&&typeof e.post=="function"&&typeof e.listen=="function"}function pe(e,t){let n=Mt(e)?e:L(e),p=t.name??"workerBridge",l=Object.entries(t.expose??{}),r=t.import??[],f=t.transfer??{},v=O("connecting",{name:`${p}::meta::status`}),N=O(null,{name:`${p}::meta::error`}),o=new Map,u=new Map;for(let c of r){let a=O(void 0,{name:`${p}::${c}`});o.set(c,a)}let m;if(l.length>0){let c=l.map(([,d])=>d),a=j(c,(d,i)=>{let k={};for(let y=0;y<l.length;y++){let[R]=l[y],E=d[y];E!=null&&E.length>0&&(k[R]=E.at(-1))}Object.keys(k).length!==0&&i.emit(k)},{name:`${p}::aggregated`,partial:!0});m=D([a],d=>{let i=d[0];if(i==null||Object.keys(i).length===0)return;let k=[];for(let E of Object.keys(i)){let z=f[E];z&&k.push(...z(i[E]))}let y;for(let[E,z]of l)E in i&&z.v!=null&&(y==null&&(y={}),y[E]=z.v.version);let R={t:"b",u:i,...y?{v:y}:{}};try{n.post(R,k.length>0?k:void 0)}catch(E){N.down([[h,E instanceof Error?E:new Error(String(E))]])}}).subscribe(()=>{})}let g=!1,w=n.listen(c=>{if(g)return;let a=c;switch(a.t){case"r":{B(()=>{for(let[d,i]of Object.entries(a.stores)){let k=o.get(d);k&&k.down([[h,i]])}}),v.down([[h,"connected"]]);let s={};for(let[d,i]of l)s[d]=i.cache;n.post({t:"i",stores:s});break}case"v":{let s=o.get(a.s);s&&s.down([[h,a.d]]);break}case"b":{B(()=>{for(let[s,d]of Object.entries(a.u)){let i=a.v?.[s];if(i!=null){let y=u.get(s);if(y!=null&&i<=y)continue;u.set(s,i)}let k=o.get(s);k&&k.down([[h,d]])}});break}case"e":{let s=o.get(a.s);s&&s.down([[W,A(a.err)]]);break}case"s":{let s=V(a.sig);if(!s)break;let d=a.s==="*"?[...o.values()]:o.has(a.s)?[o.get(a.s)]:[];for(let i of d)i.down(a.d===void 0?[[s]]:[[s,a.d]]);break}}}),T=[];for(let[c,a]of l){let s=a.subscribe((d=>{if(!g)for(let i of d){let k=i[0];k!==h&&(K.isLocalOnly(k)||(k===W?n.post({t:"e",s:c,err:P(i[1])}):n.post({t:"s",s:c,sig:I(k),d:i.length>1?i[1]:void 0})))}}));T.push(s)}let M;if(t.timeoutMs!=null&&t.timeoutMs>0){let c=G(t.timeoutMs),a=J(v,d=>d==="connected");M=Q(X(U(c,()=>"timeout"),U(a,()=>"ready"))).subscribe(d=>{for(let i of d)i[0]===h&&i[1]==="timeout"&&(N.down([[h,new Error("Worker bridge handshake timeout")]]),x())})}function x(){if(!g){g=!0,M?.(),n.post({t:"s",s:"*",sig:I(S)}),m&&m();for(let c of T)c();T.length=0,w(),v.down([[h,"closed"]]),u.clear(),o.clear()}}let b={meta:{status:v,error:N},destroy:x};for(let[c,a]of o)b[c]=a;return b}function St(e){return typeof e=="object"&&e!==null&&typeof e.post=="function"&&typeof e.listen=="function"}function le(e,t){let n=St(e)?e:L(e),p=t.import??[],l=t.transfer??{},r=new Map,f=new Map,v={};for(let x of p){let b=O(void 0,{name:`worker::${x}`});r.set(x,b),v[x]=b}let N=t.expose(v),o=Object.entries(N),u,m=!1;if(o.length>0){let x=o.map(([,a])=>a),b=j(x,(a,s)=>{let d={};for(let i=0;i<o.length;i++){let[k]=o[i],y=a[i];y!=null&&y.length>0&&(d[k]=y.at(-1))}Object.keys(d).length!==0&&s.emit(d)},{name:"workerSelf::aggregated",partial:!0});u=D([b],a=>{if(m)return;let s=a[0];if(s==null||Object.keys(s).length===0)return;let d=[];for(let y of Object.keys(s)){let R=l[y];R&&d.push(...R(s[y]))}let i;for(let[y,R]of o)y in s&&R.v!=null&&(i==null&&(i={}),i[y]=R.v.version);let k={t:"b",u:s,...i?{v:i}:{}};try{n.post(k,d.length>0?d:void 0)}catch{}}).subscribe(()=>{})}let g=[];for(let[x,b]of o){let c=b.subscribe((a=>{if(!m)for(let s of a){let d=s[0];d!==h&&(K.isLocalOnly(d)||(d===W?n.post({t:"e",s:x,err:P(s[1])}):n.post({t:"s",s:x,sig:I(d),d:s.length>1?s[1]:void 0})))}}));g.push(c)}let w=n.listen(x=>{if(m)return;let b=x;switch(b.t){case"i":{B(()=>{for(let[c,a]of Object.entries(b.stores)){let s=r.get(c);s&&s.down([[h,a]])}});break}case"v":{let c=r.get(b.s);c&&c.down([[h,b.d]]);break}case"b":{B(()=>{for(let[c,a]of Object.entries(b.u)){let s=b.v?.[c];if(s!=null){let i=f.get(c);if(i!=null&&s<=i)continue;f.set(c,s)}let d=r.get(c);d&&d.down([[h,a]])}});break}case"e":{let c=r.get(b.s);c&&c.down([[W,A(b.err)]]);break}case"s":{let c=V(b.sig);if(!c)break;if(c===S&&b.s==="*"){M();return}let a=b.s==="*"?[...r.values()]:r.has(b.s)?[r.get(b.s)]:[];for(let s of a)s.down(b.d===void 0?[[c]]:[[c,b.d]]);break}}}),T={};for(let[x,b]of o)T[x]=b.cache;n.post({t:"r",stores:T});function M(){if(!m){m=!0,u&&u();for(let x of g)x();g.length=0,w(),n.terminate?.(),f.clear(),r.clear()}}return{destroy:M}}export{fe as a,Tt as b,_ as c,wt as d,I as e,V as f,P as g,A as h,L as i,pe as j,le as k,Rt as l};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{a as M,c as re,d as se}from"./chunk-CGA5RXO6.js";import{c as ae}from"./chunk-O32GJOUJ.js";import{b as J}from"./chunk-KUVDFOJH.js";import{j as ne}from"./chunk-5KPIYVCC.js";import{C as z}from"./chunk-MQZWA3DF.js";import{D as ee,E as te,G as j,m as Y,p as R,t as D}from"./chunk-LYCLF26R.js";import{b as X}from"./chunk-CK2E7BTU.js";import{b as ge}from"./chunk-QYADASLV.js";var fe={};ge(fe,{CqrsGraph:()=>G,cqrs:()=>ve,cqrsEventKeyOf:()=>ue,dispatchKeyOf:()=>pe,sagaInvocationKeyOf:()=>he});var x=class extends Error{constructor(e,n){super(e,n),this.name=this.constructor.name}},B=class extends x{constructor(n,t){super(`Duplicate ${n} registration: "${t}"`);this.kind=n;this.registrationName=t}},N=class extends x{constructor(n,t,r){super(`Command "${n}" emitted undeclared event "${t}". Declared emits: [${r.join(", ")}]`);this.commandName=n;this.eventName=t;this.declaredEmits=r}},K=class extends x{constructor(n,t,r){super(`Optimistic concurrency conflict on aggregate "${n}": expected version ${t}, got ${r}`);this.aggregateId=n;this.expected=t;this.actual=r}},H=class extends x{constructor(n){super(`Unknown command: "${n}". Register with command() first.`);this.commandName=n}},O=class extends x{constructor(n,t){super(`Command handler "${n}" threw: ${t instanceof Error?t.message:String(t)}`,{cause:t});this.commandName=n}};var P=class extends x{constructor(n,t){super(`Projection "${n}" rebuild failed: ${t instanceof Error?t.message:String(t)}`,{cause:t});this.projectionName=n}};var ce=D((a,e)=>{a("write"),a("signal"),e("observe")}),le=D((a,e)=>{a("observe"),a("signal"),e("write")}),oe=D((a,e)=>{a("observe"),a("signal"),e("write")});function $(a,e){return ae("cqrs",a,e)}function Z(a){if(a===null||typeof a!="object"||Object.isFrozen(a))return a;for(let e of Object.keys(a))Z(a[e]);return Object.freeze(a)}var ue=a=>`${a.type}::${a.aggregateId??"__default__"}`,pe=a=>a.commandName,he=a=>a.eventType,G=class extends ne{_eventLogs=new Map;_eventLogsByAggregate=new Map;_aggregateVersions=new Map;_aggregateLru=new Map;_commandRegs=new Map;_projections=new Set;_sagas=new Set;_keepaliveDisposers=[];_seq=0;_retainedLimit;_freezeCommandPayload;_freezeEventPayload;_maxAggregates;_dispatchSeqCursor;dispatches;audit;aggregateEvictions;constructor(e,n={}){super(e,n.graph),this._retainedLimit=n.retainedLimit??1024,this._freezeCommandPayload=n.freezeCommandPayload??!0,this._freezeEventPayload=n.freezeEventPayload??!0,this._maxAggregates=n.maxAggregates??1e4,this.dispatches=M({name:"dispatches",retainedLimit:this._retainedLimit,graph:this}),this.audit=this.dispatches,this.aggregateEvictions=M({name:"aggregateEvictions",retainedLimit:this._retainedLimit,graph:this}),this._dispatchSeqCursor=re(this,"dispatch_seq",0)}aggregateVersion(e,n){return this._aggregateVersions.get(`${e}::${n}`)??0}_touchAggregate(e){this._aggregateLru.delete(e),this._aggregateLru.set(e,!0)}_enforceAggregateLru(){for(;this._aggregateLru.size>this._maxAggregates;){let e=this._aggregateLru.keys().next();if(e.done)break;let n=e.value;this._aggregateLru.delete(n);let t=n.indexOf("::");if(t<0)continue;let r=n.slice(0,t),s=n.slice(t+2),o=this._aggregateVersions.get(n)??0;this._aggregateVersions.delete(n);let i=this._eventLogsByAggregate.get(r);i&&(i.delete(s),i.size===0&&this._eventLogsByAggregate.delete(r)),this.aggregateEvictions.append({aggregateId:s,type:r,lastVersion:o,t_ns:R()})}}destroy(){for(let e of this._keepaliveDisposers)e();this._keepaliveDisposers.length=0,super.destroy()}_attachedEventTiers=[];_attachedTierDisposers=new Map;attachEventStorage(e){this._attachedEventTiers.push(e);for(let[n,t]of this._eventLogs){let r=t.log.attachStorage(e),s=this._attachedTierDisposers.get(n);s||(s=[],this._attachedTierDisposers.set(n,s)),s.push(r)}for(let[n,t]of this._eventLogsByAggregate)for(let[r,s]of t){let o=`${n}::${r}`,i=s.log.attachStorage(e),c=this._attachedTierDisposers.get(o);c||(c=[],this._attachedTierDisposers.set(o,c)),c.push(i)}return()=>{let n=this._attachedEventTiers.indexOf(e);n>=0&&this._attachedEventTiers.splice(n,1)}}_autoWireStreamStorage(e,n){if(this._attachedEventTiers.length===0)return;let t=this._attachedTierDisposers.get(e);t||(t=[],this._attachedTierDisposers.set(e,t));for(let r of this._attachedEventTiers)t.push(n.attachStorage(r))}_bumpDispatchSeq(){let n=(this._dispatchSeqCursor.cache??0)+1;return this._dispatchSeqCursor.emit(n),n}event(e,n){if(n!==void 0)return this._ensureAggregateStream(e,n).node;let t=this._eventLogs.get(e);if(t)return t.node;let r=J([],{name:e,versioning:0,maxSize:this._retainedLimit});r.withLatest();let s=r.entries,o=j([s],([i])=>i,{name:e,describeKind:"state",meta:$("event",{event_name:e}),guard:oe,initial:s.cache});return this.add(o,{name:e}),this._keepaliveDisposers.push(z(o)),this._eventLogs.set(e,{log:r,node:o}),this._autoWireStreamStorage(e,r),o}_ensureAggregateStream(e,n){this._eventLogs.has(e)||this.event(e);let t=this._eventLogsByAggregate.get(e);t||(t=new Map,this._eventLogsByAggregate.set(e,t));let r=`${e}::${n}`;this._touchAggregate(r);let s=t.get(n);if(s)return s;let o=`${e}_${n.replace(/[^a-zA-Z0-9_-]/g,"_")}`,i=J([],{name:o,versioning:0,maxSize:this._retainedLimit});i.withLatest();let c=i.entries,h=j([c],([p])=>p,{name:o,describeKind:"state",meta:$("event_aggregate",{event_name:e,aggregate_id:n}),guard:oe,initial:c.cache}),l=o,m=0;for(;this.nameOf(this.resolveOptional(l)??h)===l&&(m+=1,l=`${o}_${m}`,this.resolveOptional(l)!==void 0););try{this.add(h,{name:l})}catch{}this._keepaliveDisposers.push(z(h));let u={log:i,node:h};return t.set(n,u),this._autoWireStreamStorage(`${e}::${n}`,i),this._enforceAggregateLru(),u}resolveOptional(e){try{return this.resolve(e)}catch{return}}_appendEvent(e,n,t){let r=this._eventLogs.get(e);if(r||(this.event(e),r=this._eventLogs.get(e)),r.node.status==="completed"||r.node.status==="errored")throw new Error(`Cannot dispatch to terminated event stream "${e}" (status: ${r.node.status}).`);let s,o;if(t?.aggregateId!==void 0){let l=`${e}::${t.aggregateId}`;s=(this._aggregateVersions.get(l)??0)+1,this._aggregateVersions.set(l,s),o=this._ensureAggregateStream(e,t.aggregateId)}let i=r.log.entries.v,c=this._freezeEventPayload?Z(n):n,h={type:e,payload:c,timestampNs:R(),seq:++this._seq,...t?.aggregateId!==void 0?{aggregateId:t.aggregateId}:{},...s!==void 0?{aggregateVersion:s}:{},...t?.correlationId!==void 0?{correlationId:t.correlationId}:{},...t?.causationId!==void 0?{causationId:t.causationId}:{},...t?.metadata!==void 0?{metadata:Object.freeze({...t.metadata})}:{},...t?.handlerVersion!==void 0?{handlerVersion:t.handlerVersion}:{},...i!=null?{v0:{id:i.id,version:i.version}}:{}};return r.log.append(h),o&&o.log.append(h),h}command(e,n){if(this._commandRegs.has(e))throw new B("command",e);let t=typeof n=="function"?{handler:n}:n,r=te(void 0,{name:e,describeKind:"state",meta:{...$("command",{command_name:e}),error:null},guard:ce});if(this.add(r,{name:e}),this._commandRegs.set(e,{handler:t.handler,...t.emits!==void 0?{emits:t.emits}:{},...t.handlerVersion!==void 0?{handlerVersion:t.handlerVersion}:{}}),t.emits)for(let s of t.emits)this._eventLogs.has(s)||this.event(s);return r}dispatch(e,n,t){let r=this._commandRegs.get(e);if(!r)throw new H(e);if(t?.aggregateId!==void 0&&t.expectedAggregateVersion!==void 0&&r.emits!==void 0){let u=0;for(let p of r.emits){let _=this._aggregateVersions.get(`${p}::${t.aggregateId}`);_!==void 0&&_>u&&(u=_)}if(u!==t.expectedAggregateVersion)throw new K(t.aggregateId,t.expectedAggregateVersion,u)}let s=this.resolve(e),o=this._freezeCommandPayload?Z(n):n,i=[],c=R(),h=0,l,m=!1;try{Y(()=>{h=this._bumpDispatchSeq(),s.emit(o,{internal:!0});try{r.handler(o,{emit:(u,p)=>{if(r.emits!==void 0&&!r.emits.includes(u))throw new N(e,u,r.emits);i.push(u),this._appendEvent(u,p,{...t?.aggregateId!==void 0?{aggregateId:t.aggregateId}:{},...t?.correlationId!==void 0?{correlationId:t.correlationId}:{},...t?.causationId!==void 0?{causationId:t.causationId}:{},...t?.metadata!==void 0?{metadata:Object.freeze({...t.metadata})}:{},...r.handlerVersion!==void 0?{handlerVersion:r.handlerVersion}:{}})}}),s.meta.error.emit(null,{internal:!0}),this.dispatches.append({commandName:e,payload:o,status:"success",emittedEvents:[...i],t_ns:c,seq:h,...r.handlerVersion!==void 0?{handlerVersion:r.handlerVersion}:{}})}catch(u){throw l=u,m=!0,u}})}catch(u){if(m){s.meta.error.emit(l,{internal:!0});let p=l instanceof Error?l.name:typeof l,_=l instanceof O?l:new O(e,l);this.dispatches.append({commandName:e,payload:o,status:"failed",error:_,errorType:p,emittedEvents:[...i],t_ns:c,seq:h,...r.handlerVersion!==void 0?{handlerVersion:r.handlerVersion}:{}})}throw m?l:u}}projection(e){let{name:n,events:t,reducer:r,initial:s}=e,o=e.mode??"scan",i=e.freezeInputs??!0,c=e.snapshot,h=t.map(d=>(this._eventLogs.has(d)||this.event(d),this._eventLogs.get(d).node));function l(d){d.sort((g,v)=>g.timestampNs-v.timestampNs||g.seq-v.seq||(g.aggregateId??"").localeCompare(v.aggregateId??""))}function m(d){let g=[];for(let v of d)g.push(...v);return l(g),g}let u=h.map(d=>d.cache??[]),p=m(u),_=i?Object.freeze(p):p,C=0,y=s;o==="scan"&&p.length>0&&(y=r(s,_),C=p.length);let q=o==="replay"?r(s,_):y,V=c?.saveDebounceMs??1e3,A=c?.saveEvery??1e3,E,L=0;function U(d){if(c?.save){if(L+=1,L>=A){L=0,E!==void 0&&(clearTimeout(E),E=void 0);let g=c.save(d);g instanceof Promise&&g.catch(()=>{});return}E!==void 0&&clearTimeout(E),E=setTimeout(()=>{E=void 0,L=0;let g=c.save(d);g instanceof Promise&&g.catch(()=>{})},V)}}let S=j(h,d=>{let g=m(d),v;if(o==="replay"){let w=i?Object.freeze(g):g;v=r(s,w)}else{let w=g.slice(C);C=g.length;let f=i?Object.freeze(w):w;v=r(y,f),y=v}return U(v),v},{name:n,describeKind:"derived",meta:$("projection",{projection_name:n,source_events:t}),guard:le,initial:q});return this.add(S,{name:n}),this._keepaliveDisposers.push(z(S)),this._keepaliveDisposers.push(()=>{E!==void 0&&(clearTimeout(E),E=void 0)}),this._projections.add(n),{node:S,rebuild:async d=>{try{let g=d?.pageSize??1e3,v=d?.fromTier??this._attachedEventTiers[0]?.[0],w=m(h.map(T=>T.cache??[])).length,f=s;if(c?.load){let T=await c.load();T!==void 0&&(f=T)}if(!v||!v.loadEntries){let T=m(h.map(I=>I.cache??[])),b=i?Object.freeze(T):T;f=r(f,b)}else{let T=new Set(t),b,I=!1;for(;!I;){let F=await v.loadEntries({cursor:b,pageSize:g}),W=[...F.entries].filter(de=>T.has(de.type));l(W);let ie=i?Object.freeze(W):W;f=r(f,ie),b=F.cursor,I=!b||F.entries.length===0}}if(o==="scan"){let T=m(h.map(I=>I.cache??[])),b=T.slice(w);if(b.length>0){let I=i?Object.freeze(b):b;f=r(f,I)}y=f,C=T.length}return S.emit(f,{internal:!0}),f}catch(g){throw new P(n,g)}},reset:async()=>{try{let d=s;if(c?.load){let f=await c.load();f!==void 0&&(d=f)}let g=m(h.map(f=>f.cache??[])),v=i?Object.freeze(g):g,w=r(d,v);return o==="scan"&&(y=w,C=g.length),S.emit(w,{internal:!0}),w}catch(d){throw new P(n,d)}}}}saga(e,n,t,r={}){let s=n.map(p=>(this._eventLogs.has(p)||this.event(p),this._eventLogs.get(p).node)),o=se(this,`${e}_cursor`,n,0),i=M({name:`${e}_invocations`,retainedLimit:this._retainedLimit,graph:this}),c=r.aggregateId,h=r.errorPolicy??"advance",l=new Map;for(let p of n){let _=o[p];l.set(p,_.cache??0);let C=_.subscribe(y=>{for(let q of y)q[0]===X&&l.set(p,q[1])});this._keepaliveDisposers.push(C)}let m={},u=ee(s,(p,_)=>{let C=m.n.meta.error;for(let y=0;y<p.length;y++){let q=p[y];if(q==null||q.length===0)continue;let V=q.at(-1);if(!V)continue;let A=n[y],E=o[A],L=l.get(A)??0;if(V.length>L){let U=V.slice(L),S=L;for(let Q of U){let k=Q;if(c!==void 0&&k.aggregateId!==c){S+=1;continue}try{t(k),C.emit(null,{internal:!0}),i.append({eventType:A,status:"success",aggregateId:k.aggregateId,event:k,t_ns:R(),...r.handlerVersion!==void 0?{handlerVersion:r.handlerVersion}:{}}),S+=1}catch(d){if(C.emit(d,{internal:!0}),i.append({eventType:A,status:"failed",error:d,errorType:d instanceof Error?d.name:typeof d,aggregateId:k.aggregateId,event:k,t_ns:R(),...r.handlerVersion!==void 0?{handlerVersion:r.handlerVersion}:{}}),h==="hold")break;S+=1}}E.emit(S)}}},{name:e,describeKind:"effect",meta:{...$("saga",{saga_name:e,source_events:n}),error:null}});return m.n=u,this.add(u,{name:e}),this._keepaliveDisposers.push(z(u)),this._sagas.add(e),{node:u,invocations:i,audit:i,cursors:o}}};function ve(a,e){return new G(a,e)}export{ue as a,pe as b,he as c,G as d,ve as e,fe as f};
|
|
1
|
+
import{a as M,c as re,d as se}from"./chunk-FJ6IEMOS.js";import{c as ae}from"./chunk-O32GJOUJ.js";import{j as ne}from"./chunk-B4L5X2QO.js";import{b as J}from"./chunk-KUVDFOJH.js";import{C as z}from"./chunk-MQZWA3DF.js";import{D as ee,E as te,G as j,m as Y,p as R,t as D}from"./chunk-LYCLF26R.js";import{b as X}from"./chunk-CK2E7BTU.js";import{b as ge}from"./chunk-QYADASLV.js";var fe={};ge(fe,{CqrsGraph:()=>G,cqrs:()=>ve,cqrsEventKeyOf:()=>ue,dispatchKeyOf:()=>pe,sagaInvocationKeyOf:()=>he});var x=class extends Error{constructor(e,n){super(e,n),this.name=this.constructor.name}},B=class extends x{constructor(n,t){super(`Duplicate ${n} registration: "${t}"`);this.kind=n;this.registrationName=t}},N=class extends x{constructor(n,t,r){super(`Command "${n}" emitted undeclared event "${t}". Declared emits: [${r.join(", ")}]`);this.commandName=n;this.eventName=t;this.declaredEmits=r}},K=class extends x{constructor(n,t,r){super(`Optimistic concurrency conflict on aggregate "${n}": expected version ${t}, got ${r}`);this.aggregateId=n;this.expected=t;this.actual=r}},H=class extends x{constructor(n){super(`Unknown command: "${n}". Register with command() first.`);this.commandName=n}},O=class extends x{constructor(n,t){super(`Command handler "${n}" threw: ${t instanceof Error?t.message:String(t)}`,{cause:t});this.commandName=n}};var P=class extends x{constructor(n,t){super(`Projection "${n}" rebuild failed: ${t instanceof Error?t.message:String(t)}`,{cause:t});this.projectionName=n}};var ce=D((a,e)=>{a("write"),a("signal"),e("observe")}),le=D((a,e)=>{a("observe"),a("signal"),e("write")}),oe=D((a,e)=>{a("observe"),a("signal"),e("write")});function $(a,e){return ae("cqrs",a,e)}function Z(a){if(a===null||typeof a!="object"||Object.isFrozen(a))return a;for(let e of Object.keys(a))Z(a[e]);return Object.freeze(a)}var ue=a=>`${a.type}::${a.aggregateId??"__default__"}`,pe=a=>a.commandName,he=a=>a.eventType,G=class extends ne{_eventLogs=new Map;_eventLogsByAggregate=new Map;_aggregateVersions=new Map;_aggregateLru=new Map;_commandRegs=new Map;_projections=new Set;_sagas=new Set;_keepaliveDisposers=[];_seq=0;_retainedLimit;_freezeCommandPayload;_freezeEventPayload;_maxAggregates;_dispatchSeqCursor;dispatches;audit;aggregateEvictions;constructor(e,n={}){super(e,n.graph),this._retainedLimit=n.retainedLimit??1024,this._freezeCommandPayload=n.freezeCommandPayload??!0,this._freezeEventPayload=n.freezeEventPayload??!0,this._maxAggregates=n.maxAggregates??1e4,this.dispatches=M({name:"dispatches",retainedLimit:this._retainedLimit,graph:this}),this.audit=this.dispatches,this.aggregateEvictions=M({name:"aggregateEvictions",retainedLimit:this._retainedLimit,graph:this}),this._dispatchSeqCursor=re(this,"dispatch_seq",0)}aggregateVersion(e,n){return this._aggregateVersions.get(`${e}::${n}`)??0}_touchAggregate(e){this._aggregateLru.delete(e),this._aggregateLru.set(e,!0)}_enforceAggregateLru(){for(;this._aggregateLru.size>this._maxAggregates;){let e=this._aggregateLru.keys().next();if(e.done)break;let n=e.value;this._aggregateLru.delete(n);let t=n.indexOf("::");if(t<0)continue;let r=n.slice(0,t),s=n.slice(t+2),o=this._aggregateVersions.get(n)??0;this._aggregateVersions.delete(n);let i=this._eventLogsByAggregate.get(r);i&&(i.delete(s),i.size===0&&this._eventLogsByAggregate.delete(r)),this.aggregateEvictions.append({aggregateId:s,type:r,lastVersion:o,t_ns:R()})}}destroy(){for(let e of this._keepaliveDisposers)e();this._keepaliveDisposers.length=0,super.destroy()}_attachedEventTiers=[];_attachedTierDisposers=new Map;attachEventStorage(e){this._attachedEventTiers.push(e);for(let[n,t]of this._eventLogs){let r=t.log.attachStorage(e),s=this._attachedTierDisposers.get(n);s||(s=[],this._attachedTierDisposers.set(n,s)),s.push(r)}for(let[n,t]of this._eventLogsByAggregate)for(let[r,s]of t){let o=`${n}::${r}`,i=s.log.attachStorage(e),c=this._attachedTierDisposers.get(o);c||(c=[],this._attachedTierDisposers.set(o,c)),c.push(i)}return()=>{let n=this._attachedEventTiers.indexOf(e);n>=0&&this._attachedEventTiers.splice(n,1)}}_autoWireStreamStorage(e,n){if(this._attachedEventTiers.length===0)return;let t=this._attachedTierDisposers.get(e);t||(t=[],this._attachedTierDisposers.set(e,t));for(let r of this._attachedEventTiers)t.push(n.attachStorage(r))}_bumpDispatchSeq(){let n=(this._dispatchSeqCursor.cache??0)+1;return this._dispatchSeqCursor.emit(n),n}event(e,n){if(n!==void 0)return this._ensureAggregateStream(e,n).node;let t=this._eventLogs.get(e);if(t)return t.node;let r=J([],{name:e,versioning:0,maxSize:this._retainedLimit});r.withLatest();let s=r.entries,o=j([s],([i])=>i,{name:e,describeKind:"state",meta:$("event",{event_name:e}),guard:oe,initial:s.cache});return this.add(o,{name:e}),this._keepaliveDisposers.push(z(o)),this._eventLogs.set(e,{log:r,node:o}),this._autoWireStreamStorage(e,r),o}_ensureAggregateStream(e,n){this._eventLogs.has(e)||this.event(e);let t=this._eventLogsByAggregate.get(e);t||(t=new Map,this._eventLogsByAggregate.set(e,t));let r=`${e}::${n}`;this._touchAggregate(r);let s=t.get(n);if(s)return s;let o=`${e}_${n.replace(/[^a-zA-Z0-9_-]/g,"_")}`,i=J([],{name:o,versioning:0,maxSize:this._retainedLimit});i.withLatest();let c=i.entries,h=j([c],([p])=>p,{name:o,describeKind:"state",meta:$("event_aggregate",{event_name:e,aggregate_id:n}),guard:oe,initial:c.cache}),l=o,m=0;for(;this.nameOf(this.resolveOptional(l)??h)===l&&(m+=1,l=`${o}_${m}`,this.resolveOptional(l)!==void 0););try{this.add(h,{name:l})}catch{}this._keepaliveDisposers.push(z(h));let u={log:i,node:h};return t.set(n,u),this._autoWireStreamStorage(`${e}::${n}`,i),this._enforceAggregateLru(),u}resolveOptional(e){try{return this.resolve(e)}catch{return}}_appendEvent(e,n,t){let r=this._eventLogs.get(e);if(r||(this.event(e),r=this._eventLogs.get(e)),r.node.status==="completed"||r.node.status==="errored")throw new Error(`Cannot dispatch to terminated event stream "${e}" (status: ${r.node.status}).`);let s,o;if(t?.aggregateId!==void 0){let l=`${e}::${t.aggregateId}`;s=(this._aggregateVersions.get(l)??0)+1,this._aggregateVersions.set(l,s),o=this._ensureAggregateStream(e,t.aggregateId)}let i=r.log.entries.v,c=this._freezeEventPayload?Z(n):n,h={type:e,payload:c,timestampNs:R(),seq:++this._seq,...t?.aggregateId!==void 0?{aggregateId:t.aggregateId}:{},...s!==void 0?{aggregateVersion:s}:{},...t?.correlationId!==void 0?{correlationId:t.correlationId}:{},...t?.causationId!==void 0?{causationId:t.causationId}:{},...t?.metadata!==void 0?{metadata:Object.freeze({...t.metadata})}:{},...t?.handlerVersion!==void 0?{handlerVersion:t.handlerVersion}:{},...i!=null?{v0:{id:i.id,version:i.version}}:{}};return r.log.append(h),o&&o.log.append(h),h}command(e,n){if(this._commandRegs.has(e))throw new B("command",e);let t=typeof n=="function"?{handler:n}:n,r=te(void 0,{name:e,describeKind:"state",meta:{...$("command",{command_name:e}),error:null},guard:ce});if(this.add(r,{name:e}),this._commandRegs.set(e,{handler:t.handler,...t.emits!==void 0?{emits:t.emits}:{},...t.handlerVersion!==void 0?{handlerVersion:t.handlerVersion}:{}}),t.emits)for(let s of t.emits)this._eventLogs.has(s)||this.event(s);return r}dispatch(e,n,t){let r=this._commandRegs.get(e);if(!r)throw new H(e);if(t?.aggregateId!==void 0&&t.expectedAggregateVersion!==void 0&&r.emits!==void 0){let u=0;for(let p of r.emits){let _=this._aggregateVersions.get(`${p}::${t.aggregateId}`);_!==void 0&&_>u&&(u=_)}if(u!==t.expectedAggregateVersion)throw new K(t.aggregateId,t.expectedAggregateVersion,u)}let s=this.resolve(e),o=this._freezeCommandPayload?Z(n):n,i=[],c=R(),h=0,l,m=!1;try{Y(()=>{h=this._bumpDispatchSeq(),s.emit(o,{internal:!0});try{r.handler(o,{emit:(u,p)=>{if(r.emits!==void 0&&!r.emits.includes(u))throw new N(e,u,r.emits);i.push(u),this._appendEvent(u,p,{...t?.aggregateId!==void 0?{aggregateId:t.aggregateId}:{},...t?.correlationId!==void 0?{correlationId:t.correlationId}:{},...t?.causationId!==void 0?{causationId:t.causationId}:{},...t?.metadata!==void 0?{metadata:Object.freeze({...t.metadata})}:{},...r.handlerVersion!==void 0?{handlerVersion:r.handlerVersion}:{}})}}),s.meta.error.emit(null,{internal:!0}),this.dispatches.append({commandName:e,payload:o,status:"success",emittedEvents:[...i],t_ns:c,seq:h,...r.handlerVersion!==void 0?{handlerVersion:r.handlerVersion}:{}})}catch(u){throw l=u,m=!0,u}})}catch(u){if(m){s.meta.error.emit(l,{internal:!0});let p=l instanceof Error?l.name:typeof l,_=l instanceof O?l:new O(e,l);this.dispatches.append({commandName:e,payload:o,status:"failed",error:_,errorType:p,emittedEvents:[...i],t_ns:c,seq:h,...r.handlerVersion!==void 0?{handlerVersion:r.handlerVersion}:{}})}throw m?l:u}}projection(e){let{name:n,events:t,reducer:r,initial:s}=e,o=e.mode??"scan",i=e.freezeInputs??!0,c=e.snapshot,h=t.map(d=>(this._eventLogs.has(d)||this.event(d),this._eventLogs.get(d).node));function l(d){d.sort((g,v)=>g.timestampNs-v.timestampNs||g.seq-v.seq||(g.aggregateId??"").localeCompare(v.aggregateId??""))}function m(d){let g=[];for(let v of d)g.push(...v);return l(g),g}let u=h.map(d=>d.cache??[]),p=m(u),_=i?Object.freeze(p):p,C=0,y=s;o==="scan"&&p.length>0&&(y=r(s,_),C=p.length);let q=o==="replay"?r(s,_):y,V=c?.saveDebounceMs??1e3,A=c?.saveEvery??1e3,E,L=0;function U(d){if(c?.save){if(L+=1,L>=A){L=0,E!==void 0&&(clearTimeout(E),E=void 0);let g=c.save(d);g instanceof Promise&&g.catch(()=>{});return}E!==void 0&&clearTimeout(E),E=setTimeout(()=>{E=void 0,L=0;let g=c.save(d);g instanceof Promise&&g.catch(()=>{})},V)}}let S=j(h,d=>{let g=m(d),v;if(o==="replay"){let w=i?Object.freeze(g):g;v=r(s,w)}else{let w=g.slice(C);C=g.length;let f=i?Object.freeze(w):w;v=r(y,f),y=v}return U(v),v},{name:n,describeKind:"derived",meta:$("projection",{projection_name:n,source_events:t}),guard:le,initial:q});return this.add(S,{name:n}),this._keepaliveDisposers.push(z(S)),this._keepaliveDisposers.push(()=>{E!==void 0&&(clearTimeout(E),E=void 0)}),this._projections.add(n),{node:S,rebuild:async d=>{try{let g=d?.pageSize??1e3,v=d?.fromTier??this._attachedEventTiers[0]?.[0],w=m(h.map(T=>T.cache??[])).length,f=s;if(c?.load){let T=await c.load();T!==void 0&&(f=T)}if(!v||!v.loadEntries){let T=m(h.map(I=>I.cache??[])),b=i?Object.freeze(T):T;f=r(f,b)}else{let T=new Set(t),b,I=!1;for(;!I;){let F=await v.loadEntries({cursor:b,pageSize:g}),W=[...F.entries].filter(de=>T.has(de.type));l(W);let ie=i?Object.freeze(W):W;f=r(f,ie),b=F.cursor,I=!b||F.entries.length===0}}if(o==="scan"){let T=m(h.map(I=>I.cache??[])),b=T.slice(w);if(b.length>0){let I=i?Object.freeze(b):b;f=r(f,I)}y=f,C=T.length}return S.emit(f,{internal:!0}),f}catch(g){throw new P(n,g)}},reset:async()=>{try{let d=s;if(c?.load){let f=await c.load();f!==void 0&&(d=f)}let g=m(h.map(f=>f.cache??[])),v=i?Object.freeze(g):g,w=r(d,v);return o==="scan"&&(y=w,C=g.length),S.emit(w,{internal:!0}),w}catch(d){throw new P(n,d)}}}}saga(e,n,t,r={}){let s=n.map(p=>(this._eventLogs.has(p)||this.event(p),this._eventLogs.get(p).node)),o=se(this,`${e}_cursor`,n,0),i=M({name:`${e}_invocations`,retainedLimit:this._retainedLimit,graph:this}),c=r.aggregateId,h=r.errorPolicy??"advance",l=new Map;for(let p of n){let _=o[p];l.set(p,_.cache??0);let C=_.subscribe(y=>{for(let q of y)q[0]===X&&l.set(p,q[1])});this._keepaliveDisposers.push(C)}let m={},u=ee(s,(p,_)=>{let C=m.n.meta.error;for(let y=0;y<p.length;y++){let q=p[y];if(q==null||q.length===0)continue;let V=q.at(-1);if(!V)continue;let A=n[y],E=o[A],L=l.get(A)??0;if(V.length>L){let U=V.slice(L),S=L;for(let Q of U){let k=Q;if(c!==void 0&&k.aggregateId!==c){S+=1;continue}try{t(k),C.emit(null,{internal:!0}),i.append({eventType:A,status:"success",aggregateId:k.aggregateId,event:k,t_ns:R(),...r.handlerVersion!==void 0?{handlerVersion:r.handlerVersion}:{}}),S+=1}catch(d){if(C.emit(d,{internal:!0}),i.append({eventType:A,status:"failed",error:d,errorType:d instanceof Error?d.name:typeof d,aggregateId:k.aggregateId,event:k,t_ns:R(),...r.handlerVersion!==void 0?{handlerVersion:r.handlerVersion}:{}}),h==="hold")break;S+=1}}E.emit(S)}}},{name:e,describeKind:"effect",meta:{...$("saga",{saga_name:e,source_events:n}),error:null}});return m.n=u,this.add(u,{name:e}),this._keepaliveDisposers.push(z(u)),this._sagas.add(e),{node:u,invocations:i,audit:i,cursors:o}}};function ve(a,e){return new G(a,e)}export{ue as a,pe as b,he as c,G as d,ve as e,fe as f};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{a as L,b as _}from"./chunk-
|
|
1
|
+
import{a as L,b as _}from"./chunk-FJ6IEMOS.js";import{c as z}from"./chunk-O32GJOUJ.js";import{j as F}from"./chunk-B4L5X2QO.js";import{D as j,E as G,G as D,m as E,p as B}from"./chunk-LYCLF26R.js";import{b as P,d as S,i as I,j as K}from"./chunk-CK2E7BTU.js";import{b as te}from"./chunk-QYADASLV.js";var ie={};te(ie,{PipelineGraph:()=>x,decisionKeyOf:()=>$,pipelineGraph:()=>q});function N(y,t){return z("orchestration",y,t)}var $=y=>y.action,x=class extends F{constructor(t,s){super(t,s)}task(t,s,e={}){let a=(e.deps??[]).map(c=>this._resolveStep(c)),p=D(a,s,{name:t,describeKind:"derived",meta:N("task",e.meta)});return this.add(p,{name:t}),p}classify(t,s,e,a={}){let p=this._resolveStep(s),c=D([p],([d])=>{try{return{tag:e(d),value:d}}catch(f){return{tag:"error",value:d,error:f}}},{name:t,describeKind:"derived",meta:N("classify",a.meta)});return this.add(c,{name:t}),c}combine(t,s,e={}){let a=Object.keys(s),p=a.map(d=>this._resolveStep(s[d])),c=D(p,d=>{let f={};for(let i=0;i<a.length;i++)f[a[i]]=d[i];return f},{name:t,describeKind:"derived",meta:N("combine",e.meta)});return this.add(c,{name:t}),c}gate(t,s,e={}){let a=e.maxPending??1e3;if(a<1&&a!==Number.POSITIVE_INFINITY)throw new RangeError("gate: maxPending must be >= 1");let p=e.startOpen??!1;typeof s!="string"&&this.nameOf(s)===void 0&&this.add(s,{name:`${t}/source`});let c=this._resolveStep(s),d=new F(`${t}_state`),f=G([],{name:"pending",equals:()=>!1}),i=G(p,{name:"isOpen"}),R=D([f],([n])=>n.length,{name:"count"}),h=G(0,{name:"droppedCount"}),u=L({name:"decisions",retainedLimit:1024,graph:d});d.add(f,{name:"pending"}),d.add(i,{name:"isOpen"}),d.add(R,{name:"count"}),d.add(h,{name:"droppedCount"}),this.mount(`${t}_state`,d);let l=[],v=!1,k=!1,O=p,W=i.subscribe(n=>{for(let o of n)o[0]===P&&(O=o[1])});this.addDisposer(W);function A(){f.emit([...l])}function C(n,o,r){u.append({action:n,t_ns:B(),...o!==void 0?{items:o,count:o.length}:{},...r!==void 0?{unflushed:r}:{},...e.handlerVersion!=null?{handlerVersion:e.handlerVersion}:{}})}function M(n){if(l.push(n),l.length>a){let o=l.shift();h.emit(h.cache+1),C("drop",[o])}A()}function w(n){let o=l.splice(0,n);return A(),o}let b=j([c],(n,o,r)=>{let T=r.terminalDeps[0];if(T!==void 0){v=!0;let g=l.length;l=[],A(),C("teardown",void 0,g),o.down(T===!0?[[I]]:[[K,T]]);return}let m=n[0];if(m==null||m.length===0){o.down([[S]]);return}for(let g of m)O?o.emit(g):(M(g),o.down([[S]]))},{name:t,describeKind:"derived",meta:N("gate",e.meta)});if(this.add(b,{name:t}),e.approver!=null){e.approver.cache&&(i.emit(!0),O=!0,e.onceOnly&&(k=!0));let o=e.approver.subscribe(r=>{for(let T of r){if(T[0]!==P)continue;let m=!!T[1];if(m&&!O){if(e.onceOnly){if(k)continue;k=!0}E(()=>{i.emit(!0);let g=w(l.length);C("open",g);for(let oe of g){if(v)break;b.emit(oe)}})}else if(!m&&O){if(e.onceOnly&&k)continue;E(()=>{i.emit(!1),C("close")})}}});this.addDisposer(o)}let V=n=>{if(v)throw new Error(`gate: ${n}() called after gate was torn down`)},U=(n=1)=>{V("approve");let o=w(n);for(let r of o){if(v)break;b.emit(r)}},Y=(n=1)=>{V("reject"),w(n)},H=(n,o=1)=>{V("modify");let r=[...l],T=w(o);for(let m=0;m<T.length&&!v;m++)b.emit(n(T[m],m,r))},J=()=>{V("open"),i.emit(!0);let n=w(l.length);for(let o of n){if(v)break;b.emit(o)}},Q=()=>{V("close"),!(e.onceOnly&&k)&&i.emit(!1)},X=_(U,{audit:u,freeze:!1,onSuccess:(n,o,r)=>({action:"approve",count:n[0]??1,t_ns:r.t_ns,...e.handlerVersion!=null?{handlerVersion:e.handlerVersion}:{}}),onFailure:(n,o,r)=>({action:"drop",t_ns:r.t_ns,errorType:r.errorType,...e.handlerVersion!=null?{handlerVersion:e.handlerVersion}:{}})}),Z=_(Y,{audit:u,freeze:!1,onSuccess:(n,o,r)=>({action:"reject",count:n[0]??1,t_ns:r.t_ns,...e.handlerVersion!=null?{handlerVersion:e.handlerVersion}:{}}),onFailure:(n,o,r)=>({action:"drop",t_ns:r.t_ns,errorType:r.errorType,...e.handlerVersion!=null?{handlerVersion:e.handlerVersion}:{}})}),ee=_(H,{audit:u,freeze:!1,onSuccess:(n,o,r)=>({action:"modify",count:n[1]??1,t_ns:r.t_ns,...e.handlerVersion!=null?{handlerVersion:e.handlerVersion}:{}}),onFailure:(n,o,r)=>({action:"drop",t_ns:r.t_ns,errorType:r.errorType,...e.handlerVersion!=null?{handlerVersion:e.handlerVersion}:{}})}),ne=_(J,{audit:u,freeze:!1,onSuccess:(n,o,r)=>({action:"open",t_ns:r.t_ns,...e.handlerVersion!=null?{handlerVersion:e.handlerVersion}:{}}),onFailure:(n,o,r)=>({action:"drop",t_ns:r.t_ns,errorType:r.errorType,...e.handlerVersion!=null?{handlerVersion:e.handlerVersion}:{}})}),re=_(Q,{audit:u,freeze:!1,onSuccess:(n,o,r)=>({action:"close",t_ns:r.t_ns,...e.handlerVersion!=null?{handlerVersion:e.handlerVersion}:{}}),onFailure:(n,o,r)=>({action:"drop",t_ns:r.t_ns,errorType:r.errorType,...e.handlerVersion!=null?{handlerVersion:e.handlerVersion}:{}})});return this.addDisposer(R.subscribe(()=>{})),{node:b,pending:f,count:R,isOpen:i,droppedCount:h,decisions:u,audit:u,approve:X,reject:Z,modify:ee,open:ne,close:re}}approval(t,s,e,a={}){return this.gate(t,s,{...a,approver:e,maxPending:1})}catch(t,s,e,a={}){let p=this._resolveStep(s),c=a.on??"error",d=j([p],(f,i,R)=>{let h=R.terminalDeps[0];if(h!==void 0){let l=h===!0?{kind:"complete"}:{kind:"error",error:h};if(c==="terminal"||c===l.kind){i.emit(e(l,i));return}i.down(l.kind==="complete"?[[I]]:[[K,l.error]]);return}let u=f[0];if(u==null||u.length===0){i.down([[S]]);return}for(let l of u)i.emit(l)},{name:t,describeKind:"derived",completeWhenDepsComplete:a.completeWhenDepsComplete??!(c==="complete"||c==="terminal"),errorWhenDepsError:!(c==="error"||c==="terminal"),meta:N("catch",a.meta)});return this.add(d,{name:t}),d}_resolveStep(t){if(typeof t=="string")return this.resolve(t);if(this.nameOf(t)===void 0)throw new Error(`PipelineGraph "${this.name}": Node dep is not registered. Pass a string path or call graph.add(node) first.`);return t}};function q(y,t){return new x(y,t)}export{$ as a,x as b,q as c,ie as d};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{a as L,c as D}from"./chunk-
|
|
1
|
+
import{a as L,c as D}from"./chunk-FJ6IEMOS.js";import{c as Q}from"./chunk-O32GJOUJ.js";import{j as F}from"./chunk-B4L5X2QO.js";import{b as G}from"./chunk-KGKJCHEK.js";import{b as I}from"./chunk-TZQPPQEQ.js";import{b as M}from"./chunk-KUVDFOJH.js";import{C as v,m as C}from"./chunk-MQZWA3DF.js";import{D as x,G as P,m as _,p as m}from"./chunk-LYCLF26R.js";import{b as N,j as A}from"./chunk-CK2E7BTU.js";import{b as V}from"./chunk-QYADASLV.js";var ee={};V(ee,{JobFlowGraph:()=>w,JobQueueGraph:()=>y,jobEventKeyOf:()=>Y,jobFlow:()=>Z,jobQueue:()=>z});var X=256,H=1024;function W(i,e){if(!Number.isFinite(i)||!Number.isInteger(i)||i<0)throw new Error(`${e} must be a non-negative integer`);return i}function T(i,e){return Q("job_queue",i,e)}var Y=i=>i.action,y=class extends F{_pending;_jobs;_seqCursor;pending;jobs;depth;events;audit;constructor(e,t={}){super(e,t.graph),this._pending=G([],{name:"pending"}),this._jobs=I({name:"jobs"}),this.pending=this._pending.items,this.jobs=this._jobs.entries,this.add(this.pending,{name:"pending"}),this.add(this.jobs,{name:"jobs"}),this.depth=P([this.pending],([o])=>o.length,{name:"depth",describeKind:"derived",meta:T("queue_depth"),initial:0}),this.add(this.depth,{name:"depth"}),this.addDisposer(v(this.depth)),this.events=L({name:"events",retainedLimit:1024,graph:this}),this.audit=this.events,this._seqCursor=D(this,"seq",0)}_bumpSeq(){let t=(this._seqCursor.cache??0)+1;return this._seqCursor.emit(t),t}attachEventStorage(e){return this.events.attachStorage(e)}enqueue(e,t={}){let o=this._bumpSeq(),n=t.id??`${this.name}-${o}`;if(this._jobs.get(n)!==void 0)throw new Error(`jobQueue("${this.name}"): duplicate job id "${n}"`);let p={id:n,payload:e,attempts:0,metadata:Object.freeze({...t.metadata??{}}),state:"queued"};return this._jobs.set(n,p),this._pending.append(n),this.events.append({action:"enqueue",id:n,payload:e,t_ns:m(),seq:o}),n}claim(e=1){let t=W(e,"job queue claim limit");if(t===0)return[];let o=[];for(;o.length<t&&this.pending.cache.length!==0;){let p=this._pending.pop(0),h=this._jobs.get(p);if(!h||h.state!=="queued")continue;let l={...h,state:"inflight",attempts:h.attempts+1};this._jobs.set(p,l),o.push(l),this.events.append({action:"claim",id:p,attempts:l.attempts,t_ns:m(),seq:this._bumpSeq()})}return o}ack(e){let t=this._jobs.get(e);return!t||t.state!=="inflight"?!1:(this._jobs.delete(e),this.events.append({action:"ack",id:e,attempts:t.attempts,t_ns:m(),seq:this._bumpSeq()}),!0)}nack(e,t={}){let o=this._jobs.get(e);return!o||o.state!=="inflight"?!1:t.requeue??!0?(this._jobs.set(e,{...o,state:"queued"}),this._pending.append(e),this.events.append({action:"nack",id:e,attempts:o.attempts,t_ns:m(),seq:this._bumpSeq()}),!0):(this._jobs.delete(e),this.events.append({action:"nack",id:e,attempts:o.attempts,t_ns:m(),seq:this._bumpSeq()}),!0)}removeById(e){let t=this._jobs.get(e);if(!t)return!1;if(t.state==="queued"){let n=this.pending.cache.indexOf(e);n>=0&&this._pending.pop(n)}return this._jobs.delete(e),this.events.append({action:"remove",id:e,attempts:t.attempts,t_ns:m(),seq:this._bumpSeq()}),!0}consumeFrom(e,t){return e.subscribe(o=>{for(let n of o){if(n[0]!==N)continue;let p=n[1];this.enqueue(p,t?{metadata:t.metadata}:void 0)}})}},w=class extends F{_stageNames;_stageWorkFns;_queues=new Map;_completed;completed;completedCount;constructor(e,t={}){super(e,t.graph);let o=t.stages??["incoming","processing","done"],n=[],p=new Map;for(let s of o){let r=typeof s=="string"?s.trim():s.name.trim();typeof s!="string"&&s.work&&p.set(r,s.work),n.push(r)}if(n.length<2)throw new Error(`jobFlow("${e}"): requires at least 2 stages`);if(new Set(n).size!==n.length)throw new Error(`jobFlow("${e}"): stage names must be unique`);this._stageNames=Object.freeze([...n]),this._stageWorkFns=p;for(let s of this._stageNames){let r=z(`${e}-${s}`);this._queues.set(s,r),this.mount(s,r)}this._completed=M([],{name:"completed",maxSize:H}),this.completed=this._completed.entries,this.add(this.completed,{name:"completed"}),this.completedCount=P([this.completed],([s])=>s.length,{name:"completedCount",describeKind:"derived",meta:T("job_flow_completed_count"),initial:0}),this.add(this.completedCount,{name:"completedCount"}),this.addDisposer(v(this.completedCount));let l=Math.max(1,W(t.maxPerPump??X,"job flow maxPerPump"));for(let s=0;s<this._stageNames.length;s+=1){let r=this._stageNames[s],d=this.queue(r),q=s+1<this._stageNames.length?this.queue(this._stageNames[s+1]):null,R=this._stageWorkFns.get(r),S=q===null;if(R){let g=x([d.pending],()=>{let c=0;for(;c<l;){let b=d.claim(1);if(b.length===0)break;let a=b[0];if(!a)break;let j=[...a.metadata.job_flow_path??[],r],f;try{f=R(a)}catch{d.nack(a.id,{requeue:!1}),c+=1;continue}let k=C(f),E=!1,u;u=k.subscribe(K=>{if(!E){for(let J of K)if(J[0]===N){E=!0,u?u():Promise.resolve().then(()=>u?.());let O=J[1],$={...a.metadata,job_flow_path:j};if(S){let U={...a,payload:O,metadata:Object.freeze($)};_(()=>{d.ack(a.id),this._completed.append(U)})}else _(()=>{d.ack(a.id),q.enqueue(O,{metadata:$})});return}else if(J[0]===A){E=!0,u?u():Promise.resolve().then(()=>u?.()),d.nack(a.id,{requeue:!1});return}}}),c+=1}},{name:`pump_${r}`,describeKind:"effect",meta:T("job_flow_pump",{stage:r,has_work:!0})});this.add(g,{name:`pump_${r}`}),this.addDisposer(v(g))}else{let g=x([d.pending],()=>{let c=0;for(;c<l;){let b=d.claim(1);if(b.length===0)break;let a=b[0];if(!a)break;let j=[...a.metadata.job_flow_path??[],r],f={...a.metadata,job_flow_path:j};if(S){let k={...a,metadata:Object.freeze(f)};_(()=>{d.ack(a.id),this._completed.append(k)})}else _(()=>{d.ack(a.id),q.enqueue(a.payload,{metadata:f})});c+=1}},{name:`pump_${r}`,describeKind:"effect",meta:T("job_flow_pump",{stage:r,has_work:!1})});this.add(g,{name:`pump_${r}`}),this.addDisposer(v(g))}}}stages(){return this._stageNames}queue(e){let t=this._queues.get(e);if(!t)throw new Error(`jobFlow("${this.name}"): unknown stage "${e}"`);return t}enqueue(e,t={}){return this.queue(this._stageNames[0]).enqueue(e,t)}retainedCompleted(){return this.completed.cache}};function z(i,e){return new y(i,e)}function Z(i,e){return new w(i,e)}export{Y as a,y as b,w as c,z as d,Z as e,ee as f};
|