@mcp-fe/mcp-worker 0.0.9 → 0.0.12

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/index.js CHANGED
@@ -1,4 +1,5 @@
1
- class W {
1
+ // libs/mcp-worker/src/lib/worker-client.ts
2
+ var WorkerClient = class {
2
3
  serviceWorkerRegistration = null;
3
4
  sharedWorker = null;
4
5
  sharedWorkerPort = null;
@@ -10,246 +11,369 @@ class W {
10
11
  // Mutex/promise to prevent concurrent init runs
11
12
  initPromise = null;
12
13
  // Initialize and choose worker implementation (prefer SharedWorker)
13
- async init(e) {
14
- return this.initPromise ? this.initPromise.then(async () => {
15
- e && this.workerType !== "service" && await this.init(e);
16
- }) : (this.initPromise = (async () => {
14
+ async init(registration) {
15
+ if (this.initPromise) {
16
+ return this.initPromise.then(async () => {
17
+ if (registration && this.workerType !== "service") {
18
+ await this.init(registration);
19
+ }
20
+ });
21
+ }
22
+ this.initPromise = (async () => {
17
23
  try {
18
- if (e) {
19
- this.serviceWorkerRegistration = e, this.workerType = "service", console.log("[WorkerClient] Using ServiceWorker (explicit registration)"), this.pendingAuthToken && (this.sendAuthTokenToServiceWorker(this.pendingAuthToken), this.pendingAuthToken = null);
24
+ if (registration) {
25
+ this.serviceWorkerRegistration = registration;
26
+ this.workerType = "service";
27
+ console.log("[WorkerClient] Using ServiceWorker (explicit registration)");
28
+ if (this.pendingAuthToken) {
29
+ this.sendAuthTokenToServiceWorker(this.pendingAuthToken);
30
+ this.pendingAuthToken = null;
31
+ }
20
32
  return;
21
33
  }
22
- if (typeof SharedWorker < "u")
34
+ if (typeof SharedWorker !== "undefined") {
23
35
  try {
24
- if (this.sharedWorker = new SharedWorker("/shared-worker.js", { type: "module" }), this.sharedWorkerPort = this.sharedWorker.port, this.sharedWorkerPort.start(), this.pendingAuthToken && this.sharedWorkerPort)
36
+ this.sharedWorker = new SharedWorker("/mcp-shared-worker.js", { type: "module" });
37
+ this.sharedWorkerPort = this.sharedWorker.port;
38
+ this.sharedWorkerPort.start();
39
+ if (this.pendingAuthToken && this.sharedWorkerPort) {
25
40
  try {
26
41
  this.sharedWorkerPort.postMessage({ type: "SET_AUTH_TOKEN", token: this.pendingAuthToken });
27
- } catch (o) {
28
- console.warn("[WorkerClient] Immediate postMessage to SharedWorker failed (will retry after init):", o);
42
+ } catch (err) {
43
+ console.warn("[WorkerClient] Immediate postMessage to SharedWorker failed (will retry after init):", err);
29
44
  }
30
- this.sharedWorker.onerror = (o) => {
31
- console.error("[WorkerClient] SharedWorker error:", o.message || o.error || o), this.workerType !== "shared" && this.initServiceWorkerFallback().catch((s) => {
32
- console.error("[WorkerClient] Failed to initialize ServiceWorker fallback:", s);
33
- });
34
- }, await new Promise((o, s) => {
35
- let n = !1;
36
- const c = setTimeout(() => {
37
- if (!n) {
38
- const r = this.sharedWorkerPort;
39
- r && (r.onmessage = null), s(new Error("SharedWorker initialization timeout"));
45
+ }
46
+ this.sharedWorker.onerror = (event) => {
47
+ console.error("[WorkerClient] SharedWorker error:", event.message || event.error || event);
48
+ if (this.workerType !== "shared") {
49
+ this.initServiceWorkerFallback().catch((err) => {
50
+ console.error("[WorkerClient] Failed to initialize ServiceWorker fallback:", err);
51
+ });
52
+ }
53
+ };
54
+ await new Promise((resolve, reject) => {
55
+ let resolved = false;
56
+ const timeout = setTimeout(() => {
57
+ if (!resolved) {
58
+ const p2 = this.sharedWorkerPort;
59
+ if (p2)
60
+ p2.onmessage = null;
61
+ reject(new Error("SharedWorker initialization timeout"));
40
62
  }
41
- }, 2e3), a = this.sharedWorkerPort;
42
- if (!a)
43
- return clearTimeout(c), s(new Error("SharedWorker port not available"));
44
- a.onmessage = (r) => {
63
+ }, 2e3);
64
+ const p = this.sharedWorkerPort;
65
+ if (!p) {
66
+ clearTimeout(timeout);
67
+ return reject(new Error("SharedWorker port not available"));
68
+ }
69
+ p.onmessage = (ev) => {
45
70
  try {
46
- const i = r.data;
47
- i && i.type === "CONNECTION_STATUS" && (clearTimeout(c), n = !0, this.workerType = "shared", a.onmessage = null, o());
71
+ const data = ev.data;
72
+ if (data && data.type === "CONNECTION_STATUS") {
73
+ clearTimeout(timeout);
74
+ resolved = true;
75
+ this.workerType = "shared";
76
+ p.onmessage = null;
77
+ resolve();
78
+ }
48
79
  } catch {
49
80
  }
50
81
  };
51
82
  });
52
- const t = this.sharedWorkerPort;
53
- if (this.pendingAuthToken && t)
83
+ const portAfterInit = this.sharedWorkerPort;
84
+ if (this.pendingAuthToken && portAfterInit) {
54
85
  try {
55
- t.postMessage({ type: "SET_AUTH_TOKEN", token: this.pendingAuthToken }), this.pendingAuthToken = null;
56
- } catch (o) {
57
- console.error("[WorkerClient] Failed to send pending auth token to SharedWorker:", o);
86
+ portAfterInit.postMessage({ type: "SET_AUTH_TOKEN", token: this.pendingAuthToken });
87
+ this.pendingAuthToken = null;
88
+ } catch (e) {
89
+ console.error("[WorkerClient] Failed to send pending auth token to SharedWorker:", e);
58
90
  }
59
- t && (t.onmessage = (o) => {
60
- try {
61
- const s = o.data;
62
- if (s && s.type === "CONNECTION_STATUS") {
63
- const n = !!s.connected;
64
- this.connectionStatusCallbacks.forEach((c) => {
65
- try {
66
- c(n);
67
- } catch {
68
- }
69
- });
91
+ }
92
+ if (portAfterInit) {
93
+ portAfterInit.onmessage = (ev) => {
94
+ try {
95
+ const data = ev.data;
96
+ if (data && data.type === "CONNECTION_STATUS") {
97
+ const connected = !!data.connected;
98
+ this.connectionStatusCallbacks.forEach((cb) => {
99
+ try {
100
+ cb(connected);
101
+ } catch (e) {
102
+ }
103
+ });
104
+ }
105
+ } catch {
70
106
  }
71
- } catch {
72
- }
73
- }), console.log("[WorkerClient] Using SharedWorker");
107
+ };
108
+ }
109
+ console.log("[WorkerClient] Using SharedWorker");
74
110
  return;
75
- } catch (t) {
76
- console.warn("[WorkerClient] SharedWorker not available, falling back to ServiceWorker:", t);
111
+ } catch (error) {
112
+ console.warn("[WorkerClient] SharedWorker not available, falling back to ServiceWorker:", error);
77
113
  }
78
- console.log("this should not be called"), await this.initServiceWorkerFallback(), this.pendingAuthToken && this.workerType === "service" && (this.sendAuthTokenToServiceWorker(this.pendingAuthToken), this.pendingAuthToken = null);
114
+ }
115
+ console.log("this should not be called");
116
+ await this.initServiceWorkerFallback();
117
+ if (this.pendingAuthToken && this.workerType === "service") {
118
+ this.sendAuthTokenToServiceWorker(this.pendingAuthToken);
119
+ this.pendingAuthToken = null;
120
+ }
79
121
  } finally {
80
122
  this.initPromise = null;
81
123
  }
82
- })(), this.initPromise);
124
+ })();
125
+ return this.initPromise;
83
126
  }
84
127
  async initServiceWorkerFallback() {
85
- if (console.log("initServiceWorkerFallback called"), "serviceWorker" in navigator)
128
+ console.log("initServiceWorkerFallback called");
129
+ if ("serviceWorker" in navigator) {
86
130
  try {
87
- const e = await navigator.serviceWorker.getRegistration();
88
- if (e) {
89
- this.serviceWorkerRegistration = e, this.workerType = "service", console.log("[WorkerClient] Using existing ServiceWorker registration");
131
+ const existingRegistration = await navigator.serviceWorker.getRegistration();
132
+ if (existingRegistration) {
133
+ this.serviceWorkerRegistration = existingRegistration;
134
+ this.workerType = "service";
135
+ console.log("[WorkerClient] Using existing ServiceWorker registration");
90
136
  return;
91
137
  }
92
- const t = await navigator.serviceWorker.register("/sw.js");
93
- this.serviceWorkerRegistration = t, this.workerType = "service", console.log("[WorkerClient] Using ServiceWorker (fallback)"), this.serviceWorkerMessageHandler && (navigator.serviceWorker.removeEventListener("message", this.serviceWorkerMessageHandler), this.serviceWorkerMessageHandler = null), this.serviceWorkerMessageHandler = (o) => {
138
+ const reg = await navigator.serviceWorker.register("/mcp-service-worker.js");
139
+ this.serviceWorkerRegistration = reg;
140
+ this.workerType = "service";
141
+ console.log("[WorkerClient] Using ServiceWorker (fallback)");
142
+ if (this.serviceWorkerMessageHandler) {
143
+ navigator.serviceWorker.removeEventListener("message", this.serviceWorkerMessageHandler);
144
+ this.serviceWorkerMessageHandler = null;
145
+ }
146
+ this.serviceWorkerMessageHandler = (ev) => {
94
147
  try {
95
- const s = o.data;
96
- if (s && s.type === "CONNECTION_STATUS") {
97
- const n = !!s.connected;
98
- this.connectionStatusCallbacks.forEach((c) => {
148
+ const data = ev.data;
149
+ if (data && data.type === "CONNECTION_STATUS") {
150
+ const connected = !!data.connected;
151
+ this.connectionStatusCallbacks.forEach((cb) => {
99
152
  try {
100
- c(n);
101
- } catch {
153
+ cb(connected);
154
+ } catch (e) {
102
155
  }
103
156
  });
104
157
  }
105
158
  } catch {
106
159
  }
107
- }, navigator.serviceWorker.addEventListener("message", this.serviceWorkerMessageHandler);
108
- } catch (e) {
109
- throw console.error("[WorkerClient] Failed to register ServiceWorker:", e), e;
160
+ };
161
+ navigator.serviceWorker.addEventListener("message", this.serviceWorkerMessageHandler);
162
+ } catch (error) {
163
+ console.error("[WorkerClient] Failed to register ServiceWorker:", error);
164
+ throw error;
110
165
  }
111
- else
166
+ } else {
112
167
  throw new Error("Neither SharedWorker nor ServiceWorker is supported");
168
+ }
113
169
  }
114
170
  // Low-level request that expects a reply via MessageChannel
115
- async request(e, t, o = 5e3) {
116
- if (this.workerType === "shared" && this.sharedWorkerPort)
117
- return new Promise((s, n) => {
118
- const c = new MessageChannel(), a = setTimeout(() => {
119
- c.port1.onmessage = null, n(new Error("Request timeout"));
120
- }, o);
121
- c.port1.onmessage = (r) => {
122
- clearTimeout(a), r.data && r.data.success ? s(r.data) : r.data && r.data.success === !1 ? n(new Error(r.data.error || "Worker error")) : s(r.data);
171
+ async request(type, payload, timeoutMs = 5e3) {
172
+ if (this.workerType === "shared" && this.sharedWorkerPort) {
173
+ return new Promise((resolve, reject) => {
174
+ const mc = new MessageChannel();
175
+ const timer = setTimeout(() => {
176
+ mc.port1.onmessage = null;
177
+ reject(new Error("Request timeout"));
178
+ }, timeoutMs);
179
+ mc.port1.onmessage = (ev) => {
180
+ clearTimeout(timer);
181
+ if (ev.data && ev.data.success) {
182
+ resolve(ev.data);
183
+ } else if (ev.data && ev.data.success === false) {
184
+ reject(new Error(ev.data.error || "Worker error"));
185
+ } else {
186
+ resolve(ev.data);
187
+ }
123
188
  };
124
189
  try {
125
- const r = this.sharedWorkerPort;
126
- if (!r)
127
- return clearTimeout(a), n(new Error("SharedWorker port not available"));
128
- r.postMessage({ type: e, ...t || {} }, [c.port2]);
129
- } catch (r) {
130
- clearTimeout(a), n(r instanceof Error ? r : new Error(String(r)));
190
+ const port = this.sharedWorkerPort;
191
+ if (!port) {
192
+ clearTimeout(timer);
193
+ return reject(new Error("SharedWorker port not available"));
194
+ }
195
+ port.postMessage({ type, ...payload || {} }, [mc.port2]);
196
+ } catch (e) {
197
+ clearTimeout(timer);
198
+ reject(e instanceof Error ? e : new Error(String(e)));
131
199
  }
132
200
  });
201
+ }
133
202
  if (this.workerType === "service" && this.serviceWorkerRegistration) {
134
- const s = this.serviceWorkerRegistration;
135
- if (!s) throw new Error("Service worker registration missing");
136
- if (!s.active && (await navigator.serviceWorker.ready, !s.active))
137
- throw new Error("Service worker not active");
138
- return new Promise((n, c) => {
139
- const a = new MessageChannel(), r = setTimeout(() => {
140
- a.port1.onmessage = null, c(new Error("Request timeout"));
141
- }, o);
142
- a.port1.onmessage = (i) => {
143
- clearTimeout(r), i.data && i.data.success ? n(i.data) : i.data && i.data.success === !1 ? c(new Error(i.data.error || "Worker error")) : n(i.data);
203
+ const reg = this.serviceWorkerRegistration;
204
+ if (!reg)
205
+ throw new Error("Service worker registration missing");
206
+ if (!reg.active) {
207
+ await navigator.serviceWorker.ready;
208
+ if (!reg.active) {
209
+ throw new Error("Service worker not active");
210
+ }
211
+ }
212
+ return new Promise((resolve, reject) => {
213
+ const mc = new MessageChannel();
214
+ const timer = setTimeout(() => {
215
+ mc.port1.onmessage = null;
216
+ reject(new Error("Request timeout"));
217
+ }, timeoutMs);
218
+ mc.port1.onmessage = (ev) => {
219
+ clearTimeout(timer);
220
+ if (ev.data && ev.data.success) {
221
+ resolve(ev.data);
222
+ } else if (ev.data && ev.data.success === false) {
223
+ reject(new Error(ev.data.error || "Worker error"));
224
+ } else {
225
+ resolve(ev.data);
226
+ }
144
227
  };
145
228
  try {
146
- const i = s.active;
147
- if (!i)
148
- return clearTimeout(r), c(new Error("Service worker active instance not available"));
149
- i.postMessage({ type: e, ...t || {} }, [a.port2]);
150
- } catch (i) {
151
- clearTimeout(r), c(i instanceof Error ? i : new Error(String(i)));
229
+ const active = reg.active;
230
+ if (!active) {
231
+ clearTimeout(timer);
232
+ return reject(new Error("Service worker active instance not available"));
233
+ }
234
+ active.postMessage({ type, ...payload || {} }, [mc.port2]);
235
+ } catch (e) {
236
+ clearTimeout(timer);
237
+ reject(e instanceof Error ? e : new Error(String(e)));
152
238
  }
153
239
  });
154
240
  }
155
241
  throw new Error("No worker registered");
156
242
  }
157
243
  // Fire-and-forget postMessage (no response expected)
158
- async post(e, t) {
244
+ async post(type, payload) {
159
245
  if (this.workerType === "shared" && this.sharedWorkerPort) {
160
246
  try {
161
- this.sharedWorkerPort.postMessage({ type: e, ...t || {} });
162
- } catch (o) {
163
- console.error("[WorkerClient] Failed to post to SharedWorker:", o);
247
+ this.sharedWorkerPort.postMessage({ type, ...payload || {} });
248
+ } catch (e) {
249
+ console.error("[WorkerClient] Failed to post to SharedWorker:", e);
164
250
  }
165
251
  return;
166
252
  }
167
253
  if (this.workerType === "service" && this.serviceWorkerRegistration?.active) {
168
254
  try {
169
- this.serviceWorkerRegistration.active.postMessage({ type: e, ...t || {} });
170
- } catch (o) {
171
- console.error("[WorkerClient] Failed to post to ServiceWorker (active):", o);
255
+ this.serviceWorkerRegistration.active.postMessage({ type, ...payload || {} });
256
+ } catch (e) {
257
+ console.error("[WorkerClient] Failed to post to ServiceWorker (active):", e);
172
258
  }
173
259
  return;
174
260
  }
175
261
  if ("serviceWorker" in navigator && navigator.serviceWorker.controller) {
176
262
  try {
177
- navigator.serviceWorker.controller.postMessage({ type: e, ...t || {} });
178
- } catch (o) {
179
- console.error("[WorkerClient] Failed to post to ServiceWorker.controller:", o);
263
+ navigator.serviceWorker.controller.postMessage({ type, ...payload || {} });
264
+ } catch (e) {
265
+ console.error("[WorkerClient] Failed to post to ServiceWorker.controller:", e);
180
266
  }
181
267
  return;
182
268
  }
183
- if (e === "SET_AUTH_TOKEN" && t) {
184
- const o = t.token;
185
- typeof o == "string" && (this.pendingAuthToken = o);
269
+ if (type === "SET_AUTH_TOKEN" && payload) {
270
+ const token = payload["token"];
271
+ if (typeof token === "string")
272
+ this.pendingAuthToken = token;
186
273
  }
187
274
  }
188
- sendAuthTokenToServiceWorker(e) {
189
- if (this.serviceWorkerRegistration?.active)
275
+ sendAuthTokenToServiceWorker(token) {
276
+ if (this.serviceWorkerRegistration?.active) {
190
277
  try {
191
- this.serviceWorkerRegistration.active.postMessage({ type: "SET_AUTH_TOKEN", token: e });
192
- } catch (t) {
193
- console.error("[WorkerClient] Failed to send auth token to ServiceWorker:", t);
278
+ this.serviceWorkerRegistration.active.postMessage({ type: "SET_AUTH_TOKEN", token });
279
+ } catch (e) {
280
+ console.error("[WorkerClient] Failed to send auth token to ServiceWorker:", e);
194
281
  }
195
- else if ("serviceWorker" in navigator && navigator.serviceWorker.controller)
282
+ } else if ("serviceWorker" in navigator && navigator.serviceWorker.controller) {
196
283
  try {
197
- navigator.serviceWorker.controller.postMessage({ type: "SET_AUTH_TOKEN", token: e });
198
- } catch (t) {
199
- console.error("[WorkerClient] Failed to send auth token to ServiceWorker.controller:", t);
284
+ navigator.serviceWorker.controller.postMessage({ type: "SET_AUTH_TOKEN", token });
285
+ } catch (e) {
286
+ console.error("[WorkerClient] Failed to send auth token to ServiceWorker.controller:", e);
200
287
  }
201
- else
202
- this.pendingAuthToken = e;
288
+ } else {
289
+ this.pendingAuthToken = token;
290
+ }
203
291
  }
204
292
  // Subscription API for consumers to listen for connection status updates
205
- onConnectionStatus(e) {
206
- this.connectionStatusCallbacks.add(e);
293
+ onConnectionStatus(cb) {
294
+ this.connectionStatusCallbacks.add(cb);
207
295
  }
208
- offConnectionStatus(e) {
209
- this.connectionStatusCallbacks.delete(e);
296
+ offConnectionStatus(cb) {
297
+ this.connectionStatusCallbacks.delete(cb);
210
298
  }
211
299
  async getConnectionStatus() {
212
300
  try {
213
- const e = await this.request("GET_CONNECTION_STATUS", void 0, 2e3);
214
- return e && typeof e == "object" && "connected" in e, !!e.connected;
301
+ const res = await this.request("GET_CONNECTION_STATUS", void 0, 2e3);
302
+ if (res && typeof res === "object" && "connected" in res)
303
+ return !!res.connected;
304
+ return !!res.connected;
215
305
  } catch {
216
- return !1;
306
+ return false;
217
307
  }
218
308
  }
219
- setAuthToken(e) {
220
- if (this.pendingAuthToken = e, this.workerType === "shared" && this.sharedWorkerPort)
309
+ setAuthToken(token) {
310
+ this.pendingAuthToken = token;
311
+ if (this.workerType === "shared" && this.sharedWorkerPort) {
221
312
  try {
222
- this.sharedWorkerPort.postMessage({ type: "SET_AUTH_TOKEN", token: e }), this.pendingAuthToken = null;
223
- } catch (t) {
224
- console.error("[WorkerClient] Failed to set auth token on SharedWorker:", t);
313
+ this.sharedWorkerPort.postMessage({ type: "SET_AUTH_TOKEN", token });
314
+ this.pendingAuthToken = null;
315
+ } catch (e) {
316
+ console.error("[WorkerClient] Failed to set auth token on SharedWorker:", e);
225
317
  }
226
- else this.workerType === "service" && (this.sendAuthTokenToServiceWorker(e), this.pendingAuthToken = null);
318
+ } else if (this.workerType === "service") {
319
+ this.sendAuthTokenToServiceWorker(token);
320
+ this.pendingAuthToken = null;
321
+ } else {
322
+ }
227
323
  }
228
- }
229
- const d = "user-activity-db", u = 1, h = "user-events";
230
- async function g() {
231
- return new Promise((l, e) => {
232
- const t = indexedDB.open(d, u);
233
- t.onerror = () => e(t.error), t.onsuccess = () => l(t.result), t.onupgradeneeded = (o) => {
234
- const s = o.target.result;
235
- if (!s.objectStoreNames.contains(h)) {
236
- const n = s.createObjectStore(h, { keyPath: "id" });
237
- n.createIndex("timestamp", "timestamp", { unique: !1 }), n.createIndex("type", "type", { unique: !1 }), n.createIndex("path", "path", { unique: !1 });
324
+ };
325
+
326
+ // libs/mcp-worker/src/lib/database.ts
327
+ var DB_NAME = "user-activity-db";
328
+ var DB_VERSION = 1;
329
+ var STORE_NAME = "user-events";
330
+ async function initDB() {
331
+ return new Promise((resolve, reject) => {
332
+ const request = indexedDB.open(DB_NAME, DB_VERSION);
333
+ request.onerror = () => reject(request.error);
334
+ request.onsuccess = () => resolve(request.result);
335
+ request.onupgradeneeded = (event) => {
336
+ const db = event.target.result;
337
+ if (!db.objectStoreNames.contains(STORE_NAME)) {
338
+ const store = db.createObjectStore(STORE_NAME, { keyPath: "id" });
339
+ store.createIndex("timestamp", "timestamp", { unique: false });
340
+ store.createIndex("type", "type", { unique: false });
341
+ store.createIndex("path", "path", { unique: false });
238
342
  }
239
343
  };
240
344
  });
241
345
  }
242
- async function T(l) {
243
- const s = (await g()).transaction([h], "readonly").objectStore(h).index("timestamp");
244
- return new Promise((n, c) => {
245
- const a = s.getAll();
246
- a.onsuccess = () => {
247
- let r = a.result;
248
- l?.type && (r = r.filter((i) => i.type === l.type)), l?.startTime && (r = r.filter((i) => i.timestamp >= l.startTime)), l?.endTime && (r = r.filter((i) => i.timestamp <= l.endTime)), l?.path && (r = r.filter((i) => i.path?.includes(l.path))), r.sort((i, k) => k.timestamp - i.timestamp), l?.limit && (r = r.slice(0, l.limit)), n(r);
249
- }, a.onerror = () => c(a.error);
346
+ async function queryEvents(filters) {
347
+ const db = await initDB();
348
+ const transaction = db.transaction([STORE_NAME], "readonly");
349
+ const store = transaction.objectStore(STORE_NAME);
350
+ const index = store.index("timestamp");
351
+ return new Promise((resolve, reject) => {
352
+ const request = index.getAll();
353
+ request.onsuccess = () => {
354
+ let events = request.result;
355
+ if (filters?.type) {
356
+ events = events.filter((e) => e.type === filters.type);
357
+ }
358
+ if (filters?.startTime) {
359
+ events = events.filter((e) => e.timestamp >= filters.startTime);
360
+ }
361
+ if (filters?.endTime) {
362
+ events = events.filter((e) => e.timestamp <= filters.endTime);
363
+ }
364
+ if (filters?.path) {
365
+ events = events.filter((e) => e.path?.includes(filters.path));
366
+ }
367
+ events.sort((a, b) => b.timestamp - a.timestamp);
368
+ if (filters?.limit) {
369
+ events = events.slice(0, filters.limit);
370
+ }
371
+ resolve(events);
372
+ };
373
+ request.onerror = () => reject(request.error);
250
374
  });
251
375
  }
252
376
  export {
253
- W as WorkerClient,
254
- T as queryEvents
377
+ WorkerClient,
378
+ queryEvents
255
379
  };