nvent 0.4.3 → 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 -15
- package/dist/runtime/app/composables/useFlowRunTimeline.js +0 -66
- 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 -20
- 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 -44
- 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,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
|
-
}
|
|
@@ -1,171 +0,0 @@
|
|
|
1
|
-
const GLOBAL_KEY = "__nuxt_queue_memory_adapter__";
|
|
2
|
-
function getStore() {
|
|
3
|
-
if (!globalThis[GLOBAL_KEY]) {
|
|
4
|
-
globalThis[GLOBAL_KEY] = {
|
|
5
|
-
events: /* @__PURE__ */ new Map(),
|
|
6
|
-
listeners: /* @__PURE__ */ new Map(),
|
|
7
|
-
indices: /* @__PURE__ */ new Map()
|
|
8
|
-
};
|
|
9
|
-
}
|
|
10
|
-
return globalThis[GLOBAL_KEY];
|
|
11
|
-
}
|
|
12
|
-
export function createMemoryAdapter() {
|
|
13
|
-
const { events, listeners, indices } = getStore();
|
|
14
|
-
return {
|
|
15
|
-
async append(stream, e) {
|
|
16
|
-
const id = `${Date.now()}-${Math.random().toString(16).slice(2)}`;
|
|
17
|
-
const rec = { ...e, id, ts: (/* @__PURE__ */ new Date()).toISOString() };
|
|
18
|
-
const list = events.get(stream) || [];
|
|
19
|
-
list.push(rec);
|
|
20
|
-
events.set(stream, list);
|
|
21
|
-
const set = listeners.get(stream);
|
|
22
|
-
if (set) set.forEach((cb) => cb(rec));
|
|
23
|
-
return rec;
|
|
24
|
-
},
|
|
25
|
-
async read(stream, opts) {
|
|
26
|
-
const list = events.get(stream) || [];
|
|
27
|
-
const dir = opts?.direction || "forward";
|
|
28
|
-
if (dir === "backward") {
|
|
29
|
-
let end = list.length;
|
|
30
|
-
if (opts?.fromId) {
|
|
31
|
-
const idx2 = list.findIndex((e) => e.id === opts.fromId);
|
|
32
|
-
end = idx2 >= 0 ? idx2 : list.length;
|
|
33
|
-
}
|
|
34
|
-
const count = opts?.limit && opts.limit > 0 ? opts.limit : end;
|
|
35
|
-
const start = Math.max(0, end - count);
|
|
36
|
-
const slice = list.slice(start, end);
|
|
37
|
-
return slice.reverse();
|
|
38
|
-
}
|
|
39
|
-
if (!opts?.fromId) {
|
|
40
|
-
if (opts?.limit && opts.limit > 0) return list.slice(0, opts.limit);
|
|
41
|
-
return list;
|
|
42
|
-
}
|
|
43
|
-
const idx = list.findIndex((e) => e.id === opts.fromId);
|
|
44
|
-
const out = idx >= 0 ? list.slice(idx + 1) : list;
|
|
45
|
-
if (opts?.limit && opts.limit > 0) return out.slice(0, opts.limit);
|
|
46
|
-
return out;
|
|
47
|
-
},
|
|
48
|
-
async subscribe(stream, onEvent) {
|
|
49
|
-
let set = listeners.get(stream);
|
|
50
|
-
if (!set) {
|
|
51
|
-
set = /* @__PURE__ */ new Set();
|
|
52
|
-
listeners.set(stream, set);
|
|
53
|
-
}
|
|
54
|
-
set.add(onEvent);
|
|
55
|
-
return {
|
|
56
|
-
unsubscribe() {
|
|
57
|
-
set.delete(onEvent);
|
|
58
|
-
}
|
|
59
|
-
};
|
|
60
|
-
},
|
|
61
|
-
async indexAdd(key, id, score, metadata) {
|
|
62
|
-
const data = indices.get(key) || [];
|
|
63
|
-
const existing = data.findIndex((entry) => entry.id === id);
|
|
64
|
-
if (existing >= 0) {
|
|
65
|
-
data[existing].score = score;
|
|
66
|
-
if (metadata) {
|
|
67
|
-
data[existing].metadata = metadata;
|
|
68
|
-
}
|
|
69
|
-
} else {
|
|
70
|
-
data.push({ id, score, metadata });
|
|
71
|
-
}
|
|
72
|
-
indices.set(key, data);
|
|
73
|
-
},
|
|
74
|
-
async indexRead(key, opts) {
|
|
75
|
-
const data = indices.get(key) || [];
|
|
76
|
-
const sorted = [...data].sort((a, b) => b.score - a.score);
|
|
77
|
-
const offset = opts?.offset || 0;
|
|
78
|
-
const limit = opts?.limit || 50;
|
|
79
|
-
return sorted.slice(offset, offset + limit);
|
|
80
|
-
},
|
|
81
|
-
async indexGet(key, id) {
|
|
82
|
-
const data = indices.get(key) || [];
|
|
83
|
-
const entry = data.find((item) => item.id === id);
|
|
84
|
-
if (!entry) return null;
|
|
85
|
-
return {
|
|
86
|
-
id: entry.id,
|
|
87
|
-
score: entry.score,
|
|
88
|
-
metadata: entry.metadata
|
|
89
|
-
};
|
|
90
|
-
},
|
|
91
|
-
async indexUpdate(key, id, metadata) {
|
|
92
|
-
const data = indices.get(key) || [];
|
|
93
|
-
const entryIndex = data.findIndex((item) => item.id === id);
|
|
94
|
-
if (entryIndex === -1) {
|
|
95
|
-
data.push({ id, score: Date.now(), metadata: { ...metadata, version: 1 } });
|
|
96
|
-
indices.set(key, data);
|
|
97
|
-
return true;
|
|
98
|
-
}
|
|
99
|
-
const entry = data[entryIndex];
|
|
100
|
-
const currentVersion = entry.metadata?.version || 0;
|
|
101
|
-
const expectedVersion = metadata.version !== void 0 ? metadata.version - 1 : currentVersion;
|
|
102
|
-
if (currentVersion !== expectedVersion) {
|
|
103
|
-
return false;
|
|
104
|
-
}
|
|
105
|
-
entry.metadata = {
|
|
106
|
-
...entry.metadata,
|
|
107
|
-
...metadata,
|
|
108
|
-
version: currentVersion + 1
|
|
109
|
-
};
|
|
110
|
-
indices.set(key, data);
|
|
111
|
-
return true;
|
|
112
|
-
},
|
|
113
|
-
async indexUpdateWithRetry(key, id, metadata, maxRetries = 3) {
|
|
114
|
-
for (let attempt = 0; attempt < maxRetries; attempt++) {
|
|
115
|
-
const success = await this.indexUpdate(key, id, metadata);
|
|
116
|
-
if (success) return;
|
|
117
|
-
await new Promise((resolve) => setTimeout(resolve, 10 * Math.pow(2, attempt)));
|
|
118
|
-
}
|
|
119
|
-
throw new Error(`Failed to update index after ${maxRetries} retries`);
|
|
120
|
-
},
|
|
121
|
-
async indexIncrement(key, id, field, increment = 1) {
|
|
122
|
-
const data = indices.get(key) || [];
|
|
123
|
-
const entryIndex = data.findIndex((item) => item.id === id);
|
|
124
|
-
if (entryIndex === -1) {
|
|
125
|
-
const newEntry = {
|
|
126
|
-
id,
|
|
127
|
-
score: Date.now(),
|
|
128
|
-
metadata: { [field]: increment, version: 1 }
|
|
129
|
-
};
|
|
130
|
-
data.push(newEntry);
|
|
131
|
-
indices.set(key, data);
|
|
132
|
-
return increment;
|
|
133
|
-
}
|
|
134
|
-
const entry = data[entryIndex];
|
|
135
|
-
if (!entry.metadata) {
|
|
136
|
-
entry.metadata = { version: 0 };
|
|
137
|
-
}
|
|
138
|
-
const currentValue = entry.metadata[field] || 0;
|
|
139
|
-
const newValue = currentValue + increment;
|
|
140
|
-
entry.metadata[field] = newValue;
|
|
141
|
-
entry.metadata.version = (entry.metadata.version || 0) + 1;
|
|
142
|
-
indices.set(key, data);
|
|
143
|
-
return newValue;
|
|
144
|
-
},
|
|
145
|
-
async deleteStream(subject) {
|
|
146
|
-
events.delete(subject);
|
|
147
|
-
listeners.delete(subject);
|
|
148
|
-
},
|
|
149
|
-
async deleteByPattern(pattern) {
|
|
150
|
-
const regexPattern = pattern.replace(/\*/g, ".*").replace(/\?/g, ".");
|
|
151
|
-
const regex = new RegExp(`^${regexPattern}$`);
|
|
152
|
-
let count = 0;
|
|
153
|
-
for (const key of events.keys()) {
|
|
154
|
-
if (regex.test(key)) {
|
|
155
|
-
events.delete(key);
|
|
156
|
-
listeners.delete(key);
|
|
157
|
-
count++;
|
|
158
|
-
}
|
|
159
|
-
}
|
|
160
|
-
return count;
|
|
161
|
-
},
|
|
162
|
-
async deleteIndex(key) {
|
|
163
|
-
indices.delete(key);
|
|
164
|
-
},
|
|
165
|
-
async close() {
|
|
166
|
-
listeners.clear();
|
|
167
|
-
events.clear();
|
|
168
|
-
indices.clear();
|
|
169
|
-
}
|
|
170
|
-
};
|
|
171
|
-
}
|