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