@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.
Files changed (330) hide show
  1. package/dist/actions-types-CSC3NMDl.d.ts +657 -0
  2. package/dist/actions-types-wl9Mgkmr.d.cts +657 -0
  3. package/dist/adapters/index.cjs +5157 -2951
  4. package/dist/adapters/index.cjs.map +1 -1
  5. package/dist/adapters/index.d.cts +207 -70
  6. package/dist/adapters/index.d.ts +207 -70
  7. package/dist/adapters/index.js +3738 -1688
  8. package/dist/adapters/index.js.map +1 -1
  9. package/dist/adapters/nestjs/microservices.cjs +841 -0
  10. package/dist/adapters/nestjs/microservices.cjs.map +1 -0
  11. package/dist/adapters/nestjs/microservices.d.cts +45 -0
  12. package/dist/adapters/nestjs/microservices.d.ts +45 -0
  13. package/dist/adapters/nestjs/microservices.js +206 -0
  14. package/dist/adapters/nestjs/microservices.js.map +1 -0
  15. package/dist/adapters/nestjs/native.cjs +1391 -0
  16. package/dist/adapters/nestjs/native.cjs.map +1 -0
  17. package/dist/adapters/nestjs/native.d.cts +111 -0
  18. package/dist/adapters/nestjs/native.d.ts +111 -0
  19. package/dist/adapters/nestjs/native.js +577 -0
  20. package/dist/adapters/nestjs/native.js.map +1 -0
  21. package/dist/adapters/nestjs/websockets.cjs +924 -0
  22. package/dist/adapters/nestjs/websockets.cjs.map +1 -0
  23. package/dist/adapters/nestjs/websockets.d.cts +47 -0
  24. package/dist/adapters/nestjs/websockets.d.ts +47 -0
  25. package/dist/adapters/nestjs/websockets.js +286 -0
  26. package/dist/adapters/nestjs/websockets.js.map +1 -0
  27. package/dist/adapters/nestjs.cjs +1085 -0
  28. package/dist/adapters/nestjs.cjs.map +1 -0
  29. package/dist/adapters/nestjs.d.cts +385 -0
  30. package/dist/adapters/nestjs.d.ts +385 -0
  31. package/dist/adapters/nestjs.js +112 -0
  32. package/dist/adapters/nestjs.js.map +1 -0
  33. package/dist/adapters/observe-storage.d.cts +3 -3
  34. package/dist/adapters/observe-storage.d.ts +3 -3
  35. package/dist/adapters/observe-storage.js +4 -4
  36. package/dist/adapters/react.cjs.map +1 -1
  37. package/dist/adapters/react.d.cts +2 -2
  38. package/dist/adapters/react.d.ts +2 -2
  39. package/dist/adapters/react.js +1 -1
  40. package/dist/adapters/solid.cjs.map +1 -1
  41. package/dist/adapters/solid.d.cts +2 -2
  42. package/dist/adapters/solid.d.ts +2 -2
  43. package/dist/adapters/solid.js +1 -1
  44. package/dist/adapters/svelte.cjs.map +1 -1
  45. package/dist/adapters/svelte.d.cts +2 -2
  46. package/dist/adapters/svelte.d.ts +2 -2
  47. package/dist/adapters/svelte.js +1 -1
  48. package/dist/adapters/vue.cjs.map +1 -1
  49. package/dist/adapters/vue.d.cts +2 -2
  50. package/dist/adapters/vue.d.ts +2 -2
  51. package/dist/adapters/vue.js +1 -1
  52. package/dist/{agent-runtime-DZTJ3C-p.d.cts → agent-runtime-types-core-CaXfKNtY.d.cts} +171 -320
  53. package/dist/{agent-runtime-BesGDZcB.d.ts → agent-runtime-types-core-hU299uIC.d.ts} +171 -320
  54. package/dist/agent-runtime-types-tool-BEpSINol.d.ts +695 -0
  55. package/dist/agent-runtime-types-tool-DninPEzk.d.cts +695 -0
  56. package/dist/agentic-memory-retention-BmGX368S.d.ts +14 -0
  57. package/dist/agentic-memory-retention-Ih1qhX9Z.d.cts +14 -0
  58. package/dist/{agentic-memory-BmRCvh0d.d.ts → agentic-memory-types-CVSUS6XR.d.ts} +13 -57
  59. package/dist/{agentic-memory-DfuVZ-lY.d.cts → agentic-memory-types-FnnYlVUs.d.cts} +13 -57
  60. package/dist/{capability-admission-g0mn9hpq.d.ts → capability-admission-BW2CziT6.d.ts} +3 -3
  61. package/dist/{capability-admission-B0BzqAm5.d.cts → capability-admission-lwSecxXs.d.cts} +3 -3
  62. package/dist/chunk-2KUAG2GZ.js +9693 -0
  63. package/dist/chunk-2KUAG2GZ.js.map +1 -0
  64. package/dist/chunk-2NJP6GO4.js +1320 -0
  65. package/dist/chunk-2NJP6GO4.js.map +1 -0
  66. package/dist/{chunk-YDSIVHRR.js → chunk-4NWSNI4K.js} +1598 -1584
  67. package/dist/chunk-4NWSNI4K.js.map +1 -0
  68. package/dist/{chunk-Z2ANQ6JW.js → chunk-4Q77MMJY.js} +2 -2
  69. package/dist/chunk-6E76H4OU.js +132 -0
  70. package/dist/chunk-6E76H4OU.js.map +1 -0
  71. package/dist/chunk-7GOTIIQ7.js +819 -0
  72. package/dist/chunk-7GOTIIQ7.js.map +1 -0
  73. package/dist/{chunk-IXZBUWSP.js → chunk-7HZRJMN6.js} +2 -2
  74. package/dist/{chunk-SS2A464I.js → chunk-CJIFGJQG.js} +3 -3
  75. package/dist/{chunk-V7CIJE4B.js → chunk-CX6B6PO2.js} +92 -9
  76. package/dist/chunk-CX6B6PO2.js.map +1 -0
  77. package/dist/{chunk-FBUU43PM.js → chunk-E4QCH32M.js} +448 -446
  78. package/dist/chunk-E4QCH32M.js.map +1 -0
  79. package/dist/{chunk-HKK2JD7Z.js → chunk-ECURQ3HD.js} +12 -125
  80. package/dist/chunk-ECURQ3HD.js.map +1 -0
  81. package/dist/{chunk-3JR3EDB2.js → chunk-EOKT4QFF.js} +121 -115
  82. package/dist/chunk-EOKT4QFF.js.map +1 -0
  83. package/dist/{chunk-K3FXTC3I.js → chunk-HJACH5PU.js} +3 -3
  84. package/dist/{chunk-GTPCOEOZ.js → chunk-IDMLXLLG.js} +3 -3
  85. package/dist/{chunk-DKP56CSW.js → chunk-JKAYLDQV.js} +2 -2
  86. package/dist/{chunk-4VLAQHZI.js → chunk-K7FB3JTD.js} +17 -1
  87. package/dist/chunk-K7FB3JTD.js.map +1 -0
  88. package/dist/{chunk-H75VXTGT.js → chunk-L6LDXRWE.js} +3 -3
  89. package/dist/{chunk-H75VXTGT.js.map → chunk-L6LDXRWE.js.map} +1 -1
  90. package/dist/{chunk-YXMZ2N6J.js → chunk-M7J6Z4IJ.js} +1071 -1025
  91. package/dist/chunk-M7J6Z4IJ.js.map +1 -0
  92. package/dist/chunk-MQEQMS7B.js +1009 -0
  93. package/dist/chunk-MQEQMS7B.js.map +1 -0
  94. package/dist/chunk-MTELVIYR.js +1421 -0
  95. package/dist/chunk-MTELVIYR.js.map +1 -0
  96. package/dist/{chunk-QFY4AFY4.js → chunk-PVC7WDKI.js} +58 -52
  97. package/dist/chunk-PVC7WDKI.js.map +1 -0
  98. package/dist/{chunk-VTHLCFN4.js → chunk-RAHNUYA5.js} +2 -2
  99. package/dist/{chunk-XKXWK2KP.js → chunk-SHZDP2MQ.js} +1157 -1021
  100. package/dist/chunk-SHZDP2MQ.js.map +1 -0
  101. package/dist/{chunk-CZNV3VXM.js → chunk-SIDJO2T4.js} +11 -11
  102. package/dist/chunk-STXRMPW4.js +4131 -0
  103. package/dist/chunk-STXRMPW4.js.map +1 -0
  104. package/dist/{chunk-2747WN4Y.js → chunk-TPND5MJS.js} +3 -3
  105. package/dist/chunk-TQPCAIQI.js +612 -0
  106. package/dist/chunk-TQPCAIQI.js.map +1 -0
  107. package/dist/{chunk-43BKLFZU.js → chunk-YDWBXXQZ.js} +10 -10
  108. package/dist/{chunk-6PHB5CJS.js → chunk-ZLFRB6FI.js} +2 -2
  109. package/dist/composition/index.cjs +1228 -1076
  110. package/dist/composition/index.cjs.map +1 -1
  111. package/dist/composition/index.d.cts +3 -3
  112. package/dist/composition/index.d.ts +3 -3
  113. package/dist/composition/index.js +4 -4
  114. package/dist/core/index.cjs +1198 -1046
  115. package/dist/core/index.cjs.map +1 -1
  116. package/dist/core/index.d.cts +1 -1
  117. package/dist/core/index.d.ts +1 -1
  118. package/dist/core/index.js +2 -2
  119. package/dist/cqrs/index.d.cts +3 -3
  120. package/dist/cqrs/index.d.ts +3 -3
  121. package/dist/cqrs/messaging.d.cts +4 -4
  122. package/dist/cqrs/messaging.d.ts +4 -4
  123. package/dist/cqrs/work-queue.d.cts +5 -5
  124. package/dist/cqrs/work-queue.d.ts +5 -5
  125. package/dist/data-structures/index.cjs +1226 -1074
  126. package/dist/data-structures/index.cjs.map +1 -1
  127. package/dist/data-structures/index.d.cts +8 -7
  128. package/dist/data-structures/index.d.ts +8 -7
  129. package/dist/data-structures/index.js +6 -5
  130. package/dist/{describe-BpyJuWkw.d.ts → describe-B_A5fbXH.d.ts} +1 -1
  131. package/dist/{describe-DYMw_l1C.d.cts → describe-CQRrkv-Q.d.cts} +1 -1
  132. package/dist/executors/tool-provider-adapters.cjs +3091 -0
  133. package/dist/executors/tool-provider-adapters.cjs.map +1 -0
  134. package/dist/executors/tool-provider-adapters.d.cts +174 -0
  135. package/dist/executors/tool-provider-adapters.d.ts +174 -0
  136. package/dist/executors/tool-provider-adapters.js +1336 -0
  137. package/dist/executors/tool-provider-adapters.js.map +1 -0
  138. package/dist/executors/tool-provider-runtime.cjs +5178 -0
  139. package/dist/executors/tool-provider-runtime.cjs.map +1 -0
  140. package/dist/executors/tool-provider-runtime.d.cts +17 -0
  141. package/dist/executors/tool-provider-runtime.d.ts +17 -0
  142. package/dist/executors/tool-provider-runtime.js +15 -0
  143. package/dist/executors/tool-provider-runtime.js.map +1 -0
  144. package/dist/executors/tool-provider.cjs +6392 -0
  145. package/dist/executors/tool-provider.cjs.map +1 -0
  146. package/dist/executors/tool-provider.d.cts +60 -0
  147. package/dist/executors/tool-provider.d.ts +60 -0
  148. package/dist/executors/tool-provider.js +89 -0
  149. package/dist/executors/tool-provider.js.map +1 -0
  150. package/dist/executors/work-queue.d.cts +6 -6
  151. package/dist/executors/work-queue.d.ts +6 -6
  152. package/dist/graph/index.cjs +1499 -1341
  153. package/dist/graph/index.cjs.map +1 -1
  154. package/dist/graph/index.d.cts +9 -8
  155. package/dist/graph/index.d.ts +9 -8
  156. package/dist/graph/index.js +23 -22
  157. package/dist/{graph-DCEWh4T2.d.cts → graph-CWK3HLPB.d.cts} +133 -131
  158. package/dist/{graph-D-1-SQeC.d.ts → graph-ho5sotHP.d.ts} +133 -131
  159. package/dist/{index-Bmxeu0nK.d.ts → index-CQWcE0Dw.d.ts} +18 -4
  160. package/dist/{index-72VZC0-E.d.cts → index-DHA1i67c.d.cts} +18 -4
  161. package/dist/index.cjs +3397 -3140
  162. package/dist/index.cjs.map +1 -1
  163. package/dist/index.d.cts +12 -9
  164. package/dist/index.d.ts +12 -9
  165. package/dist/index.js +110 -109
  166. package/dist/inspection/boundary.d.cts +4 -4
  167. package/dist/inspection/boundary.d.ts +4 -4
  168. package/dist/measurements-C0mAvWU1.d.cts +164 -0
  169. package/dist/measurements-OMpCeBwh.d.ts +164 -0
  170. package/dist/messaging/index.cjs +57 -51
  171. package/dist/messaging/index.cjs.map +1 -1
  172. package/dist/messaging/index.d.cts +11 -276
  173. package/dist/messaging/index.d.ts +11 -276
  174. package/dist/messaging/index.js +1 -1
  175. package/dist/operators/index.cjs +1228 -1076
  176. package/dist/operators/index.cjs.map +1 -1
  177. package/dist/operators/index.d.cts +5 -5
  178. package/dist/operators/index.d.ts +5 -5
  179. package/dist/operators/index.js +5 -5
  180. package/dist/orchestration/index.cjs +8844 -6071
  181. package/dist/orchestration/index.cjs.map +1 -1
  182. package/dist/orchestration/index.d.cts +171 -224
  183. package/dist/orchestration/index.d.ts +171 -224
  184. package/dist/orchestration/index.js +42 -991
  185. package/dist/orchestration/index.js.map +1 -1
  186. package/dist/orchestration/messaging.d.cts +5 -8
  187. package/dist/orchestration/messaging.d.ts +5 -8
  188. package/dist/orchestration/work-queue.cjs +1243 -5
  189. package/dist/orchestration/work-queue.cjs.map +1 -1
  190. package/dist/orchestration/work-queue.d.cts +121 -10
  191. package/dist/orchestration/work-queue.d.ts +121 -10
  192. package/dist/orchestration/work-queue.js +1067 -4
  193. package/dist/orchestration/work-queue.js.map +1 -1
  194. package/dist/patterns/event-flow.cjs +6 -20
  195. package/dist/patterns/event-flow.cjs.map +1 -1
  196. package/dist/patterns/event-flow.d.cts +4 -4
  197. package/dist/patterns/event-flow.d.ts +4 -4
  198. package/dist/patterns/event-flow.js +2 -2
  199. package/dist/patterns/index.cjs +453 -465
  200. package/dist/patterns/index.cjs.map +1 -1
  201. package/dist/patterns/index.d.cts +6 -5
  202. package/dist/patterns/index.d.ts +6 -5
  203. package/dist/patterns/index.js +3 -3
  204. package/dist/process-types-C9uMYz3i.d.ts +200 -0
  205. package/dist/process-types-h3uRlzDc.d.cts +200 -0
  206. package/dist/{reactive-collection-DNV0-gFi.d.cts → reactive-collection-B9R0Bl1P.d.cts} +4 -34
  207. package/dist/{reactive-collection-BAmfrGjd.d.ts → reactive-collection-BXFrH0U2.d.ts} +4 -34
  208. package/dist/{reactive-collection-storage-BNEldDyi.d.cts → reactive-collection-storage-BLGv8Xp8.d.cts} +5 -5
  209. package/dist/{reactive-collection-storage-YZsAQsWK.d.ts → reactive-collection-storage-a4zD3665.d.ts} +5 -5
  210. package/dist/{reactive-map-DRD1LJ2H.d.cts → reactive-map-C_8sOfdS.d.cts} +3 -2
  211. package/dist/{reactive-map-EsDiCmJk.d.ts → reactive-map-jle5dnok.d.ts} +3 -2
  212. package/dist/render/index.d.cts +2 -2
  213. package/dist/render/index.d.ts +2 -2
  214. package/dist/scheduled-readiness-5rwQlyjV.d.ts +91 -0
  215. package/dist/scheduled-readiness-DpRY8jI0.d.cts +91 -0
  216. package/dist/semantic-memory-graph-C2ZUwIlq.d.ts +30 -0
  217. package/dist/semantic-memory-graph-DlZBD_Eu.d.cts +30 -0
  218. package/dist/{semantic-memory-graph-DKuNzuWw.d.cts → semantic-memory-graph-types-BvzdqmkY.d.cts} +2 -28
  219. package/dist/{semantic-memory-graph-uwbwJdhe.d.ts → semantic-memory-graph-types-Ci-OtahO.d.ts} +2 -28
  220. package/dist/solutions/index.cjs +6353 -6169
  221. package/dist/solutions/index.cjs.map +1 -1
  222. package/dist/solutions/index.d.cts +12 -10
  223. package/dist/solutions/index.d.ts +12 -10
  224. package/dist/solutions/index.js +5 -5
  225. package/dist/solutions/reactive-layout/browser/index.cjs +116 -108
  226. package/dist/solutions/reactive-layout/browser/index.cjs.map +1 -1
  227. package/dist/solutions/reactive-layout/browser/index.d.cts +4 -4
  228. package/dist/solutions/reactive-layout/browser/index.d.ts +4 -4
  229. package/dist/solutions/reactive-layout/browser/index.js +3 -3
  230. package/dist/solutions/reactive-layout/index.cjs +3578 -3350
  231. package/dist/solutions/reactive-layout/index.cjs.map +1 -1
  232. package/dist/solutions/reactive-layout/index.d.cts +32 -576
  233. package/dist/solutions/reactive-layout/index.d.ts +32 -576
  234. package/dist/solutions/reactive-layout/index.js +65 -5
  235. package/dist/solutions/reactive-layout/node-canvas/index.cjs +127 -117
  236. package/dist/solutions/reactive-layout/node-canvas/index.cjs.map +1 -1
  237. package/dist/solutions/reactive-layout/node-canvas/index.d.cts +4 -4
  238. package/dist/solutions/reactive-layout/node-canvas/index.d.ts +4 -4
  239. package/dist/solutions/reactive-layout/node-canvas/index.js +3 -3
  240. package/dist/solutions/reactive-layout/react-native/index.cjs +127 -117
  241. package/dist/solutions/reactive-layout/react-native/index.cjs.map +1 -1
  242. package/dist/solutions/reactive-layout/react-native/index.d.cts +4 -4
  243. package/dist/solutions/reactive-layout/react-native/index.d.ts +4 -4
  244. package/dist/solutions/reactive-layout/react-native/index.js +3 -3
  245. package/dist/solutions/reactive-layout/skia/index.cjs +127 -117
  246. package/dist/solutions/reactive-layout/skia/index.cjs.map +1 -1
  247. package/dist/solutions/reactive-layout/skia/index.d.cts +4 -4
  248. package/dist/solutions/reactive-layout/skia/index.d.ts +4 -4
  249. package/dist/solutions/reactive-layout/skia/index.js +3 -3
  250. package/dist/solutions/work-item/actions.cjs +1609 -1428
  251. package/dist/solutions/work-item/actions.cjs.map +1 -1
  252. package/dist/solutions/work-item/actions.d.cts +23 -184
  253. package/dist/solutions/work-item/actions.d.ts +23 -184
  254. package/dist/solutions/work-item/actions.js +1558 -934
  255. package/dist/solutions/work-item/actions.js.map +1 -1
  256. package/dist/solutions/work-item/scheduling.cjs +9181 -1838
  257. package/dist/solutions/work-item/scheduling.cjs.map +1 -1
  258. package/dist/solutions/work-item/scheduling.d.cts +1763 -328
  259. package/dist/solutions/work-item/scheduling.d.ts +1763 -328
  260. package/dist/solutions/work-item/scheduling.js +117 -3
  261. package/dist/solutions/work-item/work-queue.d.cts +7 -7
  262. package/dist/solutions/work-item/work-queue.d.ts +7 -7
  263. package/dist/sources/browser.cjs +1318 -1083
  264. package/dist/sources/browser.cjs.map +1 -1
  265. package/dist/sources/browser.d.cts +4 -4
  266. package/dist/sources/browser.d.ts +4 -4
  267. package/dist/sources/browser.js +4 -4
  268. package/dist/sources/index.cjs +1318 -1083
  269. package/dist/sources/index.cjs.map +1 -1
  270. package/dist/sources/index.d.cts +4 -4
  271. package/dist/sources/index.d.ts +4 -4
  272. package/dist/sources/index.js +4 -4
  273. package/dist/sources/node.d.cts +3 -3
  274. package/dist/sources/node.d.ts +3 -3
  275. package/dist/storage/browser.cjs +16 -0
  276. package/dist/storage/browser.cjs.map +1 -1
  277. package/dist/storage/browser.js +3 -3
  278. package/dist/storage/index.cjs +16 -0
  279. package/dist/storage/index.cjs.map +1 -1
  280. package/dist/storage/index.d.cts +5 -4
  281. package/dist/storage/index.d.ts +5 -4
  282. package/dist/storage/index.js +6 -6
  283. package/dist/storage/node.cjs +16 -0
  284. package/dist/storage/node.cjs.map +1 -1
  285. package/dist/storage/node.js +3 -3
  286. package/dist/{store-C-joM4gh.d.ts → store-BmtEs9mG.d.ts} +1 -1
  287. package/dist/{store-CNJwmT-h.d.cts → store-PAAsYvML.d.cts} +1 -1
  288. package/dist/types-BRNKoFHj.d.ts +357 -0
  289. package/dist/{types-CcPIn7sy.d.cts → types-BS6CyR-x.d.cts} +27 -108
  290. package/dist/types-BWK2ay3e.d.cts +457 -0
  291. package/dist/types-BXKSAoE1.d.cts +357 -0
  292. package/dist/types-BaPpZItj.d.ts +457 -0
  293. package/dist/types-BhveCMg5.d.cts +274 -0
  294. package/dist/{types-BsJvElYZ.d.ts → types-C9NOgNJw.d.ts} +27 -108
  295. package/dist/types-CTsQ8Ww4.d.ts +274 -0
  296. package/dist/types-DL_05n2M.d.ts +34 -0
  297. package/dist/types-XDoqxYO9.d.cts +34 -0
  298. package/dist/{work-item-runtime-C3M79vE9.d.ts → work-item-runtime-types-BqtWnSCS.d.ts} +3 -93
  299. package/dist/{work-item-runtime-qaVgsL0T.d.cts → work-item-runtime-types-CHO03AKh.d.cts} +3 -93
  300. package/dist/work-queue/index.cjs +957 -953
  301. package/dist/work-queue/index.cjs.map +1 -1
  302. package/dist/work-queue/index.d.cts +9 -357
  303. package/dist/work-queue/index.d.ts +9 -357
  304. package/dist/work-queue/index.js +957 -953
  305. package/dist/work-queue/index.js.map +1 -1
  306. package/package.json +603 -513
  307. package/dist/chunk-3JR3EDB2.js.map +0 -1
  308. package/dist/chunk-4VLAQHZI.js.map +0 -1
  309. package/dist/chunk-6XAIOL3X.js +0 -2407
  310. package/dist/chunk-6XAIOL3X.js.map +0 -1
  311. package/dist/chunk-FBUU43PM.js.map +0 -1
  312. package/dist/chunk-HKK2JD7Z.js.map +0 -1
  313. package/dist/chunk-PC3BTTBE.js +0 -3217
  314. package/dist/chunk-PC3BTTBE.js.map +0 -1
  315. package/dist/chunk-QFY4AFY4.js.map +0 -1
  316. package/dist/chunk-V7CIJE4B.js.map +0 -1
  317. package/dist/chunk-XKXWK2KP.js.map +0 -1
  318. package/dist/chunk-YDSIVHRR.js.map +0 -1
  319. package/dist/chunk-YXMZ2N6J.js.map +0 -1
  320. /package/dist/{chunk-Z2ANQ6JW.js.map → chunk-4Q77MMJY.js.map} +0 -0
  321. /package/dist/{chunk-IXZBUWSP.js.map → chunk-7HZRJMN6.js.map} +0 -0
  322. /package/dist/{chunk-SS2A464I.js.map → chunk-CJIFGJQG.js.map} +0 -0
  323. /package/dist/{chunk-K3FXTC3I.js.map → chunk-HJACH5PU.js.map} +0 -0
  324. /package/dist/{chunk-GTPCOEOZ.js.map → chunk-IDMLXLLG.js.map} +0 -0
  325. /package/dist/{chunk-DKP56CSW.js.map → chunk-JKAYLDQV.js.map} +0 -0
  326. /package/dist/{chunk-VTHLCFN4.js.map → chunk-RAHNUYA5.js.map} +0 -0
  327. /package/dist/{chunk-CZNV3VXM.js.map → chunk-SIDJO2T4.js.map} +0 -0
  328. /package/dist/{chunk-2747WN4Y.js.map → chunk-TPND5MJS.js.map} +0 -0
  329. /package/dist/{chunk-43BKLFZU.js.map → chunk-YDWBXXQZ.js.map} +0 -0
  330. /package/dist/{chunk-6PHB5CJS.js.map → chunk-ZLFRB6FI.js.map} +0 -0
@@ -461,30 +461,6 @@ function drain() {
461
461
  if (escaped !== null) throw escaped.e;
462
462
  }
463
463
 
464
- // src/batch/batch.ts
465
- var active = null;
466
- var boundaryOwner = null;
467
- function currentBatch() {
468
- return active !== null;
469
- }
470
- function currentBoundaryBatchToken() {
471
- return active ?? boundaryOwner ?? void 0;
472
- }
473
- function deferToBatch(target, tier3Wave) {
474
- if (active === null) return false;
475
- if (!active.deferred.has(target)) active.order.push(target);
476
- active.deferred.set(target, tier3Wave);
477
- return true;
478
- }
479
- function deferAfterBatchForTarget(target, fn) {
480
- if (active === null || !active.deferred.has(target)) return false;
481
- const owner = active;
482
- target.__deferBoundary(() => {
483
- if (owner.committed) fn();
484
- }, owner);
485
- return true;
486
- }
487
-
488
464
  // src/dispatcher/index.ts
489
465
  var PoolTable = class {
490
466
  constructor(kind) {
@@ -791,6 +767,586 @@ function makeDepBookkeeping(depCount2) {
791
767
  };
792
768
  }
793
769
 
770
+ // src/node/protocol-guards.ts
771
+ function terminalView(t) {
772
+ return t === void 0 ? false : t;
773
+ }
774
+ function normalizePullDemand(demand) {
775
+ if (typeof demand !== "object" || demand === null || Array.isArray(demand)) {
776
+ throw new Error("ctx.up: PULL requires { pullId, params? } demand payload (D269)");
777
+ }
778
+ const pullId = demand.pullId;
779
+ if (typeof pullId !== "string" && typeof pullId !== "symbol") {
780
+ throw new Error("ctx.up: PULL demand requires a string or symbol pullId (D269)");
781
+ }
782
+ const params = demand.params;
783
+ return params === void 0 ? { pullId } : { pullId, params };
784
+ }
785
+ function validateDownPayloads(msgs) {
786
+ for (const m of msgs) {
787
+ if (m[0] === "DATA" && m[1] === void 0) {
788
+ throw new Error("down: DATA requires a non-SENTINEL payload (R-data-payload)");
789
+ }
790
+ if (m[0] === "ERROR" && isInvalidErrorPayload(m[1])) {
791
+ throw new Error("down: ERROR requires a non-SENTINEL, non-boolean payload (R-data-payload)");
792
+ }
793
+ }
794
+ }
795
+
796
+ // src/node/runtime-accessors.ts
797
+ var constructingCore;
798
+ var constructingEnvironment;
799
+ var ownerTokens = /* @__PURE__ */ new WeakMap();
800
+ var topologyDepsChangedObservers = /* @__PURE__ */ new WeakMap();
801
+ var checkpointReaders = /* @__PURE__ */ new WeakMap();
802
+ var restoreWriters = /* @__PURE__ */ new WeakMap();
803
+ var runtimeReleasers = /* @__PURE__ */ new WeakMap();
804
+ var runtimeQuiescenceReaders = /* @__PURE__ */ new WeakMap();
805
+ var subscriberCountReaders = /* @__PURE__ */ new WeakMap();
806
+ var activationReaders = /* @__PURE__ */ new WeakMap();
807
+ var releasedNodes = /* @__PURE__ */ new WeakSet();
808
+ function withNodeCore(core, create) {
809
+ const prev = constructingCore;
810
+ constructingCore = core;
811
+ try {
812
+ return create();
813
+ } finally {
814
+ constructingCore = prev;
815
+ }
816
+ }
817
+ function takeConstructingNodeCore() {
818
+ const core = constructingCore;
819
+ constructingCore = void 0;
820
+ return core;
821
+ }
822
+ function withEnvironmentDrivers(environment, create) {
823
+ const prev = constructingEnvironment;
824
+ constructingEnvironment = environment;
825
+ try {
826
+ return create();
827
+ } finally {
828
+ constructingEnvironment = prev;
829
+ }
830
+ }
831
+ function takeConstructingEnvironmentDrivers() {
832
+ const environment = constructingEnvironment;
833
+ constructingEnvironment = void 0;
834
+ return environment;
835
+ }
836
+ function getNodeOwner(n) {
837
+ return ownerTokens.get(n);
838
+ }
839
+ function notifyTopologyDepsChanged(node, prevDeps, deps) {
840
+ topologyDepsChangedObservers.get(node)?.(node, prevDeps, deps);
841
+ }
842
+
843
+ // src/node/node-context-runtime.ts
844
+ function nodeBuildCtx(self) {
845
+ const kind = self._slot.handle ? self._slot.dispatcher.poolKind(self._slot.handle.poolId) : "sync";
846
+ if (kind === "sync") {
847
+ if (self._syncCtx === null) self._syncCtx = self._makeCtx();
848
+ self._refreshCtx(self._syncCtx);
849
+ return self._syncCtx;
850
+ }
851
+ return self._makeCtx({
852
+ waveData: self._dep.waveData.map((waves) => waves.map((w) => [...w])),
853
+ terminal: self._dep.terminalInput.map(terminalView),
854
+ latest: [...self._dep.prev]
855
+ });
856
+ }
857
+ function nodeMakeCtx(self, snapshot) {
858
+ const ctx = {
859
+ // Wave-owner boundary (D47): a SYNC fn's emit nests under the public entry that drove
860
+ // it (cheap inc/dec, no early drain); an ASYNC-pool fn re-enters here from its stashed
861
+ // ctx at depth 0, so this is the boundary that drains any rewireNext it issued.
862
+ up: (msgs, towardDep) => {
863
+ if (self._released) return;
864
+ enterWave();
865
+ try {
866
+ self._up(msgs, towardDep);
867
+ } finally {
868
+ exitWave();
869
+ }
870
+ },
871
+ down: (msgs) => {
872
+ if (self._released) return;
873
+ enterWave();
874
+ try {
875
+ self._down(msgs);
876
+ } finally {
877
+ exitWave();
878
+ }
879
+ },
880
+ waveData: snapshot?.waveData ?? self._dep.waveData,
881
+ terminal: snapshot?.terminal ?? self._dep.terminalInput.map(terminalView),
882
+ state: self._makeState(),
883
+ onDeactivation: (fn) => {
884
+ if (self._released) return;
885
+ self._hooks.onDeactivation.push(fn);
886
+ },
887
+ onInvalidate: (fn) => {
888
+ if (self._released) return;
889
+ self._hooks.onInvalidate.push(fn);
890
+ },
891
+ environment: () => self._slot.environment,
892
+ // R-rewire-deferred (D47): defer a self-dep-set mutation to the committed boundary.
893
+ rewireNext: {
894
+ subscribeDep: (dep, fn) => self._requestRewireNext({ kind: "add", dep, fn }),
895
+ unsubscribeDep: (dep, fn) => self._requestRewireNext({ kind: "remove", dep, fn }),
896
+ replaceDeps: (deps, fn) => self._requestRewireNext({ kind: "set", deps, fn })
897
+ },
898
+ // R-up-routing / R-pull (D269): deferred up — route a control/demand wave (e.g. PULL)
899
+ // up the declared cone at the committed boundary. The SELF-demand path: an
900
+ // immediate ctx.up whose delivery loops back re-enters this fn (D37 / R-reentrancy).
901
+ upNext: (msgs, towardDep) => self._requestUpNext(msgs, towardDep),
902
+ ...self._control.activePull === void 0 ? {} : { pull: self._control.activePull },
903
+ [CTX_DEP_CACHE]: { latest: snapshot?.latest ?? self._dep.prev },
904
+ [CTX_NODE_BINDING]: {
905
+ dispatcher: self._slot.dispatcher,
906
+ create: (factory) => withEnvironmentDrivers(self._slot.environment, () => withNodeCore(self._core, factory))
907
+ }
908
+ };
909
+ if (self._slot.dynamic) {
910
+ ctx.track = (i) => ctx[CTX_DEP_CACHE]?.latest[i];
911
+ }
912
+ return ctx;
913
+ }
914
+ function nodeRefreshCtx(self, ctx) {
915
+ ctx.waveData = self._dep.waveData;
916
+ ctx.terminal = self._dep.terminalInput.map(terminalView);
917
+ if (self._control.activePull === void 0) {
918
+ delete ctx.pull;
919
+ } else {
920
+ ctx.pull = self._control.activePull;
921
+ }
922
+ ctx[CTX_DEP_CACHE] = { latest: self._dep.prev };
923
+ }
924
+ function nodeMakeState(self) {
925
+ return {
926
+ get: () => self._privateState.value,
927
+ set: (v) => {
928
+ self._privateState.value = v;
929
+ },
930
+ persist: (on = true) => {
931
+ self._privateState.persist = on;
932
+ }
933
+ };
934
+ }
935
+
936
+ // src/node/node-input-runtime.ts
937
+ function nodeRecordDepProjection(self, idx, delivery) {
938
+ const token = delivery?.wave ?? {};
939
+ if (self._dep.waveTokens[idx] !== token) {
940
+ self._dep.waveData[idx].push([]);
941
+ self._dep.waveTokens[idx] = token;
942
+ }
943
+ return self._dep.waveData[idx][self._dep.waveData[idx].length - 1];
944
+ }
945
+ function nodeDepProjectionHasData(self, idx) {
946
+ const projection = self._dep.waveData[idx][self._dep.waveData[idx].length - 1];
947
+ return projection?.some((v) => v !== SENTINEL) ?? false;
948
+ }
949
+ function nodeReceiveFromDep(self, idx, msg, delivery) {
950
+ if (self._released) return;
951
+ const t = msg[0];
952
+ if (t === "START") return;
953
+ const isLastInDeliveredWave = delivery?.last ?? true;
954
+ if (self._value.terminal !== void 0) {
955
+ if (t === "TEARDOWN") self._down([["TEARDOWN"]]);
956
+ return;
957
+ }
958
+ if (t === "INVALIDATE") {
959
+ const projection = self._recordDepProjection(idx, delivery);
960
+ projection.push(SENTINEL);
961
+ if (projection.some((v) => v !== SENTINEL) && isLastInDeliveredWave) self._maybeRun();
962
+ self._dep.prev[idx] = SENTINEL;
963
+ self._dep.hasData[idx] = false;
964
+ self._dep.batch[idx] = null;
965
+ if (self._dep.dirty[idx]) {
966
+ self._dep.dirty[idx] = false;
967
+ self._wave.pending--;
968
+ }
969
+ if (self._control.pausedDepWaveOccurred && self._dep.batch.every((b) => b === null)) {
970
+ self._control.pausedDepWaveOccurred = false;
971
+ }
972
+ const hadData = self._value.hasData;
973
+ self._invalidate();
974
+ if (self._wave.pending === 0 && self._wave.emittedDirtyThisWave) {
975
+ if (!hadData) self._down([["RESOLVED"]]);
976
+ else self._wave.emittedDirtyThisWave = false;
977
+ }
978
+ self._fireOwedDemandIfReady();
979
+ return;
980
+ }
981
+ if (isTerminal(t)) {
982
+ const isError = t === "ERROR";
983
+ const errPayload = isError ? msg[1] : void 0;
984
+ self._dep.terminal[idx] = isError ? errPayload : true;
985
+ self._dep.terminalInput[idx] = isError ? errPayload : true;
986
+ self._releaseDepDirty(idx);
987
+ const ranValueBeforeTerminal = self._depProjectionHasData(idx) && isLastInDeliveredWave;
988
+ if (ranValueBeforeTerminal) self._maybeRun();
989
+ if (isError && self._slot.errorWhenDepsError) {
990
+ self._down([["ERROR", errPayload]]);
991
+ } else if (self._slot.terminalAsRealInput) {
992
+ if (ranValueBeforeTerminal) {
993
+ self._fireOwedDemandIfReady();
994
+ return;
995
+ }
996
+ self._maybeRun();
997
+ } else if (self._slot.completeWhenDepsComplete && self._allDepsTerminal()) {
998
+ self._down([["COMPLETE"]]);
999
+ } else {
1000
+ self._settleAfterAbsorbedTerminal();
1001
+ }
1002
+ self._fireOwedDemandIfReady();
1003
+ return;
1004
+ }
1005
+ if (t === "TEARDOWN") {
1006
+ self._down([["TEARDOWN"]]);
1007
+ return;
1008
+ }
1009
+ if (t === "DIRTY") {
1010
+ if (!self._dep.dirty[idx]) {
1011
+ self._dep.dirty[idx] = true;
1012
+ self._wave.pending++;
1013
+ self._dep.tier[idx] = 2;
1014
+ self._markDirty();
1015
+ }
1016
+ return;
1017
+ }
1018
+ if (t === "DATA") {
1019
+ const v = msg[1];
1020
+ self._recordDepProjection(idx, delivery).push(v);
1021
+ const b = self._dep.batch[idx];
1022
+ if (b === null) self._dep.batch[idx] = [v];
1023
+ else b.push(v);
1024
+ self._dep.prev[idx] = v;
1025
+ self._dep.hasData[idx] = true;
1026
+ self._dep.tier[idx] = 3;
1027
+ if (self._dep.dirty[idx]) {
1028
+ self._dep.dirty[idx] = false;
1029
+ self._wave.pending--;
1030
+ }
1031
+ if (isLastInDeliveredWave) self._maybeRun();
1032
+ self._fireOwedDemandIfReady();
1033
+ return;
1034
+ }
1035
+ if (t === "RESOLVED") {
1036
+ self._recordDepProjection(idx, delivery);
1037
+ self._dep.tier[idx] = 3;
1038
+ if (self._dep.dirty[idx]) {
1039
+ self._dep.dirty[idx] = false;
1040
+ self._wave.pending--;
1041
+ }
1042
+ if (isLastInDeliveredWave) self._maybeRun();
1043
+ self._fireOwedDemandIfReady();
1044
+ return;
1045
+ }
1046
+ }
1047
+ function nodeReleaseDepDirty(self, idx) {
1048
+ if (self._dep.dirty[idx]) {
1049
+ self._dep.dirty[idx] = false;
1050
+ self._wave.pending--;
1051
+ }
1052
+ }
1053
+ function nodeSettleAfterAbsorbedTerminal(self) {
1054
+ if (self._wave.pending !== 0 || !self._wave.emittedDirtyThisWave) return;
1055
+ const sawData = self._dep.batch.some((b) => b !== null && b.length > 0);
1056
+ if (sawData) self._maybeRun();
1057
+ if (self._wave.emittedDirtyThisWave) self._down([["RESOLVED"]]);
1058
+ }
1059
+ function nodeMarkDirty(self) {
1060
+ self._value.status = "dirty";
1061
+ if (self._isPullQuiet()) return;
1062
+ if (!self._wave.emittedDirtyThisWave) {
1063
+ self._wave.emittedDirtyThisWave = true;
1064
+ self._emitToSubs(["DIRTY"]);
1065
+ }
1066
+ }
1067
+ function nodeMaybeRun(self) {
1068
+ if (self._wave.inDepMutation) {
1069
+ self._wave.rewireRunPending = true;
1070
+ return;
1071
+ }
1072
+ if (self._slot.pausable === true && (self._isPaused() || self._isPullQuiet())) {
1073
+ self._control.pausedDepWaveOccurred = true;
1074
+ return;
1075
+ }
1076
+ self._tryRun();
1077
+ }
1078
+ function nodeSettleRewire(self) {
1079
+ if (self._slot.pausable === true && self._isPaused()) {
1080
+ self._control.pausedDepWaveOccurred = true;
1081
+ return;
1082
+ }
1083
+ if (self._wave.pending > 0) return;
1084
+ if (self._slot.handle === null) {
1085
+ self._passthroughEmit();
1086
+ return;
1087
+ }
1088
+ if (!self._wave.hasCalledFnOnce && !(self._slot.partial || self._allDepsSettled())) return;
1089
+ self._markDirty();
1090
+ self._runWave();
1091
+ }
1092
+ function nodeTryRun(self) {
1093
+ if (self._wave.pending > 0) return;
1094
+ if (self._slot.handle === null) {
1095
+ self._passthroughEmit();
1096
+ return;
1097
+ }
1098
+ if (!self._wave.hasCalledFnOnce) {
1099
+ if (self._slot.partial || self._allDepsSettled()) self._runWave();
1100
+ return;
1101
+ }
1102
+ self._runWave();
1103
+ }
1104
+ function nodeAllDepsSettled(self) {
1105
+ for (let i = 0; i < self._slot.deps.length; i++) {
1106
+ if (self._dep.hasData[i]) continue;
1107
+ if (self._slot.terminalAsRealInput && self._dep.terminal[i] !== void 0) continue;
1108
+ return false;
1109
+ }
1110
+ return true;
1111
+ }
1112
+ function nodePassthroughEmit(self) {
1113
+ const b = self._dep.batch[0];
1114
+ if (b !== null && b.length > 0) {
1115
+ self._down([["DATA", b[b.length - 1]]]);
1116
+ } else if (self._wave.emittedDirtyThisWave) {
1117
+ self._down([["RESOLVED"]]);
1118
+ }
1119
+ self._dep.batch[0] = null;
1120
+ self._wave.emittedDirtyThisWave = false;
1121
+ }
1122
+ function nodeRunWave(self) {
1123
+ if (self._wave.insideRunWave)
1124
+ throw new Error(
1125
+ "synchronous feedback cycle: node fn re-entered its own wave (R-reentrancy / D37)"
1126
+ );
1127
+ self._wave.hasCalledFnOnce = true;
1128
+ self._hooks.onInvalidate = [];
1129
+ self._hooks.onDeactivation = [];
1130
+ const ctx = self._buildCtx();
1131
+ const wasDirty = self._wave.emittedDirtyThisWave;
1132
+ self._wave.emittedSettleThisWave = false;
1133
+ self._wave.insideRunWave = true;
1134
+ try {
1135
+ self._slot.dispatcher.invoke(self._slot.handle, ctx);
1136
+ } finally {
1137
+ self._wave.insideRunWave = false;
1138
+ }
1139
+ if (wasDirty && !self._wave.emittedSettleThisWave && self._value.terminal === void 0 && !self._isAsyncPool()) {
1140
+ self._down([["RESOLVED"]]);
1141
+ }
1142
+ for (let i = 0; i < self._dep.batch.length; i++) {
1143
+ self._dep.batch[i] = null;
1144
+ self._dep.waveData[i] = [];
1145
+ self._dep.waveTokens[i] = void 0;
1146
+ self._dep.terminalInput[i] = void 0;
1147
+ }
1148
+ self._wave.emittedDirtyThisWave = false;
1149
+ }
1150
+
1151
+ // src/node/node-runtime-host.ts
1152
+ function nodeRuntimeHost(node) {
1153
+ return node;
1154
+ }
1155
+
1156
+ // src/node/node-lifecycle-runtime.ts
1157
+ function nodeActivate(self) {
1158
+ self._lifecycle.activated = true;
1159
+ const seedRestoredDeps = self._restoredActivationPending;
1160
+ self._restoredActivationPending = false;
1161
+ self._dep.unsubs = new Array(self._slot.deps.length);
1162
+ self._dep.idxBoxes = new Array(self._slot.deps.length);
1163
+ for (const dep of self._slot.deps) self._subscribeDepAt(dep, { seedRestored: seedRestoredDeps });
1164
+ if (self._slot.deps.length === 0 && self._slot.handle !== null && !self._wave.hasCalledFnOnce) {
1165
+ self._runWave();
1166
+ }
1167
+ }
1168
+ function nodeSubscribeDepAt(self, depNode, opts = {}) {
1169
+ const idx0 = self._slot.deps.indexOf(depNode);
1170
+ const box = { v: idx0 };
1171
+ let ignoreInitialPush = opts.seedRestored === true;
1172
+ if (ignoreInitialPush && idx0 !== -1) {
1173
+ self._seedRestoredDepAt(idx0, depNode);
1174
+ const dep = nodeRuntimeHost(depNode);
1175
+ if (dep._value.terminal !== void 0 && !dep._slot.resubscribable) {
1176
+ self._dep.unsubs[idx0] = () => {
1177
+ };
1178
+ self._dep.idxBoxes[idx0] = box;
1179
+ return;
1180
+ }
1181
+ }
1182
+ const unsub = depNode.subscribe((msg, delivery) => {
1183
+ if (ignoreInitialPush && delivery === void 0) return;
1184
+ if (ignoreInitialPush) ignoreInitialPush = false;
1185
+ if (box.v === -1) return;
1186
+ self._receiveFromDep(box.v, msg, delivery);
1187
+ });
1188
+ if (ignoreInitialPush && idx0 !== -1 && box.v !== -1) self._seedRestoredDepAt(idx0, depNode);
1189
+ ignoreInitialPush = false;
1190
+ if (idx0 !== -1) {
1191
+ self._dep.unsubs[idx0] = unsub;
1192
+ self._dep.idxBoxes[idx0] = box;
1193
+ }
1194
+ }
1195
+ function nodeSeedRestoredDepAt(self, idx, depNode) {
1196
+ const dep = nodeRuntimeHost(depNode);
1197
+ const seedData = dep._value.hasData && !dep._slot.pull;
1198
+ self._dep.batch[idx] = null;
1199
+ self._dep.waveData[idx] = [];
1200
+ self._dep.waveTokens[idx] = void 0;
1201
+ self._dep.prev[idx] = seedData ? dep._value.cache : SENTINEL;
1202
+ self._dep.hasData[idx] = seedData;
1203
+ self._dep.dirty[idx] = false;
1204
+ self._dep.tier[idx] = seedData ? 3 : 0;
1205
+ self._dep.terminal[idx] = dep._value.terminal;
1206
+ self._dep.terminalInput[idx] = void 0;
1207
+ }
1208
+ function nodeDeactivate(self) {
1209
+ self._lifecycle.activated = false;
1210
+ for (const u of self._dep.unsubs) if (u) u();
1211
+ self._dep.unsubs = [];
1212
+ self._dep.idxBoxes = [];
1213
+ for (const fn of self._hooks.onDeactivation) fn();
1214
+ self._hooks.onDeactivation = [];
1215
+ self._hooks.onInvalidate = [];
1216
+ const isCompute = self._slot.handle !== null || self._slot.deps.length > 0;
1217
+ if (isCompute) {
1218
+ self._value.cache = SENTINEL;
1219
+ self._value.hasData = false;
1220
+ self._value.status = "sentinel";
1221
+ }
1222
+ self._resetDepState();
1223
+ self._wave.hasCalledFnOnce = false;
1224
+ self._control.pauseLockset.clear();
1225
+ self._control.pauseBuffer = [];
1226
+ self._control.pausedDepWaveOccurred = false;
1227
+ self._control.demandOwed = void 0;
1228
+ self._control.activePull = void 0;
1229
+ self._control.pullDirtyOwed = false;
1230
+ self._value.replayRing = [];
1231
+ if (!self._privateState.persist) self._privateState.value = SENTINEL;
1232
+ }
1233
+ function nodeSubscriberCount(self) {
1234
+ return self._lifecycle.subscribers.size;
1235
+ }
1236
+ function nodeIsRuntimeQuiescentForRelease(self) {
1237
+ 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;
1238
+ }
1239
+ function nodeReleaseRuntime(self) {
1240
+ if (self._released) return;
1241
+ self._released = true;
1242
+ const node = self;
1243
+ releasedNodes.add(node);
1244
+ let releaseError;
1245
+ const recordReleaseError = (error) => {
1246
+ if (releaseError === void 0) releaseError = error;
1247
+ };
1248
+ self._lifecycle.activated = false;
1249
+ for (const u of self._dep.unsubs) {
1250
+ try {
1251
+ u();
1252
+ } catch (error) {
1253
+ recordReleaseError(error);
1254
+ }
1255
+ }
1256
+ for (const fn of self._hooks.onDeactivation) {
1257
+ try {
1258
+ fn();
1259
+ } catch (error) {
1260
+ recordReleaseError(error);
1261
+ }
1262
+ }
1263
+ self._dep.unsubs = [];
1264
+ self._dep.idxBoxes = [];
1265
+ self._lifecycle.subscribers.clear();
1266
+ if (self._slot.handle !== null) {
1267
+ self._slot.dispatcher.unregister(self._slot.handle);
1268
+ self._slot.handle = null;
1269
+ }
1270
+ self._slot.deps = [];
1271
+ self._dep.batch = [];
1272
+ self._dep.waveData = [];
1273
+ self._dep.waveTokens = [];
1274
+ self._dep.prev = [];
1275
+ self._dep.hasData = [];
1276
+ self._dep.dirty = [];
1277
+ self._dep.tier = [];
1278
+ self._dep.terminal = [];
1279
+ self._dep.terminalInput = [];
1280
+ self._value.cache = SENTINEL;
1281
+ self._value.hasData = false;
1282
+ self._value.status = "sentinel";
1283
+ self._value.terminal = void 0;
1284
+ self._value.replayRing = [];
1285
+ self._privateState.value = SENTINEL;
1286
+ self._privateState.persist = false;
1287
+ self._syncCtx = null;
1288
+ self._resetDepState();
1289
+ self._hooks.onDeactivation = [];
1290
+ self._hooks.onInvalidate = [];
1291
+ self._control.pauseLockset.clear();
1292
+ self._control.pauseBuffer = [];
1293
+ self._control.pausedDepWaveOccurred = false;
1294
+ self._control.demandOwed = void 0;
1295
+ self._control.activePull = void 0;
1296
+ self._control.pullDirtyOwed = false;
1297
+ self._restoredActivationPending = false;
1298
+ checkpointReaders.delete(node);
1299
+ restoreWriters.delete(node);
1300
+ runtimeReleasers.delete(node);
1301
+ runtimeQuiescenceReaders.delete(node);
1302
+ subscriberCountReaders.delete(node);
1303
+ activationReaders.delete(node);
1304
+ ownerTokens.delete(node);
1305
+ topologyDepsChangedObservers.delete(node);
1306
+ self._core.releaseSlot(self._id);
1307
+ if (releaseError !== void 0) throw releaseError;
1308
+ }
1309
+ function nodeResetDepState(self) {
1310
+ const n = self._slot.deps.length;
1311
+ for (let i = 0; i < n; i++) {
1312
+ self._dep.batch[i] = null;
1313
+ self._dep.waveData[i] = [];
1314
+ self._dep.waveTokens[i] = void 0;
1315
+ self._dep.prev[i] = SENTINEL;
1316
+ self._dep.hasData[i] = false;
1317
+ self._dep.dirty[i] = false;
1318
+ self._dep.tier[i] = 0;
1319
+ self._dep.terminal[i] = void 0;
1320
+ self._dep.terminalInput[i] = void 0;
1321
+ }
1322
+ self._wave.pending = 0;
1323
+ self._wave.emittedDirtyThisWave = false;
1324
+ }
1325
+
1326
+ // src/batch/batch.ts
1327
+ var active = null;
1328
+ var boundaryOwner = null;
1329
+ function currentBatch() {
1330
+ return active !== null;
1331
+ }
1332
+ function currentBoundaryBatchToken() {
1333
+ return active ?? boundaryOwner ?? void 0;
1334
+ }
1335
+ function deferToBatch(target, tier3Wave) {
1336
+ if (active === null) return false;
1337
+ if (!active.deferred.has(target)) active.order.push(target);
1338
+ active.deferred.set(target, tier3Wave);
1339
+ return true;
1340
+ }
1341
+ function deferAfterBatchForTarget(target, fn) {
1342
+ if (active === null || !active.deferred.has(target)) return false;
1343
+ const owner = active;
1344
+ target.__deferBoundary(() => {
1345
+ if (owner.committed) fn();
1346
+ }, owner);
1347
+ return true;
1348
+ }
1349
+
794
1350
  // src/json/codec.ts
795
1351
  var JS_MIN_NORMAL_NUMBER = 2 ** -1022;
796
1352
  function assertStableJsonNumber(value, path) {
@@ -835,9 +1391,16 @@ function sortedJsonValue(value, seen = /* @__PURE__ */ new Set(), path = "$", st
835
1391
  }
836
1392
  for (const key of Object.getOwnPropertyNames(value)) {
837
1393
  const isIndex = /^(0|[1-9]\d*)$/.test(key) && Number.isSafeInteger(Number(key)) && Number(key) < value.length;
1394
+ const descriptor = Object.getOwnPropertyDescriptor(value, key);
1395
+ if (descriptor !== void 0 && ("get" in descriptor || "set" in descriptor)) {
1396
+ throw new TypeError(`stableJsonString: accessor property at ${path}.${key}`);
1397
+ }
838
1398
  if (key !== "length" && !isIndex) {
839
1399
  throw new TypeError(`stableJsonString: non-index array property at ${path}.${key}`);
840
1400
  }
1401
+ if (key !== "length" && descriptor !== void 0 && !descriptor.enumerable) {
1402
+ throw new TypeError(`stableJsonString: non-enumerable array property at ${path}.${key}`);
1403
+ }
841
1404
  }
842
1405
  const out2 = [];
843
1406
  for (let i = 0; i < value.length; i += 1) {
@@ -851,6 +1414,15 @@ function sortedJsonValue(value, seen = /* @__PURE__ */ new Set(), path = "$", st
851
1414
  if (Object.getOwnPropertySymbols(value).length > 0) {
852
1415
  throw new TypeError(`stableJsonString: symbol-keyed properties at ${path}`);
853
1416
  }
1417
+ for (const key of Object.getOwnPropertyNames(value)) {
1418
+ const descriptor = Object.getOwnPropertyDescriptor(value, key);
1419
+ if (descriptor !== void 0 && ("get" in descriptor || "set" in descriptor)) {
1420
+ throw new TypeError(`stableJsonString: accessor property at ${path}.${key}`);
1421
+ }
1422
+ if (descriptor !== void 0 && !descriptor.enumerable) {
1423
+ throw new TypeError(`stableJsonString: non-enumerable property at ${path}.${key}`);
1424
+ }
1425
+ }
854
1426
  const out = /* @__PURE__ */ Object.create(null);
855
1427
  for (const key of Object.keys(value).sort()) {
856
1428
  out[key] = sortedJsonValue(
@@ -1173,67 +1745,532 @@ function restoredV1Cid(policy, hasData, cache) {
1173
1745
  return computeV1Cid(policy, hasData ? cache : ABSENT_V1_SEED);
1174
1746
  }
1175
1747
 
1176
- // src/node/node.ts
1177
- var constructingCore;
1178
- var constructingEnvironment;
1179
- var ownerTokens = /* @__PURE__ */ new WeakMap();
1180
- var topologyDepsChangedObservers = /* @__PURE__ */ new WeakMap();
1181
- var checkpointReaders = /* @__PURE__ */ new WeakMap();
1182
- var restoreWriters = /* @__PURE__ */ new WeakMap();
1183
- var runtimeReleasers = /* @__PURE__ */ new WeakMap();
1184
- var runtimeQuiescenceReaders = /* @__PURE__ */ new WeakMap();
1185
- var subscriberCountReaders = /* @__PURE__ */ new WeakMap();
1186
- var activationReaders = /* @__PURE__ */ new WeakMap();
1187
- var releasedNodes = /* @__PURE__ */ new WeakSet();
1188
- function withNodeCore(core, create) {
1189
- const prev = constructingCore;
1190
- constructingCore = core;
1191
- try {
1192
- return create();
1193
- } finally {
1194
- constructingCore = prev;
1748
+ // src/node/node-output-runtime.ts
1749
+ function nodeDown(self, msgs) {
1750
+ if (self._released) return;
1751
+ validateDownPayloads(msgs);
1752
+ const deliveryWave = {};
1753
+ const assertVersionDataCompatible = (wave) => {
1754
+ for (const m of wave) {
1755
+ if (m[0] === "DATA") assertNodeVersionDataCompatible(self._version.policy, m[1]);
1756
+ }
1757
+ };
1758
+ const snapshotVersionData = (wave) => wave.map(
1759
+ (m) => m[0] === "DATA" ? ["DATA", snapshotNodeVersionData(self._version.policy, m[1])] : m
1760
+ );
1761
+ assertVersionDataCompatible(msgs);
1762
+ if (self._value.terminal !== void 0) {
1763
+ if (!msgs.some((m) => m[0] === "TEARDOWN")) return;
1764
+ self._value.hasTorndown = true;
1765
+ if (self._slot.resetOnTeardown) {
1766
+ self._value.cache = SENTINEL;
1767
+ self._value.hasData = false;
1768
+ }
1769
+ self._emitToSubs(["TEARDOWN"], { wave: deliveryWave, last: true });
1770
+ return;
1195
1771
  }
1196
- }
1197
- function withEnvironmentDrivers(environment, create) {
1198
- const prev = constructingEnvironment;
1199
- constructingEnvironment = environment;
1200
- try {
1201
- return create();
1202
- } finally {
1203
- constructingEnvironment = prev;
1772
+ let sorted = [...msgs].sort((a, b) => messageTier(a[0]) - messageTier(b[0]));
1773
+ const firstInvalidate = sorted.findIndex((m) => m[0] === "INVALIDATE");
1774
+ if (firstInvalidate !== -1) {
1775
+ sorted = sorted.filter((m, i) => m[0] !== "INVALIDATE" || i === firstInvalidate);
1776
+ }
1777
+ const hasTeardown = sorted.some((m) => m[0] === "TEARDOWN");
1778
+ const hasTerminal = sorted.some((m) => m[0] === "COMPLETE" || m[0] === "ERROR");
1779
+ if (hasTeardown && !hasTerminal && self._value.terminal === void 0 && !self._value.hasTorndown) {
1780
+ sorted = [["COMPLETE"], ...sorted];
1781
+ }
1782
+ if (!self._wave.insideRunWave && currentBatch()) {
1783
+ const deferred = snapshotVersionData(sorted.filter((m) => isDeferredTier(m[0])));
1784
+ if (deferred.length > 0) {
1785
+ if (!self._wave.emittedDirtyThisWave) {
1786
+ self._wave.emittedDirtyThisWave = true;
1787
+ self._value.status = "dirty";
1788
+ self._emitToSubs(["DIRTY"], { wave: deliveryWave, last: false });
1789
+ }
1790
+ self._wave.batchDirtyOwed = true;
1791
+ deferToBatch(self, deferred);
1792
+ return;
1793
+ }
1204
1794
  }
1205
- }
1206
- function getNodeOwner(n) {
1207
- return ownerTokens.get(n);
1208
- }
1209
- function notifyTopologyDepsChanged(node, prevDeps, deps) {
1210
- topologyDepsChangedObservers.get(node)?.(node, prevDeps, deps);
1211
- }
1212
- function terminalView(t) {
1213
- return t === void 0 ? false : t;
1214
- }
1215
- function normalizePullDemand(demand) {
1216
- if (typeof demand !== "object" || demand === null || Array.isArray(demand)) {
1217
- throw new Error("ctx.up: PULL requires { pullId, params? } demand payload (D269)");
1795
+ if (self._shouldBufferOnPause()) {
1796
+ const buffered = snapshotVersionData(sorted.filter((m) => isPauseBufferedTier(m[0])));
1797
+ if (buffered.length > 0) {
1798
+ self._wave.emittedSettleThisWave = true;
1799
+ self._control.pauseBuffer.push(buffered);
1800
+ }
1801
+ sorted = sorted.filter((m) => !isPauseBufferedTier(m[0]));
1802
+ if (sorted.length === 0) return;
1218
1803
  }
1219
- const pullId = demand.pullId;
1220
- if (typeof pullId !== "string" && typeof pullId !== "symbol") {
1221
- throw new Error("ctx.up: PULL demand requires a string or symbol pullId (D269)");
1804
+ let dataCount = 0;
1805
+ let hasTier3 = false;
1806
+ let hasResolved = false;
1807
+ for (const m of sorted) {
1808
+ if (m[0] === "DATA") dataCount++;
1809
+ if (m[0] === "RESOLVED") hasResolved = true;
1810
+ if (isValueTier(m[0])) hasTier3 = true;
1222
1811
  }
1223
- const params = demand.params;
1224
- return params === void 0 ? { pullId } : { pullId, params };
1812
+ if (dataCount >= 1 && hasResolved) {
1813
+ throw new Error(
1814
+ "down: a wave cannot mix DATA and RESOLVED (tier-3 exclusivity, R-resolved-undirty)"
1815
+ );
1816
+ }
1817
+ const plannedVersions = new Array(sorted.length);
1818
+ if (dataCount > 0) {
1819
+ let plannedVersion = self._version.value;
1820
+ for (let i = 0; i < sorted.length; i++) {
1821
+ const m = sorted[i];
1822
+ if (m[0] !== "DATA") continue;
1823
+ plannedVersion = advanceNodeVersion(plannedVersion, self._version.policy, m[1]);
1824
+ plannedVersions[i] = plannedVersion;
1825
+ }
1826
+ }
1827
+ if (hasTier3 && (!self._wave.insideRunWave || self._control.pullDirtyOwed) && !self._wave.emittedDirtyThisWave) {
1828
+ self._wave.emittedDirtyThisWave = true;
1829
+ self._value.status = "dirty";
1830
+ self._emitToSubs(["DIRTY"], { wave: deliveryWave, last: false });
1831
+ }
1832
+ for (let i = 0; i < sorted.length; i++) {
1833
+ const m = sorted[i];
1834
+ const delivery = { wave: deliveryWave, last: i === sorted.length - 1 };
1835
+ if (isDeferredTier(m[0])) self._wave.emittedSettleThisWave = true;
1836
+ if (m[0] === "DIRTY") {
1837
+ if (!self._wave.emittedDirtyThisWave) {
1838
+ self._wave.emittedDirtyThisWave = true;
1839
+ self._value.status = "dirty";
1840
+ self._emitToSubs(["DIRTY"], delivery);
1841
+ }
1842
+ continue;
1843
+ }
1844
+ if (m[0] === "DATA") {
1845
+ const v = m[1];
1846
+ self._value.cache = v;
1847
+ self._value.hasData = true;
1848
+ self._value.status = "settled";
1849
+ self._version.value = plannedVersions[i];
1850
+ if (self._slot.replayN > 0) {
1851
+ self._value.replayRing.push(v);
1852
+ if (self._value.replayRing.length > self._slot.replayN) self._value.replayRing.shift();
1853
+ }
1854
+ self._emitToSubs(["DATA", v], delivery);
1855
+ continue;
1856
+ }
1857
+ if (m[0] === "RESOLVED") {
1858
+ self._value.status = self._value.hasData ? "resolved" : "sentinel";
1859
+ self._emitToSubs(["RESOLVED"], delivery);
1860
+ continue;
1861
+ }
1862
+ if (m[0] === "INVALIDATE") {
1863
+ self._invalidate(delivery);
1864
+ continue;
1865
+ }
1866
+ if (m[0] === "COMPLETE") {
1867
+ if (self._value.terminal !== void 0) continue;
1868
+ self._value.terminal = true;
1869
+ self._control.pauseBuffer = [];
1870
+ self._value.status = "completed";
1871
+ self._emitToSubs(["COMPLETE"], delivery);
1872
+ continue;
1873
+ }
1874
+ if (m[0] === "ERROR") {
1875
+ if (self._value.terminal !== void 0) continue;
1876
+ self._value.terminal = m[1];
1877
+ self._control.pauseBuffer = [];
1878
+ self._value.status = "errored";
1879
+ self._emitToSubs(["ERROR", m[1]], delivery);
1880
+ continue;
1881
+ }
1882
+ if (m[0] === "TEARDOWN") {
1883
+ self._value.hasTorndown = true;
1884
+ if (self._slot.resetOnTeardown) {
1885
+ self._value.cache = SENTINEL;
1886
+ self._value.hasData = false;
1887
+ }
1888
+ self._emitToSubs(["TEARDOWN"], delivery);
1889
+ }
1890
+ }
1891
+ if (!self._wave.insideRunWave) self._wave.emittedDirtyThisWave = false;
1225
1892
  }
1226
- function validateDownPayloads(msgs) {
1893
+ function nodeUp(self, msgs, towardDep, route) {
1894
+ if (self._released) return;
1895
+ const routeState = route ?? { demandFired: /* @__PURE__ */ new Map() };
1227
1896
  for (const m of msgs) {
1228
- if (m[0] === "DATA" && m[1] === void 0) {
1229
- throw new Error("down: DATA requires a non-SENTINEL payload (R-data-payload)");
1897
+ if (!isUpAllowed(m[0])) {
1898
+ throw new Error(
1899
+ `ctx.up: ${m[0]} is down-only (tier ${messageTier(m[0])}); up carries control tiers only (R-ctx-up)`
1900
+ );
1230
1901
  }
1231
- if (m[0] === "ERROR" && isInvalidErrorPayload(m[1])) {
1232
- throw new Error("down: ERROR requires a non-SENTINEL, non-boolean payload (R-data-payload)");
1902
+ }
1903
+ for (const m of msgs) {
1904
+ if (m[0] === "PAUSE") {
1905
+ self._pauseAcquire(m[1]);
1906
+ } else if (m[0] === "RESUME") {
1907
+ if (self._control.pauseLockset.has(m[1])) {
1908
+ self._pauseRelease(m[1]);
1909
+ } else {
1910
+ self._forwardUp(m, towardDep, routeState);
1911
+ }
1912
+ } else if (m[0] === "PULL") {
1913
+ const demand = normalizePullDemand(m[1]);
1914
+ if (self._slot.pull && demand.pullId === self._slot.pullLock) {
1915
+ if (!self._markDemandRouted(demand.pullId, routeState)) self._onDemand(demand);
1916
+ } else {
1917
+ self._forwardUp(["PULL", demand], towardDep, routeState);
1918
+ }
1919
+ } else if (self._slot.deps.length === 0) {
1920
+ if (m[0] === "INVALIDATE") self._down([["INVALIDATE"]]);
1921
+ } else {
1922
+ self._forwardUp(m, towardDep, routeState);
1233
1923
  }
1234
1924
  }
1235
1925
  }
1236
- var Node = class {
1926
+ function nodeMarkDemandRouted(self, lockId, route) {
1927
+ let holders = route.demandFired.get(lockId);
1928
+ if (holders === void 0) {
1929
+ holders = /* @__PURE__ */ new Set();
1930
+ route.demandFired.set(lockId, holders);
1931
+ }
1932
+ const node = self;
1933
+ if (holders.has(node)) return true;
1934
+ holders.add(node);
1935
+ return false;
1936
+ }
1937
+ function nodeForwardUp(self, m, towardDep, route) {
1938
+ if (self._slot.deps.length === 0) return;
1939
+ if (towardDep !== void 0) {
1940
+ const d = self._slot.deps[towardDep];
1941
+ if (d !== void 0) nodeRuntimeHost(d)._up([m], void 0, route);
1942
+ } else {
1943
+ for (const dep of self._slot.deps) nodeRuntimeHost(dep)._up([m], void 0, route);
1944
+ }
1945
+ }
1946
+ function nodeIsPaused(self) {
1947
+ return self._control.pauseLockset.size > 0;
1948
+ }
1949
+ function nodeHasBoundaryPauseLock(self) {
1950
+ if (self._slot.pausable === false) return false;
1951
+ return self._control.pauseLockset.size > 0;
1952
+ }
1953
+ function nodeIsAsyncPool(self) {
1954
+ return self._slot.handle !== null && self._slot.dispatcher.poolKind(self._slot.handle.poolId) === "async";
1955
+ }
1956
+ function nodePauseAcquire(self, lockId) {
1957
+ self._control.pauseLockset.add(lockId);
1958
+ }
1959
+ function nodePauseRelease(self, lockId) {
1960
+ if (!self._control.pauseLockset.has(lockId)) return;
1961
+ self._control.pauseLockset.delete(lockId);
1962
+ if (self._slot.pull && self._control.demandOwed !== void 0) self._fireOwedDemandIfReady();
1963
+ if (self._hasBoundaryPauseLock()) return;
1964
+ scheduleBoundaryDrain(self._core);
1965
+ if (self._slot.pull) return;
1966
+ self._onResume();
1967
+ }
1968
+ function nodeOnResume(self) {
1969
+ if (self._value.terminal !== void 0) {
1970
+ self._control.pauseBuffer = [];
1971
+ self._control.pausedDepWaveOccurred = false;
1972
+ self._control.demandOwed = void 0;
1973
+ self._control.activePull = void 0;
1974
+ self._control.pullDirtyOwed = false;
1975
+ return;
1976
+ }
1977
+ if (self._control.pauseBuffer.length > 0) {
1978
+ const buf = self._control.pauseBuffer;
1979
+ self._control.pauseBuffer = [];
1980
+ for (const wave of buf) self._down(wave);
1981
+ }
1982
+ if (self._control.pausedDepWaveOccurred) {
1983
+ self._control.pausedDepWaveOccurred = false;
1984
+ self._tryRun();
1985
+ }
1986
+ }
1987
+ function nodeCanFireDemand(self) {
1988
+ if (self._value.terminal !== void 0 || self._wave.pending > 0) return false;
1989
+ return self._control.pauseLockset.size === 0;
1990
+ }
1991
+ function nodeDeliverPullDemand(self, demand) {
1992
+ self._control.demandOwed = void 0;
1993
+ self._control.activePull = demand;
1994
+ self._control.inDeliverDemand = true;
1995
+ try {
1996
+ self._firePullDemand();
1997
+ } finally {
1998
+ self._control.activePull = void 0;
1999
+ self._control.inDeliverDemand = false;
2000
+ }
2001
+ }
2002
+ function nodeOnDemand(self, demand) {
2003
+ if (self._control.inDeliverDemand) return;
2004
+ if (self._canFireDemand()) self._deliverPullDemand(demand);
2005
+ else self._control.demandOwed = demand;
2006
+ }
2007
+ function nodeFirePullDemand(self) {
2008
+ let drainedBuffer = false;
2009
+ if (self._control.pauseBuffer.length > 0) {
2010
+ const buf = self._control.pauseBuffer;
2011
+ self._control.pauseBuffer = [];
2012
+ for (const wave of buf) self._down(wave);
2013
+ drainedBuffer = true;
2014
+ }
2015
+ if (drainedBuffer) return;
2016
+ if (self._control.pausedDepWaveOccurred) {
2017
+ const gated = self._slot.handle !== null && !self._wave.hasCalledFnOnce && !(self._slot.partial || self._allDepsSettled());
2018
+ if (self._wave.pending > 0 || gated) return;
2019
+ self._control.pausedDepWaveOccurred = false;
2020
+ self._wave.emittedDirtyThisWave = false;
2021
+ self._control.pullDirtyOwed = true;
2022
+ try {
2023
+ self._tryRun();
2024
+ } finally {
2025
+ self._control.pullDirtyOwed = false;
2026
+ }
2027
+ return;
2028
+ }
2029
+ if (self._slot.handle !== null) {
2030
+ if (!self._wave.hasCalledFnOnce && !(self._slot.partial || self._allDepsSettled())) return;
2031
+ self._wave.emittedDirtyThisWave = false;
2032
+ self._control.pullDirtyOwed = true;
2033
+ try {
2034
+ self._runWave();
2035
+ } finally {
2036
+ self._control.pullDirtyOwed = false;
2037
+ }
2038
+ }
2039
+ }
2040
+ function nodeFireOwedDemandIfReady(self) {
2041
+ if (self._control.inDeliverDemand) return;
2042
+ if (self._slot.pull && self._control.demandOwed !== void 0 && self._canFireDemand()) {
2043
+ self._deliverPullDemand(self._control.demandOwed);
2044
+ }
2045
+ }
2046
+ function nodeShouldBufferOnPause(self) {
2047
+ if (self._slot.pausable === false) return false;
2048
+ if (!self._isPaused() && !self._isPullQuiet()) return false;
2049
+ if (self._slot.pausable === "resumeAll") return true;
2050
+ if (!self._wave.insideRunWave && self._isAsyncPool() && self._slot.deps.length > 0) return true;
2051
+ return false;
2052
+ }
2053
+ function nodeInvalidate(self, delivery) {
2054
+ if (!self._value.hasData) return;
2055
+ self._value.cache = SENTINEL;
2056
+ self._value.hasData = false;
2057
+ self._value.status = "sentinel";
2058
+ self._value.replayRing = [];
2059
+ for (const fn of self._hooks.onInvalidate) fn();
2060
+ self._emitToSubs(["INVALIDATE"], delivery);
2061
+ }
2062
+ function nodeAllDepsTerminal(self) {
2063
+ if (self._slot.deps.length === 0) return false;
2064
+ for (const tm of self._dep.terminal) if (tm === void 0) return false;
2065
+ return true;
2066
+ }
2067
+ function nodeResetLifecycle(self) {
2068
+ for (const u of self._dep.unsubs) if (u) u();
2069
+ self._dep.unsubs = [];
2070
+ self._dep.idxBoxes = [];
2071
+ self._lifecycle.subscribers.clear();
2072
+ self._lifecycle.activated = false;
2073
+ self._value.terminal = void 0;
2074
+ self._value.hasTorndown = false;
2075
+ self._wave.hasCalledFnOnce = false;
2076
+ self._resetDepState();
2077
+ self._control.pauseLockset.clear();
2078
+ self._control.pauseBuffer = [];
2079
+ self._control.pausedDepWaveOccurred = false;
2080
+ self._control.demandOwed = void 0;
2081
+ self._control.activePull = void 0;
2082
+ self._control.pullDirtyOwed = false;
2083
+ self._value.replayRing = [];
2084
+ const isCompute = self._slot.handle !== null || self._slot.deps.length > 0;
2085
+ if (isCompute) {
2086
+ self._value.cache = SENTINEL;
2087
+ self._value.hasData = false;
2088
+ self._value.status = "sentinel";
2089
+ } else {
2090
+ self._value.status = self._value.hasData ? "settled" : "sentinel";
2091
+ }
2092
+ if (!self._privateState.persist) self._privateState.value = SENTINEL;
2093
+ }
2094
+ function nodeEmitToSubs(self, msg, delivery) {
2095
+ if (self._released) return;
2096
+ const subs = [...self._lifecycle.subscribers];
2097
+ for (const sink of subs) sink(msg, delivery);
2098
+ }
2099
+ function nodeCommitBatchedWave(self, wave) {
2100
+ self._wave.batchDirtyOwed = false;
2101
+ self._down(wave);
2102
+ }
2103
+ function nodeRollbackBatched(self) {
2104
+ if (self._wave.batchDirtyOwed) {
2105
+ self._wave.batchDirtyOwed = false;
2106
+ self._wave.emittedDirtyThisWave = false;
2107
+ self._value.status = self._value.hasData ? "settled" : "sentinel";
2108
+ self._emitToSubs(["RESOLVED"]);
2109
+ }
2110
+ }
2111
+ function nodeDeferBoundary(self, fn, batchToken) {
2112
+ deferRewire(self._core, fn, {
2113
+ batchToken,
2114
+ isReady: () => !self._hasBoundaryPauseLock()
2115
+ });
2116
+ }
2117
+
2118
+ // src/node/node-rewire-runtime.ts
2119
+ function nodeRequestRewireNext(self, op) {
2120
+ deferRewire(self._core, () => self._applyRewireNext(op), {
2121
+ batchToken: currentBoundaryBatchToken(),
2122
+ isReady: () => !self._hasBoundaryPauseLock()
2123
+ });
2124
+ }
2125
+ function nodeRequestUpNext(self, msgs, towardDep) {
2126
+ deferRewire(
2127
+ self._core,
2128
+ () => {
2129
+ if (!self._released) self._up(msgs, towardDep);
2130
+ },
2131
+ {
2132
+ batchToken: currentBoundaryBatchToken(),
2133
+ isReady: () => !self._hasBoundaryPauseLock()
2134
+ }
2135
+ );
2136
+ }
2137
+ function nodeApplyRewireNext(self, op) {
2138
+ if (self._released) return;
2139
+ try {
2140
+ if (op.kind === "add") {
2141
+ const next = self._slot.deps.includes(op.dep) ? [...self._slot.deps] : [...self._slot.deps, op.dep];
2142
+ self._rewire(next, op.fn, { allowTerminalOwner: true });
2143
+ } else if (op.kind === "remove") {
2144
+ self._rewire(
2145
+ self._slot.deps.filter((d) => d !== op.dep),
2146
+ op.fn,
2147
+ { allowTerminalOwner: true }
2148
+ );
2149
+ } else {
2150
+ self._rewire(self._dedupDeps(op.deps), op.fn, { allowTerminalOwner: true });
2151
+ }
2152
+ } catch (e) {
2153
+ self._down([["ERROR", errorPayload(e, "rewireNext op failed")]]);
2154
+ }
2155
+ }
2156
+ function nodeRewire(self, newDeps, fn, opts = {}) {
2157
+ const node = self;
2158
+ if (self._value.terminal !== void 0 && !opts.allowTerminalOwner)
2159
+ throw new Error(
2160
+ "rewire: node is terminal (completed/errored) \u2014 cannot rewire (R-rewire / D42)"
2161
+ );
2162
+ if (self._wave.insideRunWave)
2163
+ throw new Error(
2164
+ "rewire: mid-fn topology mutation \u2014 a fn mutating its own deps mid-wave is the feedback cycle (R-rewire / D37)"
2165
+ );
2166
+ if (self._wave.inDepMutation)
2167
+ throw new Error(
2168
+ "rewire: reentrant dep mutation \u2014 another replaceDeps/subscribeDep/unsubscribeDep is in flight (R-rewire)"
2169
+ );
2170
+ if (newDeps.includes(node)) throw new Error("rewire: self-dependency rejected (R-rewire / D42)");
2171
+ const oldDeps = self._slot.deps;
2172
+ const added = newDeps.filter((d) => !oldDeps.includes(d));
2173
+ for (const d of added) {
2174
+ if (self._reachableUpstream(d, node))
2175
+ throw new Error(
2176
+ "rewire: would create a cycle \u2014 dep already transitively depends on this node (R-rewire / D42)"
2177
+ );
2178
+ const dep = nodeRuntimeHost(d);
2179
+ if (dep._value.terminal !== void 0 && !dep._slot.resubscribable)
2180
+ throw new Error(
2181
+ "rewire: cannot add a non-resubscribable terminal dep \u2014 would wedge (R-rewire / D42)"
2182
+ );
2183
+ self._assertRewireDepOwner(d);
2184
+ }
2185
+ if (deferAfterBatchForTarget(node, () => {
2186
+ self._rewire(newDeps, fn, { ...opts, allowTerminalOwner: true });
2187
+ })) {
2188
+ return true;
2189
+ }
2190
+ if (!self._lifecycle.activated) self._restoredActivationPending = false;
2191
+ self._wave.inDepMutation = true;
2192
+ self._wave.rewireRunPending = false;
2193
+ let zeroDepUnDirty = false;
2194
+ try {
2195
+ const oldHandle = self._slot.handle;
2196
+ self._slot.handle = self._slot.dispatcher.register(fn, self._slot.pool);
2197
+ if (oldHandle !== null) self._slot.dispatcher.unregister(oldHandle);
2198
+ const removed = oldDeps.filter((d) => !newDeps.includes(d));
2199
+ let removedDirtyContributor = false;
2200
+ for (const d of removed) {
2201
+ const oldIdx = oldDeps.indexOf(d);
2202
+ if (self._dep.dirty[oldIdx]) {
2203
+ removedDirtyContributor = true;
2204
+ self._wave.pending--;
2205
+ }
2206
+ if (self._lifecycle.activated) {
2207
+ const box = self._dep.idxBoxes[oldIdx];
2208
+ if (box) box.v = -1;
2209
+ const unsub = self._dep.unsubs[oldIdx];
2210
+ if (unsub) unsub();
2211
+ }
2212
+ }
2213
+ const n = newDeps.length;
2214
+ const newBatch = new Array(n).fill(null);
2215
+ const newPrev = new Array(n).fill(SENTINEL);
2216
+ const newHasData = new Array(n).fill(false);
2217
+ const newDirty = new Array(n).fill(false);
2218
+ const newTier = new Array(n).fill(0);
2219
+ const newTerminal = new Array(n).fill(void 0);
2220
+ const newTerminalInput = new Array(n).fill(void 0);
2221
+ const newUnsubs = new Array(n);
2222
+ const newBoxes = new Array(n);
2223
+ for (let j = 0; j < n; j++) {
2224
+ const oldIdx = oldDeps.indexOf(newDeps[j]);
2225
+ if (oldIdx !== -1) {
2226
+ newBatch[j] = self._dep.batch[oldIdx];
2227
+ newPrev[j] = self._dep.prev[oldIdx];
2228
+ newHasData[j] = self._dep.hasData[oldIdx];
2229
+ newDirty[j] = self._dep.dirty[oldIdx];
2230
+ newTier[j] = self._dep.tier[oldIdx];
2231
+ newTerminal[j] = self._dep.terminal[oldIdx];
2232
+ newUnsubs[j] = self._dep.unsubs[oldIdx];
2233
+ const box = self._dep.idxBoxes[oldIdx];
2234
+ if (box) box.v = j;
2235
+ newBoxes[j] = box;
2236
+ }
2237
+ }
2238
+ self._slot.deps = newDeps;
2239
+ self._dep.batch = newBatch;
2240
+ self._dep.prev = newPrev;
2241
+ self._dep.hasData = newHasData;
2242
+ self._dep.dirty = newDirty;
2243
+ self._dep.tier = newTier;
2244
+ self._dep.terminal = newTerminal;
2245
+ self._dep.terminalInput = newTerminalInput;
2246
+ self._dep.unsubs = newUnsubs;
2247
+ self._dep.idxBoxes = newBoxes;
2248
+ self._dep.waveData = newDeps.map(() => []);
2249
+ self._dep.waveTokens = new Array(newDeps.length).fill(void 0);
2250
+ self._syncCtx = null;
2251
+ if (self._lifecycle.activated) {
2252
+ for (const d of added) self._subscribeDepAt(d);
2253
+ }
2254
+ notifyTopologyDepsChanged(node, oldDeps, newDeps);
2255
+ if (removedDirtyContributor && self._wave.pending === 0 && self._value.status === "dirty") {
2256
+ if (newDeps.length > 0) self._wave.rewireRunPending = true;
2257
+ else zeroDepUnDirty = true;
2258
+ }
2259
+ } finally {
2260
+ self._wave.inDepMutation = false;
2261
+ }
2262
+ if (self._wave.rewireRunPending) {
2263
+ self._wave.rewireRunPending = false;
2264
+ self._settleRewire();
2265
+ } else if (zeroDepUnDirty) {
2266
+ if (self._wave.emittedDirtyThisWave) self._down([["RESOLVED"]]);
2267
+ else self._value.status = self._value.hasData ? "settled" : "sentinel";
2268
+ }
2269
+ return false;
2270
+ }
2271
+
2272
+ // src/node/node.ts
2273
+ var Node = class _Node {
1237
2274
  _core;
1238
2275
  _id;
1239
2276
  _slot;
@@ -1254,12 +2291,56 @@ var Node = class {
1254
2291
  set _syncCtx(ctx) {
1255
2292
  this._syncCtxState.value = ctx;
1256
2293
  }
2294
+ static _retainIndirectRuntimeMethods(node) {
2295
+ void node._dep;
2296
+ void node._hooks;
2297
+ void node._restoredActivationPending;
2298
+ void node._requestRewireNext;
2299
+ void node._requestUpNext;
2300
+ void node._applyRewireNext;
2301
+ void node._reachableUpstream;
2302
+ void node._assertRewireDepOwner;
2303
+ void node._subscribeDepAt;
2304
+ void node._seedRestoredDepAt;
2305
+ void node._recordDepProjection;
2306
+ void node._depProjectionHasData;
2307
+ void node._receiveFromDep;
2308
+ void node._releaseDepDirty;
2309
+ void node._settleAfterAbsorbedTerminal;
2310
+ void node._markDirty;
2311
+ void node._maybeRun;
2312
+ void node._settleRewire;
2313
+ void node._tryRun;
2314
+ void node._allDepsSettled;
2315
+ void node._passthroughEmit;
2316
+ void node._runWave;
2317
+ void node._buildCtx;
2318
+ void node._makeCtx;
2319
+ void node._refreshCtx;
2320
+ void node._makeState;
2321
+ void node._markDemandRouted;
2322
+ void node._forwardUp;
2323
+ void node._isPullQuiet;
2324
+ void node._isPaused;
2325
+ void node._hasBoundaryPauseLock;
2326
+ void node._isAsyncPool;
2327
+ void node._pauseAcquire;
2328
+ void node._pauseRelease;
2329
+ void node._onResume;
2330
+ void node._canFireDemand;
2331
+ void node._deliverPullDemand;
2332
+ void node._onDemand;
2333
+ void node._firePullDemand;
2334
+ void node._fireOwedDemandIfReady;
2335
+ void node._shouldBufferOnPause;
2336
+ void node._invalidate;
2337
+ void node._allDepsTerminal;
2338
+ void node._emitToSubs;
2339
+ }
1257
2340
  constructor(deps, handleOrFn, opts = {}) {
1258
- const core = constructingCore;
1259
- constructingCore = void 0;
2341
+ const core = takeConstructingNodeCore();
1260
2342
  const dispatcher = opts.dispatcher ?? defaultDispatcher;
1261
- const environment = constructingEnvironment ?? EnvironmentDrivers.empty();
1262
- constructingEnvironment = void 0;
2343
+ const environment = takeConstructingEnvironmentDrivers() ?? EnvironmentDrivers.empty();
1263
2344
  const pool = opts.pool ?? "sync";
1264
2345
  const pausable = opts.pausable ?? true;
1265
2346
  const pullLock = opts.pullId;
@@ -1430,6 +2511,7 @@ var Node = class {
1430
2511
  runtimeQuiescenceReaders.set(this, () => this._isRuntimeQuiescentForRelease());
1431
2512
  subscriberCountReaders.set(this, () => this._subscriberCount());
1432
2513
  activationReaders.set(this, () => this._lifecycle.activated);
2514
+ _Node._retainIndirectRuntimeMethods(this);
1433
2515
  }
1434
2516
  /** R-pull (D55/D272): true while a pull node is not serving a PULL demand pulse. */
1435
2517
  _isPullQuiet() {
@@ -1534,58 +2616,6 @@ var Node = class {
1534
2616
  exitWave();
1535
2617
  }
1536
2618
  }
1537
- // ── deferred self-rewire (R-rewire-deferred / D47): ctx.rewireNext drain support ──
1538
- /**
1539
- * Enqueue a deferred self-rewire op (issued from this node's fn via `ctx.rewireNext`).
1540
- * Applied at the committed wave boundary (boundary.ts drain), never in place — the in-fn
1541
- * immediate path (`subscribeDep`/`replaceDeps`/`unsubscribeDep`) still throws mid-run (D37/R-reentrancy).
1542
- */
1543
- _requestRewireNext(op) {
1544
- deferRewire(this._core, () => this._applyRewireNext(op), {
1545
- batchToken: currentBoundaryBatchToken(),
1546
- isReady: () => !this._hasBoundaryPauseLock()
1547
- });
1548
- }
1549
- /**
1550
- * Enqueue a deferred up-going control/demand wave (R-up-routing / R-pull / D269): at the committed wave
1551
- * boundary, route `msgs` up from THIS node (broadcast, or up the single `towardDep` edge). The
1552
- * deferred form of `ctx.up` — the SELF-demand path: a consumer issues `ctx.upNext([[PULL,
1553
- * { pullId }]])` to demand a dep it ALSO reads; the demand applies at the boundary (not mid-fn), so
1554
- * the pull node's delivery loops back as a FRESH wave rather than re-entering the consumer (D37 /
1555
- * R-reentrancy). Rides the same R-rewire-deferred (D47) drain as ctx.rewireNext.
1556
- */
1557
- _requestUpNext(msgs, towardDep) {
1558
- deferRewire(
1559
- this._core,
1560
- () => {
1561
- if (!this._released) this._up(msgs, towardDep);
1562
- },
1563
- {
1564
- batchToken: currentBoundaryBatchToken(),
1565
- isReady: () => !this._hasBoundaryPauseLock()
1566
- }
1567
- );
1568
- }
1569
- /** Apply one queued self-rewire at the boundary (drain thunk). */
1570
- _applyRewireNext(op) {
1571
- if (this._released) return;
1572
- try {
1573
- if (op.kind === "add") {
1574
- const next = this._slot.deps.includes(op.dep) ? [...this._slot.deps] : [...this._slot.deps, op.dep];
1575
- this._rewire(next, op.fn, { allowTerminalOwner: true });
1576
- } else if (op.kind === "remove") {
1577
- this._rewire(
1578
- this._slot.deps.filter((d) => d !== op.dep),
1579
- op.fn,
1580
- { allowTerminalOwner: true }
1581
- );
1582
- } else {
1583
- this._rewire(this._dedupDeps(op.deps), op.fn, { allowTerminalOwner: true });
1584
- }
1585
- } catch (e) {
1586
- this._down([["ERROR", errorPayload(e, "rewireNext op failed")]]);
1587
- }
1588
- }
1589
2619
  // ── rewire (R-rewire / D42): intra-graph runtime topology mutation ──
1590
2620
  /**
1591
2621
  * Replace this node's deps atomically (surgical, Option-C). Requires an explicit
@@ -1613,6 +2643,15 @@ var Node = class {
1613
2643
  fn
1614
2644
  );
1615
2645
  }
2646
+ _requestRewireNext(op) {
2647
+ nodeRequestRewireNext(nodeRuntimeHost(this), op);
2648
+ }
2649
+ _requestUpNext(msgs, towardDep) {
2650
+ nodeRequestUpNext(nodeRuntimeHost(this), msgs, towardDep);
2651
+ }
2652
+ _applyRewireNext(op) {
2653
+ nodeApplyRewireNext(nodeRuntimeHost(this), op);
2654
+ }
1616
2655
  _dedupDeps(deps) {
1617
2656
  const seen = /* @__PURE__ */ new Set();
1618
2657
  const out = [];
@@ -1623,7 +2662,6 @@ var Node = class {
1623
2662
  }
1624
2663
  return out;
1625
2664
  }
1626
- /** Is `target` reachable upstream from `from` (following deps)? Cycle-prevention DFS. */
1627
2665
  _reachableUpstream(from, target) {
1628
2666
  const seen = /* @__PURE__ */ new Set();
1629
2667
  const stack = [from];
@@ -1633,1057 +2671,171 @@ var Node = class {
1633
2671
  if (n === target) return true;
1634
2672
  if (seen.has(n)) continue;
1635
2673
  seen.add(n);
1636
- for (const d of n._slot.deps) stack.push(d);
2674
+ for (const d of nodeRuntimeHost(n)._slot.deps) stack.push(d);
1637
2675
  }
1638
2676
  return false;
1639
2677
  }
1640
2678
  _assertRewireDepOwner(dep) {
1641
2679
  const selfOwner = getNodeOwner(this);
1642
2680
  const depOwner = getNodeOwner(dep);
1643
- if (selfOwner !== void 0 && depOwner !== void 0 && selfOwner !== depOwner) {
2681
+ if (selfOwner !== void 0 && depOwner !== void 0 && selfOwner !== depOwner)
1644
2682
  throw new Error(
1645
2683
  "rewire: dep belongs to a different graph; cross-graph deps require a wire bridge (D22 / R-graph-domain)"
1646
2684
  );
1647
- }
1648
2685
  }
1649
2686
  _rewire(newDeps, fn, opts = {}) {
1650
- if (this._value.terminal !== void 0 && !opts.allowTerminalOwner)
1651
- throw new Error(
1652
- "rewire: node is terminal (completed/errored) \u2014 cannot rewire (R-rewire / D42)"
1653
- );
1654
- if (this._wave.insideRunWave)
1655
- throw new Error(
1656
- "rewire: mid-fn topology mutation \u2014 a fn mutating its own deps mid-wave is the feedback cycle (R-rewire / D37)"
1657
- );
1658
- if (this._wave.inDepMutation)
1659
- throw new Error(
1660
- "rewire: reentrant dep mutation \u2014 another replaceDeps/subscribeDep/unsubscribeDep is in flight (R-rewire)"
1661
- );
1662
- if (newDeps.includes(this))
1663
- throw new Error("rewire: self-dependency rejected (R-rewire / D42)");
1664
- const oldDeps = this._slot.deps;
1665
- const added = newDeps.filter((d) => !oldDeps.includes(d));
1666
- for (const d of added) {
1667
- if (this._reachableUpstream(d, this))
1668
- throw new Error(
1669
- "rewire: would create a cycle \u2014 dep already transitively depends on this node (R-rewire / D42)"
1670
- );
1671
- if (d._value.terminal !== void 0 && !d._slot.resubscribable)
1672
- throw new Error(
1673
- "rewire: cannot add a non-resubscribable terminal dep \u2014 would wedge (R-rewire / D42)"
1674
- );
1675
- this._assertRewireDepOwner(d);
1676
- }
1677
- if (deferAfterBatchForTarget(this, () => {
1678
- this._rewire(newDeps, fn, { ...opts, allowTerminalOwner: true });
1679
- })) {
1680
- return true;
1681
- }
1682
- if (!this._lifecycle.activated) this._restoredActivationPending = false;
1683
- this._wave.inDepMutation = true;
1684
- this._wave.rewireRunPending = false;
1685
- let zeroDepUnDirty = false;
1686
- try {
1687
- const oldHandle = this._slot.handle;
1688
- this._slot.handle = this._slot.dispatcher.register(fn, this._slot.pool);
1689
- if (oldHandle !== null) this._slot.dispatcher.unregister(oldHandle);
1690
- const removed = oldDeps.filter((d) => !newDeps.includes(d));
1691
- let removedDirtyContributor = false;
1692
- for (const d of removed) {
1693
- const oldIdx = oldDeps.indexOf(d);
1694
- if (this._dep.dirty[oldIdx]) {
1695
- removedDirtyContributor = true;
1696
- this._wave.pending--;
1697
- }
1698
- if (this._lifecycle.activated) {
1699
- const box = this._dep.idxBoxes[oldIdx];
1700
- if (box) box.v = -1;
1701
- const unsub = this._dep.unsubs[oldIdx];
1702
- if (unsub) unsub();
1703
- }
1704
- }
1705
- const n = newDeps.length;
1706
- const newBatch = new Array(n).fill(null);
1707
- const newPrev = new Array(n).fill(SENTINEL);
1708
- const newHasData = new Array(n).fill(false);
1709
- const newDirty = new Array(n).fill(false);
1710
- const newTier = new Array(n).fill(0);
1711
- const newTerminal = new Array(n).fill(void 0);
1712
- const newTerminalInput = new Array(n).fill(void 0);
1713
- const newUnsubs = new Array(n);
1714
- const newBoxes = new Array(n);
1715
- for (let j = 0; j < n; j++) {
1716
- const oldIdx = oldDeps.indexOf(newDeps[j]);
1717
- if (oldIdx !== -1) {
1718
- newBatch[j] = this._dep.batch[oldIdx];
1719
- newPrev[j] = this._dep.prev[oldIdx];
1720
- newHasData[j] = this._dep.hasData[oldIdx];
1721
- newDirty[j] = this._dep.dirty[oldIdx];
1722
- newTier[j] = this._dep.tier[oldIdx];
1723
- newTerminal[j] = this._dep.terminal[oldIdx];
1724
- newUnsubs[j] = this._dep.unsubs[oldIdx];
1725
- const box = this._dep.idxBoxes[oldIdx];
1726
- if (box) box.v = j;
1727
- newBoxes[j] = box;
1728
- }
1729
- }
1730
- this._slot.deps = newDeps;
1731
- this._dep.batch = newBatch;
1732
- this._dep.prev = newPrev;
1733
- this._dep.hasData = newHasData;
1734
- this._dep.dirty = newDirty;
1735
- this._dep.tier = newTier;
1736
- this._dep.terminal = newTerminal;
1737
- this._dep.terminalInput = newTerminalInput;
1738
- this._dep.unsubs = newUnsubs;
1739
- this._dep.idxBoxes = newBoxes;
1740
- this._dep.waveData = newDeps.map(() => []);
1741
- this._dep.waveTokens = new Array(newDeps.length).fill(void 0);
1742
- this._syncCtx = null;
1743
- if (this._lifecycle.activated) {
1744
- for (const d of added) this._subscribeDepAt(d);
1745
- }
1746
- notifyTopologyDepsChanged(this, oldDeps, newDeps);
1747
- if (removedDirtyContributor && this._wave.pending === 0 && this._value.status === "dirty") {
1748
- if (newDeps.length > 0) this._wave.rewireRunPending = true;
1749
- else zeroDepUnDirty = true;
1750
- }
1751
- } finally {
1752
- this._wave.inDepMutation = false;
1753
- }
1754
- if (this._wave.rewireRunPending) {
1755
- this._wave.rewireRunPending = false;
1756
- this._settleRewire();
1757
- } else if (zeroDepUnDirty) {
1758
- if (this._wave.emittedDirtyThisWave) this._down([["RESOLVED"]]);
1759
- else this._value.status = this._value.hasData ? "settled" : "sentinel";
1760
- }
1761
- return false;
2687
+ return nodeRewire(nodeRuntimeHost(this), newDeps, fn, opts);
1762
2688
  }
1763
2689
  // ── activation / deactivation (lazy; R-rom-ram) ──
1764
2690
  _activate() {
1765
- this._lifecycle.activated = true;
1766
- const seedRestoredDeps = this._restoredActivationPending;
1767
- this._restoredActivationPending = false;
1768
- this._dep.unsubs = new Array(this._slot.deps.length);
1769
- this._dep.idxBoxes = new Array(this._slot.deps.length);
1770
- for (const dep of this._slot.deps)
1771
- this._subscribeDepAt(dep, { seedRestored: seedRestoredDeps });
1772
- if (this._slot.deps.length === 0 && this._slot.handle !== null && !this._wave.hasCalledFnOnce) {
1773
- this._runWave();
1774
- }
1775
- }
1776
- /**
1777
- * Subscribe to a dep. The dispatch callback reads the dep's CURRENT index from a
1778
- * mutable box (O(1)); a surgical rewire that reorders kept deps just updates the box
1779
- * (R-rewire Option-C / D42) — no re-subscribe, no per-message indexOf scan. A removed
1780
- * dep's box is set to -1 so any stale in-flight callback drops (drain).
1781
- */
1782
- _subscribeDepAt(depNode, opts = {}) {
1783
- const idx0 = this._slot.deps.indexOf(depNode);
1784
- const box = { v: idx0 };
1785
- let ignoreInitialPush = opts.seedRestored === true;
1786
- if (ignoreInitialPush && idx0 !== -1) {
1787
- this._seedRestoredDepAt(idx0, depNode);
1788
- if (depNode._value.terminal !== void 0 && !depNode._slot.resubscribable) {
1789
- this._dep.unsubs[idx0] = () => {
1790
- };
1791
- this._dep.idxBoxes[idx0] = box;
1792
- return;
1793
- }
1794
- }
1795
- const unsub = depNode.subscribe((msg, delivery) => {
1796
- if (ignoreInitialPush && delivery === void 0) return;
1797
- if (ignoreInitialPush) ignoreInitialPush = false;
1798
- if (box.v === -1) return;
1799
- this._receiveFromDep(box.v, msg, delivery);
1800
- });
1801
- if (ignoreInitialPush && idx0 !== -1 && box.v !== -1) this._seedRestoredDepAt(idx0, depNode);
1802
- ignoreInitialPush = false;
1803
- if (idx0 !== -1) {
1804
- this._dep.unsubs[idx0] = unsub;
1805
- this._dep.idxBoxes[idx0] = box;
1806
- }
1807
- }
1808
- _seedRestoredDepAt(idx, depNode) {
1809
- const seedData = depNode._value.hasData && !depNode._slot.pull;
1810
- this._dep.batch[idx] = null;
1811
- this._dep.waveData[idx] = [];
1812
- this._dep.waveTokens[idx] = void 0;
1813
- this._dep.prev[idx] = seedData ? depNode._value.cache : SENTINEL;
1814
- this._dep.hasData[idx] = seedData;
1815
- this._dep.dirty[idx] = false;
1816
- this._dep.tier[idx] = seedData ? 3 : 0;
1817
- this._dep.terminal[idx] = depNode._value.terminal;
1818
- this._dep.terminalInput[idx] = void 0;
2691
+ nodeActivate(nodeRuntimeHost(this));
1819
2692
  }
1820
2693
  _deactivate() {
1821
- this._lifecycle.activated = false;
1822
- for (const u of this._dep.unsubs) if (u) u();
1823
- this._dep.unsubs = [];
1824
- this._dep.idxBoxes = [];
1825
- for (const fn of this._hooks.onDeactivation) fn();
1826
- this._hooks.onDeactivation = [];
1827
- this._hooks.onInvalidate = [];
1828
- const isCompute = this._slot.handle !== null || this._slot.deps.length > 0;
1829
- if (isCompute) {
1830
- this._value.cache = SENTINEL;
1831
- this._value.hasData = false;
1832
- this._value.status = "sentinel";
1833
- }
1834
- this._resetDepState();
1835
- this._wave.hasCalledFnOnce = false;
1836
- this._control.pauseLockset.clear();
1837
- this._control.pauseBuffer = [];
1838
- this._control.pausedDepWaveOccurred = false;
1839
- this._control.demandOwed = void 0;
1840
- this._control.activePull = void 0;
1841
- this._control.pullDirtyOwed = false;
1842
- this._value.replayRing = [];
1843
- if (!this._privateState.persist) this._privateState.value = SENTINEL;
2694
+ nodeDeactivate(nodeRuntimeHost(this));
1844
2695
  }
1845
2696
  _assertNotReleased(op) {
1846
2697
  if (this._released)
1847
2698
  throw new Error(`${op}: node has been released from its graph lifecycle (D122)`);
1848
2699
  }
1849
2700
  _subscriberCount() {
1850
- return this._lifecycle.subscribers.size;
2701
+ return nodeSubscriberCount(nodeRuntimeHost(this));
1851
2702
  }
1852
2703
  _isRuntimeQuiescentForRelease() {
1853
- return !this._released && this._value.status !== "dirty" && this._value.status !== "pending" && this._wave.pending === 0 && !this._wave.insideRunWave && !this._wave.inDepMutation && !this._wave.rewireRunPending && !this._wave.batchDirtyOwed && this._dep.dirty.every((dirty) => !dirty) && this._control.pauseBuffer.length === 0 && !this._control.pausedDepWaveOccurred && this._control.demandOwed === void 0 && this._control.activePull === void 0 && !this._control.inDeliverDemand && this._control.pauseLockset.size === 0;
2704
+ return nodeIsRuntimeQuiescentForRelease(nodeRuntimeHost(this));
1854
2705
  }
1855
2706
  _releaseRuntime() {
1856
- if (this._released) return;
1857
- this._released = true;
1858
- releasedNodes.add(this);
1859
- let releaseError;
1860
- const recordReleaseError = (error) => {
1861
- if (releaseError === void 0) releaseError = error;
1862
- };
1863
- this._lifecycle.activated = false;
1864
- for (const u of this._dep.unsubs) {
1865
- try {
1866
- u();
1867
- } catch (error) {
1868
- recordReleaseError(error);
1869
- }
1870
- }
1871
- for (const fn of this._hooks.onDeactivation) {
1872
- try {
1873
- fn();
1874
- } catch (error) {
1875
- recordReleaseError(error);
1876
- }
1877
- }
1878
- this._dep.unsubs = [];
1879
- this._dep.idxBoxes = [];
1880
- this._lifecycle.subscribers.clear();
1881
- if (this._slot.handle !== null) {
1882
- this._slot.dispatcher.unregister(this._slot.handle);
1883
- this._slot.handle = null;
1884
- }
1885
- this._slot.deps = [];
1886
- this._dep.batch = [];
1887
- this._dep.waveData = [];
1888
- this._dep.waveTokens = [];
1889
- this._dep.prev = [];
1890
- this._dep.hasData = [];
1891
- this._dep.dirty = [];
1892
- this._dep.tier = [];
1893
- this._dep.terminal = [];
1894
- this._dep.terminalInput = [];
1895
- this._value.cache = SENTINEL;
1896
- this._value.hasData = false;
1897
- this._value.status = "sentinel";
1898
- this._value.terminal = void 0;
1899
- this._value.replayRing = [];
1900
- this._privateState.value = SENTINEL;
1901
- this._privateState.persist = false;
1902
- this._syncCtx = null;
1903
- this._resetDepState();
1904
- this._hooks.onDeactivation = [];
1905
- this._hooks.onInvalidate = [];
1906
- this._control.pauseLockset.clear();
1907
- this._control.pauseBuffer = [];
1908
- this._control.pausedDepWaveOccurred = false;
1909
- this._control.demandOwed = void 0;
1910
- this._control.activePull = void 0;
1911
- this._control.pullDirtyOwed = false;
1912
- this._restoredActivationPending = false;
1913
- checkpointReaders.delete(this);
1914
- restoreWriters.delete(this);
1915
- runtimeReleasers.delete(this);
1916
- runtimeQuiescenceReaders.delete(this);
1917
- subscriberCountReaders.delete(this);
1918
- activationReaders.delete(this);
1919
- ownerTokens.delete(this);
1920
- topologyDepsChangedObservers.delete(this);
1921
- this._core.releaseSlot(this._id);
1922
- if (releaseError !== void 0) throw releaseError;
2707
+ nodeReleaseRuntime(nodeRuntimeHost(this));
1923
2708
  }
1924
2709
  _resetDepState() {
1925
- const n = this._slot.deps.length;
1926
- for (let i = 0; i < n; i++) {
1927
- this._dep.batch[i] = null;
1928
- this._dep.waveData[i] = [];
1929
- this._dep.waveTokens[i] = void 0;
1930
- this._dep.prev[i] = SENTINEL;
1931
- this._dep.hasData[i] = false;
1932
- this._dep.dirty[i] = false;
1933
- this._dep.tier[i] = 0;
1934
- this._dep.terminal[i] = void 0;
1935
- this._dep.terminalInput[i] = void 0;
1936
- }
1937
- this._wave.pending = 0;
1938
- this._wave.emittedDirtyThisWave = false;
1939
- }
1940
- // ── upstream wave receive (two-phase + diamond) ──
2710
+ nodeResetDepState(nodeRuntimeHost(this));
2711
+ }
2712
+ _subscribeDepAt(depNode, opts = {}) {
2713
+ nodeSubscribeDepAt(nodeRuntimeHost(this), depNode, opts);
2714
+ }
2715
+ _seedRestoredDepAt(idx, depNode) {
2716
+ nodeSeedRestoredDepAt(nodeRuntimeHost(this), idx, depNode);
2717
+ }
1941
2718
  _recordDepProjection(idx, delivery) {
1942
- const token = delivery?.wave ?? {};
1943
- if (this._dep.waveTokens[idx] !== token) {
1944
- this._dep.waveData[idx].push([]);
1945
- this._dep.waveTokens[idx] = token;
1946
- }
1947
- return this._dep.waveData[idx][this._dep.waveData[idx].length - 1];
2719
+ return nodeRecordDepProjection(nodeRuntimeHost(this), idx, delivery);
1948
2720
  }
1949
2721
  _depProjectionHasData(idx) {
1950
- const projection = this._dep.waveData[idx][this._dep.waveData[idx].length - 1];
1951
- return projection?.some((v) => v !== SENTINEL) ?? false;
2722
+ return nodeDepProjectionHasData(nodeRuntimeHost(this), idx);
1952
2723
  }
1953
2724
  _receiveFromDep(idx, msg, delivery) {
1954
- if (this._released) return;
1955
- const t = msg[0];
1956
- if (t === "START") return;
1957
- const isLastInDeliveredWave = delivery?.last ?? true;
1958
- if (this._value.terminal !== void 0) {
1959
- if (t === "TEARDOWN") this._down([["TEARDOWN"]]);
1960
- return;
1961
- }
1962
- if (t === "INVALIDATE") {
1963
- const projection = this._recordDepProjection(idx, delivery);
1964
- projection.push(SENTINEL);
1965
- if (projection.some((v) => v !== SENTINEL) && isLastInDeliveredWave) this._maybeRun();
1966
- this._dep.prev[idx] = SENTINEL;
1967
- this._dep.hasData[idx] = false;
1968
- this._dep.batch[idx] = null;
1969
- if (this._dep.dirty[idx]) {
1970
- this._dep.dirty[idx] = false;
1971
- this._wave.pending--;
1972
- }
1973
- if (this._control.pausedDepWaveOccurred && this._dep.batch.every((b) => b === null)) {
1974
- this._control.pausedDepWaveOccurred = false;
1975
- }
1976
- const hadData = this._value.hasData;
1977
- this._invalidate();
1978
- if (this._wave.pending === 0 && this._wave.emittedDirtyThisWave) {
1979
- if (!hadData) this._down([["RESOLVED"]]);
1980
- else this._wave.emittedDirtyThisWave = false;
1981
- }
1982
- this._fireOwedDemandIfReady();
1983
- return;
1984
- }
1985
- if (isTerminal(t)) {
1986
- const isError = t === "ERROR";
1987
- const errPayload = isError ? msg[1] : void 0;
1988
- this._dep.terminal[idx] = isError ? errPayload : true;
1989
- this._dep.terminalInput[idx] = isError ? errPayload : true;
1990
- this._releaseDepDirty(idx);
1991
- const ranValueBeforeTerminal = this._depProjectionHasData(idx) && isLastInDeliveredWave;
1992
- if (ranValueBeforeTerminal) this._maybeRun();
1993
- if (isError && this._slot.errorWhenDepsError) {
1994
- this._down([["ERROR", errPayload]]);
1995
- } else if (this._slot.terminalAsRealInput) {
1996
- if (ranValueBeforeTerminal) {
1997
- this._fireOwedDemandIfReady();
1998
- return;
1999
- }
2000
- this._maybeRun();
2001
- } else if (this._slot.completeWhenDepsComplete && this._allDepsTerminal()) {
2002
- this._down([["COMPLETE"]]);
2003
- } else {
2004
- this._settleAfterAbsorbedTerminal();
2005
- }
2006
- this._fireOwedDemandIfReady();
2007
- return;
2008
- }
2009
- if (t === "TEARDOWN") {
2010
- this._down([["TEARDOWN"]]);
2011
- return;
2012
- }
2013
- if (t === "DIRTY") {
2014
- if (!this._dep.dirty[idx]) {
2015
- this._dep.dirty[idx] = true;
2016
- this._wave.pending++;
2017
- this._dep.tier[idx] = 2;
2018
- this._markDirty();
2019
- }
2020
- return;
2021
- }
2022
- if (t === "DATA") {
2023
- const v = msg[1];
2024
- this._recordDepProjection(idx, delivery).push(v);
2025
- const b = this._dep.batch[idx];
2026
- if (b === null) this._dep.batch[idx] = [v];
2027
- else b.push(v);
2028
- this._dep.prev[idx] = v;
2029
- this._dep.hasData[idx] = true;
2030
- this._dep.tier[idx] = 3;
2031
- if (this._dep.dirty[idx]) {
2032
- this._dep.dirty[idx] = false;
2033
- this._wave.pending--;
2034
- }
2035
- if (isLastInDeliveredWave) this._maybeRun();
2036
- this._fireOwedDemandIfReady();
2037
- return;
2038
- }
2039
- if (t === "RESOLVED") {
2040
- this._recordDepProjection(idx, delivery);
2041
- this._dep.tier[idx] = 3;
2042
- if (this._dep.dirty[idx]) {
2043
- this._dep.dirty[idx] = false;
2044
- this._wave.pending--;
2045
- }
2046
- if (isLastInDeliveredWave) this._maybeRun();
2047
- this._fireOwedDemandIfReady();
2048
- return;
2049
- }
2725
+ nodeReceiveFromDep(nodeRuntimeHost(this), idx, msg, delivery);
2050
2726
  }
2051
- /**
2052
- * R-terminal-settles-dirty (B35): release a dep's outstanding in-wave DIRTY contribution.
2053
- * A settle-class event for that dep (DATA/RESOLVED inline above, INVALIDATE, and now
2054
- * COMPLETE/ERROR) clears its dirty flag + decrements _pending. No-op if the dep already
2055
- * settled this wave (DATA/RESOLVED ran first) — so the normal DATA-then-COMPLETE flow is
2056
- * unaffected. This makes the exactly-one-settle invariant a single, shared step.
2057
- */
2058
2727
  _releaseDepDirty(idx) {
2059
- if (this._dep.dirty[idx]) {
2060
- this._dep.dirty[idx] = false;
2061
- this._wave.pending--;
2062
- }
2728
+ nodeReleaseDepDirty(nodeRuntimeHost(this), idx);
2063
2729
  }
2064
- /**
2065
- * R-terminal-settles-dirty (B35): settle a node whose dirtied dep was released by an ABSORBED
2066
- * terminal that is NOT a real input (a plain derived/effect — the common default-node case when
2067
- * one of several deps completes while others stay live). Runs only when the release drained
2068
- * _pending while the node still owes a downstream settle (it broadcast DIRTY this wave):
2069
- * - if some OTHER dep delivered real DATA this wave (a value occurred) → recompute (→ DATA);
2070
- * - else the terminal's signalled change did not materialise (no value) → one undirty RESOLVED
2071
- * (R-resolved-undirty), keeping the cache (a terminal, unlike INVALIDATE, leaves the value).
2072
- * A terminalAsRealInput node instead recomputes unconditionally (its fn reads the terminal).
2073
- */
2074
2730
  _settleAfterAbsorbedTerminal() {
2075
- if (this._wave.pending !== 0 || !this._wave.emittedDirtyThisWave) return;
2076
- const sawData = this._dep.batch.some((b) => b !== null && b.length > 0);
2077
- if (sawData) this._maybeRun();
2078
- if (this._wave.emittedDirtyThisWave) this._down([["RESOLVED"]]);
2731
+ nodeSettleAfterAbsorbedTerminal(nodeRuntimeHost(this));
2079
2732
  }
2080
2733
  _markDirty() {
2081
- this._value.status = "dirty";
2082
- if (this._isPullQuiet()) return;
2083
- if (!this._wave.emittedDirtyThisWave) {
2084
- this._wave.emittedDirtyThisWave = true;
2085
- this._emitToSubs(["DIRTY"]);
2086
- }
2734
+ nodeMarkDirty(nodeRuntimeHost(this));
2087
2735
  }
2088
2736
  _maybeRun() {
2089
- if (this._wave.inDepMutation) {
2090
- this._wave.rewireRunPending = true;
2091
- return;
2092
- }
2093
- if (this._slot.pausable === true && (this._isPaused() || this._isPullQuiet())) {
2094
- this._control.pausedDepWaveOccurred = true;
2095
- return;
2096
- }
2097
- this._tryRun();
2737
+ nodeMaybeRun(nodeRuntimeHost(this));
2098
2738
  }
2099
- /**
2100
- * R-rewire atomic settle (after a rewire that warrants a recompute): emit a proper
2101
- * two-phase DIRTY→DATA wave (R-dirty-before-data — a rewire-triggered settle is a wave),
2102
- * once, with every added dep already wired. Mirrors _maybeRun/_tryRun's pause + gate +
2103
- * pending guards, then injects the phase-1 DIRTY the added dep's [START,DATA] handshake
2104
- * did not carry.
2105
- */
2106
2739
  _settleRewire() {
2107
- if (this._slot.pausable === true && this._isPaused()) {
2108
- this._control.pausedDepWaveOccurred = true;
2109
- return;
2110
- }
2111
- if (this._wave.pending > 0) return;
2112
- if (this._slot.handle === null) {
2113
- this._passthroughEmit();
2114
- return;
2115
- }
2116
- if (!this._wave.hasCalledFnOnce && !(this._slot.partial || this._allDepsSettled())) return;
2117
- this._markDirty();
2118
- this._runWave();
2740
+ nodeSettleRewire(nodeRuntimeHost(this));
2119
2741
  }
2120
2742
  _tryRun() {
2121
- if (this._wave.pending > 0) return;
2122
- if (this._slot.handle === null) {
2123
- this._passthroughEmit();
2124
- return;
2125
- }
2126
- if (!this._wave.hasCalledFnOnce) {
2127
- if (this._slot.partial || this._allDepsSettled()) this._runWave();
2128
- return;
2129
- }
2130
- this._runWave();
2743
+ nodeTryRun(nodeRuntimeHost(this));
2131
2744
  }
2132
2745
  _allDepsSettled() {
2133
- for (let i = 0; i < this._slot.deps.length; i++) {
2134
- if (this._dep.hasData[i]) continue;
2135
- if (this._slot.terminalAsRealInput && this._dep.terminal[i] !== void 0) continue;
2136
- return false;
2137
- }
2138
- return true;
2746
+ return nodeAllDepsSettled(nodeRuntimeHost(this));
2139
2747
  }
2140
2748
  _passthroughEmit() {
2141
- const b = this._dep.batch[0];
2142
- if (b !== null && b.length > 0) {
2143
- this._down([["DATA", b[b.length - 1]]]);
2144
- } else if (this._wave.emittedDirtyThisWave) {
2145
- this._down([["RESOLVED"]]);
2146
- }
2147
- this._dep.batch[0] = null;
2148
- this._wave.emittedDirtyThisWave = false;
2749
+ nodePassthroughEmit(nodeRuntimeHost(this));
2149
2750
  }
2150
2751
  _runWave() {
2151
- if (this._wave.insideRunWave)
2152
- throw new Error(
2153
- "synchronous feedback cycle: node fn re-entered its own wave (R-reentrancy / D37)"
2154
- );
2155
- this._wave.hasCalledFnOnce = true;
2156
- this._hooks.onInvalidate = [];
2157
- this._hooks.onDeactivation = [];
2158
- const ctx = this._buildCtx();
2159
- const wasDirty = this._wave.emittedDirtyThisWave;
2160
- this._wave.emittedSettleThisWave = false;
2161
- this._wave.insideRunWave = true;
2162
- try {
2163
- this._slot.dispatcher.invoke(this._slot.handle, ctx);
2164
- } finally {
2165
- this._wave.insideRunWave = false;
2166
- }
2167
- if (wasDirty && !this._wave.emittedSettleThisWave && this._value.terminal === void 0 && !this._isAsyncPool()) {
2168
- this._down([["RESOLVED"]]);
2169
- }
2170
- for (let i = 0; i < this._dep.batch.length; i++) {
2171
- this._dep.batch[i] = null;
2172
- this._dep.waveData[i] = [];
2173
- this._dep.waveTokens[i] = void 0;
2174
- this._dep.terminalInput[i] = void 0;
2175
- }
2176
- this._wave.emittedDirtyThisWave = false;
2752
+ nodeRunWave(nodeRuntimeHost(this));
2177
2753
  }
2178
- // ── ctx construction (L3-Q5: sync = node-stable reused ctx; async = per-invocation) ──
2179
2754
  _buildCtx() {
2180
- const kind = this._slot.handle ? this._slot.dispatcher.poolKind(this._slot.handle.poolId) : "sync";
2181
- if (kind === "sync") {
2182
- if (this._syncCtx === null) this._syncCtx = this._makeCtx();
2183
- this._refreshCtx(this._syncCtx);
2184
- return this._syncCtx;
2185
- }
2186
- return this._makeCtx({
2187
- waveData: this._dep.waveData.map((waves) => waves.map((w) => [...w])),
2188
- terminal: this._dep.terminalInput.map(terminalView),
2189
- latest: [...this._dep.prev]
2190
- });
2755
+ return nodeBuildCtx(nodeRuntimeHost(this));
2191
2756
  }
2192
2757
  _makeCtx(snapshot) {
2193
- const ctx = {
2194
- // Wave-owner boundary (D47): a SYNC fn's emit nests under the public entry that drove
2195
- // it (cheap inc/dec, no early drain); an ASYNC-pool fn re-enters here from its stashed
2196
- // ctx at depth 0, so this is the boundary that drains any rewireNext it issued.
2197
- up: (msgs, towardDep) => {
2198
- if (this._released) return;
2199
- enterWave();
2200
- try {
2201
- this._up(msgs, towardDep);
2202
- } finally {
2203
- exitWave();
2204
- }
2205
- },
2206
- down: (msgs) => {
2207
- if (this._released) return;
2208
- enterWave();
2209
- try {
2210
- this._down(msgs);
2211
- } finally {
2212
- exitWave();
2213
- }
2214
- },
2215
- waveData: snapshot?.waveData ?? this._dep.waveData,
2216
- terminal: snapshot?.terminal ?? this._dep.terminalInput.map(terminalView),
2217
- state: this._makeState(),
2218
- onDeactivation: (fn) => {
2219
- if (this._released) return;
2220
- this._hooks.onDeactivation.push(fn);
2221
- },
2222
- onInvalidate: (fn) => {
2223
- if (this._released) return;
2224
- this._hooks.onInvalidate.push(fn);
2225
- },
2226
- environment: () => this._slot.environment,
2227
- // R-rewire-deferred (D47): defer a self-dep-set mutation to the committed boundary.
2228
- rewireNext: {
2229
- subscribeDep: (dep, fn) => this._requestRewireNext({ kind: "add", dep, fn }),
2230
- unsubscribeDep: (dep, fn) => this._requestRewireNext({ kind: "remove", dep, fn }),
2231
- replaceDeps: (deps, fn) => this._requestRewireNext({ kind: "set", deps, fn })
2232
- },
2233
- // R-up-routing / R-pull (D269): deferred up — route a control/demand wave (e.g. PULL)
2234
- // up the declared cone at the committed boundary. The SELF-demand path: an
2235
- // immediate ctx.up whose delivery loops back re-enters this fn (D37 / R-reentrancy).
2236
- upNext: (msgs, towardDep) => this._requestUpNext(msgs, towardDep),
2237
- ...this._control.activePull === void 0 ? {} : { pull: this._control.activePull },
2238
- [CTX_DEP_CACHE]: { latest: snapshot?.latest ?? this._dep.prev },
2239
- [CTX_NODE_BINDING]: {
2240
- dispatcher: this._slot.dispatcher,
2241
- create: (factory) => withEnvironmentDrivers(this._slot.environment, () => withNodeCore(this._core, factory))
2242
- }
2243
- };
2244
- if (this._slot.dynamic) {
2245
- ctx.track = (i) => ctx[CTX_DEP_CACHE]?.latest[i];
2246
- }
2247
- return ctx;
2758
+ return nodeMakeCtx(nodeRuntimeHost(this), snapshot);
2248
2759
  }
2249
2760
  _refreshCtx(ctx) {
2250
- ctx.waveData = this._dep.waveData;
2251
- ctx.terminal = this._dep.terminalInput.map(terminalView);
2252
- if (this._control.activePull === void 0) {
2253
- delete ctx.pull;
2254
- } else {
2255
- ctx.pull = this._control.activePull;
2256
- }
2257
- ctx[CTX_DEP_CACHE] = { latest: this._dep.prev };
2761
+ nodeRefreshCtx(nodeRuntimeHost(this), ctx);
2258
2762
  }
2259
2763
  _makeState() {
2260
- return {
2261
- get: () => this._privateState.value,
2262
- set: (v) => {
2263
- this._privateState.value = v;
2264
- },
2265
- persist: (on = true) => {
2266
- this._privateState.persist = on;
2267
- }
2268
- };
2764
+ return nodeMakeState(nodeRuntimeHost(this));
2269
2765
  }
2270
2766
  // ── downstream emission pipeline (the unified waist) ──
2271
2767
  _down(msgs) {
2272
- if (this._released) return;
2273
- validateDownPayloads(msgs);
2274
- const deliveryWave = {};
2275
- const assertVersionDataCompatible = (wave) => {
2276
- for (const m of wave) {
2277
- if (m[0] === "DATA") assertNodeVersionDataCompatible(this._version.policy, m[1]);
2278
- }
2279
- };
2280
- const snapshotVersionData = (wave) => wave.map(
2281
- (m) => m[0] === "DATA" ? ["DATA", snapshotNodeVersionData(this._version.policy, m[1])] : m
2282
- );
2283
- assertVersionDataCompatible(msgs);
2284
- if (this._value.terminal !== void 0) {
2285
- if (!msgs.some((m) => m[0] === "TEARDOWN")) return;
2286
- this._value.hasTorndown = true;
2287
- if (this._slot.resetOnTeardown) {
2288
- this._value.cache = SENTINEL;
2289
- this._value.hasData = false;
2290
- }
2291
- this._emitToSubs(["TEARDOWN"], { wave: deliveryWave, last: true });
2292
- return;
2293
- }
2294
- let sorted = [...msgs].sort((a, b) => messageTier(a[0]) - messageTier(b[0]));
2295
- const firstInvalidate = sorted.findIndex((m) => m[0] === "INVALIDATE");
2296
- if (firstInvalidate !== -1) {
2297
- sorted = sorted.filter((m, i) => m[0] !== "INVALIDATE" || i === firstInvalidate);
2298
- }
2299
- const hasTeardown = sorted.some((m) => m[0] === "TEARDOWN");
2300
- const hasTerminal = sorted.some((m) => m[0] === "COMPLETE" || m[0] === "ERROR");
2301
- if (hasTeardown && !hasTerminal && this._value.terminal === void 0 && !this._value.hasTorndown) {
2302
- sorted = [["COMPLETE"], ...sorted];
2303
- }
2304
- if (!this._wave.insideRunWave && currentBatch()) {
2305
- const deferred = snapshotVersionData(sorted.filter((m) => isDeferredTier(m[0])));
2306
- if (deferred.length > 0) {
2307
- if (!this._wave.emittedDirtyThisWave) {
2308
- this._wave.emittedDirtyThisWave = true;
2309
- this._value.status = "dirty";
2310
- this._emitToSubs(["DIRTY"], { wave: deliveryWave, last: false });
2311
- }
2312
- this._wave.batchDirtyOwed = true;
2313
- deferToBatch(this, deferred);
2314
- return;
2315
- }
2316
- }
2317
- if (this._shouldBufferOnPause()) {
2318
- const buffered = snapshotVersionData(sorted.filter((m) => isPauseBufferedTier(m[0])));
2319
- if (buffered.length > 0) {
2320
- this._wave.emittedSettleThisWave = true;
2321
- this._control.pauseBuffer.push(buffered);
2322
- }
2323
- sorted = sorted.filter((m) => !isPauseBufferedTier(m[0]));
2324
- if (sorted.length === 0) return;
2325
- }
2326
- let dataCount = 0;
2327
- let hasTier3 = false;
2328
- let hasResolved = false;
2329
- for (const m of sorted) {
2330
- if (m[0] === "DATA") dataCount++;
2331
- if (m[0] === "RESOLVED") hasResolved = true;
2332
- if (isValueTier(m[0])) hasTier3 = true;
2333
- }
2334
- if (dataCount >= 1 && hasResolved) {
2335
- throw new Error(
2336
- "down: a wave cannot mix DATA and RESOLVED (tier-3 exclusivity, R-resolved-undirty)"
2337
- );
2338
- }
2339
- const plannedVersions = new Array(sorted.length);
2340
- if (dataCount > 0) {
2341
- let plannedVersion = this._version.value;
2342
- for (let i = 0; i < sorted.length; i++) {
2343
- const m = sorted[i];
2344
- if (m[0] !== "DATA") continue;
2345
- plannedVersion = advanceNodeVersion(plannedVersion, this._version.policy, m[1]);
2346
- plannedVersions[i] = plannedVersion;
2347
- }
2348
- }
2349
- if (hasTier3 && (!this._wave.insideRunWave || this._control.pullDirtyOwed) && !this._wave.emittedDirtyThisWave) {
2350
- this._wave.emittedDirtyThisWave = true;
2351
- this._value.status = "dirty";
2352
- this._emitToSubs(["DIRTY"], { wave: deliveryWave, last: false });
2353
- }
2354
- for (let i = 0; i < sorted.length; i++) {
2355
- const m = sorted[i];
2356
- const delivery = { wave: deliveryWave, last: i === sorted.length - 1 };
2357
- if (isDeferredTier(m[0])) this._wave.emittedSettleThisWave = true;
2358
- if (m[0] === "DIRTY") {
2359
- if (!this._wave.emittedDirtyThisWave) {
2360
- this._wave.emittedDirtyThisWave = true;
2361
- this._value.status = "dirty";
2362
- this._emitToSubs(["DIRTY"], delivery);
2363
- }
2364
- continue;
2365
- }
2366
- if (m[0] === "DATA") {
2367
- const v = m[1];
2368
- this._value.cache = v;
2369
- this._value.hasData = true;
2370
- this._value.status = "settled";
2371
- this._version.value = plannedVersions[i];
2372
- if (this._slot.replayN > 0) {
2373
- this._value.replayRing.push(v);
2374
- if (this._value.replayRing.length > this._slot.replayN) this._value.replayRing.shift();
2375
- }
2376
- this._emitToSubs(["DATA", v], delivery);
2377
- continue;
2378
- }
2379
- if (m[0] === "RESOLVED") {
2380
- this._value.status = this._value.hasData ? "resolved" : "sentinel";
2381
- this._emitToSubs(["RESOLVED"], delivery);
2382
- continue;
2383
- }
2384
- if (m[0] === "INVALIDATE") {
2385
- this._invalidate(delivery);
2386
- continue;
2387
- }
2388
- if (m[0] === "COMPLETE") {
2389
- if (this._value.terminal !== void 0) continue;
2390
- this._value.terminal = true;
2391
- this._control.pauseBuffer = [];
2392
- this._value.status = "completed";
2393
- this._emitToSubs(["COMPLETE"], delivery);
2394
- continue;
2395
- }
2396
- if (m[0] === "ERROR") {
2397
- if (this._value.terminal !== void 0) continue;
2398
- this._value.terminal = m[1];
2399
- this._control.pauseBuffer = [];
2400
- this._value.status = "errored";
2401
- this._emitToSubs(["ERROR", m[1]], delivery);
2402
- continue;
2403
- }
2404
- if (m[0] === "TEARDOWN") {
2405
- this._value.hasTorndown = true;
2406
- if (this._slot.resetOnTeardown) {
2407
- this._value.cache = SENTINEL;
2408
- this._value.hasData = false;
2409
- }
2410
- this._emitToSubs(["TEARDOWN"], delivery);
2411
- }
2412
- }
2413
- if (!this._wave.insideRunWave) this._wave.emittedDirtyThisWave = false;
2768
+ nodeDown(nodeRuntimeHost(this), msgs);
2414
2769
  }
2415
2770
  _up(msgs, towardDep, route) {
2416
- if (this._released) return;
2417
- const routeState = route ?? { demandFired: /* @__PURE__ */ new Map() };
2418
- for (const m of msgs) {
2419
- if (!isUpAllowed(m[0])) {
2420
- throw new Error(
2421
- `ctx.up: ${m[0]} is down-only (tier ${messageTier(m[0])}); up carries control tiers only (R-ctx-up)`
2422
- );
2423
- }
2424
- }
2425
- for (const m of msgs) {
2426
- if (m[0] === "PAUSE") {
2427
- this._pauseAcquire(m[1]);
2428
- } else if (m[0] === "RESUME") {
2429
- if (this._control.pauseLockset.has(m[1])) {
2430
- this._pauseRelease(m[1]);
2431
- } else {
2432
- this._forwardUp(m, towardDep, routeState);
2433
- }
2434
- } else if (m[0] === "PULL") {
2435
- const demand = normalizePullDemand(m[1]);
2436
- if (this._slot.pull && demand.pullId === this._slot.pullLock) {
2437
- if (!this._markDemandRouted(demand.pullId, routeState)) this._onDemand(demand);
2438
- } else {
2439
- this._forwardUp(["PULL", demand], towardDep, routeState);
2440
- }
2441
- } else if (this._slot.deps.length === 0) {
2442
- if (m[0] === "INVALIDATE") this._down([["INVALIDATE"]]);
2443
- } else {
2444
- this._forwardUp(m, towardDep, routeState);
2445
- }
2446
- }
2771
+ nodeUp(nodeRuntimeHost(this), msgs, towardDep, route);
2447
2772
  }
2448
2773
  _markDemandRouted(lockId, route) {
2449
- let holders = route.demandFired.get(lockId);
2450
- if (holders === void 0) {
2451
- holders = /* @__PURE__ */ new Set();
2452
- route.demandFired.set(lockId, holders);
2453
- }
2454
- if (holders.has(this)) return true;
2455
- holders.add(this);
2456
- return false;
2774
+ return nodeMarkDemandRouted(nodeRuntimeHost(this), lockId, route);
2457
2775
  }
2458
- /**
2459
- * Forward one up-going control message toward deps (R-up-routing): up the single declared edge
2460
- * `towardDep` (directed — prunes other branches; only meaningful on the issuer's FIRST hop) or
2461
- * broadcast up ALL deps. A depless source has no deps → the message DROPS here (the terminus —
2462
- * e.g. a cone-routed PULL whose pullId no node up this cone holds, R-up-at-source). Recursive
2463
- * forwarding carries the same per-wave route state and no `towardDep` → broadcast beyond the
2464
- * first hop.
2465
- */
2466
2776
  _forwardUp(m, towardDep, route) {
2467
- if (this._slot.deps.length === 0) return;
2468
- if (towardDep !== void 0) {
2469
- const d = this._slot.deps[towardDep];
2470
- if (d !== void 0) d._up([m], void 0, route);
2471
- } else {
2472
- for (const dep of this._slot.deps) dep._up([m], void 0, route);
2473
- }
2777
+ nodeForwardUp(nodeRuntimeHost(this), m, towardDep, route);
2474
2778
  }
2475
- // ── PAUSE/RESUME lockset (R-pause-lockset) + modes (R-pause-modes) ──
2476
2779
  _isPaused() {
2477
- return this._control.pauseLockset.size > 0;
2780
+ return nodeIsPaused(nodeRuntimeHost(this));
2478
2781
  }
2479
2782
  _hasBoundaryPauseLock() {
2480
- if (this._slot.pausable === false) return false;
2481
- return this._control.pauseLockset.size > 0;
2783
+ return nodeHasBoundaryPauseLock(nodeRuntimeHost(this));
2482
2784
  }
2483
2785
  _isAsyncPool() {
2484
- return this._slot.handle !== null && this._slot.dispatcher.poolKind(this._slot.handle.poolId) === "async";
2786
+ return nodeIsAsyncPool(nodeRuntimeHost(this));
2485
2787
  }
2486
2788
  _pauseAcquire(lockId) {
2487
- this._control.pauseLockset.add(lockId);
2789
+ nodePauseAcquire(nodeRuntimeHost(this), lockId);
2488
2790
  }
2489
2791
  _pauseRelease(lockId) {
2490
- if (!this._control.pauseLockset.has(lockId)) return;
2491
- this._control.pauseLockset.delete(lockId);
2492
- if (this._slot.pull && this._control.demandOwed !== void 0) this._fireOwedDemandIfReady();
2493
- if (this._hasBoundaryPauseLock()) return;
2494
- scheduleBoundaryDrain(this._core);
2495
- if (this._slot.pull) return;
2496
- this._onResume();
2792
+ nodePauseRelease(nodeRuntimeHost(this), lockId);
2497
2793
  }
2498
2794
  _onResume() {
2499
- if (this._value.terminal !== void 0) {
2500
- this._control.pauseBuffer = [];
2501
- this._control.pausedDepWaveOccurred = false;
2502
- this._control.demandOwed = void 0;
2503
- this._control.activePull = void 0;
2504
- this._control.pullDirtyOwed = false;
2505
- return;
2506
- }
2507
- if (this._control.pauseBuffer.length > 0) {
2508
- const buf = this._control.pauseBuffer;
2509
- this._control.pauseBuffer = [];
2510
- for (const wave of buf) this._down(wave);
2511
- }
2512
- if (this._control.pausedDepWaveOccurred) {
2513
- this._control.pausedDepWaveOccurred = false;
2514
- this._tryRun();
2515
- }
2795
+ nodeOnResume(nodeRuntimeHost(this));
2516
2796
  }
2517
- /**
2518
- * R-pull (D269): can this pull node fire a demand NOW? — not terminal, settle-ready (_pending===0),
2519
- * and no OTHER (non-pullId) lock holds it paused. The gate that decides fire-now vs OWE.
2520
- */
2521
2797
  _canFireDemand() {
2522
- if (this._value.terminal !== void 0 || this._wave.pending > 0) return false;
2523
- return this._control.pauseLockset.size === 0;
2798
+ return nodeCanFireDemand(nodeRuntimeHost(this));
2524
2799
  }
2525
- /**
2526
- * R-pull (D269/D272): deliver ONE demand pulse — install activePull so the demand wave may
2527
- * emit, fire it, then clear activePull so the node is quiet again (1:1).
2528
- */
2529
2800
  _deliverPullDemand(demand) {
2530
- this._control.demandOwed = void 0;
2531
- this._control.activePull = demand;
2532
- this._control.inDeliverDemand = true;
2533
- try {
2534
- this._firePullDemand();
2535
- } finally {
2536
- this._control.activePull = void 0;
2537
- this._control.inDeliverDemand = false;
2538
- }
2801
+ nodeDeliverPullDemand(nodeRuntimeHost(this), demand);
2539
2802
  }
2540
- /**
2541
- * R-pull (D269): a cone-routed PULL of THIS node's pullId arrived (R-up-routing) = a DEMAND.
2542
- * Fire immediately if able; else OWE it — pin-5 (a dep DIRTY in flight, _pending>0) or F4/F5 (an
2543
- * external PAUSE lock co-holds the node) — and fire when the node next becomes able. A demand
2544
- * arriving WHILE a delivery is in flight (synchronous re-entry) is DROPPED (1:1, QA guard).
2545
- */
2546
2803
  _onDemand(demand) {
2547
- if (this._control.inDeliverDemand) return;
2548
- if (this._canFireDemand()) this._deliverPullDemand(demand);
2549
- else this._control.demandOwed = demand;
2804
+ nodeOnDemand(nodeRuntimeHost(this), demand);
2550
2805
  }
2551
- /**
2552
- * R-pull (D55): service ONE demand. Delivery content = the orthogonal pausable mode:
2553
- * - 'resumeAll' → drain the buffered BACKLOG (each `_down` re-synthesizes a leading DIRTY, so
2554
- * the per-entry replay is DIRTY-before-DATA — R-pause-modes per-entry arrival order);
2555
- * - true → deliver the coalesced LATEST as ONE DIRTY-before-DATA wave (pin 2: the quiet absorb
2556
- * suppressed the dep's original DIRTY, so the demand wave restores it before the value).
2557
- * Neither branch fires when nothing changed since the last demand → the demand is SILENT.
2558
- * Called by `_deliverPullDemand` only when settle-ready; the caller has released the pullId, so
2559
- * `_markDirty` relays the leading DIRTY (not absorbed).
2560
- */
2561
2806
  _firePullDemand() {
2562
- let drainedBuffer = false;
2563
- if (this._control.pauseBuffer.length > 0) {
2564
- const buf = this._control.pauseBuffer;
2565
- this._control.pauseBuffer = [];
2566
- for (const wave of buf) this._down(wave);
2567
- drainedBuffer = true;
2568
- }
2569
- if (drainedBuffer) return;
2570
- if (this._control.pausedDepWaveOccurred) {
2571
- const gated = this._slot.handle !== null && !this._wave.hasCalledFnOnce && !(this._slot.partial || this._allDepsSettled());
2572
- if (this._wave.pending > 0 || gated) return;
2573
- this._control.pausedDepWaveOccurred = false;
2574
- this._wave.emittedDirtyThisWave = false;
2575
- this._control.pullDirtyOwed = true;
2576
- try {
2577
- this._tryRun();
2578
- } finally {
2579
- this._control.pullDirtyOwed = false;
2580
- }
2581
- return;
2582
- }
2583
- if (this._slot.handle !== null) {
2584
- if (!this._wave.hasCalledFnOnce && !(this._slot.partial || this._allDepsSettled())) return;
2585
- this._wave.emittedDirtyThisWave = false;
2586
- this._control.pullDirtyOwed = true;
2587
- try {
2588
- this._runWave();
2589
- } finally {
2590
- this._control.pullDirtyOwed = false;
2591
- }
2592
- }
2807
+ nodeFirePullDemand(nodeRuntimeHost(this));
2593
2808
  }
2594
- /**
2595
- * R-pull (D269): fire a demand that was OWED (deferred at demand time) once the node becomes
2596
- * able — called from the dep-settle arms (DATA/RESOLVED/INVALIDATE/terminal drain _pending, pin-5
2597
- * + B1/F6) and from `_pauseRelease` (an external PAUSE lock releases, F4/F5).
2598
- */
2599
2809
  _fireOwedDemandIfReady() {
2600
- if (this._control.inDeliverDemand) return;
2601
- if (this._slot.pull && this._control.demandOwed !== void 0 && this._canFireDemand()) {
2602
- this._deliverPullDemand(this._control.demandOwed);
2603
- }
2810
+ nodeFireOwedDemandIfReady(nodeRuntimeHost(this));
2604
2811
  }
2605
- /** Should an outgoing settle slice be deferred into the pause buffer? */
2606
2812
  _shouldBufferOnPause() {
2607
- if (this._slot.pausable === false) return false;
2608
- if (!this._isPaused() && !this._isPullQuiet()) return false;
2609
- if (this._slot.pausable === "resumeAll") return true;
2610
- if (!this._wave.insideRunWave && this._isAsyncPool() && this._slot.deps.length > 0) return true;
2611
- return false;
2813
+ return nodeShouldBufferOnPause(nodeRuntimeHost(this));
2612
2814
  }
2613
- /** R-invalidate-idempotent: clear cache + flush + cascade; no-op if nothing cached. */
2614
2815
  _invalidate(delivery) {
2615
- if (!this._value.hasData) return;
2616
- this._value.cache = SENTINEL;
2617
- this._value.hasData = false;
2618
- this._value.status = "sentinel";
2619
- this._value.replayRing = [];
2620
- for (const fn of this._hooks.onInvalidate) fn();
2621
- this._emitToSubs(["INVALIDATE"], delivery);
2622
- }
2623
- // B42 (R-deps-terminal): ALL deps TERMINAL = every dep has reached COMPLETE *or* an ABSORBED
2624
- // ERROR. Block only on a LIVE dep (_depTerminal[i] === undefined); an errored dep (terminal = the
2625
- // error payload, which R-data-payload guarantees is !== undefined and non-boolean) COUNTS as
2626
- // terminal-done. Was
2627
- // `tm !== true`, which wedged a node whose errorWhenDepsError:false dep ERRORed (it never
2628
- // auto-completed even after every other dep completed). Drives the completeWhenDepsComplete cascade.
2816
+ nodeInvalidate(nodeRuntimeHost(this), delivery);
2817
+ }
2629
2818
  _allDepsTerminal() {
2630
- if (this._slot.deps.length === 0) return false;
2631
- for (const tm of this._dep.terminal) if (tm === void 0) return false;
2632
- return true;
2819
+ return nodeAllDepsTerminal(nodeRuntimeHost(this));
2820
+ }
2821
+ _emitToSubs(msg, delivery) {
2822
+ nodeEmitToSubs(nodeRuntimeHost(this), msg, delivery);
2633
2823
  }
2634
2824
  /** R-terminal: resubscribable reset clears terminal + dep state + re-arms the gate. */
2635
2825
  _resetLifecycle() {
2636
- for (const u of this._dep.unsubs) if (u) u();
2637
- this._dep.unsubs = [];
2638
- this._dep.idxBoxes = [];
2639
- this._lifecycle.subscribers.clear();
2640
- this._lifecycle.activated = false;
2641
- this._value.terminal = void 0;
2642
- this._value.hasTorndown = false;
2643
- this._wave.hasCalledFnOnce = false;
2644
- this._resetDepState();
2645
- this._control.pauseLockset.clear();
2646
- this._control.pauseBuffer = [];
2647
- this._control.pausedDepWaveOccurred = false;
2648
- this._control.demandOwed = void 0;
2649
- this._control.activePull = void 0;
2650
- this._control.pullDirtyOwed = false;
2651
- this._value.replayRing = [];
2652
- const isCompute = this._slot.handle !== null || this._slot.deps.length > 0;
2653
- if (isCompute) {
2654
- this._value.cache = SENTINEL;
2655
- this._value.hasData = false;
2656
- this._value.status = "sentinel";
2657
- } else {
2658
- this._value.status = this._value.hasData ? "settled" : "sentinel";
2659
- }
2660
- if (!this._privateState.persist) this._privateState.value = SENTINEL;
2661
- }
2662
- _emitToSubs(msg, delivery) {
2663
- if (this._released) return;
2664
- const subs = [...this._lifecycle.subscribers];
2665
- for (const sink of subs) sink(msg, delivery);
2826
+ nodeResetLifecycle(nodeRuntimeHost(this));
2666
2827
  }
2667
2828
  /** Batch commit (R-batch-coalesce): deliver the deferred tier-3 wave now. */
2668
2829
  __commitBatchedWave(wave) {
2669
- this._wave.batchDirtyOwed = false;
2670
- this._down(wave);
2830
+ nodeCommitBatchedWave(nodeRuntimeHost(this), wave);
2671
2831
  }
2672
2832
  /** Batch rollback: balance the immediate DIRTY with a RESOLVED so downstream un-dirties. */
2673
2833
  __rollbackBatched() {
2674
- if (this._wave.batchDirtyOwed) {
2675
- this._wave.batchDirtyOwed = false;
2676
- this._wave.emittedDirtyThisWave = false;
2677
- this._value.status = this._value.hasData ? "settled" : "sentinel";
2678
- this._emitToSubs(["RESOLVED"]);
2679
- }
2834
+ nodeRollbackBatched(nodeRuntimeHost(this));
2680
2835
  }
2681
2836
  /** B49: enqueue a committed-boundary task on this node's graph-local core. */
2682
2837
  __deferBoundary(fn, batchToken) {
2683
- deferRewire(this._core, fn, {
2684
- batchToken,
2685
- isReady: () => !this._hasBoundaryPauseLock()
2686
- });
2838
+ nodeDeferBoundary(nodeRuntimeHost(this), fn, batchToken);
2687
2839
  }
2688
2840
  };
2689
2841