@logixjs/core 0.0.1 → 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (300) hide show
  1. package/LICENSE +201 -0
  2. package/dist/{Bound-BN1DQ_lM.d.ts → Bound-CEa1ihvH.d.ts} +2 -2
  3. package/dist/{Bound-BPIfH9SS.d.cts → Bound-CNLNkC7c.d.cts} +2 -2
  4. package/dist/Bound.cjs +620 -163
  5. package/dist/Bound.cjs.map +1 -1
  6. package/dist/Bound.d.cts +3 -3
  7. package/dist/Bound.d.ts +3 -3
  8. package/dist/Bound.js +14 -14
  9. package/dist/{Debug-Bq8Sqjcr.d.cts → Debug-BhMYr-1i.d.cts} +3 -3
  10. package/dist/{Debug-B5q5Bkzx.d.ts → Debug-ByM7m4Ft.d.ts} +3 -3
  11. package/dist/Debug.cjs +553 -32
  12. package/dist/Debug.cjs.map +1 -1
  13. package/dist/Debug.d.cts +10 -8
  14. package/dist/Debug.d.ts +10 -8
  15. package/dist/Debug.js +12 -10
  16. package/dist/EffectOp.cjs.map +1 -1
  17. package/dist/EffectOp.js +2 -3
  18. package/dist/EffectOp.js.map +1 -1
  19. package/dist/Env.cjs +664 -6
  20. package/dist/Env.cjs.map +1 -1
  21. package/dist/Env.js +5 -2
  22. package/dist/ExternalStore-BAz83PVq.d.cts +60 -0
  23. package/dist/ExternalStore-BYWPbYs8.d.ts +60 -0
  24. package/dist/ExternalStore.cjs +746 -0
  25. package/dist/ExternalStore.cjs.map +1 -0
  26. package/dist/ExternalStore.d.cts +4 -0
  27. package/dist/ExternalStore.d.ts +4 -0
  28. package/dist/ExternalStore.js +19 -0
  29. package/dist/ExternalStore.js.map +1 -0
  30. package/dist/{Flow-1fZT8MpX.d.cts → Flow-BlSoMmhV.d.cts} +2 -2
  31. package/dist/{Flow-BhpjE22E.d.ts → Flow-CQSGve5c.d.ts} +2 -2
  32. package/dist/Flow.cjs +2 -2
  33. package/dist/Flow.cjs.map +1 -1
  34. package/dist/Flow.d.cts +4 -4
  35. package/dist/Flow.d.ts +4 -4
  36. package/dist/Flow.js +7 -8
  37. package/dist/{Handle-D_cLW1Z3.d.ts → Handle-B7PSmsrY.d.ts} +1 -1
  38. package/dist/{Handle-D8D1zPb_.d.cts → Handle-ByovhL-c.d.cts} +1 -1
  39. package/dist/Handle.d.cts +3 -3
  40. package/dist/Handle.d.ts +3 -3
  41. package/dist/{Kernel-CnGE1Fyk.d.ts → Kernel-DGSpS4GM.d.ts} +2 -2
  42. package/dist/{Kernel-8kC-jOda.d.cts → Kernel-DZAk-Mrn.d.cts} +2 -2
  43. package/dist/Kernel.cjs +680 -22
  44. package/dist/Kernel.cjs.map +1 -1
  45. package/dist/Kernel.d.cts +10 -8
  46. package/dist/Kernel.d.ts +10 -8
  47. package/dist/Kernel.js +7 -4
  48. package/dist/{Link-Db7975nU.d.ts → Link-Cm4eR9n0.d.ts} +10 -3
  49. package/dist/{Link-fX8x1eCK.d.cts → Link-DF8i8iWR.d.cts} +10 -3
  50. package/dist/Link.cjs +1128 -86
  51. package/dist/Link.cjs.map +1 -1
  52. package/dist/Link.d.cts +3 -3
  53. package/dist/Link.d.ts +3 -3
  54. package/dist/Link.js +30 -25
  55. package/dist/{Logic-DRh4sDZj.d.cts → Logic-BcQA0AvE.d.cts} +1 -1
  56. package/dist/{Logic-BRjEMr-W.d.ts → Logic-OotSE1xw.d.ts} +1 -1
  57. package/dist/Logic.d.cts +3 -3
  58. package/dist/Logic.d.ts +3 -3
  59. package/dist/{MatchBuilder-CJk5oCkR.d.cts → MatchBuilder-BNDJ8waF.d.ts} +1 -1
  60. package/dist/{MatchBuilder-0QOc-nlU.d.ts → MatchBuilder-CvZ5WY1B.d.cts} +1 -1
  61. package/dist/MatchBuilder.d.cts +4 -4
  62. package/dist/MatchBuilder.d.ts +4 -4
  63. package/dist/Middleware-D8tUDLv_.d.cts +100 -0
  64. package/dist/Middleware-DS7CbTTN.d.ts +100 -0
  65. package/dist/Middleware.cjs +461 -13
  66. package/dist/Middleware.cjs.map +1 -1
  67. package/dist/Middleware.d.cts +2 -86
  68. package/dist/Middleware.d.ts +2 -86
  69. package/dist/Middleware.js +13 -11
  70. package/dist/{Module-DnzluX2J.d.ts → Module-CFj0I2yE.d.ts} +45 -18
  71. package/dist/{Module-B_0xRDMR.d.cts → Module-DpXPW9EQ.d.cts} +45 -18
  72. package/dist/Module.cjs +8583 -5741
  73. package/dist/Module.cjs.map +1 -1
  74. package/dist/Module.d.cts +5 -4
  75. package/dist/Module.d.ts +5 -4
  76. package/dist/Module.js +32 -27
  77. package/dist/ModuleTag-BcVF6z7B.d.ts +113 -0
  78. package/dist/ModuleTag-DuZXo_NS.d.cts +113 -0
  79. package/dist/ModuleTag.cjs +2609 -1232
  80. package/dist/ModuleTag.cjs.map +1 -1
  81. package/dist/ModuleTag.d.cts +4 -4
  82. package/dist/ModuleTag.d.ts +4 -4
  83. package/dist/ModuleTag.js +28 -25
  84. package/dist/{Observability-cY4kLn0S.d.ts → Observability-D-ZWeEVb.d.ts} +22 -15
  85. package/dist/{Observability-COqEvp2C.d.cts → Observability-V7sRMYTh.d.cts} +22 -15
  86. package/dist/Observability.cjs +1938 -640
  87. package/dist/Observability.cjs.map +1 -1
  88. package/dist/Observability.d.cts +4 -4
  89. package/dist/Observability.d.ts +4 -4
  90. package/dist/Observability.js +21 -19
  91. package/dist/{Process-mL8fHDSB.d.cts → Process-B55aJMFk.d.cts} +29 -4
  92. package/dist/{Process-CM9xbMdP.d.ts → Process-DvhFEwUS.d.ts} +29 -4
  93. package/dist/Process.cjs +1122 -85
  94. package/dist/Process.cjs.map +1 -1
  95. package/dist/Process.d.cts +4 -3
  96. package/dist/Process.d.ts +4 -3
  97. package/dist/Process.js +27 -22
  98. package/dist/{ReadQuery-BlMwhe-F.d.ts → ReadQuery-C4vZ8Prc.d.ts} +2 -2
  99. package/dist/{ReadQuery-SinbStGF.d.ts → ReadQuery-CafjlJQo.d.cts} +1 -1
  100. package/dist/{ReadQuery-SinbStGF.d.cts → ReadQuery-CafjlJQo.d.ts} +1 -1
  101. package/dist/{ReadQuery-CL5XlXts.d.cts → ReadQuery-mc0NgrFV.d.cts} +2 -2
  102. package/dist/ReadQuery.cjs +3 -3
  103. package/dist/ReadQuery.cjs.map +1 -1
  104. package/dist/ReadQuery.d.cts +2 -2
  105. package/dist/ReadQuery.d.ts +2 -2
  106. package/dist/ReadQuery.js +3 -3
  107. package/dist/{Reflection-CQnKwPXj.d.ts → Reflection-C8xZ267q.d.ts} +88 -7
  108. package/dist/{Reflection-Kabo1mlU.d.cts → Reflection-DP7Vsv3f.d.cts} +88 -7
  109. package/dist/Reflection.cjs +2934 -1553
  110. package/dist/Reflection.cjs.map +1 -1
  111. package/dist/Reflection.d.cts +14 -11
  112. package/dist/Reflection.d.ts +14 -11
  113. package/dist/Reflection.js +26 -21
  114. package/dist/Resource.cjs +670 -12
  115. package/dist/Resource.cjs.map +1 -1
  116. package/dist/Resource.js +6 -3
  117. package/dist/Root.cjs +675 -17
  118. package/dist/Root.cjs.map +1 -1
  119. package/dist/Root.js +7 -3
  120. package/dist/{Runtime-CtyzZG4i.d.ts → Runtime-BWc9YfUB.d.ts} +37 -7
  121. package/dist/{Runtime-B-aL-f29.d.cts → Runtime-PShIC4DW.d.cts} +37 -7
  122. package/dist/Runtime.cjs +1899 -809
  123. package/dist/Runtime.cjs.map +1 -1
  124. package/dist/Runtime.d.cts +14 -11
  125. package/dist/Runtime.d.ts +14 -11
  126. package/dist/Runtime.js +33 -28
  127. package/dist/ScopeRegistry.cjs +668 -10
  128. package/dist/ScopeRegistry.cjs.map +1 -1
  129. package/dist/ScopeRegistry.js +6 -3
  130. package/dist/{StateTrait-OWhbj12c.d.cts → StateTrait-CQsDlXJm.d.cts} +23 -6
  131. package/dist/{StateTrait-BGsZghTz.d.ts → StateTrait-YvJzVDKl.d.ts} +23 -6
  132. package/dist/StateTrait.cjs +1475 -370
  133. package/dist/StateTrait.cjs.map +1 -1
  134. package/dist/StateTrait.d.cts +7 -5
  135. package/dist/StateTrait.d.ts +7 -5
  136. package/dist/StateTrait.js +17 -14
  137. package/dist/{TraitLifecycle-LdIWmKlg.d.ts → TraitLifecycle-CjIBICAA.d.ts} +2 -2
  138. package/dist/{TraitLifecycle-CwV5WPFX.d.cts → TraitLifecycle-NmqGiXPC.d.cts} +2 -2
  139. package/dist/TraitLifecycle.cjs +489 -32
  140. package/dist/TraitLifecycle.cjs.map +1 -1
  141. package/dist/TraitLifecycle.d.cts +4 -4
  142. package/dist/TraitLifecycle.d.ts +4 -4
  143. package/dist/TraitLifecycle.js +7 -7
  144. package/dist/Workflow-BlFG_20_.d.cts +414 -0
  145. package/dist/Workflow-CW9S_aAP.d.ts +414 -0
  146. package/dist/Workflow.cjs +2977 -0
  147. package/dist/Workflow.cjs.map +1 -0
  148. package/dist/Workflow.d.cts +7 -0
  149. package/dist/Workflow.d.ts +7 -0
  150. package/dist/Workflow.js +55 -0
  151. package/dist/Workflow.js.map +1 -0
  152. package/dist/{chunk-G5ZBFPNU.js → chunk-2A4UKO2D.js} +2 -2
  153. package/dist/chunk-2DE6D42I.js +248 -0
  154. package/dist/chunk-2DE6D42I.js.map +1 -0
  155. package/dist/{chunk-ANLBCBDC.js → chunk-2DVLMSOE.js} +6 -6
  156. package/dist/{chunk-BE3HW4FY.js → chunk-34CF6OGE.js} +14 -16
  157. package/dist/chunk-34CF6OGE.js.map +1 -0
  158. package/dist/{chunk-ZFY7U2FR.js → chunk-3LPIXG56.js} +43 -3
  159. package/dist/chunk-3LPIXG56.js.map +1 -0
  160. package/dist/chunk-3VZYDNXZ.js +10 -0
  161. package/dist/chunk-3VZYDNXZ.js.map +1 -0
  162. package/dist/{chunk-3TMODYZV.js → chunk-3XO4HR6V.js} +2 -2
  163. package/dist/chunk-46FGVWRF.js +817 -0
  164. package/dist/chunk-46FGVWRF.js.map +1 -0
  165. package/dist/chunk-4LODUXFI.js +288 -0
  166. package/dist/chunk-4LODUXFI.js.map +1 -0
  167. package/dist/{chunk-GMPEOUP2.js → chunk-4MZ7BT3R.js} +2 -2
  168. package/dist/chunk-4MZ7BT3R.js.map +1 -0
  169. package/dist/{chunk-TKZ7MEIA.js → chunk-53GVPGSM.js} +2 -2
  170. package/dist/{chunk-KP7MUZNX.js → chunk-5W2V2NVJ.js} +2 -2
  171. package/dist/chunk-5W2V2NVJ.js.map +1 -0
  172. package/dist/chunk-6DACKW3D.js +613 -0
  173. package/dist/chunk-6DACKW3D.js.map +1 -0
  174. package/dist/chunk-AQ7L2QZ5.js +1395 -0
  175. package/dist/chunk-AQ7L2QZ5.js.map +1 -0
  176. package/dist/{chunk-NZJKFF45.js → chunk-C2UZZQ76.js} +2 -2
  177. package/dist/chunk-CCKP5Z6F.js +701 -0
  178. package/dist/chunk-CCKP5Z6F.js.map +1 -0
  179. package/dist/chunk-CUKM2XUW.js +27 -0
  180. package/dist/{chunk-QCHIQWAJ.js.map → chunk-CUKM2XUW.js.map} +1 -1
  181. package/dist/{chunk-M2RGJPXX.js → chunk-DBD6Q6JH.js} +3 -3
  182. package/dist/{chunk-ZGDVUPTM.js → chunk-EB4RGQO3.js} +2 -2
  183. package/dist/{chunk-PAYXCY6A.js → chunk-G7ESIQTI.js} +12 -14
  184. package/dist/chunk-G7ESIQTI.js.map +1 -0
  185. package/dist/chunk-GPBAZQ23.js +348 -0
  186. package/dist/chunk-GPBAZQ23.js.map +1 -0
  187. package/dist/{chunk-OFADUJWJ.js → chunk-I4LCE5OY.js} +3 -5
  188. package/dist/{chunk-OFADUJWJ.js.map → chunk-I4LCE5OY.js.map} +1 -1
  189. package/dist/{chunk-DFNM3WX2.js → chunk-IMCC6TBN.js} +158 -39
  190. package/dist/chunk-IMCC6TBN.js.map +1 -0
  191. package/dist/{chunk-76WT3HOR.js → chunk-IROZNQAF.js} +22 -21
  192. package/dist/chunk-IROZNQAF.js.map +1 -0
  193. package/dist/{chunk-TAAPQVZN.js → chunk-ISKNULNH.js} +2 -2
  194. package/dist/chunk-J3CWXIPV.js +242 -0
  195. package/dist/chunk-J3CWXIPV.js.map +1 -0
  196. package/dist/{chunk-PYOE4VSI.js → chunk-JBKYRTCS.js} +224 -161
  197. package/dist/chunk-JBKYRTCS.js.map +1 -0
  198. package/dist/{chunk-66ALHVEX.js → chunk-KKIAYH4X.js} +3 -3
  199. package/dist/{chunk-3RMKLXHX.js → chunk-KLDVG3SY.js} +2 -2
  200. package/dist/{chunk-BABLDP24.js → chunk-KSZQYSEH.js} +3 -3
  201. package/dist/chunk-KSZQYSEH.js.map +1 -0
  202. package/dist/{chunk-CW6T36TN.js → chunk-M3M7JFAH.js} +4 -4
  203. package/dist/chunk-M3M7JFAH.js.map +1 -0
  204. package/dist/{chunk-THATMZXD.js → chunk-MLB253V2.js} +2 -2
  205. package/dist/{chunk-THATMZXD.js.map → chunk-MLB253V2.js.map} +1 -1
  206. package/dist/{chunk-JGIWG6SR.js → chunk-MS77U77X.js} +664 -550
  207. package/dist/chunk-MS77U77X.js.map +1 -0
  208. package/dist/chunk-MW4FA3MW.js +23 -0
  209. package/dist/chunk-MW4FA3MW.js.map +1 -0
  210. package/dist/chunk-MYKNINNN.js +228 -0
  211. package/dist/chunk-MYKNINNN.js.map +1 -0
  212. package/dist/{chunk-4CQAV7YB.js → chunk-O6TTQXTY.js} +2 -2
  213. package/dist/{chunk-NBD3KUOZ.js → chunk-OJDJ4VDQ.js} +35 -24
  214. package/dist/chunk-OJDJ4VDQ.js.map +1 -0
  215. package/dist/{chunk-NQZ2OSGR.js → chunk-PVZEMNJY.js} +9 -9
  216. package/dist/chunk-PVZEMNJY.js.map +1 -0
  217. package/dist/chunk-RN26DV2M.js +271 -0
  218. package/dist/chunk-RN26DV2M.js.map +1 -0
  219. package/dist/{chunk-JCXGZRMU.js → chunk-RQQW3IQC.js} +3 -3
  220. package/dist/chunk-RQQW3IQC.js.map +1 -0
  221. package/dist/{chunk-24VULZ7A.js → chunk-TKOGZDD6.js} +3 -3
  222. package/dist/{chunk-EGK3KN7B.js → chunk-TQYLVXGY.js} +70 -39
  223. package/dist/chunk-TQYLVXGY.js.map +1 -0
  224. package/dist/{chunk-QMM6O4CD.js → chunk-UACD2CL2.js} +15 -3
  225. package/dist/{chunk-QMM6O4CD.js.map → chunk-UACD2CL2.js.map} +1 -1
  226. package/dist/{chunk-M3WTHJHJ.js → chunk-VH575UTV.js} +30 -34
  227. package/dist/chunk-VH575UTV.js.map +1 -0
  228. package/dist/{chunk-AUIR5O6W.js → chunk-WWBMC24F.js} +9 -15
  229. package/dist/chunk-WWBMC24F.js.map +1 -0
  230. package/dist/{chunk-JWOYLO27.js → chunk-WYJUJV4L.js} +80 -7
  231. package/dist/chunk-WYJUJV4L.js.map +1 -0
  232. package/dist/{chunk-EY4NZKDR.js → chunk-XFMMPYNU.js} +2 -2
  233. package/dist/chunk-Y4VRBIS6.js +35 -0
  234. package/dist/chunk-Y4VRBIS6.js.map +1 -0
  235. package/dist/{chunk-DMBALCE2.js → chunk-ZC7MSQ5U.js} +77 -4
  236. package/dist/chunk-ZC7MSQ5U.js.map +1 -0
  237. package/dist/{chunk-OGWBVHB3.js → chunk-ZCK6SCOE.js} +67 -8
  238. package/dist/chunk-ZCK6SCOE.js.map +1 -0
  239. package/dist/{chunk-IHVBV5C2.js → chunk-ZTFTABXV.js} +2 -1
  240. package/dist/chunk-ZTFTABXV.js.map +1 -0
  241. package/dist/index.cjs +9532 -5017
  242. package/dist/index.cjs.map +1 -1
  243. package/dist/index.d.cts +163 -27
  244. package/dist/index.d.ts +163 -27
  245. package/dist/index.js +119 -56
  246. package/dist/index.js.map +1 -1
  247. package/dist/{ir-BMP7yxJJ.d.cts → ir-C-Zm_GlZ.d.cts} +1 -1
  248. package/dist/{ir-DUOz6H-5.d.ts → ir-DGyGiwVe.d.ts} +1 -1
  249. package/dist/{module-k7m3txak.d.ts → module-DqQ1U-Me.d.ts} +129 -100
  250. package/dist/{module-B8CBqIZ_.d.cts → module-doenaCsZ.d.cts} +129 -100
  251. package/package.json +12 -1
  252. package/dist/ModuleTag-C8FHY_sY.d.ts +0 -93
  253. package/dist/ModuleTag-EGbgBMpZ.d.cts +0 -93
  254. package/dist/chunk-3QMIVH35.js +0 -43
  255. package/dist/chunk-3QMIVH35.js.map +0 -1
  256. package/dist/chunk-76WT3HOR.js.map +0 -1
  257. package/dist/chunk-AUIR5O6W.js.map +0 -1
  258. package/dist/chunk-BABLDP24.js.map +0 -1
  259. package/dist/chunk-BE3HW4FY.js.map +0 -1
  260. package/dist/chunk-CW6T36TN.js.map +0 -1
  261. package/dist/chunk-DFNM3WX2.js.map +0 -1
  262. package/dist/chunk-DMBALCE2.js.map +0 -1
  263. package/dist/chunk-EGK3KN7B.js.map +0 -1
  264. package/dist/chunk-GMPEOUP2.js.map +0 -1
  265. package/dist/chunk-IHVBV5C2.js.map +0 -1
  266. package/dist/chunk-JCXGZRMU.js.map +0 -1
  267. package/dist/chunk-JGIWG6SR.js.map +0 -1
  268. package/dist/chunk-JWOYLO27.js.map +0 -1
  269. package/dist/chunk-KIXAU3GM.js +0 -137
  270. package/dist/chunk-KIXAU3GM.js.map +0 -1
  271. package/dist/chunk-KP7MUZNX.js.map +0 -1
  272. package/dist/chunk-M3WTHJHJ.js.map +0 -1
  273. package/dist/chunk-M7IYCTJV.js +0 -79
  274. package/dist/chunk-M7IYCTJV.js.map +0 -1
  275. package/dist/chunk-NBD3KUOZ.js.map +0 -1
  276. package/dist/chunk-NQZ2OSGR.js.map +0 -1
  277. package/dist/chunk-OGWBVHB3.js.map +0 -1
  278. package/dist/chunk-PAYXCY6A.js.map +0 -1
  279. package/dist/chunk-PYOE4VSI.js.map +0 -1
  280. package/dist/chunk-QCHIQWAJ.js +0 -21
  281. package/dist/chunk-VZB726PE.js +0 -93
  282. package/dist/chunk-VZB726PE.js.map +0 -1
  283. package/dist/chunk-W3TEWHLO.js +0 -568
  284. package/dist/chunk-W3TEWHLO.js.map +0 -1
  285. package/dist/chunk-ZFLHVFUC.js +0 -192
  286. package/dist/chunk-ZFLHVFUC.js.map +0 -1
  287. package/dist/chunk-ZFY7U2FR.js.map +0 -1
  288. /package/dist/{chunk-G5ZBFPNU.js.map → chunk-2A4UKO2D.js.map} +0 -0
  289. /package/dist/{chunk-ANLBCBDC.js.map → chunk-2DVLMSOE.js.map} +0 -0
  290. /package/dist/{chunk-3TMODYZV.js.map → chunk-3XO4HR6V.js.map} +0 -0
  291. /package/dist/{chunk-TKZ7MEIA.js.map → chunk-53GVPGSM.js.map} +0 -0
  292. /package/dist/{chunk-NZJKFF45.js.map → chunk-C2UZZQ76.js.map} +0 -0
  293. /package/dist/{chunk-M2RGJPXX.js.map → chunk-DBD6Q6JH.js.map} +0 -0
  294. /package/dist/{chunk-ZGDVUPTM.js.map → chunk-EB4RGQO3.js.map} +0 -0
  295. /package/dist/{chunk-TAAPQVZN.js.map → chunk-ISKNULNH.js.map} +0 -0
  296. /package/dist/{chunk-66ALHVEX.js.map → chunk-KKIAYH4X.js.map} +0 -0
  297. /package/dist/{chunk-3RMKLXHX.js.map → chunk-KLDVG3SY.js.map} +0 -0
  298. /package/dist/{chunk-4CQAV7YB.js.map → chunk-O6TTQXTY.js.map} +0 -0
  299. /package/dist/{chunk-24VULZ7A.js.map → chunk-TKOGZDD6.js.map} +0 -0
  300. /package/dist/{chunk-EY4NZKDR.js.map → chunk-XFMMPYNU.js.map} +0 -0
@@ -0,0 +1,817 @@
1
+ import {
2
+ compileWorkflowRuntimeStepsV1,
3
+ evalInputExpr,
4
+ makeWorkflowError
5
+ } from "./chunk-CCKP5Z6F.js";
6
+ import {
7
+ attachLogicUnitMeta,
8
+ currentTxnOriginOverride
9
+ } from "./chunk-Y4VRBIS6.js";
10
+ import {
11
+ RootContextTag
12
+ } from "./chunk-3VZYDNXZ.js";
13
+ import {
14
+ getRuntimeInternals
15
+ } from "./chunk-KLDVG3SY.js";
16
+ import {
17
+ HostSchedulerTag,
18
+ TickSchedulerTag,
19
+ forceSourceRefresh,
20
+ inSyncTransactionFiber
21
+ } from "./chunk-AQ7L2QZ5.js";
22
+ import {
23
+ makeInRunSession,
24
+ run
25
+ } from "./chunk-I4LCE5OY.js";
26
+ import {
27
+ currentDiagnosticsLevel,
28
+ record,
29
+ toSerializableErrorSummary
30
+ } from "./chunk-ZC7MSQ5U.js";
31
+ import {
32
+ EffectOpMiddlewareTag
33
+ } from "./chunk-WYJUJV4L.js";
34
+
35
+ // src/internal/runtime/core/WorkflowRuntime.ts
36
+ import { Cause, Context, Deferred, Effect, Exit, Fiber, FiberRef, Option, Stream } from "effect";
37
+ var WORKFLOW_REGISTRY = /* @__PURE__ */ Symbol.for("@logixjs/core/workflowRegistry");
38
+ var isRecord = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
39
+ var isObjectLike = (value) => typeof value === "object" && value !== null || typeof value === "function";
40
+ var getRegistry = (runtime) => runtime[WORKFLOW_REGISTRY];
41
+ var resolveActionTag = (action) => {
42
+ const tag = isObjectLike(action) ? action._tag : void 0;
43
+ if (typeof tag === "string" && tag.length > 0) return tag;
44
+ const type = isObjectLike(action) ? action.type : void 0;
45
+ if (typeof type === "string" && type.length > 0) return type;
46
+ if (tag != null) return String(tag);
47
+ if (type != null) return String(type);
48
+ return void 0;
49
+ };
50
+ var asNonEmptyString = (value) => typeof value === "string" && value.trim().length > 0 ? value.trim() : void 0;
51
+ var KERNEL_PORT_SOURCE_REFRESH = "logix/kernel/sourceRefresh";
52
+ var resolveServicePort = (runtime, env, serviceId, programId, stepKey) => {
53
+ if (serviceId === KERNEL_PORT_SOURCE_REFRESH) {
54
+ return (input) => Effect.gen(function* () {
55
+ const fieldPath = asNonEmptyString(isRecord(input) ? input.fieldPath : void 0);
56
+ if (!fieldPath) {
57
+ throw makeWorkflowError({
58
+ code: "WORKFLOW_INVALID_STEP",
59
+ message: "KernelPort sourceRefresh requires input.fieldPath (non-empty string).",
60
+ programId,
61
+ source: { stepKey },
62
+ detail: { serviceId, input }
63
+ });
64
+ }
65
+ const internals = getRuntimeInternals(runtime);
66
+ const handler = internals.traits.getSourceRefreshHandler(fieldPath);
67
+ if (!handler) {
68
+ return;
69
+ }
70
+ const force = isRecord(input) && input.force === true;
71
+ const runHandler = (state) => force ? Effect.locally(forceSourceRefresh, true)(handler(state)) : handler(state);
72
+ const inTxn = yield* FiberRef.get(inSyncTransactionFiber);
73
+ if (inTxn) {
74
+ const state = yield* runtime.getState;
75
+ yield* runHandler(state);
76
+ return;
77
+ }
78
+ yield* internals.txn.runWithStateTransaction(
79
+ {
80
+ kind: "source-refresh",
81
+ name: fieldPath
82
+ },
83
+ () => Effect.gen(function* () {
84
+ const state = yield* runtime.getState;
85
+ yield* runHandler(state);
86
+ })
87
+ );
88
+ });
89
+ }
90
+ const tag = Context.GenericTag(serviceId);
91
+ const opt = Context.getOption(env, tag);
92
+ if (Option.isNone(opt)) {
93
+ throw makeWorkflowError({
94
+ code: "WORKFLOW_MISSING_SERVICE",
95
+ message: `Missing service for serviceId="${serviceId}".`,
96
+ programId,
97
+ source: { stepKey },
98
+ detail: { serviceId }
99
+ });
100
+ }
101
+ const value = opt.value;
102
+ if (typeof value === "function") {
103
+ const fn = value;
104
+ return (input) => fn(input);
105
+ }
106
+ const callFn = isObjectLike(value) ? value.call : void 0;
107
+ if (typeof callFn === "function") {
108
+ const call = callFn;
109
+ return (input) => call.call(value, input);
110
+ }
111
+ throw makeWorkflowError({
112
+ code: "WORKFLOW_INVALID_SERVICE_PORT",
113
+ message: `Invalid service port for serviceId="${serviceId}" (expected a function or { call(input): Effect }).`,
114
+ programId,
115
+ source: { stepKey },
116
+ detail: { serviceId, portType: typeof value }
117
+ });
118
+ };
119
+ var compileSteps = (steps, resolvePort) => {
120
+ const visit = (step) => {
121
+ switch (step.kind) {
122
+ case "dispatch":
123
+ return {
124
+ kind: "dispatch",
125
+ key: step.key,
126
+ actionTag: step.actionTag,
127
+ ...step.payload ? { payload: step.payload } : null
128
+ };
129
+ case "delay":
130
+ return { kind: "delay", key: step.key, ms: step.ms };
131
+ case "call":
132
+ return {
133
+ kind: "call",
134
+ key: step.key,
135
+ serviceId: step.serviceId,
136
+ port: resolvePort(step.serviceId, step.key),
137
+ ...step.input ? { input: step.input } : null,
138
+ ...step.timeoutMs !== void 0 ? { timeoutMs: step.timeoutMs } : null,
139
+ ...step.retryTimes !== void 0 ? { retryTimes: step.retryTimes } : null,
140
+ onSuccess: step.onSuccess.map(visit),
141
+ onFailure: step.onFailure.map(visit)
142
+ };
143
+ }
144
+ };
145
+ return steps.map(visit);
146
+ };
147
+ var resolveConcurrency = (def) => def.policy?.concurrency ?? "parallel";
148
+ var resolvePriority = (def) => def.policy?.priority ?? "urgent";
149
+ var makeRunId = (instanceId, programId, runSeq) => `${instanceId}::wf:${programId}::r${runSeq}`;
150
+ var runBoundary = (args) => Effect.gen(function* () {
151
+ const op = yield* makeInRunSession({
152
+ kind: args.kind,
153
+ name: args.name,
154
+ effect: args.effect,
155
+ payload: args.payload,
156
+ meta: args.meta
157
+ });
158
+ const stack = args.middleware?.stack ?? [];
159
+ return yield* run(op, stack);
160
+ });
161
+ var makeTimer = (args) => Effect.async((resume) => {
162
+ let fired = false;
163
+ const cancel = args.host.scheduleTimeout(args.ms, () => {
164
+ fired = true;
165
+ args.host.scheduleMicrotask(() => resume(Effect.void));
166
+ });
167
+ return Effect.sync(() => {
168
+ cancel();
169
+ }).pipe(Effect.zipRight(fired ? Effect.void : args.onCancel));
170
+ });
171
+ var ensureLimiterReady = (registry, runtime) => Effect.gen(function* () {
172
+ if (registry.parallelLimiter !== void 0) return;
173
+ const internals = getRuntimeInternals(runtime);
174
+ const policy = yield* internals.concurrency.resolveConcurrencyPolicy();
175
+ const limit = policy.concurrencyLimit;
176
+ if (limit === "unbounded") {
177
+ registry.parallelLimiter = null;
178
+ return;
179
+ }
180
+ const n = typeof limit === "number" && Number.isFinite(limit) && limit >= 1 ? Math.floor(limit) : 16;
181
+ registry.parallelLimiter = yield* Effect.makeSemaphore(n);
182
+ });
183
+ var withRootEnvIfAvailable = (eff) => Effect.gen(function* () {
184
+ const rootOpt = yield* Effect.serviceOption(RootContextTag);
185
+ if (Option.isNone(rootOpt)) {
186
+ return yield* eff;
187
+ }
188
+ const root = rootOpt.value;
189
+ const rootEnv = root.context ?? (yield* Deferred.await(root.ready));
190
+ const currentEnv = yield* Effect.context();
191
+ const mergedEnv = Context.merge(rootEnv, currentEnv);
192
+ return yield* Effect.provide(eff, mergedEnv);
193
+ });
194
+ var ensurePortsResolved = (registry, runtime) => Effect.gen(function* () {
195
+ const done = yield* Deferred.isDone(registry.portsReady);
196
+ if (done) {
197
+ yield* Deferred.await(registry.portsReady);
198
+ return;
199
+ }
200
+ if (registry.portsResolving) {
201
+ yield* Deferred.await(registry.portsReady);
202
+ return;
203
+ }
204
+ registry.portsResolving = true;
205
+ const env = yield* Effect.context();
206
+ yield* Effect.sync(() => {
207
+ const portCache = /* @__PURE__ */ new Map();
208
+ for (const entry of registry.entries) {
209
+ const program = entry.program;
210
+ if (program.steps) continue;
211
+ const resolvePort = (serviceId, stepKey) => {
212
+ const cached = portCache.get(serviceId);
213
+ if (cached) return cached;
214
+ const resolved = resolveServicePort(runtime, env, serviceId, program.programId, stepKey);
215
+ portCache.set(serviceId, resolved);
216
+ return resolved;
217
+ };
218
+ program.steps = compileSteps(program.compiledSteps, resolvePort);
219
+ }
220
+ }).pipe(
221
+ Effect.tap(() => Deferred.succeed(registry.portsReady, void 0)),
222
+ Effect.catchAllCause((cause) => Deferred.failCause(registry.portsReady, cause).pipe(Effect.zipRight(Effect.failCause(cause)))),
223
+ Effect.ensuring(
224
+ Effect.sync(() => {
225
+ registry.portsResolving = false;
226
+ })
227
+ )
228
+ );
229
+ });
230
+ var shouldObserveForRun = (diagnostics, runSeq) => {
231
+ if (diagnostics === "off") return false;
232
+ if (diagnostics === "sampled") {
233
+ return (runSeq & 15) === 0;
234
+ }
235
+ return true;
236
+ };
237
+ var startProgramRun = (args) => Effect.gen(function* () {
238
+ const { entry, runtime, registry } = args;
239
+ const { program, state } = entry;
240
+ const diagnostics = yield* FiberRef.get(currentDiagnosticsLevel);
241
+ const beginRun = () => {
242
+ if (state.mode === "latest") {
243
+ state.runSeq += 1;
244
+ const runSeq3 = state.runSeq;
245
+ const runId3 = makeRunId(runtime.instanceId, program.programId, runSeq3);
246
+ return {
247
+ runSeq: runSeq3,
248
+ runId: runId3,
249
+ canWriteBack: () => state.runSeq === runSeq3
250
+ };
251
+ }
252
+ state.runSeq += 1;
253
+ const runSeq2 = state.runSeq;
254
+ const runId2 = makeRunId(runtime.instanceId, program.programId, runSeq2);
255
+ return {
256
+ runSeq: runSeq2,
257
+ runId: runId2,
258
+ canWriteBack: () => true
259
+ };
260
+ };
261
+ if (state.mode === "exhaust") {
262
+ if (state.busy) {
263
+ if (diagnostics !== "off") {
264
+ const observe2 = shouldObserveForRun(diagnostics, state.runSeq);
265
+ const tickSeq = observe2 ? (yield* TickSchedulerTag).getTickSeq() : void 0;
266
+ yield* runBoundary({
267
+ kind: "flow",
268
+ name: "workflow.drop",
269
+ payload: { programId: program.programId, trigger: args.trigger },
270
+ meta: {
271
+ moduleId: runtime.moduleId,
272
+ instanceId: runtime.instanceId,
273
+ programId: program.programId,
274
+ ...tickSeq !== void 0 ? { tickSeq } : null,
275
+ policy: { disableObservers: !observe2 },
276
+ reason: "exhaust"
277
+ },
278
+ effect: Effect.void,
279
+ middleware: args.middleware
280
+ });
281
+ }
282
+ return;
283
+ }
284
+ state.busy = true;
285
+ }
286
+ const { runSeq, runId, canWriteBack } = beginRun();
287
+ if (state.mode === "latest") {
288
+ const prev = state.current;
289
+ const prevRunId = state.currentRunId;
290
+ if (prev) {
291
+ yield* Fiber.interruptFork(prev);
292
+ if (diagnostics !== "off") {
293
+ const observe2 = shouldObserveForRun(diagnostics, runSeq);
294
+ const tickSeq = observe2 ? (yield* TickSchedulerTag).getTickSeq() : void 0;
295
+ yield* runBoundary({
296
+ kind: "flow",
297
+ name: "workflow.cancel",
298
+ payload: { programId: program.programId, cancelled: prevRunId, by: runId },
299
+ meta: {
300
+ moduleId: runtime.moduleId,
301
+ instanceId: runtime.instanceId,
302
+ programId: program.programId,
303
+ ...tickSeq !== void 0 ? { tickSeq } : null,
304
+ policy: { disableObservers: !observe2 },
305
+ reason: "latest",
306
+ cancelledByRunId: runId,
307
+ cancelledRunId: prevRunId
308
+ },
309
+ effect: Effect.void,
310
+ middleware: args.middleware
311
+ });
312
+ }
313
+ }
314
+ state.currentRunId = runId;
315
+ }
316
+ const observe = shouldObserveForRun(diagnostics, runSeq);
317
+ const policy = { disableObservers: !observe };
318
+ const programEffect = Effect.gen(function* () {
319
+ const host = yield* HostSchedulerTag;
320
+ const tick = yield* TickSchedulerTag;
321
+ if (!program.steps) {
322
+ const env = yield* Effect.context();
323
+ const portCache = /* @__PURE__ */ new Map();
324
+ const resolvePort = (serviceId, stepKey) => {
325
+ const cached = portCache.get(serviceId);
326
+ if (cached) return cached;
327
+ const resolved = resolveServicePort(runtime, env, serviceId, program.programId, stepKey);
328
+ portCache.set(serviceId, resolved);
329
+ return resolved;
330
+ };
331
+ program.steps = compileSteps(program.compiledSteps, resolvePort);
332
+ }
333
+ const getTickSeq = () => observe ? tick.getTickSeq() : void 0;
334
+ const emitTimerEvents = observe && diagnostics === "full";
335
+ const evalPayload = (expr) => expr ? evalInputExpr(expr, args.payload) : void 0;
336
+ const defaultInputForCall = () => args.trigger.kind === "action" ? args.payload : void 0;
337
+ let timerTriggered = false;
338
+ const runSteps = (steps) => Effect.gen(function* () {
339
+ for (const step of steps) {
340
+ if (!canWriteBack()) return;
341
+ if (step.kind === "dispatch") {
342
+ const payload = evalPayload(step.payload);
343
+ const action = { _tag: step.actionTag, payload };
344
+ const tickSeq = getTickSeq();
345
+ const dispatchEffectBase = program.priority === "nonUrgent" ? runtime.dispatchLowPriority(action) : runtime.dispatch(action);
346
+ const dispatchEffect = timerTriggered ? Effect.locally(
347
+ currentTxnOriginOverride,
348
+ {
349
+ kind: "workflow.timer",
350
+ name: `timer:${program.programId}:${step.key}`
351
+ }
352
+ )(dispatchEffectBase) : dispatchEffectBase;
353
+ yield* runBoundary({
354
+ kind: "flow",
355
+ name: "workflow.dispatch",
356
+ payload: { actionTag: step.actionTag },
357
+ meta: {
358
+ moduleId: runtime.moduleId,
359
+ instanceId: runtime.instanceId,
360
+ programId: program.programId,
361
+ runId,
362
+ stepKey: step.key,
363
+ ...tickSeq !== void 0 ? { tickSeq } : null,
364
+ policy
365
+ },
366
+ effect: dispatchEffect,
367
+ middleware: args.middleware
368
+ }).pipe(Effect.asVoid);
369
+ continue;
370
+ }
371
+ if (step.kind === "delay") {
372
+ const timerId = emitTimerEvents ? `${runId}::timer:${step.key}` : void 0;
373
+ const recordTimerEvent = (name, patchMeta) => Effect.gen(function* () {
374
+ const tickSeq2 = getTickSeq();
375
+ yield* runBoundary({
376
+ kind: "flow",
377
+ name,
378
+ payload: { ms: step.ms },
379
+ meta: {
380
+ moduleId: runtime.moduleId,
381
+ instanceId: runtime.instanceId,
382
+ programId: program.programId,
383
+ runId,
384
+ stepKey: step.key,
385
+ ...timerId ? { timerId } : null,
386
+ ...tickSeq2 !== void 0 ? { tickSeq: tickSeq2 } : null,
387
+ policy,
388
+ ...patchMeta ?? null
389
+ },
390
+ effect: Effect.void,
391
+ middleware: args.middleware
392
+ });
393
+ });
394
+ const schedule = emitTimerEvents ? recordTimerEvent("workflow.timer.schedule") : Effect.void;
395
+ const onCancel = emitTimerEvents ? recordTimerEvent("workflow.timer.cancel", { reason: "interrupt" }) : Effect.void;
396
+ const fired = emitTimerEvents ? recordTimerEvent("workflow.timer.fired") : Effect.void;
397
+ const delayEffect = schedule.pipe(
398
+ Effect.zipRight(makeTimer({ host, ms: step.ms, onCancel })),
399
+ Effect.zipRight(fired)
400
+ );
401
+ const tickSeq = getTickSeq();
402
+ yield* runBoundary({
403
+ kind: "flow",
404
+ name: "workflow.delay",
405
+ payload: { ms: step.ms },
406
+ meta: {
407
+ moduleId: runtime.moduleId,
408
+ instanceId: runtime.instanceId,
409
+ programId: program.programId,
410
+ runId,
411
+ stepKey: step.key,
412
+ ...tickSeq !== void 0 ? { tickSeq } : null,
413
+ ...timerId ? { timerId } : null,
414
+ policy
415
+ },
416
+ effect: delayEffect,
417
+ middleware: args.middleware
418
+ }).pipe(Effect.asVoid);
419
+ timerTriggered = true;
420
+ continue;
421
+ }
422
+ const input = step.input ? evalInputExpr(step.input, args.payload) : defaultInputForCall();
423
+ const maxRetries = step.retryTimes ?? 0;
424
+ let exit;
425
+ for (let attempt = 1; attempt <= maxRetries + 1; attempt += 1) {
426
+ const tickSeq = getTickSeq();
427
+ const base = runBoundary({
428
+ kind: "service",
429
+ name: `workflow.call:${step.serviceId}`,
430
+ payload: { serviceId: step.serviceId },
431
+ meta: {
432
+ moduleId: runtime.moduleId,
433
+ instanceId: runtime.instanceId,
434
+ programId: program.programId,
435
+ runId,
436
+ stepKey: step.key,
437
+ serviceId: step.serviceId,
438
+ attempt,
439
+ ...tickSeq !== void 0 ? { tickSeq } : null,
440
+ policy
441
+ },
442
+ effect: step.port(input),
443
+ middleware: args.middleware
444
+ });
445
+ const withTimeout = step.timeoutMs === void 0 ? base : Effect.gen(function* () {
446
+ const timeoutMs = step.timeoutMs;
447
+ if (timeoutMs === void 0) {
448
+ return yield* base;
449
+ }
450
+ const timerId = emitTimerEvents ? `${runId}::timeout:${step.key}:a${attempt}` : void 0;
451
+ const recordTimeoutEvent = (name, patchMeta) => Effect.gen(function* () {
452
+ const tickSeq2 = getTickSeq();
453
+ yield* runBoundary({
454
+ kind: "flow",
455
+ name,
456
+ payload: { ms: timeoutMs },
457
+ meta: {
458
+ moduleId: runtime.moduleId,
459
+ instanceId: runtime.instanceId,
460
+ programId: program.programId,
461
+ runId,
462
+ stepKey: step.key,
463
+ attempt,
464
+ ...timerId ? { timerId } : null,
465
+ ...tickSeq2 !== void 0 ? { tickSeq: tickSeq2 } : null,
466
+ policy,
467
+ ...patchMeta ?? null
468
+ },
469
+ effect: Effect.void,
470
+ middleware: args.middleware
471
+ });
472
+ });
473
+ const schedule = emitTimerEvents ? recordTimeoutEvent("workflow.timeout.schedule") : Effect.void;
474
+ const onCancel = emitTimerEvents ? recordTimeoutEvent("workflow.timeout.cancel", { reason: "interrupt" }) : Effect.void;
475
+ const fired = emitTimerEvents ? recordTimeoutEvent("workflow.timeout.fired") : Effect.void;
476
+ const timeoutError = makeWorkflowError({
477
+ code: "WORKFLOW_CALL_TIMEOUT",
478
+ message: `Workflow call timed out (serviceId="${step.serviceId}", timeoutMs=${timeoutMs}).`,
479
+ programId: program.programId,
480
+ source: { stepKey: step.key },
481
+ detail: { serviceId: step.serviceId, timeoutMs, attempt }
482
+ });
483
+ const timeoutFail = schedule.pipe(
484
+ Effect.zipRight(makeTimer({ host, ms: timeoutMs, onCancel })),
485
+ Effect.zipRight(fired),
486
+ Effect.zipRight(Effect.fail(timeoutError))
487
+ );
488
+ return yield* Effect.raceFirst(base, timeoutFail);
489
+ });
490
+ const attemptExit = yield* Effect.exit(withTimeout);
491
+ exit = attemptExit;
492
+ if (!canWriteBack() || Exit.isSuccess(attemptExit)) {
493
+ break;
494
+ }
495
+ if (Cause.isInterrupted(attemptExit.cause) || Option.isNone(Cause.failureOption(attemptExit.cause))) {
496
+ break;
497
+ }
498
+ if (attempt < maxRetries + 1) {
499
+ continue;
500
+ }
501
+ break;
502
+ }
503
+ if (!exit) {
504
+ exit = Exit.succeed(void 0);
505
+ }
506
+ if (!canWriteBack()) return;
507
+ if (Exit.isSuccess(exit)) {
508
+ yield* runSteps(step.onSuccess);
509
+ } else {
510
+ const failure = Option.getOrUndefined(Cause.failureOption(exit.cause));
511
+ const isTimeout = isObjectLike(failure) && failure._tag === "WorkflowError" && failure.code === "WORKFLOW_CALL_TIMEOUT";
512
+ if (isTimeout) timerTriggered = true;
513
+ yield* runSteps(step.onFailure);
514
+ }
515
+ }
516
+ });
517
+ const runTickSeq = getTickSeq();
518
+ yield* runBoundary({
519
+ kind: "flow",
520
+ name: "workflow.run",
521
+ payload: { trigger: args.trigger },
522
+ meta: {
523
+ moduleId: runtime.moduleId,
524
+ instanceId: runtime.instanceId,
525
+ programId: program.programId,
526
+ runId,
527
+ ...runTickSeq !== void 0 ? { tickSeq: runTickSeq } : null,
528
+ policy
529
+ },
530
+ effect: runSteps(program.steps),
531
+ middleware: args.middleware
532
+ }).pipe(Effect.asVoid);
533
+ });
534
+ const limited = registry.parallelLimiter ? registry.parallelLimiter.withPermits(1)(programEffect) : programEffect;
535
+ const fiber = yield* Effect.forkScoped(
536
+ limited.pipe(
537
+ Effect.catchAllCause((cause) => {
538
+ const { errorSummary, downgrade } = toSerializableErrorSummary(cause);
539
+ const downgradeHint = downgrade ? ` (downgrade=${downgrade})` : "";
540
+ return record({
541
+ type: "diagnostic",
542
+ moduleId: runtime.moduleId,
543
+ instanceId: runtime.instanceId,
544
+ code: "workflow::run_crashed",
545
+ severity: "error",
546
+ message: `Workflow run crashed for programId="${program.programId}" runId="${runId}".${downgradeHint}`,
547
+ hint: `${errorSummary.name ? `${errorSummary.name}: ` : ""}${errorSummary.message}`,
548
+ actionTag: args.trigger.kind === "action" ? args.trigger.actionTag : void 0,
549
+ kind: "workflow_run_crashed",
550
+ trigger: {
551
+ kind: "workflow",
552
+ name: "run",
553
+ details: {
554
+ programId: program.programId,
555
+ runId,
556
+ trigger: args.trigger
557
+ }
558
+ }
559
+ }).pipe(Effect.catchAllCause(() => Effect.void));
560
+ }),
561
+ Effect.ensuring(
562
+ Effect.sync(() => {
563
+ if (state.mode === "exhaust") {
564
+ state.busy = false;
565
+ }
566
+ })
567
+ )
568
+ )
569
+ );
570
+ if (state.mode === "latest") {
571
+ state.current = fiber;
572
+ }
573
+ });
574
+ var ensureRegistry = (runtime) => Effect.gen(function* () {
575
+ const existing = getRegistry(runtime);
576
+ if (existing) {
577
+ return {
578
+ moduleId: runtime.moduleId,
579
+ instanceId: runtime.instanceId,
580
+ registry: existing
581
+ };
582
+ }
583
+ const portsReady = yield* Deferred.make();
584
+ const next = {
585
+ byActionTag: /* @__PURE__ */ new Map(),
586
+ entries: [],
587
+ watcherStarted: false,
588
+ watcherStartCount: 0,
589
+ portsResolving: false,
590
+ portsReady,
591
+ parallelLimiter: void 0
592
+ };
593
+ Object.defineProperty(runtime, WORKFLOW_REGISTRY, {
594
+ value: next,
595
+ enumerable: false,
596
+ configurable: true,
597
+ writable: false
598
+ });
599
+ return { moduleId: runtime.moduleId, instanceId: runtime.instanceId, registry: next };
600
+ });
601
+ var registerPrograms = (args) => Effect.gen(function* () {
602
+ const runtime = yield* args.moduleTag;
603
+ const { moduleId, instanceId, registry } = yield* ensureRegistry(runtime);
604
+ if (registry.parallelLimiter === void 0) {
605
+ yield* ensureLimiterReady(registry, runtime);
606
+ }
607
+ const validateNoIoStepsForOnInit = (steps, programId) => {
608
+ const visit = (step) => {
609
+ if (step.kind === "call" || step.kind === "delay") {
610
+ throw makeWorkflowError({
611
+ code: "WORKFLOW_INVALID_TRIGGER",
612
+ message: "Lifecycle onInit programs must not include call/delay (initRequired must stay sync-only; use onStart for IO/time).",
613
+ programId,
614
+ source: { stepKey: step.key },
615
+ detail: { kind: step.kind }
616
+ });
617
+ }
618
+ };
619
+ for (const s of steps) visit(s);
620
+ };
621
+ const programHasCall = (steps) => steps.some((s) => s.kind === "call");
622
+ const insertEntry = (actionTag, entry) => {
623
+ const prev = registry.byActionTag.get(actionTag);
624
+ registry.byActionTag.set(actionTag, prev ? [...prev, entry] : [entry]);
625
+ };
626
+ const internals = getRuntimeInternals(runtime);
627
+ for (const program of args.programs) {
628
+ const def = program.def;
629
+ const localId = asNonEmptyString(def.localId);
630
+ if (!localId) {
631
+ throw makeWorkflowError({
632
+ code: "WORKFLOW_INVALID_DEF",
633
+ message: "Workflow.install: def.localId must be a non-empty string.",
634
+ detail: { localId: def.localId }
635
+ });
636
+ }
637
+ const programId = `${moduleId}.${localId}`;
638
+ const compiled = compileWorkflowRuntimeStepsV1({ def });
639
+ if (def.trigger.kind === "lifecycle" && def.trigger.phase === "onInit") {
640
+ validateNoIoStepsForOnInit(compiled, programId);
641
+ }
642
+ const compiledProgram = {
643
+ programId,
644
+ localId,
645
+ trigger: def.trigger,
646
+ concurrency: resolveConcurrency(def),
647
+ priority: resolvePriority(def),
648
+ compiledSteps: compiled
649
+ };
650
+ if (!programHasCall(compiled)) {
651
+ compiledProgram.steps = compileSteps(compiled, () => {
652
+ throw makeWorkflowError({
653
+ code: "WORKFLOW_MISSING_SERVICE",
654
+ message: "Internal error: unexpected call step while resolving call-less program.",
655
+ programId,
656
+ detail: { programId }
657
+ });
658
+ });
659
+ }
660
+ const state = compiledProgram.concurrency === "latest" ? { mode: "latest", runSeq: 0, current: void 0, currentRunId: void 0 } : compiledProgram.concurrency === "exhaust" ? { mode: "exhaust", runSeq: 0, busy: false } : { mode: "parallel", runSeq: 0 };
661
+ const entry = { program: compiledProgram, state };
662
+ registry.entries.push(entry);
663
+ if (def.trigger.kind === "action") {
664
+ insertEntry(def.trigger.actionTag, entry);
665
+ } else {
666
+ if (def.trigger.phase === "onStart") {
667
+ internals.lifecycle.registerStart(
668
+ withRootEnvIfAvailable(
669
+ Effect.gen(function* () {
670
+ const middlewareOpt = yield* Effect.serviceOption(EffectOpMiddlewareTag);
671
+ const middleware = Option.isSome(middlewareOpt) ? middlewareOpt.value : void 0;
672
+ yield* ensurePortsResolved(registry, runtime).pipe(Effect.orDie);
673
+ yield* startProgramRun({
674
+ entry,
675
+ runtime,
676
+ registry,
677
+ trigger: { kind: "lifecycle", phase: "onStart" },
678
+ payload: void 0,
679
+ middleware
680
+ });
681
+ })
682
+ ),
683
+ { name: `workflow:${localId}` }
684
+ );
685
+ } else {
686
+ internals.lifecycle.registerInitRequired(
687
+ Effect.gen(function* () {
688
+ const middlewareOpt = yield* Effect.serviceOption(EffectOpMiddlewareTag);
689
+ const middleware = Option.isSome(middlewareOpt) ? middlewareOpt.value : void 0;
690
+ yield* startProgramRun({
691
+ entry,
692
+ runtime,
693
+ registry,
694
+ trigger: { kind: "lifecycle", phase: "onInit" },
695
+ payload: void 0,
696
+ middleware
697
+ });
698
+ }),
699
+ { name: `workflow:${localId}` }
700
+ );
701
+ }
702
+ }
703
+ }
704
+ void instanceId;
705
+ });
706
+ var startWatcherIfNeeded = (args) => Effect.gen(function* () {
707
+ const runtime = yield* args.moduleTag;
708
+ const init = yield* ensureRegistry(runtime);
709
+ const registry = init.registry;
710
+ if (registry.watcherStarted) {
711
+ return;
712
+ }
713
+ registry.watcherStarted = true;
714
+ registry.watcherStartCount += 1;
715
+ const middlewareOpt = yield* Effect.serviceOption(EffectOpMiddlewareTag);
716
+ const middleware = Option.isSome(middlewareOpt) ? middlewareOpt.value : void 0;
717
+ const actions$ = runtime.actions$;
718
+ const portsExit = yield* Effect.exit(ensurePortsResolved(registry, runtime));
719
+ if (Exit.isFailure(portsExit)) {
720
+ const { errorSummary, downgrade } = toSerializableErrorSummary(portsExit.cause);
721
+ const downgradeHint = downgrade ? ` (downgrade=${downgrade})` : "";
722
+ yield* record({
723
+ type: "diagnostic",
724
+ moduleId: runtime.moduleId,
725
+ instanceId: runtime.instanceId,
726
+ code: "workflow::ports_resolution_failed",
727
+ severity: "error",
728
+ message: `Workflow ports resolution failed before starting watcher.${downgradeHint}`,
729
+ hint: `${errorSummary.name ? `${errorSummary.name}: ` : ""}${errorSummary.message}`,
730
+ kind: "workflow_ports_resolution_failed",
731
+ trigger: {
732
+ kind: "workflow",
733
+ name: "portsResolution",
734
+ details: {
735
+ entryLabel: args.entryLabel
736
+ }
737
+ }
738
+ });
739
+ return;
740
+ }
741
+ yield* Stream.runForEach(
742
+ actions$,
743
+ (action) => Effect.gen(function* () {
744
+ const actionTag = resolveActionTag(action);
745
+ if (!actionTag) return;
746
+ const entries = registry.byActionTag.get(actionTag);
747
+ if (!entries || entries.length === 0) return;
748
+ const payload = isRecord(action) ? action.payload : void 0;
749
+ yield* Effect.forEach(
750
+ entries,
751
+ (entry) => startProgramRun({
752
+ entry,
753
+ runtime,
754
+ registry,
755
+ trigger: { kind: "action", actionTag },
756
+ payload,
757
+ middleware
758
+ }),
759
+ { discard: true }
760
+ );
761
+ })
762
+ ).pipe(
763
+ Effect.catchAllCause((cause) => {
764
+ const { errorSummary, downgrade } = toSerializableErrorSummary(cause);
765
+ const downgradeHint = downgrade ? ` (downgrade=${downgrade})` : "";
766
+ return record({
767
+ type: "diagnostic",
768
+ moduleId: runtime.moduleId,
769
+ instanceId: runtime.instanceId,
770
+ code: "workflow::watcher_crashed",
771
+ severity: "error",
772
+ message: `Workflow watcher crashed.${downgradeHint}`,
773
+ hint: `${errorSummary.name ? `${errorSummary.name}: ` : ""}${errorSummary.message}`,
774
+ kind: "workflow_watcher_crashed",
775
+ trigger: {
776
+ kind: "workflow",
777
+ name: "watcher",
778
+ details: {
779
+ entryLabel: args.entryLabel
780
+ }
781
+ }
782
+ });
783
+ })
784
+ );
785
+ void args.entryLabel;
786
+ });
787
+ var mountAll = (args) => {
788
+ const plan = {
789
+ setup: registerPrograms({ moduleTag: args.moduleTag, programs: args.programs, entryLabel: "mountAll" }),
790
+ run: startWatcherIfNeeded({ moduleTag: args.moduleTag, entryLabel: "mountAll" })
791
+ };
792
+ attachLogicUnitMeta(plan, {
793
+ id: "__logix_internal:workflows",
794
+ kind: "internal",
795
+ name: "workflows"
796
+ });
797
+ return plan;
798
+ };
799
+ var installOne = (args) => {
800
+ const localId = asNonEmptyString(args.program.def.localId) ?? "unknown";
801
+ const plan = {
802
+ setup: registerPrograms({ moduleTag: args.moduleTag, programs: [args.program], entryLabel: `install:${localId}` }),
803
+ run: startWatcherIfNeeded({ moduleTag: args.moduleTag, entryLabel: `install:${localId}` })
804
+ };
805
+ attachLogicUnitMeta(plan, {
806
+ id: `workflow:${localId}`,
807
+ kind: "workflow",
808
+ name: localId
809
+ });
810
+ return plan;
811
+ };
812
+
813
+ export {
814
+ mountAll,
815
+ installOne
816
+ };
817
+ //# sourceMappingURL=chunk-46FGVWRF.js.map