@graphrefly/ts 0.0.1 → 0.0.3
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/README.md +197 -117
- package/dist/actions-types-CH-XCU9O.d.cts +657 -0
- package/dist/actions-types-w2iPQTkv.d.ts +657 -0
- package/dist/adapters/index.cjs +5157 -2951
- package/dist/adapters/index.cjs.map +1 -1
- package/dist/adapters/index.d.cts +207 -70
- package/dist/adapters/index.d.ts +207 -70
- package/dist/adapters/index.js +3738 -1688
- package/dist/adapters/index.js.map +1 -1
- package/dist/adapters/nestjs/microservices.cjs +841 -0
- package/dist/adapters/nestjs/microservices.cjs.map +1 -0
- package/dist/adapters/nestjs/microservices.d.cts +45 -0
- package/dist/adapters/nestjs/microservices.d.ts +45 -0
- package/dist/adapters/nestjs/microservices.js +206 -0
- package/dist/adapters/nestjs/microservices.js.map +1 -0
- package/dist/adapters/nestjs/native.cjs +1391 -0
- package/dist/adapters/nestjs/native.cjs.map +1 -0
- package/dist/adapters/nestjs/native.d.cts +111 -0
- package/dist/adapters/nestjs/native.d.ts +111 -0
- package/dist/adapters/nestjs/native.js +577 -0
- package/dist/adapters/nestjs/native.js.map +1 -0
- package/dist/adapters/nestjs/websockets.cjs +924 -0
- package/dist/adapters/nestjs/websockets.cjs.map +1 -0
- package/dist/adapters/nestjs/websockets.d.cts +47 -0
- package/dist/adapters/nestjs/websockets.d.ts +47 -0
- package/dist/adapters/nestjs/websockets.js +286 -0
- package/dist/adapters/nestjs/websockets.js.map +1 -0
- package/dist/adapters/nestjs.cjs +1085 -0
- package/dist/adapters/nestjs.cjs.map +1 -0
- package/dist/adapters/nestjs.d.cts +385 -0
- package/dist/adapters/nestjs.d.ts +385 -0
- package/dist/adapters/nestjs.js +112 -0
- package/dist/adapters/nestjs.js.map +1 -0
- package/dist/adapters/observe-storage.d.cts +3 -3
- package/dist/adapters/observe-storage.d.ts +3 -3
- package/dist/adapters/observe-storage.js +4 -4
- package/dist/adapters/react.cjs.map +1 -1
- package/dist/adapters/react.d.cts +2 -2
- package/dist/adapters/react.d.ts +2 -2
- package/dist/adapters/react.js +1 -1
- package/dist/adapters/solid.cjs.map +1 -1
- package/dist/adapters/solid.d.cts +2 -2
- package/dist/adapters/solid.d.ts +2 -2
- package/dist/adapters/solid.js +1 -1
- package/dist/adapters/svelte.cjs.map +1 -1
- package/dist/adapters/svelte.d.cts +2 -2
- package/dist/adapters/svelte.d.ts +2 -2
- package/dist/adapters/svelte.js +1 -1
- package/dist/adapters/vue.cjs.map +1 -1
- package/dist/adapters/vue.d.cts +2 -2
- package/dist/adapters/vue.d.ts +2 -2
- package/dist/adapters/vue.js +1 -1
- package/dist/{agent-runtime-BesGDZcB.d.ts → agent-runtime-types-core-CKwrBDyi.d.ts} +171 -320
- package/dist/{agent-runtime-DZTJ3C-p.d.cts → agent-runtime-types-core-bfl4m0vM.d.cts} +171 -320
- package/dist/agent-runtime-types-tool-BLPV3azj.d.cts +695 -0
- package/dist/agent-runtime-types-tool-hwqvVqNt.d.ts +695 -0
- package/dist/agentic-memory-retention-CLwI76JK.d.ts +14 -0
- package/dist/agentic-memory-retention-Cz8GR6ie.d.cts +14 -0
- package/dist/{agentic-memory-DfuVZ-lY.d.cts → agentic-memory-types-JDr7MPhh.d.cts} +13 -57
- package/dist/{agentic-memory-BmRCvh0d.d.ts → agentic-memory-types-khYJgzKL.d.ts} +13 -57
- package/dist/{capability-admission-B0BzqAm5.d.cts → capability-admission-B8RNFyaZ.d.cts} +3 -3
- package/dist/{capability-admission-g0mn9hpq.d.ts → capability-admission-Dkw1Xz3r.d.ts} +3 -3
- package/dist/chunk-2KUAG2GZ.js +9693 -0
- package/dist/chunk-2KUAG2GZ.js.map +1 -0
- package/dist/{chunk-CZNV3VXM.js → chunk-3J7UPZL5.js} +11 -11
- package/dist/{chunk-HKK2JD7Z.js → chunk-3LYI6ADX.js} +12 -125
- package/dist/chunk-3LYI6ADX.js.map +1 -0
- package/dist/{chunk-YXMZ2N6J.js → chunk-4M37FH2I.js} +1071 -1025
- package/dist/chunk-4M37FH2I.js.map +1 -0
- package/dist/{chunk-YDSIVHRR.js → chunk-4NWSNI4K.js} +1598 -1584
- package/dist/chunk-4NWSNI4K.js.map +1 -0
- package/dist/{chunk-Z2ANQ6JW.js → chunk-4Q77MMJY.js} +2 -2
- package/dist/{chunk-SS2A464I.js → chunk-54WPEODM.js} +3 -3
- package/dist/chunk-54WPEODM.js.map +1 -0
- package/dist/chunk-6E76H4OU.js +132 -0
- package/dist/chunk-6E76H4OU.js.map +1 -0
- package/dist/chunk-7GOTIIQ7.js +819 -0
- package/dist/chunk-7GOTIIQ7.js.map +1 -0
- package/dist/{chunk-V7CIJE4B.js → chunk-DKFWDTVY.js} +92 -9
- package/dist/chunk-DKFWDTVY.js.map +1 -0
- package/dist/{chunk-FBUU43PM.js → chunk-E4QCH32M.js} +448 -446
- package/dist/chunk-E4QCH32M.js.map +1 -0
- package/dist/{chunk-XKXWK2KP.js → chunk-GXU6WFEJ.js} +1157 -1021
- package/dist/chunk-GXU6WFEJ.js.map +1 -0
- package/dist/{chunk-K3FXTC3I.js → chunk-HJACH5PU.js} +3 -3
- package/dist/{chunk-GTPCOEOZ.js → chunk-IDMLXLLG.js} +3 -3
- package/dist/{chunk-DKP56CSW.js → chunk-JKAYLDQV.js} +2 -2
- package/dist/{chunk-4VLAQHZI.js → chunk-K7FB3JTD.js} +17 -1
- package/dist/chunk-K7FB3JTD.js.map +1 -0
- package/dist/{chunk-43BKLFZU.js → chunk-KFURM6FM.js} +10 -10
- package/dist/{chunk-H75VXTGT.js → chunk-L6LDXRWE.js} +3 -3
- package/dist/{chunk-H75VXTGT.js.map → chunk-L6LDXRWE.js.map} +1 -1
- package/dist/chunk-MCOFHMUU.js +4131 -0
- package/dist/chunk-MCOFHMUU.js.map +1 -0
- package/dist/chunk-MQEQMS7B.js +1009 -0
- package/dist/chunk-MQEQMS7B.js.map +1 -0
- package/dist/chunk-MTELVIYR.js +1421 -0
- package/dist/chunk-MTELVIYR.js.map +1 -0
- package/dist/{chunk-3JR3EDB2.js → chunk-NNDIFUKX.js} +121 -115
- package/dist/chunk-NNDIFUKX.js.map +1 -0
- package/dist/{chunk-2747WN4Y.js → chunk-PUSRRALM.js} +3 -3
- package/dist/{chunk-QFY4AFY4.js → chunk-PVC7WDKI.js} +58 -52
- package/dist/chunk-PVC7WDKI.js.map +1 -0
- package/dist/{chunk-VTHLCFN4.js → chunk-RAHNUYA5.js} +2 -2
- package/dist/chunk-TQPCAIQI.js +612 -0
- package/dist/chunk-TQPCAIQI.js.map +1 -0
- package/dist/{chunk-IXZBUWSP.js → chunk-UEMN5URK.js} +2 -2
- package/dist/chunk-WOS7RJYZ.js +1320 -0
- package/dist/chunk-WOS7RJYZ.js.map +1 -0
- package/dist/{chunk-6PHB5CJS.js → chunk-ZLFRB6FI.js} +2 -2
- package/dist/composition/index.cjs +1228 -1076
- package/dist/composition/index.cjs.map +1 -1
- package/dist/composition/index.d.cts +3 -3
- package/dist/composition/index.d.ts +3 -3
- package/dist/composition/index.js +4 -4
- package/dist/core/index.cjs +1198 -1046
- package/dist/core/index.cjs.map +1 -1
- package/dist/core/index.d.cts +23 -2
- package/dist/core/index.d.ts +23 -2
- package/dist/core/index.js +2 -2
- package/dist/cqrs/index.d.cts +3 -3
- package/dist/cqrs/index.d.ts +3 -3
- package/dist/cqrs/messaging.d.cts +4 -4
- package/dist/cqrs/messaging.d.ts +4 -4
- package/dist/cqrs/work-queue.d.cts +5 -5
- package/dist/cqrs/work-queue.d.ts +5 -5
- package/dist/data-structures/index.cjs +1226 -1074
- package/dist/data-structures/index.cjs.map +1 -1
- package/dist/data-structures/index.d.cts +8 -7
- package/dist/data-structures/index.d.ts +8 -7
- package/dist/data-structures/index.js +6 -5
- package/dist/{describe-DYMw_l1C.d.cts → describe-BumQ-3_0.d.cts} +1 -1
- package/dist/{describe-BpyJuWkw.d.ts → describe-cYr_Z5zm.d.ts} +1 -1
- package/dist/executors/tool-provider-adapters.cjs +3091 -0
- package/dist/executors/tool-provider-adapters.cjs.map +1 -0
- package/dist/executors/tool-provider-adapters.d.cts +174 -0
- package/dist/executors/tool-provider-adapters.d.ts +174 -0
- package/dist/executors/tool-provider-adapters.js +1336 -0
- package/dist/executors/tool-provider-adapters.js.map +1 -0
- package/dist/executors/tool-provider-runtime.cjs +5178 -0
- package/dist/executors/tool-provider-runtime.cjs.map +1 -0
- package/dist/executors/tool-provider-runtime.d.cts +17 -0
- package/dist/executors/tool-provider-runtime.d.ts +17 -0
- package/dist/executors/tool-provider-runtime.js +15 -0
- package/dist/executors/tool-provider-runtime.js.map +1 -0
- package/dist/executors/tool-provider.cjs +6392 -0
- package/dist/executors/tool-provider.cjs.map +1 -0
- package/dist/executors/tool-provider.d.cts +60 -0
- package/dist/executors/tool-provider.d.ts +60 -0
- package/dist/executors/tool-provider.js +89 -0
- package/dist/executors/tool-provider.js.map +1 -0
- package/dist/executors/work-queue.d.cts +6 -6
- package/dist/executors/work-queue.d.ts +6 -6
- package/dist/graph/index.cjs +1499 -1341
- package/dist/graph/index.cjs.map +1 -1
- package/dist/graph/index.d.cts +9 -8
- package/dist/graph/index.d.ts +9 -8
- package/dist/graph/index.js +23 -22
- package/dist/{graph-DCEWh4T2.d.cts → graph-C1C-wb0L.d.cts} +266 -137
- package/dist/{graph-D-1-SQeC.d.ts → graph-CS0b4V9B.d.ts} +266 -137
- package/dist/{index-72VZC0-E.d.cts → index-DLrNopda.d.cts} +151 -10
- package/dist/{index-Bmxeu0nK.d.ts → index-DzJni3_6.d.ts} +151 -10
- package/dist/index.cjs +3397 -3140
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +12 -9
- package/dist/index.d.ts +12 -9
- package/dist/index.js +110 -109
- package/dist/inspection/boundary.d.cts +4 -4
- package/dist/inspection/boundary.d.ts +4 -4
- package/dist/measurements-BWAnochv.d.ts +294 -0
- package/dist/measurements-B_gJfD8h.d.cts +294 -0
- package/dist/messaging/index.cjs +57 -51
- package/dist/messaging/index.cjs.map +1 -1
- package/dist/messaging/index.d.cts +11 -276
- package/dist/messaging/index.d.ts +11 -276
- package/dist/messaging/index.js +1 -1
- package/dist/operators/index.cjs +1228 -1076
- package/dist/operators/index.cjs.map +1 -1
- package/dist/operators/index.d.cts +5 -5
- package/dist/operators/index.d.ts +5 -5
- package/dist/operators/index.js +5 -5
- package/dist/orchestration/index.cjs +8844 -6071
- package/dist/orchestration/index.cjs.map +1 -1
- package/dist/orchestration/index.d.cts +171 -224
- package/dist/orchestration/index.d.ts +171 -224
- package/dist/orchestration/index.js +42 -991
- package/dist/orchestration/index.js.map +1 -1
- package/dist/orchestration/messaging.d.cts +5 -8
- package/dist/orchestration/messaging.d.ts +5 -8
- package/dist/orchestration/work-queue.cjs +1243 -5
- package/dist/orchestration/work-queue.cjs.map +1 -1
- package/dist/orchestration/work-queue.d.cts +121 -10
- package/dist/orchestration/work-queue.d.ts +121 -10
- package/dist/orchestration/work-queue.js +1067 -4
- package/dist/orchestration/work-queue.js.map +1 -1
- package/dist/patterns/event-flow.cjs +6 -20
- package/dist/patterns/event-flow.cjs.map +1 -1
- package/dist/patterns/event-flow.d.cts +4 -4
- package/dist/patterns/event-flow.d.ts +4 -4
- package/dist/patterns/event-flow.js +2 -2
- package/dist/patterns/index.cjs +453 -465
- package/dist/patterns/index.cjs.map +1 -1
- package/dist/patterns/index.d.cts +6 -5
- package/dist/patterns/index.d.ts +6 -5
- package/dist/patterns/index.js +3 -3
- package/dist/process-types-BB7oRhX3.d.cts +200 -0
- package/dist/process-types-QNhyoYJ8.d.ts +200 -0
- package/dist/{reactive-collection-DNV0-gFi.d.cts → reactive-collection-BYlWvtnp.d.cts} +4 -34
- package/dist/{reactive-collection-BAmfrGjd.d.ts → reactive-collection-efOEdGFN.d.ts} +4 -34
- package/dist/{reactive-collection-storage-BNEldDyi.d.cts → reactive-collection-storage-BjoLsoiC.d.cts} +5 -5
- package/dist/{reactive-collection-storage-YZsAQsWK.d.ts → reactive-collection-storage-DwW6UuK_.d.ts} +5 -5
- package/dist/{reactive-map-DRD1LJ2H.d.cts → reactive-map-BHacbIqz.d.cts} +7 -2
- package/dist/{reactive-map-EsDiCmJk.d.ts → reactive-map-DN4Jyqnf.d.ts} +7 -2
- package/dist/render/index.d.cts +2 -2
- package/dist/render/index.d.ts +2 -2
- package/dist/scheduled-readiness-BmqXxnzX.d.ts +91 -0
- package/dist/scheduled-readiness-CYSw7KDE.d.cts +91 -0
- package/dist/semantic-memory-graph-B_LwbM-E.d.cts +30 -0
- package/dist/semantic-memory-graph-rsFNNhwn.d.ts +30 -0
- package/dist/{semantic-memory-graph-DKuNzuWw.d.cts → semantic-memory-graph-types-Y73bbwVI.d.cts} +2 -28
- package/dist/{semantic-memory-graph-uwbwJdhe.d.ts → semantic-memory-graph-types-safmPkuX.d.ts} +2 -28
- package/dist/solutions/index.cjs +6353 -6169
- package/dist/solutions/index.cjs.map +1 -1
- package/dist/solutions/index.d.cts +12 -10
- package/dist/solutions/index.d.ts +12 -10
- package/dist/solutions/index.js +5 -5
- package/dist/solutions/reactive-layout/browser/index.cjs +116 -108
- package/dist/solutions/reactive-layout/browser/index.cjs.map +1 -1
- package/dist/solutions/reactive-layout/browser/index.d.cts +4 -4
- package/dist/solutions/reactive-layout/browser/index.d.ts +4 -4
- package/dist/solutions/reactive-layout/browser/index.js +3 -3
- package/dist/solutions/reactive-layout/index.cjs +3578 -3350
- package/dist/solutions/reactive-layout/index.cjs.map +1 -1
- package/dist/solutions/reactive-layout/index.d.cts +32 -576
- package/dist/solutions/reactive-layout/index.d.ts +32 -576
- package/dist/solutions/reactive-layout/index.js +65 -5
- package/dist/solutions/reactive-layout/node-canvas/index.cjs +127 -117
- package/dist/solutions/reactive-layout/node-canvas/index.cjs.map +1 -1
- package/dist/solutions/reactive-layout/node-canvas/index.d.cts +4 -4
- package/dist/solutions/reactive-layout/node-canvas/index.d.ts +4 -4
- package/dist/solutions/reactive-layout/node-canvas/index.js +3 -3
- package/dist/solutions/reactive-layout/react-native/index.cjs +127 -117
- package/dist/solutions/reactive-layout/react-native/index.cjs.map +1 -1
- package/dist/solutions/reactive-layout/react-native/index.d.cts +4 -4
- package/dist/solutions/reactive-layout/react-native/index.d.ts +4 -4
- package/dist/solutions/reactive-layout/react-native/index.js +3 -3
- package/dist/solutions/reactive-layout/skia/index.cjs +127 -117
- package/dist/solutions/reactive-layout/skia/index.cjs.map +1 -1
- package/dist/solutions/reactive-layout/skia/index.d.cts +4 -4
- package/dist/solutions/reactive-layout/skia/index.d.ts +4 -4
- package/dist/solutions/reactive-layout/skia/index.js +3 -3
- package/dist/solutions/work-item/actions.cjs +1609 -1428
- package/dist/solutions/work-item/actions.cjs.map +1 -1
- package/dist/solutions/work-item/actions.d.cts +23 -184
- package/dist/solutions/work-item/actions.d.ts +23 -184
- package/dist/solutions/work-item/actions.js +1558 -934
- package/dist/solutions/work-item/actions.js.map +1 -1
- package/dist/solutions/work-item/scheduling.cjs +9181 -1838
- package/dist/solutions/work-item/scheduling.cjs.map +1 -1
- package/dist/solutions/work-item/scheduling.d.cts +1763 -328
- package/dist/solutions/work-item/scheduling.d.ts +1763 -328
- package/dist/solutions/work-item/scheduling.js +117 -3
- package/dist/solutions/work-item/work-queue.d.cts +7 -7
- package/dist/solutions/work-item/work-queue.d.ts +7 -7
- package/dist/sources/browser.cjs +1318 -1083
- package/dist/sources/browser.cjs.map +1 -1
- package/dist/sources/browser.d.cts +22 -6
- package/dist/sources/browser.d.ts +22 -6
- package/dist/sources/browser.js +4 -4
- package/dist/sources/browser.js.map +1 -1
- package/dist/sources/index.cjs +1318 -1083
- package/dist/sources/index.cjs.map +1 -1
- package/dist/sources/index.d.cts +4 -4
- package/dist/sources/index.d.ts +4 -4
- package/dist/sources/index.js +4 -4
- package/dist/sources/node.d.cts +3 -3
- package/dist/sources/node.d.ts +3 -3
- package/dist/storage/browser.cjs +16 -0
- package/dist/storage/browser.cjs.map +1 -1
- package/dist/storage/browser.js +3 -3
- package/dist/storage/index.cjs +16 -0
- package/dist/storage/index.cjs.map +1 -1
- package/dist/storage/index.d.cts +5 -4
- package/dist/storage/index.d.ts +5 -4
- package/dist/storage/index.js +6 -6
- package/dist/storage/node.cjs +16 -0
- package/dist/storage/node.cjs.map +1 -1
- package/dist/storage/node.js +3 -3
- package/dist/{store-C-joM4gh.d.ts → store-6_CHF6Ge.d.ts} +1 -1
- package/dist/{store-CNJwmT-h.d.cts → store-BljX8RkQ.d.cts} +1 -1
- package/dist/types-BAw2QVVE.d.cts +274 -0
- package/dist/types-BUbbbh4f.d.cts +34 -0
- package/dist/types-CMnzoL54.d.cts +457 -0
- package/dist/{types-CcPIn7sy.d.cts → types-CTN3XoMl.d.cts} +57 -108
- package/dist/types-CV_ohy5T.d.cts +357 -0
- package/dist/{types-BsJvElYZ.d.ts → types-DChxk1vK.d.ts} +57 -108
- package/dist/types-DRu7SnLV.d.ts +274 -0
- package/dist/types-DeID_FRl.d.ts +34 -0
- package/dist/types-IhKH0hGW.d.ts +357 -0
- package/dist/types-ePlD2uyT.d.ts +457 -0
- package/dist/{work-item-runtime-qaVgsL0T.d.cts → work-item-runtime-types-BTxLskN5.d.cts} +3 -93
- package/dist/{work-item-runtime-C3M79vE9.d.ts → work-item-runtime-types-DAsZbb2y.d.ts} +3 -93
- package/dist/work-queue/index.cjs +957 -953
- package/dist/work-queue/index.cjs.map +1 -1
- package/dist/work-queue/index.d.cts +9 -357
- package/dist/work-queue/index.d.ts +9 -357
- package/dist/work-queue/index.js +957 -953
- package/dist/work-queue/index.js.map +1 -1
- package/package.json +611 -513
- package/dist/chunk-3JR3EDB2.js.map +0 -1
- package/dist/chunk-4VLAQHZI.js.map +0 -1
- package/dist/chunk-6XAIOL3X.js +0 -2407
- package/dist/chunk-6XAIOL3X.js.map +0 -1
- package/dist/chunk-FBUU43PM.js.map +0 -1
- package/dist/chunk-HKK2JD7Z.js.map +0 -1
- package/dist/chunk-PC3BTTBE.js +0 -3217
- package/dist/chunk-PC3BTTBE.js.map +0 -1
- package/dist/chunk-QFY4AFY4.js.map +0 -1
- package/dist/chunk-SS2A464I.js.map +0 -1
- package/dist/chunk-V7CIJE4B.js.map +0 -1
- package/dist/chunk-XKXWK2KP.js.map +0 -1
- package/dist/chunk-YDSIVHRR.js.map +0 -1
- package/dist/chunk-YXMZ2N6J.js.map +0 -1
- /package/dist/{chunk-CZNV3VXM.js.map → chunk-3J7UPZL5.js.map} +0 -0
- /package/dist/{chunk-Z2ANQ6JW.js.map → chunk-4Q77MMJY.js.map} +0 -0
- /package/dist/{chunk-K3FXTC3I.js.map → chunk-HJACH5PU.js.map} +0 -0
- /package/dist/{chunk-GTPCOEOZ.js.map → chunk-IDMLXLLG.js.map} +0 -0
- /package/dist/{chunk-DKP56CSW.js.map → chunk-JKAYLDQV.js.map} +0 -0
- /package/dist/{chunk-43BKLFZU.js.map → chunk-KFURM6FM.js.map} +0 -0
- /package/dist/{chunk-2747WN4Y.js.map → chunk-PUSRRALM.js.map} +0 -0
- /package/dist/{chunk-VTHLCFN4.js.map → chunk-RAHNUYA5.js.map} +0 -0
- /package/dist/{chunk-IXZBUWSP.js.map → chunk-UEMN5URK.js.map} +0 -0
- /package/dist/{chunk-6PHB5CJS.js.map → chunk-ZLFRB6FI.js.map} +0 -0
package/dist/sources/index.cjs
CHANGED
|
@@ -142,9 +142,16 @@ function sortedJsonValue(value, seen = /* @__PURE__ */ new Set(), path = "$", st
|
|
|
142
142
|
}
|
|
143
143
|
for (const key of Object.getOwnPropertyNames(value)) {
|
|
144
144
|
const isIndex = /^(0|[1-9]\d*)$/.test(key) && Number.isSafeInteger(Number(key)) && Number(key) < value.length;
|
|
145
|
+
const descriptor = Object.getOwnPropertyDescriptor(value, key);
|
|
146
|
+
if (descriptor !== void 0 && ("get" in descriptor || "set" in descriptor)) {
|
|
147
|
+
throw new TypeError(`stableJsonString: accessor property at ${path}.${key}`);
|
|
148
|
+
}
|
|
145
149
|
if (key !== "length" && !isIndex) {
|
|
146
150
|
throw new TypeError(`stableJsonString: non-index array property at ${path}.${key}`);
|
|
147
151
|
}
|
|
152
|
+
if (key !== "length" && descriptor !== void 0 && !descriptor.enumerable) {
|
|
153
|
+
throw new TypeError(`stableJsonString: non-enumerable array property at ${path}.${key}`);
|
|
154
|
+
}
|
|
148
155
|
}
|
|
149
156
|
const out2 = [];
|
|
150
157
|
for (let i = 0; i < value.length; i += 1) {
|
|
@@ -158,6 +165,15 @@ function sortedJsonValue(value, seen = /* @__PURE__ */ new Set(), path = "$", st
|
|
|
158
165
|
if (Object.getOwnPropertySymbols(value).length > 0) {
|
|
159
166
|
throw new TypeError(`stableJsonString: symbol-keyed properties at ${path}`);
|
|
160
167
|
}
|
|
168
|
+
for (const key of Object.getOwnPropertyNames(value)) {
|
|
169
|
+
const descriptor = Object.getOwnPropertyDescriptor(value, key);
|
|
170
|
+
if (descriptor !== void 0 && ("get" in descriptor || "set" in descriptor)) {
|
|
171
|
+
throw new TypeError(`stableJsonString: accessor property at ${path}.${key}`);
|
|
172
|
+
}
|
|
173
|
+
if (descriptor !== void 0 && !descriptor.enumerable) {
|
|
174
|
+
throw new TypeError(`stableJsonString: non-enumerable property at ${path}.${key}`);
|
|
175
|
+
}
|
|
176
|
+
}
|
|
161
177
|
const out = /* @__PURE__ */ Object.create(null);
|
|
162
178
|
for (const key of Object.keys(value).sort()) {
|
|
163
179
|
out[key] = sortedJsonValue(
|
|
@@ -464,30 +480,6 @@ function drain() {
|
|
|
464
480
|
if (escaped !== null) throw escaped.e;
|
|
465
481
|
}
|
|
466
482
|
|
|
467
|
-
// src/batch/batch.ts
|
|
468
|
-
var active = null;
|
|
469
|
-
var boundaryOwner = null;
|
|
470
|
-
function currentBatch() {
|
|
471
|
-
return active !== null;
|
|
472
|
-
}
|
|
473
|
-
function currentBoundaryBatchToken() {
|
|
474
|
-
return active ?? boundaryOwner ?? void 0;
|
|
475
|
-
}
|
|
476
|
-
function deferToBatch(target, tier3Wave) {
|
|
477
|
-
if (active === null) return false;
|
|
478
|
-
if (!active.deferred.has(target)) active.order.push(target);
|
|
479
|
-
active.deferred.set(target, tier3Wave);
|
|
480
|
-
return true;
|
|
481
|
-
}
|
|
482
|
-
function deferAfterBatchForTarget(target, fn) {
|
|
483
|
-
if (active === null || !active.deferred.has(target)) return false;
|
|
484
|
-
const owner = active;
|
|
485
|
-
target.__deferBoundary(() => {
|
|
486
|
-
if (owner.committed) fn();
|
|
487
|
-
}, owner);
|
|
488
|
-
return true;
|
|
489
|
-
}
|
|
490
|
-
|
|
491
483
|
// src/dispatcher/index.ts
|
|
492
484
|
var PoolTable = class {
|
|
493
485
|
constructor(kind) {
|
|
@@ -794,6 +786,586 @@ function makeDepBookkeeping(depCount) {
|
|
|
794
786
|
};
|
|
795
787
|
}
|
|
796
788
|
|
|
789
|
+
// src/node/protocol-guards.ts
|
|
790
|
+
function terminalView(t) {
|
|
791
|
+
return t === void 0 ? false : t;
|
|
792
|
+
}
|
|
793
|
+
function normalizePullDemand(demand) {
|
|
794
|
+
if (typeof demand !== "object" || demand === null || Array.isArray(demand)) {
|
|
795
|
+
throw new Error("ctx.up: PULL requires { pullId, params? } demand payload (D269)");
|
|
796
|
+
}
|
|
797
|
+
const pullId = demand.pullId;
|
|
798
|
+
if (typeof pullId !== "string" && typeof pullId !== "symbol") {
|
|
799
|
+
throw new Error("ctx.up: PULL demand requires a string or symbol pullId (D269)");
|
|
800
|
+
}
|
|
801
|
+
const params = demand.params;
|
|
802
|
+
return params === void 0 ? { pullId } : { pullId, params };
|
|
803
|
+
}
|
|
804
|
+
function validateDownPayloads(msgs) {
|
|
805
|
+
for (const m of msgs) {
|
|
806
|
+
if (m[0] === "DATA" && m[1] === void 0) {
|
|
807
|
+
throw new Error("down: DATA requires a non-SENTINEL payload (R-data-payload)");
|
|
808
|
+
}
|
|
809
|
+
if (m[0] === "ERROR" && isInvalidErrorPayload(m[1])) {
|
|
810
|
+
throw new Error("down: ERROR requires a non-SENTINEL, non-boolean payload (R-data-payload)");
|
|
811
|
+
}
|
|
812
|
+
}
|
|
813
|
+
}
|
|
814
|
+
|
|
815
|
+
// src/node/runtime-accessors.ts
|
|
816
|
+
var constructingCore;
|
|
817
|
+
var constructingEnvironment;
|
|
818
|
+
var ownerTokens = /* @__PURE__ */ new WeakMap();
|
|
819
|
+
var topologyDepsChangedObservers = /* @__PURE__ */ new WeakMap();
|
|
820
|
+
var checkpointReaders = /* @__PURE__ */ new WeakMap();
|
|
821
|
+
var restoreWriters = /* @__PURE__ */ new WeakMap();
|
|
822
|
+
var runtimeReleasers = /* @__PURE__ */ new WeakMap();
|
|
823
|
+
var runtimeQuiescenceReaders = /* @__PURE__ */ new WeakMap();
|
|
824
|
+
var subscriberCountReaders = /* @__PURE__ */ new WeakMap();
|
|
825
|
+
var activationReaders = /* @__PURE__ */ new WeakMap();
|
|
826
|
+
var releasedNodes = /* @__PURE__ */ new WeakSet();
|
|
827
|
+
function withNodeCore(core, create) {
|
|
828
|
+
const prev = constructingCore;
|
|
829
|
+
constructingCore = core;
|
|
830
|
+
try {
|
|
831
|
+
return create();
|
|
832
|
+
} finally {
|
|
833
|
+
constructingCore = prev;
|
|
834
|
+
}
|
|
835
|
+
}
|
|
836
|
+
function takeConstructingNodeCore() {
|
|
837
|
+
const core = constructingCore;
|
|
838
|
+
constructingCore = void 0;
|
|
839
|
+
return core;
|
|
840
|
+
}
|
|
841
|
+
function withEnvironmentDrivers(environment, create) {
|
|
842
|
+
const prev = constructingEnvironment;
|
|
843
|
+
constructingEnvironment = environment;
|
|
844
|
+
try {
|
|
845
|
+
return create();
|
|
846
|
+
} finally {
|
|
847
|
+
constructingEnvironment = prev;
|
|
848
|
+
}
|
|
849
|
+
}
|
|
850
|
+
function takeConstructingEnvironmentDrivers() {
|
|
851
|
+
const environment = constructingEnvironment;
|
|
852
|
+
constructingEnvironment = void 0;
|
|
853
|
+
return environment;
|
|
854
|
+
}
|
|
855
|
+
function getNodeOwner(n) {
|
|
856
|
+
return ownerTokens.get(n);
|
|
857
|
+
}
|
|
858
|
+
function notifyTopologyDepsChanged(node, prevDeps, deps) {
|
|
859
|
+
topologyDepsChangedObservers.get(node)?.(node, prevDeps, deps);
|
|
860
|
+
}
|
|
861
|
+
|
|
862
|
+
// src/node/node-context-runtime.ts
|
|
863
|
+
function nodeBuildCtx(self) {
|
|
864
|
+
const kind = self._slot.handle ? self._slot.dispatcher.poolKind(self._slot.handle.poolId) : "sync";
|
|
865
|
+
if (kind === "sync") {
|
|
866
|
+
if (self._syncCtx === null) self._syncCtx = self._makeCtx();
|
|
867
|
+
self._refreshCtx(self._syncCtx);
|
|
868
|
+
return self._syncCtx;
|
|
869
|
+
}
|
|
870
|
+
return self._makeCtx({
|
|
871
|
+
waveData: self._dep.waveData.map((waves) => waves.map((w) => [...w])),
|
|
872
|
+
terminal: self._dep.terminalInput.map(terminalView),
|
|
873
|
+
latest: [...self._dep.prev]
|
|
874
|
+
});
|
|
875
|
+
}
|
|
876
|
+
function nodeMakeCtx(self, snapshot) {
|
|
877
|
+
const ctx = {
|
|
878
|
+
// Wave-owner boundary (D47): a SYNC fn's emit nests under the public entry that drove
|
|
879
|
+
// it (cheap inc/dec, no early drain); an ASYNC-pool fn re-enters here from its stashed
|
|
880
|
+
// ctx at depth 0, so this is the boundary that drains any rewireNext it issued.
|
|
881
|
+
up: (msgs, towardDep) => {
|
|
882
|
+
if (self._released) return;
|
|
883
|
+
enterWave();
|
|
884
|
+
try {
|
|
885
|
+
self._up(msgs, towardDep);
|
|
886
|
+
} finally {
|
|
887
|
+
exitWave();
|
|
888
|
+
}
|
|
889
|
+
},
|
|
890
|
+
down: (msgs) => {
|
|
891
|
+
if (self._released) return;
|
|
892
|
+
enterWave();
|
|
893
|
+
try {
|
|
894
|
+
self._down(msgs);
|
|
895
|
+
} finally {
|
|
896
|
+
exitWave();
|
|
897
|
+
}
|
|
898
|
+
},
|
|
899
|
+
waveData: snapshot?.waveData ?? self._dep.waveData,
|
|
900
|
+
terminal: snapshot?.terminal ?? self._dep.terminalInput.map(terminalView),
|
|
901
|
+
state: self._makeState(),
|
|
902
|
+
onDeactivation: (fn) => {
|
|
903
|
+
if (self._released) return;
|
|
904
|
+
self._hooks.onDeactivation.push(fn);
|
|
905
|
+
},
|
|
906
|
+
onInvalidate: (fn) => {
|
|
907
|
+
if (self._released) return;
|
|
908
|
+
self._hooks.onInvalidate.push(fn);
|
|
909
|
+
},
|
|
910
|
+
environment: () => self._slot.environment,
|
|
911
|
+
// R-rewire-deferred (D47): defer a self-dep-set mutation to the committed boundary.
|
|
912
|
+
rewireNext: {
|
|
913
|
+
subscribeDep: (dep, fn) => self._requestRewireNext({ kind: "add", dep, fn }),
|
|
914
|
+
unsubscribeDep: (dep, fn) => self._requestRewireNext({ kind: "remove", dep, fn }),
|
|
915
|
+
replaceDeps: (deps, fn) => self._requestRewireNext({ kind: "set", deps, fn })
|
|
916
|
+
},
|
|
917
|
+
// R-up-routing / R-pull (D269): deferred up — route a control/demand wave (e.g. PULL)
|
|
918
|
+
// up the declared cone at the committed boundary. The SELF-demand path: an
|
|
919
|
+
// immediate ctx.up whose delivery loops back re-enters this fn (D37 / R-reentrancy).
|
|
920
|
+
upNext: (msgs, towardDep) => self._requestUpNext(msgs, towardDep),
|
|
921
|
+
...self._control.activePull === void 0 ? {} : { pull: self._control.activePull },
|
|
922
|
+
[CTX_DEP_CACHE]: { latest: snapshot?.latest ?? self._dep.prev },
|
|
923
|
+
[CTX_NODE_BINDING]: {
|
|
924
|
+
dispatcher: self._slot.dispatcher,
|
|
925
|
+
create: (factory) => withEnvironmentDrivers(self._slot.environment, () => withNodeCore(self._core, factory))
|
|
926
|
+
}
|
|
927
|
+
};
|
|
928
|
+
if (self._slot.dynamic) {
|
|
929
|
+
ctx.track = (i) => ctx[CTX_DEP_CACHE]?.latest[i];
|
|
930
|
+
}
|
|
931
|
+
return ctx;
|
|
932
|
+
}
|
|
933
|
+
function nodeRefreshCtx(self, ctx) {
|
|
934
|
+
ctx.waveData = self._dep.waveData;
|
|
935
|
+
ctx.terminal = self._dep.terminalInput.map(terminalView);
|
|
936
|
+
if (self._control.activePull === void 0) {
|
|
937
|
+
delete ctx.pull;
|
|
938
|
+
} else {
|
|
939
|
+
ctx.pull = self._control.activePull;
|
|
940
|
+
}
|
|
941
|
+
ctx[CTX_DEP_CACHE] = { latest: self._dep.prev };
|
|
942
|
+
}
|
|
943
|
+
function nodeMakeState(self) {
|
|
944
|
+
return {
|
|
945
|
+
get: () => self._privateState.value,
|
|
946
|
+
set: (v) => {
|
|
947
|
+
self._privateState.value = v;
|
|
948
|
+
},
|
|
949
|
+
persist: (on = true) => {
|
|
950
|
+
self._privateState.persist = on;
|
|
951
|
+
}
|
|
952
|
+
};
|
|
953
|
+
}
|
|
954
|
+
|
|
955
|
+
// src/node/node-input-runtime.ts
|
|
956
|
+
function nodeRecordDepProjection(self, idx, delivery) {
|
|
957
|
+
const token = delivery?.wave ?? {};
|
|
958
|
+
if (self._dep.waveTokens[idx] !== token) {
|
|
959
|
+
self._dep.waveData[idx].push([]);
|
|
960
|
+
self._dep.waveTokens[idx] = token;
|
|
961
|
+
}
|
|
962
|
+
return self._dep.waveData[idx][self._dep.waveData[idx].length - 1];
|
|
963
|
+
}
|
|
964
|
+
function nodeDepProjectionHasData(self, idx) {
|
|
965
|
+
const projection = self._dep.waveData[idx][self._dep.waveData[idx].length - 1];
|
|
966
|
+
return projection?.some((v) => v !== SENTINEL) ?? false;
|
|
967
|
+
}
|
|
968
|
+
function nodeReceiveFromDep(self, idx, msg, delivery) {
|
|
969
|
+
if (self._released) return;
|
|
970
|
+
const t = msg[0];
|
|
971
|
+
if (t === "START") return;
|
|
972
|
+
const isLastInDeliveredWave = delivery?.last ?? true;
|
|
973
|
+
if (self._value.terminal !== void 0) {
|
|
974
|
+
if (t === "TEARDOWN") self._down([["TEARDOWN"]]);
|
|
975
|
+
return;
|
|
976
|
+
}
|
|
977
|
+
if (t === "INVALIDATE") {
|
|
978
|
+
const projection = self._recordDepProjection(idx, delivery);
|
|
979
|
+
projection.push(SENTINEL);
|
|
980
|
+
if (projection.some((v) => v !== SENTINEL) && isLastInDeliveredWave) self._maybeRun();
|
|
981
|
+
self._dep.prev[idx] = SENTINEL;
|
|
982
|
+
self._dep.hasData[idx] = false;
|
|
983
|
+
self._dep.batch[idx] = null;
|
|
984
|
+
if (self._dep.dirty[idx]) {
|
|
985
|
+
self._dep.dirty[idx] = false;
|
|
986
|
+
self._wave.pending--;
|
|
987
|
+
}
|
|
988
|
+
if (self._control.pausedDepWaveOccurred && self._dep.batch.every((b) => b === null)) {
|
|
989
|
+
self._control.pausedDepWaveOccurred = false;
|
|
990
|
+
}
|
|
991
|
+
const hadData = self._value.hasData;
|
|
992
|
+
self._invalidate();
|
|
993
|
+
if (self._wave.pending === 0 && self._wave.emittedDirtyThisWave) {
|
|
994
|
+
if (!hadData) self._down([["RESOLVED"]]);
|
|
995
|
+
else self._wave.emittedDirtyThisWave = false;
|
|
996
|
+
}
|
|
997
|
+
self._fireOwedDemandIfReady();
|
|
998
|
+
return;
|
|
999
|
+
}
|
|
1000
|
+
if (isTerminal(t)) {
|
|
1001
|
+
const isError = t === "ERROR";
|
|
1002
|
+
const errPayload = isError ? msg[1] : void 0;
|
|
1003
|
+
self._dep.terminal[idx] = isError ? errPayload : true;
|
|
1004
|
+
self._dep.terminalInput[idx] = isError ? errPayload : true;
|
|
1005
|
+
self._releaseDepDirty(idx);
|
|
1006
|
+
const ranValueBeforeTerminal = self._depProjectionHasData(idx) && isLastInDeliveredWave;
|
|
1007
|
+
if (ranValueBeforeTerminal) self._maybeRun();
|
|
1008
|
+
if (isError && self._slot.errorWhenDepsError) {
|
|
1009
|
+
self._down([["ERROR", errPayload]]);
|
|
1010
|
+
} else if (self._slot.terminalAsRealInput) {
|
|
1011
|
+
if (ranValueBeforeTerminal) {
|
|
1012
|
+
self._fireOwedDemandIfReady();
|
|
1013
|
+
return;
|
|
1014
|
+
}
|
|
1015
|
+
self._maybeRun();
|
|
1016
|
+
} else if (self._slot.completeWhenDepsComplete && self._allDepsTerminal()) {
|
|
1017
|
+
self._down([["COMPLETE"]]);
|
|
1018
|
+
} else {
|
|
1019
|
+
self._settleAfterAbsorbedTerminal();
|
|
1020
|
+
}
|
|
1021
|
+
self._fireOwedDemandIfReady();
|
|
1022
|
+
return;
|
|
1023
|
+
}
|
|
1024
|
+
if (t === "TEARDOWN") {
|
|
1025
|
+
self._down([["TEARDOWN"]]);
|
|
1026
|
+
return;
|
|
1027
|
+
}
|
|
1028
|
+
if (t === "DIRTY") {
|
|
1029
|
+
if (!self._dep.dirty[idx]) {
|
|
1030
|
+
self._dep.dirty[idx] = true;
|
|
1031
|
+
self._wave.pending++;
|
|
1032
|
+
self._dep.tier[idx] = 2;
|
|
1033
|
+
self._markDirty();
|
|
1034
|
+
}
|
|
1035
|
+
return;
|
|
1036
|
+
}
|
|
1037
|
+
if (t === "DATA") {
|
|
1038
|
+
const v = msg[1];
|
|
1039
|
+
self._recordDepProjection(idx, delivery).push(v);
|
|
1040
|
+
const b = self._dep.batch[idx];
|
|
1041
|
+
if (b === null) self._dep.batch[idx] = [v];
|
|
1042
|
+
else b.push(v);
|
|
1043
|
+
self._dep.prev[idx] = v;
|
|
1044
|
+
self._dep.hasData[idx] = true;
|
|
1045
|
+
self._dep.tier[idx] = 3;
|
|
1046
|
+
if (self._dep.dirty[idx]) {
|
|
1047
|
+
self._dep.dirty[idx] = false;
|
|
1048
|
+
self._wave.pending--;
|
|
1049
|
+
}
|
|
1050
|
+
if (isLastInDeliveredWave) self._maybeRun();
|
|
1051
|
+
self._fireOwedDemandIfReady();
|
|
1052
|
+
return;
|
|
1053
|
+
}
|
|
1054
|
+
if (t === "RESOLVED") {
|
|
1055
|
+
self._recordDepProjection(idx, delivery);
|
|
1056
|
+
self._dep.tier[idx] = 3;
|
|
1057
|
+
if (self._dep.dirty[idx]) {
|
|
1058
|
+
self._dep.dirty[idx] = false;
|
|
1059
|
+
self._wave.pending--;
|
|
1060
|
+
}
|
|
1061
|
+
if (isLastInDeliveredWave) self._maybeRun();
|
|
1062
|
+
self._fireOwedDemandIfReady();
|
|
1063
|
+
return;
|
|
1064
|
+
}
|
|
1065
|
+
}
|
|
1066
|
+
function nodeReleaseDepDirty(self, idx) {
|
|
1067
|
+
if (self._dep.dirty[idx]) {
|
|
1068
|
+
self._dep.dirty[idx] = false;
|
|
1069
|
+
self._wave.pending--;
|
|
1070
|
+
}
|
|
1071
|
+
}
|
|
1072
|
+
function nodeSettleAfterAbsorbedTerminal(self) {
|
|
1073
|
+
if (self._wave.pending !== 0 || !self._wave.emittedDirtyThisWave) return;
|
|
1074
|
+
const sawData = self._dep.batch.some((b) => b !== null && b.length > 0);
|
|
1075
|
+
if (sawData) self._maybeRun();
|
|
1076
|
+
if (self._wave.emittedDirtyThisWave) self._down([["RESOLVED"]]);
|
|
1077
|
+
}
|
|
1078
|
+
function nodeMarkDirty(self) {
|
|
1079
|
+
self._value.status = "dirty";
|
|
1080
|
+
if (self._isPullQuiet()) return;
|
|
1081
|
+
if (!self._wave.emittedDirtyThisWave) {
|
|
1082
|
+
self._wave.emittedDirtyThisWave = true;
|
|
1083
|
+
self._emitToSubs(["DIRTY"]);
|
|
1084
|
+
}
|
|
1085
|
+
}
|
|
1086
|
+
function nodeMaybeRun(self) {
|
|
1087
|
+
if (self._wave.inDepMutation) {
|
|
1088
|
+
self._wave.rewireRunPending = true;
|
|
1089
|
+
return;
|
|
1090
|
+
}
|
|
1091
|
+
if (self._slot.pausable === true && (self._isPaused() || self._isPullQuiet())) {
|
|
1092
|
+
self._control.pausedDepWaveOccurred = true;
|
|
1093
|
+
return;
|
|
1094
|
+
}
|
|
1095
|
+
self._tryRun();
|
|
1096
|
+
}
|
|
1097
|
+
function nodeSettleRewire(self) {
|
|
1098
|
+
if (self._slot.pausable === true && self._isPaused()) {
|
|
1099
|
+
self._control.pausedDepWaveOccurred = true;
|
|
1100
|
+
return;
|
|
1101
|
+
}
|
|
1102
|
+
if (self._wave.pending > 0) return;
|
|
1103
|
+
if (self._slot.handle === null) {
|
|
1104
|
+
self._passthroughEmit();
|
|
1105
|
+
return;
|
|
1106
|
+
}
|
|
1107
|
+
if (!self._wave.hasCalledFnOnce && !(self._slot.partial || self._allDepsSettled())) return;
|
|
1108
|
+
self._markDirty();
|
|
1109
|
+
self._runWave();
|
|
1110
|
+
}
|
|
1111
|
+
function nodeTryRun(self) {
|
|
1112
|
+
if (self._wave.pending > 0) return;
|
|
1113
|
+
if (self._slot.handle === null) {
|
|
1114
|
+
self._passthroughEmit();
|
|
1115
|
+
return;
|
|
1116
|
+
}
|
|
1117
|
+
if (!self._wave.hasCalledFnOnce) {
|
|
1118
|
+
if (self._slot.partial || self._allDepsSettled()) self._runWave();
|
|
1119
|
+
return;
|
|
1120
|
+
}
|
|
1121
|
+
self._runWave();
|
|
1122
|
+
}
|
|
1123
|
+
function nodeAllDepsSettled(self) {
|
|
1124
|
+
for (let i = 0; i < self._slot.deps.length; i++) {
|
|
1125
|
+
if (self._dep.hasData[i]) continue;
|
|
1126
|
+
if (self._slot.terminalAsRealInput && self._dep.terminal[i] !== void 0) continue;
|
|
1127
|
+
return false;
|
|
1128
|
+
}
|
|
1129
|
+
return true;
|
|
1130
|
+
}
|
|
1131
|
+
function nodePassthroughEmit(self) {
|
|
1132
|
+
const b = self._dep.batch[0];
|
|
1133
|
+
if (b !== null && b.length > 0) {
|
|
1134
|
+
self._down([["DATA", b[b.length - 1]]]);
|
|
1135
|
+
} else if (self._wave.emittedDirtyThisWave) {
|
|
1136
|
+
self._down([["RESOLVED"]]);
|
|
1137
|
+
}
|
|
1138
|
+
self._dep.batch[0] = null;
|
|
1139
|
+
self._wave.emittedDirtyThisWave = false;
|
|
1140
|
+
}
|
|
1141
|
+
function nodeRunWave(self) {
|
|
1142
|
+
if (self._wave.insideRunWave)
|
|
1143
|
+
throw new Error(
|
|
1144
|
+
"synchronous feedback cycle: node fn re-entered its own wave (R-reentrancy / D37)"
|
|
1145
|
+
);
|
|
1146
|
+
self._wave.hasCalledFnOnce = true;
|
|
1147
|
+
self._hooks.onInvalidate = [];
|
|
1148
|
+
self._hooks.onDeactivation = [];
|
|
1149
|
+
const ctx = self._buildCtx();
|
|
1150
|
+
const wasDirty = self._wave.emittedDirtyThisWave;
|
|
1151
|
+
self._wave.emittedSettleThisWave = false;
|
|
1152
|
+
self._wave.insideRunWave = true;
|
|
1153
|
+
try {
|
|
1154
|
+
self._slot.dispatcher.invoke(self._slot.handle, ctx);
|
|
1155
|
+
} finally {
|
|
1156
|
+
self._wave.insideRunWave = false;
|
|
1157
|
+
}
|
|
1158
|
+
if (wasDirty && !self._wave.emittedSettleThisWave && self._value.terminal === void 0 && !self._isAsyncPool()) {
|
|
1159
|
+
self._down([["RESOLVED"]]);
|
|
1160
|
+
}
|
|
1161
|
+
for (let i = 0; i < self._dep.batch.length; i++) {
|
|
1162
|
+
self._dep.batch[i] = null;
|
|
1163
|
+
self._dep.waveData[i] = [];
|
|
1164
|
+
self._dep.waveTokens[i] = void 0;
|
|
1165
|
+
self._dep.terminalInput[i] = void 0;
|
|
1166
|
+
}
|
|
1167
|
+
self._wave.emittedDirtyThisWave = false;
|
|
1168
|
+
}
|
|
1169
|
+
|
|
1170
|
+
// src/node/node-runtime-host.ts
|
|
1171
|
+
function nodeRuntimeHost(node) {
|
|
1172
|
+
return node;
|
|
1173
|
+
}
|
|
1174
|
+
|
|
1175
|
+
// src/node/node-lifecycle-runtime.ts
|
|
1176
|
+
function nodeActivate(self) {
|
|
1177
|
+
self._lifecycle.activated = true;
|
|
1178
|
+
const seedRestoredDeps = self._restoredActivationPending;
|
|
1179
|
+
self._restoredActivationPending = false;
|
|
1180
|
+
self._dep.unsubs = new Array(self._slot.deps.length);
|
|
1181
|
+
self._dep.idxBoxes = new Array(self._slot.deps.length);
|
|
1182
|
+
for (const dep of self._slot.deps) self._subscribeDepAt(dep, { seedRestored: seedRestoredDeps });
|
|
1183
|
+
if (self._slot.deps.length === 0 && self._slot.handle !== null && !self._wave.hasCalledFnOnce) {
|
|
1184
|
+
self._runWave();
|
|
1185
|
+
}
|
|
1186
|
+
}
|
|
1187
|
+
function nodeSubscribeDepAt(self, depNode, opts = {}) {
|
|
1188
|
+
const idx0 = self._slot.deps.indexOf(depNode);
|
|
1189
|
+
const box = { v: idx0 };
|
|
1190
|
+
let ignoreInitialPush = opts.seedRestored === true;
|
|
1191
|
+
if (ignoreInitialPush && idx0 !== -1) {
|
|
1192
|
+
self._seedRestoredDepAt(idx0, depNode);
|
|
1193
|
+
const dep = nodeRuntimeHost(depNode);
|
|
1194
|
+
if (dep._value.terminal !== void 0 && !dep._slot.resubscribable) {
|
|
1195
|
+
self._dep.unsubs[idx0] = () => {
|
|
1196
|
+
};
|
|
1197
|
+
self._dep.idxBoxes[idx0] = box;
|
|
1198
|
+
return;
|
|
1199
|
+
}
|
|
1200
|
+
}
|
|
1201
|
+
const unsub = depNode.subscribe((msg, delivery) => {
|
|
1202
|
+
if (ignoreInitialPush && delivery === void 0) return;
|
|
1203
|
+
if (ignoreInitialPush) ignoreInitialPush = false;
|
|
1204
|
+
if (box.v === -1) return;
|
|
1205
|
+
self._receiveFromDep(box.v, msg, delivery);
|
|
1206
|
+
});
|
|
1207
|
+
if (ignoreInitialPush && idx0 !== -1 && box.v !== -1) self._seedRestoredDepAt(idx0, depNode);
|
|
1208
|
+
ignoreInitialPush = false;
|
|
1209
|
+
if (idx0 !== -1) {
|
|
1210
|
+
self._dep.unsubs[idx0] = unsub;
|
|
1211
|
+
self._dep.idxBoxes[idx0] = box;
|
|
1212
|
+
}
|
|
1213
|
+
}
|
|
1214
|
+
function nodeSeedRestoredDepAt(self, idx, depNode) {
|
|
1215
|
+
const dep = nodeRuntimeHost(depNode);
|
|
1216
|
+
const seedData = dep._value.hasData && !dep._slot.pull;
|
|
1217
|
+
self._dep.batch[idx] = null;
|
|
1218
|
+
self._dep.waveData[idx] = [];
|
|
1219
|
+
self._dep.waveTokens[idx] = void 0;
|
|
1220
|
+
self._dep.prev[idx] = seedData ? dep._value.cache : SENTINEL;
|
|
1221
|
+
self._dep.hasData[idx] = seedData;
|
|
1222
|
+
self._dep.dirty[idx] = false;
|
|
1223
|
+
self._dep.tier[idx] = seedData ? 3 : 0;
|
|
1224
|
+
self._dep.terminal[idx] = dep._value.terminal;
|
|
1225
|
+
self._dep.terminalInput[idx] = void 0;
|
|
1226
|
+
}
|
|
1227
|
+
function nodeDeactivate(self) {
|
|
1228
|
+
self._lifecycle.activated = false;
|
|
1229
|
+
for (const u of self._dep.unsubs) if (u) u();
|
|
1230
|
+
self._dep.unsubs = [];
|
|
1231
|
+
self._dep.idxBoxes = [];
|
|
1232
|
+
for (const fn of self._hooks.onDeactivation) fn();
|
|
1233
|
+
self._hooks.onDeactivation = [];
|
|
1234
|
+
self._hooks.onInvalidate = [];
|
|
1235
|
+
const isCompute = self._slot.handle !== null || self._slot.deps.length > 0;
|
|
1236
|
+
if (isCompute) {
|
|
1237
|
+
self._value.cache = SENTINEL;
|
|
1238
|
+
self._value.hasData = false;
|
|
1239
|
+
self._value.status = "sentinel";
|
|
1240
|
+
}
|
|
1241
|
+
self._resetDepState();
|
|
1242
|
+
self._wave.hasCalledFnOnce = false;
|
|
1243
|
+
self._control.pauseLockset.clear();
|
|
1244
|
+
self._control.pauseBuffer = [];
|
|
1245
|
+
self._control.pausedDepWaveOccurred = false;
|
|
1246
|
+
self._control.demandOwed = void 0;
|
|
1247
|
+
self._control.activePull = void 0;
|
|
1248
|
+
self._control.pullDirtyOwed = false;
|
|
1249
|
+
self._value.replayRing = [];
|
|
1250
|
+
if (!self._privateState.persist) self._privateState.value = SENTINEL;
|
|
1251
|
+
}
|
|
1252
|
+
function nodeSubscriberCount(self) {
|
|
1253
|
+
return self._lifecycle.subscribers.size;
|
|
1254
|
+
}
|
|
1255
|
+
function nodeIsRuntimeQuiescentForRelease(self) {
|
|
1256
|
+
return !self._released && self._value.status !== "dirty" && self._value.status !== "pending" && self._wave.pending === 0 && !self._wave.insideRunWave && !self._wave.inDepMutation && !self._wave.rewireRunPending && !self._wave.batchDirtyOwed && self._dep.dirty.every((dirty) => !dirty) && self._control.pauseBuffer.length === 0 && !self._control.pausedDepWaveOccurred && self._control.demandOwed === void 0 && self._control.activePull === void 0 && !self._control.inDeliverDemand && self._control.pauseLockset.size === 0;
|
|
1257
|
+
}
|
|
1258
|
+
function nodeReleaseRuntime(self) {
|
|
1259
|
+
if (self._released) return;
|
|
1260
|
+
self._released = true;
|
|
1261
|
+
const node = self;
|
|
1262
|
+
releasedNodes.add(node);
|
|
1263
|
+
let releaseError;
|
|
1264
|
+
const recordReleaseError = (error) => {
|
|
1265
|
+
if (releaseError === void 0) releaseError = error;
|
|
1266
|
+
};
|
|
1267
|
+
self._lifecycle.activated = false;
|
|
1268
|
+
for (const u of self._dep.unsubs) {
|
|
1269
|
+
try {
|
|
1270
|
+
u();
|
|
1271
|
+
} catch (error) {
|
|
1272
|
+
recordReleaseError(error);
|
|
1273
|
+
}
|
|
1274
|
+
}
|
|
1275
|
+
for (const fn of self._hooks.onDeactivation) {
|
|
1276
|
+
try {
|
|
1277
|
+
fn();
|
|
1278
|
+
} catch (error) {
|
|
1279
|
+
recordReleaseError(error);
|
|
1280
|
+
}
|
|
1281
|
+
}
|
|
1282
|
+
self._dep.unsubs = [];
|
|
1283
|
+
self._dep.idxBoxes = [];
|
|
1284
|
+
self._lifecycle.subscribers.clear();
|
|
1285
|
+
if (self._slot.handle !== null) {
|
|
1286
|
+
self._slot.dispatcher.unregister(self._slot.handle);
|
|
1287
|
+
self._slot.handle = null;
|
|
1288
|
+
}
|
|
1289
|
+
self._slot.deps = [];
|
|
1290
|
+
self._dep.batch = [];
|
|
1291
|
+
self._dep.waveData = [];
|
|
1292
|
+
self._dep.waveTokens = [];
|
|
1293
|
+
self._dep.prev = [];
|
|
1294
|
+
self._dep.hasData = [];
|
|
1295
|
+
self._dep.dirty = [];
|
|
1296
|
+
self._dep.tier = [];
|
|
1297
|
+
self._dep.terminal = [];
|
|
1298
|
+
self._dep.terminalInput = [];
|
|
1299
|
+
self._value.cache = SENTINEL;
|
|
1300
|
+
self._value.hasData = false;
|
|
1301
|
+
self._value.status = "sentinel";
|
|
1302
|
+
self._value.terminal = void 0;
|
|
1303
|
+
self._value.replayRing = [];
|
|
1304
|
+
self._privateState.value = SENTINEL;
|
|
1305
|
+
self._privateState.persist = false;
|
|
1306
|
+
self._syncCtx = null;
|
|
1307
|
+
self._resetDepState();
|
|
1308
|
+
self._hooks.onDeactivation = [];
|
|
1309
|
+
self._hooks.onInvalidate = [];
|
|
1310
|
+
self._control.pauseLockset.clear();
|
|
1311
|
+
self._control.pauseBuffer = [];
|
|
1312
|
+
self._control.pausedDepWaveOccurred = false;
|
|
1313
|
+
self._control.demandOwed = void 0;
|
|
1314
|
+
self._control.activePull = void 0;
|
|
1315
|
+
self._control.pullDirtyOwed = false;
|
|
1316
|
+
self._restoredActivationPending = false;
|
|
1317
|
+
checkpointReaders.delete(node);
|
|
1318
|
+
restoreWriters.delete(node);
|
|
1319
|
+
runtimeReleasers.delete(node);
|
|
1320
|
+
runtimeQuiescenceReaders.delete(node);
|
|
1321
|
+
subscriberCountReaders.delete(node);
|
|
1322
|
+
activationReaders.delete(node);
|
|
1323
|
+
ownerTokens.delete(node);
|
|
1324
|
+
topologyDepsChangedObservers.delete(node);
|
|
1325
|
+
self._core.releaseSlot(self._id);
|
|
1326
|
+
if (releaseError !== void 0) throw releaseError;
|
|
1327
|
+
}
|
|
1328
|
+
function nodeResetDepState(self) {
|
|
1329
|
+
const n = self._slot.deps.length;
|
|
1330
|
+
for (let i = 0; i < n; i++) {
|
|
1331
|
+
self._dep.batch[i] = null;
|
|
1332
|
+
self._dep.waveData[i] = [];
|
|
1333
|
+
self._dep.waveTokens[i] = void 0;
|
|
1334
|
+
self._dep.prev[i] = SENTINEL;
|
|
1335
|
+
self._dep.hasData[i] = false;
|
|
1336
|
+
self._dep.dirty[i] = false;
|
|
1337
|
+
self._dep.tier[i] = 0;
|
|
1338
|
+
self._dep.terminal[i] = void 0;
|
|
1339
|
+
self._dep.terminalInput[i] = void 0;
|
|
1340
|
+
}
|
|
1341
|
+
self._wave.pending = 0;
|
|
1342
|
+
self._wave.emittedDirtyThisWave = false;
|
|
1343
|
+
}
|
|
1344
|
+
|
|
1345
|
+
// src/batch/batch.ts
|
|
1346
|
+
var active = null;
|
|
1347
|
+
var boundaryOwner = null;
|
|
1348
|
+
function currentBatch() {
|
|
1349
|
+
return active !== null;
|
|
1350
|
+
}
|
|
1351
|
+
function currentBoundaryBatchToken() {
|
|
1352
|
+
return active ?? boundaryOwner ?? void 0;
|
|
1353
|
+
}
|
|
1354
|
+
function deferToBatch(target, tier3Wave) {
|
|
1355
|
+
if (active === null) return false;
|
|
1356
|
+
if (!active.deferred.has(target)) active.order.push(target);
|
|
1357
|
+
active.deferred.set(target, tier3Wave);
|
|
1358
|
+
return true;
|
|
1359
|
+
}
|
|
1360
|
+
function deferAfterBatchForTarget(target, fn) {
|
|
1361
|
+
if (active === null || !active.deferred.has(target)) return false;
|
|
1362
|
+
const owner = active;
|
|
1363
|
+
target.__deferBoundary(() => {
|
|
1364
|
+
if (owner.committed) fn();
|
|
1365
|
+
}, owner);
|
|
1366
|
+
return true;
|
|
1367
|
+
}
|
|
1368
|
+
|
|
797
1369
|
// src/node/versioning.ts
|
|
798
1370
|
var ABSENT_V1_SEED = Object.freeze({
|
|
799
1371
|
"@graphrefly/node-version": "v1-absent"
|
|
@@ -872,67 +1444,532 @@ function restoredV1Cid(policy, hasData, cache) {
|
|
|
872
1444
|
return computeV1Cid(policy, hasData ? cache : ABSENT_V1_SEED);
|
|
873
1445
|
}
|
|
874
1446
|
|
|
875
|
-
// src/node/node.ts
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
1447
|
+
// src/node/node-output-runtime.ts
|
|
1448
|
+
function nodeDown(self, msgs) {
|
|
1449
|
+
if (self._released) return;
|
|
1450
|
+
validateDownPayloads(msgs);
|
|
1451
|
+
const deliveryWave = {};
|
|
1452
|
+
const assertVersionDataCompatible = (wave) => {
|
|
1453
|
+
for (const m of wave) {
|
|
1454
|
+
if (m[0] === "DATA") assertNodeVersionDataCompatible(self._version.policy, m[1]);
|
|
1455
|
+
}
|
|
1456
|
+
};
|
|
1457
|
+
const snapshotVersionData = (wave) => wave.map(
|
|
1458
|
+
(m) => m[0] === "DATA" ? ["DATA", snapshotNodeVersionData(self._version.policy, m[1])] : m
|
|
1459
|
+
);
|
|
1460
|
+
assertVersionDataCompatible(msgs);
|
|
1461
|
+
if (self._value.terminal !== void 0) {
|
|
1462
|
+
if (!msgs.some((m) => m[0] === "TEARDOWN")) return;
|
|
1463
|
+
self._value.hasTorndown = true;
|
|
1464
|
+
if (self._slot.resetOnTeardown) {
|
|
1465
|
+
self._value.cache = SENTINEL;
|
|
1466
|
+
self._value.hasData = false;
|
|
1467
|
+
}
|
|
1468
|
+
self._emitToSubs(["TEARDOWN"], { wave: deliveryWave, last: true });
|
|
1469
|
+
return;
|
|
894
1470
|
}
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
1471
|
+
let sorted = [...msgs].sort((a, b) => messageTier(a[0]) - messageTier(b[0]));
|
|
1472
|
+
const firstInvalidate = sorted.findIndex((m) => m[0] === "INVALIDATE");
|
|
1473
|
+
if (firstInvalidate !== -1) {
|
|
1474
|
+
sorted = sorted.filter((m, i) => m[0] !== "INVALIDATE" || i === firstInvalidate);
|
|
1475
|
+
}
|
|
1476
|
+
const hasTeardown = sorted.some((m) => m[0] === "TEARDOWN");
|
|
1477
|
+
const hasTerminal = sorted.some((m) => m[0] === "COMPLETE" || m[0] === "ERROR");
|
|
1478
|
+
if (hasTeardown && !hasTerminal && self._value.terminal === void 0 && !self._value.hasTorndown) {
|
|
1479
|
+
sorted = [["COMPLETE"], ...sorted];
|
|
1480
|
+
}
|
|
1481
|
+
if (!self._wave.insideRunWave && currentBatch()) {
|
|
1482
|
+
const deferred = snapshotVersionData(sorted.filter((m) => isDeferredTier(m[0])));
|
|
1483
|
+
if (deferred.length > 0) {
|
|
1484
|
+
if (!self._wave.emittedDirtyThisWave) {
|
|
1485
|
+
self._wave.emittedDirtyThisWave = true;
|
|
1486
|
+
self._value.status = "dirty";
|
|
1487
|
+
self._emitToSubs(["DIRTY"], { wave: deliveryWave, last: false });
|
|
1488
|
+
}
|
|
1489
|
+
self._wave.batchDirtyOwed = true;
|
|
1490
|
+
deferToBatch(self, deferred);
|
|
1491
|
+
return;
|
|
1492
|
+
}
|
|
903
1493
|
}
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
return t === void 0 ? false : t;
|
|
913
|
-
}
|
|
914
|
-
function normalizePullDemand(demand) {
|
|
915
|
-
if (typeof demand !== "object" || demand === null || Array.isArray(demand)) {
|
|
916
|
-
throw new Error("ctx.up: PULL requires { pullId, params? } demand payload (D269)");
|
|
1494
|
+
if (self._shouldBufferOnPause()) {
|
|
1495
|
+
const buffered = snapshotVersionData(sorted.filter((m) => isPauseBufferedTier(m[0])));
|
|
1496
|
+
if (buffered.length > 0) {
|
|
1497
|
+
self._wave.emittedSettleThisWave = true;
|
|
1498
|
+
self._control.pauseBuffer.push(buffered);
|
|
1499
|
+
}
|
|
1500
|
+
sorted = sorted.filter((m) => !isPauseBufferedTier(m[0]));
|
|
1501
|
+
if (sorted.length === 0) return;
|
|
917
1502
|
}
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
1503
|
+
let dataCount = 0;
|
|
1504
|
+
let hasTier3 = false;
|
|
1505
|
+
let hasResolved = false;
|
|
1506
|
+
for (const m of sorted) {
|
|
1507
|
+
if (m[0] === "DATA") dataCount++;
|
|
1508
|
+
if (m[0] === "RESOLVED") hasResolved = true;
|
|
1509
|
+
if (isValueTier(m[0])) hasTier3 = true;
|
|
921
1510
|
}
|
|
922
|
-
|
|
923
|
-
|
|
1511
|
+
if (dataCount >= 1 && hasResolved) {
|
|
1512
|
+
throw new Error(
|
|
1513
|
+
"down: a wave cannot mix DATA and RESOLVED (tier-3 exclusivity, R-resolved-undirty)"
|
|
1514
|
+
);
|
|
1515
|
+
}
|
|
1516
|
+
const plannedVersions = new Array(sorted.length);
|
|
1517
|
+
if (dataCount > 0) {
|
|
1518
|
+
let plannedVersion = self._version.value;
|
|
1519
|
+
for (let i = 0; i < sorted.length; i++) {
|
|
1520
|
+
const m = sorted[i];
|
|
1521
|
+
if (m[0] !== "DATA") continue;
|
|
1522
|
+
plannedVersion = advanceNodeVersion(plannedVersion, self._version.policy, m[1]);
|
|
1523
|
+
plannedVersions[i] = plannedVersion;
|
|
1524
|
+
}
|
|
1525
|
+
}
|
|
1526
|
+
if (hasTier3 && (!self._wave.insideRunWave || self._control.pullDirtyOwed) && !self._wave.emittedDirtyThisWave) {
|
|
1527
|
+
self._wave.emittedDirtyThisWave = true;
|
|
1528
|
+
self._value.status = "dirty";
|
|
1529
|
+
self._emitToSubs(["DIRTY"], { wave: deliveryWave, last: false });
|
|
1530
|
+
}
|
|
1531
|
+
for (let i = 0; i < sorted.length; i++) {
|
|
1532
|
+
const m = sorted[i];
|
|
1533
|
+
const delivery = { wave: deliveryWave, last: i === sorted.length - 1 };
|
|
1534
|
+
if (isDeferredTier(m[0])) self._wave.emittedSettleThisWave = true;
|
|
1535
|
+
if (m[0] === "DIRTY") {
|
|
1536
|
+
if (!self._wave.emittedDirtyThisWave) {
|
|
1537
|
+
self._wave.emittedDirtyThisWave = true;
|
|
1538
|
+
self._value.status = "dirty";
|
|
1539
|
+
self._emitToSubs(["DIRTY"], delivery);
|
|
1540
|
+
}
|
|
1541
|
+
continue;
|
|
1542
|
+
}
|
|
1543
|
+
if (m[0] === "DATA") {
|
|
1544
|
+
const v = m[1];
|
|
1545
|
+
self._value.cache = v;
|
|
1546
|
+
self._value.hasData = true;
|
|
1547
|
+
self._value.status = "settled";
|
|
1548
|
+
self._version.value = plannedVersions[i];
|
|
1549
|
+
if (self._slot.replayN > 0) {
|
|
1550
|
+
self._value.replayRing.push(v);
|
|
1551
|
+
if (self._value.replayRing.length > self._slot.replayN) self._value.replayRing.shift();
|
|
1552
|
+
}
|
|
1553
|
+
self._emitToSubs(["DATA", v], delivery);
|
|
1554
|
+
continue;
|
|
1555
|
+
}
|
|
1556
|
+
if (m[0] === "RESOLVED") {
|
|
1557
|
+
self._value.status = self._value.hasData ? "resolved" : "sentinel";
|
|
1558
|
+
self._emitToSubs(["RESOLVED"], delivery);
|
|
1559
|
+
continue;
|
|
1560
|
+
}
|
|
1561
|
+
if (m[0] === "INVALIDATE") {
|
|
1562
|
+
self._invalidate(delivery);
|
|
1563
|
+
continue;
|
|
1564
|
+
}
|
|
1565
|
+
if (m[0] === "COMPLETE") {
|
|
1566
|
+
if (self._value.terminal !== void 0) continue;
|
|
1567
|
+
self._value.terminal = true;
|
|
1568
|
+
self._control.pauseBuffer = [];
|
|
1569
|
+
self._value.status = "completed";
|
|
1570
|
+
self._emitToSubs(["COMPLETE"], delivery);
|
|
1571
|
+
continue;
|
|
1572
|
+
}
|
|
1573
|
+
if (m[0] === "ERROR") {
|
|
1574
|
+
if (self._value.terminal !== void 0) continue;
|
|
1575
|
+
self._value.terminal = m[1];
|
|
1576
|
+
self._control.pauseBuffer = [];
|
|
1577
|
+
self._value.status = "errored";
|
|
1578
|
+
self._emitToSubs(["ERROR", m[1]], delivery);
|
|
1579
|
+
continue;
|
|
1580
|
+
}
|
|
1581
|
+
if (m[0] === "TEARDOWN") {
|
|
1582
|
+
self._value.hasTorndown = true;
|
|
1583
|
+
if (self._slot.resetOnTeardown) {
|
|
1584
|
+
self._value.cache = SENTINEL;
|
|
1585
|
+
self._value.hasData = false;
|
|
1586
|
+
}
|
|
1587
|
+
self._emitToSubs(["TEARDOWN"], delivery);
|
|
1588
|
+
}
|
|
1589
|
+
}
|
|
1590
|
+
if (!self._wave.insideRunWave) self._wave.emittedDirtyThisWave = false;
|
|
924
1591
|
}
|
|
925
|
-
function
|
|
1592
|
+
function nodeUp(self, msgs, towardDep, route) {
|
|
1593
|
+
if (self._released) return;
|
|
1594
|
+
const routeState = route ?? { demandFired: /* @__PURE__ */ new Map() };
|
|
926
1595
|
for (const m of msgs) {
|
|
927
|
-
if (m[0]
|
|
928
|
-
throw new Error(
|
|
1596
|
+
if (!isUpAllowed(m[0])) {
|
|
1597
|
+
throw new Error(
|
|
1598
|
+
`ctx.up: ${m[0]} is down-only (tier ${messageTier(m[0])}); up carries control tiers only (R-ctx-up)`
|
|
1599
|
+
);
|
|
929
1600
|
}
|
|
930
|
-
|
|
931
|
-
|
|
1601
|
+
}
|
|
1602
|
+
for (const m of msgs) {
|
|
1603
|
+
if (m[0] === "PAUSE") {
|
|
1604
|
+
self._pauseAcquire(m[1]);
|
|
1605
|
+
} else if (m[0] === "RESUME") {
|
|
1606
|
+
if (self._control.pauseLockset.has(m[1])) {
|
|
1607
|
+
self._pauseRelease(m[1]);
|
|
1608
|
+
} else {
|
|
1609
|
+
self._forwardUp(m, towardDep, routeState);
|
|
1610
|
+
}
|
|
1611
|
+
} else if (m[0] === "PULL") {
|
|
1612
|
+
const demand = normalizePullDemand(m[1]);
|
|
1613
|
+
if (self._slot.pull && demand.pullId === self._slot.pullLock) {
|
|
1614
|
+
if (!self._markDemandRouted(demand.pullId, routeState)) self._onDemand(demand);
|
|
1615
|
+
} else {
|
|
1616
|
+
self._forwardUp(["PULL", demand], towardDep, routeState);
|
|
1617
|
+
}
|
|
1618
|
+
} else if (self._slot.deps.length === 0) {
|
|
1619
|
+
if (m[0] === "INVALIDATE") self._down([["INVALIDATE"]]);
|
|
1620
|
+
} else {
|
|
1621
|
+
self._forwardUp(m, towardDep, routeState);
|
|
1622
|
+
}
|
|
1623
|
+
}
|
|
1624
|
+
}
|
|
1625
|
+
function nodeMarkDemandRouted(self, lockId, route) {
|
|
1626
|
+
let holders = route.demandFired.get(lockId);
|
|
1627
|
+
if (holders === void 0) {
|
|
1628
|
+
holders = /* @__PURE__ */ new Set();
|
|
1629
|
+
route.demandFired.set(lockId, holders);
|
|
1630
|
+
}
|
|
1631
|
+
const node = self;
|
|
1632
|
+
if (holders.has(node)) return true;
|
|
1633
|
+
holders.add(node);
|
|
1634
|
+
return false;
|
|
1635
|
+
}
|
|
1636
|
+
function nodeForwardUp(self, m, towardDep, route) {
|
|
1637
|
+
if (self._slot.deps.length === 0) return;
|
|
1638
|
+
if (towardDep !== void 0) {
|
|
1639
|
+
const d = self._slot.deps[towardDep];
|
|
1640
|
+
if (d !== void 0) nodeRuntimeHost(d)._up([m], void 0, route);
|
|
1641
|
+
} else {
|
|
1642
|
+
for (const dep of self._slot.deps) nodeRuntimeHost(dep)._up([m], void 0, route);
|
|
1643
|
+
}
|
|
1644
|
+
}
|
|
1645
|
+
function nodeIsPaused(self) {
|
|
1646
|
+
return self._control.pauseLockset.size > 0;
|
|
1647
|
+
}
|
|
1648
|
+
function nodeHasBoundaryPauseLock(self) {
|
|
1649
|
+
if (self._slot.pausable === false) return false;
|
|
1650
|
+
return self._control.pauseLockset.size > 0;
|
|
1651
|
+
}
|
|
1652
|
+
function nodeIsAsyncPool(self) {
|
|
1653
|
+
return self._slot.handle !== null && self._slot.dispatcher.poolKind(self._slot.handle.poolId) === "async";
|
|
1654
|
+
}
|
|
1655
|
+
function nodePauseAcquire(self, lockId) {
|
|
1656
|
+
self._control.pauseLockset.add(lockId);
|
|
1657
|
+
}
|
|
1658
|
+
function nodePauseRelease(self, lockId) {
|
|
1659
|
+
if (!self._control.pauseLockset.has(lockId)) return;
|
|
1660
|
+
self._control.pauseLockset.delete(lockId);
|
|
1661
|
+
if (self._slot.pull && self._control.demandOwed !== void 0) self._fireOwedDemandIfReady();
|
|
1662
|
+
if (self._hasBoundaryPauseLock()) return;
|
|
1663
|
+
scheduleBoundaryDrain(self._core);
|
|
1664
|
+
if (self._slot.pull) return;
|
|
1665
|
+
self._onResume();
|
|
1666
|
+
}
|
|
1667
|
+
function nodeOnResume(self) {
|
|
1668
|
+
if (self._value.terminal !== void 0) {
|
|
1669
|
+
self._control.pauseBuffer = [];
|
|
1670
|
+
self._control.pausedDepWaveOccurred = false;
|
|
1671
|
+
self._control.demandOwed = void 0;
|
|
1672
|
+
self._control.activePull = void 0;
|
|
1673
|
+
self._control.pullDirtyOwed = false;
|
|
1674
|
+
return;
|
|
1675
|
+
}
|
|
1676
|
+
if (self._control.pauseBuffer.length > 0) {
|
|
1677
|
+
const buf = self._control.pauseBuffer;
|
|
1678
|
+
self._control.pauseBuffer = [];
|
|
1679
|
+
for (const wave of buf) self._down(wave);
|
|
1680
|
+
}
|
|
1681
|
+
if (self._control.pausedDepWaveOccurred) {
|
|
1682
|
+
self._control.pausedDepWaveOccurred = false;
|
|
1683
|
+
self._tryRun();
|
|
1684
|
+
}
|
|
1685
|
+
}
|
|
1686
|
+
function nodeCanFireDemand(self) {
|
|
1687
|
+
if (self._value.terminal !== void 0 || self._wave.pending > 0) return false;
|
|
1688
|
+
return self._control.pauseLockset.size === 0;
|
|
1689
|
+
}
|
|
1690
|
+
function nodeDeliverPullDemand(self, demand) {
|
|
1691
|
+
self._control.demandOwed = void 0;
|
|
1692
|
+
self._control.activePull = demand;
|
|
1693
|
+
self._control.inDeliverDemand = true;
|
|
1694
|
+
try {
|
|
1695
|
+
self._firePullDemand();
|
|
1696
|
+
} finally {
|
|
1697
|
+
self._control.activePull = void 0;
|
|
1698
|
+
self._control.inDeliverDemand = false;
|
|
1699
|
+
}
|
|
1700
|
+
}
|
|
1701
|
+
function nodeOnDemand(self, demand) {
|
|
1702
|
+
if (self._control.inDeliverDemand) return;
|
|
1703
|
+
if (self._canFireDemand()) self._deliverPullDemand(demand);
|
|
1704
|
+
else self._control.demandOwed = demand;
|
|
1705
|
+
}
|
|
1706
|
+
function nodeFirePullDemand(self) {
|
|
1707
|
+
let drainedBuffer = false;
|
|
1708
|
+
if (self._control.pauseBuffer.length > 0) {
|
|
1709
|
+
const buf = self._control.pauseBuffer;
|
|
1710
|
+
self._control.pauseBuffer = [];
|
|
1711
|
+
for (const wave of buf) self._down(wave);
|
|
1712
|
+
drainedBuffer = true;
|
|
1713
|
+
}
|
|
1714
|
+
if (drainedBuffer) return;
|
|
1715
|
+
if (self._control.pausedDepWaveOccurred) {
|
|
1716
|
+
const gated = self._slot.handle !== null && !self._wave.hasCalledFnOnce && !(self._slot.partial || self._allDepsSettled());
|
|
1717
|
+
if (self._wave.pending > 0 || gated) return;
|
|
1718
|
+
self._control.pausedDepWaveOccurred = false;
|
|
1719
|
+
self._wave.emittedDirtyThisWave = false;
|
|
1720
|
+
self._control.pullDirtyOwed = true;
|
|
1721
|
+
try {
|
|
1722
|
+
self._tryRun();
|
|
1723
|
+
} finally {
|
|
1724
|
+
self._control.pullDirtyOwed = false;
|
|
932
1725
|
}
|
|
1726
|
+
return;
|
|
933
1727
|
}
|
|
1728
|
+
if (self._slot.handle !== null) {
|
|
1729
|
+
if (!self._wave.hasCalledFnOnce && !(self._slot.partial || self._allDepsSettled())) return;
|
|
1730
|
+
self._wave.emittedDirtyThisWave = false;
|
|
1731
|
+
self._control.pullDirtyOwed = true;
|
|
1732
|
+
try {
|
|
1733
|
+
self._runWave();
|
|
1734
|
+
} finally {
|
|
1735
|
+
self._control.pullDirtyOwed = false;
|
|
1736
|
+
}
|
|
1737
|
+
}
|
|
1738
|
+
}
|
|
1739
|
+
function nodeFireOwedDemandIfReady(self) {
|
|
1740
|
+
if (self._control.inDeliverDemand) return;
|
|
1741
|
+
if (self._slot.pull && self._control.demandOwed !== void 0 && self._canFireDemand()) {
|
|
1742
|
+
self._deliverPullDemand(self._control.demandOwed);
|
|
1743
|
+
}
|
|
1744
|
+
}
|
|
1745
|
+
function nodeShouldBufferOnPause(self) {
|
|
1746
|
+
if (self._slot.pausable === false) return false;
|
|
1747
|
+
if (!self._isPaused() && !self._isPullQuiet()) return false;
|
|
1748
|
+
if (self._slot.pausable === "resumeAll") return true;
|
|
1749
|
+
if (!self._wave.insideRunWave && self._isAsyncPool() && self._slot.deps.length > 0) return true;
|
|
1750
|
+
return false;
|
|
1751
|
+
}
|
|
1752
|
+
function nodeInvalidate(self, delivery) {
|
|
1753
|
+
if (!self._value.hasData) return;
|
|
1754
|
+
self._value.cache = SENTINEL;
|
|
1755
|
+
self._value.hasData = false;
|
|
1756
|
+
self._value.status = "sentinel";
|
|
1757
|
+
self._value.replayRing = [];
|
|
1758
|
+
for (const fn of self._hooks.onInvalidate) fn();
|
|
1759
|
+
self._emitToSubs(["INVALIDATE"], delivery);
|
|
1760
|
+
}
|
|
1761
|
+
function nodeAllDepsTerminal(self) {
|
|
1762
|
+
if (self._slot.deps.length === 0) return false;
|
|
1763
|
+
for (const tm of self._dep.terminal) if (tm === void 0) return false;
|
|
1764
|
+
return true;
|
|
1765
|
+
}
|
|
1766
|
+
function nodeResetLifecycle(self) {
|
|
1767
|
+
for (const u of self._dep.unsubs) if (u) u();
|
|
1768
|
+
self._dep.unsubs = [];
|
|
1769
|
+
self._dep.idxBoxes = [];
|
|
1770
|
+
self._lifecycle.subscribers.clear();
|
|
1771
|
+
self._lifecycle.activated = false;
|
|
1772
|
+
self._value.terminal = void 0;
|
|
1773
|
+
self._value.hasTorndown = false;
|
|
1774
|
+
self._wave.hasCalledFnOnce = false;
|
|
1775
|
+
self._resetDepState();
|
|
1776
|
+
self._control.pauseLockset.clear();
|
|
1777
|
+
self._control.pauseBuffer = [];
|
|
1778
|
+
self._control.pausedDepWaveOccurred = false;
|
|
1779
|
+
self._control.demandOwed = void 0;
|
|
1780
|
+
self._control.activePull = void 0;
|
|
1781
|
+
self._control.pullDirtyOwed = false;
|
|
1782
|
+
self._value.replayRing = [];
|
|
1783
|
+
const isCompute = self._slot.handle !== null || self._slot.deps.length > 0;
|
|
1784
|
+
if (isCompute) {
|
|
1785
|
+
self._value.cache = SENTINEL;
|
|
1786
|
+
self._value.hasData = false;
|
|
1787
|
+
self._value.status = "sentinel";
|
|
1788
|
+
} else {
|
|
1789
|
+
self._value.status = self._value.hasData ? "settled" : "sentinel";
|
|
1790
|
+
}
|
|
1791
|
+
if (!self._privateState.persist) self._privateState.value = SENTINEL;
|
|
1792
|
+
}
|
|
1793
|
+
function nodeEmitToSubs(self, msg, delivery) {
|
|
1794
|
+
if (self._released) return;
|
|
1795
|
+
const subs = [...self._lifecycle.subscribers];
|
|
1796
|
+
for (const sink of subs) sink(msg, delivery);
|
|
1797
|
+
}
|
|
1798
|
+
function nodeCommitBatchedWave(self, wave) {
|
|
1799
|
+
self._wave.batchDirtyOwed = false;
|
|
1800
|
+
self._down(wave);
|
|
1801
|
+
}
|
|
1802
|
+
function nodeRollbackBatched(self) {
|
|
1803
|
+
if (self._wave.batchDirtyOwed) {
|
|
1804
|
+
self._wave.batchDirtyOwed = false;
|
|
1805
|
+
self._wave.emittedDirtyThisWave = false;
|
|
1806
|
+
self._value.status = self._value.hasData ? "settled" : "sentinel";
|
|
1807
|
+
self._emitToSubs(["RESOLVED"]);
|
|
1808
|
+
}
|
|
1809
|
+
}
|
|
1810
|
+
function nodeDeferBoundary(self, fn, batchToken) {
|
|
1811
|
+
deferRewire(self._core, fn, {
|
|
1812
|
+
batchToken,
|
|
1813
|
+
isReady: () => !self._hasBoundaryPauseLock()
|
|
1814
|
+
});
|
|
1815
|
+
}
|
|
1816
|
+
|
|
1817
|
+
// src/node/node-rewire-runtime.ts
|
|
1818
|
+
function nodeRequestRewireNext(self, op) {
|
|
1819
|
+
deferRewire(self._core, () => self._applyRewireNext(op), {
|
|
1820
|
+
batchToken: currentBoundaryBatchToken(),
|
|
1821
|
+
isReady: () => !self._hasBoundaryPauseLock()
|
|
1822
|
+
});
|
|
934
1823
|
}
|
|
935
|
-
|
|
1824
|
+
function nodeRequestUpNext(self, msgs, towardDep) {
|
|
1825
|
+
deferRewire(
|
|
1826
|
+
self._core,
|
|
1827
|
+
() => {
|
|
1828
|
+
if (!self._released) self._up(msgs, towardDep);
|
|
1829
|
+
},
|
|
1830
|
+
{
|
|
1831
|
+
batchToken: currentBoundaryBatchToken(),
|
|
1832
|
+
isReady: () => !self._hasBoundaryPauseLock()
|
|
1833
|
+
}
|
|
1834
|
+
);
|
|
1835
|
+
}
|
|
1836
|
+
function nodeApplyRewireNext(self, op) {
|
|
1837
|
+
if (self._released) return;
|
|
1838
|
+
try {
|
|
1839
|
+
if (op.kind === "add") {
|
|
1840
|
+
const next = self._slot.deps.includes(op.dep) ? [...self._slot.deps] : [...self._slot.deps, op.dep];
|
|
1841
|
+
self._rewire(next, op.fn, { allowTerminalOwner: true });
|
|
1842
|
+
} else if (op.kind === "remove") {
|
|
1843
|
+
self._rewire(
|
|
1844
|
+
self._slot.deps.filter((d) => d !== op.dep),
|
|
1845
|
+
op.fn,
|
|
1846
|
+
{ allowTerminalOwner: true }
|
|
1847
|
+
);
|
|
1848
|
+
} else {
|
|
1849
|
+
self._rewire(self._dedupDeps(op.deps), op.fn, { allowTerminalOwner: true });
|
|
1850
|
+
}
|
|
1851
|
+
} catch (e) {
|
|
1852
|
+
self._down([["ERROR", errorPayload(e, "rewireNext op failed")]]);
|
|
1853
|
+
}
|
|
1854
|
+
}
|
|
1855
|
+
function nodeRewire(self, newDeps, fn, opts = {}) {
|
|
1856
|
+
const node = self;
|
|
1857
|
+
if (self._value.terminal !== void 0 && !opts.allowTerminalOwner)
|
|
1858
|
+
throw new Error(
|
|
1859
|
+
"rewire: node is terminal (completed/errored) \u2014 cannot rewire (R-rewire / D42)"
|
|
1860
|
+
);
|
|
1861
|
+
if (self._wave.insideRunWave)
|
|
1862
|
+
throw new Error(
|
|
1863
|
+
"rewire: mid-fn topology mutation \u2014 a fn mutating its own deps mid-wave is the feedback cycle (R-rewire / D37)"
|
|
1864
|
+
);
|
|
1865
|
+
if (self._wave.inDepMutation)
|
|
1866
|
+
throw new Error(
|
|
1867
|
+
"rewire: reentrant dep mutation \u2014 another replaceDeps/subscribeDep/unsubscribeDep is in flight (R-rewire)"
|
|
1868
|
+
);
|
|
1869
|
+
if (newDeps.includes(node)) throw new Error("rewire: self-dependency rejected (R-rewire / D42)");
|
|
1870
|
+
const oldDeps = self._slot.deps;
|
|
1871
|
+
const added = newDeps.filter((d) => !oldDeps.includes(d));
|
|
1872
|
+
for (const d of added) {
|
|
1873
|
+
if (self._reachableUpstream(d, node))
|
|
1874
|
+
throw new Error(
|
|
1875
|
+
"rewire: would create a cycle \u2014 dep already transitively depends on this node (R-rewire / D42)"
|
|
1876
|
+
);
|
|
1877
|
+
const dep = nodeRuntimeHost(d);
|
|
1878
|
+
if (dep._value.terminal !== void 0 && !dep._slot.resubscribable)
|
|
1879
|
+
throw new Error(
|
|
1880
|
+
"rewire: cannot add a non-resubscribable terminal dep \u2014 would wedge (R-rewire / D42)"
|
|
1881
|
+
);
|
|
1882
|
+
self._assertRewireDepOwner(d);
|
|
1883
|
+
}
|
|
1884
|
+
if (deferAfterBatchForTarget(node, () => {
|
|
1885
|
+
self._rewire(newDeps, fn, { ...opts, allowTerminalOwner: true });
|
|
1886
|
+
})) {
|
|
1887
|
+
return true;
|
|
1888
|
+
}
|
|
1889
|
+
if (!self._lifecycle.activated) self._restoredActivationPending = false;
|
|
1890
|
+
self._wave.inDepMutation = true;
|
|
1891
|
+
self._wave.rewireRunPending = false;
|
|
1892
|
+
let zeroDepUnDirty = false;
|
|
1893
|
+
try {
|
|
1894
|
+
const oldHandle = self._slot.handle;
|
|
1895
|
+
self._slot.handle = self._slot.dispatcher.register(fn, self._slot.pool);
|
|
1896
|
+
if (oldHandle !== null) self._slot.dispatcher.unregister(oldHandle);
|
|
1897
|
+
const removed = oldDeps.filter((d) => !newDeps.includes(d));
|
|
1898
|
+
let removedDirtyContributor = false;
|
|
1899
|
+
for (const d of removed) {
|
|
1900
|
+
const oldIdx = oldDeps.indexOf(d);
|
|
1901
|
+
if (self._dep.dirty[oldIdx]) {
|
|
1902
|
+
removedDirtyContributor = true;
|
|
1903
|
+
self._wave.pending--;
|
|
1904
|
+
}
|
|
1905
|
+
if (self._lifecycle.activated) {
|
|
1906
|
+
const box = self._dep.idxBoxes[oldIdx];
|
|
1907
|
+
if (box) box.v = -1;
|
|
1908
|
+
const unsub = self._dep.unsubs[oldIdx];
|
|
1909
|
+
if (unsub) unsub();
|
|
1910
|
+
}
|
|
1911
|
+
}
|
|
1912
|
+
const n = newDeps.length;
|
|
1913
|
+
const newBatch = new Array(n).fill(null);
|
|
1914
|
+
const newPrev = new Array(n).fill(SENTINEL);
|
|
1915
|
+
const newHasData = new Array(n).fill(false);
|
|
1916
|
+
const newDirty = new Array(n).fill(false);
|
|
1917
|
+
const newTier = new Array(n).fill(0);
|
|
1918
|
+
const newTerminal = new Array(n).fill(void 0);
|
|
1919
|
+
const newTerminalInput = new Array(n).fill(void 0);
|
|
1920
|
+
const newUnsubs = new Array(n);
|
|
1921
|
+
const newBoxes = new Array(n);
|
|
1922
|
+
for (let j = 0; j < n; j++) {
|
|
1923
|
+
const oldIdx = oldDeps.indexOf(newDeps[j]);
|
|
1924
|
+
if (oldIdx !== -1) {
|
|
1925
|
+
newBatch[j] = self._dep.batch[oldIdx];
|
|
1926
|
+
newPrev[j] = self._dep.prev[oldIdx];
|
|
1927
|
+
newHasData[j] = self._dep.hasData[oldIdx];
|
|
1928
|
+
newDirty[j] = self._dep.dirty[oldIdx];
|
|
1929
|
+
newTier[j] = self._dep.tier[oldIdx];
|
|
1930
|
+
newTerminal[j] = self._dep.terminal[oldIdx];
|
|
1931
|
+
newUnsubs[j] = self._dep.unsubs[oldIdx];
|
|
1932
|
+
const box = self._dep.idxBoxes[oldIdx];
|
|
1933
|
+
if (box) box.v = j;
|
|
1934
|
+
newBoxes[j] = box;
|
|
1935
|
+
}
|
|
1936
|
+
}
|
|
1937
|
+
self._slot.deps = newDeps;
|
|
1938
|
+
self._dep.batch = newBatch;
|
|
1939
|
+
self._dep.prev = newPrev;
|
|
1940
|
+
self._dep.hasData = newHasData;
|
|
1941
|
+
self._dep.dirty = newDirty;
|
|
1942
|
+
self._dep.tier = newTier;
|
|
1943
|
+
self._dep.terminal = newTerminal;
|
|
1944
|
+
self._dep.terminalInput = newTerminalInput;
|
|
1945
|
+
self._dep.unsubs = newUnsubs;
|
|
1946
|
+
self._dep.idxBoxes = newBoxes;
|
|
1947
|
+
self._dep.waveData = newDeps.map(() => []);
|
|
1948
|
+
self._dep.waveTokens = new Array(newDeps.length).fill(void 0);
|
|
1949
|
+
self._syncCtx = null;
|
|
1950
|
+
if (self._lifecycle.activated) {
|
|
1951
|
+
for (const d of added) self._subscribeDepAt(d);
|
|
1952
|
+
}
|
|
1953
|
+
notifyTopologyDepsChanged(node, oldDeps, newDeps);
|
|
1954
|
+
if (removedDirtyContributor && self._wave.pending === 0 && self._value.status === "dirty") {
|
|
1955
|
+
if (newDeps.length > 0) self._wave.rewireRunPending = true;
|
|
1956
|
+
else zeroDepUnDirty = true;
|
|
1957
|
+
}
|
|
1958
|
+
} finally {
|
|
1959
|
+
self._wave.inDepMutation = false;
|
|
1960
|
+
}
|
|
1961
|
+
if (self._wave.rewireRunPending) {
|
|
1962
|
+
self._wave.rewireRunPending = false;
|
|
1963
|
+
self._settleRewire();
|
|
1964
|
+
} else if (zeroDepUnDirty) {
|
|
1965
|
+
if (self._wave.emittedDirtyThisWave) self._down([["RESOLVED"]]);
|
|
1966
|
+
else self._value.status = self._value.hasData ? "settled" : "sentinel";
|
|
1967
|
+
}
|
|
1968
|
+
return false;
|
|
1969
|
+
}
|
|
1970
|
+
|
|
1971
|
+
// src/node/node.ts
|
|
1972
|
+
var Node = class _Node {
|
|
936
1973
|
_core;
|
|
937
1974
|
_id;
|
|
938
1975
|
_slot;
|
|
@@ -953,12 +1990,56 @@ var Node = class {
|
|
|
953
1990
|
set _syncCtx(ctx) {
|
|
954
1991
|
this._syncCtxState.value = ctx;
|
|
955
1992
|
}
|
|
1993
|
+
static _retainIndirectRuntimeMethods(node) {
|
|
1994
|
+
void node._dep;
|
|
1995
|
+
void node._hooks;
|
|
1996
|
+
void node._restoredActivationPending;
|
|
1997
|
+
void node._requestRewireNext;
|
|
1998
|
+
void node._requestUpNext;
|
|
1999
|
+
void node._applyRewireNext;
|
|
2000
|
+
void node._reachableUpstream;
|
|
2001
|
+
void node._assertRewireDepOwner;
|
|
2002
|
+
void node._subscribeDepAt;
|
|
2003
|
+
void node._seedRestoredDepAt;
|
|
2004
|
+
void node._recordDepProjection;
|
|
2005
|
+
void node._depProjectionHasData;
|
|
2006
|
+
void node._receiveFromDep;
|
|
2007
|
+
void node._releaseDepDirty;
|
|
2008
|
+
void node._settleAfterAbsorbedTerminal;
|
|
2009
|
+
void node._markDirty;
|
|
2010
|
+
void node._maybeRun;
|
|
2011
|
+
void node._settleRewire;
|
|
2012
|
+
void node._tryRun;
|
|
2013
|
+
void node._allDepsSettled;
|
|
2014
|
+
void node._passthroughEmit;
|
|
2015
|
+
void node._runWave;
|
|
2016
|
+
void node._buildCtx;
|
|
2017
|
+
void node._makeCtx;
|
|
2018
|
+
void node._refreshCtx;
|
|
2019
|
+
void node._makeState;
|
|
2020
|
+
void node._markDemandRouted;
|
|
2021
|
+
void node._forwardUp;
|
|
2022
|
+
void node._isPullQuiet;
|
|
2023
|
+
void node._isPaused;
|
|
2024
|
+
void node._hasBoundaryPauseLock;
|
|
2025
|
+
void node._isAsyncPool;
|
|
2026
|
+
void node._pauseAcquire;
|
|
2027
|
+
void node._pauseRelease;
|
|
2028
|
+
void node._onResume;
|
|
2029
|
+
void node._canFireDemand;
|
|
2030
|
+
void node._deliverPullDemand;
|
|
2031
|
+
void node._onDemand;
|
|
2032
|
+
void node._firePullDemand;
|
|
2033
|
+
void node._fireOwedDemandIfReady;
|
|
2034
|
+
void node._shouldBufferOnPause;
|
|
2035
|
+
void node._invalidate;
|
|
2036
|
+
void node._allDepsTerminal;
|
|
2037
|
+
void node._emitToSubs;
|
|
2038
|
+
}
|
|
956
2039
|
constructor(deps, handleOrFn, opts = {}) {
|
|
957
|
-
const core =
|
|
958
|
-
constructingCore = void 0;
|
|
2040
|
+
const core = takeConstructingNodeCore();
|
|
959
2041
|
const dispatcher = opts.dispatcher ?? defaultDispatcher;
|
|
960
|
-
const environment =
|
|
961
|
-
constructingEnvironment = void 0;
|
|
2042
|
+
const environment = takeConstructingEnvironmentDrivers() ?? EnvironmentDrivers.empty();
|
|
962
2043
|
const pool = opts.pool ?? "sync";
|
|
963
2044
|
const pausable = opts.pausable ?? true;
|
|
964
2045
|
const pullLock = opts.pullId;
|
|
@@ -1129,6 +2210,7 @@ var Node = class {
|
|
|
1129
2210
|
runtimeQuiescenceReaders.set(this, () => this._isRuntimeQuiescentForRelease());
|
|
1130
2211
|
subscriberCountReaders.set(this, () => this._subscriberCount());
|
|
1131
2212
|
activationReaders.set(this, () => this._lifecycle.activated);
|
|
2213
|
+
_Node._retainIndirectRuntimeMethods(this);
|
|
1132
2214
|
}
|
|
1133
2215
|
/** R-pull (D55/D272): true while a pull node is not serving a PULL demand pulse. */
|
|
1134
2216
|
_isPullQuiet() {
|
|
@@ -1233,58 +2315,6 @@ var Node = class {
|
|
|
1233
2315
|
exitWave();
|
|
1234
2316
|
}
|
|
1235
2317
|
}
|
|
1236
|
-
// ── deferred self-rewire (R-rewire-deferred / D47): ctx.rewireNext drain support ──
|
|
1237
|
-
/**
|
|
1238
|
-
* Enqueue a deferred self-rewire op (issued from this node's fn via `ctx.rewireNext`).
|
|
1239
|
-
* Applied at the committed wave boundary (boundary.ts drain), never in place — the in-fn
|
|
1240
|
-
* immediate path (`subscribeDep`/`replaceDeps`/`unsubscribeDep`) still throws mid-run (D37/R-reentrancy).
|
|
1241
|
-
*/
|
|
1242
|
-
_requestRewireNext(op) {
|
|
1243
|
-
deferRewire(this._core, () => this._applyRewireNext(op), {
|
|
1244
|
-
batchToken: currentBoundaryBatchToken(),
|
|
1245
|
-
isReady: () => !this._hasBoundaryPauseLock()
|
|
1246
|
-
});
|
|
1247
|
-
}
|
|
1248
|
-
/**
|
|
1249
|
-
* Enqueue a deferred up-going control/demand wave (R-up-routing / R-pull / D269): at the committed wave
|
|
1250
|
-
* boundary, route `msgs` up from THIS node (broadcast, or up the single `towardDep` edge). The
|
|
1251
|
-
* deferred form of `ctx.up` — the SELF-demand path: a consumer issues `ctx.upNext([[PULL,
|
|
1252
|
-
* { pullId }]])` to demand a dep it ALSO reads; the demand applies at the boundary (not mid-fn), so
|
|
1253
|
-
* the pull node's delivery loops back as a FRESH wave rather than re-entering the consumer (D37 /
|
|
1254
|
-
* R-reentrancy). Rides the same R-rewire-deferred (D47) drain as ctx.rewireNext.
|
|
1255
|
-
*/
|
|
1256
|
-
_requestUpNext(msgs, towardDep) {
|
|
1257
|
-
deferRewire(
|
|
1258
|
-
this._core,
|
|
1259
|
-
() => {
|
|
1260
|
-
if (!this._released) this._up(msgs, towardDep);
|
|
1261
|
-
},
|
|
1262
|
-
{
|
|
1263
|
-
batchToken: currentBoundaryBatchToken(),
|
|
1264
|
-
isReady: () => !this._hasBoundaryPauseLock()
|
|
1265
|
-
}
|
|
1266
|
-
);
|
|
1267
|
-
}
|
|
1268
|
-
/** Apply one queued self-rewire at the boundary (drain thunk). */
|
|
1269
|
-
_applyRewireNext(op) {
|
|
1270
|
-
if (this._released) return;
|
|
1271
|
-
try {
|
|
1272
|
-
if (op.kind === "add") {
|
|
1273
|
-
const next = this._slot.deps.includes(op.dep) ? [...this._slot.deps] : [...this._slot.deps, op.dep];
|
|
1274
|
-
this._rewire(next, op.fn, { allowTerminalOwner: true });
|
|
1275
|
-
} else if (op.kind === "remove") {
|
|
1276
|
-
this._rewire(
|
|
1277
|
-
this._slot.deps.filter((d) => d !== op.dep),
|
|
1278
|
-
op.fn,
|
|
1279
|
-
{ allowTerminalOwner: true }
|
|
1280
|
-
);
|
|
1281
|
-
} else {
|
|
1282
|
-
this._rewire(this._dedupDeps(op.deps), op.fn, { allowTerminalOwner: true });
|
|
1283
|
-
}
|
|
1284
|
-
} catch (e) {
|
|
1285
|
-
this._down([["ERROR", errorPayload(e, "rewireNext op failed")]]);
|
|
1286
|
-
}
|
|
1287
|
-
}
|
|
1288
2318
|
// ── rewire (R-rewire / D42): intra-graph runtime topology mutation ──
|
|
1289
2319
|
/**
|
|
1290
2320
|
* Replace this node's deps atomically (surgical, Option-C). Requires an explicit
|
|
@@ -1312,6 +2342,15 @@ var Node = class {
|
|
|
1312
2342
|
fn
|
|
1313
2343
|
);
|
|
1314
2344
|
}
|
|
2345
|
+
_requestRewireNext(op) {
|
|
2346
|
+
nodeRequestRewireNext(nodeRuntimeHost(this), op);
|
|
2347
|
+
}
|
|
2348
|
+
_requestUpNext(msgs, towardDep) {
|
|
2349
|
+
nodeRequestUpNext(nodeRuntimeHost(this), msgs, towardDep);
|
|
2350
|
+
}
|
|
2351
|
+
_applyRewireNext(op) {
|
|
2352
|
+
nodeApplyRewireNext(nodeRuntimeHost(this), op);
|
|
2353
|
+
}
|
|
1315
2354
|
_dedupDeps(deps) {
|
|
1316
2355
|
const seen = /* @__PURE__ */ new Set();
|
|
1317
2356
|
const out = [];
|
|
@@ -1322,7 +2361,6 @@ var Node = class {
|
|
|
1322
2361
|
}
|
|
1323
2362
|
return out;
|
|
1324
2363
|
}
|
|
1325
|
-
/** Is `target` reachable upstream from `from` (following deps)? Cycle-prevention DFS. */
|
|
1326
2364
|
_reachableUpstream(from, target) {
|
|
1327
2365
|
const seen = /* @__PURE__ */ new Set();
|
|
1328
2366
|
const stack = [from];
|
|
@@ -1332,1057 +2370,171 @@ var Node = class {
|
|
|
1332
2370
|
if (n === target) return true;
|
|
1333
2371
|
if (seen.has(n)) continue;
|
|
1334
2372
|
seen.add(n);
|
|
1335
|
-
for (const d of n._slot.deps) stack.push(d);
|
|
2373
|
+
for (const d of nodeRuntimeHost(n)._slot.deps) stack.push(d);
|
|
1336
2374
|
}
|
|
1337
2375
|
return false;
|
|
1338
2376
|
}
|
|
1339
2377
|
_assertRewireDepOwner(dep) {
|
|
1340
2378
|
const selfOwner = getNodeOwner(this);
|
|
1341
2379
|
const depOwner = getNodeOwner(dep);
|
|
1342
|
-
if (selfOwner !== void 0 && depOwner !== void 0 && selfOwner !== depOwner)
|
|
2380
|
+
if (selfOwner !== void 0 && depOwner !== void 0 && selfOwner !== depOwner)
|
|
1343
2381
|
throw new Error(
|
|
1344
2382
|
"rewire: dep belongs to a different graph; cross-graph deps require a wire bridge (D22 / R-graph-domain)"
|
|
1345
2383
|
);
|
|
1346
|
-
}
|
|
1347
2384
|
}
|
|
1348
2385
|
_rewire(newDeps, fn, opts = {}) {
|
|
1349
|
-
|
|
1350
|
-
throw new Error(
|
|
1351
|
-
"rewire: node is terminal (completed/errored) \u2014 cannot rewire (R-rewire / D42)"
|
|
1352
|
-
);
|
|
1353
|
-
if (this._wave.insideRunWave)
|
|
1354
|
-
throw new Error(
|
|
1355
|
-
"rewire: mid-fn topology mutation \u2014 a fn mutating its own deps mid-wave is the feedback cycle (R-rewire / D37)"
|
|
1356
|
-
);
|
|
1357
|
-
if (this._wave.inDepMutation)
|
|
1358
|
-
throw new Error(
|
|
1359
|
-
"rewire: reentrant dep mutation \u2014 another replaceDeps/subscribeDep/unsubscribeDep is in flight (R-rewire)"
|
|
1360
|
-
);
|
|
1361
|
-
if (newDeps.includes(this))
|
|
1362
|
-
throw new Error("rewire: self-dependency rejected (R-rewire / D42)");
|
|
1363
|
-
const oldDeps = this._slot.deps;
|
|
1364
|
-
const added = newDeps.filter((d) => !oldDeps.includes(d));
|
|
1365
|
-
for (const d of added) {
|
|
1366
|
-
if (this._reachableUpstream(d, this))
|
|
1367
|
-
throw new Error(
|
|
1368
|
-
"rewire: would create a cycle \u2014 dep already transitively depends on this node (R-rewire / D42)"
|
|
1369
|
-
);
|
|
1370
|
-
if (d._value.terminal !== void 0 && !d._slot.resubscribable)
|
|
1371
|
-
throw new Error(
|
|
1372
|
-
"rewire: cannot add a non-resubscribable terminal dep \u2014 would wedge (R-rewire / D42)"
|
|
1373
|
-
);
|
|
1374
|
-
this._assertRewireDepOwner(d);
|
|
1375
|
-
}
|
|
1376
|
-
if (deferAfterBatchForTarget(this, () => {
|
|
1377
|
-
this._rewire(newDeps, fn, { ...opts, allowTerminalOwner: true });
|
|
1378
|
-
})) {
|
|
1379
|
-
return true;
|
|
1380
|
-
}
|
|
1381
|
-
if (!this._lifecycle.activated) this._restoredActivationPending = false;
|
|
1382
|
-
this._wave.inDepMutation = true;
|
|
1383
|
-
this._wave.rewireRunPending = false;
|
|
1384
|
-
let zeroDepUnDirty = false;
|
|
1385
|
-
try {
|
|
1386
|
-
const oldHandle = this._slot.handle;
|
|
1387
|
-
this._slot.handle = this._slot.dispatcher.register(fn, this._slot.pool);
|
|
1388
|
-
if (oldHandle !== null) this._slot.dispatcher.unregister(oldHandle);
|
|
1389
|
-
const removed = oldDeps.filter((d) => !newDeps.includes(d));
|
|
1390
|
-
let removedDirtyContributor = false;
|
|
1391
|
-
for (const d of removed) {
|
|
1392
|
-
const oldIdx = oldDeps.indexOf(d);
|
|
1393
|
-
if (this._dep.dirty[oldIdx]) {
|
|
1394
|
-
removedDirtyContributor = true;
|
|
1395
|
-
this._wave.pending--;
|
|
1396
|
-
}
|
|
1397
|
-
if (this._lifecycle.activated) {
|
|
1398
|
-
const box = this._dep.idxBoxes[oldIdx];
|
|
1399
|
-
if (box) box.v = -1;
|
|
1400
|
-
const unsub = this._dep.unsubs[oldIdx];
|
|
1401
|
-
if (unsub) unsub();
|
|
1402
|
-
}
|
|
1403
|
-
}
|
|
1404
|
-
const n = newDeps.length;
|
|
1405
|
-
const newBatch = new Array(n).fill(null);
|
|
1406
|
-
const newPrev = new Array(n).fill(SENTINEL);
|
|
1407
|
-
const newHasData = new Array(n).fill(false);
|
|
1408
|
-
const newDirty = new Array(n).fill(false);
|
|
1409
|
-
const newTier = new Array(n).fill(0);
|
|
1410
|
-
const newTerminal = new Array(n).fill(void 0);
|
|
1411
|
-
const newTerminalInput = new Array(n).fill(void 0);
|
|
1412
|
-
const newUnsubs = new Array(n);
|
|
1413
|
-
const newBoxes = new Array(n);
|
|
1414
|
-
for (let j = 0; j < n; j++) {
|
|
1415
|
-
const oldIdx = oldDeps.indexOf(newDeps[j]);
|
|
1416
|
-
if (oldIdx !== -1) {
|
|
1417
|
-
newBatch[j] = this._dep.batch[oldIdx];
|
|
1418
|
-
newPrev[j] = this._dep.prev[oldIdx];
|
|
1419
|
-
newHasData[j] = this._dep.hasData[oldIdx];
|
|
1420
|
-
newDirty[j] = this._dep.dirty[oldIdx];
|
|
1421
|
-
newTier[j] = this._dep.tier[oldIdx];
|
|
1422
|
-
newTerminal[j] = this._dep.terminal[oldIdx];
|
|
1423
|
-
newUnsubs[j] = this._dep.unsubs[oldIdx];
|
|
1424
|
-
const box = this._dep.idxBoxes[oldIdx];
|
|
1425
|
-
if (box) box.v = j;
|
|
1426
|
-
newBoxes[j] = box;
|
|
1427
|
-
}
|
|
1428
|
-
}
|
|
1429
|
-
this._slot.deps = newDeps;
|
|
1430
|
-
this._dep.batch = newBatch;
|
|
1431
|
-
this._dep.prev = newPrev;
|
|
1432
|
-
this._dep.hasData = newHasData;
|
|
1433
|
-
this._dep.dirty = newDirty;
|
|
1434
|
-
this._dep.tier = newTier;
|
|
1435
|
-
this._dep.terminal = newTerminal;
|
|
1436
|
-
this._dep.terminalInput = newTerminalInput;
|
|
1437
|
-
this._dep.unsubs = newUnsubs;
|
|
1438
|
-
this._dep.idxBoxes = newBoxes;
|
|
1439
|
-
this._dep.waveData = newDeps.map(() => []);
|
|
1440
|
-
this._dep.waveTokens = new Array(newDeps.length).fill(void 0);
|
|
1441
|
-
this._syncCtx = null;
|
|
1442
|
-
if (this._lifecycle.activated) {
|
|
1443
|
-
for (const d of added) this._subscribeDepAt(d);
|
|
1444
|
-
}
|
|
1445
|
-
notifyTopologyDepsChanged(this, oldDeps, newDeps);
|
|
1446
|
-
if (removedDirtyContributor && this._wave.pending === 0 && this._value.status === "dirty") {
|
|
1447
|
-
if (newDeps.length > 0) this._wave.rewireRunPending = true;
|
|
1448
|
-
else zeroDepUnDirty = true;
|
|
1449
|
-
}
|
|
1450
|
-
} finally {
|
|
1451
|
-
this._wave.inDepMutation = false;
|
|
1452
|
-
}
|
|
1453
|
-
if (this._wave.rewireRunPending) {
|
|
1454
|
-
this._wave.rewireRunPending = false;
|
|
1455
|
-
this._settleRewire();
|
|
1456
|
-
} else if (zeroDepUnDirty) {
|
|
1457
|
-
if (this._wave.emittedDirtyThisWave) this._down([["RESOLVED"]]);
|
|
1458
|
-
else this._value.status = this._value.hasData ? "settled" : "sentinel";
|
|
1459
|
-
}
|
|
1460
|
-
return false;
|
|
2386
|
+
return nodeRewire(nodeRuntimeHost(this), newDeps, fn, opts);
|
|
1461
2387
|
}
|
|
1462
2388
|
// ── activation / deactivation (lazy; R-rom-ram) ──
|
|
1463
2389
|
_activate() {
|
|
1464
|
-
this
|
|
1465
|
-
const seedRestoredDeps = this._restoredActivationPending;
|
|
1466
|
-
this._restoredActivationPending = false;
|
|
1467
|
-
this._dep.unsubs = new Array(this._slot.deps.length);
|
|
1468
|
-
this._dep.idxBoxes = new Array(this._slot.deps.length);
|
|
1469
|
-
for (const dep of this._slot.deps)
|
|
1470
|
-
this._subscribeDepAt(dep, { seedRestored: seedRestoredDeps });
|
|
1471
|
-
if (this._slot.deps.length === 0 && this._slot.handle !== null && !this._wave.hasCalledFnOnce) {
|
|
1472
|
-
this._runWave();
|
|
1473
|
-
}
|
|
1474
|
-
}
|
|
1475
|
-
/**
|
|
1476
|
-
* Subscribe to a dep. The dispatch callback reads the dep's CURRENT index from a
|
|
1477
|
-
* mutable box (O(1)); a surgical rewire that reorders kept deps just updates the box
|
|
1478
|
-
* (R-rewire Option-C / D42) — no re-subscribe, no per-message indexOf scan. A removed
|
|
1479
|
-
* dep's box is set to -1 so any stale in-flight callback drops (drain).
|
|
1480
|
-
*/
|
|
1481
|
-
_subscribeDepAt(depNode, opts = {}) {
|
|
1482
|
-
const idx0 = this._slot.deps.indexOf(depNode);
|
|
1483
|
-
const box = { v: idx0 };
|
|
1484
|
-
let ignoreInitialPush = opts.seedRestored === true;
|
|
1485
|
-
if (ignoreInitialPush && idx0 !== -1) {
|
|
1486
|
-
this._seedRestoredDepAt(idx0, depNode);
|
|
1487
|
-
if (depNode._value.terminal !== void 0 && !depNode._slot.resubscribable) {
|
|
1488
|
-
this._dep.unsubs[idx0] = () => {
|
|
1489
|
-
};
|
|
1490
|
-
this._dep.idxBoxes[idx0] = box;
|
|
1491
|
-
return;
|
|
1492
|
-
}
|
|
1493
|
-
}
|
|
1494
|
-
const unsub = depNode.subscribe((msg, delivery) => {
|
|
1495
|
-
if (ignoreInitialPush && delivery === void 0) return;
|
|
1496
|
-
if (ignoreInitialPush) ignoreInitialPush = false;
|
|
1497
|
-
if (box.v === -1) return;
|
|
1498
|
-
this._receiveFromDep(box.v, msg, delivery);
|
|
1499
|
-
});
|
|
1500
|
-
if (ignoreInitialPush && idx0 !== -1 && box.v !== -1) this._seedRestoredDepAt(idx0, depNode);
|
|
1501
|
-
ignoreInitialPush = false;
|
|
1502
|
-
if (idx0 !== -1) {
|
|
1503
|
-
this._dep.unsubs[idx0] = unsub;
|
|
1504
|
-
this._dep.idxBoxes[idx0] = box;
|
|
1505
|
-
}
|
|
1506
|
-
}
|
|
1507
|
-
_seedRestoredDepAt(idx, depNode) {
|
|
1508
|
-
const seedData = depNode._value.hasData && !depNode._slot.pull;
|
|
1509
|
-
this._dep.batch[idx] = null;
|
|
1510
|
-
this._dep.waveData[idx] = [];
|
|
1511
|
-
this._dep.waveTokens[idx] = void 0;
|
|
1512
|
-
this._dep.prev[idx] = seedData ? depNode._value.cache : SENTINEL;
|
|
1513
|
-
this._dep.hasData[idx] = seedData;
|
|
1514
|
-
this._dep.dirty[idx] = false;
|
|
1515
|
-
this._dep.tier[idx] = seedData ? 3 : 0;
|
|
1516
|
-
this._dep.terminal[idx] = depNode._value.terminal;
|
|
1517
|
-
this._dep.terminalInput[idx] = void 0;
|
|
2390
|
+
nodeActivate(nodeRuntimeHost(this));
|
|
1518
2391
|
}
|
|
1519
2392
|
_deactivate() {
|
|
1520
|
-
this
|
|
1521
|
-
for (const u of this._dep.unsubs) if (u) u();
|
|
1522
|
-
this._dep.unsubs = [];
|
|
1523
|
-
this._dep.idxBoxes = [];
|
|
1524
|
-
for (const fn of this._hooks.onDeactivation) fn();
|
|
1525
|
-
this._hooks.onDeactivation = [];
|
|
1526
|
-
this._hooks.onInvalidate = [];
|
|
1527
|
-
const isCompute = this._slot.handle !== null || this._slot.deps.length > 0;
|
|
1528
|
-
if (isCompute) {
|
|
1529
|
-
this._value.cache = SENTINEL;
|
|
1530
|
-
this._value.hasData = false;
|
|
1531
|
-
this._value.status = "sentinel";
|
|
1532
|
-
}
|
|
1533
|
-
this._resetDepState();
|
|
1534
|
-
this._wave.hasCalledFnOnce = false;
|
|
1535
|
-
this._control.pauseLockset.clear();
|
|
1536
|
-
this._control.pauseBuffer = [];
|
|
1537
|
-
this._control.pausedDepWaveOccurred = false;
|
|
1538
|
-
this._control.demandOwed = void 0;
|
|
1539
|
-
this._control.activePull = void 0;
|
|
1540
|
-
this._control.pullDirtyOwed = false;
|
|
1541
|
-
this._value.replayRing = [];
|
|
1542
|
-
if (!this._privateState.persist) this._privateState.value = SENTINEL;
|
|
2393
|
+
nodeDeactivate(nodeRuntimeHost(this));
|
|
1543
2394
|
}
|
|
1544
2395
|
_assertNotReleased(op) {
|
|
1545
2396
|
if (this._released)
|
|
1546
2397
|
throw new Error(`${op}: node has been released from its graph lifecycle (D122)`);
|
|
1547
2398
|
}
|
|
1548
2399
|
_subscriberCount() {
|
|
1549
|
-
return this
|
|
2400
|
+
return nodeSubscriberCount(nodeRuntimeHost(this));
|
|
1550
2401
|
}
|
|
1551
2402
|
_isRuntimeQuiescentForRelease() {
|
|
1552
|
-
return
|
|
2403
|
+
return nodeIsRuntimeQuiescentForRelease(nodeRuntimeHost(this));
|
|
1553
2404
|
}
|
|
1554
2405
|
_releaseRuntime() {
|
|
1555
|
-
|
|
1556
|
-
this._released = true;
|
|
1557
|
-
releasedNodes.add(this);
|
|
1558
|
-
let releaseError;
|
|
1559
|
-
const recordReleaseError = (error) => {
|
|
1560
|
-
if (releaseError === void 0) releaseError = error;
|
|
1561
|
-
};
|
|
1562
|
-
this._lifecycle.activated = false;
|
|
1563
|
-
for (const u of this._dep.unsubs) {
|
|
1564
|
-
try {
|
|
1565
|
-
u();
|
|
1566
|
-
} catch (error) {
|
|
1567
|
-
recordReleaseError(error);
|
|
1568
|
-
}
|
|
1569
|
-
}
|
|
1570
|
-
for (const fn of this._hooks.onDeactivation) {
|
|
1571
|
-
try {
|
|
1572
|
-
fn();
|
|
1573
|
-
} catch (error) {
|
|
1574
|
-
recordReleaseError(error);
|
|
1575
|
-
}
|
|
1576
|
-
}
|
|
1577
|
-
this._dep.unsubs = [];
|
|
1578
|
-
this._dep.idxBoxes = [];
|
|
1579
|
-
this._lifecycle.subscribers.clear();
|
|
1580
|
-
if (this._slot.handle !== null) {
|
|
1581
|
-
this._slot.dispatcher.unregister(this._slot.handle);
|
|
1582
|
-
this._slot.handle = null;
|
|
1583
|
-
}
|
|
1584
|
-
this._slot.deps = [];
|
|
1585
|
-
this._dep.batch = [];
|
|
1586
|
-
this._dep.waveData = [];
|
|
1587
|
-
this._dep.waveTokens = [];
|
|
1588
|
-
this._dep.prev = [];
|
|
1589
|
-
this._dep.hasData = [];
|
|
1590
|
-
this._dep.dirty = [];
|
|
1591
|
-
this._dep.tier = [];
|
|
1592
|
-
this._dep.terminal = [];
|
|
1593
|
-
this._dep.terminalInput = [];
|
|
1594
|
-
this._value.cache = SENTINEL;
|
|
1595
|
-
this._value.hasData = false;
|
|
1596
|
-
this._value.status = "sentinel";
|
|
1597
|
-
this._value.terminal = void 0;
|
|
1598
|
-
this._value.replayRing = [];
|
|
1599
|
-
this._privateState.value = SENTINEL;
|
|
1600
|
-
this._privateState.persist = false;
|
|
1601
|
-
this._syncCtx = null;
|
|
1602
|
-
this._resetDepState();
|
|
1603
|
-
this._hooks.onDeactivation = [];
|
|
1604
|
-
this._hooks.onInvalidate = [];
|
|
1605
|
-
this._control.pauseLockset.clear();
|
|
1606
|
-
this._control.pauseBuffer = [];
|
|
1607
|
-
this._control.pausedDepWaveOccurred = false;
|
|
1608
|
-
this._control.demandOwed = void 0;
|
|
1609
|
-
this._control.activePull = void 0;
|
|
1610
|
-
this._control.pullDirtyOwed = false;
|
|
1611
|
-
this._restoredActivationPending = false;
|
|
1612
|
-
checkpointReaders.delete(this);
|
|
1613
|
-
restoreWriters.delete(this);
|
|
1614
|
-
runtimeReleasers.delete(this);
|
|
1615
|
-
runtimeQuiescenceReaders.delete(this);
|
|
1616
|
-
subscriberCountReaders.delete(this);
|
|
1617
|
-
activationReaders.delete(this);
|
|
1618
|
-
ownerTokens.delete(this);
|
|
1619
|
-
topologyDepsChangedObservers.delete(this);
|
|
1620
|
-
this._core.releaseSlot(this._id);
|
|
1621
|
-
if (releaseError !== void 0) throw releaseError;
|
|
2406
|
+
nodeReleaseRuntime(nodeRuntimeHost(this));
|
|
1622
2407
|
}
|
|
1623
2408
|
_resetDepState() {
|
|
1624
|
-
|
|
1625
|
-
|
|
1626
|
-
|
|
1627
|
-
|
|
1628
|
-
|
|
1629
|
-
|
|
1630
|
-
|
|
1631
|
-
|
|
1632
|
-
this._dep.tier[i] = 0;
|
|
1633
|
-
this._dep.terminal[i] = void 0;
|
|
1634
|
-
this._dep.terminalInput[i] = void 0;
|
|
1635
|
-
}
|
|
1636
|
-
this._wave.pending = 0;
|
|
1637
|
-
this._wave.emittedDirtyThisWave = false;
|
|
1638
|
-
}
|
|
1639
|
-
// ── upstream wave receive (two-phase + diamond) ──
|
|
2409
|
+
nodeResetDepState(nodeRuntimeHost(this));
|
|
2410
|
+
}
|
|
2411
|
+
_subscribeDepAt(depNode, opts = {}) {
|
|
2412
|
+
nodeSubscribeDepAt(nodeRuntimeHost(this), depNode, opts);
|
|
2413
|
+
}
|
|
2414
|
+
_seedRestoredDepAt(idx, depNode) {
|
|
2415
|
+
nodeSeedRestoredDepAt(nodeRuntimeHost(this), idx, depNode);
|
|
2416
|
+
}
|
|
1640
2417
|
_recordDepProjection(idx, delivery) {
|
|
1641
|
-
|
|
1642
|
-
if (this._dep.waveTokens[idx] !== token) {
|
|
1643
|
-
this._dep.waveData[idx].push([]);
|
|
1644
|
-
this._dep.waveTokens[idx] = token;
|
|
1645
|
-
}
|
|
1646
|
-
return this._dep.waveData[idx][this._dep.waveData[idx].length - 1];
|
|
2418
|
+
return nodeRecordDepProjection(nodeRuntimeHost(this), idx, delivery);
|
|
1647
2419
|
}
|
|
1648
2420
|
_depProjectionHasData(idx) {
|
|
1649
|
-
|
|
1650
|
-
return projection?.some((v) => v !== SENTINEL) ?? false;
|
|
2421
|
+
return nodeDepProjectionHasData(nodeRuntimeHost(this), idx);
|
|
1651
2422
|
}
|
|
1652
2423
|
_receiveFromDep(idx, msg, delivery) {
|
|
1653
|
-
|
|
1654
|
-
const t = msg[0];
|
|
1655
|
-
if (t === "START") return;
|
|
1656
|
-
const isLastInDeliveredWave = delivery?.last ?? true;
|
|
1657
|
-
if (this._value.terminal !== void 0) {
|
|
1658
|
-
if (t === "TEARDOWN") this._down([["TEARDOWN"]]);
|
|
1659
|
-
return;
|
|
1660
|
-
}
|
|
1661
|
-
if (t === "INVALIDATE") {
|
|
1662
|
-
const projection = this._recordDepProjection(idx, delivery);
|
|
1663
|
-
projection.push(SENTINEL);
|
|
1664
|
-
if (projection.some((v) => v !== SENTINEL) && isLastInDeliveredWave) this._maybeRun();
|
|
1665
|
-
this._dep.prev[idx] = SENTINEL;
|
|
1666
|
-
this._dep.hasData[idx] = false;
|
|
1667
|
-
this._dep.batch[idx] = null;
|
|
1668
|
-
if (this._dep.dirty[idx]) {
|
|
1669
|
-
this._dep.dirty[idx] = false;
|
|
1670
|
-
this._wave.pending--;
|
|
1671
|
-
}
|
|
1672
|
-
if (this._control.pausedDepWaveOccurred && this._dep.batch.every((b) => b === null)) {
|
|
1673
|
-
this._control.pausedDepWaveOccurred = false;
|
|
1674
|
-
}
|
|
1675
|
-
const hadData = this._value.hasData;
|
|
1676
|
-
this._invalidate();
|
|
1677
|
-
if (this._wave.pending === 0 && this._wave.emittedDirtyThisWave) {
|
|
1678
|
-
if (!hadData) this._down([["RESOLVED"]]);
|
|
1679
|
-
else this._wave.emittedDirtyThisWave = false;
|
|
1680
|
-
}
|
|
1681
|
-
this._fireOwedDemandIfReady();
|
|
1682
|
-
return;
|
|
1683
|
-
}
|
|
1684
|
-
if (isTerminal(t)) {
|
|
1685
|
-
const isError = t === "ERROR";
|
|
1686
|
-
const errPayload = isError ? msg[1] : void 0;
|
|
1687
|
-
this._dep.terminal[idx] = isError ? errPayload : true;
|
|
1688
|
-
this._dep.terminalInput[idx] = isError ? errPayload : true;
|
|
1689
|
-
this._releaseDepDirty(idx);
|
|
1690
|
-
const ranValueBeforeTerminal = this._depProjectionHasData(idx) && isLastInDeliveredWave;
|
|
1691
|
-
if (ranValueBeforeTerminal) this._maybeRun();
|
|
1692
|
-
if (isError && this._slot.errorWhenDepsError) {
|
|
1693
|
-
this._down([["ERROR", errPayload]]);
|
|
1694
|
-
} else if (this._slot.terminalAsRealInput) {
|
|
1695
|
-
if (ranValueBeforeTerminal) {
|
|
1696
|
-
this._fireOwedDemandIfReady();
|
|
1697
|
-
return;
|
|
1698
|
-
}
|
|
1699
|
-
this._maybeRun();
|
|
1700
|
-
} else if (this._slot.completeWhenDepsComplete && this._allDepsTerminal()) {
|
|
1701
|
-
this._down([["COMPLETE"]]);
|
|
1702
|
-
} else {
|
|
1703
|
-
this._settleAfterAbsorbedTerminal();
|
|
1704
|
-
}
|
|
1705
|
-
this._fireOwedDemandIfReady();
|
|
1706
|
-
return;
|
|
1707
|
-
}
|
|
1708
|
-
if (t === "TEARDOWN") {
|
|
1709
|
-
this._down([["TEARDOWN"]]);
|
|
1710
|
-
return;
|
|
1711
|
-
}
|
|
1712
|
-
if (t === "DIRTY") {
|
|
1713
|
-
if (!this._dep.dirty[idx]) {
|
|
1714
|
-
this._dep.dirty[idx] = true;
|
|
1715
|
-
this._wave.pending++;
|
|
1716
|
-
this._dep.tier[idx] = 2;
|
|
1717
|
-
this._markDirty();
|
|
1718
|
-
}
|
|
1719
|
-
return;
|
|
1720
|
-
}
|
|
1721
|
-
if (t === "DATA") {
|
|
1722
|
-
const v = msg[1];
|
|
1723
|
-
this._recordDepProjection(idx, delivery).push(v);
|
|
1724
|
-
const b = this._dep.batch[idx];
|
|
1725
|
-
if (b === null) this._dep.batch[idx] = [v];
|
|
1726
|
-
else b.push(v);
|
|
1727
|
-
this._dep.prev[idx] = v;
|
|
1728
|
-
this._dep.hasData[idx] = true;
|
|
1729
|
-
this._dep.tier[idx] = 3;
|
|
1730
|
-
if (this._dep.dirty[idx]) {
|
|
1731
|
-
this._dep.dirty[idx] = false;
|
|
1732
|
-
this._wave.pending--;
|
|
1733
|
-
}
|
|
1734
|
-
if (isLastInDeliveredWave) this._maybeRun();
|
|
1735
|
-
this._fireOwedDemandIfReady();
|
|
1736
|
-
return;
|
|
1737
|
-
}
|
|
1738
|
-
if (t === "RESOLVED") {
|
|
1739
|
-
this._recordDepProjection(idx, delivery);
|
|
1740
|
-
this._dep.tier[idx] = 3;
|
|
1741
|
-
if (this._dep.dirty[idx]) {
|
|
1742
|
-
this._dep.dirty[idx] = false;
|
|
1743
|
-
this._wave.pending--;
|
|
1744
|
-
}
|
|
1745
|
-
if (isLastInDeliveredWave) this._maybeRun();
|
|
1746
|
-
this._fireOwedDemandIfReady();
|
|
1747
|
-
return;
|
|
1748
|
-
}
|
|
2424
|
+
nodeReceiveFromDep(nodeRuntimeHost(this), idx, msg, delivery);
|
|
1749
2425
|
}
|
|
1750
|
-
/**
|
|
1751
|
-
* R-terminal-settles-dirty (B35): release a dep's outstanding in-wave DIRTY contribution.
|
|
1752
|
-
* A settle-class event for that dep (DATA/RESOLVED inline above, INVALIDATE, and now
|
|
1753
|
-
* COMPLETE/ERROR) clears its dirty flag + decrements _pending. No-op if the dep already
|
|
1754
|
-
* settled this wave (DATA/RESOLVED ran first) — so the normal DATA-then-COMPLETE flow is
|
|
1755
|
-
* unaffected. This makes the exactly-one-settle invariant a single, shared step.
|
|
1756
|
-
*/
|
|
1757
2426
|
_releaseDepDirty(idx) {
|
|
1758
|
-
|
|
1759
|
-
this._dep.dirty[idx] = false;
|
|
1760
|
-
this._wave.pending--;
|
|
1761
|
-
}
|
|
2427
|
+
nodeReleaseDepDirty(nodeRuntimeHost(this), idx);
|
|
1762
2428
|
}
|
|
1763
|
-
/**
|
|
1764
|
-
* R-terminal-settles-dirty (B35): settle a node whose dirtied dep was released by an ABSORBED
|
|
1765
|
-
* terminal that is NOT a real input (a plain derived/effect — the common default-node case when
|
|
1766
|
-
* one of several deps completes while others stay live). Runs only when the release drained
|
|
1767
|
-
* _pending while the node still owes a downstream settle (it broadcast DIRTY this wave):
|
|
1768
|
-
* - if some OTHER dep delivered real DATA this wave (a value occurred) → recompute (→ DATA);
|
|
1769
|
-
* - else the terminal's signalled change did not materialise (no value) → one undirty RESOLVED
|
|
1770
|
-
* (R-resolved-undirty), keeping the cache (a terminal, unlike INVALIDATE, leaves the value).
|
|
1771
|
-
* A terminalAsRealInput node instead recomputes unconditionally (its fn reads the terminal).
|
|
1772
|
-
*/
|
|
1773
2429
|
_settleAfterAbsorbedTerminal() {
|
|
1774
|
-
|
|
1775
|
-
const sawData = this._dep.batch.some((b) => b !== null && b.length > 0);
|
|
1776
|
-
if (sawData) this._maybeRun();
|
|
1777
|
-
if (this._wave.emittedDirtyThisWave) this._down([["RESOLVED"]]);
|
|
2430
|
+
nodeSettleAfterAbsorbedTerminal(nodeRuntimeHost(this));
|
|
1778
2431
|
}
|
|
1779
2432
|
_markDirty() {
|
|
1780
|
-
this
|
|
1781
|
-
if (this._isPullQuiet()) return;
|
|
1782
|
-
if (!this._wave.emittedDirtyThisWave) {
|
|
1783
|
-
this._wave.emittedDirtyThisWave = true;
|
|
1784
|
-
this._emitToSubs(["DIRTY"]);
|
|
1785
|
-
}
|
|
2433
|
+
nodeMarkDirty(nodeRuntimeHost(this));
|
|
1786
2434
|
}
|
|
1787
2435
|
_maybeRun() {
|
|
1788
|
-
|
|
1789
|
-
this._wave.rewireRunPending = true;
|
|
1790
|
-
return;
|
|
1791
|
-
}
|
|
1792
|
-
if (this._slot.pausable === true && (this._isPaused() || this._isPullQuiet())) {
|
|
1793
|
-
this._control.pausedDepWaveOccurred = true;
|
|
1794
|
-
return;
|
|
1795
|
-
}
|
|
1796
|
-
this._tryRun();
|
|
2436
|
+
nodeMaybeRun(nodeRuntimeHost(this));
|
|
1797
2437
|
}
|
|
1798
|
-
/**
|
|
1799
|
-
* R-rewire atomic settle (after a rewire that warrants a recompute): emit a proper
|
|
1800
|
-
* two-phase DIRTY→DATA wave (R-dirty-before-data — a rewire-triggered settle is a wave),
|
|
1801
|
-
* once, with every added dep already wired. Mirrors _maybeRun/_tryRun's pause + gate +
|
|
1802
|
-
* pending guards, then injects the phase-1 DIRTY the added dep's [START,DATA] handshake
|
|
1803
|
-
* did not carry.
|
|
1804
|
-
*/
|
|
1805
2438
|
_settleRewire() {
|
|
1806
|
-
|
|
1807
|
-
this._control.pausedDepWaveOccurred = true;
|
|
1808
|
-
return;
|
|
1809
|
-
}
|
|
1810
|
-
if (this._wave.pending > 0) return;
|
|
1811
|
-
if (this._slot.handle === null) {
|
|
1812
|
-
this._passthroughEmit();
|
|
1813
|
-
return;
|
|
1814
|
-
}
|
|
1815
|
-
if (!this._wave.hasCalledFnOnce && !(this._slot.partial || this._allDepsSettled())) return;
|
|
1816
|
-
this._markDirty();
|
|
1817
|
-
this._runWave();
|
|
2439
|
+
nodeSettleRewire(nodeRuntimeHost(this));
|
|
1818
2440
|
}
|
|
1819
2441
|
_tryRun() {
|
|
1820
|
-
|
|
1821
|
-
if (this._slot.handle === null) {
|
|
1822
|
-
this._passthroughEmit();
|
|
1823
|
-
return;
|
|
1824
|
-
}
|
|
1825
|
-
if (!this._wave.hasCalledFnOnce) {
|
|
1826
|
-
if (this._slot.partial || this._allDepsSettled()) this._runWave();
|
|
1827
|
-
return;
|
|
1828
|
-
}
|
|
1829
|
-
this._runWave();
|
|
2442
|
+
nodeTryRun(nodeRuntimeHost(this));
|
|
1830
2443
|
}
|
|
1831
2444
|
_allDepsSettled() {
|
|
1832
|
-
|
|
1833
|
-
if (this._dep.hasData[i]) continue;
|
|
1834
|
-
if (this._slot.terminalAsRealInput && this._dep.terminal[i] !== void 0) continue;
|
|
1835
|
-
return false;
|
|
1836
|
-
}
|
|
1837
|
-
return true;
|
|
2445
|
+
return nodeAllDepsSettled(nodeRuntimeHost(this));
|
|
1838
2446
|
}
|
|
1839
2447
|
_passthroughEmit() {
|
|
1840
|
-
|
|
1841
|
-
if (b !== null && b.length > 0) {
|
|
1842
|
-
this._down([["DATA", b[b.length - 1]]]);
|
|
1843
|
-
} else if (this._wave.emittedDirtyThisWave) {
|
|
1844
|
-
this._down([["RESOLVED"]]);
|
|
1845
|
-
}
|
|
1846
|
-
this._dep.batch[0] = null;
|
|
1847
|
-
this._wave.emittedDirtyThisWave = false;
|
|
2448
|
+
nodePassthroughEmit(nodeRuntimeHost(this));
|
|
1848
2449
|
}
|
|
1849
2450
|
_runWave() {
|
|
1850
|
-
|
|
1851
|
-
throw new Error(
|
|
1852
|
-
"synchronous feedback cycle: node fn re-entered its own wave (R-reentrancy / D37)"
|
|
1853
|
-
);
|
|
1854
|
-
this._wave.hasCalledFnOnce = true;
|
|
1855
|
-
this._hooks.onInvalidate = [];
|
|
1856
|
-
this._hooks.onDeactivation = [];
|
|
1857
|
-
const ctx = this._buildCtx();
|
|
1858
|
-
const wasDirty = this._wave.emittedDirtyThisWave;
|
|
1859
|
-
this._wave.emittedSettleThisWave = false;
|
|
1860
|
-
this._wave.insideRunWave = true;
|
|
1861
|
-
try {
|
|
1862
|
-
this._slot.dispatcher.invoke(this._slot.handle, ctx);
|
|
1863
|
-
} finally {
|
|
1864
|
-
this._wave.insideRunWave = false;
|
|
1865
|
-
}
|
|
1866
|
-
if (wasDirty && !this._wave.emittedSettleThisWave && this._value.terminal === void 0 && !this._isAsyncPool()) {
|
|
1867
|
-
this._down([["RESOLVED"]]);
|
|
1868
|
-
}
|
|
1869
|
-
for (let i = 0; i < this._dep.batch.length; i++) {
|
|
1870
|
-
this._dep.batch[i] = null;
|
|
1871
|
-
this._dep.waveData[i] = [];
|
|
1872
|
-
this._dep.waveTokens[i] = void 0;
|
|
1873
|
-
this._dep.terminalInput[i] = void 0;
|
|
1874
|
-
}
|
|
1875
|
-
this._wave.emittedDirtyThisWave = false;
|
|
2451
|
+
nodeRunWave(nodeRuntimeHost(this));
|
|
1876
2452
|
}
|
|
1877
|
-
// ── ctx construction (L3-Q5: sync = node-stable reused ctx; async = per-invocation) ──
|
|
1878
2453
|
_buildCtx() {
|
|
1879
|
-
|
|
1880
|
-
if (kind === "sync") {
|
|
1881
|
-
if (this._syncCtx === null) this._syncCtx = this._makeCtx();
|
|
1882
|
-
this._refreshCtx(this._syncCtx);
|
|
1883
|
-
return this._syncCtx;
|
|
1884
|
-
}
|
|
1885
|
-
return this._makeCtx({
|
|
1886
|
-
waveData: this._dep.waveData.map((waves) => waves.map((w) => [...w])),
|
|
1887
|
-
terminal: this._dep.terminalInput.map(terminalView),
|
|
1888
|
-
latest: [...this._dep.prev]
|
|
1889
|
-
});
|
|
2454
|
+
return nodeBuildCtx(nodeRuntimeHost(this));
|
|
1890
2455
|
}
|
|
1891
2456
|
_makeCtx(snapshot) {
|
|
1892
|
-
|
|
1893
|
-
// Wave-owner boundary (D47): a SYNC fn's emit nests under the public entry that drove
|
|
1894
|
-
// it (cheap inc/dec, no early drain); an ASYNC-pool fn re-enters here from its stashed
|
|
1895
|
-
// ctx at depth 0, so this is the boundary that drains any rewireNext it issued.
|
|
1896
|
-
up: (msgs, towardDep) => {
|
|
1897
|
-
if (this._released) return;
|
|
1898
|
-
enterWave();
|
|
1899
|
-
try {
|
|
1900
|
-
this._up(msgs, towardDep);
|
|
1901
|
-
} finally {
|
|
1902
|
-
exitWave();
|
|
1903
|
-
}
|
|
1904
|
-
},
|
|
1905
|
-
down: (msgs) => {
|
|
1906
|
-
if (this._released) return;
|
|
1907
|
-
enterWave();
|
|
1908
|
-
try {
|
|
1909
|
-
this._down(msgs);
|
|
1910
|
-
} finally {
|
|
1911
|
-
exitWave();
|
|
1912
|
-
}
|
|
1913
|
-
},
|
|
1914
|
-
waveData: snapshot?.waveData ?? this._dep.waveData,
|
|
1915
|
-
terminal: snapshot?.terminal ?? this._dep.terminalInput.map(terminalView),
|
|
1916
|
-
state: this._makeState(),
|
|
1917
|
-
onDeactivation: (fn) => {
|
|
1918
|
-
if (this._released) return;
|
|
1919
|
-
this._hooks.onDeactivation.push(fn);
|
|
1920
|
-
},
|
|
1921
|
-
onInvalidate: (fn) => {
|
|
1922
|
-
if (this._released) return;
|
|
1923
|
-
this._hooks.onInvalidate.push(fn);
|
|
1924
|
-
},
|
|
1925
|
-
environment: () => this._slot.environment,
|
|
1926
|
-
// R-rewire-deferred (D47): defer a self-dep-set mutation to the committed boundary.
|
|
1927
|
-
rewireNext: {
|
|
1928
|
-
subscribeDep: (dep, fn) => this._requestRewireNext({ kind: "add", dep, fn }),
|
|
1929
|
-
unsubscribeDep: (dep, fn) => this._requestRewireNext({ kind: "remove", dep, fn }),
|
|
1930
|
-
replaceDeps: (deps, fn) => this._requestRewireNext({ kind: "set", deps, fn })
|
|
1931
|
-
},
|
|
1932
|
-
// R-up-routing / R-pull (D269): deferred up — route a control/demand wave (e.g. PULL)
|
|
1933
|
-
// up the declared cone at the committed boundary. The SELF-demand path: an
|
|
1934
|
-
// immediate ctx.up whose delivery loops back re-enters this fn (D37 / R-reentrancy).
|
|
1935
|
-
upNext: (msgs, towardDep) => this._requestUpNext(msgs, towardDep),
|
|
1936
|
-
...this._control.activePull === void 0 ? {} : { pull: this._control.activePull },
|
|
1937
|
-
[CTX_DEP_CACHE]: { latest: snapshot?.latest ?? this._dep.prev },
|
|
1938
|
-
[CTX_NODE_BINDING]: {
|
|
1939
|
-
dispatcher: this._slot.dispatcher,
|
|
1940
|
-
create: (factory) => withEnvironmentDrivers(this._slot.environment, () => withNodeCore(this._core, factory))
|
|
1941
|
-
}
|
|
1942
|
-
};
|
|
1943
|
-
if (this._slot.dynamic) {
|
|
1944
|
-
ctx.track = (i) => ctx[CTX_DEP_CACHE]?.latest[i];
|
|
1945
|
-
}
|
|
1946
|
-
return ctx;
|
|
2457
|
+
return nodeMakeCtx(nodeRuntimeHost(this), snapshot);
|
|
1947
2458
|
}
|
|
1948
2459
|
_refreshCtx(ctx) {
|
|
1949
|
-
ctx
|
|
1950
|
-
ctx.terminal = this._dep.terminalInput.map(terminalView);
|
|
1951
|
-
if (this._control.activePull === void 0) {
|
|
1952
|
-
delete ctx.pull;
|
|
1953
|
-
} else {
|
|
1954
|
-
ctx.pull = this._control.activePull;
|
|
1955
|
-
}
|
|
1956
|
-
ctx[CTX_DEP_CACHE] = { latest: this._dep.prev };
|
|
2460
|
+
nodeRefreshCtx(nodeRuntimeHost(this), ctx);
|
|
1957
2461
|
}
|
|
1958
2462
|
_makeState() {
|
|
1959
|
-
return
|
|
1960
|
-
get: () => this._privateState.value,
|
|
1961
|
-
set: (v) => {
|
|
1962
|
-
this._privateState.value = v;
|
|
1963
|
-
},
|
|
1964
|
-
persist: (on = true) => {
|
|
1965
|
-
this._privateState.persist = on;
|
|
1966
|
-
}
|
|
1967
|
-
};
|
|
2463
|
+
return nodeMakeState(nodeRuntimeHost(this));
|
|
1968
2464
|
}
|
|
1969
2465
|
// ── downstream emission pipeline (the unified waist) ──
|
|
1970
2466
|
_down(msgs) {
|
|
1971
|
-
|
|
1972
|
-
validateDownPayloads(msgs);
|
|
1973
|
-
const deliveryWave = {};
|
|
1974
|
-
const assertVersionDataCompatible = (wave) => {
|
|
1975
|
-
for (const m of wave) {
|
|
1976
|
-
if (m[0] === "DATA") assertNodeVersionDataCompatible(this._version.policy, m[1]);
|
|
1977
|
-
}
|
|
1978
|
-
};
|
|
1979
|
-
const snapshotVersionData = (wave) => wave.map(
|
|
1980
|
-
(m) => m[0] === "DATA" ? ["DATA", snapshotNodeVersionData(this._version.policy, m[1])] : m
|
|
1981
|
-
);
|
|
1982
|
-
assertVersionDataCompatible(msgs);
|
|
1983
|
-
if (this._value.terminal !== void 0) {
|
|
1984
|
-
if (!msgs.some((m) => m[0] === "TEARDOWN")) return;
|
|
1985
|
-
this._value.hasTorndown = true;
|
|
1986
|
-
if (this._slot.resetOnTeardown) {
|
|
1987
|
-
this._value.cache = SENTINEL;
|
|
1988
|
-
this._value.hasData = false;
|
|
1989
|
-
}
|
|
1990
|
-
this._emitToSubs(["TEARDOWN"], { wave: deliveryWave, last: true });
|
|
1991
|
-
return;
|
|
1992
|
-
}
|
|
1993
|
-
let sorted = [...msgs].sort((a, b) => messageTier(a[0]) - messageTier(b[0]));
|
|
1994
|
-
const firstInvalidate = sorted.findIndex((m) => m[0] === "INVALIDATE");
|
|
1995
|
-
if (firstInvalidate !== -1) {
|
|
1996
|
-
sorted = sorted.filter((m, i) => m[0] !== "INVALIDATE" || i === firstInvalidate);
|
|
1997
|
-
}
|
|
1998
|
-
const hasTeardown = sorted.some((m) => m[0] === "TEARDOWN");
|
|
1999
|
-
const hasTerminal = sorted.some((m) => m[0] === "COMPLETE" || m[0] === "ERROR");
|
|
2000
|
-
if (hasTeardown && !hasTerminal && this._value.terminal === void 0 && !this._value.hasTorndown) {
|
|
2001
|
-
sorted = [["COMPLETE"], ...sorted];
|
|
2002
|
-
}
|
|
2003
|
-
if (!this._wave.insideRunWave && currentBatch()) {
|
|
2004
|
-
const deferred = snapshotVersionData(sorted.filter((m) => isDeferredTier(m[0])));
|
|
2005
|
-
if (deferred.length > 0) {
|
|
2006
|
-
if (!this._wave.emittedDirtyThisWave) {
|
|
2007
|
-
this._wave.emittedDirtyThisWave = true;
|
|
2008
|
-
this._value.status = "dirty";
|
|
2009
|
-
this._emitToSubs(["DIRTY"], { wave: deliveryWave, last: false });
|
|
2010
|
-
}
|
|
2011
|
-
this._wave.batchDirtyOwed = true;
|
|
2012
|
-
deferToBatch(this, deferred);
|
|
2013
|
-
return;
|
|
2014
|
-
}
|
|
2015
|
-
}
|
|
2016
|
-
if (this._shouldBufferOnPause()) {
|
|
2017
|
-
const buffered = snapshotVersionData(sorted.filter((m) => isPauseBufferedTier(m[0])));
|
|
2018
|
-
if (buffered.length > 0) {
|
|
2019
|
-
this._wave.emittedSettleThisWave = true;
|
|
2020
|
-
this._control.pauseBuffer.push(buffered);
|
|
2021
|
-
}
|
|
2022
|
-
sorted = sorted.filter((m) => !isPauseBufferedTier(m[0]));
|
|
2023
|
-
if (sorted.length === 0) return;
|
|
2024
|
-
}
|
|
2025
|
-
let dataCount = 0;
|
|
2026
|
-
let hasTier3 = false;
|
|
2027
|
-
let hasResolved = false;
|
|
2028
|
-
for (const m of sorted) {
|
|
2029
|
-
if (m[0] === "DATA") dataCount++;
|
|
2030
|
-
if (m[0] === "RESOLVED") hasResolved = true;
|
|
2031
|
-
if (isValueTier(m[0])) hasTier3 = true;
|
|
2032
|
-
}
|
|
2033
|
-
if (dataCount >= 1 && hasResolved) {
|
|
2034
|
-
throw new Error(
|
|
2035
|
-
"down: a wave cannot mix DATA and RESOLVED (tier-3 exclusivity, R-resolved-undirty)"
|
|
2036
|
-
);
|
|
2037
|
-
}
|
|
2038
|
-
const plannedVersions = new Array(sorted.length);
|
|
2039
|
-
if (dataCount > 0) {
|
|
2040
|
-
let plannedVersion = this._version.value;
|
|
2041
|
-
for (let i = 0; i < sorted.length; i++) {
|
|
2042
|
-
const m = sorted[i];
|
|
2043
|
-
if (m[0] !== "DATA") continue;
|
|
2044
|
-
plannedVersion = advanceNodeVersion(plannedVersion, this._version.policy, m[1]);
|
|
2045
|
-
plannedVersions[i] = plannedVersion;
|
|
2046
|
-
}
|
|
2047
|
-
}
|
|
2048
|
-
if (hasTier3 && (!this._wave.insideRunWave || this._control.pullDirtyOwed) && !this._wave.emittedDirtyThisWave) {
|
|
2049
|
-
this._wave.emittedDirtyThisWave = true;
|
|
2050
|
-
this._value.status = "dirty";
|
|
2051
|
-
this._emitToSubs(["DIRTY"], { wave: deliveryWave, last: false });
|
|
2052
|
-
}
|
|
2053
|
-
for (let i = 0; i < sorted.length; i++) {
|
|
2054
|
-
const m = sorted[i];
|
|
2055
|
-
const delivery = { wave: deliveryWave, last: i === sorted.length - 1 };
|
|
2056
|
-
if (isDeferredTier(m[0])) this._wave.emittedSettleThisWave = true;
|
|
2057
|
-
if (m[0] === "DIRTY") {
|
|
2058
|
-
if (!this._wave.emittedDirtyThisWave) {
|
|
2059
|
-
this._wave.emittedDirtyThisWave = true;
|
|
2060
|
-
this._value.status = "dirty";
|
|
2061
|
-
this._emitToSubs(["DIRTY"], delivery);
|
|
2062
|
-
}
|
|
2063
|
-
continue;
|
|
2064
|
-
}
|
|
2065
|
-
if (m[0] === "DATA") {
|
|
2066
|
-
const v = m[1];
|
|
2067
|
-
this._value.cache = v;
|
|
2068
|
-
this._value.hasData = true;
|
|
2069
|
-
this._value.status = "settled";
|
|
2070
|
-
this._version.value = plannedVersions[i];
|
|
2071
|
-
if (this._slot.replayN > 0) {
|
|
2072
|
-
this._value.replayRing.push(v);
|
|
2073
|
-
if (this._value.replayRing.length > this._slot.replayN) this._value.replayRing.shift();
|
|
2074
|
-
}
|
|
2075
|
-
this._emitToSubs(["DATA", v], delivery);
|
|
2076
|
-
continue;
|
|
2077
|
-
}
|
|
2078
|
-
if (m[0] === "RESOLVED") {
|
|
2079
|
-
this._value.status = this._value.hasData ? "resolved" : "sentinel";
|
|
2080
|
-
this._emitToSubs(["RESOLVED"], delivery);
|
|
2081
|
-
continue;
|
|
2082
|
-
}
|
|
2083
|
-
if (m[0] === "INVALIDATE") {
|
|
2084
|
-
this._invalidate(delivery);
|
|
2085
|
-
continue;
|
|
2086
|
-
}
|
|
2087
|
-
if (m[0] === "COMPLETE") {
|
|
2088
|
-
if (this._value.terminal !== void 0) continue;
|
|
2089
|
-
this._value.terminal = true;
|
|
2090
|
-
this._control.pauseBuffer = [];
|
|
2091
|
-
this._value.status = "completed";
|
|
2092
|
-
this._emitToSubs(["COMPLETE"], delivery);
|
|
2093
|
-
continue;
|
|
2094
|
-
}
|
|
2095
|
-
if (m[0] === "ERROR") {
|
|
2096
|
-
if (this._value.terminal !== void 0) continue;
|
|
2097
|
-
this._value.terminal = m[1];
|
|
2098
|
-
this._control.pauseBuffer = [];
|
|
2099
|
-
this._value.status = "errored";
|
|
2100
|
-
this._emitToSubs(["ERROR", m[1]], delivery);
|
|
2101
|
-
continue;
|
|
2102
|
-
}
|
|
2103
|
-
if (m[0] === "TEARDOWN") {
|
|
2104
|
-
this._value.hasTorndown = true;
|
|
2105
|
-
if (this._slot.resetOnTeardown) {
|
|
2106
|
-
this._value.cache = SENTINEL;
|
|
2107
|
-
this._value.hasData = false;
|
|
2108
|
-
}
|
|
2109
|
-
this._emitToSubs(["TEARDOWN"], delivery);
|
|
2110
|
-
}
|
|
2111
|
-
}
|
|
2112
|
-
if (!this._wave.insideRunWave) this._wave.emittedDirtyThisWave = false;
|
|
2467
|
+
nodeDown(nodeRuntimeHost(this), msgs);
|
|
2113
2468
|
}
|
|
2114
2469
|
_up(msgs, towardDep, route) {
|
|
2115
|
-
|
|
2116
|
-
const routeState = route ?? { demandFired: /* @__PURE__ */ new Map() };
|
|
2117
|
-
for (const m of msgs) {
|
|
2118
|
-
if (!isUpAllowed(m[0])) {
|
|
2119
|
-
throw new Error(
|
|
2120
|
-
`ctx.up: ${m[0]} is down-only (tier ${messageTier(m[0])}); up carries control tiers only (R-ctx-up)`
|
|
2121
|
-
);
|
|
2122
|
-
}
|
|
2123
|
-
}
|
|
2124
|
-
for (const m of msgs) {
|
|
2125
|
-
if (m[0] === "PAUSE") {
|
|
2126
|
-
this._pauseAcquire(m[1]);
|
|
2127
|
-
} else if (m[0] === "RESUME") {
|
|
2128
|
-
if (this._control.pauseLockset.has(m[1])) {
|
|
2129
|
-
this._pauseRelease(m[1]);
|
|
2130
|
-
} else {
|
|
2131
|
-
this._forwardUp(m, towardDep, routeState);
|
|
2132
|
-
}
|
|
2133
|
-
} else if (m[0] === "PULL") {
|
|
2134
|
-
const demand = normalizePullDemand(m[1]);
|
|
2135
|
-
if (this._slot.pull && demand.pullId === this._slot.pullLock) {
|
|
2136
|
-
if (!this._markDemandRouted(demand.pullId, routeState)) this._onDemand(demand);
|
|
2137
|
-
} else {
|
|
2138
|
-
this._forwardUp(["PULL", demand], towardDep, routeState);
|
|
2139
|
-
}
|
|
2140
|
-
} else if (this._slot.deps.length === 0) {
|
|
2141
|
-
if (m[0] === "INVALIDATE") this._down([["INVALIDATE"]]);
|
|
2142
|
-
} else {
|
|
2143
|
-
this._forwardUp(m, towardDep, routeState);
|
|
2144
|
-
}
|
|
2145
|
-
}
|
|
2470
|
+
nodeUp(nodeRuntimeHost(this), msgs, towardDep, route);
|
|
2146
2471
|
}
|
|
2147
2472
|
_markDemandRouted(lockId, route) {
|
|
2148
|
-
|
|
2149
|
-
if (holders === void 0) {
|
|
2150
|
-
holders = /* @__PURE__ */ new Set();
|
|
2151
|
-
route.demandFired.set(lockId, holders);
|
|
2152
|
-
}
|
|
2153
|
-
if (holders.has(this)) return true;
|
|
2154
|
-
holders.add(this);
|
|
2155
|
-
return false;
|
|
2473
|
+
return nodeMarkDemandRouted(nodeRuntimeHost(this), lockId, route);
|
|
2156
2474
|
}
|
|
2157
|
-
/**
|
|
2158
|
-
* Forward one up-going control message toward deps (R-up-routing): up the single declared edge
|
|
2159
|
-
* `towardDep` (directed — prunes other branches; only meaningful on the issuer's FIRST hop) or
|
|
2160
|
-
* broadcast up ALL deps. A depless source has no deps → the message DROPS here (the terminus —
|
|
2161
|
-
* e.g. a cone-routed PULL whose pullId no node up this cone holds, R-up-at-source). Recursive
|
|
2162
|
-
* forwarding carries the same per-wave route state and no `towardDep` → broadcast beyond the
|
|
2163
|
-
* first hop.
|
|
2164
|
-
*/
|
|
2165
2475
|
_forwardUp(m, towardDep, route) {
|
|
2166
|
-
|
|
2167
|
-
if (towardDep !== void 0) {
|
|
2168
|
-
const d = this._slot.deps[towardDep];
|
|
2169
|
-
if (d !== void 0) d._up([m], void 0, route);
|
|
2170
|
-
} else {
|
|
2171
|
-
for (const dep of this._slot.deps) dep._up([m], void 0, route);
|
|
2172
|
-
}
|
|
2476
|
+
nodeForwardUp(nodeRuntimeHost(this), m, towardDep, route);
|
|
2173
2477
|
}
|
|
2174
|
-
// ── PAUSE/RESUME lockset (R-pause-lockset) + modes (R-pause-modes) ──
|
|
2175
2478
|
_isPaused() {
|
|
2176
|
-
return this
|
|
2479
|
+
return nodeIsPaused(nodeRuntimeHost(this));
|
|
2177
2480
|
}
|
|
2178
2481
|
_hasBoundaryPauseLock() {
|
|
2179
|
-
|
|
2180
|
-
return this._control.pauseLockset.size > 0;
|
|
2482
|
+
return nodeHasBoundaryPauseLock(nodeRuntimeHost(this));
|
|
2181
2483
|
}
|
|
2182
2484
|
_isAsyncPool() {
|
|
2183
|
-
return
|
|
2485
|
+
return nodeIsAsyncPool(nodeRuntimeHost(this));
|
|
2184
2486
|
}
|
|
2185
2487
|
_pauseAcquire(lockId) {
|
|
2186
|
-
this
|
|
2488
|
+
nodePauseAcquire(nodeRuntimeHost(this), lockId);
|
|
2187
2489
|
}
|
|
2188
2490
|
_pauseRelease(lockId) {
|
|
2189
|
-
|
|
2190
|
-
this._control.pauseLockset.delete(lockId);
|
|
2191
|
-
if (this._slot.pull && this._control.demandOwed !== void 0) this._fireOwedDemandIfReady();
|
|
2192
|
-
if (this._hasBoundaryPauseLock()) return;
|
|
2193
|
-
scheduleBoundaryDrain(this._core);
|
|
2194
|
-
if (this._slot.pull) return;
|
|
2195
|
-
this._onResume();
|
|
2491
|
+
nodePauseRelease(nodeRuntimeHost(this), lockId);
|
|
2196
2492
|
}
|
|
2197
2493
|
_onResume() {
|
|
2198
|
-
|
|
2199
|
-
this._control.pauseBuffer = [];
|
|
2200
|
-
this._control.pausedDepWaveOccurred = false;
|
|
2201
|
-
this._control.demandOwed = void 0;
|
|
2202
|
-
this._control.activePull = void 0;
|
|
2203
|
-
this._control.pullDirtyOwed = false;
|
|
2204
|
-
return;
|
|
2205
|
-
}
|
|
2206
|
-
if (this._control.pauseBuffer.length > 0) {
|
|
2207
|
-
const buf = this._control.pauseBuffer;
|
|
2208
|
-
this._control.pauseBuffer = [];
|
|
2209
|
-
for (const wave of buf) this._down(wave);
|
|
2210
|
-
}
|
|
2211
|
-
if (this._control.pausedDepWaveOccurred) {
|
|
2212
|
-
this._control.pausedDepWaveOccurred = false;
|
|
2213
|
-
this._tryRun();
|
|
2214
|
-
}
|
|
2494
|
+
nodeOnResume(nodeRuntimeHost(this));
|
|
2215
2495
|
}
|
|
2216
|
-
/**
|
|
2217
|
-
* R-pull (D269): can this pull node fire a demand NOW? — not terminal, settle-ready (_pending===0),
|
|
2218
|
-
* and no OTHER (non-pullId) lock holds it paused. The gate that decides fire-now vs OWE.
|
|
2219
|
-
*/
|
|
2220
2496
|
_canFireDemand() {
|
|
2221
|
-
|
|
2222
|
-
return this._control.pauseLockset.size === 0;
|
|
2497
|
+
return nodeCanFireDemand(nodeRuntimeHost(this));
|
|
2223
2498
|
}
|
|
2224
|
-
/**
|
|
2225
|
-
* R-pull (D269/D272): deliver ONE demand pulse — install activePull so the demand wave may
|
|
2226
|
-
* emit, fire it, then clear activePull so the node is quiet again (1:1).
|
|
2227
|
-
*/
|
|
2228
2499
|
_deliverPullDemand(demand) {
|
|
2229
|
-
this
|
|
2230
|
-
this._control.activePull = demand;
|
|
2231
|
-
this._control.inDeliverDemand = true;
|
|
2232
|
-
try {
|
|
2233
|
-
this._firePullDemand();
|
|
2234
|
-
} finally {
|
|
2235
|
-
this._control.activePull = void 0;
|
|
2236
|
-
this._control.inDeliverDemand = false;
|
|
2237
|
-
}
|
|
2500
|
+
nodeDeliverPullDemand(nodeRuntimeHost(this), demand);
|
|
2238
2501
|
}
|
|
2239
|
-
/**
|
|
2240
|
-
* R-pull (D269): a cone-routed PULL of THIS node's pullId arrived (R-up-routing) = a DEMAND.
|
|
2241
|
-
* Fire immediately if able; else OWE it — pin-5 (a dep DIRTY in flight, _pending>0) or F4/F5 (an
|
|
2242
|
-
* external PAUSE lock co-holds the node) — and fire when the node next becomes able. A demand
|
|
2243
|
-
* arriving WHILE a delivery is in flight (synchronous re-entry) is DROPPED (1:1, QA guard).
|
|
2244
|
-
*/
|
|
2245
2502
|
_onDemand(demand) {
|
|
2246
|
-
|
|
2247
|
-
if (this._canFireDemand()) this._deliverPullDemand(demand);
|
|
2248
|
-
else this._control.demandOwed = demand;
|
|
2503
|
+
nodeOnDemand(nodeRuntimeHost(this), demand);
|
|
2249
2504
|
}
|
|
2250
|
-
/**
|
|
2251
|
-
* R-pull (D55): service ONE demand. Delivery content = the orthogonal pausable mode:
|
|
2252
|
-
* - 'resumeAll' → drain the buffered BACKLOG (each `_down` re-synthesizes a leading DIRTY, so
|
|
2253
|
-
* the per-entry replay is DIRTY-before-DATA — R-pause-modes per-entry arrival order);
|
|
2254
|
-
* - true → deliver the coalesced LATEST as ONE DIRTY-before-DATA wave (pin 2: the quiet absorb
|
|
2255
|
-
* suppressed the dep's original DIRTY, so the demand wave restores it before the value).
|
|
2256
|
-
* Neither branch fires when nothing changed since the last demand → the demand is SILENT.
|
|
2257
|
-
* Called by `_deliverPullDemand` only when settle-ready; the caller has released the pullId, so
|
|
2258
|
-
* `_markDirty` relays the leading DIRTY (not absorbed).
|
|
2259
|
-
*/
|
|
2260
2505
|
_firePullDemand() {
|
|
2261
|
-
|
|
2262
|
-
if (this._control.pauseBuffer.length > 0) {
|
|
2263
|
-
const buf = this._control.pauseBuffer;
|
|
2264
|
-
this._control.pauseBuffer = [];
|
|
2265
|
-
for (const wave of buf) this._down(wave);
|
|
2266
|
-
drainedBuffer = true;
|
|
2267
|
-
}
|
|
2268
|
-
if (drainedBuffer) return;
|
|
2269
|
-
if (this._control.pausedDepWaveOccurred) {
|
|
2270
|
-
const gated = this._slot.handle !== null && !this._wave.hasCalledFnOnce && !(this._slot.partial || this._allDepsSettled());
|
|
2271
|
-
if (this._wave.pending > 0 || gated) return;
|
|
2272
|
-
this._control.pausedDepWaveOccurred = false;
|
|
2273
|
-
this._wave.emittedDirtyThisWave = false;
|
|
2274
|
-
this._control.pullDirtyOwed = true;
|
|
2275
|
-
try {
|
|
2276
|
-
this._tryRun();
|
|
2277
|
-
} finally {
|
|
2278
|
-
this._control.pullDirtyOwed = false;
|
|
2279
|
-
}
|
|
2280
|
-
return;
|
|
2281
|
-
}
|
|
2282
|
-
if (this._slot.handle !== null) {
|
|
2283
|
-
if (!this._wave.hasCalledFnOnce && !(this._slot.partial || this._allDepsSettled())) return;
|
|
2284
|
-
this._wave.emittedDirtyThisWave = false;
|
|
2285
|
-
this._control.pullDirtyOwed = true;
|
|
2286
|
-
try {
|
|
2287
|
-
this._runWave();
|
|
2288
|
-
} finally {
|
|
2289
|
-
this._control.pullDirtyOwed = false;
|
|
2290
|
-
}
|
|
2291
|
-
}
|
|
2506
|
+
nodeFirePullDemand(nodeRuntimeHost(this));
|
|
2292
2507
|
}
|
|
2293
|
-
/**
|
|
2294
|
-
* R-pull (D269): fire a demand that was OWED (deferred at demand time) once the node becomes
|
|
2295
|
-
* able — called from the dep-settle arms (DATA/RESOLVED/INVALIDATE/terminal drain _pending, pin-5
|
|
2296
|
-
* + B1/F6) and from `_pauseRelease` (an external PAUSE lock releases, F4/F5).
|
|
2297
|
-
*/
|
|
2298
2508
|
_fireOwedDemandIfReady() {
|
|
2299
|
-
|
|
2300
|
-
if (this._slot.pull && this._control.demandOwed !== void 0 && this._canFireDemand()) {
|
|
2301
|
-
this._deliverPullDemand(this._control.demandOwed);
|
|
2302
|
-
}
|
|
2509
|
+
nodeFireOwedDemandIfReady(nodeRuntimeHost(this));
|
|
2303
2510
|
}
|
|
2304
|
-
/** Should an outgoing settle slice be deferred into the pause buffer? */
|
|
2305
2511
|
_shouldBufferOnPause() {
|
|
2306
|
-
|
|
2307
|
-
if (!this._isPaused() && !this._isPullQuiet()) return false;
|
|
2308
|
-
if (this._slot.pausable === "resumeAll") return true;
|
|
2309
|
-
if (!this._wave.insideRunWave && this._isAsyncPool() && this._slot.deps.length > 0) return true;
|
|
2310
|
-
return false;
|
|
2512
|
+
return nodeShouldBufferOnPause(nodeRuntimeHost(this));
|
|
2311
2513
|
}
|
|
2312
|
-
/** R-invalidate-idempotent: clear cache + flush + cascade; no-op if nothing cached. */
|
|
2313
2514
|
_invalidate(delivery) {
|
|
2314
|
-
|
|
2315
|
-
|
|
2316
|
-
this._value.hasData = false;
|
|
2317
|
-
this._value.status = "sentinel";
|
|
2318
|
-
this._value.replayRing = [];
|
|
2319
|
-
for (const fn of this._hooks.onInvalidate) fn();
|
|
2320
|
-
this._emitToSubs(["INVALIDATE"], delivery);
|
|
2321
|
-
}
|
|
2322
|
-
// B42 (R-deps-terminal): ALL deps TERMINAL = every dep has reached COMPLETE *or* an ABSORBED
|
|
2323
|
-
// ERROR. Block only on a LIVE dep (_depTerminal[i] === undefined); an errored dep (terminal = the
|
|
2324
|
-
// error payload, which R-data-payload guarantees is !== undefined and non-boolean) COUNTS as
|
|
2325
|
-
// terminal-done. Was
|
|
2326
|
-
// `tm !== true`, which wedged a node whose errorWhenDepsError:false dep ERRORed (it never
|
|
2327
|
-
// auto-completed even after every other dep completed). Drives the completeWhenDepsComplete cascade.
|
|
2515
|
+
nodeInvalidate(nodeRuntimeHost(this), delivery);
|
|
2516
|
+
}
|
|
2328
2517
|
_allDepsTerminal() {
|
|
2329
|
-
|
|
2330
|
-
|
|
2331
|
-
|
|
2518
|
+
return nodeAllDepsTerminal(nodeRuntimeHost(this));
|
|
2519
|
+
}
|
|
2520
|
+
_emitToSubs(msg, delivery) {
|
|
2521
|
+
nodeEmitToSubs(nodeRuntimeHost(this), msg, delivery);
|
|
2332
2522
|
}
|
|
2333
2523
|
/** R-terminal: resubscribable reset clears terminal + dep state + re-arms the gate. */
|
|
2334
2524
|
_resetLifecycle() {
|
|
2335
|
-
|
|
2336
|
-
this._dep.unsubs = [];
|
|
2337
|
-
this._dep.idxBoxes = [];
|
|
2338
|
-
this._lifecycle.subscribers.clear();
|
|
2339
|
-
this._lifecycle.activated = false;
|
|
2340
|
-
this._value.terminal = void 0;
|
|
2341
|
-
this._value.hasTorndown = false;
|
|
2342
|
-
this._wave.hasCalledFnOnce = false;
|
|
2343
|
-
this._resetDepState();
|
|
2344
|
-
this._control.pauseLockset.clear();
|
|
2345
|
-
this._control.pauseBuffer = [];
|
|
2346
|
-
this._control.pausedDepWaveOccurred = false;
|
|
2347
|
-
this._control.demandOwed = void 0;
|
|
2348
|
-
this._control.activePull = void 0;
|
|
2349
|
-
this._control.pullDirtyOwed = false;
|
|
2350
|
-
this._value.replayRing = [];
|
|
2351
|
-
const isCompute = this._slot.handle !== null || this._slot.deps.length > 0;
|
|
2352
|
-
if (isCompute) {
|
|
2353
|
-
this._value.cache = SENTINEL;
|
|
2354
|
-
this._value.hasData = false;
|
|
2355
|
-
this._value.status = "sentinel";
|
|
2356
|
-
} else {
|
|
2357
|
-
this._value.status = this._value.hasData ? "settled" : "sentinel";
|
|
2358
|
-
}
|
|
2359
|
-
if (!this._privateState.persist) this._privateState.value = SENTINEL;
|
|
2360
|
-
}
|
|
2361
|
-
_emitToSubs(msg, delivery) {
|
|
2362
|
-
if (this._released) return;
|
|
2363
|
-
const subs = [...this._lifecycle.subscribers];
|
|
2364
|
-
for (const sink of subs) sink(msg, delivery);
|
|
2525
|
+
nodeResetLifecycle(nodeRuntimeHost(this));
|
|
2365
2526
|
}
|
|
2366
2527
|
/** Batch commit (R-batch-coalesce): deliver the deferred tier-3 wave now. */
|
|
2367
2528
|
__commitBatchedWave(wave) {
|
|
2368
|
-
this
|
|
2369
|
-
this._down(wave);
|
|
2529
|
+
nodeCommitBatchedWave(nodeRuntimeHost(this), wave);
|
|
2370
2530
|
}
|
|
2371
2531
|
/** Batch rollback: balance the immediate DIRTY with a RESOLVED so downstream un-dirties. */
|
|
2372
2532
|
__rollbackBatched() {
|
|
2373
|
-
|
|
2374
|
-
this._wave.batchDirtyOwed = false;
|
|
2375
|
-
this._wave.emittedDirtyThisWave = false;
|
|
2376
|
-
this._value.status = this._value.hasData ? "settled" : "sentinel";
|
|
2377
|
-
this._emitToSubs(["RESOLVED"]);
|
|
2378
|
-
}
|
|
2533
|
+
nodeRollbackBatched(nodeRuntimeHost(this));
|
|
2379
2534
|
}
|
|
2380
2535
|
/** B49: enqueue a committed-boundary task on this node's graph-local core. */
|
|
2381
2536
|
__deferBoundary(fn, batchToken) {
|
|
2382
|
-
|
|
2383
|
-
batchToken,
|
|
2384
|
-
isReady: () => !this._hasBoundaryPauseLock()
|
|
2385
|
-
});
|
|
2537
|
+
nodeDeferBoundary(nodeRuntimeHost(this), fn, batchToken);
|
|
2386
2538
|
}
|
|
2387
2539
|
};
|
|
2388
2540
|
|
|
@@ -2581,18 +2733,90 @@ function parseCron(expr) {
|
|
|
2581
2733
|
daysOfWeek: parseCronField(parts[4], 0, 6)
|
|
2582
2734
|
};
|
|
2583
2735
|
}
|
|
2584
|
-
function matchesCron(schedule, date) {
|
|
2585
|
-
|
|
2736
|
+
function matchesCron(schedule, date, opts = {}) {
|
|
2737
|
+
const fields = cronWallClockFields(date, opts.timezone);
|
|
2738
|
+
return schedule.minutes.has(fields.minute) && schedule.hours.has(fields.hour) && schedule.daysOfMonth.has(fields.day) && schedule.months.has(fields.month) && schedule.daysOfWeek.has(fields.dayOfWeek);
|
|
2739
|
+
}
|
|
2740
|
+
function cronMinuteKey(date, timezone) {
|
|
2741
|
+
const fields = cronWallClockFields(date, timezone);
|
|
2742
|
+
return `${fields.year}-${fields.month}-${fields.day}-${fields.hour}-${fields.minute}`;
|
|
2743
|
+
}
|
|
2744
|
+
function cronDayKey(date, timezone) {
|
|
2745
|
+
const fields = cronWallClockFields(date, timezone);
|
|
2746
|
+
return `${fields.year}-${fields.month}-${fields.day}`;
|
|
2747
|
+
}
|
|
2748
|
+
function cronWallClockFields(date, timezone) {
|
|
2749
|
+
if (timezone === void 0) {
|
|
2750
|
+
return {
|
|
2751
|
+
year: date.getFullYear(),
|
|
2752
|
+
month: date.getMonth() + 1,
|
|
2753
|
+
day: date.getDate(),
|
|
2754
|
+
hour: date.getHours(),
|
|
2755
|
+
minute: date.getMinutes(),
|
|
2756
|
+
dayOfWeek: date.getDay()
|
|
2757
|
+
};
|
|
2758
|
+
}
|
|
2759
|
+
const parts = timezoneFormatter(timezone).formatToParts(date);
|
|
2760
|
+
const values = {};
|
|
2761
|
+
for (const part of parts) {
|
|
2762
|
+
if (part.type === "year" || part.type === "month" || part.type === "day" || part.type === "hour" || part.type === "minute") {
|
|
2763
|
+
values[part.type] = Number.parseInt(part.value, 10);
|
|
2764
|
+
}
|
|
2765
|
+
}
|
|
2766
|
+
const year = values.year;
|
|
2767
|
+
const month = values.month;
|
|
2768
|
+
const day = values.day;
|
|
2769
|
+
const hour = values.hour;
|
|
2770
|
+
const minute = values.minute;
|
|
2771
|
+
if (year === void 0 || month === void 0 || day === void 0 || hour === void 0 || minute === void 0) {
|
|
2772
|
+
throw new Error(`fromCron: timezone projection failed for ${timezone}`);
|
|
2773
|
+
}
|
|
2774
|
+
return {
|
|
2775
|
+
year,
|
|
2776
|
+
month,
|
|
2777
|
+
day,
|
|
2778
|
+
hour,
|
|
2779
|
+
minute,
|
|
2780
|
+
dayOfWeek: new Date(Date.UTC(year, month - 1, day)).getUTCDay()
|
|
2781
|
+
};
|
|
2586
2782
|
}
|
|
2587
|
-
|
|
2588
|
-
|
|
2783
|
+
var TIMEZONE_FORMATTERS = /* @__PURE__ */ new Map();
|
|
2784
|
+
function timezoneFormatter(timezone) {
|
|
2785
|
+
const existing = TIMEZONE_FORMATTERS.get(timezone);
|
|
2786
|
+
if (existing !== void 0) return existing;
|
|
2787
|
+
assertNonEmptyString(timezone, "fromCron: timezone");
|
|
2788
|
+
try {
|
|
2789
|
+
const formatter = new Intl.DateTimeFormat("en-US-u-ca-gregory-nu-latn", {
|
|
2790
|
+
timeZone: timezone,
|
|
2791
|
+
year: "numeric",
|
|
2792
|
+
month: "2-digit",
|
|
2793
|
+
day: "2-digit",
|
|
2794
|
+
hour: "2-digit",
|
|
2795
|
+
minute: "2-digit",
|
|
2796
|
+
hourCycle: "h23"
|
|
2797
|
+
});
|
|
2798
|
+
formatter.format(/* @__PURE__ */ new Date(0));
|
|
2799
|
+
TIMEZONE_FORMATTERS.set(timezone, formatter);
|
|
2800
|
+
return formatter;
|
|
2801
|
+
} catch (error) {
|
|
2802
|
+
throw new RangeError(
|
|
2803
|
+
`fromCron: unsupported IANA timezone '${timezone}' (${error instanceof Error ? error.message : String(error)})`
|
|
2804
|
+
);
|
|
2805
|
+
}
|
|
2589
2806
|
}
|
|
2590
2807
|
function dateToTimestampNs(date) {
|
|
2591
2808
|
return (BigInt(date.getTime()) * 1000000n).toString();
|
|
2592
2809
|
}
|
|
2593
2810
|
function fromCron(expr, opts = {}) {
|
|
2594
2811
|
const schedule = parseCron(expr);
|
|
2595
|
-
const { tickMs = 6e4, output = "timestamp_ns", signal } = opts;
|
|
2812
|
+
const { tickMs = 6e4, output = "timestamp_ns", signal, timezone } = opts;
|
|
2813
|
+
if (opts.dst?.nonexistent !== void 0 && opts.dst.nonexistent !== "skip") {
|
|
2814
|
+
throw new RangeError("fromCron: dst.nonexistent currently supports only 'skip'");
|
|
2815
|
+
}
|
|
2816
|
+
if (opts.dst?.repeated !== void 0 && opts.dst.repeated !== "once") {
|
|
2817
|
+
throw new RangeError("fromCron: dst.repeated currently supports only 'once'");
|
|
2818
|
+
}
|
|
2819
|
+
if (timezone !== void 0) timezoneFormatter(timezone);
|
|
2596
2820
|
if (!Number.isFinite(tickMs) || tickMs <= 0) {
|
|
2597
2821
|
throw new RangeError("fromCron: tickMs must be a positive finite number");
|
|
2598
2822
|
}
|
|
@@ -2601,6 +2825,8 @@ function fromCron(expr, opts = {}) {
|
|
|
2601
2825
|
(ctx) => {
|
|
2602
2826
|
let done = false;
|
|
2603
2827
|
let lastFiredKey;
|
|
2828
|
+
let firedTimezoneDay;
|
|
2829
|
+
const firedTimezoneMinutes = /* @__PURE__ */ new Set();
|
|
2604
2830
|
let intervalId;
|
|
2605
2831
|
const cleanup = () => {
|
|
2606
2832
|
done = true;
|
|
@@ -2621,9 +2847,18 @@ function fromCron(expr, opts = {}) {
|
|
|
2621
2847
|
const check = () => {
|
|
2622
2848
|
if (done) return;
|
|
2623
2849
|
const now = /* @__PURE__ */ new Date();
|
|
2624
|
-
const key = cronMinuteKey(now);
|
|
2625
|
-
|
|
2850
|
+
const key = cronMinuteKey(now, timezone);
|
|
2851
|
+
const alreadyFired = timezone === void 0 ? key === lastFiredKey : firedTimezoneMinutes.has(key);
|
|
2852
|
+
if (!alreadyFired && matchesCron(schedule, now, { timezone })) {
|
|
2626
2853
|
lastFiredKey = key;
|
|
2854
|
+
if (timezone !== void 0) {
|
|
2855
|
+
const dayKey = cronDayKey(now, timezone);
|
|
2856
|
+
if (dayKey !== firedTimezoneDay) {
|
|
2857
|
+
firedTimezoneDay = dayKey;
|
|
2858
|
+
firedTimezoneMinutes.clear();
|
|
2859
|
+
}
|
|
2860
|
+
firedTimezoneMinutes.add(key);
|
|
2861
|
+
}
|
|
2627
2862
|
emitNow(now);
|
|
2628
2863
|
}
|
|
2629
2864
|
};
|