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,164 +0,0 @@
|
|
|
1
|
-
import { Queue, QueueEvents } from "bullmq";
|
|
2
|
-
import defu from "defu";
|
|
3
|
-
import { useRuntimeConfig, $useQueueRegistry, useEventManager, useNventLogger } from "#imports";
|
|
4
|
-
export class BullMQProvider {
|
|
5
|
-
queues = /* @__PURE__ */ new Map();
|
|
6
|
-
logger = useNventLogger("bullmq-adapter");
|
|
7
|
-
async init() {
|
|
8
|
-
}
|
|
9
|
-
ensureQueue(name) {
|
|
10
|
-
let cached = this.queues.get(name);
|
|
11
|
-
if (cached) return cached;
|
|
12
|
-
const { publishBus } = useEventManager();
|
|
13
|
-
const rc = useRuntimeConfig();
|
|
14
|
-
const connection = rc.queue?.queue?.redis;
|
|
15
|
-
let queueDefaults = void 0;
|
|
16
|
-
let prefix;
|
|
17
|
-
let limiter = void 0;
|
|
18
|
-
try {
|
|
19
|
-
const registry = $useQueueRegistry();
|
|
20
|
-
if (registry && Array.isArray(registry.workers)) {
|
|
21
|
-
const w = registry.workers.find((w2) => w2?.queue?.name === name);
|
|
22
|
-
if (w?.queue) {
|
|
23
|
-
queueDefaults = w.queue.defaultJobOptions;
|
|
24
|
-
prefix = w.queue.prefix;
|
|
25
|
-
limiter = w.queue.limiter;
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
} catch {
|
|
29
|
-
}
|
|
30
|
-
const queueOpts = { connection, prefix, defaultJobOptions: queueDefaults };
|
|
31
|
-
if (limiter) {
|
|
32
|
-
queueOpts.limiter = {
|
|
33
|
-
max: limiter.max,
|
|
34
|
-
duration: limiter.duration,
|
|
35
|
-
groupKey: limiter.groupKey
|
|
36
|
-
};
|
|
37
|
-
}
|
|
38
|
-
const queue = new Queue(name, queueOpts);
|
|
39
|
-
const events = new QueueEvents(name, { connection, prefix });
|
|
40
|
-
events.setMaxListeners(50);
|
|
41
|
-
cached = { queue, events, wired: false, defaults: queueDefaults };
|
|
42
|
-
this.queues.set(name, cached);
|
|
43
|
-
const forward = async (kind, payload) => {
|
|
44
|
-
const jobId = payload?.jobId || "unknown";
|
|
45
|
-
let runId = "";
|
|
46
|
-
try {
|
|
47
|
-
if (jobId && jobId !== "unknown") {
|
|
48
|
-
const job = await queue.getJob(jobId);
|
|
49
|
-
if (job?.data?.flowId) {
|
|
50
|
-
runId = job.data.flowId;
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
} catch {
|
|
54
|
-
}
|
|
55
|
-
const rec = {
|
|
56
|
-
type: `job.${kind}`,
|
|
57
|
-
runId,
|
|
58
|
-
data: { ...payload, queue: name, jobId }
|
|
59
|
-
};
|
|
60
|
-
await publishBus(rec);
|
|
61
|
-
};
|
|
62
|
-
for (const ev of ["waiting", "active", "progress", "completed", "failed", "delayed"]) {
|
|
63
|
-
events.on(ev, (p) => {
|
|
64
|
-
void forward(ev, p);
|
|
65
|
-
});
|
|
66
|
-
}
|
|
67
|
-
cached.wired = true;
|
|
68
|
-
return cached;
|
|
69
|
-
}
|
|
70
|
-
async enqueue(queueName, job) {
|
|
71
|
-
const { queue, defaults } = this.ensureQueue(queueName);
|
|
72
|
-
const opts = defu(job.opts || {}, defaults || {});
|
|
73
|
-
const bullJob = await queue.add(job.name, job.data, opts);
|
|
74
|
-
return bullJob.id;
|
|
75
|
-
}
|
|
76
|
-
async schedule(queueName, job, opts) {
|
|
77
|
-
const { queue, defaults } = this.ensureQueue(queueName);
|
|
78
|
-
const jobsOpts = defu({ ...job.opts }, defaults || {});
|
|
79
|
-
if (opts?.delay) jobsOpts.delay = opts.delay;
|
|
80
|
-
if (opts?.cron) jobsOpts.repeat = { pattern: opts.cron };
|
|
81
|
-
const bullJob = await queue.add(job.name, job.data, jobsOpts);
|
|
82
|
-
return bullJob.id;
|
|
83
|
-
}
|
|
84
|
-
async getJob(queueName, id) {
|
|
85
|
-
const { queue } = this.ensureQueue(queueName);
|
|
86
|
-
const j = await queue.getJob(id);
|
|
87
|
-
if (!j) return null;
|
|
88
|
-
return await this.toJob(j);
|
|
89
|
-
}
|
|
90
|
-
async getJobs(queueName, _q) {
|
|
91
|
-
const { queue } = this.ensureQueue(queueName);
|
|
92
|
-
const states = _q?.state && _q.state.length > 0 ? _q.state : ["waiting", "active", "completed", "failed", "delayed", "paused"];
|
|
93
|
-
const limit = _q?.limit || 1e3;
|
|
94
|
-
const jobs = await queue.getJobs(states, 0, limit - 1);
|
|
95
|
-
return await Promise.all(jobs.map((j) => this.toJob(j)));
|
|
96
|
-
}
|
|
97
|
-
on(queueName, event, cb) {
|
|
98
|
-
const { events } = this.ensureQueue(queueName);
|
|
99
|
-
const handler = (payload) => cb(payload);
|
|
100
|
-
events.on(event, handler);
|
|
101
|
-
return () => {
|
|
102
|
-
events.off(event, handler);
|
|
103
|
-
};
|
|
104
|
-
}
|
|
105
|
-
async isPaused(queueName) {
|
|
106
|
-
const { queue } = this.ensureQueue(queueName);
|
|
107
|
-
return await queue.isPaused();
|
|
108
|
-
}
|
|
109
|
-
async getJobCounts(queueName) {
|
|
110
|
-
const { queue } = this.ensureQueue(queueName);
|
|
111
|
-
const counts = await queue.getJobCounts("waiting", "active", "completed", "failed", "delayed", "paused");
|
|
112
|
-
return {
|
|
113
|
-
active: counts.active || 0,
|
|
114
|
-
completed: counts.completed || 0,
|
|
115
|
-
failed: counts.failed || 0,
|
|
116
|
-
delayed: counts.delayed || 0,
|
|
117
|
-
waiting: counts.waiting || 0,
|
|
118
|
-
paused: counts.paused || 0
|
|
119
|
-
};
|
|
120
|
-
}
|
|
121
|
-
async pause(queueName) {
|
|
122
|
-
const { queue } = this.ensureQueue(queueName);
|
|
123
|
-
await queue.pause();
|
|
124
|
-
}
|
|
125
|
-
async resume(queueName) {
|
|
126
|
-
const { queue } = this.ensureQueue(queueName);
|
|
127
|
-
await queue.resume();
|
|
128
|
-
}
|
|
129
|
-
async close() {
|
|
130
|
-
const closePromises = [];
|
|
131
|
-
for (const [queueName, { queue, events }] of this.queues.entries()) {
|
|
132
|
-
closePromises.push(
|
|
133
|
-
queue.close().catch((err) => {
|
|
134
|
-
if (err.code !== "EPIPE" && !err.message?.includes("Connection is closed")) {
|
|
135
|
-
this.logger.warn("Error closing queue", { queueName, error: err });
|
|
136
|
-
}
|
|
137
|
-
})
|
|
138
|
-
);
|
|
139
|
-
closePromises.push(
|
|
140
|
-
events.close().catch((err) => {
|
|
141
|
-
if (err.code !== "EPIPE" && !err.message?.includes("Connection is closed")) {
|
|
142
|
-
this.logger.warn("Error closing events for queue", { queueName, error: err });
|
|
143
|
-
}
|
|
144
|
-
})
|
|
145
|
-
);
|
|
146
|
-
}
|
|
147
|
-
await Promise.allSettled(closePromises);
|
|
148
|
-
this.queues.clear();
|
|
149
|
-
}
|
|
150
|
-
async toJob(j) {
|
|
151
|
-
const state = await j.getState();
|
|
152
|
-
return {
|
|
153
|
-
id: j.id,
|
|
154
|
-
name: j.name,
|
|
155
|
-
data: j.data,
|
|
156
|
-
returnvalue: j.returnvalue,
|
|
157
|
-
failedReason: j.failedReason,
|
|
158
|
-
state,
|
|
159
|
-
timestamp: j.timestamp,
|
|
160
|
-
processedOn: j.processedOn,
|
|
161
|
-
finishedOn: j.finishedOn
|
|
162
|
-
};
|
|
163
|
-
}
|
|
164
|
-
}
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
export type JobCounts = {
|
|
2
|
-
active: number;
|
|
3
|
-
completed: number;
|
|
4
|
-
failed: number;
|
|
5
|
-
delayed: number;
|
|
6
|
-
waiting: number;
|
|
7
|
-
paused: number;
|
|
8
|
-
};
|
|
9
|
-
export type QueueEvent = 'added' | 'waiting' | 'active' | 'progress' | 'completed' | 'failed' | 'paused' | 'resumed';
|
|
10
|
-
export interface JobInput {
|
|
11
|
-
name: string;
|
|
12
|
-
data: any;
|
|
13
|
-
opts?: Record<string, any>;
|
|
14
|
-
}
|
|
15
|
-
export interface Job {
|
|
16
|
-
id: string;
|
|
17
|
-
name: string;
|
|
18
|
-
data: any;
|
|
19
|
-
state?: 'waiting' | 'active' | 'completed' | 'failed' | 'delayed' | 'paused';
|
|
20
|
-
returnvalue?: any;
|
|
21
|
-
failedReason?: string;
|
|
22
|
-
timestamp?: number;
|
|
23
|
-
processedOn?: number;
|
|
24
|
-
finishedOn?: number;
|
|
25
|
-
}
|
|
26
|
-
export interface JobsQuery {
|
|
27
|
-
state?: Array<Job['state']>;
|
|
28
|
-
limit?: number;
|
|
29
|
-
cursor?: string;
|
|
30
|
-
}
|
|
31
|
-
export interface ScheduleOptions {
|
|
32
|
-
delay?: number;
|
|
33
|
-
cron?: string;
|
|
34
|
-
}
|
|
35
|
-
export interface QueueProvider {
|
|
36
|
-
init(): Promise<void>;
|
|
37
|
-
enqueue(queue: string, job: JobInput): Promise<string>;
|
|
38
|
-
schedule(queue: string, job: JobInput, opts?: ScheduleOptions): Promise<string>;
|
|
39
|
-
getJob(queue: string, id: string): Promise<Job | null>;
|
|
40
|
-
getJobs(queue: string, q?: JobsQuery): Promise<Job[]>;
|
|
41
|
-
on(queue: string, event: QueueEvent, cb: (p: any) => void): () => void;
|
|
42
|
-
getJobCounts?(queue: string): Promise<Record<string, number>>;
|
|
43
|
-
isPaused?(queue: string): Promise<boolean>;
|
|
44
|
-
pause(queue: string): Promise<void>;
|
|
45
|
-
resume(queue: string): Promise<void>;
|
|
46
|
-
close(): Promise<void>;
|
|
47
|
-
}
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
import { useStorage, useRuntimeConfig } from "#imports";
|
|
2
|
-
function nsKey(ns, key) {
|
|
3
|
-
if (!key) return ns;
|
|
4
|
-
return key.startsWith(ns + ":") ? key : `${ns}:${key}`;
|
|
5
|
-
}
|
|
6
|
-
export function createRedisStateProvider(namespace) {
|
|
7
|
-
const storage = useStorage("redis");
|
|
8
|
-
const ns = namespace || useRuntimeConfig()?.queue?.state?.namespace || "nq";
|
|
9
|
-
return {
|
|
10
|
-
async get(key) {
|
|
11
|
-
return storage.getItem(nsKey(ns, key));
|
|
12
|
-
},
|
|
13
|
-
async set(key, value, opts) {
|
|
14
|
-
await storage.setItem(nsKey(ns, key), value, { ttl: opts?.ttl });
|
|
15
|
-
},
|
|
16
|
-
async delete(key) {
|
|
17
|
-
await storage.removeItem(nsKey(ns, key));
|
|
18
|
-
},
|
|
19
|
-
async list(prefix, opts) {
|
|
20
|
-
const base = nsKey(ns, prefix);
|
|
21
|
-
const keys = await storage.getKeys(base);
|
|
22
|
-
const filtered = keys.filter((k) => k.startsWith(base)).slice(0, opts?.limit || keys.length);
|
|
23
|
-
return { keys: filtered };
|
|
24
|
-
},
|
|
25
|
-
async patch(key, updater, opts) {
|
|
26
|
-
const retries = Math.max(0, opts?.retries ?? 3);
|
|
27
|
-
const k = nsKey(ns, key);
|
|
28
|
-
let lastErr;
|
|
29
|
-
for (let i = 0; i <= retries; i++) {
|
|
30
|
-
try {
|
|
31
|
-
const prev = await storage.getItem(k);
|
|
32
|
-
const next = updater(prev);
|
|
33
|
-
await storage.setItem(k, next);
|
|
34
|
-
return next;
|
|
35
|
-
} catch (err) {
|
|
36
|
-
lastErr = err;
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
throw lastErr || new Error("patch failed");
|
|
40
|
-
}
|
|
41
|
-
};
|
|
42
|
-
}
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { useRuntimeConfig } from "#imports";
|
|
2
|
-
import { createRedisStateProvider } from "./adapters/redis.js";
|
|
3
|
-
let currentStateProvider = null;
|
|
4
|
-
export function getStateProvider() {
|
|
5
|
-
if (currentStateProvider) return currentStateProvider;
|
|
6
|
-
const rc = useRuntimeConfig();
|
|
7
|
-
const adapter = rc?.queue?.state?.adapter || "redis";
|
|
8
|
-
const ns = rc?.queue?.state?.namespace || "nq";
|
|
9
|
-
if (adapter === "redis") {
|
|
10
|
-
currentStateProvider = createRedisStateProvider(ns);
|
|
11
|
-
return currentStateProvider;
|
|
12
|
-
}
|
|
13
|
-
throw new Error(`[nuxt-queue] Unsupported StateProvider: ${adapter}`);
|
|
14
|
-
}
|
|
15
|
-
export function setStateProvider(p) {
|
|
16
|
-
currentStateProvider = p;
|
|
17
|
-
}
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
export interface StateProvider {
|
|
2
|
-
get<T = any>(key: string): Promise<T | null>;
|
|
3
|
-
set<T = any>(key: string, value: T, opts?: {
|
|
4
|
-
ttl?: number;
|
|
5
|
-
}): Promise<void>;
|
|
6
|
-
delete(key: string): Promise<void>;
|
|
7
|
-
list(prefix: string, opts?: {
|
|
8
|
-
limit?: number;
|
|
9
|
-
}): Promise<{
|
|
10
|
-
keys: string[];
|
|
11
|
-
}>;
|
|
12
|
-
patch<T = any>(key: string, updater: (prev: T | null) => T, opts?: {
|
|
13
|
-
retries?: number;
|
|
14
|
-
}): Promise<T>;
|
|
15
|
-
}
|
|
16
|
-
export interface StorageLike {
|
|
17
|
-
getItem<T = any>(key: string): Promise<T | null>;
|
|
18
|
-
setItem<T = any>(key: string, value: T, opts?: {
|
|
19
|
-
ttl?: number;
|
|
20
|
-
}): Promise<void>;
|
|
21
|
-
removeItem(key: string): Promise<void>;
|
|
22
|
-
getKeys(base?: string): Promise<string[]>;
|
|
23
|
-
}
|
|
@@ -1,154 +0,0 @@
|
|
|
1
|
-
export type FlowRole = 'entry' | 'step';
|
|
2
|
-
export interface FlowConfig {
|
|
3
|
-
/**
|
|
4
|
-
* One or more flow names this step belongs to.
|
|
5
|
-
* A single worker step can participate in multiple flows.
|
|
6
|
-
*/
|
|
7
|
-
name: string | string[];
|
|
8
|
-
/**
|
|
9
|
-
* Role of this step in the flow.
|
|
10
|
-
*/
|
|
11
|
-
role: FlowRole;
|
|
12
|
-
/**
|
|
13
|
-
* Logical step name (used as job name and event kind on start).
|
|
14
|
-
*/
|
|
15
|
-
step: string;
|
|
16
|
-
/**
|
|
17
|
-
* Event kinds this step emits (e.g., `${step}.completed`).
|
|
18
|
-
*/
|
|
19
|
-
emits?: string[];
|
|
20
|
-
/**
|
|
21
|
-
* Event kinds this step subscribes to; can be a single string or an array.
|
|
22
|
-
* The compiler normalizes this to `string[]` under `subscribes`.
|
|
23
|
-
*/
|
|
24
|
-
subscribes?: string | string[];
|
|
25
|
-
}
|
|
26
|
-
export interface QueueJobDefaults {
|
|
27
|
-
/**
|
|
28
|
-
* Number of retry attempts for failed jobs.
|
|
29
|
-
* BullMQ: attempts, PGBoss: retryLimit
|
|
30
|
-
*/
|
|
31
|
-
attempts?: number;
|
|
32
|
-
/**
|
|
33
|
-
* Backoff strategy for retries.
|
|
34
|
-
* BullMQ: backoff, PGBoss: retryBackoff + exponentialBackoff
|
|
35
|
-
*/
|
|
36
|
-
backoff?: number | {
|
|
37
|
-
type: 'fixed' | 'exponential';
|
|
38
|
-
delay: number;
|
|
39
|
-
};
|
|
40
|
-
/**
|
|
41
|
-
* Delay in milliseconds before the job is processed.
|
|
42
|
-
* BullMQ: delay, PGBoss: startAfter
|
|
43
|
-
*/
|
|
44
|
-
delay?: number;
|
|
45
|
-
/**
|
|
46
|
-
* Job priority (higher number = higher priority).
|
|
47
|
-
* BullMQ: priority, PGBoss: priority
|
|
48
|
-
*/
|
|
49
|
-
priority?: number;
|
|
50
|
-
/**
|
|
51
|
-
* Job timeout in milliseconds.
|
|
52
|
-
* BullMQ: timeout, PGBoss: expireInSeconds (converted)
|
|
53
|
-
*/
|
|
54
|
-
timeout?: number;
|
|
55
|
-
/**
|
|
56
|
-
* Process jobs in LIFO (Last In First Out) order.
|
|
57
|
-
* BullMQ: lifo, PGBoss: not supported
|
|
58
|
-
*/
|
|
59
|
-
lifo?: boolean;
|
|
60
|
-
/**
|
|
61
|
-
* Remove job from queue when completed.
|
|
62
|
-
* BullMQ: removeOnComplete, PGBoss: deleteAfterSeconds
|
|
63
|
-
*/
|
|
64
|
-
removeOnComplete?: boolean | number;
|
|
65
|
-
/**
|
|
66
|
-
* Remove job from queue when failed.
|
|
67
|
-
* BullMQ: removeOnFail, PGBoss: deleteAfterSeconds
|
|
68
|
-
*/
|
|
69
|
-
removeOnFail?: boolean | number;
|
|
70
|
-
/**
|
|
71
|
-
* Repeatable job configuration.
|
|
72
|
-
* BullMQ: repeat, PGBoss: schedule pattern
|
|
73
|
-
*/
|
|
74
|
-
repeat?: {
|
|
75
|
-
cron?: string;
|
|
76
|
-
every?: number;
|
|
77
|
-
limit?: number;
|
|
78
|
-
tz?: string;
|
|
79
|
-
};
|
|
80
|
-
}
|
|
81
|
-
export interface QueueConfig {
|
|
82
|
-
/**
|
|
83
|
-
* Queue name. If not provided, the filename will be used.
|
|
84
|
-
*/
|
|
85
|
-
name?: string;
|
|
86
|
-
/**
|
|
87
|
-
* Default options for jobs enqueued to this queue.
|
|
88
|
-
*/
|
|
89
|
-
defaultJobOptions?: QueueJobDefaults;
|
|
90
|
-
/**
|
|
91
|
-
* Prefix for queue keys in Redis/storage.
|
|
92
|
-
* BullMQ: prefix, PGBoss: schema
|
|
93
|
-
*/
|
|
94
|
-
prefix?: string;
|
|
95
|
-
/**
|
|
96
|
-
* Rate limiting configuration.
|
|
97
|
-
* BullMQ: limiter, PGBoss: teamSize + teamConcurrency (partial)
|
|
98
|
-
*/
|
|
99
|
-
limiter?: {
|
|
100
|
-
/**
|
|
101
|
-
* Maximum number of jobs to process in the duration window.
|
|
102
|
-
*/
|
|
103
|
-
max?: number;
|
|
104
|
-
/**
|
|
105
|
-
* Duration of the rate limit window in milliseconds.
|
|
106
|
-
*/
|
|
107
|
-
duration?: number;
|
|
108
|
-
/**
|
|
109
|
-
* Group key for rate limiting (optional).
|
|
110
|
-
* BullMQ only: allows per-group rate limiting
|
|
111
|
-
*/
|
|
112
|
-
groupKey?: string;
|
|
113
|
-
};
|
|
114
|
-
}
|
|
115
|
-
export interface WorkerConfig {
|
|
116
|
-
/**
|
|
117
|
-
* Number of jobs to process concurrently.
|
|
118
|
-
* BullMQ: concurrency, PGBoss: teamSize
|
|
119
|
-
*/
|
|
120
|
-
concurrency?: number;
|
|
121
|
-
/**
|
|
122
|
-
* Lock duration in milliseconds.
|
|
123
|
-
* BullMQ: lockDuration, PGBoss: newJobCheckInterval (similar concept)
|
|
124
|
-
*/
|
|
125
|
-
lockDurationMs?: number;
|
|
126
|
-
/**
|
|
127
|
-
* Maximum number of times a job can be stalled before being failed.
|
|
128
|
-
* BullMQ: maxStalledCount, PGBoss: not directly supported
|
|
129
|
-
*/
|
|
130
|
-
maxStalledCount?: number;
|
|
131
|
-
/**
|
|
132
|
-
* Delay in milliseconds before processing jobs after queue is drained.
|
|
133
|
-
* BullMQ: drainDelay, PGBoss: not directly supported
|
|
134
|
-
*/
|
|
135
|
-
drainDelayMs?: number;
|
|
136
|
-
/**
|
|
137
|
-
* Automatically run worker on startup.
|
|
138
|
-
* BullMQ: autorun, PGBoss: workers start automatically
|
|
139
|
-
*/
|
|
140
|
-
autorun?: boolean;
|
|
141
|
-
/**
|
|
142
|
-
* Polling interval in milliseconds for checking new jobs.
|
|
143
|
-
* PGBoss: newJobCheckInterval, BullMQ: uses blocking wait
|
|
144
|
-
*/
|
|
145
|
-
pollingIntervalMs?: number;
|
|
146
|
-
}
|
|
147
|
-
export interface QueueWorkerConfig {
|
|
148
|
-
queue?: QueueConfig;
|
|
149
|
-
flow?: FlowConfig;
|
|
150
|
-
worker?: WorkerConfig;
|
|
151
|
-
}
|
|
152
|
-
export type DefineQueueConfig = <T extends QueueWorkerConfig>(cfg: T) => T;
|
|
153
|
-
export declare const defineQueueConfig: DefineQueueConfig;
|
|
154
|
-
export default defineQueueConfig;
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { useFlowEngine, useQueue } from '#imports';
|
|
2
|
-
import type { RunContext, NodeHandler } from '../worker/runner/node.js';
|
|
3
|
-
export type ExtendedRunContext = RunContext & {
|
|
4
|
-
provider: ReturnType<typeof useQueue>;
|
|
5
|
-
flow: ReturnType<typeof useFlowEngine>;
|
|
6
|
-
registry: any;
|
|
7
|
-
};
|
|
8
|
-
export type DefineQueueWorker = (handler: (input: any, ctx: ExtendedRunContext) => Promise<any>) => NodeHandler;
|
|
9
|
-
export declare const defineQueueWorker: DefineQueueWorker;
|
|
10
|
-
export default defineQueueWorker;
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { $useQueueRegistry, useFlowEngine, useQueue } from "#imports";
|
|
2
|
-
export const defineQueueWorker = (handler) => {
|
|
3
|
-
const wrapped = async (input, ctx) => {
|
|
4
|
-
const provider = useQueue();
|
|
5
|
-
const flow = ctx.flow || useFlowEngine();
|
|
6
|
-
const registry = $useQueueRegistry();
|
|
7
|
-
const extended = {
|
|
8
|
-
...ctx,
|
|
9
|
-
provider,
|
|
10
|
-
flow,
|
|
11
|
-
registry
|
|
12
|
-
};
|
|
13
|
-
return handler(input, extended);
|
|
14
|
-
};
|
|
15
|
-
return wrapped;
|
|
16
|
-
};
|
|
17
|
-
export default defineQueueWorker;
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import type { EventReadOptions } from '../events/types.js';
|
|
2
|
-
import type { EventRecord } from '../types.js';
|
|
3
|
-
export declare function useEventStore(): {
|
|
4
|
-
names: () => import("../events/streamNames.js").StreamNames;
|
|
5
|
-
read: (stream: string, opts?: EventReadOptions) => Promise<EventRecord[]>;
|
|
6
|
-
indexAdd: (key: string, id: string, score: number, metadata?: Record<string, any>) => Promise<void>;
|
|
7
|
-
indexGet: (key: string, id: string) => Promise<import("../events/types.js").IndexEntry | null>;
|
|
8
|
-
indexUpdate: (key: string, id: string, metadata: Record<string, any>) => Promise<boolean>;
|
|
9
|
-
indexUpdateWithRetry: (key: string, id: string, metadata: Record<string, any>, maxRetries?: number) => Promise<void>;
|
|
10
|
-
indexIncrement: (key: string, id: string, field: string, increment?: number) => Promise<number>;
|
|
11
|
-
indexRead: (key: string, opts?: {
|
|
12
|
-
offset?: number;
|
|
13
|
-
limit?: number;
|
|
14
|
-
}) => Promise<import("../events/types.js").IndexEntry[]>;
|
|
15
|
-
deleteStream: (subject: string) => Promise<void>;
|
|
16
|
-
deleteByPattern: (pattern: string) => Promise<number>;
|
|
17
|
-
deleteIndex: (key: string) => Promise<void>;
|
|
18
|
-
subscribe: (stream: string, handler: (e: EventRecord) => void) => () => void;
|
|
19
|
-
adapter: import("../events/types.js").EventStoreAdapter;
|
|
20
|
-
};
|
|
@@ -1,119 +0,0 @@
|
|
|
1
|
-
import { getEventStoreFactory } from "../events/eventStoreFactory.js";
|
|
2
|
-
import { useNventLogger } from "#imports";
|
|
3
|
-
export function useEventStore() {
|
|
4
|
-
const logger = useNventLogger("event-store");
|
|
5
|
-
const factory = getEventStoreFactory();
|
|
6
|
-
async function read(stream, opts) {
|
|
7
|
-
return await factory.adapter.read(stream, opts);
|
|
8
|
-
}
|
|
9
|
-
async function indexAdd(key, id, score, metadata) {
|
|
10
|
-
if (!factory.adapter.indexAdd) {
|
|
11
|
-
throw new Error("Current adapter does not support indexAdd");
|
|
12
|
-
}
|
|
13
|
-
return await factory.adapter.indexAdd(key, id, score, metadata);
|
|
14
|
-
}
|
|
15
|
-
async function indexGet(key, id) {
|
|
16
|
-
if (!factory.adapter.indexGet) {
|
|
17
|
-
throw new Error("Current adapter does not support indexGet");
|
|
18
|
-
}
|
|
19
|
-
return await factory.adapter.indexGet(key, id);
|
|
20
|
-
}
|
|
21
|
-
async function indexUpdate(key, id, metadata) {
|
|
22
|
-
if (!factory.adapter.indexUpdate) {
|
|
23
|
-
throw new Error("Current adapter does not support indexUpdate");
|
|
24
|
-
}
|
|
25
|
-
return await factory.adapter.indexUpdate(key, id, metadata);
|
|
26
|
-
}
|
|
27
|
-
async function indexUpdateWithRetry(key, id, metadata, maxRetries) {
|
|
28
|
-
if (!factory.adapter.indexUpdateWithRetry) {
|
|
29
|
-
throw new Error("Current adapter does not support indexUpdateWithRetry");
|
|
30
|
-
}
|
|
31
|
-
return await factory.adapter.indexUpdateWithRetry(key, id, metadata, maxRetries);
|
|
32
|
-
}
|
|
33
|
-
async function indexIncrement(key, id, field, increment) {
|
|
34
|
-
if (!factory.adapter.indexIncrement) {
|
|
35
|
-
throw new Error("Current adapter does not support indexIncrement");
|
|
36
|
-
}
|
|
37
|
-
return await factory.adapter.indexIncrement(key, id, field, increment);
|
|
38
|
-
}
|
|
39
|
-
async function indexRead(key, opts) {
|
|
40
|
-
if (!factory.adapter.indexRead) {
|
|
41
|
-
throw new Error("Current adapter does not support indexRead");
|
|
42
|
-
}
|
|
43
|
-
return await factory.adapter.indexRead(key, opts);
|
|
44
|
-
}
|
|
45
|
-
async function deleteStream(subject) {
|
|
46
|
-
if (!factory.adapter.deleteStream) {
|
|
47
|
-
throw new Error("Current adapter does not support deleteStream");
|
|
48
|
-
}
|
|
49
|
-
return await factory.adapter.deleteStream(subject);
|
|
50
|
-
}
|
|
51
|
-
async function deleteByPattern(pattern) {
|
|
52
|
-
if (!factory.adapter.deleteByPattern) {
|
|
53
|
-
throw new Error("Current adapter does not support deleteByPattern");
|
|
54
|
-
}
|
|
55
|
-
return await factory.adapter.deleteByPattern(pattern);
|
|
56
|
-
}
|
|
57
|
-
async function deleteIndex(key) {
|
|
58
|
-
if (!factory.adapter.deleteIndex) {
|
|
59
|
-
throw new Error("Current adapter does not support deleteIndex");
|
|
60
|
-
}
|
|
61
|
-
return await factory.adapter.deleteIndex(key);
|
|
62
|
-
}
|
|
63
|
-
function names() {
|
|
64
|
-
return factory.names;
|
|
65
|
-
}
|
|
66
|
-
function subscribe(stream, handler) {
|
|
67
|
-
logger.debug("Subscribing to stream", { stream });
|
|
68
|
-
let sub = null;
|
|
69
|
-
let active = true;
|
|
70
|
-
(async () => {
|
|
71
|
-
try {
|
|
72
|
-
sub = await factory.adapter.subscribe(stream, (e) => {
|
|
73
|
-
logger.debug("Event received", { stream, id: e?.id, type: e?.type });
|
|
74
|
-
handler(e);
|
|
75
|
-
});
|
|
76
|
-
logger.debug("Subscription active", { stream });
|
|
77
|
-
} catch (err) {
|
|
78
|
-
logger.error("Subscription error", { stream, error: err });
|
|
79
|
-
}
|
|
80
|
-
if (!active && sub) {
|
|
81
|
-
try {
|
|
82
|
-
sub.unsubscribe();
|
|
83
|
-
} catch {
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
})();
|
|
87
|
-
return () => {
|
|
88
|
-
active = false;
|
|
89
|
-
if (sub) {
|
|
90
|
-
try {
|
|
91
|
-
sub.unsubscribe();
|
|
92
|
-
} catch {
|
|
93
|
-
}
|
|
94
|
-
sub = null;
|
|
95
|
-
}
|
|
96
|
-
};
|
|
97
|
-
}
|
|
98
|
-
return {
|
|
99
|
-
// names
|
|
100
|
-
names,
|
|
101
|
-
// read from canonical streams
|
|
102
|
-
read,
|
|
103
|
-
// sorted set index operations
|
|
104
|
-
indexAdd,
|
|
105
|
-
indexGet,
|
|
106
|
-
indexUpdate,
|
|
107
|
-
indexUpdateWithRetry,
|
|
108
|
-
indexIncrement,
|
|
109
|
-
indexRead,
|
|
110
|
-
// deletion operations
|
|
111
|
-
deleteStream,
|
|
112
|
-
deleteByPattern,
|
|
113
|
-
deleteIndex,
|
|
114
|
-
// subscribe to canonical stream events via the adapter (Store Bus)
|
|
115
|
-
subscribe,
|
|
116
|
-
// expose adapter if advanced usage is needed
|
|
117
|
-
adapter: factory.adapter
|
|
118
|
-
};
|
|
119
|
-
}
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
export declare const useFlowEngine: () => {
|
|
2
|
-
startFlow: (flowName: string, payload?: any) => Promise<{
|
|
3
|
-
id: any;
|
|
4
|
-
queue: any;
|
|
5
|
-
step: any;
|
|
6
|
-
flowId: `${string}-${string}-${string}-${string}-${string}`;
|
|
7
|
-
}>;
|
|
8
|
-
emit: (trigger: string, payload?: any) => Promise<never[]>;
|
|
9
|
-
};
|