dara-core 1.21.25__py3-none-any.whl → 1.22.0__py3-none-any.whl

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.
@@ -0,0 +1,4078 @@
1
+ // From https://unpkg.com/@tanstack/react-query@4/build/umd/index.development.js
2
+ (function (global, factory) {
3
+ typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('react-dom'), require('react')) :
4
+ typeof define === 'function' && define.amd ? define(['exports', 'react-dom', 'react'], factory) :
5
+ (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.ReactQuery = {}, global.ReactDOM, global.React));
6
+ })(this, (function (exports, ReactDOM, React) { 'use strict';
7
+
8
+ function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
9
+
10
+ function _interopNamespace(e) {
11
+ if (e && e.__esModule) return e;
12
+ var n = Object.create(null);
13
+ if (e) {
14
+ Object.keys(e).forEach(function (k) {
15
+ if (k !== 'default') {
16
+ var d = Object.getOwnPropertyDescriptor(e, k);
17
+ Object.defineProperty(n, k, d.get ? d : {
18
+ enumerable: true,
19
+ get: function () { return e[k]; }
20
+ });
21
+ }
22
+ });
23
+ }
24
+ n["default"] = e;
25
+ return Object.freeze(n);
26
+ }
27
+
28
+ var ReactDOM__namespace = /*#__PURE__*/_interopNamespace(ReactDOM);
29
+ var React__default = /*#__PURE__*/_interopDefaultLegacy(React);
30
+ var React__namespace = /*#__PURE__*/_interopNamespace(React);
31
+
32
+ class Subscribable {
33
+ constructor() {
34
+ this.listeners = new Set();
35
+ this.subscribe = this.subscribe.bind(this);
36
+ }
37
+
38
+ subscribe(listener) {
39
+ const identity = {
40
+ listener
41
+ };
42
+ this.listeners.add(identity);
43
+ this.onSubscribe();
44
+ return () => {
45
+ this.listeners.delete(identity);
46
+ this.onUnsubscribe();
47
+ };
48
+ }
49
+
50
+ hasListeners() {
51
+ return this.listeners.size > 0;
52
+ }
53
+
54
+ onSubscribe() {// Do nothing
55
+ }
56
+
57
+ onUnsubscribe() {// Do nothing
58
+ }
59
+
60
+ }
61
+
62
+ // TYPES
63
+ // UTILS
64
+ const isServer = typeof window === 'undefined' || 'Deno' in window;
65
+ function noop$1() {
66
+ return undefined;
67
+ }
68
+ function functionalUpdate(updater, input) {
69
+ return typeof updater === 'function' ? updater(input) : updater;
70
+ }
71
+ function isValidTimeout(value) {
72
+ return typeof value === 'number' && value >= 0 && value !== Infinity;
73
+ }
74
+ function difference(array1, array2) {
75
+ return array1.filter(x => !array2.includes(x));
76
+ }
77
+ function replaceAt(array, index, value) {
78
+ const copy = array.slice(0);
79
+ copy[index] = value;
80
+ return copy;
81
+ }
82
+ function timeUntilStale(updatedAt, staleTime) {
83
+ return Math.max(updatedAt + (staleTime || 0) - Date.now(), 0);
84
+ }
85
+ function parseQueryArgs(arg1, arg2, arg3) {
86
+ if (!isQueryKey(arg1)) {
87
+ return arg1;
88
+ }
89
+
90
+ if (typeof arg2 === 'function') {
91
+ return { ...arg3,
92
+ queryKey: arg1,
93
+ queryFn: arg2
94
+ };
95
+ }
96
+
97
+ return { ...arg2,
98
+ queryKey: arg1
99
+ };
100
+ }
101
+ function parseMutationArgs(arg1, arg2, arg3) {
102
+ if (isQueryKey(arg1)) {
103
+ if (typeof arg2 === 'function') {
104
+ return { ...arg3,
105
+ mutationKey: arg1,
106
+ mutationFn: arg2
107
+ };
108
+ }
109
+
110
+ return { ...arg2,
111
+ mutationKey: arg1
112
+ };
113
+ }
114
+
115
+ if (typeof arg1 === 'function') {
116
+ return { ...arg2,
117
+ mutationFn: arg1
118
+ };
119
+ }
120
+
121
+ return { ...arg1
122
+ };
123
+ }
124
+ function parseFilterArgs(arg1, arg2, arg3) {
125
+ return isQueryKey(arg1) ? [{ ...arg2,
126
+ queryKey: arg1
127
+ }, arg3] : [arg1 || {}, arg2];
128
+ }
129
+ function parseMutationFilterArgs(arg1, arg2, arg3) {
130
+ return isQueryKey(arg1) ? [{ ...arg2,
131
+ mutationKey: arg1
132
+ }, arg3] : [arg1 || {}, arg2];
133
+ }
134
+ function matchQuery(filters, query) {
135
+ const {
136
+ type = 'all',
137
+ exact,
138
+ fetchStatus,
139
+ predicate,
140
+ queryKey,
141
+ stale
142
+ } = filters;
143
+
144
+ if (isQueryKey(queryKey)) {
145
+ if (exact) {
146
+ if (query.queryHash !== hashQueryKeyByOptions(queryKey, query.options)) {
147
+ return false;
148
+ }
149
+ } else if (!partialMatchKey(query.queryKey, queryKey)) {
150
+ return false;
151
+ }
152
+ }
153
+
154
+ if (type !== 'all') {
155
+ const isActive = query.isActive();
156
+
157
+ if (type === 'active' && !isActive) {
158
+ return false;
159
+ }
160
+
161
+ if (type === 'inactive' && isActive) {
162
+ return false;
163
+ }
164
+ }
165
+
166
+ if (typeof stale === 'boolean' && query.isStale() !== stale) {
167
+ return false;
168
+ }
169
+
170
+ if (typeof fetchStatus !== 'undefined' && fetchStatus !== query.state.fetchStatus) {
171
+ return false;
172
+ }
173
+
174
+ if (predicate && !predicate(query)) {
175
+ return false;
176
+ }
177
+
178
+ return true;
179
+ }
180
+ function matchMutation(filters, mutation) {
181
+ const {
182
+ exact,
183
+ fetching,
184
+ predicate,
185
+ mutationKey
186
+ } = filters;
187
+
188
+ if (isQueryKey(mutationKey)) {
189
+ if (!mutation.options.mutationKey) {
190
+ return false;
191
+ }
192
+
193
+ if (exact) {
194
+ if (hashQueryKey(mutation.options.mutationKey) !== hashQueryKey(mutationKey)) {
195
+ return false;
196
+ }
197
+ } else if (!partialMatchKey(mutation.options.mutationKey, mutationKey)) {
198
+ return false;
199
+ }
200
+ }
201
+
202
+ if (typeof fetching === 'boolean' && mutation.state.status === 'loading' !== fetching) {
203
+ return false;
204
+ }
205
+
206
+ if (predicate && !predicate(mutation)) {
207
+ return false;
208
+ }
209
+
210
+ return true;
211
+ }
212
+ function hashQueryKeyByOptions(queryKey, options) {
213
+ const hashFn = (options == null ? void 0 : options.queryKeyHashFn) || hashQueryKey;
214
+ return hashFn(queryKey);
215
+ }
216
+ /**
217
+ * Default query keys hash function.
218
+ * Hashes the value into a stable hash.
219
+ */
220
+
221
+ function hashQueryKey(queryKey) {
222
+ return JSON.stringify(queryKey, (_, val) => isPlainObject(val) ? Object.keys(val).sort().reduce((result, key) => {
223
+ result[key] = val[key];
224
+ return result;
225
+ }, {}) : val);
226
+ }
227
+ /**
228
+ * Checks if key `b` partially matches with key `a`.
229
+ */
230
+
231
+ function partialMatchKey(a, b) {
232
+ return partialDeepEqual(a, b);
233
+ }
234
+ /**
235
+ * Checks if `b` partially matches with `a`.
236
+ */
237
+
238
+ function partialDeepEqual(a, b) {
239
+ if (a === b) {
240
+ return true;
241
+ }
242
+
243
+ if (typeof a !== typeof b) {
244
+ return false;
245
+ }
246
+
247
+ if (a && b && typeof a === 'object' && typeof b === 'object') {
248
+ return !Object.keys(b).some(key => !partialDeepEqual(a[key], b[key]));
249
+ }
250
+
251
+ return false;
252
+ }
253
+ /**
254
+ * This function returns `a` if `b` is deeply equal.
255
+ * If not, it will replace any deeply equal children of `b` with those of `a`.
256
+ * This can be used for structural sharing between JSON values for example.
257
+ */
258
+
259
+ function replaceEqualDeep(a, b) {
260
+ if (a === b) {
261
+ return a;
262
+ }
263
+
264
+ const array = isPlainArray(a) && isPlainArray(b);
265
+
266
+ if (array || isPlainObject(a) && isPlainObject(b)) {
267
+ const aSize = array ? a.length : Object.keys(a).length;
268
+ const bItems = array ? b : Object.keys(b);
269
+ const bSize = bItems.length;
270
+ const copy = array ? [] : {};
271
+ let equalItems = 0;
272
+
273
+ for (let i = 0; i < bSize; i++) {
274
+ const key = array ? i : bItems[i];
275
+ copy[key] = replaceEqualDeep(a[key], b[key]);
276
+
277
+ if (copy[key] === a[key]) {
278
+ equalItems++;
279
+ }
280
+ }
281
+
282
+ return aSize === bSize && equalItems === aSize ? a : copy;
283
+ }
284
+
285
+ return b;
286
+ }
287
+ /**
288
+ * Shallow compare objects. Only works with objects that always have the same properties.
289
+ */
290
+
291
+ function shallowEqualObjects(a, b) {
292
+ if (a && !b || b && !a) {
293
+ return false;
294
+ }
295
+
296
+ for (const key in a) {
297
+ if (a[key] !== b[key]) {
298
+ return false;
299
+ }
300
+ }
301
+
302
+ return true;
303
+ }
304
+ function isPlainArray(value) {
305
+ return Array.isArray(value) && value.length === Object.keys(value).length;
306
+ } // Copied from: https://github.com/jonschlinkert/is-plain-object
307
+
308
+ function isPlainObject(o) {
309
+ if (!hasObjectPrototype(o)) {
310
+ return false;
311
+ } // If has modified constructor
312
+
313
+
314
+ const ctor = o.constructor;
315
+
316
+ if (typeof ctor === 'undefined') {
317
+ return true;
318
+ } // If has modified prototype
319
+
320
+
321
+ const prot = ctor.prototype;
322
+
323
+ if (!hasObjectPrototype(prot)) {
324
+ return false;
325
+ } // If constructor does not have an Object-specific method
326
+
327
+
328
+ if (!prot.hasOwnProperty('isPrototypeOf')) {
329
+ return false;
330
+ } // Most likely a plain Object
331
+
332
+
333
+ return true;
334
+ }
335
+
336
+ function hasObjectPrototype(o) {
337
+ return Object.prototype.toString.call(o) === '[object Object]';
338
+ }
339
+
340
+ function isQueryKey(value) {
341
+ return Array.isArray(value);
342
+ }
343
+ function isError(value) {
344
+ return value instanceof Error;
345
+ }
346
+ function sleep(timeout) {
347
+ return new Promise(resolve => {
348
+ setTimeout(resolve, timeout);
349
+ });
350
+ }
351
+ /**
352
+ * Schedules a microtask.
353
+ * This can be useful to schedule state updates after rendering.
354
+ */
355
+
356
+ function scheduleMicrotask(callback) {
357
+ sleep(0).then(callback);
358
+ }
359
+ function getAbortController() {
360
+ if (typeof AbortController === 'function') {
361
+ return new AbortController();
362
+ }
363
+
364
+ return;
365
+ }
366
+ function replaceData(prevData, data, options) {
367
+ // Use prev data if an isDataEqual function is defined and returns `true`
368
+ if (options.isDataEqual != null && options.isDataEqual(prevData, data)) {
369
+ return prevData;
370
+ } else if (typeof options.structuralSharing === 'function') {
371
+ return options.structuralSharing(prevData, data);
372
+ } else if (options.structuralSharing !== false) {
373
+ // Structurally share data between prev and new data if needed
374
+ return replaceEqualDeep(prevData, data);
375
+ }
376
+
377
+ return data;
378
+ }
379
+
380
+ class FocusManager extends Subscribable {
381
+ constructor() {
382
+ super();
383
+
384
+ this.setup = onFocus => {
385
+ // addEventListener does not exist in React Native, but window does
386
+ // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
387
+ if (!isServer && window.addEventListener) {
388
+ const listener = () => onFocus(); // Listen to visibillitychange and focus
389
+
390
+
391
+ window.addEventListener('visibilitychange', listener, false);
392
+ window.addEventListener('focus', listener, false);
393
+ return () => {
394
+ // Be sure to unsubscribe if a new handler is set
395
+ window.removeEventListener('visibilitychange', listener);
396
+ window.removeEventListener('focus', listener);
397
+ };
398
+ }
399
+
400
+ return;
401
+ };
402
+ }
403
+
404
+ onSubscribe() {
405
+ if (!this.cleanup) {
406
+ this.setEventListener(this.setup);
407
+ }
408
+ }
409
+
410
+ onUnsubscribe() {
411
+ if (!this.hasListeners()) {
412
+ var _this$cleanup;
413
+
414
+ (_this$cleanup = this.cleanup) == null ? void 0 : _this$cleanup.call(this);
415
+ this.cleanup = undefined;
416
+ }
417
+ }
418
+
419
+ setEventListener(setup) {
420
+ var _this$cleanup2;
421
+
422
+ this.setup = setup;
423
+ (_this$cleanup2 = this.cleanup) == null ? void 0 : _this$cleanup2.call(this);
424
+ this.cleanup = setup(focused => {
425
+ if (typeof focused === 'boolean') {
426
+ this.setFocused(focused);
427
+ } else {
428
+ this.onFocus();
429
+ }
430
+ });
431
+ }
432
+
433
+ setFocused(focused) {
434
+ const changed = this.focused !== focused;
435
+
436
+ if (changed) {
437
+ this.focused = focused;
438
+ this.onFocus();
439
+ }
440
+ }
441
+
442
+ onFocus() {
443
+ this.listeners.forEach(({
444
+ listener
445
+ }) => {
446
+ listener();
447
+ });
448
+ }
449
+
450
+ isFocused() {
451
+ if (typeof this.focused === 'boolean') {
452
+ return this.focused;
453
+ } // document global can be unavailable in react native
454
+
455
+
456
+ if (typeof document === 'undefined') {
457
+ return true;
458
+ }
459
+
460
+ return [undefined, 'visible', 'prerender'].includes(document.visibilityState);
461
+ }
462
+
463
+ }
464
+ const focusManager = new FocusManager();
465
+
466
+ const onlineEvents = ['online', 'offline'];
467
+ class OnlineManager extends Subscribable {
468
+ constructor() {
469
+ super();
470
+
471
+ this.setup = onOnline => {
472
+ // addEventListener does not exist in React Native, but window does
473
+ // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
474
+ if (!isServer && window.addEventListener) {
475
+ const listener = () => onOnline(); // Listen to online
476
+
477
+
478
+ onlineEvents.forEach(event => {
479
+ window.addEventListener(event, listener, false);
480
+ });
481
+ return () => {
482
+ // Be sure to unsubscribe if a new handler is set
483
+ onlineEvents.forEach(event => {
484
+ window.removeEventListener(event, listener);
485
+ });
486
+ };
487
+ }
488
+
489
+ return;
490
+ };
491
+ }
492
+
493
+ onSubscribe() {
494
+ if (!this.cleanup) {
495
+ this.setEventListener(this.setup);
496
+ }
497
+ }
498
+
499
+ onUnsubscribe() {
500
+ if (!this.hasListeners()) {
501
+ var _this$cleanup;
502
+
503
+ (_this$cleanup = this.cleanup) == null ? void 0 : _this$cleanup.call(this);
504
+ this.cleanup = undefined;
505
+ }
506
+ }
507
+
508
+ setEventListener(setup) {
509
+ var _this$cleanup2;
510
+
511
+ this.setup = setup;
512
+ (_this$cleanup2 = this.cleanup) == null ? void 0 : _this$cleanup2.call(this);
513
+ this.cleanup = setup(online => {
514
+ if (typeof online === 'boolean') {
515
+ this.setOnline(online);
516
+ } else {
517
+ this.onOnline();
518
+ }
519
+ });
520
+ }
521
+
522
+ setOnline(online) {
523
+ const changed = this.online !== online;
524
+
525
+ if (changed) {
526
+ this.online = online;
527
+ this.onOnline();
528
+ }
529
+ }
530
+
531
+ onOnline() {
532
+ this.listeners.forEach(({
533
+ listener
534
+ }) => {
535
+ listener();
536
+ });
537
+ }
538
+
539
+ isOnline() {
540
+ if (typeof this.online === 'boolean') {
541
+ return this.online;
542
+ }
543
+
544
+ if (typeof navigator === 'undefined' || typeof navigator.onLine === 'undefined') {
545
+ return true;
546
+ }
547
+
548
+ return navigator.onLine;
549
+ }
550
+
551
+ }
552
+ const onlineManager = new OnlineManager();
553
+
554
+ function defaultRetryDelay(failureCount) {
555
+ return Math.min(1000 * 2 ** failureCount, 30000);
556
+ }
557
+
558
+ function canFetch(networkMode) {
559
+ return (networkMode != null ? networkMode : 'online') === 'online' ? onlineManager.isOnline() : true;
560
+ }
561
+ class CancelledError {
562
+ constructor(options) {
563
+ this.revert = options == null ? void 0 : options.revert;
564
+ this.silent = options == null ? void 0 : options.silent;
565
+ }
566
+
567
+ }
568
+ function isCancelledError(value) {
569
+ return value instanceof CancelledError;
570
+ }
571
+ function createRetryer(config) {
572
+ let isRetryCancelled = false;
573
+ let failureCount = 0;
574
+ let isResolved = false;
575
+ let continueFn;
576
+ let promiseResolve;
577
+ let promiseReject;
578
+ const promise = new Promise((outerResolve, outerReject) => {
579
+ promiseResolve = outerResolve;
580
+ promiseReject = outerReject;
581
+ });
582
+
583
+ const cancel = cancelOptions => {
584
+ if (!isResolved) {
585
+ reject(new CancelledError(cancelOptions));
586
+ config.abort == null ? void 0 : config.abort();
587
+ }
588
+ };
589
+
590
+ const cancelRetry = () => {
591
+ isRetryCancelled = true;
592
+ };
593
+
594
+ const continueRetry = () => {
595
+ isRetryCancelled = false;
596
+ };
597
+
598
+ const shouldPause = () => !focusManager.isFocused() || config.networkMode !== 'always' && !onlineManager.isOnline();
599
+
600
+ const resolve = value => {
601
+ if (!isResolved) {
602
+ isResolved = true;
603
+ config.onSuccess == null ? void 0 : config.onSuccess(value);
604
+ continueFn == null ? void 0 : continueFn();
605
+ promiseResolve(value);
606
+ }
607
+ };
608
+
609
+ const reject = value => {
610
+ if (!isResolved) {
611
+ isResolved = true;
612
+ config.onError == null ? void 0 : config.onError(value);
613
+ continueFn == null ? void 0 : continueFn();
614
+ promiseReject(value);
615
+ }
616
+ };
617
+
618
+ const pause = () => {
619
+ return new Promise(continueResolve => {
620
+ continueFn = value => {
621
+ const canContinue = isResolved || !shouldPause();
622
+
623
+ if (canContinue) {
624
+ continueResolve(value);
625
+ }
626
+
627
+ return canContinue;
628
+ };
629
+
630
+ config.onPause == null ? void 0 : config.onPause();
631
+ }).then(() => {
632
+ continueFn = undefined;
633
+
634
+ if (!isResolved) {
635
+ config.onContinue == null ? void 0 : config.onContinue();
636
+ }
637
+ });
638
+ }; // Create loop function
639
+
640
+
641
+ const run = () => {
642
+ // Do nothing if already resolved
643
+ if (isResolved) {
644
+ return;
645
+ }
646
+
647
+ let promiseOrValue; // Execute query
648
+
649
+ try {
650
+ promiseOrValue = config.fn();
651
+ } catch (error) {
652
+ promiseOrValue = Promise.reject(error);
653
+ }
654
+
655
+ Promise.resolve(promiseOrValue).then(resolve).catch(error => {
656
+ var _config$retry, _config$retryDelay;
657
+
658
+ // Stop if the fetch is already resolved
659
+ if (isResolved) {
660
+ return;
661
+ } // Do we need to retry the request?
662
+
663
+
664
+ const retry = (_config$retry = config.retry) != null ? _config$retry : 3;
665
+ const retryDelay = (_config$retryDelay = config.retryDelay) != null ? _config$retryDelay : defaultRetryDelay;
666
+ const delay = typeof retryDelay === 'function' ? retryDelay(failureCount, error) : retryDelay;
667
+ const shouldRetry = retry === true || typeof retry === 'number' && failureCount < retry || typeof retry === 'function' && retry(failureCount, error);
668
+
669
+ if (isRetryCancelled || !shouldRetry) {
670
+ // We are done if the query does not need to be retried
671
+ reject(error);
672
+ return;
673
+ }
674
+
675
+ failureCount++; // Notify on fail
676
+
677
+ config.onFail == null ? void 0 : config.onFail(failureCount, error); // Delay
678
+
679
+ sleep(delay) // Pause if the document is not visible or when the device is offline
680
+ .then(() => {
681
+ if (shouldPause()) {
682
+ return pause();
683
+ }
684
+
685
+ return;
686
+ }).then(() => {
687
+ if (isRetryCancelled) {
688
+ reject(error);
689
+ } else {
690
+ run();
691
+ }
692
+ });
693
+ });
694
+ }; // Start loop
695
+
696
+
697
+ if (canFetch(config.networkMode)) {
698
+ run();
699
+ } else {
700
+ pause().then(run);
701
+ }
702
+
703
+ return {
704
+ promise,
705
+ cancel,
706
+ continue: () => {
707
+ const didContinue = continueFn == null ? void 0 : continueFn();
708
+ return didContinue ? promise : Promise.resolve();
709
+ },
710
+ cancelRetry,
711
+ continueRetry
712
+ };
713
+ }
714
+
715
+ const defaultLogger = console;
716
+
717
+ function createNotifyManager() {
718
+ let queue = [];
719
+ let transactions = 0;
720
+
721
+ let notifyFn = callback => {
722
+ callback();
723
+ };
724
+
725
+ let batchNotifyFn = callback => {
726
+ callback();
727
+ };
728
+
729
+ const batch = callback => {
730
+ let result;
731
+ transactions++;
732
+
733
+ try {
734
+ result = callback();
735
+ } finally {
736
+ transactions--;
737
+
738
+ if (!transactions) {
739
+ flush();
740
+ }
741
+ }
742
+
743
+ return result;
744
+ };
745
+
746
+ const schedule = callback => {
747
+ if (transactions) {
748
+ queue.push(callback);
749
+ } else {
750
+ scheduleMicrotask(() => {
751
+ notifyFn(callback);
752
+ });
753
+ }
754
+ };
755
+ /**
756
+ * All calls to the wrapped function will be batched.
757
+ */
758
+
759
+
760
+ const batchCalls = callback => {
761
+ return (...args) => {
762
+ schedule(() => {
763
+ callback(...args);
764
+ });
765
+ };
766
+ };
767
+
768
+ const flush = () => {
769
+ const originalQueue = queue;
770
+ queue = [];
771
+
772
+ if (originalQueue.length) {
773
+ scheduleMicrotask(() => {
774
+ batchNotifyFn(() => {
775
+ originalQueue.forEach(callback => {
776
+ notifyFn(callback);
777
+ });
778
+ });
779
+ });
780
+ }
781
+ };
782
+ /**
783
+ * Use this method to set a custom notify function.
784
+ * This can be used to for example wrap notifications with `React.act` while running tests.
785
+ */
786
+
787
+
788
+ const setNotifyFunction = fn => {
789
+ notifyFn = fn;
790
+ };
791
+ /**
792
+ * Use this method to set a custom function to batch notifications together into a single tick.
793
+ * By default React Query will use the batch function provided by ReactDOM or React Native.
794
+ */
795
+
796
+
797
+ const setBatchNotifyFunction = fn => {
798
+ batchNotifyFn = fn;
799
+ };
800
+
801
+ return {
802
+ batch,
803
+ batchCalls,
804
+ schedule,
805
+ setNotifyFunction,
806
+ setBatchNotifyFunction
807
+ };
808
+ } // SINGLETON
809
+
810
+ const notifyManager = createNotifyManager();
811
+
812
+ class Removable {
813
+ destroy() {
814
+ this.clearGcTimeout();
815
+ }
816
+
817
+ scheduleGc() {
818
+ this.clearGcTimeout();
819
+
820
+ if (isValidTimeout(this.cacheTime)) {
821
+ this.gcTimeout = setTimeout(() => {
822
+ this.optionalRemove();
823
+ }, this.cacheTime);
824
+ }
825
+ }
826
+
827
+ updateCacheTime(newCacheTime) {
828
+ // Default to 5 minutes (Infinity for server-side) if no cache time is set
829
+ this.cacheTime = Math.max(this.cacheTime || 0, newCacheTime != null ? newCacheTime : isServer ? Infinity : 5 * 60 * 1000);
830
+ }
831
+
832
+ clearGcTimeout() {
833
+ if (this.gcTimeout) {
834
+ clearTimeout(this.gcTimeout);
835
+ this.gcTimeout = undefined;
836
+ }
837
+ }
838
+
839
+ }
840
+
841
+ // CLASS
842
+ class Query extends Removable {
843
+ constructor(config) {
844
+ super();
845
+ this.abortSignalConsumed = false;
846
+ this.defaultOptions = config.defaultOptions;
847
+ this.setOptions(config.options);
848
+ this.observers = [];
849
+ this.cache = config.cache;
850
+ this.logger = config.logger || defaultLogger;
851
+ this.queryKey = config.queryKey;
852
+ this.queryHash = config.queryHash;
853
+ this.initialState = config.state || getDefaultState$1(this.options);
854
+ this.state = this.initialState;
855
+ this.scheduleGc();
856
+ }
857
+
858
+ get meta() {
859
+ return this.options.meta;
860
+ }
861
+
862
+ setOptions(options) {
863
+ this.options = { ...this.defaultOptions,
864
+ ...options
865
+ };
866
+ this.updateCacheTime(this.options.cacheTime);
867
+ }
868
+
869
+ optionalRemove() {
870
+ if (!this.observers.length && this.state.fetchStatus === 'idle') {
871
+ this.cache.remove(this);
872
+ }
873
+ }
874
+
875
+ setData(newData, options) {
876
+ const data = replaceData(this.state.data, newData, this.options); // Set data and mark it as cached
877
+
878
+ this.dispatch({
879
+ data,
880
+ type: 'success',
881
+ dataUpdatedAt: options == null ? void 0 : options.updatedAt,
882
+ manual: options == null ? void 0 : options.manual
883
+ });
884
+ return data;
885
+ }
886
+
887
+ setState(state, setStateOptions) {
888
+ this.dispatch({
889
+ type: 'setState',
890
+ state,
891
+ setStateOptions
892
+ });
893
+ }
894
+
895
+ cancel(options) {
896
+ var _this$retryer;
897
+
898
+ const promise = this.promise;
899
+ (_this$retryer = this.retryer) == null ? void 0 : _this$retryer.cancel(options);
900
+ return promise ? promise.then(noop$1).catch(noop$1) : Promise.resolve();
901
+ }
902
+
903
+ destroy() {
904
+ super.destroy();
905
+ this.cancel({
906
+ silent: true
907
+ });
908
+ }
909
+
910
+ reset() {
911
+ this.destroy();
912
+ this.setState(this.initialState);
913
+ }
914
+
915
+ isActive() {
916
+ return this.observers.some(observer => observer.options.enabled !== false);
917
+ }
918
+
919
+ isDisabled() {
920
+ return this.getObserversCount() > 0 && !this.isActive();
921
+ }
922
+
923
+ isStale() {
924
+ return this.state.isInvalidated || !this.state.dataUpdatedAt || this.observers.some(observer => observer.getCurrentResult().isStale);
925
+ }
926
+
927
+ isStaleByTime(staleTime = 0) {
928
+ return this.state.isInvalidated || !this.state.dataUpdatedAt || !timeUntilStale(this.state.dataUpdatedAt, staleTime);
929
+ }
930
+
931
+ onFocus() {
932
+ var _this$retryer2;
933
+
934
+ const observer = this.observers.find(x => x.shouldFetchOnWindowFocus());
935
+
936
+ if (observer) {
937
+ observer.refetch({
938
+ cancelRefetch: false
939
+ });
940
+ } // Continue fetch if currently paused
941
+
942
+
943
+ (_this$retryer2 = this.retryer) == null ? void 0 : _this$retryer2.continue();
944
+ }
945
+
946
+ onOnline() {
947
+ var _this$retryer3;
948
+
949
+ const observer = this.observers.find(x => x.shouldFetchOnReconnect());
950
+
951
+ if (observer) {
952
+ observer.refetch({
953
+ cancelRefetch: false
954
+ });
955
+ } // Continue fetch if currently paused
956
+
957
+
958
+ (_this$retryer3 = this.retryer) == null ? void 0 : _this$retryer3.continue();
959
+ }
960
+
961
+ addObserver(observer) {
962
+ if (!this.observers.includes(observer)) {
963
+ this.observers.push(observer); // Stop the query from being garbage collected
964
+
965
+ this.clearGcTimeout();
966
+ this.cache.notify({
967
+ type: 'observerAdded',
968
+ query: this,
969
+ observer
970
+ });
971
+ }
972
+ }
973
+
974
+ removeObserver(observer) {
975
+ if (this.observers.includes(observer)) {
976
+ this.observers = this.observers.filter(x => x !== observer);
977
+
978
+ if (!this.observers.length) {
979
+ // If the transport layer does not support cancellation
980
+ // we'll let the query continue so the result can be cached
981
+ if (this.retryer) {
982
+ if (this.abortSignalConsumed) {
983
+ this.retryer.cancel({
984
+ revert: true
985
+ });
986
+ } else {
987
+ this.retryer.cancelRetry();
988
+ }
989
+ }
990
+
991
+ this.scheduleGc();
992
+ }
993
+
994
+ this.cache.notify({
995
+ type: 'observerRemoved',
996
+ query: this,
997
+ observer
998
+ });
999
+ }
1000
+ }
1001
+
1002
+ getObserversCount() {
1003
+ return this.observers.length;
1004
+ }
1005
+
1006
+ invalidate() {
1007
+ if (!this.state.isInvalidated) {
1008
+ this.dispatch({
1009
+ type: 'invalidate'
1010
+ });
1011
+ }
1012
+ }
1013
+
1014
+ fetch(options, fetchOptions) {
1015
+ var _this$options$behavio, _context$fetchOptions;
1016
+
1017
+ if (this.state.fetchStatus !== 'idle') {
1018
+ if (this.state.dataUpdatedAt && fetchOptions != null && fetchOptions.cancelRefetch) {
1019
+ // Silently cancel current fetch if the user wants to cancel refetches
1020
+ this.cancel({
1021
+ silent: true
1022
+ });
1023
+ } else if (this.promise) {
1024
+ var _this$retryer4;
1025
+
1026
+ // make sure that retries that were potentially cancelled due to unmounts can continue
1027
+ (_this$retryer4 = this.retryer) == null ? void 0 : _this$retryer4.continueRetry(); // Return current promise if we are already fetching
1028
+
1029
+ return this.promise;
1030
+ }
1031
+ } // Update config if passed, otherwise the config from the last execution is used
1032
+
1033
+
1034
+ if (options) {
1035
+ this.setOptions(options);
1036
+ } // Use the options from the first observer with a query function if no function is found.
1037
+ // This can happen when the query is hydrated or created with setQueryData.
1038
+
1039
+
1040
+ if (!this.options.queryFn) {
1041
+ const observer = this.observers.find(x => x.options.queryFn);
1042
+
1043
+ if (observer) {
1044
+ this.setOptions(observer.options);
1045
+ }
1046
+ }
1047
+
1048
+ {
1049
+ if (!Array.isArray(this.options.queryKey)) {
1050
+ this.logger.error("As of v4, queryKey needs to be an Array. If you are using a string like 'repoData', please change it to an Array, e.g. ['repoData']");
1051
+ }
1052
+ }
1053
+
1054
+ const abortController = getAbortController(); // Create query function context
1055
+
1056
+ const queryFnContext = {
1057
+ queryKey: this.queryKey,
1058
+ pageParam: undefined,
1059
+ meta: this.meta
1060
+ }; // Adds an enumerable signal property to the object that
1061
+ // which sets abortSignalConsumed to true when the signal
1062
+ // is read.
1063
+
1064
+ const addSignalProperty = object => {
1065
+ Object.defineProperty(object, 'signal', {
1066
+ enumerable: true,
1067
+ get: () => {
1068
+ if (abortController) {
1069
+ this.abortSignalConsumed = true;
1070
+ return abortController.signal;
1071
+ }
1072
+
1073
+ return undefined;
1074
+ }
1075
+ });
1076
+ };
1077
+
1078
+ addSignalProperty(queryFnContext); // Create fetch function
1079
+
1080
+ const fetchFn = () => {
1081
+ if (!this.options.queryFn) {
1082
+ return Promise.reject("Missing queryFn for queryKey '" + this.options.queryHash + "'");
1083
+ }
1084
+
1085
+ this.abortSignalConsumed = false;
1086
+ return this.options.queryFn(queryFnContext);
1087
+ }; // Trigger behavior hook
1088
+
1089
+
1090
+ const context = {
1091
+ fetchOptions,
1092
+ options: this.options,
1093
+ queryKey: this.queryKey,
1094
+ state: this.state,
1095
+ fetchFn
1096
+ };
1097
+ addSignalProperty(context);
1098
+ (_this$options$behavio = this.options.behavior) == null ? void 0 : _this$options$behavio.onFetch(context); // Store state in case the current fetch needs to be reverted
1099
+
1100
+ this.revertState = this.state; // Set to fetching state if not already in it
1101
+
1102
+ if (this.state.fetchStatus === 'idle' || this.state.fetchMeta !== ((_context$fetchOptions = context.fetchOptions) == null ? void 0 : _context$fetchOptions.meta)) {
1103
+ var _context$fetchOptions2;
1104
+
1105
+ this.dispatch({
1106
+ type: 'fetch',
1107
+ meta: (_context$fetchOptions2 = context.fetchOptions) == null ? void 0 : _context$fetchOptions2.meta
1108
+ });
1109
+ }
1110
+
1111
+ const onError = error => {
1112
+ // Optimistically update state if needed
1113
+ if (!(isCancelledError(error) && error.silent)) {
1114
+ this.dispatch({
1115
+ type: 'error',
1116
+ error: error
1117
+ });
1118
+ }
1119
+
1120
+ if (!isCancelledError(error)) {
1121
+ var _this$cache$config$on, _this$cache$config, _this$cache$config$on2, _this$cache$config2;
1122
+
1123
+ // Notify cache callback
1124
+ (_this$cache$config$on = (_this$cache$config = this.cache.config).onError) == null ? void 0 : _this$cache$config$on.call(_this$cache$config, error, this);
1125
+ (_this$cache$config$on2 = (_this$cache$config2 = this.cache.config).onSettled) == null ? void 0 : _this$cache$config$on2.call(_this$cache$config2, this.state.data, error, this);
1126
+
1127
+ {
1128
+ this.logger.error(error);
1129
+ }
1130
+ }
1131
+
1132
+ if (!this.isFetchingOptimistic) {
1133
+ // Schedule query gc after fetching
1134
+ this.scheduleGc();
1135
+ }
1136
+
1137
+ this.isFetchingOptimistic = false;
1138
+ }; // Try to fetch the data
1139
+
1140
+
1141
+ this.retryer = createRetryer({
1142
+ fn: context.fetchFn,
1143
+ abort: abortController == null ? void 0 : abortController.abort.bind(abortController),
1144
+ onSuccess: data => {
1145
+ var _this$cache$config$on3, _this$cache$config3, _this$cache$config$on4, _this$cache$config4;
1146
+
1147
+ if (typeof data === 'undefined') {
1148
+ {
1149
+ this.logger.error("Query data cannot be undefined. Please make sure to return a value other than undefined from your query function. Affected query key: " + this.queryHash);
1150
+ }
1151
+
1152
+ onError(new Error(this.queryHash + " data is undefined"));
1153
+ return;
1154
+ }
1155
+
1156
+ this.setData(data); // Notify cache callback
1157
+
1158
+ (_this$cache$config$on3 = (_this$cache$config3 = this.cache.config).onSuccess) == null ? void 0 : _this$cache$config$on3.call(_this$cache$config3, data, this);
1159
+ (_this$cache$config$on4 = (_this$cache$config4 = this.cache.config).onSettled) == null ? void 0 : _this$cache$config$on4.call(_this$cache$config4, data, this.state.error, this);
1160
+
1161
+ if (!this.isFetchingOptimistic) {
1162
+ // Schedule query gc after fetching
1163
+ this.scheduleGc();
1164
+ }
1165
+
1166
+ this.isFetchingOptimistic = false;
1167
+ },
1168
+ onError,
1169
+ onFail: (failureCount, error) => {
1170
+ this.dispatch({
1171
+ type: 'failed',
1172
+ failureCount,
1173
+ error
1174
+ });
1175
+ },
1176
+ onPause: () => {
1177
+ this.dispatch({
1178
+ type: 'pause'
1179
+ });
1180
+ },
1181
+ onContinue: () => {
1182
+ this.dispatch({
1183
+ type: 'continue'
1184
+ });
1185
+ },
1186
+ retry: context.options.retry,
1187
+ retryDelay: context.options.retryDelay,
1188
+ networkMode: context.options.networkMode
1189
+ });
1190
+ this.promise = this.retryer.promise;
1191
+ return this.promise;
1192
+ }
1193
+
1194
+ dispatch(action) {
1195
+ const reducer = state => {
1196
+ var _action$meta, _action$dataUpdatedAt;
1197
+
1198
+ switch (action.type) {
1199
+ case 'failed':
1200
+ return { ...state,
1201
+ fetchFailureCount: action.failureCount,
1202
+ fetchFailureReason: action.error
1203
+ };
1204
+
1205
+ case 'pause':
1206
+ return { ...state,
1207
+ fetchStatus: 'paused'
1208
+ };
1209
+
1210
+ case 'continue':
1211
+ return { ...state,
1212
+ fetchStatus: 'fetching'
1213
+ };
1214
+
1215
+ case 'fetch':
1216
+ return { ...state,
1217
+ fetchFailureCount: 0,
1218
+ fetchFailureReason: null,
1219
+ fetchMeta: (_action$meta = action.meta) != null ? _action$meta : null,
1220
+ fetchStatus: canFetch(this.options.networkMode) ? 'fetching' : 'paused',
1221
+ ...(!state.dataUpdatedAt && {
1222
+ error: null,
1223
+ status: 'loading'
1224
+ })
1225
+ };
1226
+
1227
+ case 'success':
1228
+ return { ...state,
1229
+ data: action.data,
1230
+ dataUpdateCount: state.dataUpdateCount + 1,
1231
+ dataUpdatedAt: (_action$dataUpdatedAt = action.dataUpdatedAt) != null ? _action$dataUpdatedAt : Date.now(),
1232
+ error: null,
1233
+ isInvalidated: false,
1234
+ status: 'success',
1235
+ ...(!action.manual && {
1236
+ fetchStatus: 'idle',
1237
+ fetchFailureCount: 0,
1238
+ fetchFailureReason: null
1239
+ })
1240
+ };
1241
+
1242
+ case 'error':
1243
+ const error = action.error;
1244
+
1245
+ if (isCancelledError(error) && error.revert && this.revertState) {
1246
+ return { ...this.revertState,
1247
+ fetchStatus: 'idle'
1248
+ };
1249
+ }
1250
+
1251
+ return { ...state,
1252
+ error: error,
1253
+ errorUpdateCount: state.errorUpdateCount + 1,
1254
+ errorUpdatedAt: Date.now(),
1255
+ fetchFailureCount: state.fetchFailureCount + 1,
1256
+ fetchFailureReason: error,
1257
+ fetchStatus: 'idle',
1258
+ status: 'error'
1259
+ };
1260
+
1261
+ case 'invalidate':
1262
+ return { ...state,
1263
+ isInvalidated: true
1264
+ };
1265
+
1266
+ case 'setState':
1267
+ return { ...state,
1268
+ ...action.state
1269
+ };
1270
+ }
1271
+ };
1272
+
1273
+ this.state = reducer(this.state);
1274
+ notifyManager.batch(() => {
1275
+ this.observers.forEach(observer => {
1276
+ observer.onQueryUpdate(action);
1277
+ });
1278
+ this.cache.notify({
1279
+ query: this,
1280
+ type: 'updated',
1281
+ action
1282
+ });
1283
+ });
1284
+ }
1285
+
1286
+ }
1287
+
1288
+ function getDefaultState$1(options) {
1289
+ const data = typeof options.initialData === 'function' ? options.initialData() : options.initialData;
1290
+ const hasData = typeof data !== 'undefined';
1291
+ const initialDataUpdatedAt = hasData ? typeof options.initialDataUpdatedAt === 'function' ? options.initialDataUpdatedAt() : options.initialDataUpdatedAt : 0;
1292
+ return {
1293
+ data,
1294
+ dataUpdateCount: 0,
1295
+ dataUpdatedAt: hasData ? initialDataUpdatedAt != null ? initialDataUpdatedAt : Date.now() : 0,
1296
+ error: null,
1297
+ errorUpdateCount: 0,
1298
+ errorUpdatedAt: 0,
1299
+ fetchFailureCount: 0,
1300
+ fetchFailureReason: null,
1301
+ fetchMeta: null,
1302
+ isInvalidated: false,
1303
+ status: hasData ? 'success' : 'loading',
1304
+ fetchStatus: 'idle'
1305
+ };
1306
+ }
1307
+
1308
+ // CLASS
1309
+ class QueryCache extends Subscribable {
1310
+ constructor(config) {
1311
+ super();
1312
+ this.config = config || {};
1313
+ this.queries = [];
1314
+ this.queriesMap = {};
1315
+ }
1316
+
1317
+ build(client, options, state) {
1318
+ var _options$queryHash;
1319
+
1320
+ const queryKey = options.queryKey;
1321
+ const queryHash = (_options$queryHash = options.queryHash) != null ? _options$queryHash : hashQueryKeyByOptions(queryKey, options);
1322
+ let query = this.get(queryHash);
1323
+
1324
+ if (!query) {
1325
+ query = new Query({
1326
+ cache: this,
1327
+ logger: client.getLogger(),
1328
+ queryKey,
1329
+ queryHash,
1330
+ options: client.defaultQueryOptions(options),
1331
+ state,
1332
+ defaultOptions: client.getQueryDefaults(queryKey)
1333
+ });
1334
+ this.add(query);
1335
+ }
1336
+
1337
+ return query;
1338
+ }
1339
+
1340
+ add(query) {
1341
+ if (!this.queriesMap[query.queryHash]) {
1342
+ this.queriesMap[query.queryHash] = query;
1343
+ this.queries.push(query);
1344
+ this.notify({
1345
+ type: 'added',
1346
+ query
1347
+ });
1348
+ }
1349
+ }
1350
+
1351
+ remove(query) {
1352
+ const queryInMap = this.queriesMap[query.queryHash];
1353
+
1354
+ if (queryInMap) {
1355
+ query.destroy();
1356
+ this.queries = this.queries.filter(x => x !== query);
1357
+
1358
+ if (queryInMap === query) {
1359
+ delete this.queriesMap[query.queryHash];
1360
+ }
1361
+
1362
+ this.notify({
1363
+ type: 'removed',
1364
+ query
1365
+ });
1366
+ }
1367
+ }
1368
+
1369
+ clear() {
1370
+ notifyManager.batch(() => {
1371
+ this.queries.forEach(query => {
1372
+ this.remove(query);
1373
+ });
1374
+ });
1375
+ }
1376
+
1377
+ get(queryHash) {
1378
+ return this.queriesMap[queryHash];
1379
+ }
1380
+
1381
+ getAll() {
1382
+ return this.queries;
1383
+ }
1384
+
1385
+ /**
1386
+ * @deprecated This method should be used with only one object argument.
1387
+ */
1388
+ find(arg1, arg2) {
1389
+ const [filters] = parseFilterArgs(arg1, arg2);
1390
+
1391
+ if (typeof filters.exact === 'undefined') {
1392
+ filters.exact = true;
1393
+ }
1394
+
1395
+ return this.queries.find(query => matchQuery(filters, query));
1396
+ }
1397
+
1398
+ /**
1399
+ * @deprecated This method should be used with only one object argument.
1400
+ */
1401
+ findAll(arg1, arg2) {
1402
+ const [filters] = parseFilterArgs(arg1, arg2);
1403
+ return Object.keys(filters).length > 0 ? this.queries.filter(query => matchQuery(filters, query)) : this.queries;
1404
+ }
1405
+
1406
+ notify(event) {
1407
+ notifyManager.batch(() => {
1408
+ this.listeners.forEach(({
1409
+ listener
1410
+ }) => {
1411
+ listener(event);
1412
+ });
1413
+ });
1414
+ }
1415
+
1416
+ onFocus() {
1417
+ notifyManager.batch(() => {
1418
+ this.queries.forEach(query => {
1419
+ query.onFocus();
1420
+ });
1421
+ });
1422
+ }
1423
+
1424
+ onOnline() {
1425
+ notifyManager.batch(() => {
1426
+ this.queries.forEach(query => {
1427
+ query.onOnline();
1428
+ });
1429
+ });
1430
+ }
1431
+
1432
+ }
1433
+
1434
+ // CLASS
1435
+ class Mutation extends Removable {
1436
+ constructor(config) {
1437
+ super();
1438
+ this.defaultOptions = config.defaultOptions;
1439
+ this.mutationId = config.mutationId;
1440
+ this.mutationCache = config.mutationCache;
1441
+ this.logger = config.logger || defaultLogger;
1442
+ this.observers = [];
1443
+ this.state = config.state || getDefaultState();
1444
+ this.setOptions(config.options);
1445
+ this.scheduleGc();
1446
+ }
1447
+
1448
+ setOptions(options) {
1449
+ this.options = { ...this.defaultOptions,
1450
+ ...options
1451
+ };
1452
+ this.updateCacheTime(this.options.cacheTime);
1453
+ }
1454
+
1455
+ get meta() {
1456
+ return this.options.meta;
1457
+ }
1458
+
1459
+ setState(state) {
1460
+ this.dispatch({
1461
+ type: 'setState',
1462
+ state
1463
+ });
1464
+ }
1465
+
1466
+ addObserver(observer) {
1467
+ if (!this.observers.includes(observer)) {
1468
+ this.observers.push(observer); // Stop the mutation from being garbage collected
1469
+
1470
+ this.clearGcTimeout();
1471
+ this.mutationCache.notify({
1472
+ type: 'observerAdded',
1473
+ mutation: this,
1474
+ observer
1475
+ });
1476
+ }
1477
+ }
1478
+
1479
+ removeObserver(observer) {
1480
+ this.observers = this.observers.filter(x => x !== observer);
1481
+ this.scheduleGc();
1482
+ this.mutationCache.notify({
1483
+ type: 'observerRemoved',
1484
+ mutation: this,
1485
+ observer
1486
+ });
1487
+ }
1488
+
1489
+ optionalRemove() {
1490
+ if (!this.observers.length) {
1491
+ if (this.state.status === 'loading') {
1492
+ this.scheduleGc();
1493
+ } else {
1494
+ this.mutationCache.remove(this);
1495
+ }
1496
+ }
1497
+ }
1498
+
1499
+ continue() {
1500
+ var _this$retryer$continu, _this$retryer;
1501
+
1502
+ return (_this$retryer$continu = (_this$retryer = this.retryer) == null ? void 0 : _this$retryer.continue()) != null ? _this$retryer$continu : this.execute();
1503
+ }
1504
+
1505
+ async execute() {
1506
+ const executeMutation = () => {
1507
+ var _this$options$retry;
1508
+
1509
+ this.retryer = createRetryer({
1510
+ fn: () => {
1511
+ if (!this.options.mutationFn) {
1512
+ return Promise.reject('No mutationFn found');
1513
+ }
1514
+
1515
+ return this.options.mutationFn(this.state.variables);
1516
+ },
1517
+ onFail: (failureCount, error) => {
1518
+ this.dispatch({
1519
+ type: 'failed',
1520
+ failureCount,
1521
+ error
1522
+ });
1523
+ },
1524
+ onPause: () => {
1525
+ this.dispatch({
1526
+ type: 'pause'
1527
+ });
1528
+ },
1529
+ onContinue: () => {
1530
+ this.dispatch({
1531
+ type: 'continue'
1532
+ });
1533
+ },
1534
+ retry: (_this$options$retry = this.options.retry) != null ? _this$options$retry : 0,
1535
+ retryDelay: this.options.retryDelay,
1536
+ networkMode: this.options.networkMode
1537
+ });
1538
+ return this.retryer.promise;
1539
+ };
1540
+
1541
+ const restored = this.state.status === 'loading';
1542
+
1543
+ try {
1544
+ var _this$mutationCache$c3, _this$mutationCache$c4, _this$options$onSucce, _this$options2, _this$mutationCache$c5, _this$mutationCache$c6, _this$options$onSettl, _this$options3;
1545
+
1546
+ if (!restored) {
1547
+ var _this$mutationCache$c, _this$mutationCache$c2, _this$options$onMutat, _this$options;
1548
+
1549
+ this.dispatch({
1550
+ type: 'loading',
1551
+ variables: this.options.variables
1552
+ }); // Notify cache callback
1553
+
1554
+ await ((_this$mutationCache$c = (_this$mutationCache$c2 = this.mutationCache.config).onMutate) == null ? void 0 : _this$mutationCache$c.call(_this$mutationCache$c2, this.state.variables, this));
1555
+ const context = await ((_this$options$onMutat = (_this$options = this.options).onMutate) == null ? void 0 : _this$options$onMutat.call(_this$options, this.state.variables));
1556
+
1557
+ if (context !== this.state.context) {
1558
+ this.dispatch({
1559
+ type: 'loading',
1560
+ context,
1561
+ variables: this.state.variables
1562
+ });
1563
+ }
1564
+ }
1565
+
1566
+ const data = await executeMutation(); // Notify cache callback
1567
+
1568
+ await ((_this$mutationCache$c3 = (_this$mutationCache$c4 = this.mutationCache.config).onSuccess) == null ? void 0 : _this$mutationCache$c3.call(_this$mutationCache$c4, data, this.state.variables, this.state.context, this));
1569
+ await ((_this$options$onSucce = (_this$options2 = this.options).onSuccess) == null ? void 0 : _this$options$onSucce.call(_this$options2, data, this.state.variables, this.state.context)); // Notify cache callback
1570
+
1571
+ await ((_this$mutationCache$c5 = (_this$mutationCache$c6 = this.mutationCache.config).onSettled) == null ? void 0 : _this$mutationCache$c5.call(_this$mutationCache$c6, data, null, this.state.variables, this.state.context, this));
1572
+ await ((_this$options$onSettl = (_this$options3 = this.options).onSettled) == null ? void 0 : _this$options$onSettl.call(_this$options3, data, null, this.state.variables, this.state.context));
1573
+ this.dispatch({
1574
+ type: 'success',
1575
+ data
1576
+ });
1577
+ return data;
1578
+ } catch (error) {
1579
+ try {
1580
+ var _this$mutationCache$c7, _this$mutationCache$c8, _this$options$onError, _this$options4, _this$mutationCache$c9, _this$mutationCache$c10, _this$options$onSettl2, _this$options5;
1581
+
1582
+ // Notify cache callback
1583
+ await ((_this$mutationCache$c7 = (_this$mutationCache$c8 = this.mutationCache.config).onError) == null ? void 0 : _this$mutationCache$c7.call(_this$mutationCache$c8, error, this.state.variables, this.state.context, this));
1584
+
1585
+ if ("development" !== 'production') {
1586
+ this.logger.error(error);
1587
+ }
1588
+
1589
+ await ((_this$options$onError = (_this$options4 = this.options).onError) == null ? void 0 : _this$options$onError.call(_this$options4, error, this.state.variables, this.state.context)); // Notify cache callback
1590
+
1591
+ await ((_this$mutationCache$c9 = (_this$mutationCache$c10 = this.mutationCache.config).onSettled) == null ? void 0 : _this$mutationCache$c9.call(_this$mutationCache$c10, undefined, error, this.state.variables, this.state.context, this));
1592
+ await ((_this$options$onSettl2 = (_this$options5 = this.options).onSettled) == null ? void 0 : _this$options$onSettl2.call(_this$options5, undefined, error, this.state.variables, this.state.context));
1593
+ throw error;
1594
+ } finally {
1595
+ this.dispatch({
1596
+ type: 'error',
1597
+ error: error
1598
+ });
1599
+ }
1600
+ }
1601
+ }
1602
+
1603
+ dispatch(action) {
1604
+ const reducer = state => {
1605
+ switch (action.type) {
1606
+ case 'failed':
1607
+ return { ...state,
1608
+ failureCount: action.failureCount,
1609
+ failureReason: action.error
1610
+ };
1611
+
1612
+ case 'pause':
1613
+ return { ...state,
1614
+ isPaused: true
1615
+ };
1616
+
1617
+ case 'continue':
1618
+ return { ...state,
1619
+ isPaused: false
1620
+ };
1621
+
1622
+ case 'loading':
1623
+ return { ...state,
1624
+ context: action.context,
1625
+ data: undefined,
1626
+ failureCount: 0,
1627
+ failureReason: null,
1628
+ error: null,
1629
+ isPaused: !canFetch(this.options.networkMode),
1630
+ status: 'loading',
1631
+ variables: action.variables
1632
+ };
1633
+
1634
+ case 'success':
1635
+ return { ...state,
1636
+ data: action.data,
1637
+ failureCount: 0,
1638
+ failureReason: null,
1639
+ error: null,
1640
+ status: 'success',
1641
+ isPaused: false
1642
+ };
1643
+
1644
+ case 'error':
1645
+ return { ...state,
1646
+ data: undefined,
1647
+ error: action.error,
1648
+ failureCount: state.failureCount + 1,
1649
+ failureReason: action.error,
1650
+ isPaused: false,
1651
+ status: 'error'
1652
+ };
1653
+
1654
+ case 'setState':
1655
+ return { ...state,
1656
+ ...action.state
1657
+ };
1658
+ }
1659
+ };
1660
+
1661
+ this.state = reducer(this.state);
1662
+ notifyManager.batch(() => {
1663
+ this.observers.forEach(observer => {
1664
+ observer.onMutationUpdate(action);
1665
+ });
1666
+ this.mutationCache.notify({
1667
+ mutation: this,
1668
+ type: 'updated',
1669
+ action
1670
+ });
1671
+ });
1672
+ }
1673
+
1674
+ }
1675
+ function getDefaultState() {
1676
+ return {
1677
+ context: undefined,
1678
+ data: undefined,
1679
+ error: null,
1680
+ failureCount: 0,
1681
+ failureReason: null,
1682
+ isPaused: false,
1683
+ status: 'idle',
1684
+ variables: undefined
1685
+ };
1686
+ }
1687
+
1688
+ // CLASS
1689
+ class MutationCache extends Subscribable {
1690
+ constructor(config) {
1691
+ super();
1692
+ this.config = config || {};
1693
+ this.mutations = [];
1694
+ this.mutationId = 0;
1695
+ }
1696
+
1697
+ build(client, options, state) {
1698
+ const mutation = new Mutation({
1699
+ mutationCache: this,
1700
+ logger: client.getLogger(),
1701
+ mutationId: ++this.mutationId,
1702
+ options: client.defaultMutationOptions(options),
1703
+ state,
1704
+ defaultOptions: options.mutationKey ? client.getMutationDefaults(options.mutationKey) : undefined
1705
+ });
1706
+ this.add(mutation);
1707
+ return mutation;
1708
+ }
1709
+
1710
+ add(mutation) {
1711
+ this.mutations.push(mutation);
1712
+ this.notify({
1713
+ type: 'added',
1714
+ mutation
1715
+ });
1716
+ }
1717
+
1718
+ remove(mutation) {
1719
+ this.mutations = this.mutations.filter(x => x !== mutation);
1720
+ this.notify({
1721
+ type: 'removed',
1722
+ mutation
1723
+ });
1724
+ }
1725
+
1726
+ clear() {
1727
+ notifyManager.batch(() => {
1728
+ this.mutations.forEach(mutation => {
1729
+ this.remove(mutation);
1730
+ });
1731
+ });
1732
+ }
1733
+
1734
+ getAll() {
1735
+ return this.mutations;
1736
+ }
1737
+
1738
+ find(filters) {
1739
+ if (typeof filters.exact === 'undefined') {
1740
+ filters.exact = true;
1741
+ }
1742
+
1743
+ return this.mutations.find(mutation => matchMutation(filters, mutation));
1744
+ }
1745
+
1746
+ findAll(filters) {
1747
+ return this.mutations.filter(mutation => matchMutation(filters, mutation));
1748
+ }
1749
+
1750
+ notify(event) {
1751
+ notifyManager.batch(() => {
1752
+ this.listeners.forEach(({
1753
+ listener
1754
+ }) => {
1755
+ listener(event);
1756
+ });
1757
+ });
1758
+ }
1759
+
1760
+ resumePausedMutations() {
1761
+ var _this$resuming;
1762
+
1763
+ this.resuming = ((_this$resuming = this.resuming) != null ? _this$resuming : Promise.resolve()).then(() => {
1764
+ const pausedMutations = this.mutations.filter(x => x.state.isPaused);
1765
+ return notifyManager.batch(() => pausedMutations.reduce((promise, mutation) => promise.then(() => mutation.continue().catch(noop$1)), Promise.resolve()));
1766
+ }).then(() => {
1767
+ this.resuming = undefined;
1768
+ });
1769
+ return this.resuming;
1770
+ }
1771
+
1772
+ }
1773
+
1774
+ function infiniteQueryBehavior() {
1775
+ return {
1776
+ onFetch: context => {
1777
+ context.fetchFn = () => {
1778
+ var _context$fetchOptions, _context$fetchOptions2, _context$fetchOptions3, _context$fetchOptions4, _context$state$data, _context$state$data2;
1779
+
1780
+ const refetchPage = (_context$fetchOptions = context.fetchOptions) == null ? void 0 : (_context$fetchOptions2 = _context$fetchOptions.meta) == null ? void 0 : _context$fetchOptions2.refetchPage;
1781
+ const fetchMore = (_context$fetchOptions3 = context.fetchOptions) == null ? void 0 : (_context$fetchOptions4 = _context$fetchOptions3.meta) == null ? void 0 : _context$fetchOptions4.fetchMore;
1782
+ const pageParam = fetchMore == null ? void 0 : fetchMore.pageParam;
1783
+ const isFetchingNextPage = (fetchMore == null ? void 0 : fetchMore.direction) === 'forward';
1784
+ const isFetchingPreviousPage = (fetchMore == null ? void 0 : fetchMore.direction) === 'backward';
1785
+ const oldPages = ((_context$state$data = context.state.data) == null ? void 0 : _context$state$data.pages) || [];
1786
+ const oldPageParams = ((_context$state$data2 = context.state.data) == null ? void 0 : _context$state$data2.pageParams) || [];
1787
+ let newPageParams = oldPageParams;
1788
+ let cancelled = false;
1789
+
1790
+ const addSignalProperty = object => {
1791
+ Object.defineProperty(object, 'signal', {
1792
+ enumerable: true,
1793
+ get: () => {
1794
+ var _context$signal;
1795
+
1796
+ if ((_context$signal = context.signal) != null && _context$signal.aborted) {
1797
+ cancelled = true;
1798
+ } else {
1799
+ var _context$signal2;
1800
+
1801
+ (_context$signal2 = context.signal) == null ? void 0 : _context$signal2.addEventListener('abort', () => {
1802
+ cancelled = true;
1803
+ });
1804
+ }
1805
+
1806
+ return context.signal;
1807
+ }
1808
+ });
1809
+ }; // Get query function
1810
+
1811
+
1812
+ const queryFn = context.options.queryFn || (() => Promise.reject("Missing queryFn for queryKey '" + context.options.queryHash + "'"));
1813
+
1814
+ const buildNewPages = (pages, param, page, previous) => {
1815
+ newPageParams = previous ? [param, ...newPageParams] : [...newPageParams, param];
1816
+ return previous ? [page, ...pages] : [...pages, page];
1817
+ }; // Create function to fetch a page
1818
+
1819
+
1820
+ const fetchPage = (pages, manual, param, previous) => {
1821
+ if (cancelled) {
1822
+ return Promise.reject('Cancelled');
1823
+ }
1824
+
1825
+ if (typeof param === 'undefined' && !manual && pages.length) {
1826
+ return Promise.resolve(pages);
1827
+ }
1828
+
1829
+ const queryFnContext = {
1830
+ queryKey: context.queryKey,
1831
+ pageParam: param,
1832
+ meta: context.options.meta
1833
+ };
1834
+ addSignalProperty(queryFnContext);
1835
+ const queryFnResult = queryFn(queryFnContext);
1836
+ const promise = Promise.resolve(queryFnResult).then(page => buildNewPages(pages, param, page, previous));
1837
+ return promise;
1838
+ };
1839
+
1840
+ let promise; // Fetch first page?
1841
+
1842
+ if (!oldPages.length) {
1843
+ promise = fetchPage([]);
1844
+ } // Fetch next page?
1845
+ else if (isFetchingNextPage) {
1846
+ const manual = typeof pageParam !== 'undefined';
1847
+ const param = manual ? pageParam : getNextPageParam(context.options, oldPages);
1848
+ promise = fetchPage(oldPages, manual, param);
1849
+ } // Fetch previous page?
1850
+ else if (isFetchingPreviousPage) {
1851
+ const manual = typeof pageParam !== 'undefined';
1852
+ const param = manual ? pageParam : getPreviousPageParam(context.options, oldPages);
1853
+ promise = fetchPage(oldPages, manual, param, true);
1854
+ } // Refetch pages
1855
+ else {
1856
+ newPageParams = [];
1857
+ const manual = typeof context.options.getNextPageParam === 'undefined';
1858
+ const shouldFetchFirstPage = refetchPage && oldPages[0] ? refetchPage(oldPages[0], 0, oldPages) : true; // Fetch first page
1859
+
1860
+ promise = shouldFetchFirstPage ? fetchPage([], manual, oldPageParams[0]) : Promise.resolve(buildNewPages([], oldPageParams[0], oldPages[0])); // Fetch remaining pages
1861
+
1862
+ for (let i = 1; i < oldPages.length; i++) {
1863
+ promise = promise.then(pages => {
1864
+ const shouldFetchNextPage = refetchPage && oldPages[i] ? refetchPage(oldPages[i], i, oldPages) : true;
1865
+
1866
+ if (shouldFetchNextPage) {
1867
+ const param = manual ? oldPageParams[i] : getNextPageParam(context.options, pages);
1868
+ return fetchPage(pages, manual, param);
1869
+ }
1870
+
1871
+ return Promise.resolve(buildNewPages(pages, oldPageParams[i], oldPages[i]));
1872
+ });
1873
+ }
1874
+ }
1875
+
1876
+ const finalPromise = promise.then(pages => ({
1877
+ pages,
1878
+ pageParams: newPageParams
1879
+ }));
1880
+ return finalPromise;
1881
+ };
1882
+ }
1883
+ };
1884
+ }
1885
+ function getNextPageParam(options, pages) {
1886
+ return options.getNextPageParam == null ? void 0 : options.getNextPageParam(pages[pages.length - 1], pages);
1887
+ }
1888
+ function getPreviousPageParam(options, pages) {
1889
+ return options.getPreviousPageParam == null ? void 0 : options.getPreviousPageParam(pages[0], pages);
1890
+ }
1891
+ /**
1892
+ * Checks if there is a next page.
1893
+ * Returns `undefined` if it cannot be determined.
1894
+ */
1895
+
1896
+ function hasNextPage(options, pages) {
1897
+ if (options.getNextPageParam && Array.isArray(pages)) {
1898
+ const nextPageParam = getNextPageParam(options, pages);
1899
+ return typeof nextPageParam !== 'undefined' && nextPageParam !== null && nextPageParam !== false;
1900
+ }
1901
+
1902
+ return;
1903
+ }
1904
+ /**
1905
+ * Checks if there is a previous page.
1906
+ * Returns `undefined` if it cannot be determined.
1907
+ */
1908
+
1909
+ function hasPreviousPage(options, pages) {
1910
+ if (options.getPreviousPageParam && Array.isArray(pages)) {
1911
+ const previousPageParam = getPreviousPageParam(options, pages);
1912
+ return typeof previousPageParam !== 'undefined' && previousPageParam !== null && previousPageParam !== false;
1913
+ }
1914
+
1915
+ return;
1916
+ }
1917
+
1918
+ // CLASS
1919
+ class QueryClient {
1920
+ constructor(config = {}) {
1921
+ this.queryCache = config.queryCache || new QueryCache();
1922
+ this.mutationCache = config.mutationCache || new MutationCache();
1923
+ this.logger = config.logger || defaultLogger;
1924
+ this.defaultOptions = config.defaultOptions || {};
1925
+ this.queryDefaults = [];
1926
+ this.mutationDefaults = [];
1927
+ this.mountCount = 0;
1928
+
1929
+ if (config.logger) {
1930
+ this.logger.error("Passing a custom logger has been deprecated and will be removed in the next major version.");
1931
+ }
1932
+ }
1933
+
1934
+ mount() {
1935
+ this.mountCount++;
1936
+ if (this.mountCount !== 1) return;
1937
+ this.unsubscribeFocus = focusManager.subscribe(() => {
1938
+ if (focusManager.isFocused()) {
1939
+ this.resumePausedMutations();
1940
+ this.queryCache.onFocus();
1941
+ }
1942
+ });
1943
+ this.unsubscribeOnline = onlineManager.subscribe(() => {
1944
+ if (onlineManager.isOnline()) {
1945
+ this.resumePausedMutations();
1946
+ this.queryCache.onOnline();
1947
+ }
1948
+ });
1949
+ }
1950
+
1951
+ unmount() {
1952
+ var _this$unsubscribeFocu, _this$unsubscribeOnli;
1953
+
1954
+ this.mountCount--;
1955
+ if (this.mountCount !== 0) return;
1956
+ (_this$unsubscribeFocu = this.unsubscribeFocus) == null ? void 0 : _this$unsubscribeFocu.call(this);
1957
+ this.unsubscribeFocus = undefined;
1958
+ (_this$unsubscribeOnli = this.unsubscribeOnline) == null ? void 0 : _this$unsubscribeOnli.call(this);
1959
+ this.unsubscribeOnline = undefined;
1960
+ }
1961
+
1962
+ /**
1963
+ * @deprecated This method should be used with only one object argument.
1964
+ */
1965
+ isFetching(arg1, arg2) {
1966
+ const [filters] = parseFilterArgs(arg1, arg2);
1967
+ filters.fetchStatus = 'fetching';
1968
+ return this.queryCache.findAll(filters).length;
1969
+ }
1970
+
1971
+ isMutating(filters) {
1972
+ return this.mutationCache.findAll({ ...filters,
1973
+ fetching: true
1974
+ }).length;
1975
+ }
1976
+
1977
+ /**
1978
+ * @deprecated This method will accept only queryKey in the next major version.
1979
+ */
1980
+ getQueryData(queryKey, filters) {
1981
+ var _this$queryCache$find;
1982
+
1983
+ return (_this$queryCache$find = this.queryCache.find(queryKey, filters)) == null ? void 0 : _this$queryCache$find.state.data;
1984
+ }
1985
+
1986
+ /**
1987
+ * @deprecated This method should be used with only one object argument.
1988
+ */
1989
+ ensureQueryData(arg1, arg2, arg3) {
1990
+ const parsedOptions = parseQueryArgs(arg1, arg2, arg3);
1991
+ const cachedData = this.getQueryData(parsedOptions.queryKey);
1992
+ return cachedData ? Promise.resolve(cachedData) : this.fetchQuery(parsedOptions);
1993
+ }
1994
+
1995
+ /**
1996
+ * @deprecated This method should be used with only one object argument.
1997
+ */
1998
+ getQueriesData(queryKeyOrFilters) {
1999
+ return this.getQueryCache().findAll(queryKeyOrFilters).map(({
2000
+ queryKey,
2001
+ state
2002
+ }) => {
2003
+ const data = state.data;
2004
+ return [queryKey, data];
2005
+ });
2006
+ }
2007
+
2008
+ setQueryData(queryKey, updater, options) {
2009
+ const query = this.queryCache.find(queryKey);
2010
+ const prevData = query == null ? void 0 : query.state.data;
2011
+ const data = functionalUpdate(updater, prevData);
2012
+
2013
+ if (typeof data === 'undefined') {
2014
+ return undefined;
2015
+ }
2016
+
2017
+ const parsedOptions = parseQueryArgs(queryKey);
2018
+ const defaultedOptions = this.defaultQueryOptions(parsedOptions);
2019
+ return this.queryCache.build(this, defaultedOptions).setData(data, { ...options,
2020
+ manual: true
2021
+ });
2022
+ }
2023
+
2024
+ /**
2025
+ * @deprecated This method should be used with only one object argument.
2026
+ */
2027
+ setQueriesData(queryKeyOrFilters, updater, options) {
2028
+ return notifyManager.batch(() => this.getQueryCache().findAll(queryKeyOrFilters).map(({
2029
+ queryKey
2030
+ }) => [queryKey, this.setQueryData(queryKey, updater, options)]));
2031
+ }
2032
+
2033
+ getQueryState(queryKey,
2034
+ /**
2035
+ * @deprecated This filters will be removed in the next major version.
2036
+ */
2037
+ filters) {
2038
+ var _this$queryCache$find2;
2039
+
2040
+ return (_this$queryCache$find2 = this.queryCache.find(queryKey, filters)) == null ? void 0 : _this$queryCache$find2.state;
2041
+ }
2042
+
2043
+ /**
2044
+ * @deprecated This method should be used with only one object argument.
2045
+ */
2046
+ removeQueries(arg1, arg2) {
2047
+ const [filters] = parseFilterArgs(arg1, arg2);
2048
+ const queryCache = this.queryCache;
2049
+ notifyManager.batch(() => {
2050
+ queryCache.findAll(filters).forEach(query => {
2051
+ queryCache.remove(query);
2052
+ });
2053
+ });
2054
+ }
2055
+
2056
+ /**
2057
+ * @deprecated This method should be used with only one object argument.
2058
+ */
2059
+ resetQueries(arg1, arg2, arg3) {
2060
+ const [filters, options] = parseFilterArgs(arg1, arg2, arg3);
2061
+ const queryCache = this.queryCache;
2062
+ const refetchFilters = {
2063
+ type: 'active',
2064
+ ...filters
2065
+ };
2066
+ return notifyManager.batch(() => {
2067
+ queryCache.findAll(filters).forEach(query => {
2068
+ query.reset();
2069
+ });
2070
+ return this.refetchQueries(refetchFilters, options);
2071
+ });
2072
+ }
2073
+
2074
+ /**
2075
+ * @deprecated This method should be used with only one object argument.
2076
+ */
2077
+ cancelQueries(arg1, arg2, arg3) {
2078
+ const [filters, cancelOptions = {}] = parseFilterArgs(arg1, arg2, arg3);
2079
+
2080
+ if (typeof cancelOptions.revert === 'undefined') {
2081
+ cancelOptions.revert = true;
2082
+ }
2083
+
2084
+ const promises = notifyManager.batch(() => this.queryCache.findAll(filters).map(query => query.cancel(cancelOptions)));
2085
+ return Promise.all(promises).then(noop$1).catch(noop$1);
2086
+ }
2087
+
2088
+ /**
2089
+ * @deprecated This method should be used with only one object argument.
2090
+ */
2091
+ invalidateQueries(arg1, arg2, arg3) {
2092
+ const [filters, options] = parseFilterArgs(arg1, arg2, arg3);
2093
+ return notifyManager.batch(() => {
2094
+ var _ref, _filters$refetchType;
2095
+
2096
+ this.queryCache.findAll(filters).forEach(query => {
2097
+ query.invalidate();
2098
+ });
2099
+
2100
+ if (filters.refetchType === 'none') {
2101
+ return Promise.resolve();
2102
+ }
2103
+
2104
+ const refetchFilters = { ...filters,
2105
+ type: (_ref = (_filters$refetchType = filters.refetchType) != null ? _filters$refetchType : filters.type) != null ? _ref : 'active'
2106
+ };
2107
+ return this.refetchQueries(refetchFilters, options);
2108
+ });
2109
+ }
2110
+
2111
+ /**
2112
+ * @deprecated This method should be used with only one object argument.
2113
+ */
2114
+ refetchQueries(arg1, arg2, arg3) {
2115
+ const [filters, options] = parseFilterArgs(arg1, arg2, arg3);
2116
+ const promises = notifyManager.batch(() => this.queryCache.findAll(filters).filter(query => !query.isDisabled()).map(query => {
2117
+ var _options$cancelRefetc;
2118
+
2119
+ return query.fetch(undefined, { ...options,
2120
+ cancelRefetch: (_options$cancelRefetc = options == null ? void 0 : options.cancelRefetch) != null ? _options$cancelRefetc : true,
2121
+ meta: {
2122
+ refetchPage: filters.refetchPage
2123
+ }
2124
+ });
2125
+ }));
2126
+ let promise = Promise.all(promises).then(noop$1);
2127
+
2128
+ if (!(options != null && options.throwOnError)) {
2129
+ promise = promise.catch(noop$1);
2130
+ }
2131
+
2132
+ return promise;
2133
+ }
2134
+
2135
+ /**
2136
+ * @deprecated This method should be used with only one object argument.
2137
+ */
2138
+ fetchQuery(arg1, arg2, arg3) {
2139
+ const parsedOptions = parseQueryArgs(arg1, arg2, arg3);
2140
+ const defaultedOptions = this.defaultQueryOptions(parsedOptions); // https://github.com/tannerlinsley/react-query/issues/652
2141
+
2142
+ if (typeof defaultedOptions.retry === 'undefined') {
2143
+ defaultedOptions.retry = false;
2144
+ }
2145
+
2146
+ const query = this.queryCache.build(this, defaultedOptions);
2147
+ return query.isStaleByTime(defaultedOptions.staleTime) ? query.fetch(defaultedOptions) : Promise.resolve(query.state.data);
2148
+ }
2149
+
2150
+ /**
2151
+ * @deprecated This method should be used with only one object argument.
2152
+ */
2153
+ prefetchQuery(arg1, arg2, arg3) {
2154
+ return this.fetchQuery(arg1, arg2, arg3).then(noop$1).catch(noop$1);
2155
+ }
2156
+
2157
+ /**
2158
+ * @deprecated This method should be used with only one object argument.
2159
+ */
2160
+ fetchInfiniteQuery(arg1, arg2, arg3) {
2161
+ const parsedOptions = parseQueryArgs(arg1, arg2, arg3);
2162
+ parsedOptions.behavior = infiniteQueryBehavior();
2163
+ return this.fetchQuery(parsedOptions);
2164
+ }
2165
+
2166
+ /**
2167
+ * @deprecated This method should be used with only one object argument.
2168
+ */
2169
+ prefetchInfiniteQuery(arg1, arg2, arg3) {
2170
+ return this.fetchInfiniteQuery(arg1, arg2, arg3).then(noop$1).catch(noop$1);
2171
+ }
2172
+
2173
+ resumePausedMutations() {
2174
+ return this.mutationCache.resumePausedMutations();
2175
+ }
2176
+
2177
+ getQueryCache() {
2178
+ return this.queryCache;
2179
+ }
2180
+
2181
+ getMutationCache() {
2182
+ return this.mutationCache;
2183
+ }
2184
+
2185
+ getLogger() {
2186
+ return this.logger;
2187
+ }
2188
+
2189
+ getDefaultOptions() {
2190
+ return this.defaultOptions;
2191
+ }
2192
+
2193
+ setDefaultOptions(options) {
2194
+ this.defaultOptions = options;
2195
+ }
2196
+
2197
+ setQueryDefaults(queryKey, options) {
2198
+ const result = this.queryDefaults.find(x => hashQueryKey(queryKey) === hashQueryKey(x.queryKey));
2199
+
2200
+ if (result) {
2201
+ result.defaultOptions = options;
2202
+ } else {
2203
+ this.queryDefaults.push({
2204
+ queryKey,
2205
+ defaultOptions: options
2206
+ });
2207
+ }
2208
+ }
2209
+
2210
+ getQueryDefaults(queryKey) {
2211
+ if (!queryKey) {
2212
+ return undefined;
2213
+ } // Get the first matching defaults
2214
+
2215
+
2216
+ const firstMatchingDefaults = this.queryDefaults.find(x => partialMatchKey(queryKey, x.queryKey)); // Additional checks and error in dev mode
2217
+
2218
+ {
2219
+ // Retrieve all matching defaults for the given key
2220
+ const matchingDefaults = this.queryDefaults.filter(x => partialMatchKey(queryKey, x.queryKey)); // It is ok not having defaults, but it is error prone to have more than 1 default for a given key
2221
+
2222
+ if (matchingDefaults.length > 1) {
2223
+ this.logger.error("[QueryClient] Several query defaults match with key '" + JSON.stringify(queryKey) + "'. The first matching query defaults are used. Please check how query defaults are registered. Order does matter here. cf. https://react-query.tanstack.com/reference/QueryClient#queryclientsetquerydefaults.");
2224
+ }
2225
+ }
2226
+
2227
+ return firstMatchingDefaults == null ? void 0 : firstMatchingDefaults.defaultOptions;
2228
+ }
2229
+
2230
+ setMutationDefaults(mutationKey, options) {
2231
+ const result = this.mutationDefaults.find(x => hashQueryKey(mutationKey) === hashQueryKey(x.mutationKey));
2232
+
2233
+ if (result) {
2234
+ result.defaultOptions = options;
2235
+ } else {
2236
+ this.mutationDefaults.push({
2237
+ mutationKey,
2238
+ defaultOptions: options
2239
+ });
2240
+ }
2241
+ }
2242
+
2243
+ getMutationDefaults(mutationKey) {
2244
+ if (!mutationKey) {
2245
+ return undefined;
2246
+ } // Get the first matching defaults
2247
+
2248
+
2249
+ const firstMatchingDefaults = this.mutationDefaults.find(x => partialMatchKey(mutationKey, x.mutationKey)); // Additional checks and error in dev mode
2250
+
2251
+ {
2252
+ // Retrieve all matching defaults for the given key
2253
+ const matchingDefaults = this.mutationDefaults.filter(x => partialMatchKey(mutationKey, x.mutationKey)); // It is ok not having defaults, but it is error prone to have more than 1 default for a given key
2254
+
2255
+ if (matchingDefaults.length > 1) {
2256
+ this.logger.error("[QueryClient] Several mutation defaults match with key '" + JSON.stringify(mutationKey) + "'. The first matching mutation defaults are used. Please check how mutation defaults are registered. Order does matter here. cf. https://react-query.tanstack.com/reference/QueryClient#queryclientsetmutationdefaults.");
2257
+ }
2258
+ }
2259
+
2260
+ return firstMatchingDefaults == null ? void 0 : firstMatchingDefaults.defaultOptions;
2261
+ }
2262
+
2263
+ defaultQueryOptions(options) {
2264
+ if (options != null && options._defaulted) {
2265
+ return options;
2266
+ }
2267
+
2268
+ const defaultedOptions = { ...this.defaultOptions.queries,
2269
+ ...this.getQueryDefaults(options == null ? void 0 : options.queryKey),
2270
+ ...options,
2271
+ _defaulted: true
2272
+ };
2273
+
2274
+ if (!defaultedOptions.queryHash && defaultedOptions.queryKey) {
2275
+ defaultedOptions.queryHash = hashQueryKeyByOptions(defaultedOptions.queryKey, defaultedOptions);
2276
+ } // dependent default values
2277
+
2278
+
2279
+ if (typeof defaultedOptions.refetchOnReconnect === 'undefined') {
2280
+ defaultedOptions.refetchOnReconnect = defaultedOptions.networkMode !== 'always';
2281
+ }
2282
+
2283
+ if (typeof defaultedOptions.useErrorBoundary === 'undefined') {
2284
+ defaultedOptions.useErrorBoundary = !!defaultedOptions.suspense;
2285
+ }
2286
+
2287
+ return defaultedOptions;
2288
+ }
2289
+
2290
+ defaultMutationOptions(options) {
2291
+ if (options != null && options._defaulted) {
2292
+ return options;
2293
+ }
2294
+
2295
+ return { ...this.defaultOptions.mutations,
2296
+ ...this.getMutationDefaults(options == null ? void 0 : options.mutationKey),
2297
+ ...options,
2298
+ _defaulted: true
2299
+ };
2300
+ }
2301
+
2302
+ clear() {
2303
+ this.queryCache.clear();
2304
+ this.mutationCache.clear();
2305
+ }
2306
+
2307
+ }
2308
+
2309
+ class QueryObserver extends Subscribable {
2310
+ constructor(client, options) {
2311
+ super();
2312
+ this.client = client;
2313
+ this.options = options;
2314
+ this.trackedProps = new Set();
2315
+ this.selectError = null;
2316
+ this.bindMethods();
2317
+ this.setOptions(options);
2318
+ }
2319
+
2320
+ bindMethods() {
2321
+ this.remove = this.remove.bind(this);
2322
+ this.refetch = this.refetch.bind(this);
2323
+ }
2324
+
2325
+ onSubscribe() {
2326
+ if (this.listeners.size === 1) {
2327
+ this.currentQuery.addObserver(this);
2328
+
2329
+ if (shouldFetchOnMount(this.currentQuery, this.options)) {
2330
+ this.executeFetch();
2331
+ }
2332
+
2333
+ this.updateTimers();
2334
+ }
2335
+ }
2336
+
2337
+ onUnsubscribe() {
2338
+ if (!this.hasListeners()) {
2339
+ this.destroy();
2340
+ }
2341
+ }
2342
+
2343
+ shouldFetchOnReconnect() {
2344
+ return shouldFetchOn(this.currentQuery, this.options, this.options.refetchOnReconnect);
2345
+ }
2346
+
2347
+ shouldFetchOnWindowFocus() {
2348
+ return shouldFetchOn(this.currentQuery, this.options, this.options.refetchOnWindowFocus);
2349
+ }
2350
+
2351
+ destroy() {
2352
+ this.listeners = new Set();
2353
+ this.clearStaleTimeout();
2354
+ this.clearRefetchInterval();
2355
+ this.currentQuery.removeObserver(this);
2356
+ }
2357
+
2358
+ setOptions(options, notifyOptions) {
2359
+ const prevOptions = this.options;
2360
+ const prevQuery = this.currentQuery;
2361
+ this.options = this.client.defaultQueryOptions(options);
2362
+
2363
+ if (typeof (options == null ? void 0 : options.isDataEqual) !== 'undefined') {
2364
+ this.client.getLogger().error("The isDataEqual option has been deprecated and will be removed in the next major version. You can achieve the same functionality by passing a function as the structuralSharing option");
2365
+ }
2366
+
2367
+ if (!shallowEqualObjects(prevOptions, this.options)) {
2368
+ this.client.getQueryCache().notify({
2369
+ type: 'observerOptionsUpdated',
2370
+ query: this.currentQuery,
2371
+ observer: this
2372
+ });
2373
+ }
2374
+
2375
+ if (typeof this.options.enabled !== 'undefined' && typeof this.options.enabled !== 'boolean') {
2376
+ throw new Error('Expected enabled to be a boolean');
2377
+ } // Keep previous query key if the user does not supply one
2378
+
2379
+
2380
+ if (!this.options.queryKey) {
2381
+ this.options.queryKey = prevOptions.queryKey;
2382
+ }
2383
+
2384
+ this.updateQuery();
2385
+ const mounted = this.hasListeners(); // Fetch if there are subscribers
2386
+
2387
+ if (mounted && shouldFetchOptionally(this.currentQuery, prevQuery, this.options, prevOptions)) {
2388
+ this.executeFetch();
2389
+ } // Update result
2390
+
2391
+
2392
+ this.updateResult(notifyOptions); // Update stale interval if needed
2393
+
2394
+ if (mounted && (this.currentQuery !== prevQuery || this.options.enabled !== prevOptions.enabled || this.options.staleTime !== prevOptions.staleTime)) {
2395
+ this.updateStaleTimeout();
2396
+ }
2397
+
2398
+ const nextRefetchInterval = this.computeRefetchInterval(); // Update refetch interval if needed
2399
+
2400
+ if (mounted && (this.currentQuery !== prevQuery || this.options.enabled !== prevOptions.enabled || nextRefetchInterval !== this.currentRefetchInterval)) {
2401
+ this.updateRefetchInterval(nextRefetchInterval);
2402
+ }
2403
+ }
2404
+
2405
+ getOptimisticResult(options) {
2406
+ const query = this.client.getQueryCache().build(this.client, options);
2407
+ const result = this.createResult(query, options);
2408
+
2409
+ if (shouldAssignObserverCurrentProperties(this, result, options)) {
2410
+ // this assigns the optimistic result to the current Observer
2411
+ // because if the query function changes, useQuery will be performing
2412
+ // an effect where it would fetch again.
2413
+ // When the fetch finishes, we perform a deep data cloning in order
2414
+ // to reuse objects references. This deep data clone is performed against
2415
+ // the `observer.currentResult.data` property
2416
+ // When QueryKey changes, we refresh the query and get new `optimistic`
2417
+ // result, while we leave the `observer.currentResult`, so when new data
2418
+ // arrives, it finds the old `observer.currentResult` which is related
2419
+ // to the old QueryKey. Which means that currentResult and selectData are
2420
+ // out of sync already.
2421
+ // To solve this, we move the cursor of the currentResult everytime
2422
+ // an observer reads an optimistic value.
2423
+ // When keeping the previous data, the result doesn't change until new
2424
+ // data arrives.
2425
+ this.currentResult = result;
2426
+ this.currentResultOptions = this.options;
2427
+ this.currentResultState = this.currentQuery.state;
2428
+ }
2429
+
2430
+ return result;
2431
+ }
2432
+
2433
+ getCurrentResult() {
2434
+ return this.currentResult;
2435
+ }
2436
+
2437
+ trackResult(result) {
2438
+ const trackedResult = {};
2439
+ Object.keys(result).forEach(key => {
2440
+ Object.defineProperty(trackedResult, key, {
2441
+ configurable: false,
2442
+ enumerable: true,
2443
+ get: () => {
2444
+ this.trackedProps.add(key);
2445
+ return result[key];
2446
+ }
2447
+ });
2448
+ });
2449
+ return trackedResult;
2450
+ }
2451
+
2452
+ getCurrentQuery() {
2453
+ return this.currentQuery;
2454
+ }
2455
+
2456
+ remove() {
2457
+ this.client.getQueryCache().remove(this.currentQuery);
2458
+ }
2459
+
2460
+ refetch({
2461
+ refetchPage,
2462
+ ...options
2463
+ } = {}) {
2464
+ return this.fetch({ ...options,
2465
+ meta: {
2466
+ refetchPage
2467
+ }
2468
+ });
2469
+ }
2470
+
2471
+ fetchOptimistic(options) {
2472
+ const defaultedOptions = this.client.defaultQueryOptions(options);
2473
+ const query = this.client.getQueryCache().build(this.client, defaultedOptions);
2474
+ query.isFetchingOptimistic = true;
2475
+ return query.fetch().then(() => this.createResult(query, defaultedOptions));
2476
+ }
2477
+
2478
+ fetch(fetchOptions) {
2479
+ var _fetchOptions$cancelR;
2480
+
2481
+ return this.executeFetch({ ...fetchOptions,
2482
+ cancelRefetch: (_fetchOptions$cancelR = fetchOptions.cancelRefetch) != null ? _fetchOptions$cancelR : true
2483
+ }).then(() => {
2484
+ this.updateResult();
2485
+ return this.currentResult;
2486
+ });
2487
+ }
2488
+
2489
+ executeFetch(fetchOptions) {
2490
+ // Make sure we reference the latest query as the current one might have been removed
2491
+ this.updateQuery(); // Fetch
2492
+
2493
+ let promise = this.currentQuery.fetch(this.options, fetchOptions);
2494
+
2495
+ if (!(fetchOptions != null && fetchOptions.throwOnError)) {
2496
+ promise = promise.catch(noop$1);
2497
+ }
2498
+
2499
+ return promise;
2500
+ }
2501
+
2502
+ updateStaleTimeout() {
2503
+ this.clearStaleTimeout();
2504
+
2505
+ if (isServer || this.currentResult.isStale || !isValidTimeout(this.options.staleTime)) {
2506
+ return;
2507
+ }
2508
+
2509
+ const time = timeUntilStale(this.currentResult.dataUpdatedAt, this.options.staleTime); // The timeout is sometimes triggered 1 ms before the stale time expiration.
2510
+ // To mitigate this issue we always add 1 ms to the timeout.
2511
+
2512
+ const timeout = time + 1;
2513
+ this.staleTimeoutId = setTimeout(() => {
2514
+ if (!this.currentResult.isStale) {
2515
+ this.updateResult();
2516
+ }
2517
+ }, timeout);
2518
+ }
2519
+
2520
+ computeRefetchInterval() {
2521
+ var _this$options$refetch;
2522
+
2523
+ return typeof this.options.refetchInterval === 'function' ? this.options.refetchInterval(this.currentResult.data, this.currentQuery) : (_this$options$refetch = this.options.refetchInterval) != null ? _this$options$refetch : false;
2524
+ }
2525
+
2526
+ updateRefetchInterval(nextInterval) {
2527
+ this.clearRefetchInterval();
2528
+ this.currentRefetchInterval = nextInterval;
2529
+
2530
+ if (isServer || this.options.enabled === false || !isValidTimeout(this.currentRefetchInterval) || this.currentRefetchInterval === 0) {
2531
+ return;
2532
+ }
2533
+
2534
+ this.refetchIntervalId = setInterval(() => {
2535
+ if (this.options.refetchIntervalInBackground || focusManager.isFocused()) {
2536
+ this.executeFetch();
2537
+ }
2538
+ }, this.currentRefetchInterval);
2539
+ }
2540
+
2541
+ updateTimers() {
2542
+ this.updateStaleTimeout();
2543
+ this.updateRefetchInterval(this.computeRefetchInterval());
2544
+ }
2545
+
2546
+ clearStaleTimeout() {
2547
+ if (this.staleTimeoutId) {
2548
+ clearTimeout(this.staleTimeoutId);
2549
+ this.staleTimeoutId = undefined;
2550
+ }
2551
+ }
2552
+
2553
+ clearRefetchInterval() {
2554
+ if (this.refetchIntervalId) {
2555
+ clearInterval(this.refetchIntervalId);
2556
+ this.refetchIntervalId = undefined;
2557
+ }
2558
+ }
2559
+
2560
+ createResult(query, options) {
2561
+ const prevQuery = this.currentQuery;
2562
+ const prevOptions = this.options;
2563
+ const prevResult = this.currentResult;
2564
+ const prevResultState = this.currentResultState;
2565
+ const prevResultOptions = this.currentResultOptions;
2566
+ const queryChange = query !== prevQuery;
2567
+ const queryInitialState = queryChange ? query.state : this.currentQueryInitialState;
2568
+ const prevQueryResult = queryChange ? this.currentResult : this.previousQueryResult;
2569
+ const {
2570
+ state
2571
+ } = query;
2572
+ let {
2573
+ dataUpdatedAt,
2574
+ error,
2575
+ errorUpdatedAt,
2576
+ fetchStatus,
2577
+ status
2578
+ } = state;
2579
+ let isPreviousData = false;
2580
+ let isPlaceholderData = false;
2581
+ let data; // Optimistically set result in fetching state if needed
2582
+
2583
+ if (options._optimisticResults) {
2584
+ const mounted = this.hasListeners();
2585
+ const fetchOnMount = !mounted && shouldFetchOnMount(query, options);
2586
+ const fetchOptionally = mounted && shouldFetchOptionally(query, prevQuery, options, prevOptions);
2587
+
2588
+ if (fetchOnMount || fetchOptionally) {
2589
+ fetchStatus = canFetch(query.options.networkMode) ? 'fetching' : 'paused';
2590
+
2591
+ if (!dataUpdatedAt) {
2592
+ status = 'loading';
2593
+ }
2594
+ }
2595
+
2596
+ if (options._optimisticResults === 'isRestoring') {
2597
+ fetchStatus = 'idle';
2598
+ }
2599
+ } // Keep previous data if needed
2600
+
2601
+
2602
+ if (options.keepPreviousData && !state.dataUpdatedAt && prevQueryResult != null && prevQueryResult.isSuccess && status !== 'error') {
2603
+ data = prevQueryResult.data;
2604
+ dataUpdatedAt = prevQueryResult.dataUpdatedAt;
2605
+ status = prevQueryResult.status;
2606
+ isPreviousData = true;
2607
+ } // Select data if needed
2608
+ else if (options.select && typeof state.data !== 'undefined') {
2609
+ // Memoize select result
2610
+ if (prevResult && state.data === (prevResultState == null ? void 0 : prevResultState.data) && options.select === this.selectFn) {
2611
+ data = this.selectResult;
2612
+ } else {
2613
+ try {
2614
+ this.selectFn = options.select;
2615
+ data = options.select(state.data);
2616
+ data = replaceData(prevResult == null ? void 0 : prevResult.data, data, options);
2617
+ this.selectResult = data;
2618
+ this.selectError = null;
2619
+ } catch (selectError) {
2620
+ {
2621
+ this.client.getLogger().error(selectError);
2622
+ }
2623
+
2624
+ this.selectError = selectError;
2625
+ }
2626
+ }
2627
+ } // Use query data
2628
+ else {
2629
+ data = state.data;
2630
+ } // Show placeholder data if needed
2631
+
2632
+
2633
+ if (typeof options.placeholderData !== 'undefined' && typeof data === 'undefined' && status === 'loading') {
2634
+ let placeholderData; // Memoize placeholder data
2635
+
2636
+ if (prevResult != null && prevResult.isPlaceholderData && options.placeholderData === (prevResultOptions == null ? void 0 : prevResultOptions.placeholderData)) {
2637
+ placeholderData = prevResult.data;
2638
+ } else {
2639
+ placeholderData = typeof options.placeholderData === 'function' ? options.placeholderData() : options.placeholderData;
2640
+
2641
+ if (options.select && typeof placeholderData !== 'undefined') {
2642
+ try {
2643
+ placeholderData = options.select(placeholderData);
2644
+ this.selectError = null;
2645
+ } catch (selectError) {
2646
+ {
2647
+ this.client.getLogger().error(selectError);
2648
+ }
2649
+
2650
+ this.selectError = selectError;
2651
+ }
2652
+ }
2653
+ }
2654
+
2655
+ if (typeof placeholderData !== 'undefined') {
2656
+ status = 'success';
2657
+ data = replaceData(prevResult == null ? void 0 : prevResult.data, placeholderData, options);
2658
+ isPlaceholderData = true;
2659
+ }
2660
+ }
2661
+
2662
+ if (this.selectError) {
2663
+ error = this.selectError;
2664
+ data = this.selectResult;
2665
+ errorUpdatedAt = Date.now();
2666
+ status = 'error';
2667
+ }
2668
+
2669
+ const isFetching = fetchStatus === 'fetching';
2670
+ const isLoading = status === 'loading';
2671
+ const isError = status === 'error';
2672
+ const result = {
2673
+ status,
2674
+ fetchStatus,
2675
+ isLoading,
2676
+ isSuccess: status === 'success',
2677
+ isError,
2678
+ isInitialLoading: isLoading && isFetching,
2679
+ data,
2680
+ dataUpdatedAt,
2681
+ error,
2682
+ errorUpdatedAt,
2683
+ failureCount: state.fetchFailureCount,
2684
+ failureReason: state.fetchFailureReason,
2685
+ errorUpdateCount: state.errorUpdateCount,
2686
+ isFetched: state.dataUpdateCount > 0 || state.errorUpdateCount > 0,
2687
+ isFetchedAfterMount: state.dataUpdateCount > queryInitialState.dataUpdateCount || state.errorUpdateCount > queryInitialState.errorUpdateCount,
2688
+ isFetching,
2689
+ isRefetching: isFetching && !isLoading,
2690
+ isLoadingError: isError && state.dataUpdatedAt === 0,
2691
+ isPaused: fetchStatus === 'paused',
2692
+ isPlaceholderData,
2693
+ isPreviousData,
2694
+ isRefetchError: isError && state.dataUpdatedAt !== 0,
2695
+ isStale: isStale(query, options),
2696
+ refetch: this.refetch,
2697
+ remove: this.remove
2698
+ };
2699
+ return result;
2700
+ }
2701
+
2702
+ updateResult(notifyOptions) {
2703
+ const prevResult = this.currentResult;
2704
+ const nextResult = this.createResult(this.currentQuery, this.options);
2705
+ this.currentResultState = this.currentQuery.state;
2706
+ this.currentResultOptions = this.options; // Only notify and update result if something has changed
2707
+
2708
+ if (shallowEqualObjects(nextResult, prevResult)) {
2709
+ return;
2710
+ }
2711
+
2712
+ this.currentResult = nextResult; // Determine which callbacks to trigger
2713
+
2714
+ const defaultNotifyOptions = {
2715
+ cache: true
2716
+ };
2717
+
2718
+ const shouldNotifyListeners = () => {
2719
+ if (!prevResult) {
2720
+ return true;
2721
+ }
2722
+
2723
+ const {
2724
+ notifyOnChangeProps
2725
+ } = this.options;
2726
+ const notifyOnChangePropsValue = typeof notifyOnChangeProps === 'function' ? notifyOnChangeProps() : notifyOnChangeProps;
2727
+
2728
+ if (notifyOnChangePropsValue === 'all' || !notifyOnChangePropsValue && !this.trackedProps.size) {
2729
+ return true;
2730
+ }
2731
+
2732
+ const includedProps = new Set(notifyOnChangePropsValue != null ? notifyOnChangePropsValue : this.trackedProps);
2733
+
2734
+ if (this.options.useErrorBoundary) {
2735
+ includedProps.add('error');
2736
+ }
2737
+
2738
+ return Object.keys(this.currentResult).some(key => {
2739
+ const typedKey = key;
2740
+ const changed = this.currentResult[typedKey] !== prevResult[typedKey];
2741
+ return changed && includedProps.has(typedKey);
2742
+ });
2743
+ };
2744
+
2745
+ if ((notifyOptions == null ? void 0 : notifyOptions.listeners) !== false && shouldNotifyListeners()) {
2746
+ defaultNotifyOptions.listeners = true;
2747
+ }
2748
+
2749
+ this.notify({ ...defaultNotifyOptions,
2750
+ ...notifyOptions
2751
+ });
2752
+ }
2753
+
2754
+ updateQuery() {
2755
+ const query = this.client.getQueryCache().build(this.client, this.options);
2756
+
2757
+ if (query === this.currentQuery) {
2758
+ return;
2759
+ }
2760
+
2761
+ const prevQuery = this.currentQuery;
2762
+ this.currentQuery = query;
2763
+ this.currentQueryInitialState = query.state;
2764
+ this.previousQueryResult = this.currentResult;
2765
+
2766
+ if (this.hasListeners()) {
2767
+ prevQuery == null ? void 0 : prevQuery.removeObserver(this);
2768
+ query.addObserver(this);
2769
+ }
2770
+ }
2771
+
2772
+ onQueryUpdate(action) {
2773
+ const notifyOptions = {};
2774
+
2775
+ if (action.type === 'success') {
2776
+ notifyOptions.onSuccess = !action.manual;
2777
+ } else if (action.type === 'error' && !isCancelledError(action.error)) {
2778
+ notifyOptions.onError = true;
2779
+ }
2780
+
2781
+ this.updateResult(notifyOptions);
2782
+
2783
+ if (this.hasListeners()) {
2784
+ this.updateTimers();
2785
+ }
2786
+ }
2787
+
2788
+ notify(notifyOptions) {
2789
+ notifyManager.batch(() => {
2790
+ // First trigger the configuration callbacks
2791
+ if (notifyOptions.onSuccess) {
2792
+ var _this$options$onSucce, _this$options, _this$options$onSettl, _this$options2;
2793
+
2794
+ (_this$options$onSucce = (_this$options = this.options).onSuccess) == null ? void 0 : _this$options$onSucce.call(_this$options, this.currentResult.data);
2795
+ (_this$options$onSettl = (_this$options2 = this.options).onSettled) == null ? void 0 : _this$options$onSettl.call(_this$options2, this.currentResult.data, null);
2796
+ } else if (notifyOptions.onError) {
2797
+ var _this$options$onError, _this$options3, _this$options$onSettl2, _this$options4;
2798
+
2799
+ (_this$options$onError = (_this$options3 = this.options).onError) == null ? void 0 : _this$options$onError.call(_this$options3, this.currentResult.error);
2800
+ (_this$options$onSettl2 = (_this$options4 = this.options).onSettled) == null ? void 0 : _this$options$onSettl2.call(_this$options4, undefined, this.currentResult.error);
2801
+ } // Then trigger the listeners
2802
+
2803
+
2804
+ if (notifyOptions.listeners) {
2805
+ this.listeners.forEach(({
2806
+ listener
2807
+ }) => {
2808
+ listener(this.currentResult);
2809
+ });
2810
+ } // Then the cache listeners
2811
+
2812
+
2813
+ if (notifyOptions.cache) {
2814
+ this.client.getQueryCache().notify({
2815
+ query: this.currentQuery,
2816
+ type: 'observerResultsUpdated'
2817
+ });
2818
+ }
2819
+ });
2820
+ }
2821
+
2822
+ }
2823
+
2824
+ function shouldLoadOnMount(query, options) {
2825
+ return options.enabled !== false && !query.state.dataUpdatedAt && !(query.state.status === 'error' && options.retryOnMount === false);
2826
+ }
2827
+
2828
+ function shouldFetchOnMount(query, options) {
2829
+ return shouldLoadOnMount(query, options) || query.state.dataUpdatedAt > 0 && shouldFetchOn(query, options, options.refetchOnMount);
2830
+ }
2831
+
2832
+ function shouldFetchOn(query, options, field) {
2833
+ if (options.enabled !== false) {
2834
+ const value = typeof field === 'function' ? field(query) : field;
2835
+ return value === 'always' || value !== false && isStale(query, options);
2836
+ }
2837
+
2838
+ return false;
2839
+ }
2840
+
2841
+ function shouldFetchOptionally(query, prevQuery, options, prevOptions) {
2842
+ return options.enabled !== false && (query !== prevQuery || prevOptions.enabled === false) && (!options.suspense || query.state.status !== 'error') && isStale(query, options);
2843
+ }
2844
+
2845
+ function isStale(query, options) {
2846
+ return query.isStaleByTime(options.staleTime);
2847
+ } // this function would decide if we will update the observer's 'current'
2848
+ // properties after an optimistic reading via getOptimisticResult
2849
+
2850
+
2851
+ function shouldAssignObserverCurrentProperties(observer, optimisticResult, options) {
2852
+ // it is important to keep this condition like this for three reasons:
2853
+ // 1. It will get removed in the v5
2854
+ // 2. it reads: don't update the properties if we want to keep the previous
2855
+ // data.
2856
+ // 3. The opposite condition (!options.keepPreviousData) would fallthrough
2857
+ // and will result in a bad decision
2858
+ if (options.keepPreviousData) {
2859
+ return false;
2860
+ } // this means we want to put some placeholder data when pending and queryKey
2861
+ // changed.
2862
+
2863
+
2864
+ if (options.placeholderData !== undefined) {
2865
+ // re-assign properties only if current data is placeholder data
2866
+ // which means that data did not arrive yet, so, if there is some cached data
2867
+ // we need to "prepare" to receive it
2868
+ return optimisticResult.isPlaceholderData;
2869
+ } // if the newly created result isn't what the observer is holding as current,
2870
+ // then we'll need to update the properties as well
2871
+
2872
+
2873
+ if (!shallowEqualObjects(observer.getCurrentResult(), optimisticResult)) {
2874
+ return true;
2875
+ } // basically, just keep previous properties if nothing changed
2876
+
2877
+
2878
+ return false;
2879
+ }
2880
+
2881
+ class QueriesObserver extends Subscribable {
2882
+ constructor(client, queries) {
2883
+ super();
2884
+ this.client = client;
2885
+ this.queries = [];
2886
+ this.result = [];
2887
+ this.observers = [];
2888
+ this.observersMap = {};
2889
+
2890
+ if (queries) {
2891
+ this.setQueries(queries);
2892
+ }
2893
+ }
2894
+
2895
+ onSubscribe() {
2896
+ if (this.listeners.size === 1) {
2897
+ this.observers.forEach(observer => {
2898
+ observer.subscribe(result => {
2899
+ this.onUpdate(observer, result);
2900
+ });
2901
+ });
2902
+ }
2903
+ }
2904
+
2905
+ onUnsubscribe() {
2906
+ if (!this.listeners.size) {
2907
+ this.destroy();
2908
+ }
2909
+ }
2910
+
2911
+ destroy() {
2912
+ this.listeners = new Set();
2913
+ this.observers.forEach(observer => {
2914
+ observer.destroy();
2915
+ });
2916
+ }
2917
+
2918
+ setQueries(queries, notifyOptions) {
2919
+ this.queries = queries;
2920
+ notifyManager.batch(() => {
2921
+ const prevObservers = this.observers;
2922
+ const newObserverMatches = this.findMatchingObservers(this.queries); // set options for the new observers to notify of changes
2923
+
2924
+ newObserverMatches.forEach(match => match.observer.setOptions(match.defaultedQueryOptions, notifyOptions));
2925
+ const newObservers = newObserverMatches.map(match => match.observer);
2926
+ const newObserversMap = Object.fromEntries(newObservers.map(observer => [observer.options.queryHash, observer]));
2927
+ const newResult = newObservers.map(observer => observer.getCurrentResult());
2928
+ const hasIndexChange = newObservers.some((observer, index) => observer !== prevObservers[index]);
2929
+
2930
+ if (prevObservers.length === newObservers.length && !hasIndexChange) {
2931
+ return;
2932
+ }
2933
+
2934
+ this.observers = newObservers;
2935
+ this.observersMap = newObserversMap;
2936
+ this.result = newResult;
2937
+
2938
+ if (!this.hasListeners()) {
2939
+ return;
2940
+ }
2941
+
2942
+ difference(prevObservers, newObservers).forEach(observer => {
2943
+ observer.destroy();
2944
+ });
2945
+ difference(newObservers, prevObservers).forEach(observer => {
2946
+ observer.subscribe(result => {
2947
+ this.onUpdate(observer, result);
2948
+ });
2949
+ });
2950
+ this.notify();
2951
+ });
2952
+ }
2953
+
2954
+ getCurrentResult() {
2955
+ return this.result;
2956
+ }
2957
+
2958
+ getQueries() {
2959
+ return this.observers.map(observer => observer.getCurrentQuery());
2960
+ }
2961
+
2962
+ getObservers() {
2963
+ return this.observers;
2964
+ }
2965
+
2966
+ getOptimisticResult(queries) {
2967
+ return this.findMatchingObservers(queries).map(match => match.observer.getOptimisticResult(match.defaultedQueryOptions));
2968
+ }
2969
+
2970
+ findMatchingObservers(queries) {
2971
+ const prevObservers = this.observers;
2972
+ const prevObserversMap = new Map(prevObservers.map(observer => [observer.options.queryHash, observer]));
2973
+ const defaultedQueryOptions = queries.map(options => this.client.defaultQueryOptions(options));
2974
+ const matchingObservers = defaultedQueryOptions.flatMap(defaultedOptions => {
2975
+ const match = prevObserversMap.get(defaultedOptions.queryHash);
2976
+
2977
+ if (match != null) {
2978
+ return [{
2979
+ defaultedQueryOptions: defaultedOptions,
2980
+ observer: match
2981
+ }];
2982
+ }
2983
+
2984
+ return [];
2985
+ });
2986
+ const matchedQueryHashes = new Set(matchingObservers.map(match => match.defaultedQueryOptions.queryHash));
2987
+ const unmatchedQueries = defaultedQueryOptions.filter(defaultedOptions => !matchedQueryHashes.has(defaultedOptions.queryHash));
2988
+ const matchingObserversSet = new Set(matchingObservers.map(match => match.observer));
2989
+ const unmatchedObservers = prevObservers.filter(prevObserver => !matchingObserversSet.has(prevObserver));
2990
+
2991
+ const getObserver = options => {
2992
+ const defaultedOptions = this.client.defaultQueryOptions(options);
2993
+ const currentObserver = this.observersMap[defaultedOptions.queryHash];
2994
+ return currentObserver != null ? currentObserver : new QueryObserver(this.client, defaultedOptions);
2995
+ };
2996
+
2997
+ const newOrReusedObservers = unmatchedQueries.map((options, index) => {
2998
+ if (options.keepPreviousData) {
2999
+ // return previous data from one of the observers that no longer match
3000
+ const previouslyUsedObserver = unmatchedObservers[index];
3001
+
3002
+ if (previouslyUsedObserver !== undefined) {
3003
+ return {
3004
+ defaultedQueryOptions: options,
3005
+ observer: previouslyUsedObserver
3006
+ };
3007
+ }
3008
+ }
3009
+
3010
+ return {
3011
+ defaultedQueryOptions: options,
3012
+ observer: getObserver(options)
3013
+ };
3014
+ });
3015
+
3016
+ const sortMatchesByOrderOfQueries = (a, b) => defaultedQueryOptions.indexOf(a.defaultedQueryOptions) - defaultedQueryOptions.indexOf(b.defaultedQueryOptions);
3017
+
3018
+ return matchingObservers.concat(newOrReusedObservers).sort(sortMatchesByOrderOfQueries);
3019
+ }
3020
+
3021
+ onUpdate(observer, result) {
3022
+ const index = this.observers.indexOf(observer);
3023
+
3024
+ if (index !== -1) {
3025
+ this.result = replaceAt(this.result, index, result);
3026
+ this.notify();
3027
+ }
3028
+ }
3029
+
3030
+ notify() {
3031
+ notifyManager.batch(() => {
3032
+ this.listeners.forEach(({
3033
+ listener
3034
+ }) => {
3035
+ listener(this.result);
3036
+ });
3037
+ });
3038
+ }
3039
+
3040
+ }
3041
+
3042
+ class InfiniteQueryObserver extends QueryObserver {
3043
+ // Type override
3044
+ // Type override
3045
+ // Type override
3046
+ // eslint-disable-next-line @typescript-eslint/no-useless-constructor
3047
+ constructor(client, options) {
3048
+ super(client, options);
3049
+ }
3050
+
3051
+ bindMethods() {
3052
+ super.bindMethods();
3053
+ this.fetchNextPage = this.fetchNextPage.bind(this);
3054
+ this.fetchPreviousPage = this.fetchPreviousPage.bind(this);
3055
+ }
3056
+
3057
+ setOptions(options, notifyOptions) {
3058
+ super.setOptions({ ...options,
3059
+ behavior: infiniteQueryBehavior()
3060
+ }, notifyOptions);
3061
+ }
3062
+
3063
+ getOptimisticResult(options) {
3064
+ options.behavior = infiniteQueryBehavior();
3065
+ return super.getOptimisticResult(options);
3066
+ }
3067
+
3068
+ fetchNextPage({
3069
+ pageParam,
3070
+ ...options
3071
+ } = {}) {
3072
+ return this.fetch({ ...options,
3073
+ meta: {
3074
+ fetchMore: {
3075
+ direction: 'forward',
3076
+ pageParam
3077
+ }
3078
+ }
3079
+ });
3080
+ }
3081
+
3082
+ fetchPreviousPage({
3083
+ pageParam,
3084
+ ...options
3085
+ } = {}) {
3086
+ return this.fetch({ ...options,
3087
+ meta: {
3088
+ fetchMore: {
3089
+ direction: 'backward',
3090
+ pageParam
3091
+ }
3092
+ }
3093
+ });
3094
+ }
3095
+
3096
+ createResult(query, options) {
3097
+ var _state$fetchMeta, _state$fetchMeta$fetc, _state$fetchMeta2, _state$fetchMeta2$fet, _state$data, _state$data2;
3098
+
3099
+ const {
3100
+ state
3101
+ } = query;
3102
+ const result = super.createResult(query, options);
3103
+ const {
3104
+ isFetching,
3105
+ isRefetching
3106
+ } = result;
3107
+ const isFetchingNextPage = isFetching && ((_state$fetchMeta = state.fetchMeta) == null ? void 0 : (_state$fetchMeta$fetc = _state$fetchMeta.fetchMore) == null ? void 0 : _state$fetchMeta$fetc.direction) === 'forward';
3108
+ const isFetchingPreviousPage = isFetching && ((_state$fetchMeta2 = state.fetchMeta) == null ? void 0 : (_state$fetchMeta2$fet = _state$fetchMeta2.fetchMore) == null ? void 0 : _state$fetchMeta2$fet.direction) === 'backward';
3109
+ return { ...result,
3110
+ fetchNextPage: this.fetchNextPage,
3111
+ fetchPreviousPage: this.fetchPreviousPage,
3112
+ hasNextPage: hasNextPage(options, (_state$data = state.data) == null ? void 0 : _state$data.pages),
3113
+ hasPreviousPage: hasPreviousPage(options, (_state$data2 = state.data) == null ? void 0 : _state$data2.pages),
3114
+ isFetchingNextPage,
3115
+ isFetchingPreviousPage,
3116
+ isRefetching: isRefetching && !isFetchingNextPage && !isFetchingPreviousPage
3117
+ };
3118
+ }
3119
+
3120
+ }
3121
+
3122
+ // CLASS
3123
+ class MutationObserver extends Subscribable {
3124
+ constructor(client, options) {
3125
+ super();
3126
+ this.client = client;
3127
+ this.setOptions(options);
3128
+ this.bindMethods();
3129
+ this.updateResult();
3130
+ }
3131
+
3132
+ bindMethods() {
3133
+ this.mutate = this.mutate.bind(this);
3134
+ this.reset = this.reset.bind(this);
3135
+ }
3136
+
3137
+ setOptions(options) {
3138
+ var _this$currentMutation;
3139
+
3140
+ const prevOptions = this.options;
3141
+ this.options = this.client.defaultMutationOptions(options);
3142
+
3143
+ if (!shallowEqualObjects(prevOptions, this.options)) {
3144
+ this.client.getMutationCache().notify({
3145
+ type: 'observerOptionsUpdated',
3146
+ mutation: this.currentMutation,
3147
+ observer: this
3148
+ });
3149
+ }
3150
+
3151
+ (_this$currentMutation = this.currentMutation) == null ? void 0 : _this$currentMutation.setOptions(this.options);
3152
+ }
3153
+
3154
+ onUnsubscribe() {
3155
+ if (!this.hasListeners()) {
3156
+ var _this$currentMutation2;
3157
+
3158
+ (_this$currentMutation2 = this.currentMutation) == null ? void 0 : _this$currentMutation2.removeObserver(this);
3159
+ }
3160
+ }
3161
+
3162
+ onMutationUpdate(action) {
3163
+ this.updateResult(); // Determine which callbacks to trigger
3164
+
3165
+ const notifyOptions = {
3166
+ listeners: true
3167
+ };
3168
+
3169
+ if (action.type === 'success') {
3170
+ notifyOptions.onSuccess = true;
3171
+ } else if (action.type === 'error') {
3172
+ notifyOptions.onError = true;
3173
+ }
3174
+
3175
+ this.notify(notifyOptions);
3176
+ }
3177
+
3178
+ getCurrentResult() {
3179
+ return this.currentResult;
3180
+ }
3181
+
3182
+ reset() {
3183
+ this.currentMutation = undefined;
3184
+ this.updateResult();
3185
+ this.notify({
3186
+ listeners: true
3187
+ });
3188
+ }
3189
+
3190
+ mutate(variables, options) {
3191
+ this.mutateOptions = options;
3192
+
3193
+ if (this.currentMutation) {
3194
+ this.currentMutation.removeObserver(this);
3195
+ }
3196
+
3197
+ this.currentMutation = this.client.getMutationCache().build(this.client, { ...this.options,
3198
+ variables: typeof variables !== 'undefined' ? variables : this.options.variables
3199
+ });
3200
+ this.currentMutation.addObserver(this);
3201
+ return this.currentMutation.execute();
3202
+ }
3203
+
3204
+ updateResult() {
3205
+ const state = this.currentMutation ? this.currentMutation.state : getDefaultState();
3206
+ const isLoading = state.status === 'loading';
3207
+ const result = { ...state,
3208
+ isLoading,
3209
+ isPending: isLoading,
3210
+ isSuccess: state.status === 'success',
3211
+ isError: state.status === 'error',
3212
+ isIdle: state.status === 'idle',
3213
+ mutate: this.mutate,
3214
+ reset: this.reset
3215
+ };
3216
+ this.currentResult = result;
3217
+ }
3218
+
3219
+ notify(options) {
3220
+ notifyManager.batch(() => {
3221
+ // First trigger the mutate callbacks
3222
+ if (this.mutateOptions && this.hasListeners()) {
3223
+ if (options.onSuccess) {
3224
+ var _this$mutateOptions$o, _this$mutateOptions, _this$mutateOptions$o2, _this$mutateOptions2;
3225
+
3226
+ (_this$mutateOptions$o = (_this$mutateOptions = this.mutateOptions).onSuccess) == null ? void 0 : _this$mutateOptions$o.call(_this$mutateOptions, this.currentResult.data, this.currentResult.variables, this.currentResult.context);
3227
+ (_this$mutateOptions$o2 = (_this$mutateOptions2 = this.mutateOptions).onSettled) == null ? void 0 : _this$mutateOptions$o2.call(_this$mutateOptions2, this.currentResult.data, null, this.currentResult.variables, this.currentResult.context);
3228
+ } else if (options.onError) {
3229
+ var _this$mutateOptions$o3, _this$mutateOptions3, _this$mutateOptions$o4, _this$mutateOptions4;
3230
+
3231
+ (_this$mutateOptions$o3 = (_this$mutateOptions3 = this.mutateOptions).onError) == null ? void 0 : _this$mutateOptions$o3.call(_this$mutateOptions3, this.currentResult.error, this.currentResult.variables, this.currentResult.context);
3232
+ (_this$mutateOptions$o4 = (_this$mutateOptions4 = this.mutateOptions).onSettled) == null ? void 0 : _this$mutateOptions$o4.call(_this$mutateOptions4, undefined, this.currentResult.error, this.currentResult.variables, this.currentResult.context);
3233
+ }
3234
+ } // Then trigger the listeners
3235
+
3236
+
3237
+ if (options.listeners) {
3238
+ this.listeners.forEach(({
3239
+ listener
3240
+ }) => {
3241
+ listener(this.currentResult);
3242
+ });
3243
+ }
3244
+ });
3245
+ }
3246
+
3247
+ }
3248
+
3249
+ // TYPES
3250
+ // FUNCTIONS
3251
+ function dehydrateMutation(mutation) {
3252
+ return {
3253
+ mutationKey: mutation.options.mutationKey,
3254
+ state: mutation.state
3255
+ };
3256
+ } // Most config is not dehydrated but instead meant to configure again when
3257
+ // consuming the de/rehydrated data, typically with useQuery on the client.
3258
+ // Sometimes it might make sense to prefetch data on the server and include
3259
+ // in the html-payload, but not consume it on the initial render.
3260
+
3261
+
3262
+ function dehydrateQuery(query) {
3263
+ return {
3264
+ state: query.state,
3265
+ queryKey: query.queryKey,
3266
+ queryHash: query.queryHash
3267
+ };
3268
+ }
3269
+
3270
+ function defaultShouldDehydrateMutation(mutation) {
3271
+ return mutation.state.isPaused;
3272
+ }
3273
+ function defaultShouldDehydrateQuery(query) {
3274
+ return query.state.status === 'success';
3275
+ }
3276
+ function dehydrate(client, options = {}) {
3277
+ const mutations = [];
3278
+ const queries = [];
3279
+
3280
+ if (options.dehydrateMutations !== false) {
3281
+ const shouldDehydrateMutation = options.shouldDehydrateMutation || defaultShouldDehydrateMutation;
3282
+ client.getMutationCache().getAll().forEach(mutation => {
3283
+ if (shouldDehydrateMutation(mutation)) {
3284
+ mutations.push(dehydrateMutation(mutation));
3285
+ }
3286
+ });
3287
+ }
3288
+
3289
+ if (options.dehydrateQueries !== false) {
3290
+ const shouldDehydrateQuery = options.shouldDehydrateQuery || defaultShouldDehydrateQuery;
3291
+ client.getQueryCache().getAll().forEach(query => {
3292
+ if (shouldDehydrateQuery(query)) {
3293
+ queries.push(dehydrateQuery(query));
3294
+ }
3295
+ });
3296
+ }
3297
+
3298
+ return {
3299
+ mutations,
3300
+ queries
3301
+ };
3302
+ }
3303
+ function hydrate(client, dehydratedState, options) {
3304
+ if (typeof dehydratedState !== 'object' || dehydratedState === null) {
3305
+ return;
3306
+ }
3307
+
3308
+ const mutationCache = client.getMutationCache();
3309
+ const queryCache = client.getQueryCache(); // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
3310
+
3311
+ const mutations = dehydratedState.mutations || []; // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
3312
+
3313
+ const queries = dehydratedState.queries || [];
3314
+ mutations.forEach(dehydratedMutation => {
3315
+ var _options$defaultOptio;
3316
+
3317
+ mutationCache.build(client, { ...(options == null ? void 0 : (_options$defaultOptio = options.defaultOptions) == null ? void 0 : _options$defaultOptio.mutations),
3318
+ mutationKey: dehydratedMutation.mutationKey
3319
+ }, dehydratedMutation.state);
3320
+ });
3321
+ queries.forEach(({
3322
+ queryKey,
3323
+ state,
3324
+ queryHash
3325
+ }) => {
3326
+ var _options$defaultOptio2;
3327
+
3328
+ const query = queryCache.get(queryHash); // Do not hydrate if an existing query exists with newer data
3329
+
3330
+ if (query) {
3331
+ if (query.state.dataUpdatedAt < state.dataUpdatedAt) {
3332
+ // omit fetchStatus from dehydrated state
3333
+ // so that query stays in its current fetchStatus
3334
+ const {
3335
+ fetchStatus: _ignored,
3336
+ ...dehydratedQueryState
3337
+ } = state;
3338
+ query.setState(dehydratedQueryState);
3339
+ }
3340
+
3341
+ return;
3342
+ } // Restore query
3343
+
3344
+
3345
+ queryCache.build(client, { ...(options == null ? void 0 : (_options$defaultOptio2 = options.defaultOptions) == null ? void 0 : _options$defaultOptio2.queries),
3346
+ queryKey,
3347
+ queryHash
3348
+ }, // Reset fetch status to idle to avoid
3349
+ // query being stuck in fetching state upon hydration
3350
+ { ...state,
3351
+ fetchStatus: 'idle'
3352
+ });
3353
+ });
3354
+ }
3355
+
3356
+ const unstable_batchedUpdates = ReactDOM__namespace.unstable_batchedUpdates;
3357
+
3358
+ notifyManager.setBatchNotifyFunction(unstable_batchedUpdates);
3359
+
3360
+ var shim = {exports: {}};
3361
+
3362
+ var useSyncExternalStoreShim_development = {};
3363
+
3364
+ /**
3365
+ * @license React
3366
+ * use-sync-external-store-shim.development.js
3367
+ *
3368
+ * Copyright (c) Facebook, Inc. and its affiliates.
3369
+ *
3370
+ * This source code is licensed under the MIT license found in the
3371
+ * LICENSE file in the root directory of this source tree.
3372
+ */
3373
+
3374
+ var hasRequiredUseSyncExternalStoreShim_development;
3375
+
3376
+ function requireUseSyncExternalStoreShim_development () {
3377
+ if (hasRequiredUseSyncExternalStoreShim_development) return useSyncExternalStoreShim_development;
3378
+ hasRequiredUseSyncExternalStoreShim_development = 1;
3379
+
3380
+ {
3381
+ (function() {
3382
+
3383
+ /* global __REACT_DEVTOOLS_GLOBAL_HOOK__ */
3384
+ if (
3385
+ typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ !== 'undefined' &&
3386
+ typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart ===
3387
+ 'function'
3388
+ ) {
3389
+ __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart(new Error());
3390
+ }
3391
+ var React = React__default["default"];
3392
+
3393
+ var ReactSharedInternals = React.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;
3394
+
3395
+ function error(format) {
3396
+ {
3397
+ {
3398
+ for (var _len2 = arguments.length, args = new Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) {
3399
+ args[_key2 - 1] = arguments[_key2];
3400
+ }
3401
+
3402
+ printWarning('error', format, args);
3403
+ }
3404
+ }
3405
+ }
3406
+
3407
+ function printWarning(level, format, args) {
3408
+ // When changing this logic, you might want to also
3409
+ // update consoleWithStackDev.www.js as well.
3410
+ {
3411
+ var ReactDebugCurrentFrame = ReactSharedInternals.ReactDebugCurrentFrame;
3412
+ var stack = ReactDebugCurrentFrame.getStackAddendum();
3413
+
3414
+ if (stack !== '') {
3415
+ format += '%s';
3416
+ args = args.concat([stack]);
3417
+ } // eslint-disable-next-line react-internal/safe-string-coercion
3418
+
3419
+
3420
+ var argsWithFormat = args.map(function (item) {
3421
+ return String(item);
3422
+ }); // Careful: RN currently depends on this prefix
3423
+
3424
+ argsWithFormat.unshift('Warning: ' + format); // We intentionally don't use spread (or .apply) directly because it
3425
+ // breaks IE9: https://github.com/facebook/react/issues/13610
3426
+ // eslint-disable-next-line react-internal/no-production-logging
3427
+
3428
+ Function.prototype.apply.call(console[level], console, argsWithFormat);
3429
+ }
3430
+ }
3431
+
3432
+ /**
3433
+ * inlined Object.is polyfill to avoid requiring consumers ship their own
3434
+ * https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/is
3435
+ */
3436
+ function is(x, y) {
3437
+ return x === y && (x !== 0 || 1 / x === 1 / y) || x !== x && y !== y // eslint-disable-line no-self-compare
3438
+ ;
3439
+ }
3440
+
3441
+ var objectIs = typeof Object.is === 'function' ? Object.is : is;
3442
+
3443
+ // dispatch for CommonJS interop named imports.
3444
+
3445
+ var useState = React.useState,
3446
+ useEffect = React.useEffect,
3447
+ useLayoutEffect = React.useLayoutEffect,
3448
+ useDebugValue = React.useDebugValue;
3449
+ var didWarnOld18Alpha = false;
3450
+ var didWarnUncachedGetSnapshot = false; // Disclaimer: This shim breaks many of the rules of React, and only works
3451
+ // because of a very particular set of implementation details and assumptions
3452
+ // -- change any one of them and it will break. The most important assumption
3453
+ // is that updates are always synchronous, because concurrent rendering is
3454
+ // only available in versions of React that also have a built-in
3455
+ // useSyncExternalStore API. And we only use this shim when the built-in API
3456
+ // does not exist.
3457
+ //
3458
+ // Do not assume that the clever hacks used by this hook also work in general.
3459
+ // The point of this shim is to replace the need for hacks by other libraries.
3460
+
3461
+ function useSyncExternalStore(subscribe, getSnapshot, // Note: The shim does not use getServerSnapshot, because pre-18 versions of
3462
+ // React do not expose a way to check if we're hydrating. So users of the shim
3463
+ // will need to track that themselves and return the correct value
3464
+ // from `getSnapshot`.
3465
+ getServerSnapshot) {
3466
+ {
3467
+ if (!didWarnOld18Alpha) {
3468
+ if (React.startTransition !== undefined) {
3469
+ didWarnOld18Alpha = true;
3470
+
3471
+ error('You are using an outdated, pre-release alpha of React 18 that ' + 'does not support useSyncExternalStore. The ' + 'use-sync-external-store shim will not work correctly. Upgrade ' + 'to a newer pre-release.');
3472
+ }
3473
+ }
3474
+ } // Read the current snapshot from the store on every render. Again, this
3475
+ // breaks the rules of React, and only works here because of specific
3476
+ // implementation details, most importantly that updates are
3477
+ // always synchronous.
3478
+
3479
+
3480
+ var value = getSnapshot();
3481
+
3482
+ {
3483
+ if (!didWarnUncachedGetSnapshot) {
3484
+ var cachedValue = getSnapshot();
3485
+
3486
+ if (!objectIs(value, cachedValue)) {
3487
+ error('The result of getSnapshot should be cached to avoid an infinite loop');
3488
+
3489
+ didWarnUncachedGetSnapshot = true;
3490
+ }
3491
+ }
3492
+ } // Because updates are synchronous, we don't queue them. Instead we force a
3493
+ // re-render whenever the subscribed state changes by updating an some
3494
+ // arbitrary useState hook. Then, during render, we call getSnapshot to read
3495
+ // the current value.
3496
+ //
3497
+ // Because we don't actually use the state returned by the useState hook, we
3498
+ // can save a bit of memory by storing other stuff in that slot.
3499
+ //
3500
+ // To implement the early bailout, we need to track some things on a mutable
3501
+ // object. Usually, we would put that in a useRef hook, but we can stash it in
3502
+ // our useState hook instead.
3503
+ //
3504
+ // To force a re-render, we call forceUpdate({inst}). That works because the
3505
+ // new object always fails an equality check.
3506
+
3507
+
3508
+ var _useState = useState({
3509
+ inst: {
3510
+ value: value,
3511
+ getSnapshot: getSnapshot
3512
+ }
3513
+ }),
3514
+ inst = _useState[0].inst,
3515
+ forceUpdate = _useState[1]; // Track the latest getSnapshot function with a ref. This needs to be updated
3516
+ // in the layout phase so we can access it during the tearing check that
3517
+ // happens on subscribe.
3518
+
3519
+
3520
+ useLayoutEffect(function () {
3521
+ inst.value = value;
3522
+ inst.getSnapshot = getSnapshot; // Whenever getSnapshot or subscribe changes, we need to check in the
3523
+ // commit phase if there was an interleaved mutation. In concurrent mode
3524
+ // this can happen all the time, but even in synchronous mode, an earlier
3525
+ // effect may have mutated the store.
3526
+
3527
+ if (checkIfSnapshotChanged(inst)) {
3528
+ // Force a re-render.
3529
+ forceUpdate({
3530
+ inst: inst
3531
+ });
3532
+ }
3533
+ }, [subscribe, value, getSnapshot]);
3534
+ useEffect(function () {
3535
+ // Check for changes right before subscribing. Subsequent changes will be
3536
+ // detected in the subscription handler.
3537
+ if (checkIfSnapshotChanged(inst)) {
3538
+ // Force a re-render.
3539
+ forceUpdate({
3540
+ inst: inst
3541
+ });
3542
+ }
3543
+
3544
+ var handleStoreChange = function () {
3545
+ // TODO: Because there is no cross-renderer API for batching updates, it's
3546
+ // up to the consumer of this library to wrap their subscription event
3547
+ // with unstable_batchedUpdates. Should we try to detect when this isn't
3548
+ // the case and print a warning in development?
3549
+ // The store changed. Check if the snapshot changed since the last time we
3550
+ // read from the store.
3551
+ if (checkIfSnapshotChanged(inst)) {
3552
+ // Force a re-render.
3553
+ forceUpdate({
3554
+ inst: inst
3555
+ });
3556
+ }
3557
+ }; // Subscribe to the store and return a clean-up function.
3558
+
3559
+
3560
+ return subscribe(handleStoreChange);
3561
+ }, [subscribe]);
3562
+ useDebugValue(value);
3563
+ return value;
3564
+ }
3565
+
3566
+ function checkIfSnapshotChanged(inst) {
3567
+ var latestGetSnapshot = inst.getSnapshot;
3568
+ var prevValue = inst.value;
3569
+
3570
+ try {
3571
+ var nextValue = latestGetSnapshot();
3572
+ return !objectIs(prevValue, nextValue);
3573
+ } catch (error) {
3574
+ return true;
3575
+ }
3576
+ }
3577
+
3578
+ function useSyncExternalStore$1(subscribe, getSnapshot, getServerSnapshot) {
3579
+ // Note: The shim does not use getServerSnapshot, because pre-18 versions of
3580
+ // React do not expose a way to check if we're hydrating. So users of the shim
3581
+ // will need to track that themselves and return the correct value
3582
+ // from `getSnapshot`.
3583
+ return getSnapshot();
3584
+ }
3585
+
3586
+ var canUseDOM = !!(typeof window !== 'undefined' && typeof window.document !== 'undefined' && typeof window.document.createElement !== 'undefined');
3587
+
3588
+ var isServerEnvironment = !canUseDOM;
3589
+
3590
+ var shim = isServerEnvironment ? useSyncExternalStore$1 : useSyncExternalStore;
3591
+ var useSyncExternalStore$2 = React.useSyncExternalStore !== undefined ? React.useSyncExternalStore : shim;
3592
+
3593
+ useSyncExternalStoreShim_development.useSyncExternalStore = useSyncExternalStore$2;
3594
+ /* global __REACT_DEVTOOLS_GLOBAL_HOOK__ */
3595
+ if (
3596
+ typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ !== 'undefined' &&
3597
+ typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop ===
3598
+ 'function'
3599
+ ) {
3600
+ __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop(new Error());
3601
+ }
3602
+
3603
+ })();
3604
+ }
3605
+ return useSyncExternalStoreShim_development;
3606
+ }
3607
+
3608
+ (function (module) {
3609
+
3610
+ {
3611
+ module.exports = requireUseSyncExternalStoreShim_development();
3612
+ }
3613
+ } (shim));
3614
+
3615
+ const useSyncExternalStore = shim.exports.useSyncExternalStore;
3616
+
3617
+ const defaultContext = /*#__PURE__*/React__namespace.createContext(undefined);
3618
+ const QueryClientSharingContext = /*#__PURE__*/React__namespace.createContext(false); // If we are given a context, we will use it.
3619
+ // Otherwise, if contextSharing is on, we share the first and at least one
3620
+ // instance of the context across the window
3621
+ // to ensure that if React Query is used across
3622
+ // different bundles or microfrontends they will
3623
+ // all use the same **instance** of context, regardless
3624
+ // of module scoping.
3625
+
3626
+ function getQueryClientContext(context, contextSharing) {
3627
+ if (context) {
3628
+ return context;
3629
+ }
3630
+
3631
+ if (contextSharing && typeof window !== 'undefined') {
3632
+ if (!window.ReactQueryClientContext) {
3633
+ window.ReactQueryClientContext = defaultContext;
3634
+ }
3635
+
3636
+ return window.ReactQueryClientContext;
3637
+ }
3638
+
3639
+ return defaultContext;
3640
+ }
3641
+
3642
+ const useQueryClient = ({
3643
+ context
3644
+ } = {}) => {
3645
+ const queryClient = React__namespace.useContext(getQueryClientContext(context, React__namespace.useContext(QueryClientSharingContext)));
3646
+
3647
+ if (!queryClient) {
3648
+ throw new Error('No QueryClient set, use QueryClientProvider to set one');
3649
+ }
3650
+
3651
+ return queryClient;
3652
+ };
3653
+ const QueryClientProvider = ({
3654
+ client,
3655
+ children,
3656
+ context,
3657
+ contextSharing = false
3658
+ }) => {
3659
+ React__namespace.useEffect(() => {
3660
+ client.mount();
3661
+ return () => {
3662
+ client.unmount();
3663
+ };
3664
+ }, [client]);
3665
+
3666
+ if (contextSharing) {
3667
+ client.getLogger().error("The contextSharing option has been deprecated and will be removed in the next major version");
3668
+ }
3669
+
3670
+ const Context = getQueryClientContext(context, contextSharing);
3671
+ return /*#__PURE__*/React__namespace.createElement(QueryClientSharingContext.Provider, {
3672
+ value: !context && contextSharing
3673
+ }, /*#__PURE__*/React__namespace.createElement(Context.Provider, {
3674
+ value: client
3675
+ }, children));
3676
+ };
3677
+
3678
+ const IsRestoringContext = /*#__PURE__*/React__namespace.createContext(false);
3679
+ const useIsRestoring = () => React__namespace.useContext(IsRestoringContext);
3680
+ const IsRestoringProvider = IsRestoringContext.Provider;
3681
+
3682
+ function createValue() {
3683
+ let isReset = false;
3684
+ return {
3685
+ clearReset: () => {
3686
+ isReset = false;
3687
+ },
3688
+ reset: () => {
3689
+ isReset = true;
3690
+ },
3691
+ isReset: () => {
3692
+ return isReset;
3693
+ }
3694
+ };
3695
+ }
3696
+
3697
+ const QueryErrorResetBoundaryContext = /*#__PURE__*/React__namespace.createContext(createValue()); // HOOK
3698
+
3699
+ const useQueryErrorResetBoundary = () => React__namespace.useContext(QueryErrorResetBoundaryContext); // COMPONENT
3700
+
3701
+ const QueryErrorResetBoundary = ({
3702
+ children
3703
+ }) => {
3704
+ const [value] = React__namespace.useState(() => createValue());
3705
+ return /*#__PURE__*/React__namespace.createElement(QueryErrorResetBoundaryContext.Provider, {
3706
+ value: value
3707
+ }, typeof children === 'function' ? children(value) : children);
3708
+ };
3709
+
3710
+ function shouldThrowError(_useErrorBoundary, params) {
3711
+ // Allow useErrorBoundary function to override throwing behavior on a per-error basis
3712
+ if (typeof _useErrorBoundary === 'function') {
3713
+ return _useErrorBoundary(...params);
3714
+ }
3715
+
3716
+ return !!_useErrorBoundary;
3717
+ }
3718
+
3719
+ const ensurePreventErrorBoundaryRetry = (options, errorResetBoundary) => {
3720
+ if (options.suspense || options.useErrorBoundary) {
3721
+ // Prevent retrying failed query if the error boundary has not been reset yet
3722
+ if (!errorResetBoundary.isReset()) {
3723
+ options.retryOnMount = false;
3724
+ }
3725
+ }
3726
+ };
3727
+ const useClearResetErrorBoundary = errorResetBoundary => {
3728
+ React__namespace.useEffect(() => {
3729
+ errorResetBoundary.clearReset();
3730
+ }, [errorResetBoundary]);
3731
+ };
3732
+ const getHasError = ({
3733
+ result,
3734
+ errorResetBoundary,
3735
+ useErrorBoundary,
3736
+ query
3737
+ }) => {
3738
+ return result.isError && !errorResetBoundary.isReset() && !result.isFetching && shouldThrowError(useErrorBoundary, [result.error, query]);
3739
+ };
3740
+
3741
+ /**
3742
+ * Ensures minimum staleTime and cacheTime values when suspense is enabled.
3743
+ * Despite the name, this function guards both staleTime and cacheTime to prevent
3744
+ * infinite re-render loops with synchronous queries.
3745
+ *
3746
+ * @deprecated in v5 - replaced by ensureSuspenseTimers
3747
+ */
3748
+ const ensureStaleTime = defaultedOptions => {
3749
+ if (defaultedOptions.suspense) {
3750
+ // Always set stale time when using suspense to prevent
3751
+ // fetching again when directly mounting after suspending
3752
+ if (typeof defaultedOptions.staleTime !== 'number') {
3753
+ defaultedOptions.staleTime = 1000;
3754
+ }
3755
+
3756
+ if (typeof defaultedOptions.cacheTime === 'number') {
3757
+ defaultedOptions.cacheTime = Math.max(defaultedOptions.cacheTime, 1000);
3758
+ }
3759
+ }
3760
+ };
3761
+ const willFetch = (result, isRestoring) => result.isLoading && result.isFetching && !isRestoring;
3762
+ const shouldSuspend = (defaultedOptions, result, isRestoring) => (defaultedOptions == null ? void 0 : defaultedOptions.suspense) && willFetch(result, isRestoring);
3763
+ const fetchOptimistic = (defaultedOptions, observer, errorResetBoundary) => observer.fetchOptimistic(defaultedOptions).then(({
3764
+ data
3765
+ }) => {
3766
+ defaultedOptions.onSuccess == null ? void 0 : defaultedOptions.onSuccess(data);
3767
+ defaultedOptions.onSettled == null ? void 0 : defaultedOptions.onSettled(data, null);
3768
+ }).catch(error => {
3769
+ errorResetBoundary.clearReset();
3770
+ defaultedOptions.onError == null ? void 0 : defaultedOptions.onError(error);
3771
+ defaultedOptions.onSettled == null ? void 0 : defaultedOptions.onSettled(undefined, error);
3772
+ });
3773
+
3774
+ function useQueries({
3775
+ queries,
3776
+ context
3777
+ }) {
3778
+ const queryClient = useQueryClient({
3779
+ context
3780
+ });
3781
+ const isRestoring = useIsRestoring();
3782
+ const errorResetBoundary = useQueryErrorResetBoundary();
3783
+ const defaultedQueries = React__namespace.useMemo(() => queries.map(options => {
3784
+ const defaultedOptions = queryClient.defaultQueryOptions(options); // Make sure the results are already in fetching state before subscribing or updating options
3785
+
3786
+ defaultedOptions._optimisticResults = isRestoring ? 'isRestoring' : 'optimistic';
3787
+ return defaultedOptions;
3788
+ }), [queries, queryClient, isRestoring]);
3789
+ defaultedQueries.forEach(query => {
3790
+ ensureStaleTime(query);
3791
+ ensurePreventErrorBoundaryRetry(query, errorResetBoundary);
3792
+ });
3793
+ useClearResetErrorBoundary(errorResetBoundary);
3794
+ const [observer] = React__namespace.useState(() => new QueriesObserver(queryClient, defaultedQueries));
3795
+ const optimisticResult = observer.getOptimisticResult(defaultedQueries);
3796
+ useSyncExternalStore(React__namespace.useCallback(onStoreChange => isRestoring ? () => undefined : observer.subscribe(notifyManager.batchCalls(onStoreChange)), [observer, isRestoring]), () => observer.getCurrentResult(), () => observer.getCurrentResult());
3797
+ React__namespace.useEffect(() => {
3798
+ // Do not notify on updates because of changes in the options because
3799
+ // these changes should already be reflected in the optimistic result.
3800
+ observer.setQueries(defaultedQueries, {
3801
+ listeners: false
3802
+ });
3803
+ }, [defaultedQueries, observer]);
3804
+ const shouldAtLeastOneSuspend = optimisticResult.some((result, index) => shouldSuspend(defaultedQueries[index], result, isRestoring));
3805
+ const suspensePromises = shouldAtLeastOneSuspend ? optimisticResult.flatMap((result, index) => {
3806
+ const options = defaultedQueries[index];
3807
+ const queryObserver = observer.getObservers()[index];
3808
+
3809
+ if (options && queryObserver) {
3810
+ if (shouldSuspend(options, result, isRestoring)) {
3811
+ return fetchOptimistic(options, queryObserver, errorResetBoundary);
3812
+ } else if (willFetch(result, isRestoring)) {
3813
+ void fetchOptimistic(options, queryObserver, errorResetBoundary);
3814
+ }
3815
+ }
3816
+
3817
+ return [];
3818
+ }) : [];
3819
+
3820
+ if (suspensePromises.length > 0) {
3821
+ throw Promise.all(suspensePromises);
3822
+ }
3823
+
3824
+ const observerQueries = observer.getQueries();
3825
+ const firstSingleResultWhichShouldThrow = optimisticResult.find((result, index) => {
3826
+ var _defaultedQueries$ind, _defaultedQueries$ind2;
3827
+
3828
+ return getHasError({
3829
+ result,
3830
+ errorResetBoundary,
3831
+ useErrorBoundary: (_defaultedQueries$ind = (_defaultedQueries$ind2 = defaultedQueries[index]) == null ? void 0 : _defaultedQueries$ind2.useErrorBoundary) != null ? _defaultedQueries$ind : false,
3832
+ query: observerQueries[index]
3833
+ });
3834
+ });
3835
+
3836
+ if (firstSingleResultWhichShouldThrow != null && firstSingleResultWhichShouldThrow.error) {
3837
+ throw firstSingleResultWhichShouldThrow.error;
3838
+ }
3839
+
3840
+ return optimisticResult;
3841
+ }
3842
+
3843
+ function useBaseQuery(options, Observer) {
3844
+ const queryClient = useQueryClient({
3845
+ context: options.context
3846
+ });
3847
+ const isRestoring = useIsRestoring();
3848
+ const errorResetBoundary = useQueryErrorResetBoundary();
3849
+ const defaultedOptions = queryClient.defaultQueryOptions(options); // Make sure results are optimistically set in fetching state before subscribing or updating options
3850
+
3851
+ defaultedOptions._optimisticResults = isRestoring ? 'isRestoring' : 'optimistic'; // Include callbacks in batch renders
3852
+
3853
+ if (defaultedOptions.onError) {
3854
+ defaultedOptions.onError = notifyManager.batchCalls(defaultedOptions.onError);
3855
+ }
3856
+
3857
+ if (defaultedOptions.onSuccess) {
3858
+ defaultedOptions.onSuccess = notifyManager.batchCalls(defaultedOptions.onSuccess);
3859
+ }
3860
+
3861
+ if (defaultedOptions.onSettled) {
3862
+ defaultedOptions.onSettled = notifyManager.batchCalls(defaultedOptions.onSettled);
3863
+ }
3864
+
3865
+ ensureStaleTime(defaultedOptions);
3866
+ ensurePreventErrorBoundaryRetry(defaultedOptions, errorResetBoundary);
3867
+ useClearResetErrorBoundary(errorResetBoundary);
3868
+ const [observer] = React__namespace.useState(() => new Observer(queryClient, defaultedOptions));
3869
+ const result = observer.getOptimisticResult(defaultedOptions);
3870
+ useSyncExternalStore(React__namespace.useCallback(onStoreChange => {
3871
+ const unsubscribe = isRestoring ? () => undefined : observer.subscribe(notifyManager.batchCalls(onStoreChange)); // Update result to make sure we did not miss any query updates
3872
+ // between creating the observer and subscribing to it.
3873
+
3874
+ observer.updateResult();
3875
+ return unsubscribe;
3876
+ }, [observer, isRestoring]), () => observer.getCurrentResult(), () => observer.getCurrentResult());
3877
+ React__namespace.useEffect(() => {
3878
+ // Do not notify on updates because of changes in the options because
3879
+ // these changes should already be reflected in the optimistic result.
3880
+ observer.setOptions(defaultedOptions, {
3881
+ listeners: false
3882
+ });
3883
+ }, [defaultedOptions, observer]); // Handle suspense
3884
+
3885
+ if (shouldSuspend(defaultedOptions, result, isRestoring)) {
3886
+ throw fetchOptimistic(defaultedOptions, observer, errorResetBoundary);
3887
+ } // Handle error boundary
3888
+
3889
+
3890
+ if (getHasError({
3891
+ result,
3892
+ errorResetBoundary,
3893
+ useErrorBoundary: defaultedOptions.useErrorBoundary,
3894
+ query: observer.getCurrentQuery()
3895
+ })) {
3896
+ throw result.error;
3897
+ } // Handle result property usage tracking
3898
+
3899
+
3900
+ return !defaultedOptions.notifyOnChangeProps ? observer.trackResult(result) : result;
3901
+ }
3902
+
3903
+ function useQuery(arg1, arg2, arg3) {
3904
+ const parsedOptions = parseQueryArgs(arg1, arg2, arg3);
3905
+ return useBaseQuery(parsedOptions, QueryObserver);
3906
+ }
3907
+
3908
+ function useSuspenseQuery(options) {
3909
+ return useBaseQuery({ ...options,
3910
+ enabled: true,
3911
+ useErrorBoundary: true,
3912
+ suspense: true,
3913
+ placeholderData: undefined,
3914
+ networkMode: 'always',
3915
+ onSuccess: undefined,
3916
+ onError: undefined,
3917
+ onSettled: undefined
3918
+ }, QueryObserver);
3919
+ }
3920
+
3921
+ function useSuspenseInfiniteQuery(options) {
3922
+ return useBaseQuery({ ...options,
3923
+ enabled: true,
3924
+ suspense: true,
3925
+ useErrorBoundary: true,
3926
+ networkMode: 'always'
3927
+ }, InfiniteQueryObserver);
3928
+ }
3929
+
3930
+ function useSuspenseQueries({
3931
+ queries,
3932
+ context
3933
+ }) {
3934
+ return useQueries({
3935
+ queries: queries.map(query => ({ ...query,
3936
+ enabled: true,
3937
+ useErrorBoundary: true,
3938
+ suspense: true,
3939
+ placeholderData: undefined,
3940
+ networkMode: 'always'
3941
+ })),
3942
+ context
3943
+ });
3944
+ }
3945
+
3946
+ function queryOptions(options) {
3947
+ return options;
3948
+ }
3949
+
3950
+ function infiniteQueryOptions(options) {
3951
+ return options;
3952
+ }
3953
+
3954
+ function useHydrate(state, options = {}) {
3955
+ const queryClient = useQueryClient({
3956
+ context: options.context
3957
+ });
3958
+ const optionsRef = React__namespace.useRef(options);
3959
+ optionsRef.current = options; // Running hydrate again with the same queries is safe,
3960
+ // it wont overwrite or initialize existing queries,
3961
+ // relying on useMemo here is only a performance optimization.
3962
+ // hydrate can and should be run *during* render here for SSR to work properly
3963
+
3964
+ React__namespace.useMemo(() => {
3965
+ if (state) {
3966
+ hydrate(queryClient, state, optionsRef.current);
3967
+ }
3968
+ }, [queryClient, state]);
3969
+ }
3970
+ const Hydrate = ({
3971
+ children,
3972
+ options,
3973
+ state
3974
+ }) => {
3975
+ useHydrate(state, options);
3976
+ return children;
3977
+ };
3978
+
3979
+ function useIsFetching(arg1, arg2, arg3) {
3980
+ const [filters, options = {}] = parseFilterArgs(arg1, arg2, arg3);
3981
+ const queryClient = useQueryClient({
3982
+ context: options.context
3983
+ });
3984
+ const queryCache = queryClient.getQueryCache();
3985
+ return useSyncExternalStore(React__namespace.useCallback(onStoreChange => queryCache.subscribe(notifyManager.batchCalls(onStoreChange)), [queryCache]), () => queryClient.isFetching(filters), () => queryClient.isFetching(filters));
3986
+ }
3987
+
3988
+ function useIsMutating(arg1, arg2, arg3) {
3989
+ const [filters, options = {}] = parseMutationFilterArgs(arg1, arg2, arg3);
3990
+ const queryClient = useQueryClient({
3991
+ context: options.context
3992
+ });
3993
+ const mutationCache = queryClient.getMutationCache();
3994
+ return useSyncExternalStore(React__namespace.useCallback(onStoreChange => mutationCache.subscribe(notifyManager.batchCalls(onStoreChange)), [mutationCache]), () => queryClient.isMutating(filters), () => queryClient.isMutating(filters));
3995
+ }
3996
+
3997
+ function useMutation(arg1, arg2, arg3) {
3998
+ const options = parseMutationArgs(arg1, arg2, arg3);
3999
+ const queryClient = useQueryClient({
4000
+ context: options.context
4001
+ });
4002
+ const [observer] = React__namespace.useState(() => new MutationObserver(queryClient, options));
4003
+ React__namespace.useEffect(() => {
4004
+ observer.setOptions(options);
4005
+ }, [observer, options]);
4006
+ const result = useSyncExternalStore(React__namespace.useCallback(onStoreChange => observer.subscribe(notifyManager.batchCalls(onStoreChange)), [observer]), () => observer.getCurrentResult(), () => observer.getCurrentResult());
4007
+ const mutate = React__namespace.useCallback((variables, mutateOptions) => {
4008
+ observer.mutate(variables, mutateOptions).catch(noop);
4009
+ }, [observer]);
4010
+
4011
+ if (result.error && shouldThrowError(observer.options.useErrorBoundary, [result.error])) {
4012
+ throw result.error;
4013
+ }
4014
+
4015
+ return { ...result,
4016
+ mutate,
4017
+ mutateAsync: result.mutate
4018
+ };
4019
+ } // eslint-disable-next-line @typescript-eslint/no-empty-function
4020
+
4021
+ function noop() {}
4022
+
4023
+ function useInfiniteQuery(arg1, arg2, arg3) {
4024
+ const options = parseQueryArgs(arg1, arg2, arg3);
4025
+ return useBaseQuery(options, InfiniteQueryObserver);
4026
+ }
4027
+
4028
+ exports.CancelledError = CancelledError;
4029
+ exports.Hydrate = Hydrate;
4030
+ exports.InfiniteQueryObserver = InfiniteQueryObserver;
4031
+ exports.IsRestoringProvider = IsRestoringProvider;
4032
+ exports.MutationCache = MutationCache;
4033
+ exports.MutationObserver = MutationObserver;
4034
+ exports.QueriesObserver = QueriesObserver;
4035
+ exports.Query = Query;
4036
+ exports.QueryCache = QueryCache;
4037
+ exports.QueryClient = QueryClient;
4038
+ exports.QueryClientProvider = QueryClientProvider;
4039
+ exports.QueryErrorResetBoundary = QueryErrorResetBoundary;
4040
+ exports.QueryObserver = QueryObserver;
4041
+ exports.defaultContext = defaultContext;
4042
+ exports.defaultShouldDehydrateMutation = defaultShouldDehydrateMutation;
4043
+ exports.defaultShouldDehydrateQuery = defaultShouldDehydrateQuery;
4044
+ exports.dehydrate = dehydrate;
4045
+ exports.focusManager = focusManager;
4046
+ exports.hashQueryKey = hashQueryKey;
4047
+ exports.hydrate = hydrate;
4048
+ exports.infiniteQueryOptions = infiniteQueryOptions;
4049
+ exports.isCancelledError = isCancelledError;
4050
+ exports.isError = isError;
4051
+ exports.isServer = isServer;
4052
+ exports.matchQuery = matchQuery;
4053
+ exports.notifyManager = notifyManager;
4054
+ exports.onlineManager = onlineManager;
4055
+ exports.parseFilterArgs = parseFilterArgs;
4056
+ exports.parseMutationArgs = parseMutationArgs;
4057
+ exports.parseMutationFilterArgs = parseMutationFilterArgs;
4058
+ exports.parseQueryArgs = parseQueryArgs;
4059
+ exports.queryOptions = queryOptions;
4060
+ exports.replaceEqualDeep = replaceEqualDeep;
4061
+ exports.useHydrate = useHydrate;
4062
+ exports.useInfiniteQuery = useInfiniteQuery;
4063
+ exports.useIsFetching = useIsFetching;
4064
+ exports.useIsMutating = useIsMutating;
4065
+ exports.useIsRestoring = useIsRestoring;
4066
+ exports.useMutation = useMutation;
4067
+ exports.useQueries = useQueries;
4068
+ exports.useQuery = useQuery;
4069
+ exports.useQueryClient = useQueryClient;
4070
+ exports.useQueryErrorResetBoundary = useQueryErrorResetBoundary;
4071
+ exports.useSuspenseInfiniteQuery = useSuspenseInfiniteQuery;
4072
+ exports.useSuspenseQueries = useSuspenseQueries;
4073
+ exports.useSuspenseQuery = useSuspenseQuery;
4074
+
4075
+ Object.defineProperty(exports, '__esModule', { value: true });
4076
+
4077
+ }));
4078
+ //# sourceMappingURL=index.development.js.map