nvent 0.4.4 → 0.4.5
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 +3 -184
- package/dist/module.json +3 -3
- package/dist/module.mjs +133 -197
- package/dist/runtime/adapters/builtin/file-queue.d.ts +53 -0
- package/dist/runtime/adapters/builtin/file-queue.js +435 -0
- package/dist/runtime/adapters/builtin/file-store.d.ts +46 -0
- package/dist/runtime/adapters/builtin/file-store.js +225 -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 +239 -0
- package/dist/runtime/adapters/builtin/memory-store.d.ts +57 -0
- package/dist/runtime/adapters/builtin/memory-store.js +263 -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 +100 -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 +233 -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 +167 -0
- package/dist/runtime/config/types.d.ts +367 -0
- package/dist/runtime/config/types.js +0 -0
- package/dist/runtime/events/types.d.ts +116 -0
- package/dist/runtime/events/types.js +0 -0
- package/dist/runtime/events/utils/stallDetector.d.ts +99 -0
- package/dist/runtime/events/utils/stallDetector.js +237 -0
- package/dist/runtime/{server-utils/events → events}/wiring/flowWiring.d.ts +3 -8
- package/dist/runtime/{server-utils/events → events}/wiring/flowWiring.js +119 -36
- package/dist/runtime/events/wiring/registry.d.ts +19 -0
- package/dist/runtime/events/wiring/registry.js +33 -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 +32 -0
- package/dist/runtime/events/wiring/streamWiring.js +79 -0
- package/dist/runtime/server/api/_flows/[name]/clear-history.delete.js +16 -5
- package/dist/runtime/server/api/_flows/[name]/runs/[runId]/cancel.post.js +21 -0
- package/dist/runtime/server/api/_flows/[name]/runs.get.d.ts +12 -2
- package/dist/runtime/server/api/_flows/[name]/runs.get.js +15 -4
- package/dist/runtime/server/api/_flows/[name]/schedule.post.js +11 -2
- package/dist/runtime/server/api/_flows/[name]/schedules/[id].delete.js +21 -16
- package/dist/runtime/server/api/_flows/[name]/schedules.get.js +21 -19
- package/dist/runtime/server/api/_flows/ws.js +43 -22
- package/dist/runtime/server/api/_queues/[name]/job/[id].get.js +8 -3
- package/dist/runtime/server/api/_queues/[name]/job/index.get.js +12 -3
- package/dist/runtime/server/api/_queues/index.get.js +66 -23
- package/dist/runtime/server/api/_queues/ws.js +14 -4
- package/dist/runtime/server/plugins/00.adapters.d.ts +14 -0
- package/dist/runtime/server/plugins/00.adapters.js +69 -0
- package/dist/runtime/server/plugins/02.workers.js +45 -0
- package/dist/runtime/tsconfig.json +8 -0
- package/dist/runtime/utils/adapters.d.ts +66 -0
- package/dist/runtime/utils/adapters.js +51 -0
- package/dist/runtime/utils/defineFunction.d.ts +10 -0
- package/dist/runtime/{server-utils/utils/defineQueueWorker.js → utils/defineFunction.js} +4 -4
- package/dist/runtime/{server-utils/utils/defineQueueConfig.d.ts → utils/defineFunctionConfig.d.ts} +3 -3
- package/dist/runtime/utils/defineFunctionConfig.js +2 -0
- package/dist/runtime/utils/registerAdapter.d.ts +59 -0
- package/dist/runtime/utils/registerAdapter.js +13 -0
- package/dist/runtime/utils/useFlowEngine.d.ts +19 -0
- package/dist/runtime/utils/useFlowEngine.js +108 -0
- package/dist/runtime/{server-utils/utils → utils}/useNventLogger.js +2 -2
- package/dist/runtime/utils/useStreamTopics.d.ts +72 -0
- package/dist/runtime/utils/useStreamTopics.js +47 -0
- package/dist/runtime/{server-utils/worker/runner/node.d.ts → worker/node/runner.d.ts} +18 -2
- package/dist/runtime/{server-utils/worker/runner/node.js → worker/node/runner.js} +44 -17
- package/dist/types.d.mts +2 -2
- package/package.json +14 -44
- 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/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.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.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/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.js +0 -2
- package/dist/runtime/server-utils/utils/defineQueueWorker.d.ts +0 -10
- 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/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.d.ts +0 -0
- /package/dist/runtime/{server-utils/events → events}/eventBus.js +0 -0
- /package/dist/runtime/server/{plugins/queue-management.d.ts → api/_flows/[name]/runs/[runId]/cancel.post.d.ts} +0 -0
- /package/dist/runtime/server/plugins/{00.ws-lifecycle.d.ts → 01.ws-lifecycle.d.ts} +0 -0
- /package/dist/runtime/server/plugins/{00.ws-lifecycle.js → 01.ws-lifecycle.js} +0 -0
- /package/dist/runtime/server/plugins/{worker-management.d.ts → 02.workers.d.ts} +0 -0
- /package/dist/runtime/{server-utils/utils → utils}/useEventManager.d.ts +0 -0
- /package/dist/runtime/{server-utils/utils → utils}/useEventManager.js +0 -0
- /package/dist/runtime/{server-utils/utils → utils}/useNventLogger.d.ts +0 -0
- /package/dist/runtime/{server-utils/utils → utils}/wsPeerManager.d.ts +0 -0
- /package/dist/runtime/{server-utils/utils → utils}/wsPeerManager.js +0 -0
- /package/dist/runtime/{python → worker/python}/get_config.py +0 -0
|
@@ -1,348 +0,0 @@
|
|
|
1
|
-
import { useRuntimeConfig, useNventLogger } from "#imports";
|
|
2
|
-
import IORedis from "ioredis";
|
|
3
|
-
import { RedisPubSubGateway } from "./redisPubSubGateway.js";
|
|
4
|
-
function nowIso() {
|
|
5
|
-
return (/* @__PURE__ */ new Date()).toISOString();
|
|
6
|
-
}
|
|
7
|
-
export function createRedisAdapter() {
|
|
8
|
-
const rc = useRuntimeConfig();
|
|
9
|
-
const logger = useNventLogger("redis-adapter");
|
|
10
|
-
const conn = rc?.queue?.eventStore?.redis || {};
|
|
11
|
-
const rsOpts = rc?.queue?.eventStore?.options?.redisStreams || {};
|
|
12
|
-
const redis = new IORedis({
|
|
13
|
-
host: conn.host,
|
|
14
|
-
port: conn.port,
|
|
15
|
-
username: conn.username,
|
|
16
|
-
password: conn.password,
|
|
17
|
-
lazyConnect: true,
|
|
18
|
-
enableReadyCheck: false
|
|
19
|
-
// Disable ready check to avoid INFO command conflicts
|
|
20
|
-
});
|
|
21
|
-
const subscriber = new IORedis({
|
|
22
|
-
host: conn.host,
|
|
23
|
-
port: conn.port,
|
|
24
|
-
username: conn.username,
|
|
25
|
-
password: conn.password,
|
|
26
|
-
lazyConnect: true,
|
|
27
|
-
enableReadyCheck: false
|
|
28
|
-
});
|
|
29
|
-
const gateway = new RedisPubSubGateway(subscriber);
|
|
30
|
-
function buildFields(e) {
|
|
31
|
-
const dataStr = e.data !== void 0 ? JSON.stringify(e.data) : "";
|
|
32
|
-
const fields = [
|
|
33
|
-
"type",
|
|
34
|
-
String(e.type || ""),
|
|
35
|
-
"runId",
|
|
36
|
-
String(e.runId || ""),
|
|
37
|
-
"flowName",
|
|
38
|
-
String(e.flowName || ""),
|
|
39
|
-
"data",
|
|
40
|
-
dataStr,
|
|
41
|
-
"ts",
|
|
42
|
-
e.ts || nowIso()
|
|
43
|
-
];
|
|
44
|
-
if (e.stepName) {
|
|
45
|
-
fields.push("stepName", String(e.stepName));
|
|
46
|
-
}
|
|
47
|
-
if (e.stepId) {
|
|
48
|
-
fields.push("stepId", String(e.stepId));
|
|
49
|
-
}
|
|
50
|
-
if (e.attempt !== void 0) {
|
|
51
|
-
fields.push("attempt", String(e.attempt));
|
|
52
|
-
}
|
|
53
|
-
return fields;
|
|
54
|
-
}
|
|
55
|
-
function parseFieldsToRecord(id, arr) {
|
|
56
|
-
const obj = {};
|
|
57
|
-
for (let i = 0; i < arr.length; i += 2) {
|
|
58
|
-
const k = String(arr[i]);
|
|
59
|
-
const v = String(arr[i + 1] ?? "");
|
|
60
|
-
obj[k] = v;
|
|
61
|
-
}
|
|
62
|
-
let data;
|
|
63
|
-
try {
|
|
64
|
-
data = obj.data ? JSON.parse(obj.data) : void 0;
|
|
65
|
-
} catch {
|
|
66
|
-
data = void 0;
|
|
67
|
-
}
|
|
68
|
-
const rec = {
|
|
69
|
-
id,
|
|
70
|
-
ts: obj.ts || nowIso(),
|
|
71
|
-
type: obj.type || "event",
|
|
72
|
-
runId: obj.runId || "",
|
|
73
|
-
flowName: obj.flowName || "",
|
|
74
|
-
data
|
|
75
|
-
};
|
|
76
|
-
if (obj.stepName) rec.stepName = obj.stepName;
|
|
77
|
-
if (obj.stepId) rec.stepId = obj.stepId;
|
|
78
|
-
if (obj.attempt) rec.attempt = Number.parseInt(obj.attempt, 10);
|
|
79
|
-
return rec;
|
|
80
|
-
}
|
|
81
|
-
return {
|
|
82
|
-
async append(subject, e) {
|
|
83
|
-
if (!redis.status || redis.status === "end") await redis.connect();
|
|
84
|
-
const ts = nowIso();
|
|
85
|
-
const payloadFields = buildFields({ ...e, ts });
|
|
86
|
-
const stream = subject;
|
|
87
|
-
let id;
|
|
88
|
-
if (rsOpts?.trim?.maxLen && rsOpts.trim.maxLen > 0) {
|
|
89
|
-
const approx = rsOpts?.trim?.approx !== false;
|
|
90
|
-
const args = approx ? ["MAXLEN", "~", String(rsOpts.trim.maxLen)] : ["MAXLEN", String(rsOpts.trim.maxLen)];
|
|
91
|
-
id = await redis.xadd(stream, ...args, "*", ...payloadFields);
|
|
92
|
-
} else {
|
|
93
|
-
id = await redis.xadd(stream, "*", ...payloadFields);
|
|
94
|
-
}
|
|
95
|
-
const channel = `nq:events:${subject}`;
|
|
96
|
-
await redis.publish(channel, id);
|
|
97
|
-
if (process.env.NQ_DEBUG_EVENTS === "1") {
|
|
98
|
-
logger.info("[redis-streams] appended and published", { stream, id, channel, type: e.type });
|
|
99
|
-
}
|
|
100
|
-
const rec = { ...e, id, ts, subject };
|
|
101
|
-
return rec;
|
|
102
|
-
},
|
|
103
|
-
async read(subject, opts) {
|
|
104
|
-
if (!redis.status || redis.status === "end") await redis.connect();
|
|
105
|
-
const from = opts?.fromId ? opts.fromId : "0-0";
|
|
106
|
-
const count = opts?.limit || 100;
|
|
107
|
-
const dir = opts?.direction || "forward";
|
|
108
|
-
const stream = subject;
|
|
109
|
-
let resp = [];
|
|
110
|
-
if (dir === "backward") {
|
|
111
|
-
resp = await redis.xrevrange(stream, from === "0-0" ? "+" : `(${from}`, "-", "COUNT", count);
|
|
112
|
-
} else {
|
|
113
|
-
resp = await redis.xrange(stream, from === "0-0" ? "-" : `(${from}`, "+", "COUNT", count);
|
|
114
|
-
}
|
|
115
|
-
const out = [];
|
|
116
|
-
for (const [id, arr] of resp) {
|
|
117
|
-
try {
|
|
118
|
-
const rec = parseFieldsToRecord(id, arr);
|
|
119
|
-
out.push(rec);
|
|
120
|
-
} catch {
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
return out;
|
|
124
|
-
},
|
|
125
|
-
async subscribe(subject, onEvent) {
|
|
126
|
-
const stream = subject;
|
|
127
|
-
const channel = `nq:events:${subject}`;
|
|
128
|
-
if (!redis.status || redis.status === "end") await redis.connect();
|
|
129
|
-
let running = true;
|
|
130
|
-
if (process.env.NQ_DEBUG_EVENTS === "1") {
|
|
131
|
-
logger.info("[redis-streams] subscribing", { stream, channel });
|
|
132
|
-
}
|
|
133
|
-
const messageHandler = async (messageId) => {
|
|
134
|
-
if (!running) return;
|
|
135
|
-
try {
|
|
136
|
-
const entries = await redis.xrange(stream, messageId, messageId, "COUNT", 1);
|
|
137
|
-
if (entries && entries.length > 0) {
|
|
138
|
-
const [id, arr] = entries[0];
|
|
139
|
-
const rec = parseFieldsToRecord(id, arr);
|
|
140
|
-
if (process.env.NQ_DEBUG_EVENTS === "1") {
|
|
141
|
-
logger.info("[redis-streams] received event", { stream, id, type: rec.type });
|
|
142
|
-
}
|
|
143
|
-
onEvent(rec);
|
|
144
|
-
}
|
|
145
|
-
} catch (err) {
|
|
146
|
-
if (process.env.NQ_DEBUG_EVENTS === "1") {
|
|
147
|
-
logger.error("[redis-streams] message handling error:", err);
|
|
148
|
-
}
|
|
149
|
-
}
|
|
150
|
-
};
|
|
151
|
-
const unsubscribe = await gateway.subscribe(channel, messageHandler);
|
|
152
|
-
return {
|
|
153
|
-
unsubscribe() {
|
|
154
|
-
running = false;
|
|
155
|
-
unsubscribe();
|
|
156
|
-
}
|
|
157
|
-
};
|
|
158
|
-
},
|
|
159
|
-
async indexAdd(key, id, score, metadata) {
|
|
160
|
-
if (!redis.status || redis.status === "end") await redis.connect();
|
|
161
|
-
await redis.zadd(key, score, id);
|
|
162
|
-
if (metadata) {
|
|
163
|
-
const metaKey = `${key}:meta:${id}`;
|
|
164
|
-
const toStore = { version: "0" };
|
|
165
|
-
for (const [k, v] of Object.entries(metadata)) {
|
|
166
|
-
toStore[k] = Array.isArray(v) ? JSON.stringify(v) : String(v);
|
|
167
|
-
}
|
|
168
|
-
await redis.hset(metaKey, toStore);
|
|
169
|
-
}
|
|
170
|
-
},
|
|
171
|
-
async indexRead(key, opts) {
|
|
172
|
-
if (!redis.status || redis.status === "end") await redis.connect();
|
|
173
|
-
const offset = opts?.offset || 0;
|
|
174
|
-
const limit = opts?.limit || 50;
|
|
175
|
-
const end = offset + limit - 1;
|
|
176
|
-
const results = await redis.zrevrange(key, offset, end, "WITHSCORES");
|
|
177
|
-
const entries = [];
|
|
178
|
-
for (let i = 0; i < results.length; i += 2) {
|
|
179
|
-
const id = results[i];
|
|
180
|
-
const score = Number.parseInt(results[i + 1]);
|
|
181
|
-
const metaKey = `${key}:meta:${id}`;
|
|
182
|
-
const metadata = await redis.hgetall(metaKey);
|
|
183
|
-
let parsedMetadata = void 0;
|
|
184
|
-
if (Object.keys(metadata).length > 0) {
|
|
185
|
-
parsedMetadata = { ...metadata };
|
|
186
|
-
if (parsedMetadata.emittedEvents) {
|
|
187
|
-
parsedMetadata.emittedEvents = JSON.parse(parsedMetadata.emittedEvents);
|
|
188
|
-
}
|
|
189
|
-
if (parsedMetadata.version !== void 0) {
|
|
190
|
-
parsedMetadata.version = Number.parseInt(parsedMetadata.version, 10);
|
|
191
|
-
}
|
|
192
|
-
if (parsedMetadata.startedAt !== void 0) {
|
|
193
|
-
parsedMetadata.startedAt = Number.parseInt(parsedMetadata.startedAt, 10);
|
|
194
|
-
}
|
|
195
|
-
if (parsedMetadata.completedAt !== void 0) {
|
|
196
|
-
parsedMetadata.completedAt = Number.parseInt(parsedMetadata.completedAt, 10);
|
|
197
|
-
}
|
|
198
|
-
if (parsedMetadata.stepCount !== void 0) {
|
|
199
|
-
parsedMetadata.stepCount = Number.parseInt(parsedMetadata.stepCount, 10);
|
|
200
|
-
}
|
|
201
|
-
if (parsedMetadata.completedSteps !== void 0) {
|
|
202
|
-
parsedMetadata.completedSteps = Number.parseInt(parsedMetadata.completedSteps, 10);
|
|
203
|
-
}
|
|
204
|
-
}
|
|
205
|
-
entries.push({
|
|
206
|
-
id,
|
|
207
|
-
score,
|
|
208
|
-
metadata: parsedMetadata
|
|
209
|
-
});
|
|
210
|
-
}
|
|
211
|
-
return entries;
|
|
212
|
-
},
|
|
213
|
-
async indexGet(key, id) {
|
|
214
|
-
if (!redis.status || redis.status === "end") await redis.connect();
|
|
215
|
-
const score = await redis.zscore(key, id);
|
|
216
|
-
if (!score) return null;
|
|
217
|
-
const metaKey = `${key}:meta:${id}`;
|
|
218
|
-
const metadata = await redis.hgetall(metaKey);
|
|
219
|
-
if (Object.keys(metadata).length === 0) {
|
|
220
|
-
return { id, score: Number.parseFloat(score) };
|
|
221
|
-
}
|
|
222
|
-
const parsed = { ...metadata };
|
|
223
|
-
if (parsed.emittedEvents) {
|
|
224
|
-
parsed.emittedEvents = JSON.parse(parsed.emittedEvents);
|
|
225
|
-
}
|
|
226
|
-
if (parsed.version !== void 0) {
|
|
227
|
-
parsed.version = Number.parseInt(parsed.version, 10);
|
|
228
|
-
}
|
|
229
|
-
if (parsed.startedAt !== void 0) {
|
|
230
|
-
parsed.startedAt = Number.parseInt(parsed.startedAt, 10);
|
|
231
|
-
}
|
|
232
|
-
if (parsed.completedAt !== void 0) {
|
|
233
|
-
parsed.completedAt = Number.parseInt(parsed.completedAt, 10);
|
|
234
|
-
}
|
|
235
|
-
if (parsed.stepCount !== void 0) {
|
|
236
|
-
parsed.stepCount = Number.parseInt(parsed.stepCount, 10);
|
|
237
|
-
}
|
|
238
|
-
if (parsed.completedSteps !== void 0) {
|
|
239
|
-
parsed.completedSteps = Number.parseInt(parsed.completedSteps, 10);
|
|
240
|
-
}
|
|
241
|
-
return {
|
|
242
|
-
id,
|
|
243
|
-
score: Number.parseFloat(score),
|
|
244
|
-
metadata: parsed
|
|
245
|
-
};
|
|
246
|
-
},
|
|
247
|
-
async indexUpdate(key, id, metadata) {
|
|
248
|
-
if (!redis.status || redis.status === "end") await redis.connect();
|
|
249
|
-
const metaKey = `${key}:meta:${id}`;
|
|
250
|
-
const current = await redis.hget(metaKey, "version");
|
|
251
|
-
const currentVersion = current ? Number.parseInt(current, 10) : 0;
|
|
252
|
-
const script = `
|
|
253
|
-
local current = redis.call('HGET', KEYS[1], 'version')
|
|
254
|
-
if current == ARGV[1] then
|
|
255
|
-
for i = 2, #ARGV, 2 do
|
|
256
|
-
redis.call('HSET', KEYS[1], ARGV[i], ARGV[i + 1])
|
|
257
|
-
end
|
|
258
|
-
redis.call('HSET', KEYS[1], 'version', tonumber(ARGV[1]) + 1)
|
|
259
|
-
return 1
|
|
260
|
-
else
|
|
261
|
-
return 0
|
|
262
|
-
end
|
|
263
|
-
`;
|
|
264
|
-
const args = [currentVersion.toString()];
|
|
265
|
-
for (const [k, v] of Object.entries(metadata)) {
|
|
266
|
-
if (v === void 0) continue;
|
|
267
|
-
args.push(k);
|
|
268
|
-
if (Array.isArray(v)) {
|
|
269
|
-
args.push(JSON.stringify(v.filter((item) => item != null)));
|
|
270
|
-
} else {
|
|
271
|
-
args.push(String(v));
|
|
272
|
-
}
|
|
273
|
-
}
|
|
274
|
-
const result = await redis.eval(script, 1, metaKey, ...args);
|
|
275
|
-
return result === 1;
|
|
276
|
-
},
|
|
277
|
-
async indexUpdateWithRetry(key, id, metadata, maxRetries = 3) {
|
|
278
|
-
for (let attempt = 0; attempt < maxRetries; attempt++) {
|
|
279
|
-
const success = await this.indexUpdate(key, id, metadata);
|
|
280
|
-
if (success) return;
|
|
281
|
-
await new Promise((resolve) => setTimeout(resolve, 10 * Math.pow(2, attempt)));
|
|
282
|
-
}
|
|
283
|
-
throw new Error(`Failed to update index after ${maxRetries} retries`);
|
|
284
|
-
},
|
|
285
|
-
async indexIncrement(key, id, field, increment = 1) {
|
|
286
|
-
if (!redis.status || redis.status === "end") await redis.connect();
|
|
287
|
-
const metaKey = `${key}:meta:${id}`;
|
|
288
|
-
const newValue = await redis.hincrby(metaKey, field, increment);
|
|
289
|
-
await redis.hincrby(metaKey, "version", 1);
|
|
290
|
-
return newValue;
|
|
291
|
-
},
|
|
292
|
-
async setMetadataTTL(flowName, runId, ttlSeconds) {
|
|
293
|
-
if (!redis.status || redis.status === "end") await redis.connect();
|
|
294
|
-
const metaKey = `nq:flow:idx:${flowName}:meta:${runId}`;
|
|
295
|
-
await redis.expire(metaKey, ttlSeconds);
|
|
296
|
-
},
|
|
297
|
-
async cleanupCompletedFlows(key, retentionSeconds) {
|
|
298
|
-
if (!redis.status || redis.status === "end") await redis.connect();
|
|
299
|
-
const now = Date.now();
|
|
300
|
-
const cutoffTime = now - retentionSeconds * 1e3;
|
|
301
|
-
const oldEntries = await redis.zrangebyscore(key, "-inf", cutoffTime);
|
|
302
|
-
let removedCount = 0;
|
|
303
|
-
for (const runId of oldEntries) {
|
|
304
|
-
const metaKey = `${key}:meta:${runId}`;
|
|
305
|
-
const metadata = await redis.hgetall(metaKey);
|
|
306
|
-
if (metadata && (metadata.status === "completed" || metadata.status === "failed")) {
|
|
307
|
-
await redis.zrem(key, runId);
|
|
308
|
-
await redis.del(metaKey);
|
|
309
|
-
removedCount++;
|
|
310
|
-
}
|
|
311
|
-
}
|
|
312
|
-
return removedCount;
|
|
313
|
-
},
|
|
314
|
-
async deleteStream(subject) {
|
|
315
|
-
if (!redis.status || redis.status === "end") await redis.connect();
|
|
316
|
-
await redis.del(subject);
|
|
317
|
-
},
|
|
318
|
-
async deleteByPattern(pattern) {
|
|
319
|
-
if (!redis.status || redis.status === "end") await redis.connect();
|
|
320
|
-
let cursor = "0";
|
|
321
|
-
const keysToDelete = [];
|
|
322
|
-
do {
|
|
323
|
-
const result = await redis.scan(cursor, "MATCH", pattern, "COUNT", 100);
|
|
324
|
-
cursor = result[0];
|
|
325
|
-
const keys = result[1];
|
|
326
|
-
if (keys.length > 0) {
|
|
327
|
-
keysToDelete.push(...keys);
|
|
328
|
-
}
|
|
329
|
-
} while (cursor !== "0");
|
|
330
|
-
if (keysToDelete.length > 0) {
|
|
331
|
-
await redis.del(...keysToDelete);
|
|
332
|
-
}
|
|
333
|
-
return keysToDelete.length;
|
|
334
|
-
},
|
|
335
|
-
async deleteIndex(key) {
|
|
336
|
-
if (!redis.status || redis.status === "end") await redis.connect();
|
|
337
|
-
await redis.del(key);
|
|
338
|
-
},
|
|
339
|
-
async close() {
|
|
340
|
-
try {
|
|
341
|
-
await gateway.cleanup();
|
|
342
|
-
await redis.quit();
|
|
343
|
-
await subscriber.quit();
|
|
344
|
-
} catch {
|
|
345
|
-
}
|
|
346
|
-
}
|
|
347
|
-
};
|
|
348
|
-
}
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import type IORedis from 'ioredis';
|
|
2
|
-
/**
|
|
3
|
-
* Gateway pattern for Redis Pub/Sub
|
|
4
|
-
* Maintains a single 'message' listener and routes to channel-specific handlers
|
|
5
|
-
*/
|
|
6
|
-
export declare class RedisPubSubGateway {
|
|
7
|
-
private subscriber;
|
|
8
|
-
private channelSubscribers;
|
|
9
|
-
private initialized;
|
|
10
|
-
private logger;
|
|
11
|
-
constructor(subscriber: IORedis);
|
|
12
|
-
private initialize;
|
|
13
|
-
/**
|
|
14
|
-
* Subscribe to a channel with a handler
|
|
15
|
-
* Returns unsubscribe function
|
|
16
|
-
*/
|
|
17
|
-
subscribe(channel: string, handler: (messageId: string) => void): Promise<() => void>;
|
|
18
|
-
/**
|
|
19
|
-
* Get subscriber count for a channel (for debugging)
|
|
20
|
-
*/
|
|
21
|
-
getSubscriberCount(channel: string): number;
|
|
22
|
-
/**
|
|
23
|
-
* Get total subscriber count across all channels
|
|
24
|
-
*/
|
|
25
|
-
getTotalSubscriberCount(): number;
|
|
26
|
-
/**
|
|
27
|
-
* Cleanup all subscriptions
|
|
28
|
-
*/
|
|
29
|
-
cleanup(): Promise<void>;
|
|
30
|
-
}
|
|
@@ -1,82 +0,0 @@
|
|
|
1
|
-
import { useNventLogger } from "#imports";
|
|
2
|
-
export class RedisPubSubGateway {
|
|
3
|
-
constructor(subscriber) {
|
|
4
|
-
this.subscriber = subscriber;
|
|
5
|
-
}
|
|
6
|
-
channelSubscribers = /* @__PURE__ */ new Map();
|
|
7
|
-
initialized = false;
|
|
8
|
-
logger = useNventLogger("redis-pubsub-gateway");
|
|
9
|
-
initialize() {
|
|
10
|
-
if (this.initialized) return;
|
|
11
|
-
this.initialized = true;
|
|
12
|
-
this.subscriber.on("message", (channel, messageId) => {
|
|
13
|
-
const handlers = this.channelSubscribers.get(channel);
|
|
14
|
-
if (!handlers || handlers.size === 0) return;
|
|
15
|
-
for (const handler of handlers) {
|
|
16
|
-
try {
|
|
17
|
-
handler(messageId);
|
|
18
|
-
} catch (err) {
|
|
19
|
-
if (process.env.NQ_DEBUG_EVENTS === "1") {
|
|
20
|
-
this.logger.error("[redis-pubsub-gateway] Handler error:", err);
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
});
|
|
25
|
-
}
|
|
26
|
-
/**
|
|
27
|
-
* Subscribe to a channel with a handler
|
|
28
|
-
* Returns unsubscribe function
|
|
29
|
-
*/
|
|
30
|
-
async subscribe(channel, handler) {
|
|
31
|
-
this.initialize();
|
|
32
|
-
if (!this.channelSubscribers.has(channel)) {
|
|
33
|
-
this.channelSubscribers.set(channel, /* @__PURE__ */ new Set());
|
|
34
|
-
await this.subscriber.subscribe(channel);
|
|
35
|
-
if (process.env.NQ_DEBUG_EVENTS === "1") {
|
|
36
|
-
this.logger.info("[redis-pubsub-gateway] Subscribed to channel:", channel);
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
this.channelSubscribers.get(channel).add(handler);
|
|
40
|
-
return () => {
|
|
41
|
-
const handlers = this.channelSubscribers.get(channel);
|
|
42
|
-
if (handlers) {
|
|
43
|
-
handlers.delete(handler);
|
|
44
|
-
if (handlers.size === 0) {
|
|
45
|
-
this.channelSubscribers.delete(channel);
|
|
46
|
-
this.subscriber.unsubscribe(channel).catch(() => {
|
|
47
|
-
});
|
|
48
|
-
if (process.env.NQ_DEBUG_EVENTS === "1") {
|
|
49
|
-
this.logger.info("[redis-pubsub-gateway] Unsubscribed from channel:", channel);
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
};
|
|
54
|
-
}
|
|
55
|
-
/**
|
|
56
|
-
* Get subscriber count for a channel (for debugging)
|
|
57
|
-
*/
|
|
58
|
-
getSubscriberCount(channel) {
|
|
59
|
-
return this.channelSubscribers.get(channel)?.size ?? 0;
|
|
60
|
-
}
|
|
61
|
-
/**
|
|
62
|
-
* Get total subscriber count across all channels
|
|
63
|
-
*/
|
|
64
|
-
getTotalSubscriberCount() {
|
|
65
|
-
let count = 0;
|
|
66
|
-
for (const handlers of this.channelSubscribers.values()) {
|
|
67
|
-
count += handlers.size;
|
|
68
|
-
}
|
|
69
|
-
return count;
|
|
70
|
-
}
|
|
71
|
-
/**
|
|
72
|
-
* Cleanup all subscriptions
|
|
73
|
-
*/
|
|
74
|
-
async cleanup() {
|
|
75
|
-
const channels = Array.from(this.channelSubscribers.keys());
|
|
76
|
-
this.channelSubscribers.clear();
|
|
77
|
-
if (channels.length > 0) {
|
|
78
|
-
await this.subscriber.unsubscribe(...channels).catch(() => {
|
|
79
|
-
});
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
}
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import { getStreamNames } from './streamNames.js';
|
|
2
|
-
import type { EventStoreAdapter } from './types.js';
|
|
3
|
-
export interface EventStoreInstance {
|
|
4
|
-
name: string;
|
|
5
|
-
append: EventStoreAdapter['append'];
|
|
6
|
-
read: EventStoreAdapter['read'];
|
|
7
|
-
subscribe: EventStoreAdapter['subscribe'];
|
|
8
|
-
}
|
|
9
|
-
export interface EventStoreFactory {
|
|
10
|
-
adapter: EventStoreAdapter;
|
|
11
|
-
names: ReturnType<typeof getStreamNames>;
|
|
12
|
-
stream(name: string): EventStoreInstance;
|
|
13
|
-
/** Idempotently start stream store wiring that persists ingress events and projections */
|
|
14
|
-
start(): void;
|
|
15
|
-
/** Stop wiring and release listeners */
|
|
16
|
-
stop(): void;
|
|
17
|
-
}
|
|
18
|
-
export declare function getEventStoreFactory(): EventStoreFactory;
|
|
19
|
-
export declare function setEventStoreFactory(f: EventStoreFactory): void;
|
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
import { useRuntimeConfig, useNventLogger } from "#imports";
|
|
2
|
-
import { getStreamNames } from "./streamNames.js";
|
|
3
|
-
import { createRedisAdapter } from "./adapters/redis/redisAdapter.js";
|
|
4
|
-
import { createMemoryAdapter } from "./adapters/memoryAdapter.js";
|
|
5
|
-
import { createFileAdapter } from "./adapters/fileAdapter.js";
|
|
6
|
-
import { createWiringRegistry } from "./wiring/registry.js";
|
|
7
|
-
let cachedFactory = null;
|
|
8
|
-
export function getEventStoreFactory() {
|
|
9
|
-
if (cachedFactory) return cachedFactory;
|
|
10
|
-
const logger = useNventLogger("event-store-factory");
|
|
11
|
-
const rc = useRuntimeConfig();
|
|
12
|
-
const adapter = rc?.queue?.eventStore?.adapter || "memory";
|
|
13
|
-
let adapterInstance;
|
|
14
|
-
if (adapter === "memory") adapterInstance = createMemoryAdapter();
|
|
15
|
-
else if (adapter === "file") adapterInstance = createFileAdapter();
|
|
16
|
-
else if (adapter === "redis") adapterInstance = createRedisAdapter();
|
|
17
|
-
else adapterInstance = createMemoryAdapter();
|
|
18
|
-
logger.debug("Event store initialized", { adapter, adapterType: adapter });
|
|
19
|
-
const names = getStreamNames();
|
|
20
|
-
const wiring = createWiringRegistry({ adapter: adapterInstance, names });
|
|
21
|
-
const factory = {
|
|
22
|
-
adapter: adapterInstance,
|
|
23
|
-
names,
|
|
24
|
-
stream(name) {
|
|
25
|
-
return {
|
|
26
|
-
name,
|
|
27
|
-
append: (s, e) => adapterInstance.append(s, e),
|
|
28
|
-
read: (s, o) => adapterInstance.read(s, o),
|
|
29
|
-
subscribe: (s, cb) => adapterInstance.subscribe(s, cb)
|
|
30
|
-
};
|
|
31
|
-
},
|
|
32
|
-
start() {
|
|
33
|
-
wiring.start();
|
|
34
|
-
},
|
|
35
|
-
stop() {
|
|
36
|
-
wiring.stop();
|
|
37
|
-
}
|
|
38
|
-
};
|
|
39
|
-
cachedFactory = factory;
|
|
40
|
-
return factory;
|
|
41
|
-
}
|
|
42
|
-
export function setEventStoreFactory(f) {
|
|
43
|
-
cachedFactory = f;
|
|
44
|
-
}
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Stream naming utilities
|
|
3
|
-
*
|
|
4
|
-
* Core streams:
|
|
5
|
-
* - nq:flow:{runId} - Flow run event stream
|
|
6
|
-
* - nq:flows:{flowName} - Sorted set index of flow runs by flow name
|
|
7
|
-
*/
|
|
8
|
-
export interface StreamNamesConfig {
|
|
9
|
-
flow?: string | ((runId: string) => string);
|
|
10
|
-
flowIndex?: string | ((flowName: string) => string);
|
|
11
|
-
}
|
|
12
|
-
export interface StreamNames {
|
|
13
|
-
flow: (runId: string) => string;
|
|
14
|
-
flowIndex: (flowName: string) => string;
|
|
15
|
-
}
|
|
16
|
-
export declare function getStreamNames(): StreamNames;
|
|
17
|
-
export default getStreamNames;
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { useRuntimeConfig } from "#imports";
|
|
2
|
-
function defaults() {
|
|
3
|
-
return {
|
|
4
|
-
flow: (runId) => `nq:flow:${runId}`,
|
|
5
|
-
flowIndex: (flowName) => `nq:flows:${flowName}`
|
|
6
|
-
};
|
|
7
|
-
}
|
|
8
|
-
export function getStreamNames() {
|
|
9
|
-
const rc = useRuntimeConfig();
|
|
10
|
-
const cfg = rc?.queue?.eventStore?.streams || {};
|
|
11
|
-
const d = defaults();
|
|
12
|
-
return {
|
|
13
|
-
flow: typeof cfg.flow === "string" ? (runId) => `${cfg.flow}${runId}` : cfg.flow || d.flow,
|
|
14
|
-
flowIndex: typeof cfg.flowIndex === "string" ? (flowName) => `${cfg.flowIndex}${flowName}` : cfg.flowIndex || d.flowIndex
|
|
15
|
-
};
|
|
16
|
-
}
|
|
17
|
-
export default getStreamNames;
|
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
import type { EventRecord } from '../types.js';
|
|
2
|
-
export interface PublishContext {
|
|
3
|
-
queue?: string;
|
|
4
|
-
jobId?: string;
|
|
5
|
-
/** Flow run ID for flow events */
|
|
6
|
-
flowId?: string;
|
|
7
|
-
/** Trigger ID for trigger events */
|
|
8
|
-
triggerId?: string;
|
|
9
|
-
}
|
|
10
|
-
export interface PublishPayload<T = any> {
|
|
11
|
-
type: string;
|
|
12
|
-
runId: string;
|
|
13
|
-
flowName: string;
|
|
14
|
-
stepName?: string;
|
|
15
|
-
stepId?: string;
|
|
16
|
-
attempt?: number;
|
|
17
|
-
data?: T;
|
|
18
|
-
}
|
|
19
|
-
export interface EventReadOptions {
|
|
20
|
-
fromId?: string;
|
|
21
|
-
limit?: number;
|
|
22
|
-
direction?: 'forward' | 'backward';
|
|
23
|
-
}
|
|
24
|
-
export interface EventSubscription {
|
|
25
|
-
unsubscribe(): void;
|
|
26
|
-
}
|
|
27
|
-
export interface IndexEntry {
|
|
28
|
-
id: string;
|
|
29
|
-
score: number;
|
|
30
|
-
metadata?: {
|
|
31
|
-
status?: 'running' | 'completed' | 'failed';
|
|
32
|
-
startedAt?: number;
|
|
33
|
-
completedAt?: number;
|
|
34
|
-
stepCount?: number;
|
|
35
|
-
completedSteps?: number;
|
|
36
|
-
emittedEvents?: string[];
|
|
37
|
-
version?: number;
|
|
38
|
-
};
|
|
39
|
-
}
|
|
40
|
-
export interface IndexReadOptions {
|
|
41
|
-
offset?: number;
|
|
42
|
-
limit?: number;
|
|
43
|
-
}
|
|
44
|
-
export interface EventStoreAdapter {
|
|
45
|
-
append(subject: string, e: Omit<EventRecord, 'id' | 'ts'>): Promise<EventRecord>;
|
|
46
|
-
read(subject: string, opts?: EventReadOptions): Promise<EventRecord[]>;
|
|
47
|
-
subscribe(subject: string, onEvent: (e: EventRecord) => void): Promise<EventSubscription>;
|
|
48
|
-
indexAdd?(key: string, id: string, score: number, metadata?: Record<string, any>): Promise<void>;
|
|
49
|
-
indexGet?(key: string, id: string): Promise<IndexEntry | null>;
|
|
50
|
-
indexUpdate?(key: string, id: string, metadata: Record<string, any>): Promise<boolean>;
|
|
51
|
-
indexUpdateWithRetry?(key: string, id: string, metadata: Record<string, any>, maxRetries?: number): Promise<void>;
|
|
52
|
-
indexIncrement?(key: string, id: string, field: string, increment?: number): Promise<number>;
|
|
53
|
-
indexRead?(key: string, opts?: IndexReadOptions): Promise<IndexEntry[]>;
|
|
54
|
-
setMetadataTTL?(flowName: string, runId: string, ttlSeconds: number): Promise<void>;
|
|
55
|
-
cleanupCompletedFlows?(key: string, retentionSeconds: number): Promise<number>;
|
|
56
|
-
/** Delete a specific stream/subject */
|
|
57
|
-
deleteStream?(subject: string): Promise<void>;
|
|
58
|
-
/** Delete all streams matching a pattern (e.g., 'flow:*' or 'trigger:webhook-*') */
|
|
59
|
-
deleteByPattern?(pattern: string): Promise<number>;
|
|
60
|
-
/** Delete an index key */
|
|
61
|
-
deleteIndex?(key: string): Promise<void>;
|
|
62
|
-
close(): Promise<void>;
|
|
63
|
-
}
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import type { StreamAdapter } from '../types.js';
|
|
2
|
-
export interface WiringDeps {
|
|
3
|
-
adapter: StreamAdapter;
|
|
4
|
-
names?: any;
|
|
5
|
-
}
|
|
6
|
-
export interface Wiring {
|
|
7
|
-
start(): void;
|
|
8
|
-
stop(): void;
|
|
9
|
-
}
|
|
10
|
-
export declare function createWiringRegistry(deps: WiringDeps): Wiring;
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import { createFlowWiring } from "./flowWiring.js";
|
|
2
|
-
export function createWiringRegistry(deps) {
|
|
3
|
-
const wirings = [
|
|
4
|
-
createFlowWiring({ adapter: deps.adapter })
|
|
5
|
-
// add future wirings here (triggers, webhooks, etc.)
|
|
6
|
-
];
|
|
7
|
-
let started = false;
|
|
8
|
-
return {
|
|
9
|
-
start() {
|
|
10
|
-
if (started) return;
|
|
11
|
-
started = true;
|
|
12
|
-
for (const w of wirings) w.start();
|
|
13
|
-
},
|
|
14
|
-
stop() {
|
|
15
|
-
for (const w of wirings) {
|
|
16
|
-
try {
|
|
17
|
-
w.stop();
|
|
18
|
-
} catch {
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
started = false;
|
|
22
|
-
}
|
|
23
|
-
};
|
|
24
|
-
}
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import type { QueueProvider, JobInput, Job, JobsQuery, ScheduleOptions, QueueEvent, JobCounts } from '../types.js';
|
|
2
|
-
export declare class BullMQProvider implements QueueProvider {
|
|
3
|
-
private queues;
|
|
4
|
-
private logger;
|
|
5
|
-
init(): Promise<void>;
|
|
6
|
-
private ensureQueue;
|
|
7
|
-
enqueue(queueName: string, job: JobInput): Promise<string>;
|
|
8
|
-
schedule(queueName: string, job: JobInput, opts?: ScheduleOptions): Promise<string>;
|
|
9
|
-
getJob(queueName: string, id: string): Promise<Job | null>;
|
|
10
|
-
getJobs(queueName: string, _q?: JobsQuery): Promise<Job[]>;
|
|
11
|
-
on(queueName: string, event: QueueEvent, cb: (p: any) => void): () => void;
|
|
12
|
-
isPaused(queueName: string): Promise<boolean>;
|
|
13
|
-
getJobCounts(queueName: string): Promise<JobCounts>;
|
|
14
|
-
pause(queueName: string): Promise<void>;
|
|
15
|
-
resume(queueName: string): Promise<void>;
|
|
16
|
-
close(): Promise<void>;
|
|
17
|
-
private toJob;
|
|
18
|
-
}
|