@graphrefly/graphrefly 0.38.0 → 0.40.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-BNfxffgc.d.ts} +2 -2
- package/dist/{cascading-B25wxpRa.d.cts → cascading-Cxs1eztH.d.cts} +2 -2
- package/dist/chunk-2BX4NB34.js +3 -0
- package/dist/{chunk-6VFC334U.js → chunk-2DMKW2AD.js} +1 -1
- package/dist/{chunk-4BDQXBXE.js → chunk-2QXRYP7Q.js} +1 -1
- package/dist/chunk-32N3JALT.js +1 -0
- package/dist/chunk-35JTVPOX.js +1 -0
- package/dist/chunk-3G5U5QNE.js +5 -0
- package/dist/{chunk-PHXZRR6C.js → chunk-4I45FVQS.js} +1 -1
- package/dist/{chunk-B5S7KTGP.js → chunk-6I726LZU.js} +1 -1
- package/dist/{chunk-NV63VQHI.js → chunk-6VWBPSSY.js} +1 -1
- package/dist/chunk-6XVD5TZV.js +1 -0
- package/dist/chunk-756D5TFD.js +1 -0
- package/dist/{chunk-DSOVKKTI.js → chunk-7Q4ZD3YW.js} +1 -1
- package/dist/{chunk-TMVY7OWG.js → chunk-B7LCDQEV.js} +1 -1
- package/dist/chunk-C72GO4IZ.js +1 -0
- package/dist/{chunk-RZ5HKPGI.js → chunk-CKFQS2CJ.js} +1 -1
- package/dist/chunk-D27JNOLZ.js +1 -0
- package/dist/chunk-ECQRP2UT.js +1 -0
- package/dist/{chunk-6773HURD.js → chunk-FHRBBHJN.js} +1 -1
- package/dist/{chunk-UVLZX2OU.js → chunk-I2DEVPMU.js} +1 -1
- package/dist/chunk-INQFTVZA.js +61 -0
- package/dist/{chunk-6KZZ6XQE.js → chunk-J63M5U46.js} +1 -1
- package/dist/{chunk-POCWFIJ7.js → chunk-JKBOIJ22.js} +1 -1
- package/dist/chunk-K2Z7UENB.js +1 -0
- package/dist/chunk-L6NSJVJZ.js +1 -0
- package/dist/{chunk-K5C67OGE.js → chunk-LCGAVGGV.js} +2 -2
- package/dist/chunk-LYM4PBMV.js +1 -0
- package/dist/{chunk-O2BLVQU4.js → chunk-MNZIKXK4.js} +1 -1
- package/dist/chunk-N43XM7BM.js +1 -0
- package/dist/{chunk-FWGIZP3W.js → chunk-OSZ22J7O.js} +1 -1
- package/dist/{chunk-FAYEMS5M.js → chunk-PPUYQ66A.js} +1 -1
- package/dist/{chunk-SP5O2MIX.js → chunk-QSK3RRII.js} +1 -1
- package/dist/chunk-RZJDIV2G.js +1 -0
- package/dist/chunk-SSCGRYJ2.js +1 -0
- package/dist/chunk-SVFKHUCW.js +1 -0
- package/dist/chunk-TSOYJ743.js +1 -0
- package/dist/{chunk-O245YLM5.js → chunk-UWA6D7UF.js} +1 -1
- package/dist/chunk-VMF23LGB.js +1 -0
- package/dist/chunk-WL6LFPJB.js +1 -0
- package/dist/chunk-WUT362QV.js +1 -0
- package/dist/chunk-XJLYLLIJ.js +1 -0
- package/dist/{chunk-IBGE62GZ.js → chunk-XW4YDF6G.js} +1 -1
- package/dist/chunk-YKD7WUYJ.js +43 -0
- package/dist/{chunk-7KZZLWZ6.js → chunk-YXDRGKXP.js} +1 -1
- package/dist/chunk-Z4F3DOWS.js +84 -0
- 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 +7 -11
- 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/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/{composite-DTOlDuch.d.ts → decay-BnrlbxSv.d.ts} +39 -3
- package/dist/{composite-CgG0MqHm.d.cts → decay-C25AyNAj.d.cts} +39 -3
- package/dist/extra/browser.d.cts +1 -1
- package/dist/extra/browser.d.ts +1 -1
- package/dist/extra/index.cjs +16 -20
- 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 +1 -1
- package/dist/extra/node.d.ts +1 -1
- package/dist/extra/node.js +1 -1
- 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/{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-BjW1taJl.d.ts → graph-BkIkog4h.d.ts} +76 -100
- package/dist/{graph-CHsVwf9S.d.cts → graph-E6likq7w.d.cts} +76 -100
- package/dist/{index-CIcu6fIR.d.ts → index-2n8Eai6M.d.ts} +1 -1
- package/dist/{index-BwOsJfLJ.d.ts → index-3k4Gg6-n.d.ts} +3 -3
- package/dist/{index-BUFCHvOR.d.ts → index-40ZT4MHj.d.ts} +3 -3
- package/dist/index-8s-Qm-gz.d.ts +218 -0
- package/dist/index-A3U3CSve.d.cts +113 -0
- package/dist/{index-CDvC1m5p.d.ts → index-B2RUoIUz.d.ts} +1 -1
- package/dist/{index-Byp771zP.d.ts → index-B6iTqKtJ.d.ts} +2 -2
- package/dist/{index-D-B7U42V.d.cts → index-B72TQQHd.d.cts} +2 -2
- package/dist/{resilience-Bys63Cpd.d.ts → index-BAQrjuZF.d.ts} +202 -26
- package/dist/{index-BiomL7AW.d.ts → index-BJSZxSFX.d.ts} +1 -1
- package/dist/index-BQ1fR4li.d.ts +210 -0
- package/dist/{index-D7-RSD93.d.cts → index-BTHOTC0Q.d.cts} +4 -4
- package/dist/{index-CEVzBWeB.d.ts → index-BaA-xpSw.d.ts} +26 -19
- package/dist/{index-CAV-3RpJ.d.cts → index-Bd91Nmf4.d.cts} +4 -4
- package/dist/{index-BI1wMfyc.d.ts → index-BgjS2b8N.d.ts} +3 -3
- package/dist/{index-Bpr0Pwgl.d.cts → index-BiHUBEKq.d.cts} +3 -3
- package/dist/{index-UsU9ptzs.d.cts → index-BilOa6AE.d.cts} +55 -9
- package/dist/{index-DJVQ-t07.d.ts → index-BmSQLAZo.d.cts} +41 -48
- package/dist/{index-DTDVDzhA.d.ts → index-C-dkXOpB.d.cts} +56 -54
- package/dist/{index-B-ORMr3k.d.ts → index-C5cQ7Gfx.d.ts} +4 -4
- package/dist/{index-ML6vHKXK.d.ts → index-C6ZUaos7.d.ts} +1 -1
- package/dist/{index-Vz7KPfgz.d.ts → index-CAP3UGsq.d.ts} +1 -1
- package/dist/{index-BFaALJxR.d.ts → index-CD2dBMet.d.ts} +10 -8
- package/dist/index-CGhMJNHb.d.cts +128 -0
- package/dist/{index-B3D_z0Z6.d.cts → index-CL7oilfm.d.cts} +1 -1
- package/dist/{index-Bn0uZEL4.d.ts → index-CQtWm7jS.d.ts} +9 -9
- package/dist/{index-CM-i58FY.d.cts → index-CRm0YIzC.d.cts} +9 -9
- package/dist/index-CUIkE1l9.d.cts +230 -0
- package/dist/{index-CijfwEWx.d.ts → index-Cczxgd2D.d.ts} +2 -2
- package/dist/{index-CAbHN_rP.d.cts → index-CgnCFhr2.d.cts} +1 -1
- package/dist/{index-B2IUcH13.d.cts → index-Ck35nA-T.d.ts} +41 -48
- package/dist/{index-BpMZzX9P.d.cts → index-Cnr1WrlX.d.cts} +3 -3
- package/dist/{index-JYtN9uqM.d.ts → index-CoM4rzyB.d.ts} +1 -1
- package/dist/{index-Ckil6miL.d.cts → index-CtFNGe-m.d.cts} +2 -2
- package/dist/{index-BjWZARLy.d.ts → index-Ctb7_2sG.d.ts} +1 -1
- package/dist/index-CuPUehFa.d.cts +218 -0
- package/dist/index-D1Gc7wV5.d.ts +230 -0
- package/dist/{index-DqICM_I7.d.ts → index-D1IEZUsj.d.ts} +67 -9
- package/dist/{index-BFuVcqL8.d.cts → index-D3ayz3hy.d.cts} +1 -1
- package/dist/{index-CQsqqEVz.d.cts → index-D4uimgee.d.cts} +1 -1
- package/dist/{resilience-BWP2c7Af.d.cts → index-DGTo1yka.d.cts} +202 -26
- package/dist/{index-BmWuVdER.d.ts → index-DH4fm2Ck.d.ts} +2 -2
- package/dist/{index-BkQqf1EF.d.cts → index-DJ_MPOJ5.d.cts} +67 -9
- package/dist/{index-9xhIaM-w.d.cts → index-DOBLxOti.d.cts} +1 -1
- package/dist/{index-BqcgiSQg.d.cts → index-DQQCOIt8.d.cts} +10 -8
- package/dist/{index-DJNAWzcH.d.cts → index-DVAlsmEU.d.cts} +26 -19
- package/dist/index-DVDapw2k.d.cts +210 -0
- package/dist/{index-D_QQ_dTD.d.cts → index-DYTBbF8T.d.cts} +1 -1
- package/dist/{index-BgzPO43H.d.cts → index-DgJc8Zgc.d.cts} +6 -6
- package/dist/{index-Czk3r0yA.d.cts → index-DhLyOHYZ.d.ts} +56 -54
- package/dist/{index-CrlHFsiT.d.ts → index-DhnsQfa3.d.ts} +100 -118
- package/dist/{index-Bub6x_D4.d.cts → index-DktLSZOc.d.cts} +37 -90
- package/dist/{index-BaSy4L6w.d.cts → index-DpiGqtrs.d.cts} +100 -118
- package/dist/{index-D-HZ7sP4.d.ts → index-I1cCY3ZI.d.ts} +6 -6
- package/dist/{index-D9vBTuzo.d.ts → index-IUCY0OFN.d.ts} +4 -4
- package/dist/{index-DeSsvHDD.d.cts → index-MxYuWOrf.d.cts} +3 -3
- package/dist/index-N2MAxt7_.d.ts +128 -0
- package/dist/{index-CpZKtdMw.d.cts → index-PgwvGWa1.d.cts} +1 -1
- package/dist/{index-AUqWe_fX.d.ts → index-WSlcjhQF.d.ts} +55 -9
- package/dist/{index-Di7OdwlO.d.ts → index-bXXLSvor.d.ts} +37 -90
- package/dist/index-da2V5vPy.d.ts +113 -0
- package/dist/{index-DY2f2b9z.d.ts → index-eaQuGJnv.d.ts} +3 -3
- package/dist/{index-BsgxnHN8.d.cts → index-t6L2qpHh.d.cts} +3 -3
- package/dist/{index-C-3UXnHT.d.cts → index-tV3AA9hI.d.cts} +2 -2
- 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 +63 -59
- package/dist/index.d.cts +48 -47
- package/dist/index.d.ts +48 -47
- package/dist/index.js +1 -1
- package/dist/{meta-DreaEM_a.d.cts → meta-Ct9nqQS5.d.cts} +11 -7
- package/dist/{meta-BYqlATmg.d.ts → meta-D8OyedKp.d.ts} +11 -7
- 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 +16 -20
- 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 +37 -37
- 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 +5 -6
- package/dist/patterns/lens/index.d.ts +5 -6
- package/dist/patterns/lens/index.js +1 -1
- package/dist/patterns/memory/index.cjs +3 -7
- package/dist/patterns/memory/index.d.cts +6 -6
- package/dist/patterns/memory/index.d.ts +6 -6
- 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 +3 -1
- package/dist/patterns/resilient-pipeline/index.d.cts +6 -6
- package/dist/patterns/resilient-pipeline/index.d.ts +6 -6
- package/dist/patterns/resilient-pipeline/index.js +1 -1
- package/dist/patterns/surface/index.cjs +12 -16
- 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-9JBbmRxA.d.ts → pipeline-graph-CB4La-UW.d.ts} +34 -17
- package/dist/{pipeline-graph-DuHpXSOn.d.cts → pipeline-graph-MWrQZXCq.d.cts} +34 -17
- package/dist/{reactive-layout-BMLDB4Vd.d.cts → reactive-layout-BtZfUKuL.d.cts} +2 -2
- package/dist/{reactive-layout-D-tRiNhg.d.ts → reactive-layout-KJj4E2dT.d.ts} +2 -2
- package/dist/{reactive-log-BgWSA1fg.d.ts → reactive-log-BlAsPLl2.d.ts} +2 -2
- package/dist/{reactive-log-C3IMAGpT.d.cts → reactive-log-_zeEnB9H.d.cts} +2 -2
- package/dist/{reactive-map-DmgeADH8.d.cts → reactive-map-6P_k3AQM.d.cts} +2 -2
- package/dist/{reactive-map-CHyeCf4D.d.ts → reactive-map-CjXByDV-.d.ts} +2 -2
- package/dist/resilience-S33JV6XC.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-jrZue3ao.d.cts → topology-tree-3LBKFsUo.d.cts} +1 -1
- package/dist/{topology-tree-D47-nI6Z.d.ts → topology-tree-mF7Emqzm.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-2YFDSYEF.js +0 -1
- package/dist/chunk-5BGFS2XH.js +0 -1
- package/dist/chunk-CMTN3KPT.js +0 -80
- package/dist/chunk-DQJLC6YY.js +0 -1
- package/dist/chunk-G7JN6LCB.js +0 -1
- package/dist/chunk-KJEAIIIY.js +0 -43
- package/dist/chunk-LV3ACS5J.js +0 -1
- package/dist/chunk-NBGPXQSP.js +0 -1
- package/dist/chunk-NN3QPJ6U.js +0 -1
- package/dist/chunk-NSAZ6PR6.js +0 -1
- package/dist/chunk-O32GJOUJ.js +0 -1
- package/dist/chunk-QEVSIVSF.js +0 -1
- package/dist/chunk-QMC2PLNM.js +0 -7
- package/dist/chunk-QOJFR6GS.js +0 -1
- package/dist/chunk-SFK7MN7S.js +0 -1
- package/dist/chunk-TB7JKSVS.js +0 -61
- package/dist/chunk-UAXFKMAG.js +0 -1
- package/dist/chunk-XIMFHEKV.js +0 -1
- package/dist/chunk-XLMYQB6F.js +0 -1
- package/dist/chunk-XLYF4LBH.js +0 -1
- package/dist/imperative-audit-ahAE65a9.d.cts +0 -28
- package/dist/imperative-audit-ahAE65a9.d.ts +0 -28
- package/dist/index-5dNRlW7J.d.ts +0 -135
- package/dist/index-BWUMIt7J.d.cts +0 -135
- package/dist/index-BhzwpIJc.d.cts +0 -105
- package/dist/index-BsZk9T8y.d.ts +0 -105
- package/dist/index-C56XZiDe.d.cts +0 -163
- package/dist/index-CpdnP-0y.d.cts +0 -186
- package/dist/index-DKrIuF-r.d.ts +0 -163
- package/dist/index-DOU1Ee_k.d.ts +0 -186
- package/dist/resilience-LGBK236C.js +0 -1
|
@@ -1,15 +1,11 @@
|
|
|
1
|
-
"use strict";var Zr=Object.create;var Ae=Object.defineProperty;var En=Object.getOwnPropertyDescriptor;var eo=Object.getOwnPropertyNames;var to=Object.prototype.hasOwnProperty;var On=(n,e)=>(e=Symbol[n])?e:Symbol.for("Symbol."+n),Ye=n=>{throw TypeError(n)};var no=(n,e,t)=>e in n?Ae(n,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):n[e]=t;var wn=(n,e)=>Ae(n,"name",{value:e,configurable:!0});var B=(n,e)=>()=>(n&&(e=n(n=0)),e);var ro=(n,e)=>{for(var t in e)Ae(n,t,{get:e[t],enumerable:!0})},oo=(n,e,t,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of eo(e))!to.call(n,o)&&o!==t&&Ae(n,o,{get:()=>e[o],enumerable:!(r=En(e,o))||r.enumerable});return n};var so=n=>oo(Ae({},"__esModule",{value:!0}),n);var Rn=n=>[,,,Zr(n?.[On("metadata")]??null)],kn=["class","method","getter","setter","accessor","field","value","get","set"],Ue=n=>n!==void 0&&typeof n!="function"?Ye("Function expected"):n,io=(n,e,t,r,o)=>({kind:kn[n],name:e,metadata:r,addInitializer:s=>t._?Ye("Already initialized"):o.push(Ue(s||null))}),ao=(n,e)=>no(e,On("metadata"),n[3]),Sn=(n,e,t,r)=>{for(var o=0,s=n[e>>1],i=s&&s.length;o<i;o++)e&1?s[o].call(t):r=s[o].call(t,r);return r},Nn=(n,e,t,r,o,s)=>{var i,a,d,u,c,f=e&7,p=!!(e&8),h=!!(e&16),l=f>3?n.length+1:f?p?1:2:0,y=kn[f+5],m=f>3&&(n[l-1]=[]),x=n[l]||(n[l]=[]),_=f&&(!h&&!p&&(o=o.prototype),f<5&&(f>3||!h)&&En(f<4?o:{get[t](){return xn(this,s)},set[t](b){return Tn(this,s,b)}},t));f?h&&f<4&&wn(s,(f>2?"set ":f>1?"get ":"")+t):wn(o,t);for(var v=r.length-1;v>=0;v--)u=io(f,t,d={},n[3],x),f&&(u.static=p,u.private=h,c=u.access={has:h?b=>uo(o,b):b=>t in b},f^3&&(c.get=h?b=>(f^1?xn:co)(b,o,f^4?s:_.get):b=>b[t]),f>2&&(c.set=h?(b,O)=>Tn(b,o,O,f^4?s:_.set):(b,O)=>b[t]=O)),a=(0,r[v])(f?f<4?h?s:_[y]:f>4?void 0:{get:_.get,set:_.set}:o,u),d._=1,f^4||a===void 0?Ue(a)&&(f>4?m.unshift(a):f?h?s=a:_[y]=a:o=a):typeof a!="object"||a===null?Ye("Object expected"):(Ue(i=a.get)&&(_.get=i),Ue(i=a.set)&&(_.set=i),Ue(i=a.init)&&m.unshift(i));return f||ao(n,o),_&&Ae(o,t,_),h?f^4?s:_:o};var Vt=(n,e,t)=>e.has(n)||Ye("Cannot "+t),uo=(n,e)=>Object(e)!==e?Ye('Cannot use the "in" operator on this value'):n.has(e),xn=(n,e,t)=>(Vt(n,e,"read from private field"),t?t.call(n):e.get(n));var Tn=(n,e,t,r)=>(Vt(n,e,"write to private field"),r?r.call(n,t):e.set(n,t),t),co=(n,e,t)=>(Vt(n,e,"access private method"),t);var me,M,W,K,ee,J,te,F,$,D,ye,ft,An,pt,Cn,Mn,ht,zt,qt,jt,gt,ae=B(()=>{"use strict";me=Symbol.for("graphrefly/START"),M=Symbol.for("graphrefly/DATA"),W=Symbol.for("graphrefly/DIRTY"),K=Symbol.for("graphrefly/RESOLVED"),ee=Symbol.for("graphrefly/INVALIDATE"),J=Symbol.for("graphrefly/PAUSE"),te=Symbol.for("graphrefly/RESUME"),F=Symbol.for("graphrefly/TEARDOWN"),$=Symbol.for("graphrefly/COMPLETE"),D=Symbol.for("graphrefly/ERROR"),ye=Object.freeze([W]),ft=Object.freeze([K]),An=Object.freeze([ee]),pt=Object.freeze([me]),Cn=Object.freeze([$]),Mn=Object.freeze([F]),ht=Object.freeze([ye]),zt=Object.freeze([ft]),qt=Object.freeze([An]),jt=Object.freeze([Cn]),gt=Object.freeze([Mn])});function ce(){return Math.trunc(performance.now()*1e6)}function re(){return Date.now()*1e6}var $e=B(()=>{"use strict"});function Bn(n,e){let t=new TextEncoder().encode(n.name);if(t.length===0||t.length>255)throw new Error(`encodeEnvelope: codec name "${n.name}" encodes to ${t.length} bytes (must be 1\u2013255)`);let r=n.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 o=2+t.length+2+e.length;if(o>4294967295)throw new Error(`encodeEnvelope: total envelope size ${o} exceeds 2^32-1 bytes (payload ${e.length} bytes)`);let s=new Uint8Array(o),i=0;return s[i++]=Wt,s[i++]=t.length,s.set(t,i),i+=t.length,s[i++]=r>>>8&255,s[i++]=r&255,s.set(e,i),s}function Wn(n,e){if(n.length<jn)throw new Error(`decodeEnvelope: bytes too short (${n.length} < ${jn})`);let t=0,r=n[t++];if(r!==Wt)throw new Error(`decodeEnvelope: unsupported envelope version ${r} (expected ${Wt})`);let o=n[t++];if(o===0)throw new Error("decodeEnvelope: name_len must be >= 1");if(t+o+2>n.length)throw new Error(`decodeEnvelope: envelope truncated (need ${t+o+2} bytes, have ${n.length})`);let s=new TextDecoder().decode(n.subarray(t,t+o));t+=o;let i=(n[t]<<8|n[t+1])>>>0;t+=2;let a=n.subarray(t),d=e.lookupCodec(s);if(d==null)throw new Error(`decodeEnvelope: codec "${s}" not registered (envelope codec_v=${i})`);return{codec:d,codecVersion:i,payload:a}}function Kn(n){n.registerCodec(lo)}var lo,Wt,jn,Kt=B(()=>{"use strict";lo={name:"json",version:1,contentType:"application/json",encode(n){let e=JSON.stringify(n);return new TextEncoder().encode(e)},decode(n,e){let t=new TextDecoder().decode(n);return JSON.parse(t)}},Wt=1,jn=4});function ve(n){if(n==null)return fe;let{type:e,id:t,...r}=n;return{type:e??"system",id:t??"",...r}}var fe,Qe=B(()=>{"use strict";fe={type:"system",id:""}});function mt(){return He>0||Xe}function Un(){return He>0}function Ve(n){He>0?Ze.push(n):n()}function ze(n){He+=1;let e=!1;try{n()}catch(t){throw e=!0,t}finally{if(He-=1,He===0)if(e){if(!Xe){let t=Ze.splice(0);for(let r of t)try{r()}catch{}_e.length=0,we.length=0,Fe.length=0}}else fo()}}function fo(){let n=!Xe;n&&(Xe=!0);let e=[],t=0;try{for(;_e.length>0||we.length>0||Fe.length>0||n&&Ze.length>0;){if(n&&Ze.length>0){let s=Ze.splice(0);for(let i of s)try{i()}catch(a){e.push(a)}continue}if(t+=1,t>1e3)throw _e.length=0,we.length=0,Fe.length=0,new Error("batch drain exceeded 1000 iterations \u2014 likely a reactive cycle");let o=(_e.length>0?_e:we.length>0?we:Fe).splice(0);for(let s of o)try{s()}catch(i){e.push(i)}}}finally{n&&(Xe=!1)}if(e.length===1)throw e[0];if(e.length>1)throw new AggregateError(e,"batch drain: multiple callbacks threw")}function yt(n,e,t){if(e.length===0)return;if(e.length===1){let u=t(e[0][0]);if(u<3||!mt()){n(e);return}(u>=5?Fe:u===4?we:_e).push(()=>n(e));return}let r=e.length,o=r,s=r,i=r,a=0;for(;a<r&&t(e[a][0])<3;)a++;for(o=a;a<r&&t(e[a][0])===3;)a++;for(s=a;a<r&&t(e[a][0])===4;)a++;i=a;let d=mt();if(o>0){let u=e.slice(0,o);n(u)}if(s>o){let u=e.slice(o,s);d?_e.push(()=>n(u)):n(u)}if(i>s){let u=e.slice(s,i);d?we.push(()=>n(u)):n(u)}if(r>i){let u=e.slice(i,r);d?Fe.push(()=>n(u)):n(u)}}var He,Xe,_e,we,Fe,Ze,et=B(()=>{"use strict";He=0,Xe=!1,_e=[],we=[],Fe=[],Ze=[]});function Yn(n){n.registerMessageType(me,{tier:0,wireCrossing:!1}),n.registerMessageType(W,{tier:1,wireCrossing:!1}),n.registerMessageType(ee,{tier:1,wireCrossing:!1,metaPassthrough:!1}),n.registerMessageType(J,{tier:2,wireCrossing:!1}),n.registerMessageType(te,{tier:2,wireCrossing:!1}),n.registerMessageType(M,{tier:3,wireCrossing:!0}),n.registerMessageType(K,{tier:3,wireCrossing:!0}),n.registerMessageType($,{tier:4,wireCrossing:!0,metaPassthrough:!1}),n.registerMessageType(D,{tier:4,wireCrossing:!0,metaPassthrough:!1}),n.registerMessageType(F,{tier:5,wireCrossing:!0,metaPassthrough:!1})}var bt,Jn=B(()=>{"use strict";ae();bt=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 r=this._messageTypes.get(t);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,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 Qn(n){return Array.isArray(n)?[...n]:[n]}function po(n,e){return n.has(e)||n.has("*")}function qe(n){let e=[];return n((o,s)=>{e.push({kind:"allow",actions:new Set(Qn(o)),where:s?.where??(()=>!0)})},(o,s)=>{e.push({kind:"deny",actions:new Set(Qn(o)),where:s?.where??(()=>!0)})}),(o,s)=>{let i=!1,a=!1;for(let d of e)po(d.actions,s)&&d.where(o)&&(d.kind==="deny"?i=!0:a=!0);return i?!1:a}}function Ut(n){let e=ho.filter(t=>n({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 oe,ho,xe=B(()=>{"use strict";oe=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}};ho=["human","llm","wallet","system"]});function Yt(n){if(n===void 0)return null;if(typeof n=="number"){if(!Number.isFinite(n))throw new TypeError(`Cannot hash non-finite number: ${n}`);if(Number.isInteger(n)&&!Number.isSafeInteger(n))throw new TypeError(`Cannot hash integer outside safe range (|n| > 2^53-1): ${n}. Cross-language cid parity is not guaranteed for unsafe integers.`);return n}if(typeof n=="string"||typeof n=="boolean"||n===null)return n;if(Array.isArray(n))return n.map(Yt);if(typeof n=="object"&&n!==null){let e={};for(let t of Object.keys(n).sort())e[t]=Yt(n[t]);return e}return null}function yo(n){let e=mo.encode(n),t=e.length,r=t*8,o=t+9+63&-64,s=new Uint8Array(o);s.set(e),s[t]=128;let i=new DataView(s.buffer);i.setUint32(o-4,r>>>0,!1),i.setUint32(o-8,Math.floor(r/4294967296)>>>0,!1);let a=1779033703,d=3144134277,u=1013904242,c=2773480762,f=1359893119,p=2600822924,h=528734635,l=1541459225,y=new Uint32Array(64),m=(_,v)=>_>>>v|_<<32-v;for(let _=0;_<o;_+=64){for(let T=0;T<16;T++)y[T]=i.getUint32(_+T*4,!1);for(let T=16;T<64;T++){let N=y[T-15],S=y[T-2],A=m(N,7)^m(N,18)^N>>>3,G=m(S,17)^m(S,19)^S>>>10;y[T]=y[T-16]+A+y[T-7]+G>>>0}let v=a,b=d,O=u,R=c,g=f,w=p,k=h,E=l;for(let T=0;T<64;T++){let N=m(g,6)^m(g,11)^m(g,25),S=g&w^~g&k,A=E+N+S+go[T]+y[T]>>>0,G=m(v,2)^m(v,13)^m(v,22),I=v&b^v&O^b&O,q=G+I>>>0;E=k,k=w,w=g,g=R+A>>>0,R=O,O=b,b=v,v=A+q>>>0}a=a+v>>>0,d=d+b>>>0,u=u+O>>>0,c=c+R>>>0,f=f+g>>>0,p=p+w>>>0,h=h+k>>>0,l=l+E>>>0}let x=_=>_.toString(16).padStart(8,"0");return x(a)+x(d)+x(u)+x(c)+x(f)+x(p)+x(h)+x(l)}function Jt(n){let e=Yt(n??null),t=JSON.stringify(e);return yo(t).slice(0,16)}function bo(){let n=globalThis.crypto;if(n?.randomUUID)return n.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 Qt(n,e,t){let r=t?.id??bo();if(n===0)return{id:r,version:0};let s=(t?.hash??Jt)(e);return{id:r,version:0,cid:s,prev:null}}function Xn(n,e,t){n.version+=1,"cid"in n&&(n.prev=n.cid,n.cid=t(e))}var go,mo,Zn=B(()=>{"use strict";go=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]),mo=new TextEncoder});function nr(n){return{node:n,unsub:null,prevData:void 0,dirty:!1,involvedThisWave:!1,dataBatch:[],terminal:void 0}}function Xt(n){n.prevData=void 0,n.dirty=!1,n.involvedThisWave=!1,n.dataBatch.length=0,n.terminal=void 0}function vt(n){return n.length===0?n:typeof n[0]=="symbol"?[n]:n}function le(n,e,t){let r=rr(n)?n:[],o=typeof n=="function"?n:typeof e=="function"?e:void 0,s={};return rr(n)?s=(Zt(e)?e:t)??{}:Zt(n)?s=n:s=(Zt(e)?e:t)??{},new V(r,o,s)}var er,tr,vo,_o,Te,V,rr,Zt,Ee=B(()=>{"use strict";Kt();Qe();et();$e();Jn();xe();ae();Zn();er=()=>{},tr=100;vo=(n,e,t,r)=>{t.direction==="down-in"&&n._onDepMessage(t.depIndex,e)},_o=(n,e,t,r)=>{let o=n;if(o._status==="completed"||o._status==="errored")return;let s=o._cached,i=s===void 0?[pt]:[pt,[M,s]];o._status==="dirty"&&i.push(ye),yt(e,i,o._config.tierOf)},Te=new bt({onMessage:vo,onSubscribe:_o});Yn(Te);Kn(Te);V=class n{_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,r){this._config=r.config??Te,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=t,this._partial=r.partial??!1,this._cached=r.initial!==void 0?r.initial:void 0,this._status=e.length===0&&t==null&&this._cached!==void 0?"settled":"sentinel",this._hashFn=r.versioningHash??this._config.defaultHashFn??Jt;let o=r.versioning??this._config.defaultVersioning;this._versioningLevel=o,this._versioning=o!=null?Qt(o,this._cached===void 0?void 0:this._cached,{id:r.versioningId,hash:this._hashFn}):void 0,this._deps=e.map(nr);let s={};for(let[a,d]of Object.entries(r.meta??{})){let u={initial:d,name:`${r.name??"node"}:meta:${a}`,describeKind:"state",config:this._config};r.guard!=null&&(u.guard=r.guard),s[a]=new n([],void 0,u)}Object.freeze(s),this.meta=s,this._hasMeta=Object.keys(s).length>0;let i=this;this._actions={emit(a){i._emit([[M,a]])},down(a){i._emit(vt(a))},up(a){i._emitUp(vt(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 r=this._versioningLevel;if(r!=null&&e<=r)return;let o=t?.hash??this._hashFn;o!==this._hashFn&&(this._hashFn=o);let s=this._cached===void 0?void 0:this._cached,i=this._versioning,a=i?.id??t?.id,d=i?.version??0,u=Qt(e,s,{id:a,hash:o});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=ve(e);if(this._guard!=null&&!this._guard(t,"observe"))return!1;if(this._extraGuards!=null){for(let r of this._extraGuards)if(!r(t,"observe"))return!1}return!0}_checkGuard(e){if(e?.internal)return;let t=this._guard!=null||this._extraGuards!=null,r=e?.actor!=null;if(!t&&!r)return;let o=ve(e?.actor),s=e?.delivery==="signal"?"signal":"write";if(this._guard!=null&&!this._guard(o,s))throw new oe({actor:o,action:s,nodeName:this.name});if(this._extraGuards!=null){for(let i of this._extraGuards)if(!i(o,s))throw new oe({actor:o,action:s,nodeName:this.name})}this._lastMutation={actor:o,timestamp_ns:re()}}down(e,t){let r=vt(e);r.length!==0&&(this._checkGuard(t),this._emit(r))}emit(e,t){this._checkGuard(t),this._emit([[M,e]])}up(e,t){if(this._deps.length===0)return;let r=vt(e);if(r.length===0)return;this._checkGuard(t);let o=t??{internal:!0};this._validateUpTiers(r);for(let s of this._deps)s.node.up?.(r,o)}_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 r of e){let o=t(r[0]);if(o===3||o===4)throw new Error(`Node "${this.name}": tier-${o} 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=ve(t);if(!this._guard(d,"observe"))throw new oe({actor:d,action:"observe",nodeName:this.name})}let o=this._isTerminal&&this._resubscribable;if(o){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 s;try{s=this._config.onSubscribe(this,e,{sinkCount:this._sinkCount,afterTerminalReset:o},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 s=="function")try{s()}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 s=="function"&&s(),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 r=0;r<e;r++){let o=r,s=this._deps[r];s.unsub=er,s.unsub=s.node.subscribe(i=>{if(s.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:o},this._actions);d&&this._maybeRunFnOnSettlement()}),t++}}catch(r){this._deps[t].unsub=null;for(let o=0;o<t;o++){let s=this._deps[o];if(s.unsub!=null){let i=s.unsub;s.unsub=null;try{i()}catch{}Xt(s)}}throw this._dirtyDepCount=0,r}}_addDep(e){for(let o=0;o<this._deps.length;o++)if(this._deps[o].node===e)return o;let t=this._deps.length,r=nr(e);if(this._deps.push(r),this._sinks==null)return t;r.dirty=!0,this._dirtyDepCount++,this._status!=="dirty"&&this._emit(ht),r.unsub=er;try{r.unsub=e.subscribe(o=>{if(r.unsub===null)return;let s=this._config.tierOf,i=!1;for(let a of o)s(a[0])>=3&&(i=!0),this._config.onMessage(this,a,{direction:"down-in",depIndex:t},this._actions);i&&this._maybeRunFnOnSettlement()})}catch(o){throw r.unsub=null,this._deps.pop(),this._dirtyDepCount--,o}return t}_deactivate(e=!1){let t=this._cleanup;if(this._cleanup=void 0,typeof t=="function")try{t()}catch(r){this._emit([[D,this._wrapFnError("cleanup threw",r)]])}else if(t!=null&&typeof t=="object"){let r=t.deactivate;if(typeof r=="function")try{r()}catch(o){this._emit([[D,this._wrapFnError("cleanup.deactivate threw",o)]])}}for(let r of this._deps){if(r.unsub!=null){let o=r.unsub;r.unsub=null;try{o()}catch{}}Xt(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,t){let r=this._deps[e],o=t[0];if(this._inspectorHooks!=null){let s={kind:"dep_message",depIndex:e,message:t};for(let i of this._inspectorHooks)i(s)}if(o!==me){if(o===W){this._depDirtied(r);return}if(o===ee){if(this._depInvalidated(r),this._cached===void 0)return;this._emit(qt);return}if(o===J||o===te){this._emit([t]);return}if(o===F){this._emit(gt);return}if(o===M)this._depSettledAsData(r,t[1]);else if(o===K)this._depSettledAsResolved(r);else if(o===$)this._depSettledAsTerminal(r,!0);else if(o===D)this._depSettledAsTerminal(r,t[1]);else{this._emit([t]);return}if(!this._fn){(o===M||o===K)&&this._emit([t]),(o===$||o===D)&&this._maybeAutoTerminalAfterWave();return}}}_depDirtied(e){e.dirty||(e.dirty=!0,e.involvedThisWave=!0,this._dirtyDepCount++,this._status!=="dirty"&&this._emit(ht))}_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(zt),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([[D,e.terminal]]);return}this._autoComplete&&this._deps.every(t=>t.terminal!==void 0)&&this._emit(jt)}_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([[D,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([[D,this._wrapFnError("cleanup.beforeRun threw",a)]]);return}}}let t=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=t[i];a!=null&&a.length>0&&(this._deps[i].prevData=a[a.length-1])}let o=this._deps.map(i=>i.terminal),s={prevData:r,terminalDeps:o,store:this._store};if(this._hasCalledFnOnce=!0,this._clearWaveFlags(),this._inspectorHooks!=null){let i={kind:"run",batchData:t,prevData:r};for(let a of this._inspectorHooks)a(i)}this._isExecutingFn=!0;try{let i=this._fn(t,this._actions,s);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([[D,this._wrapFnError("fn threw",i)]])}finally{this._isExecutingFn=!1,this._pendingRerun?(this._pendingRerun=!1,this._rerunDepth+=1,this._rerunDepth>tr?(this._rerunDepth=0,this._emit([[D,new Error(`Node "${this.name}": _pendingRerun depth exceeded ${tr} \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 r=t instanceof Error?t.message:String(t);return new Error(`Node "${this.name}": ${e}: ${r}`,{cause:t})}_frameBatch(e){let t=this._config.tierOf;if(e.length===1)return t(e[0][0])===3&&this._status!=="dirty"?[ye,e[0]]:e;let r=!0,o=!1,s=!1,i=-1;for(let d of e){let u=t(d[0]);u<i&&(r=!1),u===3&&(o=!0),d[0]===W&&(s=!0),i=u}let a=e;if(!r){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(o&&!s&&this._status!=="dirty"){let d=0;for(;d<a.length&&t(a[d][0])===0;)d++;return d===0?[ye,...a]:[...a.slice(0,d),ye,...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]===D&&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]===F||d[0]===ee);if(a.length===0)return;t=a}t=this._frameBatch(t);let o=null;for(let a=0;a<t.length;a++){let d=t[a],u=d[0];if(u!==J&&u!==te){o?.push(d);continue}if(d.length<2)throw new Error(`Node "${this.name}": [[${u===J?"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 f=d[1];if(u===J)this._pauseLocks==null&&(this._pauseLocks=new Set),this._pauseLocks.add(f),this._paused=!0,this._pausable==="resumeAll"&&this._pauseBuffer==null&&(this._pauseBuffer=[]);else if(this._pauseLocks==null||!this._pauseLocks.has(f))c=!1;else if(this._pauseLocks.delete(f),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?o?.push(d):o==null&&(o=t.slice(0,a))}if(o!=null){if(o.length===0)return;t=o}if(this._hasMeta&&t.some(a=>a[0]===F))for(let a of Object.keys(this.meta))try{this.meta[a]._emit(gt)}catch{}let{finalMessages:s,equalsError:i}=this._updateState(t);if(s.length>0&&this._config.inspectorEnabled){let a=this._config.globalInspector;if(a!=null)try{a({kind:"emit",node:this,messages:s})}catch{}}if(s.length>0)if(this._paused&&this._pausable==="resumeAll"&&this._pauseBuffer!=null){let a=this._config.tierOf,d=[];for(let u of s)a(u[0])===3?this._pauseBuffer.push(u):d.push(u);d.length>0&&this._dispatchOrAccumulate(d)}else this._dispatchOrAccumulate(s);i!=null&&this._emit([[D,i]])}_updateState(e){let t=this._config.tierOf,r,o,s=-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]===M){d=c;break}}for(let c=0;c<e.length;c++){let f=e[c],p=f[0];if(p===M){if(f.length>=2){let h=!1;if(a&&this._cached!==void 0)try{h=this._equals(this._cached,f[1])}catch(l){o=this._wrapFnError("equals threw",l),s=c;break}if(h){r==null&&(r=e.slice(0,c)),r.push(ft),this._status="resolved";continue}this._cached=f[1],this._versioning!=null&&(d<0||c===d)&&Xn(this._versioning,f[1],this._hashFn)}this._status="settled",r?.push(f)}else if(r?.push(f),p===W)this._status="dirty";else if(p===K)this._status="resolved";else if(p===$){this._status="completed";{let h=this._config.rigorRecorder;if(h!=null)try{h.onTerminalTransition(this,"completed",this._autoComplete,this._autoError,this._deps.length>0)}catch{}}}else if(p===D){this._status="errored";{let h=this._config.rigorRecorder;if(h!=null)try{h.onTerminalTransition(this,"errored",this._autoComplete,this._autoError,this._deps.length>0)}catch{}}}else if(p===ee){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 h=this._cleanup;if(typeof h=="function"){this._cleanup=void 0;try{h()}catch{}}else if(h!=null&&typeof h=="object"){let l=h.invalidate;if(typeof l=="function")try{l()}catch{}}}else p===F&&(this._resetOnTeardown&&(this._cached=void 0),this._deactivate(!0),this._status="sentinel")}let u=s>=0?r??e.slice(0,s):r??e;return o!=null?{finalMessages:u,equalsError:o}:{finalMessages:u}}_deliverToSinks=e=>{if(this._sinks==null)return;if(typeof this._sinks=="function"){this._sinks(e);return}let t=[...this._sinks];for(let r of t)r(e)};_dispatchOrAccumulate(e){if(Un()){this._batchPendingMessages===null&&(this._batchPendingMessages=[],Ve(()=>this._flushBatchPending()));for(let t of e)this._batchPendingMessages.push(t);return}yt(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);yt(this._deliverToSinks,t,this._config.tierOf)}},rr=n=>Array.isArray(n),Zt=n=>typeof n=="object"&&n!=null&&!Array.isArray(n)});function Y(n,e){return le([],{...e,initial:n})}function Oe(n,e){return le((r,o,s)=>n(o,s)??void 0,{describeKind:"producer",...e})}function Q(n,e,t){return le(n,(o,s,i)=>{let a=o.map((d,u)=>d!=null&&d.length>0?d.at(-1):i.prevData[u]);s.emit(e(a,i))},{describeKind:"derived",...t})}var je=B(()=>{"use strict";Ee()});function tt(n,e,t){let r=new Set;for(let o of n.split(",")){let[s,i]=o.split("/"),a=i?Number.parseInt(i,10):1;if(Number.isNaN(a)||a<1)throw new Error(`Invalid cron step: ${o}`);let d,u;if(s==="*")d=e,u=t;else if(s.includes("-")){let[c,f]=s.split("-");d=Number.parseInt(c,10),u=Number.parseInt(f,10)}else d=Number.parseInt(s,10),u=d;if(Number.isNaN(d)||Number.isNaN(u))throw new Error(`Invalid cron field: ${n}`);if(d<e||u>t)throw new Error(`Cron field out of range: ${n} (${e}-${t})`);if(d>u)throw new Error(`Invalid cron range: ${d}-${u} in ${n}`);for(let c=d;c<=u;c+=a)r.add(c)}return r}function or(n){let e=n.trim().split(/\s+/);if(e.length!==5)throw new Error(`Invalid cron: expected 5 fields, got ${e.length}`);return{minutes:tt(e[0],0,59),hours:tt(e[1],0,23),daysOfMonth:tt(e[2],1,31),months:tt(e[3],1,12),daysOfWeek:tt(e[4],0,6)}}function sr(n,e){return n.minutes.has(e.getMinutes())&&n.hours.has(e.getHours())&&n.daysOfMonth.has(e.getDate())&&n.months.has(e.getMonth()+1)&&n.daysOfWeek.has(e.getDay())}var ir=B(()=>{"use strict"});function ar(n){return{describeKind:"producer",...n}}function ur(n,e){let{signal:t,period:r,...o}=e??{};return Oe(s=>{let i=!1,a=0,d,u,c=()=>{i=!0,d!==void 0&&clearTimeout(d),u!==void 0&&clearInterval(u),t?.removeEventListener("abort",p)},f=()=>{i||(r!=null?(s.emit(a++),u=setInterval(()=>{i||s.emit(a++)},r)):(i=!0,t?.removeEventListener("abort",p),s.emit(a++),s.down([[$]])))},p=()=>{i||(c(),s.down([[D,t.reason]]))};if(t?.aborted){p();return}return d=setTimeout(f,n),t?.addEventListener("abort",p,{once:!0}),c},ar(o))}function dr(n,e){let t=or(n),{tickMs:r,output:o,...s}=e??{},i=r??6e4,a=o==="date";return Oe(d=>{let u=-1,c=()=>{let p=new Date,h=p.getFullYear()*1e8+(p.getMonth()+1)*1e6+p.getDate()*1e4+p.getHours()*100+p.getMinutes();h!==u&&sr(t,p)&&(u=h,d.emit(a?p:re()))};c();let f=setInterval(c,i);return()=>clearInterval(f)},{...ar(s),name:s.name??`cron:${n}`})}function de(n){return n.subscribe(()=>{})}var _t=B(()=>{"use strict";$e();ae();je();ir()});function rt(n,e){if(e!=null&&e.length>0)return new Set(e);switch(n){case"standard":return new Set(["type","status","value","deps","meta","v"]);case"full":return null;case"spec":return new Set(["type","deps","meta"]);default:return new Set(["type","deps"])}}function Oo(n){return n._describeKind!=null?n._describeKind:n._deps.length>0?"derived":n._fn!=null?"producer":"state"}function on(n){let e=new WeakSet,t={};for(let[r,o]of mr(n))t[r]=rn(o,e);return t}function rn(n,e){if(n==null)return n;let t=typeof n;if(t==="boolean"||t==="number"||t==="string")return n;if(t==="function")return"<function>";if(Array.isArray(n))return e.has(n)?"<cycle>":(e.add(n),n.map(r=>rn(r,e)));if(t==="object"){let r=n;if(e.has(r))return"<cycle>";e.add(r);try{if(typeof r.subscribe=="function"&&"cache"in r)return"<Node>"}catch{return"<unserializable>"}let o={};for(let[s,i]of mr(r))o[s]=rn(i,e);return o}return"<unserializable>"}function mr(n){let e=[],t;try{t=Object.keys(n)}catch{return e}for(let r of t)try{e.push([r,n[r]])}catch{e.push([r,"<unserializable>"])}return e}function Ro(n){let e={};for(let[t,r]of Object.entries(n.meta))try{e[t]=r.cache}catch{}return e}function sn(n,e){let t=e==null,r=!t&&e!=null?[...e].filter(u=>u.startsWith("meta.")).map(u=>u.slice(5)):null,o=t||e.has("meta")||r!=null&&r.length>0,s="state",i=[];n instanceof V&&(s=Oo(n),i=n._deps.map(u=>u.node.name??""));let a={type:s,deps:i};(t||e.has("status"))&&(a.status=n.status);let d=n instanceof V?n._guard:void 0;if(o){let u={...Ro(n)};if(d!=null&&u.access===void 0&&(u.access=Ut(d)),r!=null&&r.length>0&&!e.has("meta")){let c={};for(let f of r)f in u&&(c[f]=u[f]);a.meta=c}else a.meta=u}if(n.name!=null&&(a.name=n.name),t||e.has("value")){n.status==="sentinel"&&(a.sentinel=!0);try{a.value=n.cache}catch{}}if((t||e.has("v"))&&n.v!=null){let u={id:n.v.id,version:n.v.version};"cid"in n.v&&(u.cid=n.v.cid,u.prev=n.v.prev),a.v=u}return(t||e.has("guard"))&&d!=null&&(a.guard=Ut(d)),(t||e.has("lastMutation"))&&n.lastMutation!=null&&(a.lastMutation=n.lastMutation),a}var an=B(()=>{"use strict";xe();Ee()});var Et,br=B(()=>{"use strict";Et=class{_timer;_gen=0;start(e,t){this.cancel(),this._gen+=1;let r=this._gen;this._timer=setTimeout(()=>{this._timer=void 0,r===this._gen&&t()},e)}cancel(){this._timer!==void 0&&(clearTimeout(this._timer),this._timer=void 0)}get pending(){return this._timer!==void 0}}});var Es={};ro(Es,{ACTOR_KEY:()=>Tt,COMMAND_HANDLERS:()=>Ge,CQRS_EVENT_HANDLERS:()=>Le,CRON_HANDLERS:()=>De,CommandHandler:()=>Fn,EVENT_HANDLERS:()=>Ce,EventHandler:()=>Vn,GRAPHREFLY_REQUEST_GRAPH:()=>be,GRAPHREFLY_ROOT_GRAPH:()=>ne,GraphCron:()=>Hn,GraphInterval:()=>$n,GraphReflyEventExplorer:()=>Re,GraphReflyGuard:()=>gr,GraphReflyGuardImpl:()=>nt,GraphReflyModule:()=>$t,INTERVAL_HANDLERS:()=>Me,InjectCqrsGraph:()=>Ln,InjectGraph:()=>Gn,InjectNode:()=>In,ObserveGateway:()=>xt,OnGraphEvent:()=>Pn,QUERY_HANDLERS:()=>Ie,QueryHandler:()=>zn,SAGA_HANDLERS:()=>Pe,SagaHandler:()=>qn,fromHeader:()=>pr,fromJwtPayload:()=>nn,getActor:()=>hr,getGraphToken:()=>U,getNodeToken:()=>ue,observeSSE:()=>lr,observeSubscription:()=>fr,toObservable:()=>Dn});module.exports=so(Es);var Bt=require("rxjs");ae();function Dn(n,e){return e?.raw?new Bt.Observable(t=>n.subscribe(o=>{if(!t.closed){t.next(o);for(let s of o){if(s[0]===D){t.error(s[1]);return}if(s[0]===$){t.complete();return}}}})):new Bt.Observable(t=>n.subscribe(o=>{for(let s of o){if(t.closed)return;if(s[0]===M)t.next(s[1]);else if(s[0]===D){t.error(s[1]);return}else if(s[0]===$){t.complete();return}}}))}var Je=require("@nestjs/common");var ne=Symbol.for("graphrefly:root-graph");var be=Symbol.for("graphrefly:request-graph");function U(n){return Symbol.for(`graphrefly:graph:${n}`)}function ue(n){return Symbol.for(`graphrefly:node:${n}`)}var Ce=new Map,Me=new Map,De=new Map,Ge=new Map,Le=new Map,Ie=new Map,Pe=new Map;function Gn(n){return n==="request"?(0,Je.Inject)(be):(0,Je.Inject)(n?U(n):ne)}function Ln(n){return(0,Je.Inject)(U(n))}function In(n){return(0,Je.Inject)(ue(n))}function Pn(n){return(e,t)=>{let r=t.name;t.addInitializer(function(){let o=this.constructor,s=Ce.get(o)??[];s.push({nodeName:n,methodKey:r}),Ce.set(o,s)})}}function $n(n){return(e,t)=>{let r=t.name;t.addInitializer(function(){let o=this.constructor,s=Me.get(o)??[];s.push({ms:n,methodKey:r}),Me.set(o,s)})}}function Hn(n){return(e,t)=>{let r=t.name;t.addInitializer(function(){let o=this.constructor,s=De.get(o)??[];s.push({expr:n,methodKey:r}),De.set(o,s)})}}function Fn(n,e){return(t,r)=>{let o=r.name;r.addInitializer(function(){let s=this.constructor,i=Ge.get(s)??[];i.push({cqrsName:n,commandName:e,methodKey:o}),Ge.set(s,i)})}}function Vn(n,e){return(t,r)=>{let o=r.name;r.addInitializer(function(){let s=this.constructor,i=Le.get(s)??[];i.push({cqrsName:n,eventName:e,methodKey:o}),Le.set(s,i)})}}function zn(n,e){return(t,r)=>{let o=r.name;r.addInitializer(function(){let s=this.constructor,i=Ie.get(s)??[];i.push({cqrsName:n,projectionName:e,methodKey:o}),Ie.set(s,i)})}}function qn(n,e,t){return(r,o)=>{let s=o.name;o.addInitializer(function(){let i=this.constructor,a=Pe.get(i)??[];a.push({cqrsName:n,eventNames:t,sagaName:e,methodKey:s}),Pe.set(i,a)})}}ae();_t();var cr=0,Re=class{constructor(e,t){this.graph=e;this.moduleRef=t}disposers=[];scheduleNodeNames=[];onModuleInit(){this.wireEvents(),this.wireIntervals(),this.wireCrons(),this.wireCqrsCommands(),this.wireCqrsEvents(),this.wireCqrsQueries(),this.wireCqrsSagas()}onModuleDestroy(){for(let e of this.disposers)e();this.disposers.length=0;for(let e of this.scheduleNodeNames)try{this.graph.remove(e)}catch{}this.scheduleNodeNames.length=0}wireEvents(){for(let[e,t]of Ce){let r=this.resolveInstance(e);if(r)for(let o of t)this.wireEventHandler(r,o)}}wireEventHandler(e,t){let r=e[t.methodKey];if(typeof r!="function")return;let o=r.bind(e),i=this.observeNode(t.nodeName).subscribe(a=>{for(let d of a)d[0]===M&&o(d[1])});this.disposers.push(i)}wireIntervals(){for(let[e,t]of Me){let r=this.resolveInstance(e);if(r)for(let o of t)this.wireIntervalHandler(r,e,o)}}wireIntervalHandler(e,t,r){let o=e[r.methodKey];if(typeof o!="function")return;let s=o.bind(e),a=`__schedule__.${t.name??"anonymous"}.${String(r.methodKey)}.${cr++}`,d=ur(r.ms,{period:r.ms,name:a});this.graph.add(d),this.scheduleNodeNames.push(a);let c=this.observeNode(a).subscribe(f=>{for(let p of f)p[0]===M&&s(p[1])});this.disposers.push(c)}wireCrons(){for(let[e,t]of De){let r=this.resolveInstance(e);if(r)for(let o of t)this.wireCronHandler(r,e,o)}}wireCronHandler(e,t,r){let o=e[r.methodKey];if(typeof o!="function")return;let s=o.bind(e),a=`__schedule__.${t.name??"anonymous"}.${String(r.methodKey)}.${cr++}`,d=dr(r.expr,{name:a});this.graph.add(d),this.scheduleNodeNames.push(a);let c=this.observeNode(a).subscribe(f=>{for(let p of f)p[0]===M&&s(p[1])});this.disposers.push(c)}wireCqrsCommands(){for(let[e,t]of Ge){let r=this.resolveInstance(e);if(r)for(let o of t)this.wireCqrsCommand(r,o)}}wireCqrsCommand(e,t){let r=e[t.methodKey];if(typeof r!="function")return;let o=r.bind(e),s=this.resolveCqrsGraph(t.cqrsName);s&&s.command(t.commandName,o)}wireCqrsEvents(){for(let[e,t]of Le){let r=this.resolveInstance(e);if(r)for(let o of t)this.wireCqrsEventHandler(r,o)}}wireCqrsEventHandler(e,t){let r=e[t.methodKey];if(typeof r!="function")return;let o=r.bind(e),s=this.resolveCqrsGraph(t.cqrsName);if(!s)return;s.event(t.eventName);let a=s.resolve(t.eventName).cache,d=a&&a.length>0?a[a.length-1].seq:0,c=this.observeNodeOn(s,t.eventName).subscribe(f=>{for(let p of f)if(p[0]===M){let h=p[1];for(let l of h)l.seq>d&&(o(l),d=l.seq)}});this.disposers.push(c)}wireCqrsQueries(){for(let[e,t]of Ie){let r=this.resolveInstance(e);if(r)for(let o of t)this.wireCqrsQuery(r,o)}}wireCqrsQuery(e,t){let r=e[t.methodKey];if(typeof r!="function")return;let o=r.bind(e),s=this.resolveCqrsGraph(t.cqrsName);if(!s)return;let a=this.observeNodeOn(s,t.projectionName).subscribe(d=>{for(let u of d)u[0]===M&&o(u[1])});this.disposers.push(a)}wireCqrsSagas(){for(let[e,t]of Pe){let r=this.resolveInstance(e);if(r)for(let o of t)this.wireCqrsSaga(r,o)}}wireCqrsSaga(e,t){let r=e[t.methodKey];if(typeof r!="function")return;let o=r.bind(e),s=this.resolveCqrsGraph(t.cqrsName);s&&s.saga(t.sagaName,t.eventNames,o)}observeNode(e){return this.graph.observe(e)}observeNodeOn(e,t){return e.observe(t)}resolveCqrsGraph(e){try{return this.moduleRef.get(U(e),{strict:!1})}catch{return console.warn(`[GraphReFly] CqrsGraph "${e}" not found in DI \u2014 did you import GraphReflyModule.forCqrs({ name: "${e}" })?`),null}}resolveInstance(e){try{return this.moduleRef.get(e,{strict:!1})}catch{return null}}};ae();ae();var wo=0;function wt(n,e){if(e.highWaterMark<1)throw new RangeError("highWaterMark must be >= 1");if(e.lowWaterMark<0)throw new RangeError("lowWaterMark must be >= 0");if(e.lowWaterMark>=e.highWaterMark)throw new RangeError("lowWaterMark must be < highWaterMark");let t=Symbol(`bp-${++wo}`),r=0,o=!1;return{onEnqueue(){return r+=1,!o&&r>=e.highWaterMark?(o=!0,n([[J,t]]),!0):!1},onDequeue(){return r>0&&(r-=1),o&&r<=e.lowWaterMark?(o=!1,n([[te,t]]),!0):!1},get pending(){return r},get paused(){return o},dispose(){o&&(o=!1,n([[te,t]]))}}}function lr(n,e,t){let{actor:r,serialize:o=xo,keepAliveMs:s,signal:i}=t??{},a=new TextEncoder,d,u=t?.highWaterMark!=null,c,f,p=[],h=!1;return new ReadableStream({start(l){let y,m=()=>{},x=()=>{if(!h){h=!0,y!==void 0&&clearInterval(y),i?.removeEventListener("abort",_),m(),c?.dispose(),f?.(),f=void 0;for(let b of p)l.enqueue(b.frame);p.length=0,l.close()}};d=x;let _=()=>x(),v=n.observe(e,{actor:r});u&&(c=wt(b=>v.up(b),{highWaterMark:t.highWaterMark,lowWaterMark:t.lowWaterMark??Math.floor(t.highWaterMark/2)})),m=v.subscribe(b=>{for(let O of b){if(h)return;let R=O[0];if(R===M){let g=a.encode(en("data",o(O[1])));u?(p.push({frame:g,counted:!0}),c.onEnqueue(),f?.(),f=void 0):l.enqueue(g)}else if(R===D){let g=a.encode(en("error",o(O[1])));u?(p.push({frame:g,counted:!1}),f?.(),f=void 0):l.enqueue(g),x();return}else if(R===$||R===F){if(R===$){let g=a.encode(en("complete"));u?(p.push({frame:g,counted:!1}),f?.(),f=void 0):l.enqueue(g)}x();return}}}),s!==void 0&&s>0&&(y=setInterval(()=>{h||(u?(p.push({frame:a.encode(`: keepalive
|
|
1
|
+
"use strict";var Fr=Object.create;var Ce=Object.defineProperty;var _n=Object.getOwnPropertyDescriptor;var Hr=Object.getOwnPropertyNames;var qr=Object.prototype.hasOwnProperty;var wn=(r,e)=>(e=Symbol[r])?e:Symbol.for("Symbol."+r),Je=r=>{throw TypeError(r)};var Vr=(r,e,t)=>e in r?Ce(r,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[e]=t;var yn=(r,e)=>Ce(r,"name",{value:e,configurable:!0});var z=(r,e)=>()=>(r&&(e=r(r=0)),e);var zr=(r,e)=>{for(var t in e)Ce(r,t,{get:e[t],enumerable:!0})},jr=(r,e,t,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let s of Hr(e))!qr.call(r,s)&&s!==t&&Ce(r,s,{get:()=>e[s],enumerable:!(n=_n(e,s))||n.enumerable});return r};var Br=r=>jr(Ce({},"__esModule",{value:!0}),r);var Tn=r=>[,,,Fr(r?.[wn("metadata")]??null)],En=["class","method","getter","setter","accessor","field","value","get","set"],Ye=r=>r!==void 0&&typeof r!="function"?Je("Function expected"):r,Wr=(r,e,t,n,s)=>({kind:En[r],name:e,metadata:n,addInitializer:o=>t._?Je("Already initialized"):s.push(Ye(o||null))}),Ur=(r,e)=>Vr(e,wn("metadata"),r[3]),On=(r,e,t,n)=>{for(var s=0,o=r[e>>1],i=o&&o.length;s<i;s++)e&1?o[s].call(t):n=o[s].call(t,n);return n},xn=(r,e,t,n,s,o)=>{var i,a,d,u,c,f=e&7,p=!!(e&8),h=!!(e&16),l=f>3?r.length+1:f?p?1:2:0,y=En[f+5],g=f>3&&(r[l-1]=[]),E=r[l]||(r[l]=[]),v=f&&(!h&&!p&&(s=s.prototype),f<5&&(f>3||!h)&&_n(f<4?s:{get[t](){return bn(this,o)},set[t](b){return vn(this,o,b)}},t));f?h&&f<4&&yn(o,(f>2?"set ":f>1?"get ":"")+t):yn(s,t);for(var _=n.length-1;_>=0;_--)u=Wr(f,t,d={},r[3],E),f&&(u.static=p,u.private=h,c=u.access={has:h?b=>Kr(s,b):b=>t in b},f^3&&(c.get=h?b=>(f^1?bn:Yr)(b,s,f^4?o:v.get):b=>b[t]),f>2&&(c.set=h?(b,w)=>vn(b,s,w,f^4?o:v.set):(b,w)=>b[t]=w)),a=(0,n[_])(f?f<4?h?o:v[y]:f>4?void 0:{get:v.get,set:v.set}:s,u),d._=1,f^4||a===void 0?Ye(a)&&(f>4?g.unshift(a):f?h?o=a:v[y]=a:s=a):typeof a!="object"||a===null?Je("Object expected"):(Ye(i=a.get)&&(v.get=i),Ye(i=a.set)&&(v.set=i),Ye(i=a.init)&&g.unshift(i));return f||Ur(r,s),v&&Ce(s,t,v),h?f^4?o:v:s};var $t=(r,e,t)=>e.has(r)||Je("Cannot "+t),Kr=(r,e)=>Object(e)!==e?Je('Cannot use the "in" operator on this value'):r.has(e),bn=(r,e,t)=>($t(r,e,"read from private field"),t?t.call(r):e.get(r));var vn=(r,e,t,n)=>($t(r,e,"write to private field"),n?n.call(r,t):e.set(r,t),t),Yr=(r,e,t)=>($t(r,e,"access private method"),t);var me,M,B,W,ee,J,te,$,I,D,ye,ft,kn,pt,Nn,Rn,ht,Ft,Ht,qt,gt,ae=z(()=>{"use strict";me=Symbol.for("graphrefly/START"),M=Symbol.for("graphrefly/DATA"),B=Symbol.for("graphrefly/DIRTY"),W=Symbol.for("graphrefly/RESOLVED"),ee=Symbol.for("graphrefly/INVALIDATE"),J=Symbol.for("graphrefly/PAUSE"),te=Symbol.for("graphrefly/RESUME"),$=Symbol.for("graphrefly/TEARDOWN"),I=Symbol.for("graphrefly/COMPLETE"),D=Symbol.for("graphrefly/ERROR"),ye=Object.freeze([B]),ft=Object.freeze([W]),kn=Object.freeze([ee]),pt=Object.freeze([me]),Nn=Object.freeze([I]),Rn=Object.freeze([$]),ht=Object.freeze([ye]),Ft=Object.freeze([ft]),Ht=Object.freeze([kn]),qt=Object.freeze([Nn]),gt=Object.freeze([Rn])});function ue(){return Math.trunc(performance.now()*1e6)}function re(){return Date.now()*1e6}var Fe=z(()=>{"use strict"});function qn(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++]=zt,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 Vn(r,e){if(r.length<Hn)throw new Error(`decodeEnvelope: bytes too short (${r.length} < ${Hn})`);let t=0,n=r[t++];if(n!==zt)throw new Error(`decodeEnvelope: unsupported envelope version ${n} (expected ${zt})`);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 zn(r){r.registerCodec(Jr)}var Jr,zt,Hn,jt=z(()=>{"use strict";Jr={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)}},zt=1,Hn=4});function ve(r){if(r==null)return fe;let{type:e,id:t,...n}=r;return{type:e??"system",id:t??"",...n}}var fe,Ze=z(()=>{"use strict";fe={type:"system",id:""}});function mt(){return He>0||Xe}function jn(){return He>0}function Ve(r){He>0?et.push(r):r()}function ze(r){He+=1;let e=!1;try{r()}catch(t){throw e=!0,t}finally{if(He-=1,He===0)if(e){if(!Xe){let t=et.splice(0);for(let n of t)try{n()}catch{}_e.length=0,we.length=0,qe.length=0}}else Qr()}}function Qr(){let r=!Xe;r&&(Xe=!0);let e=[],t=0;try{for(;_e.length>0||we.length>0||qe.length>0||r&&et.length>0;){if(r&&et.length>0){let o=et.splice(0);for(let i of o)try{i()}catch(a){e.push(a)}continue}if(t+=1,t>1e3)throw _e.length=0,we.length=0,qe.length=0,new Error("batch drain exceeded 1000 iterations \u2014 likely a reactive cycle");let s=(_e.length>0?_e:we.length>0?we:qe).splice(0);for(let o of s)try{o()}catch(i){e.push(i)}}}finally{r&&(Xe=!1)}if(e.length===1)throw e[0];if(e.length>1)throw new AggregateError(e,"batch drain: multiple callbacks threw")}function yt(r,e,t){if(e.length===0)return;if(e.length===1){let u=t(e[0][0]);if(u<3||!mt()){r(e);return}(u>=5?qe:u===4?we:_e).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=mt();if(s>0){let u=e.slice(0,s);r(u)}if(o>s){let u=e.slice(s,o);d?_e.push(()=>r(u)):r(u)}if(i>o){let u=e.slice(o,i);d?we.push(()=>r(u)):r(u)}if(n>i){let u=e.slice(i,n);d?qe.push(()=>r(u)):r(u)}}var He,Xe,_e,we,qe,et,tt=z(()=>{"use strict";He=0,Xe=!1,_e=[],we=[],qe=[],et=[]});function Bn(r){r.registerMessageType(me,{tier:0,wireCrossing:!1}),r.registerMessageType(B,{tier:1,wireCrossing:!1}),r.registerMessageType(ee,{tier:1,wireCrossing:!1,metaPassthrough:!1}),r.registerMessageType(J,{tier:2,wireCrossing:!1}),r.registerMessageType(te,{tier:2,wireCrossing:!1}),r.registerMessageType(M,{tier:3,wireCrossing:!0}),r.registerMessageType(W,{tier:3,wireCrossing:!0}),r.registerMessageType(I,{tier:4,wireCrossing:!0,metaPassthrough:!1}),r.registerMessageType(D,{tier:4,wireCrossing:!0,metaPassthrough:!1}),r.registerMessageType($,{tier:5,wireCrossing:!0,metaPassthrough:!1})}var bt,Wn=z(()=>{"use strict";ae();bt=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 Un(r){return Array.isArray(r)?[...r]:[r]}function Zr(r,e){return r.has(e)||r.has("*")}function je(r){let e=[];return r((s,o)=>{e.push({kind:"allow",actions:new Set(Un(s)),where:o?.where??(()=>!0)})},(s,o)=>{e.push({kind:"deny",actions:new Set(Un(s)),where:o?.where??(()=>!0)})}),(s,o)=>{let i=!1,a=!1;for(let d of e)Zr(d.actions,o)&&d.where(s)&&(d.kind==="deny"?i=!0:a=!0);return i?!1:a}}function Bt(r){let e=Xr.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 se,Xr,Te=z(()=>{"use strict";se=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}};Xr=["human","llm","wallet","system"]});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 ns(r){let e=ts.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,f=1359893119,p=2600822924,h=528734635,l=1541459225,y=new Uint32Array(64),g=(v,_)=>v>>>_|v<<32-_;for(let v=0;v<s;v+=64){for(let T=0;T<16;T++)y[T]=i.getUint32(v+T*4,!1);for(let T=16;T<64;T++){let R=y[T-15],C=y[T-2],S=g(R,7)^g(R,18)^R>>>3,F=g(C,17)^g(C,19)^C>>>10;y[T]=y[T-16]+S+y[T-7]+F>>>0}let _=a,b=d,w=u,k=c,m=f,x=p,N=h,O=l;for(let T=0;T<64;T++){let R=g(m,6)^g(m,11)^g(m,25),C=m&x^~m&N,S=O+R+C+es[T]+y[T]>>>0,F=g(_,2)^g(_,13)^g(_,22),V=_&b^_&w^b&w,Y=F+V>>>0;O=N,N=x,x=m,m=k+S>>>0,k=w,w=b,b=_,_=S+Y>>>0}a=a+_>>>0,d=d+b>>>0,u=u+w>>>0,c=c+k>>>0,f=f+m>>>0,p=p+x>>>0,h=h+N>>>0,l=l+O>>>0}let E=v=>v.toString(16).padStart(8,"0");return E(a)+E(d)+E(u)+E(c)+E(f)+E(p)+E(h)+E(l)}function Ut(r){let e=Wt(r??null),t=JSON.stringify(e);return ns(t).slice(0,16)}function rs(){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 Kt(r,e,t){let n=t?.id??rs();if(r===0)return{id:n,version:0};let o=(t?.hash??Ut)(e);return{id:n,version:0,cid:o,prev:null}}function Kn(r,e,t){r.version+=1,"cid"in r&&(r.prev=r.cid,r.cid=t(e))}var es,ts,Yn=z(()=>{"use strict";es=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]),ts=new TextEncoder});function Zn(r){return{node:r,unsub:null,prevData:void 0,dirty:!1,involvedThisWave:!1,dataBatch:[],terminal:void 0}}function Yt(r){r.prevData=void 0,r.dirty=!1,r.involvedThisWave=!1,r.dataBatch.length=0,r.terminal=void 0}function vt(r){return r.length===0?r:typeof r[0]=="symbol"?[r]:r}function ce(r,e,t){let n=Xn(r)?r:[],s=typeof r=="function"?r:typeof e=="function"?e:void 0,o={};return Xn(r)?o=(Jt(e)?e:t)??{}:Jt(r)?o=r:o=(Jt(e)?e:t)??{},new H(n,s,o)}var Jn,Qn,ss,os,Ee,H,Xn,Jt,Oe=z(()=>{"use strict";jt();Ze();tt();Fe();Wn();Te();ae();Yn();Jn=()=>{},Qn=100;ss=(r,e,t,n)=>{t.direction==="down-in"&&r._onDepMessage(t.depIndex,e)},os=(r,e,t,n)=>{let s=r;if(s._status==="completed"||s._status==="errored")return;let o=s._cached,i=o===void 0?[pt]:[pt,[M,o]];s._status==="dirty"&&i.push(ye),yt(e,i,s._config.tierOf)},Ee=new bt({onMessage:ss,onSubscribe:os});Bn(Ee);zn(Ee);H=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??Ee,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??Ut;let s=n.versioning??this._config.defaultVersioning;this._versioningLevel=s,this._versioning=s!=null?Kt(s,this._cached===void 0?void 0:this._cached,{id:n.versioningId,hash:this._hashFn}):void 0,this._deps=e.map(Zn);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([[M,a]])},down(a){i._emit(vt(a))},up(a){i._emitUp(vt(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=Kt(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=ve(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=ve(e?.actor),o=e?.delivery==="signal"?"signal":"write";if(this._guard!=null&&!this._guard(s,o))throw new se({actor:s,action:o,nodeName:this.name});if(this._extraGuards!=null){for(let i of this._extraGuards)if(!i(s,o))throw new se({actor:s,action:o,nodeName:this.name})}this._lastMutation={actor:s,timestamp_ns:re()}}down(e,t){let n=vt(e);n.length!==0&&(this._checkGuard(t),this._emit(n))}emit(e,t){this._checkGuard(t),this._emit([[M,e]])}up(e,t){if(this._deps.length===0)return;let n=vt(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=ve(t);if(!this._guard(d,"observe"))throw new se({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)Yt(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=Jn,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{}Yt(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=Zn(e);if(this._deps.push(n),this._sinks==null)return t;n.dirty=!0,this._dirtyDepCount++,this._status!=="dirty"&&this._emit(ht),n.unsub=Jn;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([[D,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([[D,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{}}Yt(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!==me){if(s===B){this._depDirtied(n);return}if(s===ee){if(this._depInvalidated(n),this._cached===void 0)return;this._emit(Ht);return}if(s===J||s===te){this._emit([t]);return}if(s===$){this._emit(gt);return}if(s===M)this._depSettledAsData(n,t[1]);else if(s===W)this._depSettledAsResolved(n);else if(s===I)this._depSettledAsTerminal(n,!0);else if(s===D)this._depSettledAsTerminal(n,t[1]);else{this._emit([t]);return}if(!this._fn){(s===M||s===W)&&this._emit([t]),(s===I||s===D)&&this._maybeAutoTerminalAfterWave();return}}}_depDirtied(e){e.dirty||(e.dirty=!0,e.involvedThisWave=!0,this._dirtyDepCount++,this._status!=="dirty"&&this._emit(ht))}_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(Ft),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([[D,e.terminal]]);return}this._autoComplete&&this._deps.every(t=>t.terminal!==void 0)&&this._emit(qt)}_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([[D,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([[D,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([[D,this._wrapFnError("fn threw",i)]])}finally{this._isExecutingFn=!1,this._pendingRerun?(this._pendingRerun=!1,this._rerunDepth+=1,this._rerunDepth>Qn?(this._rerunDepth=0,this._emit([[D,new Error(`Node "${this.name}": _pendingRerun depth exceeded ${Qn} \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"?[ye,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]===B&&(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?[ye,...a]:[...a.slice(0,d),ye,...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]===D&&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]===$||d[0]===ee);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!==J&&u!==te){s?.push(d);continue}if(d.length<2)throw new Error(`Node "${this.name}": [[${u===J?"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 f=d[1];if(u===J)this._pauseLocks==null&&(this._pauseLocks=new Set),this._pauseLocks.add(f),this._paused=!0,this._pausable==="resumeAll"&&this._pauseBuffer==null&&(this._pauseBuffer=[]);else if(this._pauseLocks==null||!this._pauseLocks.has(f))c=!1;else if(this._pauseLocks.delete(f),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(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]===$))for(let a of Object.keys(this.meta))try{this.meta[a]._emit(gt)}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([[D,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]===M){d=c;break}}for(let c=0;c<e.length;c++){let f=e[c],p=f[0];if(p===M){if(f.length>=2){let h=!1;if(a&&this._cached!==void 0)try{h=this._equals(this._cached,f[1])}catch(l){s=this._wrapFnError("equals threw",l),o=c;break}if(h){n==null&&(n=e.slice(0,c)),n.push(ft),this._status="resolved";continue}this._cached=f[1],this._versioning!=null&&(d<0||c===d)&&Kn(this._versioning,f[1],this._hashFn)}this._status="settled",n?.push(f)}else if(n?.push(f),p===B)this._status="dirty";else if(p===W)this._status="resolved";else if(p===I){this._status="completed";{let h=this._config.rigorRecorder;if(h!=null)try{h.onTerminalTransition(this,"completed",this._autoComplete,this._autoError,this._deps.length>0)}catch{}}}else if(p===D){this._status="errored";{let h=this._config.rigorRecorder;if(h!=null)try{h.onTerminalTransition(this,"errored",this._autoComplete,this._autoError,this._deps.length>0)}catch{}}}else if(p===ee){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 h=this._cleanup;if(typeof h=="function"){this._cleanup=void 0;try{h()}catch{}}else if(h!=null&&typeof h=="object"){let l=h.invalidate;if(typeof l=="function")try{l()}catch{}}}else p===$&&(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(jn()){this._batchPendingMessages===null&&(this._batchPendingMessages=[],Ve(()=>this._flushBatchPending()));for(let t of e)this._batchPendingMessages.push(t);return}yt(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);yt(this._deliverToSinks,t,this._config.tierOf)}},Xn=r=>Array.isArray(r),Jt=r=>typeof r=="object"&&r!=null&&!Array.isArray(r)});function K(r,e){return ce([],{...e,initial:r})}function xe(r,e){return ce((n,s,o)=>r(s,o)??void 0,{describeKind:"producer",...e})}function Q(r,e,t){return ce(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 Be=z(()=>{"use strict";Oe()});function nt(r,e,t){let n=new Set;for(let s of r.split(",")){let[o,i]=s.split("/"),a=i?Number.parseInt(i,10):1;if(Number.isNaN(a)||a<1)throw new Error(`Invalid cron step: ${s}`);let d,u;if(o==="*")d=e,u=t;else if(o.includes("-")){let[c,f]=o.split("-");d=Number.parseInt(c,10),u=Number.parseInt(f,10)}else d=Number.parseInt(o,10),u=d;if(Number.isNaN(d)||Number.isNaN(u))throw new Error(`Invalid cron field: ${r}`);if(d<e||u>t)throw new Error(`Cron field out of range: ${r} (${e}-${t})`);if(d>u)throw new Error(`Invalid cron range: ${d}-${u} in ${r}`);for(let c=d;c<=u;c+=a)n.add(c)}return n}function er(r){let e=r.trim().split(/\s+/);if(e.length!==5)throw new Error(`Invalid cron: expected 5 fields, got ${e.length}`);return{minutes:nt(e[0],0,59),hours:nt(e[1],0,23),daysOfMonth:nt(e[2],1,31),months:nt(e[3],1,12),daysOfWeek:nt(e[4],0,6)}}function tr(r,e){return r.minutes.has(e.getMinutes())&&r.hours.has(e.getHours())&&r.daysOfMonth.has(e.getDate())&&r.months.has(e.getMonth()+1)&&r.daysOfWeek.has(e.getDay())}var nr=z(()=>{"use strict"});function rr(r){return{describeKind:"producer",...r}}function sr(r,e){let{signal:t,period:n,...s}=e??{};return xe(o=>{let i=!1,a=0,d,u,c=()=>{i=!0,d!==void 0&&clearTimeout(d),u!==void 0&&clearInterval(u),t?.removeEventListener("abort",p)},f=()=>{i||(n!=null?(o.emit(a++),u=setInterval(()=>{i||o.emit(a++)},n)):(i=!0,t?.removeEventListener("abort",p),o.emit(a++),o.down([[I]])))},p=()=>{i||(c(),o.down([[D,t.reason]]))};if(t?.aborted){p();return}return d=setTimeout(f,r),t?.addEventListener("abort",p,{once:!0}),c},rr(s))}function or(r,e){let t=er(r),{tickMs:n,output:s,...o}=e??{},i=n??6e4,a=s==="date";return xe(d=>{let u=-1,c=()=>{let p=new Date,h=p.getFullYear()*1e8+(p.getMonth()+1)*1e6+p.getDate()*1e4+p.getHours()*100+p.getMinutes();h!==u&&tr(t,p)&&(u=h,d.emit(a?p:re()))};c();let f=setInterval(c,i);return()=>clearInterval(f)},{...rr(o),name:o.name??`cron:${r}`})}function le(r){return r.subscribe(()=>{})}var ir=z(()=>{"use strict";Fe();ae();Be();nr()});var _t=z(()=>{"use strict";ir()});function Ot(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 cs(r){return r._describeKind!=null?r._describeKind:r._deps.length>0?"derived":r._fn!=null?"producer":"state"}function tn(r){let e=new WeakSet,t={};for(let[n,s]of pr(r))t[n]=en(s,e);return t}function en(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=>en(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 pr(n))s[o]=en(i,e);return s}return"<unserializable>"}function pr(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 ls(r){let e={};for(let[t,n]of Object.entries(r.meta))try{e[t]=n.cache}catch{}return e}function nn(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 H&&(i=cs(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 H?r._guard:void 0;if(o){let c={...ls(r)};if(u!=null&&c.access===void 0&&(c.access=Bt(u)),s!=null&&s.length>0&&!e.has("meta")){let f={};for(let p of s)p in c&&(f[p]=c[p]);d.meta=f}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=Bt(u)),(n||e.has("lastMutation"))&&r.lastMutation!=null&&(d.lastMutation=r.lastMutation),d}var rn=z(()=>{"use strict";Te();Oe()});var xt,gr=z(()=>{"use strict";xt=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 st,mr=z(()=>{"use strict";st=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 Dr(r,e,t){return{[r]:!0,[`${r}_type`]:e,...t??{}}}var Gr=z(()=>{"use strict"});var Ds={};zr(Ds,{ACTOR_KEY:()=>Et,COMMAND_HANDLERS:()=>Ie,CQRS_EVENT_HANDLERS:()=>Pe,CRON_HANDLERS:()=>Ge,CommandHandler:()=>Pn,EVENT_HANDLERS:()=>Me,EventHandler:()=>Ln,GRAPHREFLY_REQUEST_GRAPH:()=>be,GRAPHREFLY_ROOT_GRAPH:()=>ne,GraphCron:()=>In,GraphInterval:()=>Gn,GraphReflyEventExplorer:()=>ke,GraphReflyGuard:()=>fr,GraphReflyGuardImpl:()=>rt,GraphReflyModule:()=>It,INTERVAL_HANDLERS:()=>De,InjectCqrsGraph:()=>Cn,InjectGraph:()=>An,InjectNode:()=>Mn,ObserveGateway:()=>Tt,OnGraphEvent:()=>Dn,QUERY_HANDLERS:()=>Le,QueryHandler:()=>$n,SAGA_HANDLERS:()=>$e,SagaHandler:()=>Fn,fromHeader:()=>cr,fromJwtPayload:()=>Xt,getActor:()=>lr,getGraphToken:()=>U,getNodeToken:()=>de,observeSSE:()=>dr,observeSubscription:()=>ur,toObservable:()=>Sn});module.exports=Br(Ds);var Vt=require("rxjs");ae();function Sn(r,e){return e?.raw?new Vt.Observable(t=>r.subscribe(s=>{if(!t.closed){t.next(s);for(let o of s){if(o[0]===D){t.error(o[1]);return}if(o[0]===I){t.complete();return}}}})):new Vt.Observable(t=>r.subscribe(s=>{for(let o of s){if(t.closed)return;if(o[0]===M)t.next(o[1]);else if(o[0]===D){t.error(o[1]);return}else if(o[0]===I){t.complete();return}}}))}var Qe=require("@nestjs/common");var ne=Symbol.for("graphrefly:root-graph");var be=Symbol.for("graphrefly:request-graph");function U(r){return Symbol.for(`graphrefly:graph:${r}`)}function de(r){return Symbol.for(`graphrefly:node:${r}`)}var Me=new Map,De=new Map,Ge=new Map,Ie=new Map,Pe=new Map,Le=new Map,$e=new Map;function An(r){return r==="request"?(0,Qe.Inject)(be):(0,Qe.Inject)(r?U(r):ne)}function Cn(r){return(0,Qe.Inject)(U(r))}function Mn(r){return(0,Qe.Inject)(de(r))}function Dn(r){return(e,t)=>{let n=t.name;t.addInitializer(function(){let s=this.constructor,o=Me.get(s)??[];o.push({nodeName:r,methodKey:n}),Me.set(s,o)})}}function Gn(r){return(e,t)=>{let n=t.name;t.addInitializer(function(){let s=this.constructor,o=De.get(s)??[];o.push({ms:r,methodKey:n}),De.set(s,o)})}}function In(r){return(e,t)=>{let n=t.name;t.addInitializer(function(){let s=this.constructor,o=Ge.get(s)??[];o.push({expr:r,methodKey:n}),Ge.set(s,o)})}}function Pn(r,e){return(t,n)=>{let s=n.name;n.addInitializer(function(){let o=this.constructor,i=Ie.get(o)??[];i.push({cqrsName:r,commandName:e,methodKey:s}),Ie.set(o,i)})}}function Ln(r,e){return(t,n)=>{let s=n.name;n.addInitializer(function(){let o=this.constructor,i=Pe.get(o)??[];i.push({cqrsName:r,eventName:e,methodKey:s}),Pe.set(o,i)})}}function $n(r,e){return(t,n)=>{let s=n.name;n.addInitializer(function(){let o=this.constructor,i=Le.get(o)??[];i.push({cqrsName:r,projectionName:e,methodKey:s}),Le.set(o,i)})}}function Fn(r,e,t){return(n,s)=>{let o=s.name;s.addInitializer(function(){let i=this.constructor,a=$e.get(i)??[];a.push({cqrsName:r,eventNames:t,sagaName:e,methodKey:o}),$e.set(i,a)})}}ae();_t();var ar=0,ke=class{constructor(e,t){this.graph=e;this.moduleRef=t}disposers=[];scheduleNodeNames=[];onModuleInit(){this.wireEvents(),this.wireIntervals(),this.wireCrons(),this.wireCqrsCommands(),this.wireCqrsEvents(),this.wireCqrsQueries(),this.wireCqrsSagas()}onModuleDestroy(){for(let e of this.disposers)e();this.disposers.length=0;for(let e of this.scheduleNodeNames)try{this.graph.remove(e)}catch{}this.scheduleNodeNames.length=0}wireEvents(){for(let[e,t]of Me){let n=this.resolveInstance(e);if(n)for(let s of t)this.wireEventHandler(n,s)}}wireEventHandler(e,t){let n=e[t.methodKey];if(typeof n!="function")return;let s=n.bind(e),i=this.observeNode(t.nodeName).subscribe(a=>{for(let d of a)d[0]===M&&s(d[1])});this.disposers.push(i)}wireIntervals(){for(let[e,t]of De){let n=this.resolveInstance(e);if(n)for(let s of t)this.wireIntervalHandler(n,e,s)}}wireIntervalHandler(e,t,n){let s=e[n.methodKey];if(typeof s!="function")return;let o=s.bind(e),a=`__schedule__.${t.name??"anonymous"}.${String(n.methodKey)}.${ar++}`,d=sr(n.ms,{period:n.ms,name:a});this.graph.add(d),this.scheduleNodeNames.push(a);let c=this.observeNode(a).subscribe(f=>{for(let p of f)p[0]===M&&o(p[1])});this.disposers.push(c)}wireCrons(){for(let[e,t]of Ge){let n=this.resolveInstance(e);if(n)for(let s of t)this.wireCronHandler(n,e,s)}}wireCronHandler(e,t,n){let s=e[n.methodKey];if(typeof s!="function")return;let o=s.bind(e),a=`__schedule__.${t.name??"anonymous"}.${String(n.methodKey)}.${ar++}`,d=or(n.expr,{name:a});this.graph.add(d),this.scheduleNodeNames.push(a);let c=this.observeNode(a).subscribe(f=>{for(let p of f)p[0]===M&&o(p[1])});this.disposers.push(c)}wireCqrsCommands(){for(let[e,t]of Ie){let n=this.resolveInstance(e);if(n)for(let s of t)this.wireCqrsCommand(n,s)}}wireCqrsCommand(e,t){let n=e[t.methodKey];if(typeof n!="function")return;let s=n.bind(e),o=this.resolveCqrsGraph(t.cqrsName);o&&o.command(t.commandName,s)}wireCqrsEvents(){for(let[e,t]of Pe){let n=this.resolveInstance(e);if(n)for(let s of t)this.wireCqrsEventHandler(n,s)}}wireCqrsEventHandler(e,t){let n=e[t.methodKey];if(typeof n!="function")return;let s=n.bind(e),o=this.resolveCqrsGraph(t.cqrsName);if(!o)return;o.event(t.eventName);let a=o.resolve(t.eventName).cache,d=a&&a.length>0?a[a.length-1].seq:0,c=this.observeNodeOn(o,t.eventName).subscribe(f=>{for(let p of f)if(p[0]===M){let h=p[1];for(let l of h)l.seq>d&&(s(l),d=l.seq)}});this.disposers.push(c)}wireCqrsQueries(){for(let[e,t]of Le){let n=this.resolveInstance(e);if(n)for(let s of t)this.wireCqrsQuery(n,s)}}wireCqrsQuery(e,t){let n=e[t.methodKey];if(typeof n!="function")return;let s=n.bind(e),o=this.resolveCqrsGraph(t.cqrsName);if(!o)return;let a=this.observeNodeOn(o,t.projectionName).subscribe(d=>{for(let u of d)u[0]===M&&s(u[1])});this.disposers.push(a)}wireCqrsSagas(){for(let[e,t]of $e){let n=this.resolveInstance(e);if(n)for(let s of t)this.wireCqrsSaga(n,s)}}wireCqrsSaga(e,t){let n=e[t.methodKey];if(typeof n!="function")return;let s=n.bind(e),o=this.resolveCqrsGraph(t.cqrsName);o&&o.saga(t.sagaName,t.eventNames,s)}observeNode(e){return this.graph.observe(e)}observeNodeOn(e,t){return e.observe(t)}resolveCqrsGraph(e){try{return this.moduleRef.get(U(e),{strict:!1})}catch{return console.warn(`[GraphReFly] CqrsGraph "${e}" not found in DI \u2014 did you import GraphReflyModule.forCqrs({ name: "${e}" })?`),null}}resolveInstance(e){try{return this.moduleRef.get(e,{strict:!1})}catch{return null}}};ae();ae();var is=0;function wt(r,e){if(e.highWaterMark<1)throw new RangeError("highWaterMark must be >= 1");if(e.lowWaterMark<0)throw new RangeError("lowWaterMark must be >= 0");if(e.lowWaterMark>=e.highWaterMark)throw new RangeError("lowWaterMark must be < highWaterMark");let t=Symbol(`bp-${++is}`),n=0,s=!1;return{onEnqueue(){return n+=1,!s&&n>=e.highWaterMark?(s=!0,r([[J,t]]),!0):!1},onDequeue(){return n>0&&(n-=1),s&&n<=e.lowWaterMark?(s=!1,r([[te,t]]),!0):!1},get pending(){return n},get paused(){return s},dispose(){s&&(s=!1,r([[te,t]]))}}}function dr(r,e,t){let{actor:n,serialize:s=as,keepAliveMs:o,signal:i}=t??{},a=new TextEncoder,d,u=t?.highWaterMark!=null,c,f,p=[],h=!1;return new ReadableStream({start(l){let y,g=()=>{},E=()=>{if(!h){h=!0,y!==void 0&&clearInterval(y),i?.removeEventListener("abort",v),g(),c?.dispose(),f?.(),f=void 0;for(let b of p)l.enqueue(b.frame);p.length=0,l.close()}};d=E;let v=()=>E(),_=r.observe(e,{actor:n});u&&(c=wt(b=>_.up(b),{highWaterMark:t.highWaterMark,lowWaterMark:t.lowWaterMark??Math.floor(t.highWaterMark/2)})),g=_.subscribe(b=>{for(let w of b){if(h)return;let k=w[0];if(k===M){let m=a.encode(Qt("data",s(w[1])));u?(p.push({frame:m,counted:!0}),c.onEnqueue(),f?.(),f=void 0):l.enqueue(m)}else if(k===D){let m=a.encode(Qt("error",s(w[1])));u?(p.push({frame:m,counted:!1}),f?.(),f=void 0):l.enqueue(m),E();return}else if(k===I||k===$){if(k===I){let m=a.encode(Qt("complete"));u?(p.push({frame:m,counted:!1}),f?.(),f=void 0):l.enqueue(m)}E();return}}}),o!==void 0&&o>0&&(y=setInterval(()=>{h||(u?(p.push({frame:a.encode(`: keepalive
|
|
2
2
|
|
|
3
3
|
`),counted:!1}),f?.(),f=void 0):l.enqueue(a.encode(`: keepalive
|
|
4
4
|
|
|
5
|
-
`)))},
|
|
6
|
-
`;if(e!==void 0)for(let
|
|
7
|
-
`))t+=`data: ${
|
|
5
|
+
`)))},o)),i?.aborted?v():i?.addEventListener("abort",v,{once:!0})},pull(l){if(u&&!h){if(p.length>0){let y=p.shift();l.enqueue(y.frame),y.counted&&c.onDequeue();return}return new Promise(y=>{f=y})}},cancel(){try{d?.()}catch{}}})}function ur(r,e,t){let{actor:n,filter:s}=t??{},o=[],i=[],a=!1,d=r.observe(e,{actor:n}),u=t?.highWaterMark!=null?wt(l=>d.up(l),{highWaterMark:t.highWaterMark,lowWaterMark:t.lowWaterMark??Math.floor(t.highWaterMark/2)}):void 0,c=()=>{a||(a=!0,u?.dispose(),p())},f=l=>{if(!a)if(i.length>0){let y=i.shift();l.done&&l.error?y.reject(l.error):l.done?y.resolve({done:!0,value:void 0}):y.resolve({done:!1,value:l.value})}else o.push(l),l.done||u?.onEnqueue()},p=d.subscribe(l=>{for(let y of l){let g=y[0];if(g===M){let E=y[1];if(s&&!s(E))continue;f({done:!1,value:E})}else if(g===D){let E=y[1]instanceof Error?y[1]:new Error(String(y[1]));f({done:!0,error:E}),c();return}else if(g===I||g===$){f({done:!0}),c();return}}});return{next(){if(o.length>0){let l=o.shift();return l.done||u?.onDequeue(),l.done&&l.error?Promise.reject(l.error):Promise.resolve(l.done?{done:!0,value:void 0}:{done:!1,value:l.value})}return a?Promise.resolve({done:!0,value:void 0}):new Promise((l,y)=>{i.push({resolve:l,reject:y})})},return(){c();for(let l of i)l.resolve({done:!0,value:void 0});return i.length=0,Promise.resolve({done:!0,value:void 0})},throw(l){return c(),Promise.reject(l)},[Symbol.asyncIterator](){return this}}}var Tt=class{constructor(e,t){this.graph=e;this.extractActor=t?.extractActor??(()=>{}),this.parse=t?.parse??ds,this.highWaterMark=t?.highWaterMark,this.lowWaterMark=t?.lowWaterMark}clients=new Map;extractActor;parse;highWaterMark;lowWaterMark;handleConnection(e){this.clients.has(e)||this.clients.set(e,new Map)}handleDisconnect(e){let t=this.clients.get(e);if(t){for(let n of t.values())n.wm?.dispose(),n.unsub();this.clients.delete(e)}}handleMessage(e,t,n){let s=n??us.bind(null,e),o;try{o=typeof t=="string"?this.parse(t):t}catch{s({type:"err",message:"invalid command"});return}o.type==="subscribe"?this.subscribe(e,o.path,s):o.type==="unsubscribe"?this.unsubscribe(e,o.path,s):o.type==="ack"?this.ack(e,o.path,o.count??1):s({type:"err",message:`unknown command type: ${o.type}`})}subscriptionCount(e){return this.clients.get(e)?.size??0}destroy(){for(let[e]of this.clients)this.handleDisconnect(e)}subscribe(e,t,n){let s=this.clients.get(e);if(s||(s=new Map,this.clients.set(e,s)),s.has(t)){n({type:"subscribed",path:t});return}let o=this.extractActor(e),i;try{i=this.graph.observe(t,{actor:o})}catch(c){let f=c instanceof Error?c.message:String(c);n({type:"err",message:f});return}let a=this.highWaterMark!=null?wt(c=>i.up(c),{highWaterMark:this.highWaterMark,lowWaterMark:this.lowWaterMark??Math.floor(this.highWaterMark/2)}):void 0,d=()=>{a?.dispose(),u(),s.delete(t)},u=i.subscribe(c=>{for(let f of c){let p=f[0];if(p===M)a?.onEnqueue(),Zt(n,{type:"data",path:t,value:f[1]});else if(p===D){let h=f[1]instanceof Error?f[1].message:String(f[1]);Zt(n,{type:"error",path:t,error:h}),d();return}else if(p===I||p===$){Zt(n,{type:"complete",path:t}),d();return}}});s.set(t,{unsub:u,wm:a}),n({type:"subscribed",path:t})}unsubscribe(e,t,n){let s=this.clients.get(e),o=s?.get(t);o&&(o.wm?.dispose(),o.unsub(),s.delete(t)),n({type:"unsubscribed",path:t})}ack(e,t,n){let s=this.clients.get(e)?.get(t);if(!s?.wm)return;let o=Math.min(Math.max(0,Math.floor(n)),1024);for(let i=0;i<o;i++)s.wm.onDequeue()}};function as(r){if(r instanceof Error)return r.message;try{return JSON.stringify(r)}catch{return String(r)}}function Qt(r,e){let t=`event: ${r}
|
|
6
|
+
`;if(e!==void 0)for(let n of e.split(`
|
|
7
|
+
`))t+=`data: ${n}
|
|
8
8
|
`;return t+=`
|
|
9
|
-
`,t}function
|
|
10
|
-
`)}function No(n,e,t,r,o){let{x:s,y:i,w:a,h:d}=r;if(a<2||d<2){d>0&&_r(n,e,s,i,a,o);return}pe(n,e,s,i,t.boxTL);for(let c=s+1;c<s+a-1;c+=1)pe(n,e,c,i,t.boxH);pe(n,e,s+a-1,i,t.boxTR);for(let c=i+1;c<i+d-1;c+=1){pe(n,e,s,c,t.boxV);for(let f=s+1;f<s+a-1;f+=1)Er(n,e,f,c," ","empty");pe(n,e,s+a-1,c,t.boxV)}pe(n,e,s,i+d-1,t.boxBL);for(let c=s+1;c<s+a-1;c+=1)pe(n,e,c,i+d-1,t.boxH);pe(n,e,s+a-1,i+d-1,t.boxBR);let u=i+Math.floor(d/2);_r(n,e,s+1,u,a-2,o)}function pe(n,e,t,r,o){Er(n,e,t,r,o,o===" "?"empty":o==="\u2500"||o==="-"?"boxH":o==="\u2502"||o==="|"?"boxV":"boxCorner")}function Er(n,e,t,r,o,s){if(r<0||r>=n.length)return;let i=n[r];t<0||t>=i.length||(i[t]=o,e[r][t]=s)}function _r(n,e,t,r,o,s){if(r<0||r>=n.length)return;let i=t,a=o;for(let d of s){let u=Ot(d);if(u!==0){if(a<u)break;i>=0&&i<n[r].length&&(n[r][i]=d,e[r][i]="label",u===2&&i+1<n[r].length&&(n[r][i+1]="",e[r][i+1]="label")),i+=u,a-=u}}for(;a>0;)i>=0&&i<n[r].length&&(n[r][i]=" ",e[r][i]="empty"),i+=1,a-=1}function Ao(n,e,t,r){let o=r.points;if(o.length<2)return;for(let d=0;d+1<o.length;d+=1)Co(n,e,t,o[d],o[d+1]);for(let d=1;d+1<o.length;d+=1){let u=o[d-1],c=o[d],f=o[d+1],p=Mo(u,c,f,t);p&&xr(n,e,c.x,c.y,p,"edgeCorner")}let s=o[o.length-1],i=o[o.length-2],a=Do(i,s,t);a&&xr(n,e,s.x,s.y,a,"arrow")}function Co(n,e,t,r,o){if(!(r.x===o.x&&r.y===o.y)){if(r.y===o.y){let s=r.y,i=Math.min(r.x,o.x),a=Math.max(r.x,o.x);for(let d=i;d<=a;d+=1)wr(n,e,d,s,t,"h")}else if(r.x===o.x){let s=r.x,i=Math.min(r.y,o.y),a=Math.max(r.y,o.y);for(let d=i;d<=a;d+=1)wr(n,e,s,d,t,"v")}}}function wr(n,e,t,r,o,s){if(r<0||r>=n.length)return;let i=n[r];if(t<0||t>=i.length)return;let a=e[r][t];if(!(a==="boxH"||a==="boxV"||a==="boxCorner"||a==="label")){if(a==="empty"){i[t]=s==="h"?o.horizontal:o.vertical,e[r][t]=s==="h"?"edgeH":"edgeV";return}if(a==="edgeH"&&s==="v"){i[t]=o.cross,e[r][t]="edgeCorner";return}if(a==="edgeV"&&s==="h"){i[t]=o.cross,e[r][t]="edgeCorner";return}}}function xr(n,e,t,r,o,s){if(r<0||r>=n.length)return;let i=n[r];if(t<0||t>=i.length)return;let a=e[r][t];a==="boxH"||a==="boxV"||a==="boxCorner"||a==="label"||(i[t]=o,e[r][t]=s)}function Mo(n,e,t,r){let o=n.y===e.y,s=e.y===t.y;if(o===s)return;if(o){let d=n.x<e.x,u=t.y>e.y;return d&&u?r.cornerTR:d&&!u?r.cornerBR:!d&&u?r.cornerTL:r.cornerBL}let i=n.y<e.y,a=t.x>e.x;return i&&a?r.cornerBL:i&&!a?r.cornerBR:!i&&a?r.cornerTL:r.cornerTR}function Do(n,e,t){if(e.x>n.x)return t.arrowRight;if(e.x<n.x)return t.arrowLeft;if(e.y>n.y)return t.arrowDown;if(e.y<n.y)return t.arrowUp}function Go(n){let e=n.length;for(;e>0&&n.charCodeAt(e-1)===32;)e-=1;return n.slice(0,e)}function kr(n){let e=Lo(n);Io(e),Po(e),$o(e),Ho(e,n);let t=zo(e,n),{width:r,height:o}=jo(e),s=[];for(let i of e.layers)for(let a of i)a.isVirtual||s.push({id:a.id,layer:a.layer,order:a.order,x:a.x,y:a.y,w:a.w,h:a.h});return{boxes:s,edges:t,width:r,height:o}}function Lo(n){let e=new Map;for(let o of n.nodes)e.set(o,{id:o,isVirtual:!1,layer:-1,order:0,x:0,y:0,w:n.widthCells(o),h:n.heightCells(o),in:[],out:[]});let t=[],r=0;for(let o of n.edges){if(o.from===o.to)continue;let s=e.get(o.from),i=e.get(o.to);if(!s||!i)continue;let a={chainId:r++,chainFrom:o.from,chainTo:o.to,fromId:o.from,toId:o.to,hopIndex:0,chainLen:1};s.out.push(a),i.in.push(a),t.push(a)}return{nodes:e,layers:[],hops:t}}function Io(n){let e=new Map;for(let s of n.nodes.values())e.set(s.id,s.in.length);let t=[];for(let s of n.nodes.values())(e.get(s.id)??0)===0&&(s.layer=0,t.push(s));let r=new Set,o=0;for(;o<t.length;){let s=t[o++];if(!r.has(s.id)){r.add(s.id);for(let i of s.out){let a=n.nodes.get(i.toId);a.layer=Math.max(a.layer,s.layer+1);let d=(e.get(a.id)??0)-1;e.set(a.id,d),d<=0&&t.push(a)}}}for(let s of n.nodes.values())s.layer<0&&(s.layer=0)}function Po(n){let e=Math.max(0,...Array.from(n.nodes.values(),s=>s.layer)),t=Array.from({length:e+1},()=>[]);for(let s of n.nodes.values())t[s.layer].push(s);let r=[],o=0;for(let s of n.hops){let i=n.nodes.get(s.fromId),a=n.nodes.get(s.toId),d=a.layer-i.layer;if(d<=0){i.out=i.out.filter(f=>f!==s),a.in=a.in.filter(f=>f!==s);continue}if(d===1){s.hopIndex=0,s.chainLen=1,r.push(s);continue}i.out=i.out.filter(f=>f!==s),a.in=a.in.filter(f=>f!==s);let u=i;for(let f=1;f<d;f+=1){let p=`__virt_${o++}__`,h={id:p,isVirtual:!0,layer:i.layer+f,order:0,x:0,y:0,w:0,h:1,in:[],out:[]};n.nodes.set(p,h),t[h.layer].push(h);let l={chainId:s.chainId,chainFrom:s.chainFrom,chainTo:s.chainTo,fromId:u.id,toId:p,hopIndex:f-1,chainLen:d};u.out.push(l),h.in.push(l),r.push(l),u=h}let c={chainId:s.chainId,chainFrom:s.chainFrom,chainTo:s.chainTo,fromId:u.id,toId:a.id,hopIndex:d-1,chainLen:d};u.out.push(c),a.in.push(c),r.push(c)}for(let s of t)for(let i=0;i<s.length;i+=1)s[i].order=i;n.layers=t,n.hops=r}function $o(n){for(let t=0;t<4;t+=1){for(let r=1;r<n.layers.length;r+=1)Or(n,n.layers[r],"in"),Rt(n.layers[r]);for(let r=n.layers.length-2;r>=0;r-=1)Or(n,n.layers[r],"out"),Rt(n.layers[r])}for(let t=0;t<2;t+=1){let r=!1;for(let o=1;o<n.layers.length;o+=1){let s=n.layers[o];for(let i=0;i+1<s.length;i+=1){let a=Rr(n,s[i],s[i+1],"in");[s[i],s[i+1]]=[s[i+1],s[i]],Rt(s),Rr(n,s[i],s[i+1],"in")<a?r=!0:([s[i],s[i+1]]=[s[i+1],s[i]],Rt(s))}}if(!r)break}}function Or(n,e,t){let r=new Map;for(let o of e){let s=t==="in"?o.in:o.out;if(s.length===0){r.set(o.id,o.order);continue}let i=0,a=0;for(let d of s){let u=n.nodes.get(t==="in"?d.fromId:d.toId);u&&(i+=u.order,a+=1)}r.set(o.id,a===0?o.order:i/a)}e.sort((o,s)=>{let i=r.get(o.id),a=r.get(s.id);return i!==a?i-a:o.order-s.order})}function Rt(n){for(let e=0;e<n.length;e+=1)n[e].order=e}function Rr(n,e,t,r){let o=r==="in"?e.in:e.out,s=r==="in"?t.in:t.out,i=0;for(let a of o)for(let d of s){let u=n.nodes.get(r==="in"?a.fromId:a.toId)?.order??0,c=n.nodes.get(r==="in"?d.fromId:d.toId)?.order??0;(e.order<t.order&&u>c||e.order>t.order&&u<c)&&(i+=1)}return i}function Ho(n,e){e.direction==="LR"?Fo(n,e):Vo(n,e)}function Fo(n,e){let t=[],r=0;for(let o=0;o<n.layers.length;o+=1){t.push(r);let s=0;for(let i of n.layers[o])s=Math.max(s,i.w);r+=s+e.layerGap}for(let o=0;o<n.layers.length;o+=1)for(let s of n.layers[o])s.x=t[o];for(let o of n.layers){let s=0;for(let i of o)i.y=s,s+=i.h+e.nodeGap}Sr(n,e,"y")}function Vo(n,e){let t=[],r=0;for(let o=0;o<n.layers.length;o+=1){t.push(r);let s=0;for(let i of n.layers[o])s=Math.max(s,i.h);r+=s+e.layerGap}for(let o=0;o<n.layers.length;o+=1)for(let s of n.layers[o])s.y=t[o];for(let o of n.layers){let s=0;for(let i of o)i.x=s,s+=i.w+e.nodeGap}Sr(n,e,"x")}function Sr(n,e,t){let r=s=>t==="y"?s.h:s.w,o=e.nodeGap;for(let s=0;s<2;s+=1){let i=s===0?n.layers.slice(1):n.layers.slice(0,-1).reverse();for(let a of i){let d=new Map;for(let c of a){let f=s===0?c.in:c.out;if(f.length===0)continue;let p=[];for(let l of f){let y=n.nodes.get(s===0?l.fromId:l.toId);if(!y)continue;let m=t==="y"?y.y:y.x;p.push(m+Math.floor(r(y)/2))}if(p.length===0)continue;p.sort((l,y)=>l-y);let h=p[Math.floor(p.length/2)];d.set(c.id,h-Math.floor(r(c)/2))}let u=0;for(let c of a){let f=d.get(c.id),p=t==="y"?c.y:c.x,l=Math.max(f??p,u);t==="y"?c.y=l:c.x=l,u=l+r(c)+o}}}}function zo(n,e){let t=new Map;for(let u of n.hops){let c=t.get(u.chainId);c?c.push(u):t.set(u.chainId,[u])}for(let u of t.values())u.sort((c,f)=>c.hopIndex-f.hopIndex);let r=e.direction==="LR",o=u=>r?u.x:u.y,s=u=>r?u.w:u.h,i=u=>r?u.y+Math.floor(u.h/2):u.x+Math.floor(u.w/2),a=new Map;for(let u=0;u+1<n.layers.length;u+=1){let c=n.layers[u],f=n.layers[u+1],p=0;for(let w of c)p=Math.max(p,o(w)+s(w));let h=Number.POSITIVE_INFINITY;for(let w of f)h=Math.min(h,o(w));let l=Number.isFinite(h)?h-1:p,y=Math.max(1,l-p+1),m=[];for(let w of c)for(let k of w.out)m.push(k);m.sort((w,k)=>{let E=i(n.nodes.get(w.fromId)),T=i(n.nodes.get(k.fromId));if(E!==T)return E-T;let N=i(n.nodes.get(w.toId)),S=i(n.nodes.get(k.toId));return N-S});let x=[],_=new Map;for(let w of m){let k=i(n.nodes.get(w.fromId)),E=i(n.nodes.get(w.toId)),T=Math.min(k,E),N=Math.max(k,E),S=-1;for(let A=0;A<x.length;A+=1){let G=x[A],I=!0;for(let q of G)if(q.lo<=N&&T<=q.hi){I=!1;break}if(I){G.push({lo:T,hi:N}),S=A;break}}S<0&&(x.push([{lo:T,hi:N}]),S=x.length-1),_.set(w,S)}let v=x.length,b=y>=Math.max(3,v+2),O=b?p+1:p,R=b?l-1:l,g=Math.max(1,R-O+1);for(let w of m){let k=_.get(w),E;if(v<=1)E=O+Math.floor(g/2);else{let T=(g-1)/(v-1);E=O+Math.floor(k*T)}a.set(w,Math.max(p,Math.min(l,E)))}}let d=[];for(let[,u]of t){let c=[];for(let p=0;p<u.length;p+=1){let h=u[p],l=n.nodes.get(h.fromId),y=n.nodes.get(h.toId),m=a.get(h),x=l.isVirtual?o(l):o(l)+s(l),_=y.isVirtual?o(y):o(y)-1,v=i(l),b=i(y);p===0&&kt(c,r,x,v),v!==b&&(kt(c,r,m,v),kt(c,r,m,b)),kt(c,r,_,b)}let f=u[0];d.push({from:f.chainFrom,to:f.chainTo,points:qo(c)})}return d}function kt(n,e,t,r){n.push(e?{x:t,y:r}:{x:r,y:t})}function qo(n){let e=[];for(let t of n){let r=e[e.length-1];(!r||r.x!==t.x||r.y!==t.y)&&e.push(t)}return e}function jo(n){let e=0,t=0;for(let r of n.layers)for(let o of r)e=Math.max(e,o.x+o.w),t=Math.max(t,o.y+o.h);return{width:e,height:t}}var Bo=24,Wo=4,Ko=1,Uo=3;function Nr(n,e){let t=Yo(e.direction),r=Math.max(3,e.maxLabelWidth??Bo),o=e.asciiCharset??"unicode",s=Object.keys(n.nodes).sort(),i=new Set(s),a=n.edges.filter(h=>i.has(h.from)&&i.has(h.to)),d=new Map,u=new Map;for(let h of s){let l=vr(h,r);d.set(h,l),u.set(h,Ot(l)+4)}let c=kr({nodes:s,edges:a,widthCells:h=>u.get(h)??3,heightCells:()=>Uo,layerGap:Wo,nodeGap:Ko,direction:t}),f=Tr(c,{charset:o,labelOf:h=>d.get(h)??h}),p=e.logger;return p&&p(f),f}function Yo(n){if(n===void 0||n==="LR")return"LR";if(n==="TD")return"TD";throw new Error(`ascii describe supports direction "LR" or "TD" only; got ${String(n)}`)}function Ar(n,e,t,r={}){let o=e in n.nodes,s=t in n.nodes;if(!o)return St(e,t,"no-such-from");if(!s)return St(e,t,"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===t){if(r.findCycle===!0){let u=Jo(n,e,r);if(u!=null)return u}let d=Nt(e,n.nodes[e],0,r);return At(e,t,[d])}if(i===0)return St(e,t,"no-path");let a=Cr(n,e,t,i);return a.found?At(e,t,Mr(n,a.pathOrder,r)):St(e,t,a.truncated?"max-depth-exceeded":"no-path")}function Cr(n,e,t,r){let o=new Map,s=[{path:t,depth:0}],i=new Set([t]),a=0,d=!1;for(;a<s.length;){let f=s[a++];if(f.path===e)break;if(r!=null&&f.depth>=r){let y=n.nodes[f.path];y?.deps&&y.deps.length>0&&(d=!0);continue}let p=n.nodes[f.path];if(p==null)continue;let h=p.deps??[],l=new Map;for(let y=0;y<h.length;y++){let m=h[y];if(!m)continue;let x=l.get(m);x==null&&(x=[],l.set(m,x)),x.push(y)}for(let[y,m]of l)i.has(y)||(i.add(y),o.set(y,{from:f.path,depIndices:m}),s.push({path:y,depth:f.depth+1}))}if(!o.has(e))return{found:!1,pathOrder:[],truncated:d};let u=[{path:e}],c=e;for(;c!==t;){let f=o.get(c);if(f==null)return{found:!1,pathOrder:[],truncated:!1};u[u.length-1].depIndices=f.depIndices,u.push({path:f.from}),c=f.from}return{found:!0,pathOrder:u,truncated:!1}}function Jo(n,e,t){let r=n.nodes[e];if(r==null)return null;let o=r.deps??[],s=[];for(let a=0;a<o.length;a++)o[a]===e&&s.push(a);if(s.length>0){let a=Nt(e,r,0,t);a.dep_index=s[0];let d=Nt(e,r,1,t);return At(e,e,[a,d])}let i=null;for(let a=0;a<o.length;a++){let d=o[a];if(!d||d===e)continue;let u=Cr(n,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:At(e,e,Mr(n,i.pathOrder,t))}function Mr(n,e,t){return e.map((r,o)=>{let s=n.nodes[r.path],i=Nt(r.path,s,o,t);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 Nt(n,e,t,r){let o={path:n,type:e.type,hop:t};e.status!==void 0&&(o.status=e.status),"value"in e&&(o.value=e.value),e.v!=null&&(o.v=e.v);let s=r.annotations?.get(n)??e.annotation;s!=null&&(o.annotation=s);let i=r.lastMutations?.get(n)??e.lastMutation;return i!=null&&(o.lastMutation=i),o}function At(n,e,t){return Dr(n,e,!0,"ok",t)}function St(n,e,t){return Dr(n,e,!1,t,[])}function Dr(n,e,t,r,o){let s=Qo(n,e,t,r,o);return{from:n,to:e,found:t,reason:r,steps:o,text:s,toJSON(){return{from:n,to:e,found:t,reason:r,steps:o}}}}function Qo(n,e,t,r,o){if(!t)switch(r){case"no-such-from":return`explainPath: no node named "${n}"`;case"no-such-to":return`explainPath: no node named "${e}"`;case"max-depth-exceeded":return`explainPath: no path from "${n}" to "${e}" within maxDepth`;default:return`explainPath: no path from "${n}" to "${e}"`}let s=[`Causal path: ${n} \u2192 ${e} (${o.length} step(s))`];for(let i of o){let d=` ${i.hop===0?"\xB7":"\u2193"} ${i.path} (${i.type}${i.status?`/${i.status}`:""})`;if(s.push(d),"value"in i&&s.push(` value: ${Xo(i.value)}`),i.annotation!=null&&s.push(` annotation: ${i.annotation}`),i.lastMutation!=null){let u=i.lastMutation.actor;s.push(` actor: ${u.type}${u.id?`:${u.id}`:""}`)}}return s.join(`
|
|
11
|
-
`)}function Xo(n){if(n===void 0)return"<sentinel>";if(n===null)return"null";if(typeof n=="string")return JSON.stringify(n);if(typeof n=="number"||typeof n=="boolean"||typeof n=="bigint")return String(n);try{let e=JSON.stringify(n);return e.length>80?`${e.slice(0,77)}...`:e}catch{return String(n)}}Ee();var z={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},Zo=Symbol.for("sizeof");function Gr(n){let e=new WeakSet,t=new WeakSet,r=[n],o=0;for(;r.length>0;){let s=r.pop();o+=es(s,e,t,r)}return o}function es(n,e,t,r){if(n==null)return 0;switch(typeof n){case"number":return z.number;case"boolean":return z.boolean;case"string":return z.string+n.length*2;case"bigint":return z.bigint+ts(n);case"symbol":return z.symbol;case"function":return e.has(n)?0:(e.add(n),z.function);case"undefined":return 0}let s=n;if(e.has(s))return 0;e.add(s);let i=s[Zo];if(typeof i=="function")try{let u=i.call(s);if(typeof u=="number"&&Number.isFinite(u))return u}catch{}if(s instanceof Date)return z.date;if(s instanceof RegExp)return z.regexp+s.source.length*2;if(s instanceof Error){let u=s.message?s.message.length*2:0,c=s.stack?s.stack.length*2:0;return z.error+u+c}if(typeof URL<"u"&&s instanceof URL)return z.url+s.href.length*2;if(typeof Promise<"u"&&s instanceof Promise)return z.promise;if(s instanceof WeakMap)return z.weakmap;if(s instanceof WeakSet)return z.weakset;if(s instanceof Map){let u=z.map;for(let[c,f]of s)u+=z.mapEntry,r.push(c),r.push(f);return u}if(s instanceof Set){let u=z.set;for(let c of s)u+=z.setEntry,r.push(c);return u}if(Array.isArray(s)){let u=z.array+s.length*8;for(let c of s)r.push(c);return u}if(s instanceof ArrayBuffer)return t.has(s)?0:(t.add(s),s.byteLength);if(ArrayBuffer.isView(s)){let u=s;return t.has(u.buffer)?48:(t.add(u.buffer),u.buffer.byteLength+48)}let a=z.object,d=Object.keys(s);for(let u of d){a+=z.string+u.length*2;try{r.push(s[u])}catch{}}return a}function ts(n){let e=n<0n?-n:n;if(e===0n)return 0;let t=e.toString(2).length;return Math.ceil(t/32)*8}function Lr(n,e){let t=e?.topN??10,r=n.describe({detail:"standard"}),o=[],s=n._collectObserveTargets;typeof s=="function"&&s.call(n,"",o);let i=new Map;for(let[p,h]of o)i.set(p,h);let a=[];for(let[p,h]of Object.entries(r.nodes)){let l=i.get(p),y=l instanceof V?l:null,m=y?Gr(y.cache):0,x=y?y._sinkCount:0,_=h.deps?.length??0,v=h.type==="effect"&&x===0,b=x===0?h.type==="effect"?"orphan-effect":h.type==="derived"?"idle-derived":h.type==="producer"?"idle-producer":null:null;a.push({path:p,type:h.type,status:h.status??"unknown",valueSizeBytes:m,subscriberCount:x,depCount:_,isOrphanEffect:v,orphanKind:b})}let d=a.reduce((p,h)=>p+h.valueSizeBytes,0),u=(p,h)=>[...a].sort(h??((l,y)=>y[p]-l[p])).slice(0,t),c=a.filter(p=>p.orphanKind!=null),f=a.filter(p=>p.isOrphanEffect);return{nodeCount:a.length,edgeCount:r.edges.length,subgraphCount:r.subgraphs.length,nodes:a,totalValueSizeBytes:d,hotspots:{byValueSize:u("valueSizeBytes"),bySubscriberCount:u("subscriberCount"),byDepCount:u("depCount")},orphans:c,orphanEffects:f}}var H="::",se="__meta__",ke=1;function Ir(n,e){let t=Math.max(16,n.size*4),r=0;for(;n.size>0;){if(r++>=t){console.error(`[Graph "${e}".destroy] disposer drain exceeded cap (${t}); ${n.size} disposer(s) discarded`),n.clear();return}let o=n.values().next();if(o.done)return;let s=o.value;n.delete(s);try{s()}catch(i){console.error(`[Graph "${e}".destroy] disposer threw:`,i)}}}function Hr(n){return n!=null&&typeof n=="object"&&"cache"in n&&typeof n.subscribe=="function"&&typeof n.down=="function"}function ns(n){if(n!=null)return Hr(n)?n.cache:n}function rs(n){let e=[];for(let t of Object.keys(n).sort()){let r=n[t].v;r!=null&&e.push(`${t} ${r.id} ${r.version}`)}return e.join(`
|
|
12
|
-
`)}function Pr(n){if(n.version!==ke)throw new Error(`unsupported snapshot version ${String(n.version)} (expected ${ke})`);for(let e of["name","nodes","edges","subgraphs"])if(!(e in n))throw new Error(`snapshot missing required key "${e}"`);if(typeof n.name!="string")throw new TypeError("snapshot 'name' must be a string");if(typeof n.nodes!="object"||n.nodes===null||Array.isArray(n.nodes))throw new TypeError("snapshot 'nodes' must be an object");if(!Array.isArray(n.edges))throw new TypeError("snapshot 'edges' must be an array");if(!Array.isArray(n.subgraphs))throw new TypeError("snapshot 'subgraphs' must be an array")}function os(n,e){let t=new WeakMap,r=(o,s)=>{if(Object.is(o,s))return!0;if(o==null||s==null||typeof o!="object"||typeof s!="object")return!1;let i=t.get(o);if(i==null&&(i=new WeakSet,t.set(o,i)),i.has(s))return!0;i.add(s);let a=o.constructor,d=s.constructor;if(a!==d)return!1;if(o instanceof Date)return o.getTime()===s.getTime();if(o instanceof RegExp)return o.source===s.source&&o.flags===s.flags;if(Array.isArray(o)){let p=s;if(o.length!==p.length)return!1;for(let h=0;h<o.length;h++)if(!r(o[h],p[h]))return!1;return!0}if(o instanceof Map){let p=s;if(o.size!==p.size)return!1;for(let[h,l]of o)if(!p.has(h)||!r(l,p.get(h)))return!1;return!0}if(o instanceof Set){let p=s;if(o.size!==p.size)return!1;for(let h of o){let l=!1;for(let y of p)if(r(h,y)){l=!0;break}if(!l)return!1}return!0}if(ArrayBuffer.isView(o)){let p=o,h=s;if(p.length!==h.length)return!1;for(let l=0;l<p.length;l++)if(p[l]!==h[l])return!1;return!0}let u=Object.keys(o),c=Object.keys(s);if(u.length!==c.length)return!1;let f=new Set(c);for(let p of u)if(!f.has(p)||!r(o[p],s[p]))return!1;return!0};return r(n,e)}function fn(n){if(n===null||typeof n!="object")return n;if(Array.isArray(n))return n.map(fn);let e=n,t=Object.keys(e).sort(),r={};for(let o of t)r[o]=fn(e[o]);return r}function ss(n){return n.replaceAll("\\","\\\\").replaceAll('"','\\"')}function is(n){return n.replaceAll("\\","\\\\").replaceAll('"','\\"')}function as(n){return n==="TD"?"down":n==="BT"?"up":n==="RL"?"left":"right"}function Fr(n){let e=new Set,t=[];function r(o,s){let i=`${o}\0${s}`;e.has(i)||(e.add(i),t.push([o,s]))}for(let[o,s]of Object.entries(n.nodes)){let i=s.deps;if(i)for(let a of i)r(a,o)}for(let o of n.edges)r(o.from,o.to);return t}function Vr(n){if(n===void 0)return"LR";if(n==="TD"||n==="LR"||n==="BT"||n==="RL")return n;throw new Error(`invalid diagram direction ${String(n)}; expected one of: TD, LR, BT, RL`)}function us(n,e){let t=e.includeEdges??!0,r=e.includeSubgraphs??!0,{expand:o,...s}=n,i={...s,edges:t?n.edges:[],subgraphs:r?n.subgraphs:[]},a=JSON.stringify(fn(i),null,e.indent??2);return e.logger?.(a),a}function ds(n,e){let t=e.includeEdges??!0,r=e.includeSubgraphs??!0,o=[];o.push(`Graph ${n.name}`),o.push("Nodes:");for(let i of Object.keys(n.nodes).sort()){let a=n.nodes[i];o.push(`- ${i} (${a.type}/${a.status}): ${Mt(a.value)}`)}if(t){o.push("Edges:");for(let i of n.edges)o.push(`- ${i.from} -> ${i.to}`)}if(r){o.push("Subgraphs:");for(let i of n.subgraphs)o.push(`- ${i}`)}let s=o.join(`
|
|
13
|
-
`);return e.logger?.(s),s}function zr(n,e){let t=Vr(e.direction),r=Object.keys(n.nodes).sort(),o=new Map;for(let i=0;i<r.length;i+=1)o.set(r[i],`n${i}`);let s=[`flowchart ${t}`];for(let i of r){let a=o.get(i);s.push(` ${a}["${ss(i)}"]`)}for(let[i,a]of Fr(n)){let d=o.get(i),u=o.get(a);!d||!u||s.push(` ${d} --> ${u}`)}return s.join(`
|
|
14
|
-
`)}function cs(n,e){let t=zr(n,e);return qr(t)}function qr(n,e){let t=e?.theme??"default",r=e?.autoSync??!0,s=JSON.stringify({code:n,mermaid:{theme:t},autoSync:r}),i=new TextEncoder().encode(s),a="";for(let u=0;u<i.length;u++)a+=String.fromCharCode(i[u]);return`https://mermaid.live/edit#base64:${globalThis.btoa(a).replace(/\+/g,"-").replace(/\//g,"_").replace(/=+$/,"")}`}function ls(n,e){let t=Vr(e.direction),r=Object.keys(n.nodes).sort(),o=new Map;for(let i=0;i<r.length;i+=1)o.set(r[i],`n${i}`);let s=[`direction: ${as(t)}`];for(let i of r){let a=o.get(i);s.push(`${a}: "${is(i)}"`)}for(let[i,a]of Fr(n)){let d=o.get(i),u=o.get(a);!d||!u||s.push(`${d} -> ${u}`)}return s.join(`
|
|
15
|
-
`)}function fs(n){return n.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function Ct(n){let e="^";for(let t=0;t<n.length;t+=1){let r=n[t];if(r==="*"){e+=".*";continue}if(r==="?"){e+=".";continue}if(r==="["){let o=n.indexOf("]",t+1);if(o<=t+1){e+="\\[";continue}let s=n.slice(t+1,o);s.startsWith("!")&&(s=`^${s.slice(1)}`),s=s.replace(/\\/g,"\\\\"),e+=`[${s}]`,t=o;continue}e+=fs(r)}return e+="$",new RegExp(e)}var ps={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"},hs={data:"",dirty:"",resolved:"",invalidate:"",pause:"",resume:"",complete:"",error:"",teardown:"",derived:"",path:"",reset:""};function Mt(n){if(typeof n=="string")return JSON.stringify(n);if(typeof n=="number"||typeof n=="boolean"||n==null)return String(n);try{return JSON.stringify(n)}catch{return"[unserializable]"}}function gs(n){return n==="none"?hs:n==="ansi"||n==null?ps:{data:n.data??"",dirty:n.dirty??"",resolved:n.resolved??"",invalidate:n.invalidate??"",pause:n.pause??"",resume:n.resume??"",complete:n.complete??"",error:n.error??"",teardown:n.teardown??"",derived:n.derived??"",path:n.path??"",reset:n.reset??""}}function $r(n){if(n==null)return{};let e=n.detail;return e==="full"?{...n,structured:n.structured??!0,timeline:n.timeline??!0,causal:n.causal??!0,derived:n.derived??!0}:e==="minimal"?{...n,structured:n.structured??!0}:n.format==="stage-log"?{...n,structured:n.structured??!0,timeline:n.timeline??!0}:n}function ms(n,e,t){for(let r=0;r<n.length;r++){let o=n.charCodeAt(r);if(o<32||o===127)throw new Error(`Graph "${e}": ${t} "${n}" must not contain control character (U+${o.toString(16).padStart(4,"0").toUpperCase()} at index ${r})`)}}function ln(n,e,t){if(n==="")throw new Error(`Graph "${e}": ${t} name must be non-empty`);if(n.includes(H))throw new Error(`Graph "${e}": ${t} "${n}" must not contain '${H}' (path separator)`);if(n===se)throw new Error(`Graph "${e}": ${t} name "${se}" is reserved for meta companion paths`);ms(n,e,t)}function ys(n,e){if(n==="")throw new Error(`Graph "${e}": resolve path must be non-empty`);let t=n.split(H);for(let r of t)if(r==="")throw new Error(`Graph "${e}": resolve path has empty segment`);return t}function bs(n,e){let t=!1;for(let o of n)if(!e.isMetaPassthrough(o[0])){t=!0;break}return t?n.filter(o=>e.isMetaPassthrough(o[0])):n}function jr(n){for(let e of n._mounts.values())jr(e);for(let e of n._nodes.values())try{e.down([[F]],{internal:!0})}catch{}}var ie=class n{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(H))throw new Error(`Graph name must not contain '${H}' (got "${e}")`);if(e===se)throw new Error(`Graph name "${se}" is reserved for meta companion paths`);this.name=e,this.opts=Object.freeze({...t??{}}),this.config=t?.config??Te,this._traceRing=new ot(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=[],r=e?this:this._parent;for(;r!=null;)t.push(r),r=r._parent;return t}get topology(){return this._topology==null&&(this._topology=Oe(e=>{let t=r=>{e.emit(r)};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 r=e.name,o=t?.name??r;if(o==null||o==="")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 s=o,i=t?.annotation;if(ln(s,this.name,"add"),this._mounts.has(s))throw new Error(`Graph "${this.name}": name "${s}" is already a mount point`);if(this._nodes.has(s))throw new Error(`Graph "${this.name}": node "${s}" 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(s,e),this._nodeToName.set(e,s),this._emitTopology({kind:"added",name:s,nodeKind:"node"}),i!=null&&(this._annotations.set(s,i),this.config.inspectorEnabled&&this._traceRing.push({path:s,annotation:i,timestamp_ns:ce()})),e}setVersioning(e){if(e!=null)for(let t of this._nodes.values())t instanceof V&&t._applyVersioning(e)}remove(e){ln(e,this.name,"remove");let t=this._mounts.get(e);if(t){let s={kind:"mount",nodes:[],mounts:[]},i=[];t._collectObserveTargets("",i);for(let[a,d]of i)a.includes(`${H}${se}${H}`)||s.nodes.push(a);return s.nodes.sort(),s.mounts.push(e),s.mounts.push(...t._collectSubgraphs(`${e}${H}`)),this._mounts.delete(e),t._parent=void 0,jr(t),this._emitTopology({kind:"removed",name:e,nodeKind:"mount",audit:s}),s}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([[F]],{internal:!0});let o={kind:"node",nodes:[e],mounts:[]};return this._emitTopology({kind:"removed",name:e,nodeKind:"node",audit:o}),o}removeAll(e){let t=typeof e=="function"?e:(()=>{let s=Ct(e);return i=>s.test(i)})(),r={kind:"mount",nodes:[],mounts:[]},o=[...this._nodes.keys(),...this._mounts.keys()].filter(s=>t(s));for(let s of o){let i=this.remove(s);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(),t=this._nodes,r=0;return{[Symbol.iterator](){return this},next(){if(r>=e.length)return{value:void 0,done:!0};let o=e[r++];return{value:[o,t.get(o)],done:!1}}}}node(e){if(e==="")throw new Error(`Graph "${this.name}": node name must be non-empty`);if(e.includes(H))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,r){let o=r?.internal===!0;this.node(e).down([[M,t]],{actor:r?.actor,internal:o,delivery:"write"})}setAll(e,t){let r=Symbol.iterator in e?e:Object.entries(e);ze(()=>{for(let[o,s]of r)this.set(o,s,t)})}invalidate(e,t){let r=t?.internal===!0;this.node(e).down([[ee]],{actor:t?.actor,internal:r,delivery:"write"})}error(e,t,r){let o=r?.internal===!0;this.node(e).down([[D,t]],{actor:r?.actor,internal:o,delivery:"write"})}complete(e,t){let r=t?.internal===!0;this.node(e).down([[$]],{actor:t?.actor,internal:r,delivery:"write"})}edges(e){let t=e?.recursive===!0,r=new Map;if(!t){for(let[d,u]of this._nodes)r.set(u,d);let a=[];for(let[d,u]of this._nodes)if(u instanceof V)for(let c of u._deps){let f=r.get(c.node);f!=null&&a.push([f,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 o=[];this._collectObserveTargets("",o);let s=new Map;for(let[a,d]of o)s.set(d,a);let i=[];for(let[a,d]of o)if(d instanceof V)for(let u of d._deps){let c=s.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 o=new n(e);return this.mount(e,o)}if(typeof t=="function"){let o=new n(e);return t(o),this.mount(e,o)}let r=t;if(ln(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 o=this;o!=null;o=o._parent)if(o===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 t=ys(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 r=t[0],o=t.slice(1);if(o.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 s=this._nodes.get(r);if(s&&o.length>0&&o[0]===se)return this._resolveMetaChainFromNode(s,o,t.join(H));let i=this._mounts.get(r);if(!i)throw this._nodes.has(r)?new Error(`Graph "${this.name}": "${r}" is a node; trailing path "${o.join(H)}" is invalid`):new Error(`Graph "${this.name}": unknown mount or node "${r}"`);return i.resolve(o.join(H))}_resolveMetaChainFromNode(e,t,r){let o=e,s=0,i=[...t];for(;s<i.length;){if(i[s]!==se)throw new Error(`Graph "${this.name}": expected ${se} segment in meta path "${r}"`);if(s+1>=i.length)throw new Error(`Graph "${this.name}": meta path requires a key after ${se} in "${r}"`);let a=i[s+1],d=o.meta[a];if(!d)throw new Error(`Graph "${this.name}": unknown meta "${a}" in path "${r}"`);o=d,s+=2}return o}signal(e,t){if(t?.internal!==!0){for(let o of e)if(this.config.messageTier(o[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,t??{},new Set,r),r.length>0)throw r[0]}_signalDeliver(e,t,r,o){for(let d of this._mounts.values())d._signalDeliver(e,t,r,o);let i=t.internal===!0?{internal:!0}:{actor:t.actor,delivery:"signal"},a=bs(e,this.config);for(let d of[...this._nodes.keys()].sort()){let u=this._nodes.get(d);if(!r.has(u)){r.add(u);try{u.down(e,i)}catch(c){if(c instanceof oe)throw c;o.push(c)}a.length!==0&&this._signalMetaSubtree(u,a,r,i,o)}}}_signalMetaSubtree(e,t,r,o,s){for(let i of Object.keys(e.meta).sort()){let a=e.meta[i];if(!r.has(a)){r.add(a);try{a.down(t,o)}catch(d){if(d instanceof oe)throw d;s.push(d)}this._signalMetaSubtree(a,t,r,o,s)}}}describe(e){if(e?.reactive==="diff")return this._describeReactiveDiff(e);if(e?.reactive===!0)return this._describeReactive(e);let t=ns(e?.actor),r=e?.filter,o=rt(e?.detail,e?.fields),s=e?.format==="spec",i=s?rt("minimal"):o,a=[];this._collectObserveTargets("",a);let d=new Map;for(let[R,g]of a)d.set(g,R);let u=[];{let R=a.map(([,k])=>k),g=new Set(d.values()),w=0;for(;R.length>0;){let k=R.shift();if(k instanceof V)for(let E of k._deps){let T=E.node;if(d.has(T))continue;let N=T.name??"",S=N;if(!S||g.has(S))if(N){let A=2;for(;g.has(`${N}#${A}`);)A++;S=`${N}#${A}`}else for(S=`__internal__/${w++}`;g.has(S);)S=`__internal__/${w++}`;d.set(T,S),g.add(S),u.push([S,T]),R.push(T)}}}let c=[...a,...u],f={};for(let[R,g]of c){if(t!=null&&!g.allowsObserve(t))continue;let w=sn(g,i),k=g instanceof V?g._deps.map(S=>d.get(S.node)??S.node.name??""):[],{name:E,...T}=w,N={...T,deps:k};if(!s){let S=this._annotations.get(R);S!=null&&(N.annotation=S)}if(r!=null)if(typeof r=="function"){let S=r;if(!(S.length>=2?S(R,N):S(N)))continue}else{let S=!0;for(let[A,G]of Object.entries(r)){let I=A==="deps_includes"?"depsIncludes":A==="meta_has"?"metaHas":A;if(I==="depsIncludes"){if(!N.deps.includes(String(G))){S=!1;break}continue}if(I==="metaHas"){if(!Object.hasOwn(N.meta??{},String(G))){S=!1;break}continue}if(N[I]!==G){S=!1;break}}if(!S)continue}f[R]=N}let p=new Set(Object.keys(f)),h=[];for(let[R,g]of c)if(g instanceof V)for(let w of g._deps){let k=d.get(w.node);k!=null&&h.push([k,R])}h.sort((R,g)=>R[0]<g[0]?-1:R[0]>g[0]?1:R[1]<g[1]?-1:R[1]>g[1]?1:0);let l=h.map(([R,g])=>({from:R,to:g}));(t!=null||r!=null)&&(l=l.filter(R=>p.has(R.from)&&p.has(R.to)));let y=this._collectSubgraphs(""),m=t!=null||r!=null?y.filter(R=>{let g=`${R}${H}`;return[...p].some(w=>w===R||w.startsWith(g))}):y,x=this,_=e,v={name:this.name,nodes:f,edges:l,subgraphs:m,...this._factory!==void 0?{factory:this._factory}:{},...this._factoryArgs!==void 0?{factoryArgs:this._factoryArgs}:{},expand(R){let g={..._,format:void 0};return Array.isArray(R)?(g.fields=R,g.detail=void 0):(g.detail=R,g.fields=void 0),x.describe(g)}},b=e??{},O=b.format;return O==="json"?us(v,b):O==="pretty"?ds(v,b):O==="mermaid"?zr(v,b):O==="mermaid-url"?cs(v,b):O==="d2"?ls(v,b):O==="ascii"?Nr(v,b):v}_collectSubgraphs(e){let t=[];for(let r of[...this._mounts.keys()].sort()){let o=e===""?r:`${e}${r}`;t.push(o),t.push(...this._mounts.get(r)._collectSubgraphs(`${o}${H}`))}return t}resourceProfile(e){return Lr(this,e)}reachable(e,t,r={}){return r.withDetail===!0?pn(this.describe(),e,t,{...r,withDetail:!0}):pn(this.describe(),e,t,r)}explain(e,t,r){return r?.reactive===!0?this._explainReactive(e,t,r):this._explainStatic(e,t,r)}_explainStatic(e,t,r){let o=this.describe({detail:"full"}),s=new Map(this._annotations),i=new Map;for(let[a,d]of Object.entries(o.nodes))d.lastMutation!=null&&i.set(a,d.lastMutation);return Ar(o,e,t,{...r?.maxDepth!=null?{maxDepth:r.maxDepth}:{},...r?.findCycle===!0?{findCycle:!0}:{},annotations:s,lastMutations:i})}_describeReactive(e){let t={...e,reactive:!1},r=e.reactiveName??"describe",o=0,s=Y(o,{name:`${r}_version`}),i=this.observe({timeline:!0,structured:!0}),a=!1,d=!1,u=()=>{a||d||(a=!0,Ve(()=>{a=!1,!d&&(o+=1,s.emit(o))}))},c=i.onEvent(_=>{let v=_.type;v!=="data"&&v!=="error"&&v!=="complete"&&v!=="teardown"||u()}),f=[],p=new WeakSet,h=_=>{if(p.has(_)||d)return;p.add(_);let v=_.topology.subscribe(b=>{for(let O of b){if(O[0]!==M)continue;let R=O[1];if(u(),R.kind==="added"&&R.nodeKind==="mount"){let g=_._mounts.get(R.name);g!=null&&h(g)}}});f.push(v);for(let b of _._mounts.keys()){let O=_._mounts.get(b);O!=null&&h(O)}};h(this);let l,y=e.actor;Hr(y)&&(l=y.subscribe(_=>{let v=!1,b=!1;for(let O of _){let R=O[0];R===M?v=!0:(R===$||R===D||R===F)&&(b=!0)}v&&u(),b&&(l?.(),l=void 0,u())}));let m;try{m=Q([s],()=>this.describe(t),{name:r,describeKind:"derived",meta:{domain:"audit",kind:"describe"},equals:(_,v)=>_===v})}catch(_){c(),l?.();for(let v of f)v();throw i.dispose(),_}let x=de(m);return{node:m,dispose(){d=!0,c(),l?.();for(let _ of f)_();f.length=0,i.dispose(),x()}}}_describeReactiveDiff(e){let t={...e,format:void 0,reactive:!1},r=e.reactiveName??"describe-diff",o={name:this.name,nodes:{},edges:[],subgraphs:[]},s=this.describe(t),i=dn(o,s),a=Y(i,{name:r,meta:{domain:"audit",kind:"describe-diff"},equals:(p,h)=>p===h}),d=this._describeReactive({...e,format:void 0,reactiveName:void 0}),u=!1,c=d.node.subscribe(p=>{if(!u)for(let h of p){if(h[0]!==M)continue;let l=h[1],y=dn(s,l);s=l,y.events.length!==0&&a.emit(y)}}),f=de(a);return{node:a,dispose(){u=!0,c(),d.dispose(),a.down([[F,"describe-diff disposed"]]),f()}}}_explainReactive(e,t,r){let o=0,s=Y(o,{name:"explain_version"}),i=this.observe({timeline:!0,structured:!0}),a=!1,d=!1,u=i.onEvent(h=>{let l=h.type;l!=="data"&&l!=="error"&&l!=="complete"&&l!=="teardown"||a||d||(a=!0,Ve(()=>{a=!1,!d&&(o+=1,s.emit(o))}))}),c={...r?.maxDepth!=null?{maxDepth:r.maxDepth}:{},...r?.findCycle===!0?{findCycle:!0}:{}},f;try{f=Q([s],()=>this._explainStatic(e,t,c),{name:r?.name??"explain",describeKind:"derived",meta:{domain:"audit",kind:"explain_path",from:e,to:t},equals:(h,l)=>h.found===l.found&&h.reason===l.reason&&h.steps.length===l.steps.length&&vs(h.steps,l.steps)})}catch(h){throw u(),i.dispose(),h}let p=de(f);return{node:f,dispose(){d=!0,u(),i.dispose(),p()}}}_pathsMatching(e){let t=Ct(e),r=[];return this._collectObserveTargets("",r),r.map(([o])=>o).filter(o=>t.test(o))}_collectObserveTargets(e,t){for(let r of[...this._mounts.keys()].sort()){let o=e===""?r:`${e}${H}${r}`;this._mounts.get(r)._collectObserveTargets(o,t)}for(let r of[...this._nodes.keys()].sort()){let o=this._nodes.get(r),s=e===""?r:`${e}${H}${r}`;t.push([s,o]),this._appendMetaObserveTargets(s,o,t)}}_appendMetaObserveTargets(e,t,r){for(let o of Object.keys(t.meta).sort()){let s=t.meta[o],i=`${e}${H}${se}${H}${o}`;r.push([i,s]),this._appendMetaObserveTargets(i,s,r)}}observe(e,t){let r=typeof e=="string",s=$r(r?t:e);if(s.reactive===!0)return this._observeReactive(r?e:void 0,s);let i=s.structured===!0||s.timeline===!0||s.causal===!0||s.derived===!0||s.detail==="minimal"||s.detail==="full"||s.format!=null,a=s.actor;if(r){let c=e,f=this.resolve(c);if(a!=null&&!f.allowsObserve(a))throw new oe({actor:a,action:"observe",nodeName:c});return i?this._buildStructuredObserver([[c,f]],s,"one"):{subscribe(p){return f.subscribe(p)},up(p){try{f.up?.(p)}catch(h){if(h instanceof oe)return;throw h}}}}let d=[];this._collectObserveTargets("",d),d.sort((c,f)=>c[0]<f[0]?-1:c[0]>f[0]?1:0);let u=a==null?d:d.filter(([,c])=>c.allowsObserve(a));return i?this._buildStructuredObserver(u,s,"all"):{subscribe:c=>{let f=u.map(([p,h])=>h.subscribe(l=>{c(p,l)}));return()=>{for(let p of f)p()}},up:(c,f)=>{try{this.resolve(c).up?.(f)}catch(p){if(p instanceof oe)return;throw p}}}}_observeReactive(e,t){let r=t.tiers,o=r!=null?new Set(r):null,s=t.reactiveName??"observe";return Oe(i=>{let a=[],d=!1,u=!1,c=()=>{if(a.length===0||u)return;let y={events:a.slice(),flushedAt_ns:ce()};a.length=0,i.emit(y)},f={...t,reactive:!1,structured:!0,timeline:!0},p=e!=null?this.observe(e,f):this.observe(f),h=y=>{u||(a.push(y),!d&&(d=!0,Ve(()=>{d=!1,c()})))};for(let y of p.events)h(y);let l=p.onEvent(h);return()=>{u=!0,l(),p.dispose()}},{name:s,meta:{domain:"audit",kind:"observe-reactive"}})}_buildStructuredObserver(e,t,r){let o=r==="one"?e[0]?.[0]:void 0,s=i=>{if(r==="one"&&o!=null){let c=this.resolve(o);return this._buildStructuredObserver([[o,c]],i,"one")}let a=[];this._collectObserveTargets("",a),a.sort((c,f)=>c[0]<f[0]?-1:c[0]>f[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,s)}_createObserveResult(e,t,r){let o=t.timeline===!0,s=t.causal===!0,i=t.derived===!0,a=t.detail==="minimal",d=this.config.inspectorEnabled,u=(s||i)&&d,c=t.maxEvents,f=c!=null&&c>0?new ot(c):null,p=[],h=new Set,l=t.tiers!=null?new Set(t.tiers):null,y={},m=new Set,x=0,_=0,v=0,b=0,O=0,R=0,g=!1,w=!1,k=0,E=new Map,T=new Map,N=new Map,S=C=>{if(!(l!=null&&!l.has(C.type))){f?f.push(C):p.push(C);for(let P of h)P(C)}},A=C=>l==null||l.has(C),G=()=>o?{timestamp_ns:ce(),in_batch:mt(),batch_id:k}:{},I=(C,P)=>{if(!(!u||!(C instanceof V)))return C._setInspectorHook(X=>{if(X.kind==="dep_message")E.set(C,X.depIndex);else if(X.kind==="run"){let Ke=X.batchData.map((L,j)=>L!=null&&L.length>0?L.at(-1):X.prevData[j]);T.set(C,Ke);let Z=X.batchData.map(L=>L!=null?[...L]:void 0);N.set(C,Z),i&&S({type:"derived",path:P,dep_values:Ke,dep_batches:Z,...G()})}})},q=C=>{let P=E.get(C),X=T.get(C);if(!s||X==null)return{};let Z=(P!=null&&P>=0&&C instanceof V?C._deps[P]:void 0)?.node,L=Z?.v,j=N.get(C);return{trigger_dep_index:P,trigger_dep_name:Z?.name,...L!=null?{trigger_version:{id:L.id,version:L.version}}:{},dep_values:[...X],...j!=null?{dep_batches:j}:{}}},Se=[],Ne=[];for(let[C,P]of e){let X=I(P,C);X&&Se.push(X),Ne.push(P.subscribe(Ke=>{k++;for(let Z of Ke){let L=Z[0],j=G();if(L===M){y[C]=Z[1];let Ft=P instanceof V?P.lastMutation?.actor??fe:fe;S({type:"data",path:C,data:Z[1],actor:Ft,...j,...q(P)})}else if(a)L===W?A("dirty")&&x++:L===K?A("resolved")&&_++:L===ee?A("invalidate")&&v++:L===J?A("pause")&&b++:L===te?A("resume")&&O++:L===F?A("teardown")&&R++:L===$&&!m.has(C)?A("complete")&&(g=!0):L===D&&A("error")&&(w=!0,m.add(C));else if(L===W)A("dirty")&&x++,S({type:"dirty",path:C,...j});else if(L===K)A("resolved")&&_++,S({type:"resolved",path:C,...j,...q(P)});else if(L===ee)A("invalidate")&&v++,S({type:"invalidate",path:C,...j});else if(L===J)A("pause")&&b++,S({type:"pause",path:C,lockId:Z[1],...j});else if(L===te)A("resume")&&O++,S({type:"resume",path:C,lockId:Z[1],...j});else if(L===$)A("complete")&&!m.has(C)&&(g=!0),S({type:"complete",path:C,...j});else if(L===D){A("error")&&(w=!0,m.add(C));let Ft=P instanceof V?P.lastMutation?.actor??fe:fe;S({type:"error",path:C,data:Z[1],actor:Ft,...j})}else L===F&&(A("teardown")&&R++,S({type:"teardown",path:C,...j}))}}))}let Be=!1,We=()=>{if(!Be){Be=!0;for(let C of Ne)C();for(let C of Se)C();for(let C of lt)C({value:void 0,done:!0});lt.length=0}},Ht=[],lt=[];h.add(C=>{let P=lt.shift();P?P({value:C,done:!1}):Ht.push(C)});let _n={get values(){return y},get dirtyCount(){return x},get resolvedCount(){return _},get invalidateCount(){return v},get pauseCount(){return b},get resumeCount(){return O},get teardownCount(){return R},get events(){return f?f.toArray():[...p]},get anyCompletedCleanly(){return g},get anyErrored(){return w},get completedWithoutErrors(){return g&&!w},onEvent(C){return h.add(C),()=>h.delete(C)},dispose:We,expand(C){We();let P={...t};return typeof C=="string"?P.detail=C:Object.assign(P,C),r($r(P))},[Symbol.asyncIterator](){return{next(){return Ht.length>0?Promise.resolve({value:Ht.shift(),done:!1}):Be?Promise.resolve({value:void 0,done:!0}):new Promise(C=>lt.push(C))},return(){return We(),Promise.resolve({value:void 0,done:!0})}}}};return t.format!=null&&this._attachFormatLogger(_n,t),_n}_attachFormatLogger(e,t){let r=t.format;if(r==null)return;let o=t.logger??(l=>console.log(l)),s=t.includeTypes?new Set(t.includeTypes):null,i=t.excludeTypes?new Set(t.excludeTypes):null,a=s==null&&i==null?()=>!0:l=>(s==null||s.has(l))&&(i==null||!i.has(l)),d=gs(t.theme),u=r==="stage-log"?ce():0,c=l=>l==null?"":t.stageLabels?.[l]??l,f=(l,y)=>l.length>y?`${l.slice(0,y-1)}\u2026`:l,p=l=>l.type==="data"||l.type==="error"?f(Mt(l.data),120):"",h=l=>{if(r==="stage-log"){let g=(ce()-u)/1e9,w=c(l.path).padEnd(9);if(l.type==="data"){let k=p(l);return`[${g.toFixed(3)}s] ${w} \u2190${k?` ${k}`:""}`}if(l.type==="error"){let k=p(l);return`[${g.toFixed(3)}s] ${w} \u2717${k?` ${k}`:""}`}return l.type==="complete"?`[${g.toFixed(3)}s] ${w} \u25A0 complete`:`[${g.toFixed(3)}s] ${w} ${l.type}`}if(r==="json")try{return JSON.stringify(l)}catch{return JSON.stringify({type:l.type,path:l.path,data:"[unserializable]"})}let y=d[l.type]??"",m=l.path?`${d.path}${l.path}${d.reset} `:"",x=l.type==="data"||l.type==="error",_=l.type==="pause"||l.type==="resume",v=x?` ${Mt(l.data)}`:_?` ${Mt(l.lockId)}`:"",b=l.type==="data"||l.type==="resolved"||l.type==="derived"?l:void 0,O=b?.trigger_dep_name!=null?` <- ${b.trigger_dep_name}`:b?.trigger_dep_index!=null?` <- #${b.trigger_dep_index}`:"",R=l.in_batch?" [batch]":"";return`${m}${y}${l.type.toUpperCase()}${d.reset}${v}${O}${R}`};e.onEvent(l=>{a(l.type)&&o(h(l),l)})}addDisposer(e){return this._disposers.add(e),()=>{this._disposers.delete(e)}}destroy(){Ir(this._disposers,this.name),this.signal([[F]],{internal:!0}),Ir(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,...r}=this.describe({detail:"full"}),o={};for(let a of Object.keys(r.nodes).sort()){let{lastMutation:d,guard:u,...c}=r.nodes[a];o[a]=c}let s=[...r.subgraphs].sort(),i={...r,version:1,nodes:o,subgraphs:s};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 Bn(a,a.encode(i))}throw new Error(`snapshot: unknown format "${String(e.format)}"`)}static decode(e,t){let r=t?.config??Te,{codec:o,codecVersion:s,payload:i}=Wn(e,r);return o.decode(i,s)}restore(e,t){if(Pr(e),e.name!==this.name)throw new Error(`Graph "${this.name}": restore snapshot name "${e.name}" does not match this graph`);let r=t?.only==null?null:(Array.isArray(t.only)?t.only:[t.only]).map(s=>Ct(s)),o=t?.includeProducers===!0;for(let s of Object.keys(e.nodes).sort()){if(r!==null&&!r.some(a=>a.test(s)))continue;let i=e.nodes[s];if(i!==void 0){if(!("value"in i)||i.value===void 0){"value"in i&&i.value===void 0&&t?.onError?.(s,new Error(`restore: slice.value is undefined for "${s}" (undefined is the global SENTINEL; not valid DATA)`));continue}if(!(i.type==="derived"||i.type==="effect")&&!(i.type==="producer"&&!o)){if(i.v!=null){let d=this.tryResolve(s)?.v;if(d!=null&&d.id===i.v.id&&d.version===i.v.version)continue}try{this.set(s,i.value)}catch(a){t?.onError?.(s,a)}}}}}static fromSnapshot(e,t){Pr(e);let r=typeof t=="function"?t:t?.build,o=typeof t=="function"?void 0:t?.factories,s=new n(e.name);if(r)return r(s),s.restore(e),s;for(let h of[...e.subgraphs].sort((l,y)=>{let m=l.split(H).length,x=y.split(H).length;return m!==x?m-x:l<y?-1:l>y?1:0})){let l=h.split(H),y=s;for(let m of l)y._mounts.has(m)||y.mount(m,new n(m)),y=y._mounts.get(m)}let i=o?Object.entries(o).map(([h,l])=>({re:Ct(h),factory:l})):[],a=h=>{for(let l of i)if(l.re.test(h))return l.factory},d=h=>{let l=h.split(H),y=l.pop();if(y==null||y.length===0)throw new Error(`invalid snapshot path "${h}"`);let m=s;for(let x of l){let _=m._mounts.get(x);if(!_)throw new Error(`unknown mount "${x}" in path "${h}"`);m=_}return[m,y]},u=Object.entries(e.nodes).filter(([h])=>!h.includes(`${H}${se}${H}`)).sort((h,l)=>h[0]<l[0]?-1:h[0]>l[0]?1:0),c=new Map(u),f=new Map,p=!0;for(;c.size>0&&p;){p=!1;for(let[h,l]of[...c.entries()]){let y=l?.deps??[];if(!y.every(O=>f.has(O)))continue;let[m,x]=d(h),_={...l?.meta??{}},v=a(h),b;if(l?.type==="state")b=Y(l.value,{meta:_});else{if(v==null)continue;b=v(x,{path:h,type:l.type,value:l.value,meta:_,deps:y,resolvedDeps:y.map(O=>f.get(O))})}m.add(b,{name:x}),f.set(h,b),c.delete(h),p=!0}}if(c.size>0){let h=[...c.keys()].sort().join(", ");throw new Error(`Graph.fromSnapshot could not reconstruct nodes without build callback: ${h}. Pass matching factories via fromSnapshot(data, { factories: { pattern: factoryFn } }).`)}return s.restore(e),s}toJSON(){return this.snapshot()}attachSnapshotStorage(e,t={}){let r=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 o=(u,c)=>{if(u.disposed)return;let f=rs(c.nodes);if(u.lastSnapshot!=null&&f!==""&&f===u.lastFingerprint)return;let p=u.seq+1,h=re(),m=u.lastSnapshot==null||p%u.compactEvery===0?{name:this.name,mode:"full",snapshot:c,seq:p,timestamp_ns:h,format_version:ke}:{name:this.name,mode:"diff",diff:Br(u.lastSnapshot,c),seq:p,timestamp_ns:h,format_version:ke};if(u.tier.filter&&!u.tier.filter(m))return;let x;try{x=u.tier.save(m)}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=p,u.lastSnapshot=c,u.lastFingerprint=f)},O=>{t.onError?.(O,u.tier)});u.savePending=b.finally(()=>{u.savePending===b&&(u.savePending=void 0)})}else u.seq=p,u.lastSnapshot=c,u.lastFingerprint=f},s=(u,c)=>{try{o(u,c)}catch(f){t.onError?.(f,u.tier)}},i=(u,c)=>{if(!c.some(l=>{let y=this.config.messageTier(l[0]);return y>=3&&y<5}))return;if(t.filter){let l=this.tryResolve(u);if(l==null)return;let y=sn(l,rt("standard"));if(!t.filter(u,y))return}let p,h=()=>(p==null&&(p=this.snapshot()),p);for(let l of r)l.disposed||(l.debounceMs===0?s(l,h()):(l.timer==null&&(l.timer=new Et),l.timer.start(l.debounceMs,()=>{l.disposed||s(l,this.snapshot())})))},a;if(t.paths!=null){let c=(typeof t.paths=="string"?this._pathsMatching(t.paths):t.paths).map(f=>{let p=this.tryResolve(f);return p==null?()=>{}:p.subscribe(h=>i(f,h))});a=()=>{for(let f of c)f()}}else a=this.observe().subscribe((u,c)=>i(u,c));let d=()=>{a();for(let u of r)u.disposed=!0,u.timer?.cancel();this._storageDisposers.delete(d)};return this._storageDisposers.add(d),{dispose:d}}async _cascadeRestore(e,t){for(let r of e){let o;try{o=await r.load?.()}catch(i){t?.(i,r);continue}if(o==null||typeof o!="object"||Array.isArray(o))continue;let s=o;try{if(s.mode==="full"&&s.snapshot!=null)return this.restore(s.snapshot),!0;if(s.version===ke&&s.nodes!=null)return this.restore(s),!0}catch(i){t?.(i,r)}}return!1}static async fromStorage(e,t,r){for(let o of t){let s;try{s=await o.load?.()}catch(d){r?.onError?.(d,o);continue}if(s==null||typeof s!="object"||Array.isArray(s))continue;let i=s,a=i.mode==="full"&&i.snapshot!=null?i.snapshot:i.version===ke&&i.nodes!=null?i:void 0;if(a!=null)try{return n.fromSnapshot(a,r)}catch(d){r?.onError?.(d,o)}}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,r){if(e!=null&&t!=null){if(this.tryResolve(e)==null)return;if(this._annotations.set(e,t),this.config.inspectorEnabled){let o={path:e,annotation:t,timestamp_ns:ce(),...r?.actor!=null?{actor:r.actor}:{}};this._traceRing.push(o)}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(o=>!e(o)),r=this._traceRing.size-t.length;this._traceRing.clear();for(let o of t)this._traceRing.push(o);return r}static diff(e,t){let r=new Set(Object.keys(e.nodes)),o=new Set(Object.keys(t.nodes)),s=[...o].filter(_=>!r.has(_)).sort(),i=[...r].filter(_=>!o.has(_)).sort(),a=[],d=[];for(let _ of r){if(!o.has(_))continue;let v=e.nodes[_],b=t.nodes[_],O=v.v,R=b.v;O!=null&&R!=null&&O.id===R.id&&O.version!==R.version&&d.push({path:_,id:O.id,from:O.version,to:R.version});let g=O!=null&&R!=null&&O.id===R.id&&O.version===R.version;for(let w of["type","status","sentinel"]){let k=v[w],E=b[w];k!==E&&a.push({path:_,field:w,from:k,to:E})}if(!g)for(let w of["value","meta"]){let k=v[w],E=b[w];os(k,E)||a.push({path:_,field:w,from:k,to:E})}}let u=_=>`${_.from} ${_.to}`,c=new Set(e.edges.map(u)),f=new Set(t.edges.map(u)),p=t.edges.filter(_=>!c.has(u(_))),h=e.edges.filter(_=>!f.has(u(_))),l=new Set(e.subgraphs),y=new Set(t.subgraphs),m=[...y].filter(_=>!l.has(_)).sort(),x=[...l].filter(_=>!y.has(_)).sort();return{nodesAdded:s,nodesRemoved:i,nodesChanged:a,versionChanges:d,edgesAdded:p,edgesRemoved:h,subgraphsAdded:m,subgraphsRemoved:x}}};function Br(n,e){let t=ie.diff(n,e),r={};for(let o of t.nodesAdded){let s=e.nodes[o];s!=null&&(r[o]=s)}return{...t,nodesAddedFull:r}}function pn(n,e,t,r={}){let o={paths:[],depths:new Map,truncated:!1};if(!e)return r.withDetail?o:[];if(!r.both&&t!=="upstream"&&t!=="downstream")throw new Error('reachable: direction must be "upstream" or "downstream"');let s=r.maxDepth;if(s!=null&&(!Number.isInteger(s)||s<0))throw new Error("reachable: maxDepth must be an integer >= 0");if(s===0)return r.withDetail?o:[];let i=new Map,a=new Map,d=new Map,u=new Map,c=new Set;for(let[v,b]of Object.entries(n.nodes)){if(!v)continue;c.add(v);let O=b.deps??[];i.set(v,O);for(let R of O)R&&(c.add(R),a.has(R)||a.set(R,new Set),a.get(R).add(v))}for(let v of n.edges){if(v==null||typeof v!="object")continue;let b=typeof v.from=="string"?v.from:"",O=typeof v.to=="string"?v.to:"";!b||!O||(c.add(b),c.add(O),u.has(b)||u.set(b,new Set),u.get(b).add(O),d.has(O)||d.set(O,new Set),d.get(O).add(b))}if(!c.has(e))return r.withDetail?o:[];let f=r.both===!0,p=v=>{if(f){let g=i.get(v)??[],w=d.get(v),k=a.get(v),E=u.get(v),T=[...g];return w&&T.push(...w),k&&T.push(...k),E&&T.push(...E),T}if(t==="upstream"){let g=i.get(v)??[],w=d.get(v);return w?[...g,...w]:g}let b=a.get(v),O=u.get(v),R=b?[...b]:[];return O&&R.push(...O),R},h=new Set([e]),l=new Map,y=[{path:e,depth:0}],m=0,x=!1;for(;m<y.length;){let v=y[m++];if(s!=null&&v.depth>=s){p(v.path).length>0&&(x=!0);continue}for(let b of p(v.path))!b||h.has(b)||(h.add(b),l.set(b,v.depth+1),y.push({path:b,depth:v.depth+1}))}let _=[...l.keys()].sort((v,b)=>v<b?-1:v>b?1:0);return r.withDetail?{paths:_,depths:l,truncated:x}:_}function vs(n,e){if(n.length!==e.length)return!1;for(let t=0;t<n.length;t++){let r=n[t],o=e[t];if(r.path!==o.path||r.type!==o.type||r.status!==o.status||r.hop!==o.hop||r.dep_index!==o.dep_index||r.annotation!==o.annotation||r.value!==o.value||r.lastMutation!==o.lastMutation)return!1;let s=r.v,i=o.v;if(s!==i&&(s==null||i==null||s.id!==i.id||s.version!==i.version))return!1}return!0}et();$e();xe();Qe();xe();ae();an();Ee();je();et();ae();Ee();je();var hn=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 r=Math.min(e.length,t),o=e.length-r;for(let s=0;s<r;s++)this._buf[s]=e[o+s];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 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 r=t;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 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 r=0;r<t;r++)this._buf[(this._head+r)%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 r=t===void 0?this._size:Math.min(Math.max(t,0),this._size),o=Math.min(e,this._size);if(o>=r)return[];let s=r-o;if(this._maxSize===void 0)return this._buf.slice(o,r);let i=new Array(s);for(let a=0;a<s;a++)i[a]=this._buf[(this._head+o+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 s=0;s<t;s++)this._buf[s]=void 0;this._head=0;let r=Math.min(e.length,t),o=e.length-r;for(let s=0;s<r;s++)this._buf[s]=e[o+s];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 st(n){return n.subscribe(()=>{})}var _s=64;function it(n,e={}){let{name:t,maxSize:r,versioning:o,guard:s,backend:i}=e,a=i??new hn(n,r),d=Y(a.toArray(),{name:t,describeKind:"state",equals:(g,w)=>g===w,...o!=null?{versioning:o}:{},...s!=null?{guard:s}:{}});function u(){let g=a.toArray();ze(()=>{d.down([[W]],{internal:!0}),d.down([[M,g]],{internal:!0})})}let c=new Map,f=new Map,p=new Map;function h(g,w){return`${g}:${w===void 0?"END":w}`}function l(g){if(g.size<_s)return;let w=g.keys().next();if(w.done)return;let k=g.get(w.value);k!==void 0&&k.dispose(),g.delete(w.value)}function y(g){let w=a.version;try{return g()}finally{a.version!==w&&u()}}function m(g){if(!Number.isInteger(g)||g<0)throw new RangeError(`tail: n must be a non-negative integer (got ${g})`);let w=c.get(g);if(w!==void 0)return c.delete(g),c.set(g,w),w.node;l(c);let k=Q([d],([T])=>{let N=T;return g===0||N.length===0?[]:N.slice(Math.max(0,N.length-g))},{initial:a.tail(g),describeKind:"derived"}),E=st(k);return c.set(g,{node:k,dispose:E}),k}function x(g,w){if(!Number.isInteger(g)||g<0)throw new RangeError(`slice: start must be a non-negative integer (got ${g})`);if(w!==void 0&&(!Number.isInteger(w)||w<0))throw new RangeError(`slice: stop must be a non-negative integer or undefined (got ${w})`);let k=h(g,w),E=f.get(k);if(E!==void 0)return f.delete(k),f.set(k,E),E.node;l(f);let T=Q([d],([S])=>{let A=S;return w===void 0?A.slice(g):A.slice(g,w)},{initial:a.slice(g,w),describeKind:"derived"}),N=st(T);return f.set(k,{node:T,dispose:N}),T}function _(g){let w=p.get(g);if(w!==void 0)return w.node;let k=Q([d,g],([T,N])=>{let S=T,A=Math.max(0,Math.trunc(N??0));return S.slice(A)},{initial:[],describeKind:"derived"}),E=st(k);return p.set(g,{node:k,dispose:E}),k}let v,b;function O(){v===void 0&&(v=le([d],(g,w,k)=>{let E=g[0],N=E!=null&&E.length>0?E.at(-1):k.prevData[0];if(N==null||N.length===0){w.down([[K]]);return}w.emit(N[N.length-1])},{name:t!=null?`${t}::lastValue`:"lastValue",describeKind:"derived",initial:a.size===0?void 0:a.at(a.size-1)}),b=Q([d],([g])=>g.length>0,{name:t!=null?`${t}::hasLatest`:"hasLatest",describeKind:"derived",initial:a.size>0}),st(v),st(b))}let R={entries:d,get size(){return a.size},at(g){return a.at(g)},append(g){y(()=>a.append(g))},appendMany(g){g.length!==0&&y(()=>a.appendMany(g))},clear(){y(()=>a.clear())},trimHead(g){y(()=>a.trimHead(g))},withLatest(){return O(),d},get lastValue(){return O(),v},get hasLatest(){return O(),b},view(g){switch(g.kind){case"tail":return m(g.n);case"slice":return x(g.start,g.stop);case"fromCursor":return _(g.cursor)}},attach(g){let w=g.subscribe(k=>{for(let E of k)E[0]===M&&R.append(E[1])});return()=>w()},attachStorage(g){if(g.length===0)return()=>{};let w=new Map;for(let E of g)w.set(E,a.size);(async()=>{for(let E of g)if(typeof E.loadEntries=="function")try{let T=await Promise.resolve(E.loadEntries());T.entries.length>0&&a.size===0&&(a.restore(T.entries),w.set(E,T.entries.length),u());break}catch{}})();let k=d.subscribe(E=>{for(let T of E){if(T[0]!==M)continue;let N=T[1];for(let S of g){let A=w.get(S)??0;if(N.length<A){try{let I=S.appendEntries(N);I instanceof Promise&&I.catch(()=>{})}catch{}w.set(S,N.length);continue}if(N.length===A)continue;let G=N.slice(A);w.set(S,N.length);try{let I=S.appendEntries(G);I instanceof Promise&&I.catch(()=>{})}catch{}}}});return()=>k()},disposeAllViews(){for(let g of c.values())g.dispose();c.clear();for(let g of f.values())g.dispose();f.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 f.values())g.dispose();f.clear();for(let g of p.values())g.dispose();p.clear()}};return R}var he=class extends Error{constructor(e,t){super(e,t),this.name=this.constructor.name}},Dt=class extends he{constructor(t,r){super(`Duplicate ${t} registration: "${r}"`);this.kind=t;this.registrationName=r}},Gt=class extends he{constructor(t,r,o){super(`Command "${t}" emitted undeclared event "${r}". Declared emits: [${o.join(", ")}]`);this.commandName=t;this.eventName=r;this.declaredEmits=o}},Lt=class extends he{constructor(t,r,o){super(`Optimistic concurrency conflict on aggregate "${t}": expected version ${r}, got ${o}`);this.aggregateId=t;this.expected=r;this.actual=o}},It=class extends he{constructor(t){super(`Unknown command: "${t}". Register with command() first.`);this.commandName=t}},at=class extends he{constructor(t,r){super(`Command handler "${t}" threw: ${r instanceof Error?r.message:String(r)}`,{cause:r});this.commandName=t}};var ut=class extends he{constructor(t,r){super(`Projection "${t}" rebuild failed: ${r instanceof Error?r.message:String(r)}`,{cause:r});this.projectionName=t}};xe();je();var ws=qe((n,e)=>{n("observe"),n("signal"),e("write")});function Pt(n){let e=it([],{name:n.name,maxSize:n.retainedLimit??1024,guard:n.guard??ws,...n.versioning!=null?{versioning:n.versioning}:{}});return e.withLatest(),n.graph&&n.graph.add(e.entries,{name:n.name}),e}function Wr(n,e,t=0){let r=Y(t,{name:e,describeKind:"state"});return n.add(r,{name:e}),r}function Kr(n,e,t,r=0){let o={},s=new ie(e);for(let i of t){let a=Y(r,{name:i,describeKind:"state"});s.add(a,{name:i}),o[i]=a}return n.mount(e,s),o}_t();function Ur(n,e,t){return{[n]:!0,[`${n}_type`]:e,...t??{}}}var xs=qe((n,e)=>{n("write"),n("signal"),e("observe")}),Ts=qe((n,e)=>{n("observe"),n("signal"),e("write")}),Yr=qe((n,e)=>{n("observe"),n("signal"),e("write")});function dt(n,e){return Ur("cqrs",n,e)}function gn(n){if(n===null||typeof n!="object"||Object.isFrozen(n))return n;for(let e of Object.keys(n))gn(n[e]);return Object.freeze(n)}var mn=class extends ie{_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=Pt({name:"dispatches",retainedLimit:this._retainedLimit,graph:this}),this.audit=this.dispatches,this.aggregateEvictions=Pt({name:"aggregateEvictions",retainedLimit:this._retainedLimit,graph:this}),this._dispatchSeqCursor=Wr(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 r=t.indexOf("::");if(r<0)continue;let o=t.slice(0,r),s=t.slice(r+2),i=this._aggregateVersions.get(t)??0;this._aggregateVersions.delete(t);let a=this._eventLogsByAggregate.get(o);a&&(a.delete(s),a.size===0&&this._eventLogsByAggregate.delete(o)),this.aggregateEvictions.append({aggregateId:s,type:o,lastVersion:i,t_ns:re()})}}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,r]of this._eventLogs){let o=r.log.attachStorage(e),s=this._attachedTierDisposers.get(t);s||(s=[],this._attachedTierDisposers.set(t,s)),s.push(o)}for(let[t,r]of this._eventLogsByAggregate)for(let[o,s]of r){let i=`${t}::${o}`,a=s.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 r=this._attachedTierDisposers.get(e);r||(r=[],this._attachedTierDisposers.set(e,r));for(let o of this._attachedEventTiers)r.push(t.attachStorage(o))}_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 r=this._eventLogs.get(e);if(r)return r.node;let o=it([],{name:e,versioning:0,maxSize:this._retainedLimit});o.withLatest();let s=o.entries,i=Q([s],([a])=>a,{name:e,describeKind:"state",meta:dt("event",{event_name:e}),guard:Yr,initial:s.cache});return this.add(i,{name:e}),this._keepaliveDisposers.push(de(i)),this._eventLogs.set(e,{log:o,node:i}),this._autoWireStreamStorage(e,o),i}_ensureAggregateStream(e,t){this._eventLogs.has(e)||this.event(e);let r=this._eventLogsByAggregate.get(e);r||(r=new Map,this._eventLogsByAggregate.set(e,r));let o=`${e}::${t}`;this._touchAggregate(o);let s=r.get(t);if(s)return s;let i=`${e}_${t.replace(/[^a-zA-Z0-9_-]/g,"_")}`,a=it([],{name:i,versioning:0,maxSize:this._retainedLimit});a.withLatest();let d=a.entries,u=Q([d],([h])=>h,{name:i,describeKind:"state",meta:dt("event_aggregate",{event_name:e,aggregate_id:t}),guard:Yr,initial:d.cache}),c=i,f=0;for(;this.nameOf(this.resolveOptional(c)??u)===c&&(f+=1,c=`${i}_${f}`,this.resolveOptional(c)!==void 0););try{this.add(u,{name:c})}catch{}this._keepaliveDisposers.push(de(u));let p={log:a,node:u};return r.set(t,p),this._autoWireStreamStorage(`${e}::${t}`,a),this._enforceAggregateLru(),p}resolveOptional(e){try{return this.resolve(e)}catch{return}}_appendEvent(e,t,r){let o=this._eventLogs.get(e);if(o||(this.event(e),o=this._eventLogs.get(e)),o.node.status==="completed"||o.node.status==="errored")throw new Error(`Cannot dispatch to terminated event stream "${e}" (status: ${o.node.status}).`);let s,i;if(r?.aggregateId!==void 0){let c=`${e}::${r.aggregateId}`;s=(this._aggregateVersions.get(c)??0)+1,this._aggregateVersions.set(c,s),i=this._ensureAggregateStream(e,r.aggregateId)}let a=o.log.entries.v,d=this._freezeEventPayload?gn(t):t,u={type:e,payload:d,timestampNs:re(),seq:++this._seq,...r?.aggregateId!==void 0?{aggregateId:r.aggregateId}:{},...s!==void 0?{aggregateVersion:s}:{},...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 o.log.append(u),i&&i.log.append(u),u}command(e,t){if(this._commandRegs.has(e))throw new Dt("command",e);let r=typeof t=="function"?{handler:t}:t,o=Y(void 0,{name:e,describeKind:"state",meta:{...dt("command",{command_name:e}),error:null},guard:xs});if(this.add(o,{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 s of r.emits)this._eventLogs.has(s)||this.event(s);return o}dispatch(e,t,r){let o=this._commandRegs.get(e);if(!o)throw new It(e);if(r?.aggregateId!==void 0&&r.expectedAggregateVersion!==void 0&&o.emits!==void 0){let p=0;for(let h of o.emits){let l=this._aggregateVersions.get(`${h}::${r.aggregateId}`);l!==void 0&&l>p&&(p=l)}if(p!==r.expectedAggregateVersion)throw new Lt(r.aggregateId,r.expectedAggregateVersion,p)}let s=this.resolve(e),i=this._freezeCommandPayload?gn(t):t,a=[],d=re(),u=0,c,f=!1;try{ze(()=>{u=this._bumpDispatchSeq(),s.emit(i,{internal:!0});try{o.handler(i,{emit:(p,h)=>{if(o.emits!==void 0&&!o.emits.includes(p))throw new Gt(e,p,o.emits);a.push(p),this._appendEvent(p,h,{...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})}:{},...o.handlerVersion!==void 0?{handlerVersion:o.handlerVersion}:{}})}}),s.meta.error.emit(null,{internal:!0}),this.dispatches.append({commandName:e,payload:i,status:"success",emittedEvents:[...a],t_ns:d,seq:u,...o.handlerVersion!==void 0?{handlerVersion:o.handlerVersion}:{}})}catch(p){throw c=p,f=!0,p}})}catch(p){if(f){s.meta.error.emit(c,{internal:!0});let h=c instanceof Error?c.name:typeof c,l=c instanceof at?c:new at(e,c);this.dispatches.append({commandName:e,payload:i,status:"failed",error:l,errorType:h,emittedEvents:[...a],t_ns:d,seq:u,...o.handlerVersion!==void 0?{handlerVersion:o.handlerVersion}:{}})}throw f?c:p}}projection(e){let{name:t,events:r,reducer:o,initial:s}=e,i=e.mode??"scan",a=e.freezeInputs??!0,d=e.snapshot,u=r.map(E=>(this._eventLogs.has(E)||this.event(E),this._eventLogs.get(E).node));function c(E){E.sort((T,N)=>T.timestampNs-N.timestampNs||T.seq-N.seq||(T.aggregateId??"").localeCompare(N.aggregateId??""))}function f(E){let T=[];for(let N of E)T.push(...N);return c(T),T}let p=u.map(E=>E.cache??[]),h=f(p),l=a?Object.freeze(h):h,y=0,m=s;i==="scan"&&h.length>0&&(m=o(s,l),y=h.length);let x=i==="replay"?o(s,l):m,_=d?.saveDebounceMs??1e3,v=d?.saveEvery??1e3,b,O=0;function R(E){if(d?.save){if(O+=1,O>=v){O=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,O=0;let T=d.save(E);T instanceof Promise&&T.catch(()=>{})},_)}}let g=Q(u,E=>{let T=f(E),N;if(i==="replay"){let S=a?Object.freeze(T):T;N=o(s,S)}else{let S=T.slice(y);y=T.length;let A=a?Object.freeze(S):S;N=o(m,A),m=N}return R(N),N},{name:t,describeKind:"derived",meta:dt("projection",{projection_name:t,source_events:r}),guard:Ts,initial:x});return this.add(g,{name:t}),this._keepaliveDisposers.push(de(g)),this._keepaliveDisposers.push(()=>{b!==void 0&&(clearTimeout(b),b=void 0)}),this._projections.add(t),{node:g,rebuild:async E=>{try{let T=E?.pageSize??1e3,N=E?.fromTier??this._attachedEventTiers[0]?.[0],S=f(u.map(G=>G.cache??[])).length,A=s;if(d?.load){let G=await d.load();G!==void 0&&(A=G)}if(!N||!N.loadEntries){let G=f(u.map(q=>q.cache??[])),I=a?Object.freeze(G):G;A=o(A,I)}else{let G=new Set(r),I,q=!1;for(;!q;){let Se=await N.loadEntries({cursor:I,pageSize:T}),Ne=[...Se.entries].filter(We=>G.has(We.type));c(Ne);let Be=a?Object.freeze(Ne):Ne;A=o(A,Be),I=Se.cursor,q=!I||Se.entries.length===0}}if(i==="scan"){let G=f(u.map(q=>q.cache??[])),I=G.slice(S);if(I.length>0){let q=a?Object.freeze(I):I;A=o(A,q)}m=A,y=G.length}return g.emit(A,{internal:!0}),A}catch(T){throw new ut(t,T)}},reset:async()=>{try{let E=s;if(d?.load){let A=await d.load();A!==void 0&&(E=A)}let T=f(u.map(A=>A.cache??[])),N=a?Object.freeze(T):T,S=o(E,N);return i==="scan"&&(m=S,y=T.length),g.emit(S,{internal:!0}),S}catch(E){throw new ut(t,E)}}}}saga(e,t,r,o={}){let s=t.map(h=>(this._eventLogs.has(h)||this.event(h),this._eventLogs.get(h).node)),i=Kr(this,`${e}_cursor`,t,0),a=Pt({name:`${e}_invocations`,retainedLimit:this._retainedLimit,graph:this}),d=o.aggregateId,u=o.errorPolicy??"advance",c=new Map;for(let h of t){let l=i[h];c.set(h,l.cache??0);let y=l.subscribe(m=>{for(let x of m)x[0]===M&&c.set(h,x[1])});this._keepaliveDisposers.push(y)}let f={},p=le(s,(h,l)=>{let y=f.n.meta.error;for(let m=0;m<h.length;m++){let x=h[m];if(x==null||x.length===0)continue;let _=x.at(-1);if(!_)continue;let v=t[m],b=i[v],O=c.get(v)??0;if(_.length>O){let R=_.slice(O),g=O;for(let w of R){let k=w;if(d!==void 0&&k.aggregateId!==d){g+=1;continue}try{r(k),y.emit(null,{internal:!0}),a.append({eventType:v,status:"success",aggregateId:k.aggregateId,event:k,t_ns:re(),...o.handlerVersion!==void 0?{handlerVersion:o.handlerVersion}:{}}),g+=1}catch(E){if(y.emit(E,{internal:!0}),a.append({eventType:v,status:"failed",error:E,errorType:E instanceof Error?E.name:typeof E,aggregateId:k.aggregateId,event:k,t_ns:re(),...o.handlerVersion!==void 0?{handlerVersion:o.handlerVersion}:{}}),u==="hold")break;g+=1}}b.emit(g)}}},{name:e,describeKind:"effect",meta:{...dt("saga",{saga_name:e,source_events:t}),error:null}});return f.n=p,this.add(p,{name:e}),this._keepaliveDisposers.push(de(p)),this._sagas.add(e),{node:p,invocations:a,audit:a,cursors:i}}};function Jr(n,e){let t=new mn(n,e),{factory:r,factoryArgs:o,...s}=e??{};return t.tagFactory("cqrs",on(s)),t}var bn=class{constructor(e){this.graph=e}onModuleDestroy(){this.graph.destroy()}},vn=class{graph=new ie("request");onModuleDestroy(){this.graph.destroy()}},Qr,yn;Qr=[(0,ct.Module)({})];var ge=class ge{static forRoot(e){let t=e??{},r=t.name??"root",o=[{provide:ne,useFactory:()=>{let s=new ie(r);return t.build&&t.build(s),t.snapshot&&s.restore(t.snapshot),s}},{provide:Symbol.for("graphrefly:root-lifecycle"),useFactory:s=>new bn(s),inject:[ne]},{provide:Re,useFactory:(s,i)=>new Re(s,i),inject:[ne,Xr.ModuleRef]}];if(t.nodes)for(let s of t.nodes)o.push({provide:ue(s),useFactory:i=>i.resolve(s),inject:[ne]});return t.requestScope&&o.push({provide:Symbol.for("graphrefly:request-lifecycle"),useFactory:()=>new vn,scope:ct.Scope.REQUEST},{provide:be,useFactory:s=>s.graph,inject:[Symbol.for("graphrefly:request-lifecycle")],scope:ct.Scope.REQUEST}),{module:ge,global:!0,providers:o,exports:[ne,...(t.nodes??[]).map(ue),...t.requestScope?[be]:[]]}}static forFeature(e){let t=[{provide:U(e.name),useFactory:r=>{let o=new ie(e.name);return e.build&&e.build(o),e.snapshot&&o.restore(e.snapshot),r.mount(e.name,o),o},inject:[ne]}];if(e.nodes)for(let r of e.nodes)t.push({provide:ue(`${e.name}::${r}`),useFactory:o=>o.resolve(r),inject:[U(e.name)]});return{module:ge,providers:t,exports:[U(e.name),...(e.nodes??[]).map(r=>ue(`${e.name}::${r}`))]}}static forCqrs(e){let t=[{provide:U(e.name),useFactory:r=>{let o=Jr(e.name,e.cqrs);return e.eventStorage&&o.attachEventStorage(e.eventStorage),e.build&&e.build(o),r.mount(e.name,o),o},inject:[ne]}];if(e.nodes)for(let r of e.nodes)t.push({provide:ue(`${e.name}::${r}`),useFactory:o=>o.resolve(r),inject:[U(e.name)]});return{module:ge,providers:t,exports:[U(e.name),...(e.nodes??[]).map(r=>ue(`${e.name}::${r}`))]}}};yn=Rn(null),ge=Nn(yn,0,"GraphReflyModule",Qr,ge),Sn(yn,1,ge);var $t=ge;0&&(module.exports={ACTOR_KEY,COMMAND_HANDLERS,CQRS_EVENT_HANDLERS,CRON_HANDLERS,CommandHandler,EVENT_HANDLERS,EventHandler,GRAPHREFLY_REQUEST_GRAPH,GRAPHREFLY_ROOT_GRAPH,GraphCron,GraphInterval,GraphReflyEventExplorer,GraphReflyGuard,GraphReflyGuardImpl,GraphReflyModule,INTERVAL_HANDLERS,InjectCqrsGraph,InjectGraph,InjectNode,ObserveGateway,OnGraphEvent,QUERY_HANDLERS,QueryHandler,SAGA_HANDLERS,SagaHandler,fromHeader,fromJwtPayload,getActor,getGraphToken,getNodeToken,observeSSE,observeSubscription,toObservable});
|
|
9
|
+
`,t}function ds(r){return JSON.parse(r)}function us(r,e){try{r.send(JSON.stringify(e))}catch{}}function Zt(r,e){try{r(e)}catch{}}Ze();var Et="graphReflyActor";function Xt(r){return e=>{let n=e.switchToHttp().getRequest()?.user;if(n!=null)return r?r(n):n}}function cr(r="x-graphrefly-actor"){return e=>{let n=e.switchToHttp().getRequest()?.headers?.[r.toLowerCase()];if(!(typeof n!="string"||n.length===0))try{return JSON.parse(n)}catch{return}}}function lr(r){let e=r?.[Et];return e!=null?ve(e):fe}var rt=class{constructor(e){this.extractor=e}canActivate(e){let t=ve(this.extractor(e)),n=e.switchToHttp().getRequest();return n!=null&&(n[Et]=t),!0}};function fr(r){return new rt(r??Xt())}var ct=require("@nestjs/common"),$r=require("@nestjs/core");Ze();tt();Fe();Te();ae();rn();Oe();Be();Fe();function sn(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(!sn(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)||!sn(r[o],e[o]))return!1;return!0}function hr(r,e){return`${r}\0${e}`}function on(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 E=r.nodes[g]?.meta,v=e.nodes[g]?.meta;E==null&&v==null||sn(E??{},v??{})||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(hr(g.from,g.to),g);let f=new Map;for(let g of e.edges)f.set(hr(g.from,g.to),g);let p=[];for(let[g,E]of f)c.has(g)||p.push(E);p.sort((g,E)=>g.from<E.from?-1:g.from>E.from?1:g.to<E.to?-1:g.to>E.to?1:0);for(let g of p)t.push({type:"edge-added",from:g.from,to:g.to});let h=[];for(let[g,E]of c)f.has(g)||h.push(E);h.sort((g,E)=>g.from<E.from?-1:g.from>E.from?1:g.to<E.to?-1:g.to>E.to?1:0);for(let g of h)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 y=[];for(let g of n)s.has(g)||y.push(g);y.sort();for(let g of y)t.push({type:"subgraph-unmounted",path:g});return{events:t,flushedAt_ns:ue()}}_t();gr();mr();jt();function yr(r,e,t,n={}){let s=e in r.nodes,o=t in r.nodes;if(!s)return kt(e,t,"no-such-from");if(!o)return kt(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=fs(r,e,n);if(u!=null)return u}let d=Nt(e,r.nodes[e],0,n);return Rt(e,t,[d])}if(i===0)return kt(e,t,"no-path");let a=br(r,e,t,i);return a.found?Rt(e,t,vr(r,a.pathOrder,n)):kt(e,t,a.truncated?"max-depth-exceeded":"no-path")}function br(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 f=o[a++];if(f.path===e)break;if(n!=null&&f.depth>=n){let y=r.nodes[f.path];y?.deps&&y.deps.length>0&&(d=!0);continue}let p=r.nodes[f.path];if(p==null)continue;let h=p.deps??[],l=new Map;for(let y=0;y<h.length;y++){let g=h[y];if(!g)continue;let E=l.get(g);E==null&&(E=[],l.set(g,E)),E.push(y)}for(let[y,g]of l)i.has(y)||(i.add(y),s.set(y,{from:f.path,depIndices:g}),o.push({path:y,depth:f.depth+1}))}if(!s.has(e))return{found:!1,pathOrder:[],truncated:d};let u=[{path:e}],c=e;for(;c!==t;){let f=s.get(c);if(f==null)return{found:!1,pathOrder:[],truncated:!1};u[u.length-1].depIndices=f.depIndices,u.push({path:f.from}),c=f.from}return{found:!0,pathOrder:u,truncated:!1}}function fs(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=Nt(e,n,0,t);a.dep_index=o[0];let d=Nt(e,n,1,t);return Rt(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=br(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:Rt(e,e,vr(r,i.pathOrder,t))}function vr(r,e,t){return e.map((n,s)=>{let o=r.nodes[n.path],i=Nt(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 Nt(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 Rt(r,e,t){return _r(r,e,!0,"ok",t)}function kt(r,e,t){return _r(r,e,!1,t,[])}function _r(r,e,t,n,s){let o=ps(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 ps(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: ${hs(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(`
|
|
10
|
+
`)}function hs(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)}}Oe();var q={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},gs=Symbol.for("sizeof");function wr(r){let e=new WeakSet,t=new WeakSet,n=[r],s=0;for(;n.length>0;){let o=n.pop();s+=ms(o,e,t,n)}return s}function ms(r,e,t,n){if(r==null)return 0;switch(typeof r){case"number":return q.number;case"boolean":return q.boolean;case"string":return q.string+r.length*2;case"bigint":return q.bigint+ys(r);case"symbol":return q.symbol;case"function":return e.has(r)?0:(e.add(r),q.function);case"undefined":return 0}let o=r;if(e.has(o))return 0;e.add(o);let i=o[gs];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 q.date;if(o instanceof RegExp)return q.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 q.error+u+c}if(typeof URL<"u"&&o instanceof URL)return q.url+o.href.length*2;if(typeof Promise<"u"&&o instanceof Promise)return q.promise;if(o instanceof WeakMap)return q.weakmap;if(o instanceof WeakSet)return q.weakset;if(o instanceof Map){let u=q.map;for(let[c,f]of o)u+=q.mapEntry,n.push(c),n.push(f);return u}if(o instanceof Set){let u=q.set;for(let c of o)u+=q.setEntry,n.push(c);return u}if(Array.isArray(o)){let u=q.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=q.object,d=Object.keys(o);for(let u of d){a+=q.string+u.length*2;try{n.push(o[u])}catch{}}return a}function ys(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 Tr(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[p,h]of s)i.set(p,h);let a=[];for(let[p,h]of Object.entries(n.nodes)){let l=i.get(p),y=l instanceof H?l:null,g=y?wr(y.cache):0,E=y?y._sinkCount:0,v=h.deps?.length??0,_=h.type==="effect"&&E===0,b=E===0?h.type==="effect"?"orphan-effect":h.type==="derived"?"idle-derived":h.type==="producer"?"idle-producer":null:null;a.push({path:p,type:h.type,status:h.status??"unknown",valueSizeBytes:g,subscriberCount:E,depCount:v,isOrphanEffect:_,orphanKind:b})}let d=a.reduce((p,h)=>p+h.valueSizeBytes,0),u=(p,h)=>[...a].sort(h??((l,y)=>y[p]-l[p])).slice(0,t),c=a.filter(p=>p.orphanKind!=null),f=a.filter(p=>p.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:f}}var L="::",oe="__meta__",Ne=1;function Er(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 Rr(r){return r!=null&&typeof r=="object"&&"cache"in r&&typeof r.subscribe=="function"&&typeof r.down=="function"}function bs(r){if(r!=null)return Rr(r)?r.cache:r}function Re(r){return r!=null&&typeof r=="object"&&"cache"in r&&typeof r.subscribe=="function"&&typeof r.down=="function"}function pe(r){return Re(r)?r.cache??"":r}function Or(r){return Re(r)?r.cache??0:r}function xr(r){return Re(r)?r.cache??!1:r}function vs(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(`
|
|
11
|
+
`)}function kr(r){if(r.version!==Ne)throw new Error(`unsupported snapshot version ${String(r.version)} (expected ${Ne})`);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 _s(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 p=o;if(s.length!==p.length)return!1;for(let h=0;h<s.length;h++)if(!n(s[h],p[h]))return!1;return!0}if(s instanceof Map){let p=o;if(s.size!==p.size)return!1;for(let[h,l]of s)if(!p.has(h)||!n(l,p.get(h)))return!1;return!0}if(s instanceof Set){let p=o;if(s.size!==p.size)return!1;for(let h of s){let l=!1;for(let y of p)if(n(h,y)){l=!0;break}if(!l)return!1}return!0}if(ArrayBuffer.isView(s)){let p=s,h=o;if(p.length!==h.length)return!1;for(let l=0;l<p.length;l++)if(p[l]!==h[l])return!1;return!0}let u=Object.keys(s),c=Object.keys(o);if(u.length!==c.length)return!1;let f=new Set(c);for(let p of u)if(!f.has(p)||!n(s[p],o[p]))return!1;return!0};return n(r,e)}function ws(r){return r.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function St(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+=ws(n)}return e+="$",new RegExp(e)}var Ts={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"},Es={data:"",dirty:"",resolved:"",invalidate:"",pause:"",resume:"",complete:"",error:"",teardown:"",derived:"",path:"",reset:""};function an(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 Os(r){return r==="none"?Es:r==="ansi"||r==null?Ts:{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 Nr(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 xs(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 dn(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===oe)throw new Error(`Graph "${e}": ${t} name "${oe}" is reserved for meta companion paths`);xs(r,e,t)}function ks(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 Ns(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 Sr(r){for(let e of r._mounts.values())Sr(e);for(let e of r._nodes.values())try{e.down([[$]],{internal:!0})}catch{}}var ie=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===oe)throw new Error(`Graph name "${oe}" is reserved for meta companion paths`);this.name=e,this.opts=Object.freeze({...t??{}}),this.config=t?.config??Ee,this._traceRing=new st(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=xe(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(dn(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:ue()})),e}setVersioning(e){if(e!=null)for(let t of this._nodes.values())t instanceof H&&t._applyVersioning(e)}remove(e){dn(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}${oe}${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,Sr(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([[$]],{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=St(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([[M,t]],{actor:n?.actor,internal:s,delivery:"write"})}setAll(e,t){let n=Symbol.iterator in e?e:Object.entries(e);ze(()=>{for(let[s,o]of n)this.set(s,o,t)})}invalidate(e,t){let n=t?.internal===!0;this.node(e).down([[ee]],{actor:t?.actor,internal:n,delivery:"write"})}error(e,t,n){let s=n?.internal===!0;this.node(e).down([[D,t]],{actor:n?.actor,internal:s,delivery:"write"})}complete(e,t){let n=t?.internal===!0;this.node(e).down([[I]],{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 H)for(let c of u._deps){let f=n.get(c.node);f!=null&&a.push([f,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 H)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(dn(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=ks(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]===oe)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]!==oe)throw new Error(`Graph "${this.name}": expected ${oe} segment in meta path "${n}"`);if(o+1>=i.length)throw new Error(`Graph "${this.name}": meta path requires a key after ${oe} 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=Ns(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 se)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 se)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=bs(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=Ot(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()),k=0;for(;b.length>0;){let m=b.shift();if(m instanceof H)for(let x of m._deps){let N=x.node;if(d.has(N))continue;let O=N.name??"",T=O;if(!T||w.has(T))if(O){let R=2;for(;w.has(`${O}#${R}`);)R++;T=`${O}#${R}`}else for(T=`__internal__/${k++}`;w.has(T);)T=`__internal__/${k++}`;d.set(N,T),w.add(T),u.push([T,N]),b.push(N)}}}let c=[...a,...u],f={};for(let[b,w]of c){if(t!=null&&!w.allowsObserve(t))continue;let k=nn(w,i,o),m=w instanceof H?w._deps.map(T=>d.get(T.node)??T.node.name??""):[],{name:x,...N}=k,O={...N,deps:m};if(!o){let T=this._annotations.get(b);T!=null&&(O.annotation=T)}if(n!=null)if(typeof n=="function"){let T=n;if(!(T.length>=2?T(b,O):T(O)))continue}else{let T=!0;for(let[R,C]of Object.entries(n)){let S=R==="deps_includes"?"depsIncludes":R==="meta_has"?"metaHas":R;if(S==="depsIncludes"){if(!O.deps.includes(String(C))){T=!1;break}continue}if(S==="metaHas"){if(!Object.hasOwn(O.meta??{},String(C))){T=!1;break}continue}if(O[S]!==C){T=!1;break}}if(!T)continue}f[b]=O}let p=new Set(Object.keys(f)),h=[];for(let[b,w]of c)if(w instanceof H)for(let k of w._deps){let m=d.get(k.node);m!=null&&h.push([m,b])}h.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=h.map(([b,w])=>({from:b,to:w}));(t!=null||n!=null)&&(l=l.filter(b=>p.has(b.from)&&p.has(b.to)));let y=this._collectSubgraphs(""),g=t!=null||n!=null?y.filter(b=>{let w=`${b}${L}`;return[...p].some(k=>k===b||k.startsWith(w))}):y,E=this,v=e;return{name:this.name,nodes:f,edges:l,subgraphs:g,...this._factory!==void 0?{factory:this._factory}:{},...this._factoryArgs!==void 0?{factoryArgs:this._factoryArgs}:{},expand(b){let w={...v};return Array.isArray(b)?(w.fields=b,w.detail=void 0):(w.detail=b,w.fields=void 0),E.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 Tr(this,e)}reachable(e,t,n={}){return n.withDetail===!0?un(this.describe(),e,t,{...n,withDetail:!0}):un(this.describe(),e,t,n)}explain(e,t,n){return n?.reactive===!0?this._explainReactive(e,t,n):this._explainStatic(pe(e),pe(t),{...n?.maxDepth!==void 0?{maxDepth:Or(n.maxDepth)}:{},...n?.findCycle!==void 0?{findCycle:xr(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 yr(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,Ve(()=>{a=!1,!d&&(s+=1,o.emit(s))}))},c=i.onEvent(v=>{let _=v.type;_!=="data"&&_!=="error"&&_!=="complete"&&_!=="teardown"||u()}),f=[],p=new WeakSet,h=v=>{if(p.has(v)||d)return;p.add(v);let _=v.topology.subscribe(b=>{for(let w of b){if(w[0]!==M)continue;let k=w[1];if(u(),k.kind==="added"&&k.nodeKind==="mount"){let m=v._mounts.get(k.name);m!=null&&h(m)}}});f.push(_);for(let b of v._mounts.keys()){let w=v._mounts.get(b);w!=null&&h(w)}};h(this);let l,y=e.actor;Rr(y)&&(l=y.subscribe(v=>{let _=!1,b=!1;for(let w of v){let k=w[0];k===M?_=!0:(k===I||k===D||k===$)&&(b=!0)}_&&u(),b&&(l?.(),l=void 0,u())}));let g;try{g=Q([o],()=>this.describe(t),{name:n,describeKind:"derived",meta:{domain:"audit",kind:"describe"},equals:(v,_)=>v===_})}catch(v){c(),l?.();for(let _ of f)_();throw i.dispose(),v}let E=le(g);return{node:g,dispose(){d=!0,c(),l?.();for(let v of f)v();f.length=0,i.dispose(),E()}}}_describeReactiveDiff(e){let t={...e,reactive:!1},n=e.reactiveName??"describe-diff",s={name:this.name,nodes:{},edges:[],subgraphs:[]},o=this.describe(t),i=on(s,o),a=K(i,{name:n,meta:{domain:"audit",kind:"describe-diff"},equals:(p,h)=>p===h}),d=this._describeReactive({...e,reactiveName:void 0}),u=!1,c=d.node.subscribe(p=>{if(!u)for(let h of p){if(h[0]!==M)continue;let l=h[1],y=on(o,l);o=l,y.events.length!==0&&a.emit(y)}}),f=le(a);return{node:a,dispose(){u=!0,c(),d.dispose(),a.down([[$,"describe-diff disposed"]]),f()}}}_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,Ve(()=>{a=!1,!d&&(s+=1,o.emit(s))}))},c=i.onEvent(v=>{let _=v.type;_!=="data"&&_!=="error"&&_!=="complete"&&_!=="teardown"||u()}),f=[];e!=null&&Re(e)&&f.push(e),t!=null&&Re(t)&&f.push(t),n?.maxDepth!=null&&Re(n.maxDepth)&&f.push(n.maxDepth),n?.findCycle!=null&&Re(n.findCycle)&&f.push(n.findCycle);let p=()=>{for(let v of f)if(v.cache===void 0)return!1;return!0},h=()=>{let v=pe(e),_=pe(t);return{from:v,to:_,found:!1,reason:"pending",steps:[],text:"(awaiting reactive args)",toJSON:()=>({from:v,to:_,found:!1,reason:"pending",steps:[]})}},l;try{l=Q([o],()=>{if(!p())return h();let v=pe(e),_=pe(t),b={...n?.maxDepth!==void 0?{maxDepth:Or(n.maxDepth)}:{},...n?.findCycle!==void 0?{findCycle:xr(n.findCycle)}:{}};return this._explainStatic(v,_,b)},{name:n?.name??"explain",describeKind:"derived",meta:{domain:"audit",kind:"explain_path",from:pe(e),to:pe(t)},equals:(v,_)=>v.found===_.found&&v.reason===_.reason&&v.steps.length===_.steps.length&&Rs(v.steps,_.steps)})}catch(v){throw c(),i.dispose(),v}let y=le(l),g=[],E=v=>{let _;return _=v.subscribe(b=>{let w=!1,k=!1;for(let m of b){let x=m[0];x===M?w=!0:(x===I||x===D||x===$)&&(k=!0)}(w||k)&&u(),k&&_&&(_(),_=void 0)}),()=>{_&&(_(),_=void 0)}};for(let v of f)g.push(E(v));return{node:l,dispose(){d=!0,c();for(let v of g)v?.();g.length=0,i.dispose(),y()}}}_pathsMatching(e){let t=St(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}${oe}${L}${s}`;n.push([i,o]),this._appendMetaObserveTargets(i,o,n)}}observe(e,t){let n=typeof e=="string",o=Nr(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,f=this.resolve(c);if(a!=null&&!f.allowsObserve(a))throw new se({actor:a,action:"observe",nodeName:c});return i?this._buildStructuredObserver([[c,f]],o,"one"):{subscribe(p){return f.subscribe(p)},up(p){try{f.up?.(p)}catch(h){if(h instanceof se)return;throw h}}}}let d=[];this._collectObserveTargets("",d),d.sort((c,f)=>c[0]<f[0]?-1:c[0]>f[0]?1:0);let u=a==null?d:d.filter(([,c])=>c.allowsObserve(a));return i?this._buildStructuredObserver(u,o,"all"):{subscribe:c=>{let f=u.map(([p,h])=>h.subscribe(l=>{c(p,l)}));return()=>{for(let p of f)p()}},up:(c,f)=>{try{this.resolve(c).up?.(f)}catch(p){if(p instanceof se)return;throw p}}}}_observeReactive(e,t){let n=t.tiers,s=n!=null?new Set(n):null,o=t.reactiveName??"observe";return xe(i=>{let a=[],d=!1,u=!1,c=()=>{if(a.length===0||u)return;let y={events:a.slice(),flushedAt_ns:ue()};a.length=0,i.emit(y)},f={...t,reactive:!1,structured:!0,timeline:!0},p=e!=null?this.observe(e,f):this.observe(f),h=y=>{u||(a.push(y),!d&&(d=!0,Ve(()=>{d=!1,c()})))};for(let y of p.events)h(y);let l=p.onEvent(h);return()=>{u=!0,l(),p.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,f)=>c[0]<f[0]?-1:c[0]>f[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,f=c!=null&&c>0?new st(c):null,p=[],h=new Set,l=t.tiers!=null?new Set(t.tiers):null,y={},g=new Set,E=0,v=0,_=0,b=0,w=0,k=0,m=!1,x=!1,N=0,O=new Map,T=new Map,R=new Map,C=A=>{if(!(l!=null&&!l.has(A.type))){f?f.push(A):p.push(A);for(let P of h)P(A)}},S=A=>l==null||l.has(A),F=()=>s?{timestamp_ns:ue(),in_batch:mt(),batch_id:N}:{},V=(A,P)=>{if(!(!u||!(A instanceof H)))return A._setInspectorHook(Z=>{if(Z.kind==="dep_message")O.set(A,Z.depIndex);else if(Z.kind==="run"){let Ke=Z.batchData.map((G,j)=>G!=null&&G.length>0?G.at(-1):Z.prevData[j]);T.set(A,Ke);let X=Z.batchData.map(G=>G!=null?[...G]:void 0);R.set(A,X),i&&C({type:"derived",path:P,dep_values:Ke,dep_batches:X,...F()})}})},Y=A=>{let P=O.get(A),Z=T.get(A);if(!o||Z==null)return{};let X=(P!=null&&P>=0&&A instanceof H?A._deps[P]:void 0)?.node,G=X?.v,j=R.get(A);return{trigger_dep_index:P,trigger_dep_name:X?.name,...G!=null?{trigger_version:{id:G.id,version:G.version}}:{},dep_values:[...Z],...j!=null?{dep_batches:j}:{}}},Se=[],Ae=[];for(let[A,P]of e){let Z=V(P,A);Z&&Se.push(Z),Ae.push(P.subscribe(Ke=>{N++;for(let X of Ke){let G=X[0],j=F();if(G===M){y[A]=X[1];let Lt=P instanceof H?P.lastMutation?.actor??fe:fe;C({type:"data",path:A,data:X[1],actor:Lt,...j,...Y(P)})}else if(a)G===B?S("dirty")&&E++:G===W?S("resolved")&&v++:G===ee?S("invalidate")&&_++:G===J?S("pause")&&b++:G===te?S("resume")&&w++:G===$?S("teardown")&&k++:G===I&&!g.has(A)?S("complete")&&(m=!0):G===D&&S("error")&&(x=!0,g.add(A));else if(G===B)S("dirty")&&E++,C({type:"dirty",path:A,...j});else if(G===W)S("resolved")&&v++,C({type:"resolved",path:A,...j,...Y(P)});else if(G===ee)S("invalidate")&&_++,C({type:"invalidate",path:A,...j});else if(G===J)S("pause")&&b++,C({type:"pause",path:A,lockId:X[1],...j});else if(G===te)S("resume")&&w++,C({type:"resume",path:A,lockId:X[1],...j});else if(G===I)S("complete")&&!g.has(A)&&(m=!0),C({type:"complete",path:A,...j});else if(G===D){S("error")&&(x=!0,g.add(A));let Lt=P instanceof H?P.lastMutation?.actor??fe:fe;C({type:"error",path:A,data:X[1],actor:Lt,...j})}else G===$&&(S("teardown")&&k++,C({type:"teardown",path:A,...j}))}}))}let We=!1,Ue=()=>{if(!We){We=!0;for(let A of Ae)A();for(let A of Se)A();for(let A of lt)A({value:void 0,done:!0});lt.length=0}},Pt=[],lt=[];h.add(A=>{let P=lt.shift();P?P({value:A,done:!1}):Pt.push(A)});let mn={get values(){return y},get dirtyCount(){return E},get resolvedCount(){return v},get invalidateCount(){return _},get pauseCount(){return b},get resumeCount(){return w},get teardownCount(){return k},get events(){return f?f.toArray():[...p]},get anyCompletedCleanly(){return m},get anyErrored(){return x},get completedWithoutErrors(){return m&&!x},onEvent(A){return h.add(A),()=>h.delete(A)},dispose:Ue,expand(A){Ue();let P={...t};return typeof A=="string"?P.detail=A:Object.assign(P,A),n(Nr(P))},[Symbol.asyncIterator](){return{next(){return Pt.length>0?Promise.resolve({value:Pt.shift(),done:!1}):We?Promise.resolve({value:void 0,done:!0}):new Promise(A=>lt.push(A))},return(){return Ue(),Promise.resolve({value:void 0,done:!0})}}}};return t.format!=null&&this._attachFormatLogger(mn,t),mn}_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=Os(t.theme),u=n==="stage-log"?ue():0,c=l=>l==null?"":t.stageLabels?.[l]??l,f=(l,y)=>l.length>y?`${l.slice(0,y-1)}\u2026`:l,p=l=>l.type==="data"||l.type==="error"?f(an(l.data),120):"",h=l=>{if(n==="stage-log"){let m=(ue()-u)/1e9,x=c(l.path).padEnd(9);if(l.type==="data"){let N=p(l);return`[${m.toFixed(3)}s] ${x} \u2190${N?` ${N}`:""}`}if(l.type==="error"){let N=p(l);return`[${m.toFixed(3)}s] ${x} \u2717${N?` ${N}`:""}`}return l.type==="complete"?`[${m.toFixed(3)}s] ${x} \u25A0 complete`:`[${m.toFixed(3)}s] ${x} ${l.type}`}if(n==="json")try{return JSON.stringify(l)}catch{return JSON.stringify({type:l.type,path:l.path,data:"[unserializable]"})}let y=d[l.type]??"",g=l.path?`${d.path}${l.path}${d.reset} `:"",E=l.type==="data"||l.type==="error",v=l.type==="pause"||l.type==="resume",_=E?` ${an(l.data)}`:v?` ${an(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}`:"",k=l.in_batch?" [batch]":"";return`${g}${y}${l.type.toUpperCase()}${d.reset}${_}${w}${k}`};e.onEvent(l=>{a(l.type)&&s(h(l),l)})}addDisposer(e){return this._disposers.add(e),()=>{this._disposers.delete(e)}}destroy(){Er(this._disposers,this.name),this.signal([[$]],{internal:!0}),Er(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 qn(a,a.encode(i))}throw new Error(`snapshot: unknown format "${String(e.format)}"`)}static decode(e,t){let n=t?.config??Ee,{codec:s,codecVersion:o,payload:i}=Vn(e,n);return s.decode(i,o)}restore(e,t){if(kr(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=>St(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){kr(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 h of[...e.subgraphs].sort((l,y)=>{let g=l.split(L).length,E=y.split(L).length;return g!==E?g-E:l<y?-1:l>y?1:0})){let l=h.split(L),y=o;for(let g of l)y._mounts.has(g)||y.mount(g,new r(g)),y=y._mounts.get(g)}let i=s?Object.entries(s).map(([h,l])=>({re:St(h),factory:l})):[],a=h=>{for(let l of i)if(l.re.test(h))return l.factory},d=h=>{let l=h.split(L),y=l.pop();if(y==null||y.length===0)throw new Error(`invalid snapshot path "${h}"`);let g=o;for(let E of l){let v=g._mounts.get(E);if(!v)throw new Error(`unknown mount "${E}" in path "${h}"`);g=v}return[g,y]},u=Object.entries(e.nodes).filter(([h])=>!h.includes(`${L}${oe}${L}`)).sort((h,l)=>h[0]<l[0]?-1:h[0]>l[0]?1:0),c=new Map(u),f=new Map,p=!0;for(;c.size>0&&p;){p=!1;for(let[h,l]of[...c.entries()]){let y=l?.deps??[];if(!y.every(w=>f.has(w)))continue;let[g,E]=d(h),v={...l?.meta??{}},_=a(h),b;if(l?.type==="state")b=K(l.value,{meta:v});else{if(_==null)continue;b=_(E,{path:h,type:l.type,value:l.value,meta:v,deps:y,resolvedDeps:y.map(w=>f.get(w))})}g.add(b,{name:E}),f.set(h,b),c.delete(h),p=!0}}if(c.size>0){let h=[...c.keys()].sort().join(", ");throw new Error(`Graph.fromSnapshot could not reconstruct nodes without build callback: ${h}. 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 f=vs(c.nodes);if(u.lastSnapshot!=null&&f!==""&&f===u.lastFingerprint)return;let p=u.seq+1,h=re(),g=u.lastSnapshot==null||p%u.compactEvery===0?{name:this.name,mode:"full",snapshot:c,seq:p,timestamp_ns:h,format_version:Ne}:{name:this.name,mode:"diff",diff:Ar(u.lastSnapshot,c),seq:p,timestamp_ns:h,format_version:Ne};if(u.tier.filter&&!u.tier.filter(g))return;let E;try{E=u.tier.save(g)}catch(v){t.onError?.(v,u.tier);return}if(E&&typeof E.then=="function"){let b=(u.savePending??Promise.resolve()).then(()=>E,()=>E).then(()=>{u.disposed||(u.seq=p,u.lastSnapshot=c,u.lastFingerprint=f)},w=>{t.onError?.(w,u.tier)});u.savePending=b.finally(()=>{u.savePending===b&&(u.savePending=void 0)})}else u.seq=p,u.lastSnapshot=c,u.lastFingerprint=f},o=(u,c)=>{try{s(u,c)}catch(f){t.onError?.(f,u.tier)}},i=(u,c)=>{if(!c.some(l=>{let y=this.config.messageTier(l[0]);return y>=3&&y<5}))return;if(t.filter){let l=this.tryResolve(u);if(l==null)return;let y=nn(l,Ot("standard"));if(!t.filter(u,y))return}let p,h=()=>(p==null&&(p=this.snapshot()),p);for(let l of n)l.disposed||(l.debounceMs===0?o(l,h()):(l.timer==null&&(l.timer=new xt),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(f=>{let p=this.tryResolve(f);return p==null?()=>{}:p.subscribe(h=>i(f,h))});a=()=>{for(let f of c)f()}}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===Ne&&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===Ne&&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:ue(),...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(v=>!n.has(v)).sort(),i=[...n].filter(v=>!s.has(v)).sort(),a=[],d=[];for(let v of n){if(!s.has(v))continue;let _=e.nodes[v],b=t.nodes[v],w=_.v,k=b.v;w!=null&&k!=null&&w.id===k.id&&w.version!==k.version&&d.push({path:v,id:w.id,from:w.version,to:k.version});let m=w!=null&&k!=null&&w.id===k.id&&w.version===k.version;for(let x of["type","status","sentinel"]){let N=_[x],O=b[x];N!==O&&a.push({path:v,field:x,from:N,to:O})}if(!m)for(let x of["value","meta"]){let N=_[x],O=b[x];_s(N,O)||a.push({path:v,field:x,from:N,to:O})}}let u=v=>`${v.from} ${v.to}`,c=new Set(e.edges.map(u)),f=new Set(t.edges.map(u)),p=t.edges.filter(v=>!c.has(u(v))),h=e.edges.filter(v=>!f.has(u(v))),l=new Set(e.subgraphs),y=new Set(t.subgraphs),g=[...y].filter(v=>!l.has(v)).sort(),E=[...l].filter(v=>!y.has(v)).sort();return{nodesAdded:o,nodesRemoved:i,nodesChanged:a,versionChanges:d,edgesAdded:p,edgesRemoved:h,subgraphsAdded:g,subgraphsRemoved:E}}};function Ar(r,e){let t=ie.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 un(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[_,b]of Object.entries(r.nodes)){if(!_)continue;c.add(_);let w=b.deps??[];i.set(_,w);for(let k of w)k&&(c.add(k),a.has(k)||a.set(k,new Set),a.get(k).add(_))}for(let _ of r.edges){if(_==null||typeof _!="object")continue;let b=typeof _.from=="string"?_.from:"",w=typeof _.to=="string"?_.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 f=n.both===!0,p=_=>{if(f){let m=i.get(_)??[],x=d.get(_),N=a.get(_),O=u.get(_),T=[...m];return x&&T.push(...x),N&&T.push(...N),O&&T.push(...O),T}if(t==="upstream"){let m=i.get(_)??[],x=d.get(_);return x?[...m,...x]:m}let b=a.get(_),w=u.get(_),k=b?[...b]:[];return w&&k.push(...w),k},h=new Set([e]),l=new Map,y=[{path:e,depth:0}],g=0,E=!1;for(;g<y.length;){let _=y[g++];if(o!=null&&_.depth>=o){p(_.path).length>0&&(E=!0);continue}for(let b of p(_.path))!b||h.has(b)||(h.add(b),l.set(b,_.depth+1),y.push({path:b,depth:_.depth+1}))}let v=[...l.keys()].sort((_,b)=>_<b?-1:_>b?1:0);return n.withDetail?{paths:v,depths:l,truncated:E}:v}function Rs(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}tt();Fe();Te();Ze();Te();ae();rn();Oe();Be();Te();Be();tt();ae();Oe();Be();var cn=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 ot(r){return r.subscribe(()=>{})}var Ss=64;function it(r,e={}){let{name:t,maxSize:n,versioning:s,guard:o,backend:i}=e,a=i??new cn(r,n),d=K(a.toArray(),{name:t,describeKind:"state",equals:(m,x)=>m===x,...s!=null?{versioning:s}:{},...o!=null?{guard:o}:{}});function u(){let m=a.toArray();ze(()=>{d.down([[B]],{internal:!0}),d.down([[M,m]],{internal:!0})})}let c=new Map,f=new Map,p=new Map;function h(m,x){return`${m}:${x===void 0?"END":x}`}function l(m){if(m.size<Ss)return;let x=m.keys().next();if(x.done)return;let N=m.get(x.value);N!==void 0&&N.dispose(),m.delete(x.value)}function y(m){let x=a.version;try{return m()}finally{a.version!==x&&u()}}function g(m){if(!Number.isInteger(m)||m<0)throw new RangeError(`tail: n must be a non-negative integer (got ${m})`);let x=c.get(m);if(x!==void 0)return c.delete(m),c.set(m,x),x.node;l(c);let N=Q([d],([T])=>{let R=T;return m===0||R.length===0?[]:R.slice(Math.max(0,R.length-m))},{initial:a.tail(m),describeKind:"derived"}),O=ot(N);return c.set(m,{node:N,dispose:O}),N}function E(m,x){if(!Number.isInteger(m)||m<0)throw new RangeError(`slice: start must be a non-negative integer (got ${m})`);if(x!==void 0&&(!Number.isInteger(x)||x<0))throw new RangeError(`slice: stop must be a non-negative integer or undefined (got ${x})`);let N=h(m,x),O=f.get(N);if(O!==void 0)return f.delete(N),f.set(N,O),O.node;l(f);let T=Q([d],([C])=>{let S=C;return x===void 0?S.slice(m):S.slice(m,x)},{initial:a.slice(m,x),describeKind:"derived"}),R=ot(T);return f.set(N,{node:T,dispose:R}),T}function v(m){let x=p.get(m);if(x!==void 0)return x.node;let N=Q([d,m],([T,R])=>{let C=T,S=Math.max(0,Math.trunc(R??0));return C.slice(S)},{initial:[],describeKind:"derived"}),O=ot(N);return p.set(m,{node:N,dispose:O}),N}let _,b;function w(){_===void 0&&(_=ce([d],(m,x,N)=>{let O=m[0],R=O!=null&&O.length>0?O.at(-1):N.prevData[0];if(R==null||R.length===0){x.down([[W]]);return}x.emit(R[R.length-1])},{name:t!=null?`${t}::lastValue`:"lastValue",describeKind:"derived",initial:a.size===0?void 0:a.at(a.size-1)}),b=Q([d],([m])=>m.length>0,{name:t!=null?`${t}::hasLatest`:"hasLatest",describeKind:"derived",initial:a.size>0}),ot(_),ot(b))}let k={entries:d,get size(){return a.size},at(m){return a.at(m)},append(m){y(()=>a.append(m))},appendMany(m){m.length!==0&&y(()=>a.appendMany(m))},clear(){y(()=>a.clear())},trimHead(m){y(()=>a.trimHead(m))},withLatest(){return w(),d},get lastValue(){return w(),_},get hasLatest(){return w(),b},view(m){switch(m.kind){case"tail":return g(m.n);case"slice":return E(m.start,m.stop);case"fromCursor":return v(m.cursor)}},attach(m){let x=m.subscribe(N=>{for(let O of N)O[0]===M&&k.append(O[1])});return()=>x()},attachStorage(m){if(m.length===0)return()=>{};let x=new Map;for(let O of m)x.set(O,a.size);(async()=>{for(let O of m)if(typeof O.loadEntries=="function")try{let T=await Promise.resolve(O.loadEntries());T.entries.length>0&&a.size===0&&(a.restore(T.entries),x.set(O,T.entries.length),u());break}catch{}})();let N=d.subscribe(O=>{for(let T of O){if(T[0]!==M)continue;let R=T[1];for(let C of m){let S=x.get(C)??0;if(R.length<S){try{let V=C.appendEntries(R);V instanceof Promise&&V.catch(()=>{})}catch{}x.set(C,R.length);continue}if(R.length===S)continue;let F=R.slice(S);x.set(C,R.length);try{let V=C.appendEntries(F);V instanceof Promise&&V.catch(()=>{})}catch{}}}});return()=>N()},disposeAllViews(){for(let m of c.values())m.dispose();c.clear();for(let m of f.values())m.dispose();f.clear();for(let m of p.values())m.dispose();p.clear()},dispose(){for(let m of c.values())m.dispose();c.clear();for(let m of f.values())m.dispose();f.clear();for(let m of p.values())m.dispose();p.clear()}};return k}var As=je((r,e)=>{r("observe"),r("signal"),e("write")});function At(r){let e=it([],{name:r.name,maxSize:r.retainedLimit??1024,guard:r.guard??As,...r.versioning!=null?{versioning:r.versioning}:{}});return e.withLatest(),r.graph&&r.graph.add(e.entries,{name:r.name}),e}function Cr(r,e,t=0){let n=K(t,{name:e,describeKind:"state"});return r.add(n,{name:e}),n}function Mr(r,e,t,n=0){let s={},o=new ie(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 he=class extends Error{constructor(e,t){super(e,t),this.name=this.constructor.name}},Ct=class extends he{constructor(t,n){super(`Duplicate ${t} registration: "${n}"`);this.kind=t;this.registrationName=n}},Mt=class extends he{constructor(t,n,s){super(`Command "${t}" emitted undeclared event "${n}". Declared emits: [${s.join(", ")}]`);this.commandName=t;this.eventName=n;this.declaredEmits=s}},Dt=class extends he{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}},Gt=class extends he{constructor(t){super(`Unknown command: "${t}". Register with command() first.`);this.commandName=t}},at=class extends he{constructor(t,n){super(`Command handler "${t}" threw: ${n instanceof Error?n.message:String(n)}`,{cause:n});this.commandName=t}};var dt=class extends he{constructor(t,n){super(`Projection "${t}" rebuild failed: ${n instanceof Error?n.message:String(n)}`,{cause:n});this.projectionName=t}};Gr();_t();var Cs=je((r,e)=>{r("write"),r("signal"),e("observe")}),Ms=je((r,e)=>{r("observe"),r("signal"),e("write")}),Ir=je((r,e)=>{r("observe"),r("signal"),e("write")});function ut(r,e){return Dr("cqrs",r,e)}function ln(r){if(r===null||typeof r!="object"||Object.isFrozen(r))return r;for(let e of Object.keys(r))ln(r[e]);return Object.freeze(r)}var fn=class extends ie{_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=At({name:"dispatches",retainedLimit:this._retainedLimit,graph:this}),this.audit=this.dispatches,this.aggregateEvictions=At({name:"aggregateEvictions",retainedLimit:this._retainedLimit,graph:this}),this._dispatchSeqCursor=Cr(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:re()})}}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=it([],{name:e,versioning:0,maxSize:this._retainedLimit});s.withLatest();let o=s.entries,i=Q([o],([a])=>a,{name:e,describeKind:"state",meta:ut("event",{event_name:e}),guard:Ir,initial:o.cache});return this.add(i,{name:e}),this._keepaliveDisposers.push(le(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=it([],{name:i,versioning:0,maxSize:this._retainedLimit});a.withLatest();let d=a.entries,u=Q([d],([h])=>h,{name:i,describeKind:"state",meta:ut("event_aggregate",{event_name:e,aggregate_id:t}),guard:Ir,initial:d.cache}),c=i,f=0;for(;this.nameOf(this.resolveOptional(c)??u)===c&&(f+=1,c=`${i}_${f}`,this.resolveOptional(c)!==void 0););try{this.add(u,{name:c})}catch{}this._keepaliveDisposers.push(le(u));let p={log:a,node:u};return n.set(t,p),this._autoWireStreamStorage(`${e}::${t}`,a),this._enforceAggregateLru(),p}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?ln(t):t,u={type:e,payload:d,timestampNs:re(),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 Ct("command",e);let n=typeof t=="function"?{handler:t}:t,s=K(void 0,{name:e,describeKind:"state",meta:{...ut("command",{command_name:e}),error:null},guard:Cs});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 Gt(e);if(n?.aggregateId!==void 0&&n.expectedAggregateVersion!==void 0&&s.emits!==void 0){let p=0;for(let h of s.emits){let l=this._aggregateVersions.get(`${h}::${n.aggregateId}`);l!==void 0&&l>p&&(p=l)}if(p!==n.expectedAggregateVersion)throw new Dt(n.aggregateId,n.expectedAggregateVersion,p)}let o=this.resolve(e),i=this._freezeCommandPayload?ln(t):t,a=[],d=re(),u=0,c,f=!1;try{ze(()=>{u=this._bumpDispatchSeq(),o.emit(i,{internal:!0});try{s.handler(i,{emit:(p,h)=>{if(s.emits!==void 0&&!s.emits.includes(p))throw new Mt(e,p,s.emits);a.push(p),this._appendEvent(p,h,{...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(p){throw c=p,f=!0,p}})}catch(p){if(f){o.meta.error.emit(c,{internal:!0});let h=c instanceof Error?c.name:typeof c,l=c instanceof at?c:new at(e,c);this.dispatches.append({commandName:e,payload:i,outcome:"failure",error:l,errorType:h,emittedEvents:[...a],t_ns:d,seq:u,...s.handlerVersion!==void 0?{handlerVersion:s.handlerVersion}:{}})}throw f?c:p}}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(O=>(this._eventLogs.has(O)||this.event(O),this._eventLogs.get(O).node));function c(O){O.sort((T,R)=>T.timestampNs-R.timestampNs||T.seq-R.seq||(T.aggregateId??"").localeCompare(R.aggregateId??""))}function f(O){let T=[];for(let R of O)T.push(...R);return c(T),T}let p=u.map(O=>O.cache??[]),h=f(p),l=a?Object.freeze(h):h,y=0,g=o;i==="scan"&&h.length>0&&(g=s(o,l),y=h.length);let E=i==="replay"?s(o,l):g,v=d?.saveDebounceMs??1e3,_=d?.saveEvery??1e3,b,w=0;function k(O){if(d?.save){if(w+=1,w>=_){w=0,b!==void 0&&(clearTimeout(b),b=void 0);let T=d.save(O);T instanceof Promise&&T.catch(()=>{});return}b!==void 0&&clearTimeout(b),b=setTimeout(()=>{b=void 0,w=0;let T=d.save(O);T instanceof Promise&&T.catch(()=>{})},v)}}let m=Q(u,O=>{let T=f(O),R;if(i==="replay"){let C=a?Object.freeze(T):T;R=s(o,C)}else{let C=T.slice(y);y=T.length;let S=a?Object.freeze(C):C;R=s(g,S),g=R}return k(R),R},{name:t,describeKind:"derived",meta:ut("projection",{projection_name:t,source_events:n}),guard:Ms,initial:E});return this.add(m,{name:t}),this._keepaliveDisposers.push(le(m)),this._keepaliveDisposers.push(()=>{b!==void 0&&(clearTimeout(b),b=void 0)}),this._projections.add(t),{node:m,rebuild:async O=>{try{let T=O?.pageSize??1e3,R=O?.fromTier??this._attachedEventTiers[0]?.[0],C=f(u.map(F=>F.cache??[])).length,S=o;if(d?.load){let F=await d.load();F!==void 0&&(S=F)}if(!R||!R.loadEntries){let F=f(u.map(Y=>Y.cache??[])),V=a?Object.freeze(F):F;S=s(S,V)}else{let F=new Set(n),V,Y=!1;for(;!Y;){let Se=await R.loadEntries({cursor:V,pageSize:T}),Ae=[...Se.entries].filter(Ue=>F.has(Ue.type));c(Ae);let We=a?Object.freeze(Ae):Ae;S=s(S,We),V=Se.cursor,Y=!V||Se.entries.length===0}}if(i==="scan"){let F=f(u.map(Y=>Y.cache??[])),V=F.slice(C);if(V.length>0){let Y=a?Object.freeze(V):V;S=s(S,Y)}g=S,y=F.length}return m.emit(S,{internal:!0}),S}catch(T){throw new dt(t,T)}},reset:async()=>{try{let O=o;if(d?.load){let S=await d.load();S!==void 0&&(O=S)}let T=f(u.map(S=>S.cache??[])),R=a?Object.freeze(T):T,C=s(O,R);return i==="scan"&&(g=C,y=T.length),m.emit(C,{internal:!0}),C}catch(O){throw new dt(t,O)}}}}saga(e,t,n,s={}){let o=t.map(h=>(this._eventLogs.has(h)||this.event(h),this._eventLogs.get(h).node)),i=Mr(this,`${e}_cursor`,t,0),a=At({name:`${e}_invocations`,retainedLimit:this._retainedLimit,graph:this}),d=s.aggregateId,u=s.errorPolicy??"advance",c=new Map;for(let h of t){let l=i[h];c.set(h,l.cache??0);let y=l.subscribe(g=>{for(let E of g)E[0]===M&&c.set(h,E[1])});this._keepaliveDisposers.push(y)}let f={},p=ce(o,(h,l)=>{let y=f.n.meta.error;for(let g=0;g<h.length;g++){let E=h[g];if(E==null||E.length===0)continue;let v=E.at(-1);if(!v)continue;let _=t[g],b=i[_],w=c.get(_)??0;if(v.length>w){let k=v.slice(w),m=w;for(let x of k){let N=x;if(d!==void 0&&N.aggregateId!==d){m+=1;continue}try{n(N),y.emit(null,{internal:!0}),a.append({eventType:_,outcome:"success",aggregateId:N.aggregateId,event:N,t_ns:re(),...s.handlerVersion!==void 0?{handlerVersion:s.handlerVersion}:{}}),m+=1}catch(O){if(y.emit(O,{internal:!0}),a.append({eventType:_,outcome:"failure",error:O,errorType:O instanceof Error?O.name:typeof O,aggregateId:N.aggregateId,event:N,t_ns:re(),...s.handlerVersion!==void 0?{handlerVersion:s.handlerVersion}:{}}),u==="hold")break;m+=1}}b.emit(m)}}},{name:e,describeKind:"effect",meta:{...ut("saga",{saga_name:e,source_events:t}),error:null}});return f.n=p,this.add(p,{name:e}),this._keepaliveDisposers.push(le(p)),this._sagas.add(e),{node:p,invocations:a,audit:a,cursors:i}}};function Pr(r,e){let t=new fn(r,e),{factory:n,factoryArgs:s,...o}=e??{};return t.tagFactory("cqrs",tn(o)),t}var hn=class{constructor(e){this.graph=e}onModuleDestroy(){this.graph.destroy()}},gn=class{graph=new ie("request");onModuleDestroy(){this.graph.destroy()}},Lr,pn;Lr=[(0,ct.Module)({})];var ge=class ge{static forRoot(e){let t=e??{},n=t.name??"root",s=[{provide:ne,useFactory:()=>{let o=new ie(n);return t.build&&t.build(o),t.snapshot&&o.restore(t.snapshot),o}},{provide:Symbol.for("graphrefly:root-lifecycle"),useFactory:o=>new hn(o),inject:[ne]},{provide:ke,useFactory:(o,i)=>new ke(o,i),inject:[ne,$r.ModuleRef]}];if(t.nodes)for(let o of t.nodes)s.push({provide:de(o),useFactory:i=>i.resolve(o),inject:[ne]});return t.requestScope&&s.push({provide:Symbol.for("graphrefly:request-lifecycle"),useFactory:()=>new gn,scope:ct.Scope.REQUEST},{provide:be,useFactory:o=>o.graph,inject:[Symbol.for("graphrefly:request-lifecycle")],scope:ct.Scope.REQUEST}),{module:ge,global:!0,providers:s,exports:[ne,...(t.nodes??[]).map(de),...t.requestScope?[be]:[]]}}static forFeature(e){let t=[{provide:U(e.name),useFactory:n=>{let s=new ie(e.name);return e.build&&e.build(s),e.snapshot&&s.restore(e.snapshot),n.mount(e.name,s),s},inject:[ne]}];if(e.nodes)for(let n of e.nodes)t.push({provide:de(`${e.name}::${n}`),useFactory:s=>s.resolve(n),inject:[U(e.name)]});return{module:ge,providers:t,exports:[U(e.name),...(e.nodes??[]).map(n=>de(`${e.name}::${n}`))]}}static forCqrs(e){let t=[{provide:U(e.name),useFactory:n=>{let s=Pr(e.name,e.cqrs);return e.eventStorage&&s.attachEventStorage(e.eventStorage),e.build&&e.build(s),n.mount(e.name,s),s},inject:[ne]}];if(e.nodes)for(let n of e.nodes)t.push({provide:de(`${e.name}::${n}`),useFactory:s=>s.resolve(n),inject:[U(e.name)]});return{module:ge,providers:t,exports:[U(e.name),...(e.nodes??[]).map(n=>de(`${e.name}::${n}`))]}}};pn=Tn(null),ge=xn(pn,0,"GraphReflyModule",Lr,ge),On(pn,1,ge);var It=ge;0&&(module.exports={ACTOR_KEY,COMMAND_HANDLERS,CQRS_EVENT_HANDLERS,CRON_HANDLERS,CommandHandler,EVENT_HANDLERS,EventHandler,GRAPHREFLY_REQUEST_GRAPH,GRAPHREFLY_ROOT_GRAPH,GraphCron,GraphInterval,GraphReflyEventExplorer,GraphReflyGuard,GraphReflyGuardImpl,GraphReflyModule,INTERVAL_HANDLERS,InjectCqrsGraph,InjectGraph,InjectNode,ObserveGateway,OnGraphEvent,QUERY_HANDLERS,QueryHandler,SAGA_HANDLERS,SagaHandler,fromHeader,fromJwtPayload,getActor,getGraphToken,getNodeToken,observeSSE,observeSubscription,toObservable});
|