@graphrefly/graphrefly 0.37.0 → 0.39.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/budget-gate-CmmVtasH.d.ts +115 -0
- package/dist/budget-gate-DiP_nK0n.d.cts +115 -0
- package/dist/{cascading-BsJ4GbnS.d.ts → cascading-BzuxW0_w.d.cts} +2 -2
- package/dist/{cascading-B25wxpRa.d.cts → cascading-g2_rhhaM.d.ts} +2 -2
- package/dist/chunk-35JTVPOX.js +1 -0
- package/dist/chunk-3G5U5QNE.js +5 -0
- package/dist/chunk-4I45FVQS.js +1 -0
- package/dist/chunk-5LK7XMEV.js +1 -0
- package/dist/chunk-5XRI6RM3.js +1 -0
- package/dist/chunk-73PBQNST.js +1 -0
- package/dist/chunk-7JRF5YEK.js +3 -0
- package/dist/{chunk-YVYSO5CW.js → chunk-7NZMZJMW.js} +1 -1
- package/dist/chunk-7QFRK3N3.js +84 -0
- package/dist/{chunk-K6ZFJ473.js → chunk-7SD73DS6.js} +1 -1
- package/dist/{chunk-LOQRPP4Y.js → chunk-A6ZSKGUG.js} +1 -1
- package/dist/{chunk-KUVDFOJH.js → chunk-AU7YTQX7.js} +1 -1
- package/dist/chunk-C72GO4IZ.js +1 -0
- package/dist/{chunk-Q7EUZ6NN.js → chunk-CGDMTXSY.js} +1 -1
- package/dist/chunk-D27JNOLZ.js +1 -0
- package/dist/chunk-D47YVDR5.js +1 -0
- package/dist/chunk-EWF7KCDJ.js +61 -0
- package/dist/{chunk-PCD2MU7X.js → chunk-GEAO3TL3.js} +1 -1
- package/dist/chunk-GX5LSSRE.js +1 -0
- package/dist/{chunk-2C4NESZE.js → chunk-HAWKGIXM.js} +1 -1
- package/dist/chunk-HX3EGQ5Z.js +1 -0
- package/dist/{chunk-MQZWA3DF.js → chunk-IA7DUNGB.js} +1 -1
- package/dist/{chunk-MYFR67PY.js → chunk-INH6FS2G.js} +2 -2
- package/dist/chunk-INHC33EH.js +1 -0
- package/dist/chunk-IUB4NYI2.js +1 -0
- package/dist/{chunk-TFK4P4CX.js → chunk-JNMC2WJ6.js} +1 -1
- package/dist/{chunk-TLS7M7H4.js → chunk-KD4NHLMU.js} +1 -1
- package/dist/chunk-L6NSJVJZ.js +1 -0
- package/dist/chunk-L7WY6TZS.js +1 -0
- package/dist/chunk-LQNOXGET.js +1 -0
- package/dist/chunk-MC4UYY2X.js +1 -0
- package/dist/{chunk-U3COB5WU.js → chunk-N7UIBZCW.js} +1 -1
- package/dist/chunk-NQI2C36M.js +1 -0
- package/dist/chunk-R75BMDLA.js +1 -0
- package/dist/chunk-RF3QZP6D.js +1 -0
- package/dist/{chunk-MC5LZG3U.js → chunk-S2U57TFC.js} +1 -1
- package/dist/{chunk-QP5TH523.js → chunk-SC7BQDNP.js} +1 -1
- package/dist/{chunk-5CPPC75H.js → chunk-TFPZLQ5H.js} +1 -1
- package/dist/chunk-VJJLIEAL.js +1 -0
- package/dist/chunk-WHIZM6JV.js +1 -0
- package/dist/chunk-XEUANKBO.js +43 -0
- package/dist/chunk-XQ55HO5N.js +1 -0
- package/dist/chunk-ZJ7SM3G2.js +1 -0
- package/dist/{chunk-T4U24DXX.js → chunk-ZOX3LBRV.js} +1 -1
- package/dist/compat/index.cjs +9 -13
- package/dist/compat/index.d.cts +16 -16
- package/dist/compat/index.d.ts +16 -16
- package/dist/compat/index.js +1 -1
- package/dist/compat/jotai/index.d.cts +2 -2
- package/dist/compat/jotai/index.d.ts +2 -2
- package/dist/compat/nanostores/index.d.cts +2 -2
- package/dist/compat/nanostores/index.d.ts +2 -2
- package/dist/compat/nestjs/index.cjs +8 -12
- package/dist/compat/nestjs/index.d.cts +8 -8
- package/dist/compat/nestjs/index.d.ts +8 -8
- package/dist/compat/nestjs/index.js +1 -1
- package/dist/compat/react/index.d.cts +2 -2
- package/dist/compat/react/index.d.ts +2 -2
- package/dist/compat/solid/index.d.cts +2 -2
- package/dist/compat/solid/index.d.ts +2 -2
- package/dist/compat/svelte/index.d.cts +2 -2
- package/dist/compat/svelte/index.d.ts +2 -2
- package/dist/compat/vue/index.d.cts +2 -2
- package/dist/compat/vue/index.d.ts +2 -2
- package/dist/compat/zustand/index.cjs +3 -7
- package/dist/compat/zustand/index.d.cts +4 -4
- package/dist/compat/zustand/index.d.ts +4 -4
- package/dist/compat/zustand/index.js +1 -1
- package/dist/{composite-_XckYx2e.d.cts → composite-CKd0e2vz.d.cts} +10 -3
- package/dist/{composite-CT_mApQD.d.ts → composite-DGatA-JK.d.ts} +10 -3
- package/dist/core/index.cjs +1 -1
- package/dist/core/index.d.cts +4 -4
- package/dist/core/index.d.ts +4 -4
- package/dist/core/index.js +1 -1
- package/dist/extra/browser.d.cts +1 -1
- package/dist/extra/browser.d.ts +1 -1
- package/dist/extra/index.cjs +17 -21
- package/dist/extra/index.d.cts +11 -9
- package/dist/extra/index.d.ts +11 -9
- package/dist/extra/index.js +1 -1
- package/dist/extra/node.cjs +2 -2
- package/dist/extra/node.d.cts +108 -2
- package/dist/extra/node.d.ts +108 -2
- package/dist/extra/node.js +2 -2
- package/dist/extra/operators.cjs +1 -1
- package/dist/extra/operators.d.cts +1 -1
- package/dist/extra/operators.d.ts +1 -1
- package/dist/extra/operators.js +1 -1
- package/dist/extra/reactive.cjs +1 -1
- package/dist/extra/reactive.d.cts +3 -3
- package/dist/extra/reactive.d.ts +3 -3
- package/dist/extra/reactive.js +1 -1
- package/dist/extra/render/index.cjs +5 -0
- package/dist/extra/render/index.d.cts +183 -0
- package/dist/extra/render/index.d.ts +183 -0
- package/dist/extra/render/index.js +1 -0
- package/dist/extra/sources.cjs +1 -1
- package/dist/extra/sources.d.cts +1 -1
- package/dist/extra/sources.d.ts +1 -1
- package/dist/extra/sources.js +1 -1
- package/dist/extra/storage-browser.d.cts +1 -1
- package/dist/extra/storage-browser.d.ts +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/{fallback-axI2cXwt.d.cts → fallback-8JYU8tlT.d.cts} +1 -1
- package/dist/{fallback-DuEXfA4F.d.ts → fallback-CMZl39L5.d.ts} +1 -1
- package/dist/graph/index.cjs +7 -7
- package/dist/graph/index.d.cts +5 -5
- package/dist/graph/index.d.ts +5 -5
- package/dist/graph/index.js +1 -1
- package/dist/{graph-YQXDndFy.d.ts → graph-30XSgtVX.d.ts} +287 -104
- package/dist/{graph-CaNXUc3c.d.cts → graph-BUwMAxJI.d.cts} +287 -104
- package/dist/{index-CIcu6fIR.d.ts → index-2n8Eai6M.d.ts} +1 -1
- package/dist/{index-BmLkcDlj.d.ts → index-89FczVZ_.d.ts} +47 -71
- package/dist/{index-Ci358GSC.d.cts → index-8R1vzNOx.d.cts} +9 -9
- package/dist/{index-CDvC1m5p.d.ts → index-B2RUoIUz.d.ts} +1 -1
- package/dist/{index-DuhOdNyg.d.ts → index-B41Asm7D.d.ts} +10 -8
- package/dist/{index-CKcnuQ2c.d.ts → index-B9fmw5n2.d.ts} +4 -6
- package/dist/{index-0qOD-421.d.ts → index-BAlaVimV.d.ts} +9 -9
- package/dist/{index-Ae6L8liv.d.ts → index-BC9VybQs.d.ts} +41 -48
- package/dist/{index-CUTHDZ7Q.d.ts → index-BEHmxORq.d.ts} +11 -11
- package/dist/{index-C_qi0WlF.d.cts → index-BJ26eEjs.d.cts} +26 -19
- package/dist/{index-BiomL7AW.d.ts → index-BJSZxSFX.d.ts} +1 -1
- package/dist/{index-DCAuN9u5.d.cts → index-BKMdnYnk.d.ts} +75 -39
- package/dist/{index-DfAo9WKr.d.ts → index-BM9szD8n.d.cts} +14 -6
- package/dist/{index-CajEOoAN.d.ts → index-BUPVld1w.d.ts} +2 -2
- package/dist/{index-C-pFD_FV.d.ts → index-BXd6OMEy.d.ts} +3 -3
- package/dist/index-BhUaMYm_.d.ts +113 -0
- package/dist/{index-DAKm44My.d.cts → index-BndG0cpK.d.cts} +3 -3
- package/dist/{index-Bpzw8hx3.d.ts → index-Br3WnqEn.d.ts} +84 -9
- package/dist/{index-D6tRNEKz.d.cts → index-BskfDoZ_.d.ts} +14 -6
- package/dist/{index-9mbs_PIG.d.ts → index-C19qqa38.d.ts} +4 -4
- package/dist/{index-fHKHdAso.d.ts → index-C7VV_qOs.d.ts} +4 -4
- package/dist/{index-CLPQyYY5.d.cts → index-CIRG8Hxp.d.cts} +11 -11
- package/dist/{index-B3D_z0Z6.d.cts → index-CL7oilfm.d.cts} +1 -1
- package/dist/{index-BOfHwQc1.d.ts → index-CPhBvRJU.d.ts} +1 -1
- package/dist/{index-B9qJmmv3.d.cts → index-CWHtYmSh.d.cts} +1 -1
- package/dist/{index-D_d1erkR.d.ts → index-Cey6VTnX.d.ts} +8 -5
- package/dist/{resilience-BWP2c7Af.d.cts → index-CmqiJZKM.d.ts} +141 -23
- package/dist/{index-JYtN9uqM.d.ts → index-CoM4rzyB.d.ts} +1 -1
- package/dist/{index-DTYIRT_v.d.cts → index-CpLpJb6A.d.cts} +8 -5
- package/dist/{index-BjWZARLy.d.ts → index-Ctb7_2sG.d.ts} +1 -1
- package/dist/index-CusEP3Sv.d.ts +210 -0
- package/dist/{resilience-Bys63Cpd.d.ts → index-CwP_KAMS.d.cts} +141 -23
- package/dist/{index-BFuVcqL8.d.cts → index-D3ayz3hy.d.cts} +1 -1
- package/dist/{index-CrpjECS6.d.cts → index-DCbE8fFM.d.cts} +3 -3
- package/dist/{index-D_DThl_J.d.cts → index-DIHcMLr6.d.cts} +1 -1
- package/dist/index-DINuaZlJ.d.cts +210 -0
- package/dist/{index-9xhIaM-w.d.cts → index-DOBLxOti.d.cts} +1 -1
- package/dist/index-DQUVq1_d.d.ts +374 -0
- package/dist/{index-B1IcU--K.d.cts → index-DTtBpuQy.d.cts} +4 -6
- package/dist/{index-D_QQ_dTD.d.cts → index-DYTBbF8T.d.cts} +1 -1
- package/dist/{index-DqtXA3yX.d.cts → index-DlgHqQxW.d.cts} +84 -9
- package/dist/{index-D1E1tqHT.d.ts → index-DlrWu9Hs.d.cts} +75 -39
- package/dist/{index-DcWbx58m.d.cts → index-DoYc8BWK.d.cts} +41 -48
- package/dist/{index-D0ZxFXYl.d.ts → index-DszPlZzK.d.ts} +3 -3
- package/dist/{index-BECJ8M0T.d.cts → index-DyM4tFAe.d.cts} +10 -8
- package/dist/{index-D11pGlaI.d.cts → index-FVoPvhAu.d.cts} +4 -4
- package/dist/{index-BwtIbzSV.d.cts → index-H_I66pav.d.cts} +2 -2
- package/dist/{index-e1m3ZHgc.d.cts → index-IwFqHxCs.d.cts} +2 -2
- package/dist/index-K-vl_c6A.d.cts +113 -0
- package/dist/{index-C4N-dg5U.d.cts → index-KlZ_ZUip.d.cts} +2 -2
- package/dist/index-L8XI8Zql.d.cts +374 -0
- package/dist/{index-D8IyqHvT.d.cts → index-MxYuWOrf.d.cts} +6 -4
- package/dist/{index-CpZKtdMw.d.cts → index-PgwvGWa1.d.cts} +1 -1
- package/dist/{index-B46GWgk3.d.ts → index-PlJ3MraE.d.ts} +1 -1
- package/dist/{index-DPqR3wdW.d.ts → index-PqbnoScQ.d.ts} +3 -3
- package/dist/{index-CU3z8Cel.d.cts → index-PsVHpPwP.d.cts} +3 -3
- package/dist/{index-C0tga1_x.d.ts → index-WyFKER-c.d.ts} +2 -2
- package/dist/{index-B5UR87KG.d.ts → index-eaQuGJnv.d.ts} +6 -4
- package/dist/{index-CzIWlnPp.d.ts → index-iTX5IqSP.d.ts} +140 -9
- package/dist/{index-CRycrNfn.d.ts → index-jKLph6cu.d.ts} +2 -2
- package/dist/{index-BhLA9feT.d.ts → index-jr6PuSBt.d.ts} +26 -19
- package/dist/{index-4IwO4mH2.d.cts → index-mNwgxC21.d.cts} +140 -9
- package/dist/{index-CkN8CZlT.d.cts → index-pVDQcbar.d.cts} +47 -71
- package/dist/{index-D6pwWiOc.d.cts → index-xZYcDqFH.d.cts} +4 -4
- package/dist/{index-8OxXae3g.d.ts → index-yLt-aPMp.d.ts} +1 -1
- package/dist/{index-CqSJ25A9.d.cts → index-z8WFPVI8.d.cts} +1 -1
- package/dist/index.cjs +64 -60
- package/dist/index.d.cts +48 -47
- package/dist/index.d.ts +48 -47
- package/dist/index.js +1 -1
- package/dist/meta-Ct9nqQS5.d.cts +102 -0
- package/dist/meta-D8OyedKp.d.ts +102 -0
- package/dist/{node-fSc-hCv8.d.cts → node-BYInONRr.d.cts} +3 -3
- package/dist/{node-fSc-hCv8.d.ts → node-BYInONRr.d.ts} +3 -3
- package/dist/{observable-Cqty11jG.d.cts → observable-DMIlYJV1.d.cts} +1 -1
- package/dist/{observable-EAV_rNfM.d.ts → observable-DO8DDEzv.d.ts} +1 -1
- package/dist/patterns/ai/browser.cjs +5 -5
- package/dist/patterns/ai/browser.d.cts +4 -4
- package/dist/patterns/ai/browser.d.ts +4 -4
- package/dist/patterns/ai/browser.js +1 -1
- package/dist/patterns/ai/index.cjs +17 -21
- package/dist/patterns/ai/index.d.cts +17 -17
- package/dist/patterns/ai/index.d.ts +17 -17
- package/dist/patterns/ai/index.js +1 -1
- package/dist/patterns/ai/node.cjs +1 -1
- package/dist/patterns/ai/node.d.cts +4 -4
- package/dist/patterns/ai/node.d.ts +4 -4
- package/dist/patterns/ai/node.js +1 -1
- package/dist/patterns/audit/index.cjs +3 -7
- package/dist/patterns/audit/index.d.cts +6 -6
- package/dist/patterns/audit/index.d.ts +6 -6
- package/dist/patterns/audit/index.js +1 -1
- package/dist/patterns/cqrs/index.cjs +3 -7
- package/dist/patterns/cqrs/index.d.cts +6 -6
- package/dist/patterns/cqrs/index.d.ts +6 -6
- package/dist/patterns/cqrs/index.js +1 -1
- package/dist/patterns/demo-shell/index.cjs +5 -8
- package/dist/patterns/demo-shell/index.d.cts +5 -5
- package/dist/patterns/demo-shell/index.d.ts +5 -5
- package/dist/patterns/demo-shell/index.js +1 -1
- package/dist/patterns/domain-templates/index.cjs +3 -7
- package/dist/patterns/domain-templates/index.d.cts +4 -4
- package/dist/patterns/domain-templates/index.d.ts +4 -4
- package/dist/patterns/domain-templates/index.js +1 -1
- package/dist/patterns/graphspec/index.cjs +38 -38
- package/dist/patterns/graphspec/index.d.cts +5 -5
- package/dist/patterns/graphspec/index.d.ts +5 -5
- package/dist/patterns/graphspec/index.js +1 -1
- package/dist/patterns/guarded-execution/index.cjs +3 -7
- package/dist/patterns/guarded-execution/index.d.cts +7 -7
- package/dist/patterns/guarded-execution/index.d.ts +7 -7
- package/dist/patterns/guarded-execution/index.js +1 -1
- package/dist/patterns/harness/index.cjs +8 -12
- package/dist/patterns/harness/index.d.cts +12 -12
- package/dist/patterns/harness/index.d.ts +12 -12
- package/dist/patterns/harness/index.js +1 -1
- package/dist/patterns/job-queue/index.cjs +3 -7
- package/dist/patterns/job-queue/index.d.cts +6 -6
- package/dist/patterns/job-queue/index.d.ts +6 -6
- package/dist/patterns/job-queue/index.js +1 -1
- package/dist/patterns/lens/index.cjs +3 -7
- package/dist/patterns/lens/index.d.cts +6 -6
- package/dist/patterns/lens/index.d.ts +6 -6
- package/dist/patterns/lens/index.js +1 -1
- package/dist/patterns/memory/index.cjs +3 -7
- package/dist/patterns/memory/index.d.cts +7 -5
- package/dist/patterns/memory/index.d.ts +7 -5
- package/dist/patterns/memory/index.js +1 -1
- package/dist/patterns/messaging/index.cjs +3 -7
- package/dist/patterns/messaging/index.d.cts +5 -5
- package/dist/patterns/messaging/index.d.ts +5 -5
- package/dist/patterns/messaging/index.js +1 -1
- package/dist/patterns/orchestration/index.cjs +3 -7
- package/dist/patterns/orchestration/index.d.cts +8 -8
- package/dist/patterns/orchestration/index.d.ts +8 -8
- package/dist/patterns/orchestration/index.js +1 -1
- package/dist/patterns/process/index.cjs +1 -1
- package/dist/patterns/process/index.d.cts +7 -7
- package/dist/patterns/process/index.d.ts +7 -7
- package/dist/patterns/process/index.js +1 -1
- package/dist/patterns/reactive-layout/index.cjs +4 -8
- package/dist/patterns/reactive-layout/index.d.cts +5 -5
- package/dist/patterns/reactive-layout/index.d.ts +5 -5
- package/dist/patterns/reactive-layout/index.js +1 -1
- package/dist/patterns/reduction/index.cjs +3 -7
- package/dist/patterns/reduction/index.d.cts +4 -4
- package/dist/patterns/reduction/index.d.ts +4 -4
- package/dist/patterns/reduction/index.js +1 -1
- package/dist/patterns/refine-loop/index.cjs +5 -9
- package/dist/patterns/refine-loop/index.d.cts +6 -6
- package/dist/patterns/refine-loop/index.d.ts +6 -6
- 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 -8
- package/dist/patterns/resilient-pipeline/index.d.ts +4 -8
- package/dist/patterns/resilient-pipeline/index.js +1 -1
- package/dist/patterns/surface/index.cjs +13 -17
- package/dist/patterns/surface/index.d.cts +6 -6
- package/dist/patterns/surface/index.d.ts +6 -6
- package/dist/patterns/surface/index.js +1 -1
- package/dist/{pipeline-graph-BrrYGjuZ.d.cts → pipeline-graph-BQPr2Lqs.d.cts} +34 -17
- package/dist/{pipeline-graph-DX2Twdj-.d.ts → pipeline-graph-D8vKcO_p.d.ts} +34 -17
- package/dist/{reactive-layout-DrGjuwyC.d.cts → reactive-layout-8CSc0tiA.d.cts} +2 -2
- package/dist/{reactive-layout-BDdngW56.d.ts → reactive-layout-DkTXxtSy.d.ts} +2 -2
- package/dist/{reactive-log-jirQsxMY.d.ts → reactive-log-BlAsPLl2.d.ts} +30 -3
- package/dist/{reactive-log-ScpWyqny.d.cts → reactive-log-_zeEnB9H.d.cts} +30 -3
- package/dist/{reactive-map-DmgeADH8.d.cts → reactive-map-B2qfD3hb.d.cts} +1 -1
- package/dist/{reactive-map-CHyeCf4D.d.ts → reactive-map-jFIsE6Kt.d.ts} +1 -1
- package/dist/resilience-HTF2LBRS.js +1 -0
- package/dist/{sugar-D13E2M_z.d.ts → sugar-BhfjgetH.d.ts} +1 -1
- package/dist/{sugar-DgaGJcI6.d.cts → sugar-DzePN5-g.d.cts} +1 -1
- package/dist/{topology-tree-BkhmMg2a.d.cts → topology-tree-B5Ngw3j0.d.cts} +1 -1
- package/dist/{topology-tree-BI665P0L.d.ts → topology-tree-BtvbgMXJ.d.ts} +1 -1
- package/dist/{types-BMSGPlpO.d.cts → types-1Dhoi7HM.d.cts} +1 -1
- package/dist/{types-CidcBDuk.d.ts → types-39jk0kaV.d.ts} +1 -1
- package/package.json +11 -1
- package/dist/chunk-4EATTNAE.js +0 -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-C5CBVOCB.js +0 -1
- package/dist/chunk-CZIQ6JCE.js +0 -1
- package/dist/chunk-FJ6IEMOS.js +0 -1
- package/dist/chunk-FMI4CWFL.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-O32GJOUJ.js +0 -1
- package/dist/chunk-QKBCTKH7.js +0 -1
- package/dist/chunk-QWVQIL3T.js +0 -1
- package/dist/chunk-UODQF4EY.js +0 -1
- package/dist/chunk-WGST56ZH.js +0 -80
- package/dist/chunk-WSLN4JFO.js +0 -1
- package/dist/chunk-XIJKEXWR.js +0 -1
- package/dist/imperative-audit-ahAE65a9.d.cts +0 -28
- package/dist/imperative-audit-ahAE65a9.d.ts +0 -28
- package/dist/index-BCq12BqB.d.ts +0 -139
- package/dist/index-BokynmA4.d.cts +0 -186
- package/dist/index-DXz9uwcs.d.ts +0 -186
- 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,7 +1,3 @@
|
|
|
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 vn(t){if(t.version!==ye)throw new Error(`unsupported snapshot version ${String(t.version)} (expected ${ye})`);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 Nr(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 m of p)if(r(f,m)){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 Dt(t){if(t===null||typeof t!="object")return t;if(Array.isArray(t))return t.map(Dt);let e=t,n=Object.keys(e).sort(),r={};for(let s of n)r[s]=Dt(e[s]);return r}function kr(t){return t.replaceAll("\\","\\\\").replaceAll('"','\\"')}function Ar(t){return t.replaceAll("\\","\\\\").replaceAll('"','\\"')}function Cr(t){return t==="TD"?"down":t==="BT"?"up":t==="RL"?"left":"right"}function xn(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 Tn(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 Dr(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(Dt(i),null,e.indent??2);return e.logger?.(a),a}function Mr(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}): ${it(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 En(t,e){let n=Tn(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}["${kr(i)}"]`)}for(let[i,a]of xn(t)){let u=s.get(i),d=s.get(a);!u||!d||o.push(` ${u} --> ${d}`)}return o.join(`
|
|
6
|
-
`)}function Gr(t,e){let n=En(t,e);return On(n)}function On(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 Lr(t,e){let n=Tn(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: ${Cr(n)}`];for(let i of r){let a=s.get(i);o.push(`${a}: "${Ar(i)}"`)}for(let[i,a]of xn(t)){let u=s.get(i),d=s.get(a);!u||!d||o.push(`${u} -> ${d}`)}return o.join(`
|
|
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 ht=Object.defineProperty;var Nn=Object.getOwnPropertyDescriptor;var Sn=Object.getOwnPropertyNames;var Rn=Object.prototype.hasOwnProperty;var j=(r,e)=>()=>(r&&(e=r(r=0)),e);var An=(r,e)=>{for(var t in e)ht(r,t,{get:e[t],enumerable:!0})},Cn=(r,e,t,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let s of Sn(e))!Rn.call(r,s)&&s!==t&&ht(r,s,{get:()=>e[s],enumerable:!(n=Nn(e,s))||n.enumerable});return r};var Dn=r=>Cn(ht({},"__esModule",{value:!0}),r);function Be(){return _e>0||Ce}function Ft(){return _e>0}function Te(r){_e>0?De.push(r):r()}function Ee(r){_e+=1;let e=!1;try{r()}catch(t){throw e=!0,t}finally{if(_e-=1,_e===0)if(e){if(!Ce){let t=De.splice(0);for(let n of t)try{n()}catch{}ce.length=0,le.length=0,we.length=0}}else Mn()}}function Mn(){let r=!Ce;r&&(Ce=!0);let e=[],t=0;try{for(;ce.length>0||le.length>0||we.length>0||r&&De.length>0;){if(r&&De.length>0){let o=De.splice(0);for(let i of o)try{i()}catch(a){e.push(a)}continue}if(t+=1,t>1e3)throw ce.length=0,le.length=0,we.length=0,new Error("batch drain exceeded 1000 iterations \u2014 likely a reactive cycle");let s=(ce.length>0?ce:le.length>0?le:we).splice(0);for(let o of s)try{o()}catch(i){e.push(i)}}}finally{r&&(Ce=!1)}if(e.length===1)throw e[0];if(e.length>1)throw new AggregateError(e,"batch drain: multiple callbacks threw")}function He(r,e,t){if(e.length===0)return;if(e.length===1){let u=t(e[0][0]);if(u<3||!Be()){r(e);return}(u>=5?we:u===4?le:ce).push(()=>r(e));return}let n=e.length,s=n,o=n,i=n,a=0;for(;a<n&&t(e[a][0])<3;)a++;for(s=a;a<n&&t(e[a][0])===3;)a++;for(o=a;a<n&&t(e[a][0])===4;)a++;i=a;let d=Be();if(s>0){let u=e.slice(0,s);r(u)}if(o>s){let u=e.slice(s,o);d?ce.push(()=>r(u)):r(u)}if(i>o){let u=e.slice(o,i);d?le.push(()=>r(u)):r(u)}if(n>i){let u=e.slice(i,n);d?we.push(()=>r(u)):r(u)}}var _e,Ce,ce,le,we,De,Me=j(()=>{"use strict";_e=0,Ce=!1,ce=[],le=[],we=[],De=[]});function re(){return Math.trunc(performance.now()*1e6)}function ne(){return Date.now()*1e6}var Ge=j(()=>{"use strict"});function Vt(r){return Array.isArray(r)?[...r]:[r]}function Gn(r,e){return r.has(e)||r.has("*")}function xe(r){let e=[];return r((s,o)=>{e.push({kind:"allow",actions:new Set(Vt(s)),where:o?.where??(()=>!0)})},(s,o)=>{e.push({kind:"deny",actions:new Set(Vt(s)),where:o?.where??(()=>!0)})}),(s,o)=>{let i=!1,a=!1;for(let d of e)Gn(d.actions,o)&&d.where(s)&&(d.kind==="deny"?i=!0:a=!0);return i?!1:a}}function gt(r){let e=Ln.filter(t=>r({type:t,id:""},"write"));return e.length===0?"restricted":e.includes("human")&&e.includes("llm")&&e.every(t=>t==="human"||t==="llm"||t==="system")?"both":e.length===1?e[0]:e.join("+")}var X,Ln,fe=j(()=>{"use strict";X=class extends Error{actor;action;nodeName;constructor(e,t){super(t??`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}};Ln=["human","llm","wallet","system"]});function qe(r){if(r==null)return Oe;let{type:e,id:t,...n}=r;return{type:e??"system",id:t??"",...n}}var Oe,We=j(()=>{"use strict";Oe={type:"system",id:""}});var ke,G,W,U,Q,te,se,z,B,P,pe,Ue,zt,Ke,jt,Bt,Ye,mt,yt,bt,Je,Ne=j(()=>{"use strict";ke=Symbol.for("graphrefly/START"),G=Symbol.for("graphrefly/DATA"),W=Symbol.for("graphrefly/DIRTY"),U=Symbol.for("graphrefly/RESOLVED"),Q=Symbol.for("graphrefly/INVALIDATE"),te=Symbol.for("graphrefly/PAUSE"),se=Symbol.for("graphrefly/RESUME"),z=Symbol.for("graphrefly/TEARDOWN"),B=Symbol.for("graphrefly/COMPLETE"),P=Symbol.for("graphrefly/ERROR"),pe=Object.freeze([W]),Ue=Object.freeze([U]),zt=Object.freeze([Q]),Ke=Object.freeze([ke]),jt=Object.freeze([B]),Bt=Object.freeze([z]),Ye=Object.freeze([pe]),mt=Object.freeze([Ue]),yt=Object.freeze([zt]),bt=Object.freeze([jt]),Je=Object.freeze([Bt])});function Ht(r){r.registerMessageType(ke,{tier:0,wireCrossing:!1}),r.registerMessageType(W,{tier:1,wireCrossing:!1}),r.registerMessageType(Q,{tier:1,wireCrossing:!1,metaPassthrough:!1}),r.registerMessageType(te,{tier:2,wireCrossing:!1}),r.registerMessageType(se,{tier:2,wireCrossing:!1}),r.registerMessageType(G,{tier:3,wireCrossing:!0}),r.registerMessageType(U,{tier:3,wireCrossing:!0}),r.registerMessageType(B,{tier:4,wireCrossing:!0,metaPassthrough:!1}),r.registerMessageType(P,{tier:4,wireCrossing:!0,metaPassthrough:!1}),r.registerMessageType(z,{tier:5,wireCrossing:!0,metaPassthrough:!1})}var Ze,qt=j(()=>{"use strict";Ne();Ze=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=t=>{let n=this._messageTypes.get(t);return n!=null?n.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,t){return this._assertUnfrozen(),this._messageTypes.set(e,{tier:t.tier,wireCrossing:t.wireCrossing??t.tier>=3,metaPassthrough:t.metaPassthrough??!0}),this}messageTier(e){let t=this._messageTypes.get(e);return t!=null?t.tier:1}isWireCrossing(e){let t=this._messageTypes.get(e);return t!=null?t.wireCrossing:!0}isLocalOnly(e){return!this.isWireCrossing(e)}isMetaPassthrough(e){let t=this._messageTypes.get(e);return t!=null?t.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 Ut(r,e){let t=new TextEncoder().encode(r.name);if(t.length===0||t.length>255)throw new Error(`encodeEnvelope: codec name "${r.name}" encodes to ${t.length} bytes (must be 1\u2013255)`);let n=r.version;if(!Number.isInteger(n)||n<0||n>65535)throw new Error(`encodeEnvelope: codec.version ${n} out of u16 range (expected integer 0\u201365535)`);let s=2+t.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++]=t.length,o.set(t,i),i+=t.length,o[i++]=n>>>8&255,o[i++]=n&255,o.set(e,i),o}function Kt(r,e){if(r.length<Wt)throw new Error(`decodeEnvelope: bytes too short (${r.length} < ${Wt})`);let t=0,n=r[t++];if(n!==vt)throw new Error(`decodeEnvelope: unsupported envelope version ${n} (expected ${vt})`);let s=r[t++];if(s===0)throw new Error("decodeEnvelope: name_len must be >= 1");if(t+s+2>r.length)throw new Error(`decodeEnvelope: envelope truncated (need ${t+s+2} bytes, have ${r.length})`);let o=new TextDecoder().decode(r.subarray(t,t+s));t+=s;let i=(r[t]<<8|r[t+1])>>>0;t+=2;let a=r.subarray(t),d=e.lookupCodec(o);if(d==null)throw new Error(`decodeEnvelope: codec "${o}" not registered (envelope codec_v=${i})`);return{codec:d,codecVersion:i,payload:a}}function Yt(r){r.registerCodec(Pn)}var Pn,vt,Wt,_t=j(()=>{"use strict";Pn={name:"json",version:1,contentType:"application/json",encode(r){let e=JSON.stringify(r);return new TextEncoder().encode(e)},decode(r,e){let t=new TextDecoder().decode(r);return JSON.parse(t)}},vt=1,Wt=4});function wt(r){if(r===void 0)return null;if(typeof r=="number"){if(!Number.isFinite(r))throw new TypeError(`Cannot hash non-finite number: ${r}`);if(Number.isInteger(r)&&!Number.isSafeInteger(r))throw new TypeError(`Cannot hash integer outside safe range (|n| > 2^53-1): ${r}. Cross-language cid parity is not guaranteed for unsafe integers.`);return r}if(typeof r=="string"||typeof r=="boolean"||r===null)return r;if(Array.isArray(r))return r.map(wt);if(typeof r=="object"&&r!==null){let e={};for(let t of Object.keys(r).sort())e[t]=wt(r[t]);return e}return null}function Fn(r){let e=$n.encode(r),t=e.length,n=t*8,s=t+9+63&-64,o=new Uint8Array(s);o.set(e),o[t]=128;let i=new DataView(o.buffer);i.setUint32(s-4,n>>>0,!1),i.setUint32(s-8,Math.floor(n/4294967296)>>>0,!1);let a=1779033703,d=3144134277,u=1013904242,c=2773480762,h=1359893119,f=2600822924,p=528734635,l=1541459225,v=new Uint32Array(64),g=(_,y)=>_>>>y|_<<32-y;for(let _=0;_<s;_+=64){for(let T=0;T<16;T++)v[T]=i.getUint32(_+T*4,!1);for(let T=16;T<64;T++){let S=v[T-15],C=v[T-2],R=g(S,7)^g(S,18)^S>>>3,I=g(C,17)^g(C,19)^C>>>10;v[T]=v[T-16]+R+v[T-7]+I>>>0}let y=a,b=d,w=u,N=c,m=h,O=f,k=p,E=l;for(let T=0;T<64;T++){let S=g(m,6)^g(m,11)^g(m,25),C=m&O^~m&k,R=E+S+C+In[T]+v[T]>>>0,I=g(y,2)^g(y,13)^g(y,22),V=y&b^y&w^b&w,q=I+V>>>0;E=k,k=O,O=m,m=N+R>>>0,N=w,w=b,b=y,y=R+q>>>0}a=a+y>>>0,d=d+b>>>0,u=u+w>>>0,c=c+N>>>0,h=h+m>>>0,f=f+O>>>0,p=p+k>>>0,l=l+E>>>0}let x=_=>_.toString(16).padStart(8,"0");return x(a)+x(d)+x(u)+x(c)+x(h)+x(f)+x(p)+x(l)}function Tt(r){let e=wt(r??null),t=JSON.stringify(e);return Fn(t).slice(0,16)}function Vn(){let r=globalThis.crypto;if(r?.randomUUID)return r.randomUUID();let e=()=>Math.floor(Math.random()*4294967296).toString(16).padStart(8,"0"),t=e()+e()+e()+e();return`${t.slice(0,8)}-${t.slice(8,12)}-4${t.slice(13,16)}-${(parseInt(t.slice(16,17),16)&3|8).toString(16)}${t.slice(17,20)}-${t.slice(20,32)}`}function Et(r,e,t){let n=t?.id??Vn();if(r===0)return{id:n,version:0};let o=(t?.hash??Tt)(e);return{id:n,version:0,cid:o,prev:null}}function Jt(r,e,t){r.version+=1,"cid"in r&&(r.prev=r.cid,r.cid=t(e))}var In,$n,Zt=j(()=>{"use strict";In=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]),$n=new TextEncoder});function en(r){return{node:r,unsub:null,prevData:void 0,dirty:!1,involvedThisWave:!1,dataBatch:[],terminal:void 0}}function xt(r){r.prevData=void 0,r.dirty=!1,r.involvedThisWave=!1,r.dataBatch.length=0,r.terminal=void 0}function Xe(r){return r.length===0?r:typeof r[0]=="symbol"?[r]:r}function oe(r,e,t){let n=tn(r)?r:[],s=typeof r=="function"?r:typeof e=="function"?e:void 0,o={};return tn(r)?o=(Ot(e)?e:t)??{}:Ot(r)?o=r:o=(Ot(e)?e:t)??{},new $(n,s,o)}var Xt,Qt,zn,jn,he,$,tn,Ot,ge=j(()=>{"use strict";_t();We();Me();Ge();qt();fe();Ne();Zt();Xt=()=>{},Qt=100;zn=(r,e,t,n)=>{t.direction==="down-in"&&r._onDepMessage(t.depIndex,e)},jn=(r,e,t,n)=>{let s=r;if(s._status==="completed"||s._status==="errored")return;let o=s._cached,i=o===void 0?[Ke]:[Ke,[G,o]];s._status==="dirty"&&i.push(pe),He(e,i,s._config.tierOf)},he=new Ze({onMessage:zn,onSubscribe:jn});Ht(he);Yt(he);$=class r{_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,t,n){this._config=n.config??he,this._config.onMessage,this._optsName=n.name,this._describeKind=n.describeKind,this._equals=n.equals??Object.is,this._resubscribable=n.resubscribable??!1,this._resetOnTeardown=n.resetOnTeardown??!1,this._autoComplete=n.completeWhenDepsComplete??!0,this._autoError=n.errorWhenDepsError??!0,this._pausable=n.pausable??!0,this._guard=n.guard,this._fn=t,this._partial=n.partial??!1,this._cached=n.initial!==void 0?n.initial:void 0,this._status=e.length===0&&t==null&&this._cached!==void 0?"settled":"sentinel",this._hashFn=n.versioningHash??this._config.defaultHashFn??Tt;let s=n.versioning??this._config.defaultVersioning;this._versioningLevel=s,this._versioning=s!=null?Et(s,this._cached===void 0?void 0:this._cached,{id:n.versioningId,hash:this._hashFn}):void 0,this._deps=e.map(en);let o={};for(let[a,d]of Object.entries(n.meta??{})){let u={initial:d,name:`${n.name??"node"}:meta:${a}`,describeKind:"state",config:this._config};n.guard!=null&&(u.guard=n.guard),o[a]=new r([],void 0,u)}Object.freeze(o),this.meta=o,this._hasMeta=Object.keys(o).length>0;let i=this;this._actions={emit(a){i._emit([[G,a]])},down(a){i._emit(Xe(a))},up(a){i._emitUp(Xe(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,t){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 n=this._versioningLevel;if(n!=null&&e<=n)return;let s=t?.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??t?.id,d=i?.version??0,u=Et(e,o,{id:a,hash:s});u.version=d,this._versioning=u,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 t=qe(e);if(this._guard!=null&&!this._guard(t,"observe"))return!1;if(this._extraGuards!=null){for(let n of this._extraGuards)if(!n(t,"observe"))return!1}return!0}_checkGuard(e){if(e?.internal)return;let t=this._guard!=null||this._extraGuards!=null,n=e?.actor!=null;if(!t&&!n)return;let s=qe(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,t){let n=Xe(e);n.length!==0&&(this._checkGuard(t),this._emit(n))}emit(e,t){this._checkGuard(t),this._emit([[G,e]])}up(e,t){if(this._deps.length===0)return;let n=Xe(e);if(n.length===0)return;this._checkGuard(t);let s=t??{internal:!0};this._validateUpTiers(n);for(let o of this._deps)o.node.up?.(n,s)}_emitUp(e){if(this._deps.length!==0&&e.length!==0){this._validateUpTiers(e);for(let t of this._deps)t.node.up?.(e,{internal:!0})}}_validateUpTiers(e){let t=this._config.tierOf;for(let n of e){let s=t(n[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,t){if(t!=null&&this._guard!=null){let d=qe(t);if(!this._guard(d,"observe"))throw new X({actor:d,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 d of this._deps)xt(d);if(this._partial===!1){for(let d of this._deps)if(d.prevData!==void 0||d.dataBatch.length!==0||d.terminal!==void 0||d.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(d){throw this._sinkCount-=1,d}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(d){if(this._sinkCount-=1,this._removeSink(e),this._sinkCount===0&&(this._status="sentinel"),typeof o=="function")try{o()}catch{}throw d}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[t]=this._sinks;this._sinks=t}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,t=0;try{for(let n=0;n<e;n++){let s=n,o=this._deps[n];o.unsub=Xt,o.unsub=o.node.subscribe(i=>{if(o.unsub===null)return;let a=this._config.tierOf,d=!1;for(let u of i)a(u[0])>=3&&(d=!0),this._config.onMessage(this,u,{direction:"down-in",depIndex:s},this._actions);d&&this._maybeRunFnOnSettlement()}),t++}}catch(n){this._deps[t].unsub=null;for(let s=0;s<t;s++){let o=this._deps[s];if(o.unsub!=null){let i=o.unsub;o.unsub=null;try{i()}catch{}xt(o)}}throw this._dirtyDepCount=0,n}}_addDep(e){for(let s=0;s<this._deps.length;s++)if(this._deps[s].node===e)return s;let t=this._deps.length,n=en(e);if(this._deps.push(n),this._sinks==null)return t;n.dirty=!0,this._dirtyDepCount++,this._status!=="dirty"&&this._emit(Ye),n.unsub=Xt;try{n.unsub=e.subscribe(s=>{if(n.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:t},this._actions);i&&this._maybeRunFnOnSettlement()})}catch(s){throw n.unsub=null,this._deps.pop(),this._dirtyDepCount--,s}return t}_deactivate(e=!1){let t=this._cleanup;if(this._cleanup=void 0,typeof t=="function")try{t()}catch(n){this._emit([[P,this._wrapFnError("cleanup threw",n)]])}else if(t!=null&&typeof t=="object"){let n=t.deactivate;if(typeof n=="function")try{n()}catch(s){this._emit([[P,this._wrapFnError("cleanup.deactivate threw",s)]])}}for(let n of this._deps){if(n.unsub!=null){let s=n.unsub;n.unsub=null;try{s()}catch{}}xt(n)}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,t){let n=this._deps[e],s=t[0];if(this._inspectorHooks!=null){let o={kind:"dep_message",depIndex:e,message:t};for(let i of this._inspectorHooks)i(o)}if(s!==ke){if(s===W){this._depDirtied(n);return}if(s===Q){if(this._depInvalidated(n),this._cached===void 0)return;this._emit(yt);return}if(s===te||s===se){this._emit([t]);return}if(s===z){this._emit(Je);return}if(s===G)this._depSettledAsData(n,t[1]);else if(s===U)this._depSettledAsResolved(n);else if(s===B)this._depSettledAsTerminal(n,!0);else if(s===P)this._depSettledAsTerminal(n,t[1]);else{this._emit([t]);return}if(!this._fn){(s===G||s===U)&&this._emit([t]),(s===B||s===P)&&this._maybeAutoTerminalAfterWave();return}}}_depDirtied(e){e.dirty||(e.dirty=!0,e.involvedThisWave=!0,this._dirtyDepCount++,this._status!=="dirty"&&this._emit(Ye))}_depSettledAsData(e,t){e.dirty&&(e.dirty=!1,this._dirtyDepCount--),e.involvedThisWave=!0,e.dataBatch.push(t),this._waveHasNewData=!0}_depSettledAsResolved(e){e.dirty&&(e.dirty=!1,this._dirtyDepCount--)}_depSettledAsTerminal(e,t){e.dirty&&(e.dirty=!1,this._dirtyDepCount--),e.terminal=t,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 t=this._deps[e];if(t.dataBatch.length===0&&t.prevData===void 0&&t.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(t=>t.terminal!==void 0&&t.terminal!==!0);if(e!=null){this._autoError&&this._emit([[P,e.terminal]]);return}this._autoComplete&&this._deps.every(t=>t.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([[P,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([[P,this._wrapFnError("cleanup.beforeRun threw",a)]]);return}}}let t=this._deps.map(i=>i.involvedThisWave?i.dataBatch.length>0?[...i.dataBatch]:[]:void 0),n=this._deps.map(i=>i.prevData);for(let i=0;i<this._deps.length;i++){let a=t[i];a!=null&&a.length>0&&(this._deps[i].prevData=a[a.length-1])}let s=this._deps.map(i=>i.terminal),o={prevData:n,terminalDeps:s,store:this._store};if(this._hasCalledFnOnce=!0,this._clearWaveFlags(),this._inspectorHooks!=null){let i={kind:"run",batchData:t,prevData:n};for(let a of this._inspectorHooks)a(i)}this._isExecutingFn=!0;try{let i=this._fn(t,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([[P,this._wrapFnError("fn threw",i)]])}finally{this._isExecutingFn=!1,this._pendingRerun?(this._pendingRerun=!1,this._rerunDepth+=1,this._rerunDepth>Qt?(this._rerunDepth=0,this._emit([[P,new Error(`Node "${this.name}": _pendingRerun depth exceeded ${Qt} \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,t){let n=t instanceof Error?t.message:String(t);return new Error(`Node "${this.name}": ${e}: ${n}`,{cause:t})}_frameBatch(e){let t=this._config.tierOf;if(e.length===1)return t(e[0][0])===3&&this._status!=="dirty"?[pe,e[0]]:e;let n=!0,s=!1,o=!1,i=-1;for(let d of e){let u=t(d[0]);u<i&&(n=!1),u===3&&(s=!0),d[0]===W&&(o=!0),i=u}let a=e;if(!n){let d=e.map((u,c)=>({m:u,i:c,tier:t(u[0])}));d.sort((u,c)=>u.tier-c.tier||u.i-c.i),a=d.map(u=>u.m)}if(s&&!o&&this._status!=="dirty"){let d=0;for(;d<a.length&&t(a[d][0])===0;)d++;return d===0?[pe,...a]:[...a.slice(0,d),pe,...a.slice(d)]}return a}_emit(e){if(e.length===0)return;for(let a=0;a<e.length;a++){let d=e[a];if(d[0]===P&&d[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 t=e;if(this._isTerminal&&!this._resubscribable){let a=e.filter(d=>d[0]===z||d[0]===Q);if(a.length===0)return;t=a}t=this._frameBatch(t);let s=null;for(let a=0;a<t.length;a++){let d=t[a],u=d[0];if(u!==te&&u!==se){s?.push(d);continue}if(d.length<2)throw new Error(`Node "${this.name}": [[${u===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=d[1];if(u===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 f=this._pauseBuffer;this._pauseBuffer=[],this._emit(f)}this._pendingWave&&(this._pendingWave=!1,this._maybeRunFnOnSettlement())}}c?s?.push(d):s==null&&(s=t.slice(0,a))}if(s!=null){if(s.length===0)return;t=s}if(this._hasMeta&&t.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(t);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,d=[];for(let u of o)a(u[0])===3?this._pauseBuffer.push(u):d.push(u);d.length>0&&this._dispatchOrAccumulate(d)}else this._dispatchOrAccumulate(o);i!=null&&this._emit([[P,i]])}_updateState(e){let t=this._config.tierOf,n,s,o=-1,i=0;for(let c of e)t(c[0])===3&&i++;let a=i<=1,d=-1;if(this._versioning!=null&&i>1){for(let c=e.length-1;c>=0;c--)if(e[c][0]===G){d=c;break}}for(let c=0;c<e.length;c++){let h=e[c],f=h[0];if(f===G){if(h.length>=2){let p=!1;if(a&&this._cached!==void 0)try{p=this._equals(this._cached,h[1])}catch(l){s=this._wrapFnError("equals threw",l),o=c;break}if(p){n==null&&(n=e.slice(0,c)),n.push(Ue),this._status="resolved";continue}this._cached=h[1],this._versioning!=null&&(d<0||c===d)&&Jt(this._versioning,h[1],this._hashFn)}this._status="settled",n?.push(h)}else if(n?.push(h),f===W)this._status="dirty";else if(f===U)this._status="resolved";else if(f===B){this._status="completed";{let p=this._config.rigorRecorder;if(p!=null)try{p.onTerminalTransition(this,"completed",this._autoComplete,this._autoError,this._deps.length>0)}catch{}}}else if(f===P){this._status="errored";{let p=this._config.rigorRecorder;if(p!=null)try{p.onTerminalTransition(this,"errored",this._autoComplete,this._autoError,this._deps.length>0)}catch{}}}else if(f===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 p=this._cleanup;if(typeof p=="function"){this._cleanup=void 0;try{p()}catch{}}else if(p!=null&&typeof p=="object"){let l=p.invalidate;if(typeof l=="function")try{l()}catch{}}}else f===z&&(this._resetOnTeardown&&(this._cached=void 0),this._deactivate(!0),this._status="sentinel")}let u=o>=0?n??e.slice(0,o):n??e;return s!=null?{finalMessages:u,equalsError:s}:{finalMessages:u}}_deliverToSinks=e=>{if(this._sinks==null)return;if(typeof this._sinks=="function"){this._sinks(e);return}let t=[...this._sinks];for(let n of t)n(e)};_dispatchOrAccumulate(e){if(Ft()){this._batchPendingMessages===null&&(this._batchPendingMessages=[],Te(()=>this._flushBatchPending()));for(let t of e)this._batchPendingMessages.push(t);return}He(this._deliverToSinks,e,this._config.tierOf)}_flushBatchPending(){let e=this._batchPendingMessages;if(e===null||(this._batchPendingMessages=null,e.length===0))return;let t=this._frameBatch(e);He(this._deliverToSinks,t,this._config.tierOf)}},tn=r=>Array.isArray(r),Ot=r=>typeof r=="object"&&r!=null&&!Array.isArray(r)});function Qe(r,e){if(e!=null&&e.length>0)return new Set(e);switch(r){case"standard":return new Set(["type","status","value","deps","meta","v"]);case"full":return null;case"spec":return new Set(["type","deps","meta","value"]);default:return new Set(["type","deps"])}}function Bn(r){return r._describeKind!=null?r._describeKind:r._deps.length>0?"derived":r._fn!=null?"producer":"state"}function Nt(r){let e=new WeakSet,t={};for(let[n,s]of nn(r))t[n]=kt(s,e);return t}function kt(r,e){if(r==null)return r;let t=typeof r;if(t==="boolean"||t==="number"||t==="string")return r;if(t==="function")return"<function>";if(Array.isArray(r))return e.has(r)?"<cycle>":(e.add(r),r.map(n=>kt(n,e)));if(t==="object"){let n=r;if(e.has(n))return"<cycle>";e.add(n);try{if(typeof n.subscribe=="function"&&"cache"in n)return"<Node>"}catch{return"<unserializable>"}let s={};for(let[o,i]of nn(n))s[o]=kt(i,e);return s}return"<unserializable>"}function nn(r){let e=[],t;try{t=Object.keys(r)}catch{return e}for(let n of t)try{e.push([n,r[n]])}catch{e.push([n,"<unserializable>"])}return e}function Hn(r){let e={};for(let[t,n]of Object.entries(r.meta))try{e[t]=n.cache}catch{}return e}function St(r,e,t){let n=e==null,s=!n&&e!=null?[...e].filter(c=>c.startsWith("meta.")).map(c=>c.slice(5)):null,o=n||e.has("meta")||s!=null&&s.length>0,i="state",a=[];r instanceof $&&(i=Bn(r),a=r._deps.map(c=>c.node.name??""));let d={type:i,deps:a};(n||e.has("status"))&&(d.status=r.status);let u=r instanceof $?r._guard:void 0;if(o){let c={...Hn(r)};if(u!=null&&c.access===void 0&&(c.access=gt(u)),s!=null&&s.length>0&&!e.has("meta")){let h={};for(let f of s)f in c&&(h[f]=c[f]);d.meta=h}else d.meta=c}if(r.name!=null&&(d.name=r.name),(n||e.has("value"))&&(!t||i==="state")){r.status==="sentinel"&&(d.sentinel=!0);try{d.value=r.cache}catch{}}if((n||e.has("v"))&&r.v!=null){let c={id:r.v.id,version:r.v.version};"cid"in r.v&&(c.cid=r.v.cid,c.prev=r.v.prev),d.v=c}return(n||e.has("guard"))&&u!=null&&(d.guard=gt(u)),(n||e.has("lastMutation"))&&r.lastMutation!=null&&(d.lastMutation=r.lastMutation),d}var Rt=j(()=>{"use strict";fe();ge()});function K(r,e){return oe([],{...e,initial:r})}function et(r,e){return oe((n,s,o)=>r(s,o)??void 0,{describeKind:"producer",...e})}function Y(r,e,t){return oe(r,(s,o,i)=>{let a=s.map((d,u)=>d!=null&&d.length>0?d.at(-1):i.prevData[u]);o.emit(e(a,i))},{describeKind:"derived",...t})}var Le=j(()=>{"use strict";ge()});function ie(r){return r.subscribe(()=>{})}var sn=j(()=>{"use strict"});var Dt=j(()=>{"use strict";sn()});var tt,on=j(()=>{"use strict";tt=class{_timer;_gen=0;start(e,t){this.cancel(),this._gen+=1;let n=this._gen;this._timer=setTimeout(()=>{this._timer=void 0,n===this._gen&&t()},e)}cancel(){this._timer!==void 0&&(clearTimeout(this._timer),this._timer=void 0)}get pending(){return this._timer!==void 0}}});var Pe,an=j(()=>{"use strict";Pe=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 t=(this.head+this._size)%this.capacity;this.buf[t]=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 t=e<0?this._size+e:e;if(!(t<0||t>=this._size))return this.buf[(this.head+t)%this.capacity]}toArray(){let e=new Array(this._size);for(let t=0;t<this._size;t++)e[t]=this.buf[(this.head+t)%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}}});function xn(r,e,t){return{[r]:!0,[`${r}_type`]:e,...t??{}}}var On=j(()=>{"use strict"});var mr={};An(mr,{CqrsGraph:()=>lt,cqrs:()=>gr,cqrsEventKeyOf:()=>fr,dispatchKeyOf:()=>pr,sagaInvocationKeyOf:()=>hr});module.exports=Dn(mr);Me();Ge();fe();We();fe();Ne();Rt();ge();Le();fe();Le();We();Me();Ge();fe();Ne();Rt();ge();Le();Ge();function At(r,e){if(Object.is(r,e))return!0;if(r==null||e==null||typeof r!="object"||typeof e!="object")return!1;if(Array.isArray(r)){if(!Array.isArray(e)||r.length!==e.length)return!1;for(let o=0;o<r.length;o++)if(!At(r[o],e[o]))return!1;return!0}if(Array.isArray(e))return!1;let t=Object.keys(r),n=Object.keys(e);if(t.length!==n.length)return!1;let s=new Set(n);for(let o of t)if(!s.has(o)||!At(r[o],e[o]))return!1;return!0}function rn(r,e){return`${r}\0${e}`}function Ct(r,e){let t=[],n=new Set(r.subgraphs),s=new Set(e.subgraphs),o=[];for(let g of s)n.has(g)||o.push(g);o.sort();for(let g of o)t.push({type:"subgraph-mounted",path:g});let i=new Set(Object.keys(r.nodes)),a=new Set(Object.keys(e.nodes)),d=[];for(let g of a)i.has(g)||d.push(g);d.sort();for(let g of d)t.push({type:"node-added",path:g,node:{...e.nodes[g]}});let u=[];for(let g of a){if(!i.has(g))continue;let x=r.nodes[g]?.meta,_=e.nodes[g]?.meta;x==null&&_==null||At(x??{},_??{})||u.push(g)}u.sort();for(let g of u)t.push({type:"node-meta-changed",path:g,prevMeta:r.nodes[g]?.meta??{},nextMeta:e.nodes[g]?.meta??{}});let c=new Map;for(let g of r.edges)c.set(rn(g.from,g.to),g);let h=new Map;for(let g of e.edges)h.set(rn(g.from,g.to),g);let f=[];for(let[g,x]of h)c.has(g)||f.push(x);f.sort((g,x)=>g.from<x.from?-1:g.from>x.from?1:g.to<x.to?-1:g.to>x.to?1:0);for(let g of f)t.push({type:"edge-added",from:g.from,to:g.to});let p=[];for(let[g,x]of c)h.has(g)||p.push(x);p.sort((g,x)=>g.from<x.from?-1:g.from>x.from?1:g.to<x.to?-1:g.to>x.to?1:0);for(let g of p)t.push({type:"edge-removed",from:g.from,to:g.to});let l=[];for(let g of i)a.has(g)||l.push(g);l.sort();for(let g of l)t.push({type:"node-removed",path:g});let v=[];for(let g of n)s.has(g)||v.push(g);v.sort();for(let g of v)t.push({type:"subgraph-unmounted",path:g});return{events:t,flushedAt_ns:re()}}Dt();on();an();_t();function dn(r,e,t,n={}){let s=e in r.nodes,o=t in r.nodes;if(!s)return nt(e,t,"no-such-from");if(!o)return nt(e,t,"no-such-to");let i=n.maxDepth;if(i!=null&&(!Number.isInteger(i)||i<0))throw new Error("explainPath: maxDepth must be an integer >= 0");if(e===t){if(n.findCycle===!0){let u=qn(r,e,n);if(u!=null)return u}let d=rt(e,r.nodes[e],0,n);return st(e,t,[d])}if(i===0)return nt(e,t,"no-path");let a=un(r,e,t,i);return a.found?st(e,t,cn(r,a.pathOrder,n)):nt(e,t,a.truncated?"max-depth-exceeded":"no-path")}function un(r,e,t,n){let s=new Map,o=[{path:t,depth:0}],i=new Set([t]),a=0,d=!1;for(;a<o.length;){let h=o[a++];if(h.path===e)break;if(n!=null&&h.depth>=n){let v=r.nodes[h.path];v?.deps&&v.deps.length>0&&(d=!0);continue}let f=r.nodes[h.path];if(f==null)continue;let p=f.deps??[],l=new Map;for(let v=0;v<p.length;v++){let g=p[v];if(!g)continue;let x=l.get(g);x==null&&(x=[],l.set(g,x)),x.push(v)}for(let[v,g]of l)i.has(v)||(i.add(v),s.set(v,{from:h.path,depIndices:g}),o.push({path:v,depth:h.depth+1}))}if(!s.has(e))return{found:!1,pathOrder:[],truncated:d};let u=[{path:e}],c=e;for(;c!==t;){let h=s.get(c);if(h==null)return{found:!1,pathOrder:[],truncated:!1};u[u.length-1].depIndices=h.depIndices,u.push({path:h.from}),c=h.from}return{found:!0,pathOrder:u,truncated:!1}}function qn(r,e,t){let n=r.nodes[e];if(n==null)return null;let s=n.deps??[],o=[];for(let a=0;a<s.length;a++)s[a]===e&&o.push(a);if(o.length>0){let a=rt(e,n,0,t);a.dep_index=o[0];let d=rt(e,n,1,t);return st(e,e,[a,d])}let i=null;for(let a=0;a<s.length;a++){let d=s[a];if(!d||d===e)continue;let u=un(r,d,e,t.maxDepth);u.found&&(i==null||u.pathOrder.length<i.pathOrder.length)&&(i=u,i={found:!0,pathOrder:[{path:e,depIndices:[a]},...u.pathOrder],truncated:!1})}return i==null?null:st(e,e,cn(r,i.pathOrder,t))}function cn(r,e,t){return e.map((n,s)=>{let o=r.nodes[n.path],i=rt(n.path,o,s,t);return n.depIndices!=null&&n.depIndices.length>0&&(i.dep_index=n.depIndices[0],n.depIndices.length>1&&(i.dep_indices=[...n.depIndices])),i})}function rt(r,e,t,n){let s={path:r,type:e.type,hop:t};e.status!==void 0&&(s.status=e.status),"value"in e&&(s.value=e.value),e.v!=null&&(s.v=e.v);let o=n.annotations?.get(r)??e.annotation;o!=null&&(s.annotation=o);let i=n.lastMutations?.get(r)??e.lastMutation;return i!=null&&(s.lastMutation=i),s}function st(r,e,t){return ln(r,e,!0,"ok",t)}function nt(r,e,t){return ln(r,e,!1,t,[])}function ln(r,e,t,n,s){let o=Wn(r,e,t,n,s);return{from:r,to:e,found:t,reason:n,steps:s,text:o,toJSON(){return{from:r,to:e,found:t,reason:n,steps:s}}}}function Wn(r,e,t,n,s){if(!t)switch(n){case"no-such-from":return`explainPath: no node named "${r}"`;case"no-such-to":return`explainPath: no node named "${e}"`;case"max-depth-exceeded":return`explainPath: no path from "${r}" to "${e}" within maxDepth`;default:return`explainPath: no path from "${r}" to "${e}"`}let o=[`Causal path: ${r} \u2192 ${e} (${s.length} step(s))`];for(let i of s){let d=` ${i.hop===0?"\xB7":"\u2193"} ${i.path} (${i.type}${i.status?`/${i.status}`:""})`;if(o.push(d),"value"in i&&o.push(` value: ${Un(i.value)}`),i.annotation!=null&&o.push(` annotation: ${i.annotation}`),i.lastMutation!=null){let u=i.lastMutation.actor;o.push(` actor: ${u.type}${u.id?`:${u.id}`:""}`)}}return o.join(`
|
|
2
|
+
`)}function Un(r){if(r===void 0)return"<sentinel>";if(r===null)return"null";if(typeof r=="string")return JSON.stringify(r);if(typeof r=="number"||typeof r=="boolean"||typeof r=="bigint")return String(r);try{let e=JSON.stringify(r);return e.length>80?`${e.slice(0,77)}...`:e}catch{return String(r)}}ge();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},Kn=Symbol.for("sizeof");function fn(r){let e=new WeakSet,t=new WeakSet,n=[r],s=0;for(;n.length>0;){let o=n.pop();s+=Yn(o,e,t,n)}return s}function Yn(r,e,t,n){if(r==null)return 0;switch(typeof r){case"number":return F.number;case"boolean":return F.boolean;case"string":return F.string+r.length*2;case"bigint":return F.bigint+Jn(r);case"symbol":return F.symbol;case"function":return e.has(r)?0:(e.add(r),F.function);case"undefined":return 0}let o=r;if(e.has(o))return 0;e.add(o);let i=o[Kn];if(typeof i=="function")try{let u=i.call(o);if(typeof u=="number"&&Number.isFinite(u))return u}catch{}if(o instanceof Date)return F.date;if(o instanceof RegExp)return F.regexp+o.source.length*2;if(o instanceof Error){let u=o.message?o.message.length*2:0,c=o.stack?o.stack.length*2:0;return F.error+u+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 u=F.map;for(let[c,h]of o)u+=F.mapEntry,n.push(c),n.push(h);return u}if(o instanceof Set){let u=F.set;for(let c of o)u+=F.setEntry,n.push(c);return u}if(Array.isArray(o)){let u=F.array+o.length*8;for(let c of o)n.push(c);return u}if(o instanceof ArrayBuffer)return t.has(o)?0:(t.add(o),o.byteLength);if(ArrayBuffer.isView(o)){let u=o;return t.has(u.buffer)?48:(t.add(u.buffer),u.buffer.byteLength+48)}let a=F.object,d=Object.keys(o);for(let u of d){a+=F.string+u.length*2;try{n.push(o[u])}catch{}}return a}function Jn(r){let e=r<0n?-r:r;if(e===0n)return 0;let t=e.toString(2).length;return Math.ceil(t/32)*8}function pn(r,e){let t=e?.topN??10,n=r.describe({detail:"standard"}),s=[],o=r._collectObserveTargets;typeof o=="function"&&o.call(r,"",s);let i=new Map;for(let[f,p]of s)i.set(f,p);let a=[];for(let[f,p]of Object.entries(n.nodes)){let l=i.get(f),v=l instanceof $?l:null,g=v?fn(v.cache):0,x=v?v._sinkCount:0,_=p.deps?.length??0,y=p.type==="effect"&&x===0,b=x===0?p.type==="effect"?"orphan-effect":p.type==="derived"?"idle-derived":p.type==="producer"?"idle-producer":null:null;a.push({path:f,type:p.type,status:p.status??"unknown",valueSizeBytes:g,subscriberCount:x,depCount:_,isOrphanEffect:y,orphanKind:b})}let d=a.reduce((f,p)=>f+p.valueSizeBytes,0),u=(f,p)=>[...a].sort(p??((l,v)=>v[f]-l[f])).slice(0,t),c=a.filter(f=>f.orphanKind!=null),h=a.filter(f=>f.isOrphanEffect);return{nodeCount:a.length,edgeCount:n.edges.length,subgraphCount:n.subgraphs.length,nodes:a,totalValueSizeBytes:d,hotspots:{byValueSize:u("valueSizeBytes"),bySubscriberCount:u("subscriberCount"),byDepCount:u("depCount")},orphans:c,orphanEffects:h}}var L="::",ee="__meta__",me=1;function hn(r,e){let t=Math.max(16,r.size*4),n=0;for(;r.size>0;){if(n++>=t){console.error(`[Graph "${e}".destroy] disposer drain exceeded cap (${t}); ${r.size} disposer(s) discarded`),r.clear();return}let s=r.values().next();if(s.done)return;let o=s.value;r.delete(o);try{o()}catch(i){console.error(`[Graph "${e}".destroy] disposer threw:`,i)}}}function vn(r){return r!=null&&typeof r=="object"&&"cache"in r&&typeof r.subscribe=="function"&&typeof r.down=="function"}function Zn(r){if(r!=null)return vn(r)?r.cache:r}function ye(r){return r!=null&&typeof r=="object"&&"cache"in r&&typeof r.subscribe=="function"&&typeof r.down=="function"}function ae(r){return ye(r)?r.cache??"":r}function gn(r){return ye(r)?r.cache??0:r}function mn(r){return ye(r)?r.cache??!1:r}function Xn(r){let e=[];for(let t of Object.keys(r).sort()){let n=r[t].v;n!=null&&e.push(`${t} ${n.id} ${n.version}`)}return e.join(`
|
|
3
|
+
`)}function yn(r){if(r.version!==me)throw new Error(`unsupported snapshot version ${String(r.version)} (expected ${me})`);for(let e of["name","nodes","edges","subgraphs"])if(!(e in r))throw new Error(`snapshot missing required key "${e}"`);if(typeof r.name!="string")throw new TypeError("snapshot 'name' must be a string");if(typeof r.nodes!="object"||r.nodes===null||Array.isArray(r.nodes))throw new TypeError("snapshot 'nodes' must be an object");if(!Array.isArray(r.edges))throw new TypeError("snapshot 'edges' must be an array");if(!Array.isArray(r.subgraphs))throw new TypeError("snapshot 'subgraphs' must be an array")}function Qn(r,e){let t=new WeakMap,n=(s,o)=>{if(Object.is(s,o))return!0;if(s==null||o==null||typeof s!="object"||typeof o!="object")return!1;let i=t.get(s);if(i==null&&(i=new WeakSet,t.set(s,i)),i.has(o))return!0;i.add(o);let a=s.constructor,d=o.constructor;if(a!==d)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 f=o;if(s.length!==f.length)return!1;for(let p=0;p<s.length;p++)if(!n(s[p],f[p]))return!1;return!0}if(s instanceof Map){let f=o;if(s.size!==f.size)return!1;for(let[p,l]of s)if(!f.has(p)||!n(l,f.get(p)))return!1;return!0}if(s instanceof Set){let f=o;if(s.size!==f.size)return!1;for(let p of s){let l=!1;for(let v of f)if(n(p,v)){l=!0;break}if(!l)return!1}return!0}if(ArrayBuffer.isView(s)){let f=s,p=o;if(f.length!==p.length)return!1;for(let l=0;l<f.length;l++)if(f[l]!==p[l])return!1;return!0}let u=Object.keys(s),c=Object.keys(o);if(u.length!==c.length)return!1;let h=new Set(c);for(let f of u)if(!h.has(f)||!n(s[f],o[f]))return!1;return!0};return n(r,e)}function er(r){return r.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function ot(r){let e="^";for(let t=0;t<r.length;t+=1){let n=r[t];if(n==="*"){e+=".*";continue}if(n==="?"){e+=".";continue}if(n==="["){let s=r.indexOf("]",t+1);if(s<=t+1){e+="\\[";continue}let o=r.slice(t+1,s);o.startsWith("!")&&(o=`^${o.slice(1)}`),o=o.replace(/\\/g,"\\\\"),e+=`[${o}]`,t=s;continue}e+=er(n)}return e+="$",new RegExp(e)}var tr={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"},nr={data:"",dirty:"",resolved:"",invalidate:"",pause:"",resume:"",complete:"",error:"",teardown:"",derived:"",path:"",reset:""};function Mt(r){if(typeof r=="string")return JSON.stringify(r);if(typeof r=="number"||typeof r=="boolean"||r==null)return String(r);try{return JSON.stringify(r)}catch{return"[unserializable]"}}function rr(r){return r==="none"?nr:r==="ansi"||r==null?tr:{data:r.data??"",dirty:r.dirty??"",resolved:r.resolved??"",invalidate:r.invalidate??"",pause:r.pause??"",resume:r.resume??"",complete:r.complete??"",error:r.error??"",teardown:r.teardown??"",derived:r.derived??"",path:r.path??"",reset:r.reset??""}}function bn(r){if(r==null)return{};let e=r.detail;return e==="full"?{...r,structured:r.structured??!0,timeline:r.timeline??!0,causal:r.causal??!0,derived:r.derived??!0}:e==="minimal"?{...r,structured:r.structured??!0}:r.format==="stage-log"?{...r,structured:r.structured??!0,timeline:r.timeline??!0}:r}function sr(r,e,t){for(let n=0;n<r.length;n++){let s=r.charCodeAt(n);if(s<32||s===127)throw new Error(`Graph "${e}": ${t} "${r}" must not contain control character (U+${s.toString(16).padStart(4,"0").toUpperCase()} at index ${n})`)}}function Gt(r,e,t){if(r==="")throw new Error(`Graph "${e}": ${t} name must be non-empty`);if(r.includes(L))throw new Error(`Graph "${e}": ${t} "${r}" must not contain '${L}' (path separator)`);if(r===ee)throw new Error(`Graph "${e}": ${t} name "${ee}" is reserved for meta companion paths`);sr(r,e,t)}function or(r,e){if(r==="")throw new Error(`Graph "${e}": resolve path must be non-empty`);let t=r.split(L);for(let n of t)if(n==="")throw new Error(`Graph "${e}": resolve path has empty segment`);return t}function ir(r,e){let t=!1;for(let s of r)if(!e.isMetaPassthrough(s[0])){t=!0;break}return t?r.filter(s=>e.isMetaPassthrough(s[0])):r}function _n(r){for(let e of r._mounts.values())_n(e);for(let e of r._nodes.values())try{e.down([[z]],{internal:!0})}catch{}}var de=class r{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,t){if(e==="")throw new Error("Graph name must be non-empty");if(e.includes(L))throw new Error(`Graph name must not contain '${L}' (got "${e}")`);if(e===ee)throw new Error(`Graph name "${ee}" is reserved for meta companion paths`);this.name=e,this.opts=Object.freeze({...t??{}}),this.config=t?.config??he,this._traceRing=new Pe(t?.traceCapacity??1e3),t?.versioning!=null&&this.setVersioning(t.versioning),typeof t?.factory=="string"&&(this._factory=t.factory,t.factoryArgs!==void 0&&(this._factoryArgs=t.factoryArgs))}tagFactory(e,t){return this._factory=e,this._factoryArgs=t,this}ancestors(e=!0){let t=[],n=e?this:this._parent;for(;n!=null;)t.push(n),n=n._parent;return t}get topology(){return this._topology==null&&(this._topology=et(e=>{let t=n=>{e.emit(n)};return this._topologyEmitters.add(t),()=>{this._topologyEmitters.delete(t)}},{name:`${this.name}_topology`})),this._topology}_emitTopology(e){if(!(this._topology==null||this._topologyEmitters.size===0))for(let t of this._topologyEmitters)t(e)}nameOf(e){return this._nodeToName.get(e)}add(e,t){let n=e.name,s=t?.name??n;if(s==null||s==="")throw new Error(`Graph "${this.name}": graph.add requires a non-empty name \u2014 pass via opts.name or set it on the node (e.g. state(0, { name: "x" }))`);let o=s,i=t?.annotation;if(Gt(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:re()})),e}setVersioning(e){if(e!=null)for(let t of this._nodes.values())t instanceof $&&t._applyVersioning(e)}remove(e){Gt(e,this.name,"remove");let t=this._mounts.get(e);if(t){let o={kind:"mount",nodes:[],mounts:[]},i=[];t._collectObserveTargets("",i);for(let[a,d]of i)a.includes(`${L}${ee}${L}`)||o.nodes.push(a);return o.nodes.sort(),o.mounts.push(e),o.mounts.push(...t._collectSubgraphs(`${e}${L}`)),this._mounts.delete(e),t._parent=void 0,_n(t),this._emitTopology({kind:"removed",name:e,nodeKind:"mount",audit:o}),o}let n=this._nodes.get(e);if(!n)throw new Error(`Graph "${this.name}": unknown node or mount "${e}"`);this._nodes.delete(e),this._nodeToName.delete(n),n.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 t=typeof e=="function"?e:(()=>{let o=ot(e);return i=>o.test(i)})(),n={kind:"mount",nodes:[],mounts:[]},s=[...this._nodes.keys(),...this._mounts.keys()].filter(o=>t(o));for(let o of s){let i=this.remove(o);n.nodes.push(...i.nodes),n.mounts.push(...i.mounts)}return n.nodes.sort(),n.mounts.sort(),n}[Symbol.iterator](){let e=[...this._nodes.keys()].sort(),t=this._nodes,n=0;return{[Symbol.iterator](){return this},next(){if(n>=e.length)return{value:void 0,done:!0};let s=e[n++];return{value:[s,t.get(s)],done:!1}}}}node(e){if(e==="")throw new Error(`Graph "${this.name}": node name must be non-empty`);if(e.includes(L))return this.resolve(e);let t=this._nodes.get(e);if(!t)throw new Error(`Graph "${this.name}": unknown node "${e}"`);return t}get(e){return this.node(e).cache}set(e,t,n){let s=n?.internal===!0;this.node(e).down([[G,t]],{actor:n?.actor,internal:s,delivery:"write"})}setAll(e,t){let n=Symbol.iterator in e?e:Object.entries(e);Ee(()=>{for(let[s,o]of n)this.set(s,o,t)})}invalidate(e,t){let n=t?.internal===!0;this.node(e).down([[Q]],{actor:t?.actor,internal:n,delivery:"write"})}error(e,t,n){let s=n?.internal===!0;this.node(e).down([[P,t]],{actor:n?.actor,internal:s,delivery:"write"})}complete(e,t){let n=t?.internal===!0;this.node(e).down([[B]],{actor:t?.actor,internal:n,delivery:"write"})}edges(e){let t=e?.recursive===!0,n=new Map;if(!t){for(let[d,u]of this._nodes)n.set(u,d);let a=[];for(let[d,u]of this._nodes)if(u instanceof $)for(let c of u._deps){let h=n.get(c.node);h!=null&&a.push([h,d])}return a.sort((d,u)=>d[0]<u[0]?-1:d[0]>u[0]?1:d[1]<u[1]?-1:d[1]>u[1]?1:0),a}let s=[];this._collectObserveTargets("",s);let o=new Map;for(let[a,d]of s)o.set(d,a);let i=[];for(let[a,d]of s)if(d instanceof $)for(let u of d._deps){let c=o.get(u.node);c!=null&&i.push([c,a])}return i.sort((a,d)=>a[0]<d[0]?-1:a[0]>d[0]?1:a[1]<d[1]?-1:a[1]>d[1]?1:0),i}mount(e,t){if(t===void 0){let s=new r(e);return this.mount(e,s)}if(typeof t=="function"){let s=new r(e);return t(s),this.mount(e,s)}let n=t;if(Gt(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(n===this)throw new Error(`Graph "${this.name}": cannot mount a graph into itself`);if(n._parent!=null)throw new Error(`Graph "${this.name}": this child graph is already mounted on "${n._parent.name}"`);for(let s=this;s!=null;s=s._parent)if(s===n)throw new Error(`Graph "${this.name}": mount("${e}", \u2026) would create a mount cycle`);return this._mounts.set(e,n),n._parent=this,this._emitTopology({kind:"added",name:e,nodeKind:"mount"}),n}resolve(e){let t=or(e,this.name);return this._resolveFromSegments(t)}tryResolve(e){try{return this.resolve(e)}catch{return}}_resolveFromSegments(e){let t=e;if(t[0]===this.name&&(t=t.slice(1),t.length===0))throw new Error(`Graph "${this.name}": resolve path ends at graph name only`);let n=t[0],s=t.slice(1);if(s.length===0){let a=this._nodes.get(n);if(a)return a;throw this._mounts.has(n)?new Error(`Graph "${this.name}": path ends at subgraph "${n}" \u2014 not a node (GRAPHREFLY-SPEC \xA73.5)`):new Error(`Graph "${this.name}": unknown name "${n}"`)}let o=this._nodes.get(n);if(o&&s.length>0&&s[0]===ee)return this._resolveMetaChainFromNode(o,s,t.join(L));let i=this._mounts.get(n);if(!i)throw this._nodes.has(n)?new Error(`Graph "${this.name}": "${n}" is a node; trailing path "${s.join(L)}" is invalid`):new Error(`Graph "${this.name}": unknown mount or node "${n}"`);return i.resolve(s.join(L))}_resolveMetaChainFromNode(e,t,n){let s=e,o=0,i=[...t];for(;o<i.length;){if(i[o]!==ee)throw new Error(`Graph "${this.name}": expected ${ee} segment in meta path "${n}"`);if(o+1>=i.length)throw new Error(`Graph "${this.name}": meta path requires a key after ${ee} in "${n}"`);let a=i[o+1],d=s.meta[a];if(!d)throw new Error(`Graph "${this.name}": unknown meta "${a}" in path "${n}"`);s=d,o+=2}return s}signal(e,t){if(t?.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 n=[];if(this._signalDeliver(e,t??{},new Set,n),n.length>0)throw n[0]}_signalDeliver(e,t,n,s){for(let d of this._mounts.values())d._signalDeliver(e,t,n,s);let i=t.internal===!0?{internal:!0}:{actor:t.actor,delivery:"signal"},a=ir(e,this.config);for(let d of[...this._nodes.keys()].sort()){let u=this._nodes.get(d);if(!n.has(u)){n.add(u);try{u.down(e,i)}catch(c){if(c instanceof X)throw c;s.push(c)}a.length!==0&&this._signalMetaSubtree(u,a,n,i,s)}}}_signalMetaSubtree(e,t,n,s,o){for(let i of Object.keys(e.meta).sort()){let a=e.meta[i];if(!n.has(a)){n.add(a);try{a.down(t,s)}catch(d){if(d instanceof X)throw d;o.push(d)}this._signalMetaSubtree(a,t,n,s,o)}}}describe(e){if(e?.reactive==="diff")return this._describeReactiveDiff(e);if(e?.reactive===!0)return this._describeReactive(e);let t=Zn(e?.actor),n=e?.filter;if(e?.detail!=null&&e?.fields!=null)throw new TypeError("Graph.describe(): pass either `detail` or `fields`, not both. `detail: 'spec'` is the canonical spec projection; use `fields` only when you need a custom subset.");let s=Qe(e?.detail,e?.fields),o=e?.detail==="spec",i=s,a=[];this._collectObserveTargets("",a);let d=new Map;for(let[b,w]of a)d.set(w,b);let u=[];{let b=a.map(([,m])=>m),w=new Set(d.values()),N=0;for(;b.length>0;){let m=b.shift();if(m instanceof $)for(let O of m._deps){let k=O.node;if(d.has(k))continue;let E=k.name??"",T=E;if(!T||w.has(T))if(E){let S=2;for(;w.has(`${E}#${S}`);)S++;T=`${E}#${S}`}else for(T=`__internal__/${N++}`;w.has(T);)T=`__internal__/${N++}`;d.set(k,T),w.add(T),u.push([T,k]),b.push(k)}}}let c=[...a,...u],h={};for(let[b,w]of c){if(t!=null&&!w.allowsObserve(t))continue;let N=St(w,i,o),m=w instanceof $?w._deps.map(T=>d.get(T.node)??T.node.name??""):[],{name:O,...k}=N,E={...k,deps:m};if(!o){let T=this._annotations.get(b);T!=null&&(E.annotation=T)}if(n!=null)if(typeof n=="function"){let T=n;if(!(T.length>=2?T(b,E):T(E)))continue}else{let T=!0;for(let[S,C]of Object.entries(n)){let R=S==="deps_includes"?"depsIncludes":S==="meta_has"?"metaHas":S;if(R==="depsIncludes"){if(!E.deps.includes(String(C))){T=!1;break}continue}if(R==="metaHas"){if(!Object.hasOwn(E.meta??{},String(C))){T=!1;break}continue}if(E[R]!==C){T=!1;break}}if(!T)continue}h[b]=E}let f=new Set(Object.keys(h)),p=[];for(let[b,w]of c)if(w instanceof $)for(let N of w._deps){let m=d.get(N.node);m!=null&&p.push([m,b])}p.sort((b,w)=>b[0]<w[0]?-1:b[0]>w[0]?1:b[1]<w[1]?-1:b[1]>w[1]?1:0);let l=p.map(([b,w])=>({from:b,to:w}));(t!=null||n!=null)&&(l=l.filter(b=>f.has(b.from)&&f.has(b.to)));let v=this._collectSubgraphs(""),g=t!=null||n!=null?v.filter(b=>{let w=`${b}${L}`;return[...f].some(N=>N===b||N.startsWith(w))}):v,x=this,_=e;return{name:this.name,nodes:h,edges:l,subgraphs:g,...this._factory!==void 0?{factory:this._factory}:{},...this._factoryArgs!==void 0?{factoryArgs:this._factoryArgs}:{},expand(b){let w={..._};return Array.isArray(b)?(w.fields=b,w.detail=void 0):(w.detail=b,w.fields=void 0),x.describe(w)}}}_collectSubgraphs(e){let t=[];for(let n of[...this._mounts.keys()].sort()){let s=e===""?n:`${e}${n}`;t.push(s),t.push(...this._mounts.get(n)._collectSubgraphs(`${s}${L}`))}return t}resourceProfile(e){return pn(this,e)}reachable(e,t,n={}){return n.withDetail===!0?Lt(this.describe(),e,t,{...n,withDetail:!0}):Lt(this.describe(),e,t,n)}explain(e,t,n){return n?.reactive===!0?this._explainReactive(e,t,n):this._explainStatic(ae(e),ae(t),{...n?.maxDepth!==void 0?{maxDepth:gn(n.maxDepth)}:{},...n?.findCycle!==void 0?{findCycle:mn(n.findCycle)}:{}})}_explainStatic(e,t,n){let s=this.describe({detail:"full"}),o=new Map(this._annotations),i=new Map;for(let[a,d]of Object.entries(s.nodes))d.lastMutation!=null&&i.set(a,d.lastMutation);return dn(s,e,t,{...n?.maxDepth!=null?{maxDepth:n.maxDepth}:{},...n?.findCycle===!0?{findCycle:!0}:{},annotations:o,lastMutations:i})}_describeReactive(e){let t={...e,reactive:!1},n=e.reactiveName??"describe",s=0,o=K(s,{name:`${n}_version`}),i=this.observe({timeline:!0,structured:!0}),a=!1,d=!1,u=()=>{a||d||(a=!0,Te(()=>{a=!1,!d&&(s+=1,o.emit(s))}))},c=i.onEvent(_=>{let y=_.type;y!=="data"&&y!=="error"&&y!=="complete"&&y!=="teardown"||u()}),h=[],f=new WeakSet,p=_=>{if(f.has(_)||d)return;f.add(_);let y=_.topology.subscribe(b=>{for(let w of b){if(w[0]!==G)continue;let N=w[1];if(u(),N.kind==="added"&&N.nodeKind==="mount"){let m=_._mounts.get(N.name);m!=null&&p(m)}}});h.push(y);for(let b of _._mounts.keys()){let w=_._mounts.get(b);w!=null&&p(w)}};p(this);let l,v=e.actor;vn(v)&&(l=v.subscribe(_=>{let y=!1,b=!1;for(let w of _){let N=w[0];N===G?y=!0:(N===B||N===P||N===z)&&(b=!0)}y&&u(),b&&(l?.(),l=void 0,u())}));let g;try{g=Y([o],()=>this.describe(t),{name:n,describeKind:"derived",meta:{domain:"audit",kind:"describe"},equals:(_,y)=>_===y})}catch(_){c(),l?.();for(let y of h)y();throw i.dispose(),_}let x=ie(g);return{node:g,dispose(){d=!0,c(),l?.();for(let _ of h)_();h.length=0,i.dispose(),x()}}}_describeReactiveDiff(e){let t={...e,reactive:!1},n=e.reactiveName??"describe-diff",s={name:this.name,nodes:{},edges:[],subgraphs:[]},o=this.describe(t),i=Ct(s,o),a=K(i,{name:n,meta:{domain:"audit",kind:"describe-diff"},equals:(f,p)=>f===p}),d=this._describeReactive({...e,reactiveName:void 0}),u=!1,c=d.node.subscribe(f=>{if(!u)for(let p of f){if(p[0]!==G)continue;let l=p[1],v=Ct(o,l);o=l,v.events.length!==0&&a.emit(v)}}),h=ie(a);return{node:a,dispose(){u=!0,c(),d.dispose(),a.down([[z,"describe-diff disposed"]]),h()}}}_explainReactive(e,t,n){let s=0,o=K(s,{name:"explain_version"}),i=this.observe({timeline:!0,structured:!0}),a=!1,d=!1,u=()=>{a||d||(a=!0,Te(()=>{a=!1,!d&&(s+=1,o.emit(s))}))},c=i.onEvent(_=>{let y=_.type;y!=="data"&&y!=="error"&&y!=="complete"&&y!=="teardown"||u()}),h=[];e!=null&&ye(e)&&h.push(e),t!=null&&ye(t)&&h.push(t),n?.maxDepth!=null&&ye(n.maxDepth)&&h.push(n.maxDepth),n?.findCycle!=null&&ye(n.findCycle)&&h.push(n.findCycle);let f=()=>{for(let _ of h)if(_.cache===void 0)return!1;return!0},p=()=>{let _=ae(e),y=ae(t);return{from:_,to:y,found:!1,reason:"pending",steps:[],text:"(awaiting reactive args)",toJSON:()=>({from:_,to:y,found:!1,reason:"pending",steps:[]})}},l;try{l=Y([o],()=>{if(!f())return p();let _=ae(e),y=ae(t),b={...n?.maxDepth!==void 0?{maxDepth:gn(n.maxDepth)}:{},...n?.findCycle!==void 0?{findCycle:mn(n.findCycle)}:{}};return this._explainStatic(_,y,b)},{name:n?.name??"explain",describeKind:"derived",meta:{domain:"audit",kind:"explain_path",from:ae(e),to:ae(t)},equals:(_,y)=>_.found===y.found&&_.reason===y.reason&&_.steps.length===y.steps.length&&ar(_.steps,y.steps)})}catch(_){throw c(),i.dispose(),_}let v=ie(l),g=[],x=_=>{let y;return y=_.subscribe(b=>{let w=!1,N=!1;for(let m of b){let O=m[0];O===G?w=!0:(O===B||O===P||O===z)&&(N=!0)}(w||N)&&u(),N&&y&&(y(),y=void 0)}),()=>{y&&(y(),y=void 0)}};for(let _ of h)g.push(x(_));return{node:l,dispose(){d=!0,c();for(let _ of g)_?.();g.length=0,i.dispose(),v()}}}_pathsMatching(e){let t=ot(e),n=[];return this._collectObserveTargets("",n),n.map(([s])=>s).filter(s=>t.test(s))}_collectObserveTargets(e,t){for(let n of[...this._mounts.keys()].sort()){let s=e===""?n:`${e}${L}${n}`;this._mounts.get(n)._collectObserveTargets(s,t)}for(let n of[...this._nodes.keys()].sort()){let s=this._nodes.get(n),o=e===""?n:`${e}${L}${n}`;t.push([o,s]),this._appendMetaObserveTargets(o,s,t)}}_appendMetaObserveTargets(e,t,n){for(let s of Object.keys(t.meta).sort()){let o=t.meta[s],i=`${e}${L}${ee}${L}${s}`;n.push([i,o]),this._appendMetaObserveTargets(i,o,n)}}observe(e,t){let n=typeof e=="string",o=bn(n?t:e);if(o.reactive===!0)return this._observeReactive(n?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(n){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(f){return h.subscribe(f)},up(f){try{h.up?.(f)}catch(p){if(p instanceof X)return;throw p}}}}let d=[];this._collectObserveTargets("",d),d.sort((c,h)=>c[0]<h[0]?-1:c[0]>h[0]?1:0);let u=a==null?d:d.filter(([,c])=>c.allowsObserve(a));return i?this._buildStructuredObserver(u,o,"all"):{subscribe:c=>{let h=u.map(([f,p])=>p.subscribe(l=>{c(f,l)}));return()=>{for(let f of h)f()}},up:(c,h)=>{try{this.resolve(c).up?.(h)}catch(f){if(f instanceof X)return;throw f}}}}_observeReactive(e,t){let n=t.tiers,s=n!=null?new Set(n):null,o=t.reactiveName??"observe";return et(i=>{let a=[],d=!1,u=!1,c=()=>{if(a.length===0||u)return;let v={events:a.slice(),flushedAt_ns:re()};a.length=0,i.emit(v)},h={...t,reactive:!1,structured:!0,timeline:!0},f=e!=null?this.observe(e,h):this.observe(h),p=v=>{u||(a.push(v),!d&&(d=!0,Te(()=>{d=!1,c()})))};for(let v of f.events)p(v);let l=f.onEvent(p);return()=>{u=!0,l(),f.dispose()}},{name:o,meta:{domain:"audit",kind:"observe-reactive"}})}_buildStructuredObserver(e,t,n){let s=n==="one"?e[0]?.[0]:void 0,o=i=>{if(n==="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 d=i.actor,u=d==null?a:a.filter(([,c])=>c.allowsObserve(d));return this._buildStructuredObserver(u,i,"all")};return this._createObserveResult(e,t,o)}_createObserveResult(e,t,n){let s=t.timeline===!0,o=t.causal===!0,i=t.derived===!0,a=t.detail==="minimal",d=this.config.inspectorEnabled,u=(o||i)&&d,c=t.maxEvents,h=c!=null&&c>0?new Pe(c):null,f=[],p=new Set,l=t.tiers!=null?new Set(t.tiers):null,v={},g=new Set,x=0,_=0,y=0,b=0,w=0,N=0,m=!1,O=!1,k=0,E=new Map,T=new Map,S=new Map,C=A=>{if(!(l!=null&&!l.has(A.type))){h?h.push(A):f.push(A);for(let M of p)M(A)}},R=A=>l==null||l.has(A),I=()=>s?{timestamp_ns:re(),in_batch:Be(),batch_id:k}:{},V=(A,M)=>{if(!(!u||!(A instanceof $)))return A._setInspectorHook(J=>{if(J.kind==="dep_message")E.set(A,J.depIndex);else if(J.kind==="run"){let Ae=J.batchData.map((D,H)=>D!=null&&D.length>0?D.at(-1):J.prevData[H]);T.set(A,Ae);let Z=J.batchData.map(D=>D!=null?[...D]:void 0);S.set(A,Z),i&&C({type:"derived",path:M,dep_values:Ae,dep_batches:Z,...I()})}})},q=A=>{let M=E.get(A),J=T.get(A);if(!o||J==null)return{};let Z=(M!=null&&M>=0&&A instanceof $?A._deps[M]:void 0)?.node,D=Z?.v,H=S.get(A);return{trigger_dep_index:M,trigger_dep_name:Z?.name,...D!=null?{trigger_version:{id:D.id,version:D.version}}:{},dep_values:[...J],...H!=null?{dep_batches:H}:{}}},be=[],ve=[];for(let[A,M]of e){let J=V(M,A);J&&be.push(J),ve.push(M.subscribe(Ae=>{k++;for(let Z of Ae){let D=Z[0],H=I();if(D===G){v[A]=Z[1];let pt=M instanceof $?M.lastMutation?.actor??Oe:Oe;C({type:"data",path:A,data:Z[1],actor:pt,...H,...q(M)})}else if(a)D===W?R("dirty")&&x++:D===U?R("resolved")&&_++:D===Q?R("invalidate")&&y++:D===te?R("pause")&&b++:D===se?R("resume")&&w++:D===z?R("teardown")&&N++:D===B&&!g.has(A)?R("complete")&&(m=!0):D===P&&R("error")&&(O=!0,g.add(A));else if(D===W)R("dirty")&&x++,C({type:"dirty",path:A,...H});else if(D===U)R("resolved")&&_++,C({type:"resolved",path:A,...H,...q(M)});else if(D===Q)R("invalidate")&&y++,C({type:"invalidate",path:A,...H});else if(D===te)R("pause")&&b++,C({type:"pause",path:A,lockId:Z[1],...H});else if(D===se)R("resume")&&w++,C({type:"resume",path:A,lockId:Z[1],...H});else if(D===B)R("complete")&&!g.has(A)&&(m=!0),C({type:"complete",path:A,...H});else if(D===P){R("error")&&(O=!0,g.add(A));let pt=M instanceof $?M.lastMutation?.actor??Oe:Oe;C({type:"error",path:A,data:Z[1],actor:pt,...H})}else D===z&&(R("teardown")&&N++,C({type:"teardown",path:A,...H}))}}))}let Se=!1,Re=()=>{if(!Se){Se=!0;for(let A of ve)A();for(let A of be)A();for(let A of je)A({value:void 0,done:!0});je.length=0}},ft=[],je=[];p.add(A=>{let M=je.shift();M?M({value:A,done:!1}):ft.push(A)});let $t={get values(){return v},get dirtyCount(){return x},get resolvedCount(){return _},get invalidateCount(){return y},get pauseCount(){return b},get resumeCount(){return w},get teardownCount(){return N},get events(){return h?h.toArray():[...f]},get anyCompletedCleanly(){return m},get anyErrored(){return O},get completedWithoutErrors(){return m&&!O},onEvent(A){return p.add(A),()=>p.delete(A)},dispose:Re,expand(A){Re();let M={...t};return typeof A=="string"?M.detail=A:Object.assign(M,A),n(bn(M))},[Symbol.asyncIterator](){return{next(){return ft.length>0?Promise.resolve({value:ft.shift(),done:!1}):Se?Promise.resolve({value:void 0,done:!0}):new Promise(A=>je.push(A))},return(){return Re(),Promise.resolve({value:void 0,done:!0})}}}};return t.format!=null&&this._attachFormatLogger($t,t),$t}_attachFormatLogger(e,t){let n=t.format;if(n==null)return;let s=t.logger??(l=>console.log(l)),o=t.includeTypes?new Set(t.includeTypes):null,i=t.excludeTypes?new Set(t.excludeTypes):null,a=o==null&&i==null?()=>!0:l=>(o==null||o.has(l))&&(i==null||!i.has(l)),d=rr(t.theme),u=n==="stage-log"?re():0,c=l=>l==null?"":t.stageLabels?.[l]??l,h=(l,v)=>l.length>v?`${l.slice(0,v-1)}\u2026`:l,f=l=>l.type==="data"||l.type==="error"?h(Mt(l.data),120):"",p=l=>{if(n==="stage-log"){let m=(re()-u)/1e9,O=c(l.path).padEnd(9);if(l.type==="data"){let k=f(l);return`[${m.toFixed(3)}s] ${O} \u2190${k?` ${k}`:""}`}if(l.type==="error"){let k=f(l);return`[${m.toFixed(3)}s] ${O} \u2717${k?` ${k}`:""}`}return l.type==="complete"?`[${m.toFixed(3)}s] ${O} \u25A0 complete`:`[${m.toFixed(3)}s] ${O} ${l.type}`}if(n==="json")try{return JSON.stringify(l)}catch{return JSON.stringify({type:l.type,path:l.path,data:"[unserializable]"})}let v=d[l.type]??"",g=l.path?`${d.path}${l.path}${d.reset} `:"",x=l.type==="data"||l.type==="error",_=l.type==="pause"||l.type==="resume",y=x?` ${Mt(l.data)}`:_?` ${Mt(l.lockId)}`:"",b=l.type==="data"||l.type==="resolved"||l.type==="derived"?l:void 0,w=b?.trigger_dep_name!=null?` <- ${b.trigger_dep_name}`:b?.trigger_dep_index!=null?` <- #${b.trigger_dep_index}`:"",N=l.in_batch?" [batch]":"";return`${g}${v}${l.type.toUpperCase()}${d.reset}${y}${w}${N}`};e.onEvent(l=>{a(l.type)&&s(p(l),l)})}addDisposer(e){return this._disposers.add(e),()=>{this._disposers.delete(e)}}destroy(){hn(this._disposers,this.name),this.signal([[z]],{internal:!0}),hn(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:t,...n}=this.describe({detail:"full"}),s={};for(let a of Object.keys(n.nodes).sort()){let{lastMutation:d,guard:u,...c}=n.nodes[a];s[a]=c}let o=[...n.subgraphs].sort(),i={...n,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 Ut(a,a.encode(i))}throw new Error(`snapshot: unknown format "${String(e.format)}"`)}static decode(e,t){let n=t?.config??he,{codec:s,codecVersion:o,payload:i}=Kt(e,n);return s.decode(i,o)}restore(e,t){if(yn(e),e.name!==this.name)throw new Error(`Graph "${this.name}": restore snapshot name "${e.name}" does not match this graph`);let n=t?.only==null?null:(Array.isArray(t.only)?t.only:[t.only]).map(o=>ot(o)),s=t?.includeProducers===!0;for(let o of Object.keys(e.nodes).sort()){if(n!==null&&!n.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&&t?.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 d=this.tryResolve(o)?.v;if(d!=null&&d.id===i.v.id&&d.version===i.v.version)continue}try{this.set(o,i.value)}catch(a){t?.onError?.(o,a)}}}}}static fromSnapshot(e,t){yn(e);let n=typeof t=="function"?t:t?.build,s=typeof t=="function"?void 0:t?.factories,o=new r(e.name);if(n)return n(o),o.restore(e),o;for(let p of[...e.subgraphs].sort((l,v)=>{let g=l.split(L).length,x=v.split(L).length;return g!==x?g-x:l<v?-1:l>v?1:0})){let l=p.split(L),v=o;for(let g of l)v._mounts.has(g)||v.mount(g,new r(g)),v=v._mounts.get(g)}let i=s?Object.entries(s).map(([p,l])=>({re:ot(p),factory:l})):[],a=p=>{for(let l of i)if(l.re.test(p))return l.factory},d=p=>{let l=p.split(L),v=l.pop();if(v==null||v.length===0)throw new Error(`invalid snapshot path "${p}"`);let g=o;for(let x of l){let _=g._mounts.get(x);if(!_)throw new Error(`unknown mount "${x}" in path "${p}"`);g=_}return[g,v]},u=Object.entries(e.nodes).filter(([p])=>!p.includes(`${L}${ee}${L}`)).sort((p,l)=>p[0]<l[0]?-1:p[0]>l[0]?1:0),c=new Map(u),h=new Map,f=!0;for(;c.size>0&&f;){f=!1;for(let[p,l]of[...c.entries()]){let v=l?.deps??[];if(!v.every(w=>h.has(w)))continue;let[g,x]=d(p),_={...l?.meta??{}},y=a(p),b;if(l?.type==="state")b=K(l.value,{meta:_});else{if(y==null)continue;b=y(x,{path:p,type:l.type,value:l.value,meta:_,deps:v,resolvedDeps:v.map(w=>h.get(w))})}g.add(b,{name:x}),h.set(p,b),c.delete(p),f=!0}}if(c.size>0){let p=[...c.keys()].sort().join(", ");throw new Error(`Graph.fromSnapshot could not reconstruct nodes without build callback: ${p}. Pass matching factories via fromSnapshot(data, { factories: { pattern: factoryFn } }).`)}return o.restore(e),o}toJSON(){return this.snapshot()}attachSnapshotStorage(e,t={}){let n=e.map(u=>({tier:u,debounceMs:Math.max(0,u.debounceMs??0),compactEvery:Math.max(1,u.compactEvery??10),timer:void 0,seq:0,lastSnapshot:void 0,lastFingerprint:"",disposed:!1,savePending:void 0}));t.autoRestore===!0&&this._cascadeRestore(e,t.onError);let s=(u,c)=>{if(u.disposed)return;let h=Xn(c.nodes);if(u.lastSnapshot!=null&&h!==""&&h===u.lastFingerprint)return;let f=u.seq+1,p=ne(),g=u.lastSnapshot==null||f%u.compactEvery===0?{name:this.name,mode:"full",snapshot:c,seq:f,timestamp_ns:p,format_version:me}:{name:this.name,mode:"diff",diff:wn(u.lastSnapshot,c),seq:f,timestamp_ns:p,format_version:me};if(u.tier.filter&&!u.tier.filter(g))return;let x;try{x=u.tier.save(g)}catch(_){t.onError?.(_,u.tier);return}if(x&&typeof x.then=="function"){let b=(u.savePending??Promise.resolve()).then(()=>x,()=>x).then(()=>{u.disposed||(u.seq=f,u.lastSnapshot=c,u.lastFingerprint=h)},w=>{t.onError?.(w,u.tier)});u.savePending=b.finally(()=>{u.savePending===b&&(u.savePending=void 0)})}else u.seq=f,u.lastSnapshot=c,u.lastFingerprint=h},o=(u,c)=>{try{s(u,c)}catch(h){t.onError?.(h,u.tier)}},i=(u,c)=>{if(!c.some(l=>{let v=this.config.messageTier(l[0]);return v>=3&&v<5}))return;if(t.filter){let l=this.tryResolve(u);if(l==null)return;let v=St(l,Qe("standard"));if(!t.filter(u,v))return}let f,p=()=>(f==null&&(f=this.snapshot()),f);for(let l of n)l.disposed||(l.debounceMs===0?o(l,p()):(l.timer==null&&(l.timer=new tt),l.timer.start(l.debounceMs,()=>{l.disposed||o(l,this.snapshot())})))},a;if(t.paths!=null){let c=(typeof t.paths=="string"?this._pathsMatching(t.paths):t.paths).map(h=>{let f=this.tryResolve(h);return f==null?()=>{}:f.subscribe(p=>i(h,p))});a=()=>{for(let h of c)h()}}else a=this.observe().subscribe((u,c)=>i(u,c));let d=()=>{a();for(let u of n)u.disposed=!0,u.timer?.cancel();this._storageDisposers.delete(d)};return this._storageDisposers.add(d),{dispose:d}}async _cascadeRestore(e,t){for(let n of e){let s;try{s=await n.load?.()}catch(i){t?.(i,n);continue}if(s==null||typeof s!="object"||Array.isArray(s))continue;let o=s;try{if(o.mode==="full"&&o.snapshot!=null)return this.restore(o.snapshot),!0;if(o.version===me&&o.nodes!=null)return this.restore(o),!0}catch(i){t?.(i,n)}}return!1}static async fromStorage(e,t,n){for(let s of t){let o;try{o=await s.load?.()}catch(d){n?.onError?.(d,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 r.fromSnapshot(a,n)}catch(d){n?.onError?.(d,s)}}throw new Error(`Graph.fromStorage: no tier held a restorable record for "${e}" across ${t.length} tier(s)`)}_annotations=new Map;_traceRing;trace(e,t,n){if(e!=null&&t!=null){if(this.tryResolve(e)==null)return;if(this._annotations.set(e,t),this.config.inspectorEnabled){let s={path:e,annotation:t,timestamp_ns:re(),...n?.actor!=null?{actor:n.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 t=this._traceRing.toArray().filter(s=>!e(s)),n=this._traceRing.size-t.length;this._traceRing.clear();for(let s of t)this._traceRing.push(s);return n}static diff(e,t){let n=new Set(Object.keys(e.nodes)),s=new Set(Object.keys(t.nodes)),o=[...s].filter(_=>!n.has(_)).sort(),i=[...n].filter(_=>!s.has(_)).sort(),a=[],d=[];for(let _ of n){if(!s.has(_))continue;let y=e.nodes[_],b=t.nodes[_],w=y.v,N=b.v;w!=null&&N!=null&&w.id===N.id&&w.version!==N.version&&d.push({path:_,id:w.id,from:w.version,to:N.version});let m=w!=null&&N!=null&&w.id===N.id&&w.version===N.version;for(let O of["type","status","sentinel"]){let k=y[O],E=b[O];k!==E&&a.push({path:_,field:O,from:k,to:E})}if(!m)for(let O of["value","meta"]){let k=y[O],E=b[O];Qn(k,E)||a.push({path:_,field:O,from:k,to:E})}}let u=_=>`${_.from} ${_.to}`,c=new Set(e.edges.map(u)),h=new Set(t.edges.map(u)),f=t.edges.filter(_=>!c.has(u(_))),p=e.edges.filter(_=>!h.has(u(_))),l=new Set(e.subgraphs),v=new Set(t.subgraphs),g=[...v].filter(_=>!l.has(_)).sort(),x=[...l].filter(_=>!v.has(_)).sort();return{nodesAdded:o,nodesRemoved:i,nodesChanged:a,versionChanges:d,edgesAdded:f,edgesRemoved:p,subgraphsAdded:g,subgraphsRemoved:x}}};function wn(r,e){let t=de.diff(r,e),n={};for(let s of t.nodesAdded){let o=e.nodes[s];o!=null&&(n[s]=o)}return{...t,nodesAddedFull:n}}function Lt(r,e,t,n={}){let s={paths:[],depths:new Map,truncated:!1};if(!e)return n.withDetail?s:[];if(!n.both&&t!=="upstream"&&t!=="downstream")throw new Error('reachable: direction must be "upstream" or "downstream"');let o=n.maxDepth;if(o!=null&&(!Number.isInteger(o)||o<0))throw new Error("reachable: maxDepth must be an integer >= 0");if(o===0)return n.withDetail?s:[];let i=new Map,a=new Map,d=new Map,u=new Map,c=new Set;for(let[y,b]of Object.entries(r.nodes)){if(!y)continue;c.add(y);let w=b.deps??[];i.set(y,w);for(let N of w)N&&(c.add(N),a.has(N)||a.set(N,new Set),a.get(N).add(y))}for(let y of r.edges){if(y==null||typeof y!="object")continue;let b=typeof y.from=="string"?y.from:"",w=typeof y.to=="string"?y.to:"";!b||!w||(c.add(b),c.add(w),u.has(b)||u.set(b,new Set),u.get(b).add(w),d.has(w)||d.set(w,new Set),d.get(w).add(b))}if(!c.has(e))return n.withDetail?s:[];let h=n.both===!0,f=y=>{if(h){let m=i.get(y)??[],O=d.get(y),k=a.get(y),E=u.get(y),T=[...m];return O&&T.push(...O),k&&T.push(...k),E&&T.push(...E),T}if(t==="upstream"){let m=i.get(y)??[],O=d.get(y);return O?[...m,...O]:m}let b=a.get(y),w=u.get(y),N=b?[...b]:[];return w&&N.push(...w),N},p=new Set([e]),l=new Map,v=[{path:e,depth:0}],g=0,x=!1;for(;g<v.length;){let y=v[g++];if(o!=null&&y.depth>=o){f(y.path).length>0&&(x=!0);continue}for(let b of f(y.path))!b||p.has(b)||(p.add(b),l.set(b,y.depth+1),v.push({path:b,depth:y.depth+1}))}let _=[...l.keys()].sort((y,b)=>y<b?-1:y>b?1:0);return n.withDetail?{paths:_,depths:l,truncated:x}:_}function ar(r,e){if(r.length!==e.length)return!1;for(let t=0;t<r.length;t++){let n=r[t],s=e[t];if(n.path!==s.path||n.type!==s.type||n.status!==s.status||n.hop!==s.hop||n.dep_index!==s.dep_index||n.annotation!==s.annotation||n.value!==s.value||n.lastMutation!==s.lastMutation)return!1;let o=n.v,i=s.v;if(o!==i&&(o==null||i==null||o.id!==i.id||o.version!==i.version))return!1}return!0}Me();Ne();ge();Le();var Pt=class{_version=0;_maxSize;_buf;_head=0;_size=0;constructor(e,t){if(t!==void 0&&t<1)throw new RangeError("maxSize must be >= 1");if(this._maxSize=t,t!==void 0){if(this._buf=new Array(t),e&&e.length>0){let n=Math.min(e.length,t),s=e.length-n;for(let o=0;o<n;o++)this._buf[o]=e[s+o];this._size=n}}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 t=e>=0?e:this._size+e;if(!(t<0||t>=this._size))return this._maxSize!==void 0?this._buf[(this._head+t)%this._maxSize]:this._buf[t]}append(e){this._rawAppend(e),this._version+=1}appendMany(e){if(e.length===0)return;let t=this._maxSize!==void 0&&e.length>this._maxSize?e.length-this._maxSize:0;for(let n=t;n<e.length;n++)this._rawAppend(e[n]);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 t=0;t<e;t++)this._buf[(this._head+t)%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 t=Math.min(e,this._size);if(this._maxSize===void 0)this._buf.splice(0,t);else{for(let n=0;n<t;n++)this._buf[(this._head+n)%this._maxSize]=void 0;this._head=(this._head+t)%this._maxSize}return this._size-=t,this._version+=1,t}slice(e,t){if(!Number.isInteger(e)||e<0)throw new RangeError(`slice: start must be a non-negative integer (got ${e})`);if(t!==void 0&&(!Number.isInteger(t)||t<0))throw new RangeError(`slice: stop must be a non-negative integer or undefined (got ${t})`);let n=t===void 0?this._size:Math.min(Math.max(t,0),this._size),s=Math.min(e,this._size);if(s>=n)return[];let o=n-s;if(this._maxSize===void 0)return this._buf.slice(s,n);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 t=Math.min(e,this._size);return this.slice(this._size-t,this._size)}toArray(){if(this._maxSize===void 0)return[...this._buf];let e=new Array(this._size);for(let t=0;t<this._size;t++)e[t]=this._buf[(this._head+t)%this._maxSize];return e}snapshot(){return this.toArray()}restore(e){if(this._maxSize===void 0){this._buf.length=0;for(let t=0;t<e.length;t++)this._buf.push(e[t]);this._size=this._buf.length}else{let t=this._maxSize;for(let o=0;o<t;o++)this._buf[o]=void 0;this._head=0;let n=Math.min(e.length,t),s=e.length-n;for(let o=0;o<n;o++)this._buf[o]=e[s+o];this._size=n}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(r){return r.subscribe(()=>{})}var dr=64;function $e(r,e={}){let{name:t,maxSize:n,versioning:s,guard:o,backend:i}=e,a=i??new Pt(r,n),d=K(a.toArray(),{name:t,describeKind:"state",equals:(m,O)=>m===O,...s!=null?{versioning:s}:{},...o!=null?{guard:o}:{}});function u(){let m=a.toArray();Ee(()=>{d.down([[W]],{internal:!0}),d.down([[G,m]],{internal:!0})})}let c=new Map,h=new Map,f=new Map;function p(m,O){return`${m}:${O===void 0?"END":O}`}function l(m){if(m.size<dr)return;let O=m.keys().next();if(O.done)return;let k=m.get(O.value);k!==void 0&&k.dispose(),m.delete(O.value)}function v(m){let O=a.version;try{return m()}finally{a.version!==O&&u()}}function g(m){if(!Number.isInteger(m)||m<0)throw new RangeError(`tail: n must be a non-negative integer (got ${m})`);let O=c.get(m);if(O!==void 0)return c.delete(m),c.set(m,O),O.node;l(c);let k=Y([d],([T])=>{let S=T;return m===0||S.length===0?[]:S.slice(Math.max(0,S.length-m))},{initial:a.tail(m),describeKind:"derived"}),E=Ie(k);return c.set(m,{node:k,dispose:E}),k}function x(m,O){if(!Number.isInteger(m)||m<0)throw new RangeError(`slice: start must be a non-negative integer (got ${m})`);if(O!==void 0&&(!Number.isInteger(O)||O<0))throw new RangeError(`slice: stop must be a non-negative integer or undefined (got ${O})`);let k=p(m,O),E=h.get(k);if(E!==void 0)return h.delete(k),h.set(k,E),E.node;l(h);let T=Y([d],([C])=>{let R=C;return O===void 0?R.slice(m):R.slice(m,O)},{initial:a.slice(m,O),describeKind:"derived"}),S=Ie(T);return h.set(k,{node:T,dispose:S}),T}function _(m){let O=f.get(m);if(O!==void 0)return O.node;let k=Y([d,m],([T,S])=>{let C=T,R=Math.max(0,Math.trunc(S??0));return C.slice(R)},{initial:[],describeKind:"derived"}),E=Ie(k);return f.set(m,{node:k,dispose:E}),k}let y,b;function w(){y===void 0&&(y=oe([d],(m,O,k)=>{let E=m[0],S=E!=null&&E.length>0?E.at(-1):k.prevData[0];if(S==null||S.length===0){O.down([[U]]);return}O.emit(S[S.length-1])},{name:t!=null?`${t}::lastValue`:"lastValue",describeKind:"derived",initial:a.size===0?void 0:a.at(a.size-1)}),b=Y([d],([m])=>m.length>0,{name:t!=null?`${t}::hasLatest`:"hasLatest",describeKind:"derived",initial:a.size>0}),Ie(y),Ie(b))}let N={entries:d,get size(){return a.size},at(m){return a.at(m)},append(m){v(()=>a.append(m))},appendMany(m){m.length!==0&&v(()=>a.appendMany(m))},clear(){v(()=>a.clear())},trimHead(m){v(()=>a.trimHead(m))},withLatest(){return w(),d},get lastValue(){return w(),y},get hasLatest(){return w(),b},view(m){switch(m.kind){case"tail":return g(m.n);case"slice":return x(m.start,m.stop);case"fromCursor":return _(m.cursor)}},attach(m){let O=m.subscribe(k=>{for(let E of k)E[0]===G&&N.append(E[1])});return()=>O()},attachStorage(m){if(m.length===0)return()=>{};let O=new Map;for(let E of m)O.set(E,a.size);(async()=>{for(let E of m)if(typeof E.loadEntries=="function")try{let T=await Promise.resolve(E.loadEntries());T.entries.length>0&&a.size===0&&(a.restore(T.entries),O.set(E,T.entries.length),u());break}catch{}})();let k=d.subscribe(E=>{for(let T of E){if(T[0]!==G)continue;let S=T[1];for(let C of m){let R=O.get(C)??0;if(S.length<R){try{let V=C.appendEntries(S);V instanceof Promise&&V.catch(()=>{})}catch{}O.set(C,S.length);continue}if(S.length===R)continue;let I=S.slice(R);O.set(C,S.length);try{let V=C.appendEntries(I);V instanceof Promise&&V.catch(()=>{})}catch{}}}});return()=>k()},disposeAllViews(){for(let m of c.values())m.dispose();c.clear();for(let m of h.values())m.dispose();h.clear();for(let m of f.values())m.dispose();f.clear()},dispose(){for(let m of c.values())m.dispose();c.clear();for(let m of h.values())m.dispose();h.clear();for(let m of f.values())m.dispose();f.clear()}};return N}var ur=xe((r,e)=>{r("observe"),r("signal"),e("write")});function it(r){let e=$e([],{name:r.name,maxSize:r.retainedLimit??1024,guard:r.guard??ur,...r.versioning!=null?{versioning:r.versioning}:{}});return e.withLatest(),r.graph&&r.graph.add(e.entries,{name:r.name}),e}function Tn(r,e,t=0){let n=K(t,{name:e,describeKind:"state"});return r.add(n,{name:e}),n}function En(r,e,t,n=0){let s={},o=new de(e);for(let i of t){let a=K(n,{name:i,describeKind:"state"});o.add(a,{name:i}),s[i]=a}return r.mount(e,o),s}var ue=class extends Error{constructor(e,t){super(e,t),this.name=this.constructor.name}},at=class extends ue{constructor(t,n){super(`Duplicate ${t} registration: "${n}"`);this.kind=t;this.registrationName=n}},dt=class extends ue{constructor(t,n,s){super(`Command "${t}" emitted undeclared event "${n}". Declared emits: [${s.join(", ")}]`);this.commandName=t;this.eventName=n;this.declaredEmits=s}},ut=class extends ue{constructor(t,n,s){super(`Optimistic concurrency conflict on aggregate "${t}": expected version ${n}, got ${s}`);this.aggregateId=t;this.expected=n;this.actual=s}},ct=class extends ue{constructor(t){super(`Unknown command: "${t}". Register with command() first.`);this.commandName=t}},Fe=class extends ue{constructor(t,n){super(`Command handler "${t}" threw: ${n instanceof Error?n.message:String(n)}`,{cause:n});this.commandName=t}};var Ve=class extends ue{constructor(t,n){super(`Projection "${t}" rebuild failed: ${n instanceof Error?n.message:String(n)}`,{cause:n});this.projectionName=t}};On();Dt();var cr=xe((r,e)=>{r("write"),r("signal"),e("observe")}),lr=xe((r,e)=>{r("observe"),r("signal"),e("write")}),kn=xe((r,e)=>{r("observe"),r("signal"),e("write")});function ze(r,e){return xn("cqrs",r,e)}function It(r){if(r===null||typeof r!="object"||Object.isFrozen(r))return r;for(let e of Object.keys(r))It(r[e]);return Object.freeze(r)}var fr=r=>`${r.type}::${r.aggregateId??"__default__"}`,pr=r=>r.commandName,hr=r=>r.eventType,lt=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,t={}){super(e,t.graph),this._retainedLimit=t.retainedLimit??1024,this._freezeCommandPayload=t.freezeCommandPayload??!0,this._freezeEventPayload=t.freezeEventPayload??!0,this._maxAggregates=t.maxAggregates??1e4,this.dispatches=it({name:"dispatches",retainedLimit:this._retainedLimit,graph:this}),this.audit=this.dispatches,this.aggregateEvictions=it({name:"aggregateEvictions",retainedLimit:this._retainedLimit,graph:this}),this._dispatchSeqCursor=Tn(this,"dispatch_seq",0)}aggregateVersion(e,t){return this._aggregateVersions.get(`${e}::${t}`)??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 t=e.value;this._aggregateLru.delete(t);let n=t.indexOf("::");if(n<0)continue;let s=t.slice(0,n),o=t.slice(n+2),i=this._aggregateVersions.get(t)??0;this._aggregateVersions.delete(t);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[t,n]of this._eventLogs){let s=n.log.attachStorage(e),o=this._attachedTierDisposers.get(t);o||(o=[],this._attachedTierDisposers.set(t,o)),o.push(s)}for(let[t,n]of this._eventLogsByAggregate)for(let[s,o]of n){let i=`${t}::${s}`,a=o.log.attachStorage(e),d=this._attachedTierDisposers.get(i);d||(d=[],this._attachedTierDisposers.set(i,d)),d.push(a)}return()=>{let t=this._attachedEventTiers.indexOf(e);t>=0&&this._attachedEventTiers.splice(t,1)}}_autoWireStreamStorage(e,t){if(this._attachedEventTiers.length===0)return;let n=this._attachedTierDisposers.get(e);n||(n=[],this._attachedTierDisposers.set(e,n));for(let s of this._attachedEventTiers)n.push(t.attachStorage(s))}_bumpDispatchSeq(){let t=(this._dispatchSeqCursor.cache??0)+1;return this._dispatchSeqCursor.emit(t),t}event(e,t){if(t!==void 0)return this._ensureAggregateStream(e,t).node;let n=this._eventLogs.get(e);if(n)return n.node;let s=$e([],{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:kn,initial:o.cache});return this.add(i,{name:e}),this._keepaliveDisposers.push(ie(i)),this._eventLogs.set(e,{log:s,node:i}),this._autoWireStreamStorage(e,s),i}_ensureAggregateStream(e,t){this._eventLogs.has(e)||this.event(e);let n=this._eventLogsByAggregate.get(e);n||(n=new Map,this._eventLogsByAggregate.set(e,n));let s=`${e}::${t}`;this._touchAggregate(s);let o=n.get(t);if(o)return o;let i=`${e}_${t.replace(/[^a-zA-Z0-9_-]/g,"_")}`,a=$e([],{name:i,versioning:0,maxSize:this._retainedLimit});a.withLatest();let d=a.entries,u=Y([d],([p])=>p,{name:i,describeKind:"state",meta:ze("event_aggregate",{event_name:e,aggregate_id:t}),guard:kn,initial:d.cache}),c=i,h=0;for(;this.nameOf(this.resolveOptional(c)??u)===c&&(h+=1,c=`${i}_${h}`,this.resolveOptional(c)!==void 0););try{this.add(u,{name:c})}catch{}this._keepaliveDisposers.push(ie(u));let f={log:a,node:u};return n.set(t,f),this._autoWireStreamStorage(`${e}::${t}`,a),this._enforceAggregateLru(),f}resolveOptional(e){try{return this.resolve(e)}catch{return}}_appendEvent(e,t,n){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(n?.aggregateId!==void 0){let c=`${e}::${n.aggregateId}`;o=(this._aggregateVersions.get(c)??0)+1,this._aggregateVersions.set(c,o),i=this._ensureAggregateStream(e,n.aggregateId)}let a=s.log.entries.v,d=this._freezeEventPayload?It(t):t,u={type:e,payload:d,timestampNs:ne(),seq:++this._seq,...n?.aggregateId!==void 0?{aggregateId:n.aggregateId}:{},...o!==void 0?{aggregateVersion:o}:{},...n?.correlationId!==void 0?{correlationId:n.correlationId}:{},...n?.causationId!==void 0?{causationId:n.causationId}:{},...n?.metadata!==void 0?{metadata:Object.freeze({...n.metadata})}:{},...n?.handlerVersion!==void 0?{handlerVersion:n.handlerVersion}:{},...a!=null?{v0:{id:a.id,version:a.version}}:{}};return s.log.append(u),i&&i.log.append(u),u}command(e,t){if(this._commandRegs.has(e))throw new at("command",e);let n=typeof t=="function"?{handler:t}:t,s=K(void 0,{name:e,describeKind:"state",meta:{...ze("command",{command_name:e}),error:null},guard:cr});if(this.add(s,{name:e}),this._commandRegs.set(e,{handler:n.handler,...n.emits!==void 0?{emits:n.emits}:{},...n.handlerVersion!==void 0?{handlerVersion:n.handlerVersion}:{}}),n.emits)for(let o of n.emits)this._eventLogs.has(o)||this.event(o);return s}dispatch(e,t,n){let s=this._commandRegs.get(e);if(!s)throw new ct(e);if(n?.aggregateId!==void 0&&n.expectedAggregateVersion!==void 0&&s.emits!==void 0){let f=0;for(let p of s.emits){let l=this._aggregateVersions.get(`${p}::${n.aggregateId}`);l!==void 0&&l>f&&(f=l)}if(f!==n.expectedAggregateVersion)throw new ut(n.aggregateId,n.expectedAggregateVersion,f)}let o=this.resolve(e),i=this._freezeCommandPayload?It(t):t,a=[],d=ne(),u=0,c,h=!1;try{Ee(()=>{u=this._bumpDispatchSeq(),o.emit(i,{internal:!0});try{s.handler(i,{emit:(f,p)=>{if(s.emits!==void 0&&!s.emits.includes(f))throw new dt(e,f,s.emits);a.push(f),this._appendEvent(f,p,{...n?.aggregateId!==void 0?{aggregateId:n.aggregateId}:{},...n?.correlationId!==void 0?{correlationId:n.correlationId}:{},...n?.causationId!==void 0?{causationId:n.causationId}:{},...n?.metadata!==void 0?{metadata:Object.freeze({...n.metadata})}:{},...s.handlerVersion!==void 0?{handlerVersion:s.handlerVersion}:{}})}}),o.meta.error.emit(null,{internal:!0}),this.dispatches.append({commandName:e,payload:i,outcome:"success",emittedEvents:[...a],t_ns:d,seq:u,...s.handlerVersion!==void 0?{handlerVersion:s.handlerVersion}:{}})}catch(f){throw c=f,h=!0,f}})}catch(f){if(h){o.meta.error.emit(c,{internal:!0});let p=c instanceof Error?c.name:typeof c,l=c instanceof Fe?c:new Fe(e,c);this.dispatches.append({commandName:e,payload:i,outcome:"failure",error:l,errorType:p,emittedEvents:[...a],t_ns:d,seq:u,...s.handlerVersion!==void 0?{handlerVersion:s.handlerVersion}:{}})}throw h?c:f}}projection(e){let{name:t,events:n,reducer:s,initial:o}=e,i=e.mode??"scan",a=e.freezeInputs??!0,d=e.snapshot,u=n.map(E=>(this._eventLogs.has(E)||this.event(E),this._eventLogs.get(E).node));function c(E){E.sort((T,S)=>T.timestampNs-S.timestampNs||T.seq-S.seq||(T.aggregateId??"").localeCompare(S.aggregateId??""))}function h(E){let T=[];for(let S of E)T.push(...S);return c(T),T}let f=u.map(E=>E.cache??[]),p=h(f),l=a?Object.freeze(p):p,v=0,g=o;i==="scan"&&p.length>0&&(g=s(o,l),v=p.length);let x=i==="replay"?s(o,l):g,_=d?.saveDebounceMs??1e3,y=d?.saveEvery??1e3,b,w=0;function N(E){if(d?.save){if(w+=1,w>=y){w=0,b!==void 0&&(clearTimeout(b),b=void 0);let T=d.save(E);T instanceof Promise&&T.catch(()=>{});return}b!==void 0&&clearTimeout(b),b=setTimeout(()=>{b=void 0,w=0;let T=d.save(E);T instanceof Promise&&T.catch(()=>{})},_)}}let m=Y(u,E=>{let T=h(E),S;if(i==="replay"){let C=a?Object.freeze(T):T;S=s(o,C)}else{let C=T.slice(v);v=T.length;let R=a?Object.freeze(C):C;S=s(g,R),g=S}return N(S),S},{name:t,describeKind:"derived",meta:ze("projection",{projection_name:t,source_events:n}),guard:lr,initial:x});return this.add(m,{name:t}),this._keepaliveDisposers.push(ie(m)),this._keepaliveDisposers.push(()=>{b!==void 0&&(clearTimeout(b),b=void 0)}),this._projections.add(t),{node:m,rebuild:async E=>{try{let T=E?.pageSize??1e3,S=E?.fromTier??this._attachedEventTiers[0]?.[0],C=h(u.map(I=>I.cache??[])).length,R=o;if(d?.load){let I=await d.load();I!==void 0&&(R=I)}if(!S||!S.loadEntries){let I=h(u.map(q=>q.cache??[])),V=a?Object.freeze(I):I;R=s(R,V)}else{let I=new Set(n),V,q=!1;for(;!q;){let be=await S.loadEntries({cursor:V,pageSize:T}),ve=[...be.entries].filter(Re=>I.has(Re.type));c(ve);let Se=a?Object.freeze(ve):ve;R=s(R,Se),V=be.cursor,q=!V||be.entries.length===0}}if(i==="scan"){let I=h(u.map(q=>q.cache??[])),V=I.slice(C);if(V.length>0){let q=a?Object.freeze(V):V;R=s(R,q)}g=R,v=I.length}return m.emit(R,{internal:!0}),R}catch(T){throw new Ve(t,T)}},reset:async()=>{try{let E=o;if(d?.load){let R=await d.load();R!==void 0&&(E=R)}let T=h(u.map(R=>R.cache??[])),S=a?Object.freeze(T):T,C=s(E,S);return i==="scan"&&(g=C,v=T.length),m.emit(C,{internal:!0}),C}catch(E){throw new Ve(t,E)}}}}saga(e,t,n,s={}){let o=t.map(p=>(this._eventLogs.has(p)||this.event(p),this._eventLogs.get(p).node)),i=En(this,`${e}_cursor`,t,0),a=it({name:`${e}_invocations`,retainedLimit:this._retainedLimit,graph:this}),d=s.aggregateId,u=s.errorPolicy??"advance",c=new Map;for(let p of t){let l=i[p];c.set(p,l.cache??0);let v=l.subscribe(g=>{for(let x of g)x[0]===G&&c.set(p,x[1])});this._keepaliveDisposers.push(v)}let h={},f=oe(o,(p,l)=>{let v=h.n.meta.error;for(let g=0;g<p.length;g++){let x=p[g];if(x==null||x.length===0)continue;let _=x.at(-1);if(!_)continue;let y=t[g],b=i[y],w=c.get(y)??0;if(_.length>w){let N=_.slice(w),m=w;for(let O of N){let k=O;if(d!==void 0&&k.aggregateId!==d){m+=1;continue}try{n(k),v.emit(null,{internal:!0}),a.append({eventType:y,outcome:"success",aggregateId:k.aggregateId,event:k,t_ns:ne(),...s.handlerVersion!==void 0?{handlerVersion:s.handlerVersion}:{}}),m+=1}catch(E){if(v.emit(E,{internal:!0}),a.append({eventType:y,outcome:"failure",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}:{}}),u==="hold")break;m+=1}}b.emit(m)}}},{name:e,describeKind:"effect",meta:{...ze("saga",{saga_name:e,source_events:t}),error:null}});return h.n=f,this.add(f,{name:e}),this._keepaliveDisposers.push(ie(f)),this._sagas.add(e),{node:f,invocations:a,audit:a,cursors:i}}};function gr(r,e){let t=new lt(r,e),{factory:n,factoryArgs:s,...o}=e??{};return t.tagFactory("cqrs",Nt(o)),t}0&&(module.exports={CqrsGraph,cqrs,cqrsEventKeyOf,dispatchKeyOf,sagaInvocationKeyOf});
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import '../../node-
|
|
2
|
-
import '../../
|
|
1
|
+
import '../../node-BYInONRr.cjs';
|
|
2
|
+
import '../../index-DINuaZlJ.cjs';
|
|
3
|
+
import '../../reactive-log-_zeEnB9H.cjs';
|
|
3
4
|
import '../../extra/storage-tiers.cjs';
|
|
4
|
-
import '../../graph-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
import '../../meta-BGO6C7K9.cjs';
|
|
5
|
+
import '../../graph-BUwMAxJI.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-DyM4tFAe.cjs';
|
|
7
|
+
import '../../meta-Ct9nqQS5.cjs';
|
|
8
8
|
import '../../extra/storage-core.cjs';
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import '../../node-
|
|
2
|
-
import '../../
|
|
1
|
+
import '../../node-BYInONRr.js';
|
|
2
|
+
import '../../index-CusEP3Sv.js';
|
|
3
|
+
import '../../reactive-log-BlAsPLl2.js';
|
|
3
4
|
import '../../extra/storage-tiers.js';
|
|
4
|
-
import '../../graph-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
import '../../meta-CC6EPdpK.js';
|
|
5
|
+
import '../../graph-30XSgtVX.js';
|
|
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-B41Asm7D.js';
|
|
7
|
+
import '../../meta-D8OyedKp.js';
|
|
8
8
|
import '../../extra/storage-core.js';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{a,b,c,d,e}from"../../chunk-
|
|
1
|
+
import{a,b,c,d,e}from"../../chunk-XQ55HO5N.js";import"../../chunk-R75BMDLA.js";import"../../chunk-3G5U5QNE.js";import"../../chunk-C72GO4IZ.js";import"../../chunk-4I45FVQS.js";import"../../chunk-VJJLIEAL.js";import"../../chunk-L6NSJVJZ.js";import"../../chunk-7JRF5YEK.js";import"../../chunk-SGS4OJGS.js";import"../../chunk-ESMPEKEV.js";import"../../chunk-35JTVPOX.js";import"../../chunk-AU7YTQX7.js";import"../../chunk-IA7DUNGB.js";import"../../chunk-LYCLF26R.js";import"../../chunk-CK2E7BTU.js";import"../../chunk-QYADASLV.js";export{d as CqrsGraph,e as cqrs,a as cqrsEventKeyOf,b as dispatchKeyOf,c as sagaInvocationKeyOf};
|