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.
- package/dist/module.d.mts +4 -185
- package/dist/module.json +3 -3
- package/dist/module.mjs +451 -257
- package/dist/runtime/adapters/base/index.d.ts +6 -0
- package/dist/runtime/adapters/base/index.js +1 -0
- package/dist/runtime/adapters/base/store-validator.d.ts +48 -0
- package/dist/runtime/adapters/base/store-validator.js +147 -0
- package/dist/runtime/adapters/builtin/file-queue.d.ts +67 -0
- package/dist/runtime/adapters/builtin/file-queue.js +499 -0
- package/dist/runtime/adapters/builtin/file-store.d.ts +32 -0
- package/dist/runtime/adapters/builtin/file-store.js +206 -0
- package/dist/runtime/adapters/builtin/file-stream.d.ts +39 -0
- package/dist/runtime/adapters/builtin/file-stream.js +56 -0
- package/dist/runtime/adapters/builtin/index.d.ts +10 -0
- package/dist/runtime/adapters/builtin/index.js +5 -0
- package/dist/runtime/adapters/builtin/memory-queue.d.ts +52 -0
- package/dist/runtime/adapters/builtin/memory-queue.js +243 -0
- package/dist/runtime/adapters/builtin/memory-store.d.ts +68 -0
- package/dist/runtime/adapters/builtin/memory-store.js +333 -0
- package/dist/runtime/adapters/builtin/memory-stream.d.ts +21 -0
- package/dist/runtime/adapters/builtin/memory-stream.js +56 -0
- package/dist/runtime/adapters/factory.d.ts +31 -0
- package/dist/runtime/adapters/factory.js +134 -0
- package/dist/runtime/adapters/index.d.ts +8 -0
- package/dist/runtime/adapters/index.js +3 -0
- package/dist/runtime/adapters/interfaces/index.d.ts +11 -0
- package/dist/runtime/adapters/interfaces/index.js +3 -0
- package/dist/runtime/adapters/interfaces/queue.d.ts +150 -0
- package/dist/runtime/adapters/interfaces/store.d.ts +297 -0
- package/dist/runtime/adapters/interfaces/stream.d.ts +62 -0
- package/dist/runtime/adapters/registry.d.ts +85 -0
- package/dist/runtime/adapters/registry.js +161 -0
- package/dist/runtime/config/index.d.ts +29 -0
- package/dist/runtime/config/index.js +175 -0
- package/dist/runtime/config/types.d.ts +397 -0
- package/dist/runtime/config/types.js +0 -0
- package/dist/runtime/{server-utils/events → events}/eventBus.d.ts +1 -1
- package/dist/runtime/events/types.d.ts +145 -0
- package/dist/runtime/events/types.js +0 -0
- package/dist/runtime/events/utils/scheduleTrigger.d.ts +8 -0
- package/dist/runtime/events/utils/scheduleTrigger.js +69 -0
- package/dist/runtime/events/utils/stallDetector.d.ts +140 -0
- package/dist/runtime/events/utils/stallDetector.js +436 -0
- package/dist/runtime/events/utils/triggerRuntime.d.ts +58 -0
- package/dist/runtime/events/utils/triggerRuntime.js +212 -0
- package/dist/runtime/{server-utils/events → events}/wiring/flowWiring.d.ts +12 -11
- package/dist/runtime/events/wiring/flowWiring.js +1020 -0
- package/dist/runtime/events/wiring/registry.d.ts +19 -0
- package/dist/runtime/events/wiring/registry.js +35 -0
- package/dist/runtime/events/wiring/stateWiring.d.ts +37 -0
- package/dist/runtime/events/wiring/stateWiring.js +92 -0
- package/dist/runtime/events/wiring/streamWiring.d.ts +36 -0
- package/dist/runtime/events/wiring/streamWiring.js +156 -0
- package/dist/runtime/events/wiring/triggerWiring.d.ts +21 -0
- package/dist/runtime/events/wiring/triggerWiring.js +412 -0
- package/dist/runtime/nitro/plugins/00.adapters.d.ts +14 -0
- package/dist/runtime/nitro/plugins/00.adapters.js +73 -0
- package/dist/runtime/nitro/plugins/02.workers.js +63 -0
- package/dist/runtime/nitro/plugins/03.triggers.d.ts +12 -0
- package/dist/runtime/nitro/plugins/03.triggers.js +55 -0
- package/dist/runtime/nitro/routes/webhook.await.d.ts +23 -0
- package/dist/runtime/nitro/routes/webhook.await.js +90 -0
- package/dist/runtime/nitro/routes/webhook.trigger.d.ts +69 -0
- package/dist/runtime/nitro/routes/webhook.trigger.js +64 -0
- package/dist/runtime/nitro/utils/adapters.d.ts +66 -0
- package/dist/runtime/nitro/utils/adapters.js +51 -0
- package/dist/runtime/nitro/utils/awaitPatterns/event.d.ts +15 -0
- package/dist/runtime/nitro/utils/awaitPatterns/event.js +120 -0
- package/dist/runtime/nitro/utils/awaitPatterns/index.d.ts +28 -0
- package/dist/runtime/nitro/utils/awaitPatterns/index.js +55 -0
- package/dist/runtime/nitro/utils/awaitPatterns/schedule.d.ts +16 -0
- package/dist/runtime/nitro/utils/awaitPatterns/schedule.js +78 -0
- package/dist/runtime/nitro/utils/awaitPatterns/time.d.ts +15 -0
- package/dist/runtime/nitro/utils/awaitPatterns/time.js +67 -0
- package/dist/runtime/nitro/utils/awaitPatterns/webhook.d.ts +15 -0
- package/dist/runtime/nitro/utils/awaitPatterns/webhook.js +120 -0
- package/dist/runtime/nitro/utils/defineFunction.d.ts +10 -0
- package/dist/runtime/nitro/utils/defineFunction.js +17 -0
- package/dist/runtime/nitro/utils/defineFunctionConfig.d.ts +310 -0
- package/dist/runtime/nitro/utils/defineFunctionConfig.js +3 -0
- package/dist/runtime/nitro/utils/defineHooks.d.ts +41 -0
- package/dist/runtime/nitro/utils/defineHooks.js +6 -0
- package/dist/runtime/nitro/utils/registerAdapter.d.ts +59 -0
- package/dist/runtime/nitro/utils/registerAdapter.js +13 -0
- package/dist/runtime/nitro/utils/useAwait.d.ts +71 -0
- package/dist/runtime/nitro/utils/useAwait.js +139 -0
- package/dist/runtime/{server-utils → nitro}/utils/useEventManager.d.ts +2 -2
- package/dist/runtime/{server-utils → nitro}/utils/useEventManager.js +1 -1
- package/dist/runtime/nitro/utils/useFlow.d.ts +68 -0
- package/dist/runtime/nitro/utils/useFlow.js +226 -0
- package/dist/runtime/nitro/utils/useHookRegistry.d.ts +34 -0
- package/dist/runtime/nitro/utils/useHookRegistry.js +25 -0
- package/dist/runtime/{server-utils → nitro}/utils/useNventLogger.js +2 -2
- package/dist/runtime/nitro/utils/useRunContext.d.ts +6 -0
- package/dist/runtime/nitro/utils/useRunContext.js +102 -0
- package/dist/runtime/nitro/utils/useStreamTopics.d.ts +83 -0
- package/dist/runtime/nitro/utils/useStreamTopics.js +94 -0
- package/dist/runtime/nitro/utils/useTrigger.d.ts +150 -0
- package/dist/runtime/nitro/utils/useTrigger.js +320 -0
- package/dist/runtime/scheduler/index.d.ts +33 -0
- package/dist/runtime/scheduler/index.js +38 -0
- package/dist/runtime/scheduler/scheduler.d.ts +113 -0
- package/dist/runtime/scheduler/scheduler.js +623 -0
- package/dist/runtime/scheduler/types.d.ts +116 -0
- package/dist/runtime/scheduler/types.js +0 -0
- package/dist/runtime/tsconfig.json +8 -0
- package/dist/runtime/worker/node/runner.d.ts +53 -0
- package/dist/runtime/worker/node/runner.js +327 -0
- package/dist/types.d.mts +2 -2
- package/package.json +16 -46
- package/LICENSE +0 -21
- package/README.md +0 -389
- package/dist/runtime/app/assets/vueflow.css +0 -1
- package/dist/runtime/app/components/ConfirmDialog.d.vue.ts +0 -33
- package/dist/runtime/app/components/ConfirmDialog.vue +0 -121
- package/dist/runtime/app/components/ConfirmDialog.vue.d.ts +0 -33
- package/dist/runtime/app/components/FlowDiagram.d.vue.ts +0 -64
- package/dist/runtime/app/components/FlowDiagram.vue +0 -338
- package/dist/runtime/app/components/FlowDiagram.vue.d.ts +0 -64
- package/dist/runtime/app/components/FlowNodeCard.d.vue.ts +0 -29
- package/dist/runtime/app/components/FlowNodeCard.vue +0 -156
- package/dist/runtime/app/components/FlowNodeCard.vue.d.ts +0 -29
- package/dist/runtime/app/components/FlowRunOverview.d.vue.ts +0 -9
- package/dist/runtime/app/components/FlowRunOverview.vue +0 -291
- package/dist/runtime/app/components/FlowRunOverview.vue.d.ts +0 -9
- package/dist/runtime/app/components/FlowRunStatusBadge.d.vue.ts +0 -14
- package/dist/runtime/app/components/FlowRunStatusBadge.vue +0 -60
- package/dist/runtime/app/components/FlowRunStatusBadge.vue.d.ts +0 -14
- package/dist/runtime/app/components/FlowRunTimeline.d.vue.ts +0 -12
- package/dist/runtime/app/components/FlowRunTimeline.vue +0 -127
- package/dist/runtime/app/components/FlowRunTimeline.vue.d.ts +0 -12
- package/dist/runtime/app/components/FlowScheduleDialog.d.vue.ts +0 -16
- package/dist/runtime/app/components/FlowScheduleDialog.vue +0 -226
- package/dist/runtime/app/components/FlowScheduleDialog.vue.d.ts +0 -16
- package/dist/runtime/app/components/FlowSchedulesList.d.vue.ts +0 -12
- package/dist/runtime/app/components/FlowSchedulesList.vue +0 -99
- package/dist/runtime/app/components/FlowSchedulesList.vue.d.ts +0 -12
- package/dist/runtime/app/components/JobScheduling.d.vue.ts +0 -6
- package/dist/runtime/app/components/JobScheduling.vue +0 -203
- package/dist/runtime/app/components/JobScheduling.vue.d.ts +0 -6
- package/dist/runtime/app/components/ListItem.d.vue.ts +0 -23
- package/dist/runtime/app/components/ListItem.vue +0 -70
- package/dist/runtime/app/components/ListItem.vue.d.ts +0 -23
- package/dist/runtime/app/components/QueueConfigDetails.d.vue.ts +0 -45
- package/dist/runtime/app/components/QueueConfigDetails.vue +0 -412
- package/dist/runtime/app/components/QueueConfigDetails.vue.d.ts +0 -45
- package/dist/runtime/app/components/StatCounter.d.vue.ts +0 -9
- package/dist/runtime/app/components/StatCounter.vue +0 -25
- package/dist/runtime/app/components/StatCounter.vue.d.ts +0 -9
- package/dist/runtime/app/components/TimelineList.d.vue.ts +0 -7
- package/dist/runtime/app/components/TimelineList.vue +0 -210
- package/dist/runtime/app/components/TimelineList.vue.d.ts +0 -7
- package/dist/runtime/app/components/nhealth/component-router.d.vue.ts +0 -46
- package/dist/runtime/app/components/nhealth/component-router.vue +0 -26
- package/dist/runtime/app/components/nhealth/component-router.vue.d.ts +0 -46
- package/dist/runtime/app/components/nhealth/component-shell.d.vue.ts +0 -24
- package/dist/runtime/app/components/nhealth/component-shell.vue +0 -89
- package/dist/runtime/app/components/nhealth/component-shell.vue.d.ts +0 -24
- package/dist/runtime/app/composables/useAnalyzedFlows.d.ts +0 -14
- package/dist/runtime/app/composables/useAnalyzedFlows.js +0 -8
- package/dist/runtime/app/composables/useComponentRouter.d.ts +0 -38
- package/dist/runtime/app/composables/useComponentRouter.js +0 -240
- package/dist/runtime/app/composables/useFlowRunTimeline.d.ts +0 -80
- package/dist/runtime/app/composables/useFlowRunTimeline.js +0 -68
- package/dist/runtime/app/composables/useFlowRuns.d.ts +0 -18
- package/dist/runtime/app/composables/useFlowRuns.js +0 -32
- package/dist/runtime/app/composables/useFlowRunsInfinite.d.ts +0 -24
- package/dist/runtime/app/composables/useFlowRunsInfinite.js +0 -123
- package/dist/runtime/app/composables/useFlowRunsPolling.d.ts +0 -9
- package/dist/runtime/app/composables/useFlowRunsPolling.js +0 -33
- package/dist/runtime/app/composables/useFlowState.d.ts +0 -125
- package/dist/runtime/app/composables/useFlowState.js +0 -211
- package/dist/runtime/app/composables/useFlowWebSocket.d.ts +0 -27
- package/dist/runtime/app/composables/useFlowWebSocket.js +0 -205
- package/dist/runtime/app/composables/useFlowsNavigation.d.ts +0 -10
- package/dist/runtime/app/composables/useFlowsNavigation.js +0 -58
- package/dist/runtime/app/composables/useQueueJobs.d.ts +0 -26
- package/dist/runtime/app/composables/useQueueJobs.js +0 -20
- package/dist/runtime/app/composables/useQueueUpdates.d.ts +0 -26
- package/dist/runtime/app/composables/useQueueUpdates.js +0 -122
- package/dist/runtime/app/composables/useQueues.d.ts +0 -45
- package/dist/runtime/app/composables/useQueues.js +0 -26
- package/dist/runtime/app/composables/useQueuesLive.d.ts +0 -19
- package/dist/runtime/app/composables/useQueuesLive.js +0 -143
- package/dist/runtime/app/pages/flows/index.d.vue.ts +0 -3
- package/dist/runtime/app/pages/flows/index.vue +0 -645
- package/dist/runtime/app/pages/flows/index.vue.d.ts +0 -3
- package/dist/runtime/app/pages/index.d.vue.ts +0 -3
- package/dist/runtime/app/pages/index.vue +0 -34
- package/dist/runtime/app/pages/index.vue.d.ts +0 -3
- package/dist/runtime/app/pages/queues/index.d.vue.ts +0 -3
- package/dist/runtime/app/pages/queues/index.vue +0 -229
- package/dist/runtime/app/pages/queues/index.vue.d.ts +0 -3
- package/dist/runtime/app/pages/queues/job.d.vue.ts +0 -3
- package/dist/runtime/app/pages/queues/job.vue +0 -262
- package/dist/runtime/app/pages/queues/job.vue.d.ts +0 -3
- package/dist/runtime/app/pages/queues/jobs.d.vue.ts +0 -3
- package/dist/runtime/app/pages/queues/jobs.vue +0 -291
- package/dist/runtime/app/pages/queues/jobs.vue.d.ts +0 -3
- package/dist/runtime/app/plugins/vueflow.client.d.ts +0 -2
- package/dist/runtime/app/plugins/vueflow.client.js +0 -11
- package/dist/runtime/constants.d.ts +0 -11
- package/dist/runtime/constants.js +0 -11
- package/dist/runtime/schema.d.ts +0 -37
- package/dist/runtime/schema.js +0 -20
- package/dist/runtime/server/api/_flows/[name]/clear-history.delete.d.ts +0 -10
- package/dist/runtime/server/api/_flows/[name]/clear-history.delete.js +0 -44
- package/dist/runtime/server/api/_flows/[name]/runs.get.d.ts +0 -7
- package/dist/runtime/server/api/_flows/[name]/runs.get.js +0 -53
- package/dist/runtime/server/api/_flows/[name]/schedule.post.js +0 -57
- package/dist/runtime/server/api/_flows/[name]/schedules/[id].delete.d.ts +0 -2
- package/dist/runtime/server/api/_flows/[name]/schedules/[id].delete.js +0 -42
- package/dist/runtime/server/api/_flows/[name]/schedules.get.d.ts +0 -2
- package/dist/runtime/server/api/_flows/[name]/schedules.get.js +0 -48
- package/dist/runtime/server/api/_flows/[name]/start.post.d.ts +0 -2
- package/dist/runtime/server/api/_flows/[name]/start.post.js +0 -9
- package/dist/runtime/server/api/_flows/index.get.d.ts +0 -6
- package/dist/runtime/server/api/_flows/index.get.js +0 -5
- package/dist/runtime/server/api/_flows/ws.d.ts +0 -60
- package/dist/runtime/server/api/_flows/ws.js +0 -188
- package/dist/runtime/server/api/_queues/[name]/job/[id].get.d.ts +0 -2
- package/dist/runtime/server/api/_queues/[name]/job/[id].get.js +0 -9
- package/dist/runtime/server/api/_queues/[name]/job/index.get.d.ts +0 -2
- package/dist/runtime/server/api/_queues/[name]/job/index.get.js +0 -18
- package/dist/runtime/server/api/_queues/index.get.d.ts +0 -2
- package/dist/runtime/server/api/_queues/index.get.js +0 -63
- package/dist/runtime/server/api/_queues/ws.d.ts +0 -48
- package/dist/runtime/server/api/_queues/ws.js +0 -205
- package/dist/runtime/server/plugins/00.event-store.d.ts +0 -13
- package/dist/runtime/server/plugins/00.event-store.js +0 -16
- package/dist/runtime/server/plugins/flow-management.d.ts +0 -13
- package/dist/runtime/server/plugins/flow-management.js +0 -65
- package/dist/runtime/server/plugins/queue-management.d.ts +0 -2
- package/dist/runtime/server/plugins/queue-management.js +0 -27
- package/dist/runtime/server/plugins/state-cleanup.d.ts +0 -11
- package/dist/runtime/server/plugins/state-cleanup.js +0 -93
- package/dist/runtime/server/plugins/worker-management.d.ts +0 -2
- package/dist/runtime/server/plugins/worker-management.js +0 -33
- package/dist/runtime/server/tsconfig.json +0 -3
- package/dist/runtime/server-utils/events/adapters/fileAdapter.d.ts +0 -2
- package/dist/runtime/server-utils/events/adapters/fileAdapter.js +0 -382
- package/dist/runtime/server-utils/events/adapters/memoryAdapter.d.ts +0 -2
- package/dist/runtime/server-utils/events/adapters/memoryAdapter.js +0 -171
- package/dist/runtime/server-utils/events/adapters/redis/redisAdapter.d.ts +0 -2
- package/dist/runtime/server-utils/events/adapters/redis/redisAdapter.js +0 -348
- package/dist/runtime/server-utils/events/adapters/redis/redisPubSubGateway.d.ts +0 -30
- package/dist/runtime/server-utils/events/adapters/redis/redisPubSubGateway.js +0 -82
- package/dist/runtime/server-utils/events/eventStoreFactory.d.ts +0 -19
- package/dist/runtime/server-utils/events/eventStoreFactory.js +0 -44
- package/dist/runtime/server-utils/events/streamNames.d.ts +0 -17
- package/dist/runtime/server-utils/events/streamNames.js +0 -17
- package/dist/runtime/server-utils/events/types.d.ts +0 -63
- package/dist/runtime/server-utils/events/wiring/flowWiring.js +0 -409
- package/dist/runtime/server-utils/events/wiring/registry.d.ts +0 -10
- package/dist/runtime/server-utils/events/wiring/registry.js +0 -24
- package/dist/runtime/server-utils/queue/adapters/bullmq.d.ts +0 -18
- package/dist/runtime/server-utils/queue/adapters/bullmq.js +0 -164
- package/dist/runtime/server-utils/queue/queueFactory.d.ts +0 -3
- package/dist/runtime/server-utils/queue/queueFactory.js +0 -10
- package/dist/runtime/server-utils/queue/types.d.ts +0 -47
- package/dist/runtime/server-utils/state/adapters/redis.d.ts +0 -2
- package/dist/runtime/server-utils/state/adapters/redis.js +0 -42
- package/dist/runtime/server-utils/state/stateFactory.d.ts +0 -3
- package/dist/runtime/server-utils/state/stateFactory.js +0 -17
- package/dist/runtime/server-utils/state/types.d.ts +0 -23
- package/dist/runtime/server-utils/utils/defineQueueConfig.d.ts +0 -154
- package/dist/runtime/server-utils/utils/defineQueueConfig.js +0 -2
- package/dist/runtime/server-utils/utils/defineQueueWorker.d.ts +0 -10
- package/dist/runtime/server-utils/utils/defineQueueWorker.js +0 -17
- package/dist/runtime/server-utils/utils/useEventStore.d.ts +0 -20
- package/dist/runtime/server-utils/utils/useEventStore.js +0 -119
- package/dist/runtime/server-utils/utils/useFlowEngine.d.ts +0 -9
- package/dist/runtime/server-utils/utils/useFlowEngine.js +0 -44
- package/dist/runtime/server-utils/utils/useLogs.d.ts +0 -41
- package/dist/runtime/server-utils/utils/useLogs.js +0 -74
- package/dist/runtime/server-utils/utils/useQueue.d.ts +0 -31
- package/dist/runtime/server-utils/utils/useQueue.js +0 -24
- package/dist/runtime/server-utils/worker/adapter.d.ts +0 -4
- package/dist/runtime/server-utils/worker/adapter.js +0 -66
- package/dist/runtime/server-utils/worker/runner/node.d.ts +0 -27
- package/dist/runtime/server-utils/worker/runner/node.js +0 -196
- package/dist/runtime/types.d.ts +0 -132
- /package/dist/runtime/{server-utils/events/types.js → adapters/interfaces/queue.js} +0 -0
- /package/dist/runtime/{server-utils/queue/types.js → adapters/interfaces/store.js} +0 -0
- /package/dist/runtime/{server-utils/state/types.js → adapters/interfaces/stream.js} +0 -0
- /package/dist/runtime/{server-utils/events → events}/eventBus.js +0 -0
- /package/dist/runtime/{server/plugins/00.ws-lifecycle.d.ts → nitro/plugins/01.ws-lifecycle.d.ts} +0 -0
- /package/dist/runtime/{server/plugins/00.ws-lifecycle.js → nitro/plugins/01.ws-lifecycle.js} +0 -0
- /package/dist/runtime/{server/api/_flows/[name]/schedule.post.d.ts → nitro/plugins/02.workers.d.ts} +0 -0
- /package/dist/runtime/{server-utils → nitro}/utils/useNventLogger.d.ts +0 -0
- /package/dist/runtime/{server-utils → nitro}/utils/wsPeerManager.d.ts +0 -0
- /package/dist/runtime/{server-utils → nitro}/utils/wsPeerManager.js +0 -0
- /package/dist/runtime/{python → worker/python}/get_config.py +0 -0
|
@@ -0,0 +1,412 @@
|
|
|
1
|
+
import { getEventBus } from "../eventBus.js";
|
|
2
|
+
import { useTrigger, useNventLogger, useStoreAdapter, useQueueAdapter, $useAnalyzedFlows, $useFunctionRegistry, useStreamTopics } from "#imports";
|
|
3
|
+
import { getTriggerRuntime } from "../utils/triggerRuntime.js";
|
|
4
|
+
import { scheduleTrigger, unscheduleTrigger } from "../utils/scheduleTrigger.js";
|
|
5
|
+
export function createTriggerWiring() {
|
|
6
|
+
const unsubs = [];
|
|
7
|
+
let wired = false;
|
|
8
|
+
async function start() {
|
|
9
|
+
if (wired) return;
|
|
10
|
+
wired = true;
|
|
11
|
+
const logger = useNventLogger("trigger-wiring");
|
|
12
|
+
const eventBus = getEventBus();
|
|
13
|
+
const trigger = useTrigger();
|
|
14
|
+
const store = useStoreAdapter();
|
|
15
|
+
const { StoreSubjects } = useStreamTopics();
|
|
16
|
+
const runtime = getTriggerRuntime(store, logger);
|
|
17
|
+
await trigger.initialize();
|
|
18
|
+
logger.info("Setting up trigger event wiring");
|
|
19
|
+
const handlePersistence = async (e) => {
|
|
20
|
+
try {
|
|
21
|
+
if (e.id && e.ts) {
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
const triggerName = e.triggerName || e.data?.triggerName;
|
|
25
|
+
if (!triggerName) {
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
const streamName = StoreSubjects.triggerStream(triggerName);
|
|
29
|
+
if (!e.type) {
|
|
30
|
+
logger.error("Event missing type field", { event: e });
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
const eventData = {
|
|
34
|
+
type: e.type,
|
|
35
|
+
triggerName,
|
|
36
|
+
data: e.data
|
|
37
|
+
};
|
|
38
|
+
const persistedEvent = await store.stream.append(streamName, eventData);
|
|
39
|
+
await eventBus.publish(persistedEvent);
|
|
40
|
+
logger.debug("Stored trigger event", {
|
|
41
|
+
type: e.type,
|
|
42
|
+
triggerName,
|
|
43
|
+
id: persistedEvent.id
|
|
44
|
+
});
|
|
45
|
+
} catch (err) {
|
|
46
|
+
logger.error("ERROR persisting trigger event", {
|
|
47
|
+
type: e.type,
|
|
48
|
+
triggerName: e.triggerName,
|
|
49
|
+
error: err?.message
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
const handleOrchestration = async (e) => {
|
|
54
|
+
try {
|
|
55
|
+
if (e.id && e.ts) {
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
const triggerName = e.triggerName || e.data?.triggerName;
|
|
59
|
+
if (!triggerName) {
|
|
60
|
+
logger.debug("Orchestration skipped - no triggerName", { type: e.type });
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
logger.debug("Processing trigger orchestration", { type: e.type, triggerName });
|
|
64
|
+
const indexKey = StoreSubjects.triggerIndex();
|
|
65
|
+
const now = (/* @__PURE__ */ new Date()).toISOString();
|
|
66
|
+
const nowTimestamp = Date.now();
|
|
67
|
+
if (e.type === "trigger.registered") {
|
|
68
|
+
const data = e.data;
|
|
69
|
+
if (store.index.add) {
|
|
70
|
+
await store.index.add(indexKey, triggerName, nowTimestamp, {
|
|
71
|
+
"name": data.name,
|
|
72
|
+
"type": data.type,
|
|
73
|
+
"scope": data.scope,
|
|
74
|
+
"status": "active",
|
|
75
|
+
"displayName": data.displayName,
|
|
76
|
+
"description": data.description,
|
|
77
|
+
"source": data.source || "programmatic",
|
|
78
|
+
"registeredAt": now,
|
|
79
|
+
"registeredBy": "runtime",
|
|
80
|
+
"lastActivityAt": now,
|
|
81
|
+
"stats.totalFires": 0,
|
|
82
|
+
"stats.totalFlowsStarted": 0,
|
|
83
|
+
"stats.activeSubscribers": 0,
|
|
84
|
+
"webhook": data.webhook,
|
|
85
|
+
"schedule": data.schedule,
|
|
86
|
+
"config": data.config,
|
|
87
|
+
"version": 1
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
const entry = {
|
|
91
|
+
name: data.name,
|
|
92
|
+
type: data.type,
|
|
93
|
+
scope: data.scope,
|
|
94
|
+
status: "active",
|
|
95
|
+
displayName: data.displayName,
|
|
96
|
+
description: data.description,
|
|
97
|
+
source: data.source || "programmatic",
|
|
98
|
+
registeredAt: now,
|
|
99
|
+
registeredBy: "runtime",
|
|
100
|
+
lastActivityAt: now,
|
|
101
|
+
subscriptions: {},
|
|
102
|
+
stats: { totalFires: 0, totalFlowsStarted: 0, activeSubscribers: 0 },
|
|
103
|
+
webhook: data.webhook,
|
|
104
|
+
schedule: data.schedule,
|
|
105
|
+
config: data.config,
|
|
106
|
+
version: 1
|
|
107
|
+
};
|
|
108
|
+
runtime.addTrigger(triggerName, entry);
|
|
109
|
+
logger.info("Registered trigger in index", { triggerName });
|
|
110
|
+
if (data.type === "schedule" && data.schedule) {
|
|
111
|
+
await scheduleTrigger(triggerName, data.schedule, data.status || "active");
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
if (e.type === "trigger.updated") {
|
|
115
|
+
const data = e.data;
|
|
116
|
+
if (store.index.updateWithRetry) {
|
|
117
|
+
await store.index.updateWithRetry(indexKey, triggerName, {
|
|
118
|
+
type: data.type,
|
|
119
|
+
scope: data.scope,
|
|
120
|
+
status: data.status,
|
|
121
|
+
displayName: data.displayName,
|
|
122
|
+
description: data.description,
|
|
123
|
+
webhook: data.webhook,
|
|
124
|
+
schedule: data.schedule,
|
|
125
|
+
config: data.config,
|
|
126
|
+
lastActivityAt: now
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
const existing = runtime.getTrigger(triggerName);
|
|
130
|
+
if (existing) {
|
|
131
|
+
const updated = {
|
|
132
|
+
...existing,
|
|
133
|
+
status: data.status !== void 0 ? data.status : existing.status,
|
|
134
|
+
displayName: data.displayName !== void 0 ? data.displayName : existing.displayName,
|
|
135
|
+
description: data.description !== void 0 ? data.description : existing.description,
|
|
136
|
+
webhook: data.webhook !== void 0 ? data.webhook : existing.webhook,
|
|
137
|
+
schedule: data.schedule !== void 0 ? data.schedule : existing.schedule,
|
|
138
|
+
config: data.config !== void 0 ? data.config : existing.config,
|
|
139
|
+
lastActivityAt: now
|
|
140
|
+
};
|
|
141
|
+
runtime.addTrigger(triggerName, updated);
|
|
142
|
+
if (updated.type === "schedule" && updated.schedule) {
|
|
143
|
+
await scheduleTrigger(triggerName, updated.schedule, updated.status);
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
logger.info("Updated trigger in index and runtime", { triggerName, status: data.status });
|
|
147
|
+
}
|
|
148
|
+
if (e.type === "subscription.added") {
|
|
149
|
+
const data = e.data;
|
|
150
|
+
const { flow, mode } = data;
|
|
151
|
+
const existingSub = runtime.getSubscription(triggerName, flow);
|
|
152
|
+
if (store.index.updateWithRetry) {
|
|
153
|
+
await store.index.updateWithRetry(indexKey, triggerName, {
|
|
154
|
+
subscriptions: {
|
|
155
|
+
[flow]: {
|
|
156
|
+
mode,
|
|
157
|
+
subscribedAt: existingSub ? existingSub.registeredAt || now : now
|
|
158
|
+
}
|
|
159
|
+
},
|
|
160
|
+
lastActivityAt: now
|
|
161
|
+
});
|
|
162
|
+
if (!existingSub && store.index.increment) {
|
|
163
|
+
await store.index.increment(indexKey, triggerName, "stats.activeSubscribers", 1);
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
const subscription = {
|
|
167
|
+
triggerName,
|
|
168
|
+
flowName: flow,
|
|
169
|
+
mode,
|
|
170
|
+
source: "programmatic",
|
|
171
|
+
registeredAt: existingSub?.registeredAt || now
|
|
172
|
+
};
|
|
173
|
+
runtime.addSubscription(triggerName, flow, subscription);
|
|
174
|
+
logger.info(`Subscription ${existingSub ? "updated" : "added"}`, { triggerName, flow, mode });
|
|
175
|
+
}
|
|
176
|
+
if (e.type === "subscription.removed") {
|
|
177
|
+
const data = e.data;
|
|
178
|
+
const { flow } = data;
|
|
179
|
+
if (store.index.updateWithRetry) {
|
|
180
|
+
await store.index.updateWithRetry(indexKey, triggerName, {
|
|
181
|
+
subscriptions: {
|
|
182
|
+
[flow]: null
|
|
183
|
+
// null removes the field
|
|
184
|
+
},
|
|
185
|
+
lastActivityAt: now
|
|
186
|
+
});
|
|
187
|
+
if (store.index.increment) {
|
|
188
|
+
await store.index.increment(indexKey, triggerName, "stats.activeSubscribers", -1);
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
runtime.removeSubscription(triggerName, flow);
|
|
192
|
+
logger.info("Subscription removed", { triggerName, flow });
|
|
193
|
+
}
|
|
194
|
+
if (e.type === "trigger.fired") {
|
|
195
|
+
const flowsStarted = await handleTriggerFired(e);
|
|
196
|
+
if (flowsStarted.length > 0 && store.index.increment) {
|
|
197
|
+
await store.index.increment(indexKey, triggerName, "stats.totalFlowsStarted", flowsStarted.length);
|
|
198
|
+
}
|
|
199
|
+
logger.debug("Trigger fired and processed", { triggerName, flowsStarted: flowsStarted.length });
|
|
200
|
+
}
|
|
201
|
+
if (e.type === "trigger.deleted") {
|
|
202
|
+
const triggerEntry = runtime.getTrigger(triggerName);
|
|
203
|
+
const wasScheduleTrigger = triggerEntry?.type === "schedule";
|
|
204
|
+
if (store.index.delete) {
|
|
205
|
+
await store.index.delete(indexKey, triggerName);
|
|
206
|
+
}
|
|
207
|
+
const triggerStreamKey = StoreSubjects.triggerStream(triggerName);
|
|
208
|
+
if (store.stream.delete) {
|
|
209
|
+
await store.stream.delete(triggerStreamKey);
|
|
210
|
+
}
|
|
211
|
+
runtime.removeTrigger(triggerName);
|
|
212
|
+
if (wasScheduleTrigger) {
|
|
213
|
+
await unscheduleTrigger(triggerName);
|
|
214
|
+
}
|
|
215
|
+
logger.info("Trigger deleted completely", { triggerName });
|
|
216
|
+
}
|
|
217
|
+
} catch (err) {
|
|
218
|
+
logger.error("ERROR in trigger orchestration", {
|
|
219
|
+
type: e.type,
|
|
220
|
+
triggerName: e.triggerName,
|
|
221
|
+
error: err?.message,
|
|
222
|
+
stack: err?.stack
|
|
223
|
+
});
|
|
224
|
+
}
|
|
225
|
+
};
|
|
226
|
+
const handleTriggerStats = async (e) => {
|
|
227
|
+
try {
|
|
228
|
+
if (!e.id || !e.ts) {
|
|
229
|
+
return;
|
|
230
|
+
}
|
|
231
|
+
const triggerName = e.triggerName || e.data?.triggerName;
|
|
232
|
+
if (!triggerName) return;
|
|
233
|
+
const indexKey = StoreSubjects.triggerIndex();
|
|
234
|
+
const now = (/* @__PURE__ */ new Date()).toISOString();
|
|
235
|
+
if (e.type === "trigger.fired") {
|
|
236
|
+
if (store.index.updateWithRetry) {
|
|
237
|
+
await store.index.updateWithRetry(indexKey, triggerName, {
|
|
238
|
+
stats: {
|
|
239
|
+
lastFiredAt: now
|
|
240
|
+
},
|
|
241
|
+
lastActivityAt: now
|
|
242
|
+
});
|
|
243
|
+
}
|
|
244
|
+
if (store.index.increment) {
|
|
245
|
+
await store.index.increment(indexKey, triggerName, "stats.totalFires", 1);
|
|
246
|
+
}
|
|
247
|
+
logger.debug("Updated trigger stats for fire", { triggerName });
|
|
248
|
+
}
|
|
249
|
+
try {
|
|
250
|
+
if (store.index.get) {
|
|
251
|
+
const indexEntry = await store.index.get(indexKey, triggerName);
|
|
252
|
+
if (indexEntry) {
|
|
253
|
+
await eventBus.publish({
|
|
254
|
+
type: "trigger.stats.updated",
|
|
255
|
+
triggerName,
|
|
256
|
+
id: indexEntry.id,
|
|
257
|
+
metadata: indexEntry.metadata,
|
|
258
|
+
ts: Date.now()
|
|
259
|
+
});
|
|
260
|
+
logger.debug("Published trigger stats update event to bus", { triggerName });
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
} catch (err) {
|
|
264
|
+
logger.warn("Failed to publish trigger stats update event", {
|
|
265
|
+
triggerName,
|
|
266
|
+
error: err?.message
|
|
267
|
+
});
|
|
268
|
+
}
|
|
269
|
+
} catch (err) {
|
|
270
|
+
logger.warn("Failed to update trigger stats", {
|
|
271
|
+
type: e.type,
|
|
272
|
+
triggerName: e.triggerName,
|
|
273
|
+
error: err?.message
|
|
274
|
+
});
|
|
275
|
+
}
|
|
276
|
+
};
|
|
277
|
+
const eventTypes = [
|
|
278
|
+
"trigger.registered",
|
|
279
|
+
"trigger.updated",
|
|
280
|
+
"trigger.deleted",
|
|
281
|
+
"trigger.fired",
|
|
282
|
+
"subscription.added",
|
|
283
|
+
"subscription.removed"
|
|
284
|
+
];
|
|
285
|
+
const triggerStatsEventTypes = ["trigger.fired"];
|
|
286
|
+
for (const type of eventTypes) {
|
|
287
|
+
unsubs.push(eventBus.onType(type, handlePersistence));
|
|
288
|
+
}
|
|
289
|
+
for (const type of eventTypes) {
|
|
290
|
+
unsubs.push(eventBus.onType(type, handleOrchestration));
|
|
291
|
+
}
|
|
292
|
+
for (const type of triggerStatsEventTypes) {
|
|
293
|
+
unsubs.push(eventBus.onType(type, handleTriggerStats));
|
|
294
|
+
}
|
|
295
|
+
logger.info("Trigger event wiring setup complete (persistence + orchestration + stats)");
|
|
296
|
+
}
|
|
297
|
+
function stop() {
|
|
298
|
+
const logger = useNventLogger("trigger-wiring");
|
|
299
|
+
for (const u of unsubs.splice(0)) {
|
|
300
|
+
try {
|
|
301
|
+
u();
|
|
302
|
+
} catch {
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
wired = false;
|
|
306
|
+
logger.debug("Trigger wiring stopped");
|
|
307
|
+
}
|
|
308
|
+
return { start, stop };
|
|
309
|
+
}
|
|
310
|
+
export async function handleTriggerFired(event) {
|
|
311
|
+
const logger = useNventLogger("trigger-wiring");
|
|
312
|
+
const trigger = useTrigger();
|
|
313
|
+
const { triggerName, data } = event;
|
|
314
|
+
logger.debug("Trigger fired", { trigger: triggerName });
|
|
315
|
+
const subscriptions = trigger.getAllSubscriptions().filter((sub) => sub.triggerName === triggerName);
|
|
316
|
+
if (subscriptions.length === 0) {
|
|
317
|
+
logger.warn(`No flows subscribed to trigger: ${triggerName}`);
|
|
318
|
+
return [];
|
|
319
|
+
}
|
|
320
|
+
const flowsStarted = [];
|
|
321
|
+
const store = useStoreAdapter();
|
|
322
|
+
const loggerForRuntime = useNventLogger("trigger-runtime");
|
|
323
|
+
const runtime = getTriggerRuntime(store, loggerForRuntime);
|
|
324
|
+
const resolvedData = await runtime.resolvePayload(data);
|
|
325
|
+
for (const subscription of subscriptions) {
|
|
326
|
+
try {
|
|
327
|
+
if (subscription.mode === "manual") {
|
|
328
|
+
logger.info(
|
|
329
|
+
`Trigger '${triggerName}' fired for flow '${subscription.flowName}' (manual mode - awaiting manual start)`
|
|
330
|
+
);
|
|
331
|
+
continue;
|
|
332
|
+
}
|
|
333
|
+
await startFlowFromTrigger(subscription.flowName, triggerName, resolvedData);
|
|
334
|
+
flowsStarted.push(subscription.flowName);
|
|
335
|
+
} catch (error) {
|
|
336
|
+
logger.error("Error starting flow from trigger", {
|
|
337
|
+
flow: subscription.flowName,
|
|
338
|
+
trigger: triggerName,
|
|
339
|
+
error: error instanceof Error ? error.message : String(error)
|
|
340
|
+
});
|
|
341
|
+
}
|
|
342
|
+
}
|
|
343
|
+
return flowsStarted;
|
|
344
|
+
}
|
|
345
|
+
export async function startFlowFromTrigger(flowName, triggerName, triggerData) {
|
|
346
|
+
const logger = useNventLogger("trigger-wiring");
|
|
347
|
+
const eventBus = getEventBus();
|
|
348
|
+
const queue = useQueueAdapter();
|
|
349
|
+
const registry = $useFunctionRegistry();
|
|
350
|
+
const analyzedFlows = $useAnalyzedFlows();
|
|
351
|
+
const store = useStoreAdapter();
|
|
352
|
+
const triggerRuntime = getTriggerRuntime(store, logger);
|
|
353
|
+
const flowDef = analyzedFlows.find((f) => f.id === flowName);
|
|
354
|
+
if (!flowDef || !flowDef.entry) {
|
|
355
|
+
logger.error(`Flow '${flowName}' not found or has no entry point`);
|
|
356
|
+
return;
|
|
357
|
+
}
|
|
358
|
+
const flowRegistry = (registry?.flows || {})[flowName];
|
|
359
|
+
if (!flowRegistry?.entry) {
|
|
360
|
+
logger.error(`Flow '${flowName}' has no entry in registry`);
|
|
361
|
+
return;
|
|
362
|
+
}
|
|
363
|
+
const triggerDef = triggerRuntime.getTrigger(triggerName);
|
|
364
|
+
const triggerType = triggerDef?.type || "manual";
|
|
365
|
+
const runId = `${flowName}-${Date.now()}-${Math.random().toString(36).substring(2, 9)}`;
|
|
366
|
+
logger.info(`Starting flow '${flowName}' from trigger '${triggerName}'`, { runId });
|
|
367
|
+
const queueName = flowRegistry.entry.queue;
|
|
368
|
+
const stepName = flowRegistry.entry.step;
|
|
369
|
+
const payload = {
|
|
370
|
+
flowId: runId,
|
|
371
|
+
flowName,
|
|
372
|
+
trigger: {
|
|
373
|
+
name: triggerName,
|
|
374
|
+
type: triggerType,
|
|
375
|
+
data: triggerData
|
|
376
|
+
},
|
|
377
|
+
...triggerData
|
|
378
|
+
};
|
|
379
|
+
const entryWorker = registry?.workers?.find(
|
|
380
|
+
(w) => w?.flow?.step === stepName && w?.queue?.name === queueName
|
|
381
|
+
);
|
|
382
|
+
const defaultOpts = entryWorker?.queue?.defaultJobOptions || {};
|
|
383
|
+
const jobId = `${runId}__${stepName}`;
|
|
384
|
+
const opts = { ...defaultOpts, jobId };
|
|
385
|
+
try {
|
|
386
|
+
await queue.enqueue(queueName, {
|
|
387
|
+
name: stepName,
|
|
388
|
+
data: payload,
|
|
389
|
+
opts
|
|
390
|
+
});
|
|
391
|
+
logger.info(`Enqueued entry step '${stepName}' to queue '${queueName}'`, { runId });
|
|
392
|
+
await eventBus.publish({
|
|
393
|
+
type: "flow.start",
|
|
394
|
+
flowName,
|
|
395
|
+
runId,
|
|
396
|
+
data: {
|
|
397
|
+
input: triggerData,
|
|
398
|
+
trigger: {
|
|
399
|
+
name: triggerName,
|
|
400
|
+
type: triggerType,
|
|
401
|
+
data: triggerData
|
|
402
|
+
}
|
|
403
|
+
}
|
|
404
|
+
});
|
|
405
|
+
} catch (error) {
|
|
406
|
+
logger.error("Failed to start flow from trigger", {
|
|
407
|
+
flowName,
|
|
408
|
+
trigger: triggerName,
|
|
409
|
+
error: error instanceof Error ? error.message : String(error)
|
|
410
|
+
});
|
|
411
|
+
}
|
|
412
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Adapter Initialization Plugin (v0.4.1)
|
|
3
|
+
*
|
|
4
|
+
* Initializes the three-adapter architecture with new config format:
|
|
5
|
+
* - QueueAdapter: Job queue operations (from config.queue)
|
|
6
|
+
* - StreamAdapter: Cross-instance pub/sub messaging (from config.stream)
|
|
7
|
+
* - StoreAdapter: Storage - events, documents, KV, indices (from config.store)
|
|
8
|
+
*
|
|
9
|
+
* Uses normalized config with connection fallback from connections.*
|
|
10
|
+
*
|
|
11
|
+
* External adapters can register themselves via the nvent:registerAdapter Nitro hook
|
|
12
|
+
*/
|
|
13
|
+
declare const _default: any;
|
|
14
|
+
export default _default;
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { defineNitroPlugin, useRuntimeConfig, useNventLogger, setAdapters, initializeScheduler, shutdownScheduler } from "#imports";
|
|
2
|
+
import { createAdapters, shutdownAdapters } from "../../adapters/factory.js";
|
|
3
|
+
import { useAdapterRegistry } from "../../adapters/registry.js";
|
|
4
|
+
import { createWiringRegistry } from "../../events/wiring/registry.js";
|
|
5
|
+
export default defineNitroPlugin(async (nitroApp) => {
|
|
6
|
+
const logger = useNventLogger("adapters-plugin");
|
|
7
|
+
const runtimeConfig = useRuntimeConfig();
|
|
8
|
+
const config = runtimeConfig.nvent;
|
|
9
|
+
if (!config) {
|
|
10
|
+
logger.error("No nvent config found in runtime config");
|
|
11
|
+
throw new Error("Missing nvent configuration");
|
|
12
|
+
}
|
|
13
|
+
logger.info("Initializing adapters", {
|
|
14
|
+
queue: config.queue?.adapter || "file",
|
|
15
|
+
stream: config.stream?.adapter || "memory",
|
|
16
|
+
store: config.store?.adapter || "file"
|
|
17
|
+
});
|
|
18
|
+
try {
|
|
19
|
+
await nitroApp.hooks.callHook("nvent:register-adapters");
|
|
20
|
+
const registry = useAdapterRegistry();
|
|
21
|
+
logger.info("Checking registered adapters", {
|
|
22
|
+
queueAdapters: registry.listQueueAdapters(),
|
|
23
|
+
streamAdapters: registry.listStreamAdapters(),
|
|
24
|
+
storeAdapters: registry.listStoreAdapters()
|
|
25
|
+
});
|
|
26
|
+
const adapters = await createAdapters({
|
|
27
|
+
queue: config.queue,
|
|
28
|
+
stream: config.stream,
|
|
29
|
+
store: config.store
|
|
30
|
+
});
|
|
31
|
+
setAdapters(adapters);
|
|
32
|
+
logger.info("Adapters initialized successfully", {
|
|
33
|
+
queueAdapter: config.queue.adapter,
|
|
34
|
+
streamAdapter: config.stream.adapter,
|
|
35
|
+
storeAdapter: config.store.adapter
|
|
36
|
+
});
|
|
37
|
+
await initializeScheduler(adapters.store);
|
|
38
|
+
logger.info("Scheduler initialized");
|
|
39
|
+
const wiring = createWiringRegistry({
|
|
40
|
+
streamWiring: {
|
|
41
|
+
enabled: true
|
|
42
|
+
// Enable for WebSocket support
|
|
43
|
+
},
|
|
44
|
+
stateWiring: {
|
|
45
|
+
// Strategy is read from config by default (queue.store.state.cleanup.strategy)
|
|
46
|
+
// Can be overridden here if needed
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
await wiring.start();
|
|
50
|
+
logger.info("Flow wiring started");
|
|
51
|
+
await nitroApp.hooks.callHook("nvent:adapters:ready");
|
|
52
|
+
return {
|
|
53
|
+
hooks: {
|
|
54
|
+
close: async () => {
|
|
55
|
+
logger.info("Shutting down");
|
|
56
|
+
try {
|
|
57
|
+
await wiring.stop();
|
|
58
|
+
logger.info("Flow wiring stopped");
|
|
59
|
+
await shutdownScheduler();
|
|
60
|
+
logger.info("Scheduler shut down");
|
|
61
|
+
await shutdownAdapters(adapters);
|
|
62
|
+
logger.info("Adapters shut down successfully");
|
|
63
|
+
} catch (error) {
|
|
64
|
+
logger.error("Error during shutdown", { error });
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
};
|
|
69
|
+
} catch (error) {
|
|
70
|
+
logger.error("Failed to initialize adapters", { error });
|
|
71
|
+
throw error;
|
|
72
|
+
}
|
|
73
|
+
});
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { defineNitroPlugin, $useWorkerHandlers, $useFunctionRegistry, useQueueAdapter, useHookRegistry } from "#imports";
|
|
2
|
+
import { createJobProcessor } from "../../worker/node/runner.js";
|
|
3
|
+
export default defineNitroPlugin(async (nitroApp) => {
|
|
4
|
+
nitroApp.hooks.hook("close", async () => {
|
|
5
|
+
const queueAdapter = useQueueAdapter();
|
|
6
|
+
await queueAdapter.close();
|
|
7
|
+
});
|
|
8
|
+
nitroApp.hooks.hook("nvent:adapters:ready", async () => {
|
|
9
|
+
const queueAdapter = useQueueAdapter();
|
|
10
|
+
try {
|
|
11
|
+
const handlers = $useWorkerHandlers();
|
|
12
|
+
const registry = $useFunctionRegistry() || { workers: [] };
|
|
13
|
+
const registeredQueues = /* @__PURE__ */ new Set();
|
|
14
|
+
for (const entry of handlers) {
|
|
15
|
+
const { queue, id, handler, module } = entry;
|
|
16
|
+
const w = registry.workers.find((rw) => rw?.id === id || rw?.queue?.name === queue && rw?.absPath === entry.absPath);
|
|
17
|
+
let jobName;
|
|
18
|
+
if (w?.flow?.step) {
|
|
19
|
+
jobName = Array.isArray(w.flow.step) ? w.flow.step[0] : w.flow.step;
|
|
20
|
+
} else {
|
|
21
|
+
jobName = id.includes("/") ? id.split("/").pop() : id;
|
|
22
|
+
}
|
|
23
|
+
if (module && w?.flow) {
|
|
24
|
+
const hooks = {};
|
|
25
|
+
if (typeof module.onAwaitRegister === "function") {
|
|
26
|
+
hooks.onAwaitRegister = module.onAwaitRegister;
|
|
27
|
+
}
|
|
28
|
+
if (typeof module.onAwaitResolve === "function") {
|
|
29
|
+
hooks.onAwaitResolve = module.onAwaitResolve;
|
|
30
|
+
}
|
|
31
|
+
if (Object.keys(hooks).length > 0) {
|
|
32
|
+
const hookRegistry = useHookRegistry();
|
|
33
|
+
const flowNames = w.flow.names ? Array.isArray(w.flow.names) ? w.flow.names : [w.flow.names] : w.flow.name ? Array.isArray(w.flow.name) ? w.flow.name : [w.flow.name] : [];
|
|
34
|
+
for (const flowName of flowNames) {
|
|
35
|
+
if (flowName) {
|
|
36
|
+
hookRegistry.register(flowName, jobName, hooks);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
if (typeof handler === "function") {
|
|
42
|
+
const workerCfg = w && w.worker || {};
|
|
43
|
+
const queueCfg = w && w.queue || {};
|
|
44
|
+
const opts = {};
|
|
45
|
+
if (typeof workerCfg.concurrency === "number") opts.concurrency = workerCfg.concurrency;
|
|
46
|
+
if (typeof workerCfg.autorun === "boolean") opts.autorun = workerCfg.autorun;
|
|
47
|
+
if (queueCfg.defaultJobOptions) opts.defaultJobOptions = queueCfg.defaultJobOptions;
|
|
48
|
+
if (queueCfg.prefix) opts.prefix = queueCfg.prefix;
|
|
49
|
+
if (queueCfg.limiter) opts.limiter = queueCfg.limiter;
|
|
50
|
+
const processor = createJobProcessor(handler, queue);
|
|
51
|
+
queueAdapter.registerWorker(queue, jobName, processor, opts);
|
|
52
|
+
registeredQueues.add(queue);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
if (queueAdapter.startProcessingQueue) {
|
|
56
|
+
for (const queueName of Array.from(registeredQueues)) {
|
|
57
|
+
queueAdapter.startProcessingQueue(queueName);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
} catch {
|
|
61
|
+
}
|
|
62
|
+
});
|
|
63
|
+
});
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Trigger Registration Plugin
|
|
3
|
+
*
|
|
4
|
+
* Loads pre-analyzed triggers and subscriptions from build-time registry
|
|
5
|
+
* and registers them via event bus (trigger.registered events).
|
|
6
|
+
* The trigger wiring will handle the actual registration logic.
|
|
7
|
+
*
|
|
8
|
+
* This plugin is ONLY for registering dev/build-time discovered triggers.
|
|
9
|
+
* Trigger wiring and event handling is done in the wiring registry.
|
|
10
|
+
*/
|
|
11
|
+
declare const _default: any;
|
|
12
|
+
export default _default;
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { defineNitroPlugin, $useTriggerRegistry, useNventLogger, useTrigger } from "#imports";
|
|
2
|
+
import { getEventBus } from "../../events/eventBus.js";
|
|
3
|
+
export default defineNitroPlugin(async (nitroApp) => {
|
|
4
|
+
nitroApp.hooks.hook("nvent:adapters:ready", async () => {
|
|
5
|
+
const logger = useNventLogger("trigger-registration");
|
|
6
|
+
const eventBus = getEventBus();
|
|
7
|
+
const trigger = useTrigger();
|
|
8
|
+
try {
|
|
9
|
+
logger.info("Registering build-time triggers...");
|
|
10
|
+
const triggerRegistry = $useTriggerRegistry();
|
|
11
|
+
const subscriptions = triggerRegistry?.subscriptions || [];
|
|
12
|
+
const triggers = triggerRegistry?.triggers || [];
|
|
13
|
+
logger.info(`Found ${triggers.length} triggers and ${subscriptions.length} subscriptions from build`);
|
|
14
|
+
let newTriggers = 0;
|
|
15
|
+
for (const triggerData of triggers) {
|
|
16
|
+
if (!trigger.hasTrigger(triggerData.name)) {
|
|
17
|
+
await eventBus.publish({
|
|
18
|
+
type: "trigger.registered",
|
|
19
|
+
triggerName: triggerData.name,
|
|
20
|
+
data: triggerData
|
|
21
|
+
});
|
|
22
|
+
newTriggers++;
|
|
23
|
+
} else {
|
|
24
|
+
logger.debug(`Trigger '${triggerData.name}' already registered, skipping`);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
let newSubscriptions = 0;
|
|
28
|
+
for (const sub of subscriptions) {
|
|
29
|
+
const existing = trigger.getSubscription(sub.triggerName, sub.flowName);
|
|
30
|
+
if (!existing) {
|
|
31
|
+
await eventBus.publish({
|
|
32
|
+
type: "subscription.added",
|
|
33
|
+
triggerName: sub.triggerName,
|
|
34
|
+
data: {
|
|
35
|
+
trigger: sub.triggerName,
|
|
36
|
+
flow: sub.flowName,
|
|
37
|
+
mode: sub.mode,
|
|
38
|
+
source: "build-time"
|
|
39
|
+
}
|
|
40
|
+
});
|
|
41
|
+
newSubscriptions++;
|
|
42
|
+
} else {
|
|
43
|
+
logger.debug(`Subscription '${sub.flowName}' -> '${sub.triggerName}' already exists, skipping`);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
logger.info(
|
|
47
|
+
`Build-time trigger registration complete (${newTriggers} new triggers, ${newSubscriptions} new subscriptions)`
|
|
48
|
+
);
|
|
49
|
+
} catch (error) {
|
|
50
|
+
logger.error("Failed to register build-time triggers", {
|
|
51
|
+
error: error instanceof Error ? error.message : String(error)
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
});
|
|
55
|
+
});
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Dynamic webhook handler for await patterns
|
|
3
|
+
* Handles webhook calls and resolves awaiting steps
|
|
4
|
+
*
|
|
5
|
+
* Routes:
|
|
6
|
+
* - POST /api/_webhook/await/{flowName}/{runId}/{stepName}
|
|
7
|
+
* - GET /api/_webhook/await/{flowName}/{runId}/{stepName}
|
|
8
|
+
*
|
|
9
|
+
* Architecture:
|
|
10
|
+
* 1. Parse URL params to get flowName, runId, stepName
|
|
11
|
+
* 2. Look up flow in store index to verify it exists and is awaiting
|
|
12
|
+
* 3. Verify flow status and await configuration
|
|
13
|
+
* 4. Use useAwait().webhook.resolve() which publishes await.resolved event
|
|
14
|
+
* 5. Trigger wiring handles the actual flow resumption
|
|
15
|
+
*/
|
|
16
|
+
declare const _default: import("h3").EventHandler<import("h3").EventHandlerRequest, Promise<{
|
|
17
|
+
success: boolean;
|
|
18
|
+
runId: string;
|
|
19
|
+
stepName: string;
|
|
20
|
+
flowName: string;
|
|
21
|
+
message: string;
|
|
22
|
+
}>>;
|
|
23
|
+
export default _default;
|