reactjrx 1.112.0 → 1.113.0

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