@graphrefly/ts 0.0.1 → 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/actions-types-CSC3NMDl.d.ts +657 -0
- package/dist/actions-types-wl9Mgkmr.d.cts +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-DZTJ3C-p.d.cts → agent-runtime-types-core-CaXfKNtY.d.cts} +171 -320
- package/dist/{agent-runtime-BesGDZcB.d.ts → agent-runtime-types-core-hU299uIC.d.ts} +171 -320
- package/dist/agent-runtime-types-tool-BEpSINol.d.ts +695 -0
- package/dist/agent-runtime-types-tool-DninPEzk.d.cts +695 -0
- package/dist/agentic-memory-retention-BmGX368S.d.ts +14 -0
- package/dist/agentic-memory-retention-Ih1qhX9Z.d.cts +14 -0
- package/dist/{agentic-memory-BmRCvh0d.d.ts → agentic-memory-types-CVSUS6XR.d.ts} +13 -57
- package/dist/{agentic-memory-DfuVZ-lY.d.cts → agentic-memory-types-FnnYlVUs.d.cts} +13 -57
- package/dist/{capability-admission-g0mn9hpq.d.ts → capability-admission-BW2CziT6.d.ts} +3 -3
- package/dist/{capability-admission-B0BzqAm5.d.cts → capability-admission-lwSecxXs.d.cts} +3 -3
- package/dist/chunk-2KUAG2GZ.js +9693 -0
- package/dist/chunk-2KUAG2GZ.js.map +1 -0
- package/dist/chunk-2NJP6GO4.js +1320 -0
- package/dist/chunk-2NJP6GO4.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-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-IXZBUWSP.js → chunk-7HZRJMN6.js} +2 -2
- package/dist/{chunk-SS2A464I.js → chunk-CJIFGJQG.js} +3 -3
- package/dist/{chunk-V7CIJE4B.js → chunk-CX6B6PO2.js} +92 -9
- package/dist/chunk-CX6B6PO2.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-HKK2JD7Z.js → chunk-ECURQ3HD.js} +12 -125
- package/dist/chunk-ECURQ3HD.js.map +1 -0
- package/dist/{chunk-3JR3EDB2.js → chunk-EOKT4QFF.js} +121 -115
- package/dist/chunk-EOKT4QFF.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-H75VXTGT.js → chunk-L6LDXRWE.js} +3 -3
- package/dist/{chunk-H75VXTGT.js.map → chunk-L6LDXRWE.js.map} +1 -1
- package/dist/{chunk-YXMZ2N6J.js → chunk-M7J6Z4IJ.js} +1071 -1025
- package/dist/chunk-M7J6Z4IJ.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-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-XKXWK2KP.js → chunk-SHZDP2MQ.js} +1157 -1021
- package/dist/chunk-SHZDP2MQ.js.map +1 -0
- package/dist/{chunk-CZNV3VXM.js → chunk-SIDJO2T4.js} +11 -11
- package/dist/chunk-STXRMPW4.js +4131 -0
- package/dist/chunk-STXRMPW4.js.map +1 -0
- package/dist/{chunk-2747WN4Y.js → chunk-TPND5MJS.js} +3 -3
- package/dist/chunk-TQPCAIQI.js +612 -0
- package/dist/chunk-TQPCAIQI.js.map +1 -0
- package/dist/{chunk-43BKLFZU.js → chunk-YDWBXXQZ.js} +10 -10
- 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 +1 -1
- package/dist/core/index.d.ts +1 -1
- 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-BpyJuWkw.d.ts → describe-B_A5fbXH.d.ts} +1 -1
- package/dist/{describe-DYMw_l1C.d.cts → describe-CQRrkv-Q.d.cts} +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-CWK3HLPB.d.cts} +133 -131
- package/dist/{graph-D-1-SQeC.d.ts → graph-ho5sotHP.d.ts} +133 -131
- package/dist/{index-Bmxeu0nK.d.ts → index-CQWcE0Dw.d.ts} +18 -4
- package/dist/{index-72VZC0-E.d.cts → index-DHA1i67c.d.cts} +18 -4
- 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-C0mAvWU1.d.cts +164 -0
- package/dist/measurements-OMpCeBwh.d.ts +164 -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-C9uMYz3i.d.ts +200 -0
- package/dist/process-types-h3uRlzDc.d.cts +200 -0
- package/dist/{reactive-collection-DNV0-gFi.d.cts → reactive-collection-B9R0Bl1P.d.cts} +4 -34
- package/dist/{reactive-collection-BAmfrGjd.d.ts → reactive-collection-BXFrH0U2.d.ts} +4 -34
- package/dist/{reactive-collection-storage-BNEldDyi.d.cts → reactive-collection-storage-BLGv8Xp8.d.cts} +5 -5
- package/dist/{reactive-collection-storage-YZsAQsWK.d.ts → reactive-collection-storage-a4zD3665.d.ts} +5 -5
- package/dist/{reactive-map-DRD1LJ2H.d.cts → reactive-map-C_8sOfdS.d.cts} +3 -2
- package/dist/{reactive-map-EsDiCmJk.d.ts → reactive-map-jle5dnok.d.ts} +3 -2
- package/dist/render/index.d.cts +2 -2
- package/dist/render/index.d.ts +2 -2
- package/dist/scheduled-readiness-5rwQlyjV.d.ts +91 -0
- package/dist/scheduled-readiness-DpRY8jI0.d.cts +91 -0
- package/dist/semantic-memory-graph-C2ZUwIlq.d.ts +30 -0
- package/dist/semantic-memory-graph-DlZBD_Eu.d.cts +30 -0
- package/dist/{semantic-memory-graph-DKuNzuWw.d.cts → semantic-memory-graph-types-BvzdqmkY.d.cts} +2 -28
- package/dist/{semantic-memory-graph-uwbwJdhe.d.ts → semantic-memory-graph-types-Ci-OtahO.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 +4 -4
- package/dist/sources/browser.d.ts +4 -4
- package/dist/sources/browser.js +4 -4
- 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-BmtEs9mG.d.ts} +1 -1
- package/dist/{store-CNJwmT-h.d.cts → store-PAAsYvML.d.cts} +1 -1
- package/dist/types-BRNKoFHj.d.ts +357 -0
- package/dist/{types-CcPIn7sy.d.cts → types-BS6CyR-x.d.cts} +27 -108
- package/dist/types-BWK2ay3e.d.cts +457 -0
- package/dist/types-BXKSAoE1.d.cts +357 -0
- package/dist/types-BaPpZItj.d.ts +457 -0
- package/dist/types-BhveCMg5.d.cts +274 -0
- package/dist/{types-BsJvElYZ.d.ts → types-C9NOgNJw.d.ts} +27 -108
- package/dist/types-CTsQ8Ww4.d.ts +274 -0
- package/dist/types-DL_05n2M.d.ts +34 -0
- package/dist/types-XDoqxYO9.d.cts +34 -0
- package/dist/{work-item-runtime-C3M79vE9.d.ts → work-item-runtime-types-BqtWnSCS.d.ts} +3 -93
- package/dist/{work-item-runtime-qaVgsL0T.d.cts → work-item-runtime-types-CHO03AKh.d.cts} +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 +603 -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-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-Z2ANQ6JW.js.map → chunk-4Q77MMJY.js.map} +0 -0
- /package/dist/{chunk-IXZBUWSP.js.map → chunk-7HZRJMN6.js.map} +0 -0
- /package/dist/{chunk-SS2A464I.js.map → chunk-CJIFGJQG.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-VTHLCFN4.js.map → chunk-RAHNUYA5.js.map} +0 -0
- /package/dist/{chunk-CZNV3VXM.js.map → chunk-SIDJO2T4.js.map} +0 -0
- /package/dist/{chunk-2747WN4Y.js.map → chunk-TPND5MJS.js.map} +0 -0
- /package/dist/{chunk-43BKLFZU.js.map → chunk-YDWBXXQZ.js.map} +0 -0
- /package/dist/{chunk-6PHB5CJS.js.map → chunk-ZLFRB6FI.js.map} +0 -0
package/dist/graph/index.cjs
CHANGED
|
@@ -215,86 +215,6 @@ function drain() {
|
|
|
215
215
|
if (escaped !== null) throw escaped.e;
|
|
216
216
|
}
|
|
217
217
|
|
|
218
|
-
// src/batch/batch.ts
|
|
219
|
-
var active = null;
|
|
220
|
-
var boundaryOwner = null;
|
|
221
|
-
function currentBatch() {
|
|
222
|
-
return active !== null;
|
|
223
|
-
}
|
|
224
|
-
function currentBoundaryBatchToken() {
|
|
225
|
-
return active ?? boundaryOwner ?? void 0;
|
|
226
|
-
}
|
|
227
|
-
function deferToBatch(target, tier3Wave) {
|
|
228
|
-
if (active === null) return false;
|
|
229
|
-
if (!active.deferred.has(target)) active.order.push(target);
|
|
230
|
-
active.deferred.set(target, tier3Wave);
|
|
231
|
-
return true;
|
|
232
|
-
}
|
|
233
|
-
function deferAfterBatchForTarget(target, fn) {
|
|
234
|
-
if (active === null || !active.deferred.has(target)) return false;
|
|
235
|
-
const owner = active;
|
|
236
|
-
target.__deferBoundary(() => {
|
|
237
|
-
if (owner.committed) fn();
|
|
238
|
-
}, owner);
|
|
239
|
-
return true;
|
|
240
|
-
}
|
|
241
|
-
function commit(b) {
|
|
242
|
-
const prev = boundaryOwner;
|
|
243
|
-
boundaryOwner = b;
|
|
244
|
-
try {
|
|
245
|
-
for (const target of b.order) {
|
|
246
|
-
const wave = b.deferred.get(target);
|
|
247
|
-
if (wave) target.__commitBatchedWave(wave);
|
|
248
|
-
}
|
|
249
|
-
b.committed = true;
|
|
250
|
-
} catch (e) {
|
|
251
|
-
dropBoundaryTasksForBatch(b);
|
|
252
|
-
throw e;
|
|
253
|
-
} finally {
|
|
254
|
-
boundaryOwner = prev;
|
|
255
|
-
}
|
|
256
|
-
}
|
|
257
|
-
function rollback(b) {
|
|
258
|
-
dropBoundaryTasksForBatch(b);
|
|
259
|
-
for (const target of b.order) target.__rollbackBatched();
|
|
260
|
-
}
|
|
261
|
-
function batch(fn) {
|
|
262
|
-
enterWave();
|
|
263
|
-
try {
|
|
264
|
-
if (active !== null) {
|
|
265
|
-
const outer = active;
|
|
266
|
-
return fn({
|
|
267
|
-
rollback: () => {
|
|
268
|
-
outer.rolledBack = true;
|
|
269
|
-
}
|
|
270
|
-
});
|
|
271
|
-
}
|
|
272
|
-
const b = { order: [], deferred: /* @__PURE__ */ new Map(), committed: false, rolledBack: false };
|
|
273
|
-
active = b;
|
|
274
|
-
const bctx = {
|
|
275
|
-
rollback: () => {
|
|
276
|
-
b.rolledBack = true;
|
|
277
|
-
}
|
|
278
|
-
};
|
|
279
|
-
let result;
|
|
280
|
-
try {
|
|
281
|
-
result = fn(bctx);
|
|
282
|
-
} catch (e) {
|
|
283
|
-
active = null;
|
|
284
|
-
rollback(b);
|
|
285
|
-
throw e;
|
|
286
|
-
}
|
|
287
|
-
active = null;
|
|
288
|
-
if (b.rolledBack) rollback(b);
|
|
289
|
-
else {
|
|
290
|
-
commit(b);
|
|
291
|
-
}
|
|
292
|
-
return result;
|
|
293
|
-
} finally {
|
|
294
|
-
exitWave();
|
|
295
|
-
}
|
|
296
|
-
}
|
|
297
|
-
|
|
298
218
|
// src/dispatcher/index.ts
|
|
299
219
|
var PoolTable = class {
|
|
300
220
|
constructor(kind) {
|
|
@@ -758,100 +678,783 @@ function makeDepBookkeeping(depCount2) {
|
|
|
758
678
|
};
|
|
759
679
|
}
|
|
760
680
|
|
|
761
|
-
// src/
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
if (!Number.isFinite(value)) {
|
|
765
|
-
throw new TypeError(`stableJsonString: non-finite number at ${path}`);
|
|
766
|
-
}
|
|
681
|
+
// src/node/protocol-guards.ts
|
|
682
|
+
function terminalView(t) {
|
|
683
|
+
return t === void 0 ? false : t;
|
|
767
684
|
}
|
|
768
|
-
function
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
throw new TypeError(`stableJsonString: non-canonical number at ${path}`);
|
|
772
|
-
}
|
|
773
|
-
const abs = Math.abs(value);
|
|
774
|
-
if (abs > 0 && abs < JS_MIN_NORMAL_NUMBER) {
|
|
775
|
-
throw new TypeError(`stableJsonString: subnormal number at ${path}`);
|
|
685
|
+
function normalizePullDemand(demand) {
|
|
686
|
+
if (typeof demand !== "object" || demand === null || Array.isArray(demand)) {
|
|
687
|
+
throw new Error("ctx.up: PULL requires { pullId, params? } demand payload (D269)");
|
|
776
688
|
}
|
|
777
|
-
|
|
778
|
-
|
|
689
|
+
const pullId = demand.pullId;
|
|
690
|
+
if (typeof pullId !== "string" && typeof pullId !== "symbol") {
|
|
691
|
+
throw new Error("ctx.up: PULL demand requires a string or symbol pullId (D269)");
|
|
779
692
|
}
|
|
693
|
+
const params = demand.params;
|
|
694
|
+
return params === void 0 ? { pullId } : { pullId, params };
|
|
780
695
|
}
|
|
781
|
-
function
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
if (typeof value !== "object") {
|
|
790
|
-
throw new TypeError(`stableJsonString: value at ${path} is not JSON-encodable`);
|
|
696
|
+
function validateDownPayloads(msgs) {
|
|
697
|
+
for (const m of msgs) {
|
|
698
|
+
if (m[0] === "DATA" && m[1] === void 0) {
|
|
699
|
+
throw new Error("down: DATA requires a non-SENTINEL payload (R-data-payload)");
|
|
700
|
+
}
|
|
701
|
+
if (m[0] === "ERROR" && isInvalidErrorPayload(m[1])) {
|
|
702
|
+
throw new Error("down: ERROR requires a non-SENTINEL, non-boolean payload (R-data-payload)");
|
|
703
|
+
}
|
|
791
704
|
}
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
705
|
+
}
|
|
706
|
+
|
|
707
|
+
// src/node/runtime-accessors.ts
|
|
708
|
+
var constructingCore;
|
|
709
|
+
var constructingEnvironment;
|
|
710
|
+
var ownerTokens = /* @__PURE__ */ new WeakMap();
|
|
711
|
+
var topologyDepsChangedObservers = /* @__PURE__ */ new WeakMap();
|
|
712
|
+
var checkpointReaders = /* @__PURE__ */ new WeakMap();
|
|
713
|
+
var restoreWriters = /* @__PURE__ */ new WeakMap();
|
|
714
|
+
var runtimeReleasers = /* @__PURE__ */ new WeakMap();
|
|
715
|
+
var runtimeQuiescenceReaders = /* @__PURE__ */ new WeakMap();
|
|
716
|
+
var subscriberCountReaders = /* @__PURE__ */ new WeakMap();
|
|
717
|
+
var activationReaders = /* @__PURE__ */ new WeakMap();
|
|
718
|
+
var releasedNodes = /* @__PURE__ */ new WeakSet();
|
|
719
|
+
function withNodeCore(core, create) {
|
|
720
|
+
const prev = constructingCore;
|
|
721
|
+
constructingCore = core;
|
|
722
|
+
try {
|
|
723
|
+
return create();
|
|
724
|
+
} finally {
|
|
725
|
+
constructingCore = prev;
|
|
796
726
|
}
|
|
797
|
-
|
|
727
|
+
}
|
|
728
|
+
function takeConstructingNodeCore() {
|
|
729
|
+
const core = constructingCore;
|
|
730
|
+
constructingCore = void 0;
|
|
731
|
+
return core;
|
|
732
|
+
}
|
|
733
|
+
function withEnvironmentDrivers(environment, create) {
|
|
734
|
+
const prev = constructingEnvironment;
|
|
735
|
+
constructingEnvironment = environment;
|
|
798
736
|
try {
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
737
|
+
return create();
|
|
738
|
+
} finally {
|
|
739
|
+
constructingEnvironment = prev;
|
|
740
|
+
}
|
|
741
|
+
}
|
|
742
|
+
function takeConstructingEnvironmentDrivers() {
|
|
743
|
+
const environment = constructingEnvironment;
|
|
744
|
+
constructingEnvironment = void 0;
|
|
745
|
+
return environment;
|
|
746
|
+
}
|
|
747
|
+
function getNodeOwner(n) {
|
|
748
|
+
return ownerTokens.get(n);
|
|
749
|
+
}
|
|
750
|
+
function setNodeOwner(n, owner) {
|
|
751
|
+
ownerTokens.set(n, owner);
|
|
752
|
+
}
|
|
753
|
+
function setNodeTopologyDepsChangedObserver(n, observer) {
|
|
754
|
+
topologyDepsChangedObservers.set(n, observer);
|
|
755
|
+
}
|
|
756
|
+
function notifyTopologyDepsChanged(node2, prevDeps, deps) {
|
|
757
|
+
topologyDepsChangedObservers.get(node2)?.(node2, prevDeps, deps);
|
|
758
|
+
}
|
|
759
|
+
function checkpointStateOfNode(n) {
|
|
760
|
+
const read = checkpointReaders.get(n);
|
|
761
|
+
if (read === void 0) throw new Error("checkpoint: unknown node state");
|
|
762
|
+
return read();
|
|
763
|
+
}
|
|
764
|
+
function restoreStateOfNode(n, state) {
|
|
765
|
+
const write = restoreWriters.get(n);
|
|
766
|
+
if (write === void 0) throw new Error("restoreGraph: unknown node state");
|
|
767
|
+
write(state);
|
|
768
|
+
}
|
|
769
|
+
function releaseRuntimeOfNode(n) {
|
|
770
|
+
runtimeReleasers.get(n)?.();
|
|
771
|
+
}
|
|
772
|
+
function isNodeRuntimeQuiescentForRelease(n) {
|
|
773
|
+
return runtimeQuiescenceReaders.get(n)?.() ?? false;
|
|
774
|
+
}
|
|
775
|
+
function subscriberCountOfNode(n) {
|
|
776
|
+
return subscriberCountReaders.get(n)?.() ?? 0;
|
|
777
|
+
}
|
|
778
|
+
function isNodeActiveForRelease(n) {
|
|
779
|
+
return activationReaders.get(n)?.() ?? false;
|
|
780
|
+
}
|
|
781
|
+
function isNodeRuntimeReleased(n) {
|
|
782
|
+
return releasedNodes.has(n);
|
|
783
|
+
}
|
|
784
|
+
|
|
785
|
+
// src/node/node-context-runtime.ts
|
|
786
|
+
function nodeBuildCtx(self) {
|
|
787
|
+
const kind = self._slot.handle ? self._slot.dispatcher.poolKind(self._slot.handle.poolId) : "sync";
|
|
788
|
+
if (kind === "sync") {
|
|
789
|
+
if (self._syncCtx === null) self._syncCtx = self._makeCtx();
|
|
790
|
+
self._refreshCtx(self._syncCtx);
|
|
791
|
+
return self._syncCtx;
|
|
792
|
+
}
|
|
793
|
+
return self._makeCtx({
|
|
794
|
+
waveData: self._dep.waveData.map((waves) => waves.map((w) => [...w])),
|
|
795
|
+
terminal: self._dep.terminalInput.map(terminalView),
|
|
796
|
+
latest: [...self._dep.prev]
|
|
797
|
+
});
|
|
798
|
+
}
|
|
799
|
+
function nodeMakeCtx(self, snapshot) {
|
|
800
|
+
const ctx = {
|
|
801
|
+
// Wave-owner boundary (D47): a SYNC fn's emit nests under the public entry that drove
|
|
802
|
+
// it (cheap inc/dec, no early drain); an ASYNC-pool fn re-enters here from its stashed
|
|
803
|
+
// ctx at depth 0, so this is the boundary that drains any rewireNext it issued.
|
|
804
|
+
up: (msgs, towardDep) => {
|
|
805
|
+
if (self._released) return;
|
|
806
|
+
enterWave();
|
|
807
|
+
try {
|
|
808
|
+
self._up(msgs, towardDep);
|
|
809
|
+
} finally {
|
|
810
|
+
exitWave();
|
|
808
811
|
}
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
812
|
+
},
|
|
813
|
+
down: (msgs) => {
|
|
814
|
+
if (self._released) return;
|
|
815
|
+
enterWave();
|
|
816
|
+
try {
|
|
817
|
+
self._down(msgs);
|
|
818
|
+
} finally {
|
|
819
|
+
exitWave();
|
|
815
820
|
}
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
821
|
+
},
|
|
822
|
+
waveData: snapshot?.waveData ?? self._dep.waveData,
|
|
823
|
+
terminal: snapshot?.terminal ?? self._dep.terminalInput.map(terminalView),
|
|
824
|
+
state: self._makeState(),
|
|
825
|
+
onDeactivation: (fn) => {
|
|
826
|
+
if (self._released) return;
|
|
827
|
+
self._hooks.onDeactivation.push(fn);
|
|
828
|
+
},
|
|
829
|
+
onInvalidate: (fn) => {
|
|
830
|
+
if (self._released) return;
|
|
831
|
+
self._hooks.onInvalidate.push(fn);
|
|
832
|
+
},
|
|
833
|
+
environment: () => self._slot.environment,
|
|
834
|
+
// R-rewire-deferred (D47): defer a self-dep-set mutation to the committed boundary.
|
|
835
|
+
rewireNext: {
|
|
836
|
+
subscribeDep: (dep, fn) => self._requestRewireNext({ kind: "add", dep, fn }),
|
|
837
|
+
unsubscribeDep: (dep, fn) => self._requestRewireNext({ kind: "remove", dep, fn }),
|
|
838
|
+
replaceDeps: (deps, fn) => self._requestRewireNext({ kind: "set", deps, fn })
|
|
839
|
+
},
|
|
840
|
+
// R-up-routing / R-pull (D269): deferred up — route a control/demand wave (e.g. PULL)
|
|
841
|
+
// up the declared cone at the committed boundary. The SELF-demand path: an
|
|
842
|
+
// immediate ctx.up whose delivery loops back re-enters this fn (D37 / R-reentrancy).
|
|
843
|
+
upNext: (msgs, towardDep) => self._requestUpNext(msgs, towardDep),
|
|
844
|
+
...self._control.activePull === void 0 ? {} : { pull: self._control.activePull },
|
|
845
|
+
[CTX_DEP_CACHE]: { latest: snapshot?.latest ?? self._dep.prev },
|
|
846
|
+
[CTX_NODE_BINDING]: {
|
|
847
|
+
dispatcher: self._slot.dispatcher,
|
|
848
|
+
create: (factory) => withEnvironmentDrivers(self._slot.environment, () => withNodeCore(self._core, factory))
|
|
829
849
|
}
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
850
|
+
};
|
|
851
|
+
if (self._slot.dynamic) {
|
|
852
|
+
ctx.track = (i) => ctx[CTX_DEP_CACHE]?.latest[i];
|
|
833
853
|
}
|
|
854
|
+
return ctx;
|
|
834
855
|
}
|
|
835
|
-
function
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
856
|
+
function nodeRefreshCtx(self, ctx) {
|
|
857
|
+
ctx.waveData = self._dep.waveData;
|
|
858
|
+
ctx.terminal = self._dep.terminalInput.map(terminalView);
|
|
859
|
+
if (self._control.activePull === void 0) {
|
|
860
|
+
delete ctx.pull;
|
|
861
|
+
} else {
|
|
862
|
+
ctx.pull = self._control.activePull;
|
|
863
|
+
}
|
|
864
|
+
ctx[CTX_DEP_CACHE] = { latest: self._dep.prev };
|
|
840
865
|
}
|
|
841
|
-
function
|
|
842
|
-
const encoder = new TextEncoder();
|
|
843
|
-
const decoder = new TextDecoder();
|
|
866
|
+
function nodeMakeState(self) {
|
|
844
867
|
return {
|
|
845
|
-
|
|
846
|
-
|
|
868
|
+
get: () => self._privateState.value,
|
|
869
|
+
set: (v) => {
|
|
870
|
+
self._privateState.value = v;
|
|
847
871
|
},
|
|
848
|
-
|
|
849
|
-
|
|
872
|
+
persist: (on = true) => {
|
|
873
|
+
self._privateState.persist = on;
|
|
850
874
|
}
|
|
851
875
|
};
|
|
852
876
|
}
|
|
853
|
-
|
|
854
|
-
|
|
877
|
+
|
|
878
|
+
// src/node/node-input-runtime.ts
|
|
879
|
+
function nodeRecordDepProjection(self, idx, delivery) {
|
|
880
|
+
const token = delivery?.wave ?? {};
|
|
881
|
+
if (self._dep.waveTokens[idx] !== token) {
|
|
882
|
+
self._dep.waveData[idx].push([]);
|
|
883
|
+
self._dep.waveTokens[idx] = token;
|
|
884
|
+
}
|
|
885
|
+
return self._dep.waveData[idx][self._dep.waveData[idx].length - 1];
|
|
886
|
+
}
|
|
887
|
+
function nodeDepProjectionHasData(self, idx) {
|
|
888
|
+
const projection = self._dep.waveData[idx][self._dep.waveData[idx].length - 1];
|
|
889
|
+
return projection?.some((v) => v !== SENTINEL) ?? false;
|
|
890
|
+
}
|
|
891
|
+
function nodeReceiveFromDep(self, idx, msg, delivery) {
|
|
892
|
+
if (self._released) return;
|
|
893
|
+
const t = msg[0];
|
|
894
|
+
if (t === "START") return;
|
|
895
|
+
const isLastInDeliveredWave = delivery?.last ?? true;
|
|
896
|
+
if (self._value.terminal !== void 0) {
|
|
897
|
+
if (t === "TEARDOWN") self._down([["TEARDOWN"]]);
|
|
898
|
+
return;
|
|
899
|
+
}
|
|
900
|
+
if (t === "INVALIDATE") {
|
|
901
|
+
const projection = self._recordDepProjection(idx, delivery);
|
|
902
|
+
projection.push(SENTINEL);
|
|
903
|
+
if (projection.some((v) => v !== SENTINEL) && isLastInDeliveredWave) self._maybeRun();
|
|
904
|
+
self._dep.prev[idx] = SENTINEL;
|
|
905
|
+
self._dep.hasData[idx] = false;
|
|
906
|
+
self._dep.batch[idx] = null;
|
|
907
|
+
if (self._dep.dirty[idx]) {
|
|
908
|
+
self._dep.dirty[idx] = false;
|
|
909
|
+
self._wave.pending--;
|
|
910
|
+
}
|
|
911
|
+
if (self._control.pausedDepWaveOccurred && self._dep.batch.every((b) => b === null)) {
|
|
912
|
+
self._control.pausedDepWaveOccurred = false;
|
|
913
|
+
}
|
|
914
|
+
const hadData = self._value.hasData;
|
|
915
|
+
self._invalidate();
|
|
916
|
+
if (self._wave.pending === 0 && self._wave.emittedDirtyThisWave) {
|
|
917
|
+
if (!hadData) self._down([["RESOLVED"]]);
|
|
918
|
+
else self._wave.emittedDirtyThisWave = false;
|
|
919
|
+
}
|
|
920
|
+
self._fireOwedDemandIfReady();
|
|
921
|
+
return;
|
|
922
|
+
}
|
|
923
|
+
if (isTerminal(t)) {
|
|
924
|
+
const isError = t === "ERROR";
|
|
925
|
+
const errPayload = isError ? msg[1] : void 0;
|
|
926
|
+
self._dep.terminal[idx] = isError ? errPayload : true;
|
|
927
|
+
self._dep.terminalInput[idx] = isError ? errPayload : true;
|
|
928
|
+
self._releaseDepDirty(idx);
|
|
929
|
+
const ranValueBeforeTerminal = self._depProjectionHasData(idx) && isLastInDeliveredWave;
|
|
930
|
+
if (ranValueBeforeTerminal) self._maybeRun();
|
|
931
|
+
if (isError && self._slot.errorWhenDepsError) {
|
|
932
|
+
self._down([["ERROR", errPayload]]);
|
|
933
|
+
} else if (self._slot.terminalAsRealInput) {
|
|
934
|
+
if (ranValueBeforeTerminal) {
|
|
935
|
+
self._fireOwedDemandIfReady();
|
|
936
|
+
return;
|
|
937
|
+
}
|
|
938
|
+
self._maybeRun();
|
|
939
|
+
} else if (self._slot.completeWhenDepsComplete && self._allDepsTerminal()) {
|
|
940
|
+
self._down([["COMPLETE"]]);
|
|
941
|
+
} else {
|
|
942
|
+
self._settleAfterAbsorbedTerminal();
|
|
943
|
+
}
|
|
944
|
+
self._fireOwedDemandIfReady();
|
|
945
|
+
return;
|
|
946
|
+
}
|
|
947
|
+
if (t === "TEARDOWN") {
|
|
948
|
+
self._down([["TEARDOWN"]]);
|
|
949
|
+
return;
|
|
950
|
+
}
|
|
951
|
+
if (t === "DIRTY") {
|
|
952
|
+
if (!self._dep.dirty[idx]) {
|
|
953
|
+
self._dep.dirty[idx] = true;
|
|
954
|
+
self._wave.pending++;
|
|
955
|
+
self._dep.tier[idx] = 2;
|
|
956
|
+
self._markDirty();
|
|
957
|
+
}
|
|
958
|
+
return;
|
|
959
|
+
}
|
|
960
|
+
if (t === "DATA") {
|
|
961
|
+
const v = msg[1];
|
|
962
|
+
self._recordDepProjection(idx, delivery).push(v);
|
|
963
|
+
const b = self._dep.batch[idx];
|
|
964
|
+
if (b === null) self._dep.batch[idx] = [v];
|
|
965
|
+
else b.push(v);
|
|
966
|
+
self._dep.prev[idx] = v;
|
|
967
|
+
self._dep.hasData[idx] = true;
|
|
968
|
+
self._dep.tier[idx] = 3;
|
|
969
|
+
if (self._dep.dirty[idx]) {
|
|
970
|
+
self._dep.dirty[idx] = false;
|
|
971
|
+
self._wave.pending--;
|
|
972
|
+
}
|
|
973
|
+
if (isLastInDeliveredWave) self._maybeRun();
|
|
974
|
+
self._fireOwedDemandIfReady();
|
|
975
|
+
return;
|
|
976
|
+
}
|
|
977
|
+
if (t === "RESOLVED") {
|
|
978
|
+
self._recordDepProjection(idx, delivery);
|
|
979
|
+
self._dep.tier[idx] = 3;
|
|
980
|
+
if (self._dep.dirty[idx]) {
|
|
981
|
+
self._dep.dirty[idx] = false;
|
|
982
|
+
self._wave.pending--;
|
|
983
|
+
}
|
|
984
|
+
if (isLastInDeliveredWave) self._maybeRun();
|
|
985
|
+
self._fireOwedDemandIfReady();
|
|
986
|
+
return;
|
|
987
|
+
}
|
|
988
|
+
}
|
|
989
|
+
function nodeReleaseDepDirty(self, idx) {
|
|
990
|
+
if (self._dep.dirty[idx]) {
|
|
991
|
+
self._dep.dirty[idx] = false;
|
|
992
|
+
self._wave.pending--;
|
|
993
|
+
}
|
|
994
|
+
}
|
|
995
|
+
function nodeSettleAfterAbsorbedTerminal(self) {
|
|
996
|
+
if (self._wave.pending !== 0 || !self._wave.emittedDirtyThisWave) return;
|
|
997
|
+
const sawData = self._dep.batch.some((b) => b !== null && b.length > 0);
|
|
998
|
+
if (sawData) self._maybeRun();
|
|
999
|
+
if (self._wave.emittedDirtyThisWave) self._down([["RESOLVED"]]);
|
|
1000
|
+
}
|
|
1001
|
+
function nodeMarkDirty(self) {
|
|
1002
|
+
self._value.status = "dirty";
|
|
1003
|
+
if (self._isPullQuiet()) return;
|
|
1004
|
+
if (!self._wave.emittedDirtyThisWave) {
|
|
1005
|
+
self._wave.emittedDirtyThisWave = true;
|
|
1006
|
+
self._emitToSubs(["DIRTY"]);
|
|
1007
|
+
}
|
|
1008
|
+
}
|
|
1009
|
+
function nodeMaybeRun(self) {
|
|
1010
|
+
if (self._wave.inDepMutation) {
|
|
1011
|
+
self._wave.rewireRunPending = true;
|
|
1012
|
+
return;
|
|
1013
|
+
}
|
|
1014
|
+
if (self._slot.pausable === true && (self._isPaused() || self._isPullQuiet())) {
|
|
1015
|
+
self._control.pausedDepWaveOccurred = true;
|
|
1016
|
+
return;
|
|
1017
|
+
}
|
|
1018
|
+
self._tryRun();
|
|
1019
|
+
}
|
|
1020
|
+
function nodeSettleRewire(self) {
|
|
1021
|
+
if (self._slot.pausable === true && self._isPaused()) {
|
|
1022
|
+
self._control.pausedDepWaveOccurred = true;
|
|
1023
|
+
return;
|
|
1024
|
+
}
|
|
1025
|
+
if (self._wave.pending > 0) return;
|
|
1026
|
+
if (self._slot.handle === null) {
|
|
1027
|
+
self._passthroughEmit();
|
|
1028
|
+
return;
|
|
1029
|
+
}
|
|
1030
|
+
if (!self._wave.hasCalledFnOnce && !(self._slot.partial || self._allDepsSettled())) return;
|
|
1031
|
+
self._markDirty();
|
|
1032
|
+
self._runWave();
|
|
1033
|
+
}
|
|
1034
|
+
function nodeTryRun(self) {
|
|
1035
|
+
if (self._wave.pending > 0) return;
|
|
1036
|
+
if (self._slot.handle === null) {
|
|
1037
|
+
self._passthroughEmit();
|
|
1038
|
+
return;
|
|
1039
|
+
}
|
|
1040
|
+
if (!self._wave.hasCalledFnOnce) {
|
|
1041
|
+
if (self._slot.partial || self._allDepsSettled()) self._runWave();
|
|
1042
|
+
return;
|
|
1043
|
+
}
|
|
1044
|
+
self._runWave();
|
|
1045
|
+
}
|
|
1046
|
+
function nodeAllDepsSettled(self) {
|
|
1047
|
+
for (let i = 0; i < self._slot.deps.length; i++) {
|
|
1048
|
+
if (self._dep.hasData[i]) continue;
|
|
1049
|
+
if (self._slot.terminalAsRealInput && self._dep.terminal[i] !== void 0) continue;
|
|
1050
|
+
return false;
|
|
1051
|
+
}
|
|
1052
|
+
return true;
|
|
1053
|
+
}
|
|
1054
|
+
function nodePassthroughEmit(self) {
|
|
1055
|
+
const b = self._dep.batch[0];
|
|
1056
|
+
if (b !== null && b.length > 0) {
|
|
1057
|
+
self._down([["DATA", b[b.length - 1]]]);
|
|
1058
|
+
} else if (self._wave.emittedDirtyThisWave) {
|
|
1059
|
+
self._down([["RESOLVED"]]);
|
|
1060
|
+
}
|
|
1061
|
+
self._dep.batch[0] = null;
|
|
1062
|
+
self._wave.emittedDirtyThisWave = false;
|
|
1063
|
+
}
|
|
1064
|
+
function nodeRunWave(self) {
|
|
1065
|
+
if (self._wave.insideRunWave)
|
|
1066
|
+
throw new Error(
|
|
1067
|
+
"synchronous feedback cycle: node fn re-entered its own wave (R-reentrancy / D37)"
|
|
1068
|
+
);
|
|
1069
|
+
self._wave.hasCalledFnOnce = true;
|
|
1070
|
+
self._hooks.onInvalidate = [];
|
|
1071
|
+
self._hooks.onDeactivation = [];
|
|
1072
|
+
const ctx = self._buildCtx();
|
|
1073
|
+
const wasDirty = self._wave.emittedDirtyThisWave;
|
|
1074
|
+
self._wave.emittedSettleThisWave = false;
|
|
1075
|
+
self._wave.insideRunWave = true;
|
|
1076
|
+
try {
|
|
1077
|
+
self._slot.dispatcher.invoke(self._slot.handle, ctx);
|
|
1078
|
+
} finally {
|
|
1079
|
+
self._wave.insideRunWave = false;
|
|
1080
|
+
}
|
|
1081
|
+
if (wasDirty && !self._wave.emittedSettleThisWave && self._value.terminal === void 0 && !self._isAsyncPool()) {
|
|
1082
|
+
self._down([["RESOLVED"]]);
|
|
1083
|
+
}
|
|
1084
|
+
for (let i = 0; i < self._dep.batch.length; i++) {
|
|
1085
|
+
self._dep.batch[i] = null;
|
|
1086
|
+
self._dep.waveData[i] = [];
|
|
1087
|
+
self._dep.waveTokens[i] = void 0;
|
|
1088
|
+
self._dep.terminalInput[i] = void 0;
|
|
1089
|
+
}
|
|
1090
|
+
self._wave.emittedDirtyThisWave = false;
|
|
1091
|
+
}
|
|
1092
|
+
|
|
1093
|
+
// src/node/node-runtime-host.ts
|
|
1094
|
+
function nodeRuntimeHost(node2) {
|
|
1095
|
+
return node2;
|
|
1096
|
+
}
|
|
1097
|
+
|
|
1098
|
+
// src/node/node-lifecycle-runtime.ts
|
|
1099
|
+
function nodeActivate(self) {
|
|
1100
|
+
self._lifecycle.activated = true;
|
|
1101
|
+
const seedRestoredDeps = self._restoredActivationPending;
|
|
1102
|
+
self._restoredActivationPending = false;
|
|
1103
|
+
self._dep.unsubs = new Array(self._slot.deps.length);
|
|
1104
|
+
self._dep.idxBoxes = new Array(self._slot.deps.length);
|
|
1105
|
+
for (const dep of self._slot.deps) self._subscribeDepAt(dep, { seedRestored: seedRestoredDeps });
|
|
1106
|
+
if (self._slot.deps.length === 0 && self._slot.handle !== null && !self._wave.hasCalledFnOnce) {
|
|
1107
|
+
self._runWave();
|
|
1108
|
+
}
|
|
1109
|
+
}
|
|
1110
|
+
function nodeSubscribeDepAt(self, depNode, opts = {}) {
|
|
1111
|
+
const idx0 = self._slot.deps.indexOf(depNode);
|
|
1112
|
+
const box = { v: idx0 };
|
|
1113
|
+
let ignoreInitialPush = opts.seedRestored === true;
|
|
1114
|
+
if (ignoreInitialPush && idx0 !== -1) {
|
|
1115
|
+
self._seedRestoredDepAt(idx0, depNode);
|
|
1116
|
+
const dep = nodeRuntimeHost(depNode);
|
|
1117
|
+
if (dep._value.terminal !== void 0 && !dep._slot.resubscribable) {
|
|
1118
|
+
self._dep.unsubs[idx0] = () => {
|
|
1119
|
+
};
|
|
1120
|
+
self._dep.idxBoxes[idx0] = box;
|
|
1121
|
+
return;
|
|
1122
|
+
}
|
|
1123
|
+
}
|
|
1124
|
+
const unsub = depNode.subscribe((msg, delivery) => {
|
|
1125
|
+
if (ignoreInitialPush && delivery === void 0) return;
|
|
1126
|
+
if (ignoreInitialPush) ignoreInitialPush = false;
|
|
1127
|
+
if (box.v === -1) return;
|
|
1128
|
+
self._receiveFromDep(box.v, msg, delivery);
|
|
1129
|
+
});
|
|
1130
|
+
if (ignoreInitialPush && idx0 !== -1 && box.v !== -1) self._seedRestoredDepAt(idx0, depNode);
|
|
1131
|
+
ignoreInitialPush = false;
|
|
1132
|
+
if (idx0 !== -1) {
|
|
1133
|
+
self._dep.unsubs[idx0] = unsub;
|
|
1134
|
+
self._dep.idxBoxes[idx0] = box;
|
|
1135
|
+
}
|
|
1136
|
+
}
|
|
1137
|
+
function nodeSeedRestoredDepAt(self, idx, depNode) {
|
|
1138
|
+
const dep = nodeRuntimeHost(depNode);
|
|
1139
|
+
const seedData = dep._value.hasData && !dep._slot.pull;
|
|
1140
|
+
self._dep.batch[idx] = null;
|
|
1141
|
+
self._dep.waveData[idx] = [];
|
|
1142
|
+
self._dep.waveTokens[idx] = void 0;
|
|
1143
|
+
self._dep.prev[idx] = seedData ? dep._value.cache : SENTINEL;
|
|
1144
|
+
self._dep.hasData[idx] = seedData;
|
|
1145
|
+
self._dep.dirty[idx] = false;
|
|
1146
|
+
self._dep.tier[idx] = seedData ? 3 : 0;
|
|
1147
|
+
self._dep.terminal[idx] = dep._value.terminal;
|
|
1148
|
+
self._dep.terminalInput[idx] = void 0;
|
|
1149
|
+
}
|
|
1150
|
+
function nodeDeactivate(self) {
|
|
1151
|
+
self._lifecycle.activated = false;
|
|
1152
|
+
for (const u of self._dep.unsubs) if (u) u();
|
|
1153
|
+
self._dep.unsubs = [];
|
|
1154
|
+
self._dep.idxBoxes = [];
|
|
1155
|
+
for (const fn of self._hooks.onDeactivation) fn();
|
|
1156
|
+
self._hooks.onDeactivation = [];
|
|
1157
|
+
self._hooks.onInvalidate = [];
|
|
1158
|
+
const isCompute = self._slot.handle !== null || self._slot.deps.length > 0;
|
|
1159
|
+
if (isCompute) {
|
|
1160
|
+
self._value.cache = SENTINEL;
|
|
1161
|
+
self._value.hasData = false;
|
|
1162
|
+
self._value.status = "sentinel";
|
|
1163
|
+
}
|
|
1164
|
+
self._resetDepState();
|
|
1165
|
+
self._wave.hasCalledFnOnce = false;
|
|
1166
|
+
self._control.pauseLockset.clear();
|
|
1167
|
+
self._control.pauseBuffer = [];
|
|
1168
|
+
self._control.pausedDepWaveOccurred = false;
|
|
1169
|
+
self._control.demandOwed = void 0;
|
|
1170
|
+
self._control.activePull = void 0;
|
|
1171
|
+
self._control.pullDirtyOwed = false;
|
|
1172
|
+
self._value.replayRing = [];
|
|
1173
|
+
if (!self._privateState.persist) self._privateState.value = SENTINEL;
|
|
1174
|
+
}
|
|
1175
|
+
function nodeSubscriberCount(self) {
|
|
1176
|
+
return self._lifecycle.subscribers.size;
|
|
1177
|
+
}
|
|
1178
|
+
function nodeIsRuntimeQuiescentForRelease(self) {
|
|
1179
|
+
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;
|
|
1180
|
+
}
|
|
1181
|
+
function nodeReleaseRuntime(self) {
|
|
1182
|
+
if (self._released) return;
|
|
1183
|
+
self._released = true;
|
|
1184
|
+
const node2 = self;
|
|
1185
|
+
releasedNodes.add(node2);
|
|
1186
|
+
let releaseError;
|
|
1187
|
+
const recordReleaseError = (error) => {
|
|
1188
|
+
if (releaseError === void 0) releaseError = error;
|
|
1189
|
+
};
|
|
1190
|
+
self._lifecycle.activated = false;
|
|
1191
|
+
for (const u of self._dep.unsubs) {
|
|
1192
|
+
try {
|
|
1193
|
+
u();
|
|
1194
|
+
} catch (error) {
|
|
1195
|
+
recordReleaseError(error);
|
|
1196
|
+
}
|
|
1197
|
+
}
|
|
1198
|
+
for (const fn of self._hooks.onDeactivation) {
|
|
1199
|
+
try {
|
|
1200
|
+
fn();
|
|
1201
|
+
} catch (error) {
|
|
1202
|
+
recordReleaseError(error);
|
|
1203
|
+
}
|
|
1204
|
+
}
|
|
1205
|
+
self._dep.unsubs = [];
|
|
1206
|
+
self._dep.idxBoxes = [];
|
|
1207
|
+
self._lifecycle.subscribers.clear();
|
|
1208
|
+
if (self._slot.handle !== null) {
|
|
1209
|
+
self._slot.dispatcher.unregister(self._slot.handle);
|
|
1210
|
+
self._slot.handle = null;
|
|
1211
|
+
}
|
|
1212
|
+
self._slot.deps = [];
|
|
1213
|
+
self._dep.batch = [];
|
|
1214
|
+
self._dep.waveData = [];
|
|
1215
|
+
self._dep.waveTokens = [];
|
|
1216
|
+
self._dep.prev = [];
|
|
1217
|
+
self._dep.hasData = [];
|
|
1218
|
+
self._dep.dirty = [];
|
|
1219
|
+
self._dep.tier = [];
|
|
1220
|
+
self._dep.terminal = [];
|
|
1221
|
+
self._dep.terminalInput = [];
|
|
1222
|
+
self._value.cache = SENTINEL;
|
|
1223
|
+
self._value.hasData = false;
|
|
1224
|
+
self._value.status = "sentinel";
|
|
1225
|
+
self._value.terminal = void 0;
|
|
1226
|
+
self._value.replayRing = [];
|
|
1227
|
+
self._privateState.value = SENTINEL;
|
|
1228
|
+
self._privateState.persist = false;
|
|
1229
|
+
self._syncCtx = null;
|
|
1230
|
+
self._resetDepState();
|
|
1231
|
+
self._hooks.onDeactivation = [];
|
|
1232
|
+
self._hooks.onInvalidate = [];
|
|
1233
|
+
self._control.pauseLockset.clear();
|
|
1234
|
+
self._control.pauseBuffer = [];
|
|
1235
|
+
self._control.pausedDepWaveOccurred = false;
|
|
1236
|
+
self._control.demandOwed = void 0;
|
|
1237
|
+
self._control.activePull = void 0;
|
|
1238
|
+
self._control.pullDirtyOwed = false;
|
|
1239
|
+
self._restoredActivationPending = false;
|
|
1240
|
+
checkpointReaders.delete(node2);
|
|
1241
|
+
restoreWriters.delete(node2);
|
|
1242
|
+
runtimeReleasers.delete(node2);
|
|
1243
|
+
runtimeQuiescenceReaders.delete(node2);
|
|
1244
|
+
subscriberCountReaders.delete(node2);
|
|
1245
|
+
activationReaders.delete(node2);
|
|
1246
|
+
ownerTokens.delete(node2);
|
|
1247
|
+
topologyDepsChangedObservers.delete(node2);
|
|
1248
|
+
self._core.releaseSlot(self._id);
|
|
1249
|
+
if (releaseError !== void 0) throw releaseError;
|
|
1250
|
+
}
|
|
1251
|
+
function nodeResetDepState(self) {
|
|
1252
|
+
const n = self._slot.deps.length;
|
|
1253
|
+
for (let i = 0; i < n; i++) {
|
|
1254
|
+
self._dep.batch[i] = null;
|
|
1255
|
+
self._dep.waveData[i] = [];
|
|
1256
|
+
self._dep.waveTokens[i] = void 0;
|
|
1257
|
+
self._dep.prev[i] = SENTINEL;
|
|
1258
|
+
self._dep.hasData[i] = false;
|
|
1259
|
+
self._dep.dirty[i] = false;
|
|
1260
|
+
self._dep.tier[i] = 0;
|
|
1261
|
+
self._dep.terminal[i] = void 0;
|
|
1262
|
+
self._dep.terminalInput[i] = void 0;
|
|
1263
|
+
}
|
|
1264
|
+
self._wave.pending = 0;
|
|
1265
|
+
self._wave.emittedDirtyThisWave = false;
|
|
1266
|
+
}
|
|
1267
|
+
|
|
1268
|
+
// src/batch/batch.ts
|
|
1269
|
+
var active = null;
|
|
1270
|
+
var boundaryOwner = null;
|
|
1271
|
+
function currentBatch() {
|
|
1272
|
+
return active !== null;
|
|
1273
|
+
}
|
|
1274
|
+
function currentBoundaryBatchToken() {
|
|
1275
|
+
return active ?? boundaryOwner ?? void 0;
|
|
1276
|
+
}
|
|
1277
|
+
function deferToBatch(target, tier3Wave) {
|
|
1278
|
+
if (active === null) return false;
|
|
1279
|
+
if (!active.deferred.has(target)) active.order.push(target);
|
|
1280
|
+
active.deferred.set(target, tier3Wave);
|
|
1281
|
+
return true;
|
|
1282
|
+
}
|
|
1283
|
+
function deferAfterBatchForTarget(target, fn) {
|
|
1284
|
+
if (active === null || !active.deferred.has(target)) return false;
|
|
1285
|
+
const owner = active;
|
|
1286
|
+
target.__deferBoundary(() => {
|
|
1287
|
+
if (owner.committed) fn();
|
|
1288
|
+
}, owner);
|
|
1289
|
+
return true;
|
|
1290
|
+
}
|
|
1291
|
+
function commit(b) {
|
|
1292
|
+
const prev = boundaryOwner;
|
|
1293
|
+
boundaryOwner = b;
|
|
1294
|
+
try {
|
|
1295
|
+
for (const target of b.order) {
|
|
1296
|
+
const wave = b.deferred.get(target);
|
|
1297
|
+
if (wave) target.__commitBatchedWave(wave);
|
|
1298
|
+
}
|
|
1299
|
+
b.committed = true;
|
|
1300
|
+
} catch (e) {
|
|
1301
|
+
dropBoundaryTasksForBatch(b);
|
|
1302
|
+
throw e;
|
|
1303
|
+
} finally {
|
|
1304
|
+
boundaryOwner = prev;
|
|
1305
|
+
}
|
|
1306
|
+
}
|
|
1307
|
+
function rollback(b) {
|
|
1308
|
+
dropBoundaryTasksForBatch(b);
|
|
1309
|
+
for (const target of b.order) target.__rollbackBatched();
|
|
1310
|
+
}
|
|
1311
|
+
function batch(fn) {
|
|
1312
|
+
enterWave();
|
|
1313
|
+
try {
|
|
1314
|
+
if (active !== null) {
|
|
1315
|
+
const outer = active;
|
|
1316
|
+
return fn({
|
|
1317
|
+
rollback: () => {
|
|
1318
|
+
outer.rolledBack = true;
|
|
1319
|
+
}
|
|
1320
|
+
});
|
|
1321
|
+
}
|
|
1322
|
+
const b = { order: [], deferred: /* @__PURE__ */ new Map(), committed: false, rolledBack: false };
|
|
1323
|
+
active = b;
|
|
1324
|
+
const bctx = {
|
|
1325
|
+
rollback: () => {
|
|
1326
|
+
b.rolledBack = true;
|
|
1327
|
+
}
|
|
1328
|
+
};
|
|
1329
|
+
let result;
|
|
1330
|
+
try {
|
|
1331
|
+
result = fn(bctx);
|
|
1332
|
+
} catch (e) {
|
|
1333
|
+
active = null;
|
|
1334
|
+
rollback(b);
|
|
1335
|
+
throw e;
|
|
1336
|
+
}
|
|
1337
|
+
active = null;
|
|
1338
|
+
if (b.rolledBack) rollback(b);
|
|
1339
|
+
else {
|
|
1340
|
+
commit(b);
|
|
1341
|
+
}
|
|
1342
|
+
return result;
|
|
1343
|
+
} finally {
|
|
1344
|
+
exitWave();
|
|
1345
|
+
}
|
|
1346
|
+
}
|
|
1347
|
+
|
|
1348
|
+
// src/json/codec.ts
|
|
1349
|
+
var JS_MIN_NORMAL_NUMBER = 2 ** -1022;
|
|
1350
|
+
function assertStableJsonNumber(value, path) {
|
|
1351
|
+
if (!Number.isFinite(value)) {
|
|
1352
|
+
throw new TypeError(`stableJsonString: non-finite number at ${path}`);
|
|
1353
|
+
}
|
|
1354
|
+
}
|
|
1355
|
+
function assertStrictJsonNumber(value, path) {
|
|
1356
|
+
assertStableJsonNumber(value, path);
|
|
1357
|
+
if (Object.is(value, -0)) {
|
|
1358
|
+
throw new TypeError(`stableJsonString: non-canonical number at ${path}`);
|
|
1359
|
+
}
|
|
1360
|
+
const abs = Math.abs(value);
|
|
1361
|
+
if (abs > 0 && abs < JS_MIN_NORMAL_NUMBER) {
|
|
1362
|
+
throw new TypeError(`stableJsonString: subnormal number at ${path}`);
|
|
1363
|
+
}
|
|
1364
|
+
if (Number.isInteger(value) && !Number.isSafeInteger(value)) {
|
|
1365
|
+
throw new TypeError(`stableJsonString: integer outside safe range at ${path}`);
|
|
1366
|
+
}
|
|
1367
|
+
}
|
|
1368
|
+
function sortedJsonValue(value, seen = /* @__PURE__ */ new Set(), path = "$", strictNumbers = false) {
|
|
1369
|
+
if (value === null) return null;
|
|
1370
|
+
if (typeof value === "string" || typeof value === "boolean") return value;
|
|
1371
|
+
if (typeof value === "number") {
|
|
1372
|
+
if (strictNumbers) assertStrictJsonNumber(value, path);
|
|
1373
|
+
else assertStableJsonNumber(value, path);
|
|
1374
|
+
return value;
|
|
1375
|
+
}
|
|
1376
|
+
if (typeof value !== "object") {
|
|
1377
|
+
throw new TypeError(`stableJsonString: value at ${path} is not JSON-encodable`);
|
|
1378
|
+
}
|
|
1379
|
+
if (seen.has(value)) throw new TypeError(`stableJsonString: circular reference at ${path}`);
|
|
1380
|
+
const proto = Object.getPrototypeOf(value);
|
|
1381
|
+
if (!Array.isArray(value) && proto !== Object.prototype && proto !== null) {
|
|
1382
|
+
throw new TypeError(`stableJsonString: non-plain object at ${path}`);
|
|
1383
|
+
}
|
|
1384
|
+
seen.add(value);
|
|
1385
|
+
try {
|
|
1386
|
+
if (Array.isArray(value)) {
|
|
1387
|
+
if (Object.getOwnPropertySymbols(value).length > 0) {
|
|
1388
|
+
throw new TypeError(`stableJsonString: symbol-keyed properties at ${path}`);
|
|
1389
|
+
}
|
|
1390
|
+
for (const key of Object.getOwnPropertyNames(value)) {
|
|
1391
|
+
const isIndex = /^(0|[1-9]\d*)$/.test(key) && Number.isSafeInteger(Number(key)) && Number(key) < value.length;
|
|
1392
|
+
const descriptor = Object.getOwnPropertyDescriptor(value, key);
|
|
1393
|
+
if (descriptor !== void 0 && ("get" in descriptor || "set" in descriptor)) {
|
|
1394
|
+
throw new TypeError(`stableJsonString: accessor property at ${path}.${key}`);
|
|
1395
|
+
}
|
|
1396
|
+
if (key !== "length" && !isIndex) {
|
|
1397
|
+
throw new TypeError(`stableJsonString: non-index array property at ${path}.${key}`);
|
|
1398
|
+
}
|
|
1399
|
+
if (key !== "length" && descriptor !== void 0 && !descriptor.enumerable) {
|
|
1400
|
+
throw new TypeError(`stableJsonString: non-enumerable array property at ${path}.${key}`);
|
|
1401
|
+
}
|
|
1402
|
+
}
|
|
1403
|
+
const out2 = [];
|
|
1404
|
+
for (let i = 0; i < value.length; i += 1) {
|
|
1405
|
+
if (!(i in value)) {
|
|
1406
|
+
throw new TypeError(`stableJsonString: sparse array hole at ${path}[${i}]`);
|
|
1407
|
+
}
|
|
1408
|
+
out2.push(sortedJsonValue(value[i], seen, `${path}[${i}]`, strictNumbers));
|
|
1409
|
+
}
|
|
1410
|
+
return out2;
|
|
1411
|
+
}
|
|
1412
|
+
if (Object.getOwnPropertySymbols(value).length > 0) {
|
|
1413
|
+
throw new TypeError(`stableJsonString: symbol-keyed properties at ${path}`);
|
|
1414
|
+
}
|
|
1415
|
+
for (const key of Object.getOwnPropertyNames(value)) {
|
|
1416
|
+
const descriptor = Object.getOwnPropertyDescriptor(value, key);
|
|
1417
|
+
if (descriptor !== void 0 && ("get" in descriptor || "set" in descriptor)) {
|
|
1418
|
+
throw new TypeError(`stableJsonString: accessor property at ${path}.${key}`);
|
|
1419
|
+
}
|
|
1420
|
+
if (descriptor !== void 0 && !descriptor.enumerable) {
|
|
1421
|
+
throw new TypeError(`stableJsonString: non-enumerable property at ${path}.${key}`);
|
|
1422
|
+
}
|
|
1423
|
+
}
|
|
1424
|
+
const out = /* @__PURE__ */ Object.create(null);
|
|
1425
|
+
for (const key of Object.keys(value).sort()) {
|
|
1426
|
+
out[key] = sortedJsonValue(
|
|
1427
|
+
value[key],
|
|
1428
|
+
seen,
|
|
1429
|
+
`${path}.${key}`,
|
|
1430
|
+
strictNumbers
|
|
1431
|
+
);
|
|
1432
|
+
}
|
|
1433
|
+
return out;
|
|
1434
|
+
} finally {
|
|
1435
|
+
seen.delete(value);
|
|
1436
|
+
}
|
|
1437
|
+
}
|
|
1438
|
+
function stableJsonString(value) {
|
|
1439
|
+
return JSON.stringify(sortedJsonValue(value));
|
|
1440
|
+
}
|
|
1441
|
+
function strictStableJsonString(value) {
|
|
1442
|
+
return JSON.stringify(sortedJsonValue(value, /* @__PURE__ */ new Set(), "$", true));
|
|
1443
|
+
}
|
|
1444
|
+
function jsonCodecFor() {
|
|
1445
|
+
const encoder = new TextEncoder();
|
|
1446
|
+
const decoder = new TextDecoder();
|
|
1447
|
+
return {
|
|
1448
|
+
encode(value) {
|
|
1449
|
+
return encoder.encode(stableJsonString(value));
|
|
1450
|
+
},
|
|
1451
|
+
decode(bytes) {
|
|
1452
|
+
return JSON.parse(decoder.decode(bytes));
|
|
1453
|
+
}
|
|
1454
|
+
};
|
|
1455
|
+
}
|
|
1456
|
+
var jsonCodec = jsonCodecFor();
|
|
1457
|
+
function bytesEqual(a, b) {
|
|
855
1458
|
if (a.byteLength !== b.byteLength) return false;
|
|
856
1459
|
for (let i = 0; i < a.byteLength; i += 1) {
|
|
857
1460
|
if (a[i] !== b[i]) return false;
|
|
@@ -1191,98 +1794,532 @@ function validateNodeVersionJson(value, path) {
|
|
|
1191
1794
|
throw new Error(`restoreGraph: ${path}.level must be 0 or 1`);
|
|
1192
1795
|
}
|
|
1193
1796
|
|
|
1194
|
-
// src/node/node.ts
|
|
1195
|
-
|
|
1196
|
-
|
|
1197
|
-
|
|
1198
|
-
|
|
1199
|
-
|
|
1200
|
-
|
|
1201
|
-
|
|
1202
|
-
|
|
1203
|
-
|
|
1204
|
-
|
|
1205
|
-
|
|
1206
|
-
|
|
1207
|
-
|
|
1208
|
-
|
|
1209
|
-
|
|
1210
|
-
|
|
1211
|
-
|
|
1212
|
-
|
|
1797
|
+
// src/node/node-output-runtime.ts
|
|
1798
|
+
function nodeDown(self, msgs) {
|
|
1799
|
+
if (self._released) return;
|
|
1800
|
+
validateDownPayloads(msgs);
|
|
1801
|
+
const deliveryWave = {};
|
|
1802
|
+
const assertVersionDataCompatible = (wave) => {
|
|
1803
|
+
for (const m of wave) {
|
|
1804
|
+
if (m[0] === "DATA") assertNodeVersionDataCompatible(self._version.policy, m[1]);
|
|
1805
|
+
}
|
|
1806
|
+
};
|
|
1807
|
+
const snapshotVersionData = (wave) => wave.map(
|
|
1808
|
+
(m) => m[0] === "DATA" ? ["DATA", snapshotNodeVersionData(self._version.policy, m[1])] : m
|
|
1809
|
+
);
|
|
1810
|
+
assertVersionDataCompatible(msgs);
|
|
1811
|
+
if (self._value.terminal !== void 0) {
|
|
1812
|
+
if (!msgs.some((m) => m[0] === "TEARDOWN")) return;
|
|
1813
|
+
self._value.hasTorndown = true;
|
|
1814
|
+
if (self._slot.resetOnTeardown) {
|
|
1815
|
+
self._value.cache = SENTINEL;
|
|
1816
|
+
self._value.hasData = false;
|
|
1817
|
+
}
|
|
1818
|
+
self._emitToSubs(["TEARDOWN"], { wave: deliveryWave, last: true });
|
|
1819
|
+
return;
|
|
1213
1820
|
}
|
|
1214
|
-
|
|
1215
|
-
|
|
1216
|
-
|
|
1217
|
-
|
|
1218
|
-
|
|
1219
|
-
|
|
1220
|
-
|
|
1221
|
-
|
|
1821
|
+
let sorted = [...msgs].sort((a, b) => messageTier(a[0]) - messageTier(b[0]));
|
|
1822
|
+
const firstInvalidate = sorted.findIndex((m) => m[0] === "INVALIDATE");
|
|
1823
|
+
if (firstInvalidate !== -1) {
|
|
1824
|
+
sorted = sorted.filter((m, i) => m[0] !== "INVALIDATE" || i === firstInvalidate);
|
|
1825
|
+
}
|
|
1826
|
+
const hasTeardown = sorted.some((m) => m[0] === "TEARDOWN");
|
|
1827
|
+
const hasTerminal = sorted.some((m) => m[0] === "COMPLETE" || m[0] === "ERROR");
|
|
1828
|
+
if (hasTeardown && !hasTerminal && self._value.terminal === void 0 && !self._value.hasTorndown) {
|
|
1829
|
+
sorted = [["COMPLETE"], ...sorted];
|
|
1830
|
+
}
|
|
1831
|
+
if (!self._wave.insideRunWave && currentBatch()) {
|
|
1832
|
+
const deferred = snapshotVersionData(sorted.filter((m) => isDeferredTier(m[0])));
|
|
1833
|
+
if (deferred.length > 0) {
|
|
1834
|
+
if (!self._wave.emittedDirtyThisWave) {
|
|
1835
|
+
self._wave.emittedDirtyThisWave = true;
|
|
1836
|
+
self._value.status = "dirty";
|
|
1837
|
+
self._emitToSubs(["DIRTY"], { wave: deliveryWave, last: false });
|
|
1838
|
+
}
|
|
1839
|
+
self._wave.batchDirtyOwed = true;
|
|
1840
|
+
deferToBatch(self, deferred);
|
|
1841
|
+
return;
|
|
1842
|
+
}
|
|
1222
1843
|
}
|
|
1844
|
+
if (self._shouldBufferOnPause()) {
|
|
1845
|
+
const buffered = snapshotVersionData(sorted.filter((m) => isPauseBufferedTier(m[0])));
|
|
1846
|
+
if (buffered.length > 0) {
|
|
1847
|
+
self._wave.emittedSettleThisWave = true;
|
|
1848
|
+
self._control.pauseBuffer.push(buffered);
|
|
1849
|
+
}
|
|
1850
|
+
sorted = sorted.filter((m) => !isPauseBufferedTier(m[0]));
|
|
1851
|
+
if (sorted.length === 0) return;
|
|
1852
|
+
}
|
|
1853
|
+
let dataCount = 0;
|
|
1854
|
+
let hasTier3 = false;
|
|
1855
|
+
let hasResolved = false;
|
|
1856
|
+
for (const m of sorted) {
|
|
1857
|
+
if (m[0] === "DATA") dataCount++;
|
|
1858
|
+
if (m[0] === "RESOLVED") hasResolved = true;
|
|
1859
|
+
if (isValueTier(m[0])) hasTier3 = true;
|
|
1860
|
+
}
|
|
1861
|
+
if (dataCount >= 1 && hasResolved) {
|
|
1862
|
+
throw new Error(
|
|
1863
|
+
"down: a wave cannot mix DATA and RESOLVED (tier-3 exclusivity, R-resolved-undirty)"
|
|
1864
|
+
);
|
|
1865
|
+
}
|
|
1866
|
+
const plannedVersions = new Array(sorted.length);
|
|
1867
|
+
if (dataCount > 0) {
|
|
1868
|
+
let plannedVersion = self._version.value;
|
|
1869
|
+
for (let i = 0; i < sorted.length; i++) {
|
|
1870
|
+
const m = sorted[i];
|
|
1871
|
+
if (m[0] !== "DATA") continue;
|
|
1872
|
+
plannedVersion = advanceNodeVersion(plannedVersion, self._version.policy, m[1]);
|
|
1873
|
+
plannedVersions[i] = plannedVersion;
|
|
1874
|
+
}
|
|
1875
|
+
}
|
|
1876
|
+
if (hasTier3 && (!self._wave.insideRunWave || self._control.pullDirtyOwed) && !self._wave.emittedDirtyThisWave) {
|
|
1877
|
+
self._wave.emittedDirtyThisWave = true;
|
|
1878
|
+
self._value.status = "dirty";
|
|
1879
|
+
self._emitToSubs(["DIRTY"], { wave: deliveryWave, last: false });
|
|
1880
|
+
}
|
|
1881
|
+
for (let i = 0; i < sorted.length; i++) {
|
|
1882
|
+
const m = sorted[i];
|
|
1883
|
+
const delivery = { wave: deliveryWave, last: i === sorted.length - 1 };
|
|
1884
|
+
if (isDeferredTier(m[0])) self._wave.emittedSettleThisWave = true;
|
|
1885
|
+
if (m[0] === "DIRTY") {
|
|
1886
|
+
if (!self._wave.emittedDirtyThisWave) {
|
|
1887
|
+
self._wave.emittedDirtyThisWave = true;
|
|
1888
|
+
self._value.status = "dirty";
|
|
1889
|
+
self._emitToSubs(["DIRTY"], delivery);
|
|
1890
|
+
}
|
|
1891
|
+
continue;
|
|
1892
|
+
}
|
|
1893
|
+
if (m[0] === "DATA") {
|
|
1894
|
+
const v = m[1];
|
|
1895
|
+
self._value.cache = v;
|
|
1896
|
+
self._value.hasData = true;
|
|
1897
|
+
self._value.status = "settled";
|
|
1898
|
+
self._version.value = plannedVersions[i];
|
|
1899
|
+
if (self._slot.replayN > 0) {
|
|
1900
|
+
self._value.replayRing.push(v);
|
|
1901
|
+
if (self._value.replayRing.length > self._slot.replayN) self._value.replayRing.shift();
|
|
1902
|
+
}
|
|
1903
|
+
self._emitToSubs(["DATA", v], delivery);
|
|
1904
|
+
continue;
|
|
1905
|
+
}
|
|
1906
|
+
if (m[0] === "RESOLVED") {
|
|
1907
|
+
self._value.status = self._value.hasData ? "resolved" : "sentinel";
|
|
1908
|
+
self._emitToSubs(["RESOLVED"], delivery);
|
|
1909
|
+
continue;
|
|
1910
|
+
}
|
|
1911
|
+
if (m[0] === "INVALIDATE") {
|
|
1912
|
+
self._invalidate(delivery);
|
|
1913
|
+
continue;
|
|
1914
|
+
}
|
|
1915
|
+
if (m[0] === "COMPLETE") {
|
|
1916
|
+
if (self._value.terminal !== void 0) continue;
|
|
1917
|
+
self._value.terminal = true;
|
|
1918
|
+
self._control.pauseBuffer = [];
|
|
1919
|
+
self._value.status = "completed";
|
|
1920
|
+
self._emitToSubs(["COMPLETE"], delivery);
|
|
1921
|
+
continue;
|
|
1922
|
+
}
|
|
1923
|
+
if (m[0] === "ERROR") {
|
|
1924
|
+
if (self._value.terminal !== void 0) continue;
|
|
1925
|
+
self._value.terminal = m[1];
|
|
1926
|
+
self._control.pauseBuffer = [];
|
|
1927
|
+
self._value.status = "errored";
|
|
1928
|
+
self._emitToSubs(["ERROR", m[1]], delivery);
|
|
1929
|
+
continue;
|
|
1930
|
+
}
|
|
1931
|
+
if (m[0] === "TEARDOWN") {
|
|
1932
|
+
self._value.hasTorndown = true;
|
|
1933
|
+
if (self._slot.resetOnTeardown) {
|
|
1934
|
+
self._value.cache = SENTINEL;
|
|
1935
|
+
self._value.hasData = false;
|
|
1936
|
+
}
|
|
1937
|
+
self._emitToSubs(["TEARDOWN"], delivery);
|
|
1938
|
+
}
|
|
1939
|
+
}
|
|
1940
|
+
if (!self._wave.insideRunWave) self._wave.emittedDirtyThisWave = false;
|
|
1223
1941
|
}
|
|
1224
|
-
function
|
|
1225
|
-
|
|
1226
|
-
}
|
|
1227
|
-
|
|
1228
|
-
|
|
1942
|
+
function nodeUp(self, msgs, towardDep, route) {
|
|
1943
|
+
if (self._released) return;
|
|
1944
|
+
const routeState = route ?? { demandFired: /* @__PURE__ */ new Map() };
|
|
1945
|
+
for (const m of msgs) {
|
|
1946
|
+
if (!isUpAllowed(m[0])) {
|
|
1947
|
+
throw new Error(
|
|
1948
|
+
`ctx.up: ${m[0]} is down-only (tier ${messageTier(m[0])}); up carries control tiers only (R-ctx-up)`
|
|
1949
|
+
);
|
|
1950
|
+
}
|
|
1951
|
+
}
|
|
1952
|
+
for (const m of msgs) {
|
|
1953
|
+
if (m[0] === "PAUSE") {
|
|
1954
|
+
self._pauseAcquire(m[1]);
|
|
1955
|
+
} else if (m[0] === "RESUME") {
|
|
1956
|
+
if (self._control.pauseLockset.has(m[1])) {
|
|
1957
|
+
self._pauseRelease(m[1]);
|
|
1958
|
+
} else {
|
|
1959
|
+
self._forwardUp(m, towardDep, routeState);
|
|
1960
|
+
}
|
|
1961
|
+
} else if (m[0] === "PULL") {
|
|
1962
|
+
const demand = normalizePullDemand(m[1]);
|
|
1963
|
+
if (self._slot.pull && demand.pullId === self._slot.pullLock) {
|
|
1964
|
+
if (!self._markDemandRouted(demand.pullId, routeState)) self._onDemand(demand);
|
|
1965
|
+
} else {
|
|
1966
|
+
self._forwardUp(["PULL", demand], towardDep, routeState);
|
|
1967
|
+
}
|
|
1968
|
+
} else if (self._slot.deps.length === 0) {
|
|
1969
|
+
if (m[0] === "INVALIDATE") self._down([["INVALIDATE"]]);
|
|
1970
|
+
} else {
|
|
1971
|
+
self._forwardUp(m, towardDep, routeState);
|
|
1972
|
+
}
|
|
1973
|
+
}
|
|
1229
1974
|
}
|
|
1230
|
-
function
|
|
1231
|
-
|
|
1975
|
+
function nodeMarkDemandRouted(self, lockId, route) {
|
|
1976
|
+
let holders = route.demandFired.get(lockId);
|
|
1977
|
+
if (holders === void 0) {
|
|
1978
|
+
holders = /* @__PURE__ */ new Set();
|
|
1979
|
+
route.demandFired.set(lockId, holders);
|
|
1980
|
+
}
|
|
1981
|
+
const node2 = self;
|
|
1982
|
+
if (holders.has(node2)) return true;
|
|
1983
|
+
holders.add(node2);
|
|
1984
|
+
return false;
|
|
1232
1985
|
}
|
|
1233
|
-
function
|
|
1234
|
-
|
|
1986
|
+
function nodeForwardUp(self, m, towardDep, route) {
|
|
1987
|
+
if (self._slot.deps.length === 0) return;
|
|
1988
|
+
if (towardDep !== void 0) {
|
|
1989
|
+
const d = self._slot.deps[towardDep];
|
|
1990
|
+
if (d !== void 0) nodeRuntimeHost(d)._up([m], void 0, route);
|
|
1991
|
+
} else {
|
|
1992
|
+
for (const dep of self._slot.deps) nodeRuntimeHost(dep)._up([m], void 0, route);
|
|
1993
|
+
}
|
|
1994
|
+
}
|
|
1995
|
+
function nodeIsPaused(self) {
|
|
1996
|
+
return self._control.pauseLockset.size > 0;
|
|
1997
|
+
}
|
|
1998
|
+
function nodeHasBoundaryPauseLock(self) {
|
|
1999
|
+
if (self._slot.pausable === false) return false;
|
|
2000
|
+
return self._control.pauseLockset.size > 0;
|
|
2001
|
+
}
|
|
2002
|
+
function nodeIsAsyncPool(self) {
|
|
2003
|
+
return self._slot.handle !== null && self._slot.dispatcher.poolKind(self._slot.handle.poolId) === "async";
|
|
2004
|
+
}
|
|
2005
|
+
function nodePauseAcquire(self, lockId) {
|
|
2006
|
+
self._control.pauseLockset.add(lockId);
|
|
2007
|
+
}
|
|
2008
|
+
function nodePauseRelease(self, lockId) {
|
|
2009
|
+
if (!self._control.pauseLockset.has(lockId)) return;
|
|
2010
|
+
self._control.pauseLockset.delete(lockId);
|
|
2011
|
+
if (self._slot.pull && self._control.demandOwed !== void 0) self._fireOwedDemandIfReady();
|
|
2012
|
+
if (self._hasBoundaryPauseLock()) return;
|
|
2013
|
+
scheduleBoundaryDrain(self._core);
|
|
2014
|
+
if (self._slot.pull) return;
|
|
2015
|
+
self._onResume();
|
|
2016
|
+
}
|
|
2017
|
+
function nodeOnResume(self) {
|
|
2018
|
+
if (self._value.terminal !== void 0) {
|
|
2019
|
+
self._control.pauseBuffer = [];
|
|
2020
|
+
self._control.pausedDepWaveOccurred = false;
|
|
2021
|
+
self._control.demandOwed = void 0;
|
|
2022
|
+
self._control.activePull = void 0;
|
|
2023
|
+
self._control.pullDirtyOwed = false;
|
|
2024
|
+
return;
|
|
2025
|
+
}
|
|
2026
|
+
if (self._control.pauseBuffer.length > 0) {
|
|
2027
|
+
const buf = self._control.pauseBuffer;
|
|
2028
|
+
self._control.pauseBuffer = [];
|
|
2029
|
+
for (const wave of buf) self._down(wave);
|
|
2030
|
+
}
|
|
2031
|
+
if (self._control.pausedDepWaveOccurred) {
|
|
2032
|
+
self._control.pausedDepWaveOccurred = false;
|
|
2033
|
+
self._tryRun();
|
|
2034
|
+
}
|
|
1235
2035
|
}
|
|
1236
|
-
function
|
|
1237
|
-
|
|
1238
|
-
|
|
1239
|
-
return read();
|
|
2036
|
+
function nodeCanFireDemand(self) {
|
|
2037
|
+
if (self._value.terminal !== void 0 || self._wave.pending > 0) return false;
|
|
2038
|
+
return self._control.pauseLockset.size === 0;
|
|
1240
2039
|
}
|
|
1241
|
-
function
|
|
1242
|
-
|
|
1243
|
-
|
|
1244
|
-
|
|
2040
|
+
function nodeDeliverPullDemand(self, demand) {
|
|
2041
|
+
self._control.demandOwed = void 0;
|
|
2042
|
+
self._control.activePull = demand;
|
|
2043
|
+
self._control.inDeliverDemand = true;
|
|
2044
|
+
try {
|
|
2045
|
+
self._firePullDemand();
|
|
2046
|
+
} finally {
|
|
2047
|
+
self._control.activePull = void 0;
|
|
2048
|
+
self._control.inDeliverDemand = false;
|
|
2049
|
+
}
|
|
2050
|
+
}
|
|
2051
|
+
function nodeOnDemand(self, demand) {
|
|
2052
|
+
if (self._control.inDeliverDemand) return;
|
|
2053
|
+
if (self._canFireDemand()) self._deliverPullDemand(demand);
|
|
2054
|
+
else self._control.demandOwed = demand;
|
|
2055
|
+
}
|
|
2056
|
+
function nodeFirePullDemand(self) {
|
|
2057
|
+
let drainedBuffer = false;
|
|
2058
|
+
if (self._control.pauseBuffer.length > 0) {
|
|
2059
|
+
const buf = self._control.pauseBuffer;
|
|
2060
|
+
self._control.pauseBuffer = [];
|
|
2061
|
+
for (const wave of buf) self._down(wave);
|
|
2062
|
+
drainedBuffer = true;
|
|
2063
|
+
}
|
|
2064
|
+
if (drainedBuffer) return;
|
|
2065
|
+
if (self._control.pausedDepWaveOccurred) {
|
|
2066
|
+
const gated = self._slot.handle !== null && !self._wave.hasCalledFnOnce && !(self._slot.partial || self._allDepsSettled());
|
|
2067
|
+
if (self._wave.pending > 0 || gated) return;
|
|
2068
|
+
self._control.pausedDepWaveOccurred = false;
|
|
2069
|
+
self._wave.emittedDirtyThisWave = false;
|
|
2070
|
+
self._control.pullDirtyOwed = true;
|
|
2071
|
+
try {
|
|
2072
|
+
self._tryRun();
|
|
2073
|
+
} finally {
|
|
2074
|
+
self._control.pullDirtyOwed = false;
|
|
2075
|
+
}
|
|
2076
|
+
return;
|
|
2077
|
+
}
|
|
2078
|
+
if (self._slot.handle !== null) {
|
|
2079
|
+
if (!self._wave.hasCalledFnOnce && !(self._slot.partial || self._allDepsSettled())) return;
|
|
2080
|
+
self._wave.emittedDirtyThisWave = false;
|
|
2081
|
+
self._control.pullDirtyOwed = true;
|
|
2082
|
+
try {
|
|
2083
|
+
self._runWave();
|
|
2084
|
+
} finally {
|
|
2085
|
+
self._control.pullDirtyOwed = false;
|
|
2086
|
+
}
|
|
2087
|
+
}
|
|
1245
2088
|
}
|
|
1246
|
-
function
|
|
1247
|
-
|
|
2089
|
+
function nodeFireOwedDemandIfReady(self) {
|
|
2090
|
+
if (self._control.inDeliverDemand) return;
|
|
2091
|
+
if (self._slot.pull && self._control.demandOwed !== void 0 && self._canFireDemand()) {
|
|
2092
|
+
self._deliverPullDemand(self._control.demandOwed);
|
|
2093
|
+
}
|
|
1248
2094
|
}
|
|
1249
|
-
function
|
|
1250
|
-
|
|
2095
|
+
function nodeShouldBufferOnPause(self) {
|
|
2096
|
+
if (self._slot.pausable === false) return false;
|
|
2097
|
+
if (!self._isPaused() && !self._isPullQuiet()) return false;
|
|
2098
|
+
if (self._slot.pausable === "resumeAll") return true;
|
|
2099
|
+
if (!self._wave.insideRunWave && self._isAsyncPool() && self._slot.deps.length > 0) return true;
|
|
2100
|
+
return false;
|
|
1251
2101
|
}
|
|
1252
|
-
function
|
|
1253
|
-
|
|
2102
|
+
function nodeInvalidate(self, delivery) {
|
|
2103
|
+
if (!self._value.hasData) return;
|
|
2104
|
+
self._value.cache = SENTINEL;
|
|
2105
|
+
self._value.hasData = false;
|
|
2106
|
+
self._value.status = "sentinel";
|
|
2107
|
+
self._value.replayRing = [];
|
|
2108
|
+
for (const fn of self._hooks.onInvalidate) fn();
|
|
2109
|
+
self._emitToSubs(["INVALIDATE"], delivery);
|
|
2110
|
+
}
|
|
2111
|
+
function nodeAllDepsTerminal(self) {
|
|
2112
|
+
if (self._slot.deps.length === 0) return false;
|
|
2113
|
+
for (const tm of self._dep.terminal) if (tm === void 0) return false;
|
|
2114
|
+
return true;
|
|
1254
2115
|
}
|
|
1255
|
-
function
|
|
1256
|
-
|
|
2116
|
+
function nodeResetLifecycle(self) {
|
|
2117
|
+
for (const u of self._dep.unsubs) if (u) u();
|
|
2118
|
+
self._dep.unsubs = [];
|
|
2119
|
+
self._dep.idxBoxes = [];
|
|
2120
|
+
self._lifecycle.subscribers.clear();
|
|
2121
|
+
self._lifecycle.activated = false;
|
|
2122
|
+
self._value.terminal = void 0;
|
|
2123
|
+
self._value.hasTorndown = false;
|
|
2124
|
+
self._wave.hasCalledFnOnce = false;
|
|
2125
|
+
self._resetDepState();
|
|
2126
|
+
self._control.pauseLockset.clear();
|
|
2127
|
+
self._control.pauseBuffer = [];
|
|
2128
|
+
self._control.pausedDepWaveOccurred = false;
|
|
2129
|
+
self._control.demandOwed = void 0;
|
|
2130
|
+
self._control.activePull = void 0;
|
|
2131
|
+
self._control.pullDirtyOwed = false;
|
|
2132
|
+
self._value.replayRing = [];
|
|
2133
|
+
const isCompute = self._slot.handle !== null || self._slot.deps.length > 0;
|
|
2134
|
+
if (isCompute) {
|
|
2135
|
+
self._value.cache = SENTINEL;
|
|
2136
|
+
self._value.hasData = false;
|
|
2137
|
+
self._value.status = "sentinel";
|
|
2138
|
+
} else {
|
|
2139
|
+
self._value.status = self._value.hasData ? "settled" : "sentinel";
|
|
2140
|
+
}
|
|
2141
|
+
if (!self._privateState.persist) self._privateState.value = SENTINEL;
|
|
2142
|
+
}
|
|
2143
|
+
function nodeEmitToSubs(self, msg, delivery) {
|
|
2144
|
+
if (self._released) return;
|
|
2145
|
+
const subs = [...self._lifecycle.subscribers];
|
|
2146
|
+
for (const sink of subs) sink(msg, delivery);
|
|
2147
|
+
}
|
|
2148
|
+
function nodeCommitBatchedWave(self, wave) {
|
|
2149
|
+
self._wave.batchDirtyOwed = false;
|
|
2150
|
+
self._down(wave);
|
|
2151
|
+
}
|
|
2152
|
+
function nodeRollbackBatched(self) {
|
|
2153
|
+
if (self._wave.batchDirtyOwed) {
|
|
2154
|
+
self._wave.batchDirtyOwed = false;
|
|
2155
|
+
self._wave.emittedDirtyThisWave = false;
|
|
2156
|
+
self._value.status = self._value.hasData ? "settled" : "sentinel";
|
|
2157
|
+
self._emitToSubs(["RESOLVED"]);
|
|
2158
|
+
}
|
|
2159
|
+
}
|
|
2160
|
+
function nodeDeferBoundary(self, fn, batchToken) {
|
|
2161
|
+
deferRewire(self._core, fn, {
|
|
2162
|
+
batchToken,
|
|
2163
|
+
isReady: () => !self._hasBoundaryPauseLock()
|
|
2164
|
+
});
|
|
1257
2165
|
}
|
|
1258
|
-
|
|
1259
|
-
|
|
2166
|
+
|
|
2167
|
+
// src/node/node-rewire-runtime.ts
|
|
2168
|
+
function nodeRequestRewireNext(self, op) {
|
|
2169
|
+
deferRewire(self._core, () => self._applyRewireNext(op), {
|
|
2170
|
+
batchToken: currentBoundaryBatchToken(),
|
|
2171
|
+
isReady: () => !self._hasBoundaryPauseLock()
|
|
2172
|
+
});
|
|
1260
2173
|
}
|
|
1261
|
-
function
|
|
1262
|
-
|
|
2174
|
+
function nodeRequestUpNext(self, msgs, towardDep) {
|
|
2175
|
+
deferRewire(
|
|
2176
|
+
self._core,
|
|
2177
|
+
() => {
|
|
2178
|
+
if (!self._released) self._up(msgs, towardDep);
|
|
2179
|
+
},
|
|
2180
|
+
{
|
|
2181
|
+
batchToken: currentBoundaryBatchToken(),
|
|
2182
|
+
isReady: () => !self._hasBoundaryPauseLock()
|
|
2183
|
+
}
|
|
2184
|
+
);
|
|
1263
2185
|
}
|
|
1264
|
-
function
|
|
1265
|
-
if (
|
|
1266
|
-
|
|
1267
|
-
|
|
1268
|
-
|
|
1269
|
-
|
|
1270
|
-
|
|
2186
|
+
function nodeApplyRewireNext(self, op) {
|
|
2187
|
+
if (self._released) return;
|
|
2188
|
+
try {
|
|
2189
|
+
if (op.kind === "add") {
|
|
2190
|
+
const next = self._slot.deps.includes(op.dep) ? [...self._slot.deps] : [...self._slot.deps, op.dep];
|
|
2191
|
+
self._rewire(next, op.fn, { allowTerminalOwner: true });
|
|
2192
|
+
} else if (op.kind === "remove") {
|
|
2193
|
+
self._rewire(
|
|
2194
|
+
self._slot.deps.filter((d) => d !== op.dep),
|
|
2195
|
+
op.fn,
|
|
2196
|
+
{ allowTerminalOwner: true }
|
|
2197
|
+
);
|
|
2198
|
+
} else {
|
|
2199
|
+
self._rewire(self._dedupDeps(op.deps), op.fn, { allowTerminalOwner: true });
|
|
2200
|
+
}
|
|
2201
|
+
} catch (e) {
|
|
2202
|
+
self._down([["ERROR", errorPayload(e, "rewireNext op failed")]]);
|
|
1271
2203
|
}
|
|
1272
|
-
const params = demand.params;
|
|
1273
|
-
return params === void 0 ? { pullId } : { pullId, params };
|
|
1274
2204
|
}
|
|
1275
|
-
function
|
|
1276
|
-
|
|
1277
|
-
|
|
1278
|
-
|
|
1279
|
-
|
|
1280
|
-
|
|
1281
|
-
|
|
2205
|
+
function nodeRewire(self, newDeps, fn, opts = {}) {
|
|
2206
|
+
const node2 = self;
|
|
2207
|
+
if (self._value.terminal !== void 0 && !opts.allowTerminalOwner)
|
|
2208
|
+
throw new Error(
|
|
2209
|
+
"rewire: node is terminal (completed/errored) \u2014 cannot rewire (R-rewire / D42)"
|
|
2210
|
+
);
|
|
2211
|
+
if (self._wave.insideRunWave)
|
|
2212
|
+
throw new Error(
|
|
2213
|
+
"rewire: mid-fn topology mutation \u2014 a fn mutating its own deps mid-wave is the feedback cycle (R-rewire / D37)"
|
|
2214
|
+
);
|
|
2215
|
+
if (self._wave.inDepMutation)
|
|
2216
|
+
throw new Error(
|
|
2217
|
+
"rewire: reentrant dep mutation \u2014 another replaceDeps/subscribeDep/unsubscribeDep is in flight (R-rewire)"
|
|
2218
|
+
);
|
|
2219
|
+
if (newDeps.includes(node2)) throw new Error("rewire: self-dependency rejected (R-rewire / D42)");
|
|
2220
|
+
const oldDeps = self._slot.deps;
|
|
2221
|
+
const added = newDeps.filter((d) => !oldDeps.includes(d));
|
|
2222
|
+
for (const d of added) {
|
|
2223
|
+
if (self._reachableUpstream(d, node2))
|
|
2224
|
+
throw new Error(
|
|
2225
|
+
"rewire: would create a cycle \u2014 dep already transitively depends on this node (R-rewire / D42)"
|
|
2226
|
+
);
|
|
2227
|
+
const dep = nodeRuntimeHost(d);
|
|
2228
|
+
if (dep._value.terminal !== void 0 && !dep._slot.resubscribable)
|
|
2229
|
+
throw new Error(
|
|
2230
|
+
"rewire: cannot add a non-resubscribable terminal dep \u2014 would wedge (R-rewire / D42)"
|
|
2231
|
+
);
|
|
2232
|
+
self._assertRewireDepOwner(d);
|
|
2233
|
+
}
|
|
2234
|
+
if (deferAfterBatchForTarget(node2, () => {
|
|
2235
|
+
self._rewire(newDeps, fn, { ...opts, allowTerminalOwner: true });
|
|
2236
|
+
})) {
|
|
2237
|
+
return true;
|
|
2238
|
+
}
|
|
2239
|
+
if (!self._lifecycle.activated) self._restoredActivationPending = false;
|
|
2240
|
+
self._wave.inDepMutation = true;
|
|
2241
|
+
self._wave.rewireRunPending = false;
|
|
2242
|
+
let zeroDepUnDirty = false;
|
|
2243
|
+
try {
|
|
2244
|
+
const oldHandle = self._slot.handle;
|
|
2245
|
+
self._slot.handle = self._slot.dispatcher.register(fn, self._slot.pool);
|
|
2246
|
+
if (oldHandle !== null) self._slot.dispatcher.unregister(oldHandle);
|
|
2247
|
+
const removed = oldDeps.filter((d) => !newDeps.includes(d));
|
|
2248
|
+
let removedDirtyContributor = false;
|
|
2249
|
+
for (const d of removed) {
|
|
2250
|
+
const oldIdx = oldDeps.indexOf(d);
|
|
2251
|
+
if (self._dep.dirty[oldIdx]) {
|
|
2252
|
+
removedDirtyContributor = true;
|
|
2253
|
+
self._wave.pending--;
|
|
2254
|
+
}
|
|
2255
|
+
if (self._lifecycle.activated) {
|
|
2256
|
+
const box = self._dep.idxBoxes[oldIdx];
|
|
2257
|
+
if (box) box.v = -1;
|
|
2258
|
+
const unsub = self._dep.unsubs[oldIdx];
|
|
2259
|
+
if (unsub) unsub();
|
|
2260
|
+
}
|
|
2261
|
+
}
|
|
2262
|
+
const n = newDeps.length;
|
|
2263
|
+
const newBatch = new Array(n).fill(null);
|
|
2264
|
+
const newPrev = new Array(n).fill(SENTINEL);
|
|
2265
|
+
const newHasData = new Array(n).fill(false);
|
|
2266
|
+
const newDirty = new Array(n).fill(false);
|
|
2267
|
+
const newTier = new Array(n).fill(0);
|
|
2268
|
+
const newTerminal = new Array(n).fill(void 0);
|
|
2269
|
+
const newTerminalInput = new Array(n).fill(void 0);
|
|
2270
|
+
const newUnsubs = new Array(n);
|
|
2271
|
+
const newBoxes = new Array(n);
|
|
2272
|
+
for (let j = 0; j < n; j++) {
|
|
2273
|
+
const oldIdx = oldDeps.indexOf(newDeps[j]);
|
|
2274
|
+
if (oldIdx !== -1) {
|
|
2275
|
+
newBatch[j] = self._dep.batch[oldIdx];
|
|
2276
|
+
newPrev[j] = self._dep.prev[oldIdx];
|
|
2277
|
+
newHasData[j] = self._dep.hasData[oldIdx];
|
|
2278
|
+
newDirty[j] = self._dep.dirty[oldIdx];
|
|
2279
|
+
newTier[j] = self._dep.tier[oldIdx];
|
|
2280
|
+
newTerminal[j] = self._dep.terminal[oldIdx];
|
|
2281
|
+
newUnsubs[j] = self._dep.unsubs[oldIdx];
|
|
2282
|
+
const box = self._dep.idxBoxes[oldIdx];
|
|
2283
|
+
if (box) box.v = j;
|
|
2284
|
+
newBoxes[j] = box;
|
|
2285
|
+
}
|
|
2286
|
+
}
|
|
2287
|
+
self._slot.deps = newDeps;
|
|
2288
|
+
self._dep.batch = newBatch;
|
|
2289
|
+
self._dep.prev = newPrev;
|
|
2290
|
+
self._dep.hasData = newHasData;
|
|
2291
|
+
self._dep.dirty = newDirty;
|
|
2292
|
+
self._dep.tier = newTier;
|
|
2293
|
+
self._dep.terminal = newTerminal;
|
|
2294
|
+
self._dep.terminalInput = newTerminalInput;
|
|
2295
|
+
self._dep.unsubs = newUnsubs;
|
|
2296
|
+
self._dep.idxBoxes = newBoxes;
|
|
2297
|
+
self._dep.waveData = newDeps.map(() => []);
|
|
2298
|
+
self._dep.waveTokens = new Array(newDeps.length).fill(void 0);
|
|
2299
|
+
self._syncCtx = null;
|
|
2300
|
+
if (self._lifecycle.activated) {
|
|
2301
|
+
for (const d of added) self._subscribeDepAt(d);
|
|
2302
|
+
}
|
|
2303
|
+
notifyTopologyDepsChanged(node2, oldDeps, newDeps);
|
|
2304
|
+
if (removedDirtyContributor && self._wave.pending === 0 && self._value.status === "dirty") {
|
|
2305
|
+
if (newDeps.length > 0) self._wave.rewireRunPending = true;
|
|
2306
|
+
else zeroDepUnDirty = true;
|
|
1282
2307
|
}
|
|
2308
|
+
} finally {
|
|
2309
|
+
self._wave.inDepMutation = false;
|
|
2310
|
+
}
|
|
2311
|
+
if (self._wave.rewireRunPending) {
|
|
2312
|
+
self._wave.rewireRunPending = false;
|
|
2313
|
+
self._settleRewire();
|
|
2314
|
+
} else if (zeroDepUnDirty) {
|
|
2315
|
+
if (self._wave.emittedDirtyThisWave) self._down([["RESOLVED"]]);
|
|
2316
|
+
else self._value.status = self._value.hasData ? "settled" : "sentinel";
|
|
1283
2317
|
}
|
|
2318
|
+
return false;
|
|
1284
2319
|
}
|
|
1285
|
-
|
|
2320
|
+
|
|
2321
|
+
// src/node/node.ts
|
|
2322
|
+
var Node = class _Node {
|
|
1286
2323
|
_core;
|
|
1287
2324
|
_id;
|
|
1288
2325
|
_slot;
|
|
@@ -1303,12 +2340,56 @@ var Node = class {
|
|
|
1303
2340
|
set _syncCtx(ctx) {
|
|
1304
2341
|
this._syncCtxState.value = ctx;
|
|
1305
2342
|
}
|
|
2343
|
+
static _retainIndirectRuntimeMethods(node2) {
|
|
2344
|
+
void node2._dep;
|
|
2345
|
+
void node2._hooks;
|
|
2346
|
+
void node2._restoredActivationPending;
|
|
2347
|
+
void node2._requestRewireNext;
|
|
2348
|
+
void node2._requestUpNext;
|
|
2349
|
+
void node2._applyRewireNext;
|
|
2350
|
+
void node2._reachableUpstream;
|
|
2351
|
+
void node2._assertRewireDepOwner;
|
|
2352
|
+
void node2._subscribeDepAt;
|
|
2353
|
+
void node2._seedRestoredDepAt;
|
|
2354
|
+
void node2._recordDepProjection;
|
|
2355
|
+
void node2._depProjectionHasData;
|
|
2356
|
+
void node2._receiveFromDep;
|
|
2357
|
+
void node2._releaseDepDirty;
|
|
2358
|
+
void node2._settleAfterAbsorbedTerminal;
|
|
2359
|
+
void node2._markDirty;
|
|
2360
|
+
void node2._maybeRun;
|
|
2361
|
+
void node2._settleRewire;
|
|
2362
|
+
void node2._tryRun;
|
|
2363
|
+
void node2._allDepsSettled;
|
|
2364
|
+
void node2._passthroughEmit;
|
|
2365
|
+
void node2._runWave;
|
|
2366
|
+
void node2._buildCtx;
|
|
2367
|
+
void node2._makeCtx;
|
|
2368
|
+
void node2._refreshCtx;
|
|
2369
|
+
void node2._makeState;
|
|
2370
|
+
void node2._markDemandRouted;
|
|
2371
|
+
void node2._forwardUp;
|
|
2372
|
+
void node2._isPullQuiet;
|
|
2373
|
+
void node2._isPaused;
|
|
2374
|
+
void node2._hasBoundaryPauseLock;
|
|
2375
|
+
void node2._isAsyncPool;
|
|
2376
|
+
void node2._pauseAcquire;
|
|
2377
|
+
void node2._pauseRelease;
|
|
2378
|
+
void node2._onResume;
|
|
2379
|
+
void node2._canFireDemand;
|
|
2380
|
+
void node2._deliverPullDemand;
|
|
2381
|
+
void node2._onDemand;
|
|
2382
|
+
void node2._firePullDemand;
|
|
2383
|
+
void node2._fireOwedDemandIfReady;
|
|
2384
|
+
void node2._shouldBufferOnPause;
|
|
2385
|
+
void node2._invalidate;
|
|
2386
|
+
void node2._allDepsTerminal;
|
|
2387
|
+
void node2._emitToSubs;
|
|
2388
|
+
}
|
|
1306
2389
|
constructor(deps, handleOrFn, opts = {}) {
|
|
1307
|
-
const core =
|
|
1308
|
-
constructingCore = void 0;
|
|
2390
|
+
const core = takeConstructingNodeCore();
|
|
1309
2391
|
const dispatcher = opts.dispatcher ?? defaultDispatcher;
|
|
1310
|
-
const environment =
|
|
1311
|
-
constructingEnvironment = void 0;
|
|
2392
|
+
const environment = takeConstructingEnvironmentDrivers() ?? EnvironmentDrivers.empty();
|
|
1312
2393
|
const pool = opts.pool ?? "sync";
|
|
1313
2394
|
const pausable = opts.pausable ?? true;
|
|
1314
2395
|
const pullLock = opts.pullId;
|
|
@@ -1479,6 +2560,7 @@ var Node = class {
|
|
|
1479
2560
|
runtimeQuiescenceReaders.set(this, () => this._isRuntimeQuiescentForRelease());
|
|
1480
2561
|
subscriberCountReaders.set(this, () => this._subscriberCount());
|
|
1481
2562
|
activationReaders.set(this, () => this._lifecycle.activated);
|
|
2563
|
+
_Node._retainIndirectRuntimeMethods(this);
|
|
1482
2564
|
}
|
|
1483
2565
|
/** R-pull (D55/D272): true while a pull node is not serving a PULL demand pulse. */
|
|
1484
2566
|
_isPullQuiet() {
|
|
@@ -1583,58 +2665,6 @@ var Node = class {
|
|
|
1583
2665
|
exitWave();
|
|
1584
2666
|
}
|
|
1585
2667
|
}
|
|
1586
|
-
// ── deferred self-rewire (R-rewire-deferred / D47): ctx.rewireNext drain support ──
|
|
1587
|
-
/**
|
|
1588
|
-
* Enqueue a deferred self-rewire op (issued from this node's fn via `ctx.rewireNext`).
|
|
1589
|
-
* Applied at the committed wave boundary (boundary.ts drain), never in place — the in-fn
|
|
1590
|
-
* immediate path (`subscribeDep`/`replaceDeps`/`unsubscribeDep`) still throws mid-run (D37/R-reentrancy).
|
|
1591
|
-
*/
|
|
1592
|
-
_requestRewireNext(op) {
|
|
1593
|
-
deferRewire(this._core, () => this._applyRewireNext(op), {
|
|
1594
|
-
batchToken: currentBoundaryBatchToken(),
|
|
1595
|
-
isReady: () => !this._hasBoundaryPauseLock()
|
|
1596
|
-
});
|
|
1597
|
-
}
|
|
1598
|
-
/**
|
|
1599
|
-
* Enqueue a deferred up-going control/demand wave (R-up-routing / R-pull / D269): at the committed wave
|
|
1600
|
-
* boundary, route `msgs` up from THIS node (broadcast, or up the single `towardDep` edge). The
|
|
1601
|
-
* deferred form of `ctx.up` — the SELF-demand path: a consumer issues `ctx.upNext([[PULL,
|
|
1602
|
-
* { pullId }]])` to demand a dep it ALSO reads; the demand applies at the boundary (not mid-fn), so
|
|
1603
|
-
* the pull node's delivery loops back as a FRESH wave rather than re-entering the consumer (D37 /
|
|
1604
|
-
* R-reentrancy). Rides the same R-rewire-deferred (D47) drain as ctx.rewireNext.
|
|
1605
|
-
*/
|
|
1606
|
-
_requestUpNext(msgs, towardDep) {
|
|
1607
|
-
deferRewire(
|
|
1608
|
-
this._core,
|
|
1609
|
-
() => {
|
|
1610
|
-
if (!this._released) this._up(msgs, towardDep);
|
|
1611
|
-
},
|
|
1612
|
-
{
|
|
1613
|
-
batchToken: currentBoundaryBatchToken(),
|
|
1614
|
-
isReady: () => !this._hasBoundaryPauseLock()
|
|
1615
|
-
}
|
|
1616
|
-
);
|
|
1617
|
-
}
|
|
1618
|
-
/** Apply one queued self-rewire at the boundary (drain thunk). */
|
|
1619
|
-
_applyRewireNext(op) {
|
|
1620
|
-
if (this._released) return;
|
|
1621
|
-
try {
|
|
1622
|
-
if (op.kind === "add") {
|
|
1623
|
-
const next = this._slot.deps.includes(op.dep) ? [...this._slot.deps] : [...this._slot.deps, op.dep];
|
|
1624
|
-
this._rewire(next, op.fn, { allowTerminalOwner: true });
|
|
1625
|
-
} else if (op.kind === "remove") {
|
|
1626
|
-
this._rewire(
|
|
1627
|
-
this._slot.deps.filter((d) => d !== op.dep),
|
|
1628
|
-
op.fn,
|
|
1629
|
-
{ allowTerminalOwner: true }
|
|
1630
|
-
);
|
|
1631
|
-
} else {
|
|
1632
|
-
this._rewire(this._dedupDeps(op.deps), op.fn, { allowTerminalOwner: true });
|
|
1633
|
-
}
|
|
1634
|
-
} catch (e) {
|
|
1635
|
-
this._down([["ERROR", errorPayload(e, "rewireNext op failed")]]);
|
|
1636
|
-
}
|
|
1637
|
-
}
|
|
1638
2668
|
// ── rewire (R-rewire / D42): intra-graph runtime topology mutation ──
|
|
1639
2669
|
/**
|
|
1640
2670
|
* Replace this node's deps atomically (surgical, Option-C). Requires an explicit
|
|
@@ -1662,6 +2692,15 @@ var Node = class {
|
|
|
1662
2692
|
fn
|
|
1663
2693
|
);
|
|
1664
2694
|
}
|
|
2695
|
+
_requestRewireNext(op) {
|
|
2696
|
+
nodeRequestRewireNext(nodeRuntimeHost(this), op);
|
|
2697
|
+
}
|
|
2698
|
+
_requestUpNext(msgs, towardDep) {
|
|
2699
|
+
nodeRequestUpNext(nodeRuntimeHost(this), msgs, towardDep);
|
|
2700
|
+
}
|
|
2701
|
+
_applyRewireNext(op) {
|
|
2702
|
+
nodeApplyRewireNext(nodeRuntimeHost(this), op);
|
|
2703
|
+
}
|
|
1665
2704
|
_dedupDeps(deps) {
|
|
1666
2705
|
const seen = /* @__PURE__ */ new Set();
|
|
1667
2706
|
const out = [];
|
|
@@ -1672,7 +2711,6 @@ var Node = class {
|
|
|
1672
2711
|
}
|
|
1673
2712
|
return out;
|
|
1674
2713
|
}
|
|
1675
|
-
/** Is `target` reachable upstream from `from` (following deps)? Cycle-prevention DFS. */
|
|
1676
2714
|
_reachableUpstream(from, target) {
|
|
1677
2715
|
const seen = /* @__PURE__ */ new Set();
|
|
1678
2716
|
const stack = [from];
|
|
@@ -1682,1057 +2720,171 @@ var Node = class {
|
|
|
1682
2720
|
if (n === target) return true;
|
|
1683
2721
|
if (seen.has(n)) continue;
|
|
1684
2722
|
seen.add(n);
|
|
1685
|
-
for (const d of n._slot.deps) stack.push(d);
|
|
2723
|
+
for (const d of nodeRuntimeHost(n)._slot.deps) stack.push(d);
|
|
1686
2724
|
}
|
|
1687
2725
|
return false;
|
|
1688
2726
|
}
|
|
1689
2727
|
_assertRewireDepOwner(dep) {
|
|
1690
2728
|
const selfOwner = getNodeOwner(this);
|
|
1691
2729
|
const depOwner = getNodeOwner(dep);
|
|
1692
|
-
if (selfOwner !== void 0 && depOwner !== void 0 && selfOwner !== depOwner)
|
|
2730
|
+
if (selfOwner !== void 0 && depOwner !== void 0 && selfOwner !== depOwner)
|
|
1693
2731
|
throw new Error(
|
|
1694
2732
|
"rewire: dep belongs to a different graph; cross-graph deps require a wire bridge (D22 / R-graph-domain)"
|
|
1695
2733
|
);
|
|
1696
|
-
}
|
|
1697
2734
|
}
|
|
1698
2735
|
_rewire(newDeps, fn, opts = {}) {
|
|
1699
|
-
|
|
1700
|
-
throw new Error(
|
|
1701
|
-
"rewire: node is terminal (completed/errored) \u2014 cannot rewire (R-rewire / D42)"
|
|
1702
|
-
);
|
|
1703
|
-
if (this._wave.insideRunWave)
|
|
1704
|
-
throw new Error(
|
|
1705
|
-
"rewire: mid-fn topology mutation \u2014 a fn mutating its own deps mid-wave is the feedback cycle (R-rewire / D37)"
|
|
1706
|
-
);
|
|
1707
|
-
if (this._wave.inDepMutation)
|
|
1708
|
-
throw new Error(
|
|
1709
|
-
"rewire: reentrant dep mutation \u2014 another replaceDeps/subscribeDep/unsubscribeDep is in flight (R-rewire)"
|
|
1710
|
-
);
|
|
1711
|
-
if (newDeps.includes(this))
|
|
1712
|
-
throw new Error("rewire: self-dependency rejected (R-rewire / D42)");
|
|
1713
|
-
const oldDeps = this._slot.deps;
|
|
1714
|
-
const added = newDeps.filter((d) => !oldDeps.includes(d));
|
|
1715
|
-
for (const d of added) {
|
|
1716
|
-
if (this._reachableUpstream(d, this))
|
|
1717
|
-
throw new Error(
|
|
1718
|
-
"rewire: would create a cycle \u2014 dep already transitively depends on this node (R-rewire / D42)"
|
|
1719
|
-
);
|
|
1720
|
-
if (d._value.terminal !== void 0 && !d._slot.resubscribable)
|
|
1721
|
-
throw new Error(
|
|
1722
|
-
"rewire: cannot add a non-resubscribable terminal dep \u2014 would wedge (R-rewire / D42)"
|
|
1723
|
-
);
|
|
1724
|
-
this._assertRewireDepOwner(d);
|
|
1725
|
-
}
|
|
1726
|
-
if (deferAfterBatchForTarget(this, () => {
|
|
1727
|
-
this._rewire(newDeps, fn, { ...opts, allowTerminalOwner: true });
|
|
1728
|
-
})) {
|
|
1729
|
-
return true;
|
|
1730
|
-
}
|
|
1731
|
-
if (!this._lifecycle.activated) this._restoredActivationPending = false;
|
|
1732
|
-
this._wave.inDepMutation = true;
|
|
1733
|
-
this._wave.rewireRunPending = false;
|
|
1734
|
-
let zeroDepUnDirty = false;
|
|
1735
|
-
try {
|
|
1736
|
-
const oldHandle = this._slot.handle;
|
|
1737
|
-
this._slot.handle = this._slot.dispatcher.register(fn, this._slot.pool);
|
|
1738
|
-
if (oldHandle !== null) this._slot.dispatcher.unregister(oldHandle);
|
|
1739
|
-
const removed = oldDeps.filter((d) => !newDeps.includes(d));
|
|
1740
|
-
let removedDirtyContributor = false;
|
|
1741
|
-
for (const d of removed) {
|
|
1742
|
-
const oldIdx = oldDeps.indexOf(d);
|
|
1743
|
-
if (this._dep.dirty[oldIdx]) {
|
|
1744
|
-
removedDirtyContributor = true;
|
|
1745
|
-
this._wave.pending--;
|
|
1746
|
-
}
|
|
1747
|
-
if (this._lifecycle.activated) {
|
|
1748
|
-
const box = this._dep.idxBoxes[oldIdx];
|
|
1749
|
-
if (box) box.v = -1;
|
|
1750
|
-
const unsub = this._dep.unsubs[oldIdx];
|
|
1751
|
-
if (unsub) unsub();
|
|
1752
|
-
}
|
|
1753
|
-
}
|
|
1754
|
-
const n = newDeps.length;
|
|
1755
|
-
const newBatch = new Array(n).fill(null);
|
|
1756
|
-
const newPrev = new Array(n).fill(SENTINEL);
|
|
1757
|
-
const newHasData = new Array(n).fill(false);
|
|
1758
|
-
const newDirty = new Array(n).fill(false);
|
|
1759
|
-
const newTier = new Array(n).fill(0);
|
|
1760
|
-
const newTerminal = new Array(n).fill(void 0);
|
|
1761
|
-
const newTerminalInput = new Array(n).fill(void 0);
|
|
1762
|
-
const newUnsubs = new Array(n);
|
|
1763
|
-
const newBoxes = new Array(n);
|
|
1764
|
-
for (let j = 0; j < n; j++) {
|
|
1765
|
-
const oldIdx = oldDeps.indexOf(newDeps[j]);
|
|
1766
|
-
if (oldIdx !== -1) {
|
|
1767
|
-
newBatch[j] = this._dep.batch[oldIdx];
|
|
1768
|
-
newPrev[j] = this._dep.prev[oldIdx];
|
|
1769
|
-
newHasData[j] = this._dep.hasData[oldIdx];
|
|
1770
|
-
newDirty[j] = this._dep.dirty[oldIdx];
|
|
1771
|
-
newTier[j] = this._dep.tier[oldIdx];
|
|
1772
|
-
newTerminal[j] = this._dep.terminal[oldIdx];
|
|
1773
|
-
newUnsubs[j] = this._dep.unsubs[oldIdx];
|
|
1774
|
-
const box = this._dep.idxBoxes[oldIdx];
|
|
1775
|
-
if (box) box.v = j;
|
|
1776
|
-
newBoxes[j] = box;
|
|
1777
|
-
}
|
|
1778
|
-
}
|
|
1779
|
-
this._slot.deps = newDeps;
|
|
1780
|
-
this._dep.batch = newBatch;
|
|
1781
|
-
this._dep.prev = newPrev;
|
|
1782
|
-
this._dep.hasData = newHasData;
|
|
1783
|
-
this._dep.dirty = newDirty;
|
|
1784
|
-
this._dep.tier = newTier;
|
|
1785
|
-
this._dep.terminal = newTerminal;
|
|
1786
|
-
this._dep.terminalInput = newTerminalInput;
|
|
1787
|
-
this._dep.unsubs = newUnsubs;
|
|
1788
|
-
this._dep.idxBoxes = newBoxes;
|
|
1789
|
-
this._dep.waveData = newDeps.map(() => []);
|
|
1790
|
-
this._dep.waveTokens = new Array(newDeps.length).fill(void 0);
|
|
1791
|
-
this._syncCtx = null;
|
|
1792
|
-
if (this._lifecycle.activated) {
|
|
1793
|
-
for (const d of added) this._subscribeDepAt(d);
|
|
1794
|
-
}
|
|
1795
|
-
notifyTopologyDepsChanged(this, oldDeps, newDeps);
|
|
1796
|
-
if (removedDirtyContributor && this._wave.pending === 0 && this._value.status === "dirty") {
|
|
1797
|
-
if (newDeps.length > 0) this._wave.rewireRunPending = true;
|
|
1798
|
-
else zeroDepUnDirty = true;
|
|
1799
|
-
}
|
|
1800
|
-
} finally {
|
|
1801
|
-
this._wave.inDepMutation = false;
|
|
1802
|
-
}
|
|
1803
|
-
if (this._wave.rewireRunPending) {
|
|
1804
|
-
this._wave.rewireRunPending = false;
|
|
1805
|
-
this._settleRewire();
|
|
1806
|
-
} else if (zeroDepUnDirty) {
|
|
1807
|
-
if (this._wave.emittedDirtyThisWave) this._down([["RESOLVED"]]);
|
|
1808
|
-
else this._value.status = this._value.hasData ? "settled" : "sentinel";
|
|
1809
|
-
}
|
|
1810
|
-
return false;
|
|
2736
|
+
return nodeRewire(nodeRuntimeHost(this), newDeps, fn, opts);
|
|
1811
2737
|
}
|
|
1812
2738
|
// ── activation / deactivation (lazy; R-rom-ram) ──
|
|
1813
2739
|
_activate() {
|
|
1814
|
-
this
|
|
1815
|
-
const seedRestoredDeps = this._restoredActivationPending;
|
|
1816
|
-
this._restoredActivationPending = false;
|
|
1817
|
-
this._dep.unsubs = new Array(this._slot.deps.length);
|
|
1818
|
-
this._dep.idxBoxes = new Array(this._slot.deps.length);
|
|
1819
|
-
for (const dep of this._slot.deps)
|
|
1820
|
-
this._subscribeDepAt(dep, { seedRestored: seedRestoredDeps });
|
|
1821
|
-
if (this._slot.deps.length === 0 && this._slot.handle !== null && !this._wave.hasCalledFnOnce) {
|
|
1822
|
-
this._runWave();
|
|
1823
|
-
}
|
|
1824
|
-
}
|
|
1825
|
-
/**
|
|
1826
|
-
* Subscribe to a dep. The dispatch callback reads the dep's CURRENT index from a
|
|
1827
|
-
* mutable box (O(1)); a surgical rewire that reorders kept deps just updates the box
|
|
1828
|
-
* (R-rewire Option-C / D42) — no re-subscribe, no per-message indexOf scan. A removed
|
|
1829
|
-
* dep's box is set to -1 so any stale in-flight callback drops (drain).
|
|
1830
|
-
*/
|
|
1831
|
-
_subscribeDepAt(depNode, opts = {}) {
|
|
1832
|
-
const idx0 = this._slot.deps.indexOf(depNode);
|
|
1833
|
-
const box = { v: idx0 };
|
|
1834
|
-
let ignoreInitialPush = opts.seedRestored === true;
|
|
1835
|
-
if (ignoreInitialPush && idx0 !== -1) {
|
|
1836
|
-
this._seedRestoredDepAt(idx0, depNode);
|
|
1837
|
-
if (depNode._value.terminal !== void 0 && !depNode._slot.resubscribable) {
|
|
1838
|
-
this._dep.unsubs[idx0] = () => {
|
|
1839
|
-
};
|
|
1840
|
-
this._dep.idxBoxes[idx0] = box;
|
|
1841
|
-
return;
|
|
1842
|
-
}
|
|
1843
|
-
}
|
|
1844
|
-
const unsub = depNode.subscribe((msg, delivery) => {
|
|
1845
|
-
if (ignoreInitialPush && delivery === void 0) return;
|
|
1846
|
-
if (ignoreInitialPush) ignoreInitialPush = false;
|
|
1847
|
-
if (box.v === -1) return;
|
|
1848
|
-
this._receiveFromDep(box.v, msg, delivery);
|
|
1849
|
-
});
|
|
1850
|
-
if (ignoreInitialPush && idx0 !== -1 && box.v !== -1) this._seedRestoredDepAt(idx0, depNode);
|
|
1851
|
-
ignoreInitialPush = false;
|
|
1852
|
-
if (idx0 !== -1) {
|
|
1853
|
-
this._dep.unsubs[idx0] = unsub;
|
|
1854
|
-
this._dep.idxBoxes[idx0] = box;
|
|
1855
|
-
}
|
|
1856
|
-
}
|
|
1857
|
-
_seedRestoredDepAt(idx, depNode) {
|
|
1858
|
-
const seedData = depNode._value.hasData && !depNode._slot.pull;
|
|
1859
|
-
this._dep.batch[idx] = null;
|
|
1860
|
-
this._dep.waveData[idx] = [];
|
|
1861
|
-
this._dep.waveTokens[idx] = void 0;
|
|
1862
|
-
this._dep.prev[idx] = seedData ? depNode._value.cache : SENTINEL;
|
|
1863
|
-
this._dep.hasData[idx] = seedData;
|
|
1864
|
-
this._dep.dirty[idx] = false;
|
|
1865
|
-
this._dep.tier[idx] = seedData ? 3 : 0;
|
|
1866
|
-
this._dep.terminal[idx] = depNode._value.terminal;
|
|
1867
|
-
this._dep.terminalInput[idx] = void 0;
|
|
2740
|
+
nodeActivate(nodeRuntimeHost(this));
|
|
1868
2741
|
}
|
|
1869
2742
|
_deactivate() {
|
|
1870
|
-
this
|
|
1871
|
-
for (const u of this._dep.unsubs) if (u) u();
|
|
1872
|
-
this._dep.unsubs = [];
|
|
1873
|
-
this._dep.idxBoxes = [];
|
|
1874
|
-
for (const fn of this._hooks.onDeactivation) fn();
|
|
1875
|
-
this._hooks.onDeactivation = [];
|
|
1876
|
-
this._hooks.onInvalidate = [];
|
|
1877
|
-
const isCompute = this._slot.handle !== null || this._slot.deps.length > 0;
|
|
1878
|
-
if (isCompute) {
|
|
1879
|
-
this._value.cache = SENTINEL;
|
|
1880
|
-
this._value.hasData = false;
|
|
1881
|
-
this._value.status = "sentinel";
|
|
1882
|
-
}
|
|
1883
|
-
this._resetDepState();
|
|
1884
|
-
this._wave.hasCalledFnOnce = false;
|
|
1885
|
-
this._control.pauseLockset.clear();
|
|
1886
|
-
this._control.pauseBuffer = [];
|
|
1887
|
-
this._control.pausedDepWaveOccurred = false;
|
|
1888
|
-
this._control.demandOwed = void 0;
|
|
1889
|
-
this._control.activePull = void 0;
|
|
1890
|
-
this._control.pullDirtyOwed = false;
|
|
1891
|
-
this._value.replayRing = [];
|
|
1892
|
-
if (!this._privateState.persist) this._privateState.value = SENTINEL;
|
|
2743
|
+
nodeDeactivate(nodeRuntimeHost(this));
|
|
1893
2744
|
}
|
|
1894
2745
|
_assertNotReleased(op) {
|
|
1895
2746
|
if (this._released)
|
|
1896
2747
|
throw new Error(`${op}: node has been released from its graph lifecycle (D122)`);
|
|
1897
2748
|
}
|
|
1898
2749
|
_subscriberCount() {
|
|
1899
|
-
return this
|
|
2750
|
+
return nodeSubscriberCount(nodeRuntimeHost(this));
|
|
1900
2751
|
}
|
|
1901
2752
|
_isRuntimeQuiescentForRelease() {
|
|
1902
|
-
return
|
|
2753
|
+
return nodeIsRuntimeQuiescentForRelease(nodeRuntimeHost(this));
|
|
1903
2754
|
}
|
|
1904
2755
|
_releaseRuntime() {
|
|
1905
|
-
|
|
1906
|
-
this._released = true;
|
|
1907
|
-
releasedNodes.add(this);
|
|
1908
|
-
let releaseError;
|
|
1909
|
-
const recordReleaseError = (error) => {
|
|
1910
|
-
if (releaseError === void 0) releaseError = error;
|
|
1911
|
-
};
|
|
1912
|
-
this._lifecycle.activated = false;
|
|
1913
|
-
for (const u of this._dep.unsubs) {
|
|
1914
|
-
try {
|
|
1915
|
-
u();
|
|
1916
|
-
} catch (error) {
|
|
1917
|
-
recordReleaseError(error);
|
|
1918
|
-
}
|
|
1919
|
-
}
|
|
1920
|
-
for (const fn of this._hooks.onDeactivation) {
|
|
1921
|
-
try {
|
|
1922
|
-
fn();
|
|
1923
|
-
} catch (error) {
|
|
1924
|
-
recordReleaseError(error);
|
|
1925
|
-
}
|
|
1926
|
-
}
|
|
1927
|
-
this._dep.unsubs = [];
|
|
1928
|
-
this._dep.idxBoxes = [];
|
|
1929
|
-
this._lifecycle.subscribers.clear();
|
|
1930
|
-
if (this._slot.handle !== null) {
|
|
1931
|
-
this._slot.dispatcher.unregister(this._slot.handle);
|
|
1932
|
-
this._slot.handle = null;
|
|
1933
|
-
}
|
|
1934
|
-
this._slot.deps = [];
|
|
1935
|
-
this._dep.batch = [];
|
|
1936
|
-
this._dep.waveData = [];
|
|
1937
|
-
this._dep.waveTokens = [];
|
|
1938
|
-
this._dep.prev = [];
|
|
1939
|
-
this._dep.hasData = [];
|
|
1940
|
-
this._dep.dirty = [];
|
|
1941
|
-
this._dep.tier = [];
|
|
1942
|
-
this._dep.terminal = [];
|
|
1943
|
-
this._dep.terminalInput = [];
|
|
1944
|
-
this._value.cache = SENTINEL;
|
|
1945
|
-
this._value.hasData = false;
|
|
1946
|
-
this._value.status = "sentinel";
|
|
1947
|
-
this._value.terminal = void 0;
|
|
1948
|
-
this._value.replayRing = [];
|
|
1949
|
-
this._privateState.value = SENTINEL;
|
|
1950
|
-
this._privateState.persist = false;
|
|
1951
|
-
this._syncCtx = null;
|
|
1952
|
-
this._resetDepState();
|
|
1953
|
-
this._hooks.onDeactivation = [];
|
|
1954
|
-
this._hooks.onInvalidate = [];
|
|
1955
|
-
this._control.pauseLockset.clear();
|
|
1956
|
-
this._control.pauseBuffer = [];
|
|
1957
|
-
this._control.pausedDepWaveOccurred = false;
|
|
1958
|
-
this._control.demandOwed = void 0;
|
|
1959
|
-
this._control.activePull = void 0;
|
|
1960
|
-
this._control.pullDirtyOwed = false;
|
|
1961
|
-
this._restoredActivationPending = false;
|
|
1962
|
-
checkpointReaders.delete(this);
|
|
1963
|
-
restoreWriters.delete(this);
|
|
1964
|
-
runtimeReleasers.delete(this);
|
|
1965
|
-
runtimeQuiescenceReaders.delete(this);
|
|
1966
|
-
subscriberCountReaders.delete(this);
|
|
1967
|
-
activationReaders.delete(this);
|
|
1968
|
-
ownerTokens.delete(this);
|
|
1969
|
-
topologyDepsChangedObservers.delete(this);
|
|
1970
|
-
this._core.releaseSlot(this._id);
|
|
1971
|
-
if (releaseError !== void 0) throw releaseError;
|
|
2756
|
+
nodeReleaseRuntime(nodeRuntimeHost(this));
|
|
1972
2757
|
}
|
|
1973
2758
|
_resetDepState() {
|
|
1974
|
-
|
|
1975
|
-
|
|
1976
|
-
|
|
1977
|
-
|
|
1978
|
-
|
|
1979
|
-
|
|
1980
|
-
|
|
1981
|
-
|
|
1982
|
-
this._dep.tier[i] = 0;
|
|
1983
|
-
this._dep.terminal[i] = void 0;
|
|
1984
|
-
this._dep.terminalInput[i] = void 0;
|
|
1985
|
-
}
|
|
1986
|
-
this._wave.pending = 0;
|
|
1987
|
-
this._wave.emittedDirtyThisWave = false;
|
|
1988
|
-
}
|
|
1989
|
-
// ── upstream wave receive (two-phase + diamond) ──
|
|
2759
|
+
nodeResetDepState(nodeRuntimeHost(this));
|
|
2760
|
+
}
|
|
2761
|
+
_subscribeDepAt(depNode, opts = {}) {
|
|
2762
|
+
nodeSubscribeDepAt(nodeRuntimeHost(this), depNode, opts);
|
|
2763
|
+
}
|
|
2764
|
+
_seedRestoredDepAt(idx, depNode) {
|
|
2765
|
+
nodeSeedRestoredDepAt(nodeRuntimeHost(this), idx, depNode);
|
|
2766
|
+
}
|
|
1990
2767
|
_recordDepProjection(idx, delivery) {
|
|
1991
|
-
|
|
1992
|
-
if (this._dep.waveTokens[idx] !== token) {
|
|
1993
|
-
this._dep.waveData[idx].push([]);
|
|
1994
|
-
this._dep.waveTokens[idx] = token;
|
|
1995
|
-
}
|
|
1996
|
-
return this._dep.waveData[idx][this._dep.waveData[idx].length - 1];
|
|
2768
|
+
return nodeRecordDepProjection(nodeRuntimeHost(this), idx, delivery);
|
|
1997
2769
|
}
|
|
1998
2770
|
_depProjectionHasData(idx) {
|
|
1999
|
-
|
|
2000
|
-
return projection?.some((v) => v !== SENTINEL) ?? false;
|
|
2771
|
+
return nodeDepProjectionHasData(nodeRuntimeHost(this), idx);
|
|
2001
2772
|
}
|
|
2002
2773
|
_receiveFromDep(idx, msg, delivery) {
|
|
2003
|
-
|
|
2004
|
-
const t = msg[0];
|
|
2005
|
-
if (t === "START") return;
|
|
2006
|
-
const isLastInDeliveredWave = delivery?.last ?? true;
|
|
2007
|
-
if (this._value.terminal !== void 0) {
|
|
2008
|
-
if (t === "TEARDOWN") this._down([["TEARDOWN"]]);
|
|
2009
|
-
return;
|
|
2010
|
-
}
|
|
2011
|
-
if (t === "INVALIDATE") {
|
|
2012
|
-
const projection = this._recordDepProjection(idx, delivery);
|
|
2013
|
-
projection.push(SENTINEL);
|
|
2014
|
-
if (projection.some((v) => v !== SENTINEL) && isLastInDeliveredWave) this._maybeRun();
|
|
2015
|
-
this._dep.prev[idx] = SENTINEL;
|
|
2016
|
-
this._dep.hasData[idx] = false;
|
|
2017
|
-
this._dep.batch[idx] = null;
|
|
2018
|
-
if (this._dep.dirty[idx]) {
|
|
2019
|
-
this._dep.dirty[idx] = false;
|
|
2020
|
-
this._wave.pending--;
|
|
2021
|
-
}
|
|
2022
|
-
if (this._control.pausedDepWaveOccurred && this._dep.batch.every((b) => b === null)) {
|
|
2023
|
-
this._control.pausedDepWaveOccurred = false;
|
|
2024
|
-
}
|
|
2025
|
-
const hadData = this._value.hasData;
|
|
2026
|
-
this._invalidate();
|
|
2027
|
-
if (this._wave.pending === 0 && this._wave.emittedDirtyThisWave) {
|
|
2028
|
-
if (!hadData) this._down([["RESOLVED"]]);
|
|
2029
|
-
else this._wave.emittedDirtyThisWave = false;
|
|
2030
|
-
}
|
|
2031
|
-
this._fireOwedDemandIfReady();
|
|
2032
|
-
return;
|
|
2033
|
-
}
|
|
2034
|
-
if (isTerminal(t)) {
|
|
2035
|
-
const isError = t === "ERROR";
|
|
2036
|
-
const errPayload = isError ? msg[1] : void 0;
|
|
2037
|
-
this._dep.terminal[idx] = isError ? errPayload : true;
|
|
2038
|
-
this._dep.terminalInput[idx] = isError ? errPayload : true;
|
|
2039
|
-
this._releaseDepDirty(idx);
|
|
2040
|
-
const ranValueBeforeTerminal = this._depProjectionHasData(idx) && isLastInDeliveredWave;
|
|
2041
|
-
if (ranValueBeforeTerminal) this._maybeRun();
|
|
2042
|
-
if (isError && this._slot.errorWhenDepsError) {
|
|
2043
|
-
this._down([["ERROR", errPayload]]);
|
|
2044
|
-
} else if (this._slot.terminalAsRealInput) {
|
|
2045
|
-
if (ranValueBeforeTerminal) {
|
|
2046
|
-
this._fireOwedDemandIfReady();
|
|
2047
|
-
return;
|
|
2048
|
-
}
|
|
2049
|
-
this._maybeRun();
|
|
2050
|
-
} else if (this._slot.completeWhenDepsComplete && this._allDepsTerminal()) {
|
|
2051
|
-
this._down([["COMPLETE"]]);
|
|
2052
|
-
} else {
|
|
2053
|
-
this._settleAfterAbsorbedTerminal();
|
|
2054
|
-
}
|
|
2055
|
-
this._fireOwedDemandIfReady();
|
|
2056
|
-
return;
|
|
2057
|
-
}
|
|
2058
|
-
if (t === "TEARDOWN") {
|
|
2059
|
-
this._down([["TEARDOWN"]]);
|
|
2060
|
-
return;
|
|
2061
|
-
}
|
|
2062
|
-
if (t === "DIRTY") {
|
|
2063
|
-
if (!this._dep.dirty[idx]) {
|
|
2064
|
-
this._dep.dirty[idx] = true;
|
|
2065
|
-
this._wave.pending++;
|
|
2066
|
-
this._dep.tier[idx] = 2;
|
|
2067
|
-
this._markDirty();
|
|
2068
|
-
}
|
|
2069
|
-
return;
|
|
2070
|
-
}
|
|
2071
|
-
if (t === "DATA") {
|
|
2072
|
-
const v = msg[1];
|
|
2073
|
-
this._recordDepProjection(idx, delivery).push(v);
|
|
2074
|
-
const b = this._dep.batch[idx];
|
|
2075
|
-
if (b === null) this._dep.batch[idx] = [v];
|
|
2076
|
-
else b.push(v);
|
|
2077
|
-
this._dep.prev[idx] = v;
|
|
2078
|
-
this._dep.hasData[idx] = true;
|
|
2079
|
-
this._dep.tier[idx] = 3;
|
|
2080
|
-
if (this._dep.dirty[idx]) {
|
|
2081
|
-
this._dep.dirty[idx] = false;
|
|
2082
|
-
this._wave.pending--;
|
|
2083
|
-
}
|
|
2084
|
-
if (isLastInDeliveredWave) this._maybeRun();
|
|
2085
|
-
this._fireOwedDemandIfReady();
|
|
2086
|
-
return;
|
|
2087
|
-
}
|
|
2088
|
-
if (t === "RESOLVED") {
|
|
2089
|
-
this._recordDepProjection(idx, delivery);
|
|
2090
|
-
this._dep.tier[idx] = 3;
|
|
2091
|
-
if (this._dep.dirty[idx]) {
|
|
2092
|
-
this._dep.dirty[idx] = false;
|
|
2093
|
-
this._wave.pending--;
|
|
2094
|
-
}
|
|
2095
|
-
if (isLastInDeliveredWave) this._maybeRun();
|
|
2096
|
-
this._fireOwedDemandIfReady();
|
|
2097
|
-
return;
|
|
2098
|
-
}
|
|
2774
|
+
nodeReceiveFromDep(nodeRuntimeHost(this), idx, msg, delivery);
|
|
2099
2775
|
}
|
|
2100
|
-
/**
|
|
2101
|
-
* R-terminal-settles-dirty (B35): release a dep's outstanding in-wave DIRTY contribution.
|
|
2102
|
-
* A settle-class event for that dep (DATA/RESOLVED inline above, INVALIDATE, and now
|
|
2103
|
-
* COMPLETE/ERROR) clears its dirty flag + decrements _pending. No-op if the dep already
|
|
2104
|
-
* settled this wave (DATA/RESOLVED ran first) — so the normal DATA-then-COMPLETE flow is
|
|
2105
|
-
* unaffected. This makes the exactly-one-settle invariant a single, shared step.
|
|
2106
|
-
*/
|
|
2107
2776
|
_releaseDepDirty(idx) {
|
|
2108
|
-
|
|
2109
|
-
this._dep.dirty[idx] = false;
|
|
2110
|
-
this._wave.pending--;
|
|
2111
|
-
}
|
|
2777
|
+
nodeReleaseDepDirty(nodeRuntimeHost(this), idx);
|
|
2112
2778
|
}
|
|
2113
|
-
/**
|
|
2114
|
-
* R-terminal-settles-dirty (B35): settle a node whose dirtied dep was released by an ABSORBED
|
|
2115
|
-
* terminal that is NOT a real input (a plain derived/effect — the common default-node case when
|
|
2116
|
-
* one of several deps completes while others stay live). Runs only when the release drained
|
|
2117
|
-
* _pending while the node still owes a downstream settle (it broadcast DIRTY this wave):
|
|
2118
|
-
* - if some OTHER dep delivered real DATA this wave (a value occurred) → recompute (→ DATA);
|
|
2119
|
-
* - else the terminal's signalled change did not materialise (no value) → one undirty RESOLVED
|
|
2120
|
-
* (R-resolved-undirty), keeping the cache (a terminal, unlike INVALIDATE, leaves the value).
|
|
2121
|
-
* A terminalAsRealInput node instead recomputes unconditionally (its fn reads the terminal).
|
|
2122
|
-
*/
|
|
2123
2779
|
_settleAfterAbsorbedTerminal() {
|
|
2124
|
-
|
|
2125
|
-
const sawData = this._dep.batch.some((b) => b !== null && b.length > 0);
|
|
2126
|
-
if (sawData) this._maybeRun();
|
|
2127
|
-
if (this._wave.emittedDirtyThisWave) this._down([["RESOLVED"]]);
|
|
2780
|
+
nodeSettleAfterAbsorbedTerminal(nodeRuntimeHost(this));
|
|
2128
2781
|
}
|
|
2129
2782
|
_markDirty() {
|
|
2130
|
-
this
|
|
2131
|
-
if (this._isPullQuiet()) return;
|
|
2132
|
-
if (!this._wave.emittedDirtyThisWave) {
|
|
2133
|
-
this._wave.emittedDirtyThisWave = true;
|
|
2134
|
-
this._emitToSubs(["DIRTY"]);
|
|
2135
|
-
}
|
|
2783
|
+
nodeMarkDirty(nodeRuntimeHost(this));
|
|
2136
2784
|
}
|
|
2137
2785
|
_maybeRun() {
|
|
2138
|
-
|
|
2139
|
-
this._wave.rewireRunPending = true;
|
|
2140
|
-
return;
|
|
2141
|
-
}
|
|
2142
|
-
if (this._slot.pausable === true && (this._isPaused() || this._isPullQuiet())) {
|
|
2143
|
-
this._control.pausedDepWaveOccurred = true;
|
|
2144
|
-
return;
|
|
2145
|
-
}
|
|
2146
|
-
this._tryRun();
|
|
2786
|
+
nodeMaybeRun(nodeRuntimeHost(this));
|
|
2147
2787
|
}
|
|
2148
|
-
/**
|
|
2149
|
-
* R-rewire atomic settle (after a rewire that warrants a recompute): emit a proper
|
|
2150
|
-
* two-phase DIRTY→DATA wave (R-dirty-before-data — a rewire-triggered settle is a wave),
|
|
2151
|
-
* once, with every added dep already wired. Mirrors _maybeRun/_tryRun's pause + gate +
|
|
2152
|
-
* pending guards, then injects the phase-1 DIRTY the added dep's [START,DATA] handshake
|
|
2153
|
-
* did not carry.
|
|
2154
|
-
*/
|
|
2155
2788
|
_settleRewire() {
|
|
2156
|
-
|
|
2157
|
-
this._control.pausedDepWaveOccurred = true;
|
|
2158
|
-
return;
|
|
2159
|
-
}
|
|
2160
|
-
if (this._wave.pending > 0) return;
|
|
2161
|
-
if (this._slot.handle === null) {
|
|
2162
|
-
this._passthroughEmit();
|
|
2163
|
-
return;
|
|
2164
|
-
}
|
|
2165
|
-
if (!this._wave.hasCalledFnOnce && !(this._slot.partial || this._allDepsSettled())) return;
|
|
2166
|
-
this._markDirty();
|
|
2167
|
-
this._runWave();
|
|
2789
|
+
nodeSettleRewire(nodeRuntimeHost(this));
|
|
2168
2790
|
}
|
|
2169
2791
|
_tryRun() {
|
|
2170
|
-
|
|
2171
|
-
if (this._slot.handle === null) {
|
|
2172
|
-
this._passthroughEmit();
|
|
2173
|
-
return;
|
|
2174
|
-
}
|
|
2175
|
-
if (!this._wave.hasCalledFnOnce) {
|
|
2176
|
-
if (this._slot.partial || this._allDepsSettled()) this._runWave();
|
|
2177
|
-
return;
|
|
2178
|
-
}
|
|
2179
|
-
this._runWave();
|
|
2792
|
+
nodeTryRun(nodeRuntimeHost(this));
|
|
2180
2793
|
}
|
|
2181
2794
|
_allDepsSettled() {
|
|
2182
|
-
|
|
2183
|
-
if (this._dep.hasData[i]) continue;
|
|
2184
|
-
if (this._slot.terminalAsRealInput && this._dep.terminal[i] !== void 0) continue;
|
|
2185
|
-
return false;
|
|
2186
|
-
}
|
|
2187
|
-
return true;
|
|
2795
|
+
return nodeAllDepsSettled(nodeRuntimeHost(this));
|
|
2188
2796
|
}
|
|
2189
2797
|
_passthroughEmit() {
|
|
2190
|
-
|
|
2191
|
-
if (b !== null && b.length > 0) {
|
|
2192
|
-
this._down([["DATA", b[b.length - 1]]]);
|
|
2193
|
-
} else if (this._wave.emittedDirtyThisWave) {
|
|
2194
|
-
this._down([["RESOLVED"]]);
|
|
2195
|
-
}
|
|
2196
|
-
this._dep.batch[0] = null;
|
|
2197
|
-
this._wave.emittedDirtyThisWave = false;
|
|
2798
|
+
nodePassthroughEmit(nodeRuntimeHost(this));
|
|
2198
2799
|
}
|
|
2199
2800
|
_runWave() {
|
|
2200
|
-
|
|
2201
|
-
throw new Error(
|
|
2202
|
-
"synchronous feedback cycle: node fn re-entered its own wave (R-reentrancy / D37)"
|
|
2203
|
-
);
|
|
2204
|
-
this._wave.hasCalledFnOnce = true;
|
|
2205
|
-
this._hooks.onInvalidate = [];
|
|
2206
|
-
this._hooks.onDeactivation = [];
|
|
2207
|
-
const ctx = this._buildCtx();
|
|
2208
|
-
const wasDirty = this._wave.emittedDirtyThisWave;
|
|
2209
|
-
this._wave.emittedSettleThisWave = false;
|
|
2210
|
-
this._wave.insideRunWave = true;
|
|
2211
|
-
try {
|
|
2212
|
-
this._slot.dispatcher.invoke(this._slot.handle, ctx);
|
|
2213
|
-
} finally {
|
|
2214
|
-
this._wave.insideRunWave = false;
|
|
2215
|
-
}
|
|
2216
|
-
if (wasDirty && !this._wave.emittedSettleThisWave && this._value.terminal === void 0 && !this._isAsyncPool()) {
|
|
2217
|
-
this._down([["RESOLVED"]]);
|
|
2218
|
-
}
|
|
2219
|
-
for (let i = 0; i < this._dep.batch.length; i++) {
|
|
2220
|
-
this._dep.batch[i] = null;
|
|
2221
|
-
this._dep.waveData[i] = [];
|
|
2222
|
-
this._dep.waveTokens[i] = void 0;
|
|
2223
|
-
this._dep.terminalInput[i] = void 0;
|
|
2224
|
-
}
|
|
2225
|
-
this._wave.emittedDirtyThisWave = false;
|
|
2801
|
+
nodeRunWave(nodeRuntimeHost(this));
|
|
2226
2802
|
}
|
|
2227
|
-
// ── ctx construction (L3-Q5: sync = node-stable reused ctx; async = per-invocation) ──
|
|
2228
2803
|
_buildCtx() {
|
|
2229
|
-
|
|
2230
|
-
if (kind === "sync") {
|
|
2231
|
-
if (this._syncCtx === null) this._syncCtx = this._makeCtx();
|
|
2232
|
-
this._refreshCtx(this._syncCtx);
|
|
2233
|
-
return this._syncCtx;
|
|
2234
|
-
}
|
|
2235
|
-
return this._makeCtx({
|
|
2236
|
-
waveData: this._dep.waveData.map((waves) => waves.map((w) => [...w])),
|
|
2237
|
-
terminal: this._dep.terminalInput.map(terminalView),
|
|
2238
|
-
latest: [...this._dep.prev]
|
|
2239
|
-
});
|
|
2804
|
+
return nodeBuildCtx(nodeRuntimeHost(this));
|
|
2240
2805
|
}
|
|
2241
2806
|
_makeCtx(snapshot) {
|
|
2242
|
-
|
|
2243
|
-
// Wave-owner boundary (D47): a SYNC fn's emit nests under the public entry that drove
|
|
2244
|
-
// it (cheap inc/dec, no early drain); an ASYNC-pool fn re-enters here from its stashed
|
|
2245
|
-
// ctx at depth 0, so this is the boundary that drains any rewireNext it issued.
|
|
2246
|
-
up: (msgs, towardDep) => {
|
|
2247
|
-
if (this._released) return;
|
|
2248
|
-
enterWave();
|
|
2249
|
-
try {
|
|
2250
|
-
this._up(msgs, towardDep);
|
|
2251
|
-
} finally {
|
|
2252
|
-
exitWave();
|
|
2253
|
-
}
|
|
2254
|
-
},
|
|
2255
|
-
down: (msgs) => {
|
|
2256
|
-
if (this._released) return;
|
|
2257
|
-
enterWave();
|
|
2258
|
-
try {
|
|
2259
|
-
this._down(msgs);
|
|
2260
|
-
} finally {
|
|
2261
|
-
exitWave();
|
|
2262
|
-
}
|
|
2263
|
-
},
|
|
2264
|
-
waveData: snapshot?.waveData ?? this._dep.waveData,
|
|
2265
|
-
terminal: snapshot?.terminal ?? this._dep.terminalInput.map(terminalView),
|
|
2266
|
-
state: this._makeState(),
|
|
2267
|
-
onDeactivation: (fn) => {
|
|
2268
|
-
if (this._released) return;
|
|
2269
|
-
this._hooks.onDeactivation.push(fn);
|
|
2270
|
-
},
|
|
2271
|
-
onInvalidate: (fn) => {
|
|
2272
|
-
if (this._released) return;
|
|
2273
|
-
this._hooks.onInvalidate.push(fn);
|
|
2274
|
-
},
|
|
2275
|
-
environment: () => this._slot.environment,
|
|
2276
|
-
// R-rewire-deferred (D47): defer a self-dep-set mutation to the committed boundary.
|
|
2277
|
-
rewireNext: {
|
|
2278
|
-
subscribeDep: (dep, fn) => this._requestRewireNext({ kind: "add", dep, fn }),
|
|
2279
|
-
unsubscribeDep: (dep, fn) => this._requestRewireNext({ kind: "remove", dep, fn }),
|
|
2280
|
-
replaceDeps: (deps, fn) => this._requestRewireNext({ kind: "set", deps, fn })
|
|
2281
|
-
},
|
|
2282
|
-
// R-up-routing / R-pull (D269): deferred up — route a control/demand wave (e.g. PULL)
|
|
2283
|
-
// up the declared cone at the committed boundary. The SELF-demand path: an
|
|
2284
|
-
// immediate ctx.up whose delivery loops back re-enters this fn (D37 / R-reentrancy).
|
|
2285
|
-
upNext: (msgs, towardDep) => this._requestUpNext(msgs, towardDep),
|
|
2286
|
-
...this._control.activePull === void 0 ? {} : { pull: this._control.activePull },
|
|
2287
|
-
[CTX_DEP_CACHE]: { latest: snapshot?.latest ?? this._dep.prev },
|
|
2288
|
-
[CTX_NODE_BINDING]: {
|
|
2289
|
-
dispatcher: this._slot.dispatcher,
|
|
2290
|
-
create: (factory) => withEnvironmentDrivers(this._slot.environment, () => withNodeCore(this._core, factory))
|
|
2291
|
-
}
|
|
2292
|
-
};
|
|
2293
|
-
if (this._slot.dynamic) {
|
|
2294
|
-
ctx.track = (i) => ctx[CTX_DEP_CACHE]?.latest[i];
|
|
2295
|
-
}
|
|
2296
|
-
return ctx;
|
|
2807
|
+
return nodeMakeCtx(nodeRuntimeHost(this), snapshot);
|
|
2297
2808
|
}
|
|
2298
2809
|
_refreshCtx(ctx) {
|
|
2299
|
-
ctx
|
|
2300
|
-
ctx.terminal = this._dep.terminalInput.map(terminalView);
|
|
2301
|
-
if (this._control.activePull === void 0) {
|
|
2302
|
-
delete ctx.pull;
|
|
2303
|
-
} else {
|
|
2304
|
-
ctx.pull = this._control.activePull;
|
|
2305
|
-
}
|
|
2306
|
-
ctx[CTX_DEP_CACHE] = { latest: this._dep.prev };
|
|
2810
|
+
nodeRefreshCtx(nodeRuntimeHost(this), ctx);
|
|
2307
2811
|
}
|
|
2308
2812
|
_makeState() {
|
|
2309
|
-
return
|
|
2310
|
-
get: () => this._privateState.value,
|
|
2311
|
-
set: (v) => {
|
|
2312
|
-
this._privateState.value = v;
|
|
2313
|
-
},
|
|
2314
|
-
persist: (on = true) => {
|
|
2315
|
-
this._privateState.persist = on;
|
|
2316
|
-
}
|
|
2317
|
-
};
|
|
2813
|
+
return nodeMakeState(nodeRuntimeHost(this));
|
|
2318
2814
|
}
|
|
2319
2815
|
// ── downstream emission pipeline (the unified waist) ──
|
|
2320
2816
|
_down(msgs) {
|
|
2321
|
-
|
|
2322
|
-
validateDownPayloads(msgs);
|
|
2323
|
-
const deliveryWave = {};
|
|
2324
|
-
const assertVersionDataCompatible = (wave) => {
|
|
2325
|
-
for (const m of wave) {
|
|
2326
|
-
if (m[0] === "DATA") assertNodeVersionDataCompatible(this._version.policy, m[1]);
|
|
2327
|
-
}
|
|
2328
|
-
};
|
|
2329
|
-
const snapshotVersionData = (wave) => wave.map(
|
|
2330
|
-
(m) => m[0] === "DATA" ? ["DATA", snapshotNodeVersionData(this._version.policy, m[1])] : m
|
|
2331
|
-
);
|
|
2332
|
-
assertVersionDataCompatible(msgs);
|
|
2333
|
-
if (this._value.terminal !== void 0) {
|
|
2334
|
-
if (!msgs.some((m) => m[0] === "TEARDOWN")) return;
|
|
2335
|
-
this._value.hasTorndown = true;
|
|
2336
|
-
if (this._slot.resetOnTeardown) {
|
|
2337
|
-
this._value.cache = SENTINEL;
|
|
2338
|
-
this._value.hasData = false;
|
|
2339
|
-
}
|
|
2340
|
-
this._emitToSubs(["TEARDOWN"], { wave: deliveryWave, last: true });
|
|
2341
|
-
return;
|
|
2342
|
-
}
|
|
2343
|
-
let sorted = [...msgs].sort((a, b) => messageTier(a[0]) - messageTier(b[0]));
|
|
2344
|
-
const firstInvalidate = sorted.findIndex((m) => m[0] === "INVALIDATE");
|
|
2345
|
-
if (firstInvalidate !== -1) {
|
|
2346
|
-
sorted = sorted.filter((m, i) => m[0] !== "INVALIDATE" || i === firstInvalidate);
|
|
2347
|
-
}
|
|
2348
|
-
const hasTeardown = sorted.some((m) => m[0] === "TEARDOWN");
|
|
2349
|
-
const hasTerminal = sorted.some((m) => m[0] === "COMPLETE" || m[0] === "ERROR");
|
|
2350
|
-
if (hasTeardown && !hasTerminal && this._value.terminal === void 0 && !this._value.hasTorndown) {
|
|
2351
|
-
sorted = [["COMPLETE"], ...sorted];
|
|
2352
|
-
}
|
|
2353
|
-
if (!this._wave.insideRunWave && currentBatch()) {
|
|
2354
|
-
const deferred = snapshotVersionData(sorted.filter((m) => isDeferredTier(m[0])));
|
|
2355
|
-
if (deferred.length > 0) {
|
|
2356
|
-
if (!this._wave.emittedDirtyThisWave) {
|
|
2357
|
-
this._wave.emittedDirtyThisWave = true;
|
|
2358
|
-
this._value.status = "dirty";
|
|
2359
|
-
this._emitToSubs(["DIRTY"], { wave: deliveryWave, last: false });
|
|
2360
|
-
}
|
|
2361
|
-
this._wave.batchDirtyOwed = true;
|
|
2362
|
-
deferToBatch(this, deferred);
|
|
2363
|
-
return;
|
|
2364
|
-
}
|
|
2365
|
-
}
|
|
2366
|
-
if (this._shouldBufferOnPause()) {
|
|
2367
|
-
const buffered = snapshotVersionData(sorted.filter((m) => isPauseBufferedTier(m[0])));
|
|
2368
|
-
if (buffered.length > 0) {
|
|
2369
|
-
this._wave.emittedSettleThisWave = true;
|
|
2370
|
-
this._control.pauseBuffer.push(buffered);
|
|
2371
|
-
}
|
|
2372
|
-
sorted = sorted.filter((m) => !isPauseBufferedTier(m[0]));
|
|
2373
|
-
if (sorted.length === 0) return;
|
|
2374
|
-
}
|
|
2375
|
-
let dataCount = 0;
|
|
2376
|
-
let hasTier3 = false;
|
|
2377
|
-
let hasResolved = false;
|
|
2378
|
-
for (const m of sorted) {
|
|
2379
|
-
if (m[0] === "DATA") dataCount++;
|
|
2380
|
-
if (m[0] === "RESOLVED") hasResolved = true;
|
|
2381
|
-
if (isValueTier(m[0])) hasTier3 = true;
|
|
2382
|
-
}
|
|
2383
|
-
if (dataCount >= 1 && hasResolved) {
|
|
2384
|
-
throw new Error(
|
|
2385
|
-
"down: a wave cannot mix DATA and RESOLVED (tier-3 exclusivity, R-resolved-undirty)"
|
|
2386
|
-
);
|
|
2387
|
-
}
|
|
2388
|
-
const plannedVersions = new Array(sorted.length);
|
|
2389
|
-
if (dataCount > 0) {
|
|
2390
|
-
let plannedVersion = this._version.value;
|
|
2391
|
-
for (let i = 0; i < sorted.length; i++) {
|
|
2392
|
-
const m = sorted[i];
|
|
2393
|
-
if (m[0] !== "DATA") continue;
|
|
2394
|
-
plannedVersion = advanceNodeVersion(plannedVersion, this._version.policy, m[1]);
|
|
2395
|
-
plannedVersions[i] = plannedVersion;
|
|
2396
|
-
}
|
|
2397
|
-
}
|
|
2398
|
-
if (hasTier3 && (!this._wave.insideRunWave || this._control.pullDirtyOwed) && !this._wave.emittedDirtyThisWave) {
|
|
2399
|
-
this._wave.emittedDirtyThisWave = true;
|
|
2400
|
-
this._value.status = "dirty";
|
|
2401
|
-
this._emitToSubs(["DIRTY"], { wave: deliveryWave, last: false });
|
|
2402
|
-
}
|
|
2403
|
-
for (let i = 0; i < sorted.length; i++) {
|
|
2404
|
-
const m = sorted[i];
|
|
2405
|
-
const delivery = { wave: deliveryWave, last: i === sorted.length - 1 };
|
|
2406
|
-
if (isDeferredTier(m[0])) this._wave.emittedSettleThisWave = true;
|
|
2407
|
-
if (m[0] === "DIRTY") {
|
|
2408
|
-
if (!this._wave.emittedDirtyThisWave) {
|
|
2409
|
-
this._wave.emittedDirtyThisWave = true;
|
|
2410
|
-
this._value.status = "dirty";
|
|
2411
|
-
this._emitToSubs(["DIRTY"], delivery);
|
|
2412
|
-
}
|
|
2413
|
-
continue;
|
|
2414
|
-
}
|
|
2415
|
-
if (m[0] === "DATA") {
|
|
2416
|
-
const v = m[1];
|
|
2417
|
-
this._value.cache = v;
|
|
2418
|
-
this._value.hasData = true;
|
|
2419
|
-
this._value.status = "settled";
|
|
2420
|
-
this._version.value = plannedVersions[i];
|
|
2421
|
-
if (this._slot.replayN > 0) {
|
|
2422
|
-
this._value.replayRing.push(v);
|
|
2423
|
-
if (this._value.replayRing.length > this._slot.replayN) this._value.replayRing.shift();
|
|
2424
|
-
}
|
|
2425
|
-
this._emitToSubs(["DATA", v], delivery);
|
|
2426
|
-
continue;
|
|
2427
|
-
}
|
|
2428
|
-
if (m[0] === "RESOLVED") {
|
|
2429
|
-
this._value.status = this._value.hasData ? "resolved" : "sentinel";
|
|
2430
|
-
this._emitToSubs(["RESOLVED"], delivery);
|
|
2431
|
-
continue;
|
|
2432
|
-
}
|
|
2433
|
-
if (m[0] === "INVALIDATE") {
|
|
2434
|
-
this._invalidate(delivery);
|
|
2435
|
-
continue;
|
|
2436
|
-
}
|
|
2437
|
-
if (m[0] === "COMPLETE") {
|
|
2438
|
-
if (this._value.terminal !== void 0) continue;
|
|
2439
|
-
this._value.terminal = true;
|
|
2440
|
-
this._control.pauseBuffer = [];
|
|
2441
|
-
this._value.status = "completed";
|
|
2442
|
-
this._emitToSubs(["COMPLETE"], delivery);
|
|
2443
|
-
continue;
|
|
2444
|
-
}
|
|
2445
|
-
if (m[0] === "ERROR") {
|
|
2446
|
-
if (this._value.terminal !== void 0) continue;
|
|
2447
|
-
this._value.terminal = m[1];
|
|
2448
|
-
this._control.pauseBuffer = [];
|
|
2449
|
-
this._value.status = "errored";
|
|
2450
|
-
this._emitToSubs(["ERROR", m[1]], delivery);
|
|
2451
|
-
continue;
|
|
2452
|
-
}
|
|
2453
|
-
if (m[0] === "TEARDOWN") {
|
|
2454
|
-
this._value.hasTorndown = true;
|
|
2455
|
-
if (this._slot.resetOnTeardown) {
|
|
2456
|
-
this._value.cache = SENTINEL;
|
|
2457
|
-
this._value.hasData = false;
|
|
2458
|
-
}
|
|
2459
|
-
this._emitToSubs(["TEARDOWN"], delivery);
|
|
2460
|
-
}
|
|
2461
|
-
}
|
|
2462
|
-
if (!this._wave.insideRunWave) this._wave.emittedDirtyThisWave = false;
|
|
2817
|
+
nodeDown(nodeRuntimeHost(this), msgs);
|
|
2463
2818
|
}
|
|
2464
2819
|
_up(msgs, towardDep, route) {
|
|
2465
|
-
|
|
2466
|
-
const routeState = route ?? { demandFired: /* @__PURE__ */ new Map() };
|
|
2467
|
-
for (const m of msgs) {
|
|
2468
|
-
if (!isUpAllowed(m[0])) {
|
|
2469
|
-
throw new Error(
|
|
2470
|
-
`ctx.up: ${m[0]} is down-only (tier ${messageTier(m[0])}); up carries control tiers only (R-ctx-up)`
|
|
2471
|
-
);
|
|
2472
|
-
}
|
|
2473
|
-
}
|
|
2474
|
-
for (const m of msgs) {
|
|
2475
|
-
if (m[0] === "PAUSE") {
|
|
2476
|
-
this._pauseAcquire(m[1]);
|
|
2477
|
-
} else if (m[0] === "RESUME") {
|
|
2478
|
-
if (this._control.pauseLockset.has(m[1])) {
|
|
2479
|
-
this._pauseRelease(m[1]);
|
|
2480
|
-
} else {
|
|
2481
|
-
this._forwardUp(m, towardDep, routeState);
|
|
2482
|
-
}
|
|
2483
|
-
} else if (m[0] === "PULL") {
|
|
2484
|
-
const demand = normalizePullDemand(m[1]);
|
|
2485
|
-
if (this._slot.pull && demand.pullId === this._slot.pullLock) {
|
|
2486
|
-
if (!this._markDemandRouted(demand.pullId, routeState)) this._onDemand(demand);
|
|
2487
|
-
} else {
|
|
2488
|
-
this._forwardUp(["PULL", demand], towardDep, routeState);
|
|
2489
|
-
}
|
|
2490
|
-
} else if (this._slot.deps.length === 0) {
|
|
2491
|
-
if (m[0] === "INVALIDATE") this._down([["INVALIDATE"]]);
|
|
2492
|
-
} else {
|
|
2493
|
-
this._forwardUp(m, towardDep, routeState);
|
|
2494
|
-
}
|
|
2495
|
-
}
|
|
2820
|
+
nodeUp(nodeRuntimeHost(this), msgs, towardDep, route);
|
|
2496
2821
|
}
|
|
2497
2822
|
_markDemandRouted(lockId, route) {
|
|
2498
|
-
|
|
2499
|
-
if (holders === void 0) {
|
|
2500
|
-
holders = /* @__PURE__ */ new Set();
|
|
2501
|
-
route.demandFired.set(lockId, holders);
|
|
2502
|
-
}
|
|
2503
|
-
if (holders.has(this)) return true;
|
|
2504
|
-
holders.add(this);
|
|
2505
|
-
return false;
|
|
2823
|
+
return nodeMarkDemandRouted(nodeRuntimeHost(this), lockId, route);
|
|
2506
2824
|
}
|
|
2507
|
-
/**
|
|
2508
|
-
* Forward one up-going control message toward deps (R-up-routing): up the single declared edge
|
|
2509
|
-
* `towardDep` (directed — prunes other branches; only meaningful on the issuer's FIRST hop) or
|
|
2510
|
-
* broadcast up ALL deps. A depless source has no deps → the message DROPS here (the terminus —
|
|
2511
|
-
* e.g. a cone-routed PULL whose pullId no node up this cone holds, R-up-at-source). Recursive
|
|
2512
|
-
* forwarding carries the same per-wave route state and no `towardDep` → broadcast beyond the
|
|
2513
|
-
* first hop.
|
|
2514
|
-
*/
|
|
2515
2825
|
_forwardUp(m, towardDep, route) {
|
|
2516
|
-
|
|
2517
|
-
if (towardDep !== void 0) {
|
|
2518
|
-
const d = this._slot.deps[towardDep];
|
|
2519
|
-
if (d !== void 0) d._up([m], void 0, route);
|
|
2520
|
-
} else {
|
|
2521
|
-
for (const dep of this._slot.deps) dep._up([m], void 0, route);
|
|
2522
|
-
}
|
|
2826
|
+
nodeForwardUp(nodeRuntimeHost(this), m, towardDep, route);
|
|
2523
2827
|
}
|
|
2524
|
-
// ── PAUSE/RESUME lockset (R-pause-lockset) + modes (R-pause-modes) ──
|
|
2525
2828
|
_isPaused() {
|
|
2526
|
-
return this
|
|
2829
|
+
return nodeIsPaused(nodeRuntimeHost(this));
|
|
2527
2830
|
}
|
|
2528
2831
|
_hasBoundaryPauseLock() {
|
|
2529
|
-
|
|
2530
|
-
return this._control.pauseLockset.size > 0;
|
|
2832
|
+
return nodeHasBoundaryPauseLock(nodeRuntimeHost(this));
|
|
2531
2833
|
}
|
|
2532
2834
|
_isAsyncPool() {
|
|
2533
|
-
return
|
|
2835
|
+
return nodeIsAsyncPool(nodeRuntimeHost(this));
|
|
2534
2836
|
}
|
|
2535
2837
|
_pauseAcquire(lockId) {
|
|
2536
|
-
this
|
|
2838
|
+
nodePauseAcquire(nodeRuntimeHost(this), lockId);
|
|
2537
2839
|
}
|
|
2538
2840
|
_pauseRelease(lockId) {
|
|
2539
|
-
|
|
2540
|
-
this._control.pauseLockset.delete(lockId);
|
|
2541
|
-
if (this._slot.pull && this._control.demandOwed !== void 0) this._fireOwedDemandIfReady();
|
|
2542
|
-
if (this._hasBoundaryPauseLock()) return;
|
|
2543
|
-
scheduleBoundaryDrain(this._core);
|
|
2544
|
-
if (this._slot.pull) return;
|
|
2545
|
-
this._onResume();
|
|
2841
|
+
nodePauseRelease(nodeRuntimeHost(this), lockId);
|
|
2546
2842
|
}
|
|
2547
2843
|
_onResume() {
|
|
2548
|
-
|
|
2549
|
-
this._control.pauseBuffer = [];
|
|
2550
|
-
this._control.pausedDepWaveOccurred = false;
|
|
2551
|
-
this._control.demandOwed = void 0;
|
|
2552
|
-
this._control.activePull = void 0;
|
|
2553
|
-
this._control.pullDirtyOwed = false;
|
|
2554
|
-
return;
|
|
2555
|
-
}
|
|
2556
|
-
if (this._control.pauseBuffer.length > 0) {
|
|
2557
|
-
const buf = this._control.pauseBuffer;
|
|
2558
|
-
this._control.pauseBuffer = [];
|
|
2559
|
-
for (const wave of buf) this._down(wave);
|
|
2560
|
-
}
|
|
2561
|
-
if (this._control.pausedDepWaveOccurred) {
|
|
2562
|
-
this._control.pausedDepWaveOccurred = false;
|
|
2563
|
-
this._tryRun();
|
|
2564
|
-
}
|
|
2844
|
+
nodeOnResume(nodeRuntimeHost(this));
|
|
2565
2845
|
}
|
|
2566
|
-
/**
|
|
2567
|
-
* R-pull (D269): can this pull node fire a demand NOW? — not terminal, settle-ready (_pending===0),
|
|
2568
|
-
* and no OTHER (non-pullId) lock holds it paused. The gate that decides fire-now vs OWE.
|
|
2569
|
-
*/
|
|
2570
2846
|
_canFireDemand() {
|
|
2571
|
-
|
|
2572
|
-
return this._control.pauseLockset.size === 0;
|
|
2847
|
+
return nodeCanFireDemand(nodeRuntimeHost(this));
|
|
2573
2848
|
}
|
|
2574
|
-
/**
|
|
2575
|
-
* R-pull (D269/D272): deliver ONE demand pulse — install activePull so the demand wave may
|
|
2576
|
-
* emit, fire it, then clear activePull so the node is quiet again (1:1).
|
|
2577
|
-
*/
|
|
2578
2849
|
_deliverPullDemand(demand) {
|
|
2579
|
-
this
|
|
2580
|
-
this._control.activePull = demand;
|
|
2581
|
-
this._control.inDeliverDemand = true;
|
|
2582
|
-
try {
|
|
2583
|
-
this._firePullDemand();
|
|
2584
|
-
} finally {
|
|
2585
|
-
this._control.activePull = void 0;
|
|
2586
|
-
this._control.inDeliverDemand = false;
|
|
2587
|
-
}
|
|
2850
|
+
nodeDeliverPullDemand(nodeRuntimeHost(this), demand);
|
|
2588
2851
|
}
|
|
2589
|
-
/**
|
|
2590
|
-
* R-pull (D269): a cone-routed PULL of THIS node's pullId arrived (R-up-routing) = a DEMAND.
|
|
2591
|
-
* Fire immediately if able; else OWE it — pin-5 (a dep DIRTY in flight, _pending>0) or F4/F5 (an
|
|
2592
|
-
* external PAUSE lock co-holds the node) — and fire when the node next becomes able. A demand
|
|
2593
|
-
* arriving WHILE a delivery is in flight (synchronous re-entry) is DROPPED (1:1, QA guard).
|
|
2594
|
-
*/
|
|
2595
2852
|
_onDemand(demand) {
|
|
2596
|
-
|
|
2597
|
-
if (this._canFireDemand()) this._deliverPullDemand(demand);
|
|
2598
|
-
else this._control.demandOwed = demand;
|
|
2853
|
+
nodeOnDemand(nodeRuntimeHost(this), demand);
|
|
2599
2854
|
}
|
|
2600
|
-
/**
|
|
2601
|
-
* R-pull (D55): service ONE demand. Delivery content = the orthogonal pausable mode:
|
|
2602
|
-
* - 'resumeAll' → drain the buffered BACKLOG (each `_down` re-synthesizes a leading DIRTY, so
|
|
2603
|
-
* the per-entry replay is DIRTY-before-DATA — R-pause-modes per-entry arrival order);
|
|
2604
|
-
* - true → deliver the coalesced LATEST as ONE DIRTY-before-DATA wave (pin 2: the quiet absorb
|
|
2605
|
-
* suppressed the dep's original DIRTY, so the demand wave restores it before the value).
|
|
2606
|
-
* Neither branch fires when nothing changed since the last demand → the demand is SILENT.
|
|
2607
|
-
* Called by `_deliverPullDemand` only when settle-ready; the caller has released the pullId, so
|
|
2608
|
-
* `_markDirty` relays the leading DIRTY (not absorbed).
|
|
2609
|
-
*/
|
|
2610
2855
|
_firePullDemand() {
|
|
2611
|
-
|
|
2612
|
-
if (this._control.pauseBuffer.length > 0) {
|
|
2613
|
-
const buf = this._control.pauseBuffer;
|
|
2614
|
-
this._control.pauseBuffer = [];
|
|
2615
|
-
for (const wave of buf) this._down(wave);
|
|
2616
|
-
drainedBuffer = true;
|
|
2617
|
-
}
|
|
2618
|
-
if (drainedBuffer) return;
|
|
2619
|
-
if (this._control.pausedDepWaveOccurred) {
|
|
2620
|
-
const gated = this._slot.handle !== null && !this._wave.hasCalledFnOnce && !(this._slot.partial || this._allDepsSettled());
|
|
2621
|
-
if (this._wave.pending > 0 || gated) return;
|
|
2622
|
-
this._control.pausedDepWaveOccurred = false;
|
|
2623
|
-
this._wave.emittedDirtyThisWave = false;
|
|
2624
|
-
this._control.pullDirtyOwed = true;
|
|
2625
|
-
try {
|
|
2626
|
-
this._tryRun();
|
|
2627
|
-
} finally {
|
|
2628
|
-
this._control.pullDirtyOwed = false;
|
|
2629
|
-
}
|
|
2630
|
-
return;
|
|
2631
|
-
}
|
|
2632
|
-
if (this._slot.handle !== null) {
|
|
2633
|
-
if (!this._wave.hasCalledFnOnce && !(this._slot.partial || this._allDepsSettled())) return;
|
|
2634
|
-
this._wave.emittedDirtyThisWave = false;
|
|
2635
|
-
this._control.pullDirtyOwed = true;
|
|
2636
|
-
try {
|
|
2637
|
-
this._runWave();
|
|
2638
|
-
} finally {
|
|
2639
|
-
this._control.pullDirtyOwed = false;
|
|
2640
|
-
}
|
|
2641
|
-
}
|
|
2856
|
+
nodeFirePullDemand(nodeRuntimeHost(this));
|
|
2642
2857
|
}
|
|
2643
|
-
/**
|
|
2644
|
-
* R-pull (D269): fire a demand that was OWED (deferred at demand time) once the node becomes
|
|
2645
|
-
* able — called from the dep-settle arms (DATA/RESOLVED/INVALIDATE/terminal drain _pending, pin-5
|
|
2646
|
-
* + B1/F6) and from `_pauseRelease` (an external PAUSE lock releases, F4/F5).
|
|
2647
|
-
*/
|
|
2648
2858
|
_fireOwedDemandIfReady() {
|
|
2649
|
-
|
|
2650
|
-
if (this._slot.pull && this._control.demandOwed !== void 0 && this._canFireDemand()) {
|
|
2651
|
-
this._deliverPullDemand(this._control.demandOwed);
|
|
2652
|
-
}
|
|
2859
|
+
nodeFireOwedDemandIfReady(nodeRuntimeHost(this));
|
|
2653
2860
|
}
|
|
2654
|
-
/** Should an outgoing settle slice be deferred into the pause buffer? */
|
|
2655
2861
|
_shouldBufferOnPause() {
|
|
2656
|
-
|
|
2657
|
-
if (!this._isPaused() && !this._isPullQuiet()) return false;
|
|
2658
|
-
if (this._slot.pausable === "resumeAll") return true;
|
|
2659
|
-
if (!this._wave.insideRunWave && this._isAsyncPool() && this._slot.deps.length > 0) return true;
|
|
2660
|
-
return false;
|
|
2862
|
+
return nodeShouldBufferOnPause(nodeRuntimeHost(this));
|
|
2661
2863
|
}
|
|
2662
|
-
/** R-invalidate-idempotent: clear cache + flush + cascade; no-op if nothing cached. */
|
|
2663
2864
|
_invalidate(delivery) {
|
|
2664
|
-
|
|
2665
|
-
|
|
2666
|
-
this._value.hasData = false;
|
|
2667
|
-
this._value.status = "sentinel";
|
|
2668
|
-
this._value.replayRing = [];
|
|
2669
|
-
for (const fn of this._hooks.onInvalidate) fn();
|
|
2670
|
-
this._emitToSubs(["INVALIDATE"], delivery);
|
|
2671
|
-
}
|
|
2672
|
-
// B42 (R-deps-terminal): ALL deps TERMINAL = every dep has reached COMPLETE *or* an ABSORBED
|
|
2673
|
-
// ERROR. Block only on a LIVE dep (_depTerminal[i] === undefined); an errored dep (terminal = the
|
|
2674
|
-
// error payload, which R-data-payload guarantees is !== undefined and non-boolean) COUNTS as
|
|
2675
|
-
// terminal-done. Was
|
|
2676
|
-
// `tm !== true`, which wedged a node whose errorWhenDepsError:false dep ERRORed (it never
|
|
2677
|
-
// auto-completed even after every other dep completed). Drives the completeWhenDepsComplete cascade.
|
|
2865
|
+
nodeInvalidate(nodeRuntimeHost(this), delivery);
|
|
2866
|
+
}
|
|
2678
2867
|
_allDepsTerminal() {
|
|
2679
|
-
|
|
2680
|
-
|
|
2681
|
-
|
|
2868
|
+
return nodeAllDepsTerminal(nodeRuntimeHost(this));
|
|
2869
|
+
}
|
|
2870
|
+
_emitToSubs(msg, delivery) {
|
|
2871
|
+
nodeEmitToSubs(nodeRuntimeHost(this), msg, delivery);
|
|
2682
2872
|
}
|
|
2683
2873
|
/** R-terminal: resubscribable reset clears terminal + dep state + re-arms the gate. */
|
|
2684
2874
|
_resetLifecycle() {
|
|
2685
|
-
|
|
2686
|
-
this._dep.unsubs = [];
|
|
2687
|
-
this._dep.idxBoxes = [];
|
|
2688
|
-
this._lifecycle.subscribers.clear();
|
|
2689
|
-
this._lifecycle.activated = false;
|
|
2690
|
-
this._value.terminal = void 0;
|
|
2691
|
-
this._value.hasTorndown = false;
|
|
2692
|
-
this._wave.hasCalledFnOnce = false;
|
|
2693
|
-
this._resetDepState();
|
|
2694
|
-
this._control.pauseLockset.clear();
|
|
2695
|
-
this._control.pauseBuffer = [];
|
|
2696
|
-
this._control.pausedDepWaveOccurred = false;
|
|
2697
|
-
this._control.demandOwed = void 0;
|
|
2698
|
-
this._control.activePull = void 0;
|
|
2699
|
-
this._control.pullDirtyOwed = false;
|
|
2700
|
-
this._value.replayRing = [];
|
|
2701
|
-
const isCompute = this._slot.handle !== null || this._slot.deps.length > 0;
|
|
2702
|
-
if (isCompute) {
|
|
2703
|
-
this._value.cache = SENTINEL;
|
|
2704
|
-
this._value.hasData = false;
|
|
2705
|
-
this._value.status = "sentinel";
|
|
2706
|
-
} else {
|
|
2707
|
-
this._value.status = this._value.hasData ? "settled" : "sentinel";
|
|
2708
|
-
}
|
|
2709
|
-
if (!this._privateState.persist) this._privateState.value = SENTINEL;
|
|
2710
|
-
}
|
|
2711
|
-
_emitToSubs(msg, delivery) {
|
|
2712
|
-
if (this._released) return;
|
|
2713
|
-
const subs = [...this._lifecycle.subscribers];
|
|
2714
|
-
for (const sink of subs) sink(msg, delivery);
|
|
2875
|
+
nodeResetLifecycle(nodeRuntimeHost(this));
|
|
2715
2876
|
}
|
|
2716
2877
|
/** Batch commit (R-batch-coalesce): deliver the deferred tier-3 wave now. */
|
|
2717
2878
|
__commitBatchedWave(wave) {
|
|
2718
|
-
this
|
|
2719
|
-
this._down(wave);
|
|
2879
|
+
nodeCommitBatchedWave(nodeRuntimeHost(this), wave);
|
|
2720
2880
|
}
|
|
2721
2881
|
/** Batch rollback: balance the immediate DIRTY with a RESOLVED so downstream un-dirties. */
|
|
2722
2882
|
__rollbackBatched() {
|
|
2723
|
-
|
|
2724
|
-
this._wave.batchDirtyOwed = false;
|
|
2725
|
-
this._wave.emittedDirtyThisWave = false;
|
|
2726
|
-
this._value.status = this._value.hasData ? "settled" : "sentinel";
|
|
2727
|
-
this._emitToSubs(["RESOLVED"]);
|
|
2728
|
-
}
|
|
2883
|
+
nodeRollbackBatched(nodeRuntimeHost(this));
|
|
2729
2884
|
}
|
|
2730
2885
|
/** B49: enqueue a committed-boundary task on this node's graph-local core. */
|
|
2731
2886
|
__deferBoundary(fn, batchToken) {
|
|
2732
|
-
|
|
2733
|
-
batchToken,
|
|
2734
|
-
isReady: () => !this._hasBoundaryPauseLock()
|
|
2735
|
-
});
|
|
2887
|
+
nodeDeferBoundary(nodeRuntimeHost(this), fn, batchToken);
|
|
2736
2888
|
}
|
|
2737
2889
|
};
|
|
2738
2890
|
function node(deps = [], handleOrFn = null, opts = {}) {
|
|
@@ -6082,28 +6234,110 @@ function cloneTopologyValue(value, seen) {
|
|
|
6082
6234
|
return out;
|
|
6083
6235
|
}
|
|
6084
6236
|
|
|
6085
|
-
// src/graph/graph.ts
|
|
6237
|
+
// src/graph/graph-lifecycle.ts
|
|
6086
6238
|
var restoreRegistrars = /* @__PURE__ */ new WeakMap();
|
|
6087
6239
|
var lifecycleRegistrars = /* @__PURE__ */ new WeakMap();
|
|
6088
|
-
|
|
6089
|
-
|
|
6240
|
+
|
|
6241
|
+
// src/graph/graph-support.ts
|
|
6242
|
+
function isNonAuthoritativeCollectionHelperMeta(meta) {
|
|
6243
|
+
return meta?.kind === "collection_delta" || meta?.kind === "collection_intent" || meta?.kind === "collection_policy_apply" || meta?.kind === "collection_snapshot" || meta?.kind === "collection_snapshot_prep";
|
|
6090
6244
|
}
|
|
6091
|
-
function
|
|
6092
|
-
if (
|
|
6093
|
-
throw new Error(`${label} has been released from its graph lifecycle (D122)`);
|
|
6094
|
-
}
|
|
6095
|
-
const existing = nodeOwner(n);
|
|
6096
|
-
if (existing !== void 0 && existing !== owner) {
|
|
6245
|
+
function assertCheckpointQuiescentStatus(status, id, op) {
|
|
6246
|
+
if (status === "pending" || status === "dirty") {
|
|
6097
6247
|
throw new Error(
|
|
6098
|
-
`${
|
|
6248
|
+
`${op}: node '${id}' has non-quiescent status '${status}' that cannot be checkpoint-restored yet`
|
|
6099
6249
|
);
|
|
6100
6250
|
}
|
|
6101
6251
|
}
|
|
6102
|
-
|
|
6103
|
-
|
|
6104
|
-
|
|
6252
|
+
function topologyPathMatches(eventPath, path) {
|
|
6253
|
+
return eventPath === path || eventPath.startsWith(`${path}::`);
|
|
6254
|
+
}
|
|
6255
|
+
function prefixTopologyPath(prefix, path) {
|
|
6256
|
+
return `${prefix}::${path}`;
|
|
6257
|
+
}
|
|
6258
|
+
function cloneTopologyEvent(event) {
|
|
6259
|
+
const deps = Object.freeze([...event.deps]);
|
|
6260
|
+
const prevDeps = event.prevDeps === void 0 ? void 0 : Object.freeze([...event.prevDeps]);
|
|
6261
|
+
return Object.freeze({
|
|
6262
|
+
kind: event.kind,
|
|
6263
|
+
path: event.path,
|
|
6264
|
+
deps,
|
|
6265
|
+
...prevDeps !== void 0 ? { prevDeps } : {},
|
|
6266
|
+
...event.factory !== void 0 ? { factory: event.factory } : {},
|
|
6267
|
+
seq: event.seq
|
|
6268
|
+
});
|
|
6269
|
+
}
|
|
6270
|
+
function checkpointFactory(name, node2, unregistered, restore, meta) {
|
|
6271
|
+
const state = checkpointStateOfNode(node2);
|
|
6272
|
+
if (unregistered) {
|
|
6273
|
+
return {
|
|
6274
|
+
kind: "local-only",
|
|
6275
|
+
name,
|
|
6276
|
+
reason: "node is an unregistered live dependency auto-discovered from topology"
|
|
6277
|
+
};
|
|
6105
6278
|
}
|
|
6106
|
-
|
|
6279
|
+
if (restore === void 0 && typeof meta?.kind === "string" && meta.kind.startsWith("collection_")) {
|
|
6280
|
+
return {
|
|
6281
|
+
kind: "local-only",
|
|
6282
|
+
name,
|
|
6283
|
+
reason: "collection helper node has no backend checkpoint restore metadata"
|
|
6284
|
+
};
|
|
6285
|
+
}
|
|
6286
|
+
if (restore !== void 0) {
|
|
6287
|
+
const out = {
|
|
6288
|
+
kind: "registry-ref",
|
|
6289
|
+
ref: toCheckpointJson(restore.ref, `${name}.factory.ref`)
|
|
6290
|
+
};
|
|
6291
|
+
if (restore.config !== void 0)
|
|
6292
|
+
out.config = toCheckpointJson(restore.config, `${name}.factory.config`);
|
|
6293
|
+
if (restore.configVersion !== void 0)
|
|
6294
|
+
out.configVersion = toCheckpointJson(restore.configVersion, `${name}.factory.configVersion`);
|
|
6295
|
+
return out;
|
|
6296
|
+
}
|
|
6297
|
+
if (state.handle !== null) {
|
|
6298
|
+
return {
|
|
6299
|
+
kind: "local-only",
|
|
6300
|
+
name,
|
|
6301
|
+
reason: "node uses a function body; first-cut checkpoints do not serialize local functions"
|
|
6302
|
+
};
|
|
6303
|
+
}
|
|
6304
|
+
return { kind: "registry-ref", ref: name };
|
|
6305
|
+
}
|
|
6306
|
+
function explainSubset(snap, chain) {
|
|
6307
|
+
const fwd = /* @__PURE__ */ new Map();
|
|
6308
|
+
const rev = /* @__PURE__ */ new Map();
|
|
6309
|
+
const push = (map2, k, v) => {
|
|
6310
|
+
const a = map2.get(k);
|
|
6311
|
+
if (a) a.push(v);
|
|
6312
|
+
else map2.set(k, [v]);
|
|
6313
|
+
};
|
|
6314
|
+
for (const e of snap.edges) {
|
|
6315
|
+
push(fwd, e.from, e.to);
|
|
6316
|
+
push(rev, e.to, e.from);
|
|
6317
|
+
}
|
|
6318
|
+
const reach = (start, adj) => {
|
|
6319
|
+
const seen = /* @__PURE__ */ new Set([start]);
|
|
6320
|
+
const stack = [start];
|
|
6321
|
+
while (stack.length > 0) {
|
|
6322
|
+
const cur = stack.pop();
|
|
6323
|
+
for (const nxt of adj.get(cur) ?? []) {
|
|
6324
|
+
if (!seen.has(nxt)) {
|
|
6325
|
+
seen.add(nxt);
|
|
6326
|
+
stack.push(nxt);
|
|
6327
|
+
}
|
|
6328
|
+
}
|
|
6329
|
+
}
|
|
6330
|
+
return seen;
|
|
6331
|
+
};
|
|
6332
|
+
const onPath = new Set([...reach(chain.from, fwd)].filter((id) => reach(chain.to, rev).has(id)));
|
|
6333
|
+
return {
|
|
6334
|
+
...snap.name !== void 0 ? { name: snap.name } : {},
|
|
6335
|
+
nodes: snap.nodes.filter((n) => onPath.has(n.id)),
|
|
6336
|
+
edges: snap.edges.filter((e) => onPath.has(e.from) && onPath.has(e.to))
|
|
6337
|
+
};
|
|
6338
|
+
}
|
|
6339
|
+
|
|
6340
|
+
// src/graph/graph-topology-group.ts
|
|
6107
6341
|
var GraphTopologyGroup = class {
|
|
6108
6342
|
name;
|
|
6109
6343
|
_graph;
|
|
@@ -6164,6 +6398,27 @@ var GraphTopologyGroup = class {
|
|
|
6164
6398
|
}
|
|
6165
6399
|
}
|
|
6166
6400
|
};
|
|
6401
|
+
|
|
6402
|
+
// src/graph/graph.ts
|
|
6403
|
+
function nodeOwner(n) {
|
|
6404
|
+
return getNodeOwner(n);
|
|
6405
|
+
}
|
|
6406
|
+
function assertGraphLocalNode(owner, n, label) {
|
|
6407
|
+
if (isNodeRuntimeReleased(n)) {
|
|
6408
|
+
throw new Error(`${label} has been released from its graph lifecycle (D122)`);
|
|
6409
|
+
}
|
|
6410
|
+
const existing = nodeOwner(n);
|
|
6411
|
+
if (existing !== void 0 && existing !== owner) {
|
|
6412
|
+
throw new Error(
|
|
6413
|
+
`${label} belongs to a different graph; cross-graph deps require a wire bridge`
|
|
6414
|
+
);
|
|
6415
|
+
}
|
|
6416
|
+
}
|
|
6417
|
+
var StateNode = class extends Node {
|
|
6418
|
+
set(v) {
|
|
6419
|
+
this.down([["DATA", v]]);
|
|
6420
|
+
}
|
|
6421
|
+
};
|
|
6167
6422
|
var Graph = class {
|
|
6168
6423
|
name;
|
|
6169
6424
|
_dispatcher;
|
|
@@ -6829,103 +7084,6 @@ var Graph = class {
|
|
|
6829
7084
|
return out;
|
|
6830
7085
|
}
|
|
6831
7086
|
};
|
|
6832
|
-
function isNonAuthoritativeCollectionHelperMeta(meta) {
|
|
6833
|
-
return meta?.kind === "collection_delta" || meta?.kind === "collection_intent" || meta?.kind === "collection_policy_apply" || meta?.kind === "collection_snapshot" || meta?.kind === "collection_snapshot_prep";
|
|
6834
|
-
}
|
|
6835
|
-
function assertCheckpointQuiescentStatus(status, id, op) {
|
|
6836
|
-
if (status === "pending" || status === "dirty") {
|
|
6837
|
-
throw new Error(
|
|
6838
|
-
`${op}: node '${id}' has non-quiescent status '${status}' that cannot be checkpoint-restored yet`
|
|
6839
|
-
);
|
|
6840
|
-
}
|
|
6841
|
-
}
|
|
6842
|
-
function topologyPathMatches(eventPath, path) {
|
|
6843
|
-
return eventPath === path || eventPath.startsWith(`${path}::`);
|
|
6844
|
-
}
|
|
6845
|
-
function prefixTopologyPath(prefix, path) {
|
|
6846
|
-
return `${prefix}::${path}`;
|
|
6847
|
-
}
|
|
6848
|
-
function cloneTopologyEvent(event) {
|
|
6849
|
-
const deps = Object.freeze([...event.deps]);
|
|
6850
|
-
const prevDeps = event.prevDeps === void 0 ? void 0 : Object.freeze([...event.prevDeps]);
|
|
6851
|
-
return Object.freeze({
|
|
6852
|
-
kind: event.kind,
|
|
6853
|
-
path: event.path,
|
|
6854
|
-
deps,
|
|
6855
|
-
...prevDeps !== void 0 ? { prevDeps } : {},
|
|
6856
|
-
...event.factory !== void 0 ? { factory: event.factory } : {},
|
|
6857
|
-
seq: event.seq
|
|
6858
|
-
});
|
|
6859
|
-
}
|
|
6860
|
-
function checkpointFactory(name, node2, unregistered, restore, meta) {
|
|
6861
|
-
const state = checkpointStateOfNode(node2);
|
|
6862
|
-
if (unregistered) {
|
|
6863
|
-
return {
|
|
6864
|
-
kind: "local-only",
|
|
6865
|
-
name,
|
|
6866
|
-
reason: "node is an unregistered live dependency auto-discovered from topology"
|
|
6867
|
-
};
|
|
6868
|
-
}
|
|
6869
|
-
if (restore === void 0 && typeof meta?.kind === "string" && meta.kind.startsWith("collection_")) {
|
|
6870
|
-
return {
|
|
6871
|
-
kind: "local-only",
|
|
6872
|
-
name,
|
|
6873
|
-
reason: "collection helper node has no backend checkpoint restore metadata"
|
|
6874
|
-
};
|
|
6875
|
-
}
|
|
6876
|
-
if (restore !== void 0) {
|
|
6877
|
-
const out = {
|
|
6878
|
-
kind: "registry-ref",
|
|
6879
|
-
ref: toCheckpointJson(restore.ref, `${name}.factory.ref`)
|
|
6880
|
-
};
|
|
6881
|
-
if (restore.config !== void 0)
|
|
6882
|
-
out.config = toCheckpointJson(restore.config, `${name}.factory.config`);
|
|
6883
|
-
if (restore.configVersion !== void 0)
|
|
6884
|
-
out.configVersion = toCheckpointJson(restore.configVersion, `${name}.factory.configVersion`);
|
|
6885
|
-
return out;
|
|
6886
|
-
}
|
|
6887
|
-
if (state.handle !== null) {
|
|
6888
|
-
return {
|
|
6889
|
-
kind: "local-only",
|
|
6890
|
-
name,
|
|
6891
|
-
reason: "node uses a function body; first-cut checkpoints do not serialize local functions"
|
|
6892
|
-
};
|
|
6893
|
-
}
|
|
6894
|
-
return { kind: "registry-ref", ref: name };
|
|
6895
|
-
}
|
|
6896
|
-
function explainSubset(snap, chain) {
|
|
6897
|
-
const fwd = /* @__PURE__ */ new Map();
|
|
6898
|
-
const rev = /* @__PURE__ */ new Map();
|
|
6899
|
-
const push = (map2, k, v) => {
|
|
6900
|
-
const a = map2.get(k);
|
|
6901
|
-
if (a) a.push(v);
|
|
6902
|
-
else map2.set(k, [v]);
|
|
6903
|
-
};
|
|
6904
|
-
for (const e of snap.edges) {
|
|
6905
|
-
push(fwd, e.from, e.to);
|
|
6906
|
-
push(rev, e.to, e.from);
|
|
6907
|
-
}
|
|
6908
|
-
const reach = (start, adj) => {
|
|
6909
|
-
const seen = /* @__PURE__ */ new Set([start]);
|
|
6910
|
-
const stack = [start];
|
|
6911
|
-
while (stack.length > 0) {
|
|
6912
|
-
const cur = stack.pop();
|
|
6913
|
-
for (const nxt of adj.get(cur) ?? []) {
|
|
6914
|
-
if (!seen.has(nxt)) {
|
|
6915
|
-
seen.add(nxt);
|
|
6916
|
-
stack.push(nxt);
|
|
6917
|
-
}
|
|
6918
|
-
}
|
|
6919
|
-
}
|
|
6920
|
-
return seen;
|
|
6921
|
-
};
|
|
6922
|
-
const onPath = new Set([...reach(chain.from, fwd)].filter((id) => reach(chain.to, rev).has(id)));
|
|
6923
|
-
return {
|
|
6924
|
-
...snap.name !== void 0 ? { name: snap.name } : {},
|
|
6925
|
-
nodes: snap.nodes.filter((n) => onPath.has(n.id)),
|
|
6926
|
-
edges: snap.edges.filter((e) => onPath.has(e.from) && onPath.has(e.to))
|
|
6927
|
-
};
|
|
6928
|
-
}
|
|
6929
7087
|
function graph(opts = {}) {
|
|
6930
7088
|
return new Graph(opts);
|
|
6931
7089
|
}
|