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
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
import { defineNitroPlugin, useEventManager, $useQueueRegistry, useQueue, useNventLogger } from "#imports";
|
|
2
|
-
export default defineNitroPlugin((nitro) => {
|
|
3
|
-
const logger = useNventLogger("plugin-flow-management");
|
|
4
|
-
const { onType, publishBus } = useEventManager();
|
|
5
|
-
const registry = $useQueueRegistry();
|
|
6
|
-
const flowIdToName = /* @__PURE__ */ new Map();
|
|
7
|
-
const getFlowNameById = (id) => {
|
|
8
|
-
const cached = flowIdToName.get(id);
|
|
9
|
-
if (cached) return cached;
|
|
10
|
-
try {
|
|
11
|
-
const flows = registry?.flows || {};
|
|
12
|
-
for (const [name, def] of Object.entries(flows)) {
|
|
13
|
-
if (def?.id === id) {
|
|
14
|
-
flowIdToName.set(id, name);
|
|
15
|
-
return name;
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
} catch {
|
|
19
|
-
}
|
|
20
|
-
return void 0;
|
|
21
|
-
};
|
|
22
|
-
const unsubscribes = [];
|
|
23
|
-
unsubscribes.push(onType("emit", async (e) => {
|
|
24
|
-
if (e.runId) return;
|
|
25
|
-
const emitName = e.data?.name;
|
|
26
|
-
if (!emitName) return;
|
|
27
|
-
const triggers = Object.keys(registry?.eventIndex || {});
|
|
28
|
-
if (!triggers.includes(emitName)) return;
|
|
29
|
-
const { enqueue } = useQueue();
|
|
30
|
-
const targets = (registry?.eventIndex)[emitName] || [];
|
|
31
|
-
for (const t of targets) {
|
|
32
|
-
const payload = { ...e.data };
|
|
33
|
-
try {
|
|
34
|
-
const id = await enqueue(t.queue, { name: t.step, data: payload });
|
|
35
|
-
try {
|
|
36
|
-
const targetFlowName = getFlowNameById(String(t.flowId)) || String(t.flowId);
|
|
37
|
-
const newRunId = String(id);
|
|
38
|
-
await publishBus({
|
|
39
|
-
type: "flow.start",
|
|
40
|
-
runId: newRunId,
|
|
41
|
-
flowName: targetFlowName,
|
|
42
|
-
data: { input: payload }
|
|
43
|
-
});
|
|
44
|
-
if (process.env.NQ_DEBUG_EVENTS === "1") {
|
|
45
|
-
logger.info("[flow-lifecycle] started new flow:", {
|
|
46
|
-
flowName: targetFlowName,
|
|
47
|
-
runId: newRunId,
|
|
48
|
-
entryStep: t.step
|
|
49
|
-
});
|
|
50
|
-
}
|
|
51
|
-
} catch {
|
|
52
|
-
}
|
|
53
|
-
} catch (err) {
|
|
54
|
-
logger.warn("[flow-lifecycle] failed to start flow:", {
|
|
55
|
-
step: t.step,
|
|
56
|
-
error: err?.message
|
|
57
|
-
});
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
}));
|
|
61
|
-
nitro.hooks.hook("close", () => {
|
|
62
|
-
unsubscribes.forEach((fn) => fn());
|
|
63
|
-
flowIdToName.clear();
|
|
64
|
-
});
|
|
65
|
-
});
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import { defineNitroPlugin, useNventLogger } from "#imports";
|
|
2
|
-
import { BullMQProvider } from "../../server-utils/queue/adapters/bullmq.js";
|
|
3
|
-
import { setQueueProvider, getQueueProvider } from "../../server-utils/queue/queueFactory.js";
|
|
4
|
-
export default defineNitroPlugin(async (nitroApp) => {
|
|
5
|
-
const logger = useNventLogger("plugin-queue-management");
|
|
6
|
-
try {
|
|
7
|
-
const existingProvider = getQueueProvider();
|
|
8
|
-
if (existingProvider) {
|
|
9
|
-
logger.info("[queues plugin] Closing existing queue provider before creating new one...");
|
|
10
|
-
await existingProvider.close();
|
|
11
|
-
await new Promise((resolve) => setTimeout(resolve, 100));
|
|
12
|
-
}
|
|
13
|
-
} catch {
|
|
14
|
-
}
|
|
15
|
-
const provider = new BullMQProvider();
|
|
16
|
-
await provider.init();
|
|
17
|
-
setQueueProvider(provider);
|
|
18
|
-
nitroApp.hooks.hook("close", async () => {
|
|
19
|
-
logger.info("[queues plugin] Closing queue provider...");
|
|
20
|
-
await provider.close();
|
|
21
|
-
});
|
|
22
|
-
return {
|
|
23
|
-
async close() {
|
|
24
|
-
await provider.close();
|
|
25
|
-
}
|
|
26
|
-
};
|
|
27
|
-
});
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* State Cleanup Plugin
|
|
3
|
-
*
|
|
4
|
-
* Handles automatic cleanup of flow state based on configuration strategy:
|
|
5
|
-
* - 'never': State persists indefinitely
|
|
6
|
-
* - 'immediate': Cleanup after each step (original behavior, not recommended)
|
|
7
|
-
* - 'on-complete': Cleanup when flow completes (recommended, uses lifecycle tracking)
|
|
8
|
-
* - 'ttl': State expires automatically via TTL (handled by storage provider)
|
|
9
|
-
*/
|
|
10
|
-
declare const _default: any;
|
|
11
|
-
export default _default;
|
|
@@ -1,93 +0,0 @@
|
|
|
1
|
-
import { useNventLogger, defineNitroPlugin, useEventManager, useRuntimeConfig } from "#imports";
|
|
2
|
-
import { getStateProvider } from "../../server-utils/state/stateFactory.js";
|
|
3
|
-
export default defineNitroPlugin(() => {
|
|
4
|
-
const logger = useNventLogger("plugin-state-cleanup");
|
|
5
|
-
const rc = useRuntimeConfig();
|
|
6
|
-
const cleanup = rc?.queue?.state?.cleanup || { strategy: "never" };
|
|
7
|
-
if (cleanup.strategy === "never" || cleanup.strategy === "ttl") {
|
|
8
|
-
return;
|
|
9
|
-
}
|
|
10
|
-
const { onType } = useEventManager();
|
|
11
|
-
const unsubs = [];
|
|
12
|
-
if (cleanup.strategy === "on-complete") {
|
|
13
|
-
unsubs.push(onType("flow.completed", async (event) => {
|
|
14
|
-
const flowId = event.runId;
|
|
15
|
-
if (!flowId) return;
|
|
16
|
-
try {
|
|
17
|
-
const sp = getStateProvider();
|
|
18
|
-
const prefix = `flow:${flowId}:`;
|
|
19
|
-
const { keys } = await sp.list(prefix);
|
|
20
|
-
if (keys.length > 0) {
|
|
21
|
-
const rc2 = useRuntimeConfig();
|
|
22
|
-
const ns = rc2?.queue?.state?.namespace || "nq";
|
|
23
|
-
const nsPrefix = `${ns}:`;
|
|
24
|
-
await Promise.all(keys.map((k) => {
|
|
25
|
-
const keyWithoutNs = k.startsWith(nsPrefix) ? k.substring(nsPrefix.length) : k;
|
|
26
|
-
return sp.delete(keyWithoutNs);
|
|
27
|
-
}));
|
|
28
|
-
logger.info(`Cleaned up ${keys.length} state keys after flow completion`, { flowId, keys });
|
|
29
|
-
}
|
|
30
|
-
} catch (error) {
|
|
31
|
-
logger.error("Error cleaning up state after flow completion", { flowId, error });
|
|
32
|
-
}
|
|
33
|
-
}));
|
|
34
|
-
unsubs.push(onType("flow.failed", async (event) => {
|
|
35
|
-
const flowId = event.runId;
|
|
36
|
-
if (!flowId) return;
|
|
37
|
-
try {
|
|
38
|
-
const sp = getStateProvider();
|
|
39
|
-
const prefix = `flow:${flowId}:`;
|
|
40
|
-
const { keys } = await sp.list(prefix);
|
|
41
|
-
if (keys.length > 0) {
|
|
42
|
-
const rc2 = useRuntimeConfig();
|
|
43
|
-
const ns = rc2?.queue?.state?.namespace || "nq";
|
|
44
|
-
const nsPrefix = `${ns}:`;
|
|
45
|
-
await Promise.all(keys.map((k) => {
|
|
46
|
-
const keyWithoutNs = k.startsWith(nsPrefix) ? k.substring(nsPrefix.length) : k;
|
|
47
|
-
return sp.delete(keyWithoutNs);
|
|
48
|
-
}));
|
|
49
|
-
logger.info(`Cleaned up ${keys.length} state keys after flow failure`, { flowId, keys });
|
|
50
|
-
}
|
|
51
|
-
} catch (error) {
|
|
52
|
-
logger.error("Error cleaning up state after flow failure", { flowId, error });
|
|
53
|
-
}
|
|
54
|
-
}));
|
|
55
|
-
logger.debug("Plugin initialized with strategy: on-complete");
|
|
56
|
-
} else if (cleanup.strategy === "immediate") {
|
|
57
|
-
unsubs.push(onType("step.completed", async (event) => {
|
|
58
|
-
const flowId = event.runId;
|
|
59
|
-
if (!flowId) return;
|
|
60
|
-
try {
|
|
61
|
-
const sp = getStateProvider();
|
|
62
|
-
const prefix = `flow:${flowId}:`;
|
|
63
|
-
const { keys } = await sp.list(prefix);
|
|
64
|
-
if (keys.length > 0) {
|
|
65
|
-
const rc2 = useRuntimeConfig();
|
|
66
|
-
const ns = rc2?.queue?.state?.namespace || "nq";
|
|
67
|
-
const nsPrefix = `${ns}:`;
|
|
68
|
-
await Promise.all(keys.map((k) => {
|
|
69
|
-
const keyWithoutNs = k.startsWith(nsPrefix) ? k.substring(nsPrefix.length) : k;
|
|
70
|
-
return sp.delete(keyWithoutNs);
|
|
71
|
-
}));
|
|
72
|
-
logger.info(`Cleaned up ${keys.length} state keys after step completion`, { flowId, keys });
|
|
73
|
-
}
|
|
74
|
-
} catch (error) {
|
|
75
|
-
logger.error("Error cleaning up state after step", { flowId, error });
|
|
76
|
-
}
|
|
77
|
-
}));
|
|
78
|
-
logger.debug("Plugin initialized with strategy: immediate");
|
|
79
|
-
}
|
|
80
|
-
return {
|
|
81
|
-
hooks: {
|
|
82
|
-
close: async () => {
|
|
83
|
-
for (const u of unsubs) {
|
|
84
|
-
try {
|
|
85
|
-
u();
|
|
86
|
-
} catch {
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
unsubs.length = 0;
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
};
|
|
93
|
-
});
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
import { defineNitroPlugin, $useWorkerHandlers, $useQueueRegistry } from "#imports";
|
|
2
|
-
import { registerTsWorker, closeAllWorkers } from "../../server-utils/worker/adapter.js";
|
|
3
|
-
export default defineNitroPlugin(async (nitroApp) => {
|
|
4
|
-
nitroApp.hooks.hook("close", async () => {
|
|
5
|
-
await closeAllWorkers();
|
|
6
|
-
});
|
|
7
|
-
try {
|
|
8
|
-
const handlers = $useWorkerHandlers();
|
|
9
|
-
const registry = $useQueueRegistry() || { workers: [] };
|
|
10
|
-
for (const entry of handlers) {
|
|
11
|
-
const { queue, id, handler } = entry;
|
|
12
|
-
const w = registry.workers.find((rw) => rw?.id === id || rw?.queue?.name === queue && rw?.absPath === entry.absPath);
|
|
13
|
-
let jobName;
|
|
14
|
-
if (w?.flow?.step) {
|
|
15
|
-
jobName = Array.isArray(w.flow.step) ? w.flow.step[0] : w.flow.step;
|
|
16
|
-
} else {
|
|
17
|
-
jobName = id.includes("/") ? id.split("/").pop() : id;
|
|
18
|
-
}
|
|
19
|
-
if (typeof handler === "function") {
|
|
20
|
-
const cfg = w && w.worker || {};
|
|
21
|
-
const opts = {};
|
|
22
|
-
if (typeof cfg.concurrency === "number") opts.concurrency = cfg.concurrency;
|
|
23
|
-
if (typeof cfg.lockDurationMs === "number") opts.lockDuration = cfg.lockDurationMs;
|
|
24
|
-
if (typeof cfg.maxStalledCount === "number") opts.maxStalledCount = cfg.maxStalledCount;
|
|
25
|
-
if (typeof cfg.drainDelayMs === "number") opts.drainDelay = cfg.drainDelayMs;
|
|
26
|
-
if (typeof cfg.autorun === "boolean") opts.autorun = cfg.autorun;
|
|
27
|
-
if (w?.queue?.prefix) opts.prefix = w.queue.prefix;
|
|
28
|
-
await registerTsWorker(queue, jobName, handler, opts);
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
} catch {
|
|
32
|
-
}
|
|
33
|
-
});
|
|
@@ -1,382 +0,0 @@
|
|
|
1
|
-
import { promises as fsp } from "node:fs";
|
|
2
|
-
import { dirname, join } from "node:path";
|
|
3
|
-
import { useRuntimeConfig } from "#imports";
|
|
4
|
-
function nowIso() {
|
|
5
|
-
return (/* @__PURE__ */ new Date()).toISOString();
|
|
6
|
-
}
|
|
7
|
-
function sanitize(name) {
|
|
8
|
-
return name.replace(/[^\w.-]/g, "_");
|
|
9
|
-
}
|
|
10
|
-
async function ensureDir(path) {
|
|
11
|
-
try {
|
|
12
|
-
await fsp.mkdir(path, { recursive: true });
|
|
13
|
-
} catch {
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
async function fileExists(path) {
|
|
17
|
-
try {
|
|
18
|
-
await fsp.access(path);
|
|
19
|
-
return true;
|
|
20
|
-
} catch {
|
|
21
|
-
return false;
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
export function createFileAdapter() {
|
|
25
|
-
const rc = useRuntimeConfig();
|
|
26
|
-
const rootDir = rc?.queue?.rootDir || process.cwd();
|
|
27
|
-
const dirRoot = rc?.queue?.eventStore?.options?.file?.dir ? join(rootDir, rc.queue.eventStore.options.file.dir) : join(rootDir, ".data/nq-events");
|
|
28
|
-
const ext = rc?.queue?.eventStore?.options?.file?.ext || ".ndjson";
|
|
29
|
-
const pollMs = rc?.queue?.eventStore?.options?.file?.pollMs ?? 1e3;
|
|
30
|
-
const subscribers = /* @__PURE__ */ new Map();
|
|
31
|
-
const timers = /* @__PURE__ */ new Map();
|
|
32
|
-
const lastIds = /* @__PURE__ */ new Map();
|
|
33
|
-
const indices = /* @__PURE__ */ new Map();
|
|
34
|
-
const streamPath = (stream) => join(dirRoot, sanitize(stream) + ext);
|
|
35
|
-
const indexPath = (key) => join(dirRoot, "indices", sanitize(key) + ".json");
|
|
36
|
-
const readAll = async (stream) => {
|
|
37
|
-
const p = streamPath(stream);
|
|
38
|
-
if (!await fileExists(p)) return [];
|
|
39
|
-
const content = await fsp.readFile(p, "utf8");
|
|
40
|
-
const lines = content.split("\n").filter(Boolean);
|
|
41
|
-
const out = [];
|
|
42
|
-
for (const line of lines) {
|
|
43
|
-
try {
|
|
44
|
-
const rec = JSON.parse(line);
|
|
45
|
-
out.push(rec);
|
|
46
|
-
} catch {
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
return out;
|
|
50
|
-
};
|
|
51
|
-
const adapter = {
|
|
52
|
-
async append(stream, e) {
|
|
53
|
-
const id = `${Date.now()}-${Math.random().toString(16).slice(2)}`;
|
|
54
|
-
const rec = { ...e, id, ts: nowIso() };
|
|
55
|
-
const p = streamPath(stream);
|
|
56
|
-
await ensureDir(dirname(p));
|
|
57
|
-
await fsp.appendFile(p, JSON.stringify(rec) + "\n", { encoding: "utf8" });
|
|
58
|
-
const set = subscribers.get(stream);
|
|
59
|
-
if (set) {
|
|
60
|
-
for (const cb of set) {
|
|
61
|
-
try {
|
|
62
|
-
cb(rec);
|
|
63
|
-
} catch {
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
return rec;
|
|
68
|
-
},
|
|
69
|
-
async read(stream, opts) {
|
|
70
|
-
const list = await readAll(stream);
|
|
71
|
-
const dir = opts?.direction || "forward";
|
|
72
|
-
if (dir === "backward") {
|
|
73
|
-
let end = list.length;
|
|
74
|
-
if (opts?.fromId) {
|
|
75
|
-
const idx2 = list.findIndex((e) => e.id === opts.fromId);
|
|
76
|
-
end = idx2 >= 0 ? idx2 : list.length;
|
|
77
|
-
}
|
|
78
|
-
const count = opts?.limit && opts.limit > 0 ? opts.limit : end;
|
|
79
|
-
const start = Math.max(0, end - count);
|
|
80
|
-
const slice = list.slice(start, end);
|
|
81
|
-
return slice.reverse();
|
|
82
|
-
}
|
|
83
|
-
if (!opts?.fromId) {
|
|
84
|
-
if (opts?.limit && opts.limit > 0) return list.slice(0, opts.limit);
|
|
85
|
-
return list;
|
|
86
|
-
}
|
|
87
|
-
const idx = list.findIndex((e) => e.id === opts.fromId);
|
|
88
|
-
const sliced = idx >= 0 ? list.slice(idx + 1) : list;
|
|
89
|
-
if (opts?.limit && opts.limit > 0) return sliced.slice(0, opts.limit);
|
|
90
|
-
return sliced;
|
|
91
|
-
},
|
|
92
|
-
async subscribe(stream, onEvent) {
|
|
93
|
-
let set = subscribers.get(stream);
|
|
94
|
-
if (!set) {
|
|
95
|
-
set = /* @__PURE__ */ new Set();
|
|
96
|
-
subscribers.set(stream, set);
|
|
97
|
-
}
|
|
98
|
-
set.add(onEvent);
|
|
99
|
-
if (!timers.has(stream)) {
|
|
100
|
-
const t = setInterval(async () => {
|
|
101
|
-
try {
|
|
102
|
-
const fromId = lastIds.get(stream);
|
|
103
|
-
const fresh = await adapter.read(stream, fromId ? { fromId } : void 0);
|
|
104
|
-
if (fresh.length) {
|
|
105
|
-
for (const rec of fresh) {
|
|
106
|
-
set.forEach((cb) => {
|
|
107
|
-
try {
|
|
108
|
-
cb(rec);
|
|
109
|
-
} catch {
|
|
110
|
-
}
|
|
111
|
-
});
|
|
112
|
-
lastIds.set(stream, rec.id);
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
} catch {
|
|
116
|
-
}
|
|
117
|
-
}, pollMs);
|
|
118
|
-
timers.set(stream, t);
|
|
119
|
-
}
|
|
120
|
-
return {
|
|
121
|
-
unsubscribe() {
|
|
122
|
-
const s = subscribers.get(stream);
|
|
123
|
-
if (s) s.delete(onEvent);
|
|
124
|
-
if (s && s.size === 0) {
|
|
125
|
-
subscribers.delete(stream);
|
|
126
|
-
const t = timers.get(stream);
|
|
127
|
-
if (t) {
|
|
128
|
-
try {
|
|
129
|
-
clearInterval(t);
|
|
130
|
-
} catch {
|
|
131
|
-
}
|
|
132
|
-
timers.delete(stream);
|
|
133
|
-
}
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
};
|
|
137
|
-
},
|
|
138
|
-
async deleteStream(subject) {
|
|
139
|
-
const p = streamPath(subject);
|
|
140
|
-
try {
|
|
141
|
-
await fsp.unlink(p);
|
|
142
|
-
} catch {
|
|
143
|
-
}
|
|
144
|
-
subscribers.delete(subject);
|
|
145
|
-
const t = timers.get(subject);
|
|
146
|
-
if (t) {
|
|
147
|
-
clearInterval(t);
|
|
148
|
-
timers.delete(subject);
|
|
149
|
-
}
|
|
150
|
-
lastIds.delete(subject);
|
|
151
|
-
},
|
|
152
|
-
async deleteByPattern(pattern) {
|
|
153
|
-
const regexPattern = pattern.replace(/\*/g, ".*").replace(/\?/g, ".");
|
|
154
|
-
const regex = new RegExp(`^${regexPattern}$`);
|
|
155
|
-
let count = 0;
|
|
156
|
-
try {
|
|
157
|
-
await ensureDir(dirRoot);
|
|
158
|
-
const files = await fsp.readdir(dirRoot);
|
|
159
|
-
for (const file of files) {
|
|
160
|
-
if (!file.endsWith(ext)) continue;
|
|
161
|
-
const subject = file.slice(0, -ext.length);
|
|
162
|
-
if (regex.test(subject)) {
|
|
163
|
-
const p = join(dirRoot, file);
|
|
164
|
-
await fsp.unlink(p);
|
|
165
|
-
subscribers.delete(subject);
|
|
166
|
-
const t = timers.get(subject);
|
|
167
|
-
if (t) {
|
|
168
|
-
clearInterval(t);
|
|
169
|
-
timers.delete(subject);
|
|
170
|
-
}
|
|
171
|
-
lastIds.delete(subject);
|
|
172
|
-
count++;
|
|
173
|
-
}
|
|
174
|
-
}
|
|
175
|
-
} catch {
|
|
176
|
-
}
|
|
177
|
-
return count;
|
|
178
|
-
},
|
|
179
|
-
async deleteIndex(key) {
|
|
180
|
-
indices.delete(key);
|
|
181
|
-
const p = indexPath(key);
|
|
182
|
-
try {
|
|
183
|
-
await fsp.unlink(p);
|
|
184
|
-
} catch {
|
|
185
|
-
}
|
|
186
|
-
},
|
|
187
|
-
async indexAdd(key, id, score, metadata) {
|
|
188
|
-
let data = indices.get(key);
|
|
189
|
-
if (!data) {
|
|
190
|
-
const p2 = indexPath(key);
|
|
191
|
-
if (await fileExists(p2)) {
|
|
192
|
-
try {
|
|
193
|
-
const content = await fsp.readFile(p2, "utf8");
|
|
194
|
-
data = JSON.parse(content);
|
|
195
|
-
} catch {
|
|
196
|
-
data = [];
|
|
197
|
-
}
|
|
198
|
-
} else {
|
|
199
|
-
data = [];
|
|
200
|
-
}
|
|
201
|
-
indices.set(key, data);
|
|
202
|
-
}
|
|
203
|
-
const existing = data.findIndex((entry) => entry.id === id);
|
|
204
|
-
if (existing >= 0) {
|
|
205
|
-
data[existing] = { ...data[existing], score, ...metadata };
|
|
206
|
-
} else {
|
|
207
|
-
data.push({ id, score, ...metadata });
|
|
208
|
-
}
|
|
209
|
-
const p = indexPath(key);
|
|
210
|
-
await ensureDir(dirname(p));
|
|
211
|
-
await fsp.writeFile(p, JSON.stringify(data, null, 2), "utf8");
|
|
212
|
-
},
|
|
213
|
-
async indexRead(key, opts) {
|
|
214
|
-
let data = indices.get(key);
|
|
215
|
-
if (!data) {
|
|
216
|
-
const p = indexPath(key);
|
|
217
|
-
if (await fileExists(p)) {
|
|
218
|
-
try {
|
|
219
|
-
const content = await fsp.readFile(p, "utf8");
|
|
220
|
-
data = JSON.parse(content);
|
|
221
|
-
indices.set(key, data);
|
|
222
|
-
} catch {
|
|
223
|
-
data = [];
|
|
224
|
-
}
|
|
225
|
-
} else {
|
|
226
|
-
data = [];
|
|
227
|
-
}
|
|
228
|
-
}
|
|
229
|
-
const sorted = [...data].sort((a, b) => b.score - a.score);
|
|
230
|
-
const offset = opts?.offset || 0;
|
|
231
|
-
const limit = opts?.limit || 50;
|
|
232
|
-
return sorted.slice(offset, offset + limit).map((entry) => ({
|
|
233
|
-
id: entry.id,
|
|
234
|
-
score: entry.score,
|
|
235
|
-
metadata: {
|
|
236
|
-
status: entry.status,
|
|
237
|
-
startedAt: entry.startedAt,
|
|
238
|
-
completedAt: entry.completedAt,
|
|
239
|
-
stepCount: entry.stepCount,
|
|
240
|
-
completedSteps: entry.completedSteps,
|
|
241
|
-
emittedEvents: entry.emittedEvents
|
|
242
|
-
}
|
|
243
|
-
}));
|
|
244
|
-
},
|
|
245
|
-
async indexGet(key, id) {
|
|
246
|
-
let data = indices.get(key);
|
|
247
|
-
if (!data) {
|
|
248
|
-
const p = indexPath(key);
|
|
249
|
-
if (await fileExists(p)) {
|
|
250
|
-
try {
|
|
251
|
-
const content = await fsp.readFile(p, "utf8");
|
|
252
|
-
data = JSON.parse(content);
|
|
253
|
-
indices.set(key, data);
|
|
254
|
-
} catch {
|
|
255
|
-
data = [];
|
|
256
|
-
}
|
|
257
|
-
} else {
|
|
258
|
-
data = [];
|
|
259
|
-
}
|
|
260
|
-
}
|
|
261
|
-
const entry = data.find((e) => e.id === id);
|
|
262
|
-
if (!entry) return null;
|
|
263
|
-
return {
|
|
264
|
-
id: entry.id,
|
|
265
|
-
score: entry.score,
|
|
266
|
-
metadata: {
|
|
267
|
-
status: entry.status,
|
|
268
|
-
startedAt: entry.startedAt,
|
|
269
|
-
completedAt: entry.completedAt,
|
|
270
|
-
stepCount: entry.stepCount,
|
|
271
|
-
completedSteps: entry.completedSteps,
|
|
272
|
-
emittedEvents: entry.emittedEvents
|
|
273
|
-
}
|
|
274
|
-
};
|
|
275
|
-
},
|
|
276
|
-
async indexUpdate(key, id, metadata) {
|
|
277
|
-
let data = indices.get(key);
|
|
278
|
-
if (!data) {
|
|
279
|
-
const p2 = indexPath(key);
|
|
280
|
-
if (await fileExists(p2)) {
|
|
281
|
-
try {
|
|
282
|
-
const content = await fsp.readFile(p2, "utf8");
|
|
283
|
-
data = JSON.parse(content);
|
|
284
|
-
} catch {
|
|
285
|
-
data = [];
|
|
286
|
-
}
|
|
287
|
-
} else {
|
|
288
|
-
data = [];
|
|
289
|
-
}
|
|
290
|
-
indices.set(key, data);
|
|
291
|
-
}
|
|
292
|
-
const entry = data.find((e) => e.id === id);
|
|
293
|
-
if (!entry) return false;
|
|
294
|
-
Object.assign(entry, metadata);
|
|
295
|
-
const p = indexPath(key);
|
|
296
|
-
await ensureDir(dirname(p));
|
|
297
|
-
await fsp.writeFile(p, JSON.stringify(data, null, 2), "utf8");
|
|
298
|
-
return true;
|
|
299
|
-
},
|
|
300
|
-
async indexUpdateWithRetry(key, id, metadata, maxRetries = 3) {
|
|
301
|
-
for (let attempt = 0; attempt < maxRetries; attempt++) {
|
|
302
|
-
const success = await this.indexUpdate(key, id, metadata);
|
|
303
|
-
if (success) return;
|
|
304
|
-
await new Promise((resolve) => setTimeout(resolve, 10 * Math.pow(2, attempt)));
|
|
305
|
-
}
|
|
306
|
-
throw new Error(`Failed to update index after ${maxRetries} retries`);
|
|
307
|
-
},
|
|
308
|
-
async indexIncrement(key, id, field, increment = 1) {
|
|
309
|
-
let data = indices.get(key);
|
|
310
|
-
if (!data) {
|
|
311
|
-
const p2 = indexPath(key);
|
|
312
|
-
if (await fileExists(p2)) {
|
|
313
|
-
try {
|
|
314
|
-
const content = await fsp.readFile(p2, "utf8");
|
|
315
|
-
data = JSON.parse(content);
|
|
316
|
-
} catch {
|
|
317
|
-
data = [];
|
|
318
|
-
}
|
|
319
|
-
} else {
|
|
320
|
-
data = [];
|
|
321
|
-
}
|
|
322
|
-
indices.set(key, data);
|
|
323
|
-
}
|
|
324
|
-
const entry = data.find((e) => e.id === id);
|
|
325
|
-
if (!entry) return 0;
|
|
326
|
-
const currentValue = entry[field] || 0;
|
|
327
|
-
const newValue = currentValue + increment;
|
|
328
|
-
entry[field] = newValue;
|
|
329
|
-
const p = indexPath(key);
|
|
330
|
-
await ensureDir(dirname(p));
|
|
331
|
-
await fsp.writeFile(p, JSON.stringify(data, null, 2), "utf8");
|
|
332
|
-
return newValue;
|
|
333
|
-
},
|
|
334
|
-
async cleanupCompletedFlows(key, retentionSeconds) {
|
|
335
|
-
let data = indices.get(key);
|
|
336
|
-
if (!data) {
|
|
337
|
-
const p = indexPath(key);
|
|
338
|
-
if (await fileExists(p)) {
|
|
339
|
-
try {
|
|
340
|
-
const content = await fsp.readFile(p, "utf8");
|
|
341
|
-
data = JSON.parse(content);
|
|
342
|
-
} catch {
|
|
343
|
-
data = [];
|
|
344
|
-
}
|
|
345
|
-
} else {
|
|
346
|
-
data = [];
|
|
347
|
-
}
|
|
348
|
-
indices.set(key, data);
|
|
349
|
-
}
|
|
350
|
-
const now = Date.now();
|
|
351
|
-
const cutoffTime = now - retentionSeconds * 1e3;
|
|
352
|
-
const originalLength = data.length;
|
|
353
|
-
const filtered = data.filter((entry) => {
|
|
354
|
-
const isTerminal = entry.status === "completed" || entry.status === "failed";
|
|
355
|
-
const isOld = entry.completedAt ? entry.completedAt < cutoffTime : false;
|
|
356
|
-
return !(isTerminal && isOld);
|
|
357
|
-
});
|
|
358
|
-
const removedCount = originalLength - filtered.length;
|
|
359
|
-
if (removedCount > 0) {
|
|
360
|
-
indices.set(key, filtered);
|
|
361
|
-
const p = indexPath(key);
|
|
362
|
-
await ensureDir(dirname(p));
|
|
363
|
-
await fsp.writeFile(p, JSON.stringify(filtered, null, 2), "utf8");
|
|
364
|
-
}
|
|
365
|
-
return removedCount;
|
|
366
|
-
},
|
|
367
|
-
async setMetadataTTL(_key, _id, _ttlSeconds) {
|
|
368
|
-
},
|
|
369
|
-
async close() {
|
|
370
|
-
for (const t of timers.values()) {
|
|
371
|
-
try {
|
|
372
|
-
clearInterval(t);
|
|
373
|
-
} catch {
|
|
374
|
-
}
|
|
375
|
-
}
|
|
376
|
-
timers.clear();
|
|
377
|
-
subscribers.clear();
|
|
378
|
-
lastIds.clear();
|
|
379
|
-
}
|
|
380
|
-
};
|
|
381
|
-
return adapter;
|
|
382
|
-
}
|