@pattern-stack/codegen 0.15.1 → 0.15.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 (521) hide show
  1. package/CHANGELOG.md +53 -0
  2. package/dist/chunk-24CWKBK5.js +94 -0
  3. package/dist/chunk-24CWKBK5.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-4JLJYWJC.js +308 -0
  29. package/dist/chunk-4JLJYWJC.js.map +1 -0
  30. package/dist/chunk-4KNXX6TI.js +29 -0
  31. package/dist/chunk-4KNXX6TI.js.map +1 -0
  32. package/dist/chunk-4LH67P4U.js +17 -0
  33. package/dist/chunk-4LH67P4U.js.map +1 -0
  34. package/dist/chunk-4MVGAMUA.js +40 -0
  35. package/dist/chunk-4MVGAMUA.js.map +1 -0
  36. package/dist/chunk-4OMHBMZJ.js +75 -0
  37. package/dist/chunk-4OMHBMZJ.js.map +1 -0
  38. package/dist/chunk-4RFHUZXU.js +635 -0
  39. package/dist/chunk-4RFHUZXU.js.map +1 -0
  40. package/dist/chunk-5A432NZJ.js +7 -0
  41. package/dist/chunk-5A432NZJ.js.map +1 -0
  42. package/dist/chunk-5Y7W3XR6.js +356 -0
  43. package/dist/chunk-5Y7W3XR6.js.map +1 -0
  44. package/dist/chunk-6DWFJNIK.js +15 -0
  45. package/dist/chunk-6DWFJNIK.js.map +1 -0
  46. package/dist/chunk-6I7ULIN6.js +15 -0
  47. package/dist/chunk-6I7ULIN6.js.map +1 -0
  48. package/dist/chunk-6XY6ZMMD.js +25 -0
  49. package/dist/chunk-6XY6ZMMD.js.map +1 -0
  50. package/dist/chunk-7B3RYX45.js +63 -0
  51. package/dist/chunk-7B3RYX45.js.map +1 -0
  52. package/dist/chunk-7C3FOSDI.js +1 -0
  53. package/dist/chunk-7C3FOSDI.js.map +1 -0
  54. package/dist/chunk-7KOW6PU6.js +59 -0
  55. package/dist/chunk-7KOW6PU6.js.map +1 -0
  56. package/dist/chunk-7LKAMLV4.js +92 -0
  57. package/dist/chunk-7LKAMLV4.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-AHV4GDYM.js +63 -0
  61. package/dist/chunk-AHV4GDYM.js.map +1 -0
  62. package/dist/chunk-AQFQ4BYM.js +81 -0
  63. package/dist/chunk-AQFQ4BYM.js.map +1 -0
  64. package/dist/chunk-AS3NAZB6.js +14 -0
  65. package/dist/chunk-AS3NAZB6.js.map +1 -0
  66. package/dist/chunk-BGULBWKJ.js +88 -0
  67. package/dist/chunk-BGULBWKJ.js.map +1 -0
  68. package/dist/chunk-BIO6F7YI.js +17 -0
  69. package/dist/chunk-BIO6F7YI.js.map +1 -0
  70. package/dist/chunk-BOPZWRJK.js +36 -0
  71. package/dist/chunk-BOPZWRJK.js.map +1 -0
  72. package/dist/chunk-BPARRK6F.js +14 -0
  73. package/dist/chunk-BPARRK6F.js.map +1 -0
  74. package/dist/chunk-CO6LUM72.js +59 -0
  75. package/dist/chunk-CO6LUM72.js.map +1 -0
  76. package/dist/chunk-COGHTKXY.js +84 -0
  77. package/dist/chunk-COGHTKXY.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-DKKFTHHI.js +53 -0
  81. package/dist/chunk-DKKFTHHI.js.map +1 -0
  82. package/dist/chunk-DV4RV2DC.js +59 -0
  83. package/dist/chunk-DV4RV2DC.js.map +1 -0
  84. package/dist/chunk-EDKJU5BO.js +11 -0
  85. package/dist/chunk-EDKJU5BO.js.map +1 -0
  86. package/dist/chunk-EO2QPOKH.js +116 -0
  87. package/dist/chunk-EO2QPOKH.js.map +1 -0
  88. package/dist/chunk-EOLLMEAH.js +155 -0
  89. package/dist/chunk-EOLLMEAH.js.map +1 -0
  90. package/dist/chunk-EWYCWP4H.js +14 -0
  91. package/dist/chunk-EWYCWP4H.js.map +1 -0
  92. package/dist/chunk-EXVDJMIY.js +33 -0
  93. package/dist/chunk-EXVDJMIY.js.map +1 -0
  94. package/dist/chunk-FASRXRX5.js +19 -0
  95. package/dist/chunk-FASRXRX5.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-GM3RMJIJ.js +92 -0
  101. package/dist/chunk-GM3RMJIJ.js.map +1 -0
  102. package/dist/chunk-GYGNEQSC.js +9 -0
  103. package/dist/chunk-GYGNEQSC.js.map +1 -0
  104. package/dist/chunk-H5NH7KPE.js +21 -0
  105. package/dist/chunk-H5NH7KPE.js.map +1 -0
  106. package/dist/chunk-HNWZFNKP.js +168 -0
  107. package/dist/chunk-HNWZFNKP.js.map +1 -0
  108. package/dist/chunk-HUH73XGI.js +1 -0
  109. package/dist/chunk-HUH73XGI.js.map +1 -0
  110. package/dist/chunk-I6MG4M3F.js +201 -0
  111. package/dist/chunk-I6MG4M3F.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-J37YWU7Y.js +19 -0
  123. package/dist/chunk-J37YWU7Y.js.map +1 -0
  124. package/dist/chunk-J6KZS54B.js +269 -0
  125. package/dist/chunk-J6KZS54B.js.map +1 -0
  126. package/dist/chunk-J6MN42LG.js +19 -0
  127. package/dist/chunk-J6MN42LG.js.map +1 -0
  128. package/dist/chunk-JRQO2IOF.js +65 -0
  129. package/dist/chunk-JRQO2IOF.js.map +1 -0
  130. package/dist/chunk-JRVNVKN6.js +212 -0
  131. package/dist/chunk-JRVNVKN6.js.map +1 -0
  132. package/dist/chunk-JWNHNUYL.js +96 -0
  133. package/dist/chunk-JWNHNUYL.js.map +1 -0
  134. package/dist/chunk-K2I6XIK5.js +122 -0
  135. package/dist/chunk-K2I6XIK5.js.map +1 -0
  136. package/dist/chunk-KMZCQASO.js +111 -0
  137. package/dist/chunk-KMZCQASO.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-OFRRBC7M.js +78 -0
  167. package/dist/chunk-OFRRBC7M.js.map +1 -0
  168. package/dist/chunk-OGIZXGPY.js +222 -0
  169. package/dist/chunk-OGIZXGPY.js.map +1 -0
  170. package/dist/chunk-OKXZ63IA.js +168 -0
  171. package/dist/chunk-OKXZ63IA.js.map +1 -0
  172. package/dist/chunk-OSQRXVG2.js +58 -0
  173. package/dist/chunk-OSQRXVG2.js.map +1 -0
  174. package/dist/chunk-OTDN3OUQ.js +215 -0
  175. package/dist/chunk-OTDN3OUQ.js.map +1 -0
  176. package/dist/chunk-OZZJDRGW.js +122 -0
  177. package/dist/chunk-OZZJDRGW.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-RFH7N6EP.js +36 -0
  189. package/dist/chunk-RFH7N6EP.js.map +1 -0
  190. package/dist/chunk-RHVN6NA7.js +134 -0
  191. package/dist/chunk-RHVN6NA7.js.map +1 -0
  192. package/dist/chunk-S7C6TIIF.js +21 -0
  193. package/dist/chunk-S7C6TIIF.js.map +1 -0
  194. package/dist/chunk-SNQ3TOWP.js +20 -0
  195. package/dist/chunk-SNQ3TOWP.js.map +1 -0
  196. package/dist/chunk-SOVM2VEK.js +14 -0
  197. package/dist/chunk-SOVM2VEK.js.map +1 -0
  198. package/dist/chunk-SQDOBLBP.js +13 -0
  199. package/dist/chunk-SQDOBLBP.js.map +1 -0
  200. package/dist/chunk-SR7F3TJY.js +130 -0
  201. package/dist/chunk-SR7F3TJY.js.map +1 -0
  202. package/dist/chunk-SZVPIHWE.js +129 -0
  203. package/dist/chunk-SZVPIHWE.js.map +1 -0
  204. package/dist/chunk-T4BIIU5E.js +89 -0
  205. package/dist/chunk-T4BIIU5E.js.map +1 -0
  206. package/dist/chunk-T6C4LFLC.js +112 -0
  207. package/dist/chunk-T6C4LFLC.js.map +1 -0
  208. package/dist/chunk-TNXH7BJS.js +48 -0
  209. package/dist/chunk-TNXH7BJS.js.map +1 -0
  210. package/dist/chunk-U64T4YZE.js +9 -0
  211. package/dist/chunk-U64T4YZE.js.map +1 -0
  212. package/dist/chunk-UQ5EHOH2.js +39 -0
  213. package/dist/chunk-UQ5EHOH2.js.map +1 -0
  214. package/dist/chunk-UTN4GBPQ.js +1 -0
  215. package/dist/chunk-UTN4GBPQ.js.map +1 -0
  216. package/dist/chunk-V4AF6DI4.js +16 -0
  217. package/dist/chunk-V4AF6DI4.js.map +1 -0
  218. package/dist/chunk-W72PRNJY.js +126 -0
  219. package/dist/chunk-W72PRNJY.js.map +1 -0
  220. package/dist/chunk-WEVWJKOW.js +81 -0
  221. package/dist/chunk-WEVWJKOW.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-WPXNN6QS.js +290 -0
  225. package/dist/chunk-WPXNN6QS.js.map +1 -0
  226. package/dist/chunk-WRUUSZDJ.js +29 -0
  227. package/dist/chunk-WRUUSZDJ.js.map +1 -0
  228. package/dist/chunk-X2GMTYPA.js +50 -0
  229. package/dist/chunk-X2GMTYPA.js.map +1 -0
  230. package/dist/chunk-XCEI7NUH.js +41 -0
  231. package/dist/chunk-XCEI7NUH.js.map +1 -0
  232. package/dist/chunk-Y7GDG744.js +88 -0
  233. package/dist/chunk-Y7GDG744.js.map +1 -0
  234. package/dist/chunk-Y7RRSEOC.js +9 -0
  235. package/dist/chunk-Y7RRSEOC.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.js +171 -5912
  406. package/dist/runtime/subsystems/index.js.map +1 -1
  407. package/dist/runtime/subsystems/integration/build-change-source.js +6 -178
  408. package/dist/runtime/subsystems/integration/build-change-source.js.map +1 -1
  409. package/dist/runtime/subsystems/integration/deep-equal.differ.js +4 -109
  410. package/dist/runtime/subsystems/integration/deep-equal.differ.js.map +1 -1
  411. package/dist/runtime/subsystems/integration/detection-config.schema.js +11 -78
  412. package/dist/runtime/subsystems/integration/detection-config.schema.js.map +1 -1
  413. package/dist/runtime/subsystems/integration/entity-change-source-registry.memory.js +5 -30
  414. package/dist/runtime/subsystems/integration/entity-change-source-registry.memory.js.map +1 -1
  415. package/dist/runtime/subsystems/integration/entity-change-source-registry.protocol.js +4 -9
  416. package/dist/runtime/subsystems/integration/entity-change-source-registry.protocol.js.map +1 -1
  417. package/dist/runtime/subsystems/integration/execute-integration.use-case.js +6 -239
  418. package/dist/runtime/subsystems/integration/execute-integration.use-case.js.map +1 -1
  419. package/dist/runtime/subsystems/integration/incremental-read.js +5 -144
  420. package/dist/runtime/subsystems/integration/incremental-read.js.map +1 -1
  421. package/dist/runtime/subsystems/integration/index.js +83 -1352
  422. package/dist/runtime/subsystems/integration/index.js.map +1 -1
  423. package/dist/runtime/subsystems/integration/integration-audit.schema.js +10 -155
  424. package/dist/runtime/subsystems/integration/integration-audit.schema.js.map +1 -1
  425. package/dist/runtime/subsystems/integration/integration-cursor-store.drizzle-backend.js +7 -270
  426. package/dist/runtime/subsystems/integration/integration-cursor-store.drizzle-backend.js.map +1 -1
  427. package/dist/runtime/subsystems/integration/integration-cursor-store.memory-backend.js +4 -65
  428. package/dist/runtime/subsystems/integration/integration-cursor-store.memory-backend.js.map +1 -1
  429. package/dist/runtime/subsystems/integration/integration-errors.js +5 -15
  430. package/dist/runtime/subsystems/integration/integration-errors.js.map +1 -1
  431. package/dist/runtime/subsystems/integration/integration-field-diff.protocol.js +5 -7
  432. package/dist/runtime/subsystems/integration/integration-field-diff.protocol.js.map +1 -1
  433. package/dist/runtime/subsystems/integration/integration-run-recorder.drizzle-backend.js +8 -303
  434. package/dist/runtime/subsystems/integration/integration-run-recorder.drizzle-backend.js.map +1 -1
  435. package/dist/runtime/subsystems/integration/integration-run-recorder.memory-backend.js +5 -125
  436. package/dist/runtime/subsystems/integration/integration-run-recorder.memory-backend.js.map +1 -1
  437. package/dist/runtime/subsystems/integration/integration.module.js +13 -700
  438. package/dist/runtime/subsystems/integration/integration.module.js.map +1 -1
  439. package/dist/runtime/subsystems/integration/integration.tokens.js +11 -9
  440. package/dist/runtime/subsystems/integration/integration.tokens.js.map +1 -1
  441. package/dist/runtime/subsystems/integration/loopback.middleware.js +4 -16
  442. package/dist/runtime/subsystems/integration/loopback.middleware.js.map +1 -1
  443. package/dist/runtime/subsystems/integration/poll-change-source.js +4 -89
  444. package/dist/runtime/subsystems/integration/poll-change-source.js.map +1 -1
  445. package/dist/runtime/subsystems/integration/webhook-change-source.js +4 -70
  446. package/dist/runtime/subsystems/integration/webhook-change-source.js.map +1 -1
  447. package/dist/runtime/subsystems/jobs/bullmq.config.js +9 -140
  448. package/dist/runtime/subsystems/jobs/bullmq.config.js.map +1 -1
  449. package/dist/runtime/subsystems/jobs/index.js +88 -2691
  450. package/dist/runtime/subsystems/jobs/index.js.map +1 -1
  451. package/dist/runtime/subsystems/jobs/job-handler.base.js +10 -49
  452. package/dist/runtime/subsystems/jobs/job-handler.base.js.map +1 -1
  453. package/dist/runtime/subsystems/jobs/job-orchestration.schema.js +13 -152
  454. package/dist/runtime/subsystems/jobs/job-orchestration.schema.js.map +1 -1
  455. package/dist/runtime/subsystems/jobs/job-orchestrator.bullmq-backend.js +36 -699
  456. package/dist/runtime/subsystems/jobs/job-orchestrator.bullmq-backend.js.map +1 -1
  457. package/dist/runtime/subsystems/jobs/job-orchestrator.drizzle-backend.js +10 -564
  458. package/dist/runtime/subsystems/jobs/job-orchestrator.drizzle-backend.js.map +1 -1
  459. package/dist/runtime/subsystems/jobs/job-orchestrator.memory-backend.js +10 -824
  460. package/dist/runtime/subsystems/jobs/job-orchestrator.memory-backend.js.map +1 -1
  461. package/dist/runtime/subsystems/jobs/job-run-keyset-cursor.js +9 -51
  462. package/dist/runtime/subsystems/jobs/job-run-keyset-cursor.js.map +1 -1
  463. package/dist/runtime/subsystems/jobs/job-run-service.drizzle-backend.js +9 -416
  464. package/dist/runtime/subsystems/jobs/job-run-service.drizzle-backend.js.map +1 -1
  465. package/dist/runtime/subsystems/jobs/job-run-service.memory-backend.js +9 -290
  466. package/dist/runtime/subsystems/jobs/job-run-service.memory-backend.js.map +1 -1
  467. package/dist/runtime/subsystems/jobs/job-step-service.drizzle-backend.js +5 -213
  468. package/dist/runtime/subsystems/jobs/job-step-service.drizzle-backend.js.map +1 -1
  469. package/dist/runtime/subsystems/jobs/job-step-service.memory-backend.js +5 -131
  470. package/dist/runtime/subsystems/jobs/job-step-service.memory-backend.js.map +1 -1
  471. package/dist/runtime/subsystems/jobs/job-worker.bullmq-backend.js +9 -175
  472. package/dist/runtime/subsystems/jobs/job-worker.bullmq-backend.js.map +1 -1
  473. package/dist/runtime/subsystems/jobs/job-worker.js +14 -613
  474. package/dist/runtime/subsystems/jobs/job-worker.js.map +1 -1
  475. package/dist/runtime/subsystems/jobs/job-worker.module.js +23 -2647
  476. package/dist/runtime/subsystems/jobs/job-worker.module.js.map +1 -1
  477. package/dist/runtime/subsystems/jobs/jobs-domain.module.js +19 -1897
  478. package/dist/runtime/subsystems/jobs/jobs-domain.module.js.map +1 -1
  479. package/dist/runtime/subsystems/jobs/jobs-domain.tokens.js +8 -9
  480. package/dist/runtime/subsystems/jobs/jobs-domain.tokens.js.map +1 -1
  481. package/dist/runtime/subsystems/jobs/jobs-errors.js +10 -78
  482. package/dist/runtime/subsystems/jobs/jobs-errors.js.map +1 -1
  483. package/dist/runtime/subsystems/jobs/memory-job-store.js +4 -15
  484. package/dist/runtime/subsystems/jobs/memory-job-store.js.map +1 -1
  485. package/dist/runtime/subsystems/jobs/pool-config.loader.js +9 -124
  486. package/dist/runtime/subsystems/jobs/pool-config.loader.js.map +1 -1
  487. package/dist/runtime/subsystems/observability/index.js +21 -310
  488. package/dist/runtime/subsystems/observability/index.js.map +1 -1
  489. package/dist/runtime/subsystems/observability/observability-errors.js +4 -9
  490. package/dist/runtime/subsystems/observability/observability-errors.js.map +1 -1
  491. package/dist/runtime/subsystems/observability/observability.module.js +11 -300
  492. package/dist/runtime/subsystems/observability/observability.module.js.map +1 -1
  493. package/dist/runtime/subsystems/observability/observability.service.js +9 -197
  494. package/dist/runtime/subsystems/observability/observability.service.js.map +1 -1
  495. package/dist/runtime/subsystems/observability/observability.tokens.js +5 -3
  496. package/dist/runtime/subsystems/observability/observability.tokens.js.map +1 -1
  497. package/dist/runtime/subsystems/observability/reporters/bridge-metrics.reporter.js +4 -84
  498. package/dist/runtime/subsystems/observability/reporters/bridge-metrics.reporter.js.map +1 -1
  499. package/dist/runtime/subsystems/observability/reporters/index.js +5 -84
  500. package/dist/runtime/subsystems/observability/reporters/index.js.map +1 -1
  501. package/dist/runtime/subsystems/storage/index.js +15 -200
  502. package/dist/runtime/subsystems/storage/index.js.map +1 -1
  503. package/dist/runtime/subsystems/storage/storage.local-backend.js +4 -103
  504. package/dist/runtime/subsystems/storage/storage.local-backend.js.map +1 -1
  505. package/dist/runtime/subsystems/storage/storage.memory-backend.js +5 -68
  506. package/dist/runtime/subsystems/storage/storage.memory-backend.js.map +1 -1
  507. package/dist/runtime/subsystems/storage/storage.module.js +8 -200
  508. package/dist/runtime/subsystems/storage/storage.module.js.map +1 -1
  509. package/dist/runtime/subsystems/storage/storage.tokens.js +5 -6
  510. package/dist/runtime/subsystems/storage/storage.tokens.js.map +1 -1
  511. package/dist/runtime/subsystems/storage/storage.utils.js +4 -14
  512. package/dist/runtime/subsystems/storage/storage.utils.js.map +1 -1
  513. package/dist/runtime/subsystems/token-key.js +5 -3
  514. package/dist/runtime/subsystems/token-key.js.map +1 -1
  515. package/dist/src/cli/index.js +637 -5454
  516. package/dist/src/cli/index.js.map +1 -1
  517. package/dist/src/index.js +68 -4170
  518. package/dist/src/index.js.map +1 -1
  519. package/package.json +1 -1
  520. package/runtime/subsystems/bridge/bridge-outbox-drain-hook.ts +44 -21
  521. package/runtime/subsystems/jobs/job-worker.ts +17 -11
@@ -1,1079 +1,62 @@
1
- // runtime/base-classes/base-repository.ts
2
- import { and, eq, inArray, isNull, sql } from "drizzle-orm";
3
-
4
- // runtime/base-classes/tenant-context.ts
5
- import { AsyncLocalStorage } from "async_hooks";
6
- var als = new AsyncLocalStorage();
7
- function withRequester(ctx, fn) {
8
- return als.run(ctx, fn);
9
- }
10
- function requireRequester() {
11
- const ctx = als.getStore();
12
- if (!ctx) {
13
- throw new Error(
14
- "No requester context active. Wrap the entry point in withRequester({ userId, organizationId }, fn). See tenant-context.ts."
15
- );
16
- }
17
- return ctx;
18
- }
19
- function tryGetRequester() {
20
- return als.getStore();
21
- }
22
- function requireRequesterScope() {
23
- return requireRequester().scope ?? "user";
24
- }
25
- function withUserScope(userId, organizationId, fn) {
26
- return withRequester({ userId, organizationId, scope: "user" }, fn);
27
- }
28
- function withOrgScope(userId, organizationId, orgUserIds, fn) {
29
- return withRequester(
30
- { userId, organizationId, scope: "org", orgUserIds },
31
- fn
32
- );
33
- }
34
- function withSuperuserScope(userId, fn) {
35
- return withRequester(
36
- { userId, organizationId: null, scope: "superuser" },
37
- fn
38
- );
39
- }
40
-
41
- // runtime/base-classes/base-repository.ts
42
- var BaseRepository = class {
43
- // eslint-disable-line @typescript-eslint/no-explicit-any
44
- /**
45
- * Behavior flags controlling automatic behavior injection.
46
- * Override in concrete repositories to enable behaviors.
47
- */
48
- behaviors = {
49
- timestamps: false,
50
- softDelete: false,
51
- userTracking: false
52
- };
53
- /**
54
- * Ambient tenant-scope enforcement for `userTracking` repos (see
55
- * `scopePredicate`). Only has effect when `behaviors.userTracking === true`.
56
- *
57
- * - `'lenient'` (default): when no ambient requester context is active,
58
- * reads/writes are NOT scoped — preserves pre-scoping behavior, so adopting
59
- * ambient scoping is additive. Scoping kicks in automatically once a
60
- * boundary installs `withRequester(...)`.
61
- * - `'strict'`: a missing ambient context throws (`requireRequester`),
62
- * making a forgotten boundary fail loud instead of silently returning
63
- * cross-tenant rows. Recommended for new multi-tenant consumers — override
64
- * in a concrete repo or a family base class.
65
- */
66
- scopeEnforcement = "lenient";
67
- db;
68
- constructor(db) {
69
- this.db = db;
70
- }
71
- /**
72
- * Pick the runner for a write: the caller-supplied transaction handle
73
- * if present, otherwise the repository's own client. Keeps the `tx`
74
- * parameter purely additive — callers without a transaction call as
75
- * before. Used by the write methods below + consumer overrides (e.g.
76
- * the generated `upsertCurrentValues` on EAV value tables).
77
- */
78
- runner(tx) {
79
- return tx ?? this.db;
80
- }
81
- // ============================================================================
82
- // Read Operations
83
- // ============================================================================
84
- /**
85
- * Find a single entity by its primary key.
86
- * Returns null if not found (or soft-deleted when softDelete=true).
87
- */
88
- async findById(id) {
89
- const rows = await this.baseQuery(eq(this.table["id"], id)).limit(1);
90
- return rows[0] ?? null;
91
- }
92
- /**
93
- * Find multiple entities by their primary keys.
94
- * Returns empty array immediately for empty input (avoids DB errors).
95
- */
96
- async findByIds(ids) {
97
- if (ids.length === 0) return [];
98
- const rows = await this.baseQuery(inArray(this.table["id"], ids));
99
- return rows;
100
- }
101
- /**
102
- * List entities with optional filtering, pagination, and ordering.
103
- */
104
- async list(options) {
105
- let query = this.baseQuery(options?.where);
106
- if (options?.orderBy) {
107
- query = query.orderBy(options.orderBy);
108
- }
109
- if (options?.limit !== void 0) {
110
- query = query.limit(options.limit);
111
- }
112
- if (options?.offset !== void 0) {
113
- query = query.offset(options.offset);
114
- }
115
- const rows = await query;
116
- return rows;
117
- }
118
- /**
119
- * Count entities matching an optional WHERE clause.
120
- * Soft-deleted rows are always excluded when softDelete=true.
121
- */
122
- async count(where) {
123
- let query = this.db.select({ count: sql`cast(count(*) as integer)` }).from(this.table);
124
- const conditions = [];
125
- if (this.behaviors.softDelete) {
126
- conditions.push(isNull(this.table["deletedAt"]));
127
- }
128
- const scope = this.scopePredicate();
129
- if (scope) {
130
- conditions.push(scope);
131
- }
132
- if (where) {
133
- conditions.push(where);
134
- }
135
- if (conditions.length === 1) {
136
- query = query.where(conditions[0]);
137
- } else if (conditions.length > 1) {
138
- query = query.where(and(...conditions));
139
- }
140
- const rows = await query;
141
- return rows[0]?.count ?? 0;
142
- }
143
- /**
144
- * Check whether an entity with the given id exists.
145
- */
146
- async exists(id) {
147
- const result = await this.findById(id);
148
- return result !== null;
149
- }
150
- // ============================================================================
151
- // Write Operations
152
- // ============================================================================
153
- /**
154
- * Insert a new entity. Timestamps are auto-injected when timestamps=true.
155
- */
156
- async create(input, tx) {
157
- const data = this.withTimestamps(input, "create");
158
- const rows = await this.runner(tx).insert(this.table).values(data).returning();
159
- return rows[0];
160
- }
161
- /**
162
- * Update an existing entity by id. updatedAt is auto-injected when timestamps=true.
163
- * Returns the updated entity.
164
- */
165
- async update(id, input, tx) {
166
- const data = this.withTimestamps(input, "update");
167
- const rows = await this.runner(tx).update(this.table).set(data).where(this.scopeAnd(eq(this.table["id"], id))).returning();
168
- return rows[0];
169
- }
170
- /**
171
- * Delete an entity by id.
172
- * - softDelete=true: sets deletedAt to current timestamp
173
- * - softDelete=false: hard-deletes the row
174
- */
175
- async delete(id, tx) {
176
- const runner = this.runner(tx);
177
- if (this.behaviors.softDelete) {
178
- await runner.update(this.table).set({ deletedAt: /* @__PURE__ */ new Date() }).where(this.scopeAnd(eq(this.table["id"], id)));
179
- } else {
180
- await runner.delete(this.table).where(this.scopeAnd(eq(this.table["id"], id)));
181
- }
182
- }
183
- /**
184
- * Insert or update multiple entities.
185
- * Default naive implementation — family repositories override with
186
- * proper conflict-target upsert (e.g., CrmEntityRepository).
187
- */
188
- async upsertMany(inputs, tx) {
189
- return Promise.all(inputs.map((input) => this.create(input, tx)));
190
- }
191
- // ============================================================================
192
- // Protected Helpers
193
- // ============================================================================
194
- /**
195
- * Base SELECT query that automatically applies the ambient guards —
196
- * soft-delete exclusion (when `softDelete`) and tenant scope (when
197
- * `userTracking` + an active requester context) — combined with an optional
198
- * caller `extra` predicate into a SINGLE `WHERE`.
199
- *
200
- * Pass the leaf predicate as `extra` rather than chaining a second
201
- * `.where(...)`: Drizzle's `.where()` OVERRIDES (does not AND) a prior
202
- * `.where()` on a `$dynamic()` query, so a chained call would silently drop
203
- * the soft-delete and scope guards. `baseQuery(extra)` is the safe form.
204
- */
205
- baseQuery(extra) {
206
- const query = this.db.select().from(this.table).$dynamic();
207
- const where = this.scopeAnd(extra, { softDelete: this.behaviors.softDelete });
208
- return where ? query.where(where) : query;
209
- }
210
- /**
211
- * Build the ambient tenant-scope predicate for this repo's table.
212
- *
213
- * Returns `undefined` (no scoping) when:
214
- * - `behaviors.userTracking` is false (repo is not user-owned), or
215
- * - no ambient requester context is active AND `scopeEnforcement` is
216
- * `'lenient'` (the default — preserves pre-scoping behavior).
217
- *
218
- * When a requester context is active, scopes by `user_id` per the ambient
219
- * scope: `'user'` → `user_id = ctx.userId`; `'org'` → `user_id IN
220
- * ctx.orgUserIds` (empty list matches nothing — fail-closed); `'superuser'`
221
- * → no filter. See `tenant-context.ts` for the boundary-install contract.
222
- */
223
- scopePredicate() {
224
- if (!this.behaviors.userTracking) return void 0;
225
- const ctx = this.scopeEnforcement === "strict" ? requireRequester() : tryGetRequester();
226
- if (!ctx) return void 0;
227
- const scope = ctx.scope ?? "user";
228
- switch (scope) {
229
- case "superuser":
230
- return void 0;
231
- case "org":
232
- return ctx.orgUserIds && ctx.orgUserIds.length > 0 ? inArray(this.table["userId"], ctx.orgUserIds) : sql`false`;
233
- case "user":
234
- default:
235
- return eq(this.table["userId"], ctx.userId);
236
- }
237
- }
238
- /**
239
- * Combine the ambient scope predicate (and, optionally, the soft-delete
240
- * guard) with a caller `extra` predicate into one `SQL`. Returns `undefined`
241
- * when nothing applies. Used by read + by-id write paths so a single
242
- * `.where(...)` carries every guard.
243
- */
244
- scopeAnd(extra, opts) {
245
- const conditions = [];
246
- if (opts?.softDelete) conditions.push(isNull(this.table["deletedAt"]));
247
- const scope = this.scopePredicate();
248
- if (scope) conditions.push(scope);
249
- if (extra) conditions.push(extra);
250
- if (conditions.length === 0) return void 0;
251
- if (conditions.length === 1) return conditions[0];
252
- return and(...conditions);
253
- }
254
- /**
255
- * Merge timestamp fields into an input object.
256
- * - mode='create': adds createdAt and updatedAt
257
- * - mode='update': adds updatedAt only
258
- *
259
- * No-op when timestamps behavior is disabled.
260
- */
261
- withTimestamps(input, mode) {
262
- if (!this.behaviors.timestamps) return input;
263
- const now = /* @__PURE__ */ new Date();
264
- if (mode === "create") {
265
- return { ...input, createdAt: now, updatedAt: now };
266
- }
267
- return { ...input, updatedAt: now };
268
- }
269
- /**
270
- * Build a WHERE clause fragment that restricts results to rows whose
271
- * parent (identified by a belongs_to FK) is not soft-deleted.
272
- *
273
- * Use this in custom repository methods when you need "rows reachable
274
- * from an active parent". The default findAll / findById behavior is
275
- * NOT changed by this helper — opt in explicitly where needed.
276
- *
277
- * ADR-021 — Soft-delete cascade: Option A (filter at query time).
278
- * `on_delete` FK rules do not fire for soft-deletes; use this helper
279
- * instead of expecting cascade semantics on the DB level.
280
- *
281
- * Example:
282
- * async listActiveMessages(): Promise<Message[]> {
283
- * return this.list({
284
- * where: this.activeParentFilter(conversations, this.table['conversationId']),
285
- * });
286
- * }
287
- *
288
- * @param parentTable The Drizzle table object for the parent entity.
289
- * @param parentFkColumn The FK column on this (child) table that references parent.id.
290
- */
291
- activeParentFilter(parentTable, parentFkColumn) {
292
- return sql`EXISTS (
293
- SELECT 1 FROM ${parentTable} p
294
- WHERE p.id = ${parentFkColumn}
295
- AND p.deleted_at IS NULL
296
- )`;
297
- }
298
- };
299
-
300
- // runtime/base-classes/lifecycle-events.ts
301
- import { randomUUID } from "crypto";
302
- var SYSTEM_FIELDS = /* @__PURE__ */ new Set([
303
- "id",
304
- "createdAt",
305
- "updatedAt",
306
- "deletedAt"
307
- ]);
308
- function entitySnapshot(entity) {
309
- const snap = {};
310
- for (const [key, value] of Object.entries(entity)) {
311
- if (!SYSTEM_FIELDS.has(key)) {
312
- snap[key] = value;
313
- }
314
- }
315
- return snap;
316
- }
317
- function diffSnapshots(before, after) {
318
- const changes = [];
319
- const allKeys = /* @__PURE__ */ new Set([...Object.keys(before), ...Object.keys(after)]);
320
- for (const key of allKeys) {
321
- if (SYSTEM_FIELDS.has(key)) continue;
322
- const oldVal = before[key];
323
- const newVal = after[key];
324
- if (oldVal !== newVal && JSON.stringify(oldVal) !== JSON.stringify(newVal)) {
325
- changes.push({ field: key, oldValue: oldVal, newValue: newVal });
326
- }
327
- }
328
- return changes;
329
- }
330
- function buildLifecycleEvent(entityName, action, entityId, snapshot) {
331
- return {
332
- id: randomUUID(),
333
- type: `${entityName}.${action}`,
334
- aggregateId: entityId,
335
- aggregateType: entityName,
336
- payload: snapshot ? { snapshot } : {},
337
- occurredAt: /* @__PURE__ */ new Date(),
338
- metadata: { category: "lifecycle" }
339
- };
340
- }
341
- function buildChangeEvents(entityName, entityId, changes) {
342
- return changes.map((c) => ({
343
- id: randomUUID(),
344
- type: `${entityName}.field_changed`,
345
- aggregateId: entityId,
346
- aggregateType: entityName,
347
- payload: {
348
- fieldName: c.field,
349
- oldValue: c.oldValue,
350
- newValue: c.newValue
351
- },
352
- occurredAt: /* @__PURE__ */ new Date(),
353
- metadata: { category: "change" }
354
- }));
355
- }
356
- async function emitSafely(eventBus, events) {
357
- if (!eventBus || events.length === 0) return;
358
- try {
359
- if (events.length === 1) {
360
- const only = events[0];
361
- if (!only) return;
362
- await eventBus.publish(only);
363
- } else {
364
- await eventBus.publishMany(events);
365
- }
366
- } catch {
367
- console.warn(`[lifecycle-events] failed to emit ${events.length} event(s)`);
368
- }
369
- }
370
-
371
- // runtime/base-classes/base-service.ts
372
- var BaseService = class {
373
- constructor(repository) {
374
- this.repository = repository;
375
- }
376
- repository;
377
- /**
378
- * Entity name for event types (e.g., 'account' → 'account.created').
379
- * Set by generated services. If empty, lifecycle events are skipped.
380
- */
381
- entityName;
382
- /**
383
- * Event bus for lifecycle/change event emission.
384
- * Injected via @Inject(EVENT_BUS) @Optional() on generated services.
385
- * If undefined (no events subsystem installed), emission is silently skipped.
386
- */
387
- eventBus;
388
- /**
389
- * Whether to emit lifecycle events. Default: true.
390
- * Override to false in entity YAML via behaviors or in the service class.
391
- */
392
- emitLifecycleEvents = true;
393
- /**
394
- * Find a single entity by its primary key.
395
- * Returns null if not found.
396
- */
397
- findById(id) {
398
- return this.repository.findById(id);
399
- }
400
- /**
401
- * Find multiple entities by their primary keys.
402
- */
403
- findByIds(ids) {
404
- return this.repository.findByIds(ids);
405
- }
406
- /**
407
- * List entities with optional filtering/pagination options.
408
- */
409
- list(options) {
410
- return this.repository.list(options);
411
- }
412
- /**
413
- * Count entities matching an optional filter.
414
- */
415
- count(where) {
416
- return this.repository.count(where);
417
- }
418
- /**
419
- * Check whether an entity with the given id exists.
420
- */
421
- exists(id) {
422
- return this.repository.exists(id);
423
- }
424
- /**
425
- * Insert a new entity.
426
- * Emits a LIFECYCLE 'created' event with entity snapshot.
427
- */
428
- async create(input, tx) {
429
- const result = await this.repository.create(input, tx);
430
- if (this._shouldEmit()) {
431
- const snap = entitySnapshot(result);
432
- const id = result.id;
433
- const event = buildLifecycleEvent(this.entityName, "created", id, snap);
434
- void emitSafely(this.eventBus, [event]);
435
- }
436
- return result;
437
- }
438
- /**
439
- * Update an existing entity by id.
440
- * Emits a LIFECYCLE 'updated' event + CHANGE events for each modified field.
441
- */
442
- async update(id, input, tx) {
443
- let before;
444
- if (this._shouldEmit()) {
445
- const existing = await this.repository.findById(id);
446
- if (existing) {
447
- before = entitySnapshot(existing);
448
- }
449
- }
450
- const result = await this.repository.update(id, input, tx);
451
- if (this._shouldEmit()) {
452
- const after = entitySnapshot(result);
453
- const events = [
454
- buildLifecycleEvent(this.entityName, "updated", id, after)
455
- ];
456
- if (before) {
457
- const changes = diffSnapshots(before, after);
458
- if (changes.length > 0) {
459
- events.push(...buildChangeEvents(this.entityName, id, changes));
460
- }
461
- }
462
- void emitSafely(this.eventBus, events);
463
- }
464
- return result;
465
- }
466
- /**
467
- * Delete an entity by id.
468
- * Emits a LIFECYCLE 'deleted' event.
469
- */
470
- async delete(id, tx) {
471
- await this.repository.delete(id, tx);
472
- if (this._shouldEmit()) {
473
- const event = buildLifecycleEvent(this.entityName, "deleted", id);
474
- void emitSafely(this.eventBus, [event]);
475
- }
476
- }
477
- /** Check whether lifecycle event emission is active. */
478
- _shouldEmit() {
479
- return Boolean(
480
- this.emitLifecycleEvents && this.entityName && this.eventBus
481
- );
482
- }
483
- };
484
-
485
- // runtime/base-classes/base-read-use-cases.ts
486
- var BaseFindByIdUseCase = class {
487
- constructor(service) {
488
- this.service = service;
489
- }
490
- service;
491
- /**
492
- * Find a single entity by its primary key.
493
- * Returns null if not found.
494
- */
495
- execute(id) {
496
- return this.service.findById(id);
497
- }
498
- };
499
- var BaseListUseCase = class {
500
- constructor(service) {
501
- this.service = service;
502
- }
503
- service;
504
- /**
505
- * List all entities (no filters).
506
- * Controllers that need filtered lists should use a dedicated use case.
507
- */
508
- execute() {
509
- return this.service.list();
510
- }
511
- };
512
-
513
- // runtime/base-classes/integrated-entity-repository.ts
514
- import { and as and2, eq as eq2, inArray as inArray2 } from "drizzle-orm";
515
- var IntegratedEntityRepository = class extends BaseRepository {
516
- /**
517
- * Find a single entity by its external CRM identifier.
518
- */
519
- async findByExternalId(externalId) {
520
- const rows = await this.baseQuery().where(eq2(this.table["externalId"], externalId)).limit(1);
521
- return rows[0] ?? null;
522
- }
523
- /**
524
- * Find multiple entities by external CRM identifiers.
525
- */
526
- async findManyByExternalIds(externalIds) {
527
- if (externalIds.length === 0) return [];
528
- const rows = await this.baseQuery().where(inArray2(this.table["externalId"], externalIds));
529
- return rows;
530
- }
531
- /**
532
- * Find all entities owned by a specific user.
533
- */
534
- async findAllByUserId(userId) {
535
- const rows = await this.baseQuery().where(eq2(this.table["userId"], userId));
536
- return rows;
537
- }
538
- // ==========================================================================
539
- // Inbound integration (#374) — canonical→Drizzle write + provider-scoped FK
540
- // resolution + EAV dual-write seam, all inside a SINGLE transaction.
541
- // Driven entirely by `this.integrationConfig`; the per-entity shape lives there.
542
- // ==========================================================================
543
- /**
544
- * Upsert ONE entity by its `(provider, externalId)` identity, in a single
545
- * transaction:
546
- * 1. resolve each `integrationConfig.fkResolvers` FK (provider-scoped). Strict
547
- * resolvers throw on unresolved; non-strict leave the column null.
548
- * 2. insert-or-update the canonical columns via `onConflictDoUpdate` on the
549
- * `conflictTarget`. Resolved FKs are only written into `set` when
550
- * non-null this run (no-clobber).
551
- * 3. EAV dual-write of `write.fields` via `writeCustomFields` when
552
- * `integrationConfig.eav` and the bag is non-empty (same tx).
553
- *
554
- * Idempotent: a second call with the same identity updates in place. Returns
555
- * the canonical projection (so the orchestrator records `local_id`).
556
- *
557
- * @param write canonical fields + parent external ids + custom-field bag
558
- * @param provider adapter/provider label persisted + used to scope lookups
559
- * @param tx optional outer transaction; when omitted we open our own
560
- */
561
- async integrationUpsertOne(write, provider, tx) {
562
- const cfg = this.integrationConfig;
563
- const w = write;
564
- const run = async (db) => {
565
- const resolvedFks = {};
566
- for (const fk of cfg.fkResolvers) {
567
- resolvedFks[fk.column] = await this.resolveFk(db, fk, w[fk.writeKey], provider);
568
- }
569
- const now = /* @__PURE__ */ new Date();
570
- const copyThrough = {};
571
- for (const col of cfg.writeColumns) copyThrough[col] = w[col];
572
- const values = {
573
- externalId: w["externalId"],
574
- provider,
575
- ...copyThrough,
576
- ...resolvedFks,
577
- ...this.behaviors.timestamps ? { updatedAt: now } : {}
578
- };
579
- const set = {
580
- ...copyThrough,
581
- ...this.behaviors.timestamps ? { updatedAt: now } : {}
582
- };
583
- for (const fk of cfg.fkResolvers) {
584
- if (resolvedFks[fk.column] !== null) set[fk.column] = resolvedFks[fk.column];
585
- }
586
- const rows = await db.insert(this.table).values(values).onConflictDoUpdate({
587
- target: cfg.conflictTarget.map((c) => this.table[c]),
588
- set
589
- }).returning();
590
- const saved = rows[0];
591
- const fields = w["fields"];
592
- if (cfg.eav && fields && Object.keys(fields).length > 0) {
593
- await this.writeCustomFields(
594
- db,
595
- saved["id"],
596
- w["userId"],
597
- fields
598
- );
599
- }
600
- return this.toProjection(saved);
601
- };
602
- return tx ? run(tx) : this.db.transaction((t) => run(t));
603
- }
604
- /**
605
- * Canonical-projected lookup by external id (differ-ready). Returns `null`
606
- * when no local row exists. Provider-scoped so a HubSpot id can't match a
607
- * Salesforce row.
608
- */
609
- async findByExternalIdProjected(externalId, provider) {
610
- const rows = await this.db.select().from(this.table).where(
611
- and2(
612
- eq2(this.table["provider"], provider),
613
- eq2(this.table["externalId"], externalId)
614
- )
615
- ).limit(1);
616
- const row = rows[0];
617
- return row ? this.toProjection(row) : null;
618
- }
619
- /**
620
- * Integration "delete" by external id, provider-scoped. When `softDelete: true`,
621
- * sets `deletedAt`. When `softDelete: false`, tombstone-by-clearing: null out
622
- * `external_id`/`provider` so the row no longer matches future inbound
623
- * changes while preserving local-id references. Returns `{ id }` or `null`.
624
- */
625
- async softDeleteByExternalId(externalId, provider, tx) {
626
- const db = this.runner(tx);
627
- const set = this.integrationConfig.softDelete ? { deletedAt: /* @__PURE__ */ new Date(), updatedAt: /* @__PURE__ */ new Date() } : { externalId: null, provider: null, updatedAt: /* @__PURE__ */ new Date() };
628
- const rows = await db.update(this.table).set(set).where(
629
- and2(
630
- eq2(this.table["provider"], provider),
631
- eq2(this.table["externalId"], externalId)
632
- )
633
- ).returning({ id: this.table["id"] });
634
- return rows[0] ? { id: rows[0].id } : null;
635
- }
636
- /**
637
- * Batch integration upsert — concretizes the former abstract stub. Delegates to
638
- * `integrationUpsertOne` per input inside one transaction. Inputs are raw partial
639
- * rows: provider is read from each input's own `provider` column; rows
640
- * missing `externalId`/`provider` are skipped.
641
- */
642
- async integrationUpsert(inputs) {
643
- if (inputs.length === 0) return [];
644
- return this.db.transaction(async (tx) => {
645
- const out = [];
646
- for (const input of inputs) {
647
- const rec = input;
648
- if (!rec["externalId"] || !rec["provider"]) continue;
649
- const proj = await this.integrationUpsertOne(
650
- input,
651
- rec["provider"],
652
- tx
653
- );
654
- const id = proj["id"];
655
- const row = await tx.select().from(this.table).where(eq2(this.table["id"], id)).limit(1);
656
- out.push(row[0]);
657
- }
658
- return out;
659
- });
660
- }
661
- /**
662
- * Project a raw row to the canonical differ shape — a generic pick over
663
- * `integrationConfig.projectionColumns`. Override only for synthesized projections
664
- * (e.g. junctions); entities use this verbatim.
665
- */
666
- toProjection(row) {
667
- const r = row;
668
- const out = {};
669
- for (const col of this.integrationConfig.projectionColumns) out[col] = r[col];
670
- return out;
671
- }
672
- /**
673
- * EAV dual-write seam (#374, live path lands in #124). No-op by default;
674
- * `eav: true` entities emit a concrete override that injects
675
- * `FieldValueService` and delegates to `upsertFieldsTransactional` so the
676
- * dual-write joins the same tx (`db`). Kept as an explicit hook so the base
677
- * stays portable (the FieldValueService dependency is eav-only).
678
- */
679
- async writeCustomFields(_db, _entityId, _userId, _fields) {
680
- }
681
- /**
682
- * Resolve one FK from a parent external id (provider-scoped). `self` resolves
683
- * against `this.table`. Strict resolvers throw when unresolved; non-strict
684
- * return null. A null/absent write value short-circuits to null.
685
- */
686
- async resolveFk(db, fk, rawExternalId, provider) {
687
- const parentExternalId = rawExternalId;
688
- if (!parentExternalId) {
689
- if (fk.strict) {
690
- throw new Error(
691
- `${this.constructor.name}.integrationUpsertOne: missing required parent external id for '${fk.column}' (writeKey '${fk.writeKey}')`
692
- );
693
- }
694
- return null;
695
- }
696
- const refTable = fk.refTable === "self" ? this.table : fk.refTable;
697
- const rows = await db.select({ id: refTable["id"] }).from(refTable).where(
698
- and2(
699
- eq2(refTable["provider"], provider),
700
- eq2(refTable["externalId"], parentExternalId)
701
- )
702
- ).limit(1);
703
- const id = rows[0]?.id ?? null;
704
- if (id === null && fk.strict) {
705
- throw new Error(
706
- `${this.constructor.name}.integrationUpsertOne: unresolved parent '${parentExternalId}' (provider '${provider}') for '${fk.column}' \u2014 parent not integrated yet`
707
- );
708
- }
709
- return id;
710
- }
711
- /**
712
- * Find entities visible to a user (ownership + sharing rules).
713
- * Concrete repositories must implement with visibility logic.
714
- */
715
- async findVisibleByUserId(_userId) {
716
- throw new Error("findVisibleByUserId not implemented \u2014 override in concrete repository");
717
- }
718
- };
719
-
720
- // runtime/base-classes/junction-integration-repository.ts
721
- import { and as and3, eq as eq3 } from "drizzle-orm";
722
- var JunctionIntegrationRepository = class extends BaseRepository {
723
- /**
724
- * Upsert ONE junction row by its composite identity, in a single transaction:
725
- * 1. resolve the REQUIRED left FK (provider-scoped) — STRICT: missing → throws;
726
- * 2. resolve the REQUIRED right FK (provider-scoped) — STRICT: missing → throws;
727
- * 3. insert-or-update on the `(left, right[, role])` conflict target.
728
- *
729
- * Idempotent. Returns the composite externalId as the projection `id`.
730
- *
731
- * @param write parent external ids (`<left>ExternalId`/`<right>ExternalId`)
732
- * + optional `role` + `userId`
733
- * @param provider adapter/provider label used to scope the parent lookups
734
- * @param tx optional outer transaction; when omitted we open our own
735
- */
736
- async integrationUpsertOne(write, provider, tx) {
737
- const cfg = this.integrationConfig;
738
- const w = write;
739
- const leftWriteKey = `${cfg.left.column.replace(/Id$/, "")}ExternalId`;
740
- const rightWriteKey = `${cfg.right.column.replace(/Id$/, "")}ExternalId`;
741
- const run = async (db) => {
742
- const leftId = await this.resolveStrict(
743
- db,
744
- cfg.left.refTable,
745
- w[leftWriteKey],
746
- provider,
747
- cfg.left.column
748
- );
749
- const rightId = await this.resolveStrict(
750
- db,
751
- cfg.right.refTable,
752
- w[rightWriteKey],
753
- provider,
754
- cfg.right.column
755
- );
756
- const now = /* @__PURE__ */ new Date();
757
- const role = cfg.roleColumn ? w["role"] : void 0;
758
- const values = {
759
- [cfg.left.column]: leftId,
760
- [cfg.right.column]: rightId,
761
- ...cfg.roleColumn ? { [cfg.roleColumn]: role } : {},
762
- ...this.behaviors.timestamps ? { updatedAt: now } : {}
763
- };
764
- const target = cfg.roleColumn ? [this.table[cfg.left.column], this.table[cfg.right.column], this.table[cfg.roleColumn]] : [this.table[cfg.left.column], this.table[cfg.right.column]];
765
- const rows = await db.insert(this.table).values(values).onConflictDoUpdate({
766
- target,
767
- set: { ...this.behaviors.timestamps ? { updatedAt: now } : {} }
768
- }).returning();
769
- const saved = rows[0];
770
- return this.toProjection(saved, w, provider);
771
- };
772
- return tx ? run(tx) : this.db.transaction((t) => run(t));
773
- }
774
- /**
775
- * Canonical-projected lookup by the COMPOSITE externalId, differ-ready. Parses
776
- * the composite, resolves BOTH parents NON-throwing (→ null), then selects by
777
- * the identity tuple. Returns `null` on malformed composite / unresolved
778
- * parent / no row (a missing "before" side is a create from the differ's view).
779
- */
780
- async findByExternalIdProjected(externalId, provider) {
781
- const cfg = this.integrationConfig;
782
- const parsed = parseCompositeExternalId(externalId, cfg.roleColumn !== null);
783
- if (!parsed) return null;
784
- const leftId = await this.resolveLoose(this.db, cfg.left.refTable, parsed.left, provider);
785
- if (leftId === null) return null;
786
- const rightId = await this.resolveLoose(this.db, cfg.right.refTable, parsed.right, provider);
787
- if (rightId === null) return null;
788
- const rows = await this.db.select().from(this.table).where(this.identityWhere(leftId, rightId, parsed.role)).limit(1);
789
- const row = rows[0];
790
- if (!row) return null;
791
- const w = {
792
- [`${cfg.left.column.replace(/Id$/, "")}ExternalId`]: parsed.left,
793
- [`${cfg.right.column.replace(/Id$/, "")}ExternalId`]: parsed.right,
794
- ...cfg.roleColumn ? { role: parsed.role } : {},
795
- userId: ""
796
- };
797
- return this.toProjection(row, w, provider);
798
- }
799
- /**
800
- * Hard-delete the junction by composite externalId. Junctions have no
801
- * `deleted_at` and no external-linkage columns to clear, so a integration "delete"
802
- * removes the row. Resolves both parents NON-throwing, then deletes by the
803
- * identity tuple. Returns the composite id, or `null` when nothing matched.
804
- */
805
- async softDeleteByExternalId(externalId, provider, tx) {
806
- const cfg = this.integrationConfig;
807
- const parsed = parseCompositeExternalId(externalId, cfg.roleColumn !== null);
808
- if (!parsed) return null;
809
- const db = this.runner(tx);
810
- const leftId = await this.resolveLoose(db, cfg.left.refTable, parsed.left, provider);
811
- if (leftId === null) return null;
812
- const rightId = await this.resolveLoose(db, cfg.right.refTable, parsed.right, provider);
813
- if (rightId === null) return null;
814
- const rows = await db.delete(this.table).where(this.identityWhere(leftId, rightId, parsed.role)).returning({ id: this.table[cfg.left.column] });
815
- return rows[0] ? { id: externalId } : null;
816
- }
817
- /**
818
- * Project a raw junction row to the differ shape: the COMPOSITE externalId
819
- * `id` (junctions have no surrogate id) plus the local FK columns, role (when
820
- * role-bearing) and timestamps — matching the emitted
821
- * `<Junction>IntegrationProjection` interface (id + leftId + rightId + role? +
822
- * createdAt + updatedAt). Junction projections are purely structural, so this
823
- * is fully generic over `integrationConfig` — no per-junction override is emitted.
824
- */
825
- toProjection(row, write, _provider) {
826
- const cfg = this.integrationConfig;
827
- const r = row;
828
- const leftExt = write[`${cfg.left.column.replace(/Id$/, "")}ExternalId`];
829
- const rightExt = write[`${cfg.right.column.replace(/Id$/, "")}ExternalId`];
830
- const role = cfg.roleColumn ? r[cfg.roleColumn] : void 0;
831
- const out = {
832
- id: buildCompositeExternalId(leftExt, rightExt, role),
833
- [cfg.left.column]: r[cfg.left.column],
834
- [cfg.right.column]: r[cfg.right.column]
835
- };
836
- if (cfg.roleColumn) out[cfg.roleColumn] = r[cfg.roleColumn];
837
- out["createdAt"] = r["createdAt"];
838
- out["updatedAt"] = r["updatedAt"];
839
- return out;
840
- }
841
- /** Build the identity WHERE clause `(left, right[, role])`. */
842
- identityWhere(leftId, rightId, role) {
843
- const cfg = this.integrationConfig;
844
- const conds = [
845
- eq3(this.table[cfg.left.column], leftId),
846
- eq3(this.table[cfg.right.column], rightId)
847
- ];
848
- if (cfg.roleColumn && role !== void 0) {
849
- conds.push(eq3(this.table[cfg.roleColumn], role));
850
- }
851
- return and3(...conds);
852
- }
853
- /** Resolve a parent id (provider-scoped), throwing when unresolved. */
854
- async resolveStrict(db, refTable, parentExternalId, provider, column) {
855
- const id = await this.resolveLoose(db, refTable, parentExternalId, provider);
856
- if (!id) {
857
- throw new Error(
858
- `${this.constructor.name}.integrationUpsertOne: unresolved parent '${parentExternalId}' (provider '${provider}') for '${column}' \u2014 parent not integrated yet`
859
- );
860
- }
861
- return id;
862
- }
863
- /** Resolve a parent id (provider-scoped), returning null when unresolved. */
864
- async resolveLoose(db, refTable, parentExternalId, provider) {
865
- if (!parentExternalId) return null;
866
- const rows = await db.select({ id: refTable["id"] }).from(refTable).where(
867
- and3(
868
- eq3(refTable["provider"], provider),
869
- eq3(refTable["externalId"], parentExternalId)
870
- )
871
- ).limit(1);
872
- return rows[0]?.id ?? null;
873
- }
874
- };
875
- function buildCompositeExternalId(leftExternalId, rightExternalId, role) {
876
- return role !== void 0 ? `${leftExternalId}::${rightExternalId}::${role}` : `${leftExternalId}::${rightExternalId}`;
877
- }
878
- function parseCompositeExternalId(externalId, withRole) {
879
- const parts = externalId.split("::");
880
- const expected = withRole ? 3 : 2;
881
- if (parts.length !== expected || parts.some((p) => p.length === 0)) return null;
882
- return {
883
- left: parts[0],
884
- right: parts[1],
885
- role: withRole ? parts[2] : void 0
886
- };
887
- }
888
-
889
- // runtime/base-classes/activity-entity-repository.ts
890
- import { eq as eq4, between, desc } from "drizzle-orm";
891
- var ActivityEntityRepository = class extends BaseRepository {
892
- /**
893
- * Find activities within a date range (inclusive).
894
- */
895
- async findByDateRange(start, end) {
896
- const rows = await this.baseQuery().where(between(this.table["occurredAt"], start, end));
897
- return rows;
898
- }
899
- /**
900
- * Find all activities for a specific user.
901
- */
902
- async findByUserId(userId) {
903
- const rows = await this.baseQuery().where(eq4(this.table["userId"], userId));
904
- return rows;
905
- }
906
- /**
907
- * Find all activities for a specific opportunity.
908
- */
909
- async findByOpportunityId(opportunityId) {
910
- const rows = await this.baseQuery().where(eq4(this.table["opportunityId"], opportunityId));
911
- return rows;
912
- }
913
- /**
914
- * Find the most recent activities for an opportunity, ordered by occurredAt desc.
915
- */
916
- async findRecentByOpportunityId(opportunityId, limit = 10) {
917
- const rows = await this.baseQuery().where(eq4(this.table["opportunityId"], opportunityId)).orderBy(desc(this.table["occurredAt"])).limit(limit);
918
- return rows;
919
- }
920
- };
921
-
922
- // runtime/base-classes/metadata-entity-repository.ts
923
- import { eq as eq5, and as and4, desc as desc2 } from "drizzle-orm";
924
- var MetadataEntityRepository = class extends BaseRepository {
925
- /**
926
- * Bulk upsert with a caller-specified conflict target.
927
- * Uses Drizzle's onConflictDoUpdate to merge records.
928
- */
929
- async upsertMany(inputs, tx, options) {
930
- if (inputs.length === 0) return [];
931
- const conflictTarget = options?.conflictTarget;
932
- if (!conflictTarget) {
933
- return super.upsertMany(inputs, tx);
934
- }
935
- const data = inputs.map(
936
- (input) => this.withTimestamps(input, "create")
937
- );
938
- const rows = await this.runner(tx).insert(this.table).values(data).onConflictDoUpdate({
939
- target: this.table[conflictTarget],
940
- set: data[0]
941
- // eslint-disable-line @typescript-eslint/no-explicit-any
942
- }).returning();
943
- return rows;
944
- }
945
- /**
946
- * Find metadata by entity ID and entity type (compound lookup).
947
- */
948
- async findByEntityIdAndType(entityId, entityType) {
949
- const rows = await this.baseQuery().where(
950
- and4(
951
- eq5(this.table["entityId"], entityId),
952
- eq5(this.table["entityType"], entityType)
953
- )
954
- );
955
- return rows;
956
- }
957
- /**
958
- * List all metadata records for an entity.
959
- */
960
- async listByEntityId(entityId) {
961
- const rows = await this.baseQuery().where(eq5(this.table["entityId"], entityId));
962
- return rows;
963
- }
964
- /**
965
- * List metadata history for an entity, ordered by validFrom descending.
966
- */
967
- async listHistoryByEntityId(entityId) {
968
- const rows = await this.baseQuery().where(eq5(this.table["entityId"], entityId)).orderBy(desc2(this.table["validFrom"]));
969
- return rows;
970
- }
971
- };
972
-
973
- // runtime/base-classes/knowledge-entity-repository.ts
974
- var KnowledgeEntityRepository = class extends BaseRepository {
975
- // pgvector-dependent methods will be added when the extension is available:
976
- // semanticSearch, findPendingByOpportunityId, updateStatus, updateStatusBatch
977
- };
978
-
979
- // runtime/base-classes/integrated-entity-service.ts
980
- var IntegratedEntityService = class extends BaseService {
981
- /**
982
- * Find a single entity by its external CRM identifier.
983
- */
984
- findByExternalId(externalId) {
985
- return this.repository.findByExternalId(externalId);
986
- }
987
- /**
988
- * Find multiple entities by external CRM identifiers.
989
- */
990
- findManyByExternalIds(externalIds) {
991
- return this.repository.findManyByExternalIds(externalIds);
992
- }
993
- /**
994
- * Find all entities owned by a specific user.
995
- */
996
- findAllByUser(userId) {
997
- return this.repository.findAllByUserId(userId);
998
- }
999
- /**
1000
- * Find entities visible to a user (ownership + sharing rules).
1001
- * Concrete services may override with domain-specific visibility logic.
1002
- */
1003
- findVisibleByUser(userId) {
1004
- return this.repository.findVisibleByUserId(userId);
1005
- }
1006
- };
1007
-
1008
- // runtime/base-classes/activity-entity-service.ts
1009
- var ActivityEntityService = class extends BaseService {
1010
- /**
1011
- * Find activities within a date range (inclusive).
1012
- */
1013
- findByDateRange(start, end) {
1014
- return this.repository.findByDateRange(start, end);
1015
- }
1016
- /**
1017
- * Find all activities for a specific user.
1018
- */
1019
- findByUser(userId) {
1020
- return this.repository.findByUserId(userId);
1021
- }
1022
- /**
1023
- * Find all activities for a specific opportunity.
1024
- */
1025
- findByOpportunity(opportunityId) {
1026
- return this.repository.findByOpportunityId(opportunityId);
1027
- }
1028
- /**
1029
- * Find the most recent activities for an opportunity.
1030
- */
1031
- findRecent(opportunityId, limit) {
1032
- return this.repository.findRecentByOpportunityId(opportunityId, limit);
1033
- }
1034
- };
1035
-
1036
- // runtime/base-classes/metadata-entity-service.ts
1037
- var MetadataEntityService = class extends BaseService {
1038
- /**
1039
- * Find metadata records by entity ID and entity type (EAV polymorphic lookup).
1040
- */
1041
- findByEntityIdAndType(entityId, entityType) {
1042
- return this.repository.findByEntityIdAndType(entityId, entityType);
1043
- }
1044
- /**
1045
- * List all metadata records for an entity.
1046
- */
1047
- listByEntity(entityId) {
1048
- return this.repository.listByEntityId(entityId);
1049
- }
1050
- /**
1051
- * List metadata history for an entity, ordered by validFrom desc.
1052
- */
1053
- listHistory(entityId) {
1054
- return this.repository.listHistoryByEntityId(entityId);
1055
- }
1056
- /**
1057
- * Bulk upsert metadata values.
1058
- */
1059
- upsertValues(inputs, conflictTarget, tx) {
1060
- return this.repository.upsertMany(inputs, tx, { conflictTarget });
1061
- }
1062
- };
1063
-
1064
- // runtime/base-classes/knowledge-entity-service.ts
1065
- var KnowledgeEntityService = class extends BaseService {
1066
- // pgvector-dependent methods will be added when the extension is available:
1067
- // semanticSearch, findPendingByOpportunityId, updateStatus, updateStatusBatch
1068
- };
1069
-
1070
- // runtime/base-classes/with-analytics.ts
1071
- function WithAnalytics(Base) {
1072
- class WithAnalyticsMixin extends Base {
1073
- analytics;
1074
- }
1075
- return WithAnalyticsMixin;
1076
- }
1
+ import {
2
+ WithAnalytics
3
+ } from "../../chunk-IBGER4YK.js";
4
+ import {
5
+ JunctionIntegrationRepository,
6
+ buildCompositeExternalId,
7
+ parseCompositeExternalId
8
+ } from "../../chunk-2FTZLDBP.js";
9
+ import {
10
+ KnowledgeEntityRepository
11
+ } from "../../chunk-NN7XZEGF.js";
12
+ import {
13
+ KnowledgeEntityService
14
+ } from "../../chunk-AS3NAZB6.js";
15
+ import {
16
+ MetadataEntityRepository
17
+ } from "../../chunk-7KOW6PU6.js";
18
+ import {
19
+ MetadataEntityService
20
+ } from "../../chunk-RFH7N6EP.js";
21
+ import {
22
+ ActivityEntityRepository
23
+ } from "../../chunk-XCEI7NUH.js";
24
+ import {
25
+ ActivityEntityService
26
+ } from "../../chunk-BOPZWRJK.js";
27
+ import {
28
+ BaseFindByIdUseCase,
29
+ BaseListUseCase
30
+ } from "../../chunk-EXVDJMIY.js";
31
+ import {
32
+ IntegratedEntityRepository
33
+ } from "../../chunk-OTDN3OUQ.js";
34
+ import {
35
+ BaseRepository
36
+ } from "../../chunk-J6KZS54B.js";
37
+ import {
38
+ requireRequester,
39
+ requireRequesterScope,
40
+ tryGetRequester,
41
+ withOrgScope,
42
+ withRequester,
43
+ withSuperuserScope,
44
+ withUserScope
45
+ } from "../../chunk-ZUKFQL6E.js";
46
+ import {
47
+ IntegratedEntityService
48
+ } from "../../chunk-2VHZ7EKC.js";
49
+ import {
50
+ BaseService
51
+ } from "../../chunk-W72PRNJY.js";
52
+ import {
53
+ buildChangeEvents,
54
+ buildLifecycleEvent,
55
+ diffSnapshots,
56
+ emitSafely,
57
+ entitySnapshot
58
+ } from "../../chunk-KYR3B3OW.js";
59
+ import "../../chunk-2E224ZSN.js";
1077
60
  export {
1078
61
  ActivityEntityRepository,
1079
62
  ActivityEntityService,