@logixjs/core 0.0.1 → 1.0.0

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 (398) hide show
  1. package/LICENSE +201 -0
  2. package/dist/{Action-mqVvtEHt.d.ts → Action-DYl88bwj.d.ts} +1 -1
  3. package/dist/{Action-BkRHy2vg.d.cts → Action-DkxsI_DK.d.cts} +1 -1
  4. package/dist/Action.cjs.map +1 -1
  5. package/dist/Action.d.cts +1 -1
  6. package/dist/Action.d.ts +1 -1
  7. package/dist/Action.js +2 -2
  8. package/dist/{Actions-AsQ07yTP.d.cts → Actions-Dicm7jdc.d.cts} +2 -2
  9. package/dist/{Actions-AsQ07yTP.d.ts → Actions-Dicm7jdc.d.ts} +2 -2
  10. package/dist/Actions.cjs.map +1 -1
  11. package/dist/Actions.d.cts +1 -1
  12. package/dist/Actions.d.ts +1 -1
  13. package/dist/Actions.js +1 -1
  14. package/dist/{Bound-BN1DQ_lM.d.ts → Bound-1OJLzVIS.d.ts} +2 -2
  15. package/dist/{Bound-BPIfH9SS.d.cts → Bound-BMLrtQ1V.d.cts} +2 -2
  16. package/dist/Bound.cjs +1737 -399
  17. package/dist/Bound.cjs.map +1 -1
  18. package/dist/Bound.d.cts +5 -5
  19. package/dist/Bound.d.ts +5 -5
  20. package/dist/Bound.js +19 -17
  21. package/dist/{Debug-B5q5Bkzx.d.ts → Debug-DKrWP5H1.d.ts} +40 -22
  22. package/dist/{Debug-Bq8Sqjcr.d.cts → Debug-hIT44XsY.d.cts} +40 -22
  23. package/dist/Debug.cjs +1348 -318
  24. package/dist/Debug.cjs.map +1 -1
  25. package/dist/Debug.d.cts +12 -11
  26. package/dist/Debug.d.ts +12 -11
  27. package/dist/Debug.js +20 -11
  28. package/dist/EffectOp.cjs +15 -6
  29. package/dist/EffectOp.cjs.map +1 -1
  30. package/dist/EffectOp.js +3 -3
  31. package/dist/Env.cjs +772 -6
  32. package/dist/Env.cjs.map +1 -1
  33. package/dist/Env.js +5 -2
  34. package/dist/ExternalStore-DqJKKRJ4.d.ts +61 -0
  35. package/dist/ExternalStore-JC-gAgEI.d.cts +61 -0
  36. package/dist/ExternalStore.cjs +774 -0
  37. package/dist/ExternalStore.cjs.map +1 -0
  38. package/dist/ExternalStore.d.cts +8 -0
  39. package/dist/ExternalStore.d.ts +8 -0
  40. package/dist/ExternalStore.js +19 -0
  41. package/dist/ExternalStore.js.map +1 -0
  42. package/dist/{Flow-BhpjE22E.d.ts → Flow-CZmXRDqp.d.cts} +13 -4
  43. package/dist/{Flow-1fZT8MpX.d.cts → Flow-DIVDxz7R.d.ts} +13 -4
  44. package/dist/Flow.cjs +765 -148
  45. package/dist/Flow.cjs.map +1 -1
  46. package/dist/Flow.d.cts +6 -6
  47. package/dist/Flow.d.ts +6 -6
  48. package/dist/Flow.js +9 -8
  49. package/dist/{Handle-D_cLW1Z3.d.ts → Handle-Bo6cAFut.d.ts} +1 -1
  50. package/dist/{Handle-D8D1zPb_.d.cts → Handle-CfDvSqN7.d.cts} +1 -1
  51. package/dist/Handle.d.cts +5 -5
  52. package/dist/Handle.d.ts +5 -5
  53. package/dist/{Kernel-8kC-jOda.d.cts → Kernel-CuXBF9S_.d.cts} +16 -7
  54. package/dist/{Kernel-CnGE1Fyk.d.ts → Kernel-D9guNwRL.d.ts} +16 -7
  55. package/dist/Kernel.cjs +814 -26
  56. package/dist/Kernel.cjs.map +1 -1
  57. package/dist/Kernel.d.cts +13 -12
  58. package/dist/Kernel.d.ts +13 -12
  59. package/dist/Kernel.js +7 -4
  60. package/dist/{Link-Db7975nU.d.ts → Link-CUM0yUCH.d.ts} +10 -3
  61. package/dist/{Link-fX8x1eCK.d.cts → Link-NAfR6uGD.d.cts} +10 -3
  62. package/dist/Link.cjs +1294 -121
  63. package/dist/Link.cjs.map +1 -1
  64. package/dist/Link.d.cts +5 -5
  65. package/dist/Link.d.ts +5 -5
  66. package/dist/Link.js +37 -29
  67. package/dist/{Logic-DRh4sDZj.d.cts → Logic-09VQpIj3.d.cts} +7 -4
  68. package/dist/{Logic-BRjEMr-W.d.ts → Logic-DKg7ghGy.d.ts} +7 -4
  69. package/dist/Logic.cjs +2 -1
  70. package/dist/Logic.cjs.map +1 -1
  71. package/dist/Logic.d.cts +5 -5
  72. package/dist/Logic.d.ts +5 -5
  73. package/dist/Logic.js +1 -1
  74. package/dist/{MatchBuilder-CJk5oCkR.d.cts → MatchBuilder-CsW5jgrL.d.ts} +1 -1
  75. package/dist/{MatchBuilder-0QOc-nlU.d.ts → MatchBuilder-Dksk07F4.d.cts} +1 -1
  76. package/dist/MatchBuilder.cjs +2 -2
  77. package/dist/MatchBuilder.cjs.map +1 -1
  78. package/dist/MatchBuilder.d.cts +6 -6
  79. package/dist/MatchBuilder.d.ts +6 -6
  80. package/dist/MatchBuilder.js +2 -2
  81. package/dist/Middleware-D8tUDLv_.d.cts +100 -0
  82. package/dist/Middleware-DS7CbTTN.d.ts +100 -0
  83. package/dist/Middleware.cjs +678 -58
  84. package/dist/Middleware.cjs.map +1 -1
  85. package/dist/Middleware.d.cts +2 -86
  86. package/dist/Middleware.d.ts +2 -86
  87. package/dist/Middleware.js +15 -12
  88. package/dist/{Module-DnzluX2J.d.ts → Module-B_Cntyms.d.ts} +54 -25
  89. package/dist/{Module-B_0xRDMR.d.cts → Module-CmNOVXzf.d.cts} +54 -25
  90. package/dist/Module.cjs +9331 -3317
  91. package/dist/Module.cjs.map +1 -1
  92. package/dist/Module.d.cts +7 -6
  93. package/dist/Module.d.ts +7 -6
  94. package/dist/Module.js +39 -31
  95. package/dist/ModuleTag-CGho_InD.d.ts +113 -0
  96. package/dist/ModuleTag-CITb8L_G.d.cts +113 -0
  97. package/dist/ModuleTag.cjs +7248 -2847
  98. package/dist/ModuleTag.cjs.map +1 -1
  99. package/dist/ModuleTag.d.cts +6 -6
  100. package/dist/ModuleTag.d.ts +6 -6
  101. package/dist/ModuleTag.js +35 -29
  102. package/dist/Observability-Bdhnx2Dv.d.ts +385 -0
  103. package/dist/Observability-DXGAFBIT.d.cts +385 -0
  104. package/dist/Observability.cjs +5093 -1556
  105. package/dist/Observability.cjs.map +1 -1
  106. package/dist/Observability.d.cts +6 -7
  107. package/dist/Observability.d.ts +6 -7
  108. package/dist/Observability.js +28 -23
  109. package/dist/{Platform-CHX8o-U4.d.ts → Platform-B4s8tg6C.d.cts} +4 -5
  110. package/dist/{Platform-C49Pv956.d.cts → Platform-BV_0MW7g.d.cts} +5 -2
  111. package/dist/{Platform-C49Pv956.d.ts → Platform-BV_0MW7g.d.ts} +5 -2
  112. package/dist/{Platform-CVlv0xLQ.d.cts → Platform-W0Mefy_e.d.ts} +4 -5
  113. package/dist/Platform.cjs +2 -1
  114. package/dist/Platform.cjs.map +1 -1
  115. package/dist/Platform.d.cts +2 -3
  116. package/dist/Platform.d.ts +2 -3
  117. package/dist/Platform.js +2 -2
  118. package/dist/{Process-CM9xbMdP.d.ts → Process-CO8G7HO9.d.cts} +30 -5
  119. package/dist/{Process-mL8fHDSB.d.cts → Process-Cyf6VNDR.d.ts} +30 -5
  120. package/dist/Process.cjs +1288 -120
  121. package/dist/Process.cjs.map +1 -1
  122. package/dist/Process.d.cts +6 -6
  123. package/dist/Process.d.ts +6 -6
  124. package/dist/Process.js +34 -26
  125. package/dist/ReadQuery-C_or5nLC.d.ts +128 -0
  126. package/dist/ReadQuery-DXLzCE0E.d.cts +614 -0
  127. package/dist/ReadQuery-DXLzCE0E.d.ts +614 -0
  128. package/dist/ReadQuery-Yve1lmUo.d.cts +128 -0
  129. package/dist/ReadQuery.cjs +290 -5
  130. package/dist/ReadQuery.cjs.map +1 -1
  131. package/dist/ReadQuery.d.cts +3 -2
  132. package/dist/ReadQuery.d.ts +3 -2
  133. package/dist/ReadQuery.js +23 -5
  134. package/dist/{Reflection-CQnKwPXj.d.ts → Reflection-B2Xi1e4Q.d.ts} +89 -7
  135. package/dist/{Reflection-Kabo1mlU.d.cts → Reflection-DNB4V4_e.d.cts} +89 -7
  136. package/dist/Reflection.cjs +3227 -1617
  137. package/dist/Reflection.cjs.map +1 -1
  138. package/dist/Reflection.d.cts +17 -15
  139. package/dist/Reflection.d.ts +17 -15
  140. package/dist/Reflection.js +33 -25
  141. package/dist/{Resource-Dy1xD_DG.d.cts → Resource-pKvQQ4x5.d.cts} +3 -3
  142. package/dist/{Resource-Dy1xD_DG.d.ts → Resource-pKvQQ4x5.d.ts} +3 -3
  143. package/dist/Resource.cjs +781 -15
  144. package/dist/Resource.cjs.map +1 -1
  145. package/dist/Resource.d.cts +1 -1
  146. package/dist/Resource.d.ts +1 -1
  147. package/dist/Resource.js +6 -3
  148. package/dist/{Root-7ADUMk4t.d.cts → Root-CCVuFHB6.d.cts} +3 -3
  149. package/dist/{Root-7ADUMk4t.d.ts → Root-CCVuFHB6.d.ts} +3 -3
  150. package/dist/Root.cjs +786 -20
  151. package/dist/Root.cjs.map +1 -1
  152. package/dist/Root.d.cts +2 -2
  153. package/dist/Root.d.ts +2 -2
  154. package/dist/Root.js +7 -3
  155. package/dist/{Runtime-CtyzZG4i.d.ts → Runtime-CRmvwK4I.d.ts} +70 -14
  156. package/dist/{Runtime-B-aL-f29.d.cts → Runtime-C_wJM9mN.d.cts} +70 -14
  157. package/dist/Runtime.cjs +4942 -1601
  158. package/dist/Runtime.cjs.map +1 -1
  159. package/dist/Runtime.d.cts +17 -15
  160. package/dist/Runtime.d.ts +17 -15
  161. package/dist/Runtime.js +44 -32
  162. package/dist/{ScopeRegistry-D1owDNSm.d.cts → ScopeRegistry-BhYzqWri.d.cts} +6 -6
  163. package/dist/{ScopeRegistry-D1owDNSm.d.ts → ScopeRegistry-BhYzqWri.d.ts} +6 -6
  164. package/dist/ScopeRegistry.cjs +776 -10
  165. package/dist/ScopeRegistry.cjs.map +1 -1
  166. package/dist/ScopeRegistry.d.cts +1 -1
  167. package/dist/ScopeRegistry.d.ts +1 -1
  168. package/dist/ScopeRegistry.js +6 -3
  169. package/dist/{State-CU50R26M.d.cts → State-rNFsFPTl.d.cts} +2 -2
  170. package/dist/{State-CU50R26M.d.ts → State-rNFsFPTl.d.ts} +2 -2
  171. package/dist/State.cjs.map +1 -1
  172. package/dist/State.d.cts +1 -1
  173. package/dist/State.d.ts +1 -1
  174. package/dist/State.js +1 -1
  175. package/dist/{StateTrait-BGsZghTz.d.ts → StateTrait-CijdwNb6.d.ts} +25 -8
  176. package/dist/{StateTrait-OWhbj12c.d.cts → StateTrait-Dltto6PU.d.cts} +25 -8
  177. package/dist/StateTrait.cjs +1890 -528
  178. package/dist/StateTrait.cjs.map +1 -1
  179. package/dist/StateTrait.d.cts +9 -7
  180. package/dist/StateTrait.d.ts +9 -7
  181. package/dist/StateTrait.js +18 -14
  182. package/dist/{TraitLifecycle-CwV5WPFX.d.cts → TraitLifecycle-BKzDqzLu.d.cts} +2 -2
  183. package/dist/{TraitLifecycle-LdIWmKlg.d.ts → TraitLifecycle-Cvo94uDB.d.ts} +2 -2
  184. package/dist/TraitLifecycle.cjs +630 -67
  185. package/dist/TraitLifecycle.cjs.map +1 -1
  186. package/dist/TraitLifecycle.d.cts +6 -6
  187. package/dist/TraitLifecycle.d.ts +6 -6
  188. package/dist/TraitLifecycle.js +8 -7
  189. package/dist/Workflow-C_OWr4dV.d.ts +415 -0
  190. package/dist/Workflow-DmydkHO8.d.cts +415 -0
  191. package/dist/Workflow.cjs +3150 -0
  192. package/dist/Workflow.cjs.map +1 -0
  193. package/dist/Workflow.d.cts +7 -0
  194. package/dist/Workflow.d.ts +7 -0
  195. package/dist/Workflow.js +58 -0
  196. package/dist/Workflow.js.map +1 -0
  197. package/dist/{action-DiMDD_0v.d.cts → action-BQxjPFEw.d.cts} +5 -5
  198. package/dist/{action-DiMDD_0v.d.ts → action-BQxjPFEw.d.ts} +5 -5
  199. package/dist/chunk-2XRLXDWR.js +276 -0
  200. package/dist/chunk-2XRLXDWR.js.map +1 -0
  201. package/dist/chunk-3L6QGFMM.js +701 -0
  202. package/dist/chunk-3L6QGFMM.js.map +1 -0
  203. package/dist/{chunk-GMPEOUP2.js → chunk-4MZ7BT3R.js} +2 -2
  204. package/dist/chunk-4MZ7BT3R.js.map +1 -0
  205. package/dist/{chunk-3IYZ5IGG.js → chunk-5WKUGEBY.js} +2 -2
  206. package/dist/{chunk-3RMKLXHX.js → chunk-63ZQ5RIN.js} +2 -2
  207. package/dist/{chunk-M3WTHJHJ.js → chunk-67DIEA53.js} +385 -148
  208. package/dist/chunk-67DIEA53.js.map +1 -0
  209. package/dist/{chunk-YS3AZQ2G.js → chunk-6HFAW2MH.js} +1 -1
  210. package/dist/chunk-6HFAW2MH.js.map +1 -0
  211. package/dist/{chunk-EY4NZKDR.js → chunk-6Y2TKCNY.js} +2 -2
  212. package/dist/{chunk-76WT3HOR.js → chunk-6YZOXFPQ.js} +25 -24
  213. package/dist/chunk-6YZOXFPQ.js.map +1 -0
  214. package/dist/{chunk-G5ZBFPNU.js → chunk-A2RQOJC7.js} +2 -2
  215. package/dist/{chunk-AUIR5O6W.js → chunk-AFSB6NKM.js} +13 -19
  216. package/dist/chunk-AFSB6NKM.js.map +1 -0
  217. package/dist/{chunk-JCXGZRMU.js → chunk-AO4JEOKD.js} +22 -23
  218. package/dist/chunk-AO4JEOKD.js.map +1 -0
  219. package/dist/{chunk-TAAPQVZN.js → chunk-AYELIQXR.js} +2 -2
  220. package/dist/{chunk-QMM6O4CD.js → chunk-BLHZW7DG.js} +15 -3
  221. package/dist/{chunk-QMM6O4CD.js.map → chunk-BLHZW7DG.js.map} +1 -1
  222. package/dist/{chunk-TQOBJYDP.js → chunk-CD4N74YC.js} +1 -1
  223. package/dist/chunk-CD4N74YC.js.map +1 -0
  224. package/dist/{chunk-ANLBCBDC.js → chunk-CGE2HBTH.js} +11 -11
  225. package/dist/chunk-CGE2HBTH.js.map +1 -0
  226. package/dist/{chunk-OFADUJWJ.js → chunk-CYYSQMLO.js} +5 -5
  227. package/dist/chunk-CYYSQMLO.js.map +1 -0
  228. package/dist/{chunk-66ALHVEX.js → chunk-EB46EYI7.js} +3 -3
  229. package/dist/{chunk-NZJKFF45.js → chunk-EKCDHWRK.js} +4 -4
  230. package/dist/chunk-EKCDHWRK.js.map +1 -0
  231. package/dist/{chunk-BABLDP24.js → chunk-EPQFNJU3.js} +152 -7
  232. package/dist/chunk-EPQFNJU3.js.map +1 -0
  233. package/dist/{chunk-OGWBVHB3.js → chunk-ESR6HGOY.js} +73 -14
  234. package/dist/chunk-ESR6HGOY.js.map +1 -0
  235. package/dist/{chunk-NBD3KUOZ.js → chunk-F6RP62H3.js} +150 -98
  236. package/dist/chunk-F6RP62H3.js.map +1 -0
  237. package/dist/chunk-FBYW3QDI.js +252 -0
  238. package/dist/chunk-FBYW3QDI.js.map +1 -0
  239. package/dist/{chunk-IPF7E66P.js → chunk-FYAODKVP.js} +2 -2
  240. package/dist/chunk-GNEN7NKO.js +908 -0
  241. package/dist/chunk-GNEN7NKO.js.map +1 -0
  242. package/dist/chunk-GWSM4KLB.js +763 -0
  243. package/dist/chunk-GWSM4KLB.js.map +1 -0
  244. package/dist/{chunk-4SO6JMZL.js → chunk-HDMXCUZL.js} +1 -1
  245. package/dist/chunk-HDMXCUZL.js.map +1 -0
  246. package/dist/{chunk-ZFY7U2FR.js → chunk-HJM5Y5NU.js} +43 -3
  247. package/dist/chunk-HJM5Y5NU.js.map +1 -0
  248. package/dist/{chunk-ZGDVUPTM.js → chunk-IOZ3VKPK.js} +129 -68
  249. package/dist/chunk-IOZ3VKPK.js.map +1 -0
  250. package/dist/{chunk-PYOE4VSI.js → chunk-IVXSVHO4.js} +303 -247
  251. package/dist/chunk-IVXSVHO4.js.map +1 -0
  252. package/dist/chunk-J3CWXIPV.js +242 -0
  253. package/dist/chunk-J3CWXIPV.js.map +1 -0
  254. package/dist/chunk-K6JQW266.js +42 -0
  255. package/dist/chunk-K6JQW266.js.map +1 -0
  256. package/dist/chunk-KMZYQF6Q.js +202 -0
  257. package/dist/chunk-KMZYQF6Q.js.map +1 -0
  258. package/dist/{chunk-JWOYLO27.js → chunk-LPPZDFTD.js} +22 -12
  259. package/dist/chunk-LPPZDFTD.js.map +1 -0
  260. package/dist/{chunk-PAYXCY6A.js → chunk-MYB2B5WX.js} +997 -576
  261. package/dist/chunk-MYB2B5WX.js.map +1 -0
  262. package/dist/chunk-MYKNINNN.js +228 -0
  263. package/dist/chunk-MYKNINNN.js.map +1 -0
  264. package/dist/chunk-NSQIRMVF.js +27 -0
  265. package/dist/{chunk-QCHIQWAJ.js.map → chunk-NSQIRMVF.js.map} +1 -1
  266. package/dist/chunk-NUDBM4MM.js +30 -0
  267. package/dist/chunk-NUDBM4MM.js.map +1 -0
  268. package/dist/chunk-NZMWWDAY.js +23 -0
  269. package/dist/chunk-NZMWWDAY.js.map +1 -0
  270. package/dist/{chunk-RNFE3ML2.js → chunk-OCUV2Y25.js} +4 -3
  271. package/dist/chunk-OCUV2Y25.js.map +1 -0
  272. package/dist/chunk-P4ZJOQA7.js +271 -0
  273. package/dist/chunk-P4ZJOQA7.js.map +1 -0
  274. package/dist/chunk-P6C5EZ3D.js +342 -0
  275. package/dist/chunk-P6C5EZ3D.js.map +1 -0
  276. package/dist/{chunk-CW6T36TN.js → chunk-PBD7BJUN.js} +62 -4
  277. package/dist/chunk-PBD7BJUN.js.map +1 -0
  278. package/dist/chunk-PBIUCQY3.js +696 -0
  279. package/dist/chunk-PBIUCQY3.js.map +1 -0
  280. package/dist/chunk-PD6YECQH.js +845 -0
  281. package/dist/chunk-PD6YECQH.js.map +1 -0
  282. package/dist/{chunk-M7IYCTJV.js → chunk-R4LFQGP3.js} +2 -2
  283. package/dist/chunk-RHJIGDUE.js +21 -0
  284. package/dist/chunk-RHJIGDUE.js.map +1 -0
  285. package/dist/{chunk-KP7MUZNX.js → chunk-RLXO27MW.js} +30 -8
  286. package/dist/chunk-RLXO27MW.js.map +1 -0
  287. package/dist/{chunk-DFNM3WX2.js → chunk-S44BEV4B.js} +168 -45
  288. package/dist/chunk-S44BEV4B.js.map +1 -0
  289. package/dist/chunk-S4S5N4BJ.js +1461 -0
  290. package/dist/chunk-S4S5N4BJ.js.map +1 -0
  291. package/dist/{chunk-BZ2SHDN2.js → chunk-SGTRAXXX.js} +3 -3
  292. package/dist/chunk-SGTRAXXX.js.map +1 -0
  293. package/dist/{chunk-M2RGJPXX.js → chunk-SJAE5PB5.js} +3 -3
  294. package/dist/{chunk-JGIWG6SR.js → chunk-SNPNHU3H.js} +3937 -1776
  295. package/dist/chunk-SNPNHU3H.js.map +1 -0
  296. package/dist/{chunk-IHVBV5C2.js → chunk-SOOBFXRR.js} +94 -71
  297. package/dist/chunk-SOOBFXRR.js.map +1 -0
  298. package/dist/{chunk-ZDTRWK5F.js → chunk-TAHFWKS6.js} +2 -2
  299. package/dist/chunk-UEFFTVPY.js +9 -0
  300. package/dist/chunk-UEFFTVPY.js.map +1 -0
  301. package/dist/{chunk-24VULZ7A.js → chunk-UR5BXLBP.js} +3 -3
  302. package/dist/chunk-UR5BXLBP.js.map +1 -0
  303. package/dist/{chunk-DMBALCE2.js → chunk-V2SBGVDO.js} +471 -186
  304. package/dist/chunk-V2SBGVDO.js.map +1 -0
  305. package/dist/chunk-VJLWD47W.js +23 -0
  306. package/dist/chunk-VJLWD47W.js.map +1 -0
  307. package/dist/{chunk-4CQAV7YB.js → chunk-W647DX5Z.js} +2 -2
  308. package/dist/{chunk-THATMZXD.js → chunk-WFIIU3YZ.js} +2 -2
  309. package/dist/{chunk-THATMZXD.js.map → chunk-WFIIU3YZ.js.map} +1 -1
  310. package/dist/chunk-YZDJMAKL.js +82 -0
  311. package/dist/chunk-YZDJMAKL.js.map +1 -0
  312. package/dist/{chunk-3TMODYZV.js → chunk-Z5XH6VHY.js} +5 -5
  313. package/dist/chunk-Z5XH6VHY.js.map +1 -0
  314. package/dist/{chunk-BE3HW4FY.js → chunk-ZBBMZMA6.js} +377 -170
  315. package/dist/chunk-ZBBMZMA6.js.map +1 -0
  316. package/dist/index.cjs +21224 -11714
  317. package/dist/index.cjs.map +1 -1
  318. package/dist/index.d.cts +195 -49
  319. package/dist/index.d.ts +195 -49
  320. package/dist/index.js +150 -74
  321. package/dist/index.js.map +1 -1
  322. package/dist/{ir-BMP7yxJJ.d.cts → ir-BSosEwc8.d.cts} +1 -1
  323. package/dist/{ir-DUOz6H-5.d.ts → ir-D-uqwL_4.d.ts} +1 -1
  324. package/dist/{module-B8CBqIZ_.d.cts → module-Ds4tarcI.d.cts} +230 -140
  325. package/dist/{module-k7m3txak.d.ts → module-Zd1Gn-Nj.d.ts} +230 -140
  326. package/package.json +20 -4
  327. package/dist/ModuleTag-C8FHY_sY.d.ts +0 -93
  328. package/dist/ModuleTag-EGbgBMpZ.d.cts +0 -93
  329. package/dist/Observability-COqEvp2C.d.cts +0 -713
  330. package/dist/Observability-cY4kLn0S.d.ts +0 -713
  331. package/dist/ReadQuery-BlMwhe-F.d.ts +0 -30
  332. package/dist/ReadQuery-CL5XlXts.d.cts +0 -30
  333. package/dist/ReadQuery-SinbStGF.d.cts +0 -38
  334. package/dist/ReadQuery-SinbStGF.d.ts +0 -38
  335. package/dist/chunk-24VULZ7A.js.map +0 -1
  336. package/dist/chunk-3QMIVH35.js +0 -43
  337. package/dist/chunk-3QMIVH35.js.map +0 -1
  338. package/dist/chunk-3TMODYZV.js.map +0 -1
  339. package/dist/chunk-4SO6JMZL.js.map +0 -1
  340. package/dist/chunk-76WT3HOR.js.map +0 -1
  341. package/dist/chunk-ANLBCBDC.js.map +0 -1
  342. package/dist/chunk-AUIR5O6W.js.map +0 -1
  343. package/dist/chunk-BABLDP24.js.map +0 -1
  344. package/dist/chunk-BE3HW4FY.js.map +0 -1
  345. package/dist/chunk-BZ2SHDN2.js.map +0 -1
  346. package/dist/chunk-CW6T36TN.js.map +0 -1
  347. package/dist/chunk-DFNM3WX2.js.map +0 -1
  348. package/dist/chunk-DMBALCE2.js.map +0 -1
  349. package/dist/chunk-EGK3KN7B.js +0 -406
  350. package/dist/chunk-EGK3KN7B.js.map +0 -1
  351. package/dist/chunk-GMPEOUP2.js.map +0 -1
  352. package/dist/chunk-IHVBV5C2.js.map +0 -1
  353. package/dist/chunk-JCXGZRMU.js.map +0 -1
  354. package/dist/chunk-JGIWG6SR.js.map +0 -1
  355. package/dist/chunk-JWOYLO27.js.map +0 -1
  356. package/dist/chunk-KIXAU3GM.js +0 -137
  357. package/dist/chunk-KIXAU3GM.js.map +0 -1
  358. package/dist/chunk-KL5ACTCT.js +0 -8
  359. package/dist/chunk-KL5ACTCT.js.map +0 -1
  360. package/dist/chunk-KP7MUZNX.js.map +0 -1
  361. package/dist/chunk-M3BFQ7HK.js +0 -13
  362. package/dist/chunk-M3BFQ7HK.js.map +0 -1
  363. package/dist/chunk-M3WTHJHJ.js.map +0 -1
  364. package/dist/chunk-NBD3KUOZ.js.map +0 -1
  365. package/dist/chunk-NQZ2OSGR.js +0 -151
  366. package/dist/chunk-NQZ2OSGR.js.map +0 -1
  367. package/dist/chunk-NZJKFF45.js.map +0 -1
  368. package/dist/chunk-OFADUJWJ.js.map +0 -1
  369. package/dist/chunk-OGWBVHB3.js.map +0 -1
  370. package/dist/chunk-PAYXCY6A.js.map +0 -1
  371. package/dist/chunk-PYOE4VSI.js.map +0 -1
  372. package/dist/chunk-QCHIQWAJ.js +0 -21
  373. package/dist/chunk-RNFE3ML2.js.map +0 -1
  374. package/dist/chunk-TKZ7MEIA.js +0 -27
  375. package/dist/chunk-TKZ7MEIA.js.map +0 -1
  376. package/dist/chunk-TQOBJYDP.js.map +0 -1
  377. package/dist/chunk-VZB726PE.js +0 -93
  378. package/dist/chunk-VZB726PE.js.map +0 -1
  379. package/dist/chunk-W3TEWHLO.js +0 -568
  380. package/dist/chunk-W3TEWHLO.js.map +0 -1
  381. package/dist/chunk-YS3AZQ2G.js.map +0 -1
  382. package/dist/chunk-ZFLHVFUC.js +0 -192
  383. package/dist/chunk-ZFLHVFUC.js.map +0 -1
  384. package/dist/chunk-ZFY7U2FR.js.map +0 -1
  385. package/dist/chunk-ZGDVUPTM.js.map +0 -1
  386. package/dist/protocol-g_1897M2.d.cts +0 -127
  387. package/dist/protocol-g_1897M2.d.ts +0 -127
  388. /package/dist/{chunk-3IYZ5IGG.js.map → chunk-5WKUGEBY.js.map} +0 -0
  389. /package/dist/{chunk-3RMKLXHX.js.map → chunk-63ZQ5RIN.js.map} +0 -0
  390. /package/dist/{chunk-EY4NZKDR.js.map → chunk-6Y2TKCNY.js.map} +0 -0
  391. /package/dist/{chunk-G5ZBFPNU.js.map → chunk-A2RQOJC7.js.map} +0 -0
  392. /package/dist/{chunk-TAAPQVZN.js.map → chunk-AYELIQXR.js.map} +0 -0
  393. /package/dist/{chunk-66ALHVEX.js.map → chunk-EB46EYI7.js.map} +0 -0
  394. /package/dist/{chunk-IPF7E66P.js.map → chunk-FYAODKVP.js.map} +0 -0
  395. /package/dist/{chunk-M7IYCTJV.js.map → chunk-R4LFQGP3.js.map} +0 -0
  396. /package/dist/{chunk-M2RGJPXX.js.map → chunk-SJAE5PB5.js.map} +0 -0
  397. /package/dist/{chunk-ZDTRWK5F.js.map → chunk-TAHFWKS6.js.map} +0 -0
  398. /package/dist/{chunk-4CQAV7YB.js.map → chunk-W647DX5Z.js.map} +0 -0
@@ -1,24 +1,37 @@
1
1
  import {
2
- shouldNoopInSyncTransactionFiber
3
- } from "./chunk-ZFLHVFUC.js";
2
+ moduleRuntimeTagFromModuleId
3
+ } from "./chunk-VJLWD47W.js";
4
4
  import {
5
5
  getRuntimeInternals
6
- } from "./chunk-3RMKLXHX.js";
6
+ } from "./chunk-63ZQ5RIN.js";
7
+ import {
8
+ inSyncTransactionFiber,
9
+ isDevEnv,
10
+ shouldNoopInSyncTransactionFiber
11
+ } from "./chunk-S4S5N4BJ.js";
7
12
  import {
8
- isDevEnv
9
- } from "./chunk-3QMIVH35.js";
13
+ makeRunBudgetEnvelopeV1,
14
+ makeRunDegradeMarkerV1
15
+ } from "./chunk-K6JQW266.js";
16
+ import {
17
+ makeEvidenceSink
18
+ } from "./chunk-CYYSQMLO.js";
10
19
  import {
20
+ beginRun,
21
+ clearIfCurrent,
11
22
  currentDiagnosticsLevel,
23
+ make,
12
24
  record,
25
+ setFiberIfCurrent,
13
26
  toRuntimeDebugEventRef,
14
27
  toSerializableErrorSummary
15
- } from "./chunk-DMBALCE2.js";
16
- import {
17
- makeEvidenceSink
18
- } from "./chunk-OFADUJWJ.js";
28
+ } from "./chunk-V2SBGVDO.js";
19
29
  import {
20
30
  projectJsonValue
21
- } from "./chunk-JWOYLO27.js";
31
+ } from "./chunk-LPPZDFTD.js";
32
+ import {
33
+ make as make2
34
+ } from "./chunk-PBD7BJUN.js";
22
35
 
23
36
  // src/internal/runtime/core/process/meta.ts
24
37
  var PROCESS_META = /* @__PURE__ */ Symbol.for("@logixjs/core/processMeta");
@@ -38,8 +51,38 @@ var attachMeta = (effect, meta) => {
38
51
  };
39
52
 
40
53
  // src/internal/observability/evidenceCollector.ts
41
- import { Context, Effect, FiberRef, Layer } from "effect";
42
- var EvidenceCollectorTagImpl = class extends Context.Tag("@logixjs/core/EvidenceCollector")() {
54
+ import { Effect, Layer, ServiceMap } from "effect";
55
+
56
+ // src/internal/observability/evidenceExportPipeline.ts
57
+ var collectEvidenceExport = (args) => {
58
+ const convergeSummary = args.convergeStaticIrByDigest.size > 0 ? {
59
+ staticIrByDigest: Object.fromEntries(
60
+ Array.from(args.convergeStaticIrByDigest.entries()).sort(([a], [b]) => a < b ? -1 : a > b ? 1 : 0)
61
+ )
62
+ } : void 0;
63
+ const runtimeSummary = args.kernelImplementationRef != null || args.runtimeServicesEvidence != null ? {
64
+ ...args.kernelImplementationRef != null ? { kernelImplementationRef: args.kernelImplementationRef } : {},
65
+ ...args.runtimeServicesEvidence != null ? { services: args.runtimeServicesEvidence } : {}
66
+ } : void 0;
67
+ return {
68
+ convergeSummary,
69
+ runtimeSummary
70
+ };
71
+ };
72
+ var summarizeEvidenceExport = (collection) => {
73
+ const summary = collection.convergeSummary != null || collection.runtimeSummary != null ? {
74
+ ...collection.convergeSummary != null ? { converge: collection.convergeSummary } : {},
75
+ ...collection.runtimeSummary != null ? { runtime: collection.runtimeSummary } : {}
76
+ } : void 0;
77
+ return { summary };
78
+ };
79
+ var reExportEvidencePackage = (args) => args.sink.export({
80
+ maxEvents: args.maxEvents,
81
+ summary: args.summary.summary
82
+ });
83
+
84
+ // src/internal/observability/evidenceCollector.ts
85
+ var EvidenceCollectorTagImpl = class extends ServiceMap.Service()("@logixjs/core/EvidenceCollector") {
43
86
  };
44
87
  var EvidenceCollectorTag = EvidenceCollectorTagImpl;
45
88
  var evidenceCollectorLayer = (collector) => Layer.succeed(EvidenceCollectorTag, collector);
@@ -56,7 +99,7 @@ var makeEvidenceCollector = (session) => {
56
99
  };
57
100
  const debugSink = {
58
101
  record: (event) => Effect.gen(function* () {
59
- const level = yield* FiberRef.get(currentDiagnosticsLevel);
102
+ const level = yield* Effect.service(currentDiagnosticsLevel);
60
103
  const instanceIdRaw = event.instanceId;
61
104
  const instanceId = typeof instanceIdRaw === "string" && instanceIdRaw.length > 0 ? instanceIdRaw : "unknown";
62
105
  const eventSeq = level === "off" ? void 0 : session.local.nextSeq("eventSeq", instanceId);
@@ -103,18 +146,14 @@ var makeEvidenceCollector = (session) => {
103
146
  runtimeServicesEvidence = projected.value;
104
147
  };
105
148
  const exportEvidencePackage = (options) => {
106
- const convergeSummary = convergeStaticIrByDigest.size > 0 ? {
107
- staticIrByDigest: Object.fromEntries(convergeStaticIrByDigest)
108
- } : void 0;
109
- const runtimeSummary = kernelImplementationRef != null || runtimeServicesEvidence != null ? {
110
- ...kernelImplementationRef != null ? { kernelImplementationRef } : {},
111
- ...runtimeServicesEvidence != null ? { services: runtimeServicesEvidence } : {}
112
- } : void 0;
113
- const summary = convergeSummary != null || runtimeSummary != null ? {
114
- ...convergeSummary != null ? { converge: convergeSummary } : {},
115
- ...runtimeSummary != null ? { runtime: runtimeSummary } : {}
116
- } : void 0;
117
- return sink.export({
149
+ const collection = collectEvidenceExport({
150
+ convergeStaticIrByDigest,
151
+ kernelImplementationRef,
152
+ runtimeServicesEvidence
153
+ });
154
+ const summary = summarizeEvidenceExport(collection);
155
+ return reExportEvidencePackage({
156
+ sink,
118
157
  maxEvents: options?.maxEvents,
119
158
  summary
120
159
  });
@@ -139,23 +178,8 @@ var makeEvidenceCollector = (session) => {
139
178
  };
140
179
  };
141
180
 
142
- // src/internal/runtime/core/process/ProcessRuntime.ts
143
- import {
144
- Cause,
145
- Context as Context2,
146
- Deferred,
147
- Duration,
148
- Effect as Effect3,
149
- Fiber as Fiber2,
150
- FiberRef as FiberRef2,
151
- Layer as Layer2,
152
- Option as Option2,
153
- PubSub,
154
- Queue,
155
- Ref as Ref2,
156
- Scope as Scope2,
157
- Stream as Stream2
158
- } from "effect";
181
+ // src/internal/runtime/core/process/ProcessRuntime.make.ts
182
+ import { Cause, Deferred, Effect as Effect4, Fiber as Fiber2, Layer as Layer2, Option as Option3, PubSub, Queue, Ref as Ref3, ServiceMap as ServiceMap2, Scope as Scope2, Stream as Stream3 } from "effect";
159
183
 
160
184
  // src/internal/runtime/core/process/identity.ts
161
185
  var scopeKeyFromScope = (scope) => {
@@ -178,6 +202,7 @@ var processInstanceIdFromIdentity = (identity) => {
178
202
  import { Effect as Effect2, Fiber, Option, Ref, Stream } from "effect";
179
203
  var DEFAULT_SERIAL_QUEUE_GUARD_LIMIT = 4096;
180
204
  var DEFAULT_PARALLEL_LIMIT = 16;
205
+ var QUEUE_COMPACTION_MIN_CONSUMED = 64;
181
206
  var resolveQueueLimit = (maxQueue, options) => {
182
207
  const defaultGuard = options?.defaultGuard ?? DEFAULT_SERIAL_QUEUE_GUARD_LIMIT;
183
208
  const configured = typeof maxQueue === "number" && Number.isFinite(maxQueue) && maxQueue >= 0 ? Math.floor(maxQueue) : "unbounded";
@@ -186,27 +211,51 @@ var resolveQueueLimit = (maxQueue, options) => {
186
211
  guard: configured === "unbounded" ? defaultGuard : configured
187
212
  };
188
213
  };
214
+ var queueLength = (state) => state.queue.length - state.queueStart;
215
+ var compactQueueIfNeeded = (state) => {
216
+ if (state.queueStart === 0) return;
217
+ if (state.queueStart >= state.queue.length) {
218
+ state.queue = [];
219
+ state.queueStart = 0;
220
+ return;
221
+ }
222
+ if (state.queueStart >= QUEUE_COMPACTION_MIN_CONSUMED && state.queueStart * 2 >= state.queue.length) {
223
+ state.queue = state.queue.slice(state.queueStart);
224
+ state.queueStart = 0;
225
+ }
226
+ };
227
+ var enqueueTrigger = (state, trigger) => {
228
+ state.queue.push(trigger);
229
+ const size = queueLength(state);
230
+ if (size > state.peak) {
231
+ state.peak = size;
232
+ }
233
+ return size;
234
+ };
235
+ var dequeueTrigger = (state) => {
236
+ if (state.queueStart >= state.queue.length) {
237
+ state.queue = [];
238
+ state.queueStart = 0;
239
+ return void 0;
240
+ }
241
+ const next = state.queue[state.queueStart];
242
+ state.queueStart += 1;
243
+ compactQueueIfNeeded(state);
244
+ return next;
245
+ };
189
246
  var runProcessTriggerStream = (args) => Effect2.gen(function* () {
190
247
  const policy = args.policy;
191
248
  const defaultQueueGuard = args.defaultQueueGuard ?? DEFAULT_SERIAL_QUEUE_GUARD_LIMIT;
192
249
  if (policy.mode === "latest") {
193
- const stateRef = yield* Ref.make({ fiber: void 0, runningId: 0, nextId: 0 });
250
+ const stateRef = yield* make();
194
251
  const onTrigger2 = (trigger0) => Effect2.gen(function* () {
195
252
  const trigger = args.assignTriggerSeq(trigger0);
196
- const [prevFiber, prevRunningId, runId] = yield* Ref.modify(stateRef, (s) => {
197
- const nextId = s.nextId + 1;
198
- return [[s.fiber, s.runningId, nextId], { ...s, nextId, runningId: nextId }];
199
- });
253
+ const [prevFiber, prevRunningId, runId] = yield* beginRun(stateRef);
200
254
  if (prevFiber && prevRunningId !== 0) {
201
- const done = yield* Fiber.poll(prevFiber);
202
- if (Option.isNone(done)) {
203
- yield* Fiber.interruptFork(prevFiber);
204
- }
255
+ yield* Fiber.interrupt(prevFiber);
205
256
  }
206
- const fiber = yield* Effect2.forkScoped(
207
- args.run(trigger).pipe(Effect2.ensuring(Ref.update(stateRef, (s) => s.runningId === runId ? { ...s, runningId: 0 } : s)))
208
- );
209
- yield* Ref.update(stateRef, (s) => ({ ...s, fiber }));
257
+ const fiber = yield* args.run(trigger).pipe(Effect2.ensuring(clearIfCurrent(stateRef, runId)), Effect2.forkScoped);
258
+ yield* setFiberIfCurrent(stateRef, runId, fiber);
210
259
  });
211
260
  return yield* Stream.runForEach(args.stream, onTrigger2);
212
261
  }
@@ -214,11 +263,13 @@ var runProcessTriggerStream = (args) => Effect2.gen(function* () {
214
263
  const serialStateRef = yield* Ref.make({
215
264
  running: false,
216
265
  queue: [],
266
+ queueStart: 0,
217
267
  peak: 0
218
268
  });
219
269
  const parallelStateRef = yield* Ref.make({
220
270
  active: 0,
221
271
  queue: [],
272
+ queueStart: 0,
222
273
  peak: 0
223
274
  });
224
275
  const serialQueueLimit = resolveQueueLimit(policy.maxQueue, { defaultGuard: defaultQueueGuard });
@@ -226,19 +277,28 @@ var runProcessTriggerStream = (args) => Effect2.gen(function* () {
226
277
  const parallelLimit = typeof policy.maxParallel === "number" && Number.isFinite(policy.maxParallel) && policy.maxParallel >= 1 ? Math.floor(policy.maxParallel) : args.defaultParallelLimit ?? DEFAULT_PARALLEL_LIMIT;
227
278
  const drainSerial = () => Effect2.suspend(
228
279
  () => Ref.modify(serialStateRef, (state) => {
229
- if (state.running || state.queue.length === 0) {
280
+ if (state.running || queueLength(state) === 0) {
230
281
  return [Option.none(), state];
231
282
  }
232
- const [next, ...rest] = state.queue;
233
- return [Option.some(next), { ...state, running: true, queue: rest }];
283
+ const next = dequeueTrigger(state);
284
+ if (next === void 0) {
285
+ return [Option.none(), state];
286
+ }
287
+ state.running = true;
288
+ return [Option.some(next), state];
234
289
  }).pipe(
235
290
  Effect2.flatMap(
236
291
  (next) => Option.match(next, {
237
292
  onNone: () => Effect2.void,
238
293
  onSome: (trigger) => Effect2.forkScoped(
239
294
  args.run(trigger).pipe(
240
- Effect2.ensuring(Ref.update(serialStateRef, (s) => ({ ...s, running: false }))),
241
- Effect2.zipRight(drainSerial())
295
+ Effect2.ensuring(
296
+ Ref.update(serialStateRef, (s) => {
297
+ s.running = false;
298
+ return s;
299
+ })
300
+ ),
301
+ Effect2.flatMap(() => drainSerial())
242
302
  )
243
303
  ).pipe(Effect2.asVoid)
244
304
  })
@@ -247,11 +307,15 @@ var runProcessTriggerStream = (args) => Effect2.gen(function* () {
247
307
  );
248
308
  const drainParallel = () => Effect2.suspend(
249
309
  () => Ref.modify(parallelStateRef, (state) => {
250
- if (state.active >= parallelLimit || state.queue.length === 0) {
310
+ if (state.active >= parallelLimit || queueLength(state) === 0) {
251
311
  return [Option.none(), state];
252
312
  }
253
- const [next, ...rest] = state.queue;
254
- return [Option.some(next), { ...state, active: state.active + 1, queue: rest }];
313
+ const next = dequeueTrigger(state);
314
+ if (next === void 0) {
315
+ return [Option.none(), state];
316
+ }
317
+ state.active += 1;
318
+ return [Option.some(next), state];
255
319
  }).pipe(
256
320
  Effect2.flatMap(
257
321
  (next) => Option.match(next, {
@@ -259,14 +323,14 @@ var runProcessTriggerStream = (args) => Effect2.gen(function* () {
259
323
  onSome: (trigger) => Effect2.forkScoped(
260
324
  args.run(trigger).pipe(
261
325
  Effect2.ensuring(
262
- Ref.update(parallelStateRef, (s) => ({
263
- ...s,
264
- active: Math.max(0, s.active - 1)
265
- }))
326
+ Ref.update(parallelStateRef, (s) => {
327
+ s.active = Math.max(0, s.active - 1);
328
+ return s;
329
+ })
266
330
  ),
267
- Effect2.zipRight(drainParallel())
331
+ Effect2.flatMap(() => drainParallel())
268
332
  )
269
- ).pipe(Effect2.asVoid, Effect2.zipRight(drainParallel()))
333
+ ).pipe(Effect2.asVoid, Effect2.flatMap(() => drainParallel()))
270
334
  })
271
335
  )
272
336
  )
@@ -286,16 +350,15 @@ var runProcessTriggerStream = (args) => Effect2.gen(function* () {
286
350
  return;
287
351
  }
288
352
  if (policy.mode === "parallel") {
289
- const nextSize2 = yield* Ref.modify(parallelStateRef, (state) => {
290
- const queue = [...state.queue, trigger];
291
- return [queue.length, { ...state, queue, peak: Math.max(state.peak, queue.length) }];
353
+ const [nextSize2, peak2] = yield* Ref.modify(parallelStateRef, (state) => {
354
+ const size = enqueueTrigger(state, trigger);
355
+ return [[size, state.peak], state];
292
356
  });
293
357
  if (nextSize2 > parallelQueueLimit.guard) {
294
- const state = yield* Ref.get(parallelStateRef);
295
358
  yield* args.onQueueOverflow({
296
359
  mode: "parallel",
297
360
  currentLength: nextSize2,
298
- peak: state.peak,
361
+ peak: peak2,
299
362
  limit: parallelQueueLimit,
300
363
  policy
301
364
  });
@@ -304,16 +367,15 @@ var runProcessTriggerStream = (args) => Effect2.gen(function* () {
304
367
  yield* drainParallel();
305
368
  return;
306
369
  }
307
- const nextSize = yield* Ref.modify(serialStateRef, (state) => {
308
- const queue = [...state.queue, trigger];
309
- return [queue.length, { ...state, queue, peak: Math.max(state.peak, queue.length) }];
370
+ const [nextSize, peak] = yield* Ref.modify(serialStateRef, (state) => {
371
+ const size = enqueueTrigger(state, trigger);
372
+ return [[size, state.peak], state];
310
373
  });
311
374
  if (nextSize > serialQueueLimit.guard) {
312
- const state = yield* Ref.get(serialStateRef);
313
375
  yield* args.onQueueOverflow({
314
376
  mode: "serial",
315
377
  currentLength: nextSize,
316
- peak: state.peak,
378
+ peak,
317
379
  limit: serialQueueLimit,
318
380
  policy
319
381
  });
@@ -328,7 +390,26 @@ var runProcessTriggerStream = (args) => Effect2.gen(function* () {
328
390
  var PROCESS_EVENT_MAX_BYTES = 4 * 1024;
329
391
  var PROCESS_EVENT_MAX_EVENTS_PER_RUN = 50;
330
392
  var PROCESS_EVENT_RESERVED_EVENTS_FOR_SUMMARY = 1;
393
+ var PROCESS_RUN_BUDGET_RUN_ID_UNKNOWN = "process:run:unknown";
394
+ var scopeKeyFromProcessEventIdentity = (eventIdentity) => {
395
+ switch (eventIdentity.type) {
396
+ case "app":
397
+ return `app:${eventIdentity.appId}`;
398
+ case "moduleInstance":
399
+ return `module:${eventIdentity.moduleId}:${eventIdentity.instanceId}`;
400
+ case "uiSubtree":
401
+ return `subtree:${eventIdentity.subtreeId}`;
402
+ }
403
+ };
404
+ var makeProcessRunBudgetRunId = (identity, trigger) => {
405
+ const processId = identity.identity.processId;
406
+ const scopeKey = scopeKeyFromProcessEventIdentity(identity.identity.scope);
407
+ const runSeq = identity.runSeq;
408
+ const triggerSeq = trigger && typeof trigger.triggerSeq === "number" && Number.isFinite(trigger.triggerSeq) && trigger.triggerSeq >= 1 ? Math.floor(trigger.triggerSeq) : void 0;
409
+ return triggerSeq != null ? `${processId}@${scopeKey}::r${runSeq}::g${triggerSeq}` : `${processId}@${scopeKey}::r${runSeq}`;
410
+ };
331
411
  var makeProcessRunEventBudgetState = (options) => ({
412
+ runId: typeof options?.runId === "string" && options.runId.length > 0 ? options.runId : PROCESS_RUN_BUDGET_RUN_ID_UNKNOWN,
332
413
  maxEvents: typeof options?.maxEvents === "number" && Number.isFinite(options.maxEvents) && options.maxEvents >= 0 ? Math.floor(options.maxEvents) : PROCESS_EVENT_MAX_EVENTS_PER_RUN,
333
414
  maxBytes: typeof options?.maxBytes === "number" && Number.isFinite(options.maxBytes) && options.maxBytes >= 0 ? Math.floor(options.maxBytes) : PROCESS_EVENT_MAX_BYTES,
334
415
  emitted: 0,
@@ -336,6 +417,48 @@ var makeProcessRunEventBudgetState = (options) => ({
336
417
  downgraded: 0,
337
418
  summaryEmitted: false
338
419
  });
420
+ var attachProcessRunBudgetEnvelope = (event, state, degradeReason) => ({
421
+ ...event,
422
+ budgetEnvelope: makeRunBudgetEnvelopeV1({
423
+ domain: "process",
424
+ runId: state.runId,
425
+ limits: {
426
+ maxEvents: state.maxEvents,
427
+ maxBytes: state.maxBytes
428
+ },
429
+ usage: {
430
+ emitted: state.emitted,
431
+ dropped: state.dropped,
432
+ downgraded: state.downgraded
433
+ }
434
+ }),
435
+ degrade: makeRunDegradeMarkerV1(Boolean(degradeReason), degradeReason)
436
+ });
437
+ var finalizeBudgetedProcessEvent = (args) => {
438
+ const withEnvelope = attachProcessRunBudgetEnvelope(args.event, args.state, args.degradeReason);
439
+ if (estimateEventBytes(withEnvelope) <= args.maxBytes) {
440
+ return { event: withEnvelope, state: args.state };
441
+ }
442
+ let nextState = {
443
+ ...args.state,
444
+ downgraded: args.state.downgraded + 1
445
+ };
446
+ const compact = {
447
+ ...args.event,
448
+ degrade: makeRunDegradeMarkerV1(true, args.degradeReason ?? "payload_oversized")
449
+ };
450
+ const enforcedCompact = enforceProcessEventMaxBytes(compact, { maxBytes: args.maxBytes });
451
+ if (enforcedCompact.downgraded) {
452
+ nextState = {
453
+ ...nextState,
454
+ downgraded: nextState.downgraded + 1
455
+ };
456
+ }
457
+ return {
458
+ event: enforcedCompact.event,
459
+ state: nextState
460
+ };
461
+ };
339
462
  var makeBudgetSummaryEvent = (args) => ({
340
463
  type: "process:trigger",
341
464
  identity: args.sourceEvent.identity,
@@ -365,13 +488,20 @@ var applyProcessRunEventBudget = (state, event) => {
365
488
  const allowedRegular = Math.max(0, maxEvents - reserve);
366
489
  if (state.emitted < allowedRegular) {
367
490
  const enforced = enforceProcessEventMaxBytes(event, { maxBytes });
491
+ const baseState2 = {
492
+ ...state,
493
+ emitted: state.emitted + 1,
494
+ downgraded: state.downgraded + (enforced.downgraded ? 1 : 0)
495
+ };
496
+ const finalized2 = finalizeBudgetedProcessEvent({
497
+ event: enforced.event,
498
+ state: baseState2,
499
+ maxBytes,
500
+ degradeReason: enforced.downgraded ? "payload_oversized" : void 0
501
+ });
368
502
  return [
369
- { _tag: "emit", event: enforced.event },
370
- {
371
- ...state,
372
- emitted: state.emitted + 1,
373
- downgraded: state.downgraded + (enforced.downgraded ? 1 : 0)
374
- }
503
+ { _tag: "emit", event: finalized2.event },
504
+ finalized2.state
375
505
  ];
376
506
  }
377
507
  const dropped = state.dropped + 1;
@@ -384,15 +514,22 @@ var applyProcessRunEventBudget = (state, event) => {
384
514
  downgraded: state.downgraded
385
515
  });
386
516
  const enforcedSummary = enforceProcessEventMaxBytes(summary, { maxBytes });
517
+ const baseState = {
518
+ ...state,
519
+ emitted: Math.min(maxEvents, state.emitted + 1),
520
+ dropped,
521
+ downgraded: state.downgraded + (enforcedSummary.downgraded ? 1 : 0),
522
+ summaryEmitted: true
523
+ };
524
+ const finalized = finalizeBudgetedProcessEvent({
525
+ event: enforcedSummary.event,
526
+ state: baseState,
527
+ maxBytes,
528
+ degradeReason: "budget_exceeded"
529
+ });
387
530
  return [
388
- { _tag: "emitSummary", event: enforcedSummary.event },
389
- {
390
- ...state,
391
- emitted: Math.min(maxEvents, state.emitted + 1),
392
- dropped,
393
- downgraded: state.downgraded + (enforcedSummary.downgraded ? 1 : 0),
394
- summaryEmitted: true
395
- }
531
+ { _tag: "emitSummary", event: finalized.event },
532
+ finalized.state
396
533
  ];
397
534
  };
398
535
  var estimateEventBytes = (event) => {
@@ -537,26 +674,13 @@ var parseDotPath = (path) => {
537
674
  return { ok: true, segments };
538
675
  };
539
676
  var resolveAstForPath = (ast, segments, seen) => {
540
- if (segments.length === 0) return ast;
541
- let current = ast;
542
- while (true) {
543
- if (SchemaAST.isSuspend(current)) {
544
- if (seen.has(current)) return void 0;
545
- seen.add(current);
546
- current = current.f();
547
- continue;
548
- }
549
- if (SchemaAST.isRefinement(current)) {
550
- current = current.from;
551
- continue;
552
- }
553
- break;
554
- }
555
- if (SchemaAST.isTransformation(current)) {
556
- const from = resolveAstForPath(current.from, segments, seen);
557
- if (from) return from;
558
- return resolveAstForPath(current.to, segments, seen);
677
+ let current = SchemaAST.toType(ast);
678
+ while (SchemaAST.isSuspend(current)) {
679
+ if (seen.has(current)) return void 0;
680
+ seen.add(current);
681
+ current = SchemaAST.toType(current.thunk());
559
682
  }
683
+ if (segments.length === 0) return current;
560
684
  if (SchemaAST.isUnion(current)) {
561
685
  for (const node of current.types) {
562
686
  const resolved = resolveAstForPath(node, segments, seen);
@@ -564,13 +688,13 @@ var resolveAstForPath = (ast, segments, seen) => {
564
688
  }
565
689
  return void 0;
566
690
  }
567
- if (SchemaAST.isTupleType(current)) {
691
+ if (SchemaAST.isArrays(current)) {
568
692
  const [head, ...tail] = segments;
569
693
  if (typeof head !== "number") return void 0;
570
694
  const element = head < current.elements.length ? current.elements[head] : current.rest.length > 0 ? current.rest[0] : void 0;
571
- return element ? resolveAstForPath(element.type, tail, seen) : void 0;
695
+ return element ? resolveAstForPath(element, tail, seen) : void 0;
572
696
  }
573
- if (SchemaAST.isTypeLiteral(current)) {
697
+ if (SchemaAST.isObjects(current)) {
574
698
  const [head, ...tail] = segments;
575
699
  if (head === void 0) return void 0;
576
700
  if (typeof head === "string") {
@@ -580,13 +704,10 @@ var resolveAstForPath = (ast, segments, seen) => {
580
704
  }
581
705
  }
582
706
  for (const sig of current.indexSignatures) {
583
- let param = sig.parameter;
584
- while (SchemaAST.isRefinement(param)) {
585
- param = param.from;
586
- }
707
+ const param = SchemaAST.toType(sig.parameter);
587
708
  const tag2 = param?._tag;
588
- const acceptsString = tag2 === "StringKeyword" || tag2 === "TemplateLiteral";
589
- const acceptsNumber = tag2 === "NumberKeyword";
709
+ const acceptsString = tag2 === "String" || tag2 === "TemplateLiteral";
710
+ const acceptsNumber = tag2 === "Number";
590
711
  if (typeof head === "string" && acceptsString) {
591
712
  return resolveAstForPath(sig.type, tail, seen);
592
713
  }
@@ -640,9 +761,400 @@ var makeSchemaSelector = (path, schemaAst) => {
640
761
  };
641
762
  };
642
763
 
764
+ // src/internal/runtime/core/process/triggerStartPlan.ts
765
+ var PROCESS_RUNTIME_BOOT_EVENT = "runtime:boot";
766
+ var appendUniqueModuleId = (ids, seen, moduleId) => {
767
+ if (typeof moduleId !== "string" || moduleId.length === 0 || seen.has(moduleId)) {
768
+ return;
769
+ }
770
+ seen.add(moduleId);
771
+ ids.push(moduleId);
772
+ };
773
+ var compileProcessTriggerStartPlan = (definition) => {
774
+ const nonPlatformTriggers = [];
775
+ let bootTrigger = void 0;
776
+ const implicitModuleIds = [];
777
+ const implicitSeen = /* @__PURE__ */ new Set();
778
+ for (const trigger of definition.triggers) {
779
+ switch (trigger.kind) {
780
+ case "platformEvent": {
781
+ if (!bootTrigger && trigger.platformEvent === PROCESS_RUNTIME_BOOT_EVENT) {
782
+ bootTrigger = {
783
+ kind: "platformEvent",
784
+ name: trigger.name,
785
+ platformEvent: PROCESS_RUNTIME_BOOT_EVENT
786
+ };
787
+ }
788
+ break;
789
+ }
790
+ case "timer": {
791
+ nonPlatformTriggers.push(trigger);
792
+ break;
793
+ }
794
+ case "moduleAction": {
795
+ nonPlatformTriggers.push(trigger);
796
+ appendUniqueModuleId(implicitModuleIds, implicitSeen, trigger.moduleId);
797
+ break;
798
+ }
799
+ case "moduleStateChange": {
800
+ nonPlatformTriggers.push(trigger);
801
+ appendUniqueModuleId(implicitModuleIds, implicitSeen, trigger.moduleId);
802
+ break;
803
+ }
804
+ default: {
805
+ nonPlatformTriggers.push(trigger);
806
+ break;
807
+ }
808
+ }
809
+ }
810
+ const dispatchTracingModuleIds = [];
811
+ const dispatchSeen = /* @__PURE__ */ new Set();
812
+ for (const moduleId of definition.requires ?? []) {
813
+ appendUniqueModuleId(dispatchTracingModuleIds, dispatchSeen, moduleId);
814
+ }
815
+ const dependencyModuleIds = dispatchTracingModuleIds.slice();
816
+ const dependencySeen = new Set(dependencyModuleIds);
817
+ for (const moduleId of implicitModuleIds) {
818
+ appendUniqueModuleId(dependencyModuleIds, dependencySeen, moduleId);
819
+ }
820
+ return {
821
+ nonPlatformTriggers,
822
+ bootTrigger,
823
+ dependencyModuleIds,
824
+ dispatchTracingModuleIds
825
+ };
826
+ };
827
+
828
+ // src/internal/runtime/core/process/triggerStreams.ts
829
+ import { Duration, Effect as Effect3, Ref as Ref2, Stream as Stream2 } from "effect";
830
+
831
+ // src/internal/runtime/core/process/selectorDiagnostics.ts
832
+ var makeSelectorDiagnosticsConfig = (isDevEnv2) => ({
833
+ sampleEveryMask: 127,
834
+ // sample every 128 calls
835
+ slowSampleThresholdMs: 4,
836
+ triggerWindowMs: 1e3,
837
+ triggerWarningThreshold: isDevEnv2 ? 20 : 200,
838
+ warningCooldownMs: 3e4
839
+ });
840
+ var initialSelectorDiagnosticsState = (now) => ({
841
+ windowStartedMs: now,
842
+ triggersInWindow: 0,
843
+ lastWarningAtMs: 0
844
+ });
845
+ var makeSelectorSamplingTracker = (config) => {
846
+ let calls = 0;
847
+ let sampled = 0;
848
+ let slowSamples = 0;
849
+ let maxSampleMs = 0;
850
+ return {
851
+ onSelectorCall: () => {
852
+ calls += 1;
853
+ return (calls & config.sampleEveryMask) === 0;
854
+ },
855
+ recordSample: (sampleMs) => {
856
+ sampled += 1;
857
+ if (sampleMs >= config.slowSampleThresholdMs) {
858
+ slowSamples += 1;
859
+ }
860
+ if (sampleMs > maxSampleMs) {
861
+ maxSampleMs = sampleMs;
862
+ }
863
+ },
864
+ resetSampling: () => {
865
+ sampled = 0;
866
+ slowSamples = 0;
867
+ maxSampleMs = 0;
868
+ },
869
+ snapshot: () => ({
870
+ calls,
871
+ sampled,
872
+ slowSamples,
873
+ maxSampleMs
874
+ })
875
+ };
876
+ };
877
+ var evaluateSelectorWarning = (state, now, options) => {
878
+ const { config, sampling } = options;
879
+ const windowExpired = now - state.windowStartedMs >= config.triggerWindowMs;
880
+ const windowStartedMs = windowExpired ? now : state.windowStartedMs;
881
+ const triggersInWindow = windowExpired ? 1 : state.triggersInWindow + 1;
882
+ const shouldCooldown = now - state.lastWarningAtMs < config.warningCooldownMs;
883
+ const tooFrequent = triggersInWindow >= config.triggerWarningThreshold;
884
+ const tooSlow = sampling.maxSampleMs >= config.slowSampleThresholdMs && sampling.sampled > 0;
885
+ const shouldWarn = !shouldCooldown && (tooFrequent || tooSlow);
886
+ const next = shouldWarn ? {
887
+ windowStartedMs: now,
888
+ triggersInWindow: 0,
889
+ lastWarningAtMs: now
890
+ } : {
891
+ ...state,
892
+ windowStartedMs,
893
+ triggersInWindow
894
+ };
895
+ return [
896
+ {
897
+ shouldWarn,
898
+ tooFrequent,
899
+ tooSlow,
900
+ triggersInWindow
901
+ },
902
+ next
903
+ ];
904
+ };
905
+ var buildSelectorWarningHint = (options) => {
906
+ const { moduleId, path, decision, config, sampling } = options;
907
+ return [
908
+ `moduleId=${moduleId}`,
909
+ `path=${path}`,
910
+ `windowMs=${config.triggerWindowMs}`,
911
+ `triggersInWindow=${decision.triggersInWindow}`,
912
+ `threshold=${config.triggerWarningThreshold}`,
913
+ `cooldownMs=${config.warningCooldownMs}`,
914
+ "",
915
+ "selector sampling:",
916
+ `calls=${sampling.calls}`,
917
+ `sampled=${sampling.sampled}`,
918
+ `slowSamples(>=${config.slowSampleThresholdMs}ms)=${sampling.slowSamples}`,
919
+ `maxSampleMs=${sampling.maxSampleMs.toFixed(2)}`,
920
+ "",
921
+ "notes:",
922
+ "- Ensure the selected value is stable (prefer primitive/tuple; avoid returning fresh objects).",
923
+ "- Narrow the path to reduce change frequency; avoid selecting large objects."
924
+ ].join("\n");
925
+ };
926
+
927
+ // src/internal/runtime/core/process/triggerStreams.ts
928
+ var makeInvalidTriggerKindError = (spec) => Object.assign(
929
+ new Error(`[ProcessRuntime] unreachable non-platform trigger kind: ${String(spec?.kind ?? "unknown")}`),
930
+ { code: "process::invalid_trigger_kind" }
931
+ );
932
+ var makeInvalidTimerIdError = (timerId) => {
933
+ const err = new Error(`[ProcessRuntime] invalid timerId (expected DurationInput): ${timerId}`);
934
+ err.code = "process::invalid_timer_id";
935
+ err.hint = "timerId must be a valid DurationInput string, e.g. '10 millis', '1 seconds', '5 minutes'.";
936
+ return err;
937
+ };
938
+ var makeMissingActionStreamError = (moduleId) => {
939
+ const err = new Error("ModuleRuntime does not provide actions$ (required for moduleAction trigger).");
940
+ err.code = "process::missing_action_stream";
941
+ err.hint = `moduleId=${moduleId}`;
942
+ return err;
943
+ };
944
+ var makeMissingActionMetaStreamError = (moduleId) => {
945
+ const err = new Error("ModuleRuntime does not provide actionsWithMeta$ (required for moduleAction trigger).");
946
+ err.code = "process::missing_action_meta_stream";
947
+ err.hint = `moduleId=${moduleId}`;
948
+ return err;
949
+ };
950
+ var makeMissingChangesStreamError = (moduleId) => {
951
+ const err = new Error("ModuleRuntime does not provide changesWithMeta (required for moduleStateChange trigger).");
952
+ err.code = "process::missing_changes_stream";
953
+ err.hint = `moduleId=${moduleId}`;
954
+ return err;
955
+ };
956
+ var nowMs = () => {
957
+ if (typeof performance !== "undefined" && typeof performance.now === "function") {
958
+ return performance.now();
959
+ }
960
+ return Date.now();
961
+ };
962
+ var isWeakMapKey = (value) => typeof value === "object" && value !== null || typeof value === "function";
963
+ var makeModuleStateChangeReadQuery = (args) => make2({
964
+ selectorId: `process:moduleStateChange:${args.moduleId}:${args.path}`,
965
+ debugKey: `process.moduleStateChange:${args.moduleId}.${args.path}`,
966
+ reads: [args.path],
967
+ select: args.selector,
968
+ equalsKind: "objectIs"
969
+ });
970
+ var makeNonPlatformTriggerStreamFactory = (options) => {
971
+ const moduleRuntimeCache = /* @__PURE__ */ new Map();
972
+ const runtimeSchemaAstCache = /* @__PURE__ */ new WeakMap();
973
+ const resolveModuleRuntime = (moduleId) => Effect3.gen(function* () {
974
+ if (moduleRuntimeCache.has(moduleId)) {
975
+ return moduleRuntimeCache.get(moduleId);
976
+ }
977
+ const runtime = options.moduleRuntimeRegistry.get(moduleId);
978
+ if (runtime === void 0) {
979
+ return yield* Effect3.fail(new Error(`Missing module runtime in scope: ${moduleId}`));
980
+ }
981
+ moduleRuntimeCache.set(moduleId, runtime);
982
+ return runtime;
983
+ });
984
+ const resolveRuntimeStateSchemaAst2 = (runtime) => {
985
+ if (!isWeakMapKey(runtime)) {
986
+ return options.resolveRuntimeStateSchemaAst(runtime);
987
+ }
988
+ const cached = runtimeSchemaAstCache.get(runtime);
989
+ if (cached) {
990
+ return cached.ast;
991
+ }
992
+ const ast = options.resolveRuntimeStateSchemaAst(runtime);
993
+ runtimeSchemaAstCache.set(runtime, { ast });
994
+ return ast;
995
+ };
996
+ const makeTimerTriggerStream = (spec) => Effect3.gen(function* () {
997
+ const interval = Duration.fromInput(spec.timerId);
998
+ if (!interval) {
999
+ return yield* Effect3.fail(makeInvalidTimerIdError(spec.timerId));
1000
+ }
1001
+ return Stream2.tick(interval).pipe(
1002
+ Stream2.map(
1003
+ () => ({
1004
+ kind: "timer",
1005
+ name: spec.name,
1006
+ timerId: spec.timerId
1007
+ })
1008
+ )
1009
+ );
1010
+ });
1011
+ const makeModuleActionTriggerStream = (spec) => Effect3.gen(function* () {
1012
+ const runtime = yield* resolveModuleRuntime(spec.moduleId);
1013
+ const buildModuleActionTrigger = (txnSeq) => ({
1014
+ kind: "moduleAction",
1015
+ name: spec.name,
1016
+ moduleId: spec.moduleId,
1017
+ instanceId: runtime.instanceId,
1018
+ actionId: spec.actionId,
1019
+ txnSeq
1020
+ });
1021
+ if (!options.shouldRecordChainEvents) {
1022
+ const stream2 = runtime.actions$;
1023
+ if (!stream2) {
1024
+ return yield* Effect3.fail(makeMissingActionStreamError(spec.moduleId));
1025
+ }
1026
+ return stream2.pipe(
1027
+ Stream2.filter((action) => options.actionIdFromUnknown(action) === spec.actionId),
1028
+ Stream2.map(() => buildModuleActionTrigger(1))
1029
+ );
1030
+ }
1031
+ const stream = runtime.actionsWithMeta$;
1032
+ if (!stream) {
1033
+ return yield* Effect3.fail(makeMissingActionMetaStreamError(spec.moduleId));
1034
+ }
1035
+ return stream.pipe(
1036
+ Stream2.filter((evt) => options.actionIdFromUnknown(evt.value) === spec.actionId),
1037
+ Stream2.map((evt) => {
1038
+ const txnSeq = evt?.meta?.txnSeq;
1039
+ return buildModuleActionTrigger(typeof txnSeq === "number" ? txnSeq : 1);
1040
+ })
1041
+ );
1042
+ });
1043
+ const makeModuleStateChangeTriggerStream = (spec) => Effect3.gen(function* () {
1044
+ const runtime = yield* resolveModuleRuntime(spec.moduleId);
1045
+ const schemaAst = resolveRuntimeStateSchemaAst2(runtime);
1046
+ const selectorResult = makeSchemaSelector(spec.path, schemaAst);
1047
+ if (!selectorResult.ok) {
1048
+ return yield* Effect3.fail(options.withModuleHint(selectorResult.error, spec.moduleId));
1049
+ }
1050
+ const selectorBase = selectorResult.selector;
1051
+ const buildModuleStateChangeTrigger = (txnSeq) => ({
1052
+ kind: "moduleStateChange",
1053
+ name: spec.name,
1054
+ moduleId: spec.moduleId,
1055
+ instanceId: runtime.instanceId,
1056
+ path: spec.path,
1057
+ txnSeq: typeof txnSeq === "number" ? txnSeq : 1
1058
+ });
1059
+ const buildModuleStateChangeBaseStream = (selector2) => Effect3.gen(function* () {
1060
+ const readQuery = makeModuleStateChangeReadQuery({
1061
+ moduleId: spec.moduleId,
1062
+ path: spec.path,
1063
+ selector: selector2
1064
+ });
1065
+ const changesReadQueryWithMeta = runtime.changesReadQueryWithMeta;
1066
+ if (typeof changesReadQueryWithMeta === "function") {
1067
+ return changesReadQueryWithMeta(readQuery).pipe(
1068
+ Stream2.map((evt) => buildModuleStateChangeTrigger(evt?.meta?.txnSeq))
1069
+ );
1070
+ }
1071
+ const changesWithMeta = runtime.changesWithMeta;
1072
+ if (typeof changesWithMeta !== "function") {
1073
+ return yield* Effect3.fail(makeMissingChangesStreamError(spec.moduleId));
1074
+ }
1075
+ let hasPrevValue = false;
1076
+ let prevValue;
1077
+ return changesWithMeta(selector2).pipe(
1078
+ Stream2.filter((evt) => {
1079
+ if (hasPrevValue && Object.is(prevValue, evt.value)) {
1080
+ return false;
1081
+ }
1082
+ hasPrevValue = true;
1083
+ prevValue = evt.value;
1084
+ return true;
1085
+ }),
1086
+ Stream2.map((evt) => buildModuleStateChangeTrigger(evt?.meta?.txnSeq))
1087
+ );
1088
+ });
1089
+ if (!options.shouldRecordChainEvents) {
1090
+ return yield* buildModuleStateChangeBaseStream(selectorBase);
1091
+ }
1092
+ const selectorDiagnosticsConfig = makeSelectorDiagnosticsConfig(isDevEnv());
1093
+ const selectorDiagnosticsRef = yield* Ref2.make(initialSelectorDiagnosticsState(Date.now()));
1094
+ const selectorSampling = makeSelectorSamplingTracker(selectorDiagnosticsConfig);
1095
+ const selector = (state) => {
1096
+ if (!selectorSampling.onSelectorCall()) {
1097
+ return selectorBase(state);
1098
+ }
1099
+ const t0 = nowMs();
1100
+ const value = selectorBase(state);
1101
+ const dt = nowMs() - t0;
1102
+ selectorSampling.recordSample(dt);
1103
+ return value;
1104
+ };
1105
+ const maybeWarnSelector = (trigger) => {
1106
+ return Effect3.gen(function* () {
1107
+ const now = Date.now();
1108
+ const sampling = selectorSampling.snapshot();
1109
+ const decision = yield* Ref2.modify(
1110
+ selectorDiagnosticsRef,
1111
+ (state) => evaluateSelectorWarning(state, now, {
1112
+ config: selectorDiagnosticsConfig,
1113
+ sampling: {
1114
+ sampled: sampling.sampled,
1115
+ maxSampleMs: sampling.maxSampleMs
1116
+ }
1117
+ })
1118
+ );
1119
+ if (!decision.shouldWarn) {
1120
+ return;
1121
+ }
1122
+ const code = decision.tooFrequent ? "process::selector_high_frequency" : "process::selector_slow";
1123
+ const hint = buildSelectorWarningHint({
1124
+ moduleId: spec.moduleId,
1125
+ path: spec.path,
1126
+ decision,
1127
+ config: selectorDiagnosticsConfig,
1128
+ sampling
1129
+ });
1130
+ selectorSampling.resetSampling();
1131
+ yield* options.emitSelectorWarning(trigger, {
1132
+ message: "moduleStateChange selector diagnostics warning",
1133
+ code,
1134
+ hint
1135
+ });
1136
+ });
1137
+ };
1138
+ const baseStream = yield* buildModuleStateChangeBaseStream(selector);
1139
+ return baseStream.pipe(Stream2.tap(maybeWarnSelector));
1140
+ });
1141
+ return (spec) => Effect3.gen(function* () {
1142
+ switch (spec.kind) {
1143
+ case "timer":
1144
+ return yield* makeTimerTriggerStream(spec);
1145
+ case "moduleAction":
1146
+ return yield* makeModuleActionTriggerStream(spec);
1147
+ case "moduleStateChange":
1148
+ return yield* makeModuleStateChangeTriggerStream(spec);
1149
+ default:
1150
+ return yield* Effect3.fail(makeInvalidTriggerKindError(spec));
1151
+ }
1152
+ });
1153
+ };
1154
+
643
1155
  // src/internal/runtime/core/process/supervision.ts
644
1156
  var initialState = () => ({ failureTimes: [] });
645
- var onFailure = (policy, state, nowMs) => {
1157
+ var onFailure = (policy, state, nowMs2) => {
646
1158
  if (policy.mode === "failStop") {
647
1159
  return {
648
1160
  decision: "stop",
@@ -665,8 +1177,8 @@ var onFailure = (policy, state, nowMs) => {
665
1177
  }
666
1178
  const windowMsRaw = policy.windowMs;
667
1179
  const windowMs = typeof windowMsRaw === "number" && Number.isFinite(windowMsRaw) && windowMsRaw > 0 ? Math.floor(windowMsRaw) : void 0;
668
- const failureTimesRaw = [...state.failureTimes, nowMs];
669
- const failureTimes = windowMs ? failureTimesRaw.filter((t) => t >= nowMs - windowMs) : failureTimesRaw;
1180
+ const failureTimesRaw = [...state.failureTimes, nowMs2];
1181
+ const failureTimes = windowMs ? failureTimesRaw.filter((t) => t >= nowMs2 - windowMs) : failureTimesRaw;
670
1182
  const cap = maxRestarts + 1;
671
1183
  const capped = failureTimes.length > cap ? failureTimes.slice(failureTimes.length - cap) : failureTimes;
672
1184
  const withinWindowFailures = capped.length;
@@ -680,14 +1192,19 @@ var onFailure = (policy, state, nowMs) => {
680
1192
  };
681
1193
  };
682
1194
 
683
- // src/internal/runtime/core/process/ProcessRuntime.ts
684
- var ProcessRuntimeTag = class extends Context2.Tag("@logixjs/core/ProcessRuntime")() {
1195
+ // src/internal/runtime/core/process/ProcessRuntime.make.ts
1196
+ var ProcessRuntimeTag = class extends ServiceMap2.Service()("@logixjs/core/ProcessRuntime") {
685
1197
  };
686
- var currentProcessTrigger = FiberRef2.unsafeMake(void 0);
687
- var currentProcessEventBudget = FiberRef2.unsafeMake(
688
- void 0
1198
+ var currentProcessTrigger = ServiceMap2.Reference("@logixjs/core/ProcessRuntime.currentTrigger", {
1199
+ defaultValue: () => void 0
1200
+ });
1201
+ var currentProcessEventBudget = ServiceMap2.Reference(
1202
+ "@logixjs/core/ProcessRuntime.currentEventBudget",
1203
+ {
1204
+ defaultValue: () => void 0
1205
+ }
689
1206
  );
690
- var RUNTIME_BOOT_EVENT = "runtime:boot";
1207
+ var PROCESS_EVENT_HISTORY_MAX_CAPACITY = 4294967294;
691
1208
  var deriveDebugModuleId = (processId) => `process:${processId}`;
692
1209
  var deriveTxnAnchor = (event) => {
693
1210
  const trigger = event.trigger;
@@ -701,18 +1218,48 @@ var deriveTxnAnchor = (event) => {
701
1218
  }
702
1219
  return {};
703
1220
  };
1221
+ var makeProcessTriggerChainKernel = (args) => {
1222
+ const assignTriggerSeq = (trigger) => {
1223
+ if (!args.shouldRecordChainEvents) {
1224
+ return trigger;
1225
+ }
1226
+ return {
1227
+ ...trigger,
1228
+ triggerSeq: args.nextTriggerSeq()
1229
+ };
1230
+ };
1231
+ const run = (trigger, fatal) => {
1232
+ if (!args.shouldRecordChainEvents) {
1233
+ return args.runWithoutChainBudget(trigger, fatal);
1234
+ }
1235
+ return Effect4.gen(function* () {
1236
+ const budgetRef = yield* Ref3.make(args.makeBudgetState(trigger));
1237
+ return yield* Effect4.provideService(args.emitTriggerEvent(trigger, "info").pipe(Effect4.flatMap(() => args.runWithoutChainBudget(trigger, fatal))), currentProcessEventBudget, budgetRef);
1238
+ });
1239
+ };
1240
+ const onDrop = (trigger) => args.emitTriggerEvent(trigger, "warning");
1241
+ return {
1242
+ assignTriggerSeq,
1243
+ run,
1244
+ onDrop
1245
+ };
1246
+ };
704
1247
  var shouldNoopDueToSyncTxn = (scope, kind) => {
705
1248
  const moduleId = scope.type === "moduleInstance" ? scope.moduleId : void 0;
706
1249
  const instanceId = scope.type === "moduleInstance" ? scope.instanceId : void 0;
707
- return shouldNoopInSyncTransactionFiber({
708
- moduleId,
709
- instanceId,
710
- code: "process::invalid_usage",
711
- severity: "error",
712
- message: "ProcessRuntime scheduling is not allowed inside a synchronous StateTransaction body (it may deadlock the txnQueue).",
713
- hint: "Trigger/schedule Process outside the transaction window (e.g. in a watcher's run section or a separate fiber); do not trigger Process directly inside a reducer / synchronous transaction body.",
714
- kind
715
- });
1250
+ return Effect4.provideService(
1251
+ shouldNoopInSyncTransactionFiber({
1252
+ moduleId,
1253
+ instanceId,
1254
+ code: "process::invalid_usage",
1255
+ severity: "error",
1256
+ message: "ProcessRuntime scheduling is not allowed inside a synchronous StateTransaction body (it may deadlock the txnQueue).",
1257
+ hint: "Trigger/schedule Process outside the transaction window (e.g. in a watcher's run section or a separate fiber); do not trigger Process directly inside a reducer / synchronous transaction body.",
1258
+ kind
1259
+ }),
1260
+ inSyncTransactionFiber,
1261
+ false
1262
+ );
716
1263
  };
717
1264
  var resolveRuntimeStateSchemaAst = (runtime) => {
718
1265
  try {
@@ -743,24 +1290,83 @@ var actionIdFromUnknown = (action) => {
743
1290
  if (typeof anyAction.type === "string" && anyAction.type.length > 0) return anyAction.type;
744
1291
  return void 0;
745
1292
  };
746
- var make = (options) => Effect3.gen(function* () {
747
- const runtimeScope = yield* Effect3.scope;
748
- const maxEventHistory = typeof options?.maxEventHistory === "number" && Number.isFinite(options.maxEventHistory) && options.maxEventHistory >= 0 ? Math.floor(options.maxEventHistory) : 500;
1293
+ var buildPlatformEventTriggerIndex = (definition) => {
1294
+ const index = /* @__PURE__ */ new Map();
1295
+ for (const trigger of definition.triggers) {
1296
+ if (trigger.kind !== "platformEvent") continue;
1297
+ const current = index.get(trigger.platformEvent);
1298
+ if (current) {
1299
+ current.push(trigger);
1300
+ } else {
1301
+ index.set(trigger.platformEvent, [trigger]);
1302
+ }
1303
+ }
1304
+ return index;
1305
+ };
1306
+ var syncPlatformEventInstallations = (options) => {
1307
+ for (const eventName of options.previousEventNames) {
1308
+ const current = options.installationsByEventName.get(eventName);
1309
+ if (!current) continue;
1310
+ current.delete(options.installationKey);
1311
+ if (current.size === 0) {
1312
+ options.installationsByEventName.delete(eventName);
1313
+ }
1314
+ }
1315
+ const nextEventNames = Array.from(options.nextTriggerIndex.keys());
1316
+ for (const eventName of nextEventNames) {
1317
+ const current = options.installationsByEventName.get(eventName);
1318
+ if (current) {
1319
+ current.add(options.installationKey);
1320
+ } else {
1321
+ options.installationsByEventName.set(eventName, /* @__PURE__ */ new Set([options.installationKey]));
1322
+ }
1323
+ }
1324
+ return nextEventNames;
1325
+ };
1326
+ var make3 = (options) => Effect4.gen(function* () {
1327
+ const runtimeScope = yield* Effect4.scope;
1328
+ const requestedMaxEventHistory = typeof options?.maxEventHistory === "number" && Number.isFinite(options.maxEventHistory) && options.maxEventHistory >= 0 ? Math.floor(options.maxEventHistory) : 500;
1329
+ const maxEventHistory = Math.min(requestedMaxEventHistory, PROCESS_EVENT_HISTORY_MAX_CAPACITY);
749
1330
  const installations = /* @__PURE__ */ new Map();
1331
+ const installationsByPlatformEvent = /* @__PURE__ */ new Map();
750
1332
  const instances = /* @__PURE__ */ new Map();
751
- const eventsBuffer = [];
1333
+ const eventHistoryCapacity = maxEventHistory > 0 ? maxEventHistory : 0;
1334
+ const eventHistoryRing = [];
1335
+ let eventHistoryStart = 0;
1336
+ let eventHistorySize = 0;
752
1337
  const eventsHub = yield* PubSub.sliding(Math.max(1, Math.min(2048, maxEventHistory)));
753
- const trimEvents = () => {
754
- if (maxEventHistory <= 0) {
755
- eventsBuffer.length = 0;
1338
+ const appendEventHistory = (event) => {
1339
+ if (eventHistoryCapacity <= 0) {
1340
+ eventHistorySize = 0;
1341
+ eventHistoryStart = 0;
1342
+ return;
1343
+ }
1344
+ if (eventHistorySize < eventHistoryCapacity) {
1345
+ const writeIndex = (eventHistoryStart + eventHistorySize) % eventHistoryCapacity;
1346
+ if (writeIndex === eventHistoryRing.length) {
1347
+ eventHistoryRing.push(event);
1348
+ } else {
1349
+ eventHistoryRing[writeIndex] = event;
1350
+ }
1351
+ eventHistorySize += 1;
756
1352
  return;
757
1353
  }
758
- if (eventsBuffer.length <= maxEventHistory) return;
759
- const excess = eventsBuffer.length - maxEventHistory;
760
- eventsBuffer.splice(0, excess);
1354
+ eventHistoryRing[eventHistoryStart] = event;
1355
+ eventHistoryStart = (eventHistoryStart + 1) % eventHistoryCapacity;
761
1356
  };
762
- const recordDebugEvent = (event) => Effect3.gen(function* () {
763
- const diagnosticsLevel = yield* FiberRef2.get(currentDiagnosticsLevel);
1357
+ const snapshotEventHistory = () => {
1358
+ if (eventHistoryCapacity <= 0 || eventHistorySize === 0) {
1359
+ return [];
1360
+ }
1361
+ const snapshot = new Array(eventHistorySize);
1362
+ for (let index = 0; index < eventHistorySize; index += 1) {
1363
+ const ringIndex = (eventHistoryStart + index) % eventHistoryCapacity;
1364
+ snapshot[index] = eventHistoryRing[ringIndex];
1365
+ }
1366
+ return snapshot;
1367
+ };
1368
+ const recordDebugEvent = (event) => Effect4.gen(function* () {
1369
+ const diagnosticsLevel = yield* Effect4.service(currentDiagnosticsLevel).pipe(Effect4.orDie);
764
1370
  if (diagnosticsLevel === "off") {
765
1371
  return;
766
1372
  }
@@ -779,20 +1385,21 @@ var make = (options) => Effect3.gen(function* () {
779
1385
  trigger: event.trigger,
780
1386
  dispatch: event.dispatch,
781
1387
  error: event.error,
1388
+ budgetEnvelope: event.budgetEnvelope,
1389
+ degrade: event.degrade,
782
1390
  txnSeq,
783
1391
  txnId
784
1392
  });
785
1393
  });
786
- const publishEvent = (event) => Effect3.gen(function* () {
787
- eventsBuffer.push(event);
788
- trimEvents();
1394
+ const publishEvent = (event) => Effect4.gen(function* () {
1395
+ appendEventHistory(event);
789
1396
  yield* PubSub.publish(eventsHub, event);
790
1397
  yield* recordDebugEvent(event);
791
1398
  });
792
- const emit = (event) => Effect3.gen(function* () {
793
- const budgetRef = yield* FiberRef2.get(currentProcessEventBudget);
1399
+ const emit = (event) => Effect4.gen(function* () {
1400
+ const budgetRef = yield* Effect4.service(currentProcessEventBudget).pipe(Effect4.orDie);
794
1401
  if (budgetRef) {
795
- const decision = yield* Ref2.modify(budgetRef, (state) => {
1402
+ const decision = yield* Ref3.modify(budgetRef, (state) => {
796
1403
  const [nextDecision, nextState] = applyProcessRunEventBudget(state, event);
797
1404
  return [nextDecision, nextState];
798
1405
  });
@@ -806,7 +1413,7 @@ var make = (options) => Effect3.gen(function* () {
806
1413
  });
807
1414
  const emitErrorDiagnostic = (scope, processId, code, message, hint) => {
808
1415
  if (!isDevEnv()) {
809
- return Effect3.void;
1416
+ return Effect4.void;
810
1417
  }
811
1418
  const moduleId = scope.type === "moduleInstance" ? scope.moduleId : void 0;
812
1419
  const instanceId = scope.type === "moduleInstance" ? scope.instanceId : void 0;
@@ -823,27 +1430,32 @@ var make = (options) => Effect3.gen(function* () {
823
1430
  });
824
1431
  };
825
1432
  const resolveMissingDependencies = (installation) => {
826
- const declared = installation.definition.requires ?? [];
827
- const implicitFromTriggers = [];
828
- for (const trigger of installation.definition.triggers) {
829
- if (trigger.kind === "moduleAction" || trigger.kind === "moduleStateChange") {
830
- implicitFromTriggers.push(trigger.moduleId);
831
- }
832
- }
833
- const requires = Array.from(/* @__PURE__ */ new Set([...declared, ...implicitFromTriggers]));
1433
+ const requires = installation.startPlan.dependencyModuleIds;
834
1434
  if (requires.length === 0) return [];
835
1435
  const missing = [];
836
1436
  for (const dep of requires) {
837
1437
  if (typeof dep !== "string" || dep.length === 0) continue;
838
- const tag = Context2.Tag(`@logixjs/Module/${dep}`)();
839
- const found = Context2.getOption(installation.env, tag);
840
- if (Option2.isNone(found)) {
1438
+ const tag = moduleRuntimeTagFromModuleId(dep);
1439
+ const found = ServiceMap2.getOption(installation.env, tag);
1440
+ if (Option3.isNone(found)) {
841
1441
  missing.push(dep);
842
1442
  }
843
1443
  }
844
1444
  return missing;
845
1445
  };
846
- const stopInstance = (instance, reason) => Effect3.gen(function* () {
1446
+ const buildModuleRuntimeRegistry = (installation, env) => {
1447
+ const registry = /* @__PURE__ */ new Map();
1448
+ for (const moduleId of installation.startPlan.dependencyModuleIds) {
1449
+ if (typeof moduleId !== "string" || moduleId.length === 0 || registry.has(moduleId)) continue;
1450
+ const tag = moduleRuntimeTagFromModuleId(moduleId);
1451
+ const found = ServiceMap2.getOption(env, tag);
1452
+ if (Option3.isSome(found)) {
1453
+ registry.set(moduleId, found.value);
1454
+ }
1455
+ }
1456
+ return registry;
1457
+ };
1458
+ const stopInstance = (instance, reason) => Effect4.gen(function* () {
847
1459
  if (instance.status.status === "stopped" || instance.status.status === "failed" || instance.status.status === "stopping") {
848
1460
  return;
849
1461
  }
@@ -877,7 +1489,7 @@ var make = (options) => Effect3.gen(function* () {
877
1489
  yield* startInstallation(instance.installationKey);
878
1490
  }
879
1491
  });
880
- const startInstallation = (installationKey) => Effect3.gen(function* () {
1492
+ const startInstallation = (installationKey) => Effect4.gen(function* () {
881
1493
  const installation = installations.get(installationKey);
882
1494
  if (!installation) return;
883
1495
  installation.pendingStart = void 0;
@@ -917,13 +1529,13 @@ var make = (options) => Effect3.gen(function* () {
917
1529
  if (installation.forkScope !== runtimeScope) {
918
1530
  yield* Scope2.addFinalizer(
919
1531
  installation.forkScope,
920
- Effect3.suspend(() => {
1532
+ Effect4.suspend(() => {
921
1533
  const status = instanceState.status.status;
922
1534
  if (status === "stopped" || status === "failed" || status === "stopping") {
923
- return Effect3.void;
1535
+ return Effect4.void;
924
1536
  }
925
1537
  return stopInstance(instanceState, "scopeDisposed");
926
- }).pipe(Effect3.catchAllCause(() => Effect3.void))
1538
+ }).pipe(Effect4.catchCause(() => Effect4.void))
927
1539
  );
928
1540
  }
929
1541
  yield* emit({
@@ -974,345 +1586,113 @@ var make = (options) => Effect3.gen(function* () {
974
1586
  }
975
1587
  const shouldRecordChainEvents = installation.definition.diagnosticsLevel !== "off";
976
1588
  const baseEnv = installation.env;
1589
+ const moduleRuntimeRegistry = buildModuleRuntimeRegistry(installation, baseEnv);
977
1590
  const makeWrappedEnv = () => {
978
1591
  if (!shouldRecordChainEvents) {
979
1592
  return baseEnv;
980
1593
  }
981
- const requires = installation.definition.requires ?? [];
1594
+ const requires = installation.startPlan.dispatchTracingModuleIds;
982
1595
  if (requires.length === 0) {
983
1596
  return baseEnv;
984
1597
  }
985
- const ids = Array.from(new Set(requires));
986
1598
  let nextEnv = baseEnv;
987
- for (const moduleId of ids) {
1599
+ for (const moduleId of requires) {
988
1600
  if (typeof moduleId !== "string" || moduleId.length === 0) continue;
989
- const tag = Context2.Tag(`@logixjs/Module/${moduleId}`)();
990
- const found = Context2.getOption(baseEnv, tag);
991
- if (Option2.isNone(found)) continue;
1601
+ const tag = moduleRuntimeTagFromModuleId(moduleId);
1602
+ const found = ServiceMap2.getOption(baseEnv, tag);
1603
+ if (Option3.isNone(found)) continue;
992
1604
  const runtime = found.value;
993
- const recordDispatch = (action) => Effect3.gen(function* () {
994
- const trigger = yield* FiberRef2.get(currentProcessTrigger);
1605
+ const recordDispatch = (action) => Effect4.gen(function* () {
1606
+ const trigger = yield* Effect4.service(currentProcessTrigger).pipe(Effect4.orDie);
995
1607
  if (!trigger) return;
996
1608
  const actionId = actionIdFromUnknown(action) ?? "unknown";
997
1609
  const dispatchModuleId = typeof runtime.moduleId === "string" ? runtime.moduleId : moduleId;
998
1610
  const dispatchInstanceId = typeof runtime.instanceId === "string" ? runtime.instanceId : "unknown";
999
- const evt = {
1000
- type: "process:dispatch",
1001
- identity,
1002
- trigger,
1003
- dispatch: {
1611
+ yield* emit(
1612
+ makeDispatchEvent(trigger, {
1004
1613
  moduleId: dispatchModuleId,
1005
1614
  instanceId: dispatchInstanceId,
1006
1615
  actionId
1007
- },
1008
- severity: "info",
1009
- eventSeq: instanceState.nextEventSeq++,
1010
- timestampMs: Date.now()
1011
- };
1012
- yield* emit(evt);
1616
+ })
1617
+ );
1013
1618
  });
1014
1619
  const wrapped = {
1015
1620
  ...runtime,
1016
- dispatch: (action) => runtime.dispatch(action).pipe(Effect3.tap(() => recordDispatch(action))),
1017
- dispatchLowPriority: (action) => runtime.dispatchLowPriority(action).pipe(Effect3.tap(() => recordDispatch(action))),
1018
- dispatchBatch: (actions) => runtime.dispatchBatch(actions).pipe(Effect3.tap(() => Effect3.forEach(actions, recordDispatch, { discard: true })))
1621
+ dispatch: (action) => runtime.dispatch(action).pipe(Effect4.tap(() => recordDispatch(action))),
1622
+ dispatchLowPriority: (action) => runtime.dispatchLowPriority(action).pipe(Effect4.tap(() => recordDispatch(action))),
1623
+ dispatchBatch: (actions) => runtime.dispatchBatch(actions).pipe(Effect4.tap(() => Effect4.forEach(actions, recordDispatch, { discard: true })))
1019
1624
  };
1020
- nextEnv = Context2.add(tag, wrapped)(nextEnv);
1625
+ nextEnv = ServiceMap2.add(nextEnv, tag, wrapped);
1021
1626
  }
1022
1627
  return nextEnv;
1023
1628
  };
1024
1629
  const wrappedEnv = makeWrappedEnv();
1025
- const providedProcess = Effect3.provide(installation.process, wrappedEnv);
1026
- const makeTriggerStream = (spec) => Effect3.gen(function* () {
1027
- if (spec.kind === "timer") {
1028
- const interval = Duration.decodeUnknown(spec.timerId);
1029
- if (Option2.isNone(interval)) {
1030
- const err = new Error(`[ProcessRuntime] invalid timerId (expected DurationInput): ${spec.timerId}`);
1031
- err.code = "process::invalid_timer_id";
1032
- err.hint = "timerId must be a valid DurationInput string, e.g. '10 millis', '1 seconds', '5 minutes'.";
1033
- return yield* Effect3.fail(err);
1034
- }
1035
- return Stream2.tick(interval.value).pipe(
1036
- Stream2.map(
1037
- () => ({
1038
- kind: "timer",
1039
- name: spec.name,
1040
- timerId: spec.timerId
1041
- })
1042
- )
1043
- );
1044
- }
1045
- if (spec.kind === "moduleAction") {
1046
- const tag2 = Context2.Tag(`@logixjs/Module/${spec.moduleId}`)();
1047
- const found2 = Context2.getOption(baseEnv, tag2);
1048
- if (Option2.isNone(found2)) {
1049
- return yield* Effect3.fail(new Error(`Missing module runtime in scope: ${spec.moduleId}`));
1050
- }
1051
- const runtime2 = found2.value;
1052
- if (!shouldRecordChainEvents) {
1053
- const stream2 = runtime2.actions$;
1054
- if (!stream2) {
1055
- const err = new Error("ModuleRuntime does not provide actions$ (required for moduleAction trigger).");
1056
- err.code = "process::missing_action_stream";
1057
- err.hint = `moduleId=${spec.moduleId}`;
1058
- return yield* Effect3.fail(err);
1059
- }
1060
- return stream2.pipe(
1061
- Stream2.filter((action) => actionIdFromUnknown(action) === spec.actionId),
1062
- Stream2.map(
1063
- () => ({
1064
- kind: "moduleAction",
1065
- name: spec.name,
1066
- moduleId: spec.moduleId,
1067
- instanceId: runtime2.instanceId,
1068
- actionId: spec.actionId,
1069
- txnSeq: 1
1070
- })
1071
- )
1072
- );
1073
- }
1074
- const stream = runtime2.actionsWithMeta$;
1075
- if (!stream) {
1076
- const err = new Error(
1077
- "ModuleRuntime does not provide actionsWithMeta$ (required for moduleAction trigger)."
1078
- );
1079
- err.code = "process::missing_action_meta_stream";
1080
- err.hint = `moduleId=${spec.moduleId}`;
1081
- return yield* Effect3.fail(err);
1630
+ const providedProcess = Effect4.provide(installation.process, wrappedEnv);
1631
+ const nextProcessEventMeta = () => ({
1632
+ identity,
1633
+ eventSeq: instanceState.nextEventSeq++,
1634
+ timestampMs: Date.now()
1635
+ });
1636
+ const makeDispatchEvent = (trigger, dispatch) => ({
1637
+ type: "process:dispatch",
1638
+ trigger,
1639
+ dispatch,
1640
+ severity: "info",
1641
+ ...nextProcessEventMeta()
1642
+ });
1643
+ const makeTriggerEvent = (trigger, severity, error) => ({
1644
+ type: "process:trigger",
1645
+ trigger,
1646
+ severity,
1647
+ ...error ? { error } : null,
1648
+ ...nextProcessEventMeta()
1649
+ });
1650
+ const makeTriggerStream = makeNonPlatformTriggerStreamFactory({
1651
+ moduleRuntimeRegistry,
1652
+ shouldRecordChainEvents,
1653
+ actionIdFromUnknown,
1654
+ resolveRuntimeStateSchemaAst,
1655
+ withModuleHint,
1656
+ emitSelectorWarning: (trigger, warning) => emit(makeTriggerEvent(trigger, "warning", warning))
1657
+ });
1658
+ const makeRun = (trigger, fatal) => Effect4.provideService(providedProcess.pipe(
1659
+ Effect4.catchCause((cause) => {
1660
+ if (Cause.hasInterruptsOnly(cause)) {
1661
+ return Effect4.void;
1082
1662
  }
1083
- return stream.pipe(
1084
- Stream2.filter((evt) => actionIdFromUnknown(evt.value) === spec.actionId),
1085
- Stream2.map((evt) => {
1086
- const txnSeq = evt?.meta?.txnSeq;
1087
- return {
1088
- kind: "moduleAction",
1089
- name: spec.name,
1090
- moduleId: spec.moduleId,
1091
- instanceId: runtime2.instanceId,
1092
- actionId: spec.actionId,
1093
- txnSeq: typeof txnSeq === "number" ? txnSeq : 1
1094
- };
1095
- })
1663
+ return Deferred.succeed(fatal, cause).pipe(
1664
+ Effect4.asVoid,
1665
+ Effect4.catch(() => Effect4.void)
1096
1666
  );
1097
- }
1098
- const tag = Context2.Tag(`@logixjs/Module/${spec.moduleId}`)();
1099
- const found = Context2.getOption(baseEnv, tag);
1100
- if (Option2.isNone(found)) {
1101
- return yield* Effect3.fail(new Error(`Missing module runtime in scope: ${spec.moduleId}`));
1102
- }
1103
- const runtime = found.value;
1104
- const schemaAst = resolveRuntimeStateSchemaAst(runtime);
1105
- const selectorResult = makeSchemaSelector(spec.path, schemaAst);
1106
- if (!selectorResult.ok) {
1107
- return yield* Effect3.fail(withModuleHint(selectorResult.error, spec.moduleId));
1108
- }
1109
- const selectorBase = selectorResult.selector;
1110
- const prevRef = yield* Ref2.make(Option2.none());
1111
- const enableSelectorDiagnostics = shouldRecordChainEvents;
1112
- const selectorDiagnosticsRef = enableSelectorDiagnostics ? yield* Ref2.make({
1113
- windowStartedMs: Date.now(),
1114
- triggersInWindow: 0,
1115
- lastWarningAtMs: 0
1116
- }) : void 0;
1117
- const sampleEveryMask = 127;
1118
- const slowSampleThresholdMs = 4;
1119
- const triggerWindowMs = 1e3;
1120
- const triggerWarningThreshold = isDevEnv() ? 20 : 200;
1121
- const warningCooldownMs = 3e4;
1122
- let selectorCalls = 0;
1123
- let selectorSamples = 0;
1124
- let selectorSlowSamples = 0;
1125
- let selectorMaxSampleMs = 0;
1126
- const nowMs = () => {
1127
- if (typeof performance !== "undefined" && typeof performance.now === "function") {
1128
- return performance.now();
1129
- }
1130
- return Date.now();
1131
- };
1132
- const selector = enableSelectorDiagnostics ? (state) => {
1133
- selectorCalls += 1;
1134
- if ((selectorCalls & sampleEveryMask) !== 0) {
1135
- return selectorBase(state);
1136
- }
1137
- const t0 = nowMs();
1138
- const value = selectorBase(state);
1139
- const dt = nowMs() - t0;
1140
- selectorSamples += 1;
1141
- if (dt >= slowSampleThresholdMs) {
1142
- selectorSlowSamples += 1;
1143
- }
1144
- if (dt > selectorMaxSampleMs) {
1145
- selectorMaxSampleMs = dt;
1146
- }
1147
- return value;
1148
- } : selectorBase;
1149
- const maybeWarnSelector = (trigger) => {
1150
- if (!selectorDiagnosticsRef) {
1151
- return Effect3.void;
1152
- }
1153
- return Effect3.gen(function* () {
1154
- const now = Date.now();
1155
- const decision = yield* Ref2.modify(selectorDiagnosticsRef, (s) => {
1156
- const windowExpired = now - s.windowStartedMs >= triggerWindowMs;
1157
- const windowStartedMs = windowExpired ? now : s.windowStartedMs;
1158
- const triggersInWindow = windowExpired ? 1 : s.triggersInWindow + 1;
1159
- const shouldCooldown = now - s.lastWarningAtMs < warningCooldownMs;
1160
- const tooFrequent = triggersInWindow >= triggerWarningThreshold;
1161
- const tooSlow = selectorMaxSampleMs >= slowSampleThresholdMs && selectorSamples > 0;
1162
- const shouldWarn = !shouldCooldown && (tooFrequent || tooSlow);
1163
- const next = shouldWarn ? {
1164
- windowStartedMs: now,
1165
- triggersInWindow: 0,
1166
- lastWarningAtMs: now
1167
- } : {
1168
- ...s,
1169
- windowStartedMs,
1170
- triggersInWindow
1171
- };
1172
- return [
1173
- {
1174
- shouldWarn,
1175
- tooFrequent,
1176
- tooSlow,
1177
- triggersInWindow
1178
- },
1179
- next
1180
- ];
1181
- });
1182
- if (!decision.shouldWarn) {
1183
- return;
1184
- }
1185
- const code = decision.tooFrequent ? "process::selector_high_frequency" : "process::selector_slow";
1186
- const hint = [
1187
- `moduleId=${spec.moduleId}`,
1188
- `path=${spec.path}`,
1189
- `windowMs=${triggerWindowMs}`,
1190
- `triggersInWindow=${decision.triggersInWindow}`,
1191
- `threshold=${triggerWarningThreshold}`,
1192
- `cooldownMs=${warningCooldownMs}`,
1193
- "",
1194
- "selector sampling:",
1195
- `calls=${selectorCalls}`,
1196
- `sampled=${selectorSamples}`,
1197
- `slowSamples(>=${slowSampleThresholdMs}ms)=${selectorSlowSamples}`,
1198
- `maxSampleMs=${selectorMaxSampleMs.toFixed(2)}`,
1199
- "",
1200
- "notes:",
1201
- "- Ensure the selected value is stable (prefer primitive/tuple; avoid returning fresh objects).",
1202
- "- Narrow the path to reduce change frequency; avoid selecting large objects."
1203
- ].join("\n");
1204
- selectorSamples = 0;
1205
- selectorSlowSamples = 0;
1206
- selectorMaxSampleMs = 0;
1207
- yield* emit({
1208
- type: "process:trigger",
1209
- identity,
1210
- trigger,
1211
- severity: "warning",
1212
- eventSeq: instanceState.nextEventSeq++,
1213
- timestampMs: Date.now(),
1214
- error: {
1215
- message: "moduleStateChange selector diagnostics warning",
1216
- code,
1217
- hint
1218
- }
1219
- });
1220
- });
1221
- };
1222
- const baseStream = runtime.changesWithMeta(selector).pipe(
1223
- Stream2.mapEffect(
1224
- (evt) => Ref2.get(prevRef).pipe(
1225
- Effect3.flatMap((prev) => {
1226
- if (Option2.isSome(prev) && Object.is(prev.value, evt.value)) {
1227
- return Effect3.succeed(Option2.none());
1228
- }
1229
- return Ref2.set(prevRef, Option2.some(evt.value)).pipe(Effect3.as(Option2.some(evt)));
1230
- })
1231
- )
1232
- ),
1233
- Stream2.filterMap((opt) => opt),
1234
- Stream2.map((evt) => {
1235
- const txnSeq = evt?.meta?.txnSeq;
1236
- return {
1237
- kind: "moduleStateChange",
1238
- name: spec.name,
1239
- moduleId: spec.moduleId,
1240
- instanceId: runtime.instanceId,
1241
- path: spec.path,
1242
- txnSeq: typeof txnSeq === "number" ? txnSeq : 1
1243
- };
1244
- })
1245
- );
1246
- return enableSelectorDiagnostics ? baseStream.pipe(Stream2.tap(maybeWarnSelector)) : baseStream;
1247
- });
1248
- const makeRun = (trigger, fatal) => Effect3.locally(
1249
- currentProcessTrigger,
1250
- trigger
1251
- )(
1252
- providedProcess.pipe(
1253
- Effect3.catchAllCause((cause) => {
1254
- if (Cause.isInterruptedOnly(cause)) {
1255
- return Effect3.void;
1256
- }
1257
- return Deferred.succeed(fatal, cause).pipe(
1258
- Effect3.asVoid,
1259
- Effect3.catchAll(() => Effect3.void)
1260
- );
1261
- })
1262
- )
1263
- );
1264
- const makeChainRun = (trigger, fatal) => {
1265
- if (!shouldRecordChainEvents) {
1266
- return makeRun(trigger, fatal);
1267
- }
1268
- return Effect3.gen(function* () {
1269
- const budgetRef = yield* Ref2.make(makeProcessRunEventBudgetState());
1270
- return yield* Effect3.locally(
1271
- currentProcessEventBudget,
1272
- budgetRef
1273
- )(emitTriggerEvent(trigger, "info").pipe(Effect3.zipRight(makeRun(trigger, fatal))));
1274
- });
1275
- };
1276
- const assignTriggerSeq = (trigger) => {
1277
- if (!shouldRecordChainEvents) {
1278
- return trigger;
1279
- }
1280
- return {
1281
- ...trigger,
1282
- triggerSeq: instanceState.nextTriggerSeq++
1283
- };
1284
- };
1667
+ })
1668
+ ), currentProcessTrigger, trigger);
1285
1669
  const emitTriggerEvent = (trigger, severity) => {
1286
1670
  if (!shouldRecordChainEvents) {
1287
- return Effect3.void;
1671
+ return Effect4.void;
1288
1672
  }
1289
- const evt = {
1290
- type: "process:trigger",
1291
- identity,
1292
- trigger,
1293
- severity,
1294
- eventSeq: instanceState.nextEventSeq++,
1295
- timestampMs: Date.now()
1296
- };
1297
- return emit(evt);
1673
+ return emit(makeTriggerEvent(trigger, severity));
1298
1674
  };
1675
+ const triggerChainKernel = makeProcessTriggerChainKernel({
1676
+ shouldRecordChainEvents,
1677
+ nextTriggerSeq: () => instanceState.nextTriggerSeq++,
1678
+ makeBudgetState: (trigger) => makeProcessRunEventBudgetState({
1679
+ runId: makeProcessRunBudgetRunId(identity, trigger)
1680
+ }),
1681
+ emitTriggerEvent,
1682
+ runWithoutChainBudget: makeRun
1683
+ });
1299
1684
  const policy = installation.definition.concurrency;
1300
- const autoStart = installation.definition.triggers.some(
1301
- (t) => t.kind === "platformEvent" && t.platformEvent === RUNTIME_BOOT_EVENT
1302
- );
1303
- const bootTriggerSpec = installation.definition.triggers.find(
1304
- (t) => t.kind === "platformEvent" && t.platformEvent === RUNTIME_BOOT_EVENT
1305
- );
1306
- const instanceProgram = Effect3.gen(function* () {
1685
+ const bootTrigger = installation.startPlan.bootTrigger;
1686
+ const streamReady = yield* Deferred.make();
1687
+ const markStreamReady = Deferred.succeed(streamReady, void 0).pipe(Effect4.asVoid);
1688
+ const instanceProgram = Effect4.gen(function* () {
1307
1689
  const fatal = yield* Deferred.make();
1308
- const platformEventStream = Stream2.fromQueue(
1690
+ const platformEventStream = Stream3.fromQueue(
1309
1691
  instanceState.platformTriggersQueue
1310
1692
  );
1311
- const nonPlatformTriggers = installation.definition.triggers.filter(
1312
- (t) => t.kind !== "platformEvent"
1313
- );
1314
- const streams = yield* Effect3.forEach(nonPlatformTriggers, makeTriggerStream);
1315
- const triggerStream = Stream2.mergeAll([platformEventStream, ...streams], {
1693
+ const nonPlatformTriggers = installation.startPlan.nonPlatformTriggers;
1694
+ const streams = yield* Effect4.forEach(nonPlatformTriggers, makeTriggerStream);
1695
+ const triggerStream = Stream3.mergeAll([platformEventStream, ...streams], {
1316
1696
  concurrency: "unbounded"
1317
1697
  });
1318
1698
  const reportQueueOverflow = (info) => {
@@ -1328,36 +1708,41 @@ var make = (options) => Effect3.gen(function* () {
1328
1708
  "- Configure concurrency.maxQueue (serial) to a finite value, or switch to mode=latest/drop to avoid unbounded backlog."
1329
1709
  ].join("\n");
1330
1710
  return Deferred.succeed(fatal, Cause.fail(err)).pipe(
1331
- Effect3.asVoid,
1332
- Effect3.catchAll(() => Effect3.void)
1711
+ Effect4.asVoid,
1712
+ Effect4.catch(() => Effect4.void)
1333
1713
  );
1334
1714
  };
1335
- const runnerFiber = yield* Effect3.forkScoped(
1715
+ const runnerFiber = yield* Effect4.forkScoped(
1336
1716
  runProcessTriggerStream({
1337
1717
  stream: triggerStream,
1338
1718
  policy,
1339
- assignTriggerSeq,
1340
- run: (trigger) => makeChainRun(trigger, fatal),
1341
- onDrop: (trigger) => emitTriggerEvent(trigger, "warning"),
1719
+ assignTriggerSeq: triggerChainKernel.assignTriggerSeq,
1720
+ run: (trigger) => triggerChainKernel.run(trigger, fatal),
1721
+ onDrop: triggerChainKernel.onDrop,
1342
1722
  onQueueOverflow: reportQueueOverflow
1343
1723
  })
1344
1724
  );
1345
- if (autoStart) {
1346
- yield* Queue.offer(instanceState.platformTriggersQueue, {
1347
- kind: "platformEvent",
1348
- name: bootTriggerSpec?.name,
1349
- platformEvent: RUNTIME_BOOT_EVENT
1350
- });
1725
+ for (let i = 0; i < 64; i++) {
1726
+ const exitOpt = yield* Fiber2.await(runnerFiber).pipe(Effect4.timeoutOption(0));
1727
+ if (Option3.isSome(exitOpt)) {
1728
+ break;
1729
+ }
1730
+ yield* Effect4.yieldNow;
1731
+ }
1732
+ yield* markStreamReady;
1733
+ if (bootTrigger) {
1734
+ yield* Queue.offer(instanceState.platformTriggersQueue, bootTrigger);
1351
1735
  }
1352
1736
  const cause = yield* Deferred.await(fatal);
1353
1737
  yield* Fiber2.interrupt(runnerFiber);
1354
- return yield* Effect3.failCause(cause);
1738
+ return yield* Effect4.failCause(cause);
1355
1739
  });
1356
- const fiber = yield* Effect3.forkIn(installation.forkScope)(
1357
- Effect3.scoped(instanceProgram).pipe(
1358
- Effect3.catchAllCause(
1359
- (cause) => Effect3.gen(function* () {
1360
- if (Cause.isInterruptedOnly(cause)) {
1740
+ const processFiberEffect = Effect4.provideService(
1741
+ Effect4.scoped(instanceProgram).pipe(
1742
+ Effect4.ensuring(markStreamReady),
1743
+ Effect4.catchCause(
1744
+ (cause) => Effect4.gen(function* () {
1745
+ if (Cause.hasInterruptsOnly(cause)) {
1361
1746
  if (instanceState.status.status === "stopping") {
1362
1747
  return;
1363
1748
  }
@@ -1367,7 +1752,7 @@ var make = (options) => Effect3.gen(function* () {
1367
1752
  stoppedReason: "scopeDisposed"
1368
1753
  };
1369
1754
  instanceState.fiber = void 0;
1370
- yield* Effect3.uninterruptible(
1755
+ yield* Effect4.uninterruptible(
1371
1756
  emit({
1372
1757
  type: "process:stop",
1373
1758
  identity,
@@ -1376,17 +1761,17 @@ var make = (options) => Effect3.gen(function* () {
1376
1761
  timestampMs: Date.now()
1377
1762
  })
1378
1763
  );
1379
- const installation2 = installations.get(installationKey);
1380
- if (installation2?.pendingStart) {
1381
- installation2.pendingStart = void 0;
1764
+ const pendingInstallation = installations.get(installationKey);
1765
+ if (pendingInstallation?.pendingStart) {
1766
+ pendingInstallation.pendingStart = void 0;
1382
1767
  yield* startInstallation(installationKey);
1383
1768
  }
1384
1769
  return;
1385
1770
  }
1386
- const primary = Option2.getOrElse(
1387
- Cause.failureOption(cause),
1388
- () => Option2.getOrElse(Cause.dieOption(cause), () => cause)
1389
- );
1771
+ const primary = Option3.getOrElse(Cause.findErrorOption(cause), () => {
1772
+ const defects = cause.reasons.filter(Cause.isDieReason).map((reason) => reason.defect);
1773
+ return defects[0] ?? cause;
1774
+ });
1390
1775
  const summary = toSerializableErrorSummary(primary);
1391
1776
  const error = summary.errorSummary;
1392
1777
  instanceState.status = {
@@ -1430,53 +1815,78 @@ var make = (options) => Effect3.gen(function* () {
1430
1815
  }
1431
1816
  })
1432
1817
  )
1433
- )
1818
+ ),
1819
+ inSyncTransactionFiber,
1820
+ false
1434
1821
  );
1822
+ const fiber = yield* Effect4.forkIn(processFiberEffect, installation.forkScope);
1435
1823
  instanceState.fiber = fiber;
1436
1824
  instanceState.status = {
1437
1825
  ...instanceState.status,
1438
1826
  status: "running"
1439
1827
  };
1440
- yield* Effect3.yieldNow();
1828
+ yield* Deferred.await(streamReady);
1441
1829
  });
1442
- const install = (process, options2) => Effect3.gen(function* () {
1830
+ const install = (process, options2) => Effect4.gen(function* () {
1443
1831
  const meta = getMeta(process);
1444
1832
  if (!meta) {
1445
1833
  return void 0;
1446
1834
  }
1447
- const env = yield* Effect3.context();
1448
- const forkScopeOpt = yield* Effect3.serviceOption(Scope2.Scope);
1449
- const forkScope = Option2.isSome(forkScopeOpt) ? forkScopeOpt.value : runtimeScope;
1835
+ const env = yield* Effect4.services();
1836
+ const forkScopeOpt = yield* Effect4.serviceOption(Scope2.Scope);
1837
+ const forkScope = Option3.isSome(forkScopeOpt) ? forkScopeOpt.value : runtimeScope;
1450
1838
  const scopeKey = scopeKeyFromScope(options2.scope);
1451
1839
  const identity = {
1452
1840
  processId: meta.definition.processId,
1453
1841
  scope: options2.scope
1454
1842
  };
1455
1843
  const installationKey = installationKeyFromIdentity(identity);
1844
+ const derived = Effect4.suspend(() => process);
1845
+ attachMeta(derived, {
1846
+ ...meta,
1847
+ installationScope: options2.scope
1848
+ });
1849
+ const nextPlatformEventTriggerIndex = buildPlatformEventTriggerIndex(meta.definition);
1850
+ const nextStartPlan = compileProcessTriggerStartPlan(meta.definition);
1456
1851
  const existing = installations.get(installationKey);
1457
1852
  if (existing) {
1458
- existing.env = env;
1459
- existing.forkScope = forkScope;
1460
- existing.enabled = options2.enabled ?? true;
1461
- existing.installedAt = options2.installedAt ?? existing.installedAt;
1462
- if (!existing.enabled) {
1463
- existing.pendingStart = void 0;
1853
+ const updated = {
1854
+ ...existing,
1855
+ definition: meta.definition,
1856
+ env,
1857
+ forkScope,
1858
+ process: derived,
1859
+ kind: meta.kind ?? "process",
1860
+ platformEventTriggerIndex: nextPlatformEventTriggerIndex,
1861
+ platformEventNames: syncPlatformEventInstallations({
1862
+ installationKey,
1863
+ previousEventNames: existing.platformEventNames,
1864
+ nextTriggerIndex: nextPlatformEventTriggerIndex,
1865
+ installationsByEventName: installationsByPlatformEvent
1866
+ }),
1867
+ startPlan: nextStartPlan,
1868
+ enabled: options2.enabled ?? existing.enabled,
1869
+ installedAt: options2.installedAt ?? existing.installedAt
1870
+ };
1871
+ installations.set(installationKey, updated);
1872
+ if (!updated.enabled) {
1873
+ updated.pendingStart = void 0;
1464
1874
  return {
1465
1875
  identity,
1466
- enabled: existing.enabled,
1467
- installedAt: existing.installedAt
1876
+ enabled: updated.enabled,
1877
+ installedAt: updated.installedAt
1468
1878
  };
1469
1879
  }
1470
- const currentId = existing.currentInstanceId;
1880
+ const currentId = updated.currentInstanceId;
1471
1881
  const current = currentId ? instances.get(currentId) : void 0;
1472
1882
  const status = current?.status.status;
1473
1883
  if (status === "running" || status === "starting") {
1474
1884
  const mode = options2.mode ?? "switch";
1475
1885
  if (mode === "switch" && current && current.forkScope !== forkScope) {
1476
- existing.pendingStart = { forkScope };
1886
+ updated.pendingStart = { forkScope };
1477
1887
  yield* Scope2.addFinalizer(
1478
1888
  forkScope,
1479
- Effect3.sync(() => {
1889
+ Effect4.sync(() => {
1480
1890
  const installation2 = installations.get(installationKey);
1481
1891
  if (!installation2) return;
1482
1892
  if (installation2.pendingStart?.forkScope === forkScope) {
@@ -1485,21 +1895,21 @@ var make = (options) => Effect3.gen(function* () {
1485
1895
  })
1486
1896
  );
1487
1897
  } else {
1488
- existing.pendingStart = void 0;
1898
+ updated.pendingStart = void 0;
1489
1899
  }
1490
1900
  return {
1491
1901
  identity,
1492
- enabled: existing.enabled,
1493
- installedAt: existing.installedAt
1902
+ enabled: updated.enabled,
1903
+ installedAt: updated.installedAt
1494
1904
  };
1495
1905
  }
1496
1906
  if (status === "stopping") {
1497
1907
  const mode = options2.mode ?? "switch";
1498
1908
  if (mode === "switch") {
1499
- existing.pendingStart = { forkScope };
1909
+ updated.pendingStart = { forkScope };
1500
1910
  yield* Scope2.addFinalizer(
1501
1911
  forkScope,
1502
- Effect3.sync(() => {
1912
+ Effect4.sync(() => {
1503
1913
  const installation2 = installations.get(installationKey);
1504
1914
  if (!installation2) return;
1505
1915
  if (installation2.pendingStart?.forkScope === forkScope) {
@@ -1508,26 +1918,27 @@ var make = (options) => Effect3.gen(function* () {
1508
1918
  })
1509
1919
  );
1510
1920
  } else {
1511
- existing.pendingStart = void 0;
1921
+ updated.pendingStart = void 0;
1512
1922
  }
1513
1923
  return {
1514
1924
  identity,
1515
- enabled: existing.enabled,
1516
- installedAt: existing.installedAt
1925
+ enabled: updated.enabled,
1926
+ installedAt: updated.installedAt
1517
1927
  };
1518
1928
  }
1519
- existing.pendingStart = void 0;
1929
+ updated.pendingStart = void 0;
1520
1930
  yield* startInstallation(installationKey);
1521
1931
  return {
1522
1932
  identity,
1523
- enabled: existing.enabled,
1524
- installedAt: existing.installedAt
1933
+ enabled: updated.enabled,
1934
+ installedAt: updated.installedAt
1525
1935
  };
1526
1936
  }
1527
- const derived = Effect3.suspend(() => process);
1528
- attachMeta(derived, {
1529
- ...meta,
1530
- installationScope: options2.scope
1937
+ const nextPlatformEventNames = syncPlatformEventInstallations({
1938
+ installationKey,
1939
+ previousEventNames: [],
1940
+ nextTriggerIndex: nextPlatformEventTriggerIndex,
1941
+ installationsByEventName: installationsByPlatformEvent
1531
1942
  });
1532
1943
  const installation = {
1533
1944
  identity,
@@ -1537,6 +1948,9 @@ var make = (options) => Effect3.gen(function* () {
1537
1948
  forkScope,
1538
1949
  process: derived,
1539
1950
  kind: meta.kind ?? "process",
1951
+ platformEventTriggerIndex: nextPlatformEventTriggerIndex,
1952
+ platformEventNames: nextPlatformEventNames,
1953
+ startPlan: nextStartPlan,
1540
1954
  enabled: options2.enabled ?? true,
1541
1955
  installedAt: options2.installedAt,
1542
1956
  nextRunSeq: 1,
@@ -1553,7 +1967,7 @@ var make = (options) => Effect3.gen(function* () {
1553
1967
  installedAt: installation.installedAt
1554
1968
  };
1555
1969
  });
1556
- const listInstallations = (filter) => Effect3.sync(() => {
1970
+ const listInstallations = (filter) => Effect4.sync(() => {
1557
1971
  const scopeType = filter?.scopeType;
1558
1972
  const scopeKey = filter?.scopeKey;
1559
1973
  const out = [];
@@ -1568,26 +1982,26 @@ var make = (options) => Effect3.gen(function* () {
1568
1982
  }
1569
1983
  return out;
1570
1984
  });
1571
- const getInstanceStatus = (processInstanceId) => Effect3.sync(() => instances.get(processInstanceId)?.status);
1572
- const controlInstance = (processInstanceId, request) => Effect3.suspend(() => {
1985
+ const getInstanceStatus = (processInstanceId) => Effect4.sync(() => instances.get(processInstanceId)?.status);
1986
+ const controlInstance = (processInstanceId, request) => Effect4.suspend(() => {
1573
1987
  const instance = instances.get(processInstanceId);
1574
1988
  if (!instance) {
1575
- return Effect3.void;
1989
+ return Effect4.void;
1576
1990
  }
1577
1991
  return shouldNoopDueToSyncTxn(instance.scope, "process_control_in_transaction").pipe(
1578
- Effect3.flatMap((noop) => {
1992
+ Effect4.flatMap((noop) => {
1579
1993
  if (noop) {
1580
- return Effect3.void;
1994
+ return Effect4.void;
1581
1995
  }
1582
1996
  if (request.action === "stop") {
1583
1997
  return stopInstance(instance, "manualStop");
1584
1998
  }
1585
1999
  if (request.action === "restart") {
1586
2000
  return stopInstance(instance, "manualStop").pipe(
1587
- Effect3.flatMap(() => {
2001
+ Effect4.flatMap(() => {
1588
2002
  const installation = installations.get(instance.installationKey);
1589
2003
  if (!installation) {
1590
- return Effect3.void;
2004
+ return Effect4.void;
1591
2005
  }
1592
2006
  installation.currentInstanceId = void 0;
1593
2007
  return startInstallation(instance.installationKey);
@@ -1596,20 +2010,20 @@ var make = (options) => Effect3.gen(function* () {
1596
2010
  }
1597
2011
  if (request.action === "start") {
1598
2012
  if (instance.status.status === "running" || instance.status.status === "starting") {
1599
- return Effect3.void;
2013
+ return Effect4.void;
1600
2014
  }
1601
2015
  const installation = installations.get(instance.installationKey);
1602
2016
  if (!installation) {
1603
- return Effect3.void;
2017
+ return Effect4.void;
1604
2018
  }
1605
2019
  installation.currentInstanceId = void 0;
1606
2020
  return startInstallation(instance.installationKey);
1607
2021
  }
1608
- return Effect3.void;
2022
+ return Effect4.void;
1609
2023
  })
1610
2024
  );
1611
2025
  });
1612
- const deliverPlatformEvent = (event) => Effect3.gen(function* () {
2026
+ const deliverPlatformEvent = (event) => Effect4.gen(function* () {
1613
2027
  const noop = yield* shouldNoopInSyncTransactionFiber({
1614
2028
  code: "process::invalid_usage",
1615
2029
  severity: "error",
@@ -1618,25 +2032,34 @@ var make = (options) => Effect3.gen(function* () {
1618
2032
  kind: "process_platform_event_in_transaction"
1619
2033
  });
1620
2034
  if (noop) return;
1621
- const targets = Array.from(instances.values());
1622
2035
  const eventName = event.eventName;
1623
- yield* Effect3.forEach(
1624
- targets,
1625
- (instance) => Effect3.suspend(() => {
1626
- if (instance.status.status !== "starting" && instance.status.status !== "running") {
1627
- return Effect3.void;
1628
- }
1629
- const installation = installations.get(instance.installationKey);
2036
+ const installationKeys = installationsByPlatformEvent.get(eventName);
2037
+ if (!installationKeys || installationKeys.size === 0) {
2038
+ return;
2039
+ }
2040
+ yield* Effect4.forEach(
2041
+ installationKeys,
2042
+ (installationKey) => Effect4.suspend(() => {
2043
+ const installation = installations.get(installationKey);
1630
2044
  if (!installation) {
1631
- return Effect3.void;
2045
+ return Effect4.void;
1632
2046
  }
1633
- const specs = installation.definition.triggers.filter(
1634
- (t) => t.kind === "platformEvent" && t.platformEvent === eventName
1635
- );
1636
- if (specs.length === 0) {
1637
- return Effect3.void;
2047
+ const currentInstanceId = installation.currentInstanceId;
2048
+ if (!currentInstanceId) {
2049
+ return Effect4.void;
2050
+ }
2051
+ const instance = instances.get(currentInstanceId);
2052
+ if (!instance) {
2053
+ return Effect4.void;
2054
+ }
2055
+ if (instance.status.status !== "starting" && instance.status.status !== "running") {
2056
+ return Effect4.void;
2057
+ }
2058
+ const specs = installation.platformEventTriggerIndex.get(eventName);
2059
+ if (!specs || specs.length === 0) {
2060
+ return Effect4.void;
1638
2061
  }
1639
- return Effect3.forEach(
2062
+ return Effect4.forEach(
1640
2063
  specs,
1641
2064
  (spec) => Queue.offer(instance.platformTriggersQueue, {
1642
2065
  kind: "platformEvent",
@@ -1649,10 +2072,10 @@ var make = (options) => Effect3.gen(function* () {
1649
2072
  { discard: true }
1650
2073
  );
1651
2074
  });
1652
- const eventsStream = Stream2.fromPubSub(eventsHub);
1653
- const getEventsSnapshot = () => Effect3.sync(() => eventsBuffer.slice());
1654
- yield* Effect3.addFinalizer(
1655
- () => Effect3.gen(function* () {
2075
+ const eventsStream = Stream3.fromPubSub(eventsHub);
2076
+ const getEventsSnapshot = () => Effect4.sync(snapshotEventHistory);
2077
+ yield* Effect4.addFinalizer(
2078
+ () => Effect4.gen(function* () {
1656
2079
  for (const installation of installations.values()) {
1657
2080
  installation.pendingStart = void 0;
1658
2081
  }
@@ -1662,13 +2085,11 @@ var make = (options) => Effect3.gen(function* () {
1662
2085
  }
1663
2086
  }
1664
2087
  }).pipe(
1665
- Effect3.catchAllCause(
1666
- (cause) => Effect3.sync(() => {
1667
- if (isDevEnv()) {
1668
- console.warn("[ProcessRuntime] finalizer failed", Cause.pretty(cause));
1669
- }
1670
- })
1671
- )
2088
+ Effect4.catchCause((cause) => Effect4.sync(() => {
2089
+ if (isDevEnv()) {
2090
+ console.warn("[ProcessRuntime] finalizer failed", Cause.pretty(cause));
2091
+ }
2092
+ }))
1672
2093
  )
1673
2094
  );
1674
2095
  return {
@@ -1681,7 +2102,7 @@ var make = (options) => Effect3.gen(function* () {
1681
2102
  getEventsSnapshot
1682
2103
  };
1683
2104
  });
1684
- var layer = (options) => Layer2.scoped(ProcessRuntimeTag, make(options));
2105
+ var layer = (options) => Layer2.effect(ProcessRuntimeTag, make3(options));
1685
2106
 
1686
2107
  export {
1687
2108
  EvidenceCollectorTag,
@@ -1693,4 +2114,4 @@ export {
1693
2114
  ProcessRuntimeTag,
1694
2115
  layer
1695
2116
  };
1696
- //# sourceMappingURL=chunk-PAYXCY6A.js.map
2117
+ //# sourceMappingURL=chunk-MYB2B5WX.js.map