nvent 0.4.4 → 0.5.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 (293) hide show
  1. package/dist/module.d.mts +4 -185
  2. package/dist/module.json +3 -3
  3. package/dist/module.mjs +451 -257
  4. package/dist/runtime/adapters/base/index.d.ts +6 -0
  5. package/dist/runtime/adapters/base/index.js +1 -0
  6. package/dist/runtime/adapters/base/store-validator.d.ts +48 -0
  7. package/dist/runtime/adapters/base/store-validator.js +147 -0
  8. package/dist/runtime/adapters/builtin/file-queue.d.ts +67 -0
  9. package/dist/runtime/adapters/builtin/file-queue.js +499 -0
  10. package/dist/runtime/adapters/builtin/file-store.d.ts +32 -0
  11. package/dist/runtime/adapters/builtin/file-store.js +206 -0
  12. package/dist/runtime/adapters/builtin/file-stream.d.ts +39 -0
  13. package/dist/runtime/adapters/builtin/file-stream.js +56 -0
  14. package/dist/runtime/adapters/builtin/index.d.ts +10 -0
  15. package/dist/runtime/adapters/builtin/index.js +5 -0
  16. package/dist/runtime/adapters/builtin/memory-queue.d.ts +52 -0
  17. package/dist/runtime/adapters/builtin/memory-queue.js +243 -0
  18. package/dist/runtime/adapters/builtin/memory-store.d.ts +68 -0
  19. package/dist/runtime/adapters/builtin/memory-store.js +333 -0
  20. package/dist/runtime/adapters/builtin/memory-stream.d.ts +21 -0
  21. package/dist/runtime/adapters/builtin/memory-stream.js +56 -0
  22. package/dist/runtime/adapters/factory.d.ts +31 -0
  23. package/dist/runtime/adapters/factory.js +134 -0
  24. package/dist/runtime/adapters/index.d.ts +8 -0
  25. package/dist/runtime/adapters/index.js +3 -0
  26. package/dist/runtime/adapters/interfaces/index.d.ts +11 -0
  27. package/dist/runtime/adapters/interfaces/index.js +3 -0
  28. package/dist/runtime/adapters/interfaces/queue.d.ts +150 -0
  29. package/dist/runtime/adapters/interfaces/store.d.ts +297 -0
  30. package/dist/runtime/adapters/interfaces/stream.d.ts +62 -0
  31. package/dist/runtime/adapters/registry.d.ts +85 -0
  32. package/dist/runtime/adapters/registry.js +161 -0
  33. package/dist/runtime/config/index.d.ts +29 -0
  34. package/dist/runtime/config/index.js +175 -0
  35. package/dist/runtime/config/types.d.ts +397 -0
  36. package/dist/runtime/config/types.js +0 -0
  37. package/dist/runtime/{server-utils/events → events}/eventBus.d.ts +1 -1
  38. package/dist/runtime/events/types.d.ts +145 -0
  39. package/dist/runtime/events/types.js +0 -0
  40. package/dist/runtime/events/utils/scheduleTrigger.d.ts +8 -0
  41. package/dist/runtime/events/utils/scheduleTrigger.js +69 -0
  42. package/dist/runtime/events/utils/stallDetector.d.ts +140 -0
  43. package/dist/runtime/events/utils/stallDetector.js +436 -0
  44. package/dist/runtime/events/utils/triggerRuntime.d.ts +58 -0
  45. package/dist/runtime/events/utils/triggerRuntime.js +212 -0
  46. package/dist/runtime/{server-utils/events → events}/wiring/flowWiring.d.ts +12 -11
  47. package/dist/runtime/events/wiring/flowWiring.js +1020 -0
  48. package/dist/runtime/events/wiring/registry.d.ts +19 -0
  49. package/dist/runtime/events/wiring/registry.js +35 -0
  50. package/dist/runtime/events/wiring/stateWiring.d.ts +37 -0
  51. package/dist/runtime/events/wiring/stateWiring.js +92 -0
  52. package/dist/runtime/events/wiring/streamWiring.d.ts +36 -0
  53. package/dist/runtime/events/wiring/streamWiring.js +156 -0
  54. package/dist/runtime/events/wiring/triggerWiring.d.ts +21 -0
  55. package/dist/runtime/events/wiring/triggerWiring.js +412 -0
  56. package/dist/runtime/nitro/plugins/00.adapters.d.ts +14 -0
  57. package/dist/runtime/nitro/plugins/00.adapters.js +73 -0
  58. package/dist/runtime/nitro/plugins/02.workers.js +63 -0
  59. package/dist/runtime/nitro/plugins/03.triggers.d.ts +12 -0
  60. package/dist/runtime/nitro/plugins/03.triggers.js +55 -0
  61. package/dist/runtime/nitro/routes/webhook.await.d.ts +23 -0
  62. package/dist/runtime/nitro/routes/webhook.await.js +90 -0
  63. package/dist/runtime/nitro/routes/webhook.trigger.d.ts +69 -0
  64. package/dist/runtime/nitro/routes/webhook.trigger.js +64 -0
  65. package/dist/runtime/nitro/utils/adapters.d.ts +66 -0
  66. package/dist/runtime/nitro/utils/adapters.js +51 -0
  67. package/dist/runtime/nitro/utils/awaitPatterns/event.d.ts +15 -0
  68. package/dist/runtime/nitro/utils/awaitPatterns/event.js +120 -0
  69. package/dist/runtime/nitro/utils/awaitPatterns/index.d.ts +28 -0
  70. package/dist/runtime/nitro/utils/awaitPatterns/index.js +55 -0
  71. package/dist/runtime/nitro/utils/awaitPatterns/schedule.d.ts +16 -0
  72. package/dist/runtime/nitro/utils/awaitPatterns/schedule.js +78 -0
  73. package/dist/runtime/nitro/utils/awaitPatterns/time.d.ts +15 -0
  74. package/dist/runtime/nitro/utils/awaitPatterns/time.js +67 -0
  75. package/dist/runtime/nitro/utils/awaitPatterns/webhook.d.ts +15 -0
  76. package/dist/runtime/nitro/utils/awaitPatterns/webhook.js +120 -0
  77. package/dist/runtime/nitro/utils/defineFunction.d.ts +10 -0
  78. package/dist/runtime/nitro/utils/defineFunction.js +17 -0
  79. package/dist/runtime/nitro/utils/defineFunctionConfig.d.ts +310 -0
  80. package/dist/runtime/nitro/utils/defineFunctionConfig.js +3 -0
  81. package/dist/runtime/nitro/utils/defineHooks.d.ts +41 -0
  82. package/dist/runtime/nitro/utils/defineHooks.js +6 -0
  83. package/dist/runtime/nitro/utils/registerAdapter.d.ts +59 -0
  84. package/dist/runtime/nitro/utils/registerAdapter.js +13 -0
  85. package/dist/runtime/nitro/utils/useAwait.d.ts +71 -0
  86. package/dist/runtime/nitro/utils/useAwait.js +139 -0
  87. package/dist/runtime/{server-utils → nitro}/utils/useEventManager.d.ts +2 -2
  88. package/dist/runtime/{server-utils → nitro}/utils/useEventManager.js +1 -1
  89. package/dist/runtime/nitro/utils/useFlow.d.ts +68 -0
  90. package/dist/runtime/nitro/utils/useFlow.js +226 -0
  91. package/dist/runtime/nitro/utils/useHookRegistry.d.ts +34 -0
  92. package/dist/runtime/nitro/utils/useHookRegistry.js +25 -0
  93. package/dist/runtime/{server-utils → nitro}/utils/useNventLogger.js +2 -2
  94. package/dist/runtime/nitro/utils/useRunContext.d.ts +6 -0
  95. package/dist/runtime/nitro/utils/useRunContext.js +102 -0
  96. package/dist/runtime/nitro/utils/useStreamTopics.d.ts +83 -0
  97. package/dist/runtime/nitro/utils/useStreamTopics.js +94 -0
  98. package/dist/runtime/nitro/utils/useTrigger.d.ts +150 -0
  99. package/dist/runtime/nitro/utils/useTrigger.js +320 -0
  100. package/dist/runtime/scheduler/index.d.ts +33 -0
  101. package/dist/runtime/scheduler/index.js +38 -0
  102. package/dist/runtime/scheduler/scheduler.d.ts +113 -0
  103. package/dist/runtime/scheduler/scheduler.js +623 -0
  104. package/dist/runtime/scheduler/types.d.ts +116 -0
  105. package/dist/runtime/scheduler/types.js +0 -0
  106. package/dist/runtime/tsconfig.json +8 -0
  107. package/dist/runtime/worker/node/runner.d.ts +53 -0
  108. package/dist/runtime/worker/node/runner.js +327 -0
  109. package/dist/types.d.mts +2 -2
  110. package/package.json +16 -46
  111. package/LICENSE +0 -21
  112. package/README.md +0 -389
  113. package/dist/runtime/app/assets/vueflow.css +0 -1
  114. package/dist/runtime/app/components/ConfirmDialog.d.vue.ts +0 -33
  115. package/dist/runtime/app/components/ConfirmDialog.vue +0 -121
  116. package/dist/runtime/app/components/ConfirmDialog.vue.d.ts +0 -33
  117. package/dist/runtime/app/components/FlowDiagram.d.vue.ts +0 -64
  118. package/dist/runtime/app/components/FlowDiagram.vue +0 -338
  119. package/dist/runtime/app/components/FlowDiagram.vue.d.ts +0 -64
  120. package/dist/runtime/app/components/FlowNodeCard.d.vue.ts +0 -29
  121. package/dist/runtime/app/components/FlowNodeCard.vue +0 -156
  122. package/dist/runtime/app/components/FlowNodeCard.vue.d.ts +0 -29
  123. package/dist/runtime/app/components/FlowRunOverview.d.vue.ts +0 -9
  124. package/dist/runtime/app/components/FlowRunOverview.vue +0 -291
  125. package/dist/runtime/app/components/FlowRunOverview.vue.d.ts +0 -9
  126. package/dist/runtime/app/components/FlowRunStatusBadge.d.vue.ts +0 -14
  127. package/dist/runtime/app/components/FlowRunStatusBadge.vue +0 -60
  128. package/dist/runtime/app/components/FlowRunStatusBadge.vue.d.ts +0 -14
  129. package/dist/runtime/app/components/FlowRunTimeline.d.vue.ts +0 -12
  130. package/dist/runtime/app/components/FlowRunTimeline.vue +0 -127
  131. package/dist/runtime/app/components/FlowRunTimeline.vue.d.ts +0 -12
  132. package/dist/runtime/app/components/FlowScheduleDialog.d.vue.ts +0 -16
  133. package/dist/runtime/app/components/FlowScheduleDialog.vue +0 -226
  134. package/dist/runtime/app/components/FlowScheduleDialog.vue.d.ts +0 -16
  135. package/dist/runtime/app/components/FlowSchedulesList.d.vue.ts +0 -12
  136. package/dist/runtime/app/components/FlowSchedulesList.vue +0 -99
  137. package/dist/runtime/app/components/FlowSchedulesList.vue.d.ts +0 -12
  138. package/dist/runtime/app/components/JobScheduling.d.vue.ts +0 -6
  139. package/dist/runtime/app/components/JobScheduling.vue +0 -203
  140. package/dist/runtime/app/components/JobScheduling.vue.d.ts +0 -6
  141. package/dist/runtime/app/components/ListItem.d.vue.ts +0 -23
  142. package/dist/runtime/app/components/ListItem.vue +0 -70
  143. package/dist/runtime/app/components/ListItem.vue.d.ts +0 -23
  144. package/dist/runtime/app/components/QueueConfigDetails.d.vue.ts +0 -45
  145. package/dist/runtime/app/components/QueueConfigDetails.vue +0 -412
  146. package/dist/runtime/app/components/QueueConfigDetails.vue.d.ts +0 -45
  147. package/dist/runtime/app/components/StatCounter.d.vue.ts +0 -9
  148. package/dist/runtime/app/components/StatCounter.vue +0 -25
  149. package/dist/runtime/app/components/StatCounter.vue.d.ts +0 -9
  150. package/dist/runtime/app/components/TimelineList.d.vue.ts +0 -7
  151. package/dist/runtime/app/components/TimelineList.vue +0 -210
  152. package/dist/runtime/app/components/TimelineList.vue.d.ts +0 -7
  153. package/dist/runtime/app/components/nhealth/component-router.d.vue.ts +0 -46
  154. package/dist/runtime/app/components/nhealth/component-router.vue +0 -26
  155. package/dist/runtime/app/components/nhealth/component-router.vue.d.ts +0 -46
  156. package/dist/runtime/app/components/nhealth/component-shell.d.vue.ts +0 -24
  157. package/dist/runtime/app/components/nhealth/component-shell.vue +0 -89
  158. package/dist/runtime/app/components/nhealth/component-shell.vue.d.ts +0 -24
  159. package/dist/runtime/app/composables/useAnalyzedFlows.d.ts +0 -14
  160. package/dist/runtime/app/composables/useAnalyzedFlows.js +0 -8
  161. package/dist/runtime/app/composables/useComponentRouter.d.ts +0 -38
  162. package/dist/runtime/app/composables/useComponentRouter.js +0 -240
  163. package/dist/runtime/app/composables/useFlowRunTimeline.d.ts +0 -80
  164. package/dist/runtime/app/composables/useFlowRunTimeline.js +0 -68
  165. package/dist/runtime/app/composables/useFlowRuns.d.ts +0 -18
  166. package/dist/runtime/app/composables/useFlowRuns.js +0 -32
  167. package/dist/runtime/app/composables/useFlowRunsInfinite.d.ts +0 -24
  168. package/dist/runtime/app/composables/useFlowRunsInfinite.js +0 -123
  169. package/dist/runtime/app/composables/useFlowRunsPolling.d.ts +0 -9
  170. package/dist/runtime/app/composables/useFlowRunsPolling.js +0 -33
  171. package/dist/runtime/app/composables/useFlowState.d.ts +0 -125
  172. package/dist/runtime/app/composables/useFlowState.js +0 -211
  173. package/dist/runtime/app/composables/useFlowWebSocket.d.ts +0 -27
  174. package/dist/runtime/app/composables/useFlowWebSocket.js +0 -205
  175. package/dist/runtime/app/composables/useFlowsNavigation.d.ts +0 -10
  176. package/dist/runtime/app/composables/useFlowsNavigation.js +0 -58
  177. package/dist/runtime/app/composables/useQueueJobs.d.ts +0 -26
  178. package/dist/runtime/app/composables/useQueueJobs.js +0 -20
  179. package/dist/runtime/app/composables/useQueueUpdates.d.ts +0 -26
  180. package/dist/runtime/app/composables/useQueueUpdates.js +0 -122
  181. package/dist/runtime/app/composables/useQueues.d.ts +0 -45
  182. package/dist/runtime/app/composables/useQueues.js +0 -26
  183. package/dist/runtime/app/composables/useQueuesLive.d.ts +0 -19
  184. package/dist/runtime/app/composables/useQueuesLive.js +0 -143
  185. package/dist/runtime/app/pages/flows/index.d.vue.ts +0 -3
  186. package/dist/runtime/app/pages/flows/index.vue +0 -645
  187. package/dist/runtime/app/pages/flows/index.vue.d.ts +0 -3
  188. package/dist/runtime/app/pages/index.d.vue.ts +0 -3
  189. package/dist/runtime/app/pages/index.vue +0 -34
  190. package/dist/runtime/app/pages/index.vue.d.ts +0 -3
  191. package/dist/runtime/app/pages/queues/index.d.vue.ts +0 -3
  192. package/dist/runtime/app/pages/queues/index.vue +0 -229
  193. package/dist/runtime/app/pages/queues/index.vue.d.ts +0 -3
  194. package/dist/runtime/app/pages/queues/job.d.vue.ts +0 -3
  195. package/dist/runtime/app/pages/queues/job.vue +0 -262
  196. package/dist/runtime/app/pages/queues/job.vue.d.ts +0 -3
  197. package/dist/runtime/app/pages/queues/jobs.d.vue.ts +0 -3
  198. package/dist/runtime/app/pages/queues/jobs.vue +0 -291
  199. package/dist/runtime/app/pages/queues/jobs.vue.d.ts +0 -3
  200. package/dist/runtime/app/plugins/vueflow.client.d.ts +0 -2
  201. package/dist/runtime/app/plugins/vueflow.client.js +0 -11
  202. package/dist/runtime/constants.d.ts +0 -11
  203. package/dist/runtime/constants.js +0 -11
  204. package/dist/runtime/schema.d.ts +0 -37
  205. package/dist/runtime/schema.js +0 -20
  206. package/dist/runtime/server/api/_flows/[name]/clear-history.delete.d.ts +0 -10
  207. package/dist/runtime/server/api/_flows/[name]/clear-history.delete.js +0 -44
  208. package/dist/runtime/server/api/_flows/[name]/runs.get.d.ts +0 -7
  209. package/dist/runtime/server/api/_flows/[name]/runs.get.js +0 -53
  210. package/dist/runtime/server/api/_flows/[name]/schedule.post.js +0 -57
  211. package/dist/runtime/server/api/_flows/[name]/schedules/[id].delete.d.ts +0 -2
  212. package/dist/runtime/server/api/_flows/[name]/schedules/[id].delete.js +0 -42
  213. package/dist/runtime/server/api/_flows/[name]/schedules.get.d.ts +0 -2
  214. package/dist/runtime/server/api/_flows/[name]/schedules.get.js +0 -48
  215. package/dist/runtime/server/api/_flows/[name]/start.post.d.ts +0 -2
  216. package/dist/runtime/server/api/_flows/[name]/start.post.js +0 -9
  217. package/dist/runtime/server/api/_flows/index.get.d.ts +0 -6
  218. package/dist/runtime/server/api/_flows/index.get.js +0 -5
  219. package/dist/runtime/server/api/_flows/ws.d.ts +0 -60
  220. package/dist/runtime/server/api/_flows/ws.js +0 -188
  221. package/dist/runtime/server/api/_queues/[name]/job/[id].get.d.ts +0 -2
  222. package/dist/runtime/server/api/_queues/[name]/job/[id].get.js +0 -9
  223. package/dist/runtime/server/api/_queues/[name]/job/index.get.d.ts +0 -2
  224. package/dist/runtime/server/api/_queues/[name]/job/index.get.js +0 -18
  225. package/dist/runtime/server/api/_queues/index.get.d.ts +0 -2
  226. package/dist/runtime/server/api/_queues/index.get.js +0 -63
  227. package/dist/runtime/server/api/_queues/ws.d.ts +0 -48
  228. package/dist/runtime/server/api/_queues/ws.js +0 -205
  229. package/dist/runtime/server/plugins/00.event-store.d.ts +0 -13
  230. package/dist/runtime/server/plugins/00.event-store.js +0 -16
  231. package/dist/runtime/server/plugins/flow-management.d.ts +0 -13
  232. package/dist/runtime/server/plugins/flow-management.js +0 -65
  233. package/dist/runtime/server/plugins/queue-management.d.ts +0 -2
  234. package/dist/runtime/server/plugins/queue-management.js +0 -27
  235. package/dist/runtime/server/plugins/state-cleanup.d.ts +0 -11
  236. package/dist/runtime/server/plugins/state-cleanup.js +0 -93
  237. package/dist/runtime/server/plugins/worker-management.d.ts +0 -2
  238. package/dist/runtime/server/plugins/worker-management.js +0 -33
  239. package/dist/runtime/server/tsconfig.json +0 -3
  240. package/dist/runtime/server-utils/events/adapters/fileAdapter.d.ts +0 -2
  241. package/dist/runtime/server-utils/events/adapters/fileAdapter.js +0 -382
  242. package/dist/runtime/server-utils/events/adapters/memoryAdapter.d.ts +0 -2
  243. package/dist/runtime/server-utils/events/adapters/memoryAdapter.js +0 -171
  244. package/dist/runtime/server-utils/events/adapters/redis/redisAdapter.d.ts +0 -2
  245. package/dist/runtime/server-utils/events/adapters/redis/redisAdapter.js +0 -348
  246. package/dist/runtime/server-utils/events/adapters/redis/redisPubSubGateway.d.ts +0 -30
  247. package/dist/runtime/server-utils/events/adapters/redis/redisPubSubGateway.js +0 -82
  248. package/dist/runtime/server-utils/events/eventStoreFactory.d.ts +0 -19
  249. package/dist/runtime/server-utils/events/eventStoreFactory.js +0 -44
  250. package/dist/runtime/server-utils/events/streamNames.d.ts +0 -17
  251. package/dist/runtime/server-utils/events/streamNames.js +0 -17
  252. package/dist/runtime/server-utils/events/types.d.ts +0 -63
  253. package/dist/runtime/server-utils/events/wiring/flowWiring.js +0 -409
  254. package/dist/runtime/server-utils/events/wiring/registry.d.ts +0 -10
  255. package/dist/runtime/server-utils/events/wiring/registry.js +0 -24
  256. package/dist/runtime/server-utils/queue/adapters/bullmq.d.ts +0 -18
  257. package/dist/runtime/server-utils/queue/adapters/bullmq.js +0 -164
  258. package/dist/runtime/server-utils/queue/queueFactory.d.ts +0 -3
  259. package/dist/runtime/server-utils/queue/queueFactory.js +0 -10
  260. package/dist/runtime/server-utils/queue/types.d.ts +0 -47
  261. package/dist/runtime/server-utils/state/adapters/redis.d.ts +0 -2
  262. package/dist/runtime/server-utils/state/adapters/redis.js +0 -42
  263. package/dist/runtime/server-utils/state/stateFactory.d.ts +0 -3
  264. package/dist/runtime/server-utils/state/stateFactory.js +0 -17
  265. package/dist/runtime/server-utils/state/types.d.ts +0 -23
  266. package/dist/runtime/server-utils/utils/defineQueueConfig.d.ts +0 -154
  267. package/dist/runtime/server-utils/utils/defineQueueConfig.js +0 -2
  268. package/dist/runtime/server-utils/utils/defineQueueWorker.d.ts +0 -10
  269. package/dist/runtime/server-utils/utils/defineQueueWorker.js +0 -17
  270. package/dist/runtime/server-utils/utils/useEventStore.d.ts +0 -20
  271. package/dist/runtime/server-utils/utils/useEventStore.js +0 -119
  272. package/dist/runtime/server-utils/utils/useFlowEngine.d.ts +0 -9
  273. package/dist/runtime/server-utils/utils/useFlowEngine.js +0 -44
  274. package/dist/runtime/server-utils/utils/useLogs.d.ts +0 -41
  275. package/dist/runtime/server-utils/utils/useLogs.js +0 -74
  276. package/dist/runtime/server-utils/utils/useQueue.d.ts +0 -31
  277. package/dist/runtime/server-utils/utils/useQueue.js +0 -24
  278. package/dist/runtime/server-utils/worker/adapter.d.ts +0 -4
  279. package/dist/runtime/server-utils/worker/adapter.js +0 -66
  280. package/dist/runtime/server-utils/worker/runner/node.d.ts +0 -27
  281. package/dist/runtime/server-utils/worker/runner/node.js +0 -196
  282. package/dist/runtime/types.d.ts +0 -132
  283. /package/dist/runtime/{server-utils/events/types.js → adapters/interfaces/queue.js} +0 -0
  284. /package/dist/runtime/{server-utils/queue/types.js → adapters/interfaces/store.js} +0 -0
  285. /package/dist/runtime/{server-utils/state/types.js → adapters/interfaces/stream.js} +0 -0
  286. /package/dist/runtime/{server-utils/events → events}/eventBus.js +0 -0
  287. /package/dist/runtime/{server/plugins/00.ws-lifecycle.d.ts → nitro/plugins/01.ws-lifecycle.d.ts} +0 -0
  288. /package/dist/runtime/{server/plugins/00.ws-lifecycle.js → nitro/plugins/01.ws-lifecycle.js} +0 -0
  289. /package/dist/runtime/{server/api/_flows/[name]/schedule.post.d.ts → nitro/plugins/02.workers.d.ts} +0 -0
  290. /package/dist/runtime/{server-utils → nitro}/utils/useNventLogger.d.ts +0 -0
  291. /package/dist/runtime/{server-utils → nitro}/utils/wsPeerManager.d.ts +0 -0
  292. /package/dist/runtime/{server-utils → nitro}/utils/wsPeerManager.js +0 -0
  293. /package/dist/runtime/{python → worker/python}/get_config.py +0 -0
@@ -0,0 +1,320 @@
1
+ import { useStoreAdapter, useNventLogger, useStreamTopics } from "#imports";
2
+ import { getEventBus } from "../../events/eventBus.js";
3
+ import { getTriggerRuntime } from "../../events/utils/triggerRuntime.js";
4
+ export async function resolvePayload(data) {
5
+ const logger = useNventLogger("trigger");
6
+ const store = useStoreAdapter();
7
+ const runtime = getTriggerRuntime(store, logger);
8
+ return runtime.resolvePayload(data);
9
+ }
10
+ export function useTrigger() {
11
+ const logger = useNventLogger("trigger");
12
+ const store = useStoreAdapter();
13
+ const runtime = getTriggerRuntime(store, logger);
14
+ return {
15
+ /**
16
+ * Register a trigger (programmatic)
17
+ * Publishes event to bus - triggerWiring handles persistence and orchestration
18
+ */
19
+ async registerTrigger(opts) {
20
+ const eventBus = getEventBus();
21
+ const existing = runtime.getTrigger(opts.name);
22
+ const isUpdate = !!existing;
23
+ if (isUpdate) {
24
+ logger.info(`Updating trigger: ${opts.name}`);
25
+ await eventBus.publish({
26
+ type: "trigger.updated",
27
+ triggerName: opts.name,
28
+ data: {
29
+ type: opts.type,
30
+ scope: opts.scope,
31
+ status: opts.status,
32
+ displayName: opts.displayName,
33
+ description: opts.description,
34
+ source: opts.source || "programmatic",
35
+ webhook: opts.webhook,
36
+ schedule: opts.schedule,
37
+ config: opts.config,
38
+ expectedSubscribers: opts.expectedSubscribers
39
+ }
40
+ });
41
+ } else {
42
+ logger.info(`Registering trigger: ${opts.name}`);
43
+ await eventBus.publish({
44
+ type: "trigger.registered",
45
+ triggerName: opts.name,
46
+ data: {
47
+ name: opts.name,
48
+ type: opts.type,
49
+ scope: opts.scope,
50
+ displayName: opts.displayName,
51
+ description: opts.description,
52
+ source: opts.source || "programmatic",
53
+ expectedSubscribers: opts.expectedSubscribers,
54
+ webhook: opts.webhook,
55
+ schedule: opts.schedule,
56
+ config: opts.config
57
+ }
58
+ });
59
+ }
60
+ },
61
+ /**
62
+ * Subscribe flow to trigger (programmatic)
63
+ * Publishes event to bus - triggerWiring handles persistence and orchestration
64
+ */
65
+ async subscribeTrigger(opts) {
66
+ const eventBus = getEventBus();
67
+ const { trigger, flow, mode = "auto" } = opts;
68
+ const existingSub = runtime.getSubscription(trigger, flow);
69
+ const isUpdate = !!existingSub;
70
+ logger.info(`${isUpdate ? "Updating" : "Subscribing"} flow '${flow}' to trigger '${trigger}' (${mode})`);
71
+ await eventBus.publish({
72
+ type: "subscription.added",
73
+ triggerName: trigger,
74
+ data: {
75
+ trigger,
76
+ flow,
77
+ mode,
78
+ isUpdate
79
+ }
80
+ });
81
+ },
82
+ /**
83
+ * Unsubscribe flow from trigger
84
+ * Publishes event to bus - triggerWiring handles persistence and orchestration
85
+ */
86
+ async unsubscribeTrigger(trigger, flow) {
87
+ const eventBus = getEventBus();
88
+ logger.info(`Unsubscribing flow '${flow}' from trigger '${trigger}'`);
89
+ await eventBus.publish({
90
+ type: "subscription.removed",
91
+ triggerName: trigger,
92
+ data: {
93
+ trigger,
94
+ flow
95
+ }
96
+ });
97
+ },
98
+ /**
99
+ * Emit trigger (fire event)
100
+ * Publishes event to bus - triggerWiring handles persistence, stats, and orchestration
101
+ *
102
+ * Large payloads are automatically stored in KV store and replaced with references
103
+ * to keep stream events small and memory-efficient.
104
+ */
105
+ async emitTrigger(name, data, opts) {
106
+ const eventBus = getEventBus();
107
+ const trigger = runtime.getTrigger(name);
108
+ if (!trigger) {
109
+ logger.warn(
110
+ `Emitting unregistered trigger '${name}'. Consider registering it first with registerTrigger().`
111
+ );
112
+ }
113
+ const threshold = opts?.payloadThreshold || trigger?.config?.payloadThreshold || 10 * 1024;
114
+ const eventData = await runtime.handleLargePayload(name, data, threshold);
115
+ logger.debug(`Emitting trigger: ${name}`, {
116
+ hasReference: !!eventData.__payloadRef,
117
+ size: eventData.__size
118
+ });
119
+ await eventBus.publish({
120
+ type: "trigger.fired",
121
+ triggerName: name,
122
+ data: eventData
123
+ });
124
+ },
125
+ /**
126
+ * Query methods
127
+ */
128
+ /**
129
+ * Check if a trigger exists in the registry
130
+ */
131
+ hasTrigger(name) {
132
+ return runtime.hasTrigger(name);
133
+ },
134
+ /**
135
+ * Get trigger entry by name
136
+ */
137
+ getTrigger(name) {
138
+ return runtime.getTrigger(name);
139
+ },
140
+ /**
141
+ * Get all registered triggers
142
+ * @param options - Sorting and pagination options
143
+ * @param options.sortBy - Field to sort by
144
+ * @param options.order - Sort order (asc or desc)
145
+ * @param options.limit - Maximum number of results
146
+ * @param options.offset - Number of results to skip
147
+ */
148
+ getAllTriggers(options) {
149
+ return runtime.getAllTriggers(options);
150
+ },
151
+ /**
152
+ * Get all flows subscribed to a specific trigger
153
+ */
154
+ getSubscribedFlows(trigger) {
155
+ return runtime.getSubscribedFlows(trigger);
156
+ },
157
+ /**
158
+ * Get all triggers that a flow is subscribed to
159
+ */
160
+ getFlowTriggers(flow) {
161
+ return runtime.getFlowTriggers(flow);
162
+ },
163
+ /**
164
+ * Get subscription details for a specific trigger-flow pair
165
+ */
166
+ getSubscription(trigger, flow) {
167
+ return runtime.getSubscription(trigger, flow);
168
+ },
169
+ getAllSubscriptions() {
170
+ return runtime.getAllSubscriptions();
171
+ },
172
+ /**
173
+ * Initialize runtime from store (called on startup)
174
+ * Uses index + stream architecture (v0.5.1)
175
+ */
176
+ async initialize() {
177
+ if (runtime.initialized) return;
178
+ const { StoreSubjects } = useStreamTopics();
179
+ const indexKey = StoreSubjects.triggerIndex();
180
+ logger.info("Initializing trigger runtime from index...");
181
+ if (store.index.read) {
182
+ const entries = await store.index.read(indexKey, { limit: 1e3 });
183
+ let activeCount = 0;
184
+ let totalSubscriptions = 0;
185
+ for (const entry of entries) {
186
+ const metadata = entry.metadata;
187
+ const triggerEntry = {
188
+ name: metadata.name,
189
+ type: metadata.type,
190
+ scope: metadata.scope,
191
+ status: metadata.status || "active",
192
+ displayName: metadata.displayName,
193
+ description: metadata.description,
194
+ source: metadata.source,
195
+ registeredAt: metadata.registeredAt,
196
+ registeredBy: metadata.registeredBy,
197
+ lastActivityAt: metadata.lastActivityAt,
198
+ subscriptions: metadata.subscriptions || {},
199
+ stats: metadata.stats || { totalFires: 0, activeSubscribers: 0 },
200
+ webhook: metadata.webhook,
201
+ schedule: metadata.schedule,
202
+ config: metadata.config,
203
+ version: metadata.version || 1
204
+ };
205
+ runtime.addTrigger(entry.id, triggerEntry);
206
+ if (metadata.status === "active") {
207
+ activeCount++;
208
+ }
209
+ if (metadata.subscriptions) {
210
+ for (const [flowName, subData] of Object.entries(metadata.subscriptions)) {
211
+ const subscription = {
212
+ triggerName: entry.id,
213
+ flowName,
214
+ mode: subData.mode || "auto",
215
+ source: "programmatic",
216
+ registeredAt: subData.subscribedAt
217
+ };
218
+ runtime.addSubscription(entry.id, flowName, subscription);
219
+ totalSubscriptions++;
220
+ }
221
+ }
222
+ }
223
+ logger.info(
224
+ `Loaded ${activeCount} active triggers with ${totalSubscriptions} subscriptions from index`
225
+ );
226
+ } else {
227
+ logger.warn("Store does not support indexRead, falling back to doc-based loading");
228
+ if (store.list) {
229
+ const triggers = await store.list("triggers");
230
+ for (const { id, doc } of triggers) {
231
+ runtime.addTrigger(id, doc);
232
+ }
233
+ const subscriptions = await store.list("trigger-subscriptions");
234
+ for (const { doc } of subscriptions) {
235
+ const sub = doc;
236
+ runtime.addSubscription(sub.triggerName, sub.flowName, sub);
237
+ }
238
+ logger.info(
239
+ `Loaded ${triggers.length} triggers and ${subscriptions.length} subscriptions from doc store (legacy)`
240
+ );
241
+ }
242
+ }
243
+ runtime.setInitialized(true);
244
+ },
245
+ /**
246
+ * Get runtime state (for debugging)
247
+ */
248
+ getRuntime() {
249
+ return runtime.getRuntimeStats();
250
+ },
251
+ /**
252
+ * Delete a trigger completely (removes all data)
253
+ * Publishes event to bus - triggerWiring handles persistence and orchestration
254
+ */
255
+ async deleteTrigger(name) {
256
+ const eventBus = getEventBus();
257
+ const trigger = runtime.getTrigger(name);
258
+ if (!trigger) {
259
+ logger.warn(`Cannot delete non-existent trigger: ${name}`);
260
+ return;
261
+ }
262
+ logger.info(`Deleting trigger: ${name}`);
263
+ await eventBus.publish({
264
+ type: "trigger.deleted",
265
+ triggerName: name,
266
+ data: {}
267
+ });
268
+ },
269
+ /**
270
+ * Update trigger status (active/inactive/retired)
271
+ * For future status management UI
272
+ */
273
+ async updateTriggerStatus(name, status) {
274
+ const eventBus = getEventBus();
275
+ const trigger = runtime.getTrigger(name);
276
+ if (!trigger) {
277
+ logger.warn(`Cannot update status of non-existent trigger: ${name}`);
278
+ return;
279
+ }
280
+ logger.info(`Updating trigger ${name} status to: ${status}`);
281
+ await eventBus.publish({
282
+ type: "trigger.updated",
283
+ triggerName: name,
284
+ data: {
285
+ ...trigger,
286
+ status
287
+ }
288
+ });
289
+ },
290
+ /**
291
+ * Get trigger statistics
292
+ * v0.5.1: New analytics method
293
+ */
294
+ async getTriggerStats(name) {
295
+ const { StoreSubjects } = useStreamTopics();
296
+ const indexKey = StoreSubjects.triggerIndex();
297
+ if (!store.index.get) {
298
+ const trigger = runtime.getTrigger(name);
299
+ return trigger?.stats;
300
+ }
301
+ const entry = await store.index.get(indexKey, name);
302
+ if (!entry?.metadata) return null;
303
+ return entry.metadata.stats;
304
+ },
305
+ /**
306
+ * Get trigger history from stream
307
+ * v0.5.1: New analytics method
308
+ */
309
+ async getTriggerHistory(name, opts) {
310
+ const { StoreSubjects } = useStreamTopics();
311
+ const streamName = StoreSubjects.triggerStream(name);
312
+ const events = await store.stream.read(streamName, {
313
+ limit: opts?.limit || 100,
314
+ types: opts?.types,
315
+ order: "desc"
316
+ });
317
+ return events;
318
+ }
319
+ };
320
+ }
@@ -0,0 +1,33 @@
1
+ /**
2
+ * Scheduler Factory and Composable
3
+ *
4
+ * Provides a unified scheduler interface for the entire application.
5
+ * Uses Scheduler with store adapter (supports both distributed and single-instance modes).
6
+ */
7
+ import type { SchedulerAdapter } from './types.js';
8
+ /**
9
+ * Create a scheduler instance
10
+ * Uses Scheduler which adapts based on store capabilities:
11
+ * - With indexAdd/indexGet: Full distributed locking
12
+ * - Without: Degrades gracefully to KV-based locking (single instance)
13
+ */
14
+ export declare function createScheduler(store: any): SchedulerAdapter;
15
+ /**
16
+ * Get the global scheduler instance
17
+ * Must be initialized first with initializeScheduler()
18
+ */
19
+ export declare function useScheduler(): SchedulerAdapter;
20
+ /**
21
+ * Initialize the scheduler
22
+ * Should be called once during app startup
23
+ */
24
+ export declare function initializeScheduler(store: any): Promise<SchedulerAdapter>;
25
+ /**
26
+ * Shutdown the scheduler
27
+ * Should be called during app shutdown
28
+ */
29
+ export declare function shutdownScheduler(): Promise<void>;
30
+ /**
31
+ * Reset the scheduler instance (for testing)
32
+ */
33
+ export declare function resetScheduler(): void;
@@ -0,0 +1,38 @@
1
+ import { Scheduler } from "./scheduler.js";
2
+ import { useRuntimeConfig } from "#imports";
3
+ let schedulerInstance = null;
4
+ export function createScheduler(store) {
5
+ const config = useRuntimeConfig();
6
+ const prefix = config.nvent.store?.prefix || "nvent";
7
+ const useIndexLocking = !!(store.indexAdd && store.index.get);
8
+ return new Scheduler({
9
+ store,
10
+ keyPrefix: `${prefix}:scheduler`,
11
+ lockTTL: 3e5,
12
+ // 5 minutes
13
+ useIndexLocking
14
+ });
15
+ }
16
+ export function useScheduler() {
17
+ if (!schedulerInstance) {
18
+ throw new Error("Scheduler not initialized. Call initializeScheduler() first.");
19
+ }
20
+ return schedulerInstance;
21
+ }
22
+ export async function initializeScheduler(store) {
23
+ if (schedulerInstance) {
24
+ return schedulerInstance;
25
+ }
26
+ schedulerInstance = createScheduler(store);
27
+ await schedulerInstance.start();
28
+ return schedulerInstance;
29
+ }
30
+ export async function shutdownScheduler() {
31
+ if (schedulerInstance) {
32
+ await schedulerInstance.stop();
33
+ schedulerInstance = null;
34
+ }
35
+ }
36
+ export function resetScheduler() {
37
+ schedulerInstance = null;
38
+ }
@@ -0,0 +1,113 @@
1
+ /**
2
+ * Scheduler
3
+ *
4
+ * Store-based scheduler with distributed locking for horizontal scaling.
5
+ * Ensures only one instance executes each scheduled job.
6
+ */
7
+ import type { ScheduledJob, SchedulerAdapter } from './types.js';
8
+ import type { StoreAdapter } from '../adapters/interfaces/store.js';
9
+ export interface SchedulerOptions {
10
+ /**
11
+ * Store adapter for locking (Redis recommended)
12
+ */
13
+ store: StoreAdapter;
14
+ /**
15
+ * Key prefix for locks and job data
16
+ * Uses configured store prefix + ':scheduler'
17
+ * @default '{prefix}:scheduler' (e.g., 'nvent:scheduler')
18
+ */
19
+ keyPrefix?: string;
20
+ /**
21
+ * Lock TTL in milliseconds
22
+ * @default 300000 (5 minutes)
23
+ */
24
+ lockTTL?: number;
25
+ /**
26
+ * Unique instance identifier
27
+ * @default Auto-generated
28
+ */
29
+ instanceId?: string;
30
+ /**
31
+ * Use store indexes for locking (more robust) vs simple KV
32
+ * @default true
33
+ */
34
+ useIndexLocking?: boolean;
35
+ }
36
+ export declare class Scheduler implements SchedulerAdapter {
37
+ private store;
38
+ private keyPrefix;
39
+ private lockTTL;
40
+ private instanceId;
41
+ private useIndexLocking;
42
+ private jobs;
43
+ private jobConfigs;
44
+ private lockRenewalTimers;
45
+ private started;
46
+ private logger;
47
+ constructor(options: SchedulerOptions);
48
+ schedule(job: ScheduledJob): Promise<string>;
49
+ /**
50
+ * Execute job with distributed lock
51
+ * Prevents multiple instances from running the same job
52
+ */
53
+ private executeWithLock;
54
+ private executeJob;
55
+ /**
56
+ * Acquire distributed lock using store adapter
57
+ */
58
+ private acquireLock;
59
+ /**
60
+ * Release distributed lock
61
+ */
62
+ private releaseLock;
63
+ /**
64
+ * Start periodic lock renewal (for long-running jobs)
65
+ */
66
+ private startLockRenewal;
67
+ /**
68
+ * Stop lock renewal
69
+ */
70
+ private stopLockRenewal;
71
+ /**
72
+ * Persist job configuration
73
+ */
74
+ private persistJob;
75
+ /**
76
+ * Update job statistics
77
+ */
78
+ private updateJobStats;
79
+ unschedule(jobId: string): Promise<boolean>;
80
+ /**
81
+ * Recover jobs from store on startup
82
+ * Critical for:
83
+ * - Restarts: Re-create in-memory schedulers
84
+ * - Horizontal scaling: New instances pick up existing jobs
85
+ * - Orphaned awaits: Resume flows waiting on schedules
86
+ */
87
+ private recoverJobs;
88
+ /**
89
+ * Recover a single job from persisted data
90
+ *
91
+ * IMPORTANT: This method reconstructs in-memory schedulers (CronJob/setInterval)
92
+ * WITHOUT calling schedule() to avoid re-persisting handler functions (which
93
+ * cannot be serialized). Handlers are reconstructed from metadata where possible.
94
+ */
95
+ private recoverJob;
96
+ /**
97
+ * Recover well-known job patterns when index scan is not available
98
+ * This includes:
99
+ * - stall-detection (always exists)
100
+ * - await-time-* (flows waiting on time delays)
101
+ * - await-schedule-* (flows waiting on cron schedules)
102
+ */
103
+ private recoverWellKnownJobs;
104
+ start(): Promise<void>;
105
+ stop(): Promise<void>;
106
+ getScheduledJobs(): Promise<ScheduledJob[]>;
107
+ /**
108
+ * Get all persisted jobs from store (for debugging/monitoring)
109
+ * This shows ALL jobs across ALL instances with their runtime stats
110
+ */
111
+ getAllPersistedJobs(): Promise<ScheduledJob[]>;
112
+ isHealthy(): Promise<boolean>;
113
+ }