@graphrefly/ts 0.0.1 → 0.0.2

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