@pattern-stack/codegen 0.15.1 → 0.15.3

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 (527) hide show
  1. package/CHANGELOG.md +85 -0
  2. package/dist/chunk-27ETSJ2X.js +84 -0
  3. package/dist/chunk-27ETSJ2X.js.map +1 -0
  4. package/dist/chunk-2E224ZSN.js +20 -0
  5. package/dist/chunk-2E224ZSN.js.map +1 -0
  6. package/dist/chunk-2FTZLDBP.js +179 -0
  7. package/dist/chunk-2FTZLDBP.js.map +1 -0
  8. package/dist/chunk-2N4UG4VD.js +20 -0
  9. package/dist/chunk-2N4UG4VD.js.map +1 -0
  10. package/dist/chunk-2TVVBC53.js +92 -0
  11. package/dist/chunk-2TVVBC53.js.map +1 -0
  12. package/dist/chunk-2VHZ7EKC.js +37 -0
  13. package/dist/chunk-2VHZ7EKC.js.map +1 -0
  14. package/dist/chunk-32BMMV4H.js +109 -0
  15. package/dist/chunk-32BMMV4H.js.map +1 -0
  16. package/dist/chunk-32DOFN3T.js +4042 -0
  17. package/dist/chunk-32DOFN3T.js.map +1 -0
  18. package/dist/chunk-36U5UGIO.js +107 -0
  19. package/dist/chunk-36U5UGIO.js.map +1 -0
  20. package/dist/chunk-3CJFPU6Q.js +14 -0
  21. package/dist/chunk-3CJFPU6Q.js.map +1 -0
  22. package/dist/chunk-3NMCDN7L.js +90 -0
  23. package/dist/chunk-3NMCDN7L.js.map +1 -0
  24. package/dist/chunk-3SZFUTXE.js +62 -0
  25. package/dist/chunk-3SZFUTXE.js.map +1 -0
  26. package/dist/chunk-4DOJBQTP.js +117 -0
  27. package/dist/chunk-4DOJBQTP.js.map +1 -0
  28. package/dist/chunk-4H3PETLM.js +290 -0
  29. package/dist/chunk-4H3PETLM.js.map +1 -0
  30. package/dist/chunk-4JLJYWJC.js +308 -0
  31. package/dist/chunk-4JLJYWJC.js.map +1 -0
  32. package/dist/chunk-4KNXX6TI.js +29 -0
  33. package/dist/chunk-4KNXX6TI.js.map +1 -0
  34. package/dist/chunk-4LH67P4U.js +17 -0
  35. package/dist/chunk-4LH67P4U.js.map +1 -0
  36. package/dist/chunk-4MF3HKJA.js +94 -0
  37. package/dist/chunk-4MF3HKJA.js.map +1 -0
  38. package/dist/chunk-4MVGAMUA.js +40 -0
  39. package/dist/chunk-4MVGAMUA.js.map +1 -0
  40. package/dist/chunk-4RFHUZXU.js +635 -0
  41. package/dist/chunk-4RFHUZXU.js.map +1 -0
  42. package/dist/chunk-5A432NZJ.js +7 -0
  43. package/dist/chunk-5A432NZJ.js.map +1 -0
  44. package/dist/chunk-5Y7W3XR6.js +356 -0
  45. package/dist/chunk-5Y7W3XR6.js.map +1 -0
  46. package/dist/chunk-6DWFJNIK.js +15 -0
  47. package/dist/chunk-6DWFJNIK.js.map +1 -0
  48. package/dist/chunk-6I7ULIN6.js +15 -0
  49. package/dist/chunk-6I7ULIN6.js.map +1 -0
  50. package/dist/chunk-6XY6ZMMD.js +25 -0
  51. package/dist/chunk-6XY6ZMMD.js.map +1 -0
  52. package/dist/chunk-7B3RYX45.js +63 -0
  53. package/dist/chunk-7B3RYX45.js.map +1 -0
  54. package/dist/chunk-7C3FOSDI.js +1 -0
  55. package/dist/chunk-7C3FOSDI.js.map +1 -0
  56. package/dist/chunk-7KOW6PU6.js +59 -0
  57. package/dist/chunk-7KOW6PU6.js.map +1 -0
  58. package/dist/chunk-7RELQJIN.js +22 -0
  59. package/dist/chunk-7RELQJIN.js.map +1 -0
  60. package/dist/chunk-7YGORYZD.js +112 -0
  61. package/dist/chunk-7YGORYZD.js.map +1 -0
  62. package/dist/chunk-AHV4GDYM.js +63 -0
  63. package/dist/chunk-AHV4GDYM.js.map +1 -0
  64. package/dist/chunk-AQFQ4BYM.js +81 -0
  65. package/dist/chunk-AQFQ4BYM.js.map +1 -0
  66. package/dist/chunk-AS3NAZB6.js +14 -0
  67. package/dist/chunk-AS3NAZB6.js.map +1 -0
  68. package/dist/chunk-BGULBWKJ.js +88 -0
  69. package/dist/chunk-BGULBWKJ.js.map +1 -0
  70. package/dist/chunk-BIO6F7YI.js +17 -0
  71. package/dist/chunk-BIO6F7YI.js.map +1 -0
  72. package/dist/chunk-BOPZWRJK.js +36 -0
  73. package/dist/chunk-BOPZWRJK.js.map +1 -0
  74. package/dist/chunk-BPARRK6F.js +14 -0
  75. package/dist/chunk-BPARRK6F.js.map +1 -0
  76. package/dist/chunk-CO6LUM72.js +59 -0
  77. package/dist/chunk-CO6LUM72.js.map +1 -0
  78. package/dist/chunk-DCCZB4UC.js +100 -0
  79. package/dist/chunk-DCCZB4UC.js.map +1 -0
  80. package/dist/chunk-DV4RV2DC.js +59 -0
  81. package/dist/chunk-DV4RV2DC.js.map +1 -0
  82. package/dist/chunk-EDKJU5BO.js +11 -0
  83. package/dist/chunk-EDKJU5BO.js.map +1 -0
  84. package/dist/chunk-EO2QPOKH.js +116 -0
  85. package/dist/chunk-EO2QPOKH.js.map +1 -0
  86. package/dist/chunk-EOLLMEAH.js +155 -0
  87. package/dist/chunk-EOLLMEAH.js.map +1 -0
  88. package/dist/chunk-EWYCWP4H.js +14 -0
  89. package/dist/chunk-EWYCWP4H.js.map +1 -0
  90. package/dist/chunk-EXVDJMIY.js +33 -0
  91. package/dist/chunk-EXVDJMIY.js.map +1 -0
  92. package/dist/chunk-FASRXRX5.js +19 -0
  93. package/dist/chunk-FASRXRX5.js.map +1 -0
  94. package/dist/chunk-FBGHYQIZ.js +201 -0
  95. package/dist/chunk-FBGHYQIZ.js.map +1 -0
  96. package/dist/chunk-FI34KYZ5.js +1 -0
  97. package/dist/chunk-FI34KYZ5.js.map +1 -0
  98. package/dist/chunk-FN2PYDPP.js +1 -0
  99. package/dist/chunk-FN2PYDPP.js.map +1 -0
  100. package/dist/chunk-GCYKMF22.js +81 -0
  101. package/dist/chunk-GCYKMF22.js.map +1 -0
  102. package/dist/chunk-GM3RMJIJ.js +92 -0
  103. package/dist/chunk-GM3RMJIJ.js.map +1 -0
  104. package/dist/chunk-GYGNEQSC.js +9 -0
  105. package/dist/chunk-GYGNEQSC.js.map +1 -0
  106. package/dist/chunk-H5NH7KPE.js +21 -0
  107. package/dist/chunk-H5NH7KPE.js.map +1 -0
  108. package/dist/chunk-HNWZFNKP.js +168 -0
  109. package/dist/chunk-HNWZFNKP.js.map +1 -0
  110. package/dist/chunk-HUH73XGI.js +1 -0
  111. package/dist/chunk-HUH73XGI.js.map +1 -0
  112. package/dist/chunk-I6MVCB5A.js +39 -0
  113. package/dist/chunk-I6MVCB5A.js.map +1 -0
  114. package/dist/chunk-IBGER4YK.js +12 -0
  115. package/dist/chunk-IBGER4YK.js.map +1 -0
  116. package/dist/chunk-IF5I3DAA.js +92 -0
  117. package/dist/chunk-IF5I3DAA.js.map +1 -0
  118. package/dist/chunk-IP4OO26U.js +54 -0
  119. package/dist/chunk-IP4OO26U.js.map +1 -0
  120. package/dist/chunk-IWAOY6KC.js +1 -0
  121. package/dist/chunk-IWAOY6KC.js.map +1 -0
  122. package/dist/chunk-IYNSRIGR.js +122 -0
  123. package/dist/chunk-IYNSRIGR.js.map +1 -0
  124. package/dist/chunk-J37YWU7Y.js +19 -0
  125. package/dist/chunk-J37YWU7Y.js.map +1 -0
  126. package/dist/chunk-J6KZS54B.js +269 -0
  127. package/dist/chunk-J6KZS54B.js.map +1 -0
  128. package/dist/chunk-J6MN42LG.js +19 -0
  129. package/dist/chunk-J6MN42LG.js.map +1 -0
  130. package/dist/chunk-J7JMVS2B.js +53 -0
  131. package/dist/chunk-J7JMVS2B.js.map +1 -0
  132. package/dist/chunk-JRQO2IOF.js +65 -0
  133. package/dist/chunk-JRQO2IOF.js.map +1 -0
  134. package/dist/chunk-JWNHNUYL.js +96 -0
  135. package/dist/chunk-JWNHNUYL.js.map +1 -0
  136. package/dist/chunk-K2I6XIK5.js +122 -0
  137. package/dist/chunk-K2I6XIK5.js.map +1 -0
  138. package/dist/chunk-KVOWSC5S.js +1 -0
  139. package/dist/chunk-KVOWSC5S.js.map +1 -0
  140. package/dist/chunk-KYR3B3OW.js +79 -0
  141. package/dist/chunk-KYR3B3OW.js.map +1 -0
  142. package/dist/chunk-L3LZWWSX.js +61 -0
  143. package/dist/chunk-L3LZWWSX.js.map +1 -0
  144. package/dist/chunk-L4SDDEEU.js +1 -0
  145. package/dist/chunk-L4SDDEEU.js.map +1 -0
  146. package/dist/chunk-L6FTY45T.js +13 -0
  147. package/dist/chunk-L6FTY45T.js.map +1 -0
  148. package/dist/chunk-L7BNNRGI.js +134 -0
  149. package/dist/chunk-L7BNNRGI.js.map +1 -0
  150. package/dist/chunk-LG57S2SC.js +150 -0
  151. package/dist/chunk-LG57S2SC.js.map +1 -0
  152. package/dist/chunk-M6QLSLPO.js +97 -0
  153. package/dist/chunk-M6QLSLPO.js.map +1 -0
  154. package/dist/chunk-MZ6GV4YF.js +21 -0
  155. package/dist/chunk-MZ6GV4YF.js.map +1 -0
  156. package/dist/chunk-N5OTOWTP.js +55 -0
  157. package/dist/chunk-N5OTOWTP.js.map +1 -0
  158. package/dist/chunk-NN7XZEGF.js +14 -0
  159. package/dist/chunk-NN7XZEGF.js.map +1 -0
  160. package/dist/chunk-NPFPZ2HO.js +13 -0
  161. package/dist/chunk-NPFPZ2HO.js.map +1 -0
  162. package/dist/chunk-NXXDZ6ZF.js +42 -0
  163. package/dist/chunk-NXXDZ6ZF.js.map +1 -0
  164. package/dist/chunk-NYBCQZC7.js +11 -0
  165. package/dist/chunk-NYBCQZC7.js.map +1 -0
  166. package/dist/chunk-O37C3YE6.js +111 -0
  167. package/dist/chunk-O37C3YE6.js.map +1 -0
  168. package/dist/chunk-OFRRBC7M.js +78 -0
  169. package/dist/chunk-OFRRBC7M.js.map +1 -0
  170. package/dist/chunk-OGIZXGPY.js +222 -0
  171. package/dist/chunk-OGIZXGPY.js.map +1 -0
  172. package/dist/chunk-OKXZ63IA.js +168 -0
  173. package/dist/chunk-OKXZ63IA.js.map +1 -0
  174. package/dist/chunk-OSQRXVG2.js +58 -0
  175. package/dist/chunk-OSQRXVG2.js.map +1 -0
  176. package/dist/chunk-OTDN3OUQ.js +215 -0
  177. package/dist/chunk-OTDN3OUQ.js.map +1 -0
  178. package/dist/chunk-PNZSGAB2.js +114 -0
  179. package/dist/chunk-PNZSGAB2.js.map +1 -0
  180. package/dist/chunk-PRWIX6UW.js +21 -0
  181. package/dist/chunk-PRWIX6UW.js.map +1 -0
  182. package/dist/chunk-PSXUNOVU.js +7 -0
  183. package/dist/chunk-PSXUNOVU.js.map +1 -0
  184. package/dist/chunk-QLTJSCE6.js +44 -0
  185. package/dist/chunk-QLTJSCE6.js.map +1 -0
  186. package/dist/chunk-RC23QROE.js +447 -0
  187. package/dist/chunk-RC23QROE.js.map +1 -0
  188. package/dist/chunk-RDVTWIYY.js +212 -0
  189. package/dist/chunk-RDVTWIYY.js.map +1 -0
  190. package/dist/chunk-RFH7N6EP.js +36 -0
  191. package/dist/chunk-RFH7N6EP.js.map +1 -0
  192. package/dist/chunk-RHVN6NA7.js +134 -0
  193. package/dist/chunk-RHVN6NA7.js.map +1 -0
  194. package/dist/chunk-S7C6TIIF.js +21 -0
  195. package/dist/chunk-S7C6TIIF.js.map +1 -0
  196. package/dist/chunk-SNQ3TOWP.js +20 -0
  197. package/dist/chunk-SNQ3TOWP.js.map +1 -0
  198. package/dist/chunk-SOVM2VEK.js +14 -0
  199. package/dist/chunk-SOVM2VEK.js.map +1 -0
  200. package/dist/chunk-SQDOBLBP.js +13 -0
  201. package/dist/chunk-SQDOBLBP.js.map +1 -0
  202. package/dist/chunk-SR7F3TJY.js +130 -0
  203. package/dist/chunk-SR7F3TJY.js.map +1 -0
  204. package/dist/chunk-SZVPIHWE.js +129 -0
  205. package/dist/chunk-SZVPIHWE.js.map +1 -0
  206. package/dist/chunk-T4BIIU5E.js +89 -0
  207. package/dist/chunk-T4BIIU5E.js.map +1 -0
  208. package/dist/chunk-T6SCOJF4.js +92 -0
  209. package/dist/chunk-T6SCOJF4.js.map +1 -0
  210. package/dist/chunk-TNXH7BJS.js +48 -0
  211. package/dist/chunk-TNXH7BJS.js.map +1 -0
  212. package/dist/chunk-U64T4YZE.js +9 -0
  213. package/dist/chunk-U64T4YZE.js.map +1 -0
  214. package/dist/chunk-UQ5EHOH2.js +39 -0
  215. package/dist/chunk-UQ5EHOH2.js.map +1 -0
  216. package/dist/chunk-UTN4GBPQ.js +1 -0
  217. package/dist/chunk-UTN4GBPQ.js.map +1 -0
  218. package/dist/chunk-V4AF6DI4.js +16 -0
  219. package/dist/chunk-V4AF6DI4.js.map +1 -0
  220. package/dist/chunk-W72PRNJY.js +126 -0
  221. package/dist/chunk-W72PRNJY.js.map +1 -0
  222. package/dist/chunk-WL67FZGF.js +21 -0
  223. package/dist/chunk-WL67FZGF.js.map +1 -0
  224. package/dist/chunk-WWGYCIJX.js +29 -0
  225. package/dist/chunk-WWGYCIJX.js.map +1 -0
  226. package/dist/chunk-X2GMTYPA.js +50 -0
  227. package/dist/chunk-X2GMTYPA.js.map +1 -0
  228. package/dist/chunk-XCEI7NUH.js +41 -0
  229. package/dist/chunk-XCEI7NUH.js.map +1 -0
  230. package/dist/chunk-Y7GDG744.js +88 -0
  231. package/dist/chunk-Y7GDG744.js.map +1 -0
  232. package/dist/chunk-Y7RRSEOC.js +9 -0
  233. package/dist/chunk-Y7RRSEOC.js.map +1 -0
  234. package/dist/chunk-YLPAPPLW.js +75 -0
  235. package/dist/chunk-YLPAPPLW.js.map +1 -0
  236. package/dist/chunk-YPWODKD5.js +184 -0
  237. package/dist/chunk-YPWODKD5.js.map +1 -0
  238. package/dist/chunk-YSLTTQLC.js +25 -0
  239. package/dist/chunk-YSLTTQLC.js.map +1 -0
  240. package/dist/chunk-YTN6BKWA.js +121 -0
  241. package/dist/chunk-YTN6BKWA.js.map +1 -0
  242. package/dist/chunk-Z7PQCAVK.js +200 -0
  243. package/dist/chunk-Z7PQCAVK.js.map +1 -0
  244. package/dist/chunk-ZUKFQL6E.js +47 -0
  245. package/dist/chunk-ZUKFQL6E.js.map +1 -0
  246. package/dist/chunk-ZUMULSEQ.js +1 -0
  247. package/dist/chunk-ZUMULSEQ.js.map +1 -0
  248. package/dist/runtime/analytics/index.js +8 -41
  249. package/dist/runtime/analytics/index.js.map +1 -1
  250. package/dist/runtime/analytics/types.js +8 -41
  251. package/dist/runtime/analytics/types.js.map +1 -1
  252. package/dist/runtime/base-classes/activity-entity-repository.js +6 -312
  253. package/dist/runtime/base-classes/activity-entity-repository.js.map +1 -1
  254. package/dist/runtime/base-classes/activity-entity-service.js +6 -212
  255. package/dist/runtime/base-classes/activity-entity-service.js.map +1 -1
  256. package/dist/runtime/base-classes/base-read-use-cases.js +5 -27
  257. package/dist/runtime/base-classes/base-read-use-cases.js.map +1 -1
  258. package/dist/runtime/base-classes/base-repository.js +5 -277
  259. package/dist/runtime/base-classes/base-repository.js.map +1 -1
  260. package/dist/runtime/base-classes/base-service.js +5 -184
  261. package/dist/runtime/base-classes/base-service.js.map +1 -1
  262. package/dist/runtime/base-classes/index.js +59 -1076
  263. package/dist/runtime/base-classes/index.js.map +1 -1
  264. package/dist/runtime/base-classes/integrated-entity-repository.js +6 -486
  265. package/dist/runtime/base-classes/integrated-entity-repository.js.map +1 -1
  266. package/dist/runtime/base-classes/integrated-entity-service.js +6 -213
  267. package/dist/runtime/base-classes/integrated-entity-service.js.map +1 -1
  268. package/dist/runtime/base-classes/junction-integration-repository.js +8 -448
  269. package/dist/runtime/base-classes/junction-integration-repository.js.map +1 -1
  270. package/dist/runtime/base-classes/knowledge-entity-repository.js +6 -283
  271. package/dist/runtime/base-classes/knowledge-entity-repository.js.map +1 -1
  272. package/dist/runtime/base-classes/knowledge-entity-service.js +6 -190
  273. package/dist/runtime/base-classes/knowledge-entity-service.js.map +1 -1
  274. package/dist/runtime/base-classes/lifecycle-events.js +8 -70
  275. package/dist/runtime/base-classes/lifecycle-events.js.map +1 -1
  276. package/dist/runtime/base-classes/metadata-entity-repository.js +6 -330
  277. package/dist/runtime/base-classes/metadata-entity-repository.js.map +1 -1
  278. package/dist/runtime/base-classes/metadata-entity-service.js +6 -212
  279. package/dist/runtime/base-classes/metadata-entity-service.js.map +1 -1
  280. package/dist/runtime/base-classes/tenant-context.js +10 -36
  281. package/dist/runtime/base-classes/tenant-context.js.map +1 -1
  282. package/dist/runtime/base-classes/with-analytics.js +4 -7
  283. package/dist/runtime/base-classes/with-analytics.js.map +1 -1
  284. package/dist/runtime/constants/tokens.js +5 -3
  285. package/dist/runtime/constants/tokens.js.map +1 -1
  286. package/dist/runtime/eav-helpers.js +2 -0
  287. package/dist/runtime/eav-helpers.js.map +1 -1
  288. package/dist/runtime/pipes/zod-validation.pipe.js +3 -10
  289. package/dist/runtime/pipes/zod-validation.pipe.js.map +1 -1
  290. package/dist/runtime/shared/openapi/error-response.dto.js +5 -8
  291. package/dist/runtime/shared/openapi/error-response.dto.js.map +1 -1
  292. package/dist/runtime/shared/openapi/errors.js +5 -19
  293. package/dist/runtime/shared/openapi/errors.js.map +1 -1
  294. package/dist/runtime/shared/openapi/index.js +15 -106
  295. package/dist/runtime/shared/openapi/index.js.map +1 -1
  296. package/dist/runtime/shared/openapi/registry.js +6 -103
  297. package/dist/runtime/shared/openapi/registry.js.map +1 -1
  298. package/dist/runtime/shared/openapi/registry.tokens.js +4 -2
  299. package/dist/runtime/shared/openapi/registry.tokens.js.map +1 -1
  300. package/dist/runtime/subsystems/analytics/analytics.module.js +8 -117
  301. package/dist/runtime/subsystems/analytics/analytics.module.js.map +1 -1
  302. package/dist/runtime/subsystems/analytics/analytics.tokens.js +7 -8
  303. package/dist/runtime/subsystems/analytics/analytics.tokens.js.map +1 -1
  304. package/dist/runtime/subsystems/analytics/cube-backend.js +6 -71
  305. package/dist/runtime/subsystems/analytics/cube-backend.js.map +1 -1
  306. package/dist/runtime/subsystems/analytics/index.js +16 -117
  307. package/dist/runtime/subsystems/analytics/index.js.map +1 -1
  308. package/dist/runtime/subsystems/analytics/noop-backend.js +4 -21
  309. package/dist/runtime/subsystems/analytics/noop-backend.js.map +1 -1
  310. package/dist/runtime/subsystems/auth/auth-oauth-state.schema.js +4 -8
  311. package/dist/runtime/subsystems/auth/auth-oauth-state.schema.js.map +1 -1
  312. package/dist/runtime/subsystems/auth/auth.module.js +12 -359
  313. package/dist/runtime/subsystems/auth/auth.module.js.map +1 -1
  314. package/dist/runtime/subsystems/auth/auth.tokens.js +12 -13
  315. package/dist/runtime/subsystems/auth/auth.tokens.js.map +1 -1
  316. package/dist/runtime/subsystems/auth/backends/encryption-key/env.js +4 -49
  317. package/dist/runtime/subsystems/auth/backends/encryption-key/env.js.map +1 -1
  318. package/dist/runtime/subsystems/auth/backends/state-store.drizzle-backend.js +6 -64
  319. package/dist/runtime/subsystems/auth/backends/state-store.drizzle-backend.js.map +1 -1
  320. package/dist/runtime/subsystems/auth/backends/state-store.memory-backend.js +5 -47
  321. package/dist/runtime/subsystems/auth/backends/state-store.memory-backend.js.map +1 -1
  322. package/dist/runtime/subsystems/auth/controllers/auth.controller.js +5 -139
  323. package/dist/runtime/subsystems/auth/controllers/auth.controller.js.map +1 -1
  324. package/dist/runtime/subsystems/auth/index.js +53 -542
  325. package/dist/runtime/subsystems/auth/index.js.map +1 -1
  326. package/dist/runtime/subsystems/auth/middleware/requester-context.js +9 -65
  327. package/dist/runtime/subsystems/auth/middleware/requester-context.js.map +1 -1
  328. package/dist/runtime/subsystems/auth/protocols/oauth-state-store.js +4 -9
  329. package/dist/runtime/subsystems/auth/protocols/oauth-state-store.js.map +1 -1
  330. package/dist/runtime/subsystems/auth/runtime/connection-broken.error.js +4 -15
  331. package/dist/runtime/subsystems/auth/runtime/connection-broken.error.js.map +1 -1
  332. package/dist/runtime/subsystems/auth/runtime/oauth2-refresh.strategy.js +5 -104
  333. package/dist/runtime/subsystems/auth/runtime/oauth2-refresh.strategy.js.map +1 -1
  334. package/dist/runtime/subsystems/auth/runtime/session-expired.error.js +5 -16
  335. package/dist/runtime/subsystems/auth/runtime/session-expired.error.js.map +1 -1
  336. package/dist/runtime/subsystems/auth/runtime/with-auth-retry.js +5 -29
  337. package/dist/runtime/subsystems/auth/runtime/with-auth-retry.js.map +1 -1
  338. package/dist/runtime/subsystems/bridge/assert-tenant-id.js +5 -18
  339. package/dist/runtime/subsystems/bridge/assert-tenant-id.js.map +1 -1
  340. package/dist/runtime/subsystems/bridge/bridge-delivery-handler.js +12 -184
  341. package/dist/runtime/subsystems/bridge/bridge-delivery-handler.js.map +1 -1
  342. package/dist/runtime/subsystems/bridge/bridge-delivery.drizzle-backend.js +10 -448
  343. package/dist/runtime/subsystems/bridge/bridge-delivery.drizzle-backend.js.map +1 -1
  344. package/dist/runtime/subsystems/bridge/bridge-delivery.memory-backend.js +5 -126
  345. package/dist/runtime/subsystems/bridge/bridge-delivery.memory-backend.js.map +1 -1
  346. package/dist/runtime/subsystems/bridge/bridge-delivery.schema.js +6 -308
  347. package/dist/runtime/subsystems/bridge/bridge-delivery.schema.js.map +1 -1
  348. package/dist/runtime/subsystems/bridge/bridge-errors.js +6 -35
  349. package/dist/runtime/subsystems/bridge/bridge-errors.js.map +1 -1
  350. package/dist/runtime/subsystems/bridge/bridge-outbox-drain-hook.js +14 -606
  351. package/dist/runtime/subsystems/bridge/bridge-outbox-drain-hook.js.map +1 -1
  352. package/dist/runtime/subsystems/bridge/bridge.module.js +35 -3476
  353. package/dist/runtime/subsystems/bridge/bridge.module.js.map +1 -1
  354. package/dist/runtime/subsystems/bridge/bridge.tokens.js +9 -7
  355. package/dist/runtime/subsystems/bridge/bridge.tokens.js.map +1 -1
  356. package/dist/runtime/subsystems/bridge/event-flow.service.js +11 -137
  357. package/dist/runtime/subsystems/bridge/event-flow.service.js.map +1 -1
  358. package/dist/runtime/subsystems/bridge/generated/registry.js +4 -2
  359. package/dist/runtime/subsystems/bridge/generated/registry.js.map +1 -1
  360. package/dist/runtime/subsystems/bridge/index.js +60 -3470
  361. package/dist/runtime/subsystems/bridge/index.js.map +1 -1
  362. package/dist/runtime/subsystems/bridge/reserved-pools.js +4 -6
  363. package/dist/runtime/subsystems/bridge/reserved-pools.js.map +1 -1
  364. package/dist/runtime/subsystems/cache/cache.drizzle-backend.js +10 -133
  365. package/dist/runtime/subsystems/cache/cache.drizzle-backend.js.map +1 -1
  366. package/dist/runtime/subsystems/cache/cache.memory-backend.js +6 -101
  367. package/dist/runtime/subsystems/cache/cache.memory-backend.js.map +1 -1
  368. package/dist/runtime/subsystems/cache/cache.module.js +10 -278
  369. package/dist/runtime/subsystems/cache/cache.module.js.map +1 -1
  370. package/dist/runtime/subsystems/cache/cache.schema.js +4 -14
  371. package/dist/runtime/subsystems/cache/cache.schema.js.map +1 -1
  372. package/dist/runtime/subsystems/cache/cache.tokens.js +6 -7
  373. package/dist/runtime/subsystems/cache/cache.tokens.js.map +1 -1
  374. package/dist/runtime/subsystems/cache/index.js +20 -278
  375. package/dist/runtime/subsystems/cache/index.js.map +1 -1
  376. package/dist/runtime/subsystems/events/domain-events.schema.js +3 -72
  377. package/dist/runtime/subsystems/events/domain-events.schema.js.map +1 -1
  378. package/dist/runtime/subsystems/events/event-bus.drizzle-backend.js +9 -413
  379. package/dist/runtime/subsystems/events/event-bus.drizzle-backend.js.map +1 -1
  380. package/dist/runtime/subsystems/events/event-bus.memory-backend.js +7 -235
  381. package/dist/runtime/subsystems/events/event-bus.memory-backend.js.map +1 -1
  382. package/dist/runtime/subsystems/events/event-bus.redis-backend.js +8 -20
  383. package/dist/runtime/subsystems/events/event-bus.redis-backend.js.map +1 -1
  384. package/dist/runtime/subsystems/events/event-keyset-cursor.js +8 -30
  385. package/dist/runtime/subsystems/events/event-keyset-cursor.js.map +1 -1
  386. package/dist/runtime/subsystems/events/event-read.protocol.js +2 -0
  387. package/dist/runtime/subsystems/events/event-read.protocol.js.map +1 -1
  388. package/dist/runtime/subsystems/events/events-errors.js +4 -11
  389. package/dist/runtime/subsystems/events/events-errors.js.map +1 -1
  390. package/dist/runtime/subsystems/events/events.module.js +15 -949
  391. package/dist/runtime/subsystems/events/events.module.js.map +1 -1
  392. package/dist/runtime/subsystems/events/events.tokens.js +10 -11
  393. package/dist/runtime/subsystems/events/events.tokens.js.map +1 -1
  394. package/dist/runtime/subsystems/events/generated/bus.js +9 -240
  395. package/dist/runtime/subsystems/events/generated/bus.js.map +1 -1
  396. package/dist/runtime/subsystems/events/generated/index.js +23 -240
  397. package/dist/runtime/subsystems/events/generated/index.js.map +1 -1
  398. package/dist/runtime/subsystems/events/generated/registry.js +5 -82
  399. package/dist/runtime/subsystems/events/generated/registry.js.map +1 -1
  400. package/dist/runtime/subsystems/events/generated/schemas.js +12 -52
  401. package/dist/runtime/subsystems/events/generated/schemas.js.map +1 -1
  402. package/dist/runtime/subsystems/events/generated/types.js +1 -0
  403. package/dist/runtime/subsystems/events/index.js +32 -949
  404. package/dist/runtime/subsystems/events/index.js.map +1 -1
  405. package/dist/runtime/subsystems/index.d.ts +5 -1
  406. package/dist/runtime/subsystems/index.js +182 -5912
  407. package/dist/runtime/subsystems/index.js.map +1 -1
  408. package/dist/runtime/subsystems/integration/build-change-source.js +6 -178
  409. package/dist/runtime/subsystems/integration/build-change-source.js.map +1 -1
  410. package/dist/runtime/subsystems/integration/deep-equal.differ.js +4 -109
  411. package/dist/runtime/subsystems/integration/deep-equal.differ.js.map +1 -1
  412. package/dist/runtime/subsystems/integration/detection-config.schema.js +11 -78
  413. package/dist/runtime/subsystems/integration/detection-config.schema.js.map +1 -1
  414. package/dist/runtime/subsystems/integration/entity-change-source-registry.memory.js +5 -30
  415. package/dist/runtime/subsystems/integration/entity-change-source-registry.memory.js.map +1 -1
  416. package/dist/runtime/subsystems/integration/entity-change-source-registry.protocol.js +4 -9
  417. package/dist/runtime/subsystems/integration/entity-change-source-registry.protocol.js.map +1 -1
  418. package/dist/runtime/subsystems/integration/execute-integration.use-case.js +6 -239
  419. package/dist/runtime/subsystems/integration/execute-integration.use-case.js.map +1 -1
  420. package/dist/runtime/subsystems/integration/incremental-read.js +5 -144
  421. package/dist/runtime/subsystems/integration/incremental-read.js.map +1 -1
  422. package/dist/runtime/subsystems/integration/index.js +83 -1352
  423. package/dist/runtime/subsystems/integration/index.js.map +1 -1
  424. package/dist/runtime/subsystems/integration/integration-audit.schema.js +10 -155
  425. package/dist/runtime/subsystems/integration/integration-audit.schema.js.map +1 -1
  426. package/dist/runtime/subsystems/integration/integration-cursor-store.drizzle-backend.js +7 -270
  427. package/dist/runtime/subsystems/integration/integration-cursor-store.drizzle-backend.js.map +1 -1
  428. package/dist/runtime/subsystems/integration/integration-cursor-store.memory-backend.js +4 -65
  429. package/dist/runtime/subsystems/integration/integration-cursor-store.memory-backend.js.map +1 -1
  430. package/dist/runtime/subsystems/integration/integration-errors.js +5 -15
  431. package/dist/runtime/subsystems/integration/integration-errors.js.map +1 -1
  432. package/dist/runtime/subsystems/integration/integration-field-diff.protocol.js +5 -7
  433. package/dist/runtime/subsystems/integration/integration-field-diff.protocol.js.map +1 -1
  434. package/dist/runtime/subsystems/integration/integration-run-recorder.drizzle-backend.js +8 -303
  435. package/dist/runtime/subsystems/integration/integration-run-recorder.drizzle-backend.js.map +1 -1
  436. package/dist/runtime/subsystems/integration/integration-run-recorder.memory-backend.js +5 -125
  437. package/dist/runtime/subsystems/integration/integration-run-recorder.memory-backend.js.map +1 -1
  438. package/dist/runtime/subsystems/integration/integration.module.js +13 -700
  439. package/dist/runtime/subsystems/integration/integration.module.js.map +1 -1
  440. package/dist/runtime/subsystems/integration/integration.tokens.js +11 -9
  441. package/dist/runtime/subsystems/integration/integration.tokens.js.map +1 -1
  442. package/dist/runtime/subsystems/integration/loopback.middleware.js +4 -16
  443. package/dist/runtime/subsystems/integration/loopback.middleware.js.map +1 -1
  444. package/dist/runtime/subsystems/integration/poll-change-source.d.ts +1 -1
  445. package/dist/runtime/subsystems/integration/poll-change-source.js +4 -89
  446. package/dist/runtime/subsystems/integration/poll-change-source.js.map +1 -1
  447. package/dist/runtime/subsystems/integration/webhook-change-source.d.ts +4 -3
  448. package/dist/runtime/subsystems/integration/webhook-change-source.js +4 -70
  449. package/dist/runtime/subsystems/integration/webhook-change-source.js.map +1 -1
  450. package/dist/runtime/subsystems/jobs/bullmq.config.js +9 -140
  451. package/dist/runtime/subsystems/jobs/bullmq.config.js.map +1 -1
  452. package/dist/runtime/subsystems/jobs/index.js +88 -2691
  453. package/dist/runtime/subsystems/jobs/index.js.map +1 -1
  454. package/dist/runtime/subsystems/jobs/job-handler.base.js +10 -49
  455. package/dist/runtime/subsystems/jobs/job-handler.base.js.map +1 -1
  456. package/dist/runtime/subsystems/jobs/job-orchestration.schema.js +13 -152
  457. package/dist/runtime/subsystems/jobs/job-orchestration.schema.js.map +1 -1
  458. package/dist/runtime/subsystems/jobs/job-orchestrator.bullmq-backend.js +36 -699
  459. package/dist/runtime/subsystems/jobs/job-orchestrator.bullmq-backend.js.map +1 -1
  460. package/dist/runtime/subsystems/jobs/job-orchestrator.drizzle-backend.js +10 -564
  461. package/dist/runtime/subsystems/jobs/job-orchestrator.drizzle-backend.js.map +1 -1
  462. package/dist/runtime/subsystems/jobs/job-orchestrator.memory-backend.js +10 -824
  463. package/dist/runtime/subsystems/jobs/job-orchestrator.memory-backend.js.map +1 -1
  464. package/dist/runtime/subsystems/jobs/job-run-keyset-cursor.js +9 -51
  465. package/dist/runtime/subsystems/jobs/job-run-keyset-cursor.js.map +1 -1
  466. package/dist/runtime/subsystems/jobs/job-run-service.drizzle-backend.js +9 -416
  467. package/dist/runtime/subsystems/jobs/job-run-service.drizzle-backend.js.map +1 -1
  468. package/dist/runtime/subsystems/jobs/job-run-service.memory-backend.js +9 -290
  469. package/dist/runtime/subsystems/jobs/job-run-service.memory-backend.js.map +1 -1
  470. package/dist/runtime/subsystems/jobs/job-step-service.drizzle-backend.js +5 -213
  471. package/dist/runtime/subsystems/jobs/job-step-service.drizzle-backend.js.map +1 -1
  472. package/dist/runtime/subsystems/jobs/job-step-service.memory-backend.js +5 -131
  473. package/dist/runtime/subsystems/jobs/job-step-service.memory-backend.js.map +1 -1
  474. package/dist/runtime/subsystems/jobs/job-worker.bullmq-backend.js +9 -175
  475. package/dist/runtime/subsystems/jobs/job-worker.bullmq-backend.js.map +1 -1
  476. package/dist/runtime/subsystems/jobs/job-worker.js +14 -613
  477. package/dist/runtime/subsystems/jobs/job-worker.js.map +1 -1
  478. package/dist/runtime/subsystems/jobs/job-worker.module.js +23 -2647
  479. package/dist/runtime/subsystems/jobs/job-worker.module.js.map +1 -1
  480. package/dist/runtime/subsystems/jobs/jobs-domain.module.js +19 -1897
  481. package/dist/runtime/subsystems/jobs/jobs-domain.module.js.map +1 -1
  482. package/dist/runtime/subsystems/jobs/jobs-domain.tokens.js +8 -9
  483. package/dist/runtime/subsystems/jobs/jobs-domain.tokens.js.map +1 -1
  484. package/dist/runtime/subsystems/jobs/jobs-errors.js +10 -78
  485. package/dist/runtime/subsystems/jobs/jobs-errors.js.map +1 -1
  486. package/dist/runtime/subsystems/jobs/memory-job-store.js +4 -15
  487. package/dist/runtime/subsystems/jobs/memory-job-store.js.map +1 -1
  488. package/dist/runtime/subsystems/jobs/pool-config.loader.js +9 -124
  489. package/dist/runtime/subsystems/jobs/pool-config.loader.js.map +1 -1
  490. package/dist/runtime/subsystems/observability/index.js +21 -310
  491. package/dist/runtime/subsystems/observability/index.js.map +1 -1
  492. package/dist/runtime/subsystems/observability/observability-errors.js +4 -9
  493. package/dist/runtime/subsystems/observability/observability-errors.js.map +1 -1
  494. package/dist/runtime/subsystems/observability/observability.module.js +11 -300
  495. package/dist/runtime/subsystems/observability/observability.module.js.map +1 -1
  496. package/dist/runtime/subsystems/observability/observability.service.js +9 -197
  497. package/dist/runtime/subsystems/observability/observability.service.js.map +1 -1
  498. package/dist/runtime/subsystems/observability/observability.tokens.js +5 -3
  499. package/dist/runtime/subsystems/observability/observability.tokens.js.map +1 -1
  500. package/dist/runtime/subsystems/observability/reporters/bridge-metrics.reporter.js +4 -84
  501. package/dist/runtime/subsystems/observability/reporters/bridge-metrics.reporter.js.map +1 -1
  502. package/dist/runtime/subsystems/observability/reporters/index.js +5 -84
  503. package/dist/runtime/subsystems/observability/reporters/index.js.map +1 -1
  504. package/dist/runtime/subsystems/storage/index.js +15 -200
  505. package/dist/runtime/subsystems/storage/index.js.map +1 -1
  506. package/dist/runtime/subsystems/storage/storage.local-backend.js +4 -103
  507. package/dist/runtime/subsystems/storage/storage.local-backend.js.map +1 -1
  508. package/dist/runtime/subsystems/storage/storage.memory-backend.js +5 -68
  509. package/dist/runtime/subsystems/storage/storage.memory-backend.js.map +1 -1
  510. package/dist/runtime/subsystems/storage/storage.module.js +8 -200
  511. package/dist/runtime/subsystems/storage/storage.module.js.map +1 -1
  512. package/dist/runtime/subsystems/storage/storage.tokens.js +5 -6
  513. package/dist/runtime/subsystems/storage/storage.tokens.js.map +1 -1
  514. package/dist/runtime/subsystems/storage/storage.utils.js +4 -14
  515. package/dist/runtime/subsystems/storage/storage.utils.js.map +1 -1
  516. package/dist/runtime/subsystems/token-key.js +5 -3
  517. package/dist/runtime/subsystems/token-key.js.map +1 -1
  518. package/dist/src/cli/index.js +637 -5454
  519. package/dist/src/cli/index.js.map +1 -1
  520. package/dist/src/index.js +68 -4170
  521. package/dist/src/index.js.map +1 -1
  522. package/package.json +1 -1
  523. package/runtime/subsystems/bridge/bridge-outbox-drain-hook.ts +44 -21
  524. package/runtime/subsystems/index.ts +27 -0
  525. package/runtime/subsystems/integration/poll-change-source.ts +10 -7
  526. package/runtime/subsystems/integration/webhook-change-source.ts +12 -8
  527. package/runtime/subsystems/jobs/job-worker.ts +17 -11
@@ -0,0 +1,290 @@
1
+ import {
2
+ JobWorker
3
+ } from "./chunk-RC23QROE.js";
4
+ import {
5
+ JobsDomainModule
6
+ } from "./chunk-O37C3YE6.js";
7
+ import {
8
+ BULLMQ_CONNECTION,
9
+ BULLMQ_RESOLVED_CONFIG,
10
+ resolvePoolQueueName
11
+ } from "./chunk-I6MVCB5A.js";
12
+ import {
13
+ allNonReservedPoolNames,
14
+ allPoolNames,
15
+ loadPoolConfig
16
+ } from "./chunk-RHVN6NA7.js";
17
+ import {
18
+ BootValidationError,
19
+ ReservedPoolViolationError
20
+ } from "./chunk-T4BIIU5E.js";
21
+ import {
22
+ HandlerRegistry
23
+ } from "./chunk-CO6LUM72.js";
24
+ import {
25
+ JOB_ORCHESTRATOR,
26
+ JOB_RUN_SERVICE,
27
+ JOB_STEP_SERVICE
28
+ } from "./chunk-BIO6F7YI.js";
29
+ import {
30
+ tokenKey
31
+ } from "./chunk-GYGNEQSC.js";
32
+ import {
33
+ DRIZZLE
34
+ } from "./chunk-U64T4YZE.js";
35
+ import {
36
+ __decorateClass,
37
+ __decorateParam
38
+ } from "./chunk-2E224ZSN.js";
39
+
40
+ // runtime/subsystems/jobs/job-worker.module.ts
41
+ import {
42
+ Inject,
43
+ Injectable,
44
+ Logger,
45
+ Module,
46
+ Optional
47
+ } from "@nestjs/common";
48
+ import { ModuleRef } from "@nestjs/core";
49
+ var DEFAULT_SHUTDOWN_TIMEOUT_MS = 3e4;
50
+ var JOB_WORKER_MODULE_OPTIONS = Symbol.for(tokenKey("jobs", "worker-module-options"));
51
+ var JobWorkerOrchestrator = class {
52
+ constructor(orchestrator, runService, stepService, options, db = null, moduleRef, bullConnection = null, bullConfig = null) {
53
+ this.orchestrator = orchestrator;
54
+ this.runService = runService;
55
+ this.stepService = stepService;
56
+ this.options = options;
57
+ this.db = db;
58
+ this.moduleRef = moduleRef;
59
+ this.bullConnection = bullConnection;
60
+ this.bullConfig = bullConfig;
61
+ }
62
+ orchestrator;
63
+ runService;
64
+ stepService;
65
+ options;
66
+ db;
67
+ moduleRef;
68
+ bullConnection;
69
+ bullConfig;
70
+ logger = new Logger(JobWorkerOrchestrator.name);
71
+ workers = [];
72
+ // ============================================================================
73
+ // Lifecycle
74
+ // ============================================================================
75
+ async onModuleInit() {
76
+ const backend = this.options.backend ?? "drizzle";
77
+ const poolConfig = loadPoolConfig(this.options.configPath);
78
+ const entries = HandlerRegistry.getAll();
79
+ this.assertNoReservedPoolHandlers(entries, poolConfig);
80
+ const { orphaned } = await this.orchestrator.upsertJobRows(
81
+ entries,
82
+ poolConfig
83
+ );
84
+ if (backend !== "memory" && orphaned.length > 0) {
85
+ throw new BootValidationError(orphaned);
86
+ }
87
+ const activePools = this.options.pools ? this.options.pools : this.options.allPools ? allPoolNames(poolConfig) : allNonReservedPoolNames(poolConfig);
88
+ for (const poolName of activePools) {
89
+ const def = poolConfig.get(poolName);
90
+ if (!def) {
91
+ throw new Error(
92
+ `JobWorkerModule: active pool '${poolName}' is not defined in the resolved pool config. Configured pools: [${[...poolConfig.keys()].join(", ")}].`
93
+ );
94
+ }
95
+ const workerOptions = {
96
+ pool: poolName,
97
+ concurrency: def.concurrency,
98
+ shutdownTimeoutMs: this.options.shutdownTimeoutMs ?? DEFAULT_SHUTDOWN_TIMEOUT_MS
99
+ };
100
+ const worker = this.options.workerFactory ? this.options.workerFactory(workerOptions) : backend === "bullmq" ? await this.spawnBullMQWorker(poolName, def.queue, def.concurrency, poolConfig) : this.spawnWorker(workerOptions);
101
+ await worker.onModuleInit();
102
+ this.workers.push(worker);
103
+ this.logger.log(
104
+ `JobWorker started: pool='${poolName}' (queue='${def.queue}') concurrency=${def.concurrency} backend='${backend}'`
105
+ );
106
+ }
107
+ }
108
+ async onModuleDestroy() {
109
+ for (let i = this.workers.length - 1; i >= 0; i--) {
110
+ const worker = this.workers[i];
111
+ if (!worker) continue;
112
+ try {
113
+ await worker.onModuleDestroy();
114
+ } catch (err) {
115
+ this.logger.error(
116
+ `JobWorker shutdown failed: ${err.message}`
117
+ );
118
+ }
119
+ }
120
+ this.workers.length = 0;
121
+ const orch = this.orchestrator;
122
+ if (typeof orch.closeConnections === "function") {
123
+ try {
124
+ await orch.closeConnections();
125
+ } catch (err) {
126
+ this.logger.error(
127
+ `BullMQ orchestrator connection close failed: ${err.message}`
128
+ );
129
+ }
130
+ }
131
+ }
132
+ // ============================================================================
133
+ // Internals
134
+ // ============================================================================
135
+ /**
136
+ * Walk every registered handler; collect any whose declared `pool`
137
+ * targets a reserved pool from the resolved config. If non-empty,
138
+ * throw `ReservedPoolViolationError` with the offender list so the
139
+ * operator sees every violating class on a single boot.
140
+ */
141
+ assertNoReservedPoolHandlers(entries, poolConfig) {
142
+ const offenders = [];
143
+ for (const entry of entries) {
144
+ if (entry.type.startsWith("@framework/")) continue;
145
+ const declaredPool = entry.meta.pool ?? "batch";
146
+ const def = poolConfig.get(declaredPool);
147
+ if (def?.reserved) {
148
+ offenders.push({
149
+ handlerClass: entry.handlerClass.name,
150
+ pool: declaredPool
151
+ });
152
+ }
153
+ }
154
+ if (offenders.length > 0) {
155
+ throw new ReservedPoolViolationError(offenders);
156
+ }
157
+ }
158
+ /**
159
+ * Production worker spawn. `JobWorker` requires `DRIZZLE` so this only
160
+ * succeeds when the module was booted with `backend: 'drizzle'`. Memory
161
+ * mode tests must supply `workerFactory` — the memory backend has no
162
+ * polling loop equivalent (`MemoryJobOrchestrator` is direct-invocation
163
+ * only).
164
+ *
165
+ * We instantiate outside the Nest container because the module spawns
166
+ * N workers from a single options shape, which doesn't fit Nest's
167
+ * "one provider per token" model. The dependencies are passed
168
+ * positionally; the constructor's `@Inject` decorators are unused on
169
+ * this path (Nest still uses them when `JobWorker` is a provider — e.g.
170
+ * in JOB-6's standalone `worker.ts` entrypoint).
171
+ */
172
+ spawnWorker(workerOptions) {
173
+ if (!this.db) {
174
+ throw new Error(
175
+ `JobWorkerModule: in-process worker spawning requires the Drizzle backend (no DRIZZLE provider available). Memory-mode tests must pass 'workerFactory' to inject a stub.`
176
+ );
177
+ }
178
+ if (!this.moduleRef) {
179
+ throw new Error(
180
+ `JobWorkerModule: ModuleRef not available \u2014 cannot construct JobWorker with handler DI support. Ensure the orchestrator is resolved through the Nest container (not instantiated manually in tests).`
181
+ );
182
+ }
183
+ return new JobWorker(
184
+ this.db,
185
+ this.orchestrator,
186
+ this.runService,
187
+ this.stepService,
188
+ workerOptions,
189
+ this.moduleRef
190
+ );
191
+ }
192
+ /**
193
+ * BULLMQ-1 — spawn a per-pool `BullMQJobWorker`. Requires the Drizzle
194
+ * client (the worker drives `job_run` as the source of truth) AND the
195
+ * resolved BullMQ connection (bound by `JobsDomainModule` when
196
+ * `backend: 'bullmq'`). The queue name is derived identically to the
197
+ * orchestrator's `dispatch` via `resolvePoolQueueName(pool, …)` so producer
198
+ * and consumer agree.
199
+ */
200
+ /**
201
+ * #6 — async + dynamic-import. The `job-worker.bullmq-backend.ts` file is
202
+ * filtered out of the vendor set for drizzle/memory installs (no `bullmq`
203
+ * peer dep needed). The non-literal import specifier makes TS treat the
204
+ * module as `any` so the consumer's tsc never tries to resolve an absent
205
+ * file. This method is only entered when `backend === 'bullmq'` — at which
206
+ * point the file IS vendored.
207
+ */
208
+ async spawnBullMQWorker(pool, _queueAlias, concurrency, poolConfig) {
209
+ if (!this.db) {
210
+ throw new Error(
211
+ `JobWorkerModule: BullMQ worker spawning requires the Drizzle client (no DRIZZLE provider available) \u2014 job_run remains the source of truth.`
212
+ );
213
+ }
214
+ if (!this.bullConnection) {
215
+ throw new Error(
216
+ `JobWorkerModule: BullMQ worker spawning requires a resolved BULLMQ_CONNECTION. Ensure JobsDomainModule was booted with backend: 'bullmq'.`
217
+ );
218
+ }
219
+ if (!this.moduleRef) {
220
+ throw new Error(
221
+ `JobWorkerModule: ModuleRef not available \u2014 cannot construct BullMQJobWorker with handler DI support.`
222
+ );
223
+ }
224
+ const queueName = resolvePoolQueueName(pool, this.bullConfig, poolConfig);
225
+ const specifier = "./job-worker.bullmq-backend";
226
+ const mod = await import(specifier);
227
+ return new mod.BullMQJobWorker(
228
+ this.db,
229
+ this.orchestrator,
230
+ this.stepService,
231
+ {
232
+ pool,
233
+ queueName,
234
+ concurrency,
235
+ connection: this.bullConnection
236
+ },
237
+ this.moduleRef
238
+ );
239
+ }
240
+ };
241
+ JobWorkerOrchestrator = __decorateClass([
242
+ Injectable(),
243
+ __decorateParam(0, Inject(JOB_ORCHESTRATOR)),
244
+ __decorateParam(1, Inject(JOB_RUN_SERVICE)),
245
+ __decorateParam(2, Inject(JOB_STEP_SERVICE)),
246
+ __decorateParam(3, Inject(JOB_WORKER_MODULE_OPTIONS)),
247
+ __decorateParam(4, Optional()),
248
+ __decorateParam(4, Inject(DRIZZLE)),
249
+ __decorateParam(5, Inject(ModuleRef)),
250
+ __decorateParam(6, Optional()),
251
+ __decorateParam(6, Inject(BULLMQ_CONNECTION)),
252
+ __decorateParam(7, Optional()),
253
+ __decorateParam(7, Inject(BULLMQ_RESOLVED_CONFIG))
254
+ ], JobWorkerOrchestrator);
255
+ var JobWorkerModule = class {
256
+ static forRoot(opts) {
257
+ return {
258
+ module: JobWorkerModule,
259
+ imports: [
260
+ JobsDomainModule.forRoot({
261
+ backend: opts.backend ?? "drizzle",
262
+ extensions: opts.domainModuleExtensions,
263
+ multiTenant: opts.multiTenant
264
+ })
265
+ ],
266
+ providers: [
267
+ { provide: JOB_WORKER_MODULE_OPTIONS, useValue: opts },
268
+ JobWorkerOrchestrator
269
+ ],
270
+ // BULLMQ-1 Phase 1 — export the options token so `BridgeModule`'s
271
+ // reserved-pool guard (`onModuleInit`) can actually inject it.
272
+ // Previously `exports: []` left the `@Optional()` inject resolving to
273
+ // `undefined` and the guard silently no-opped (a dead check). With the
274
+ // token exported the guard fires for real; consumers that omit the
275
+ // reserved pools (and don't set `allPools`) now fail fast with
276
+ // `BridgeReservedPoolsNotPolledError` — which is correct.
277
+ exports: [JOB_WORKER_MODULE_OPTIONS]
278
+ };
279
+ }
280
+ };
281
+ JobWorkerModule = __decorateClass([
282
+ Module({})
283
+ ], JobWorkerModule);
284
+
285
+ export {
286
+ JOB_WORKER_MODULE_OPTIONS,
287
+ JobWorkerOrchestrator,
288
+ JobWorkerModule
289
+ };
290
+ //# sourceMappingURL=chunk-4H3PETLM.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../runtime/subsystems/jobs/job-worker.module.ts"],"sourcesContent":["/**\n * JobWorkerModule — `DynamicModule.forRoot({ mode, pools? })` factory that\n * boots one `JobWorker` per active pool and runs the boot-time validator\n * (Drizzle only) (ADR-022, JOB-5).\n *\n * Imports `JobsDomainModule` internally so call sites only need to add\n * `JobWorkerModule.forRoot(...)` to `AppModule.imports` — the protocol\n * tokens become available transitively via `global: true`.\n *\n * Lifecycle (`onModuleInit`, **order-critical** per JOB-5 spec):\n * 1. `loadPoolConfig()` → resolved `PoolConfig`\n * 2. `HandlerRegistry.getAll()` → registered entries\n * 3. Reserved-pool validation → throws `ReservedPoolViolationError`\n * 4. `orchestrator.upsertJobRows(entries, …)` → persist `job` definitions\n * 5. Boot validator (Drizzle only) → throws `BootValidationError`\n * (skipped entirely in memory mode — Q4 resolution 2026-04-19)\n * 6. Spawn one `JobWorker` per active pool → start polling loops\n *\n * `onModuleDestroy` calls `gracefulStop` on each worker (drains in-flight,\n * resets `running` rows, removes SIGTERM handler).\n */\nimport {\n Inject,\n Injectable,\n Logger,\n Module,\n Optional,\n type DynamicModule,\n type OnModuleDestroy,\n type OnModuleInit,\n} from '@nestjs/common';\nimport { ModuleRef } from '@nestjs/core';\nimport { tokenKey } from '../token-key';\nimport { DRIZZLE } from '../../constants/tokens';\nimport type { DrizzleClient } from '../../types/drizzle';\nimport { HandlerRegistry, type HandlerRegistryEntry } from './job-handler.base';\nimport {\n JobsDomainModule,\n type JobsDomainModuleOptions,\n} from './jobs-domain.module';\nimport {\n JOB_ORCHESTRATOR,\n JOB_RUN_SERVICE,\n JOB_STEP_SERVICE,\n} from './jobs-domain.tokens';\nimport type { IJobOrchestrator } from './job-orchestrator.protocol';\nimport type { IJobRunService } from './job-run-service.protocol';\nimport type { IJobStepService } from './job-step-service.protocol';\nimport {\n allNonReservedPoolNames,\n allPoolNames,\n loadPoolConfig,\n type PoolConfig,\n} from './pool-config.loader';\nimport { JobWorker, type JobWorkerOptions } from './job-worker';\n// #6 — `BullMQJobWorker` is lazy-loaded only when `backend: 'bullmq'` is\n// selected (`spawnBullMQWorker` below). The file is filtered out of drizzle/\n// memory installs (see `backendFileFilter`). The `ConnectionOptions` type\n// previously imported from `'bullmq'` is replaced by `BullMqConnectionOptions`\n// from `./bullmq.config` (a self-contained structural mirror that does NOT\n// require the `bullmq` peer dep to type-check).\nimport {\n BULLMQ_CONNECTION,\n BULLMQ_RESOLVED_CONFIG,\n resolvePoolQueueName,\n type BullMqConnectionOptions,\n type BullMqResolvedConfig,\n} from './bullmq.config';\nimport {\n BootValidationError,\n ReservedPoolViolationError,\n} from './jobs-errors';\n\nconst DEFAULT_SHUTDOWN_TIMEOUT_MS = 30_000;\n\nexport interface JobWorkerModuleOptions {\n mode: 'embedded' | 'standalone';\n /**\n * Threads into the internal `JobsDomainModule.forRoot({ backend })`\n * import. Default `'drizzle'`. The boot-time validator runs for both\n * `'drizzle'` and `'bullmq'` (both persist `job` rows to Postgres);\n * `'memory'` skips it.\n */\n backend?: 'drizzle' | 'memory' | 'bullmq';\n /**\n * Active pool names. Defaults to every non-reserved pool in the resolved\n * config (i.e. `interactive`, `batch`, plus any user-defined pools).\n * Operators reduce this to one or two pools per worker process to scale\n * horizontally.\n */\n pools?: string[];\n /**\n * BULLMQ-1 Phase 1 — when `true`, `onModuleInit` activates **every** pool\n * in the resolved config, including the reserved `events_*` lanes. This is\n * how the standalone worker (`worker.ts`) drains bridge wrappers without\n * the consumer hand-listing `...BRIDGE_RESERVED_POOLS`. Mutually exclusive\n * with an explicit `pools` list — when both are set, `pools` wins (explicit\n * beats blanket) and `allPools` is ignored.\n *\n * `BridgeModule`'s reserved-pool guard short-circuits to \"pass\" when this\n * is `true`, since every reserved pool is provably being polled.\n */\n allPools?: boolean;\n /** SIGTERM drain budget. Default 30_000 ms. */\n shutdownTimeoutMs?: number;\n /**\n * Test-only — point the pool config loader at a specific YAML file.\n * Production code reads `${process.cwd()}/codegen.config.yaml`.\n */\n configPath?: string;\n /**\n * Forwarded into the inner `JobsDomainModule.forRoot()` call so the\n * worker module's caller can configure backend extensions in one place.\n */\n domainModuleExtensions?: JobsDomainModuleOptions['extensions'];\n /** Forwarded into `JobsDomainModule.forRoot()`. JOB-8 wires this. */\n multiTenant?: boolean;\n /**\n * Test-only escape hatch — when set, the module uses this factory\n * instead of `new JobWorker(...)` so unit tests can stub the worker\n * without spinning up the polling loop.\n */\n workerFactory?: (options: JobWorkerOptions) => Pick<JobWorker, 'onModuleInit' | 'onModuleDestroy'>;\n}\n\n/**\n * DI token for the resolved `JobWorkerModuleOptions`. Exported so other\n * subsystems can inject it `@Optional()` and inspect the active\n * configuration — e.g. `BridgeModule.onModuleInit` checks\n * `options.pools` against `BRIDGE_RESERVED_POOLS` to fail fast when a\n * reserved pool isn't being polled (BRIDGE-8).\n *\n * ADR-037: namespaced `Symbol.for(...)` (via `tokenKey()`) — matches by value\n * across runtime copies.\n */\nexport const JOB_WORKER_MODULE_OPTIONS = Symbol.for(tokenKey('jobs', 'worker-module-options'));\n\n/**\n * The lifecycle holder. Named `JobWorkerOrchestrator` in the spec to avoid\n * collision with `JobWorker` and `IJobOrchestrator`. Registered as a\n * provider on `JobWorkerModule`; Nest invokes `onModuleInit` /\n * `onModuleDestroy` automatically.\n */\n@Injectable()\nexport class JobWorkerOrchestrator implements OnModuleInit, OnModuleDestroy {\n private readonly logger = new Logger(JobWorkerOrchestrator.name);\n private readonly workers: Array<Pick<JobWorker, 'onModuleInit' | 'onModuleDestroy'>> = [];\n\n constructor(\n @Inject(JOB_ORCHESTRATOR) private readonly orchestrator: IJobOrchestrator,\n @Inject(JOB_RUN_SERVICE) private readonly runService: IJobRunService,\n @Inject(JOB_STEP_SERVICE) private readonly stepService: IJobStepService,\n @Inject(JOB_WORKER_MODULE_OPTIONS)\n private readonly options: JobWorkerModuleOptions,\n /**\n * Drizzle client is only required when `backend === 'drizzle'`. Made\n * `@Optional()` so memory-mode boots in `Test.createTestingModule`\n * without supplying a `DRIZZLE` provider.\n */\n @Optional() @Inject(DRIZZLE) private readonly db: DrizzleClient | null = null,\n /**\n * ADR-037 (package-mode DI): inject `ModuleRef` EXPLICITLY via `@Inject`\n * rather than relying on `design:paramtypes` reflection. The published\n * package bundle is built without `emitDecoratorMetadata` (tsup/esbuild\n * default), so a by-type injection here would resolve to `undefined` at\n * boot in package mode — breaking the worker entirely (the\n * `ModuleRef not available` throw). Vendored mode happened to work only\n * because the consumer's own `tsc` (emitDecoratorMetadata: true)\n * recompiled the source and emitted the metadata. The explicit token is\n * mode-agnostic. `ModuleRef` is always provided by `@nestjs/core`, so no\n * `@Optional()` is needed (it's a hard dependency of the worker path).\n */\n @Inject(ModuleRef) private readonly moduleRef?: ModuleRef,\n /**\n * BULLMQ-1 — resolved BullMQ connection + config, only bound when the\n * inner `JobsDomainModule` was booted with `backend: 'bullmq'`. `@Optional()`\n * so drizzle/memory boots see `null`.\n */\n @Optional()\n @Inject(BULLMQ_CONNECTION)\n private readonly bullConnection: BullMqConnectionOptions | null = null,\n @Optional()\n @Inject(BULLMQ_RESOLVED_CONFIG)\n private readonly bullConfig: BullMqResolvedConfig | null = null,\n ) {}\n\n // ============================================================================\n // Lifecycle\n // ============================================================================\n\n async onModuleInit(): Promise<void> {\n const backend = this.options.backend ?? 'drizzle';\n\n // (1) Pool config first — every later step needs the resolved map.\n const poolConfig = loadPoolConfig(this.options.configPath);\n\n // (2) Snapshot the registry. Decorators run at class-load time so the\n // map is fully populated before any module init fires.\n const entries = HandlerRegistry.getAll();\n\n // (3) Reserved-pool validation BEFORE the upsert. Persisting a\n // reserved-pool handler row would leave the DB in a bad state for\n // the next boot to clean up.\n this.assertNoReservedPoolHandlers(entries, poolConfig);\n\n // (4) Upsert `job` definitions. Drizzle: hash-gated `ON CONFLICT DO\n // UPDATE`. Memory: populates `MemoryJobStore.jobs` + handler-class\n // registry.\n const { orphaned } = await this.orchestrator.upsertJobRows(\n entries,\n poolConfig,\n );\n\n // (5) Boot validator — Drizzle only. Memory mode never has DB rows\n // to validate (Q4 resolution 2026-04-19); the equivalent\n // protection is `MemoryJobOrchestrator.start()` throwing\n // `JobTypeNotFoundError` synchronously for unknown types.\n if (backend !== 'memory' && orphaned.length > 0) {\n throw new BootValidationError(orphaned);\n }\n\n // (6) Resolve active pool list and spawn one worker per pool.\n // Precedence: explicit `pools` > `allPools` (incl. reserved) >\n // non-reserved default. BULLMQ-1 Phase 1 adds the `allPools` rung so\n // the standalone worker drains the reserved `events_*` bridge lanes.\n const activePools = this.options.pools\n ? this.options.pools\n : this.options.allPools\n ? allPoolNames(poolConfig)\n : allNonReservedPoolNames(poolConfig);\n\n for (const poolName of activePools) {\n const def = poolConfig.get(poolName);\n if (!def) {\n throw new Error(\n `JobWorkerModule: active pool '${poolName}' is not defined in ` +\n `the resolved pool config. Configured pools: [${[...poolConfig.keys()].join(', ')}].`,\n );\n }\n // `pool` here is the logical pool name (e.g. 'crm_sync') — the same\n // value the orchestrator persists into `job_run.pool` from\n // `@JobHandler.meta.pool`, and therefore the value the worker's\n // claim query filters on. `def.queue` is a display/routing alias\n // (e.g. 'jobs-crm-sync') used by BullMQ-style backends for queue\n // naming; it MUST NOT be passed as the claim-filter pool, or the\n // worker will never match any row and the pool silently never\n // drains. See v0.4.4 fix notes.\n const workerOptions: JobWorkerOptions = {\n pool: poolName,\n concurrency: def.concurrency,\n shutdownTimeoutMs:\n this.options.shutdownTimeoutMs ?? DEFAULT_SHUTDOWN_TIMEOUT_MS,\n };\n const worker = this.options.workerFactory\n ? this.options.workerFactory(workerOptions)\n : backend === 'bullmq'\n ? await this.spawnBullMQWorker(poolName, def.queue, def.concurrency, poolConfig)\n : this.spawnWorker(workerOptions);\n // `JobWorker` extends Nest's lifecycle hooks but the worker isn't\n // a Nest provider here (we manage the array ourselves). Call\n // `onModuleInit` to start the loop. The Drizzle/stub workers return\n // void; `BullMQJobWorker.onModuleInit` is async (it lazily loads the\n // optional `bullmq` package), so we `await` — awaiting a `void` is a\n // harmless no-op for the synchronous workers.\n await worker.onModuleInit();\n this.workers.push(worker);\n this.logger.log(\n `JobWorker started: pool='${poolName}' (queue='${def.queue}') ` +\n `concurrency=${def.concurrency} backend='${backend}'`,\n );\n }\n }\n\n async onModuleDestroy(): Promise<void> {\n // Tear down in reverse order so the most recently started worker\n // drains first — keeps the SIGTERM handler graph predictable.\n for (let i = this.workers.length - 1; i >= 0; i--) {\n const worker = this.workers[i];\n if (!worker) continue;\n try {\n await worker.onModuleDestroy();\n } catch (err) {\n this.logger.error(\n `JobWorker shutdown failed: ${(err as Error).message}`,\n );\n }\n }\n this.workers.length = 0;\n\n // BULLMQ-1 — close the orchestrator's producer-side Queue/FlowProducer\n // connections so the process can exit cleanly. The orchestrator is the\n // BullMQ producer; workers are the consumers (closed above).\n const orch = this.orchestrator as { closeConnections?: () => Promise<void> };\n if (typeof orch.closeConnections === 'function') {\n try {\n await orch.closeConnections();\n } catch (err) {\n this.logger.error(\n `BullMQ orchestrator connection close failed: ${(err as Error).message}`,\n );\n }\n }\n }\n\n // ============================================================================\n // Internals\n // ============================================================================\n\n /**\n * Walk every registered handler; collect any whose declared `pool`\n * targets a reserved pool from the resolved config. If non-empty,\n * throw `ReservedPoolViolationError` with the offender list so the\n * operator sees every violating class on a single boot.\n */\n private assertNoReservedPoolHandlers(\n entries: HandlerRegistryEntry[],\n poolConfig: PoolConfig,\n ): void {\n const offenders: Array<{ handlerClass: string; pool: string }> = [];\n for (const entry of entries) {\n // Framework-owned handlers (`@framework/*` job types) are allowed in\n // reserved pools — that is in fact the entire point of the reserved\n // `events_*` pools (ADR-022 + ADR-023). The reserved-pool guard\n // exists to keep USER handlers out, not the framework's own\n // bridge-delivery handler. BRIDGE-5 introduced this exemption.\n if (entry.type.startsWith('@framework/')) continue;\n const declaredPool = entry.meta.pool ?? 'batch';\n const def = poolConfig.get(declaredPool);\n if (def?.reserved) {\n offenders.push({\n handlerClass: entry.handlerClass.name,\n pool: declaredPool,\n });\n }\n }\n if (offenders.length > 0) {\n throw new ReservedPoolViolationError(offenders);\n }\n }\n\n /**\n * Production worker spawn. `JobWorker` requires `DRIZZLE` so this only\n * succeeds when the module was booted with `backend: 'drizzle'`. Memory\n * mode tests must supply `workerFactory` — the memory backend has no\n * polling loop equivalent (`MemoryJobOrchestrator` is direct-invocation\n * only).\n *\n * We instantiate outside the Nest container because the module spawns\n * N workers from a single options shape, which doesn't fit Nest's\n * \"one provider per token\" model. The dependencies are passed\n * positionally; the constructor's `@Inject` decorators are unused on\n * this path (Nest still uses them when `JobWorker` is a provider — e.g.\n * in JOB-6's standalone `worker.ts` entrypoint).\n */\n private spawnWorker(workerOptions: JobWorkerOptions): JobWorker {\n if (!this.db) {\n throw new Error(\n `JobWorkerModule: in-process worker spawning requires the Drizzle ` +\n `backend (no DRIZZLE provider available). Memory-mode tests must ` +\n `pass 'workerFactory' to inject a stub.`,\n );\n }\n if (!this.moduleRef) {\n throw new Error(\n `JobWorkerModule: ModuleRef not available — cannot construct JobWorker ` +\n `with handler DI support. Ensure the orchestrator is resolved through ` +\n `the Nest container (not instantiated manually in tests).`,\n );\n }\n return new JobWorker(\n this.db,\n this.orchestrator,\n this.runService,\n this.stepService,\n workerOptions,\n this.moduleRef,\n );\n }\n\n /**\n * BULLMQ-1 — spawn a per-pool `BullMQJobWorker`. Requires the Drizzle\n * client (the worker drives `job_run` as the source of truth) AND the\n * resolved BullMQ connection (bound by `JobsDomainModule` when\n * `backend: 'bullmq'`). The queue name is derived identically to the\n * orchestrator's `dispatch` via `resolvePoolQueueName(pool, …)` so producer\n * and consumer agree.\n */\n /**\n * #6 — async + dynamic-import. The `job-worker.bullmq-backend.ts` file is\n * filtered out of the vendor set for drizzle/memory installs (no `bullmq`\n * peer dep needed). The non-literal import specifier makes TS treat the\n * module as `any` so the consumer's tsc never tries to resolve an absent\n * file. This method is only entered when `backend === 'bullmq'` — at which\n * point the file IS vendored.\n */\n private async spawnBullMQWorker(\n pool: string,\n _queueAlias: string,\n concurrency: number,\n poolConfig: PoolConfig,\n ): Promise<Pick<JobWorker, 'onModuleInit' | 'onModuleDestroy'>> {\n if (!this.db) {\n throw new Error(\n `JobWorkerModule: BullMQ worker spawning requires the Drizzle client ` +\n `(no DRIZZLE provider available) — job_run remains the source of truth.`,\n );\n }\n if (!this.bullConnection) {\n throw new Error(\n `JobWorkerModule: BullMQ worker spawning requires a resolved ` +\n `BULLMQ_CONNECTION. Ensure JobsDomainModule was booted with ` +\n `backend: 'bullmq'.`,\n );\n }\n if (!this.moduleRef) {\n throw new Error(\n `JobWorkerModule: ModuleRef not available — cannot construct ` +\n `BullMQJobWorker with handler DI support.`,\n );\n }\n const queueName = resolvePoolQueueName(pool, this.bullConfig, poolConfig);\n const specifier = './job-worker.bullmq-backend';\n const mod = (await import(specifier)) as {\n BullMQJobWorker: new (...args: unknown[]) => Pick<\n JobWorker,\n 'onModuleInit' | 'onModuleDestroy'\n >;\n };\n return new mod.BullMQJobWorker(\n this.db,\n this.orchestrator,\n this.stepService,\n {\n pool,\n queueName,\n concurrency,\n connection: this.bullConnection,\n },\n this.moduleRef,\n );\n }\n}\n\n@Module({})\nexport class JobWorkerModule {\n static forRoot(opts: JobWorkerModuleOptions): DynamicModule {\n return {\n module: JobWorkerModule,\n imports: [\n JobsDomainModule.forRoot({\n backend: opts.backend ?? 'drizzle',\n extensions: opts.domainModuleExtensions,\n multiTenant: opts.multiTenant,\n }),\n ],\n providers: [\n { provide: JOB_WORKER_MODULE_OPTIONS, useValue: opts },\n JobWorkerOrchestrator,\n ],\n // BULLMQ-1 Phase 1 — export the options token so `BridgeModule`'s\n // reserved-pool guard (`onModuleInit`) can actually inject it.\n // Previously `exports: []` left the `@Optional()` inject resolving to\n // `undefined` and the guard silently no-opped (a dead check). With the\n // token exported the guard fires for real; consumers that omit the\n // reserved pools (and don't set `allPools`) now fail fast with\n // `BridgeReservedPoolsNotPolledError` — which is correct.\n exports: [JOB_WORKER_MODULE_OPTIONS],\n };\n }\n}\n"],"mappings":"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","names":[]}
@@ -0,0 +1,308 @@
1
+ import {
2
+ clampEventLimit,
3
+ decodeEventCursor,
4
+ encodeEventCursor
5
+ } from "./chunk-UQ5EHOH2.js";
6
+ import {
7
+ EVENTS_MODULE_OPTIONS
8
+ } from "./chunk-H5NH7KPE.js";
9
+ import {
10
+ BRIDGE_OUTBOX_DRAIN_HOOK
11
+ } from "./chunk-4LH67P4U.js";
12
+ import {
13
+ domainEvents
14
+ } from "./chunk-OFRRBC7M.js";
15
+ import {
16
+ DRIZZLE
17
+ } from "./chunk-U64T4YZE.js";
18
+ import {
19
+ __decorateClass,
20
+ __decorateParam
21
+ } from "./chunk-2E224ZSN.js";
22
+
23
+ // runtime/subsystems/events/event-bus.drizzle-backend.ts
24
+ import { Injectable, Inject, Logger, Optional } from "@nestjs/common";
25
+ import { eq, and, inArray, asc, desc, gte, lt, or, sql } from "drizzle-orm";
26
+ var POLL_INTERVAL_MS = 1e3;
27
+ var POLL_BATCH_SIZE = 50;
28
+ function toInsertValues(event, multiTenant) {
29
+ const metadata = event.metadata ?? void 0;
30
+ const pool = metadata?.["pool"] ?? null;
31
+ const direction = metadata?.["direction"] ?? null;
32
+ const tier = metadata?.["tier"] ?? "domain";
33
+ const base = {
34
+ id: event.id,
35
+ type: event.type,
36
+ aggregateId: event.aggregateId,
37
+ aggregateType: event.aggregateType,
38
+ payload: event.payload,
39
+ occurredAt: event.occurredAt,
40
+ processedAt: null,
41
+ status: "pending",
42
+ metadata: event.metadata,
43
+ pool,
44
+ direction,
45
+ tier
46
+ };
47
+ if (!multiTenant) return base;
48
+ const tenantId = metadata?.["tenantId"] ?? null;
49
+ return { ...base, tenantId };
50
+ }
51
+ function toEventSummary(r) {
52
+ const metadata = r.metadata ?? void 0;
53
+ const rootRunId = metadata?.["rootRunId"];
54
+ return {
55
+ id: r.id,
56
+ type: r.type,
57
+ aggregateId: r.aggregateId,
58
+ aggregateType: r.aggregateType,
59
+ status: r.status,
60
+ pool: r.pool,
61
+ direction: r.direction,
62
+ tier: r.tier,
63
+ rootRunId: typeof rootRunId === "string" ? rootRunId : null,
64
+ // EVT-8: `tenant_id` is a scaffold-time conditional column. Read it
65
+ // structurally so this projection typechecks against both the
66
+ // multi-tenant schema (column present) and the single-tenant schema
67
+ // (column absent → undefined → null).
68
+ tenantId: r.tenantId ?? null,
69
+ occurredAt: r.occurredAt instanceof Date ? r.occurredAt : new Date(r.occurredAt),
70
+ processedAt: r.processedAt == null ? null : r.processedAt instanceof Date ? r.processedAt : new Date(r.processedAt)
71
+ };
72
+ }
73
+ var DrizzleEventBus = class {
74
+ constructor(db, opts, bridgeHook = null) {
75
+ this.db = db;
76
+ this.bridgeHook = bridgeHook;
77
+ this.opts = opts ?? { backend: "drizzle" };
78
+ }
79
+ db;
80
+ bridgeHook;
81
+ logger = new Logger(DrizzleEventBus.name);
82
+ polling = false;
83
+ pollTimer = null;
84
+ handlers = /* @__PURE__ */ new Map();
85
+ opts;
86
+ // ============================================================================
87
+ // Lifecycle
88
+ // ============================================================================
89
+ async onModuleInit() {
90
+ this.polling = true;
91
+ this.schedulePoll();
92
+ }
93
+ async onModuleDestroy() {
94
+ this.polling = false;
95
+ if (this.pollTimer) {
96
+ clearTimeout(this.pollTimer);
97
+ this.pollTimer = null;
98
+ }
99
+ }
100
+ // ============================================================================
101
+ // IEventBus
102
+ // ============================================================================
103
+ async publish(event, tx) {
104
+ const client = tx ?? this.db;
105
+ const multiTenant = this.opts.multiTenant ?? false;
106
+ await client.insert(domainEvents).values(toInsertValues(event, multiTenant));
107
+ }
108
+ async publishMany(events, tx) {
109
+ if (events.length === 0) return;
110
+ const client = tx ?? this.db;
111
+ const multiTenant = this.opts.multiTenant ?? false;
112
+ await client.insert(domainEvents).values(events.map((e) => toInsertValues(e, multiTenant)));
113
+ }
114
+ async findById(eventId) {
115
+ const rows = await this.db.select().from(domainEvents).where(eq(domainEvents.id, eventId)).limit(1);
116
+ const row = rows[0];
117
+ if (!row) return null;
118
+ return {
119
+ id: row.id,
120
+ type: row.type,
121
+ aggregateId: row.aggregateId,
122
+ aggregateType: row.aggregateType,
123
+ payload: row.payload,
124
+ occurredAt: row.occurredAt instanceof Date ? row.occurredAt : new Date(row.occurredAt),
125
+ metadata: row.metadata ?? void 0
126
+ };
127
+ }
128
+ subscribe(eventType, handler) {
129
+ if (!this.handlers.has(eventType)) {
130
+ this.handlers.set(eventType, /* @__PURE__ */ new Set());
131
+ }
132
+ const set = this.handlers.get(eventType);
133
+ const h = handler;
134
+ set.add(h);
135
+ return () => {
136
+ set.delete(h);
137
+ };
138
+ }
139
+ // ============================================================================
140
+ // IEventReadPort (OBS-LIST-1)
141
+ // ============================================================================
142
+ async listEvents(query = {}) {
143
+ const limit = clampEventLimit(query.limit);
144
+ const conditions = [];
145
+ if (query.poolId) conditions.push(eq(domainEvents.pool, query.poolId));
146
+ if (query.direction)
147
+ conditions.push(eq(domainEvents.direction, query.direction));
148
+ if (query.since) conditions.push(gte(domainEvents.occurredAt, query.since));
149
+ if (query.rootRunId) {
150
+ conditions.push(
151
+ sql`${domainEvents.metadata}->>'rootRunId' = ${query.rootRunId}`
152
+ );
153
+ }
154
+ if (this.opts.multiTenant && query.tenantId !== void 0) {
155
+ const tenantIdColumn = domainEvents.tenantId;
156
+ conditions.push(
157
+ query.tenantId === null ? sql`${tenantIdColumn} is null` : eq(tenantIdColumn, query.tenantId)
158
+ );
159
+ }
160
+ if (query.cursor) {
161
+ const keyset = decodeEventCursor(query.cursor);
162
+ if (keyset) {
163
+ conditions.push(
164
+ or(
165
+ lt(domainEvents.occurredAt, keyset.occurredAt),
166
+ and(
167
+ eq(domainEvents.occurredAt, keyset.occurredAt),
168
+ lt(domainEvents.id, keyset.id)
169
+ )
170
+ )
171
+ );
172
+ }
173
+ }
174
+ const rows = await this.db.select().from(domainEvents).where(conditions.length > 0 ? and(...conditions) : void 0).orderBy(desc(domainEvents.occurredAt), desc(domainEvents.id)).limit(limit + 1);
175
+ const hasMore = rows.length > limit;
176
+ const page = hasMore ? rows.slice(0, limit) : rows;
177
+ const items = page.map(toEventSummary);
178
+ const last = page[page.length - 1];
179
+ const nextCursor = hasMore && last ? encodeEventCursor({ occurredAt: last.occurredAt, id: last.id }) : null;
180
+ return { items, nextCursor };
181
+ }
182
+ // ============================================================================
183
+ // Polling
184
+ // ============================================================================
185
+ /**
186
+ * Test-only hook. Runs exactly one drain cycle and returns. Production
187
+ * code goes through `onModuleInit` → `schedulePoll`, which calls the
188
+ * same `processBatch` under a timer.
189
+ */
190
+ async drainOnce() {
191
+ await this.processBatch();
192
+ }
193
+ schedulePoll() {
194
+ if (!this.polling) return;
195
+ this.pollTimer = setTimeout(async () => {
196
+ try {
197
+ await this.processBatch();
198
+ } catch (err) {
199
+ this.logger.error(`Poll cycle error: ${err}`);
200
+ } finally {
201
+ this.schedulePoll();
202
+ }
203
+ }, POLL_INTERVAL_MS);
204
+ }
205
+ /**
206
+ * Drain one batch (BRIDGE-4 restructure of EVT-4).
207
+ *
208
+ * Two-phase per drained event:
209
+ *
210
+ * 1. **Per-event transaction** — bridge fanout (`bridgeHook.processEvent`)
211
+ * + `processed_at` stamp. Both write through the same `tx`. A throw
212
+ * inside the tx (only infra-level failures should reach here, since
213
+ * the hook tolerates null direction and registry misses inline)
214
+ * rolls back the bridge inserts AND the `processed_at` stamp; the
215
+ * event re-claims on the next drain cycle. Bridge `UNIQUE
216
+ * (event_id, trigger_id)` makes the retry idempotent.
217
+ *
218
+ * 2. **After commit** — dispatch in-process subscribers (`IEventBus.subscribe`
219
+ * handlers). This deliberately runs OUTSIDE the per-event tx (lead
220
+ * decision 2026-04-22): subscribers are best-effort and must not
221
+ * gate forward progress or roll back bridge fanout. Subscriber
222
+ * errors are caught + logged; `processed_at` is already committed.
223
+ * The old `MAX_RETRIES=3` in-process retry loop and the
224
+ * `failed`-stamping path were removed in BRIDGE-4 along with their
225
+ * coupling.
226
+ *
227
+ * The `processed_at` UPDATE carries `AND status='pending'` (BRIDGE-4
228
+ * tightening — without it, a hypothetical double-claim could double-stamp
229
+ * the timestamp). The per-event tx + `FOR UPDATE SKIP LOCKED` claim
230
+ * make this defensive belt-and-suspenders.
231
+ */
232
+ async processBatch() {
233
+ const pools = this.opts.pools;
234
+ const whereClause = pools && pools.length > 0 ? and(eq(domainEvents.status, "pending"), inArray(domainEvents.pool, pools)) : eq(domainEvents.status, "pending");
235
+ const rows = await this.db.transaction(async (tx) => {
236
+ return tx.select().from(domainEvents).where(whereClause).orderBy(asc(domainEvents.occurredAt)).limit(POLL_BATCH_SIZE).for("update", { skipLocked: true });
237
+ });
238
+ for (const row of rows) {
239
+ const event = {
240
+ id: row.id,
241
+ type: row.type,
242
+ aggregateId: row.aggregateId,
243
+ aggregateType: row.aggregateType,
244
+ payload: row.payload,
245
+ occurredAt: row.occurredAt instanceof Date ? row.occurredAt : new Date(row.occurredAt),
246
+ metadata: row.metadata ?? void 0
247
+ };
248
+ try {
249
+ await this.db.transaction(async (tx) => {
250
+ if (this.bridgeHook) {
251
+ await this.bridgeHook.processEvent(event, tx);
252
+ }
253
+ await tx.update(domainEvents).set({ status: "processed", processedAt: /* @__PURE__ */ new Date() }).where(
254
+ and(
255
+ eq(domainEvents.id, event.id),
256
+ eq(domainEvents.status, "pending")
257
+ )
258
+ );
259
+ });
260
+ } catch (err) {
261
+ this.logger.error(
262
+ `Per-event tx failed for event id=${event.id} type=${event.type}: ${err}`
263
+ );
264
+ continue;
265
+ }
266
+ try {
267
+ await this.dispatch(event);
268
+ } catch (err) {
269
+ this.logger.error(
270
+ `Subscriber dispatch failed for event id=${event.id} type=${event.type} (processed_at already committed; failure does not retry): ${err}`
271
+ );
272
+ }
273
+ }
274
+ }
275
+ async dispatch(event) {
276
+ const set = this.handlers.get(event.type);
277
+ if (!set) return;
278
+ let firstError;
279
+ for (const handler of set) {
280
+ try {
281
+ await handler(event);
282
+ } catch (err) {
283
+ this.logger.error(
284
+ `Handler error for event type "${event.type}" (id: ${event.id}): ${err}`
285
+ );
286
+ if (firstError === void 0) {
287
+ firstError = err;
288
+ }
289
+ }
290
+ }
291
+ if (firstError !== void 0) {
292
+ throw firstError;
293
+ }
294
+ }
295
+ };
296
+ DrizzleEventBus = __decorateClass([
297
+ Injectable(),
298
+ __decorateParam(0, Inject(DRIZZLE)),
299
+ __decorateParam(1, Optional()),
300
+ __decorateParam(1, Inject(EVENTS_MODULE_OPTIONS)),
301
+ __decorateParam(2, Optional()),
302
+ __decorateParam(2, Inject(BRIDGE_OUTBOX_DRAIN_HOOK))
303
+ ], DrizzleEventBus);
304
+
305
+ export {
306
+ DrizzleEventBus
307
+ };
308
+ //# sourceMappingURL=chunk-4JLJYWJC.js.map