reactjrx 1.118.0 → 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,69 +167,69 @@ 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() {
258
234
  /**
259
235
  * items only get added as they are created. The only time we should cleanup
@@ -261,14 +237,14 @@ class G {
261
237
  * return the same persisted state.
262
238
  */
263
239
  // biome-ignore lint/suspicious/noExplicitAny: <explanation>
264
- w(this, "signals", new F(/* @__PURE__ */ new Map()));
265
- w(this, "isDestroyed", !1);
240
+ I(this, "signals", new E(/* @__PURE__ */ new Map()));
241
+ I(this, "isDestroyed", !1);
266
242
  }
267
243
  getOrCreateSignal(t) {
268
244
  const r = this.signals.value.get(t);
269
245
  if (r)
270
246
  return r;
271
- const n = new le({ ...t.config, key: void 0 });
247
+ const n = new ye({ ...t.config, key: void 0 });
272
248
  return this.signals.value.set(t, n), this.signals.next(this.signals.value), n;
273
249
  }
274
250
  destroy() {
@@ -277,17 +253,20 @@ class G {
277
253
  }), this.signals.value.clear(), this.signals.complete(), this.isDestroyed = !0;
278
254
  }
279
255
  }
280
- const fe = X(void 0), St = Z(
256
+ const de = ee(void 0), ht = te(
281
257
  ({ children: e }) => {
282
- const t = _(() => new G());
283
- t.current.isDestroyed && (t.current = new G());
284
- const r = W(() => t.current, [t]);
285
- return b(() => () => {
286
- t.current.destroy();
287
- }, [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 });
288
267
  }
289
- ), ye = () => B(fe), ze = (e) => {
290
- const t = ye();
268
+ ), me = () => re(de), Le = (e) => {
269
+ const t = me();
291
270
  if (!t) {
292
271
  if (e)
293
272
  throw new Error(
@@ -296,7 +275,7 @@ const fe = X(void 0), St = Z(
296
275
  return;
297
276
  }
298
277
  const r = t.signals;
299
- return k(
278
+ return H(
300
279
  () => r.pipe(
301
280
  N(
302
281
  () => e ? t.getOrCreateSignal(e) : void 0
@@ -308,24 +287,24 @@ const fe = X(void 0), St = Z(
308
287
  [r]
309
288
  );
310
289
  };
311
- function H(e) {
312
- const t = ye();
313
- if (e instanceof A && !t)
290
+ function L(e) {
291
+ const t = me();
292
+ if (e instanceof q && !t)
314
293
  throw new Error(
315
294
  "useSignalValue must be used within a SignalContextProvider"
316
295
  );
317
- return ze(
318
- e instanceof A ? e : void 0
296
+ return Le(
297
+ e instanceof q ? e : void 0
319
298
  ) ?? e;
320
299
  }
321
- function Le(e, t) {
322
- const r = v(t), n = H(e);
323
- return k(
300
+ function Je(e, t) {
301
+ const r = b(t), n = L(e);
302
+ return H(
324
303
  () => {
325
- const s = r.current ?? ((u) => u);
304
+ const u = r.current ?? ((a) => a);
326
305
  return n.pipe(
327
- N(s),
328
- te()
306
+ N(u),
307
+ se()
329
308
  );
330
309
  },
331
310
  {
@@ -334,11 +313,11 @@ function Le(e, t) {
334
313
  [n]
335
314
  );
336
315
  }
337
- function Je(e) {
338
- return H(e).update;
316
+ function Ye(e) {
317
+ return L(e).update;
339
318
  }
340
319
  function vt(e) {
341
- const t = H(e), r = Le(e), n = Je(e);
320
+ const t = L(e), r = Je(e), n = Ye(e);
342
321
  return [r, n, t];
343
322
  }
344
323
  const bt = (e) => ({
@@ -354,33 +333,33 @@ const bt = (e) => ({
354
333
  },
355
334
  clear: async () => {
356
335
  }
357
- }), q = (e) => {
336
+ }), O = (e) => {
358
337
  if (!(!e || typeof e != "object"))
359
338
  return e;
360
- }, Ye = ({
339
+ }, je = ({
361
340
  adapter: e,
362
341
  key: t
363
342
  }) => ({
364
343
  clear: async () => await e.removeItem(t),
365
344
  removeItem: async (r) => {
366
- const n = await e.getItem(t), { [r]: s, ...c } = (
345
+ const n = await e.getItem(t), { [r]: u, ...c } = (
367
346
  // biome-ignore lint/suspicious/noExplicitAny: <explanation>
368
- q(n) ?? {}
347
+ O(n) ?? {}
369
348
  );
370
349
  await e.setItem(t, c);
371
350
  },
372
351
  getItem: async (r) => {
373
- const n = await e.getItem(t), s = q(n) ?? {};
374
- if (r in s)
375
- return s[r];
352
+ const n = await e.getItem(t), u = O(n) ?? {};
353
+ if (r in u)
354
+ return u[r];
376
355
  },
377
356
  setItem: async (r, n) => {
378
- const s = await e.getItem(t), c = q(s) ?? {};
357
+ const u = await e.getItem(t), c = O(u) ?? {};
379
358
  await e.setItem(t, { ...c, [r]: n });
380
359
  }
381
360
  }), Ue = ({
382
361
  key: e
383
- } = {}) => e ? Ye({
362
+ } = {}) => e ? je({
384
363
  adapter: Ue(),
385
364
  key: e
386
365
  }) : {
@@ -407,13 +386,13 @@ function Ge(e, t) {
407
386
  const r = Object.keys(e), n = Object.keys(t);
408
387
  if (r.length !== n.length)
409
388
  return !1;
410
- for (const s of r)
411
- if (!t.hasOwnProperty(s) || e[s] !== t[s])
389
+ for (const u of r)
390
+ if (!t.hasOwnProperty(u) || e[u] !== t[u])
412
391
  return !1;
413
392
  return !0;
414
393
  }
415
- const V = "__reactjrx", We = (e) => {
416
- 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)
417
396
  return e;
418
397
  }, Xe = ({
419
398
  adapter: e,
@@ -421,7 +400,7 @@ const V = "__reactjrx", We = (e) => {
421
400
  }) => {
422
401
  const { signal: r, version: n } = t, c = {
423
402
  value: r.getValue(),
424
- [V]: V,
403
+ [x]: x,
425
404
  migrationVersion: n
426
405
  };
427
406
  return process.env.NODE_ENV === "development" && console.log(
@@ -429,29 +408,29 @@ const V = "__reactjrx", We = (e) => {
429
408
  "Persist value",
430
409
  c,
431
410
  `for signal ${r.config.key}`
432
- ), x(e.setItem(r.config.key, c)).pipe(
433
- $((u) => (console.error(u), p(null)))
411
+ ), V(e.setItem(r.config.key, c)).pipe(
412
+ F((a) => (console.error(a), g(null)))
434
413
  );
435
414
  };
436
415
  function Ze({
437
416
  adapter: e,
438
417
  config: t
439
418
  }) {
440
- const { hydrate: r = ({ value: c }) => c, signal: n, version: s } = t;
441
- return x(e.getItem(n.config.key)).pipe(
442
- C((c) => {
443
- const u = We(c);
444
- if (!u) return p(c);
445
- const l = typeof u.migrationVersion != "number", a = u.migrationVersion !== void 0 && s > u.migrationVersion;
446
- if (l || a || u.value === void 0)
447
- return p(c);
448
- 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;
449
428
  return process.env.NODE_ENV === "development" && console.log(
450
429
  "[reactjrx][state][persistance]:",
451
430
  "Hydrate value",
452
- u,
431
+ a,
453
432
  `for signal ${n.config.key}`
454
- ), n.setValue(r({ value: o, version: s })), p(c);
433
+ ), n.setValue(r({ value: o, version: u })), g(c);
455
434
  })
456
435
  );
457
436
  }
@@ -460,30 +439,30 @@ function Be({
460
439
  onHydrated: t,
461
440
  adapter: r
462
441
  }) {
463
- const s = (e.length === 0 ? p([]) : we(
442
+ const u = (e.length === 0 ? g([]) : Ee(
464
443
  ...e.map(
465
- (u) => Ze({
444
+ (a) => Ze({
466
445
  adapter: r,
467
- config: u
446
+ config: a
468
447
  })
469
448
  )
470
449
  )).pipe(
471
- re(t),
472
- $((u) => (console.error("Unable to hydrate", u), T)),
473
- ne()
474
- ), c = s.pipe(
475
- C(
476
- () => M(
450
+ T(t),
451
+ F((a) => (console.error("Unable to hydrate", a), _)),
452
+ ue()
453
+ ), c = u.pipe(
454
+ M(
455
+ () => C(
477
456
  ...e.map(
478
- (u) => u.signal.pipe(
479
- Ee(500, Ve, {
457
+ (a) => a.signal.pipe(
458
+ xe(500, Ve, {
480
459
  trailing: !0
481
460
  }),
482
- C(
483
- () => x(
461
+ M(
462
+ () => V(
484
463
  Xe({
485
464
  adapter: r,
486
- config: u
465
+ config: a
487
466
  })
488
467
  )
489
468
  )
@@ -492,8 +471,8 @@ function Be({
492
471
  )
493
472
  )
494
473
  );
495
- return M(
496
- s.pipe(
474
+ return C(
475
+ u.pipe(
497
476
  N(() => ({
498
477
  type: "hydrated"
499
478
  }))
@@ -505,21 +484,21 @@ function Be({
505
484
  )
506
485
  );
507
486
  }
508
- function It({
487
+ function wt({
509
488
  entries: e = [],
510
489
  onHydrated: t,
511
490
  adapter: r
512
491
  }) {
513
- const n = v(t), s = U(r), c = U(e);
514
- return k(
515
- () => s.pipe(
516
- C((l) => l ? M(
517
- 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" }),
518
497
  c.pipe(
519
- xe(
520
- (a) => Be({
498
+ Ce(
499
+ (s) => Be({
521
500
  adapter: l,
522
- entries: a,
501
+ entries: s,
523
502
  onHydrated: () => {
524
503
  var o;
525
504
  (o = n.current) == null || o.call(n);
@@ -527,52 +506,52 @@ function It({
527
506
  })
528
507
  )
529
508
  )
530
- ) : p({ type: "reset" }))
509
+ ) : g({ type: "reset" }))
531
510
  ).pipe(
532
- Fe(
533
- (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,
534
513
  { isHydrated: !1 }
535
514
  )
536
515
  ),
537
516
  { defaultValue: { isHydrated: !1 }, compareFn: Ge },
538
- [s, c]
517
+ [u, c]
539
518
  );
540
519
  }
541
520
  class et {
542
521
  constructor() {
543
- w(this, "queryMap", /* @__PURE__ */ new Map());
522
+ I(this, "queryMap", /* @__PURE__ */ new Map());
544
523
  }
545
524
  getQuery(t) {
546
525
  return this.queryMap.get(t);
547
526
  }
548
527
  setQuery(t, r, n) {
549
- const s = ae(t), c = r.pipe(
528
+ const u = le(t), c = r.pipe(
550
529
  /**
551
530
  * abort signal is triggered on:
552
531
  * - manual cancellation from user
553
532
  * - unmounting the component
554
533
  * @see https://tanstack.com/query/latest/docs/framework/react/guides/query-cancellation
555
534
  */
556
- se(Ce(n, "abort")),
557
- ne()
558
- ), u = {
535
+ Fe(ae(n, "abort")),
536
+ ue()
537
+ ), a = {
559
538
  query$: c,
560
539
  signal: n,
561
540
  sub: void 0,
562
541
  isCompleted: !1,
563
542
  lastData: void 0
564
543
  };
565
- this.queryMap.set(s, u);
544
+ this.queryMap.set(u, a);
566
545
  const l = c.subscribe({
567
- next: (a) => {
568
- const o = this.queryMap.get(s);
569
- o && (o.lastData = { value: a });
546
+ next: (s) => {
547
+ const o = this.queryMap.get(u);
548
+ o && (o.lastData = { value: s });
570
549
  },
571
550
  complete: () => {
572
- this.deleteQuery(s);
551
+ this.deleteQuery(u);
573
552
  }
574
553
  });
575
- return u.sub = l, u;
554
+ return a.sub = l, a;
576
555
  }
577
556
  deleteQuery(t) {
578
557
  const r = this.queryMap.get(t);
@@ -584,18 +563,18 @@ class et {
584
563
  });
585
564
  }
586
565
  }
587
- const de = X(void 0), wt = Z(
566
+ const ge = ee(void 0), It = te(
588
567
  ({
589
568
  children: e,
590
569
  client: t
591
570
  }) => {
592
- const [r] = Se(() => t ?? new et());
593
- return b(() => () => {
571
+ const [r] = Q(() => t ?? new et());
572
+ return v(() => () => {
594
573
  r.destroy();
595
- }, [r]), /* @__PURE__ */ ce(de.Provider, { value: r, children: e });
574
+ }, [r]), /* @__PURE__ */ ie(ge.Provider, { value: r, children: e });
596
575
  }
597
576
  ), tt = () => {
598
- const e = B(de);
577
+ const e = re(ge);
599
578
  if (!e)
600
579
  throw new Error(
601
580
  "useReactJrxQueryClient must be used within a ReactJrxQueryProvider"
@@ -603,36 +582,36 @@ const de = X(void 0), wt = Z(
603
582
  return e;
604
583
  };
605
584
  function Et(e, t) {
606
- const r = oe(t), n = tt();
607
- return Qe(
585
+ const r = fe(t), n = tt();
586
+ return De(
608
587
  {
609
588
  ...e,
610
- queryFn: (u) => new Promise((l, a) => {
611
- const o = () => Q(
612
- () => typeof e.queryFn == "function" ? e.queryFn(u) : e.queryFn
613
- ), 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);
614
593
  i.query$.pipe(
615
- ue(1),
594
+ ce(1),
616
595
  /**
617
596
  * If several values are emitted during this delay, we will only
618
597
  * keep the last value. This is unfortunate but it's the best we can do
619
598
  * for now.
620
599
  */
621
- $e(1)
600
+ Ne(1)
622
601
  ).subscribe({
623
- error: (g) => a(g),
602
+ error: (p) => s(p),
624
603
  complete: () => {
625
604
  if ((i == null ? void 0 : i.lastData) === void 0)
626
605
  return i.signal.aborted || (console.log(
627
606
  `cancelled due to stream completing without data for query ${f}`,
628
607
  i == null ? void 0 : i.lastData
629
608
  ), r.cancelQueries({
630
- queryKey: u.queryKey,
609
+ queryKey: a.queryKey,
631
610
  exact: !0
632
611
  })), l(void 0);
633
612
  l(i.lastData.value), (i == null ? void 0 : i.isCompleted) === !1 && setTimeout(() => {
634
613
  r == null || r.refetchQueries({
635
- queryKey: u.queryKey,
614
+ queryKey: a.queryKey,
636
615
  exact: !0
637
616
  });
638
617
  });
@@ -643,29 +622,31 @@ function Et(e, t) {
643
622
  t
644
623
  );
645
624
  }
646
- function me(e, t) {
647
- const r = j({
648
- status: "idle",
649
- isPending: !1,
650
- isError: !1,
651
- isSuccess: !1,
652
- isIdle: !0
653
- }), 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(
654
635
  {
655
636
  ...e,
656
637
  mutationFn: (o) => {
657
638
  let f;
658
- return new Promise((i, m) => {
659
- (typeof e.mutationFn == "function" ? e.mutationFn(o) : e.mutationFn).pipe(ue(1)).subscribe({
660
- next: (d) => {
661
- 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 };
662
643
  },
663
- error: (d) => {
664
- m(d);
644
+ error: (m) => {
645
+ d(m);
665
646
  },
666
647
  complete: () => {
667
648
  if (f === void 0)
668
- return m(new Error("Stream completed without any data"));
649
+ return d(new Error("Stream completed without any data"));
669
650
  i(f.value);
670
651
  }
671
652
  });
@@ -673,125 +654,163 @@ function me(e, t) {
673
654
  }
674
655
  },
675
656
  t
676
- ), { status: s, isPending: c, isError: u, isSuccess: l, isIdle: a } = n;
677
- return b(() => {
657
+ ), { status: u, isPending: c, isError: a, isSuccess: l, isIdle: s } = n;
658
+ return v(() => {
678
659
  r.next({
679
- status: s,
660
+ status: u,
680
661
  isPending: c,
681
- isError: u,
662
+ isError: a,
682
663
  isSuccess: l,
683
- isIdle: a
664
+ isIdle: s
684
665
  });
685
- }, [s, c, u, l, a, r]), { ...n, state$: r };
666
+ }, [u, c, a, l, s, r]), { ...n, state$: r };
686
667
  }
687
- function Vt(e, t) {
688
- 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(
689
675
  {
690
676
  ...e,
691
- 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
+ }
692
707
  },
693
708
  t
694
- ), l = h(
695
- (o) => (n(), s(o)),
696
- [s, n]
697
709
  ), a = h(
698
- (o) => (n(), c(o)),
699
- [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]
700
721
  );
701
- return { ...u, mutate: l, mutateAsync: a };
722
+ return { ...c, mutate: a, mutateAsync: l };
702
723
  }
703
- function xt(e, t) {
704
- 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(
705
726
  {
706
727
  ...e,
707
- onMutate({ variables: a }) {
728
+ onMutate({ variables: s }) {
708
729
  var o;
709
- return (o = e.onMutate) == null ? void 0 : o.call(e, a);
730
+ return (o = e.onMutate) == null ? void 0 : o.call(e, s);
710
731
  },
711
- onSuccess(a, o, f) {
732
+ onSuccess(s, o, f) {
712
733
  var i;
713
- 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);
714
735
  },
715
- onError(a, o, f) {
736
+ onError(s, o, f) {
716
737
  var i;
717
- 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);
718
739
  },
719
- onSettled(a, o, f, i) {
720
- var m;
721
- 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);
722
743
  },
723
- mutationFn: ({ ready$: a, variables: o }) => {
744
+ mutationFn: ({ ready$: s, variables: o }) => {
724
745
  const f = typeof e.mutationFn == "function" ? e.mutationFn(o) : e.mutationFn;
725
- return a.pipe(
726
- Ne((i) => i),
727
- Pe(),
728
- C(() => f)
746
+ return s.pipe(
747
+ Pe((i) => i),
748
+ oe(),
749
+ M(() => f)
729
750
  );
730
751
  }
731
752
  },
732
753
  t
733
- ), u = h(
734
- async (a) => {
754
+ ), a = h(
755
+ async (s) => {
735
756
  const o = r.getMutationCache().findAll({
736
757
  mutationKey: n,
737
758
  exact: !0
738
- }), f = new F(!1), i = s({ variables: a, ready$: f });
759
+ }), f = new E(!1), i = u({ variables: s, ready$: f });
739
760
  return await Promise.all(
740
- o.map((m) => m.continue().catch(L))
761
+ o.map((d) => d.continue().catch(j))
741
762
  ), f.next(!0), await i.finally(() => {
742
763
  f.complete();
743
764
  });
744
765
  },
745
- [s, r, n]
766
+ [u, r, n]
746
767
  ), l = h(
747
- (a) => {
748
- u(a).catch(L);
768
+ (s) => {
769
+ a(s).catch(j);
749
770
  },
750
- [u]
771
+ [a]
751
772
  );
752
- return { ...c, mutate: l, mutateAsync: u };
773
+ return { ...c, mutate: l, mutateAsync: a };
753
774
  }
754
775
  export {
755
- de as Context,
776
+ ge as Context,
756
777
  et as QueryClient$,
757
- wt as QueryClientProvider$,
758
- _e as SIGNAL_RESET,
759
- le as Signal,
760
- St as SignalContextProvider,
761
- fe as SignalReactContext,
762
- A as VirtualSignal,
763
- 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,
764
786
  Ue as createLocalStorageAdapter,
765
787
  bt as createLocalforageAdapter,
766
- Ke as exponentialBackoffDelay,
767
- He as getDelay,
768
- pt as isDefined,
769
- Y as isPromiseLike,
770
- ht as isServer,
788
+ ze as exponentialBackoffDelay,
789
+ Ke as getDelay,
790
+ gt as isDefined,
791
+ G as isPromiseLike,
792
+ St as isServer,
771
793
  mt as retryBackoff,
772
794
  lt as signal,
773
- j as useBehaviorSubject,
774
- xt as useContactMutation$,
775
- je as useEffectOnce,
776
- U as useLiveBehaviorSubject,
777
- v as useLiveRef,
778
- ze as useMakeOrRetrieveSignal,
795
+ Vt as useContactMutation$,
796
+ He as useEffectOnce,
797
+ W as useLiveBehaviorSubject,
798
+ b as useLiveRef,
799
+ Le as useMakeOrRetrieveSignal,
779
800
  dt as useMount,
780
- me as useMutation$,
781
- ke as useObservableCallback,
801
+ pe as useMutation$,
782
802
  ot as useObservableState,
783
- k as useObserve,
784
- It as usePersistSignals,
803
+ H as useObserve,
804
+ wt as usePersistSignals,
785
805
  Et as useQuery$,
786
806
  tt as useQueryClient$,
787
- Je as useSetSignal,
807
+ Ye as useSetSignal,
788
808
  vt as useSignal,
789
- ye as useSignalContext,
790
- Le as useSignalValue,
791
- ie as useSubject,
792
- De as useSubscribe,
809
+ me as useSignalContext,
810
+ Je as useSignalValue,
811
+ _e as useSubscribe,
793
812
  it as useSubscribeEffect,
794
- Vt as useSwitchMutation$,
813
+ xt as useSwitchMutation$,
795
814
  yt as useUnmountObservable,
796
815
  ft as virtualSignal
797
816
  };