nvent 0.4.3 → 0.4.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (234) hide show
  1. package/dist/module.d.mts +3 -184
  2. package/dist/module.json +3 -3
  3. package/dist/module.mjs +133 -197
  4. package/dist/runtime/adapters/builtin/file-queue.d.ts +53 -0
  5. package/dist/runtime/adapters/builtin/file-queue.js +435 -0
  6. package/dist/runtime/adapters/builtin/file-store.d.ts +46 -0
  7. package/dist/runtime/adapters/builtin/file-store.js +225 -0
  8. package/dist/runtime/adapters/builtin/file-stream.d.ts +39 -0
  9. package/dist/runtime/adapters/builtin/file-stream.js +56 -0
  10. package/dist/runtime/adapters/builtin/index.d.ts +10 -0
  11. package/dist/runtime/adapters/builtin/index.js +5 -0
  12. package/dist/runtime/adapters/builtin/memory-queue.d.ts +52 -0
  13. package/dist/runtime/adapters/builtin/memory-queue.js +239 -0
  14. package/dist/runtime/adapters/builtin/memory-store.d.ts +57 -0
  15. package/dist/runtime/adapters/builtin/memory-store.js +263 -0
  16. package/dist/runtime/adapters/builtin/memory-stream.d.ts +21 -0
  17. package/dist/runtime/adapters/builtin/memory-stream.js +56 -0
  18. package/dist/runtime/adapters/factory.d.ts +31 -0
  19. package/dist/runtime/adapters/factory.js +100 -0
  20. package/dist/runtime/adapters/index.d.ts +8 -0
  21. package/dist/runtime/adapters/index.js +3 -0
  22. package/dist/runtime/adapters/interfaces/index.d.ts +11 -0
  23. package/dist/runtime/adapters/interfaces/index.js +3 -0
  24. package/dist/runtime/adapters/interfaces/queue.d.ts +150 -0
  25. package/dist/runtime/adapters/interfaces/store.d.ts +233 -0
  26. package/dist/runtime/adapters/interfaces/stream.d.ts +62 -0
  27. package/dist/runtime/adapters/registry.d.ts +85 -0
  28. package/dist/runtime/adapters/registry.js +161 -0
  29. package/dist/runtime/config/index.d.ts +29 -0
  30. package/dist/runtime/config/index.js +167 -0
  31. package/dist/runtime/config/types.d.ts +367 -0
  32. package/dist/runtime/config/types.js +0 -0
  33. package/dist/runtime/events/types.d.ts +116 -0
  34. package/dist/runtime/events/types.js +0 -0
  35. package/dist/runtime/events/utils/stallDetector.d.ts +99 -0
  36. package/dist/runtime/events/utils/stallDetector.js +237 -0
  37. package/dist/runtime/{server-utils/events → events}/wiring/flowWiring.d.ts +3 -8
  38. package/dist/runtime/{server-utils/events → events}/wiring/flowWiring.js +119 -36
  39. package/dist/runtime/events/wiring/registry.d.ts +19 -0
  40. package/dist/runtime/events/wiring/registry.js +33 -0
  41. package/dist/runtime/events/wiring/stateWiring.d.ts +37 -0
  42. package/dist/runtime/events/wiring/stateWiring.js +92 -0
  43. package/dist/runtime/events/wiring/streamWiring.d.ts +32 -0
  44. package/dist/runtime/events/wiring/streamWiring.js +79 -0
  45. package/dist/runtime/server/api/_flows/[name]/clear-history.delete.js +16 -5
  46. package/dist/runtime/server/api/_flows/[name]/runs/[runId]/cancel.post.js +21 -0
  47. package/dist/runtime/server/api/_flows/[name]/runs.get.d.ts +12 -2
  48. package/dist/runtime/server/api/_flows/[name]/runs.get.js +15 -4
  49. package/dist/runtime/server/api/_flows/[name]/schedule.post.js +11 -2
  50. package/dist/runtime/server/api/_flows/[name]/schedules/[id].delete.js +21 -16
  51. package/dist/runtime/server/api/_flows/[name]/schedules.get.js +21 -19
  52. package/dist/runtime/server/api/_flows/ws.js +43 -22
  53. package/dist/runtime/server/api/_queues/[name]/job/[id].get.js +8 -3
  54. package/dist/runtime/server/api/_queues/[name]/job/index.get.js +12 -3
  55. package/dist/runtime/server/api/_queues/index.get.js +66 -23
  56. package/dist/runtime/server/api/_queues/ws.js +14 -4
  57. package/dist/runtime/server/plugins/00.adapters.d.ts +14 -0
  58. package/dist/runtime/server/plugins/00.adapters.js +69 -0
  59. package/dist/runtime/server/plugins/02.workers.js +45 -0
  60. package/dist/runtime/tsconfig.json +8 -0
  61. package/dist/runtime/utils/adapters.d.ts +66 -0
  62. package/dist/runtime/utils/adapters.js +51 -0
  63. package/dist/runtime/utils/defineFunction.d.ts +10 -0
  64. package/dist/runtime/{server-utils/utils/defineQueueWorker.js → utils/defineFunction.js} +4 -4
  65. package/dist/runtime/{server-utils/utils/defineQueueConfig.d.ts → utils/defineFunctionConfig.d.ts} +3 -3
  66. package/dist/runtime/utils/defineFunctionConfig.js +2 -0
  67. package/dist/runtime/utils/registerAdapter.d.ts +59 -0
  68. package/dist/runtime/utils/registerAdapter.js +13 -0
  69. package/dist/runtime/utils/useFlowEngine.d.ts +19 -0
  70. package/dist/runtime/utils/useFlowEngine.js +108 -0
  71. package/dist/runtime/{server-utils/utils → utils}/useNventLogger.js +2 -2
  72. package/dist/runtime/utils/useStreamTopics.d.ts +72 -0
  73. package/dist/runtime/utils/useStreamTopics.js +47 -0
  74. package/dist/runtime/{server-utils/worker/runner/node.d.ts → worker/node/runner.d.ts} +18 -2
  75. package/dist/runtime/{server-utils/worker/runner/node.js → worker/node/runner.js} +44 -17
  76. package/dist/types.d.mts +2 -2
  77. package/package.json +14 -44
  78. package/LICENSE +0 -21
  79. package/README.md +0 -389
  80. package/dist/runtime/app/assets/vueflow.css +0 -1
  81. package/dist/runtime/app/components/ConfirmDialog.d.vue.ts +0 -33
  82. package/dist/runtime/app/components/ConfirmDialog.vue +0 -121
  83. package/dist/runtime/app/components/ConfirmDialog.vue.d.ts +0 -33
  84. package/dist/runtime/app/components/FlowDiagram.d.vue.ts +0 -64
  85. package/dist/runtime/app/components/FlowDiagram.vue +0 -338
  86. package/dist/runtime/app/components/FlowDiagram.vue.d.ts +0 -64
  87. package/dist/runtime/app/components/FlowNodeCard.d.vue.ts +0 -29
  88. package/dist/runtime/app/components/FlowNodeCard.vue +0 -156
  89. package/dist/runtime/app/components/FlowNodeCard.vue.d.ts +0 -29
  90. package/dist/runtime/app/components/FlowRunOverview.d.vue.ts +0 -9
  91. package/dist/runtime/app/components/FlowRunOverview.vue +0 -291
  92. package/dist/runtime/app/components/FlowRunOverview.vue.d.ts +0 -9
  93. package/dist/runtime/app/components/FlowRunStatusBadge.d.vue.ts +0 -14
  94. package/dist/runtime/app/components/FlowRunStatusBadge.vue +0 -60
  95. package/dist/runtime/app/components/FlowRunStatusBadge.vue.d.ts +0 -14
  96. package/dist/runtime/app/components/FlowRunTimeline.d.vue.ts +0 -12
  97. package/dist/runtime/app/components/FlowRunTimeline.vue +0 -127
  98. package/dist/runtime/app/components/FlowRunTimeline.vue.d.ts +0 -12
  99. package/dist/runtime/app/components/FlowScheduleDialog.d.vue.ts +0 -16
  100. package/dist/runtime/app/components/FlowScheduleDialog.vue +0 -226
  101. package/dist/runtime/app/components/FlowScheduleDialog.vue.d.ts +0 -16
  102. package/dist/runtime/app/components/FlowSchedulesList.d.vue.ts +0 -12
  103. package/dist/runtime/app/components/FlowSchedulesList.vue +0 -99
  104. package/dist/runtime/app/components/FlowSchedulesList.vue.d.ts +0 -12
  105. package/dist/runtime/app/components/JobScheduling.d.vue.ts +0 -6
  106. package/dist/runtime/app/components/JobScheduling.vue +0 -203
  107. package/dist/runtime/app/components/JobScheduling.vue.d.ts +0 -6
  108. package/dist/runtime/app/components/ListItem.d.vue.ts +0 -23
  109. package/dist/runtime/app/components/ListItem.vue +0 -70
  110. package/dist/runtime/app/components/ListItem.vue.d.ts +0 -23
  111. package/dist/runtime/app/components/QueueConfigDetails.d.vue.ts +0 -45
  112. package/dist/runtime/app/components/QueueConfigDetails.vue +0 -412
  113. package/dist/runtime/app/components/QueueConfigDetails.vue.d.ts +0 -45
  114. package/dist/runtime/app/components/StatCounter.d.vue.ts +0 -9
  115. package/dist/runtime/app/components/StatCounter.vue +0 -25
  116. package/dist/runtime/app/components/StatCounter.vue.d.ts +0 -9
  117. package/dist/runtime/app/components/TimelineList.d.vue.ts +0 -7
  118. package/dist/runtime/app/components/TimelineList.vue +0 -210
  119. package/dist/runtime/app/components/TimelineList.vue.d.ts +0 -7
  120. package/dist/runtime/app/components/nhealth/component-router.d.vue.ts +0 -46
  121. package/dist/runtime/app/components/nhealth/component-router.vue +0 -26
  122. package/dist/runtime/app/components/nhealth/component-router.vue.d.ts +0 -46
  123. package/dist/runtime/app/components/nhealth/component-shell.d.vue.ts +0 -24
  124. package/dist/runtime/app/components/nhealth/component-shell.vue +0 -89
  125. package/dist/runtime/app/components/nhealth/component-shell.vue.d.ts +0 -24
  126. package/dist/runtime/app/composables/useAnalyzedFlows.d.ts +0 -14
  127. package/dist/runtime/app/composables/useAnalyzedFlows.js +0 -8
  128. package/dist/runtime/app/composables/useComponentRouter.d.ts +0 -38
  129. package/dist/runtime/app/composables/useComponentRouter.js +0 -240
  130. package/dist/runtime/app/composables/useFlowRunTimeline.d.ts +0 -15
  131. package/dist/runtime/app/composables/useFlowRunTimeline.js +0 -66
  132. package/dist/runtime/app/composables/useFlowRuns.d.ts +0 -18
  133. package/dist/runtime/app/composables/useFlowRuns.js +0 -32
  134. package/dist/runtime/app/composables/useFlowRunsInfinite.d.ts +0 -24
  135. package/dist/runtime/app/composables/useFlowRunsInfinite.js +0 -123
  136. package/dist/runtime/app/composables/useFlowRunsPolling.d.ts +0 -9
  137. package/dist/runtime/app/composables/useFlowRunsPolling.js +0 -33
  138. package/dist/runtime/app/composables/useFlowState.d.ts +0 -125
  139. package/dist/runtime/app/composables/useFlowState.js +0 -211
  140. package/dist/runtime/app/composables/useFlowWebSocket.d.ts +0 -27
  141. package/dist/runtime/app/composables/useFlowWebSocket.js +0 -205
  142. package/dist/runtime/app/composables/useFlowsNavigation.d.ts +0 -10
  143. package/dist/runtime/app/composables/useFlowsNavigation.js +0 -58
  144. package/dist/runtime/app/composables/useQueueJobs.d.ts +0 -20
  145. package/dist/runtime/app/composables/useQueueJobs.js +0 -20
  146. package/dist/runtime/app/composables/useQueueUpdates.d.ts +0 -26
  147. package/dist/runtime/app/composables/useQueueUpdates.js +0 -122
  148. package/dist/runtime/app/composables/useQueues.d.ts +0 -44
  149. package/dist/runtime/app/composables/useQueues.js +0 -26
  150. package/dist/runtime/app/composables/useQueuesLive.d.ts +0 -19
  151. package/dist/runtime/app/composables/useQueuesLive.js +0 -143
  152. package/dist/runtime/app/pages/flows/index.d.vue.ts +0 -3
  153. package/dist/runtime/app/pages/flows/index.vue +0 -645
  154. package/dist/runtime/app/pages/flows/index.vue.d.ts +0 -3
  155. package/dist/runtime/app/pages/index.d.vue.ts +0 -3
  156. package/dist/runtime/app/pages/index.vue +0 -34
  157. package/dist/runtime/app/pages/index.vue.d.ts +0 -3
  158. package/dist/runtime/app/pages/queues/index.d.vue.ts +0 -3
  159. package/dist/runtime/app/pages/queues/index.vue +0 -229
  160. package/dist/runtime/app/pages/queues/index.vue.d.ts +0 -3
  161. package/dist/runtime/app/pages/queues/job.d.vue.ts +0 -3
  162. package/dist/runtime/app/pages/queues/job.vue +0 -262
  163. package/dist/runtime/app/pages/queues/job.vue.d.ts +0 -3
  164. package/dist/runtime/app/pages/queues/jobs.d.vue.ts +0 -3
  165. package/dist/runtime/app/pages/queues/jobs.vue +0 -291
  166. package/dist/runtime/app/pages/queues/jobs.vue.d.ts +0 -3
  167. package/dist/runtime/app/plugins/vueflow.client.d.ts +0 -2
  168. package/dist/runtime/app/plugins/vueflow.client.js +0 -11
  169. package/dist/runtime/constants.d.ts +0 -11
  170. package/dist/runtime/constants.js +0 -11
  171. package/dist/runtime/schema.d.ts +0 -37
  172. package/dist/runtime/schema.js +0 -20
  173. package/dist/runtime/server/plugins/00.event-store.d.ts +0 -13
  174. package/dist/runtime/server/plugins/00.event-store.js +0 -16
  175. package/dist/runtime/server/plugins/flow-management.d.ts +0 -13
  176. package/dist/runtime/server/plugins/flow-management.js +0 -65
  177. package/dist/runtime/server/plugins/queue-management.js +0 -27
  178. package/dist/runtime/server/plugins/state-cleanup.d.ts +0 -11
  179. package/dist/runtime/server/plugins/state-cleanup.js +0 -93
  180. package/dist/runtime/server/plugins/worker-management.js +0 -33
  181. package/dist/runtime/server/tsconfig.json +0 -3
  182. package/dist/runtime/server-utils/events/adapters/fileAdapter.d.ts +0 -2
  183. package/dist/runtime/server-utils/events/adapters/fileAdapter.js +0 -382
  184. package/dist/runtime/server-utils/events/adapters/memoryAdapter.d.ts +0 -2
  185. package/dist/runtime/server-utils/events/adapters/memoryAdapter.js +0 -171
  186. package/dist/runtime/server-utils/events/adapters/redis/redisAdapter.d.ts +0 -2
  187. package/dist/runtime/server-utils/events/adapters/redis/redisAdapter.js +0 -348
  188. package/dist/runtime/server-utils/events/adapters/redis/redisPubSubGateway.d.ts +0 -30
  189. package/dist/runtime/server-utils/events/adapters/redis/redisPubSubGateway.js +0 -82
  190. package/dist/runtime/server-utils/events/eventStoreFactory.d.ts +0 -19
  191. package/dist/runtime/server-utils/events/eventStoreFactory.js +0 -44
  192. package/dist/runtime/server-utils/events/streamNames.d.ts +0 -17
  193. package/dist/runtime/server-utils/events/streamNames.js +0 -17
  194. package/dist/runtime/server-utils/events/types.d.ts +0 -63
  195. package/dist/runtime/server-utils/events/wiring/registry.d.ts +0 -10
  196. package/dist/runtime/server-utils/events/wiring/registry.js +0 -24
  197. package/dist/runtime/server-utils/queue/adapters/bullmq.d.ts +0 -18
  198. package/dist/runtime/server-utils/queue/adapters/bullmq.js +0 -164
  199. package/dist/runtime/server-utils/queue/queueFactory.d.ts +0 -3
  200. package/dist/runtime/server-utils/queue/queueFactory.js +0 -10
  201. package/dist/runtime/server-utils/queue/types.d.ts +0 -47
  202. package/dist/runtime/server-utils/state/adapters/redis.d.ts +0 -2
  203. package/dist/runtime/server-utils/state/adapters/redis.js +0 -42
  204. package/dist/runtime/server-utils/state/stateFactory.d.ts +0 -3
  205. package/dist/runtime/server-utils/state/stateFactory.js +0 -17
  206. package/dist/runtime/server-utils/state/types.d.ts +0 -23
  207. package/dist/runtime/server-utils/utils/defineQueueConfig.js +0 -2
  208. package/dist/runtime/server-utils/utils/defineQueueWorker.d.ts +0 -10
  209. package/dist/runtime/server-utils/utils/useEventStore.d.ts +0 -20
  210. package/dist/runtime/server-utils/utils/useEventStore.js +0 -119
  211. package/dist/runtime/server-utils/utils/useFlowEngine.d.ts +0 -9
  212. package/dist/runtime/server-utils/utils/useFlowEngine.js +0 -44
  213. package/dist/runtime/server-utils/utils/useLogs.d.ts +0 -41
  214. package/dist/runtime/server-utils/utils/useLogs.js +0 -74
  215. package/dist/runtime/server-utils/utils/useQueue.d.ts +0 -31
  216. package/dist/runtime/server-utils/utils/useQueue.js +0 -24
  217. package/dist/runtime/server-utils/worker/adapter.d.ts +0 -4
  218. package/dist/runtime/server-utils/worker/adapter.js +0 -66
  219. package/dist/runtime/types.d.ts +0 -132
  220. /package/dist/runtime/{server-utils/events/types.js → adapters/interfaces/queue.js} +0 -0
  221. /package/dist/runtime/{server-utils/queue/types.js → adapters/interfaces/store.js} +0 -0
  222. /package/dist/runtime/{server-utils/state/types.js → adapters/interfaces/stream.js} +0 -0
  223. /package/dist/runtime/{server-utils/events → events}/eventBus.d.ts +0 -0
  224. /package/dist/runtime/{server-utils/events → events}/eventBus.js +0 -0
  225. /package/dist/runtime/server/{plugins/queue-management.d.ts → api/_flows/[name]/runs/[runId]/cancel.post.d.ts} +0 -0
  226. /package/dist/runtime/server/plugins/{00.ws-lifecycle.d.ts → 01.ws-lifecycle.d.ts} +0 -0
  227. /package/dist/runtime/server/plugins/{00.ws-lifecycle.js → 01.ws-lifecycle.js} +0 -0
  228. /package/dist/runtime/server/plugins/{worker-management.d.ts → 02.workers.d.ts} +0 -0
  229. /package/dist/runtime/{server-utils/utils → utils}/useEventManager.d.ts +0 -0
  230. /package/dist/runtime/{server-utils/utils → utils}/useEventManager.js +0 -0
  231. /package/dist/runtime/{server-utils/utils → utils}/useNventLogger.d.ts +0 -0
  232. /package/dist/runtime/{server-utils/utils → utils}/wsPeerManager.d.ts +0 -0
  233. /package/dist/runtime/{server-utils/utils → utils}/wsPeerManager.js +0 -0
  234. /package/dist/runtime/{python → worker/python}/get_config.py +0 -0
@@ -0,0 +1,39 @@
1
+ /**
2
+ * File Stream Adapter
3
+ *
4
+ * DEPRECATED: This adapter is identical to MemoryStreamAdapter
5
+ *
6
+ * For file-based deployments (single instance):
7
+ * - StreamAdapter is NOT needed for cross-instance pub/sub
8
+ * - StoreAdapter.subscribe() handles in-process subscriptions
9
+ * - StoreAdapter handles ALL persistence (events, documents, KV)
10
+ *
11
+ * This adapter exists only for API compatibility.
12
+ * Use MemoryStreamAdapter instead - it's the same implementation.
13
+ */
14
+ import type { StreamAdapter, StreamEvent, SubscribeOptions, SubscriptionHandle } from '../interfaces/stream.js';
15
+ /**
16
+ * @deprecated Use MemoryStreamAdapter instead. FileStreamAdapter is identical.
17
+ */
18
+ export interface FileStreamAdapterOptions {
19
+ dataDir?: string;
20
+ }
21
+ /**
22
+ * @deprecated Use MemoryStreamAdapter instead
23
+ *
24
+ * Pure in-memory pub/sub (same as MemoryStreamAdapter)
25
+ * - No persistence (StoreAdapter handles that)
26
+ * - Single instance only
27
+ * - Events lost if no subscribers
28
+ */
29
+ export declare class FileStreamAdapter implements StreamAdapter {
30
+ private subscriptions;
31
+ private subscriptionCounter;
32
+ init(): Promise<void>;
33
+ publish(topic: string, event: StreamEvent): Promise<void>;
34
+ subscribe(topic: string, handler: (event: StreamEvent) => void | Promise<void>, _opts?: SubscribeOptions): Promise<SubscriptionHandle>;
35
+ unsubscribe(handle: SubscriptionHandle): Promise<void>;
36
+ listTopics(): Promise<string[]>;
37
+ getSubscriptionCount(topic: string): Promise<number>;
38
+ shutdown(): Promise<void>;
39
+ }
@@ -0,0 +1,56 @@
1
+ export class FileStreamAdapter {
2
+ subscriptions = /* @__PURE__ */ new Map();
3
+ subscriptionCounter = 0;
4
+ async init() {
5
+ }
6
+ async publish(topic, event) {
7
+ const topicSubscriptions = this.subscriptions.get(topic);
8
+ if (!topicSubscriptions || topicSubscriptions.size === 0) {
9
+ return;
10
+ }
11
+ const eventWithTs = {
12
+ ...event,
13
+ timestamp: event.timestamp || Date.now()
14
+ };
15
+ const promises = [];
16
+ Array.from(topicSubscriptions.values()).forEach((handler) => {
17
+ promises.push(handler(eventWithTs));
18
+ });
19
+ await Promise.all(promises);
20
+ }
21
+ async subscribe(topic, handler, _opts) {
22
+ const subscriptionId = `sub-${++this.subscriptionCounter}`;
23
+ if (!this.subscriptions.has(topic)) {
24
+ this.subscriptions.set(topic, /* @__PURE__ */ new Map());
25
+ }
26
+ const topicSubscriptions = this.subscriptions.get(topic);
27
+ topicSubscriptions.set(subscriptionId, handler);
28
+ return {
29
+ id: subscriptionId,
30
+ topic,
31
+ unsubscribe: async () => {
32
+ await this.unsubscribe({ id: subscriptionId, topic, unsubscribe: async () => {
33
+ } });
34
+ }
35
+ };
36
+ }
37
+ async unsubscribe(handle) {
38
+ const topicSubscriptions = this.subscriptions.get(handle.topic);
39
+ if (topicSubscriptions) {
40
+ topicSubscriptions.delete(handle.id);
41
+ if (topicSubscriptions.size === 0) {
42
+ this.subscriptions.delete(handle.topic);
43
+ }
44
+ }
45
+ }
46
+ async listTopics() {
47
+ return Array.from(this.subscriptions.keys());
48
+ }
49
+ async getSubscriptionCount(topic) {
50
+ const topicSubscriptions = this.subscriptions.get(topic);
51
+ return topicSubscriptions ? topicSubscriptions.size : 0;
52
+ }
53
+ async shutdown() {
54
+ this.subscriptions.clear();
55
+ }
56
+ }
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Built-in Adapters
3
+ *
4
+ * In-memory and file-based adapters for development (no external dependencies)
5
+ */
6
+ export { MemoryQueueAdapter } from './memory-queue.js';
7
+ export { MemoryStreamAdapter } from './memory-stream.js';
8
+ export { MemoryStoreAdapter } from './memory-store.js';
9
+ export { FileQueueAdapter } from './file-queue.js';
10
+ export { FileStoreAdapter } from './file-store.js';
@@ -0,0 +1,5 @@
1
+ export { MemoryQueueAdapter } from "./memory-queue.js";
2
+ export { MemoryStreamAdapter } from "./memory-stream.js";
3
+ export { MemoryStoreAdapter } from "./memory-store.js";
4
+ export { FileQueueAdapter } from "./file-queue.js";
5
+ export { FileStoreAdapter } from "./file-store.js";
@@ -0,0 +1,52 @@
1
+ /**
2
+ * Memory Queue Adapter
3
+ *
4
+ * In-memory queue implementation using fastq for development
5
+ * - Fast and simple
6
+ * - No external dependencies beyond fastq
7
+ * - Data lost on restart
8
+ * - Single instance only
9
+ *
10
+ * Architecture:
11
+ * - QueueAdapter: Manages job storage and queue events
12
+ * - WorkerManager: Executes jobs using fastq
13
+ * - Dispatcher pattern: Routes jobs to handlers by job.name
14
+ */
15
+ import type { QueueAdapter, JobInput, Job, JobsQuery, ScheduleOptions, JobCounts, QueueEvent, WorkerHandler, WorkerOptions } from '../interfaces/queue.js';
16
+ export interface MemoryQueueAdapterOptions {
17
+ maxQueueSize?: number;
18
+ }
19
+ export declare class MemoryQueueAdapter implements QueueAdapter {
20
+ private jobs;
21
+ private eventListeners;
22
+ private workers;
23
+ private options;
24
+ constructor(options?: MemoryQueueAdapterOptions);
25
+ init(): Promise<void>;
26
+ enqueue(queueName: string, job: JobInput): Promise<string>;
27
+ schedule(queueName: string, job: JobInput, opts?: ScheduleOptions): Promise<string>;
28
+ getJob(_queueName: string, id: string): Promise<Job | null>;
29
+ getJobs(queueName: string, query?: JobsQuery): Promise<Job[]>;
30
+ on(queueName: string, event: QueueEvent, callback: (payload: any) => void): () => void;
31
+ isPaused(queueName: string): Promise<boolean>;
32
+ getJobCounts(queueName: string): Promise<JobCounts>;
33
+ pause(queueName: string): Promise<void>;
34
+ resume(queueName: string): Promise<void>;
35
+ close(): Promise<void>;
36
+ /**
37
+ * Register a worker handler for a queue
38
+ * This is called by the worker registration system
39
+ */
40
+ registerWorker(queueName: string, jobName: string, handler: WorkerHandler, opts?: WorkerOptions): void;
41
+ /**
42
+ * Start processing waiting jobs for a queue
43
+ * Should be called after all handlers are registered
44
+ */
45
+ startProcessingQueue(queueName: string): void;
46
+ /**
47
+ * Update job state (called internally and by worker manager)
48
+ */
49
+ updateJobState(jobId: string, state: Job['state'], extra?: Partial<Job>): void;
50
+ private emitEvent;
51
+ private generateId;
52
+ }
@@ -0,0 +1,239 @@
1
+ import * as fastq from "fastq";
2
+ export class MemoryQueueAdapter {
3
+ jobs = /* @__PURE__ */ new Map();
4
+ eventListeners = /* @__PURE__ */ new Map();
5
+ workers = /* @__PURE__ */ new Map();
6
+ options;
7
+ constructor(options = {}) {
8
+ this.options = {
9
+ maxQueueSize: options.maxQueueSize || 1e3
10
+ };
11
+ }
12
+ async init() {
13
+ }
14
+ async enqueue(queueName, job) {
15
+ const jobId = job.opts?.jobId || this.generateId();
16
+ if (this.jobs.has(jobId)) {
17
+ return jobId;
18
+ }
19
+ if (this.jobs.size >= this.options.maxQueueSize) {
20
+ throw new Error(`Queue ${queueName} is full (max: ${this.options.maxQueueSize})`);
21
+ }
22
+ const internalJob = {
23
+ id: jobId,
24
+ name: job.name,
25
+ data: { ...job.data, __queueName: queueName },
26
+ state: "waiting",
27
+ timestamp: Date.now()
28
+ };
29
+ this.jobs.set(jobId, internalJob);
30
+ this.emitEvent(queueName, "waiting", { jobId, job: internalJob });
31
+ const workerInfo = this.workers.get(queueName);
32
+ if (workerInfo && !workerInfo.paused) {
33
+ workerInfo.queue.push({ jobId, jobName: job.name, data: job.data }).catch((error) => {
34
+ console.error(`[MemoryQueueAdapter] Error processing job ${jobId}:`, error);
35
+ });
36
+ }
37
+ return jobId;
38
+ }
39
+ async schedule(queueName, job, opts) {
40
+ if (opts?.delay) {
41
+ const jobId = this.generateId();
42
+ const internalJob = {
43
+ id: jobId,
44
+ name: job.name,
45
+ data: { ...job.data, __queueName: queueName },
46
+ state: "delayed",
47
+ timestamp: Date.now()
48
+ };
49
+ this.jobs.set(jobId, internalJob);
50
+ this.emitEvent(queueName, "delayed", { jobId, job: internalJob, delay: opts.delay });
51
+ setTimeout(() => {
52
+ this.enqueue(queueName, job);
53
+ }, opts.delay);
54
+ return jobId;
55
+ }
56
+ if (opts?.cron || opts?.repeat) {
57
+ throw new Error("Cron/repeat scheduling not supported in memory adapter");
58
+ }
59
+ return this.enqueue(queueName, job);
60
+ }
61
+ async getJob(_queueName, id) {
62
+ return this.jobs.get(id) || null;
63
+ }
64
+ async getJobs(queueName, query) {
65
+ let jobs = Array.from(this.jobs.values()).filter((j) => j.data?.__queueName === queueName);
66
+ if (query?.state && query.state.length > 0) {
67
+ jobs = jobs.filter((j) => query.state.includes(j.state));
68
+ }
69
+ if (query?.offset) {
70
+ jobs = jobs.slice(query.offset);
71
+ }
72
+ if (query?.limit) {
73
+ jobs = jobs.slice(0, query.limit);
74
+ }
75
+ return jobs;
76
+ }
77
+ on(queueName, event, callback) {
78
+ const key = `${queueName}:${event}`;
79
+ if (!this.eventListeners.has(key)) {
80
+ this.eventListeners.set(key, []);
81
+ }
82
+ this.eventListeners.get(key).push(callback);
83
+ return () => {
84
+ const listeners = this.eventListeners.get(key);
85
+ if (listeners) {
86
+ const index = listeners.indexOf(callback);
87
+ if (index > -1) {
88
+ listeners.splice(index, 1);
89
+ }
90
+ }
91
+ };
92
+ }
93
+ async isPaused(queueName) {
94
+ const workerInfo = this.workers.get(queueName);
95
+ return workerInfo?.paused || false;
96
+ }
97
+ async getJobCounts(queueName) {
98
+ const jobs = Array.from(this.jobs.values()).filter((j) => j.data?.__queueName === queueName);
99
+ return {
100
+ active: jobs.filter((j) => j.state === "active").length,
101
+ completed: jobs.filter((j) => j.state === "completed").length,
102
+ failed: jobs.filter((j) => j.state === "failed").length,
103
+ delayed: jobs.filter((j) => j.state === "delayed").length,
104
+ waiting: jobs.filter((j) => j.state === "waiting").length,
105
+ paused: jobs.filter((j) => j.state === "paused").length
106
+ };
107
+ }
108
+ async pause(queueName) {
109
+ const workerInfo = this.workers.get(queueName);
110
+ if (workerInfo) {
111
+ workerInfo.paused = true;
112
+ workerInfo.queue.pause();
113
+ }
114
+ }
115
+ async resume(queueName) {
116
+ const workerInfo = this.workers.get(queueName);
117
+ if (workerInfo) {
118
+ workerInfo.paused = false;
119
+ workerInfo.queue.resume();
120
+ }
121
+ }
122
+ async close() {
123
+ const drainPromises = Array.from(this.workers.values()).map((w) => w.queue.drained());
124
+ await Promise.all(drainPromises);
125
+ this.jobs.clear();
126
+ this.eventListeners.clear();
127
+ this.workers.clear();
128
+ }
129
+ // ============================================================
130
+ // Worker Management (used by worker registration system)
131
+ // ============================================================
132
+ /**
133
+ * Register a worker handler for a queue
134
+ * This is called by the worker registration system
135
+ */
136
+ registerWorker(queueName, jobName, handler, opts) {
137
+ let workerInfo = this.workers.get(queueName);
138
+ if (workerInfo) {
139
+ console.info(`[MemoryQueue] Adding handler for job "${jobName}" to queue "${queueName}"`);
140
+ workerInfo.handlers.set(jobName, handler);
141
+ return;
142
+ }
143
+ console.info(`[MemoryQueue] Creating new worker for queue: ${queueName}`);
144
+ const handlers = /* @__PURE__ */ new Map();
145
+ handlers.set(jobName, handler);
146
+ const dispatcher = async (task) => {
147
+ const handler2 = handlers.get(task.jobName);
148
+ if (!handler2) {
149
+ const error = `No handler for job "${task.jobName}" on queue "${queueName}". Available: ${Array.from(handlers.keys()).join(", ")}`;
150
+ console.error(error);
151
+ throw new Error(error);
152
+ }
153
+ this.updateJobState(task.jobId, "active", { processedOn: Date.now() });
154
+ this.emitEvent(queueName, "active", { jobId: task.jobId });
155
+ try {
156
+ const result = await handler2(task.data, {
157
+ jobId: task.jobId,
158
+ queueName
159
+ // Add more context as needed
160
+ });
161
+ this.updateJobState(task.jobId, "completed", {
162
+ returnvalue: result,
163
+ finishedOn: Date.now()
164
+ });
165
+ this.emitEvent(queueName, "completed", { jobId: task.jobId, returnvalue: result });
166
+ return result;
167
+ } catch (err) {
168
+ this.updateJobState(task.jobId, "failed", {
169
+ failedReason: err.message,
170
+ finishedOn: Date.now()
171
+ });
172
+ this.emitEvent(queueName, "failed", {
173
+ jobId: task.jobId,
174
+ failedReason: err.message
175
+ });
176
+ throw err;
177
+ }
178
+ };
179
+ const concurrency = opts?.concurrency || 1;
180
+ const queue = fastq.promise(dispatcher, concurrency);
181
+ const shouldPause = opts?.autorun === false;
182
+ workerInfo = {
183
+ queue,
184
+ handlers,
185
+ paused: shouldPause || false,
186
+ concurrency
187
+ };
188
+ if (shouldPause) {
189
+ queue.pause();
190
+ console.info(`[MemoryQueue] Worker for "${queueName}" created but paused`);
191
+ }
192
+ this.workers.set(queueName, workerInfo);
193
+ }
194
+ /**
195
+ * Start processing waiting jobs for a queue
196
+ * Should be called after all handlers are registered
197
+ */
198
+ startProcessingQueue(queueName) {
199
+ const workerInfo = this.workers.get(queueName);
200
+ if (!workerInfo || workerInfo.paused) return;
201
+ const waitingJobs = Array.from(this.jobs.values()).filter(
202
+ (j) => j.state === "waiting" && j.data?.__queueName === queueName
203
+ );
204
+ for (const job of waitingJobs) {
205
+ workerInfo.queue.push({ jobId: job.id, jobName: job.name, data: job.data }).catch((error) => {
206
+ console.error(`[MemoryQueueAdapter] Error processing queued job ${job.id}:`, error);
207
+ });
208
+ }
209
+ }
210
+ // ============================================================
211
+ // Helper Methods
212
+ // ============================================================
213
+ /**
214
+ * Update job state (called internally and by worker manager)
215
+ */
216
+ updateJobState(jobId, state, extra) {
217
+ const job = this.jobs.get(jobId);
218
+ if (job) {
219
+ job.state = state;
220
+ if (extra) {
221
+ Object.assign(job, extra);
222
+ }
223
+ }
224
+ }
225
+ emitEvent(queueName, event, payload) {
226
+ const key = `${queueName}:${event}`;
227
+ const listeners = this.eventListeners.get(key) || [];
228
+ for (const callback of listeners) {
229
+ try {
230
+ callback(payload);
231
+ } catch (error) {
232
+ console.error(`[MemoryQueueAdapter] Error in event listener for ${key}:`, error);
233
+ }
234
+ }
235
+ }
236
+ generateId() {
237
+ return `${Date.now()}-${Math.random().toString(36).substr(2, 9)}`;
238
+ }
239
+ }
@@ -0,0 +1,57 @@
1
+ /**
2
+ * Memory Store Adapter
3
+ *
4
+ * In-memory storage implementation for development
5
+ * Three-tier storage:
6
+ * 1. Event Stream - Append-only event log
7
+ * 2. Document Store - Generic document storage
8
+ * 3. Key-Value Store - Fast lookups
9
+ *
10
+ * All data is lost on restart (ephemeral)
11
+ */
12
+ import type { StoreAdapter, EventRecord, EventReadOptions, EventSubscription, ListOptions } from '../interfaces/store.js';
13
+ export declare class MemoryStoreAdapter implements StoreAdapter {
14
+ private eventStreams;
15
+ private eventSubscriptions;
16
+ private subscriptionCounter;
17
+ private documents;
18
+ private kvStore;
19
+ close(): Promise<void>;
20
+ append(subject: string, event: Omit<EventRecord, 'id' | 'ts'>): Promise<EventRecord>;
21
+ read(subject: string, opts?: EventReadOptions): Promise<EventRecord[]>;
22
+ subscribe(subject: string, onEvent: (event: EventRecord) => void): Promise<EventSubscription>;
23
+ private notifySubscribers;
24
+ save(collection: string, id: string, doc: Record<string, any>): Promise<void>;
25
+ get(collection: string, id: string): Promise<Record<string, any> | null>;
26
+ list(collection: string, opts?: ListOptions): Promise<Array<{
27
+ id: string;
28
+ doc: any;
29
+ }>>;
30
+ delete(collection: string, id: string): Promise<void>;
31
+ kv: {
32
+ get: <T = any>(key: string) => Promise<T | null>;
33
+ set: <T = any>(key: string, value: T, _ttl?: number) => Promise<void>;
34
+ delete: (key: string) => Promise<void>;
35
+ clear: (pattern: string) => Promise<number>;
36
+ increment: (key: string, by?: number) => Promise<number>;
37
+ };
38
+ private sortedIndices;
39
+ indexAdd(key: string, id: string, score: number, metadata?: Record<string, any>): Promise<void>;
40
+ indexGet(key: string, id: string): Promise<{
41
+ id: string;
42
+ score: number;
43
+ metadata?: any;
44
+ } | null>;
45
+ indexRead(key: string, opts?: {
46
+ offset?: number;
47
+ limit?: number;
48
+ }): Promise<Array<{
49
+ id: string;
50
+ score: number;
51
+ metadata?: any;
52
+ }>>;
53
+ indexUpdate(key: string, id: string, metadata: Record<string, any>): Promise<boolean>;
54
+ indexUpdateWithRetry(key: string, id: string, metadata: Record<string, any>, maxRetries?: number): Promise<void>;
55
+ indexIncrement(key: string, id: string, field: string, increment?: number): Promise<number>;
56
+ private generateId;
57
+ }