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,8 +1,10 @@
|
|
|
1
1
|
import {
|
|
2
2
|
defineWebSocketHandler,
|
|
3
|
-
useEventStore,
|
|
4
3
|
usePeerManager,
|
|
5
|
-
useNventLogger
|
|
4
|
+
useNventLogger,
|
|
5
|
+
useStreamAdapter,
|
|
6
|
+
useStoreAdapter,
|
|
7
|
+
useStreamTopics
|
|
6
8
|
} from "#imports";
|
|
7
9
|
const peerContexts = /* @__PURE__ */ new WeakMap();
|
|
8
10
|
function safeSend(peer, data) {
|
|
@@ -14,7 +16,7 @@ function safeSend(peer, data) {
|
|
|
14
16
|
}
|
|
15
17
|
}
|
|
16
18
|
export default defineWebSocketHandler({
|
|
17
|
-
open(peer) {
|
|
19
|
+
async open(peer) {
|
|
18
20
|
const logger = useNventLogger("api-flows-ws");
|
|
19
21
|
logger.info("[ws] client connected:", { peerId: peer.id });
|
|
20
22
|
const { registerWsPeer } = usePeerManager();
|
|
@@ -53,19 +55,37 @@ export default defineWebSocketHandler({
|
|
|
53
55
|
});
|
|
54
56
|
return;
|
|
55
57
|
}
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
58
|
+
let stream;
|
|
59
|
+
let store;
|
|
60
|
+
try {
|
|
61
|
+
stream = useStreamAdapter();
|
|
62
|
+
store = useStoreAdapter();
|
|
63
|
+
} catch (err) {
|
|
64
|
+
logger.error("[ws] Adapters not initialized yet:", { error: err });
|
|
65
|
+
safeSend(peer, {
|
|
66
|
+
type: "error",
|
|
67
|
+
message: "Server initializing, please retry"
|
|
68
|
+
});
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
59
71
|
const subscriptionKey = `${flowName}:${runId}`;
|
|
60
|
-
const
|
|
61
|
-
if (
|
|
72
|
+
const existingHandle = context.subscriptions.get(subscriptionKey);
|
|
73
|
+
if (existingHandle) {
|
|
62
74
|
try {
|
|
63
|
-
|
|
75
|
+
await existingHandle.unsubscribe();
|
|
64
76
|
} catch (err) {
|
|
65
77
|
logger.error("[ws] error unsubscribing:", { error: err });
|
|
66
78
|
}
|
|
67
79
|
}
|
|
68
|
-
const
|
|
80
|
+
const { SubjectPatterns, getClientFlowTopic } = useStreamTopics();
|
|
81
|
+
const subject = SubjectPatterns.flowRun(runId);
|
|
82
|
+
const topic = getClientFlowTopic(runId);
|
|
83
|
+
const handle = await stream.subscribe(topic, async (message2) => {
|
|
84
|
+
const event = message2.data?.event;
|
|
85
|
+
if (!event) {
|
|
86
|
+
logger.warn("[ws] Received message without event data:", message2);
|
|
87
|
+
return;
|
|
88
|
+
}
|
|
69
89
|
safeSend(peer, {
|
|
70
90
|
type: "event",
|
|
71
91
|
flowName,
|
|
@@ -77,11 +97,12 @@ export default defineWebSocketHandler({
|
|
|
77
97
|
}
|
|
78
98
|
});
|
|
79
99
|
});
|
|
80
|
-
context.subscriptions.set(subscriptionKey,
|
|
100
|
+
context.subscriptions.set(subscriptionKey, handle);
|
|
81
101
|
try {
|
|
82
|
-
const historicalEvents = await store.read(
|
|
102
|
+
const historicalEvents = await store.read(subject, {
|
|
83
103
|
limit: 100,
|
|
84
|
-
|
|
104
|
+
order: "asc"
|
|
105
|
+
// forward order
|
|
85
106
|
});
|
|
86
107
|
safeSend(peer, {
|
|
87
108
|
type: "history",
|
|
@@ -114,10 +135,10 @@ export default defineWebSocketHandler({
|
|
|
114
135
|
return;
|
|
115
136
|
}
|
|
116
137
|
const subscriptionKey = `${flowName}:${runId}`;
|
|
117
|
-
const
|
|
118
|
-
if (
|
|
138
|
+
const handle = context.subscriptions.get(subscriptionKey);
|
|
139
|
+
if (handle) {
|
|
119
140
|
try {
|
|
120
|
-
|
|
141
|
+
await handle.unsubscribe();
|
|
121
142
|
context.subscriptions.delete(subscriptionKey);
|
|
122
143
|
safeSend(peer, {
|
|
123
144
|
type: "unsubscribed",
|
|
@@ -144,7 +165,7 @@ export default defineWebSocketHandler({
|
|
|
144
165
|
});
|
|
145
166
|
}
|
|
146
167
|
},
|
|
147
|
-
close(peer, event) {
|
|
168
|
+
async close(peer, event) {
|
|
148
169
|
const logger = useNventLogger("api-flows-ws");
|
|
149
170
|
const isNormalClosure = event?.code === 1e3 || event?.code === 1001;
|
|
150
171
|
if (!isNormalClosure) {
|
|
@@ -154,9 +175,9 @@ export default defineWebSocketHandler({
|
|
|
154
175
|
unregisterWsPeer(peer);
|
|
155
176
|
const context = peerContexts.get(peer);
|
|
156
177
|
if (context) {
|
|
157
|
-
for (const
|
|
178
|
+
for (const handle of Array.from(context.subscriptions.values())) {
|
|
158
179
|
try {
|
|
159
|
-
|
|
180
|
+
await handle.unsubscribe();
|
|
160
181
|
} catch (err) {
|
|
161
182
|
if (!isNormalClosure) {
|
|
162
183
|
logger.error("[ws] error unsubscribing on close:", { error: err });
|
|
@@ -167,16 +188,16 @@ export default defineWebSocketHandler({
|
|
|
167
188
|
peerContexts.delete(peer);
|
|
168
189
|
}
|
|
169
190
|
},
|
|
170
|
-
error(peer, error) {
|
|
191
|
+
async error(peer, error) {
|
|
171
192
|
const logger = useNventLogger("api-flows-ws");
|
|
172
193
|
logger.error("[ws] error for peer:", { peerId: peer.id, error });
|
|
173
194
|
const { unregisterWsPeer } = usePeerManager();
|
|
174
195
|
unregisterWsPeer(peer);
|
|
175
196
|
const context = peerContexts.get(peer);
|
|
176
197
|
if (context) {
|
|
177
|
-
for (const
|
|
198
|
+
for (const handle of Array.from(context.subscriptions.values())) {
|
|
178
199
|
try {
|
|
179
|
-
|
|
200
|
+
await handle.unsubscribe();
|
|
180
201
|
} catch (err) {
|
|
181
202
|
logger.error("[ws] error unsubscribing on error:", { error: err });
|
|
182
203
|
}
|
|
@@ -1,9 +1,14 @@
|
|
|
1
|
-
import { defineEventHandler, getRouterParam,
|
|
1
|
+
import { defineEventHandler, getRouterParam, useQueueAdapter } from "#imports";
|
|
2
2
|
export default defineEventHandler(async (event) => {
|
|
3
3
|
const name = getRouterParam(event, "name") || "";
|
|
4
4
|
const id = getRouterParam(event, "id") || "";
|
|
5
|
-
|
|
6
|
-
|
|
5
|
+
let queue;
|
|
6
|
+
try {
|
|
7
|
+
queue = useQueueAdapter();
|
|
8
|
+
} catch {
|
|
9
|
+
return null;
|
|
10
|
+
}
|
|
11
|
+
const job = await queue.getJob(name, id);
|
|
7
12
|
if (!job) return null;
|
|
8
13
|
return { ...job, queue: name };
|
|
9
14
|
});
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { defineEventHandler, getRouterParam, getQuery,
|
|
1
|
+
import { defineEventHandler, getRouterParam, getQuery, useQueueAdapter, createError } from "#imports";
|
|
2
2
|
export default defineEventHandler(async (event) => {
|
|
3
3
|
const name = getRouterParam(event, "name");
|
|
4
4
|
if (!name) {
|
|
@@ -6,8 +6,17 @@ export default defineEventHandler(async (event) => {
|
|
|
6
6
|
}
|
|
7
7
|
const query = getQuery(event);
|
|
8
8
|
const state = query.state;
|
|
9
|
-
|
|
10
|
-
|
|
9
|
+
let queue;
|
|
10
|
+
try {
|
|
11
|
+
queue = useQueueAdapter();
|
|
12
|
+
} catch {
|
|
13
|
+
throw createError({
|
|
14
|
+
statusCode: 503,
|
|
15
|
+
statusMessage: "Server initializing",
|
|
16
|
+
data: "Queue adapter not ready yet, please retry"
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
const jobs = await queue.getJobs(name, {
|
|
11
20
|
state: state ? [state] : void 0,
|
|
12
21
|
limit: 1e3
|
|
13
22
|
// Fetch all jobs, pagination happens client-side
|
|
@@ -1,12 +1,23 @@
|
|
|
1
|
-
import { defineEventHandler, useRuntimeConfig, $useQueueRegistry,
|
|
1
|
+
import { defineEventHandler, useRuntimeConfig, $useQueueRegistry, useQueueAdapter, useNventLogger } from "#imports";
|
|
2
|
+
const logger = useNventLogger("api-queues-index");
|
|
2
3
|
export default defineEventHandler(async () => {
|
|
3
4
|
const rc = useRuntimeConfig();
|
|
4
|
-
const logger = useNventLogger("api-queues-index");
|
|
5
|
-
const cfgQueues = rc?.queue?.queues || {};
|
|
6
5
|
const registry = $useQueueRegistry();
|
|
7
|
-
|
|
6
|
+
let queue;
|
|
7
|
+
try {
|
|
8
|
+
queue = useQueueAdapter();
|
|
9
|
+
} catch (err) {
|
|
10
|
+
logger.error("[queues/index] Adapters not initialized yet:", { error: err });
|
|
11
|
+
return [];
|
|
12
|
+
}
|
|
13
|
+
const globalQueueConfig = rc?.nvent?.queue || {};
|
|
14
|
+
const globalWorkerDefaults = globalQueueConfig.worker || {};
|
|
15
|
+
const globalQueueDefaults = {
|
|
16
|
+
prefix: globalQueueConfig.prefix,
|
|
17
|
+
defaultJobOptions: globalQueueConfig.defaultJobOptions,
|
|
18
|
+
limiter: globalQueueConfig.limiter
|
|
19
|
+
};
|
|
8
20
|
const names = /* @__PURE__ */ new Set();
|
|
9
|
-
for (const q in cfgQueues) names.add(q);
|
|
10
21
|
if (registry?.workers?.length) {
|
|
11
22
|
for (const w of registry.workers) names.add(w.queue.name);
|
|
12
23
|
}
|
|
@@ -15,27 +26,59 @@ export default defineEventHandler(async () => {
|
|
|
15
26
|
try {
|
|
16
27
|
const counts = await queue.getJobCounts(name);
|
|
17
28
|
const isPaused = await queue.isPaused(name);
|
|
18
|
-
const
|
|
19
|
-
const
|
|
20
|
-
|
|
29
|
+
const workers = registry?.workers?.filter((w) => w.queue.name === name) || [];
|
|
30
|
+
const mergedQueueConfig = workers.reduce((acc, w) => {
|
|
31
|
+
if (!w.queue) return acc;
|
|
32
|
+
const result = {
|
|
33
|
+
...acc,
|
|
34
|
+
name: w.queue.name
|
|
35
|
+
};
|
|
36
|
+
if (w.queue.prefix && w.queue.prefix !== acc.prefix) {
|
|
37
|
+
result.prefix = w.queue.prefix;
|
|
38
|
+
}
|
|
39
|
+
if (w.queue.limiter) {
|
|
40
|
+
result.limiter = w.queue.limiter;
|
|
41
|
+
}
|
|
42
|
+
if (w.queue.defaultJobOptions) {
|
|
43
|
+
result.defaultJobOptions = { ...acc.defaultJobOptions };
|
|
44
|
+
const wOpts = w.queue.defaultJobOptions;
|
|
45
|
+
const accOpts = acc.defaultJobOptions || {};
|
|
46
|
+
if (typeof wOpts.attempts === "number") {
|
|
47
|
+
result.defaultJobOptions.attempts = Math.max(wOpts.attempts, accOpts.attempts || 0);
|
|
48
|
+
}
|
|
49
|
+
if (wOpts.backoff) {
|
|
50
|
+
if (!accOpts.backoff || wOpts.backoff.delay && wOpts.backoff.delay !== globalQueueDefaults.defaultJobOptions?.backoff?.delay) {
|
|
51
|
+
result.defaultJobOptions.backoff = wOpts.backoff;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
if (typeof wOpts.priority === "number") result.defaultJobOptions.priority = wOpts.priority;
|
|
55
|
+
if (typeof wOpts.timeout === "number") result.defaultJobOptions.timeout = wOpts.timeout;
|
|
56
|
+
if (typeof wOpts.delay === "number") result.defaultJobOptions.delay = wOpts.delay;
|
|
57
|
+
if (typeof wOpts.lifo === "boolean") result.defaultJobOptions.lifo = wOpts.lifo;
|
|
58
|
+
if (wOpts.removeOnComplete !== void 0) result.defaultJobOptions.removeOnComplete = wOpts.removeOnComplete;
|
|
59
|
+
if (wOpts.removeOnFail !== void 0) result.defaultJobOptions.removeOnFail = wOpts.removeOnFail;
|
|
60
|
+
}
|
|
61
|
+
return result;
|
|
62
|
+
}, { ...globalQueueDefaults, name });
|
|
63
|
+
const mergedWorkerConfig = workers.reduce((acc, w) => {
|
|
64
|
+
if (!w.worker) return acc;
|
|
65
|
+
return {
|
|
66
|
+
concurrency: Math.max(acc.concurrency || 0, w.worker.concurrency || 0),
|
|
67
|
+
// Use max concurrency
|
|
68
|
+
lockDurationMs: w.worker.lockDurationMs ?? acc.lockDurationMs,
|
|
69
|
+
maxStalledCount: w.worker.maxStalledCount ?? acc.maxStalledCount,
|
|
70
|
+
drainDelayMs: w.worker.drainDelayMs ?? acc.drainDelayMs,
|
|
71
|
+
autorun: w.worker.autorun ?? acc.autorun,
|
|
72
|
+
pollingIntervalMs: w.worker.pollingIntervalMs ?? acc.pollingIntervalMs
|
|
73
|
+
};
|
|
74
|
+
}, { ...globalWorkerDefaults });
|
|
21
75
|
return {
|
|
22
76
|
name,
|
|
23
77
|
counts,
|
|
24
78
|
isPaused,
|
|
25
79
|
config: {
|
|
26
|
-
queue:
|
|
27
|
-
|
|
28
|
-
defaultJobOptions: queueConfig.defaultJobOptions,
|
|
29
|
-
limiter: queueConfig.limiter
|
|
30
|
-
},
|
|
31
|
-
worker: {
|
|
32
|
-
concurrency: workerConfig.concurrency,
|
|
33
|
-
lockDurationMs: workerConfig.lockDurationMs,
|
|
34
|
-
maxStalledCount: workerConfig.maxStalledCount,
|
|
35
|
-
drainDelayMs: workerConfig.drainDelayMs,
|
|
36
|
-
autorun: workerConfig.autorun,
|
|
37
|
-
pollingIntervalMs: workerConfig.pollingIntervalMs
|
|
38
|
-
}
|
|
80
|
+
queue: mergedQueueConfig,
|
|
81
|
+
worker: mergedWorkerConfig
|
|
39
82
|
}
|
|
40
83
|
};
|
|
41
84
|
} catch (err) {
|
|
@@ -52,8 +95,8 @@ export default defineEventHandler(async () => {
|
|
|
52
95
|
},
|
|
53
96
|
isPaused: false,
|
|
54
97
|
config: {
|
|
55
|
-
queue:
|
|
56
|
-
worker:
|
|
98
|
+
queue: globalQueueDefaults,
|
|
99
|
+
worker: globalWorkerDefaults
|
|
57
100
|
}
|
|
58
101
|
};
|
|
59
102
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
defineWebSocketHandler,
|
|
3
|
-
|
|
3
|
+
useQueueAdapter,
|
|
4
4
|
usePeerManager,
|
|
5
5
|
useNventLogger
|
|
6
6
|
} from "#imports";
|
|
@@ -53,7 +53,17 @@ export default defineWebSocketHandler({
|
|
|
53
53
|
});
|
|
54
54
|
return;
|
|
55
55
|
}
|
|
56
|
-
|
|
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
|
+
}
|
|
57
67
|
const existingUnsub = context.subscriptions.get(queueName);
|
|
58
68
|
if (existingUnsub) {
|
|
59
69
|
try {
|
|
@@ -168,7 +178,7 @@ export default defineWebSocketHandler({
|
|
|
168
178
|
unregisterWsPeer(peer);
|
|
169
179
|
const context = peerContexts.get(peer);
|
|
170
180
|
if (context) {
|
|
171
|
-
for (const unsub of context.subscriptions.values()) {
|
|
181
|
+
for (const unsub of Array.from(context.subscriptions.values())) {
|
|
172
182
|
try {
|
|
173
183
|
unsub();
|
|
174
184
|
} catch (err) {
|
|
@@ -191,7 +201,7 @@ export default defineWebSocketHandler({
|
|
|
191
201
|
unregisterWsPeer(peer);
|
|
192
202
|
const context = peerContexts.get(peer);
|
|
193
203
|
if (context) {
|
|
194
|
-
for (const unsub of context.subscriptions.values()) {
|
|
204
|
+
for (const unsub of Array.from(context.subscriptions.values())) {
|
|
195
205
|
try {
|
|
196
206
|
unsub();
|
|
197
207
|
} catch (err) {
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Adapter Initialization Plugin (v0.4.1)
|
|
3
|
+
*
|
|
4
|
+
* Initializes the three-adapter architecture with new config format:
|
|
5
|
+
* - QueueAdapter: Job queue operations (from config.queue)
|
|
6
|
+
* - StreamAdapter: Cross-instance pub/sub messaging (from config.stream)
|
|
7
|
+
* - StoreAdapter: Storage - events, documents, KV, indices (from config.store)
|
|
8
|
+
*
|
|
9
|
+
* Uses normalized config with connection fallback from connections.*
|
|
10
|
+
*
|
|
11
|
+
* External adapters can register themselves via the nvent:registerAdapter Nitro hook
|
|
12
|
+
*/
|
|
13
|
+
declare const _default: any;
|
|
14
|
+
export default _default;
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { defineNitroPlugin, useRuntimeConfig, useNventLogger, setAdapters } from "#imports";
|
|
2
|
+
import { createAdapters, shutdownAdapters } from "../../adapters/factory.js";
|
|
3
|
+
import { useAdapterRegistry } from "../../adapters/registry.js";
|
|
4
|
+
import { createWiringRegistry } from "../../events/wiring/registry.js";
|
|
5
|
+
export default defineNitroPlugin(async (nitroApp) => {
|
|
6
|
+
const logger = useNventLogger("adapters-plugin");
|
|
7
|
+
const runtimeConfig = useRuntimeConfig();
|
|
8
|
+
const config = runtimeConfig.nvent;
|
|
9
|
+
if (!config) {
|
|
10
|
+
logger.error("No nvent config found in runtime config");
|
|
11
|
+
throw new Error("Missing nvent configuration");
|
|
12
|
+
}
|
|
13
|
+
logger.info("Initializing adapters", {
|
|
14
|
+
queue: config.queue?.adapter || "file",
|
|
15
|
+
stream: config.stream?.adapter || "memory",
|
|
16
|
+
store: config.store?.adapter || "file"
|
|
17
|
+
});
|
|
18
|
+
try {
|
|
19
|
+
await nitroApp.hooks.callHook("nvent:register-adapters");
|
|
20
|
+
const registry = useAdapterRegistry();
|
|
21
|
+
logger.info("Checking registered adapters", {
|
|
22
|
+
queueAdapters: registry.listQueueAdapters(),
|
|
23
|
+
streamAdapters: registry.listStreamAdapters(),
|
|
24
|
+
storeAdapters: registry.listStoreAdapters()
|
|
25
|
+
});
|
|
26
|
+
const adapters = await createAdapters({
|
|
27
|
+
queue: config.queue,
|
|
28
|
+
stream: config.stream,
|
|
29
|
+
store: config.store
|
|
30
|
+
});
|
|
31
|
+
setAdapters(adapters);
|
|
32
|
+
logger.info("Adapters initialized successfully", {
|
|
33
|
+
queueAdapter: config.queue.adapter,
|
|
34
|
+
streamAdapter: config.stream.adapter,
|
|
35
|
+
storeAdapter: config.store.adapter
|
|
36
|
+
});
|
|
37
|
+
await nitroApp.hooks.callHook("nvent:adapters:ready");
|
|
38
|
+
const wiring = createWiringRegistry({
|
|
39
|
+
streamWiring: {
|
|
40
|
+
enabled: true
|
|
41
|
+
// Enable for WebSocket support
|
|
42
|
+
},
|
|
43
|
+
stateWiring: {
|
|
44
|
+
// Strategy is read from config by default (queue.store.state.cleanup.strategy)
|
|
45
|
+
// Can be overridden here if needed
|
|
46
|
+
}
|
|
47
|
+
});
|
|
48
|
+
wiring.start();
|
|
49
|
+
logger.info("Flow wiring started");
|
|
50
|
+
return {
|
|
51
|
+
hooks: {
|
|
52
|
+
close: async () => {
|
|
53
|
+
logger.info("Shutting down");
|
|
54
|
+
try {
|
|
55
|
+
wiring.stop();
|
|
56
|
+
logger.info("Flow wiring stopped");
|
|
57
|
+
await shutdownAdapters(adapters);
|
|
58
|
+
logger.info("Adapters shut down successfully");
|
|
59
|
+
} catch (error) {
|
|
60
|
+
logger.error("Error during shutdown", { error });
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
};
|
|
65
|
+
} catch (error) {
|
|
66
|
+
logger.error("Failed to initialize adapters", { error });
|
|
67
|
+
throw error;
|
|
68
|
+
}
|
|
69
|
+
});
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { defineNitroPlugin, $useWorkerHandlers, $useQueueRegistry, useQueueAdapter } from "#imports";
|
|
2
|
+
import { createJobProcessor } from "../../worker/node/runner.js";
|
|
3
|
+
export default defineNitroPlugin(async (nitroApp) => {
|
|
4
|
+
nitroApp.hooks.hook("close", async () => {
|
|
5
|
+
const queueAdapter = useQueueAdapter();
|
|
6
|
+
await queueAdapter.close();
|
|
7
|
+
});
|
|
8
|
+
nitroApp.hooks.hook("nvent:adapters:ready", async () => {
|
|
9
|
+
const queueAdapter = useQueueAdapter();
|
|
10
|
+
try {
|
|
11
|
+
const handlers = $useWorkerHandlers();
|
|
12
|
+
const registry = $useQueueRegistry() || { workers: [] };
|
|
13
|
+
const registeredQueues = /* @__PURE__ */ new Set();
|
|
14
|
+
for (const entry of handlers) {
|
|
15
|
+
const { queue, id, handler } = entry;
|
|
16
|
+
const w = registry.workers.find((rw) => rw?.id === id || rw?.queue?.name === queue && rw?.absPath === entry.absPath);
|
|
17
|
+
let jobName;
|
|
18
|
+
if (w?.flow?.step) {
|
|
19
|
+
jobName = Array.isArray(w.flow.step) ? w.flow.step[0] : w.flow.step;
|
|
20
|
+
} else {
|
|
21
|
+
jobName = id.includes("/") ? id.split("/").pop() : id;
|
|
22
|
+
}
|
|
23
|
+
if (typeof handler === "function") {
|
|
24
|
+
const workerCfg = w && w.worker || {};
|
|
25
|
+
const queueCfg = w && w.queue || {};
|
|
26
|
+
const opts = {};
|
|
27
|
+
if (typeof workerCfg.concurrency === "number") opts.concurrency = workerCfg.concurrency;
|
|
28
|
+
if (typeof workerCfg.autorun === "boolean") opts.autorun = workerCfg.autorun;
|
|
29
|
+
if (queueCfg.defaultJobOptions) opts.defaultJobOptions = queueCfg.defaultJobOptions;
|
|
30
|
+
if (queueCfg.prefix) opts.prefix = queueCfg.prefix;
|
|
31
|
+
if (queueCfg.limiter) opts.limiter = queueCfg.limiter;
|
|
32
|
+
const processor = createJobProcessor(handler, queue);
|
|
33
|
+
queueAdapter.registerWorker(queue, jobName, processor, opts);
|
|
34
|
+
registeredQueues.add(queue);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
if (queueAdapter.startProcessingQueue) {
|
|
38
|
+
for (const queueName of Array.from(registeredQueues)) {
|
|
39
|
+
queueAdapter.startProcessingQueue(queueName);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
} catch {
|
|
43
|
+
}
|
|
44
|
+
});
|
|
45
|
+
});
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import type { QueueAdapter } from '../adapters/interfaces/queue.js';
|
|
2
|
+
import type { StreamAdapter } from '../adapters/interfaces/stream.js';
|
|
3
|
+
import type { StoreAdapter } from '../adapters/interfaces/store.js';
|
|
4
|
+
import type { AdapterSet } from '../adapters/factory.js';
|
|
5
|
+
declare global {
|
|
6
|
+
var __nq_adapters: AdapterSet | undefined;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Set the global adapter set (called by plugin during initialization)
|
|
10
|
+
*/
|
|
11
|
+
export declare function setAdapters(adapters: AdapterSet): void;
|
|
12
|
+
/**
|
|
13
|
+
* Get all adapters (internal use)
|
|
14
|
+
*/
|
|
15
|
+
export declare function getAdapters(): AdapterSet;
|
|
16
|
+
/**
|
|
17
|
+
* Access QueueAdapter for job queue operations
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* const queue = useQueueAdapter()
|
|
21
|
+
* await queue.enqueue('my-queue', { name: 'job', data: {...} })
|
|
22
|
+
*/
|
|
23
|
+
export declare function useQueueAdapter(): QueueAdapter;
|
|
24
|
+
/**
|
|
25
|
+
* Access StreamAdapter for cross-instance pub/sub
|
|
26
|
+
*
|
|
27
|
+
* @example
|
|
28
|
+
* const stream = useStreamAdapter()
|
|
29
|
+
* await stream.subscribe('store:append:*', (event) => {
|
|
30
|
+
* console.log('Remote update:', event)
|
|
31
|
+
* })
|
|
32
|
+
*/
|
|
33
|
+
export declare function useStreamAdapter(): StreamAdapter;
|
|
34
|
+
/**
|
|
35
|
+
* Access StoreAdapter for storage operations
|
|
36
|
+
*
|
|
37
|
+
* @example
|
|
38
|
+
* const store = useStoreAdapter()
|
|
39
|
+
* await store.append('nq:flow:abc-123', { type: 'step.completed', data: {...} })
|
|
40
|
+
* const events = await store.read('nq:flow:abc-123')
|
|
41
|
+
*/
|
|
42
|
+
export declare function useStoreAdapter(): StoreAdapter;
|
|
43
|
+
/**
|
|
44
|
+
* State provider interface for flow state management
|
|
45
|
+
*/
|
|
46
|
+
export interface StateAdapter {
|
|
47
|
+
get<T = any>(key: string): Promise<T | null>;
|
|
48
|
+
set<T = any>(key: string, value: T, opts?: {
|
|
49
|
+
ttl?: number;
|
|
50
|
+
}): Promise<void>;
|
|
51
|
+
delete(key: string): Promise<void>;
|
|
52
|
+
clear(pattern: string): Promise<number>;
|
|
53
|
+
increment?: (key: string, by?: number) => Promise<number>;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Access StateAdapter for scoped key-value state storage
|
|
57
|
+
*
|
|
58
|
+
* State is backed by StoreAdapter's KV store with automatic namespacing.
|
|
59
|
+
* Used by worker context (ctx.state) for flow-scoped state management.
|
|
60
|
+
*
|
|
61
|
+
* @example
|
|
62
|
+
* const state = useStateAdapter()
|
|
63
|
+
* await state.set('lastEmail', { to: 'user@example.com' })
|
|
64
|
+
* const value = await state.get('lastEmail')
|
|
65
|
+
*/
|
|
66
|
+
export declare function useStateAdapter(): StateAdapter;
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { useRuntimeConfig } from "#imports";
|
|
2
|
+
export function setAdapters(adapters) {
|
|
3
|
+
globalThis.__nq_adapters = adapters;
|
|
4
|
+
}
|
|
5
|
+
export function getAdapters() {
|
|
6
|
+
if (!globalThis.__nq_adapters) {
|
|
7
|
+
throw new Error("[nvent] Adapters not initialized. Make sure the nvent plugin is loaded.");
|
|
8
|
+
}
|
|
9
|
+
return globalThis.__nq_adapters;
|
|
10
|
+
}
|
|
11
|
+
export function useQueueAdapter() {
|
|
12
|
+
return getAdapters().queue;
|
|
13
|
+
}
|
|
14
|
+
export function useStreamAdapter() {
|
|
15
|
+
return getAdapters().stream;
|
|
16
|
+
}
|
|
17
|
+
export function useStoreAdapter() {
|
|
18
|
+
return getAdapters().store;
|
|
19
|
+
}
|
|
20
|
+
export function useStateAdapter() {
|
|
21
|
+
const store = useStoreAdapter();
|
|
22
|
+
let namespace = "nq";
|
|
23
|
+
try {
|
|
24
|
+
const rc = useRuntimeConfig();
|
|
25
|
+
namespace = rc?.nvent?.state?.namespace || "nq";
|
|
26
|
+
} catch {
|
|
27
|
+
}
|
|
28
|
+
return {
|
|
29
|
+
async get(key) {
|
|
30
|
+
return store.kv.get(`${namespace}:${key}`);
|
|
31
|
+
},
|
|
32
|
+
async set(key, value, opts) {
|
|
33
|
+
await store.kv.set(`${namespace}:${key}`, value, opts?.ttl);
|
|
34
|
+
},
|
|
35
|
+
async delete(key) {
|
|
36
|
+
await store.kv.delete(`${namespace}:${key}`);
|
|
37
|
+
},
|
|
38
|
+
async clear(pattern) {
|
|
39
|
+
if (!store.kv.clear) {
|
|
40
|
+
throw new Error("Store adapter does not support clear operation");
|
|
41
|
+
}
|
|
42
|
+
return store.kv.clear(`${namespace}:${pattern}`);
|
|
43
|
+
},
|
|
44
|
+
increment: store.kv.increment ? async (key, by = 1) => {
|
|
45
|
+
if (!store.kv.increment) {
|
|
46
|
+
throw new Error("Store adapter does not support increment operation");
|
|
47
|
+
}
|
|
48
|
+
return store.kv.increment(`${namespace}:${key}`, by);
|
|
49
|
+
} : void 0
|
|
50
|
+
};
|
|
51
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { useFlowEngine, useQueueAdapter } from '#imports';
|
|
2
|
+
import type { RunContext, NodeHandler } from '../worker/node/runner.js';
|
|
3
|
+
export type ExtendedRunContext = RunContext & {
|
|
4
|
+
provider: ReturnType<typeof useQueueAdapter>;
|
|
5
|
+
flow: ReturnType<typeof useFlowEngine>;
|
|
6
|
+
registry: any;
|
|
7
|
+
};
|
|
8
|
+
export type DefineFunction = (handler: (input: any, ctx: ExtendedRunContext) => Promise<any>) => NodeHandler;
|
|
9
|
+
export declare const defineFunction: DefineFunction;
|
|
10
|
+
export default defineFunction;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { $useQueueRegistry, useFlowEngine,
|
|
2
|
-
export const
|
|
1
|
+
import { $useQueueRegistry, useFlowEngine, useQueueAdapter } from "#imports";
|
|
2
|
+
export const defineFunction = (handler) => {
|
|
3
3
|
const wrapped = async (input, ctx) => {
|
|
4
|
-
const provider =
|
|
4
|
+
const provider = useQueueAdapter();
|
|
5
5
|
const flow = ctx.flow || useFlowEngine();
|
|
6
6
|
const registry = $useQueueRegistry();
|
|
7
7
|
const extended = {
|
|
@@ -14,4 +14,4 @@ export const defineQueueWorker = (handler) => {
|
|
|
14
14
|
};
|
|
15
15
|
return wrapped;
|
|
16
16
|
};
|
|
17
|
-
export default
|
|
17
|
+
export default defineFunction;
|
package/dist/runtime/{server-utils/utils/defineQueueConfig.d.ts → utils/defineFunctionConfig.d.ts}
RENAMED
|
@@ -149,6 +149,6 @@ export interface QueueWorkerConfig {
|
|
|
149
149
|
flow?: FlowConfig;
|
|
150
150
|
worker?: WorkerConfig;
|
|
151
151
|
}
|
|
152
|
-
export type
|
|
153
|
-
export declare const
|
|
154
|
-
export default
|
|
152
|
+
export type DefineFunctionConfig = <T extends QueueWorkerConfig>(cfg: T) => T;
|
|
153
|
+
export declare const defineFunctionConfig: DefineFunctionConfig;
|
|
154
|
+
export default defineFunctionConfig;
|