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