reactjrx 1.130.0 → 1.131.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.
package/dist/index.js CHANGED
@@ -1,944 +1,2 @@
1
- import { c as E } from "react/compiler-runtime";
2
- import { useRef as R, useEffect as N, useMemo as ie, useState as G, useSyncExternalStore as Ve, useCallback as ee, createContext as ue, memo as ae, useContext as le } from "react";
3
- import { BehaviorSubject as V, of as w, defer as W, merge as A, throwError as j, timer as Re, ReplaySubject as te, NEVER as qe, distinctUntilChanged as fe, tap as X, share as Z, isObservable as re, from as T, catchError as D, EMPTY as ye, retry as Fe, identity as Pe, takeUntil as Ae, fromEvent as de, take as pe, filter as Te, first as me, switchMap as O, noop as be, delay as Oe, ignoreElements as Qe, defaultIfEmpty as ke, zip as De, throttleTime as He, asyncScheduler as Ke, map as Y, concatMap as je, scan as Le } from "rxjs";
4
- import { catchError as ne, mergeMap as L, retryWhen as ze, concatMap as Ye, first as Je, tap as Ue } from "rxjs/operators";
5
- import { jsx as he } from "react/jsx-runtime";
6
- import { hashKey as ve, useMutation as Ge, useQueryClient as ge, useQuery as We } from "@tanstack/react-query";
7
- const se = /* @__PURE__ */ Symbol("UNSET"), H = (r) => {
8
- const t = R(se);
9
- return t.current === se && (t.current = r()), t;
10
- }, K = (r) => H(r).current, oe = (r) => {
11
- const t = E(6);
12
- let e;
13
- t[0] !== r ? (e = () => new V(r), t[0] = r, t[1] = e) : e = t[1];
14
- const n = K(e);
15
- let s, o;
16
- return t[2] !== r || t[3] !== n ? (s = () => {
17
- n.next(r);
18
- }, o = [r, n], t[2] = r, t[3] = n, t[4] = s, t[5] = o) : (s = t[4], o = t[5]), N(s, o), n;
19
- }, q = (r) => {
20
- const t = R(r);
21
- return ie(() => {
22
- t.current = r;
23
- }, [r]), t;
24
- }, Rt = (r) => {
25
- const t = E(10);
26
- let e;
27
- t[0] !== r ? (e = () => new V(r), t[0] = r, t[1] = e) : e = t[1];
28
- const n = K(e), s = q(n);
29
- let o;
30
- t[2] !== n ? (o = (p) => {
31
- n.next(p);
32
- }, t[2] = n, t[3] = o) : o = t[3];
33
- const c = o, u = s.current;
34
- let i;
35
- t[4] !== n ? (i = n.getValue(), t[4] = n, t[5] = i) : i = t[5];
36
- let a;
37
- return t[6] !== c || t[7] !== s.current || t[8] !== i ? (a = [u, c, i], t[6] = c, t[7] = s.current, t[8] = i, t[9] = a) : a = t[9], a;
38
- }, Xe = (r, t) => r.length === t.length && r.every((e, n) => e === t[n]);
39
- function qt(r) {
40
- return r != null;
41
- }
42
- function ce(r) {
43
- return r instanceof Promise || r && typeof r == "object" && "then" in r && typeof r.then == "function" && "catch" in r && r.catch === "function";
44
- }
45
- const Ft = typeof window > "u" || "Deno" in window;
46
- function Ze(r, t) {
47
- return Math.min(r, t);
48
- }
49
- function Be(r, t) {
50
- return 2 ** r * t;
51
- }
52
- function Pt(r) {
53
- const {
54
- retry: t,
55
- retryDelay: e,
56
- retryAfterDelay: n,
57
- retryAfter: s = () => w(!0)
58
- } = r, o = typeof t != "function" ? t === !1 ? 0 : t === !0 ? Number.POSITIVE_INFINITY : t ?? Number.POSITIVE_INFINITY : Number.POSITIVE_INFINITY, c = typeof t == "function" ? (
59
- // ? (attempt: number, error: TError) => of(retry(attempt, error))
60
- t
61
- ) : () => !0, u = typeof e == "number" ? e : 100, i = {
62
- ...r
63
- }, {
64
- maxInterval: a = Number.POSITIVE_INFINITY,
65
- resetOnSuccess: p = !1,
66
- backoffDelay: l = Be
67
- } = i;
68
- return (y) => W(() => {
69
- let m = 0;
70
- const v = (d, b) => d < o ? c(d, b) : !1;
71
- return y.pipe(ne((d) => {
72
- if (m++, !v(m - 1, d)) throw d;
73
- const b = r.caughtError?.(m, d);
74
- if (!b) throw d;
75
- return b.pipe(L((f) => A(w(f), j(() => d))));
76
- }), ze((d) => d.pipe(Ye((b) => {
77
- const f = m - 1;
78
- return s().pipe(Je(), L(() => v(f, b) ? Re(Ze(l(f, u), a)).pipe(L((h) => n && !n(f, b) ? j(() => b) : w(h))) : j(() => b)));
79
- }))), ne((d) => {
80
- if (r.catchError)
81
- return r.catchError(m, d);
82
- throw d;
83
- }), Ue(() => {
84
- p && (m = 0);
85
- }));
86
- });
87
- }
88
- const At = () => {
89
- const r = H(() => new te(1)), [t, e] = G(!1);
90
- return t && (r.current = new te(1), e(!1)), N(() => () => {
91
- r.current.next(void 0), e(!0);
92
- }, [r]), r.current;
93
- }, Se = (r) => {
94
- const t = E(1);
95
- let e;
96
- t[0] === /* @__PURE__ */ Symbol.for("react.memo_cache_sentinel") ? (e = [], t[0] = e) : e = t[0], N(r, e);
97
- }, et = (r) => {
98
- const t = R(r);
99
- t.current = r, Se(() => () => t.current());
100
- }, Tt = (r, t, e) => {
101
- const n = E(7);
102
- let s;
103
- n[0] !== e ? (s = e === void 0 ? {} : e, n[0] = e, n[1] = s) : s = n[1];
104
- const o = s, {
105
- cancelOnUnmount: c
106
- } = o, u = c === void 0 ? !1 : c, i = R(null);
107
- let a;
108
- n[2] !== r || n[3] !== t ? (a = (y) => {
109
- i.current !== null && clearTimeout(i.current), i.current = setTimeout(() => r(y), t);
110
- }, n[2] = r, n[3] = t, n[4] = a) : a = n[4];
111
- const p = a;
112
- let l;
113
- return n[5] !== u ? (l = () => {
114
- u && i.current && clearTimeout(i.current);
115
- }, n[5] = u, n[6] = l) : l = n[6], et(l), p;
116
- }, Ot = (r, t) => {
117
- const e = R({
118
- value: r
119
- });
120
- return ie(() => t(r, e.current.value) ? e.current.value : (e.current = {
121
- value: r
122
- }, r), [r, t]);
123
- }, Qt = (r) => {
124
- const t = E(2);
125
- let e;
126
- t[0] !== r ? (e = () => {
127
- r();
128
- }, t[0] = r, t[1] = e) : e = t[1], Se(e);
129
- };
130
- class tt {
131
- state;
132
- source$;
133
- sub;
134
- constructor({
135
- source$: t,
136
- defaultValue: e,
137
- compareFn: n
138
- }) {
139
- const s = typeof t == "function" ? t() : t, o = s === void 0;
140
- this.state = {
141
- data: s instanceof V ? s.value : e,
142
- status: o ? "success" : "pending",
143
- observableState: o ? "complete" : "live",
144
- error: void 0
145
- }, this.source$ = (s ?? qe).pipe(fe(n), X({
146
- complete: () => {
147
- this.state = {
148
- ...this.state,
149
- status: "success",
150
- observableState: "complete"
151
- };
152
- },
153
- error: (c) => {
154
- this.state = {
155
- ...this.state,
156
- observableState: "error",
157
- status: "error",
158
- error: c
159
- };
160
- },
161
- next: (c) => {
162
- this.state = {
163
- ...this.state,
164
- data: c
165
- };
166
- }
167
- }), Z()), this.sub = this.source$.subscribe();
168
- }
169
- subscribe = (t) => {
170
- if (this.state.observableState === "complete")
171
- return () => {
172
- };
173
- const e = this.source$.subscribe({
174
- complete: t,
175
- error: t,
176
- next: t
177
- });
178
- return () => {
179
- e.unsubscribe();
180
- };
181
- };
182
- getSnapshot = () => this.state;
183
- }
184
- const rt = (r, t, e) => {
185
- const n = q(t), s = R(void 0);
186
- (!s.current || !Xe([...e], [...s.current.deps])) && (s.current = {
187
- deps: e,
188
- store: new tt({
189
- source$: r,
190
- defaultValue: n.current.defaultValue,
191
- compareFn: (c, u) => n.current?.compareFn?.(c, u) ?? c === u
192
- })
193
- });
194
- const o = s.current.store;
195
- return N(() => () => {
196
- o.sub.unsubscribe();
197
- }, [o]), o;
198
- };
199
- function Ee(r, t, e) {
200
- const n = E(6);
201
- let s;
202
- n[0] !== t ? (s = t != null && !Array.isArray(t) ? t : {
203
- defaultValue: void 0,
204
- compareFn: void 0
205
- }, n[0] = t, n[1] = s) : s = n[1];
206
- const o = s;
207
- let c;
208
- n[2] !== e || n[3] !== t || n[4] !== r ? (c = !e && Array.isArray(t) ? t : typeof r == "function" ? e ?? [] : [r], n[2] = e, n[3] = t, n[4] = r, n[5] = c) : c = n[5];
209
- const i = rt(r, o, c);
210
- return Ve(i.subscribe, i.getSnapshot, i.getSnapshot);
211
- }
212
- function Ie(r) {
213
- if (re(r)) return () => r;
214
- if (ce(r)) return () => T(r);
215
- if (typeof r != "function") return () => w(r);
216
- const t = r;
217
- return (e) => W(() => {
218
- const n = t(e);
219
- return ce(n) ? T(n) : re(n) ? n : w(n);
220
- });
221
- }
222
- function nt(r, t) {
223
- const e = E(7);
224
- let n;
225
- e[0] !== t ? (n = t === void 0 ? [] : t, e[0] = t, e[1] = n) : n = e[1];
226
- const s = n, o = q(r);
227
- let c;
228
- e[2] !== o ? (c = () => {
229
- const i = Ie(o.current)().pipe(D(st)).subscribe();
230
- return () => {
231
- i.unsubscribe();
232
- };
233
- }, e[2] = o, e[3] = c) : c = e[3];
234
- let u;
235
- e[4] !== s || e[5] !== o ? (u = [...s, o], e[4] = s, e[5] = o, e[6] = u) : u = e[6], N(c, u);
236
- }
237
- function st(r) {
238
- return console.error(r), ye;
239
- }
240
- function kt(r, t, e = []) {
241
- const n = t != null && !Array.isArray(t) ? t : {}, s = n.retry ?? !0, o = q(n.onError ?? ((i) => {
242
- console.error(i);
243
- })), c = ee(() => Ie(r)(), e), u = ee(() => c().pipe(D((i) => {
244
- throw o.current(i), i;
245
- }), s ? Fe() : Pe), [c, s, o]);
246
- nt(u, e);
247
- }
248
- class ot {
249
- queryMap = /* @__PURE__ */ new Map();
250
- getQuery(t) {
251
- return this.queryMap.get(t);
252
- }
253
- setQuery(t, e, n) {
254
- const s = ve(t), o = e.pipe(
255
- /**
256
- * abort signal is triggered on:
257
- * - manual cancellation from user
258
- * - unmounting the component
259
- * @see https://tanstack.com/query/latest/docs/framework/react/guides/query-cancellation
260
- */
261
- Ae(de(n, "abort")),
262
- Z()
263
- ), c = {
264
- query$: o,
265
- signal: n,
266
- sub: void 0,
267
- isCompleted: !1,
268
- lastData: void 0
269
- };
270
- this.queryMap.set(s, c);
271
- const u = o.subscribe({
272
- next: (i) => {
273
- const a = this.queryMap.get(s);
274
- a && (a.lastData = {
275
- value: i
276
- });
277
- },
278
- complete: () => {
279
- this.deleteQuery(s);
280
- }
281
- });
282
- return c.sub = u, c;
283
- }
284
- deleteQuery(t) {
285
- const e = this.queryMap.get(t);
286
- e && (e.sub && (e.sub.unsubscribe(), e.sub = void 0), e.isCompleted = !0, this.queryMap.delete(t));
287
- }
288
- destroy() {
289
- this.queryMap.forEach((t, e) => {
290
- this.deleteQuery(e);
291
- });
292
- }
293
- }
294
- const we = ue(void 0), Dt = ae((r) => {
295
- const t = E(8), {
296
- children: e,
297
- client: n
298
- } = r;
299
- let s;
300
- t[0] !== n ? (s = () => n ?? new ot(), t[0] = n, t[1] = s) : s = t[1];
301
- const [o] = G(s);
302
- let c, u;
303
- t[2] !== o ? (c = () => () => {
304
- o.destroy();
305
- }, u = [o], t[2] = o, t[3] = c, t[4] = u) : (c = t[3], u = t[4]), N(c, u);
306
- let i;
307
- return t[5] !== e || t[6] !== o ? (i = /* @__PURE__ */ he(we.Provider, { value: o, children: e }), t[5] = e, t[6] = o, t[7] = i) : i = t[7], i;
308
- }), ct = () => {
309
- const r = le(we);
310
- if (!r)
311
- throw new Error("useReactJrxQueryClient must be used within a ReactJrxQueryProvider");
312
- return r;
313
- };
314
- function $e(r, t) {
315
- const e = E(16), n = K(it);
316
- let s;
317
- e[0] !== r ? (s = (d) => {
318
- let b;
319
- return new Promise((f, h) => {
320
- (typeof r.mutationFn == "function" ? r.mutationFn(d) : r.mutationFn).pipe(pe(1)).subscribe({
321
- next: (S) => {
322
- b = {
323
- value: S
324
- };
325
- },
326
- error: (S) => {
327
- h(S);
328
- },
329
- complete: () => {
330
- if (b === void 0)
331
- return h(new Error("Stream completed without any data"));
332
- f(b.value);
333
- }
334
- });
335
- });
336
- }, e[0] = r, e[1] = s) : s = e[1];
337
- let o;
338
- e[2] !== r || e[3] !== s ? (o = {
339
- ...r,
340
- mutationFn: s
341
- }, e[2] = r, e[3] = s, e[4] = o) : o = e[4];
342
- const c = Ge(o, t), {
343
- status: u,
344
- isPending: i,
345
- isError: a,
346
- isSuccess: p,
347
- isIdle: l
348
- } = c;
349
- let y, m;
350
- e[5] !== a || e[6] !== l || e[7] !== i || e[8] !== p || e[9] !== n || e[10] !== u ? (y = () => {
351
- n.next({
352
- status: u,
353
- isPending: i,
354
- isError: a,
355
- isSuccess: p,
356
- isIdle: l
357
- });
358
- }, m = [u, i, a, p, l, n], e[5] = a, e[6] = l, e[7] = i, e[8] = p, e[9] = n, e[10] = u, e[11] = y, e[12] = m) : (y = e[11], m = e[12]), N(y, m);
359
- let v;
360
- return e[13] !== c || e[14] !== n ? (v = {
361
- ...c,
362
- state$: n
363
- }, e[13] = c, e[14] = n, e[15] = v) : v = e[15], v;
364
- }
365
- function it() {
366
- return new V({
367
- status: "idle",
368
- isPending: !1,
369
- isError: !1,
370
- isSuccess: !1,
371
- isIdle: !0
372
- });
373
- }
374
- function Ht(r, t) {
375
- const e = E(23);
376
- let n, s;
377
- e[0] !== r ? ({
378
- onMutate: n,
379
- ...s
380
- } = r, e[0] = r, e[1] = n, e[2] = s) : (n = e[1], s = e[2]);
381
- const o = ge(t), c = s.mutationKey;
382
- let u;
383
- e[3] !== n ? (u = n ? (f, ...h) => {
384
- const {
385
- variables: g
386
- } = f;
387
- return n(g, ...h);
388
- } : void 0, e[3] = n, e[4] = u) : u = e[4];
389
- let i;
390
- if (e[5] !== s || e[6] !== u) {
391
- let f;
392
- e[8] !== s ? (f = (h) => {
393
- const {
394
- ready$: g,
395
- variables: S
396
- } = h, $ = typeof s.mutationFn == "function" ? s.mutationFn(S) : s.mutationFn;
397
- return g.pipe(Te(at), me(), O(() => $));
398
- }, e[8] = s, e[9] = f) : f = e[9], i = {
399
- ...s,
400
- onMutate: u,
401
- onSuccess(h, g, ...S) {
402
- const {
403
- variables: $
404
- } = g, _ = S;
405
- return s.onSuccess?.(h, $, ..._);
406
- },
407
- onError(h, g, ...S) {
408
- const {
409
- variables: $
410
- } = g, _ = S;
411
- return s.onError?.(h, $, ..._);
412
- },
413
- onSettled(h, g, S, ...$) {
414
- const {
415
- variables: _
416
- } = S, F = $;
417
- return s.onSettled?.(h, g, _, ...F);
418
- },
419
- mutationFn: f
420
- }, e[5] = s, e[6] = u, e[7] = i;
421
- } else
422
- i = e[7];
423
- const a = $e(i, t);
424
- let p, l;
425
- e[10] !== a ? ({
426
- mutateAsync: p,
427
- ...l
428
- } = a, e[10] = a, e[11] = p, e[12] = l) : (p = e[11], l = e[12]);
429
- let y;
430
- e[13] !== o || e[14] !== p || e[15] !== c ? (y = async (f) => {
431
- const h = o.getMutationCache().findAll({
432
- mutationKey: c,
433
- exact: !0
434
- }), g = new V(!1), S = p({
435
- variables: f,
436
- ready$: g
437
- });
438
- return await Promise.all(h.map(ut)), g.next(!0), await S.finally(() => {
439
- g.complete();
440
- });
441
- }, e[13] = o, e[14] = p, e[15] = c, e[16] = y) : y = e[16];
442
- const m = y;
443
- let v;
444
- e[17] !== m ? (v = (f) => {
445
- m(f).catch(be);
446
- }, e[17] = m, e[18] = v) : v = e[18];
447
- const d = v;
448
- let b;
449
- return e[19] !== m || e[20] !== d || e[21] !== l ? (b = {
450
- ...l,
451
- mutate: d,
452
- mutateAsync: m
453
- }, e[19] = m, e[20] = d, e[21] = l, e[22] = b) : b = e[22], b;
454
- }
455
- function ut(r) {
456
- return r.continue().catch(be);
457
- }
458
- function at(r) {
459
- return r;
460
- }
461
- function Kt(r, t) {
462
- const e = E(10);
463
- let n, s;
464
- e[0] !== r ? ({
465
- queryFn: s,
466
- ...n
467
- } = r, e[0] = r, e[1] = n, e[2] = s) : (n = e[1], s = e[2]);
468
- const o = ge(t), c = ct();
469
- let u;
470
- e[3] !== o || e[4] !== c || e[5] !== s ? (u = (l) => new Promise((y, m) => {
471
- const v = () => W(() => typeof s == "function" ? s(l) : s), d = ve(l.queryKey), b = c.getQuery(d), f = b ?? c.setQuery(l.queryKey, v(), l.signal), h = () => {
472
- f?.isCompleted === !1 && setTimeout(() => {
473
- o?.refetchQueries({
474
- queryKey: l.queryKey,
475
- exact: !0
476
- });
477
- });
478
- };
479
- if (!b && f.lastData !== void 0) {
480
- y(f.lastData.value), h();
481
- return;
482
- }
483
- f.query$.pipe(pe(1), Oe(1)).subscribe({
484
- error: (S) => m(S),
485
- complete: () => {
486
- if (f?.lastData === void 0)
487
- return f.signal.aborted || (console.log(`cancelled due to stream completing without data for query ${d}`, f?.lastData), o.cancelQueries({
488
- queryKey: l.queryKey,
489
- exact: !0
490
- })), y(void 0);
491
- y(f.lastData.value), h();
492
- }
493
- });
494
- }), e[3] = o, e[4] = c, e[5] = s, e[6] = u) : u = e[6];
495
- const i = u;
496
- let a;
497
- return e[7] !== n || e[8] !== i ? (a = {
498
- ...n,
499
- queryFn: i
500
- }, e[7] = n, e[8] = i, e[9] = a) : a = e[9], We(a, t);
501
- }
502
- class _e extends Error {
503
- constructor(t = "Mutation canceled") {
504
- super(t), this.name = "SwitchMutationCancelError";
505
- }
506
- }
507
- function jt(r, t) {
508
- const e = E(37);
509
- let n, s, o, c, u;
510
- e[0] !== r ? ({
511
- mutationFn: n,
512
- onMutate: o,
513
- onError: s,
514
- onSettled: c,
515
- ...u
516
- } = r, e[0] = r, e[1] = n, e[2] = s, e[3] = o, e[4] = c, e[5] = u) : (n = e[1], s = e[2], o = e[3], c = e[4], u = e[5]);
517
- const i = H(ft);
518
- let a;
519
- e[6] !== n ? (a = (I) => {
520
- const {
521
- variables: M,
522
- abort: C
523
- } = I;
524
- if (C.aborted)
525
- throw new _e();
526
- const x = typeof n == "function" ? n(M) : n;
527
- return A(x, de(C, "abort").pipe(X(lt), Qe())).pipe(me(), ke(null));
528
- }, e[6] = n, e[7] = a) : a = e[7];
529
- const p = a;
530
- let l;
531
- e[8] !== o ? (l = o ? (I, ...M) => {
532
- const {
533
- variables: C
534
- } = I;
535
- return o(C, ...M);
536
- } : void 0, e[8] = o, e[9] = l) : l = e[9];
537
- let y;
538
- e[10] !== u ? (y = (I, M, ...C) => {
539
- const {
540
- variables: x
541
- } = M, k = C;
542
- return u.onSuccess?.(I, x, ...k);
543
- }, e[10] = u, e[11] = y) : y = e[11];
544
- let m;
545
- e[12] !== s ? (m = (I, M, ...C) => {
546
- const {
547
- variables: x
548
- } = M;
549
- return s?.(I, x, ...C);
550
- }, e[12] = s, e[13] = m) : m = e[13];
551
- let v;
552
- e[14] !== c ? (v = (I, M, C, ...x) => {
553
- const {
554
- variables: k
555
- } = C;
556
- return c?.(I, M, k, ...x);
557
- }, e[14] = c, e[15] = v) : v = e[15];
558
- let d;
559
- e[16] !== u || e[17] !== p || e[18] !== l || e[19] !== y || e[20] !== m || e[21] !== v ? (d = {
560
- ...u,
561
- mutationFn: p,
562
- onMutate: l,
563
- onSuccess: y,
564
- onError: m,
565
- onSettled: v
566
- }, e[16] = u, e[17] = p, e[18] = l, e[19] = y, e[20] = m, e[21] = v, e[22] = d) : d = e[22];
567
- const b = $e(d, t);
568
- let f, h, g;
569
- e[23] !== b ? ({
570
- mutate: f,
571
- mutateAsync: h,
572
- ...g
573
- } = b, e[23] = b, e[24] = f, e[25] = h, e[26] = g) : (f = e[24], h = e[25], g = e[26]);
574
- let S;
575
- e[27] !== f || e[28] !== i ? (S = (I) => (i.current.abort(), i.current = new AbortController(), f({
576
- variables: I,
577
- abort: i.current.signal
578
- })), e[27] = f, e[28] = i, e[29] = S) : S = e[29];
579
- const $ = S;
580
- let _;
581
- e[30] !== h || e[31] !== i ? (_ = (I) => (i.current.abort(), i.current = new AbortController(), h({
582
- variables: I,
583
- abort: i.current.signal
584
- })), e[30] = h, e[31] = i, e[32] = _) : _ = e[32];
585
- const F = _;
586
- let Q;
587
- return e[33] !== F || e[34] !== $ || e[35] !== g ? (Q = {
588
- ...g,
589
- mutate: $,
590
- mutateAsync: F
591
- }, e[33] = F, e[34] = $, e[35] = g, e[36] = Q) : Q = e[36], Q;
592
- }
593
- function lt() {
594
- throw new _e();
595
- }
596
- function ft() {
597
- return new AbortController();
598
- }
599
- const yt = /* @__PURE__ */ Symbol("SIGNAL_RESET"), Lt = (r) => ({
600
- getItem: async (t) => {
601
- const e = await r.getItem(t);
602
- if (e)
603
- return JSON.parse(e);
604
- },
605
- setItem: async (t, e) => {
606
- await r.setItem(t, JSON.stringify(e));
607
- },
608
- removeItem: async (t) => {
609
- },
610
- clear: async () => {
611
- }
612
- }), z = (r) => {
613
- if (!(!r || typeof r != "object"))
614
- return r;
615
- }, dt = ({
616
- adapter: r,
617
- key: t
618
- }) => ({
619
- clear: async () => await r.removeItem(t),
620
- removeItem: async (e) => {
621
- const n = await r.getItem(t), {
622
- [e]: s,
623
- ...o
624
- } = (
625
- // biome-ignore lint/suspicious/noExplicitAny: TODO
626
- z(n) ?? {}
627
- );
628
- await r.setItem(t, o);
629
- },
630
- getItem: async (e) => {
631
- const n = await r.getItem(t), s = z(n) ?? {};
632
- if (e in s)
633
- return s[e];
634
- },
635
- setItem: async (e, n) => {
636
- const s = await r.getItem(t), o = z(s) ?? {};
637
- await r.setItem(t, {
638
- ...o,
639
- [e]: n
640
- });
641
- }
642
- }), pt = ({
643
- key: r
644
- } = {}) => r ? dt({
645
- adapter: pt(),
646
- key: r
647
- }) : {
648
- clear: async () => {
649
- localStorage.clear();
650
- },
651
- removeItem: async (t) => {
652
- localStorage.removeItem(t);
653
- },
654
- getItem: async (t) => {
655
- const e = localStorage.getItem(t);
656
- if (e)
657
- return JSON.parse(e);
658
- },
659
- setItem: async (t, e) => {
660
- localStorage.setItem(t, JSON.stringify(e));
661
- }
662
- };
663
- class Ce extends V {
664
- constructor(t) {
665
- super(t.default), this.config = t;
666
- }
667
- update = (t) => {
668
- if (t === yt)
669
- super.next(this.config.default);
670
- else if (typeof t == "function") {
671
- const e = t;
672
- super.next(e(this.value));
673
- } else
674
- super.next(t);
675
- };
676
- /**
677
- * @deprecated Use `next` instead
678
- */
679
- setValue = this.update.bind(this);
680
- /**
681
- * @deprecated Use `this` instead
682
- */
683
- get subject() {
684
- return this;
685
- }
686
- get key() {
687
- return this.config.key;
688
- }
689
- }
690
- class J {
691
- constructor(t) {
692
- this.config = t;
693
- }
694
- }
695
- function zt(r = {}) {
696
- return new Ce({
697
- key: void 0,
698
- ...r,
699
- default: r.default ?? void 0
700
- });
701
- }
702
- function Yt(r) {
703
- return new J(r);
704
- }
705
- class U {
706
- /**
707
- * items only get added as they are created. The only time we should cleanup
708
- * are on context destroy. This is to ensure later re-use of virtual signals
709
- * return the same persisted state.
710
- */
711
- // biome-ignore lint/suspicious/noExplicitAny: TODO
712
- signals = new V(/* @__PURE__ */ new Map());
713
- isDestroyed = !1;
714
- getOrCreateSignal(t) {
715
- const e = this.signals.value.get(t);
716
- if (e)
717
- return e;
718
- const n = new Ce({
719
- ...t.config,
720
- key: void 0
721
- });
722
- return this.signals.value.set(t, n), this.signals.next(this.signals.value), n;
723
- }
724
- destroy() {
725
- this.signals.value.forEach((t) => {
726
- t.complete();
727
- }), this.signals.value.clear(), this.signals.complete(), this.isDestroyed = !0;
728
- }
729
- }
730
- const Me = ue(new U()), Jt = ae(({
731
- children: r
732
- }) => {
733
- const t = H(() => new U()), e = t.current, [n, s] = G(!1);
734
- n && (t.current = new U(), s(!1));
735
- const o = e;
736
- return N(() => () => {
737
- t.current?.destroy(), s(!0);
738
- }, [t]), /* @__PURE__ */ he(Me.Provider, { value: o, children: r });
739
- }), xe = () => le(Me), mt = (r) => {
740
- const t = E(3), e = xe();
741
- let n;
742
- return t[0] !== e || t[1] !== r ? (n = r ? e.getOrCreateSignal(r) : void 0, t[0] = e, t[1] = r, t[2] = n) : n = t[2], n;
743
- };
744
- function bt(r, t) {
745
- if (r == null || t === void 0 || typeof r != "object" || typeof t != "object")
746
- return r === t;
747
- if (r.constructor !== t?.constructor)
748
- return !1;
749
- const e = Object.keys(r), n = Object.keys(t);
750
- if (e.length !== n.length)
751
- return !1;
752
- for (const s of e)
753
- if (!t.hasOwnProperty(s) || r[s] !== t[s])
754
- return !1;
755
- return !0;
756
- }
757
- const P = "__reactjrx", ht = (r) => {
758
- if (typeof r == "object" && r !== null && P in r && r[P] === P)
759
- return r;
760
- }, vt = ({
761
- adapter: r,
762
- config: t
763
- }) => {
764
- const {
765
- signal: e,
766
- version: n
767
- } = t, o = {
768
- value: e.getValue(),
769
- [P]: P,
770
- migrationVersion: n
771
- };
772
- return process.env.NODE_ENV === "development" && console.log("[reactjrx][state][persistance]:", "Persist value", o, `for signal ${e.config.key}`), T(r.setItem(e.config.key, o)).pipe(D((c) => (console.error(c), w(null))));
773
- };
774
- function gt({
775
- adapter: r,
776
- config: t
777
- }) {
778
- const {
779
- hydrate: e = ({
780
- value: o
781
- }) => o,
782
- signal: n,
783
- version: s
784
- } = t;
785
- return T(r.getItem(n.config.key)).pipe(O((o) => {
786
- const c = ht(o);
787
- if (!c) return w(o);
788
- const u = typeof c.migrationVersion != "number", i = c.migrationVersion !== void 0 && s > c.migrationVersion;
789
- if (u || i || c.value === void 0)
790
- return w(o);
791
- const a = c.value;
792
- return process.env.NODE_ENV === "development" && console.log("[reactjrx][state][persistance]:", "Hydrate value", c, `for signal ${n.config.key}`), n.setValue(e({
793
- value: a,
794
- version: s
795
- })), w(o);
796
- }));
797
- }
798
- function St({
799
- entries: r = [],
800
- onHydrated: t,
801
- adapter: e
802
- }) {
803
- const s = (r.length === 0 ? w([]) : De(...r.map((c) => gt({
804
- adapter: e,
805
- config: c
806
- })))).pipe(X(t), D((c) => (console.error("Unable to hydrate", c), ye)), Z()), o = s.pipe(O(() => A(...r.map((c) => c.signal.pipe(He(500, Ke, {
807
- trailing: !0
808
- }), O(() => T(vt({
809
- adapter: e,
810
- config: c
811
- }))))))));
812
- return A(s.pipe(Y(() => ({
813
- type: "hydrated"
814
- }))), o.pipe(Y(() => ({
815
- type: "persisted"
816
- }))));
817
- }
818
- function Ut(r) {
819
- const t = E(10), {
820
- entries: e,
821
- onHydrated: n,
822
- adapter: s
823
- } = r;
824
- let o;
825
- t[0] !== e ? (o = e === void 0 ? [] : e, t[0] = e, t[1] = o) : o = t[1];
826
- const c = o, u = q(n), i = oe(s), a = oe(c);
827
- let p;
828
- t[2] !== i || t[3] !== a || t[4] !== u ? (p = () => i.pipe(O((d) => d ? A(w({
829
- type: "reset"
830
- }), a.pipe(je((b) => St({
831
- adapter: d,
832
- entries: b,
833
- onHydrated: () => {
834
- u.current?.();
835
- }
836
- })))) : w({
837
- type: "reset"
838
- }))).pipe(Le(Et, {
839
- isHydrated: !1
840
- })), t[2] = i, t[3] = a, t[4] = u, t[5] = p) : p = t[5];
841
- let l;
842
- t[6] === /* @__PURE__ */ Symbol.for("react.memo_cache_sentinel") ? (l = {
843
- defaultValue: {
844
- isHydrated: !1
845
- },
846
- compareFn: bt
847
- }, t[6] = l) : l = t[6];
848
- let y;
849
- return t[7] !== i || t[8] !== a ? (y = [i, a], t[7] = i, t[8] = a, t[9] = y) : y = t[9], Ee(p, l, y).data;
850
- }
851
- function Et(r, t) {
852
- return t.type === "reset" ? {
853
- isHydrated: !1
854
- } : t.type === "hydrated" ? {
855
- isHydrated: !0
856
- } : r;
857
- }
858
- function B(r) {
859
- const t = xe();
860
- if (r instanceof J && !t)
861
- throw new Error("useSignalValue must be used within a SignalContextProvider");
862
- return mt(r instanceof J ? r : void 0) ?? r;
863
- }
864
- function It(r) {
865
- return B(r).update;
866
- }
867
- function Ne(r, t) {
868
- const e = E(10), n = q(t), s = B(r);
869
- let o;
870
- e[0] !== s || e[1] !== n ? (o = () => {
871
- const a = n.current ?? wt;
872
- return s.pipe(Y(a), fe());
873
- }, e[0] = s, e[1] = n, e[2] = o) : o = e[2];
874
- let c;
875
- e[3] !== s.value || e[4] !== t ? (c = t ? t?.(s.value) : s.value, e[3] = s.value, e[4] = t, e[5] = c) : c = e[5];
876
- let u;
877
- e[6] !== c ? (u = {
878
- defaultValue: c
879
- }, e[6] = c, e[7] = u) : u = e[7];
880
- let i;
881
- return e[8] !== s ? (i = [s], e[8] = s, e[9] = i) : i = e[9], Ee(o, u, i).data;
882
- }
883
- function wt(r) {
884
- return r;
885
- }
886
- function Gt(r) {
887
- const t = E(4), e = B(r), n = Ne(r), s = It(r);
888
- let o;
889
- return t[0] !== e || t[1] !== s || t[2] !== n ? (o = [n, s, e], t[0] = e, t[1] = s, t[2] = n, t[3] = o) : o = t[3], o;
890
- }
891
- const Wt = (r) => {
892
- const t = E(3), e = K(r), n = Ne(e);
893
- let s;
894
- return t[0] !== e || t[1] !== n ? (s = [n, e], t[0] = e, t[1] = n, t[2] = s) : s = t[2], s;
895
- };
896
- export {
897
- we as Context,
898
- ot as QueryClient$,
899
- Dt as QueryClientProvider$,
900
- yt as SIGNAL_RESET,
901
- Ce as Signal,
902
- Jt as SignalContextProvider,
903
- Me as SignalReactContext,
904
- _e as SwitchMutationCancelError,
905
- J as VirtualSignal,
906
- Xe as arrayEqual,
907
- pt as createLocalStorageAdapter,
908
- Lt as createLocalforageAdapter,
909
- Be as exponentialBackoffDelay,
910
- Ze as getDelay,
911
- qt as isDefined,
912
- ce as isPromiseLike,
913
- Ft as isServer,
914
- Pt as retryBackoff,
915
- zt as signal,
916
- K as useConstant,
917
- Ht as useContactMutation$,
918
- Tt as useDebounced,
919
- Se as useEffectOnce,
920
- oe as useLiveBehaviorSubject,
921
- q as useLiveRef,
922
- mt as useMakeOrRetrieveSignal,
923
- Ot as useMemoCompare,
924
- Qt as useMount,
925
- $e as useMutation$,
926
- Rt as useObservableState,
927
- Ee as useObserve,
928
- Ut as usePersistSignals,
929
- Kt as useQuery$,
930
- ct as useQueryClient$,
931
- H as useRefOnce,
932
- It as useSetSignal,
933
- Gt as useSignal,
934
- xe as useSignalContext,
935
- Wt as useSignalState,
936
- Ne as useSignalValue,
937
- nt as useSubscribe,
938
- kt as useSubscribeEffect,
939
- jt as useSwitchMutation$,
940
- et as useUnmount,
941
- At as useUnmountObservable,
942
- Yt as virtualSignal
943
- };
1
+ import{c as e}from"react/compiler-runtime";import{useRef as t,useEffect as r,useMemo as n,useState as o,useSyncExternalStore as s,useCallback as a,createContext as c,memo as u,useContext as i}from"react";import{BehaviorSubject as l,of as p,defer as f,merge as y,throwError as d,timer as m,ReplaySubject as v,NEVER as b,distinctUntilChanged as g,tap as h,share as w,isObservable as I,from as S,catchError as E,EMPTY as x,retry as N,identity as F,takeUntil as V,fromEvent as q,take as M,filter as A,first as O,switchMap as P,noop as k,delay as D,ignoreElements as j,defaultIfEmpty as T,zip as $,throttleTime as _,asyncScheduler as C,map as Q,concatMap as H,scan as K}from"rxjs";import{catchError as J,mergeMap as Y,retryWhen as R,concatMap as U,first as G,tap as L}from"rxjs/operators";import{jsx as z}from"react/jsx-runtime";import{hashKey as B,useMutation as W,useQueryClient as X,useQuery as Z}from"@tanstack/react-query";const ee=/* @__PURE__ */Symbol("UNSET"),te=e=>{const r=t(ee);return r.current===ee&&(r.current=e()),r},re=e=>te(e).current,ne=t=>{const n=e(6);let o;n[0]!==t?(o=()=>new l(t),n[0]=t,n[1]=o):o=n[1];const s=re(o);let a,c;return n[2]!==t||n[3]!==s?(a=()=>{s.next(t)},c=[t,s],n[2]=t,n[3]=s,n[4]=a,n[5]=c):(a=n[4],c=n[5]),r(a,c),s},oe=e=>{const r=t(e);return n(()=>{r.current=e},[e]),r},se=t=>{const r=e(10);let n;r[0]!==t?(n=()=>new l(t),r[0]=t,r[1]=n):n=r[1];const o=re(n),s=oe(o);let a;r[2]!==o?(a=e=>{o.next(e)},r[2]=o,r[3]=a):a=r[3];const c=a,u=s.current;let i,p;return r[4]!==o?(i=o.getValue(),r[4]=o,r[5]=i):i=r[5],r[6]!==c||r[7]!==s.current||r[8]!==i?(p=[u,c,i],r[6]=c,r[7]=s.current,r[8]=i,r[9]=p):p=r[9],p},ae=(e,t)=>e.length===t.length&&e.every((e,r)=>e===t[r]);function ce(e){return null!=e}function ue(e){return e instanceof Promise||e&&"object"==typeof e&&"then"in e&&"function"==typeof e.then&&"catch"in e&&"function"===e.catch}const ie="undefined"==typeof window||"Deno"in window;function le(e,t){return Math.min(e,t)}function pe(e,t){return 2**e*t}function fe(e){const{retry:t,retryDelay:r,retryAfterDelay:n,retryAfter:o=()=>p(!0)}=e,s="function"!=typeof t?!1===t?0:!0===t?Number.POSITIVE_INFINITY:t??Number.POSITIVE_INFINITY:Number.POSITIVE_INFINITY,a="function"==typeof t?t:()=>!0,c="number"==typeof r?r:100,u={...e},{maxInterval:i=Number.POSITIVE_INFINITY,resetOnSuccess:l=!1,backoffDelay:v=pe}=u;return t=>f(()=>{let r=0;const u=(e,t)=>e<s&&a(e,t);return t.pipe(J(t=>{if(r++,!u(r-1,t))throw t;const n=e.caughtError?.(r,t);if(!n)throw t;return n.pipe(Y(e=>y(p(e),d(()=>t))))}),R(e=>e.pipe(U(e=>{const t=r-1;return o().pipe(G(),Y(()=>u(t,e)?m(le(v(t,c),i)).pipe(Y(r=>n&&!n(t,e)?d(()=>e):p(r))):d(()=>e)))}))),J(t=>{if(e.catchError)return e.catchError(r,t);throw t}),L(()=>{l&&(r=0)}))})}const ye=()=>{const e=te(()=>new v(1)),[t,n]=o(!1);return t&&(e.current=new v(1),n(!1)),r(()=>()=>{e.current.next(void 0),n(!0)},[e]),e.current},de=t=>{const n=e(1);let o;n[0]===/* @__PURE__ */Symbol.for("react.memo_cache_sentinel")?(o=[],n[0]=o):o=n[0],r(t,o)},me=e=>{const r=t(e);r.current=e,de(()=>()=>r.current())},ve=(r,n,o)=>{const s=e(7);let a;s[0]!==o?(a=void 0===o?{}:o,s[0]=o,s[1]=a):a=s[1];const c=a,{cancelOnUnmount:u}=c,i=void 0!==u&&u,l=t(null);let p;s[2]!==r||s[3]!==n?(p=e=>{null!==l.current&&clearTimeout(l.current),l.current=setTimeout(()=>r(e),n)},s[2]=r,s[3]=n,s[4]=p):p=s[4];const f=p;let y;return s[5]!==i?(y=()=>{i&&l.current&&clearTimeout(l.current)},s[5]=i,s[6]=y):y=s[6],me(y),f},be=(e,r)=>{const o=t({value:e});return n(()=>r(e,o.current.value)?o.current.value:(o.current={value:e},e),[e,r])},ge=t=>{const r=e(2);let n;r[0]!==t?(n=()=>{t()},r[0]=t,r[1]=n):n=r[1],de(n)};class he{state;source$;sub;constructor({source$:e,defaultValue:t,compareFn:r}){const n="function"==typeof e?e():e,o=void 0===n;this.state={data:n instanceof l?n.value:t,status:o?"success":"pending",observableState:o?"complete":"live",error:void 0},this.source$=(n??b).pipe(g(r),h({complete:()=>{this.state={...this.state,status:"success",observableState:"complete"}},error:e=>{this.state={...this.state,observableState:"error",status:"error",error:e}},next:e=>{this.state={...this.state,data:e}}}),w()),this.sub=this.source$.subscribe()}subscribe=e=>{if("complete"===this.state.observableState)return()=>{};const t=this.source$.subscribe({complete:e,error:e,next:e});return()=>{t.unsubscribe()}};getSnapshot=()=>this.state}function we(n,o,a){const c=e(6);let u;c[0]!==o?(u=null==o||Array.isArray(o)?{defaultValue:void 0,compareFn:void 0}:o,c[0]=o,c[1]=u):u=c[1];const i=u;let l;c[2]!==a||c[3]!==o||c[4]!==n?(l=!a&&Array.isArray(o)?o:"function"==typeof n?a??[]:[n],c[2]=a,c[3]=o,c[4]=n,c[5]=l):l=c[5];const p=((e,n,o)=>{const s=oe(n),a=t(void 0);a.current&&ae([...o],[...a.current.deps])||(a.current={deps:o,store:new he({source$:e,defaultValue:s.current.defaultValue,compareFn:(e,t)=>s.current?.compareFn?.(e,t)??e===t})});const c=a.current.store;return r(()=>()=>{c.sub.unsubscribe()},[c]),c})(n,i,l);return s(p.subscribe,p.getSnapshot,p.getSnapshot)}function Ie(e){if(I(e))return()=>e;if(ue(e))return()=>S(e);if("function"!=typeof e)return()=>p(e);const t=e;return e=>f(()=>{const r=t(e);return ue(r)?S(r):I(r)?r:p(r)})}function Se(t,n){const o=e(7);let s;o[0]!==n?(s=void 0===n?[]:n,o[0]=n,o[1]=s):s=o[1];const a=s,c=oe(t);let u,i;o[2]!==c?(u=()=>{const e=Ie(c.current)().pipe(E(Ee)).subscribe();return()=>{e.unsubscribe()}},o[2]=c,o[3]=u):u=o[3],o[4]!==a||o[5]!==c?(i=[...a,c],o[4]=a,o[5]=c,o[6]=i):i=o[6],r(u,i)}function Ee(e){return console.error(e),x}function xe(e,t,r=[]){const n=null==t||Array.isArray(t)?{}:t,o=n.retry??!0,s=oe(n.onError??(e=>{console.error(e)})),c=a(()=>Ie(e)(),r);Se(a(()=>c().pipe(E(e=>{throw s.current(e),e}),o?N():F),[c,o,s]),r)}class Ne{queryMap=/* @__PURE__ */new Map;getQuery(e){return this.queryMap.get(e)}setQuery(e,t,r){const n=B(e),o=t.pipe(V(q(r,"abort")),w()),s={query$:o,signal:r,sub:void 0,isCompleted:!1,lastData:void 0};this.queryMap.set(n,s);const a=o.subscribe({next:e=>{const t=this.queryMap.get(n);t&&(t.lastData={value:e})},complete:()=>{this.deleteQuery(n)}});return s.sub=a,s}deleteQuery(e){const t=this.queryMap.get(e);t&&(t.sub&&(t.sub.unsubscribe(),t.sub=void 0),t.isCompleted=!0,this.queryMap.delete(e))}destroy(){this.queryMap.forEach((e,t)=>{this.deleteQuery(t)})}}const Fe=c(void 0),Ve=u(t=>{const n=e(8),{children:s,client:a}=t;let c;n[0]!==a?(c=()=>a??new Ne,n[0]=a,n[1]=c):c=n[1];const[u]=o(c);let i,l,p;return n[2]!==u?(i=()=>()=>{u.destroy()},l=[u],n[2]=u,n[3]=i,n[4]=l):(i=n[3],l=n[4]),r(i,l),n[5]!==s||n[6]!==u?(p=/* @__PURE__ */z(Fe.Provider,{value:u,children:s}),n[5]=s,n[6]=u,n[7]=p):p=n[7],p}),qe=()=>{const e=i(Fe);if(!e)throw new Error("useReactJrxQueryClient must be used within a ReactJrxQueryProvider");return e};function Me(t,n){const o=e(16),s=re(Ae);let a,c;o[0]!==t?(a=e=>{let r;return new Promise((n,o)=>{("function"==typeof t.mutationFn?t.mutationFn(e):t.mutationFn).pipe(M(1)).subscribe({next:e=>{r={value:e}},error:e=>{o(e)},complete:()=>{if(void 0===r)return o(new Error("Stream completed without any data"));n(r.value)}})})},o[0]=t,o[1]=a):a=o[1],o[2]!==t||o[3]!==a?(c={...t,mutationFn:a},o[2]=t,o[3]=a,o[4]=c):c=o[4];const u=W(c,n),{status:i,isPending:l,isError:p,isSuccess:f,isIdle:y}=u;let d,m,v;return o[5]!==p||o[6]!==y||o[7]!==l||o[8]!==f||o[9]!==s||o[10]!==i?(d=()=>{s.next({status:i,isPending:l,isError:p,isSuccess:f,isIdle:y})},m=[i,l,p,f,y,s],o[5]=p,o[6]=y,o[7]=l,o[8]=f,o[9]=s,o[10]=i,o[11]=d,o[12]=m):(d=o[11],m=o[12]),r(d,m),o[13]!==u||o[14]!==s?(v={...u,state$:s},o[13]=u,o[14]=s,o[15]=v):v=o[15],v}function Ae(){return new l({status:"idle",isPending:!1,isError:!1,isSuccess:!1,isIdle:!0})}function Oe(t,r){const n=e(23);let o,s;n[0]!==t?(({onMutate:o,...s}=t),n[0]=t,n[1]=o,n[2]=s):(o=n[1],s=n[2]);const a=X(r),c=s.mutationKey;let u,i;if(n[3]!==o?(u=o?(e,...t)=>{const{variables:r}=e;return o(r,...t)}:void 0,n[3]=o,n[4]=u):u=n[4],n[5]!==s||n[6]!==u){let e;n[8]!==s?(e=e=>{const{ready$:t,variables:r}=e,n="function"==typeof s.mutationFn?s.mutationFn(r):s.mutationFn;return t.pipe(A(ke),O(),P(()=>n))},n[8]=s,n[9]=e):e=n[9],i={...s,onMutate:u,onSuccess(e,t,...r){const{variables:n}=t,o=r;return s.onSuccess?.(e,n,...o)},onError(e,t,...r){const{variables:n}=t,o=r;return s.onError?.(e,n,...o)},onSettled(e,t,r,...n){const{variables:o}=r,a=n;return s.onSettled?.(e,t,o,...a)},mutationFn:e},n[5]=s,n[6]=u,n[7]=i}else i=n[7];const p=Me(i,r);let f,y,d;n[10]!==p?(({mutateAsync:f,...y}=p),n[10]=p,n[11]=f,n[12]=y):(f=n[11],y=n[12]),n[13]!==a||n[14]!==f||n[15]!==c?(d=async e=>{const t=a.getMutationCache().findAll({mutationKey:c,exact:!0}),r=new l(!1),n=f({variables:e,ready$:r});return await Promise.all(t.map(Pe)),r.next(!0),await n.finally(()=>{r.complete()})},n[13]=a,n[14]=f,n[15]=c,n[16]=d):d=n[16];const m=d;let v;n[17]!==m?(v=e=>{m(e).catch(k)},n[17]=m,n[18]=v):v=n[18];const b=v;let g;return n[19]!==m||n[20]!==b||n[21]!==y?(g={...y,mutate:b,mutateAsync:m},n[19]=m,n[20]=b,n[21]=y,n[22]=g):g=n[22],g}function Pe(e){return e.continue().catch(k)}function ke(e){return e}function De(t,r){const n=e(10);let o,s;n[0]!==t?(({queryFn:s,...o}=t),n[0]=t,n[1]=o,n[2]=s):(o=n[1],s=n[2]);const a=X(r),c=qe();let u;n[3]!==a||n[4]!==c||n[5]!==s?(u=e=>new Promise((t,r)=>{const n=B(e.queryKey),o=c.getQuery(n),u=o??c.setQuery(e.queryKey,f(()=>"function"==typeof s?s(e):s),e.signal),i=()=>{!1===u?.isCompleted&&setTimeout(()=>{a?.refetchQueries({queryKey:e.queryKey,exact:!0})})};if(!o&&void 0!==u.lastData)return t(u.lastData.value),void i();u.query$.pipe(M(1),D(1)).subscribe({error:e=>r(e),complete:()=>{if(void 0===u?.lastData)return u.signal.aborted||(console.log(`cancelled due to stream completing without data for query ${n}`,u?.lastData),a.cancelQueries({queryKey:e.queryKey,exact:!0})),t(void 0);t(u.lastData.value),i()}})}),n[3]=a,n[4]=c,n[5]=s,n[6]=u):u=n[6];const i=u;let l;n[7]!==o||n[8]!==i?(l={...o,queryFn:i},n[7]=o,n[8]=i,n[9]=l):l=n[9];return Z(l,r)}class je extends Error{constructor(e="Mutation canceled"){super(e),this.name="SwitchMutationCancelError"}}function Te(t,r){const n=e(37);let o,s,a,c,u;n[0]!==t?(({mutationFn:o,onMutate:a,onError:s,onSettled:c,...u}=t),n[0]=t,n[1]=o,n[2]=s,n[3]=a,n[4]=c,n[5]=u):(o=n[1],s=n[2],a=n[3],c=n[4],u=n[5]);const i=te(_e);let l;n[6]!==o?(l=e=>{const{variables:t,abort:r}=e;if(r.aborted)throw new je;const n="function"==typeof o?o(t):o;return y(n,q(r,"abort").pipe(h($e),j())).pipe(O(),T(null))},n[6]=o,n[7]=l):l=n[7];const p=l;let f,d,m,v,b;n[8]!==a?(f=a?(e,...t)=>{const{variables:r}=e;return a(r,...t)}:void 0,n[8]=a,n[9]=f):f=n[9],n[10]!==u?(d=(e,t,...r)=>{const{variables:n}=t,o=r;return u.onSuccess?.(e,n,...o)},n[10]=u,n[11]=d):d=n[11],n[12]!==s?(m=(e,t,...r)=>{const{variables:n}=t,o=r;return s?.(e,n,...o)},n[12]=s,n[13]=m):m=n[13],n[14]!==c?(v=(e,t,r,...n)=>{const{variables:o}=r,s=n;return c?.(e,t,o,...s)},n[14]=c,n[15]=v):v=n[15],n[16]!==u||n[17]!==p||n[18]!==f||n[19]!==d||n[20]!==m||n[21]!==v?(b={...u,mutationFn:p,onMutate:f,onSuccess:d,onError:m,onSettled:v},n[16]=u,n[17]=p,n[18]=f,n[19]=d,n[20]=m,n[21]=v,n[22]=b):b=n[22];const g=Me(b,r);let w,I,S,E;n[23]!==g?(({mutate:w,mutateAsync:I,...S}=g),n[23]=g,n[24]=w,n[25]=I,n[26]=S):(w=n[24],I=n[25],S=n[26]),n[27]!==w||n[28]!==i?(E=e=>(i.current.abort(),i.current=new AbortController,w({variables:e,abort:i.current.signal})),n[27]=w,n[28]=i,n[29]=E):E=n[29];const x=E;let N;n[30]!==I||n[31]!==i?(N=e=>(i.current.abort(),i.current=new AbortController,I({variables:e,abort:i.current.signal})),n[30]=I,n[31]=i,n[32]=N):N=n[32];const F=N;let V;return n[33]!==F||n[34]!==x||n[35]!==S?(V={...S,mutate:x,mutateAsync:F},n[33]=F,n[34]=x,n[35]=S,n[36]=V):V=n[36],V}function $e(){throw new je}function _e(){return new AbortController}const Ce=/* @__PURE__ */Symbol("SIGNAL_RESET"),Qe=e=>({getItem:async t=>{const r=await e.getItem(t);if(r)return JSON.parse(r)},setItem:async(t,r)=>{await e.setItem(t,JSON.stringify(r))},removeItem:async e=>{},clear:async()=>{}}),He=e=>{if(e&&"object"==typeof e)return e},Ke=({key:e}={})=>e?(({adapter:e,key:t})=>({clear:async()=>await e.removeItem(t),removeItem:async r=>{const n=await e.getItem(t),{[r]:o,...s}=He(n)??{};await e.setItem(t,s)},getItem:async r=>{const n=await e.getItem(t),o=He(n)??{};if(r in o)return o[r]},setItem:async(r,n)=>{const o=await e.getItem(t),s=He(o)??{};await e.setItem(t,{...s,[r]:n})}}))({adapter:Ke(),key:e}):{clear:async()=>{localStorage.clear()},removeItem:async e=>{localStorage.removeItem(e)},getItem:async e=>{const t=localStorage.getItem(e);if(t)return JSON.parse(t)},setItem:async(e,t)=>{localStorage.setItem(e,JSON.stringify(t))}};class Je extends l{constructor(e){super(e.default),this.config=e}update=e=>{if(e===Ce)super.next(this.config.default);else if("function"==typeof e){const t=e;super.next(t(this.value))}else super.next(e)};setValue=this.update.bind(this);get subject(){return this}get key(){return this.config.key}}class Ye{constructor(e){this.config=e}}function Re(e={}){return new Je({key:void 0,...e,default:e.default??void 0})}function Ue(e){return new Ye(e)}class Ge{signals=new l(/* @__PURE__ */new Map);isDestroyed=!1;getOrCreateSignal(e){const t=this.signals.value.get(e);if(t)return t;const r=new Je({...e.config,key:void 0});return this.signals.value.set(e,r),this.signals.next(this.signals.value),r}destroy(){this.signals.value.forEach(e=>{e.complete()}),this.signals.value.clear(),this.signals.complete(),this.isDestroyed=!0}}const Le=c(new Ge),ze=u(({children:e})=>{const t=te(()=>new Ge),n=t.current,[s,a]=o(!1);s&&(t.current=new Ge,a(!1));const c=n;return r(()=>()=>{t.current?.destroy(),a(!0)},[t]),/* @__PURE__ */z(Le.Provider,{value:c,children:e})}),Be=()=>i(Le),We=t=>{const r=e(3),n=Be();let o;r[0]!==n||r[1]!==t?(o=t?n.getOrCreateSignal(t):void 0,r[0]=n,r[1]=t,r[2]=o):o=r[2];return o};function Xe(e,t){if(null==e||void 0===t)return e===t;if("object"!=typeof e||"object"!=typeof t)return e===t;if(e.constructor!==t?.constructor)return!1;const r=Object.keys(e),n=Object.keys(t);if(r.length!==n.length)return!1;for(const o of r)if(!t.hasOwnProperty(o)||e[o]!==t[o])return!1;return!0}const Ze="__reactjrx";function et({adapter:e,config:t}){const{hydrate:r=({value:e})=>e,signal:n,version:o}=t;return S(e.getItem(n.config.key)).pipe(P(e=>{const t=(e=>{if("object"==typeof e&&null!==e&&Ze in e&&e[Ze]===Ze)return e})(e);if(!t)return p(e);const s="number"!=typeof t.migrationVersion,a=void 0!==t.migrationVersion&&o>t.migrationVersion;if(s||a||void 0===t.value)return p(e);const c=t.value;return"development"===process.env.NODE_ENV&&console.log("[reactjrx][state][persistance]:","Hydrate value",t,`for signal ${n.config.key}`),n.setValue(r({value:c,version:o})),p(e)}))}function tt({entries:e=[],onHydrated:t,adapter:r}){const n=(0===e.length?p([]):$(...e.map(e=>et({adapter:r,config:e})))).pipe(h(t),E(e=>(console.error("Unable to hydrate",e),x)),w()),o=n.pipe(P(()=>y(...e.map(e=>e.signal.pipe(_(500,C,{trailing:!0}),P(()=>S((({adapter:e,config:t})=>{const{signal:r,version:n}=t,o={value:r.getValue(),[Ze]:Ze,migrationVersion:n};return"development"===process.env.NODE_ENV&&console.log("[reactjrx][state][persistance]:","Persist value",o,`for signal ${r.config.key}`),S(e.setItem(r.config.key,o)).pipe(E(e=>(console.error(e),p(null))))})({adapter:r,config:e}))))))));return y(n.pipe(Q(()=>({type:"hydrated"}))),o.pipe(Q(()=>({type:"persisted"}))))}function rt(t){const r=e(10),{entries:n,onHydrated:o,adapter:s}=t;let a;r[0]!==n?(a=void 0===n?[]:n,r[0]=n,r[1]=a):a=r[1];const c=a,u=oe(o),i=ne(s),l=ne(c);let f,d,m;r[2]!==i||r[3]!==l||r[4]!==u?(f=()=>i.pipe(P(e=>e?y(p({type:"reset"}),l.pipe(H(t=>tt({adapter:e,entries:t,onHydrated:()=>{u.current?.()}})))):p({type:"reset"}))).pipe(K(nt,{isHydrated:!1})),r[2]=i,r[3]=l,r[4]=u,r[5]=f):f=r[5],r[6]===/* @__PURE__ */Symbol.for("react.memo_cache_sentinel")?(d={defaultValue:{isHydrated:!1},compareFn:Xe},r[6]=d):d=r[6],r[7]!==i||r[8]!==l?(m=[i,l],r[7]=i,r[8]=l,r[9]=m):m=r[9];return we(f,d,m).data}function nt(e,t){return"reset"===t.type?{isHydrated:!1}:"hydrated"===t.type?{isHydrated:!0}:e}function ot(e){const t=Be();if(e instanceof Ye&&!t)throw new Error("useSignalValue must be used within a SignalContextProvider");return We(e instanceof Ye?e:void 0)??e}function st(e){return ot(e).update}function at(t,r){const n=e(10),o=oe(r),s=ot(t);let a,c,u,i;return n[0]!==s||n[1]!==o?(a=()=>{const e=o.current??ct;return s.pipe(Q(e),g())},n[0]=s,n[1]=o,n[2]=a):a=n[2],n[3]!==s.value||n[4]!==r?(c=r?r?.(s.value):s.value,n[3]=s.value,n[4]=r,n[5]=c):c=n[5],n[6]!==c?(u={defaultValue:c},n[6]=c,n[7]=u):u=n[7],n[8]!==s?(i=[s],n[8]=s,n[9]=i):i=n[9],we(a,u,i).data}function ct(e){return e}function ut(t){const r=e(4),n=ot(t),o=at(t),s=st(t);let a;return r[0]!==n||r[1]!==s||r[2]!==o?(a=[o,s,n],r[0]=n,r[1]=s,r[2]=o,r[3]=a):a=r[3],a}const it=t=>{const r=e(3),n=re(t),o=at(n);let s;return r[0]!==n||r[1]!==o?(s=[o,n],r[0]=n,r[1]=o,r[2]=s):s=r[2],s};export{Fe as Context,Ne as QueryClient$,Ve as QueryClientProvider$,Ce as SIGNAL_RESET,Je as Signal,ze as SignalContextProvider,Le as SignalReactContext,je as SwitchMutationCancelError,Ye as VirtualSignal,ae as arrayEqual,Ke as createLocalStorageAdapter,Qe as createLocalforageAdapter,pe as exponentialBackoffDelay,le as getDelay,ce as isDefined,ue as isPromiseLike,ie as isServer,fe as retryBackoff,Re as signal,re as useConstant,Oe as useContactMutation$,ve as useDebounced,de as useEffectOnce,ne as useLiveBehaviorSubject,oe as useLiveRef,We as useMakeOrRetrieveSignal,be as useMemoCompare,ge as useMount,Me as useMutation$,se as useObservableState,we as useObserve,rt as usePersistSignals,De as useQuery$,qe as useQueryClient$,te as useRefOnce,st as useSetSignal,ut as useSignal,Be as useSignalContext,it as useSignalState,at as useSignalValue,Se as useSubscribe,xe as useSubscribeEffect,Te as useSwitchMutation$,me as useUnmount,ye as useUnmountObservable,Ue as virtualSignal};
944
2
  //# sourceMappingURL=index.js.map