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,55 +0,0 @@
1
- import { defineNitroPlugin, $useTriggerRegistry, useNventLogger, useTrigger } from "#imports";
2
- import { getEventBus } from "../../events/eventBus.js";
3
- export default defineNitroPlugin(async (nitroApp) => {
4
- nitroApp.hooks.hook("nvent:adapters:ready", async () => {
5
- const logger = useNventLogger("trigger-registration");
6
- const eventBus = getEventBus();
7
- const trigger = useTrigger();
8
- try {
9
- logger.info("Registering build-time triggers...");
10
- const triggerRegistry = $useTriggerRegistry();
11
- const subscriptions = triggerRegistry?.subscriptions || [];
12
- const triggers = triggerRegistry?.triggers || [];
13
- logger.info(`Found ${triggers.length} triggers and ${subscriptions.length} subscriptions from build`);
14
- let newTriggers = 0;
15
- for (const triggerData of triggers) {
16
- if (!trigger.hasTrigger(triggerData.name)) {
17
- await eventBus.publish({
18
- type: "trigger.registered",
19
- triggerName: triggerData.name,
20
- data: triggerData
21
- });
22
- newTriggers++;
23
- } else {
24
- logger.debug(`Trigger '${triggerData.name}' already registered, skipping`);
25
- }
26
- }
27
- let newSubscriptions = 0;
28
- for (const sub of subscriptions) {
29
- const existing = trigger.getSubscription(sub.triggerName, sub.flowName);
30
- if (!existing) {
31
- await eventBus.publish({
32
- type: "subscription.added",
33
- triggerName: sub.triggerName,
34
- data: {
35
- trigger: sub.triggerName,
36
- flow: sub.flowName,
37
- mode: sub.mode,
38
- source: "build-time"
39
- }
40
- });
41
- newSubscriptions++;
42
- } else {
43
- logger.debug(`Subscription '${sub.flowName}' -> '${sub.triggerName}' already exists, skipping`);
44
- }
45
- }
46
- logger.info(
47
- `Build-time trigger registration complete (${newTriggers} new triggers, ${newSubscriptions} new subscriptions)`
48
- );
49
- } catch (error) {
50
- logger.error("Failed to register build-time triggers", {
51
- error: error instanceof Error ? error.message : String(error)
52
- });
53
- }
54
- });
55
- });
@@ -1,23 +0,0 @@
1
- /**
2
- * Dynamic webhook handler for await patterns
3
- * Handles webhook calls and resolves awaiting steps
4
- *
5
- * Routes:
6
- * - POST /api/_webhook/await/{flowName}/{runId}/{stepName}
7
- * - GET /api/_webhook/await/{flowName}/{runId}/{stepName}
8
- *
9
- * Architecture:
10
- * 1. Parse URL params to get flowName, runId, stepName
11
- * 2. Look up flow in store index to verify it exists and is awaiting
12
- * 3. Verify flow status and await configuration
13
- * 4. Use useAwait().webhook.resolve() which publishes await.resolved event
14
- * 5. Trigger wiring handles the actual flow resumption
15
- */
16
- declare const _default: import("h3").EventHandler<import("h3").EventHandlerRequest, Promise<{
17
- success: boolean;
18
- runId: string;
19
- stepName: string;
20
- flowName: string;
21
- message: string;
22
- }>>;
23
- export default _default;
@@ -1,112 +0,0 @@
1
- import { defineEventHandler, readBody, getRouterParams, createError, setResponseStatus } from "h3";
2
- import { useStoreAdapter, useStreamTopics, useNventLogger, useAwait } from "#imports";
3
- export default defineEventHandler(async (event) => {
4
- const logger = useNventLogger("webhook-handler");
5
- const store = useStoreAdapter();
6
- const await$ = useAwait();
7
- const { StoreSubjects } = useStreamTopics();
8
- const params = getRouterParams(event);
9
- const flowName = params.flowName;
10
- const runId = params.runId;
11
- const stepName = params.stepName;
12
- if (!flowName || !runId || !stepName) {
13
- logger.warn("Missing required webhook parameters", { params });
14
- throw createError({
15
- statusCode: 400,
16
- statusMessage: "Invalid webhook path",
17
- message: "Webhook path must include flowName, runId, and stepName"
18
- });
19
- }
20
- logger.info(`Webhook received: ${event.method} for ${flowName}/${runId}/${stepName}`);
21
- const indexKey = StoreSubjects.flowRunIndex(flowName);
22
- const flowEntry = await store.index.get?.(indexKey, runId);
23
- if (!flowEntry) {
24
- logger.warn(`Flow not found`, { flowName, runId, stepName });
25
- setResponseStatus(event, 404);
26
- throw createError({
27
- statusCode: 404,
28
- statusMessage: "Flow not found",
29
- message: "The flow associated with this webhook no longer exists."
30
- });
31
- }
32
- const status = flowEntry.metadata?.status;
33
- if (status && status !== "running" && status !== "awaiting") {
34
- logger.warn(`Flow is not running or awaiting`, { flowName, runId, stepName, status });
35
- setResponseStatus(event, 410);
36
- throw createError({
37
- statusCode: 410,
38
- statusMessage: `Flow is ${status}`,
39
- message: `This webhook is no longer valid because the flow is ${status}.`
40
- });
41
- }
42
- const awaitingSteps = flowEntry.metadata?.awaitingSteps || {};
43
- const awaitKeyBefore = `${stepName}:before`;
44
- const awaitKeyAfter = `${stepName}:after`;
45
- let awaitState = null;
46
- let position = "before";
47
- const awaitStateBefore = awaitingSteps[awaitKeyBefore];
48
- if (awaitStateBefore && awaitStateBefore.status === "awaiting") {
49
- awaitState = awaitStateBefore;
50
- position = "before";
51
- }
52
- if (!awaitState) {
53
- const awaitStateAfter = awaitingSteps[awaitKeyAfter];
54
- if (awaitStateAfter && awaitStateAfter.status === "awaiting") {
55
- awaitState = awaitStateAfter;
56
- position = "after";
57
- }
58
- }
59
- if (!awaitState) {
60
- const legacyAwaitState = awaitingSteps[stepName];
61
- if (legacyAwaitState && legacyAwaitState.status === "awaiting") {
62
- awaitState = legacyAwaitState;
63
- position = "after";
64
- }
65
- }
66
- if (!awaitState) {
67
- logger.warn(`Step is not awaiting`, { flowName, runId, stepName, awaitingSteps });
68
- setResponseStatus(event, 410);
69
- throw createError({
70
- statusCode: 410,
71
- statusMessage: "Step is not awaiting",
72
- message: "This webhook has already been called or the await has expired."
73
- });
74
- }
75
- if (awaitState.awaitType !== "webhook") {
76
- logger.warn(`Step is not waiting for webhook`, { flowName, runId, stepName, awaitType: awaitState.awaitType });
77
- throw createError({
78
- statusCode: 400,
79
- statusMessage: "Invalid await type",
80
- message: `This step is waiting for ${awaitState.awaitType}, not a webhook.`
81
- });
82
- }
83
- const expectedMethod = awaitState.config?.method || "POST";
84
- if (event.method !== expectedMethod) {
85
- logger.warn(`Method mismatch: expected ${expectedMethod}, got ${event.method}`, { flowName, runId, stepName });
86
- throw createError({
87
- statusCode: 405,
88
- statusMessage: "Method Not Allowed",
89
- message: `This webhook expects ${expectedMethod} requests.`
90
- });
91
- }
92
- let webhookData;
93
- if (event.method === "GET") {
94
- webhookData = getRouterParams(event, { decode: true });
95
- } else {
96
- webhookData = await readBody(event).catch(() => ({}));
97
- }
98
- logger.debug(`Webhook data received`, {
99
- runId,
100
- stepName,
101
- dataKeys: Object.keys(webhookData || {})
102
- });
103
- await await$.webhook.resolve(runId, stepName, flowName, position, webhookData);
104
- logger.info(`Webhook await resolved`, { flowName, runId, stepName });
105
- return {
106
- success: true,
107
- runId,
108
- stepName,
109
- flowName,
110
- message: "Webhook processed successfully. Flow will resume shortly."
111
- };
112
- });
@@ -1,86 +0,0 @@
1
- /**
2
- * Dynamic webhook trigger handler for entry triggers (flow-scoped)
3
- * Receives webhook calls and fires triggers to start flows
4
- *
5
- * Routes:
6
- * - POST /api/_webhook/trigger/{triggerName}
7
- * - GET /api/_webhook/trigger/{triggerName}
8
- *
9
- * Different from await webhooks:
10
- * - Entry triggers are flow-scoped (start new flow runs)
11
- * - Await webhooks are run-scoped (resume specific steps)
12
- */
13
- declare const _default: import("h3").EventHandler<import("h3").EventHandlerRequest, Promise<{
14
- error: string;
15
- message: string;
16
- triggerName?: undefined;
17
- expectedType?: undefined;
18
- actualType?: undefined;
19
- status?: undefined;
20
- expectedMethod?: undefined;
21
- actualMethod?: undefined;
22
- success?: undefined;
23
- subscribedFlows?: undefined;
24
- timestamp?: undefined;
25
- } | {
26
- error: string;
27
- triggerName: string;
28
- message: string;
29
- expectedType?: undefined;
30
- actualType?: undefined;
31
- status?: undefined;
32
- expectedMethod?: undefined;
33
- actualMethod?: undefined;
34
- success?: undefined;
35
- subscribedFlows?: undefined;
36
- timestamp?: undefined;
37
- } | {
38
- error: string;
39
- triggerName: string;
40
- expectedType: string;
41
- actualType: any;
42
- message?: undefined;
43
- status?: undefined;
44
- expectedMethod?: undefined;
45
- actualMethod?: undefined;
46
- success?: undefined;
47
- subscribedFlows?: undefined;
48
- timestamp?: undefined;
49
- } | {
50
- error: string;
51
- triggerName: string;
52
- status: any;
53
- message: string;
54
- expectedType?: undefined;
55
- actualType?: undefined;
56
- expectedMethod?: undefined;
57
- actualMethod?: undefined;
58
- success?: undefined;
59
- subscribedFlows?: undefined;
60
- timestamp?: undefined;
61
- } | {
62
- error: string;
63
- expectedMethod: any;
64
- actualMethod: import("h3").HTTPMethod;
65
- message?: undefined;
66
- triggerName?: undefined;
67
- expectedType?: undefined;
68
- actualType?: undefined;
69
- status?: undefined;
70
- success?: undefined;
71
- subscribedFlows?: undefined;
72
- timestamp?: undefined;
73
- } | {
74
- success: boolean;
75
- triggerName: string;
76
- subscribedFlows: any;
77
- message: string;
78
- timestamp: string;
79
- error?: undefined;
80
- expectedType?: undefined;
81
- actualType?: undefined;
82
- status?: undefined;
83
- expectedMethod?: undefined;
84
- actualMethod?: undefined;
85
- }>>;
86
- export default _default;
@@ -1,73 +0,0 @@
1
- import { defineEventHandler, readBody } from "h3";
2
- import { useNventLogger, useTrigger } from "#imports";
3
- export default defineEventHandler(async (event) => {
4
- const logger = useNventLogger("webhook-trigger");
5
- const trigger = useTrigger();
6
- const triggerName = event.context.params?.triggerName;
7
- if (!triggerName) {
8
- logger.warn("No trigger name provided in request");
9
- return {
10
- error: "Missing trigger name",
11
- message: "Trigger name is required"
12
- };
13
- }
14
- logger.info(`Webhook trigger received: ${event.method} ${triggerName}`);
15
- const triggerEntry = trigger.getTrigger(triggerName);
16
- if (!triggerEntry) {
17
- logger.warn(`Trigger not found: ${triggerName}`);
18
- return {
19
- error: "Trigger not found",
20
- triggerName,
21
- message: `No trigger registered with name '${triggerName}'`
22
- };
23
- }
24
- if (triggerEntry.type !== "webhook") {
25
- logger.warn(`Trigger is not a webhook: ${triggerName} (type: ${triggerEntry.type})`);
26
- return {
27
- error: "Invalid trigger type",
28
- triggerName,
29
- expectedType: "webhook",
30
- actualType: triggerEntry.type
31
- };
32
- }
33
- if (triggerEntry.status !== "active") {
34
- logger.info(`Trigger '${triggerName}' is ${triggerEntry.status}, rejecting webhook`);
35
- return {
36
- error: "Trigger not active",
37
- triggerName,
38
- status: triggerEntry.status,
39
- message: `Trigger '${triggerName}' is ${triggerEntry.status}. Update status to 'active' to enable.`
40
- };
41
- }
42
- const expectedMethod = triggerEntry.webhook?.method || "POST";
43
- if (event.method !== expectedMethod) {
44
- logger.warn(`Method mismatch: expected ${expectedMethod}, got ${event.method}`);
45
- return {
46
- error: "Method not allowed",
47
- expectedMethod,
48
- actualMethod: event.method
49
- };
50
- }
51
- let webhookData;
52
- if (event.method === "GET") {
53
- webhookData = event.context.params || {};
54
- } else {
55
- webhookData = await readBody(event);
56
- }
57
- logger.debug(`Webhook data received`, {
58
- triggerName,
59
- dataKeys: Object.keys(webhookData || {})
60
- });
61
- await trigger.emitTrigger(triggerName, webhookData);
62
- logger.info(`Webhook trigger fired`, {
63
- triggerName,
64
- subscribedFlows: trigger.getSubscribedFlows(triggerName).length
65
- });
66
- return {
67
- success: true,
68
- triggerName,
69
- subscribedFlows: trigger.getSubscribedFlows(triggerName),
70
- message: "Trigger fired successfully",
71
- timestamp: (/* @__PURE__ */ new Date()).toISOString()
72
- };
73
- });
@@ -1,66 +0,0 @@
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.stream.append('nq:flow:abc-123', { type: 'step.completed', data: {...} })
40
- * const events = await store.stream.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;
@@ -1,51 +0,0 @@
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
- }
@@ -1,15 +0,0 @@
1
- import type { AwaitConfig } from '../../../../registry/types.js';
2
- /**
3
- * Await Pattern: Event
4
- *
5
- * Waits for a specific event to be emitted (internal or external)
6
- * Useful for cross-flow coordination, external system notifications
7
- */
8
- export declare function registerEventAwait(runId: string, stepName: string, flowName: string, config: AwaitConfig, position?: 'before' | 'after'): Promise<{
9
- eventName: string;
10
- timeout: number | undefined;
11
- }>;
12
- /**
13
- * Resolve event await when target event is received
14
- */
15
- export declare function resolveEventAwait(runId: string, stepName: string, flowName: string, position: 'before' | 'after', eventData: any): Promise<void>;
@@ -1,128 +0,0 @@
1
- import { useNventLogger, useScheduler } from "#imports";
2
- import { getEventBus } from "../../../events/eventBus.js";
3
- export async function registerEventAwait(runId, stepName, flowName, config, position = "after") {
4
- const logger = useNventLogger("await-event");
5
- const eventBus = getEventBus();
6
- if (!config.event) {
7
- throw new Error("Event await requires event name configuration");
8
- }
9
- logger.info(`Registering event await: ${config.event}`, { runId, stepName });
10
- const unsubscribe = eventBus.onType(config.event, async (event) => {
11
- if (config.filterKey) {
12
- const awaitValue = event.data?.[config.filterKey];
13
- const stepValue = event.data?.stepData?.[config.filterKey];
14
- if (awaitValue !== stepValue) {
15
- return;
16
- }
17
- }
18
- await resolveEventAwait(runId, stepName, flowName, position, event.data);
19
- unsubscribe();
20
- });
21
- const { useAwaitDefaults } = await import("../useAwait.js");
22
- const { eventTimeout: defaultTimeout, timeoutAction: defaultTimeoutAction } = useAwaitDefaults();
23
- const timeoutMs = config.timeout && config.timeout > 0 ? config.timeout : defaultTimeout;
24
- eventBus.publish({
25
- type: "await.registered",
26
- flowName,
27
- runId,
28
- stepName,
29
- awaitType: "event",
30
- position,
31
- config,
32
- data: {
33
- position,
34
- // Store position in data for database persistence
35
- eventName: config.event,
36
- filterKey: config.filterKey,
37
- timeout: timeoutMs,
38
- // Store resolved timeout (with default)
39
- registeredAt: Date.now(),
40
- timeoutAction: config.timeoutAction || defaultTimeoutAction
41
- }
42
- });
43
- const scheduler = useScheduler();
44
- const timeoutAt = Date.now() + timeoutMs;
45
- const jobId = `await-event-timeout-${runId}-${stepName}-${position}`;
46
- await scheduler.schedule({
47
- id: jobId,
48
- name: `Event Await Timeout: ${flowName} - ${stepName}`,
49
- type: "one-time",
50
- executeAt: timeoutAt,
51
- handler: async () => {
52
- logger.warn("Event await timeout", {
53
- runId,
54
- stepName,
55
- flowName,
56
- eventName: config.event,
57
- timeout: timeoutMs,
58
- timeoutAction: config.timeoutAction || "fail"
59
- });
60
- eventBus.publish({
61
- type: "await.timeout",
62
- flowName,
63
- runId,
64
- stepName,
65
- position,
66
- awaitType: "event",
67
- timeoutAction: config.timeoutAction || "fail",
68
- data: {
69
- eventName: config.event,
70
- timeout: timeoutMs,
71
- registeredAt: Date.now() - timeoutMs,
72
- timedOutAt: Date.now()
73
- }
74
- });
75
- unsubscribe();
76
- },
77
- metadata: {
78
- component: "await-pattern",
79
- awaitType: "event",
80
- runId,
81
- stepName,
82
- flowName,
83
- position,
84
- timeout: timeoutMs,
85
- eventName: config.event
86
- }
87
- });
88
- logger.debug(`Event timeout scheduled`, {
89
- runId,
90
- stepName,
91
- eventName: config.event,
92
- timeout: timeoutMs,
93
- timeoutAction: config.timeoutAction,
94
- isDefault: !config.timeout || config.timeout <= 0
95
- });
96
- logger.debug(`Event await registered: ${config.event}`, { runId, stepName });
97
- return {
98
- eventName: config.event,
99
- timeout: config.timeout
100
- };
101
- }
102
- export async function resolveEventAwait(runId, stepName, flowName, position, eventData) {
103
- const logger = useNventLogger("await-event");
104
- const eventBus = getEventBus();
105
- const scheduler = useScheduler();
106
- logger.info(`Resolving event await`, { runId, stepName });
107
- const jobId = `await-event-timeout-${runId}-${stepName}-${position}`;
108
- try {
109
- await scheduler.unschedule(jobId);
110
- logger.debug("Unscheduled event timeout job", { runId, stepName, jobId });
111
- } catch {
112
- logger.debug("Could not unschedule timeout job (may not exist)", { runId, stepName, jobId });
113
- }
114
- eventBus.publish({
115
- type: "await.resolved",
116
- flowName,
117
- runId,
118
- stepName,
119
- position,
120
- triggerData: eventData,
121
- data: {
122
- position,
123
- // Store position in data for database persistence
124
- resolvedAt: Date.now()
125
- }
126
- });
127
- logger.debug(`Event await resolved`, { runId, stepName });
128
- }
@@ -1,28 +0,0 @@
1
- import type { AwaitConfig } from '../../../../registry/types.js';
2
- import { registerWebhookAwait, resolveWebhookAwait } from './webhook.js';
3
- import { registerEventAwait, resolveEventAwait } from './event.js';
4
- import { registerScheduleAwait, resolveScheduleAwait } from './schedule.js';
5
- import { registerTimeAwait, resolveTimeAwait } from './time.js';
6
- /**
7
- * Unified await pattern registry
8
- * Routes to appropriate await implementation based on type
9
- */
10
- export declare function registerAwaitPattern(runId: string, stepName: string, flowName: string, config: AwaitConfig, position?: 'before' | 'after'): Promise<{
11
- delay: number;
12
- resolveAt: number;
13
- } | {
14
- cron: string;
15
- nextOccurrence: number;
16
- timeUntilNext: number;
17
- } | {
18
- webhookUrl: string;
19
- timeout: number | undefined;
20
- } | {
21
- eventName: string;
22
- timeout: number | undefined;
23
- }>;
24
- /**
25
- * Resolve await pattern by type
26
- */
27
- export declare function resolveAwaitPattern(type: 'webhook' | 'event' | 'schedule' | 'time', runId: string, stepName: string, flowName: string, position: 'before' | 'after', data: any): Promise<void>;
28
- export { registerWebhookAwait, resolveWebhookAwait, registerEventAwait, resolveEventAwait, registerScheduleAwait, resolveScheduleAwait, registerTimeAwait, resolveTimeAwait, };