reactjrx 1.65.0 → 1.67.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (44) hide show
  1. package/dist/index.cjs +1 -2396
  2. package/dist/index.d.ts +1 -1
  3. package/dist/index.js +1584 -2042
  4. package/dist/lib/queries/client/cache/registerResultInCache.d.ts +1 -1
  5. package/dist/lib/queries/client/createClient.d.ts +11 -9
  6. package/dist/lib/queries/client/fetch/notifyQueryResult.d.ts +1 -1
  7. package/dist/lib/queries/client/fetch/queryFetch.d.ts +2 -2
  8. package/dist/lib/queries/client/mutations/cache/MutationCache.d.ts +19 -27
  9. package/dist/lib/queries/client/mutations/cache/types.d.ts +8 -1
  10. package/dist/lib/queries/client/mutations/defaultMutationState.d.ts +1 -1
  11. package/dist/lib/queries/client/mutations/filters.d.ts +1 -1
  12. package/dist/lib/queries/client/mutations/mutation/Mutation.d.ts +36 -0
  13. package/dist/lib/queries/client/mutations/mutation/executeMutation.d.ts +6 -0
  14. package/dist/lib/queries/client/mutations/mutation/types.d.ts +51 -0
  15. package/dist/lib/queries/client/mutations/mutations.test.d.ts +1 -0
  16. package/dist/lib/queries/client/mutations/observers/MutationObserver.d.ts +27 -11
  17. package/dist/lib/queries/client/mutations/observers/mutationObserver.rq.test.d.ts +1 -0
  18. package/dist/lib/queries/client/mutations/observers/types.d.ts +7 -1
  19. package/dist/lib/queries/client/mutations/runner/MutationRunner.d.ts +17 -0
  20. package/dist/lib/queries/client/mutations/runner/mutationRunner.test.d.ts +1 -0
  21. package/dist/lib/queries/client/mutations/types.d.ts +4 -45
  22. package/dist/lib/queries/client/operators.d.ts +6 -2
  23. package/dist/lib/queries/client/refetch/client.d.ts +1 -1
  24. package/dist/lib/queries/client/store/createQueryStore.d.ts +1 -1
  25. package/dist/lib/queries/client/store/updateStoreWithNewQuery.d.ts +1 -1
  26. package/dist/lib/queries/client/tests/utils.d.ts +2 -2
  27. package/dist/lib/queries/client/triggers.d.ts +1 -1
  28. package/dist/lib/queries/client/types.d.ts +2 -1
  29. package/dist/lib/queries/react/mutations/types.d.ts +18 -0
  30. package/dist/lib/queries/react/mutations/useMutation.d.ts +2 -19
  31. package/dist/lib/queries/react/mutations/useMutation.rq.test.d.ts +1 -0
  32. package/dist/lib/queries/react/mutations/useMutationState.d.ts +3 -2
  33. package/dist/lib/queries/react/queries/helpers.d.ts +1 -0
  34. package/dist/lib/utils/{retryBackoff.d.ts → operators/retryBackoff.d.ts} +5 -3
  35. package/dist/lib/utils/operators/trackSubscriptions.d.ts +2 -0
  36. package/package.json +2 -1
  37. package/dist/lib/queries/client/mutations/Mutation.d.ts +0 -27
  38. package/dist/lib/queries/client/mutations/operators.d.ts +0 -3
  39. package/dist/lib/queries/client/mutations/runners/MutationRunner.d.ts +0 -19
  40. package/dist/lib/queries/client/mutations/runners/MutationRunners.d.ts +0 -54
  41. package/dist/lib/utils/trackSubscriptions.d.ts +0 -2
  42. /package/dist/lib/queries/{react/mutations/useMutation.cancel.test.d.ts → client/mutations/mutation/mutation.options.test.d.ts} +0 -0
  43. /package/dist/lib/utils/{emitToSubject.d.ts → operators/emitToSubject.d.ts} +0 -0
  44. /package/dist/lib/utils/{shareLatest.d.ts → operators/shareLatest.d.ts} +0 -0
package/dist/index.js CHANGED
@@ -1,655 +1,667 @@
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) => {
4
- __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
5
- return value;
1
+ var ze = Object.defineProperty;
2
+ var Je = (t, e, r) => e in t ? ze(t, e, { enumerable: !0, configurable: !0, writable: !0, value: r }) : t[e] = r;
3
+ var y = (t, e, r) => (Je(t, typeof e != "symbol" ? e + "" : e, r), r), We = (t, e, r) => {
4
+ if (!e.has(t))
5
+ throw TypeError("Cannot " + r);
6
6
  };
7
- import { useRef, useMemo, useCallback, useSyncExternalStore, useEffect, createContext, memo, useContext } from "react";
8
- import { distinctUntilChanged, tap, finalize, catchError, EMPTY, Subject, identity, BehaviorSubject, map, of, zip, merge, throttleTime, asyncScheduler, switchMap, from, defer, iif, timer, throwError, fromEvent, filter, skip, withLatestFrom, scan, retry, shareReplay, endWith, delay, take, takeUntil, share, startWith, pairwise, mergeMap, NEVER, combineLatest, concatMap as concatMap$1, last, Observable, concat, toArray, takeWhile } from "rxjs";
9
- import { retryWhen, concatMap, tap as tap$1 } from "rxjs/operators";
10
- import { jsxs, jsx } from "react/jsx-runtime";
11
- const useLiveRef = (value) => {
12
- const ref = useRef(value);
13
- useMemo(() => {
14
- ref.current = value;
15
- }, [value]);
16
- return ref;
7
+ var k = (t, e, r) => (We(t, e, "read from private field"), r ? r.call(t) : e.get(t)), de = (t, e, r) => {
8
+ if (e.has(t))
9
+ throw TypeError("Cannot add the same private member more than once");
10
+ e instanceof WeakSet ? e.add(t) : e.set(t, r);
17
11
  };
18
- function primitiveEqual(objA, objB) {
19
- if (typeof objA === "string" && objA === objB)
20
- return true;
21
- if (typeof objA === "number" && objA === objB)
22
- return true;
23
- if (typeof objA === "boolean" && objA === objB)
24
- return true;
25
- if (typeof objA === "symbol" && objA === objB)
26
- return true;
27
- if (typeof objA === "bigint" && objA === objB)
28
- return true;
29
- if (typeof objA === "undefined" && objA === objB)
30
- return true;
31
- if (objA === null && objA === objB)
32
- return true;
33
- return false;
12
+ import { useRef as H, useMemo as ye, useCallback as Y, useSyncExternalStore as Ye, useEffect as K, createContext as Ge, memo as He, useContext as De, useState as Xe } from "react";
13
+ import { distinctUntilChanged as R, tap as x, finalize as ae, catchError as A, EMPTY as M, Subject as F, identity as le, BehaviorSubject as I, map as p, of as S, zip as Ze, merge as O, throttleTime as Ve, asyncScheduler as qe, switchMap as w, from as ne, defer as se, throwError as Re, iif as Te, timer as ie, Observable as Me, filter as $, mergeMap as _, takeUntil as P, skip as B, last as ge, scan as pe, shareReplay as $e, concatMap as Be, fromEvent as me, withLatestFrom as D, retry as et, endWith as tt, delay as rt, take as be, share as J, startWith as Ie, pairwise as oe, NEVER as Qe, combineLatest as Fe, takeWhile as ve, concat as ue, toArray as ce, lastValueFrom as nt } from "rxjs";
14
+ import { catchError as Ce, retryWhen as st, concatMap as it, tap as ut } from "rxjs/operators";
15
+ import { jsxs as ct, jsx as ot } from "react/jsx-runtime";
16
+ const U = (t) => {
17
+ const e = H(t);
18
+ return ye(() => {
19
+ e.current = t;
20
+ }, [t]), e;
21
+ };
22
+ function at(t, e) {
23
+ return typeof t == "string" && t === e || typeof t == "number" && t === e || typeof t == "boolean" && t === e || typeof t == "symbol" && t === e || typeof t == "bigint" && t === e || typeof t > "u" && t === e || t === null && t === e;
34
24
  }
35
- function useObserve(source$, unsafeOptions, unsafeDeps) {
36
- const options = unsafeOptions != null && !Array.isArray(unsafeOptions) ? unsafeOptions : {
25
+ function fe(t, e, r) {
26
+ const n = e != null && !Array.isArray(e) ? e : {
37
27
  defaultValue: void 0,
38
28
  key: "",
39
- unsubscribeOnUnmount: true
40
- };
41
- const deps = unsafeDeps == null && Array.isArray(unsafeOptions) ? unsafeOptions : typeof source$ === "function" ? unsafeDeps ?? [] : [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 subscribe = useCallback(
48
- (next) => {
49
- const source = sourceRef.current;
50
- const makeObservable = typeof source === "function" ? source : () => source;
51
- const sub = makeObservable().pipe(
29
+ unsubscribeOnUnmount: !0
30
+ }, s = r == null && Array.isArray(e) ? e : typeof t == "function" ? r ?? [] : [t], i = H(
31
+ "getValue" in t && typeof t.getValue == "function" ? t.getValue() : n.defaultValue
32
+ ), u = U(t), l = U(n), f = Y(
33
+ (g) => {
34
+ const a = u.current, o = (typeof a == "function" ? a : () => a)().pipe(
52
35
  /**
53
36
  * @important
54
37
  * We only check primitives because underlying subscription might
55
38
  * be using objects and keeping same reference but pushing new
56
39
  * properties values
57
40
  */
58
- distinctUntilChanged(primitiveEqual),
59
- tap((value) => {
60
- valueRef.current = value;
41
+ R(at),
42
+ x((m) => {
43
+ i.current = m;
61
44
  }),
62
- finalize(next),
63
- catchError((error) => {
64
- console.error(error);
65
- valueRef.current = void 0;
66
- return EMPTY;
67
- })
68
- ).subscribe(next);
45
+ ae(g),
46
+ A((m) => (console.error(m), i.current = void 0, M))
47
+ ).subscribe(g);
69
48
  return () => {
70
- if (optionsRef.current.unsubscribeOnUnmount === false)
71
- return;
72
- sub.unsubscribe();
49
+ l.current.unsubscribeOnUnmount !== !1 && o.unsubscribe();
73
50
  };
74
51
  },
75
52
  // eslint-disable-next-line react-hooks/exhaustive-deps
76
- [...deps]
77
- );
78
- const getSnapshot = useCallback(() => {
79
- return valueRef.current;
80
- }, []);
81
- const result = useSyncExternalStore(subscribe, getSnapshot, getSnapshot);
82
- return result;
53
+ [...s]
54
+ ), d = Y(() => i.current, []);
55
+ return Ye(f, d, d);
83
56
  }
84
- function useSubscribe(source, deps = []) {
85
- const sourceRef = useLiveRef(source);
86
- const sourceAsObservable = typeof source === "function" ? void 0 : source;
87
- useEffect(() => {
88
- const source2 = sourceRef.current;
89
- const makeObservable = typeof source2 === "function" ? source2 : () => source2;
90
- const sub = makeObservable().pipe(
91
- catchError((error) => {
92
- console.error(
93
- "Uncaught error at useSubscribe. Please consider adding a catchError or other handling."
94
- );
95
- console.error(error);
96
- return EMPTY;
97
- })
57
+ function Se(t, e = []) {
58
+ const r = U(t), n = typeof t == "function" ? void 0 : t;
59
+ K(() => {
60
+ const s = r.current, u = (typeof s == "function" ? s : () => s)().pipe(
61
+ A((l) => (console.error(
62
+ "Uncaught error at useSubscribe. Please consider adding a catchError or other handling."
63
+ ), console.error(l), M))
98
64
  ).subscribe();
99
65
  return () => {
100
- sub.unsubscribe();
66
+ u.unsubscribe();
101
67
  };
102
68
  }, [
103
69
  // eslint-disable-next-line react-hooks/exhaustive-deps
104
- ...deps,
105
- sourceAsObservable,
106
- sourceRef
70
+ ...e,
71
+ n,
72
+ r
107
73
  ]);
108
74
  }
109
- const useConstant = (fn) => {
110
- const ref = useRef();
111
- if (!ref.current) {
112
- ref.current = fn();
113
- }
114
- useEffect(() => {
115
- if (process.env.NODE_ENV === "development")
116
- ;
117
- }, []);
118
- return ref;
119
- };
120
- const useSubject = ({
121
- onBeforeComplete,
122
- completeOnUnmount = true
75
+ const we = (t) => {
76
+ const e = H();
77
+ return e.current || (e.current = t()), K(() => {
78
+ process.env.NODE_ENV;
79
+ }, []), e;
80
+ }, Oe = ({
81
+ onBeforeComplete: t,
82
+ completeOnUnmount: e = !0
123
83
  } = {}) => {
124
- const subject = useConstant(() => new Subject());
125
- const completed = useRef(false);
126
- const onBeforeCompleteRef = useLiveRef(onBeforeComplete);
127
- const completeOnUnmountRef = useLiveRef(completeOnUnmount);
128
- useEffect(() => {
129
- if (completed.current) {
130
- subject.current = new Subject();
131
- completed.current = false;
84
+ const r = we(() => new F()), n = H(!1), s = U(t), i = U(e);
85
+ return K(() => (n.current && (r.current = new F(), n.current = !1), () => {
86
+ if (!i.current) {
87
+ n.current = !0;
88
+ return;
132
89
  }
133
- return () => {
134
- if (!completeOnUnmountRef.current) {
135
- completed.current = true;
136
- return;
137
- }
138
- if (!completed.current) {
139
- if (onBeforeCompleteRef.current != null)
140
- onBeforeCompleteRef.current();
141
- subject.current.complete();
142
- completed.current = true;
143
- }
144
- };
145
- }, [completeOnUnmountRef, onBeforeCompleteRef, subject]);
146
- return subject;
90
+ n.current || (s.current != null && s.current(), r.current.complete(), n.current = !0);
91
+ }), [i, s, r]), r;
92
+ }, ar = (t, e) => {
93
+ const r = Oe();
94
+ return Se(() => t(r.current), [r, ...e]), [Y((s) => {
95
+ r.current.next(s);
96
+ }, [r]), r];
147
97
  };
148
- const useObserveCallback = (callback, deps) => {
149
- const trigger$ = useSubject();
150
- useSubscribe(() => callback(trigger$.current), [trigger$, ...deps]);
151
- const trigger2 = useCallback((arg) => {
152
- trigger$.current.next(arg);
153
- }, [trigger$]);
154
- return [trigger2, trigger$];
155
- };
156
- function trigger(mapper = identity) {
157
- const subject = new Subject();
98
+ function lr(t = le) {
99
+ const e = new F();
158
100
  return [
159
- subject.asObservable(),
160
- (...args) => {
161
- subject.next(mapper(...args));
101
+ e.asObservable(),
102
+ (...r) => {
103
+ e.next(t(...r));
162
104
  }
163
105
  ];
164
106
  }
165
- const useBehaviorSubject = (state) => {
166
- const subject = useConstant(() => new BehaviorSubject(state));
167
- const completed = useRef(false);
168
- const stateRef = useRef(state);
169
- useEffect(() => {
170
- if (completed.current) {
171
- subject.current = new BehaviorSubject(stateRef.current);
172
- completed.current = false;
173
- }
174
- return () => {
175
- if (!completed.current) {
176
- subject.current.complete();
177
- completed.current = true;
107
+ const lt = (t) => {
108
+ const e = we(() => new I(t)), r = H(!1), n = H(t);
109
+ return K(() => (r.current && (e.current = new I(n.current), r.current = !1), () => {
110
+ r.current || (e.current.complete(), r.current = !0);
111
+ }), [e]), e;
112
+ }, pt = Symbol("SIGNAL_RESET");
113
+ function pr(t) {
114
+ const { default: e } = t ?? {}, r = new I(e);
115
+ return {
116
+ setValue: (i) => {
117
+ if (typeof i == "function") {
118
+ const u = i(r.getValue());
119
+ if (u === r.getValue())
120
+ return;
121
+ r.next(u);
122
+ return;
178
123
  }
179
- };
180
- }, [subject]);
181
- return subject;
182
- };
183
- const SIGNAL_RESET = Symbol("SIGNAL_RESET");
184
- function signal(config) {
185
- const { default: defaultValue2 } = config ?? {};
186
- const subject = new BehaviorSubject(defaultValue2);
187
- const setValue = (arg) => {
188
- if (typeof arg === "function") {
189
- const change = arg(subject.getValue());
190
- if (change === subject.getValue())
124
+ if (i === pt) {
125
+ r.next(e ?? void 0);
191
126
  return;
192
- subject.next(change);
193
- return;
194
- }
195
- if (arg === SIGNAL_RESET) {
196
- subject.next(defaultValue2 ?? void 0);
197
- return;
198
- }
199
- subject.next(arg);
200
- };
201
- const getValue = () => subject.getValue();
202
- return {
203
- setValue,
204
- getValue,
205
- config,
206
- subject
127
+ }
128
+ r.next(i);
129
+ },
130
+ getValue: () => r.getValue(),
131
+ config: t,
132
+ subject: r
207
133
  };
208
134
  }
209
- function useSignalValue(signal2, selector) {
210
- const selectorOrDefault = selector ?? ((v) => v);
211
- return useObserve(
212
- () => signal2.subject.pipe(
213
- map((value) => selectorOrDefault(value)),
214
- distinctUntilChanged()
135
+ function fr(t, e) {
136
+ const r = e ?? ((n) => n);
137
+ return fe(
138
+ () => t.subject.pipe(
139
+ p((n) => r(n)),
140
+ R()
215
141
  ),
216
142
  {
217
- defaultValue: selectorOrDefault(signal2.getValue())
143
+ defaultValue: r(t.getValue())
218
144
  },
219
145
  []
220
146
  );
221
147
  }
222
- const normalizeStore = (store) => {
223
- if (!store || typeof store !== "object") {
224
- return void 0;
225
- }
226
- return store;
227
- };
228
- const createSharedStoreAdapter = ({
229
- adapter,
230
- key
148
+ const xe = (t) => {
149
+ if (!(!t || typeof t != "object"))
150
+ return t;
151
+ }, dr = ({
152
+ adapter: t,
153
+ key: e
231
154
  }) => ({
232
- getItem: async (itemKey) => {
233
- const unsafeStore = await adapter.getItem(key);
234
- const store = normalizeStore(unsafeStore) ?? {};
235
- if (itemKey in store) {
236
- return store[itemKey];
237
- }
238
- return void 0;
155
+ getItem: async (r) => {
156
+ const n = await t.getItem(e), s = xe(n) ?? {};
157
+ if (r in s)
158
+ return s[r];
239
159
  },
240
- setItem: async (itemKey, value) => {
241
- const unsafeStore = await adapter.getItem(key);
242
- const store = normalizeStore(unsafeStore) ?? {};
243
- await adapter.setItem(key, { ...store, [itemKey]: value });
160
+ setItem: async (r, n) => {
161
+ const s = await t.getItem(e), i = xe(s) ?? {};
162
+ await t.setItem(e, { ...i, [r]: n });
244
163
  }
245
- });
246
- const createLocalforageAdapter = (forage) => ({
247
- getItem: async (key) => {
248
- const serializedValue = await forage.getItem(key);
249
- if (!serializedValue)
250
- return void 0;
251
- return JSON.parse(serializedValue);
164
+ }), hr = (t) => ({
165
+ getItem: async (e) => {
166
+ const r = await t.getItem(e);
167
+ if (r)
168
+ return JSON.parse(r);
252
169
  },
253
- setItem: async (key, value) => {
254
- await forage.setItem(key, JSON.stringify(value));
170
+ setItem: async (e, r) => {
171
+ await t.setItem(e, JSON.stringify(r));
255
172
  }
256
- });
257
- const createLocalStorageAdapter = (forage) => ({
258
- getItem: async (key) => {
259
- const serializedValue = forage.getItem(key);
260
- if (!serializedValue)
261
- return void 0;
262
- return JSON.parse(serializedValue);
173
+ }), ft = (t) => ({
174
+ getItem: async (e) => {
175
+ const r = t.getItem(e);
176
+ if (r)
177
+ return JSON.parse(r);
263
178
  },
264
- setItem: async (key, value) => {
265
- forage.setItem(key, JSON.stringify(value));
266
- }
267
- });
268
- const IDENTIFIER_PERSISTANCE_KEY = "__reactjrx";
269
- const getNormalizedPersistanceValue = (unknownValue) => {
270
- if (typeof unknownValue === "object" && unknownValue !== null && IDENTIFIER_PERSISTANCE_KEY in unknownValue && unknownValue[IDENTIFIER_PERSISTANCE_KEY] === IDENTIFIER_PERSISTANCE_KEY) {
271
- return unknownValue;
179
+ setItem: async (e, r) => {
180
+ t.setItem(e, JSON.stringify(r));
272
181
  }
273
- return void 0;
274
- };
275
- const persistValue = async ({
276
- adapter,
277
- signal: signal2,
278
- version
182
+ }), Z = "__reactjrx", dt = (t) => {
183
+ if (typeof t == "object" && t !== null && Z in t && t[Z] === Z)
184
+ return t;
185
+ }, ht = async ({
186
+ adapter: t,
187
+ signal: e,
188
+ version: r
279
189
  }) => {
280
- const state = signal2.getValue();
281
- const value = {
282
- value: state,
283
- [IDENTIFIER_PERSISTANCE_KEY]: IDENTIFIER_PERSISTANCE_KEY,
284
- migrationVersion: version
190
+ const s = {
191
+ value: e.getValue(),
192
+ [Z]: Z,
193
+ migrationVersion: r
285
194
  };
286
- await adapter.setItem(signal2.config.key, value);
287
- };
288
- const hydrateValueToSignal = ({
289
- adapter,
290
- version,
291
- signal: signal2
292
- }) => {
293
- return from(adapter.getItem(signal2.config.key)).pipe(
294
- switchMap((value) => {
295
- const normalizedValue = getNormalizedPersistanceValue(value);
296
- if (!normalizedValue)
297
- return of(value);
298
- if (normalizedValue.migrationVersion !== void 0 && version > normalizedValue.migrationVersion) {
299
- return of(value);
300
- }
301
- signal2.setValue(value.value);
302
- return of(value);
303
- })
304
- );
305
- };
306
- const usePersistSignals = ({
307
- entries = [],
308
- onReady,
309
- adapter = createLocalStorageAdapter(localStorage)
195
+ await t.setItem(e.config.key, s);
196
+ }, gt = ({
197
+ adapter: t,
198
+ version: e,
199
+ signal: r
200
+ }) => ne(t.getItem(r.config.key)).pipe(
201
+ w((n) => {
202
+ const s = dt(n);
203
+ return s ? s.migrationVersion !== void 0 && e > s.migrationVersion ? S(n) : (r.setValue(n.value), S(n)) : S(n);
204
+ })
205
+ ), gr = ({
206
+ entries: t = [],
207
+ onReady: e,
208
+ adapter: r = ft(localStorage)
310
209
  }) => {
311
- const entriesRef = useLiveRef(entries);
312
- const onReadyRef = useLiveRef(onReady);
313
- const adapterRef = useLiveRef(adapter);
314
- const isHydrated = useObserve(
210
+ const n = U(t), s = U(e), i = U(r), u = fe(
315
211
  () => {
316
- const entries2 = entriesRef.current;
317
- const stream = entries2.length === 0 ? of(true) : zip(
318
- ...entries2.map(
319
- ({ signal: signal2, version }) => hydrateValueToSignal({
320
- adapter: adapterRef.current,
321
- signal: signal2,
322
- version
212
+ const l = n.current;
213
+ return (l.length === 0 ? S(!0) : Ze(
214
+ ...l.map(
215
+ ({ signal: d, version: h }) => gt({
216
+ adapter: i.current,
217
+ signal: d,
218
+ version: h
323
219
  })
324
220
  )
325
- ).pipe(map(() => true));
326
- return stream.pipe(
327
- tap(() => {
328
- if (onReadyRef.current != null)
329
- onReadyRef.current();
221
+ ).pipe(p(() => !0))).pipe(
222
+ x(() => {
223
+ s.current != null && s.current();
330
224
  }),
331
- catchError((error) => {
332
- console.error("Unable to hydrate", error);
333
- return EMPTY;
334
- })
225
+ A((d) => (console.error("Unable to hydrate", d), M))
335
226
  );
336
227
  },
337
- { defaultValue: false },
228
+ { defaultValue: !1 },
338
229
  []
339
230
  );
340
- useSubscribe(() => {
341
- return !isHydrated ? EMPTY : merge(
342
- ...entriesRef.current.map(
343
- ({ signal: signal2, version }) => signal2.subject.pipe(
344
- throttleTime(500, asyncScheduler, {
345
- trailing: true
346
- }),
347
- switchMap(
348
- () => from(
349
- persistValue({ adapter: adapterRef.current, signal: signal2, version })
350
- )
231
+ return Se(() => u ? O(
232
+ ...n.current.map(
233
+ ({ signal: l, version: f }) => l.subject.pipe(
234
+ Ve(500, qe, {
235
+ trailing: !0
236
+ }),
237
+ w(
238
+ () => ne(
239
+ ht({ adapter: i.current, signal: l, version: f })
351
240
  )
352
241
  )
353
242
  )
354
- );
355
- }, [isHydrated, adapterRef]);
356
- return { isHydrated };
357
- };
358
- const useUnmountObservable = () => {
359
- const subject = useSubject({
243
+ )
244
+ ) : M, [u, i]), { isHydrated: u };
245
+ }, mr = () => {
246
+ const t = Oe({
360
247
  onBeforeComplete: () => {
361
- subject.current.next();
248
+ t.current.next();
362
249
  }
363
250
  });
364
- return subject;
251
+ return t;
365
252
  };
366
- function getDelay(backoffDelay, maxInterval) {
367
- return Math.min(backoffDelay, maxInterval);
253
+ function mt(t, e) {
254
+ return Math.min(t, e);
368
255
  }
369
- function exponentialBackoffDelay(iteration, initialInterval) {
370
- return Math.pow(2, iteration) * initialInterval;
256
+ function bt(t, e) {
257
+ return Math.pow(2, t) * e;
371
258
  }
372
- function retryBackoff(config) {
259
+ function yt(t) {
373
260
  const {
374
- initialInterval,
375
- maxRetries = Infinity,
376
- maxInterval = Infinity,
377
- shouldRetry = () => true,
378
- resetOnSuccess = false,
379
- backoffDelay = exponentialBackoffDelay
380
- } = typeof config === "number" ? { initialInterval: config } : config;
381
- return (source) => defer(() => {
382
- let index = 0;
383
- return source.pipe(
384
- retryWhen((errors) => {
385
- return errors.pipe(
386
- concatMap((error) => {
387
- const attempt = index++;
388
- return iif(
389
- () => attempt < maxRetries && shouldRetry(attempt, error),
390
- timer(
391
- getDelay(backoffDelay(attempt, initialInterval), maxInterval)
392
- ),
393
- throwError(error)
394
- );
395
- })
261
+ initialInterval: e,
262
+ maxRetries: r = 1 / 0,
263
+ maxInterval: n = 1 / 0,
264
+ shouldRetry: s = () => !0,
265
+ resetOnSuccess: i = !1,
266
+ backoffDelay: u = bt
267
+ } = t;
268
+ return (l) => se(() => {
269
+ let f = 0;
270
+ const d = (h, g) => h < r && s(h, g);
271
+ return l.pipe(
272
+ Ce((h) => {
273
+ var a;
274
+ if (f++, !d(f - 1, h))
275
+ throw h;
276
+ const g = (a = t.caughtError) == null ? void 0 : a.call(t, f, h);
277
+ if (!g)
278
+ throw h;
279
+ return O(
280
+ g,
281
+ Re(() => h)
396
282
  );
397
283
  }),
398
- tap$1(() => {
399
- if (resetOnSuccess) {
400
- index = 0;
401
- }
284
+ st((h) => h.pipe(
285
+ it((g) => {
286
+ const a = f - 1;
287
+ return Te(
288
+ () => d(a, g),
289
+ ie(
290
+ mt(u(a, e), n)
291
+ ),
292
+ Re(() => g)
293
+ );
294
+ })
295
+ )),
296
+ Ce((h) => {
297
+ if (t.catchError)
298
+ return t.catchError(f, h);
299
+ throw h;
300
+ }),
301
+ ut(() => {
302
+ i && (f = 0);
402
303
  })
403
304
  );
404
305
  });
405
306
  }
406
- const Context = createContext({
307
+ const _e = Ge({
407
308
  client: null
408
- });
409
- const ClientEffect = ({ client }) => {
410
- useEffect(() => {
411
- const stop = client.mount();
412
- return () => {
413
- stop();
414
- };
415
- }, [client]);
416
- return null;
417
- };
418
- const QueryClientProvider = memo(
419
- ({ children, client }) => {
420
- const value = useMemo(() => ({ client }), [client]);
421
- return /* @__PURE__ */ jsxs(Context.Provider, { value, children: [
422
- /* @__PURE__ */ jsx(ClientEffect, { client: value.client }),
423
- children
309
+ }), $t = ({ client: t }) => (K(() => {
310
+ const e = t.mount();
311
+ return () => {
312
+ e();
313
+ };
314
+ }, [t]), null), br = He(
315
+ ({ children: t, client: e }) => {
316
+ const r = ye(() => ({ client: e }), [e]);
317
+ return /* @__PURE__ */ ct(_e.Provider, { value: r, children: [
318
+ /* @__PURE__ */ ot($t, { client: r.client }),
319
+ t
424
320
  ] });
425
321
  }
426
- );
427
- const useQueryClient = ({
428
- unsafe = false
322
+ ), Pe = ({
323
+ unsafe: t = !1
429
324
  } = {}) => {
430
- const context = useContext(Context);
431
- if (!unsafe && context.client === null) {
325
+ const e = De(_e);
326
+ if (!t && e.client === null)
432
327
  throw new Error("You forgot to register the provider");
328
+ return e.client;
329
+ }, ee = (t) => Array.isArray(t) ? t.reduce((e, r, n) => n === t.length - 1 ? `${e}${ee(r)}]` : `${e}${ee(r)},`, "[") : t === void 0 ? "" : JSON.stringify(t, Object.keys(t).sort()), N = (t) => t.length === 0 ? "[]" : ee(t), Ne = (t = 21) => crypto.getRandomValues(new Uint8Array(t)).reduce((e, r) => (r &= 63, r < 36 ? e += r.toString(36) : r < 62 ? e += (r - 26).toString(36).toUpperCase() : r > 62 ? e += "-" : e += "_", e), ""), W = () => ({
330
+ context: void 0,
331
+ data: void 0,
332
+ error: null,
333
+ status: "idle",
334
+ submittedAt: 0,
335
+ variables: void 0,
336
+ failureCount: 0,
337
+ failureReason: null,
338
+ isPaused: !1
339
+ });
340
+ function G(t) {
341
+ return t != null;
342
+ }
343
+ function T(t, e) {
344
+ if (t == null || e === void 0 || typeof t != "object" || typeof e != "object")
345
+ return t === e;
346
+ if (t.constructor !== (e == null ? void 0 : e.constructor))
347
+ return !1;
348
+ const r = Object.keys(t), n = Object.keys(e);
349
+ if (r.length !== n.length)
350
+ return !1;
351
+ for (const s of r)
352
+ if (!e.hasOwnProperty(s) || t[s] !== e[s])
353
+ return !1;
354
+ return !0;
355
+ }
356
+ function ke(t) {
357
+ let e = 0;
358
+ return function(n) {
359
+ return new Me((s) => {
360
+ e++, t(e);
361
+ const i = n.subscribe(s);
362
+ return () => {
363
+ e--, t(e), i.unsubscribe();
364
+ };
365
+ });
366
+ };
367
+ }
368
+ class vt {
369
+ constructor({
370
+ __queryFinalizeHook: e
371
+ } = {}) {
372
+ y(this, "trigger$", new F());
373
+ y(this, "mapOperator$", new I("merge"));
374
+ y(this, "state$");
375
+ const r = new I(0), n = r.pipe(
376
+ $((i) => i === 0)
377
+ ), s = this.mapOperator$.pipe(
378
+ $(G),
379
+ R()
380
+ );
381
+ this.state$ = s.pipe(
382
+ _((i) => {
383
+ const u = i === "concat" ? Be : i === "switch" ? w : _, l = this.trigger$.pipe(
384
+ $(() => i === "merge")
385
+ );
386
+ return this.trigger$.pipe(
387
+ P(s.pipe(B(1))),
388
+ u(({ args: f, mutation: d }) => {
389
+ const h = se(() => (d.execute(f), M)), g = d.observeTillFinished().pipe(
390
+ ge(),
391
+ _(() => d.state$),
392
+ P(this.trigger$)
393
+ ), a = d.observeTillFinished().pipe(B(1));
394
+ return O(a, g, h).pipe(
395
+ e ?? le,
396
+ P(O(n, l))
397
+ );
398
+ }),
399
+ pe((f, d) => ({
400
+ ...f,
401
+ ...d,
402
+ ...d.status === "pending" && {
403
+ data: d.data ?? f.data
404
+ },
405
+ ...d.status === "pending" && {
406
+ error: d.error ?? f.error
407
+ }
408
+ }), W()),
409
+ R(
410
+ ({ data: f, ...d }, { data: h, ...g }) => T(d, g) && T(f, h)
411
+ )
412
+ );
413
+ }),
414
+ $e({
415
+ refCount: !0,
416
+ bufferSize: 1
417
+ }),
418
+ ke((i) => {
419
+ r.next(i);
420
+ })
421
+ );
433
422
  }
434
- return context.client;
435
- };
436
- const serializeObject = (object) => {
437
- if (Array.isArray(object)) {
438
- return object.reduce((acc, value, index) => {
439
- if (index === object.length - 1)
440
- return `${acc}${serializeObject(value)}]`;
441
- return `${acc}${serializeObject(value)},`;
442
- }, "[");
443
- }
444
- if (object === void 0)
445
- return "";
446
- return JSON.stringify(object, Object.keys(object).sort());
447
- };
448
- const serializeKey = (key) => {
449
- if (key.length === 0)
450
- return "[]";
451
- return serializeObject(key);
452
- };
453
- const nanoid = (size = 21) => crypto.getRandomValues(new Uint8Array(size)).reduce((id, byte) => {
454
- byte &= 63;
455
- if (byte < 36) {
456
- id += byte.toString(36);
457
- } else if (byte < 62) {
458
- id += (byte - 26).toString(36).toUpperCase();
459
- } else if (byte > 62) {
460
- id += "-";
461
- } else {
462
- id += "_";
423
+ trigger({ args: e, options: r, mutation: n }) {
424
+ r.mapOperator && this.mapOperator$.next(r.mapOperator), this.trigger$.next({ args: e, options: r, mutation: n });
463
425
  }
464
- return id;
465
- }, "");
466
- function noop() {
467
426
  }
468
- function useMutation(options, queryClient) {
469
- const defaultQueryClient = useQueryClient({ unsafe: !!queryClient });
470
- const finalQueryClient = queryClient ?? defaultQueryClient;
471
- const optionsRef = useLiveRef(options);
472
- const defaultKey = useConstant(() => [nanoid()]);
473
- const serializedKey = serializeKey(options.mutationKey ?? defaultKey.current);
474
- const mutationsToCancel = useRef([]);
475
- const observedMutation = useMemo(() => {
476
- return finalQueryClient.mutationObserver.observeBy({
477
- mutationKey: optionsRef.current.mutationKey ?? defaultKey.current
478
- });
479
- }, [serializedKey, defaultKey, finalQueryClient, optionsRef]);
480
- const result = useObserve(observedMutation.result$) ?? observedMutation.lastValue;
481
- const mutate = useCallback(
482
- (mutationArgs) => {
483
- finalQueryClient.mutationRunners.mutate({
484
- options: {
485
- ...optionsRef.current,
486
- mutationKey: optionsRef.current.mutationKey ?? defaultKey.current
487
- },
488
- args: mutationArgs
489
- }).catch(noop);
490
- const mutation = finalQueryClient.getMutationCache().findLatest({
491
- mutationKey: optionsRef.current.mutationKey ?? defaultKey.current
492
- });
493
- if (mutation) {
494
- mutationsToCancel.current.push(mutation);
495
- }
496
- },
497
- [finalQueryClient, serializedKey, defaultKey, optionsRef]
498
- );
499
- const cancel = useCallback(() => {
500
- mutationsToCancel.current.forEach((mutation) => {
501
- mutation.cancel();
427
+ const te = (t, e, { exact: r = !1 } = {}) => r ? N(t) === N(e) : t.reduce((n, s, i) => n ? s === void 0 && !t.slice(i, t.length - 1).some((l) => l !== void 0) ? !0 : ee(s) === ee(e[i]) : !1, !0);
428
+ var L;
429
+ class St {
430
+ constructor(e, r = {}, n) {
431
+ y(this, "numberOfObservers", 0);
432
+ y(this, "mutationRunner");
433
+ de(this, L, new I(void 0));
434
+ y(this, "observed$");
435
+ y(this, "result$");
436
+ y(this, "getObserverResultFromState", (e) => ({
437
+ ...W(),
438
+ ...e,
439
+ isSuccess: e.status === "success",
440
+ isPending: e.status === "pending",
441
+ isIdle: e.status === "idle",
442
+ isError: e.status === "error",
443
+ mutate: this.mutate,
444
+ reset: this.reset
445
+ }));
446
+ var s;
447
+ this.client = e, this.options = r, this.options.mutationKey = ((s = this.options) == null ? void 0 : s.mutationKey) ?? [Ne()], this.mutationRunner = n ?? new vt(this.options), this.mutate = this.mutate.bind(this), this.reset = this.reset.bind(this), this.result$ = this.mutationRunner.state$.pipe(
448
+ p((i) => ({
449
+ state: this.getObserverResultFromState(i),
450
+ options: {}
451
+ }))
452
+ ), k(this, L).pipe(
453
+ $(G),
454
+ _(
455
+ (i) => this.mutationRunner.state$.pipe(
456
+ P(i.mutation.observeTillFinished().pipe(ge()))
457
+ )
458
+ )
459
+ ).subscribe(), this.observed$ = k(this, L).pipe(
460
+ w(
461
+ (i) => (i == null ? void 0 : i.mutation.state$.pipe(
462
+ p((u) => ({
463
+ state: this.getObserverResultFromState(u),
464
+ options: i.options
465
+ }))
466
+ )) ?? M
467
+ ),
468
+ _(({ state: i, options: u }) => (i.status === "error" && (u != null && u.onError && (u == null || u.onError(
469
+ i.error,
470
+ i.variables,
471
+ i.context
472
+ )), u != null && u.onSettled && (u == null || u.onSettled(
473
+ i.data,
474
+ i.error,
475
+ i.variables,
476
+ i.context
477
+ ))), i.status === "success" && (u != null && u.onSuccess && (u == null || u.onSuccess(
478
+ i.data,
479
+ i.variables,
480
+ i.context
481
+ )), u != null && u.onSettled && (u == null || u.onSettled(
482
+ i.data,
483
+ i.error,
484
+ i.variables,
485
+ i.context
486
+ ))), M))
487
+ );
488
+ }
489
+ setOptions(e) {
490
+ var n;
491
+ const r = this.options;
492
+ this.options = this.client.defaultMutationOptions({
493
+ mutationKey: this.options.mutationKey,
494
+ ...e
495
+ }), (n = k(this, L).getValue()) == null || n.mutation.setOptions(this.options), this.options.mutationKey && r.mutationKey && !te(this.options.mutationKey, r.mutationKey, {
496
+ exact: !0
497
+ }) && this.reset();
498
+ }
499
+ observe() {
500
+ var n;
501
+ const e = this.getObserverResultFromState(
502
+ ((n = k(this, L).getValue()) == null ? void 0 : n.mutation.state) ?? W()
503
+ );
504
+ return { result$: O(this.observed$, this.result$).pipe(
505
+ p(({ state: s }) => (console.log({ state: s }), s))
506
+ ), lastValue: e };
507
+ }
508
+ /**
509
+ * @important
510
+ * Compliance react-query only
511
+ */
512
+ subscribe(e) {
513
+ const r = this.observe().result$.subscribe((n) => {
514
+ e(n);
502
515
  });
503
- }, []);
504
- useEffect(() => {
505
516
  return () => {
506
- if (optionsRef.current.cancelOnUnMount) {
507
- cancel();
508
- }
517
+ r.unsubscribe();
509
518
  };
510
- }, [cancel, optionsRef]);
511
- return { mutate, cancel, ...result };
512
- }
513
- const arrayEqual = (a, b) => a.length === b.length && a.every((v, i) => v === b[i]);
514
- function shallowEqual(objA, objB) {
515
- if (objA === null || objA === void 0 || objB === void 0) {
516
- return objA === objB;
517
- }
518
- if (typeof objA !== "object" || typeof objB !== "object") {
519
- return objA === objB;
520
519
  }
521
- if (objA.constructor !== (objB == null ? void 0 : objB.constructor)) {
522
- return false;
520
+ async mutate(e, r = {}) {
521
+ const n = this.client.getMutationCache().build(this.client, this.options);
522
+ return k(this, L).next({ mutation: n, options: r }), this.mutationRunner.trigger({
523
+ args: e,
524
+ options: this.options,
525
+ mutation: n
526
+ }), await new Promise((s, i) => {
527
+ n.observeTillFinished().pipe(ge()).subscribe({
528
+ error: (u) => {
529
+ i(u);
530
+ },
531
+ next: (u) => {
532
+ u.error ? i(u.error) : s(u.data);
533
+ }
534
+ });
535
+ });
523
536
  }
524
- const keysA = Object.keys(objA);
525
- const keysB = Object.keys(objB);
526
- if (keysA.length !== keysB.length) {
527
- return false;
537
+ getCurrentResult() {
538
+ var r;
539
+ const e = this.client.getMutationCache().find({ exact: !0, mutationKey: (r = this.options) == null ? void 0 : r.mutationKey });
540
+ return this.getObserverResultFromState(
541
+ (e == null ? void 0 : e.state) ?? W()
542
+ );
528
543
  }
529
- for (const key of keysA) {
530
- if (!objB.hasOwnProperty(key) || objA[key] !== objB[key]) {
531
- return false;
532
- }
544
+ reset() {
545
+ var e;
546
+ (e = k(this, L).getValue()) == null || e.mutation.reset();
533
547
  }
534
- return true;
535
548
  }
536
- function isDefined(arg) {
537
- return arg !== null && arg !== void 0;
549
+ L = new WeakMap();
550
+ function wt() {
538
551
  }
539
- const createActivityTrigger = (params$) => {
540
- return params$.pipe(
541
- switchMap(({ options: { refetchOnWindowFocus = true } }) => {
542
- const shouldRunTrigger = typeof refetchOnWindowFocus === "function" ? refetchOnWindowFocus({}) : refetchOnWindowFocus;
543
- return shouldRunTrigger !== false ? merge(
544
- fromEvent(document, "visibilitychange").pipe(
545
- filter(() => !document.hidden),
546
- map(() => ({
547
- type: "refetch",
548
- ignoreStale: shouldRunTrigger === "always"
549
- }))
550
- ),
551
- fromEvent(window, "focus").pipe(
552
- map(() => ({
553
- type: "refetch",
554
- ignoreStale: shouldRunTrigger === "always"
555
- }))
556
- )
557
- ) : EMPTY;
558
- })
552
+ function yr(t, e) {
553
+ const r = Pe({ unsafe: !!e }), n = e ?? r, s = U(t), i = we(() => [Ne()]), u = N(t.mutationKey ?? i.current), [l] = Xe(
554
+ () => new St(
555
+ n,
556
+ t
557
+ )
559
558
  );
560
- };
561
- const createNetworkTrigger = (params$) => {
562
- return params$.pipe(
563
- switchMap(({ options: { refetchOnReconnect = true } }) => {
564
- const shouldRunTrigger = typeof refetchOnReconnect === "function" ? refetchOnReconnect({}) : refetchOnReconnect;
565
- return shouldRunTrigger !== false ? fromEvent(window, "online").pipe(
566
- map(() => ({
559
+ K(() => {
560
+ l.setOptions(t);
561
+ }, [l, t]);
562
+ const f = ye(() => l.observe(), [u, l]), d = fe(f.result$) ?? f.lastValue, h = Y(
563
+ (g, a) => {
564
+ l.mutate(g, a).catch(wt);
565
+ },
566
+ [l]
567
+ );
568
+ return K(() => () => {
569
+ s.current.cancelOnUnMount && l.reset();
570
+ }, [l, s]), { ...d, mutate: h, mutateAsync: d.mutate };
571
+ }
572
+ const Le = (t, e) => t.length === e.length && t.every((r, n) => r === e[n]), Ot = (t) => t.pipe(
573
+ w(({ options: { refetchOnWindowFocus: e = !0 } }) => {
574
+ const r = typeof e == "function" ? e({}) : e;
575
+ return r !== !1 ? O(
576
+ me(document, "visibilitychange").pipe(
577
+ $(() => !document.hidden),
578
+ p(() => ({
567
579
  type: "refetch",
568
- ignoreStale: shouldRunTrigger === "always"
580
+ ignoreStale: r === "always"
569
581
  }))
570
- ) : EMPTY;
571
- })
572
- );
573
- };
574
- const useQueryParams = ({
575
- queryKey,
576
- queryFn,
577
- ...options
582
+ ),
583
+ me(window, "focus").pipe(
584
+ p(() => ({
585
+ type: "refetch",
586
+ ignoreStale: r === "always"
587
+ }))
588
+ )
589
+ ) : M;
590
+ })
591
+ ), Et = (t) => t.pipe(
592
+ w(({ options: { refetchOnReconnect: e = !0 } }) => {
593
+ const r = typeof e == "function" ? e({}) : e;
594
+ return r !== !1 ? me(window, "online").pipe(
595
+ p(() => ({
596
+ type: "refetch",
597
+ ignoreStale: r === "always"
598
+ }))
599
+ ) : M;
600
+ })
601
+ ), Rt = ({
602
+ queryKey: t,
603
+ queryFn: e,
604
+ ...r
578
605
  }) => {
579
- const params$ = useBehaviorSubject({ queryKey, options, queryFn });
580
- useEffect(() => {
581
- params$.current.next({
582
- queryKey,
583
- options,
584
- queryFn
606
+ const n = lt({ queryKey: t, options: r, queryFn: e });
607
+ return K(() => {
608
+ n.current.next({
609
+ queryKey: t,
610
+ options: r,
611
+ queryFn: e
585
612
  });
586
- }, [queryKey, options, queryFn, params$]);
587
- return params$;
588
- };
589
- const defaultValue = {
613
+ }, [t, r, e, n]), n;
614
+ }, Ct = {
590
615
  data: void 0,
591
- isLoading: true,
616
+ isLoading: !0,
592
617
  error: void 0,
593
618
  status: "loading",
594
619
  fetchStatus: "idle"
595
620
  };
596
- function useQuery({
597
- queryKey,
598
- queryFn,
599
- ...options
621
+ function $r({
622
+ queryKey: t,
623
+ queryFn: e,
624
+ ...r
600
625
  }) {
601
- const internalRefresh$ = useSubject();
602
- const client = useQueryClient();
603
- const params$ = useQueryParams({ queryFn, queryKey, ...options });
604
- const result = useObserve(
626
+ const n = Oe(), s = Pe(), i = Rt({ queryFn: e, queryKey: t, ...r }), u = fe(
605
627
  () => {
606
- const key$ = params$.current.pipe(map(({ queryKey: queryKey2 }) => queryKey2 ?? []));
607
- const initialTrigger$ = of(null);
608
- const newKeyTrigger$ = key$.pipe(
609
- distinctUntilChanged(arrayEqual),
610
- skip(1)
611
- );
612
- const isQueryObject = (query) => !!query && typeof query !== "function";
613
- const newObservableObjectQuery$ = params$.current.pipe(
614
- map(({ queryFn: queryFn2 }) => queryFn2),
615
- filter(isQueryObject),
616
- distinctUntilChanged(shallowEqual),
617
- isQueryObject(params$.current.getValue().queryFn) ? skip(1) : identity
618
- );
619
- const fn$ = params$.current.pipe(
620
- map(({ queryFn: queryFn2 }) => queryFn2),
621
- filter(isDefined)
628
+ const f = i.current.pipe(p(({ queryKey: v }) => v ?? [])), d = S(null), h = f.pipe(
629
+ R(Le),
630
+ B(1)
631
+ ), g = (v) => !!v && typeof v != "function", a = i.current.pipe(
632
+ p(({ queryFn: v }) => v),
633
+ $(g),
634
+ R(T),
635
+ g(i.current.getValue().queryFn) ? B(1) : le
636
+ ), c = i.current.pipe(
637
+ p(({ queryFn: v }) => v),
638
+ $(G)
639
+ ), o = i.current.pipe(p(({ options: v }) => v)), m = Ot(i.current), C = Et(i.current), b = O(
640
+ d,
641
+ h,
642
+ a
643
+ ), j = O(
644
+ n.current,
645
+ O(m, C).pipe(Ve(500))
622
646
  );
623
- const options$ = params$.current.pipe(map(({ options: options2 }) => options2));
624
- const activityRefetch$ = createActivityTrigger(params$.current);
625
- const networkRefetch$ = createNetworkTrigger(params$.current);
626
- const newQueryTrigger$ = merge(
627
- initialTrigger$,
628
- newKeyTrigger$,
629
- newObservableObjectQuery$
630
- );
631
- const trigger$ = merge(
632
- internalRefresh$.current,
633
- merge(activityRefetch$, networkRefetch$).pipe(throttleTime(500))
634
- );
635
- return newQueryTrigger$.pipe(
636
- withLatestFrom(key$),
637
- switchMap(([, key]) => {
638
- const { result$ } = client.client.query({
639
- key,
640
- fn$,
641
- options$,
642
- trigger$
647
+ return b.pipe(
648
+ D(f),
649
+ w(([, v]) => {
650
+ const { result$: E } = s.client.query({
651
+ key: v,
652
+ fn$: c,
653
+ options$: o,
654
+ trigger$: j
643
655
  });
644
- return result$.pipe(
645
- scan(
646
- (previousValue, { data: currentData, ...currentValue }) => ({
656
+ return E.pipe(
657
+ pe(
658
+ (Q, { data: z, ...Ee }) => ({
647
659
  data: void 0,
648
- ...previousValue,
649
- ...currentValue,
650
- isLoading: currentValue.status === "loading",
651
- ...currentData && {
652
- data: currentData.result
660
+ ...Q,
661
+ ...Ee,
662
+ isLoading: Ee.status === "loading",
663
+ ...z && {
664
+ data: z.result
653
665
  }
654
666
  }),
655
667
  {}
@@ -669,53 +681,49 @@ function useQuery({
669
681
  },
670
682
  {
671
683
  defaultValue: {
672
- ...defaultValue,
673
- isLoading: params$.current.getValue().options.enabled !== false
684
+ ...Ct,
685
+ isLoading: i.current.getValue().options.enabled !== !1
674
686
  }
675
687
  },
676
- [client]
677
- );
678
- const refetch = useCallback(() => {
679
- internalRefresh$.current.next({ type: "refetch", ignoreStale: true });
680
- }, [internalRefresh$]);
681
- return { ...result, refetch };
688
+ [s]
689
+ ), l = Y(() => {
690
+ n.current.next({ type: "refetch", ignoreStale: !0 });
691
+ }, [n]);
692
+ return { ...u, refetch: l };
682
693
  }
683
- function useSubscribeEffect(source, unsafeOptions, deps = []) {
684
- const options = unsafeOptions != null && !Array.isArray(unsafeOptions) ? unsafeOptions : {};
685
- const retryOption = options.retry ?? true;
686
- const isSourceFn = typeof source === "function";
687
- const makeObservable = useCallback(
688
- isSourceFn ? source : () => source,
689
- isSourceFn ? deps : [source]
690
- );
691
- const enhancerMakeObservable = useCallback(
692
- () => makeObservable().pipe(
693
- catchError((error) => {
694
- console.error(error);
695
- throw error;
694
+ function vr(t, e, r = []) {
695
+ const s = (e != null && !Array.isArray(e) ? e : {}).retry ?? !0, i = typeof t == "function", u = Y(
696
+ i ? t : () => t,
697
+ i ? r : [t]
698
+ ), l = Y(
699
+ () => u().pipe(
700
+ A((f) => {
701
+ throw console.error(f), f;
696
702
  }),
697
- retryOption ? retry() : identity
703
+ s ? et() : le
698
704
  ),
699
- [makeObservable, retryOption]
705
+ [u, s]
700
706
  );
701
- useSubscribe(enhancerMakeObservable, deps);
707
+ Se(l, r);
702
708
  }
703
- const retryOnError = (options) => retryBackoff({
704
- initialInterval: 100,
705
- ...typeof options.retry === "function" ? {
706
- shouldRetry: options.retry
709
+ const Ue = ({
710
+ retryDelay: t,
711
+ retry: e,
712
+ ...r
713
+ }) => yt({
714
+ initialInterval: typeof t == "number" ? t : 100,
715
+ ...typeof e == "function" ? {
716
+ shouldRetry: e
707
717
  } : {
708
- maxRetries: options.retry === false ? 0 : options.retry ?? 3
709
- }
710
- });
711
- const mergeResults$1 = (stream$) => stream$.pipe(
712
- scan(
713
- (acc, current) => {
714
- return {
715
- ...acc,
716
- ...current
717
- };
718
- },
718
+ maxRetries: e === !1 ? 0 : e ?? 0
719
+ },
720
+ ...r
721
+ }), xt = (t) => t.pipe(
722
+ pe(
723
+ (e, r) => ({
724
+ ...e,
725
+ ...r
726
+ }),
719
727
  {
720
728
  data: void 0,
721
729
  error: void 0,
@@ -723,347 +731,273 @@ const mergeResults$1 = (stream$) => stream$.pipe(
723
731
  status: "loading"
724
732
  }
725
733
  ),
726
- distinctUntilChanged(
727
- ({ data: prevData, ...prev }, { data: currData, ...curr }) => shallowEqual(prev, curr) && shallowEqual(prevData, currData)
734
+ R(
735
+ ({ data: e, ...r }, { data: n, ...s }) => T(r, s) && T(e, n)
728
736
  )
729
- );
730
- const resetStyle = { backgroundColor: "transparent", color: "inherit" };
731
- function createLogger(env) {
732
- const _logger = {
737
+ ), Vt = { backgroundColor: "transparent", color: "inherit" };
738
+ function je(t) {
739
+ const e = {
733
740
  namespaces: [
734
741
  {
735
742
  name: "@reactjrx",
736
743
  style: { backgroundColor: "#d02f4e", color: "white" }
737
744
  }
738
745
  ],
739
- namespace(name, style) {
740
- const logger2 = createLogger(env);
741
- logger2.namespaces.push({
742
- name,
743
- style: style ?? resetStyle
744
- });
745
- return logger2;
746
+ namespace(r, n) {
747
+ const s = je(t);
748
+ return s.namespaces.push({
749
+ name: r,
750
+ style: n ?? Vt
751
+ }), s;
746
752
  },
747
753
  printNamespaces() {
748
754
  return {
749
- namespaces: _logger.namespaces.map(({ name }) => `%c ${name} %c`).join(" "),
750
- styles: _logger.namespaces.reduce((acc, { style }) => {
751
- acc.push(
752
- `background-color: ${style.backgroundColor}; color: ${style.color};`
753
- );
754
- acc.push("background-color: transparent; color: inherit;");
755
- return acc;
756
- }, [])
755
+ namespaces: e.namespaces.map(({ name: r }) => `%c ${r} %c`).join(" "),
756
+ styles: e.namespaces.reduce((r, { style: n }) => (r.push(
757
+ `background-color: ${n.backgroundColor}; color: ${n.color};`
758
+ ), r.push("background-color: transparent; color: inherit;"), r), [])
757
759
  };
758
760
  },
759
- print(method, ...message) {
760
- if (env === "development") {
761
- const { namespaces, styles } = _logger.printNamespaces();
762
- console[method](namespaces, ...styles, ...message);
761
+ print(r, ...n) {
762
+ if (t === "development") {
763
+ const { namespaces: s, styles: i } = e.printNamespaces();
764
+ console[r](s, ...i, ...n);
763
765
  }
764
- return _logger;
766
+ return e;
765
767
  },
766
- printWithoutNamespace(method, ...message) {
767
- if (env === "development") {
768
- console[method](...message);
769
- }
770
- return _logger;
768
+ printWithoutNamespace(r, ...n) {
769
+ return t === "development" && console[r](...n), e;
771
770
  },
772
- log(...message) {
773
- return _logger.print("log", ...message);
771
+ log(...r) {
772
+ return e.print("log", ...r);
774
773
  },
775
- warn(...message) {
776
- return _logger.print("warn", ...message);
774
+ warn(...r) {
775
+ return e.print("warn", ...r);
777
776
  },
778
- error(...message) {
779
- return _logger.print("error", ...message);
777
+ error(...r) {
778
+ return e.print("error", ...r);
780
779
  },
781
- group(...message) {
782
- return _logger.print("group", ...message);
780
+ group(...r) {
781
+ return e.print("group", ...r);
783
782
  },
784
783
  groupEnd() {
785
- if (env === "development") {
786
- console.groupEnd();
787
- }
788
- return _logger;
784
+ return t === "development" && console.groupEnd(), e;
789
785
  }
790
786
  };
791
- return _logger;
787
+ return e;
792
788
  }
793
- const Logger = createLogger("production");
794
- const logger$3 = Logger.namespace("store");
795
- const createDebugger = (store$) => {
796
- return store$.pipe(
797
- map(
798
- (value) => [...value.keys()].reduce((acc, key) => {
799
- var _a;
800
- acc[key] = (_a = value.get(key)) == null ? void 0 : _a.getValue();
801
- return acc;
802
- }, {})
803
- ),
804
- distinctUntilChanged(shallowEqual)
805
- ).subscribe((value) => {
806
- logger$3.log("store", "update", value);
807
- });
808
- };
809
- const createQueryStore = () => {
810
- const store = /* @__PURE__ */ new Map();
811
- const store$ = new BehaviorSubject(store);
812
- const queryEventSubject = new Subject();
813
- const queryTriggerSubject = new Subject();
814
- const notify = () => {
815
- store$.next(store);
816
- };
817
- const setValue = (key, value) => {
818
- store.set(key, new BehaviorSubject(value));
819
- notify();
820
- };
821
- const getValue = (serializedKey) => {
822
- var _a;
823
- return (_a = store.get(serializedKey)) == null ? void 0 : _a.getValue();
824
- };
825
- const getValue$ = (key) => {
826
- return store$.pipe(
827
- map(() => store.get(key)),
828
- filter(isDefined),
829
- map((entry) => entry.getValue()),
830
- distinctUntilChanged(shallowEqual)
831
- );
832
- };
833
- const updateValue = (key, value) => {
834
- const existingObject = store.get(key);
835
- if (!existingObject)
836
- return;
837
- if (typeof value === "function") {
838
- existingObject.next({
839
- ...existingObject.getValue(),
840
- ...value(existingObject.getValue())
841
- });
842
- } else {
843
- existingObject.next({ ...existingObject.getValue(), ...value });
844
- }
845
- store$.next(store);
846
- };
847
- const updateMany = (value, predicate = () => true) => {
848
- store.forEach((oldValue$) => {
849
- const oldValue = oldValue$.getValue();
850
- if (predicate(oldValue)) {
851
- oldValue$.next({ ...oldValue, ...value });
852
- }
853
- });
854
- store$.next(store);
855
- };
856
- const deleteValue = (key) => {
857
- store.delete(key);
858
- store$.next(store);
859
- };
860
- const addRunner = (key, stream) => {
861
- updateValue(key, (old) => ({
862
- ...old,
863
- runners: [...old.runners, stream]
789
+ const X = je("production"), Tt = X.namespace("store"), Mt = (t) => t.pipe(
790
+ p(
791
+ (e) => [...e.keys()].reduce((r, n) => {
792
+ var s;
793
+ return r[n] = (s = e.get(n)) == null ? void 0 : s.getValue(), r;
794
+ }, {})
795
+ ),
796
+ R(T)
797
+ ).subscribe((e) => {
798
+ Tt.log("store", "update", e);
799
+ }), It = () => {
800
+ const t = /* @__PURE__ */ new Map(), e = new I(t), r = new F(), n = new F(), s = () => {
801
+ e.next(t);
802
+ }, i = (c, o) => {
803
+ t.set(c, new I(o)), s();
804
+ }, u = (c) => {
805
+ var o;
806
+ return (o = t.get(c)) == null ? void 0 : o.getValue();
807
+ }, l = (c) => e.pipe(
808
+ p(() => t.get(c)),
809
+ $(G),
810
+ p((o) => o.getValue()),
811
+ R(T)
812
+ ), f = (c, o) => {
813
+ const m = t.get(c);
814
+ m && (typeof o == "function" ? m.next({
815
+ ...m.getValue(),
816
+ ...o(m.getValue())
817
+ }) : m.next({ ...m.getValue(), ...o }), e.next(t));
818
+ }, d = (c, o = () => !0) => {
819
+ t.forEach((m) => {
820
+ const C = m.getValue();
821
+ o(C) && m.next({ ...C, ...c });
822
+ }), e.next(t);
823
+ }, h = (c) => {
824
+ t.delete(c), e.next(t);
825
+ }, g = (c, o) => (f(c, (m) => ({
826
+ ...m,
827
+ runners: [...m.runners, o]
828
+ })), () => {
829
+ var C;
830
+ const m = ((C = t.get(c)) == null ? void 0 : C.getValue().runners.filter((b) => b !== o)) ?? [];
831
+ f(c, (b) => ({
832
+ ...b,
833
+ runners: m
864
834
  }));
835
+ }), a = () => {
836
+ const c = Mt(e);
865
837
  return () => {
866
- var _a;
867
- const newListeners = ((_a = store.get(key)) == null ? void 0 : _a.getValue().runners.filter((reference) => reference !== stream)) ?? [];
868
- updateValue(key, (old) => ({
869
- ...old,
870
- runners: newListeners
871
- }));
872
- };
873
- };
874
- const start = () => {
875
- const debugger$ = createDebugger(store$);
876
- return () => {
877
- debugger$.unsubscribe();
838
+ c.unsubscribe();
878
839
  };
879
840
  };
880
841
  return {
881
- set: setValue,
882
- get: getValue,
883
- get$: getValue$,
884
- delete: deleteValue,
885
- update: updateValue,
886
- keys: () => store.keys(),
887
- updateMany,
888
- addRunner,
889
- store$,
890
- queryEvent$: queryEventSubject.asObservable(),
891
- dispatchQueryEvent: (event) => {
892
- queryEventSubject.next(event);
842
+ set: i,
843
+ get: u,
844
+ get$: l,
845
+ delete: h,
846
+ update: f,
847
+ keys: () => t.keys(),
848
+ updateMany: d,
849
+ addRunner: g,
850
+ store$: e,
851
+ queryEvent$: r.asObservable(),
852
+ dispatchQueryEvent: (c) => {
853
+ r.next(c);
893
854
  },
894
- queryTrigger$: queryTriggerSubject.asObservable(),
895
- dispatchQueryTrigger: (event) => {
896
- queryTriggerSubject.next(event);
855
+ queryTrigger$: n.asObservable(),
856
+ dispatchQueryTrigger: (c) => {
857
+ n.next(c);
897
858
  },
898
- size: () => store.size,
899
- start
859
+ size: () => t.size,
860
+ start: a
900
861
  };
901
- };
902
- const createQueryTrigger = ({
903
- options$,
904
- queryStore,
905
- key
862
+ }, Qt = ({
863
+ options$: t,
864
+ queryStore: e,
865
+ key: r
906
866
  }) => {
907
- const enabledOption$ = options$.pipe(
908
- map(({ enabled = true }) => enabled),
909
- distinctUntilChanged()
867
+ const s = t.pipe(
868
+ p(({ enabled: i = !0 }) => i),
869
+ R()
870
+ ).pipe(
871
+ B(1),
872
+ $((i) => i)
910
873
  );
911
- const enabledTrigger$ = enabledOption$.pipe(
912
- skip(1),
913
- filter((enabled) => enabled)
914
- );
915
- return merge(
916
- queryStore.queryTrigger$.pipe(
917
- filter((event) => key === event.key),
918
- map(({ trigger: trigger2 }) => trigger2)
874
+ return O(
875
+ e.queryTrigger$.pipe(
876
+ $((i) => r === i.key),
877
+ p(({ trigger: i }) => i)
919
878
  ),
920
- enabledTrigger$.pipe(
921
- map(() => ({
879
+ s.pipe(
880
+ p(() => ({
922
881
  type: "enabled",
923
- ignoreStale: false
882
+ ignoreStale: !1
924
883
  }))
925
884
  )
926
885
  );
927
- };
928
- const deduplicate = (key, queryStore) => (source) => {
929
- if (key === serializeKey([]))
930
- return source;
931
- return defer(() => {
932
- var _a;
933
- const sourceFromStore = (_a = queryStore.get(key)) == null ? void 0 : _a.deduplication_fn;
934
- if (sourceFromStore)
935
- return sourceFromStore;
936
- let sourceToDeduplicate;
937
- const deleteFromStore = () => {
938
- var _a2;
939
- if (((_a2 = queryStore.get(key)) == null ? void 0 : _a2.deduplication_fn) === sourceToDeduplicate) {
940
- queryStore.update(key, {
941
- deduplication_fn: void 0
942
- });
943
- }
944
- };
945
- sourceToDeduplicate = source.pipe(
946
- /**
947
- * Ideally we would want to remove the query from the store only on finalize,
948
- * which means whenever the query complete or error. Unfortunately finalize is
949
- * triggered after a new stream arrive which create a concurrency issue.
950
- * tap is triggered correctly synchronously and before a new query arrive.
951
- */
952
- tap({
953
- error: deleteFromStore,
954
- complete: deleteFromStore
955
- }),
956
- /**
957
- * Because tap is not called on unsubscription we still need to handle the case.
958
- */
959
- finalize(deleteFromStore),
960
- shareReplay({
961
- refCount: true,
962
- bufferSize: 1
963
- })
964
- );
965
- queryStore.update(key, {
966
- deduplication_fn: sourceToDeduplicate
886
+ }, Ft = (t, e) => (r) => t === N([]) ? r : se(() => {
887
+ var u;
888
+ const n = (u = e.get(t)) == null ? void 0 : u.deduplication_fn;
889
+ if (n)
890
+ return n;
891
+ let s;
892
+ const i = () => {
893
+ var l;
894
+ ((l = e.get(t)) == null ? void 0 : l.deduplication_fn) === s && e.update(t, {
895
+ deduplication_fn: void 0
967
896
  });
968
- return sourceToDeduplicate;
969
- });
970
- };
971
- const notifyQueryResult = (options$) => (stream$) => stream$.pipe(
972
- withLatestFrom(options$),
973
- map(([result, options]) => {
974
- var _a, _b;
975
- if (result.error) {
976
- (_a = options.onError) == null ? void 0 : _a.call(options, result.error);
977
- } else {
978
- (_b = options.onSuccess) == null ? void 0 : _b.call(options, result);
979
- }
980
- return result;
897
+ };
898
+ return s = r.pipe(
899
+ /**
900
+ * Ideally we would want to remove the query from the store only on finalize,
901
+ * which means whenever the query complete or error. Unfortunately finalize is
902
+ * triggered after a new stream arrive which create a concurrency issue.
903
+ * tap is triggered correctly synchronously and before a new query arrive.
904
+ */
905
+ x({
906
+ error: i,
907
+ complete: i
908
+ }),
909
+ /**
910
+ * Because tap is not called on unsubscription we still need to handle the case.
911
+ */
912
+ ae(i),
913
+ $e({
914
+ refCount: !0,
915
+ bufferSize: 1
916
+ })
917
+ ), e.update(t, {
918
+ deduplication_fn: s
919
+ }), s;
920
+ }), _t = (t) => (e) => e.pipe(
921
+ D(t),
922
+ p(([r, n]) => {
923
+ var s, i;
924
+ return r.error ? (s = n.onError) == null || s.call(n, r.error) : (i = n.onSuccess) == null || i.call(n, r), r;
981
925
  })
982
- );
983
- const registerResultInCache = ({
984
- queryStore,
985
- serializedKey,
986
- options
987
- }) => (stream) => stream.pipe(
988
- tap(({ data }) => {
989
- if (data == null ? void 0 : data.result) {
990
- const result = data == null ? void 0 : data.result;
991
- queryStore.update(serializedKey, {
992
- ...options.cacheTime !== 0 && {
993
- cache_fnResult: { result }
926
+ ), Pt = ({
927
+ queryStore: t,
928
+ serializedKey: e,
929
+ options: r
930
+ }) => (n) => n.pipe(
931
+ x(({ data: s }) => {
932
+ if (s != null && s.result) {
933
+ const i = s == null ? void 0 : s.result;
934
+ t.update(e, {
935
+ ...r.cacheTime !== 0 && {
936
+ cache_fnResult: { result: i }
994
937
  }
995
938
  });
996
939
  }
997
940
  })
998
- );
999
- const createQueryFetch = ({
1000
- options$,
1001
- options,
1002
- fn,
1003
- queryStore,
1004
- serializedKey,
1005
- trigger: trigger2,
1006
- trigger$
941
+ ), Nt = ({
942
+ options$: t,
943
+ options: e,
944
+ fn: r,
945
+ queryStore: n,
946
+ serializedKey: s,
947
+ trigger: i,
948
+ trigger$: u
1007
949
  }) => {
1008
- const enabledOption$ = options$.pipe(
1009
- map(({ enabled = true }) => enabled),
1010
- distinctUntilChanged()
1011
- );
1012
- const disabled$ = enabledOption$.pipe(
1013
- distinctUntilChanged(),
1014
- filter((enabled) => !enabled)
1015
- );
1016
- const deferredQuery = defer(() => {
1017
- const queryOrResponse = typeof fn === "function" ? fn() : fn;
1018
- return from(queryOrResponse);
1019
- });
1020
- const fnExecution$ = deferredQuery.pipe(
1021
- retryOnError(options),
1022
- deduplicate(serializedKey, queryStore),
1023
- tap(() => {
1024
- queryStore.dispatchQueryEvent({
1025
- key: serializedKey,
950
+ const f = t.pipe(
951
+ p(({ enabled: b = !0 }) => b),
952
+ R()
953
+ ).pipe(
954
+ R(),
955
+ $((b) => !b)
956
+ ), h = se(() => {
957
+ const b = typeof r == "function" ? r() : r;
958
+ return ne(b);
959
+ }).pipe(
960
+ Ue(e),
961
+ Ft(s, n),
962
+ x(() => {
963
+ n.dispatchQueryEvent({
964
+ key: s,
1026
965
  type: "fetchSuccess"
1027
- });
1028
- queryStore.update(serializedKey, {
966
+ }), n.update(s, {
1029
967
  lastFetchedAt: (/* @__PURE__ */ new Date()).getTime()
1030
968
  });
1031
969
  }),
1032
- map((result) => ({
970
+ p((b) => ({
1033
971
  status: "success",
1034
- data: { result },
972
+ data: { result: b },
1035
973
  error: void 0
1036
974
  })),
1037
- endWith({
975
+ tt({
1038
976
  fetchStatus: "idle"
1039
977
  }),
1040
- catchError((error) => {
1041
- queryStore.dispatchQueryEvent({
1042
- key: serializedKey,
1043
- type: "fetchError"
1044
- });
1045
- return of({
1046
- fetchStatus: "idle",
1047
- status: "error",
1048
- data: void 0,
1049
- error
1050
- });
1051
- }),
1052
- notifyQueryResult(options$),
1053
- registerResultInCache({ serializedKey, options, queryStore })
1054
- );
1055
- const newCache$ = queryStore.queryEvent$.pipe(
1056
- filter(
1057
- (event) => event.key === serializedKey && event.type === "queryDataSet"
978
+ A((b) => (n.dispatchQueryEvent({
979
+ key: s,
980
+ type: "fetchError"
981
+ }), S({
982
+ fetchStatus: "idle",
983
+ status: "error",
984
+ data: void 0,
985
+ error: b
986
+ }))),
987
+ _t(t),
988
+ Pt({ serializedKey: s, options: e, queryStore: n })
989
+ ), g = n.queryEvent$.pipe(
990
+ $(
991
+ (b) => b.key === s && b.type === "queryDataSet"
1058
992
  ),
1059
- map(() => {
1060
- var _a, _b;
1061
- return (_b = (_a = queryStore.get(serializedKey)) == null ? void 0 : _a.cache_fnResult) == null ? void 0 : _b.result;
993
+ p(() => {
994
+ var b, j;
995
+ return (j = (b = n.get(s)) == null ? void 0 : b.cache_fnResult) == null ? void 0 : j.result;
1062
996
  }),
1063
- filter(isDefined),
1064
- map((result) => ({
997
+ $(G),
998
+ p((b) => ({
1065
999
  status: "success",
1066
- data: { result }
1000
+ data: { result: b }
1067
1001
  })),
1068
1002
  /**
1069
1003
  * @important
@@ -1071,815 +1005,574 @@ const createQueryFetch = ({
1071
1005
  * For example if user set query data inside onSuccess callback, we simulate
1072
1006
  * a small delay to ensure it happens after.
1073
1007
  */
1074
- delay(1)
1075
- );
1076
- const execution$ = merge(
1077
- disabled$.pipe(
1078
- take(1),
1079
- map(() => ({
1008
+ rt(1)
1009
+ ), a = O(
1010
+ f.pipe(
1011
+ be(1),
1012
+ p(() => ({
1080
1013
  fetchStatus: "idle"
1081
1014
  }))
1082
1015
  ),
1083
- merge(
1084
- of({ fetchStatus: "fetching", error: void 0 }),
1085
- fnExecution$
1086
- ).pipe(takeUntil(disabled$)),
1087
- newCache$
1088
- ).pipe(takeUntil(trigger$));
1089
- const query = queryStore.get(serializedKey);
1090
- const cacheResult = query == null ? void 0 : query.cache_fnResult;
1091
- const hasCache = !!cacheResult;
1092
- const ignoreStale = trigger2.type === "refetch" && trigger2.ignoreStale;
1093
- if (hasCache) {
1094
- if (!(query == null ? void 0 : query.isStale) && !ignoreStale) {
1095
- return of({
1096
- fetchStatus: "idle",
1097
- status: "success",
1098
- data: { result: cacheResult.result },
1099
- error: void 0
1100
- });
1101
- } else {
1102
- return merge(
1103
- of({
1104
- fetchStatus: "fetching",
1105
- status: "success",
1106
- data: { result: cacheResult.result },
1107
- error: void 0
1108
- }),
1109
- execution$
1110
- );
1111
- }
1112
- }
1113
- return execution$;
1114
- };
1115
- const compareKeys = (keyA, keyB, { exact = false } = {}) => {
1116
- if (exact) {
1117
- return serializeKey(keyA) === serializeKey(keyB);
1118
- }
1119
- return keyA.reduce((acc, value, index) => {
1120
- if (!acc)
1121
- return false;
1122
- if (value === void 0) {
1123
- const hasNextItemInLineNotUndefined = keyA.slice(index, keyA.length - 1).some((item) => item !== void 0);
1124
- if (!hasNextItemInLineNotUndefined) {
1125
- return true;
1126
- }
1127
- }
1128
- return serializeObject(value) === serializeObject(keyB[index]);
1129
- }, true);
1130
- };
1131
- const logger$2 = Logger.namespace("invalidation");
1132
- const createInvalidationClient = ({
1133
- queryStore
1134
- }) => {
1135
- const invalidateQueries = ({
1136
- queryKey,
1137
- exact = false,
1138
- predicate
1016
+ O(
1017
+ S({ fetchStatus: "fetching", error: void 0 }),
1018
+ h
1019
+ ).pipe(P(f)),
1020
+ g
1021
+ ).pipe(P(u)), c = n.get(s), o = c == null ? void 0 : c.cache_fnResult, m = !!o, C = i.type === "refetch" && i.ignoreStale;
1022
+ return m ? !(c != null && c.isStale) && !C ? S({
1023
+ fetchStatus: "idle",
1024
+ status: "success",
1025
+ data: { result: o.result },
1026
+ error: void 0
1027
+ }) : O(
1028
+ S({
1029
+ fetchStatus: "fetching",
1030
+ status: "success",
1031
+ data: { result: o.result },
1032
+ error: void 0
1033
+ }),
1034
+ a
1035
+ ) : a;
1036
+ }, q = X.namespace("invalidation"), kt = ({
1037
+ queryStore: t
1038
+ }) => ({
1039
+ invalidateQueries: ({
1040
+ queryKey: r,
1041
+ exact: n = !1,
1042
+ predicate: s
1139
1043
  } = {}) => {
1140
- let keysToRefetch = [];
1141
- if (queryKey) {
1142
- logger$2.log(`invalidation requested for`, queryKey);
1143
- queryStore.updateMany({ isStale: true }, (entry) => {
1144
- const isValid = compareKeys(queryKey, entry.queryKey, { exact });
1145
- if (isValid) {
1146
- keysToRefetch.push(serializeKey(entry.queryKey));
1147
- }
1148
- return isValid;
1149
- });
1150
- } else if (predicate) {
1151
- queryStore.updateMany({ isStale: true }, (entry) => {
1152
- const isValid = predicate(entry);
1153
- if (isValid) {
1154
- keysToRefetch.push(serializeKey(entry.queryKey));
1155
- }
1156
- return isValid;
1157
- });
1158
- } else {
1159
- logger$2.log(`Invalidation requested for all queries`);
1160
- queryStore.updateMany({ isStale: true });
1161
- keysToRefetch = Array.from(queryStore.keys());
1162
- }
1163
- keysToRefetch.forEach((key) => {
1164
- queryStore.update(key, {
1044
+ let i = [];
1045
+ r ? (q.log("invalidation requested for", r), t.updateMany({ isStale: !0 }, (u) => {
1046
+ const l = te(r, u.queryKey, { exact: n });
1047
+ return l && i.push(N(u.queryKey)), l;
1048
+ })) : s ? t.updateMany({ isStale: !0 }, (u) => {
1049
+ const l = s(u);
1050
+ return l && i.push(N(u.queryKey)), l;
1051
+ }) : (q.log("Invalidation requested for all queries"), t.updateMany({ isStale: !0 }), i = Array.from(t.keys())), i.forEach((u) => {
1052
+ t.update(u, {
1165
1053
  deduplication_fn: void 0
1166
- });
1167
- queryStore.dispatchQueryTrigger({
1168
- key,
1169
- trigger: { ignoreStale: true, type: "refetch" }
1054
+ }), t.dispatchQueryTrigger({
1055
+ key: u,
1056
+ trigger: { ignoreStale: !0, type: "refetch" }
1170
1057
  });
1171
1058
  });
1172
- };
1173
- return {
1174
- invalidateQueries
1175
- };
1176
- };
1177
- const createRefetchClient = (_) => {
1178
- const pipeQueryResult = ({
1179
- options$
1180
- }) => (stream) => {
1181
- const sharedStream = stream.pipe(share());
1182
- return merge(
1183
- sharedStream,
1184
- sharedStream.pipe(
1185
- filter(
1186
- (result) => !!result.data && result.fetchStatus !== "fetching"
1059
+ }
1060
+ }), Lt = (t) => ({
1061
+ pipeQueryResult: ({
1062
+ options$: n
1063
+ }) => (s) => {
1064
+ const i = s.pipe(J());
1065
+ return O(
1066
+ i,
1067
+ i.pipe(
1068
+ $(
1069
+ (u) => !!u.data && u.fetchStatus !== "fetching"
1187
1070
  ),
1188
- distinctUntilChanged((prev, curr) => prev.data === curr.data),
1189
- withLatestFrom(options$),
1190
- map(([, { refetchInterval }]) => refetchInterval),
1191
- filter(isDefined),
1192
- switchMap((refetchInterval) => {
1193
- if (typeof refetchInterval === "number") {
1194
- return timer(refetchInterval).pipe(
1195
- map(() => ({
1196
- type: "refetch",
1197
- ignoreStale: true
1198
- })),
1199
- switchMap(() => EMPTY)
1200
- );
1201
- }
1202
- return EMPTY;
1203
- })
1071
+ R((u, l) => u.data === l.data),
1072
+ D(n),
1073
+ p(([, { refetchInterval: u }]) => u),
1074
+ $(G),
1075
+ w((u) => typeof u == "number" ? ie(u).pipe(
1076
+ p(() => ({
1077
+ type: "refetch",
1078
+ ignoreStale: !0
1079
+ })),
1080
+ w(() => M)
1081
+ ) : M)
1204
1082
  )
1205
1083
  );
1206
- };
1207
- const refetchQueries = (_2) => {
1208
- };
1209
- return {
1210
- pipeQueryResult,
1211
- refetchQueries
1212
- };
1213
- };
1214
- const difference = (a, b) => a.filter((element) => !b.includes(element));
1215
- const createQueryListener = (store, onQuery) => store.store$.pipe(
1216
- map((store2) => [...store2.keys()]),
1217
- startWith([]),
1218
- pairwise(),
1219
- mergeMap(([previousKeys, currentKeys]) => {
1220
- const newKeys = difference(currentKeys, previousKeys);
1221
- return merge(
1222
- ...newKeys.map((key) => {
1223
- const deleted$ = store.store$.pipe(
1224
- map(() => store.get(key)),
1225
- filter((item) => item === void 0)
1084
+ },
1085
+ refetchQueries: (n) => {
1086
+ }
1087
+ }), Ut = (t, e) => t.filter((r) => !e.includes(r)), jt = (t, e) => t.store$.pipe(
1088
+ p((r) => [...r.keys()]),
1089
+ Ie([]),
1090
+ oe(),
1091
+ _(([r, n]) => {
1092
+ const s = Ut(n, r);
1093
+ return O(
1094
+ ...s.map((i) => {
1095
+ const u = t.store$.pipe(
1096
+ p(() => t.get(i)),
1097
+ $((l) => l === void 0)
1226
1098
  );
1227
- return merge(NEVER, of(key)).pipe(
1228
- tap(() => {
1099
+ return O(Qe, S(i)).pipe(
1100
+ x(() => {
1229
1101
  }),
1230
- onQuery,
1231
- finalize(() => {
1102
+ e,
1103
+ ae(() => {
1232
1104
  }),
1233
- takeUntil(deleted$)
1105
+ P(u)
1234
1106
  );
1235
1107
  })
1236
1108
  );
1237
1109
  })
1238
- );
1239
- const mapStoreQueryToRunnerOptions = (stream) => stream.pipe(
1240
- switchMap((entry) => combineLatest(entry.runners)),
1241
- map((runnerValues) => runnerValues.map(({ options }) => options))
1242
- );
1243
- const mapOptionsToOption$1 = (stream) => stream.pipe(
1244
- map(
1245
- (options) => options.reduce(
1246
- (acc, value) => {
1247
- return {
1248
- ...acc,
1249
- lowestStaleTime: value.staleTime === void 0 ? acc.lowestStaleTime : Math.min(
1250
- value.staleTime ?? Infinity,
1251
- acc.lowestStaleTime ?? Infinity
1252
- )
1253
- };
1254
- },
1110
+ ), Ae = (t) => t.pipe(
1111
+ w((e) => Fe(e.runners)),
1112
+ p((e) => e.map(({ options: r }) => r))
1113
+ ), At = (t) => t.pipe(
1114
+ p(
1115
+ (e) => e.reduce(
1116
+ (r, n) => ({
1117
+ ...r,
1118
+ lowestStaleTime: n.staleTime === void 0 ? r.lowestStaleTime : Math.min(
1119
+ n.staleTime ?? 1 / 0,
1120
+ r.lowestStaleTime ?? 1 / 0
1121
+ )
1122
+ }),
1255
1123
  { lowestStaleTime: void 0 }
1256
1124
  )
1257
1125
  ),
1258
- distinctUntilChanged(shallowEqual)
1259
- );
1260
- const onlyFetchEventDone = (key) => (stream) => stream.pipe(
1261
- filter(
1262
- (event) => event.key === key && (event.type === "fetchError" || event.type === "fetchSuccess")
1126
+ R(T)
1127
+ ), Kt = (t) => (e) => e.pipe(
1128
+ $(
1129
+ (r) => r.key === t && (r.type === "fetchError" || r.type === "fetchSuccess")
1263
1130
  )
1264
- );
1265
- const markAsStale = ({
1266
- queryStore
1267
- }) => (stream) => stream.pipe(
1268
- switchMap((key) => {
1269
- const query$ = queryStore.get$(key);
1270
- return queryStore.queryEvent$.pipe(
1271
- onlyFetchEventDone(key),
1272
- switchMap(
1273
- () => query$.pipe(
1274
- mapStoreQueryToRunnerOptions,
1275
- mapOptionsToOption$1,
1276
- tap(({ lowestStaleTime = 0 }) => {
1277
- var _a;
1278
- if (lowestStaleTime === 0) {
1279
- logger$2.log(key, "marked as stale!", {
1280
- staleTime: lowestStaleTime
1281
- });
1282
- queryStore.update(key, { isStale: true });
1283
- } else if ((_a = queryStore.get(key)) == null ? void 0 : _a.isStale) {
1284
- logger$2.log(key, "marked non stale", {
1285
- staleTime: lowestStaleTime
1286
- });
1287
- queryStore.update(key, { isStale: false });
1288
- }
1131
+ ), zt = ({
1132
+ queryStore: t
1133
+ }) => (e) => e.pipe(
1134
+ w((r) => {
1135
+ const n = t.get$(r);
1136
+ return t.queryEvent$.pipe(
1137
+ Kt(r),
1138
+ w(
1139
+ () => n.pipe(
1140
+ Ae,
1141
+ At,
1142
+ x(({ lowestStaleTime: s = 0 }) => {
1143
+ var i;
1144
+ s === 0 ? (q.log(r, "marked as stale!", {
1145
+ staleTime: s
1146
+ }), t.update(r, { isStale: !0 })) : (i = t.get(r)) != null && i.isStale && (q.log(r, "marked non stale", {
1147
+ staleTime: s
1148
+ }), t.update(r, { isStale: !1 }));
1289
1149
  }),
1290
- filter(
1291
- ({ lowestStaleTime }) => lowestStaleTime !== Infinity && lowestStaleTime !== 0
1150
+ $(
1151
+ ({ lowestStaleTime: s }) => s !== 1 / 0 && s !== 0
1292
1152
  ),
1293
- switchMap(({ lowestStaleTime = 0 }) => timer(lowestStaleTime)),
1294
- tap(() => {
1295
- var _a;
1296
- if (!((_a = queryStore.get(key)) == null ? void 0 : _a.isStale)) {
1297
- logger$2.log(key, "marked as stale!");
1298
- queryStore.update(key, { isStale: true });
1299
- }
1153
+ w(({ lowestStaleTime: s = 0 }) => ie(s)),
1154
+ x(() => {
1155
+ var s;
1156
+ (s = t.get(r)) != null && s.isStale || (q.log(r, "marked as stale!"), t.update(r, { isStale: !0 }));
1300
1157
  })
1301
1158
  )
1302
1159
  ),
1303
- map(() => key)
1160
+ p(() => r)
1304
1161
  );
1305
1162
  })
1306
- );
1307
- const mapOptionsToOption = (stream) => stream.pipe(
1308
- map(
1309
- (options) => options.reduce(
1310
- (acc, value) => {
1311
- return {
1312
- ...acc,
1313
- lowestCacheTime: value.cacheTime === void 0 ? acc.lowestCacheTime : Math.min(
1314
- value.cacheTime ?? Infinity,
1315
- acc.lowestCacheTime ?? Infinity
1316
- )
1317
- };
1318
- },
1163
+ ), Jt = (t) => t.pipe(
1164
+ p(
1165
+ (e) => e.reduce(
1166
+ (r, n) => ({
1167
+ ...r,
1168
+ lowestCacheTime: n.cacheTime === void 0 ? r.lowestCacheTime : Math.min(
1169
+ n.cacheTime ?? 1 / 0,
1170
+ r.lowestCacheTime ?? 1 / 0
1171
+ )
1172
+ }),
1319
1173
  { lowestCacheTime: void 0 }
1320
1174
  )
1321
1175
  ),
1322
- distinctUntilChanged(shallowEqual)
1323
- );
1324
- const onCacheUpdate = (stream) => stream.pipe(
1325
- map((item) => item.cache_fnResult),
1326
- distinctUntilChanged(shallowEqual)
1327
- );
1328
- const invalidateCache = ({
1329
- queryStore
1330
- }) => (stream) => stream.pipe(
1331
- switchMap((key) => {
1332
- const query$ = queryStore.get$(key);
1333
- const invalidateCache$ = query$.pipe(
1334
- onCacheUpdate,
1335
- switchMap(
1336
- () => query$.pipe(
1337
- mapStoreQueryToRunnerOptions,
1338
- mapOptionsToOption,
1339
- switchMap(
1176
+ R(T)
1177
+ ), Wt = (t) => t.pipe(
1178
+ p((e) => e.cache_fnResult),
1179
+ R(T)
1180
+ ), Yt = ({
1181
+ queryStore: t
1182
+ }) => (e) => e.pipe(
1183
+ w((r) => {
1184
+ const n = t.get$(r);
1185
+ return n.pipe(
1186
+ Wt,
1187
+ w(
1188
+ () => n.pipe(
1189
+ Ae,
1190
+ Jt,
1191
+ w(
1340
1192
  ({
1341
- lowestCacheTime = 5 * 60 * 1e3
1193
+ lowestCacheTime: i = 5 * 60 * 1e3
1342
1194
  /* 5mn */
1343
- }) => timer(lowestCacheTime).pipe(
1344
- tap(() => {
1345
- queryStore.update(key, { cache_fnResult: void 0 });
1195
+ }) => ie(i).pipe(
1196
+ x(() => {
1197
+ t.update(r, { cache_fnResult: void 0 });
1346
1198
  })
1347
1199
  )
1348
1200
  )
1349
1201
  )
1350
1202
  )
1351
- );
1352
- return invalidateCache$.pipe(map(() => key));
1203
+ ).pipe(p(() => r));
1353
1204
  })
1354
- );
1355
- const garbageCache = ({
1356
- queryStore
1357
- }) => (stream) => stream.pipe(
1358
- switchMap((key) => {
1359
- const query$ = queryStore.get$(key);
1360
- return query$.pipe(
1361
- filter((entry) => !entry.cache_fnResult),
1362
- map((entry) => entry.runners.length > 0),
1363
- pairwise(),
1364
- filter(([hadRunners, hasRunners]) => hadRunners && !hasRunners),
1365
- tap(() => {
1366
- queryStore.delete(key);
1367
- }),
1368
- map(() => key)
1369
- );
1370
- })
1371
- );
1372
- const getInitialQueryEntity = ({ key }) => ({
1373
- isStale: true,
1374
- queryKey: key,
1205
+ ), Gt = ({
1206
+ queryStore: t
1207
+ }) => (e) => e.pipe(
1208
+ w((r) => t.get$(r).pipe(
1209
+ $((s) => !s.cache_fnResult),
1210
+ p((s) => s.runners.length > 0),
1211
+ oe(),
1212
+ $(([s, i]) => s && !i),
1213
+ x(() => {
1214
+ t.delete(r);
1215
+ }),
1216
+ p(() => r)
1217
+ ))
1218
+ ), Ke = ({ key: t }) => ({
1219
+ isStale: !0,
1220
+ queryKey: t,
1375
1221
  runners: []
1376
- });
1377
- const updateStoreWithNewQuery = ({
1378
- queryStore,
1379
- serializedKey,
1380
- runner$,
1381
- options$,
1382
- key
1383
- }) => (stream) => stream.pipe(
1384
- withLatestFrom(options$),
1385
- map(([trigger2, options]) => {
1386
- if (key.length === 0)
1387
- return [trigger2, void 0];
1388
- if (trigger2.type !== "initial")
1389
- return [trigger2, void 0];
1390
- if (!queryStore.get(serializedKey)) {
1391
- queryStore.set(serializedKey, getInitialQueryEntity({ key }));
1392
- } else {
1393
- queryStore.update(serializedKey, {
1394
- queryKey: key,
1395
- ...options.markStale && {
1396
- isStale: true
1397
- }
1398
- });
1222
+ }), Ht = ({
1223
+ queryStore: t,
1224
+ serializedKey: e,
1225
+ runner$: r,
1226
+ options$: n,
1227
+ key: s
1228
+ }) => (i) => i.pipe(
1229
+ D(n),
1230
+ p(([u, l]) => s.length === 0 ? [u, void 0] : u.type !== "initial" ? [u, void 0] : (t.get(e) ? t.update(e, {
1231
+ queryKey: s,
1232
+ ...l.markStale && {
1233
+ isStale: !0
1399
1234
  }
1400
- return [trigger2, queryStore.addRunner(serializedKey, runner$)];
1401
- })
1402
- );
1403
- const logger$1 = Logger.namespace("cache");
1404
- const createCacheClient = ({
1405
- queryStore
1406
- }) => {
1407
- const setQueryData = ({
1408
- queryKey,
1409
- updater
1235
+ }) : t.set(e, Ke({ key: s })), [u, t.addRunner(e, r)]))
1236
+ ), Dt = X.namespace("cache"), Xt = ({
1237
+ queryStore: t
1238
+ }) => ({
1239
+ setQueryData: ({
1240
+ queryKey: r,
1241
+ updater: n
1410
1242
  }) => {
1411
- const serializedKey = serializeKey(queryKey);
1412
- if (queryKey.length === 0)
1413
- return;
1414
- logger$1.log("set cache for query", serializeKey);
1415
- if (!queryStore.get(serializedKey)) {
1416
- queryStore.set(serializedKey, getInitialQueryEntity({ key: queryKey }));
1417
- }
1418
- queryStore.update(serializedKey, (entity) => {
1419
- var _a;
1420
- if (typeof updater === "function") {
1421
- const callableUpdater = updater;
1422
- return {
1423
- ...entity,
1424
- cache_fnResult: {
1425
- result: callableUpdater(
1426
- (_a = entity.cache_fnResult) == null ? void 0 : _a.result
1427
- )
1428
- }
1429
- };
1430
- }
1431
- return {
1432
- ...entity,
1243
+ const s = N(r);
1244
+ r.length !== 0 && (Dt.log("set cache for query", N), t.get(s) || t.set(s, Ke({ key: r })), t.update(s, (i) => {
1245
+ var u;
1246
+ return typeof n == "function" ? {
1247
+ ...i,
1248
+ cache_fnResult: {
1249
+ result: n(
1250
+ (u = i.cache_fnResult) == null ? void 0 : u.result
1251
+ )
1252
+ }
1253
+ } : {
1254
+ ...i,
1433
1255
  cache_fnResult: {
1434
- result: updater
1256
+ result: n
1435
1257
  }
1436
1258
  };
1437
- });
1438
- queryStore.dispatchQueryEvent({
1439
- key: serializedKey,
1259
+ }), t.dispatchQueryEvent({
1260
+ key: s,
1440
1261
  type: "queryDataSet"
1441
- });
1442
- };
1443
- return {
1444
- setQueryData
1445
- };
1446
- };
1447
- const logger = Logger.namespace("refetch");
1448
- const markQueryAsStaleIfRefetch = ({
1449
- key,
1450
- serializedKey,
1451
- queryStore
1452
- }) => (stream) => {
1453
- return stream.pipe(
1454
- tap((trigger2) => {
1455
- if (trigger2.type !== "refetch")
1456
- return;
1457
- const query = queryStore.get(serializedKey);
1458
- if (query && trigger2.ignoreStale && !query.isStale) {
1459
- logger.log(key, "marked stale by trigger!");
1460
- queryStore.update(serializedKey, {
1461
- isStale: true
1462
- });
1463
- }
1464
- })
1465
- );
1466
- };
1467
- const dispatchExternalRefetchToAllQueries = ({
1468
- queryStore,
1469
- serializedKey
1470
- }) => (stream) => stream.pipe(
1471
- tap((trigger2) => {
1472
- if (trigger2.type === "refetch") {
1473
- queryStore.update(serializedKey, {
1474
- deduplication_fn: void 0
1475
- });
1476
- queryStore.dispatchQueryTrigger({
1477
- key: serializedKey,
1478
- trigger: trigger2
1479
- });
1480
- }
1262
+ }));
1263
+ }
1264
+ }), Zt = X.namespace("refetch"), qt = ({
1265
+ key: t,
1266
+ serializedKey: e,
1267
+ queryStore: r
1268
+ }) => (n) => n.pipe(
1269
+ x((s) => {
1270
+ if (s.type !== "refetch")
1271
+ return;
1272
+ const i = r.get(e);
1273
+ i && s.ignoreStale && !i.isStale && (Zt.log(t, "marked stale by trigger!"), r.update(e, {
1274
+ isStale: !0
1275
+ }));
1276
+ })
1277
+ ), Bt = ({
1278
+ queryStore: t,
1279
+ serializedKey: e
1280
+ }) => (r) => r.pipe(
1281
+ x((n) => {
1282
+ n.type === "refetch" && (t.update(e, {
1283
+ deduplication_fn: void 0
1284
+ }), t.dispatchQueryTrigger({
1285
+ key: e,
1286
+ trigger: n
1287
+ }));
1481
1288
  }),
1482
- filter((trigger2) => trigger2.type !== "refetch")
1483
- );
1484
- const getDefaultMutationState = () => ({
1485
- context: void 0,
1486
- data: void 0,
1487
- error: null,
1488
- status: "idle",
1489
- submittedAt: 0,
1490
- variables: void 0
1491
- });
1492
- const mergeResults = (stream$) => stream$.pipe(
1493
- scan((acc, current) => {
1494
- return {
1495
- ...acc,
1496
- ...current,
1497
- data: current.data ?? acc.data,
1498
- error: current.error ?? acc.error
1499
- };
1500
- }, getDefaultMutationState()),
1501
- distinctUntilChanged(
1502
- ({ data: prevData, ...prev }, { data: currData, ...curr }) => shallowEqual(prev, curr) && shallowEqual(prevData, currData)
1503
- )
1504
- );
1505
- const createMutationRunner = ({
1506
- __queryFinalizeHook,
1507
- __queryInitHook,
1508
- __queryTriggerHook,
1509
- mutationKey,
1510
- mutationCache
1289
+ $((n) => n.type !== "refetch")
1290
+ ), V = (t) => se(() => {
1291
+ const e = t();
1292
+ return e instanceof Promise ? ne(e) : e instanceof Me ? e : S(e);
1293
+ }), er = ({
1294
+ variables: t,
1295
+ state: e,
1296
+ options: r
1511
1297
  }) => {
1512
- const trigger$ = new Subject();
1513
- const cancel$ = new Subject();
1514
- let closed = false;
1515
- const mapOperator$ = new BehaviorSubject(
1516
- "merge"
1517
- );
1518
- const destroy = () => {
1519
- if (closed) {
1520
- throw new Error("Trying to close an already closed mutation");
1298
+ const n = e.isPaused, s = async () => await Promise.reject(new Error("No mutationFn found")), i = r.mutationFn ?? s, l = Te(
1299
+ () => n,
1300
+ S(e.context),
1301
+ V(
1302
+ // eslint-disable-next-line @typescript-eslint/promise-function-async
1303
+ () => {
1304
+ var a;
1305
+ return ((a = r.onMutate) == null ? void 0 : a.call(r, t)) ?? void 0;
1306
+ }
1307
+ )
1308
+ ).pipe(J()), f = (a, c, o) => (console.error(a), V(
1309
+ () => {
1310
+ var C;
1311
+ return (C = r.onError) == null ? void 0 : C.call(r, a, t, c);
1521
1312
  }
1522
- closed = true;
1523
- mapOperator$.complete();
1524
- trigger$.complete();
1525
- cancel$.next();
1526
- cancel$.complete();
1527
- };
1528
- const stableMapOperator$ = mapOperator$.pipe(
1529
- filter(isDefined),
1530
- distinctUntilChanged()
1531
- );
1532
- const runner$ = stableMapOperator$.pipe(
1533
- __queryInitHook ?? identity,
1534
- mergeMap((mapOperator) => {
1535
- const switchOperator = mapOperator === "concat" ? concatMap$1 : mapOperator === "switch" ? switchMap : mergeMap;
1536
- return trigger$.pipe(
1537
- takeUntil(stableMapOperator$.pipe(skip(1))),
1538
- switchOperator(({ args }) => {
1539
- const mutation = mutationCache.findLatest({
1540
- exact: true,
1541
- mutationKey
1313
+ ).pipe(
1314
+ A(() => S(a)),
1315
+ p(
1316
+ () => ({
1317
+ failureCount: o,
1318
+ error: a,
1319
+ failureReason: a,
1320
+ context: c,
1321
+ status: "error"
1322
+ })
1323
+ )
1324
+ )), d = l.pipe(
1325
+ w((a) => (typeof i == "function" ? (
1326
+ // eslint-disable-next-line @typescript-eslint/promise-function-async
1327
+ V(() => i(t))
1328
+ ) : i).pipe(
1329
+ p(
1330
+ (o) => ({
1331
+ result: {
1332
+ data: o
1333
+ },
1334
+ error: null,
1335
+ context: a
1336
+ })
1337
+ ),
1338
+ Ue({
1339
+ ...r,
1340
+ caughtError: (o, m) => S({
1341
+ failureCount: o,
1342
+ failureReason: m
1343
+ }),
1344
+ catchError: (o, m) => f(m, a, o).pipe(
1345
+ p((C) => ({
1346
+ ...C,
1347
+ result: void 0
1348
+ }))
1349
+ )
1350
+ }),
1351
+ ve(
1352
+ ({ result: o, error: m }) => (o == null ? void 0 : o.data) === void 0 && m === void 0,
1353
+ !0
1354
+ )
1355
+ ))
1356
+ ), h = S({
1357
+ ...e,
1358
+ variables: t,
1359
+ status: "pending",
1360
+ isPaused: !1,
1361
+ failureCount: 0,
1362
+ failureReason: null,
1363
+ submittedAt: e.submittedAt ?? (/* @__PURE__ */ new Date()).getTime()
1364
+ });
1365
+ return O(
1366
+ h,
1367
+ // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
1368
+ l.pipe(p((a) => ({ context: a }))),
1369
+ d.pipe(
1370
+ w(({ result: a, error: c, ...o }) => {
1371
+ if (!a && !c)
1372
+ return S({
1373
+ ...o
1542
1374
  });
1543
- if (!mutation) {
1544
- return of({});
1375
+ const m = c ? S(null) : V(
1376
+ () => {
1377
+ var v;
1378
+ return (v = r.onSuccess) == null ? void 0 : v.call(
1379
+ r,
1380
+ a == null ? void 0 : a.data,
1381
+ t,
1382
+ o.context
1383
+ );
1545
1384
  }
1546
- const mutation$ = mutation.execute(args);
1547
- const queryIsOver$ = merge(
1548
- cancel$,
1549
- mutation$.pipe(
1550
- filter(({ status }) => status === "success" || status === "error")
1385
+ ), b = V(
1386
+ () => {
1387
+ var v;
1388
+ return (v = r.onSettled) == null ? void 0 : v.call(
1389
+ r,
1390
+ a == null ? void 0 : a.data,
1391
+ c,
1392
+ t,
1393
+ o.context
1394
+ );
1395
+ }
1396
+ ).pipe(
1397
+ A((v) => a ? S(a) : S(v))
1398
+ );
1399
+ return ue(m, b).pipe(
1400
+ ce(),
1401
+ p(
1402
+ () => c ? {
1403
+ error: c,
1404
+ data: void 0,
1405
+ variables: t,
1406
+ ...o
1407
+ } : {
1408
+ status: "success",
1409
+ error: c,
1410
+ data: a == null ? void 0 : a.data,
1411
+ variables: t,
1412
+ ...o
1413
+ }
1414
+ ),
1415
+ A(
1416
+ (v) => f(v, o.context, 0).pipe(
1417
+ p((E) => ({
1418
+ ...E,
1419
+ data: void 0
1420
+ }))
1551
1421
  )
1552
- );
1553
- const isThisCurrentFunctionLastOneCalled = trigger$.pipe(
1554
- take(1),
1555
- map(() => mapOperator === "concat"),
1556
- startWith(true),
1557
- takeUntil(queryIsOver$)
1558
- );
1559
- const result$ = combineLatest([
1560
- mutation$,
1561
- isThisCurrentFunctionLastOneCalled
1562
- ]).pipe(
1563
- map(([result, isLastMutationCalled]) => {
1564
- if ((result.status === "success" || result.status === "error") && !isLastMutationCalled) {
1565
- return {};
1566
- }
1567
- return result;
1568
- }),
1569
- mergeResults
1570
- );
1571
- return result$;
1572
- }),
1573
- mergeResults,
1574
- __queryTriggerHook ?? identity
1575
- );
1576
- }),
1577
- __queryFinalizeHook ?? identity,
1578
- shareReplay(1)
1422
+ )
1423
+ );
1424
+ })
1425
+ )
1426
+ ).pipe(
1427
+ pe((a, c) => ({
1428
+ ...a,
1429
+ ...c,
1430
+ data: c.data ?? a.data,
1431
+ error: c.error ?? a.error
1432
+ }), W()),
1433
+ R(
1434
+ ({ data: a, ...c }, { data: o, ...m }) => T(c, m) && T(a, o)
1435
+ )
1579
1436
  );
1580
- cancel$.subscribe(() => {
1581
- var _a;
1582
- (_a = mutationCache.findAll({
1583
- mutationKey,
1584
- exact: true
1585
- })) == null ? void 0 : _a.forEach((mutation) => {
1586
- mutation.cancel();
1587
- });
1588
- });
1589
- return {
1590
- mutationKey,
1591
- runner$,
1592
- trigger: ({
1593
- args,
1594
- options
1595
- }) => {
1596
- mapOperator$.next(options.mapOperator);
1597
- trigger$.next({ args, options });
1598
- },
1599
- cancel$,
1600
- destroy,
1601
- getClosed: () => closed
1602
- };
1603
1437
  };
1604
- class MutationRunners {
1605
- constructor(client) {
1606
- /**
1607
- * Contain all active mutation for a given key.
1608
- * A mutation ca have several triggers running (it is not necessarily one function running)
1609
- *
1610
- * @important
1611
- * - automatically cleaned as soon as the last mutation is done for a given key
1612
- */
1613
- __publicField(this, "mutationRunnersByKey$", new BehaviorSubject(/* @__PURE__ */ new Map()));
1614
- this.client = client;
1615
- }
1616
- /**
1617
- * @helper
1618
- */
1619
- setMutationRunnersByKey(key, value) {
1620
- const map2 = this.mutationRunnersByKey$.getValue();
1621
- map2.set(key, value);
1622
- this.mutationRunnersByKey$.next(map2);
1623
- }
1624
- /**
1625
- * @helper
1626
- */
1627
- deleteMutationRunnersByKey(key) {
1628
- const map2 = this.mutationRunnersByKey$.getValue();
1629
- map2.delete(key);
1630
- this.mutationRunnersByKey$.next(map2);
1631
- }
1632
- /**
1633
- * @helper
1634
- */
1635
- getMutationRunnersByKey(key) {
1636
- return this.mutationRunnersByKey$.getValue().get(key);
1637
- }
1638
- async mutate(params) {
1639
- const { mutationKey } = params.options;
1640
- const serializedMutationKey = serializeKey(mutationKey);
1641
- let mutationForKey = this.getMutationRunnersByKey(serializedMutationKey);
1642
- if (!mutationForKey) {
1643
- mutationForKey = {
1644
- ...createMutationRunner({
1645
- ...params.options,
1646
- client: this.client,
1647
- mutationCache: this.client.getMutationCache()
1648
- }),
1649
- mutationKey
1650
- };
1651
- this.setMutationRunnersByKey(serializedMutationKey, mutationForKey);
1652
- mutationForKey.runner$.subscribe();
1653
- this.client.getMutationCache().mutationsBy({
1654
- exact: true,
1655
- mutationKey
1656
- }).pipe(
1657
- distinctUntilChanged(shallowEqual),
1658
- skip(1),
1659
- filter((items) => items.length === 0),
1660
- take(1)
1661
- ).subscribe(() => {
1662
- mutationForKey == null ? void 0 : mutationForKey.destroy();
1663
- this.deleteMutationRunnersByKey(serializedMutationKey);
1664
- });
1665
- }
1666
- const mutation = this.client.getMutationCache().build(this.client, params.options);
1667
- mutationForKey.trigger(params);
1668
- return await new Promise((resolve, reject) => {
1669
- mutation.observeTillFinished().pipe(last()).subscribe({
1670
- error: reject,
1671
- next: resolve
1672
- });
1673
- });
1674
- }
1675
- destroy() {
1676
- this.mutationRunnersByKey$.complete();
1677
- }
1678
- }
1679
- const functionAsObservable = (fn) => {
1680
- return defer(() => {
1681
- const result = fn();
1682
- if (result instanceof Promise) {
1683
- return from(result);
1684
- }
1685
- if (result instanceof Observable) {
1686
- return result;
1687
- }
1688
- return of(result);
1689
- });
1690
- };
1691
- class Mutation {
1438
+ class tr {
1692
1439
  constructor({
1693
- options,
1694
- mutationCache
1440
+ options: e,
1441
+ mutationCache: r,
1442
+ state: n
1695
1443
  }) {
1696
- __publicField(this, "state", getDefaultMutationState());
1697
- __publicField(this, "state$");
1698
- __publicField(this, "options");
1699
- __publicField(this, "mutationCache");
1700
- __publicField(this, "observerCount", new BehaviorSubject(0));
1701
- __publicField(this, "observerCount$", this.observerCount.asObservable());
1702
- __publicField(this, "cancelSubject", new Subject());
1703
- __publicField(this, "executeSubject", new Subject());
1704
- this.options = options;
1705
- this.mutationCache = mutationCache;
1706
- this.state$ = merge(
1707
- of(this.state),
1708
- this.executeSubject.pipe(
1709
- switchMap((variables) => this.createMutation(variables)),
1710
- tap((value) => {
1711
- this.state = { ...this.state, ...value };
1712
- }),
1713
- takeUntil(this.cancelSubject)
1444
+ y(this, "mutationCache");
1445
+ y(this, "observerCount", new I(0));
1446
+ y(this, "destroySubject", new F());
1447
+ y(this, "resetSubject", new F());
1448
+ y(this, "executeSubject", new F());
1449
+ y(this, "state", W());
1450
+ y(this, "state$");
1451
+ y(this, "options");
1452
+ y(this, "observerCount$", this.observerCount.asObservable());
1453
+ y(this, "destroyed$", this.destroySubject.asObservable());
1454
+ this.options = e, this.mutationCache = r, this.state = n ?? this.state;
1455
+ const s = S(this.state), i = this.resetSubject.pipe(
1456
+ p(() => W())
1457
+ ), u = this.executeSubject.pipe(
1458
+ w(
1459
+ (l) => er({
1460
+ options: {
1461
+ ...this.options,
1462
+ onMutate: (f) => {
1463
+ const d = V(
1464
+ () => {
1465
+ var g, a;
1466
+ return (a = (g = r.config).onMutate) == null ? void 0 : a.call(
1467
+ g,
1468
+ f,
1469
+ this
1470
+ );
1471
+ }
1472
+ ), h = V(
1473
+ // eslint-disable-next-line @typescript-eslint/promise-function-async
1474
+ () => {
1475
+ var g, a;
1476
+ return ((a = (g = this.options).onMutate) == null ? void 0 : a.call(g, f)) ?? void 0;
1477
+ }
1478
+ );
1479
+ return d.pipe(_(() => h));
1480
+ },
1481
+ onError: (f, d, h) => {
1482
+ const g = V(
1483
+ () => {
1484
+ var c, o;
1485
+ return (o = (c = r.config).onError) == null ? void 0 : o.call(
1486
+ c,
1487
+ f,
1488
+ d,
1489
+ h,
1490
+ this
1491
+ );
1492
+ }
1493
+ ), a = V(
1494
+ () => {
1495
+ var c, o;
1496
+ return (o = (c = this.options).onError) == null ? void 0 : o.call(c, f, d, h);
1497
+ }
1498
+ );
1499
+ return ue(g, a).pipe(ce());
1500
+ },
1501
+ onSettled: (f, d, h, g) => {
1502
+ const a = V(
1503
+ () => {
1504
+ var o, m;
1505
+ return (m = (o = r.config).onSettled) == null ? void 0 : m.call(
1506
+ o,
1507
+ f,
1508
+ d,
1509
+ h,
1510
+ g,
1511
+ this
1512
+ );
1513
+ }
1514
+ ), c = V(
1515
+ () => {
1516
+ var o, m;
1517
+ return (m = (o = this.options).onSettled) == null ? void 0 : m.call(o, f, d, h, g);
1518
+ }
1519
+ );
1520
+ return ue(a, c).pipe(ce());
1521
+ },
1522
+ onSuccess: (f, d, h) => {
1523
+ const g = V(
1524
+ () => {
1525
+ var c, o;
1526
+ return (o = (c = r.config).onSuccess) == null ? void 0 : o.call(
1527
+ c,
1528
+ f,
1529
+ d,
1530
+ h,
1531
+ this
1532
+ );
1533
+ }
1534
+ ), a = V(
1535
+ () => {
1536
+ var c, o;
1537
+ return (o = (c = this.options).onSuccess) == null ? void 0 : o.call(c, f, d, h);
1538
+ }
1539
+ );
1540
+ return ue(g, a).pipe(ce());
1541
+ }
1542
+ },
1543
+ state: this.state,
1544
+ variables: l
1545
+ })
1714
1546
  ),
1715
- NEVER
1716
- ).pipe(
1547
+ x((l) => {
1548
+ this.state = { ...this.state, ...l };
1549
+ }),
1550
+ P(this.destroySubject)
1551
+ );
1552
+ this.state$ = O(s, u, i).pipe(
1717
1553
  /**
1718
1554
  * refCount as true somewhat make NEVER complete when there are
1719
1555
  * no more observers. I thought I should have to complete manually (which is
1720
1556
  * why we still cancel the observable when we remove it from cache)
1721
1557
  */
1722
- shareReplay({ bufferSize: 1, refCount: true }),
1723
- takeUntil(this.cancelSubject),
1724
- (source) => {
1725
- return new Observable(
1726
- (observer) => {
1727
- this.observerCount.next(this.observerCount.getValue() + 1);
1728
- const sub = source.subscribe(observer);
1729
- return () => {
1730
- this.observerCount.next(this.observerCount.getValue() - 1);
1731
- sub.unsubscribe();
1732
- };
1733
- }
1734
- );
1735
- }
1736
- );
1737
- }
1738
- createMutation(variables) {
1739
- const mutationFn = this.options.mutationFn;
1740
- const onCacheMutate$ = functionAsObservable(
1741
- () => {
1742
- var _a, _b;
1743
- return (_b = (_a = this.mutationCache.config).onMutate) == null ? void 0 : _b.call(
1744
- _a,
1745
- variables,
1746
- this
1747
- );
1748
- }
1749
- );
1750
- const onMutate = concat(
1751
- onCacheMutate$.pipe(
1752
- mergeMap(() => {
1753
- const onMutate$ = functionAsObservable(
1754
- // eslint-disable-next-line @typescript-eslint/promise-function-async
1755
- () => {
1756
- var _a, _b;
1757
- return ((_b = (_a = this.options).onMutate) == null ? void 0 : _b.call(_a, variables)) ?? void 0;
1758
- }
1759
- );
1760
- return onMutate$;
1761
- })
1762
- )
1763
- );
1764
- const queryRunner$ = onMutate.pipe(
1765
- switchMap((context) => {
1766
- const fn$ = typeof mutationFn === "function" ? (
1767
- // eslint-disable-next-line @typescript-eslint/promise-function-async
1768
- functionAsObservable(() => mutationFn(variables))
1769
- ) : mutationFn;
1770
- return fn$.pipe(
1771
- retryOnError(this.options),
1772
- take(1),
1773
- map((data) => ({ data, context, isError: false })),
1774
- catchError((error) => {
1775
- console.error(error);
1776
- const onCacheError$ = functionAsObservable(
1777
- () => {
1778
- var _a, _b;
1779
- return (_b = (_a = this.mutationCache.config).onError) == null ? void 0 : _b.call(_a, error, variables, context, this);
1780
- }
1781
- );
1782
- const onError$ = functionAsObservable(
1783
- () => {
1784
- var _a, _b;
1785
- return (_b = (_a = this.options).onError) == null ? void 0 : _b.call(_a, error, variables, context);
1786
- }
1787
- );
1788
- return concat(onCacheError$, onError$).pipe(
1789
- toArray(),
1790
- map(() => ({ data: error, context, isError: true }))
1791
- );
1792
- })
1793
- );
1558
+ $e({ bufferSize: 1, refCount: !1 }),
1559
+ P(this.destroySubject),
1560
+ ke((l) => {
1561
+ this.observerCount.next(l);
1794
1562
  })
1795
1563
  );
1796
- const initState$ = of({
1797
- ...this.state,
1798
- variables,
1799
- status: "pending",
1800
- submittedAt: (/* @__PURE__ */ new Date()).getTime()
1801
- });
1802
- const mutation$ = merge(
1803
- initState$,
1804
- queryRunner$.pipe(
1805
- switchMap(({ data: dataOrError, isError, context }) => {
1806
- const error = isError ? dataOrError : null;
1807
- const data = isError ? void 0 : dataOrError;
1808
- const onCacheSuccess$ = isError ? of(null) : functionAsObservable(
1809
- () => {
1810
- var _a, _b;
1811
- return (_b = (_a = this.mutationCache.config).onSuccess) == null ? void 0 : _b.call(
1812
- _a,
1813
- data,
1814
- variables,
1815
- context,
1816
- this
1817
- );
1818
- }
1819
- );
1820
- const onSuccess$ = isError ? of(null) : functionAsObservable(
1821
- () => {
1822
- var _a, _b;
1823
- return (_b = (_a = this.options).onSuccess) == null ? void 0 : _b.call(_a, data, variables, context);
1824
- }
1825
- );
1826
- const onCacheSettled$ = functionAsObservable(
1827
- () => {
1828
- var _a, _b;
1829
- return (_b = (_a = this.mutationCache.config).onSettled) == null ? void 0 : _b.call(
1830
- _a,
1831
- data,
1832
- error,
1833
- variables,
1834
- context,
1835
- this
1836
- );
1837
- }
1838
- );
1839
- const onSettled$ = functionAsObservable(
1840
- () => {
1841
- var _a, _b;
1842
- return (_b = (_a = this.options).onSettled) == null ? void 0 : _b.call(_a, data, error, variables, context);
1843
- }
1844
- );
1845
- const result$ = concat(
1846
- onCacheSuccess$,
1847
- onSuccess$,
1848
- onCacheSettled$,
1849
- onSettled$
1850
- ).pipe(
1851
- toArray(),
1852
- map(
1853
- () => isError ? {
1854
- status: "error",
1855
- error,
1856
- data,
1857
- context,
1858
- variables
1859
- } : {
1860
- status: "success",
1861
- error,
1862
- data,
1863
- context,
1864
- variables
1865
- }
1866
- )
1867
- );
1868
- return result$;
1869
- })
1870
- )
1871
- ).pipe(
1872
- mergeResults,
1873
- this.options.__queryRunnerHook ?? identity,
1874
- takeUntil(this.cancelSubject)
1875
- );
1876
- return mutation$;
1564
+ }
1565
+ get meta() {
1566
+ return this.options.meta;
1567
+ }
1568
+ setOptions(e) {
1569
+ this.options = { ...this.options, ...e };
1877
1570
  }
1878
1571
  observeTillFinished() {
1879
1572
  return this.state$.pipe(
1880
- takeWhile(
1881
- (result) => result.status !== "error" && result.status !== "success",
1882
- true
1573
+ ve(
1574
+ (e) => e.status !== "error" && e.status !== "success",
1575
+ !0
1883
1576
  )
1884
1577
  );
1885
1578
  }
@@ -1888,509 +1581,358 @@ class Mutation {
1888
1581
  * The resulting observable will complete as soon as the mutation
1889
1582
  * is over, unlike the state which can be re-subscribed later.
1890
1583
  */
1891
- execute(variables) {
1892
- this.executeSubject.next(variables);
1893
- this.executeSubject.complete();
1894
- return this.observeTillFinished();
1584
+ execute(e) {
1585
+ return this.executeSubject.next(e), this.executeSubject.complete(), this.observeTillFinished();
1895
1586
  }
1896
- cancel() {
1897
- this.cancelSubject.next();
1898
- this.cancelSubject.complete();
1899
- this.executeSubject.complete();
1587
+ continue() {
1588
+ return this.execute(this.state.variables);
1589
+ }
1590
+ destroy() {
1591
+ this.destroySubject.next(), this.destroySubject.complete(), this.executeSubject.complete();
1592
+ }
1593
+ reset() {
1594
+ this.resetSubject.next(), this.resetSubject.complete(), this.destroy();
1900
1595
  }
1901
1596
  }
1902
- const createPredicateForFilters = ({
1903
- mutationKey,
1904
- status,
1905
- predicate,
1906
- exact = true
1907
- } = {}) => {
1908
- const finalPredicate = (mutation) => {
1909
- if (exact && mutationKey !== void 0 && !compareKeys(mutation.options.mutationKey, mutationKey, { exact })) {
1910
- return false;
1911
- }
1912
- if (!exact && mutationKey !== void 0 && !compareKeys(mutationKey, mutation.options.mutationKey, { exact })) {
1913
- return false;
1914
- }
1915
- if (status && mutation.state.status !== status)
1916
- return false;
1917
- if (predicate) {
1918
- return predicate(mutation);
1919
- }
1920
- return true;
1921
- };
1922
- return finalPredicate;
1923
- };
1924
- class MutationCache {
1925
- constructor(config = {}) {
1926
- __publicField(this, "mutationsSubject", new BehaviorSubject([]));
1927
- __publicField(this, "mutations$", this.mutationsSubject.pipe(
1928
- map((mutations) => mutations.map(({ mutation }) => mutation)),
1929
- distinctUntilChanged(arrayEqual),
1930
- share()
1597
+ const he = ({
1598
+ mutationKey: t,
1599
+ status: e,
1600
+ predicate: r,
1601
+ exact: n = !0
1602
+ } = {}) => (i) => n && t !== void 0 && i.options.mutationKey !== void 0 && !te(i.options.mutationKey, t, { exact: n }) || !n && t !== void 0 && i.options.mutationKey !== void 0 && !te(t, i.options.mutationKey, { exact: n }) || e && i.state.status !== e ? !1 : r ? r(i) : !0;
1603
+ class rr {
1604
+ constructor(e = {}) {
1605
+ y(this, "mutationsSubject", new I([]));
1606
+ y(this, "mutations$", this.mutationsSubject.pipe(
1607
+ p((e) => e.map((r) => r)),
1608
+ R(Le),
1609
+ J()
1931
1610
  ));
1932
- __publicField(this, "added$", this.mutations$.pipe(
1933
- pairwise(),
1934
- map(
1935
- ([previous, current]) => current.filter((mutation) => !previous.includes(mutation))[0]
1611
+ y(this, "added$", this.mutations$.pipe(
1612
+ oe(),
1613
+ p(
1614
+ ([e, r]) => r.filter((n) => !e.includes(n))[0]
1936
1615
  ),
1937
- filter(isDefined),
1938
- share()
1616
+ $(G),
1617
+ J()
1939
1618
  ));
1940
- __publicField(this, "removed$", this.mutations$.pipe(
1941
- pairwise(),
1942
- map(
1943
- ([previous, current]) => previous.filter((mutation) => !current.includes(mutation))
1619
+ y(this, "removed$", this.mutations$.pipe(
1620
+ oe(),
1621
+ p(
1622
+ ([e, r]) => e.filter((n) => !r.includes(n))
1944
1623
  ),
1945
- mergeMap((removedItems) => from(removedItems)),
1946
- share()
1624
+ _((e) => ne(e)),
1625
+ J()
1947
1626
  ));
1948
- __publicField(this, "stateChange$", this.added$.pipe(
1949
- mergeMap(
1950
- (mutation) => mutation.state$.pipe(
1951
- map(() => mutation),
1952
- takeUntil(
1627
+ y(this, "stateChange$", this.added$.pipe(
1628
+ _(
1629
+ (e) => e.state$.pipe(
1630
+ p(() => e),
1631
+ P(
1953
1632
  this.removed$.pipe(
1954
- filter((removedMutation) => removedMutation === mutation)
1633
+ $((r) => r === e)
1955
1634
  )
1956
1635
  )
1957
1636
  )
1958
1637
  ),
1959
- share()
1638
+ J()
1960
1639
  ));
1961
- this.config = config;
1962
- }
1963
- subscribe(listener) {
1964
- const sub = merge(
1965
- this.added$.pipe(
1966
- tap((mutation) => {
1967
- listener({
1968
- type: "added",
1969
- mutation
1970
- });
1971
- })
1972
- ),
1973
- this.removed$.pipe(
1974
- tap((mutation) => {
1975
- listener({
1976
- type: "removed",
1977
- mutation
1978
- });
1979
- })
1980
- ),
1981
- this.stateChange$.pipe(
1982
- tap((mutation) => {
1983
- listener({
1984
- type: "updated",
1985
- action: {
1986
- ...mutation.state,
1987
- // @todo
1988
- type: "success"
1989
- },
1990
- mutation
1991
- });
1992
- })
1993
- )
1994
- ).subscribe();
1995
- return () => {
1996
- sub.unsubscribe();
1997
- };
1640
+ this.config = e;
1998
1641
  }
1999
- build(client, options) {
2000
- const mutation = new Mutation({
1642
+ build(e, r, n) {
1643
+ const s = new tr({
2001
1644
  mutationCache: this,
2002
- // mutationId: ++this.#mutationId,
2003
- options: client.defaultMutationOptions(options)
2004
- // state
1645
+ options: e.defaultMutationOptions(r),
1646
+ state: n
2005
1647
  });
2006
- const sub = mutation.state$.pipe(
1648
+ return s.state$.pipe(
2007
1649
  /**
2008
1650
  * Once a mutation is finished and there are no more observers than us
2009
1651
  * we start the process of cleaning it up based on gc settings
2010
1652
  */
2011
- filter(({ status }) => status === "success" || status === "error"),
2012
- switchMap(
2013
- () => mutation.observerCount$.pipe(
2014
- filter((count) => count <= 1),
2015
- take(1)
1653
+ $(({ status: i }) => i === "success" || i === "error"),
1654
+ w(
1655
+ () => s.observerCount$.pipe(
1656
+ $((i) => i <= 1),
1657
+ be(1)
2016
1658
  )
2017
1659
  ),
2018
- switchMap(() => timer(mutation.options.gcTime ?? 0)),
2019
- take(1)
1660
+ // defaults to 5mn
1661
+ w(() => ie(s.options.gcTime ?? 5 * 60 * 1e3)),
1662
+ be(1)
2020
1663
  ).subscribe({
2021
1664
  complete: () => {
2022
- this.remove(mutation);
1665
+ this.mutationsSubject.next(
1666
+ this.mutationsSubject.getValue().filter((i) => s !== i)
1667
+ );
2023
1668
  }
2024
- });
2025
- this.mutationsSubject.next([
2026
- ...this.mutationsSubject.getValue(),
2027
- { mutation, sub }
2028
- ]);
2029
- return mutation;
1669
+ }), this.mutationsSubject.next([...this.mutationsSubject.getValue(), s]), s;
2030
1670
  }
2031
1671
  getAll() {
2032
1672
  return this.findAll();
2033
1673
  }
2034
- remove(mutation) {
2035
- this.removeBy({ predicate: (item) => item === mutation });
2036
- }
2037
- removeBy(filters) {
2038
- const defaultedFilters = { exact: true, ...filters };
2039
- const predicate = createPredicateForFilters(defaultedFilters);
2040
- const toRemove = this.mutationsSubject.getValue().filter(({ mutation }) => {
2041
- return predicate(mutation);
2042
- }).map(({ mutation, sub }) => {
2043
- mutation.cancel();
2044
- sub.unsubscribe();
2045
- return mutation;
2046
- });
2047
- this.mutationsSubject.next(
2048
- this.mutationsSubject.getValue().filter(({ mutation }) => !toRemove.includes(mutation))
2049
- );
2050
- }
2051
- find(filters) {
2052
- var _a;
2053
- const defaultedFilters = { exact: true, ...filters };
2054
- const predicate = createPredicateForFilters(defaultedFilters);
2055
- return (_a = this.mutationsSubject.getValue().find(({ mutation }) => predicate(mutation))) == null ? void 0 : _a.mutation;
1674
+ remove(e) {
1675
+ const r = this.mutationsSubject.getValue().find((n) => n === e);
1676
+ r == null || r.destroy();
2056
1677
  }
2057
- findLatest(filters) {
2058
- var _a;
2059
- const defaultedFilters = { exact: true, ...filters };
2060
- const predicate = createPredicateForFilters(defaultedFilters);
2061
- return (_a = this.mutationsSubject.getValue().slice().reverse().find(({ mutation }) => predicate(mutation))) == null ? void 0 : _a.mutation;
1678
+ find(e) {
1679
+ const r = { exact: !0, ...e }, n = he(r);
1680
+ return this.mutationsSubject.getValue().find((s) => n(s));
2062
1681
  }
2063
- findAll(filters = {}) {
2064
- const defaultedFilters = { exact: true, ...filters };
2065
- const predicate = createPredicateForFilters(defaultedFilters);
2066
- return this.mutationsSubject.getValue().filter(({ mutation }) => predicate(mutation)).map(({ mutation }) => mutation);
1682
+ findAll(e = {}) {
1683
+ const r = { exact: !0, ...e }, n = he(r);
1684
+ return this.mutationsSubject.getValue().filter((s) => n(s)).map((s) => s);
2067
1685
  }
2068
- mutationsBy(filters) {
2069
- const defaultedFilters = { exact: true, ...filters };
2070
- const predicate = createPredicateForFilters(defaultedFilters);
2071
- return this.mutations$.pipe(
2072
- map((mutations) => mutations.filter(predicate)),
2073
- distinctUntilChanged(arrayEqual)
2074
- );
2075
- }
2076
- mutationStateBy({
2077
- filters,
2078
- select
1686
+ observe({
1687
+ filters: e,
1688
+ select: r
2079
1689
  } = {}) {
2080
- const predicate = createPredicateForFilters(filters);
2081
- const finalSelect = select ?? ((mutation) => mutation.state);
2082
- const lastValue = this.getAll().reduce((acc, mutation) => {
2083
- const result = [...acc, mutation];
2084
- return result;
2085
- }, []).filter(predicate).map((mutation) => finalSelect(mutation));
2086
- const value$ = this.stateChange$.pipe(
2087
- startWith(),
2088
- map(() => {
2089
- const filteredMutations = this.getAll().filter(predicate);
2090
- return filteredMutations.map(finalSelect);
2091
- }),
2092
- distinctUntilChanged(shallowEqual)
2093
- );
2094
- return { value$, lastValue };
2095
- }
2096
- cancelBy(filters) {
2097
- this.findAll(filters).forEach((mutation) => {
2098
- mutation.cancel();
2099
- });
1690
+ const n = he(e), s = r ?? ((l) => l.state), i = this.getAll().reduce((l, f) => [...l, f], []).filter(n).map((l) => s(l));
1691
+ return { value$: this.stateChange$.pipe(
1692
+ Ie(),
1693
+ p(() => this.getAll().filter(n).map(s)),
1694
+ R(T)
1695
+ ), lastValue: i };
2100
1696
  }
2101
- clear() {
2102
- this.getAll().forEach((mutation) => {
2103
- this.remove(mutation);
2104
- });
2105
- }
2106
- }
2107
- class MutationObserver {
2108
- constructor(client, options) {
2109
- __publicField(this, "getDerivedState", (state) => {
2110
- return {
2111
- ...getDefaultMutationState(),
2112
- ...state,
2113
- isSuccess: state.status === "success",
2114
- isPending: state.status === "pending",
2115
- isIdle: state.status === "idle",
2116
- isError: state.status === "error"
2117
- };
2118
- });
2119
- this.client = client;
2120
- this.options = options;
2121
- }
2122
- observeBy(filters) {
2123
- const reduceStateFromMutation = (values) => {
2124
- var _a;
2125
- return values.reduce(
2126
- (acc, { state, options }) => {
2127
- if (options.mapOperator === "switch")
2128
- return state;
2129
- if (acc && state.submittedAt >= acc.submittedAt) {
2130
- return {
2131
- ...state,
2132
- data: state.data ?? acc.data,
2133
- error: state.error ?? acc.error
2134
- };
2135
- }
2136
- return acc;
2137
- },
2138
- ((_a = values[0]) == null ? void 0 : _a.state) ?? getDefaultMutationState()
2139
- );
2140
- };
2141
- const mutations = this.client.getMutationCache().findAll(filters);
2142
- const lastValue = this.getDerivedState(
2143
- reduceStateFromMutation(mutations)
2144
- );
2145
- const result$ = this.client.getMutationCache().mutationsBy(filters).pipe(
2146
- switchMap(
2147
- (mutations2) => combineLatest(
2148
- mutations2.map(
2149
- (mutation) => this.observe(mutation).pipe(
2150
- map((state) => ({ state, options: mutation.options }))
2151
- )
2152
- )
2153
- )
1697
+ /**
1698
+ * @important
1699
+ * ISO api react-query
1700
+ */
1701
+ subscribe(e) {
1702
+ const r = O(
1703
+ this.added$.pipe(
1704
+ x((n) => {
1705
+ e({
1706
+ type: "added",
1707
+ mutation: n
1708
+ });
1709
+ })
2154
1710
  ),
2155
- map(reduceStateFromMutation),
2156
- filter(isDefined),
2157
- map(this.getDerivedState),
2158
- distinctUntilChanged(shallowEqual)
2159
- );
2160
- return { result$, lastValue };
2161
- }
2162
- observe(mutation) {
2163
- return mutation.state$;
2164
- }
2165
- subscribe(subscription) {
2166
- const sub = this.client.getMutationCache().mutations$.pipe(
2167
- mergeMap((mutations) => {
2168
- const observed$ = mutations.map(
2169
- (mutation) => this.observe(mutation).pipe(
2170
- // we only want next changes
2171
- skip(1)
2172
- )
2173
- );
2174
- return merge(...observed$);
2175
- })
2176
- ).subscribe(subscription);
1711
+ this.removed$.pipe(
1712
+ x((n) => {
1713
+ e({
1714
+ type: "removed",
1715
+ mutation: n
1716
+ });
1717
+ })
1718
+ ),
1719
+ this.stateChange$.pipe(
1720
+ x((n) => {
1721
+ e({
1722
+ type: "updated",
1723
+ action: {
1724
+ ...n.state,
1725
+ type: "success"
1726
+ },
1727
+ mutation: n
1728
+ });
1729
+ })
1730
+ )
1731
+ ).subscribe();
2177
1732
  return () => {
2178
- sub.unsubscribe();
1733
+ r.unsubscribe();
2179
1734
  };
2180
1735
  }
2181
- async mutate(variables, options) {
2182
- const mergedOptions = {
2183
- ...this.options,
2184
- ...options
2185
- };
2186
- return await this.client.mutationRunners.mutate({
2187
- args: variables,
2188
- options: {
2189
- mutationFn: async () => void 0,
2190
- ...mergedOptions,
2191
- mutationKey: mergedOptions.mutationKey ?? [nanoid()]
2192
- }
1736
+ resumePausedMutations() {
1737
+ const e = this.findAll({
1738
+ predicate: (n) => n.state.isPaused
2193
1739
  });
1740
+ if (!e.length)
1741
+ return M;
1742
+ const r = e.map((n) => n.continue());
1743
+ return Fe(r);
2194
1744
  }
2195
- reset() {
2196
- this.client.getMutationCache().getAll().forEach((mutation) => {
2197
- mutation.cancel();
1745
+ clear() {
1746
+ this.getAll().forEach((e) => {
1747
+ this.remove(e);
2198
1748
  });
2199
1749
  }
2200
- destroy() {
2201
- }
2202
1750
  }
2203
- const createClient = () => {
2204
- const queryStore = createQueryStore();
2205
- const invalidationClient = createInvalidationClient({ queryStore });
2206
- const cacheClient = createCacheClient({ queryStore });
2207
- const refetchClient = createRefetchClient();
2208
- let hasCalledStart = false;
2209
- const query = ({
2210
- key,
2211
- fn$: maybeFn$,
2212
- fn: maybeFn,
2213
- trigger$: externalTrigger$ = new Subject(),
2214
- options$ = new BehaviorSubject({})
1751
+ const nr = () => {
1752
+ const t = It(), e = kt({ queryStore: t }), r = Xt({ queryStore: t }), n = Lt();
1753
+ let s = !1;
1754
+ const i = ({
1755
+ key: d,
1756
+ fn$: h,
1757
+ fn: g,
1758
+ trigger$: a = new F(),
1759
+ options$: c = new I({})
2215
1760
  }) => {
2216
- if (!hasCalledStart) {
1761
+ if (!s)
2217
1762
  throw new Error("You forgot to start client");
2218
- }
2219
- const serializedKey = serializeKey(key);
2220
- const fn$ = maybeFn$ ?? (maybeFn ? of(maybeFn) : NEVER);
2221
- Logger.log("query$)", serializedKey);
2222
- const runner$ = options$.pipe(map((options) => ({ options })));
2223
- let deleteRunner = () => {
1763
+ const o = N(d), m = h ?? (g ? S(g) : Qe);
1764
+ X.log("query$)", o);
1765
+ const C = c.pipe(p((E) => ({ options: E })));
1766
+ let b = () => {
2224
1767
  };
2225
- const trigger$ = merge(
2226
- externalTrigger$.pipe(
2227
- dispatchExternalRefetchToAllQueries({
2228
- queryStore,
2229
- serializedKey
1768
+ const j = O(
1769
+ a.pipe(
1770
+ Bt({
1771
+ queryStore: t,
1772
+ serializedKey: o
2230
1773
  })
2231
1774
  ),
2232
- createQueryTrigger({
2233
- options$,
2234
- key: serializedKey,
2235
- queryStore
1775
+ Qt({
1776
+ options$: c,
1777
+ key: o,
1778
+ queryStore: t
2236
1779
  })
2237
- ).pipe(share());
2238
- const result$ = merge(
2239
- of({
2240
- type: "initial"
2241
- }),
2242
- trigger$
2243
- ).pipe(
2244
- updateStoreWithNewQuery({
2245
- key,
2246
- queryStore,
2247
- runner$,
2248
- serializedKey,
2249
- options$
2250
- }),
2251
- map(([value, deleteRunnerFn]) => {
2252
- if (deleteRunnerFn) {
2253
- deleteRunner = deleteRunnerFn;
2254
- }
2255
- return value;
2256
- }),
2257
- markQueryAsStaleIfRefetch({
2258
- key,
2259
- options$,
2260
- queryStore,
2261
- serializedKey
2262
- }),
2263
- withLatestFrom(fn$, options$),
2264
- map(([trigger2, fn, options]) => ({ trigger: trigger2, fn, options })),
2265
- map((value) => {
2266
- Logger.log(serializedKey, "query trigger", {
2267
- trigger: value.trigger,
2268
- options: value.options
2269
- });
2270
- return value;
2271
- }),
2272
- filter(({ options }) => options.enabled !== false),
2273
- mergeMap(
2274
- ({ fn, options, trigger: trigger2 }) => createQueryFetch({
2275
- options$,
2276
- options,
2277
- fn,
2278
- queryStore,
2279
- serializedKey,
2280
- trigger: trigger2,
2281
- trigger$
2282
- })
2283
- ),
2284
- mergeResults$1,
2285
- withLatestFrom(options$),
2286
- takeWhile(([result, options]) => {
2287
- const shouldStop = result.data !== void 0 && options.terminateOnFirstResult;
2288
- return !shouldStop;
2289
- }, true),
2290
- map(([result]) => result),
2291
- finalize(() => {
2292
- deleteRunner();
2293
- })
2294
- );
1780
+ ).pipe(J());
2295
1781
  return {
2296
- result$
1782
+ result$: O(
1783
+ S({
1784
+ type: "initial"
1785
+ }),
1786
+ j
1787
+ ).pipe(
1788
+ Ht({
1789
+ key: d,
1790
+ queryStore: t,
1791
+ runner$: C,
1792
+ serializedKey: o,
1793
+ options$: c
1794
+ }),
1795
+ p(([E, Q]) => (Q && (b = Q), E)),
1796
+ qt({
1797
+ key: d,
1798
+ options$: c,
1799
+ queryStore: t,
1800
+ serializedKey: o
1801
+ }),
1802
+ D(m, c),
1803
+ p(([E, Q, z]) => ({ trigger: E, fn: Q, options: z })),
1804
+ p((E) => (X.log(o, "query trigger", {
1805
+ trigger: E.trigger,
1806
+ options: E.options
1807
+ }), E)),
1808
+ $(({ options: E }) => E.enabled !== !1),
1809
+ _(
1810
+ ({ fn: E, options: Q, trigger: z }) => Nt({
1811
+ options$: c,
1812
+ options: Q,
1813
+ fn: E,
1814
+ queryStore: t,
1815
+ serializedKey: o,
1816
+ trigger: z,
1817
+ trigger$: j
1818
+ })
1819
+ ),
1820
+ xt,
1821
+ D(c),
1822
+ ve(([E, Q]) => !(E.data !== void 0 && Q.terminateOnFirstResult), !0),
1823
+ p(([E]) => E),
1824
+ ae(() => {
1825
+ b();
1826
+ })
1827
+ )
2297
1828
  };
2298
- };
2299
- const queryListener$ = createQueryListener(
2300
- queryStore,
2301
- (stream) => stream.pipe(
2302
- switchMap((key) => {
2303
- const key$ = of(key);
2304
- return merge(
2305
- invalidateCache({
2306
- queryStore
2307
- })(key$),
2308
- markAsStale({
2309
- queryStore
2310
- })(key$),
2311
- garbageCache({
2312
- queryStore
2313
- })(key$)
1829
+ }, u = jt(
1830
+ t,
1831
+ (d) => d.pipe(
1832
+ w((h) => {
1833
+ const g = S(h);
1834
+ return O(
1835
+ Yt({
1836
+ queryStore: t
1837
+ })(g),
1838
+ zt({
1839
+ queryStore: t
1840
+ })(g),
1841
+ Gt({
1842
+ queryStore: t
1843
+ })(g)
2314
1844
  );
2315
1845
  })
2316
1846
  )
2317
1847
  );
2318
- const destroy = () => {
2319
- };
2320
- const start = () => {
2321
- hasCalledStart = true;
2322
- const queryListenerSub = queryListener$.subscribe();
2323
- const started = [queryStore.start()];
2324
- return () => {
2325
- started.forEach((destroy2) => {
2326
- destroy2();
2327
- });
2328
- queryListenerSub.unsubscribe();
2329
- };
2330
- };
2331
1848
  return {
2332
- start,
2333
- query,
2334
- queryStore,
2335
- ...invalidationClient,
2336
- ...cacheClient,
2337
- ...refetchClient,
2338
- destroy
1849
+ start: () => {
1850
+ s = !0;
1851
+ const d = u.subscribe(), h = [t.start()];
1852
+ return () => {
1853
+ h.forEach((g) => {
1854
+ g();
1855
+ }), d.unsubscribe();
1856
+ };
1857
+ },
1858
+ query: i,
1859
+ queryStore: t,
1860
+ ...e,
1861
+ ...r,
1862
+ ...n,
1863
+ destroy: () => {
1864
+ }
2339
1865
  };
2340
1866
  };
2341
- class QueryClient {
2342
- constructor({ mutationCache } = {
2343
- mutationCache: new MutationCache()
1867
+ var re;
1868
+ class Sr {
1869
+ constructor({ mutationCache: e } = {
1870
+ mutationCache: new rr()
2344
1871
  }) {
2345
- __publicField(this, "client");
2346
- __publicField(this, "mutationCache");
2347
- __publicField(this, "mutationRunners");
2348
- __publicField(this, "mutationObserver");
2349
- this.mutationCache = mutationCache;
2350
- this.mutationRunners = new MutationRunners(this);
2351
- this.mutationObserver = new MutationObserver(this);
2352
- this.client = createClient();
1872
+ y(this, "client");
1873
+ y(this, "mutationCache");
1874
+ de(this, re, /* @__PURE__ */ new Map());
1875
+ this.mutationCache = e, this.client = nr();
2353
1876
  }
2354
1877
  mount() {
2355
- const stop = this.client.start();
1878
+ const e = this.client.start();
2356
1879
  return () => {
2357
- this.mutationRunners.destroy();
2358
- stop();
1880
+ e();
2359
1881
  };
2360
1882
  }
2361
1883
  getMutationCache() {
2362
1884
  return this.mutationCache;
2363
1885
  }
2364
- defaultMutationOptions(options) {
2365
- return options;
1886
+ defaultMutationOptions(e) {
1887
+ return {
1888
+ ...(e == null ? void 0 : e.mutationKey) && this.getMutationDefaults(e.mutationKey),
1889
+ ...e
1890
+ };
1891
+ }
1892
+ getMutationDefaults(e) {
1893
+ const r = [...k(this, re).values()];
1894
+ let n = {};
1895
+ return r.forEach((s) => {
1896
+ te(e, s.mutationKey) && (n = { ...n, ...s.defaultOptions });
1897
+ }), n;
1898
+ }
1899
+ setMutationDefaults(e, r) {
1900
+ k(this, re).set(N(e), {
1901
+ mutationKey: e,
1902
+ defaultOptions: r
1903
+ });
1904
+ }
1905
+ async resumePausedMutations() {
1906
+ return await nt(this.mutationCache.resumePausedMutations());
2366
1907
  }
2367
1908
  clear() {
2368
1909
  }
2369
1910
  }
1911
+ re = new WeakMap();
2370
1912
  export {
2371
- MutationCache,
2372
- QueryClient,
2373
- QueryClientProvider,
2374
- SIGNAL_RESET,
2375
- createClient,
2376
- createLocalforageAdapter,
2377
- createSharedStoreAdapter,
2378
- exponentialBackoffDelay,
2379
- getDelay,
2380
- retryBackoff,
2381
- signal,
2382
- trigger,
2383
- useBehaviorSubject,
2384
- useLiveRef,
2385
- useMutation,
2386
- useObserve,
2387
- useObserveCallback,
2388
- usePersistSignals,
2389
- useQuery,
2390
- useQueryClient,
2391
- useSignalValue,
2392
- useSubject,
2393
- useSubscribe,
2394
- useSubscribeEffect,
2395
- useUnmountObservable
1913
+ rr as MutationCache,
1914
+ Sr as QueryClient,
1915
+ br as QueryClientProvider,
1916
+ pt as SIGNAL_RESET,
1917
+ nr as createClient,
1918
+ hr as createLocalforageAdapter,
1919
+ dr as createSharedStoreAdapter,
1920
+ bt as exponentialBackoffDelay,
1921
+ mt as getDelay,
1922
+ yt as retryBackoff,
1923
+ pr as signal,
1924
+ lr as trigger,
1925
+ lt as useBehaviorSubject,
1926
+ U as useLiveRef,
1927
+ yr as useMutation,
1928
+ fe as useObserve,
1929
+ ar as useObserveCallback,
1930
+ gr as usePersistSignals,
1931
+ $r as useQuery,
1932
+ Pe as useQueryClient,
1933
+ fr as useSignalValue,
1934
+ Oe as useSubject,
1935
+ Se as useSubscribe,
1936
+ vr as useSubscribeEffect,
1937
+ mr as useUnmountObservable
2396
1938
  };