@graphrefly/graphrefly 0.27.0 → 0.29.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/backoff-HPZMEZNF.js +1 -0
- package/dist/cascading-Bp99ckMJ.d.ts +180 -0
- package/dist/cascading-CcAgRacD.d.cts +180 -0
- package/dist/chunk-22F4K3G7.js +1 -0
- package/dist/chunk-22SVXUPB.js +64 -0
- package/dist/chunk-2GQREQ6C.js +1 -0
- package/dist/chunk-3JXNEPCD.js +2 -0
- package/dist/chunk-4JJCCD5S.js +2 -0
- package/dist/chunk-4OFIQ66T.js +1 -0
- package/dist/chunk-4V4C7K56.js +1 -0
- package/dist/chunk-4VVTGLXJ.js +1 -0
- package/dist/chunk-567NWZ3T.js +1 -0
- package/dist/chunk-5JDE5JHE.js +1 -0
- package/dist/chunk-5QDBSZBV.js +1 -0
- package/dist/chunk-5Z4HDCO6.js +1 -0
- package/dist/chunk-63FFOHLA.js +1 -0
- package/dist/chunk-6QZNQS5B.js +1 -0
- package/dist/chunk-7JDLFI6N.js +1 -0
- package/dist/chunk-7TDOES3L.js +1 -0
- package/dist/chunk-A7IAQQ63.js +1 -0
- package/dist/chunk-AMG5VBHW.js +1 -0
- package/dist/chunk-AUY2YKCO.js +1 -0
- package/dist/chunk-AV3PIDFQ.js +1 -0
- package/dist/chunk-BA5URFYW.js +1 -0
- package/dist/chunk-BKPLTBL5.js +1 -0
- package/dist/chunk-BZP5T4X6.js +1 -0
- package/dist/chunk-CK2E7BTU.js +1 -0
- package/dist/chunk-CSJE2EKV.js +1 -0
- package/dist/chunk-E3AXATVZ.js +9 -0
- package/dist/chunk-ESMPEKEV.js +1 -0
- package/dist/chunk-GJR3P6JG.js +1 -0
- package/dist/chunk-GNCBXARM.js +1 -0
- package/dist/chunk-GPW2V3RE.js +1 -0
- package/dist/chunk-HSIEYSDY.js +1 -0
- package/dist/chunk-I6VIH3VA.js +1 -0
- package/dist/chunk-ISCENNXS.js +1 -0
- package/dist/chunk-JYOUF6UQ.js +1 -0
- package/dist/chunk-KASHOCF5.js +1 -0
- package/dist/chunk-LGSNR4LU.js +5 -0
- package/dist/chunk-LVGBLZM2.js +1 -0
- package/dist/chunk-MGKAO4EK.js +7 -0
- package/dist/chunk-NSG4C6BF.js +23 -0
- package/dist/chunk-OL33ZI6R.js +1 -0
- package/dist/chunk-PCZ35NXD.js +78 -0
- package/dist/chunk-PGMUCUHG.js +43 -0
- package/dist/chunk-QYADASLV.js +1 -0
- package/dist/chunk-RD52SNH2.js +1 -0
- package/dist/chunk-SLMYTGTU.js +1 -0
- package/dist/chunk-TWMEGG45.js +1 -0
- package/dist/chunk-UVJQ35G2.js +1 -0
- package/dist/chunk-VGTCGNRX.js +18 -0
- package/dist/chunk-VIMF6LGM.js +1 -0
- package/dist/chunk-VJLMUKOI.js +1 -0
- package/dist/chunk-VWPRPPKR.js +1 -0
- package/dist/chunk-W4TSQ6RJ.js +1 -0
- package/dist/chunk-WM7H7WTY.js +3 -0
- package/dist/chunk-Y32RJO24.js +1 -0
- package/dist/chunk-Y53B6NS4.js +1 -0
- package/dist/compat/index.cjs +15 -7656
- package/dist/compat/index.d.cts +15 -14
- package/dist/compat/index.d.ts +15 -14
- package/dist/compat/index.js +1 -50
- package/dist/compat/jotai/index.cjs +1 -2048
- package/dist/compat/jotai/index.d.cts +2 -2
- package/dist/compat/jotai/index.d.ts +2 -2
- package/dist/compat/jotai/index.js +1 -9
- package/dist/compat/nanostores/index.cjs +1 -2175
- package/dist/compat/nanostores/index.d.cts +2 -2
- package/dist/compat/nanostores/index.d.ts +2 -2
- package/dist/compat/nanostores/index.js +1 -23
- package/dist/compat/nestjs/index.cjs +15 -6782
- package/dist/compat/nestjs/index.d.cts +7 -6
- package/dist/compat/nestjs/index.d.ts +7 -6
- package/dist/compat/nestjs/index.js +1 -83
- package/dist/compat/react/index.cjs +1 -141
- package/dist/compat/react/index.d.cts +2 -2
- package/dist/compat/react/index.d.ts +2 -2
- package/dist/compat/react/index.js +1 -12
- package/dist/compat/solid/index.cjs +1 -128
- package/dist/compat/solid/index.d.cts +2 -2
- package/dist/compat/solid/index.d.ts +2 -2
- package/dist/compat/solid/index.js +1 -12
- package/dist/compat/svelte/index.cjs +1 -131
- package/dist/compat/svelte/index.d.cts +2 -2
- package/dist/compat/svelte/index.d.ts +2 -2
- package/dist/compat/svelte/index.js +1 -12
- package/dist/compat/vue/index.cjs +1 -146
- package/dist/compat/vue/index.d.cts +2 -2
- package/dist/compat/vue/index.d.ts +2 -2
- package/dist/compat/vue/index.js +1 -12
- package/dist/compat/zustand/index.cjs +7 -4931
- package/dist/compat/zustand/index.d.cts +5 -5
- package/dist/compat/zustand/index.d.ts +5 -5
- package/dist/compat/zustand/index.js +1 -12
- package/dist/composite-BL-llbnE.d.ts +69 -0
- package/dist/composite-Dze--DaA.d.cts +69 -0
- package/dist/core/index.cjs +1 -2271
- package/dist/core/index.d.cts +4 -4
- package/dist/core/index.d.ts +4 -4
- package/dist/core/index.js +1 -110
- package/dist/extra/browser.cjs +1 -0
- package/dist/extra/browser.d.cts +3 -0
- package/dist/extra/browser.d.ts +3 -0
- package/dist/extra/browser.js +1 -0
- package/dist/extra/index.cjs +24 -9971
- package/dist/extra/index.d.cts +13 -6
- package/dist/extra/index.d.ts +13 -6
- package/dist/extra/index.js +1 -381
- package/dist/extra/node.cjs +3 -0
- package/dist/extra/node.d.cts +81 -0
- package/dist/extra/node.d.ts +81 -0
- package/dist/extra/node.js +2 -0
- package/dist/extra/operators.cjs +1 -0
- package/dist/extra/operators.d.cts +910 -0
- package/dist/extra/operators.d.ts +910 -0
- package/dist/extra/operators.js +1 -0
- package/dist/extra/reactive.cjs +1 -0
- package/dist/extra/reactive.d.cts +352 -0
- package/dist/extra/reactive.d.ts +352 -0
- package/dist/extra/reactive.js +1 -0
- package/dist/extra/sources.cjs +1 -2486
- package/dist/extra/sources.d.cts +6 -2
- package/dist/extra/sources.d.ts +6 -2
- package/dist/extra/sources.js +1 -57
- package/dist/extra/storage-browser.cjs +1 -0
- package/dist/extra/storage-browser.d.cts +71 -0
- package/dist/extra/storage-browser.d.ts +71 -0
- package/dist/extra/storage-browser.js +1 -0
- package/dist/extra/storage-core.cjs +1 -0
- package/dist/extra/storage-core.d.cts +98 -0
- package/dist/extra/storage-core.d.ts +98 -0
- package/dist/extra/storage-core.js +1 -0
- package/dist/extra/storage-node.cjs +2 -0
- package/dist/extra/storage-node.d.cts +60 -0
- package/dist/extra/storage-node.d.ts +60 -0
- package/dist/extra/storage-node.js +1 -0
- package/dist/fallback-BaTS7vVY.d.cts +258 -0
- package/dist/fallback-eOm3LNxP.d.ts +258 -0
- package/dist/graph/index.cjs +7 -5030
- package/dist/graph/index.d.cts +6 -5
- package/dist/graph/index.d.ts +6 -5
- package/dist/graph/index.js +1 -50
- package/dist/{graph-DNCrvZSn.d.cts → graph-DgohqXK-.d.cts} +151 -32
- package/dist/{graph-CCwGKLCm.d.ts → graph-Qjg9gWHI.d.ts} +151 -32
- package/dist/{index-BwfLUNw4.d.ts → index-2BVuRCI4.d.ts} +173 -2040
- package/dist/{index-BPVt8kqc.d.ts → index-2NvguqQA.d.ts} +10 -195
- package/dist/index-A65LZhoM.d.ts +186 -0
- package/dist/{index-DlLp-2Xn.d.cts → index-B-8FCEua.d.cts} +10 -195
- package/dist/index-B-gqvYel.d.ts +135 -0
- package/dist/index-B2PRuolf.d.cts +86 -0
- package/dist/index-BJqt9EwW.d.ts +231 -0
- package/dist/{index-BHlKbUwO.d.cts → index-BKjT5DiZ.d.cts} +173 -2040
- package/dist/{index-C0svESO4.d.ts → index-BM8BU4q6.d.ts} +1 -1
- package/dist/{index-VdHQMPy1.d.ts → index-BQaEnxBf.d.ts} +1 -1
- package/dist/index-BSfwiy5B.d.ts +192 -0
- package/dist/index-BTSkeCZs.d.cts +291 -0
- package/dist/index-BUVtw1Ay.d.cts +186 -0
- package/dist/index-BUi57v_p.d.ts +163 -0
- package/dist/{messaging-Gt4LPbyA.d.cts → index-BanNUILp.d.cts} +31 -93
- package/dist/{audit-DRlSzBu9.d.ts → index-BayHDRx6.d.cts} +27 -21
- package/dist/{index-B6D3QNSA.d.ts → index-BiyjsZ0m.d.ts} +148 -20
- package/dist/index-BqZ6vB2A.d.ts +2057 -0
- package/dist/{memory-li6FL5RM.d.ts → index-BuVidq3D.d.cts} +26 -26
- package/dist/index-Byh-xTyp.d.ts +105 -0
- package/dist/index-C08QPDcV.d.cts +321 -0
- package/dist/{demo-shell-BDkOptd6.d.ts → index-C66RJiX8.d.ts} +14 -14
- package/dist/index-C8RfjffH.d.ts +291 -0
- package/dist/index-CA1Cu7Ud.d.ts +873 -0
- package/dist/{index-ByQxazQJ.d.cts → index-CABbltIu.d.cts} +1 -1
- package/dist/{index-VHqptjhu.d.cts → index-CHEBsnYv.d.cts} +1 -1
- package/dist/{index-BuEoe-Qu.d.ts → index-CI0yDnLp.d.ts} +9 -9
- package/dist/{index-B9B7_HEY.d.ts → index-CJ45TW-h.d.ts} +1 -1
- package/dist/{index-CO8uBlUh.d.cts → index-CJZKZoo4.d.cts} +148 -20
- package/dist/{index-wEn0eFe8.d.ts → index-CX2tFJL1.d.ts} +1 -1
- package/dist/{index-BaSM3aYt.d.ts → index-CcWOJ6F0.d.ts} +3 -3
- package/dist/{audit-ClmqGOCx.d.cts → index-CiaVoZGo.d.ts} +27 -21
- package/dist/{index-Dzk2hrlR.d.ts → index-Ct5CWc4E.d.ts} +1 -1
- package/dist/index-D38duMCv.d.cts +357 -0
- package/dist/{index-C8oil6M6.d.ts → index-D5XJ2tSx.d.ts} +30 -6
- package/dist/{index-DO_6JN9Z.d.cts → index-D80do5jX.d.cts} +1 -1
- package/dist/index-D9HKAH_-.d.cts +231 -0
- package/dist/index-DBe_8XW5.d.cts +143 -0
- package/dist/{memory-C6Z2tGpC.d.cts → index-DCeTyFlB.d.ts} +26 -26
- package/dist/index-DDy8eeXS.d.ts +321 -0
- package/dist/index-DJ5oNBc8.d.ts +143 -0
- package/dist/{index-CI3DprxP.d.cts → index-DP0_O3ls.d.cts} +30 -6
- package/dist/{demo-shell-Crid1WdR.d.cts → index-DX8xS-yB.d.cts} +14 -14
- package/dist/index-DiZejfCI.d.cts +2057 -0
- package/dist/index-DknyJ2Fu.d.cts +163 -0
- package/dist/index-DoWMs-Kk.d.cts +135 -0
- package/dist/{messaging-XDoYablx.d.ts → index-DuB5aO4-.d.ts} +31 -93
- package/dist/index-DwjJGKxV.d.ts +357 -0
- package/dist/{index-B6EhDnjH.d.cts → index-H_oxVec5.d.cts} +1 -1
- package/dist/{index-3lsddbbS.d.ts → index-IMAHq-ia.d.ts} +1 -1
- package/dist/{index-B1tloyhO.d.cts → index-U1nir7MX.d.cts} +1 -1
- package/dist/index-Vg7tORgk.d.ts +86 -0
- package/dist/index-dig-r2tQ.d.cts +873 -0
- package/dist/{index-CxFrXH4m.d.ts → index-gsT79Xu9.d.ts} +1 -1
- package/dist/{index-D8wS_PeY.d.cts → index-i99Ka8s7.d.cts} +9 -9
- package/dist/index-iKkyJosF.d.cts +105 -0
- package/dist/{index-Xi3u0HCQ.d.cts → index-jleeotBT.d.cts} +1 -1
- package/dist/{index-DVGiGFGT.d.cts → index-kykKWwV-.d.cts} +3 -3
- package/dist/index-vgcLF5TH.d.cts +192 -0
- package/dist/{index-DYme44FM.d.cts → index-y1RllPn4.d.cts} +1 -1
- package/dist/index.cjs +151 -24142
- package/dist/index.d.cts +69 -2099
- package/dist/index.d.ts +69 -2099
- package/dist/index.js +1 -3868
- package/dist/{meta-CbznRPYJ.d.ts → meta-CX7YsOzp.d.cts} +5 -5
- package/dist/{meta-BxCA7rcr.d.cts → meta-CckhhFRd.d.ts} +5 -5
- package/dist/{node-BmerH3kS.d.cts → node-Dd6wHSib.d.cts} +71 -11
- package/dist/{node-BmerH3kS.d.ts → node-Dd6wHSib.d.ts} +71 -11
- package/dist/{observable-BgGUwcqp.d.ts → observable-BZJgo616.d.ts} +1 -1
- package/dist/{observable-DJt_AxzQ.d.cts → observable-kwzpLvbi.d.cts} +1 -1
- package/dist/patterns/ai/browser.cjs +25 -0
- package/dist/patterns/ai/browser.d.cts +127 -0
- package/dist/patterns/ai/browser.d.ts +127 -0
- package/dist/patterns/ai/browser.js +3 -0
- package/dist/patterns/ai/index.cjs +92 -0
- package/dist/patterns/ai/index.d.cts +17 -0
- package/dist/patterns/ai/index.d.ts +17 -0
- package/dist/patterns/ai/index.js +1 -0
- package/dist/patterns/ai/node.cjs +2 -0
- package/dist/patterns/ai/node.d.cts +58 -0
- package/dist/patterns/ai/node.d.ts +58 -0
- package/dist/patterns/ai/node.js +1 -0
- package/dist/patterns/audit/index.cjs +7 -0
- package/dist/patterns/audit/index.d.cts +6 -0
- package/dist/patterns/audit/index.d.ts +6 -0
- package/dist/patterns/audit/index.js +1 -0
- package/dist/patterns/cqrs/index.cjs +7 -0
- package/dist/patterns/cqrs/index.d.cts +5 -0
- package/dist/patterns/cqrs/index.d.ts +5 -0
- package/dist/patterns/cqrs/index.js +1 -0
- package/dist/patterns/demo-shell/index.cjs +8 -0
- package/dist/patterns/demo-shell/index.d.cts +6 -0
- package/dist/patterns/demo-shell/index.d.ts +6 -0
- package/dist/patterns/demo-shell/index.js +1 -0
- package/dist/patterns/domain-templates/index.cjs +7 -0
- package/dist/patterns/domain-templates/index.d.cts +5 -0
- package/dist/patterns/domain-templates/index.d.ts +5 -0
- package/dist/patterns/domain-templates/index.js +1 -0
- package/dist/patterns/graphspec/index.cjs +84 -0
- package/dist/patterns/graphspec/index.d.cts +7 -0
- package/dist/patterns/graphspec/index.d.ts +7 -0
- package/dist/patterns/graphspec/index.js +1 -0
- package/dist/patterns/guarded-execution/index.cjs +7 -0
- package/dist/patterns/guarded-execution/index.d.cts +7 -0
- package/dist/patterns/guarded-execution/index.d.ts +7 -0
- package/dist/patterns/guarded-execution/index.js +1 -0
- package/dist/patterns/harness/index.cjs +49 -0
- package/dist/patterns/harness/index.d.cts +11 -0
- package/dist/patterns/harness/index.d.ts +11 -0
- package/dist/patterns/harness/index.js +1 -0
- package/dist/patterns/job-queue/index.cjs +7 -0
- package/dist/patterns/job-queue/index.d.cts +5 -0
- package/dist/patterns/job-queue/index.d.ts +5 -0
- package/dist/patterns/job-queue/index.js +1 -0
- package/dist/patterns/lens/index.cjs +7 -0
- package/dist/patterns/lens/index.d.cts +7 -0
- package/dist/patterns/lens/index.d.ts +7 -0
- package/dist/patterns/lens/index.js +1 -0
- package/dist/patterns/memory/index.cjs +7 -0
- package/dist/patterns/memory/index.d.cts +5 -0
- package/dist/patterns/memory/index.d.ts +5 -0
- package/dist/patterns/memory/index.js +1 -0
- package/dist/patterns/messaging/index.cjs +7 -0
- package/dist/patterns/messaging/index.d.cts +5 -0
- package/dist/patterns/messaging/index.d.ts +5 -0
- package/dist/patterns/messaging/index.js +1 -0
- package/dist/patterns/orchestration/index.cjs +7 -0
- package/dist/patterns/orchestration/index.d.cts +6 -0
- package/dist/patterns/orchestration/index.d.ts +6 -0
- package/dist/patterns/orchestration/index.js +1 -0
- package/dist/patterns/reactive-layout/index.cjs +8 -6444
- package/dist/patterns/reactive-layout/index.d.cts +6 -6
- package/dist/patterns/reactive-layout/index.d.ts +6 -6
- package/dist/patterns/reactive-layout/index.js +1 -56
- package/dist/patterns/reduction/index.cjs +7 -0
- package/dist/patterns/reduction/index.d.cts +5 -0
- package/dist/patterns/reduction/index.d.ts +5 -0
- package/dist/patterns/reduction/index.js +1 -0
- package/dist/patterns/refine-loop/index.cjs +9 -0
- package/dist/patterns/refine-loop/index.d.cts +7 -0
- package/dist/patterns/refine-loop/index.d.ts +7 -0
- package/dist/patterns/refine-loop/index.js +1 -0
- package/dist/patterns/resilient-pipeline/index.cjs +1 -0
- package/dist/patterns/resilient-pipeline/index.d.cts +7 -0
- package/dist/patterns/resilient-pipeline/index.d.ts +7 -0
- package/dist/patterns/resilient-pipeline/index.js +1 -0
- package/dist/patterns/surface/index.cjs +15 -0
- package/dist/patterns/surface/index.d.cts +8 -0
- package/dist/patterns/surface/index.d.ts +8 -0
- package/dist/patterns/surface/index.js +1 -0
- package/dist/{reactive-layout-u5Ulnqag.d.ts → reactive-layout-BkBwVvwm.d.ts} +2 -2
- package/dist/{reactive-layout-MQP--J3F.d.cts → reactive-layout-PiFwVaWS.d.cts} +2 -2
- package/dist/reactive-log-1QTyx10a.d.ts +190 -0
- package/dist/reactive-log-BiVoSxke.d.cts +190 -0
- package/dist/{composite-aUCvjZVR.d.ts → reactive-map-CwO_COHy.d.cts} +2 -67
- package/dist/{composite-C7PcQvcs.d.cts → reactive-map-FeuTVAJb.d.ts} +2 -67
- package/dist/resilience-CBfYJW5C.d.ts +493 -0
- package/dist/resilience-XRUF267O.js +1 -0
- package/dist/resilience-uBz4yvYB.d.cts +493 -0
- package/dist/{sugar-CCOxXK1e.d.ts → sugar-CY-MCfZ9.d.ts} +17 -15
- package/dist/{sugar-D02n5JjF.d.cts → sugar-DHttV0LX.d.cts} +17 -15
- package/dist/topology-tree-CVjt2gp7.d.cts +25 -0
- package/dist/topology-tree-one6oSKY.d.ts +25 -0
- package/dist/types-O3GzJY2U.d.cts +401 -0
- package/dist/types-u64Ose53.d.ts +401 -0
- package/package.json +252 -22
- package/dist/ai-CaR_912Q.d.cts +0 -1033
- package/dist/ai-WlRltJV7.d.ts +0 -1033
- package/dist/chunk-3ZWCKRHX.js +0 -117
- package/dist/chunk-3ZWCKRHX.js.map +0 -1
- package/dist/chunk-7TAQJHQV.js +0 -103
- package/dist/chunk-7TAQJHQV.js.map +0 -1
- package/dist/chunk-APFNLIRG.js +0 -62
- package/dist/chunk-APFNLIRG.js.map +0 -1
- package/dist/chunk-AT5LKYNL.js +0 -395
- package/dist/chunk-AT5LKYNL.js.map +0 -1
- package/dist/chunk-BQ6RQQFF.js +0 -5087
- package/dist/chunk-BQ6RQQFF.js.map +0 -1
- package/dist/chunk-BVZYTZ5H.js +0 -599
- package/dist/chunk-BVZYTZ5H.js.map +0 -1
- package/dist/chunk-DST5DKZS.js +0 -1371
- package/dist/chunk-DST5DKZS.js.map +0 -1
- package/dist/chunk-GTE6PWRZ.js +0 -866
- package/dist/chunk-GTE6PWRZ.js.map +0 -1
- package/dist/chunk-HXZEYDUR.js +0 -94
- package/dist/chunk-HXZEYDUR.js.map +0 -1
- package/dist/chunk-J22W6HV3.js +0 -107
- package/dist/chunk-J22W6HV3.js.map +0 -1
- package/dist/chunk-J2VBW3DZ.js +0 -302
- package/dist/chunk-J2VBW3DZ.js.map +0 -1
- package/dist/chunk-JSCT3CR4.js +0 -38
- package/dist/chunk-JSCT3CR4.js.map +0 -1
- package/dist/chunk-JWBCY4NC.js +0 -330
- package/dist/chunk-JWBCY4NC.js.map +0 -1
- package/dist/chunk-K2AUJHVP.js +0 -2251
- package/dist/chunk-K2AUJHVP.js.map +0 -1
- package/dist/chunk-MJ2NKQQL.js +0 -119
- package/dist/chunk-MJ2NKQQL.js.map +0 -1
- package/dist/chunk-N6UR7YVY.js +0 -198
- package/dist/chunk-N6UR7YVY.js.map +0 -1
- package/dist/chunk-NC6S43JJ.js +0 -456
- package/dist/chunk-NC6S43JJ.js.map +0 -1
- package/dist/chunk-OFVJBJXR.js +0 -98
- package/dist/chunk-OFVJBJXR.js.map +0 -1
- package/dist/chunk-OHISZPOJ.js +0 -97
- package/dist/chunk-OHISZPOJ.js.map +0 -1
- package/dist/chunk-OU5CQKNW.js +0 -102
- package/dist/chunk-OU5CQKNW.js.map +0 -1
- package/dist/chunk-PF7GRZMW.js +0 -2712
- package/dist/chunk-PF7GRZMW.js.map +0 -1
- package/dist/chunk-PHOUUNK7.js +0 -2291
- package/dist/chunk-PHOUUNK7.js.map +0 -1
- package/dist/chunk-RNHBMHKA.js +0 -1665
- package/dist/chunk-RNHBMHKA.js.map +0 -1
- package/dist/chunk-SX52TAR4.js +0 -110
- package/dist/chunk-SX52TAR4.js.map +0 -1
- package/dist/chunk-VYPWMZ6H.js +0 -98
- package/dist/chunk-VYPWMZ6H.js.map +0 -1
- package/dist/chunk-WBZOVTYK.js +0 -171
- package/dist/chunk-WBZOVTYK.js.map +0 -1
- package/dist/chunk-WKNUIZOY.js +0 -354
- package/dist/chunk-WKNUIZOY.js.map +0 -1
- package/dist/chunk-X3VMZYBT.js +0 -713
- package/dist/chunk-X3VMZYBT.js.map +0 -1
- package/dist/chunk-X5R3GL6H.js +0 -525
- package/dist/chunk-X5R3GL6H.js.map +0 -1
- package/dist/chunk-XGPU467M.js +0 -136
- package/dist/chunk-XGPU467M.js.map +0 -1
- package/dist/compat/index.cjs.map +0 -1
- package/dist/compat/index.js.map +0 -1
- package/dist/compat/jotai/index.cjs.map +0 -1
- package/dist/compat/jotai/index.js.map +0 -1
- package/dist/compat/nanostores/index.cjs.map +0 -1
- package/dist/compat/nanostores/index.js.map +0 -1
- package/dist/compat/nestjs/index.cjs.map +0 -1
- package/dist/compat/nestjs/index.js.map +0 -1
- package/dist/compat/react/index.cjs.map +0 -1
- package/dist/compat/react/index.js.map +0 -1
- package/dist/compat/solid/index.cjs.map +0 -1
- package/dist/compat/solid/index.js.map +0 -1
- package/dist/compat/svelte/index.cjs.map +0 -1
- package/dist/compat/svelte/index.js.map +0 -1
- package/dist/compat/vue/index.cjs.map +0 -1
- package/dist/compat/vue/index.js.map +0 -1
- package/dist/compat/zustand/index.cjs.map +0 -1
- package/dist/compat/zustand/index.js.map +0 -1
- package/dist/core/index.cjs.map +0 -1
- package/dist/core/index.js.map +0 -1
- package/dist/extra/index.cjs.map +0 -1
- package/dist/extra/index.js.map +0 -1
- package/dist/extra/sources.cjs.map +0 -1
- package/dist/extra/sources.js.map +0 -1
- package/dist/graph/index.cjs.map +0 -1
- package/dist/graph/index.js.map +0 -1
- package/dist/index.cjs.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/patterns/ai.cjs +0 -7930
- package/dist/patterns/ai.cjs.map +0 -1
- package/dist/patterns/ai.d.cts +0 -10
- package/dist/patterns/ai.d.ts +0 -10
- package/dist/patterns/ai.js +0 -71
- package/dist/patterns/ai.js.map +0 -1
- package/dist/patterns/audit.cjs +0 -5805
- package/dist/patterns/audit.cjs.map +0 -1
- package/dist/patterns/audit.d.cts +0 -6
- package/dist/patterns/audit.d.ts +0 -6
- package/dist/patterns/audit.js +0 -29
- package/dist/patterns/audit.js.map +0 -1
- package/dist/patterns/demo-shell.cjs +0 -5604
- package/dist/patterns/demo-shell.cjs.map +0 -1
- package/dist/patterns/demo-shell.d.cts +0 -6
- package/dist/patterns/demo-shell.d.ts +0 -6
- package/dist/patterns/demo-shell.js +0 -15
- package/dist/patterns/demo-shell.js.map +0 -1
- package/dist/patterns/memory.cjs +0 -5283
- package/dist/patterns/memory.cjs.map +0 -1
- package/dist/patterns/memory.d.cts +0 -5
- package/dist/patterns/memory.d.ts +0 -5
- package/dist/patterns/memory.js +0 -20
- package/dist/patterns/memory.js.map +0 -1
- package/dist/patterns/reactive-layout/index.cjs.map +0 -1
- package/dist/patterns/reactive-layout/index.js.map +0 -1
- package/dist/storage-CMjUUuxn.d.ts +0 -190
- package/dist/storage-DdWlZo6U.d.cts +0 -190
|
@@ -1,2048 +1 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
-
};
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
|
|
20
|
-
// src/compat/jotai/index.ts
|
|
21
|
-
var jotai_exports = {};
|
|
22
|
-
__export(jotai_exports, {
|
|
23
|
-
atom: () => atom
|
|
24
|
-
});
|
|
25
|
-
module.exports = __toCommonJS(jotai_exports);
|
|
26
|
-
|
|
27
|
-
// src/core/messages.ts
|
|
28
|
-
var START = /* @__PURE__ */ Symbol.for("graphrefly/START");
|
|
29
|
-
var DATA = /* @__PURE__ */ Symbol.for("graphrefly/DATA");
|
|
30
|
-
var DIRTY = /* @__PURE__ */ Symbol.for("graphrefly/DIRTY");
|
|
31
|
-
var RESOLVED = /* @__PURE__ */ Symbol.for("graphrefly/RESOLVED");
|
|
32
|
-
var INVALIDATE = /* @__PURE__ */ Symbol.for("graphrefly/INVALIDATE");
|
|
33
|
-
var PAUSE = /* @__PURE__ */ Symbol.for("graphrefly/PAUSE");
|
|
34
|
-
var RESUME = /* @__PURE__ */ Symbol.for("graphrefly/RESUME");
|
|
35
|
-
var TEARDOWN = /* @__PURE__ */ Symbol.for("graphrefly/TEARDOWN");
|
|
36
|
-
var COMPLETE = /* @__PURE__ */ Symbol.for("graphrefly/COMPLETE");
|
|
37
|
-
var ERROR = /* @__PURE__ */ Symbol.for("graphrefly/ERROR");
|
|
38
|
-
var DIRTY_MSG = Object.freeze([DIRTY]);
|
|
39
|
-
var RESOLVED_MSG = Object.freeze([RESOLVED]);
|
|
40
|
-
var INVALIDATE_MSG = Object.freeze([INVALIDATE]);
|
|
41
|
-
var START_MSG = Object.freeze([START]);
|
|
42
|
-
var COMPLETE_MSG = Object.freeze([COMPLETE]);
|
|
43
|
-
var TEARDOWN_MSG = Object.freeze([TEARDOWN]);
|
|
44
|
-
var DIRTY_ONLY_BATCH = Object.freeze([DIRTY_MSG]);
|
|
45
|
-
var RESOLVED_ONLY_BATCH = Object.freeze([RESOLVED_MSG]);
|
|
46
|
-
var INVALIDATE_ONLY_BATCH = Object.freeze([INVALIDATE_MSG]);
|
|
47
|
-
var COMPLETE_ONLY_BATCH = Object.freeze([COMPLETE_MSG]);
|
|
48
|
-
var TEARDOWN_ONLY_BATCH = Object.freeze([TEARDOWN_MSG]);
|
|
49
|
-
|
|
50
|
-
// src/graph/codec.ts
|
|
51
|
-
var JsonCodec = {
|
|
52
|
-
name: "json",
|
|
53
|
-
version: 1,
|
|
54
|
-
contentType: "application/json",
|
|
55
|
-
encode(snapshot) {
|
|
56
|
-
const json = JSON.stringify(snapshot);
|
|
57
|
-
return new TextEncoder().encode(json);
|
|
58
|
-
},
|
|
59
|
-
decode(buffer, _codecVersion) {
|
|
60
|
-
const json = new TextDecoder().decode(buffer);
|
|
61
|
-
return JSON.parse(json);
|
|
62
|
-
}
|
|
63
|
-
};
|
|
64
|
-
function registerBuiltinCodecs(config) {
|
|
65
|
-
config.registerCodec(JsonCodec);
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
// src/core/actor.ts
|
|
69
|
-
var DEFAULT_ACTOR = { type: "system", id: "" };
|
|
70
|
-
function normalizeActor(actor) {
|
|
71
|
-
if (actor == null) return DEFAULT_ACTOR;
|
|
72
|
-
const { type, id, ...rest } = actor;
|
|
73
|
-
return {
|
|
74
|
-
type: type ?? "system",
|
|
75
|
-
id: id ?? "",
|
|
76
|
-
...rest
|
|
77
|
-
};
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
// src/core/batch.ts
|
|
81
|
-
var batchDepth = 0;
|
|
82
|
-
var flushInProgress = false;
|
|
83
|
-
var drainPhase2 = [];
|
|
84
|
-
var drainPhase3 = [];
|
|
85
|
-
var drainPhase4 = [];
|
|
86
|
-
var flushHooks = [];
|
|
87
|
-
function isBatching() {
|
|
88
|
-
return batchDepth > 0 || flushInProgress;
|
|
89
|
-
}
|
|
90
|
-
function isExplicitlyBatching() {
|
|
91
|
-
return batchDepth > 0;
|
|
92
|
-
}
|
|
93
|
-
function registerBatchFlushHook(hook) {
|
|
94
|
-
if (batchDepth > 0) {
|
|
95
|
-
flushHooks.push(hook);
|
|
96
|
-
} else {
|
|
97
|
-
hook();
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
function downWithBatch(sink, messages, tierOf) {
|
|
101
|
-
if (messages.length === 0) return;
|
|
102
|
-
if (messages.length === 1) {
|
|
103
|
-
const tier = tierOf(messages[0][0]);
|
|
104
|
-
if (tier < 3 || !isBatching()) {
|
|
105
|
-
sink(messages);
|
|
106
|
-
return;
|
|
107
|
-
}
|
|
108
|
-
const queue = tier >= 5 ? drainPhase4 : tier === 4 ? drainPhase3 : drainPhase2;
|
|
109
|
-
queue.push(() => sink(messages));
|
|
110
|
-
return;
|
|
111
|
-
}
|
|
112
|
-
const n = messages.length;
|
|
113
|
-
let phase2Start = n;
|
|
114
|
-
let phase3Start = n;
|
|
115
|
-
let phase4Start = n;
|
|
116
|
-
let i = 0;
|
|
117
|
-
while (i < n && tierOf(messages[i][0]) < 3) i++;
|
|
118
|
-
phase2Start = i;
|
|
119
|
-
while (i < n && tierOf(messages[i][0]) === 3) i++;
|
|
120
|
-
phase3Start = i;
|
|
121
|
-
while (i < n && tierOf(messages[i][0]) === 4) i++;
|
|
122
|
-
phase4Start = i;
|
|
123
|
-
const batching = isBatching();
|
|
124
|
-
if (phase2Start > 0) {
|
|
125
|
-
const immediate = messages.slice(0, phase2Start);
|
|
126
|
-
sink(immediate);
|
|
127
|
-
}
|
|
128
|
-
if (phase3Start > phase2Start) {
|
|
129
|
-
const phase2 = messages.slice(phase2Start, phase3Start);
|
|
130
|
-
if (batching) drainPhase2.push(() => sink(phase2));
|
|
131
|
-
else sink(phase2);
|
|
132
|
-
}
|
|
133
|
-
if (phase4Start > phase3Start) {
|
|
134
|
-
const phase3 = messages.slice(phase3Start, phase4Start);
|
|
135
|
-
if (batching) drainPhase3.push(() => sink(phase3));
|
|
136
|
-
else sink(phase3);
|
|
137
|
-
}
|
|
138
|
-
if (n > phase4Start) {
|
|
139
|
-
const phase4 = messages.slice(phase4Start, n);
|
|
140
|
-
if (batching) drainPhase4.push(() => sink(phase4));
|
|
141
|
-
else sink(phase4);
|
|
142
|
-
}
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
// src/core/clock.ts
|
|
146
|
-
function wallClockNs() {
|
|
147
|
-
return Date.now() * 1e6;
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
// src/core/config.ts
|
|
151
|
-
var GraphReFlyConfig = class {
|
|
152
|
-
_messageTypes = /* @__PURE__ */ new Map();
|
|
153
|
-
_codecs = /* @__PURE__ */ new Map();
|
|
154
|
-
_onMessage;
|
|
155
|
-
_onSubscribe;
|
|
156
|
-
_defaultVersioning;
|
|
157
|
-
_defaultHashFn;
|
|
158
|
-
_inspectorEnabled = !(typeof process !== "undefined" && process.env?.NODE_ENV === "production");
|
|
159
|
-
_globalInspector;
|
|
160
|
-
_frozen = false;
|
|
161
|
-
/**
|
|
162
|
-
* Pre-bound tier lookup — shared by every node bound to this config. Since
|
|
163
|
-
* the registry is frozen on first hook access, this closure can be built
|
|
164
|
-
* once in the constructor and handed directly to `downWithBatch` /
|
|
165
|
-
* `_frameBatch` paths without per-node or per-emission `.bind(config)`
|
|
166
|
-
* allocation.
|
|
167
|
-
*/
|
|
168
|
-
tierOf;
|
|
169
|
-
constructor(init) {
|
|
170
|
-
this._onMessage = init.onMessage;
|
|
171
|
-
this._onSubscribe = init.onSubscribe;
|
|
172
|
-
this._defaultVersioning = init.defaultVersioning;
|
|
173
|
-
this._defaultHashFn = init.defaultHashFn;
|
|
174
|
-
this.tierOf = (t) => {
|
|
175
|
-
const reg = this._messageTypes.get(t);
|
|
176
|
-
return reg != null ? reg.tier : 1;
|
|
177
|
-
};
|
|
178
|
-
}
|
|
179
|
-
// --- Hook getters (freeze on read) ---
|
|
180
|
-
get onMessage() {
|
|
181
|
-
this._frozen = true;
|
|
182
|
-
return this._onMessage;
|
|
183
|
-
}
|
|
184
|
-
get onSubscribe() {
|
|
185
|
-
this._frozen = true;
|
|
186
|
-
return this._onSubscribe;
|
|
187
|
-
}
|
|
188
|
-
// --- Hook setters (throw when frozen) ---
|
|
189
|
-
set onMessage(v) {
|
|
190
|
-
this._assertUnfrozen();
|
|
191
|
-
this._onMessage = v;
|
|
192
|
-
}
|
|
193
|
-
set onSubscribe(v) {
|
|
194
|
-
this._assertUnfrozen();
|
|
195
|
-
this._onSubscribe = v;
|
|
196
|
-
}
|
|
197
|
-
/**
|
|
198
|
-
* Default versioning level applied to every node bound to this config,
|
|
199
|
-
* unless the node's own `opts.versioning` provides an explicit override.
|
|
200
|
-
* Setting this is only allowed before the config freezes (i.e., before
|
|
201
|
-
* the first node is created) so every node in the graph sees a
|
|
202
|
-
* consistent starting level. Individual nodes can still opt into a
|
|
203
|
-
* higher level via `opts.versioning`, or post-hoc via
|
|
204
|
-
* `NodeImpl._applyVersioning(level)` when the node is quiescent.
|
|
205
|
-
*
|
|
206
|
-
* v0 is the minimum opt-in — unversioned nodes (`undefined`) skip
|
|
207
|
-
* the version counter entirely. v1 adds content-addressed cid.
|
|
208
|
-
* Future levels (v2, v3) are reserved for linked-history and
|
|
209
|
-
* cryptographic attestation extensions.
|
|
210
|
-
*/
|
|
211
|
-
get defaultVersioning() {
|
|
212
|
-
return this._defaultVersioning;
|
|
213
|
-
}
|
|
214
|
-
set defaultVersioning(v) {
|
|
215
|
-
this._assertUnfrozen();
|
|
216
|
-
this._defaultVersioning = v;
|
|
217
|
-
}
|
|
218
|
-
/**
|
|
219
|
-
* Default content-hash function applied to every versioned node bound
|
|
220
|
-
* to this config, unless the node's own `opts.versioningHash` provides
|
|
221
|
-
* an explicit override. Use this when a graph needs a non-default hash
|
|
222
|
-
* — e.g., swap the vendored sync SHA-256 for a faster non-crypto hash
|
|
223
|
-
* (xxHash, FNV-1a) in hot-path workloads, or a stronger hash when
|
|
224
|
-
* versioning v1 cids are used as audit anchors.
|
|
225
|
-
*
|
|
226
|
-
* Only settable before the config freezes. Individual nodes can still
|
|
227
|
-
* override via `opts.versioningHash`.
|
|
228
|
-
*/
|
|
229
|
-
get defaultHashFn() {
|
|
230
|
-
return this._defaultHashFn;
|
|
231
|
-
}
|
|
232
|
-
set defaultHashFn(v) {
|
|
233
|
-
this._assertUnfrozen();
|
|
234
|
-
this._defaultHashFn = v;
|
|
235
|
-
}
|
|
236
|
-
/**
|
|
237
|
-
* When `false`, structured observation options (`causal`, `timeline`)
|
|
238
|
-
* and `Graph.trace()` writes are no-ops. Raw `Graph.observe()` always
|
|
239
|
-
* works. Default: `true` outside production (`NODE_ENV !== "production"`).
|
|
240
|
-
*
|
|
241
|
-
* Settable at any time — inspector gating is an operational concern, not
|
|
242
|
-
* a protocol invariant, so it does NOT require freeze before node creation.
|
|
243
|
-
*/
|
|
244
|
-
get inspectorEnabled() {
|
|
245
|
-
return this._inspectorEnabled;
|
|
246
|
-
}
|
|
247
|
-
set inspectorEnabled(v) {
|
|
248
|
-
this._inspectorEnabled = v;
|
|
249
|
-
}
|
|
250
|
-
/**
|
|
251
|
-
* Process-global observability hook (Redux-DevTools-style full-graph
|
|
252
|
-
* tracer). Fires once per outgoing batch from every node bound to this
|
|
253
|
-
* config, gated by {@link inspectorEnabled}. See {@link GlobalInspectorHook}.
|
|
254
|
-
*
|
|
255
|
-
* Settable at any time — like {@link inspectorEnabled} this is operational,
|
|
256
|
-
* not protocol-shaping, so it does NOT trigger config freeze.
|
|
257
|
-
*/
|
|
258
|
-
get globalInspector() {
|
|
259
|
-
return this._globalInspector;
|
|
260
|
-
}
|
|
261
|
-
set globalInspector(v) {
|
|
262
|
-
this._globalInspector = v;
|
|
263
|
-
}
|
|
264
|
-
// --- Registry (writes require unfrozen; reads are free lookups) ---
|
|
265
|
-
/**
|
|
266
|
-
* Register a custom message type. Must be called before any node that
|
|
267
|
-
* uses this config has been created — otherwise throws. Default
|
|
268
|
-
* `wireCrossing` is `tier >= 3`.
|
|
269
|
-
*/
|
|
270
|
-
registerMessageType(t, input) {
|
|
271
|
-
this._assertUnfrozen();
|
|
272
|
-
this._messageTypes.set(t, {
|
|
273
|
-
tier: input.tier,
|
|
274
|
-
wireCrossing: input.wireCrossing ?? input.tier >= 3,
|
|
275
|
-
metaPassthrough: input.metaPassthrough ?? true
|
|
276
|
-
});
|
|
277
|
-
return this;
|
|
278
|
-
}
|
|
279
|
-
/** Tier for `t`. Unknown types default to tier 1 (immediate, after START). */
|
|
280
|
-
messageTier(t) {
|
|
281
|
-
const reg = this._messageTypes.get(t);
|
|
282
|
-
return reg != null ? reg.tier : 1;
|
|
283
|
-
}
|
|
284
|
-
/**
|
|
285
|
-
* Whether `t` is registered as wire-crossing. Unknown types default to
|
|
286
|
-
* `true` (spec §1.3.6 forward-compat — unknowns cross the wire).
|
|
287
|
-
*/
|
|
288
|
-
isWireCrossing(t) {
|
|
289
|
-
const reg = this._messageTypes.get(t);
|
|
290
|
-
return reg != null ? reg.wireCrossing : true;
|
|
291
|
-
}
|
|
292
|
-
/** Convenience inverse of {@link isWireCrossing}. */
|
|
293
|
-
isLocalOnly(t) {
|
|
294
|
-
return !this.isWireCrossing(t);
|
|
295
|
-
}
|
|
296
|
-
/**
|
|
297
|
-
* Whether `t` is forwarded to meta companions by `Graph.signal`. Defaults
|
|
298
|
-
* to `true` for unknowns (forward-compat — new types pass through meta by
|
|
299
|
-
* default; opt-in filter via `registerMessageType({metaPassthrough: false})`).
|
|
300
|
-
*/
|
|
301
|
-
isMetaPassthrough(t) {
|
|
302
|
-
const reg = this._messageTypes.get(t);
|
|
303
|
-
return reg != null ? reg.metaPassthrough : true;
|
|
304
|
-
}
|
|
305
|
-
/** Whether `t` is a registered (built-in or custom) type. */
|
|
306
|
-
isKnownMessageType(t) {
|
|
307
|
-
return this._messageTypes.has(t);
|
|
308
|
-
}
|
|
309
|
-
// --- Codec registry (writes require unfrozen; reads are free lookups) ---
|
|
310
|
-
/**
|
|
311
|
-
* Register a graph codec by `codec.name`. Used by the envelope-based
|
|
312
|
-
* `graph.snapshot({format: "bytes", codec: name})` path and
|
|
313
|
-
* `Graph.decode(bytes)` auto-dispatch. Must be called before any node
|
|
314
|
-
* bound to this config is created — otherwise throws.
|
|
315
|
-
*
|
|
316
|
-
* Re-registering the same name overwrites, so user codecs can shadow
|
|
317
|
-
* built-in ones before freeze (e.g., to swap a zstd-wrapped dag-cbor in
|
|
318
|
-
* for `"dag-cbor"`).
|
|
319
|
-
*/
|
|
320
|
-
registerCodec(codec) {
|
|
321
|
-
this._assertUnfrozen();
|
|
322
|
-
this._codecs.set(codec.name, codec);
|
|
323
|
-
return this;
|
|
324
|
-
}
|
|
325
|
-
/**
|
|
326
|
-
* Resolve a registered codec by name. Returns `undefined` for unknown
|
|
327
|
-
* names. Typed callers cast to their concrete codec interface (e.g.,
|
|
328
|
-
* `config.lookupCodec<GraphCodec>("json")`) — this method stays
|
|
329
|
-
* layer-pure (no import of graph-layer types into `core/`).
|
|
330
|
-
*/
|
|
331
|
-
lookupCodec(name) {
|
|
332
|
-
return this._codecs.get(name);
|
|
333
|
-
}
|
|
334
|
-
/** @internal Used by tests and dev tooling — check freeze state without triggering it. */
|
|
335
|
-
_isFrozen() {
|
|
336
|
-
return this._frozen;
|
|
337
|
-
}
|
|
338
|
-
_assertUnfrozen() {
|
|
339
|
-
if (this._frozen) {
|
|
340
|
-
throw new Error(
|
|
341
|
-
"GraphReFlyConfig is frozen: a node has already captured this config. Register custom types and set hooks before creating any node."
|
|
342
|
-
);
|
|
343
|
-
}
|
|
344
|
-
}
|
|
345
|
-
};
|
|
346
|
-
function registerBuiltins(cfg) {
|
|
347
|
-
cfg.registerMessageType(START, { tier: 0, wireCrossing: false });
|
|
348
|
-
cfg.registerMessageType(DIRTY, { tier: 1, wireCrossing: false });
|
|
349
|
-
cfg.registerMessageType(INVALIDATE, {
|
|
350
|
-
tier: 1,
|
|
351
|
-
wireCrossing: false,
|
|
352
|
-
metaPassthrough: false
|
|
353
|
-
});
|
|
354
|
-
cfg.registerMessageType(PAUSE, { tier: 2, wireCrossing: false });
|
|
355
|
-
cfg.registerMessageType(RESUME, { tier: 2, wireCrossing: false });
|
|
356
|
-
cfg.registerMessageType(DATA, { tier: 3, wireCrossing: true });
|
|
357
|
-
cfg.registerMessageType(RESOLVED, { tier: 3, wireCrossing: true });
|
|
358
|
-
cfg.registerMessageType(COMPLETE, {
|
|
359
|
-
tier: 4,
|
|
360
|
-
wireCrossing: true,
|
|
361
|
-
metaPassthrough: false
|
|
362
|
-
});
|
|
363
|
-
cfg.registerMessageType(ERROR, {
|
|
364
|
-
tier: 4,
|
|
365
|
-
wireCrossing: true,
|
|
366
|
-
metaPassthrough: false
|
|
367
|
-
});
|
|
368
|
-
cfg.registerMessageType(TEARDOWN, {
|
|
369
|
-
tier: 5,
|
|
370
|
-
wireCrossing: true,
|
|
371
|
-
metaPassthrough: false
|
|
372
|
-
});
|
|
373
|
-
}
|
|
374
|
-
|
|
375
|
-
// src/core/guard.ts
|
|
376
|
-
var GuardDenied = class extends Error {
|
|
377
|
-
actor;
|
|
378
|
-
action;
|
|
379
|
-
nodeName;
|
|
380
|
-
/**
|
|
381
|
-
* @param details - Actor, action, and optional node name for the denial.
|
|
382
|
-
* @param message - Optional override for the default error message.
|
|
383
|
-
*/
|
|
384
|
-
constructor(details, message) {
|
|
385
|
-
super(
|
|
386
|
-
message ?? `GuardDenied: action "${String(details.action)}" denied for actor type "${String(details.actor.type)}"`
|
|
387
|
-
);
|
|
388
|
-
this.name = "GuardDenied";
|
|
389
|
-
this.actor = details.actor;
|
|
390
|
-
this.action = details.action;
|
|
391
|
-
this.nodeName = details.nodeName;
|
|
392
|
-
}
|
|
393
|
-
/** Qualified registry path when known (roadmap diagnostics: same as {@link nodeName}). */
|
|
394
|
-
get node() {
|
|
395
|
-
return this.nodeName;
|
|
396
|
-
}
|
|
397
|
-
};
|
|
398
|
-
|
|
399
|
-
// src/core/versioning.ts
|
|
400
|
-
function canonicalizeForHash(value) {
|
|
401
|
-
if (value === void 0) return null;
|
|
402
|
-
if (typeof value === "number") {
|
|
403
|
-
if (!Number.isFinite(value)) {
|
|
404
|
-
throw new TypeError(`Cannot hash non-finite number: ${value}`);
|
|
405
|
-
}
|
|
406
|
-
if (Number.isInteger(value) && !Number.isSafeInteger(value)) {
|
|
407
|
-
throw new TypeError(
|
|
408
|
-
`Cannot hash integer outside safe range (|n| > 2^53-1): ${value}. Cross-language cid parity is not guaranteed for unsafe integers.`
|
|
409
|
-
);
|
|
410
|
-
}
|
|
411
|
-
return value;
|
|
412
|
-
}
|
|
413
|
-
if (typeof value === "string" || typeof value === "boolean" || value === null) {
|
|
414
|
-
return value;
|
|
415
|
-
}
|
|
416
|
-
if (Array.isArray(value)) {
|
|
417
|
-
return value.map(canonicalizeForHash);
|
|
418
|
-
}
|
|
419
|
-
if (typeof value === "object" && value !== null) {
|
|
420
|
-
const sorted = {};
|
|
421
|
-
for (const k of Object.keys(value).sort()) {
|
|
422
|
-
sorted[k] = canonicalizeForHash(value[k]);
|
|
423
|
-
}
|
|
424
|
-
return sorted;
|
|
425
|
-
}
|
|
426
|
-
return null;
|
|
427
|
-
}
|
|
428
|
-
var SHA256_K = /* @__PURE__ */ new Uint32Array([
|
|
429
|
-
1116352408,
|
|
430
|
-
1899447441,
|
|
431
|
-
3049323471,
|
|
432
|
-
3921009573,
|
|
433
|
-
961987163,
|
|
434
|
-
1508970993,
|
|
435
|
-
2453635748,
|
|
436
|
-
2870763221,
|
|
437
|
-
3624381080,
|
|
438
|
-
310598401,
|
|
439
|
-
607225278,
|
|
440
|
-
1426881987,
|
|
441
|
-
1925078388,
|
|
442
|
-
2162078206,
|
|
443
|
-
2614888103,
|
|
444
|
-
3248222580,
|
|
445
|
-
3835390401,
|
|
446
|
-
4022224774,
|
|
447
|
-
264347078,
|
|
448
|
-
604807628,
|
|
449
|
-
770255983,
|
|
450
|
-
1249150122,
|
|
451
|
-
1555081692,
|
|
452
|
-
1996064986,
|
|
453
|
-
2554220882,
|
|
454
|
-
2821834349,
|
|
455
|
-
2952996808,
|
|
456
|
-
3210313671,
|
|
457
|
-
3336571891,
|
|
458
|
-
3584528711,
|
|
459
|
-
113926993,
|
|
460
|
-
338241895,
|
|
461
|
-
666307205,
|
|
462
|
-
773529912,
|
|
463
|
-
1294757372,
|
|
464
|
-
1396182291,
|
|
465
|
-
1695183700,
|
|
466
|
-
1986661051,
|
|
467
|
-
2177026350,
|
|
468
|
-
2456956037,
|
|
469
|
-
2730485921,
|
|
470
|
-
2820302411,
|
|
471
|
-
3259730800,
|
|
472
|
-
3345764771,
|
|
473
|
-
3516065817,
|
|
474
|
-
3600352804,
|
|
475
|
-
4094571909,
|
|
476
|
-
275423344,
|
|
477
|
-
430227734,
|
|
478
|
-
506948616,
|
|
479
|
-
659060556,
|
|
480
|
-
883997877,
|
|
481
|
-
958139571,
|
|
482
|
-
1322822218,
|
|
483
|
-
1537002063,
|
|
484
|
-
1747873779,
|
|
485
|
-
1955562222,
|
|
486
|
-
2024104815,
|
|
487
|
-
2227730452,
|
|
488
|
-
2361852424,
|
|
489
|
-
2428436474,
|
|
490
|
-
2756734187,
|
|
491
|
-
3204031479,
|
|
492
|
-
3329325298
|
|
493
|
-
]);
|
|
494
|
-
var UTF8_ENCODER = /* @__PURE__ */ new TextEncoder();
|
|
495
|
-
function sha256Hex(msg) {
|
|
496
|
-
const bytes = UTF8_ENCODER.encode(msg);
|
|
497
|
-
const msgLen = bytes.length;
|
|
498
|
-
const bitLen = msgLen * 8;
|
|
499
|
-
const totalLen = msgLen + 9 + 63 & ~63;
|
|
500
|
-
const padded = new Uint8Array(totalLen);
|
|
501
|
-
padded.set(bytes);
|
|
502
|
-
padded[msgLen] = 128;
|
|
503
|
-
const dv = new DataView(padded.buffer);
|
|
504
|
-
dv.setUint32(totalLen - 4, bitLen >>> 0, false);
|
|
505
|
-
dv.setUint32(totalLen - 8, Math.floor(bitLen / 4294967296) >>> 0, false);
|
|
506
|
-
let h0 = 1779033703;
|
|
507
|
-
let h1 = 3144134277;
|
|
508
|
-
let h2 = 1013904242;
|
|
509
|
-
let h3 = 2773480762;
|
|
510
|
-
let h4 = 1359893119;
|
|
511
|
-
let h5 = 2600822924;
|
|
512
|
-
let h6 = 528734635;
|
|
513
|
-
let h7 = 1541459225;
|
|
514
|
-
const W = new Uint32Array(64);
|
|
515
|
-
const rotr = (x, n) => x >>> n | x << 32 - n;
|
|
516
|
-
for (let off = 0; off < totalLen; off += 64) {
|
|
517
|
-
for (let i = 0; i < 16; i++) W[i] = dv.getUint32(off + i * 4, false);
|
|
518
|
-
for (let i = 16; i < 64; i++) {
|
|
519
|
-
const w15 = W[i - 15];
|
|
520
|
-
const w2 = W[i - 2];
|
|
521
|
-
const s0 = rotr(w15, 7) ^ rotr(w15, 18) ^ w15 >>> 3;
|
|
522
|
-
const s1 = rotr(w2, 17) ^ rotr(w2, 19) ^ w2 >>> 10;
|
|
523
|
-
W[i] = W[i - 16] + s0 + W[i - 7] + s1 >>> 0;
|
|
524
|
-
}
|
|
525
|
-
let a = h0;
|
|
526
|
-
let b = h1;
|
|
527
|
-
let c = h2;
|
|
528
|
-
let d = h3;
|
|
529
|
-
let e = h4;
|
|
530
|
-
let f = h5;
|
|
531
|
-
let g = h6;
|
|
532
|
-
let h = h7;
|
|
533
|
-
for (let i = 0; i < 64; i++) {
|
|
534
|
-
const S1 = rotr(e, 6) ^ rotr(e, 11) ^ rotr(e, 25);
|
|
535
|
-
const ch = e & f ^ ~e & g;
|
|
536
|
-
const t1 = h + S1 + ch + SHA256_K[i] + W[i] >>> 0;
|
|
537
|
-
const S0 = rotr(a, 2) ^ rotr(a, 13) ^ rotr(a, 22);
|
|
538
|
-
const mj = a & b ^ a & c ^ b & c;
|
|
539
|
-
const t2 = S0 + mj >>> 0;
|
|
540
|
-
h = g;
|
|
541
|
-
g = f;
|
|
542
|
-
f = e;
|
|
543
|
-
e = d + t1 >>> 0;
|
|
544
|
-
d = c;
|
|
545
|
-
c = b;
|
|
546
|
-
b = a;
|
|
547
|
-
a = t1 + t2 >>> 0;
|
|
548
|
-
}
|
|
549
|
-
h0 = h0 + a >>> 0;
|
|
550
|
-
h1 = h1 + b >>> 0;
|
|
551
|
-
h2 = h2 + c >>> 0;
|
|
552
|
-
h3 = h3 + d >>> 0;
|
|
553
|
-
h4 = h4 + e >>> 0;
|
|
554
|
-
h5 = h5 + f >>> 0;
|
|
555
|
-
h6 = h6 + g >>> 0;
|
|
556
|
-
h7 = h7 + h >>> 0;
|
|
557
|
-
}
|
|
558
|
-
const toHex = (x) => x.toString(16).padStart(8, "0");
|
|
559
|
-
return toHex(h0) + toHex(h1) + toHex(h2) + toHex(h3) + toHex(h4) + toHex(h5) + toHex(h6) + toHex(h7);
|
|
560
|
-
}
|
|
561
|
-
function defaultHash(value) {
|
|
562
|
-
const canonical = canonicalizeForHash(value ?? null);
|
|
563
|
-
const json = JSON.stringify(canonical);
|
|
564
|
-
return sha256Hex(json).slice(0, 16);
|
|
565
|
-
}
|
|
566
|
-
function randomUuid() {
|
|
567
|
-
const c = globalThis.crypto;
|
|
568
|
-
if (c?.randomUUID) return c.randomUUID();
|
|
569
|
-
const r = () => Math.floor(Math.random() * 4294967296).toString(16).padStart(8, "0");
|
|
570
|
-
const hex = r() + r() + r() + r();
|
|
571
|
-
return `${hex.slice(0, 8)}-${hex.slice(8, 12)}-4${hex.slice(13, 16)}-${(parseInt(hex.slice(16, 17), 16) & 3 | 8).toString(16)}${hex.slice(17, 20)}-${hex.slice(20, 32)}`;
|
|
572
|
-
}
|
|
573
|
-
function createVersioning(level, initialValue, opts) {
|
|
574
|
-
const id = opts?.id ?? randomUuid();
|
|
575
|
-
if (level === 0) {
|
|
576
|
-
return { id, version: 0 };
|
|
577
|
-
}
|
|
578
|
-
const hash = opts?.hash ?? defaultHash;
|
|
579
|
-
const cid = hash(initialValue);
|
|
580
|
-
return { id, version: 0, cid, prev: null };
|
|
581
|
-
}
|
|
582
|
-
function advanceVersion(info, newValue, hashFn) {
|
|
583
|
-
info.version += 1;
|
|
584
|
-
if ("cid" in info) {
|
|
585
|
-
info.prev = info.cid;
|
|
586
|
-
info.cid = hashFn(newValue);
|
|
587
|
-
}
|
|
588
|
-
}
|
|
589
|
-
|
|
590
|
-
// src/core/node.ts
|
|
591
|
-
var noopUnsub = () => {
|
|
592
|
-
};
|
|
593
|
-
var MAX_RERUN_DEPTH = 100;
|
|
594
|
-
function createDepRecord(n) {
|
|
595
|
-
return {
|
|
596
|
-
node: n,
|
|
597
|
-
unsub: null,
|
|
598
|
-
prevData: void 0,
|
|
599
|
-
dirty: false,
|
|
600
|
-
involvedThisWave: false,
|
|
601
|
-
dataBatch: [],
|
|
602
|
-
terminal: void 0
|
|
603
|
-
};
|
|
604
|
-
}
|
|
605
|
-
function resetDepRecord(d) {
|
|
606
|
-
d.prevData = void 0;
|
|
607
|
-
d.dirty = false;
|
|
608
|
-
d.involvedThisWave = false;
|
|
609
|
-
d.dataBatch.length = 0;
|
|
610
|
-
d.terminal = void 0;
|
|
611
|
-
}
|
|
612
|
-
function normalizeMessages(input) {
|
|
613
|
-
if (input.length === 0) return input;
|
|
614
|
-
return typeof input[0] === "symbol" ? [input] : input;
|
|
615
|
-
}
|
|
616
|
-
var defaultOnMessage = (node2, msg, ctx, _actions) => {
|
|
617
|
-
if (ctx.direction === "down-in") {
|
|
618
|
-
node2._onDepMessage(ctx.depIndex, msg);
|
|
619
|
-
}
|
|
620
|
-
return void 0;
|
|
621
|
-
};
|
|
622
|
-
var defaultOnSubscribe = (node2, sink, _ctx, _actions) => {
|
|
623
|
-
const impl = node2;
|
|
624
|
-
if (impl._status === "completed" || impl._status === "errored") return;
|
|
625
|
-
const cached = impl._cached;
|
|
626
|
-
const initial = cached === void 0 ? [START_MSG] : [START_MSG, [DATA, cached]];
|
|
627
|
-
if (impl._status === "dirty") initial.push(DIRTY_MSG);
|
|
628
|
-
downWithBatch(sink, initial, impl._config.tierOf);
|
|
629
|
-
};
|
|
630
|
-
var defaultConfig = new GraphReFlyConfig({
|
|
631
|
-
onMessage: defaultOnMessage,
|
|
632
|
-
onSubscribe: defaultOnSubscribe
|
|
633
|
-
});
|
|
634
|
-
registerBuiltins(defaultConfig);
|
|
635
|
-
registerBuiltinCodecs(defaultConfig);
|
|
636
|
-
var NodeImpl = class _NodeImpl {
|
|
637
|
-
// --- Identity ---
|
|
638
|
-
_optsName;
|
|
639
|
-
_describeKind;
|
|
640
|
-
meta;
|
|
641
|
-
/**
|
|
642
|
-
* Cached `Object.keys(meta).length > 0` check. `meta` is frozen at
|
|
643
|
-
* construction so this boolean never flips. Used by `_emit` to skip
|
|
644
|
-
* the meta TEARDOWN fan-out block allocation on the common "no meta"
|
|
645
|
-
* hot path.
|
|
646
|
-
*/
|
|
647
|
-
_hasMeta;
|
|
648
|
-
// --- Config ---
|
|
649
|
-
_config;
|
|
650
|
-
// --- Topology ---
|
|
651
|
-
/** Mutable for autoTrackNode / Graph.connect() post-construction dep addition. */
|
|
652
|
-
_deps;
|
|
653
|
-
_sinks = null;
|
|
654
|
-
_sinkCount = 0;
|
|
655
|
-
// --- State ---
|
|
656
|
-
_cached;
|
|
657
|
-
_status;
|
|
658
|
-
_cleanup;
|
|
659
|
-
_store = {};
|
|
660
|
-
_waveHasNewData = false;
|
|
661
|
-
_hasNewTerminal = false;
|
|
662
|
-
_hasCalledFnOnce = false;
|
|
663
|
-
_paused = false;
|
|
664
|
-
_pendingWave = false;
|
|
665
|
-
_isExecutingFn = false;
|
|
666
|
-
_pendingRerun = false;
|
|
667
|
-
_rerunDepth = 0;
|
|
668
|
-
// --- Settlement counter (A3) ---
|
|
669
|
-
/**
|
|
670
|
-
* Count of deps currently in `dirty === true`. `_maybeRunFnOnSettlement`
|
|
671
|
-
* treats `0` as "wave settled" — O(1) check for full dep settlement.
|
|
672
|
-
*/
|
|
673
|
-
_dirtyDepCount = 0;
|
|
674
|
-
// --- Per-batch emit accumulator (Bug 2: K+1 fan-in fix) ---
|
|
675
|
-
/**
|
|
676
|
-
* Inside an explicit `batch(() => ...)` scope, every `_emit` accumulates
|
|
677
|
-
* its already-framed messages here instead of dispatching synchronously.
|
|
678
|
-
* At batch end, `_flushBatchPending` runs (registered via
|
|
679
|
-
* `registerBatchFlushHook`) and delivers the whole accumulated batch as
|
|
680
|
-
* one `downWithBatch` call — collapsing what would otherwise be K
|
|
681
|
-
* separate sink invocations into one. This is the fix for the diamond
|
|
682
|
-
* fan-in K+1 over-fire.
|
|
683
|
-
*
|
|
684
|
-
* `null` outside batch (or after flush). Only ever appended to within
|
|
685
|
-
* a single explicit batch lifetime; reset to `null` on flush. State
|
|
686
|
-
* updates (cache, version, status) still happen per-emit via
|
|
687
|
-
* `_updateState` — only the downstream delivery is coalesced.
|
|
688
|
-
*/
|
|
689
|
-
_batchPendingMessages = null;
|
|
690
|
-
// --- PAUSE/RESUME lock tracking (C0) ---
|
|
691
|
-
/**
|
|
692
|
-
* Set of active pause locks held against this node. Every `[PAUSE, lockId]`
|
|
693
|
-
* adds its `lockId` to the set; every `[RESUME, lockId]` removes it.
|
|
694
|
-
* `_paused` is a derived quantity: `_pauseLocks.size > 0`. Multi-pauser
|
|
695
|
-
* correctness — one controller releasing its lock does NOT resume the
|
|
696
|
-
* node while another controller still holds its lock.
|
|
697
|
-
*/
|
|
698
|
-
_pauseLocks = null;
|
|
699
|
-
/**
|
|
700
|
-
* Buffered DATA messages held while paused. Only populated when
|
|
701
|
-
* `_pausable === "resumeAll"` (bufferAll mode). On final lock release
|
|
702
|
-
* the buffer is replayed through the node's outgoing pipeline in the
|
|
703
|
-
* order received. Non-bufferAll pause mode drops DATA on the floor
|
|
704
|
-
* (upstream is expected to honor PAUSE by suppressing production).
|
|
705
|
-
*/
|
|
706
|
-
_pauseBuffer = null;
|
|
707
|
-
// --- Options (frozen at construction) ---
|
|
708
|
-
_fn;
|
|
709
|
-
_equals;
|
|
710
|
-
_resubscribable;
|
|
711
|
-
_resetOnTeardown;
|
|
712
|
-
_autoComplete;
|
|
713
|
-
_autoError;
|
|
714
|
-
_pausable;
|
|
715
|
-
_guard;
|
|
716
|
-
/**
|
|
717
|
-
* @internal Additional guards stacked at runtime via {@link NodeImpl._pushGuard}
|
|
718
|
-
* (e.g. by `policyEnforcer({ mode: "enforce" })`, roadmap §9.2). Effective
|
|
719
|
-
* write/signal/observe checks AND the original `_guard` with every entry here.
|
|
720
|
-
*/
|
|
721
|
-
_extraGuards;
|
|
722
|
-
_hashFn;
|
|
723
|
-
_versioning;
|
|
724
|
-
/**
|
|
725
|
-
* Explicit versioning level, tracked separately from `_versioning` so
|
|
726
|
-
* monotonicity checks and future v2/v3 extensions don't rely on the
|
|
727
|
-
* fragile `"cid" in _versioning` shape discriminator. `undefined` means
|
|
728
|
-
* the node has no versioning attached; `0` / `1` / future levels name
|
|
729
|
-
* the tier. Mutated in lockstep with `_versioning` by the constructor
|
|
730
|
-
* and by `_applyVersioning`.
|
|
731
|
-
*/
|
|
732
|
-
_versioningLevel;
|
|
733
|
-
// --- ABAC ---
|
|
734
|
-
_lastMutation;
|
|
735
|
-
/**
|
|
736
|
-
* @internal Per-node inspector hooks for `Graph.observe(path,
|
|
737
|
-
* { causal, derived })`. Fires in `_onDepMessage` and `_execFn`.
|
|
738
|
-
* Attached via `_setInspectorHook` (returns a disposer). Multiple
|
|
739
|
-
* observers can attach simultaneously — all registered hooks fire for
|
|
740
|
-
* every event.
|
|
741
|
-
*/
|
|
742
|
-
_inspectorHooks;
|
|
743
|
-
// --- Actions (built once in the constructor) ---
|
|
744
|
-
_actions;
|
|
745
|
-
constructor(deps, fn, opts) {
|
|
746
|
-
this._config = opts.config ?? defaultConfig;
|
|
747
|
-
void this._config.onMessage;
|
|
748
|
-
this._optsName = opts.name;
|
|
749
|
-
this._describeKind = opts.describeKind;
|
|
750
|
-
this._equals = opts.equals ?? Object.is;
|
|
751
|
-
this._resubscribable = opts.resubscribable ?? false;
|
|
752
|
-
this._resetOnTeardown = opts.resetOnTeardown ?? false;
|
|
753
|
-
this._autoComplete = opts.completeWhenDepsComplete ?? true;
|
|
754
|
-
this._autoError = opts.errorWhenDepsError ?? true;
|
|
755
|
-
this._pausable = opts.pausable ?? true;
|
|
756
|
-
this._guard = opts.guard;
|
|
757
|
-
this._fn = fn;
|
|
758
|
-
this._cached = opts.initial !== void 0 ? opts.initial : void 0;
|
|
759
|
-
this._status = deps.length === 0 && fn == null && this._cached !== void 0 ? "settled" : "sentinel";
|
|
760
|
-
this._hashFn = opts.versioningHash ?? this._config.defaultHashFn ?? defaultHash;
|
|
761
|
-
const versioningLevel = opts.versioning ?? this._config.defaultVersioning;
|
|
762
|
-
this._versioningLevel = versioningLevel;
|
|
763
|
-
this._versioning = versioningLevel != null ? createVersioning(versioningLevel, this._cached === void 0 ? void 0 : this._cached, {
|
|
764
|
-
id: opts.versioningId,
|
|
765
|
-
hash: this._hashFn
|
|
766
|
-
}) : void 0;
|
|
767
|
-
this._deps = deps.map(createDepRecord);
|
|
768
|
-
const meta = {};
|
|
769
|
-
for (const [k, v] of Object.entries(opts.meta ?? {})) {
|
|
770
|
-
const metaOpts = {
|
|
771
|
-
initial: v,
|
|
772
|
-
name: `${opts.name ?? "node"}:meta:${k}`,
|
|
773
|
-
describeKind: "state",
|
|
774
|
-
config: this._config
|
|
775
|
-
};
|
|
776
|
-
if (opts.guard != null) metaOpts.guard = opts.guard;
|
|
777
|
-
meta[k] = new _NodeImpl([], void 0, metaOpts);
|
|
778
|
-
}
|
|
779
|
-
Object.freeze(meta);
|
|
780
|
-
this.meta = meta;
|
|
781
|
-
this._hasMeta = Object.keys(meta).length > 0;
|
|
782
|
-
const self = this;
|
|
783
|
-
this._actions = {
|
|
784
|
-
emit(value) {
|
|
785
|
-
self._emit([[DATA, value]]);
|
|
786
|
-
},
|
|
787
|
-
down(messageOrMessages) {
|
|
788
|
-
self._emit(normalizeMessages(messageOrMessages));
|
|
789
|
-
},
|
|
790
|
-
up(messageOrMessages) {
|
|
791
|
-
self._emitUp(normalizeMessages(messageOrMessages));
|
|
792
|
-
}
|
|
793
|
-
};
|
|
794
|
-
this.down = this.down.bind(this);
|
|
795
|
-
this.up = this.up.bind(this);
|
|
796
|
-
}
|
|
797
|
-
// --- Derived state ---
|
|
798
|
-
get _isTerminal() {
|
|
799
|
-
return this._status === "completed" || this._status === "errored";
|
|
800
|
-
}
|
|
801
|
-
// --- Public getters ---
|
|
802
|
-
get name() {
|
|
803
|
-
return this._optsName;
|
|
804
|
-
}
|
|
805
|
-
get status() {
|
|
806
|
-
return this._status;
|
|
807
|
-
}
|
|
808
|
-
get cache() {
|
|
809
|
-
return this._cached === void 0 ? void 0 : this._cached;
|
|
810
|
-
}
|
|
811
|
-
get lastMutation() {
|
|
812
|
-
return this._lastMutation;
|
|
813
|
-
}
|
|
814
|
-
get v() {
|
|
815
|
-
return this._versioning;
|
|
816
|
-
}
|
|
817
|
-
hasGuard() {
|
|
818
|
-
return this._guard != null;
|
|
819
|
-
}
|
|
820
|
-
/**
|
|
821
|
-
* @internal Retroactively attach (or upgrade) versioning state on this
|
|
822
|
-
* node. Intended for `Graph.setVersioning(level)` bulk application and
|
|
823
|
-
* for rare cases where a specific node needs to be bumped to a higher
|
|
824
|
-
* level (e.g., `v0 → v1`) after construction.
|
|
825
|
-
*
|
|
826
|
-
* **Safety:** the mutation is rejected mid-wave. Specifically,
|
|
827
|
-
* throws if the node is currently executing its fn (`_isExecutingFn`).
|
|
828
|
-
* Callers at quiescent points — before the first sink subscribes, or
|
|
829
|
-
* after all sinks unsubscribe, or between external `down()` / `emit()`
|
|
830
|
-
* invocations — are safe. The re-entrance window that motivated §10.6.4
|
|
831
|
-
* removal was the "transition `_versioning` from `undefined` to a fresh
|
|
832
|
-
* object mid-`_updateState`" case; that path is now guarded.
|
|
833
|
-
*
|
|
834
|
-
* **Monotonicity:** levels can only go up. Downgrade (e.g., `v1 → v0`)
|
|
835
|
-
* is a no-op — once a node carries higher-level metadata, dropping it
|
|
836
|
-
* mid-graph would tear the linked-history invariant for v1 and above.
|
|
837
|
-
*
|
|
838
|
-
* **Linked-history boundary (D1, 2026-04-13):** upgrading v0 → v1
|
|
839
|
-
* produces a **fresh history root**. The new v1 state has `cid =
|
|
840
|
-
* hash(currentCachedValue)` and `prev = null`, not a synthetic `prev`
|
|
841
|
-
* anchored to any previous v0 value. The v0 monotonic `version` counter
|
|
842
|
-
* is preserved across the upgrade, but the linked-cid chain (spec §7)
|
|
843
|
-
* starts fresh at the upgrade point. Downstream audit tools that walk
|
|
844
|
-
* `v.cid.prev` backwards through time will see a `null` boundary at
|
|
845
|
-
* the upgrade — **this is intentional**: v0 had no cid to link to, and
|
|
846
|
-
* fabricating one would lie about the hash. Callers that require an
|
|
847
|
-
* unbroken cid chain from birth must attach versioning at construction
|
|
848
|
-
* via `opts.versioning` or `config.defaultVersioning`, not retroactively.
|
|
849
|
-
*
|
|
850
|
-
* @param level - New minimum versioning level.
|
|
851
|
-
* @param opts - Optional id / hash overrides; applied only if the
|
|
852
|
-
* node currently has no versioning state.
|
|
853
|
-
*/
|
|
854
|
-
_applyVersioning(level, opts) {
|
|
855
|
-
if (this._isExecutingFn) {
|
|
856
|
-
throw new Error(
|
|
857
|
-
`Node "${this.name}": _applyVersioning cannot run mid-fn \u2014 call it outside of \`_execFn\` (typically at graph setup time before the first subscribe).`
|
|
858
|
-
);
|
|
859
|
-
}
|
|
860
|
-
const currentLevel = this._versioningLevel;
|
|
861
|
-
if (currentLevel != null && level <= currentLevel) {
|
|
862
|
-
return;
|
|
863
|
-
}
|
|
864
|
-
const hash = opts?.hash ?? this._hashFn;
|
|
865
|
-
if (hash !== this._hashFn) this._hashFn = hash;
|
|
866
|
-
const initialValue = this._cached === void 0 ? void 0 : this._cached;
|
|
867
|
-
const current = this._versioning;
|
|
868
|
-
const preservedId = current?.id ?? opts?.id;
|
|
869
|
-
const preservedVersion = current?.version ?? 0;
|
|
870
|
-
const fresh = createVersioning(level, initialValue, {
|
|
871
|
-
id: preservedId,
|
|
872
|
-
hash
|
|
873
|
-
});
|
|
874
|
-
fresh.version = preservedVersion;
|
|
875
|
-
this._versioning = fresh;
|
|
876
|
-
this._versioningLevel = level;
|
|
877
|
-
}
|
|
878
|
-
/**
|
|
879
|
-
* @internal Attach an inspector hook. Returns a disposer that removes
|
|
880
|
-
* the hook. Used by `Graph.observe(path, { causal, derived })` to build
|
|
881
|
-
* causal traces. Multiple hooks may be attached concurrently — all fire
|
|
882
|
-
* for every event in registration order. Passing `undefined` is a no-op
|
|
883
|
-
* and returns a no-op disposer.
|
|
884
|
-
*/
|
|
885
|
-
_setInspectorHook(hook) {
|
|
886
|
-
if (hook == null) return () => {
|
|
887
|
-
};
|
|
888
|
-
if (this._inspectorHooks == null) this._inspectorHooks = /* @__PURE__ */ new Set();
|
|
889
|
-
this._inspectorHooks.add(hook);
|
|
890
|
-
return () => {
|
|
891
|
-
this._inspectorHooks?.delete(hook);
|
|
892
|
-
if (this._inspectorHooks?.size === 0) this._inspectorHooks = void 0;
|
|
893
|
-
};
|
|
894
|
-
}
|
|
895
|
-
/**
|
|
896
|
-
* @internal Push an additional guard onto this node. Effective enforcement
|
|
897
|
-
* is the AND of `_guard` and every guard pushed via this hook — any one
|
|
898
|
-
* rejecting throws {@link GuardDenied}. Returns a disposer that removes
|
|
899
|
-
* the pushed guard. Multiple guards may be stacked simultaneously.
|
|
900
|
-
*
|
|
901
|
-
* Used by `policyEnforcer({ mode: "enforce" })` (roadmap §9.2) to overlay
|
|
902
|
-
* runtime constraint enforcement onto an existing graph without rebuilding
|
|
903
|
-
* its nodes. Pre-1.0 internal API; not part of the public surface.
|
|
904
|
-
*
|
|
905
|
-
* **Identity semantics:** guards are tracked in a `Set`, so pushing the
|
|
906
|
-
* same `NodeGuard` reference twice is a single registration. Wrap each
|
|
907
|
-
* push in a unique closure if independent stacking is needed.
|
|
908
|
-
*
|
|
909
|
-
* **Iteration order:** insertion-ordered (`Set` semantics). Determinism
|
|
910
|
-
* follows from single-threaded JS execution; nested re-entry from inside
|
|
911
|
-
* a guard body (push/pop while iterating) is undefined-but-survivable.
|
|
912
|
-
*/
|
|
913
|
-
_pushGuard(guard) {
|
|
914
|
-
if (this._extraGuards == null) this._extraGuards = /* @__PURE__ */ new Set();
|
|
915
|
-
this._extraGuards.add(guard);
|
|
916
|
-
return () => {
|
|
917
|
-
this._extraGuards?.delete(guard);
|
|
918
|
-
if (this._extraGuards?.size === 0) this._extraGuards = void 0;
|
|
919
|
-
};
|
|
920
|
-
}
|
|
921
|
-
allowsObserve(actor) {
|
|
922
|
-
if (this._guard == null && this._extraGuards == null) return true;
|
|
923
|
-
const a = normalizeActor(actor);
|
|
924
|
-
if (this._guard != null && !this._guard(a, "observe")) return false;
|
|
925
|
-
if (this._extraGuards != null) {
|
|
926
|
-
for (const eg of this._extraGuards) {
|
|
927
|
-
if (!eg(a, "observe")) return false;
|
|
928
|
-
}
|
|
929
|
-
}
|
|
930
|
-
return true;
|
|
931
|
-
}
|
|
932
|
-
// --- Guard helper ---
|
|
933
|
-
_checkGuard(options) {
|
|
934
|
-
if (options?.internal) return;
|
|
935
|
-
const hasGuard = this._guard != null || this._extraGuards != null;
|
|
936
|
-
const hasActor = options?.actor != null;
|
|
937
|
-
if (!hasGuard && !hasActor) return;
|
|
938
|
-
const actor = normalizeActor(options?.actor);
|
|
939
|
-
const action = options?.delivery === "signal" ? "signal" : "write";
|
|
940
|
-
if (this._guard != null && !this._guard(actor, action)) {
|
|
941
|
-
throw new GuardDenied({ actor, action, nodeName: this.name });
|
|
942
|
-
}
|
|
943
|
-
if (this._extraGuards != null) {
|
|
944
|
-
for (const eg of this._extraGuards) {
|
|
945
|
-
if (!eg(actor, action)) {
|
|
946
|
-
throw new GuardDenied({ actor, action, nodeName: this.name });
|
|
947
|
-
}
|
|
948
|
-
}
|
|
949
|
-
}
|
|
950
|
-
this._lastMutation = { actor, timestamp_ns: wallClockNs() };
|
|
951
|
-
}
|
|
952
|
-
// --- Public transport ---
|
|
953
|
-
down(messageOrMessages, options) {
|
|
954
|
-
const messages = normalizeMessages(messageOrMessages);
|
|
955
|
-
if (messages.length === 0) return;
|
|
956
|
-
this._checkGuard(options);
|
|
957
|
-
this._emit(messages);
|
|
958
|
-
}
|
|
959
|
-
emit(value, options) {
|
|
960
|
-
this._checkGuard(options);
|
|
961
|
-
this._emit([[DATA, value]]);
|
|
962
|
-
}
|
|
963
|
-
up(messageOrMessages, options) {
|
|
964
|
-
if (this._deps.length === 0) return;
|
|
965
|
-
const messages = normalizeMessages(messageOrMessages);
|
|
966
|
-
if (messages.length === 0) return;
|
|
967
|
-
this._checkGuard(options);
|
|
968
|
-
const forwardOpts = options ?? { internal: true };
|
|
969
|
-
this._validateUpTiers(messages);
|
|
970
|
-
for (const d of this._deps) {
|
|
971
|
-
d.node.up?.(messages, forwardOpts);
|
|
972
|
-
}
|
|
973
|
-
}
|
|
974
|
-
/**
|
|
975
|
-
* @internal Internal up-path used by `actions.up(...)` from inside fn.
|
|
976
|
-
* Same tier validation as public `up`, but bypasses the guard check
|
|
977
|
-
* since the fn context is already inside an authorized operation.
|
|
978
|
-
*/
|
|
979
|
-
_emitUp(messages) {
|
|
980
|
-
if (this._deps.length === 0) return;
|
|
981
|
-
if (messages.length === 0) return;
|
|
982
|
-
this._validateUpTiers(messages);
|
|
983
|
-
for (const d of this._deps) {
|
|
984
|
-
d.node.up?.(messages, { internal: true });
|
|
985
|
-
}
|
|
986
|
-
}
|
|
987
|
-
/**
|
|
988
|
-
* @internal Enforce spec §1.2 — up-direction messages are restricted to
|
|
989
|
-
* tier 0–2 and tier 5 (START, DIRTY, INVALIDATE, PAUSE, RESUME,
|
|
990
|
-
* TEARDOWN). Tier 3 (DATA/RESOLVED) and tier 4 (COMPLETE/ERROR) are
|
|
991
|
-
* downstream-only. Emitting tier-3/4 via `up` would bypass equals
|
|
992
|
-
* substitution and cache advance entirely and is a protocol bug.
|
|
993
|
-
*/
|
|
994
|
-
_validateUpTiers(messages) {
|
|
995
|
-
const tierOf = this._config.tierOf;
|
|
996
|
-
for (const m of messages) {
|
|
997
|
-
const tier = tierOf(m[0]);
|
|
998
|
-
if (tier === 3 || tier === 4) {
|
|
999
|
-
throw new Error(
|
|
1000
|
-
`Node "${this.name}": tier-${tier} 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).`
|
|
1001
|
-
);
|
|
1002
|
-
}
|
|
1003
|
-
}
|
|
1004
|
-
}
|
|
1005
|
-
subscribe(sink, actor) {
|
|
1006
|
-
if (actor != null && this._guard != null) {
|
|
1007
|
-
const a = normalizeActor(actor);
|
|
1008
|
-
if (!this._guard(a, "observe")) {
|
|
1009
|
-
throw new GuardDenied({ actor: a, action: "observe", nodeName: this.name });
|
|
1010
|
-
}
|
|
1011
|
-
}
|
|
1012
|
-
const wasTerminal = this._isTerminal;
|
|
1013
|
-
const afterTerminalReset = wasTerminal && this._resubscribable;
|
|
1014
|
-
if (afterTerminalReset) {
|
|
1015
|
-
this._cached = void 0;
|
|
1016
|
-
this._status = "sentinel";
|
|
1017
|
-
this._store = {};
|
|
1018
|
-
this._hasCalledFnOnce = false;
|
|
1019
|
-
this._waveHasNewData = false;
|
|
1020
|
-
this._hasNewTerminal = false;
|
|
1021
|
-
this._paused = false;
|
|
1022
|
-
this._pendingWave = false;
|
|
1023
|
-
this._pendingRerun = false;
|
|
1024
|
-
this._isExecutingFn = false;
|
|
1025
|
-
this._rerunDepth = 0;
|
|
1026
|
-
this._dirtyDepCount = 0;
|
|
1027
|
-
this._pauseLocks = null;
|
|
1028
|
-
this._pauseBuffer = null;
|
|
1029
|
-
for (const d of this._deps) resetDepRecord(d);
|
|
1030
|
-
}
|
|
1031
|
-
this._sinkCount += 1;
|
|
1032
|
-
let subCleanup;
|
|
1033
|
-
try {
|
|
1034
|
-
subCleanup = this._config.onSubscribe(
|
|
1035
|
-
this,
|
|
1036
|
-
sink,
|
|
1037
|
-
{ sinkCount: this._sinkCount, afterTerminalReset },
|
|
1038
|
-
this._actions
|
|
1039
|
-
);
|
|
1040
|
-
} catch (err) {
|
|
1041
|
-
this._sinkCount -= 1;
|
|
1042
|
-
throw err;
|
|
1043
|
-
}
|
|
1044
|
-
if (this._sinks == null) {
|
|
1045
|
-
this._sinks = sink;
|
|
1046
|
-
} else if (typeof this._sinks === "function") {
|
|
1047
|
-
this._sinks = /* @__PURE__ */ new Set([this._sinks, sink]);
|
|
1048
|
-
} else {
|
|
1049
|
-
this._sinks.add(sink);
|
|
1050
|
-
}
|
|
1051
|
-
const isTerminalNow = this._isTerminal;
|
|
1052
|
-
if (this._sinkCount === 1 && !isTerminalNow) {
|
|
1053
|
-
try {
|
|
1054
|
-
this._activate();
|
|
1055
|
-
} catch (err) {
|
|
1056
|
-
this._sinkCount -= 1;
|
|
1057
|
-
this._removeSink(sink);
|
|
1058
|
-
if (this._sinkCount === 0) this._status = "sentinel";
|
|
1059
|
-
if (typeof subCleanup === "function") {
|
|
1060
|
-
try {
|
|
1061
|
-
subCleanup();
|
|
1062
|
-
} catch {
|
|
1063
|
-
}
|
|
1064
|
-
}
|
|
1065
|
-
throw err;
|
|
1066
|
-
}
|
|
1067
|
-
}
|
|
1068
|
-
if (this._status === "sentinel" && this._cached === void 0) {
|
|
1069
|
-
this._status = "pending";
|
|
1070
|
-
}
|
|
1071
|
-
let removed = false;
|
|
1072
|
-
return () => {
|
|
1073
|
-
if (removed) return;
|
|
1074
|
-
removed = true;
|
|
1075
|
-
this._sinkCount -= 1;
|
|
1076
|
-
this._removeSink(sink);
|
|
1077
|
-
if (typeof subCleanup === "function") subCleanup();
|
|
1078
|
-
if (this._sinks == null) this._deactivate();
|
|
1079
|
-
};
|
|
1080
|
-
}
|
|
1081
|
-
_removeSink(sink) {
|
|
1082
|
-
if (this._sinks === sink) {
|
|
1083
|
-
this._sinks = null;
|
|
1084
|
-
} else if (this._sinks != null && typeof this._sinks !== "function") {
|
|
1085
|
-
this._sinks.delete(sink);
|
|
1086
|
-
if (this._sinks.size === 1) {
|
|
1087
|
-
const [only] = this._sinks;
|
|
1088
|
-
this._sinks = only;
|
|
1089
|
-
} else if (this._sinks.size === 0) {
|
|
1090
|
-
this._sinks = null;
|
|
1091
|
-
}
|
|
1092
|
-
}
|
|
1093
|
-
}
|
|
1094
|
-
// --- Lifecycle ---
|
|
1095
|
-
/**
|
|
1096
|
-
* @internal First-sink activation. For a producer (no deps + fn),
|
|
1097
|
-
* invokes fn once. For a compute node (has deps), subscribes to every
|
|
1098
|
-
* dep with the pre-set-dirty trick so the first-run gate waits for
|
|
1099
|
-
* every dep to settle at least once.
|
|
1100
|
-
*/
|
|
1101
|
-
_activate() {
|
|
1102
|
-
if (this._deps.length === 0) {
|
|
1103
|
-
if (this._fn) this._execFn();
|
|
1104
|
-
return;
|
|
1105
|
-
}
|
|
1106
|
-
this._dirtyDepCount = 0;
|
|
1107
|
-
const initialLen = this._deps.length;
|
|
1108
|
-
let subscribedCount = 0;
|
|
1109
|
-
try {
|
|
1110
|
-
for (let i = 0; i < initialLen; i++) {
|
|
1111
|
-
const depIdx = i;
|
|
1112
|
-
const dep = this._deps[i];
|
|
1113
|
-
dep.unsub = noopUnsub;
|
|
1114
|
-
dep.unsub = dep.node.subscribe((msgs) => {
|
|
1115
|
-
if (dep.unsub === null) return;
|
|
1116
|
-
const tierOf = this._config.tierOf;
|
|
1117
|
-
let sawSettlement = false;
|
|
1118
|
-
for (const m of msgs) {
|
|
1119
|
-
if (tierOf(m[0]) >= 3) sawSettlement = true;
|
|
1120
|
-
this._config.onMessage(
|
|
1121
|
-
this,
|
|
1122
|
-
m,
|
|
1123
|
-
{ direction: "down-in", depIndex: depIdx },
|
|
1124
|
-
this._actions
|
|
1125
|
-
);
|
|
1126
|
-
}
|
|
1127
|
-
if (sawSettlement) this._maybeRunFnOnSettlement();
|
|
1128
|
-
});
|
|
1129
|
-
subscribedCount++;
|
|
1130
|
-
}
|
|
1131
|
-
} catch (err) {
|
|
1132
|
-
this._deps[subscribedCount].unsub = null;
|
|
1133
|
-
for (let j = 0; j < subscribedCount; j++) {
|
|
1134
|
-
const d = this._deps[j];
|
|
1135
|
-
if (d.unsub != null) {
|
|
1136
|
-
const u = d.unsub;
|
|
1137
|
-
d.unsub = null;
|
|
1138
|
-
try {
|
|
1139
|
-
u();
|
|
1140
|
-
} catch {
|
|
1141
|
-
}
|
|
1142
|
-
resetDepRecord(d);
|
|
1143
|
-
}
|
|
1144
|
-
}
|
|
1145
|
-
this._dirtyDepCount = 0;
|
|
1146
|
-
throw err;
|
|
1147
|
-
}
|
|
1148
|
-
}
|
|
1149
|
-
/**
|
|
1150
|
-
* @internal Append a dep post-construction. Used by `autoTrackNode`
|
|
1151
|
-
* (runtime dep discovery) and `Graph.connect()` (post-construction
|
|
1152
|
-
* wiring). Subscribes immediately — if DATA arrives synchronously
|
|
1153
|
-
* during subscribe and fn is currently executing, the re-run is
|
|
1154
|
-
* deferred via `_pendingRerun` flag (see `_execFn` guard).
|
|
1155
|
-
*
|
|
1156
|
-
* **Dedup:** idempotent on duplicate `depNode` — if `depNode` is
|
|
1157
|
-
* already in `_deps`, returns the existing index without mutating
|
|
1158
|
-
* state. Callers can safely invoke `_addDep` without their own
|
|
1159
|
-
* "already added" check. `autoTrackNode` still keeps a `depIndexMap`
|
|
1160
|
-
* as a fast-path lookup for known deps (returning cached `data[idx]`
|
|
1161
|
-
* without calling `_addDep` at all); this internal dedup is the
|
|
1162
|
-
* backstop for any caller that doesn't track its own dep set.
|
|
1163
|
-
*
|
|
1164
|
-
* @returns The index of the new dep in `_deps`, or the existing index
|
|
1165
|
-
* if the dep was already present.
|
|
1166
|
-
*/
|
|
1167
|
-
_addDep(depNode) {
|
|
1168
|
-
for (let i = 0; i < this._deps.length; i++) {
|
|
1169
|
-
if (this._deps[i].node === depNode) return i;
|
|
1170
|
-
}
|
|
1171
|
-
const depIdx = this._deps.length;
|
|
1172
|
-
const record = createDepRecord(depNode);
|
|
1173
|
-
this._deps.push(record);
|
|
1174
|
-
if (this._sinks == null) return depIdx;
|
|
1175
|
-
record.dirty = true;
|
|
1176
|
-
this._dirtyDepCount++;
|
|
1177
|
-
if (this._status !== "dirty") this._emit(DIRTY_ONLY_BATCH);
|
|
1178
|
-
record.unsub = noopUnsub;
|
|
1179
|
-
try {
|
|
1180
|
-
record.unsub = depNode.subscribe((msgs) => {
|
|
1181
|
-
if (record.unsub === null) return;
|
|
1182
|
-
const tierOf = this._config.tierOf;
|
|
1183
|
-
let sawSettlement = false;
|
|
1184
|
-
for (const m of msgs) {
|
|
1185
|
-
if (tierOf(m[0]) >= 3) sawSettlement = true;
|
|
1186
|
-
this._config.onMessage(
|
|
1187
|
-
this,
|
|
1188
|
-
m,
|
|
1189
|
-
{ direction: "down-in", depIndex: depIdx },
|
|
1190
|
-
this._actions
|
|
1191
|
-
);
|
|
1192
|
-
}
|
|
1193
|
-
if (sawSettlement) this._maybeRunFnOnSettlement();
|
|
1194
|
-
});
|
|
1195
|
-
} catch (err) {
|
|
1196
|
-
record.unsub = null;
|
|
1197
|
-
this._deps.pop();
|
|
1198
|
-
this._dirtyDepCount--;
|
|
1199
|
-
throw err;
|
|
1200
|
-
}
|
|
1201
|
-
return depIdx;
|
|
1202
|
-
}
|
|
1203
|
-
/**
|
|
1204
|
-
* @internal Unsubscribes from deps, fires fn cleanup (both shapes),
|
|
1205
|
-
* clears wave/store state, and (for compute nodes) drops `_cached` per
|
|
1206
|
-
* the ROM/RAM rule. Idempotent: second call is a no-op.
|
|
1207
|
-
*
|
|
1208
|
-
* @param skipStatusUpdate — When `true`, the caller takes responsibility
|
|
1209
|
-
* for setting `_status` after deactivation (e.g. TEARDOWN always sets
|
|
1210
|
-
* `"sentinel"` unconditionally). When `false` (default), deactivation
|
|
1211
|
-
* applies the ROM rule: compute nodes → `"sentinel"`, state nodes
|
|
1212
|
-
* preserve their current status.
|
|
1213
|
-
*/
|
|
1214
|
-
_deactivate(skipStatusUpdate = false) {
|
|
1215
|
-
const cleanup = this._cleanup;
|
|
1216
|
-
this._cleanup = void 0;
|
|
1217
|
-
if (typeof cleanup === "function") {
|
|
1218
|
-
try {
|
|
1219
|
-
cleanup();
|
|
1220
|
-
} catch (err) {
|
|
1221
|
-
this._emit([[ERROR, this._wrapFnError("cleanup threw", err)]]);
|
|
1222
|
-
}
|
|
1223
|
-
} else if (cleanup != null && typeof cleanup.deactivation === "function") {
|
|
1224
|
-
try {
|
|
1225
|
-
cleanup.deactivation();
|
|
1226
|
-
} catch (err) {
|
|
1227
|
-
this._emit([[ERROR, this._wrapFnError("cleanup.deactivation threw", err)]]);
|
|
1228
|
-
}
|
|
1229
|
-
}
|
|
1230
|
-
for (const d of this._deps) {
|
|
1231
|
-
if (d.unsub != null) {
|
|
1232
|
-
const u = d.unsub;
|
|
1233
|
-
d.unsub = null;
|
|
1234
|
-
try {
|
|
1235
|
-
u();
|
|
1236
|
-
} catch {
|
|
1237
|
-
}
|
|
1238
|
-
}
|
|
1239
|
-
resetDepRecord(d);
|
|
1240
|
-
}
|
|
1241
|
-
this._waveHasNewData = false;
|
|
1242
|
-
this._hasNewTerminal = false;
|
|
1243
|
-
this._hasCalledFnOnce = false;
|
|
1244
|
-
this._paused = false;
|
|
1245
|
-
this._pendingWave = false;
|
|
1246
|
-
this._pendingRerun = false;
|
|
1247
|
-
this._rerunDepth = 0;
|
|
1248
|
-
this._store = {};
|
|
1249
|
-
this._dirtyDepCount = 0;
|
|
1250
|
-
this._pauseLocks = null;
|
|
1251
|
-
this._pauseBuffer = null;
|
|
1252
|
-
if (this._fn != null) {
|
|
1253
|
-
this._cached = void 0;
|
|
1254
|
-
}
|
|
1255
|
-
if (!skipStatusUpdate) {
|
|
1256
|
-
if (this._fn != null || this._deps.length > 0) {
|
|
1257
|
-
if (!this._isTerminal || this._resubscribable) {
|
|
1258
|
-
this._status = "sentinel";
|
|
1259
|
-
}
|
|
1260
|
-
}
|
|
1261
|
-
}
|
|
1262
|
-
}
|
|
1263
|
-
// --- Dep message dispatch (§3.5 singleton default) ---
|
|
1264
|
-
/**
|
|
1265
|
-
* @internal Default per-tier dispatch for incoming dep messages. Called
|
|
1266
|
-
* by `defaultOnMessage`. Updates the DepRecord, triggers wave
|
|
1267
|
-
* completion, and forwards passthrough traffic.
|
|
1268
|
-
*/
|
|
1269
|
-
_onDepMessage(depIndex, msg) {
|
|
1270
|
-
const dep = this._deps[depIndex];
|
|
1271
|
-
const t = msg[0];
|
|
1272
|
-
if (this._inspectorHooks != null) {
|
|
1273
|
-
const ev = { kind: "dep_message", depIndex, message: msg };
|
|
1274
|
-
for (const hook of this._inspectorHooks) hook(ev);
|
|
1275
|
-
}
|
|
1276
|
-
if (t === START) return;
|
|
1277
|
-
if (t === DIRTY) {
|
|
1278
|
-
this._depDirtied(dep);
|
|
1279
|
-
return;
|
|
1280
|
-
}
|
|
1281
|
-
if (t === INVALIDATE) {
|
|
1282
|
-
this._depInvalidated(dep);
|
|
1283
|
-
this._emit(INVALIDATE_ONLY_BATCH);
|
|
1284
|
-
return;
|
|
1285
|
-
}
|
|
1286
|
-
if (t === PAUSE || t === RESUME) {
|
|
1287
|
-
this._emit([msg]);
|
|
1288
|
-
return;
|
|
1289
|
-
}
|
|
1290
|
-
if (t === TEARDOWN) {
|
|
1291
|
-
this._emit(TEARDOWN_ONLY_BATCH);
|
|
1292
|
-
return;
|
|
1293
|
-
}
|
|
1294
|
-
if (t === DATA) {
|
|
1295
|
-
this._depSettledAsData(dep, msg[1]);
|
|
1296
|
-
} else if (t === RESOLVED) {
|
|
1297
|
-
this._depSettledAsResolved(dep);
|
|
1298
|
-
} else if (t === COMPLETE) {
|
|
1299
|
-
this._depSettledAsTerminal(dep, true);
|
|
1300
|
-
} else if (t === ERROR) {
|
|
1301
|
-
this._depSettledAsTerminal(dep, msg[1]);
|
|
1302
|
-
} else {
|
|
1303
|
-
this._emit([msg]);
|
|
1304
|
-
return;
|
|
1305
|
-
}
|
|
1306
|
-
if (!this._fn) {
|
|
1307
|
-
if (t === DATA || t === RESOLVED) {
|
|
1308
|
-
this._emit([msg]);
|
|
1309
|
-
}
|
|
1310
|
-
if (t === COMPLETE || t === ERROR) {
|
|
1311
|
-
this._maybeAutoTerminalAfterWave();
|
|
1312
|
-
}
|
|
1313
|
-
return;
|
|
1314
|
-
}
|
|
1315
|
-
}
|
|
1316
|
-
// --- Centralized dep-state transitions (A3 settlement counters) ---
|
|
1317
|
-
//
|
|
1318
|
-
// Every mutation to `DepRecord.dirty` / `DepRecord.prevData` /
|
|
1319
|
-
// `DepRecord.terminal` must go through one of these helpers so the
|
|
1320
|
-
// `_dirtyDepCount` and `_sentinelDepCount` counters stay in sync with
|
|
1321
|
-
// the per-record flags. `_maybeRunFnOnSettlement` reads the counters
|
|
1322
|
-
// and never re-scans the `_deps` array.
|
|
1323
|
-
/**
|
|
1324
|
-
* Called when a dep transitions `dirty: false → true` (either from an
|
|
1325
|
-
* incoming DIRTY, or pre-set during `_activate` / `_addDep` /
|
|
1326
|
-
* `_depInvalidated`). No-op if the dep is already dirty. Fires the
|
|
1327
|
-
* downstream DIRTY emit if we're the first to dirty this wave.
|
|
1328
|
-
*/
|
|
1329
|
-
_depDirtied(dep) {
|
|
1330
|
-
if (dep.dirty) return;
|
|
1331
|
-
dep.dirty = true;
|
|
1332
|
-
dep.involvedThisWave = true;
|
|
1333
|
-
this._dirtyDepCount++;
|
|
1334
|
-
if (this._status !== "dirty") {
|
|
1335
|
-
this._emit(DIRTY_ONLY_BATCH);
|
|
1336
|
-
}
|
|
1337
|
-
}
|
|
1338
|
-
/**
|
|
1339
|
-
* Called when a dep delivers new DATA: clears dirty, stores the payload,
|
|
1340
|
-
* marks wave-has-data, and — if this is the dep's first DATA — clears
|
|
1341
|
-
* its sentinel slot so the first-run gate can open.
|
|
1342
|
-
*/
|
|
1343
|
-
_depSettledAsData(dep, value) {
|
|
1344
|
-
if (dep.dirty) {
|
|
1345
|
-
dep.dirty = false;
|
|
1346
|
-
this._dirtyDepCount--;
|
|
1347
|
-
}
|
|
1348
|
-
dep.involvedThisWave = true;
|
|
1349
|
-
dep.dataBatch.push(value);
|
|
1350
|
-
this._waveHasNewData = true;
|
|
1351
|
-
}
|
|
1352
|
-
/**
|
|
1353
|
-
* Called when a dep emits RESOLVED (wave settled, value unchanged).
|
|
1354
|
-
* Clears dirty; does NOT touch `prevData` / `terminal` / sentinel
|
|
1355
|
-
* count — sentinel only exits on first DATA or terminal, not RESOLVED.
|
|
1356
|
-
*/
|
|
1357
|
-
_depSettledAsResolved(dep) {
|
|
1358
|
-
if (dep.dirty) {
|
|
1359
|
-
dep.dirty = false;
|
|
1360
|
-
this._dirtyDepCount--;
|
|
1361
|
-
}
|
|
1362
|
-
}
|
|
1363
|
-
/**
|
|
1364
|
-
* Called when a dep delivers COMPLETE (`terminal = true`) or ERROR
|
|
1365
|
-
* (`terminal = errorPayload`). Clears dirty, stores the terminal, and
|
|
1366
|
-
* — if the dep had never contributed a DATA yet — leaves sentinel
|
|
1367
|
-
* since the gate treats "terminated without data" as gate-open too.
|
|
1368
|
-
*/
|
|
1369
|
-
_depSettledAsTerminal(dep, terminal) {
|
|
1370
|
-
if (dep.dirty) {
|
|
1371
|
-
dep.dirty = false;
|
|
1372
|
-
this._dirtyDepCount--;
|
|
1373
|
-
}
|
|
1374
|
-
dep.terminal = terminal;
|
|
1375
|
-
dep.involvedThisWave = true;
|
|
1376
|
-
this._hasNewTerminal = true;
|
|
1377
|
-
}
|
|
1378
|
-
/**
|
|
1379
|
-
* Called when a dep emits INVALIDATE: clears prevData, terminal, and
|
|
1380
|
-
* dataBatch. The dep is now back in the "never delivered a real value"
|
|
1381
|
-
* state — `prevData === undefined` so the sentinel check in fn will fire.
|
|
1382
|
-
*/
|
|
1383
|
-
_depInvalidated(dep) {
|
|
1384
|
-
dep.prevData = void 0;
|
|
1385
|
-
dep.terminal = void 0;
|
|
1386
|
-
dep.dataBatch.length = 0;
|
|
1387
|
-
if (!dep.dirty) {
|
|
1388
|
-
dep.dirty = true;
|
|
1389
|
-
dep.involvedThisWave = true;
|
|
1390
|
-
this._dirtyDepCount++;
|
|
1391
|
-
} else {
|
|
1392
|
-
dep.involvedThisWave = false;
|
|
1393
|
-
}
|
|
1394
|
-
}
|
|
1395
|
-
_maybeRunFnOnSettlement() {
|
|
1396
|
-
if (this._isTerminal && !this._resubscribable) return;
|
|
1397
|
-
if (this._dirtyDepCount > 0) return;
|
|
1398
|
-
if (this._paused) {
|
|
1399
|
-
this._pendingWave = true;
|
|
1400
|
-
return;
|
|
1401
|
-
}
|
|
1402
|
-
if (!this._waveHasNewData && !this._hasNewTerminal && this._hasCalledFnOnce) {
|
|
1403
|
-
this._clearWaveFlags();
|
|
1404
|
-
this._emit(RESOLVED_ONLY_BATCH);
|
|
1405
|
-
this._maybeAutoTerminalAfterWave();
|
|
1406
|
-
return;
|
|
1407
|
-
}
|
|
1408
|
-
if (this._fn) this._execFn();
|
|
1409
|
-
this._maybeAutoTerminalAfterWave();
|
|
1410
|
-
}
|
|
1411
|
-
_maybeAutoTerminalAfterWave() {
|
|
1412
|
-
if (this._deps.length === 0) return;
|
|
1413
|
-
if (this._isTerminal) return;
|
|
1414
|
-
const erroredDep = this._deps.find((d) => d.terminal !== void 0 && d.terminal !== true);
|
|
1415
|
-
if (erroredDep != null) {
|
|
1416
|
-
if (this._autoError) {
|
|
1417
|
-
this._emit([[ERROR, erroredDep.terminal]]);
|
|
1418
|
-
}
|
|
1419
|
-
return;
|
|
1420
|
-
}
|
|
1421
|
-
if (this._autoComplete && this._deps.every((d) => d.terminal !== void 0)) {
|
|
1422
|
-
this._emit(COMPLETE_ONLY_BATCH);
|
|
1423
|
-
}
|
|
1424
|
-
}
|
|
1425
|
-
// --- Fn execution ---
|
|
1426
|
-
/**
|
|
1427
|
-
* @internal Runs the node fn once. Default cleanup (function form) fires
|
|
1428
|
-
* before the new run; `{ deactivation }` cleanup survives.
|
|
1429
|
-
*/
|
|
1430
|
-
_execFn() {
|
|
1431
|
-
if (!this._fn) return;
|
|
1432
|
-
if (this._isTerminal && !this._resubscribable) return;
|
|
1433
|
-
if (this._isExecutingFn) {
|
|
1434
|
-
this._pendingRerun = true;
|
|
1435
|
-
return;
|
|
1436
|
-
}
|
|
1437
|
-
const prevCleanup = this._cleanup;
|
|
1438
|
-
if (typeof prevCleanup === "function") {
|
|
1439
|
-
this._cleanup = void 0;
|
|
1440
|
-
try {
|
|
1441
|
-
prevCleanup();
|
|
1442
|
-
} catch (err) {
|
|
1443
|
-
this._emit([[ERROR, this._wrapFnError("cleanup threw", err)]]);
|
|
1444
|
-
return;
|
|
1445
|
-
}
|
|
1446
|
-
}
|
|
1447
|
-
const batchData = this._deps.map(
|
|
1448
|
-
(d) => !d.involvedThisWave ? void 0 : d.dataBatch.length > 0 ? [...d.dataBatch] : []
|
|
1449
|
-
);
|
|
1450
|
-
const prevData = this._deps.map((d) => d.prevData);
|
|
1451
|
-
for (let i = 0; i < this._deps.length; i++) {
|
|
1452
|
-
const batch = batchData[i];
|
|
1453
|
-
if (batch != null && batch.length > 0) {
|
|
1454
|
-
this._deps[i].prevData = batch[batch.length - 1];
|
|
1455
|
-
}
|
|
1456
|
-
}
|
|
1457
|
-
const terminalDeps = this._deps.map((d) => d.terminal);
|
|
1458
|
-
const ctx = { prevData, terminalDeps, store: this._store };
|
|
1459
|
-
this._hasCalledFnOnce = true;
|
|
1460
|
-
this._clearWaveFlags();
|
|
1461
|
-
if (this._inspectorHooks != null) {
|
|
1462
|
-
const ev = { kind: "run", batchData, prevData };
|
|
1463
|
-
for (const hook of this._inspectorHooks) hook(ev);
|
|
1464
|
-
}
|
|
1465
|
-
this._isExecutingFn = true;
|
|
1466
|
-
try {
|
|
1467
|
-
const result = this._fn(batchData, this._actions, ctx);
|
|
1468
|
-
if (typeof result === "function") {
|
|
1469
|
-
this._cleanup = result;
|
|
1470
|
-
} else if (result != null && typeof result === "object" && typeof result.deactivation === "function") {
|
|
1471
|
-
this._cleanup = result;
|
|
1472
|
-
}
|
|
1473
|
-
} catch (err) {
|
|
1474
|
-
this._emit([[ERROR, this._wrapFnError("fn threw", err)]]);
|
|
1475
|
-
} finally {
|
|
1476
|
-
this._isExecutingFn = false;
|
|
1477
|
-
if (this._pendingRerun) {
|
|
1478
|
-
this._pendingRerun = false;
|
|
1479
|
-
this._rerunDepth += 1;
|
|
1480
|
-
if (this._rerunDepth > MAX_RERUN_DEPTH) {
|
|
1481
|
-
this._rerunDepth = 0;
|
|
1482
|
-
this._emit([
|
|
1483
|
-
[
|
|
1484
|
-
ERROR,
|
|
1485
|
-
new Error(
|
|
1486
|
-
`Node "${this.name}": _pendingRerun depth exceeded ${MAX_RERUN_DEPTH} \u2014 likely a reactive cycle`
|
|
1487
|
-
)
|
|
1488
|
-
]
|
|
1489
|
-
]);
|
|
1490
|
-
} else {
|
|
1491
|
-
this._maybeRunFnOnSettlement();
|
|
1492
|
-
}
|
|
1493
|
-
} else {
|
|
1494
|
-
this._rerunDepth = 0;
|
|
1495
|
-
}
|
|
1496
|
-
this._clearWaveFlags();
|
|
1497
|
-
}
|
|
1498
|
-
}
|
|
1499
|
-
_clearWaveFlags() {
|
|
1500
|
-
this._waveHasNewData = false;
|
|
1501
|
-
this._hasNewTerminal = false;
|
|
1502
|
-
for (const d of this._deps) {
|
|
1503
|
-
d.involvedThisWave = false;
|
|
1504
|
-
d.dataBatch.length = 0;
|
|
1505
|
-
}
|
|
1506
|
-
}
|
|
1507
|
-
_wrapFnError(label, err) {
|
|
1508
|
-
const msg = err instanceof Error ? err.message : String(err);
|
|
1509
|
-
return new Error(`Node "${this.name}": ${label}: ${msg}`, { cause: err });
|
|
1510
|
-
}
|
|
1511
|
-
// --- Framing (tier sort + synthetic DIRTY prefix) ---
|
|
1512
|
-
/**
|
|
1513
|
-
* @internal Stable tier sort + synthetic DIRTY prefix for an outgoing
|
|
1514
|
-
* batch. Fast path: already-monotone single-tier batches (the common
|
|
1515
|
-
* case from interned singletons like `DIRTY_ONLY_BATCH`) return the
|
|
1516
|
-
* input unchanged. General path: decorate-sort-undecorate into a new
|
|
1517
|
-
* array, then prepend `[DIRTY]` after any tier-0 START entries when
|
|
1518
|
-
* a tier-3 payload is present and the node isn't already dirty.
|
|
1519
|
-
*
|
|
1520
|
-
* Single source of truth for the spec §1.3.1 framing invariant. Every
|
|
1521
|
-
* outgoing path hits `_frameBatch` exactly once via `_emit`.
|
|
1522
|
-
*/
|
|
1523
|
-
_frameBatch(messages) {
|
|
1524
|
-
const tierOf = this._config.tierOf;
|
|
1525
|
-
if (messages.length === 1) {
|
|
1526
|
-
const t = tierOf(messages[0][0]);
|
|
1527
|
-
if (t === 3 && this._status !== "dirty") {
|
|
1528
|
-
return [DIRTY_MSG, messages[0]];
|
|
1529
|
-
}
|
|
1530
|
-
return messages;
|
|
1531
|
-
}
|
|
1532
|
-
let monotone = true;
|
|
1533
|
-
let hasTier3 = false;
|
|
1534
|
-
let hasDirty = false;
|
|
1535
|
-
let prevTier = -1;
|
|
1536
|
-
for (const m of messages) {
|
|
1537
|
-
const tier = tierOf(m[0]);
|
|
1538
|
-
if (tier < prevTier) monotone = false;
|
|
1539
|
-
if (tier === 3) hasTier3 = true;
|
|
1540
|
-
if (m[0] === DIRTY) hasDirty = true;
|
|
1541
|
-
prevTier = tier;
|
|
1542
|
-
}
|
|
1543
|
-
let sorted = messages;
|
|
1544
|
-
if (!monotone) {
|
|
1545
|
-
const indexed = messages.map((m, i) => ({ m, i, tier: tierOf(m[0]) }));
|
|
1546
|
-
indexed.sort((a, b) => a.tier - b.tier || a.i - b.i);
|
|
1547
|
-
sorted = indexed.map((x) => x.m);
|
|
1548
|
-
}
|
|
1549
|
-
if (hasTier3 && !hasDirty && this._status !== "dirty") {
|
|
1550
|
-
let insertAt = 0;
|
|
1551
|
-
while (insertAt < sorted.length && tierOf(sorted[insertAt][0]) === 0) insertAt++;
|
|
1552
|
-
if (insertAt === 0) return [DIRTY_MSG, ...sorted];
|
|
1553
|
-
return [...sorted.slice(0, insertAt), DIRTY_MSG, ...sorted.slice(insertAt)];
|
|
1554
|
-
}
|
|
1555
|
-
return sorted;
|
|
1556
|
-
}
|
|
1557
|
-
// --- Emit pipeline ---
|
|
1558
|
-
/**
|
|
1559
|
-
* @internal The unified dispatch waist — one call = one wave.
|
|
1560
|
-
* See `GRAPHREFLY-SPEC.md` §1.3.1 for protocol context — the stages
|
|
1561
|
-
* below are the implementation order.
|
|
1562
|
-
*
|
|
1563
|
-
* Pipeline stages, in order:
|
|
1564
|
-
*
|
|
1565
|
-
* 1. Terminal filter — post-COMPLETE/ERROR only TEARDOWN/INVALIDATE
|
|
1566
|
-
* still propagate so graph teardown and cache-clear still work.
|
|
1567
|
-
* 2. Tier sort (stable) — the batch can be in any order when it
|
|
1568
|
-
* arrives; the walker downstream (`downWithBatch`) assumes
|
|
1569
|
-
* ascending tier monotone, and so does `_updateState`'s tier-3
|
|
1570
|
-
* slice walk. This is the single source of truth for ordering.
|
|
1571
|
-
* 3. Synthetic DIRTY prefix — if a tier-3 payload is present, no
|
|
1572
|
-
* DIRTY is already in the batch, and the node isn't already in
|
|
1573
|
-
* `"dirty"` status, prepend `[DIRTY]` after any tier-0 START
|
|
1574
|
-
* entries. Guarantees spec §1.3.1 (DIRTY precedes DATA within
|
|
1575
|
-
* the same batch) uniformly across every entry point.
|
|
1576
|
-
* 4. PAUSE/RESUME lock bookkeeping (C0) — update `_pauseLocks`,
|
|
1577
|
-
* derive `_paused`, filter unknown-lockId RESUME, replay
|
|
1578
|
-
* bufferAll buffer on final lock release.
|
|
1579
|
-
* 5. Meta TEARDOWN fan-out — notify meta children before
|
|
1580
|
-
* `_updateState`'s TEARDOWN branch calls `_deactivate`. Hoisted
|
|
1581
|
-
* out of the walk to keep `_updateState` re-entrance-free.
|
|
1582
|
-
* 6. `_updateState` — walk the batch in tier order, advancing
|
|
1583
|
-
* `_cached` / `_status` / `_versioning` and running equals
|
|
1584
|
-
* substitution on tier-3 DATA (§3.5.1). Returns
|
|
1585
|
-
* `{finalMessages, equalsError?}`.
|
|
1586
|
-
* 7. `downWithBatch` dispatch (or bufferAll capture if paused with
|
|
1587
|
-
* `pausable: "resumeAll"`).
|
|
1588
|
-
* 8. Recursive ERROR emission if equals threw mid-walk.
|
|
1589
|
-
*/
|
|
1590
|
-
_emit(messages) {
|
|
1591
|
-
if (messages.length === 0) return;
|
|
1592
|
-
let deliverable = messages;
|
|
1593
|
-
const terminal = this._isTerminal;
|
|
1594
|
-
if (terminal && !this._resubscribable) {
|
|
1595
|
-
const pass = messages.filter((m) => m[0] === TEARDOWN || m[0] === INVALIDATE);
|
|
1596
|
-
if (pass.length === 0) return;
|
|
1597
|
-
deliverable = pass;
|
|
1598
|
-
}
|
|
1599
|
-
deliverable = this._frameBatch(deliverable);
|
|
1600
|
-
let filtered = null;
|
|
1601
|
-
for (let i = 0; i < deliverable.length; i++) {
|
|
1602
|
-
const m = deliverable[i];
|
|
1603
|
-
const t = m[0];
|
|
1604
|
-
if (t !== PAUSE && t !== RESUME) {
|
|
1605
|
-
if (filtered != null) filtered.push(m);
|
|
1606
|
-
continue;
|
|
1607
|
-
}
|
|
1608
|
-
if (m.length < 2) {
|
|
1609
|
-
throw new Error(
|
|
1610
|
-
`Node "${this.name}": [[${t === PAUSE ? "PAUSE" : "RESUME"}]] must carry a lockId payload \u2014 bare PAUSE/RESUME is a protocol violation (C0 rule). Use \`[[PAUSE, lockId]]\` / \`[[RESUME, lockId]]\`.`
|
|
1611
|
-
);
|
|
1612
|
-
}
|
|
1613
|
-
let forward = true;
|
|
1614
|
-
if (this._pausable !== false) {
|
|
1615
|
-
const lockId = m[1];
|
|
1616
|
-
if (t === PAUSE) {
|
|
1617
|
-
if (this._pauseLocks == null) this._pauseLocks = /* @__PURE__ */ new Set();
|
|
1618
|
-
this._pauseLocks.add(lockId);
|
|
1619
|
-
this._paused = true;
|
|
1620
|
-
if (this._pausable === "resumeAll" && this._pauseBuffer == null) {
|
|
1621
|
-
this._pauseBuffer = [];
|
|
1622
|
-
}
|
|
1623
|
-
} else {
|
|
1624
|
-
if (this._pauseLocks == null || !this._pauseLocks.has(lockId)) {
|
|
1625
|
-
forward = false;
|
|
1626
|
-
} else {
|
|
1627
|
-
this._pauseLocks.delete(lockId);
|
|
1628
|
-
if (this._pauseLocks.size === 0) {
|
|
1629
|
-
this._paused = false;
|
|
1630
|
-
if (this._pauseBuffer != null && this._pauseBuffer.length > 0) {
|
|
1631
|
-
const drain = this._pauseBuffer;
|
|
1632
|
-
this._pauseBuffer = [];
|
|
1633
|
-
this._emit(drain);
|
|
1634
|
-
}
|
|
1635
|
-
if (this._pendingWave) {
|
|
1636
|
-
this._pendingWave = false;
|
|
1637
|
-
this._maybeRunFnOnSettlement();
|
|
1638
|
-
}
|
|
1639
|
-
}
|
|
1640
|
-
}
|
|
1641
|
-
}
|
|
1642
|
-
}
|
|
1643
|
-
if (!forward) {
|
|
1644
|
-
if (filtered == null) filtered = deliverable.slice(0, i);
|
|
1645
|
-
} else if (filtered != null) {
|
|
1646
|
-
filtered.push(m);
|
|
1647
|
-
}
|
|
1648
|
-
}
|
|
1649
|
-
if (filtered != null) {
|
|
1650
|
-
if (filtered.length === 0) return;
|
|
1651
|
-
deliverable = filtered;
|
|
1652
|
-
}
|
|
1653
|
-
if (this._hasMeta && deliverable.some((m) => m[0] === TEARDOWN)) {
|
|
1654
|
-
for (const k of Object.keys(this.meta)) {
|
|
1655
|
-
try {
|
|
1656
|
-
this.meta[k]._emit(TEARDOWN_ONLY_BATCH);
|
|
1657
|
-
} catch {
|
|
1658
|
-
}
|
|
1659
|
-
}
|
|
1660
|
-
}
|
|
1661
|
-
const { finalMessages, equalsError } = this._updateState(deliverable);
|
|
1662
|
-
if (finalMessages.length > 0 && this._config.inspectorEnabled) {
|
|
1663
|
-
const inspector = this._config.globalInspector;
|
|
1664
|
-
if (inspector != null) {
|
|
1665
|
-
try {
|
|
1666
|
-
inspector({ kind: "emit", node: this, messages: finalMessages });
|
|
1667
|
-
} catch {
|
|
1668
|
-
}
|
|
1669
|
-
}
|
|
1670
|
-
}
|
|
1671
|
-
if (finalMessages.length > 0) {
|
|
1672
|
-
if (this._paused && this._pausable === "resumeAll" && this._pauseBuffer != null) {
|
|
1673
|
-
const tierOf = this._config.tierOf;
|
|
1674
|
-
const immediate = [];
|
|
1675
|
-
for (const m of finalMessages) {
|
|
1676
|
-
const tier = tierOf(m[0]);
|
|
1677
|
-
if (tier < 3 || tier === 5) {
|
|
1678
|
-
immediate.push(m);
|
|
1679
|
-
} else {
|
|
1680
|
-
this._pauseBuffer.push(m);
|
|
1681
|
-
}
|
|
1682
|
-
}
|
|
1683
|
-
if (immediate.length > 0) {
|
|
1684
|
-
this._dispatchOrAccumulate(immediate);
|
|
1685
|
-
}
|
|
1686
|
-
} else {
|
|
1687
|
-
this._dispatchOrAccumulate(finalMessages);
|
|
1688
|
-
}
|
|
1689
|
-
}
|
|
1690
|
-
if (equalsError != null) {
|
|
1691
|
-
this._emit([[ERROR, equalsError]]);
|
|
1692
|
-
}
|
|
1693
|
-
}
|
|
1694
|
-
/**
|
|
1695
|
-
* @internal Walk an outgoing (already-framed) batch, updating own
|
|
1696
|
-
* cache / status / versioning and running equals substitution on
|
|
1697
|
-
* every tier-3 DATA (§3.5.1). Framing — tier sort and synthetic
|
|
1698
|
-
* DIRTY prefix — has already happened upstream in `_frameBatch`.
|
|
1699
|
-
* This walk trusts the input is in monotone tier order and that the
|
|
1700
|
-
* spec §1.3.1 DIRTY/RESOLVED precedence invariant is already
|
|
1701
|
-
* satisfied by the frame.
|
|
1702
|
-
*
|
|
1703
|
-
* Equals substitution: every DATA payload is compared against the
|
|
1704
|
-
* live `_cached`; when equal, the tuple is rewritten to `[RESOLVED]`
|
|
1705
|
-
* in a per-call copy and cache is not re-advanced. `.cache` remains
|
|
1706
|
-
* coherent with "the last DATA payload this node actually sent
|
|
1707
|
-
* downstream".
|
|
1708
|
-
*
|
|
1709
|
-
* Returns `{ finalMessages, equalsError? }`:
|
|
1710
|
-
* - `finalMessages` — the array to deliver to sinks (may be
|
|
1711
|
-
* `messages` unchanged, a rewritten copy with DATA→RESOLVED
|
|
1712
|
-
* substitutions, or a truncated prefix when equals throws mid-walk).
|
|
1713
|
-
* - `equalsError` — present only when the configured `equals` function
|
|
1714
|
-
* threw on some DATA message. `_emit` delivers the prefix first,
|
|
1715
|
-
* then emits a fresh ERROR batch via a recursive `_emit` call so
|
|
1716
|
-
* subscribers observe `[...walked_prefix, ERROR]` in order.
|
|
1717
|
-
*/
|
|
1718
|
-
_updateState(messages) {
|
|
1719
|
-
const tierOf = this._config.tierOf;
|
|
1720
|
-
let rewritten;
|
|
1721
|
-
let equalsError;
|
|
1722
|
-
let abortedAt = -1;
|
|
1723
|
-
let dataCount = 0;
|
|
1724
|
-
for (const m of messages) {
|
|
1725
|
-
if (tierOf(m[0]) === 3) dataCount++;
|
|
1726
|
-
}
|
|
1727
|
-
const checkEquals = dataCount <= 1;
|
|
1728
|
-
let lastDataIdx = -1;
|
|
1729
|
-
if (this._versioning != null && dataCount > 1) {
|
|
1730
|
-
for (let i = messages.length - 1; i >= 0; i--) {
|
|
1731
|
-
if (messages[i][0] === DATA) {
|
|
1732
|
-
lastDataIdx = i;
|
|
1733
|
-
break;
|
|
1734
|
-
}
|
|
1735
|
-
}
|
|
1736
|
-
}
|
|
1737
|
-
for (let i = 0; i < messages.length; i++) {
|
|
1738
|
-
const m = messages[i];
|
|
1739
|
-
const t = m[0];
|
|
1740
|
-
if (t === DATA) {
|
|
1741
|
-
if (m.length >= 2) {
|
|
1742
|
-
let unchanged = false;
|
|
1743
|
-
if (checkEquals && this._cached !== void 0) {
|
|
1744
|
-
try {
|
|
1745
|
-
unchanged = this._equals(this._cached, m[1]);
|
|
1746
|
-
} catch (err) {
|
|
1747
|
-
equalsError = this._wrapFnError("equals threw", err);
|
|
1748
|
-
abortedAt = i;
|
|
1749
|
-
break;
|
|
1750
|
-
}
|
|
1751
|
-
}
|
|
1752
|
-
if (unchanged) {
|
|
1753
|
-
if (rewritten == null) rewritten = messages.slice(0, i);
|
|
1754
|
-
rewritten.push(RESOLVED_MSG);
|
|
1755
|
-
this._status = "resolved";
|
|
1756
|
-
continue;
|
|
1757
|
-
}
|
|
1758
|
-
this._cached = m[1];
|
|
1759
|
-
if (this._versioning != null) {
|
|
1760
|
-
if (lastDataIdx < 0 || i === lastDataIdx) {
|
|
1761
|
-
advanceVersion(this._versioning, m[1], this._hashFn);
|
|
1762
|
-
}
|
|
1763
|
-
}
|
|
1764
|
-
}
|
|
1765
|
-
this._status = "settled";
|
|
1766
|
-
if (rewritten != null) rewritten.push(m);
|
|
1767
|
-
} else {
|
|
1768
|
-
if (rewritten != null) rewritten.push(m);
|
|
1769
|
-
if (t === DIRTY) {
|
|
1770
|
-
this._status = "dirty";
|
|
1771
|
-
} else if (t === RESOLVED) {
|
|
1772
|
-
this._status = "resolved";
|
|
1773
|
-
} else if (t === COMPLETE) {
|
|
1774
|
-
this._status = "completed";
|
|
1775
|
-
} else if (t === ERROR) {
|
|
1776
|
-
this._status = "errored";
|
|
1777
|
-
} else if (t === INVALIDATE) {
|
|
1778
|
-
this._cached = void 0;
|
|
1779
|
-
this._status = "dirty";
|
|
1780
|
-
const c = this._cleanup;
|
|
1781
|
-
if (typeof c === "function") {
|
|
1782
|
-
this._cleanup = void 0;
|
|
1783
|
-
try {
|
|
1784
|
-
c();
|
|
1785
|
-
} catch {
|
|
1786
|
-
}
|
|
1787
|
-
}
|
|
1788
|
-
} else if (t === TEARDOWN) {
|
|
1789
|
-
if (this._resetOnTeardown) this._cached = void 0;
|
|
1790
|
-
this._deactivate(
|
|
1791
|
-
/* skipStatusUpdate */
|
|
1792
|
-
true
|
|
1793
|
-
);
|
|
1794
|
-
this._status = "sentinel";
|
|
1795
|
-
}
|
|
1796
|
-
}
|
|
1797
|
-
}
|
|
1798
|
-
const base = abortedAt >= 0 ? rewritten ?? messages.slice(0, abortedAt) : rewritten ?? messages;
|
|
1799
|
-
return equalsError != null ? { finalMessages: base, equalsError } : { finalMessages: base };
|
|
1800
|
-
}
|
|
1801
|
-
_deliverToSinks = (messages) => {
|
|
1802
|
-
if (this._sinks == null) return;
|
|
1803
|
-
if (typeof this._sinks === "function") {
|
|
1804
|
-
this._sinks(messages);
|
|
1805
|
-
return;
|
|
1806
|
-
}
|
|
1807
|
-
const snapshot = [...this._sinks];
|
|
1808
|
-
for (const sink of snapshot) sink(messages);
|
|
1809
|
-
};
|
|
1810
|
-
/**
|
|
1811
|
-
* @internal Dispatch entry point that respects the per-batch emit
|
|
1812
|
-
* accumulator (Bug 2). Inside an explicit `batch()` scope, append to
|
|
1813
|
-
* `_batchPendingMessages` and register a flush hook on first append.
|
|
1814
|
-
* Outside batch — or during a drain (where `flushInProgress` is true
|
|
1815
|
-
* but `batchDepth` is 0) — dispatch synchronously through `downWithBatch`.
|
|
1816
|
-
*
|
|
1817
|
-
* Per-emit state updates (`_frameBatch`, `_updateState`) have already
|
|
1818
|
-
* happened by the time we reach here; only the **downstream delivery**
|
|
1819
|
-
* is coalesced. Cache, version, and status are visible mid-batch on
|
|
1820
|
-
* the emitting node itself.
|
|
1821
|
-
*/
|
|
1822
|
-
_dispatchOrAccumulate(messages) {
|
|
1823
|
-
if (isExplicitlyBatching()) {
|
|
1824
|
-
if (this._batchPendingMessages === null) {
|
|
1825
|
-
this._batchPendingMessages = [];
|
|
1826
|
-
registerBatchFlushHook(() => this._flushBatchPending());
|
|
1827
|
-
}
|
|
1828
|
-
for (const m of messages) this._batchPendingMessages.push(m);
|
|
1829
|
-
return;
|
|
1830
|
-
}
|
|
1831
|
-
downWithBatch(this._deliverToSinks, messages, this._config.tierOf);
|
|
1832
|
-
}
|
|
1833
|
-
/**
|
|
1834
|
-
* @internal Flushes the accumulated batch through `downWithBatch` and
|
|
1835
|
-
* clears the pending state. Idempotent — safe to call when pending is
|
|
1836
|
-
* already null or empty (e.g. on a `batch()` throw, where the hook
|
|
1837
|
-
* fires for cleanup but the drainPhase queues are wiped after).
|
|
1838
|
-
*
|
|
1839
|
-
* Critical: the accumulated batch is interleaved per-emit framings like
|
|
1840
|
-
* `[DIRTY, DATA(1), DIRTY, DATA(2)]` — non-monotone tier order. We must
|
|
1841
|
-
* re-frame to sort by tier before handing to `downWithBatch`, which
|
|
1842
|
-
* assumes pre-sorted input. `_frameBatch` also handles the synthetic
|
|
1843
|
-
* DIRTY prepend rule (no-op here — `hasDirty` is true since each
|
|
1844
|
-
* accumulated emit already carries its own DIRTY prefix).
|
|
1845
|
-
*/
|
|
1846
|
-
_flushBatchPending() {
|
|
1847
|
-
const pending = this._batchPendingMessages;
|
|
1848
|
-
if (pending === null) return;
|
|
1849
|
-
this._batchPendingMessages = null;
|
|
1850
|
-
if (pending.length === 0) return;
|
|
1851
|
-
const framed = this._frameBatch(pending);
|
|
1852
|
-
downWithBatch(this._deliverToSinks, framed, this._config.tierOf);
|
|
1853
|
-
}
|
|
1854
|
-
};
|
|
1855
|
-
var isNodeArray = (value) => Array.isArray(value);
|
|
1856
|
-
var isNodeOptionsObject = (value) => typeof value === "object" && value != null && !Array.isArray(value);
|
|
1857
|
-
function node(depsOrFn, fnOrOpts, optsArg) {
|
|
1858
|
-
const deps = isNodeArray(depsOrFn) ? depsOrFn : [];
|
|
1859
|
-
const fn = typeof depsOrFn === "function" ? depsOrFn : typeof fnOrOpts === "function" ? fnOrOpts : void 0;
|
|
1860
|
-
let opts = {};
|
|
1861
|
-
if (isNodeArray(depsOrFn)) {
|
|
1862
|
-
opts = (isNodeOptionsObject(fnOrOpts) ? fnOrOpts : optsArg) ?? {};
|
|
1863
|
-
} else if (isNodeOptionsObject(depsOrFn)) {
|
|
1864
|
-
opts = depsOrFn;
|
|
1865
|
-
} else {
|
|
1866
|
-
opts = (isNodeOptionsObject(fnOrOpts) ? fnOrOpts : optsArg) ?? {};
|
|
1867
|
-
}
|
|
1868
|
-
return new NodeImpl(deps, fn, opts);
|
|
1869
|
-
}
|
|
1870
|
-
|
|
1871
|
-
// src/core/sugar.ts
|
|
1872
|
-
function state(initial, opts) {
|
|
1873
|
-
return node([], { ...opts, initial });
|
|
1874
|
-
}
|
|
1875
|
-
function autoTrackNode(fn, opts) {
|
|
1876
|
-
let implRef;
|
|
1877
|
-
const depIndexMap = /* @__PURE__ */ new Map();
|
|
1878
|
-
const allowPartial = opts?.partial ?? false;
|
|
1879
|
-
const wrappedFn = (batchData, actions, ctx) => {
|
|
1880
|
-
let foundNew = false;
|
|
1881
|
-
const track = (dep) => {
|
|
1882
|
-
const idx = depIndexMap.get(dep);
|
|
1883
|
-
if (idx !== void 0) {
|
|
1884
|
-
if (idx < batchData.length) {
|
|
1885
|
-
const batch = batchData[idx];
|
|
1886
|
-
if (batch != null && batch.length > 0) return batch.at(-1);
|
|
1887
|
-
return ctx.prevData[idx];
|
|
1888
|
-
}
|
|
1889
|
-
return dep.cache;
|
|
1890
|
-
}
|
|
1891
|
-
foundNew = true;
|
|
1892
|
-
const newIdx = implRef._addDep(dep);
|
|
1893
|
-
depIndexMap.set(dep, newIdx);
|
|
1894
|
-
return dep.cache;
|
|
1895
|
-
};
|
|
1896
|
-
if (!allowPartial && depIndexMap.size > 0) {
|
|
1897
|
-
for (const [, idx] of depIndexMap) {
|
|
1898
|
-
if (idx < batchData.length) {
|
|
1899
|
-
const batch = batchData[idx];
|
|
1900
|
-
if (!(batch != null && batch.length > 0) && ctx.prevData[idx] === void 0) {
|
|
1901
|
-
actions.down([[RESOLVED]]);
|
|
1902
|
-
return void 0;
|
|
1903
|
-
}
|
|
1904
|
-
}
|
|
1905
|
-
}
|
|
1906
|
-
}
|
|
1907
|
-
try {
|
|
1908
|
-
const result = fn(track, ctx);
|
|
1909
|
-
if (!foundNew) {
|
|
1910
|
-
actions.emit(result);
|
|
1911
|
-
if (ctx.store.__autoTrackLastDiscoveryError != null) {
|
|
1912
|
-
delete ctx.store.__autoTrackLastDiscoveryError;
|
|
1913
|
-
}
|
|
1914
|
-
}
|
|
1915
|
-
} catch (err) {
|
|
1916
|
-
if (!foundNew) throw err;
|
|
1917
|
-
ctx.store.__autoTrackLastDiscoveryError = err;
|
|
1918
|
-
}
|
|
1919
|
-
return void 0;
|
|
1920
|
-
};
|
|
1921
|
-
implRef = new NodeImpl([], wrappedFn, {
|
|
1922
|
-
describeKind: "derived",
|
|
1923
|
-
...opts
|
|
1924
|
-
});
|
|
1925
|
-
return implRef;
|
|
1926
|
-
}
|
|
1927
|
-
|
|
1928
|
-
// src/compat/jotai/index.ts
|
|
1929
|
-
function atom(initialOrRead, writeOrOptions, options) {
|
|
1930
|
-
if (typeof initialOrRead === "function") {
|
|
1931
|
-
const read = initialOrRead;
|
|
1932
|
-
if (typeof writeOrOptions === "function") {
|
|
1933
|
-
return createDerivedAtom(read, writeOrOptions, options);
|
|
1934
|
-
}
|
|
1935
|
-
return createDerivedAtom(read, void 0, writeOrOptions);
|
|
1936
|
-
}
|
|
1937
|
-
return createPrimitiveAtom(initialOrRead, writeOrOptions);
|
|
1938
|
-
}
|
|
1939
|
-
function pull(n) {
|
|
1940
|
-
let val = n.cache;
|
|
1941
|
-
let err;
|
|
1942
|
-
const unsub = n.subscribe((msgs) => {
|
|
1943
|
-
for (const [t, v] of msgs) {
|
|
1944
|
-
if (t === DATA) val = v;
|
|
1945
|
-
if (t === ERROR) err = v;
|
|
1946
|
-
}
|
|
1947
|
-
});
|
|
1948
|
-
unsub();
|
|
1949
|
-
if (err) throw err;
|
|
1950
|
-
return val;
|
|
1951
|
-
}
|
|
1952
|
-
function createPrimitiveAtom(initial, options) {
|
|
1953
|
-
const n = state(initial, {
|
|
1954
|
-
...options,
|
|
1955
|
-
resubscribable: true,
|
|
1956
|
-
resetOnTeardown: true
|
|
1957
|
-
});
|
|
1958
|
-
return {
|
|
1959
|
-
get: () => {
|
|
1960
|
-
if (n.status === "sentinel") {
|
|
1961
|
-
return pull(n);
|
|
1962
|
-
}
|
|
1963
|
-
return n.cache;
|
|
1964
|
-
},
|
|
1965
|
-
// Use `n.emit` (not raw `n.down`) so writes go through the framed
|
|
1966
|
-
// emit pipeline: bundle() auto-prefixes DIRTY (diamond-safe wave
|
|
1967
|
-
// coordination) and the equals check folds same-value writes to
|
|
1968
|
-
// RESOLVED (no spurious subscriber fires).
|
|
1969
|
-
set: (value) => n.emit(value),
|
|
1970
|
-
update: (fn) => {
|
|
1971
|
-
const current = n.status === "sentinel" ? pull(n) : n.cache;
|
|
1972
|
-
n.emit(fn(current));
|
|
1973
|
-
},
|
|
1974
|
-
subscribe: (cb) => {
|
|
1975
|
-
let initial2 = true;
|
|
1976
|
-
return n.subscribe((msgs) => {
|
|
1977
|
-
for (const [t, v] of msgs) {
|
|
1978
|
-
if (t === DATA) {
|
|
1979
|
-
if (initial2) {
|
|
1980
|
-
initial2 = false;
|
|
1981
|
-
continue;
|
|
1982
|
-
}
|
|
1983
|
-
cb(v);
|
|
1984
|
-
}
|
|
1985
|
-
}
|
|
1986
|
-
});
|
|
1987
|
-
},
|
|
1988
|
-
meta: n.meta,
|
|
1989
|
-
_node: n
|
|
1990
|
-
};
|
|
1991
|
-
}
|
|
1992
|
-
function createDerivedAtom(read, write, options) {
|
|
1993
|
-
const n = autoTrackNode(
|
|
1994
|
-
(track) => read((a) => {
|
|
1995
|
-
const dn = a._node;
|
|
1996
|
-
if (dn.status === "sentinel") {
|
|
1997
|
-
pull(dn);
|
|
1998
|
-
}
|
|
1999
|
-
return track(dn);
|
|
2000
|
-
}),
|
|
2001
|
-
{
|
|
2002
|
-
...options,
|
|
2003
|
-
resubscribable: true,
|
|
2004
|
-
resetOnTeardown: true
|
|
2005
|
-
}
|
|
2006
|
-
);
|
|
2007
|
-
const result = {
|
|
2008
|
-
get: () => {
|
|
2009
|
-
if (n.status === "sentinel") {
|
|
2010
|
-
return pull(n);
|
|
2011
|
-
}
|
|
2012
|
-
return n.cache;
|
|
2013
|
-
},
|
|
2014
|
-
subscribe: (cb) => {
|
|
2015
|
-
let initial = true;
|
|
2016
|
-
return n.subscribe((msgs) => {
|
|
2017
|
-
for (const [t, v] of msgs) {
|
|
2018
|
-
if (t === DATA) {
|
|
2019
|
-
if (initial) {
|
|
2020
|
-
initial = false;
|
|
2021
|
-
continue;
|
|
2022
|
-
}
|
|
2023
|
-
cb(v);
|
|
2024
|
-
}
|
|
2025
|
-
}
|
|
2026
|
-
});
|
|
2027
|
-
},
|
|
2028
|
-
meta: n.meta,
|
|
2029
|
-
_node: n
|
|
2030
|
-
};
|
|
2031
|
-
if (write) {
|
|
2032
|
-
const getFn = (a) => a.get();
|
|
2033
|
-
const setFn = (a, value) => a.set(value);
|
|
2034
|
-
const writable = result;
|
|
2035
|
-
writable.set = (value) => write(getFn, setFn, value);
|
|
2036
|
-
writable.update = (fn) => {
|
|
2037
|
-
const current = n.status === "sentinel" ? pull(n) : n.cache;
|
|
2038
|
-
return write(getFn, setFn, fn(current));
|
|
2039
|
-
};
|
|
2040
|
-
return writable;
|
|
2041
|
-
}
|
|
2042
|
-
return result;
|
|
2043
|
-
}
|
|
2044
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
2045
|
-
0 && (module.exports = {
|
|
2046
|
-
atom
|
|
2047
|
-
});
|
|
2048
|
-
//# sourceMappingURL=index.cjs.map
|
|
1
|
+
"use strict";var J=Object.defineProperty;var Oe=Object.getOwnPropertyDescriptor;var De=Object.getOwnPropertyNames;var Ce=Object.prototype.hasOwnProperty;var Fe=(s,e)=>{for(var t in e)J(s,t,{get:e[t],enumerable:!0})},Ge=(s,e,t,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of De(e))!Ce.call(s,r)&&r!==t&&J(s,r,{get:()=>e[r],enumerable:!(n=Oe(e,r))||n.enumerable});return s};var Ie=s=>Ge(J({},"__esModule",{value:!0}),s);var Ze={};Fe(Ze,{atom:()=>Je});module.exports=Ie(Ze);var I=Symbol.for("graphrefly/START"),g=Symbol.for("graphrefly/DATA"),A=Symbol.for("graphrefly/DIRTY"),k=Symbol.for("graphrefly/RESOLVED"),M=Symbol.for("graphrefly/INVALIDATE"),E=Symbol.for("graphrefly/PAUSE"),V=Symbol.for("graphrefly/RESUME"),w=Symbol.for("graphrefly/TEARDOWN"),S=Symbol.for("graphrefly/COMPLETE"),p=Symbol.for("graphrefly/ERROR"),R=Object.freeze([A]),X=Object.freeze([k]),Ve=Object.freeze([M]),Z=Object.freeze([I]),He=Object.freeze([S]),Le=Object.freeze([w]),Q=Object.freeze([R]),de=Object.freeze([X]),le=Object.freeze([Ve]),ce=Object.freeze([He]),ee=Object.freeze([Le]);var Pe={name:"json",version:1,contentType:"application/json",encode(s){let e=JSON.stringify(s);return new TextEncoder().encode(e)},decode(s,e){let t=new TextDecoder().decode(s);return JSON.parse(t)}};function ue(s){s.registerCodec(Pe)}var We={type:"system",id:""};function B(s){if(s==null)return We;let{type:e,id:t,...n}=s;return{type:e??"system",id:t??"",...n}}var te=0,Ue=!1,fe=[],he=[],pe=[],Be=[];function _e(){return te>0||Ue}function ge(){return te>0}function ye(s){te>0?Be.push(s):s()}function j(s,e,t){if(e.length===0)return;if(e.length===1){let l=t(e[0][0]);if(l<3||!_e()){s(e);return}(l>=5?pe:l===4?he:fe).push(()=>s(e));return}let n=e.length,r=n,a=n,i=n,o=0;for(;o<n&&t(e[o][0])<3;)o++;for(r=o;o<n&&t(e[o][0])===3;)o++;for(a=o;o<n&&t(e[o][0])===4;)o++;i=o;let d=_e();if(r>0){let l=e.slice(0,r);s(l)}if(a>r){let l=e.slice(r,a);d?fe.push(()=>s(l)):s(l)}if(i>a){let l=e.slice(a,i);d?he.push(()=>s(l)):s(l)}if(n>i){let l=e.slice(i,n);d?pe.push(()=>s(l)):s(l)}}function me(){return Date.now()*1e6}var z=class{_messageTypes=new Map;_codecs=new Map;_onMessage;_onSubscribe;_defaultVersioning;_defaultHashFn;_inspectorEnabled=!(typeof process<"u"&&process.env?.NODE_ENV==="production");_globalInspector;_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}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 be(s){s.registerMessageType(I,{tier:0,wireCrossing:!1}),s.registerMessageType(A,{tier:1,wireCrossing:!1}),s.registerMessageType(M,{tier:1,wireCrossing:!1,metaPassthrough:!1}),s.registerMessageType(E,{tier:2,wireCrossing:!1}),s.registerMessageType(V,{tier:2,wireCrossing:!1}),s.registerMessageType(g,{tier:3,wireCrossing:!0}),s.registerMessageType(k,{tier:3,wireCrossing:!0}),s.registerMessageType(S,{tier:4,wireCrossing:!0,metaPassthrough:!1}),s.registerMessageType(p,{tier:4,wireCrossing:!0,metaPassthrough:!1}),s.registerMessageType(w,{tier:5,wireCrossing:!0,metaPassthrough:!1})}var O=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}};function ne(s){if(s===void 0)return null;if(typeof s=="number"){if(!Number.isFinite(s))throw new TypeError(`Cannot hash non-finite number: ${s}`);if(Number.isInteger(s)&&!Number.isSafeInteger(s))throw new TypeError(`Cannot hash integer outside safe range (|n| > 2^53-1): ${s}. Cross-language cid parity is not guaranteed for unsafe integers.`);return s}if(typeof s=="string"||typeof s=="boolean"||s===null)return s;if(Array.isArray(s))return s.map(ne);if(typeof s=="object"&&s!==null){let e={};for(let t of Object.keys(s).sort())e[t]=ne(s[t]);return e}return null}var je=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]),ze=new TextEncoder;function $e(s){let e=ze.encode(s),t=e.length,n=t*8,r=t+9+63&-64,a=new Uint8Array(r);a.set(e),a[t]=128;let i=new DataView(a.buffer);i.setUint32(r-4,n>>>0,!1),i.setUint32(r-8,Math.floor(n/4294967296)>>>0,!1);let o=1779033703,d=3144134277,l=1013904242,c=2773480762,u=1359893119,_=2600822924,f=528734635,b=1541459225,N=new Uint32Array(64),m=(T,y)=>T>>>y|T<<32-y;for(let T=0;T<r;T+=64){for(let h=0;h<16;h++)N[h]=i.getUint32(T+h*4,!1);for(let h=16;h<64;h++){let F=N[h-15],G=N[h-2],U=m(F,7)^m(F,18)^F>>>3,K=m(G,17)^m(G,19)^G>>>10;N[h]=N[h-16]+U+N[h-7]+K>>>0}let y=o,D=d,C=l,q=c,x=u,P=_,W=f,Y=b;for(let h=0;h<64;h++){let F=m(x,6)^m(x,11)^m(x,25),G=x&P^~x&W,U=Y+F+G+je[h]+N[h]>>>0,K=m(y,2)^m(y,13)^m(y,22),Se=y&D^y&C^D&C,Re=K+Se>>>0;Y=W,W=P,P=x,x=q+U>>>0,q=C,C=D,D=y,y=U+Re>>>0}o=o+y>>>0,d=d+D>>>0,l=l+C>>>0,c=c+q>>>0,u=u+x>>>0,_=_+P>>>0,f=f+W>>>0,b=b+Y>>>0}let v=T=>T.toString(16).padStart(8,"0");return v(o)+v(d)+v(l)+v(c)+v(u)+v(_)+v(f)+v(b)}function se(s){let e=ne(s??null),t=JSON.stringify(e);return $e(t).slice(0,16)}function qe(){let s=globalThis.crypto;if(s?.randomUUID)return s.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 re(s,e,t){let n=t?.id??qe();if(s===0)return{id:n,version:0};let a=(t?.hash??se)(e);return{id:n,version:0,cid:a,prev:null}}function ve(s,e,t){s.version+=1,"cid"in s&&(s.prev=s.cid,s.cid=t(e))}var Te=()=>{},xe=100;function we(s){return{node:s,unsub:null,prevData:void 0,dirty:!1,involvedThisWave:!1,dataBatch:[],terminal:void 0}}function oe(s){s.prevData=void 0,s.dirty=!1,s.involvedThisWave=!1,s.dataBatch.length=0,s.terminal=void 0}function $(s){return s.length===0?s:typeof s[0]=="symbol"?[s]:s}var Ye=(s,e,t,n)=>{t.direction==="down-in"&&s._onDepMessage(t.depIndex,e)},Ke=(s,e,t,n)=>{let r=s;if(r._status==="completed"||r._status==="errored")return;let a=r._cached,i=a===void 0?[Z]:[Z,[g,a]];r._status==="dirty"&&i.push(R),j(e,i,r._config.tierOf)},ae=new z({onMessage:Ye,onSubscribe:Ke});be(ae);ue(ae);var H=class s{_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??ae,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??se;let r=n.versioning??this._config.defaultVersioning;this._versioningLevel=r,this._versioning=r!=null?re(r,this._cached===void 0?void 0:this._cached,{id:n.versioningId,hash:this._hashFn}):void 0,this._deps=e.map(we);let a={};for(let[o,d]of Object.entries(n.meta??{})){let l={initial:d,name:`${n.name??"node"}:meta:${o}`,describeKind:"state",config:this._config};n.guard!=null&&(l.guard=n.guard),a[o]=new s([],void 0,l)}Object.freeze(a),this.meta=a,this._hasMeta=Object.keys(a).length>0;let i=this;this._actions={emit(o){i._emit([[g,o]])},down(o){i._emit($(o))},up(o){i._emitUp($(o))}},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 r=t?.hash??this._hashFn;r!==this._hashFn&&(this._hashFn=r);let a=this._cached===void 0?void 0:this._cached,i=this._versioning,o=i?.id??t?.id,d=i?.version??0,l=re(e,a,{id:o,hash:r});l.version=d,this._versioning=l,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=B(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 r=B(e?.actor),a=e?.delivery==="signal"?"signal":"write";if(this._guard!=null&&!this._guard(r,a))throw new O({actor:r,action:a,nodeName:this.name});if(this._extraGuards!=null){for(let i of this._extraGuards)if(!i(r,a))throw new O({actor:r,action:a,nodeName:this.name})}this._lastMutation={actor:r,timestamp_ns:me()}}down(e,t){let n=$(e);n.length!==0&&(this._checkGuard(t),this._emit(n))}emit(e,t){this._checkGuard(t),this._emit([[g,e]])}up(e,t){if(this._deps.length===0)return;let n=$(e);if(n.length===0)return;this._checkGuard(t);let r=t??{internal:!0};this._validateUpTiers(n);for(let a of this._deps)a.node.up?.(n,r)}_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 r=t(n[0]);if(r===3||r===4)throw new Error(`Node "${this.name}": tier-${r} 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=B(t);if(!this._guard(d,"observe"))throw new O({actor:d,action:"observe",nodeName:this.name})}let r=this._isTerminal&&this._resubscribable;if(r){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)oe(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 a;try{a=this._config.onSubscribe(this,e,{sinkCount:this._sinkCount,afterTerminalReset:r},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 a=="function")try{a()}catch{}throw d}this._status==="sentinel"&&this._cached===void 0&&(this._status="pending");let o=!1;return()=>{o||(o=!0,this._sinkCount-=1,this._removeSink(e),typeof a=="function"&&a(),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 r=n,a=this._deps[n];a.unsub=Te,a.unsub=a.node.subscribe(i=>{if(a.unsub===null)return;let o=this._config.tierOf,d=!1;for(let l of i)o(l[0])>=3&&(d=!0),this._config.onMessage(this,l,{direction:"down-in",depIndex:r},this._actions);d&&this._maybeRunFnOnSettlement()}),t++}}catch(n){this._deps[t].unsub=null;for(let r=0;r<t;r++){let a=this._deps[r];if(a.unsub!=null){let i=a.unsub;a.unsub=null;try{i()}catch{}oe(a)}}throw this._dirtyDepCount=0,n}}_addDep(e){for(let r=0;r<this._deps.length;r++)if(this._deps[r].node===e)return r;let t=this._deps.length,n=we(e);if(this._deps.push(n),this._sinks==null)return t;n.dirty=!0,this._dirtyDepCount++,this._status!=="dirty"&&this._emit(Q),n.unsub=Te;try{n.unsub=e.subscribe(r=>{if(n.unsub===null)return;let a=this._config.tierOf,i=!1;for(let o of r)a(o[0])>=3&&(i=!0),this._config.onMessage(this,o,{direction:"down-in",depIndex:t},this._actions);i&&this._maybeRunFnOnSettlement()})}catch(r){throw n.unsub=null,this._deps.pop(),this._dirtyDepCount--,r}return t}_deactivate(e=!1){let t=this._cleanup;if(this._cleanup=void 0,typeof t=="function")try{t()}catch(n){this._emit([[p,this._wrapFnError("cleanup threw",n)]])}else if(t!=null&&typeof t=="object"){let n=t.deactivate;if(typeof n=="function")try{n()}catch(r){this._emit([[p,this._wrapFnError("cleanup.deactivate threw",r)]])}}for(let n of this._deps){if(n.unsub!=null){let r=n.unsub;n.unsub=null;try{r()}catch{}}oe(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],r=t[0];if(this._inspectorHooks!=null){let a={kind:"dep_message",depIndex:e,message:t};for(let i of this._inspectorHooks)i(a)}if(r!==I){if(r===A){this._depDirtied(n);return}if(r===M){this._depInvalidated(n),this._emit(le);return}if(r===E||r===V){this._emit([t]);return}if(r===w){this._emit(ee);return}if(r===g)this._depSettledAsData(n,t[1]);else if(r===k)this._depSettledAsResolved(n);else if(r===S)this._depSettledAsTerminal(n,!0);else if(r===p)this._depSettledAsTerminal(n,t[1]);else{this._emit([t]);return}if(!this._fn){(r===g||r===k)&&this._emit([t]),(r===S||r===p)&&this._maybeAutoTerminalAfterWave();return}}}_depDirtied(e){e.dirty||(e.dirty=!0,e.involvedThisWave=!0,this._dirtyDepCount++,this._status!=="dirty"&&this._emit(Q))}_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(de),this._maybeAutoTerminalAfterWave();return}this._fn&&this._execFn(),this._maybeAutoTerminalAfterWave()}}_maybeAutoTerminalAfterWave(){if(this._deps.length===0||this._isTerminal)return;let e=this._deps.find(t=>t.terminal!==void 0&&t.terminal!==!0);if(e!=null){this._autoError&&this._emit([[p,e.terminal]]);return}this._autoComplete&&this._deps.every(t=>t.terminal!==void 0)&&this._emit(ce)}_execFn(){if(!this._fn||this._isTerminal&&!this._resubscribable)return;if(this._isExecutingFn){this._pendingRerun=!0;return}let e=this._cleanup;if(typeof e=="function"){this._cleanup=void 0;try{e()}catch(i){this._emit([[p,this._wrapFnError("cleanup threw",i)]]);return}}else if(e!=null&&typeof e=="object"){let i=e.beforeRun;if(typeof i=="function"){e.beforeRun=void 0;try{i()}catch(o){this._emit([[p,this._wrapFnError("cleanup.beforeRun threw",o)]]);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 o=t[i];o!=null&&o.length>0&&(this._deps[i].prevData=o[o.length-1])}let r=this._deps.map(i=>i.terminal),a={prevData:n,terminalDeps:r,store:this._store};if(this._hasCalledFnOnce=!0,this._clearWaveFlags(),this._inspectorHooks!=null){let i={kind:"run",batchData:t,prevData:n};for(let o of this._inspectorHooks)o(i)}this._isExecutingFn=!0;try{let i=this._fn(t,this._actions,a);if(typeof i=="function")this._cleanup=i;else if(i!=null&&typeof i=="object"){let o=i;(typeof o.beforeRun=="function"||typeof o.deactivate=="function"||typeof o.invalidate=="function")&&(this._cleanup=i)}}catch(i){this._emit([[p,this._wrapFnError("fn threw",i)]])}finally{this._isExecutingFn=!1,this._pendingRerun?(this._pendingRerun=!1,this._rerunDepth+=1,this._rerunDepth>xe?(this._rerunDepth=0,this._emit([[p,new Error(`Node "${this.name}": _pendingRerun depth exceeded ${xe} \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"?[R,e[0]]:e;let n=!0,r=!1,a=!1,i=-1;for(let d of e){let l=t(d[0]);l<i&&(n=!1),l===3&&(r=!0),d[0]===A&&(a=!0),i=l}let o=e;if(!n){let d=e.map((l,c)=>({m:l,i:c,tier:t(l[0])}));d.sort((l,c)=>l.tier-c.tier||l.i-c.i),o=d.map(l=>l.m)}if(r&&!a&&this._status!=="dirty"){let d=0;for(;d<o.length&&t(o[d][0])===0;)d++;return d===0?[R,...o]:[...o.slice(0,d),R,...o.slice(d)]}return o}_emit(e){if(e.length===0)return;for(let o=0;o<e.length;o++){let d=e[o];if(d[0]===p&&d[1]===void 0)throw new TypeError('[ERROR, payload] requires a non-undefined payload (spec \xA71.2). Pass an Error object or domain tag instead \u2014 e.g. node.down([[ERROR, new Error("reason")]])')}let t=e;if(this._isTerminal&&!this._resubscribable){let o=e.filter(d=>d[0]===w||d[0]===M);if(o.length===0)return;t=o}t=this._frameBatch(t);let r=null;for(let o=0;o<t.length;o++){let d=t[o],l=d[0];if(l!==E&&l!==V){r?.push(d);continue}if(d.length<2)throw new Error(`Node "${this.name}": [[${l===E?"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 u=d[1];if(l===E)this._pauseLocks==null&&(this._pauseLocks=new Set),this._pauseLocks.add(u),this._paused=!0,this._pausable==="resumeAll"&&this._pauseBuffer==null&&(this._pauseBuffer=[]);else if(this._pauseLocks==null||!this._pauseLocks.has(u))c=!1;else if(this._pauseLocks.delete(u),this._pauseLocks.size===0){if(this._paused=!1,this._pauseBuffer!=null&&this._pauseBuffer.length>0){let _=this._pauseBuffer;this._pauseBuffer=[],this._emit(_)}this._pendingWave&&(this._pendingWave=!1,this._maybeRunFnOnSettlement())}}c?r?.push(d):r==null&&(r=t.slice(0,o))}if(r!=null){if(r.length===0)return;t=r}if(this._hasMeta&&t.some(o=>o[0]===w))for(let o of Object.keys(this.meta))try{this.meta[o]._emit(ee)}catch{}let{finalMessages:a,equalsError:i}=this._updateState(t);if(a.length>0&&this._config.inspectorEnabled){let o=this._config.globalInspector;if(o!=null)try{o({kind:"emit",node:this,messages:a})}catch{}}if(a.length>0)if(this._paused&&this._pausable==="resumeAll"&&this._pauseBuffer!=null){let o=this._config.tierOf,d=[];for(let l of a)o(l[0])===3?this._pauseBuffer.push(l):d.push(l);d.length>0&&this._dispatchOrAccumulate(d)}else this._dispatchOrAccumulate(a);i!=null&&this._emit([[p,i]])}_updateState(e){let t=this._config.tierOf,n,r,a=-1,i=0;for(let c of e)t(c[0])===3&&i++;let o=i<=1,d=-1;if(this._versioning!=null&&i>1){for(let c=e.length-1;c>=0;c--)if(e[c][0]===g){d=c;break}}for(let c=0;c<e.length;c++){let u=e[c],_=u[0];if(_===g){if(u.length>=2){let f=!1;if(o&&this._cached!==void 0)try{f=this._equals(this._cached,u[1])}catch(b){r=this._wrapFnError("equals threw",b),a=c;break}if(f){n==null&&(n=e.slice(0,c)),n.push(X),this._status="resolved";continue}this._cached=u[1],this._versioning!=null&&(d<0||c===d)&&ve(this._versioning,u[1],this._hashFn)}this._status="settled",n?.push(u)}else if(n?.push(u),_===A)this._status="dirty";else if(_===k)this._status="resolved";else if(_===S)this._status="completed";else if(_===p)this._status="errored";else if(_===M){this._cached=void 0,this._status="dirty";let f=this._cleanup;if(typeof f=="function"){this._cleanup=void 0;try{f()}catch{}}else if(f!=null&&typeof f=="object"){let b=f.invalidate;if(typeof b=="function")try{b()}catch{}}}else _===w&&(this._resetOnTeardown&&(this._cached=void 0),this._deactivate(!0),this._status="sentinel")}let l=a>=0?n??e.slice(0,a):n??e;return r!=null?{finalMessages:l,equalsError:r}:{finalMessages:l}}_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(ge()){this._batchPendingMessages===null&&(this._batchPendingMessages=[],ye(()=>this._flushBatchPending()));for(let t of e)this._batchPendingMessages.push(t);return}j(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);j(this._deliverToSinks,t,this._config.tierOf)}},Ne=s=>Array.isArray(s),ie=s=>typeof s=="object"&&s!=null&&!Array.isArray(s);function Ae(s,e,t){let n=Ne(s)?s:[],r=typeof s=="function"?s:typeof e=="function"?e:void 0,a={};return Ne(s)?a=(ie(e)?e:t)??{}:ie(s)?a=s:a=(ie(e)?e:t)??{},new H(n,r,a)}function ke(s,e){return Ae([],{...e,initial:s})}function Me(s,e){let t,n=new Map,r=(a,i,o)=>{let d=!1,l=c=>{let u=n.get(c);if(u!==void 0){if(u<a.length){let f=a[u];return f!=null&&f.length>0?f.at(-1):o.prevData[u]}return c.cache}d=!0;let _=t._addDep(c);return n.set(c,_),c.cache};try{let c=s(l,o);d||(i.emit(c),o.store.__autoTrackLastDiscoveryError!=null&&delete o.store.__autoTrackLastDiscoveryError)}catch(c){if(!d)throw c;o.store.__autoTrackLastDiscoveryError=c}};return t=new H([],r,{describeKind:"derived",...e}),t}function Je(s,e,t){if(typeof s=="function"){let n=s;return typeof e=="function"?Ee(n,e,t):Ee(n,void 0,e)}return Xe(s,e)}function L(s){let e=s.cache,t;if(s.subscribe(r=>{for(let[a,i]of r)a===g&&(e=i),a===p&&(t=i)})(),t)throw t;return e}function Xe(s,e){let t=ke(s,{...e,resubscribable:!0,resetOnTeardown:!0});return{get:()=>t.status==="sentinel"?L(t):t.cache,set:n=>t.emit(n),update:n=>{let r=t.status==="sentinel"?L(t):t.cache;t.emit(n(r))},subscribe:n=>{let r=!0;return t.subscribe(a=>{for(let[i,o]of a)if(i===g){if(r){r=!1;continue}n(o)}})},meta:t.meta,_node:t}}function Ee(s,e,t){let n=Me(a=>s(i=>{let o=i._node;return o.status==="sentinel"&&L(o),a(o)}),{...t,resubscribable:!0,resetOnTeardown:!0}),r={get:()=>n.status==="sentinel"?L(n):n.cache,subscribe:a=>{let i=!0;return n.subscribe(o=>{for(let[d,l]of o)if(d===g){if(i){i=!1;continue}a(l)}})},meta:n.meta,_node:n};if(e){let a=d=>d.get(),i=(d,l)=>d.set(l),o=r;return o.set=d=>e(a,i,d),o.update=d=>{let l=n.status==="sentinel"?L(n):n.cache;return e(a,i,d(l))},o}return r}0&&(module.exports={atom});
|