nvent 0.4.5 → 0.5.1
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 +1 -1
- package/dist/module.mjs +433 -180
- 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 +15 -1
- package/dist/runtime/adapters/builtin/file-queue.js +70 -6
- package/dist/runtime/adapters/builtin/file-store.d.ts +4 -18
- package/dist/runtime/adapters/builtin/file-store.js +90 -109
- package/dist/runtime/adapters/builtin/memory-queue.js +4 -0
- package/dist/runtime/adapters/builtin/memory-store.d.ts +42 -31
- package/dist/runtime/adapters/builtin/memory-store.js +253 -183
- package/dist/runtime/adapters/factory.d.ts +2 -2
- package/dist/runtime/adapters/factory.js +54 -20
- package/dist/runtime/adapters/interfaces/store.d.ts +177 -113
- package/dist/runtime/config/index.d.ts +2 -2
- package/dist/runtime/config/index.js +14 -6
- package/dist/runtime/config/types.d.ts +32 -2
- package/dist/runtime/events/eventBus.d.ts +1 -1
- package/dist/runtime/events/types.d.ts +31 -2
- 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 +44 -3
- package/dist/runtime/events/utils/stallDetector.js +288 -89
- package/dist/runtime/events/utils/triggerRuntime.d.ts +58 -0
- package/dist/runtime/events/utils/triggerRuntime.js +212 -0
- package/dist/runtime/events/wiring/flowWiring.d.ts +11 -5
- package/dist/runtime/events/wiring/flowWiring.js +620 -92
- package/dist/runtime/events/wiring/registry.d.ts +2 -2
- package/dist/runtime/events/wiring/registry.js +8 -6
- package/dist/runtime/events/wiring/streamWiring.d.ts +15 -11
- package/dist/runtime/events/wiring/streamWiring.js +88 -11
- package/dist/runtime/events/wiring/triggerWiring.d.ts +21 -0
- package/dist/runtime/events/wiring/triggerWiring.js +412 -0
- package/dist/runtime/{server → nitro}/plugins/00.adapters.js +8 -4
- package/dist/runtime/{server → nitro}/plugins/02.workers.js +21 -3
- 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/{utils → nitro/utils}/adapters.d.ts +6 -6
- 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/{utils → nitro/utils}/defineFunction.d.ts +2 -2
- package/dist/runtime/{utils → nitro/utils}/defineFunction.js +3 -3
- package/dist/runtime/{utils → nitro/utils}/defineFunctionConfig.d.ts +156 -0
- package/dist/runtime/{utils → nitro/utils}/defineFunctionConfig.js +1 -0
- package/dist/runtime/nitro/utils/defineHooks.d.ts +41 -0
- package/dist/runtime/nitro/utils/defineHooks.js +6 -0
- package/dist/runtime/{utils → nitro/utils}/registerAdapter.d.ts +3 -3
- package/dist/runtime/{utils → nitro/utils}/registerAdapter.js +1 -1
- package/dist/runtime/nitro/utils/useAwait.d.ts +71 -0
- package/dist/runtime/nitro/utils/useAwait.js +139 -0
- package/dist/runtime/{utils → nitro/utils}/useEventManager.d.ts +2 -2
- package/dist/runtime/{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/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/worker/node/runner.d.ts +12 -2
- package/dist/runtime/worker/node/runner.js +141 -37
- package/package.json +6 -6
- 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 -55
- package/dist/runtime/server/api/_flows/[name]/runs/[runId]/cancel.post.d.ts +0 -2
- package/dist/runtime/server/api/_flows/[name]/runs/[runId]/cancel.post.js +0 -21
- package/dist/runtime/server/api/_flows/[name]/runs.get.d.ts +0 -17
- package/dist/runtime/server/api/_flows/[name]/runs.get.js +0 -64
- package/dist/runtime/server/api/_flows/[name]/schedule.post.d.ts +0 -2
- package/dist/runtime/server/api/_flows/[name]/schedule.post.js +0 -66
- 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 -47
- package/dist/runtime/server/api/_flows/[name]/schedules.get.d.ts +0 -2
- package/dist/runtime/server/api/_flows/[name]/schedules.get.js +0 -50
- 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 -209
- 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 -14
- 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 -27
- package/dist/runtime/server/api/_queues/index.get.d.ts +0 -2
- package/dist/runtime/server/api/_queues/index.get.js +0 -106
- package/dist/runtime/server/api/_queues/ws.d.ts +0 -48
- package/dist/runtime/server/api/_queues/ws.js +0 -215
- package/dist/runtime/utils/useFlowEngine.d.ts +0 -19
- package/dist/runtime/utils/useFlowEngine.js +0 -108
- package/dist/runtime/utils/useStreamTopics.d.ts +0 -72
- package/dist/runtime/utils/useStreamTopics.js +0 -47
- /package/dist/runtime/{server → nitro}/plugins/00.adapters.d.ts +0 -0
- /package/dist/runtime/{server → nitro}/plugins/01.ws-lifecycle.d.ts +0 -0
- /package/dist/runtime/{server → nitro}/plugins/01.ws-lifecycle.js +0 -0
- /package/dist/runtime/{server → nitro}/plugins/02.workers.d.ts +0 -0
- /package/dist/runtime/{utils → nitro/utils}/adapters.js +0 -0
- /package/dist/runtime/{utils → nitro/utils}/useNventLogger.d.ts +0 -0
- /package/dist/runtime/{utils → nitro/utils}/useNventLogger.js +0 -0
- /package/dist/runtime/{utils → nitro/utils}/wsPeerManager.d.ts +0 -0
- /package/dist/runtime/{utils → nitro/utils}/wsPeerManager.js +0 -0
|
@@ -1,215 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
defineWebSocketHandler,
|
|
3
|
-
useQueueAdapter,
|
|
4
|
-
usePeerManager,
|
|
5
|
-
useNventLogger
|
|
6
|
-
} from "#imports";
|
|
7
|
-
const peerContexts = /* @__PURE__ */ new WeakMap();
|
|
8
|
-
function safeSend(peer, data) {
|
|
9
|
-
try {
|
|
10
|
-
peer.send(JSON.stringify(data));
|
|
11
|
-
return true;
|
|
12
|
-
} catch {
|
|
13
|
-
return false;
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
export default defineWebSocketHandler({
|
|
17
|
-
open(peer) {
|
|
18
|
-
const logger = useNventLogger("api-queues-ws");
|
|
19
|
-
logger.info("[ws:queues] client connected:", peer.id);
|
|
20
|
-
const { registerWsPeer } = usePeerManager();
|
|
21
|
-
registerWsPeer(peer);
|
|
22
|
-
peerContexts.set(peer, {
|
|
23
|
-
subscriptions: /* @__PURE__ */ new Map()
|
|
24
|
-
});
|
|
25
|
-
safeSend(peer, {
|
|
26
|
-
type: "connected",
|
|
27
|
-
timestamp: Date.now()
|
|
28
|
-
});
|
|
29
|
-
},
|
|
30
|
-
async message(peer, message) {
|
|
31
|
-
const logger = useNventLogger("api-queues-ws");
|
|
32
|
-
const context = peerContexts.get(peer);
|
|
33
|
-
if (!context) {
|
|
34
|
-
logger.error("[ws:queues] no context for peer:", peer.id);
|
|
35
|
-
return;
|
|
36
|
-
}
|
|
37
|
-
let data;
|
|
38
|
-
try {
|
|
39
|
-
data = JSON.parse(message.text());
|
|
40
|
-
} catch {
|
|
41
|
-
safeSend(peer, {
|
|
42
|
-
type: "error",
|
|
43
|
-
message: "Invalid JSON"
|
|
44
|
-
});
|
|
45
|
-
return;
|
|
46
|
-
}
|
|
47
|
-
const { type, queueName } = data;
|
|
48
|
-
if (type === "subscribe") {
|
|
49
|
-
if (!queueName) {
|
|
50
|
-
safeSend(peer, {
|
|
51
|
-
type: "error",
|
|
52
|
-
message: "Missing queueName"
|
|
53
|
-
});
|
|
54
|
-
return;
|
|
55
|
-
}
|
|
56
|
-
let queue;
|
|
57
|
-
try {
|
|
58
|
-
queue = useQueueAdapter();
|
|
59
|
-
} catch (err) {
|
|
60
|
-
logger.error("[ws:queues] Adapters not initialized yet:", err);
|
|
61
|
-
safeSend(peer, {
|
|
62
|
-
type: "error",
|
|
63
|
-
message: "Server initializing, please retry"
|
|
64
|
-
});
|
|
65
|
-
return;
|
|
66
|
-
}
|
|
67
|
-
const existingUnsub = context.subscriptions.get(queueName);
|
|
68
|
-
if (existingUnsub) {
|
|
69
|
-
try {
|
|
70
|
-
existingUnsub();
|
|
71
|
-
} catch (err) {
|
|
72
|
-
logger.error("[ws:queues] error unsubscribing:", err);
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
const events = [
|
|
76
|
-
"waiting",
|
|
77
|
-
"active",
|
|
78
|
-
"completed",
|
|
79
|
-
"failed",
|
|
80
|
-
"progress"
|
|
81
|
-
];
|
|
82
|
-
const unsubs = events.map(
|
|
83
|
-
(eventType) => queue.on(queueName, eventType, async (payload) => {
|
|
84
|
-
safeSend(peer, {
|
|
85
|
-
type: "event",
|
|
86
|
-
queueName,
|
|
87
|
-
event: {
|
|
88
|
-
eventType,
|
|
89
|
-
...payload
|
|
90
|
-
}
|
|
91
|
-
});
|
|
92
|
-
if (["waiting", "active", "completed", "failed"].includes(eventType)) {
|
|
93
|
-
try {
|
|
94
|
-
const counts = await queue.getJobCounts(queueName);
|
|
95
|
-
safeSend(peer, {
|
|
96
|
-
type: "counts",
|
|
97
|
-
queueName,
|
|
98
|
-
counts
|
|
99
|
-
});
|
|
100
|
-
} catch (err) {
|
|
101
|
-
logger.error("[ws:queues] error fetching counts after event:", err);
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
})
|
|
105
|
-
);
|
|
106
|
-
const unsub = () => {
|
|
107
|
-
for (const u of unsubs) {
|
|
108
|
-
try {
|
|
109
|
-
u();
|
|
110
|
-
} catch (err) {
|
|
111
|
-
logger.error("[ws:queues] error unsubscribing:", err);
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
};
|
|
115
|
-
context.subscriptions.set(queueName, unsub);
|
|
116
|
-
try {
|
|
117
|
-
const counts = await queue.getJobCounts(queueName);
|
|
118
|
-
safeSend(peer, {
|
|
119
|
-
type: "counts",
|
|
120
|
-
queueName,
|
|
121
|
-
counts
|
|
122
|
-
});
|
|
123
|
-
} catch (err) {
|
|
124
|
-
logger.error("[ws:queues] error fetching counts:", err);
|
|
125
|
-
}
|
|
126
|
-
safeSend(peer, {
|
|
127
|
-
type: "subscribed",
|
|
128
|
-
queueName
|
|
129
|
-
});
|
|
130
|
-
} else if (type === "unsubscribe") {
|
|
131
|
-
if (!queueName) {
|
|
132
|
-
safeSend(peer, {
|
|
133
|
-
type: "error",
|
|
134
|
-
message: "Missing queueName"
|
|
135
|
-
});
|
|
136
|
-
return;
|
|
137
|
-
}
|
|
138
|
-
const unsub = context.subscriptions.get(queueName);
|
|
139
|
-
if (unsub) {
|
|
140
|
-
try {
|
|
141
|
-
unsub();
|
|
142
|
-
context.subscriptions.delete(queueName);
|
|
143
|
-
safeSend(peer, {
|
|
144
|
-
type: "unsubscribed",
|
|
145
|
-
queueName
|
|
146
|
-
});
|
|
147
|
-
} catch (err) {
|
|
148
|
-
logger.error("[ws:queues] error unsubscribing:", err);
|
|
149
|
-
safeSend(peer, {
|
|
150
|
-
type: "error",
|
|
151
|
-
message: "Failed to unsubscribe"
|
|
152
|
-
});
|
|
153
|
-
}
|
|
154
|
-
}
|
|
155
|
-
} else if (type === "ping") {
|
|
156
|
-
safeSend(peer, {
|
|
157
|
-
type: "pong",
|
|
158
|
-
timestamp: Date.now()
|
|
159
|
-
});
|
|
160
|
-
} else {
|
|
161
|
-
safeSend(peer, {
|
|
162
|
-
type: "error",
|
|
163
|
-
message: `Unknown message type: ${type}`
|
|
164
|
-
});
|
|
165
|
-
}
|
|
166
|
-
},
|
|
167
|
-
close(peer, event) {
|
|
168
|
-
const logger = useNventLogger("api-queues-ws");
|
|
169
|
-
const isNormalClosure = event?.code === 1e3 || event?.code === 1001;
|
|
170
|
-
if (!isNormalClosure) {
|
|
171
|
-
logger.info("[ws:queues] client disconnected:", {
|
|
172
|
-
peerId: peer.id,
|
|
173
|
-
code: event?.code,
|
|
174
|
-
reason: event?.reason
|
|
175
|
-
});
|
|
176
|
-
}
|
|
177
|
-
const { unregisterWsPeer } = usePeerManager();
|
|
178
|
-
unregisterWsPeer(peer);
|
|
179
|
-
const context = peerContexts.get(peer);
|
|
180
|
-
if (context) {
|
|
181
|
-
for (const unsub of Array.from(context.subscriptions.values())) {
|
|
182
|
-
try {
|
|
183
|
-
unsub();
|
|
184
|
-
} catch (err) {
|
|
185
|
-
if (!isNormalClosure) {
|
|
186
|
-
logger.error("[ws:queues] error unsubscribing on close:", err);
|
|
187
|
-
}
|
|
188
|
-
}
|
|
189
|
-
}
|
|
190
|
-
context.subscriptions.clear();
|
|
191
|
-
peerContexts.delete(peer);
|
|
192
|
-
}
|
|
193
|
-
},
|
|
194
|
-
error(peer, error) {
|
|
195
|
-
const logger = useNventLogger("api-queues-ws");
|
|
196
|
-
logger.error("[ws:queues] error for peer:", {
|
|
197
|
-
peerId: peer.id,
|
|
198
|
-
error
|
|
199
|
-
});
|
|
200
|
-
const { unregisterWsPeer } = usePeerManager();
|
|
201
|
-
unregisterWsPeer(peer);
|
|
202
|
-
const context = peerContexts.get(peer);
|
|
203
|
-
if (context) {
|
|
204
|
-
for (const unsub of Array.from(context.subscriptions.values())) {
|
|
205
|
-
try {
|
|
206
|
-
unsub();
|
|
207
|
-
} catch (err) {
|
|
208
|
-
logger.error("[ws:queues] error unsubscribing on error:", { error: err });
|
|
209
|
-
}
|
|
210
|
-
}
|
|
211
|
-
context.subscriptions.clear();
|
|
212
|
-
peerContexts.delete(peer);
|
|
213
|
-
}
|
|
214
|
-
}
|
|
215
|
-
});
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Flow Engine for starting and emitting flow events
|
|
3
|
-
*/
|
|
4
|
-
export declare const useFlowEngine: () => {
|
|
5
|
-
startFlow: (flowName: string, payload?: any) => Promise<{
|
|
6
|
-
id: any;
|
|
7
|
-
queue: any;
|
|
8
|
-
step: any;
|
|
9
|
-
flowId: `${string}-${string}-${string}-${string}-${string}`;
|
|
10
|
-
}>;
|
|
11
|
-
emit: (trigger: string, payload?: any) => Promise<never[]>;
|
|
12
|
-
cancelFlow: (flowName: string, runId: string) => Promise<{
|
|
13
|
-
success: boolean;
|
|
14
|
-
runId: string;
|
|
15
|
-
flowName: string;
|
|
16
|
-
}>;
|
|
17
|
-
isRunning: (flowName: string, runId?: string) => Promise<any>;
|
|
18
|
-
getRunningFlows: (flowName: string) => Promise<any>;
|
|
19
|
-
};
|
|
@@ -1,108 +0,0 @@
|
|
|
1
|
-
import { $useQueueRegistry, useQueueAdapter, useEventManager, useNventLogger, useStoreAdapter, useStreamTopics } from "#imports";
|
|
2
|
-
import { randomUUID } from "node:crypto";
|
|
3
|
-
const logger = useNventLogger("flow-engine");
|
|
4
|
-
export const useFlowEngine = () => {
|
|
5
|
-
const registry = $useQueueRegistry();
|
|
6
|
-
const queueAdapter = useQueueAdapter();
|
|
7
|
-
const eventsManager = useEventManager();
|
|
8
|
-
const startFlow = async (flowName, payload = {}) => {
|
|
9
|
-
const flow = registry?.flows?.[flowName];
|
|
10
|
-
if (!flow || !flow.entry) throw new Error("Flow not found");
|
|
11
|
-
const queueName = typeof flow.entry.queue === "string" ? flow.entry.queue : flow.entry.queue?.name || flow.entry.queue;
|
|
12
|
-
const entryWorker = registry?.workers?.find(
|
|
13
|
-
(w) => w?.flow?.step === flow.entry.step && w?.queue?.name === queueName
|
|
14
|
-
);
|
|
15
|
-
const opts = entryWorker?.queue?.defaultJobOptions || {};
|
|
16
|
-
const flowId = randomUUID();
|
|
17
|
-
const id = await queueAdapter.enqueue(queueName, { name: flow.entry.step, data: { ...payload, flowId, flowName }, opts });
|
|
18
|
-
try {
|
|
19
|
-
await eventsManager.publishBus({ type: "flow.start", runId: flowId, flowName, data: { input: payload } });
|
|
20
|
-
} catch {
|
|
21
|
-
}
|
|
22
|
-
return { id, queue: queueName, step: flow.entry.step, flowId };
|
|
23
|
-
};
|
|
24
|
-
const emit = async (trigger, payload = {}) => {
|
|
25
|
-
const flowId = payload?.flowId;
|
|
26
|
-
const flowName = payload?.flowName || "unknown";
|
|
27
|
-
if (!flowId) {
|
|
28
|
-
logger.warn("emit called without flowId, trigger may not work", { trigger });
|
|
29
|
-
}
|
|
30
|
-
const { flowId: _, flowName: __, ...actualPayload } = payload;
|
|
31
|
-
try {
|
|
32
|
-
await eventsManager.publishBus({
|
|
33
|
-
type: "emit",
|
|
34
|
-
runId: flowId || "unknown",
|
|
35
|
-
flowName,
|
|
36
|
-
data: {
|
|
37
|
-
name: trigger,
|
|
38
|
-
payload: actualPayload
|
|
39
|
-
// Store actual payload separately
|
|
40
|
-
}
|
|
41
|
-
});
|
|
42
|
-
} catch (err) {
|
|
43
|
-
logger.error("Failed to emit trigger event", { trigger, error: err });
|
|
44
|
-
}
|
|
45
|
-
return [];
|
|
46
|
-
};
|
|
47
|
-
const cancelFlow = async (flowName, runId) => {
|
|
48
|
-
try {
|
|
49
|
-
await eventsManager.publishBus({
|
|
50
|
-
type: "flow.cancel",
|
|
51
|
-
runId,
|
|
52
|
-
flowName,
|
|
53
|
-
data: {
|
|
54
|
-
canceledAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
55
|
-
}
|
|
56
|
-
});
|
|
57
|
-
logger.info("Flow canceled", { flowName, runId });
|
|
58
|
-
return { success: true, runId, flowName };
|
|
59
|
-
} catch (err) {
|
|
60
|
-
logger.error("Failed to cancel flow", { flowName, runId, error: err });
|
|
61
|
-
throw err;
|
|
62
|
-
}
|
|
63
|
-
};
|
|
64
|
-
const isRunning = async (flowName, runId) => {
|
|
65
|
-
try {
|
|
66
|
-
const store = useStoreAdapter();
|
|
67
|
-
const { SubjectPatterns } = useStreamTopics();
|
|
68
|
-
if (!store.indexRead) {
|
|
69
|
-
return false;
|
|
70
|
-
}
|
|
71
|
-
if (runId) {
|
|
72
|
-
const runIndexKey2 = SubjectPatterns.flowRunIndex(flowName);
|
|
73
|
-
const entries2 = await store.indexRead(runIndexKey2, { limit: 1e3 });
|
|
74
|
-
const run = entries2.find((e) => e.id === runId);
|
|
75
|
-
return run?.metadata?.status === "running";
|
|
76
|
-
}
|
|
77
|
-
const runIndexKey = SubjectPatterns.flowRunIndex(flowName);
|
|
78
|
-
const entries = await store.indexRead(runIndexKey, { limit: 1e3 });
|
|
79
|
-
return entries.some((e) => e.metadata?.status === "running");
|
|
80
|
-
} catch (err) {
|
|
81
|
-
logger.error("[isRunning] Error checking flow status:", err);
|
|
82
|
-
return false;
|
|
83
|
-
}
|
|
84
|
-
};
|
|
85
|
-
const getRunningFlows = async (flowName) => {
|
|
86
|
-
try {
|
|
87
|
-
const store = useStoreAdapter();
|
|
88
|
-
const { SubjectPatterns } = useStreamTopics();
|
|
89
|
-
if (!store.indexRead) {
|
|
90
|
-
return [];
|
|
91
|
-
}
|
|
92
|
-
const runIndexKey = SubjectPatterns.flowRunIndex(flowName);
|
|
93
|
-
const entries = await store.indexRead(runIndexKey, { limit: 1e3 });
|
|
94
|
-
return entries.filter((e) => e.metadata?.status === "running").map((e) => ({
|
|
95
|
-
id: e.id,
|
|
96
|
-
flowName,
|
|
97
|
-
status: e.metadata?.status,
|
|
98
|
-
startedAt: e.metadata?.startedAt,
|
|
99
|
-
stepCount: e.metadata?.stepCount || 0,
|
|
100
|
-
completedSteps: e.metadata?.completedSteps || 0
|
|
101
|
-
}));
|
|
102
|
-
} catch (err) {
|
|
103
|
-
logger.error("[getRunningFlows] Error getting running flows:", err);
|
|
104
|
-
return [];
|
|
105
|
-
}
|
|
106
|
-
};
|
|
107
|
-
return { startFlow, emit, cancelFlow, isRunning, getRunningFlows };
|
|
108
|
-
};
|
|
@@ -1,72 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Stream topic naming utilities
|
|
3
|
-
*
|
|
4
|
-
* Standardized topic patterns for StreamAdapter pub/sub
|
|
5
|
-
* These match the topics published by StoreAdapter mutations and wiring coordinators
|
|
6
|
-
*/
|
|
7
|
-
/**
|
|
8
|
-
* Get topic for store append events
|
|
9
|
-
* Pattern: store:append:{subject}
|
|
10
|
-
* Published when: StoreAdapter.append() adds an event to a subject
|
|
11
|
-
* Used by: StreamCoordinator (store-sync channel)
|
|
12
|
-
*/
|
|
13
|
-
declare function getStoreAppendTopic(subject: string): string;
|
|
14
|
-
/**
|
|
15
|
-
* Get topic for store save events
|
|
16
|
-
* Pattern: store:save:{collection}
|
|
17
|
-
* Published when: StoreAdapter.save() creates/updates a document
|
|
18
|
-
*/
|
|
19
|
-
declare function getStoreSaveTopic(collection: string): string;
|
|
20
|
-
/**
|
|
21
|
-
* Get topic for store delete events
|
|
22
|
-
* Pattern: store:delete:{collection}
|
|
23
|
-
* Published when: StoreAdapter.delete() removes a document
|
|
24
|
-
*/
|
|
25
|
-
declare function getStoreDeleteTopic(collection: string): string;
|
|
26
|
-
/**
|
|
27
|
-
* Get topic for KV store events
|
|
28
|
-
* Pattern: store:kv:{key}
|
|
29
|
-
* Published when: StoreAdapter.kvSet() updates a key
|
|
30
|
-
*/
|
|
31
|
-
declare function getStoreKvTopic(key: string): string;
|
|
32
|
-
/**
|
|
33
|
-
* Get topic for flow orchestration events
|
|
34
|
-
* Pattern: flow:event:{runId}
|
|
35
|
-
* Published when: StreamCoordinator flow-events channel publishes flow lifecycle events
|
|
36
|
-
* Used by: Future trigger system for cross-instance coordination
|
|
37
|
-
*/
|
|
38
|
-
declare function getFlowEventTopic(runId: string): string;
|
|
39
|
-
/**
|
|
40
|
-
* Get topic for client messages (WebSocket/SSE)
|
|
41
|
-
* Pattern: client:flow:{runId}
|
|
42
|
-
* Published when: StreamCoordinator client-messages channel publishes UI updates
|
|
43
|
-
* Used by: WebSocket handler for real-time UI updates
|
|
44
|
-
*/
|
|
45
|
-
declare function getClientFlowTopic(runId: string): string;
|
|
46
|
-
export declare function useStreamTopics(): {
|
|
47
|
-
getStoreAppendTopic: typeof getStoreAppendTopic;
|
|
48
|
-
getStoreSaveTopic: typeof getStoreSaveTopic;
|
|
49
|
-
getStoreDeleteTopic: typeof getStoreDeleteTopic;
|
|
50
|
-
getStoreKvTopic: typeof getStoreKvTopic;
|
|
51
|
-
getFlowEventTopic: typeof getFlowEventTopic;
|
|
52
|
-
getClientFlowTopic: typeof getClientFlowTopic;
|
|
53
|
-
SubjectPatterns: {
|
|
54
|
-
/**
|
|
55
|
-
* Flow run event stream subject
|
|
56
|
-
*/
|
|
57
|
-
readonly flowRun: (runId: string) => string;
|
|
58
|
-
/**
|
|
59
|
-
* Flow run index (sorted set of runs by flow name)
|
|
60
|
-
*/
|
|
61
|
-
readonly flowRunIndex: (flowName: string) => string;
|
|
62
|
-
/**
|
|
63
|
-
* Flow definition subject
|
|
64
|
-
*/
|
|
65
|
-
readonly flowDefinition: (flowName: string) => string;
|
|
66
|
-
/**
|
|
67
|
-
* Worker heartbeat subject
|
|
68
|
-
*/
|
|
69
|
-
readonly workerHeartbeat: (workerId: string) => string;
|
|
70
|
-
};
|
|
71
|
-
};
|
|
72
|
-
export {};
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
function getStoreAppendTopic(subject) {
|
|
2
|
-
return `store:append:${subject}`;
|
|
3
|
-
}
|
|
4
|
-
function getStoreSaveTopic(collection) {
|
|
5
|
-
return `store:save:${collection}`;
|
|
6
|
-
}
|
|
7
|
-
function getStoreDeleteTopic(collection) {
|
|
8
|
-
return `store:delete:${collection}`;
|
|
9
|
-
}
|
|
10
|
-
function getStoreKvTopic(key) {
|
|
11
|
-
return `store:kv:${key}`;
|
|
12
|
-
}
|
|
13
|
-
function getFlowEventTopic(runId) {
|
|
14
|
-
return `flow:event:${runId}`;
|
|
15
|
-
}
|
|
16
|
-
function getClientFlowTopic(runId) {
|
|
17
|
-
return `client:flow:${runId}`;
|
|
18
|
-
}
|
|
19
|
-
const SubjectPatterns = {
|
|
20
|
-
/**
|
|
21
|
-
* Flow run event stream subject
|
|
22
|
-
*/
|
|
23
|
-
flowRun: (runId) => `nq:flow:${runId}`,
|
|
24
|
-
/**
|
|
25
|
-
* Flow run index (sorted set of runs by flow name)
|
|
26
|
-
*/
|
|
27
|
-
flowRunIndex: (flowName) => `nq:flows:${flowName}`,
|
|
28
|
-
/**
|
|
29
|
-
* Flow definition subject
|
|
30
|
-
*/
|
|
31
|
-
flowDefinition: (flowName) => `flow-def:${flowName}`,
|
|
32
|
-
/**
|
|
33
|
-
* Worker heartbeat subject
|
|
34
|
-
*/
|
|
35
|
-
workerHeartbeat: (workerId) => `worker:${workerId}`
|
|
36
|
-
};
|
|
37
|
-
export function useStreamTopics() {
|
|
38
|
-
return {
|
|
39
|
-
getStoreAppendTopic,
|
|
40
|
-
getStoreSaveTopic,
|
|
41
|
-
getStoreDeleteTopic,
|
|
42
|
-
getStoreKvTopic,
|
|
43
|
-
getFlowEventTopic,
|
|
44
|
-
getClientFlowTopic,
|
|
45
|
-
SubjectPatterns
|
|
46
|
-
};
|
|
47
|
-
}
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|