@tanstack/query-core 4.24.10 → 5.0.0-alpha.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (183) hide show
  1. package/build/lib/focusManager.d.ts +1 -3
  2. package/build/lib/focusManager.esm.js +19 -36
  3. package/build/lib/focusManager.esm.js.map +1 -1
  4. package/build/lib/focusManager.js +19 -38
  5. package/build/lib/focusManager.js.map +1 -1
  6. package/build/lib/focusManager.mjs +19 -36
  7. package/build/lib/focusManager.mjs.map +1 -1
  8. package/build/lib/hydration.esm.js +21 -23
  9. package/build/lib/hydration.esm.js.map +1 -1
  10. package/build/lib/hydration.js +21 -25
  11. package/build/lib/hydration.js.map +1 -1
  12. package/build/lib/hydration.mjs +21 -23
  13. package/build/lib/hydration.mjs.map +1 -1
  14. package/build/lib/index.d.ts +1 -2
  15. package/build/lib/index.esm.js +1 -1
  16. package/build/lib/index.js +2 -8
  17. package/build/lib/index.js.map +1 -1
  18. package/build/lib/index.mjs +1 -1
  19. package/build/lib/infiniteQueryBehavior.d.ts +3 -7
  20. package/build/lib/infiniteQueryBehavior.esm.js +52 -75
  21. package/build/lib/infiniteQueryBehavior.esm.js.map +1 -1
  22. package/build/lib/infiniteQueryBehavior.js +50 -77
  23. package/build/lib/infiniteQueryBehavior.js.map +1 -1
  24. package/build/lib/infiniteQueryBehavior.mjs +52 -75
  25. package/build/lib/infiniteQueryBehavior.mjs.map +1 -1
  26. package/build/lib/infiniteQueryObserver.d.ts +4 -4
  27. package/build/lib/infiniteQueryObserver.esm.js +18 -26
  28. package/build/lib/infiniteQueryObserver.esm.js.map +1 -1
  29. package/build/lib/infiniteQueryObserver.js +18 -28
  30. package/build/lib/infiniteQueryObserver.js.map +1 -1
  31. package/build/lib/infiniteQueryObserver.mjs +18 -26
  32. package/build/lib/infiniteQueryObserver.mjs.map +1 -1
  33. package/build/lib/mutation.d.ts +11 -22
  34. package/build/lib/mutation.esm.js +73 -105
  35. package/build/lib/mutation.esm.js.map +1 -1
  36. package/build/lib/mutation.js +73 -107
  37. package/build/lib/mutation.js.map +1 -1
  38. package/build/lib/mutation.mjs +73 -105
  39. package/build/lib/mutation.mjs.map +1 -1
  40. package/build/lib/mutationCache.d.ts +4 -6
  41. package/build/lib/mutationCache.esm.js +23 -32
  42. package/build/lib/mutationCache.esm.js.map +1 -1
  43. package/build/lib/mutationCache.js +23 -34
  44. package/build/lib/mutationCache.js.map +1 -1
  45. package/build/lib/mutationCache.mjs +23 -32
  46. package/build/lib/mutationCache.mjs.map +1 -1
  47. package/build/lib/mutationObserver.d.ts +4 -9
  48. package/build/lib/mutationObserver.esm.js +43 -72
  49. package/build/lib/mutationObserver.esm.js.map +1 -1
  50. package/build/lib/mutationObserver.js +43 -74
  51. package/build/lib/mutationObserver.js.map +1 -1
  52. package/build/lib/mutationObserver.mjs +43 -72
  53. package/build/lib/mutationObserver.mjs.map +1 -1
  54. package/build/lib/notifyManager.esm.js +7 -17
  55. package/build/lib/notifyManager.esm.js.map +1 -1
  56. package/build/lib/notifyManager.js +7 -19
  57. package/build/lib/notifyManager.js.map +1 -1
  58. package/build/lib/notifyManager.mjs +7 -17
  59. package/build/lib/notifyManager.mjs.map +1 -1
  60. package/build/lib/onlineManager.d.ts +1 -3
  61. package/build/lib/onlineManager.esm.js +16 -30
  62. package/build/lib/onlineManager.esm.js.map +1 -1
  63. package/build/lib/onlineManager.js +16 -32
  64. package/build/lib/onlineManager.js.map +1 -1
  65. package/build/lib/onlineManager.mjs +16 -30
  66. package/build/lib/onlineManager.mjs.map +1 -1
  67. package/build/lib/queriesObserver.d.ts +3 -10
  68. package/build/lib/queriesObserver.esm.js +47 -71
  69. package/build/lib/queriesObserver.esm.js.map +1 -1
  70. package/build/lib/queriesObserver.js +49 -75
  71. package/build/lib/queriesObserver.js.map +1 -1
  72. package/build/lib/queriesObserver.mjs +47 -71
  73. package/build/lib/queriesObserver.mjs.map +1 -1
  74. package/build/lib/query.d.ts +14 -21
  75. package/build/lib/query.esm.js +140 -194
  76. package/build/lib/query.esm.js.map +1 -1
  77. package/build/lib/query.js +139 -195
  78. package/build/lib/query.js.map +1 -1
  79. package/build/lib/query.mjs +140 -194
  80. package/build/lib/query.mjs.map +1 -1
  81. package/build/lib/queryCache.d.ts +12 -7
  82. package/build/lib/queryCache.esm.js +21 -45
  83. package/build/lib/queryCache.esm.js.map +1 -1
  84. package/build/lib/queryCache.js +20 -46
  85. package/build/lib/queryCache.js.map +1 -1
  86. package/build/lib/queryCache.mjs +21 -45
  87. package/build/lib/queryCache.mjs.map +1 -1
  88. package/build/lib/queryClient.d.ts +18 -46
  89. package/build/lib/queryClient.esm.js +137 -216
  90. package/build/lib/queryClient.esm.js.map +1 -1
  91. package/build/lib/queryClient.js +136 -217
  92. package/build/lib/queryClient.js.map +1 -1
  93. package/build/lib/queryClient.mjs +137 -216
  94. package/build/lib/queryClient.mjs.map +1 -1
  95. package/build/lib/queryObserver.d.ts +4 -29
  96. package/build/lib/queryObserver.esm.js +176 -258
  97. package/build/lib/queryObserver.esm.js.map +1 -1
  98. package/build/lib/queryObserver.js +176 -260
  99. package/build/lib/queryObserver.js.map +1 -1
  100. package/build/lib/queryObserver.mjs +176 -258
  101. package/build/lib/queryObserver.mjs.map +1 -1
  102. package/build/lib/removable.d.ts +3 -3
  103. package/build/lib/removable.esm.js +10 -14
  104. package/build/lib/removable.esm.js.map +1 -1
  105. package/build/lib/removable.js +10 -16
  106. package/build/lib/removable.js.map +1 -1
  107. package/build/lib/removable.mjs +10 -14
  108. package/build/lib/removable.mjs.map +1 -1
  109. package/build/lib/retryer.d.ts +5 -5
  110. package/build/lib/retryer.esm.js +27 -44
  111. package/build/lib/retryer.esm.js.map +1 -1
  112. package/build/lib/retryer.js +27 -46
  113. package/build/lib/retryer.js.map +1 -1
  114. package/build/lib/retryer.mjs +27 -44
  115. package/build/lib/retryer.mjs.map +1 -1
  116. package/build/lib/subscribable.esm.js +4 -7
  117. package/build/lib/subscribable.esm.js.map +1 -1
  118. package/build/lib/subscribable.js +4 -9
  119. package/build/lib/subscribable.js.map +1 -1
  120. package/build/lib/subscribable.mjs +4 -7
  121. package/build/lib/subscribable.mjs.map +1 -1
  122. package/build/lib/tests/utils.d.ts +3 -12
  123. package/build/lib/types.d.ts +111 -99
  124. package/build/lib/utils.d.ts +8 -18
  125. package/build/lib/utils.esm.js +39 -132
  126. package/build/lib/utils.esm.js.map +1 -1
  127. package/build/lib/utils.js +42 -144
  128. package/build/lib/utils.js.map +1 -1
  129. package/build/lib/utils.mjs +39 -132
  130. package/build/lib/utils.mjs.map +1 -1
  131. package/build/umd/index.development.js +868 -1398
  132. package/build/umd/index.development.js.map +1 -1
  133. package/build/umd/index.production.js +1 -1
  134. package/build/umd/index.production.js.map +1 -1
  135. package/package.json +1 -1
  136. package/src/focusManager.ts +17 -24
  137. package/src/index.ts +1 -11
  138. package/src/infiniteQueryBehavior.ts +54 -94
  139. package/src/infiniteQueryObserver.ts +10 -12
  140. package/src/mutation.ts +68 -92
  141. package/src/mutationCache.ts +27 -27
  142. package/src/mutationObserver.ts +60 -97
  143. package/src/onlineManager.ts +14 -14
  144. package/src/queriesObserver.ts +50 -54
  145. package/src/query.ts +106 -110
  146. package/src/queryCache.ts +42 -41
  147. package/src/queryClient.ts +155 -434
  148. package/src/queryObserver.ts +155 -192
  149. package/src/removable.ts +13 -13
  150. package/src/retryer.ts +5 -5
  151. package/src/tests/focusManager.test.tsx +25 -25
  152. package/src/tests/hydration.test.tsx +167 -81
  153. package/src/tests/infiniteQueryBehavior.test.tsx +209 -17
  154. package/src/tests/infiniteQueryObserver.test.tsx +6 -2
  155. package/src/tests/mutationCache.test.tsx +127 -127
  156. package/src/tests/mutationObserver.test.tsx +1 -31
  157. package/src/tests/mutations.test.tsx +62 -43
  158. package/src/tests/onlineManager.test.tsx +12 -4
  159. package/src/tests/queriesObserver.test.tsx +41 -77
  160. package/src/tests/query.test.tsx +175 -243
  161. package/src/tests/queryCache.test.tsx +170 -93
  162. package/src/tests/queryClient.test.tsx +229 -378
  163. package/src/tests/queryObserver.test.tsx +23 -147
  164. package/src/tests/utils.test.tsx +84 -29
  165. package/src/tests/utils.ts +9 -18
  166. package/src/types.ts +187 -140
  167. package/src/utils.ts +31 -124
  168. package/build/lib/logger.d.ts +0 -8
  169. package/build/lib/logger.esm.js +0 -4
  170. package/build/lib/logger.esm.js.map +0 -1
  171. package/build/lib/logger.js +0 -8
  172. package/build/lib/logger.js.map +0 -1
  173. package/build/lib/logger.mjs +0 -4
  174. package/build/lib/logger.mjs.map +0 -1
  175. package/build/lib/logger.native.d.ts +0 -6
  176. package/build/lib/logger.native.esm.js +0 -12
  177. package/build/lib/logger.native.esm.js.map +0 -1
  178. package/build/lib/logger.native.js +0 -16
  179. package/build/lib/logger.native.js.map +0 -1
  180. package/build/lib/logger.native.mjs +0 -12
  181. package/build/lib/logger.native.mjs.map +0 -1
  182. package/src/logger.native.ts +0 -11
  183. package/src/logger.ts +0 -9
@@ -1,7 +1,5 @@
1
1
  'use strict';
2
2
 
3
- Object.defineProperty(exports, '__esModule', { value: true });
4
-
5
3
  var utils = require('./utils.js');
6
4
  var queryCache = require('./queryCache.js');
7
5
  var mutationCache = require('./mutationCache.js');
@@ -9,78 +7,73 @@ var focusManager = require('./focusManager.js');
9
7
  var onlineManager = require('./onlineManager.js');
10
8
  var notifyManager = require('./notifyManager.js');
11
9
  var infiniteQueryBehavior = require('./infiniteQueryBehavior.js');
12
- var logger = require('./logger');
13
10
 
14
11
  // CLASS
12
+
15
13
  class QueryClient {
14
+ #queryCache;
15
+ #mutationCache;
16
+ #defaultOptions;
17
+ #queryDefaults;
18
+ #mutationDefaults;
19
+ #mountCount;
20
+ #unsubscribeFocus;
21
+ #unsubscribeOnline;
16
22
  constructor(config = {}) {
17
- this.queryCache = config.queryCache || new queryCache.QueryCache();
18
- this.mutationCache = config.mutationCache || new mutationCache.MutationCache();
19
- this.logger = config.logger || logger.defaultLogger;
20
- this.defaultOptions = config.defaultOptions || {};
21
- this.queryDefaults = [];
22
- this.mutationDefaults = [];
23
- this.mountCount = 0;
24
-
25
- if (process.env.NODE_ENV !== 'production' && config.logger) {
26
- this.logger.error("Passing a custom logger has been deprecated and will be removed in the next major version.");
27
- }
23
+ this.#queryCache = config.queryCache || new queryCache.QueryCache();
24
+ this.#mutationCache = config.mutationCache || new mutationCache.MutationCache();
25
+ this.#defaultOptions = config.defaultOptions || {};
26
+ this.#queryDefaults = new Map();
27
+ this.#mutationDefaults = new Map();
28
+ this.#mountCount = 0;
28
29
  }
29
-
30
30
  mount() {
31
- this.mountCount++;
32
- if (this.mountCount !== 1) return;
33
- this.unsubscribeFocus = focusManager.focusManager.subscribe(() => {
31
+ this.#mountCount++;
32
+ if (this.#mountCount !== 1) return;
33
+ this.#unsubscribeFocus = focusManager.focusManager.subscribe(() => {
34
34
  if (focusManager.focusManager.isFocused()) {
35
35
  this.resumePausedMutations();
36
- this.queryCache.onFocus();
36
+ this.#queryCache.onFocus();
37
37
  }
38
38
  });
39
- this.unsubscribeOnline = onlineManager.onlineManager.subscribe(() => {
39
+ this.#unsubscribeOnline = onlineManager.onlineManager.subscribe(() => {
40
40
  if (onlineManager.onlineManager.isOnline()) {
41
41
  this.resumePausedMutations();
42
- this.queryCache.onOnline();
42
+ this.#queryCache.onOnline();
43
43
  }
44
44
  });
45
45
  }
46
-
47
46
  unmount() {
48
- var _this$unsubscribeFocu, _this$unsubscribeOnli;
49
-
50
- this.mountCount--;
51
- if (this.mountCount !== 0) return;
52
- (_this$unsubscribeFocu = this.unsubscribeFocus) == null ? void 0 : _this$unsubscribeFocu.call(this);
53
- this.unsubscribeFocus = undefined;
54
- (_this$unsubscribeOnli = this.unsubscribeOnline) == null ? void 0 : _this$unsubscribeOnli.call(this);
55
- this.unsubscribeOnline = undefined;
56
- }
57
-
58
- isFetching(arg1, arg2) {
59
- const [filters] = utils.parseFilterArgs(arg1, arg2);
60
- filters.fetchStatus = 'fetching';
61
- return this.queryCache.findAll(filters).length;
47
+ this.#mountCount--;
48
+ if (this.#mountCount !== 0) return;
49
+ this.#unsubscribeFocus?.();
50
+ this.#unsubscribeFocus = undefined;
51
+ this.#unsubscribeOnline?.();
52
+ this.#unsubscribeOnline = undefined;
53
+ }
54
+ isFetching(filters) {
55
+ return this.#queryCache.findAll({
56
+ ...filters,
57
+ fetchStatus: 'fetching'
58
+ }).length;
62
59
  }
63
-
64
60
  isMutating(filters) {
65
- return this.mutationCache.findAll({ ...filters,
66
- fetching: true
61
+ return this.#mutationCache.findAll({
62
+ ...filters,
63
+ status: 'pending'
67
64
  }).length;
68
65
  }
69
-
70
- getQueryData(queryKey, filters) {
71
- var _this$queryCache$find;
72
-
73
- return (_this$queryCache$find = this.queryCache.find(queryKey, filters)) == null ? void 0 : _this$queryCache$find.state.data;
66
+ getQueryData(queryKey) {
67
+ return this.#queryCache.find({
68
+ queryKey
69
+ })?.state.data;
74
70
  }
75
-
76
- ensureQueryData(arg1, arg2, arg3) {
77
- const parsedOptions = utils.parseQueryArgs(arg1, arg2, arg3);
78
- const cachedData = this.getQueryData(parsedOptions.queryKey);
79
- return cachedData ? Promise.resolve(cachedData) : this.fetchQuery(parsedOptions);
71
+ ensureQueryData(options) {
72
+ const cachedData = this.getQueryData(options.queryKey);
73
+ return cachedData ? Promise.resolve(cachedData) : this.fetchQuery(options);
80
74
  }
81
-
82
- getQueriesData(queryKeyOrFilters) {
83
- return this.getQueryCache().findAll(queryKeyOrFilters).map(({
75
+ getQueriesData(filters) {
76
+ return this.getQueryCache().findAll(filters).map(({
84
77
  queryKey,
85
78
  state
86
79
  }) => {
@@ -88,48 +81,43 @@ class QueryClient {
88
81
  return [queryKey, data];
89
82
  });
90
83
  }
91
-
92
84
  setQueryData(queryKey, updater, options) {
93
- const query = this.queryCache.find(queryKey);
94
- const prevData = query == null ? void 0 : query.state.data;
85
+ const query = this.#queryCache.find({
86
+ queryKey
87
+ });
88
+ const prevData = query?.state.data;
95
89
  const data = utils.functionalUpdate(updater, prevData);
96
-
97
90
  if (typeof data === 'undefined') {
98
91
  return undefined;
99
92
  }
100
-
101
- const parsedOptions = utils.parseQueryArgs(queryKey);
102
- const defaultedOptions = this.defaultQueryOptions(parsedOptions);
103
- return this.queryCache.build(this, defaultedOptions).setData(data, { ...options,
93
+ const defaultedOptions = this.defaultQueryOptions({
94
+ queryKey
95
+ });
96
+ return this.#queryCache.build(this, defaultedOptions).setData(data, {
97
+ ...options,
104
98
  manual: true
105
99
  });
106
100
  }
107
-
108
- setQueriesData(queryKeyOrFilters, updater, options) {
109
- return notifyManager.notifyManager.batch(() => this.getQueryCache().findAll(queryKeyOrFilters).map(({
101
+ setQueriesData(filters, updater, options) {
102
+ return notifyManager.notifyManager.batch(() => this.getQueryCache().findAll(filters).map(({
110
103
  queryKey
111
104
  }) => [queryKey, this.setQueryData(queryKey, updater, options)]));
112
105
  }
113
-
114
- getQueryState(queryKey, filters) {
115
- var _this$queryCache$find2;
116
-
117
- return (_this$queryCache$find2 = this.queryCache.find(queryKey, filters)) == null ? void 0 : _this$queryCache$find2.state;
106
+ getQueryState(queryKey) {
107
+ return this.#queryCache.find({
108
+ queryKey
109
+ })?.state;
118
110
  }
119
-
120
- removeQueries(arg1, arg2) {
121
- const [filters] = utils.parseFilterArgs(arg1, arg2);
122
- const queryCache = this.queryCache;
111
+ removeQueries(filters) {
112
+ const queryCache = this.#queryCache;
123
113
  notifyManager.notifyManager.batch(() => {
124
114
  queryCache.findAll(filters).forEach(query => {
125
115
  queryCache.remove(query);
126
116
  });
127
117
  });
128
118
  }
129
-
130
- resetQueries(arg1, arg2, arg3) {
131
- const [filters, options] = utils.parseFilterArgs(arg1, arg2, arg3);
132
- const queryCache = this.queryCache;
119
+ resetQueries(filters, options) {
120
+ const queryCache = this.#queryCache;
133
121
  const refetchFilters = {
134
122
  type: 'active',
135
123
  ...filters
@@ -141,219 +129,150 @@ class QueryClient {
141
129
  return this.refetchQueries(refetchFilters, options);
142
130
  });
143
131
  }
144
-
145
- cancelQueries(arg1, arg2, arg3) {
146
- const [filters, cancelOptions = {}] = utils.parseFilterArgs(arg1, arg2, arg3);
147
-
132
+ cancelQueries(filters = {}, cancelOptions = {}) {
148
133
  if (typeof cancelOptions.revert === 'undefined') {
149
134
  cancelOptions.revert = true;
150
135
  }
151
-
152
- const promises = notifyManager.notifyManager.batch(() => this.queryCache.findAll(filters).map(query => query.cancel(cancelOptions)));
136
+ const promises = notifyManager.notifyManager.batch(() => this.#queryCache.findAll(filters).map(query => query.cancel(cancelOptions)));
153
137
  return Promise.all(promises).then(utils.noop).catch(utils.noop);
154
138
  }
155
-
156
- invalidateQueries(arg1, arg2, arg3) {
157
- const [filters, options] = utils.parseFilterArgs(arg1, arg2, arg3);
139
+ invalidateQueries(filters = {}, options = {}) {
158
140
  return notifyManager.notifyManager.batch(() => {
159
- var _ref, _filters$refetchType;
160
-
161
- this.queryCache.findAll(filters).forEach(query => {
141
+ this.#queryCache.findAll(filters).forEach(query => {
162
142
  query.invalidate();
163
143
  });
164
-
165
144
  if (filters.refetchType === 'none') {
166
145
  return Promise.resolve();
167
146
  }
168
-
169
- const refetchFilters = { ...filters,
170
- type: (_ref = (_filters$refetchType = filters.refetchType) != null ? _filters$refetchType : filters.type) != null ? _ref : 'active'
147
+ const refetchFilters = {
148
+ ...filters,
149
+ type: filters.refetchType ?? filters.type ?? 'active'
171
150
  };
172
151
  return this.refetchQueries(refetchFilters, options);
173
152
  });
174
153
  }
175
-
176
- refetchQueries(arg1, arg2, arg3) {
177
- const [filters, options] = utils.parseFilterArgs(arg1, arg2, arg3);
178
- const promises = notifyManager.notifyManager.batch(() => this.queryCache.findAll(filters).filter(query => !query.isDisabled()).map(query => {
179
- var _options$cancelRefetc;
180
-
181
- return query.fetch(undefined, { ...options,
182
- cancelRefetch: (_options$cancelRefetc = options == null ? void 0 : options.cancelRefetch) != null ? _options$cancelRefetc : true,
183
- meta: {
184
- refetchPage: filters.refetchPage
185
- }
186
- });
187
- }));
154
+ refetchQueries(filters = {}, options) {
155
+ const promises = notifyManager.notifyManager.batch(() => this.#queryCache.findAll(filters).filter(query => !query.isDisabled()).map(query => query.fetch(undefined, {
156
+ ...options,
157
+ cancelRefetch: options?.cancelRefetch ?? true
158
+ })));
188
159
  let promise = Promise.all(promises).then(utils.noop);
189
-
190
- if (!(options != null && options.throwOnError)) {
160
+ if (!options?.throwOnError) {
191
161
  promise = promise.catch(utils.noop);
192
162
  }
193
-
194
163
  return promise;
195
164
  }
165
+ fetchQuery(options) {
166
+ const defaultedOptions = this.defaultQueryOptions(options);
196
167
 
197
- fetchQuery(arg1, arg2, arg3) {
198
- const parsedOptions = utils.parseQueryArgs(arg1, arg2, arg3);
199
- const defaultedOptions = this.defaultQueryOptions(parsedOptions); // https://github.com/tannerlinsley/react-query/issues/652
200
-
168
+ // https://github.com/tannerlinsley/react-query/issues/652
201
169
  if (typeof defaultedOptions.retry === 'undefined') {
202
170
  defaultedOptions.retry = false;
203
171
  }
204
-
205
- const query = this.queryCache.build(this, defaultedOptions);
172
+ const query = this.#queryCache.build(this, defaultedOptions);
206
173
  return query.isStaleByTime(defaultedOptions.staleTime) ? query.fetch(defaultedOptions) : Promise.resolve(query.state.data);
207
174
  }
208
-
209
- prefetchQuery(arg1, arg2, arg3) {
210
- return this.fetchQuery(arg1, arg2, arg3).then(utils.noop).catch(utils.noop);
175
+ prefetchQuery(options) {
176
+ return this.fetchQuery(options).then(utils.noop).catch(utils.noop);
211
177
  }
212
-
213
- fetchInfiniteQuery(arg1, arg2, arg3) {
214
- const parsedOptions = utils.parseQueryArgs(arg1, arg2, arg3);
215
- parsedOptions.behavior = infiniteQueryBehavior.infiniteQueryBehavior();
216
- return this.fetchQuery(parsedOptions);
178
+ fetchInfiniteQuery(options) {
179
+ options.behavior = infiniteQueryBehavior.infiniteQueryBehavior();
180
+ return this.fetchQuery(options);
217
181
  }
218
-
219
- prefetchInfiniteQuery(arg1, arg2, arg3) {
220
- return this.fetchInfiniteQuery(arg1, arg2, arg3).then(utils.noop).catch(utils.noop);
182
+ prefetchInfiniteQuery(options) {
183
+ return this.fetchInfiniteQuery(options).then(utils.noop).catch(utils.noop);
221
184
  }
222
-
223
185
  resumePausedMutations() {
224
- return this.mutationCache.resumePausedMutations();
186
+ return this.#mutationCache.resumePausedMutations();
225
187
  }
226
-
227
188
  getQueryCache() {
228
- return this.queryCache;
189
+ return this.#queryCache;
229
190
  }
230
-
231
191
  getMutationCache() {
232
- return this.mutationCache;
192
+ return this.#mutationCache;
233
193
  }
234
-
235
- getLogger() {
236
- return this.logger;
237
- }
238
-
239
194
  getDefaultOptions() {
240
- return this.defaultOptions;
195
+ return this.#defaultOptions;
241
196
  }
242
-
243
197
  setDefaultOptions(options) {
244
- this.defaultOptions = options;
198
+ this.#defaultOptions = options;
245
199
  }
246
-
247
200
  setQueryDefaults(queryKey, options) {
248
- const result = this.queryDefaults.find(x => utils.hashQueryKey(queryKey) === utils.hashQueryKey(x.queryKey));
249
-
250
- if (result) {
251
- result.defaultOptions = options;
252
- } else {
253
- this.queryDefaults.push({
254
- queryKey,
255
- defaultOptions: options
256
- });
257
- }
201
+ this.#queryDefaults.set(utils.hashKey(queryKey), {
202
+ queryKey,
203
+ defaultOptions: options
204
+ });
258
205
  }
259
-
260
206
  getQueryDefaults(queryKey) {
261
- if (!queryKey) {
262
- return undefined;
263
- } // Get the first matching defaults
264
-
265
-
266
- const firstMatchingDefaults = this.queryDefaults.find(x => utils.partialMatchKey(queryKey, x.queryKey)); // Additional checks and error in dev mode
267
-
268
- if (process.env.NODE_ENV !== 'production') {
269
- // Retrieve all matching defaults for the given key
270
- const matchingDefaults = this.queryDefaults.filter(x => utils.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
271
-
272
- if (matchingDefaults.length > 1) {
273
- 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.");
207
+ const defaults = [...this.#queryDefaults.values()];
208
+ let result = {};
209
+ defaults.forEach(queryDefault => {
210
+ if (utils.partialMatchKey(queryKey, queryDefault.queryKey)) {
211
+ result = {
212
+ ...result,
213
+ ...queryDefault.defaultOptions
214
+ };
274
215
  }
275
- }
276
-
277
- return firstMatchingDefaults == null ? void 0 : firstMatchingDefaults.defaultOptions;
216
+ });
217
+ return result;
278
218
  }
279
-
280
219
  setMutationDefaults(mutationKey, options) {
281
- const result = this.mutationDefaults.find(x => utils.hashQueryKey(mutationKey) === utils.hashQueryKey(x.mutationKey));
282
-
283
- if (result) {
284
- result.defaultOptions = options;
285
- } else {
286
- this.mutationDefaults.push({
287
- mutationKey,
288
- defaultOptions: options
289
- });
290
- }
220
+ this.#mutationDefaults.set(utils.hashKey(mutationKey), {
221
+ mutationKey,
222
+ defaultOptions: options
223
+ });
291
224
  }
292
-
293
225
  getMutationDefaults(mutationKey) {
294
- if (!mutationKey) {
295
- return undefined;
296
- } // Get the first matching defaults
297
-
298
-
299
- const firstMatchingDefaults = this.mutationDefaults.find(x => utils.partialMatchKey(mutationKey, x.mutationKey)); // Additional checks and error in dev mode
300
-
301
- if (process.env.NODE_ENV !== 'production') {
302
- // Retrieve all matching defaults for the given key
303
- const matchingDefaults = this.mutationDefaults.filter(x => utils.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
304
-
305
- if (matchingDefaults.length > 1) {
306
- 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.");
226
+ const defaults = [...this.#mutationDefaults.values()];
227
+ let result = {};
228
+ defaults.forEach(queryDefault => {
229
+ if (utils.partialMatchKey(mutationKey, queryDefault.mutationKey)) {
230
+ result = {
231
+ ...result,
232
+ ...queryDefault.defaultOptions
233
+ };
307
234
  }
308
- }
309
-
310
- return firstMatchingDefaults == null ? void 0 : firstMatchingDefaults.defaultOptions;
235
+ });
236
+ return result;
311
237
  }
312
-
313
238
  defaultQueryOptions(options) {
314
- if (options != null && options._defaulted) {
239
+ if (options?._defaulted) {
315
240
  return options;
316
241
  }
317
-
318
- const defaultedOptions = { ...this.defaultOptions.queries,
319
- ...this.getQueryDefaults(options == null ? void 0 : options.queryKey),
242
+ const defaultedOptions = {
243
+ ...this.#defaultOptions.queries,
244
+ ...(options?.queryKey && this.getQueryDefaults(options.queryKey)),
320
245
  ...options,
321
246
  _defaulted: true
322
247
  };
323
-
324
- if (!defaultedOptions.queryHash && defaultedOptions.queryKey) {
248
+ if (!defaultedOptions.queryHash) {
325
249
  defaultedOptions.queryHash = utils.hashQueryKeyByOptions(defaultedOptions.queryKey, defaultedOptions);
326
- } // dependent default values
327
-
250
+ }
328
251
 
252
+ // dependent default values
329
253
  if (typeof defaultedOptions.refetchOnReconnect === 'undefined') {
330
254
  defaultedOptions.refetchOnReconnect = defaultedOptions.networkMode !== 'always';
331
255
  }
332
-
333
- if (typeof defaultedOptions.useErrorBoundary === 'undefined') {
334
- defaultedOptions.useErrorBoundary = !!defaultedOptions.suspense;
256
+ if (typeof defaultedOptions.throwErrors === 'undefined') {
257
+ defaultedOptions.throwErrors = !!defaultedOptions.suspense;
335
258
  }
336
-
337
259
  return defaultedOptions;
338
260
  }
339
-
340
261
  defaultMutationOptions(options) {
341
- if (options != null && options._defaulted) {
262
+ if (options?._defaulted) {
342
263
  return options;
343
264
  }
344
-
345
- return { ...this.defaultOptions.mutations,
346
- ...this.getMutationDefaults(options == null ? void 0 : options.mutationKey),
265
+ return {
266
+ ...this.#defaultOptions.mutations,
267
+ ...(options?.mutationKey && this.getMutationDefaults(options.mutationKey)),
347
268
  ...options,
348
269
  _defaulted: true
349
270
  };
350
271
  }
351
-
352
272
  clear() {
353
- this.queryCache.clear();
354
- this.mutationCache.clear();
273
+ this.#queryCache.clear();
274
+ this.#mutationCache.clear();
355
275
  }
356
-
357
276
  }
358
277
 
359
278
  exports.QueryClient = QueryClient;