@shipfox/api-triggers 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (331) hide show
  1. package/.turbo/turbo-build.log +2 -0
  2. package/.turbo/turbo-type$colon$emit.log +1 -0
  3. package/.turbo/turbo-type.log +1 -0
  4. package/CHANGELOG.md +224 -0
  5. package/LICENSE +21 -0
  6. package/README.md +300 -0
  7. package/dist/config.d.ts +10 -0
  8. package/dist/config.d.ts.map +1 -0
  9. package/dist/config.js +42 -0
  10. package/dist/config.js.map +1 -0
  11. package/dist/core/compute-next-fire-at.d.ts +9 -0
  12. package/dist/core/compute-next-fire-at.d.ts.map +1 -0
  13. package/dist/core/compute-next-fire-at.js +28 -0
  14. package/dist/core/compute-next-fire-at.js.map +1 -0
  15. package/dist/core/config.d.ts +26 -0
  16. package/dist/core/config.d.ts.map +1 -0
  17. package/dist/core/config.js +68 -0
  18. package/dist/core/config.js.map +1 -0
  19. package/dist/core/dispatch-integration-event.d.ts +14 -0
  20. package/dist/core/dispatch-integration-event.d.ts.map +1 -0
  21. package/dist/core/dispatch-integration-event.js +136 -0
  22. package/dist/core/dispatch-integration-event.js.map +1 -0
  23. package/dist/core/drain-cron-schedules.d.ts +30 -0
  24. package/dist/core/drain-cron-schedules.d.ts.map +1 -0
  25. package/dist/core/drain-cron-schedules.js +76 -0
  26. package/dist/core/drain-cron-schedules.js.map +1 -0
  27. package/dist/core/entities/cron-schedule.d.ts +11 -0
  28. package/dist/core/entities/cron-schedule.d.ts.map +1 -0
  29. package/dist/core/entities/cron-schedule.js +3 -0
  30. package/dist/core/entities/cron-schedule.js.map +1 -0
  31. package/dist/core/entities/decision.d.ts +23 -0
  32. package/dist/core/entities/decision.d.ts.map +1 -0
  33. package/dist/core/entities/decision.js +7 -0
  34. package/dist/core/entities/decision.js.map +1 -0
  35. package/dist/core/entities/index.d.ts +3 -0
  36. package/dist/core/entities/index.d.ts.map +1 -0
  37. package/dist/core/entities/index.js +3 -0
  38. package/dist/core/entities/index.js.map +1 -0
  39. package/dist/core/entities/job-listener-subscription.d.ts +14 -0
  40. package/dist/core/entities/job-listener-subscription.d.ts.map +1 -0
  41. package/dist/core/entities/job-listener-subscription.js +3 -0
  42. package/dist/core/entities/job-listener-subscription.js.map +1 -0
  43. package/dist/core/entities/received-event.d.ts +28 -0
  44. package/dist/core/entities/received-event.d.ts.map +1 -0
  45. package/dist/core/entities/received-event.js +14 -0
  46. package/dist/core/entities/received-event.js.map +1 -0
  47. package/dist/core/entities/subscription.d.ts +13 -0
  48. package/dist/core/entities/subscription.d.ts.map +1 -0
  49. package/dist/core/entities/subscription.js +3 -0
  50. package/dist/core/entities/subscription.js.map +1 -0
  51. package/dist/core/errors.d.ts +25 -0
  52. package/dist/core/errors.d.ts.map +1 -0
  53. package/dist/core/errors.js +41 -0
  54. package/dist/core/errors.js.map +1 -0
  55. package/dist/core/fire-cron.d.ts +28 -0
  56. package/dist/core/fire-cron.d.ts.map +1 -0
  57. package/dist/core/fire-cron.js +85 -0
  58. package/dist/core/fire-cron.js.map +1 -0
  59. package/dist/core/fire-manual.d.ts +9 -0
  60. package/dist/core/fire-manual.d.ts.map +1 -0
  61. package/dist/core/fire-manual.js +87 -0
  62. package/dist/core/fire-manual.js.map +1 -0
  63. package/dist/core/index.d.ts +11 -0
  64. package/dist/core/index.d.ts.map +1 -0
  65. package/dist/core/index.js +10 -0
  66. package/dist/core/index.js.map +1 -0
  67. package/dist/core/record-trigger-history.d.ts +35 -0
  68. package/dist/core/record-trigger-history.d.ts.map +1 -0
  69. package/dist/core/record-trigger-history.js +75 -0
  70. package/dist/core/record-trigger-history.js.map +1 -0
  71. package/dist/core/route-event-to-job-listeners.d.ts +31 -0
  72. package/dist/core/route-event-to-job-listeners.d.ts.map +1 -0
  73. package/dist/core/route-event-to-job-listeners.js +140 -0
  74. package/dist/core/route-event-to-job-listeners.js.map +1 -0
  75. package/dist/db/cron-schedules.d.ts +36 -0
  76. package/dist/db/cron-schedules.d.ts.map +1 -0
  77. package/dist/db/cron-schedules.js +104 -0
  78. package/dist/db/cron-schedules.js.map +1 -0
  79. package/dist/db/db.d.ts +2515 -0
  80. package/dist/db/db.d.ts.map +1 -0
  81. package/dist/db/db.js +28 -0
  82. package/dist/db/db.js.map +1 -0
  83. package/dist/db/event-history.d.ts +50 -0
  84. package/dist/db/event-history.d.ts.map +1 -0
  85. package/dist/db/event-history.js +207 -0
  86. package/dist/db/event-history.js.map +1 -0
  87. package/dist/db/event-queries.d.ts +38 -0
  88. package/dist/db/event-queries.d.ts.map +1 -0
  89. package/dist/db/event-queries.js +78 -0
  90. package/dist/db/event-queries.js.map +1 -0
  91. package/dist/db/index.d.ts +11 -0
  92. package/dist/db/index.d.ts.map +1 -0
  93. package/dist/db/index.js +14 -0
  94. package/dist/db/index.js.map +1 -0
  95. package/dist/db/job-listener-subscriptions.d.ts +24 -0
  96. package/dist/db/job-listener-subscriptions.d.ts.map +1 -0
  97. package/dist/db/job-listener-subscriptions.js +69 -0
  98. package/dist/db/job-listener-subscriptions.js.map +1 -0
  99. package/dist/db/received-events.d.ts +7 -0
  100. package/dist/db/received-events.d.ts.map +1 -0
  101. package/dist/db/received-events.js +11 -0
  102. package/dist/db/received-events.js.map +1 -0
  103. package/dist/db/schema/common.d.ts +2 -0
  104. package/dist/db/schema/common.d.ts.map +1 -0
  105. package/dist/db/schema/common.js +4 -0
  106. package/dist/db/schema/common.js.map +1 -0
  107. package/dist/db/schema/cron-schedules.d.ts +148 -0
  108. package/dist/db/schema/cron-schedules.d.ts.map +1 -0
  109. package/dist/db/schema/cron-schedules.js +39 -0
  110. package/dist/db/schema/cron-schedules.js.map +1 -0
  111. package/dist/db/schema/decisions.d.ts +284 -0
  112. package/dist/db/schema/decisions.d.ts.map +1 -0
  113. package/dist/db/schema/decisions.js +70 -0
  114. package/dist/db/schema/decisions.js.map +1 -0
  115. package/dist/db/schema/job-listener-subscriptions.d.ts +185 -0
  116. package/dist/db/schema/job-listener-subscriptions.d.ts.map +1 -0
  117. package/dist/db/schema/job-listener-subscriptions.js +41 -0
  118. package/dist/db/schema/job-listener-subscriptions.js.map +1 -0
  119. package/dist/db/schema/outbox.d.ts +195 -0
  120. package/dist/db/schema/outbox.d.ts.map +1 -0
  121. package/dist/db/schema/outbox.js +5 -0
  122. package/dist/db/schema/outbox.js.map +1 -0
  123. package/dist/db/schema/received-events.d.ts +544 -0
  124. package/dist/db/schema/received-events.d.ts.map +1 -0
  125. package/dist/db/schema/received-events.js +86 -0
  126. package/dist/db/schema/received-events.js.map +1 -0
  127. package/dist/db/schema/subscriptions.d.ts +182 -0
  128. package/dist/db/schema/subscriptions.d.ts.map +1 -0
  129. package/dist/db/schema/subscriptions.js +39 -0
  130. package/dist/db/schema/subscriptions.js.map +1 -0
  131. package/dist/db/subscriptions.d.ts +26 -0
  132. package/dist/db/subscriptions.d.ts.map +1 -0
  133. package/dist/db/subscriptions.js +103 -0
  134. package/dist/db/subscriptions.js.map +1 -0
  135. package/dist/index.d.ts +7 -0
  136. package/dist/index.d.ts.map +1 -0
  137. package/dist/index.js +68 -0
  138. package/dist/index.js.map +1 -0
  139. package/dist/metrics/index.d.ts +3 -0
  140. package/dist/metrics/index.d.ts.map +1 -0
  141. package/dist/metrics/index.js +4 -0
  142. package/dist/metrics/index.js.map +1 -0
  143. package/dist/metrics/instance.d.ts +15 -0
  144. package/dist/metrics/instance.d.ts.map +1 -0
  145. package/dist/metrics/instance.js +32 -0
  146. package/dist/metrics/instance.js.map +1 -0
  147. package/dist/metrics/service.d.ts +2 -0
  148. package/dist/metrics/service.d.ts.map +1 -0
  149. package/dist/metrics/service.js +15 -0
  150. package/dist/metrics/service.js.map +1 -0
  151. package/dist/presentation/dto/trigger-events.d.ts +7 -0
  152. package/dist/presentation/dto/trigger-events.d.ts.map +1 -0
  153. package/dist/presentation/dto/trigger-events.js +47 -0
  154. package/dist/presentation/dto/trigger-events.js.map +1 -0
  155. package/dist/presentation/index.d.ts +3 -0
  156. package/dist/presentation/index.d.ts.map +1 -0
  157. package/dist/presentation/index.js +4 -0
  158. package/dist/presentation/index.js.map +1 -0
  159. package/dist/presentation/routes/fire-manual.d.ts +2 -0
  160. package/dist/presentation/routes/fire-manual.d.ts.map +1 -0
  161. package/dist/presentation/routes/fire-manual.js +71 -0
  162. package/dist/presentation/routes/fire-manual.js.map +1 -0
  163. package/dist/presentation/routes/get-trigger-event.d.ts +2 -0
  164. package/dist/presentation/routes/get-trigger-event.d.ts.map +1 -0
  165. package/dist/presentation/routes/get-trigger-event.js +37 -0
  166. package/dist/presentation/routes/get-trigger-event.js.map +1 -0
  167. package/dist/presentation/routes/index.d.ts +3 -0
  168. package/dist/presentation/routes/index.d.ts.map +1 -0
  169. package/dist/presentation/routes/index.js +27 -0
  170. package/dist/presentation/routes/index.js.map +1 -0
  171. package/dist/presentation/routes/list-trigger-event-facets.d.ts +2 -0
  172. package/dist/presentation/routes/list-trigger-event-facets.d.ts.map +1 -0
  173. package/dist/presentation/routes/list-trigger-event-facets.js +29 -0
  174. package/dist/presentation/routes/list-trigger-event-facets.js.map +1 -0
  175. package/dist/presentation/routes/list-trigger-events.d.ts +2 -0
  176. package/dist/presentation/routes/list-trigger-events.d.ts.map +1 -0
  177. package/dist/presentation/routes/list-trigger-events.js +56 -0
  178. package/dist/presentation/routes/list-trigger-events.js.map +1 -0
  179. package/dist/presentation/subscribers/index.d.ts +6 -0
  180. package/dist/presentation/subscribers/index.d.ts.map +1 -0
  181. package/dist/presentation/subscribers/index.js +7 -0
  182. package/dist/presentation/subscribers/index.js.map +1 -0
  183. package/dist/presentation/subscribers/on-definition-deleted.d.ts +3 -0
  184. package/dist/presentation/subscribers/on-definition-deleted.d.ts.map +1 -0
  185. package/dist/presentation/subscribers/on-definition-deleted.js +8 -0
  186. package/dist/presentation/subscribers/on-definition-deleted.js.map +1 -0
  187. package/dist/presentation/subscribers/on-definition-resolved.d.ts +3 -0
  188. package/dist/presentation/subscribers/on-definition-resolved.d.ts.map +1 -0
  189. package/dist/presentation/subscribers/on-definition-resolved.js +11 -0
  190. package/dist/presentation/subscribers/on-definition-resolved.js.map +1 -0
  191. package/dist/presentation/subscribers/on-integration-event-received.d.ts +4 -0
  192. package/dist/presentation/subscribers/on-integration-event-received.d.ts.map +1 -0
  193. package/dist/presentation/subscribers/on-integration-event-received.js +17 -0
  194. package/dist/presentation/subscribers/on-integration-event-received.js.map +1 -0
  195. package/dist/presentation/subscribers/on-job-activated.d.ts +3 -0
  196. package/dist/presentation/subscribers/on-job-activated.d.ts.map +1 -0
  197. package/dist/presentation/subscribers/on-job-activated.js +13 -0
  198. package/dist/presentation/subscribers/on-job-activated.js.map +1 -0
  199. package/dist/presentation/subscribers/on-job-terminated.d.ts +3 -0
  200. package/dist/presentation/subscribers/on-job-terminated.d.ts.map +1 -0
  201. package/dist/presentation/subscribers/on-job-terminated.js +6 -0
  202. package/dist/presentation/subscribers/on-job-terminated.js.map +1 -0
  203. package/dist/temporal/activities/drain-cron-batch.d.ts +4 -0
  204. package/dist/temporal/activities/drain-cron-batch.d.ts.map +1 -0
  205. package/dist/temporal/activities/drain-cron-batch.js +20 -0
  206. package/dist/temporal/activities/drain-cron-batch.js.map +1 -0
  207. package/dist/temporal/activities/index.d.ts +10 -0
  208. package/dist/temporal/activities/index.d.ts.map +1 -0
  209. package/dist/temporal/activities/index.js +15 -0
  210. package/dist/temporal/activities/index.js.map +1 -0
  211. package/dist/temporal/activities/prune-trigger-events.d.ts +4 -0
  212. package/dist/temporal/activities/prune-trigger-events.d.ts.map +1 -0
  213. package/dist/temporal/activities/prune-trigger-events.js +11 -0
  214. package/dist/temporal/activities/prune-trigger-events.js.map +1 -0
  215. package/dist/temporal/constants.d.ts +7 -0
  216. package/dist/temporal/constants.d.ts.map +1 -0
  217. package/dist/temporal/constants.js +7 -0
  218. package/dist/temporal/constants.js.map +1 -0
  219. package/dist/temporal/workflows/cron-tick-cron.d.ts +9 -0
  220. package/dist/temporal/workflows/cron-tick-cron.d.ts.map +1 -0
  221. package/dist/temporal/workflows/cron-tick-cron.js +54 -0
  222. package/dist/temporal/workflows/cron-tick-cron.js.map +1 -0
  223. package/dist/temporal/workflows/index.d.ts +3 -0
  224. package/dist/temporal/workflows/index.d.ts.map +1 -0
  225. package/dist/temporal/workflows/index.js +4 -0
  226. package/dist/temporal/workflows/index.js.map +1 -0
  227. package/dist/temporal/workflows/prune-trigger-events-cron.d.ts +2 -0
  228. package/dist/temporal/workflows/prune-trigger-events-cron.d.ts.map +1 -0
  229. package/dist/temporal/workflows/prune-trigger-events-cron.js +18 -0
  230. package/dist/temporal/workflows/prune-trigger-events-cron.js.map +1 -0
  231. package/dist/tsconfig.test.tsbuildinfo +1 -0
  232. package/drizzle/0000_initial.sql +109 -0
  233. package/drizzle/meta/0000_snapshot.json +905 -0
  234. package/drizzle/meta/_journal.json +13 -0
  235. package/drizzle.config.ts +14 -0
  236. package/package.json +83 -0
  237. package/src/config.test.ts +33 -0
  238. package/src/config.ts +53 -0
  239. package/src/core/compute-next-fire-at.test.ts +69 -0
  240. package/src/core/compute-next-fire-at.ts +37 -0
  241. package/src/core/config.test.ts +213 -0
  242. package/src/core/config.ts +86 -0
  243. package/src/core/dispatch-integration-event.history-failure.test.ts +66 -0
  244. package/src/core/dispatch-integration-event.test.ts +1006 -0
  245. package/src/core/dispatch-integration-event.ts +150 -0
  246. package/src/core/drain-cron-schedules.test.ts +265 -0
  247. package/src/core/drain-cron-schedules.ts +90 -0
  248. package/src/core/entities/cron-schedule.ts +10 -0
  249. package/src/core/entities/decision.ts +24 -0
  250. package/src/core/entities/index.ts +5 -0
  251. package/src/core/entities/job-listener-subscription.ts +14 -0
  252. package/src/core/entities/received-event.ts +36 -0
  253. package/src/core/entities/subscription.ts +12 -0
  254. package/src/core/errors.ts +63 -0
  255. package/src/core/fire-cron.test.ts +146 -0
  256. package/src/core/fire-cron.ts +98 -0
  257. package/src/core/fire-manual.test.ts +157 -0
  258. package/src/core/fire-manual.ts +92 -0
  259. package/src/core/index.ts +34 -0
  260. package/src/core/record-trigger-history.test.ts +159 -0
  261. package/src/core/record-trigger-history.ts +145 -0
  262. package/src/core/route-event-to-job-listeners.test.ts +369 -0
  263. package/src/core/route-event-to-job-listeners.ts +184 -0
  264. package/src/db/cron-schedules.test.ts +358 -0
  265. package/src/db/cron-schedules.ts +163 -0
  266. package/src/db/db.ts +31 -0
  267. package/src/db/event-history.test.ts +421 -0
  268. package/src/db/event-history.ts +279 -0
  269. package/src/db/event-queries.ts +140 -0
  270. package/src/db/index.ts +51 -0
  271. package/src/db/job-listener-subscriptions.test.ts +270 -0
  272. package/src/db/job-listener-subscriptions.ts +133 -0
  273. package/src/db/received-events.ts +16 -0
  274. package/src/db/schema/common.ts +3 -0
  275. package/src/db/schema/cron-schedules.ts +37 -0
  276. package/src/db/schema/decisions.test.ts +279 -0
  277. package/src/db/schema/decisions.ts +77 -0
  278. package/src/db/schema/job-listener-subscriptions.ts +65 -0
  279. package/src/db/schema/outbox.ts +4 -0
  280. package/src/db/schema/received-events.test.ts +135 -0
  281. package/src/db/schema/received-events.ts +93 -0
  282. package/src/db/schema/subscriptions.ts +46 -0
  283. package/src/db/subscriptions.test.ts +340 -0
  284. package/src/db/subscriptions.ts +179 -0
  285. package/src/index.ts +108 -0
  286. package/src/metrics/index.ts +8 -0
  287. package/src/metrics/instance.ts +33 -0
  288. package/src/metrics/service.ts +18 -0
  289. package/src/presentation/dto/trigger-events.test.ts +144 -0
  290. package/src/presentation/dto/trigger-events.ts +60 -0
  291. package/src/presentation/index.ts +6 -0
  292. package/src/presentation/routes/fire-manual.test.ts +118 -0
  293. package/src/presentation/routes/fire-manual.ts +70 -0
  294. package/src/presentation/routes/get-trigger-event.test.ts +184 -0
  295. package/src/presentation/routes/get-trigger-event.ts +37 -0
  296. package/src/presentation/routes/index.ts +21 -0
  297. package/src/presentation/routes/list-trigger-event-facets.test.ts +116 -0
  298. package/src/presentation/routes/list-trigger-event-facets.ts +29 -0
  299. package/src/presentation/routes/list-trigger-events.test.ts +379 -0
  300. package/src/presentation/routes/list-trigger-events.ts +68 -0
  301. package/src/presentation/subscribers/index.ts +5 -0
  302. package/src/presentation/subscribers/on-definition-deleted.test.ts +42 -0
  303. package/src/presentation/subscribers/on-definition-deleted.ts +6 -0
  304. package/src/presentation/subscribers/on-definition-resolved.test.ts +67 -0
  305. package/src/presentation/subscribers/on-definition-resolved.ts +11 -0
  306. package/src/presentation/subscribers/on-integration-event-received.test.ts +53 -0
  307. package/src/presentation/subscribers/on-integration-event-received.ts +21 -0
  308. package/src/presentation/subscribers/on-job-activated.ts +14 -0
  309. package/src/presentation/subscribers/on-job-terminated.ts +6 -0
  310. package/src/temporal/activities/drain-cron-batch.ts +20 -0
  311. package/src/temporal/activities/index.ts +15 -0
  312. package/src/temporal/activities/prune-trigger-events.test.ts +78 -0
  313. package/src/temporal/activities/prune-trigger-events.ts +9 -0
  314. package/src/temporal/constants.ts +7 -0
  315. package/src/temporal/workflows/cron-tick-cron.ts +56 -0
  316. package/src/temporal/workflows/index.ts +2 -0
  317. package/src/temporal/workflows/prune-trigger-events-cron.ts +17 -0
  318. package/test/env.ts +8 -0
  319. package/test/factories/cron-schedule.ts +34 -0
  320. package/test/factories/decision.ts +49 -0
  321. package/test/factories/job-listener-subscription.ts +42 -0
  322. package/test/factories/received-event.ts +49 -0
  323. package/test/factories/subscription.ts +38 -0
  324. package/test/globalSetup.ts +20 -0
  325. package/test/index.ts +5 -0
  326. package/test/setup.ts +17 -0
  327. package/tsconfig.build.json +9 -0
  328. package/tsconfig.build.tsbuildinfo +1 -0
  329. package/tsconfig.json +3 -0
  330. package/tsconfig.test.json +8 -0
  331. package/vitest.config.ts +11 -0
@@ -0,0 +1,182 @@
1
+ import type { TriggerSubscription } from '#core/entities/subscription.js';
2
+ export declare const triggerSubscriptions: import("drizzle-orm/pg-core").PgTableWithColumns<{
3
+ name: "subscriptions";
4
+ schema: undefined;
5
+ columns: {
6
+ id: import("drizzle-orm/pg-core").PgColumn<{
7
+ name: "id";
8
+ tableName: "subscriptions";
9
+ dataType: "string";
10
+ columnType: "PgUUID";
11
+ data: string;
12
+ driverParam: string;
13
+ notNull: true;
14
+ hasDefault: true;
15
+ isPrimaryKey: true;
16
+ isAutoincrement: false;
17
+ hasRuntimeDefault: false;
18
+ enumValues: undefined;
19
+ baseColumn: never;
20
+ identity: undefined;
21
+ generated: undefined;
22
+ }, {}, {}>;
23
+ workspaceId: import("drizzle-orm/pg-core").PgColumn<{
24
+ name: "workspace_id";
25
+ tableName: "subscriptions";
26
+ dataType: "string";
27
+ columnType: "PgUUID";
28
+ data: string;
29
+ driverParam: string;
30
+ notNull: true;
31
+ hasDefault: false;
32
+ isPrimaryKey: false;
33
+ isAutoincrement: false;
34
+ hasRuntimeDefault: false;
35
+ enumValues: undefined;
36
+ baseColumn: never;
37
+ identity: undefined;
38
+ generated: undefined;
39
+ }, {}, {}>;
40
+ projectId: import("drizzle-orm/pg-core").PgColumn<{
41
+ name: "project_id";
42
+ tableName: "subscriptions";
43
+ dataType: "string";
44
+ columnType: "PgUUID";
45
+ data: string;
46
+ driverParam: string;
47
+ notNull: true;
48
+ hasDefault: false;
49
+ isPrimaryKey: false;
50
+ isAutoincrement: false;
51
+ hasRuntimeDefault: false;
52
+ enumValues: undefined;
53
+ baseColumn: never;
54
+ identity: undefined;
55
+ generated: undefined;
56
+ }, {}, {}>;
57
+ workflowDefinitionId: import("drizzle-orm/pg-core").PgColumn<{
58
+ name: "workflow_definition_id";
59
+ tableName: "subscriptions";
60
+ dataType: "string";
61
+ columnType: "PgUUID";
62
+ data: string;
63
+ driverParam: string;
64
+ notNull: true;
65
+ hasDefault: false;
66
+ isPrimaryKey: false;
67
+ isAutoincrement: false;
68
+ hasRuntimeDefault: false;
69
+ enumValues: undefined;
70
+ baseColumn: never;
71
+ identity: undefined;
72
+ generated: undefined;
73
+ }, {}, {}>;
74
+ name: import("drizzle-orm/pg-core").PgColumn<{
75
+ name: "name";
76
+ tableName: "subscriptions";
77
+ dataType: "string";
78
+ columnType: "PgText";
79
+ data: string;
80
+ driverParam: string;
81
+ notNull: true;
82
+ hasDefault: false;
83
+ isPrimaryKey: false;
84
+ isAutoincrement: false;
85
+ hasRuntimeDefault: false;
86
+ enumValues: [string, ...string[]];
87
+ baseColumn: never;
88
+ identity: undefined;
89
+ generated: undefined;
90
+ }, {}, {}>;
91
+ source: import("drizzle-orm/pg-core").PgColumn<{
92
+ name: "source";
93
+ tableName: "subscriptions";
94
+ dataType: "string";
95
+ columnType: "PgText";
96
+ data: string;
97
+ driverParam: string;
98
+ notNull: true;
99
+ hasDefault: false;
100
+ isPrimaryKey: false;
101
+ isAutoincrement: false;
102
+ hasRuntimeDefault: false;
103
+ enumValues: [string, ...string[]];
104
+ baseColumn: never;
105
+ identity: undefined;
106
+ generated: undefined;
107
+ }, {}, {}>;
108
+ event: import("drizzle-orm/pg-core").PgColumn<{
109
+ name: "event";
110
+ tableName: "subscriptions";
111
+ dataType: "string";
112
+ columnType: "PgText";
113
+ data: string;
114
+ driverParam: string;
115
+ notNull: true;
116
+ hasDefault: false;
117
+ isPrimaryKey: false;
118
+ isAutoincrement: false;
119
+ hasRuntimeDefault: false;
120
+ enumValues: [string, ...string[]];
121
+ baseColumn: never;
122
+ identity: undefined;
123
+ generated: undefined;
124
+ }, {}, {}>;
125
+ config: import("drizzle-orm/pg-core").PgColumn<{
126
+ name: "config";
127
+ tableName: "subscriptions";
128
+ dataType: "json";
129
+ columnType: "PgJsonb";
130
+ data: unknown;
131
+ driverParam: unknown;
132
+ notNull: true;
133
+ hasDefault: false;
134
+ isPrimaryKey: false;
135
+ isAutoincrement: false;
136
+ hasRuntimeDefault: false;
137
+ enumValues: undefined;
138
+ baseColumn: never;
139
+ identity: undefined;
140
+ generated: undefined;
141
+ }, {}, {}>;
142
+ createdAt: import("drizzle-orm/pg-core").PgColumn<{
143
+ name: "created_at";
144
+ tableName: "subscriptions";
145
+ dataType: "date";
146
+ columnType: "PgTimestamp";
147
+ data: Date;
148
+ driverParam: string;
149
+ notNull: true;
150
+ hasDefault: true;
151
+ isPrimaryKey: false;
152
+ isAutoincrement: false;
153
+ hasRuntimeDefault: false;
154
+ enumValues: undefined;
155
+ baseColumn: never;
156
+ identity: undefined;
157
+ generated: undefined;
158
+ }, {}, {}>;
159
+ updatedAt: import("drizzle-orm/pg-core").PgColumn<{
160
+ name: "updated_at";
161
+ tableName: "subscriptions";
162
+ dataType: "date";
163
+ columnType: "PgTimestamp";
164
+ data: Date;
165
+ driverParam: string;
166
+ notNull: true;
167
+ hasDefault: true;
168
+ isPrimaryKey: false;
169
+ isAutoincrement: false;
170
+ hasRuntimeDefault: false;
171
+ enumValues: undefined;
172
+ baseColumn: never;
173
+ identity: undefined;
174
+ generated: undefined;
175
+ }, {}, {}>;
176
+ };
177
+ dialect: "pg";
178
+ }>;
179
+ export type TriggerSubscriptionDb = typeof triggerSubscriptions.$inferSelect;
180
+ export type TriggerSubscriptionInsertDb = typeof triggerSubscriptions.$inferInsert;
181
+ export declare function toTriggerSubscription(row: TriggerSubscriptionDb): TriggerSubscription;
182
+ //# sourceMappingURL=subscriptions.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"subscriptions.d.ts","sourceRoot":"","sources":["../../../src/db/schema/subscriptions.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAC,mBAAmB,EAAC,MAAM,gCAAgC,CAAC;AAGxE,eAAO,MAAM,oBAAoB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAsBhC,CAAC;AAEF,MAAM,MAAM,qBAAqB,GAAG,OAAO,oBAAoB,CAAC,YAAY,CAAC;AAC7E,MAAM,MAAM,2BAA2B,GAAG,OAAO,oBAAoB,CAAC,YAAY,CAAC;AAEnF,wBAAgB,qBAAqB,CAAC,GAAG,EAAE,qBAAqB,GAAG,mBAAmB,CAarF"}
@@ -0,0 +1,39 @@
1
+ import { uuidv7PrimaryKey } from '@shipfox/node-drizzle';
2
+ import { index, jsonb, text, timestamp, uniqueIndex, uuid } from 'drizzle-orm/pg-core';
3
+ import { pgTable } from './common.js';
4
+ export const triggerSubscriptions = pgTable('subscriptions', {
5
+ id: uuidv7PrimaryKey(),
6
+ workspaceId: uuid('workspace_id').notNull(),
7
+ projectId: uuid('project_id').notNull(),
8
+ workflowDefinitionId: uuid('workflow_definition_id').notNull(),
9
+ name: text('name').notNull(),
10
+ source: text('source').notNull(),
11
+ event: text('event').notNull(),
12
+ config: jsonb('config').notNull(),
13
+ createdAt: timestamp('created_at', {
14
+ withTimezone: true
15
+ }).notNull().defaultNow(),
16
+ updatedAt: timestamp('updated_at', {
17
+ withTimezone: true
18
+ }).notNull().defaultNow()
19
+ }, (table)=>[
20
+ uniqueIndex('triggers_subscriptions_definition_name_unique').on(table.workflowDefinitionId, table.name),
21
+ index('triggers_subscriptions_match_idx').on(table.workspaceId, table.source, table.event),
22
+ index('triggers_subscriptions_definition_idx').on(table.workflowDefinitionId)
23
+ ]);
24
+ export function toTriggerSubscription(row) {
25
+ return {
26
+ id: row.id,
27
+ workspaceId: row.workspaceId,
28
+ projectId: row.projectId,
29
+ workflowDefinitionId: row.workflowDefinitionId,
30
+ name: row.name,
31
+ source: row.source,
32
+ event: row.event,
33
+ config: row.config,
34
+ createdAt: row.createdAt,
35
+ updatedAt: row.updatedAt
36
+ };
37
+ }
38
+
39
+ //# sourceMappingURL=subscriptions.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/db/schema/subscriptions.ts"],"sourcesContent":["import {uuidv7PrimaryKey} from '@shipfox/node-drizzle';\nimport {index, jsonb, text, timestamp, uniqueIndex, uuid} from 'drizzle-orm/pg-core';\nimport type {TriggerSubscription} from '#core/entities/subscription.js';\nimport {pgTable} from './common.js';\n\nexport const triggerSubscriptions = pgTable(\n 'subscriptions',\n {\n id: uuidv7PrimaryKey(),\n workspaceId: uuid('workspace_id').notNull(),\n projectId: uuid('project_id').notNull(),\n workflowDefinitionId: uuid('workflow_definition_id').notNull(),\n name: text('name').notNull(),\n source: text('source').notNull(),\n event: text('event').notNull(),\n config: jsonb('config').notNull(),\n createdAt: timestamp('created_at', {withTimezone: true}).notNull().defaultNow(),\n updatedAt: timestamp('updated_at', {withTimezone: true}).notNull().defaultNow(),\n },\n (table) => [\n uniqueIndex('triggers_subscriptions_definition_name_unique').on(\n table.workflowDefinitionId,\n table.name,\n ),\n index('triggers_subscriptions_match_idx').on(table.workspaceId, table.source, table.event),\n index('triggers_subscriptions_definition_idx').on(table.workflowDefinitionId),\n ],\n);\n\nexport type TriggerSubscriptionDb = typeof triggerSubscriptions.$inferSelect;\nexport type TriggerSubscriptionInsertDb = typeof triggerSubscriptions.$inferInsert;\n\nexport function toTriggerSubscription(row: TriggerSubscriptionDb): TriggerSubscription {\n return {\n id: row.id,\n workspaceId: row.workspaceId,\n projectId: row.projectId,\n workflowDefinitionId: row.workflowDefinitionId,\n name: row.name,\n source: row.source,\n event: row.event,\n config: row.config as Record<string, unknown>,\n createdAt: row.createdAt,\n updatedAt: row.updatedAt,\n };\n}\n"],"names":["uuidv7PrimaryKey","index","jsonb","text","timestamp","uniqueIndex","uuid","pgTable","triggerSubscriptions","id","workspaceId","notNull","projectId","workflowDefinitionId","name","source","event","config","createdAt","withTimezone","defaultNow","updatedAt","table","on","toTriggerSubscription","row"],"mappings":"AAAA,SAAQA,gBAAgB,QAAO,wBAAwB;AACvD,SAAQC,KAAK,EAAEC,KAAK,EAAEC,IAAI,EAAEC,SAAS,EAAEC,WAAW,EAAEC,IAAI,QAAO,sBAAsB;AAErF,SAAQC,OAAO,QAAO,cAAc;AAEpC,OAAO,MAAMC,uBAAuBD,QAClC,iBACA;IACEE,IAAIT;IACJU,aAAaJ,KAAK,gBAAgBK,OAAO;IACzCC,WAAWN,KAAK,cAAcK,OAAO;IACrCE,sBAAsBP,KAAK,0BAA0BK,OAAO;IAC5DG,MAAMX,KAAK,QAAQQ,OAAO;IAC1BI,QAAQZ,KAAK,UAAUQ,OAAO;IAC9BK,OAAOb,KAAK,SAASQ,OAAO;IAC5BM,QAAQf,MAAM,UAAUS,OAAO;IAC/BO,WAAWd,UAAU,cAAc;QAACe,cAAc;IAAI,GAAGR,OAAO,GAAGS,UAAU;IAC7EC,WAAWjB,UAAU,cAAc;QAACe,cAAc;IAAI,GAAGR,OAAO,GAAGS,UAAU;AAC/E,GACA,CAACE,QAAU;QACTjB,YAAY,iDAAiDkB,EAAE,CAC7DD,MAAMT,oBAAoB,EAC1BS,MAAMR,IAAI;QAEZb,MAAM,oCAAoCsB,EAAE,CAACD,MAAMZ,WAAW,EAAEY,MAAMP,MAAM,EAAEO,MAAMN,KAAK;QACzFf,MAAM,yCAAyCsB,EAAE,CAACD,MAAMT,oBAAoB;KAC7E,EACD;AAKF,OAAO,SAASW,sBAAsBC,GAA0B;IAC9D,OAAO;QACLhB,IAAIgB,IAAIhB,EAAE;QACVC,aAAae,IAAIf,WAAW;QAC5BE,WAAWa,IAAIb,SAAS;QACxBC,sBAAsBY,IAAIZ,oBAAoB;QAC9CC,MAAMW,IAAIX,IAAI;QACdC,QAAQU,IAAIV,MAAM;QAClBC,OAAOS,IAAIT,KAAK;QAChBC,QAAQQ,IAAIR,MAAM;QAClBC,WAAWO,IAAIP,SAAS;QACxBG,WAAWI,IAAIJ,SAAS;IAC1B;AACF"}
@@ -0,0 +1,26 @@
1
+ import type { TriggerDto } from '@shipfox/api-definitions-dto';
2
+ import type { TriggerSubscription } from '#core/entities/subscription.js';
3
+ import { type Tx } from './db.js';
4
+ export interface ProjectDefinitionTriggersParams {
5
+ tx?: Tx | undefined;
6
+ workspaceId: string;
7
+ projectId: string;
8
+ workflowDefinitionId: string;
9
+ triggers: Record<string, TriggerDto>;
10
+ }
11
+ export declare function projectDefinitionTriggers(params: ProjectDefinitionTriggersParams): Promise<void>;
12
+ export interface DeleteSubscriptionsForDefinitionParams {
13
+ tx?: Tx | undefined;
14
+ workflowDefinitionId: string;
15
+ }
16
+ export declare function deleteSubscriptionsForDefinition(params: DeleteSubscriptionsForDefinitionParams): Promise<number>;
17
+ export declare function getTriggerSubscriptionById(id: string): Promise<TriggerSubscription | undefined>;
18
+ export declare function getManualSubscriptionByDefinitionId(workflowDefinitionId: string): Promise<TriggerSubscription | undefined>;
19
+ export interface FindMatchingSubscriptionsParams {
20
+ workspaceId: string;
21
+ source: string;
22
+ event: string;
23
+ }
24
+ export declare function findMatchingSubscriptions(params: FindMatchingSubscriptionsParams): Promise<TriggerSubscription[]>;
25
+ export declare function listSubscriptionsByWorkflowDefinitionIds(workflowDefinitionIds: string[]): Promise<TriggerSubscription[]>;
26
+ //# sourceMappingURL=subscriptions.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"subscriptions.d.ts","sourceRoot":"","sources":["../../src/db/subscriptions.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,UAAU,EAAC,MAAM,8BAA8B,CAAC;AAE7D,OAAO,KAAK,EAAC,mBAAmB,EAAC,MAAM,gCAAgC,CAAC;AAExE,OAAO,EAAoB,KAAK,EAAE,EAAC,MAAM,SAAS,CAAC;AAGnD,MAAM,WAAW,+BAA+B;IAC9C,EAAE,CAAC,EAAE,EAAE,GAAG,SAAS,CAAC;IACpB,WAAW,EAAE,MAAM,CAAC;IACpB,SAAS,EAAE,MAAM,CAAC;IAClB,oBAAoB,EAAE,MAAM,CAAC;IAC7B,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,UAAU,CAAC,CAAC;CACtC;AAED,wBAAsB,yBAAyB,CAC7C,MAAM,EAAE,+BAA+B,GACtC,OAAO,CAAC,IAAI,CAAC,CAqEf;AAED,MAAM,WAAW,sCAAsC;IACrD,EAAE,CAAC,EAAE,EAAE,GAAG,SAAS,CAAC;IACpB,oBAAoB,EAAE,MAAM,CAAC;CAC9B;AAED,wBAAsB,gCAAgC,CACpD,MAAM,EAAE,sCAAsC,GAC7C,OAAO,CAAC,MAAM,CAAC,CAUjB;AAED,wBAAsB,0BAA0B,CAC9C,EAAE,EAAE,MAAM,GACT,OAAO,CAAC,mBAAmB,GAAG,SAAS,CAAC,CAS1C;AAED,wBAAsB,mCAAmC,CACvD,oBAAoB,EAAE,MAAM,GAC3B,OAAO,CAAC,mBAAmB,GAAG,SAAS,CAAC,CAoB1C;AAED,MAAM,WAAW,+BAA+B;IAC9C,WAAW,EAAE,MAAM,CAAC;IACpB,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,MAAM,CAAC;CACf;AAKD,wBAAsB,yBAAyB,CAC7C,MAAM,EAAE,+BAA+B,GACtC,OAAO,CAAC,mBAAmB,EAAE,CAAC,CAYhC;AAED,wBAAsB,wCAAwC,CAC5D,qBAAqB,EAAE,MAAM,EAAE,GAC9B,OAAO,CAAC,mBAAmB,EAAE,CAAC,CAOhC"}
@@ -0,0 +1,103 @@
1
+ import { and, eq, inArray, notInArray } from 'drizzle-orm';
2
+ import { deleteCronScheduleForSubscription, syncCronSchedule } from './cron-schedules.js';
3
+ import { db } from './db.js';
4
+ import { toTriggerSubscription, triggerSubscriptions } from './schema/subscriptions.js';
5
+ export async function projectDefinitionTriggers(params) {
6
+ const work = async (tx)=>{
7
+ const entries = Object.entries(params.triggers);
8
+ const keepNames = entries.map(([name])=>name);
9
+ if (keepNames.length === 0) {
10
+ await tx.delete(triggerSubscriptions).where(eq(triggerSubscriptions.workflowDefinitionId, params.workflowDefinitionId));
11
+ return;
12
+ }
13
+ await tx.delete(triggerSubscriptions).where(and(eq(triggerSubscriptions.workflowDefinitionId, params.workflowDefinitionId), notInArray(triggerSubscriptions.name, keepNames)));
14
+ for (const [name, trigger] of entries){
15
+ const config = {};
16
+ if (trigger.with !== undefined) config.with = trigger.with;
17
+ if (trigger.filter !== undefined) config.filter = trigger.filter;
18
+ const [upserted] = await tx.insert(triggerSubscriptions).values({
19
+ workspaceId: params.workspaceId,
20
+ projectId: params.projectId,
21
+ workflowDefinitionId: params.workflowDefinitionId,
22
+ name,
23
+ source: trigger.source,
24
+ event: trigger.event,
25
+ config
26
+ }).onConflictDoUpdate({
27
+ target: [
28
+ triggerSubscriptions.workflowDefinitionId,
29
+ triggerSubscriptions.name
30
+ ],
31
+ set: {
32
+ workspaceId: params.workspaceId,
33
+ projectId: params.projectId,
34
+ source: trigger.source,
35
+ event: trigger.event,
36
+ config,
37
+ updatedAt: new Date()
38
+ }
39
+ }).returning({
40
+ id: triggerSubscriptions.id
41
+ });
42
+ if (!upserted) throw new Error('Trigger subscription upsert returned no rows');
43
+ if (trigger.source === 'cron') {
44
+ await syncCronSchedule({
45
+ tx,
46
+ subscriptionId: upserted.id,
47
+ workspaceId: params.workspaceId,
48
+ triggerConfig: trigger.config
49
+ });
50
+ } else {
51
+ await deleteCronScheduleForSubscription({
52
+ tx,
53
+ subscriptionId: upserted.id
54
+ });
55
+ }
56
+ }
57
+ };
58
+ if (params.tx) {
59
+ await work(params.tx);
60
+ return;
61
+ }
62
+ await db().transaction(work);
63
+ }
64
+ export async function deleteSubscriptionsForDefinition(params) {
65
+ const work = async (executor)=>{
66
+ const rows = await executor.delete(triggerSubscriptions).where(eq(triggerSubscriptions.workflowDefinitionId, params.workflowDefinitionId)).returning({
67
+ id: triggerSubscriptions.id
68
+ });
69
+ return rows.length;
70
+ };
71
+ if (params.tx) return await work(params.tx);
72
+ return await db().transaction(work);
73
+ }
74
+ export async function getTriggerSubscriptionById(id) {
75
+ const rows = await db().select().from(triggerSubscriptions).where(eq(triggerSubscriptions.id, id)).limit(1);
76
+ const row = rows[0];
77
+ if (!row) return undefined;
78
+ return toTriggerSubscription(row);
79
+ }
80
+ export async function getManualSubscriptionByDefinitionId(workflowDefinitionId) {
81
+ // limit(2) catches a broken parser invariant (>1 manual per definition) loudly instead of silently picking one.
82
+ const rows = await db().select().from(triggerSubscriptions).where(and(eq(triggerSubscriptions.workflowDefinitionId, workflowDefinitionId), eq(triggerSubscriptions.source, 'manual'))).limit(2);
83
+ if (rows.length > 1) {
84
+ throw new Error(`Workflow definition ${workflowDefinitionId} has ${rows.length} manual triggers; expected at most 1`);
85
+ }
86
+ const row = rows[0];
87
+ if (!row) return undefined;
88
+ return toTriggerSubscription(row);
89
+ }
90
+ // Matches at workspace scope: an inbound integration event is a workspace-level
91
+ // fact, not addressed to a project. Narrowing to a repo/project/branch is left to
92
+ // user-defined per-workflow filters, not inferred here.
93
+ export async function findMatchingSubscriptions(params) {
94
+ const rows = await db().select().from(triggerSubscriptions).where(and(eq(triggerSubscriptions.workspaceId, params.workspaceId), eq(triggerSubscriptions.source, params.source), eq(triggerSubscriptions.event, params.event)));
95
+ return rows.map(toTriggerSubscription);
96
+ }
97
+ export async function listSubscriptionsByWorkflowDefinitionIds(workflowDefinitionIds) {
98
+ if (workflowDefinitionIds.length === 0) return [];
99
+ const rows = await db().select().from(triggerSubscriptions).where(inArray(triggerSubscriptions.workflowDefinitionId, workflowDefinitionIds));
100
+ return rows.map(toTriggerSubscription);
101
+ }
102
+
103
+ //# sourceMappingURL=subscriptions.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/db/subscriptions.ts"],"sourcesContent":["import type {TriggerDto} from '@shipfox/api-definitions-dto';\nimport {and, eq, inArray, notInArray} from 'drizzle-orm';\nimport type {TriggerSubscription} from '#core/entities/subscription.js';\nimport {deleteCronScheduleForSubscription, syncCronSchedule} from './cron-schedules.js';\nimport {db, type Executor, type Tx} from './db.js';\nimport {toTriggerSubscription, triggerSubscriptions} from './schema/subscriptions.js';\n\nexport interface ProjectDefinitionTriggersParams {\n tx?: Tx | undefined;\n workspaceId: string;\n projectId: string;\n workflowDefinitionId: string;\n triggers: Record<string, TriggerDto>;\n}\n\nexport async function projectDefinitionTriggers(\n params: ProjectDefinitionTriggersParams,\n): Promise<void> {\n const work = async (tx: Tx): Promise<void> => {\n const entries = Object.entries(params.triggers);\n const keepNames = entries.map(([name]) => name);\n\n if (keepNames.length === 0) {\n await tx\n .delete(triggerSubscriptions)\n .where(eq(triggerSubscriptions.workflowDefinitionId, params.workflowDefinitionId));\n return;\n }\n\n await tx\n .delete(triggerSubscriptions)\n .where(\n and(\n eq(triggerSubscriptions.workflowDefinitionId, params.workflowDefinitionId),\n notInArray(triggerSubscriptions.name, keepNames),\n ),\n );\n\n for (const [name, trigger] of entries) {\n const config: Record<string, unknown> = {};\n if (trigger.with !== undefined) config.with = trigger.with;\n if (trigger.filter !== undefined) config.filter = trigger.filter;\n\n const [upserted] = await tx\n .insert(triggerSubscriptions)\n .values({\n workspaceId: params.workspaceId,\n projectId: params.projectId,\n workflowDefinitionId: params.workflowDefinitionId,\n name,\n source: trigger.source,\n event: trigger.event,\n config,\n })\n .onConflictDoUpdate({\n target: [triggerSubscriptions.workflowDefinitionId, triggerSubscriptions.name],\n set: {\n workspaceId: params.workspaceId,\n projectId: params.projectId,\n source: trigger.source,\n event: trigger.event,\n config,\n updatedAt: new Date(),\n },\n })\n .returning({id: triggerSubscriptions.id});\n if (!upserted) throw new Error('Trigger subscription upsert returned no rows');\n\n if (trigger.source === 'cron') {\n await syncCronSchedule({\n tx,\n subscriptionId: upserted.id,\n workspaceId: params.workspaceId,\n triggerConfig: trigger.config,\n });\n } else {\n await deleteCronScheduleForSubscription({tx, subscriptionId: upserted.id});\n }\n }\n };\n\n if (params.tx) {\n await work(params.tx);\n return;\n }\n await db().transaction(work);\n}\n\nexport interface DeleteSubscriptionsForDefinitionParams {\n tx?: Tx | undefined;\n workflowDefinitionId: string;\n}\n\nexport async function deleteSubscriptionsForDefinition(\n params: DeleteSubscriptionsForDefinitionParams,\n): Promise<number> {\n const work = async (executor: Executor): Promise<number> => {\n const rows = await executor\n .delete(triggerSubscriptions)\n .where(eq(triggerSubscriptions.workflowDefinitionId, params.workflowDefinitionId))\n .returning({id: triggerSubscriptions.id});\n return rows.length;\n };\n if (params.tx) return await work(params.tx);\n return await db().transaction(work);\n}\n\nexport async function getTriggerSubscriptionById(\n id: string,\n): Promise<TriggerSubscription | undefined> {\n const rows = await db()\n .select()\n .from(triggerSubscriptions)\n .where(eq(triggerSubscriptions.id, id))\n .limit(1);\n const row = rows[0];\n if (!row) return undefined;\n return toTriggerSubscription(row);\n}\n\nexport async function getManualSubscriptionByDefinitionId(\n workflowDefinitionId: string,\n): Promise<TriggerSubscription | undefined> {\n // limit(2) catches a broken parser invariant (>1 manual per definition) loudly instead of silently picking one.\n const rows = await db()\n .select()\n .from(triggerSubscriptions)\n .where(\n and(\n eq(triggerSubscriptions.workflowDefinitionId, workflowDefinitionId),\n eq(triggerSubscriptions.source, 'manual'),\n ),\n )\n .limit(2);\n if (rows.length > 1) {\n throw new Error(\n `Workflow definition ${workflowDefinitionId} has ${rows.length} manual triggers; expected at most 1`,\n );\n }\n const row = rows[0];\n if (!row) return undefined;\n return toTriggerSubscription(row);\n}\n\nexport interface FindMatchingSubscriptionsParams {\n workspaceId: string;\n source: string;\n event: string;\n}\n\n// Matches at workspace scope: an inbound integration event is a workspace-level\n// fact, not addressed to a project. Narrowing to a repo/project/branch is left to\n// user-defined per-workflow filters, not inferred here.\nexport async function findMatchingSubscriptions(\n params: FindMatchingSubscriptionsParams,\n): Promise<TriggerSubscription[]> {\n const rows = await db()\n .select()\n .from(triggerSubscriptions)\n .where(\n and(\n eq(triggerSubscriptions.workspaceId, params.workspaceId),\n eq(triggerSubscriptions.source, params.source),\n eq(triggerSubscriptions.event, params.event),\n ),\n );\n return rows.map(toTriggerSubscription);\n}\n\nexport async function listSubscriptionsByWorkflowDefinitionIds(\n workflowDefinitionIds: string[],\n): Promise<TriggerSubscription[]> {\n if (workflowDefinitionIds.length === 0) return [];\n const rows = await db()\n .select()\n .from(triggerSubscriptions)\n .where(inArray(triggerSubscriptions.workflowDefinitionId, workflowDefinitionIds));\n return rows.map(toTriggerSubscription);\n}\n"],"names":["and","eq","inArray","notInArray","deleteCronScheduleForSubscription","syncCronSchedule","db","toTriggerSubscription","triggerSubscriptions","projectDefinitionTriggers","params","work","tx","entries","Object","triggers","keepNames","map","name","length","delete","where","workflowDefinitionId","trigger","config","with","undefined","filter","upserted","insert","values","workspaceId","projectId","source","event","onConflictDoUpdate","target","set","updatedAt","Date","returning","id","Error","subscriptionId","triggerConfig","transaction","deleteSubscriptionsForDefinition","executor","rows","getTriggerSubscriptionById","select","from","limit","row","getManualSubscriptionByDefinitionId","findMatchingSubscriptions","listSubscriptionsByWorkflowDefinitionIds","workflowDefinitionIds"],"mappings":"AACA,SAAQA,GAAG,EAAEC,EAAE,EAAEC,OAAO,EAAEC,UAAU,QAAO,cAAc;AAEzD,SAAQC,iCAAiC,EAAEC,gBAAgB,QAAO,sBAAsB;AACxF,SAAQC,EAAE,QAA+B,UAAU;AACnD,SAAQC,qBAAqB,EAAEC,oBAAoB,QAAO,4BAA4B;AAUtF,OAAO,eAAeC,0BACpBC,MAAuC;IAEvC,MAAMC,OAAO,OAAOC;QAClB,MAAMC,UAAUC,OAAOD,OAAO,CAACH,OAAOK,QAAQ;QAC9C,MAAMC,YAAYH,QAAQI,GAAG,CAAC,CAAC,CAACC,KAAK,GAAKA;QAE1C,IAAIF,UAAUG,MAAM,KAAK,GAAG;YAC1B,MAAMP,GACHQ,MAAM,CAACZ,sBACPa,KAAK,CAACpB,GAAGO,qBAAqBc,oBAAoB,EAAEZ,OAAOY,oBAAoB;YAClF;QACF;QAEA,MAAMV,GACHQ,MAAM,CAACZ,sBACPa,KAAK,CACJrB,IACEC,GAAGO,qBAAqBc,oBAAoB,EAAEZ,OAAOY,oBAAoB,GACzEnB,WAAWK,qBAAqBU,IAAI,EAAEF;QAI5C,KAAK,MAAM,CAACE,MAAMK,QAAQ,IAAIV,QAAS;YACrC,MAAMW,SAAkC,CAAC;YACzC,IAAID,QAAQE,IAAI,KAAKC,WAAWF,OAAOC,IAAI,GAAGF,QAAQE,IAAI;YAC1D,IAAIF,QAAQI,MAAM,KAAKD,WAAWF,OAAOG,MAAM,GAAGJ,QAAQI,MAAM;YAEhE,MAAM,CAACC,SAAS,GAAG,MAAMhB,GACtBiB,MAAM,CAACrB,sBACPsB,MAAM,CAAC;gBACNC,aAAarB,OAAOqB,WAAW;gBAC/BC,WAAWtB,OAAOsB,SAAS;gBAC3BV,sBAAsBZ,OAAOY,oBAAoB;gBACjDJ;gBACAe,QAAQV,QAAQU,MAAM;gBACtBC,OAAOX,QAAQW,KAAK;gBACpBV;YACF,GACCW,kBAAkB,CAAC;gBAClBC,QAAQ;oBAAC5B,qBAAqBc,oBAAoB;oBAAEd,qBAAqBU,IAAI;iBAAC;gBAC9EmB,KAAK;oBACHN,aAAarB,OAAOqB,WAAW;oBAC/BC,WAAWtB,OAAOsB,SAAS;oBAC3BC,QAAQV,QAAQU,MAAM;oBACtBC,OAAOX,QAAQW,KAAK;oBACpBV;oBACAc,WAAW,IAAIC;gBACjB;YACF,GACCC,SAAS,CAAC;gBAACC,IAAIjC,qBAAqBiC,EAAE;YAAA;YACzC,IAAI,CAACb,UAAU,MAAM,IAAIc,MAAM;YAE/B,IAAInB,QAAQU,MAAM,KAAK,QAAQ;gBAC7B,MAAM5B,iBAAiB;oBACrBO;oBACA+B,gBAAgBf,SAASa,EAAE;oBAC3BV,aAAarB,OAAOqB,WAAW;oBAC/Ba,eAAerB,QAAQC,MAAM;gBAC/B;YACF,OAAO;gBACL,MAAMpB,kCAAkC;oBAACQ;oBAAI+B,gBAAgBf,SAASa,EAAE;gBAAA;YAC1E;QACF;IACF;IAEA,IAAI/B,OAAOE,EAAE,EAAE;QACb,MAAMD,KAAKD,OAAOE,EAAE;QACpB;IACF;IACA,MAAMN,KAAKuC,WAAW,CAAClC;AACzB;AAOA,OAAO,eAAemC,iCACpBpC,MAA8C;IAE9C,MAAMC,OAAO,OAAOoC;QAClB,MAAMC,OAAO,MAAMD,SAChB3B,MAAM,CAACZ,sBACPa,KAAK,CAACpB,GAAGO,qBAAqBc,oBAAoB,EAAEZ,OAAOY,oBAAoB,GAC/EkB,SAAS,CAAC;YAACC,IAAIjC,qBAAqBiC,EAAE;QAAA;QACzC,OAAOO,KAAK7B,MAAM;IACpB;IACA,IAAIT,OAAOE,EAAE,EAAE,OAAO,MAAMD,KAAKD,OAAOE,EAAE;IAC1C,OAAO,MAAMN,KAAKuC,WAAW,CAAClC;AAChC;AAEA,OAAO,eAAesC,2BACpBR,EAAU;IAEV,MAAMO,OAAO,MAAM1C,KAChB4C,MAAM,GACNC,IAAI,CAAC3C,sBACLa,KAAK,CAACpB,GAAGO,qBAAqBiC,EAAE,EAAEA,KAClCW,KAAK,CAAC;IACT,MAAMC,MAAML,IAAI,CAAC,EAAE;IACnB,IAAI,CAACK,KAAK,OAAO3B;IACjB,OAAOnB,sBAAsB8C;AAC/B;AAEA,OAAO,eAAeC,oCACpBhC,oBAA4B;IAE5B,gHAAgH;IAChH,MAAM0B,OAAO,MAAM1C,KAChB4C,MAAM,GACNC,IAAI,CAAC3C,sBACLa,KAAK,CACJrB,IACEC,GAAGO,qBAAqBc,oBAAoB,EAAEA,uBAC9CrB,GAAGO,qBAAqByB,MAAM,EAAE,YAGnCmB,KAAK,CAAC;IACT,IAAIJ,KAAK7B,MAAM,GAAG,GAAG;QACnB,MAAM,IAAIuB,MACR,CAAC,oBAAoB,EAAEpB,qBAAqB,KAAK,EAAE0B,KAAK7B,MAAM,CAAC,oCAAoC,CAAC;IAExG;IACA,MAAMkC,MAAML,IAAI,CAAC,EAAE;IACnB,IAAI,CAACK,KAAK,OAAO3B;IACjB,OAAOnB,sBAAsB8C;AAC/B;AAQA,gFAAgF;AAChF,kFAAkF;AAClF,wDAAwD;AACxD,OAAO,eAAeE,0BACpB7C,MAAuC;IAEvC,MAAMsC,OAAO,MAAM1C,KAChB4C,MAAM,GACNC,IAAI,CAAC3C,sBACLa,KAAK,CACJrB,IACEC,GAAGO,qBAAqBuB,WAAW,EAAErB,OAAOqB,WAAW,GACvD9B,GAAGO,qBAAqByB,MAAM,EAAEvB,OAAOuB,MAAM,GAC7ChC,GAAGO,qBAAqB0B,KAAK,EAAExB,OAAOwB,KAAK;IAGjD,OAAOc,KAAK/B,GAAG,CAACV;AAClB;AAEA,OAAO,eAAeiD,yCACpBC,qBAA+B;IAE/B,IAAIA,sBAAsBtC,MAAM,KAAK,GAAG,OAAO,EAAE;IACjD,MAAM6B,OAAO,MAAM1C,KAChB4C,MAAM,GACNC,IAAI,CAAC3C,sBACLa,KAAK,CAACnB,QAAQM,qBAAqBc,oBAAoB,EAAEmC;IAC5D,OAAOT,KAAK/B,GAAG,CAACV;AAClB"}
@@ -0,0 +1,7 @@
1
+ import { type ShipfoxModule } from '@shipfox/node-module';
2
+ export type { JobListenerMatcherKind, JobListenerSubscription, } from '#core/entities/job-listener-subscription.js';
3
+ export type { TriggerSubscription } from '#core/entities/subscription.js';
4
+ export { fireCronSubscription, fireManualSubscription, ManualTriggerNotFoundError, TriggerSubscriptionNotCronError, TriggerSubscriptionNotFoundError, TriggerSubscriptionNotManualError, TriggerWorkspaceMismatchError, } from '#core/index.js';
5
+ export { db, findMatchingJobListenerSubscriptions, findMatchingSubscriptions, getManualSubscriptionByDefinitionId, getTriggerSubscriptionById, jobListenerSubscriptions, listSubscriptionsByWorkflowDefinitionIds, migrationsPath, projectJobListenerSubscriptions, removeJobListenerSubscriptionsForJob, triggersOutbox, } from '#db/index.js';
6
+ export declare const triggersModule: ShipfoxModule;
7
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAgBA,OAAO,EAAC,KAAK,aAAa,EAAoB,MAAM,sBAAsB,CAAC;AAiB3E,YAAY,EACV,sBAAsB,EACtB,uBAAuB,GACxB,MAAM,6CAA6C,CAAC;AACrD,YAAY,EAAC,mBAAmB,EAAC,MAAM,gCAAgC,CAAC;AACxE,OAAO,EACL,oBAAoB,EACpB,sBAAsB,EACtB,0BAA0B,EAC1B,+BAA+B,EAC/B,gCAAgC,EAChC,iCAAiC,EACjC,6BAA6B,GAC9B,MAAM,gBAAgB,CAAC;AACxB,OAAO,EACL,EAAE,EACF,oCAAoC,EACpC,yBAAyB,EACzB,mCAAmC,EACnC,0BAA0B,EAC1B,wBAAwB,EACxB,wCAAwC,EACxC,cAAc,EACd,+BAA+B,EAC/B,oCAAoC,EACpC,cAAc,GACf,MAAM,cAAc,CAAC;AAStB,eAAO,MAAM,cAAc,EAAE,aAuC5B,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,68 @@
1
+ import { dirname, resolve } from 'node:path';
2
+ import { fileURLToPath } from 'node:url';
3
+ import { DEFINITION_DELETED, DEFINITION_RESOLVED } from '@shipfox/api-definitions-dto';
4
+ import { INTEGRATION_EVENT_RECEIVED } from '@shipfox/api-integration-core-dto';
5
+ import { WORKFLOWS_JOB_ACTIVATED, WORKFLOWS_JOB_TERMINATED } from '@shipfox/api-workflows-dto';
6
+ import { subscriberFactory } from '@shipfox/node-module';
7
+ import { db, migrationsPath, triggersOutbox } from '#db/index.js';
8
+ import { registerTriggersServiceMetrics } from '#metrics/index.js';
9
+ import { routes } from '#presentation/index.js';
10
+ import { onDefinitionDeleted, onDefinitionResolved, onIntegrationEventReceived, onJobActivated, onJobTerminated } from '#presentation/subscribers/index.js';
11
+ import { createTriggersCronActivities, createTriggersMaintenanceActivities } from '#temporal/activities/index.js';
12
+ import { TRIGGERS_CRON_TASK_QUEUE, TRIGGERS_MAINTENANCE_TASK_QUEUE } from '#temporal/constants.js';
13
+ export { fireCronSubscription, fireManualSubscription, ManualTriggerNotFoundError, TriggerSubscriptionNotCronError, TriggerSubscriptionNotFoundError, TriggerSubscriptionNotManualError, TriggerWorkspaceMismatchError } from '#core/index.js';
14
+ export { db, findMatchingJobListenerSubscriptions, findMatchingSubscriptions, getManualSubscriptionByDefinitionId, getTriggerSubscriptionById, jobListenerSubscriptions, listSubscriptionsByWorkflowDefinitionIds, migrationsPath, projectJobListenerSubscriptions, removeJobListenerSubscriptionsForJob, triggersOutbox } from '#db/index.js';
15
+ const packageRoot = resolve(dirname(fileURLToPath(import.meta.url)), '..');
16
+ const temporalWorkflowsPath = resolve(packageRoot, 'dist/temporal/workflows/index.js');
17
+ const subscriber = subscriberFactory();
18
+ export const triggersModule = {
19
+ name: 'triggers',
20
+ database: {
21
+ db,
22
+ migrationsPath
23
+ },
24
+ routes,
25
+ metrics: registerTriggersServiceMetrics,
26
+ publishers: [
27
+ {
28
+ name: 'triggers',
29
+ table: triggersOutbox,
30
+ db
31
+ }
32
+ ],
33
+ subscribers: [
34
+ subscriber(DEFINITION_RESOLVED, onDefinitionResolved),
35
+ subscriber(DEFINITION_DELETED, onDefinitionDeleted),
36
+ subscriber(INTEGRATION_EVENT_RECEIVED, onIntegrationEventReceived),
37
+ subscriber(WORKFLOWS_JOB_ACTIVATED, onJobActivated),
38
+ subscriber(WORKFLOWS_JOB_TERMINATED, onJobTerminated)
39
+ ],
40
+ workers: [
41
+ {
42
+ taskQueue: TRIGGERS_MAINTENANCE_TASK_QUEUE,
43
+ workflowsPath: temporalWorkflowsPath,
44
+ activities: createTriggersMaintenanceActivities,
45
+ workflows: [
46
+ {
47
+ name: 'pruneTriggerEventsCron',
48
+ id: 'triggers-prune-trigger-events',
49
+ cronSchedule: '0 * * * *'
50
+ }
51
+ ]
52
+ },
53
+ {
54
+ taskQueue: TRIGGERS_CRON_TASK_QUEUE,
55
+ workflowsPath: temporalWorkflowsPath,
56
+ activities: createTriggersCronActivities,
57
+ workflows: [
58
+ {
59
+ name: 'cronTickCron',
60
+ id: 'triggers-cron-tick',
61
+ cronSchedule: '* * * * *'
62
+ }
63
+ ]
64
+ }
65
+ ]
66
+ };
67
+
68
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/index.ts"],"sourcesContent":["import {dirname, resolve} from 'node:path';\nimport {fileURLToPath} from 'node:url';\nimport {\n DEFINITION_DELETED,\n DEFINITION_RESOLVED,\n type DefinitionsEventMap,\n} from '@shipfox/api-definitions-dto';\nimport {\n INTEGRATION_EVENT_RECEIVED,\n type IntegrationsEventMap,\n} from '@shipfox/api-integration-core-dto';\nimport {\n WORKFLOWS_JOB_ACTIVATED,\n WORKFLOWS_JOB_TERMINATED,\n type WorkflowsEventMapDto,\n} from '@shipfox/api-workflows-dto';\nimport {type ShipfoxModule, subscriberFactory} from '@shipfox/node-module';\nimport {db, migrationsPath, triggersOutbox} from '#db/index.js';\nimport {registerTriggersServiceMetrics} from '#metrics/index.js';\nimport {routes} from '#presentation/index.js';\nimport {\n onDefinitionDeleted,\n onDefinitionResolved,\n onIntegrationEventReceived,\n onJobActivated,\n onJobTerminated,\n} from '#presentation/subscribers/index.js';\nimport {\n createTriggersCronActivities,\n createTriggersMaintenanceActivities,\n} from '#temporal/activities/index.js';\nimport {TRIGGERS_CRON_TASK_QUEUE, TRIGGERS_MAINTENANCE_TASK_QUEUE} from '#temporal/constants.js';\n\nexport type {\n JobListenerMatcherKind,\n JobListenerSubscription,\n} from '#core/entities/job-listener-subscription.js';\nexport type {TriggerSubscription} from '#core/entities/subscription.js';\nexport {\n fireCronSubscription,\n fireManualSubscription,\n ManualTriggerNotFoundError,\n TriggerSubscriptionNotCronError,\n TriggerSubscriptionNotFoundError,\n TriggerSubscriptionNotManualError,\n TriggerWorkspaceMismatchError,\n} from '#core/index.js';\nexport {\n db,\n findMatchingJobListenerSubscriptions,\n findMatchingSubscriptions,\n getManualSubscriptionByDefinitionId,\n getTriggerSubscriptionById,\n jobListenerSubscriptions,\n listSubscriptionsByWorkflowDefinitionIds,\n migrationsPath,\n projectJobListenerSubscriptions,\n removeJobListenerSubscriptionsForJob,\n triggersOutbox,\n} from '#db/index.js';\n\nconst packageRoot = resolve(dirname(fileURLToPath(import.meta.url)), '..');\nconst temporalWorkflowsPath = resolve(packageRoot, 'dist/temporal/workflows/index.js');\n\nconst subscriber = subscriberFactory<\n DefinitionsEventMap & IntegrationsEventMap & WorkflowsEventMapDto\n>();\n\nexport const triggersModule: ShipfoxModule = {\n name: 'triggers',\n database: {db, migrationsPath},\n routes,\n metrics: registerTriggersServiceMetrics,\n publishers: [{name: 'triggers', table: triggersOutbox, db}],\n subscribers: [\n subscriber(DEFINITION_RESOLVED, onDefinitionResolved),\n subscriber(DEFINITION_DELETED, onDefinitionDeleted),\n subscriber(INTEGRATION_EVENT_RECEIVED, onIntegrationEventReceived),\n subscriber(WORKFLOWS_JOB_ACTIVATED, onJobActivated),\n subscriber(WORKFLOWS_JOB_TERMINATED, onJobTerminated),\n ],\n workers: [\n {\n taskQueue: TRIGGERS_MAINTENANCE_TASK_QUEUE,\n workflowsPath: temporalWorkflowsPath,\n activities: createTriggersMaintenanceActivities,\n workflows: [\n {\n name: 'pruneTriggerEventsCron',\n id: 'triggers-prune-trigger-events',\n cronSchedule: '0 * * * *',\n },\n ],\n },\n {\n taskQueue: TRIGGERS_CRON_TASK_QUEUE,\n workflowsPath: temporalWorkflowsPath,\n activities: createTriggersCronActivities,\n workflows: [\n {\n name: 'cronTickCron',\n id: 'triggers-cron-tick',\n cronSchedule: '* * * * *',\n },\n ],\n },\n ],\n};\n"],"names":["dirname","resolve","fileURLToPath","DEFINITION_DELETED","DEFINITION_RESOLVED","INTEGRATION_EVENT_RECEIVED","WORKFLOWS_JOB_ACTIVATED","WORKFLOWS_JOB_TERMINATED","subscriberFactory","db","migrationsPath","triggersOutbox","registerTriggersServiceMetrics","routes","onDefinitionDeleted","onDefinitionResolved","onIntegrationEventReceived","onJobActivated","onJobTerminated","createTriggersCronActivities","createTriggersMaintenanceActivities","TRIGGERS_CRON_TASK_QUEUE","TRIGGERS_MAINTENANCE_TASK_QUEUE","fireCronSubscription","fireManualSubscription","ManualTriggerNotFoundError","TriggerSubscriptionNotCronError","TriggerSubscriptionNotFoundError","TriggerSubscriptionNotManualError","TriggerWorkspaceMismatchError","findMatchingJobListenerSubscriptions","findMatchingSubscriptions","getManualSubscriptionByDefinitionId","getTriggerSubscriptionById","jobListenerSubscriptions","listSubscriptionsByWorkflowDefinitionIds","projectJobListenerSubscriptions","removeJobListenerSubscriptionsForJob","packageRoot","url","temporalWorkflowsPath","subscriber","triggersModule","name","database","metrics","publishers","table","subscribers","workers","taskQueue","workflowsPath","activities","workflows","id","cronSchedule"],"mappings":"AAAA,SAAQA,OAAO,EAAEC,OAAO,QAAO,YAAY;AAC3C,SAAQC,aAAa,QAAO,WAAW;AACvC,SACEC,kBAAkB,EAClBC,mBAAmB,QAEd,+BAA+B;AACtC,SACEC,0BAA0B,QAErB,oCAAoC;AAC3C,SACEC,uBAAuB,EACvBC,wBAAwB,QAEnB,6BAA6B;AACpC,SAA4BC,iBAAiB,QAAO,uBAAuB;AAC3E,SAAQC,EAAE,EAAEC,cAAc,EAAEC,cAAc,QAAO,eAAe;AAChE,SAAQC,8BAA8B,QAAO,oBAAoB;AACjE,SAAQC,MAAM,QAAO,yBAAyB;AAC9C,SACEC,mBAAmB,EACnBC,oBAAoB,EACpBC,0BAA0B,EAC1BC,cAAc,EACdC,eAAe,QACV,qCAAqC;AAC5C,SACEC,4BAA4B,EAC5BC,mCAAmC,QAC9B,gCAAgC;AACvC,SAAQC,wBAAwB,EAAEC,+BAA+B,QAAO,yBAAyB;AAOjG,SACEC,oBAAoB,EACpBC,sBAAsB,EACtBC,0BAA0B,EAC1BC,+BAA+B,EAC/BC,gCAAgC,EAChCC,iCAAiC,EACjCC,6BAA6B,QACxB,iBAAiB;AACxB,SACEpB,EAAE,EACFqB,oCAAoC,EACpCC,yBAAyB,EACzBC,mCAAmC,EACnCC,0BAA0B,EAC1BC,wBAAwB,EACxBC,wCAAwC,EACxCzB,cAAc,EACd0B,+BAA+B,EAC/BC,oCAAoC,EACpC1B,cAAc,QACT,eAAe;AAEtB,MAAM2B,cAAcrC,QAAQD,QAAQE,cAAc,YAAYqC,GAAG,IAAI;AACrE,MAAMC,wBAAwBvC,QAAQqC,aAAa;AAEnD,MAAMG,aAAajC;AAInB,OAAO,MAAMkC,iBAAgC;IAC3CC,MAAM;IACNC,UAAU;QAACnC;QAAIC;IAAc;IAC7BG;IACAgC,SAASjC;IACTkC,YAAY;QAAC;YAACH,MAAM;YAAYI,OAAOpC;YAAgBF;QAAE;KAAE;IAC3DuC,aAAa;QACXP,WAAWrC,qBAAqBW;QAChC0B,WAAWtC,oBAAoBW;QAC/B2B,WAAWpC,4BAA4BW;QACvCyB,WAAWnC,yBAAyBW;QACpCwB,WAAWlC,0BAA0BW;KACtC;IACD+B,SAAS;QACP;YACEC,WAAW5B;YACX6B,eAAeX;YACfY,YAAYhC;YACZiC,WAAW;gBACT;oBACEV,MAAM;oBACNW,IAAI;oBACJC,cAAc;gBAChB;aACD;QACH;QACA;YACEL,WAAW7B;YACX8B,eAAeX;YACfY,YAAYjC;YACZkC,WAAW;gBACT;oBACEV,MAAM;oBACNW,IAAI;oBACJC,cAAc;gBAChB;aACD;QACH;KACD;AACH,EAAE"}
@@ -0,0 +1,3 @@
1
+ export { cronFiredCount, cronFireLag, eventOutcomeCount, eventReceivedCount, subscriptionTriggeredCount, } from './instance.js';
2
+ export { registerTriggersServiceMetrics } from './service.js';
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/metrics/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,cAAc,EACd,WAAW,EACX,iBAAiB,EACjB,kBAAkB,EAClB,0BAA0B,GAC3B,MAAM,eAAe,CAAC;AACvB,OAAO,EAAC,8BAA8B,EAAC,MAAM,cAAc,CAAC"}
@@ -0,0 +1,4 @@
1
+ export { cronFiredCount, cronFireLag, eventOutcomeCount, eventReceivedCount, subscriptionTriggeredCount } from './instance.js';
2
+ export { registerTriggersServiceMetrics } from './service.js';
3
+
4
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/metrics/index.ts"],"sourcesContent":["export {\n cronFiredCount,\n cronFireLag,\n eventOutcomeCount,\n eventReceivedCount,\n subscriptionTriggeredCount,\n} from './instance.js';\nexport {registerTriggersServiceMetrics} from './service.js';\n"],"names":["cronFiredCount","cronFireLag","eventOutcomeCount","eventReceivedCount","subscriptionTriggeredCount","registerTriggersServiceMetrics"],"mappings":"AAAA,SACEA,cAAc,EACdC,WAAW,EACXC,iBAAiB,EACjBC,kBAAkB,EAClBC,0BAA0B,QACrB,gBAAgB;AACvB,SAAQC,8BAA8B,QAAO,eAAe"}
@@ -0,0 +1,15 @@
1
+ export declare const eventReceivedCount: import("@shipfox/node-opentelemetry").Counter<{
2
+ provider: string;
3
+ }>;
4
+ export declare const subscriptionTriggeredCount: import("@shipfox/node-opentelemetry").Counter<{
5
+ provider: string;
6
+ }>;
7
+ export declare const eventOutcomeCount: import("@shipfox/node-opentelemetry").Counter<{
8
+ provider: string;
9
+ outcome: "discarded" | "routed" | "failed" | "errored";
10
+ }>;
11
+ export declare const cronFiredCount: import("@shipfox/node-opentelemetry").Counter<{
12
+ outcome: "fired" | "errored";
13
+ }>;
14
+ export declare const cronFireLag: import("@shipfox/node-opentelemetry").Histogram<Record<string, never>>;
15
+ //# sourceMappingURL=instance.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"instance.d.ts","sourceRoot":"","sources":["../../src/metrics/instance.ts"],"names":[],"mappings":"AAIA,eAAO,MAAM,kBAAkB;cACnB,MAAM;EAGhB,CAAC;AAEH,eAAO,MAAM,0BAA0B;cAC3B,MAAM;EAGhB,CAAC;AAEH,eAAO,MAAM,iBAAiB;cAClB,MAAM;aACP,WAAW,GAAG,QAAQ,GAAG,QAAQ,GAAG,SAAS;EAGtD,CAAC;AAEH,eAAO,MAAM,cAAc;aAAiC,OAAO,GAAG,SAAS;EAG9E,CAAC;AAEF,eAAO,MAAM,WAAW,wEAItB,CAAC"}
@@ -0,0 +1,32 @@
1
+ import { instanceMetrics } from '@shipfox/node-opentelemetry';
2
+ const meter = instanceMetrics.getMeter('triggers');
3
+ export const eventReceivedCount = meter.createCounter('triggers_event_received', {
4
+ description: 'Trigger events received by provider (e.g. github, gitea, sentry, manual)'
5
+ });
6
+ export const subscriptionTriggeredCount = meter.createCounter('triggers_subscription_triggered', {
7
+ description: 'Subscriptions that resulted in a workflow run, by provider'
8
+ });
9
+ export const eventOutcomeCount = meter.createCounter('triggers_event_outcome', {
10
+ description: 'Final outcomes of trigger events by provider and outcome'
11
+ });
12
+ export const cronFiredCount = meter.createCounter('triggers_cron_fired', {
13
+ description: 'Cron schedule slots consumed by the tick, by fire outcome'
14
+ });
15
+ export const cronFireLag = meter.createHistogram('triggers_cron_fire_lag', {
16
+ description: 'Delay between a cron scheduled slot and when the tick actually fired it',
17
+ unit: 'ms',
18
+ advice: {
19
+ explicitBucketBoundaries: [
20
+ 0,
21
+ 100,
22
+ 500,
23
+ 1000,
24
+ 5000,
25
+ 15000,
26
+ 60000,
27
+ 300000
28
+ ]
29
+ }
30
+ });
31
+
32
+ //# sourceMappingURL=instance.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/metrics/instance.ts"],"sourcesContent":["import {instanceMetrics} from '@shipfox/node-opentelemetry';\n\nconst meter = instanceMetrics.getMeter('triggers');\n\nexport const eventReceivedCount = meter.createCounter<{\n provider: string;\n}>('triggers_event_received', {\n description: 'Trigger events received by provider (e.g. github, gitea, sentry, manual)',\n});\n\nexport const subscriptionTriggeredCount = meter.createCounter<{\n provider: string;\n}>('triggers_subscription_triggered', {\n description: 'Subscriptions that resulted in a workflow run, by provider',\n});\n\nexport const eventOutcomeCount = meter.createCounter<{\n provider: string;\n outcome: 'discarded' | 'routed' | 'failed' | 'errored';\n}>('triggers_event_outcome', {\n description: 'Final outcomes of trigger events by provider and outcome',\n});\n\nexport const cronFiredCount = meter.createCounter<{outcome: 'fired' | 'errored'}>(\n 'triggers_cron_fired',\n {description: 'Cron schedule slots consumed by the tick, by fire outcome'},\n);\n\nexport const cronFireLag = meter.createHistogram<Record<string, never>>('triggers_cron_fire_lag', {\n description: 'Delay between a cron scheduled slot and when the tick actually fired it',\n unit: 'ms',\n advice: {explicitBucketBoundaries: [0, 100, 500, 1000, 5000, 15000, 60000, 300000]},\n});\n"],"names":["instanceMetrics","meter","getMeter","eventReceivedCount","createCounter","description","subscriptionTriggeredCount","eventOutcomeCount","cronFiredCount","cronFireLag","createHistogram","unit","advice","explicitBucketBoundaries"],"mappings":"AAAA,SAAQA,eAAe,QAAO,8BAA8B;AAE5D,MAAMC,QAAQD,gBAAgBE,QAAQ,CAAC;AAEvC,OAAO,MAAMC,qBAAqBF,MAAMG,aAAa,CAElD,2BAA2B;IAC5BC,aAAa;AACf,GAAG;AAEH,OAAO,MAAMC,6BAA6BL,MAAMG,aAAa,CAE1D,mCAAmC;IACpCC,aAAa;AACf,GAAG;AAEH,OAAO,MAAME,oBAAoBN,MAAMG,aAAa,CAGjD,0BAA0B;IAC3BC,aAAa;AACf,GAAG;AAEH,OAAO,MAAMG,iBAAiBP,MAAMG,aAAa,CAC/C,uBACA;IAACC,aAAa;AAA2D,GACzE;AAEF,OAAO,MAAMI,cAAcR,MAAMS,eAAe,CAAwB,0BAA0B;IAChGL,aAAa;IACbM,MAAM;IACNC,QAAQ;QAACC,0BAA0B;YAAC;YAAG;YAAK;YAAK;YAAM;YAAM;YAAO;YAAO;SAAO;IAAA;AACpF,GAAG"}
@@ -0,0 +1,2 @@
1
+ export declare function registerTriggersServiceMetrics(): void;
2
+ //# sourceMappingURL=service.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"service.d.ts","sourceRoot":"","sources":["../../src/metrics/service.ts"],"names":[],"mappings":"AAGA,wBAAgB,8BAA8B,IAAI,IAAI,CAcrD"}
@@ -0,0 +1,15 @@
1
+ import { getServiceMetricsProvider } from '@shipfox/node-opentelemetry';
2
+ import { countDueCronSchedules } from '#db/cron-schedules.js';
3
+ export function registerTriggersServiceMetrics() {
4
+ const meter = getServiceMetricsProvider().getMeter('triggers');
5
+ const cronBacklog = meter.createObservableGauge('triggers_cron_backlog', {
6
+ description: 'Cron schedules past their next fire time and still pending a fire (including any a drain is mid-flight on). A sustained nonzero value means the minute tick is falling behind; raise TRIGGER_CRON_FANOUT, TRIGGER_CRON_CLAIM_BATCH, or pod count.'
7
+ });
8
+ meter.addBatchObservableCallback(async (observer)=>{
9
+ observer.observe(cronBacklog, await countDueCronSchedules());
10
+ }, [
11
+ cronBacklog
12
+ ]);
13
+ }
14
+
15
+ //# sourceMappingURL=service.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/metrics/service.ts"],"sourcesContent":["import {getServiceMetricsProvider} from '@shipfox/node-opentelemetry';\nimport {countDueCronSchedules} from '#db/cron-schedules.js';\n\nexport function registerTriggersServiceMetrics(): void {\n const meter = getServiceMetricsProvider().getMeter('triggers');\n\n const cronBacklog = meter.createObservableGauge('triggers_cron_backlog', {\n description:\n 'Cron schedules past their next fire time and still pending a fire (including any a drain is mid-flight on). A sustained nonzero value means the minute tick is falling behind; raise TRIGGER_CRON_FANOUT, TRIGGER_CRON_CLAIM_BATCH, or pod count.',\n });\n\n meter.addBatchObservableCallback(\n async (observer) => {\n observer.observe(cronBacklog, await countDueCronSchedules());\n },\n [cronBacklog],\n );\n}\n"],"names":["getServiceMetricsProvider","countDueCronSchedules","registerTriggersServiceMetrics","meter","getMeter","cronBacklog","createObservableGauge","description","addBatchObservableCallback","observer","observe"],"mappings":"AAAA,SAAQA,yBAAyB,QAAO,8BAA8B;AACtE,SAAQC,qBAAqB,QAAO,wBAAwB;AAE5D,OAAO,SAASC;IACd,MAAMC,QAAQH,4BAA4BI,QAAQ,CAAC;IAEnD,MAAMC,cAAcF,MAAMG,qBAAqB,CAAC,yBAAyB;QACvEC,aACE;IACJ;IAEAJ,MAAMK,0BAA0B,CAC9B,OAAOC;QACLA,SAASC,OAAO,CAACL,aAAa,MAAMJ;IACtC,GACA;QAACI;KAAY;AAEjB"}
@@ -0,0 +1,7 @@
1
+ import type { TriggerDecisionDto, TriggerEventDto, TriggerEventListItemDto } from '@shipfox/api-triggers-dto';
2
+ import type { TriggerDecision } from '#core/entities/decision.js';
3
+ import type { TriggerReceivedEvent, TriggerReceivedEventSummary } from '#core/entities/received-event.js';
4
+ export declare function toTriggerEventListItemDto(event: TriggerReceivedEventSummary): TriggerEventListItemDto;
5
+ export declare function toTriggerEventDto(event: TriggerReceivedEvent): TriggerEventDto;
6
+ export declare function toTriggerDecisionDto(decision: TriggerDecision): TriggerDecisionDto;
7
+ //# sourceMappingURL=trigger-events.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"trigger-events.d.ts","sourceRoot":"","sources":["../../../src/presentation/dto/trigger-events.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,kBAAkB,EAClB,eAAe,EACf,uBAAuB,EACxB,MAAM,2BAA2B,CAAC;AACnC,OAAO,KAAK,EAAC,eAAe,EAAC,MAAM,4BAA4B,CAAC;AAChE,OAAO,KAAK,EACV,oBAAoB,EACpB,2BAA2B,EAC5B,MAAM,kCAAkC,CAAC;AAE1C,wBAAgB,yBAAyB,CACvC,KAAK,EAAE,2BAA2B,GACjC,uBAAuB,CAiBzB;AAED,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,oBAAoB,GAAG,eAAe,CAM9E;AAED,wBAAgB,oBAAoB,CAAC,QAAQ,EAAE,eAAe,GAAG,kBAAkB,CAmBlF"}