@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
@@ -5,6 +5,26 @@ type QueryObserverListener<TData, TError> = (result: QueryObserverResult<TData,
5
5
  interface ObserverFetchOptions extends FetchOptions {
6
6
  throwOnError?: boolean;
7
7
  }
8
+ /**
9
+ * A `QueryObserver` watches a single query in the `QueryCache` and computes a
10
+ * `QueryObserverResult` from its state, recomputing and notifying subscribers
11
+ * whenever the underlying query (or the observer's options) changes. It is
12
+ * the primitive that framework adapters (e.g. `useQuery`) build their hooks
13
+ * on top of, but it can also be used directly to observe and switch between
14
+ * queries outside of any framework.
15
+ *
16
+ * @example
17
+ * ```ts
18
+ * const observer = new QueryObserver(queryClient, {
19
+ * queryKey: ['posts'],
20
+ * queryFn: fetchPosts,
21
+ * })
22
+ *
23
+ * const unsubscribe = observer.subscribe((result) => {
24
+ * console.log(result.data)
25
+ * })
26
+ * ```
27
+ */
8
28
  declare class QueryObserver<TQueryFnData = unknown, TError = DefaultError, TData = TQueryFnData, TQueryData = TQueryFnData, TQueryKey extends QueryKey = QueryKey> extends Subscribable<QueryObserverListener<TData, TError>> {
9
29
  #private;
10
30
  options: QueryObserverOptions<TQueryFnData, TError, TData, TQueryData, TQueryKey>;
@@ -12,20 +32,114 @@ declare class QueryObserver<TQueryFnData = unknown, TError = DefaultError, TData
12
32
  protected bindMethods(): void;
13
33
  protected onSubscribe(): void;
14
34
  protected onUnsubscribe(): void;
35
+ /**
36
+ * Returns whether the observed query is currently stale and configured
37
+ * (via the `refetchOnReconnect` option) to refetch when the network
38
+ * reconnects.
39
+ */
15
40
  shouldFetchOnReconnect(): boolean;
41
+ /**
42
+ * Returns whether the observed query is currently stale and configured
43
+ * (via the `refetchOnWindowFocus` option) to refetch when the window
44
+ * regains focus.
45
+ */
16
46
  shouldFetchOnWindowFocus(): boolean;
47
+ /**
48
+ * Stops observing the current query: clears all listeners, cancels the
49
+ * stale and refetch-interval timers, and removes this observer from the
50
+ * query it was observing.
51
+ */
17
52
  destroy(): void;
53
+ /**
54
+ * Updates the observer's options. This will re-resolve the query being
55
+ * observed (switching to a different query if the `queryKey` changed),
56
+ * trigger a fetch if the new options require one and the observer has
57
+ * subscribers, recompute the current result, and reschedule the stale and
58
+ * refetch-interval timers as needed.
59
+ *
60
+ * @example
61
+ * ```ts
62
+ * observer.setOptions({ queryKey: ['posts', 1], queryFn: () => fetchPost(1) })
63
+ * // later: switch to a different query, reusing the same observer
64
+ * observer.setOptions({ queryKey: ['posts', 2], queryFn: () => fetchPost(2) })
65
+ * ```
66
+ */
18
67
  setOptions(options: QueryObserverOptions<TQueryFnData, TError, TData, TQueryData, TQueryKey>): void;
68
+ /**
69
+ * Computes the result the observer would produce for the given (already-defaulted) options
70
+ * right now, building the underlying `Query` if it doesn't exist yet, without waiting for a
71
+ * subscription callback. Called by framework adapters on every render (e.g. `useQuery`) so the
72
+ * returned value is available synchronously, ahead of `setOptions` triggering an actual fetch.
73
+ */
19
74
  getOptimisticResult(options: DefaultedQueryObserverOptions<TQueryFnData, TError, TData, TQueryData, TQueryKey>): QueryObserverResult<TData, TError>;
75
+ /**
76
+ * Returns the most recently computed `QueryObserverResult` for the
77
+ * observed query. This is a point-in-time read; to be notified of updates
78
+ * as they happen, subscribe to the observer instead (its inherited
79
+ * `subscribe` method).
80
+ *
81
+ * @example
82
+ * ```ts
83
+ * const result = observer.getCurrentResult()
84
+ * console.log(result.status, result.data)
85
+ * ```
86
+ */
20
87
  getCurrentResult(): QueryObserverResult<TData, TError>;
88
+ /**
89
+ * Wraps a `QueryObserverResult` in a `Proxy` that records which properties are read, via
90
+ * {@link QueryObserver#trackProp} (and an optional `onPropTracked` callback). Used by framework
91
+ * adapters when `notifyOnChangeProps` is not set, to implement its default "only re-render on
92
+ * properties you actually read" behavior.
93
+ */
21
94
  trackResult(result: QueryObserverResult<TData, TError>, onPropTracked?: (key: keyof QueryObserverResult) => void): QueryObserverResult<TData, TError>;
95
+ /**
96
+ * Records that the given `QueryObserverResult` property was read, so a subsequent update only
97
+ * notifies this observer if a tracked property actually changed. Normally called indirectly via
98
+ * {@link QueryObserver#trackResult}'s proxy; exposed directly for adapters that track property
99
+ * access themselves (e.g. through their own reactivity system) instead of via the proxy.
100
+ */
22
101
  trackProp(key: keyof QueryObserverResult): void;
102
+ /**
103
+ * Returns the `Query` instance this observer is currently observing.
104
+ */
23
105
  getCurrentQuery(): Query<TQueryFnData, TError, TQueryData, TQueryKey>;
106
+ /**
107
+ * Refetches the observed query and returns a promise that resolves with
108
+ * the resulting `QueryObserverResult`.
109
+ *
110
+ * @example
111
+ * ```ts
112
+ * const result = await observer.refetch({ cancelRefetch: false })
113
+ * console.log(result.data)
114
+ * ```
115
+ */
24
116
  refetch({ ...options }?: RefetchOptions): Promise<QueryObserverResult<TData, TError>>;
117
+ /**
118
+ * Fetches a query defined by the given options without affecting this
119
+ * observer's own tracked query or result, and returns a promise that
120
+ * resolves with the `QueryObserverResult` for that fetch. This is useful
121
+ * for prefetching data that another observer (e.g. a query about to be
122
+ * navigated to) will need, ahead of time.
123
+ *
124
+ * @example
125
+ * ```ts
126
+ * const result = await observer.fetchOptimistic({
127
+ * queryKey: ['posts', 2],
128
+ * queryFn: () => fetchPost(2),
129
+ * })
130
+ * console.log(result.data)
131
+ * ```
132
+ */
25
133
  fetchOptimistic(options: QueryObserverOptions<TQueryFnData, TError, TData, TQueryData, TQueryKey>): Promise<QueryObserverResult<TData, TError>>;
26
134
  protected fetch(fetchOptions: ObserverFetchOptions): Promise<QueryObserverResult<TData, TError>>;
27
135
  protected createResult(query: Query<TQueryFnData, TError, TQueryData, TQueryKey>, options: QueryObserverOptions<TQueryFnData, TError, TData, TQueryData, TQueryKey>): QueryObserverResult<TData, TError>;
136
+ /**
137
+ * Recomputes and stores the current result from the current query/options, notifying listeners
138
+ * if it changed. Framework adapters call this right after subscribing to make sure no query
139
+ * update was missed in the gap between creating the observer and subscribing to it.
140
+ */
28
141
  updateResult(): void;
142
+ /** @internal */
29
143
  onQueryUpdate(): void;
30
144
  }
31
145
  //#endregion
@@ -38,18 +152,70 @@ interface QueryConfig<TQueryFnData, TError, TData, TQueryKey extends QueryKey =
38
152
  defaultOptions?: QueryOptions<TQueryFnData, TError, TData, TQueryKey>;
39
153
  state?: QueryState<TData, TError>;
40
154
  }
155
+ /**
156
+ * The raw state stored on a `Query` instance. This is the underlying state
157
+ * that observer results (e.g. `QueryObserverResult`) are derived from.
158
+ */
41
159
  interface QueryState<TData = unknown, TError = DefaultError> {
160
+ /**
161
+ * The last successfully resolved data for the query.
162
+ */
42
163
  data: TData | undefined;
164
+ /**
165
+ * The number of times the query has successfully resolved.
166
+ */
43
167
  dataUpdateCount: number;
168
+ /**
169
+ * The timestamp for when the query most recently returned the `status` as `"success"`.
170
+ */
44
171
  dataUpdatedAt: number;
172
+ /**
173
+ * The error object for the query, if the last attempt resulted in an error.
174
+ * - Defaults to `null`.
175
+ */
45
176
  error: TError | null;
177
+ /**
178
+ * The sum of all errors, incremented every time the query resolves with an error.
179
+ */
46
180
  errorUpdateCount: number;
181
+ /**
182
+ * The timestamp for when the query most recently returned the `status` as `"error"`.
183
+ */
47
184
  errorUpdatedAt: number;
185
+ /**
186
+ * The failure count for the current fetch.
187
+ * - Incremented every time the fetch fails.
188
+ * - Reset to `0` when the fetch succeeds.
189
+ */
48
190
  fetchFailureCount: number;
191
+ /**
192
+ * The reason the current fetch failed, as reported by the retryer.
193
+ * - Reset to `null` when the fetch succeeds.
194
+ */
49
195
  fetchFailureReason: TError | null;
196
+ /**
197
+ * Metadata passed to the currently in-flight (or most recent) fetch, e.g. the
198
+ * `fetchMore` direction for infinite queries.
199
+ */
50
200
  fetchMeta: FetchMeta | null;
201
+ /**
202
+ * Whether the query has been marked as invalidated via `invalidate()`.
203
+ * - Reset to `false` whenever the query resolves successfully.
204
+ */
51
205
  isInvalidated: boolean;
206
+ /**
207
+ * The status of the query.
208
+ * - `pending` if there's no cached data and no attempt was finished yet.
209
+ * - `error` if the last attempt resulted in an error.
210
+ * - `success` if the query has data.
211
+ */
52
212
  status: QueryStatus;
213
+ /**
214
+ * The fetch status of the query.
215
+ * - `fetching`: the `queryFn` is currently executing.
216
+ * - `paused`: a fetch wanted to run but has been paused (see network mode).
217
+ * - `idle`: the query is not fetching.
218
+ */
53
219
  fetchStatus: FetchStatus;
54
220
  }
55
221
  interface FetchContext<TQueryFnData, TError, TData, TQueryKey extends QueryKey = QueryKey> {
@@ -108,6 +274,25 @@ interface SetStateAction<TData, TError> {
108
274
  state: Partial<QueryState<TData, TError>>;
109
275
  }
110
276
  type Action$1<TData, TError> = ContinueAction$1 | ErrorAction$1<TError> | FailedAction$1<TError> | FetchAction | InvalidateAction | PauseAction$1 | SetStateAction<TData, TError> | SuccessAction$1<TData>;
277
+ /**
278
+ * Represents a single cached query. A `Query` holds the query's key, options,
279
+ * state (data/error/status), and the observers currently subscribed to it.
280
+ *
281
+ * Instances are created and managed internally by `QueryCache`; application
282
+ * code typically interacts with queries indirectly through `QueryClient` or
283
+ * a framework hook like `useQuery`. Direct access to a `Query` instance is
284
+ * possible via `queryCache.find()`/`findAll()` for inspecting cache state.
285
+ *
286
+ * @example
287
+ * ```ts
288
+ * const queryCache = queryClient.getQueryCache()
289
+ * const query = queryCache.find({ queryKey: ['posts'] })
290
+ *
291
+ * if (query) {
292
+ * console.log(query.state.dataUpdatedAt)
293
+ * }
294
+ * ```
295
+ */
111
296
  declare class Query<TQueryFnData = unknown, TError = DefaultError, TData = TQueryFnData, TQueryKey extends QueryKey = QueryKey> extends Removable {
112
297
  #private;
113
298
  queryKey: TQueryKey;
@@ -116,31 +301,153 @@ declare class Query<TQueryFnData = unknown, TError = DefaultError, TData = TQuer
116
301
  state: QueryState<TData, TError>;
117
302
  observers: Array<QueryObserver<any, any, any, any, any>>;
118
303
  constructor(config: QueryConfig<TQueryFnData, TError, TData, TQueryKey>);
304
+ /**
305
+ * The `meta` object passed in the query's options, if any.
306
+ */
119
307
  get meta(): QueryMeta | undefined;
308
+ /** @internal */
120
309
  get queryType(): "infinite" | undefined;
310
+ /**
311
+ * The promise for the currently in-flight fetch, if the query is fetching.
312
+ * `undefined` when the query is not fetching.
313
+ */
121
314
  get promise(): Promise<TData> | undefined;
315
+ /** @internal */
122
316
  setOptions(options?: QueryOptions<TQueryFnData, TError, TData, TQueryKey>): void;
123
317
  protected optionalRemove(): void;
318
+ /** @internal */
124
319
  setData(newData: TData, options?: SetDataOptions & {
125
320
  manual: boolean;
126
321
  }): TData;
322
+ /**
323
+ * Merges the given partial state directly into this query's state, notifying observers. Used
324
+ * by persistence and broadcast plugins to restore a state snapshot, and by devtools to let a
325
+ * user manually trigger a loading/error state or edit the cached data.
326
+ */
127
327
  setState(state: Partial<QueryState<TData, TError>>): void;
328
+ /**
329
+ * Cancels the query's currently in-flight fetch, if any.
330
+ * - Returns a promise that resolves once the cancellation has settled.
331
+ * - If no fetch is in progress, resolves immediately.
332
+ *
333
+ * @example
334
+ * ```ts
335
+ * await query.cancel()
336
+ * ```
337
+ */
128
338
  cancel(options?: CancelOptions): Promise<void>;
339
+ /**
340
+ * Clears the query's garbage collection timeout and silently cancels any
341
+ * in-flight fetch. Called by `QueryCache` when the query is removed from
342
+ * the cache.
343
+ *
344
+ * @see {@link Query#cancel}
345
+ */
129
346
  destroy(): void;
347
+ /** @internal */
130
348
  get resetState(): QueryState<TData, TError>;
349
+ /**
350
+ * Resets the query back to its initial state (the state it had when it was
351
+ * first created, e.g. any `initialData`), destroying it first to cancel any
352
+ * in-flight fetch.
353
+ */
131
354
  reset(): void;
355
+ /**
356
+ * Returns `true` if the query has at least one observer for which `enabled`
357
+ * does not resolve to `false`.
358
+ */
132
359
  isActive(): boolean;
360
+ /**
361
+ * Returns `true` if the query is disabled, meaning it will not fetch
362
+ * automatically.
363
+ * - If the query has observers, it is disabled when none of them are active
364
+ * (see `isActive`).
365
+ * - If the query has no observers, it is disabled when its `queryFn` is
366
+ * `skipToken` or it has never been fetched.
367
+ */
133
368
  isDisabled(): boolean;
369
+ /**
370
+ * Returns `true` if the query has been fetched, i.e. it has resolved with
371
+ * either data or an error at least once.
372
+ */
134
373
  isFetched(): boolean;
374
+ /**
375
+ * Returns `true` if the query has at least one observer configured with
376
+ * `staleTime: 'static'`, meaning it is treated as never stale.
377
+ */
135
378
  isStatic(): boolean;
379
+ /**
380
+ * Returns `true` if the query is stale.
381
+ * - If the query has observers, defers to whether any observer's current
382
+ * result reports `isStale` (which accounts for each observer's own
383
+ * `staleTime` and `enabled` state).
384
+ * - If the query has no observers, it is considered stale when it has no
385
+ * data or has been invalidated.
386
+ *
387
+ * @see {@link Query#isStaleByTime}
388
+ * @example
389
+ * ```ts
390
+ * if (query.isStale()) {
391
+ * // refetch or otherwise treat the cached data as outdated
392
+ * }
393
+ * ```
394
+ */
136
395
  isStale(): boolean;
396
+ /**
397
+ * Returns `true` if the query's data is stale relative to the given
398
+ * `staleTime` (defaults to `0`).
399
+ * - A query with no data is always stale.
400
+ * - `staleTime: 'static'` is never stale.
401
+ * - An invalidated query is always stale.
402
+ * - Otherwise, staleness is based on elapsed time since `dataUpdatedAt`.
403
+ *
404
+ * @see {@link Query#isStale}
405
+ * @example
406
+ * ```ts
407
+ * const isStale = query.isStaleByTime(1000 * 60)
408
+ * ```
409
+ */
137
410
  isStaleByTime(staleTime?: StaleTime): boolean;
411
+ /** @internal */
138
412
  onFocus(): void;
413
+ /** @internal */
139
414
  onOnline(): void;
415
+ /** @internal */
140
416
  addObserver(observer: QueryObserver<any, any, any, any, any>): void;
417
+ /** @internal */
141
418
  removeObserver(observer: QueryObserver<any, any, any, any, any>): void;
419
+ /**
420
+ * Returns the number of observers currently subscribed to this query.
421
+ *
422
+ * @example
423
+ * ```ts
424
+ * if (query.getObserversCount() === 0) {
425
+ * // no component is currently watching this query
426
+ * }
427
+ * ```
428
+ */
142
429
  getObserversCount(): number;
430
+ /**
431
+ * Marks the query as invalidated, unless it is already invalidated. This
432
+ * updates `state.isInvalidated` and notifies observers, but does not by
433
+ * itself trigger a refetch.
434
+ *
435
+ * @example
436
+ * ```ts
437
+ * query.invalidate()
438
+ * ```
439
+ */
143
440
  invalidate(): void;
441
+ /**
442
+ * Fetches the query, i.e. runs its `queryFn` (through any configured
443
+ * retryer/behavior) and updates the query's state with the result.
444
+ * - If a fetch is already in flight, returns its promise instead of
445
+ * starting a new one, unless `fetchOptions.cancelRefetch` is set and the
446
+ * query already has data, in which case the current fetch is silently
447
+ * cancelled first.
448
+ * - If `options` is passed, it replaces the query's current options
449
+ * before fetching.
450
+ */
144
451
  fetch(options?: QueryOptions<TQueryFnData, TError, TData, TQueryKey>, fetchOptions?: FetchOptions<TQueryFnData>): Promise<TData>;
145
452
  }
146
453
  declare function fetchState<TQueryFnData, TError, TData, TQueryKey extends QueryKey>(data: TData | undefined, options: QueryOptions<TQueryFnData, TError, TData, TQueryKey>): {
@@ -153,25 +460,108 @@ declare function fetchState<TQueryFnData, TError, TData, TQueryKey extends Query
153
460
  //#endregion
154
461
  //#region src/mutationObserver.d.ts
155
462
  type MutationObserverListener<TData, TError, TVariables, TOnMutateResult> = (result: MutationObserverResult<TData, TError, TVariables, TOnMutateResult>) => void;
463
+ /**
464
+ * Observes a single mutation and derives a `MutationObserverResult` from it.
465
+ * A framework hook like `useMutation` creates one `MutationObserver` per hook
466
+ * call, keeps it stable across re-renders, calls `setOptions` when the options
467
+ * passed to the hook change, subscribes to it to re-render on updates, and
468
+ * reads `getCurrentResult()` for the value to return. Calling `mutate()`
469
+ * builds a new underlying `Mutation` in the `MutationCache` and executes it.
470
+ *
471
+ * @example
472
+ * ```ts
473
+ * const observer = new MutationObserver(queryClient, {
474
+ * mutationFn: (variables: { title: string }) => addPost(variables),
475
+ * })
476
+ * ```
477
+ */
156
478
  declare class MutationObserver<TData = unknown, TError = DefaultError, TVariables = void, TOnMutateResult = unknown> extends Subscribable<MutationObserverListener<TData, TError, TVariables, TOnMutateResult>> {
157
479
  #private;
158
480
  options: MutationObserverOptions<TData, TError, TVariables, TOnMutateResult>;
159
481
  constructor(client: QueryClient, options: MutationObserverOptions<TData, TError, TVariables, TOnMutateResult>);
160
482
  protected bindMethods(): void;
483
+ /**
484
+ * Updates the observer's options.
485
+ *
486
+ * If the new `mutationKey` differs from the previous one (and both were
487
+ * defined), the observer is reset, detaching it from the mutation it was
488
+ * observing. Otherwise, if the currently observed mutation is still
489
+ * `pending`, its options are updated in place as well.
490
+ *
491
+ * @example
492
+ * ```ts
493
+ * observer.setOptions({
494
+ * mutationFn: (variables: { title: string }) => addPost(variables),
495
+ * onSuccess: (data) => console.log(data),
496
+ * })
497
+ * ```
498
+ */
161
499
  setOptions(options: MutationObserverOptions<TData, TError, TVariables, TOnMutateResult>): void;
162
500
  protected onSubscribe(): void;
163
501
  protected onUnsubscribe(): void;
502
+ /** @internal */
164
503
  onMutationUpdate(action: Action<TData, TError, TVariables, TOnMutateResult>): void;
504
+ /**
505
+ * Returns the observer's current result, derived from the observed
506
+ * mutation's state (or the default, `idle` state if no mutation has been
507
+ * built yet, e.g. before the first `mutate()` call or after `reset()`).
508
+ */
165
509
  getCurrentResult(): MutationObserverResult<TData, TError, TVariables, TOnMutateResult>;
510
+ /**
511
+ * Detaches the observer from the mutation it is currently observing (if
512
+ * any) and resets the observed result back to its default, `idle` state.
513
+ *
514
+ * This does not cancel an in-flight mutation; the mutation itself keeps
515
+ * running to completion and its own callbacks still fire, but this
516
+ * observer stops reflecting its state and a subsequent `mutate()` call
517
+ * will build a brand new mutation.
518
+ *
519
+ * @example
520
+ * ```ts
521
+ * observer.reset()
522
+ * ```
523
+ *
524
+ * @see {@link MutationObserver#mutate}
525
+ */
166
526
  reset(): void;
527
+ /**
528
+ * Builds a new `Mutation` in the `MutationCache` using the observer's
529
+ * current options, detaches this observer from any previously observed
530
+ * mutation, attaches it to the new one, and executes it with the given
531
+ * variables.
532
+ *
533
+ * The optional per-call `options` (`onSuccess`/`onError`/`onSettled`) are
534
+ * invoked once the mutation settles, in addition to any callbacks defined
535
+ * on the observer's own options.
536
+ *
537
+ * @example
538
+ * ```ts
539
+ * await observer.mutate(
540
+ * { title: 'New post' },
541
+ * { onSuccess: (data) => console.log(data) },
542
+ * )
543
+ * ```
544
+ */
167
545
  mutate(variables: TVariables, options?: MutateOptions<TData, TError, TVariables, TOnMutateResult>): Promise<TData>;
168
546
  }
169
547
  //#endregion
170
548
  //#region src/mutationCache.d.ts
549
+ /**
550
+ * Global callbacks that fire for every mutation handled by a `MutationCache`, regardless of which
551
+ * component or observer triggered it. They differ from the `defaultOptions` provided to a
552
+ * `QueryClient` in two ways: `defaultOptions` can be overridden by each mutation, while these
553
+ * callbacks are always called, and `onMutate` here does not allow returning a result.
554
+ *
555
+ * If a callback returns a promise, it will be awaited before the mutation continues.
556
+ */
171
557
  interface MutationCacheConfig {
558
+ /** Called when any mutation in the cache encounters an error. */
172
559
  onError?: (error: DefaultError, variables: unknown, onMutateResult: unknown, mutation: Mutation<unknown, unknown, unknown>, context: MutationFunctionContext) => Promise<unknown> | unknown;
560
+ /** Called when any mutation in the cache is successful. */
173
561
  onSuccess?: (data: unknown, variables: unknown, onMutateResult: unknown, mutation: Mutation<unknown, unknown, unknown>, context: MutationFunctionContext) => Promise<unknown> | unknown;
562
+ /** Called before any mutation in the cache executes. */
174
563
  onMutate?: (variables: unknown, mutation: Mutation<unknown, unknown, unknown>, context: MutationFunctionContext) => Promise<unknown> | unknown;
564
+ /** Called when any mutation in the cache is settled, either successfully or with an error. */
175
565
  onSettled?: (data: unknown | undefined, error: DefaultError | null, variables: unknown, onMutateResult: unknown, mutation: Mutation<unknown, unknown, unknown>, context: MutationFunctionContext) => Promise<unknown> | unknown;
176
566
  }
177
567
  interface NotifyEventMutationAdded extends NotifyEvent {
@@ -202,22 +592,101 @@ interface NotifyEventMutationUpdated extends NotifyEvent {
202
592
  mutation: Mutation<any, any, any, any>;
203
593
  action: Action<any, any, any, any>;
204
594
  }
595
+ /**
596
+ * The event passed to a `MutationCache` subscriber. Fired whenever a mutation is added or removed
597
+ * from the cache, its state is updated, or one of its observers is added, removed, or has its
598
+ * options updated.
599
+ */
205
600
  type MutationCacheNotifyEvent = NotifyEventMutationAdded | NotifyEventMutationRemoved | NotifyEventMutationObserverAdded | NotifyEventMutationObserverRemoved | NotifyEventMutationObserverOptionsUpdated | NotifyEventMutationUpdated;
206
601
  type MutationCacheListener = (event: MutationCacheNotifyEvent) => void;
602
+ /**
603
+ * The `MutationCache` is the storage for mutations.
604
+ *
605
+ * Normally, you will not interact with the `MutationCache` directly and instead use a
606
+ * `QueryClient`. You can subscribe to it (inherited from `Subscribable`) to be informed of
607
+ * safe/known updates to the cache, such as mutations being added, removed, or updated.
608
+ *
609
+ * @example
610
+ * ```ts
611
+ * const unsubscribe = mutationCache.subscribe((event) => {
612
+ * console.log(event.type, event.mutation)
613
+ * })
614
+ * ```
615
+ */
207
616
  declare class MutationCache extends Subscribable<MutationCacheListener> {
208
617
  #private;
209
618
  config: MutationCacheConfig;
210
619
  constructor(config?: MutationCacheConfig);
620
+ /** @internal */
211
621
  build<TData, TError, TVariables, TOnMutateResult>(client: QueryClient, options: MutationOptions<TData, TError, TVariables, TOnMutateResult>, state?: MutationState<TData, TError, TVariables, TOnMutateResult>): Mutation<TData, TError, TVariables, TOnMutateResult>;
622
+ /** @internal */
212
623
  add(mutation: Mutation<any, any, any, any>): void;
624
+ /** @internal */
213
625
  remove(mutation: Mutation<any, any, any, any>): void;
626
+ /** @internal */
214
627
  canRun(mutation: Mutation<any, any, any, any>): boolean;
628
+ /** @internal */
215
629
  runNext(mutation: Mutation<any, any, any, any>): Promise<unknown>;
630
+ /**
631
+ * Removes all mutations from the cache.
632
+ *
633
+ * @example
634
+ * ```ts
635
+ * const mutationCache = queryClient.getMutationCache()
636
+ *
637
+ * mutationCache.clear()
638
+ * ```
639
+ */
216
640
  clear(): void;
641
+ /**
642
+ * Returns all mutations within the cache.
643
+ *
644
+ * This is not typically needed for most applications, but can come in handy when needing more
645
+ * information about a mutation in rare scenarios.
646
+ *
647
+ * @example
648
+ * ```ts
649
+ * const mutationCache = queryClient.getMutationCache()
650
+ *
651
+ * const mutations = mutationCache.getAll()
652
+ * ```
653
+ */
217
654
  getAll(): Array<Mutation>;
655
+ /**
656
+ * A slightly more advanced method that can be used to get an existing mutation instance from
657
+ * the cache. If the mutation does not exist, `undefined` is returned.
658
+ *
659
+ * This is not typically needed for most applications, but can come in handy when needing more
660
+ * information about a mutation in rare scenarios.
661
+ *
662
+ * @see {@link MutationCache#findAll}
663
+ * @example
664
+ * ```ts
665
+ * const mutationCache = queryClient.getMutationCache()
666
+ *
667
+ * const mutation = mutationCache.find({ mutationKey: ['addPost'] })
668
+ * ```
669
+ */
218
670
  find<TData = unknown, TError = DefaultError, TVariables = any, TOnMutateResult = unknown>(filters: MutationFilters): Mutation<TData, TError, TVariables, TOnMutateResult> | undefined;
671
+ /**
672
+ * An even more advanced method that can be used to get existing mutation instances from the
673
+ * cache that match the given filters. If no mutations match, an empty array is returned.
674
+ *
675
+ * This is not typically needed for most applications, but can come in handy when needing more
676
+ * information about mutations in rare scenarios.
677
+ *
678
+ * @see {@link MutationCache#find}
679
+ * @example
680
+ * ```ts
681
+ * const mutationCache = queryClient.getMutationCache()
682
+ *
683
+ * const mutations = mutationCache.findAll({ mutationKey: ['addPost'] })
684
+ * ```
685
+ */
219
686
  findAll(filters?: MutationFilters): Array<Mutation>;
687
+ /** @internal */
220
688
  notify(event: MutationCacheNotifyEvent): void;
689
+ /** @internal */
221
690
  resumePausedMutations(): Promise<unknown>;
222
691
  }
223
692
  //#endregion
@@ -229,15 +698,49 @@ interface MutationConfig<TData, TError, TVariables, TOnMutateResult> {
229
698
  options: MutationOptions<TData, TError, TVariables, TOnMutateResult>;
230
699
  state?: MutationState<TData, TError, TVariables, TOnMutateResult>;
231
700
  }
701
+ /**
702
+ * The raw state stored on a `Mutation` instance. This is the underlying state
703
+ * that observer results (e.g. `MutationObserverResult`) are derived from.
704
+ */
232
705
  interface MutationState<TData = unknown, TError = DefaultError, TVariables = unknown, TOnMutateResult = unknown> {
706
+ /**
707
+ * The value returned by `onMutate`, if defined. Passed to `onSuccess`,
708
+ * `onError` and `onSettled` as the mutation's context.
709
+ */
233
710
  context: TOnMutateResult | undefined;
711
+ /**
712
+ * The last successfully resolved data for the mutation.
713
+ */
234
714
  data: TData | undefined;
715
+ /**
716
+ * The error object for the mutation, if the last attempt resulted in an error.
717
+ * - Defaults to `null`.
718
+ */
235
719
  error: TError | null;
720
+ /**
721
+ * The number of times the mutation function has failed for the current attempt.
722
+ */
236
723
  failureCount: number;
724
+ /**
725
+ * The reason the current attempt failed, as reported by the retryer.
726
+ */
237
727
  failureReason: TError | null;
728
+ /**
729
+ * Whether the mutation is currently paused (see network mode), or is
730
+ * waiting for another mutation with the same `scope` to finish.
731
+ */
238
732
  isPaused: boolean;
733
+ /**
734
+ * The status of the mutation.
735
+ */
239
736
  status: MutationStatus;
737
+ /**
738
+ * The variables the mutation was last called with.
739
+ */
240
740
  variables: TVariables | undefined;
741
+ /**
742
+ * The timestamp for when the mutation was submitted.
743
+ */
241
744
  submittedAt: number;
242
745
  }
243
746
  interface FailedAction<TError> {
@@ -266,18 +769,92 @@ interface ContinueAction {
266
769
  type: 'continue';
267
770
  }
268
771
  type Action<TData, TError, TVariables, TOnMutateResult> = ContinueAction | ErrorAction<TError> | FailedAction<TError> | PendingAction<TVariables, TOnMutateResult> | PauseAction | SuccessAction<TData>;
772
+ /**
773
+ * Represents a single mutation attempt. A `Mutation` holds the mutation's
774
+ * options, state (data/error/status), and the `MutationObserver`s currently
775
+ * subscribed to it.
776
+ *
777
+ * Instances are created and managed internally by `MutationCache`; application
778
+ * code typically interacts with mutations indirectly through `QueryClient` or
779
+ * a framework hook like `useMutation`. Direct access to a `Mutation` instance
780
+ * is possible via `mutationCache.find()`/`getAll()` for inspecting cache state.
781
+ *
782
+ * @example
783
+ * ```ts
784
+ * const mutationCache = queryClient.getMutationCache()
785
+ *
786
+ * const mutation = mutationCache.find({ mutationKey: ['addPost'] })
787
+ * ```
788
+ */
269
789
  declare class Mutation<TData = unknown, TError = DefaultError, TVariables = unknown, TOnMutateResult = unknown> extends Removable {
270
790
  #private;
271
791
  state: MutationState<TData, TError, TVariables, TOnMutateResult>;
272
792
  options: MutationOptions<TData, TError, TVariables, TOnMutateResult>;
273
793
  readonly mutationId: number;
274
794
  constructor(config: MutationConfig<TData, TError, TVariables, TOnMutateResult>);
795
+ /** @internal */
275
796
  setOptions(options: MutationOptions<TData, TError, TVariables, TOnMutateResult>): void;
797
+ /**
798
+ * The `meta` object passed in the mutation's options, if any.
799
+ */
276
800
  get meta(): MutationMeta | undefined;
801
+ /** @internal */
277
802
  addObserver(observer: MutationObserver<any, any, any, any>): void;
803
+ /** @internal */
278
804
  removeObserver(observer: MutationObserver<any, any, any, any>): void;
279
805
  protected optionalRemove(): void;
806
+ /**
807
+ * Resumes a mutation that is currently paused or was restored from a
808
+ * dehydrated, still-`pending` state.
809
+ *
810
+ * - If this mutation has an active retryer (it paused mid-attempt, e.g. due
811
+ * to the network mode or scope-based queuing), its retryer is resumed.
812
+ * - Otherwise, if the mutation's status is still `pending` (e.g. it was
813
+ * dehydrated while an attempt was in flight and never got a retryer in
814
+ * this instance), `execute` is called again with the last known variables.
815
+ * - Otherwise the mutation has already settled and this resolves immediately
816
+ * without running anything again.
817
+ *
818
+ * @example
819
+ * ```ts
820
+ * // typically driven by reconnect handling, e.g. queryClient.resumePausedMutations()
821
+ * const mutation = mutationCache.find({ mutationKey: ['addPost'] })
822
+ * await mutation?.continue()
823
+ * ```
824
+ *
825
+ * @see {@link Mutation#execute}
826
+ */
280
827
  continue(): Promise<unknown>;
828
+ /**
829
+ * Runs the mutation function for the given variables through a retryer, and
830
+ * drives the mutation's state and lifecycle callbacks through to settlement.
831
+ *
832
+ * If this mutation's state is already `pending` when `execute` is called
833
+ * (i.e. it was restored, still in-flight, from a dehydrated state), the
834
+ * `onMutate` step is skipped and a `continue` action is dispatched to
835
+ * unpause it; otherwise a `pending` action is dispatched first, then the
836
+ * mutation cache's `onMutate` and the mutation's own `onMutate` option are
837
+ * awaited in that order, and the resulting context is stored.
838
+ *
839
+ * The mutation function is then run (subject to `retry`/`retryDelay`/
840
+ * `networkMode`, and to the mutation cache's scope-based serialization).
841
+ * On success, the cache's `onSuccess`/`onSettled` callbacks run before the
842
+ * mutation's own `onSuccess`/`onSettled` options, a `success` action is
843
+ * dispatched, and the resolved data is returned. On failure, the same
844
+ * cache-then-option ordering is used for `onError`/`onSettled`, but each of
845
+ * those four callbacks is individually caught so that a throwing callback
846
+ * cannot mask the original error; an `error` action is then dispatched and
847
+ * the original error is re-thrown.
848
+ *
849
+ * @example
850
+ * ```ts
851
+ * // Called internally by `MutationObserver.mutate` and `Mutation.continue` —
852
+ * // applications normally trigger mutations through those, not this method.
853
+ * const data = await mutation.execute(variables)
854
+ * ```
855
+ *
856
+ * @see {@link Mutation#continue}
857
+ */
281
858
  execute(variables: TVariables): Promise<TData>;
282
859
  }
283
860
  declare function getDefaultState<TData, TError, TVariables, TOnMutateResult>(): MutationState<TData, TError, TVariables, TOnMutateResult>;
@@ -285,9 +862,15 @@ declare function getDefaultState<TData, TError, TVariables, TOnMutateResult>():
285
862
  //#region src/utils.d.ts
286
863
  type DropLast<T extends ReadonlyArray<unknown>> = T extends readonly [...infer R, unknown] ? readonly [...R] : never;
287
864
  type TuplePrefixes<T extends ReadonlyArray<unknown>> = T extends readonly [] ? readonly [] : TuplePrefixes<DropLast<T>> | T;
865
+ /**
866
+ * Filters used to select queries, for example in `queryClient.getQueriesData` or `queryClient.invalidateQueries`.
867
+ * All provided filters must match; filters that are left unspecified are ignored.
868
+ */
288
869
  interface QueryFilters<TQueryKey extends QueryKey = QueryKey> {
289
870
  /**
290
871
  * Filter to active queries, inactive queries or all queries
872
+ *
873
+ * Defaults to `'all'`.
291
874
  */
292
875
  type?: QueryTypeFilter;
293
876
  /**
@@ -311,6 +894,10 @@ interface QueryFilters<TQueryKey extends QueryKey = QueryKey> {
311
894
  */
312
895
  fetchStatus?: FetchStatus;
313
896
  }
897
+ /**
898
+ * Filters used to select mutations, for example in `mutationCache.findAll` or `queryClient.isMutating`.
899
+ * All provided filters must match; filters that are left unspecified are ignored.
900
+ */
314
901
  interface MutationFilters<TData = unknown, TError = DefaultError, TVariables = unknown, TOnMutateResult = unknown> {
315
902
  /**
316
903
  * Match mutation key exactly
@@ -329,24 +916,75 @@ interface MutationFilters<TData = unknown, TError = DefaultError, TVariables = u
329
916
  */
330
917
  status?: MutationStatus;
331
918
  }
919
+ /**
920
+ * Either a plain value of type `TOutput`, or a function that receives `TInput` and returns `TOutput`.
921
+ * Used for example by `setQueryData`-style updaters, which accept either the new data directly or a
922
+ * function that computes it from the previous data. See {@link functionalUpdate}.
923
+ *
924
+ * @example
925
+ * ```ts
926
+ * queryClient.setQueryData(['posts'], newPosts)
927
+ *
928
+ * // Or, using an updater function that receives the current data:
929
+ * queryClient.setQueryData(['posts'], (oldPosts) =>
930
+ * oldPosts ? [...oldPosts, newPost] : oldPosts,
931
+ * )
932
+ * ```
933
+ */
332
934
  type Updater<TInput, TOutput> = TOutput | ((input: TInput) => TOutput);
333
935
  type QueryTypeFilter = 'all' | 'active' | 'inactive';
334
936
  /** @deprecated
335
937
  * use `environmentManager.isServer()` instead.
336
938
  */
337
939
  declare const isServer: boolean;
940
+ /**
941
+ * A function that does nothing.
942
+ */
338
943
  declare function noop(): void;
339
944
  declare function noop(): undefined;
340
945
  declare function functionalUpdate<TInput, TOutput>(updater: Updater<TInput, TOutput>, input: TInput): TOutput;
341
946
  declare function isValidTimeout(value: unknown): value is number;
342
947
  declare function timeUntilStale(updatedAt: number, staleTime?: number): number;
343
948
  declare function resolveQueryValue<TValue, TQueryFnData = unknown, TError = DefaultError, TData = TQueryFnData, TQueryKey extends QueryKey = QueryKey>(value: undefined | TValue | ((query: Query<TQueryFnData, TError, TData, TQueryKey>) => TValue), query: Query<TQueryFnData, TError, TData, TQueryKey>): TValue | undefined;
949
+ /**
950
+ * Checks whether a query matches the given {@link QueryFilters}.
951
+ * Every filter that is specified must match; filters that are left unspecified are ignored.
952
+ *
953
+ * @example
954
+ * ```ts
955
+ * const queryCache = queryClient.getQueryCache()
956
+ *
957
+ * const matchingQueries = queryCache
958
+ * .getAll()
959
+ * .filter((query) => matchQuery({ queryKey: ['posts'] }, query))
960
+ * ```
961
+ */
344
962
  declare function matchQuery(filters: QueryFilters, query: Query<any, any, any, any>): boolean;
963
+ /**
964
+ * Checks whether a mutation matches the given {@link MutationFilters}.
965
+ * Every filter that is specified must match; filters that are left unspecified are ignored.
966
+ * If a `mutationKey` filter is provided but the mutation has no `mutationKey` of its own, it does not match.
967
+ *
968
+ * @example
969
+ * ```ts
970
+ * const mutationCache = queryClient.getMutationCache()
971
+ *
972
+ * const matchingMutations = mutationCache
973
+ * .getAll()
974
+ * .filter((mutation) => matchMutation({ mutationKey: ['addPost'] }, mutation))
975
+ * ```
976
+ */
345
977
  declare function matchMutation(filters: MutationFilters, mutation: Mutation<any, any>): boolean;
346
978
  declare function hashQueryKeyByOptions<TQueryKey extends QueryKey = QueryKey>(queryKey: TQueryKey, options?: Pick<QueryOptions<any, any, any, any>, 'queryKeyHashFn'>): string;
347
979
  /**
348
980
  * Default query & mutation keys hash function.
349
981
  * Hashes the value into a stable hash.
982
+ *
983
+ * @example
984
+ * ```ts
985
+ * // Object keys are sorted, so key order doesn't affect the hash:
986
+ * hashKey(['todos', { page: 1, filter: 'done' }]) // === '["todos",{"filter":"done","page":1}]'
987
+ * ```
350
988
  */
351
989
  declare function hashKey(queryKey: QueryKey | MutationKey): string;
352
990
  /**
@@ -367,24 +1005,78 @@ declare function isPlainArray(value: unknown): value is Array<unknown>;
367
1005
  declare function isPlainObject(o: any): o is Record<PropertyKey, unknown>;
368
1006
  declare function sleep(timeout: number): Promise<void>;
369
1007
  declare function replaceData<TData, TOptions extends QueryOptions<any, any, any, any>>(prevData: TData | undefined, data: TData, options: TOptions): TData;
1008
+ /**
1009
+ * Intended to be passed as a query's `placeholderData` option, for example
1010
+ * `placeholderData: keepPreviousData`. Instead of resetting the query's data to `undefined` while a new
1011
+ * query key is fetching, it keeps displaying the previously fetched data until the new data arrives.
1012
+ *
1013
+ * @example
1014
+ * ```ts
1015
+ * new QueryObserver(queryClient, {
1016
+ * queryKey: ['posts', page],
1017
+ * queryFn: () => fetchPosts(page),
1018
+ * placeholderData: keepPreviousData,
1019
+ * })
1020
+ * ```
1021
+ */
370
1022
  declare function keepPreviousData<T>(previousData: T | undefined): T | undefined;
371
1023
  declare function addToEnd<T>(items: Array<T>, item: T, max?: number): Array<T>;
372
1024
  declare function addToStart<T>(items: Array<T>, item: T, max?: number): Array<T>;
1025
+ /**
1026
+ * Sentinel value that can be passed as a query's `queryFn` to conditionally disable the query (equivalent
1027
+ * to `enabled: false`) while preserving full type inference for the query's data. Unlike `enabled: false`,
1028
+ * a query disabled via `skipToken` cannot be triggered with `refetch`.
1029
+ *
1030
+ * @example
1031
+ * ```ts
1032
+ * new QueryObserver(queryClient, {
1033
+ * queryKey: ['post', postId],
1034
+ * queryFn: postId != null ? () => fetchPost(postId) : skipToken,
1035
+ * })
1036
+ * ```
1037
+ */
373
1038
  declare const skipToken: unique symbol;
1039
+ /**
1040
+ * The type of the {@link skipToken} sentinel value.
1041
+ */
374
1042
  type SkipToken = typeof skipToken;
375
1043
  declare function ensureQueryFn<TQueryFnData = unknown, TQueryKey extends QueryKey = QueryKey>(options: {
376
1044
  queryFn?: QueryFunction<TQueryFnData, TQueryKey> | SkipToken;
377
1045
  queryHash?: string;
378
1046
  }, fetchOptions?: FetchOptions<TQueryFnData>): QueryFunction<TQueryFnData, TQueryKey>;
1047
+ /**
1048
+ * Resolves a `throwOnError` option to a boolean.
1049
+ * If `throwOnError` is a function, it is called with `params` (e.g. the error and, depending on the caller,
1050
+ * additional context such as the query or mutation) and its result is returned, allowing the throwing
1051
+ * behavior to be decided per error. Otherwise, `throwOnError` itself is coerced to a boolean (`undefined`
1052
+ * resolves to `false`).
1053
+ *
1054
+ * @example
1055
+ * ```ts
1056
+ * const throwOnError =
1057
+ * query.state.error && typeof options.throwOnError === 'function'
1058
+ * ? shouldThrowError(options.throwOnError, [query.state.error, query])
1059
+ * : options.throwOnError
1060
+ * ```
1061
+ */
379
1062
  declare function shouldThrowError<T extends (...args: Array<any>) => boolean>(throwOnError: boolean | T | undefined, params: Parameters<T>): boolean;
380
1063
  declare function addConsumeAwareSignal<T>(object: T, getSignal: () => AbortSignal, onCancelled: VoidFunction): T & {
381
1064
  signal: AbortSignal;
382
1065
  };
383
1066
  //#endregion
384
1067
  //#region src/queryCache.d.ts
1068
+ /**
1069
+ * Global callbacks that fire for every query handled by a `QueryCache`, regardless of which
1070
+ * component or observer triggered it. Unlike `QueryClient`'s `defaultOptions`, which a query can
1071
+ * override, these callbacks are always called. Unlike `MutationCacheConfig`'s callbacks, these
1072
+ * are fire-and-forget: their return value is not awaited before the query settles.
1073
+ */
385
1074
  interface QueryCacheConfig {
1075
+ /** Called when any query in the cache encounters an error. */
386
1076
  onError?: (error: DefaultError, query: Query<unknown, unknown, unknown>) => void;
1077
+ /** Called when any query in the cache is successful. */
387
1078
  onSuccess?: (data: unknown, query: Query<unknown, unknown, unknown>) => void;
1079
+ /** Called when any query in the cache is settled, either successfully or with an error. */
388
1080
  onSettled?: (data: unknown | undefined, error: DefaultError | null, query: Query<unknown, unknown, unknown>) => void;
389
1081
  }
390
1082
  interface NotifyEventQueryAdded extends NotifyEvent {
@@ -419,6 +1111,11 @@ interface NotifyEventQueryObserverOptionsUpdated extends NotifyEvent {
419
1111
  query: Query<any, any, any, any>;
420
1112
  observer: QueryObserver<any, any, any, any, any>;
421
1113
  }
1114
+ /**
1115
+ * The event passed to a `QueryCache` subscriber. Fired whenever a query is added or removed from
1116
+ * the cache, its state is updated (e.g. via `query.setState` or `queryClient.removeQueries`), or
1117
+ * one of its observers is added, removed, or has its results or options updated.
1118
+ */
422
1119
  type QueryCacheNotifyEvent = NotifyEventQueryAdded | NotifyEventQueryRemoved | NotifyEventQueryUpdated | NotifyEventQueryObserverAdded | NotifyEventQueryObserverRemoved | NotifyEventQueryObserverResultsUpdated | NotifyEventQueryObserverOptionsUpdated;
423
1120
  type QueryCacheListener = (event: QueryCacheNotifyEvent) => void;
424
1121
  interface QueryStore {
@@ -428,30 +1125,202 @@ interface QueryStore {
428
1125
  delete: (queryHash: string) => void;
429
1126
  values: () => IterableIterator<Query>;
430
1127
  }
1128
+ /**
1129
+ * The `QueryCache` is the storage mechanism for TanStack Query. It stores all the data, meta
1130
+ * information, and state of the queries it contains.
1131
+ *
1132
+ * Normally, you will not interact with the `QueryCache` directly and instead use a `QueryClient`
1133
+ * for a specific cache. You can subscribe to it (inherited from `Subscribable`) to be informed of
1134
+ * safe/known updates to the cache, such as queries being added, removed, or updated — updates made
1135
+ * outside of the cache's own tracked mechanisms (e.g. mutating a query's state object directly) do
1136
+ * not notify subscribers.
1137
+ *
1138
+ * @example
1139
+ * ```ts
1140
+ * const unsubscribe = queryCache.subscribe((event) => {
1141
+ * console.log(event.type, event.query)
1142
+ * })
1143
+ * ```
1144
+ */
431
1145
  declare class QueryCache extends Subscribable<QueryCacheListener> {
432
1146
  #private;
433
1147
  config: QueryCacheConfig;
434
1148
  constructor(config?: QueryCacheConfig);
1149
+ /**
1150
+ * Returns the existing `Query` instance for the given options' `queryKey`/`queryHash`, or
1151
+ * builds and adds a new one to the cache if none exists yet. Used by framework adapters and
1152
+ * plugins (e.g. broadcast/persistence) that need to get-or-create a `Query` directly, bypassing
1153
+ * the reactive `QueryObserver` machinery.
1154
+ *
1155
+ * @example
1156
+ * ```ts
1157
+ * const queryCache = queryClient.getQueryCache()
1158
+ *
1159
+ * const query = queryCache.build(queryClient, {
1160
+ * queryKey: ['posts'],
1161
+ * queryFn: fetchPosts,
1162
+ * })
1163
+ * ```
1164
+ */
435
1165
  build<TQueryFnData = unknown, TError = DefaultError, TData = TQueryFnData, TQueryKey extends QueryKey = QueryKey>(client: QueryClient, options: WithRequired<QueryOptions<TQueryFnData, TError, TData, TQueryKey>, 'queryKey'>, state?: QueryState<TData, TError>): Query<TQueryFnData, TError, TData, TQueryKey>;
1166
+ /** @internal */
436
1167
  add(query: Query<any, any, any, any>): void;
1168
+ /**
1169
+ * Destroys the given `Query` and removes it from the cache, notifying subscribers with a
1170
+ * `'removed'` event. A no-op if the query is no longer the one currently stored under its hash
1171
+ * (e.g. it was already replaced). Used by plugins (e.g. the broadcast client) that mirror
1172
+ * removals across `QueryCache` instances.
1173
+ *
1174
+ * @example
1175
+ * ```ts
1176
+ * const queryCache = queryClient.getQueryCache()
1177
+ * const query = queryCache.find({ queryKey: ['posts'] })
1178
+ *
1179
+ * if (query) {
1180
+ * queryCache.remove(query)
1181
+ * }
1182
+ * ```
1183
+ */
437
1184
  remove(query: Query<any, any, any, any>): void;
1185
+ /**
1186
+ * Removes all queries from the cache.
1187
+ *
1188
+ * @example
1189
+ * ```ts
1190
+ * const queryCache = queryClient.getQueryCache()
1191
+ *
1192
+ * queryCache.clear()
1193
+ * ```
1194
+ */
438
1195
  clear(): void;
1196
+ /**
1197
+ * Returns the `Query` instance stored under the given `queryHash`, or `undefined` if none
1198
+ * exists. Unlike {@link QueryCache#find}, this looks up by the already-computed hash rather
1199
+ * than by `QueryFilters`. Used by plugins (e.g. broadcast/hydration) that already have a hash
1200
+ * to look up directly.
1201
+ *
1202
+ * @example
1203
+ * ```ts
1204
+ * const queryCache = queryClient.getQueryCache()
1205
+ * const queryHash = hashKey(['posts'])
1206
+ *
1207
+ * const query = queryCache.get(queryHash)
1208
+ * ```
1209
+ */
439
1210
  get<TQueryFnData = unknown, TError = DefaultError, TData = TQueryFnData, TQueryKey extends QueryKey = QueryKey>(queryHash: string): Query<TQueryFnData, TError, TData, TQueryKey> | undefined;
1211
+ /**
1212
+ * Returns all queries within the cache.
1213
+ *
1214
+ * @example
1215
+ * ```ts
1216
+ * const queryCache = queryClient.getQueryCache()
1217
+ *
1218
+ * const queries = queryCache.getAll()
1219
+ * ```
1220
+ */
440
1221
  getAll(): Array<Query>;
1222
+ /**
1223
+ * A slightly more advanced method that can be used to get an existing query instance from the
1224
+ * cache. This instance not only contains all the state for the query, but all of the instances,
1225
+ * and underlying guts of the query as well. If the query does not exist, `undefined` is
1226
+ * returned.
1227
+ *
1228
+ * This is not typically needed for most applications, but can come in handy when needing more
1229
+ * information about a query in rare scenarios (e.g. looking at `query.state.dataUpdatedAt` to
1230
+ * decide whether a query is fresh enough to be used as an initial value).
1231
+ *
1232
+ * @see {@link QueryCache#findAll}
1233
+ * @example
1234
+ * ```ts
1235
+ * const queryCache = queryClient.getQueryCache()
1236
+ *
1237
+ * const query = queryCache.find({ queryKey: ['posts'] })
1238
+ * ```
1239
+ */
441
1240
  find<TQueryFnData = unknown, TError = DefaultError, TData = TQueryFnData>(filters: WithRequired<QueryFilters, 'queryKey'>): Query<TQueryFnData, TError, TData> | undefined;
1241
+ /**
1242
+ * An even more advanced method that can be used to get existing query instances from the cache
1243
+ * that partially match a query key. If no queries match, an empty array is returned.
1244
+ *
1245
+ * This is not typically needed for most applications, but can come in handy when needing more
1246
+ * information about queries in rare scenarios.
1247
+ *
1248
+ * @see {@link QueryCache#find}
1249
+ * @example
1250
+ * ```ts
1251
+ * const queryCache = queryClient.getQueryCache()
1252
+ *
1253
+ * const queries = queryCache.findAll({ queryKey: ['posts'] })
1254
+ * ```
1255
+ */
442
1256
  findAll(filters?: QueryFilters<any>): Array<Query>;
1257
+ /** @internal */
443
1258
  notify(event: QueryCacheNotifyEvent): void;
1259
+ /** @internal */
444
1260
  onFocus(): void;
1261
+ /** @internal */
445
1262
  onOnline(): void;
446
1263
  }
447
1264
  //#endregion
448
1265
  //#region src/queryClient.d.ts
1266
+ /**
1267
+ * `QueryClient` is used to interact with a cache of queries and mutations. It owns a
1268
+ * `QueryCache` and a `MutationCache` (creating default ones if none are passed in) and holds
1269
+ * the default options that are applied to queries and mutations created through it.
1270
+ *
1271
+ * @example
1272
+ * ```ts
1273
+ * const queryClient = new QueryClient({
1274
+ * defaultOptions: {
1275
+ * queries: {
1276
+ * staleTime: Infinity,
1277
+ * },
1278
+ * },
1279
+ * })
1280
+ *
1281
+ * await queryClient.query({ queryKey: ['posts'], queryFn: fetchPosts })
1282
+ * ```
1283
+ */
449
1284
  declare class QueryClient {
450
1285
  #private;
451
1286
  constructor(config?: QueryClientConfig);
1287
+ /**
1288
+ * Called by a framework adapter's `QueryClientProvider`-equivalent when it mounts, to start
1289
+ * listening for focus/online events and resume paused mutations. Ref-counted via an internal
1290
+ * mount count, so nested or multiple providers sharing the same `QueryClient` don't tear down
1291
+ * the shared listeners until the last one unmounts.
1292
+ */
452
1293
  mount(): void;
1294
+ /**
1295
+ * The inverse of {@link QueryClient#mount} — called by a framework adapter's
1296
+ * `QueryClientProvider`-equivalent when it unmounts. Only tears down the focus/online
1297
+ * listeners once the mount count returns to `0`.
1298
+ */
453
1299
  unmount(): void;
1300
+ /**
1301
+ * Returns the number of queries in the cache that are currently fetching, optionally
1302
+ * matching a set of filters. This includes background-fetching, loading new pages, and
1303
+ * loading more infinite query results.
1304
+ *
1305
+ * @example
1306
+ * ```ts
1307
+ * if (queryClient.isFetching()) {
1308
+ * console.log('At least one query is fetching!')
1309
+ * }
1310
+ * ```
1311
+ */
454
1312
  isFetching<TQueryFilters extends QueryFilters<any> = QueryFilters>(filters?: TQueryFilters): number;
1313
+ /**
1314
+ * Returns the number of mutations in the cache that are currently pending, optionally
1315
+ * matching a set of filters.
1316
+ *
1317
+ * @example
1318
+ * ```ts
1319
+ * if (queryClient.isMutating()) {
1320
+ * console.log('At least one mutation is pending!')
1321
+ * }
1322
+ * ```
1323
+ */
455
1324
  isMutating<TMutationFilters extends MutationFilters<any, any> = MutationFilters>(filters?: TMutationFilters): number;
456
1325
  /**
457
1326
  * Imperative (non-reactive) way to retrieve data for a QueryKey.
@@ -459,21 +1328,177 @@ declare class QueryClient {
459
1328
  *
460
1329
  * Hint: Do not use this function inside a component, because it won't receive updates.
461
1330
  * Use `useQuery` to create a `QueryObserver` that subscribes to changes.
1331
+ *
1332
+ * @see {@link QueryClient#getQueriesData}
462
1333
  */
463
1334
  getQueryData<TQueryFnData = unknown, TTaggedQueryKey extends QueryKey = QueryKey, TInferredQueryFnData = InferDataFromTag<TQueryFnData, TTaggedQueryKey>>(queryKey: TTaggedQueryKey): TInferredQueryFnData | undefined;
464
1335
  /**
465
1336
  * @deprecated Use queryClient.query({ ...options, staleTime: 'static' }) instead. This method will be removed in the next major version.
466
1337
  */
467
1338
  ensureQueryData<TQueryFnData, TError = DefaultError, TData = TQueryFnData, TQueryKey extends QueryKey = QueryKey>(options: EnsureQueryDataOptions<TQueryFnData, TError, TData, TQueryKey>): Promise<TData>;
1339
+ /**
1340
+ * Imperative (non-reactive) way to retrieve the cached data of multiple queries at once.
1341
+ * Only queries matching the given filters are returned; if none match, an empty array is
1342
+ * returned.
1343
+ *
1344
+ * Because the matched queries can hold data of different shapes (e.g. a broad filter can match
1345
+ * queries with unrelated data types), the `TQueryFnData` generic defaults to `unknown` rather
1346
+ * than being inferred. Passing a more specific type is a convenience for call sites that know
1347
+ * every matched query holds the same shape — it is not checked against the actual cache
1348
+ * contents.
1349
+ *
1350
+ * @see {@link QueryClient#getQueryData}
1351
+ * @example
1352
+ * ```ts
1353
+ * const data = queryClient.getQueriesData({ queryKey: ['posts'] })
1354
+ * ```
1355
+ */
468
1356
  getQueriesData<TQueryFnData = unknown, TQueryFilters extends QueryFilters<any> = QueryFilters>(filters: TQueryFilters): Array<[QueryKey, TQueryFnData | undefined]>;
1357
+ /**
1358
+ * Synchronous way to immediately update a query's cached data. If the updater (or the value
1359
+ * passed) resolves to `undefined`, the cache is left untouched and no query is created;
1360
+ * otherwise, if the query does not exist yet, it will be created. To update multiple queries
1361
+ * at once by partially matching query keys, use {@link QueryClient#setQueriesData} instead.
1362
+ *
1363
+ * Updates must be performed immutably: do not mutate `oldData`, or data previously retrieved
1364
+ * via {@link QueryClient#getQueryData}, in place.
1365
+ *
1366
+ * @param queryKey - The query key to set data for.
1367
+ * @param updater - Either the new data, or a function that receives the current data (which
1368
+ * may be `undefined`) and returns the new data.
1369
+ *
1370
+ * @example
1371
+ * ```ts
1372
+ * queryClient.setQueryData(['posts'], newPosts)
1373
+ *
1374
+ * // Or, using an updater function that receives the current data:
1375
+ * queryClient.setQueryData(['posts'], (oldPosts) => [...oldPosts, newPost])
1376
+ * ```
1377
+ */
469
1378
  setQueryData<TQueryFnData = unknown, TTaggedQueryKey extends QueryKey = QueryKey, TInferredQueryFnData = InferDataFromTag<TQueryFnData, TTaggedQueryKey>>(queryKey: TTaggedQueryKey, updater: Updater<NoInfer<TInferredQueryFnData> | undefined, NoInfer<TInferredQueryFnData> | undefined>, options?: SetDataOptions): NoInfer<TInferredQueryFnData> | undefined;
1379
+ /**
1380
+ * Synchronous way to immediately update the cached data of multiple queries at once, using
1381
+ * filters or partial query key matching. Only queries that already exist and match the given
1382
+ * filters are updated; no new cache entries are created. Internally this calls
1383
+ * {@link QueryClient#setQueryData} for each matching query.
1384
+ *
1385
+ * @example
1386
+ * ```ts
1387
+ * queryClient.setQueriesData({ queryKey: ['posts'] }, (oldPosts) =>
1388
+ * oldPosts ? oldPosts.filter((post) => post.id !== deletedId) : oldPosts,
1389
+ * )
1390
+ * ```
1391
+ */
470
1392
  setQueriesData<TQueryFnData, TQueryFilters extends QueryFilters<any> = QueryFilters>(filters: TQueryFilters, updater: Updater<NoInfer<TQueryFnData> | undefined, NoInfer<TQueryFnData> | undefined>, options?: SetDataOptions): Array<[QueryKey, TQueryFnData | undefined]>;
1393
+ /**
1394
+ * Imperative (non-reactive) way to retrieve an existing query's state. If the query does not
1395
+ * exist, `undefined` is returned.
1396
+ *
1397
+ * @example
1398
+ * ```ts
1399
+ * const state = queryClient.getQueryState(['posts'])
1400
+ * console.log(state?.dataUpdatedAt)
1401
+ * ```
1402
+ */
471
1403
  getQueryState<TQueryFnData = unknown, TError = DefaultError, TTaggedQueryKey extends QueryKey = QueryKey, TInferredQueryFnData = InferDataFromTag<TQueryFnData, TTaggedQueryKey>, TInferredError = InferErrorFromTag<TError, TTaggedQueryKey>>(queryKey: TTaggedQueryKey): QueryState<TInferredQueryFnData, TInferredError> | undefined;
1404
+ /**
1405
+ * Removes queries from the cache that match the given filters. Unlike
1406
+ * {@link QueryClient#invalidateQueries} or {@link QueryClient#refetchQueries}, this removes
1407
+ * matching queries from the cache instead of refetching them. Without filters, every query in
1408
+ * the cache is removed.
1409
+ *
1410
+ * @example
1411
+ * ```ts
1412
+ * queryClient.removeQueries({ queryKey: ['posts'], exact: true })
1413
+ * ```
1414
+ */
472
1415
  removeQueries<TTaggedQueryKey extends QueryKey = QueryKey>(filters?: QueryFilters<TTaggedQueryKey>): void;
1416
+ /**
1417
+ * Resets queries matching the given filters back to their initial state (e.g. any
1418
+ * `initialData`), notifying subscribers rather than removing them. Active queries among the
1419
+ * matched set are then refetched, and the returned promise resolves once that refetch settles.
1420
+ *
1421
+ * @example
1422
+ * ```ts
1423
+ * await queryClient.resetQueries({ queryKey: ['posts'], exact: true })
1424
+ * ```
1425
+ */
473
1426
  resetQueries<TTaggedQueryKey extends QueryKey = QueryKey>(filters?: QueryFilters<TTaggedQueryKey>, options?: ResetOptions): Promise<void>;
1427
+ /**
1428
+ * Cancels outgoing fetches for queries matching the given filters. Most useful when performing
1429
+ * optimistic updates, since any outgoing refetch that resolves afterwards would otherwise
1430
+ * overwrite the optimistic update. By default (`revert: true`), a cancelled query's data is
1431
+ * reverted to its state before the outgoing fetch started.
1432
+ *
1433
+ * The returned promise never rejects, even if individual cancellations fail.
1434
+ *
1435
+ * @example
1436
+ * ```ts
1437
+ * await queryClient.cancelQueries({ queryKey: ['posts'], exact: true })
1438
+ * ```
1439
+ */
474
1440
  cancelQueries<TTaggedQueryKey extends QueryKey = QueryKey>(filters?: QueryFilters<TTaggedQueryKey>, cancelOptions?: CancelOptions): Promise<void>;
1441
+ /**
1442
+ * Marks queries matching the given filters as invalidated. Unlike
1443
+ * {@link QueryClient#removeQueries}, invalidated queries stay in the cache.
1444
+ *
1445
+ * Unless `filters.refetchType` is `'none'`, matching queries are then refetched via
1446
+ * {@link QueryClient#refetchQueries}, using `filters.refetchType` if set, otherwise
1447
+ * `filters.type`, otherwise `'active'`.
1448
+ *
1449
+ * @example
1450
+ * ```ts
1451
+ * await queryClient.invalidateQueries({ queryKey: ['posts'], refetchType: 'active' })
1452
+ * ```
1453
+ */
475
1454
  invalidateQueries<TTaggedQueryKey extends QueryKey = QueryKey>(filters?: InvalidateQueryFilters<TTaggedQueryKey>, options?: InvalidateOptions): Promise<void>;
1455
+ /**
1456
+ * Refetches queries matching the given filters, regardless of whether they are stale. Without
1457
+ * filters, every query in the cache is refetched. Queries that are disabled, or static (only
1458
+ * have observers with a static `staleTime`), are never refetched.
1459
+ *
1460
+ * By default (`cancelRefetch: true`), a currently running fetch is cancelled before the new
1461
+ * one starts. The returned promise resolves once all matching queries have settled; it does
1462
+ * not reject on individual query failures unless `throwOnError` is set.
1463
+ *
1464
+ * @example
1465
+ * ```ts
1466
+ * // refetch all active queries partially matching a query key:
1467
+ * await queryClient.refetchQueries({ queryKey: ['posts'], type: 'active' })
1468
+ * ```
1469
+ */
476
1470
  refetchQueries<TTaggedQueryKey extends QueryKey = QueryKey>(filters?: RefetchQueryFilters<TTaggedQueryKey>, options?: RefetchOptions): Promise<void>;
1471
+ /**
1472
+ * Asynchronous method to fetch and cache a query, resolving with the data or throwing with
1473
+ * the error.
1474
+ *
1475
+ * If the query already exists in the cache and its data is not stale (per the given
1476
+ * `staleTime`), the cached data is returned without fetching. Otherwise, the query is fetched
1477
+ * and the promise resolves once the fetch settles. If a `select` function is provided, it is
1478
+ * applied to the data in both cases (cached or freshly fetched) before it is returned.
1479
+ *
1480
+ * Unlike a reactive observer, retries are disabled by default here (`retry: false`) unless
1481
+ * explicitly configured, since there is no component to catch a thrown error and retry through
1482
+ * re-render.
1483
+ *
1484
+ * The accepted options are `QueryObserverOptions` minus the fields that only make sense for a
1485
+ * reactive observer — `enabled`, `refetchInterval`, `refetchIntervalInBackground`,
1486
+ * `refetchOnWindowFocus`, `refetchOnReconnect`, `refetchOnMount`, `retryOnMount`,
1487
+ * `notifyOnChangeProps`, `throwOnError`, `suspense`, and `placeholderData` are not part of this
1488
+ * method's options.
1489
+ *
1490
+ * This method replaces the deprecated `fetchQuery`, and — combined with
1491
+ * `{ staleTime: 'static' }` — the deprecated `ensureQueryData`.
1492
+ *
1493
+ * @example
1494
+ * ```ts
1495
+ * try {
1496
+ * const data = await queryClient.query({ queryKey, queryFn, staleTime: 10000 })
1497
+ * } catch (error) {
1498
+ * console.log(error)
1499
+ * }
1500
+ * ```
1501
+ */
477
1502
  query<TQueryFnData, TError = DefaultError, TData = TQueryFnData, TQueryData = TQueryFnData, TQueryKey extends QueryKey = QueryKey, TPageParam = never>(options: QueryExecuteOptions<TQueryFnData, TError, TData, TQueryData, TQueryKey, TPageParam>): Promise<TData>;
478
1503
  /**
479
1504
  * @deprecated Use queryClient.query(options) instead. This method will be removed in the next major version.
@@ -483,6 +1508,27 @@ declare class QueryClient {
483
1508
  * @deprecated Use queryClient.query(options) instead. You can swallow errors with `.catch(noop)`. This method will be removed in the next major version.
484
1509
  */
485
1510
  prefetchQuery<TQueryFnData = unknown, TError = DefaultError, TData = TQueryFnData, TQueryKey extends QueryKey = QueryKey>(options: FetchQueryOptions<TQueryFnData, TError, TData, TQueryKey>): Promise<void>;
1511
+ /**
1512
+ * Asynchronous method to fetch and cache an infinite query, resolving with an
1513
+ * {@link InfiniteData} object or throwing with the error.
1514
+ *
1515
+ * Behaves like {@link QueryClient#query}, accepting the same options (minus
1516
+ * `initialPageParam`), plus the required `initialPageParam`, and an optional `pages` /
1517
+ * `getNextPageParam` pair used to refetch a fixed number of pages from the start.
1518
+ *
1519
+ * This method replaces the deprecated `fetchInfiniteQuery`, and — combined with
1520
+ * `{ staleTime: 'static' }` — the deprecated `ensureInfiniteQueryData`.
1521
+ *
1522
+ * @example
1523
+ * ```ts
1524
+ * try {
1525
+ * const data = await queryClient.infiniteQuery({ queryKey, queryFn, initialPageParam: 0 })
1526
+ * console.log(data.pages)
1527
+ * } catch (error) {
1528
+ * console.log(error)
1529
+ * }
1530
+ * ```
1531
+ */
486
1532
  infiniteQuery<TQueryFnData, TError = DefaultError, TData = InfiniteData<TQueryFnData>, TQueryKey extends QueryKey = QueryKey, TPageParam = unknown>(options: InfiniteQueryExecuteOptions<TQueryFnData, TError, TData, TQueryKey, TPageParam>): Promise<Array<TData> extends Array<InfiniteData<TQueryFnData>> ? InfiniteData<TQueryFnData, TPageParam> : TData>;
487
1533
  /**
488
1534
  * @deprecated Use queryClient.infiniteQuery(options) instead. This method will be removed in the next major version.
@@ -496,17 +1542,151 @@ declare class QueryClient {
496
1542
  * @deprecated Use queryClient.infiniteQuery({ ...options, staleTime: 'static' }) instead. This method will be removed in the next major version.
497
1543
  */
498
1544
  ensureInfiniteQueryData<TQueryFnData, TError = DefaultError, TData = TQueryFnData, TQueryKey extends QueryKey = QueryKey, TPageParam = unknown>(options: EnsureInfiniteQueryDataOptions<TQueryFnData, TError, TData, TQueryKey, TPageParam>): Promise<InfiniteData<TData, TPageParam>>;
1545
+ /**
1546
+ * Resumes mutations that were paused because there was no network connection. Does nothing
1547
+ * (resolving immediately) if the client is currently offline.
1548
+ *
1549
+ * @example
1550
+ * ```ts
1551
+ * import { QueryClient } from '@tanstack/query-core'
1552
+ *
1553
+ * const queryClient = new QueryClient()
1554
+ * await queryClient.resumePausedMutations()
1555
+ * ```
1556
+ */
499
1557
  resumePausedMutations(): Promise<unknown>;
1558
+ /**
1559
+ * Returns the query cache this client is connected to.
1560
+ *
1561
+ * @example
1562
+ * ```ts
1563
+ * import { QueryClient } from '@tanstack/query-core'
1564
+ *
1565
+ * const queryClient = new QueryClient()
1566
+ * const queryCache = queryClient.getQueryCache()
1567
+ * const queries = queryCache.findAll({ queryKey: ['posts'] })
1568
+ * ```
1569
+ */
500
1570
  getQueryCache(): QueryCache;
1571
+ /**
1572
+ * Returns the mutation cache this client is connected to.
1573
+ *
1574
+ * @example
1575
+ * ```ts
1576
+ * import { QueryClient } from '@tanstack/query-core'
1577
+ *
1578
+ * const queryClient = new QueryClient()
1579
+ * const mutationCache = queryClient.getMutationCache()
1580
+ * const mutations = mutationCache.findAll({ status: 'pending' })
1581
+ * ```
1582
+ */
501
1583
  getMutationCache(): MutationCache;
1584
+ /**
1585
+ * Returns the default options that were set when creating the client, or via
1586
+ * {@link QueryClient#setDefaultOptions}.
1587
+ *
1588
+ * @example
1589
+ * ```ts
1590
+ * import { QueryClient } from '@tanstack/query-core'
1591
+ *
1592
+ * const queryClient = new QueryClient()
1593
+ * const defaultOptions = queryClient.getDefaultOptions()
1594
+ * ```
1595
+ */
502
1596
  getDefaultOptions(): DefaultOptions;
1597
+ /**
1598
+ * Dynamically sets the default options for this client, overwriting any previously defined
1599
+ * default options.
1600
+ *
1601
+ * @see {@link QueryClient#getDefaultOptions}
1602
+ * @example
1603
+ * ```ts
1604
+ * import { QueryClient } from '@tanstack/query-core'
1605
+ *
1606
+ * const queryClient = new QueryClient()
1607
+ * queryClient.setDefaultOptions({
1608
+ * queries: {
1609
+ * staleTime: Infinity,
1610
+ * },
1611
+ * })
1612
+ * ```
1613
+ */
503
1614
  setDefaultOptions(options: DefaultOptions): void;
1615
+ /**
1616
+ * Sets default options for queries whose query key partially matches the given `queryKey`.
1617
+ *
1618
+ * If several registered query defaults match a given query key, they are merged together in
1619
+ * registration order by {@link QueryClient#getQueryDefaults}, so register defaults from the
1620
+ * most generic key to the least generic one — more specific defaults should be registered
1621
+ * after more generic ones so they take precedence.
1622
+ *
1623
+ * @example
1624
+ * ```ts
1625
+ * queryClient.setQueryDefaults(['posts'], { queryFn: fetchPosts })
1626
+ *
1627
+ * await queryClient.query({ queryKey: ['posts'] })
1628
+ * ```
1629
+ */
504
1630
  setQueryDefaults<TQueryFnData = unknown, TError = DefaultError, TData = TQueryFnData, TQueryData = TQueryFnData>(queryKey: QueryKey, options: Partial<OmitKeyof<QueryObserverOptions<TQueryFnData, TError, TData, TQueryData>, 'queryKey'>>): void;
1631
+ /**
1632
+ * Returns the default options registered for queries whose query key partially matches the
1633
+ * given `queryKey`, via {@link QueryClient#setQueryDefaults}. If multiple registered defaults
1634
+ * match, they are merged together in registration order.
1635
+ *
1636
+ * @example
1637
+ * ```ts
1638
+ * const defaultOptions = queryClient.getQueryDefaults(['posts'])
1639
+ * ```
1640
+ */
505
1641
  getQueryDefaults(queryKey: QueryKey): OmitKeyof<QueryObserverOptions<any, any, any, any, any>, 'queryKey'>;
1642
+ /**
1643
+ * Sets default options for mutations whose mutation key partially matches the given
1644
+ * `mutationKey`. As with {@link QueryClient#setQueryDefaults}, the order of registration
1645
+ * matters when several registered defaults match the same mutation key.
1646
+ *
1647
+ * @see {@link QueryClient#getMutationDefaults}
1648
+ * @example
1649
+ * ```ts
1650
+ * queryClient.setMutationDefaults(['addPost'], { mutationFn: addPost })
1651
+ * ```
1652
+ */
506
1653
  setMutationDefaults<TData = unknown, TError = DefaultError, TVariables = void, TOnMutateResult = unknown>(mutationKey: MutationKey, options: OmitKeyof<MutationObserverOptions<TData, TError, TVariables, TOnMutateResult>, 'mutationKey'>): void;
1654
+ /**
1655
+ * Returns the default options registered for mutations whose mutation key partially matches
1656
+ * the given `mutationKey`, via {@link QueryClient#setMutationDefaults}. If multiple registered
1657
+ * defaults match, they are merged together in registration order.
1658
+ *
1659
+ * @example
1660
+ * ```ts
1661
+ * const defaultOptions = queryClient.getMutationDefaults(['addPost'])
1662
+ * ```
1663
+ */
507
1664
  getMutationDefaults(mutationKey: MutationKey): OmitKeyof<MutationObserverOptions<any, any, any, any>, 'mutationKey'>;
1665
+ /**
1666
+ * Called by framework adapters (e.g. inside `useQuery`) to resolve the options passed by the
1667
+ * caller into their final, defaulted form: merging `queryClient.setQueryDefaults` for the
1668
+ * given `queryKey`, then the client's own `defaultOptions.queries`, then the caller's options
1669
+ * on top. A no-op if the options are already defaulted (`_defaulted: true`).
1670
+ */
508
1671
  defaultQueryOptions<TQueryFnData = unknown, TError = DefaultError, TData = TQueryFnData, TQueryData = TQueryFnData, TQueryKey extends QueryKey = QueryKey, TPageParam = never>(options: QueryObserverOptions<TQueryFnData, TError, TData, TQueryData, TQueryKey, TPageParam> | DefaultedQueryObserverOptions<TQueryFnData, TError, TData, TQueryData, TQueryKey>): DefaultedQueryObserverOptions<TQueryFnData, TError, TData, TQueryData, TQueryKey>;
1672
+ /**
1673
+ * The mutation counterpart of {@link QueryClient#defaultQueryOptions}. Called by framework
1674
+ * adapters (e.g. inside `useMutation`) to merge `queryClient.setMutationDefaults` for the
1675
+ * given `mutationKey`, then the client's `defaultOptions.mutations`, then the caller's options
1676
+ * on top. A no-op if the options are already defaulted (`_defaulted: true`).
1677
+ */
509
1678
  defaultMutationOptions<T extends MutationOptions<any, any, any, any>>(options?: T): T;
1679
+ /**
1680
+ * Clears both the query cache and the mutation cache this client is connected to.
1681
+ *
1682
+ * @example
1683
+ * ```ts
1684
+ * import { QueryClient } from '@tanstack/query-core'
1685
+ *
1686
+ * const queryClient = new QueryClient()
1687
+ * queryClient.clear()
1688
+ * ```
1689
+ */
510
1690
  clear(): void;
511
1691
  }
512
1692
  //#endregion
@@ -538,6 +1718,24 @@ type ShouldRetryFunction<TError = DefaultError> = (failureCount: number, error:
538
1718
  type RetryDelayValue<TError> = number | RetryDelayFunction<TError>;
539
1719
  type RetryDelayFunction<TError = DefaultError> = (failureCount: number, error: TError) => number;
540
1720
  declare function canFetch(networkMode: NetworkMode | undefined): boolean;
1721
+ /**
1722
+ * The error thrown by a `Retryer` (and surfaced to `query.promise`/`mutation`) when a fetch is cancelled, e.g. via
1723
+ * `query.cancel()`. `revert`, if `true`, tells the caller to restore the state the query was in before the fetch
1724
+ * started instead of surfacing the error. `silent`, if `true`, tells the caller to suppress this error and instead
1725
+ * resolve with the promise of the fetch that triggered the cancellation.
1726
+ * @example
1727
+ * ```ts
1728
+ * query.cancel()
1729
+ *
1730
+ * try {
1731
+ * await query.promise
1732
+ * } catch (error) {
1733
+ * if (error instanceof CancelledError) {
1734
+ * // the fetch was cancelled, e.g. via `query.cancel()`
1735
+ * }
1736
+ * }
1737
+ * ```
1738
+ */
541
1739
  declare class CancelledError extends Error {
542
1740
  revert?: boolean;
543
1741
  silent?: boolean;
@@ -630,32 +1828,97 @@ interface QueryOptions<TQueryFnData = unknown, TError = DefaultError, TData = TQ
630
1828
  * If `true`, failed queries will retry infinitely.
631
1829
  * If set to an integer number, e.g. 3, failed queries will retry until the failed query count meets that number.
632
1830
  * If set to a function `(failureCount, error) => boolean` failed queries will retry until the function returns false.
1831
+ *
1832
+ * Defaults to `3` on the client and `0` on the server.
633
1833
  */
634
1834
  retry?: RetryValue<TError>;
1835
+ /**
1836
+ * This function receives a `retryAttempt` integer and the actual Error and returns the delay to apply before the
1837
+ * next attempt in milliseconds.
1838
+ *
1839
+ * A function like `attempt => Math.min(attempt > 1 ? 2 ** attempt * 1000 : 1000, 30 * 1000)` applies exponential
1840
+ * backoff.
1841
+ *
1842
+ * A function like `attempt => attempt * 1000` applies linear backoff.
1843
+ *
1844
+ * Defaults to a function that applies exponential backoff, capped at 30 seconds.
1845
+ */
635
1846
  retryDelay?: RetryDelayValue<TError>;
1847
+ /**
1848
+ * Controls whether a query is allowed to run based on the current network connectivity.
1849
+ *
1850
+ * Defaults to `'online'`.
1851
+ * @see [Network Mode](https://tanstack.com/query/latest/docs/framework/react/guides/network-mode) for more information.
1852
+ */
636
1853
  networkMode?: NetworkMode;
637
1854
  /**
638
1855
  * The time in milliseconds that unused/inactive cache data remains in memory.
639
1856
  * When a query's cache becomes unused or inactive, that cache data will be garbage collected after this duration.
640
1857
  * When different garbage collection times are specified, the longest one will be used.
641
1858
  * Setting it to `Infinity` will disable garbage collection.
1859
+ *
1860
+ * Defaults to `5 * 60 * 1000` (5 minutes), or `Infinity` during SSR.
1861
+ *
1862
+ * Note: the maximum allowed time is about 24 days, imposed by `setTimeout`'s 32-bit signed integer delay — see
1863
+ * `timeoutManager.setTimeoutProvider` for a workaround.
642
1864
  */
643
1865
  gcTime?: number;
1866
+ /**
1867
+ * The function that the query will use to request data.
1868
+ * Required, unless a default query function has been set via `queryClient.setQueryDefaults` or
1869
+ * `queryClient.setDefaultOptions`.
1870
+ * Receives a {@link QueryFunctionContext}.
1871
+ * Must return a promise that will either resolve data or throw an error. The data cannot be `undefined`.
1872
+ */
644
1873
  queryFn?: QueryFunction<TQueryFnData, TQueryKey, TPageParam> | SkipToken;
1874
+ /**
1875
+ * This option can be used to persist the result of a query to an external storage, bypassing the need to actually
1876
+ * call the `queryFn`. Useful for persisting a query's data across e.g. server/client boundaries.
1877
+ */
645
1878
  persister?: QueryPersister<TQueryFnData, NoInfer<TQueryKey>, TPageParam>;
1879
+ /**
1880
+ * The hashed form of `queryKey`, computed with `queryKeyHashFn` (or the default hashing function otherwise). Used
1881
+ * as the actual cache key internally.
1882
+ */
646
1883
  queryHash?: string;
1884
+ /**
1885
+ * The query key to use for this query.
1886
+ *
1887
+ * The query key will be hashed into a stable hash. See [Query Keys](https://tanstack.com/query/latest/docs/framework/react/guides/query-keys)
1888
+ * for more information.
1889
+ *
1890
+ * The query will automatically update when this key changes (as long as `enabled` is not set to `false`).
1891
+ */
647
1892
  queryKey?: TQueryKey;
1893
+ /**
1894
+ * If specified, this function is used to hash the `queryKey` to a string.
1895
+ */
648
1896
  queryKeyHashFn?: QueryKeyHashFunction<TQueryKey>;
1897
+ /**
1898
+ * If set, this value will be used as the initial data for the query cache (as long as the query hasn't been
1899
+ * created or cached yet).
1900
+ * If set to a function, the function will be called **once** during the shared/root query initialization, and be
1901
+ * expected to synchronously return the initial data.
1902
+ * Initial data is considered stale by default unless a `staleTime` has been set.
1903
+ * `initialData` **is persisted** to the cache.
1904
+ */
649
1905
  initialData?: TData | InitialDataFunction<TData>;
1906
+ /**
1907
+ * If set, this value will be used as the time (in milliseconds) of when the `initialData` itself was last updated.
1908
+ */
650
1909
  initialDataUpdatedAt?: number | (() => number | undefined);
1910
+ /** @internal */
651
1911
  behavior?: QueryBehavior<TQueryFnData, TError, TData, TQueryKey>;
652
1912
  /**
653
1913
  * Set this to `false` to disable structural sharing between query results.
654
1914
  * Set this to a function which accepts the old and new data and returns resolved data of the same type to implement custom structural sharing logic.
1915
+ *
655
1916
  * Defaults to `true`.
656
1917
  */
657
1918
  structuralSharing?: boolean | ((oldData: unknown | undefined, newData: unknown) => unknown);
1919
+ /** @internal */
658
1920
  _defaulted?: boolean;
1921
+ /** @internal */
659
1922
  _type?: 'infinite';
660
1923
  /**
661
1924
  * Additional payload to be stored on each query.
@@ -688,54 +1951,63 @@ interface QueryObserverOptions<TQueryFnData = unknown, TError = DefaultError, TD
688
1951
  * Set this to `false` or a function that returns `false` to disable automatic refetching when the query mounts or changes query keys.
689
1952
  * To refetch the query, use the `refetch` method returned from the `useQuery` instance.
690
1953
  * Accepts a boolean or function that returns a boolean.
1954
+ *
691
1955
  * Defaults to `true`.
692
1956
  */
693
1957
  enabled?: QueryBooleanOption<TQueryFnData, TError, TQueryData, TQueryKey>;
694
1958
  /**
695
1959
  * The time in milliseconds after data is considered stale.
696
1960
  * If set to `Infinity`, the data will never be considered stale.
1961
+ * If set to `'static'`, the data will never be considered stale.
697
1962
  * If set to a function, the function will be executed with the query to compute a `staleTime`.
1963
+ *
698
1964
  * Defaults to `0`.
699
1965
  */
700
1966
  staleTime?: StaleTimeFunction<TQueryFnData, TError, TQueryData, TQueryKey>;
701
1967
  /**
702
1968
  * If set to a number, the query will continuously refetch at this frequency in milliseconds.
703
1969
  * If set to a function, the function will be executed with the latest data and query to compute a frequency
1970
+ *
704
1971
  * Defaults to `false`.
705
1972
  */
706
1973
  refetchInterval?: number | false | ((query: Query<TQueryFnData, TError, TQueryData, TQueryKey>) => number | false | undefined);
707
1974
  /**
708
1975
  * If set to `true`, the query will continue to refetch while their tab/window is in the background.
1976
+ *
709
1977
  * Defaults to `false`.
710
1978
  */
711
1979
  refetchIntervalInBackground?: boolean;
712
1980
  /**
713
1981
  * If set to `true`, the query will refetch on window focus if the data is stale.
714
1982
  * If set to `false`, the query will not refetch on window focus.
715
- * If set to `'always'`, the query will always refetch on window focus.
1983
+ * If set to `'always'`, the query will always refetch on window focus (except when `staleTime: 'static'` is used).
716
1984
  * If set to a function, the function will be executed with the latest data and query to compute the value.
1985
+ *
717
1986
  * Defaults to `true`.
718
1987
  */
719
1988
  refetchOnWindowFocus?: boolean | 'always' | ((query: Query<TQueryFnData, TError, TQueryData, TQueryKey>) => boolean | 'always');
720
1989
  /**
721
1990
  * If set to `true`, the query will refetch on reconnect if the data is stale.
722
1991
  * If set to `false`, the query will not refetch on reconnect.
723
- * If set to `'always'`, the query will always refetch on reconnect.
1992
+ * If set to `'always'`, the query will always refetch on reconnect (except when `staleTime: 'static'` is used).
724
1993
  * If set to a function, the function will be executed with the latest data and query to compute the value.
1994
+ *
725
1995
  * Defaults to `true` unless `networkMode` is `'always'`.
726
1996
  */
727
1997
  refetchOnReconnect?: boolean | 'always' | ((query: Query<TQueryFnData, TError, TQueryData, TQueryKey>) => boolean | 'always');
728
1998
  /**
729
1999
  * If set to `true`, the query will refetch on mount if the data is stale.
730
2000
  * If set to `false`, will disable additional instances of a query to trigger background refetch.
731
- * If set to `'always'`, the query will always refetch on mount.
2001
+ * If set to `'always'`, the query will always refetch on mount (except when `staleTime: 'static'` is used).
732
2002
  * If set to a function, the function will be executed with the latest data and query to compute the value
2003
+ *
733
2004
  * Defaults to `true`.
734
2005
  */
735
2006
  refetchOnMount?: boolean | 'always' | ((query: Query<TQueryFnData, TError, TQueryData, TQueryKey>) => boolean | 'always');
736
2007
  /**
737
2008
  * If set to `false`, the query will not be retried on mount if it contains an error.
738
2009
  * If set to a function, the function will be executed with the query to compute the value.
2010
+ *
739
2011
  * Defaults to `true`.
740
2012
  */
741
2013
  retryOnMount?: QueryBooleanOption<TQueryFnData, TError, TQueryData, TQueryKey>;
@@ -744,7 +2016,9 @@ interface QueryObserverOptions<TQueryFnData = unknown, TError = DefaultError, TD
744
2016
  * When set to `['data', 'error']`, the component will only re-render when the `data` or `error` properties change.
745
2017
  * When set to `'all'`, the component will re-render whenever a query is updated.
746
2018
  * When set to a function, the function will be executed to compute the list of properties.
747
- * By default, access to properties will be tracked, and the component will only re-render when one of the tracked properties change.
2019
+ *
2020
+ * Defaults to `undefined`, in which case property access is tracked automatically, and the
2021
+ * component only re-renders when one of the tracked properties changes.
748
2022
  */
749
2023
  notifyOnChangeProps?: NotifyOnChangeProps;
750
2024
  /**
@@ -752,16 +2026,21 @@ interface QueryObserverOptions<TQueryFnData = unknown, TError = DefaultError, TD
752
2026
  * If set to `true` or `suspense` is `true`, all errors will be thrown to the error boundary.
753
2027
  * If set to `false` and `suspense` is `false`, errors are returned as state.
754
2028
  * If set to a function, it will be passed the error and the query, and it should return a boolean indicating whether to show the error in an error boundary (`true`) or return the error as state (`false`).
2029
+ *
755
2030
  * Defaults to `false`.
756
2031
  */
757
2032
  throwOnError?: ThrowOnError<TQueryFnData, TError, TQueryData, TQueryKey>;
758
2033
  /**
759
- * This option can be used to transform or select a part of the data returned by the query function.
2034
+ * This option can be used to transform or select a part of the data returned by the query function. It affects
2035
+ * the returned `data` value, but does not affect what gets stored in the query cache.
2036
+ * The `select` function will only run if `data` changed, or if the reference to the `select` function itself
2037
+ * changes. To optimize, memoize the function so its reference stays stable across calls.
760
2038
  */
761
2039
  select?: (data: TQueryData) => TData;
762
2040
  /**
763
2041
  * If set to `true`, the query will suspend when `status === 'pending'`
764
2042
  * and throw errors when `status === 'error'`.
2043
+ *
765
2044
  * Defaults to `false`.
766
2045
  */
767
2046
  suspense?: boolean;
@@ -769,6 +2048,7 @@ interface QueryObserverOptions<TQueryFnData = unknown, TError = DefaultError, TD
769
2048
  * If set, this value will be used as the placeholder data for this particular query observer while the query is still in the `loading` data and no initialData has been provided.
770
2049
  */
771
2050
  placeholderData?: NonFunctionGuard<TQueryData> | PlaceholderDataFunction<NonFunctionGuard<TQueryData>, TError, NonFunctionGuard<TQueryData>, TQueryKey>;
2051
+ /** @internal */
772
2052
  _optimisticResults?: 'optimistic' | 'isRestoring';
773
2053
  }
774
2054
  type WithRequired<TTarget, TKey extends keyof TTarget> = TTarget & { [_ in TKey]: {}; };
@@ -811,6 +2091,12 @@ type InfiniteQueryExecuteOptions<TQueryFnData = unknown, TError = DefaultError,
811
2091
  /** @deprecated */
812
2092
  type FetchInfiniteQueryOptions<TQueryFnData = unknown, TError = DefaultError, TData = TQueryFnData, TQueryKey extends QueryKey = QueryKey, TPageParam = unknown> = Omit<FetchQueryOptions<TQueryFnData, TError, InfiniteData<TData, TPageParam>, TQueryKey, TPageParam>, 'initialPageParam'> & InitialPageParam<TPageParam> & InfiniteQueryPages<TQueryFnData, TPageParam>;
813
2093
  interface ResultOptions {
2094
+ /**
2095
+ * If set to `true`, the method throws if any of the underlying query refetch tasks fail.
2096
+ *
2097
+ * Defaults to `false`, in which case failed refetches are swallowed and not surfaced to the
2098
+ * caller.
2099
+ */
814
2100
  throwOnError?: boolean;
815
2101
  }
816
2102
  interface RefetchOptions extends ResultOptions {
@@ -824,6 +2110,15 @@ interface RefetchOptions extends ResultOptions {
824
2110
  cancelRefetch?: boolean;
825
2111
  }
826
2112
  interface InvalidateQueryFilters<TQueryKey extends QueryKey = QueryKey> extends QueryFilters<TQueryKey> {
2113
+ /**
2114
+ * Controls which of the matched (now-invalidated) queries are refetched in the background.
2115
+ *
2116
+ * Defaults to `'active'`.
2117
+ * - `'active'`: only queries with at least one active observer are refetched.
2118
+ * - `'inactive'`: only queries with no active observer are refetched.
2119
+ * - `'all'`: every matched query is refetched, active or not.
2120
+ * - `'none'`: no query is refetched; matched queries are only marked as invalidated.
2121
+ */
827
2122
  refetchType?: QueryTypeFilter | 'none';
828
2123
  }
829
2124
  interface RefetchQueryFilters<TQueryKey extends QueryKey = QueryKey> extends QueryFilters<TQueryKey> {}
@@ -1188,15 +2483,50 @@ interface MutationOptions<TData = unknown, TError = DefaultError, TVariables = v
1188
2483
  onSuccess?: (data: TData, variables: TVariables, onMutateResult: TOnMutateResult, context: MutationFunctionContext) => Promise<unknown> | unknown;
1189
2484
  onError?: (error: TError, variables: TVariables, onMutateResult: TOnMutateResult | undefined, context: MutationFunctionContext) => Promise<unknown> | unknown;
1190
2485
  onSettled?: (data: TData | undefined, error: TError | null, variables: TVariables, onMutateResult: TOnMutateResult | undefined, context: MutationFunctionContext) => Promise<unknown> | unknown;
2486
+ /**
2487
+ * If `false`, failed mutations will not retry by default.
2488
+ * If `true`, failed mutations will retry infinitely.
2489
+ * If set to an integer number, e.g. 3, failed mutations will retry until the failed mutation count meets that number.
2490
+ * If set to a function `(failureCount, error) => boolean` failed mutations will retry until the function returns false.
2491
+ *
2492
+ * Defaults to `0`.
2493
+ */
1191
2494
  retry?: RetryValue<TError>;
2495
+ /**
2496
+ * This function receives a `retryAttempt` integer and the actual Error and returns the delay to apply before the
2497
+ * next attempt in milliseconds.
2498
+ *
2499
+ * Defaults to a function that applies exponential backoff, capped at 30 seconds.
2500
+ */
1192
2501
  retryDelay?: RetryDelayValue<TError>;
2502
+ /**
2503
+ * Controls whether a mutation is allowed to run based on the current network connectivity.
2504
+ *
2505
+ * Defaults to `'online'`.
2506
+ * @see [Network Mode](https://tanstack.com/query/latest/docs/framework/react/guides/network-mode) for more information.
2507
+ */
1193
2508
  networkMode?: NetworkMode;
2509
+ /**
2510
+ * The time in milliseconds that an unused/inactive mutation remains in memory before it is
2511
+ * garbage collected.
2512
+ *
2513
+ * Defaults to `5 * 60 * 1000` (5 minutes), or `Infinity` during SSR.
2514
+ */
1194
2515
  gcTime?: number;
2516
+ /** @internal */
1195
2517
  _defaulted?: boolean;
1196
2518
  meta?: MutationMeta;
1197
2519
  scope?: MutationScope;
1198
2520
  }
1199
2521
  interface MutationObserverOptions<TData = unknown, TError = DefaultError, TVariables = void, TOnMutateResult = unknown> extends MutationOptions<TData, TError, TVariables, TOnMutateResult> {
2522
+ /**
2523
+ * Whether errors should be thrown instead of setting the `error` property.
2524
+ * If set to `true`, all errors will be thrown to the nearest error boundary.
2525
+ * If set to a function, it will be passed the error and should return a boolean indicating whether to throw the
2526
+ * error (`true`) or return it as state (`false`).
2527
+ *
2528
+ * Defaults to `false`.
2529
+ */
1200
2530
  throwOnError?: boolean | ((error: TError) => boolean);
1201
2531
  }
1202
2532
  interface MutateOptions<TData = unknown, TError = DefaultError, TVariables = void, TOnMutateResult = unknown> {
@@ -1307,14 +2637,24 @@ interface MutationObserverSuccessResult<TData = unknown, TError = DefaultError,
1307
2637
  }
1308
2638
  type MutationObserverResult<TData = unknown, TError = DefaultError, TVariables = void, TOnMutateResult = unknown> = MutationObserverIdleResult<TData, TError, TVariables, TOnMutateResult> | MutationObserverLoadingResult<TData, TError, TVariables, TOnMutateResult> | MutationObserverErrorResult<TData, TError, TVariables, TOnMutateResult> | MutationObserverSuccessResult<TData, TError, TVariables, TOnMutateResult>;
1309
2639
  interface QueryClientConfig {
2640
+ /** The query cache this client is connected to. A new `QueryCache` is created if not provided. */
1310
2641
  queryCache?: QueryCache;
2642
+ /**
2643
+ * The mutation cache this client is connected to. A new `MutationCache` is created if not
2644
+ * provided.
2645
+ */
1311
2646
  mutationCache?: MutationCache;
2647
+ /** Default options for all queries and mutations created through this client. */
1312
2648
  defaultOptions?: DefaultOptions;
1313
2649
  }
1314
2650
  interface DefaultOptions<TError = DefaultError> {
2651
+ /** Default options applied to every query, unless overridden per-query. */
1315
2652
  queries?: OmitKeyof<QueryObserverOptions<unknown, TError>, 'suspense' | 'queryKey'>;
2653
+ /** Default options applied to every mutation, unless overridden per-mutation. */
1316
2654
  mutations?: MutationObserverOptions<unknown, TError, unknown, unknown>;
2655
+ /** Default options used when hydrating queries; see {@link HydrateOptions}. */
1317
2656
  hydrate?: HydrateOptions['defaultOptions'];
2657
+ /** Default options used when dehydrating the client's caches; see {@link DehydrateOptions}. */
1318
2658
  dehydrate?: DehydrateOptions;
1319
2659
  }
1320
2660
  interface CancelOptions {
@@ -1331,16 +2671,35 @@ interface NotifyEvent {
1331
2671
  //#endregion
1332
2672
  //#region src/hydration.d.ts
1333
2673
  type TransformerFn = (data: any) => any;
2674
+ /**
2675
+ * Options for `dehydrate`, controlling which queries/mutations are included in the resulting `DehydratedState` and
2676
+ * how their data/errors are transformed before being serialized (e.g. for embedding in server-rendered markup).
2677
+ */
1334
2678
  interface DehydrateOptions {
2679
+ /** Transforms a query's `data` before it is dehydrated. Useful for non-JSON-serializable data. */
1335
2680
  serializeData?: TransformerFn;
2681
+ /** Predicate to decide whether a given `Mutation` should be dehydrated. Defaults to `defaultShouldDehydrateMutation`. */
1336
2682
  shouldDehydrateMutation?: (mutation: Mutation) => boolean;
2683
+ /** Predicate to decide whether a given `Query` should be dehydrated. Defaults to `defaultShouldDehydrateQuery`. */
1337
2684
  shouldDehydrateQuery?: (query: Query) => boolean;
2685
+ /**
2686
+ * Predicate to decide whether a query's error should be redacted before dehydration. Errors are redacted
2687
+ * (replaced with a generic `Error('redacted')`) unless this function is provided and returns `false` for the
2688
+ * given error, in which case the original error is kept.
2689
+ */
1338
2690
  shouldRedactErrors?: (error: unknown) => boolean;
1339
2691
  }
2692
+ /**
2693
+ * Options for `hydrate`, controlling the default options applied to queries/mutations restored from a
2694
+ * `DehydratedState`, and how to reverse any transformation applied by `DehydrateOptions.serializeData`.
2695
+ */
1340
2696
  interface HydrateOptions {
1341
2697
  defaultOptions?: {
2698
+ /** Transforms a query's `data` after it is read from the dehydrated state, reversing `serializeData`. */
1342
2699
  deserializeData?: TransformerFn;
2700
+ /** Default options merged into every query restored from the dehydrated state. */
1343
2701
  queries?: QueryOptions;
2702
+ /** Default options merged into every mutation restored from the dehydrated state. */
1344
2703
  mutations?: MutationOptions<unknown, DefaultError, unknown, unknown>;
1345
2704
  };
1346
2705
  }
@@ -1354,20 +2713,78 @@ interface DehydratedQuery {
1354
2713
  queryHash: string;
1355
2714
  queryKey: QueryKey;
1356
2715
  state: QueryState;
2716
+ dehydratedAt: number;
1357
2717
  promise?: Promise<unknown>;
1358
2718
  meta?: QueryMeta;
1359
2719
  queryType?: 'infinite';
1360
- dehydratedAt?: number;
1361
2720
  }
2721
+ /**
2722
+ * A serializable snapshot of a `QueryClient`'s cache, as produced by `dehydrate` and consumed by `hydrate`. Typically
2723
+ * transported from server to client (e.g. embedded in server-rendered markup) to seed the client's cache with data
2724
+ * that has already been fetched, avoiding a redundant fetch on the client.
2725
+ */
1362
2726
  interface DehydratedState {
1363
2727
  mutations: Array<DehydratedMutation>;
1364
2728
  queries: Array<DehydratedQuery>;
1365
2729
  }
2730
+ /**
2731
+ * Dehydrates a single `Query` into a serializable `DehydratedQuery` snapshot. Note that most query config (e.g.
2732
+ * `queryFn`, `staleTime`) is not dehydrated but instead meant to be configured again when consuming the
2733
+ * de/rehydrated data, typically with `useQuery` on the client. If the query is still `pending`, its in-flight
2734
+ * promise is dehydrated too so it can be resumed on the other side instead of re-fetched.
2735
+ * @param query - The query to dehydrate.
2736
+ * @param serializeData - Optional transform applied to `query.state.data` before it is included in the snapshot.
2737
+ * @param shouldRedactErrors - Optional predicate; if it returns `false` for the promise's rejection error, that
2738
+ * error is kept as-is instead of being redacted.
2739
+ */
1366
2740
  declare function dehydrateQuery(query: Query, serializeData?: TransformerFn, shouldRedactErrors?: (error: unknown) => boolean): DehydratedQuery;
2741
+ /**
2742
+ * The default `shouldDehydrateMutation` predicate used by `dehydrate`. Only dehydrates mutations that are
2743
+ * currently paused (e.g. paused by `networkMode` while offline).
2744
+ */
1367
2745
  declare function defaultShouldDehydrateMutation(mutation: Mutation): boolean;
2746
+ /**
2747
+ * The default `shouldDehydrateQuery` predicate used by `dehydrate`. Only dehydrates queries whose status is
2748
+ * `'success'`.
2749
+ */
1368
2750
  declare function defaultShouldDehydrateQuery(query: Query): boolean;
2751
+ /**
2752
+ * Dehydrates a `QueryClient`'s cache (queries and mutations) into a plain, serializable `DehydratedState`,
2753
+ * typically to embed in server-rendered markup and later restore into a client-side `QueryClient` via `hydrate`.
2754
+ * Which queries/mutations are included, and how their data/errors are transformed, is controlled by `options`,
2755
+ * falling back to the client's `dehydrate` default options, and finally to `defaultShouldDehydrateQuery` /
2756
+ * `defaultShouldDehydrateMutation`.
2757
+ * @example
2758
+ * ```ts
2759
+ * const queryClient = new QueryClient()
2760
+ *
2761
+ * await queryClient.prefetchQuery({
2762
+ * queryKey: ['posts'],
2763
+ * queryFn: getPosts,
2764
+ * })
2765
+ *
2766
+ * const dehydratedState = dehydrate(queryClient)
2767
+ * ```
2768
+ */
1369
2769
  declare function dehydrate(client: QueryClient, options?: DehydrateOptions): DehydratedState;
2770
+ /**
2771
+ * Restores a `DehydratedState` (as produced by `dehydrate`) into a `QueryClient`'s cache, typically to seed the
2772
+ * client with data already fetched on the server. `mutations` and `queries` are each optional on `dehydratedState`.
2773
+ * Queries not yet in the cache are built from the dehydrated snapshot; queries that already exist are only updated
2774
+ * when the dehydrated data is newer than what's already cached. Newly built queries have their `fetchStatus` reset
2775
+ * to `'idle'` so they don't hydrate stuck in a fetching state. If a dehydrated query still had an in-flight
2776
+ * promise, it is resumed via `query.fetch()` (reusing that promise as `initialPromise`) rather than re-invoking
2777
+ * `queryFn`.
2778
+ * @example
2779
+ * ```ts
2780
+ * // dehydratedState was produced by `dehydrate` on the server
2781
+ * // and sent to the client, e.g. embedded in server-rendered markup.
2782
+ * const queryClient = new QueryClient()
2783
+ *
2784
+ * hydrate(queryClient, dehydratedState)
2785
+ * ```
2786
+ */
1370
2787
  declare function hydrate(client: QueryClient, dehydratedState: Partial<DehydratedState>, options?: HydrateOptions): void;
1371
2788
  //#endregion
1372
2789
  export { MutationObserverBaseResult as $, Query as $n, CancelledError as $t, InfiniteData as A, noop as An, QueryObserverOptions as At, InfiniteQueryObserverSuccessResult as B, Action as Bn, RefetchQueryFilters as Bt, FetchPreviousPageOptions as C, isPlainArray as Cn, QueryKey as Ct, GetPreviousPageParamFunction as D, keepPreviousData as Dn, QueryObserverBaseResult as Dt, GetNextPageParamFunction as E, isValidTimeout as En, QueryMeta as Et, InfiniteQueryObserverOptions as F, shallowEqualObjects as Fn, QueryObserverSuccessResult as Ft, InvalidateQueryFilters as G, MutationCacheConfig as Gn, StaleTime as Gt, InitialDataFunction as H, MutationState as Hn, ResetOptions as Ht, InfiniteQueryObserverPendingResult as I, shouldThrowError as In, QueryOptions as It, MutateOptions as J, Action$1 as Jn, UnsetMarker as Jt, MutateFunction as K, MutationCacheNotifyEvent as Kn, StaleTimeFunction as Kt, InfiniteQueryObserverPlaceholderResult as L, skipToken as Ln, QueryPersister as Lt, InfiniteQueryObserverBaseResult as M, replaceData as Mn, QueryObserverPlaceholderResult as Mt, InfiniteQueryObserverLoadingErrorResult as N, replaceEqualDeep as Nn, QueryObserverRefetchErrorResult as Nt, InferDataFromTag as O, matchMutation as On, QueryObserverLoadingErrorResult as Ot, InfiniteQueryObserverLoadingResult as P, resolveQueryValue as Pn, QueryObserverResult as Pt, MutationMeta as Q, FetchOptions as Qn, unsetMarker as Qt, InfiniteQueryObserverRefetchErrorResult as R, sleep as Rn, QueryStatus as Rt, FetchNextPageOptions as S, hashQueryKeyByOptions as Sn, QueryFunctionContext as St, FetchStatus as T, isServer as Tn, QueryKeyWithDataTag as Tt, InitialPageParam as U, getDefaultState as Un, ResultOptions as Ut, InfiniteQueryPageParamsOptions as V, Mutation as Vn, Register as Vt, InvalidateOptions as W, MutationCache as Wn, SetDataOptions as Wt, MutationFunctionContext as X, FetchDirection as Xn, dataTagErrorSymbol as Xt, MutationFunction as Y, FetchContext as Yn, WithRequired as Yt, MutationKey as Z, FetchMeta as Zn, dataTagSymbol as Zt, DefinedQueryObserverResult as _, addToEnd as _n, QueriesPlaceholderDataFunction as _t, defaultShouldDehydrateQuery as a, isCancelledError as an, MutationObserverSuccessResult as at, EnsureQueryDataOptions as b, functionalUpdate as bn, QueryExecuteOptions as bt, hydrate as c, QueryCacheConfig as cn, MutationStatus as ct, DataTag as d, MutationFilters as dn, NotifyEvent as dt, RetryDelayValue as en, QueryBehavior as er, MutationObserverErrorResult as et, DefaultError as f, QueryFilters as fn, NotifyEventType as ft, DefinedInfiniteQueryObserverResult as g, addConsumeAwareSignal as gn, PlaceholderDataFunction as gt, DefaultedQueryObserverOptions as h, Updater as hn, Override as ht, defaultShouldDehydrateMutation as i, createRetryer as in, MutationObserverResult as it, InfiniteQueryExecuteOptions as j, partialMatchKey as jn, QueryObserverPendingResult as jt, InferErrorFromTag as k, matchQuery as kn, QueryObserverLoadingResult as kt, AnyDataTag as l, QueryCacheNotifyEvent as ln, NetworkMode as lt, DefaultedInfiniteQueryObserverOptions as m, SkipToken as mn, OmitKeyof as mt, DehydratedState as n, Retryer as nn, fetchState as nr, MutationObserverLoadingResult as nt, dehydrate as o, QueryClient as on, MutationOptions as ot, DefaultOptions as p, QueryTypeFilter as pn, NotifyOnChangeProps as pt, MutateFunctionRest as q, MutationObserver as qn, ThrowOnError as qt, HydrateOptions as r, canFetch as rn, QueryObserver as rr, MutationObserverOptions as rt, dehydrateQuery as s, QueryCache as sn, MutationScope as st, DehydrateOptions as t, RetryValue as tn, QueryState as tr, MutationObserverIdleResult as tt, CancelOptions as u, QueryStore as un, NonUndefinedGuard as ut, DistributiveOmit as v, addToStart as vn, QueryBooleanOption as vt, FetchQueryOptions as w, isPlainObject as wn, QueryKeyHashFunction as wt, FetchInfiniteQueryOptions as x, hashKey as xn, QueryFunction as xt, EnsureInfiniteQueryDataOptions as y, ensureQueryFn as yn, QueryClientConfig as yt, InfiniteQueryObserverResult as z, timeUntilStale as zn, RefetchOptions as zt };
1373
- //# sourceMappingURL=hydration-DWGr3cFC.d.cts.map
2790
+ //# sourceMappingURL=hydration-DwR10Hi-.d.cts.map