@leancodepl/react-query-cqrs-client 9.7.2 → 9.7.4

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/index.js ADDED
@@ -0,0 +1,2470 @@
1
+ import * as R from "react";
2
+ import "react/jsx-runtime";
3
+ var ne = class {
4
+ constructor() {
5
+ this.listeners = /* @__PURE__ */ new Set(), this.subscribe = this.subscribe.bind(this);
6
+ }
7
+ subscribe(e) {
8
+ return this.listeners.add(e), this.onSubscribe(), () => {
9
+ this.listeners.delete(e), this.onUnsubscribe();
10
+ };
11
+ }
12
+ hasListeners() {
13
+ return this.listeners.size > 0;
14
+ }
15
+ onSubscribe() {
16
+ }
17
+ onUnsubscribe() {
18
+ }
19
+ }, Et = {
20
+ // We need the wrapper function syntax below instead of direct references to
21
+ // global setTimeout etc.
22
+ //
23
+ // BAD: `setTimeout: setTimeout`
24
+ // GOOD: `setTimeout: (cb, delay) => setTimeout(cb, delay)`
25
+ //
26
+ // If we use direct references here, then anything that wants to spy on or
27
+ // replace the global setTimeout (like tests) won't work since we'll already
28
+ // have a hard reference to the original implementation at the time when this
29
+ // file was imported.
30
+ setTimeout: (e, t) => setTimeout(e, t),
31
+ clearTimeout: (e) => clearTimeout(e),
32
+ setInterval: (e, t) => setInterval(e, t),
33
+ clearInterval: (e) => clearInterval(e)
34
+ }, St = class {
35
+ // We cannot have TimeoutManager<T> as we must instantiate it with a concrete
36
+ // type at app boot; and if we leave that type, then any new timer provider
37
+ // would need to support ReturnType<typeof setTimeout>, which is infeasible.
38
+ //
39
+ // We settle for type safety for the TimeoutProvider type, and accept that
40
+ // this class is unsafe internally to allow for extension.
41
+ #t = Et;
42
+ #e = !1;
43
+ setTimeoutProvider(e) {
44
+ process.env.NODE_ENV !== "production" && this.#e && e !== this.#t && console.error(
45
+ "[timeoutManager]: Switching provider after calls to previous provider might result in unexpected behavior.",
46
+ { previous: this.#t, provider: e }
47
+ ), this.#t = e, process.env.NODE_ENV !== "production" && (this.#e = !1);
48
+ }
49
+ setTimeout(e, t) {
50
+ return process.env.NODE_ENV !== "production" && (this.#e = !0), this.#t.setTimeout(e, t);
51
+ }
52
+ clearTimeout(e) {
53
+ this.#t.clearTimeout(e);
54
+ }
55
+ setInterval(e, t) {
56
+ return process.env.NODE_ENV !== "production" && (this.#e = !0), this.#t.setInterval(e, t);
57
+ }
58
+ clearInterval(e) {
59
+ this.#t.clearInterval(e);
60
+ }
61
+ }, X = new St();
62
+ function Ot(e) {
63
+ setTimeout(e, 0);
64
+ }
65
+ var V = typeof window > "u" || "Deno" in globalThis;
66
+ function Y() {
67
+ }
68
+ function ke(e) {
69
+ return typeof e == "number" && e >= 0 && e !== 1 / 0;
70
+ }
71
+ function Pt(e, t) {
72
+ return Math.max(e + (t || 0) - Date.now(), 0);
73
+ }
74
+ function B(e, t) {
75
+ return typeof e == "function" ? e(t) : e;
76
+ }
77
+ function F(e, t) {
78
+ return typeof e == "function" ? e(t) : e;
79
+ }
80
+ function Ce(e) {
81
+ return JSON.stringify(
82
+ e,
83
+ (t, r) => fe(r) ? Object.keys(r).sort().reduce((n, i) => (n[i] = r[i], n), {}) : r
84
+ );
85
+ }
86
+ var Rt = Object.prototype.hasOwnProperty;
87
+ function le(e, t) {
88
+ if (e === t)
89
+ return e;
90
+ const r = je(e) && je(t);
91
+ if (!r && !(fe(e) && fe(t))) return t;
92
+ const i = (r ? e : Object.keys(e)).length, s = r ? t : Object.keys(t), a = s.length, l = r ? new Array(a) : {};
93
+ let o = 0;
94
+ for (let c = 0; c < a; c++) {
95
+ const u = r ? c : s[c], f = e[u], h = t[u];
96
+ if (f === h) {
97
+ l[u] = f, (r ? c < i : Rt.call(e, u)) && o++;
98
+ continue;
99
+ }
100
+ if (f === null || h === null || typeof f != "object" || typeof h != "object") {
101
+ l[u] = h;
102
+ continue;
103
+ }
104
+ const d = le(f, h);
105
+ l[u] = d, d === f && o++;
106
+ }
107
+ return i === a && o === i ? e : l;
108
+ }
109
+ function Z(e, t) {
110
+ if (!t || Object.keys(e).length !== Object.keys(t).length)
111
+ return !1;
112
+ for (const r in e)
113
+ if (e[r] !== t[r])
114
+ return !1;
115
+ return !0;
116
+ }
117
+ function je(e) {
118
+ return Array.isArray(e) && e.length === Object.keys(e).length;
119
+ }
120
+ function fe(e) {
121
+ if (!Le(e))
122
+ return !1;
123
+ const t = e.constructor;
124
+ if (t === void 0)
125
+ return !0;
126
+ const r = t.prototype;
127
+ return !(!Le(r) || !r.hasOwnProperty("isPrototypeOf") || Object.getPrototypeOf(e) !== Object.prototype);
128
+ }
129
+ function Le(e) {
130
+ return Object.prototype.toString.call(e) === "[object Object]";
131
+ }
132
+ function Me(e, t, r) {
133
+ if (typeof r.structuralSharing == "function")
134
+ return r.structuralSharing(e, t);
135
+ if (r.structuralSharing !== !1) {
136
+ if (process.env.NODE_ENV !== "production")
137
+ try {
138
+ return le(e, t);
139
+ } catch (n) {
140
+ throw console.error(
141
+ `Structural sharing requires data to be JSON serializable. To fix this, turn off structuralSharing or return JSON-serializable data from your queryFn. [${r.queryHash}]: ${n}`
142
+ ), n;
143
+ }
144
+ return le(e, t);
145
+ }
146
+ return t;
147
+ }
148
+ function Tt(e, t, r = 0) {
149
+ const n = [...e, t];
150
+ return r && n.length > r ? n.slice(1) : n;
151
+ }
152
+ function xt(e, t, r = 0) {
153
+ const n = [t, ...e];
154
+ return r && n.length > r ? n.slice(0, -1) : n;
155
+ }
156
+ var Qe = /* @__PURE__ */ Symbol();
157
+ function It(e, t) {
158
+ return process.env.NODE_ENV !== "production" && e.queryFn === Qe && console.error(
159
+ `Attempted to invoke queryFn when set to skipToken. This is likely a configuration error. Query hash: '${e.queryHash}'`
160
+ ), !e.queryFn && t?.initialPromise ? () => t.initialPromise : !e.queryFn || e.queryFn === Qe ? () => Promise.reject(new Error(`Missing queryFn: '${e.queryHash}'`)) : e.queryFn;
161
+ }
162
+ function Xe(e, t) {
163
+ return typeof e == "function" ? e(...t) : !!e;
164
+ }
165
+ var At = class extends ne {
166
+ #t;
167
+ #e;
168
+ #r;
169
+ constructor() {
170
+ super(), this.#r = (e) => {
171
+ if (!V && window.addEventListener) {
172
+ const t = () => e();
173
+ return window.addEventListener("visibilitychange", t, !1), () => {
174
+ window.removeEventListener("visibilitychange", t);
175
+ };
176
+ }
177
+ };
178
+ }
179
+ onSubscribe() {
180
+ this.#e || this.setEventListener(this.#r);
181
+ }
182
+ onUnsubscribe() {
183
+ this.hasListeners() || (this.#e?.(), this.#e = void 0);
184
+ }
185
+ setEventListener(e) {
186
+ this.#r = e, this.#e?.(), this.#e = e((t) => {
187
+ typeof t == "boolean" ? this.setFocused(t) : this.onFocus();
188
+ });
189
+ }
190
+ setFocused(e) {
191
+ this.#t !== e && (this.#t = e, this.onFocus());
192
+ }
193
+ onFocus() {
194
+ const e = this.isFocused();
195
+ this.listeners.forEach((t) => {
196
+ t(e);
197
+ });
198
+ }
199
+ isFocused() {
200
+ return typeof this.#t == "boolean" ? this.#t : globalThis.document?.visibilityState !== "hidden";
201
+ }
202
+ }, Ft = new At();
203
+ function De() {
204
+ let e, t;
205
+ const r = new Promise((i, s) => {
206
+ e = i, t = s;
207
+ });
208
+ r.status = "pending", r.catch(() => {
209
+ });
210
+ function n(i) {
211
+ Object.assign(r, i), delete r.resolve, delete r.reject;
212
+ }
213
+ return r.resolve = (i) => {
214
+ n({
215
+ status: "fulfilled",
216
+ value: i
217
+ }), e(i);
218
+ }, r.reject = (i) => {
219
+ n({
220
+ status: "rejected",
221
+ reason: i
222
+ }), t(i);
223
+ }, r;
224
+ }
225
+ var kt = Ot;
226
+ function Ct() {
227
+ let e = [], t = 0, r = (l) => {
228
+ l();
229
+ }, n = (l) => {
230
+ l();
231
+ }, i = kt;
232
+ const s = (l) => {
233
+ t ? e.push(l) : i(() => {
234
+ r(l);
235
+ });
236
+ }, a = () => {
237
+ const l = e;
238
+ e = [], l.length && i(() => {
239
+ n(() => {
240
+ l.forEach((o) => {
241
+ r(o);
242
+ });
243
+ });
244
+ });
245
+ };
246
+ return {
247
+ batch: (l) => {
248
+ let o;
249
+ t++;
250
+ try {
251
+ o = l();
252
+ } finally {
253
+ t--, t || a();
254
+ }
255
+ return o;
256
+ },
257
+ /**
258
+ * All calls to the wrapped function will be batched.
259
+ */
260
+ batchCalls: (l) => (...o) => {
261
+ s(() => {
262
+ l(...o);
263
+ });
264
+ },
265
+ schedule: s,
266
+ /**
267
+ * Use this method to set a custom notify function.
268
+ * This can be used to for example wrap notifications with `React.act` while running tests.
269
+ */
270
+ setNotifyFunction: (l) => {
271
+ r = l;
272
+ },
273
+ /**
274
+ * Use this method to set a custom function to batch notifications together into a single tick.
275
+ * By default React Query will use the batch function provided by ReactDOM or React Native.
276
+ */
277
+ setBatchNotifyFunction: (l) => {
278
+ n = l;
279
+ },
280
+ setScheduler: (l) => {
281
+ i = l;
282
+ }
283
+ };
284
+ }
285
+ var ie = Ct(), jt = class extends ne {
286
+ #t = !0;
287
+ #e;
288
+ #r;
289
+ constructor() {
290
+ super(), this.#r = (e) => {
291
+ if (!V && window.addEventListener) {
292
+ const t = () => e(!0), r = () => e(!1);
293
+ return window.addEventListener("online", t, !1), window.addEventListener("offline", r, !1), () => {
294
+ window.removeEventListener("online", t), window.removeEventListener("offline", r);
295
+ };
296
+ }
297
+ };
298
+ }
299
+ onSubscribe() {
300
+ this.#e || this.setEventListener(this.#r);
301
+ }
302
+ onUnsubscribe() {
303
+ this.hasListeners() || (this.#e?.(), this.#e = void 0);
304
+ }
305
+ setEventListener(e) {
306
+ this.#r = e, this.#e?.(), this.#e = e(this.setOnline.bind(this));
307
+ }
308
+ setOnline(e) {
309
+ this.#t !== e && (this.#t = e, this.listeners.forEach((r) => {
310
+ r(e);
311
+ }));
312
+ }
313
+ isOnline() {
314
+ return this.#t;
315
+ }
316
+ }, Lt = new jt();
317
+ function Mt(e) {
318
+ return (e ?? "online") === "online" ? Lt.isOnline() : !0;
319
+ }
320
+ function Qt(e, t) {
321
+ return {
322
+ fetchFailureCount: 0,
323
+ fetchFailureReason: null,
324
+ fetchStatus: Mt(t.networkMode) ? "fetching" : "paused",
325
+ ...e === void 0 && {
326
+ error: null,
327
+ status: "pending"
328
+ }
329
+ };
330
+ }
331
+ var We = class extends ne {
332
+ constructor(e, t) {
333
+ super(), this.options = t, this.#t = e, this.#a = null, this.#o = De(), this.bindMethods(), this.setOptions(t);
334
+ }
335
+ #t;
336
+ #e = void 0;
337
+ #r = void 0;
338
+ #n = void 0;
339
+ #i;
340
+ #s;
341
+ #o;
342
+ #a;
343
+ #v;
344
+ #h;
345
+ // This property keeps track of the last query with defined data.
346
+ // It will be used to pass the previous data and query to the placeholder function between renders.
347
+ #d;
348
+ #c;
349
+ #l;
350
+ #u;
351
+ #p = /* @__PURE__ */ new Set();
352
+ bindMethods() {
353
+ this.refetch = this.refetch.bind(this);
354
+ }
355
+ onSubscribe() {
356
+ this.listeners.size === 1 && (this.#e.addObserver(this), Ne(this.#e, this.options) ? this.#f() : this.updateResult(), this.#g());
357
+ }
358
+ onUnsubscribe() {
359
+ this.hasListeners() || this.destroy();
360
+ }
361
+ shouldFetchOnReconnect() {
362
+ return he(
363
+ this.#e,
364
+ this.options,
365
+ this.options.refetchOnReconnect
366
+ );
367
+ }
368
+ shouldFetchOnWindowFocus() {
369
+ return he(
370
+ this.#e,
371
+ this.options,
372
+ this.options.refetchOnWindowFocus
373
+ );
374
+ }
375
+ destroy() {
376
+ this.listeners = /* @__PURE__ */ new Set(), this.#w(), this.#E(), this.#e.removeObserver(this);
377
+ }
378
+ setOptions(e) {
379
+ const t = this.options, r = this.#e;
380
+ if (this.options = this.#t.defaultQueryOptions(e), this.options.enabled !== void 0 && typeof this.options.enabled != "boolean" && typeof this.options.enabled != "function" && typeof F(this.options.enabled, this.#e) != "boolean")
381
+ throw new Error(
382
+ "Expected enabled to be a boolean or a callback that returns a boolean"
383
+ );
384
+ this.#S(), this.#e.setOptions(this.options), t._defaulted && !Z(this.options, t) && this.#t.getQueryCache().notify({
385
+ type: "observerOptionsUpdated",
386
+ query: this.#e,
387
+ observer: this
388
+ });
389
+ const n = this.hasListeners();
390
+ n && Ue(
391
+ this.#e,
392
+ r,
393
+ this.options,
394
+ t
395
+ ) && this.#f(), this.updateResult(), n && (this.#e !== r || F(this.options.enabled, this.#e) !== F(t.enabled, this.#e) || B(this.options.staleTime, this.#e) !== B(t.staleTime, this.#e)) && this.#y();
396
+ const i = this.#m();
397
+ n && (this.#e !== r || F(this.options.enabled, this.#e) !== F(t.enabled, this.#e) || i !== this.#u) && this.#b(i);
398
+ }
399
+ getOptimisticResult(e) {
400
+ const t = this.#t.getQueryCache().build(this.#t, e), r = this.createResult(t, e);
401
+ return Nt(this, r) && (this.#n = r, this.#s = this.options, this.#i = this.#e.state), r;
402
+ }
403
+ getCurrentResult() {
404
+ return this.#n;
405
+ }
406
+ trackResult(e, t) {
407
+ return new Proxy(e, {
408
+ get: (r, n) => (this.trackProp(n), t?.(n), n === "promise" && !this.options.experimental_prefetchInRender && this.#o.status === "pending" && this.#o.reject(
409
+ new Error(
410
+ "experimental_prefetchInRender feature flag is not enabled"
411
+ )
412
+ ), Reflect.get(r, n))
413
+ });
414
+ }
415
+ trackProp(e) {
416
+ this.#p.add(e);
417
+ }
418
+ getCurrentQuery() {
419
+ return this.#e;
420
+ }
421
+ refetch({ ...e } = {}) {
422
+ return this.fetch({
423
+ ...e
424
+ });
425
+ }
426
+ fetchOptimistic(e) {
427
+ const t = this.#t.defaultQueryOptions(e), r = this.#t.getQueryCache().build(this.#t, t);
428
+ return r.fetch().then(() => this.createResult(r, t));
429
+ }
430
+ fetch(e) {
431
+ return this.#f({
432
+ ...e,
433
+ cancelRefetch: e.cancelRefetch ?? !0
434
+ }).then(() => (this.updateResult(), this.#n));
435
+ }
436
+ #f(e) {
437
+ this.#S();
438
+ let t = this.#e.fetch(
439
+ this.options,
440
+ e
441
+ );
442
+ return e?.throwOnError || (t = t.catch(Y)), t;
443
+ }
444
+ #y() {
445
+ this.#w();
446
+ const e = B(
447
+ this.options.staleTime,
448
+ this.#e
449
+ );
450
+ if (V || this.#n.isStale || !ke(e))
451
+ return;
452
+ const r = Pt(this.#n.dataUpdatedAt, e) + 1;
453
+ this.#c = X.setTimeout(() => {
454
+ this.#n.isStale || this.updateResult();
455
+ }, r);
456
+ }
457
+ #m() {
458
+ return (typeof this.options.refetchInterval == "function" ? this.options.refetchInterval(this.#e) : this.options.refetchInterval) ?? !1;
459
+ }
460
+ #b(e) {
461
+ this.#E(), this.#u = e, !(V || F(this.options.enabled, this.#e) === !1 || !ke(this.#u) || this.#u === 0) && (this.#l = X.setInterval(() => {
462
+ (this.options.refetchIntervalInBackground || Ft.isFocused()) && this.#f();
463
+ }, this.#u));
464
+ }
465
+ #g() {
466
+ this.#y(), this.#b(this.#m());
467
+ }
468
+ #w() {
469
+ this.#c && (X.clearTimeout(this.#c), this.#c = void 0);
470
+ }
471
+ #E() {
472
+ this.#l && (X.clearInterval(this.#l), this.#l = void 0);
473
+ }
474
+ createResult(e, t) {
475
+ const r = this.#e, n = this.options, i = this.#n, s = this.#i, a = this.#s, o = e !== r ? e.state : this.#r, { state: c } = e;
476
+ let u = { ...c }, f = !1, h;
477
+ if (t._optimisticResults) {
478
+ const T = this.hasListeners(), _ = !T && Ne(e, t), k = T && Ue(e, r, t, n);
479
+ (_ || k) && (u = {
480
+ ...u,
481
+ ...Qt(c.data, e.options)
482
+ }), t._optimisticResults === "isRestoring" && (u.fetchStatus = "idle");
483
+ }
484
+ let { error: d, errorUpdatedAt: v, status: p } = u;
485
+ h = u.data;
486
+ let S = !1;
487
+ if (t.placeholderData !== void 0 && h === void 0 && p === "pending") {
488
+ let T;
489
+ i?.isPlaceholderData && t.placeholderData === a?.placeholderData ? (T = i.data, S = !0) : T = typeof t.placeholderData == "function" ? t.placeholderData(
490
+ this.#d?.state.data,
491
+ this.#d
492
+ ) : t.placeholderData, T !== void 0 && (p = "success", h = Me(
493
+ i?.data,
494
+ T,
495
+ t
496
+ ), f = !0);
497
+ }
498
+ if (t.select && h !== void 0 && !S)
499
+ if (i && h === s?.data && t.select === this.#v)
500
+ h = this.#h;
501
+ else
502
+ try {
503
+ this.#v = t.select, h = t.select(h), h = Me(i?.data, h, t), this.#h = h, this.#a = null;
504
+ } catch (T) {
505
+ this.#a = T;
506
+ }
507
+ this.#a && (d = this.#a, h = this.#h, v = Date.now(), p = "error");
508
+ const g = u.fetchStatus === "fetching", P = p === "pending", w = p === "error", y = P && g, m = h !== void 0, A = {
509
+ status: p,
510
+ fetchStatus: u.fetchStatus,
511
+ isPending: P,
512
+ isSuccess: p === "success",
513
+ isError: w,
514
+ isInitialLoading: y,
515
+ isLoading: y,
516
+ data: h,
517
+ dataUpdatedAt: u.dataUpdatedAt,
518
+ error: d,
519
+ errorUpdatedAt: v,
520
+ failureCount: u.fetchFailureCount,
521
+ failureReason: u.fetchFailureReason,
522
+ errorUpdateCount: u.errorUpdateCount,
523
+ isFetched: u.dataUpdateCount > 0 || u.errorUpdateCount > 0,
524
+ isFetchedAfterMount: u.dataUpdateCount > o.dataUpdateCount || u.errorUpdateCount > o.errorUpdateCount,
525
+ isFetching: g,
526
+ isRefetching: g && !P,
527
+ isLoadingError: w && !m,
528
+ isPaused: u.fetchStatus === "paused",
529
+ isPlaceholderData: f,
530
+ isRefetchError: w && m,
531
+ isStale: me(e, t),
532
+ refetch: this.refetch,
533
+ promise: this.#o,
534
+ isEnabled: F(t.enabled, e) !== !1
535
+ };
536
+ if (this.options.experimental_prefetchInRender) {
537
+ const T = (L) => {
538
+ A.status === "error" ? L.reject(A.error) : A.data !== void 0 && L.resolve(A.data);
539
+ }, _ = () => {
540
+ const L = this.#o = A.promise = De();
541
+ T(L);
542
+ }, k = this.#o;
543
+ switch (k.status) {
544
+ case "pending":
545
+ e.queryHash === r.queryHash && T(k);
546
+ break;
547
+ case "fulfilled":
548
+ (A.status === "error" || A.data !== k.value) && _();
549
+ break;
550
+ case "rejected":
551
+ (A.status !== "error" || A.error !== k.reason) && _();
552
+ break;
553
+ }
554
+ }
555
+ return A;
556
+ }
557
+ updateResult() {
558
+ const e = this.#n, t = this.createResult(this.#e, this.options);
559
+ if (this.#i = this.#e.state, this.#s = this.options, this.#i.data !== void 0 && (this.#d = this.#e), Z(t, e))
560
+ return;
561
+ this.#n = t;
562
+ const r = () => {
563
+ if (!e)
564
+ return !0;
565
+ const { notifyOnChangeProps: n } = this.options, i = typeof n == "function" ? n() : n;
566
+ if (i === "all" || !i && !this.#p.size)
567
+ return !0;
568
+ const s = new Set(
569
+ i ?? this.#p
570
+ );
571
+ return this.options.throwOnError && s.add("error"), Object.keys(this.#n).some((a) => {
572
+ const l = a;
573
+ return this.#n[l] !== e[l] && s.has(l);
574
+ });
575
+ };
576
+ this.#O({ listeners: r() });
577
+ }
578
+ #S() {
579
+ const e = this.#t.getQueryCache().build(this.#t, this.options);
580
+ if (e === this.#e)
581
+ return;
582
+ const t = this.#e;
583
+ this.#e = e, this.#r = e.state, this.hasListeners() && (t?.removeObserver(this), e.addObserver(this));
584
+ }
585
+ onQueryUpdate() {
586
+ this.updateResult(), this.hasListeners() && this.#g();
587
+ }
588
+ #O(e) {
589
+ ie.batch(() => {
590
+ e.listeners && this.listeners.forEach((t) => {
591
+ t(this.#n);
592
+ }), this.#t.getQueryCache().notify({
593
+ query: this.#e,
594
+ type: "observerResultsUpdated"
595
+ });
596
+ });
597
+ }
598
+ };
599
+ function Dt(e, t) {
600
+ return F(t.enabled, e) !== !1 && e.state.data === void 0 && !(e.state.status === "error" && t.retryOnMount === !1);
601
+ }
602
+ function Ne(e, t) {
603
+ return Dt(e, t) || e.state.data !== void 0 && he(e, t, t.refetchOnMount);
604
+ }
605
+ function he(e, t, r) {
606
+ if (F(t.enabled, e) !== !1 && B(t.staleTime, e) !== "static") {
607
+ const n = typeof r == "function" ? r(e) : r;
608
+ return n === "always" || n !== !1 && me(e, t);
609
+ }
610
+ return !1;
611
+ }
612
+ function Ue(e, t, r, n) {
613
+ return (e !== t || F(n.enabled, e) === !1) && (!r.suspense || e.state.status !== "error") && me(e, r);
614
+ }
615
+ function me(e, t) {
616
+ return F(t.enabled, e) !== !1 && e.isStaleByTime(B(t.staleTime, e));
617
+ }
618
+ function Nt(e, t) {
619
+ return !Z(e.getCurrentResult(), t);
620
+ }
621
+ function _e(e) {
622
+ return {
623
+ onFetch: (t, r) => {
624
+ const n = t.options, i = t.fetchOptions?.meta?.fetchMore?.direction, s = t.state.data?.pages || [], a = t.state.data?.pageParams || [];
625
+ let l = { pages: [], pageParams: [] }, o = 0;
626
+ const c = async () => {
627
+ let u = !1;
628
+ const f = (v) => {
629
+ Object.defineProperty(v, "signal", {
630
+ enumerable: !0,
631
+ get: () => (t.signal.aborted ? u = !0 : t.signal.addEventListener("abort", () => {
632
+ u = !0;
633
+ }), t.signal)
634
+ });
635
+ }, h = It(t.options, t.fetchOptions), d = async (v, p, S) => {
636
+ if (u)
637
+ return Promise.reject();
638
+ if (p == null && v.pages.length)
639
+ return Promise.resolve(v);
640
+ const P = (() => {
641
+ const j = {
642
+ client: t.client,
643
+ queryKey: t.queryKey,
644
+ pageParam: p,
645
+ direction: S ? "backward" : "forward",
646
+ meta: t.options.meta
647
+ };
648
+ return f(j), j;
649
+ })(), w = await h(P), { maxPages: y } = t.options, m = S ? xt : Tt;
650
+ return {
651
+ pages: m(v.pages, w, y),
652
+ pageParams: m(v.pageParams, p, y)
653
+ };
654
+ };
655
+ if (i && s.length) {
656
+ const v = i === "backward", p = v ? Ye : de, S = {
657
+ pages: s,
658
+ pageParams: a
659
+ }, g = p(n, S);
660
+ l = await d(S, g, v);
661
+ } else {
662
+ const v = s.length;
663
+ do {
664
+ const p = o === 0 ? a[0] ?? n.initialPageParam : de(n, l);
665
+ if (o > 0 && p == null)
666
+ break;
667
+ l = await d(l, p), o++;
668
+ } while (o < v);
669
+ }
670
+ return l;
671
+ };
672
+ t.options.persister ? t.fetchFn = () => t.options.persister?.(
673
+ c,
674
+ {
675
+ client: t.client,
676
+ queryKey: t.queryKey,
677
+ meta: t.options.meta,
678
+ signal: t.signal
679
+ },
680
+ r
681
+ ) : t.fetchFn = c;
682
+ }
683
+ };
684
+ }
685
+ function de(e, { pages: t, pageParams: r }) {
686
+ const n = t.length - 1;
687
+ return t.length > 0 ? e.getNextPageParam(
688
+ t[n],
689
+ t,
690
+ r[n],
691
+ r
692
+ ) : void 0;
693
+ }
694
+ function Ye(e, { pages: t, pageParams: r }) {
695
+ return t.length > 0 ? e.getPreviousPageParam?.(t[0], t, r[0], r) : void 0;
696
+ }
697
+ function Ut(e, t) {
698
+ return t ? de(e, t) != null : !1;
699
+ }
700
+ function _t(e, t) {
701
+ return !t || !e.getPreviousPageParam ? !1 : Ye(e, t) != null;
702
+ }
703
+ var qt = class extends We {
704
+ constructor(e, t) {
705
+ super(e, t);
706
+ }
707
+ bindMethods() {
708
+ super.bindMethods(), this.fetchNextPage = this.fetchNextPage.bind(this), this.fetchPreviousPage = this.fetchPreviousPage.bind(this);
709
+ }
710
+ setOptions(e) {
711
+ super.setOptions({
712
+ ...e,
713
+ behavior: _e()
714
+ });
715
+ }
716
+ getOptimisticResult(e) {
717
+ return e.behavior = _e(), super.getOptimisticResult(e);
718
+ }
719
+ fetchNextPage(e) {
720
+ return this.fetch({
721
+ ...e,
722
+ meta: {
723
+ fetchMore: { direction: "forward" }
724
+ }
725
+ });
726
+ }
727
+ fetchPreviousPage(e) {
728
+ return this.fetch({
729
+ ...e,
730
+ meta: {
731
+ fetchMore: { direction: "backward" }
732
+ }
733
+ });
734
+ }
735
+ createResult(e, t) {
736
+ const { state: r } = e, n = super.createResult(e, t), { isFetching: i, isRefetching: s, isError: a, isRefetchError: l } = n, o = r.fetchMeta?.fetchMore?.direction, c = a && o === "forward", u = i && o === "forward", f = a && o === "backward", h = i && o === "backward";
737
+ return {
738
+ ...n,
739
+ fetchNextPage: this.fetchNextPage,
740
+ fetchPreviousPage: this.fetchPreviousPage,
741
+ hasNextPage: Ut(t, r.data),
742
+ hasPreviousPage: _t(t, r.data),
743
+ isFetchNextPageError: c,
744
+ isFetchingNextPage: u,
745
+ isFetchPreviousPageError: f,
746
+ isFetchingPreviousPage: h,
747
+ isRefetchError: l && !c && !f,
748
+ isRefetching: s && !u && !h
749
+ };
750
+ }
751
+ };
752
+ function Ht() {
753
+ return {
754
+ context: void 0,
755
+ data: void 0,
756
+ error: null,
757
+ failureCount: 0,
758
+ failureReason: null,
759
+ isPaused: !1,
760
+ status: "idle",
761
+ variables: void 0,
762
+ submittedAt: 0
763
+ };
764
+ }
765
+ var Bt = class extends ne {
766
+ #t;
767
+ #e = void 0;
768
+ #r;
769
+ #n;
770
+ constructor(e, t) {
771
+ super(), this.#t = e, this.setOptions(t), this.bindMethods(), this.#i();
772
+ }
773
+ bindMethods() {
774
+ this.mutate = this.mutate.bind(this), this.reset = this.reset.bind(this);
775
+ }
776
+ setOptions(e) {
777
+ const t = this.options;
778
+ this.options = this.#t.defaultMutationOptions(e), Z(this.options, t) || this.#t.getMutationCache().notify({
779
+ type: "observerOptionsUpdated",
780
+ mutation: this.#r,
781
+ observer: this
782
+ }), t?.mutationKey && this.options.mutationKey && Ce(t.mutationKey) !== Ce(this.options.mutationKey) ? this.reset() : this.#r?.state.status === "pending" && this.#r.setOptions(this.options);
783
+ }
784
+ onUnsubscribe() {
785
+ this.hasListeners() || this.#r?.removeObserver(this);
786
+ }
787
+ onMutationUpdate(e) {
788
+ this.#i(), this.#s(e);
789
+ }
790
+ getCurrentResult() {
791
+ return this.#e;
792
+ }
793
+ reset() {
794
+ this.#r?.removeObserver(this), this.#r = void 0, this.#i(), this.#s();
795
+ }
796
+ mutate(e, t) {
797
+ return this.#n = t, this.#r?.removeObserver(this), this.#r = this.#t.getMutationCache().build(this.#t, this.options), this.#r.addObserver(this), this.#r.execute(e);
798
+ }
799
+ #i() {
800
+ const e = this.#r?.state ?? Ht();
801
+ this.#e = {
802
+ ...e,
803
+ isPending: e.status === "pending",
804
+ isSuccess: e.status === "success",
805
+ isError: e.status === "error",
806
+ isIdle: e.status === "idle",
807
+ mutate: this.mutate,
808
+ reset: this.reset
809
+ };
810
+ }
811
+ #s(e) {
812
+ ie.batch(() => {
813
+ if (this.#n && this.hasListeners()) {
814
+ const t = this.#e.variables, r = this.#e.context, n = {
815
+ client: this.#t,
816
+ meta: this.options.meta,
817
+ mutationKey: this.options.mutationKey
818
+ };
819
+ e?.type === "success" ? (this.#n.onSuccess?.(
820
+ e.data,
821
+ t,
822
+ r,
823
+ n
824
+ ), this.#n.onSettled?.(
825
+ e.data,
826
+ null,
827
+ t,
828
+ r,
829
+ n
830
+ )) : e?.type === "error" && (this.#n.onError?.(
831
+ e.error,
832
+ t,
833
+ r,
834
+ n
835
+ ), this.#n.onSettled?.(
836
+ void 0,
837
+ e.error,
838
+ t,
839
+ r,
840
+ n
841
+ ));
842
+ }
843
+ this.listeners.forEach((t) => {
844
+ t(this.#e);
845
+ });
846
+ });
847
+ }
848
+ }, Kt = R.createContext(
849
+ void 0
850
+ ), Ze = (e) => {
851
+ const t = R.useContext(Kt);
852
+ if (e)
853
+ return e;
854
+ if (!t)
855
+ throw new Error("No QueryClient set, use QueryClientProvider to set one");
856
+ return t;
857
+ }, et = R.createContext(!1), Vt = () => R.useContext(et);
858
+ et.Provider;
859
+ function $t() {
860
+ let e = !1;
861
+ return {
862
+ clearReset: () => {
863
+ e = !1;
864
+ },
865
+ reset: () => {
866
+ e = !0;
867
+ },
868
+ isReset: () => e
869
+ };
870
+ }
871
+ var zt = R.createContext($t()), Gt = () => R.useContext(zt), Jt = (e, t) => {
872
+ (e.suspense || e.throwOnError || e.experimental_prefetchInRender) && (t.isReset() || (e.retryOnMount = !1));
873
+ }, Xt = (e) => {
874
+ R.useEffect(() => {
875
+ e.clearReset();
876
+ }, [e]);
877
+ }, Wt = ({
878
+ result: e,
879
+ errorResetBoundary: t,
880
+ throwOnError: r,
881
+ query: n,
882
+ suspense: i
883
+ }) => e.isError && !t.isReset() && !e.isFetching && n && (i && e.data === void 0 || Xe(r, [e.error, n])), Yt = (e) => {
884
+ if (e.suspense) {
885
+ const r = (i) => i === "static" ? i : Math.max(i ?? 1e3, 1e3), n = e.staleTime;
886
+ e.staleTime = typeof n == "function" ? (...i) => r(n(...i)) : r(n), typeof e.gcTime == "number" && (e.gcTime = Math.max(
887
+ e.gcTime,
888
+ 1e3
889
+ ));
890
+ }
891
+ }, Zt = (e, t) => e.isLoading && e.isFetching && !t, er = (e, t) => e?.suspense && t.isPending, qe = (e, t, r) => t.fetchOptimistic(e).catch(() => {
892
+ r.clearReset();
893
+ });
894
+ function tt(e, t, r) {
895
+ if (process.env.NODE_ENV !== "production" && (typeof e != "object" || Array.isArray(e)))
896
+ throw new Error(
897
+ 'Bad argument type. Starting with v5, only the "Object" form is allowed when calling query related functions. Please use the error stack to find the culprit call. More info here: https://tanstack.com/query/latest/docs/react/guides/migrating-to-v5#supports-a-single-signature-one-object'
898
+ );
899
+ const n = Vt(), i = Gt(), s = Ze(r), a = s.defaultQueryOptions(e);
900
+ s.getDefaultOptions().queries?._experimental_beforeQuery?.(
901
+ a
902
+ ), process.env.NODE_ENV !== "production" && (a.queryFn || console.error(
903
+ `[${a.queryHash}]: No queryFn was passed as an option, and no default queryFn was found. The queryFn parameter is only optional when using a default queryFn. More info here: https://tanstack.com/query/latest/docs/framework/react/guides/default-query-function`
904
+ )), a._optimisticResults = n ? "isRestoring" : "optimistic", Yt(a), Jt(a, i), Xt(i);
905
+ const l = !s.getQueryCache().get(a.queryHash), [o] = R.useState(
906
+ () => new t(
907
+ s,
908
+ a
909
+ )
910
+ ), c = o.getOptimisticResult(a), u = !n && e.subscribed !== !1;
911
+ if (R.useSyncExternalStore(
912
+ R.useCallback(
913
+ (f) => {
914
+ const h = u ? o.subscribe(ie.batchCalls(f)) : Y;
915
+ return o.updateResult(), h;
916
+ },
917
+ [o, u]
918
+ ),
919
+ () => o.getCurrentResult(),
920
+ () => o.getCurrentResult()
921
+ ), R.useEffect(() => {
922
+ o.setOptions(a);
923
+ }, [a, o]), er(a, c))
924
+ throw qe(a, o, i);
925
+ if (Wt({
926
+ result: c,
927
+ errorResetBoundary: i,
928
+ throwOnError: a.throwOnError,
929
+ query: s.getQueryCache().get(a.queryHash),
930
+ suspense: a.suspense
931
+ }))
932
+ throw c.error;
933
+ return s.getDefaultOptions().queries?._experimental_afterQuery?.(
934
+ a,
935
+ c
936
+ ), a.experimental_prefetchInRender && !V && Zt(c, n) && (l ? (
937
+ // Fetch immediately on render in order to ensure `.promise` is resolved even if the component is unmounted
938
+ qe(a, o, i)
939
+ ) : (
940
+ // subscribe to the "cache promise" so that we can finalize the currentThenable once data comes in
941
+ s.getQueryCache().get(a.queryHash)?.promise
942
+ ))?.catch(Y).finally(() => {
943
+ o.updateResult();
944
+ }), a.notifyOnChangeProps ? c : o.trackResult(c);
945
+ }
946
+ function tr(e, t) {
947
+ return tt(e, We, t);
948
+ }
949
+ function oe(e, t) {
950
+ const r = Ze(t), [n] = R.useState(
951
+ () => new Bt(
952
+ r,
953
+ e
954
+ )
955
+ );
956
+ R.useEffect(() => {
957
+ n.setOptions(e);
958
+ }, [n, e]);
959
+ const i = R.useSyncExternalStore(
960
+ R.useCallback(
961
+ (a) => n.subscribe(ie.batchCalls(a)),
962
+ [n]
963
+ ),
964
+ () => n.getCurrentResult(),
965
+ () => n.getCurrentResult()
966
+ ), s = R.useCallback(
967
+ (a, l) => {
968
+ n.mutate(a, l).catch(Y);
969
+ },
970
+ [n]
971
+ );
972
+ if (i.error && Xe(n.options.throwOnError, [i.error]))
973
+ throw i.error;
974
+ return { ...i, mutate: s, mutateAsync: i.mutate };
975
+ }
976
+ function rr(e, t) {
977
+ return tt(
978
+ e,
979
+ qt,
980
+ t
981
+ );
982
+ }
983
+ var pe = function(e, t) {
984
+ return pe = Object.setPrototypeOf || { __proto__: [] } instanceof Array && function(r, n) {
985
+ r.__proto__ = n;
986
+ } || function(r, n) {
987
+ for (var i in n) Object.prototype.hasOwnProperty.call(n, i) && (r[i] = n[i]);
988
+ }, pe(e, t);
989
+ };
990
+ function be(e, t) {
991
+ if (typeof t != "function" && t !== null)
992
+ throw new TypeError("Class extends value " + String(t) + " is not a constructor or null");
993
+ pe(e, t);
994
+ function r() {
995
+ this.constructor = e;
996
+ }
997
+ e.prototype = t === null ? Object.create(t) : (r.prototype = t.prototype, new r());
998
+ }
999
+ var K = function() {
1000
+ return K = Object.assign || function(t) {
1001
+ for (var r, n = 1, i = arguments.length; n < i; n++) {
1002
+ r = arguments[n];
1003
+ for (var s in r) Object.prototype.hasOwnProperty.call(r, s) && (t[s] = r[s]);
1004
+ }
1005
+ return t;
1006
+ }, K.apply(this, arguments);
1007
+ };
1008
+ function nr(e, t, r, n) {
1009
+ function i(s) {
1010
+ return s instanceof r ? s : new r(function(a) {
1011
+ a(s);
1012
+ });
1013
+ }
1014
+ return new (r || (r = Promise))(function(s, a) {
1015
+ function l(u) {
1016
+ try {
1017
+ c(n.next(u));
1018
+ } catch (f) {
1019
+ a(f);
1020
+ }
1021
+ }
1022
+ function o(u) {
1023
+ try {
1024
+ c(n.throw(u));
1025
+ } catch (f) {
1026
+ a(f);
1027
+ }
1028
+ }
1029
+ function c(u) {
1030
+ u.done ? s(u.value) : i(u.value).then(l, o);
1031
+ }
1032
+ c((n = n.apply(e, t || [])).next());
1033
+ });
1034
+ }
1035
+ function rt(e, t) {
1036
+ var r = { label: 0, sent: function() {
1037
+ if (s[0] & 1) throw s[1];
1038
+ return s[1];
1039
+ }, trys: [], ops: [] }, n, i, s, a = Object.create((typeof Iterator == "function" ? Iterator : Object).prototype);
1040
+ return a.next = l(0), a.throw = l(1), a.return = l(2), typeof Symbol == "function" && (a[Symbol.iterator] = function() {
1041
+ return this;
1042
+ }), a;
1043
+ function l(c) {
1044
+ return function(u) {
1045
+ return o([c, u]);
1046
+ };
1047
+ }
1048
+ function o(c) {
1049
+ if (n) throw new TypeError("Generator is already executing.");
1050
+ for (; a && (a = 0, c[0] && (r = 0)), r; ) try {
1051
+ if (n = 1, i && (s = c[0] & 2 ? i.return : c[0] ? i.throw || ((s = i.return) && s.call(i), 0) : i.next) && !(s = s.call(i, c[1])).done) return s;
1052
+ switch (i = 0, s && (c = [c[0] & 2, s.value]), c[0]) {
1053
+ case 0:
1054
+ case 1:
1055
+ s = c;
1056
+ break;
1057
+ case 4:
1058
+ return r.label++, { value: c[1], done: !1 };
1059
+ case 5:
1060
+ r.label++, i = c[1], c = [0];
1061
+ continue;
1062
+ case 7:
1063
+ c = r.ops.pop(), r.trys.pop();
1064
+ continue;
1065
+ default:
1066
+ if (s = r.trys, !(s = s.length > 0 && s[s.length - 1]) && (c[0] === 6 || c[0] === 2)) {
1067
+ r = 0;
1068
+ continue;
1069
+ }
1070
+ if (c[0] === 3 && (!s || c[1] > s[0] && c[1] < s[3])) {
1071
+ r.label = c[1];
1072
+ break;
1073
+ }
1074
+ if (c[0] === 6 && r.label < s[1]) {
1075
+ r.label = s[1], s = c;
1076
+ break;
1077
+ }
1078
+ if (s && r.label < s[2]) {
1079
+ r.label = s[2], r.ops.push(c);
1080
+ break;
1081
+ }
1082
+ s[2] && r.ops.pop(), r.trys.pop();
1083
+ continue;
1084
+ }
1085
+ c = t.call(e, r);
1086
+ } catch (u) {
1087
+ c = [6, u], i = 0;
1088
+ } finally {
1089
+ n = s = 0;
1090
+ }
1091
+ if (c[0] & 5) throw c[1];
1092
+ return { value: c[0] ? c[1] : void 0, done: !0 };
1093
+ }
1094
+ }
1095
+ function $(e) {
1096
+ var t = typeof Symbol == "function" && Symbol.iterator, r = t && e[t], n = 0;
1097
+ if (r) return r.call(e);
1098
+ if (e && typeof e.length == "number") return {
1099
+ next: function() {
1100
+ return e && n >= e.length && (e = void 0), { value: e && e[n++], done: !e };
1101
+ }
1102
+ };
1103
+ throw new TypeError(t ? "Object is not iterable." : "Symbol.iterator is not defined.");
1104
+ }
1105
+ function z(e, t) {
1106
+ var r = typeof Symbol == "function" && e[Symbol.iterator];
1107
+ if (!r) return e;
1108
+ var n = r.call(e), i, s = [], a;
1109
+ try {
1110
+ for (; (t === void 0 || t-- > 0) && !(i = n.next()).done; ) s.push(i.value);
1111
+ } catch (l) {
1112
+ a = { error: l };
1113
+ } finally {
1114
+ try {
1115
+ i && !i.done && (r = n.return) && r.call(n);
1116
+ } finally {
1117
+ if (a) throw a.error;
1118
+ }
1119
+ }
1120
+ return s;
1121
+ }
1122
+ function ee(e, t, r) {
1123
+ if (r || arguments.length === 2) for (var n = 0, i = t.length, s; n < i; n++)
1124
+ (s || !(n in t)) && (s || (s = Array.prototype.slice.call(t, 0, n)), s[n] = t[n]);
1125
+ return e.concat(s || Array.prototype.slice.call(t));
1126
+ }
1127
+ function q(e) {
1128
+ return this instanceof q ? (this.v = e, this) : new q(e);
1129
+ }
1130
+ function ir(e, t, r) {
1131
+ if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
1132
+ var n = r.apply(e, t || []), i, s = [];
1133
+ return i = Object.create((typeof AsyncIterator == "function" ? AsyncIterator : Object).prototype), l("next"), l("throw"), l("return", a), i[Symbol.asyncIterator] = function() {
1134
+ return this;
1135
+ }, i;
1136
+ function a(d) {
1137
+ return function(v) {
1138
+ return Promise.resolve(v).then(d, f);
1139
+ };
1140
+ }
1141
+ function l(d, v) {
1142
+ n[d] && (i[d] = function(p) {
1143
+ return new Promise(function(S, g) {
1144
+ s.push([d, p, S, g]) > 1 || o(d, p);
1145
+ });
1146
+ }, v && (i[d] = v(i[d])));
1147
+ }
1148
+ function o(d, v) {
1149
+ try {
1150
+ c(n[d](v));
1151
+ } catch (p) {
1152
+ h(s[0][3], p);
1153
+ }
1154
+ }
1155
+ function c(d) {
1156
+ d.value instanceof q ? Promise.resolve(d.value.v).then(u, f) : h(s[0][2], d);
1157
+ }
1158
+ function u(d) {
1159
+ o("next", d);
1160
+ }
1161
+ function f(d) {
1162
+ o("throw", d);
1163
+ }
1164
+ function h(d, v) {
1165
+ d(v), s.shift(), s.length && o(s[0][0], s[0][1]);
1166
+ }
1167
+ }
1168
+ function sr(e) {
1169
+ if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
1170
+ var t = e[Symbol.asyncIterator], r;
1171
+ return t ? t.call(e) : (e = typeof $ == "function" ? $(e) : e[Symbol.iterator](), r = {}, n("next"), n("throw"), n("return"), r[Symbol.asyncIterator] = function() {
1172
+ return this;
1173
+ }, r);
1174
+ function n(s) {
1175
+ r[s] = e[s] && function(a) {
1176
+ return new Promise(function(l, o) {
1177
+ a = e[s](a), i(l, o, a.done, a.value);
1178
+ });
1179
+ };
1180
+ }
1181
+ function i(s, a, l, o) {
1182
+ Promise.resolve(o).then(function(c) {
1183
+ s({ value: c, done: l });
1184
+ }, a);
1185
+ }
1186
+ }
1187
+ function b(e) {
1188
+ return typeof e == "function";
1189
+ }
1190
+ function ge(e) {
1191
+ var t = function(n) {
1192
+ Error.call(n), n.stack = new Error().stack;
1193
+ }, r = e(t);
1194
+ return r.prototype = Object.create(Error.prototype), r.prototype.constructor = r, r;
1195
+ }
1196
+ var ae = ge(function(e) {
1197
+ return function(r) {
1198
+ e(this), this.message = r ? r.length + ` errors occurred during unsubscription:
1199
+ ` + r.map(function(n, i) {
1200
+ return i + 1 + ") " + n.toString();
1201
+ }).join(`
1202
+ `) : "", this.name = "UnsubscriptionError", this.errors = r;
1203
+ };
1204
+ });
1205
+ function He(e, t) {
1206
+ if (e) {
1207
+ var r = e.indexOf(t);
1208
+ 0 <= r && e.splice(r, 1);
1209
+ }
1210
+ }
1211
+ var we = (function() {
1212
+ function e(t) {
1213
+ this.initialTeardown = t, this.closed = !1, this._parentage = null, this._finalizers = null;
1214
+ }
1215
+ return e.prototype.unsubscribe = function() {
1216
+ var t, r, n, i, s;
1217
+ if (!this.closed) {
1218
+ this.closed = !0;
1219
+ var a = this._parentage;
1220
+ if (a)
1221
+ if (this._parentage = null, Array.isArray(a))
1222
+ try {
1223
+ for (var l = $(a), o = l.next(); !o.done; o = l.next()) {
1224
+ var c = o.value;
1225
+ c.remove(this);
1226
+ }
1227
+ } catch (p) {
1228
+ t = { error: p };
1229
+ } finally {
1230
+ try {
1231
+ o && !o.done && (r = l.return) && r.call(l);
1232
+ } finally {
1233
+ if (t) throw t.error;
1234
+ }
1235
+ }
1236
+ else
1237
+ a.remove(this);
1238
+ var u = this.initialTeardown;
1239
+ if (b(u))
1240
+ try {
1241
+ u();
1242
+ } catch (p) {
1243
+ s = p instanceof ae ? p.errors : [p];
1244
+ }
1245
+ var f = this._finalizers;
1246
+ if (f) {
1247
+ this._finalizers = null;
1248
+ try {
1249
+ for (var h = $(f), d = h.next(); !d.done; d = h.next()) {
1250
+ var v = d.value;
1251
+ try {
1252
+ Be(v);
1253
+ } catch (p) {
1254
+ s = s ?? [], p instanceof ae ? s = ee(ee([], z(s)), z(p.errors)) : s.push(p);
1255
+ }
1256
+ }
1257
+ } catch (p) {
1258
+ n = { error: p };
1259
+ } finally {
1260
+ try {
1261
+ d && !d.done && (i = h.return) && i.call(h);
1262
+ } finally {
1263
+ if (n) throw n.error;
1264
+ }
1265
+ }
1266
+ }
1267
+ if (s)
1268
+ throw new ae(s);
1269
+ }
1270
+ }, e.prototype.add = function(t) {
1271
+ var r;
1272
+ if (t && t !== this)
1273
+ if (this.closed)
1274
+ Be(t);
1275
+ else {
1276
+ if (t instanceof e) {
1277
+ if (t.closed || t._hasParent(this))
1278
+ return;
1279
+ t._addParent(this);
1280
+ }
1281
+ (this._finalizers = (r = this._finalizers) !== null && r !== void 0 ? r : []).push(t);
1282
+ }
1283
+ }, e.prototype._hasParent = function(t) {
1284
+ var r = this._parentage;
1285
+ return r === t || Array.isArray(r) && r.includes(t);
1286
+ }, e.prototype._addParent = function(t) {
1287
+ var r = this._parentage;
1288
+ this._parentage = Array.isArray(r) ? (r.push(t), r) : r ? [r, t] : t;
1289
+ }, e.prototype._removeParent = function(t) {
1290
+ var r = this._parentage;
1291
+ r === t ? this._parentage = null : Array.isArray(r) && He(r, t);
1292
+ }, e.prototype.remove = function(t) {
1293
+ var r = this._finalizers;
1294
+ r && He(r, t), t instanceof e && t._removeParent(this);
1295
+ }, e.EMPTY = (function() {
1296
+ var t = new e();
1297
+ return t.closed = !0, t;
1298
+ })(), e;
1299
+ })();
1300
+ we.EMPTY;
1301
+ function nt(e) {
1302
+ return e instanceof we || e && "closed" in e && b(e.remove) && b(e.add) && b(e.unsubscribe);
1303
+ }
1304
+ function Be(e) {
1305
+ b(e) ? e() : e.unsubscribe();
1306
+ }
1307
+ var or = {
1308
+ Promise: void 0
1309
+ }, ar = {
1310
+ setTimeout: function(e, t) {
1311
+ for (var r = [], n = 2; n < arguments.length; n++)
1312
+ r[n - 2] = arguments[n];
1313
+ return setTimeout.apply(void 0, ee([e, t], z(r)));
1314
+ },
1315
+ clearTimeout: function(e) {
1316
+ return clearTimeout(e);
1317
+ },
1318
+ delegate: void 0
1319
+ };
1320
+ function it(e) {
1321
+ ar.setTimeout(function() {
1322
+ throw e;
1323
+ });
1324
+ }
1325
+ function Ke() {
1326
+ }
1327
+ function ur(e) {
1328
+ e();
1329
+ }
1330
+ var Ee = (function(e) {
1331
+ be(t, e);
1332
+ function t(r) {
1333
+ var n = e.call(this) || this;
1334
+ return n.isStopped = !1, r ? (n.destination = r, nt(r) && r.add(n)) : n.destination = fr, n;
1335
+ }
1336
+ return t.create = function(r, n, i) {
1337
+ return new te(r, n, i);
1338
+ }, t.prototype.next = function(r) {
1339
+ this.isStopped || this._next(r);
1340
+ }, t.prototype.error = function(r) {
1341
+ this.isStopped || (this.isStopped = !0, this._error(r));
1342
+ }, t.prototype.complete = function() {
1343
+ this.isStopped || (this.isStopped = !0, this._complete());
1344
+ }, t.prototype.unsubscribe = function() {
1345
+ this.closed || (this.isStopped = !0, e.prototype.unsubscribe.call(this), this.destination = null);
1346
+ }, t.prototype._next = function(r) {
1347
+ this.destination.next(r);
1348
+ }, t.prototype._error = function(r) {
1349
+ try {
1350
+ this.destination.error(r);
1351
+ } finally {
1352
+ this.unsubscribe();
1353
+ }
1354
+ }, t.prototype._complete = function() {
1355
+ try {
1356
+ this.destination.complete();
1357
+ } finally {
1358
+ this.unsubscribe();
1359
+ }
1360
+ }, t;
1361
+ })(we), cr = (function() {
1362
+ function e(t) {
1363
+ this.partialObserver = t;
1364
+ }
1365
+ return e.prototype.next = function(t) {
1366
+ var r = this.partialObserver;
1367
+ if (r.next)
1368
+ try {
1369
+ r.next(t);
1370
+ } catch (n) {
1371
+ W(n);
1372
+ }
1373
+ }, e.prototype.error = function(t) {
1374
+ var r = this.partialObserver;
1375
+ if (r.error)
1376
+ try {
1377
+ r.error(t);
1378
+ } catch (n) {
1379
+ W(n);
1380
+ }
1381
+ else
1382
+ W(t);
1383
+ }, e.prototype.complete = function() {
1384
+ var t = this.partialObserver;
1385
+ if (t.complete)
1386
+ try {
1387
+ t.complete();
1388
+ } catch (r) {
1389
+ W(r);
1390
+ }
1391
+ }, e;
1392
+ })(), te = (function(e) {
1393
+ be(t, e);
1394
+ function t(r, n, i) {
1395
+ var s = e.call(this) || this, a;
1396
+ return b(r) || !r ? a = {
1397
+ next: r ?? void 0,
1398
+ error: n ?? void 0,
1399
+ complete: i ?? void 0
1400
+ } : a = r, s.destination = new cr(a), s;
1401
+ }
1402
+ return t;
1403
+ })(Ee);
1404
+ function W(e) {
1405
+ it(e);
1406
+ }
1407
+ function lr(e) {
1408
+ throw e;
1409
+ }
1410
+ var fr = {
1411
+ closed: !0,
1412
+ next: Ke,
1413
+ error: lr,
1414
+ complete: Ke
1415
+ }, Se = (function() {
1416
+ return typeof Symbol == "function" && Symbol.observable || "@@observable";
1417
+ })();
1418
+ function hr(e) {
1419
+ return e;
1420
+ }
1421
+ function dr(e) {
1422
+ return e.length === 0 ? hr : e.length === 1 ? e[0] : function(r) {
1423
+ return e.reduce(function(n, i) {
1424
+ return i(n);
1425
+ }, r);
1426
+ };
1427
+ }
1428
+ var I = (function() {
1429
+ function e(t) {
1430
+ t && (this._subscribe = t);
1431
+ }
1432
+ return e.prototype.lift = function(t) {
1433
+ var r = new e();
1434
+ return r.source = this, r.operator = t, r;
1435
+ }, e.prototype.subscribe = function(t, r, n) {
1436
+ var i = this, s = vr(t) ? t : new te(t, r, n);
1437
+ return ur(function() {
1438
+ var a = i, l = a.operator, o = a.source;
1439
+ s.add(l ? l.call(s, o) : o ? i._subscribe(s) : i._trySubscribe(s));
1440
+ }), s;
1441
+ }, e.prototype._trySubscribe = function(t) {
1442
+ try {
1443
+ return this._subscribe(t);
1444
+ } catch (r) {
1445
+ t.error(r);
1446
+ }
1447
+ }, e.prototype.forEach = function(t, r) {
1448
+ var n = this;
1449
+ return r = Ve(r), new r(function(i, s) {
1450
+ var a = new te({
1451
+ next: function(l) {
1452
+ try {
1453
+ t(l);
1454
+ } catch (o) {
1455
+ s(o), a.unsubscribe();
1456
+ }
1457
+ },
1458
+ error: s,
1459
+ complete: i
1460
+ });
1461
+ n.subscribe(a);
1462
+ });
1463
+ }, e.prototype._subscribe = function(t) {
1464
+ var r;
1465
+ return (r = this.source) === null || r === void 0 ? void 0 : r.subscribe(t);
1466
+ }, e.prototype[Se] = function() {
1467
+ return this;
1468
+ }, e.prototype.pipe = function() {
1469
+ for (var t = [], r = 0; r < arguments.length; r++)
1470
+ t[r] = arguments[r];
1471
+ return dr(t)(this);
1472
+ }, e.prototype.toPromise = function(t) {
1473
+ var r = this;
1474
+ return t = Ve(t), new t(function(n, i) {
1475
+ var s;
1476
+ r.subscribe(function(a) {
1477
+ return s = a;
1478
+ }, function(a) {
1479
+ return i(a);
1480
+ }, function() {
1481
+ return n(s);
1482
+ });
1483
+ });
1484
+ }, e.create = function(t) {
1485
+ return new e(t);
1486
+ }, e;
1487
+ })();
1488
+ function Ve(e) {
1489
+ var t;
1490
+ return (t = e ?? or.Promise) !== null && t !== void 0 ? t : Promise;
1491
+ }
1492
+ function pr(e) {
1493
+ return e && b(e.next) && b(e.error) && b(e.complete);
1494
+ }
1495
+ function vr(e) {
1496
+ return e && e instanceof Ee || pr(e) && nt(e);
1497
+ }
1498
+ function yr(e) {
1499
+ return b(e?.lift);
1500
+ }
1501
+ function J(e) {
1502
+ return function(t) {
1503
+ if (yr(t))
1504
+ return t.lift(function(r) {
1505
+ try {
1506
+ return e(r, this);
1507
+ } catch (n) {
1508
+ this.error(n);
1509
+ }
1510
+ });
1511
+ throw new TypeError("Unable to lift unknown Observable type");
1512
+ };
1513
+ }
1514
+ function H(e, t, r, n, i) {
1515
+ return new mr(e, t, r, n, i);
1516
+ }
1517
+ var mr = (function(e) {
1518
+ be(t, e);
1519
+ function t(r, n, i, s, a, l) {
1520
+ var o = e.call(this, r) || this;
1521
+ return o.onFinalize = a, o.shouldUnsubscribe = l, o._next = n ? function(c) {
1522
+ try {
1523
+ n(c);
1524
+ } catch (u) {
1525
+ r.error(u);
1526
+ }
1527
+ } : e.prototype._next, o._error = s ? function(c) {
1528
+ try {
1529
+ s(c);
1530
+ } catch (u) {
1531
+ r.error(u);
1532
+ } finally {
1533
+ this.unsubscribe();
1534
+ }
1535
+ } : e.prototype._error, o._complete = i ? function() {
1536
+ try {
1537
+ i();
1538
+ } catch (c) {
1539
+ r.error(c);
1540
+ } finally {
1541
+ this.unsubscribe();
1542
+ }
1543
+ } : e.prototype._complete, o;
1544
+ }
1545
+ return t.prototype.unsubscribe = function() {
1546
+ var r;
1547
+ if (!this.shouldUnsubscribe || this.shouldUnsubscribe()) {
1548
+ var n = this.closed;
1549
+ e.prototype.unsubscribe.call(this), !n && ((r = this.onFinalize) === null || r === void 0 || r.call(this));
1550
+ }
1551
+ }, t;
1552
+ })(Ee);
1553
+ function br(e) {
1554
+ return e && b(e.schedule);
1555
+ }
1556
+ function gr(e) {
1557
+ return e[e.length - 1];
1558
+ }
1559
+ function wr(e) {
1560
+ return br(gr(e)) ? e.pop() : void 0;
1561
+ }
1562
+ var Oe = (function(e) {
1563
+ return e && typeof e.length == "number" && typeof e != "function";
1564
+ });
1565
+ function st(e) {
1566
+ return b(e?.then);
1567
+ }
1568
+ function ot(e) {
1569
+ return b(e[Se]);
1570
+ }
1571
+ function at(e) {
1572
+ return Symbol.asyncIterator && b(e?.[Symbol.asyncIterator]);
1573
+ }
1574
+ function ut(e) {
1575
+ return new TypeError("You provided " + (e !== null && typeof e == "object" ? "an invalid object" : "'" + e + "'") + " where a stream was expected. You can provide an Observable, Promise, ReadableStream, Array, AsyncIterable, or Iterable.");
1576
+ }
1577
+ function Er() {
1578
+ return typeof Symbol != "function" || !Symbol.iterator ? "@@iterator" : Symbol.iterator;
1579
+ }
1580
+ var ct = Er();
1581
+ function lt(e) {
1582
+ return b(e?.[ct]);
1583
+ }
1584
+ function ft(e) {
1585
+ return ir(this, arguments, function() {
1586
+ var r, n, i, s;
1587
+ return rt(this, function(a) {
1588
+ switch (a.label) {
1589
+ case 0:
1590
+ r = e.getReader(), a.label = 1;
1591
+ case 1:
1592
+ a.trys.push([1, , 9, 10]), a.label = 2;
1593
+ case 2:
1594
+ return [4, q(r.read())];
1595
+ case 3:
1596
+ return n = a.sent(), i = n.value, s = n.done, s ? [4, q(void 0)] : [3, 5];
1597
+ case 4:
1598
+ return [2, a.sent()];
1599
+ case 5:
1600
+ return [4, q(i)];
1601
+ case 6:
1602
+ return [4, a.sent()];
1603
+ case 7:
1604
+ return a.sent(), [3, 2];
1605
+ case 8:
1606
+ return [3, 10];
1607
+ case 9:
1608
+ return r.releaseLock(), [7];
1609
+ case 10:
1610
+ return [2];
1611
+ }
1612
+ });
1613
+ });
1614
+ }
1615
+ function ht(e) {
1616
+ return b(e?.getReader);
1617
+ }
1618
+ function C(e) {
1619
+ if (e instanceof I)
1620
+ return e;
1621
+ if (e != null) {
1622
+ if (ot(e))
1623
+ return Sr(e);
1624
+ if (Oe(e))
1625
+ return Or(e);
1626
+ if (st(e))
1627
+ return Pr(e);
1628
+ if (at(e))
1629
+ return dt(e);
1630
+ if (lt(e))
1631
+ return Rr(e);
1632
+ if (ht(e))
1633
+ return Tr(e);
1634
+ }
1635
+ throw ut(e);
1636
+ }
1637
+ function Sr(e) {
1638
+ return new I(function(t) {
1639
+ var r = e[Se]();
1640
+ if (b(r.subscribe))
1641
+ return r.subscribe(t);
1642
+ throw new TypeError("Provided object does not correctly implement Symbol.observable");
1643
+ });
1644
+ }
1645
+ function Or(e) {
1646
+ return new I(function(t) {
1647
+ for (var r = 0; r < e.length && !t.closed; r++)
1648
+ t.next(e[r]);
1649
+ t.complete();
1650
+ });
1651
+ }
1652
+ function Pr(e) {
1653
+ return new I(function(t) {
1654
+ e.then(function(r) {
1655
+ t.closed || (t.next(r), t.complete());
1656
+ }, function(r) {
1657
+ return t.error(r);
1658
+ }).then(null, it);
1659
+ });
1660
+ }
1661
+ function Rr(e) {
1662
+ return new I(function(t) {
1663
+ var r, n;
1664
+ try {
1665
+ for (var i = $(e), s = i.next(); !s.done; s = i.next()) {
1666
+ var a = s.value;
1667
+ if (t.next(a), t.closed)
1668
+ return;
1669
+ }
1670
+ } catch (l) {
1671
+ r = { error: l };
1672
+ } finally {
1673
+ try {
1674
+ s && !s.done && (n = i.return) && n.call(i);
1675
+ } finally {
1676
+ if (r) throw r.error;
1677
+ }
1678
+ }
1679
+ t.complete();
1680
+ });
1681
+ }
1682
+ function dt(e) {
1683
+ return new I(function(t) {
1684
+ xr(e, t).catch(function(r) {
1685
+ return t.error(r);
1686
+ });
1687
+ });
1688
+ }
1689
+ function Tr(e) {
1690
+ return dt(ft(e));
1691
+ }
1692
+ function xr(e, t) {
1693
+ var r, n, i, s;
1694
+ return nr(this, void 0, void 0, function() {
1695
+ var a, l;
1696
+ return rt(this, function(o) {
1697
+ switch (o.label) {
1698
+ case 0:
1699
+ o.trys.push([0, 5, 6, 11]), r = sr(e), o.label = 1;
1700
+ case 1:
1701
+ return [4, r.next()];
1702
+ case 2:
1703
+ if (n = o.sent(), !!n.done) return [3, 4];
1704
+ if (a = n.value, t.next(a), t.closed)
1705
+ return [2];
1706
+ o.label = 3;
1707
+ case 3:
1708
+ return [3, 1];
1709
+ case 4:
1710
+ return [3, 11];
1711
+ case 5:
1712
+ return l = o.sent(), i = { error: l }, [3, 11];
1713
+ case 6:
1714
+ return o.trys.push([6, , 9, 10]), n && !n.done && (s = r.return) ? [4, s.call(r)] : [3, 8];
1715
+ case 7:
1716
+ o.sent(), o.label = 8;
1717
+ case 8:
1718
+ return [3, 10];
1719
+ case 9:
1720
+ if (i) throw i.error;
1721
+ return [7];
1722
+ case 10:
1723
+ return [7];
1724
+ case 11:
1725
+ return t.complete(), [2];
1726
+ }
1727
+ });
1728
+ });
1729
+ }
1730
+ function D(e, t, r, n, i) {
1731
+ n === void 0 && (n = 0), i === void 0 && (i = !1);
1732
+ var s = t.schedule(function() {
1733
+ r(), i ? e.add(this.schedule(null, n)) : this.unsubscribe();
1734
+ }, n);
1735
+ if (e.add(s), !i)
1736
+ return s;
1737
+ }
1738
+ function pt(e, t) {
1739
+ return t === void 0 && (t = 0), J(function(r, n) {
1740
+ r.subscribe(H(n, function(i) {
1741
+ return D(n, e, function() {
1742
+ return n.next(i);
1743
+ }, t);
1744
+ }, function() {
1745
+ return D(n, e, function() {
1746
+ return n.complete();
1747
+ }, t);
1748
+ }, function(i) {
1749
+ return D(n, e, function() {
1750
+ return n.error(i);
1751
+ }, t);
1752
+ }));
1753
+ });
1754
+ }
1755
+ function vt(e, t) {
1756
+ return t === void 0 && (t = 0), J(function(r, n) {
1757
+ n.add(e.schedule(function() {
1758
+ return r.subscribe(n);
1759
+ }, t));
1760
+ });
1761
+ }
1762
+ function Ir(e, t) {
1763
+ return C(e).pipe(vt(t), pt(t));
1764
+ }
1765
+ function Ar(e, t) {
1766
+ return C(e).pipe(vt(t), pt(t));
1767
+ }
1768
+ function Fr(e, t) {
1769
+ return new I(function(r) {
1770
+ var n = 0;
1771
+ return t.schedule(function() {
1772
+ n === e.length ? r.complete() : (r.next(e[n++]), r.closed || this.schedule());
1773
+ });
1774
+ });
1775
+ }
1776
+ function kr(e, t) {
1777
+ return new I(function(r) {
1778
+ var n;
1779
+ return D(r, t, function() {
1780
+ n = e[ct](), D(r, t, function() {
1781
+ var i, s, a;
1782
+ try {
1783
+ i = n.next(), s = i.value, a = i.done;
1784
+ } catch (l) {
1785
+ r.error(l);
1786
+ return;
1787
+ }
1788
+ a ? r.complete() : r.next(s);
1789
+ }, 0, !0);
1790
+ }), function() {
1791
+ return b(n?.return) && n.return();
1792
+ };
1793
+ });
1794
+ }
1795
+ function yt(e, t) {
1796
+ if (!e)
1797
+ throw new Error("Iterable cannot be null");
1798
+ return new I(function(r) {
1799
+ D(r, t, function() {
1800
+ var n = e[Symbol.asyncIterator]();
1801
+ D(r, t, function() {
1802
+ n.next().then(function(i) {
1803
+ i.done ? r.complete() : r.next(i.value);
1804
+ });
1805
+ }, 0, !0);
1806
+ });
1807
+ });
1808
+ }
1809
+ function Cr(e, t) {
1810
+ return yt(ft(e), t);
1811
+ }
1812
+ function jr(e, t) {
1813
+ if (e != null) {
1814
+ if (ot(e))
1815
+ return Ir(e, t);
1816
+ if (Oe(e))
1817
+ return Fr(e, t);
1818
+ if (st(e))
1819
+ return Ar(e, t);
1820
+ if (at(e))
1821
+ return yt(e, t);
1822
+ if (lt(e))
1823
+ return kr(e, t);
1824
+ if (ht(e))
1825
+ return Cr(e, t);
1826
+ }
1827
+ throw ut(e);
1828
+ }
1829
+ function mt(e, t) {
1830
+ return t ? jr(e, t) : C(e);
1831
+ }
1832
+ function Lr() {
1833
+ for (var e = [], t = 0; t < arguments.length; t++)
1834
+ e[t] = arguments[t];
1835
+ var r = wr(e);
1836
+ return mt(e, r);
1837
+ }
1838
+ function bt(e, t) {
1839
+ var r = b(e) ? e : function() {
1840
+ return e;
1841
+ }, n = function(i) {
1842
+ return i.error(r());
1843
+ };
1844
+ return new I(n);
1845
+ }
1846
+ var Mr = ge(function(e) {
1847
+ return function() {
1848
+ e(this), this.name = "EmptyError", this.message = "no elements in sequence";
1849
+ };
1850
+ });
1851
+ function Q(e, t) {
1852
+ return new Promise(function(r, n) {
1853
+ var i = new te({
1854
+ next: function(s) {
1855
+ r(s), i.unsubscribe();
1856
+ },
1857
+ error: n,
1858
+ complete: function() {
1859
+ n(new Mr());
1860
+ }
1861
+ });
1862
+ e.subscribe(i);
1863
+ });
1864
+ }
1865
+ function N(e, t) {
1866
+ return J(function(r, n) {
1867
+ var i = 0;
1868
+ r.subscribe(H(n, function(s) {
1869
+ n.next(e.call(t, s, i++));
1870
+ }));
1871
+ });
1872
+ }
1873
+ var Qr = Array.isArray;
1874
+ function Dr(e, t) {
1875
+ return Qr(t) ? e.apply(void 0, ee([], z(t))) : e(t);
1876
+ }
1877
+ function Nr(e) {
1878
+ return N(function(t) {
1879
+ return Dr(e, t);
1880
+ });
1881
+ }
1882
+ function Ur(e, t, r, n, i, s, a, l) {
1883
+ var o = [], c = 0, u = 0, f = !1, h = function() {
1884
+ f && !o.length && !c && t.complete();
1885
+ }, d = function(p) {
1886
+ return c < n ? v(p) : o.push(p);
1887
+ }, v = function(p) {
1888
+ c++;
1889
+ var S = !1;
1890
+ C(r(p, u++)).subscribe(H(t, function(g) {
1891
+ t.next(g);
1892
+ }, function() {
1893
+ S = !0;
1894
+ }, void 0, function() {
1895
+ if (S)
1896
+ try {
1897
+ c--;
1898
+ for (var g = function() {
1899
+ var P = o.shift();
1900
+ a || v(P);
1901
+ }; o.length && c < n; )
1902
+ g();
1903
+ h();
1904
+ } catch (P) {
1905
+ t.error(P);
1906
+ }
1907
+ }));
1908
+ };
1909
+ return e.subscribe(H(t, d, function() {
1910
+ f = !0, h();
1911
+ })), function() {
1912
+ };
1913
+ }
1914
+ function re(e, t, r) {
1915
+ return r === void 0 && (r = 1 / 0), b(t) ? re(function(n, i) {
1916
+ return N(function(s, a) {
1917
+ return t(n, s, i, a);
1918
+ })(C(e(n, i)));
1919
+ }, r) : (typeof t == "number" && (r = t), J(function(n, i) {
1920
+ return Ur(n, i, e, r);
1921
+ }));
1922
+ }
1923
+ var _r = ["addListener", "removeListener"], qr = ["addEventListener", "removeEventListener"], Hr = ["on", "off"];
1924
+ function ve(e, t, r, n) {
1925
+ if (b(r) && (n = r, r = void 0), n)
1926
+ return ve(e, t, r).pipe(Nr(n));
1927
+ var i = z(Vr(e) ? qr.map(function(l) {
1928
+ return function(o) {
1929
+ return e[l](t, o, r);
1930
+ };
1931
+ }) : Br(e) ? _r.map($e(e, t)) : Kr(e) ? Hr.map($e(e, t)) : [], 2), s = i[0], a = i[1];
1932
+ if (!s && Oe(e))
1933
+ return re(function(l) {
1934
+ return ve(l, t, r);
1935
+ })(C(e));
1936
+ if (!s)
1937
+ throw new TypeError("Invalid event target");
1938
+ return new I(function(l) {
1939
+ var o = function() {
1940
+ for (var c = [], u = 0; u < arguments.length; u++)
1941
+ c[u] = arguments[u];
1942
+ return l.next(1 < c.length ? c : c[0]);
1943
+ };
1944
+ return s(o), function() {
1945
+ return a(o);
1946
+ };
1947
+ });
1948
+ }
1949
+ function $e(e, t) {
1950
+ return function(r) {
1951
+ return function(n) {
1952
+ return e[r](t, n);
1953
+ };
1954
+ };
1955
+ }
1956
+ function Br(e) {
1957
+ return b(e.addListener) && b(e.removeListener);
1958
+ }
1959
+ function Kr(e) {
1960
+ return b(e.on) && b(e.off);
1961
+ }
1962
+ function Vr(e) {
1963
+ return b(e.addEventListener) && b(e.removeEventListener);
1964
+ }
1965
+ var $r = Array.isArray;
1966
+ function zr(e) {
1967
+ return e.length === 1 && $r(e[0]) ? e[0] : e;
1968
+ }
1969
+ function Gr() {
1970
+ for (var e = [], t = 0; t < arguments.length; t++)
1971
+ e[t] = arguments[t];
1972
+ return e = zr(e), e.length === 1 ? C(e[0]) : new I(Jr(e));
1973
+ }
1974
+ function Jr(e) {
1975
+ return function(t) {
1976
+ for (var r = [], n = function(s) {
1977
+ r.push(C(e[s]).subscribe(H(t, function(a) {
1978
+ if (r) {
1979
+ for (var l = 0; l < r.length; l++)
1980
+ l !== s && r[l].unsubscribe();
1981
+ r = null;
1982
+ }
1983
+ t.next(a);
1984
+ })));
1985
+ }, i = 0; r && !t.closed && i < e.length; i++)
1986
+ n(i);
1987
+ };
1988
+ }
1989
+ function Pe(e) {
1990
+ return J(function(t, r) {
1991
+ var n = null, i = !1, s;
1992
+ n = t.subscribe(H(r, void 0, void 0, function(a) {
1993
+ s = C(e(a, Pe(e)(t))), n ? (n.unsubscribe(), n = null, s.subscribe(r)) : i = !0;
1994
+ })), i && (n.unsubscribe(), n = null, s.subscribe(r));
1995
+ });
1996
+ }
1997
+ function gt(e) {
1998
+ switch (e.responseType) {
1999
+ case "json": {
2000
+ if ("response" in e)
2001
+ return e.response;
2002
+ var t = e;
2003
+ return JSON.parse(t.responseText);
2004
+ }
2005
+ case "document":
2006
+ return e.responseXML;
2007
+ default: {
2008
+ if ("response" in e)
2009
+ return e.response;
2010
+ var t = e;
2011
+ return t.responseText;
2012
+ }
2013
+ }
2014
+ }
2015
+ var Xr = /* @__PURE__ */ (function() {
2016
+ function e(t, r, n, i) {
2017
+ i === void 0 && (i = "download_load"), this.originalEvent = t, this.xhr = r, this.request = n, this.type = i;
2018
+ var s = r.status, a = r.responseType;
2019
+ this.status = s ?? 0, this.responseType = a ?? "";
2020
+ var l = r.getAllResponseHeaders();
2021
+ this.responseHeaders = l ? l.split(`
2022
+ `).reduce(function(u, f) {
2023
+ var h = f.indexOf(": ");
2024
+ return u[f.slice(0, h)] = f.slice(h + 2), u;
2025
+ }, {}) : {}, this.response = gt(r);
2026
+ var o = t.loaded, c = t.total;
2027
+ this.loaded = o, this.total = c;
2028
+ }
2029
+ return e;
2030
+ })(), G = ge(function(e) {
2031
+ return function(r, n, i) {
2032
+ this.message = r, this.name = "AjaxError", this.xhr = n, this.request = i, this.status = n.status, this.responseType = n.responseType;
2033
+ var s;
2034
+ try {
2035
+ s = gt(n);
2036
+ } catch {
2037
+ s = n.responseText;
2038
+ }
2039
+ this.response = s;
2040
+ };
2041
+ }), Wr = (function() {
2042
+ function e(t, r) {
2043
+ return G.call(this, "ajax timeout", t, r), this.name = "AjaxTimeoutError", this;
2044
+ }
2045
+ return e.prototype = Object.create(G.prototype), e;
2046
+ })();
2047
+ function Yr(e, t) {
2048
+ return U({ method: "GET", url: e, headers: t });
2049
+ }
2050
+ function Zr(e, t, r) {
2051
+ return U({ method: "POST", url: e, body: t, headers: r });
2052
+ }
2053
+ function en(e, t) {
2054
+ return U({ method: "DELETE", url: e, headers: t });
2055
+ }
2056
+ function tn(e, t, r) {
2057
+ return U({ method: "PUT", url: e, body: t, headers: r });
2058
+ }
2059
+ function rn(e, t, r) {
2060
+ return U({ method: "PATCH", url: e, body: t, headers: r });
2061
+ }
2062
+ var nn = N(function(e) {
2063
+ return e.response;
2064
+ });
2065
+ function sn(e, t) {
2066
+ return nn(U({
2067
+ method: "GET",
2068
+ url: e,
2069
+ headers: t
2070
+ }));
2071
+ }
2072
+ var U = (function() {
2073
+ var e = function(t) {
2074
+ var r = typeof t == "string" ? {
2075
+ url: t
2076
+ } : t;
2077
+ return an(r);
2078
+ };
2079
+ return e.get = Yr, e.post = Zr, e.delete = en, e.put = tn, e.patch = rn, e.getJSON = sn, e;
2080
+ })(), on = "upload", ze = "download", ue = "loadstart", ce = "progress", Ge = "load";
2081
+ function an(e) {
2082
+ return new I(function(t) {
2083
+ var r, n, i = K({ async: !0, crossDomain: !1, withCredentials: !1, method: "GET", timeout: 0, responseType: "json" }, e), s = i.queryParams, a = i.body, l = i.headers, o = i.url;
2084
+ if (!o)
2085
+ throw new TypeError("url is required");
2086
+ if (s) {
2087
+ var c;
2088
+ if (o.includes("?")) {
2089
+ var u = o.split("?");
2090
+ if (2 < u.length)
2091
+ throw new TypeError("invalid url");
2092
+ c = new URLSearchParams(u[1]), new URLSearchParams(s).forEach(function(E, O) {
2093
+ return c.set(O, E);
2094
+ }), o = u[0] + "?" + c;
2095
+ } else
2096
+ c = new URLSearchParams(s), o = o + "?" + c;
2097
+ }
2098
+ var f = {};
2099
+ if (l)
2100
+ for (var h in l)
2101
+ l.hasOwnProperty(h) && (f[h.toLowerCase()] = l[h]);
2102
+ var d = i.crossDomain;
2103
+ !d && !("x-requested-with" in f) && (f["x-requested-with"] = "XMLHttpRequest");
2104
+ var v = i.withCredentials, p = i.xsrfCookieName, S = i.xsrfHeaderName;
2105
+ if ((v || !d) && p && S) {
2106
+ var g = (n = (r = document?.cookie.match(new RegExp("(^|;\\s*)(" + p + ")=([^;]*)"))) === null || r === void 0 ? void 0 : r.pop()) !== null && n !== void 0 ? n : "";
2107
+ g && (f[S] = g);
2108
+ }
2109
+ var P = un(a, f), w = K(K({}, i), {
2110
+ url: o,
2111
+ headers: f,
2112
+ body: P
2113
+ }), y;
2114
+ y = e.createXHR ? e.createXHR() : new XMLHttpRequest();
2115
+ {
2116
+ var m = e.progressSubscriber, j = e.includeDownloadProgress, A = j === void 0 ? !1 : j, T = e.includeUploadProgress, _ = T === void 0 ? !1 : T, k = function(E, O) {
2117
+ y.addEventListener(E, function() {
2118
+ var x, M = O();
2119
+ (x = m?.error) === null || x === void 0 || x.call(m, M), t.error(M);
2120
+ });
2121
+ };
2122
+ k("timeout", function() {
2123
+ return new Wr(y, w);
2124
+ }), k("abort", function() {
2125
+ return new G("aborted", y, w);
2126
+ });
2127
+ var L = function(E, O) {
2128
+ return new Xr(O, y, w, E + "_" + O.type);
2129
+ }, Te = function(E, O, x) {
2130
+ E.addEventListener(O, function(M) {
2131
+ t.next(L(x, M));
2132
+ });
2133
+ };
2134
+ _ && [ue, ce, Ge].forEach(function(E) {
2135
+ return Te(y.upload, E, on);
2136
+ }), m && [ue, ce].forEach(function(E) {
2137
+ return y.upload.addEventListener(E, function(O) {
2138
+ var x;
2139
+ return (x = m?.next) === null || x === void 0 ? void 0 : x.call(m, O);
2140
+ });
2141
+ }), A && [ue, ce].forEach(function(E) {
2142
+ return Te(y, E, ze);
2143
+ });
2144
+ var xe = function(E) {
2145
+ var O = "ajax error" + (E ? " " + E : "");
2146
+ t.error(new G(O, y, w));
2147
+ };
2148
+ y.addEventListener("error", function(E) {
2149
+ var O;
2150
+ (O = m?.error) === null || O === void 0 || O.call(m, E), xe();
2151
+ }), y.addEventListener(Ge, function(E) {
2152
+ var O, x, M = y.status;
2153
+ if (M < 400) {
2154
+ (O = m?.complete) === null || O === void 0 || O.call(m);
2155
+ var Fe = void 0;
2156
+ try {
2157
+ Fe = L(ze, E);
2158
+ } catch (wt) {
2159
+ t.error(wt);
2160
+ return;
2161
+ }
2162
+ t.next(Fe), t.complete();
2163
+ } else
2164
+ (x = m?.error) === null || x === void 0 || x.call(m, E), xe(M);
2165
+ });
2166
+ }
2167
+ var Ie = w.user, Ae = w.method, se = w.async;
2168
+ Ie ? y.open(Ae, o, se, Ie, w.password) : y.open(Ae, o, se), se && (y.timeout = w.timeout, y.responseType = w.responseType), "withCredentials" in y && (y.withCredentials = w.withCredentials);
2169
+ for (var h in f)
2170
+ f.hasOwnProperty(h) && y.setRequestHeader(h, f[h]);
2171
+ return P ? y.send(P) : y.send(), function() {
2172
+ y && y.readyState !== 4 && y.abort();
2173
+ };
2174
+ });
2175
+ }
2176
+ function un(e, t) {
2177
+ var r;
2178
+ if (!e || typeof e == "string" || pn(e) || vn(e) || ln(e) || fn(e) || hn(e) || yn(e))
2179
+ return e;
2180
+ if (dn(e))
2181
+ return e.buffer;
2182
+ if (typeof e == "object")
2183
+ return t["content-type"] = (r = t["content-type"]) !== null && r !== void 0 ? r : "application/json;charset=utf-8", JSON.stringify(e);
2184
+ throw new TypeError("Unknown body type");
2185
+ }
2186
+ var cn = Object.prototype.toString;
2187
+ function Re(e, t) {
2188
+ return cn.call(e) === "[object " + t + "]";
2189
+ }
2190
+ function ln(e) {
2191
+ return Re(e, "ArrayBuffer");
2192
+ }
2193
+ function fn(e) {
2194
+ return Re(e, "File");
2195
+ }
2196
+ function hn(e) {
2197
+ return Re(e, "Blob");
2198
+ }
2199
+ function dn(e) {
2200
+ return typeof ArrayBuffer < "u" && ArrayBuffer.isView(e);
2201
+ }
2202
+ function pn(e) {
2203
+ return typeof FormData < "u" && e instanceof FormData;
2204
+ }
2205
+ function vn(e) {
2206
+ return typeof URLSearchParams < "u" && e instanceof URLSearchParams;
2207
+ }
2208
+ function yn(e) {
2209
+ return typeof ReadableStream < "u" && e instanceof ReadableStream;
2210
+ }
2211
+ function ye(e, t, r = []) {
2212
+ return {
2213
+ handle: (n, i) => {
2214
+ let s;
2215
+ for (const l of Array.isArray(n) ? n : [n]) {
2216
+ const o = e.find(
2217
+ (c) => c.ErrorCode === t[l]
2218
+ );
2219
+ if (o) {
2220
+ s = i(l, o);
2221
+ break;
2222
+ }
2223
+ }
2224
+ let a = r;
2225
+ return s !== void 0 && (a = [...a, s]), ye(
2226
+ e,
2227
+ t,
2228
+ a
2229
+ );
2230
+ },
2231
+ handleAll: (n, i) => {
2232
+ let s;
2233
+ const a = (Array.isArray(n) ? n : [n]).reduce(
2234
+ (o, c) => {
2235
+ const u = e.filter(
2236
+ (f) => f.ErrorCode === t[c]
2237
+ );
2238
+ return u.length === 0 ? o : [
2239
+ ...o,
2240
+ {
2241
+ errorName: c,
2242
+ errors: u
2243
+ }
2244
+ ];
2245
+ },
2246
+ []
2247
+ );
2248
+ a.length > 0 && (s = i(a));
2249
+ let l = r;
2250
+ return s !== void 0 && (l = [...l, s]), ye(
2251
+ e,
2252
+ t,
2253
+ l
2254
+ );
2255
+ },
2256
+ check: ((n) => {
2257
+ if (n)
2258
+ return r.reduce(n.reducer, n.initialValue);
2259
+ })
2260
+ };
2261
+ }
2262
+ function mn(e, t) {
2263
+ const r = {
2264
+ ...t,
2265
+ success: -1,
2266
+ failure: -2
2267
+ }, n = e.isSuccess ? e.result.WasSuccessful ? [
2268
+ {
2269
+ ErrorMessage: "",
2270
+ PropertyName: "",
2271
+ ErrorCode: -1
2272
+ }
2273
+ ] : e.result.ValidationErrors : [
2274
+ {
2275
+ ErrorMessage: "",
2276
+ PropertyName: "",
2277
+ ErrorCode: -2
2278
+ }
2279
+ ];
2280
+ return ye(n, r);
2281
+ }
2282
+ function bn(e) {
2283
+ return e?.invalidateToken ? (t) => t.pipe(
2284
+ Pe((r) => (r.status === 401 && e.invalidateToken?.(), bt(() => r)))
2285
+ ) : (t) => t;
2286
+ }
2287
+ process.env.NODE_ENV;
2288
+ function gn(e, t) {
2289
+ return e.length === 0 ? "" : t(e[0]) + e.slice(1);
2290
+ }
2291
+ function wn(e) {
2292
+ return gn(e, (t) => t.toLowerCase());
2293
+ }
2294
+ function En(e) {
2295
+ return JSON.parse(e, (t, r) => {
2296
+ if (!(r === null && t !== ""))
2297
+ return !r || Array.isArray(r) || typeof r != "object" ? r : Object.fromEntries(Object.entries(r).map(([n, i]) => [wn(n), i]));
2298
+ });
2299
+ }
2300
+ function Je() {
2301
+ return (e) => e.pipe(N(En));
2302
+ }
2303
+ function On({
2304
+ cqrsEndpoint: e,
2305
+ queryClient: t,
2306
+ tokenProvider: r,
2307
+ ajaxOptions: n,
2308
+ tokenHeader: i = "Authorization"
2309
+ }) {
2310
+ function s(a, l = {}) {
2311
+ const o = (f, h) => U({
2312
+ ...n,
2313
+ ...l,
2314
+ headers: {
2315
+ [i]: h,
2316
+ "Content-Type": "application/json"
2317
+ },
2318
+ url: `${e}/${a}`,
2319
+ method: "POST",
2320
+ body: f,
2321
+ withCredentials: n?.withCredentials ?? !0
2322
+ }), c = r?.getToken, u = (f, h) => o(f, h).pipe(
2323
+ bn(r),
2324
+ N((d) => d.response)
2325
+ );
2326
+ return c ? (f) => mt(c()).pipe(re((h) => u(f, h))) : (f) => u(f);
2327
+ }
2328
+ return {
2329
+ createQuery(a) {
2330
+ const l = s(`query/${a}`, { responseType: "text" });
2331
+ function o(u, f) {
2332
+ return tr(
2333
+ {
2334
+ queryKey: o.key(u),
2335
+ queryFn: (h) => Q(o.fetcher(u, h)),
2336
+ ...f
2337
+ },
2338
+ t
2339
+ );
2340
+ }
2341
+ o.type = a, o.fetcher = (u, f) => Gr([
2342
+ l(u).pipe(Je()),
2343
+ ...f?.signal ? [
2344
+ ve(f.signal, "abort").pipe(
2345
+ re(() => bt(() => new Error("Query aborted")))
2346
+ )
2347
+ ] : []
2348
+ ]), o.fetch = (u, f) => t.fetchQuery({
2349
+ queryKey: o.key(u),
2350
+ queryFn: (h) => Q(o.fetcher(u, h)),
2351
+ ...f
2352
+ }), o.lazy = function(u = {}) {
2353
+ return oe(
2354
+ {
2355
+ mutationKey: [a],
2356
+ mutationFn: (f) => Q(o.fetcher(f)),
2357
+ ...u
2358
+ },
2359
+ t
2360
+ );
2361
+ }, o.infinite = function(u, f) {
2362
+ return rr(
2363
+ {
2364
+ queryKey: [a],
2365
+ queryFn: (h) => Q(o.fetcher(h.pageParam, h)),
2366
+ initialPageParam: u,
2367
+ ...f
2368
+ },
2369
+ t
2370
+ );
2371
+ }, o.key = (u) => [a, u];
2372
+ function c(u, f) {
2373
+ const h = Array.isArray(u) ? u : o.key(u);
2374
+ return t.setQueryData(h, f);
2375
+ }
2376
+ return o.setQueryData = c, o.setQueriesData = (u, f) => t.setQueriesData({ queryKey: o.key(u) }, f), o.getQueryData = (u) => t.getQueryData(o.key(u)), o.getQueriesData = (u) => t.getQueriesData({
2377
+ queryKey: o.key(u)
2378
+ }), o.prefetch = (u, f) => t.prefetchQuery({
2379
+ queryKey: o.key(u),
2380
+ queryFn: (h) => Q(o.fetcher(u, h)),
2381
+ ...f
2382
+ }), o.invalidate = (u) => t.invalidateQueries({ queryKey: o.key(u) }), o.cancel = (u) => t.cancelQueries({ queryKey: o.key(u) }), o.optimisticUpdate = async (u, f = {}) => {
2383
+ await o.cancel(f);
2384
+ const h = o.getQueriesData(f);
2385
+ return o.setQueriesData(f, u), () => h.forEach(([d, v]) => t.setQueryData(d, v));
2386
+ }, o;
2387
+ },
2388
+ createOperation(a) {
2389
+ const l = s(`operation/${a}`, { responseType: "text" });
2390
+ function o({
2391
+ onSuccess: c,
2392
+ invalidateQueries: u,
2393
+ ...f
2394
+ } = {}) {
2395
+ return oe(
2396
+ {
2397
+ mutationKey: o.key,
2398
+ mutationFn: (h) => Q(o.fetcher(h)),
2399
+ ...f,
2400
+ async onSuccess(h, d, v, p) {
2401
+ const S = await c?.(h, d, v, p);
2402
+ return u && await Promise.allSettled(u.map((g) => t.invalidateQueries({ queryKey: g }))), S;
2403
+ }
2404
+ },
2405
+ t
2406
+ );
2407
+ }
2408
+ return o.type = a, o.key = [o.type], o.fetcher = (c) => l(c).pipe(Je()), o;
2409
+ },
2410
+ createCommand(a, l) {
2411
+ const o = s(`command/${a}`);
2412
+ function c({
2413
+ invalidateQueries: u,
2414
+ handler: f,
2415
+ optimisticUpdate: h,
2416
+ onMutate: d,
2417
+ onError: v,
2418
+ onSettled: p,
2419
+ ...S
2420
+ } = {}) {
2421
+ return oe(
2422
+ {
2423
+ ...S,
2424
+ mutationKey: c.key,
2425
+ mutationFn: (g) => Q(c.call(g, f)),
2426
+ async onMutate(g, P) {
2427
+ const w = await d?.(g, P), y = await Promise.all(h?.(g) ?? []);
2428
+ return {
2429
+ ...w,
2430
+ revertOptimisticUpdate: () => y.forEach((m) => m())
2431
+ };
2432
+ },
2433
+ async onError(g, P, w, y) {
2434
+ await v?.(g, P, w, y), w?.revertOptimisticUpdate();
2435
+ },
2436
+ // eslint-disable-next-line max-params
2437
+ async onSettled(g, P, w, y, m) {
2438
+ return u && await Promise.allSettled(u.map((j) => t.invalidateQueries({ queryKey: j }))), await p?.(g, P, w, y, m);
2439
+ }
2440
+ },
2441
+ t
2442
+ );
2443
+ }
2444
+ return c.type = a, c.key = [c.type], c.fetcher = o, c.call = (u, f) => c.fetcher(u).pipe(
2445
+ N(
2446
+ (d) => ({
2447
+ isSuccess: !0,
2448
+ result: d
2449
+ })
2450
+ ),
2451
+ Pe((d) => Lr(c.mapError(d))),
2452
+ N((d) => {
2453
+ const v = f ? c.handleResponse(f, u)(d) : d;
2454
+ if (!d.isSuccess || !d.result.WasSuccessful)
2455
+ throw v;
2456
+ return v;
2457
+ })
2458
+ ), c.mapError = (u) => u instanceof G && u.status === 422 ? {
2459
+ isSuccess: !0,
2460
+ result: u.response
2461
+ } : {
2462
+ isSuccess: !1,
2463
+ error: u
2464
+ }, c.handleResponse = (u, f) => (h) => u(mn(h, l), f), c;
2465
+ }
2466
+ };
2467
+ }
2468
+ export {
2469
+ On as mkCqrsClient
2470
+ };