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