nvent 0.5.15 → 1.0.0-alpha.2
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 +181 -8
- package/dist/module.json +1 -1
- package/dist/module.mjs +1257 -1196
- package/dist/runtime/app/composables/useFunctionCall.d.ts +17 -0
- package/dist/runtime/app/composables/useFunctionCall.js +25 -0
- package/dist/runtime/app/composables/useNventStream.d.ts +23 -0
- package/dist/runtime/app/composables/useNventStream.js +58 -0
- package/dist/runtime/nitro/plugins/00.iii-lifecycle.d.ts +19 -0
- package/dist/runtime/nitro/plugins/00.iii-lifecycle.js +62 -0
- package/dist/runtime/nitro/plugins/01.iii-worker.d.ts +15 -0
- package/dist/runtime/nitro/plugins/01.iii-worker.js +91 -0
- package/dist/runtime/nitro/routes/stream-proxy.d.ts +17 -0
- package/dist/runtime/nitro/routes/stream-proxy.js +45 -0
- package/dist/runtime/nitro/utils/console.d.ts +32 -0
- package/dist/runtime/nitro/utils/console.js +95 -0
- package/dist/runtime/nitro/utils/defineFunction.d.ts +378 -3
- package/dist/runtime/nitro/utils/defineFunction.js +224 -4
- package/dist/runtime/nitro/utils/engine.d.ts +25 -0
- package/dist/runtime/nitro/utils/engine.js +130 -0
- package/dist/runtime/nitro/utils/nventDir.d.ts +1 -0
- package/dist/runtime/nitro/utils/nventDir.js +20 -0
- package/dist/runtime/nitro/utils/useIii.d.ts +23 -0
- package/dist/runtime/nitro/utils/useIii.js +14 -0
- package/dist/runtime/nitro/utils/workers/node.d.ts +24 -0
- package/dist/runtime/nitro/utils/workers/node.js +57 -0
- package/dist/runtime/nitro/utils/workers/python.d.ts +67 -0
- package/dist/runtime/nitro/utils/workers/python.js +220 -0
- package/dist/runtime/python/nvent.py +208 -0
- package/dist/runtime/python/worker_runtime.py +659 -0
- package/dist/runtime/virtual.d.ts +17 -0
- package/dist/types.d.mts +5 -1
- package/package.json +11 -14
- package/dist/runtime/adapters/base/index.d.ts +0 -6
- package/dist/runtime/adapters/base/index.js +0 -1
- package/dist/runtime/adapters/base/store-validator.d.ts +0 -48
- package/dist/runtime/adapters/base/store-validator.js +0 -147
- package/dist/runtime/adapters/builtin/file-queue.d.ts +0 -67
- package/dist/runtime/adapters/builtin/file-queue.js +0 -499
- package/dist/runtime/adapters/builtin/file-store.d.ts +0 -32
- package/dist/runtime/adapters/builtin/file-store.js +0 -206
- package/dist/runtime/adapters/builtin/file-stream.d.ts +0 -39
- package/dist/runtime/adapters/builtin/file-stream.js +0 -56
- package/dist/runtime/adapters/builtin/index.d.ts +0 -10
- package/dist/runtime/adapters/builtin/index.js +0 -5
- package/dist/runtime/adapters/builtin/memory-queue.d.ts +0 -52
- package/dist/runtime/adapters/builtin/memory-queue.js +0 -243
- package/dist/runtime/adapters/builtin/memory-store.d.ts +0 -69
- package/dist/runtime/adapters/builtin/memory-store.js +0 -357
- package/dist/runtime/adapters/builtin/memory-stream.d.ts +0 -21
- package/dist/runtime/adapters/builtin/memory-stream.js +0 -56
- package/dist/runtime/adapters/factory.d.ts +0 -31
- package/dist/runtime/adapters/factory.js +0 -135
- package/dist/runtime/adapters/index.d.ts +0 -8
- package/dist/runtime/adapters/index.js +0 -3
- package/dist/runtime/adapters/interfaces/index.d.ts +0 -11
- package/dist/runtime/adapters/interfaces/index.js +0 -3
- package/dist/runtime/adapters/interfaces/queue.d.ts +0 -155
- package/dist/runtime/adapters/interfaces/queue.js +0 -0
- package/dist/runtime/adapters/interfaces/store.d.ts +0 -299
- package/dist/runtime/adapters/interfaces/store.js +0 -0
- package/dist/runtime/adapters/interfaces/stream.d.ts +0 -62
- package/dist/runtime/adapters/interfaces/stream.js +0 -0
- package/dist/runtime/adapters/registry.d.ts +0 -85
- package/dist/runtime/adapters/registry.js +0 -161
- package/dist/runtime/config/index.d.ts +0 -23
- package/dist/runtime/config/index.js +0 -200
- package/dist/runtime/config/types.d.ts +0 -439
- package/dist/runtime/config/types.js +0 -0
- package/dist/runtime/events/eventBus.d.ts +0 -20
- package/dist/runtime/events/eventBus.js +0 -35
- package/dist/runtime/events/types.d.ts +0 -144
- package/dist/runtime/events/types.js +0 -0
- package/dist/runtime/events/utils/scheduleTrigger.d.ts +0 -8
- package/dist/runtime/events/utils/scheduleTrigger.js +0 -71
- package/dist/runtime/events/utils/stallDetector.d.ts +0 -83
- package/dist/runtime/events/utils/stallDetector.js +0 -318
- package/dist/runtime/events/utils/triggerRuntime.d.ts +0 -58
- package/dist/runtime/events/utils/triggerRuntime.js +0 -212
- package/dist/runtime/events/wiring/flowWiring.d.ts +0 -34
- package/dist/runtime/events/wiring/flowWiring.js +0 -1258
- package/dist/runtime/events/wiring/registry.d.ts +0 -19
- package/dist/runtime/events/wiring/registry.js +0 -43
- package/dist/runtime/events/wiring/stateWiring.d.ts +0 -37
- package/dist/runtime/events/wiring/stateWiring.js +0 -92
- package/dist/runtime/events/wiring/streamWiring.d.ts +0 -36
- package/dist/runtime/events/wiring/streamWiring.js +0 -156
- package/dist/runtime/events/wiring/triggerWiring.d.ts +0 -21
- package/dist/runtime/events/wiring/triggerWiring.js +0 -422
- package/dist/runtime/nitro/plugins/00.adapters.d.ts +0 -14
- package/dist/runtime/nitro/plugins/00.adapters.js +0 -73
- package/dist/runtime/nitro/plugins/01.ws-lifecycle.d.ts +0 -5
- package/dist/runtime/nitro/plugins/01.ws-lifecycle.js +0 -69
- package/dist/runtime/nitro/plugins/02.workers.d.ts +0 -2
- package/dist/runtime/nitro/plugins/02.workers.js +0 -92
- package/dist/runtime/nitro/plugins/03.triggers.d.ts +0 -12
- package/dist/runtime/nitro/plugins/03.triggers.js +0 -55
- package/dist/runtime/nitro/routes/webhook.await.d.ts +0 -23
- package/dist/runtime/nitro/routes/webhook.await.js +0 -112
- package/dist/runtime/nitro/routes/webhook.trigger.d.ts +0 -86
- package/dist/runtime/nitro/routes/webhook.trigger.js +0 -73
- package/dist/runtime/nitro/utils/adapters.d.ts +0 -66
- package/dist/runtime/nitro/utils/adapters.js +0 -51
- package/dist/runtime/nitro/utils/awaitPatterns/event.d.ts +0 -15
- package/dist/runtime/nitro/utils/awaitPatterns/event.js +0 -128
- package/dist/runtime/nitro/utils/awaitPatterns/index.d.ts +0 -28
- package/dist/runtime/nitro/utils/awaitPatterns/index.js +0 -55
- package/dist/runtime/nitro/utils/awaitPatterns/schedule.d.ts +0 -16
- package/dist/runtime/nitro/utils/awaitPatterns/schedule.js +0 -83
- package/dist/runtime/nitro/utils/awaitPatterns/time.d.ts +0 -15
- package/dist/runtime/nitro/utils/awaitPatterns/time.js +0 -71
- package/dist/runtime/nitro/utils/awaitPatterns/webhook.d.ts +0 -15
- package/dist/runtime/nitro/utils/awaitPatterns/webhook.js +0 -128
- package/dist/runtime/nitro/utils/defineFunctionConfig.d.ts +0 -378
- package/dist/runtime/nitro/utils/defineFunctionConfig.js +0 -3
- package/dist/runtime/nitro/utils/defineHooks.d.ts +0 -95
- package/dist/runtime/nitro/utils/defineHooks.js +0 -9
- package/dist/runtime/nitro/utils/registerAdapter.d.ts +0 -59
- package/dist/runtime/nitro/utils/registerAdapter.js +0 -13
- package/dist/runtime/nitro/utils/useAwait.d.ts +0 -83
- package/dist/runtime/nitro/utils/useAwait.js +0 -169
- package/dist/runtime/nitro/utils/useEventManager.d.ts +0 -15
- package/dist/runtime/nitro/utils/useEventManager.js +0 -26
- package/dist/runtime/nitro/utils/useFlow.d.ts +0 -66
- package/dist/runtime/nitro/utils/useFlow.js +0 -310
- package/dist/runtime/nitro/utils/useHookRegistry.d.ts +0 -40
- package/dist/runtime/nitro/utils/useHookRegistry.js +0 -25
- package/dist/runtime/nitro/utils/useNventLogger.d.ts +0 -42
- package/dist/runtime/nitro/utils/useNventLogger.js +0 -54
- package/dist/runtime/nitro/utils/useRunContext.d.ts +0 -6
- package/dist/runtime/nitro/utils/useRunContext.js +0 -102
- package/dist/runtime/nitro/utils/useStreamTopics.d.ts +0 -83
- package/dist/runtime/nitro/utils/useStreamTopics.js +0 -94
- package/dist/runtime/nitro/utils/useTrigger.d.ts +0 -150
- package/dist/runtime/nitro/utils/useTrigger.js +0 -311
- package/dist/runtime/nitro/utils/wsPeerManager.d.ts +0 -44
- package/dist/runtime/nitro/utils/wsPeerManager.js +0 -32
- package/dist/runtime/scheduler/index.d.ts +0 -33
- package/dist/runtime/scheduler/index.js +0 -42
- package/dist/runtime/scheduler/scheduler.d.ts +0 -132
- package/dist/runtime/scheduler/scheduler.js +0 -799
- package/dist/runtime/scheduler/types.d.ts +0 -122
- package/dist/runtime/scheduler/types.js +0 -0
- package/dist/runtime/worker/node/runner.d.ts +0 -95
- package/dist/runtime/worker/node/runner.js +0 -272
- package/dist/runtime/worker/python/get_config.py +0 -64
- package/dist/runtime/worker/system/awaitHandlers.d.ts +0 -27
- package/dist/runtime/worker/system/awaitHandlers.js +0 -230
- package/dist/runtime/worker/system/index.d.ts +0 -24
- package/dist/runtime/worker/system/index.js +0 -39
|
@@ -1,422 +0,0 @@
|
|
|
1
|
-
import { getEventBus } from "../eventBus.js";
|
|
2
|
-
import { useTrigger, useNventLogger, useStoreAdapter, useQueueAdapter, $useAnalyzedFlows, $useFunctionRegistry, useStreamTopics } from "#imports";
|
|
3
|
-
import { getTriggerRuntime } from "../utils/triggerRuntime.js";
|
|
4
|
-
import { scheduleTrigger, unscheduleTrigger } from "../utils/scheduleTrigger.js";
|
|
5
|
-
export function createTriggerWiring() {
|
|
6
|
-
const unsubs = [];
|
|
7
|
-
let wired = false;
|
|
8
|
-
async function start() {
|
|
9
|
-
if (wired) return;
|
|
10
|
-
wired = true;
|
|
11
|
-
const logger = useNventLogger("trigger-wiring");
|
|
12
|
-
const eventBus = getEventBus();
|
|
13
|
-
const trigger = useTrigger();
|
|
14
|
-
const store = useStoreAdapter();
|
|
15
|
-
const { StoreSubjects } = useStreamTopics();
|
|
16
|
-
const runtime = getTriggerRuntime(store, logger);
|
|
17
|
-
await trigger.initialize();
|
|
18
|
-
logger.info("Setting up trigger event wiring");
|
|
19
|
-
const handlePersistence = async (e) => {
|
|
20
|
-
try {
|
|
21
|
-
if (e.id && e.ts) {
|
|
22
|
-
return;
|
|
23
|
-
}
|
|
24
|
-
const triggerName = e.triggerName || e.data?.triggerName;
|
|
25
|
-
if (!triggerName) {
|
|
26
|
-
return;
|
|
27
|
-
}
|
|
28
|
-
const streamName = StoreSubjects.triggerStream(triggerName);
|
|
29
|
-
if (!e.type) {
|
|
30
|
-
logger.error("Event missing type field", { event: e });
|
|
31
|
-
return;
|
|
32
|
-
}
|
|
33
|
-
const eventData = {
|
|
34
|
-
type: e.type,
|
|
35
|
-
triggerName,
|
|
36
|
-
data: e.data
|
|
37
|
-
};
|
|
38
|
-
const persistedEvent = await store.stream.append(streamName, eventData);
|
|
39
|
-
await eventBus.publish(persistedEvent);
|
|
40
|
-
logger.debug("Stored trigger event", {
|
|
41
|
-
type: e.type,
|
|
42
|
-
triggerName,
|
|
43
|
-
id: persistedEvent.id
|
|
44
|
-
});
|
|
45
|
-
} catch (err) {
|
|
46
|
-
logger.error("ERROR persisting trigger event", {
|
|
47
|
-
type: e.type,
|
|
48
|
-
triggerName: e.triggerName,
|
|
49
|
-
error: err?.message
|
|
50
|
-
});
|
|
51
|
-
}
|
|
52
|
-
};
|
|
53
|
-
const handleOrchestration = async (e) => {
|
|
54
|
-
try {
|
|
55
|
-
if (e.id && e.ts) {
|
|
56
|
-
return;
|
|
57
|
-
}
|
|
58
|
-
const triggerName = e.triggerName || e.data?.triggerName;
|
|
59
|
-
if (!triggerName) {
|
|
60
|
-
logger.debug("Orchestration skipped - no triggerName", { type: e.type });
|
|
61
|
-
return;
|
|
62
|
-
}
|
|
63
|
-
logger.debug("Processing trigger orchestration", { type: e.type, triggerName });
|
|
64
|
-
const indexKey = StoreSubjects.triggerIndex();
|
|
65
|
-
const now = (/* @__PURE__ */ new Date()).toISOString();
|
|
66
|
-
const nowTimestamp = Date.now();
|
|
67
|
-
if (e.type === "trigger.registered") {
|
|
68
|
-
const data = e.data;
|
|
69
|
-
if (store.index.add) {
|
|
70
|
-
await store.index.add(indexKey, triggerName, nowTimestamp, {
|
|
71
|
-
"name": data.name,
|
|
72
|
-
"type": data.type,
|
|
73
|
-
"scope": data.scope,
|
|
74
|
-
"status": "active",
|
|
75
|
-
"displayName": data.displayName,
|
|
76
|
-
"description": data.description,
|
|
77
|
-
"source": data.source || "programmatic",
|
|
78
|
-
"registeredAt": now,
|
|
79
|
-
"registeredBy": "runtime",
|
|
80
|
-
"lastActivityAt": now,
|
|
81
|
-
"stats.totalFires": 0,
|
|
82
|
-
"stats.totalFlowsStarted": 0,
|
|
83
|
-
"stats.activeSubscribers": 0,
|
|
84
|
-
"webhook": data.webhook,
|
|
85
|
-
"schedule": data.schedule,
|
|
86
|
-
"config": data.config,
|
|
87
|
-
"version": 1
|
|
88
|
-
});
|
|
89
|
-
}
|
|
90
|
-
const entry = {
|
|
91
|
-
name: data.name,
|
|
92
|
-
type: data.type,
|
|
93
|
-
scope: data.scope,
|
|
94
|
-
status: "active",
|
|
95
|
-
displayName: data.displayName,
|
|
96
|
-
description: data.description,
|
|
97
|
-
source: data.source || "programmatic",
|
|
98
|
-
registeredAt: now,
|
|
99
|
-
registeredBy: "runtime",
|
|
100
|
-
lastActivityAt: now,
|
|
101
|
-
subscriptions: {},
|
|
102
|
-
stats: { totalFires: 0, totalFlowsStarted: 0, activeSubscribers: 0 },
|
|
103
|
-
webhook: data.webhook,
|
|
104
|
-
schedule: data.schedule,
|
|
105
|
-
config: data.config,
|
|
106
|
-
version: 1
|
|
107
|
-
};
|
|
108
|
-
runtime.addTrigger(triggerName, entry);
|
|
109
|
-
logger.info("Registered trigger in index", { triggerName });
|
|
110
|
-
if (data.type === "schedule" && data.schedule) {
|
|
111
|
-
await scheduleTrigger(triggerName, data.schedule, data.status || "active");
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
if (e.type === "trigger.updated") {
|
|
115
|
-
const data = e.data;
|
|
116
|
-
if (store.index.updateWithRetry) {
|
|
117
|
-
await store.index.updateWithRetry(indexKey, triggerName, {
|
|
118
|
-
type: data.type,
|
|
119
|
-
scope: data.scope,
|
|
120
|
-
status: data.status,
|
|
121
|
-
displayName: data.displayName,
|
|
122
|
-
description: data.description,
|
|
123
|
-
webhook: data.webhook,
|
|
124
|
-
schedule: data.schedule,
|
|
125
|
-
config: data.config,
|
|
126
|
-
lastActivityAt: now
|
|
127
|
-
});
|
|
128
|
-
}
|
|
129
|
-
const existing = runtime.getTrigger(triggerName);
|
|
130
|
-
if (existing) {
|
|
131
|
-
const updated = {
|
|
132
|
-
...existing,
|
|
133
|
-
status: data.status !== void 0 ? data.status : existing.status,
|
|
134
|
-
displayName: data.displayName !== void 0 ? data.displayName : existing.displayName,
|
|
135
|
-
description: data.description !== void 0 ? data.description : existing.description,
|
|
136
|
-
webhook: data.webhook !== void 0 ? data.webhook : existing.webhook,
|
|
137
|
-
schedule: data.schedule !== void 0 ? data.schedule : existing.schedule,
|
|
138
|
-
config: data.config !== void 0 ? data.config : existing.config,
|
|
139
|
-
lastActivityAt: now
|
|
140
|
-
};
|
|
141
|
-
runtime.addTrigger(triggerName, updated);
|
|
142
|
-
if (updated.type === "schedule" && updated.schedule) {
|
|
143
|
-
await scheduleTrigger(triggerName, updated.schedule, updated.status);
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
logger.info("Updated trigger in index and runtime", { triggerName, status: data.status });
|
|
147
|
-
}
|
|
148
|
-
if (e.type === "subscription.added") {
|
|
149
|
-
const data = e.data;
|
|
150
|
-
const { flow, mode } = data;
|
|
151
|
-
const existingSub = runtime.getSubscription(triggerName, flow);
|
|
152
|
-
if (store.index.updateWithRetry) {
|
|
153
|
-
await store.index.updateWithRetry(indexKey, triggerName, {
|
|
154
|
-
subscriptions: {
|
|
155
|
-
[flow]: {
|
|
156
|
-
mode,
|
|
157
|
-
subscribedAt: existingSub ? existingSub.registeredAt || now : now
|
|
158
|
-
}
|
|
159
|
-
},
|
|
160
|
-
lastActivityAt: now
|
|
161
|
-
});
|
|
162
|
-
if (!existingSub && store.index.increment) {
|
|
163
|
-
await store.index.increment(indexKey, triggerName, "stats.activeSubscribers", 1);
|
|
164
|
-
}
|
|
165
|
-
}
|
|
166
|
-
const subscription = {
|
|
167
|
-
triggerName,
|
|
168
|
-
flowName: flow,
|
|
169
|
-
mode,
|
|
170
|
-
source: "programmatic",
|
|
171
|
-
registeredAt: existingSub?.registeredAt || now
|
|
172
|
-
};
|
|
173
|
-
runtime.addSubscription(triggerName, flow, subscription);
|
|
174
|
-
logger.info(`Subscription ${existingSub ? "updated" : "added"}`, { triggerName, flow, mode });
|
|
175
|
-
}
|
|
176
|
-
if (e.type === "subscription.removed") {
|
|
177
|
-
const data = e.data;
|
|
178
|
-
const { flow } = data;
|
|
179
|
-
if (store.index.updateWithRetry) {
|
|
180
|
-
await store.index.updateWithRetry(indexKey, triggerName, {
|
|
181
|
-
subscriptions: {
|
|
182
|
-
[flow]: null
|
|
183
|
-
// null removes the field
|
|
184
|
-
},
|
|
185
|
-
lastActivityAt: now
|
|
186
|
-
});
|
|
187
|
-
if (store.index.increment) {
|
|
188
|
-
await store.index.increment(indexKey, triggerName, "stats.activeSubscribers", -1);
|
|
189
|
-
}
|
|
190
|
-
}
|
|
191
|
-
runtime.removeSubscription(triggerName, flow);
|
|
192
|
-
logger.info("Subscription removed", { triggerName, flow });
|
|
193
|
-
}
|
|
194
|
-
if (e.type === "trigger.fired") {
|
|
195
|
-
const flowsStarted = await handleTriggerFired(e);
|
|
196
|
-
if (flowsStarted.length > 0 && store.index.increment) {
|
|
197
|
-
await store.index.increment(indexKey, triggerName, "stats.totalFlowsStarted", flowsStarted.length);
|
|
198
|
-
}
|
|
199
|
-
logger.debug("Trigger fired and processed", { triggerName, flowsStarted: flowsStarted.length });
|
|
200
|
-
}
|
|
201
|
-
if (e.type === "trigger.deleted") {
|
|
202
|
-
const triggerEntry = runtime.getTrigger(triggerName);
|
|
203
|
-
const wasScheduleTrigger = triggerEntry?.type === "schedule";
|
|
204
|
-
if (store.index.delete) {
|
|
205
|
-
await store.index.delete(indexKey, triggerName);
|
|
206
|
-
}
|
|
207
|
-
const triggerStreamKey = StoreSubjects.triggerStream(triggerName);
|
|
208
|
-
if (store.stream.delete) {
|
|
209
|
-
await store.stream.delete(triggerStreamKey);
|
|
210
|
-
}
|
|
211
|
-
runtime.removeTrigger(triggerName);
|
|
212
|
-
if (wasScheduleTrigger) {
|
|
213
|
-
await unscheduleTrigger(triggerName);
|
|
214
|
-
}
|
|
215
|
-
logger.info("Trigger deleted completely", { triggerName });
|
|
216
|
-
}
|
|
217
|
-
} catch (err) {
|
|
218
|
-
logger.error("ERROR in trigger orchestration", {
|
|
219
|
-
type: e.type,
|
|
220
|
-
triggerName: e.triggerName,
|
|
221
|
-
error: err?.message,
|
|
222
|
-
stack: err?.stack
|
|
223
|
-
});
|
|
224
|
-
}
|
|
225
|
-
};
|
|
226
|
-
const handleTriggerStats = async (e) => {
|
|
227
|
-
try {
|
|
228
|
-
if (!e.id || !e.ts) {
|
|
229
|
-
return;
|
|
230
|
-
}
|
|
231
|
-
const triggerName = e.triggerName || e.data?.triggerName;
|
|
232
|
-
if (!triggerName) return;
|
|
233
|
-
const indexKey = StoreSubjects.triggerIndex();
|
|
234
|
-
const now = (/* @__PURE__ */ new Date()).toISOString();
|
|
235
|
-
if (e.type === "trigger.fired") {
|
|
236
|
-
if (store.index.updateWithRetry) {
|
|
237
|
-
await store.index.updateWithRetry(indexKey, triggerName, {
|
|
238
|
-
stats: {
|
|
239
|
-
lastFiredAt: now
|
|
240
|
-
},
|
|
241
|
-
lastActivityAt: now
|
|
242
|
-
});
|
|
243
|
-
}
|
|
244
|
-
if (store.index.increment) {
|
|
245
|
-
await store.index.increment(indexKey, triggerName, "stats.totalFires", 1);
|
|
246
|
-
}
|
|
247
|
-
logger.debug("Updated trigger stats for fire", { triggerName });
|
|
248
|
-
}
|
|
249
|
-
try {
|
|
250
|
-
if (store.index.get) {
|
|
251
|
-
const indexEntry = await store.index.get(indexKey, triggerName);
|
|
252
|
-
if (indexEntry) {
|
|
253
|
-
await eventBus.publish({
|
|
254
|
-
type: "trigger.stats.updated",
|
|
255
|
-
triggerName,
|
|
256
|
-
id: indexEntry.id,
|
|
257
|
-
metadata: indexEntry.metadata,
|
|
258
|
-
ts: Date.now()
|
|
259
|
-
});
|
|
260
|
-
logger.debug("Published trigger stats update event to bus", { triggerName });
|
|
261
|
-
}
|
|
262
|
-
}
|
|
263
|
-
} catch (err) {
|
|
264
|
-
logger.warn("Failed to publish trigger stats update event", {
|
|
265
|
-
triggerName,
|
|
266
|
-
error: err?.message
|
|
267
|
-
});
|
|
268
|
-
}
|
|
269
|
-
} catch (err) {
|
|
270
|
-
logger.warn("Failed to update trigger stats", {
|
|
271
|
-
type: e.type,
|
|
272
|
-
triggerName: e.triggerName,
|
|
273
|
-
error: err?.message
|
|
274
|
-
});
|
|
275
|
-
}
|
|
276
|
-
};
|
|
277
|
-
const eventTypes = [
|
|
278
|
-
"trigger.registered",
|
|
279
|
-
"trigger.updated",
|
|
280
|
-
"trigger.deleted",
|
|
281
|
-
"trigger.fired",
|
|
282
|
-
"subscription.added",
|
|
283
|
-
"subscription.removed"
|
|
284
|
-
];
|
|
285
|
-
const triggerStatsEventTypes = ["trigger.fired"];
|
|
286
|
-
for (const type of eventTypes) {
|
|
287
|
-
unsubs.push(eventBus.onType(type, handlePersistence));
|
|
288
|
-
}
|
|
289
|
-
for (const type of eventTypes) {
|
|
290
|
-
unsubs.push(eventBus.onType(type, handleOrchestration));
|
|
291
|
-
}
|
|
292
|
-
for (const type of triggerStatsEventTypes) {
|
|
293
|
-
unsubs.push(eventBus.onType(type, handleTriggerStats));
|
|
294
|
-
}
|
|
295
|
-
logger.info("Trigger event wiring setup complete (persistence + orchestration + stats)");
|
|
296
|
-
}
|
|
297
|
-
function stop() {
|
|
298
|
-
const logger = useNventLogger("trigger-wiring");
|
|
299
|
-
for (const u of unsubs.splice(0)) {
|
|
300
|
-
try {
|
|
301
|
-
u();
|
|
302
|
-
} catch {
|
|
303
|
-
}
|
|
304
|
-
}
|
|
305
|
-
wired = false;
|
|
306
|
-
logger.debug("Trigger wiring stopped");
|
|
307
|
-
}
|
|
308
|
-
return { start, stop };
|
|
309
|
-
}
|
|
310
|
-
export async function handleTriggerFired(event) {
|
|
311
|
-
const logger = useNventLogger("trigger-wiring");
|
|
312
|
-
const trigger = useTrigger();
|
|
313
|
-
const { triggerName, data } = event;
|
|
314
|
-
logger.debug("Trigger fired", { trigger: triggerName });
|
|
315
|
-
const triggerEntry = trigger.getTrigger(triggerName);
|
|
316
|
-
if (triggerEntry && triggerEntry.status !== "active") {
|
|
317
|
-
logger.info(`Trigger '${triggerName}' is ${triggerEntry.status}, skipping flow starts`, {
|
|
318
|
-
trigger: triggerName,
|
|
319
|
-
status: triggerEntry.status
|
|
320
|
-
});
|
|
321
|
-
return [];
|
|
322
|
-
}
|
|
323
|
-
const subscriptions = trigger.getAllSubscriptions().filter((sub) => sub.triggerName === triggerName);
|
|
324
|
-
if (subscriptions.length === 0) {
|
|
325
|
-
logger.warn(`No flows subscribed to trigger: ${triggerName}`);
|
|
326
|
-
return [];
|
|
327
|
-
}
|
|
328
|
-
const flowsStarted = [];
|
|
329
|
-
const store = useStoreAdapter();
|
|
330
|
-
const loggerForRuntime = useNventLogger("trigger-runtime");
|
|
331
|
-
const runtime = getTriggerRuntime(store, loggerForRuntime);
|
|
332
|
-
const resolvedData = await runtime.resolvePayload(data);
|
|
333
|
-
for (const subscription of subscriptions) {
|
|
334
|
-
try {
|
|
335
|
-
if (subscription.mode === "manual") {
|
|
336
|
-
logger.info(
|
|
337
|
-
`Trigger '${triggerName}' fired for flow '${subscription.flowName}' (manual mode - awaiting manual start)`
|
|
338
|
-
);
|
|
339
|
-
continue;
|
|
340
|
-
}
|
|
341
|
-
await startFlowFromTrigger(subscription.flowName, triggerName, resolvedData);
|
|
342
|
-
flowsStarted.push(subscription.flowName);
|
|
343
|
-
} catch (error) {
|
|
344
|
-
logger.error("Error starting flow from trigger", {
|
|
345
|
-
flow: subscription.flowName,
|
|
346
|
-
trigger: triggerName,
|
|
347
|
-
error: error instanceof Error ? error.message : String(error)
|
|
348
|
-
});
|
|
349
|
-
}
|
|
350
|
-
}
|
|
351
|
-
return flowsStarted;
|
|
352
|
-
}
|
|
353
|
-
export async function startFlowFromTrigger(flowName, triggerName, triggerData) {
|
|
354
|
-
const logger = useNventLogger("trigger-wiring");
|
|
355
|
-
const eventBus = getEventBus();
|
|
356
|
-
const queue = useQueueAdapter();
|
|
357
|
-
const registry = $useFunctionRegistry();
|
|
358
|
-
const analyzedFlows = $useAnalyzedFlows();
|
|
359
|
-
const store = useStoreAdapter();
|
|
360
|
-
const triggerRuntime = getTriggerRuntime(store, logger);
|
|
361
|
-
const flowDef = analyzedFlows.find((f) => f.id === flowName);
|
|
362
|
-
if (!flowDef || !flowDef.entry) {
|
|
363
|
-
logger.error(`Flow '${flowName}' not found or has no entry point`);
|
|
364
|
-
return;
|
|
365
|
-
}
|
|
366
|
-
const flowRegistry = (registry?.flows || {})[flowName];
|
|
367
|
-
if (!flowRegistry?.entry) {
|
|
368
|
-
logger.error(`Flow '${flowName}' has no entry in registry`);
|
|
369
|
-
return;
|
|
370
|
-
}
|
|
371
|
-
const triggerDef = triggerRuntime.getTrigger(triggerName);
|
|
372
|
-
const triggerType = triggerDef?.type || "manual";
|
|
373
|
-
const runId = `${flowName}-${Date.now()}-${Math.random().toString(36).substring(2, 9)}`;
|
|
374
|
-
logger.info(`Starting flow '${flowName}' from trigger '${triggerName}'`, { runId });
|
|
375
|
-
const queueName = flowRegistry.entry.queue;
|
|
376
|
-
const stepName = flowRegistry.entry.step;
|
|
377
|
-
const payload = {
|
|
378
|
-
flowId: runId,
|
|
379
|
-
flowName,
|
|
380
|
-
trigger: {
|
|
381
|
-
name: triggerName,
|
|
382
|
-
type: triggerType,
|
|
383
|
-
data: triggerData
|
|
384
|
-
},
|
|
385
|
-
...triggerData
|
|
386
|
-
};
|
|
387
|
-
const entryWorker = registry?.workers?.find(
|
|
388
|
-
(w) => w?.flow?.step === stepName && w?.queue?.name === queueName
|
|
389
|
-
);
|
|
390
|
-
const defaultOpts = entryWorker?.queue?.defaultJobOptions || {};
|
|
391
|
-
const analyzedEntry = flowDef.analyzed?.steps?.[stepName];
|
|
392
|
-
const stepTimeout = analyzedEntry?.stepTimeout;
|
|
393
|
-
const jobId = `${runId}__${stepName}`;
|
|
394
|
-
const opts = { ...defaultOpts, jobId, timeout: stepTimeout };
|
|
395
|
-
try {
|
|
396
|
-
await queue.enqueue(queueName, {
|
|
397
|
-
name: stepName,
|
|
398
|
-
data: payload,
|
|
399
|
-
opts
|
|
400
|
-
});
|
|
401
|
-
logger.info(`Enqueued entry step '${stepName}' to queue '${queueName}'`, { runId });
|
|
402
|
-
await eventBus.publish({
|
|
403
|
-
type: "flow.start",
|
|
404
|
-
flowName,
|
|
405
|
-
runId,
|
|
406
|
-
data: {
|
|
407
|
-
input: triggerData,
|
|
408
|
-
trigger: {
|
|
409
|
-
name: triggerName,
|
|
410
|
-
type: triggerType,
|
|
411
|
-
data: triggerData
|
|
412
|
-
}
|
|
413
|
-
}
|
|
414
|
-
});
|
|
415
|
-
} catch (error) {
|
|
416
|
-
logger.error("Failed to start flow from trigger", {
|
|
417
|
-
flowName,
|
|
418
|
-
trigger: triggerName,
|
|
419
|
-
error: error instanceof Error ? error.message : String(error)
|
|
420
|
-
});
|
|
421
|
-
}
|
|
422
|
-
}
|
|
@@ -1,14 +0,0 @@
|
|
|
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;
|
|
@@ -1,73 +0,0 @@
|
|
|
1
|
-
import { defineNitroPlugin, useRuntimeConfig, useNventLogger, setAdapters, initializeScheduler, shutdownScheduler } 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 initializeScheduler(adapters.store);
|
|
38
|
-
logger.info("Scheduler initialized");
|
|
39
|
-
const wiring = createWiringRegistry({
|
|
40
|
-
streamWiring: {
|
|
41
|
-
enabled: true
|
|
42
|
-
// Enable for WebSocket support
|
|
43
|
-
},
|
|
44
|
-
stateWiring: {
|
|
45
|
-
// Strategy is read from config by default (queue.store.state.cleanup.strategy)
|
|
46
|
-
// Can be overridden here if needed
|
|
47
|
-
}
|
|
48
|
-
});
|
|
49
|
-
await wiring.start();
|
|
50
|
-
logger.info("Flow wiring started");
|
|
51
|
-
await nitroApp.hooks.callHook("nvent:adapters:ready");
|
|
52
|
-
return {
|
|
53
|
-
hooks: {
|
|
54
|
-
close: async () => {
|
|
55
|
-
logger.info("Shutting down");
|
|
56
|
-
try {
|
|
57
|
-
await wiring.stop();
|
|
58
|
-
logger.info("Flow wiring stopped");
|
|
59
|
-
await shutdownScheduler();
|
|
60
|
-
logger.info("Scheduler shut down");
|
|
61
|
-
await shutdownAdapters(adapters);
|
|
62
|
-
logger.info("Adapters shut down successfully");
|
|
63
|
-
} catch (error) {
|
|
64
|
-
logger.error("Error during shutdown", { error });
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
};
|
|
69
|
-
} catch (error) {
|
|
70
|
-
logger.error("Failed to initialize adapters", { error });
|
|
71
|
-
throw error;
|
|
72
|
-
}
|
|
73
|
-
});
|
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
defineNitroPlugin,
|
|
3
|
-
useNventLogger,
|
|
4
|
-
usePeerManager
|
|
5
|
-
} from "#imports";
|
|
6
|
-
export default defineNitroPlugin((nitroApp) => {
|
|
7
|
-
const logger = useNventLogger("plugin-ws-lifecycle");
|
|
8
|
-
logger.info("[ws-lifecycle] WebSocket lifecycle plugin initialized");
|
|
9
|
-
const {
|
|
10
|
-
getActivePeers,
|
|
11
|
-
isServerShuttingDown,
|
|
12
|
-
setShuttingDown,
|
|
13
|
-
clearAllPeers,
|
|
14
|
-
getActivePeerCount
|
|
15
|
-
} = usePeerManager();
|
|
16
|
-
const originalUnhandledRejection = process.listeners("unhandledRejection");
|
|
17
|
-
nitroApp.hooks.hook("close", async () => {
|
|
18
|
-
setShuttingDown(true);
|
|
19
|
-
const peerCount = getActivePeerCount();
|
|
20
|
-
if (peerCount === 0) {
|
|
21
|
-
logger.info("[ws-lifecycle] No active WebSocket connections to close");
|
|
22
|
-
return;
|
|
23
|
-
}
|
|
24
|
-
logger.info(`[ws-lifecycle] Closing ${peerCount} active WebSocket connections...`);
|
|
25
|
-
const closePromises = [];
|
|
26
|
-
const peers = getActivePeers();
|
|
27
|
-
for (const peer of peers) {
|
|
28
|
-
closePromises.push(
|
|
29
|
-
new Promise((resolve) => {
|
|
30
|
-
try {
|
|
31
|
-
peer.send(JSON.stringify({
|
|
32
|
-
type: "server-restart",
|
|
33
|
-
message: "Server is restarting (HMR)"
|
|
34
|
-
}));
|
|
35
|
-
setTimeout(() => {
|
|
36
|
-
try {
|
|
37
|
-
peer.close(1001, "Server restarting");
|
|
38
|
-
} catch {
|
|
39
|
-
}
|
|
40
|
-
resolve();
|
|
41
|
-
}, 200);
|
|
42
|
-
} catch {
|
|
43
|
-
try {
|
|
44
|
-
peer.close(1001, "Server restarting");
|
|
45
|
-
} catch {
|
|
46
|
-
}
|
|
47
|
-
resolve();
|
|
48
|
-
}
|
|
49
|
-
})
|
|
50
|
-
);
|
|
51
|
-
}
|
|
52
|
-
await Promise.all(closePromises);
|
|
53
|
-
clearAllPeers();
|
|
54
|
-
logger.info("[ws-lifecycle] All WebSocket connections closed");
|
|
55
|
-
setTimeout(() => {
|
|
56
|
-
setShuttingDown(false);
|
|
57
|
-
}, 500);
|
|
58
|
-
});
|
|
59
|
-
process.on("unhandledRejection", (reason) => {
|
|
60
|
-
if (isServerShuttingDown() && reason?.code === "ECONNRESET") {
|
|
61
|
-
return;
|
|
62
|
-
}
|
|
63
|
-
for (const handler of originalUnhandledRejection) {
|
|
64
|
-
if (typeof handler === "function") {
|
|
65
|
-
handler(reason, Promise.reject(reason));
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
});
|
|
69
|
-
});
|
|
@@ -1,92 +0,0 @@
|
|
|
1
|
-
import { defineNitroPlugin, $useWorkerHandlers, $useFunctionRegistry, useQueueAdapter, useHookRegistry } from "#imports";
|
|
2
|
-
import { createJobProcessor } from "../../worker/node/runner.js";
|
|
3
|
-
import { registerSystemHandlersOnQueue } from "../../worker/system/index.js";
|
|
4
|
-
export default defineNitroPlugin(async (nitroApp) => {
|
|
5
|
-
nitroApp.hooks.hook("close", async () => {
|
|
6
|
-
const queueAdapter = useQueueAdapter();
|
|
7
|
-
await queueAdapter.close();
|
|
8
|
-
});
|
|
9
|
-
nitroApp.hooks.hook("nvent:adapters:ready", async () => {
|
|
10
|
-
const queueAdapter = useQueueAdapter();
|
|
11
|
-
try {
|
|
12
|
-
const handlers = $useWorkerHandlers();
|
|
13
|
-
const registry = $useFunctionRegistry() || { workers: [] };
|
|
14
|
-
const registeredQueues = /* @__PURE__ */ new Set();
|
|
15
|
-
const queuesWithHooks = /* @__PURE__ */ new Set();
|
|
16
|
-
for (const entry of handlers) {
|
|
17
|
-
const { queue, id, handler, module } = entry;
|
|
18
|
-
const w = registry.workers.find((rw) => rw?.id === id || rw?.queue?.name === queue && rw?.absPath === entry.absPath);
|
|
19
|
-
let jobName;
|
|
20
|
-
if (w?.flow?.step) {
|
|
21
|
-
jobName = Array.isArray(w.flow.step) ? w.flow.step[0] : w.flow.step;
|
|
22
|
-
} else {
|
|
23
|
-
jobName = id.includes("/") ? id.split("/").pop() : id;
|
|
24
|
-
}
|
|
25
|
-
if (module) {
|
|
26
|
-
const hooks = {};
|
|
27
|
-
if (typeof module.onAwaitRegister === "function") {
|
|
28
|
-
hooks.onAwaitRegister = module.onAwaitRegister;
|
|
29
|
-
}
|
|
30
|
-
if (typeof module.onAwaitResolve === "function") {
|
|
31
|
-
hooks.onAwaitResolve = module.onAwaitResolve;
|
|
32
|
-
}
|
|
33
|
-
if (typeof module.onAwaitTimeout === "function") {
|
|
34
|
-
hooks.onAwaitTimeout = module.onAwaitTimeout;
|
|
35
|
-
}
|
|
36
|
-
if (Object.keys(hooks).length > 0 && w?.flow) {
|
|
37
|
-
const hookRegistry = useHookRegistry();
|
|
38
|
-
const flowNames = w.flow.names ? Array.isArray(w.flow.names) ? w.flow.names : [w.flow.names] : w.flow.name ? Array.isArray(w.flow.name) ? w.flow.name : [w.flow.name] : [];
|
|
39
|
-
for (const flowName of flowNames) {
|
|
40
|
-
if (flowName) {
|
|
41
|
-
hookRegistry.register(flowName, jobName, hooks);
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
queuesWithHooks.add(queue);
|
|
45
|
-
}
|
|
46
|
-
if (w?.flow?.awaitBefore || w?.flow?.awaitAfter) {
|
|
47
|
-
queuesWithHooks.add(queue);
|
|
48
|
-
}
|
|
49
|
-
if (w?.flow?.role === "entry") {
|
|
50
|
-
const flowNames = w.flow.names ? Array.isArray(w.flow.names) ? w.flow.names : [w.flow.names] : w.flow.name ? Array.isArray(w.flow.name) ? w.flow.name : [w.flow.name] : [];
|
|
51
|
-
for (const flowName of flowNames) {
|
|
52
|
-
const flowRegistry = (registry?.flows || {})[flowName];
|
|
53
|
-
if (flowRegistry?.entry?.awaitBefore || flowRegistry?.entry?.awaitAfter) {
|
|
54
|
-
queuesWithHooks.add(queue);
|
|
55
|
-
break;
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
if (typeof handler === "function") {
|
|
61
|
-
const workerCfg = w && w.worker || {};
|
|
62
|
-
const queueCfg = w && w.queue || {};
|
|
63
|
-
const opts = {};
|
|
64
|
-
if (typeof workerCfg.concurrency === "number") opts.concurrency = workerCfg.concurrency;
|
|
65
|
-
if (typeof workerCfg.autorun === "boolean") opts.autorun = workerCfg.autorun;
|
|
66
|
-
if (queueCfg.defaultJobOptions) opts.defaultJobOptions = queueCfg.defaultJobOptions;
|
|
67
|
-
if (queueCfg.prefix) opts.prefix = queueCfg.prefix;
|
|
68
|
-
if (queueCfg.limiter) opts.limiter = queueCfg.limiter;
|
|
69
|
-
const processor = createJobProcessor(handler, queue);
|
|
70
|
-
queueAdapter.registerWorker(queue, jobName, processor, opts);
|
|
71
|
-
registeredQueues.add(queue);
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
for (const queueName of queuesWithHooks) {
|
|
75
|
-
try {
|
|
76
|
-
const queueWorker = registry.workers.find((w) => w?.queue?.name === queueName);
|
|
77
|
-
const concurrency = queueWorker?.worker?.concurrency;
|
|
78
|
-
registerSystemHandlersOnQueue(queueName, concurrency);
|
|
79
|
-
registeredQueues.add(queueName);
|
|
80
|
-
} catch (err) {
|
|
81
|
-
console.error(`[nvent] Failed to register system handlers on queue ${queueName}:`, err);
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
if (queueAdapter.startProcessingQueue) {
|
|
85
|
-
for (const queueName of Array.from(registeredQueues)) {
|
|
86
|
-
queueAdapter.startProcessingQueue(queueName);
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
} catch {
|
|
90
|
-
}
|
|
91
|
-
});
|
|
92
|
-
});
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Trigger Registration Plugin
|
|
3
|
-
*
|
|
4
|
-
* Loads pre-analyzed triggers and subscriptions from build-time registry
|
|
5
|
-
* and registers them via event bus (trigger.registered events).
|
|
6
|
-
* The trigger wiring will handle the actual registration logic.
|
|
7
|
-
*
|
|
8
|
-
* This plugin is ONLY for registering dev/build-time discovered triggers.
|
|
9
|
-
* Trigger wiring and event handling is done in the wiring registry.
|
|
10
|
-
*/
|
|
11
|
-
declare const _default: any;
|
|
12
|
-
export default _default;
|