@tanstack/query-core 5.102.7 → 5.103.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 (301) hide show
  1. package/build/legacy/environmentManager.cjs +15 -1
  2. package/build/legacy/environmentManager.cjs.map +1 -1
  3. package/build/legacy/environmentManager.d.cts +15 -1
  4. package/build/legacy/environmentManager.d.cts.map +1 -1
  5. package/build/legacy/environmentManager.d.ts +15 -1
  6. package/build/legacy/environmentManager.d.ts.map +1 -1
  7. package/build/legacy/environmentManager.js +15 -1
  8. package/build/legacy/environmentManager.js.map +1 -1
  9. package/build/legacy/focusManager.cjs +57 -0
  10. package/build/legacy/focusManager.cjs.map +1 -1
  11. package/build/legacy/focusManager.d.cts +57 -0
  12. package/build/legacy/focusManager.d.cts.map +1 -1
  13. package/build/legacy/focusManager.d.ts +57 -0
  14. package/build/legacy/focusManager.d.ts.map +1 -1
  15. package/build/legacy/focusManager.js +57 -0
  16. package/build/legacy/focusManager.js.map +1 -1
  17. package/build/legacy/{hydration-Bjs0MSgg.d.ts → hydration-Cq7QYAzB.d.ts} +1424 -7
  18. package/build/legacy/hydration-Cq7QYAzB.d.ts.map +1 -0
  19. package/build/legacy/{hydration-DWGr3cFC.d.cts → hydration-DwR10Hi-.d.cts} +1424 -7
  20. package/build/legacy/hydration-DwR10Hi-.d.cts.map +1 -0
  21. package/build/legacy/hydration.cjs +57 -4
  22. package/build/legacy/hydration.cjs.map +1 -1
  23. package/build/legacy/hydration.d.cts +1 -1
  24. package/build/legacy/hydration.d.ts +1 -1
  25. package/build/legacy/hydration.js +57 -4
  26. package/build/legacy/hydration.js.map +1 -1
  27. package/build/legacy/index.cjs.map +1 -1
  28. package/build/legacy/index.d.cts +5 -5
  29. package/build/legacy/index.d.ts +5 -5
  30. package/build/legacy/index.js.map +1 -1
  31. package/build/legacy/infiniteQueryBehavior.d.cts +1 -1
  32. package/build/legacy/infiniteQueryBehavior.d.ts +1 -1
  33. package/build/legacy/infiniteQueryObserver.cjs +67 -0
  34. package/build/legacy/infiniteQueryObserver.cjs.map +1 -1
  35. package/build/legacy/infiniteQueryObserver.d.cts +68 -1
  36. package/build/legacy/infiniteQueryObserver.d.cts.map +1 -1
  37. package/build/legacy/infiniteQueryObserver.d.ts +68 -1
  38. package/build/legacy/infiniteQueryObserver.d.ts.map +1 -1
  39. package/build/legacy/infiniteQueryObserver.js +67 -0
  40. package/build/legacy/infiniteQueryObserver.js.map +1 -1
  41. package/build/legacy/mutation.cjs +74 -0
  42. package/build/legacy/mutation.cjs.map +1 -1
  43. package/build/legacy/mutation.d.cts +1 -1
  44. package/build/legacy/mutation.d.ts +1 -1
  45. package/build/legacy/mutation.js +74 -0
  46. package/build/legacy/mutation.js.map +1 -1
  47. package/build/legacy/mutationCache.cjs +74 -0
  48. package/build/legacy/mutationCache.cjs.map +1 -1
  49. package/build/legacy/mutationCache.d.cts +1 -1
  50. package/build/legacy/mutationCache.d.ts +1 -1
  51. package/build/legacy/mutationCache.js +74 -0
  52. package/build/legacy/mutationCache.js.map +1 -1
  53. package/build/legacy/mutationObserver.cjs +71 -0
  54. package/build/legacy/mutationObserver.cjs.map +1 -1
  55. package/build/legacy/mutationObserver.d.cts +1 -1
  56. package/build/legacy/mutationObserver.d.ts +1 -1
  57. package/build/legacy/mutationObserver.js +71 -0
  58. package/build/legacy/mutationObserver.js.map +1 -1
  59. package/build/legacy/notifyManager.cjs +45 -1
  60. package/build/legacy/notifyManager.cjs.map +1 -1
  61. package/build/legacy/notifyManager.d.cts +83 -2
  62. package/build/legacy/notifyManager.d.cts.map +1 -1
  63. package/build/legacy/notifyManager.d.ts +83 -2
  64. package/build/legacy/notifyManager.d.ts.map +1 -1
  65. package/build/legacy/notifyManager.js +45 -1
  66. package/build/legacy/notifyManager.js.map +1 -1
  67. package/build/legacy/onlineManager.cjs +47 -0
  68. package/build/legacy/onlineManager.cjs.map +1 -1
  69. package/build/legacy/onlineManager.d.cts +47 -0
  70. package/build/legacy/onlineManager.d.cts.map +1 -1
  71. package/build/legacy/onlineManager.d.ts +47 -0
  72. package/build/legacy/onlineManager.d.ts.map +1 -1
  73. package/build/legacy/onlineManager.js +47 -0
  74. package/build/legacy/onlineManager.js.map +1 -1
  75. package/build/legacy/queriesObserver.cjs +64 -0
  76. package/build/legacy/queriesObserver.cjs.map +1 -1
  77. package/build/legacy/queriesObserver.d.cts +73 -1
  78. package/build/legacy/queriesObserver.d.cts.map +1 -1
  79. package/build/legacy/queriesObserver.d.ts +73 -1
  80. package/build/legacy/queriesObserver.d.ts.map +1 -1
  81. package/build/legacy/queriesObserver.js +64 -0
  82. package/build/legacy/queriesObserver.js.map +1 -1
  83. package/build/legacy/query.cjs +141 -0
  84. package/build/legacy/query.cjs.map +1 -1
  85. package/build/legacy/query.d.cts +1 -1
  86. package/build/legacy/query.d.ts +1 -1
  87. package/build/legacy/query.js +141 -0
  88. package/build/legacy/query.js.map +1 -1
  89. package/build/legacy/queryCache.cjs +120 -0
  90. package/build/legacy/queryCache.cjs.map +1 -1
  91. package/build/legacy/queryCache.d.cts +1 -1
  92. package/build/legacy/queryCache.d.ts +1 -1
  93. package/build/legacy/queryCache.js +120 -0
  94. package/build/legacy/queryCache.js.map +1 -1
  95. package/build/legacy/queryClient.cjs +363 -0
  96. package/build/legacy/queryClient.cjs.map +1 -1
  97. package/build/legacy/queryClient.d.cts +1 -1
  98. package/build/legacy/queryClient.d.ts +1 -1
  99. package/build/legacy/queryClient.js +363 -0
  100. package/build/legacy/queryClient.js.map +1 -1
  101. package/build/legacy/queryObserver.cjs +116 -2
  102. package/build/legacy/queryObserver.cjs.map +1 -1
  103. package/build/legacy/queryObserver.d.cts +1 -1
  104. package/build/legacy/queryObserver.d.ts +1 -1
  105. package/build/legacy/queryObserver.js +116 -2
  106. package/build/legacy/queryObserver.js.map +1 -1
  107. package/build/legacy/retryer.cjs +18 -0
  108. package/build/legacy/retryer.cjs.map +1 -1
  109. package/build/legacy/retryer.d.cts +1 -1
  110. package/build/legacy/retryer.d.ts +1 -1
  111. package/build/legacy/retryer.js +18 -0
  112. package/build/legacy/retryer.js.map +1 -1
  113. package/build/legacy/streamedQuery.cjs +10 -1
  114. package/build/legacy/streamedQuery.cjs.map +1 -1
  115. package/build/legacy/streamedQuery.d.cts +26 -2
  116. package/build/legacy/streamedQuery.d.cts.map +1 -1
  117. package/build/legacy/streamedQuery.d.ts +26 -2
  118. package/build/legacy/streamedQuery.d.ts.map +1 -1
  119. package/build/legacy/streamedQuery.js +10 -1
  120. package/build/legacy/streamedQuery.js.map +1 -1
  121. package/build/legacy/timeoutManager.cjs +99 -0
  122. package/build/legacy/timeoutManager.cjs.map +1 -1
  123. package/build/legacy/timeoutManager.d.cts +105 -0
  124. package/build/legacy/timeoutManager.d.cts.map +1 -1
  125. package/build/legacy/timeoutManager.d.ts +105 -0
  126. package/build/legacy/timeoutManager.d.ts.map +1 -1
  127. package/build/legacy/timeoutManager.js +99 -0
  128. package/build/legacy/timeoutManager.js.map +1 -1
  129. package/build/legacy/types.cjs.map +1 -1
  130. package/build/legacy/types.d.cts +1 -1
  131. package/build/legacy/types.d.ts +1 -1
  132. package/build/legacy/types.js.map +1 -1
  133. package/build/legacy/utils.cjs +76 -0
  134. package/build/legacy/utils.cjs.map +1 -1
  135. package/build/legacy/utils.d.cts +1 -1
  136. package/build/legacy/utils.d.ts +1 -1
  137. package/build/legacy/utils.js +76 -0
  138. package/build/legacy/utils.js.map +1 -1
  139. package/build/modern/environmentManager.cjs +15 -1
  140. package/build/modern/environmentManager.cjs.map +1 -1
  141. package/build/modern/environmentManager.d.cts +15 -1
  142. package/build/modern/environmentManager.d.cts.map +1 -1
  143. package/build/modern/environmentManager.d.ts +15 -1
  144. package/build/modern/environmentManager.d.ts.map +1 -1
  145. package/build/modern/environmentManager.js +15 -1
  146. package/build/modern/environmentManager.js.map +1 -1
  147. package/build/modern/focusManager.cjs +57 -0
  148. package/build/modern/focusManager.cjs.map +1 -1
  149. package/build/modern/focusManager.d.cts +57 -0
  150. package/build/modern/focusManager.d.cts.map +1 -1
  151. package/build/modern/focusManager.d.ts +57 -0
  152. package/build/modern/focusManager.d.ts.map +1 -1
  153. package/build/modern/focusManager.js +57 -0
  154. package/build/modern/focusManager.js.map +1 -1
  155. package/build/modern/{hydration-Bjs0MSgg.d.ts → hydration-Cq7QYAzB.d.ts} +1424 -7
  156. package/build/modern/hydration-Cq7QYAzB.d.ts.map +1 -0
  157. package/build/modern/{hydration-DWGr3cFC.d.cts → hydration-DwR10Hi-.d.cts} +1424 -7
  158. package/build/modern/hydration-DwR10Hi-.d.cts.map +1 -0
  159. package/build/modern/hydration.cjs +57 -4
  160. package/build/modern/hydration.cjs.map +1 -1
  161. package/build/modern/hydration.d.cts +1 -1
  162. package/build/modern/hydration.d.ts +1 -1
  163. package/build/modern/hydration.js +57 -4
  164. package/build/modern/hydration.js.map +1 -1
  165. package/build/modern/index.cjs.map +1 -1
  166. package/build/modern/index.d.cts +5 -5
  167. package/build/modern/index.d.ts +5 -5
  168. package/build/modern/index.js.map +1 -1
  169. package/build/modern/infiniteQueryBehavior.d.cts +1 -1
  170. package/build/modern/infiniteQueryBehavior.d.ts +1 -1
  171. package/build/modern/infiniteQueryObserver.cjs +67 -0
  172. package/build/modern/infiniteQueryObserver.cjs.map +1 -1
  173. package/build/modern/infiniteQueryObserver.d.cts +68 -1
  174. package/build/modern/infiniteQueryObserver.d.cts.map +1 -1
  175. package/build/modern/infiniteQueryObserver.d.ts +68 -1
  176. package/build/modern/infiniteQueryObserver.d.ts.map +1 -1
  177. package/build/modern/infiniteQueryObserver.js +67 -0
  178. package/build/modern/infiniteQueryObserver.js.map +1 -1
  179. package/build/modern/mutation.cjs +74 -0
  180. package/build/modern/mutation.cjs.map +1 -1
  181. package/build/modern/mutation.d.cts +1 -1
  182. package/build/modern/mutation.d.ts +1 -1
  183. package/build/modern/mutation.js +74 -0
  184. package/build/modern/mutation.js.map +1 -1
  185. package/build/modern/mutationCache.cjs +74 -0
  186. package/build/modern/mutationCache.cjs.map +1 -1
  187. package/build/modern/mutationCache.d.cts +1 -1
  188. package/build/modern/mutationCache.d.ts +1 -1
  189. package/build/modern/mutationCache.js +74 -0
  190. package/build/modern/mutationCache.js.map +1 -1
  191. package/build/modern/mutationObserver.cjs +71 -0
  192. package/build/modern/mutationObserver.cjs.map +1 -1
  193. package/build/modern/mutationObserver.d.cts +1 -1
  194. package/build/modern/mutationObserver.d.ts +1 -1
  195. package/build/modern/mutationObserver.js +71 -0
  196. package/build/modern/mutationObserver.js.map +1 -1
  197. package/build/modern/notifyManager.cjs +45 -1
  198. package/build/modern/notifyManager.cjs.map +1 -1
  199. package/build/modern/notifyManager.d.cts +83 -2
  200. package/build/modern/notifyManager.d.cts.map +1 -1
  201. package/build/modern/notifyManager.d.ts +83 -2
  202. package/build/modern/notifyManager.d.ts.map +1 -1
  203. package/build/modern/notifyManager.js +45 -1
  204. package/build/modern/notifyManager.js.map +1 -1
  205. package/build/modern/onlineManager.cjs +47 -0
  206. package/build/modern/onlineManager.cjs.map +1 -1
  207. package/build/modern/onlineManager.d.cts +47 -0
  208. package/build/modern/onlineManager.d.cts.map +1 -1
  209. package/build/modern/onlineManager.d.ts +47 -0
  210. package/build/modern/onlineManager.d.ts.map +1 -1
  211. package/build/modern/onlineManager.js +47 -0
  212. package/build/modern/onlineManager.js.map +1 -1
  213. package/build/modern/queriesObserver.cjs +64 -0
  214. package/build/modern/queriesObserver.cjs.map +1 -1
  215. package/build/modern/queriesObserver.d.cts +73 -1
  216. package/build/modern/queriesObserver.d.cts.map +1 -1
  217. package/build/modern/queriesObserver.d.ts +73 -1
  218. package/build/modern/queriesObserver.d.ts.map +1 -1
  219. package/build/modern/queriesObserver.js +64 -0
  220. package/build/modern/queriesObserver.js.map +1 -1
  221. package/build/modern/query.cjs +141 -0
  222. package/build/modern/query.cjs.map +1 -1
  223. package/build/modern/query.d.cts +1 -1
  224. package/build/modern/query.d.ts +1 -1
  225. package/build/modern/query.js +141 -0
  226. package/build/modern/query.js.map +1 -1
  227. package/build/modern/queryCache.cjs +120 -0
  228. package/build/modern/queryCache.cjs.map +1 -1
  229. package/build/modern/queryCache.d.cts +1 -1
  230. package/build/modern/queryCache.d.ts +1 -1
  231. package/build/modern/queryCache.js +120 -0
  232. package/build/modern/queryCache.js.map +1 -1
  233. package/build/modern/queryClient.cjs +363 -0
  234. package/build/modern/queryClient.cjs.map +1 -1
  235. package/build/modern/queryClient.d.cts +1 -1
  236. package/build/modern/queryClient.d.ts +1 -1
  237. package/build/modern/queryClient.js +363 -0
  238. package/build/modern/queryClient.js.map +1 -1
  239. package/build/modern/queryObserver.cjs +116 -2
  240. package/build/modern/queryObserver.cjs.map +1 -1
  241. package/build/modern/queryObserver.d.cts +1 -1
  242. package/build/modern/queryObserver.d.ts +1 -1
  243. package/build/modern/queryObserver.js +116 -2
  244. package/build/modern/queryObserver.js.map +1 -1
  245. package/build/modern/retryer.cjs +18 -0
  246. package/build/modern/retryer.cjs.map +1 -1
  247. package/build/modern/retryer.d.cts +1 -1
  248. package/build/modern/retryer.d.ts +1 -1
  249. package/build/modern/retryer.js +18 -0
  250. package/build/modern/retryer.js.map +1 -1
  251. package/build/modern/streamedQuery.cjs +10 -1
  252. package/build/modern/streamedQuery.cjs.map +1 -1
  253. package/build/modern/streamedQuery.d.cts +26 -2
  254. package/build/modern/streamedQuery.d.cts.map +1 -1
  255. package/build/modern/streamedQuery.d.ts +26 -2
  256. package/build/modern/streamedQuery.d.ts.map +1 -1
  257. package/build/modern/streamedQuery.js +10 -1
  258. package/build/modern/streamedQuery.js.map +1 -1
  259. package/build/modern/timeoutManager.cjs +99 -0
  260. package/build/modern/timeoutManager.cjs.map +1 -1
  261. package/build/modern/timeoutManager.d.cts +105 -0
  262. package/build/modern/timeoutManager.d.cts.map +1 -1
  263. package/build/modern/timeoutManager.d.ts +105 -0
  264. package/build/modern/timeoutManager.d.ts.map +1 -1
  265. package/build/modern/timeoutManager.js +99 -0
  266. package/build/modern/timeoutManager.js.map +1 -1
  267. package/build/modern/types.cjs.map +1 -1
  268. package/build/modern/types.d.cts +1 -1
  269. package/build/modern/types.d.ts +1 -1
  270. package/build/modern/types.js.map +1 -1
  271. package/build/modern/utils.cjs +76 -0
  272. package/build/modern/utils.cjs.map +1 -1
  273. package/build/modern/utils.d.cts +1 -1
  274. package/build/modern/utils.d.ts +1 -1
  275. package/build/modern/utils.js +76 -0
  276. package/build/modern/utils.js.map +1 -1
  277. package/package.json +9 -9
  278. package/src/environmentManager.ts +15 -1
  279. package/src/focusManager.ts +57 -0
  280. package/src/hydration.ts +82 -16
  281. package/src/index.ts +3 -0
  282. package/src/infiniteQueryObserver.ts +67 -0
  283. package/src/mutation.ts +108 -0
  284. package/src/mutationCache.ts +91 -0
  285. package/src/mutationObserver.ts +71 -0
  286. package/src/notifyManager.ts +46 -1
  287. package/src/onlineManager.ts +47 -0
  288. package/src/queriesObserver.ts +72 -0
  289. package/src/query.ts +193 -0
  290. package/src/queryCache.ts +134 -0
  291. package/src/queryClient.ts +369 -0
  292. package/src/queryObserver.ts +117 -4
  293. package/src/retryer.ts +18 -0
  294. package/src/streamedQuery.ts +25 -1
  295. package/src/timeoutManager.ts +105 -0
  296. package/src/types.ts +147 -5
  297. package/src/utils.ts +107 -0
  298. package/build/legacy/hydration-Bjs0MSgg.d.ts.map +0 -1
  299. package/build/legacy/hydration-DWGr3cFC.d.cts.map +0 -1
  300. package/build/modern/hydration-Bjs0MSgg.d.ts.map +0 -1
  301. package/build/modern/hydration-DWGr3cFC.d.cts.map +0 -1
@@ -14,6 +14,24 @@ var _mutationDefaults = /* @__PURE__ */ new WeakMap();
14
14
  var _mountCount = /* @__PURE__ */ new WeakMap();
15
15
  var _unsubscribeFocus = /* @__PURE__ */ new WeakMap();
16
16
  var _unsubscribeOnline = /* @__PURE__ */ new WeakMap();
17
+ /**
18
+ * `QueryClient` is used to interact with a cache of queries and mutations. It owns a
19
+ * `QueryCache` and a `MutationCache` (creating default ones if none are passed in) and holds
20
+ * the default options that are applied to queries and mutations created through it.
21
+ *
22
+ * @example
23
+ * ```ts
24
+ * const queryClient = new QueryClient({
25
+ * defaultOptions: {
26
+ * queries: {
27
+ * staleTime: Infinity,
28
+ * },
29
+ * },
30
+ * })
31
+ *
32
+ * await queryClient.query({ queryKey: ['posts'], queryFn: fetchPosts })
33
+ * ```
34
+ */
17
35
  var QueryClient = class {
18
36
  constructor(config = {}) {
19
37
  _classPrivateFieldInitSpec(this, _queryCache, void 0);
@@ -31,6 +49,12 @@ var QueryClient = class {
31
49
  _classPrivateFieldSet2(_mutationDefaults, this, /* @__PURE__ */ new Map());
32
50
  _classPrivateFieldSet2(_mountCount, this, 0);
33
51
  }
52
+ /**
53
+ * Called by a framework adapter's `QueryClientProvider`-equivalent when it mounts, to start
54
+ * listening for focus/online events and resume paused mutations. Ref-counted via an internal
55
+ * mount count, so nested or multiple providers sharing the same `QueryClient` don't tear down
56
+ * the shared listeners until the last one unmounts.
57
+ */
34
58
  mount() {
35
59
  var _this$mountCount;
36
60
  _classPrivateFieldSet2(_mountCount, this, (_this$mountCount = _classPrivateFieldGet2(_mountCount, this), _this$mountCount++, _this$mountCount));
@@ -48,6 +72,11 @@ var QueryClient = class {
48
72
  }
49
73
  }));
50
74
  }
75
+ /**
76
+ * The inverse of {@link QueryClient#mount} — called by a framework adapter's
77
+ * `QueryClientProvider`-equivalent when it unmounts. Only tears down the focus/online
78
+ * listeners once the mount count returns to `0`.
79
+ */
51
80
  unmount() {
52
81
  var _this$mountCount3, _classPrivateFieldGet2$1, _classPrivateFieldGet3;
53
82
  _classPrivateFieldSet2(_mountCount, this, (_this$mountCount3 = _classPrivateFieldGet2(_mountCount, this), _this$mountCount3--, _this$mountCount3));
@@ -57,12 +86,35 @@ var QueryClient = class {
57
86
  (_classPrivateFieldGet3 = _classPrivateFieldGet2(_unsubscribeOnline, this)) === null || _classPrivateFieldGet3 === void 0 || _classPrivateFieldGet3.call(this);
58
87
  _classPrivateFieldSet2(_unsubscribeOnline, this, void 0);
59
88
  }
89
+ /**
90
+ * Returns the number of queries in the cache that are currently fetching, optionally
91
+ * matching a set of filters. This includes background-fetching, loading new pages, and
92
+ * loading more infinite query results.
93
+ *
94
+ * @example
95
+ * ```ts
96
+ * if (queryClient.isFetching()) {
97
+ * console.log('At least one query is fetching!')
98
+ * }
99
+ * ```
100
+ */
60
101
  isFetching(filters) {
61
102
  return _classPrivateFieldGet2(_queryCache, this).findAll({
62
103
  ...filters,
63
104
  fetchStatus: "fetching"
64
105
  }).length;
65
106
  }
107
+ /**
108
+ * Returns the number of mutations in the cache that are currently pending, optionally
109
+ * matching a set of filters.
110
+ *
111
+ * @example
112
+ * ```ts
113
+ * if (queryClient.isMutating()) {
114
+ * console.log('At least one mutation is pending!')
115
+ * }
116
+ * ```
117
+ */
66
118
  isMutating(filters) {
67
119
  return _classPrivateFieldGet2(_mutationCache, this).findAll({
68
120
  ...filters,
@@ -75,6 +127,8 @@ var QueryClient = class {
75
127
  *
76
128
  * Hint: Do not use this function inside a component, because it won't receive updates.
77
129
  * Use `useQuery` to create a `QueryObserver` that subscribes to changes.
130
+ *
131
+ * @see {@link QueryClient#getQueriesData}
78
132
  */
79
133
  getQueryData(queryKey) {
80
134
  var _classPrivateFieldGet4;
@@ -92,11 +146,49 @@ var QueryClient = class {
92
146
  if (options.revalidateIfStale && query.isStaleByTime(resolveQueryValue(defaultedOptions.staleTime, query))) this.prefetchQuery(defaultedOptions);
93
147
  return Promise.resolve(cachedData);
94
148
  }
149
+ /**
150
+ * Imperative (non-reactive) way to retrieve the cached data of multiple queries at once.
151
+ * Only queries matching the given filters are returned; if none match, an empty array is
152
+ * returned.
153
+ *
154
+ * Because the matched queries can hold data of different shapes (e.g. a broad filter can match
155
+ * queries with unrelated data types), the `TQueryFnData` generic defaults to `unknown` rather
156
+ * than being inferred. Passing a more specific type is a convenience for call sites that know
157
+ * every matched query holds the same shape — it is not checked against the actual cache
158
+ * contents.
159
+ *
160
+ * @see {@link QueryClient#getQueryData}
161
+ * @example
162
+ * ```ts
163
+ * const data = queryClient.getQueriesData({ queryKey: ['posts'] })
164
+ * ```
165
+ */
95
166
  getQueriesData(filters) {
96
167
  return _classPrivateFieldGet2(_queryCache, this).findAll(filters).map(({ queryKey, state }) => {
97
168
  return [queryKey, state.data];
98
169
  });
99
170
  }
171
+ /**
172
+ * Synchronous way to immediately update a query's cached data. If the updater (or the value
173
+ * passed) resolves to `undefined`, the cache is left untouched and no query is created;
174
+ * otherwise, if the query does not exist yet, it will be created. To update multiple queries
175
+ * at once by partially matching query keys, use {@link QueryClient#setQueriesData} instead.
176
+ *
177
+ * Updates must be performed immutably: do not mutate `oldData`, or data previously retrieved
178
+ * via {@link QueryClient#getQueryData}, in place.
179
+ *
180
+ * @param queryKey - The query key to set data for.
181
+ * @param updater - Either the new data, or a function that receives the current data (which
182
+ * may be `undefined`) and returns the new data.
183
+ *
184
+ * @example
185
+ * ```ts
186
+ * queryClient.setQueryData(['posts'], newPosts)
187
+ *
188
+ * // Or, using an updater function that receives the current data:
189
+ * queryClient.setQueryData(['posts'], (oldPosts) => [...oldPosts, newPost])
190
+ * ```
191
+ */
100
192
  setQueryData(queryKey, updater, options) {
101
193
  const defaultedOptions = this.defaultQueryOptions({ queryKey });
102
194
  const query = _classPrivateFieldGet2(_queryCache, this).get(defaultedOptions.queryHash);
@@ -108,14 +200,48 @@ var QueryClient = class {
108
200
  manual: true
109
201
  });
110
202
  }
203
+ /**
204
+ * Synchronous way to immediately update the cached data of multiple queries at once, using
205
+ * filters or partial query key matching. Only queries that already exist and match the given
206
+ * filters are updated; no new cache entries are created. Internally this calls
207
+ * {@link QueryClient#setQueryData} for each matching query.
208
+ *
209
+ * @example
210
+ * ```ts
211
+ * queryClient.setQueriesData({ queryKey: ['posts'] }, (oldPosts) =>
212
+ * oldPosts ? oldPosts.filter((post) => post.id !== deletedId) : oldPosts,
213
+ * )
214
+ * ```
215
+ */
111
216
  setQueriesData(filters, updater, options) {
112
217
  return notifyManager.batch(() => _classPrivateFieldGet2(_queryCache, this).findAll(filters).map(({ queryKey }) => [queryKey, this.setQueryData(queryKey, updater, options)]));
113
218
  }
219
+ /**
220
+ * Imperative (non-reactive) way to retrieve an existing query's state. If the query does not
221
+ * exist, `undefined` is returned.
222
+ *
223
+ * @example
224
+ * ```ts
225
+ * const state = queryClient.getQueryState(['posts'])
226
+ * console.log(state?.dataUpdatedAt)
227
+ * ```
228
+ */
114
229
  getQueryState(queryKey) {
115
230
  var _classPrivateFieldGet5;
116
231
  const options = this.defaultQueryOptions({ queryKey });
117
232
  return (_classPrivateFieldGet5 = _classPrivateFieldGet2(_queryCache, this).get(options.queryHash)) === null || _classPrivateFieldGet5 === void 0 ? void 0 : _classPrivateFieldGet5.state;
118
233
  }
234
+ /**
235
+ * Removes queries from the cache that match the given filters. Unlike
236
+ * {@link QueryClient#invalidateQueries} or {@link QueryClient#refetchQueries}, this removes
237
+ * matching queries from the cache instead of refetching them. Without filters, every query in
238
+ * the cache is removed.
239
+ *
240
+ * @example
241
+ * ```ts
242
+ * queryClient.removeQueries({ queryKey: ['posts'], exact: true })
243
+ * ```
244
+ */
119
245
  removeQueries(filters) {
120
246
  const queryCache = _classPrivateFieldGet2(_queryCache, this);
121
247
  notifyManager.batch(() => {
@@ -124,6 +250,16 @@ var QueryClient = class {
124
250
  });
125
251
  });
126
252
  }
253
+ /**
254
+ * Resets queries matching the given filters back to their initial state (e.g. any
255
+ * `initialData`), notifying subscribers rather than removing them. Active queries among the
256
+ * matched set are then refetched, and the returned promise resolves once that refetch settles.
257
+ *
258
+ * @example
259
+ * ```ts
260
+ * await queryClient.resetQueries({ queryKey: ['posts'], exact: true })
261
+ * ```
262
+ */
127
263
  resetQueries(filters, options) {
128
264
  const queryCache = _classPrivateFieldGet2(_queryCache, this);
129
265
  return notifyManager.batch(() => {
@@ -138,6 +274,19 @@ var QueryClient = class {
138
274
  }, options);
139
275
  });
140
276
  }
277
+ /**
278
+ * Cancels outgoing fetches for queries matching the given filters. Most useful when performing
279
+ * optimistic updates, since any outgoing refetch that resolves afterwards would otherwise
280
+ * overwrite the optimistic update. By default (`revert: true`), a cancelled query's data is
281
+ * reverted to its state before the outgoing fetch started.
282
+ *
283
+ * The returned promise never rejects, even if individual cancellations fail.
284
+ *
285
+ * @example
286
+ * ```ts
287
+ * await queryClient.cancelQueries({ queryKey: ['posts'], exact: true })
288
+ * ```
289
+ */
141
290
  cancelQueries(filters, cancelOptions = {}) {
142
291
  const defaultedCancelOptions = {
143
292
  revert: true,
@@ -146,6 +295,19 @@ var QueryClient = class {
146
295
  const promises = notifyManager.batch(() => _classPrivateFieldGet2(_queryCache, this).findAll(filters).map((query) => query.cancel(defaultedCancelOptions)));
147
296
  return Promise.all(promises).then(noop).catch(noop);
148
297
  }
298
+ /**
299
+ * Marks queries matching the given filters as invalidated. Unlike
300
+ * {@link QueryClient#removeQueries}, invalidated queries stay in the cache.
301
+ *
302
+ * Unless `filters.refetchType` is `'none'`, matching queries are then refetched via
303
+ * {@link QueryClient#refetchQueries}, using `filters.refetchType` if set, otherwise
304
+ * `filters.type`, otherwise `'active'`.
305
+ *
306
+ * @example
307
+ * ```ts
308
+ * await queryClient.invalidateQueries({ queryKey: ['posts'], refetchType: 'active' })
309
+ * ```
310
+ */
149
311
  invalidateQueries(filters, options = {}) {
150
312
  return notifyManager.batch(() => {
151
313
  _classPrivateFieldGet2(_queryCache, this).findAll(filters).forEach((query) => {
@@ -158,6 +320,21 @@ var QueryClient = class {
158
320
  }, options);
159
321
  });
160
322
  }
323
+ /**
324
+ * Refetches queries matching the given filters, regardless of whether they are stale. Without
325
+ * filters, every query in the cache is refetched. Queries that are disabled, or static (only
326
+ * have observers with a static `staleTime`), are never refetched.
327
+ *
328
+ * By default (`cancelRefetch: true`), a currently running fetch is cancelled before the new
329
+ * one starts. The returned promise resolves once all matching queries have settled; it does
330
+ * not reject on individual query failures unless `throwOnError` is set.
331
+ *
332
+ * @example
333
+ * ```ts
334
+ * // refetch all active queries partially matching a query key:
335
+ * await queryClient.refetchQueries({ queryKey: ['posts'], type: 'active' })
336
+ * ```
337
+ */
161
338
  refetchQueries(filters, options = {}) {
162
339
  const fetchOptions = {
163
340
  ...options,
@@ -170,6 +347,37 @@ var QueryClient = class {
170
347
  }));
171
348
  return Promise.all(promises).then(noop);
172
349
  }
350
+ /**
351
+ * Asynchronous method to fetch and cache a query, resolving with the data or throwing with
352
+ * the error.
353
+ *
354
+ * If the query already exists in the cache and its data is not stale (per the given
355
+ * `staleTime`), the cached data is returned without fetching. Otherwise, the query is fetched
356
+ * and the promise resolves once the fetch settles. If a `select` function is provided, it is
357
+ * applied to the data in both cases (cached or freshly fetched) before it is returned.
358
+ *
359
+ * Unlike a reactive observer, retries are disabled by default here (`retry: false`) unless
360
+ * explicitly configured, since there is no component to catch a thrown error and retry through
361
+ * re-render.
362
+ *
363
+ * The accepted options are `QueryObserverOptions` minus the fields that only make sense for a
364
+ * reactive observer — `enabled`, `refetchInterval`, `refetchIntervalInBackground`,
365
+ * `refetchOnWindowFocus`, `refetchOnReconnect`, `refetchOnMount`, `retryOnMount`,
366
+ * `notifyOnChangeProps`, `throwOnError`, `suspense`, and `placeholderData` are not part of this
367
+ * method's options.
368
+ *
369
+ * This method replaces the deprecated `fetchQuery`, and — combined with
370
+ * `{ staleTime: 'static' }` — the deprecated `ensureQueryData`.
371
+ *
372
+ * @example
373
+ * ```ts
374
+ * try {
375
+ * const data = await queryClient.query({ queryKey, queryFn, staleTime: 10000 })
376
+ * } catch (error) {
377
+ * console.log(error)
378
+ * }
379
+ * ```
380
+ */
173
381
  async query(options) {
174
382
  const defaultedOptions = this.defaultQueryOptions(options);
175
383
  if (defaultedOptions.retry === void 0) defaultedOptions.retry = false;
@@ -194,6 +402,27 @@ var QueryClient = class {
194
402
  prefetchQuery(options) {
195
403
  return this.fetchQuery(options).then(noop).catch(noop);
196
404
  }
405
+ /**
406
+ * Asynchronous method to fetch and cache an infinite query, resolving with an
407
+ * {@link InfiniteData} object or throwing with the error.
408
+ *
409
+ * Behaves like {@link QueryClient#query}, accepting the same options (minus
410
+ * `initialPageParam`), plus the required `initialPageParam`, and an optional `pages` /
411
+ * `getNextPageParam` pair used to refetch a fixed number of pages from the start.
412
+ *
413
+ * This method replaces the deprecated `fetchInfiniteQuery`, and — combined with
414
+ * `{ staleTime: 'static' }` — the deprecated `ensureInfiniteQueryData`.
415
+ *
416
+ * @example
417
+ * ```ts
418
+ * try {
419
+ * const data = await queryClient.infiniteQuery({ queryKey, queryFn, initialPageParam: 0 })
420
+ * console.log(data.pages)
421
+ * } catch (error) {
422
+ * console.log(error)
423
+ * }
424
+ * ```
425
+ */
197
426
  infiniteQuery(options) {
198
427
  options._type = "infinite";
199
428
  return this.query(options);
@@ -218,28 +447,118 @@ var QueryClient = class {
218
447
  options._type = "infinite";
219
448
  return this.ensureQueryData(options);
220
449
  }
450
+ /**
451
+ * Resumes mutations that were paused because there was no network connection. Does nothing
452
+ * (resolving immediately) if the client is currently offline.
453
+ *
454
+ * @example
455
+ * ```ts
456
+ * import { QueryClient } from '@tanstack/query-core'
457
+ *
458
+ * const queryClient = new QueryClient()
459
+ * await queryClient.resumePausedMutations()
460
+ * ```
461
+ */
221
462
  resumePausedMutations() {
222
463
  if (onlineManager.isOnline()) return _classPrivateFieldGet2(_mutationCache, this).resumePausedMutations();
223
464
  return Promise.resolve();
224
465
  }
466
+ /**
467
+ * Returns the query cache this client is connected to.
468
+ *
469
+ * @example
470
+ * ```ts
471
+ * import { QueryClient } from '@tanstack/query-core'
472
+ *
473
+ * const queryClient = new QueryClient()
474
+ * const queryCache = queryClient.getQueryCache()
475
+ * const queries = queryCache.findAll({ queryKey: ['posts'] })
476
+ * ```
477
+ */
225
478
  getQueryCache() {
226
479
  return _classPrivateFieldGet2(_queryCache, this);
227
480
  }
481
+ /**
482
+ * Returns the mutation cache this client is connected to.
483
+ *
484
+ * @example
485
+ * ```ts
486
+ * import { QueryClient } from '@tanstack/query-core'
487
+ *
488
+ * const queryClient = new QueryClient()
489
+ * const mutationCache = queryClient.getMutationCache()
490
+ * const mutations = mutationCache.findAll({ status: 'pending' })
491
+ * ```
492
+ */
228
493
  getMutationCache() {
229
494
  return _classPrivateFieldGet2(_mutationCache, this);
230
495
  }
496
+ /**
497
+ * Returns the default options that were set when creating the client, or via
498
+ * {@link QueryClient#setDefaultOptions}.
499
+ *
500
+ * @example
501
+ * ```ts
502
+ * import { QueryClient } from '@tanstack/query-core'
503
+ *
504
+ * const queryClient = new QueryClient()
505
+ * const defaultOptions = queryClient.getDefaultOptions()
506
+ * ```
507
+ */
231
508
  getDefaultOptions() {
232
509
  return _classPrivateFieldGet2(_defaultOptions, this);
233
510
  }
511
+ /**
512
+ * Dynamically sets the default options for this client, overwriting any previously defined
513
+ * default options.
514
+ *
515
+ * @see {@link QueryClient#getDefaultOptions}
516
+ * @example
517
+ * ```ts
518
+ * import { QueryClient } from '@tanstack/query-core'
519
+ *
520
+ * const queryClient = new QueryClient()
521
+ * queryClient.setDefaultOptions({
522
+ * queries: {
523
+ * staleTime: Infinity,
524
+ * },
525
+ * })
526
+ * ```
527
+ */
234
528
  setDefaultOptions(options) {
235
529
  _classPrivateFieldSet2(_defaultOptions, this, options);
236
530
  }
531
+ /**
532
+ * Sets default options for queries whose query key partially matches the given `queryKey`.
533
+ *
534
+ * If several registered query defaults match a given query key, they are merged together in
535
+ * registration order by {@link QueryClient#getQueryDefaults}, so register defaults from the
536
+ * most generic key to the least generic one — more specific defaults should be registered
537
+ * after more generic ones so they take precedence.
538
+ *
539
+ * @example
540
+ * ```ts
541
+ * queryClient.setQueryDefaults(['posts'], { queryFn: fetchPosts })
542
+ *
543
+ * await queryClient.query({ queryKey: ['posts'] })
544
+ * ```
545
+ */
237
546
  setQueryDefaults(queryKey, options) {
238
547
  _classPrivateFieldGet2(_queryDefaults, this).set(hashKey(queryKey), {
239
548
  queryKey,
240
549
  defaultOptions: options
241
550
  });
242
551
  }
552
+ /**
553
+ * Returns the default options registered for queries whose query key partially matches the
554
+ * given `queryKey`, via {@link QueryClient#setQueryDefaults}. If multiple registered defaults
555
+ * match, they are merged together in registration order.
556
+ *
557
+ * @example
558
+ * ```ts
559
+ * const defaultOptions = queryClient.getQueryDefaults(['posts'])
560
+ * ```
561
+ */
243
562
  getQueryDefaults(queryKey) {
244
563
  const defaults = [..._classPrivateFieldGet2(_queryDefaults, this).values()];
245
564
  const result = {};
@@ -248,12 +567,33 @@ var QueryClient = class {
248
567
  });
249
568
  return result;
250
569
  }
570
+ /**
571
+ * Sets default options for mutations whose mutation key partially matches the given
572
+ * `mutationKey`. As with {@link QueryClient#setQueryDefaults}, the order of registration
573
+ * matters when several registered defaults match the same mutation key.
574
+ *
575
+ * @see {@link QueryClient#getMutationDefaults}
576
+ * @example
577
+ * ```ts
578
+ * queryClient.setMutationDefaults(['addPost'], { mutationFn: addPost })
579
+ * ```
580
+ */
251
581
  setMutationDefaults(mutationKey, options) {
252
582
  _classPrivateFieldGet2(_mutationDefaults, this).set(hashKey(mutationKey), {
253
583
  mutationKey,
254
584
  defaultOptions: options
255
585
  });
256
586
  }
587
+ /**
588
+ * Returns the default options registered for mutations whose mutation key partially matches
589
+ * the given `mutationKey`, via {@link QueryClient#setMutationDefaults}. If multiple registered
590
+ * defaults match, they are merged together in registration order.
591
+ *
592
+ * @example
593
+ * ```ts
594
+ * const defaultOptions = queryClient.getMutationDefaults(['addPost'])
595
+ * ```
596
+ */
257
597
  getMutationDefaults(mutationKey) {
258
598
  const defaults = [..._classPrivateFieldGet2(_mutationDefaults, this).values()];
259
599
  const result = {};
@@ -262,6 +602,12 @@ var QueryClient = class {
262
602
  });
263
603
  return result;
264
604
  }
605
+ /**
606
+ * Called by framework adapters (e.g. inside `useQuery`) to resolve the options passed by the
607
+ * caller into their final, defaulted form: merging `queryClient.setQueryDefaults` for the
608
+ * given `queryKey`, then the client's own `defaultOptions.queries`, then the caller's options
609
+ * on top. A no-op if the options are already defaulted (`_defaulted: true`).
610
+ */
265
611
  defaultQueryOptions(options) {
266
612
  if (options._defaulted) return options;
267
613
  const defaultedOptions = {
@@ -277,6 +623,12 @@ var QueryClient = class {
277
623
  if (defaultedOptions.queryFn === skipToken) defaultedOptions.enabled = false;
278
624
  return defaultedOptions;
279
625
  }
626
+ /**
627
+ * The mutation counterpart of {@link QueryClient#defaultQueryOptions}. Called by framework
628
+ * adapters (e.g. inside `useMutation`) to merge `queryClient.setMutationDefaults` for the
629
+ * given `mutationKey`, then the client's `defaultOptions.mutations`, then the caller's options
630
+ * on top. A no-op if the options are already defaulted (`_defaulted: true`).
631
+ */
280
632
  defaultMutationOptions(options) {
281
633
  if (options === null || options === void 0 ? void 0 : options._defaulted) return options;
282
634
  return {
@@ -286,6 +638,17 @@ var QueryClient = class {
286
638
  _defaulted: true
287
639
  };
288
640
  }
641
+ /**
642
+ * Clears both the query cache and the mutation cache this client is connected to.
643
+ *
644
+ * @example
645
+ * ```ts
646
+ * import { QueryClient } from '@tanstack/query-core'
647
+ *
648
+ * const queryClient = new QueryClient()
649
+ * queryClient.clear()
650
+ * ```
651
+ */
289
652
  clear() {
290
653
  _classPrivateFieldGet2(_queryCache, this).clear();
291
654
  _classPrivateFieldGet2(_mutationCache, this).clear();