@bquery/bquery 1.8.2 → 1.9.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 (75) hide show
  1. package/README.md +96 -24
  2. package/dist/{a11y-DVBCy09c.js → a11y-_9X-kt-_.js} +2 -2
  3. package/dist/{a11y-DVBCy09c.js.map → a11y-_9X-kt-_.js.map} +1 -1
  4. package/dist/a11y.es.mjs +1 -1
  5. package/dist/{forms-UcRHsYxC.js → forms-UhAeJEoO.js} +13 -13
  6. package/dist/{forms-UcRHsYxC.js.map → forms-UhAeJEoO.js.map} +1 -1
  7. package/dist/forms.es.mjs +1 -1
  8. package/dist/full.d.ts +4 -4
  9. package/dist/full.d.ts.map +1 -1
  10. package/dist/full.es.mjs +201 -196
  11. package/dist/full.iife.js +20 -20
  12. package/dist/full.iife.js.map +1 -1
  13. package/dist/full.umd.js +20 -20
  14. package/dist/full.umd.js.map +1 -1
  15. package/dist/index.es.mjs +214 -209
  16. package/dist/media/index.d.ts +10 -3
  17. package/dist/media/index.d.ts.map +1 -1
  18. package/dist/media/observers.d.ts +99 -0
  19. package/dist/media/observers.d.ts.map +1 -0
  20. package/dist/media/types.d.ts +125 -0
  21. package/dist/media/types.d.ts.map +1 -1
  22. package/dist/media-D4zLj9t-.js +514 -0
  23. package/dist/media-D4zLj9t-.js.map +1 -0
  24. package/dist/media.es.mjs +12 -9
  25. package/dist/mount-B-JvH6Y0.js +449 -0
  26. package/dist/mount-B-JvH6Y0.js.map +1 -0
  27. package/dist/reactive/index.d.ts +2 -2
  28. package/dist/reactive/index.d.ts.map +1 -1
  29. package/dist/reactive/signal.d.ts +2 -1
  30. package/dist/reactive/signal.d.ts.map +1 -1
  31. package/dist/reactive/watch.d.ts +49 -0
  32. package/dist/reactive/watch.d.ts.map +1 -1
  33. package/dist/reactive-BjpLkclt.js +1184 -0
  34. package/dist/{reactive-DwkhUJfP.js.map → reactive-BjpLkclt.js.map} +1 -1
  35. package/dist/reactive.es.mjs +35 -33
  36. package/dist/{router-CQikC9Ed.js → router-BieVwgci.js} +2 -2
  37. package/dist/{router-CQikC9Ed.js.map → router-BieVwgci.js.map} +1 -1
  38. package/dist/router.es.mjs +1 -1
  39. package/dist/{ssr-_dAcGdzu.js → ssr-CrGSJySz.js} +3 -3
  40. package/dist/{ssr-_dAcGdzu.js.map → ssr-CrGSJySz.js.map} +1 -1
  41. package/dist/ssr.es.mjs +1 -1
  42. package/dist/{store-Cb3gPRve.js → store-CY6sjTW3.js} +2 -2
  43. package/dist/{store-Cb3gPRve.js.map → store-CY6sjTW3.js.map} +1 -1
  44. package/dist/store.es.mjs +1 -1
  45. package/dist/{testing-C5Sjfsna.js → testing-UjAtu9aQ.js} +9 -9
  46. package/dist/{testing-C5Sjfsna.js.map → testing-UjAtu9aQ.js.map} +1 -1
  47. package/dist/testing.es.mjs +1 -1
  48. package/dist/view/directives/aria.d.ts +7 -0
  49. package/dist/view/directives/aria.d.ts.map +1 -0
  50. package/dist/view/directives/error.d.ts +7 -0
  51. package/dist/view/directives/error.d.ts.map +1 -0
  52. package/dist/view/directives/index.d.ts +2 -0
  53. package/dist/view/directives/index.d.ts.map +1 -1
  54. package/dist/view/mount.d.ts.map +1 -1
  55. package/dist/view/process.d.ts +2 -0
  56. package/dist/view/process.d.ts.map +1 -1
  57. package/dist/view.es.mjs +2 -2
  58. package/package.json +5 -5
  59. package/src/full.ts +12 -0
  60. package/src/media/index.ts +20 -2
  61. package/src/media/observers.ts +421 -0
  62. package/src/media/types.ts +136 -0
  63. package/src/reactive/index.ts +3 -0
  64. package/src/reactive/signal.ts +2 -1
  65. package/src/reactive/watch.ts +137 -0
  66. package/src/view/directives/aria.ts +72 -0
  67. package/src/view/directives/error.ts +56 -0
  68. package/src/view/directives/index.ts +2 -0
  69. package/src/view/mount.ts +4 -0
  70. package/src/view/process.ts +6 -0
  71. package/dist/media-i-fB5WxI.js +0 -340
  72. package/dist/media-i-fB5WxI.js.map +0 -1
  73. package/dist/mount-B4Y8bk8Z.js +0 -403
  74. package/dist/mount-B4Y8bk8Z.js.map +0 -1
  75. package/dist/reactive-DwkhUJfP.js +0 -1148
@@ -1,1148 +0,0 @@
1
- import { a as K, r as he } from "./object-BCk-1c8T.js";
2
- import { d as pe, l as ye, n as C, r as z, t as Y } from "./core-DdtZHzsS.js";
3
- import { n as X } from "./config-DhT9auRm.js";
4
- import { n as Z, r as q, t as W } from "./untrack-D0fnO5k2.js";
5
- var et = (e) => {
6
- ye();
7
- try {
8
- e();
9
- } finally {
10
- pe();
11
- }
12
- }, Ee = (e) => {
13
- if (e instanceof Error) return e;
14
- if (typeof e == "string") return new Error(e);
15
- try {
16
- return new Error(JSON.stringify(e));
17
- } catch {
18
- return new Error(String(e));
19
- }
20
- }, ge = (e) => typeof e == "function" ? e() : e.value, ee = (...e) => {
21
- const t = new Headers();
22
- for (const n of e)
23
- n && new Headers(n).forEach((r, o) => {
24
- t.set(o, r);
25
- });
26
- return t;
27
- }, we = (e) => typeof e == "string" || e instanceof Blob || e instanceof FormData || e instanceof URLSearchParams || typeof ArrayBuffer < "u" && e instanceof ArrayBuffer || typeof ReadableStream < "u" && e instanceof ReadableStream ? !0 : typeof e == "object" && e !== null && ArrayBuffer.isView(e), be = (e, t) => e == null || we(e) ? e : (t.has("content-type") || t.set("content-type", "application/json"), JSON.stringify(e)), Se = (e) => typeof e == "function" ? e() : e, Re = (e, t) => {
28
- for (const [n, r] of Object.entries(t))
29
- if (r != null) {
30
- if (Array.isArray(r)) {
31
- for (const o of r) o != null && e.searchParams.append(n, String(o));
32
- continue;
33
- }
34
- e.searchParams.set(n, String(r));
35
- }
36
- }, Te = (e, t) => {
37
- const n = typeof window < "u" && /^https?:/i.test(window.location.href) ? window.location.href : "http://localhost", r = t ? new URL(t, n).toString() : n;
38
- return e instanceof URL ? new URL(e.toString(), r) : new URL(e, r);
39
- }, Oe = async (e, t) => {
40
- if (t === "response") return e;
41
- if (t === "text") return await e.text();
42
- if (t === "blob") return await e.blob();
43
- if (t === "arrayBuffer") return await e.arrayBuffer();
44
- if (t === "formData") return await e.formData();
45
- const n = await e.text();
46
- if (n)
47
- try {
48
- return JSON.parse(n);
49
- } catch (r) {
50
- const o = e.url ? ` for ${e.url}` : "";
51
- throw new Error(`Failed to parse JSON response${o} (status ${e.status}): ${r instanceof Error ? r.message : String(r)}`);
52
- }
53
- }, V = (e) => {
54
- const t = e?.trim();
55
- return t ? t.toUpperCase() : void 0;
56
- }, xe = (e, t, n) => {
57
- const r = t instanceof Request ? V(t.method) : void 0;
58
- return e ?? r ?? (n ? "POST" : void 0);
59
- }, Ce = (e, t, n) => e || (t instanceof Request ? void 0 : n), Le = (e) => {
60
- const t = V(e.method);
61
- let n;
62
- if (t !== "GET" && t !== "HEAD" && !e.bodyUsed) try {
63
- n = e.clone().body ?? void 0;
64
- } catch {
65
- n = void 0;
66
- }
67
- return {
68
- method: t,
69
- headers: e.headers,
70
- body: n,
71
- cache: e.cache,
72
- credentials: e.credentials,
73
- integrity: e.integrity,
74
- keepalive: e.keepalive,
75
- mode: e.mode,
76
- redirect: e.redirect,
77
- referrer: e.referrer,
78
- referrerPolicy: e.referrerPolicy,
79
- signal: e.signal
80
- };
81
- }, Ae = (e, t = {}) => {
82
- const n = t.immediate ?? !0, r = C(t.defaultValue), o = C(null), u = C("idle"), a = q(() => u.value === "pending");
83
- let s = 0, m = !1, l = () => {
84
- };
85
- const c = () => {
86
- s += 1, r.value = t.defaultValue, o.value = null, u.value = "idle";
87
- }, h = () => {
88
- m || (m = !0, s += 1, l());
89
- }, i = async () => {
90
- if (m) return r.peek();
91
- const E = ++s;
92
- u.value = "pending", o.value = null;
93
- try {
94
- const p = await e(), w = t.transform ? t.transform(p) : p;
95
- return m || E !== s ? r.peek() : (r.value = w, u.value = "success", t.onSuccess?.(w), w);
96
- } catch (p) {
97
- const w = Ee(p);
98
- return m || E !== s || (o.value = w, u.value = "error", t.onError?.(w)), r.peek();
99
- }
100
- };
101
- if (t.watch?.length) {
102
- let E = !1;
103
- l = z(() => {
104
- for (const p of t.watch ?? []) ge(p);
105
- if (!E) {
106
- E = !0, n && W(() => i());
107
- return;
108
- }
109
- W(() => i());
110
- });
111
- } else n && i();
112
- return {
113
- data: r,
114
- error: o,
115
- status: u,
116
- pending: a,
117
- execute: i,
118
- refresh: i,
119
- abort: () => {
120
- },
121
- clear: c,
122
- dispose: h
123
- };
124
- }, ke = (e) => e >= 200 && e < 300, te = (e, t) => e instanceof DOMException && e.name === t, B = (e) => te(e, "TimeoutError"), re = (e) => te(e, "AbortError"), De = (e) => {
125
- if (re(e) || B(e) || e.code === "ABORT" || e.code === "TIMEOUT") return !1;
126
- const t = e.status;
127
- return t === void 0 || t >= 500;
128
- }, Pe = (e) => {
129
- if (e != null)
130
- return typeof e == "number" ? { count: e } : e;
131
- }, Ie = (e, t) => e == null ? Math.min(1e3 * 2 ** t, 3e4) : typeof e == "number" ? e : e(t), qe = (e, t) => new Promise((n, r) => {
132
- if (t?.aborted) {
133
- r(t.reason ?? new DOMException("The operation was aborted.", "AbortError"));
134
- return;
135
- }
136
- let o = !1, u;
137
- const a = () => {
138
- o || (o = !0, clearTimeout(u), t?.removeEventListener("abort", a), r(t?.reason ?? new DOMException("The operation was aborted.", "AbortError")));
139
- };
140
- u = setTimeout(() => {
141
- o || (o = !0, t?.removeEventListener("abort", a), n());
142
- }, e), t?.addEventListener("abort", a, { once: !0 });
143
- }), N = (e, t = {}) => {
144
- const n = X().fetch, r = t.parseAs ?? n?.parseAs ?? "json", o = t.fetcher ?? fetch, u = t.validateStatus ?? ke;
145
- let a = null;
146
- const s = (l, c) => {
147
- const h = c || B(l) || B(a?.signal.reason);
148
- return Object.assign(/* @__PURE__ */ new Error(h ? `Request timeout of ${t.timeout}ms exceeded` : "Request aborted"), { code: h ? "TIMEOUT" : "ABORT" });
149
- }, m = Ae(async () => {
150
- const l = Se(e), c = typeof l == "string" || l instanceof URL ? Te(l, t.baseUrl ?? n?.baseUrl) : l instanceof Request && t.query ? new URL(l.url) : null;
151
- c && t.query && Re(c, t.query);
152
- const h = ee(n?.headers, l instanceof Request ? l.headers : void 0, t.headers), i = t.body != null, E = V(t.method), p = xe(E, l, i), w = p === "GET" || p === "HEAD" ? p : null;
153
- if (i && w) throw new Error(`Cannot send a request body with ${w} requests`);
154
- const R = Ce(E, l, p), b = Pe(t.retry), d = (b?.count ?? 0) + 1, v = new AbortController();
155
- a = v;
156
- let f, y = !1, g;
157
- t.signal && (t.signal.aborted ? v.abort(t.signal.reason) : (g = () => v.abort(t.signal?.reason), t.signal.addEventListener("abort", g, { once: !0 }))), t.timeout && t.timeout > 0 && (f = setTimeout(() => {
158
- y = !0, v.abort(new DOMException("Request timeout", "TimeoutError"));
159
- }, t.timeout));
160
- const S = {
161
- ...t,
162
- method: R,
163
- headers: h
164
- };
165
- delete S.baseUrl, delete S.query, delete S.parseAs, delete S.fetcher, delete S.defaultValue, delete S.immediate, delete S.watch, delete S.transform, delete S.onSuccess, delete S.onError, delete S.timeout, delete S.retry, delete S.validateStatus;
166
- let O = c ?? l;
167
- l instanceof Request && c && c.toString() !== l.url && (O = new Request(c.toString(), Le(l)));
168
- const L = () => {
169
- const x = new Headers(h);
170
- return {
171
- ...S,
172
- headers: x,
173
- body: be(t.body, x),
174
- signal: v.signal
175
- };
176
- };
177
- if (d > 1 && typeof ReadableStream < "u" && t.body instanceof ReadableStream) throw new Error("Cannot retry requests with ReadableStream bodies");
178
- if (d > 1 && typeof Request < "u" && O instanceof Request && O.body !== null) throw new Error("Cannot retry requests with non-replayable Request bodies");
179
- let k;
180
- try {
181
- for (let x = 0; x < d; x++) try {
182
- const A = await o(O, L());
183
- if (!u(A.status)) throw Object.assign(/* @__PURE__ */ new Error(`Request failed with status ${A.status}`), {
184
- response: A,
185
- status: A.status,
186
- statusText: A.statusText
187
- });
188
- return await Oe(A, r);
189
- } catch (A) {
190
- const D = A instanceof Error ? A : new Error(String(A));
191
- if (v.signal.aborted || re(D) || B(D)) throw s(v.signal.aborted ? v.signal.reason : D, y);
192
- if (k = D, !(b && (b.retryOn ?? De)(D, x)) || x >= d - 1) throw D;
193
- await qe(Ie(b.delay, x), v.signal);
194
- }
195
- throw k;
196
- } finally {
197
- f !== void 0 && clearTimeout(f), t.signal && g && t.signal.removeEventListener("abort", g), a === v && (a = null);
198
- }
199
- }, t);
200
- return m.abort = () => {
201
- a && a.abort(new DOMException("Request aborted", "AbortError"));
202
- }, m;
203
- };
204
- function tt(e = {}) {
205
- return (t, n = {}) => {
206
- const r = e, o = K({}, r.query ?? {}, n.query ?? {});
207
- return N(t, {
208
- ...r,
209
- ...n,
210
- headers: ee(r.headers, n.headers),
211
- query: Object.keys(o).length > 0 ? o : void 0
212
- });
213
- };
214
- }
215
- var U = class extends Error {
216
- constructor(e, t, n, r) {
217
- super(e), this.name = "HttpError", this.config = t, this.code = n, this.response = r;
218
- }
219
- };
220
- function Q() {
221
- const e = [];
222
- let t = 0;
223
- return {
224
- use(n, r) {
225
- const o = t++;
226
- return e.push({
227
- id: o,
228
- fulfilled: n,
229
- rejected: r
230
- }), o;
231
- },
232
- eject(n) {
233
- const r = e.findIndex((o) => o?.id === n);
234
- r !== -1 && (e[r] = null);
235
- },
236
- clear() {
237
- e.length = 0;
238
- },
239
- forEach(n) {
240
- for (const r of e) r && n(r);
241
- }
242
- };
243
- }
244
- var Ne = (e) => e >= 200 && e < 300, Ue = (e) => {
245
- if (e.code === "PARSE") return !1;
246
- if (e.code === "TIMEOUT" || e.code === "NETWORK") return !0;
247
- const t = e.response?.status;
248
- return t !== void 0 && t >= 500;
249
- }, Me = (e) => {
250
- if (e != null)
251
- return typeof e == "number" ? { count: e } : e;
252
- }, $e = (e, t) => e == null ? Math.min(1e3 * 2 ** t, 3e4) : typeof e == "number" ? e : e(t), _e = (e, t) => new Promise((n, r) => {
253
- if (t?.aborted) {
254
- r(t.reason ?? new DOMException("The operation was aborted.", "AbortError"));
255
- return;
256
- }
257
- let o;
258
- const u = () => {
259
- clearTimeout(o), t?.removeEventListener("abort", u), r(t?.reason ?? new DOMException("The operation was aborted.", "AbortError"));
260
- };
261
- o = setTimeout(() => {
262
- t?.removeEventListener("abort", u), n();
263
- }, e), t && t.addEventListener("abort", u, { once: !0 });
264
- }), ne = (...e) => {
265
- const t = new Headers();
266
- for (const n of e)
267
- n && new Headers(n).forEach((r, o) => {
268
- t.set(o, r);
269
- });
270
- return t;
271
- }, Be = (e) => typeof e == "string" || e instanceof Blob || e instanceof FormData || e instanceof URLSearchParams || typeof ArrayBuffer < "u" && e instanceof ArrayBuffer || typeof ReadableStream < "u" && e instanceof ReadableStream ? !0 : typeof e == "object" && e !== null && ArrayBuffer.isView(e), ze = (e, t) => e == null || Be(e) ? e : (t.has("content-type") || t.set("content-type", "application/json"), JSON.stringify(e)), He = (e, t) => {
272
- for (const [n, r] of Object.entries(t))
273
- if (r != null) {
274
- if (Array.isArray(r)) {
275
- for (const o of r) o != null && e.searchParams.append(n, String(o));
276
- continue;
277
- }
278
- e.searchParams.set(n, String(r));
279
- }
280
- }, je = (e, t) => {
281
- const n = typeof window < "u" && /^https?:/i.test(window.location.href) ? window.location.href : "http://localhost", r = t ? new URL(t, n).toString() : n;
282
- return new URL(e, r);
283
- }, We = async (e, t, n) => {
284
- if (t === "response") return e;
285
- if (t === "text") return await e.text();
286
- if (t === "blob") return await e.blob();
287
- if (t === "arrayBuffer") return await e.arrayBuffer();
288
- if (t === "formData") return await e.formData();
289
- const r = await e.text();
290
- if (r)
291
- try {
292
- return JSON.parse(r);
293
- } catch (o) {
294
- throw new U(`Failed to parse JSON response${e.url ? ` for ${e.url}` : ""} (status ${e.status}): ${o instanceof Error ? o.message : String(o)}`, n, "PARSE", {
295
- data: r,
296
- status: e.status,
297
- statusText: e.statusText,
298
- headers: e.headers,
299
- config: n
300
- });
301
- }
302
- }, Ve = (e, t) => {
303
- const n = e.body;
304
- if (!n) return e;
305
- const r = parseInt(e.headers.get("content-length") ?? "0", 10) || 0;
306
- let o = 0;
307
- const u = n.getReader(), a = new ReadableStream({
308
- async pull(s) {
309
- const { done: m, value: l } = await u.read();
310
- if (m) {
311
- s.close();
312
- return;
313
- }
314
- o += l.byteLength, t({
315
- loaded: o,
316
- total: r,
317
- percent: r > 0 ? Math.round(o / r * 100) : void 0
318
- }), s.enqueue(l);
319
- },
320
- cancel(s) {
321
- u.cancel(s);
322
- }
323
- });
324
- return new Response(a, {
325
- status: e.status,
326
- statusText: e.statusText,
327
- headers: e.headers
328
- });
329
- }, Fe = async (e) => {
330
- const t = X().fetch, n = e.parseAs ?? t?.parseAs ?? "json", r = e.fetcher ?? fetch, o = e.validateStatus ?? Ne, u = je(e.url ?? "/", e.baseUrl ?? t?.baseUrl);
331
- e.query && He(u, e.query);
332
- const a = ne(t?.headers, e.headers), s = ze(e.body, a), m = {};
333
- e.method && (m.method = e.method.toUpperCase()), m.headers = a, s != null && (m.body = s), e.cache && (m.cache = e.cache), e.credentials && (m.credentials = e.credentials), e.integrity && (m.integrity = e.integrity), e.keepalive !== void 0 && (m.keepalive = e.keepalive), e.mode && (m.mode = e.mode), e.redirect && (m.redirect = e.redirect), e.referrer && (m.referrer = e.referrer), e.referrerPolicy && (m.referrerPolicy = e.referrerPolicy);
334
- let l, c = e.signal, h;
335
- if (e.timeout && e.timeout > 0) {
336
- const i = new AbortController();
337
- e.signal && (h = () => i.abort(e.signal?.reason), e.signal.addEventListener("abort", h, { once: !0 })), l = setTimeout(() => {
338
- i.abort(new DOMException("Request timeout", "TimeoutError"));
339
- }, e.timeout), c = i.signal;
340
- }
341
- c && (m.signal = c);
342
- try {
343
- let i = await r(u.toString(), m);
344
- if (e.onDownloadProgress && (i = Ve(i, e.onDownloadProgress)), !o(i.status)) throw new U(`Request failed with status ${i.status}`, e, "ERR_BAD_RESPONSE", {
345
- data: void 0,
346
- status: i.status,
347
- statusText: i.statusText,
348
- headers: i.headers,
349
- config: e
350
- });
351
- return {
352
- data: await We(i, n, e),
353
- status: i.status,
354
- statusText: i.statusText,
355
- headers: i.headers,
356
- config: e
357
- };
358
- } catch (i) {
359
- if (i instanceof U) throw i;
360
- if (i instanceof DOMException && (i.name === "AbortError" || i.name === "TimeoutError")) {
361
- const E = i.name === "TimeoutError" || i.message === "Request timeout";
362
- throw new U(E ? `Request timeout of ${e.timeout}ms exceeded` : "Request aborted", e, E ? "TIMEOUT" : "ABORT");
363
- }
364
- throw new U(i instanceof Error ? i.message : String(i), e, "NETWORK");
365
- } finally {
366
- l !== void 0 && clearTimeout(l), e.signal && h && e.signal.removeEventListener("abort", h);
367
- }
368
- };
369
- function ae(e = {}) {
370
- const t = Q(), n = Q(), r = (a) => {
371
- const s = K({}, e.query ?? {}, a.query ?? {});
372
- return {
373
- ...e,
374
- ...a,
375
- headers: ne(e.headers, a.headers),
376
- query: Object.keys(s).length > 0 ? s : void 0
377
- };
378
- }, o = async (a) => {
379
- let s = a;
380
- const m = [];
381
- t.forEach((i) => m.push(i));
382
- for (const { fulfilled: i, rejected: E } of m) try {
383
- i && (s = await i(s));
384
- } catch (p) {
385
- if (E) {
386
- const w = await E(p);
387
- if (he(w)) s = w;
388
- else throw p;
389
- } else throw p;
390
- }
391
- const l = Me(s.retry);
392
- let c;
393
- const h = (l?.count ?? 0) + 1;
394
- for (let i = 0; i < h; i++) try {
395
- let E = await Fe(s);
396
- const p = [];
397
- n.forEach((w) => p.push(w));
398
- for (const { fulfilled: w, rejected: R } of p) try {
399
- w && (E = await w(E));
400
- } catch (b) {
401
- if (R) {
402
- const d = await R(b);
403
- if (d && typeof d == "object" && "data" in d) E = d;
404
- else throw b;
405
- } else throw b;
406
- }
407
- return E;
408
- } catch (E) {
409
- const p = E instanceof U ? E : new U(E instanceof Error ? E.message : String(E), s, "NETWORK");
410
- if (c = p, !(l && (l.retryOn ?? Ue)(p, i)) || i >= h - 1) {
411
- const R = [];
412
- n.forEach((d) => R.push(d));
413
- let b = p;
414
- for (const { rejected: d } of R) if (d) try {
415
- const v = await d(b);
416
- if (v && typeof v == "object" && "data" in v) return v;
417
- v != null && (b = v);
418
- } catch (v) {
419
- v != null && (b = v);
420
- }
421
- throw b instanceof Error || (b = p), b;
422
- }
423
- const w = l ? $e(l.delay, i) : 0;
424
- l?.onRetry?.(p, i + 1), await _e(w, s.signal);
425
- }
426
- throw c;
427
- }, u = (a) => o(r(a));
428
- return {
429
- request: u,
430
- get: (a, s = {}) => u({
431
- ...s,
432
- url: a,
433
- method: "GET"
434
- }),
435
- post: (a, s, m = {}) => u({
436
- ...m,
437
- url: a,
438
- method: "POST",
439
- body: s
440
- }),
441
- put: (a, s, m = {}) => u({
442
- ...m,
443
- url: a,
444
- method: "PUT",
445
- body: s
446
- }),
447
- patch: (a, s, m = {}) => u({
448
- ...m,
449
- url: a,
450
- method: "PATCH",
451
- body: s
452
- }),
453
- delete: (a, s = {}) => u({
454
- ...s,
455
- url: a,
456
- method: "DELETE"
457
- }),
458
- head: (a, s = {}) => u({
459
- ...s,
460
- url: a,
461
- method: "HEAD"
462
- }),
463
- options: (a, s = {}) => u({
464
- ...s,
465
- url: a,
466
- method: "OPTIONS"
467
- }),
468
- interceptors: {
469
- request: t,
470
- response: n
471
- },
472
- defaults: e
473
- };
474
- }
475
- var rt = ae();
476
- function nt(e = {}) {
477
- const { concurrency: t = 6 } = e;
478
- if (!Number.isInteger(t) || t < 1) throw new Error("Request queue concurrency must be a positive integer");
479
- const n = [];
480
- let r = 0;
481
- const o = () => {
482
- for (; r < t && n.length > 0; ) {
483
- const u = n.shift();
484
- r++, Promise.resolve().then(u.execute).then(u.resolve, u.reject).finally(() => {
485
- r--, o();
486
- });
487
- }
488
- };
489
- return {
490
- add(u) {
491
- return new Promise((a, s) => {
492
- n.push({
493
- execute: u,
494
- resolve: a,
495
- reject: s
496
- }), o();
497
- });
498
- },
499
- get pending() {
500
- return r;
501
- },
502
- get size() {
503
- return n.length;
504
- },
505
- clear() {
506
- const u = n.splice(0);
507
- for (const a of u) a.reject(/* @__PURE__ */ new Error("Request queue cleared"));
508
- }
509
- };
510
- }
511
- var at = (e, t) => {
512
- const n = q(e);
513
- return {
514
- get value() {
515
- return n.value;
516
- },
517
- set value(r) {
518
- t(r);
519
- },
520
- peek() {
521
- return n.peek();
522
- }
523
- };
524
- }, st = (e, t = {}) => {
525
- const { initialPage: n = 1, ...r } = t, o = C(n), u = N(() => e(o.value), {
526
- ...r,
527
- watch: r.watch
528
- });
529
- return {
530
- ...u,
531
- page: o,
532
- next: async () => (o.value = o.peek() + 1, u.execute()),
533
- prev: async () => {
534
- const l = o.peek();
535
- return l > 1 && (o.value = l - 1), u.execute();
536
- },
537
- goTo: async (l) => (o.value = Math.max(1, l), u.execute())
538
- };
539
- }, ot = (e, t) => {
540
- const { getNextCursor: n, transform: r, initialCursor: o, immediate: u = !0, onSuccess: a, onError: s, ...m } = t, l = C([]), c = C(t.defaultValue), h = C(null), i = C("idle"), E = q(() => i.value === "pending"), p = C(o), w = q(() => l.value.length === 0 || p.value !== void 0);
541
- let R = !1, b = 0;
542
- const d = (S) => r ? r(S) : S, v = async () => {
543
- if (R) return c.peek();
544
- const S = ++b;
545
- i.value = "pending", h.value = null;
546
- try {
547
- const O = N(e(p.peek()), {
548
- ...m,
549
- immediate: !1,
550
- watch: void 0
551
- }), L = await O.execute(), k = O.error.peek();
552
- if (O.dispose(), R || S !== b) return c.peek();
553
- if (k)
554
- return h.value = k, i.value = "error", s?.(k), c.peek();
555
- if (L !== void 0) {
556
- const x = L, A = [...l.peek(), x];
557
- l.value = A, p.value = n(x, A);
558
- const D = d(A);
559
- return c.value = D, i.value = "success", a?.(D), D;
560
- }
561
- return i.value = "success", c.peek();
562
- } catch (O) {
563
- if (R || S !== b) return c.peek();
564
- const L = O instanceof Error ? O : new Error(String(O));
565
- return h.value = L, i.value = "error", s?.(L), c.peek();
566
- }
567
- }, f = async () => (l.value = [], p.value = o, c.value = t.defaultValue, h.value = null, i.value = "idle", b += 1, v()), y = () => {
568
- b += 1, l.value = [], p.value = o, c.value = t.defaultValue, h.value = null, i.value = "idle";
569
- }, g = () => {
570
- R || (R = !0, b += 1);
571
- };
572
- return u && v(), {
573
- data: c,
574
- pages: l,
575
- error: h,
576
- status: i,
577
- pending: E,
578
- hasMore: w,
579
- fetchNextPage: v,
580
- refresh: f,
581
- clear: y,
582
- dispose: g
583
- };
584
- }, it = (e, t) => {
585
- let n = !1, r = null;
586
- try {
587
- if (r = globalThis.localStorage, r) {
588
- const a = `__bquery_test_${Math.random().toString(36).slice(2, 9)}__`, s = "__test__";
589
- try {
590
- r.setItem(a, s), r.getItem(a), n = !0;
591
- } finally {
592
- try {
593
- r.removeItem(a);
594
- } catch {
595
- }
596
- }
597
- }
598
- } catch {
599
- n = !1;
600
- }
601
- let o = t;
602
- if (n && r) try {
603
- const a = r.getItem(e);
604
- a !== null && (o = JSON.parse(a));
605
- } catch {
606
- }
607
- const u = C(o);
608
- return n && r && z(() => {
609
- try {
610
- r.setItem(e, JSON.stringify(u.value));
611
- } catch {
612
- }
613
- }), u;
614
- }, ut = (e, t) => {
615
- const { interval: n, enabled: r = !0, pauseOnHidden: o = !0, pauseOnOffline: u = !0, immediate: a = !0, ...s } = t;
616
- if (!Number.isFinite(n) || n < 1) throw new Error("Polling interval must be a finite number of at least 1");
617
- const m = C(!1), l = C(!1), c = C(!1), h = typeof r == "function" ? r : () => r, i = q(() => h() && !m.value && !(o && l.value) && !(u && c.value)), E = N(e, {
618
- ...s,
619
- immediate: a && h()
620
- });
621
- let p, w = [];
622
- const R = () => {
623
- b(), p = setInterval(() => {
624
- E.execute();
625
- }, n);
626
- }, b = () => {
627
- p !== void 0 && (clearInterval(p), p = void 0);
628
- }, d = z(() => {
629
- const y = i.value;
630
- W(() => {
631
- y ? R() : b();
632
- });
633
- });
634
- if (o && typeof document < "u") {
635
- l.value = document.hidden;
636
- const y = () => {
637
- l.value = document.hidden;
638
- };
639
- document.addEventListener("visibilitychange", y), w.push(() => document.removeEventListener("visibilitychange", y));
640
- }
641
- if (u && typeof window < "u") {
642
- const y = () => {
643
- c.value = !1;
644
- }, g = () => {
645
- c.value = !0;
646
- };
647
- window.addEventListener("online", y), window.addEventListener("offline", g), w.push(() => {
648
- window.removeEventListener("online", y), window.removeEventListener("offline", g);
649
- }), c.value = typeof navigator < "u" && navigator.onLine !== void 0 ? !navigator.onLine : !1;
650
- }
651
- const v = E.dispose;
652
- return {
653
- ...E,
654
- pause: () => {
655
- m.value = !0;
656
- },
657
- resume: () => {
658
- m.value = !1;
659
- },
660
- isActive: i,
661
- dispose: () => {
662
- b(), d();
663
- for (const y of w) y();
664
- w = [], v();
665
- }
666
- };
667
- }, se = /* @__PURE__ */ Symbol("bquery.readonlySignal"), Je = (e) => typeof e == "object" && e !== null && Object.prototype.hasOwnProperty.call(e, se), ct = (e) => Object.defineProperties({}, {
668
- value: {
669
- get() {
670
- return e.value;
671
- },
672
- enumerable: !0
673
- },
674
- peek: {
675
- value() {
676
- return e.peek();
677
- },
678
- enumerable: !0
679
- },
680
- [se]: {
681
- value: !0,
682
- enumerable: !1,
683
- configurable: !1,
684
- writable: !1
685
- }
686
- }), lt = (e, t = {}) => {
687
- const { optimistic: n = !1, onMutationSuccess: r, onMutationError: o, ...u } = t, a = N(e, { ...u }), s = C(!1), m = q(() => s.value);
688
- let l = !1;
689
- const c = () => {
690
- const R = typeof e == "function" ? e() : e;
691
- return R instanceof URL ? R.toString() : R;
692
- }, h = () => {
693
- const { defaultValue: R, transform: b, onSuccess: d, onError: v, ...f } = u;
694
- return f;
695
- }, i = async (R, b, d, v) => {
696
- if (l) return a.data.peek();
697
- const f = a.data.peek();
698
- n && v !== void 0 && (a.data.value = v), s.value = !0, a.error.value = null;
699
- try {
700
- const y = N(c(), {
701
- ...h(),
702
- method: b,
703
- body: d ?? void 0,
704
- immediate: !1,
705
- watch: void 0
706
- }), g = await y.execute(), S = y.error.peek();
707
- return y.dispose(), l ? a.data.peek() : S ? (n && v !== void 0 && (a.data.value = f), a.error.value = S, a.status.value = "error", s.value = !1, o?.(S, R), a.data.peek()) : (b !== "DELETE" && g !== void 0 && (a.data.value = g), s.value = !1, a.status.value = "success", r?.(g, R), g);
708
- } catch (y) {
709
- if (l) return a.data.peek();
710
- n && v !== void 0 && (a.data.value = f);
711
- const g = y instanceof Error ? y : new Error(String(y));
712
- return a.error.value = g, a.status.value = "error", s.value = !1, o?.(g, R), a.data.peek();
713
- }
714
- }, E = {
715
- fetch: () => a.execute(),
716
- create: (R) => i("create", "POST", R),
717
- update: (R) => {
718
- const b = a.data.peek();
719
- return i("update", "PUT", R, n && b !== void 0 ? {
720
- ...b,
721
- ...R
722
- } : void 0);
723
- },
724
- patch: (R) => {
725
- const b = a.data.peek();
726
- return i("patch", "PATCH", R, n && b !== void 0 ? {
727
- ...b,
728
- ...R
729
- } : void 0);
730
- },
731
- remove: async () => {
732
- await i("remove", "DELETE"), !l && a.error.peek() == null && (a.data.value = void 0);
733
- }
734
- }, p = a.dispose, w = () => {
735
- l || (l = !0, p());
736
- };
737
- return {
738
- data: a.data,
739
- error: a.error,
740
- status: a.status,
741
- pending: a.pending,
742
- isMutating: m,
743
- actions: E,
744
- refresh: a.execute,
745
- clear: a.clear,
746
- dispose: w
747
- };
748
- }, dt = (e, t = {}) => {
749
- const { method: n = "POST", ...r } = t, o = C(void 0), u = C(null), a = C("idle"), s = q(() => a.value === "pending");
750
- return {
751
- data: o,
752
- error: u,
753
- status: a,
754
- pending: s,
755
- submit: async (c) => {
756
- a.value = "pending", u.value = null;
757
- try {
758
- const h = N(e, {
759
- ...r,
760
- method: n,
761
- body: c,
762
- immediate: !1,
763
- watch: void 0
764
- }), i = await h.execute(), E = h.error.peek();
765
- if (h.dispose(), E) {
766
- u.value = E, a.value = "error";
767
- return;
768
- }
769
- return o.value = i, a.value = "success", i;
770
- } catch (h) {
771
- u.value = h instanceof Error ? h : new Error(String(h)), a.value = "error";
772
- return;
773
- }
774
- },
775
- clear: () => {
776
- o.value = void 0, u.value = null, a.value = "idle";
777
- }
778
- };
779
- }, ft = (e, t = {}) => {
780
- const n = ae({ ...t });
781
- let r = e;
782
- for (; r.endsWith("/"); ) r = r.slice(0, -1);
783
- return {
784
- list: (o) => n.get(r, o),
785
- get: (o, u) => n.get(`${r}/${encodeURIComponent(String(o))}`, u),
786
- create: (o, u) => n.post(r, o, u),
787
- update: (o, u, a) => n.put(`${r}/${encodeURIComponent(String(o))}`, u, a),
788
- patch: (o, u, a) => n.patch(`${r}/${encodeURIComponent(String(o))}`, u, a),
789
- remove: (o, u) => n.delete(`${r}/${encodeURIComponent(String(o))}`, u),
790
- http: n
791
- };
792
- }, vt = (e, t = {}) => {
793
- const { getId: n = (d) => d.id, optimistic: r = !1, onMutationSuccess: o, onMutationError: u, ...a } = t, s = N(e, { ...a }), m = C(!1), l = q(() => m.value);
794
- let c = !1;
795
- const h = () => {
796
- const d = typeof e == "function" ? e() : e;
797
- return d instanceof URL ? d.toString() : d;
798
- }, i = () => {
799
- let d = h();
800
- for (; d.endsWith("/"); ) d = d.slice(0, -1);
801
- return d;
802
- }, E = () => {
803
- const { defaultValue: d, transform: v, onSuccess: f, onError: y, ...g } = a;
804
- return g;
805
- }, p = async (d, v, f, y, g, S) => {
806
- if (!c) {
807
- r && g && g(), m.value = !0, s.error.value = null;
808
- try {
809
- const O = N(`${i()}${f}`, {
810
- ...E(),
811
- method: v,
812
- body: y ?? void 0,
813
- immediate: !1,
814
- watch: void 0
815
- }), L = await O.execute(), k = O.error.peek();
816
- if (O.dispose(), c) return;
817
- if (k) {
818
- r && S && S(), s.error.value = k, s.status.value = "error", m.value = !1, u?.(k, d);
819
- return;
820
- }
821
- return m.value = !1, s.status.value = "success", o?.(d), L;
822
- } catch (O) {
823
- if (c) return;
824
- r && S && S();
825
- const L = O instanceof Error ? O : new Error(String(O));
826
- s.error.value = L, s.status.value = "error", m.value = !1, u?.(L, d);
827
- return;
828
- }
829
- }
830
- }, w = {
831
- fetch: () => s.execute(),
832
- add: async (d) => {
833
- const v = s.data.peek(), f = d, y = v?.length ?? 0, g = await p("add", "POST", "", d, r ? () => {
834
- s.data.value = [...v ?? [], f];
835
- } : void 0, r ? () => {
836
- s.data.value = v;
837
- } : void 0);
838
- if (g !== void 0 && !c) {
839
- const S = s.data.peek() ?? [];
840
- if (r) {
841
- const O = [...S];
842
- y < O.length && O[y] === f ? O[y] = g : O.push(g), s.data.value = O;
843
- } else s.data.value = [...S, g];
844
- }
845
- return g;
846
- },
847
- update: async (d, v) => {
848
- const f = s.data.peek(), y = await p("update", "PUT", `/${encodeURIComponent(String(d))}`, v, r && f ? () => {
849
- s.data.value = f.map((g) => n(g) === d ? {
850
- ...g,
851
- ...v
852
- } : g);
853
- } : void 0, r ? () => {
854
- s.data.value = f;
855
- } : void 0);
856
- if (y !== void 0 && !c) {
857
- const g = s.data.peek() ?? [];
858
- s.data.value = g.map((S) => n(S) === d ? y : S);
859
- }
860
- return y;
861
- },
862
- patch: async (d, v) => {
863
- const f = s.data.peek(), y = await p("patch", "PATCH", `/${encodeURIComponent(String(d))}`, v, r && f ? () => {
864
- s.data.value = f.map((g) => n(g) === d ? {
865
- ...g,
866
- ...v
867
- } : g);
868
- } : void 0, r ? () => {
869
- s.data.value = f;
870
- } : void 0);
871
- if (y !== void 0 && !c) {
872
- const g = s.data.peek() ?? [];
873
- s.data.value = g.map((S) => n(S) === d ? y : S);
874
- }
875
- return y;
876
- },
877
- remove: async (d) => {
878
- const v = s.data.peek();
879
- if (await p("remove", "DELETE", `/${encodeURIComponent(String(d))}`, void 0, r && v ? () => {
880
- s.data.value = v.filter((f) => n(f) !== d);
881
- } : void 0, r ? () => {
882
- s.data.value = v;
883
- } : void 0), !r && !c && s.error.peek() == null) {
884
- const f = s.data.peek() ?? [];
885
- s.data.value = f.filter((y) => n(y) !== d);
886
- }
887
- }
888
- }, R = s.dispose, b = () => {
889
- c || (c = !0, R());
890
- };
891
- return {
892
- data: s.data,
893
- error: s.error,
894
- status: s.status,
895
- pending: s.pending,
896
- isMutating: l,
897
- actions: w,
898
- refresh: s.execute,
899
- clear: s.clear,
900
- dispose: b
901
- };
902
- }, j = /* @__PURE__ */ new Map();
903
- function mt(e, t) {
904
- const n = j.get(e);
905
- if (n) return n;
906
- const r = t().finally(() => {
907
- j.delete(e);
908
- });
909
- return j.set(e, r), r;
910
- }
911
- var ht = (e) => e instanceof Y, pt = (e) => e instanceof Z, yt = (e) => e instanceof Y || e instanceof Z || Je(e) ? e.value : e, Et = (e, t, n = {}) => {
912
- const { immediate: r = !1, equals: o = Object.is } = n;
913
- let u, a = !0;
914
- return z(() => {
915
- const s = e.value;
916
- if (a) {
917
- a = !1, u = s, r && t(s, void 0);
918
- return;
919
- }
920
- o(s, u) || (t(s, u), u = s);
921
- });
922
- };
923
- function oe(e) {
924
- return e === !1 ? !1 : e === !0 || e === void 0 ? {} : e;
925
- }
926
- var Ge = (e) => e ? e === !0 ? {} : e : !1, ie = (e, t) => {
927
- const n = t.delay ?? 1e3, r = t.factor ?? 2, o = t.maxDelay ?? 3e4;
928
- return Math.min(n * r ** e, o);
929
- }, Qe = (e, t = {}) => {
930
- const { protocols: n, immediate: r = !0, historySize: o = 0, onOpen: u, onMessage: a, onClose: s, onError: m, onReconnect: l } = t, c = t.serialize ?? ((T) => JSON.stringify(T)), h = t.deserialize ?? ((T) => {
931
- const P = T.data;
932
- if (typeof P == "string") try {
933
- return JSON.parse(P);
934
- } catch {
935
- return P;
936
- }
937
- return P;
938
- }), i = C("CLOSED"), E = C(void 0), p = C(null), w = C([]), R = C(0), b = C(0), d = C(0), v = q(() => i.value === "OPEN");
939
- let f = null, y = !1, g = !1, S, O, L, k = 0, x = !1, A = 0;
940
- const D = [], $ = oe(t.autoReconnect), M = Ge(t.heartbeat), ue = () => {
941
- if (!M) return;
942
- _();
943
- const T = M.interval ?? 3e4, P = M.pongTimeout ?? 1e4, I = M.message ?? "ping";
944
- O = setInterval(() => {
945
- f?.readyState === WebSocket.OPEN && (A = Date.now(), f.send(I), L !== void 0 && clearTimeout(L), L = setTimeout(() => {
946
- f?.close(4e3, "Heartbeat timeout");
947
- }, P));
948
- }, T);
949
- }, _ = () => {
950
- O !== void 0 && (clearInterval(O), O = void 0), L !== void 0 && (clearTimeout(L), L = void 0);
951
- }, ce = () => {
952
- L !== void 0 && (clearTimeout(L), L = void 0), A > 0 && (b.value = Date.now() - A, A = 0);
953
- }, le = (T) => {
954
- if (y || g || !$) return;
955
- const P = $.maxAttempts ?? 1 / 0;
956
- if (k >= P || $.shouldReconnect && !$.shouldReconnect(T, k)) return;
957
- const I = ie(k, $);
958
- S = setTimeout(() => {
959
- k++, R.value = k, x = !0, H();
960
- }, I);
961
- }, F = () => {
962
- S !== void 0 && (clearTimeout(S), S = void 0);
963
- }, de = () => {
964
- if (!f || f.readyState !== WebSocket.OPEN) return;
965
- let T = 0;
966
- for (; T < D.length && f.readyState === WebSocket.OPEN; T++)
967
- f.send(D[T]);
968
- T > 0 && D.splice(0, T);
969
- }, fe = () => {
970
- const T = typeof e == "function" ? e() : e;
971
- return T instanceof URL ? T.toString() : T;
972
- }, H = () => {
973
- if (!y) {
974
- F(), f && (_(), A = 0, f.onopen = null, f.onmessage = null, f.onclose = null, f.onerror = null, (f.readyState === WebSocket.OPEN || f.readyState === WebSocket.CONNECTING) && f.close(), f = null), g = !1, i.value = "CONNECTING", p.value = null;
975
- try {
976
- f = new WebSocket(fe(), n);
977
- } catch {
978
- i.value = "CLOSED";
979
- return;
980
- }
981
- f.onopen = (T) => {
982
- i.value = "OPEN";
983
- const P = x, I = k;
984
- k = 0, R.value = 0, x = !1, de(), ue(), u?.(T), P && l?.(I);
985
- }, f.onmessage = (T) => {
986
- if (M) {
987
- const I = M.responseMessage;
988
- (I === void 0 || T.data === I) && ce();
989
- }
990
- const P = h(T);
991
- if (E.value = P, o > 0) {
992
- const I = [...w.peek(), P];
993
- w.value = I.length > o ? I.slice(-o) : I;
994
- }
995
- a?.(P, T);
996
- }, f.onclose = (T) => {
997
- i.value = "CLOSED", _(), g || (d.value = Date.now()), s?.(T), !g && !y && le(T);
998
- }, f.onerror = (T) => {
999
- p.value = T, m?.(T);
1000
- };
1001
- }
1002
- }, J = (T, P) => {
1003
- g = !0, F(), _(), f && (f.readyState === WebSocket.OPEN || f.readyState === WebSocket.CONNECTING) && (i.value = "CLOSING", f.close(T, P));
1004
- }, ve = (T) => {
1005
- y || G(c(T));
1006
- }, G = (T) => {
1007
- y || (f?.readyState === WebSocket.OPEN ? f.send(T) : D.push(T));
1008
- }, me = () => {
1009
- y || (y = !0, J(), D.length = 0, f = null);
1010
- };
1011
- return r && H(), {
1012
- status: i,
1013
- data: E,
1014
- error: p,
1015
- history: w,
1016
- isConnected: v,
1017
- reconnectAttempts: R,
1018
- latency: b,
1019
- lastDisconnectedAt: d,
1020
- send: ve,
1021
- sendRaw: G,
1022
- open: H,
1023
- close: J,
1024
- dispose: me
1025
- };
1026
- }, gt = (e, t = {}, n = {}) => {
1027
- const r = n.getChannel ?? ((c) => c.channel), o = n.wrap ?? ((c, h) => ({
1028
- channel: c,
1029
- data: h
1030
- })), u = /* @__PURE__ */ new Map(), a = /* @__PURE__ */ new Map(), s = Qe(e, {
1031
- ...t,
1032
- onMessage: (c, h) => {
1033
- const i = r(c);
1034
- if (i !== void 0) {
1035
- const E = u.get(i);
1036
- E && (E.value = c);
1037
- }
1038
- t.onMessage?.(c, h);
1039
- }
1040
- });
1041
- return {
1042
- subscribe: (c) => {
1043
- let h = u.get(c);
1044
- h || (h = C(void 0), u.set(c, h)), a.set(c, (a.get(c) ?? 0) + 1);
1045
- let i = !1;
1046
- return {
1047
- data: h,
1048
- unsubscribe: () => {
1049
- if (i) return;
1050
- i = !0;
1051
- const E = (a.get(c) ?? 1) - 1;
1052
- E <= 0 ? (a.delete(c), u.delete(c)) : a.set(c, E);
1053
- }
1054
- };
1055
- },
1056
- publish: (c, h) => {
1057
- s.send(o(c, h));
1058
- },
1059
- ws: s
1060
- };
1061
- }, wt = (e, t = {}) => {
1062
- const { immediate: n = !0, events: r = [], eventSourceInit: o, onOpen: u, onMessage: a, onError: s } = t, m = t.deserialize ?? ((x) => {
1063
- try {
1064
- return JSON.parse(x);
1065
- } catch {
1066
- return x;
1067
- }
1068
- }), l = C("CLOSED"), c = C(void 0), h = C(void 0), i = C(null), E = q(() => l.value === "OPEN"), p = oe(t.autoReconnect);
1069
- let w = null, R = !1, b = !1, d, v = 0;
1070
- const f = () => {
1071
- const x = typeof e == "function" ? e() : e;
1072
- return x instanceof URL ? x.toString() : x;
1073
- }, y = (x) => (A) => {
1074
- const D = m(A.data);
1075
- c.value = D, h.value = x, a?.(D, A);
1076
- }, g = () => {
1077
- d !== void 0 && (clearTimeout(d), d = void 0);
1078
- }, S = () => {
1079
- if (R || b || !p) return;
1080
- const x = p.maxAttempts ?? 1 / 0;
1081
- if (v >= x) return;
1082
- const A = ie(v, p);
1083
- d = setTimeout(() => {
1084
- v++, O();
1085
- }, A);
1086
- }, O = () => {
1087
- if (!R) {
1088
- g(), w && (w.close(), w = null), b = !1, l.value = "CONNECTING", i.value = null;
1089
- try {
1090
- w = new EventSource(f(), o);
1091
- } catch {
1092
- l.value = "CLOSED";
1093
- return;
1094
- }
1095
- w.onopen = (x) => {
1096
- l.value = "OPEN", v = 0, u?.(x);
1097
- }, w.onerror = (x) => {
1098
- i.value = x, s?.(x), w?.readyState === EventSource.CLOSED && (l.value = "CLOSED", !b && !R && S());
1099
- }, w.addEventListener("message", y("message"));
1100
- for (const x of r) w.addEventListener(x, y(x));
1101
- }
1102
- }, L = () => {
1103
- b = !0, g(), w && (w.close(), w = null), l.value = "CLOSED";
1104
- }, k = () => {
1105
- R || (R = !0, L());
1106
- };
1107
- return n && O(), {
1108
- status: l,
1109
- data: c,
1110
- eventName: h,
1111
- error: i,
1112
- isConnected: E,
1113
- open: O,
1114
- close: L,
1115
- dispose: k
1116
- };
1117
- };
1118
- export {
1119
- rt as C,
1120
- et as D,
1121
- N as E,
1122
- nt as S,
1123
- Ae as T,
1124
- ot as _,
1125
- yt as a,
1126
- U as b,
1127
- ft as c,
1128
- vt as d,
1129
- dt as f,
1130
- it as g,
1131
- ut as h,
1132
- Et as i,
1133
- mt as l,
1134
- ct as m,
1135
- Qe as n,
1136
- pt as o,
1137
- Je as p,
1138
- gt as r,
1139
- ht as s,
1140
- wt as t,
1141
- lt as u,
1142
- st as v,
1143
- tt as w,
1144
- ae as x,
1145
- at as y
1146
- };
1147
-
1148
- //# sourceMappingURL=reactive-DwkhUJfP.js.map