@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
|
@@ -155,30 +155,6 @@ function drain() {
|
|
|
155
155
|
if (escaped !== null) throw escaped.e;
|
|
156
156
|
}
|
|
157
157
|
|
|
158
|
-
// src/batch/batch.ts
|
|
159
|
-
var active = null;
|
|
160
|
-
var boundaryOwner = null;
|
|
161
|
-
function currentBatch() {
|
|
162
|
-
return active !== null;
|
|
163
|
-
}
|
|
164
|
-
function currentBoundaryBatchToken() {
|
|
165
|
-
return active ?? boundaryOwner ?? void 0;
|
|
166
|
-
}
|
|
167
|
-
function deferToBatch(target, tier3Wave) {
|
|
168
|
-
if (active === null) return false;
|
|
169
|
-
if (!active.deferred.has(target)) active.order.push(target);
|
|
170
|
-
active.deferred.set(target, tier3Wave);
|
|
171
|
-
return true;
|
|
172
|
-
}
|
|
173
|
-
function deferAfterBatchForTarget(target, fn) {
|
|
174
|
-
if (active === null || !active.deferred.has(target)) return false;
|
|
175
|
-
const owner = active;
|
|
176
|
-
target.__deferBoundary(() => {
|
|
177
|
-
if (owner.committed) fn();
|
|
178
|
-
}, owner);
|
|
179
|
-
return true;
|
|
180
|
-
}
|
|
181
|
-
|
|
182
158
|
// src/dispatcher/index.ts
|
|
183
159
|
var PoolTable = class {
|
|
184
160
|
constructor(kind) {
|
|
@@ -485,6 +461,589 @@ function makeDepBookkeeping(depCount2) {
|
|
|
485
461
|
};
|
|
486
462
|
}
|
|
487
463
|
|
|
464
|
+
// src/node/protocol-guards.ts
|
|
465
|
+
function terminalView(t) {
|
|
466
|
+
return t === void 0 ? false : t;
|
|
467
|
+
}
|
|
468
|
+
function normalizePullDemand(demand) {
|
|
469
|
+
if (typeof demand !== "object" || demand === null || Array.isArray(demand)) {
|
|
470
|
+
throw new Error("ctx.up: PULL requires { pullId, params? } demand payload (D269)");
|
|
471
|
+
}
|
|
472
|
+
const pullId = demand.pullId;
|
|
473
|
+
if (typeof pullId !== "string" && typeof pullId !== "symbol") {
|
|
474
|
+
throw new Error("ctx.up: PULL demand requires a string or symbol pullId (D269)");
|
|
475
|
+
}
|
|
476
|
+
const params = demand.params;
|
|
477
|
+
return params === void 0 ? { pullId } : { pullId, params };
|
|
478
|
+
}
|
|
479
|
+
function validateDownPayloads(msgs) {
|
|
480
|
+
for (const m of msgs) {
|
|
481
|
+
if (m[0] === "DATA" && m[1] === void 0) {
|
|
482
|
+
throw new Error("down: DATA requires a non-SENTINEL payload (R-data-payload)");
|
|
483
|
+
}
|
|
484
|
+
if (m[0] === "ERROR" && isInvalidErrorPayload(m[1])) {
|
|
485
|
+
throw new Error("down: ERROR requires a non-SENTINEL, non-boolean payload (R-data-payload)");
|
|
486
|
+
}
|
|
487
|
+
}
|
|
488
|
+
}
|
|
489
|
+
|
|
490
|
+
// src/node/runtime-accessors.ts
|
|
491
|
+
var constructingCore;
|
|
492
|
+
var constructingEnvironment;
|
|
493
|
+
var ownerTokens = /* @__PURE__ */ new WeakMap();
|
|
494
|
+
var topologyDepsChangedObservers = /* @__PURE__ */ new WeakMap();
|
|
495
|
+
var checkpointReaders = /* @__PURE__ */ new WeakMap();
|
|
496
|
+
var restoreWriters = /* @__PURE__ */ new WeakMap();
|
|
497
|
+
var runtimeReleasers = /* @__PURE__ */ new WeakMap();
|
|
498
|
+
var runtimeQuiescenceReaders = /* @__PURE__ */ new WeakMap();
|
|
499
|
+
var subscriberCountReaders = /* @__PURE__ */ new WeakMap();
|
|
500
|
+
var activationReaders = /* @__PURE__ */ new WeakMap();
|
|
501
|
+
var releasedNodes = /* @__PURE__ */ new WeakSet();
|
|
502
|
+
function withNodeCore(core, create) {
|
|
503
|
+
const prev = constructingCore;
|
|
504
|
+
constructingCore = core;
|
|
505
|
+
try {
|
|
506
|
+
return create();
|
|
507
|
+
} finally {
|
|
508
|
+
constructingCore = prev;
|
|
509
|
+
}
|
|
510
|
+
}
|
|
511
|
+
function takeConstructingNodeCore() {
|
|
512
|
+
const core = constructingCore;
|
|
513
|
+
constructingCore = void 0;
|
|
514
|
+
return core;
|
|
515
|
+
}
|
|
516
|
+
function withEnvironmentDrivers(environment, create) {
|
|
517
|
+
const prev = constructingEnvironment;
|
|
518
|
+
constructingEnvironment = environment;
|
|
519
|
+
try {
|
|
520
|
+
return create();
|
|
521
|
+
} finally {
|
|
522
|
+
constructingEnvironment = prev;
|
|
523
|
+
}
|
|
524
|
+
}
|
|
525
|
+
function takeConstructingEnvironmentDrivers() {
|
|
526
|
+
const environment = constructingEnvironment;
|
|
527
|
+
constructingEnvironment = void 0;
|
|
528
|
+
return environment;
|
|
529
|
+
}
|
|
530
|
+
function getNodeOwner(n) {
|
|
531
|
+
return ownerTokens.get(n);
|
|
532
|
+
}
|
|
533
|
+
function notifyTopologyDepsChanged(node2, prevDeps, deps) {
|
|
534
|
+
topologyDepsChangedObservers.get(node2)?.(node2, prevDeps, deps);
|
|
535
|
+
}
|
|
536
|
+
function releaseRuntimeOfNode(n) {
|
|
537
|
+
runtimeReleasers.get(n)?.();
|
|
538
|
+
}
|
|
539
|
+
|
|
540
|
+
// src/node/node-context-runtime.ts
|
|
541
|
+
function nodeBuildCtx(self) {
|
|
542
|
+
const kind = self._slot.handle ? self._slot.dispatcher.poolKind(self._slot.handle.poolId) : "sync";
|
|
543
|
+
if (kind === "sync") {
|
|
544
|
+
if (self._syncCtx === null) self._syncCtx = self._makeCtx();
|
|
545
|
+
self._refreshCtx(self._syncCtx);
|
|
546
|
+
return self._syncCtx;
|
|
547
|
+
}
|
|
548
|
+
return self._makeCtx({
|
|
549
|
+
waveData: self._dep.waveData.map((waves) => waves.map((w) => [...w])),
|
|
550
|
+
terminal: self._dep.terminalInput.map(terminalView),
|
|
551
|
+
latest: [...self._dep.prev]
|
|
552
|
+
});
|
|
553
|
+
}
|
|
554
|
+
function nodeMakeCtx(self, snapshot) {
|
|
555
|
+
const ctx = {
|
|
556
|
+
// Wave-owner boundary (D47): a SYNC fn's emit nests under the public entry that drove
|
|
557
|
+
// it (cheap inc/dec, no early drain); an ASYNC-pool fn re-enters here from its stashed
|
|
558
|
+
// ctx at depth 0, so this is the boundary that drains any rewireNext it issued.
|
|
559
|
+
up: (msgs, towardDep) => {
|
|
560
|
+
if (self._released) return;
|
|
561
|
+
enterWave();
|
|
562
|
+
try {
|
|
563
|
+
self._up(msgs, towardDep);
|
|
564
|
+
} finally {
|
|
565
|
+
exitWave();
|
|
566
|
+
}
|
|
567
|
+
},
|
|
568
|
+
down: (msgs) => {
|
|
569
|
+
if (self._released) return;
|
|
570
|
+
enterWave();
|
|
571
|
+
try {
|
|
572
|
+
self._down(msgs);
|
|
573
|
+
} finally {
|
|
574
|
+
exitWave();
|
|
575
|
+
}
|
|
576
|
+
},
|
|
577
|
+
waveData: snapshot?.waveData ?? self._dep.waveData,
|
|
578
|
+
terminal: snapshot?.terminal ?? self._dep.terminalInput.map(terminalView),
|
|
579
|
+
state: self._makeState(),
|
|
580
|
+
onDeactivation: (fn) => {
|
|
581
|
+
if (self._released) return;
|
|
582
|
+
self._hooks.onDeactivation.push(fn);
|
|
583
|
+
},
|
|
584
|
+
onInvalidate: (fn) => {
|
|
585
|
+
if (self._released) return;
|
|
586
|
+
self._hooks.onInvalidate.push(fn);
|
|
587
|
+
},
|
|
588
|
+
environment: () => self._slot.environment,
|
|
589
|
+
// R-rewire-deferred (D47): defer a self-dep-set mutation to the committed boundary.
|
|
590
|
+
rewireNext: {
|
|
591
|
+
subscribeDep: (dep, fn) => self._requestRewireNext({ kind: "add", dep, fn }),
|
|
592
|
+
unsubscribeDep: (dep, fn) => self._requestRewireNext({ kind: "remove", dep, fn }),
|
|
593
|
+
replaceDeps: (deps, fn) => self._requestRewireNext({ kind: "set", deps, fn })
|
|
594
|
+
},
|
|
595
|
+
// R-up-routing / R-pull (D269): deferred up — route a control/demand wave (e.g. PULL)
|
|
596
|
+
// up the declared cone at the committed boundary. The SELF-demand path: an
|
|
597
|
+
// immediate ctx.up whose delivery loops back re-enters this fn (D37 / R-reentrancy).
|
|
598
|
+
upNext: (msgs, towardDep) => self._requestUpNext(msgs, towardDep),
|
|
599
|
+
...self._control.activePull === void 0 ? {} : { pull: self._control.activePull },
|
|
600
|
+
[CTX_DEP_CACHE]: { latest: snapshot?.latest ?? self._dep.prev },
|
|
601
|
+
[CTX_NODE_BINDING]: {
|
|
602
|
+
dispatcher: self._slot.dispatcher,
|
|
603
|
+
create: (factory) => withEnvironmentDrivers(self._slot.environment, () => withNodeCore(self._core, factory))
|
|
604
|
+
}
|
|
605
|
+
};
|
|
606
|
+
if (self._slot.dynamic) {
|
|
607
|
+
ctx.track = (i) => ctx[CTX_DEP_CACHE]?.latest[i];
|
|
608
|
+
}
|
|
609
|
+
return ctx;
|
|
610
|
+
}
|
|
611
|
+
function nodeRefreshCtx(self, ctx) {
|
|
612
|
+
ctx.waveData = self._dep.waveData;
|
|
613
|
+
ctx.terminal = self._dep.terminalInput.map(terminalView);
|
|
614
|
+
if (self._control.activePull === void 0) {
|
|
615
|
+
delete ctx.pull;
|
|
616
|
+
} else {
|
|
617
|
+
ctx.pull = self._control.activePull;
|
|
618
|
+
}
|
|
619
|
+
ctx[CTX_DEP_CACHE] = { latest: self._dep.prev };
|
|
620
|
+
}
|
|
621
|
+
function nodeMakeState(self) {
|
|
622
|
+
return {
|
|
623
|
+
get: () => self._privateState.value,
|
|
624
|
+
set: (v) => {
|
|
625
|
+
self._privateState.value = v;
|
|
626
|
+
},
|
|
627
|
+
persist: (on = true) => {
|
|
628
|
+
self._privateState.persist = on;
|
|
629
|
+
}
|
|
630
|
+
};
|
|
631
|
+
}
|
|
632
|
+
|
|
633
|
+
// src/node/node-input-runtime.ts
|
|
634
|
+
function nodeRecordDepProjection(self, idx, delivery) {
|
|
635
|
+
const token = delivery?.wave ?? {};
|
|
636
|
+
if (self._dep.waveTokens[idx] !== token) {
|
|
637
|
+
self._dep.waveData[idx].push([]);
|
|
638
|
+
self._dep.waveTokens[idx] = token;
|
|
639
|
+
}
|
|
640
|
+
return self._dep.waveData[idx][self._dep.waveData[idx].length - 1];
|
|
641
|
+
}
|
|
642
|
+
function nodeDepProjectionHasData(self, idx) {
|
|
643
|
+
const projection = self._dep.waveData[idx][self._dep.waveData[idx].length - 1];
|
|
644
|
+
return projection?.some((v) => v !== SENTINEL) ?? false;
|
|
645
|
+
}
|
|
646
|
+
function nodeReceiveFromDep(self, idx, msg, delivery) {
|
|
647
|
+
if (self._released) return;
|
|
648
|
+
const t = msg[0];
|
|
649
|
+
if (t === "START") return;
|
|
650
|
+
const isLastInDeliveredWave = delivery?.last ?? true;
|
|
651
|
+
if (self._value.terminal !== void 0) {
|
|
652
|
+
if (t === "TEARDOWN") self._down([["TEARDOWN"]]);
|
|
653
|
+
return;
|
|
654
|
+
}
|
|
655
|
+
if (t === "INVALIDATE") {
|
|
656
|
+
const projection = self._recordDepProjection(idx, delivery);
|
|
657
|
+
projection.push(SENTINEL);
|
|
658
|
+
if (projection.some((v) => v !== SENTINEL) && isLastInDeliveredWave) self._maybeRun();
|
|
659
|
+
self._dep.prev[idx] = SENTINEL;
|
|
660
|
+
self._dep.hasData[idx] = false;
|
|
661
|
+
self._dep.batch[idx] = null;
|
|
662
|
+
if (self._dep.dirty[idx]) {
|
|
663
|
+
self._dep.dirty[idx] = false;
|
|
664
|
+
self._wave.pending--;
|
|
665
|
+
}
|
|
666
|
+
if (self._control.pausedDepWaveOccurred && self._dep.batch.every((b) => b === null)) {
|
|
667
|
+
self._control.pausedDepWaveOccurred = false;
|
|
668
|
+
}
|
|
669
|
+
const hadData = self._value.hasData;
|
|
670
|
+
self._invalidate();
|
|
671
|
+
if (self._wave.pending === 0 && self._wave.emittedDirtyThisWave) {
|
|
672
|
+
if (!hadData) self._down([["RESOLVED"]]);
|
|
673
|
+
else self._wave.emittedDirtyThisWave = false;
|
|
674
|
+
}
|
|
675
|
+
self._fireOwedDemandIfReady();
|
|
676
|
+
return;
|
|
677
|
+
}
|
|
678
|
+
if (isTerminal(t)) {
|
|
679
|
+
const isError = t === "ERROR";
|
|
680
|
+
const errPayload = isError ? msg[1] : void 0;
|
|
681
|
+
self._dep.terminal[idx] = isError ? errPayload : true;
|
|
682
|
+
self._dep.terminalInput[idx] = isError ? errPayload : true;
|
|
683
|
+
self._releaseDepDirty(idx);
|
|
684
|
+
const ranValueBeforeTerminal = self._depProjectionHasData(idx) && isLastInDeliveredWave;
|
|
685
|
+
if (ranValueBeforeTerminal) self._maybeRun();
|
|
686
|
+
if (isError && self._slot.errorWhenDepsError) {
|
|
687
|
+
self._down([["ERROR", errPayload]]);
|
|
688
|
+
} else if (self._slot.terminalAsRealInput) {
|
|
689
|
+
if (ranValueBeforeTerminal) {
|
|
690
|
+
self._fireOwedDemandIfReady();
|
|
691
|
+
return;
|
|
692
|
+
}
|
|
693
|
+
self._maybeRun();
|
|
694
|
+
} else if (self._slot.completeWhenDepsComplete && self._allDepsTerminal()) {
|
|
695
|
+
self._down([["COMPLETE"]]);
|
|
696
|
+
} else {
|
|
697
|
+
self._settleAfterAbsorbedTerminal();
|
|
698
|
+
}
|
|
699
|
+
self._fireOwedDemandIfReady();
|
|
700
|
+
return;
|
|
701
|
+
}
|
|
702
|
+
if (t === "TEARDOWN") {
|
|
703
|
+
self._down([["TEARDOWN"]]);
|
|
704
|
+
return;
|
|
705
|
+
}
|
|
706
|
+
if (t === "DIRTY") {
|
|
707
|
+
if (!self._dep.dirty[idx]) {
|
|
708
|
+
self._dep.dirty[idx] = true;
|
|
709
|
+
self._wave.pending++;
|
|
710
|
+
self._dep.tier[idx] = 2;
|
|
711
|
+
self._markDirty();
|
|
712
|
+
}
|
|
713
|
+
return;
|
|
714
|
+
}
|
|
715
|
+
if (t === "DATA") {
|
|
716
|
+
const v = msg[1];
|
|
717
|
+
self._recordDepProjection(idx, delivery).push(v);
|
|
718
|
+
const b = self._dep.batch[idx];
|
|
719
|
+
if (b === null) self._dep.batch[idx] = [v];
|
|
720
|
+
else b.push(v);
|
|
721
|
+
self._dep.prev[idx] = v;
|
|
722
|
+
self._dep.hasData[idx] = true;
|
|
723
|
+
self._dep.tier[idx] = 3;
|
|
724
|
+
if (self._dep.dirty[idx]) {
|
|
725
|
+
self._dep.dirty[idx] = false;
|
|
726
|
+
self._wave.pending--;
|
|
727
|
+
}
|
|
728
|
+
if (isLastInDeliveredWave) self._maybeRun();
|
|
729
|
+
self._fireOwedDemandIfReady();
|
|
730
|
+
return;
|
|
731
|
+
}
|
|
732
|
+
if (t === "RESOLVED") {
|
|
733
|
+
self._recordDepProjection(idx, delivery);
|
|
734
|
+
self._dep.tier[idx] = 3;
|
|
735
|
+
if (self._dep.dirty[idx]) {
|
|
736
|
+
self._dep.dirty[idx] = false;
|
|
737
|
+
self._wave.pending--;
|
|
738
|
+
}
|
|
739
|
+
if (isLastInDeliveredWave) self._maybeRun();
|
|
740
|
+
self._fireOwedDemandIfReady();
|
|
741
|
+
return;
|
|
742
|
+
}
|
|
743
|
+
}
|
|
744
|
+
function nodeReleaseDepDirty(self, idx) {
|
|
745
|
+
if (self._dep.dirty[idx]) {
|
|
746
|
+
self._dep.dirty[idx] = false;
|
|
747
|
+
self._wave.pending--;
|
|
748
|
+
}
|
|
749
|
+
}
|
|
750
|
+
function nodeSettleAfterAbsorbedTerminal(self) {
|
|
751
|
+
if (self._wave.pending !== 0 || !self._wave.emittedDirtyThisWave) return;
|
|
752
|
+
const sawData = self._dep.batch.some((b) => b !== null && b.length > 0);
|
|
753
|
+
if (sawData) self._maybeRun();
|
|
754
|
+
if (self._wave.emittedDirtyThisWave) self._down([["RESOLVED"]]);
|
|
755
|
+
}
|
|
756
|
+
function nodeMarkDirty(self) {
|
|
757
|
+
self._value.status = "dirty";
|
|
758
|
+
if (self._isPullQuiet()) return;
|
|
759
|
+
if (!self._wave.emittedDirtyThisWave) {
|
|
760
|
+
self._wave.emittedDirtyThisWave = true;
|
|
761
|
+
self._emitToSubs(["DIRTY"]);
|
|
762
|
+
}
|
|
763
|
+
}
|
|
764
|
+
function nodeMaybeRun(self) {
|
|
765
|
+
if (self._wave.inDepMutation) {
|
|
766
|
+
self._wave.rewireRunPending = true;
|
|
767
|
+
return;
|
|
768
|
+
}
|
|
769
|
+
if (self._slot.pausable === true && (self._isPaused() || self._isPullQuiet())) {
|
|
770
|
+
self._control.pausedDepWaveOccurred = true;
|
|
771
|
+
return;
|
|
772
|
+
}
|
|
773
|
+
self._tryRun();
|
|
774
|
+
}
|
|
775
|
+
function nodeSettleRewire(self) {
|
|
776
|
+
if (self._slot.pausable === true && self._isPaused()) {
|
|
777
|
+
self._control.pausedDepWaveOccurred = true;
|
|
778
|
+
return;
|
|
779
|
+
}
|
|
780
|
+
if (self._wave.pending > 0) return;
|
|
781
|
+
if (self._slot.handle === null) {
|
|
782
|
+
self._passthroughEmit();
|
|
783
|
+
return;
|
|
784
|
+
}
|
|
785
|
+
if (!self._wave.hasCalledFnOnce && !(self._slot.partial || self._allDepsSettled())) return;
|
|
786
|
+
self._markDirty();
|
|
787
|
+
self._runWave();
|
|
788
|
+
}
|
|
789
|
+
function nodeTryRun(self) {
|
|
790
|
+
if (self._wave.pending > 0) return;
|
|
791
|
+
if (self._slot.handle === null) {
|
|
792
|
+
self._passthroughEmit();
|
|
793
|
+
return;
|
|
794
|
+
}
|
|
795
|
+
if (!self._wave.hasCalledFnOnce) {
|
|
796
|
+
if (self._slot.partial || self._allDepsSettled()) self._runWave();
|
|
797
|
+
return;
|
|
798
|
+
}
|
|
799
|
+
self._runWave();
|
|
800
|
+
}
|
|
801
|
+
function nodeAllDepsSettled(self) {
|
|
802
|
+
for (let i = 0; i < self._slot.deps.length; i++) {
|
|
803
|
+
if (self._dep.hasData[i]) continue;
|
|
804
|
+
if (self._slot.terminalAsRealInput && self._dep.terminal[i] !== void 0) continue;
|
|
805
|
+
return false;
|
|
806
|
+
}
|
|
807
|
+
return true;
|
|
808
|
+
}
|
|
809
|
+
function nodePassthroughEmit(self) {
|
|
810
|
+
const b = self._dep.batch[0];
|
|
811
|
+
if (b !== null && b.length > 0) {
|
|
812
|
+
self._down([["DATA", b[b.length - 1]]]);
|
|
813
|
+
} else if (self._wave.emittedDirtyThisWave) {
|
|
814
|
+
self._down([["RESOLVED"]]);
|
|
815
|
+
}
|
|
816
|
+
self._dep.batch[0] = null;
|
|
817
|
+
self._wave.emittedDirtyThisWave = false;
|
|
818
|
+
}
|
|
819
|
+
function nodeRunWave(self) {
|
|
820
|
+
if (self._wave.insideRunWave)
|
|
821
|
+
throw new Error(
|
|
822
|
+
"synchronous feedback cycle: node fn re-entered its own wave (R-reentrancy / D37)"
|
|
823
|
+
);
|
|
824
|
+
self._wave.hasCalledFnOnce = true;
|
|
825
|
+
self._hooks.onInvalidate = [];
|
|
826
|
+
self._hooks.onDeactivation = [];
|
|
827
|
+
const ctx = self._buildCtx();
|
|
828
|
+
const wasDirty = self._wave.emittedDirtyThisWave;
|
|
829
|
+
self._wave.emittedSettleThisWave = false;
|
|
830
|
+
self._wave.insideRunWave = true;
|
|
831
|
+
try {
|
|
832
|
+
self._slot.dispatcher.invoke(self._slot.handle, ctx);
|
|
833
|
+
} finally {
|
|
834
|
+
self._wave.insideRunWave = false;
|
|
835
|
+
}
|
|
836
|
+
if (wasDirty && !self._wave.emittedSettleThisWave && self._value.terminal === void 0 && !self._isAsyncPool()) {
|
|
837
|
+
self._down([["RESOLVED"]]);
|
|
838
|
+
}
|
|
839
|
+
for (let i = 0; i < self._dep.batch.length; i++) {
|
|
840
|
+
self._dep.batch[i] = null;
|
|
841
|
+
self._dep.waveData[i] = [];
|
|
842
|
+
self._dep.waveTokens[i] = void 0;
|
|
843
|
+
self._dep.terminalInput[i] = void 0;
|
|
844
|
+
}
|
|
845
|
+
self._wave.emittedDirtyThisWave = false;
|
|
846
|
+
}
|
|
847
|
+
|
|
848
|
+
// src/node/node-runtime-host.ts
|
|
849
|
+
function nodeRuntimeHost(node2) {
|
|
850
|
+
return node2;
|
|
851
|
+
}
|
|
852
|
+
|
|
853
|
+
// src/node/node-lifecycle-runtime.ts
|
|
854
|
+
function nodeActivate(self) {
|
|
855
|
+
self._lifecycle.activated = true;
|
|
856
|
+
const seedRestoredDeps = self._restoredActivationPending;
|
|
857
|
+
self._restoredActivationPending = false;
|
|
858
|
+
self._dep.unsubs = new Array(self._slot.deps.length);
|
|
859
|
+
self._dep.idxBoxes = new Array(self._slot.deps.length);
|
|
860
|
+
for (const dep of self._slot.deps) self._subscribeDepAt(dep, { seedRestored: seedRestoredDeps });
|
|
861
|
+
if (self._slot.deps.length === 0 && self._slot.handle !== null && !self._wave.hasCalledFnOnce) {
|
|
862
|
+
self._runWave();
|
|
863
|
+
}
|
|
864
|
+
}
|
|
865
|
+
function nodeSubscribeDepAt(self, depNode, opts = {}) {
|
|
866
|
+
const idx0 = self._slot.deps.indexOf(depNode);
|
|
867
|
+
const box = { v: idx0 };
|
|
868
|
+
let ignoreInitialPush = opts.seedRestored === true;
|
|
869
|
+
if (ignoreInitialPush && idx0 !== -1) {
|
|
870
|
+
self._seedRestoredDepAt(idx0, depNode);
|
|
871
|
+
const dep = nodeRuntimeHost(depNode);
|
|
872
|
+
if (dep._value.terminal !== void 0 && !dep._slot.resubscribable) {
|
|
873
|
+
self._dep.unsubs[idx0] = () => {
|
|
874
|
+
};
|
|
875
|
+
self._dep.idxBoxes[idx0] = box;
|
|
876
|
+
return;
|
|
877
|
+
}
|
|
878
|
+
}
|
|
879
|
+
const unsub = depNode.subscribe((msg, delivery) => {
|
|
880
|
+
if (ignoreInitialPush && delivery === void 0) return;
|
|
881
|
+
if (ignoreInitialPush) ignoreInitialPush = false;
|
|
882
|
+
if (box.v === -1) return;
|
|
883
|
+
self._receiveFromDep(box.v, msg, delivery);
|
|
884
|
+
});
|
|
885
|
+
if (ignoreInitialPush && idx0 !== -1 && box.v !== -1) self._seedRestoredDepAt(idx0, depNode);
|
|
886
|
+
ignoreInitialPush = false;
|
|
887
|
+
if (idx0 !== -1) {
|
|
888
|
+
self._dep.unsubs[idx0] = unsub;
|
|
889
|
+
self._dep.idxBoxes[idx0] = box;
|
|
890
|
+
}
|
|
891
|
+
}
|
|
892
|
+
function nodeSeedRestoredDepAt(self, idx, depNode) {
|
|
893
|
+
const dep = nodeRuntimeHost(depNode);
|
|
894
|
+
const seedData = dep._value.hasData && !dep._slot.pull;
|
|
895
|
+
self._dep.batch[idx] = null;
|
|
896
|
+
self._dep.waveData[idx] = [];
|
|
897
|
+
self._dep.waveTokens[idx] = void 0;
|
|
898
|
+
self._dep.prev[idx] = seedData ? dep._value.cache : SENTINEL;
|
|
899
|
+
self._dep.hasData[idx] = seedData;
|
|
900
|
+
self._dep.dirty[idx] = false;
|
|
901
|
+
self._dep.tier[idx] = seedData ? 3 : 0;
|
|
902
|
+
self._dep.terminal[idx] = dep._value.terminal;
|
|
903
|
+
self._dep.terminalInput[idx] = void 0;
|
|
904
|
+
}
|
|
905
|
+
function nodeDeactivate(self) {
|
|
906
|
+
self._lifecycle.activated = false;
|
|
907
|
+
for (const u of self._dep.unsubs) if (u) u();
|
|
908
|
+
self._dep.unsubs = [];
|
|
909
|
+
self._dep.idxBoxes = [];
|
|
910
|
+
for (const fn of self._hooks.onDeactivation) fn();
|
|
911
|
+
self._hooks.onDeactivation = [];
|
|
912
|
+
self._hooks.onInvalidate = [];
|
|
913
|
+
const isCompute = self._slot.handle !== null || self._slot.deps.length > 0;
|
|
914
|
+
if (isCompute) {
|
|
915
|
+
self._value.cache = SENTINEL;
|
|
916
|
+
self._value.hasData = false;
|
|
917
|
+
self._value.status = "sentinel";
|
|
918
|
+
}
|
|
919
|
+
self._resetDepState();
|
|
920
|
+
self._wave.hasCalledFnOnce = false;
|
|
921
|
+
self._control.pauseLockset.clear();
|
|
922
|
+
self._control.pauseBuffer = [];
|
|
923
|
+
self._control.pausedDepWaveOccurred = false;
|
|
924
|
+
self._control.demandOwed = void 0;
|
|
925
|
+
self._control.activePull = void 0;
|
|
926
|
+
self._control.pullDirtyOwed = false;
|
|
927
|
+
self._value.replayRing = [];
|
|
928
|
+
if (!self._privateState.persist) self._privateState.value = SENTINEL;
|
|
929
|
+
}
|
|
930
|
+
function nodeSubscriberCount(self) {
|
|
931
|
+
return self._lifecycle.subscribers.size;
|
|
932
|
+
}
|
|
933
|
+
function nodeIsRuntimeQuiescentForRelease(self) {
|
|
934
|
+
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;
|
|
935
|
+
}
|
|
936
|
+
function nodeReleaseRuntime(self) {
|
|
937
|
+
if (self._released) return;
|
|
938
|
+
self._released = true;
|
|
939
|
+
const node2 = self;
|
|
940
|
+
releasedNodes.add(node2);
|
|
941
|
+
let releaseError;
|
|
942
|
+
const recordReleaseError = (error) => {
|
|
943
|
+
if (releaseError === void 0) releaseError = error;
|
|
944
|
+
};
|
|
945
|
+
self._lifecycle.activated = false;
|
|
946
|
+
for (const u of self._dep.unsubs) {
|
|
947
|
+
try {
|
|
948
|
+
u();
|
|
949
|
+
} catch (error) {
|
|
950
|
+
recordReleaseError(error);
|
|
951
|
+
}
|
|
952
|
+
}
|
|
953
|
+
for (const fn of self._hooks.onDeactivation) {
|
|
954
|
+
try {
|
|
955
|
+
fn();
|
|
956
|
+
} catch (error) {
|
|
957
|
+
recordReleaseError(error);
|
|
958
|
+
}
|
|
959
|
+
}
|
|
960
|
+
self._dep.unsubs = [];
|
|
961
|
+
self._dep.idxBoxes = [];
|
|
962
|
+
self._lifecycle.subscribers.clear();
|
|
963
|
+
if (self._slot.handle !== null) {
|
|
964
|
+
self._slot.dispatcher.unregister(self._slot.handle);
|
|
965
|
+
self._slot.handle = null;
|
|
966
|
+
}
|
|
967
|
+
self._slot.deps = [];
|
|
968
|
+
self._dep.batch = [];
|
|
969
|
+
self._dep.waveData = [];
|
|
970
|
+
self._dep.waveTokens = [];
|
|
971
|
+
self._dep.prev = [];
|
|
972
|
+
self._dep.hasData = [];
|
|
973
|
+
self._dep.dirty = [];
|
|
974
|
+
self._dep.tier = [];
|
|
975
|
+
self._dep.terminal = [];
|
|
976
|
+
self._dep.terminalInput = [];
|
|
977
|
+
self._value.cache = SENTINEL;
|
|
978
|
+
self._value.hasData = false;
|
|
979
|
+
self._value.status = "sentinel";
|
|
980
|
+
self._value.terminal = void 0;
|
|
981
|
+
self._value.replayRing = [];
|
|
982
|
+
self._privateState.value = SENTINEL;
|
|
983
|
+
self._privateState.persist = false;
|
|
984
|
+
self._syncCtx = null;
|
|
985
|
+
self._resetDepState();
|
|
986
|
+
self._hooks.onDeactivation = [];
|
|
987
|
+
self._hooks.onInvalidate = [];
|
|
988
|
+
self._control.pauseLockset.clear();
|
|
989
|
+
self._control.pauseBuffer = [];
|
|
990
|
+
self._control.pausedDepWaveOccurred = false;
|
|
991
|
+
self._control.demandOwed = void 0;
|
|
992
|
+
self._control.activePull = void 0;
|
|
993
|
+
self._control.pullDirtyOwed = false;
|
|
994
|
+
self._restoredActivationPending = false;
|
|
995
|
+
checkpointReaders.delete(node2);
|
|
996
|
+
restoreWriters.delete(node2);
|
|
997
|
+
runtimeReleasers.delete(node2);
|
|
998
|
+
runtimeQuiescenceReaders.delete(node2);
|
|
999
|
+
subscriberCountReaders.delete(node2);
|
|
1000
|
+
activationReaders.delete(node2);
|
|
1001
|
+
ownerTokens.delete(node2);
|
|
1002
|
+
topologyDepsChangedObservers.delete(node2);
|
|
1003
|
+
self._core.releaseSlot(self._id);
|
|
1004
|
+
if (releaseError !== void 0) throw releaseError;
|
|
1005
|
+
}
|
|
1006
|
+
function nodeResetDepState(self) {
|
|
1007
|
+
const n = self._slot.deps.length;
|
|
1008
|
+
for (let i = 0; i < n; i++) {
|
|
1009
|
+
self._dep.batch[i] = null;
|
|
1010
|
+
self._dep.waveData[i] = [];
|
|
1011
|
+
self._dep.waveTokens[i] = void 0;
|
|
1012
|
+
self._dep.prev[i] = SENTINEL;
|
|
1013
|
+
self._dep.hasData[i] = false;
|
|
1014
|
+
self._dep.dirty[i] = false;
|
|
1015
|
+
self._dep.tier[i] = 0;
|
|
1016
|
+
self._dep.terminal[i] = void 0;
|
|
1017
|
+
self._dep.terminalInput[i] = void 0;
|
|
1018
|
+
}
|
|
1019
|
+
self._wave.pending = 0;
|
|
1020
|
+
self._wave.emittedDirtyThisWave = false;
|
|
1021
|
+
}
|
|
1022
|
+
|
|
1023
|
+
// src/batch/batch.ts
|
|
1024
|
+
var active = null;
|
|
1025
|
+
var boundaryOwner = null;
|
|
1026
|
+
function currentBatch() {
|
|
1027
|
+
return active !== null;
|
|
1028
|
+
}
|
|
1029
|
+
function currentBoundaryBatchToken() {
|
|
1030
|
+
return active ?? boundaryOwner ?? void 0;
|
|
1031
|
+
}
|
|
1032
|
+
function deferToBatch(target, tier3Wave) {
|
|
1033
|
+
if (active === null) return false;
|
|
1034
|
+
if (!active.deferred.has(target)) active.order.push(target);
|
|
1035
|
+
active.deferred.set(target, tier3Wave);
|
|
1036
|
+
return true;
|
|
1037
|
+
}
|
|
1038
|
+
function deferAfterBatchForTarget(target, fn) {
|
|
1039
|
+
if (active === null || !active.deferred.has(target)) return false;
|
|
1040
|
+
const owner = active;
|
|
1041
|
+
target.__deferBoundary(() => {
|
|
1042
|
+
if (owner.committed) fn();
|
|
1043
|
+
}, owner);
|
|
1044
|
+
return true;
|
|
1045
|
+
}
|
|
1046
|
+
|
|
488
1047
|
// src/json/codec.ts
|
|
489
1048
|
var JS_MIN_NORMAL_NUMBER = 2 ** -1022;
|
|
490
1049
|
function assertStableJsonNumber(value, path) {
|
|
@@ -529,9 +1088,16 @@ function sortedJsonValue(value, seen = /* @__PURE__ */ new Set(), path = "$", st
|
|
|
529
1088
|
}
|
|
530
1089
|
for (const key of Object.getOwnPropertyNames(value)) {
|
|
531
1090
|
const isIndex = /^(0|[1-9]\d*)$/.test(key) && Number.isSafeInteger(Number(key)) && Number(key) < value.length;
|
|
1091
|
+
const descriptor = Object.getOwnPropertyDescriptor(value, key);
|
|
1092
|
+
if (descriptor !== void 0 && ("get" in descriptor || "set" in descriptor)) {
|
|
1093
|
+
throw new TypeError(`stableJsonString: accessor property at ${path}.${key}`);
|
|
1094
|
+
}
|
|
532
1095
|
if (key !== "length" && !isIndex) {
|
|
533
1096
|
throw new TypeError(`stableJsonString: non-index array property at ${path}.${key}`);
|
|
534
1097
|
}
|
|
1098
|
+
if (key !== "length" && descriptor !== void 0 && !descriptor.enumerable) {
|
|
1099
|
+
throw new TypeError(`stableJsonString: non-enumerable array property at ${path}.${key}`);
|
|
1100
|
+
}
|
|
535
1101
|
}
|
|
536
1102
|
const out2 = [];
|
|
537
1103
|
for (let i = 0; i < value.length; i += 1) {
|
|
@@ -545,6 +1111,15 @@ function sortedJsonValue(value, seen = /* @__PURE__ */ new Set(), path = "$", st
|
|
|
545
1111
|
if (Object.getOwnPropertySymbols(value).length > 0) {
|
|
546
1112
|
throw new TypeError(`stableJsonString: symbol-keyed properties at ${path}`);
|
|
547
1113
|
}
|
|
1114
|
+
for (const key of Object.getOwnPropertyNames(value)) {
|
|
1115
|
+
const descriptor = Object.getOwnPropertyDescriptor(value, key);
|
|
1116
|
+
if (descriptor !== void 0 && ("get" in descriptor || "set" in descriptor)) {
|
|
1117
|
+
throw new TypeError(`stableJsonString: accessor property at ${path}.${key}`);
|
|
1118
|
+
}
|
|
1119
|
+
if (descriptor !== void 0 && !descriptor.enumerable) {
|
|
1120
|
+
throw new TypeError(`stableJsonString: non-enumerable property at ${path}.${key}`);
|
|
1121
|
+
}
|
|
1122
|
+
}
|
|
548
1123
|
const out = /* @__PURE__ */ Object.create(null);
|
|
549
1124
|
for (const key of Object.keys(value).sort()) {
|
|
550
1125
|
out[key] = sortedJsonValue(
|
|
@@ -867,70 +1442,532 @@ function restoredV1Cid(policy, hasData, cache) {
|
|
|
867
1442
|
return computeV1Cid(policy, hasData ? cache : ABSENT_V1_SEED);
|
|
868
1443
|
}
|
|
869
1444
|
|
|
870
|
-
// src/node/node.ts
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
1445
|
+
// src/node/node-output-runtime.ts
|
|
1446
|
+
function nodeDown(self, msgs) {
|
|
1447
|
+
if (self._released) return;
|
|
1448
|
+
validateDownPayloads(msgs);
|
|
1449
|
+
const deliveryWave = {};
|
|
1450
|
+
const assertVersionDataCompatible = (wave) => {
|
|
1451
|
+
for (const m of wave) {
|
|
1452
|
+
if (m[0] === "DATA") assertNodeVersionDataCompatible(self._version.policy, m[1]);
|
|
1453
|
+
}
|
|
1454
|
+
};
|
|
1455
|
+
const snapshotVersionData = (wave) => wave.map(
|
|
1456
|
+
(m) => m[0] === "DATA" ? ["DATA", snapshotNodeVersionData(self._version.policy, m[1])] : m
|
|
1457
|
+
);
|
|
1458
|
+
assertVersionDataCompatible(msgs);
|
|
1459
|
+
if (self._value.terminal !== void 0) {
|
|
1460
|
+
if (!msgs.some((m) => m[0] === "TEARDOWN")) return;
|
|
1461
|
+
self._value.hasTorndown = true;
|
|
1462
|
+
if (self._slot.resetOnTeardown) {
|
|
1463
|
+
self._value.cache = SENTINEL;
|
|
1464
|
+
self._value.hasData = false;
|
|
1465
|
+
}
|
|
1466
|
+
self._emitToSubs(["TEARDOWN"], { wave: deliveryWave, last: true });
|
|
1467
|
+
return;
|
|
889
1468
|
}
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
1469
|
+
let sorted = [...msgs].sort((a, b) => messageTier(a[0]) - messageTier(b[0]));
|
|
1470
|
+
const firstInvalidate = sorted.findIndex((m) => m[0] === "INVALIDATE");
|
|
1471
|
+
if (firstInvalidate !== -1) {
|
|
1472
|
+
sorted = sorted.filter((m, i) => m[0] !== "INVALIDATE" || i === firstInvalidate);
|
|
1473
|
+
}
|
|
1474
|
+
const hasTeardown = sorted.some((m) => m[0] === "TEARDOWN");
|
|
1475
|
+
const hasTerminal = sorted.some((m) => m[0] === "COMPLETE" || m[0] === "ERROR");
|
|
1476
|
+
if (hasTeardown && !hasTerminal && self._value.terminal === void 0 && !self._value.hasTorndown) {
|
|
1477
|
+
sorted = [["COMPLETE"], ...sorted];
|
|
1478
|
+
}
|
|
1479
|
+
if (!self._wave.insideRunWave && currentBatch()) {
|
|
1480
|
+
const deferred = snapshotVersionData(sorted.filter((m) => isDeferredTier(m[0])));
|
|
1481
|
+
if (deferred.length > 0) {
|
|
1482
|
+
if (!self._wave.emittedDirtyThisWave) {
|
|
1483
|
+
self._wave.emittedDirtyThisWave = true;
|
|
1484
|
+
self._value.status = "dirty";
|
|
1485
|
+
self._emitToSubs(["DIRTY"], { wave: deliveryWave, last: false });
|
|
1486
|
+
}
|
|
1487
|
+
self._wave.batchDirtyOwed = true;
|
|
1488
|
+
deferToBatch(self, deferred);
|
|
1489
|
+
return;
|
|
1490
|
+
}
|
|
898
1491
|
}
|
|
1492
|
+
if (self._shouldBufferOnPause()) {
|
|
1493
|
+
const buffered = snapshotVersionData(sorted.filter((m) => isPauseBufferedTier(m[0])));
|
|
1494
|
+
if (buffered.length > 0) {
|
|
1495
|
+
self._wave.emittedSettleThisWave = true;
|
|
1496
|
+
self._control.pauseBuffer.push(buffered);
|
|
1497
|
+
}
|
|
1498
|
+
sorted = sorted.filter((m) => !isPauseBufferedTier(m[0]));
|
|
1499
|
+
if (sorted.length === 0) return;
|
|
1500
|
+
}
|
|
1501
|
+
let dataCount = 0;
|
|
1502
|
+
let hasTier3 = false;
|
|
1503
|
+
let hasResolved = false;
|
|
1504
|
+
for (const m of sorted) {
|
|
1505
|
+
if (m[0] === "DATA") dataCount++;
|
|
1506
|
+
if (m[0] === "RESOLVED") hasResolved = true;
|
|
1507
|
+
if (isValueTier(m[0])) hasTier3 = true;
|
|
1508
|
+
}
|
|
1509
|
+
if (dataCount >= 1 && hasResolved) {
|
|
1510
|
+
throw new Error(
|
|
1511
|
+
"down: a wave cannot mix DATA and RESOLVED (tier-3 exclusivity, R-resolved-undirty)"
|
|
1512
|
+
);
|
|
1513
|
+
}
|
|
1514
|
+
const plannedVersions = new Array(sorted.length);
|
|
1515
|
+
if (dataCount > 0) {
|
|
1516
|
+
let plannedVersion = self._version.value;
|
|
1517
|
+
for (let i = 0; i < sorted.length; i++) {
|
|
1518
|
+
const m = sorted[i];
|
|
1519
|
+
if (m[0] !== "DATA") continue;
|
|
1520
|
+
plannedVersion = advanceNodeVersion(plannedVersion, self._version.policy, m[1]);
|
|
1521
|
+
plannedVersions[i] = plannedVersion;
|
|
1522
|
+
}
|
|
1523
|
+
}
|
|
1524
|
+
if (hasTier3 && (!self._wave.insideRunWave || self._control.pullDirtyOwed) && !self._wave.emittedDirtyThisWave) {
|
|
1525
|
+
self._wave.emittedDirtyThisWave = true;
|
|
1526
|
+
self._value.status = "dirty";
|
|
1527
|
+
self._emitToSubs(["DIRTY"], { wave: deliveryWave, last: false });
|
|
1528
|
+
}
|
|
1529
|
+
for (let i = 0; i < sorted.length; i++) {
|
|
1530
|
+
const m = sorted[i];
|
|
1531
|
+
const delivery = { wave: deliveryWave, last: i === sorted.length - 1 };
|
|
1532
|
+
if (isDeferredTier(m[0])) self._wave.emittedSettleThisWave = true;
|
|
1533
|
+
if (m[0] === "DIRTY") {
|
|
1534
|
+
if (!self._wave.emittedDirtyThisWave) {
|
|
1535
|
+
self._wave.emittedDirtyThisWave = true;
|
|
1536
|
+
self._value.status = "dirty";
|
|
1537
|
+
self._emitToSubs(["DIRTY"], delivery);
|
|
1538
|
+
}
|
|
1539
|
+
continue;
|
|
1540
|
+
}
|
|
1541
|
+
if (m[0] === "DATA") {
|
|
1542
|
+
const v = m[1];
|
|
1543
|
+
self._value.cache = v;
|
|
1544
|
+
self._value.hasData = true;
|
|
1545
|
+
self._value.status = "settled";
|
|
1546
|
+
self._version.value = plannedVersions[i];
|
|
1547
|
+
if (self._slot.replayN > 0) {
|
|
1548
|
+
self._value.replayRing.push(v);
|
|
1549
|
+
if (self._value.replayRing.length > self._slot.replayN) self._value.replayRing.shift();
|
|
1550
|
+
}
|
|
1551
|
+
self._emitToSubs(["DATA", v], delivery);
|
|
1552
|
+
continue;
|
|
1553
|
+
}
|
|
1554
|
+
if (m[0] === "RESOLVED") {
|
|
1555
|
+
self._value.status = self._value.hasData ? "resolved" : "sentinel";
|
|
1556
|
+
self._emitToSubs(["RESOLVED"], delivery);
|
|
1557
|
+
continue;
|
|
1558
|
+
}
|
|
1559
|
+
if (m[0] === "INVALIDATE") {
|
|
1560
|
+
self._invalidate(delivery);
|
|
1561
|
+
continue;
|
|
1562
|
+
}
|
|
1563
|
+
if (m[0] === "COMPLETE") {
|
|
1564
|
+
if (self._value.terminal !== void 0) continue;
|
|
1565
|
+
self._value.terminal = true;
|
|
1566
|
+
self._control.pauseBuffer = [];
|
|
1567
|
+
self._value.status = "completed";
|
|
1568
|
+
self._emitToSubs(["COMPLETE"], delivery);
|
|
1569
|
+
continue;
|
|
1570
|
+
}
|
|
1571
|
+
if (m[0] === "ERROR") {
|
|
1572
|
+
if (self._value.terminal !== void 0) continue;
|
|
1573
|
+
self._value.terminal = m[1];
|
|
1574
|
+
self._control.pauseBuffer = [];
|
|
1575
|
+
self._value.status = "errored";
|
|
1576
|
+
self._emitToSubs(["ERROR", m[1]], delivery);
|
|
1577
|
+
continue;
|
|
1578
|
+
}
|
|
1579
|
+
if (m[0] === "TEARDOWN") {
|
|
1580
|
+
self._value.hasTorndown = true;
|
|
1581
|
+
if (self._slot.resetOnTeardown) {
|
|
1582
|
+
self._value.cache = SENTINEL;
|
|
1583
|
+
self._value.hasData = false;
|
|
1584
|
+
}
|
|
1585
|
+
self._emitToSubs(["TEARDOWN"], delivery);
|
|
1586
|
+
}
|
|
1587
|
+
}
|
|
1588
|
+
if (!self._wave.insideRunWave) self._wave.emittedDirtyThisWave = false;
|
|
899
1589
|
}
|
|
900
|
-
function
|
|
901
|
-
|
|
1590
|
+
function nodeUp(self, msgs, towardDep, route) {
|
|
1591
|
+
if (self._released) return;
|
|
1592
|
+
const routeState = route ?? { demandFired: /* @__PURE__ */ new Map() };
|
|
1593
|
+
for (const m of msgs) {
|
|
1594
|
+
if (!isUpAllowed(m[0])) {
|
|
1595
|
+
throw new Error(
|
|
1596
|
+
`ctx.up: ${m[0]} is down-only (tier ${messageTier(m[0])}); up carries control tiers only (R-ctx-up)`
|
|
1597
|
+
);
|
|
1598
|
+
}
|
|
1599
|
+
}
|
|
1600
|
+
for (const m of msgs) {
|
|
1601
|
+
if (m[0] === "PAUSE") {
|
|
1602
|
+
self._pauseAcquire(m[1]);
|
|
1603
|
+
} else if (m[0] === "RESUME") {
|
|
1604
|
+
if (self._control.pauseLockset.has(m[1])) {
|
|
1605
|
+
self._pauseRelease(m[1]);
|
|
1606
|
+
} else {
|
|
1607
|
+
self._forwardUp(m, towardDep, routeState);
|
|
1608
|
+
}
|
|
1609
|
+
} else if (m[0] === "PULL") {
|
|
1610
|
+
const demand = normalizePullDemand(m[1]);
|
|
1611
|
+
if (self._slot.pull && demand.pullId === self._slot.pullLock) {
|
|
1612
|
+
if (!self._markDemandRouted(demand.pullId, routeState)) self._onDemand(demand);
|
|
1613
|
+
} else {
|
|
1614
|
+
self._forwardUp(["PULL", demand], towardDep, routeState);
|
|
1615
|
+
}
|
|
1616
|
+
} else if (self._slot.deps.length === 0) {
|
|
1617
|
+
if (m[0] === "INVALIDATE") self._down([["INVALIDATE"]]);
|
|
1618
|
+
} else {
|
|
1619
|
+
self._forwardUp(m, towardDep, routeState);
|
|
1620
|
+
}
|
|
1621
|
+
}
|
|
902
1622
|
}
|
|
903
|
-
function
|
|
904
|
-
|
|
1623
|
+
function nodeMarkDemandRouted(self, lockId, route) {
|
|
1624
|
+
let holders = route.demandFired.get(lockId);
|
|
1625
|
+
if (holders === void 0) {
|
|
1626
|
+
holders = /* @__PURE__ */ new Set();
|
|
1627
|
+
route.demandFired.set(lockId, holders);
|
|
1628
|
+
}
|
|
1629
|
+
const node2 = self;
|
|
1630
|
+
if (holders.has(node2)) return true;
|
|
1631
|
+
holders.add(node2);
|
|
1632
|
+
return false;
|
|
905
1633
|
}
|
|
906
|
-
function
|
|
907
|
-
|
|
1634
|
+
function nodeForwardUp(self, m, towardDep, route) {
|
|
1635
|
+
if (self._slot.deps.length === 0) return;
|
|
1636
|
+
if (towardDep !== void 0) {
|
|
1637
|
+
const d = self._slot.deps[towardDep];
|
|
1638
|
+
if (d !== void 0) nodeRuntimeHost(d)._up([m], void 0, route);
|
|
1639
|
+
} else {
|
|
1640
|
+
for (const dep of self._slot.deps) nodeRuntimeHost(dep)._up([m], void 0, route);
|
|
1641
|
+
}
|
|
908
1642
|
}
|
|
909
|
-
function
|
|
910
|
-
return
|
|
1643
|
+
function nodeIsPaused(self) {
|
|
1644
|
+
return self._control.pauseLockset.size > 0;
|
|
911
1645
|
}
|
|
912
|
-
function
|
|
913
|
-
if (
|
|
914
|
-
|
|
1646
|
+
function nodeHasBoundaryPauseLock(self) {
|
|
1647
|
+
if (self._slot.pausable === false) return false;
|
|
1648
|
+
return self._control.pauseLockset.size > 0;
|
|
1649
|
+
}
|
|
1650
|
+
function nodeIsAsyncPool(self) {
|
|
1651
|
+
return self._slot.handle !== null && self._slot.dispatcher.poolKind(self._slot.handle.poolId) === "async";
|
|
1652
|
+
}
|
|
1653
|
+
function nodePauseAcquire(self, lockId) {
|
|
1654
|
+
self._control.pauseLockset.add(lockId);
|
|
1655
|
+
}
|
|
1656
|
+
function nodePauseRelease(self, lockId) {
|
|
1657
|
+
if (!self._control.pauseLockset.has(lockId)) return;
|
|
1658
|
+
self._control.pauseLockset.delete(lockId);
|
|
1659
|
+
if (self._slot.pull && self._control.demandOwed !== void 0) self._fireOwedDemandIfReady();
|
|
1660
|
+
if (self._hasBoundaryPauseLock()) return;
|
|
1661
|
+
scheduleBoundaryDrain(self._core);
|
|
1662
|
+
if (self._slot.pull) return;
|
|
1663
|
+
self._onResume();
|
|
1664
|
+
}
|
|
1665
|
+
function nodeOnResume(self) {
|
|
1666
|
+
if (self._value.terminal !== void 0) {
|
|
1667
|
+
self._control.pauseBuffer = [];
|
|
1668
|
+
self._control.pausedDepWaveOccurred = false;
|
|
1669
|
+
self._control.demandOwed = void 0;
|
|
1670
|
+
self._control.activePull = void 0;
|
|
1671
|
+
self._control.pullDirtyOwed = false;
|
|
1672
|
+
return;
|
|
915
1673
|
}
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
1674
|
+
if (self._control.pauseBuffer.length > 0) {
|
|
1675
|
+
const buf = self._control.pauseBuffer;
|
|
1676
|
+
self._control.pauseBuffer = [];
|
|
1677
|
+
for (const wave of buf) self._down(wave);
|
|
1678
|
+
}
|
|
1679
|
+
if (self._control.pausedDepWaveOccurred) {
|
|
1680
|
+
self._control.pausedDepWaveOccurred = false;
|
|
1681
|
+
self._tryRun();
|
|
919
1682
|
}
|
|
920
|
-
const params = demand.params;
|
|
921
|
-
return params === void 0 ? { pullId } : { pullId, params };
|
|
922
1683
|
}
|
|
923
|
-
function
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
1684
|
+
function nodeCanFireDemand(self) {
|
|
1685
|
+
if (self._value.terminal !== void 0 || self._wave.pending > 0) return false;
|
|
1686
|
+
return self._control.pauseLockset.size === 0;
|
|
1687
|
+
}
|
|
1688
|
+
function nodeDeliverPullDemand(self, demand) {
|
|
1689
|
+
self._control.demandOwed = void 0;
|
|
1690
|
+
self._control.activePull = demand;
|
|
1691
|
+
self._control.inDeliverDemand = true;
|
|
1692
|
+
try {
|
|
1693
|
+
self._firePullDemand();
|
|
1694
|
+
} finally {
|
|
1695
|
+
self._control.activePull = void 0;
|
|
1696
|
+
self._control.inDeliverDemand = false;
|
|
1697
|
+
}
|
|
1698
|
+
}
|
|
1699
|
+
function nodeOnDemand(self, demand) {
|
|
1700
|
+
if (self._control.inDeliverDemand) return;
|
|
1701
|
+
if (self._canFireDemand()) self._deliverPullDemand(demand);
|
|
1702
|
+
else self._control.demandOwed = demand;
|
|
1703
|
+
}
|
|
1704
|
+
function nodeFirePullDemand(self) {
|
|
1705
|
+
let drainedBuffer = false;
|
|
1706
|
+
if (self._control.pauseBuffer.length > 0) {
|
|
1707
|
+
const buf = self._control.pauseBuffer;
|
|
1708
|
+
self._control.pauseBuffer = [];
|
|
1709
|
+
for (const wave of buf) self._down(wave);
|
|
1710
|
+
drainedBuffer = true;
|
|
1711
|
+
}
|
|
1712
|
+
if (drainedBuffer) return;
|
|
1713
|
+
if (self._control.pausedDepWaveOccurred) {
|
|
1714
|
+
const gated = self._slot.handle !== null && !self._wave.hasCalledFnOnce && !(self._slot.partial || self._allDepsSettled());
|
|
1715
|
+
if (self._wave.pending > 0 || gated) return;
|
|
1716
|
+
self._control.pausedDepWaveOccurred = false;
|
|
1717
|
+
self._wave.emittedDirtyThisWave = false;
|
|
1718
|
+
self._control.pullDirtyOwed = true;
|
|
1719
|
+
try {
|
|
1720
|
+
self._tryRun();
|
|
1721
|
+
} finally {
|
|
1722
|
+
self._control.pullDirtyOwed = false;
|
|
927
1723
|
}
|
|
928
|
-
|
|
929
|
-
|
|
1724
|
+
return;
|
|
1725
|
+
}
|
|
1726
|
+
if (self._slot.handle !== null) {
|
|
1727
|
+
if (!self._wave.hasCalledFnOnce && !(self._slot.partial || self._allDepsSettled())) return;
|
|
1728
|
+
self._wave.emittedDirtyThisWave = false;
|
|
1729
|
+
self._control.pullDirtyOwed = true;
|
|
1730
|
+
try {
|
|
1731
|
+
self._runWave();
|
|
1732
|
+
} finally {
|
|
1733
|
+
self._control.pullDirtyOwed = false;
|
|
930
1734
|
}
|
|
931
1735
|
}
|
|
932
1736
|
}
|
|
933
|
-
|
|
1737
|
+
function nodeFireOwedDemandIfReady(self) {
|
|
1738
|
+
if (self._control.inDeliverDemand) return;
|
|
1739
|
+
if (self._slot.pull && self._control.demandOwed !== void 0 && self._canFireDemand()) {
|
|
1740
|
+
self._deliverPullDemand(self._control.demandOwed);
|
|
1741
|
+
}
|
|
1742
|
+
}
|
|
1743
|
+
function nodeShouldBufferOnPause(self) {
|
|
1744
|
+
if (self._slot.pausable === false) return false;
|
|
1745
|
+
if (!self._isPaused() && !self._isPullQuiet()) return false;
|
|
1746
|
+
if (self._slot.pausable === "resumeAll") return true;
|
|
1747
|
+
if (!self._wave.insideRunWave && self._isAsyncPool() && self._slot.deps.length > 0) return true;
|
|
1748
|
+
return false;
|
|
1749
|
+
}
|
|
1750
|
+
function nodeInvalidate(self, delivery) {
|
|
1751
|
+
if (!self._value.hasData) return;
|
|
1752
|
+
self._value.cache = SENTINEL;
|
|
1753
|
+
self._value.hasData = false;
|
|
1754
|
+
self._value.status = "sentinel";
|
|
1755
|
+
self._value.replayRing = [];
|
|
1756
|
+
for (const fn of self._hooks.onInvalidate) fn();
|
|
1757
|
+
self._emitToSubs(["INVALIDATE"], delivery);
|
|
1758
|
+
}
|
|
1759
|
+
function nodeAllDepsTerminal(self) {
|
|
1760
|
+
if (self._slot.deps.length === 0) return false;
|
|
1761
|
+
for (const tm of self._dep.terminal) if (tm === void 0) return false;
|
|
1762
|
+
return true;
|
|
1763
|
+
}
|
|
1764
|
+
function nodeResetLifecycle(self) {
|
|
1765
|
+
for (const u of self._dep.unsubs) if (u) u();
|
|
1766
|
+
self._dep.unsubs = [];
|
|
1767
|
+
self._dep.idxBoxes = [];
|
|
1768
|
+
self._lifecycle.subscribers.clear();
|
|
1769
|
+
self._lifecycle.activated = false;
|
|
1770
|
+
self._value.terminal = void 0;
|
|
1771
|
+
self._value.hasTorndown = false;
|
|
1772
|
+
self._wave.hasCalledFnOnce = false;
|
|
1773
|
+
self._resetDepState();
|
|
1774
|
+
self._control.pauseLockset.clear();
|
|
1775
|
+
self._control.pauseBuffer = [];
|
|
1776
|
+
self._control.pausedDepWaveOccurred = false;
|
|
1777
|
+
self._control.demandOwed = void 0;
|
|
1778
|
+
self._control.activePull = void 0;
|
|
1779
|
+
self._control.pullDirtyOwed = false;
|
|
1780
|
+
self._value.replayRing = [];
|
|
1781
|
+
const isCompute = self._slot.handle !== null || self._slot.deps.length > 0;
|
|
1782
|
+
if (isCompute) {
|
|
1783
|
+
self._value.cache = SENTINEL;
|
|
1784
|
+
self._value.hasData = false;
|
|
1785
|
+
self._value.status = "sentinel";
|
|
1786
|
+
} else {
|
|
1787
|
+
self._value.status = self._value.hasData ? "settled" : "sentinel";
|
|
1788
|
+
}
|
|
1789
|
+
if (!self._privateState.persist) self._privateState.value = SENTINEL;
|
|
1790
|
+
}
|
|
1791
|
+
function nodeEmitToSubs(self, msg, delivery) {
|
|
1792
|
+
if (self._released) return;
|
|
1793
|
+
const subs = [...self._lifecycle.subscribers];
|
|
1794
|
+
for (const sink of subs) sink(msg, delivery);
|
|
1795
|
+
}
|
|
1796
|
+
function nodeCommitBatchedWave(self, wave) {
|
|
1797
|
+
self._wave.batchDirtyOwed = false;
|
|
1798
|
+
self._down(wave);
|
|
1799
|
+
}
|
|
1800
|
+
function nodeRollbackBatched(self) {
|
|
1801
|
+
if (self._wave.batchDirtyOwed) {
|
|
1802
|
+
self._wave.batchDirtyOwed = false;
|
|
1803
|
+
self._wave.emittedDirtyThisWave = false;
|
|
1804
|
+
self._value.status = self._value.hasData ? "settled" : "sentinel";
|
|
1805
|
+
self._emitToSubs(["RESOLVED"]);
|
|
1806
|
+
}
|
|
1807
|
+
}
|
|
1808
|
+
function nodeDeferBoundary(self, fn, batchToken) {
|
|
1809
|
+
deferRewire(self._core, fn, {
|
|
1810
|
+
batchToken,
|
|
1811
|
+
isReady: () => !self._hasBoundaryPauseLock()
|
|
1812
|
+
});
|
|
1813
|
+
}
|
|
1814
|
+
|
|
1815
|
+
// src/node/node-rewire-runtime.ts
|
|
1816
|
+
function nodeRequestRewireNext(self, op) {
|
|
1817
|
+
deferRewire(self._core, () => self._applyRewireNext(op), {
|
|
1818
|
+
batchToken: currentBoundaryBatchToken(),
|
|
1819
|
+
isReady: () => !self._hasBoundaryPauseLock()
|
|
1820
|
+
});
|
|
1821
|
+
}
|
|
1822
|
+
function nodeRequestUpNext(self, msgs, towardDep) {
|
|
1823
|
+
deferRewire(
|
|
1824
|
+
self._core,
|
|
1825
|
+
() => {
|
|
1826
|
+
if (!self._released) self._up(msgs, towardDep);
|
|
1827
|
+
},
|
|
1828
|
+
{
|
|
1829
|
+
batchToken: currentBoundaryBatchToken(),
|
|
1830
|
+
isReady: () => !self._hasBoundaryPauseLock()
|
|
1831
|
+
}
|
|
1832
|
+
);
|
|
1833
|
+
}
|
|
1834
|
+
function nodeApplyRewireNext(self, op) {
|
|
1835
|
+
if (self._released) return;
|
|
1836
|
+
try {
|
|
1837
|
+
if (op.kind === "add") {
|
|
1838
|
+
const next = self._slot.deps.includes(op.dep) ? [...self._slot.deps] : [...self._slot.deps, op.dep];
|
|
1839
|
+
self._rewire(next, op.fn, { allowTerminalOwner: true });
|
|
1840
|
+
} else if (op.kind === "remove") {
|
|
1841
|
+
self._rewire(
|
|
1842
|
+
self._slot.deps.filter((d) => d !== op.dep),
|
|
1843
|
+
op.fn,
|
|
1844
|
+
{ allowTerminalOwner: true }
|
|
1845
|
+
);
|
|
1846
|
+
} else {
|
|
1847
|
+
self._rewire(self._dedupDeps(op.deps), op.fn, { allowTerminalOwner: true });
|
|
1848
|
+
}
|
|
1849
|
+
} catch (e) {
|
|
1850
|
+
self._down([["ERROR", errorPayload(e, "rewireNext op failed")]]);
|
|
1851
|
+
}
|
|
1852
|
+
}
|
|
1853
|
+
function nodeRewire(self, newDeps, fn, opts = {}) {
|
|
1854
|
+
const node2 = self;
|
|
1855
|
+
if (self._value.terminal !== void 0 && !opts.allowTerminalOwner)
|
|
1856
|
+
throw new Error(
|
|
1857
|
+
"rewire: node is terminal (completed/errored) \u2014 cannot rewire (R-rewire / D42)"
|
|
1858
|
+
);
|
|
1859
|
+
if (self._wave.insideRunWave)
|
|
1860
|
+
throw new Error(
|
|
1861
|
+
"rewire: mid-fn topology mutation \u2014 a fn mutating its own deps mid-wave is the feedback cycle (R-rewire / D37)"
|
|
1862
|
+
);
|
|
1863
|
+
if (self._wave.inDepMutation)
|
|
1864
|
+
throw new Error(
|
|
1865
|
+
"rewire: reentrant dep mutation \u2014 another replaceDeps/subscribeDep/unsubscribeDep is in flight (R-rewire)"
|
|
1866
|
+
);
|
|
1867
|
+
if (newDeps.includes(node2)) throw new Error("rewire: self-dependency rejected (R-rewire / D42)");
|
|
1868
|
+
const oldDeps = self._slot.deps;
|
|
1869
|
+
const added = newDeps.filter((d) => !oldDeps.includes(d));
|
|
1870
|
+
for (const d of added) {
|
|
1871
|
+
if (self._reachableUpstream(d, node2))
|
|
1872
|
+
throw new Error(
|
|
1873
|
+
"rewire: would create a cycle \u2014 dep already transitively depends on this node (R-rewire / D42)"
|
|
1874
|
+
);
|
|
1875
|
+
const dep = nodeRuntimeHost(d);
|
|
1876
|
+
if (dep._value.terminal !== void 0 && !dep._slot.resubscribable)
|
|
1877
|
+
throw new Error(
|
|
1878
|
+
"rewire: cannot add a non-resubscribable terminal dep \u2014 would wedge (R-rewire / D42)"
|
|
1879
|
+
);
|
|
1880
|
+
self._assertRewireDepOwner(d);
|
|
1881
|
+
}
|
|
1882
|
+
if (deferAfterBatchForTarget(node2, () => {
|
|
1883
|
+
self._rewire(newDeps, fn, { ...opts, allowTerminalOwner: true });
|
|
1884
|
+
})) {
|
|
1885
|
+
return true;
|
|
1886
|
+
}
|
|
1887
|
+
if (!self._lifecycle.activated) self._restoredActivationPending = false;
|
|
1888
|
+
self._wave.inDepMutation = true;
|
|
1889
|
+
self._wave.rewireRunPending = false;
|
|
1890
|
+
let zeroDepUnDirty = false;
|
|
1891
|
+
try {
|
|
1892
|
+
const oldHandle = self._slot.handle;
|
|
1893
|
+
self._slot.handle = self._slot.dispatcher.register(fn, self._slot.pool);
|
|
1894
|
+
if (oldHandle !== null) self._slot.dispatcher.unregister(oldHandle);
|
|
1895
|
+
const removed = oldDeps.filter((d) => !newDeps.includes(d));
|
|
1896
|
+
let removedDirtyContributor = false;
|
|
1897
|
+
for (const d of removed) {
|
|
1898
|
+
const oldIdx = oldDeps.indexOf(d);
|
|
1899
|
+
if (self._dep.dirty[oldIdx]) {
|
|
1900
|
+
removedDirtyContributor = true;
|
|
1901
|
+
self._wave.pending--;
|
|
1902
|
+
}
|
|
1903
|
+
if (self._lifecycle.activated) {
|
|
1904
|
+
const box = self._dep.idxBoxes[oldIdx];
|
|
1905
|
+
if (box) box.v = -1;
|
|
1906
|
+
const unsub = self._dep.unsubs[oldIdx];
|
|
1907
|
+
if (unsub) unsub();
|
|
1908
|
+
}
|
|
1909
|
+
}
|
|
1910
|
+
const n = newDeps.length;
|
|
1911
|
+
const newBatch = new Array(n).fill(null);
|
|
1912
|
+
const newPrev = new Array(n).fill(SENTINEL);
|
|
1913
|
+
const newHasData = new Array(n).fill(false);
|
|
1914
|
+
const newDirty = new Array(n).fill(false);
|
|
1915
|
+
const newTier = new Array(n).fill(0);
|
|
1916
|
+
const newTerminal = new Array(n).fill(void 0);
|
|
1917
|
+
const newTerminalInput = new Array(n).fill(void 0);
|
|
1918
|
+
const newUnsubs = new Array(n);
|
|
1919
|
+
const newBoxes = new Array(n);
|
|
1920
|
+
for (let j = 0; j < n; j++) {
|
|
1921
|
+
const oldIdx = oldDeps.indexOf(newDeps[j]);
|
|
1922
|
+
if (oldIdx !== -1) {
|
|
1923
|
+
newBatch[j] = self._dep.batch[oldIdx];
|
|
1924
|
+
newPrev[j] = self._dep.prev[oldIdx];
|
|
1925
|
+
newHasData[j] = self._dep.hasData[oldIdx];
|
|
1926
|
+
newDirty[j] = self._dep.dirty[oldIdx];
|
|
1927
|
+
newTier[j] = self._dep.tier[oldIdx];
|
|
1928
|
+
newTerminal[j] = self._dep.terminal[oldIdx];
|
|
1929
|
+
newUnsubs[j] = self._dep.unsubs[oldIdx];
|
|
1930
|
+
const box = self._dep.idxBoxes[oldIdx];
|
|
1931
|
+
if (box) box.v = j;
|
|
1932
|
+
newBoxes[j] = box;
|
|
1933
|
+
}
|
|
1934
|
+
}
|
|
1935
|
+
self._slot.deps = newDeps;
|
|
1936
|
+
self._dep.batch = newBatch;
|
|
1937
|
+
self._dep.prev = newPrev;
|
|
1938
|
+
self._dep.hasData = newHasData;
|
|
1939
|
+
self._dep.dirty = newDirty;
|
|
1940
|
+
self._dep.tier = newTier;
|
|
1941
|
+
self._dep.terminal = newTerminal;
|
|
1942
|
+
self._dep.terminalInput = newTerminalInput;
|
|
1943
|
+
self._dep.unsubs = newUnsubs;
|
|
1944
|
+
self._dep.idxBoxes = newBoxes;
|
|
1945
|
+
self._dep.waveData = newDeps.map(() => []);
|
|
1946
|
+
self._dep.waveTokens = new Array(newDeps.length).fill(void 0);
|
|
1947
|
+
self._syncCtx = null;
|
|
1948
|
+
if (self._lifecycle.activated) {
|
|
1949
|
+
for (const d of added) self._subscribeDepAt(d);
|
|
1950
|
+
}
|
|
1951
|
+
notifyTopologyDepsChanged(node2, oldDeps, newDeps);
|
|
1952
|
+
if (removedDirtyContributor && self._wave.pending === 0 && self._value.status === "dirty") {
|
|
1953
|
+
if (newDeps.length > 0) self._wave.rewireRunPending = true;
|
|
1954
|
+
else zeroDepUnDirty = true;
|
|
1955
|
+
}
|
|
1956
|
+
} finally {
|
|
1957
|
+
self._wave.inDepMutation = false;
|
|
1958
|
+
}
|
|
1959
|
+
if (self._wave.rewireRunPending) {
|
|
1960
|
+
self._wave.rewireRunPending = false;
|
|
1961
|
+
self._settleRewire();
|
|
1962
|
+
} else if (zeroDepUnDirty) {
|
|
1963
|
+
if (self._wave.emittedDirtyThisWave) self._down([["RESOLVED"]]);
|
|
1964
|
+
else self._value.status = self._value.hasData ? "settled" : "sentinel";
|
|
1965
|
+
}
|
|
1966
|
+
return false;
|
|
1967
|
+
}
|
|
1968
|
+
|
|
1969
|
+
// src/node/node.ts
|
|
1970
|
+
var Node = class _Node {
|
|
934
1971
|
_core;
|
|
935
1972
|
_id;
|
|
936
1973
|
_slot;
|
|
@@ -951,12 +1988,56 @@ var Node = class {
|
|
|
951
1988
|
set _syncCtx(ctx) {
|
|
952
1989
|
this._syncCtxState.value = ctx;
|
|
953
1990
|
}
|
|
1991
|
+
static _retainIndirectRuntimeMethods(node2) {
|
|
1992
|
+
void node2._dep;
|
|
1993
|
+
void node2._hooks;
|
|
1994
|
+
void node2._restoredActivationPending;
|
|
1995
|
+
void node2._requestRewireNext;
|
|
1996
|
+
void node2._requestUpNext;
|
|
1997
|
+
void node2._applyRewireNext;
|
|
1998
|
+
void node2._reachableUpstream;
|
|
1999
|
+
void node2._assertRewireDepOwner;
|
|
2000
|
+
void node2._subscribeDepAt;
|
|
2001
|
+
void node2._seedRestoredDepAt;
|
|
2002
|
+
void node2._recordDepProjection;
|
|
2003
|
+
void node2._depProjectionHasData;
|
|
2004
|
+
void node2._receiveFromDep;
|
|
2005
|
+
void node2._releaseDepDirty;
|
|
2006
|
+
void node2._settleAfterAbsorbedTerminal;
|
|
2007
|
+
void node2._markDirty;
|
|
2008
|
+
void node2._maybeRun;
|
|
2009
|
+
void node2._settleRewire;
|
|
2010
|
+
void node2._tryRun;
|
|
2011
|
+
void node2._allDepsSettled;
|
|
2012
|
+
void node2._passthroughEmit;
|
|
2013
|
+
void node2._runWave;
|
|
2014
|
+
void node2._buildCtx;
|
|
2015
|
+
void node2._makeCtx;
|
|
2016
|
+
void node2._refreshCtx;
|
|
2017
|
+
void node2._makeState;
|
|
2018
|
+
void node2._markDemandRouted;
|
|
2019
|
+
void node2._forwardUp;
|
|
2020
|
+
void node2._isPullQuiet;
|
|
2021
|
+
void node2._isPaused;
|
|
2022
|
+
void node2._hasBoundaryPauseLock;
|
|
2023
|
+
void node2._isAsyncPool;
|
|
2024
|
+
void node2._pauseAcquire;
|
|
2025
|
+
void node2._pauseRelease;
|
|
2026
|
+
void node2._onResume;
|
|
2027
|
+
void node2._canFireDemand;
|
|
2028
|
+
void node2._deliverPullDemand;
|
|
2029
|
+
void node2._onDemand;
|
|
2030
|
+
void node2._firePullDemand;
|
|
2031
|
+
void node2._fireOwedDemandIfReady;
|
|
2032
|
+
void node2._shouldBufferOnPause;
|
|
2033
|
+
void node2._invalidate;
|
|
2034
|
+
void node2._allDepsTerminal;
|
|
2035
|
+
void node2._emitToSubs;
|
|
2036
|
+
}
|
|
954
2037
|
constructor(deps, handleOrFn, opts = {}) {
|
|
955
|
-
const core =
|
|
956
|
-
constructingCore = void 0;
|
|
2038
|
+
const core = takeConstructingNodeCore();
|
|
957
2039
|
const dispatcher = opts.dispatcher ?? defaultDispatcher;
|
|
958
|
-
const environment =
|
|
959
|
-
constructingEnvironment = void 0;
|
|
2040
|
+
const environment = takeConstructingEnvironmentDrivers() ?? EnvironmentDrivers.empty();
|
|
960
2041
|
const pool = opts.pool ?? "sync";
|
|
961
2042
|
const pausable = opts.pausable ?? true;
|
|
962
2043
|
const pullLock = opts.pullId;
|
|
@@ -1127,6 +2208,7 @@ var Node = class {
|
|
|
1127
2208
|
runtimeQuiescenceReaders.set(this, () => this._isRuntimeQuiescentForRelease());
|
|
1128
2209
|
subscriberCountReaders.set(this, () => this._subscriberCount());
|
|
1129
2210
|
activationReaders.set(this, () => this._lifecycle.activated);
|
|
2211
|
+
_Node._retainIndirectRuntimeMethods(this);
|
|
1130
2212
|
}
|
|
1131
2213
|
/** R-pull (D55/D272): true while a pull node is not serving a PULL demand pulse. */
|
|
1132
2214
|
_isPullQuiet() {
|
|
@@ -1231,58 +2313,6 @@ var Node = class {
|
|
|
1231
2313
|
exitWave();
|
|
1232
2314
|
}
|
|
1233
2315
|
}
|
|
1234
|
-
// ── deferred self-rewire (R-rewire-deferred / D47): ctx.rewireNext drain support ──
|
|
1235
|
-
/**
|
|
1236
|
-
* Enqueue a deferred self-rewire op (issued from this node's fn via `ctx.rewireNext`).
|
|
1237
|
-
* Applied at the committed wave boundary (boundary.ts drain), never in place — the in-fn
|
|
1238
|
-
* immediate path (`subscribeDep`/`replaceDeps`/`unsubscribeDep`) still throws mid-run (D37/R-reentrancy).
|
|
1239
|
-
*/
|
|
1240
|
-
_requestRewireNext(op) {
|
|
1241
|
-
deferRewire(this._core, () => this._applyRewireNext(op), {
|
|
1242
|
-
batchToken: currentBoundaryBatchToken(),
|
|
1243
|
-
isReady: () => !this._hasBoundaryPauseLock()
|
|
1244
|
-
});
|
|
1245
|
-
}
|
|
1246
|
-
/**
|
|
1247
|
-
* Enqueue a deferred up-going control/demand wave (R-up-routing / R-pull / D269): at the committed wave
|
|
1248
|
-
* boundary, route `msgs` up from THIS node (broadcast, or up the single `towardDep` edge). The
|
|
1249
|
-
* deferred form of `ctx.up` — the SELF-demand path: a consumer issues `ctx.upNext([[PULL,
|
|
1250
|
-
* { pullId }]])` to demand a dep it ALSO reads; the demand applies at the boundary (not mid-fn), so
|
|
1251
|
-
* the pull node's delivery loops back as a FRESH wave rather than re-entering the consumer (D37 /
|
|
1252
|
-
* R-reentrancy). Rides the same R-rewire-deferred (D47) drain as ctx.rewireNext.
|
|
1253
|
-
*/
|
|
1254
|
-
_requestUpNext(msgs, towardDep) {
|
|
1255
|
-
deferRewire(
|
|
1256
|
-
this._core,
|
|
1257
|
-
() => {
|
|
1258
|
-
if (!this._released) this._up(msgs, towardDep);
|
|
1259
|
-
},
|
|
1260
|
-
{
|
|
1261
|
-
batchToken: currentBoundaryBatchToken(),
|
|
1262
|
-
isReady: () => !this._hasBoundaryPauseLock()
|
|
1263
|
-
}
|
|
1264
|
-
);
|
|
1265
|
-
}
|
|
1266
|
-
/** Apply one queued self-rewire at the boundary (drain thunk). */
|
|
1267
|
-
_applyRewireNext(op) {
|
|
1268
|
-
if (this._released) return;
|
|
1269
|
-
try {
|
|
1270
|
-
if (op.kind === "add") {
|
|
1271
|
-
const next = this._slot.deps.includes(op.dep) ? [...this._slot.deps] : [...this._slot.deps, op.dep];
|
|
1272
|
-
this._rewire(next, op.fn, { allowTerminalOwner: true });
|
|
1273
|
-
} else if (op.kind === "remove") {
|
|
1274
|
-
this._rewire(
|
|
1275
|
-
this._slot.deps.filter((d) => d !== op.dep),
|
|
1276
|
-
op.fn,
|
|
1277
|
-
{ allowTerminalOwner: true }
|
|
1278
|
-
);
|
|
1279
|
-
} else {
|
|
1280
|
-
this._rewire(this._dedupDeps(op.deps), op.fn, { allowTerminalOwner: true });
|
|
1281
|
-
}
|
|
1282
|
-
} catch (e) {
|
|
1283
|
-
this._down([["ERROR", errorPayload(e, "rewireNext op failed")]]);
|
|
1284
|
-
}
|
|
1285
|
-
}
|
|
1286
2316
|
// ── rewire (R-rewire / D42): intra-graph runtime topology mutation ──
|
|
1287
2317
|
/**
|
|
1288
2318
|
* Replace this node's deps atomically (surgical, Option-C). Requires an explicit
|
|
@@ -1310,6 +2340,15 @@ var Node = class {
|
|
|
1310
2340
|
fn
|
|
1311
2341
|
);
|
|
1312
2342
|
}
|
|
2343
|
+
_requestRewireNext(op) {
|
|
2344
|
+
nodeRequestRewireNext(nodeRuntimeHost(this), op);
|
|
2345
|
+
}
|
|
2346
|
+
_requestUpNext(msgs, towardDep) {
|
|
2347
|
+
nodeRequestUpNext(nodeRuntimeHost(this), msgs, towardDep);
|
|
2348
|
+
}
|
|
2349
|
+
_applyRewireNext(op) {
|
|
2350
|
+
nodeApplyRewireNext(nodeRuntimeHost(this), op);
|
|
2351
|
+
}
|
|
1313
2352
|
_dedupDeps(deps) {
|
|
1314
2353
|
const seen = /* @__PURE__ */ new Set();
|
|
1315
2354
|
const out = [];
|
|
@@ -1320,7 +2359,6 @@ var Node = class {
|
|
|
1320
2359
|
}
|
|
1321
2360
|
return out;
|
|
1322
2361
|
}
|
|
1323
|
-
/** Is `target` reachable upstream from `from` (following deps)? Cycle-prevention DFS. */
|
|
1324
2362
|
_reachableUpstream(from, target) {
|
|
1325
2363
|
const seen = /* @__PURE__ */ new Set();
|
|
1326
2364
|
const stack = [from];
|
|
@@ -1330,1057 +2368,171 @@ var Node = class {
|
|
|
1330
2368
|
if (n === target) return true;
|
|
1331
2369
|
if (seen.has(n)) continue;
|
|
1332
2370
|
seen.add(n);
|
|
1333
|
-
for (const d of n._slot.deps) stack.push(d);
|
|
2371
|
+
for (const d of nodeRuntimeHost(n)._slot.deps) stack.push(d);
|
|
1334
2372
|
}
|
|
1335
2373
|
return false;
|
|
1336
2374
|
}
|
|
1337
2375
|
_assertRewireDepOwner(dep) {
|
|
1338
2376
|
const selfOwner = getNodeOwner(this);
|
|
1339
2377
|
const depOwner = getNodeOwner(dep);
|
|
1340
|
-
if (selfOwner !== void 0 && depOwner !== void 0 && selfOwner !== depOwner)
|
|
2378
|
+
if (selfOwner !== void 0 && depOwner !== void 0 && selfOwner !== depOwner)
|
|
1341
2379
|
throw new Error(
|
|
1342
2380
|
"rewire: dep belongs to a different graph; cross-graph deps require a wire bridge (D22 / R-graph-domain)"
|
|
1343
2381
|
);
|
|
1344
|
-
}
|
|
1345
2382
|
}
|
|
1346
2383
|
_rewire(newDeps, fn, opts = {}) {
|
|
1347
|
-
|
|
1348
|
-
throw new Error(
|
|
1349
|
-
"rewire: node is terminal (completed/errored) \u2014 cannot rewire (R-rewire / D42)"
|
|
1350
|
-
);
|
|
1351
|
-
if (this._wave.insideRunWave)
|
|
1352
|
-
throw new Error(
|
|
1353
|
-
"rewire: mid-fn topology mutation \u2014 a fn mutating its own deps mid-wave is the feedback cycle (R-rewire / D37)"
|
|
1354
|
-
);
|
|
1355
|
-
if (this._wave.inDepMutation)
|
|
1356
|
-
throw new Error(
|
|
1357
|
-
"rewire: reentrant dep mutation \u2014 another replaceDeps/subscribeDep/unsubscribeDep is in flight (R-rewire)"
|
|
1358
|
-
);
|
|
1359
|
-
if (newDeps.includes(this))
|
|
1360
|
-
throw new Error("rewire: self-dependency rejected (R-rewire / D42)");
|
|
1361
|
-
const oldDeps = this._slot.deps;
|
|
1362
|
-
const added = newDeps.filter((d) => !oldDeps.includes(d));
|
|
1363
|
-
for (const d of added) {
|
|
1364
|
-
if (this._reachableUpstream(d, this))
|
|
1365
|
-
throw new Error(
|
|
1366
|
-
"rewire: would create a cycle \u2014 dep already transitively depends on this node (R-rewire / D42)"
|
|
1367
|
-
);
|
|
1368
|
-
if (d._value.terminal !== void 0 && !d._slot.resubscribable)
|
|
1369
|
-
throw new Error(
|
|
1370
|
-
"rewire: cannot add a non-resubscribable terminal dep \u2014 would wedge (R-rewire / D42)"
|
|
1371
|
-
);
|
|
1372
|
-
this._assertRewireDepOwner(d);
|
|
1373
|
-
}
|
|
1374
|
-
if (deferAfterBatchForTarget(this, () => {
|
|
1375
|
-
this._rewire(newDeps, fn, { ...opts, allowTerminalOwner: true });
|
|
1376
|
-
})) {
|
|
1377
|
-
return true;
|
|
1378
|
-
}
|
|
1379
|
-
if (!this._lifecycle.activated) this._restoredActivationPending = false;
|
|
1380
|
-
this._wave.inDepMutation = true;
|
|
1381
|
-
this._wave.rewireRunPending = false;
|
|
1382
|
-
let zeroDepUnDirty = false;
|
|
1383
|
-
try {
|
|
1384
|
-
const oldHandle = this._slot.handle;
|
|
1385
|
-
this._slot.handle = this._slot.dispatcher.register(fn, this._slot.pool);
|
|
1386
|
-
if (oldHandle !== null) this._slot.dispatcher.unregister(oldHandle);
|
|
1387
|
-
const removed = oldDeps.filter((d) => !newDeps.includes(d));
|
|
1388
|
-
let removedDirtyContributor = false;
|
|
1389
|
-
for (const d of removed) {
|
|
1390
|
-
const oldIdx = oldDeps.indexOf(d);
|
|
1391
|
-
if (this._dep.dirty[oldIdx]) {
|
|
1392
|
-
removedDirtyContributor = true;
|
|
1393
|
-
this._wave.pending--;
|
|
1394
|
-
}
|
|
1395
|
-
if (this._lifecycle.activated) {
|
|
1396
|
-
const box = this._dep.idxBoxes[oldIdx];
|
|
1397
|
-
if (box) box.v = -1;
|
|
1398
|
-
const unsub = this._dep.unsubs[oldIdx];
|
|
1399
|
-
if (unsub) unsub();
|
|
1400
|
-
}
|
|
1401
|
-
}
|
|
1402
|
-
const n = newDeps.length;
|
|
1403
|
-
const newBatch = new Array(n).fill(null);
|
|
1404
|
-
const newPrev = new Array(n).fill(SENTINEL);
|
|
1405
|
-
const newHasData = new Array(n).fill(false);
|
|
1406
|
-
const newDirty = new Array(n).fill(false);
|
|
1407
|
-
const newTier = new Array(n).fill(0);
|
|
1408
|
-
const newTerminal = new Array(n).fill(void 0);
|
|
1409
|
-
const newTerminalInput = new Array(n).fill(void 0);
|
|
1410
|
-
const newUnsubs = new Array(n);
|
|
1411
|
-
const newBoxes = new Array(n);
|
|
1412
|
-
for (let j = 0; j < n; j++) {
|
|
1413
|
-
const oldIdx = oldDeps.indexOf(newDeps[j]);
|
|
1414
|
-
if (oldIdx !== -1) {
|
|
1415
|
-
newBatch[j] = this._dep.batch[oldIdx];
|
|
1416
|
-
newPrev[j] = this._dep.prev[oldIdx];
|
|
1417
|
-
newHasData[j] = this._dep.hasData[oldIdx];
|
|
1418
|
-
newDirty[j] = this._dep.dirty[oldIdx];
|
|
1419
|
-
newTier[j] = this._dep.tier[oldIdx];
|
|
1420
|
-
newTerminal[j] = this._dep.terminal[oldIdx];
|
|
1421
|
-
newUnsubs[j] = this._dep.unsubs[oldIdx];
|
|
1422
|
-
const box = this._dep.idxBoxes[oldIdx];
|
|
1423
|
-
if (box) box.v = j;
|
|
1424
|
-
newBoxes[j] = box;
|
|
1425
|
-
}
|
|
1426
|
-
}
|
|
1427
|
-
this._slot.deps = newDeps;
|
|
1428
|
-
this._dep.batch = newBatch;
|
|
1429
|
-
this._dep.prev = newPrev;
|
|
1430
|
-
this._dep.hasData = newHasData;
|
|
1431
|
-
this._dep.dirty = newDirty;
|
|
1432
|
-
this._dep.tier = newTier;
|
|
1433
|
-
this._dep.terminal = newTerminal;
|
|
1434
|
-
this._dep.terminalInput = newTerminalInput;
|
|
1435
|
-
this._dep.unsubs = newUnsubs;
|
|
1436
|
-
this._dep.idxBoxes = newBoxes;
|
|
1437
|
-
this._dep.waveData = newDeps.map(() => []);
|
|
1438
|
-
this._dep.waveTokens = new Array(newDeps.length).fill(void 0);
|
|
1439
|
-
this._syncCtx = null;
|
|
1440
|
-
if (this._lifecycle.activated) {
|
|
1441
|
-
for (const d of added) this._subscribeDepAt(d);
|
|
1442
|
-
}
|
|
1443
|
-
notifyTopologyDepsChanged(this, oldDeps, newDeps);
|
|
1444
|
-
if (removedDirtyContributor && this._wave.pending === 0 && this._value.status === "dirty") {
|
|
1445
|
-
if (newDeps.length > 0) this._wave.rewireRunPending = true;
|
|
1446
|
-
else zeroDepUnDirty = true;
|
|
1447
|
-
}
|
|
1448
|
-
} finally {
|
|
1449
|
-
this._wave.inDepMutation = false;
|
|
1450
|
-
}
|
|
1451
|
-
if (this._wave.rewireRunPending) {
|
|
1452
|
-
this._wave.rewireRunPending = false;
|
|
1453
|
-
this._settleRewire();
|
|
1454
|
-
} else if (zeroDepUnDirty) {
|
|
1455
|
-
if (this._wave.emittedDirtyThisWave) this._down([["RESOLVED"]]);
|
|
1456
|
-
else this._value.status = this._value.hasData ? "settled" : "sentinel";
|
|
1457
|
-
}
|
|
1458
|
-
return false;
|
|
2384
|
+
return nodeRewire(nodeRuntimeHost(this), newDeps, fn, opts);
|
|
1459
2385
|
}
|
|
1460
2386
|
// ── activation / deactivation (lazy; R-rom-ram) ──
|
|
1461
2387
|
_activate() {
|
|
1462
|
-
this
|
|
1463
|
-
const seedRestoredDeps = this._restoredActivationPending;
|
|
1464
|
-
this._restoredActivationPending = false;
|
|
1465
|
-
this._dep.unsubs = new Array(this._slot.deps.length);
|
|
1466
|
-
this._dep.idxBoxes = new Array(this._slot.deps.length);
|
|
1467
|
-
for (const dep of this._slot.deps)
|
|
1468
|
-
this._subscribeDepAt(dep, { seedRestored: seedRestoredDeps });
|
|
1469
|
-
if (this._slot.deps.length === 0 && this._slot.handle !== null && !this._wave.hasCalledFnOnce) {
|
|
1470
|
-
this._runWave();
|
|
1471
|
-
}
|
|
1472
|
-
}
|
|
1473
|
-
/**
|
|
1474
|
-
* Subscribe to a dep. The dispatch callback reads the dep's CURRENT index from a
|
|
1475
|
-
* mutable box (O(1)); a surgical rewire that reorders kept deps just updates the box
|
|
1476
|
-
* (R-rewire Option-C / D42) — no re-subscribe, no per-message indexOf scan. A removed
|
|
1477
|
-
* dep's box is set to -1 so any stale in-flight callback drops (drain).
|
|
1478
|
-
*/
|
|
1479
|
-
_subscribeDepAt(depNode, opts = {}) {
|
|
1480
|
-
const idx0 = this._slot.deps.indexOf(depNode);
|
|
1481
|
-
const box = { v: idx0 };
|
|
1482
|
-
let ignoreInitialPush = opts.seedRestored === true;
|
|
1483
|
-
if (ignoreInitialPush && idx0 !== -1) {
|
|
1484
|
-
this._seedRestoredDepAt(idx0, depNode);
|
|
1485
|
-
if (depNode._value.terminal !== void 0 && !depNode._slot.resubscribable) {
|
|
1486
|
-
this._dep.unsubs[idx0] = () => {
|
|
1487
|
-
};
|
|
1488
|
-
this._dep.idxBoxes[idx0] = box;
|
|
1489
|
-
return;
|
|
1490
|
-
}
|
|
1491
|
-
}
|
|
1492
|
-
const unsub = depNode.subscribe((msg, delivery) => {
|
|
1493
|
-
if (ignoreInitialPush && delivery === void 0) return;
|
|
1494
|
-
if (ignoreInitialPush) ignoreInitialPush = false;
|
|
1495
|
-
if (box.v === -1) return;
|
|
1496
|
-
this._receiveFromDep(box.v, msg, delivery);
|
|
1497
|
-
});
|
|
1498
|
-
if (ignoreInitialPush && idx0 !== -1 && box.v !== -1) this._seedRestoredDepAt(idx0, depNode);
|
|
1499
|
-
ignoreInitialPush = false;
|
|
1500
|
-
if (idx0 !== -1) {
|
|
1501
|
-
this._dep.unsubs[idx0] = unsub;
|
|
1502
|
-
this._dep.idxBoxes[idx0] = box;
|
|
1503
|
-
}
|
|
1504
|
-
}
|
|
1505
|
-
_seedRestoredDepAt(idx, depNode) {
|
|
1506
|
-
const seedData = depNode._value.hasData && !depNode._slot.pull;
|
|
1507
|
-
this._dep.batch[idx] = null;
|
|
1508
|
-
this._dep.waveData[idx] = [];
|
|
1509
|
-
this._dep.waveTokens[idx] = void 0;
|
|
1510
|
-
this._dep.prev[idx] = seedData ? depNode._value.cache : SENTINEL;
|
|
1511
|
-
this._dep.hasData[idx] = seedData;
|
|
1512
|
-
this._dep.dirty[idx] = false;
|
|
1513
|
-
this._dep.tier[idx] = seedData ? 3 : 0;
|
|
1514
|
-
this._dep.terminal[idx] = depNode._value.terminal;
|
|
1515
|
-
this._dep.terminalInput[idx] = void 0;
|
|
2388
|
+
nodeActivate(nodeRuntimeHost(this));
|
|
1516
2389
|
}
|
|
1517
2390
|
_deactivate() {
|
|
1518
|
-
this
|
|
1519
|
-
for (const u of this._dep.unsubs) if (u) u();
|
|
1520
|
-
this._dep.unsubs = [];
|
|
1521
|
-
this._dep.idxBoxes = [];
|
|
1522
|
-
for (const fn of this._hooks.onDeactivation) fn();
|
|
1523
|
-
this._hooks.onDeactivation = [];
|
|
1524
|
-
this._hooks.onInvalidate = [];
|
|
1525
|
-
const isCompute = this._slot.handle !== null || this._slot.deps.length > 0;
|
|
1526
|
-
if (isCompute) {
|
|
1527
|
-
this._value.cache = SENTINEL;
|
|
1528
|
-
this._value.hasData = false;
|
|
1529
|
-
this._value.status = "sentinel";
|
|
1530
|
-
}
|
|
1531
|
-
this._resetDepState();
|
|
1532
|
-
this._wave.hasCalledFnOnce = false;
|
|
1533
|
-
this._control.pauseLockset.clear();
|
|
1534
|
-
this._control.pauseBuffer = [];
|
|
1535
|
-
this._control.pausedDepWaveOccurred = false;
|
|
1536
|
-
this._control.demandOwed = void 0;
|
|
1537
|
-
this._control.activePull = void 0;
|
|
1538
|
-
this._control.pullDirtyOwed = false;
|
|
1539
|
-
this._value.replayRing = [];
|
|
1540
|
-
if (!this._privateState.persist) this._privateState.value = SENTINEL;
|
|
2391
|
+
nodeDeactivate(nodeRuntimeHost(this));
|
|
1541
2392
|
}
|
|
1542
2393
|
_assertNotReleased(op) {
|
|
1543
2394
|
if (this._released)
|
|
1544
2395
|
throw new Error(`${op}: node has been released from its graph lifecycle (D122)`);
|
|
1545
2396
|
}
|
|
1546
2397
|
_subscriberCount() {
|
|
1547
|
-
return this
|
|
2398
|
+
return nodeSubscriberCount(nodeRuntimeHost(this));
|
|
1548
2399
|
}
|
|
1549
2400
|
_isRuntimeQuiescentForRelease() {
|
|
1550
|
-
return
|
|
2401
|
+
return nodeIsRuntimeQuiescentForRelease(nodeRuntimeHost(this));
|
|
1551
2402
|
}
|
|
1552
2403
|
_releaseRuntime() {
|
|
1553
|
-
|
|
1554
|
-
this._released = true;
|
|
1555
|
-
releasedNodes.add(this);
|
|
1556
|
-
let releaseError;
|
|
1557
|
-
const recordReleaseError = (error) => {
|
|
1558
|
-
if (releaseError === void 0) releaseError = error;
|
|
1559
|
-
};
|
|
1560
|
-
this._lifecycle.activated = false;
|
|
1561
|
-
for (const u of this._dep.unsubs) {
|
|
1562
|
-
try {
|
|
1563
|
-
u();
|
|
1564
|
-
} catch (error) {
|
|
1565
|
-
recordReleaseError(error);
|
|
1566
|
-
}
|
|
1567
|
-
}
|
|
1568
|
-
for (const fn of this._hooks.onDeactivation) {
|
|
1569
|
-
try {
|
|
1570
|
-
fn();
|
|
1571
|
-
} catch (error) {
|
|
1572
|
-
recordReleaseError(error);
|
|
1573
|
-
}
|
|
1574
|
-
}
|
|
1575
|
-
this._dep.unsubs = [];
|
|
1576
|
-
this._dep.idxBoxes = [];
|
|
1577
|
-
this._lifecycle.subscribers.clear();
|
|
1578
|
-
if (this._slot.handle !== null) {
|
|
1579
|
-
this._slot.dispatcher.unregister(this._slot.handle);
|
|
1580
|
-
this._slot.handle = null;
|
|
1581
|
-
}
|
|
1582
|
-
this._slot.deps = [];
|
|
1583
|
-
this._dep.batch = [];
|
|
1584
|
-
this._dep.waveData = [];
|
|
1585
|
-
this._dep.waveTokens = [];
|
|
1586
|
-
this._dep.prev = [];
|
|
1587
|
-
this._dep.hasData = [];
|
|
1588
|
-
this._dep.dirty = [];
|
|
1589
|
-
this._dep.tier = [];
|
|
1590
|
-
this._dep.terminal = [];
|
|
1591
|
-
this._dep.terminalInput = [];
|
|
1592
|
-
this._value.cache = SENTINEL;
|
|
1593
|
-
this._value.hasData = false;
|
|
1594
|
-
this._value.status = "sentinel";
|
|
1595
|
-
this._value.terminal = void 0;
|
|
1596
|
-
this._value.replayRing = [];
|
|
1597
|
-
this._privateState.value = SENTINEL;
|
|
1598
|
-
this._privateState.persist = false;
|
|
1599
|
-
this._syncCtx = null;
|
|
1600
|
-
this._resetDepState();
|
|
1601
|
-
this._hooks.onDeactivation = [];
|
|
1602
|
-
this._hooks.onInvalidate = [];
|
|
1603
|
-
this._control.pauseLockset.clear();
|
|
1604
|
-
this._control.pauseBuffer = [];
|
|
1605
|
-
this._control.pausedDepWaveOccurred = false;
|
|
1606
|
-
this._control.demandOwed = void 0;
|
|
1607
|
-
this._control.activePull = void 0;
|
|
1608
|
-
this._control.pullDirtyOwed = false;
|
|
1609
|
-
this._restoredActivationPending = false;
|
|
1610
|
-
checkpointReaders.delete(this);
|
|
1611
|
-
restoreWriters.delete(this);
|
|
1612
|
-
runtimeReleasers.delete(this);
|
|
1613
|
-
runtimeQuiescenceReaders.delete(this);
|
|
1614
|
-
subscriberCountReaders.delete(this);
|
|
1615
|
-
activationReaders.delete(this);
|
|
1616
|
-
ownerTokens.delete(this);
|
|
1617
|
-
topologyDepsChangedObservers.delete(this);
|
|
1618
|
-
this._core.releaseSlot(this._id);
|
|
1619
|
-
if (releaseError !== void 0) throw releaseError;
|
|
2404
|
+
nodeReleaseRuntime(nodeRuntimeHost(this));
|
|
1620
2405
|
}
|
|
1621
2406
|
_resetDepState() {
|
|
1622
|
-
|
|
1623
|
-
|
|
1624
|
-
|
|
1625
|
-
|
|
1626
|
-
|
|
1627
|
-
|
|
1628
|
-
|
|
1629
|
-
this._dep.dirty[i] = false;
|
|
1630
|
-
this._dep.tier[i] = 0;
|
|
1631
|
-
this._dep.terminal[i] = void 0;
|
|
1632
|
-
this._dep.terminalInput[i] = void 0;
|
|
1633
|
-
}
|
|
1634
|
-
this._wave.pending = 0;
|
|
1635
|
-
this._wave.emittedDirtyThisWave = false;
|
|
2407
|
+
nodeResetDepState(nodeRuntimeHost(this));
|
|
2408
|
+
}
|
|
2409
|
+
_subscribeDepAt(depNode, opts = {}) {
|
|
2410
|
+
nodeSubscribeDepAt(nodeRuntimeHost(this), depNode, opts);
|
|
2411
|
+
}
|
|
2412
|
+
_seedRestoredDepAt(idx, depNode) {
|
|
2413
|
+
nodeSeedRestoredDepAt(nodeRuntimeHost(this), idx, depNode);
|
|
1636
2414
|
}
|
|
1637
|
-
// ── upstream wave receive (two-phase + diamond) ──
|
|
1638
2415
|
_recordDepProjection(idx, delivery) {
|
|
1639
|
-
|
|
1640
|
-
if (this._dep.waveTokens[idx] !== token) {
|
|
1641
|
-
this._dep.waveData[idx].push([]);
|
|
1642
|
-
this._dep.waveTokens[idx] = token;
|
|
1643
|
-
}
|
|
1644
|
-
return this._dep.waveData[idx][this._dep.waveData[idx].length - 1];
|
|
2416
|
+
return nodeRecordDepProjection(nodeRuntimeHost(this), idx, delivery);
|
|
1645
2417
|
}
|
|
1646
2418
|
_depProjectionHasData(idx) {
|
|
1647
|
-
|
|
1648
|
-
return projection?.some((v) => v !== SENTINEL) ?? false;
|
|
2419
|
+
return nodeDepProjectionHasData(nodeRuntimeHost(this), idx);
|
|
1649
2420
|
}
|
|
1650
2421
|
_receiveFromDep(idx, msg, delivery) {
|
|
1651
|
-
|
|
1652
|
-
const t = msg[0];
|
|
1653
|
-
if (t === "START") return;
|
|
1654
|
-
const isLastInDeliveredWave = delivery?.last ?? true;
|
|
1655
|
-
if (this._value.terminal !== void 0) {
|
|
1656
|
-
if (t === "TEARDOWN") this._down([["TEARDOWN"]]);
|
|
1657
|
-
return;
|
|
1658
|
-
}
|
|
1659
|
-
if (t === "INVALIDATE") {
|
|
1660
|
-
const projection = this._recordDepProjection(idx, delivery);
|
|
1661
|
-
projection.push(SENTINEL);
|
|
1662
|
-
if (projection.some((v) => v !== SENTINEL) && isLastInDeliveredWave) this._maybeRun();
|
|
1663
|
-
this._dep.prev[idx] = SENTINEL;
|
|
1664
|
-
this._dep.hasData[idx] = false;
|
|
1665
|
-
this._dep.batch[idx] = null;
|
|
1666
|
-
if (this._dep.dirty[idx]) {
|
|
1667
|
-
this._dep.dirty[idx] = false;
|
|
1668
|
-
this._wave.pending--;
|
|
1669
|
-
}
|
|
1670
|
-
if (this._control.pausedDepWaveOccurred && this._dep.batch.every((b) => b === null)) {
|
|
1671
|
-
this._control.pausedDepWaveOccurred = false;
|
|
1672
|
-
}
|
|
1673
|
-
const hadData = this._value.hasData;
|
|
1674
|
-
this._invalidate();
|
|
1675
|
-
if (this._wave.pending === 0 && this._wave.emittedDirtyThisWave) {
|
|
1676
|
-
if (!hadData) this._down([["RESOLVED"]]);
|
|
1677
|
-
else this._wave.emittedDirtyThisWave = false;
|
|
1678
|
-
}
|
|
1679
|
-
this._fireOwedDemandIfReady();
|
|
1680
|
-
return;
|
|
1681
|
-
}
|
|
1682
|
-
if (isTerminal(t)) {
|
|
1683
|
-
const isError = t === "ERROR";
|
|
1684
|
-
const errPayload = isError ? msg[1] : void 0;
|
|
1685
|
-
this._dep.terminal[idx] = isError ? errPayload : true;
|
|
1686
|
-
this._dep.terminalInput[idx] = isError ? errPayload : true;
|
|
1687
|
-
this._releaseDepDirty(idx);
|
|
1688
|
-
const ranValueBeforeTerminal = this._depProjectionHasData(idx) && isLastInDeliveredWave;
|
|
1689
|
-
if (ranValueBeforeTerminal) this._maybeRun();
|
|
1690
|
-
if (isError && this._slot.errorWhenDepsError) {
|
|
1691
|
-
this._down([["ERROR", errPayload]]);
|
|
1692
|
-
} else if (this._slot.terminalAsRealInput) {
|
|
1693
|
-
if (ranValueBeforeTerminal) {
|
|
1694
|
-
this._fireOwedDemandIfReady();
|
|
1695
|
-
return;
|
|
1696
|
-
}
|
|
1697
|
-
this._maybeRun();
|
|
1698
|
-
} else if (this._slot.completeWhenDepsComplete && this._allDepsTerminal()) {
|
|
1699
|
-
this._down([["COMPLETE"]]);
|
|
1700
|
-
} else {
|
|
1701
|
-
this._settleAfterAbsorbedTerminal();
|
|
1702
|
-
}
|
|
1703
|
-
this._fireOwedDemandIfReady();
|
|
1704
|
-
return;
|
|
1705
|
-
}
|
|
1706
|
-
if (t === "TEARDOWN") {
|
|
1707
|
-
this._down([["TEARDOWN"]]);
|
|
1708
|
-
return;
|
|
1709
|
-
}
|
|
1710
|
-
if (t === "DIRTY") {
|
|
1711
|
-
if (!this._dep.dirty[idx]) {
|
|
1712
|
-
this._dep.dirty[idx] = true;
|
|
1713
|
-
this._wave.pending++;
|
|
1714
|
-
this._dep.tier[idx] = 2;
|
|
1715
|
-
this._markDirty();
|
|
1716
|
-
}
|
|
1717
|
-
return;
|
|
1718
|
-
}
|
|
1719
|
-
if (t === "DATA") {
|
|
1720
|
-
const v = msg[1];
|
|
1721
|
-
this._recordDepProjection(idx, delivery).push(v);
|
|
1722
|
-
const b = this._dep.batch[idx];
|
|
1723
|
-
if (b === null) this._dep.batch[idx] = [v];
|
|
1724
|
-
else b.push(v);
|
|
1725
|
-
this._dep.prev[idx] = v;
|
|
1726
|
-
this._dep.hasData[idx] = true;
|
|
1727
|
-
this._dep.tier[idx] = 3;
|
|
1728
|
-
if (this._dep.dirty[idx]) {
|
|
1729
|
-
this._dep.dirty[idx] = false;
|
|
1730
|
-
this._wave.pending--;
|
|
1731
|
-
}
|
|
1732
|
-
if (isLastInDeliveredWave) this._maybeRun();
|
|
1733
|
-
this._fireOwedDemandIfReady();
|
|
1734
|
-
return;
|
|
1735
|
-
}
|
|
1736
|
-
if (t === "RESOLVED") {
|
|
1737
|
-
this._recordDepProjection(idx, delivery);
|
|
1738
|
-
this._dep.tier[idx] = 3;
|
|
1739
|
-
if (this._dep.dirty[idx]) {
|
|
1740
|
-
this._dep.dirty[idx] = false;
|
|
1741
|
-
this._wave.pending--;
|
|
1742
|
-
}
|
|
1743
|
-
if (isLastInDeliveredWave) this._maybeRun();
|
|
1744
|
-
this._fireOwedDemandIfReady();
|
|
1745
|
-
return;
|
|
1746
|
-
}
|
|
2422
|
+
nodeReceiveFromDep(nodeRuntimeHost(this), idx, msg, delivery);
|
|
1747
2423
|
}
|
|
1748
|
-
/**
|
|
1749
|
-
* R-terminal-settles-dirty (B35): release a dep's outstanding in-wave DIRTY contribution.
|
|
1750
|
-
* A settle-class event for that dep (DATA/RESOLVED inline above, INVALIDATE, and now
|
|
1751
|
-
* COMPLETE/ERROR) clears its dirty flag + decrements _pending. No-op if the dep already
|
|
1752
|
-
* settled this wave (DATA/RESOLVED ran first) — so the normal DATA-then-COMPLETE flow is
|
|
1753
|
-
* unaffected. This makes the exactly-one-settle invariant a single, shared step.
|
|
1754
|
-
*/
|
|
1755
2424
|
_releaseDepDirty(idx) {
|
|
1756
|
-
|
|
1757
|
-
this._dep.dirty[idx] = false;
|
|
1758
|
-
this._wave.pending--;
|
|
1759
|
-
}
|
|
2425
|
+
nodeReleaseDepDirty(nodeRuntimeHost(this), idx);
|
|
1760
2426
|
}
|
|
1761
|
-
/**
|
|
1762
|
-
* R-terminal-settles-dirty (B35): settle a node whose dirtied dep was released by an ABSORBED
|
|
1763
|
-
* terminal that is NOT a real input (a plain derived/effect — the common default-node case when
|
|
1764
|
-
* one of several deps completes while others stay live). Runs only when the release drained
|
|
1765
|
-
* _pending while the node still owes a downstream settle (it broadcast DIRTY this wave):
|
|
1766
|
-
* - if some OTHER dep delivered real DATA this wave (a value occurred) → recompute (→ DATA);
|
|
1767
|
-
* - else the terminal's signalled change did not materialise (no value) → one undirty RESOLVED
|
|
1768
|
-
* (R-resolved-undirty), keeping the cache (a terminal, unlike INVALIDATE, leaves the value).
|
|
1769
|
-
* A terminalAsRealInput node instead recomputes unconditionally (its fn reads the terminal).
|
|
1770
|
-
*/
|
|
1771
2427
|
_settleAfterAbsorbedTerminal() {
|
|
1772
|
-
|
|
1773
|
-
const sawData = this._dep.batch.some((b) => b !== null && b.length > 0);
|
|
1774
|
-
if (sawData) this._maybeRun();
|
|
1775
|
-
if (this._wave.emittedDirtyThisWave) this._down([["RESOLVED"]]);
|
|
2428
|
+
nodeSettleAfterAbsorbedTerminal(nodeRuntimeHost(this));
|
|
1776
2429
|
}
|
|
1777
2430
|
_markDirty() {
|
|
1778
|
-
this
|
|
1779
|
-
if (this._isPullQuiet()) return;
|
|
1780
|
-
if (!this._wave.emittedDirtyThisWave) {
|
|
1781
|
-
this._wave.emittedDirtyThisWave = true;
|
|
1782
|
-
this._emitToSubs(["DIRTY"]);
|
|
1783
|
-
}
|
|
2431
|
+
nodeMarkDirty(nodeRuntimeHost(this));
|
|
1784
2432
|
}
|
|
1785
2433
|
_maybeRun() {
|
|
1786
|
-
|
|
1787
|
-
this._wave.rewireRunPending = true;
|
|
1788
|
-
return;
|
|
1789
|
-
}
|
|
1790
|
-
if (this._slot.pausable === true && (this._isPaused() || this._isPullQuiet())) {
|
|
1791
|
-
this._control.pausedDepWaveOccurred = true;
|
|
1792
|
-
return;
|
|
1793
|
-
}
|
|
1794
|
-
this._tryRun();
|
|
2434
|
+
nodeMaybeRun(nodeRuntimeHost(this));
|
|
1795
2435
|
}
|
|
1796
|
-
/**
|
|
1797
|
-
* R-rewire atomic settle (after a rewire that warrants a recompute): emit a proper
|
|
1798
|
-
* two-phase DIRTY→DATA wave (R-dirty-before-data — a rewire-triggered settle is a wave),
|
|
1799
|
-
* once, with every added dep already wired. Mirrors _maybeRun/_tryRun's pause + gate +
|
|
1800
|
-
* pending guards, then injects the phase-1 DIRTY the added dep's [START,DATA] handshake
|
|
1801
|
-
* did not carry.
|
|
1802
|
-
*/
|
|
1803
2436
|
_settleRewire() {
|
|
1804
|
-
|
|
1805
|
-
this._control.pausedDepWaveOccurred = true;
|
|
1806
|
-
return;
|
|
1807
|
-
}
|
|
1808
|
-
if (this._wave.pending > 0) return;
|
|
1809
|
-
if (this._slot.handle === null) {
|
|
1810
|
-
this._passthroughEmit();
|
|
1811
|
-
return;
|
|
1812
|
-
}
|
|
1813
|
-
if (!this._wave.hasCalledFnOnce && !(this._slot.partial || this._allDepsSettled())) return;
|
|
1814
|
-
this._markDirty();
|
|
1815
|
-
this._runWave();
|
|
2437
|
+
nodeSettleRewire(nodeRuntimeHost(this));
|
|
1816
2438
|
}
|
|
1817
2439
|
_tryRun() {
|
|
1818
|
-
|
|
1819
|
-
if (this._slot.handle === null) {
|
|
1820
|
-
this._passthroughEmit();
|
|
1821
|
-
return;
|
|
1822
|
-
}
|
|
1823
|
-
if (!this._wave.hasCalledFnOnce) {
|
|
1824
|
-
if (this._slot.partial || this._allDepsSettled()) this._runWave();
|
|
1825
|
-
return;
|
|
1826
|
-
}
|
|
1827
|
-
this._runWave();
|
|
2440
|
+
nodeTryRun(nodeRuntimeHost(this));
|
|
1828
2441
|
}
|
|
1829
2442
|
_allDepsSettled() {
|
|
1830
|
-
|
|
1831
|
-
if (this._dep.hasData[i]) continue;
|
|
1832
|
-
if (this._slot.terminalAsRealInput && this._dep.terminal[i] !== void 0) continue;
|
|
1833
|
-
return false;
|
|
1834
|
-
}
|
|
1835
|
-
return true;
|
|
2443
|
+
return nodeAllDepsSettled(nodeRuntimeHost(this));
|
|
1836
2444
|
}
|
|
1837
2445
|
_passthroughEmit() {
|
|
1838
|
-
|
|
1839
|
-
if (b !== null && b.length > 0) {
|
|
1840
|
-
this._down([["DATA", b[b.length - 1]]]);
|
|
1841
|
-
} else if (this._wave.emittedDirtyThisWave) {
|
|
1842
|
-
this._down([["RESOLVED"]]);
|
|
1843
|
-
}
|
|
1844
|
-
this._dep.batch[0] = null;
|
|
1845
|
-
this._wave.emittedDirtyThisWave = false;
|
|
2446
|
+
nodePassthroughEmit(nodeRuntimeHost(this));
|
|
1846
2447
|
}
|
|
1847
2448
|
_runWave() {
|
|
1848
|
-
|
|
1849
|
-
throw new Error(
|
|
1850
|
-
"synchronous feedback cycle: node fn re-entered its own wave (R-reentrancy / D37)"
|
|
1851
|
-
);
|
|
1852
|
-
this._wave.hasCalledFnOnce = true;
|
|
1853
|
-
this._hooks.onInvalidate = [];
|
|
1854
|
-
this._hooks.onDeactivation = [];
|
|
1855
|
-
const ctx = this._buildCtx();
|
|
1856
|
-
const wasDirty = this._wave.emittedDirtyThisWave;
|
|
1857
|
-
this._wave.emittedSettleThisWave = false;
|
|
1858
|
-
this._wave.insideRunWave = true;
|
|
1859
|
-
try {
|
|
1860
|
-
this._slot.dispatcher.invoke(this._slot.handle, ctx);
|
|
1861
|
-
} finally {
|
|
1862
|
-
this._wave.insideRunWave = false;
|
|
1863
|
-
}
|
|
1864
|
-
if (wasDirty && !this._wave.emittedSettleThisWave && this._value.terminal === void 0 && !this._isAsyncPool()) {
|
|
1865
|
-
this._down([["RESOLVED"]]);
|
|
1866
|
-
}
|
|
1867
|
-
for (let i = 0; i < this._dep.batch.length; i++) {
|
|
1868
|
-
this._dep.batch[i] = null;
|
|
1869
|
-
this._dep.waveData[i] = [];
|
|
1870
|
-
this._dep.waveTokens[i] = void 0;
|
|
1871
|
-
this._dep.terminalInput[i] = void 0;
|
|
1872
|
-
}
|
|
1873
|
-
this._wave.emittedDirtyThisWave = false;
|
|
2449
|
+
nodeRunWave(nodeRuntimeHost(this));
|
|
1874
2450
|
}
|
|
1875
|
-
// ── ctx construction (L3-Q5: sync = node-stable reused ctx; async = per-invocation) ──
|
|
1876
2451
|
_buildCtx() {
|
|
1877
|
-
|
|
1878
|
-
if (kind === "sync") {
|
|
1879
|
-
if (this._syncCtx === null) this._syncCtx = this._makeCtx();
|
|
1880
|
-
this._refreshCtx(this._syncCtx);
|
|
1881
|
-
return this._syncCtx;
|
|
1882
|
-
}
|
|
1883
|
-
return this._makeCtx({
|
|
1884
|
-
waveData: this._dep.waveData.map((waves) => waves.map((w) => [...w])),
|
|
1885
|
-
terminal: this._dep.terminalInput.map(terminalView),
|
|
1886
|
-
latest: [...this._dep.prev]
|
|
1887
|
-
});
|
|
2452
|
+
return nodeBuildCtx(nodeRuntimeHost(this));
|
|
1888
2453
|
}
|
|
1889
2454
|
_makeCtx(snapshot) {
|
|
1890
|
-
|
|
1891
|
-
// Wave-owner boundary (D47): a SYNC fn's emit nests under the public entry that drove
|
|
1892
|
-
// it (cheap inc/dec, no early drain); an ASYNC-pool fn re-enters here from its stashed
|
|
1893
|
-
// ctx at depth 0, so this is the boundary that drains any rewireNext it issued.
|
|
1894
|
-
up: (msgs, towardDep) => {
|
|
1895
|
-
if (this._released) return;
|
|
1896
|
-
enterWave();
|
|
1897
|
-
try {
|
|
1898
|
-
this._up(msgs, towardDep);
|
|
1899
|
-
} finally {
|
|
1900
|
-
exitWave();
|
|
1901
|
-
}
|
|
1902
|
-
},
|
|
1903
|
-
down: (msgs) => {
|
|
1904
|
-
if (this._released) return;
|
|
1905
|
-
enterWave();
|
|
1906
|
-
try {
|
|
1907
|
-
this._down(msgs);
|
|
1908
|
-
} finally {
|
|
1909
|
-
exitWave();
|
|
1910
|
-
}
|
|
1911
|
-
},
|
|
1912
|
-
waveData: snapshot?.waveData ?? this._dep.waveData,
|
|
1913
|
-
terminal: snapshot?.terminal ?? this._dep.terminalInput.map(terminalView),
|
|
1914
|
-
state: this._makeState(),
|
|
1915
|
-
onDeactivation: (fn) => {
|
|
1916
|
-
if (this._released) return;
|
|
1917
|
-
this._hooks.onDeactivation.push(fn);
|
|
1918
|
-
},
|
|
1919
|
-
onInvalidate: (fn) => {
|
|
1920
|
-
if (this._released) return;
|
|
1921
|
-
this._hooks.onInvalidate.push(fn);
|
|
1922
|
-
},
|
|
1923
|
-
environment: () => this._slot.environment,
|
|
1924
|
-
// R-rewire-deferred (D47): defer a self-dep-set mutation to the committed boundary.
|
|
1925
|
-
rewireNext: {
|
|
1926
|
-
subscribeDep: (dep, fn) => this._requestRewireNext({ kind: "add", dep, fn }),
|
|
1927
|
-
unsubscribeDep: (dep, fn) => this._requestRewireNext({ kind: "remove", dep, fn }),
|
|
1928
|
-
replaceDeps: (deps, fn) => this._requestRewireNext({ kind: "set", deps, fn })
|
|
1929
|
-
},
|
|
1930
|
-
// R-up-routing / R-pull (D269): deferred up — route a control/demand wave (e.g. PULL)
|
|
1931
|
-
// up the declared cone at the committed boundary. The SELF-demand path: an
|
|
1932
|
-
// immediate ctx.up whose delivery loops back re-enters this fn (D37 / R-reentrancy).
|
|
1933
|
-
upNext: (msgs, towardDep) => this._requestUpNext(msgs, towardDep),
|
|
1934
|
-
...this._control.activePull === void 0 ? {} : { pull: this._control.activePull },
|
|
1935
|
-
[CTX_DEP_CACHE]: { latest: snapshot?.latest ?? this._dep.prev },
|
|
1936
|
-
[CTX_NODE_BINDING]: {
|
|
1937
|
-
dispatcher: this._slot.dispatcher,
|
|
1938
|
-
create: (factory) => withEnvironmentDrivers(this._slot.environment, () => withNodeCore(this._core, factory))
|
|
1939
|
-
}
|
|
1940
|
-
};
|
|
1941
|
-
if (this._slot.dynamic) {
|
|
1942
|
-
ctx.track = (i) => ctx[CTX_DEP_CACHE]?.latest[i];
|
|
1943
|
-
}
|
|
1944
|
-
return ctx;
|
|
2455
|
+
return nodeMakeCtx(nodeRuntimeHost(this), snapshot);
|
|
1945
2456
|
}
|
|
1946
2457
|
_refreshCtx(ctx) {
|
|
1947
|
-
ctx
|
|
1948
|
-
ctx.terminal = this._dep.terminalInput.map(terminalView);
|
|
1949
|
-
if (this._control.activePull === void 0) {
|
|
1950
|
-
delete ctx.pull;
|
|
1951
|
-
} else {
|
|
1952
|
-
ctx.pull = this._control.activePull;
|
|
1953
|
-
}
|
|
1954
|
-
ctx[CTX_DEP_CACHE] = { latest: this._dep.prev };
|
|
2458
|
+
nodeRefreshCtx(nodeRuntimeHost(this), ctx);
|
|
1955
2459
|
}
|
|
1956
2460
|
_makeState() {
|
|
1957
|
-
return
|
|
1958
|
-
get: () => this._privateState.value,
|
|
1959
|
-
set: (v) => {
|
|
1960
|
-
this._privateState.value = v;
|
|
1961
|
-
},
|
|
1962
|
-
persist: (on = true) => {
|
|
1963
|
-
this._privateState.persist = on;
|
|
1964
|
-
}
|
|
1965
|
-
};
|
|
2461
|
+
return nodeMakeState(nodeRuntimeHost(this));
|
|
1966
2462
|
}
|
|
1967
2463
|
// ── downstream emission pipeline (the unified waist) ──
|
|
1968
2464
|
_down(msgs) {
|
|
1969
|
-
|
|
1970
|
-
validateDownPayloads(msgs);
|
|
1971
|
-
const deliveryWave = {};
|
|
1972
|
-
const assertVersionDataCompatible = (wave) => {
|
|
1973
|
-
for (const m of wave) {
|
|
1974
|
-
if (m[0] === "DATA") assertNodeVersionDataCompatible(this._version.policy, m[1]);
|
|
1975
|
-
}
|
|
1976
|
-
};
|
|
1977
|
-
const snapshotVersionData = (wave) => wave.map(
|
|
1978
|
-
(m) => m[0] === "DATA" ? ["DATA", snapshotNodeVersionData(this._version.policy, m[1])] : m
|
|
1979
|
-
);
|
|
1980
|
-
assertVersionDataCompatible(msgs);
|
|
1981
|
-
if (this._value.terminal !== void 0) {
|
|
1982
|
-
if (!msgs.some((m) => m[0] === "TEARDOWN")) return;
|
|
1983
|
-
this._value.hasTorndown = true;
|
|
1984
|
-
if (this._slot.resetOnTeardown) {
|
|
1985
|
-
this._value.cache = SENTINEL;
|
|
1986
|
-
this._value.hasData = false;
|
|
1987
|
-
}
|
|
1988
|
-
this._emitToSubs(["TEARDOWN"], { wave: deliveryWave, last: true });
|
|
1989
|
-
return;
|
|
1990
|
-
}
|
|
1991
|
-
let sorted = [...msgs].sort((a, b) => messageTier(a[0]) - messageTier(b[0]));
|
|
1992
|
-
const firstInvalidate = sorted.findIndex((m) => m[0] === "INVALIDATE");
|
|
1993
|
-
if (firstInvalidate !== -1) {
|
|
1994
|
-
sorted = sorted.filter((m, i) => m[0] !== "INVALIDATE" || i === firstInvalidate);
|
|
1995
|
-
}
|
|
1996
|
-
const hasTeardown = sorted.some((m) => m[0] === "TEARDOWN");
|
|
1997
|
-
const hasTerminal = sorted.some((m) => m[0] === "COMPLETE" || m[0] === "ERROR");
|
|
1998
|
-
if (hasTeardown && !hasTerminal && this._value.terminal === void 0 && !this._value.hasTorndown) {
|
|
1999
|
-
sorted = [["COMPLETE"], ...sorted];
|
|
2000
|
-
}
|
|
2001
|
-
if (!this._wave.insideRunWave && currentBatch()) {
|
|
2002
|
-
const deferred = snapshotVersionData(sorted.filter((m) => isDeferredTier(m[0])));
|
|
2003
|
-
if (deferred.length > 0) {
|
|
2004
|
-
if (!this._wave.emittedDirtyThisWave) {
|
|
2005
|
-
this._wave.emittedDirtyThisWave = true;
|
|
2006
|
-
this._value.status = "dirty";
|
|
2007
|
-
this._emitToSubs(["DIRTY"], { wave: deliveryWave, last: false });
|
|
2008
|
-
}
|
|
2009
|
-
this._wave.batchDirtyOwed = true;
|
|
2010
|
-
deferToBatch(this, deferred);
|
|
2011
|
-
return;
|
|
2012
|
-
}
|
|
2013
|
-
}
|
|
2014
|
-
if (this._shouldBufferOnPause()) {
|
|
2015
|
-
const buffered = snapshotVersionData(sorted.filter((m) => isPauseBufferedTier(m[0])));
|
|
2016
|
-
if (buffered.length > 0) {
|
|
2017
|
-
this._wave.emittedSettleThisWave = true;
|
|
2018
|
-
this._control.pauseBuffer.push(buffered);
|
|
2019
|
-
}
|
|
2020
|
-
sorted = sorted.filter((m) => !isPauseBufferedTier(m[0]));
|
|
2021
|
-
if (sorted.length === 0) return;
|
|
2022
|
-
}
|
|
2023
|
-
let dataCount = 0;
|
|
2024
|
-
let hasTier3 = false;
|
|
2025
|
-
let hasResolved = false;
|
|
2026
|
-
for (const m of sorted) {
|
|
2027
|
-
if (m[0] === "DATA") dataCount++;
|
|
2028
|
-
if (m[0] === "RESOLVED") hasResolved = true;
|
|
2029
|
-
if (isValueTier(m[0])) hasTier3 = true;
|
|
2030
|
-
}
|
|
2031
|
-
if (dataCount >= 1 && hasResolved) {
|
|
2032
|
-
throw new Error(
|
|
2033
|
-
"down: a wave cannot mix DATA and RESOLVED (tier-3 exclusivity, R-resolved-undirty)"
|
|
2034
|
-
);
|
|
2035
|
-
}
|
|
2036
|
-
const plannedVersions = new Array(sorted.length);
|
|
2037
|
-
if (dataCount > 0) {
|
|
2038
|
-
let plannedVersion = this._version.value;
|
|
2039
|
-
for (let i = 0; i < sorted.length; i++) {
|
|
2040
|
-
const m = sorted[i];
|
|
2041
|
-
if (m[0] !== "DATA") continue;
|
|
2042
|
-
plannedVersion = advanceNodeVersion(plannedVersion, this._version.policy, m[1]);
|
|
2043
|
-
plannedVersions[i] = plannedVersion;
|
|
2044
|
-
}
|
|
2045
|
-
}
|
|
2046
|
-
if (hasTier3 && (!this._wave.insideRunWave || this._control.pullDirtyOwed) && !this._wave.emittedDirtyThisWave) {
|
|
2047
|
-
this._wave.emittedDirtyThisWave = true;
|
|
2048
|
-
this._value.status = "dirty";
|
|
2049
|
-
this._emitToSubs(["DIRTY"], { wave: deliveryWave, last: false });
|
|
2050
|
-
}
|
|
2051
|
-
for (let i = 0; i < sorted.length; i++) {
|
|
2052
|
-
const m = sorted[i];
|
|
2053
|
-
const delivery = { wave: deliveryWave, last: i === sorted.length - 1 };
|
|
2054
|
-
if (isDeferredTier(m[0])) this._wave.emittedSettleThisWave = true;
|
|
2055
|
-
if (m[0] === "DIRTY") {
|
|
2056
|
-
if (!this._wave.emittedDirtyThisWave) {
|
|
2057
|
-
this._wave.emittedDirtyThisWave = true;
|
|
2058
|
-
this._value.status = "dirty";
|
|
2059
|
-
this._emitToSubs(["DIRTY"], delivery);
|
|
2060
|
-
}
|
|
2061
|
-
continue;
|
|
2062
|
-
}
|
|
2063
|
-
if (m[0] === "DATA") {
|
|
2064
|
-
const v = m[1];
|
|
2065
|
-
this._value.cache = v;
|
|
2066
|
-
this._value.hasData = true;
|
|
2067
|
-
this._value.status = "settled";
|
|
2068
|
-
this._version.value = plannedVersions[i];
|
|
2069
|
-
if (this._slot.replayN > 0) {
|
|
2070
|
-
this._value.replayRing.push(v);
|
|
2071
|
-
if (this._value.replayRing.length > this._slot.replayN) this._value.replayRing.shift();
|
|
2072
|
-
}
|
|
2073
|
-
this._emitToSubs(["DATA", v], delivery);
|
|
2074
|
-
continue;
|
|
2075
|
-
}
|
|
2076
|
-
if (m[0] === "RESOLVED") {
|
|
2077
|
-
this._value.status = this._value.hasData ? "resolved" : "sentinel";
|
|
2078
|
-
this._emitToSubs(["RESOLVED"], delivery);
|
|
2079
|
-
continue;
|
|
2080
|
-
}
|
|
2081
|
-
if (m[0] === "INVALIDATE") {
|
|
2082
|
-
this._invalidate(delivery);
|
|
2083
|
-
continue;
|
|
2084
|
-
}
|
|
2085
|
-
if (m[0] === "COMPLETE") {
|
|
2086
|
-
if (this._value.terminal !== void 0) continue;
|
|
2087
|
-
this._value.terminal = true;
|
|
2088
|
-
this._control.pauseBuffer = [];
|
|
2089
|
-
this._value.status = "completed";
|
|
2090
|
-
this._emitToSubs(["COMPLETE"], delivery);
|
|
2091
|
-
continue;
|
|
2092
|
-
}
|
|
2093
|
-
if (m[0] === "ERROR") {
|
|
2094
|
-
if (this._value.terminal !== void 0) continue;
|
|
2095
|
-
this._value.terminal = m[1];
|
|
2096
|
-
this._control.pauseBuffer = [];
|
|
2097
|
-
this._value.status = "errored";
|
|
2098
|
-
this._emitToSubs(["ERROR", m[1]], delivery);
|
|
2099
|
-
continue;
|
|
2100
|
-
}
|
|
2101
|
-
if (m[0] === "TEARDOWN") {
|
|
2102
|
-
this._value.hasTorndown = true;
|
|
2103
|
-
if (this._slot.resetOnTeardown) {
|
|
2104
|
-
this._value.cache = SENTINEL;
|
|
2105
|
-
this._value.hasData = false;
|
|
2106
|
-
}
|
|
2107
|
-
this._emitToSubs(["TEARDOWN"], delivery);
|
|
2108
|
-
}
|
|
2109
|
-
}
|
|
2110
|
-
if (!this._wave.insideRunWave) this._wave.emittedDirtyThisWave = false;
|
|
2465
|
+
nodeDown(nodeRuntimeHost(this), msgs);
|
|
2111
2466
|
}
|
|
2112
2467
|
_up(msgs, towardDep, route) {
|
|
2113
|
-
|
|
2114
|
-
const routeState = route ?? { demandFired: /* @__PURE__ */ new Map() };
|
|
2115
|
-
for (const m of msgs) {
|
|
2116
|
-
if (!isUpAllowed(m[0])) {
|
|
2117
|
-
throw new Error(
|
|
2118
|
-
`ctx.up: ${m[0]} is down-only (tier ${messageTier(m[0])}); up carries control tiers only (R-ctx-up)`
|
|
2119
|
-
);
|
|
2120
|
-
}
|
|
2121
|
-
}
|
|
2122
|
-
for (const m of msgs) {
|
|
2123
|
-
if (m[0] === "PAUSE") {
|
|
2124
|
-
this._pauseAcquire(m[1]);
|
|
2125
|
-
} else if (m[0] === "RESUME") {
|
|
2126
|
-
if (this._control.pauseLockset.has(m[1])) {
|
|
2127
|
-
this._pauseRelease(m[1]);
|
|
2128
|
-
} else {
|
|
2129
|
-
this._forwardUp(m, towardDep, routeState);
|
|
2130
|
-
}
|
|
2131
|
-
} else if (m[0] === "PULL") {
|
|
2132
|
-
const demand = normalizePullDemand(m[1]);
|
|
2133
|
-
if (this._slot.pull && demand.pullId === this._slot.pullLock) {
|
|
2134
|
-
if (!this._markDemandRouted(demand.pullId, routeState)) this._onDemand(demand);
|
|
2135
|
-
} else {
|
|
2136
|
-
this._forwardUp(["PULL", demand], towardDep, routeState);
|
|
2137
|
-
}
|
|
2138
|
-
} else if (this._slot.deps.length === 0) {
|
|
2139
|
-
if (m[0] === "INVALIDATE") this._down([["INVALIDATE"]]);
|
|
2140
|
-
} else {
|
|
2141
|
-
this._forwardUp(m, towardDep, routeState);
|
|
2142
|
-
}
|
|
2143
|
-
}
|
|
2468
|
+
nodeUp(nodeRuntimeHost(this), msgs, towardDep, route);
|
|
2144
2469
|
}
|
|
2145
2470
|
_markDemandRouted(lockId, route) {
|
|
2146
|
-
|
|
2147
|
-
if (holders === void 0) {
|
|
2148
|
-
holders = /* @__PURE__ */ new Set();
|
|
2149
|
-
route.demandFired.set(lockId, holders);
|
|
2150
|
-
}
|
|
2151
|
-
if (holders.has(this)) return true;
|
|
2152
|
-
holders.add(this);
|
|
2153
|
-
return false;
|
|
2471
|
+
return nodeMarkDemandRouted(nodeRuntimeHost(this), lockId, route);
|
|
2154
2472
|
}
|
|
2155
|
-
/**
|
|
2156
|
-
* Forward one up-going control message toward deps (R-up-routing): up the single declared edge
|
|
2157
|
-
* `towardDep` (directed — prunes other branches; only meaningful on the issuer's FIRST hop) or
|
|
2158
|
-
* broadcast up ALL deps. A depless source has no deps → the message DROPS here (the terminus —
|
|
2159
|
-
* e.g. a cone-routed PULL whose pullId no node up this cone holds, R-up-at-source). Recursive
|
|
2160
|
-
* forwarding carries the same per-wave route state and no `towardDep` → broadcast beyond the
|
|
2161
|
-
* first hop.
|
|
2162
|
-
*/
|
|
2163
2473
|
_forwardUp(m, towardDep, route) {
|
|
2164
|
-
|
|
2165
|
-
if (towardDep !== void 0) {
|
|
2166
|
-
const d = this._slot.deps[towardDep];
|
|
2167
|
-
if (d !== void 0) d._up([m], void 0, route);
|
|
2168
|
-
} else {
|
|
2169
|
-
for (const dep of this._slot.deps) dep._up([m], void 0, route);
|
|
2170
|
-
}
|
|
2474
|
+
nodeForwardUp(nodeRuntimeHost(this), m, towardDep, route);
|
|
2171
2475
|
}
|
|
2172
|
-
// ── PAUSE/RESUME lockset (R-pause-lockset) + modes (R-pause-modes) ──
|
|
2173
2476
|
_isPaused() {
|
|
2174
|
-
return this
|
|
2477
|
+
return nodeIsPaused(nodeRuntimeHost(this));
|
|
2175
2478
|
}
|
|
2176
2479
|
_hasBoundaryPauseLock() {
|
|
2177
|
-
|
|
2178
|
-
return this._control.pauseLockset.size > 0;
|
|
2480
|
+
return nodeHasBoundaryPauseLock(nodeRuntimeHost(this));
|
|
2179
2481
|
}
|
|
2180
2482
|
_isAsyncPool() {
|
|
2181
|
-
return
|
|
2483
|
+
return nodeIsAsyncPool(nodeRuntimeHost(this));
|
|
2182
2484
|
}
|
|
2183
2485
|
_pauseAcquire(lockId) {
|
|
2184
|
-
this
|
|
2486
|
+
nodePauseAcquire(nodeRuntimeHost(this), lockId);
|
|
2185
2487
|
}
|
|
2186
2488
|
_pauseRelease(lockId) {
|
|
2187
|
-
|
|
2188
|
-
this._control.pauseLockset.delete(lockId);
|
|
2189
|
-
if (this._slot.pull && this._control.demandOwed !== void 0) this._fireOwedDemandIfReady();
|
|
2190
|
-
if (this._hasBoundaryPauseLock()) return;
|
|
2191
|
-
scheduleBoundaryDrain(this._core);
|
|
2192
|
-
if (this._slot.pull) return;
|
|
2193
|
-
this._onResume();
|
|
2489
|
+
nodePauseRelease(nodeRuntimeHost(this), lockId);
|
|
2194
2490
|
}
|
|
2195
2491
|
_onResume() {
|
|
2196
|
-
|
|
2197
|
-
this._control.pauseBuffer = [];
|
|
2198
|
-
this._control.pausedDepWaveOccurred = false;
|
|
2199
|
-
this._control.demandOwed = void 0;
|
|
2200
|
-
this._control.activePull = void 0;
|
|
2201
|
-
this._control.pullDirtyOwed = false;
|
|
2202
|
-
return;
|
|
2203
|
-
}
|
|
2204
|
-
if (this._control.pauseBuffer.length > 0) {
|
|
2205
|
-
const buf = this._control.pauseBuffer;
|
|
2206
|
-
this._control.pauseBuffer = [];
|
|
2207
|
-
for (const wave of buf) this._down(wave);
|
|
2208
|
-
}
|
|
2209
|
-
if (this._control.pausedDepWaveOccurred) {
|
|
2210
|
-
this._control.pausedDepWaveOccurred = false;
|
|
2211
|
-
this._tryRun();
|
|
2212
|
-
}
|
|
2492
|
+
nodeOnResume(nodeRuntimeHost(this));
|
|
2213
2493
|
}
|
|
2214
|
-
/**
|
|
2215
|
-
* R-pull (D269): can this pull node fire a demand NOW? — not terminal, settle-ready (_pending===0),
|
|
2216
|
-
* and no OTHER (non-pullId) lock holds it paused. The gate that decides fire-now vs OWE.
|
|
2217
|
-
*/
|
|
2218
2494
|
_canFireDemand() {
|
|
2219
|
-
|
|
2220
|
-
return this._control.pauseLockset.size === 0;
|
|
2495
|
+
return nodeCanFireDemand(nodeRuntimeHost(this));
|
|
2221
2496
|
}
|
|
2222
|
-
/**
|
|
2223
|
-
* R-pull (D269/D272): deliver ONE demand pulse — install activePull so the demand wave may
|
|
2224
|
-
* emit, fire it, then clear activePull so the node is quiet again (1:1).
|
|
2225
|
-
*/
|
|
2226
2497
|
_deliverPullDemand(demand) {
|
|
2227
|
-
this
|
|
2228
|
-
this._control.activePull = demand;
|
|
2229
|
-
this._control.inDeliverDemand = true;
|
|
2230
|
-
try {
|
|
2231
|
-
this._firePullDemand();
|
|
2232
|
-
} finally {
|
|
2233
|
-
this._control.activePull = void 0;
|
|
2234
|
-
this._control.inDeliverDemand = false;
|
|
2235
|
-
}
|
|
2498
|
+
nodeDeliverPullDemand(nodeRuntimeHost(this), demand);
|
|
2236
2499
|
}
|
|
2237
|
-
/**
|
|
2238
|
-
* R-pull (D269): a cone-routed PULL of THIS node's pullId arrived (R-up-routing) = a DEMAND.
|
|
2239
|
-
* Fire immediately if able; else OWE it — pin-5 (a dep DIRTY in flight, _pending>0) or F4/F5 (an
|
|
2240
|
-
* external PAUSE lock co-holds the node) — and fire when the node next becomes able. A demand
|
|
2241
|
-
* arriving WHILE a delivery is in flight (synchronous re-entry) is DROPPED (1:1, QA guard).
|
|
2242
|
-
*/
|
|
2243
2500
|
_onDemand(demand) {
|
|
2244
|
-
|
|
2245
|
-
if (this._canFireDemand()) this._deliverPullDemand(demand);
|
|
2246
|
-
else this._control.demandOwed = demand;
|
|
2501
|
+
nodeOnDemand(nodeRuntimeHost(this), demand);
|
|
2247
2502
|
}
|
|
2248
|
-
/**
|
|
2249
|
-
* R-pull (D55): service ONE demand. Delivery content = the orthogonal pausable mode:
|
|
2250
|
-
* - 'resumeAll' → drain the buffered BACKLOG (each `_down` re-synthesizes a leading DIRTY, so
|
|
2251
|
-
* the per-entry replay is DIRTY-before-DATA — R-pause-modes per-entry arrival order);
|
|
2252
|
-
* - true → deliver the coalesced LATEST as ONE DIRTY-before-DATA wave (pin 2: the quiet absorb
|
|
2253
|
-
* suppressed the dep's original DIRTY, so the demand wave restores it before the value).
|
|
2254
|
-
* Neither branch fires when nothing changed since the last demand → the demand is SILENT.
|
|
2255
|
-
* Called by `_deliverPullDemand` only when settle-ready; the caller has released the pullId, so
|
|
2256
|
-
* `_markDirty` relays the leading DIRTY (not absorbed).
|
|
2257
|
-
*/
|
|
2258
2503
|
_firePullDemand() {
|
|
2259
|
-
|
|
2260
|
-
if (this._control.pauseBuffer.length > 0) {
|
|
2261
|
-
const buf = this._control.pauseBuffer;
|
|
2262
|
-
this._control.pauseBuffer = [];
|
|
2263
|
-
for (const wave of buf) this._down(wave);
|
|
2264
|
-
drainedBuffer = true;
|
|
2265
|
-
}
|
|
2266
|
-
if (drainedBuffer) return;
|
|
2267
|
-
if (this._control.pausedDepWaveOccurred) {
|
|
2268
|
-
const gated = this._slot.handle !== null && !this._wave.hasCalledFnOnce && !(this._slot.partial || this._allDepsSettled());
|
|
2269
|
-
if (this._wave.pending > 0 || gated) return;
|
|
2270
|
-
this._control.pausedDepWaveOccurred = false;
|
|
2271
|
-
this._wave.emittedDirtyThisWave = false;
|
|
2272
|
-
this._control.pullDirtyOwed = true;
|
|
2273
|
-
try {
|
|
2274
|
-
this._tryRun();
|
|
2275
|
-
} finally {
|
|
2276
|
-
this._control.pullDirtyOwed = false;
|
|
2277
|
-
}
|
|
2278
|
-
return;
|
|
2279
|
-
}
|
|
2280
|
-
if (this._slot.handle !== null) {
|
|
2281
|
-
if (!this._wave.hasCalledFnOnce && !(this._slot.partial || this._allDepsSettled())) return;
|
|
2282
|
-
this._wave.emittedDirtyThisWave = false;
|
|
2283
|
-
this._control.pullDirtyOwed = true;
|
|
2284
|
-
try {
|
|
2285
|
-
this._runWave();
|
|
2286
|
-
} finally {
|
|
2287
|
-
this._control.pullDirtyOwed = false;
|
|
2288
|
-
}
|
|
2289
|
-
}
|
|
2504
|
+
nodeFirePullDemand(nodeRuntimeHost(this));
|
|
2290
2505
|
}
|
|
2291
|
-
/**
|
|
2292
|
-
* R-pull (D269): fire a demand that was OWED (deferred at demand time) once the node becomes
|
|
2293
|
-
* able — called from the dep-settle arms (DATA/RESOLVED/INVALIDATE/terminal drain _pending, pin-5
|
|
2294
|
-
* + B1/F6) and from `_pauseRelease` (an external PAUSE lock releases, F4/F5).
|
|
2295
|
-
*/
|
|
2296
2506
|
_fireOwedDemandIfReady() {
|
|
2297
|
-
|
|
2298
|
-
if (this._slot.pull && this._control.demandOwed !== void 0 && this._canFireDemand()) {
|
|
2299
|
-
this._deliverPullDemand(this._control.demandOwed);
|
|
2300
|
-
}
|
|
2507
|
+
nodeFireOwedDemandIfReady(nodeRuntimeHost(this));
|
|
2301
2508
|
}
|
|
2302
|
-
/** Should an outgoing settle slice be deferred into the pause buffer? */
|
|
2303
2509
|
_shouldBufferOnPause() {
|
|
2304
|
-
|
|
2305
|
-
if (!this._isPaused() && !this._isPullQuiet()) return false;
|
|
2306
|
-
if (this._slot.pausable === "resumeAll") return true;
|
|
2307
|
-
if (!this._wave.insideRunWave && this._isAsyncPool() && this._slot.deps.length > 0) return true;
|
|
2308
|
-
return false;
|
|
2510
|
+
return nodeShouldBufferOnPause(nodeRuntimeHost(this));
|
|
2309
2511
|
}
|
|
2310
|
-
/** R-invalidate-idempotent: clear cache + flush + cascade; no-op if nothing cached. */
|
|
2311
2512
|
_invalidate(delivery) {
|
|
2312
|
-
|
|
2313
|
-
|
|
2314
|
-
this._value.hasData = false;
|
|
2315
|
-
this._value.status = "sentinel";
|
|
2316
|
-
this._value.replayRing = [];
|
|
2317
|
-
for (const fn of this._hooks.onInvalidate) fn();
|
|
2318
|
-
this._emitToSubs(["INVALIDATE"], delivery);
|
|
2319
|
-
}
|
|
2320
|
-
// B42 (R-deps-terminal): ALL deps TERMINAL = every dep has reached COMPLETE *or* an ABSORBED
|
|
2321
|
-
// ERROR. Block only on a LIVE dep (_depTerminal[i] === undefined); an errored dep (terminal = the
|
|
2322
|
-
// error payload, which R-data-payload guarantees is !== undefined and non-boolean) COUNTS as
|
|
2323
|
-
// terminal-done. Was
|
|
2324
|
-
// `tm !== true`, which wedged a node whose errorWhenDepsError:false dep ERRORed (it never
|
|
2325
|
-
// auto-completed even after every other dep completed). Drives the completeWhenDepsComplete cascade.
|
|
2513
|
+
nodeInvalidate(nodeRuntimeHost(this), delivery);
|
|
2514
|
+
}
|
|
2326
2515
|
_allDepsTerminal() {
|
|
2327
|
-
|
|
2328
|
-
|
|
2329
|
-
|
|
2516
|
+
return nodeAllDepsTerminal(nodeRuntimeHost(this));
|
|
2517
|
+
}
|
|
2518
|
+
_emitToSubs(msg, delivery) {
|
|
2519
|
+
nodeEmitToSubs(nodeRuntimeHost(this), msg, delivery);
|
|
2330
2520
|
}
|
|
2331
2521
|
/** R-terminal: resubscribable reset clears terminal + dep state + re-arms the gate. */
|
|
2332
2522
|
_resetLifecycle() {
|
|
2333
|
-
|
|
2334
|
-
this._dep.unsubs = [];
|
|
2335
|
-
this._dep.idxBoxes = [];
|
|
2336
|
-
this._lifecycle.subscribers.clear();
|
|
2337
|
-
this._lifecycle.activated = false;
|
|
2338
|
-
this._value.terminal = void 0;
|
|
2339
|
-
this._value.hasTorndown = false;
|
|
2340
|
-
this._wave.hasCalledFnOnce = false;
|
|
2341
|
-
this._resetDepState();
|
|
2342
|
-
this._control.pauseLockset.clear();
|
|
2343
|
-
this._control.pauseBuffer = [];
|
|
2344
|
-
this._control.pausedDepWaveOccurred = false;
|
|
2345
|
-
this._control.demandOwed = void 0;
|
|
2346
|
-
this._control.activePull = void 0;
|
|
2347
|
-
this._control.pullDirtyOwed = false;
|
|
2348
|
-
this._value.replayRing = [];
|
|
2349
|
-
const isCompute = this._slot.handle !== null || this._slot.deps.length > 0;
|
|
2350
|
-
if (isCompute) {
|
|
2351
|
-
this._value.cache = SENTINEL;
|
|
2352
|
-
this._value.hasData = false;
|
|
2353
|
-
this._value.status = "sentinel";
|
|
2354
|
-
} else {
|
|
2355
|
-
this._value.status = this._value.hasData ? "settled" : "sentinel";
|
|
2356
|
-
}
|
|
2357
|
-
if (!this._privateState.persist) this._privateState.value = SENTINEL;
|
|
2358
|
-
}
|
|
2359
|
-
_emitToSubs(msg, delivery) {
|
|
2360
|
-
if (this._released) return;
|
|
2361
|
-
const subs = [...this._lifecycle.subscribers];
|
|
2362
|
-
for (const sink of subs) sink(msg, delivery);
|
|
2523
|
+
nodeResetLifecycle(nodeRuntimeHost(this));
|
|
2363
2524
|
}
|
|
2364
2525
|
/** Batch commit (R-batch-coalesce): deliver the deferred tier-3 wave now. */
|
|
2365
2526
|
__commitBatchedWave(wave) {
|
|
2366
|
-
this
|
|
2367
|
-
this._down(wave);
|
|
2527
|
+
nodeCommitBatchedWave(nodeRuntimeHost(this), wave);
|
|
2368
2528
|
}
|
|
2369
2529
|
/** Batch rollback: balance the immediate DIRTY with a RESOLVED so downstream un-dirties. */
|
|
2370
2530
|
__rollbackBatched() {
|
|
2371
|
-
|
|
2372
|
-
this._wave.batchDirtyOwed = false;
|
|
2373
|
-
this._wave.emittedDirtyThisWave = false;
|
|
2374
|
-
this._value.status = this._value.hasData ? "settled" : "sentinel";
|
|
2375
|
-
this._emitToSubs(["RESOLVED"]);
|
|
2376
|
-
}
|
|
2531
|
+
nodeRollbackBatched(nodeRuntimeHost(this));
|
|
2377
2532
|
}
|
|
2378
2533
|
/** B49: enqueue a committed-boundary task on this node's graph-local core. */
|
|
2379
2534
|
__deferBoundary(fn, batchToken) {
|
|
2380
|
-
|
|
2381
|
-
batchToken,
|
|
2382
|
-
isReady: () => !this._hasBoundaryPauseLock()
|
|
2383
|
-
});
|
|
2535
|
+
nodeDeferBoundary(nodeRuntimeHost(this), fn, batchToken);
|
|
2384
2536
|
}
|
|
2385
2537
|
};
|
|
2386
2538
|
function node(deps = [], handleOrFn = null, opts = {}) {
|