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.
Files changed (149) hide show
  1. package/dist/module.d.mts +181 -8
  2. package/dist/module.json +1 -1
  3. package/dist/module.mjs +1257 -1196
  4. package/dist/runtime/app/composables/useFunctionCall.d.ts +17 -0
  5. package/dist/runtime/app/composables/useFunctionCall.js +25 -0
  6. package/dist/runtime/app/composables/useNventStream.d.ts +23 -0
  7. package/dist/runtime/app/composables/useNventStream.js +58 -0
  8. package/dist/runtime/nitro/plugins/00.iii-lifecycle.d.ts +19 -0
  9. package/dist/runtime/nitro/plugins/00.iii-lifecycle.js +62 -0
  10. package/dist/runtime/nitro/plugins/01.iii-worker.d.ts +15 -0
  11. package/dist/runtime/nitro/plugins/01.iii-worker.js +91 -0
  12. package/dist/runtime/nitro/routes/stream-proxy.d.ts +17 -0
  13. package/dist/runtime/nitro/routes/stream-proxy.js +45 -0
  14. package/dist/runtime/nitro/utils/console.d.ts +32 -0
  15. package/dist/runtime/nitro/utils/console.js +95 -0
  16. package/dist/runtime/nitro/utils/defineFunction.d.ts +378 -3
  17. package/dist/runtime/nitro/utils/defineFunction.js +224 -4
  18. package/dist/runtime/nitro/utils/engine.d.ts +25 -0
  19. package/dist/runtime/nitro/utils/engine.js +130 -0
  20. package/dist/runtime/nitro/utils/nventDir.d.ts +1 -0
  21. package/dist/runtime/nitro/utils/nventDir.js +20 -0
  22. package/dist/runtime/nitro/utils/useIii.d.ts +23 -0
  23. package/dist/runtime/nitro/utils/useIii.js +14 -0
  24. package/dist/runtime/nitro/utils/workers/node.d.ts +24 -0
  25. package/dist/runtime/nitro/utils/workers/node.js +57 -0
  26. package/dist/runtime/nitro/utils/workers/python.d.ts +67 -0
  27. package/dist/runtime/nitro/utils/workers/python.js +220 -0
  28. package/dist/runtime/python/nvent.py +208 -0
  29. package/dist/runtime/python/worker_runtime.py +659 -0
  30. package/dist/runtime/virtual.d.ts +17 -0
  31. package/dist/types.d.mts +5 -1
  32. package/package.json +11 -14
  33. package/dist/runtime/adapters/base/index.d.ts +0 -6
  34. package/dist/runtime/adapters/base/index.js +0 -1
  35. package/dist/runtime/adapters/base/store-validator.d.ts +0 -48
  36. package/dist/runtime/adapters/base/store-validator.js +0 -147
  37. package/dist/runtime/adapters/builtin/file-queue.d.ts +0 -67
  38. package/dist/runtime/adapters/builtin/file-queue.js +0 -499
  39. package/dist/runtime/adapters/builtin/file-store.d.ts +0 -32
  40. package/dist/runtime/adapters/builtin/file-store.js +0 -206
  41. package/dist/runtime/adapters/builtin/file-stream.d.ts +0 -39
  42. package/dist/runtime/adapters/builtin/file-stream.js +0 -56
  43. package/dist/runtime/adapters/builtin/index.d.ts +0 -10
  44. package/dist/runtime/adapters/builtin/index.js +0 -5
  45. package/dist/runtime/adapters/builtin/memory-queue.d.ts +0 -52
  46. package/dist/runtime/adapters/builtin/memory-queue.js +0 -243
  47. package/dist/runtime/adapters/builtin/memory-store.d.ts +0 -69
  48. package/dist/runtime/adapters/builtin/memory-store.js +0 -357
  49. package/dist/runtime/adapters/builtin/memory-stream.d.ts +0 -21
  50. package/dist/runtime/adapters/builtin/memory-stream.js +0 -56
  51. package/dist/runtime/adapters/factory.d.ts +0 -31
  52. package/dist/runtime/adapters/factory.js +0 -135
  53. package/dist/runtime/adapters/index.d.ts +0 -8
  54. package/dist/runtime/adapters/index.js +0 -3
  55. package/dist/runtime/adapters/interfaces/index.d.ts +0 -11
  56. package/dist/runtime/adapters/interfaces/index.js +0 -3
  57. package/dist/runtime/adapters/interfaces/queue.d.ts +0 -155
  58. package/dist/runtime/adapters/interfaces/queue.js +0 -0
  59. package/dist/runtime/adapters/interfaces/store.d.ts +0 -299
  60. package/dist/runtime/adapters/interfaces/store.js +0 -0
  61. package/dist/runtime/adapters/interfaces/stream.d.ts +0 -62
  62. package/dist/runtime/adapters/interfaces/stream.js +0 -0
  63. package/dist/runtime/adapters/registry.d.ts +0 -85
  64. package/dist/runtime/adapters/registry.js +0 -161
  65. package/dist/runtime/config/index.d.ts +0 -23
  66. package/dist/runtime/config/index.js +0 -200
  67. package/dist/runtime/config/types.d.ts +0 -439
  68. package/dist/runtime/config/types.js +0 -0
  69. package/dist/runtime/events/eventBus.d.ts +0 -20
  70. package/dist/runtime/events/eventBus.js +0 -35
  71. package/dist/runtime/events/types.d.ts +0 -144
  72. package/dist/runtime/events/types.js +0 -0
  73. package/dist/runtime/events/utils/scheduleTrigger.d.ts +0 -8
  74. package/dist/runtime/events/utils/scheduleTrigger.js +0 -71
  75. package/dist/runtime/events/utils/stallDetector.d.ts +0 -83
  76. package/dist/runtime/events/utils/stallDetector.js +0 -318
  77. package/dist/runtime/events/utils/triggerRuntime.d.ts +0 -58
  78. package/dist/runtime/events/utils/triggerRuntime.js +0 -212
  79. package/dist/runtime/events/wiring/flowWiring.d.ts +0 -34
  80. package/dist/runtime/events/wiring/flowWiring.js +0 -1258
  81. package/dist/runtime/events/wiring/registry.d.ts +0 -19
  82. package/dist/runtime/events/wiring/registry.js +0 -43
  83. package/dist/runtime/events/wiring/stateWiring.d.ts +0 -37
  84. package/dist/runtime/events/wiring/stateWiring.js +0 -92
  85. package/dist/runtime/events/wiring/streamWiring.d.ts +0 -36
  86. package/dist/runtime/events/wiring/streamWiring.js +0 -156
  87. package/dist/runtime/events/wiring/triggerWiring.d.ts +0 -21
  88. package/dist/runtime/events/wiring/triggerWiring.js +0 -422
  89. package/dist/runtime/nitro/plugins/00.adapters.d.ts +0 -14
  90. package/dist/runtime/nitro/plugins/00.adapters.js +0 -73
  91. package/dist/runtime/nitro/plugins/01.ws-lifecycle.d.ts +0 -5
  92. package/dist/runtime/nitro/plugins/01.ws-lifecycle.js +0 -69
  93. package/dist/runtime/nitro/plugins/02.workers.d.ts +0 -2
  94. package/dist/runtime/nitro/plugins/02.workers.js +0 -92
  95. package/dist/runtime/nitro/plugins/03.triggers.d.ts +0 -12
  96. package/dist/runtime/nitro/plugins/03.triggers.js +0 -55
  97. package/dist/runtime/nitro/routes/webhook.await.d.ts +0 -23
  98. package/dist/runtime/nitro/routes/webhook.await.js +0 -112
  99. package/dist/runtime/nitro/routes/webhook.trigger.d.ts +0 -86
  100. package/dist/runtime/nitro/routes/webhook.trigger.js +0 -73
  101. package/dist/runtime/nitro/utils/adapters.d.ts +0 -66
  102. package/dist/runtime/nitro/utils/adapters.js +0 -51
  103. package/dist/runtime/nitro/utils/awaitPatterns/event.d.ts +0 -15
  104. package/dist/runtime/nitro/utils/awaitPatterns/event.js +0 -128
  105. package/dist/runtime/nitro/utils/awaitPatterns/index.d.ts +0 -28
  106. package/dist/runtime/nitro/utils/awaitPatterns/index.js +0 -55
  107. package/dist/runtime/nitro/utils/awaitPatterns/schedule.d.ts +0 -16
  108. package/dist/runtime/nitro/utils/awaitPatterns/schedule.js +0 -83
  109. package/dist/runtime/nitro/utils/awaitPatterns/time.d.ts +0 -15
  110. package/dist/runtime/nitro/utils/awaitPatterns/time.js +0 -71
  111. package/dist/runtime/nitro/utils/awaitPatterns/webhook.d.ts +0 -15
  112. package/dist/runtime/nitro/utils/awaitPatterns/webhook.js +0 -128
  113. package/dist/runtime/nitro/utils/defineFunctionConfig.d.ts +0 -378
  114. package/dist/runtime/nitro/utils/defineFunctionConfig.js +0 -3
  115. package/dist/runtime/nitro/utils/defineHooks.d.ts +0 -95
  116. package/dist/runtime/nitro/utils/defineHooks.js +0 -9
  117. package/dist/runtime/nitro/utils/registerAdapter.d.ts +0 -59
  118. package/dist/runtime/nitro/utils/registerAdapter.js +0 -13
  119. package/dist/runtime/nitro/utils/useAwait.d.ts +0 -83
  120. package/dist/runtime/nitro/utils/useAwait.js +0 -169
  121. package/dist/runtime/nitro/utils/useEventManager.d.ts +0 -15
  122. package/dist/runtime/nitro/utils/useEventManager.js +0 -26
  123. package/dist/runtime/nitro/utils/useFlow.d.ts +0 -66
  124. package/dist/runtime/nitro/utils/useFlow.js +0 -310
  125. package/dist/runtime/nitro/utils/useHookRegistry.d.ts +0 -40
  126. package/dist/runtime/nitro/utils/useHookRegistry.js +0 -25
  127. package/dist/runtime/nitro/utils/useNventLogger.d.ts +0 -42
  128. package/dist/runtime/nitro/utils/useNventLogger.js +0 -54
  129. package/dist/runtime/nitro/utils/useRunContext.d.ts +0 -6
  130. package/dist/runtime/nitro/utils/useRunContext.js +0 -102
  131. package/dist/runtime/nitro/utils/useStreamTopics.d.ts +0 -83
  132. package/dist/runtime/nitro/utils/useStreamTopics.js +0 -94
  133. package/dist/runtime/nitro/utils/useTrigger.d.ts +0 -150
  134. package/dist/runtime/nitro/utils/useTrigger.js +0 -311
  135. package/dist/runtime/nitro/utils/wsPeerManager.d.ts +0 -44
  136. package/dist/runtime/nitro/utils/wsPeerManager.js +0 -32
  137. package/dist/runtime/scheduler/index.d.ts +0 -33
  138. package/dist/runtime/scheduler/index.js +0 -42
  139. package/dist/runtime/scheduler/scheduler.d.ts +0 -132
  140. package/dist/runtime/scheduler/scheduler.js +0 -799
  141. package/dist/runtime/scheduler/types.d.ts +0 -122
  142. package/dist/runtime/scheduler/types.js +0 -0
  143. package/dist/runtime/worker/node/runner.d.ts +0 -95
  144. package/dist/runtime/worker/node/runner.js +0 -272
  145. package/dist/runtime/worker/python/get_config.py +0 -64
  146. package/dist/runtime/worker/system/awaitHandlers.d.ts +0 -27
  147. package/dist/runtime/worker/system/awaitHandlers.js +0 -230
  148. package/dist/runtime/worker/system/index.d.ts +0 -24
  149. package/dist/runtime/worker/system/index.js +0 -39
@@ -1,311 +0,0 @@
1
- import { useStoreAdapter, useNventLogger, useStreamTopics } from "#imports";
2
- import { getEventBus } from "../../events/eventBus.js";
3
- import { getTriggerRuntime } from "../../events/utils/triggerRuntime.js";
4
- export async function resolvePayload(data) {
5
- const logger = useNventLogger("trigger");
6
- const store = useStoreAdapter();
7
- const runtime = getTriggerRuntime(store, logger);
8
- return runtime.resolvePayload(data);
9
- }
10
- export function useTrigger() {
11
- const logger = useNventLogger("trigger");
12
- const store = useStoreAdapter();
13
- const runtime = getTriggerRuntime(store, logger);
14
- return {
15
- /**
16
- * Register a trigger (programmatic)
17
- * Publishes event to bus - triggerWiring handles persistence and orchestration
18
- */
19
- async registerTrigger(opts) {
20
- const eventBus = getEventBus();
21
- const existing = runtime.getTrigger(opts.name);
22
- const isUpdate = !!existing;
23
- if (isUpdate) {
24
- logger.info(`Updating trigger: ${opts.name}`);
25
- await eventBus.publish({
26
- type: "trigger.updated",
27
- triggerName: opts.name,
28
- data: {
29
- type: opts.type,
30
- scope: opts.scope,
31
- status: opts.status,
32
- displayName: opts.displayName,
33
- description: opts.description,
34
- source: opts.source || "programmatic",
35
- webhook: opts.webhook,
36
- schedule: opts.schedule,
37
- config: opts.config,
38
- expectedSubscribers: opts.expectedSubscribers
39
- }
40
- });
41
- } else {
42
- logger.info(`Registering trigger: ${opts.name}`);
43
- await eventBus.publish({
44
- type: "trigger.registered",
45
- triggerName: opts.name,
46
- data: {
47
- name: opts.name,
48
- type: opts.type,
49
- scope: opts.scope,
50
- displayName: opts.displayName,
51
- description: opts.description,
52
- source: opts.source || "programmatic",
53
- expectedSubscribers: opts.expectedSubscribers,
54
- webhook: opts.webhook,
55
- schedule: opts.schedule,
56
- config: opts.config
57
- }
58
- });
59
- }
60
- },
61
- /**
62
- * Subscribe flow to trigger (programmatic)
63
- * Publishes event to bus - triggerWiring handles persistence and orchestration
64
- */
65
- async subscribeTrigger(opts) {
66
- const eventBus = getEventBus();
67
- const { trigger, flow, mode = "auto" } = opts;
68
- const existingSub = runtime.getSubscription(trigger, flow);
69
- const isUpdate = !!existingSub;
70
- logger.info(`${isUpdate ? "Updating" : "Subscribing"} flow '${flow}' to trigger '${trigger}' (${mode})`);
71
- await eventBus.publish({
72
- type: "subscription.added",
73
- triggerName: trigger,
74
- data: {
75
- trigger,
76
- flow,
77
- mode,
78
- isUpdate
79
- }
80
- });
81
- },
82
- /**
83
- * Unsubscribe flow from trigger
84
- * Publishes event to bus - triggerWiring handles persistence and orchestration
85
- */
86
- async unsubscribeTrigger(trigger, flow) {
87
- const eventBus = getEventBus();
88
- logger.info(`Unsubscribing flow '${flow}' from trigger '${trigger}'`);
89
- await eventBus.publish({
90
- type: "subscription.removed",
91
- triggerName: trigger,
92
- data: {
93
- trigger,
94
- flow
95
- }
96
- });
97
- },
98
- /**
99
- * Emit trigger (fire event)
100
- * Publishes event to bus - triggerWiring handles persistence, stats, and orchestration
101
- *
102
- * Large payloads are automatically stored in KV store and replaced with references
103
- * to keep stream events small and memory-efficient.
104
- */
105
- async emitTrigger(name, data, opts) {
106
- const eventBus = getEventBus();
107
- const trigger = runtime.getTrigger(name);
108
- if (!trigger) {
109
- logger.warn(
110
- `Emitting unregistered trigger '${name}'. Consider registering it first with registerTrigger().`
111
- );
112
- }
113
- if (trigger && trigger.status !== "active") {
114
- logger.info(
115
- `Trigger '${name}' is ${trigger.status}, not emitting. Update status to 'active' to enable firing.`
116
- );
117
- return;
118
- }
119
- const threshold = opts?.payloadThreshold || trigger?.config?.payloadThreshold || 10 * 1024;
120
- const eventData = await runtime.handleLargePayload(name, data, threshold);
121
- logger.debug(`Emitting trigger: ${name}`, {
122
- hasReference: !!eventData.__payloadRef,
123
- size: eventData.__size
124
- });
125
- await eventBus.publish({
126
- type: "trigger.fired",
127
- triggerName: name,
128
- data: eventData
129
- });
130
- },
131
- /**
132
- * Query methods
133
- */
134
- /**
135
- * Check if a trigger exists in the registry
136
- */
137
- hasTrigger(name) {
138
- return runtime.hasTrigger(name);
139
- },
140
- /**
141
- * Get trigger entry by name
142
- */
143
- getTrigger(name) {
144
- return runtime.getTrigger(name);
145
- },
146
- /**
147
- * Get all registered triggers
148
- * @param options - Sorting and pagination options
149
- * @param options.sortBy - Field to sort by
150
- * @param options.order - Sort order (asc or desc)
151
- * @param options.limit - Maximum number of results
152
- * @param options.offset - Number of results to skip
153
- */
154
- getAllTriggers(options) {
155
- return runtime.getAllTriggers(options);
156
- },
157
- /**
158
- * Get all flows subscribed to a specific trigger
159
- */
160
- getSubscribedFlows(trigger) {
161
- return runtime.getSubscribedFlows(trigger);
162
- },
163
- /**
164
- * Get all triggers that a flow is subscribed to
165
- */
166
- getFlowTriggers(flow) {
167
- return runtime.getFlowTriggers(flow);
168
- },
169
- /**
170
- * Get subscription details for a specific trigger-flow pair
171
- */
172
- getSubscription(trigger, flow) {
173
- return runtime.getSubscription(trigger, flow);
174
- },
175
- getAllSubscriptions() {
176
- return runtime.getAllSubscriptions();
177
- },
178
- /**
179
- * Initialize runtime from store (called on startup)
180
- * Uses index + stream architecture (v0.5.1)
181
- */
182
- async initialize() {
183
- if (runtime.initialized) return;
184
- const { StoreSubjects } = useStreamTopics();
185
- const indexKey = StoreSubjects.triggerIndex();
186
- logger.info("Initializing trigger runtime from index...");
187
- if (store.index.read) {
188
- const entries = await store.index.read(indexKey, { limit: 1e3 });
189
- let activeCount = 0;
190
- let totalSubscriptions = 0;
191
- for (const entry of entries) {
192
- const metadata = entry.metadata;
193
- const triggerEntry = {
194
- name: metadata.name,
195
- type: metadata.type,
196
- scope: metadata.scope,
197
- status: metadata.status || "active",
198
- displayName: metadata.displayName,
199
- description: metadata.description,
200
- source: metadata.source,
201
- registeredAt: metadata.registeredAt,
202
- registeredBy: metadata.registeredBy,
203
- lastActivityAt: metadata.lastActivityAt,
204
- subscriptions: metadata.subscriptions || {},
205
- stats: metadata.stats || { totalFires: 0, activeSubscribers: 0 },
206
- webhook: metadata.webhook,
207
- schedule: metadata.schedule,
208
- config: metadata.config,
209
- version: metadata.version || 1
210
- };
211
- runtime.addTrigger(entry.id, triggerEntry);
212
- if (metadata.status === "active") {
213
- activeCount++;
214
- }
215
- if (metadata.subscriptions) {
216
- for (const [flowName, subData] of Object.entries(metadata.subscriptions)) {
217
- if (!subData) continue;
218
- const subscription = {
219
- triggerName: entry.id,
220
- flowName,
221
- mode: subData.mode || "auto",
222
- source: "programmatic",
223
- registeredAt: subData.subscribedAt
224
- };
225
- runtime.addSubscription(entry.id, flowName, subscription);
226
- totalSubscriptions++;
227
- }
228
- }
229
- }
230
- logger.info(
231
- `Loaded ${activeCount} active triggers with ${totalSubscriptions} subscriptions from index`
232
- );
233
- }
234
- runtime.setInitialized(true);
235
- },
236
- /**
237
- * Get runtime state (for debugging)
238
- */
239
- getRuntime() {
240
- return runtime.getRuntimeStats();
241
- },
242
- /**
243
- * Delete a trigger completely (removes all data)
244
- * Publishes event to bus - triggerWiring handles persistence and orchestration
245
- */
246
- async deleteTrigger(name) {
247
- const eventBus = getEventBus();
248
- const trigger = runtime.getTrigger(name);
249
- if (!trigger) {
250
- logger.warn(`Cannot delete non-existent trigger: ${name}`);
251
- return;
252
- }
253
- logger.info(`Deleting trigger: ${name}`);
254
- await eventBus.publish({
255
- type: "trigger.deleted",
256
- triggerName: name,
257
- data: {}
258
- });
259
- },
260
- /**
261
- * Update trigger status (active/inactive/retired)
262
- * For future status management UI
263
- */
264
- async updateTriggerStatus(name, status) {
265
- const eventBus = getEventBus();
266
- const trigger = runtime.getTrigger(name);
267
- if (!trigger) {
268
- logger.warn(`Cannot update status of non-existent trigger: ${name}`);
269
- return;
270
- }
271
- logger.info(`Updating trigger ${name} status to: ${status}`);
272
- await eventBus.publish({
273
- type: "trigger.updated",
274
- triggerName: name,
275
- data: {
276
- ...trigger,
277
- status
278
- }
279
- });
280
- },
281
- /**
282
- * Get trigger statistics
283
- * v0.5.1: New analytics method
284
- */
285
- async getTriggerStats(name) {
286
- const { StoreSubjects } = useStreamTopics();
287
- const indexKey = StoreSubjects.triggerIndex();
288
- if (!store.index.get) {
289
- const trigger = runtime.getTrigger(name);
290
- return trigger?.stats;
291
- }
292
- const entry = await store.index.get(indexKey, name);
293
- if (!entry?.metadata) return null;
294
- return entry.metadata.stats;
295
- },
296
- /**
297
- * Get trigger history from stream
298
- * v0.5.1: New analytics method
299
- */
300
- async getTriggerHistory(name, opts) {
301
- const { StoreSubjects } = useStreamTopics();
302
- const streamName = StoreSubjects.triggerStream(name);
303
- const events = await store.stream.read(streamName, {
304
- limit: opts?.limit || 100,
305
- types: opts?.types,
306
- order: "desc"
307
- });
308
- return events;
309
- }
310
- };
311
- }
@@ -1,44 +0,0 @@
1
- /**
2
- * WebSocket Peer Manager
3
- *
4
- * Tracks active WebSocket connections for graceful shutdown during HMR.
5
- * Auto-imported in Nitro server context.
6
- */
7
- /**
8
- * Register a peer to be tracked for graceful shutdown
9
- */
10
- declare function registerWsPeer(peer: any): void;
11
- /**
12
- * Unregister a peer (called when connection closes normally)
13
- */
14
- declare function unregisterWsPeer(peer: any): void;
15
- /**
16
- * Get all currently active WebSocket peers
17
- */
18
- declare function getActivePeers(): any[];
19
- /**
20
- * Check if server is currently shutting down
21
- */
22
- declare function isServerShuttingDown(): boolean;
23
- /**
24
- * Set the shutdown state
25
- */
26
- declare function setShuttingDown(state: boolean): void;
27
- /**
28
- * Clear all tracked peers
29
- */
30
- declare function clearAllPeers(): void;
31
- /**
32
- * Get the count of active peers
33
- */
34
- declare function getActivePeerCount(): number;
35
- export declare const usePeerManager: () => {
36
- registerWsPeer: typeof registerWsPeer;
37
- unregisterWsPeer: typeof unregisterWsPeer;
38
- getActivePeers: typeof getActivePeers;
39
- isServerShuttingDown: typeof isServerShuttingDown;
40
- setShuttingDown: typeof setShuttingDown;
41
- clearAllPeers: typeof clearAllPeers;
42
- getActivePeerCount: typeof getActivePeerCount;
43
- };
44
- export {};
@@ -1,32 +0,0 @@
1
- const activePeers = /* @__PURE__ */ new Set();
2
- let isShuttingDown = false;
3
- function registerWsPeer(peer) {
4
- activePeers.add(peer);
5
- }
6
- function unregisterWsPeer(peer) {
7
- activePeers.delete(peer);
8
- }
9
- function getActivePeers() {
10
- return Array.from(activePeers);
11
- }
12
- function isServerShuttingDown() {
13
- return isShuttingDown;
14
- }
15
- function setShuttingDown(state) {
16
- isShuttingDown = state;
17
- }
18
- function clearAllPeers() {
19
- activePeers.clear();
20
- }
21
- function getActivePeerCount() {
22
- return activePeers.size;
23
- }
24
- export const usePeerManager = () => ({
25
- registerWsPeer,
26
- unregisterWsPeer,
27
- getActivePeers,
28
- isServerShuttingDown,
29
- setShuttingDown,
30
- clearAllPeers,
31
- getActivePeerCount
32
- });
@@ -1,33 +0,0 @@
1
- /**
2
- * Scheduler Factory and Composable
3
- *
4
- * Provides a unified scheduler interface for the entire application.
5
- * Uses Scheduler with store adapter (supports both distributed and single-instance modes).
6
- */
7
- import type { SchedulerAdapter } from './types.js';
8
- /**
9
- * Create a scheduler instance
10
- * Uses Scheduler which adapts based on store capabilities:
11
- * - With indexAdd/indexGet: Full distributed locking
12
- * - Without: Degrades gracefully to KV-based locking (single instance)
13
- */
14
- export declare function createScheduler(store: any): SchedulerAdapter;
15
- /**
16
- * Get the global scheduler instance
17
- * Must be initialized first with initializeScheduler()
18
- */
19
- export declare function useScheduler(): SchedulerAdapter;
20
- /**
21
- * Initialize the scheduler
22
- * Should be called once during app startup
23
- */
24
- export declare function initializeScheduler(store: any): Promise<SchedulerAdapter>;
25
- /**
26
- * Shutdown the scheduler
27
- * Should be called during app shutdown
28
- */
29
- export declare function shutdownScheduler(): Promise<void>;
30
- /**
31
- * Reset the scheduler instance (for testing)
32
- */
33
- export declare function resetScheduler(): void;
@@ -1,42 +0,0 @@
1
- import { Scheduler } from "./scheduler.js";
2
- import { useRuntimeConfig } from "#imports";
3
- const SCHEDULER_KEY = "__nvent_scheduler__";
4
- let schedulerInstance = globalThis[SCHEDULER_KEY] || null;
5
- export function createScheduler(store) {
6
- const config = useRuntimeConfig();
7
- const prefix = config.nvent.store?.prefix || "nvent";
8
- const useIndexLocking = !!(store.indexAdd && store.index.get);
9
- return new Scheduler({
10
- store,
11
- keyPrefix: `${prefix}:scheduler`,
12
- lockTTL: 3e5,
13
- // 5 minutes
14
- useIndexLocking
15
- });
16
- }
17
- export function useScheduler() {
18
- if (!schedulerInstance) {
19
- throw new Error("Scheduler not initialized. Call initializeScheduler() first.");
20
- }
21
- return schedulerInstance;
22
- }
23
- export async function initializeScheduler(store) {
24
- if (schedulerInstance) {
25
- return schedulerInstance;
26
- }
27
- schedulerInstance = createScheduler(store);
28
- globalThis[SCHEDULER_KEY] = schedulerInstance;
29
- await schedulerInstance.start();
30
- return schedulerInstance;
31
- }
32
- export async function shutdownScheduler() {
33
- if (schedulerInstance) {
34
- await schedulerInstance.stop();
35
- schedulerInstance = null;
36
- globalThis[SCHEDULER_KEY] = null;
37
- }
38
- }
39
- export function resetScheduler() {
40
- schedulerInstance = null;
41
- globalThis[SCHEDULER_KEY] = null;
42
- }
@@ -1,132 +0,0 @@
1
- /**
2
- * Scheduler
3
- *
4
- * Store-based scheduler with distributed locking for horizontal scaling.
5
- * Ensures only one instance executes each scheduled job.
6
- */
7
- import type { ScheduledJob, SchedulerAdapter } from './types.js';
8
- import type { StoreAdapter } from '../adapters/interfaces/store.js';
9
- export interface SchedulerOptions {
10
- /**
11
- * Store adapter for locking (Redis recommended)
12
- */
13
- store: StoreAdapter;
14
- /**
15
- * Key prefix for locks and job data
16
- * Uses configured store prefix + ':scheduler'
17
- * @default '{prefix}:scheduler' (e.g., 'nvent:scheduler')
18
- */
19
- keyPrefix?: string;
20
- /**
21
- * Lock TTL in milliseconds
22
- * @default 300000 (5 minutes)
23
- */
24
- lockTTL?: number;
25
- /**
26
- * Unique instance identifier
27
- * @default Auto-generated
28
- */
29
- instanceId?: string;
30
- /**
31
- * Use store indexes for locking (more robust) vs simple KV
32
- * @default true
33
- */
34
- useIndexLocking?: boolean;
35
- }
36
- export declare class Scheduler implements SchedulerAdapter {
37
- private store;
38
- private keyPrefix;
39
- private lockTTL;
40
- private instanceId;
41
- private useIndexLocking;
42
- private jobs;
43
- private jobConfigs;
44
- private lockRenewalTimers;
45
- private started;
46
- private logger;
47
- private syncSubscription?;
48
- constructor(options: SchedulerOptions);
49
- schedule(job: ScheduledJob): Promise<string>;
50
- /**
51
- * Execute job with distributed lock
52
- * Prevents multiple instances from running the same job
53
- */
54
- private executeWithLock;
55
- private executeJob;
56
- /**
57
- * Acquire distributed lock using store adapter
58
- */
59
- private acquireLock;
60
- /**
61
- * Release distributed lock
62
- */
63
- private releaseLock;
64
- /**
65
- * Poll for new jobs created by other instances
66
- * This ensures all instances have the same jobs in-memory
67
- *
68
- * NOTE: This is a simple but not optimal solution for distributed systems.
69
- * TODO: For production multi-instance deployments, consider:
70
- * - Pub/Sub notifications (Redis PUBSUB, Postgres NOTIFY/LISTEN)
71
- * - Dedicated scheduler instance with queue-based execution
72
- * - Service mesh with leader election
73
- * See specs/distributed-scheduler.md for detailed architecture
74
- */
75
- private startJobSyncPolling;
76
- /**
77
- * Start periodic lock renewal (for long-running jobs)
78
- */
79
- private startLockRenewal;
80
- /**
81
- * Stop lock renewal
82
- */
83
- private stopLockRenewal;
84
- /**
85
- * Persist job configuration
86
- */
87
- private persistJob;
88
- /**
89
- * Update job statistics
90
- */
91
- private updateJobStats;
92
- unschedule(jobId: string): Promise<boolean>;
93
- /**
94
- * Recover jobs from store on startup
95
- * Critical for:
96
- * - Restarts: Re-create in-memory schedulers
97
- * - Horizontal scaling: New instances pick up existing jobs
98
- * - Orphaned awaits: Resume flows waiting on schedules
99
- */
100
- private recoverJobs;
101
- /**
102
- * Recover a single job from persisted data
103
- *
104
- * IMPORTANT: This method reconstructs in-memory schedulers (CronJob/setInterval)
105
- * WITHOUT calling schedule() to avoid re-persisting handler functions (which
106
- * cannot be serialized). Handlers are reconstructed from metadata where possible.
107
- */
108
- private recoverJob;
109
- /**
110
- * Recover well-known job patterns when index scan is not available
111
- * This includes:
112
- * - stall-detection (always exists)
113
- * - await-time-* (flows waiting on time delays)
114
- * - await-schedule-* (flows waiting on cron schedules)
115
- */
116
- private recoverWellKnownJobs;
117
- start(): Promise<void>;
118
- stop(): Promise<void>;
119
- getScheduledJobs(): Promise<ScheduledJob[]>;
120
- /**
121
- * Get jobs by pattern (e.g., by runId)
122
- * This queries the persisted store, not just in-memory jobs
123
- * Works across all instances in a distributed setup
124
- */
125
- getJobsByPattern(pattern: string): Promise<ScheduledJob[]>;
126
- /**
127
- * Get all persisted jobs from store (for debugging/monitoring)
128
- * This shows ALL jobs across ALL instances with their runtime stats
129
- */
130
- getAllPersistedJobs(): Promise<ScheduledJob[]>;
131
- isHealthy(): Promise<boolean>;
132
- }