nvent 0.4.0

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 (192) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +389 -0
  3. package/dist/module.d.mts +193 -0
  4. package/dist/module.json +9 -0
  5. package/dist/module.mjs +974 -0
  6. package/dist/runtime/app/components/ConfirmDialog.d.vue.ts +33 -0
  7. package/dist/runtime/app/components/ConfirmDialog.vue +121 -0
  8. package/dist/runtime/app/components/ConfirmDialog.vue.d.ts +33 -0
  9. package/dist/runtime/app/components/FlowDiagram.d.vue.ts +64 -0
  10. package/dist/runtime/app/components/FlowDiagram.vue +338 -0
  11. package/dist/runtime/app/components/FlowDiagram.vue.d.ts +64 -0
  12. package/dist/runtime/app/components/FlowNodeCard.d.vue.ts +29 -0
  13. package/dist/runtime/app/components/FlowNodeCard.vue +156 -0
  14. package/dist/runtime/app/components/FlowNodeCard.vue.d.ts +29 -0
  15. package/dist/runtime/app/components/FlowRunOverview.d.vue.ts +9 -0
  16. package/dist/runtime/app/components/FlowRunOverview.vue +291 -0
  17. package/dist/runtime/app/components/FlowRunOverview.vue.d.ts +9 -0
  18. package/dist/runtime/app/components/FlowRunStatusBadge.d.vue.ts +14 -0
  19. package/dist/runtime/app/components/FlowRunStatusBadge.vue +60 -0
  20. package/dist/runtime/app/components/FlowRunStatusBadge.vue.d.ts +14 -0
  21. package/dist/runtime/app/components/FlowRunTimeline.d.vue.ts +12 -0
  22. package/dist/runtime/app/components/FlowRunTimeline.vue +127 -0
  23. package/dist/runtime/app/components/FlowRunTimeline.vue.d.ts +12 -0
  24. package/dist/runtime/app/components/FlowScheduleDialog.d.vue.ts +16 -0
  25. package/dist/runtime/app/components/FlowScheduleDialog.vue +226 -0
  26. package/dist/runtime/app/components/FlowScheduleDialog.vue.d.ts +16 -0
  27. package/dist/runtime/app/components/FlowSchedulesList.d.vue.ts +12 -0
  28. package/dist/runtime/app/components/FlowSchedulesList.vue +99 -0
  29. package/dist/runtime/app/components/FlowSchedulesList.vue.d.ts +12 -0
  30. package/dist/runtime/app/components/JobScheduling.d.vue.ts +6 -0
  31. package/dist/runtime/app/components/JobScheduling.vue +203 -0
  32. package/dist/runtime/app/components/JobScheduling.vue.d.ts +6 -0
  33. package/dist/runtime/app/components/ListItem.d.vue.ts +23 -0
  34. package/dist/runtime/app/components/ListItem.vue +70 -0
  35. package/dist/runtime/app/components/ListItem.vue.d.ts +23 -0
  36. package/dist/runtime/app/components/QueueConfigDetails.d.vue.ts +45 -0
  37. package/dist/runtime/app/components/QueueConfigDetails.vue +412 -0
  38. package/dist/runtime/app/components/QueueConfigDetails.vue.d.ts +45 -0
  39. package/dist/runtime/app/components/StatCounter.d.vue.ts +9 -0
  40. package/dist/runtime/app/components/StatCounter.vue +25 -0
  41. package/dist/runtime/app/components/StatCounter.vue.d.ts +9 -0
  42. package/dist/runtime/app/components/TimelineList.d.vue.ts +7 -0
  43. package/dist/runtime/app/components/TimelineList.vue +210 -0
  44. package/dist/runtime/app/components/TimelineList.vue.d.ts +7 -0
  45. package/dist/runtime/app/components/nhealth/component-router.d.vue.ts +46 -0
  46. package/dist/runtime/app/components/nhealth/component-router.vue +26 -0
  47. package/dist/runtime/app/components/nhealth/component-router.vue.d.ts +46 -0
  48. package/dist/runtime/app/components/nhealth/component-shell.d.vue.ts +24 -0
  49. package/dist/runtime/app/components/nhealth/component-shell.vue +89 -0
  50. package/dist/runtime/app/components/nhealth/component-shell.vue.d.ts +24 -0
  51. package/dist/runtime/app/composables/useAnalyzedFlows.d.ts +14 -0
  52. package/dist/runtime/app/composables/useAnalyzedFlows.js +7 -0
  53. package/dist/runtime/app/composables/useComponentRouter.d.ts +38 -0
  54. package/dist/runtime/app/composables/useComponentRouter.js +240 -0
  55. package/dist/runtime/app/composables/useFlowRunTimeline.d.ts +15 -0
  56. package/dist/runtime/app/composables/useFlowRunTimeline.js +66 -0
  57. package/dist/runtime/app/composables/useFlowRuns.d.ts +11 -0
  58. package/dist/runtime/app/composables/useFlowRuns.js +31 -0
  59. package/dist/runtime/app/composables/useFlowRunsInfinite.d.ts +24 -0
  60. package/dist/runtime/app/composables/useFlowRunsInfinite.js +123 -0
  61. package/dist/runtime/app/composables/useFlowRunsPolling.d.ts +8 -0
  62. package/dist/runtime/app/composables/useFlowRunsPolling.js +26 -0
  63. package/dist/runtime/app/composables/useFlowState.d.ts +125 -0
  64. package/dist/runtime/app/composables/useFlowState.js +211 -0
  65. package/dist/runtime/app/composables/useFlowWebSocket.d.ts +27 -0
  66. package/dist/runtime/app/composables/useFlowWebSocket.js +205 -0
  67. package/dist/runtime/app/composables/useFlowsNavigation.d.ts +10 -0
  68. package/dist/runtime/app/composables/useFlowsNavigation.js +57 -0
  69. package/dist/runtime/app/composables/useQueueJobs.d.ts +20 -0
  70. package/dist/runtime/app/composables/useQueueJobs.js +20 -0
  71. package/dist/runtime/app/composables/useQueueUpdates.d.ts +26 -0
  72. package/dist/runtime/app/composables/useQueueUpdates.js +122 -0
  73. package/dist/runtime/app/composables/useQueues.d.ts +43 -0
  74. package/dist/runtime/app/composables/useQueues.js +26 -0
  75. package/dist/runtime/app/composables/useQueuesLive.d.ts +19 -0
  76. package/dist/runtime/app/composables/useQueuesLive.js +143 -0
  77. package/dist/runtime/app/pages/flows/index.d.vue.ts +3 -0
  78. package/dist/runtime/app/pages/flows/index.vue +645 -0
  79. package/dist/runtime/app/pages/flows/index.vue.d.ts +3 -0
  80. package/dist/runtime/app/pages/index.d.vue.ts +3 -0
  81. package/dist/runtime/app/pages/index.vue +34 -0
  82. package/dist/runtime/app/pages/index.vue.d.ts +3 -0
  83. package/dist/runtime/app/pages/queues/index.d.vue.ts +3 -0
  84. package/dist/runtime/app/pages/queues/index.vue +229 -0
  85. package/dist/runtime/app/pages/queues/index.vue.d.ts +3 -0
  86. package/dist/runtime/app/pages/queues/job.d.vue.ts +3 -0
  87. package/dist/runtime/app/pages/queues/job.vue +262 -0
  88. package/dist/runtime/app/pages/queues/job.vue.d.ts +3 -0
  89. package/dist/runtime/app/pages/queues/jobs.d.vue.ts +3 -0
  90. package/dist/runtime/app/pages/queues/jobs.vue +291 -0
  91. package/dist/runtime/app/pages/queues/jobs.vue.d.ts +3 -0
  92. package/dist/runtime/app/plugins/vueflow.client.d.ts +6 -0
  93. package/dist/runtime/app/plugins/vueflow.client.js +15 -0
  94. package/dist/runtime/constants.d.ts +11 -0
  95. package/dist/runtime/constants.js +11 -0
  96. package/dist/runtime/python/get_config.py +64 -0
  97. package/dist/runtime/schema.d.ts +37 -0
  98. package/dist/runtime/schema.js +20 -0
  99. package/dist/runtime/server/api/_flows/[name]/clear-history.delete.d.ts +10 -0
  100. package/dist/runtime/server/api/_flows/[name]/clear-history.delete.js +44 -0
  101. package/dist/runtime/server/api/_flows/[name]/runs.get.d.ts +7 -0
  102. package/dist/runtime/server/api/_flows/[name]/runs.get.js +53 -0
  103. package/dist/runtime/server/api/_flows/[name]/schedule.post.d.ts +2 -0
  104. package/dist/runtime/server/api/_flows/[name]/schedule.post.js +57 -0
  105. package/dist/runtime/server/api/_flows/[name]/schedules/[id].delete.d.ts +2 -0
  106. package/dist/runtime/server/api/_flows/[name]/schedules/[id].delete.js +42 -0
  107. package/dist/runtime/server/api/_flows/[name]/schedules.get.d.ts +2 -0
  108. package/dist/runtime/server/api/_flows/[name]/schedules.get.js +48 -0
  109. package/dist/runtime/server/api/_flows/[name]/start.post.d.ts +2 -0
  110. package/dist/runtime/server/api/_flows/[name]/start.post.js +9 -0
  111. package/dist/runtime/server/api/_flows/index.get.d.ts +6 -0
  112. package/dist/runtime/server/api/_flows/index.get.js +5 -0
  113. package/dist/runtime/server/api/_flows/ws.d.ts +60 -0
  114. package/dist/runtime/server/api/_flows/ws.js +183 -0
  115. package/dist/runtime/server/api/_queues/[name]/job/[id].get.d.ts +2 -0
  116. package/dist/runtime/server/api/_queues/[name]/job/[id].get.js +9 -0
  117. package/dist/runtime/server/api/_queues/[name]/job/index.get.d.ts +2 -0
  118. package/dist/runtime/server/api/_queues/[name]/job/index.get.js +18 -0
  119. package/dist/runtime/server/api/_queues/index.get.d.ts +2 -0
  120. package/dist/runtime/server/api/_queues/index.get.js +63 -0
  121. package/dist/runtime/server/api/_queues/ws.d.ts +48 -0
  122. package/dist/runtime/server/api/_queues/ws.js +200 -0
  123. package/dist/runtime/server/events/adapters/fileAdapter.d.ts +2 -0
  124. package/dist/runtime/server/events/adapters/fileAdapter.js +382 -0
  125. package/dist/runtime/server/events/adapters/memoryAdapter.d.ts +2 -0
  126. package/dist/runtime/server/events/adapters/memoryAdapter.js +171 -0
  127. package/dist/runtime/server/events/adapters/redis/redisAdapter.d.ts +2 -0
  128. package/dist/runtime/server/events/adapters/redis/redisAdapter.js +348 -0
  129. package/dist/runtime/server/events/adapters/redis/redisPubSubGateway.d.ts +29 -0
  130. package/dist/runtime/server/events/adapters/redis/redisPubSubGateway.js +82 -0
  131. package/dist/runtime/server/events/eventBus.d.ts +20 -0
  132. package/dist/runtime/server/events/eventBus.js +35 -0
  133. package/dist/runtime/server/events/eventStoreFactory.d.ts +19 -0
  134. package/dist/runtime/server/events/eventStoreFactory.js +44 -0
  135. package/dist/runtime/server/events/streamNames.d.ts +17 -0
  136. package/dist/runtime/server/events/streamNames.js +17 -0
  137. package/dist/runtime/server/events/types.d.ts +63 -0
  138. package/dist/runtime/server/events/types.js +0 -0
  139. package/dist/runtime/server/events/wiring/flowWiring.d.ts +33 -0
  140. package/dist/runtime/server/events/wiring/flowWiring.js +406 -0
  141. package/dist/runtime/server/events/wiring/registry.d.ts +10 -0
  142. package/dist/runtime/server/events/wiring/registry.js +24 -0
  143. package/dist/runtime/server/plugins/00.event-store.d.ts +13 -0
  144. package/dist/runtime/server/plugins/00.event-store.js +16 -0
  145. package/dist/runtime/server/plugins/00.ws-lifecycle.d.ts +5 -0
  146. package/dist/runtime/server/plugins/00.ws-lifecycle.js +66 -0
  147. package/dist/runtime/server/plugins/flow-management.d.ts +13 -0
  148. package/dist/runtime/server/plugins/flow-management.js +65 -0
  149. package/dist/runtime/server/plugins/queue-management.d.ts +2 -0
  150. package/dist/runtime/server/plugins/queue-management.js +27 -0
  151. package/dist/runtime/server/plugins/state-cleanup.d.ts +11 -0
  152. package/dist/runtime/server/plugins/state-cleanup.js +93 -0
  153. package/dist/runtime/server/plugins/worker-management.d.ts +2 -0
  154. package/dist/runtime/server/plugins/worker-management.js +33 -0
  155. package/dist/runtime/server/queue/adapters/bullmq.d.ts +17 -0
  156. package/dist/runtime/server/queue/adapters/bullmq.js +164 -0
  157. package/dist/runtime/server/queue/queueFactory.d.ts +3 -0
  158. package/dist/runtime/server/queue/queueFactory.js +10 -0
  159. package/dist/runtime/server/queue/types.d.ts +47 -0
  160. package/dist/runtime/server/queue/types.js +0 -0
  161. package/dist/runtime/server/state/adapters/redis.d.ts +2 -0
  162. package/dist/runtime/server/state/adapters/redis.js +42 -0
  163. package/dist/runtime/server/state/stateFactory.d.ts +3 -0
  164. package/dist/runtime/server/state/stateFactory.js +17 -0
  165. package/dist/runtime/server/state/types.d.ts +23 -0
  166. package/dist/runtime/server/state/types.js +0 -0
  167. package/dist/runtime/server/tsconfig.json +3 -0
  168. package/dist/runtime/server/utils/defineQueueConfig.d.ts +154 -0
  169. package/dist/runtime/server/utils/defineQueueConfig.js +2 -0
  170. package/dist/runtime/server/utils/defineQueueWorker.d.ts +10 -0
  171. package/dist/runtime/server/utils/defineQueueWorker.js +17 -0
  172. package/dist/runtime/server/utils/useEventManager.d.ts +15 -0
  173. package/dist/runtime/server/utils/useEventManager.js +26 -0
  174. package/dist/runtime/server/utils/useEventStore.d.ts +20 -0
  175. package/dist/runtime/server/utils/useEventStore.js +119 -0
  176. package/dist/runtime/server/utils/useFlowEngine.d.ts +9 -0
  177. package/dist/runtime/server/utils/useFlowEngine.js +44 -0
  178. package/dist/runtime/server/utils/useLogs.d.ts +41 -0
  179. package/dist/runtime/server/utils/useLogs.js +74 -0
  180. package/dist/runtime/server/utils/useQueue.d.ts +31 -0
  181. package/dist/runtime/server/utils/useQueue.js +24 -0
  182. package/dist/runtime/server/utils/useServerLogger.d.ts +42 -0
  183. package/dist/runtime/server/utils/useServerLogger.js +54 -0
  184. package/dist/runtime/server/utils/wsPeerManager.d.ts +34 -0
  185. package/dist/runtime/server/utils/wsPeerManager.js +23 -0
  186. package/dist/runtime/server/worker/adapter.d.ts +4 -0
  187. package/dist/runtime/server/worker/adapter.js +65 -0
  188. package/dist/runtime/server/worker/runner/node.d.ts +27 -0
  189. package/dist/runtime/server/worker/runner/node.js +196 -0
  190. package/dist/runtime/types.d.ts +132 -0
  191. package/dist/types.d.mts +3 -0
  192. package/package.json +75 -0
@@ -0,0 +1,122 @@
1
+ import { ref, computed, onUnmounted } from "#imports";
2
+ export function useQueueUpdates(queueName) {
3
+ const ws = ref(null);
4
+ const isConnected = ref(false);
5
+ const isReconnecting = ref(false);
6
+ const state = ref({
7
+ counts: null,
8
+ lastEvent: null,
9
+ countsUpdatedAt: null,
10
+ shouldRefreshJobs: false
11
+ });
12
+ let reconnectTimeout = null;
13
+ let reconnectAttempts = 0;
14
+ const maxReconnectAttempts = 5;
15
+ const connect = () => {
16
+ if (!import.meta.client || !queueName.value) return;
17
+ if (ws.value) {
18
+ try {
19
+ ws.value.close();
20
+ } catch {
21
+ }
22
+ ws.value = null;
23
+ }
24
+ const protocol = window.location.protocol === "https:" ? "wss:" : "ws:";
25
+ const wsUrl = `${protocol}//${window.location.host}/api/_queues/ws`;
26
+ try {
27
+ const socket = new WebSocket(wsUrl);
28
+ ws.value = socket;
29
+ socket.onopen = () => {
30
+ console.log("[useQueueUpdates] connected");
31
+ isConnected.value = true;
32
+ isReconnecting.value = false;
33
+ reconnectAttempts = 0;
34
+ socket.send(JSON.stringify({
35
+ type: "subscribe",
36
+ queueName: queueName.value
37
+ }));
38
+ };
39
+ socket.onmessage = (event) => {
40
+ try {
41
+ const message = JSON.parse(event.data);
42
+ if (message.type === "event") {
43
+ state.value.lastEvent = message.event;
44
+ const eventType = message.event?.eventType;
45
+ if (["waiting", "active", "completed", "failed"].includes(eventType)) {
46
+ state.value.shouldRefreshJobs = true;
47
+ }
48
+ } else if (message.type === "counts") {
49
+ state.value.counts = message.counts;
50
+ state.value.countsUpdatedAt = Date.now();
51
+ } else if (message.type === "error") {
52
+ console.error("[useQueueUpdates] error:", message.message);
53
+ }
54
+ } catch (err) {
55
+ console.error("[useQueueUpdates] parse error:", err);
56
+ }
57
+ };
58
+ socket.onerror = (error) => {
59
+ console.error("[useQueueUpdates] error:", error);
60
+ };
61
+ socket.onclose = () => {
62
+ console.log("[useQueueUpdates] disconnected");
63
+ isConnected.value = false;
64
+ if (reconnectAttempts < maxReconnectAttempts && queueName.value) {
65
+ isReconnecting.value = true;
66
+ reconnectAttempts++;
67
+ const delay = Math.min(1e3 * Math.pow(2, reconnectAttempts), 1e4);
68
+ reconnectTimeout = setTimeout(() => {
69
+ console.log(`[useQueueUpdates] reconnecting (attempt ${reconnectAttempts})...`);
70
+ connect();
71
+ }, delay);
72
+ } else {
73
+ isReconnecting.value = false;
74
+ }
75
+ };
76
+ } catch (err) {
77
+ console.error("[useQueueUpdates] connection error:", err);
78
+ isConnected.value = false;
79
+ }
80
+ };
81
+ const disconnect = () => {
82
+ if (reconnectTimeout) {
83
+ clearTimeout(reconnectTimeout);
84
+ reconnectTimeout = null;
85
+ }
86
+ if (ws.value) {
87
+ try {
88
+ if (ws.value.readyState === WebSocket.OPEN) {
89
+ ws.value.send(JSON.stringify({
90
+ type: "unsubscribe",
91
+ queueName: queueName.value
92
+ }));
93
+ }
94
+ ws.value.close();
95
+ } catch {
96
+ }
97
+ ws.value = null;
98
+ }
99
+ isConnected.value = false;
100
+ isReconnecting.value = false;
101
+ };
102
+ if (import.meta.client && queueName.value) {
103
+ connect();
104
+ }
105
+ onUnmounted(() => {
106
+ disconnect();
107
+ });
108
+ const resetRefreshFlag = () => {
109
+ state.value.shouldRefreshJobs = false;
110
+ };
111
+ return {
112
+ isConnected: computed(() => isConnected.value),
113
+ isReconnecting: computed(() => isReconnecting.value),
114
+ counts: computed(() => state.value.counts),
115
+ lastEvent: computed(() => state.value.lastEvent),
116
+ countsUpdatedAt: computed(() => state.value.countsUpdatedAt),
117
+ shouldRefreshJobs: computed(() => state.value.shouldRefreshJobs),
118
+ resetRefreshFlag,
119
+ connect,
120
+ disconnect
121
+ };
122
+ }
@@ -0,0 +1,43 @@
1
+ export interface QueueCounts {
2
+ active: number;
3
+ completed: number;
4
+ failed: number;
5
+ delayed: number;
6
+ waiting: number;
7
+ paused: number;
8
+ }
9
+ export interface QueueConfig {
10
+ queue: {
11
+ prefix?: string;
12
+ defaultJobOptions?: Record<string, any>;
13
+ limiter?: {
14
+ max?: number;
15
+ duration?: number;
16
+ groupKey?: string;
17
+ };
18
+ };
19
+ worker: {
20
+ concurrency?: number;
21
+ lockDurationMs?: number;
22
+ maxStalledCount?: number;
23
+ drainDelayMs?: number;
24
+ autorun?: boolean;
25
+ pollingIntervalMs?: number;
26
+ };
27
+ }
28
+ export interface QueueInfo {
29
+ name: string;
30
+ counts: QueueCounts;
31
+ isPaused: boolean;
32
+ config?: QueueConfig;
33
+ }
34
+ /**
35
+ * Composable for fetching queue list with job counts
36
+ * Client-only to avoid hydration mismatches
37
+ */
38
+ export declare function useQueues(): {
39
+ queues: any;
40
+ refresh: () => Promise<void>;
41
+ status: any;
42
+ error: any;
43
+ };
@@ -0,0 +1,26 @@
1
+ import { ref } from "#imports";
2
+ export function useQueues() {
3
+ const refreshCounter = ref(0);
4
+ const { data: queues, refresh: _refresh, status, error } = useFetch(
5
+ () => `/api/_queues?_t=${refreshCounter.value}`,
6
+ {
7
+ immediate: false,
8
+ watch: false,
9
+ server: false
10
+ // Client-only
11
+ }
12
+ );
13
+ const refresh = async () => {
14
+ refreshCounter.value++;
15
+ await _refresh();
16
+ };
17
+ if (import.meta.client) {
18
+ refresh();
19
+ }
20
+ return {
21
+ queues,
22
+ refresh,
23
+ status,
24
+ error
25
+ };
26
+ }
@@ -0,0 +1,19 @@
1
+ import { type Ref } from '#imports';
2
+ import type { QueueInfo, QueueCounts } from './useQueues.js';
3
+ /**
4
+ * Composable for live queue updates across all queues
5
+ * Subscribes to WebSocket updates for multiple queues
6
+ */
7
+ export declare function useQueuesLive(queues: Ref<QueueInfo[] | null | undefined>): {
8
+ queues: import("vue").ComputedRef<{
9
+ counts: QueueCounts;
10
+ name: string;
11
+ isPaused: boolean;
12
+ config?: import("#imports").QueueConfig;
13
+ }[] | null>;
14
+ isConnected: import("vue").ComputedRef<boolean>;
15
+ isReconnecting: import("vue").ComputedRef<boolean>;
16
+ liveCounts: import("vue").ComputedRef<Record<string, QueueCounts>>;
17
+ connect: () => void;
18
+ disconnect: () => void;
19
+ };
@@ -0,0 +1,143 @@
1
+ import { ref, computed, watch, onUnmounted } from "#imports";
2
+ export function useQueuesLive(queues) {
3
+ const ws = ref(null);
4
+ const isConnected = ref(false);
5
+ const isReconnecting = ref(false);
6
+ const liveCounts = ref({});
7
+ let reconnectTimeout = null;
8
+ let reconnectAttempts = 0;
9
+ const maxReconnectAttempts = 5;
10
+ const safeSend = (data) => {
11
+ if (!ws.value || ws.value.readyState !== WebSocket.OPEN) return false;
12
+ try {
13
+ ws.value.send(JSON.stringify(data));
14
+ return true;
15
+ } catch {
16
+ return false;
17
+ }
18
+ };
19
+ const subscribeToQueues = (queueNames) => {
20
+ if (!ws.value || ws.value.readyState !== WebSocket.OPEN) return;
21
+ for (const queueName of queueNames) {
22
+ safeSend({
23
+ type: "subscribe",
24
+ queueName
25
+ });
26
+ }
27
+ };
28
+ const connect = () => {
29
+ if (!import.meta.client) return;
30
+ if (ws.value) {
31
+ try {
32
+ ws.value.close();
33
+ } catch {
34
+ }
35
+ ws.value = null;
36
+ }
37
+ const protocol = window.location.protocol === "https:" ? "wss:" : "ws:";
38
+ const wsUrl = `${protocol}//${window.location.host}/api/_queues/ws`;
39
+ try {
40
+ const socket = new WebSocket(wsUrl);
41
+ ws.value = socket;
42
+ socket.onopen = () => {
43
+ console.log("[useQueuesLive] connected");
44
+ isConnected.value = true;
45
+ isReconnecting.value = false;
46
+ reconnectAttempts = 0;
47
+ if (queues.value) {
48
+ const queueNames = queues.value.map((q) => q.name);
49
+ subscribeToQueues(queueNames);
50
+ }
51
+ };
52
+ socket.onmessage = (event) => {
53
+ try {
54
+ const message = JSON.parse(event.data);
55
+ if (message.type === "counts" && message.queueName) {
56
+ liveCounts.value[message.queueName] = message.counts;
57
+ } else if (message.type === "error") {
58
+ console.error("[useQueuesLive] error:", message.message);
59
+ }
60
+ } catch (err) {
61
+ console.error("[useQueuesLive] parse error:", err);
62
+ }
63
+ };
64
+ socket.onerror = (error) => {
65
+ console.error("[useQueuesLive] error:", error);
66
+ };
67
+ socket.onclose = () => {
68
+ console.log("[useQueuesLive] disconnected");
69
+ isConnected.value = false;
70
+ if (reconnectAttempts < maxReconnectAttempts) {
71
+ isReconnecting.value = true;
72
+ reconnectAttempts++;
73
+ const delay = Math.min(1e3 * Math.pow(2, reconnectAttempts), 1e4);
74
+ reconnectTimeout = setTimeout(() => {
75
+ console.log(`[useQueuesLive] reconnecting (attempt ${reconnectAttempts})...`);
76
+ connect();
77
+ }, delay);
78
+ } else {
79
+ isReconnecting.value = false;
80
+ }
81
+ };
82
+ } catch (err) {
83
+ console.error("[useQueuesLive] connection error:", err);
84
+ isConnected.value = false;
85
+ }
86
+ };
87
+ const disconnect = () => {
88
+ if (reconnectTimeout) {
89
+ clearTimeout(reconnectTimeout);
90
+ reconnectTimeout = null;
91
+ }
92
+ if (ws.value) {
93
+ try {
94
+ if (queues.value) {
95
+ for (const queue of queues.value) {
96
+ safeSend({
97
+ type: "unsubscribe",
98
+ queueName: queue.name
99
+ });
100
+ }
101
+ }
102
+ ws.value.close();
103
+ } catch {
104
+ }
105
+ ws.value = null;
106
+ }
107
+ isConnected.value = false;
108
+ isReconnecting.value = false;
109
+ };
110
+ if (import.meta.client) {
111
+ connect();
112
+ }
113
+ watch(
114
+ () => queues.value,
115
+ (newQueues, oldQueues) => {
116
+ if (!newQueues || !ws.value || ws.value.readyState !== WebSocket.OPEN) return;
117
+ const oldNames = new Set(oldQueues?.map((q) => q.name) || []);
118
+ const newNames = newQueues.map((q) => q.name);
119
+ const toSubscribe = newNames.filter((name) => !oldNames.has(name));
120
+ if (toSubscribe.length > 0) {
121
+ subscribeToQueues(toSubscribe);
122
+ }
123
+ }
124
+ );
125
+ onUnmounted(() => {
126
+ disconnect();
127
+ });
128
+ const queuesWithLiveCounts = computed(() => {
129
+ if (!queues.value) return null;
130
+ return queues.value.map((queue) => ({
131
+ ...queue,
132
+ counts: liveCounts.value[queue.name] || queue.counts
133
+ }));
134
+ });
135
+ return {
136
+ queues: queuesWithLiveCounts,
137
+ isConnected: computed(() => isConnected.value),
138
+ isReconnecting: computed(() => isReconnecting.value),
139
+ liveCounts: computed(() => liveCounts.value),
140
+ connect,
141
+ disconnect
142
+ };
143
+ }
@@ -0,0 +1,3 @@
1
+ declare const __VLS_export: import("vue").DefineComponent<{}, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<{}> & Readonly<{}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
2
+ declare const _default: typeof __VLS_export;
3
+ export default _default;