@motiadev/plugin-bullmq 0.13.0-beta.162-717198 → 0.13.0-beta.162-415452

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/plugin.js CHANGED
@@ -1,64 +1,143 @@
1
- import q from "ioredis";
2
- import { Queue as w } from "bullmq";
3
- const h = /* @__PURE__ */ new Map(), i = (s, n, c) => {
4
- const m = h.get(s);
5
- if (m)
6
- return m;
7
- const t = new w(s, { connection: n, prefix: c });
8
- return h.set(s, t), t;
9
- }, g = async (s, n, c) => {
10
- const m = `${n}:*:id`, t = await s.keys(m), e = /* @__PURE__ */ new Set();
11
- for (const u of t) {
12
- const l = u.slice(n.length + 1).slice(0, -3);
13
- e.add(l);
1
+ import P from "ioredis";
2
+ import { StreamAdapter as I } from "@motiadev/core";
3
+ import { QueueEvents as _, Queue as v } from "bullmq";
4
+ const g = /* @__PURE__ */ new Map(), f = /* @__PURE__ */ new Map(), d = (u, s, a) => {
5
+ const o = g.get(u);
6
+ if (o)
7
+ return o;
8
+ const t = new v(u, { connection: s, prefix: a });
9
+ return g.set(u, t), t;
10
+ }, w = async (u, s) => {
11
+ const a = `${s}:*:id`, o = await u.keys(a), t = /* @__PURE__ */ new Set();
12
+ for (const e of o) {
13
+ const i = e.slice(s.length + 1).slice(0, -3);
14
+ t.add(i);
14
15
  }
15
- const r = [];
16
- for (const u of e) {
17
- const a = i(u, s, n), [l, d] = await Promise.all([a.isPaused(), a.getJobCounts()]);
18
- r.push({
19
- name: u,
20
- displayName: u,
21
- isPaused: l,
22
- isDLQ: u.endsWith(c),
23
- stats: {
24
- waiting: d.waiting || 0,
25
- active: d.active || 0,
26
- completed: d.completed || 0,
27
- failed: d.failed || 0,
28
- delayed: d.delayed || 0,
29
- paused: d.paused || 0,
30
- prioritized: d.prioritized || 0
31
- }
32
- });
16
+ return t;
17
+ }, b = async (u, s, a, o) => {
18
+ const t = d(u, s, a), [e, n] = await Promise.all([t.isPaused(), t.getJobCounts()]);
19
+ return {
20
+ name: u,
21
+ displayName: u,
22
+ isPaused: e,
23
+ isDLQ: u.endsWith(o),
24
+ stats: {
25
+ waiting: n.waiting || 0,
26
+ active: n.active || 0,
27
+ completed: n.completed || 0,
28
+ failed: n.failed || 0,
29
+ delayed: n.delayed || 0,
30
+ paused: n.paused || 0,
31
+ prioritized: n.prioritized || 0
32
+ }
33
+ };
34
+ }, Q = 500;
35
+ class E extends I {
36
+ constructor(s, a, o) {
37
+ super("__motia.bullmq-queues"), this.knownQueues = /* @__PURE__ */ new Set(), this.lastStatsCache = /* @__PURE__ */ new Map(), this.debounceTimers = /* @__PURE__ */ new Map(), this.connection = s, this.prefix = a, this.dlqSuffix = o;
38
+ }
39
+ setUpdateCallback(s) {
40
+ this.onQueueUpdate = s;
41
+ }
42
+ async get(s, a) {
43
+ try {
44
+ const o = await b(a, this.connection, this.prefix, this.dlqSuffix);
45
+ return { ...o, id: o.name };
46
+ } catch {
47
+ return null;
48
+ }
49
+ }
50
+ async set(s, a, o) {
51
+ return o;
52
+ }
53
+ async delete(s, a) {
54
+ return this.knownQueues.delete(a), this.lastStatsCache.delete(a), { id: a };
55
+ }
56
+ async getGroup(s) {
57
+ const a = await w(this.connection, this.prefix), o = [];
58
+ for (const t of a) {
59
+ this.knownQueues.add(t);
60
+ const e = await b(t, this.connection, this.prefix, this.dlqSuffix), n = { ...e, id: e.name };
61
+ o.push(n), this.lastStatsCache.set(t, JSON.stringify({ stats: e.stats, isPaused: e.isPaused }));
62
+ }
63
+ return o;
64
+ }
65
+ async refreshQueue(s) {
66
+ const a = await b(s, this.connection, this.prefix, this.dlqSuffix), o = { ...a, id: a.name };
67
+ this.knownQueues.add(s);
68
+ const t = JSON.stringify({ stats: a.stats, isPaused: a.isPaused });
69
+ return this.lastStatsCache.get(s) !== t && (this.lastStatsCache.set(s, t), this.onQueueUpdate?.(o)), o;
70
+ }
71
+ debouncedRefresh(s) {
72
+ const a = this.debounceTimers.get(s);
73
+ a && clearTimeout(a);
74
+ const o = setTimeout(() => {
75
+ this.debounceTimers.delete(s), this.refreshQueue(s);
76
+ }, Q);
77
+ this.debounceTimers.set(s, o);
78
+ }
79
+ setupQueueEvents(s) {
80
+ if (f.has(s))
81
+ return;
82
+ const a = new _(s, {
83
+ connection: this.connection,
84
+ prefix: this.prefix
85
+ }), o = () => {
86
+ this.debouncedRefresh(s);
87
+ };
88
+ a.on("waiting", o), a.on("active", o), a.on("completed", o), a.on("failed", o), a.on("delayed", o), a.on("removed", o);
89
+ }
90
+ async setupAllQueueEvents() {
91
+ const s = await w(this.connection, this.prefix);
92
+ for (const a of s)
93
+ this.setupQueueEvents(a);
94
+ }
95
+ async closeAllQueueEvents() {
96
+ for (const s of this.debounceTimers.values())
97
+ clearTimeout(s);
98
+ this.debounceTimers.clear();
99
+ for (const [, s] of f)
100
+ await s.close();
101
+ f.clear();
33
102
  }
34
- return r;
35
- }, f = ({ registerApi: s }, n, c, m) => {
36
- s({ method: "GET", path: "/__motia/bullmq/queues" }, async () => {
103
+ getKnownQueues() {
104
+ return this.knownQueues;
105
+ }
106
+ }
107
+ const S = async (u, s, a) => {
108
+ const o = await w(u, s), t = [];
109
+ for (const e of o) {
110
+ const n = await b(e, u, s, a);
111
+ t.push(n);
112
+ }
113
+ return t;
114
+ }, O = ({ registerApi: u }, s, a, o) => {
115
+ u({ method: "GET", path: "/__motia/bullmq/queues" }, async () => {
37
116
  try {
38
- return { status: 200, body: { queues: await g(m, n, c) } };
117
+ return { status: 200, body: { queues: await S(o, s, a) } };
39
118
  } catch (t) {
40
119
  return { status: 500, body: { error: t instanceof Error ? t.message : "Unknown error" } };
41
120
  }
42
- }), s(
121
+ }), u(
43
122
  { method: "GET", path: "/__motia/bullmq/queues/:name" },
44
123
  async (t) => {
45
124
  try {
46
- const e = t.pathParams.name, r = i(e, m, n), [u, a] = await Promise.all([r.isPaused(), r.getJobCounts()]);
125
+ const e = t.pathParams.name, n = d(e, o, s), [i, r] = await Promise.all([n.isPaused(), n.getJobCounts()]);
47
126
  return {
48
127
  status: 200,
49
128
  body: {
50
129
  name: e,
51
130
  displayName: e,
52
- isPaused: u,
53
- isDLQ: e.endsWith(c),
131
+ isPaused: i,
132
+ isDLQ: e.endsWith(a),
54
133
  stats: {
55
- waiting: a.waiting || 0,
56
- active: a.active || 0,
57
- completed: a.completed || 0,
58
- failed: a.failed || 0,
59
- delayed: a.delayed || 0,
60
- paused: a.paused || 0,
61
- prioritized: a.prioritized || 0
134
+ waiting: r.waiting || 0,
135
+ active: r.active || 0,
136
+ completed: r.completed || 0,
137
+ failed: r.failed || 0,
138
+ delayed: r.delayed || 0,
139
+ paused: r.paused || 0,
140
+ prioritized: r.prioritized || 0
62
141
  }
63
142
  }
64
143
  };
@@ -66,210 +145,226 @@ const h = /* @__PURE__ */ new Map(), i = (s, n, c) => {
66
145
  return { status: 500, body: { error: e instanceof Error ? e.message : "Unknown error" } };
67
146
  }
68
147
  }
69
- ), s(
148
+ ), u(
70
149
  { method: "POST", path: "/__motia/bullmq/queues/:name/pause" },
71
150
  async (t) => {
72
151
  try {
73
152
  const e = t.pathParams.name;
74
- return await i(e, m, n).pause(), { status: 200, body: { message: "Queue paused" } };
153
+ return await d(e, o, s).pause(), { status: 200, body: { message: "Queue paused" } };
75
154
  } catch (e) {
76
155
  return { status: 500, body: { error: e instanceof Error ? e.message : "Unknown error" } };
77
156
  }
78
157
  }
79
- ), s(
158
+ ), u(
80
159
  { method: "POST", path: "/__motia/bullmq/queues/:name/resume" },
81
160
  async (t) => {
82
161
  try {
83
162
  const e = t.pathParams.name;
84
- return await i(e, m, n).resume(), { status: 200, body: { message: "Queue resumed" } };
163
+ return await d(e, o, s).resume(), { status: 200, body: { message: "Queue resumed" } };
85
164
  } catch (e) {
86
165
  return { status: 500, body: { error: e instanceof Error ? e.message : "Unknown error" } };
87
166
  }
88
167
  }
89
- ), s(
168
+ ), u(
90
169
  { method: "POST", path: "/__motia/bullmq/queues/:name/clean" },
91
170
  async (t) => {
92
171
  try {
93
- const e = t.pathParams.name, r = t.body, u = {
94
- grace: r.grace ?? 0,
95
- limit: r.limit ?? 1e3,
96
- status: r.status ?? "completed"
97
- }, l = await i(e, m, n).clean(u.grace, u.limit, u.status);
98
- return { status: 200, body: { deleted: l.length, ids: l } };
172
+ const e = t.pathParams.name, n = t.body, i = {
173
+ grace: n.grace ?? 0,
174
+ limit: n.limit ?? 1e3,
175
+ status: n.status ?? "completed"
176
+ }, m = await d(e, o, s).clean(i.grace, i.limit, i.status);
177
+ return { status: 200, body: { deleted: m.length, ids: m } };
99
178
  } catch (e) {
100
179
  return { status: 500, body: { error: e instanceof Error ? e.message : "Unknown error" } };
101
180
  }
102
181
  }
103
- ), s(
182
+ ), u(
104
183
  { method: "POST", path: "/__motia/bullmq/queues/:name/drain" },
105
184
  async (t) => {
106
185
  try {
107
186
  const e = t.pathParams.name;
108
- return await i(e, m, n).drain(), { status: 200, body: { message: "Queue drained" } };
187
+ return await d(e, o, s).drain(), { status: 200, body: { message: "Queue drained" } };
109
188
  } catch (e) {
110
189
  return { status: 500, body: { error: e instanceof Error ? e.message : "Unknown error" } };
111
190
  }
112
191
  }
113
- ), s(
192
+ ), u(
114
193
  { method: "GET", path: "/__motia/bullmq/queues/:name/jobs" },
115
194
  async (t) => {
116
195
  try {
117
- const e = t.pathParams.name, r = t.queryParams.status || "waiting", u = parseInt(t.queryParams.start, 10) || 0, a = parseInt(t.queryParams.end, 10) || 100;
118
- return { status: 200, body: { jobs: (await i(e, m, n).getJobs([r], u, a)).map((o) => ({
119
- id: o.id || "",
120
- name: o.name,
121
- data: o.data,
122
- opts: o.opts,
123
- progress: typeof o.progress == "object" ? JSON.stringify(o.progress) : o.progress,
124
- timestamp: o.timestamp,
125
- attemptsMade: o.attemptsMade,
126
- processedOn: o.processedOn,
127
- finishedOn: o.finishedOn,
128
- returnvalue: o.returnvalue,
129
- failedReason: o.failedReason,
130
- stacktrace: o.stacktrace
196
+ const e = t.pathParams.name, n = t.queryParams.status || "waiting", i = parseInt(t.queryParams.start, 10) || 0, r = parseInt(t.queryParams.end, 10) || 100;
197
+ return { status: 200, body: { jobs: (await d(e, o, s).getJobs([n], i, r)).map((c) => ({
198
+ id: c.id || "",
199
+ name: c.name,
200
+ data: c.data,
201
+ opts: c.opts,
202
+ progress: typeof c.progress == "object" ? JSON.stringify(c.progress) : c.progress,
203
+ timestamp: c.timestamp,
204
+ attemptsMade: c.attemptsMade,
205
+ processedOn: c.processedOn,
206
+ finishedOn: c.finishedOn,
207
+ returnvalue: c.returnvalue,
208
+ failedReason: c.failedReason,
209
+ stacktrace: c.stacktrace
131
210
  })) } };
132
211
  } catch (e) {
133
212
  return { status: 500, body: { error: e instanceof Error ? e.message : "Unknown error" } };
134
213
  }
135
214
  }
136
- ), s(
215
+ ), u(
137
216
  { method: "GET", path: "/__motia/bullmq/queues/:queueName/jobs/:jobId" },
138
217
  async (t) => {
139
218
  try {
140
- const e = t.pathParams.queueName, r = t.pathParams.jobId, a = await i(e, m, n).getJob(r);
141
- return a ? { status: 200, body: {
142
- id: a.id || "",
143
- name: a.name,
144
- data: a.data,
145
- opts: a.opts,
146
- progress: typeof a.progress == "object" ? JSON.stringify(a.progress) : a.progress,
147
- timestamp: a.timestamp,
148
- attemptsMade: a.attemptsMade,
149
- processedOn: a.processedOn,
150
- finishedOn: a.finishedOn,
151
- returnvalue: a.returnvalue,
152
- failedReason: a.failedReason,
153
- stacktrace: a.stacktrace
219
+ const e = t.pathParams.queueName, n = t.pathParams.jobId, r = await d(e, o, s).getJob(n);
220
+ return r ? { status: 200, body: {
221
+ id: r.id || "",
222
+ name: r.name,
223
+ data: r.data,
224
+ opts: r.opts,
225
+ progress: typeof r.progress == "object" ? JSON.stringify(r.progress) : r.progress,
226
+ timestamp: r.timestamp,
227
+ attemptsMade: r.attemptsMade,
228
+ processedOn: r.processedOn,
229
+ finishedOn: r.finishedOn,
230
+ returnvalue: r.returnvalue,
231
+ failedReason: r.failedReason,
232
+ stacktrace: r.stacktrace
154
233
  } } : { status: 404, body: { error: "Job not found" } };
155
234
  } catch (e) {
156
235
  return { status: 500, body: { error: e instanceof Error ? e.message : "Unknown error" } };
157
236
  }
158
237
  }
159
- ), s(
238
+ ), u(
160
239
  { method: "POST", path: "/__motia/bullmq/queues/:queueName/jobs/:jobId/retry" },
161
240
  async (t) => {
162
241
  try {
163
- const e = t.pathParams.queueName, r = t.pathParams.jobId, a = await i(e, m, n).getJob(r);
164
- return a ? (await a.retry(), { status: 200, body: { message: "Job retried" } }) : { status: 404, body: { error: "Job not found" } };
242
+ const e = t.pathParams.queueName, n = t.pathParams.jobId, r = await d(e, o, s).getJob(n);
243
+ return r ? (await r.retry(), { status: 200, body: { message: "Job retried" } }) : { status: 404, body: { error: "Job not found" } };
165
244
  } catch (e) {
166
245
  return { status: 500, body: { error: e instanceof Error ? e.message : "Unknown error" } };
167
246
  }
168
247
  }
169
- ), s(
248
+ ), u(
170
249
  { method: "POST", path: "/__motia/bullmq/queues/:queueName/jobs/:jobId/remove" },
171
250
  async (t) => {
172
251
  try {
173
- const e = t.pathParams.queueName, r = t.pathParams.jobId, a = await i(e, m, n).getJob(r);
174
- return a ? (await a.remove(), { status: 200, body: { message: "Job removed" } }) : { status: 404, body: { error: "Job not found" } };
252
+ const e = t.pathParams.queueName, n = t.pathParams.jobId, r = await d(e, o, s).getJob(n);
253
+ return r ? (await r.remove(), { status: 200, body: { message: "Job removed" } }) : { status: 404, body: { error: "Job not found" } };
175
254
  } catch (e) {
176
255
  return { status: 500, body: { error: e instanceof Error ? e.message : "Unknown error" } };
177
256
  }
178
257
  }
179
- ), s(
258
+ ), u(
180
259
  { method: "POST", path: "/__motia/bullmq/queues/:queueName/jobs/:jobId/promote" },
181
260
  async (t) => {
182
261
  try {
183
- const e = t.pathParams.queueName, r = t.pathParams.jobId, a = await i(e, m, n).getJob(r);
184
- return a ? (await a.promote(), { status: 200, body: { message: "Job promoted" } }) : { status: 404, body: { error: "Job not found" } };
262
+ const e = t.pathParams.queueName, n = t.pathParams.jobId, r = await d(e, o, s).getJob(n);
263
+ return r ? (await r.promote(), { status: 200, body: { message: "Job promoted" } }) : { status: 404, body: { error: "Job not found" } };
185
264
  } catch (e) {
186
265
  return { status: 500, body: { error: e instanceof Error ? e.message : "Unknown error" } };
187
266
  }
188
267
  }
189
- ), s(
268
+ ), u(
190
269
  { method: "GET", path: "/__motia/bullmq/dlq/:name/jobs" },
191
270
  async (t) => {
192
271
  try {
193
- const e = t.pathParams.name, r = parseInt(t.queryParams.start, 10) || 0, u = parseInt(t.queryParams.end, 10) || 100, a = e.endsWith(c) ? e : `${e}${c}`;
194
- return { status: 200, body: { jobs: (await i(a, m, n).getJobs(["waiting", "completed"], r, u)).map((o) => ({
195
- id: o.id || "",
196
- name: o.name,
197
- data: o.data,
198
- timestamp: o.timestamp,
199
- originalEvent: o.data?.originalEvent,
200
- failureReason: o.data?.failureReason || o.failedReason,
201
- failureTimestamp: o.data?.failureTimestamp || o.finishedOn,
202
- attemptsMade: o.data?.attemptsMade || o.attemptsMade
272
+ const e = t.pathParams.name, n = parseInt(t.queryParams.start, 10) || 0, i = parseInt(t.queryParams.end, 10) || 100, r = e.endsWith(a) ? e : `${e}${a}`;
273
+ return { status: 200, body: { jobs: (await d(r, o, s).getJobs(["waiting", "completed"], n, i)).map((c) => ({
274
+ id: c.id || "",
275
+ name: c.name,
276
+ data: c.data,
277
+ timestamp: c.timestamp,
278
+ originalEvent: c.data?.originalEvent,
279
+ failureReason: c.data?.failureReason || c.failedReason,
280
+ failureTimestamp: c.data?.failureTimestamp || c.finishedOn,
281
+ attemptsMade: c.data?.attemptsMade || c.attemptsMade
203
282
  })) } };
204
283
  } catch (e) {
205
284
  return { status: 500, body: { error: e instanceof Error ? e.message : "Unknown error" } };
206
285
  }
207
286
  }
208
- ), s(
287
+ ), u(
209
288
  { method: "POST", path: "/__motia/bullmq/dlq/:name/retry/:jobId" },
210
289
  async (t) => {
211
290
  try {
212
- const e = t.pathParams.name, r = t.pathParams.jobId, u = e.endsWith(c) ? e : `${e}${c}`, l = await i(u, m, n).getJob(r);
213
- if (!l)
291
+ const e = t.pathParams.name, n = t.pathParams.jobId, i = e.endsWith(a) ? e : `${e}${a}`, m = await d(i, o, s).getJob(n);
292
+ if (!m)
214
293
  return { status: 404, body: { error: "Job not found in DLQ" } };
215
- const d = l.data?.originalEvent;
216
- if (d) {
217
- const b = u.replace(c, ""), o = i(b, m, n), p = {
218
- topic: d.topic,
219
- data: d.data,
220
- traceId: d.traceId
294
+ const l = m.data?.originalEvent;
295
+ if (l) {
296
+ const p = i.replace(a, ""), c = d(p, o, s), h = {
297
+ topic: l.topic,
298
+ data: l.data,
299
+ traceId: l.traceId
221
300
  };
222
- d.flows && (p.flows = d.flows), d.messageGroupId && (p.messageGroupId = d.messageGroupId), await o.add(d.topic || l.name, p);
301
+ l.flows && (h.flows = l.flows), l.messageGroupId && (h.messageGroupId = l.messageGroupId), await c.add(l.topic || m.name, h);
223
302
  }
224
- return await l.remove(), { status: 200, body: { message: "Job retried from DLQ" } };
303
+ return await m.remove(), { status: 200, body: { message: "Job retried from DLQ" } };
225
304
  } catch (e) {
226
305
  return { status: 500, body: { error: e instanceof Error ? e.message : "Unknown error" } };
227
306
  }
228
307
  }
229
- ), s(
308
+ ), u(
230
309
  { method: "POST", path: "/__motia/bullmq/dlq/:name/retry-all" },
231
310
  async (t) => {
232
311
  try {
233
- const e = t.pathParams.name, r = e.endsWith(c) ? e : `${e}${c}`, a = await i(r, m, n).getJobs(["waiting", "completed"]), l = r.replace(c, ""), d = i(l, m, n);
234
- let b = 0;
235
- for (const o of a) {
236
- const p = o.data?.originalEvent;
237
- if (p) {
312
+ const e = t.pathParams.name, n = e.endsWith(a) ? e : `${e}${a}`, r = await d(n, o, s).getJobs(["waiting", "completed"]), m = n.replace(a, ""), l = d(m, o, s);
313
+ let p = 0;
314
+ for (const c of r) {
315
+ const h = c.data?.originalEvent;
316
+ if (h) {
238
317
  const y = {
239
- topic: p.topic,
240
- data: p.data,
241
- traceId: p.traceId
318
+ topic: h.topic,
319
+ data: h.data,
320
+ traceId: h.traceId
242
321
  };
243
- p.flows && (y.flows = p.flows), p.messageGroupId && (y.messageGroupId = p.messageGroupId), await d.add(p.topic || o.name, y);
322
+ h.flows && (y.flows = h.flows), h.messageGroupId && (y.messageGroupId = h.messageGroupId), await l.add(h.topic || c.name, y);
244
323
  }
245
- await o.remove(), b++;
324
+ await c.remove(), p++;
246
325
  }
247
- return { status: 200, body: { message: `Retried ${b} jobs from DLQ`, count: b } };
326
+ return { status: 200, body: { message: `Retried ${p} jobs from DLQ`, count: p } };
248
327
  } catch (e) {
249
328
  return { status: 500, body: { error: e instanceof Error ? e.message : "Unknown error" } };
250
329
  }
251
330
  }
252
- ), s(
331
+ ), u(
253
332
  { method: "POST", path: "/__motia/bullmq/dlq/:name/clear" },
254
333
  async (t) => {
255
334
  try {
256
- const e = t.pathParams.name, r = e.endsWith(c) ? e : `${e}${c}`;
257
- return await i(r, m, n).obliterate({ force: !0 }), { status: 200, body: { message: "DLQ cleared" } };
335
+ const e = t.pathParams.name, n = e.endsWith(a) ? e : `${e}${a}`;
336
+ return await d(n, o, s).obliterate({ force: !0 }), { status: 200, body: { message: "DLQ cleared" } };
258
337
  } catch (e) {
259
338
  return { status: 500, body: { error: e instanceof Error ? e.message : "Unknown error" } };
260
339
  }
261
340
  }
262
341
  );
263
- }, P = (s) => s !== null && typeof s == "object" && "connection" in s && "prefix" in s && "dlqSuffix" in s;
264
- function v(s) {
265
- let n, c, m, t = !1;
266
- if (P(s.eventAdapter))
267
- n = s.eventAdapter.connection, c = s.eventAdapter.prefix, m = s.eventAdapter.dlqSuffix;
342
+ }, q = "__motia.bullmq-queues", k = (u) => u !== null && typeof u == "object" && "connection" in u && "prefix" in u && "dlqSuffix" in u;
343
+ function U(u) {
344
+ let s, a, o, t = !1;
345
+ if (k(u.eventAdapter))
346
+ s = u.eventAdapter.connection, a = u.eventAdapter.prefix, o = u.eventAdapter.dlqSuffix;
268
347
  else {
269
- const e = process.env.BULLMQ_REDIS_HOST || process.env.REDIS_HOST || "localhost", r = parseInt(process.env.BULLMQ_REDIS_PORT || process.env.REDIS_PORT || "6379", 10), u = process.env.BULLMQ_REDIS_PASSWORD || process.env.REDIS_PASSWORD || void 0;
270
- c = process.env.BULLMQ_PREFIX || "motia:events", m = process.env.BULLMQ_DLQ_SUFFIX || ".dlq", n = new q({ host: e, port: r, password: u, maxRetriesPerRequest: null }), t = !0;
348
+ const i = process.env.BULLMQ_REDIS_HOST || process.env.REDIS_HOST || "localhost", r = parseInt(process.env.BULLMQ_REDIS_PORT || process.env.REDIS_PORT || "6379", 10), m = process.env.BULLMQ_REDIS_PASSWORD || process.env.REDIS_PASSWORD || void 0;
349
+ a = process.env.BULLMQ_PREFIX || "motia:events", o = process.env.BULLMQ_DLQ_SUFFIX || ".dlq", s = new P({ host: i, port: r, password: m, maxRetriesPerRequest: null }), t = !0;
271
350
  }
272
- return f(s, c, m, n), {
351
+ const e = new E(s, a, o), n = u.lockedData.createStream({
352
+ filePath: `${q}.ts`,
353
+ hidden: !0,
354
+ config: {
355
+ name: q,
356
+ baseConfig: { storageType: "custom", factory: () => e },
357
+ schema: null
358
+ }
359
+ })();
360
+ return e.setUpdateCallback((i) => {
361
+ n.set("default", i.id, i);
362
+ }), e.setupAllQueueEvents().then(() => {
363
+ e.getGroup("default").then((i) => {
364
+ for (const r of i)
365
+ n.set("default", r.id, r);
366
+ });
367
+ }), O(u, a, o, s), {
273
368
  workbench: [
274
369
  {
275
370
  packageName: "@motiadev/plugin-bullmq",
@@ -281,10 +376,10 @@ function v(s) {
281
376
  }
282
377
  ],
283
378
  onShutdown: async () => {
284
- t && await n.quit();
379
+ await e.closeAllQueueEvents(), t && await s.quit();
285
380
  }
286
381
  };
287
382
  }
288
383
  export {
289
- v as default
384
+ U as default
290
385
  };
@@ -0,0 +1,7 @@
1
+ import { ReactNode } from 'react';
2
+ type QueryProviderProps = {
3
+ children: ReactNode;
4
+ };
5
+ export declare const QueryProvider: ({ children }: QueryProviderProps) => import("react/jsx-runtime").JSX.Element;
6
+ export {};
7
+ //# sourceMappingURL=query-provider.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"query-provider.d.ts","sourceRoot":"","sources":["../../src/providers/query-provider.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,OAAO,CAAA;AAYtC,KAAK,kBAAkB,GAAG;IACxB,QAAQ,EAAE,SAAS,CAAA;CACpB,CAAA;AAED,eAAO,MAAM,aAAa,GAAI,cAAc,kBAAkB,4CAE7D,CAAA"}
@@ -2,20 +2,16 @@ import { JobInfo, JobStatus, QueueInfo } from '../types/queue';
2
2
  type BullMQState = {
3
3
  queues: QueueInfo[];
4
4
  selectedQueue: QueueInfo | null;
5
- jobs: JobInfo[];
6
5
  selectedJob: JobInfo | null;
7
6
  selectedStatus: JobStatus;
8
- isLoading: boolean;
9
7
  error: string | null;
10
8
  searchQuery: string;
11
9
  jobDetailOpen: boolean;
12
10
  setQueues: (queues: QueueInfo[]) => void;
13
11
  setSelectedQueue: (queue: QueueInfo | null) => void;
14
12
  updateSelectedQueueStats: (queue: QueueInfo) => void;
15
- setJobs: (jobs: JobInfo[]) => void;
16
13
  setSelectedJob: (job: JobInfo | null) => void;
17
14
  setSelectedStatus: (status: JobStatus) => void;
18
- setLoading: (loading: boolean) => void;
19
15
  setError: (error: string | null) => void;
20
16
  setSearchQuery: (query: string) => void;
21
17
  setJobDetailOpen: (open: boolean) => void;
@@ -1 +1 @@
1
- {"version":3,"file":"use-bullmq-store.d.ts","sourceRoot":"","sources":["../../src/stores/use-bullmq-store.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAA;AAEnE,KAAK,WAAW,GAAG;IACjB,MAAM,EAAE,SAAS,EAAE,CAAA;IACnB,aAAa,EAAE,SAAS,GAAG,IAAI,CAAA;IAC/B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E,SAAS,GAAG,IAAI,CAAA;IAC/B,WAAW,EAAE,OAAO,GAAG,IAAI,CAAA;IAC3B,cAAc,EAAE,SAAS,CAAA;IACzB,KAAK,EAAE,MAAM,GAAG,IAAI,CAAA;IACpB,WAAW,EAAE,MAAM,CAAA;IACnB,aAAa,EAAE,OAAO,CAAA;IAEtB,SAAS,EAAE,CAAC,MAAM,EAAE,SAAS,EAAE,KAAK,IAAI,CAAA;IACxC,gBAAgB,EAAE,CAAC,KAAK,EAAE,SAAS,GAAG,IAAI,KAAK,IAAI,CAAA;IACnD,wBAAwB,EAAE,CAAC,KAAK,EAAE,SAAS,KAAK,IAAI,CAAA;IACpD,cAAc,EAAE,CAAC,GAAG,EAAE,OAAO,GAAG,IAAI,KAAK,IAAI,CAAA;IAC7C,iBAAiB,EAAE,CAAC,MAAM,EAAE,SAAS,KAAK,IAAI,CAAA;IAC9C,QAAQ,EAAE,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,KAAK,IAAI,CAAA;IACxC,cAAc,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAA;IACvC,gBAAgB,EAAE,CAAC,IAAI,EAAE,OAAO,KAAK,IAAI,CAAA;IACzC,KAAK,EAAE,MAAM,IAAI,CAAA;CAClB,CAAA;AAYD,eAAO,MAAM,cAAc,0EAYxB,CAAA"}
@@ -0,0 +1,33 @@
1
+ import { StreamAdapter } from '@motiadev/core';
2
+ import { Queue } from 'bullmq';
3
+ import { Redis } from 'ioredis';
4
+ import { QueueInfo } from '../types/queue';
5
+ export declare const getOrCreateQueue: (name: string, connection: Redis, prefix: string) => Queue;
6
+ export declare const discoverQueueNames: (connection: Redis, prefix: string) => Promise<Set<string>>;
7
+ export declare const getQueueInfo: (name: string, connection: Redis, prefix: string, dlqSuffix: string) => Promise<QueueInfo>;
8
+ type StreamQueueInfo = QueueInfo & {
9
+ id: string;
10
+ };
11
+ export declare class QueuesStream extends StreamAdapter<StreamQueueInfo> {
12
+ private connection;
13
+ private prefix;
14
+ private dlqSuffix;
15
+ private knownQueues;
16
+ private onQueueUpdate?;
17
+ private lastStatsCache;
18
+ private debounceTimers;
19
+ constructor(connection: Redis, prefix: string, dlqSuffix: string);
20
+ setUpdateCallback(callback: (queueInfo: StreamQueueInfo) => void): void;
21
+ get(_groupId: string, id: string): Promise<StreamQueueInfo | null>;
22
+ set(_groupId: string, _id: string, data: StreamQueueInfo): Promise<StreamQueueInfo>;
23
+ delete(_groupId: string, id: string): Promise<StreamQueueInfo | null>;
24
+ getGroup(_groupId: string): Promise<StreamQueueInfo[]>;
25
+ refreshQueue(name: string): Promise<StreamQueueInfo>;
26
+ private debouncedRefresh;
27
+ setupQueueEvents(queueName: string): void;
28
+ setupAllQueueEvents(): Promise<void>;
29
+ closeAllQueueEvents(): Promise<void>;
30
+ getKnownQueues(): Set<string>;
31
+ }
32
+ export {};
33
+ //# sourceMappingURL=queues-stream.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"queues-stream.d.ts","sourceRoot":"","sources":["../../src/streams/queues-stream.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAA;AAC9C,OAAO,EAAE,KAAK,EAAe,MAAM,QAAQ,CAAA;AAC3C,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,SAAS,CAAA;AACpC,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAA;AAK/C,eAAO,MAAM,gBAAgB,GAAI,MAAM,MAAM,EAAE,YAAY,KAAK,EAAE,QAAQ,MAAM,KAAG,KAQlF,CAAA;AAED,eAAO,MAAM,kBAAkB,GAAU,YAAY,KAAK,EAAE,QAAQ,MAAM,KAAG,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,CAY/F,CAAA;AAED,eAAO,MAAM,YAAY,GACvB,MAAM,MAAM,EACZ,YAAY,KAAK,EACjB,QAAQ,MAAM,EACd,WAAW,MAAM,KAChB,OAAO,CAAC,SAAS,CAmBnB,CAAA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,6 @@
1
1
  {
2
2
  "name": "@motiadev/plugin-bullmq",
3
- "version": "0.13.0-beta.162-717198",
3
+ "version": "0.13.0-beta.162-415452",
4
4
  "type": "module",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.js",
@@ -22,6 +22,7 @@
22
22
  "dist"
23
23
  ],
24
24
  "dependencies": {
25
+ "@tanstack/react-query": "^5.62.0",
25
26
  "bullmq": "^5.63.0",
26
27
  "date-fns": "^3.6.0",
27
28
  "ioredis": "^5.8.2",
@@ -30,10 +31,10 @@
30
31
  "zustand": "^5.0.8"
31
32
  },
32
33
  "peerDependencies": {
33
- "@motiadev/adapter-bullmq-events": "0.13.0-beta.162-717198",
34
- "@motiadev/stream-client-react": "0.13.0-beta.162-717198",
35
- "@motiadev/ui": "0.13.0-beta.162-717198",
36
- "@motiadev/core": "0.13.0-beta.162-717198"
34
+ "@motiadev/adapter-bullmq-events": "0.13.0-beta.162-415452",
35
+ "@motiadev/core": "0.13.0-beta.162-415452",
36
+ "@motiadev/stream-client-react": "0.13.0-beta.162-415452",
37
+ "@motiadev/ui": "0.13.0-beta.162-415452"
37
38
  },
38
39
  "devDependencies": {
39
40
  "@tailwindcss/vite": "^4.1.14",