reactjrx 1.129.0 → 1.130.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 (31) hide show
  1. package/dist/index.cjs +1 -1
  2. package/dist/index.cjs.map +1 -1
  3. package/dist/index.d.ts +4 -4
  4. package/dist/index.js +802 -687
  5. package/dist/index.js.map +1 -1
  6. package/dist/lib/binding/useObserve/store.d.ts +21 -0
  7. package/dist/lib/binding/useObserve/types.d.ts +5 -0
  8. package/dist/lib/binding/useObserve/useObserve.d.ts +15 -0
  9. package/dist/lib/binding/useObserve/useStore.d.ts +17 -0
  10. package/dist/lib/queries/useConcatMutation$.d.ts +1 -1
  11. package/dist/lib/queries/useMutation$.d.ts +18 -18
  12. package/dist/lib/queries/useQuery$.d.ts +1 -1
  13. package/dist/lib/queries/useSwitchMutation$.d.ts +9 -9
  14. package/dist/lib/state/Signal.d.ts +10 -2
  15. package/dist/lib/state/index.d.ts +1 -1
  16. package/dist/lib/state/persistence/constants.d.ts +1 -0
  17. package/dist/lib/state/{persistance → persistence}/helpers.d.ts +2 -2
  18. package/dist/lib/state/{persistance → persistence}/types.d.ts +3 -3
  19. package/dist/lib/state/react/usePersistSignals.d.ts +4 -4
  20. package/package.json +8 -6
  21. package/dist/lib/binding/useObserve.d.ts +0 -21
  22. package/dist/lib/state/persistance/constants.d.ts +0 -1
  23. /package/dist/lib/binding/{useObserve.compare.test.d.ts → useObserve/useObserve.compare.test.d.ts} +0 -0
  24. /package/dist/lib/binding/{useObserve.selector.test.d.ts → useObserve/useObserve.selector.test.d.ts} +0 -0
  25. /package/dist/lib/binding/{useObserve.test.d.ts → useObserve/useObserve.test.d.ts} +0 -0
  26. /package/dist/lib/state/{persistance → persistence}/adapters/Adapter.d.ts +0 -0
  27. /package/dist/lib/state/{persistance → persistence}/adapters/MockAdapter.d.ts +0 -0
  28. /package/dist/lib/state/{persistance → persistence}/adapters/createLocalStorageAdapter.d.ts +0 -0
  29. /package/dist/lib/state/{persistance → persistence}/adapters/createLocalforageAdapter.d.ts +0 -0
  30. /package/dist/lib/state/{persistance → persistence}/persistSignals.d.ts +0 -0
  31. /package/dist/lib/state/{persistance → persistence}/persistSignals.test.d.ts +0 -0
package/dist/index.js CHANGED
@@ -1,429 +1,649 @@
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
- });
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;
48
41
  }
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;
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";
61
44
  }
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();
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 () => {
103
172
  };
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();
173
+ const e = this.source$.subscribe({
174
+ complete: t,
175
+ error: t,
176
+ next: t
177
+ });
115
178
  return () => {
116
- n.unsubscribe();
179
+ e.unsubscribe();
117
180
  };
118
- }, [...t, r]);
181
+ };
182
+ getSnapshot = () => this.state;
119
183
  }
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);
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
124
192
  })
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;
193
+ });
194
+ const o = s.current.store;
195
+ return N(() => () => {
196
+ o.sub.unsubscribe();
197
+ }, [o]), o;
141
198
  };
142
- class je {
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 {
143
249
  queryMap = /* @__PURE__ */ new Map();
144
250
  getQuery(t) {
145
251
  return this.queryMap.get(t);
146
252
  }
147
- setQuery(t, r, n) {
148
- const s = ie(t), c = r.pipe(
253
+ setQuery(t, e, n) {
254
+ const s = ve(t), o = e.pipe(
149
255
  /**
150
256
  * abort signal is triggered on:
151
257
  * - manual cancellation from user
152
258
  * - unmounting the component
153
259
  * @see https://tanstack.com/query/latest/docs/framework/react/guides/query-cancellation
154
260
  */
155
- Ce(se(n, "abort")),
156
- ue()
157
- ), o = {
158
- query$: c,
261
+ Ae(de(n, "abort")),
262
+ Z()
263
+ ), c = {
264
+ query$: o,
159
265
  signal: n,
160
266
  sub: void 0,
161
267
  isCompleted: !1,
162
268
  lastData: void 0
163
269
  };
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 });
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
+ });
169
277
  },
170
278
  complete: () => {
171
279
  this.deleteQuery(s);
172
280
  }
173
281
  });
174
- return o.sub = l, o;
282
+ return c.sub = u, c;
175
283
  }
176
284
  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));
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));
179
287
  }
180
288
  destroy() {
181
- this.queryMap.forEach((t, r) => {
182
- this.deleteQuery(r);
289
+ this.queryMap.forEach((t, e) => {
290
+ this.deleteQuery(e);
183
291
  });
184
292
  }
185
293
  }
186
- const de = B(void 0), ft = ee(
187
- ({
294
+ const we = ue(void 0), Dt = ae((r) => {
295
+ const t = E(8), {
188
296
  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;
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;
203
313
  };
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
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
+ });
244
335
  });
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);
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, $, ..._);
256
406
  },
257
- onError(u, { variables: i }, ...a) {
258
- return e.onError?.(u, i, ...a);
407
+ onError(h, g, ...S) {
408
+ const {
409
+ variables: $
410
+ } = g, _ = S;
411
+ return s.onError?.(h, $, ..._);
259
412
  },
260
- onSettled(u, i, { variables: a }, ...y) {
261
- return e.onSettled?.(u, i, a, ...y);
413
+ onSettled(h, g, S, ...$) {
414
+ const {
415
+ variables: _
416
+ } = S, F = $;
417
+ return s.onSettled?.(h, g, _, ...F);
262
418
  },
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
- }
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
335
476
  });
336
- })
337
- },
338
- t
339
- );
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);
340
501
  }
341
- class Z extends Error {
502
+ class _e extends Error {
342
503
  constructor(t = "Mutation canceled") {
343
504
  super(t), this.name = "SwitchMutationCancelError";
344
505
  }
345
506
  }
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) => ({
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) => ({
386
600
  getItem: async (t) => {
387
- const r = await e.getItem(t);
388
- if (r)
389
- return JSON.parse(r);
601
+ const e = await r.getItem(t);
602
+ if (e)
603
+ return JSON.parse(e);
390
604
  },
391
- setItem: async (t, r) => {
392
- await e.setItem(t, JSON.stringify(r));
605
+ setItem: async (t, e) => {
606
+ await r.setItem(t, JSON.stringify(e));
393
607
  },
394
608
  removeItem: async (t) => {
395
609
  },
396
610
  clear: async () => {
397
611
  }
398
- }), O = (e) => {
399
- if (!(!e || typeof e != "object"))
400
- return e;
401
- }, Le = ({
402
- adapter: e,
612
+ }), z = (r) => {
613
+ if (!(!r || typeof r != "object"))
614
+ return r;
615
+ }, dt = ({
616
+ adapter: r,
403
617
  key: t
404
618
  }) => ({
405
- clear: async () => await e.removeItem(t),
406
- removeItem: async (r) => {
407
- const n = await e.getItem(t), { [r]: s, ...c } = (
619
+ clear: async () => await r.removeItem(t),
620
+ removeItem: async (e) => {
621
+ const n = await r.getItem(t), {
622
+ [e]: s,
623
+ ...o
624
+ } = (
408
625
  // biome-ignore lint/suspicious/noExplicitAny: TODO
409
- O(n) ?? {}
626
+ z(n) ?? {}
410
627
  );
411
- await e.setItem(t, c);
628
+ await r.setItem(t, o);
412
629
  },
413
- getItem: async (r) => {
414
- const n = await e.getItem(t), s = O(n) ?? {};
415
- if (r in s)
416
- return s[r];
630
+ getItem: async (e) => {
631
+ const n = await r.getItem(t), s = z(n) ?? {};
632
+ if (e in s)
633
+ return s[e];
417
634
  },
418
- setItem: async (r, n) => {
419
- const s = await e.getItem(t), c = O(s) ?? {};
420
- await e.setItem(t, { ...c, [r]: n });
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
+ });
421
641
  }
422
- }), Ye = ({
423
- key: e
424
- } = {}) => e ? Le({
425
- adapter: Ye(),
426
- key: e
642
+ }), pt = ({
643
+ key: r
644
+ } = {}) => r ? dt({
645
+ adapter: pt(),
646
+ key: r
427
647
  }) : {
428
648
  clear: async () => {
429
649
  localStorage.clear();
@@ -432,24 +652,24 @@ const Je = Symbol("SIGNAL_RESET"), pt = (e) => ({
432
652
  localStorage.removeItem(t);
433
653
  },
434
654
  getItem: async (t) => {
435
- const r = localStorage.getItem(t);
436
- if (r)
437
- return JSON.parse(r);
655
+ const e = localStorage.getItem(t);
656
+ if (e)
657
+ return JSON.parse(e);
438
658
  },
439
- setItem: async (t, r) => {
440
- localStorage.setItem(t, JSON.stringify(r));
659
+ setItem: async (t, e) => {
660
+ localStorage.setItem(t, JSON.stringify(e));
441
661
  }
442
662
  };
443
- class pe extends C {
663
+ class Ce extends V {
444
664
  constructor(t) {
445
665
  super(t.default), this.config = t;
446
666
  }
447
667
  update = (t) => {
448
- if (t === Je)
668
+ if (t === yt)
449
669
  super.next(this.config.default);
450
670
  else if (typeof t == "function") {
451
- const r = t;
452
- super.next(r(this.value));
671
+ const e = t;
672
+ super.next(e(this.value));
453
673
  } else
454
674
  super.next(t);
455
675
  };
@@ -467,35 +687,38 @@ class pe extends C {
467
687
  return this.config.key;
468
688
  }
469
689
  }
470
- class T {
690
+ class J {
471
691
  constructor(t) {
472
692
  this.config = t;
473
693
  }
474
694
  }
475
- function bt(e = {}) {
476
- return new pe({
695
+ function zt(r = {}) {
696
+ return new Ce({
477
697
  key: void 0,
478
- ...e,
479
- default: e.default ?? void 0
698
+ ...r,
699
+ default: r.default ?? void 0
480
700
  });
481
701
  }
482
- function gt(e) {
483
- return new T(e);
702
+ function Yt(r) {
703
+ return new J(r);
484
704
  }
485
- class Q {
705
+ class U {
486
706
  /**
487
707
  * items only get added as they are created. The only time we should cleanup
488
708
  * are on context destroy. This is to ensure later re-use of virtual signals
489
709
  * return the same persisted state.
490
710
  */
491
711
  // biome-ignore lint/suspicious/noExplicitAny: TODO
492
- signals = new C(/* @__PURE__ */ new Map());
712
+ signals = new V(/* @__PURE__ */ new Map());
493
713
  isDestroyed = !1;
494
714
  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 });
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
+ });
499
722
  return this.signals.value.set(t, n), this.signals.next(this.signals.value), n;
500
723
  }
501
724
  destroy() {
@@ -504,326 +727,218 @@ class Q {
504
727
  }), this.signals.value.clear(), this.signals.complete(), this.isDestroyed = !0;
505
728
  }
506
729
  }
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,
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,
528
762
  config: t
529
763
  }) => {
530
- const { signal: r, version: n } = t, c = {
531
- value: r.getValue(),
532
- [x]: x,
764
+ const {
765
+ signal: e,
766
+ version: n
767
+ } = t, o = {
768
+ value: e.getValue(),
769
+ [P]: P,
533
770
  migrationVersion: n
534
771
  };
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
- );
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))));
543
773
  };
544
- function Xe({
545
- adapter: e,
774
+ function gt({
775
+ adapter: r,
546
776
  config: t
547
777
  }) {
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
- );
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
+ }));
615
797
  }
616
798
  function St({
617
- entries: e = [],
799
+ entries: r = [],
618
800
  onHydrated: t,
619
- adapter: r
801
+ adapter: e
620
802
  }) {
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;
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
+ }))));
657
817
  }
658
- function Be(e) {
659
- return J(e).update;
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;
660
850
  }
661
- const vt = (e, t) => e.length === t.length && e.every((r, n) => r === t[n]);
662
- function It(e) {
663
- return e != null;
851
+ function Et(r, t) {
852
+ return t.type === "reset" ? {
853
+ isHydrated: !1
854
+ } : t.type === "hydrated" ? {
855
+ isHydrated: !0
856
+ } : r;
664
857
  }
665
- const wt = typeof window > "u" || "Deno" in window;
666
- function et(e, t) {
667
- return Math.min(e, t);
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;
668
863
  }
669
- function tt(e, t) {
670
- return 2 ** e * t;
864
+ function It(r) {
865
+ return B(r).update;
671
866
  }
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
- });
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;
733
882
  }
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
- );
883
+ function wt(r) {
884
+ return r;
772
885
  }
773
- function Vt(e) {
774
- const t = J(e), r = Se(e), n = Be(e);
775
- return [r, n, t];
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;
776
890
  }
777
- const Ft = (e) => {
778
- const t = q(e);
779
- return [Se(t), t];
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;
780
895
  };
781
896
  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
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
828
943
  };
829
944
  //# sourceMappingURL=index.js.map