reactjrx 1.117.1 → 1.120.1

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