@graphrefly/graphrefly 0.37.0 → 0.38.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-CZIQ6JCE.js → chunk-2YFDSYEF.js} +1 -1
- package/dist/{chunk-YVYSO5CW.js → chunk-4BDQXBXE.js} +1 -1
- package/dist/chunk-5BGFS2XH.js +1 -0
- package/dist/chunk-6773HURD.js +1 -0
- package/dist/{chunk-U3COB5WU.js → chunk-6KZZ6XQE.js} +1 -1
- package/dist/{chunk-5CPPC75H.js → chunk-6VFC334U.js} +1 -1
- package/dist/{chunk-KUVDFOJH.js → chunk-7KZZLWZ6.js} +1 -1
- package/dist/{chunk-Q7EUZ6NN.js → chunk-B5S7KTGP.js} +1 -1
- package/dist/chunk-CMTN3KPT.js +80 -0
- package/dist/chunk-DQJLC6YY.js +1 -0
- package/dist/chunk-DSOVKKTI.js +1 -0
- package/dist/chunk-FAYEMS5M.js +1 -0
- package/dist/chunk-FWGIZP3W.js +1 -0
- package/dist/{chunk-FMI4CWFL.js → chunk-G7JN6LCB.js} +1 -1
- package/dist/{chunk-PCD2MU7X.js → chunk-IBGE62GZ.js} +1 -1
- package/dist/{chunk-MYFR67PY.js → chunk-K5C67OGE.js} +1 -1
- package/dist/chunk-KJEAIIIY.js +43 -0
- package/dist/chunk-LV3ACS5J.js +1 -0
- package/dist/{chunk-LOQRPP4Y.js → chunk-NBGPXQSP.js} +1 -1
- package/dist/chunk-NN3QPJ6U.js +1 -0
- package/dist/{chunk-QWVQIL3T.js → chunk-NSAZ6PR6.js} +1 -1
- package/dist/{chunk-MC5LZG3U.js → chunk-NV63VQHI.js} +1 -1
- package/dist/{chunk-2C4NESZE.js → chunk-O245YLM5.js} +1 -1
- package/dist/{chunk-TLS7M7H4.js → chunk-O2BLVQU4.js} +1 -1
- package/dist/chunk-PHXZRR6C.js +1 -0
- package/dist/{chunk-K6ZFJ473.js → chunk-POCWFIJ7.js} +1 -1
- package/dist/{chunk-C5CBVOCB.js → chunk-QEVSIVSF.js} +1 -1
- package/dist/chunk-QMC2PLNM.js +7 -0
- package/dist/chunk-QOJFR6GS.js +1 -0
- package/dist/{chunk-MQZWA3DF.js → chunk-RZ5HKPGI.js} +1 -1
- package/dist/{chunk-WSLN4JFO.js → chunk-SFK7MN7S.js} +1 -1
- package/dist/{chunk-QP5TH523.js → chunk-SP5O2MIX.js} +1 -1
- package/dist/chunk-TB7JKSVS.js +61 -0
- package/dist/{chunk-T4U24DXX.js → chunk-TMVY7OWG.js} +1 -1
- package/dist/{chunk-UODQF4EY.js → chunk-UAXFKMAG.js} +1 -1
- package/dist/{chunk-TFK4P4CX.js → chunk-UVLZX2OU.js} +1 -1
- package/dist/chunk-XIMFHEKV.js +1 -0
- package/dist/{chunk-XIJKEXWR.js → chunk-XLMYQB6F.js} +1 -1
- package/dist/{chunk-4EATTNAE.js → chunk-XLYF4LBH.js} +1 -1
- package/dist/compat/index.cjs +9 -9
- package/dist/compat/index.d.cts +7 -7
- package/dist/compat/index.d.ts +7 -7
- package/dist/compat/index.js +1 -1
- package/dist/compat/nestjs/index.cjs +11 -11
- package/dist/compat/nestjs/index.d.cts +5 -5
- package/dist/compat/nestjs/index.d.ts +5 -5
- package/dist/compat/nestjs/index.js +1 -1
- package/dist/compat/zustand/index.cjs +7 -7
- package/dist/compat/zustand/index.d.cts +3 -3
- package/dist/compat/zustand/index.d.ts +3 -3
- package/dist/compat/zustand/index.js +1 -1
- package/dist/{composite-_XckYx2e.d.cts → composite-CgG0MqHm.d.cts} +8 -1
- package/dist/{composite-CT_mApQD.d.ts → composite-DTOlDuch.d.ts} +8 -1
- package/dist/core/index.cjs +1 -1
- package/dist/core/index.d.cts +2 -2
- package/dist/core/index.d.ts +2 -2
- package/dist/core/index.js +1 -1
- package/dist/extra/index.cjs +19 -19
- package/dist/extra/index.d.cts +5 -5
- package/dist/extra/index.d.ts +5 -5
- package/dist/extra/index.js +1 -1
- package/dist/extra/node.cjs +2 -2
- package/dist/extra/node.d.cts +107 -1
- package/dist/extra/node.d.ts +107 -1
- package/dist/extra/node.js +2 -2
- package/dist/extra/operators.cjs +1 -1
- package/dist/extra/operators.js +1 -1
- package/dist/extra/reactive.d.cts +1 -1
- package/dist/extra/reactive.d.ts +1 -1
- package/dist/extra/reactive.js +1 -1
- package/dist/extra/sources.cjs +1 -1
- package/dist/extra/sources.js +1 -1
- package/dist/extra/storage-tiers-browser.d.cts +76 -5
- package/dist/extra/storage-tiers-browser.d.ts +76 -5
- package/dist/extra/storage-tiers-node.d.cts +137 -13
- package/dist/extra/storage-tiers-node.d.ts +137 -13
- package/dist/extra/storage-tiers.d.cts +151 -23
- package/dist/extra/storage-tiers.d.ts +151 -23
- package/dist/graph/index.cjs +7 -7
- package/dist/graph/index.d.cts +4 -4
- package/dist/graph/index.d.ts +4 -4
- package/dist/graph/index.js +1 -1
- package/dist/{graph-YQXDndFy.d.ts → graph-BjW1taJl.d.ts} +217 -10
- package/dist/{graph-CaNXUc3c.d.cts → graph-CHsVwf9S.d.cts} +217 -10
- package/dist/{index-CUTHDZ7Q.d.ts → index-5dNRlW7J.d.ts} +3 -3
- package/dist/{index-Bpzw8hx3.d.ts → index-AUqWe_fX.d.ts} +7 -4
- package/dist/{index-fHKHdAso.d.ts → index-B-ORMr3k.d.ts} +2 -2
- package/dist/{index-DcWbx58m.d.cts → index-B2IUcH13.d.cts} +2 -2
- package/dist/{index-DuhOdNyg.d.ts → index-BFaALJxR.d.ts} +2 -2
- package/dist/{index-DPqR3wdW.d.ts → index-BI1wMfyc.d.ts} +2 -2
- package/dist/{index-D0ZxFXYl.d.ts → index-BUFCHvOR.d.ts} +2 -2
- package/dist/{index-CLPQyYY5.d.cts → index-BWUMIt7J.d.cts} +3 -3
- package/dist/{index-CkN8CZlT.d.cts → index-BaSy4L6w.d.cts} +37 -17
- package/dist/{index-B1IcU--K.d.cts → index-BgzPO43H.d.cts} +2 -2
- package/dist/{index-D6tRNEKz.d.cts → index-BhzwpIJc.d.cts} +1 -1
- package/dist/{index-4IwO4mH2.d.cts → index-BkQqf1EF.d.cts} +80 -7
- package/dist/{index-CajEOoAN.d.ts → index-BmWuVdER.d.ts} +2 -2
- package/dist/{index-0qOD-421.d.ts → index-Bn0uZEL4.d.ts} +2 -2
- package/dist/{index-DAKm44My.d.cts → index-BpMZzX9P.d.cts} +2 -2
- package/dist/{index-CrpjECS6.d.cts → index-Bpr0Pwgl.d.cts} +2 -2
- package/dist/{index-BECJ8M0T.d.cts → index-BqcgiSQg.d.cts} +2 -2
- package/dist/{index-DfAo9WKr.d.ts → index-BsZk9T8y.d.ts} +1 -1
- package/dist/{index-CU3z8Cel.d.cts → index-BsgxnHN8.d.cts} +2 -2
- package/dist/index-Bub6x_D4.d.cts +427 -0
- package/dist/{index-C-pFD_FV.d.ts → index-BwOsJfLJ.d.ts} +2 -2
- package/dist/{index-CRycrNfn.d.ts → index-Byp771zP.d.ts} +1 -1
- package/dist/{index-e1m3ZHgc.d.cts → index-C-3UXnHT.d.cts} +1 -1
- package/dist/{index-DTYIRT_v.d.cts → index-C56XZiDe.d.cts} +2 -2
- package/dist/{index-D11pGlaI.d.cts → index-CAV-3RpJ.d.cts} +2 -2
- package/dist/{index-D_DThl_J.d.cts → index-CAbHN_rP.d.cts} +1 -1
- package/dist/{index-BhLA9feT.d.ts → index-CEVzBWeB.d.ts} +2 -2
- package/dist/{index-Ci358GSC.d.cts → index-CM-i58FY.d.cts} +2 -2
- package/dist/{index-B9qJmmv3.d.cts → index-CQsqqEVz.d.cts} +1 -1
- package/dist/{index-C0tga1_x.d.ts → index-CijfwEWx.d.ts} +2 -2
- package/dist/{index-BwtIbzSV.d.cts → index-Ckil6miL.d.cts} +2 -2
- package/dist/{index-BokynmA4.d.cts → index-CpdnP-0y.d.cts} +1 -1
- package/dist/{index-BmLkcDlj.d.ts → index-CrlHFsiT.d.ts} +37 -17
- package/dist/{index-DCAuN9u5.d.cts → index-Czk3r0yA.d.cts} +37 -3
- package/dist/{index-C4N-dg5U.d.cts → index-D-B7U42V.d.cts} +2 -2
- package/dist/{index-CKcnuQ2c.d.ts → index-D-HZ7sP4.d.ts} +2 -2
- package/dist/{index-D6pwWiOc.d.cts → index-D7-RSD93.d.cts} +2 -2
- package/dist/{index-9mbs_PIG.d.ts → index-D9vBTuzo.d.ts} +2 -2
- package/dist/{index-C_qi0WlF.d.cts → index-DJNAWzcH.d.cts} +2 -2
- package/dist/{index-Ae6L8liv.d.ts → index-DJVQ-t07.d.ts} +2 -2
- package/dist/{index-D_d1erkR.d.ts → index-DKrIuF-r.d.ts} +2 -2
- package/dist/{index-DXz9uwcs.d.ts → index-DOU1Ee_k.d.ts} +1 -1
- package/dist/{index-D1E1tqHT.d.ts → index-DTDVDzhA.d.ts} +37 -3
- package/dist/{index-B5UR87KG.d.ts → index-DY2f2b9z.d.ts} +4 -2
- package/dist/{index-D8IyqHvT.d.cts → index-DeSsvHDD.d.cts} +4 -2
- package/dist/index-Di7OdwlO.d.ts +427 -0
- package/dist/{index-CzIWlnPp.d.ts → index-DqICM_I7.d.ts} +80 -7
- package/dist/{index-BOfHwQc1.d.ts → index-ML6vHKXK.d.ts} +1 -1
- package/dist/{index-DqtXA3yX.d.cts → index-UsU9ptzs.d.cts} +7 -4
- package/dist/{index-B46GWgk3.d.ts → index-Vz7KPfgz.d.ts} +1 -1
- package/dist/index.cjs +50 -50
- package/dist/index.d.cts +32 -32
- package/dist/index.d.ts +32 -32
- package/dist/index.js +1 -1
- package/dist/meta-BYqlATmg.d.ts +98 -0
- package/dist/meta-DreaEM_a.d.cts +98 -0
- package/dist/patterns/ai/browser.cjs +2 -2
- package/dist/patterns/ai/browser.js +1 -1
- package/dist/patterns/ai/index.cjs +21 -21
- package/dist/patterns/ai/index.d.cts +9 -9
- package/dist/patterns/ai/index.d.ts +9 -9
- package/dist/patterns/ai/index.js +1 -1
- package/dist/patterns/ai/node.js +1 -1
- package/dist/patterns/audit/index.cjs +7 -7
- package/dist/patterns/audit/index.d.cts +5 -5
- package/dist/patterns/audit/index.d.ts +5 -5
- package/dist/patterns/audit/index.js +1 -1
- package/dist/patterns/cqrs/index.cjs +7 -7
- package/dist/patterns/cqrs/index.d.cts +4 -4
- package/dist/patterns/cqrs/index.d.ts +4 -4
- 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 +4 -4
- package/dist/patterns/demo-shell/index.d.ts +4 -4
- 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 +3 -3
- package/dist/patterns/domain-templates/index.d.ts +3 -3
- package/dist/patterns/domain-templates/index.js +1 -1
- package/dist/patterns/graphspec/index.cjs +21 -21
- package/dist/patterns/graphspec/index.d.cts +3 -3
- package/dist/patterns/graphspec/index.d.ts +3 -3
- 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 +6 -6
- package/dist/patterns/guarded-execution/index.d.ts +6 -6
- package/dist/patterns/guarded-execution/index.js +1 -1
- package/dist/patterns/harness/index.cjs +12 -12
- package/dist/patterns/harness/index.d.cts +8 -8
- package/dist/patterns/harness/index.d.ts +8 -8
- 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 +4 -4
- package/dist/patterns/job-queue/index.d.ts +4 -4
- package/dist/patterns/job-queue/index.js +1 -1
- package/dist/patterns/lens/index.cjs +7 -7
- package/dist/patterns/lens/index.d.cts +4 -4
- package/dist/patterns/lens/index.d.ts +4 -4
- package/dist/patterns/lens/index.js +1 -1
- package/dist/patterns/memory/index.cjs +7 -7
- package/dist/patterns/memory/index.d.cts +6 -4
- package/dist/patterns/memory/index.d.ts +6 -4
- package/dist/patterns/memory/index.js +1 -1
- package/dist/patterns/messaging/index.cjs +7 -7
- package/dist/patterns/messaging/index.d.cts +4 -4
- package/dist/patterns/messaging/index.d.ts +4 -4
- package/dist/patterns/messaging/index.js +1 -1
- package/dist/patterns/orchestration/index.cjs +7 -7
- package/dist/patterns/orchestration/index.d.cts +4 -4
- package/dist/patterns/orchestration/index.d.ts +4 -4
- package/dist/patterns/orchestration/index.js +1 -1
- package/dist/patterns/process/index.d.cts +5 -5
- package/dist/patterns/process/index.d.ts +5 -5
- 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 +4 -4
- package/dist/patterns/reactive-layout/index.d.ts +4 -4
- package/dist/patterns/reactive-layout/index.js +1 -1
- package/dist/patterns/reduction/index.cjs +7 -7
- package/dist/patterns/reduction/index.d.cts +3 -3
- package/dist/patterns/reduction/index.d.ts +3 -3
- 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 +5 -5
- package/dist/patterns/refine-loop/index.d.ts +5 -5
- package/dist/patterns/refine-loop/index.js +1 -1
- package/dist/patterns/resilient-pipeline/index.cjs +1 -1
- package/dist/patterns/resilient-pipeline/index.d.cts +4 -4
- package/dist/patterns/resilient-pipeline/index.d.ts +4 -4
- package/dist/patterns/resilient-pipeline/index.js +1 -1
- package/dist/patterns/surface/index.cjs +14 -14
- package/dist/patterns/surface/index.d.cts +4 -4
- package/dist/patterns/surface/index.d.ts +4 -4
- package/dist/patterns/surface/index.js +1 -1
- package/dist/{pipeline-graph-DX2Twdj-.d.ts → pipeline-graph-9JBbmRxA.d.ts} +2 -2
- package/dist/{pipeline-graph-BrrYGjuZ.d.cts → pipeline-graph-DuHpXSOn.d.cts} +2 -2
- package/dist/{reactive-layout-DrGjuwyC.d.cts → reactive-layout-BMLDB4Vd.d.cts} +1 -1
- package/dist/{reactive-layout-BDdngW56.d.ts → reactive-layout-D-tRiNhg.d.ts} +1 -1
- package/dist/{reactive-log-jirQsxMY.d.ts → reactive-log-BgWSA1fg.d.ts} +28 -1
- package/dist/{reactive-log-ScpWyqny.d.cts → reactive-log-C3IMAGpT.d.cts} +28 -1
- package/dist/resilience-LGBK236C.js +1 -0
- package/dist/{topology-tree-BI665P0L.d.ts → topology-tree-D47-nI6Z.d.ts} +1 -1
- package/dist/{topology-tree-BkhmMg2a.d.cts → topology-tree-jrZue3ao.d.cts} +1 -1
- package/package.json +1 -1
- package/dist/chunk-533RQFF6.js +0 -1
- package/dist/chunk-6SVKZ7VI.js +0 -1
- package/dist/chunk-A5HZZYRK.js +0 -1
- package/dist/chunk-B4L5X2QO.js +0 -7
- package/dist/chunk-FJ6IEMOS.js +0 -1
- package/dist/chunk-G6Q3DUMJ.js +0 -1
- package/dist/chunk-GDDPCDLG.js +0 -1
- package/dist/chunk-GFOT6UBB.js +0 -1
- package/dist/chunk-JJTF75VS.js +0 -1
- package/dist/chunk-K2WYIVHM.js +0 -1
- package/dist/chunk-KTWBUJO5.js +0 -61
- package/dist/chunk-M27MVZCP.js +0 -1
- package/dist/chunk-NKKUUKPD.js +0 -43
- package/dist/chunk-QKBCTKH7.js +0 -1
- package/dist/chunk-WGST56ZH.js +0 -80
- package/dist/index-BCq12BqB.d.ts +0 -139
- package/dist/index-DbWwMWiB.d.cts +0 -139
- package/dist/meta-BGO6C7K9.d.cts +0 -41
- package/dist/meta-CC6EPdpK.d.ts +0 -41
- package/dist/resilience-OBU472D2.js +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
import{a,b,c,d,e,f}from"../../chunk-
|
|
1
|
+
import{a,b,c,d,e,f}from"../../chunk-XLYF4LBH.js";import"../../chunk-6KZZ6XQE.js";import"../../chunk-O32GJOUJ.js";import"../../chunk-NSAZ6PR6.js";import"../../chunk-PHXZRR6C.js";import"../../chunk-QMC2PLNM.js";import"../../chunk-SGS4OJGS.js";import"../../chunk-ESMPEKEV.js";import"../../chunk-DQJLC6YY.js";import"../../chunk-7KZZLWZ6.js";import"../../chunk-RZ5HKPGI.js";import"../../chunk-LYCLF26R.js";import"../../chunk-CK2E7BTU.js";import"../../chunk-QYADASLV.js";export{a as AuditTrailGraph,c as PolicyEnforcerGraph,b as auditTrail,f as complianceSnapshot,d as policyEnforcer,e as reactiveExplainPath};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
"use strict";var ht=Object.defineProperty;var Dn=Object.getOwnPropertyDescriptor;var Mn=Object.getOwnPropertyNames;var Gn=Object.prototype.hasOwnProperty;var J=(t,e)=>()=>(t&&(e=t(t=0)),e);var Ln=(t,e)=>{for(var n in e)ht(t,n,{get:e[n],enumerable:!0})},In=(t,e,n,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let s of Mn(e))!Gn.call(t,s)&&s!==n&&ht(t,s,{get:()=>e[s],enumerable:!(r=Dn(e,s))||r.enumerable});return t};var Pn=t=>In(ht({},"__esModule",{value:!0}),t);function Fe(){return ve>0||ke}function It(){return ve>0}function Ce(t){ve>0?Ae.push(t):t()}function we(t){ve+=1;let e=!1;try{t()}catch(n){throw e=!0,n}finally{if(ve-=1,ve===0)if(e){if(!ke){let n=Ae.splice(0);for(let r of n)try{r()}catch{}le.length=0,fe.length=0,_e.length=0}}else $n()}}function $n(){let t=!ke;t&&(ke=!0);let e=[],n=0;try{for(;le.length>0||fe.length>0||_e.length>0||t&&Ae.length>0;){if(t&&Ae.length>0){let o=Ae.splice(0);for(let i of o)try{i()}catch(a){e.push(a)}continue}if(n+=1,n>1e3)throw le.length=0,fe.length=0,_e.length=0,new Error("batch drain exceeded 1000 iterations \u2014 likely a reactive cycle");let s=(le.length>0?le:fe.length>0?fe:_e).splice(0);for(let o of s)try{o()}catch(i){e.push(i)}}}finally{t&&(ke=!1)}if(e.length===1)throw e[0];if(e.length>1)throw new AggregateError(e,"batch drain: multiple callbacks threw")}function ze(t,e,n){if(e.length===0)return;if(e.length===1){let d=n(e[0][0]);if(d<3||!Fe()){t(e);return}(d>=5?_e:d===4?fe:le).push(()=>t(e));return}let r=e.length,s=r,o=r,i=r,a=0;for(;a<r&&n(e[a][0])<3;)a++;for(s=a;a<r&&n(e[a][0])===3;)a++;for(o=a;a<r&&n(e[a][0])===4;)a++;i=a;let u=Fe();if(s>0){let d=e.slice(0,s);t(d)}if(o>s){let d=e.slice(s,o);u?le.push(()=>t(d)):t(d)}if(i>o){let d=e.slice(o,i);u?fe.push(()=>t(d)):t(d)}if(r>i){let d=e.slice(i,r);u?_e.push(()=>t(d)):t(d)}}var ve,ke,le,fe,_e,Ae,De=J(()=>{"use strict";ve=0,ke=!1,le=[],fe=[],_e=[],Ae=[]});function xe(){return Math.trunc(performance.now()*1e6)}function ne(){return Date.now()*1e6}var Be=J(()=>{"use strict"});function Pt(t){return Array.isArray(t)?[...t]:[t]}function Vn(t,e){return t.has(e)||t.has("*")}function Te(t){let e=[];return t((s,o)=>{e.push({kind:"allow",actions:new Set(Pt(s)),where:o?.where??(()=>!0)})},(s,o)=>{e.push({kind:"deny",actions:new Set(Pt(s)),where:o?.where??(()=>!0)})}),(s,o)=>{let i=!1,a=!1;for(let u of e)Vn(u.actions,o)&&u.where(s)&&(u.kind==="deny"?i=!0:a=!0);return i?!1:a}}function gt(t){let e=Fn.filter(n=>t({type:n,id:""},"write"));return e.length===0?"restricted":e.includes("human")&&e.includes("llm")&&e.every(n=>n==="human"||n==="llm"||n==="system")?"both":e.length===1?e[0]:e.join("+")}var X,Fn,pe=J(()=>{"use strict";X=class extends Error{actor;action;nodeName;constructor(e,n){super(n??`GuardDenied: action "${String(e.action)}" denied for actor type "${String(e.actor.type)}"`),this.name="GuardDenied",this.actor=e.actor,this.action=e.action,this.nodeName=e.nodeName}get node(){return this.nodeName}};Fn=["human","llm","wallet","system"]});function je(t){if(t==null)return Ee;let{type:e,id:n,...r}=t;return{type:e??"system",id:n??"",...r}}var Ee,He=J(()=>{"use strict";Ee={type:"system",id:""}});var Oe,P,q,U,Z,te,re,B,H,$,he,qe,$t,Ue,Vt,Ft,We,mt,yt,bt,Ke,Se=J(()=>{"use strict";Oe=Symbol.for("graphrefly/START"),P=Symbol.for("graphrefly/DATA"),q=Symbol.for("graphrefly/DIRTY"),U=Symbol.for("graphrefly/RESOLVED"),Z=Symbol.for("graphrefly/INVALIDATE"),te=Symbol.for("graphrefly/PAUSE"),re=Symbol.for("graphrefly/RESUME"),B=Symbol.for("graphrefly/TEARDOWN"),H=Symbol.for("graphrefly/COMPLETE"),$=Symbol.for("graphrefly/ERROR"),he=Object.freeze([q]),qe=Object.freeze([U]),$t=Object.freeze([Z]),Ue=Object.freeze([Oe]),Vt=Object.freeze([H]),Ft=Object.freeze([B]),We=Object.freeze([he]),mt=Object.freeze([qe]),yt=Object.freeze([$t]),bt=Object.freeze([Vt]),Ke=Object.freeze([Ft])});function zt(t){t.registerMessageType(Oe,{tier:0,wireCrossing:!1}),t.registerMessageType(q,{tier:1,wireCrossing:!1}),t.registerMessageType(Z,{tier:1,wireCrossing:!1,metaPassthrough:!1}),t.registerMessageType(te,{tier:2,wireCrossing:!1}),t.registerMessageType(re,{tier:2,wireCrossing:!1}),t.registerMessageType(P,{tier:3,wireCrossing:!0}),t.registerMessageType(U,{tier:3,wireCrossing:!0}),t.registerMessageType(H,{tier:4,wireCrossing:!0,metaPassthrough:!1}),t.registerMessageType($,{tier:4,wireCrossing:!0,metaPassthrough:!1}),t.registerMessageType(B,{tier:5,wireCrossing:!0,metaPassthrough:!1})}var Ye,Bt=J(()=>{"use strict";Se();Ye=class{_messageTypes=new Map;_codecs=new Map;_onMessage;_onSubscribe;_defaultVersioning;_defaultHashFn;_inspectorEnabled=!(typeof process<"u"&&process.env?.NODE_ENV==="production");_globalInspector;_rigorRecorder;_frozen=!1;tierOf;constructor(e){this._onMessage=e.onMessage,this._onSubscribe=e.onSubscribe,this._defaultVersioning=e.defaultVersioning,this._defaultHashFn=e.defaultHashFn,this.tierOf=n=>{let r=this._messageTypes.get(n);return r!=null?r.tier:1}}get onMessage(){return this._frozen=!0,this._onMessage}get onSubscribe(){return this._frozen=!0,this._onSubscribe}set onMessage(e){this._assertUnfrozen(),this._onMessage=e}set onSubscribe(e){this._assertUnfrozen(),this._onSubscribe=e}get defaultVersioning(){return this._defaultVersioning}set defaultVersioning(e){this._assertUnfrozen(),this._defaultVersioning=e}get defaultHashFn(){return this._defaultHashFn}set defaultHashFn(e){this._assertUnfrozen(),this._defaultHashFn=e}get inspectorEnabled(){return this._inspectorEnabled}set inspectorEnabled(e){this._inspectorEnabled=e}get globalInspector(){return this._globalInspector}set globalInspector(e){this._globalInspector=e}get rigorRecorder(){return this._rigorRecorder}set rigorRecorder(e){this._rigorRecorder=e}registerMessageType(e,n){return this._assertUnfrozen(),this._messageTypes.set(e,{tier:n.tier,wireCrossing:n.wireCrossing??n.tier>=3,metaPassthrough:n.metaPassthrough??!0}),this}messageTier(e){let n=this._messageTypes.get(e);return n!=null?n.tier:1}isWireCrossing(e){let n=this._messageTypes.get(e);return n!=null?n.wireCrossing:!0}isLocalOnly(e){return!this.isWireCrossing(e)}isMetaPassthrough(e){let n=this._messageTypes.get(e);return n!=null?n.metaPassthrough:!0}isKnownMessageType(e){return this._messageTypes.has(e)}registerCodec(e){return this._assertUnfrozen(),this._codecs.set(e.name,e),this}lookupCodec(e){return this._codecs.get(e)}_isFrozen(){return this._frozen}_assertUnfrozen(){if(this._frozen)throw new Error("GraphReFlyConfig is frozen: a node has already captured this config. Register custom types and set hooks before creating any node.")}}});function Ht(t,e){let n=new TextEncoder().encode(t.name);if(n.length===0||n.length>255)throw new Error(`encodeEnvelope: codec name "${t.name}" encodes to ${n.length} bytes (must be 1\u2013255)`);let r=t.version;if(!Number.isInteger(r)||r<0||r>65535)throw new Error(`encodeEnvelope: codec.version ${r} out of u16 range (expected integer 0\u201365535)`);let s=2+n.length+2+e.length;if(s>4294967295)throw new Error(`encodeEnvelope: total envelope size ${s} exceeds 2^32-1 bytes (payload ${e.length} bytes)`);let o=new Uint8Array(s),i=0;return o[i++]=vt,o[i++]=n.length,o.set(n,i),i+=n.length,o[i++]=r>>>8&255,o[i++]=r&255,o.set(e,i),o}function qt(t,e){if(t.length<jt)throw new Error(`decodeEnvelope: bytes too short (${t.length} < ${jt})`);let n=0,r=t[n++];if(r!==vt)throw new Error(`decodeEnvelope: unsupported envelope version ${r} (expected ${vt})`);let s=t[n++];if(s===0)throw new Error("decodeEnvelope: name_len must be >= 1");if(n+s+2>t.length)throw new Error(`decodeEnvelope: envelope truncated (need ${n+s+2} bytes, have ${t.length})`);let o=new TextDecoder().decode(t.subarray(n,n+s));n+=s;let i=(t[n]<<8|t[n+1])>>>0;n+=2;let a=t.subarray(n),u=e.lookupCodec(o);if(u==null)throw new Error(`decodeEnvelope: codec "${o}" not registered (envelope codec_v=${i})`);return{codec:u,codecVersion:i,payload:a}}function Ut(t){t.registerCodec(zn)}var zn,vt,jt,_t=J(()=>{"use strict";zn={name:"json",version:1,contentType:"application/json",encode(t){let e=JSON.stringify(t);return new TextEncoder().encode(e)},decode(t,e){let n=new TextDecoder().decode(t);return JSON.parse(n)}},vt=1,jt=4});function wt(t){if(t===void 0)return null;if(typeof t=="number"){if(!Number.isFinite(t))throw new TypeError(`Cannot hash non-finite number: ${t}`);if(Number.isInteger(t)&&!Number.isSafeInteger(t))throw new TypeError(`Cannot hash integer outside safe range (|n| > 2^53-1): ${t}. Cross-language cid parity is not guaranteed for unsafe integers.`);return t}if(typeof t=="string"||typeof t=="boolean"||t===null)return t;if(Array.isArray(t))return t.map(wt);if(typeof t=="object"&&t!==null){let e={};for(let n of Object.keys(t).sort())e[n]=wt(t[n]);return e}return null}function Hn(t){let e=jn.encode(t),n=e.length,r=n*8,s=n+9+63&-64,o=new Uint8Array(s);o.set(e),o[n]=128;let i=new DataView(o.buffer);i.setUint32(s-4,r>>>0,!1),i.setUint32(s-8,Math.floor(r/4294967296)>>>0,!1);let a=1779033703,u=3144134277,d=1013904242,c=2773480762,h=1359893119,p=2600822924,f=528734635,l=1541459225,m=new Uint32Array(64),T=(w,y)=>w>>>y|w<<32-y;for(let w=0;w<s;w+=64){for(let _=0;_<16;_++)m[_]=i.getUint32(w+_*4,!1);for(let _=16;_<64;_++){let O=m[_-15],k=m[_-2],C=T(O,7)^T(O,18)^O>>>3,D=T(k,17)^T(k,19)^k>>>10;m[_]=m[_-16]+C+m[_-7]+D>>>0}let y=a,v=u,R=d,E=c,g=h,b=p,S=f,x=l;for(let _=0;_<64;_++){let O=T(g,6)^T(g,11)^T(g,25),k=g&b^~g&S,C=x+O+k+Bn[_]+m[_]>>>0,D=T(y,2)^T(y,13)^T(y,22),G=y&v^y&R^v&R,z=D+G>>>0;x=S,S=b,b=g,g=E+C>>>0,E=R,R=v,v=y,y=C+z>>>0}a=a+y>>>0,u=u+v>>>0,d=d+R>>>0,c=c+E>>>0,h=h+g>>>0,p=p+b>>>0,f=f+S>>>0,l=l+x>>>0}let N=w=>w.toString(16).padStart(8,"0");return N(a)+N(u)+N(d)+N(c)+N(h)+N(p)+N(f)+N(l)}function xt(t){let e=wt(t??null),n=JSON.stringify(e);return Hn(n).slice(0,16)}function qn(){let t=globalThis.crypto;if(t?.randomUUID)return t.randomUUID();let e=()=>Math.floor(Math.random()*4294967296).toString(16).padStart(8,"0"),n=e()+e()+e()+e();return`${n.slice(0,8)}-${n.slice(8,12)}-4${n.slice(13,16)}-${(parseInt(n.slice(16,17),16)&3|8).toString(16)}${n.slice(17,20)}-${n.slice(20,32)}`}function Tt(t,e,n){let r=n?.id??qn();if(t===0)return{id:r,version:0};let o=(n?.hash??xt)(e);return{id:r,version:0,cid:o,prev:null}}function Wt(t,e,n){t.version+=1,"cid"in t&&(t.prev=t.cid,t.cid=n(e))}var Bn,jn,Kt=J(()=>{"use strict";Bn=new Uint32Array([1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298]),jn=new TextEncoder});function Xt(t){return{node:t,unsub:null,prevData:void 0,dirty:!1,involvedThisWave:!1,dataBatch:[],terminal:void 0}}function Et(t){t.prevData=void 0,t.dirty=!1,t.involvedThisWave=!1,t.dataBatch.length=0,t.terminal=void 0}function Je(t){return t.length===0?t:typeof t[0]=="symbol"?[t]:t}function se(t,e,n){let r=Zt(t)?t:[],s=typeof t=="function"?t:typeof e=="function"?e:void 0,o={};return Zt(t)?o=(Ot(e)?e:n)??{}:Ot(t)?o=t:o=(Ot(e)?e:n)??{},new V(r,s,o)}var Yt,Jt,Un,Wn,ge,V,Zt,Ot,me=J(()=>{"use strict";_t();He();De();Be();Bt();pe();Se();Kt();Yt=()=>{},Jt=100;Un=(t,e,n,r)=>{n.direction==="down-in"&&t._onDepMessage(n.depIndex,e)},Wn=(t,e,n,r)=>{let s=t;if(s._status==="completed"||s._status==="errored")return;let o=s._cached,i=o===void 0?[Ue]:[Ue,[P,o]];s._status==="dirty"&&i.push(he),ze(e,i,s._config.tierOf)},ge=new Ye({onMessage:Un,onSubscribe:Wn});zt(ge);Ut(ge);V=class t{_optsName;_describeKind;meta;_hasMeta;_config;_deps;_sinks=null;_sinkCount=0;_cached;_status;_cleanup;_store={};_waveHasNewData=!1;_hasNewTerminal=!1;_hasCalledFnOnce=!1;_paused=!1;_pendingWave=!1;_isExecutingFn=!1;_pendingRerun=!1;_rerunDepth=0;_dirtyDepCount=0;_batchPendingMessages=null;_pauseLocks=null;_pauseBuffer=null;_fn;_equals;_resubscribable;_resetOnTeardown;_autoComplete;_autoError;_pausable;_partial;_guard;_extraGuards;_hashFn;_versioning;_versioningLevel;_lastMutation;_inspectorHooks;_actions;constructor(e,n,r){this._config=r.config??ge,this._config.onMessage,this._optsName=r.name,this._describeKind=r.describeKind,this._equals=r.equals??Object.is,this._resubscribable=r.resubscribable??!1,this._resetOnTeardown=r.resetOnTeardown??!1,this._autoComplete=r.completeWhenDepsComplete??!0,this._autoError=r.errorWhenDepsError??!0,this._pausable=r.pausable??!0,this._guard=r.guard,this._fn=n,this._partial=r.partial??!1,this._cached=r.initial!==void 0?r.initial:void 0,this._status=e.length===0&&n==null&&this._cached!==void 0?"settled":"sentinel",this._hashFn=r.versioningHash??this._config.defaultHashFn??xt;let s=r.versioning??this._config.defaultVersioning;this._versioningLevel=s,this._versioning=s!=null?Tt(s,this._cached===void 0?void 0:this._cached,{id:r.versioningId,hash:this._hashFn}):void 0,this._deps=e.map(Xt);let o={};for(let[a,u]of Object.entries(r.meta??{})){let d={initial:u,name:`${r.name??"node"}:meta:${a}`,describeKind:"state",config:this._config};r.guard!=null&&(d.guard=r.guard),o[a]=new t([],void 0,d)}Object.freeze(o),this.meta=o,this._hasMeta=Object.keys(o).length>0;let i=this;this._actions={emit(a){i._emit([[P,a]])},down(a){i._emit(Je(a))},up(a){i._emitUp(Je(a))}},this.down=this.down.bind(this),this.up=this.up.bind(this)}get _isTerminal(){return this._status==="completed"||this._status==="errored"}get name(){return this._optsName}get status(){return this._status}get cache(){return this._cached===void 0?void 0:this._cached}get lastMutation(){return this._lastMutation}get v(){return this._versioning}hasGuard(){return this._guard!=null}_applyVersioning(e,n){if(this._isExecutingFn)throw new Error(`Node "${this.name}": _applyVersioning cannot run mid-fn \u2014 call it outside of \`_execFn\` (typically at graph setup time before the first subscribe).`);let r=this._versioningLevel;if(r!=null&&e<=r)return;let s=n?.hash??this._hashFn;s!==this._hashFn&&(this._hashFn=s);let o=this._cached===void 0?void 0:this._cached,i=this._versioning,a=i?.id??n?.id,u=i?.version??0,d=Tt(e,o,{id:a,hash:s});d.version=u,this._versioning=d,this._versioningLevel=e}_setInspectorHook(e){return e==null?()=>{}:(this._inspectorHooks==null&&(this._inspectorHooks=new Set),this._inspectorHooks.add(e),()=>{this._inspectorHooks?.delete(e),this._inspectorHooks?.size===0&&(this._inspectorHooks=void 0)})}_pushGuard(e){return this._extraGuards==null&&(this._extraGuards=new Set),this._extraGuards.add(e),()=>{this._extraGuards?.delete(e),this._extraGuards?.size===0&&(this._extraGuards=void 0)}}allowsObserve(e){if(this._guard==null&&this._extraGuards==null)return!0;let n=je(e);if(this._guard!=null&&!this._guard(n,"observe"))return!1;if(this._extraGuards!=null){for(let r of this._extraGuards)if(!r(n,"observe"))return!1}return!0}_checkGuard(e){if(e?.internal)return;let n=this._guard!=null||this._extraGuards!=null,r=e?.actor!=null;if(!n&&!r)return;let s=je(e?.actor),o=e?.delivery==="signal"?"signal":"write";if(this._guard!=null&&!this._guard(s,o))throw new X({actor:s,action:o,nodeName:this.name});if(this._extraGuards!=null){for(let i of this._extraGuards)if(!i(s,o))throw new X({actor:s,action:o,nodeName:this.name})}this._lastMutation={actor:s,timestamp_ns:ne()}}down(e,n){let r=Je(e);r.length!==0&&(this._checkGuard(n),this._emit(r))}emit(e,n){this._checkGuard(n),this._emit([[P,e]])}up(e,n){if(this._deps.length===0)return;let r=Je(e);if(r.length===0)return;this._checkGuard(n);let s=n??{internal:!0};this._validateUpTiers(r);for(let o of this._deps)o.node.up?.(r,s)}_emitUp(e){if(this._deps.length!==0&&e.length!==0){this._validateUpTiers(e);for(let n of this._deps)n.node.up?.(e,{internal:!0})}}_validateUpTiers(e){let n=this._config.tierOf;for(let r of e){let s=n(r[0]);if(s===3||s===4)throw new Error(`Node "${this.name}": tier-${s} messages cannot flow up \u2014 DATA/RESOLVED/COMPLETE/ERROR are downstream-only. Use \`down(...)\` for value delivery; \`up(...)\` is for control signals (DIRTY, INVALIDATE, PAUSE, RESUME, TEARDOWN).`)}}subscribe(e,n){if(n!=null&&this._guard!=null){let u=je(n);if(!this._guard(u,"observe"))throw new X({actor:u,action:"observe",nodeName:this.name})}let s=this._isTerminal&&this._resubscribable;if(s){this._cached=void 0,this._status="sentinel",this._store={},this._hasCalledFnOnce=!1,this._waveHasNewData=!1,this._hasNewTerminal=!1,this._paused=!1,this._pendingWave=!1,this._pendingRerun=!1,this._isExecutingFn=!1,this._rerunDepth=0,this._dirtyDepCount=0,this._pauseLocks=null,this._pauseBuffer=null;for(let u of this._deps)Et(u);if(this._partial===!1){for(let u of this._deps)if(u.prevData!==void 0||u.dataBatch.length!==0||u.terminal!==void 0||u.dirty)throw new Error(`resubscribable-reset invariant: DepRecord not fully reset for node ${this._optsName??"(anonymous)"}`)}}this._sinkCount+=1;let o;try{o=this._config.onSubscribe(this,e,{sinkCount:this._sinkCount,afterTerminalReset:s},this._actions)}catch(u){throw this._sinkCount-=1,u}this._sinks==null?this._sinks=e:typeof this._sinks=="function"?this._sinks=new Set([this._sinks,e]):this._sinks.add(e);let i=this._isTerminal;if(this._sinkCount===1&&!i)try{this._activate()}catch(u){if(this._sinkCount-=1,this._removeSink(e),this._sinkCount===0&&(this._status="sentinel"),typeof o=="function")try{o()}catch{}throw u}this._status==="sentinel"&&this._cached===void 0&&(this._status="pending");let a=!1;return()=>{a||(a=!0,this._sinkCount-=1,this._removeSink(e),typeof o=="function"&&o(),this._sinks==null&&this._deactivate())}}_removeSink(e){if(this._sinks===e)this._sinks=null;else if(this._sinks!=null&&typeof this._sinks!="function")if(this._sinks.delete(e),this._sinks.size===1){let[n]=this._sinks;this._sinks=n}else this._sinks.size===0&&(this._sinks=null)}_activate(){if(this._deps.length===0){this._fn&&this._execFn();return}this._dirtyDepCount=0;let e=this._deps.length,n=0;try{for(let r=0;r<e;r++){let s=r,o=this._deps[r];o.unsub=Yt,o.unsub=o.node.subscribe(i=>{if(o.unsub===null)return;let a=this._config.tierOf,u=!1;for(let d of i)a(d[0])>=3&&(u=!0),this._config.onMessage(this,d,{direction:"down-in",depIndex:s},this._actions);u&&this._maybeRunFnOnSettlement()}),n++}}catch(r){this._deps[n].unsub=null;for(let s=0;s<n;s++){let o=this._deps[s];if(o.unsub!=null){let i=o.unsub;o.unsub=null;try{i()}catch{}Et(o)}}throw this._dirtyDepCount=0,r}}_addDep(e){for(let s=0;s<this._deps.length;s++)if(this._deps[s].node===e)return s;let n=this._deps.length,r=Xt(e);if(this._deps.push(r),this._sinks==null)return n;r.dirty=!0,this._dirtyDepCount++,this._status!=="dirty"&&this._emit(We),r.unsub=Yt;try{r.unsub=e.subscribe(s=>{if(r.unsub===null)return;let o=this._config.tierOf,i=!1;for(let a of s)o(a[0])>=3&&(i=!0),this._config.onMessage(this,a,{direction:"down-in",depIndex:n},this._actions);i&&this._maybeRunFnOnSettlement()})}catch(s){throw r.unsub=null,this._deps.pop(),this._dirtyDepCount--,s}return n}_deactivate(e=!1){let n=this._cleanup;if(this._cleanup=void 0,typeof n=="function")try{n()}catch(r){this._emit([[$,this._wrapFnError("cleanup threw",r)]])}else if(n!=null&&typeof n=="object"){let r=n.deactivate;if(typeof r=="function")try{r()}catch(s){this._emit([[$,this._wrapFnError("cleanup.deactivate threw",s)]])}}for(let r of this._deps){if(r.unsub!=null){let s=r.unsub;r.unsub=null;try{s()}catch{}}Et(r)}this._waveHasNewData=!1,this._hasNewTerminal=!1,this._hasCalledFnOnce=!1,this._paused=!1,this._pendingWave=!1,this._pendingRerun=!1,this._rerunDepth=0,this._store={},this._dirtyDepCount=0,this._pauseLocks=null,this._pauseBuffer=null,this._fn!=null&&(this._cached=void 0),e||(this._fn!=null||this._deps.length>0)&&(!this._isTerminal||this._resubscribable)&&(this._status="sentinel")}_onDepMessage(e,n){let r=this._deps[e],s=n[0];if(this._inspectorHooks!=null){let o={kind:"dep_message",depIndex:e,message:n};for(let i of this._inspectorHooks)i(o)}if(s!==Oe){if(s===q){this._depDirtied(r);return}if(s===Z){if(this._depInvalidated(r),this._cached===void 0)return;this._emit(yt);return}if(s===te||s===re){this._emit([n]);return}if(s===B){this._emit(Ke);return}if(s===P)this._depSettledAsData(r,n[1]);else if(s===U)this._depSettledAsResolved(r);else if(s===H)this._depSettledAsTerminal(r,!0);else if(s===$)this._depSettledAsTerminal(r,n[1]);else{this._emit([n]);return}if(!this._fn){(s===P||s===U)&&this._emit([n]),(s===H||s===$)&&this._maybeAutoTerminalAfterWave();return}}}_depDirtied(e){e.dirty||(e.dirty=!0,e.involvedThisWave=!0,this._dirtyDepCount++,this._status!=="dirty"&&this._emit(We))}_depSettledAsData(e,n){e.dirty&&(e.dirty=!1,this._dirtyDepCount--),e.involvedThisWave=!0,e.dataBatch.push(n),this._waveHasNewData=!0}_depSettledAsResolved(e){e.dirty&&(e.dirty=!1,this._dirtyDepCount--)}_depSettledAsTerminal(e,n){e.dirty&&(e.dirty=!1,this._dirtyDepCount--),e.terminal=n,e.involvedThisWave=!0,this._hasNewTerminal=!0}_depInvalidated(e){e.prevData=void 0,e.terminal=void 0,e.dataBatch.length=0,e.dirty?e.involvedThisWave=!1:(e.dirty=!0,e.involvedThisWave=!0,this._dirtyDepCount++)}_maybeRunFnOnSettlement(){if(!(this._isTerminal&&!this._resubscribable)&&!(this._dirtyDepCount>0)){if(!this._partial&&!this._hasCalledFnOnce)for(let e=0;e<this._deps.length;e++){let n=this._deps[e];if(n.dataBatch.length===0&&n.prevData===void 0&&n.terminal===void 0){this._maybeAutoTerminalAfterWave();return}}if(this._paused){this._pendingWave=!0;return}if(!this._waveHasNewData&&!this._hasNewTerminal&&this._hasCalledFnOnce){this._clearWaveFlags(),this._emit(mt),this._maybeAutoTerminalAfterWave();return}this._fn&&this._execFn(),this._maybeAutoTerminalAfterWave()}}_maybeAutoTerminalAfterWave(){if(this._deps.length===0||this._isTerminal)return;let e=this._deps.find(n=>n.terminal!==void 0&&n.terminal!==!0);if(e!=null){this._autoError&&this._emit([[$,e.terminal]]);return}this._autoComplete&&this._deps.every(n=>n.terminal!==void 0)&&this._emit(bt)}_execFn(){if(!this._fn||this._isTerminal&&!this._resubscribable)return;if(this._isExecutingFn){this._pendingRerun=!0;return}let e=this._cleanup;if(typeof e=="function"){this._cleanup=void 0;try{e()}catch(i){this._emit([[$,this._wrapFnError("cleanup threw",i)]]);return}}else if(e!=null&&typeof e=="object"){let i=e.beforeRun;if(typeof i=="function"){e.beforeRun=void 0;try{i()}catch(a){this._emit([[$,this._wrapFnError("cleanup.beforeRun threw",a)]]);return}}}let n=this._deps.map(i=>i.involvedThisWave?i.dataBatch.length>0?[...i.dataBatch]:[]:void 0),r=this._deps.map(i=>i.prevData);for(let i=0;i<this._deps.length;i++){let a=n[i];a!=null&&a.length>0&&(this._deps[i].prevData=a[a.length-1])}let s=this._deps.map(i=>i.terminal),o={prevData:r,terminalDeps:s,store:this._store};if(this._hasCalledFnOnce=!0,this._clearWaveFlags(),this._inspectorHooks!=null){let i={kind:"run",batchData:n,prevData:r};for(let a of this._inspectorHooks)a(i)}this._isExecutingFn=!0;try{let i=this._fn(n,this._actions,o);if(typeof i=="function")this._cleanup=i;else if(i!=null&&typeof i=="object"){let a=i;(typeof a.beforeRun=="function"||typeof a.deactivate=="function"||typeof a.invalidate=="function")&&(this._cleanup=i)}}catch(i){this._emit([[$,this._wrapFnError("fn threw",i)]])}finally{this._isExecutingFn=!1,this._pendingRerun?(this._pendingRerun=!1,this._rerunDepth+=1,this._rerunDepth>Jt?(this._rerunDepth=0,this._emit([[$,new Error(`Node "${this.name}": _pendingRerun depth exceeded ${Jt} \u2014 likely a reactive cycle`)]])):this._maybeRunFnOnSettlement()):this._rerunDepth=0,this._clearWaveFlags()}}_clearWaveFlags(){this._waveHasNewData=!1,this._hasNewTerminal=!1;for(let e of this._deps)e.involvedThisWave=!1,e.dataBatch.length=0}_wrapFnError(e,n){let r=n instanceof Error?n.message:String(n);return new Error(`Node "${this.name}": ${e}: ${r}`,{cause:n})}_frameBatch(e){let n=this._config.tierOf;if(e.length===1)return n(e[0][0])===3&&this._status!=="dirty"?[he,e[0]]:e;let r=!0,s=!1,o=!1,i=-1;for(let u of e){let d=n(u[0]);d<i&&(r=!1),d===3&&(s=!0),u[0]===q&&(o=!0),i=d}let a=e;if(!r){let u=e.map((d,c)=>({m:d,i:c,tier:n(d[0])}));u.sort((d,c)=>d.tier-c.tier||d.i-c.i),a=u.map(d=>d.m)}if(s&&!o&&this._status!=="dirty"){let u=0;for(;u<a.length&&n(a[u][0])===0;)u++;return u===0?[he,...a]:[...a.slice(0,u),he,...a.slice(u)]}return a}_emit(e){if(e.length===0)return;for(let a=0;a<e.length;a++){let u=e[a];if(u[0]===$&&u[1]===void 0)throw new TypeError('[ERROR, payload] requires a non-undefined payload (spec \xA71.2). Pass an Error object or domain tag instead \u2014 e.g. node.down([[ERROR, new Error("reason")]])')}let n=e;if(this._isTerminal&&!this._resubscribable){let a=e.filter(u=>u[0]===B||u[0]===Z);if(a.length===0)return;n=a}n=this._frameBatch(n);let s=null;for(let a=0;a<n.length;a++){let u=n[a],d=u[0];if(d!==te&&d!==re){s?.push(u);continue}if(u.length<2)throw new Error(`Node "${this.name}": [[${d===te?"PAUSE":"RESUME"}]] must carry a lockId payload \u2014 bare PAUSE/RESUME is a protocol violation (C0 rule). Use \`[[PAUSE, lockId]]\` / \`[[RESUME, lockId]]\`.`);let c=!0;if(this._pausable!==!1){let h=u[1];if(d===te)this._pauseLocks==null&&(this._pauseLocks=new Set),this._pauseLocks.add(h),this._paused=!0,this._pausable==="resumeAll"&&this._pauseBuffer==null&&(this._pauseBuffer=[]);else if(this._pauseLocks==null||!this._pauseLocks.has(h))c=!1;else if(this._pauseLocks.delete(h),this._pauseLocks.size===0){if(this._paused=!1,this._pauseBuffer!=null&&this._pauseBuffer.length>0){let p=this._pauseBuffer;this._pauseBuffer=[],this._emit(p)}this._pendingWave&&(this._pendingWave=!1,this._maybeRunFnOnSettlement())}}c?s?.push(u):s==null&&(s=n.slice(0,a))}if(s!=null){if(s.length===0)return;n=s}if(this._hasMeta&&n.some(a=>a[0]===B))for(let a of Object.keys(this.meta))try{this.meta[a]._emit(Ke)}catch{}let{finalMessages:o,equalsError:i}=this._updateState(n);if(o.length>0&&this._config.inspectorEnabled){let a=this._config.globalInspector;if(a!=null)try{a({kind:"emit",node:this,messages:o})}catch{}}if(o.length>0)if(this._paused&&this._pausable==="resumeAll"&&this._pauseBuffer!=null){let a=this._config.tierOf,u=[];for(let d of o)a(d[0])===3?this._pauseBuffer.push(d):u.push(d);u.length>0&&this._dispatchOrAccumulate(u)}else this._dispatchOrAccumulate(o);i!=null&&this._emit([[$,i]])}_updateState(e){let n=this._config.tierOf,r,s,o=-1,i=0;for(let c of e)n(c[0])===3&&i++;let a=i<=1,u=-1;if(this._versioning!=null&&i>1){for(let c=e.length-1;c>=0;c--)if(e[c][0]===P){u=c;break}}for(let c=0;c<e.length;c++){let h=e[c],p=h[0];if(p===P){if(h.length>=2){let f=!1;if(a&&this._cached!==void 0)try{f=this._equals(this._cached,h[1])}catch(l){s=this._wrapFnError("equals threw",l),o=c;break}if(f){r==null&&(r=e.slice(0,c)),r.push(qe),this._status="resolved";continue}this._cached=h[1],this._versioning!=null&&(u<0||c===u)&&Wt(this._versioning,h[1],this._hashFn)}this._status="settled",r?.push(h)}else if(r?.push(h),p===q)this._status="dirty";else if(p===U)this._status="resolved";else if(p===H){this._status="completed";{let f=this._config.rigorRecorder;if(f!=null)try{f.onTerminalTransition(this,"completed",this._autoComplete,this._autoError,this._deps.length>0)}catch{}}}else if(p===$){this._status="errored";{let f=this._config.rigorRecorder;if(f!=null)try{f.onTerminalTransition(this,"errored",this._autoComplete,this._autoError,this._deps.length>0)}catch{}}}else if(p===Z){if(this._cached!==void 0){let l=this._config.rigorRecorder;if(l!=null)try{l.onNonVacuousInvalidate(this,this._cached)}catch{}}this._cached=void 0,this._status="dirty";let f=this._cleanup;if(typeof f=="function"){this._cleanup=void 0;try{f()}catch{}}else if(f!=null&&typeof f=="object"){let l=f.invalidate;if(typeof l=="function")try{l()}catch{}}}else p===B&&(this._resetOnTeardown&&(this._cached=void 0),this._deactivate(!0),this._status="sentinel")}let d=o>=0?r??e.slice(0,o):r??e;return s!=null?{finalMessages:d,equalsError:s}:{finalMessages:d}}_deliverToSinks=e=>{if(this._sinks==null)return;if(typeof this._sinks=="function"){this._sinks(e);return}let n=[...this._sinks];for(let r of n)r(e)};_dispatchOrAccumulate(e){if(It()){this._batchPendingMessages===null&&(this._batchPendingMessages=[],Ce(()=>this._flushBatchPending()));for(let n of e)this._batchPendingMessages.push(n);return}ze(this._deliverToSinks,e,this._config.tierOf)}_flushBatchPending(){let e=this._batchPendingMessages;if(e===null||(this._batchPendingMessages=null,e.length===0))return;let n=this._frameBatch(e);ze(this._deliverToSinks,n,this._config.tierOf)}},Zt=t=>Array.isArray(t),Ot=t=>typeof t=="object"&&t!=null&&!Array.isArray(t)});function Q(t,e){return se([],{...e,initial:t})}function Rt(t,e){return se((r,s,o)=>t(s,o)??void 0,{describeKind:"producer",...e})}function W(t,e,n){return se(t,(s,o,i)=>{let a=s.map((u,d)=>u!=null&&u.length>0?u.at(-1):i.prevData[d]);o.emit(e(a,i))},{describeKind:"derived",...n})}var Me=J(()=>{"use strict";me()});function oe(t){return t.subscribe(()=>{})}var Nt=J(()=>{"use strict"});var tt,sn=J(()=>{"use strict";tt=class{_timer;_gen=0;start(e,n){this.cancel(),this._gen+=1;let r=this._gen;this._timer=setTimeout(()=>{this._timer=void 0,r===this._gen&&n()},e)}cancel(){this._timer!==void 0&&(clearTimeout(this._timer),this._timer=void 0)}get pending(){return this._timer!==void 0}}});var Xr={};Ln(Xr,{CqrsGraph:()=>ft,cqrs:()=>Jr,cqrsEventKeyOf:()=>Wr,dispatchKeyOf:()=>Kr,sagaInvocationKeyOf:()=>Yr});module.exports=Pn(Xr);De();Be();pe();He();pe();Se();pe();me();function Xe(t,e){if(e!=null&&e.length>0)return new Set(e);switch(t){case"standard":return new Set(["type","status","value","deps","meta","v"]);case"full":return null;default:return new Set(["type","deps"])}}function Kn(t){return t._describeKind!=null?t._describeKind:t._deps.length>0?"derived":t._fn!=null?"producer":"state"}function Yn(t){let e={};for(let[n,r]of Object.entries(t.meta))try{e[n]=r.cache}catch{}return e}function St(t,e){let n=e==null,r=!n&&e!=null?[...e].filter(d=>d.startsWith("meta.")).map(d=>d.slice(5)):null,s=n||e.has("meta")||r!=null&&r.length>0,o="state",i=[];t instanceof V&&(o=Kn(t),i=t._deps.map(d=>d.node.name??""));let a={type:o,deps:i};(n||e.has("status"))&&(a.status=t.status);let u=t instanceof V?t._guard:void 0;if(s){let d={...Yn(t)};if(u!=null&&d.access===void 0&&(d.access=gt(u)),r!=null&&r.length>0&&!e.has("meta")){let c={};for(let h of r)h in d&&(c[h]=d[h]);a.meta=c}else a.meta=d}if(t.name!=null&&(a.name=t.name),n||e.has("value")){t.status==="sentinel"&&(a.sentinel=!0);try{a.value=t.cache}catch{}}if((n||e.has("v"))&&t.v!=null){let d={id:t.v.id,version:t.v.version};"cid"in t.v&&(d.cid=t.v.cid,d.prev=t.v.prev),a.v=d}return(n||e.has("guard"))&&u!=null&&(a.guard=gt(u)),(n||e.has("lastMutation"))&&t.lastMutation!=null&&(a.lastMutation=t.lastMutation),a}me();Me();De();Se();me();Me();var kt=class{_version=0;_maxSize;_buf;_head=0;_size=0;constructor(e,n){if(n!==void 0&&n<1)throw new RangeError("maxSize must be >= 1");if(this._maxSize=n,n!==void 0){if(this._buf=new Array(n),e&&e.length>0){let r=Math.min(e.length,n),s=e.length-r;for(let o=0;o<r;o++)this._buf[o]=e[s+o];this._size=r}}else this._buf=e?[...e]:[],this._size=this._buf.length}get version(){return this._version}get size(){return this._size}at(e){if(!Number.isInteger(e))return;let n=e>=0?e:this._size+e;if(!(n<0||n>=this._size))return this._maxSize!==void 0?this._buf[(this._head+n)%this._maxSize]:this._buf[n]}append(e){this._rawAppend(e),this._version+=1}appendMany(e){if(e.length===0)return;let n=this._maxSize!==void 0&&e.length>this._maxSize?e.length-this._maxSize:0;for(let r=n;r<e.length;r++)this._rawAppend(e[r]);this._version+=1}clear(){if(this._size===0)return 0;let e=this._size;if(this._maxSize===void 0)this._buf.length=0;else for(let n=0;n<e;n++)this._buf[(this._head+n)%this._maxSize]=void 0;return this._head=0,this._size=0,this._version+=1,e}trimHead(e){if(!Number.isInteger(e)||e<0)throw new RangeError(`trimHead: n must be a non-negative integer (got ${e})`);if(e===0||this._size===0)return 0;let n=Math.min(e,this._size);if(this._maxSize===void 0)this._buf.splice(0,n);else{for(let r=0;r<n;r++)this._buf[(this._head+r)%this._maxSize]=void 0;this._head=(this._head+n)%this._maxSize}return this._size-=n,this._version+=1,n}slice(e,n){if(!Number.isInteger(e)||e<0)throw new RangeError(`slice: start must be a non-negative integer (got ${e})`);if(n!==void 0&&(!Number.isInteger(n)||n<0))throw new RangeError(`slice: stop must be a non-negative integer or undefined (got ${n})`);let r=n===void 0?this._size:Math.min(Math.max(n,0),this._size),s=Math.min(e,this._size);if(s>=r)return[];let o=r-s;if(this._maxSize===void 0)return this._buf.slice(s,r);let i=new Array(o);for(let a=0;a<o;a++)i[a]=this._buf[(this._head+s+a)%this._maxSize];return i}tail(e){if(!Number.isInteger(e)||e<0)throw new RangeError(`tail: n must be a non-negative integer (got ${e})`);if(e===0||this._size===0)return[];let n=Math.min(e,this._size);return this.slice(this._size-n,this._size)}toArray(){if(this._maxSize===void 0)return[...this._buf];let e=new Array(this._size);for(let n=0;n<this._size;n++)e[n]=this._buf[(this._head+n)%this._maxSize];return e}snapshot(){return this.toArray()}restore(e){if(this._maxSize===void 0){this._buf.length=0;for(let n=0;n<e.length;n++)this._buf.push(e[n]);this._size=this._buf.length}else{let n=this._maxSize;for(let o=0;o<n;o++)this._buf[o]=void 0;this._head=0;let r=Math.min(e.length,n),s=e.length-r;for(let o=0;o<r;o++)this._buf[o]=e[s+o];this._size=r}this._version+=1}_rawAppend(e){if(this._maxSize===void 0){this._buf.push(e),this._size=this._buf.length;return}this._size<this._maxSize?(this._buf[(this._head+this._size)%this._maxSize]=e,this._size+=1):(this._buf[this._head]=e,this._head=(this._head+1)%this._maxSize)}};function Ge(t){return t.subscribe(()=>{})}var Jn=64;function Le(t,e={}){let{name:n,maxSize:r,versioning:s,guard:o,backend:i}=e,a=i??new kt(t,r),u=Q(a.toArray(),{name:n,describeKind:"state",equals:(g,b)=>g===b,...s!=null?{versioning:s}:{},...o!=null?{guard:o}:{}});function d(){let g=a.toArray();we(()=>{u.down([[q]],{internal:!0}),u.down([[P,g]],{internal:!0})})}let c=new Map,h=new Map,p=new Map;function f(g,b){return`${g}:${b===void 0?"END":b}`}function l(g){if(g.size<Jn)return;let b=g.keys().next();if(b.done)return;let S=g.get(b.value);S!==void 0&&S.dispose(),g.delete(b.value)}function m(g){let b=a.version;try{return g()}finally{a.version!==b&&d()}}function T(g){if(!Number.isInteger(g)||g<0)throw new RangeError(`tail: n must be a non-negative integer (got ${g})`);let b=c.get(g);if(b!==void 0)return c.delete(g),c.set(g,b),b.node;l(c);let S=W([u],([_])=>{let O=_;return g===0||O.length===0?[]:O.slice(Math.max(0,O.length-g))},{initial:a.tail(g),describeKind:"derived"}),x=Ge(S);return c.set(g,{node:S,dispose:x}),S}function N(g,b){if(!Number.isInteger(g)||g<0)throw new RangeError(`slice: start must be a non-negative integer (got ${g})`);if(b!==void 0&&(!Number.isInteger(b)||b<0))throw new RangeError(`slice: stop must be a non-negative integer or undefined (got ${b})`);let S=f(g,b),x=h.get(S);if(x!==void 0)return h.delete(S),h.set(S,x),x.node;l(h);let _=W([u],([k])=>{let C=k;return b===void 0?C.slice(g):C.slice(g,b)},{initial:a.slice(g,b),describeKind:"derived"}),O=Ge(_);return h.set(S,{node:_,dispose:O}),_}function w(g){let b=p.get(g);if(b!==void 0)return b.node;let S=W([u,g],([_,O])=>{let k=_,C=Math.max(0,Math.trunc(O??0));return k.slice(C)},{initial:[],describeKind:"derived"}),x=Ge(S);return p.set(g,{node:S,dispose:x}),S}let y,v;function R(){y===void 0&&(y=se([u],(g,b,S)=>{let x=g[0],O=x!=null&&x.length>0?x.at(-1):S.prevData[0];if(O==null||O.length===0){b.down([[U]]);return}b.emit(O[O.length-1])},{name:n!=null?`${n}::lastValue`:"lastValue",describeKind:"derived",initial:a.size===0?void 0:a.at(a.size-1)}),v=W([u],([g])=>g.length>0,{name:n!=null?`${n}::hasLatest`:"hasLatest",describeKind:"derived",initial:a.size>0}),Ge(y),Ge(v))}let E={entries:u,get size(){return a.size},at(g){return a.at(g)},append(g){m(()=>a.append(g))},appendMany(g){g.length!==0&&m(()=>a.appendMany(g))},clear(){m(()=>a.clear())},trimHead(g){m(()=>a.trimHead(g))},withLatest(){return R(),u},get lastValue(){return R(),y},get hasLatest(){return R(),v},view(g){switch(g.kind){case"tail":return T(g.n);case"slice":return N(g.start,g.stop);case"fromCursor":return w(g.cursor)}},attach(g){let b=g.subscribe(S=>{for(let x of S)x[0]===P&&E.append(x[1])});return()=>b()},attachStorage(g){if(g.length===0)return()=>{};let b=new Map;for(let x of g)b.set(x,a.size);(async()=>{for(let x of g)if(typeof x.loadEntries=="function")try{let _=await Promise.resolve(x.loadEntries());_.entries.length>0&&a.size===0&&(a.restore(_.entries),b.set(x,_.entries.length),d());break}catch{}})();let S=u.subscribe(x=>{for(let _ of x){if(_[0]!==P)continue;let O=_[1];for(let k of g){let C=b.get(k)??0;if(O.length<C){try{let G=k.appendEntries(O);G instanceof Promise&&G.catch(()=>{})}catch{}b.set(k,O.length);continue}if(O.length===C)continue;let D=O.slice(C);b.set(k,O.length);try{let G=k.appendEntries(D);G instanceof Promise&&G.catch(()=>{})}catch{}}}});return()=>S()},disposeAllViews(){for(let g of c.values())g.dispose();c.clear();for(let g of h.values())g.dispose();h.clear();for(let g of p.values())g.dispose();p.clear()},dispose(){for(let g of c.values())g.dispose();c.clear();for(let g of h.values())g.dispose();h.clear();for(let g of p.values())g.dispose();p.clear()}};return E}var F={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},Xn=Symbol.for("sizeof");function Qt(t){let e=new WeakSet,n=new WeakSet,r=[t],s=0;for(;r.length>0;){let o=r.pop();s+=Zn(o,e,n,r)}return s}function Zn(t,e,n,r){if(t==null)return 0;switch(typeof t){case"number":return F.number;case"boolean":return F.boolean;case"string":return F.string+t.length*2;case"bigint":return F.bigint+Qn(t);case"symbol":return F.symbol;case"function":return e.has(t)?0:(e.add(t),F.function);case"undefined":return 0}let o=t;if(e.has(o))return 0;e.add(o);let i=o[Xn];if(typeof i=="function")try{let d=i.call(o);if(typeof d=="number"&&Number.isFinite(d))return d}catch{}if(o instanceof Date)return F.date;if(o instanceof RegExp)return F.regexp+o.source.length*2;if(o instanceof Error){let d=o.message?o.message.length*2:0,c=o.stack?o.stack.length*2:0;return F.error+d+c}if(typeof URL<"u"&&o instanceof URL)return F.url+o.href.length*2;if(typeof Promise<"u"&&o instanceof Promise)return F.promise;if(o instanceof WeakMap)return F.weakmap;if(o instanceof WeakSet)return F.weakset;if(o instanceof Map){let d=F.map;for(let[c,h]of o)d+=F.mapEntry,r.push(c),r.push(h);return d}if(o instanceof Set){let d=F.set;for(let c of o)d+=F.setEntry,r.push(c);return d}if(Array.isArray(o)){let d=F.array+o.length*8;for(let c of o)r.push(c);return d}if(o instanceof ArrayBuffer)return n.has(o)?0:(n.add(o),o.byteLength);if(ArrayBuffer.isView(o)){let d=o;return n.has(d.buffer)?48:(n.add(d.buffer),d.buffer.byteLength+48)}let a=F.object,u=Object.keys(o);for(let d of u){a+=F.string+d.length*2;try{r.push(o[d])}catch{}}return a}function Qn(t){let e=t<0n?-t:t;if(e===0n)return 0;let n=e.toString(2).length;return Math.ceil(n/32)*8}function en(t,e,n,r={}){let s=e in t.nodes,o=n in t.nodes;if(!s)return Ze(e,n,"no-such-from");if(!o)return Ze(e,n,"no-such-to");let i=r.maxDepth;if(i!=null&&(!Number.isInteger(i)||i<0))throw new Error("explainPath: maxDepth must be an integer >= 0");if(e===n){if(r.findCycle===!0){let d=er(t,e,r);if(d!=null)return d}let u=Qe(e,t.nodes[e],0,r);return et(e,n,[u])}if(i===0)return Ze(e,n,"no-path");let a=tn(t,e,n,i);return a.found?et(e,n,nn(t,a.pathOrder,r)):Ze(e,n,a.truncated?"max-depth-exceeded":"no-path")}function tn(t,e,n,r){let s=new Map,o=[{path:n,depth:0}],i=new Set([n]),a=0,u=!1;for(;a<o.length;){let h=o[a++];if(h.path===e)break;if(r!=null&&h.depth>=r){let m=t.nodes[h.path];m?.deps&&m.deps.length>0&&(u=!0);continue}let p=t.nodes[h.path];if(p==null)continue;let f=p.deps??[],l=new Map;for(let m=0;m<f.length;m++){let T=f[m];if(!T)continue;let N=l.get(T);N==null&&(N=[],l.set(T,N)),N.push(m)}for(let[m,T]of l)i.has(m)||(i.add(m),s.set(m,{from:h.path,depIndices:T}),o.push({path:m,depth:h.depth+1}))}if(!s.has(e))return{found:!1,pathOrder:[],truncated:u};let d=[{path:e}],c=e;for(;c!==n;){let h=s.get(c);if(h==null)return{found:!1,pathOrder:[],truncated:!1};d[d.length-1].depIndices=h.depIndices,d.push({path:h.from}),c=h.from}return{found:!0,pathOrder:d,truncated:!1}}function er(t,e,n){let r=t.nodes[e];if(r==null)return null;let s=r.deps??[],o=[];for(let a=0;a<s.length;a++)s[a]===e&&o.push(a);if(o.length>0){let a=Qe(e,r,0,n);a.dep_index=o[0];let u=Qe(e,r,1,n);return et(e,e,[a,u])}let i=null;for(let a=0;a<s.length;a++){let u=s[a];if(!u||u===e)continue;let d=tn(t,u,e,n.maxDepth);d.found&&(i==null||d.pathOrder.length<i.pathOrder.length)&&(i=d,i={found:!0,pathOrder:[{path:e,depIndices:[a]},...d.pathOrder],truncated:!1})}return i==null?null:et(e,e,nn(t,i.pathOrder,n))}function nn(t,e,n){return e.map((r,s)=>{let o=t.nodes[r.path],i=Qe(r.path,o,s,n);return r.depIndices!=null&&r.depIndices.length>0&&(i.dep_index=r.depIndices[0],r.depIndices.length>1&&(i.dep_indices=[...r.depIndices])),i})}function Qe(t,e,n,r){let s={path:t,type:e.type,hop:n};e.status!==void 0&&(s.status=e.status),"value"in e&&(s.value=e.value),e.v!=null&&(s.v=e.v);let o=r.annotations?.get(t)??e.annotation;o!=null&&(s.annotation=o);let i=r.lastMutations?.get(t)??e.lastMutation;return i!=null&&(s.lastMutation=i),s}function et(t,e,n){return rn(t,e,!0,"ok",n)}function Ze(t,e,n){return rn(t,e,!1,n,[])}function rn(t,e,n,r,s){let o=tr(t,e,n,r,s);return{from:t,to:e,found:n,reason:r,steps:s,text:o,toJSON(){return{from:t,to:e,found:n,reason:r,steps:s}}}}function tr(t,e,n,r,s){if(!n)switch(r){case"no-such-from":return`explainPath: no node named "${t}"`;case"no-such-to":return`explainPath: no node named "${e}"`;case"max-depth-exceeded":return`explainPath: no path from "${t}" to "${e}" within maxDepth`;default:return`explainPath: no path from "${t}" to "${e}"`}let o=[`Causal path: ${t} \u2192 ${e} (${s.length} step(s))`];for(let i of s){let u=` ${i.hop===0?"\xB7":"\u2193"} ${i.path} (${i.type}${i.status?`/${i.status}`:""})`;if(o.push(u),"value"in i&&o.push(` value: ${nr(i.value)}`),i.annotation!=null&&o.push(` annotation: ${i.annotation}`),i.lastMutation!=null){let d=i.lastMutation.actor;o.push(` actor: ${d.type}${d.id?`:${d.id}`:""}`)}}return o.join(`
|
|
2
|
-
`)}function
|
|
3
|
-
`)}function or(t,e,n,r,s){let{x:o,y:i,w:a,h:u}=r;if(a<2||u<2){u>0&&an(t,e,o,i,a,s);return}ie(t,e,o,i,n.boxTL);for(let c=o+1;c<o+a-1;c+=1)ie(t,e,c,i,n.boxH);ie(t,e,o+a-1,i,n.boxTR);for(let c=i+1;c<i+u-1;c+=1){ie(t,e,o,c,n.boxV);for(let h=o+1;h<o+a-1;h+=1)ln(t,e,h,c," ","empty");ie(t,e,o+a-1,c,n.boxV)}ie(t,e,o,i+u-1,n.boxBL);for(let c=o+1;c<o+a-1;c+=1)ie(t,e,c,i+u-1,n.boxH);ie(t,e,o+a-1,i+u-1,n.boxBR);let d=i+Math.floor(u/2);an(t,e,o+1,d,a-2,s)}function ie(t,e,n,r,s){ln(t,e,n,r,s,s===" "?"empty":s==="\u2500"||s==="-"?"boxH":s==="\u2502"||s==="|"?"boxV":"boxCorner")}function ln(t,e,n,r,s,o){if(r<0||r>=t.length)return;let i=t[r];n<0||n>=i.length||(i[n]=s,e[r][n]=o)}function an(t,e,n,r,s,o){if(r<0||r>=t.length)return;let i=n,a=s;for(let u of o){let d=nt(u);if(d!==0){if(a<d)break;i>=0&&i<t[r].length&&(t[r][i]=u,e[r][i]="label",d===2&&i+1<t[r].length&&(t[r][i+1]="",e[r][i+1]="label")),i+=d,a-=d}}for(;a>0;)i>=0&&i<t[r].length&&(t[r][i]=" ",e[r][i]="empty"),i+=1,a-=1}function ir(t,e,n,r){let s=r.points;if(s.length<2)return;for(let u=0;u+1<s.length;u+=1)ar(t,e,n,s[u],s[u+1]);for(let u=1;u+1<s.length;u+=1){let d=s[u-1],c=s[u],h=s[u+1],p=dr(d,c,h,n);p&&un(t,e,c.x,c.y,p,"edgeCorner")}let o=s[s.length-1],i=s[s.length-2],a=ur(i,o,n);a&&un(t,e,o.x,o.y,a,"arrow")}function ar(t,e,n,r,s){if(!(r.x===s.x&&r.y===s.y)){if(r.y===s.y){let o=r.y,i=Math.min(r.x,s.x),a=Math.max(r.x,s.x);for(let u=i;u<=a;u+=1)dn(t,e,u,o,n,"h")}else if(r.x===s.x){let o=r.x,i=Math.min(r.y,s.y),a=Math.max(r.y,s.y);for(let u=i;u<=a;u+=1)dn(t,e,o,u,n,"v")}}}function dn(t,e,n,r,s,o){if(r<0||r>=t.length)return;let i=t[r];if(n<0||n>=i.length)return;let a=e[r][n];if(!(a==="boxH"||a==="boxV"||a==="boxCorner"||a==="label")){if(a==="empty"){i[n]=o==="h"?s.horizontal:s.vertical,e[r][n]=o==="h"?"edgeH":"edgeV";return}if(a==="edgeH"&&o==="v"){i[n]=s.cross,e[r][n]="edgeCorner";return}if(a==="edgeV"&&o==="h"){i[n]=s.cross,e[r][n]="edgeCorner";return}}}function un(t,e,n,r,s,o){if(r<0||r>=t.length)return;let i=t[r];if(n<0||n>=i.length)return;let a=e[r][n];a==="boxH"||a==="boxV"||a==="boxCorner"||a==="label"||(i[n]=s,e[r][n]=o)}function dr(t,e,n,r){let s=t.y===e.y,o=e.y===n.y;if(s===o)return;if(s){let u=t.x<e.x,d=n.y>e.y;return u&&d?r.cornerTR:u&&!d?r.cornerBR:!u&&d?r.cornerTL:r.cornerBL}let i=t.y<e.y,a=n.x>e.x;return i&&a?r.cornerBL:i&&!a?r.cornerBR:!i&&a?r.cornerTL:r.cornerTR}function ur(t,e,n){if(e.x>t.x)return n.arrowRight;if(e.x<t.x)return n.arrowLeft;if(e.y>t.y)return n.arrowDown;if(e.y<t.y)return n.arrowUp}function cr(t){let e=t.length;for(;e>0&&t.charCodeAt(e-1)===32;)e-=1;return t.slice(0,e)}function hn(t){let e=lr(t);fr(e),pr(e),hr(e),gr(e,t);let n=br(e,t),{width:r,height:s}=_r(e),o=[];for(let i of e.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:n,width:r,height:s}}function lr(t){let e=new Map;for(let s of t.nodes)e.set(s,{id:s,isVirtual:!1,layer:-1,order:0,x:0,y:0,w:t.widthCells(s),h:t.heightCells(s),in:[],out:[]});let n=[],r=0;for(let s of t.edges){if(s.from===s.to)continue;let o=e.get(s.from),i=e.get(s.to);if(!o||!i)continue;let a={chainId:r++,chainFrom:s.from,chainTo:s.to,fromId:s.from,toId:s.to,hopIndex:0,chainLen:1};o.out.push(a),i.in.push(a),n.push(a)}return{nodes:e,layers:[],hops:n}}function fr(t){let e=new Map;for(let o of t.nodes.values())e.set(o.id,o.in.length);let n=[];for(let o of t.nodes.values())(e.get(o.id)??0)===0&&(o.layer=0,n.push(o));let r=new Set,s=0;for(;s<n.length;){let o=n[s++];if(!r.has(o.id)){r.add(o.id);for(let i of o.out){let a=t.nodes.get(i.toId);a.layer=Math.max(a.layer,o.layer+1);let u=(e.get(a.id)??0)-1;e.set(a.id,u),u<=0&&n.push(a)}}}for(let o of t.nodes.values())o.layer<0&&(o.layer=0)}function pr(t){let e=Math.max(0,...Array.from(t.nodes.values(),o=>o.layer)),n=Array.from({length:e+1},()=>[]);for(let o of t.nodes.values())n[o.layer].push(o);let r=[],s=0;for(let o of t.hops){let i=t.nodes.get(o.fromId),a=t.nodes.get(o.toId),u=a.layer-i.layer;if(u<=0){i.out=i.out.filter(h=>h!==o),a.in=a.in.filter(h=>h!==o);continue}if(u===1){o.hopIndex=0,o.chainLen=1,r.push(o);continue}i.out=i.out.filter(h=>h!==o),a.in=a.in.filter(h=>h!==o);let d=i;for(let h=1;h<u;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:[]};t.nodes.set(p,f),n[f.layer].push(f);let l={chainId:o.chainId,chainFrom:o.chainFrom,chainTo:o.chainTo,fromId:d.id,toId:p,hopIndex:h-1,chainLen:u};d.out.push(l),f.in.push(l),r.push(l),d=f}let c={chainId:o.chainId,chainFrom:o.chainFrom,chainTo:o.chainTo,fromId:d.id,toId:a.id,hopIndex:u-1,chainLen:u};d.out.push(c),a.in.push(c),r.push(c)}for(let o of n)for(let i=0;i<o.length;i+=1)o[i].order=i;t.layers=n,t.hops=r}function hr(t){for(let n=0;n<4;n+=1){for(let r=1;r<t.layers.length;r+=1)fn(t,t.layers[r],"in"),rt(t.layers[r]);for(let r=t.layers.length-2;r>=0;r-=1)fn(t,t.layers[r],"out"),rt(t.layers[r])}for(let n=0;n<2;n+=1){let r=!1;for(let s=1;s<t.layers.length;s+=1){let o=t.layers[s];for(let i=0;i+1<o.length;i+=1){let a=pn(t,o[i],o[i+1],"in");[o[i],o[i+1]]=[o[i+1],o[i]],rt(o),pn(t,o[i],o[i+1],"in")<a?r=!0:([o[i],o[i+1]]=[o[i+1],o[i]],rt(o))}}if(!r)break}}function fn(t,e,n){let r=new Map;for(let s of e){let o=n==="in"?s.in:s.out;if(o.length===0){r.set(s.id,s.order);continue}let i=0,a=0;for(let u of o){let d=t.nodes.get(n==="in"?u.fromId:u.toId);d&&(i+=d.order,a+=1)}r.set(s.id,a===0?s.order:i/a)}e.sort((s,o)=>{let i=r.get(s.id),a=r.get(o.id);return i!==a?i-a:s.order-o.order})}function rt(t){for(let e=0;e<t.length;e+=1)t[e].order=e}function pn(t,e,n,r){let s=r==="in"?e.in:e.out,o=r==="in"?n.in:n.out,i=0;for(let a of s)for(let u of o){let d=t.nodes.get(r==="in"?a.fromId:a.toId)?.order??0,c=t.nodes.get(r==="in"?u.fromId:u.toId)?.order??0;(e.order<n.order&&d>c||e.order>n.order&&d<c)&&(i+=1)}return i}function gr(t,e){e.direction==="LR"?mr(t,e):yr(t,e)}function mr(t,e){let n=[],r=0;for(let s=0;s<t.layers.length;s+=1){n.push(r);let o=0;for(let i of t.layers[s])o=Math.max(o,i.w);r+=o+e.layerGap}for(let s=0;s<t.layers.length;s+=1)for(let o of t.layers[s])o.x=n[s];for(let s of t.layers){let o=0;for(let i of s)i.y=o,o+=i.h+e.nodeGap}gn(t,e,"y")}function yr(t,e){let n=[],r=0;for(let s=0;s<t.layers.length;s+=1){n.push(r);let o=0;for(let i of t.layers[s])o=Math.max(o,i.h);r+=o+e.layerGap}for(let s=0;s<t.layers.length;s+=1)for(let o of t.layers[s])o.y=n[s];for(let s of t.layers){let o=0;for(let i of s)i.x=o,o+=i.w+e.nodeGap}gn(t,e,"x")}function gn(t,e,n){let r=o=>n==="y"?o.h:o.w,s=e.nodeGap;for(let o=0;o<2;o+=1){let i=o===0?t.layers.slice(1):t.layers.slice(0,-1).reverse();for(let a of i){let u=new Map;for(let c of a){let h=o===0?c.in:c.out;if(h.length===0)continue;let p=[];for(let l of h){let m=t.nodes.get(o===0?l.fromId:l.toId);if(!m)continue;let T=n==="y"?m.y:m.x;p.push(T+Math.floor(r(m)/2))}if(p.length===0)continue;p.sort((l,m)=>l-m);let f=p[Math.floor(p.length/2)];u.set(c.id,f-Math.floor(r(c)/2))}let d=0;for(let c of a){let h=u.get(c.id),p=n==="y"?c.y:c.x,l=Math.max(h??p,d);n==="y"?c.y=l:c.x=l,d=l+r(c)+s}}}}function br(t,e){let n=new Map;for(let d of t.hops){let c=n.get(d.chainId);c?c.push(d):n.set(d.chainId,[d])}for(let d of n.values())d.sort((c,h)=>c.hopIndex-h.hopIndex);let r=e.direction==="LR",s=d=>r?d.x:d.y,o=d=>r?d.w:d.h,i=d=>r?d.y+Math.floor(d.h/2):d.x+Math.floor(d.w/2),a=new Map;for(let d=0;d+1<t.layers.length;d+=1){let c=t.layers[d],h=t.layers[d+1],p=0;for(let b of c)p=Math.max(p,s(b)+o(b));let f=Number.POSITIVE_INFINITY;for(let b of h)f=Math.min(f,s(b));let l=Number.isFinite(f)?f-1:p,m=Math.max(1,l-p+1),T=[];for(let b of c)for(let S of b.out)T.push(S);T.sort((b,S)=>{let x=i(t.nodes.get(b.fromId)),_=i(t.nodes.get(S.fromId));if(x!==_)return x-_;let O=i(t.nodes.get(b.toId)),k=i(t.nodes.get(S.toId));return O-k});let N=[],w=new Map;for(let b of T){let S=i(t.nodes.get(b.fromId)),x=i(t.nodes.get(b.toId)),_=Math.min(S,x),O=Math.max(S,x),k=-1;for(let C=0;C<N.length;C+=1){let D=N[C],G=!0;for(let z of D)if(z.lo<=O&&_<=z.hi){G=!1;break}if(G){D.push({lo:_,hi:O}),k=C;break}}k<0&&(N.push([{lo:_,hi:O}]),k=N.length-1),w.set(b,k)}let y=N.length,v=m>=Math.max(3,y+2),R=v?p+1:p,E=v?l-1:l,g=Math.max(1,E-R+1);for(let b of T){let S=w.get(b),x;if(y<=1)x=R+Math.floor(g/2);else{let _=(g-1)/(y-1);x=R+Math.floor(S*_)}a.set(b,Math.max(p,Math.min(l,x)))}}let u=[];for(let[,d]of n){let c=[];for(let p=0;p<d.length;p+=1){let f=d[p],l=t.nodes.get(f.fromId),m=t.nodes.get(f.toId),T=a.get(f),N=l.isVirtual?s(l):s(l)+o(l),w=m.isVirtual?s(m):s(m)-1,y=i(l),v=i(m);p===0&&st(c,r,N,y),y!==v&&(st(c,r,T,y),st(c,r,T,v)),st(c,r,w,v)}let h=d[0];u.push({from:h.chainFrom,to:h.chainTo,points:vr(c)})}return u}function st(t,e,n,r){t.push(e?{x:n,y:r}:{x:r,y:n})}function vr(t){let e=[];for(let n of t){let r=e[e.length-1];(!r||r.x!==n.x||r.y!==n.y)&&e.push(n)}return e}function _r(t){let e=0,n=0;for(let r of t.layers)for(let s of r)e=Math.max(e,s.x+s.w),n=Math.max(n,s.y+s.h);return{width:e,height:n}}var wr=24,xr=4,Tr=1,Er=3;function mn(t,e){let n=Or(e.direction),r=Math.max(3,e.maxLabelWidth??wr),s=e.asciiCharset??"unicode",o=Object.keys(t.nodes).sort(),i=new Set(o),a=t.edges.filter(f=>i.has(f.from)&&i.has(f.to)),u=new Map,d=new Map;for(let f of o){let l=on(f,r);u.set(f,l),d.set(f,nt(l)+4)}let c=hn({nodes:o,edges:a,widthCells:f=>d.get(f)??3,heightCells:()=>Er,layerGap:xr,nodeGap:Tr,direction:n}),h=cn(c,{charset:s,labelOf:f=>u.get(f)??f}),p=e.logger;return p&&p(h),h}function Or(t){if(t===void 0||t==="LR")return"LR";if(t==="TD")return"TD";throw new Error(`ascii describe supports direction "LR" or "TD" only; got ${String(t)}`)}me();function yn(t,e){let n=e?.topN??10,r=t.describe({detail:"standard"}),s=[],o=t._collectObserveTargets;typeof o=="function"&&o.call(t,"",s);let i=new Map;for(let[p,f]of s)i.set(p,f);let a=[];for(let[p,f]of Object.entries(r.nodes)){let l=i.get(p),m=l instanceof V?l:null,T=m?Qt(m.cache):0,N=m?m._sinkCount:0,w=f.deps?.length??0,y=f.type==="effect"&&N===0,v=N===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:T,subscriberCount:N,depCount:w,isOrphanEffect:y,orphanKind:v})}let u=a.reduce((p,f)=>p+f.valueSizeBytes,0),d=(p,f)=>[...a].sort(f??((l,m)=>m[p]-l[p])).slice(0,n),c=a.filter(p=>p.orphanKind!=null),h=a.filter(p=>p.isOrphanEffect);return{nodeCount:a.length,edgeCount:r.edges.length,subgraphCount:r.subgraphs.length,nodes:a,totalValueSizeBytes:u,hotspots:{byValueSize:d("valueSizeBytes"),bySubscriberCount:d("subscriberCount"),byDepCount:d("depCount")},orphans:c,orphanEffects:h}}var I="::",ee="__meta__",ye=1;function bn(t,e){let n=Math.max(16,t.size*4),r=0;for(;t.size>0;){if(r++>=n){console.error(`[Graph "${e}".destroy] disposer drain exceeded cap (${n}); ${t.size} disposer(s) discarded`),t.clear();return}let s=t.values().next();if(s.done)return;let o=s.value;t.delete(o);try{o()}catch(i){console.error(`[Graph "${e}".destroy] disposer threw:`,i)}}}function wn(t){return t!=null&&typeof t=="object"&&"cache"in t&&typeof t.subscribe=="function"&&typeof t.down=="function"}function Sr(t){if(t!=null)return wn(t)?t.cache:t}function Rr(t){let e=[];for(let n of Object.keys(t).sort()){let r=t[n].v;r!=null&&e.push(`${n} ${r.id} ${r.version}`)}return e.join(`
|
|
4
|
-
`)}function
|
|
5
|
-
`);return e.logger?.(o),o}function
|
|
6
|
-
`)}function
|
|
7
|
-
`)}function Ir(t){return t.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function ot(t){let e="^";for(let n=0;n<t.length;n+=1){let r=t[n];if(r==="*"){e+=".*";continue}if(r==="?"){e+=".";continue}if(r==="["){let s=t.indexOf("]",n+1);if(s<=n+1){e+="\\[";continue}let o=t.slice(n+1,s);o.startsWith("!")&&(o=`^${o.slice(1)}`),o=o.replace(/\\/g,"\\\\"),e+=`[${o}]`,n=s;continue}e+=Ir(r)}return e+="$",new RegExp(e)}var Pr={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"},$r={data:"",dirty:"",resolved:"",invalidate:"",pause:"",resume:"",complete:"",error:"",teardown:"",derived:"",path:"",reset:""};function it(t){if(typeof t=="string")return JSON.stringify(t);if(typeof t=="number"||typeof t=="boolean"||t==null)return String(t);try{return JSON.stringify(t)}catch{return"[unserializable]"}}function Vr(t){return t==="none"?$r:t==="ansi"||t==null?Pr:{data:t.data??"",dirty:t.dirty??"",resolved:t.resolved??"",invalidate:t.invalidate??"",pause:t.pause??"",resume:t.resume??"",complete:t.complete??"",error:t.error??"",teardown:t.teardown??"",derived:t.derived??"",path:t.path??"",reset:t.reset??""}}function _n(t){if(t==null)return{};let e=t.detail;return e==="full"?{...t,structured:t.structured??!0,timeline:t.timeline??!0,causal:t.causal??!0,derived:t.derived??!0}:e==="minimal"?{...t,structured:t.structured??!0}:t.format==="stage-log"?{...t,structured:t.structured??!0,timeline:t.timeline??!0}:t}function Fr(t,e,n){for(let r=0;r<t.length;r++){let s=t.charCodeAt(r);if(s<32||s===127)throw new Error(`Graph "${e}": ${n} "${t}" must not contain control character (U+${s.toString(16).padStart(4,"0").toUpperCase()} at index ${r})`)}}function Ct(t,e,n){if(t==="")throw new Error(`Graph "${e}": ${n} name must be non-empty`);if(t.includes(I))throw new Error(`Graph "${e}": ${n} "${t}" must not contain '${I}' (path separator)`);if(t===ee)throw new Error(`Graph "${e}": ${n} name "${ee}" is reserved for meta companion paths`);Fr(t,e,n)}function zr(t,e){if(t==="")throw new Error(`Graph "${e}": resolve path must be non-empty`);let n=t.split(I);for(let r of n)if(r==="")throw new Error(`Graph "${e}": resolve path has empty segment`);return n}function Br(t,e){let n=!1;for(let s of t)if(!e.isMetaPassthrough(s[0])){n=!0;break}return n?t.filter(s=>e.isMetaPassthrough(s[0])):t}function Sn(t){for(let e of t._mounts.values())Sn(e);for(let e of t._nodes.values())try{e.down([[B]],{internal:!0})}catch{}}var ae=class t{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(e,n){if(e==="")throw new Error("Graph name must be non-empty");if(e.includes(I))throw new Error(`Graph name must not contain '${I}' (got "${e}")`);if(e===ee)throw new Error(`Graph name "${ee}" is reserved for meta companion paths`);this.name=e,this.opts=Object.freeze({...n??{}}),this.config=n?.config??ge,this._traceRing=new Ie(n?.traceCapacity??1e3),n?.versioning!=null&&this.setVersioning(n.versioning)}ancestors(e=!0){let n=[],r=e?this:this._parent;for(;r!=null;)n.push(r),r=r._parent;return n}get topology(){return this._topology==null&&(this._topology=Rt(e=>{let n=r=>{e.emit(r)};return this._topologyEmitters.add(n),()=>{this._topologyEmitters.delete(n)}},{name:`${this.name}_topology`})),this._topology}_emitTopology(e){if(!(this._topology==null||this._topologyEmitters.size===0))for(let n of this._topologyEmitters)n(e)}nameOf(e){return this._nodeToName.get(e)}add(e,n){let r=e.name,s=n?.name??r;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=n?.annotation;if(Ct(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(e);if(a!==void 0)throw new Error(`Graph "${this.name}": node instance already registered as "${a}"`);return this._nodes.set(o,e),this._nodeToName.set(e,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:xe()})),e}setVersioning(e){if(e!=null)for(let n of this._nodes.values())n instanceof V&&n._applyVersioning(e)}remove(e){Ct(e,this.name,"remove");let n=this._mounts.get(e);if(n){let o={kind:"mount",nodes:[],mounts:[]},i=[];n._collectObserveTargets("",i);for(let[a,u]of i)a.includes(`${I}${ee}${I}`)||o.nodes.push(a);return o.nodes.sort(),o.mounts.push(e),o.mounts.push(...n._collectSubgraphs(`${e}${I}`)),this._mounts.delete(e),n._parent=void 0,Sn(n),this._emitTopology({kind:"removed",name:e,nodeKind:"mount",audit:o}),o}let r=this._nodes.get(e);if(!r)throw new Error(`Graph "${this.name}": unknown node or mount "${e}"`);this._nodes.delete(e),this._nodeToName.delete(r),r.down([[B]],{internal:!0});let s={kind:"node",nodes:[e],mounts:[]};return this._emitTopology({kind:"removed",name:e,nodeKind:"node",audit:s}),s}removeAll(e){let n=typeof e=="function"?e:(()=>{let o=ot(e);return i=>o.test(i)})(),r={kind:"mount",nodes:[],mounts:[]},s=[...this._nodes.keys(),...this._mounts.keys()].filter(o=>n(o));for(let o of s){let i=this.remove(o);r.nodes.push(...i.nodes),r.mounts.push(...i.mounts)}return r.nodes.sort(),r.mounts.sort(),r}[Symbol.iterator](){let e=[...this._nodes.keys()].sort(),n=this._nodes,r=0;return{[Symbol.iterator](){return this},next(){if(r>=e.length)return{value:void 0,done:!0};let s=e[r++];return{value:[s,n.get(s)],done:!1}}}}node(e){if(e==="")throw new Error(`Graph "${this.name}": node name must be non-empty`);if(e.includes(I))return this.resolve(e);let n=this._nodes.get(e);if(!n)throw new Error(`Graph "${this.name}": unknown node "${e}"`);return n}get(e){return this.node(e).cache}set(e,n,r){let s=r?.internal===!0;this.node(e).down([[P,n]],{actor:r?.actor,internal:s,delivery:"write"})}setAll(e,n){let r=Symbol.iterator in e?e:Object.entries(e);we(()=>{for(let[s,o]of r)this.set(s,o,n)})}invalidate(e,n){let r=n?.internal===!0;this.node(e).down([[Z]],{actor:n?.actor,internal:r,delivery:"write"})}error(e,n,r){let s=r?.internal===!0;this.node(e).down([[$,n]],{actor:r?.actor,internal:s,delivery:"write"})}complete(e,n){let r=n?.internal===!0;this.node(e).down([[H]],{actor:n?.actor,internal:r,delivery:"write"})}edges(e){let n=e?.recursive===!0,r=new Map;if(!n){for(let[u,d]of this._nodes)r.set(d,u);let a=[];for(let[u,d]of this._nodes)if(d instanceof V)for(let c of d._deps){let h=r.get(c.node);h!=null&&a.push([h,u])}return a.sort((u,d)=>u[0]<d[0]?-1:u[0]>d[0]?1:u[1]<d[1]?-1:u[1]>d[1]?1:0),a}let s=[];this._collectObserveTargets("",s);let o=new Map;for(let[a,u]of s)o.set(u,a);let i=[];for(let[a,u]of s)if(u instanceof V)for(let d of u._deps){let c=o.get(d.node);c!=null&&i.push([c,a])}return i.sort((a,u)=>a[0]<u[0]?-1:a[0]>u[0]?1:a[1]<u[1]?-1:a[1]>u[1]?1:0),i}mount(e,n){if(n===void 0){let s=new t(e);return this.mount(e,s)}if(typeof n=="function"){let s=new t(e);return n(s),this.mount(e,s)}let r=n;if(Ct(e,this.name,"mount"),this._nodes.has(e))throw new Error(`Graph "${this.name}": cannot mount at "${e}" \u2014 node with that name exists`);if(this._mounts.has(e))throw new Error(`Graph "${this.name}": mount "${e}" already exists`);if(r===this)throw new Error(`Graph "${this.name}": cannot mount a graph into itself`);if(r._parent!=null)throw new Error(`Graph "${this.name}": this child graph is already mounted on "${r._parent.name}"`);for(let s=this;s!=null;s=s._parent)if(s===r)throw new Error(`Graph "${this.name}": mount("${e}", \u2026) would create a mount cycle`);return this._mounts.set(e,r),r._parent=this,this._emitTopology({kind:"added",name:e,nodeKind:"mount"}),r}resolve(e){let n=zr(e,this.name);return this._resolveFromSegments(n)}tryResolve(e){try{return this.resolve(e)}catch{return}}_resolveFromSegments(e){let n=e;if(n[0]===this.name&&(n=n.slice(1),n.length===0))throw new Error(`Graph "${this.name}": resolve path ends at graph name only`);let r=n[0],s=n.slice(1);if(s.length===0){let a=this._nodes.get(r);if(a)return a;throw this._mounts.has(r)?new Error(`Graph "${this.name}": path ends at subgraph "${r}" \u2014 not a node (GRAPHREFLY-SPEC \xA73.5)`):new Error(`Graph "${this.name}": unknown name "${r}"`)}let o=this._nodes.get(r);if(o&&s.length>0&&s[0]===ee)return this._resolveMetaChainFromNode(o,s,n.join(I));let i=this._mounts.get(r);if(!i)throw this._nodes.has(r)?new Error(`Graph "${this.name}": "${r}" is a node; trailing path "${s.join(I)}" is invalid`):new Error(`Graph "${this.name}": unknown mount or node "${r}"`);return i.resolve(s.join(I))}_resolveMetaChainFromNode(e,n,r){let s=e,o=0,i=[...n];for(;o<i.length;){if(i[o]!==ee)throw new Error(`Graph "${this.name}": expected ${ee} segment in meta path "${r}"`);if(o+1>=i.length)throw new Error(`Graph "${this.name}": meta path requires a key after ${ee} in "${r}"`);let a=i[o+1],u=s.meta[a];if(!u)throw new Error(`Graph "${this.name}": unknown meta "${a}" in path "${r}"`);s=u,o+=2}return s}signal(e,n){if(n?.internal!==!0){for(let s of e)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 r=[];if(this._signalDeliver(e,n??{},new Set,r),r.length>0)throw r[0]}_signalDeliver(e,n,r,s){for(let u of this._mounts.values())u._signalDeliver(e,n,r,s);let i=n.internal===!0?{internal:!0}:{actor:n.actor,delivery:"signal"},a=Br(e,this.config);for(let u of[...this._nodes.keys()].sort()){let d=this._nodes.get(u);if(!r.has(d)){r.add(d);try{d.down(e,i)}catch(c){if(c instanceof X)throw c;s.push(c)}a.length!==0&&this._signalMetaSubtree(d,a,r,i,s)}}}_signalMetaSubtree(e,n,r,s,o){for(let i of Object.keys(e.meta).sort()){let a=e.meta[i];if(!r.has(a)){r.add(a);try{a.down(n,s)}catch(u){if(u instanceof X)throw u;o.push(u)}this._signalMetaSubtree(a,n,r,s,o)}}}describe(e){if(e?.reactive===!0)return this._describeReactive(e);let n=Sr(e?.actor),r=e?.filter,s=Xe(e?.detail,e?.fields),o=e?.format==="spec",i=o?Xe("minimal"):s,a=[];this._collectObserveTargets("",a);let u=new Map;for(let[E,g]of a)u.set(g,E);let d=[];{let E=a.map(([,S])=>S),g=new Set(u.values()),b=0;for(;E.length>0;){let S=E.shift();if(S instanceof V)for(let x of S._deps){let _=x.node;if(u.has(_))continue;let O=_.name??"",k=O;if(!k||g.has(k))if(O){let C=2;for(;g.has(`${O}#${C}`);)C++;k=`${O}#${C}`}else for(k=`__internal__/${b++}`;g.has(k);)k=`__internal__/${b++}`;u.set(_,k),g.add(k),d.push([k,_]),E.push(_)}}}let c=[...a,...d],h={};for(let[E,g]of c){if(n!=null&&!g.allowsObserve(n))continue;let b=St(g,i),S=g instanceof V?g._deps.map(k=>u.get(k.node)??k.node.name??""):[],{name:x,..._}=b,O={..._,deps:S};if(!o){let k=this._annotations.get(E);k!=null&&(O.annotation=k)}if(r!=null)if(typeof r=="function"){let k=r;if(!(k.length>=2?k(E,O):k(O)))continue}else{let k=!0;for(let[C,D]of Object.entries(r)){let G=C==="deps_includes"?"depsIncludes":C==="meta_has"?"metaHas":C;if(G==="depsIncludes"){if(!O.deps.includes(String(D))){k=!1;break}continue}if(G==="metaHas"){if(!Object.hasOwn(O.meta??{},String(D))){k=!1;break}continue}if(O[G]!==D){k=!1;break}}if(!k)continue}h[E]=O}let p=new Set(Object.keys(h)),f=[];for(let[E,g]of c)if(g instanceof V)for(let b of g._deps){let S=u.get(b.node);S!=null&&f.push([S,E])}f.sort((E,g)=>E[0]<g[0]?-1:E[0]>g[0]?1:E[1]<g[1]?-1:E[1]>g[1]?1:0);let l=f.map(([E,g])=>({from:E,to:g}));(n!=null||r!=null)&&(l=l.filter(E=>p.has(E.from)&&p.has(E.to)));let m=this._collectSubgraphs(""),T=n!=null||r!=null?m.filter(E=>{let g=`${E}${I}`;return[...p].some(b=>b===E||b.startsWith(g))}):m,N=this,w=e,y={name:this.name,nodes:h,edges:l,subgraphs:T,expand(E){let g={...w,format:void 0};return Array.isArray(E)?(g.fields=E,g.detail=void 0):(g.detail=E,g.fields=void 0),N.describe(g)}},v=e??{},R=v.format;return R==="json"?Dr(y,v):R==="pretty"?Mr(y,v):R==="mermaid"?En(y,v):R==="mermaid-url"?Gr(y,v):R==="d2"?Lr(y,v):R==="ascii"?mn(y,v):y}_collectSubgraphs(e){let n=[];for(let r of[...this._mounts.keys()].sort()){let s=e===""?r:`${e}${r}`;n.push(s),n.push(...this._mounts.get(r)._collectSubgraphs(`${s}${I}`))}return n}resourceProfile(e){return yn(this,e)}reachable(e,n,r={}){return r.withDetail===!0?Mt(this.describe(),e,n,{...r,withDetail:!0}):Mt(this.describe(),e,n,r)}explain(e,n,r){return r?.reactive===!0?this._explainReactive(e,n,r):this._explainStatic(e,n,r)}_explainStatic(e,n,r){let s=this.describe({detail:"full"}),o=new Map(this._annotations),i=new Map;for(let[a,u]of Object.entries(s.nodes))u.lastMutation!=null&&i.set(a,u.lastMutation);return en(s,e,n,{...r?.maxDepth!=null?{maxDepth:r.maxDepth}:{},...r?.findCycle===!0?{findCycle:!0}:{},annotations:o,lastMutations:i})}_describeReactive(e){let n={...e,reactive:!1},r=e.reactiveName??"describe",s=0,o=Q(s,{name:`${r}_version`}),i=this.observe({timeline:!0,structured:!0}),a=!1,u=!1,d=()=>{a||u||(a=!0,Ce(()=>{a=!1,!u&&(s+=1,o.emit(s))}))},c=i.onEvent(w=>{let y=w.type;y!=="data"&&y!=="error"&&y!=="complete"&&y!=="teardown"||d()}),h=[],p=new WeakSet,f=w=>{if(p.has(w)||u)return;p.add(w);let y=w.topology.subscribe(v=>{for(let R of v){if(R[0]!==P)continue;let E=R[1];if(d(),E.kind==="added"&&E.nodeKind==="mount"){let g=w._mounts.get(E.name);g!=null&&f(g)}}});h.push(y);for(let v of w._mounts.keys()){let R=w._mounts.get(v);R!=null&&f(R)}};f(this);let l,m=e.actor;wn(m)&&(l=m.subscribe(w=>{let y=!1,v=!1;for(let R of w){let E=R[0];E===P?y=!0:(E===H||E===$||E===B)&&(v=!0)}y&&d(),v&&(l?.(),l=void 0,d())}));let T;try{T=W([o],()=>this.describe(n),{name:r,describeKind:"derived",meta:{domain:"audit",kind:"describe"},equals:(w,y)=>w===y})}catch(w){c(),l?.();for(let y of h)y();throw i.dispose(),w}let N=oe(T);return{node:T,dispose(){u=!0,c(),l?.();for(let w of h)w();h.length=0,i.dispose(),N()}}}_explainReactive(e,n,r){let s=0,o=Q(s,{name:"explain_version"}),i=this.observe({timeline:!0,structured:!0}),a=!1,u=!1,d=i.onEvent(f=>{let l=f.type;l!=="data"&&l!=="error"&&l!=="complete"&&l!=="teardown"||a||u||(a=!0,Ce(()=>{a=!1,!u&&(s+=1,o.emit(s))}))}),c={...r?.maxDepth!=null?{maxDepth:r.maxDepth}:{},...r?.findCycle===!0?{findCycle:!0}:{}},h;try{h=W([o],()=>this._explainStatic(e,n,c),{name:r?.name??"explain",describeKind:"derived",meta:{domain:"audit",kind:"explain_path",from:e,to:n},equals:(f,l)=>f.found===l.found&&f.reason===l.reason&&f.steps.length===l.steps.length&&jr(f.steps,l.steps)})}catch(f){throw d(),i.dispose(),f}let p=oe(h);return{node:h,dispose(){u=!0,d(),i.dispose(),p()}}}_pathsMatching(e){let n=ot(e),r=[];return this._collectObserveTargets("",r),r.map(([s])=>s).filter(s=>n.test(s))}_collectObserveTargets(e,n){for(let r of[...this._mounts.keys()].sort()){let s=e===""?r:`${e}${I}${r}`;this._mounts.get(r)._collectObserveTargets(s,n)}for(let r of[...this._nodes.keys()].sort()){let s=this._nodes.get(r),o=e===""?r:`${e}${I}${r}`;n.push([o,s]),this._appendMetaObserveTargets(o,s,n)}}_appendMetaObserveTargets(e,n,r){for(let s of Object.keys(n.meta).sort()){let o=n.meta[s],i=`${e}${I}${ee}${I}${s}`;r.push([i,o]),this._appendMetaObserveTargets(i,o,r)}}observe(e,n){let r=typeof e=="string",o=_n(r?n:e),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(r){let c=e,h=this.resolve(c);if(a!=null&&!h.allowsObserve(a))throw new X({actor:a,action:"observe",nodeName:c});return i?this._buildStructuredObserver([[c,h]],o,"one"):{subscribe(p){return h.subscribe(p)},up(p){try{h.up?.(p)}catch(f){if(f instanceof X)return;throw f}}}}let u=[];this._collectObserveTargets("",u),u.sort((c,h)=>c[0]<h[0]?-1:c[0]>h[0]?1:0);let d=a==null?u:u.filter(([,c])=>c.allowsObserve(a));return i?this._buildStructuredObserver(d,o,"all"):{subscribe:c=>{let h=d.map(([p,f])=>f.subscribe(l=>{c(p,l)}));return()=>{for(let p of h)p()}},up:(c,h)=>{try{this.resolve(c).up?.(h)}catch(p){if(p instanceof X)return;throw p}}}}_buildStructuredObserver(e,n,r){let s=r==="one"?e[0]?.[0]:void 0,o=i=>{if(r==="one"&&s!=null){let c=this.resolve(s);return this._buildStructuredObserver([[s,c]],i,"one")}let a=[];this._collectObserveTargets("",a),a.sort((c,h)=>c[0]<h[0]?-1:c[0]>h[0]?1:0);let u=i.actor,d=u==null?a:a.filter(([,c])=>c.allowsObserve(u));return this._buildStructuredObserver(d,i,"all")};return this._createObserveResult(e,n,o)}_createObserveResult(e,n,r){let s=n.timeline===!0,o=n.causal===!0,i=n.derived===!0,a=n.detail==="minimal",u=this.config.inspectorEnabled,d=(o||i)&&u,c=n.maxEvents,h=c!=null&&c>0?new Ie(c):null,p=[],f=new Set,l={},m=new Set,T=0,N=0,w=0,y=0,v=0,R=0,E=!1,g=!1,b=0,S=new Map,x=new Map,_=new Map,O=A=>{h?h.push(A):p.push(A);for(let L of f)L(A)},k=()=>s?{timestamp_ns:xe(),in_batch:Fe(),batch_id:b}:{},C=(A,L)=>{if(!(!d||!(A instanceof V)))return A._setInspectorHook(K=>{if(K.kind==="dep_message")S.set(A,K.depIndex);else if(K.kind==="run"){let Ne=K.batchData.map((M,j)=>M!=null&&M.length>0?M.at(-1):K.prevData[j]);x.set(A,Ne);let Y=K.batchData.map(M=>M!=null?[...M]:void 0);_.set(A,Y),i&&O({type:"derived",path:L,dep_values:Ne,dep_batches:Y,...k()})}})},D=A=>{let L=S.get(A),K=x.get(A);if(!o||K==null)return{};let Y=(L!=null&&L>=0&&A instanceof V?A._deps[L]:void 0)?.node,M=Y?.v,j=_.get(A);return{trigger_dep_index:L,trigger_dep_name:Y?.name,...M!=null?{trigger_version:{id:M.id,version:M.version}}:{},dep_values:[...K],...j!=null?{dep_batches:j}:{}}},G=[],z=[];for(let[A,L]of e){let K=C(L,A);K&&G.push(K),z.push(L.subscribe(Ne=>{b++;for(let Y of Ne){let M=Y[0],j=k();if(M===P){l[A]=Y[1];let pt=L instanceof V?L.lastMutation?.actor??Ee:Ee;O({type:"data",path:A,data:Y[1],actor:pt,...j,...D(L)})}else if(a)M===q?T++:M===U?N++:M===Z?w++:M===te?y++:M===re?v++:M===B?R++:M===H&&!m.has(A)?E=!0:M===$&&(g=!0,m.add(A));else if(M===q)T++,O({type:"dirty",path:A,...j});else if(M===U)N++,O({type:"resolved",path:A,...j,...D(L)});else if(M===Z)w++,O({type:"invalidate",path:A,...j});else if(M===te)y++,O({type:"pause",path:A,lockId:Y[1],...j});else if(M===re)v++,O({type:"resume",path:A,lockId:Y[1],...j});else if(M===H)m.has(A)||(E=!0),O({type:"complete",path:A,...j});else if(M===$){g=!0,m.add(A);let pt=L instanceof V?L.lastMutation?.actor??Ee:Ee;O({type:"error",path:A,data:Y[1],actor:pt,...j})}else M===B&&(R++,O({type:"teardown",path:A,...j}))}}))}let ue=!1,ce=()=>{if(!ue){ue=!0;for(let A of z)A();for(let A of G)A();for(let A of be)A({value:void 0,done:!0});be.length=0}},Re=[],be=[];f.add(A=>{let L=be.shift();L?L({value:A,done:!1}):Re.push(A)});let Lt={get values(){return l},get dirtyCount(){return T},get resolvedCount(){return N},get invalidateCount(){return w},get pauseCount(){return y},get resumeCount(){return v},get teardownCount(){return R},get events(){return h?h.toArray():[...p]},get anyCompletedCleanly(){return E},get anyErrored(){return g},get completedWithoutErrors(){return E&&!g},onEvent(A){return f.add(A),()=>f.delete(A)},dispose:ce,expand(A){ce();let L={...n};return typeof A=="string"?L.detail=A:Object.assign(L,A),r(_n(L))},[Symbol.asyncIterator](){return{next(){return Re.length>0?Promise.resolve({value:Re.shift(),done:!1}):ue?Promise.resolve({value:void 0,done:!0}):new Promise(A=>be.push(A))},return(){return ce(),Promise.resolve({value:void 0,done:!0})}}}};return n.format!=null&&this._attachFormatLogger(Lt,n),Lt}_attachFormatLogger(e,n){let r=n.format;if(r==null)return;let s=n.logger??(l=>console.log(l)),o=n.includeTypes?new Set(n.includeTypes):null,i=n.excludeTypes?new Set(n.excludeTypes):null,a=o==null&&i==null?()=>!0:l=>(o==null||o.has(l))&&(i==null||!i.has(l)),u=Vr(n.theme),d=r==="stage-log"?xe():0,c=l=>l==null?"":n.stageLabels?.[l]??l,h=(l,m)=>l.length>m?`${l.slice(0,m-1)}\u2026`:l,p=l=>l.type==="data"||l.type==="error"?h(it(l.data),120):"",f=l=>{if(r==="stage-log"){let g=(xe()-d)/1e9,b=c(l.path).padEnd(9);if(l.type==="data"){let S=p(l);return`[${g.toFixed(3)}s] ${b} \u2190${S?` ${S}`:""}`}if(l.type==="error"){let S=p(l);return`[${g.toFixed(3)}s] ${b} \u2717${S?` ${S}`:""}`}return l.type==="complete"?`[${g.toFixed(3)}s] ${b} \u25A0 complete`:`[${g.toFixed(3)}s] ${b} ${l.type}`}if(r==="json")try{return JSON.stringify(l)}catch{return JSON.stringify({type:l.type,path:l.path,data:"[unserializable]"})}let m=u[l.type]??"",T=l.path?`${u.path}${l.path}${u.reset} `:"",N=l.type==="data"||l.type==="error",w=l.type==="pause"||l.type==="resume",y=N?` ${it(l.data)}`:w?` ${it(l.lockId)}`:"",v=l.type==="data"||l.type==="resolved"||l.type==="derived"?l:void 0,R=v?.trigger_dep_name!=null?` <- ${v.trigger_dep_name}`:v?.trigger_dep_index!=null?` <- #${v.trigger_dep_index}`:"",E=l.in_batch?" [batch]":"";return`${T}${m}${l.type.toUpperCase()}${u.reset}${y}${R}${E}`};e.onEvent(l=>{a(l.type)&&s(f(l),l)})}addDisposer(e){return this._disposers.add(e),()=>{this._disposers.delete(e)}}destroy(){bn(this._disposers,this.name),this.signal([[B]],{internal:!0}),bn(this._storageDisposers,this.name);for(let e of[...this._mounts.values()])e._parent=void 0,e._destroyClearOnly();this._mounts.clear(),this._nodes.clear(),this._parent=void 0,this._destroyed=!0}get destroyed(){return this._destroyed}_destroyClearOnly(){for(let e of[...this._mounts.values()])e._parent=void 0,e._destroyClearOnly();this._mounts.clear(),this._nodes.clear(),this._parent=void 0,this._destroyed=!0}snapshot(e){let{expand:n,...r}=this.describe({detail:"full"}),s={};for(let a of Object.keys(r.nodes).sort()){let{lastMutation:u,guard:d,...c}=r.nodes[a];s[a]=c}let o=[...r.subgraphs].sort(),i={...r,version:1,nodes:s,subgraphs:o};if(e?.format==null)return i;if(e.format==="json-string")return JSON.stringify(i);if(e.format==="bytes"){if(e.codec==null)throw new Error("snapshot({format: 'bytes'}) requires a `codec` name");let a=this.config.lookupCodec(e.codec);if(a==null)throw new Error(`snapshot: codec "${e.codec}" is not registered on this graph's config. Call config.registerCodec(...) before creating nodes.`);return Ht(a,a.encode(i))}throw new Error(`snapshot: unknown format "${String(e.format)}"`)}static decode(e,n){let r=n?.config??ge,{codec:s,codecVersion:o,payload:i}=qt(e,r);return s.decode(i,o)}restore(e,n){if(vn(e),e.name!==this.name)throw new Error(`Graph "${this.name}": restore snapshot name "${e.name}" does not match this graph`);let r=n?.only==null?null:(Array.isArray(n.only)?n.only:[n.only]).map(o=>ot(o)),s=n?.includeProducers===!0;for(let o of Object.keys(e.nodes).sort()){if(r!==null&&!r.some(a=>a.test(o)))continue;let i=e.nodes[o];if(i!==void 0){if(!("value"in i)||i.value===void 0){"value"in i&&i.value===void 0&&n?.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 u=this.tryResolve(o)?.v;if(u!=null&&u.id===i.v.id&&u.version===i.v.version)continue}try{this.set(o,i.value)}catch(a){n?.onError?.(o,a)}}}}}static fromSnapshot(e,n){vn(e);let r=typeof n=="function"?n:n?.build,s=typeof n=="function"?void 0:n?.factories,o=new t(e.name);if(r)return r(o),o.restore(e),o;for(let f of[...e.subgraphs].sort((l,m)=>{let T=l.split(I).length,N=m.split(I).length;return T!==N?T-N:l<m?-1:l>m?1:0})){let l=f.split(I),m=o;for(let T of l)m._mounts.has(T)||m.mount(T,new t(T)),m=m._mounts.get(T)}let i=s?Object.entries(s).map(([f,l])=>({re:ot(f),factory:l})):[],a=f=>{for(let l of i)if(l.re.test(f))return l.factory},u=f=>{let l=f.split(I),m=l.pop();if(m==null||m.length===0)throw new Error(`invalid snapshot path "${f}"`);let T=o;for(let N of l){let w=T._mounts.get(N);if(!w)throw new Error(`unknown mount "${N}" in path "${f}"`);T=w}return[T,m]},d=Object.entries(e.nodes).filter(([f])=>!f.includes(`${I}${ee}${I}`)).sort((f,l)=>f[0]<l[0]?-1:f[0]>l[0]?1:0),c=new Map(d),h=new Map,p=!0;for(;c.size>0&&p;){p=!1;for(let[f,l]of[...c.entries()]){let m=l?.deps??[];if(!m.every(R=>h.has(R)))continue;let[T,N]=u(f),w={...l?.meta??{}},y=a(f),v;if(l?.type==="state")v=Q(l.value,{meta:w});else{if(y==null)continue;v=y(N,{path:f,type:l.type,value:l.value,meta:w,deps:m,resolvedDeps:m.map(R=>h.get(R))})}T.add(v,{name:N}),h.set(f,v),c.delete(f),p=!0}}if(c.size>0){let f=[...c.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(e),o}toJSON(){return this.snapshot()}attachSnapshotStorage(e,n={}){let r=e.map(d=>({tier:d,debounceMs:Math.max(0,d.debounceMs??0),compactEvery:Math.max(1,d.compactEvery??10),timer:void 0,seq:0,lastSnapshot:void 0,lastFingerprint:"",disposed:!1,savePending:void 0}));n.autoRestore===!0&&this._cascadeRestore(e,n.onError);let s=(d,c)=>{if(d.disposed)return;let h=Rr(c.nodes);if(d.lastSnapshot!=null&&h!==""&&h===d.lastFingerprint)return;let p=d.seq+1,f=ne(),T=d.lastSnapshot==null||p%d.compactEvery===0?{name:this.name,mode:"full",snapshot:c,seq:p,timestamp_ns:f,format_version:ye}:{name:this.name,mode:"diff",diff:Rn(d.lastSnapshot,c),seq:p,timestamp_ns:f,format_version:ye};if(d.tier.filter&&!d.tier.filter(T))return;let N;try{N=d.tier.save(T)}catch(w){n.onError?.(w,d.tier);return}if(N&&typeof N.then=="function"){let v=(d.savePending??Promise.resolve()).then(()=>N,()=>N).then(()=>{d.disposed||(d.seq=p,d.lastSnapshot=c,d.lastFingerprint=h)},R=>{n.onError?.(R,d.tier)});d.savePending=v.finally(()=>{d.savePending===v&&(d.savePending=void 0)})}else d.seq=p,d.lastSnapshot=c,d.lastFingerprint=h},o=(d,c)=>{try{s(d,c)}catch(h){n.onError?.(h,d.tier)}},i=(d,c)=>{if(!c.some(l=>{let m=this.config.messageTier(l[0]);return m>=3&&m<5}))return;if(n.filter){let l=this.tryResolve(d);if(l==null)return;let m=St(l,Xe("standard"));if(!n.filter(d,m))return}let p,f=()=>(p==null&&(p=this.snapshot()),p);for(let l of r)l.disposed||(l.debounceMs===0?o(l,f()):(l.timer==null&&(l.timer=new tt),l.timer.start(l.debounceMs,()=>{l.disposed||o(l,this.snapshot())})))},a;if(n.paths!=null){let c=(typeof n.paths=="string"?this._pathsMatching(n.paths):n.paths).map(h=>{let p=this.tryResolve(h);return p==null?()=>{}:p.subscribe(f=>i(h,f))});a=()=>{for(let h of c)h()}}else a=this.observe().subscribe((d,c)=>i(d,c));let u=()=>{a();for(let d of r)d.disposed=!0,d.timer?.cancel();this._storageDisposers.delete(u)};return this._storageDisposers.add(u),{dispose:u}}async _cascadeRestore(e,n){for(let r of e){let s;try{s=await r.load?.()}catch(i){n?.(i,r);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===ye&&o.nodes!=null)return this.restore(o),!0}catch(i){n?.(i,r)}}return!1}static async fromStorage(e,n,r){for(let s of n){let o;try{o=await s.load?.()}catch(u){r?.onError?.(u,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===ye&&i.nodes!=null?i:void 0;if(a!=null)try{return t.fromSnapshot(a,r)}catch(u){r?.onError?.(u,s)}}throw new Error(`Graph.fromStorage: no tier held a restorable record for "${e}" across ${n.length} tier(s)`)}_annotations=new Map;_traceRing;trace(e,n,r){if(e!=null&&n!=null){if(this.tryResolve(e)==null)return;if(this._annotations.set(e,n),this.config.inspectorEnabled){let s={path:e,annotation:n,timestamp_ns:xe(),...r?.actor!=null?{actor:r.actor}:{}};this._traceRing.push(s)}return}return e!=null?this.config.inspectorEnabled?this._annotations.get(e):void 0:this.config.inspectorEnabled?this._traceRing.toArray():[]}annotation(e){return this._annotations.get(e)}clearTrace(){this._annotations.clear(),this._traceRing.clear()}pruneTrace(e){let n=this._traceRing.toArray().filter(s=>!e(s)),r=this._traceRing.size-n.length;this._traceRing.clear();for(let s of n)this._traceRing.push(s);return r}static diff(e,n){let r=new Set(Object.keys(e.nodes)),s=new Set(Object.keys(n.nodes)),o=[...s].filter(w=>!r.has(w)).sort(),i=[...r].filter(w=>!s.has(w)).sort(),a=[],u=[];for(let w of r){if(!s.has(w))continue;let y=e.nodes[w],v=n.nodes[w],R=y.v,E=v.v;R!=null&&E!=null&&R.id===E.id&&R.version!==E.version&&u.push({path:w,id:R.id,from:R.version,to:E.version});let g=R!=null&&E!=null&&R.id===E.id&&R.version===E.version;for(let b of["type","status","sentinel"]){let S=y[b],x=v[b];S!==x&&a.push({path:w,field:b,from:S,to:x})}if(!g)for(let b of["value","meta"]){let S=y[b],x=v[b];Nr(S,x)||a.push({path:w,field:b,from:S,to:x})}}let d=w=>`${w.from} ${w.to}`,c=new Set(e.edges.map(d)),h=new Set(n.edges.map(d)),p=n.edges.filter(w=>!c.has(d(w))),f=e.edges.filter(w=>!h.has(d(w))),l=new Set(e.subgraphs),m=new Set(n.subgraphs),T=[...m].filter(w=>!l.has(w)).sort(),N=[...l].filter(w=>!m.has(w)).sort();return{nodesAdded:o,nodesRemoved:i,nodesChanged:a,versionChanges:u,edgesAdded:p,edgesRemoved:f,subgraphsAdded:T,subgraphsRemoved:N}}};function Rn(t,e){let n=ae.diff(t,e),r={};for(let s of n.nodesAdded){let o=e.nodes[s];o!=null&&(r[s]=o)}return{...n,nodesAddedFull:r}}function Mt(t,e,n,r={}){let s={paths:[],depths:new Map,truncated:!1};if(!e)return r.withDetail?s:[];if(!r.both&&n!=="upstream"&&n!=="downstream")throw new Error('reachable: direction must be "upstream" or "downstream"');let o=r.maxDepth;if(o!=null&&(!Number.isInteger(o)||o<0))throw new Error("reachable: maxDepth must be an integer >= 0");if(o===0)return r.withDetail?s:[];let i=new Map,a=new Map,u=new Map,d=new Map,c=new Set;for(let[y,v]of Object.entries(t.nodes)){if(!y)continue;c.add(y);let R=v.deps??[];i.set(y,R);for(let E of R)E&&(c.add(E),a.has(E)||a.set(E,new Set),a.get(E).add(y))}for(let y of t.edges){if(y==null||typeof y!="object")continue;let v=typeof y.from=="string"?y.from:"",R=typeof y.to=="string"?y.to:"";!v||!R||(c.add(v),c.add(R),d.has(v)||d.set(v,new Set),d.get(v).add(R),u.has(R)||u.set(R,new Set),u.get(R).add(v))}if(!c.has(e))return r.withDetail?s:[];let h=r.both===!0,p=y=>{if(h){let g=i.get(y)??[],b=u.get(y),S=a.get(y),x=d.get(y),_=[...g];return b&&_.push(...b),S&&_.push(...S),x&&_.push(...x),_}if(n==="upstream"){let g=i.get(y)??[],b=u.get(y);return b?[...g,...b]:g}let v=a.get(y),R=d.get(y),E=v?[...v]:[];return R&&E.push(...R),E},f=new Set([e]),l=new Map,m=[{path:e,depth:0}],T=0,N=!1;for(;T<m.length;){let y=m[T++];if(o!=null&&y.depth>=o){p(y.path).length>0&&(N=!0);continue}for(let v of p(y.path))!v||f.has(v)||(f.add(v),l.set(v,y.depth+1),m.push({path:v,depth:y.depth+1}))}let w=[...l.keys()].sort((y,v)=>y<v?-1:y>v?1:0);return r.withDetail?{paths:w,depths:l,truncated:N}:w}function jr(t,e){if(t.length!==e.length)return!1;for(let n=0;n<t.length;n++){let r=t[n],s=e[n];if(r.path!==s.path||r.type!==s.type||r.status!==s.status||r.hop!==s.hop||r.dep_index!==s.dep_index||r.annotation!==s.annotation||r.value!==s.value||r.lastMutation!==s.lastMutation)return!1;let o=r.v,i=s.v;if(o!==i&&(o==null||i==null||o.id!==i.id||o.version!==i.version))return!1}return!0}var de=class extends Error{constructor(e,n){super(e,n),this.name=this.constructor.name}},at=class extends de{constructor(n,r){super(`Duplicate ${n} registration: "${r}"`);this.kind=n;this.registrationName=r}},dt=class extends de{constructor(n,r,s){super(`Command "${n}" emitted undeclared event "${r}". Declared emits: [${s.join(", ")}]`);this.commandName=n;this.eventName=r;this.declaredEmits=s}},ut=class extends de{constructor(n,r,s){super(`Optimistic concurrency conflict on aggregate "${n}": expected version ${r}, got ${s}`);this.aggregateId=n;this.expected=r;this.actual=s}},ct=class extends de{constructor(n){super(`Unknown command: "${n}". Register with command() first.`);this.commandName=n}},Pe=class extends de{constructor(n,r){super(`Command handler "${n}" threw: ${r instanceof Error?r.message:String(r)}`,{cause:r});this.commandName=n}};var $e=class extends de{constructor(n,r){super(`Projection "${n}" rebuild failed: ${r instanceof Error?r.message:String(r)}`,{cause:r});this.projectionName=n}};pe();Me();var Hr=Te((t,e)=>{t("observe"),t("signal"),e("write")});function lt(t){let e=Le([],{name:t.name,maxSize:t.retainedLimit??1024,guard:t.guard??Hr,...t.versioning!=null?{versioning:t.versioning}:{}});return e.withLatest(),t.graph&&t.graph.add(e.entries,{name:t.name}),e}function Nn(t,e,n=0){let r=Q(n,{name:e,describeKind:"state"});return t.add(r,{name:e}),r}function kn(t,e,n,r=0){let s={},o=new ae(e);for(let i of n){let a=Q(r,{name:i,describeKind:"state"});o.add(a,{name:i}),s[i]=a}return t.mount(e,o),s}Nt();function An(t,e,n){return{[t]:!0,[`${t}_type`]:e,...n??{}}}var qr=Te((t,e)=>{t("write"),t("signal"),e("observe")}),Ur=Te((t,e)=>{t("observe"),t("signal"),e("write")}),Cn=Te((t,e)=>{t("observe"),t("signal"),e("write")});function Ve(t,e){return An("cqrs",t,e)}function Gt(t){if(t===null||typeof t!="object"||Object.isFrozen(t))return t;for(let e of Object.keys(t))Gt(t[e]);return Object.freeze(t)}var Wr=t=>`${t.type}::${t.aggregateId??"__default__"}`,Kr=t=>t.commandName,Yr=t=>t.eventType,ft=class extends ae{_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=lt({name:"dispatches",retainedLimit:this._retainedLimit,graph:this}),this.audit=this.dispatches,this.aggregateEvictions=lt({name:"aggregateEvictions",retainedLimit:this._retainedLimit,graph:this}),this._dispatchSeqCursor=Nn(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 r=n.indexOf("::");if(r<0)continue;let s=n.slice(0,r),o=n.slice(r+2),i=this._aggregateVersions.get(n)??0;this._aggregateVersions.delete(n);let a=this._eventLogsByAggregate.get(s);a&&(a.delete(o),a.size===0&&this._eventLogsByAggregate.delete(s)),this.aggregateEvictions.append({aggregateId:o,type:s,lastVersion:i,t_ns:ne()})}}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,r]of this._eventLogs){let s=r.log.attachStorage(e),o=this._attachedTierDisposers.get(n);o||(o=[],this._attachedTierDisposers.set(n,o)),o.push(s)}for(let[n,r]of this._eventLogsByAggregate)for(let[s,o]of r){let i=`${n}::${s}`,a=o.log.attachStorage(e),u=this._attachedTierDisposers.get(i);u||(u=[],this._attachedTierDisposers.set(i,u)),u.push(a)}return()=>{let n=this._attachedEventTiers.indexOf(e);n>=0&&this._attachedEventTiers.splice(n,1)}}_autoWireStreamStorage(e,n){if(this._attachedEventTiers.length===0)return;let r=this._attachedTierDisposers.get(e);r||(r=[],this._attachedTierDisposers.set(e,r));for(let s of this._attachedEventTiers)r.push(n.attachStorage(s))}_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 r=this._eventLogs.get(e);if(r)return r.node;let s=Le([],{name:e,versioning:0,maxSize:this._retainedLimit});s.withLatest();let o=s.entries,i=W([o],([a])=>a,{name:e,describeKind:"state",meta:Ve("event",{event_name:e}),guard:Cn,initial:o.cache});return this.add(i,{name:e}),this._keepaliveDisposers.push(oe(i)),this._eventLogs.set(e,{log:s,node:i}),this._autoWireStreamStorage(e,s),i}_ensureAggregateStream(e,n){this._eventLogs.has(e)||this.event(e);let r=this._eventLogsByAggregate.get(e);r||(r=new Map,this._eventLogsByAggregate.set(e,r));let s=`${e}::${n}`;this._touchAggregate(s);let o=r.get(n);if(o)return o;let i=`${e}_${n.replace(/[^a-zA-Z0-9_-]/g,"_")}`,a=Le([],{name:i,versioning:0,maxSize:this._retainedLimit});a.withLatest();let u=a.entries,d=W([u],([f])=>f,{name:i,describeKind:"state",meta:Ve("event_aggregate",{event_name:e,aggregate_id:n}),guard:Cn,initial:u.cache}),c=i,h=0;for(;this.nameOf(this.resolveOptional(c)??d)===c&&(h+=1,c=`${i}_${h}`,this.resolveOptional(c)!==void 0););try{this.add(d,{name:c})}catch{}this._keepaliveDisposers.push(oe(d));let p={log:a,node:d};return r.set(n,p),this._autoWireStreamStorage(`${e}::${n}`,a),this._enforceAggregateLru(),p}resolveOptional(e){try{return this.resolve(e)}catch{return}}_appendEvent(e,n,r){let s=this._eventLogs.get(e);if(s||(this.event(e),s=this._eventLogs.get(e)),s.node.status==="completed"||s.node.status==="errored")throw new Error(`Cannot dispatch to terminated event stream "${e}" (status: ${s.node.status}).`);let o,i;if(r?.aggregateId!==void 0){let c=`${e}::${r.aggregateId}`;o=(this._aggregateVersions.get(c)??0)+1,this._aggregateVersions.set(c,o),i=this._ensureAggregateStream(e,r.aggregateId)}let a=s.log.entries.v,u=this._freezeEventPayload?Gt(n):n,d={type:e,payload:u,timestampNs:ne(),seq:++this._seq,...r?.aggregateId!==void 0?{aggregateId:r.aggregateId}:{},...o!==void 0?{aggregateVersion:o}:{},...r?.correlationId!==void 0?{correlationId:r.correlationId}:{},...r?.causationId!==void 0?{causationId:r.causationId}:{},...r?.metadata!==void 0?{metadata:Object.freeze({...r.metadata})}:{},...r?.handlerVersion!==void 0?{handlerVersion:r.handlerVersion}:{},...a!=null?{v0:{id:a.id,version:a.version}}:{}};return s.log.append(d),i&&i.log.append(d),d}command(e,n){if(this._commandRegs.has(e))throw new at("command",e);let r=typeof n=="function"?{handler:n}:n,s=Q(void 0,{name:e,describeKind:"state",meta:{...Ve("command",{command_name:e}),error:null},guard:qr});if(this.add(s,{name:e}),this._commandRegs.set(e,{handler:r.handler,...r.emits!==void 0?{emits:r.emits}:{},...r.handlerVersion!==void 0?{handlerVersion:r.handlerVersion}:{}}),r.emits)for(let o of r.emits)this._eventLogs.has(o)||this.event(o);return s}dispatch(e,n,r){let s=this._commandRegs.get(e);if(!s)throw new ct(e);if(r?.aggregateId!==void 0&&r.expectedAggregateVersion!==void 0&&s.emits!==void 0){let p=0;for(let f of s.emits){let l=this._aggregateVersions.get(`${f}::${r.aggregateId}`);l!==void 0&&l>p&&(p=l)}if(p!==r.expectedAggregateVersion)throw new ut(r.aggregateId,r.expectedAggregateVersion,p)}let o=this.resolve(e),i=this._freezeCommandPayload?Gt(n):n,a=[],u=ne(),d=0,c,h=!1;try{we(()=>{d=this._bumpDispatchSeq(),o.emit(i,{internal:!0});try{s.handler(i,{emit:(p,f)=>{if(s.emits!==void 0&&!s.emits.includes(p))throw new dt(e,p,s.emits);a.push(p),this._appendEvent(p,f,{...r?.aggregateId!==void 0?{aggregateId:r.aggregateId}:{},...r?.correlationId!==void 0?{correlationId:r.correlationId}:{},...r?.causationId!==void 0?{causationId:r.causationId}:{},...r?.metadata!==void 0?{metadata:Object.freeze({...r.metadata})}:{},...s.handlerVersion!==void 0?{handlerVersion:s.handlerVersion}:{}})}}),o.meta.error.emit(null,{internal:!0}),this.dispatches.append({commandName:e,payload:i,status:"success",emittedEvents:[...a],t_ns:u,seq:d,...s.handlerVersion!==void 0?{handlerVersion:s.handlerVersion}:{}})}catch(p){throw c=p,h=!0,p}})}catch(p){if(h){o.meta.error.emit(c,{internal:!0});let f=c instanceof Error?c.name:typeof c,l=c instanceof Pe?c:new Pe(e,c);this.dispatches.append({commandName:e,payload:i,status:"failed",error:l,errorType:f,emittedEvents:[...a],t_ns:u,seq:d,...s.handlerVersion!==void 0?{handlerVersion:s.handlerVersion}:{}})}throw h?c:p}}projection(e){let{name:n,events:r,reducer:s,initial:o}=e,i=e.mode??"scan",a=e.freezeInputs??!0,u=e.snapshot,d=r.map(x=>(this._eventLogs.has(x)||this.event(x),this._eventLogs.get(x).node));function c(x){x.sort((_,O)=>_.timestampNs-O.timestampNs||_.seq-O.seq||(_.aggregateId??"").localeCompare(O.aggregateId??""))}function h(x){let _=[];for(let O of x)_.push(...O);return c(_),_}let p=d.map(x=>x.cache??[]),f=h(p),l=a?Object.freeze(f):f,m=0,T=o;i==="scan"&&f.length>0&&(T=s(o,l),m=f.length);let N=i==="replay"?s(o,l):T,w=u?.saveDebounceMs??1e3,y=u?.saveEvery??1e3,v,R=0;function E(x){if(u?.save){if(R+=1,R>=y){R=0,v!==void 0&&(clearTimeout(v),v=void 0);let _=u.save(x);_ instanceof Promise&&_.catch(()=>{});return}v!==void 0&&clearTimeout(v),v=setTimeout(()=>{v=void 0,R=0;let _=u.save(x);_ instanceof Promise&&_.catch(()=>{})},w)}}let g=W(d,x=>{let _=h(x),O;if(i==="replay"){let k=a?Object.freeze(_):_;O=s(o,k)}else{let k=_.slice(m);m=_.length;let C=a?Object.freeze(k):k;O=s(T,C),T=O}return E(O),O},{name:n,describeKind:"derived",meta:Ve("projection",{projection_name:n,source_events:r}),guard:Ur,initial:N});return this.add(g,{name:n}),this._keepaliveDisposers.push(oe(g)),this._keepaliveDisposers.push(()=>{v!==void 0&&(clearTimeout(v),v=void 0)}),this._projections.add(n),{node:g,rebuild:async x=>{try{let _=x?.pageSize??1e3,O=x?.fromTier??this._attachedEventTiers[0]?.[0],k=h(d.map(D=>D.cache??[])).length,C=o;if(u?.load){let D=await u.load();D!==void 0&&(C=D)}if(!O||!O.loadEntries){let D=h(d.map(z=>z.cache??[])),G=a?Object.freeze(D):D;C=s(C,G)}else{let D=new Set(r),G,z=!1;for(;!z;){let ue=await O.loadEntries({cursor:G,pageSize:_}),ce=[...ue.entries].filter(be=>D.has(be.type));c(ce);let Re=a?Object.freeze(ce):ce;C=s(C,Re),G=ue.cursor,z=!G||ue.entries.length===0}}if(i==="scan"){let D=h(d.map(z=>z.cache??[])),G=D.slice(k);if(G.length>0){let z=a?Object.freeze(G):G;C=s(C,z)}T=C,m=D.length}return g.emit(C,{internal:!0}),C}catch(_){throw new $e(n,_)}},reset:async()=>{try{let x=o;if(u?.load){let C=await u.load();C!==void 0&&(x=C)}let _=h(d.map(C=>C.cache??[])),O=a?Object.freeze(_):_,k=s(x,O);return i==="scan"&&(T=k,m=_.length),g.emit(k,{internal:!0}),k}catch(x){throw new $e(n,x)}}}}saga(e,n,r,s={}){let o=n.map(f=>(this._eventLogs.has(f)||this.event(f),this._eventLogs.get(f).node)),i=kn(this,`${e}_cursor`,n,0),a=lt({name:`${e}_invocations`,retainedLimit:this._retainedLimit,graph:this}),u=s.aggregateId,d=s.errorPolicy??"advance",c=new Map;for(let f of n){let l=i[f];c.set(f,l.cache??0);let m=l.subscribe(T=>{for(let N of T)N[0]===P&&c.set(f,N[1])});this._keepaliveDisposers.push(m)}let h={},p=se(o,(f,l)=>{let m=h.n.meta.error;for(let T=0;T<f.length;T++){let N=f[T];if(N==null||N.length===0)continue;let w=N.at(-1);if(!w)continue;let y=n[T],v=i[y],R=c.get(y)??0;if(w.length>R){let E=w.slice(R),g=R;for(let b of E){let S=b;if(u!==void 0&&S.aggregateId!==u){g+=1;continue}try{r(S),m.emit(null,{internal:!0}),a.append({eventType:y,status:"success",aggregateId:S.aggregateId,event:S,t_ns:ne(),...s.handlerVersion!==void 0?{handlerVersion:s.handlerVersion}:{}}),g+=1}catch(x){if(m.emit(x,{internal:!0}),a.append({eventType:y,status:"failed",error:x,errorType:x instanceof Error?x.name:typeof x,aggregateId:S.aggregateId,event:S,t_ns:ne(),...s.handlerVersion!==void 0?{handlerVersion:s.handlerVersion}:{}}),d==="hold")break;g+=1}}v.emit(g)}}},{name:e,describeKind:"effect",meta:{...Ve("saga",{saga_name:e,source_events:n}),error:null}});return h.n=p,this.add(p,{name:e}),this._keepaliveDisposers.push(oe(p)),this._sagas.add(e),{node:p,invocations:a,audit:a,cursors:i}}};function Jr(t,e){return new ft(t,e)}0&&(module.exports={CqrsGraph,cqrs,cqrsEventKeyOf,dispatchKeyOf,sagaInvocationKeyOf});
|
|
1
|
+
"use strict";var yt=Object.defineProperty;var zn=Object.getOwnPropertyDescriptor;var jn=Object.getOwnPropertyNames;var Bn=Object.prototype.hasOwnProperty;var q=(t,e)=>()=>(t&&(e=t(t=0)),e);var Hn=(t,e)=>{for(var n in e)yt(t,n,{get:e[n],enumerable:!0})},qn=(t,e,n,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let s of jn(e))!Bn.call(t,s)&&s!==n&&yt(t,s,{get:()=>e[s],enumerable:!(r=zn(e,s))||r.enumerable});return t};var Wn=t=>qn(yt({},"__esModule",{value:!0}),t);function Be(){return ve>0||Ae}function Bt(){return ve>0}function we(t){ve>0?Ce.push(t):t()}function xe(t){ve+=1;let e=!1;try{t()}catch(n){throw e=!0,n}finally{if(ve-=1,ve===0)if(e){if(!Ae){let n=Ce.splice(0);for(let r of n)try{r()}catch{}ce.length=0,le.length=0,_e.length=0}}else Un()}}function Un(){let t=!Ae;t&&(Ae=!0);let e=[],n=0;try{for(;ce.length>0||le.length>0||_e.length>0||t&&Ce.length>0;){if(t&&Ce.length>0){let o=Ce.splice(0);for(let i of o)try{i()}catch(a){e.push(a)}continue}if(n+=1,n>1e3)throw ce.length=0,le.length=0,_e.length=0,new Error("batch drain exceeded 1000 iterations \u2014 likely a reactive cycle");let s=(ce.length>0?ce:le.length>0?le:_e).splice(0);for(let o of s)try{o()}catch(i){e.push(i)}}}finally{t&&(Ae=!1)}if(e.length===1)throw e[0];if(e.length>1)throw new AggregateError(e,"batch drain: multiple callbacks threw")}function He(t,e,n){if(e.length===0)return;if(e.length===1){let d=n(e[0][0]);if(d<3||!Be()){t(e);return}(d>=5?_e:d===4?le:ce).push(()=>t(e));return}let r=e.length,s=r,o=r,i=r,a=0;for(;a<r&&n(e[a][0])<3;)a++;for(s=a;a<r&&n(e[a][0])===3;)a++;for(o=a;a<r&&n(e[a][0])===4;)a++;i=a;let u=Be();if(s>0){let d=e.slice(0,s);t(d)}if(o>s){let d=e.slice(s,o);u?ce.push(()=>t(d)):t(d)}if(i>o){let d=e.slice(o,i);u?le.push(()=>t(d)):t(d)}if(r>i){let d=e.slice(i,r);u?_e.push(()=>t(d)):t(d)}}var ve,Ae,ce,le,_e,Ce,De=q(()=>{"use strict";ve=0,Ae=!1,ce=[],le=[],_e=[],Ce=[]});function se(){return Math.trunc(performance.now()*1e6)}function ne(){return Date.now()*1e6}var Me=q(()=>{"use strict"});function Ht(t){return Array.isArray(t)?[...t]:[t]}function Kn(t,e){return t.has(e)||t.has("*")}function Te(t){let e=[];return t((s,o)=>{e.push({kind:"allow",actions:new Set(Ht(s)),where:o?.where??(()=>!0)})},(s,o)=>{e.push({kind:"deny",actions:new Set(Ht(s)),where:o?.where??(()=>!0)})}),(s,o)=>{let i=!1,a=!1;for(let u of e)Kn(u.actions,o)&&u.where(s)&&(u.kind==="deny"?i=!0:a=!0);return i?!1:a}}function bt(t){let e=Yn.filter(n=>t({type:n,id:""},"write"));return e.length===0?"restricted":e.includes("human")&&e.includes("llm")&&e.every(n=>n==="human"||n==="llm"||n==="system")?"both":e.length===1?e[0]:e.join("+")}var Z,Yn,fe=q(()=>{"use strict";Z=class extends Error{actor;action;nodeName;constructor(e,n){super(n??`GuardDenied: action "${String(e.action)}" denied for actor type "${String(e.actor.type)}"`),this.name="GuardDenied",this.actor=e.actor,this.action=e.action,this.nodeName=e.nodeName}get node(){return this.nodeName}};Yn=["human","llm","wallet","system"]});function qe(t){if(t==null)return Ee;let{type:e,id:n,...r}=t;return{type:e??"system",id:n??"",...r}}var Ee,We=q(()=>{"use strict";Ee={type:"system",id:""}});var Oe,P,W,U,Q,te,oe,z,H,$,pe,Ue,qt,Ke,Wt,Ut,Ye,vt,_t,wt,Je,ke=q(()=>{"use strict";Oe=Symbol.for("graphrefly/START"),P=Symbol.for("graphrefly/DATA"),W=Symbol.for("graphrefly/DIRTY"),U=Symbol.for("graphrefly/RESOLVED"),Q=Symbol.for("graphrefly/INVALIDATE"),te=Symbol.for("graphrefly/PAUSE"),oe=Symbol.for("graphrefly/RESUME"),z=Symbol.for("graphrefly/TEARDOWN"),H=Symbol.for("graphrefly/COMPLETE"),$=Symbol.for("graphrefly/ERROR"),pe=Object.freeze([W]),Ue=Object.freeze([U]),qt=Object.freeze([Q]),Ke=Object.freeze([Oe]),Wt=Object.freeze([H]),Ut=Object.freeze([z]),Ye=Object.freeze([pe]),vt=Object.freeze([Ue]),_t=Object.freeze([qt]),wt=Object.freeze([Wt]),Je=Object.freeze([Ut])});function Kt(t){t.registerMessageType(Oe,{tier:0,wireCrossing:!1}),t.registerMessageType(W,{tier:1,wireCrossing:!1}),t.registerMessageType(Q,{tier:1,wireCrossing:!1,metaPassthrough:!1}),t.registerMessageType(te,{tier:2,wireCrossing:!1}),t.registerMessageType(oe,{tier:2,wireCrossing:!1}),t.registerMessageType(P,{tier:3,wireCrossing:!0}),t.registerMessageType(U,{tier:3,wireCrossing:!0}),t.registerMessageType(H,{tier:4,wireCrossing:!0,metaPassthrough:!1}),t.registerMessageType($,{tier:4,wireCrossing:!0,metaPassthrough:!1}),t.registerMessageType(z,{tier:5,wireCrossing:!0,metaPassthrough:!1})}var Xe,Yt=q(()=>{"use strict";ke();Xe=class{_messageTypes=new Map;_codecs=new Map;_onMessage;_onSubscribe;_defaultVersioning;_defaultHashFn;_inspectorEnabled=!(typeof process<"u"&&process.env?.NODE_ENV==="production");_globalInspector;_rigorRecorder;_frozen=!1;tierOf;constructor(e){this._onMessage=e.onMessage,this._onSubscribe=e.onSubscribe,this._defaultVersioning=e.defaultVersioning,this._defaultHashFn=e.defaultHashFn,this.tierOf=n=>{let r=this._messageTypes.get(n);return r!=null?r.tier:1}}get onMessage(){return this._frozen=!0,this._onMessage}get onSubscribe(){return this._frozen=!0,this._onSubscribe}set onMessage(e){this._assertUnfrozen(),this._onMessage=e}set onSubscribe(e){this._assertUnfrozen(),this._onSubscribe=e}get defaultVersioning(){return this._defaultVersioning}set defaultVersioning(e){this._assertUnfrozen(),this._defaultVersioning=e}get defaultHashFn(){return this._defaultHashFn}set defaultHashFn(e){this._assertUnfrozen(),this._defaultHashFn=e}get inspectorEnabled(){return this._inspectorEnabled}set inspectorEnabled(e){this._inspectorEnabled=e}get globalInspector(){return this._globalInspector}set globalInspector(e){this._globalInspector=e}get rigorRecorder(){return this._rigorRecorder}set rigorRecorder(e){this._rigorRecorder=e}registerMessageType(e,n){return this._assertUnfrozen(),this._messageTypes.set(e,{tier:n.tier,wireCrossing:n.wireCrossing??n.tier>=3,metaPassthrough:n.metaPassthrough??!0}),this}messageTier(e){let n=this._messageTypes.get(e);return n!=null?n.tier:1}isWireCrossing(e){let n=this._messageTypes.get(e);return n!=null?n.wireCrossing:!0}isLocalOnly(e){return!this.isWireCrossing(e)}isMetaPassthrough(e){let n=this._messageTypes.get(e);return n!=null?n.metaPassthrough:!0}isKnownMessageType(e){return this._messageTypes.has(e)}registerCodec(e){return this._assertUnfrozen(),this._codecs.set(e.name,e),this}lookupCodec(e){return this._codecs.get(e)}_isFrozen(){return this._frozen}_assertUnfrozen(){if(this._frozen)throw new Error("GraphReFlyConfig is frozen: a node has already captured this config. Register custom types and set hooks before creating any node.")}}});function Xt(t,e){let n=new TextEncoder().encode(t.name);if(n.length===0||n.length>255)throw new Error(`encodeEnvelope: codec name "${t.name}" encodes to ${n.length} bytes (must be 1\u2013255)`);let r=t.version;if(!Number.isInteger(r)||r<0||r>65535)throw new Error(`encodeEnvelope: codec.version ${r} out of u16 range (expected integer 0\u201365535)`);let s=2+n.length+2+e.length;if(s>4294967295)throw new Error(`encodeEnvelope: total envelope size ${s} exceeds 2^32-1 bytes (payload ${e.length} bytes)`);let o=new Uint8Array(s),i=0;return o[i++]=xt,o[i++]=n.length,o.set(n,i),i+=n.length,o[i++]=r>>>8&255,o[i++]=r&255,o.set(e,i),o}function Zt(t,e){if(t.length<Jt)throw new Error(`decodeEnvelope: bytes too short (${t.length} < ${Jt})`);let n=0,r=t[n++];if(r!==xt)throw new Error(`decodeEnvelope: unsupported envelope version ${r} (expected ${xt})`);let s=t[n++];if(s===0)throw new Error("decodeEnvelope: name_len must be >= 1");if(n+s+2>t.length)throw new Error(`decodeEnvelope: envelope truncated (need ${n+s+2} bytes, have ${t.length})`);let o=new TextDecoder().decode(t.subarray(n,n+s));n+=s;let i=(t[n]<<8|t[n+1])>>>0;n+=2;let a=t.subarray(n),u=e.lookupCodec(o);if(u==null)throw new Error(`decodeEnvelope: codec "${o}" not registered (envelope codec_v=${i})`);return{codec:u,codecVersion:i,payload:a}}function Qt(t){t.registerCodec(Jn)}var Jn,xt,Jt,Tt=q(()=>{"use strict";Jn={name:"json",version:1,contentType:"application/json",encode(t){let e=JSON.stringify(t);return new TextEncoder().encode(e)},decode(t,e){let n=new TextDecoder().decode(t);return JSON.parse(n)}},xt=1,Jt=4});function Et(t){if(t===void 0)return null;if(typeof t=="number"){if(!Number.isFinite(t))throw new TypeError(`Cannot hash non-finite number: ${t}`);if(Number.isInteger(t)&&!Number.isSafeInteger(t))throw new TypeError(`Cannot hash integer outside safe range (|n| > 2^53-1): ${t}. Cross-language cid parity is not guaranteed for unsafe integers.`);return t}if(typeof t=="string"||typeof t=="boolean"||t===null)return t;if(Array.isArray(t))return t.map(Et);if(typeof t=="object"&&t!==null){let e={};for(let n of Object.keys(t).sort())e[n]=Et(t[n]);return e}return null}function Qn(t){let e=Zn.encode(t),n=e.length,r=n*8,s=n+9+63&-64,o=new Uint8Array(s);o.set(e),o[n]=128;let i=new DataView(o.buffer);i.setUint32(s-4,r>>>0,!1),i.setUint32(s-8,Math.floor(r/4294967296)>>>0,!1);let a=1779033703,u=3144134277,d=1013904242,c=2773480762,h=1359893119,p=2600822924,f=528734635,l=1541459225,y=new Uint32Array(64),m=(w,b)=>w>>>b|w<<32-b;for(let w=0;w<s;w+=64){for(let x=0;x<16;x++)y[x]=i.getUint32(w+x*4,!1);for(let x=16;x<64;x++){let N=y[x-15],S=y[x-2],A=m(N,7)^m(N,18)^N>>>3,D=m(S,17)^m(S,19)^S>>>10;y[x]=y[x-16]+A+y[x-7]+D>>>0}let b=a,_=u,R=d,O=c,g=h,v=p,k=f,E=l;for(let x=0;x<64;x++){let N=m(g,6)^m(g,11)^m(g,25),S=g&v^~g&k,A=E+N+S+Xn[x]+y[x]>>>0,D=m(b,2)^m(b,13)^m(b,22),G=b&_^b&R^_&R,j=D+G>>>0;E=k,k=v,v=g,g=O+A>>>0,O=R,R=_,_=b,b=A+j>>>0}a=a+b>>>0,u=u+_>>>0,d=d+R>>>0,c=c+O>>>0,h=h+g>>>0,p=p+v>>>0,f=f+k>>>0,l=l+E>>>0}let T=w=>w.toString(16).padStart(8,"0");return T(a)+T(u)+T(d)+T(c)+T(h)+T(p)+T(f)+T(l)}function Ot(t){let e=Et(t??null),n=JSON.stringify(e);return Qn(n).slice(0,16)}function er(){let t=globalThis.crypto;if(t?.randomUUID)return t.randomUUID();let e=()=>Math.floor(Math.random()*4294967296).toString(16).padStart(8,"0"),n=e()+e()+e()+e();return`${n.slice(0,8)}-${n.slice(8,12)}-4${n.slice(13,16)}-${(parseInt(n.slice(16,17),16)&3|8).toString(16)}${n.slice(17,20)}-${n.slice(20,32)}`}function kt(t,e,n){let r=n?.id??er();if(t===0)return{id:r,version:0};let o=(n?.hash??Ot)(e);return{id:r,version:0,cid:o,prev:null}}function en(t,e,n){t.version+=1,"cid"in t&&(t.prev=t.cid,t.cid=n(e))}var Xn,Zn,tn=q(()=>{"use strict";Xn=new Uint32Array([1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298]),Zn=new TextEncoder});function sn(t){return{node:t,unsub:null,prevData:void 0,dirty:!1,involvedThisWave:!1,dataBatch:[],terminal:void 0}}function Rt(t){t.prevData=void 0,t.dirty=!1,t.involvedThisWave=!1,t.dataBatch.length=0,t.terminal=void 0}function Ze(t){return t.length===0?t:typeof t[0]=="symbol"?[t]:t}function ie(t,e,n){let r=on(t)?t:[],s=typeof t=="function"?t:typeof e=="function"?e:void 0,o={};return on(t)?o=(St(e)?e:n)??{}:St(t)?o=t:o=(St(e)?e:n)??{},new V(r,s,o)}var nn,rn,tr,nr,he,V,on,St,ge=q(()=>{"use strict";Tt();We();De();Me();Yt();fe();ke();tn();nn=()=>{},rn=100;tr=(t,e,n,r)=>{n.direction==="down-in"&&t._onDepMessage(n.depIndex,e)},nr=(t,e,n,r)=>{let s=t;if(s._status==="completed"||s._status==="errored")return;let o=s._cached,i=o===void 0?[Ke]:[Ke,[P,o]];s._status==="dirty"&&i.push(pe),He(e,i,s._config.tierOf)},he=new Xe({onMessage:tr,onSubscribe:nr});Kt(he);Qt(he);V=class t{_optsName;_describeKind;meta;_hasMeta;_config;_deps;_sinks=null;_sinkCount=0;_cached;_status;_cleanup;_store={};_waveHasNewData=!1;_hasNewTerminal=!1;_hasCalledFnOnce=!1;_paused=!1;_pendingWave=!1;_isExecutingFn=!1;_pendingRerun=!1;_rerunDepth=0;_dirtyDepCount=0;_batchPendingMessages=null;_pauseLocks=null;_pauseBuffer=null;_fn;_equals;_resubscribable;_resetOnTeardown;_autoComplete;_autoError;_pausable;_partial;_guard;_extraGuards;_hashFn;_versioning;_versioningLevel;_lastMutation;_inspectorHooks;_actions;constructor(e,n,r){this._config=r.config??he,this._config.onMessage,this._optsName=r.name,this._describeKind=r.describeKind,this._equals=r.equals??Object.is,this._resubscribable=r.resubscribable??!1,this._resetOnTeardown=r.resetOnTeardown??!1,this._autoComplete=r.completeWhenDepsComplete??!0,this._autoError=r.errorWhenDepsError??!0,this._pausable=r.pausable??!0,this._guard=r.guard,this._fn=n,this._partial=r.partial??!1,this._cached=r.initial!==void 0?r.initial:void 0,this._status=e.length===0&&n==null&&this._cached!==void 0?"settled":"sentinel",this._hashFn=r.versioningHash??this._config.defaultHashFn??Ot;let s=r.versioning??this._config.defaultVersioning;this._versioningLevel=s,this._versioning=s!=null?kt(s,this._cached===void 0?void 0:this._cached,{id:r.versioningId,hash:this._hashFn}):void 0,this._deps=e.map(sn);let o={};for(let[a,u]of Object.entries(r.meta??{})){let d={initial:u,name:`${r.name??"node"}:meta:${a}`,describeKind:"state",config:this._config};r.guard!=null&&(d.guard=r.guard),o[a]=new t([],void 0,d)}Object.freeze(o),this.meta=o,this._hasMeta=Object.keys(o).length>0;let i=this;this._actions={emit(a){i._emit([[P,a]])},down(a){i._emit(Ze(a))},up(a){i._emitUp(Ze(a))}},this.down=this.down.bind(this),this.up=this.up.bind(this)}get _isTerminal(){return this._status==="completed"||this._status==="errored"}get name(){return this._optsName}get status(){return this._status}get cache(){return this._cached===void 0?void 0:this._cached}get lastMutation(){return this._lastMutation}get v(){return this._versioning}hasGuard(){return this._guard!=null}_applyVersioning(e,n){if(this._isExecutingFn)throw new Error(`Node "${this.name}": _applyVersioning cannot run mid-fn \u2014 call it outside of \`_execFn\` (typically at graph setup time before the first subscribe).`);let r=this._versioningLevel;if(r!=null&&e<=r)return;let s=n?.hash??this._hashFn;s!==this._hashFn&&(this._hashFn=s);let o=this._cached===void 0?void 0:this._cached,i=this._versioning,a=i?.id??n?.id,u=i?.version??0,d=kt(e,o,{id:a,hash:s});d.version=u,this._versioning=d,this._versioningLevel=e}_setInspectorHook(e){return e==null?()=>{}:(this._inspectorHooks==null&&(this._inspectorHooks=new Set),this._inspectorHooks.add(e),()=>{this._inspectorHooks?.delete(e),this._inspectorHooks?.size===0&&(this._inspectorHooks=void 0)})}_pushGuard(e){return this._extraGuards==null&&(this._extraGuards=new Set),this._extraGuards.add(e),()=>{this._extraGuards?.delete(e),this._extraGuards?.size===0&&(this._extraGuards=void 0)}}allowsObserve(e){if(this._guard==null&&this._extraGuards==null)return!0;let n=qe(e);if(this._guard!=null&&!this._guard(n,"observe"))return!1;if(this._extraGuards!=null){for(let r of this._extraGuards)if(!r(n,"observe"))return!1}return!0}_checkGuard(e){if(e?.internal)return;let n=this._guard!=null||this._extraGuards!=null,r=e?.actor!=null;if(!n&&!r)return;let s=qe(e?.actor),o=e?.delivery==="signal"?"signal":"write";if(this._guard!=null&&!this._guard(s,o))throw new Z({actor:s,action:o,nodeName:this.name});if(this._extraGuards!=null){for(let i of this._extraGuards)if(!i(s,o))throw new Z({actor:s,action:o,nodeName:this.name})}this._lastMutation={actor:s,timestamp_ns:ne()}}down(e,n){let r=Ze(e);r.length!==0&&(this._checkGuard(n),this._emit(r))}emit(e,n){this._checkGuard(n),this._emit([[P,e]])}up(e,n){if(this._deps.length===0)return;let r=Ze(e);if(r.length===0)return;this._checkGuard(n);let s=n??{internal:!0};this._validateUpTiers(r);for(let o of this._deps)o.node.up?.(r,s)}_emitUp(e){if(this._deps.length!==0&&e.length!==0){this._validateUpTiers(e);for(let n of this._deps)n.node.up?.(e,{internal:!0})}}_validateUpTiers(e){let n=this._config.tierOf;for(let r of e){let s=n(r[0]);if(s===3||s===4)throw new Error(`Node "${this.name}": tier-${s} messages cannot flow up \u2014 DATA/RESOLVED/COMPLETE/ERROR are downstream-only. Use \`down(...)\` for value delivery; \`up(...)\` is for control signals (DIRTY, INVALIDATE, PAUSE, RESUME, TEARDOWN).`)}}subscribe(e,n){if(n!=null&&this._guard!=null){let u=qe(n);if(!this._guard(u,"observe"))throw new Z({actor:u,action:"observe",nodeName:this.name})}let s=this._isTerminal&&this._resubscribable;if(s){this._cached=void 0,this._status="sentinel",this._store={},this._hasCalledFnOnce=!1,this._waveHasNewData=!1,this._hasNewTerminal=!1,this._paused=!1,this._pendingWave=!1,this._pendingRerun=!1,this._isExecutingFn=!1,this._rerunDepth=0,this._dirtyDepCount=0,this._pauseLocks=null,this._pauseBuffer=null;for(let u of this._deps)Rt(u);if(this._partial===!1){for(let u of this._deps)if(u.prevData!==void 0||u.dataBatch.length!==0||u.terminal!==void 0||u.dirty)throw new Error(`resubscribable-reset invariant: DepRecord not fully reset for node ${this._optsName??"(anonymous)"}`)}}this._sinkCount+=1;let o;try{o=this._config.onSubscribe(this,e,{sinkCount:this._sinkCount,afterTerminalReset:s},this._actions)}catch(u){throw this._sinkCount-=1,u}this._sinks==null?this._sinks=e:typeof this._sinks=="function"?this._sinks=new Set([this._sinks,e]):this._sinks.add(e);let i=this._isTerminal;if(this._sinkCount===1&&!i)try{this._activate()}catch(u){if(this._sinkCount-=1,this._removeSink(e),this._sinkCount===0&&(this._status="sentinel"),typeof o=="function")try{o()}catch{}throw u}this._status==="sentinel"&&this._cached===void 0&&(this._status="pending");let a=!1;return()=>{a||(a=!0,this._sinkCount-=1,this._removeSink(e),typeof o=="function"&&o(),this._sinks==null&&this._deactivate())}}_removeSink(e){if(this._sinks===e)this._sinks=null;else if(this._sinks!=null&&typeof this._sinks!="function")if(this._sinks.delete(e),this._sinks.size===1){let[n]=this._sinks;this._sinks=n}else this._sinks.size===0&&(this._sinks=null)}_activate(){if(this._deps.length===0){this._fn&&this._execFn();return}this._dirtyDepCount=0;let e=this._deps.length,n=0;try{for(let r=0;r<e;r++){let s=r,o=this._deps[r];o.unsub=nn,o.unsub=o.node.subscribe(i=>{if(o.unsub===null)return;let a=this._config.tierOf,u=!1;for(let d of i)a(d[0])>=3&&(u=!0),this._config.onMessage(this,d,{direction:"down-in",depIndex:s},this._actions);u&&this._maybeRunFnOnSettlement()}),n++}}catch(r){this._deps[n].unsub=null;for(let s=0;s<n;s++){let o=this._deps[s];if(o.unsub!=null){let i=o.unsub;o.unsub=null;try{i()}catch{}Rt(o)}}throw this._dirtyDepCount=0,r}}_addDep(e){for(let s=0;s<this._deps.length;s++)if(this._deps[s].node===e)return s;let n=this._deps.length,r=sn(e);if(this._deps.push(r),this._sinks==null)return n;r.dirty=!0,this._dirtyDepCount++,this._status!=="dirty"&&this._emit(Ye),r.unsub=nn;try{r.unsub=e.subscribe(s=>{if(r.unsub===null)return;let o=this._config.tierOf,i=!1;for(let a of s)o(a[0])>=3&&(i=!0),this._config.onMessage(this,a,{direction:"down-in",depIndex:n},this._actions);i&&this._maybeRunFnOnSettlement()})}catch(s){throw r.unsub=null,this._deps.pop(),this._dirtyDepCount--,s}return n}_deactivate(e=!1){let n=this._cleanup;if(this._cleanup=void 0,typeof n=="function")try{n()}catch(r){this._emit([[$,this._wrapFnError("cleanup threw",r)]])}else if(n!=null&&typeof n=="object"){let r=n.deactivate;if(typeof r=="function")try{r()}catch(s){this._emit([[$,this._wrapFnError("cleanup.deactivate threw",s)]])}}for(let r of this._deps){if(r.unsub!=null){let s=r.unsub;r.unsub=null;try{s()}catch{}}Rt(r)}this._waveHasNewData=!1,this._hasNewTerminal=!1,this._hasCalledFnOnce=!1,this._paused=!1,this._pendingWave=!1,this._pendingRerun=!1,this._rerunDepth=0,this._store={},this._dirtyDepCount=0,this._pauseLocks=null,this._pauseBuffer=null,this._fn!=null&&(this._cached=void 0),e||(this._fn!=null||this._deps.length>0)&&(!this._isTerminal||this._resubscribable)&&(this._status="sentinel")}_onDepMessage(e,n){let r=this._deps[e],s=n[0];if(this._inspectorHooks!=null){let o={kind:"dep_message",depIndex:e,message:n};for(let i of this._inspectorHooks)i(o)}if(s!==Oe){if(s===W){this._depDirtied(r);return}if(s===Q){if(this._depInvalidated(r),this._cached===void 0)return;this._emit(_t);return}if(s===te||s===oe){this._emit([n]);return}if(s===z){this._emit(Je);return}if(s===P)this._depSettledAsData(r,n[1]);else if(s===U)this._depSettledAsResolved(r);else if(s===H)this._depSettledAsTerminal(r,!0);else if(s===$)this._depSettledAsTerminal(r,n[1]);else{this._emit([n]);return}if(!this._fn){(s===P||s===U)&&this._emit([n]),(s===H||s===$)&&this._maybeAutoTerminalAfterWave();return}}}_depDirtied(e){e.dirty||(e.dirty=!0,e.involvedThisWave=!0,this._dirtyDepCount++,this._status!=="dirty"&&this._emit(Ye))}_depSettledAsData(e,n){e.dirty&&(e.dirty=!1,this._dirtyDepCount--),e.involvedThisWave=!0,e.dataBatch.push(n),this._waveHasNewData=!0}_depSettledAsResolved(e){e.dirty&&(e.dirty=!1,this._dirtyDepCount--)}_depSettledAsTerminal(e,n){e.dirty&&(e.dirty=!1,this._dirtyDepCount--),e.terminal=n,e.involvedThisWave=!0,this._hasNewTerminal=!0}_depInvalidated(e){e.prevData=void 0,e.terminal=void 0,e.dataBatch.length=0,e.dirty?e.involvedThisWave=!1:(e.dirty=!0,e.involvedThisWave=!0,this._dirtyDepCount++)}_maybeRunFnOnSettlement(){if(!(this._isTerminal&&!this._resubscribable)&&!(this._dirtyDepCount>0)){if(!this._partial&&!this._hasCalledFnOnce)for(let e=0;e<this._deps.length;e++){let n=this._deps[e];if(n.dataBatch.length===0&&n.prevData===void 0&&n.terminal===void 0){this._maybeAutoTerminalAfterWave();return}}if(this._paused){this._pendingWave=!0;return}if(!this._waveHasNewData&&!this._hasNewTerminal&&this._hasCalledFnOnce){this._clearWaveFlags(),this._emit(vt),this._maybeAutoTerminalAfterWave();return}this._fn&&this._execFn(),this._maybeAutoTerminalAfterWave()}}_maybeAutoTerminalAfterWave(){if(this._deps.length===0||this._isTerminal)return;let e=this._deps.find(n=>n.terminal!==void 0&&n.terminal!==!0);if(e!=null){this._autoError&&this._emit([[$,e.terminal]]);return}this._autoComplete&&this._deps.every(n=>n.terminal!==void 0)&&this._emit(wt)}_execFn(){if(!this._fn||this._isTerminal&&!this._resubscribable)return;if(this._isExecutingFn){this._pendingRerun=!0;return}let e=this._cleanup;if(typeof e=="function"){this._cleanup=void 0;try{e()}catch(i){this._emit([[$,this._wrapFnError("cleanup threw",i)]]);return}}else if(e!=null&&typeof e=="object"){let i=e.beforeRun;if(typeof i=="function"){e.beforeRun=void 0;try{i()}catch(a){this._emit([[$,this._wrapFnError("cleanup.beforeRun threw",a)]]);return}}}let n=this._deps.map(i=>i.involvedThisWave?i.dataBatch.length>0?[...i.dataBatch]:[]:void 0),r=this._deps.map(i=>i.prevData);for(let i=0;i<this._deps.length;i++){let a=n[i];a!=null&&a.length>0&&(this._deps[i].prevData=a[a.length-1])}let s=this._deps.map(i=>i.terminal),o={prevData:r,terminalDeps:s,store:this._store};if(this._hasCalledFnOnce=!0,this._clearWaveFlags(),this._inspectorHooks!=null){let i={kind:"run",batchData:n,prevData:r};for(let a of this._inspectorHooks)a(i)}this._isExecutingFn=!0;try{let i=this._fn(n,this._actions,o);if(typeof i=="function")this._cleanup=i;else if(i!=null&&typeof i=="object"){let a=i;(typeof a.beforeRun=="function"||typeof a.deactivate=="function"||typeof a.invalidate=="function")&&(this._cleanup=i)}}catch(i){this._emit([[$,this._wrapFnError("fn threw",i)]])}finally{this._isExecutingFn=!1,this._pendingRerun?(this._pendingRerun=!1,this._rerunDepth+=1,this._rerunDepth>rn?(this._rerunDepth=0,this._emit([[$,new Error(`Node "${this.name}": _pendingRerun depth exceeded ${rn} \u2014 likely a reactive cycle`)]])):this._maybeRunFnOnSettlement()):this._rerunDepth=0,this._clearWaveFlags()}}_clearWaveFlags(){this._waveHasNewData=!1,this._hasNewTerminal=!1;for(let e of this._deps)e.involvedThisWave=!1,e.dataBatch.length=0}_wrapFnError(e,n){let r=n instanceof Error?n.message:String(n);return new Error(`Node "${this.name}": ${e}: ${r}`,{cause:n})}_frameBatch(e){let n=this._config.tierOf;if(e.length===1)return n(e[0][0])===3&&this._status!=="dirty"?[pe,e[0]]:e;let r=!0,s=!1,o=!1,i=-1;for(let u of e){let d=n(u[0]);d<i&&(r=!1),d===3&&(s=!0),u[0]===W&&(o=!0),i=d}let a=e;if(!r){let u=e.map((d,c)=>({m:d,i:c,tier:n(d[0])}));u.sort((d,c)=>d.tier-c.tier||d.i-c.i),a=u.map(d=>d.m)}if(s&&!o&&this._status!=="dirty"){let u=0;for(;u<a.length&&n(a[u][0])===0;)u++;return u===0?[pe,...a]:[...a.slice(0,u),pe,...a.slice(u)]}return a}_emit(e){if(e.length===0)return;for(let a=0;a<e.length;a++){let u=e[a];if(u[0]===$&&u[1]===void 0)throw new TypeError('[ERROR, payload] requires a non-undefined payload (spec \xA71.2). Pass an Error object or domain tag instead \u2014 e.g. node.down([[ERROR, new Error("reason")]])')}let n=e;if(this._isTerminal&&!this._resubscribable){let a=e.filter(u=>u[0]===z||u[0]===Q);if(a.length===0)return;n=a}n=this._frameBatch(n);let s=null;for(let a=0;a<n.length;a++){let u=n[a],d=u[0];if(d!==te&&d!==oe){s?.push(u);continue}if(u.length<2)throw new Error(`Node "${this.name}": [[${d===te?"PAUSE":"RESUME"}]] must carry a lockId payload \u2014 bare PAUSE/RESUME is a protocol violation (C0 rule). Use \`[[PAUSE, lockId]]\` / \`[[RESUME, lockId]]\`.`);let c=!0;if(this._pausable!==!1){let h=u[1];if(d===te)this._pauseLocks==null&&(this._pauseLocks=new Set),this._pauseLocks.add(h),this._paused=!0,this._pausable==="resumeAll"&&this._pauseBuffer==null&&(this._pauseBuffer=[]);else if(this._pauseLocks==null||!this._pauseLocks.has(h))c=!1;else if(this._pauseLocks.delete(h),this._pauseLocks.size===0){if(this._paused=!1,this._pauseBuffer!=null&&this._pauseBuffer.length>0){let p=this._pauseBuffer;this._pauseBuffer=[],this._emit(p)}this._pendingWave&&(this._pendingWave=!1,this._maybeRunFnOnSettlement())}}c?s?.push(u):s==null&&(s=n.slice(0,a))}if(s!=null){if(s.length===0)return;n=s}if(this._hasMeta&&n.some(a=>a[0]===z))for(let a of Object.keys(this.meta))try{this.meta[a]._emit(Je)}catch{}let{finalMessages:o,equalsError:i}=this._updateState(n);if(o.length>0&&this._config.inspectorEnabled){let a=this._config.globalInspector;if(a!=null)try{a({kind:"emit",node:this,messages:o})}catch{}}if(o.length>0)if(this._paused&&this._pausable==="resumeAll"&&this._pauseBuffer!=null){let a=this._config.tierOf,u=[];for(let d of o)a(d[0])===3?this._pauseBuffer.push(d):u.push(d);u.length>0&&this._dispatchOrAccumulate(u)}else this._dispatchOrAccumulate(o);i!=null&&this._emit([[$,i]])}_updateState(e){let n=this._config.tierOf,r,s,o=-1,i=0;for(let c of e)n(c[0])===3&&i++;let a=i<=1,u=-1;if(this._versioning!=null&&i>1){for(let c=e.length-1;c>=0;c--)if(e[c][0]===P){u=c;break}}for(let c=0;c<e.length;c++){let h=e[c],p=h[0];if(p===P){if(h.length>=2){let f=!1;if(a&&this._cached!==void 0)try{f=this._equals(this._cached,h[1])}catch(l){s=this._wrapFnError("equals threw",l),o=c;break}if(f){r==null&&(r=e.slice(0,c)),r.push(Ue),this._status="resolved";continue}this._cached=h[1],this._versioning!=null&&(u<0||c===u)&&en(this._versioning,h[1],this._hashFn)}this._status="settled",r?.push(h)}else if(r?.push(h),p===W)this._status="dirty";else if(p===U)this._status="resolved";else if(p===H){this._status="completed";{let f=this._config.rigorRecorder;if(f!=null)try{f.onTerminalTransition(this,"completed",this._autoComplete,this._autoError,this._deps.length>0)}catch{}}}else if(p===$){this._status="errored";{let f=this._config.rigorRecorder;if(f!=null)try{f.onTerminalTransition(this,"errored",this._autoComplete,this._autoError,this._deps.length>0)}catch{}}}else if(p===Q){if(this._cached!==void 0){let l=this._config.rigorRecorder;if(l!=null)try{l.onNonVacuousInvalidate(this,this._cached)}catch{}}this._cached=void 0,this._status="dirty";let f=this._cleanup;if(typeof f=="function"){this._cleanup=void 0;try{f()}catch{}}else if(f!=null&&typeof f=="object"){let l=f.invalidate;if(typeof l=="function")try{l()}catch{}}}else p===z&&(this._resetOnTeardown&&(this._cached=void 0),this._deactivate(!0),this._status="sentinel")}let d=o>=0?r??e.slice(0,o):r??e;return s!=null?{finalMessages:d,equalsError:s}:{finalMessages:d}}_deliverToSinks=e=>{if(this._sinks==null)return;if(typeof this._sinks=="function"){this._sinks(e);return}let n=[...this._sinks];for(let r of n)r(e)};_dispatchOrAccumulate(e){if(Bt()){this._batchPendingMessages===null&&(this._batchPendingMessages=[],we(()=>this._flushBatchPending()));for(let n of e)this._batchPendingMessages.push(n);return}He(this._deliverToSinks,e,this._config.tierOf)}_flushBatchPending(){let e=this._batchPendingMessages;if(e===null||(this._batchPendingMessages=null,e.length===0))return;let n=this._frameBatch(e);He(this._deliverToSinks,n,this._config.tierOf)}},on=t=>Array.isArray(t),St=t=>typeof t=="object"&&t!=null&&!Array.isArray(t)});function Ge(t,e){if(e!=null&&e.length>0)return new Set(e);switch(t){case"standard":return new Set(["type","status","value","deps","meta","v"]);case"full":return null;case"spec":return new Set(["type","deps","meta"]);default:return new Set(["type","deps"])}}function rr(t){return t._describeKind!=null?t._describeKind:t._deps.length>0?"derived":t._fn!=null?"producer":"state"}function At(t){let e=new WeakSet,n={};for(let[r,s]of an(t))n[r]=Nt(s,e);return n}function Nt(t,e){if(t==null)return t;let n=typeof t;if(n==="boolean"||n==="number"||n==="string")return t;if(n==="function")return"<function>";if(Array.isArray(t))return e.has(t)?"<cycle>":(e.add(t),t.map(r=>Nt(r,e)));if(n==="object"){let r=t;if(e.has(r))return"<cycle>";e.add(r);try{if(typeof r.subscribe=="function"&&"cache"in r)return"<Node>"}catch{return"<unserializable>"}let s={};for(let[o,i]of an(r))s[o]=Nt(i,e);return s}return"<unserializable>"}function an(t){let e=[],n;try{n=Object.keys(t)}catch{return e}for(let r of n)try{e.push([r,t[r]])}catch{e.push([r,"<unserializable>"])}return e}function sr(t){let e={};for(let[n,r]of Object.entries(t.meta))try{e[n]=r.cache}catch{}return e}function Ct(t,e){let n=e==null,r=!n&&e!=null?[...e].filter(d=>d.startsWith("meta.")).map(d=>d.slice(5)):null,s=n||e.has("meta")||r!=null&&r.length>0,o="state",i=[];t instanceof V&&(o=rr(t),i=t._deps.map(d=>d.node.name??""));let a={type:o,deps:i};(n||e.has("status"))&&(a.status=t.status);let u=t instanceof V?t._guard:void 0;if(s){let d={...sr(t)};if(u!=null&&d.access===void 0&&(d.access=bt(u)),r!=null&&r.length>0&&!e.has("meta")){let c={};for(let h of r)h in d&&(c[h]=d[h]);a.meta=c}else a.meta=d}if(t.name!=null&&(a.name=t.name),n||e.has("value")){t.status==="sentinel"&&(a.sentinel=!0);try{a.value=t.cache}catch{}}if((n||e.has("v"))&&t.v!=null){let d={id:t.v.id,version:t.v.version};"cid"in t.v&&(d.cid=t.v.cid,d.prev=t.v.prev),a.v=d}return(n||e.has("guard"))&&u!=null&&(a.guard=bt(u)),(n||e.has("lastMutation"))&&t.lastMutation!=null&&(a.lastMutation=t.lastMutation),a}var Dt=q(()=>{"use strict";fe();ge()});function K(t,e){return ie([],{...e,initial:t})}function Qe(t,e){return ie((r,s,o)=>t(s,o)??void 0,{describeKind:"producer",...e})}function Y(t,e,n){return ie(t,(s,o,i)=>{let a=s.map((u,d)=>u!=null&&u.length>0?u.at(-1):i.prevData[d]);o.emit(e(a,i))},{describeKind:"derived",...n})}var Le=q(()=>{"use strict";ge()});function re(t){return t.subscribe(()=>{})}var Mt=q(()=>{"use strict"});var rt,hn=q(()=>{"use strict";rt=class{_timer;_gen=0;start(e,n){this.cancel(),this._gen+=1;let r=this._gen;this._timer=setTimeout(()=>{this._timer=void 0,r===this._gen&&n()},e)}cancel(){this._timer!==void 0&&(clearTimeout(this._timer),this._timer=void 0)}get pending(){return this._timer!==void 0}}});var is={};Hn(is,{CqrsGraph:()=>ht,cqrs:()=>os,cqrsEventKeyOf:()=>ns,dispatchKeyOf:()=>rs,sagaInvocationKeyOf:()=>ss});module.exports=Wn(is);De();Me();fe();We();fe();ke();Dt();ge();Le();De();ke();ge();Le();var Gt=class{_version=0;_maxSize;_buf;_head=0;_size=0;constructor(e,n){if(n!==void 0&&n<1)throw new RangeError("maxSize must be >= 1");if(this._maxSize=n,n!==void 0){if(this._buf=new Array(n),e&&e.length>0){let r=Math.min(e.length,n),s=e.length-r;for(let o=0;o<r;o++)this._buf[o]=e[s+o];this._size=r}}else this._buf=e?[...e]:[],this._size=this._buf.length}get version(){return this._version}get size(){return this._size}at(e){if(!Number.isInteger(e))return;let n=e>=0?e:this._size+e;if(!(n<0||n>=this._size))return this._maxSize!==void 0?this._buf[(this._head+n)%this._maxSize]:this._buf[n]}append(e){this._rawAppend(e),this._version+=1}appendMany(e){if(e.length===0)return;let n=this._maxSize!==void 0&&e.length>this._maxSize?e.length-this._maxSize:0;for(let r=n;r<e.length;r++)this._rawAppend(e[r]);this._version+=1}clear(){if(this._size===0)return 0;let e=this._size;if(this._maxSize===void 0)this._buf.length=0;else for(let n=0;n<e;n++)this._buf[(this._head+n)%this._maxSize]=void 0;return this._head=0,this._size=0,this._version+=1,e}trimHead(e){if(!Number.isInteger(e)||e<0)throw new RangeError(`trimHead: n must be a non-negative integer (got ${e})`);if(e===0||this._size===0)return 0;let n=Math.min(e,this._size);if(this._maxSize===void 0)this._buf.splice(0,n);else{for(let r=0;r<n;r++)this._buf[(this._head+r)%this._maxSize]=void 0;this._head=(this._head+n)%this._maxSize}return this._size-=n,this._version+=1,n}slice(e,n){if(!Number.isInteger(e)||e<0)throw new RangeError(`slice: start must be a non-negative integer (got ${e})`);if(n!==void 0&&(!Number.isInteger(n)||n<0))throw new RangeError(`slice: stop must be a non-negative integer or undefined (got ${n})`);let r=n===void 0?this._size:Math.min(Math.max(n,0),this._size),s=Math.min(e,this._size);if(s>=r)return[];let o=r-s;if(this._maxSize===void 0)return this._buf.slice(s,r);let i=new Array(o);for(let a=0;a<o;a++)i[a]=this._buf[(this._head+s+a)%this._maxSize];return i}tail(e){if(!Number.isInteger(e)||e<0)throw new RangeError(`tail: n must be a non-negative integer (got ${e})`);if(e===0||this._size===0)return[];let n=Math.min(e,this._size);return this.slice(this._size-n,this._size)}toArray(){if(this._maxSize===void 0)return[...this._buf];let e=new Array(this._size);for(let n=0;n<this._size;n++)e[n]=this._buf[(this._head+n)%this._maxSize];return e}snapshot(){return this.toArray()}restore(e){if(this._maxSize===void 0){this._buf.length=0;for(let n=0;n<e.length;n++)this._buf.push(e[n]);this._size=this._buf.length}else{let n=this._maxSize;for(let o=0;o<n;o++)this._buf[o]=void 0;this._head=0;let r=Math.min(e.length,n),s=e.length-r;for(let o=0;o<r;o++)this._buf[o]=e[s+o];this._size=r}this._version+=1}_rawAppend(e){if(this._maxSize===void 0){this._buf.push(e),this._size=this._buf.length;return}this._size<this._maxSize?(this._buf[(this._head+this._size)%this._maxSize]=e,this._size+=1):(this._buf[this._head]=e,this._head=(this._head+1)%this._maxSize)}};function Ie(t){return t.subscribe(()=>{})}var or=64;function Pe(t,e={}){let{name:n,maxSize:r,versioning:s,guard:o,backend:i}=e,a=i??new Gt(t,r),u=K(a.toArray(),{name:n,describeKind:"state",equals:(g,v)=>g===v,...s!=null?{versioning:s}:{},...o!=null?{guard:o}:{}});function d(){let g=a.toArray();xe(()=>{u.down([[W]],{internal:!0}),u.down([[P,g]],{internal:!0})})}let c=new Map,h=new Map,p=new Map;function f(g,v){return`${g}:${v===void 0?"END":v}`}function l(g){if(g.size<or)return;let v=g.keys().next();if(v.done)return;let k=g.get(v.value);k!==void 0&&k.dispose(),g.delete(v.value)}function y(g){let v=a.version;try{return g()}finally{a.version!==v&&d()}}function m(g){if(!Number.isInteger(g)||g<0)throw new RangeError(`tail: n must be a non-negative integer (got ${g})`);let v=c.get(g);if(v!==void 0)return c.delete(g),c.set(g,v),v.node;l(c);let k=Y([u],([x])=>{let N=x;return g===0||N.length===0?[]:N.slice(Math.max(0,N.length-g))},{initial:a.tail(g),describeKind:"derived"}),E=Ie(k);return c.set(g,{node:k,dispose:E}),k}function T(g,v){if(!Number.isInteger(g)||g<0)throw new RangeError(`slice: start must be a non-negative integer (got ${g})`);if(v!==void 0&&(!Number.isInteger(v)||v<0))throw new RangeError(`slice: stop must be a non-negative integer or undefined (got ${v})`);let k=f(g,v),E=h.get(k);if(E!==void 0)return h.delete(k),h.set(k,E),E.node;l(h);let x=Y([u],([S])=>{let A=S;return v===void 0?A.slice(g):A.slice(g,v)},{initial:a.slice(g,v),describeKind:"derived"}),N=Ie(x);return h.set(k,{node:x,dispose:N}),x}function w(g){let v=p.get(g);if(v!==void 0)return v.node;let k=Y([u,g],([x,N])=>{let S=x,A=Math.max(0,Math.trunc(N??0));return S.slice(A)},{initial:[],describeKind:"derived"}),E=Ie(k);return p.set(g,{node:k,dispose:E}),k}let b,_;function R(){b===void 0&&(b=ie([u],(g,v,k)=>{let E=g[0],N=E!=null&&E.length>0?E.at(-1):k.prevData[0];if(N==null||N.length===0){v.down([[U]]);return}v.emit(N[N.length-1])},{name:n!=null?`${n}::lastValue`:"lastValue",describeKind:"derived",initial:a.size===0?void 0:a.at(a.size-1)}),_=Y([u],([g])=>g.length>0,{name:n!=null?`${n}::hasLatest`:"hasLatest",describeKind:"derived",initial:a.size>0}),Ie(b),Ie(_))}let O={entries:u,get size(){return a.size},at(g){return a.at(g)},append(g){y(()=>a.append(g))},appendMany(g){g.length!==0&&y(()=>a.appendMany(g))},clear(){y(()=>a.clear())},trimHead(g){y(()=>a.trimHead(g))},withLatest(){return R(),u},get lastValue(){return R(),b},get hasLatest(){return R(),_},view(g){switch(g.kind){case"tail":return m(g.n);case"slice":return T(g.start,g.stop);case"fromCursor":return w(g.cursor)}},attach(g){let v=g.subscribe(k=>{for(let E of k)E[0]===P&&O.append(E[1])});return()=>v()},attachStorage(g){if(g.length===0)return()=>{};let v=new Map;for(let E of g)v.set(E,a.size);(async()=>{for(let E of g)if(typeof E.loadEntries=="function")try{let x=await Promise.resolve(E.loadEntries());x.entries.length>0&&a.size===0&&(a.restore(x.entries),v.set(E,x.entries.length),d());break}catch{}})();let k=u.subscribe(E=>{for(let x of E){if(x[0]!==P)continue;let N=x[1];for(let S of g){let A=v.get(S)??0;if(N.length<A){try{let G=S.appendEntries(N);G instanceof Promise&&G.catch(()=>{})}catch{}v.set(S,N.length);continue}if(N.length===A)continue;let D=N.slice(A);v.set(S,N.length);try{let G=S.appendEntries(D);G instanceof Promise&&G.catch(()=>{})}catch{}}}});return()=>k()},disposeAllViews(){for(let g of c.values())g.dispose();c.clear();for(let g of h.values())g.dispose();h.clear();for(let g of p.values())g.dispose();p.clear()},dispose(){for(let g of c.values())g.dispose();c.clear();for(let g of h.values())g.dispose();h.clear();for(let g of p.values())g.dispose();p.clear()}};return O}var F={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},ir=Symbol.for("sizeof");function dn(t){let e=new WeakSet,n=new WeakSet,r=[t],s=0;for(;r.length>0;){let o=r.pop();s+=ar(o,e,n,r)}return s}function ar(t,e,n,r){if(t==null)return 0;switch(typeof t){case"number":return F.number;case"boolean":return F.boolean;case"string":return F.string+t.length*2;case"bigint":return F.bigint+dr(t);case"symbol":return F.symbol;case"function":return e.has(t)?0:(e.add(t),F.function);case"undefined":return 0}let o=t;if(e.has(o))return 0;e.add(o);let i=o[ir];if(typeof i=="function")try{let d=i.call(o);if(typeof d=="number"&&Number.isFinite(d))return d}catch{}if(o instanceof Date)return F.date;if(o instanceof RegExp)return F.regexp+o.source.length*2;if(o instanceof Error){let d=o.message?o.message.length*2:0,c=o.stack?o.stack.length*2:0;return F.error+d+c}if(typeof URL<"u"&&o instanceof URL)return F.url+o.href.length*2;if(typeof Promise<"u"&&o instanceof Promise)return F.promise;if(o instanceof WeakMap)return F.weakmap;if(o instanceof WeakSet)return F.weakset;if(o instanceof Map){let d=F.map;for(let[c,h]of o)d+=F.mapEntry,r.push(c),r.push(h);return d}if(o instanceof Set){let d=F.set;for(let c of o)d+=F.setEntry,r.push(c);return d}if(Array.isArray(o)){let d=F.array+o.length*8;for(let c of o)r.push(c);return d}if(o instanceof ArrayBuffer)return n.has(o)?0:(n.add(o),o.byteLength);if(ArrayBuffer.isView(o)){let d=o;return n.has(d.buffer)?48:(n.add(d.buffer),d.buffer.byteLength+48)}let a=F.object,u=Object.keys(o);for(let d of u){a+=F.string+d.length*2;try{r.push(o[d])}catch{}}return a}function dr(t){let e=t<0n?-t:t;if(e===0n)return 0;let n=e.toString(2).length;return Math.ceil(n/32)*8}function un(t,e,n,r={}){let s=e in t.nodes,o=n in t.nodes;if(!s)return et(e,n,"no-such-from");if(!o)return et(e,n,"no-such-to");let i=r.maxDepth;if(i!=null&&(!Number.isInteger(i)||i<0))throw new Error("explainPath: maxDepth must be an integer >= 0");if(e===n){if(r.findCycle===!0){let d=ur(t,e,r);if(d!=null)return d}let u=tt(e,t.nodes[e],0,r);return nt(e,n,[u])}if(i===0)return et(e,n,"no-path");let a=cn(t,e,n,i);return a.found?nt(e,n,ln(t,a.pathOrder,r)):et(e,n,a.truncated?"max-depth-exceeded":"no-path")}function cn(t,e,n,r){let s=new Map,o=[{path:n,depth:0}],i=new Set([n]),a=0,u=!1;for(;a<o.length;){let h=o[a++];if(h.path===e)break;if(r!=null&&h.depth>=r){let y=t.nodes[h.path];y?.deps&&y.deps.length>0&&(u=!0);continue}let p=t.nodes[h.path];if(p==null)continue;let f=p.deps??[],l=new Map;for(let y=0;y<f.length;y++){let m=f[y];if(!m)continue;let T=l.get(m);T==null&&(T=[],l.set(m,T)),T.push(y)}for(let[y,m]of l)i.has(y)||(i.add(y),s.set(y,{from:h.path,depIndices:m}),o.push({path:y,depth:h.depth+1}))}if(!s.has(e))return{found:!1,pathOrder:[],truncated:u};let d=[{path:e}],c=e;for(;c!==n;){let h=s.get(c);if(h==null)return{found:!1,pathOrder:[],truncated:!1};d[d.length-1].depIndices=h.depIndices,d.push({path:h.from}),c=h.from}return{found:!0,pathOrder:d,truncated:!1}}function ur(t,e,n){let r=t.nodes[e];if(r==null)return null;let s=r.deps??[],o=[];for(let a=0;a<s.length;a++)s[a]===e&&o.push(a);if(o.length>0){let a=tt(e,r,0,n);a.dep_index=o[0];let u=tt(e,r,1,n);return nt(e,e,[a,u])}let i=null;for(let a=0;a<s.length;a++){let u=s[a];if(!u||u===e)continue;let d=cn(t,u,e,n.maxDepth);d.found&&(i==null||d.pathOrder.length<i.pathOrder.length)&&(i=d,i={found:!0,pathOrder:[{path:e,depIndices:[a]},...d.pathOrder],truncated:!1})}return i==null?null:nt(e,e,ln(t,i.pathOrder,n))}function ln(t,e,n){return e.map((r,s)=>{let o=t.nodes[r.path],i=tt(r.path,o,s,n);return r.depIndices!=null&&r.depIndices.length>0&&(i.dep_index=r.depIndices[0],r.depIndices.length>1&&(i.dep_indices=[...r.depIndices])),i})}function tt(t,e,n,r){let s={path:t,type:e.type,hop:n};e.status!==void 0&&(s.status=e.status),"value"in e&&(s.value=e.value),e.v!=null&&(s.v=e.v);let o=r.annotations?.get(t)??e.annotation;o!=null&&(s.annotation=o);let i=r.lastMutations?.get(t)??e.lastMutation;return i!=null&&(s.lastMutation=i),s}function nt(t,e,n){return fn(t,e,!0,"ok",n)}function et(t,e,n){return fn(t,e,!1,n,[])}function fn(t,e,n,r,s){let o=cr(t,e,n,r,s);return{from:t,to:e,found:n,reason:r,steps:s,text:o,toJSON(){return{from:t,to:e,found:n,reason:r,steps:s}}}}function cr(t,e,n,r,s){if(!n)switch(r){case"no-such-from":return`explainPath: no node named "${t}"`;case"no-such-to":return`explainPath: no node named "${e}"`;case"max-depth-exceeded":return`explainPath: no path from "${t}" to "${e}" within maxDepth`;default:return`explainPath: no path from "${t}" to "${e}"`}let o=[`Causal path: ${t} \u2192 ${e} (${s.length} step(s))`];for(let i of s){let u=` ${i.hop===0?"\xB7":"\u2193"} ${i.path} (${i.type}${i.status?`/${i.status}`:""})`;if(o.push(u),"value"in i&&o.push(` value: ${lr(i.value)}`),i.annotation!=null&&o.push(` annotation: ${i.annotation}`),i.lastMutation!=null){let d=i.lastMutation.actor;o.push(` actor: ${d.type}${d.id?`:${d.id}`:""}`)}}return o.join(`
|
|
2
|
+
`)}function lr(t){if(t===void 0)return"<sentinel>";if(t===null)return"null";if(typeof t=="string")return JSON.stringify(t);if(typeof t=="number"||typeof t=="boolean"||typeof t=="bigint")return String(t);try{let e=JSON.stringify(t);return e.length>80?`${e.slice(0,77)}...`:e}catch{return String(t)}}We();De();Me();fe();ke();Dt();ge();Le();Me();function Lt(t,e){if(Object.is(t,e))return!0;if(t==null||e==null||typeof t!="object"||typeof e!="object")return!1;if(Array.isArray(t)){if(!Array.isArray(e)||t.length!==e.length)return!1;for(let o=0;o<t.length;o++)if(!Lt(t[o],e[o]))return!1;return!0}if(Array.isArray(e))return!1;let n=Object.keys(t),r=Object.keys(e);if(n.length!==r.length)return!1;let s=new Set(r);for(let o of n)if(!s.has(o)||!Lt(t[o],e[o]))return!1;return!0}function pn(t,e){return`${t}\0${e}`}function It(t,e){let n=[],r=new Set(t.subgraphs),s=new Set(e.subgraphs),o=[];for(let m of s)r.has(m)||o.push(m);o.sort();for(let m of o)n.push({type:"subgraph-mounted",path:m});let i=new Set(Object.keys(t.nodes)),a=new Set(Object.keys(e.nodes)),u=[];for(let m of a)i.has(m)||u.push(m);u.sort();for(let m of u)n.push({type:"node-added",path:m,node:{...e.nodes[m]}});let d=[];for(let m of a){if(!i.has(m))continue;let T=t.nodes[m]?.meta,w=e.nodes[m]?.meta;T==null&&w==null||Lt(T??{},w??{})||d.push(m)}d.sort();for(let m of d)n.push({type:"node-meta-changed",path:m,prevMeta:t.nodes[m]?.meta??{},nextMeta:e.nodes[m]?.meta??{}});let c=new Map;for(let m of t.edges)c.set(pn(m.from,m.to),m);let h=new Map;for(let m of e.edges)h.set(pn(m.from,m.to),m);let p=[];for(let[m,T]of h)c.has(m)||p.push(T);p.sort((m,T)=>m.from<T.from?-1:m.from>T.from?1:m.to<T.to?-1:m.to>T.to?1:0);for(let m of p)n.push({type:"edge-added",from:m.from,to:m.to});let f=[];for(let[m,T]of c)h.has(m)||f.push(T);f.sort((m,T)=>m.from<T.from?-1:m.from>T.from?1:m.to<T.to?-1:m.to>T.to?1:0);for(let m of f)n.push({type:"edge-removed",from:m.from,to:m.to});let l=[];for(let m of i)a.has(m)||l.push(m);l.sort();for(let m of l)n.push({type:"node-removed",path:m});let y=[];for(let m of r)s.has(m)||y.push(m);y.sort();for(let m of y)n.push({type:"subgraph-unmounted",path:m});return{events:n,flushedAt_ns:se()}}Mt();hn();var $e=class{constructor(e){this.capacity=e;if(!Number.isInteger(e)||e<=0)throw new Error(`RingBuffer capacity must be a positive integer (got ${e})`);this.buf=new Array(e)}buf;head=0;_size=0;get size(){return this._size}get maxSize(){return this.capacity}push(e){let n=(this.head+this._size)%this.capacity;this.buf[n]=e,this._size<this.capacity?this._size++:this.head=(this.head+1)%this.capacity}shift(){if(this._size===0)return;let e=this.buf[this.head];return this.buf[this.head]=void 0,this.head=(this.head+1)%this.capacity,this._size--,e}at(e){if(this._size===0)return;let n=e<0?this._size+e:e;if(!(n<0||n>=this._size))return this.buf[(this.head+n)%this.capacity]}toArray(){let e=new Array(this._size);for(let n=0;n<this._size;n++)e[n]=this.buf[(this.head+n)%this.capacity];return e}clear(){for(let e=0;e<this._size;e++)this.buf[(this.head+e)%this.capacity]=void 0;this.head=0,this._size=0}};Tt();function Pt(t){return t>=768&&t<=879||t>=1155&&t<=1161||t>=1425&&t<=1469||t>=1552&&t<=1562||t>=1611&&t<=1631||t>=1648&&t===1648||t>=1750&&t<=1756||t>=1759&&t<=1764||t>=1767&&t<=1768||t>=1770&&t<=1773||t>=1840&&t<=1866||t>=1958&&t<=1968||t>=2304&&t<=2307||t>=2362&&t<=2383||t>=2385&&t<=2391||t>=2402&&t<=2403||t>=2433&&t<=2435||t>=2492&&t<=2509||t>=2561&&t<=2563||t>=2620&&t<=2641||t>=2672&&t<=2673||t>=2677&&t===2677||t>=3633&&t===3633||t>=3636&&t<=3642||t>=3655&&t<=3662||t>=3761&&t===3761||t>=3764&&t<=3772||t>=3784&&t<=3790||t>=7616&&t<=7679||t>=8400&&t<=8447||t>=65024&&t<=65039||t>=65056&&t<=65071||t===8205?0:t>=4352&&t<=4447||t>=8986&&t<=8987||t>=9001&&t<=9002||t>=9193&&t<=9203||t>=9208&&t<=9210||t>=9725&&t<=9726||t>=9748&&t<=9749||t>=9800&&t<=9811||t===9855||t===9875||t===9889||t>=9898&&t<=9899||t>=9917&&t<=9918||t>=9924&&t<=9925||t===9934||t===9940||t===9962||t>=9970&&t<=9971||t===9973||t===9978||t===9981||t===9986||t===9989||t>=9992&&t<=9997||t===9999||t>=10067&&t<=10069||t===10071||t>=10133&&t<=10135||t===10160||t===10175||t>=10548&&t<=10549||t>=11013&&t<=11015||t>=11035&&t<=11036||t===11088||t===11093||t>=11904&&t<=12350||t>=12352&&t<=12447||t>=12448&&t<=12543||t>=12549&&t<=12591||t>=12593&&t<=12686||t>=12688&&t<=12771||t>=12784&&t<=12830||t>=12832&&t<=12871||t>=12880&&t<=19903||t>=19968&&t<=40959||t>=43360&&t<=43388||t>=44032&&t<=55203||t>=63744&&t<=64255||t>=65040&&t<=65049||t>=65072&&t<=65131||t>=65281&&t<=65376||t>=65504&&t<=65510||t>=126980&&t===126980||t===127183||t>=127344&&t<=127345||t===127358||t===127359||t===127374||t>=127377&&t<=127386||t>=127456&&t<=127487||t>=127488&&t<=127490||t===127514||t===127535||t>=127538&&t<=127546||t>=127568&&t<=127569||t>=127744&&t<=129535||t>=129536&&t<=129791||t>=129792&&t<=130047||t>=131072&&t<=196605||t>=196608&&t<=262141?2:1}function st(t){let e=0;for(let n of t)e+=Pt(n.codePointAt(0));return e}function gn(t,e){if(e<=0)return"";let n=0,r="";for(let s of t){let o=Pt(s.codePointAt(0));if(n+o>e){if(e<=1)return"\u2026";for(;n+1>e&&r.length>0;){let i=[...r].pop();r=r.slice(0,-i.length),n-=Pt(i.codePointAt(0))}return`${r}\u2026`}r+=s,n+=o}return r}var fr={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"},pr={horizontal:"-",vertical:"|",cornerTL:"+",cornerTR:"+",cornerBL:"+",cornerBR:"+",tDown:"+",tUp:"+",tRight:"+",tLeft:"+",cross:"+",arrowRight:">",arrowDown:"v",arrowLeft:"<",arrowUp:"^",boxTL:"+",boxTR:"+",boxBL:"+",boxBR:"+",boxH:"-",boxV:"|"};function vn(t,e){let n=e.charset==="ascii"?pr:fr,r=t.width,s=t.height,o=Array.from({length:s},()=>Array.from({length:r},()=>" ")),i=Array.from({length:s},()=>Array.from({length:r},()=>"empty"));for(let a of t.edges)gr(o,i,n,a);for(let a of t.boxes)hr(o,i,n,a,e.labelOf(a.id));return o.map(a=>vr(a.join(""))).join(`
|
|
3
|
+
`)}function hr(t,e,n,r,s){let{x:o,y:i,w:a,h:u}=r;if(a<2||u<2){u>0&&mn(t,e,o,i,a,s);return}ae(t,e,o,i,n.boxTL);for(let c=o+1;c<o+a-1;c+=1)ae(t,e,c,i,n.boxH);ae(t,e,o+a-1,i,n.boxTR);for(let c=i+1;c<i+u-1;c+=1){ae(t,e,o,c,n.boxV);for(let h=o+1;h<o+a-1;h+=1)_n(t,e,h,c," ","empty");ae(t,e,o+a-1,c,n.boxV)}ae(t,e,o,i+u-1,n.boxBL);for(let c=o+1;c<o+a-1;c+=1)ae(t,e,c,i+u-1,n.boxH);ae(t,e,o+a-1,i+u-1,n.boxBR);let d=i+Math.floor(u/2);mn(t,e,o+1,d,a-2,s)}function ae(t,e,n,r,s){_n(t,e,n,r,s,s===" "?"empty":s==="\u2500"||s==="-"?"boxH":s==="\u2502"||s==="|"?"boxV":"boxCorner")}function _n(t,e,n,r,s,o){if(r<0||r>=t.length)return;let i=t[r];n<0||n>=i.length||(i[n]=s,e[r][n]=o)}function mn(t,e,n,r,s,o){if(r<0||r>=t.length)return;let i=n,a=s;for(let u of o){let d=st(u);if(d!==0){if(a<d)break;i>=0&&i<t[r].length&&(t[r][i]=u,e[r][i]="label",d===2&&i+1<t[r].length&&(t[r][i+1]="",e[r][i+1]="label")),i+=d,a-=d}}for(;a>0;)i>=0&&i<t[r].length&&(t[r][i]=" ",e[r][i]="empty"),i+=1,a-=1}function gr(t,e,n,r){let s=r.points;if(s.length<2)return;for(let u=0;u+1<s.length;u+=1)mr(t,e,n,s[u],s[u+1]);for(let u=1;u+1<s.length;u+=1){let d=s[u-1],c=s[u],h=s[u+1],p=yr(d,c,h,n);p&&bn(t,e,c.x,c.y,p,"edgeCorner")}let o=s[s.length-1],i=s[s.length-2],a=br(i,o,n);a&&bn(t,e,o.x,o.y,a,"arrow")}function mr(t,e,n,r,s){if(!(r.x===s.x&&r.y===s.y)){if(r.y===s.y){let o=r.y,i=Math.min(r.x,s.x),a=Math.max(r.x,s.x);for(let u=i;u<=a;u+=1)yn(t,e,u,o,n,"h")}else if(r.x===s.x){let o=r.x,i=Math.min(r.y,s.y),a=Math.max(r.y,s.y);for(let u=i;u<=a;u+=1)yn(t,e,o,u,n,"v")}}}function yn(t,e,n,r,s,o){if(r<0||r>=t.length)return;let i=t[r];if(n<0||n>=i.length)return;let a=e[r][n];if(!(a==="boxH"||a==="boxV"||a==="boxCorner"||a==="label")){if(a==="empty"){i[n]=o==="h"?s.horizontal:s.vertical,e[r][n]=o==="h"?"edgeH":"edgeV";return}if(a==="edgeH"&&o==="v"){i[n]=s.cross,e[r][n]="edgeCorner";return}if(a==="edgeV"&&o==="h"){i[n]=s.cross,e[r][n]="edgeCorner";return}}}function bn(t,e,n,r,s,o){if(r<0||r>=t.length)return;let i=t[r];if(n<0||n>=i.length)return;let a=e[r][n];a==="boxH"||a==="boxV"||a==="boxCorner"||a==="label"||(i[n]=s,e[r][n]=o)}function yr(t,e,n,r){let s=t.y===e.y,o=e.y===n.y;if(s===o)return;if(s){let u=t.x<e.x,d=n.y>e.y;return u&&d?r.cornerTR:u&&!d?r.cornerBR:!u&&d?r.cornerTL:r.cornerBL}let i=t.y<e.y,a=n.x>e.x;return i&&a?r.cornerBL:i&&!a?r.cornerBR:!i&&a?r.cornerTL:r.cornerTR}function br(t,e,n){if(e.x>t.x)return n.arrowRight;if(e.x<t.x)return n.arrowLeft;if(e.y>t.y)return n.arrowDown;if(e.y<t.y)return n.arrowUp}function vr(t){let e=t.length;for(;e>0&&t.charCodeAt(e-1)===32;)e-=1;return t.slice(0,e)}function Tn(t){let e=_r(t);wr(e),xr(e),Tr(e),Er(e,t);let n=Rr(e,t),{width:r,height:s}=Nr(e),o=[];for(let i of e.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:n,width:r,height:s}}function _r(t){let e=new Map;for(let s of t.nodes)e.set(s,{id:s,isVirtual:!1,layer:-1,order:0,x:0,y:0,w:t.widthCells(s),h:t.heightCells(s),in:[],out:[]});let n=[],r=0;for(let s of t.edges){if(s.from===s.to)continue;let o=e.get(s.from),i=e.get(s.to);if(!o||!i)continue;let a={chainId:r++,chainFrom:s.from,chainTo:s.to,fromId:s.from,toId:s.to,hopIndex:0,chainLen:1};o.out.push(a),i.in.push(a),n.push(a)}return{nodes:e,layers:[],hops:n}}function wr(t){let e=new Map;for(let o of t.nodes.values())e.set(o.id,o.in.length);let n=[];for(let o of t.nodes.values())(e.get(o.id)??0)===0&&(o.layer=0,n.push(o));let r=new Set,s=0;for(;s<n.length;){let o=n[s++];if(!r.has(o.id)){r.add(o.id);for(let i of o.out){let a=t.nodes.get(i.toId);a.layer=Math.max(a.layer,o.layer+1);let u=(e.get(a.id)??0)-1;e.set(a.id,u),u<=0&&n.push(a)}}}for(let o of t.nodes.values())o.layer<0&&(o.layer=0)}function xr(t){let e=Math.max(0,...Array.from(t.nodes.values(),o=>o.layer)),n=Array.from({length:e+1},()=>[]);for(let o of t.nodes.values())n[o.layer].push(o);let r=[],s=0;for(let o of t.hops){let i=t.nodes.get(o.fromId),a=t.nodes.get(o.toId),u=a.layer-i.layer;if(u<=0){i.out=i.out.filter(h=>h!==o),a.in=a.in.filter(h=>h!==o);continue}if(u===1){o.hopIndex=0,o.chainLen=1,r.push(o);continue}i.out=i.out.filter(h=>h!==o),a.in=a.in.filter(h=>h!==o);let d=i;for(let h=1;h<u;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:[]};t.nodes.set(p,f),n[f.layer].push(f);let l={chainId:o.chainId,chainFrom:o.chainFrom,chainTo:o.chainTo,fromId:d.id,toId:p,hopIndex:h-1,chainLen:u};d.out.push(l),f.in.push(l),r.push(l),d=f}let c={chainId:o.chainId,chainFrom:o.chainFrom,chainTo:o.chainTo,fromId:d.id,toId:a.id,hopIndex:u-1,chainLen:u};d.out.push(c),a.in.push(c),r.push(c)}for(let o of n)for(let i=0;i<o.length;i+=1)o[i].order=i;t.layers=n,t.hops=r}function Tr(t){for(let n=0;n<4;n+=1){for(let r=1;r<t.layers.length;r+=1)wn(t,t.layers[r],"in"),ot(t.layers[r]);for(let r=t.layers.length-2;r>=0;r-=1)wn(t,t.layers[r],"out"),ot(t.layers[r])}for(let n=0;n<2;n+=1){let r=!1;for(let s=1;s<t.layers.length;s+=1){let o=t.layers[s];for(let i=0;i+1<o.length;i+=1){let a=xn(t,o[i],o[i+1],"in");[o[i],o[i+1]]=[o[i+1],o[i]],ot(o),xn(t,o[i],o[i+1],"in")<a?r=!0:([o[i],o[i+1]]=[o[i+1],o[i]],ot(o))}}if(!r)break}}function wn(t,e,n){let r=new Map;for(let s of e){let o=n==="in"?s.in:s.out;if(o.length===0){r.set(s.id,s.order);continue}let i=0,a=0;for(let u of o){let d=t.nodes.get(n==="in"?u.fromId:u.toId);d&&(i+=d.order,a+=1)}r.set(s.id,a===0?s.order:i/a)}e.sort((s,o)=>{let i=r.get(s.id),a=r.get(o.id);return i!==a?i-a:s.order-o.order})}function ot(t){for(let e=0;e<t.length;e+=1)t[e].order=e}function xn(t,e,n,r){let s=r==="in"?e.in:e.out,o=r==="in"?n.in:n.out,i=0;for(let a of s)for(let u of o){let d=t.nodes.get(r==="in"?a.fromId:a.toId)?.order??0,c=t.nodes.get(r==="in"?u.fromId:u.toId)?.order??0;(e.order<n.order&&d>c||e.order>n.order&&d<c)&&(i+=1)}return i}function Er(t,e){e.direction==="LR"?Or(t,e):kr(t,e)}function Or(t,e){let n=[],r=0;for(let s=0;s<t.layers.length;s+=1){n.push(r);let o=0;for(let i of t.layers[s])o=Math.max(o,i.w);r+=o+e.layerGap}for(let s=0;s<t.layers.length;s+=1)for(let o of t.layers[s])o.x=n[s];for(let s of t.layers){let o=0;for(let i of s)i.y=o,o+=i.h+e.nodeGap}En(t,e,"y")}function kr(t,e){let n=[],r=0;for(let s=0;s<t.layers.length;s+=1){n.push(r);let o=0;for(let i of t.layers[s])o=Math.max(o,i.h);r+=o+e.layerGap}for(let s=0;s<t.layers.length;s+=1)for(let o of t.layers[s])o.y=n[s];for(let s of t.layers){let o=0;for(let i of s)i.x=o,o+=i.w+e.nodeGap}En(t,e,"x")}function En(t,e,n){let r=o=>n==="y"?o.h:o.w,s=e.nodeGap;for(let o=0;o<2;o+=1){let i=o===0?t.layers.slice(1):t.layers.slice(0,-1).reverse();for(let a of i){let u=new Map;for(let c of a){let h=o===0?c.in:c.out;if(h.length===0)continue;let p=[];for(let l of h){let y=t.nodes.get(o===0?l.fromId:l.toId);if(!y)continue;let m=n==="y"?y.y:y.x;p.push(m+Math.floor(r(y)/2))}if(p.length===0)continue;p.sort((l,y)=>l-y);let f=p[Math.floor(p.length/2)];u.set(c.id,f-Math.floor(r(c)/2))}let d=0;for(let c of a){let h=u.get(c.id),p=n==="y"?c.y:c.x,l=Math.max(h??p,d);n==="y"?c.y=l:c.x=l,d=l+r(c)+s}}}}function Rr(t,e){let n=new Map;for(let d of t.hops){let c=n.get(d.chainId);c?c.push(d):n.set(d.chainId,[d])}for(let d of n.values())d.sort((c,h)=>c.hopIndex-h.hopIndex);let r=e.direction==="LR",s=d=>r?d.x:d.y,o=d=>r?d.w:d.h,i=d=>r?d.y+Math.floor(d.h/2):d.x+Math.floor(d.w/2),a=new Map;for(let d=0;d+1<t.layers.length;d+=1){let c=t.layers[d],h=t.layers[d+1],p=0;for(let v of c)p=Math.max(p,s(v)+o(v));let f=Number.POSITIVE_INFINITY;for(let v of h)f=Math.min(f,s(v));let l=Number.isFinite(f)?f-1:p,y=Math.max(1,l-p+1),m=[];for(let v of c)for(let k of v.out)m.push(k);m.sort((v,k)=>{let E=i(t.nodes.get(v.fromId)),x=i(t.nodes.get(k.fromId));if(E!==x)return E-x;let N=i(t.nodes.get(v.toId)),S=i(t.nodes.get(k.toId));return N-S});let T=[],w=new Map;for(let v of m){let k=i(t.nodes.get(v.fromId)),E=i(t.nodes.get(v.toId)),x=Math.min(k,E),N=Math.max(k,E),S=-1;for(let A=0;A<T.length;A+=1){let D=T[A],G=!0;for(let j of D)if(j.lo<=N&&x<=j.hi){G=!1;break}if(G){D.push({lo:x,hi:N}),S=A;break}}S<0&&(T.push([{lo:x,hi:N}]),S=T.length-1),w.set(v,S)}let b=T.length,_=y>=Math.max(3,b+2),R=_?p+1:p,O=_?l-1:l,g=Math.max(1,O-R+1);for(let v of m){let k=w.get(v),E;if(b<=1)E=R+Math.floor(g/2);else{let x=(g-1)/(b-1);E=R+Math.floor(k*x)}a.set(v,Math.max(p,Math.min(l,E)))}}let u=[];for(let[,d]of n){let c=[];for(let p=0;p<d.length;p+=1){let f=d[p],l=t.nodes.get(f.fromId),y=t.nodes.get(f.toId),m=a.get(f),T=l.isVirtual?s(l):s(l)+o(l),w=y.isVirtual?s(y):s(y)-1,b=i(l),_=i(y);p===0&&it(c,r,T,b),b!==_&&(it(c,r,m,b),it(c,r,m,_)),it(c,r,w,_)}let h=d[0];u.push({from:h.chainFrom,to:h.chainTo,points:Sr(c)})}return u}function it(t,e,n,r){t.push(e?{x:n,y:r}:{x:r,y:n})}function Sr(t){let e=[];for(let n of t){let r=e[e.length-1];(!r||r.x!==n.x||r.y!==n.y)&&e.push(n)}return e}function Nr(t){let e=0,n=0;for(let r of t.layers)for(let s of r)e=Math.max(e,s.x+s.w),n=Math.max(n,s.y+s.h);return{width:e,height:n}}var Ar=24,Cr=4,Dr=1,Mr=3;function On(t,e){let n=Gr(e.direction),r=Math.max(3,e.maxLabelWidth??Ar),s=e.asciiCharset??"unicode",o=Object.keys(t.nodes).sort(),i=new Set(o),a=t.edges.filter(f=>i.has(f.from)&&i.has(f.to)),u=new Map,d=new Map;for(let f of o){let l=gn(f,r);u.set(f,l),d.set(f,st(l)+4)}let c=Tn({nodes:o,edges:a,widthCells:f=>d.get(f)??3,heightCells:()=>Mr,layerGap:Cr,nodeGap:Dr,direction:n}),h=vn(c,{charset:s,labelOf:f=>u.get(f)??f}),p=e.logger;return p&&p(h),h}function Gr(t){if(t===void 0||t==="LR")return"LR";if(t==="TD")return"TD";throw new Error(`ascii describe supports direction "LR" or "TD" only; got ${String(t)}`)}ge();function kn(t,e){let n=e?.topN??10,r=t.describe({detail:"standard"}),s=[],o=t._collectObserveTargets;typeof o=="function"&&o.call(t,"",s);let i=new Map;for(let[p,f]of s)i.set(p,f);let a=[];for(let[p,f]of Object.entries(r.nodes)){let l=i.get(p),y=l instanceof V?l:null,m=y?dn(y.cache):0,T=y?y._sinkCount:0,w=f.deps?.length??0,b=f.type==="effect"&&T===0,_=T===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:m,subscriberCount:T,depCount:w,isOrphanEffect:b,orphanKind:_})}let u=a.reduce((p,f)=>p+f.valueSizeBytes,0),d=(p,f)=>[...a].sort(f??((l,y)=>y[p]-l[p])).slice(0,n),c=a.filter(p=>p.orphanKind!=null),h=a.filter(p=>p.isOrphanEffect);return{nodeCount:a.length,edgeCount:r.edges.length,subgraphCount:r.subgraphs.length,nodes:a,totalValueSizeBytes:u,hotspots:{byValueSize:d("valueSizeBytes"),bySubscriberCount:d("subscriberCount"),byDepCount:d("depCount")},orphans:c,orphanEffects:h}}var I="::",ee="__meta__",me=1;function Rn(t,e){let n=Math.max(16,t.size*4),r=0;for(;t.size>0;){if(r++>=n){console.error(`[Graph "${e}".destroy] disposer drain exceeded cap (${n}); ${t.size} disposer(s) discarded`),t.clear();return}let s=t.values().next();if(s.done)return;let o=s.value;t.delete(o);try{o()}catch(i){console.error(`[Graph "${e}".destroy] disposer threw:`,i)}}}function An(t){return t!=null&&typeof t=="object"&&"cache"in t&&typeof t.subscribe=="function"&&typeof t.down=="function"}function Lr(t){if(t!=null)return An(t)?t.cache:t}function Ir(t){let e=[];for(let n of Object.keys(t).sort()){let r=t[n].v;r!=null&&e.push(`${n} ${r.id} ${r.version}`)}return e.join(`
|
|
4
|
+
`)}function Sn(t){if(t.version!==me)throw new Error(`unsupported snapshot version ${String(t.version)} (expected ${me})`);for(let e of["name","nodes","edges","subgraphs"])if(!(e in t))throw new Error(`snapshot missing required key "${e}"`);if(typeof t.name!="string")throw new TypeError("snapshot 'name' must be a string");if(typeof t.nodes!="object"||t.nodes===null||Array.isArray(t.nodes))throw new TypeError("snapshot 'nodes' must be an object");if(!Array.isArray(t.edges))throw new TypeError("snapshot 'edges' must be an array");if(!Array.isArray(t.subgraphs))throw new TypeError("snapshot 'subgraphs' must be an array")}function Pr(t,e){let n=new WeakMap,r=(s,o)=>{if(Object.is(s,o))return!0;if(s==null||o==null||typeof s!="object"||typeof o!="object")return!1;let i=n.get(s);if(i==null&&(i=new WeakSet,n.set(s,i)),i.has(o))return!0;i.add(o);let a=s.constructor,u=o.constructor;if(a!==u)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(!r(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,l]of s)if(!p.has(f)||!r(l,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 l=!1;for(let y of p)if(r(f,y)){l=!0;break}if(!l)return!1}return!0}if(ArrayBuffer.isView(s)){let p=s,f=o;if(p.length!==f.length)return!1;for(let l=0;l<p.length;l++)if(p[l]!==f[l])return!1;return!0}let d=Object.keys(s),c=Object.keys(o);if(d.length!==c.length)return!1;let h=new Set(c);for(let p of d)if(!h.has(p)||!r(s[p],o[p]))return!1;return!0};return r(t,e)}function Vt(t){if(t===null||typeof t!="object")return t;if(Array.isArray(t))return t.map(Vt);let e=t,n=Object.keys(e).sort(),r={};for(let s of n)r[s]=Vt(e[s]);return r}function $r(t){return t.replaceAll("\\","\\\\").replaceAll('"','\\"')}function Vr(t){return t.replaceAll("\\","\\\\").replaceAll('"','\\"')}function Fr(t){return t==="TD"?"down":t==="BT"?"up":t==="RL"?"left":"right"}function Cn(t){let e=new Set,n=[];function r(s,o){let i=`${s}\0${o}`;e.has(i)||(e.add(i),n.push([s,o]))}for(let[s,o]of Object.entries(t.nodes)){let i=o.deps;if(i)for(let a of i)r(a,s)}for(let s of t.edges)r(s.from,s.to);return n}function Dn(t){if(t===void 0)return"LR";if(t==="TD"||t==="LR"||t==="BT"||t==="RL")return t;throw new Error(`invalid diagram direction ${String(t)}; expected one of: TD, LR, BT, RL`)}function zr(t,e){let n=e.includeEdges??!0,r=e.includeSubgraphs??!0,{expand:s,...o}=t,i={...o,edges:n?t.edges:[],subgraphs:r?t.subgraphs:[]},a=JSON.stringify(Vt(i),null,e.indent??2);return e.logger?.(a),a}function jr(t,e){let n=e.includeEdges??!0,r=e.includeSubgraphs??!0,s=[];s.push(`Graph ${t.name}`),s.push("Nodes:");for(let i of Object.keys(t.nodes).sort()){let a=t.nodes[i];s.push(`- ${i} (${a.type}/${a.status}): ${dt(a.value)}`)}if(n){s.push("Edges:");for(let i of t.edges)s.push(`- ${i.from} -> ${i.to}`)}if(r){s.push("Subgraphs:");for(let i of t.subgraphs)s.push(`- ${i}`)}let o=s.join(`
|
|
5
|
+
`);return e.logger?.(o),o}function Mn(t,e){let n=Dn(e.direction),r=Object.keys(t.nodes).sort(),s=new Map;for(let i=0;i<r.length;i+=1)s.set(r[i],`n${i}`);let o=[`flowchart ${n}`];for(let i of r){let a=s.get(i);o.push(` ${a}["${$r(i)}"]`)}for(let[i,a]of Cn(t)){let u=s.get(i),d=s.get(a);!u||!d||o.push(` ${u} --> ${d}`)}return o.join(`
|
|
6
|
+
`)}function Br(t,e){let n=Mn(t,e);return Gn(n)}function Gn(t,e){let n=e?.theme??"default",r=e?.autoSync??!0,o=JSON.stringify({code:t,mermaid:{theme:n},autoSync:r}),i=new TextEncoder().encode(o),a="";for(let d=0;d<i.length;d++)a+=String.fromCharCode(i[d]);return`https://mermaid.live/edit#base64:${globalThis.btoa(a).replace(/\+/g,"-").replace(/\//g,"_").replace(/=+$/,"")}`}function Hr(t,e){let n=Dn(e.direction),r=Object.keys(t.nodes).sort(),s=new Map;for(let i=0;i<r.length;i+=1)s.set(r[i],`n${i}`);let o=[`direction: ${Fr(n)}`];for(let i of r){let a=s.get(i);o.push(`${a}: "${Vr(i)}"`)}for(let[i,a]of Cn(t)){let u=s.get(i),d=s.get(a);!u||!d||o.push(`${u} -> ${d}`)}return o.join(`
|
|
7
|
+
`)}function qr(t){return t.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function at(t){let e="^";for(let n=0;n<t.length;n+=1){let r=t[n];if(r==="*"){e+=".*";continue}if(r==="?"){e+=".";continue}if(r==="["){let s=t.indexOf("]",n+1);if(s<=n+1){e+="\\[";continue}let o=t.slice(n+1,s);o.startsWith("!")&&(o=`^${o.slice(1)}`),o=o.replace(/\\/g,"\\\\"),e+=`[${o}]`,n=s;continue}e+=qr(r)}return e+="$",new RegExp(e)}var Wr={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"},Ur={data:"",dirty:"",resolved:"",invalidate:"",pause:"",resume:"",complete:"",error:"",teardown:"",derived:"",path:"",reset:""};function dt(t){if(typeof t=="string")return JSON.stringify(t);if(typeof t=="number"||typeof t=="boolean"||t==null)return String(t);try{return JSON.stringify(t)}catch{return"[unserializable]"}}function Kr(t){return t==="none"?Ur:t==="ansi"||t==null?Wr:{data:t.data??"",dirty:t.dirty??"",resolved:t.resolved??"",invalidate:t.invalidate??"",pause:t.pause??"",resume:t.resume??"",complete:t.complete??"",error:t.error??"",teardown:t.teardown??"",derived:t.derived??"",path:t.path??"",reset:t.reset??""}}function Nn(t){if(t==null)return{};let e=t.detail;return e==="full"?{...t,structured:t.structured??!0,timeline:t.timeline??!0,causal:t.causal??!0,derived:t.derived??!0}:e==="minimal"?{...t,structured:t.structured??!0}:t.format==="stage-log"?{...t,structured:t.structured??!0,timeline:t.timeline??!0}:t}function Yr(t,e,n){for(let r=0;r<t.length;r++){let s=t.charCodeAt(r);if(s<32||s===127)throw new Error(`Graph "${e}": ${n} "${t}" must not contain control character (U+${s.toString(16).padStart(4,"0").toUpperCase()} at index ${r})`)}}function $t(t,e,n){if(t==="")throw new Error(`Graph "${e}": ${n} name must be non-empty`);if(t.includes(I))throw new Error(`Graph "${e}": ${n} "${t}" must not contain '${I}' (path separator)`);if(t===ee)throw new Error(`Graph "${e}": ${n} name "${ee}" is reserved for meta companion paths`);Yr(t,e,n)}function Jr(t,e){if(t==="")throw new Error(`Graph "${e}": resolve path must be non-empty`);let n=t.split(I);for(let r of n)if(r==="")throw new Error(`Graph "${e}": resolve path has empty segment`);return n}function Xr(t,e){let n=!1;for(let s of t)if(!e.isMetaPassthrough(s[0])){n=!0;break}return n?t.filter(s=>e.isMetaPassthrough(s[0])):t}function Ln(t){for(let e of t._mounts.values())Ln(e);for(let e of t._nodes.values())try{e.down([[z]],{internal:!0})}catch{}}var de=class t{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;_factory;_factoryArgs;constructor(e,n){if(e==="")throw new Error("Graph name must be non-empty");if(e.includes(I))throw new Error(`Graph name must not contain '${I}' (got "${e}")`);if(e===ee)throw new Error(`Graph name "${ee}" is reserved for meta companion paths`);this.name=e,this.opts=Object.freeze({...n??{}}),this.config=n?.config??he,this._traceRing=new $e(n?.traceCapacity??1e3),n?.versioning!=null&&this.setVersioning(n.versioning),typeof n?.factory=="string"&&(this._factory=n.factory,n.factoryArgs!==void 0&&(this._factoryArgs=n.factoryArgs))}tagFactory(e,n){return this._factory=e,this._factoryArgs=n,this}ancestors(e=!0){let n=[],r=e?this:this._parent;for(;r!=null;)n.push(r),r=r._parent;return n}get topology(){return this._topology==null&&(this._topology=Qe(e=>{let n=r=>{e.emit(r)};return this._topologyEmitters.add(n),()=>{this._topologyEmitters.delete(n)}},{name:`${this.name}_topology`})),this._topology}_emitTopology(e){if(!(this._topology==null||this._topologyEmitters.size===0))for(let n of this._topologyEmitters)n(e)}nameOf(e){return this._nodeToName.get(e)}add(e,n){let r=e.name,s=n?.name??r;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=n?.annotation;if($t(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(e);if(a!==void 0)throw new Error(`Graph "${this.name}": node instance already registered as "${a}"`);return this._nodes.set(o,e),this._nodeToName.set(e,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:se()})),e}setVersioning(e){if(e!=null)for(let n of this._nodes.values())n instanceof V&&n._applyVersioning(e)}remove(e){$t(e,this.name,"remove");let n=this._mounts.get(e);if(n){let o={kind:"mount",nodes:[],mounts:[]},i=[];n._collectObserveTargets("",i);for(let[a,u]of i)a.includes(`${I}${ee}${I}`)||o.nodes.push(a);return o.nodes.sort(),o.mounts.push(e),o.mounts.push(...n._collectSubgraphs(`${e}${I}`)),this._mounts.delete(e),n._parent=void 0,Ln(n),this._emitTopology({kind:"removed",name:e,nodeKind:"mount",audit:o}),o}let r=this._nodes.get(e);if(!r)throw new Error(`Graph "${this.name}": unknown node or mount "${e}"`);this._nodes.delete(e),this._nodeToName.delete(r),r.down([[z]],{internal:!0});let s={kind:"node",nodes:[e],mounts:[]};return this._emitTopology({kind:"removed",name:e,nodeKind:"node",audit:s}),s}removeAll(e){let n=typeof e=="function"?e:(()=>{let o=at(e);return i=>o.test(i)})(),r={kind:"mount",nodes:[],mounts:[]},s=[...this._nodes.keys(),...this._mounts.keys()].filter(o=>n(o));for(let o of s){let i=this.remove(o);r.nodes.push(...i.nodes),r.mounts.push(...i.mounts)}return r.nodes.sort(),r.mounts.sort(),r}[Symbol.iterator](){let e=[...this._nodes.keys()].sort(),n=this._nodes,r=0;return{[Symbol.iterator](){return this},next(){if(r>=e.length)return{value:void 0,done:!0};let s=e[r++];return{value:[s,n.get(s)],done:!1}}}}node(e){if(e==="")throw new Error(`Graph "${this.name}": node name must be non-empty`);if(e.includes(I))return this.resolve(e);let n=this._nodes.get(e);if(!n)throw new Error(`Graph "${this.name}": unknown node "${e}"`);return n}get(e){return this.node(e).cache}set(e,n,r){let s=r?.internal===!0;this.node(e).down([[P,n]],{actor:r?.actor,internal:s,delivery:"write"})}setAll(e,n){let r=Symbol.iterator in e?e:Object.entries(e);xe(()=>{for(let[s,o]of r)this.set(s,o,n)})}invalidate(e,n){let r=n?.internal===!0;this.node(e).down([[Q]],{actor:n?.actor,internal:r,delivery:"write"})}error(e,n,r){let s=r?.internal===!0;this.node(e).down([[$,n]],{actor:r?.actor,internal:s,delivery:"write"})}complete(e,n){let r=n?.internal===!0;this.node(e).down([[H]],{actor:n?.actor,internal:r,delivery:"write"})}edges(e){let n=e?.recursive===!0,r=new Map;if(!n){for(let[u,d]of this._nodes)r.set(d,u);let a=[];for(let[u,d]of this._nodes)if(d instanceof V)for(let c of d._deps){let h=r.get(c.node);h!=null&&a.push([h,u])}return a.sort((u,d)=>u[0]<d[0]?-1:u[0]>d[0]?1:u[1]<d[1]?-1:u[1]>d[1]?1:0),a}let s=[];this._collectObserveTargets("",s);let o=new Map;for(let[a,u]of s)o.set(u,a);let i=[];for(let[a,u]of s)if(u instanceof V)for(let d of u._deps){let c=o.get(d.node);c!=null&&i.push([c,a])}return i.sort((a,u)=>a[0]<u[0]?-1:a[0]>u[0]?1:a[1]<u[1]?-1:a[1]>u[1]?1:0),i}mount(e,n){if(n===void 0){let s=new t(e);return this.mount(e,s)}if(typeof n=="function"){let s=new t(e);return n(s),this.mount(e,s)}let r=n;if($t(e,this.name,"mount"),this._nodes.has(e))throw new Error(`Graph "${this.name}": cannot mount at "${e}" \u2014 node with that name exists`);if(this._mounts.has(e))throw new Error(`Graph "${this.name}": mount "${e}" already exists`);if(r===this)throw new Error(`Graph "${this.name}": cannot mount a graph into itself`);if(r._parent!=null)throw new Error(`Graph "${this.name}": this child graph is already mounted on "${r._parent.name}"`);for(let s=this;s!=null;s=s._parent)if(s===r)throw new Error(`Graph "${this.name}": mount("${e}", \u2026) would create a mount cycle`);return this._mounts.set(e,r),r._parent=this,this._emitTopology({kind:"added",name:e,nodeKind:"mount"}),r}resolve(e){let n=Jr(e,this.name);return this._resolveFromSegments(n)}tryResolve(e){try{return this.resolve(e)}catch{return}}_resolveFromSegments(e){let n=e;if(n[0]===this.name&&(n=n.slice(1),n.length===0))throw new Error(`Graph "${this.name}": resolve path ends at graph name only`);let r=n[0],s=n.slice(1);if(s.length===0){let a=this._nodes.get(r);if(a)return a;throw this._mounts.has(r)?new Error(`Graph "${this.name}": path ends at subgraph "${r}" \u2014 not a node (GRAPHREFLY-SPEC \xA73.5)`):new Error(`Graph "${this.name}": unknown name "${r}"`)}let o=this._nodes.get(r);if(o&&s.length>0&&s[0]===ee)return this._resolveMetaChainFromNode(o,s,n.join(I));let i=this._mounts.get(r);if(!i)throw this._nodes.has(r)?new Error(`Graph "${this.name}": "${r}" is a node; trailing path "${s.join(I)}" is invalid`):new Error(`Graph "${this.name}": unknown mount or node "${r}"`);return i.resolve(s.join(I))}_resolveMetaChainFromNode(e,n,r){let s=e,o=0,i=[...n];for(;o<i.length;){if(i[o]!==ee)throw new Error(`Graph "${this.name}": expected ${ee} segment in meta path "${r}"`);if(o+1>=i.length)throw new Error(`Graph "${this.name}": meta path requires a key after ${ee} in "${r}"`);let a=i[o+1],u=s.meta[a];if(!u)throw new Error(`Graph "${this.name}": unknown meta "${a}" in path "${r}"`);s=u,o+=2}return s}signal(e,n){if(n?.internal!==!0){for(let s of e)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 r=[];if(this._signalDeliver(e,n??{},new Set,r),r.length>0)throw r[0]}_signalDeliver(e,n,r,s){for(let u of this._mounts.values())u._signalDeliver(e,n,r,s);let i=n.internal===!0?{internal:!0}:{actor:n.actor,delivery:"signal"},a=Xr(e,this.config);for(let u of[...this._nodes.keys()].sort()){let d=this._nodes.get(u);if(!r.has(d)){r.add(d);try{d.down(e,i)}catch(c){if(c instanceof Z)throw c;s.push(c)}a.length!==0&&this._signalMetaSubtree(d,a,r,i,s)}}}_signalMetaSubtree(e,n,r,s,o){for(let i of Object.keys(e.meta).sort()){let a=e.meta[i];if(!r.has(a)){r.add(a);try{a.down(n,s)}catch(u){if(u instanceof Z)throw u;o.push(u)}this._signalMetaSubtree(a,n,r,s,o)}}}describe(e){if(e?.reactive==="diff")return this._describeReactiveDiff(e);if(e?.reactive===!0)return this._describeReactive(e);let n=Lr(e?.actor),r=e?.filter,s=Ge(e?.detail,e?.fields),o=e?.format==="spec",i=o?Ge("minimal"):s,a=[];this._collectObserveTargets("",a);let u=new Map;for(let[O,g]of a)u.set(g,O);let d=[];{let O=a.map(([,k])=>k),g=new Set(u.values()),v=0;for(;O.length>0;){let k=O.shift();if(k instanceof V)for(let E of k._deps){let x=E.node;if(u.has(x))continue;let N=x.name??"",S=N;if(!S||g.has(S))if(N){let A=2;for(;g.has(`${N}#${A}`);)A++;S=`${N}#${A}`}else for(S=`__internal__/${v++}`;g.has(S);)S=`__internal__/${v++}`;u.set(x,S),g.add(S),d.push([S,x]),O.push(x)}}}let c=[...a,...d],h={};for(let[O,g]of c){if(n!=null&&!g.allowsObserve(n))continue;let v=Ct(g,i),k=g instanceof V?g._deps.map(S=>u.get(S.node)??S.node.name??""):[],{name:E,...x}=v,N={...x,deps:k};if(!o){let S=this._annotations.get(O);S!=null&&(N.annotation=S)}if(r!=null)if(typeof r=="function"){let S=r;if(!(S.length>=2?S(O,N):S(N)))continue}else{let S=!0;for(let[A,D]of Object.entries(r)){let G=A==="deps_includes"?"depsIncludes":A==="meta_has"?"metaHas":A;if(G==="depsIncludes"){if(!N.deps.includes(String(D))){S=!1;break}continue}if(G==="metaHas"){if(!Object.hasOwn(N.meta??{},String(D))){S=!1;break}continue}if(N[G]!==D){S=!1;break}}if(!S)continue}h[O]=N}let p=new Set(Object.keys(h)),f=[];for(let[O,g]of c)if(g instanceof V)for(let v of g._deps){let k=u.get(v.node);k!=null&&f.push([k,O])}f.sort((O,g)=>O[0]<g[0]?-1:O[0]>g[0]?1:O[1]<g[1]?-1:O[1]>g[1]?1:0);let l=f.map(([O,g])=>({from:O,to:g}));(n!=null||r!=null)&&(l=l.filter(O=>p.has(O.from)&&p.has(O.to)));let y=this._collectSubgraphs(""),m=n!=null||r!=null?y.filter(O=>{let g=`${O}${I}`;return[...p].some(v=>v===O||v.startsWith(g))}):y,T=this,w=e,b={name:this.name,nodes:h,edges:l,subgraphs:m,...this._factory!==void 0?{factory:this._factory}:{},...this._factoryArgs!==void 0?{factoryArgs:this._factoryArgs}:{},expand(O){let g={...w,format:void 0};return Array.isArray(O)?(g.fields=O,g.detail=void 0):(g.detail=O,g.fields=void 0),T.describe(g)}},_=e??{},R=_.format;return R==="json"?zr(b,_):R==="pretty"?jr(b,_):R==="mermaid"?Mn(b,_):R==="mermaid-url"?Br(b,_):R==="d2"?Hr(b,_):R==="ascii"?On(b,_):b}_collectSubgraphs(e){let n=[];for(let r of[...this._mounts.keys()].sort()){let s=e===""?r:`${e}${r}`;n.push(s),n.push(...this._mounts.get(r)._collectSubgraphs(`${s}${I}`))}return n}resourceProfile(e){return kn(this,e)}reachable(e,n,r={}){return r.withDetail===!0?Ft(this.describe(),e,n,{...r,withDetail:!0}):Ft(this.describe(),e,n,r)}explain(e,n,r){return r?.reactive===!0?this._explainReactive(e,n,r):this._explainStatic(e,n,r)}_explainStatic(e,n,r){let s=this.describe({detail:"full"}),o=new Map(this._annotations),i=new Map;for(let[a,u]of Object.entries(s.nodes))u.lastMutation!=null&&i.set(a,u.lastMutation);return un(s,e,n,{...r?.maxDepth!=null?{maxDepth:r.maxDepth}:{},...r?.findCycle===!0?{findCycle:!0}:{},annotations:o,lastMutations:i})}_describeReactive(e){let n={...e,reactive:!1},r=e.reactiveName??"describe",s=0,o=K(s,{name:`${r}_version`}),i=this.observe({timeline:!0,structured:!0}),a=!1,u=!1,d=()=>{a||u||(a=!0,we(()=>{a=!1,!u&&(s+=1,o.emit(s))}))},c=i.onEvent(w=>{let b=w.type;b!=="data"&&b!=="error"&&b!=="complete"&&b!=="teardown"||d()}),h=[],p=new WeakSet,f=w=>{if(p.has(w)||u)return;p.add(w);let b=w.topology.subscribe(_=>{for(let R of _){if(R[0]!==P)continue;let O=R[1];if(d(),O.kind==="added"&&O.nodeKind==="mount"){let g=w._mounts.get(O.name);g!=null&&f(g)}}});h.push(b);for(let _ of w._mounts.keys()){let R=w._mounts.get(_);R!=null&&f(R)}};f(this);let l,y=e.actor;An(y)&&(l=y.subscribe(w=>{let b=!1,_=!1;for(let R of w){let O=R[0];O===P?b=!0:(O===H||O===$||O===z)&&(_=!0)}b&&d(),_&&(l?.(),l=void 0,d())}));let m;try{m=Y([o],()=>this.describe(n),{name:r,describeKind:"derived",meta:{domain:"audit",kind:"describe"},equals:(w,b)=>w===b})}catch(w){c(),l?.();for(let b of h)b();throw i.dispose(),w}let T=re(m);return{node:m,dispose(){u=!0,c(),l?.();for(let w of h)w();h.length=0,i.dispose(),T()}}}_describeReactiveDiff(e){let n={...e,format:void 0,reactive:!1},r=e.reactiveName??"describe-diff",s={name:this.name,nodes:{},edges:[],subgraphs:[]},o=this.describe(n),i=It(s,o),a=K(i,{name:r,meta:{domain:"audit",kind:"describe-diff"},equals:(p,f)=>p===f}),u=this._describeReactive({...e,format:void 0,reactiveName:void 0}),d=!1,c=u.node.subscribe(p=>{if(!d)for(let f of p){if(f[0]!==P)continue;let l=f[1],y=It(o,l);o=l,y.events.length!==0&&a.emit(y)}}),h=re(a);return{node:a,dispose(){d=!0,c(),u.dispose(),a.down([[z,"describe-diff disposed"]]),h()}}}_explainReactive(e,n,r){let s=0,o=K(s,{name:"explain_version"}),i=this.observe({timeline:!0,structured:!0}),a=!1,u=!1,d=i.onEvent(f=>{let l=f.type;l!=="data"&&l!=="error"&&l!=="complete"&&l!=="teardown"||a||u||(a=!0,we(()=>{a=!1,!u&&(s+=1,o.emit(s))}))}),c={...r?.maxDepth!=null?{maxDepth:r.maxDepth}:{},...r?.findCycle===!0?{findCycle:!0}:{}},h;try{h=Y([o],()=>this._explainStatic(e,n,c),{name:r?.name??"explain",describeKind:"derived",meta:{domain:"audit",kind:"explain_path",from:e,to:n},equals:(f,l)=>f.found===l.found&&f.reason===l.reason&&f.steps.length===l.steps.length&&Zr(f.steps,l.steps)})}catch(f){throw d(),i.dispose(),f}let p=re(h);return{node:h,dispose(){u=!0,d(),i.dispose(),p()}}}_pathsMatching(e){let n=at(e),r=[];return this._collectObserveTargets("",r),r.map(([s])=>s).filter(s=>n.test(s))}_collectObserveTargets(e,n){for(let r of[...this._mounts.keys()].sort()){let s=e===""?r:`${e}${I}${r}`;this._mounts.get(r)._collectObserveTargets(s,n)}for(let r of[...this._nodes.keys()].sort()){let s=this._nodes.get(r),o=e===""?r:`${e}${I}${r}`;n.push([o,s]),this._appendMetaObserveTargets(o,s,n)}}_appendMetaObserveTargets(e,n,r){for(let s of Object.keys(n.meta).sort()){let o=n.meta[s],i=`${e}${I}${ee}${I}${s}`;r.push([i,o]),this._appendMetaObserveTargets(i,o,r)}}observe(e,n){let r=typeof e=="string",o=Nn(r?n:e);if(o.reactive===!0)return this._observeReactive(r?e:void 0,o);let 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(r){let c=e,h=this.resolve(c);if(a!=null&&!h.allowsObserve(a))throw new Z({actor:a,action:"observe",nodeName:c});return i?this._buildStructuredObserver([[c,h]],o,"one"):{subscribe(p){return h.subscribe(p)},up(p){try{h.up?.(p)}catch(f){if(f instanceof Z)return;throw f}}}}let u=[];this._collectObserveTargets("",u),u.sort((c,h)=>c[0]<h[0]?-1:c[0]>h[0]?1:0);let d=a==null?u:u.filter(([,c])=>c.allowsObserve(a));return i?this._buildStructuredObserver(d,o,"all"):{subscribe:c=>{let h=d.map(([p,f])=>f.subscribe(l=>{c(p,l)}));return()=>{for(let p of h)p()}},up:(c,h)=>{try{this.resolve(c).up?.(h)}catch(p){if(p instanceof Z)return;throw p}}}}_observeReactive(e,n){let r=n.tiers,s=r!=null?new Set(r):null,o=n.reactiveName??"observe";return Qe(i=>{let a=[],u=!1,d=!1,c=()=>{if(a.length===0||d)return;let y={events:a.slice(),flushedAt_ns:se()};a.length=0,i.emit(y)},h={...n,reactive:!1,structured:!0,timeline:!0},p=e!=null?this.observe(e,h):this.observe(h),f=y=>{d||(a.push(y),!u&&(u=!0,we(()=>{u=!1,c()})))};for(let y of p.events)f(y);let l=p.onEvent(f);return()=>{d=!0,l(),p.dispose()}},{name:o,meta:{domain:"audit",kind:"observe-reactive"}})}_buildStructuredObserver(e,n,r){let s=r==="one"?e[0]?.[0]:void 0,o=i=>{if(r==="one"&&s!=null){let c=this.resolve(s);return this._buildStructuredObserver([[s,c]],i,"one")}let a=[];this._collectObserveTargets("",a),a.sort((c,h)=>c[0]<h[0]?-1:c[0]>h[0]?1:0);let u=i.actor,d=u==null?a:a.filter(([,c])=>c.allowsObserve(u));return this._buildStructuredObserver(d,i,"all")};return this._createObserveResult(e,n,o)}_createObserveResult(e,n,r){let s=n.timeline===!0,o=n.causal===!0,i=n.derived===!0,a=n.detail==="minimal",u=this.config.inspectorEnabled,d=(o||i)&&u,c=n.maxEvents,h=c!=null&&c>0?new $e(c):null,p=[],f=new Set,l=n.tiers!=null?new Set(n.tiers):null,y={},m=new Set,T=0,w=0,b=0,_=0,R=0,O=0,g=!1,v=!1,k=0,E=new Map,x=new Map,N=new Map,S=C=>{if(!(l!=null&&!l.has(C.type))){h?h.push(C):p.push(C);for(let L of f)L(C)}},A=C=>l==null||l.has(C),D=()=>s?{timestamp_ns:se(),in_batch:Be(),batch_id:k}:{},G=(C,L)=>{if(!(!d||!(C instanceof V)))return C._setInspectorHook(J=>{if(J.kind==="dep_message")E.set(C,J.depIndex);else if(J.kind==="run"){let Ne=J.batchData.map((M,B)=>M!=null&&M.length>0?M.at(-1):J.prevData[B]);x.set(C,Ne);let X=J.batchData.map(M=>M!=null?[...M]:void 0);N.set(C,X),i&&S({type:"derived",path:L,dep_values:Ne,dep_batches:X,...D()})}})},j=C=>{let L=E.get(C),J=x.get(C);if(!o||J==null)return{};let X=(L!=null&&L>=0&&C instanceof V?C._deps[L]:void 0)?.node,M=X?.v,B=N.get(C);return{trigger_dep_index:L,trigger_dep_name:X?.name,...M!=null?{trigger_version:{id:M.id,version:M.version}}:{},dep_values:[...J],...B!=null?{dep_batches:B}:{}}},ye=[],be=[];for(let[C,L]of e){let J=G(L,C);J&&ye.push(J),be.push(L.subscribe(Ne=>{k++;for(let X of Ne){let M=X[0],B=D();if(M===P){y[C]=X[1];let mt=L instanceof V?L.lastMutation?.actor??Ee:Ee;S({type:"data",path:C,data:X[1],actor:mt,...B,...j(L)})}else if(a)M===W?A("dirty")&&T++:M===U?A("resolved")&&w++:M===Q?A("invalidate")&&b++:M===te?A("pause")&&_++:M===oe?A("resume")&&R++:M===z?A("teardown")&&O++:M===H&&!m.has(C)?A("complete")&&(g=!0):M===$&&A("error")&&(v=!0,m.add(C));else if(M===W)A("dirty")&&T++,S({type:"dirty",path:C,...B});else if(M===U)A("resolved")&&w++,S({type:"resolved",path:C,...B,...j(L)});else if(M===Q)A("invalidate")&&b++,S({type:"invalidate",path:C,...B});else if(M===te)A("pause")&&_++,S({type:"pause",path:C,lockId:X[1],...B});else if(M===oe)A("resume")&&R++,S({type:"resume",path:C,lockId:X[1],...B});else if(M===H)A("complete")&&!m.has(C)&&(g=!0),S({type:"complete",path:C,...B});else if(M===$){A("error")&&(v=!0,m.add(C));let mt=L instanceof V?L.lastMutation?.actor??Ee:Ee;S({type:"error",path:C,data:X[1],actor:mt,...B})}else M===z&&(A("teardown")&&O++,S({type:"teardown",path:C,...B}))}}))}let Re=!1,Se=()=>{if(!Re){Re=!0;for(let C of be)C();for(let C of ye)C();for(let C of je)C({value:void 0,done:!0});je.length=0}},gt=[],je=[];f.add(C=>{let L=je.shift();L?L({value:C,done:!1}):gt.push(C)});let jt={get values(){return y},get dirtyCount(){return T},get resolvedCount(){return w},get invalidateCount(){return b},get pauseCount(){return _},get resumeCount(){return R},get teardownCount(){return O},get events(){return h?h.toArray():[...p]},get anyCompletedCleanly(){return g},get anyErrored(){return v},get completedWithoutErrors(){return g&&!v},onEvent(C){return f.add(C),()=>f.delete(C)},dispose:Se,expand(C){Se();let L={...n};return typeof C=="string"?L.detail=C:Object.assign(L,C),r(Nn(L))},[Symbol.asyncIterator](){return{next(){return gt.length>0?Promise.resolve({value:gt.shift(),done:!1}):Re?Promise.resolve({value:void 0,done:!0}):new Promise(C=>je.push(C))},return(){return Se(),Promise.resolve({value:void 0,done:!0})}}}};return n.format!=null&&this._attachFormatLogger(jt,n),jt}_attachFormatLogger(e,n){let r=n.format;if(r==null)return;let s=n.logger??(l=>console.log(l)),o=n.includeTypes?new Set(n.includeTypes):null,i=n.excludeTypes?new Set(n.excludeTypes):null,a=o==null&&i==null?()=>!0:l=>(o==null||o.has(l))&&(i==null||!i.has(l)),u=Kr(n.theme),d=r==="stage-log"?se():0,c=l=>l==null?"":n.stageLabels?.[l]??l,h=(l,y)=>l.length>y?`${l.slice(0,y-1)}\u2026`:l,p=l=>l.type==="data"||l.type==="error"?h(dt(l.data),120):"",f=l=>{if(r==="stage-log"){let g=(se()-d)/1e9,v=c(l.path).padEnd(9);if(l.type==="data"){let k=p(l);return`[${g.toFixed(3)}s] ${v} \u2190${k?` ${k}`:""}`}if(l.type==="error"){let k=p(l);return`[${g.toFixed(3)}s] ${v} \u2717${k?` ${k}`:""}`}return l.type==="complete"?`[${g.toFixed(3)}s] ${v} \u25A0 complete`:`[${g.toFixed(3)}s] ${v} ${l.type}`}if(r==="json")try{return JSON.stringify(l)}catch{return JSON.stringify({type:l.type,path:l.path,data:"[unserializable]"})}let y=u[l.type]??"",m=l.path?`${u.path}${l.path}${u.reset} `:"",T=l.type==="data"||l.type==="error",w=l.type==="pause"||l.type==="resume",b=T?` ${dt(l.data)}`:w?` ${dt(l.lockId)}`:"",_=l.type==="data"||l.type==="resolved"||l.type==="derived"?l:void 0,R=_?.trigger_dep_name!=null?` <- ${_.trigger_dep_name}`:_?.trigger_dep_index!=null?` <- #${_.trigger_dep_index}`:"",O=l.in_batch?" [batch]":"";return`${m}${y}${l.type.toUpperCase()}${u.reset}${b}${R}${O}`};e.onEvent(l=>{a(l.type)&&s(f(l),l)})}addDisposer(e){return this._disposers.add(e),()=>{this._disposers.delete(e)}}destroy(){Rn(this._disposers,this.name),this.signal([[z]],{internal:!0}),Rn(this._storageDisposers,this.name);for(let e of[...this._mounts.values()])e._parent=void 0,e._destroyClearOnly();this._mounts.clear(),this._nodes.clear(),this._parent=void 0,this._destroyed=!0}get destroyed(){return this._destroyed}_destroyClearOnly(){for(let e of[...this._mounts.values()])e._parent=void 0,e._destroyClearOnly();this._mounts.clear(),this._nodes.clear(),this._parent=void 0,this._destroyed=!0}snapshot(e){let{expand:n,...r}=this.describe({detail:"full"}),s={};for(let a of Object.keys(r.nodes).sort()){let{lastMutation:u,guard:d,...c}=r.nodes[a];s[a]=c}let o=[...r.subgraphs].sort(),i={...r,version:1,nodes:s,subgraphs:o};if(e?.format==null)return i;if(e.format==="json-string")return JSON.stringify(i);if(e.format==="bytes"){if(e.codec==null)throw new Error("snapshot({format: 'bytes'}) requires a `codec` name");let a=this.config.lookupCodec(e.codec);if(a==null)throw new Error(`snapshot: codec "${e.codec}" is not registered on this graph's config. Call config.registerCodec(...) before creating nodes.`);return Xt(a,a.encode(i))}throw new Error(`snapshot: unknown format "${String(e.format)}"`)}static decode(e,n){let r=n?.config??he,{codec:s,codecVersion:o,payload:i}=Zt(e,r);return s.decode(i,o)}restore(e,n){if(Sn(e),e.name!==this.name)throw new Error(`Graph "${this.name}": restore snapshot name "${e.name}" does not match this graph`);let r=n?.only==null?null:(Array.isArray(n.only)?n.only:[n.only]).map(o=>at(o)),s=n?.includeProducers===!0;for(let o of Object.keys(e.nodes).sort()){if(r!==null&&!r.some(a=>a.test(o)))continue;let i=e.nodes[o];if(i!==void 0){if(!("value"in i)||i.value===void 0){"value"in i&&i.value===void 0&&n?.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 u=this.tryResolve(o)?.v;if(u!=null&&u.id===i.v.id&&u.version===i.v.version)continue}try{this.set(o,i.value)}catch(a){n?.onError?.(o,a)}}}}}static fromSnapshot(e,n){Sn(e);let r=typeof n=="function"?n:n?.build,s=typeof n=="function"?void 0:n?.factories,o=new t(e.name);if(r)return r(o),o.restore(e),o;for(let f of[...e.subgraphs].sort((l,y)=>{let m=l.split(I).length,T=y.split(I).length;return m!==T?m-T:l<y?-1:l>y?1:0})){let l=f.split(I),y=o;for(let m of l)y._mounts.has(m)||y.mount(m,new t(m)),y=y._mounts.get(m)}let i=s?Object.entries(s).map(([f,l])=>({re:at(f),factory:l})):[],a=f=>{for(let l of i)if(l.re.test(f))return l.factory},u=f=>{let l=f.split(I),y=l.pop();if(y==null||y.length===0)throw new Error(`invalid snapshot path "${f}"`);let m=o;for(let T of l){let w=m._mounts.get(T);if(!w)throw new Error(`unknown mount "${T}" in path "${f}"`);m=w}return[m,y]},d=Object.entries(e.nodes).filter(([f])=>!f.includes(`${I}${ee}${I}`)).sort((f,l)=>f[0]<l[0]?-1:f[0]>l[0]?1:0),c=new Map(d),h=new Map,p=!0;for(;c.size>0&&p;){p=!1;for(let[f,l]of[...c.entries()]){let y=l?.deps??[];if(!y.every(R=>h.has(R)))continue;let[m,T]=u(f),w={...l?.meta??{}},b=a(f),_;if(l?.type==="state")_=K(l.value,{meta:w});else{if(b==null)continue;_=b(T,{path:f,type:l.type,value:l.value,meta:w,deps:y,resolvedDeps:y.map(R=>h.get(R))})}m.add(_,{name:T}),h.set(f,_),c.delete(f),p=!0}}if(c.size>0){let f=[...c.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(e),o}toJSON(){return this.snapshot()}attachSnapshotStorage(e,n={}){let r=e.map(d=>({tier:d,debounceMs:Math.max(0,d.debounceMs??0),compactEvery:Math.max(1,d.compactEvery??10),timer:void 0,seq:0,lastSnapshot:void 0,lastFingerprint:"",disposed:!1,savePending:void 0}));n.autoRestore===!0&&this._cascadeRestore(e,n.onError);let s=(d,c)=>{if(d.disposed)return;let h=Ir(c.nodes);if(d.lastSnapshot!=null&&h!==""&&h===d.lastFingerprint)return;let p=d.seq+1,f=ne(),m=d.lastSnapshot==null||p%d.compactEvery===0?{name:this.name,mode:"full",snapshot:c,seq:p,timestamp_ns:f,format_version:me}:{name:this.name,mode:"diff",diff:In(d.lastSnapshot,c),seq:p,timestamp_ns:f,format_version:me};if(d.tier.filter&&!d.tier.filter(m))return;let T;try{T=d.tier.save(m)}catch(w){n.onError?.(w,d.tier);return}if(T&&typeof T.then=="function"){let _=(d.savePending??Promise.resolve()).then(()=>T,()=>T).then(()=>{d.disposed||(d.seq=p,d.lastSnapshot=c,d.lastFingerprint=h)},R=>{n.onError?.(R,d.tier)});d.savePending=_.finally(()=>{d.savePending===_&&(d.savePending=void 0)})}else d.seq=p,d.lastSnapshot=c,d.lastFingerprint=h},o=(d,c)=>{try{s(d,c)}catch(h){n.onError?.(h,d.tier)}},i=(d,c)=>{if(!c.some(l=>{let y=this.config.messageTier(l[0]);return y>=3&&y<5}))return;if(n.filter){let l=this.tryResolve(d);if(l==null)return;let y=Ct(l,Ge("standard"));if(!n.filter(d,y))return}let p,f=()=>(p==null&&(p=this.snapshot()),p);for(let l of r)l.disposed||(l.debounceMs===0?o(l,f()):(l.timer==null&&(l.timer=new rt),l.timer.start(l.debounceMs,()=>{l.disposed||o(l,this.snapshot())})))},a;if(n.paths!=null){let c=(typeof n.paths=="string"?this._pathsMatching(n.paths):n.paths).map(h=>{let p=this.tryResolve(h);return p==null?()=>{}:p.subscribe(f=>i(h,f))});a=()=>{for(let h of c)h()}}else a=this.observe().subscribe((d,c)=>i(d,c));let u=()=>{a();for(let d of r)d.disposed=!0,d.timer?.cancel();this._storageDisposers.delete(u)};return this._storageDisposers.add(u),{dispose:u}}async _cascadeRestore(e,n){for(let r of e){let s;try{s=await r.load?.()}catch(i){n?.(i,r);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===me&&o.nodes!=null)return this.restore(o),!0}catch(i){n?.(i,r)}}return!1}static async fromStorage(e,n,r){for(let s of n){let o;try{o=await s.load?.()}catch(u){r?.onError?.(u,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===me&&i.nodes!=null?i:void 0;if(a!=null)try{return t.fromSnapshot(a,r)}catch(u){r?.onError?.(u,s)}}throw new Error(`Graph.fromStorage: no tier held a restorable record for "${e}" across ${n.length} tier(s)`)}_annotations=new Map;_traceRing;trace(e,n,r){if(e!=null&&n!=null){if(this.tryResolve(e)==null)return;if(this._annotations.set(e,n),this.config.inspectorEnabled){let s={path:e,annotation:n,timestamp_ns:se(),...r?.actor!=null?{actor:r.actor}:{}};this._traceRing.push(s)}return}return e!=null?this.config.inspectorEnabled?this._annotations.get(e):void 0:this.config.inspectorEnabled?this._traceRing.toArray():[]}annotation(e){return this._annotations.get(e)}clearTrace(){this._annotations.clear(),this._traceRing.clear()}pruneTrace(e){let n=this._traceRing.toArray().filter(s=>!e(s)),r=this._traceRing.size-n.length;this._traceRing.clear();for(let s of n)this._traceRing.push(s);return r}static diff(e,n){let r=new Set(Object.keys(e.nodes)),s=new Set(Object.keys(n.nodes)),o=[...s].filter(w=>!r.has(w)).sort(),i=[...r].filter(w=>!s.has(w)).sort(),a=[],u=[];for(let w of r){if(!s.has(w))continue;let b=e.nodes[w],_=n.nodes[w],R=b.v,O=_.v;R!=null&&O!=null&&R.id===O.id&&R.version!==O.version&&u.push({path:w,id:R.id,from:R.version,to:O.version});let g=R!=null&&O!=null&&R.id===O.id&&R.version===O.version;for(let v of["type","status","sentinel"]){let k=b[v],E=_[v];k!==E&&a.push({path:w,field:v,from:k,to:E})}if(!g)for(let v of["value","meta"]){let k=b[v],E=_[v];Pr(k,E)||a.push({path:w,field:v,from:k,to:E})}}let d=w=>`${w.from} ${w.to}`,c=new Set(e.edges.map(d)),h=new Set(n.edges.map(d)),p=n.edges.filter(w=>!c.has(d(w))),f=e.edges.filter(w=>!h.has(d(w))),l=new Set(e.subgraphs),y=new Set(n.subgraphs),m=[...y].filter(w=>!l.has(w)).sort(),T=[...l].filter(w=>!y.has(w)).sort();return{nodesAdded:o,nodesRemoved:i,nodesChanged:a,versionChanges:u,edgesAdded:p,edgesRemoved:f,subgraphsAdded:m,subgraphsRemoved:T}}};function In(t,e){let n=de.diff(t,e),r={};for(let s of n.nodesAdded){let o=e.nodes[s];o!=null&&(r[s]=o)}return{...n,nodesAddedFull:r}}function Ft(t,e,n,r={}){let s={paths:[],depths:new Map,truncated:!1};if(!e)return r.withDetail?s:[];if(!r.both&&n!=="upstream"&&n!=="downstream")throw new Error('reachable: direction must be "upstream" or "downstream"');let o=r.maxDepth;if(o!=null&&(!Number.isInteger(o)||o<0))throw new Error("reachable: maxDepth must be an integer >= 0");if(o===0)return r.withDetail?s:[];let i=new Map,a=new Map,u=new Map,d=new Map,c=new Set;for(let[b,_]of Object.entries(t.nodes)){if(!b)continue;c.add(b);let R=_.deps??[];i.set(b,R);for(let O of R)O&&(c.add(O),a.has(O)||a.set(O,new Set),a.get(O).add(b))}for(let b of t.edges){if(b==null||typeof b!="object")continue;let _=typeof b.from=="string"?b.from:"",R=typeof b.to=="string"?b.to:"";!_||!R||(c.add(_),c.add(R),d.has(_)||d.set(_,new Set),d.get(_).add(R),u.has(R)||u.set(R,new Set),u.get(R).add(_))}if(!c.has(e))return r.withDetail?s:[];let h=r.both===!0,p=b=>{if(h){let g=i.get(b)??[],v=u.get(b),k=a.get(b),E=d.get(b),x=[...g];return v&&x.push(...v),k&&x.push(...k),E&&x.push(...E),x}if(n==="upstream"){let g=i.get(b)??[],v=u.get(b);return v?[...g,...v]:g}let _=a.get(b),R=d.get(b),O=_?[..._]:[];return R&&O.push(...R),O},f=new Set([e]),l=new Map,y=[{path:e,depth:0}],m=0,T=!1;for(;m<y.length;){let b=y[m++];if(o!=null&&b.depth>=o){p(b.path).length>0&&(T=!0);continue}for(let _ of p(b.path))!_||f.has(_)||(f.add(_),l.set(_,b.depth+1),y.push({path:_,depth:b.depth+1}))}let w=[...l.keys()].sort((b,_)=>b<_?-1:b>_?1:0);return r.withDetail?{paths:w,depths:l,truncated:T}:w}function Zr(t,e){if(t.length!==e.length)return!1;for(let n=0;n<t.length;n++){let r=t[n],s=e[n];if(r.path!==s.path||r.type!==s.type||r.status!==s.status||r.hop!==s.hop||r.dep_index!==s.dep_index||r.annotation!==s.annotation||r.value!==s.value||r.lastMutation!==s.lastMutation)return!1;let o=r.v,i=s.v;if(o!==i&&(o==null||i==null||o.id!==i.id||o.version!==i.version))return!1}return!0}var ue=class extends Error{constructor(e,n){super(e,n),this.name=this.constructor.name}},ut=class extends ue{constructor(n,r){super(`Duplicate ${n} registration: "${r}"`);this.kind=n;this.registrationName=r}},ct=class extends ue{constructor(n,r,s){super(`Command "${n}" emitted undeclared event "${r}". Declared emits: [${s.join(", ")}]`);this.commandName=n;this.eventName=r;this.declaredEmits=s}},lt=class extends ue{constructor(n,r,s){super(`Optimistic concurrency conflict on aggregate "${n}": expected version ${r}, got ${s}`);this.aggregateId=n;this.expected=r;this.actual=s}},ft=class extends ue{constructor(n){super(`Unknown command: "${n}". Register with command() first.`);this.commandName=n}},Ve=class extends ue{constructor(n,r){super(`Command handler "${n}" threw: ${r instanceof Error?r.message:String(r)}`,{cause:r});this.commandName=n}};var Fe=class extends ue{constructor(n,r){super(`Projection "${n}" rebuild failed: ${r instanceof Error?r.message:String(r)}`,{cause:r});this.projectionName=n}};fe();Le();var Qr=Te((t,e)=>{t("observe"),t("signal"),e("write")});function pt(t){let e=Pe([],{name:t.name,maxSize:t.retainedLimit??1024,guard:t.guard??Qr,...t.versioning!=null?{versioning:t.versioning}:{}});return e.withLatest(),t.graph&&t.graph.add(e.entries,{name:t.name}),e}function Pn(t,e,n=0){let r=K(n,{name:e,describeKind:"state"});return t.add(r,{name:e}),r}function $n(t,e,n,r=0){let s={},o=new de(e);for(let i of n){let a=K(r,{name:i,describeKind:"state"});o.add(a,{name:i}),s[i]=a}return t.mount(e,o),s}Mt();function Vn(t,e,n){return{[t]:!0,[`${t}_type`]:e,...n??{}}}var es=Te((t,e)=>{t("write"),t("signal"),e("observe")}),ts=Te((t,e)=>{t("observe"),t("signal"),e("write")}),Fn=Te((t,e)=>{t("observe"),t("signal"),e("write")});function ze(t,e){return Vn("cqrs",t,e)}function zt(t){if(t===null||typeof t!="object"||Object.isFrozen(t))return t;for(let e of Object.keys(t))zt(t[e]);return Object.freeze(t)}var ns=t=>`${t.type}::${t.aggregateId??"__default__"}`,rs=t=>t.commandName,ss=t=>t.eventType,ht=class extends de{_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=pt({name:"dispatches",retainedLimit:this._retainedLimit,graph:this}),this.audit=this.dispatches,this.aggregateEvictions=pt({name:"aggregateEvictions",retainedLimit:this._retainedLimit,graph:this}),this._dispatchSeqCursor=Pn(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 r=n.indexOf("::");if(r<0)continue;let s=n.slice(0,r),o=n.slice(r+2),i=this._aggregateVersions.get(n)??0;this._aggregateVersions.delete(n);let a=this._eventLogsByAggregate.get(s);a&&(a.delete(o),a.size===0&&this._eventLogsByAggregate.delete(s)),this.aggregateEvictions.append({aggregateId:o,type:s,lastVersion:i,t_ns:ne()})}}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,r]of this._eventLogs){let s=r.log.attachStorage(e),o=this._attachedTierDisposers.get(n);o||(o=[],this._attachedTierDisposers.set(n,o)),o.push(s)}for(let[n,r]of this._eventLogsByAggregate)for(let[s,o]of r){let i=`${n}::${s}`,a=o.log.attachStorage(e),u=this._attachedTierDisposers.get(i);u||(u=[],this._attachedTierDisposers.set(i,u)),u.push(a)}return()=>{let n=this._attachedEventTiers.indexOf(e);n>=0&&this._attachedEventTiers.splice(n,1)}}_autoWireStreamStorage(e,n){if(this._attachedEventTiers.length===0)return;let r=this._attachedTierDisposers.get(e);r||(r=[],this._attachedTierDisposers.set(e,r));for(let s of this._attachedEventTiers)r.push(n.attachStorage(s))}_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 r=this._eventLogs.get(e);if(r)return r.node;let s=Pe([],{name:e,versioning:0,maxSize:this._retainedLimit});s.withLatest();let o=s.entries,i=Y([o],([a])=>a,{name:e,describeKind:"state",meta:ze("event",{event_name:e}),guard:Fn,initial:o.cache});return this.add(i,{name:e}),this._keepaliveDisposers.push(re(i)),this._eventLogs.set(e,{log:s,node:i}),this._autoWireStreamStorage(e,s),i}_ensureAggregateStream(e,n){this._eventLogs.has(e)||this.event(e);let r=this._eventLogsByAggregate.get(e);r||(r=new Map,this._eventLogsByAggregate.set(e,r));let s=`${e}::${n}`;this._touchAggregate(s);let o=r.get(n);if(o)return o;let i=`${e}_${n.replace(/[^a-zA-Z0-9_-]/g,"_")}`,a=Pe([],{name:i,versioning:0,maxSize:this._retainedLimit});a.withLatest();let u=a.entries,d=Y([u],([f])=>f,{name:i,describeKind:"state",meta:ze("event_aggregate",{event_name:e,aggregate_id:n}),guard:Fn,initial:u.cache}),c=i,h=0;for(;this.nameOf(this.resolveOptional(c)??d)===c&&(h+=1,c=`${i}_${h}`,this.resolveOptional(c)!==void 0););try{this.add(d,{name:c})}catch{}this._keepaliveDisposers.push(re(d));let p={log:a,node:d};return r.set(n,p),this._autoWireStreamStorage(`${e}::${n}`,a),this._enforceAggregateLru(),p}resolveOptional(e){try{return this.resolve(e)}catch{return}}_appendEvent(e,n,r){let s=this._eventLogs.get(e);if(s||(this.event(e),s=this._eventLogs.get(e)),s.node.status==="completed"||s.node.status==="errored")throw new Error(`Cannot dispatch to terminated event stream "${e}" (status: ${s.node.status}).`);let o,i;if(r?.aggregateId!==void 0){let c=`${e}::${r.aggregateId}`;o=(this._aggregateVersions.get(c)??0)+1,this._aggregateVersions.set(c,o),i=this._ensureAggregateStream(e,r.aggregateId)}let a=s.log.entries.v,u=this._freezeEventPayload?zt(n):n,d={type:e,payload:u,timestampNs:ne(),seq:++this._seq,...r?.aggregateId!==void 0?{aggregateId:r.aggregateId}:{},...o!==void 0?{aggregateVersion:o}:{},...r?.correlationId!==void 0?{correlationId:r.correlationId}:{},...r?.causationId!==void 0?{causationId:r.causationId}:{},...r?.metadata!==void 0?{metadata:Object.freeze({...r.metadata})}:{},...r?.handlerVersion!==void 0?{handlerVersion:r.handlerVersion}:{},...a!=null?{v0:{id:a.id,version:a.version}}:{}};return s.log.append(d),i&&i.log.append(d),d}command(e,n){if(this._commandRegs.has(e))throw new ut("command",e);let r=typeof n=="function"?{handler:n}:n,s=K(void 0,{name:e,describeKind:"state",meta:{...ze("command",{command_name:e}),error:null},guard:es});if(this.add(s,{name:e}),this._commandRegs.set(e,{handler:r.handler,...r.emits!==void 0?{emits:r.emits}:{},...r.handlerVersion!==void 0?{handlerVersion:r.handlerVersion}:{}}),r.emits)for(let o of r.emits)this._eventLogs.has(o)||this.event(o);return s}dispatch(e,n,r){let s=this._commandRegs.get(e);if(!s)throw new ft(e);if(r?.aggregateId!==void 0&&r.expectedAggregateVersion!==void 0&&s.emits!==void 0){let p=0;for(let f of s.emits){let l=this._aggregateVersions.get(`${f}::${r.aggregateId}`);l!==void 0&&l>p&&(p=l)}if(p!==r.expectedAggregateVersion)throw new lt(r.aggregateId,r.expectedAggregateVersion,p)}let o=this.resolve(e),i=this._freezeCommandPayload?zt(n):n,a=[],u=ne(),d=0,c,h=!1;try{xe(()=>{d=this._bumpDispatchSeq(),o.emit(i,{internal:!0});try{s.handler(i,{emit:(p,f)=>{if(s.emits!==void 0&&!s.emits.includes(p))throw new ct(e,p,s.emits);a.push(p),this._appendEvent(p,f,{...r?.aggregateId!==void 0?{aggregateId:r.aggregateId}:{},...r?.correlationId!==void 0?{correlationId:r.correlationId}:{},...r?.causationId!==void 0?{causationId:r.causationId}:{},...r?.metadata!==void 0?{metadata:Object.freeze({...r.metadata})}:{},...s.handlerVersion!==void 0?{handlerVersion:s.handlerVersion}:{}})}}),o.meta.error.emit(null,{internal:!0}),this.dispatches.append({commandName:e,payload:i,status:"success",emittedEvents:[...a],t_ns:u,seq:d,...s.handlerVersion!==void 0?{handlerVersion:s.handlerVersion}:{}})}catch(p){throw c=p,h=!0,p}})}catch(p){if(h){o.meta.error.emit(c,{internal:!0});let f=c instanceof Error?c.name:typeof c,l=c instanceof Ve?c:new Ve(e,c);this.dispatches.append({commandName:e,payload:i,status:"failed",error:l,errorType:f,emittedEvents:[...a],t_ns:u,seq:d,...s.handlerVersion!==void 0?{handlerVersion:s.handlerVersion}:{}})}throw h?c:p}}projection(e){let{name:n,events:r,reducer:s,initial:o}=e,i=e.mode??"scan",a=e.freezeInputs??!0,u=e.snapshot,d=r.map(E=>(this._eventLogs.has(E)||this.event(E),this._eventLogs.get(E).node));function c(E){E.sort((x,N)=>x.timestampNs-N.timestampNs||x.seq-N.seq||(x.aggregateId??"").localeCompare(N.aggregateId??""))}function h(E){let x=[];for(let N of E)x.push(...N);return c(x),x}let p=d.map(E=>E.cache??[]),f=h(p),l=a?Object.freeze(f):f,y=0,m=o;i==="scan"&&f.length>0&&(m=s(o,l),y=f.length);let T=i==="replay"?s(o,l):m,w=u?.saveDebounceMs??1e3,b=u?.saveEvery??1e3,_,R=0;function O(E){if(u?.save){if(R+=1,R>=b){R=0,_!==void 0&&(clearTimeout(_),_=void 0);let x=u.save(E);x instanceof Promise&&x.catch(()=>{});return}_!==void 0&&clearTimeout(_),_=setTimeout(()=>{_=void 0,R=0;let x=u.save(E);x instanceof Promise&&x.catch(()=>{})},w)}}let g=Y(d,E=>{let x=h(E),N;if(i==="replay"){let S=a?Object.freeze(x):x;N=s(o,S)}else{let S=x.slice(y);y=x.length;let A=a?Object.freeze(S):S;N=s(m,A),m=N}return O(N),N},{name:n,describeKind:"derived",meta:ze("projection",{projection_name:n,source_events:r}),guard:ts,initial:T});return this.add(g,{name:n}),this._keepaliveDisposers.push(re(g)),this._keepaliveDisposers.push(()=>{_!==void 0&&(clearTimeout(_),_=void 0)}),this._projections.add(n),{node:g,rebuild:async E=>{try{let x=E?.pageSize??1e3,N=E?.fromTier??this._attachedEventTiers[0]?.[0],S=h(d.map(D=>D.cache??[])).length,A=o;if(u?.load){let D=await u.load();D!==void 0&&(A=D)}if(!N||!N.loadEntries){let D=h(d.map(j=>j.cache??[])),G=a?Object.freeze(D):D;A=s(A,G)}else{let D=new Set(r),G,j=!1;for(;!j;){let ye=await N.loadEntries({cursor:G,pageSize:x}),be=[...ye.entries].filter(Se=>D.has(Se.type));c(be);let Re=a?Object.freeze(be):be;A=s(A,Re),G=ye.cursor,j=!G||ye.entries.length===0}}if(i==="scan"){let D=h(d.map(j=>j.cache??[])),G=D.slice(S);if(G.length>0){let j=a?Object.freeze(G):G;A=s(A,j)}m=A,y=D.length}return g.emit(A,{internal:!0}),A}catch(x){throw new Fe(n,x)}},reset:async()=>{try{let E=o;if(u?.load){let A=await u.load();A!==void 0&&(E=A)}let x=h(d.map(A=>A.cache??[])),N=a?Object.freeze(x):x,S=s(E,N);return i==="scan"&&(m=S,y=x.length),g.emit(S,{internal:!0}),S}catch(E){throw new Fe(n,E)}}}}saga(e,n,r,s={}){let o=n.map(f=>(this._eventLogs.has(f)||this.event(f),this._eventLogs.get(f).node)),i=$n(this,`${e}_cursor`,n,0),a=pt({name:`${e}_invocations`,retainedLimit:this._retainedLimit,graph:this}),u=s.aggregateId,d=s.errorPolicy??"advance",c=new Map;for(let f of n){let l=i[f];c.set(f,l.cache??0);let y=l.subscribe(m=>{for(let T of m)T[0]===P&&c.set(f,T[1])});this._keepaliveDisposers.push(y)}let h={},p=ie(o,(f,l)=>{let y=h.n.meta.error;for(let m=0;m<f.length;m++){let T=f[m];if(T==null||T.length===0)continue;let w=T.at(-1);if(!w)continue;let b=n[m],_=i[b],R=c.get(b)??0;if(w.length>R){let O=w.slice(R),g=R;for(let v of O){let k=v;if(u!==void 0&&k.aggregateId!==u){g+=1;continue}try{r(k),y.emit(null,{internal:!0}),a.append({eventType:b,status:"success",aggregateId:k.aggregateId,event:k,t_ns:ne(),...s.handlerVersion!==void 0?{handlerVersion:s.handlerVersion}:{}}),g+=1}catch(E){if(y.emit(E,{internal:!0}),a.append({eventType:b,status:"failed",error:E,errorType:E instanceof Error?E.name:typeof E,aggregateId:k.aggregateId,event:k,t_ns:ne(),...s.handlerVersion!==void 0?{handlerVersion:s.handlerVersion}:{}}),d==="hold")break;g+=1}}_.emit(g)}}},{name:e,describeKind:"effect",meta:{...ze("saga",{saga_name:e,source_events:n}),error:null}});return h.n=p,this.add(p,{name:e}),this._keepaliveDisposers.push(re(p)),this._sagas.add(e),{node:p,invocations:a,audit:a,cursors:i}}};function os(t,e){let n=new ht(t,e),{factory:r,factoryArgs:s,...o}=e??{};return n.tagFactory("cqrs",At(o)),n}0&&(module.exports={CqrsGraph,cqrs,cqrsEventKeyOf,dispatchKeyOf,sagaInvocationKeyOf});
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import '../../node-fSc-hCv8.cjs';
|
|
2
|
-
import '../../reactive-log-
|
|
2
|
+
import '../../reactive-log-C3IMAGpT.cjs';
|
|
3
3
|
import '../../extra/storage-tiers.cjs';
|
|
4
|
-
import '../../graph-
|
|
4
|
+
import '../../graph-CHsVwf9S.cjs';
|
|
5
5
|
import '../../imperative-audit-ahAE65a9.cjs';
|
|
6
|
-
export { A as AggregateEvictionRecord, d as CommandActions, e as CommandHandler, f as CommandRegistration, a as CqrsEvent, C as CqrsEventMap, b as CqrsGraph, c as CqrsOptions, D as DispatchOptions, g as DispatchRecord, P as ProjectionController, h as ProjectionOptions, j as ProjectionReducer, k as ProjectionSnapshotOpts, S as SagaController, l as SagaHandler, m as SagaInvocation, n as SagaOptions, o as cqrs, p as cqrsEventKeyOf, q as dispatchKeyOf, s as sagaInvocationKeyOf } from '../../index-
|
|
7
|
-
import '../../meta-
|
|
6
|
+
export { A as AggregateEvictionRecord, d as CommandActions, e as CommandHandler, f as CommandRegistration, a as CqrsEvent, C as CqrsEventMap, b as CqrsGraph, c as CqrsOptions, D as DispatchOptions, g as DispatchRecord, P as ProjectionController, h as ProjectionOptions, j as ProjectionReducer, k as ProjectionSnapshotOpts, S as SagaController, l as SagaHandler, m as SagaInvocation, n as SagaOptions, o as cqrs, p as cqrsEventKeyOf, q as dispatchKeyOf, s as sagaInvocationKeyOf } from '../../index-BqcgiSQg.cjs';
|
|
7
|
+
import '../../meta-DreaEM_a.cjs';
|
|
8
8
|
import '../../extra/storage-core.cjs';
|