@graphrefly/ts 0.0.0 → 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 (405) hide show
  1. package/README.md +135 -0
  2. package/dist/actions-types-CSC3NMDl.d.ts +657 -0
  3. package/dist/actions-types-wl9Mgkmr.d.cts +657 -0
  4. package/dist/adapters/index.cjs +5219 -2974
  5. package/dist/adapters/index.cjs.map +1 -1
  6. package/dist/adapters/index.d.cts +204 -192
  7. package/dist/adapters/index.d.ts +204 -192
  8. package/dist/adapters/index.js +3685 -1833
  9. package/dist/adapters/index.js.map +1 -1
  10. package/dist/adapters/nestjs/microservices.cjs +841 -0
  11. package/dist/adapters/nestjs/microservices.cjs.map +1 -0
  12. package/dist/adapters/nestjs/microservices.d.cts +45 -0
  13. package/dist/adapters/nestjs/microservices.d.ts +45 -0
  14. package/dist/adapters/nestjs/microservices.js +206 -0
  15. package/dist/adapters/nestjs/microservices.js.map +1 -0
  16. package/dist/adapters/nestjs/native.cjs +1391 -0
  17. package/dist/adapters/nestjs/native.cjs.map +1 -0
  18. package/dist/adapters/nestjs/native.d.cts +111 -0
  19. package/dist/adapters/nestjs/native.d.ts +111 -0
  20. package/dist/adapters/nestjs/native.js +577 -0
  21. package/dist/adapters/nestjs/native.js.map +1 -0
  22. package/dist/adapters/nestjs/websockets.cjs +924 -0
  23. package/dist/adapters/nestjs/websockets.cjs.map +1 -0
  24. package/dist/adapters/nestjs/websockets.d.cts +47 -0
  25. package/dist/adapters/nestjs/websockets.d.ts +47 -0
  26. package/dist/adapters/nestjs/websockets.js +286 -0
  27. package/dist/adapters/nestjs/websockets.js.map +1 -0
  28. package/dist/adapters/nestjs.cjs +1085 -0
  29. package/dist/adapters/nestjs.cjs.map +1 -0
  30. package/dist/adapters/nestjs.d.cts +385 -0
  31. package/dist/adapters/nestjs.d.ts +385 -0
  32. package/dist/adapters/nestjs.js +112 -0
  33. package/dist/adapters/nestjs.js.map +1 -0
  34. package/dist/adapters/observe-storage.d.cts +4 -4
  35. package/dist/adapters/observe-storage.d.ts +4 -4
  36. package/dist/adapters/observe-storage.js +5 -4
  37. package/dist/adapters/observe-storage.js.map +1 -1
  38. package/dist/adapters/react.cjs +166 -0
  39. package/dist/adapters/react.cjs.map +1 -0
  40. package/dist/adapters/react.d.cts +31 -0
  41. package/dist/adapters/react.d.ts +31 -0
  42. package/dist/adapters/react.js +51 -0
  43. package/dist/adapters/react.js.map +1 -0
  44. package/dist/adapters/solid.cjs +157 -0
  45. package/dist/adapters/solid.cjs.map +1 -0
  46. package/dist/adapters/solid.d.cts +26 -0
  47. package/dist/adapters/solid.d.ts +26 -0
  48. package/dist/adapters/solid.js +48 -0
  49. package/dist/adapters/solid.js.map +1 -0
  50. package/dist/adapters/svelte.cjs +148 -0
  51. package/dist/adapters/svelte.cjs.map +1 -0
  52. package/dist/adapters/svelte.d.cts +31 -0
  53. package/dist/adapters/svelte.d.ts +31 -0
  54. package/dist/adapters/svelte.js +46 -0
  55. package/dist/adapters/svelte.js.map +1 -0
  56. package/dist/adapters/vue.cjs +155 -0
  57. package/dist/adapters/vue.cjs.map +1 -0
  58. package/dist/adapters/vue.d.cts +26 -0
  59. package/dist/adapters/vue.d.ts +26 -0
  60. package/dist/adapters/vue.js +46 -0
  61. package/dist/adapters/vue.js.map +1 -0
  62. package/dist/agent-runtime-types-core-CaXfKNtY.d.cts +406 -0
  63. package/dist/agent-runtime-types-core-hU299uIC.d.ts +406 -0
  64. package/dist/agent-runtime-types-tool-BEpSINol.d.ts +695 -0
  65. package/dist/agent-runtime-types-tool-DninPEzk.d.cts +695 -0
  66. package/dist/agentic-memory-retention-BmGX368S.d.ts +14 -0
  67. package/dist/agentic-memory-retention-Ih1qhX9Z.d.cts +14 -0
  68. package/dist/agentic-memory-types-CVSUS6XR.d.ts +473 -0
  69. package/dist/agentic-memory-types-FnnYlVUs.d.cts +473 -0
  70. package/dist/capability-admission-BW2CziT6.d.ts +102 -0
  71. package/dist/capability-admission-lwSecxXs.d.cts +102 -0
  72. package/dist/chunk-2KUAG2GZ.js +9693 -0
  73. package/dist/chunk-2KUAG2GZ.js.map +1 -0
  74. package/dist/chunk-2NJP6GO4.js +1320 -0
  75. package/dist/chunk-2NJP6GO4.js.map +1 -0
  76. package/dist/{chunk-GDL26N2T.js → chunk-3KN7NJDR.js} +2 -2
  77. package/dist/{chunk-COHO25CZ.js → chunk-4NWSNI4K.js} +2232 -1672
  78. package/dist/chunk-4NWSNI4K.js.map +1 -0
  79. package/dist/{chunk-Z2ANQ6JW.js → chunk-4Q77MMJY.js} +2 -2
  80. package/dist/chunk-6E76H4OU.js +132 -0
  81. package/dist/chunk-6E76H4OU.js.map +1 -0
  82. package/dist/chunk-7GOTIIQ7.js +819 -0
  83. package/dist/chunk-7GOTIIQ7.js.map +1 -0
  84. package/dist/{chunk-D6BG7U6A.js → chunk-7HZRJMN6.js} +3 -3
  85. package/dist/{chunk-SCRFRCGR.js → chunk-BSQGE5PS.js} +1 -1
  86. package/dist/{chunk-PKVBHGBM.js → chunk-CJIFGJQG.js} +7 -7
  87. package/dist/{chunk-G4M3NHRJ.js → chunk-CX6B6PO2.js} +93 -10
  88. package/dist/chunk-CX6B6PO2.js.map +1 -0
  89. package/dist/chunk-DGUM43GV.js +11 -0
  90. package/dist/chunk-DGUM43GV.js.map +1 -0
  91. package/dist/{chunk-JIMUDQN3.js → chunk-E4QCH32M.js} +449 -447
  92. package/dist/chunk-E4QCH32M.js.map +1 -0
  93. package/dist/{chunk-RIIOUTGM.js → chunk-ECURQ3HD.js} +19 -129
  94. package/dist/chunk-ECURQ3HD.js.map +1 -0
  95. package/dist/{chunk-2ILL7HQI.js → chunk-EOKT4QFF.js} +134 -128
  96. package/dist/chunk-EOKT4QFF.js.map +1 -0
  97. package/dist/{chunk-K3FXTC3I.js → chunk-HJACH5PU.js} +3 -3
  98. package/dist/{chunk-GTPCOEOZ.js → chunk-IDMLXLLG.js} +3 -3
  99. package/dist/{chunk-DKP56CSW.js → chunk-JKAYLDQV.js} +2 -2
  100. package/dist/{chunk-4VLAQHZI.js → chunk-K7FB3JTD.js} +17 -1
  101. package/dist/chunk-K7FB3JTD.js.map +1 -0
  102. package/dist/chunk-L6LDXRWE.js +219 -0
  103. package/dist/chunk-L6LDXRWE.js.map +1 -0
  104. package/dist/chunk-M7J6Z4IJ.js +1930 -0
  105. package/dist/chunk-M7J6Z4IJ.js.map +1 -0
  106. package/dist/chunk-MQEQMS7B.js +1009 -0
  107. package/dist/chunk-MQEQMS7B.js.map +1 -0
  108. package/dist/chunk-MTELVIYR.js +1421 -0
  109. package/dist/chunk-MTELVIYR.js.map +1 -0
  110. package/dist/chunk-PVC7WDKI.js +885 -0
  111. package/dist/chunk-PVC7WDKI.js.map +1 -0
  112. package/dist/chunk-RAHNUYA5.js +368 -0
  113. package/dist/chunk-RAHNUYA5.js.map +1 -0
  114. package/dist/{chunk-DK554R7P.js → chunk-S6HXABGL.js} +2 -1
  115. package/dist/chunk-S6HXABGL.js.map +1 -0
  116. package/dist/{chunk-I3IHOHCJ.js → chunk-SHZDP2MQ.js} +1181 -1001
  117. package/dist/chunk-SHZDP2MQ.js.map +1 -0
  118. package/dist/{chunk-Y3ZLRGHC.js → chunk-SIDJO2T4.js} +16 -16
  119. package/dist/chunk-STXRMPW4.js +4131 -0
  120. package/dist/chunk-STXRMPW4.js.map +1 -0
  121. package/dist/{chunk-JR4IKCR2.js → chunk-TPND5MJS.js} +5 -5
  122. package/dist/chunk-TQPCAIQI.js +612 -0
  123. package/dist/chunk-TQPCAIQI.js.map +1 -0
  124. package/dist/chunk-UT3MHJCW.js +49 -0
  125. package/dist/chunk-UT3MHJCW.js.map +1 -0
  126. package/dist/{chunk-TEW47IVR.js → chunk-VPEFSDME.js} +2 -2
  127. package/dist/{chunk-SWTLEQL6.js → chunk-WQIA3GFB.js} +2 -2
  128. package/dist/chunk-WQIA3GFB.js.map +1 -0
  129. package/dist/{chunk-DJC4CHLQ.js → chunk-YDWBXXQZ.js} +5 -5
  130. package/dist/{chunk-6PHB5CJS.js → chunk-ZLFRB6FI.js} +2 -2
  131. package/dist/composition/index.cjs +1256 -1059
  132. package/dist/composition/index.cjs.map +1 -1
  133. package/dist/composition/index.d.cts +4 -4
  134. package/dist/composition/index.d.ts +4 -4
  135. package/dist/composition/index.js +7 -6
  136. package/dist/core/index.cjs +1218 -1021
  137. package/dist/core/index.cjs.map +1 -1
  138. package/dist/core/index.d.cts +2 -2
  139. package/dist/core/index.d.ts +2 -2
  140. package/dist/core/index.js +5 -4
  141. package/dist/cqrs/index.cjs.map +1 -1
  142. package/dist/cqrs/index.d.cts +4 -4
  143. package/dist/cqrs/index.d.ts +4 -4
  144. package/dist/cqrs/index.js +3 -2
  145. package/dist/cqrs/index.js.map +1 -1
  146. package/dist/cqrs/messaging.cjs +312 -0
  147. package/dist/cqrs/messaging.cjs.map +1 -0
  148. package/dist/cqrs/messaging.d.cts +57 -0
  149. package/dist/cqrs/messaging.d.ts +57 -0
  150. package/dist/cqrs/messaging.js +274 -0
  151. package/dist/cqrs/messaging.js.map +1 -0
  152. package/dist/cqrs/work-queue.cjs +329 -0
  153. package/dist/cqrs/work-queue.cjs.map +1 -0
  154. package/dist/cqrs/work-queue.d.cts +90 -0
  155. package/dist/cqrs/work-queue.d.ts +90 -0
  156. package/dist/cqrs/work-queue.js +292 -0
  157. package/dist/cqrs/work-queue.js.map +1 -0
  158. package/dist/data/index.cjs +19 -0
  159. package/dist/data/index.cjs.map +1 -0
  160. package/dist/data/index.d.cts +36 -0
  161. package/dist/data/index.d.ts +36 -0
  162. package/dist/data/index.js +1 -0
  163. package/dist/data/index.js.map +1 -0
  164. package/dist/data-structures/index.cjs +1252 -1052
  165. package/dist/data-structures/index.cjs.map +1 -1
  166. package/dist/data-structures/index.d.cts +9 -8
  167. package/dist/data-structures/index.d.ts +9 -8
  168. package/dist/data-structures/index.js +9 -7
  169. package/dist/{describe-BZb7AS2y.d.ts → describe-B_A5fbXH.d.ts} +1 -1
  170. package/dist/{describe-Ciu8SUnN.d.cts → describe-CQRrkv-Q.d.cts} +1 -1
  171. package/dist/executors/tool-provider-adapters.cjs +3091 -0
  172. package/dist/executors/tool-provider-adapters.cjs.map +1 -0
  173. package/dist/executors/tool-provider-adapters.d.cts +174 -0
  174. package/dist/executors/tool-provider-adapters.d.ts +174 -0
  175. package/dist/executors/tool-provider-adapters.js +1336 -0
  176. package/dist/executors/tool-provider-adapters.js.map +1 -0
  177. package/dist/executors/tool-provider-runtime.cjs +5178 -0
  178. package/dist/executors/tool-provider-runtime.cjs.map +1 -0
  179. package/dist/executors/tool-provider-runtime.d.cts +17 -0
  180. package/dist/executors/tool-provider-runtime.d.ts +17 -0
  181. package/dist/executors/tool-provider-runtime.js +15 -0
  182. package/dist/executors/tool-provider-runtime.js.map +1 -0
  183. package/dist/executors/tool-provider.cjs +6392 -0
  184. package/dist/executors/tool-provider.cjs.map +1 -0
  185. package/dist/executors/tool-provider.d.cts +60 -0
  186. package/dist/executors/tool-provider.d.ts +60 -0
  187. package/dist/executors/tool-provider.js +89 -0
  188. package/dist/executors/tool-provider.js.map +1 -0
  189. package/dist/executors/work-queue.cjs +342 -0
  190. package/dist/executors/work-queue.cjs.map +1 -0
  191. package/dist/executors/work-queue.d.cts +90 -0
  192. package/dist/executors/work-queue.d.ts +90 -0
  193. package/dist/executors/work-queue.js +306 -0
  194. package/dist/executors/work-queue.js.map +1 -0
  195. package/dist/graph/index.cjs +1536 -1324
  196. package/dist/graph/index.cjs.map +1 -1
  197. package/dist/graph/index.d.cts +10 -9
  198. package/dist/graph/index.d.ts +10 -9
  199. package/dist/graph/index.js +22 -20
  200. package/dist/{graph-s23RbbFO.d.cts → graph-CWK3HLPB.d.cts} +134 -132
  201. package/dist/{graph-DfdF9zy4.d.ts → graph-ho5sotHP.d.ts} +134 -132
  202. package/dist/{index-SnzZu3x7.d.ts → index-CQWcE0Dw.d.ts} +18 -4
  203. package/dist/{index-CAEmLCYF.d.cts → index-DHA1i67c.d.cts} +18 -4
  204. package/dist/index.cjs +3331 -3020
  205. package/dist/index.cjs.map +1 -1
  206. package/dist/index.d.cts +14 -10
  207. package/dist/index.d.ts +14 -10
  208. package/dist/index.js +114 -108
  209. package/dist/inspection/boundary.cjs +98 -0
  210. package/dist/inspection/boundary.cjs.map +1 -0
  211. package/dist/inspection/boundary.d.cts +61 -0
  212. package/dist/inspection/boundary.d.ts +61 -0
  213. package/dist/inspection/boundary.js +75 -0
  214. package/dist/inspection/boundary.js.map +1 -0
  215. package/dist/measurements-C0mAvWU1.d.cts +164 -0
  216. package/dist/measurements-OMpCeBwh.d.ts +164 -0
  217. package/dist/{messages-BZqrGGm1.d.ts → messages-CAzUPPJM.d.cts} +10 -5
  218. package/dist/{messages-BZqrGGm1.d.cts → messages-CAzUPPJM.d.ts} +10 -5
  219. package/dist/messaging/index.cjs +756 -619
  220. package/dist/messaging/index.cjs.map +1 -1
  221. package/dist/messaging/index.d.cts +17 -226
  222. package/dist/messaging/index.d.ts +17 -226
  223. package/dist/messaging/index.js +19 -749
  224. package/dist/messaging/index.js.map +1 -1
  225. package/dist/operators/index.cjs +1256 -1059
  226. package/dist/operators/index.cjs.map +1 -1
  227. package/dist/operators/index.d.cts +6 -6
  228. package/dist/operators/index.d.ts +6 -6
  229. package/dist/operators/index.js +9 -8
  230. package/dist/orchestration/index.cjs +8664 -2617
  231. package/dist/orchestration/index.cjs.map +1 -1
  232. package/dist/orchestration/index.d.cts +171 -221
  233. package/dist/orchestration/index.d.ts +171 -221
  234. package/dist/orchestration/index.js +74 -982
  235. package/dist/orchestration/index.js.map +1 -1
  236. package/dist/orchestration/messaging.cjs +314 -0
  237. package/dist/orchestration/messaging.cjs.map +1 -0
  238. package/dist/orchestration/messaging.d.cts +56 -0
  239. package/dist/orchestration/messaging.d.ts +56 -0
  240. package/dist/orchestration/messaging.js +276 -0
  241. package/dist/orchestration/messaging.js.map +1 -0
  242. package/dist/orchestration/work-queue.cjs +1500 -0
  243. package/dist/orchestration/work-queue.cjs.map +1 -0
  244. package/dist/orchestration/work-queue.d.cts +196 -0
  245. package/dist/orchestration/work-queue.d.ts +196 -0
  246. package/dist/orchestration/work-queue.js +1289 -0
  247. package/dist/orchestration/work-queue.js.map +1 -0
  248. package/dist/patterns/event-flow.cjs +433 -0
  249. package/dist/patterns/event-flow.cjs.map +1 -0
  250. package/dist/patterns/event-flow.d.cts +115 -0
  251. package/dist/patterns/event-flow.d.ts +115 -0
  252. package/dist/patterns/event-flow.js +14 -0
  253. package/dist/patterns/event-flow.js.map +1 -0
  254. package/dist/patterns/index.cjs +748 -355
  255. package/dist/patterns/index.cjs.map +1 -1
  256. package/dist/patterns/index.d.cts +9 -5
  257. package/dist/patterns/index.d.ts +9 -5
  258. package/dist/patterns/index.js +13 -4
  259. package/dist/process-types-C9uMYz3i.d.ts +200 -0
  260. package/dist/process-types-h3uRlzDc.d.cts +200 -0
  261. package/dist/{reactive-collection-BxBqtIOE.d.cts → reactive-collection-B9R0Bl1P.d.cts} +11 -41
  262. package/dist/{reactive-collection-Cb1II1Fi.d.ts → reactive-collection-BXFrH0U2.d.ts} +11 -41
  263. package/dist/{reactive-collection-storage-D-KmjE0J.d.cts → reactive-collection-storage-BLGv8Xp8.d.cts} +5 -5
  264. package/dist/{reactive-collection-storage-BNiEc-Gd.d.ts → reactive-collection-storage-a4zD3665.d.ts} +5 -5
  265. package/dist/{reactive-map-BcB4KsQR.d.ts → reactive-map-C_8sOfdS.d.cts} +7 -6
  266. package/dist/{reactive-map-D-g3dv8I.d.cts → reactive-map-jle5dnok.d.ts} +7 -6
  267. package/dist/render/index.d.cts +3 -3
  268. package/dist/render/index.d.ts +3 -3
  269. package/dist/render/index.js +1 -0
  270. package/dist/scheduled-readiness-5rwQlyjV.d.ts +91 -0
  271. package/dist/scheduled-readiness-DpRY8jI0.d.cts +91 -0
  272. package/dist/semantic-memory-graph-C2ZUwIlq.d.ts +30 -0
  273. package/dist/semantic-memory-graph-DlZBD_Eu.d.cts +30 -0
  274. package/dist/{semantic-memory-graph-BYoIlP35.d.cts → semantic-memory-graph-types-BvzdqmkY.d.cts} +2 -28
  275. package/dist/{semantic-memory-graph-CxyXLms3.d.ts → semantic-memory-graph-types-Ci-OtahO.d.ts} +2 -28
  276. package/dist/solutions/index.cjs +6788 -2128
  277. package/dist/solutions/index.cjs.map +1 -1
  278. package/dist/solutions/index.d.cts +15 -519
  279. package/dist/solutions/index.d.ts +15 -519
  280. package/dist/solutions/index.js +91 -7
  281. package/dist/solutions/reactive-layout/browser/index.cjs +457 -0
  282. package/dist/solutions/reactive-layout/browser/index.cjs.map +1 -0
  283. package/dist/solutions/reactive-layout/browser/index.d.cts +44 -0
  284. package/dist/solutions/reactive-layout/browser/index.d.ts +44 -0
  285. package/dist/solutions/reactive-layout/browser/index.js +69 -0
  286. package/dist/solutions/reactive-layout/browser/index.js.map +1 -0
  287. package/dist/solutions/reactive-layout/index.cjs +4494 -0
  288. package/dist/solutions/reactive-layout/index.cjs.map +1 -0
  289. package/dist/solutions/reactive-layout/index.d.cts +37 -0
  290. package/dist/solutions/reactive-layout/index.d.ts +37 -0
  291. package/dist/solutions/reactive-layout/index.js +146 -0
  292. package/dist/solutions/reactive-layout/index.js.map +1 -0
  293. package/dist/solutions/reactive-layout/node-canvas/index.cjs +555 -0
  294. package/dist/solutions/reactive-layout/node-canvas/index.cjs.map +1 -0
  295. package/dist/solutions/reactive-layout/node-canvas/index.d.cts +54 -0
  296. package/dist/solutions/reactive-layout/node-canvas/index.d.ts +54 -0
  297. package/dist/solutions/reactive-layout/node-canvas/index.js +131 -0
  298. package/dist/solutions/reactive-layout/node-canvas/index.js.map +1 -0
  299. package/dist/solutions/reactive-layout/react-native/index.cjs +504 -0
  300. package/dist/solutions/reactive-layout/react-native/index.cjs.map +1 -0
  301. package/dist/solutions/reactive-layout/react-native/index.d.cts +51 -0
  302. package/dist/solutions/reactive-layout/react-native/index.d.ts +51 -0
  303. package/dist/solutions/reactive-layout/react-native/index.js +77 -0
  304. package/dist/solutions/reactive-layout/react-native/index.js.map +1 -0
  305. package/dist/solutions/reactive-layout/skia/index.cjs +557 -0
  306. package/dist/solutions/reactive-layout/skia/index.cjs.map +1 -0
  307. package/dist/solutions/reactive-layout/skia/index.d.cts +64 -0
  308. package/dist/solutions/reactive-layout/skia/index.d.ts +64 -0
  309. package/dist/solutions/reactive-layout/skia/index.js +70 -0
  310. package/dist/solutions/reactive-layout/skia/index.js.map +1 -0
  311. package/dist/solutions/work-item/actions.cjs +2345 -0
  312. package/dist/solutions/work-item/actions.cjs.map +1 -0
  313. package/dist/solutions/work-item/actions.d.cts +40 -0
  314. package/dist/solutions/work-item/actions.d.ts +40 -0
  315. package/dist/solutions/work-item/actions.js +2078 -0
  316. package/dist/solutions/work-item/actions.js.map +1 -0
  317. package/dist/solutions/work-item/scheduling.cjs +9797 -0
  318. package/dist/solutions/work-item/scheduling.cjs.map +1 -0
  319. package/dist/solutions/work-item/scheduling.d.cts +1868 -0
  320. package/dist/solutions/work-item/scheduling.d.ts +1868 -0
  321. package/dist/solutions/work-item/scheduling.js +146 -0
  322. package/dist/solutions/work-item/scheduling.js.map +1 -0
  323. package/dist/solutions/work-item/work-queue.cjs +306 -0
  324. package/dist/solutions/work-item/work-queue.cjs.map +1 -0
  325. package/dist/solutions/work-item/work-queue.d.cts +71 -0
  326. package/dist/solutions/work-item/work-queue.d.ts +71 -0
  327. package/dist/solutions/work-item/work-queue.js +270 -0
  328. package/dist/solutions/work-item/work-queue.js.map +1 -0
  329. package/dist/sources/browser.cjs +1399 -1052
  330. package/dist/sources/browser.cjs.map +1 -1
  331. package/dist/sources/browser.d.cts +33 -6
  332. package/dist/sources/browser.d.ts +33 -6
  333. package/dist/sources/browser.js +73 -6
  334. package/dist/sources/browser.js.map +1 -1
  335. package/dist/sources/index.cjs +1345 -1065
  336. package/dist/sources/index.cjs.map +1 -1
  337. package/dist/sources/index.d.cts +5 -5
  338. package/dist/sources/index.d.ts +5 -5
  339. package/dist/sources/index.js +7 -6
  340. package/dist/sources/node.cjs.map +1 -1
  341. package/dist/sources/node.d.cts +4 -4
  342. package/dist/sources/node.d.ts +4 -4
  343. package/dist/sources/node.js +2 -1
  344. package/dist/sources/node.js.map +1 -1
  345. package/dist/storage/browser.cjs +16 -0
  346. package/dist/storage/browser.cjs.map +1 -1
  347. package/dist/storage/browser.js +4 -3
  348. package/dist/storage/browser.js.map +1 -1
  349. package/dist/storage/index.cjs +16 -0
  350. package/dist/storage/index.cjs.map +1 -1
  351. package/dist/storage/index.d.cts +6 -5
  352. package/dist/storage/index.d.ts +6 -5
  353. package/dist/storage/index.js +10 -9
  354. package/dist/storage/node.cjs +16 -0
  355. package/dist/storage/node.cjs.map +1 -1
  356. package/dist/storage/node.js +4 -3
  357. package/dist/storage/node.js.map +1 -1
  358. package/dist/store-BmtEs9mG.d.ts +123 -0
  359. package/dist/store-PAAsYvML.d.cts +123 -0
  360. package/dist/testing/index.cjs +1 -0
  361. package/dist/testing/index.cjs.map +1 -1
  362. package/dist/testing/index.d.cts +1 -1
  363. package/dist/testing/index.d.ts +1 -1
  364. package/dist/testing/index.js +3 -2
  365. package/dist/types-BRNKoFHj.d.ts +357 -0
  366. package/dist/{types-h12mNYbq.d.ts → types-BS6CyR-x.d.cts} +49 -130
  367. package/dist/types-BWK2ay3e.d.cts +457 -0
  368. package/dist/types-BXKSAoE1.d.cts +357 -0
  369. package/dist/types-BaPpZItj.d.ts +457 -0
  370. package/dist/types-BhveCMg5.d.cts +274 -0
  371. package/dist/{types-bNMSWKqF.d.cts → types-C9NOgNJw.d.ts} +49 -130
  372. package/dist/types-CTsQ8Ww4.d.ts +274 -0
  373. package/dist/types-DL_05n2M.d.ts +34 -0
  374. package/dist/types-XDoqxYO9.d.cts +34 -0
  375. package/dist/work-item-runtime-types-BqtWnSCS.d.ts +138 -0
  376. package/dist/work-item-runtime-types-CHO03AKh.d.cts +138 -0
  377. package/dist/work-queue/index.cjs +1136 -0
  378. package/dist/work-queue/index.cjs.map +1 -0
  379. package/dist/work-queue/index.d.cts +21 -0
  380. package/dist/work-queue/index.d.ts +21 -0
  381. package/dist/work-queue/index.js +1082 -0
  382. package/dist/work-queue/index.js.map +1 -0
  383. package/package.json +603 -249
  384. package/dist/chunk-2ILL7HQI.js.map +0 -1
  385. package/dist/chunk-4VLAQHZI.js.map +0 -1
  386. package/dist/chunk-COHO25CZ.js.map +0 -1
  387. package/dist/chunk-DK554R7P.js.map +0 -1
  388. package/dist/chunk-G4M3NHRJ.js.map +0 -1
  389. package/dist/chunk-I3IHOHCJ.js.map +0 -1
  390. package/dist/chunk-JIMUDQN3.js.map +0 -1
  391. package/dist/chunk-RIIOUTGM.js.map +0 -1
  392. package/dist/chunk-SWTLEQL6.js.map +0 -1
  393. /package/dist/{chunk-GDL26N2T.js.map → chunk-3KN7NJDR.js.map} +0 -0
  394. /package/dist/{chunk-Z2ANQ6JW.js.map → chunk-4Q77MMJY.js.map} +0 -0
  395. /package/dist/{chunk-D6BG7U6A.js.map → chunk-7HZRJMN6.js.map} +0 -0
  396. /package/dist/{chunk-SCRFRCGR.js.map → chunk-BSQGE5PS.js.map} +0 -0
  397. /package/dist/{chunk-PKVBHGBM.js.map → chunk-CJIFGJQG.js.map} +0 -0
  398. /package/dist/{chunk-K3FXTC3I.js.map → chunk-HJACH5PU.js.map} +0 -0
  399. /package/dist/{chunk-GTPCOEOZ.js.map → chunk-IDMLXLLG.js.map} +0 -0
  400. /package/dist/{chunk-DKP56CSW.js.map → chunk-JKAYLDQV.js.map} +0 -0
  401. /package/dist/{chunk-Y3ZLRGHC.js.map → chunk-SIDJO2T4.js.map} +0 -0
  402. /package/dist/{chunk-JR4IKCR2.js.map → chunk-TPND5MJS.js.map} +0 -0
  403. /package/dist/{chunk-TEW47IVR.js.map → chunk-VPEFSDME.js.map} +0 -0
  404. /package/dist/{chunk-DJC4CHLQ.js.map → chunk-YDWBXXQZ.js.map} +0 -0
  405. /package/dist/{chunk-6PHB5CJS.js.map → chunk-ZLFRB6FI.js.map} +0 -0
@@ -46,6 +46,7 @@ var TIER = {
46
46
  START: TIER_START,
47
47
  PAUSE: TIER_CONTROL,
48
48
  RESUME: TIER_CONTROL,
49
+ PULL: TIER_CONTROL,
49
50
  DIRTY: TIER_NOTIFICATION,
50
51
  DATA: TIER_VALUE,
51
52
  RESOLVED: TIER_VALUE,
@@ -154,30 +155,6 @@ function drain() {
154
155
  if (escaped !== null) throw escaped.e;
155
156
  }
156
157
 
157
- // src/batch/batch.ts
158
- var active = null;
159
- var boundaryOwner = null;
160
- function currentBatch() {
161
- return active !== null;
162
- }
163
- function currentBoundaryBatchToken() {
164
- return active ?? boundaryOwner ?? void 0;
165
- }
166
- function deferToBatch(target, tier3Wave) {
167
- if (active === null) return false;
168
- if (!active.deferred.has(target)) active.order.push(target);
169
- active.deferred.set(target, tier3Wave);
170
- return true;
171
- }
172
- function deferAfterBatchForTarget(target, fn) {
173
- if (active === null || !active.deferred.has(target)) return false;
174
- const owner = active;
175
- target.__deferBoundary(() => {
176
- if (owner.committed) fn();
177
- }, owner);
178
- return true;
179
- }
180
-
181
158
  // src/dispatcher/index.ts
182
159
  var PoolTable = class {
183
160
  constructor(kind) {
@@ -484,6 +461,586 @@ function makeDepBookkeeping(depCount) {
484
461
  };
485
462
  }
486
463
 
464
+ // src/node/protocol-guards.ts
465
+ function terminalView(t) {
466
+ return t === void 0 ? false : t;
467
+ }
468
+ function normalizePullDemand(demand) {
469
+ if (typeof demand !== "object" || demand === null || Array.isArray(demand)) {
470
+ throw new Error("ctx.up: PULL requires { pullId, params? } demand payload (D269)");
471
+ }
472
+ const pullId = demand.pullId;
473
+ if (typeof pullId !== "string" && typeof pullId !== "symbol") {
474
+ throw new Error("ctx.up: PULL demand requires a string or symbol pullId (D269)");
475
+ }
476
+ const params = demand.params;
477
+ return params === void 0 ? { pullId } : { pullId, params };
478
+ }
479
+ function validateDownPayloads(msgs) {
480
+ for (const m of msgs) {
481
+ if (m[0] === "DATA" && m[1] === void 0) {
482
+ throw new Error("down: DATA requires a non-SENTINEL payload (R-data-payload)");
483
+ }
484
+ if (m[0] === "ERROR" && isInvalidErrorPayload(m[1])) {
485
+ throw new Error("down: ERROR requires a non-SENTINEL, non-boolean payload (R-data-payload)");
486
+ }
487
+ }
488
+ }
489
+
490
+ // src/node/runtime-accessors.ts
491
+ var constructingCore;
492
+ var constructingEnvironment;
493
+ var ownerTokens = /* @__PURE__ */ new WeakMap();
494
+ var topologyDepsChangedObservers = /* @__PURE__ */ new WeakMap();
495
+ var checkpointReaders = /* @__PURE__ */ new WeakMap();
496
+ var restoreWriters = /* @__PURE__ */ new WeakMap();
497
+ var runtimeReleasers = /* @__PURE__ */ new WeakMap();
498
+ var runtimeQuiescenceReaders = /* @__PURE__ */ new WeakMap();
499
+ var subscriberCountReaders = /* @__PURE__ */ new WeakMap();
500
+ var activationReaders = /* @__PURE__ */ new WeakMap();
501
+ var releasedNodes = /* @__PURE__ */ new WeakSet();
502
+ function withNodeCore(core, create) {
503
+ const prev = constructingCore;
504
+ constructingCore = core;
505
+ try {
506
+ return create();
507
+ } finally {
508
+ constructingCore = prev;
509
+ }
510
+ }
511
+ function takeConstructingNodeCore() {
512
+ const core = constructingCore;
513
+ constructingCore = void 0;
514
+ return core;
515
+ }
516
+ function withEnvironmentDrivers(environment, create) {
517
+ const prev = constructingEnvironment;
518
+ constructingEnvironment = environment;
519
+ try {
520
+ return create();
521
+ } finally {
522
+ constructingEnvironment = prev;
523
+ }
524
+ }
525
+ function takeConstructingEnvironmentDrivers() {
526
+ const environment = constructingEnvironment;
527
+ constructingEnvironment = void 0;
528
+ return environment;
529
+ }
530
+ function getNodeOwner(n) {
531
+ return ownerTokens.get(n);
532
+ }
533
+ function notifyTopologyDepsChanged(node, prevDeps, deps) {
534
+ topologyDepsChangedObservers.get(node)?.(node, prevDeps, deps);
535
+ }
536
+
537
+ // src/node/node-context-runtime.ts
538
+ function nodeBuildCtx(self) {
539
+ const kind = self._slot.handle ? self._slot.dispatcher.poolKind(self._slot.handle.poolId) : "sync";
540
+ if (kind === "sync") {
541
+ if (self._syncCtx === null) self._syncCtx = self._makeCtx();
542
+ self._refreshCtx(self._syncCtx);
543
+ return self._syncCtx;
544
+ }
545
+ return self._makeCtx({
546
+ waveData: self._dep.waveData.map((waves) => waves.map((w) => [...w])),
547
+ terminal: self._dep.terminalInput.map(terminalView),
548
+ latest: [...self._dep.prev]
549
+ });
550
+ }
551
+ function nodeMakeCtx(self, snapshot) {
552
+ const ctx = {
553
+ // Wave-owner boundary (D47): a SYNC fn's emit nests under the public entry that drove
554
+ // it (cheap inc/dec, no early drain); an ASYNC-pool fn re-enters here from its stashed
555
+ // ctx at depth 0, so this is the boundary that drains any rewireNext it issued.
556
+ up: (msgs, towardDep) => {
557
+ if (self._released) return;
558
+ enterWave();
559
+ try {
560
+ self._up(msgs, towardDep);
561
+ } finally {
562
+ exitWave();
563
+ }
564
+ },
565
+ down: (msgs) => {
566
+ if (self._released) return;
567
+ enterWave();
568
+ try {
569
+ self._down(msgs);
570
+ } finally {
571
+ exitWave();
572
+ }
573
+ },
574
+ waveData: snapshot?.waveData ?? self._dep.waveData,
575
+ terminal: snapshot?.terminal ?? self._dep.terminalInput.map(terminalView),
576
+ state: self._makeState(),
577
+ onDeactivation: (fn) => {
578
+ if (self._released) return;
579
+ self._hooks.onDeactivation.push(fn);
580
+ },
581
+ onInvalidate: (fn) => {
582
+ if (self._released) return;
583
+ self._hooks.onInvalidate.push(fn);
584
+ },
585
+ environment: () => self._slot.environment,
586
+ // R-rewire-deferred (D47): defer a self-dep-set mutation to the committed boundary.
587
+ rewireNext: {
588
+ subscribeDep: (dep, fn) => self._requestRewireNext({ kind: "add", dep, fn }),
589
+ unsubscribeDep: (dep, fn) => self._requestRewireNext({ kind: "remove", dep, fn }),
590
+ replaceDeps: (deps, fn) => self._requestRewireNext({ kind: "set", deps, fn })
591
+ },
592
+ // R-up-routing / R-pull (D269): deferred up — route a control/demand wave (e.g. PULL)
593
+ // up the declared cone at the committed boundary. The SELF-demand path: an
594
+ // immediate ctx.up whose delivery loops back re-enters this fn (D37 / R-reentrancy).
595
+ upNext: (msgs, towardDep) => self._requestUpNext(msgs, towardDep),
596
+ ...self._control.activePull === void 0 ? {} : { pull: self._control.activePull },
597
+ [CTX_DEP_CACHE]: { latest: snapshot?.latest ?? self._dep.prev },
598
+ [CTX_NODE_BINDING]: {
599
+ dispatcher: self._slot.dispatcher,
600
+ create: (factory) => withEnvironmentDrivers(self._slot.environment, () => withNodeCore(self._core, factory))
601
+ }
602
+ };
603
+ if (self._slot.dynamic) {
604
+ ctx.track = (i) => ctx[CTX_DEP_CACHE]?.latest[i];
605
+ }
606
+ return ctx;
607
+ }
608
+ function nodeRefreshCtx(self, ctx) {
609
+ ctx.waveData = self._dep.waveData;
610
+ ctx.terminal = self._dep.terminalInput.map(terminalView);
611
+ if (self._control.activePull === void 0) {
612
+ delete ctx.pull;
613
+ } else {
614
+ ctx.pull = self._control.activePull;
615
+ }
616
+ ctx[CTX_DEP_CACHE] = { latest: self._dep.prev };
617
+ }
618
+ function nodeMakeState(self) {
619
+ return {
620
+ get: () => self._privateState.value,
621
+ set: (v) => {
622
+ self._privateState.value = v;
623
+ },
624
+ persist: (on = true) => {
625
+ self._privateState.persist = on;
626
+ }
627
+ };
628
+ }
629
+
630
+ // src/node/node-input-runtime.ts
631
+ function nodeRecordDepProjection(self, idx, delivery) {
632
+ const token = delivery?.wave ?? {};
633
+ if (self._dep.waveTokens[idx] !== token) {
634
+ self._dep.waveData[idx].push([]);
635
+ self._dep.waveTokens[idx] = token;
636
+ }
637
+ return self._dep.waveData[idx][self._dep.waveData[idx].length - 1];
638
+ }
639
+ function nodeDepProjectionHasData(self, idx) {
640
+ const projection = self._dep.waveData[idx][self._dep.waveData[idx].length - 1];
641
+ return projection?.some((v) => v !== SENTINEL) ?? false;
642
+ }
643
+ function nodeReceiveFromDep(self, idx, msg, delivery) {
644
+ if (self._released) return;
645
+ const t = msg[0];
646
+ if (t === "START") return;
647
+ const isLastInDeliveredWave = delivery?.last ?? true;
648
+ if (self._value.terminal !== void 0) {
649
+ if (t === "TEARDOWN") self._down([["TEARDOWN"]]);
650
+ return;
651
+ }
652
+ if (t === "INVALIDATE") {
653
+ const projection = self._recordDepProjection(idx, delivery);
654
+ projection.push(SENTINEL);
655
+ if (projection.some((v) => v !== SENTINEL) && isLastInDeliveredWave) self._maybeRun();
656
+ self._dep.prev[idx] = SENTINEL;
657
+ self._dep.hasData[idx] = false;
658
+ self._dep.batch[idx] = null;
659
+ if (self._dep.dirty[idx]) {
660
+ self._dep.dirty[idx] = false;
661
+ self._wave.pending--;
662
+ }
663
+ if (self._control.pausedDepWaveOccurred && self._dep.batch.every((b) => b === null)) {
664
+ self._control.pausedDepWaveOccurred = false;
665
+ }
666
+ const hadData = self._value.hasData;
667
+ self._invalidate();
668
+ if (self._wave.pending === 0 && self._wave.emittedDirtyThisWave) {
669
+ if (!hadData) self._down([["RESOLVED"]]);
670
+ else self._wave.emittedDirtyThisWave = false;
671
+ }
672
+ self._fireOwedDemandIfReady();
673
+ return;
674
+ }
675
+ if (isTerminal(t)) {
676
+ const isError = t === "ERROR";
677
+ const errPayload = isError ? msg[1] : void 0;
678
+ self._dep.terminal[idx] = isError ? errPayload : true;
679
+ self._dep.terminalInput[idx] = isError ? errPayload : true;
680
+ self._releaseDepDirty(idx);
681
+ const ranValueBeforeTerminal = self._depProjectionHasData(idx) && isLastInDeliveredWave;
682
+ if (ranValueBeforeTerminal) self._maybeRun();
683
+ if (isError && self._slot.errorWhenDepsError) {
684
+ self._down([["ERROR", errPayload]]);
685
+ } else if (self._slot.terminalAsRealInput) {
686
+ if (ranValueBeforeTerminal) {
687
+ self._fireOwedDemandIfReady();
688
+ return;
689
+ }
690
+ self._maybeRun();
691
+ } else if (self._slot.completeWhenDepsComplete && self._allDepsTerminal()) {
692
+ self._down([["COMPLETE"]]);
693
+ } else {
694
+ self._settleAfterAbsorbedTerminal();
695
+ }
696
+ self._fireOwedDemandIfReady();
697
+ return;
698
+ }
699
+ if (t === "TEARDOWN") {
700
+ self._down([["TEARDOWN"]]);
701
+ return;
702
+ }
703
+ if (t === "DIRTY") {
704
+ if (!self._dep.dirty[idx]) {
705
+ self._dep.dirty[idx] = true;
706
+ self._wave.pending++;
707
+ self._dep.tier[idx] = 2;
708
+ self._markDirty();
709
+ }
710
+ return;
711
+ }
712
+ if (t === "DATA") {
713
+ const v = msg[1];
714
+ self._recordDepProjection(idx, delivery).push(v);
715
+ const b = self._dep.batch[idx];
716
+ if (b === null) self._dep.batch[idx] = [v];
717
+ else b.push(v);
718
+ self._dep.prev[idx] = v;
719
+ self._dep.hasData[idx] = true;
720
+ self._dep.tier[idx] = 3;
721
+ if (self._dep.dirty[idx]) {
722
+ self._dep.dirty[idx] = false;
723
+ self._wave.pending--;
724
+ }
725
+ if (isLastInDeliveredWave) self._maybeRun();
726
+ self._fireOwedDemandIfReady();
727
+ return;
728
+ }
729
+ if (t === "RESOLVED") {
730
+ self._recordDepProjection(idx, delivery);
731
+ self._dep.tier[idx] = 3;
732
+ if (self._dep.dirty[idx]) {
733
+ self._dep.dirty[idx] = false;
734
+ self._wave.pending--;
735
+ }
736
+ if (isLastInDeliveredWave) self._maybeRun();
737
+ self._fireOwedDemandIfReady();
738
+ return;
739
+ }
740
+ }
741
+ function nodeReleaseDepDirty(self, idx) {
742
+ if (self._dep.dirty[idx]) {
743
+ self._dep.dirty[idx] = false;
744
+ self._wave.pending--;
745
+ }
746
+ }
747
+ function nodeSettleAfterAbsorbedTerminal(self) {
748
+ if (self._wave.pending !== 0 || !self._wave.emittedDirtyThisWave) return;
749
+ const sawData = self._dep.batch.some((b) => b !== null && b.length > 0);
750
+ if (sawData) self._maybeRun();
751
+ if (self._wave.emittedDirtyThisWave) self._down([["RESOLVED"]]);
752
+ }
753
+ function nodeMarkDirty(self) {
754
+ self._value.status = "dirty";
755
+ if (self._isPullQuiet()) return;
756
+ if (!self._wave.emittedDirtyThisWave) {
757
+ self._wave.emittedDirtyThisWave = true;
758
+ self._emitToSubs(["DIRTY"]);
759
+ }
760
+ }
761
+ function nodeMaybeRun(self) {
762
+ if (self._wave.inDepMutation) {
763
+ self._wave.rewireRunPending = true;
764
+ return;
765
+ }
766
+ if (self._slot.pausable === true && (self._isPaused() || self._isPullQuiet())) {
767
+ self._control.pausedDepWaveOccurred = true;
768
+ return;
769
+ }
770
+ self._tryRun();
771
+ }
772
+ function nodeSettleRewire(self) {
773
+ if (self._slot.pausable === true && self._isPaused()) {
774
+ self._control.pausedDepWaveOccurred = true;
775
+ return;
776
+ }
777
+ if (self._wave.pending > 0) return;
778
+ if (self._slot.handle === null) {
779
+ self._passthroughEmit();
780
+ return;
781
+ }
782
+ if (!self._wave.hasCalledFnOnce && !(self._slot.partial || self._allDepsSettled())) return;
783
+ self._markDirty();
784
+ self._runWave();
785
+ }
786
+ function nodeTryRun(self) {
787
+ if (self._wave.pending > 0) return;
788
+ if (self._slot.handle === null) {
789
+ self._passthroughEmit();
790
+ return;
791
+ }
792
+ if (!self._wave.hasCalledFnOnce) {
793
+ if (self._slot.partial || self._allDepsSettled()) self._runWave();
794
+ return;
795
+ }
796
+ self._runWave();
797
+ }
798
+ function nodeAllDepsSettled(self) {
799
+ for (let i = 0; i < self._slot.deps.length; i++) {
800
+ if (self._dep.hasData[i]) continue;
801
+ if (self._slot.terminalAsRealInput && self._dep.terminal[i] !== void 0) continue;
802
+ return false;
803
+ }
804
+ return true;
805
+ }
806
+ function nodePassthroughEmit(self) {
807
+ const b = self._dep.batch[0];
808
+ if (b !== null && b.length > 0) {
809
+ self._down([["DATA", b[b.length - 1]]]);
810
+ } else if (self._wave.emittedDirtyThisWave) {
811
+ self._down([["RESOLVED"]]);
812
+ }
813
+ self._dep.batch[0] = null;
814
+ self._wave.emittedDirtyThisWave = false;
815
+ }
816
+ function nodeRunWave(self) {
817
+ if (self._wave.insideRunWave)
818
+ throw new Error(
819
+ "synchronous feedback cycle: node fn re-entered its own wave (R-reentrancy / D37)"
820
+ );
821
+ self._wave.hasCalledFnOnce = true;
822
+ self._hooks.onInvalidate = [];
823
+ self._hooks.onDeactivation = [];
824
+ const ctx = self._buildCtx();
825
+ const wasDirty = self._wave.emittedDirtyThisWave;
826
+ self._wave.emittedSettleThisWave = false;
827
+ self._wave.insideRunWave = true;
828
+ try {
829
+ self._slot.dispatcher.invoke(self._slot.handle, ctx);
830
+ } finally {
831
+ self._wave.insideRunWave = false;
832
+ }
833
+ if (wasDirty && !self._wave.emittedSettleThisWave && self._value.terminal === void 0 && !self._isAsyncPool()) {
834
+ self._down([["RESOLVED"]]);
835
+ }
836
+ for (let i = 0; i < self._dep.batch.length; i++) {
837
+ self._dep.batch[i] = null;
838
+ self._dep.waveData[i] = [];
839
+ self._dep.waveTokens[i] = void 0;
840
+ self._dep.terminalInput[i] = void 0;
841
+ }
842
+ self._wave.emittedDirtyThisWave = false;
843
+ }
844
+
845
+ // src/node/node-runtime-host.ts
846
+ function nodeRuntimeHost(node) {
847
+ return node;
848
+ }
849
+
850
+ // src/node/node-lifecycle-runtime.ts
851
+ function nodeActivate(self) {
852
+ self._lifecycle.activated = true;
853
+ const seedRestoredDeps = self._restoredActivationPending;
854
+ self._restoredActivationPending = false;
855
+ self._dep.unsubs = new Array(self._slot.deps.length);
856
+ self._dep.idxBoxes = new Array(self._slot.deps.length);
857
+ for (const dep of self._slot.deps) self._subscribeDepAt(dep, { seedRestored: seedRestoredDeps });
858
+ if (self._slot.deps.length === 0 && self._slot.handle !== null && !self._wave.hasCalledFnOnce) {
859
+ self._runWave();
860
+ }
861
+ }
862
+ function nodeSubscribeDepAt(self, depNode, opts = {}) {
863
+ const idx0 = self._slot.deps.indexOf(depNode);
864
+ const box = { v: idx0 };
865
+ let ignoreInitialPush = opts.seedRestored === true;
866
+ if (ignoreInitialPush && idx0 !== -1) {
867
+ self._seedRestoredDepAt(idx0, depNode);
868
+ const dep = nodeRuntimeHost(depNode);
869
+ if (dep._value.terminal !== void 0 && !dep._slot.resubscribable) {
870
+ self._dep.unsubs[idx0] = () => {
871
+ };
872
+ self._dep.idxBoxes[idx0] = box;
873
+ return;
874
+ }
875
+ }
876
+ const unsub = depNode.subscribe((msg, delivery) => {
877
+ if (ignoreInitialPush && delivery === void 0) return;
878
+ if (ignoreInitialPush) ignoreInitialPush = false;
879
+ if (box.v === -1) return;
880
+ self._receiveFromDep(box.v, msg, delivery);
881
+ });
882
+ if (ignoreInitialPush && idx0 !== -1 && box.v !== -1) self._seedRestoredDepAt(idx0, depNode);
883
+ ignoreInitialPush = false;
884
+ if (idx0 !== -1) {
885
+ self._dep.unsubs[idx0] = unsub;
886
+ self._dep.idxBoxes[idx0] = box;
887
+ }
888
+ }
889
+ function nodeSeedRestoredDepAt(self, idx, depNode) {
890
+ const dep = nodeRuntimeHost(depNode);
891
+ const seedData = dep._value.hasData && !dep._slot.pull;
892
+ self._dep.batch[idx] = null;
893
+ self._dep.waveData[idx] = [];
894
+ self._dep.waveTokens[idx] = void 0;
895
+ self._dep.prev[idx] = seedData ? dep._value.cache : SENTINEL;
896
+ self._dep.hasData[idx] = seedData;
897
+ self._dep.dirty[idx] = false;
898
+ self._dep.tier[idx] = seedData ? 3 : 0;
899
+ self._dep.terminal[idx] = dep._value.terminal;
900
+ self._dep.terminalInput[idx] = void 0;
901
+ }
902
+ function nodeDeactivate(self) {
903
+ self._lifecycle.activated = false;
904
+ for (const u of self._dep.unsubs) if (u) u();
905
+ self._dep.unsubs = [];
906
+ self._dep.idxBoxes = [];
907
+ for (const fn of self._hooks.onDeactivation) fn();
908
+ self._hooks.onDeactivation = [];
909
+ self._hooks.onInvalidate = [];
910
+ const isCompute = self._slot.handle !== null || self._slot.deps.length > 0;
911
+ if (isCompute) {
912
+ self._value.cache = SENTINEL;
913
+ self._value.hasData = false;
914
+ self._value.status = "sentinel";
915
+ }
916
+ self._resetDepState();
917
+ self._wave.hasCalledFnOnce = false;
918
+ self._control.pauseLockset.clear();
919
+ self._control.pauseBuffer = [];
920
+ self._control.pausedDepWaveOccurred = false;
921
+ self._control.demandOwed = void 0;
922
+ self._control.activePull = void 0;
923
+ self._control.pullDirtyOwed = false;
924
+ self._value.replayRing = [];
925
+ if (!self._privateState.persist) self._privateState.value = SENTINEL;
926
+ }
927
+ function nodeSubscriberCount(self) {
928
+ return self._lifecycle.subscribers.size;
929
+ }
930
+ function nodeIsRuntimeQuiescentForRelease(self) {
931
+ 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;
932
+ }
933
+ function nodeReleaseRuntime(self) {
934
+ if (self._released) return;
935
+ self._released = true;
936
+ const node = self;
937
+ releasedNodes.add(node);
938
+ let releaseError;
939
+ const recordReleaseError = (error) => {
940
+ if (releaseError === void 0) releaseError = error;
941
+ };
942
+ self._lifecycle.activated = false;
943
+ for (const u of self._dep.unsubs) {
944
+ try {
945
+ u();
946
+ } catch (error) {
947
+ recordReleaseError(error);
948
+ }
949
+ }
950
+ for (const fn of self._hooks.onDeactivation) {
951
+ try {
952
+ fn();
953
+ } catch (error) {
954
+ recordReleaseError(error);
955
+ }
956
+ }
957
+ self._dep.unsubs = [];
958
+ self._dep.idxBoxes = [];
959
+ self._lifecycle.subscribers.clear();
960
+ if (self._slot.handle !== null) {
961
+ self._slot.dispatcher.unregister(self._slot.handle);
962
+ self._slot.handle = null;
963
+ }
964
+ self._slot.deps = [];
965
+ self._dep.batch = [];
966
+ self._dep.waveData = [];
967
+ self._dep.waveTokens = [];
968
+ self._dep.prev = [];
969
+ self._dep.hasData = [];
970
+ self._dep.dirty = [];
971
+ self._dep.tier = [];
972
+ self._dep.terminal = [];
973
+ self._dep.terminalInput = [];
974
+ self._value.cache = SENTINEL;
975
+ self._value.hasData = false;
976
+ self._value.status = "sentinel";
977
+ self._value.terminal = void 0;
978
+ self._value.replayRing = [];
979
+ self._privateState.value = SENTINEL;
980
+ self._privateState.persist = false;
981
+ self._syncCtx = null;
982
+ self._resetDepState();
983
+ self._hooks.onDeactivation = [];
984
+ self._hooks.onInvalidate = [];
985
+ self._control.pauseLockset.clear();
986
+ self._control.pauseBuffer = [];
987
+ self._control.pausedDepWaveOccurred = false;
988
+ self._control.demandOwed = void 0;
989
+ self._control.activePull = void 0;
990
+ self._control.pullDirtyOwed = false;
991
+ self._restoredActivationPending = false;
992
+ checkpointReaders.delete(node);
993
+ restoreWriters.delete(node);
994
+ runtimeReleasers.delete(node);
995
+ runtimeQuiescenceReaders.delete(node);
996
+ subscriberCountReaders.delete(node);
997
+ activationReaders.delete(node);
998
+ ownerTokens.delete(node);
999
+ topologyDepsChangedObservers.delete(node);
1000
+ self._core.releaseSlot(self._id);
1001
+ if (releaseError !== void 0) throw releaseError;
1002
+ }
1003
+ function nodeResetDepState(self) {
1004
+ const n = self._slot.deps.length;
1005
+ for (let i = 0; i < n; i++) {
1006
+ self._dep.batch[i] = null;
1007
+ self._dep.waveData[i] = [];
1008
+ self._dep.waveTokens[i] = void 0;
1009
+ self._dep.prev[i] = SENTINEL;
1010
+ self._dep.hasData[i] = false;
1011
+ self._dep.dirty[i] = false;
1012
+ self._dep.tier[i] = 0;
1013
+ self._dep.terminal[i] = void 0;
1014
+ self._dep.terminalInput[i] = void 0;
1015
+ }
1016
+ self._wave.pending = 0;
1017
+ self._wave.emittedDirtyThisWave = false;
1018
+ }
1019
+
1020
+ // src/batch/batch.ts
1021
+ var active = null;
1022
+ var boundaryOwner = null;
1023
+ function currentBatch() {
1024
+ return active !== null;
1025
+ }
1026
+ function currentBoundaryBatchToken() {
1027
+ return active ?? boundaryOwner ?? void 0;
1028
+ }
1029
+ function deferToBatch(target, tier3Wave) {
1030
+ if (active === null) return false;
1031
+ if (!active.deferred.has(target)) active.order.push(target);
1032
+ active.deferred.set(target, tier3Wave);
1033
+ return true;
1034
+ }
1035
+ function deferAfterBatchForTarget(target, fn) {
1036
+ if (active === null || !active.deferred.has(target)) return false;
1037
+ const owner = active;
1038
+ target.__deferBoundary(() => {
1039
+ if (owner.committed) fn();
1040
+ }, owner);
1041
+ return true;
1042
+ }
1043
+
487
1044
  // src/json/codec.ts
488
1045
  var JS_MIN_NORMAL_NUMBER = 2 ** -1022;
489
1046
  function assertStableJsonNumber(value, path) {
@@ -528,9 +1085,16 @@ function sortedJsonValue(value, seen = /* @__PURE__ */ new Set(), path = "$", st
528
1085
  }
529
1086
  for (const key of Object.getOwnPropertyNames(value)) {
530
1087
  const isIndex = /^(0|[1-9]\d*)$/.test(key) && Number.isSafeInteger(Number(key)) && Number(key) < value.length;
1088
+ const descriptor = Object.getOwnPropertyDescriptor(value, key);
1089
+ if (descriptor !== void 0 && ("get" in descriptor || "set" in descriptor)) {
1090
+ throw new TypeError(`stableJsonString: accessor property at ${path}.${key}`);
1091
+ }
531
1092
  if (key !== "length" && !isIndex) {
532
1093
  throw new TypeError(`stableJsonString: non-index array property at ${path}.${key}`);
533
1094
  }
1095
+ if (key !== "length" && descriptor !== void 0 && !descriptor.enumerable) {
1096
+ throw new TypeError(`stableJsonString: non-enumerable array property at ${path}.${key}`);
1097
+ }
534
1098
  }
535
1099
  const out2 = [];
536
1100
  for (let i = 0; i < value.length; i += 1) {
@@ -544,6 +1108,15 @@ function sortedJsonValue(value, seen = /* @__PURE__ */ new Set(), path = "$", st
544
1108
  if (Object.getOwnPropertySymbols(value).length > 0) {
545
1109
  throw new TypeError(`stableJsonString: symbol-keyed properties at ${path}`);
546
1110
  }
1111
+ for (const key of Object.getOwnPropertyNames(value)) {
1112
+ const descriptor = Object.getOwnPropertyDescriptor(value, key);
1113
+ if (descriptor !== void 0 && ("get" in descriptor || "set" in descriptor)) {
1114
+ throw new TypeError(`stableJsonString: accessor property at ${path}.${key}`);
1115
+ }
1116
+ if (descriptor !== void 0 && !descriptor.enumerable) {
1117
+ throw new TypeError(`stableJsonString: non-enumerable property at ${path}.${key}`);
1118
+ }
1119
+ }
547
1120
  const out = /* @__PURE__ */ Object.create(null);
548
1121
  for (const key of Object.keys(value).sort()) {
549
1122
  out[key] = sortedJsonValue(
@@ -866,61 +1439,537 @@ function restoredV1Cid(policy, hasData, cache) {
866
1439
  return computeV1Cid(policy, hasData ? cache : ABSENT_V1_SEED);
867
1440
  }
868
1441
 
869
- // src/node/node.ts
870
- var constructingCore;
871
- var constructingEnvironment;
872
- var ownerTokens = /* @__PURE__ */ new WeakMap();
873
- var topologyDepsChangedObservers = /* @__PURE__ */ new WeakMap();
874
- var checkpointReaders = /* @__PURE__ */ new WeakMap();
875
- var restoreWriters = /* @__PURE__ */ new WeakMap();
876
- var runtimeReleasers = /* @__PURE__ */ new WeakMap();
877
- var runtimeQuiescenceReaders = /* @__PURE__ */ new WeakMap();
878
- var subscriberCountReaders = /* @__PURE__ */ new WeakMap();
879
- var activationReaders = /* @__PURE__ */ new WeakMap();
880
- var releasedNodes = /* @__PURE__ */ new WeakSet();
881
- function withNodeCore(core, create) {
882
- const prev = constructingCore;
883
- constructingCore = core;
884
- try {
885
- return create();
886
- } finally {
887
- constructingCore = prev;
888
- }
889
- }
890
- function withEnvironmentDrivers(environment, create) {
891
- const prev = constructingEnvironment;
892
- constructingEnvironment = environment;
893
- try {
894
- return create();
895
- } finally {
896
- constructingEnvironment = prev;
1442
+ // src/node/node-output-runtime.ts
1443
+ function nodeDown(self, msgs) {
1444
+ if (self._released) return;
1445
+ validateDownPayloads(msgs);
1446
+ const deliveryWave = {};
1447
+ const assertVersionDataCompatible = (wave) => {
1448
+ for (const m of wave) {
1449
+ if (m[0] === "DATA") assertNodeVersionDataCompatible(self._version.policy, m[1]);
1450
+ }
1451
+ };
1452
+ const snapshotVersionData = (wave) => wave.map(
1453
+ (m) => m[0] === "DATA" ? ["DATA", snapshotNodeVersionData(self._version.policy, m[1])] : m
1454
+ );
1455
+ assertVersionDataCompatible(msgs);
1456
+ if (self._value.terminal !== void 0) {
1457
+ if (!msgs.some((m) => m[0] === "TEARDOWN")) return;
1458
+ self._value.hasTorndown = true;
1459
+ if (self._slot.resetOnTeardown) {
1460
+ self._value.cache = SENTINEL;
1461
+ self._value.hasData = false;
1462
+ }
1463
+ self._emitToSubs(["TEARDOWN"], { wave: deliveryWave, last: true });
1464
+ return;
897
1465
  }
898
- }
899
- function getNodeOwner(n) {
900
- return ownerTokens.get(n);
901
- }
902
- function notifyTopologyDepsChanged(node, prevDeps, deps) {
903
- topologyDepsChangedObservers.get(node)?.(node, prevDeps, deps);
904
- }
905
- function terminalView(t) {
906
- return t === void 0 ? false : t;
907
- }
908
- function validateDownPayloads(msgs) {
909
- for (const m of msgs) {
910
- if (m[0] === "DATA" && m[1] === void 0) {
911
- throw new Error("down: DATA requires a non-SENTINEL payload (R-data-payload)");
1466
+ let sorted = [...msgs].sort((a, b) => messageTier(a[0]) - messageTier(b[0]));
1467
+ const firstInvalidate = sorted.findIndex((m) => m[0] === "INVALIDATE");
1468
+ if (firstInvalidate !== -1) {
1469
+ sorted = sorted.filter((m, i) => m[0] !== "INVALIDATE" || i === firstInvalidate);
1470
+ }
1471
+ const hasTeardown = sorted.some((m) => m[0] === "TEARDOWN");
1472
+ const hasTerminal = sorted.some((m) => m[0] === "COMPLETE" || m[0] === "ERROR");
1473
+ if (hasTeardown && !hasTerminal && self._value.terminal === void 0 && !self._value.hasTorndown) {
1474
+ sorted = [["COMPLETE"], ...sorted];
1475
+ }
1476
+ if (!self._wave.insideRunWave && currentBatch()) {
1477
+ const deferred = snapshotVersionData(sorted.filter((m) => isDeferredTier(m[0])));
1478
+ if (deferred.length > 0) {
1479
+ if (!self._wave.emittedDirtyThisWave) {
1480
+ self._wave.emittedDirtyThisWave = true;
1481
+ self._value.status = "dirty";
1482
+ self._emitToSubs(["DIRTY"], { wave: deliveryWave, last: false });
1483
+ }
1484
+ self._wave.batchDirtyOwed = true;
1485
+ deferToBatch(self, deferred);
1486
+ return;
912
1487
  }
913
- if (m[0] === "ERROR" && isInvalidErrorPayload(m[1])) {
914
- throw new Error("down: ERROR requires a non-SENTINEL, non-boolean payload (R-data-payload)");
1488
+ }
1489
+ if (self._shouldBufferOnPause()) {
1490
+ const buffered = snapshotVersionData(sorted.filter((m) => isPauseBufferedTier(m[0])));
1491
+ if (buffered.length > 0) {
1492
+ self._wave.emittedSettleThisWave = true;
1493
+ self._control.pauseBuffer.push(buffered);
915
1494
  }
1495
+ sorted = sorted.filter((m) => !isPauseBufferedTier(m[0]));
1496
+ if (sorted.length === 0) return;
916
1497
  }
917
- }
918
- var Node = class {
919
- _core;
920
- _id;
921
- _slot;
922
- _dep;
923
- _value;
1498
+ let dataCount = 0;
1499
+ let hasTier3 = false;
1500
+ let hasResolved = false;
1501
+ for (const m of sorted) {
1502
+ if (m[0] === "DATA") dataCount++;
1503
+ if (m[0] === "RESOLVED") hasResolved = true;
1504
+ if (isValueTier(m[0])) hasTier3 = true;
1505
+ }
1506
+ if (dataCount >= 1 && hasResolved) {
1507
+ throw new Error(
1508
+ "down: a wave cannot mix DATA and RESOLVED (tier-3 exclusivity, R-resolved-undirty)"
1509
+ );
1510
+ }
1511
+ const plannedVersions = new Array(sorted.length);
1512
+ if (dataCount > 0) {
1513
+ let plannedVersion = self._version.value;
1514
+ for (let i = 0; i < sorted.length; i++) {
1515
+ const m = sorted[i];
1516
+ if (m[0] !== "DATA") continue;
1517
+ plannedVersion = advanceNodeVersion(plannedVersion, self._version.policy, m[1]);
1518
+ plannedVersions[i] = plannedVersion;
1519
+ }
1520
+ }
1521
+ if (hasTier3 && (!self._wave.insideRunWave || self._control.pullDirtyOwed) && !self._wave.emittedDirtyThisWave) {
1522
+ self._wave.emittedDirtyThisWave = true;
1523
+ self._value.status = "dirty";
1524
+ self._emitToSubs(["DIRTY"], { wave: deliveryWave, last: false });
1525
+ }
1526
+ for (let i = 0; i < sorted.length; i++) {
1527
+ const m = sorted[i];
1528
+ const delivery = { wave: deliveryWave, last: i === sorted.length - 1 };
1529
+ if (isDeferredTier(m[0])) self._wave.emittedSettleThisWave = true;
1530
+ if (m[0] === "DIRTY") {
1531
+ if (!self._wave.emittedDirtyThisWave) {
1532
+ self._wave.emittedDirtyThisWave = true;
1533
+ self._value.status = "dirty";
1534
+ self._emitToSubs(["DIRTY"], delivery);
1535
+ }
1536
+ continue;
1537
+ }
1538
+ if (m[0] === "DATA") {
1539
+ const v = m[1];
1540
+ self._value.cache = v;
1541
+ self._value.hasData = true;
1542
+ self._value.status = "settled";
1543
+ self._version.value = plannedVersions[i];
1544
+ if (self._slot.replayN > 0) {
1545
+ self._value.replayRing.push(v);
1546
+ if (self._value.replayRing.length > self._slot.replayN) self._value.replayRing.shift();
1547
+ }
1548
+ self._emitToSubs(["DATA", v], delivery);
1549
+ continue;
1550
+ }
1551
+ if (m[0] === "RESOLVED") {
1552
+ self._value.status = self._value.hasData ? "resolved" : "sentinel";
1553
+ self._emitToSubs(["RESOLVED"], delivery);
1554
+ continue;
1555
+ }
1556
+ if (m[0] === "INVALIDATE") {
1557
+ self._invalidate(delivery);
1558
+ continue;
1559
+ }
1560
+ if (m[0] === "COMPLETE") {
1561
+ if (self._value.terminal !== void 0) continue;
1562
+ self._value.terminal = true;
1563
+ self._control.pauseBuffer = [];
1564
+ self._value.status = "completed";
1565
+ self._emitToSubs(["COMPLETE"], delivery);
1566
+ continue;
1567
+ }
1568
+ if (m[0] === "ERROR") {
1569
+ if (self._value.terminal !== void 0) continue;
1570
+ self._value.terminal = m[1];
1571
+ self._control.pauseBuffer = [];
1572
+ self._value.status = "errored";
1573
+ self._emitToSubs(["ERROR", m[1]], delivery);
1574
+ continue;
1575
+ }
1576
+ if (m[0] === "TEARDOWN") {
1577
+ self._value.hasTorndown = true;
1578
+ if (self._slot.resetOnTeardown) {
1579
+ self._value.cache = SENTINEL;
1580
+ self._value.hasData = false;
1581
+ }
1582
+ self._emitToSubs(["TEARDOWN"], delivery);
1583
+ }
1584
+ }
1585
+ if (!self._wave.insideRunWave) self._wave.emittedDirtyThisWave = false;
1586
+ }
1587
+ function nodeUp(self, msgs, towardDep, route) {
1588
+ if (self._released) return;
1589
+ const routeState = route ?? { demandFired: /* @__PURE__ */ new Map() };
1590
+ for (const m of msgs) {
1591
+ if (!isUpAllowed(m[0])) {
1592
+ throw new Error(
1593
+ `ctx.up: ${m[0]} is down-only (tier ${messageTier(m[0])}); up carries control tiers only (R-ctx-up)`
1594
+ );
1595
+ }
1596
+ }
1597
+ for (const m of msgs) {
1598
+ if (m[0] === "PAUSE") {
1599
+ self._pauseAcquire(m[1]);
1600
+ } else if (m[0] === "RESUME") {
1601
+ if (self._control.pauseLockset.has(m[1])) {
1602
+ self._pauseRelease(m[1]);
1603
+ } else {
1604
+ self._forwardUp(m, towardDep, routeState);
1605
+ }
1606
+ } else if (m[0] === "PULL") {
1607
+ const demand = normalizePullDemand(m[1]);
1608
+ if (self._slot.pull && demand.pullId === self._slot.pullLock) {
1609
+ if (!self._markDemandRouted(demand.pullId, routeState)) self._onDemand(demand);
1610
+ } else {
1611
+ self._forwardUp(["PULL", demand], towardDep, routeState);
1612
+ }
1613
+ } else if (self._slot.deps.length === 0) {
1614
+ if (m[0] === "INVALIDATE") self._down([["INVALIDATE"]]);
1615
+ } else {
1616
+ self._forwardUp(m, towardDep, routeState);
1617
+ }
1618
+ }
1619
+ }
1620
+ function nodeMarkDemandRouted(self, lockId, route) {
1621
+ let holders = route.demandFired.get(lockId);
1622
+ if (holders === void 0) {
1623
+ holders = /* @__PURE__ */ new Set();
1624
+ route.demandFired.set(lockId, holders);
1625
+ }
1626
+ const node = self;
1627
+ if (holders.has(node)) return true;
1628
+ holders.add(node);
1629
+ return false;
1630
+ }
1631
+ function nodeForwardUp(self, m, towardDep, route) {
1632
+ if (self._slot.deps.length === 0) return;
1633
+ if (towardDep !== void 0) {
1634
+ const d = self._slot.deps[towardDep];
1635
+ if (d !== void 0) nodeRuntimeHost(d)._up([m], void 0, route);
1636
+ } else {
1637
+ for (const dep of self._slot.deps) nodeRuntimeHost(dep)._up([m], void 0, route);
1638
+ }
1639
+ }
1640
+ function nodeIsPaused(self) {
1641
+ return self._control.pauseLockset.size > 0;
1642
+ }
1643
+ function nodeHasBoundaryPauseLock(self) {
1644
+ if (self._slot.pausable === false) return false;
1645
+ return self._control.pauseLockset.size > 0;
1646
+ }
1647
+ function nodeIsAsyncPool(self) {
1648
+ return self._slot.handle !== null && self._slot.dispatcher.poolKind(self._slot.handle.poolId) === "async";
1649
+ }
1650
+ function nodePauseAcquire(self, lockId) {
1651
+ self._control.pauseLockset.add(lockId);
1652
+ }
1653
+ function nodePauseRelease(self, lockId) {
1654
+ if (!self._control.pauseLockset.has(lockId)) return;
1655
+ self._control.pauseLockset.delete(lockId);
1656
+ if (self._slot.pull && self._control.demandOwed !== void 0) self._fireOwedDemandIfReady();
1657
+ if (self._hasBoundaryPauseLock()) return;
1658
+ scheduleBoundaryDrain(self._core);
1659
+ if (self._slot.pull) return;
1660
+ self._onResume();
1661
+ }
1662
+ function nodeOnResume(self) {
1663
+ if (self._value.terminal !== void 0) {
1664
+ self._control.pauseBuffer = [];
1665
+ self._control.pausedDepWaveOccurred = false;
1666
+ self._control.demandOwed = void 0;
1667
+ self._control.activePull = void 0;
1668
+ self._control.pullDirtyOwed = false;
1669
+ return;
1670
+ }
1671
+ if (self._control.pauseBuffer.length > 0) {
1672
+ const buf = self._control.pauseBuffer;
1673
+ self._control.pauseBuffer = [];
1674
+ for (const wave of buf) self._down(wave);
1675
+ }
1676
+ if (self._control.pausedDepWaveOccurred) {
1677
+ self._control.pausedDepWaveOccurred = false;
1678
+ self._tryRun();
1679
+ }
1680
+ }
1681
+ function nodeCanFireDemand(self) {
1682
+ if (self._value.terminal !== void 0 || self._wave.pending > 0) return false;
1683
+ return self._control.pauseLockset.size === 0;
1684
+ }
1685
+ function nodeDeliverPullDemand(self, demand) {
1686
+ self._control.demandOwed = void 0;
1687
+ self._control.activePull = demand;
1688
+ self._control.inDeliverDemand = true;
1689
+ try {
1690
+ self._firePullDemand();
1691
+ } finally {
1692
+ self._control.activePull = void 0;
1693
+ self._control.inDeliverDemand = false;
1694
+ }
1695
+ }
1696
+ function nodeOnDemand(self, demand) {
1697
+ if (self._control.inDeliverDemand) return;
1698
+ if (self._canFireDemand()) self._deliverPullDemand(demand);
1699
+ else self._control.demandOwed = demand;
1700
+ }
1701
+ function nodeFirePullDemand(self) {
1702
+ let drainedBuffer = false;
1703
+ if (self._control.pauseBuffer.length > 0) {
1704
+ const buf = self._control.pauseBuffer;
1705
+ self._control.pauseBuffer = [];
1706
+ for (const wave of buf) self._down(wave);
1707
+ drainedBuffer = true;
1708
+ }
1709
+ if (drainedBuffer) return;
1710
+ if (self._control.pausedDepWaveOccurred) {
1711
+ const gated = self._slot.handle !== null && !self._wave.hasCalledFnOnce && !(self._slot.partial || self._allDepsSettled());
1712
+ if (self._wave.pending > 0 || gated) return;
1713
+ self._control.pausedDepWaveOccurred = false;
1714
+ self._wave.emittedDirtyThisWave = false;
1715
+ self._control.pullDirtyOwed = true;
1716
+ try {
1717
+ self._tryRun();
1718
+ } finally {
1719
+ self._control.pullDirtyOwed = false;
1720
+ }
1721
+ return;
1722
+ }
1723
+ if (self._slot.handle !== null) {
1724
+ if (!self._wave.hasCalledFnOnce && !(self._slot.partial || self._allDepsSettled())) return;
1725
+ self._wave.emittedDirtyThisWave = false;
1726
+ self._control.pullDirtyOwed = true;
1727
+ try {
1728
+ self._runWave();
1729
+ } finally {
1730
+ self._control.pullDirtyOwed = false;
1731
+ }
1732
+ }
1733
+ }
1734
+ function nodeFireOwedDemandIfReady(self) {
1735
+ if (self._control.inDeliverDemand) return;
1736
+ if (self._slot.pull && self._control.demandOwed !== void 0 && self._canFireDemand()) {
1737
+ self._deliverPullDemand(self._control.demandOwed);
1738
+ }
1739
+ }
1740
+ function nodeShouldBufferOnPause(self) {
1741
+ if (self._slot.pausable === false) return false;
1742
+ if (!self._isPaused() && !self._isPullQuiet()) return false;
1743
+ if (self._slot.pausable === "resumeAll") return true;
1744
+ if (!self._wave.insideRunWave && self._isAsyncPool() && self._slot.deps.length > 0) return true;
1745
+ return false;
1746
+ }
1747
+ function nodeInvalidate(self, delivery) {
1748
+ if (!self._value.hasData) return;
1749
+ self._value.cache = SENTINEL;
1750
+ self._value.hasData = false;
1751
+ self._value.status = "sentinel";
1752
+ self._value.replayRing = [];
1753
+ for (const fn of self._hooks.onInvalidate) fn();
1754
+ self._emitToSubs(["INVALIDATE"], delivery);
1755
+ }
1756
+ function nodeAllDepsTerminal(self) {
1757
+ if (self._slot.deps.length === 0) return false;
1758
+ for (const tm of self._dep.terminal) if (tm === void 0) return false;
1759
+ return true;
1760
+ }
1761
+ function nodeResetLifecycle(self) {
1762
+ for (const u of self._dep.unsubs) if (u) u();
1763
+ self._dep.unsubs = [];
1764
+ self._dep.idxBoxes = [];
1765
+ self._lifecycle.subscribers.clear();
1766
+ self._lifecycle.activated = false;
1767
+ self._value.terminal = void 0;
1768
+ self._value.hasTorndown = false;
1769
+ self._wave.hasCalledFnOnce = false;
1770
+ self._resetDepState();
1771
+ self._control.pauseLockset.clear();
1772
+ self._control.pauseBuffer = [];
1773
+ self._control.pausedDepWaveOccurred = false;
1774
+ self._control.demandOwed = void 0;
1775
+ self._control.activePull = void 0;
1776
+ self._control.pullDirtyOwed = false;
1777
+ self._value.replayRing = [];
1778
+ const isCompute = self._slot.handle !== null || self._slot.deps.length > 0;
1779
+ if (isCompute) {
1780
+ self._value.cache = SENTINEL;
1781
+ self._value.hasData = false;
1782
+ self._value.status = "sentinel";
1783
+ } else {
1784
+ self._value.status = self._value.hasData ? "settled" : "sentinel";
1785
+ }
1786
+ if (!self._privateState.persist) self._privateState.value = SENTINEL;
1787
+ }
1788
+ function nodeEmitToSubs(self, msg, delivery) {
1789
+ if (self._released) return;
1790
+ const subs = [...self._lifecycle.subscribers];
1791
+ for (const sink of subs) sink(msg, delivery);
1792
+ }
1793
+ function nodeCommitBatchedWave(self, wave) {
1794
+ self._wave.batchDirtyOwed = false;
1795
+ self._down(wave);
1796
+ }
1797
+ function nodeRollbackBatched(self) {
1798
+ if (self._wave.batchDirtyOwed) {
1799
+ self._wave.batchDirtyOwed = false;
1800
+ self._wave.emittedDirtyThisWave = false;
1801
+ self._value.status = self._value.hasData ? "settled" : "sentinel";
1802
+ self._emitToSubs(["RESOLVED"]);
1803
+ }
1804
+ }
1805
+ function nodeDeferBoundary(self, fn, batchToken) {
1806
+ deferRewire(self._core, fn, {
1807
+ batchToken,
1808
+ isReady: () => !self._hasBoundaryPauseLock()
1809
+ });
1810
+ }
1811
+
1812
+ // src/node/node-rewire-runtime.ts
1813
+ function nodeRequestRewireNext(self, op) {
1814
+ deferRewire(self._core, () => self._applyRewireNext(op), {
1815
+ batchToken: currentBoundaryBatchToken(),
1816
+ isReady: () => !self._hasBoundaryPauseLock()
1817
+ });
1818
+ }
1819
+ function nodeRequestUpNext(self, msgs, towardDep) {
1820
+ deferRewire(
1821
+ self._core,
1822
+ () => {
1823
+ if (!self._released) self._up(msgs, towardDep);
1824
+ },
1825
+ {
1826
+ batchToken: currentBoundaryBatchToken(),
1827
+ isReady: () => !self._hasBoundaryPauseLock()
1828
+ }
1829
+ );
1830
+ }
1831
+ function nodeApplyRewireNext(self, op) {
1832
+ if (self._released) return;
1833
+ try {
1834
+ if (op.kind === "add") {
1835
+ const next = self._slot.deps.includes(op.dep) ? [...self._slot.deps] : [...self._slot.deps, op.dep];
1836
+ self._rewire(next, op.fn, { allowTerminalOwner: true });
1837
+ } else if (op.kind === "remove") {
1838
+ self._rewire(
1839
+ self._slot.deps.filter((d) => d !== op.dep),
1840
+ op.fn,
1841
+ { allowTerminalOwner: true }
1842
+ );
1843
+ } else {
1844
+ self._rewire(self._dedupDeps(op.deps), op.fn, { allowTerminalOwner: true });
1845
+ }
1846
+ } catch (e) {
1847
+ self._down([["ERROR", errorPayload(e, "rewireNext op failed")]]);
1848
+ }
1849
+ }
1850
+ function nodeRewire(self, newDeps, fn, opts = {}) {
1851
+ const node = self;
1852
+ if (self._value.terminal !== void 0 && !opts.allowTerminalOwner)
1853
+ throw new Error(
1854
+ "rewire: node is terminal (completed/errored) \u2014 cannot rewire (R-rewire / D42)"
1855
+ );
1856
+ if (self._wave.insideRunWave)
1857
+ throw new Error(
1858
+ "rewire: mid-fn topology mutation \u2014 a fn mutating its own deps mid-wave is the feedback cycle (R-rewire / D37)"
1859
+ );
1860
+ if (self._wave.inDepMutation)
1861
+ throw new Error(
1862
+ "rewire: reentrant dep mutation \u2014 another replaceDeps/subscribeDep/unsubscribeDep is in flight (R-rewire)"
1863
+ );
1864
+ if (newDeps.includes(node)) throw new Error("rewire: self-dependency rejected (R-rewire / D42)");
1865
+ const oldDeps = self._slot.deps;
1866
+ const added = newDeps.filter((d) => !oldDeps.includes(d));
1867
+ for (const d of added) {
1868
+ if (self._reachableUpstream(d, node))
1869
+ throw new Error(
1870
+ "rewire: would create a cycle \u2014 dep already transitively depends on this node (R-rewire / D42)"
1871
+ );
1872
+ const dep = nodeRuntimeHost(d);
1873
+ if (dep._value.terminal !== void 0 && !dep._slot.resubscribable)
1874
+ throw new Error(
1875
+ "rewire: cannot add a non-resubscribable terminal dep \u2014 would wedge (R-rewire / D42)"
1876
+ );
1877
+ self._assertRewireDepOwner(d);
1878
+ }
1879
+ if (deferAfterBatchForTarget(node, () => {
1880
+ self._rewire(newDeps, fn, { ...opts, allowTerminalOwner: true });
1881
+ })) {
1882
+ return true;
1883
+ }
1884
+ if (!self._lifecycle.activated) self._restoredActivationPending = false;
1885
+ self._wave.inDepMutation = true;
1886
+ self._wave.rewireRunPending = false;
1887
+ let zeroDepUnDirty = false;
1888
+ try {
1889
+ const oldHandle = self._slot.handle;
1890
+ self._slot.handle = self._slot.dispatcher.register(fn, self._slot.pool);
1891
+ if (oldHandle !== null) self._slot.dispatcher.unregister(oldHandle);
1892
+ const removed = oldDeps.filter((d) => !newDeps.includes(d));
1893
+ let removedDirtyContributor = false;
1894
+ for (const d of removed) {
1895
+ const oldIdx = oldDeps.indexOf(d);
1896
+ if (self._dep.dirty[oldIdx]) {
1897
+ removedDirtyContributor = true;
1898
+ self._wave.pending--;
1899
+ }
1900
+ if (self._lifecycle.activated) {
1901
+ const box = self._dep.idxBoxes[oldIdx];
1902
+ if (box) box.v = -1;
1903
+ const unsub = self._dep.unsubs[oldIdx];
1904
+ if (unsub) unsub();
1905
+ }
1906
+ }
1907
+ const n = newDeps.length;
1908
+ const newBatch = new Array(n).fill(null);
1909
+ const newPrev = new Array(n).fill(SENTINEL);
1910
+ const newHasData = new Array(n).fill(false);
1911
+ const newDirty = new Array(n).fill(false);
1912
+ const newTier = new Array(n).fill(0);
1913
+ const newTerminal = new Array(n).fill(void 0);
1914
+ const newTerminalInput = new Array(n).fill(void 0);
1915
+ const newUnsubs = new Array(n);
1916
+ const newBoxes = new Array(n);
1917
+ for (let j = 0; j < n; j++) {
1918
+ const oldIdx = oldDeps.indexOf(newDeps[j]);
1919
+ if (oldIdx !== -1) {
1920
+ newBatch[j] = self._dep.batch[oldIdx];
1921
+ newPrev[j] = self._dep.prev[oldIdx];
1922
+ newHasData[j] = self._dep.hasData[oldIdx];
1923
+ newDirty[j] = self._dep.dirty[oldIdx];
1924
+ newTier[j] = self._dep.tier[oldIdx];
1925
+ newTerminal[j] = self._dep.terminal[oldIdx];
1926
+ newUnsubs[j] = self._dep.unsubs[oldIdx];
1927
+ const box = self._dep.idxBoxes[oldIdx];
1928
+ if (box) box.v = j;
1929
+ newBoxes[j] = box;
1930
+ }
1931
+ }
1932
+ self._slot.deps = newDeps;
1933
+ self._dep.batch = newBatch;
1934
+ self._dep.prev = newPrev;
1935
+ self._dep.hasData = newHasData;
1936
+ self._dep.dirty = newDirty;
1937
+ self._dep.tier = newTier;
1938
+ self._dep.terminal = newTerminal;
1939
+ self._dep.terminalInput = newTerminalInput;
1940
+ self._dep.unsubs = newUnsubs;
1941
+ self._dep.idxBoxes = newBoxes;
1942
+ self._dep.waveData = newDeps.map(() => []);
1943
+ self._dep.waveTokens = new Array(newDeps.length).fill(void 0);
1944
+ self._syncCtx = null;
1945
+ if (self._lifecycle.activated) {
1946
+ for (const d of added) self._subscribeDepAt(d);
1947
+ }
1948
+ notifyTopologyDepsChanged(node, oldDeps, newDeps);
1949
+ if (removedDirtyContributor && self._wave.pending === 0 && self._value.status === "dirty") {
1950
+ if (newDeps.length > 0) self._wave.rewireRunPending = true;
1951
+ else zeroDepUnDirty = true;
1952
+ }
1953
+ } finally {
1954
+ self._wave.inDepMutation = false;
1955
+ }
1956
+ if (self._wave.rewireRunPending) {
1957
+ self._wave.rewireRunPending = false;
1958
+ self._settleRewire();
1959
+ } else if (zeroDepUnDirty) {
1960
+ if (self._wave.emittedDirtyThisWave) self._down([["RESOLVED"]]);
1961
+ else self._value.status = self._value.hasData ? "settled" : "sentinel";
1962
+ }
1963
+ return false;
1964
+ }
1965
+
1966
+ // src/node/node.ts
1967
+ var Node = class _Node {
1968
+ _core;
1969
+ _id;
1970
+ _slot;
1971
+ _dep;
1972
+ _value;
924
1973
  _wave;
925
1974
  _control;
926
1975
  _lifecycle;
@@ -936,19 +1985,63 @@ var Node = class {
936
1985
  set _syncCtx(ctx) {
937
1986
  this._syncCtxState.value = ctx;
938
1987
  }
1988
+ static _retainIndirectRuntimeMethods(node) {
1989
+ void node._dep;
1990
+ void node._hooks;
1991
+ void node._restoredActivationPending;
1992
+ void node._requestRewireNext;
1993
+ void node._requestUpNext;
1994
+ void node._applyRewireNext;
1995
+ void node._reachableUpstream;
1996
+ void node._assertRewireDepOwner;
1997
+ void node._subscribeDepAt;
1998
+ void node._seedRestoredDepAt;
1999
+ void node._recordDepProjection;
2000
+ void node._depProjectionHasData;
2001
+ void node._receiveFromDep;
2002
+ void node._releaseDepDirty;
2003
+ void node._settleAfterAbsorbedTerminal;
2004
+ void node._markDirty;
2005
+ void node._maybeRun;
2006
+ void node._settleRewire;
2007
+ void node._tryRun;
2008
+ void node._allDepsSettled;
2009
+ void node._passthroughEmit;
2010
+ void node._runWave;
2011
+ void node._buildCtx;
2012
+ void node._makeCtx;
2013
+ void node._refreshCtx;
2014
+ void node._makeState;
2015
+ void node._markDemandRouted;
2016
+ void node._forwardUp;
2017
+ void node._isPullQuiet;
2018
+ void node._isPaused;
2019
+ void node._hasBoundaryPauseLock;
2020
+ void node._isAsyncPool;
2021
+ void node._pauseAcquire;
2022
+ void node._pauseRelease;
2023
+ void node._onResume;
2024
+ void node._canFireDemand;
2025
+ void node._deliverPullDemand;
2026
+ void node._onDemand;
2027
+ void node._firePullDemand;
2028
+ void node._fireOwedDemandIfReady;
2029
+ void node._shouldBufferOnPause;
2030
+ void node._invalidate;
2031
+ void node._allDepsTerminal;
2032
+ void node._emitToSubs;
2033
+ }
939
2034
  constructor(deps, handleOrFn, opts = {}) {
940
- const core = constructingCore;
941
- constructingCore = void 0;
2035
+ const core = takeConstructingNodeCore();
942
2036
  const dispatcher = opts.dispatcher ?? defaultDispatcher;
943
- const environment = constructingEnvironment ?? EnvironmentDrivers.empty();
944
- constructingEnvironment = void 0;
2037
+ const environment = takeConstructingEnvironmentDrivers() ?? EnvironmentDrivers.empty();
945
2038
  const pool = opts.pool ?? "sync";
946
2039
  const pausable = opts.pausable ?? true;
947
2040
  const pullLock = opts.pullId;
948
2041
  const pull = opts.pullId !== void 0;
949
2042
  if (pull && pausable === false)
950
2043
  throw new Error(
951
- "node: pullId is incompatible with pausable:false \u2014 a pull node is demanded via RESUME, which pausable:false ignores (R-pull / R-pause-modes / D55,D59)"
2044
+ "node: pullId is incompatible with pausable:false \u2014 a pull node uses the pausable delivery-content axis (R-pull / R-pause-modes / D55,D269)"
952
2045
  );
953
2046
  let handle;
954
2047
  if (handleOrFn === null) handle = null;
@@ -971,7 +2064,6 @@ var Node = class {
971
2064
  value.status = "settled";
972
2065
  }
973
2066
  const pauseLockset = /* @__PURE__ */ new Set();
974
- if (pull) pauseLockset.add(pullLock);
975
2067
  this._core = core ?? new NodeCore();
976
2068
  const created = this._core.createSlot(
977
2069
  {
@@ -1012,7 +2104,9 @@ var Node = class {
1012
2104
  pauseLockset,
1013
2105
  pausedDepWaveOccurred: false,
1014
2106
  pauseBuffer: [],
1015
- demandOwed: false,
2107
+ demandOwed: void 0,
2108
+ activePull: void 0,
2109
+ pullDirtyOwed: false,
1016
2110
  inDeliverDemand: false
1017
2111
  },
1018
2112
  privateState: { value: SENTINEL, persist: false },
@@ -1069,10 +2163,11 @@ var Node = class {
1069
2163
  this._wave.batchDirtyOwed = false;
1070
2164
  this._control.pauseBuffer = [];
1071
2165
  this._control.pausedDepWaveOccurred = false;
1072
- this._control.demandOwed = false;
2166
+ this._control.demandOwed = void 0;
2167
+ this._control.activePull = void 0;
2168
+ this._control.pullDirtyOwed = false;
1073
2169
  this._control.inDeliverDemand = false;
1074
2170
  this._control.pauseLockset.clear();
1075
- if (this._slot.pull) this._control.pauseLockset.add(this._slot.pullLock);
1076
2171
  this._privateState.value = state.ctxState.value;
1077
2172
  this._privateState.persist = state.ctxState.persist;
1078
2173
  if (state.version === false) {
@@ -1110,18 +2205,18 @@ var Node = class {
1110
2205
  runtimeQuiescenceReaders.set(this, () => this._isRuntimeQuiescentForRelease());
1111
2206
  subscriberCountReaders.set(this, () => this._subscriberCount());
1112
2207
  activationReaders.set(this, () => this._lifecycle.activated);
2208
+ _Node._retainIndirectRuntimeMethods(this);
1113
2209
  }
1114
- /** R-pull (D55): true while a pull node is quiet (holds its own pullId/demand lock). */
2210
+ /** R-pull (D55/D272): true while a pull node is not serving a PULL demand pulse. */
1115
2211
  _isPullQuiet() {
1116
- return this._slot.pull && this._control.pauseLockset.has(this._slot.pullLock);
2212
+ return this._slot.pull && this._control.activePull === void 0;
1117
2213
  }
1118
2214
  /**
1119
- * R-pull (D55/D59): this pull node's pullId (pure data, like {@link cache}/{@link handle} — never
1120
- * triggers computation). A consumer demands one delivery by cone-routing a RESUME of it (no node
1121
- * reference): `ctx.up([["RESUME", pullId]])` (immediate; loops back → D37 for a self-read dep) or
1122
- * `ctx.upNext([["RESUME", pullId]])` (boundary-deferred self-demand, R-up-routing/R-rewire-deferred).
1123
- * Undefined for a non-pull node. The author writes the pullId verbatim, so this getter is mainly
1124
- * for inspection/describe; routing matches by the pullId value carried in the RESUME, by identity.
2215
+ * R-pull (D269/D272): this pull node's pullId (pure data, like {@link cache}/{@link handle} —
2216
+ * never triggers computation). A consumer demands one delivery by cone-routing PULL of it (no
2217
+ * node reference): `ctx.up([["PULL", { pullId }]])` (immediate; loops back → D37 for a self-read
2218
+ * dep) or `ctx.upNext([["PULL", { pullId }]])` (boundary-deferred self-demand). Undefined for a
2219
+ * non-pull node. The author writes the pullId verbatim; routing matches by identity.
1125
2220
  */
1126
2221
  get pullId() {
1127
2222
  return this._slot.pullLock;
@@ -1215,58 +2310,6 @@ var Node = class {
1215
2310
  exitWave();
1216
2311
  }
1217
2312
  }
1218
- // ── deferred self-rewire (R-rewire-deferred / D47): ctx.rewireNext drain support ──
1219
- /**
1220
- * Enqueue a deferred self-rewire op (issued from this node's fn via `ctx.rewireNext`).
1221
- * Applied at the committed wave boundary (boundary.ts drain), never in place — the in-fn
1222
- * immediate path (`subscribeDep`/`replaceDeps`/`unsubscribeDep`) still throws mid-run (D37/R-reentrancy).
1223
- */
1224
- _requestRewireNext(op) {
1225
- deferRewire(this._core, () => this._applyRewireNext(op), {
1226
- batchToken: currentBoundaryBatchToken(),
1227
- isReady: () => !this._hasBoundaryPauseLock()
1228
- });
1229
- }
1230
- /**
1231
- * Enqueue a deferred up-going control wave (R-up-routing / R-pull / D59): at the committed wave
1232
- * boundary, route `msgs` up from THIS node (broadcast, or up the single `towardDep` edge). The
1233
- * deferred form of `ctx.up` — the SELF-demand path: a consumer issues `ctx.upNext([[RESUME,
1234
- * pullId]])` to demand a dep it ALSO reads; the demand applies at the boundary (not mid-fn), so
1235
- * the pull node's delivery loops back as a FRESH wave rather than re-entering the consumer (D37 /
1236
- * R-reentrancy). Rides the same R-rewire-deferred (D47) drain as ctx.rewireNext.
1237
- */
1238
- _requestUpNext(msgs, towardDep) {
1239
- deferRewire(
1240
- this._core,
1241
- () => {
1242
- if (!this._released) this._up(msgs, towardDep);
1243
- },
1244
- {
1245
- batchToken: currentBoundaryBatchToken(),
1246
- isReady: () => !this._hasBoundaryPauseLock()
1247
- }
1248
- );
1249
- }
1250
- /** Apply one queued self-rewire at the boundary (drain thunk). */
1251
- _applyRewireNext(op) {
1252
- if (this._released) return;
1253
- try {
1254
- if (op.kind === "add") {
1255
- const next = this._slot.deps.includes(op.dep) ? [...this._slot.deps] : [...this._slot.deps, op.dep];
1256
- this._rewire(next, op.fn, { allowTerminalOwner: true });
1257
- } else if (op.kind === "remove") {
1258
- this._rewire(
1259
- this._slot.deps.filter((d) => d !== op.dep),
1260
- op.fn,
1261
- { allowTerminalOwner: true }
1262
- );
1263
- } else {
1264
- this._rewire(this._dedupDeps(op.deps), op.fn, { allowTerminalOwner: true });
1265
- }
1266
- } catch (e) {
1267
- this._down([["ERROR", errorPayload(e, "rewireNext op failed")]]);
1268
- }
1269
- }
1270
2313
  // ── rewire (R-rewire / D42): intra-graph runtime topology mutation ──
1271
2314
  /**
1272
2315
  * Replace this node's deps atomically (surgical, Option-C). Requires an explicit
@@ -1294,6 +2337,15 @@ var Node = class {
1294
2337
  fn
1295
2338
  );
1296
2339
  }
2340
+ _requestRewireNext(op) {
2341
+ nodeRequestRewireNext(nodeRuntimeHost(this), op);
2342
+ }
2343
+ _requestUpNext(msgs, towardDep) {
2344
+ nodeRequestUpNext(nodeRuntimeHost(this), msgs, towardDep);
2345
+ }
2346
+ _applyRewireNext(op) {
2347
+ nodeApplyRewireNext(nodeRuntimeHost(this), op);
2348
+ }
1297
2349
  _dedupDeps(deps) {
1298
2350
  const seen = /* @__PURE__ */ new Set();
1299
2351
  const out = [];
@@ -1304,7 +2356,6 @@ var Node = class {
1304
2356
  }
1305
2357
  return out;
1306
2358
  }
1307
- /** Is `target` reachable upstream from `from` (following deps)? Cycle-prevention DFS. */
1308
2359
  _reachableUpstream(from, target) {
1309
2360
  const seen = /* @__PURE__ */ new Set();
1310
2361
  const stack = [from];
@@ -1314,1025 +2365,171 @@ var Node = class {
1314
2365
  if (n === target) return true;
1315
2366
  if (seen.has(n)) continue;
1316
2367
  seen.add(n);
1317
- for (const d of n._slot.deps) stack.push(d);
2368
+ for (const d of nodeRuntimeHost(n)._slot.deps) stack.push(d);
1318
2369
  }
1319
2370
  return false;
1320
2371
  }
1321
2372
  _assertRewireDepOwner(dep) {
1322
2373
  const selfOwner = getNodeOwner(this);
1323
2374
  const depOwner = getNodeOwner(dep);
1324
- if (selfOwner !== void 0 && depOwner !== void 0 && selfOwner !== depOwner) {
2375
+ if (selfOwner !== void 0 && depOwner !== void 0 && selfOwner !== depOwner)
1325
2376
  throw new Error(
1326
2377
  "rewire: dep belongs to a different graph; cross-graph deps require a wire bridge (D22 / R-graph-domain)"
1327
2378
  );
1328
- }
1329
2379
  }
1330
2380
  _rewire(newDeps, fn, opts = {}) {
1331
- if (this._value.terminal !== void 0 && !opts.allowTerminalOwner)
1332
- throw new Error(
1333
- "rewire: node is terminal (completed/errored) \u2014 cannot rewire (R-rewire / D42)"
1334
- );
1335
- if (this._wave.insideRunWave)
1336
- throw new Error(
1337
- "rewire: mid-fn topology mutation \u2014 a fn mutating its own deps mid-wave is the feedback cycle (R-rewire / D37)"
1338
- );
1339
- if (this._wave.inDepMutation)
1340
- throw new Error(
1341
- "rewire: reentrant dep mutation \u2014 another replaceDeps/subscribeDep/unsubscribeDep is in flight (R-rewire)"
1342
- );
1343
- if (newDeps.includes(this))
1344
- throw new Error("rewire: self-dependency rejected (R-rewire / D42)");
1345
- const oldDeps = this._slot.deps;
1346
- const added = newDeps.filter((d) => !oldDeps.includes(d));
1347
- for (const d of added) {
1348
- if (this._reachableUpstream(d, this))
1349
- throw new Error(
1350
- "rewire: would create a cycle \u2014 dep already transitively depends on this node (R-rewire / D42)"
1351
- );
1352
- if (d._value.terminal !== void 0 && !d._slot.resubscribable)
1353
- throw new Error(
1354
- "rewire: cannot add a non-resubscribable terminal dep \u2014 would wedge (R-rewire / D42)"
1355
- );
1356
- this._assertRewireDepOwner(d);
1357
- }
1358
- if (deferAfterBatchForTarget(this, () => {
1359
- this._rewire(newDeps, fn, { ...opts, allowTerminalOwner: true });
1360
- })) {
1361
- return true;
1362
- }
1363
- if (!this._lifecycle.activated) this._restoredActivationPending = false;
1364
- this._wave.inDepMutation = true;
1365
- this._wave.rewireRunPending = false;
1366
- let zeroDepUnDirty = false;
1367
- try {
1368
- const oldHandle = this._slot.handle;
1369
- this._slot.handle = this._slot.dispatcher.register(fn, this._slot.pool);
1370
- if (oldHandle !== null) this._slot.dispatcher.unregister(oldHandle);
1371
- const removed = oldDeps.filter((d) => !newDeps.includes(d));
1372
- let removedDirtyContributor = false;
1373
- for (const d of removed) {
1374
- const oldIdx = oldDeps.indexOf(d);
1375
- if (this._dep.dirty[oldIdx]) {
1376
- removedDirtyContributor = true;
1377
- this._wave.pending--;
1378
- }
1379
- if (this._lifecycle.activated) {
1380
- const box = this._dep.idxBoxes[oldIdx];
1381
- if (box) box.v = -1;
1382
- const unsub = this._dep.unsubs[oldIdx];
1383
- if (unsub) unsub();
1384
- }
1385
- }
1386
- const n = newDeps.length;
1387
- const newBatch = new Array(n).fill(null);
1388
- const newPrev = new Array(n).fill(SENTINEL);
1389
- const newHasData = new Array(n).fill(false);
1390
- const newDirty = new Array(n).fill(false);
1391
- const newTier = new Array(n).fill(0);
1392
- const newTerminal = new Array(n).fill(void 0);
1393
- const newTerminalInput = new Array(n).fill(void 0);
1394
- const newUnsubs = new Array(n);
1395
- const newBoxes = new Array(n);
1396
- for (let j = 0; j < n; j++) {
1397
- const oldIdx = oldDeps.indexOf(newDeps[j]);
1398
- if (oldIdx !== -1) {
1399
- newBatch[j] = this._dep.batch[oldIdx];
1400
- newPrev[j] = this._dep.prev[oldIdx];
1401
- newHasData[j] = this._dep.hasData[oldIdx];
1402
- newDirty[j] = this._dep.dirty[oldIdx];
1403
- newTier[j] = this._dep.tier[oldIdx];
1404
- newTerminal[j] = this._dep.terminal[oldIdx];
1405
- newUnsubs[j] = this._dep.unsubs[oldIdx];
1406
- const box = this._dep.idxBoxes[oldIdx];
1407
- if (box) box.v = j;
1408
- newBoxes[j] = box;
1409
- }
1410
- }
1411
- this._slot.deps = newDeps;
1412
- this._dep.batch = newBatch;
1413
- this._dep.prev = newPrev;
1414
- this._dep.hasData = newHasData;
1415
- this._dep.dirty = newDirty;
1416
- this._dep.tier = newTier;
1417
- this._dep.terminal = newTerminal;
1418
- this._dep.terminalInput = newTerminalInput;
1419
- this._dep.unsubs = newUnsubs;
1420
- this._dep.idxBoxes = newBoxes;
1421
- this._dep.waveData = newDeps.map(() => []);
1422
- this._dep.waveTokens = new Array(newDeps.length).fill(void 0);
1423
- this._syncCtx = null;
1424
- if (this._lifecycle.activated) {
1425
- for (const d of added) this._subscribeDepAt(d);
1426
- }
1427
- notifyTopologyDepsChanged(this, oldDeps, newDeps);
1428
- if (removedDirtyContributor && this._wave.pending === 0 && this._value.status === "dirty") {
1429
- if (newDeps.length > 0) this._wave.rewireRunPending = true;
1430
- else zeroDepUnDirty = true;
1431
- }
1432
- } finally {
1433
- this._wave.inDepMutation = false;
1434
- }
1435
- if (this._wave.rewireRunPending) {
1436
- this._wave.rewireRunPending = false;
1437
- this._settleRewire();
1438
- } else if (zeroDepUnDirty) {
1439
- if (this._wave.emittedDirtyThisWave) this._down([["RESOLVED"]]);
1440
- else this._value.status = this._value.hasData ? "settled" : "sentinel";
1441
- }
1442
- return false;
2381
+ return nodeRewire(nodeRuntimeHost(this), newDeps, fn, opts);
1443
2382
  }
1444
2383
  // ── activation / deactivation (lazy; R-rom-ram) ──
1445
2384
  _activate() {
1446
- this._lifecycle.activated = true;
1447
- const seedRestoredDeps = this._restoredActivationPending;
1448
- this._restoredActivationPending = false;
1449
- if (this._slot.pull) this._control.pauseLockset.add(this._slot.pullLock);
1450
- this._dep.unsubs = new Array(this._slot.deps.length);
1451
- this._dep.idxBoxes = new Array(this._slot.deps.length);
1452
- for (const dep of this._slot.deps)
1453
- this._subscribeDepAt(dep, { seedRestored: seedRestoredDeps });
1454
- if (this._slot.deps.length === 0 && this._slot.handle !== null && !this._wave.hasCalledFnOnce) {
1455
- this._runWave();
1456
- }
1457
- }
1458
- /**
1459
- * Subscribe to a dep. The dispatch callback reads the dep's CURRENT index from a
1460
- * mutable box (O(1)); a surgical rewire that reorders kept deps just updates the box
1461
- * (R-rewire Option-C / D42) — no re-subscribe, no per-message indexOf scan. A removed
1462
- * dep's box is set to -1 so any stale in-flight callback drops (drain).
1463
- */
1464
- _subscribeDepAt(depNode, opts = {}) {
1465
- const idx0 = this._slot.deps.indexOf(depNode);
1466
- const box = { v: idx0 };
1467
- let ignoreInitialPush = opts.seedRestored === true;
1468
- if (ignoreInitialPush && idx0 !== -1) {
1469
- this._seedRestoredDepAt(idx0, depNode);
1470
- if (depNode._value.terminal !== void 0 && !depNode._slot.resubscribable) {
1471
- this._dep.unsubs[idx0] = () => {
1472
- };
1473
- this._dep.idxBoxes[idx0] = box;
1474
- return;
1475
- }
1476
- }
1477
- const unsub = depNode.subscribe((msg, delivery) => {
1478
- if (ignoreInitialPush && delivery === void 0) return;
1479
- if (ignoreInitialPush) ignoreInitialPush = false;
1480
- if (box.v === -1) return;
1481
- this._receiveFromDep(box.v, msg, delivery);
1482
- });
1483
- if (ignoreInitialPush && idx0 !== -1 && box.v !== -1) this._seedRestoredDepAt(idx0, depNode);
1484
- ignoreInitialPush = false;
1485
- if (idx0 !== -1) {
1486
- this._dep.unsubs[idx0] = unsub;
1487
- this._dep.idxBoxes[idx0] = box;
1488
- }
1489
- }
1490
- _seedRestoredDepAt(idx, depNode) {
1491
- const seedData = depNode._value.hasData && !depNode._slot.pull;
1492
- this._dep.batch[idx] = null;
1493
- this._dep.waveData[idx] = [];
1494
- this._dep.waveTokens[idx] = void 0;
1495
- this._dep.prev[idx] = seedData ? depNode._value.cache : SENTINEL;
1496
- this._dep.hasData[idx] = seedData;
1497
- this._dep.dirty[idx] = false;
1498
- this._dep.tier[idx] = seedData ? 3 : 0;
1499
- this._dep.terminal[idx] = depNode._value.terminal;
1500
- this._dep.terminalInput[idx] = void 0;
2385
+ nodeActivate(nodeRuntimeHost(this));
1501
2386
  }
1502
2387
  _deactivate() {
1503
- this._lifecycle.activated = false;
1504
- for (const u of this._dep.unsubs) if (u) u();
1505
- this._dep.unsubs = [];
1506
- this._dep.idxBoxes = [];
1507
- for (const fn of this._hooks.onDeactivation) fn();
1508
- this._hooks.onDeactivation = [];
1509
- this._hooks.onInvalidate = [];
1510
- const isCompute = this._slot.handle !== null || this._slot.deps.length > 0;
1511
- if (isCompute) {
1512
- this._value.cache = SENTINEL;
1513
- this._value.hasData = false;
1514
- this._value.status = "sentinel";
1515
- }
1516
- this._resetDepState();
1517
- this._wave.hasCalledFnOnce = false;
1518
- this._control.pauseLockset.clear();
1519
- this._control.pauseBuffer = [];
1520
- this._control.pausedDepWaveOccurred = false;
1521
- this._control.demandOwed = false;
1522
- this._value.replayRing = [];
1523
- if (!this._privateState.persist) this._privateState.value = SENTINEL;
2388
+ nodeDeactivate(nodeRuntimeHost(this));
1524
2389
  }
1525
2390
  _assertNotReleased(op) {
1526
2391
  if (this._released)
1527
2392
  throw new Error(`${op}: node has been released from its graph lifecycle (D122)`);
1528
2393
  }
1529
2394
  _subscriberCount() {
1530
- return this._lifecycle.subscribers.size;
2395
+ return nodeSubscriberCount(nodeRuntimeHost(this));
1531
2396
  }
1532
2397
  _isRuntimeQuiescentForRelease() {
1533
- const allowedPullQuietLock = this._slot.pull && this._control.pauseLockset.size === 1 && this._control.pauseLockset.has(this._slot.pullLock);
1534
- 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 && !this._control.inDeliverDemand && (this._control.pauseLockset.size === 0 || allowedPullQuietLock);
2398
+ return nodeIsRuntimeQuiescentForRelease(nodeRuntimeHost(this));
1535
2399
  }
1536
2400
  _releaseRuntime() {
1537
- if (this._released) return;
1538
- this._released = true;
1539
- releasedNodes.add(this);
1540
- let releaseError;
1541
- const recordReleaseError = (error) => {
1542
- if (releaseError === void 0) releaseError = error;
1543
- };
1544
- this._lifecycle.activated = false;
1545
- for (const u of this._dep.unsubs) {
1546
- try {
1547
- u();
1548
- } catch (error) {
1549
- recordReleaseError(error);
1550
- }
1551
- }
1552
- for (const fn of this._hooks.onDeactivation) {
1553
- try {
1554
- fn();
1555
- } catch (error) {
1556
- recordReleaseError(error);
1557
- }
1558
- }
1559
- this._dep.unsubs = [];
1560
- this._dep.idxBoxes = [];
1561
- this._lifecycle.subscribers.clear();
1562
- if (this._slot.handle !== null) {
1563
- this._slot.dispatcher.unregister(this._slot.handle);
1564
- this._slot.handle = null;
1565
- }
1566
- this._slot.deps = [];
1567
- this._dep.batch = [];
1568
- this._dep.waveData = [];
1569
- this._dep.waveTokens = [];
1570
- this._dep.prev = [];
1571
- this._dep.hasData = [];
1572
- this._dep.dirty = [];
1573
- this._dep.tier = [];
1574
- this._dep.terminal = [];
1575
- this._dep.terminalInput = [];
1576
- this._value.cache = SENTINEL;
1577
- this._value.hasData = false;
1578
- this._value.status = "sentinel";
1579
- this._value.terminal = void 0;
1580
- this._value.replayRing = [];
1581
- this._privateState.value = SENTINEL;
1582
- this._privateState.persist = false;
1583
- this._syncCtx = null;
1584
- this._resetDepState();
1585
- this._hooks.onDeactivation = [];
1586
- this._hooks.onInvalidate = [];
1587
- this._control.pauseLockset.clear();
1588
- this._control.pauseBuffer = [];
1589
- this._control.pausedDepWaveOccurred = false;
1590
- this._control.demandOwed = false;
1591
- this._restoredActivationPending = false;
1592
- checkpointReaders.delete(this);
1593
- restoreWriters.delete(this);
1594
- runtimeReleasers.delete(this);
1595
- runtimeQuiescenceReaders.delete(this);
1596
- subscriberCountReaders.delete(this);
1597
- activationReaders.delete(this);
1598
- ownerTokens.delete(this);
1599
- topologyDepsChangedObservers.delete(this);
1600
- this._core.releaseSlot(this._id);
1601
- if (releaseError !== void 0) throw releaseError;
2401
+ nodeReleaseRuntime(nodeRuntimeHost(this));
1602
2402
  }
1603
2403
  _resetDepState() {
1604
- const n = this._slot.deps.length;
1605
- for (let i = 0; i < n; i++) {
1606
- this._dep.batch[i] = null;
1607
- this._dep.waveData[i] = [];
1608
- this._dep.waveTokens[i] = void 0;
1609
- this._dep.prev[i] = SENTINEL;
1610
- this._dep.hasData[i] = false;
1611
- this._dep.dirty[i] = false;
1612
- this._dep.tier[i] = 0;
1613
- this._dep.terminal[i] = void 0;
1614
- this._dep.terminalInput[i] = void 0;
1615
- }
1616
- this._wave.pending = 0;
1617
- this._wave.emittedDirtyThisWave = false;
1618
- }
1619
- // ── upstream wave receive (two-phase + diamond) ──
2404
+ nodeResetDepState(nodeRuntimeHost(this));
2405
+ }
2406
+ _subscribeDepAt(depNode, opts = {}) {
2407
+ nodeSubscribeDepAt(nodeRuntimeHost(this), depNode, opts);
2408
+ }
2409
+ _seedRestoredDepAt(idx, depNode) {
2410
+ nodeSeedRestoredDepAt(nodeRuntimeHost(this), idx, depNode);
2411
+ }
1620
2412
  _recordDepProjection(idx, delivery) {
1621
- const token = delivery?.wave ?? {};
1622
- if (this._dep.waveTokens[idx] !== token) {
1623
- this._dep.waveData[idx].push([]);
1624
- this._dep.waveTokens[idx] = token;
1625
- }
1626
- return this._dep.waveData[idx][this._dep.waveData[idx].length - 1];
2413
+ return nodeRecordDepProjection(nodeRuntimeHost(this), idx, delivery);
1627
2414
  }
1628
2415
  _depProjectionHasData(idx) {
1629
- const projection = this._dep.waveData[idx][this._dep.waveData[idx].length - 1];
1630
- return projection?.some((v) => v !== SENTINEL) ?? false;
2416
+ return nodeDepProjectionHasData(nodeRuntimeHost(this), idx);
1631
2417
  }
1632
2418
  _receiveFromDep(idx, msg, delivery) {
1633
- if (this._released) return;
1634
- const t = msg[0];
1635
- if (t === "START") return;
1636
- const isLastInDeliveredWave = delivery?.last ?? true;
1637
- if (this._value.terminal !== void 0) {
1638
- if (t === "TEARDOWN") this._down([["TEARDOWN"]]);
1639
- return;
1640
- }
1641
- if (t === "INVALIDATE") {
1642
- const projection = this._recordDepProjection(idx, delivery);
1643
- projection.push(SENTINEL);
1644
- if (projection.some((v) => v !== SENTINEL) && isLastInDeliveredWave) this._maybeRun();
1645
- this._dep.prev[idx] = SENTINEL;
1646
- this._dep.hasData[idx] = false;
1647
- this._dep.batch[idx] = null;
1648
- if (this._dep.dirty[idx]) {
1649
- this._dep.dirty[idx] = false;
1650
- this._wave.pending--;
1651
- }
1652
- if (this._control.pausedDepWaveOccurred && this._dep.batch.every((b) => b === null)) {
1653
- this._control.pausedDepWaveOccurred = false;
1654
- }
1655
- const hadData = this._value.hasData;
1656
- this._invalidate();
1657
- if (this._wave.pending === 0 && this._wave.emittedDirtyThisWave) {
1658
- if (!hadData) this._down([["RESOLVED"]]);
1659
- else this._wave.emittedDirtyThisWave = false;
1660
- }
1661
- this._fireOwedDemandIfReady();
1662
- return;
1663
- }
1664
- if (isTerminal(t)) {
1665
- const isError = t === "ERROR";
1666
- const errPayload = isError ? msg[1] : void 0;
1667
- this._dep.terminal[idx] = isError ? errPayload : true;
1668
- this._dep.terminalInput[idx] = isError ? errPayload : true;
1669
- this._releaseDepDirty(idx);
1670
- const ranValueBeforeTerminal = this._depProjectionHasData(idx) && isLastInDeliveredWave;
1671
- if (ranValueBeforeTerminal) this._maybeRun();
1672
- if (isError && this._slot.errorWhenDepsError) {
1673
- this._down([["ERROR", errPayload]]);
1674
- } else if (this._slot.terminalAsRealInput) {
1675
- if (ranValueBeforeTerminal) {
1676
- this._fireOwedDemandIfReady();
1677
- return;
1678
- }
1679
- this._maybeRun();
1680
- } else if (this._slot.completeWhenDepsComplete && this._allDepsTerminal()) {
1681
- this._down([["COMPLETE"]]);
1682
- } else {
1683
- this._settleAfterAbsorbedTerminal();
1684
- }
1685
- this._fireOwedDemandIfReady();
1686
- return;
1687
- }
1688
- if (t === "TEARDOWN") {
1689
- this._down([["TEARDOWN"]]);
1690
- return;
1691
- }
1692
- if (t === "DIRTY") {
1693
- if (!this._dep.dirty[idx]) {
1694
- this._dep.dirty[idx] = true;
1695
- this._wave.pending++;
1696
- this._dep.tier[idx] = 2;
1697
- this._markDirty();
1698
- }
1699
- return;
1700
- }
1701
- if (t === "DATA") {
1702
- const v = msg[1];
1703
- this._recordDepProjection(idx, delivery).push(v);
1704
- const b = this._dep.batch[idx];
1705
- if (b === null) this._dep.batch[idx] = [v];
1706
- else b.push(v);
1707
- this._dep.prev[idx] = v;
1708
- this._dep.hasData[idx] = true;
1709
- this._dep.tier[idx] = 3;
1710
- if (this._dep.dirty[idx]) {
1711
- this._dep.dirty[idx] = false;
1712
- this._wave.pending--;
1713
- }
1714
- if (isLastInDeliveredWave) this._maybeRun();
1715
- this._fireOwedDemandIfReady();
1716
- return;
1717
- }
1718
- if (t === "RESOLVED") {
1719
- this._recordDepProjection(idx, delivery);
1720
- this._dep.tier[idx] = 3;
1721
- if (this._dep.dirty[idx]) {
1722
- this._dep.dirty[idx] = false;
1723
- this._wave.pending--;
1724
- }
1725
- if (isLastInDeliveredWave) this._maybeRun();
1726
- this._fireOwedDemandIfReady();
1727
- return;
1728
- }
2419
+ nodeReceiveFromDep(nodeRuntimeHost(this), idx, msg, delivery);
1729
2420
  }
1730
- /**
1731
- * R-terminal-settles-dirty (B35): release a dep's outstanding in-wave DIRTY contribution.
1732
- * A settle-class event for that dep (DATA/RESOLVED inline above, INVALIDATE, and now
1733
- * COMPLETE/ERROR) clears its dirty flag + decrements _pending. No-op if the dep already
1734
- * settled this wave (DATA/RESOLVED ran first) — so the normal DATA-then-COMPLETE flow is
1735
- * unaffected. This makes the exactly-one-settle invariant a single, shared step.
1736
- */
1737
2421
  _releaseDepDirty(idx) {
1738
- if (this._dep.dirty[idx]) {
1739
- this._dep.dirty[idx] = false;
1740
- this._wave.pending--;
1741
- }
2422
+ nodeReleaseDepDirty(nodeRuntimeHost(this), idx);
1742
2423
  }
1743
- /**
1744
- * R-terminal-settles-dirty (B35): settle a node whose dirtied dep was released by an ABSORBED
1745
- * terminal that is NOT a real input (a plain derived/effect — the common default-node case when
1746
- * one of several deps completes while others stay live). Runs only when the release drained
1747
- * _pending while the node still owes a downstream settle (it broadcast DIRTY this wave):
1748
- * - if some OTHER dep delivered real DATA this wave (a value occurred) → recompute (→ DATA);
1749
- * - else the terminal's signalled change did not materialise (no value) → one undirty RESOLVED
1750
- * (R-resolved-undirty), keeping the cache (a terminal, unlike INVALIDATE, leaves the value).
1751
- * A terminalAsRealInput node instead recomputes unconditionally (its fn reads the terminal).
1752
- */
1753
2424
  _settleAfterAbsorbedTerminal() {
1754
- if (this._wave.pending !== 0 || !this._wave.emittedDirtyThisWave) return;
1755
- const sawData = this._dep.batch.some((b) => b !== null && b.length > 0);
1756
- if (sawData) this._maybeRun();
1757
- if (this._wave.emittedDirtyThisWave) this._down([["RESOLVED"]]);
2425
+ nodeSettleAfterAbsorbedTerminal(nodeRuntimeHost(this));
1758
2426
  }
1759
2427
  _markDirty() {
1760
- this._value.status = "dirty";
1761
- if (this._isPullQuiet()) return;
1762
- if (!this._wave.emittedDirtyThisWave) {
1763
- this._wave.emittedDirtyThisWave = true;
1764
- this._emitToSubs(["DIRTY"]);
1765
- }
2428
+ nodeMarkDirty(nodeRuntimeHost(this));
1766
2429
  }
1767
2430
  _maybeRun() {
1768
- if (this._wave.inDepMutation) {
1769
- this._wave.rewireRunPending = true;
1770
- return;
1771
- }
1772
- if (this._slot.pausable === true && this._isPaused()) {
1773
- this._control.pausedDepWaveOccurred = true;
1774
- return;
1775
- }
1776
- this._tryRun();
2431
+ nodeMaybeRun(nodeRuntimeHost(this));
1777
2432
  }
1778
- /**
1779
- * R-rewire atomic settle (after a rewire that warrants a recompute): emit a proper
1780
- * two-phase DIRTY→DATA wave (R-dirty-before-data — a rewire-triggered settle is a wave),
1781
- * once, with every added dep already wired. Mirrors _maybeRun/_tryRun's pause + gate +
1782
- * pending guards, then injects the phase-1 DIRTY the added dep's [START,DATA] handshake
1783
- * did not carry.
1784
- */
1785
2433
  _settleRewire() {
1786
- if (this._slot.pausable === true && this._isPaused()) {
1787
- this._control.pausedDepWaveOccurred = true;
1788
- return;
1789
- }
1790
- if (this._wave.pending > 0) return;
1791
- if (this._slot.handle === null) {
1792
- this._passthroughEmit();
1793
- return;
1794
- }
1795
- if (!this._wave.hasCalledFnOnce && !(this._slot.partial || this._allDepsSettled())) return;
1796
- this._markDirty();
1797
- this._runWave();
2434
+ nodeSettleRewire(nodeRuntimeHost(this));
1798
2435
  }
1799
2436
  _tryRun() {
1800
- if (this._wave.pending > 0) return;
1801
- if (this._slot.handle === null) {
1802
- this._passthroughEmit();
1803
- return;
1804
- }
1805
- if (!this._wave.hasCalledFnOnce) {
1806
- if (this._slot.partial || this._allDepsSettled()) this._runWave();
1807
- return;
1808
- }
1809
- this._runWave();
2437
+ nodeTryRun(nodeRuntimeHost(this));
1810
2438
  }
1811
2439
  _allDepsSettled() {
1812
- for (let i = 0; i < this._slot.deps.length; i++) {
1813
- if (this._dep.hasData[i]) continue;
1814
- if (this._slot.terminalAsRealInput && this._dep.terminal[i] !== void 0) continue;
1815
- return false;
1816
- }
1817
- return true;
2440
+ return nodeAllDepsSettled(nodeRuntimeHost(this));
1818
2441
  }
1819
2442
  _passthroughEmit() {
1820
- const b = this._dep.batch[0];
1821
- if (b !== null && b.length > 0) {
1822
- this._down([["DATA", b[b.length - 1]]]);
1823
- } else if (this._wave.emittedDirtyThisWave) {
1824
- this._down([["RESOLVED"]]);
1825
- }
1826
- this._dep.batch[0] = null;
1827
- this._wave.emittedDirtyThisWave = false;
2443
+ nodePassthroughEmit(nodeRuntimeHost(this));
1828
2444
  }
1829
2445
  _runWave() {
1830
- if (this._wave.insideRunWave)
1831
- throw new Error(
1832
- "synchronous feedback cycle: node fn re-entered its own wave (R-reentrancy / D37)"
1833
- );
1834
- this._wave.hasCalledFnOnce = true;
1835
- this._hooks.onInvalidate = [];
1836
- this._hooks.onDeactivation = [];
1837
- const ctx = this._buildCtx();
1838
- const wasDirty = this._wave.emittedDirtyThisWave;
1839
- this._wave.emittedSettleThisWave = false;
1840
- this._wave.insideRunWave = true;
1841
- try {
1842
- this._slot.dispatcher.invoke(this._slot.handle, ctx);
1843
- } finally {
1844
- this._wave.insideRunWave = false;
1845
- }
1846
- if (wasDirty && !this._wave.emittedSettleThisWave && this._value.terminal === void 0 && !this._isAsyncPool()) {
1847
- this._down([["RESOLVED"]]);
1848
- }
1849
- for (let i = 0; i < this._dep.batch.length; i++) {
1850
- this._dep.batch[i] = null;
1851
- this._dep.waveData[i] = [];
1852
- this._dep.waveTokens[i] = void 0;
1853
- this._dep.terminalInput[i] = void 0;
1854
- }
1855
- this._wave.emittedDirtyThisWave = false;
2446
+ nodeRunWave(nodeRuntimeHost(this));
1856
2447
  }
1857
- // ── ctx construction (L3-Q5: sync = node-stable reused ctx; async = per-invocation) ──
1858
2448
  _buildCtx() {
1859
- const kind = this._slot.handle ? this._slot.dispatcher.poolKind(this._slot.handle.poolId) : "sync";
1860
- if (kind === "sync") {
1861
- if (this._syncCtx === null) this._syncCtx = this._makeCtx();
1862
- this._refreshCtx(this._syncCtx);
1863
- return this._syncCtx;
1864
- }
1865
- return this._makeCtx({
1866
- waveData: this._dep.waveData.map((waves) => waves.map((w) => [...w])),
1867
- terminal: this._dep.terminalInput.map(terminalView),
1868
- latest: [...this._dep.prev]
1869
- });
2449
+ return nodeBuildCtx(nodeRuntimeHost(this));
1870
2450
  }
1871
2451
  _makeCtx(snapshot) {
1872
- const ctx = {
1873
- // Wave-owner boundary (D47): a SYNC fn's emit nests under the public entry that drove
1874
- // it (cheap inc/dec, no early drain); an ASYNC-pool fn re-enters here from its stashed
1875
- // ctx at depth 0, so this is the boundary that drains any rewireNext it issued.
1876
- up: (msgs, towardDep) => {
1877
- if (this._released) return;
1878
- enterWave();
1879
- try {
1880
- this._up(msgs, towardDep);
1881
- } finally {
1882
- exitWave();
1883
- }
1884
- },
1885
- down: (msgs) => {
1886
- if (this._released) return;
1887
- enterWave();
1888
- try {
1889
- this._down(msgs);
1890
- } finally {
1891
- exitWave();
1892
- }
1893
- },
1894
- waveData: snapshot?.waveData ?? this._dep.waveData,
1895
- terminal: snapshot?.terminal ?? this._dep.terminalInput.map(terminalView),
1896
- state: this._makeState(),
1897
- onDeactivation: (fn) => {
1898
- if (this._released) return;
1899
- this._hooks.onDeactivation.push(fn);
1900
- },
1901
- onInvalidate: (fn) => {
1902
- if (this._released) return;
1903
- this._hooks.onInvalidate.push(fn);
1904
- },
1905
- environment: () => this._slot.environment,
1906
- // R-rewire-deferred (D47): defer a self-dep-set mutation to the committed boundary.
1907
- rewireNext: {
1908
- subscribeDep: (dep, fn) => this._requestRewireNext({ kind: "add", dep, fn }),
1909
- unsubscribeDep: (dep, fn) => this._requestRewireNext({ kind: "remove", dep, fn }),
1910
- replaceDeps: (deps, fn) => this._requestRewireNext({ kind: "set", deps, fn })
1911
- },
1912
- // R-up-routing / R-pull (D59): deferred up — route a control wave (e.g. a RESUME pull
1913
- // DEMAND) up the declared cone at the committed boundary. The SELF-demand path: an
1914
- // immediate ctx.up whose delivery loops back re-enters this fn (D37 / R-reentrancy).
1915
- upNext: (msgs, towardDep) => this._requestUpNext(msgs, towardDep),
1916
- [CTX_DEP_CACHE]: { latest: snapshot?.latest ?? this._dep.prev },
1917
- [CTX_NODE_BINDING]: {
1918
- dispatcher: this._slot.dispatcher,
1919
- create: (factory) => withEnvironmentDrivers(this._slot.environment, () => withNodeCore(this._core, factory))
1920
- }
1921
- };
1922
- if (this._slot.dynamic) {
1923
- ctx.track = (i) => ctx[CTX_DEP_CACHE]?.latest[i];
1924
- }
1925
- return ctx;
2452
+ return nodeMakeCtx(nodeRuntimeHost(this), snapshot);
1926
2453
  }
1927
2454
  _refreshCtx(ctx) {
1928
- ctx.waveData = this._dep.waveData;
1929
- ctx.terminal = this._dep.terminalInput.map(terminalView);
1930
- ctx[CTX_DEP_CACHE] = { latest: this._dep.prev };
2455
+ nodeRefreshCtx(nodeRuntimeHost(this), ctx);
1931
2456
  }
1932
2457
  _makeState() {
1933
- return {
1934
- get: () => this._privateState.value,
1935
- set: (v) => {
1936
- this._privateState.value = v;
1937
- },
1938
- persist: (on = true) => {
1939
- this._privateState.persist = on;
1940
- }
1941
- };
2458
+ return nodeMakeState(nodeRuntimeHost(this));
1942
2459
  }
1943
2460
  // ── downstream emission pipeline (the unified waist) ──
1944
2461
  _down(msgs) {
1945
- if (this._released) return;
1946
- validateDownPayloads(msgs);
1947
- const deliveryWave = {};
1948
- const assertVersionDataCompatible = (wave) => {
1949
- for (const m of wave) {
1950
- if (m[0] === "DATA") assertNodeVersionDataCompatible(this._version.policy, m[1]);
1951
- }
1952
- };
1953
- const snapshotVersionData = (wave) => wave.map(
1954
- (m) => m[0] === "DATA" ? ["DATA", snapshotNodeVersionData(this._version.policy, m[1])] : m
1955
- );
1956
- assertVersionDataCompatible(msgs);
1957
- if (this._value.terminal !== void 0) {
1958
- if (!msgs.some((m) => m[0] === "TEARDOWN")) return;
1959
- this._value.hasTorndown = true;
1960
- if (this._slot.resetOnTeardown) {
1961
- this._value.cache = SENTINEL;
1962
- this._value.hasData = false;
1963
- }
1964
- this._emitToSubs(["TEARDOWN"], { wave: deliveryWave, last: true });
1965
- return;
1966
- }
1967
- let sorted = [...msgs].sort((a, b) => messageTier(a[0]) - messageTier(b[0]));
1968
- const firstInvalidate = sorted.findIndex((m) => m[0] === "INVALIDATE");
1969
- if (firstInvalidate !== -1) {
1970
- sorted = sorted.filter((m, i) => m[0] !== "INVALIDATE" || i === firstInvalidate);
1971
- }
1972
- const hasTeardown = sorted.some((m) => m[0] === "TEARDOWN");
1973
- const hasTerminal = sorted.some((m) => m[0] === "COMPLETE" || m[0] === "ERROR");
1974
- if (hasTeardown && !hasTerminal && this._value.terminal === void 0 && !this._value.hasTorndown) {
1975
- sorted = [["COMPLETE"], ...sorted];
1976
- }
1977
- if (!this._wave.insideRunWave && currentBatch()) {
1978
- const deferred = snapshotVersionData(sorted.filter((m) => isDeferredTier(m[0])));
1979
- if (deferred.length > 0) {
1980
- if (!this._wave.emittedDirtyThisWave) {
1981
- this._wave.emittedDirtyThisWave = true;
1982
- this._value.status = "dirty";
1983
- this._emitToSubs(["DIRTY"], { wave: deliveryWave, last: false });
1984
- }
1985
- this._wave.batchDirtyOwed = true;
1986
- deferToBatch(this, deferred);
1987
- return;
1988
- }
1989
- }
1990
- if (this._shouldBufferOnPause()) {
1991
- const buffered = snapshotVersionData(sorted.filter((m) => isPauseBufferedTier(m[0])));
1992
- if (buffered.length > 0) {
1993
- this._wave.emittedSettleThisWave = true;
1994
- this._control.pauseBuffer.push(buffered);
1995
- }
1996
- sorted = sorted.filter((m) => !isPauseBufferedTier(m[0]));
1997
- if (sorted.length === 0) return;
1998
- }
1999
- let dataCount = 0;
2000
- let hasTier3 = false;
2001
- let hasResolved = false;
2002
- for (const m of sorted) {
2003
- if (m[0] === "DATA") dataCount++;
2004
- if (m[0] === "RESOLVED") hasResolved = true;
2005
- if (isValueTier(m[0])) hasTier3 = true;
2006
- }
2007
- if (dataCount >= 1 && hasResolved) {
2008
- throw new Error(
2009
- "down: a wave cannot mix DATA and RESOLVED (tier-3 exclusivity, R-resolved-undirty)"
2010
- );
2011
- }
2012
- const plannedVersions = new Array(sorted.length);
2013
- if (dataCount > 0) {
2014
- let plannedVersion = this._version.value;
2015
- for (let i = 0; i < sorted.length; i++) {
2016
- const m = sorted[i];
2017
- if (m[0] !== "DATA") continue;
2018
- plannedVersion = advanceNodeVersion(plannedVersion, this._version.policy, m[1]);
2019
- plannedVersions[i] = plannedVersion;
2020
- }
2021
- }
2022
- if (hasTier3 && !this._wave.insideRunWave && !this._wave.emittedDirtyThisWave) {
2023
- this._wave.emittedDirtyThisWave = true;
2024
- this._value.status = "dirty";
2025
- this._emitToSubs(["DIRTY"], { wave: deliveryWave, last: false });
2026
- }
2027
- for (let i = 0; i < sorted.length; i++) {
2028
- const m = sorted[i];
2029
- const delivery = { wave: deliveryWave, last: i === sorted.length - 1 };
2030
- if (isDeferredTier(m[0])) this._wave.emittedSettleThisWave = true;
2031
- if (m[0] === "DIRTY") {
2032
- if (!this._wave.emittedDirtyThisWave) {
2033
- this._wave.emittedDirtyThisWave = true;
2034
- this._value.status = "dirty";
2035
- this._emitToSubs(["DIRTY"], delivery);
2036
- }
2037
- continue;
2038
- }
2039
- if (m[0] === "DATA") {
2040
- const v = m[1];
2041
- this._value.cache = v;
2042
- this._value.hasData = true;
2043
- this._value.status = "settled";
2044
- this._version.value = plannedVersions[i];
2045
- if (this._slot.replayN > 0) {
2046
- this._value.replayRing.push(v);
2047
- if (this._value.replayRing.length > this._slot.replayN) this._value.replayRing.shift();
2048
- }
2049
- this._emitToSubs(["DATA", v], delivery);
2050
- continue;
2051
- }
2052
- if (m[0] === "RESOLVED") {
2053
- this._value.status = this._value.hasData ? "resolved" : "sentinel";
2054
- this._emitToSubs(["RESOLVED"], delivery);
2055
- continue;
2056
- }
2057
- if (m[0] === "INVALIDATE") {
2058
- this._invalidate(delivery);
2059
- continue;
2060
- }
2061
- if (m[0] === "COMPLETE") {
2062
- if (this._value.terminal !== void 0) continue;
2063
- this._value.terminal = true;
2064
- this._control.pauseBuffer = [];
2065
- this._value.status = "completed";
2066
- this._emitToSubs(["COMPLETE"], delivery);
2067
- continue;
2068
- }
2069
- if (m[0] === "ERROR") {
2070
- if (this._value.terminal !== void 0) continue;
2071
- this._value.terminal = m[1];
2072
- this._control.pauseBuffer = [];
2073
- this._value.status = "errored";
2074
- this._emitToSubs(["ERROR", m[1]], delivery);
2075
- continue;
2076
- }
2077
- if (m[0] === "TEARDOWN") {
2078
- this._value.hasTorndown = true;
2079
- if (this._slot.resetOnTeardown) {
2080
- this._value.cache = SENTINEL;
2081
- this._value.hasData = false;
2082
- }
2083
- this._emitToSubs(["TEARDOWN"], delivery);
2084
- }
2085
- }
2086
- if (!this._wave.insideRunWave) this._wave.emittedDirtyThisWave = false;
2462
+ nodeDown(nodeRuntimeHost(this), msgs);
2087
2463
  }
2088
2464
  _up(msgs, towardDep, route) {
2089
- if (this._released) return;
2090
- const routeState = route ?? { demandFired: /* @__PURE__ */ new Map() };
2091
- for (const m of msgs) {
2092
- if (!isUpAllowed(m[0])) {
2093
- throw new Error(
2094
- `ctx.up: ${m[0]} is down-only (tier ${messageTier(m[0])}); up carries control tiers only (R-ctx-up)`
2095
- );
2096
- }
2097
- }
2098
- for (const m of msgs) {
2099
- if (m[0] === "PAUSE") {
2100
- this._pauseAcquire(m[1]);
2101
- } else if (m[0] === "RESUME") {
2102
- if (this._slot.pull && m[1] === this._slot.pullLock) {
2103
- if (!this._markDemandRouted(m[1], routeState)) this._onDemand();
2104
- } else if (this._control.pauseLockset.has(m[1])) {
2105
- this._pauseRelease(m[1]);
2106
- } else {
2107
- this._forwardUp(m, towardDep, routeState);
2108
- }
2109
- } else if (this._slot.deps.length === 0) {
2110
- if (m[0] === "INVALIDATE") this._down([["INVALIDATE"]]);
2111
- } else {
2112
- this._forwardUp(m, towardDep, routeState);
2113
- }
2114
- }
2465
+ nodeUp(nodeRuntimeHost(this), msgs, towardDep, route);
2115
2466
  }
2116
2467
  _markDemandRouted(lockId, route) {
2117
- let holders = route.demandFired.get(lockId);
2118
- if (holders === void 0) {
2119
- holders = /* @__PURE__ */ new Set();
2120
- route.demandFired.set(lockId, holders);
2121
- }
2122
- if (holders.has(this)) return true;
2123
- holders.add(this);
2124
- return false;
2468
+ return nodeMarkDemandRouted(nodeRuntimeHost(this), lockId, route);
2125
2469
  }
2126
- /**
2127
- * Forward one up-going control message toward deps (R-up-routing): up the single declared edge
2128
- * `towardDep` (directed — prunes other branches; only meaningful on the issuer's FIRST hop) or
2129
- * broadcast up ALL deps. A depless source has no deps → the message DROPS here (the terminus —
2130
- * e.g. a cone-routed RESUME whose pullId no node up this cone holds, R-up-at-source). Recursive
2131
- * forwarding carries the same per-wave route state and no `towardDep` → broadcast beyond the
2132
- * first hop.
2133
- */
2134
2470
  _forwardUp(m, towardDep, route) {
2135
- if (this._slot.deps.length === 0) return;
2136
- if (towardDep !== void 0) {
2137
- const d = this._slot.deps[towardDep];
2138
- if (d !== void 0) d._up([m], void 0, route);
2139
- } else {
2140
- for (const dep of this._slot.deps) dep._up([m], void 0, route);
2141
- }
2471
+ nodeForwardUp(nodeRuntimeHost(this), m, towardDep, route);
2142
2472
  }
2143
- // ── PAUSE/RESUME lockset (R-pause-lockset) + modes (R-pause-modes) ──
2144
2473
  _isPaused() {
2145
- return this._control.pauseLockset.size > 0;
2474
+ return nodeIsPaused(nodeRuntimeHost(this));
2146
2475
  }
2147
2476
  _hasBoundaryPauseLock() {
2148
- if (this._slot.pausable === false) return false;
2149
- let locks = this._control.pauseLockset.size;
2150
- if (this._slot.pull && this._control.pauseLockset.has(this._slot.pullLock)) locks--;
2151
- return locks > 0;
2477
+ return nodeHasBoundaryPauseLock(nodeRuntimeHost(this));
2152
2478
  }
2153
2479
  _isAsyncPool() {
2154
- return this._slot.handle !== null && this._slot.dispatcher.poolKind(this._slot.handle.poolId) === "async";
2480
+ return nodeIsAsyncPool(nodeRuntimeHost(this));
2155
2481
  }
2156
2482
  _pauseAcquire(lockId) {
2157
- this._control.pauseLockset.add(lockId);
2483
+ nodePauseAcquire(nodeRuntimeHost(this), lockId);
2158
2484
  }
2159
2485
  _pauseRelease(lockId) {
2160
- if (!this._control.pauseLockset.has(lockId)) return;
2161
- this._control.pauseLockset.delete(lockId);
2162
- if (this._slot.pull && this._control.demandOwed) this._fireOwedDemandIfReady();
2163
- if (this._hasBoundaryPauseLock()) return;
2164
- scheduleBoundaryDrain(this._core);
2165
- if (this._control.pauseLockset.size > 0) return;
2166
- this._onResume();
2486
+ nodePauseRelease(nodeRuntimeHost(this), lockId);
2167
2487
  }
2168
2488
  _onResume() {
2169
- if (this._value.terminal !== void 0) {
2170
- this._control.pauseBuffer = [];
2171
- this._control.pausedDepWaveOccurred = false;
2172
- this._control.demandOwed = false;
2173
- return;
2174
- }
2175
- if (this._control.pauseBuffer.length > 0) {
2176
- const buf = this._control.pauseBuffer;
2177
- this._control.pauseBuffer = [];
2178
- for (const wave of buf) this._down(wave);
2179
- }
2180
- if (this._control.pausedDepWaveOccurred) {
2181
- this._control.pausedDepWaveOccurred = false;
2182
- this._tryRun();
2183
- }
2489
+ nodeOnResume(nodeRuntimeHost(this));
2184
2490
  }
2185
- /**
2186
- * R-pull (D59): can this pull node fire a demand NOW? — not terminal, settle-ready (_pending===0),
2187
- * and no OTHER (non-pullId) lock holds it paused. The gate that decides fire-now vs OWE.
2188
- */
2189
2491
  _canFireDemand() {
2190
- if (this._value.terminal !== void 0 || this._wave.pending > 0) return false;
2191
- const own = this._control.pauseLockset.has(this._slot.pullLock) ? 1 : 0;
2192
- return this._control.pauseLockset.size <= own;
2492
+ return nodeCanFireDemand(nodeRuntimeHost(this));
2193
2493
  }
2194
- /**
2195
- * R-pull (D59): deliver ONE demand pulse — release the pullId so the demand wave RELAYS (not
2196
- * absorbed), fire it, then RE-QUIET (1:1). The pullId re-add + the re-entrancy flag are in a
2197
- * `finally` so a throwing pull fn (graph-less node, no D30 catch) cannot leave the node
2198
- * permanently non-quiet (the wedge-fix silently disabled) — QA-found robustness fix.
2199
- */
2200
- _deliverPullDemand() {
2201
- this._control.demandOwed = false;
2202
- this._control.inDeliverDemand = true;
2203
- this._control.pauseLockset.delete(this._slot.pullLock);
2204
- try {
2205
- this._firePullDemand();
2206
- } finally {
2207
- this._control.pauseLockset.add(this._slot.pullLock);
2208
- this._control.inDeliverDemand = false;
2209
- }
2494
+ _deliverPullDemand(demand) {
2495
+ nodeDeliverPullDemand(nodeRuntimeHost(this), demand);
2210
2496
  }
2211
- /**
2212
- * R-pull (D59): a cone-routed RESUME of THIS node's pullId arrived (R-up-routing) = a DEMAND.
2213
- * Fire immediately if able; else OWE it — pin-5 (a dep DIRTY in flight, _pending>0) or F4/F5 (an
2214
- * external PAUSE lock co-holds the node) — and fire when the node next becomes able. A demand
2215
- * arriving WHILE a delivery is in flight (synchronous re-entry) is DROPPED (1:1, QA guard).
2216
- */
2217
- _onDemand() {
2218
- if (this._control.inDeliverDemand) return;
2219
- if (this._canFireDemand()) this._deliverPullDemand();
2220
- else this._control.demandOwed = true;
2497
+ _onDemand(demand) {
2498
+ nodeOnDemand(nodeRuntimeHost(this), demand);
2221
2499
  }
2222
- /**
2223
- * R-pull (D55): service ONE demand. Delivery content = the orthogonal pausable mode:
2224
- * - 'resumeAll' → drain the buffered BACKLOG (each `_down` re-synthesizes a leading DIRTY, so
2225
- * the per-entry replay is DIRTY-before-DATA — R-pause-modes per-entry arrival order);
2226
- * - true → deliver the coalesced LATEST as ONE DIRTY-before-DATA wave (pin 2: the quiet absorb
2227
- * suppressed the dep's original DIRTY, so the demand wave restores it before the value).
2228
- * Neither branch fires when nothing changed since the last demand → the demand is SILENT.
2229
- * Called by `_deliverPullDemand` only when settle-ready; the caller has released the pullId, so
2230
- * `_markDirty` relays the leading DIRTY (not absorbed).
2231
- */
2232
2500
  _firePullDemand() {
2233
- if (this._control.pauseBuffer.length > 0) {
2234
- const buf = this._control.pauseBuffer;
2235
- this._control.pauseBuffer = [];
2236
- for (const wave of buf) this._down(wave);
2237
- }
2238
- if (this._control.pausedDepWaveOccurred) {
2239
- const gated = this._slot.handle !== null && !this._wave.hasCalledFnOnce && !(this._slot.partial || this._allDepsSettled());
2240
- if (this._wave.pending > 0 || gated) return;
2241
- this._control.pausedDepWaveOccurred = false;
2242
- this._markDirty();
2243
- this._tryRun();
2244
- }
2501
+ nodeFirePullDemand(nodeRuntimeHost(this));
2245
2502
  }
2246
- /**
2247
- * R-pull (D55/D59): fire a demand that was OWED (deferred at demand time) once the node becomes
2248
- * able — called from the dep-settle arms (DATA/RESOLVED/INVALIDATE/terminal drain _pending, pin-5
2249
- * + B1/F6) and from `_pauseRelease` (an external PAUSE lock releases, F4/F5).
2250
- */
2251
2503
  _fireOwedDemandIfReady() {
2252
- if (this._control.inDeliverDemand) return;
2253
- if (this._slot.pull && this._control.demandOwed && this._canFireDemand())
2254
- this._deliverPullDemand();
2504
+ nodeFireOwedDemandIfReady(nodeRuntimeHost(this));
2255
2505
  }
2256
- /** Should an outgoing settle slice be deferred into the pause buffer? */
2257
2506
  _shouldBufferOnPause() {
2258
- if (this._slot.pausable === false) return false;
2259
- if (!this._isPaused()) return false;
2260
- if (this._slot.pausable === "resumeAll") return true;
2261
- if (!this._wave.insideRunWave && this._isAsyncPool() && this._slot.deps.length > 0) return true;
2262
- return false;
2507
+ return nodeShouldBufferOnPause(nodeRuntimeHost(this));
2263
2508
  }
2264
- /** R-invalidate-idempotent: clear cache + flush + cascade; no-op if nothing cached. */
2265
2509
  _invalidate(delivery) {
2266
- if (!this._value.hasData) return;
2267
- this._value.cache = SENTINEL;
2268
- this._value.hasData = false;
2269
- this._value.status = "sentinel";
2270
- this._value.replayRing = [];
2271
- for (const fn of this._hooks.onInvalidate) fn();
2272
- this._emitToSubs(["INVALIDATE"], delivery);
2273
- }
2274
- // B42 (R-deps-terminal): ALL deps TERMINAL = every dep has reached COMPLETE *or* an ABSORBED
2275
- // ERROR. Block only on a LIVE dep (_depTerminal[i] === undefined); an errored dep (terminal = the
2276
- // error payload, which R-data-payload guarantees is !== undefined and non-boolean) COUNTS as
2277
- // terminal-done. Was
2278
- // `tm !== true`, which wedged a node whose errorWhenDepsError:false dep ERRORed (it never
2279
- // auto-completed even after every other dep completed). Drives the completeWhenDepsComplete cascade.
2510
+ nodeInvalidate(nodeRuntimeHost(this), delivery);
2511
+ }
2280
2512
  _allDepsTerminal() {
2281
- if (this._slot.deps.length === 0) return false;
2282
- for (const tm of this._dep.terminal) if (tm === void 0) return false;
2283
- return true;
2513
+ return nodeAllDepsTerminal(nodeRuntimeHost(this));
2514
+ }
2515
+ _emitToSubs(msg, delivery) {
2516
+ nodeEmitToSubs(nodeRuntimeHost(this), msg, delivery);
2284
2517
  }
2285
2518
  /** R-terminal: resubscribable reset clears terminal + dep state + re-arms the gate. */
2286
2519
  _resetLifecycle() {
2287
- for (const u of this._dep.unsubs) if (u) u();
2288
- this._dep.unsubs = [];
2289
- this._dep.idxBoxes = [];
2290
- this._lifecycle.subscribers.clear();
2291
- this._lifecycle.activated = false;
2292
- this._value.terminal = void 0;
2293
- this._value.hasTorndown = false;
2294
- this._wave.hasCalledFnOnce = false;
2295
- this._resetDepState();
2296
- this._control.pauseLockset.clear();
2297
- this._control.pauseBuffer = [];
2298
- this._control.pausedDepWaveOccurred = false;
2299
- this._control.demandOwed = false;
2300
- this._value.replayRing = [];
2301
- const isCompute = this._slot.handle !== null || this._slot.deps.length > 0;
2302
- if (isCompute) {
2303
- this._value.cache = SENTINEL;
2304
- this._value.hasData = false;
2305
- this._value.status = "sentinel";
2306
- } else {
2307
- this._value.status = this._value.hasData ? "settled" : "sentinel";
2308
- }
2309
- if (!this._privateState.persist) this._privateState.value = SENTINEL;
2310
- }
2311
- _emitToSubs(msg, delivery) {
2312
- if (this._released) return;
2313
- const subs = [...this._lifecycle.subscribers];
2314
- for (const sink of subs) sink(msg, delivery);
2520
+ nodeResetLifecycle(nodeRuntimeHost(this));
2315
2521
  }
2316
2522
  /** Batch commit (R-batch-coalesce): deliver the deferred tier-3 wave now. */
2317
2523
  __commitBatchedWave(wave) {
2318
- this._wave.batchDirtyOwed = false;
2319
- this._down(wave);
2524
+ nodeCommitBatchedWave(nodeRuntimeHost(this), wave);
2320
2525
  }
2321
2526
  /** Batch rollback: balance the immediate DIRTY with a RESOLVED so downstream un-dirties. */
2322
2527
  __rollbackBatched() {
2323
- if (this._wave.batchDirtyOwed) {
2324
- this._wave.batchDirtyOwed = false;
2325
- this._wave.emittedDirtyThisWave = false;
2326
- this._value.status = this._value.hasData ? "settled" : "sentinel";
2327
- this._emitToSubs(["RESOLVED"]);
2328
- }
2528
+ nodeRollbackBatched(nodeRuntimeHost(this));
2329
2529
  }
2330
2530
  /** B49: enqueue a committed-boundary task on this node's graph-local core. */
2331
2531
  __deferBoundary(fn, batchToken) {
2332
- deferRewire(this._core, fn, {
2333
- batchToken,
2334
- isReady: () => !this._hasBoundaryPauseLock()
2335
- });
2532
+ nodeDeferBoundary(nodeRuntimeHost(this), fn, batchToken);
2336
2533
  }
2337
2534
  };
2338
2535