@tanstack/query-core 5.103.2 → 5.104.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 (267) hide show
  1. package/build/legacy/{classPrivateFieldSet2-CV7wyte-.js → classPrivateFieldSet2-CukOTU3U.js} +5 -5
  2. package/build/legacy/{classPrivateFieldSet2-Bo0ZyOIv.cjs → classPrivateFieldSet2-CvCEk6bM.cjs} +5 -5
  3. package/build/legacy/{classPrivateMethodInitSpec-CBwa_Y7C.js → classPrivateMethodInitSpec-CgB-WYk3.js} +2 -2
  4. package/build/legacy/{classPrivateMethodInitSpec-DVhcLejn.cjs → classPrivateMethodInitSpec-Nr6mgZRs.cjs} +2 -2
  5. package/build/legacy/environmentManager.d.cts +3 -4
  6. package/build/legacy/environmentManager.d.cts.map +1 -1
  7. package/build/legacy/environmentManager.d.ts +3 -4
  8. package/build/legacy/environmentManager.d.ts.map +1 -1
  9. package/build/legacy/focusManager.cjs +1 -1
  10. package/build/legacy/focusManager.d.cts +3 -4
  11. package/build/legacy/focusManager.d.cts.map +1 -1
  12. package/build/legacy/focusManager.d.ts +3 -4
  13. package/build/legacy/focusManager.d.ts.map +1 -1
  14. package/build/legacy/focusManager.js +1 -1
  15. package/build/legacy/{hydration-Bp57N3SP.d.ts → hydration-B9t5w6NC.d.ts} +11 -4
  16. package/build/legacy/hydration-B9t5w6NC.d.ts.map +1 -0
  17. package/build/{modern/hydration-DRcloXEn.d.cts → legacy/hydration-Br9VIGXa.d.cts} +11 -4
  18. package/build/legacy/hydration-Br9VIGXa.d.cts.map +1 -0
  19. package/build/legacy/hydration.d.cts +1 -1
  20. package/build/legacy/hydration.d.ts +1 -1
  21. package/build/legacy/index.d.cts +1 -1
  22. package/build/legacy/index.d.ts +1 -1
  23. package/build/legacy/infiniteQueryBehavior.d.cts +4 -5
  24. package/build/legacy/infiniteQueryBehavior.d.cts.map +1 -1
  25. package/build/legacy/infiniteQueryBehavior.d.ts +4 -5
  26. package/build/legacy/infiniteQueryBehavior.d.ts.map +1 -1
  27. package/build/legacy/infiniteQueryObserver.d.cts +3 -4
  28. package/build/legacy/infiniteQueryObserver.d.cts.map +1 -1
  29. package/build/legacy/infiniteQueryObserver.d.ts +3 -4
  30. package/build/legacy/infiniteQueryObserver.d.ts.map +1 -1
  31. package/build/legacy/mutation.cjs +2 -2
  32. package/build/legacy/mutation.d.cts +1 -1
  33. package/build/legacy/mutation.d.ts +1 -1
  34. package/build/legacy/mutation.js +2 -2
  35. package/build/legacy/mutationCache.cjs +1 -1
  36. package/build/legacy/mutationCache.d.cts +1 -1
  37. package/build/legacy/mutationCache.d.ts +1 -1
  38. package/build/legacy/mutationCache.js +1 -1
  39. package/build/legacy/mutationObserver.cjs +2 -2
  40. package/build/legacy/mutationObserver.d.cts +1 -1
  41. package/build/legacy/mutationObserver.d.ts +1 -1
  42. package/build/legacy/mutationObserver.js +2 -2
  43. package/build/legacy/notifyManager.d.cts +3 -4
  44. package/build/legacy/notifyManager.d.cts.map +1 -1
  45. package/build/legacy/notifyManager.d.ts +3 -4
  46. package/build/legacy/notifyManager.d.ts.map +1 -1
  47. package/build/legacy/onlineManager.cjs +1 -1
  48. package/build/legacy/onlineManager.d.cts +3 -4
  49. package/build/legacy/onlineManager.d.cts.map +1 -1
  50. package/build/legacy/onlineManager.d.ts +3 -4
  51. package/build/legacy/onlineManager.d.ts.map +1 -1
  52. package/build/legacy/onlineManager.js +1 -1
  53. package/build/legacy/queriesObserver.cjs +2 -2
  54. package/build/legacy/queriesObserver.d.cts +4 -5
  55. package/build/legacy/queriesObserver.d.cts.map +1 -1
  56. package/build/legacy/queriesObserver.d.ts +4 -5
  57. package/build/legacy/queriesObserver.d.ts.map +1 -1
  58. package/build/legacy/queriesObserver.js +2 -2
  59. package/build/legacy/query.cjs +2 -2
  60. package/build/legacy/query.cjs.map +1 -1
  61. package/build/legacy/query.d.cts +1 -1
  62. package/build/legacy/query.d.ts +1 -1
  63. package/build/legacy/query.js +2 -2
  64. package/build/legacy/query.js.map +1 -1
  65. package/build/legacy/queryCache.cjs +1 -1
  66. package/build/legacy/queryCache.cjs.map +1 -1
  67. package/build/legacy/queryCache.d.cts +1 -1
  68. package/build/legacy/queryCache.d.ts +1 -1
  69. package/build/legacy/queryCache.js +1 -1
  70. package/build/legacy/queryCache.js.map +1 -1
  71. package/build/legacy/queryClient.cjs +8 -1
  72. package/build/legacy/queryClient.cjs.map +1 -1
  73. package/build/legacy/queryClient.d.cts +1 -1
  74. package/build/legacy/queryClient.d.ts +1 -1
  75. package/build/legacy/queryClient.js +8 -1
  76. package/build/legacy/queryClient.js.map +1 -1
  77. package/build/legacy/queryObserver.cjs +2 -2
  78. package/build/legacy/queryObserver.cjs.map +1 -1
  79. package/build/legacy/queryObserver.d.cts +1 -1
  80. package/build/legacy/queryObserver.d.ts +1 -1
  81. package/build/legacy/queryObserver.js +2 -2
  82. package/build/legacy/queryObserver.js.map +1 -1
  83. package/build/legacy/removable-0GzhW1PK.d.cts +22 -0
  84. package/build/legacy/removable-0GzhW1PK.d.cts.map +1 -0
  85. package/build/legacy/removable-0GzhW1PK.d.ts +22 -0
  86. package/build/legacy/removable-0GzhW1PK.d.ts.map +1 -0
  87. package/build/legacy/removable.cjs +10 -1
  88. package/build/legacy/removable.cjs.map +1 -1
  89. package/build/legacy/removable.d.cts +1 -1
  90. package/build/legacy/removable.d.ts +1 -1
  91. package/build/legacy/removable.js +10 -1
  92. package/build/legacy/removable.js.map +1 -1
  93. package/build/legacy/retryer.d.cts +1 -1
  94. package/build/legacy/retryer.d.ts +1 -1
  95. package/build/legacy/streamedQuery.cjs +0 -7
  96. package/build/legacy/streamedQuery.cjs.map +1 -1
  97. package/build/legacy/streamedQuery.d.cts +2 -10
  98. package/build/legacy/streamedQuery.d.cts.map +1 -1
  99. package/build/legacy/streamedQuery.d.ts +2 -10
  100. package/build/legacy/streamedQuery.d.ts.map +1 -1
  101. package/build/legacy/streamedQuery.js +0 -7
  102. package/build/legacy/streamedQuery.js.map +1 -1
  103. package/build/legacy/subscribable-CysQ0tne.d.cts +34 -0
  104. package/build/legacy/subscribable-CysQ0tne.d.cts.map +1 -0
  105. package/build/legacy/subscribable-CysQ0tne.d.ts +34 -0
  106. package/build/legacy/subscribable-CysQ0tne.d.ts.map +1 -0
  107. package/build/legacy/subscribable.cjs +22 -0
  108. package/build/legacy/subscribable.cjs.map +1 -1
  109. package/build/legacy/subscribable.d.cts +1 -1
  110. package/build/legacy/subscribable.d.ts +1 -1
  111. package/build/legacy/subscribable.js +22 -0
  112. package/build/legacy/subscribable.js.map +1 -1
  113. package/build/legacy/timeoutManager.cjs +1 -1
  114. package/build/legacy/timeoutManager.d.cts +7 -8
  115. package/build/legacy/timeoutManager.d.cts.map +1 -1
  116. package/build/legacy/timeoutManager.d.ts +7 -8
  117. package/build/legacy/timeoutManager.d.ts.map +1 -1
  118. package/build/legacy/timeoutManager.js +1 -1
  119. package/build/legacy/types.cjs.map +1 -1
  120. package/build/legacy/types.d.cts +1 -1
  121. package/build/legacy/types.d.ts +1 -1
  122. package/build/legacy/types.js.map +1 -1
  123. package/build/legacy/utils.d.cts +1 -1
  124. package/build/legacy/utils.d.ts +1 -1
  125. package/build/modern/environmentManager.d.cts +3 -4
  126. package/build/modern/environmentManager.d.cts.map +1 -1
  127. package/build/modern/environmentManager.d.ts +3 -4
  128. package/build/modern/environmentManager.d.ts.map +1 -1
  129. package/build/modern/focusManager.cjs.map +1 -1
  130. package/build/modern/focusManager.d.cts +3 -4
  131. package/build/modern/focusManager.d.cts.map +1 -1
  132. package/build/modern/focusManager.d.ts +3 -4
  133. package/build/modern/focusManager.d.ts.map +1 -1
  134. package/build/modern/focusManager.js.map +1 -1
  135. package/build/{legacy/hydration-DRcloXEn.d.cts → modern/hydration-B9t5w6NC.d.ts} +11 -4
  136. package/build/modern/hydration-B9t5w6NC.d.ts.map +1 -0
  137. package/build/modern/{hydration-Bp57N3SP.d.ts → hydration-Br9VIGXa.d.cts} +11 -4
  138. package/build/modern/hydration-Br9VIGXa.d.cts.map +1 -0
  139. package/build/modern/hydration.d.cts +1 -1
  140. package/build/modern/hydration.d.ts +1 -1
  141. package/build/modern/index.d.cts +1 -1
  142. package/build/modern/index.d.ts +1 -1
  143. package/build/modern/infiniteQueryBehavior.d.cts +4 -5
  144. package/build/modern/infiniteQueryBehavior.d.cts.map +1 -1
  145. package/build/modern/infiniteQueryBehavior.d.ts +4 -5
  146. package/build/modern/infiniteQueryBehavior.d.ts.map +1 -1
  147. package/build/modern/infiniteQueryObserver.d.cts +3 -4
  148. package/build/modern/infiniteQueryObserver.d.cts.map +1 -1
  149. package/build/modern/infiniteQueryObserver.d.ts +3 -4
  150. package/build/modern/infiniteQueryObserver.d.ts.map +1 -1
  151. package/build/modern/mutation.cjs.map +1 -1
  152. package/build/modern/mutation.d.cts +1 -1
  153. package/build/modern/mutation.d.ts +1 -1
  154. package/build/modern/mutation.js.map +1 -1
  155. package/build/modern/mutationCache.cjs.map +1 -1
  156. package/build/modern/mutationCache.d.cts +1 -1
  157. package/build/modern/mutationCache.d.ts +1 -1
  158. package/build/modern/mutationCache.js.map +1 -1
  159. package/build/modern/mutationObserver.cjs.map +1 -1
  160. package/build/modern/mutationObserver.d.cts +1 -1
  161. package/build/modern/mutationObserver.d.ts +1 -1
  162. package/build/modern/mutationObserver.js.map +1 -1
  163. package/build/modern/notifyManager.d.cts +3 -4
  164. package/build/modern/notifyManager.d.cts.map +1 -1
  165. package/build/modern/notifyManager.d.ts +3 -4
  166. package/build/modern/notifyManager.d.ts.map +1 -1
  167. package/build/modern/onlineManager.cjs.map +1 -1
  168. package/build/modern/onlineManager.d.cts +3 -4
  169. package/build/modern/onlineManager.d.cts.map +1 -1
  170. package/build/modern/onlineManager.d.ts +3 -4
  171. package/build/modern/onlineManager.d.ts.map +1 -1
  172. package/build/modern/onlineManager.js.map +1 -1
  173. package/build/modern/queriesObserver.cjs.map +1 -1
  174. package/build/modern/queriesObserver.d.cts +4 -5
  175. package/build/modern/queriesObserver.d.cts.map +1 -1
  176. package/build/modern/queriesObserver.d.ts +4 -5
  177. package/build/modern/queriesObserver.d.ts.map +1 -1
  178. package/build/modern/queriesObserver.js.map +1 -1
  179. package/build/modern/query.cjs.map +1 -1
  180. package/build/modern/query.d.cts +1 -1
  181. package/build/modern/query.d.ts +1 -1
  182. package/build/modern/query.js.map +1 -1
  183. package/build/modern/queryCache.cjs.map +1 -1
  184. package/build/modern/queryCache.d.cts +1 -1
  185. package/build/modern/queryCache.d.ts +1 -1
  186. package/build/modern/queryCache.js.map +1 -1
  187. package/build/modern/queryClient.cjs +7 -0
  188. package/build/modern/queryClient.cjs.map +1 -1
  189. package/build/modern/queryClient.d.cts +1 -1
  190. package/build/modern/queryClient.d.ts +1 -1
  191. package/build/modern/queryClient.js +7 -0
  192. package/build/modern/queryClient.js.map +1 -1
  193. package/build/modern/queryObserver.cjs.map +1 -1
  194. package/build/modern/queryObserver.d.cts +1 -1
  195. package/build/modern/queryObserver.d.ts +1 -1
  196. package/build/modern/queryObserver.js.map +1 -1
  197. package/build/modern/removable-0GzhW1PK.d.cts +22 -0
  198. package/build/modern/removable-0GzhW1PK.d.cts.map +1 -0
  199. package/build/modern/removable-0GzhW1PK.d.ts +22 -0
  200. package/build/modern/removable-0GzhW1PK.d.ts.map +1 -0
  201. package/build/modern/removable.cjs +9 -0
  202. package/build/modern/removable.cjs.map +1 -1
  203. package/build/modern/removable.d.cts +1 -1
  204. package/build/modern/removable.d.ts +1 -1
  205. package/build/modern/removable.js +9 -0
  206. package/build/modern/removable.js.map +1 -1
  207. package/build/modern/retryer.d.cts +1 -1
  208. package/build/modern/retryer.d.ts +1 -1
  209. package/build/modern/streamedQuery.cjs +0 -7
  210. package/build/modern/streamedQuery.cjs.map +1 -1
  211. package/build/modern/streamedQuery.d.cts +2 -10
  212. package/build/modern/streamedQuery.d.cts.map +1 -1
  213. package/build/modern/streamedQuery.d.ts +2 -10
  214. package/build/modern/streamedQuery.d.ts.map +1 -1
  215. package/build/modern/streamedQuery.js +0 -7
  216. package/build/modern/streamedQuery.js.map +1 -1
  217. package/build/modern/subscribable-CysQ0tne.d.cts +34 -0
  218. package/build/modern/subscribable-CysQ0tne.d.cts.map +1 -0
  219. package/build/modern/subscribable-CysQ0tne.d.ts +34 -0
  220. package/build/modern/subscribable-CysQ0tne.d.ts.map +1 -0
  221. package/build/modern/subscribable.cjs +22 -0
  222. package/build/modern/subscribable.cjs.map +1 -1
  223. package/build/modern/subscribable.d.cts +1 -1
  224. package/build/modern/subscribable.d.ts +1 -1
  225. package/build/modern/subscribable.js +22 -0
  226. package/build/modern/subscribable.js.map +1 -1
  227. package/build/modern/timeoutManager.cjs.map +1 -1
  228. package/build/modern/timeoutManager.d.cts +7 -8
  229. package/build/modern/timeoutManager.d.cts.map +1 -1
  230. package/build/modern/timeoutManager.d.ts +7 -8
  231. package/build/modern/timeoutManager.d.ts.map +1 -1
  232. package/build/modern/timeoutManager.js.map +1 -1
  233. package/build/modern/types.cjs.map +1 -1
  234. package/build/modern/types.d.cts +1 -1
  235. package/build/modern/types.d.ts +1 -1
  236. package/build/modern/types.js.map +1 -1
  237. package/build/modern/utils.d.cts +1 -1
  238. package/build/modern/utils.d.ts +1 -1
  239. package/package.json +3 -3
  240. package/src/query.ts +1 -2
  241. package/src/queryCache.ts +1 -2
  242. package/src/queryClient.ts +7 -0
  243. package/src/queryObserver.ts +4 -8
  244. package/src/removable.ts +9 -0
  245. package/src/streamedQuery.ts +1 -7
  246. package/src/subscribable.ts +22 -0
  247. package/src/types.ts +9 -15
  248. package/build/legacy/hydration-Bp57N3SP.d.ts.map +0 -1
  249. package/build/legacy/hydration-DRcloXEn.d.cts.map +0 -1
  250. package/build/legacy/removable-DeMjhW5M.d.cts +0 -13
  251. package/build/legacy/removable-DeMjhW5M.d.cts.map +0 -1
  252. package/build/legacy/removable-DeMjhW5M.d.ts +0 -13
  253. package/build/legacy/removable-DeMjhW5M.d.ts.map +0 -1
  254. package/build/legacy/subscribable-CbifVTKz.d.cts +0 -12
  255. package/build/legacy/subscribable-CbifVTKz.d.cts.map +0 -1
  256. package/build/legacy/subscribable-CbifVTKz.d.ts +0 -12
  257. package/build/legacy/subscribable-CbifVTKz.d.ts.map +0 -1
  258. package/build/modern/hydration-Bp57N3SP.d.ts.map +0 -1
  259. package/build/modern/hydration-DRcloXEn.d.cts.map +0 -1
  260. package/build/modern/removable-DeMjhW5M.d.cts +0 -13
  261. package/build/modern/removable-DeMjhW5M.d.cts.map +0 -1
  262. package/build/modern/removable-DeMjhW5M.d.ts +0 -13
  263. package/build/modern/removable-DeMjhW5M.d.ts.map +0 -1
  264. package/build/modern/subscribable-CbifVTKz.d.cts +0 -12
  265. package/build/modern/subscribable-CbifVTKz.d.cts.map +0 -1
  266. package/build/modern/subscribable-CbifVTKz.d.ts +0 -12
  267. package/build/modern/subscribable-CbifVTKz.d.ts.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"file":"query.js","names":["#abortSignalConsumed","#defaultOptions","#client","#cache","#initialState","#queryType","#retryer","#dispatch","#revertState"],"sources":["../../src/query.ts"],"sourcesContent":["import {\n ensureQueryFn,\n noop,\n replaceData,\n resolveQueryValue,\n skipToken,\n timeUntilStale,\n} from './utils'\nimport { notifyManager } from './notifyManager'\nimport { CancelledError, canFetch, createRetryer } from './retryer'\nimport { Removable } from './removable'\nimport { infiniteQueryBehavior } from './infiniteQueryBehavior'\nimport type { QueryCache } from './queryCache'\nimport type { QueryClient } from './queryClient'\nimport type {\n CancelOptions,\n DefaultError,\n FetchStatus,\n InitialDataFunction,\n OmitKeyof,\n QueryFunctionContext,\n QueryKey,\n QueryMeta,\n QueryOptions,\n QueryStatus,\n SetDataOptions,\n StaleTime,\n} from './types'\nimport type { QueryObserver } from './queryObserver'\nimport type { Retryer } from './retryer'\n\n// TYPES\n\ninterface QueryConfig<\n TQueryFnData,\n TError,\n TData,\n TQueryKey extends QueryKey = QueryKey,\n> {\n client: QueryClient\n queryKey: TQueryKey\n queryHash: string\n options?: QueryOptions<TQueryFnData, TError, TData, TQueryKey>\n defaultOptions?: QueryOptions<TQueryFnData, TError, TData, TQueryKey>\n state?: QueryState<TData, TError>\n}\n\n/**\n * The raw state stored on a `Query` instance. This is the underlying state\n * that observer results (e.g. `QueryObserverResult`) are derived from.\n */\nexport interface QueryState<TData = unknown, TError = DefaultError> {\n /**\n * The last successfully resolved data for the query.\n */\n data: TData | undefined\n /**\n * The number of times the query has successfully resolved.\n */\n dataUpdateCount: number\n /**\n * The timestamp for when the query most recently returned the `status` as `\"success\"`.\n */\n dataUpdatedAt: number\n /**\n * The error object for the query, if the last attempt resulted in an error.\n * - Defaults to `null`.\n */\n error: TError | null\n /**\n * The sum of all errors, incremented every time the query resolves with an error.\n */\n errorUpdateCount: number\n /**\n * The timestamp for when the query most recently returned the `status` as `\"error\"`.\n */\n errorUpdatedAt: number\n /**\n * The failure count for the current fetch.\n * - Incremented every time the fetch fails.\n * - Reset to `0` when the fetch succeeds.\n */\n fetchFailureCount: number\n /**\n * The reason the current fetch failed, as reported by the retryer.\n * - Reset to `null` when the fetch succeeds.\n */\n fetchFailureReason: TError | null\n /**\n * Metadata passed to the currently in-flight (or most recent) fetch, e.g. the\n * `fetchMore` direction for infinite queries.\n */\n fetchMeta: FetchMeta | null\n /**\n * Whether the query has been marked as invalidated via `invalidate()`.\n * - Reset to `false` whenever the query resolves successfully.\n */\n isInvalidated: boolean\n /**\n * The status of the query.\n * - `pending` if there's no cached data and no attempt was finished yet.\n * - `error` if the last attempt resulted in an error.\n * - `success` if the query has data.\n */\n status: QueryStatus\n /**\n * The fetch status of the query.\n * - `fetching`: the `queryFn` is currently executing.\n * - `paused`: a fetch wanted to run but has been paused (see network mode).\n * - `idle`: the query is not fetching.\n */\n fetchStatus: FetchStatus\n}\n\nexport interface FetchContext<\n TQueryFnData,\n TError,\n TData,\n TQueryKey extends QueryKey = QueryKey,\n> {\n fetchFn: () => unknown | Promise<unknown>\n fetchOptions?: FetchOptions\n signal: AbortSignal\n options: QueryOptions<TQueryFnData, TError, TData, any>\n client: QueryClient\n queryKey: TQueryKey\n state: QueryState<TData, TError>\n}\n\nexport interface QueryBehavior<\n TQueryFnData = unknown,\n TError = DefaultError,\n TData = TQueryFnData,\n TQueryKey extends QueryKey = QueryKey,\n> {\n onFetch: (\n context: FetchContext<TQueryFnData, TError, TData, TQueryKey>,\n query: Query,\n ) => void\n}\n\nexport type FetchDirection = 'forward' | 'backward'\n\nexport interface FetchMeta {\n fetchMore?: { direction: FetchDirection }\n}\n\nexport interface FetchOptions<TData = unknown> {\n cancelRefetch?: boolean\n meta?: FetchMeta\n initialPromise?: Promise<TData>\n}\n\ninterface FailedAction<TError> {\n type: 'failed'\n failureCount: number\n error: TError\n}\n\ninterface FetchAction {\n type: 'fetch'\n meta?: FetchMeta\n}\n\ninterface SuccessAction<TData> {\n data: TData | undefined\n type: 'success'\n dataUpdatedAt?: number\n manual?: boolean\n}\n\ninterface ErrorAction<TError> {\n type: 'error'\n error: TError\n}\n\ninterface InvalidateAction {\n type: 'invalidate'\n}\n\ninterface PauseAction {\n type: 'pause'\n}\n\ninterface ContinueAction {\n type: 'continue'\n}\n\ninterface SetStateAction<TData, TError> {\n type: 'setState'\n state: Partial<QueryState<TData, TError>>\n}\n\nexport type Action<TData, TError> =\n | ContinueAction\n | ErrorAction<TError>\n | FailedAction<TError>\n | FetchAction\n | InvalidateAction\n | PauseAction\n | SetStateAction<TData, TError>\n | SuccessAction<TData>\n\n// CLASS\n\n/**\n * Represents a single cached query. A `Query` holds the query's key, options,\n * state (data/error/status), and the observers currently subscribed to it.\n *\n * Instances are created and managed internally by `QueryCache`; application\n * code typically interacts with queries indirectly through `QueryClient` or\n * a framework hook like `useQuery`. Direct access to a `Query` instance is\n * possible via `queryCache.find()`/`findAll()` for inspecting cache state.\n *\n * @example\n * ```ts\n * const queryCache = queryClient.getQueryCache()\n * const query = queryCache.find({ queryKey: ['posts'] })\n *\n * if (query) {\n * console.log(query.state.dataUpdatedAt)\n * }\n * ```\n */\nexport class Query<\n TQueryFnData = unknown,\n TError = DefaultError,\n TData = TQueryFnData,\n TQueryKey extends QueryKey = QueryKey,\n> extends Removable {\n queryKey: TQueryKey\n queryHash: string\n options!: QueryOptions<TQueryFnData, TError, TData, TQueryKey>\n state: QueryState<TData, TError>\n #queryType?: 'infinite'\n\n #initialState: QueryState<TData, TError>\n #revertState?: QueryState<TData, TError>\n #cache: QueryCache\n #client: QueryClient\n #retryer?: Retryer<TData>\n observers: Array<QueryObserver<any, any, any, any, any>>\n #defaultOptions?: QueryOptions<TQueryFnData, TError, TData, TQueryKey>\n #abortSignalConsumed: boolean\n\n constructor(config: QueryConfig<TQueryFnData, TError, TData, TQueryKey>) {\n super()\n\n this.#abortSignalConsumed = false\n this.#defaultOptions = config.defaultOptions\n this.setOptions(config.options)\n this.observers = []\n this.#client = config.client\n this.#cache = this.#client.getQueryCache()\n this.queryKey = config.queryKey\n this.queryHash = config.queryHash\n this.#initialState = getDefaultState(this.options)\n this.state = config.state ?? this.#initialState\n this.scheduleGc()\n }\n /**\n * The `meta` object passed in the query's options, if any.\n */\n get meta(): QueryMeta | undefined {\n return this.options.meta\n }\n\n /** @internal */\n get queryType() {\n return this.#queryType\n }\n\n /**\n * The promise for the currently in-flight fetch, if the query is fetching.\n * `undefined` when the query is not fetching.\n */\n get promise(): Promise<TData> | undefined {\n return this.#retryer?.promise\n }\n\n /** @internal */\n setOptions(\n options?: QueryOptions<TQueryFnData, TError, TData, TQueryKey>,\n ): void {\n this.options = { ...this.#defaultOptions, ...options }\n\n if (options?._type) {\n this.#queryType = options._type\n }\n\n this.updateGcTime(this.options.gcTime)\n\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition\n if (this.state && this.state.data === undefined) {\n const defaultState = getDefaultState(this.options)\n if (defaultState.data !== undefined) {\n this.setState(\n successState(defaultState.data, defaultState.dataUpdatedAt),\n )\n this.#initialState = defaultState\n }\n }\n }\n\n protected optionalRemove() {\n if (!this.observers.length && this.state.fetchStatus === 'idle') {\n this.#cache.remove(this)\n }\n }\n\n /** @internal */\n setData(\n newData: TData,\n options?: SetDataOptions & { manual: boolean },\n ): TData {\n const data = replaceData(this.state.data, newData, this.options)\n\n // Set data and mark it as cached\n this.#dispatch({\n data,\n type: 'success',\n dataUpdatedAt: options?.updatedAt,\n manual: options?.manual,\n })\n\n return data\n }\n\n /**\n * Merges the given partial state directly into this query's state, notifying observers. Used\n * by persistence and broadcast plugins to restore a state snapshot, and by devtools to let a\n * user manually trigger a loading/error state or edit the cached data.\n */\n setState(state: Partial<QueryState<TData, TError>>): void {\n this.#dispatch({ type: 'setState', state })\n }\n\n /**\n * Cancels the query's currently in-flight fetch, if any.\n * - Returns a promise that resolves once the cancellation has settled.\n * - If no fetch is in progress, resolves immediately.\n *\n * @example\n * ```ts\n * await query.cancel()\n * ```\n */\n cancel(options?: CancelOptions): Promise<void> {\n const promise = this.#retryer?.promise\n this.#retryer?.cancel(options)\n return promise ? promise.then(noop).catch(noop) : Promise.resolve()\n }\n\n /**\n * Clears the query's garbage collection timeout and silently cancels any\n * in-flight fetch. Called by `QueryCache` when the query is removed from\n * the cache.\n *\n * @see {@link Query#cancel}\n */\n destroy(): void {\n super.destroy()\n\n this.cancel({ silent: true })\n }\n\n /** @internal */\n get resetState(): QueryState<TData, TError> {\n return this.#initialState\n }\n\n /**\n * Resets the query back to its initial state (the state it had when it was\n * first created, e.g. any `initialData`), destroying it first to cancel any\n * in-flight fetch.\n */\n reset(): void {\n this.destroy()\n this.setState(this.resetState)\n }\n\n /**\n * Returns `true` if the query has at least one observer for which `enabled`\n * does not resolve to `false`.\n */\n isActive(): boolean {\n return this.observers.some(\n (observer) => resolveQueryValue(observer.options.enabled, this) !== false,\n )\n }\n\n /**\n * Returns `true` if the query is disabled, meaning it will not fetch\n * automatically.\n * - If the query has observers, it is disabled when none of them are active\n * (see `isActive`).\n * - If the query has no observers, it is disabled when its `queryFn` is\n * `skipToken` or it has never been fetched.\n */\n isDisabled(): boolean {\n if (this.getObserversCount() > 0) {\n return !this.isActive()\n }\n // if a query has no observers, it should still be considered disabled if it never attempted a fetch\n return this.options.queryFn === skipToken || !this.isFetched()\n }\n\n /**\n * Returns `true` if the query has been fetched, i.e. it has resolved with\n * either data or an error at least once.\n */\n isFetched() {\n return this.state.dataUpdateCount + this.state.errorUpdateCount > 0\n }\n\n /**\n * Returns `true` if the query has at least one observer configured with\n * `staleTime: 'static'`, meaning it is treated as never stale.\n */\n isStatic(): boolean {\n if (this.getObserversCount() > 0) {\n return this.observers.some(\n (observer) =>\n resolveQueryValue(observer.options.staleTime, this) === 'static',\n )\n }\n\n return false\n }\n\n /**\n * Returns `true` if the query is stale.\n * - If the query has observers, defers to whether any observer's current\n * result reports `isStale` (which accounts for each observer's own\n * `staleTime` and `enabled` state).\n * - If the query has no observers, it is considered stale when it has no\n * data or has been invalidated.\n *\n * @see {@link Query#isStaleByTime}\n * @example\n * ```ts\n * if (query.isStale()) {\n * // refetch or otherwise treat the cached data as outdated\n * }\n * ```\n */\n isStale(): boolean {\n // check observers first, their `isStale` has the source of truth\n // calculated with `isStaleByTime` and it takes `enabled` into account\n if (this.getObserversCount() > 0) {\n return this.observers.some(\n (observer) => observer.getCurrentResult().isStale,\n )\n }\n\n return this.state.data === undefined || this.state.isInvalidated\n }\n\n /**\n * Returns `true` if the query's data is stale relative to the given\n * `staleTime` (defaults to `0`).\n * - A query with no data is always stale.\n * - `staleTime: 'static'` is never stale.\n * - An invalidated query is always stale.\n * - Otherwise, staleness is based on elapsed time since `dataUpdatedAt`.\n *\n * @see {@link Query#isStale}\n * @example\n * ```ts\n * const isStale = query.isStaleByTime(1000 * 60)\n * ```\n */\n isStaleByTime(staleTime: StaleTime = 0): boolean {\n // no data is always stale\n if (this.state.data === undefined) {\n return true\n }\n // static is never stale\n if (staleTime === 'static') {\n return false\n }\n // if the query is invalidated, it is stale\n if (this.state.isInvalidated) {\n return true\n }\n\n return !timeUntilStale(this.state.dataUpdatedAt, staleTime)\n }\n\n /** @internal */\n onFocus(): void {\n const observer = this.observers.find((x) => x.shouldFetchOnWindowFocus())\n\n observer?.refetch({ cancelRefetch: false })\n\n // Continue fetch if currently paused\n this.#retryer?.continue()\n }\n\n /** @internal */\n onOnline(): void {\n const observer = this.observers.find((x) => x.shouldFetchOnReconnect())\n\n observer?.refetch({ cancelRefetch: false })\n\n // Continue fetch if currently paused\n this.#retryer?.continue()\n }\n\n /** @internal */\n addObserver(observer: QueryObserver<any, any, any, any, any>): void {\n if (!this.observers.includes(observer)) {\n this.observers.push(observer)\n\n // Stop the query from being garbage collected\n this.clearGcTimeout()\n\n this.#cache.notify({ type: 'observerAdded', query: this, observer })\n }\n }\n\n /** @internal */\n removeObserver(observer: QueryObserver<any, any, any, any, any>): void {\n const index = this.observers.indexOf(observer)\n if (index !== -1) {\n this.observers.splice(index, 1)\n\n if (!this.observers.length) {\n // If the transport layer does not support cancellation\n // we'll let the query continue so the result can be cached\n if (this.#retryer) {\n if (\n this.#abortSignalConsumed ||\n (this.state.fetchStatus === 'paused' &&\n this.state.status === 'pending')\n ) {\n this.#retryer.cancel({ revert: true })\n } else {\n this.#retryer.cancelRetry()\n }\n }\n\n this.scheduleGc()\n }\n\n this.#cache.notify({ type: 'observerRemoved', query: this, observer })\n }\n }\n\n /**\n * Returns the number of observers currently subscribed to this query.\n *\n * @example\n * ```ts\n * if (query.getObserversCount() === 0) {\n * // no component is currently watching this query\n * }\n * ```\n */\n getObserversCount(): number {\n return this.observers.length\n }\n\n /**\n * Marks the query as invalidated, unless it is already invalidated. This\n * updates `state.isInvalidated` and notifies observers, but does not by\n * itself trigger a refetch.\n *\n * @example\n * ```ts\n * query.invalidate()\n * ```\n */\n invalidate(): void {\n if (!this.state.isInvalidated) {\n this.#dispatch({ type: 'invalidate' })\n }\n }\n\n /**\n * Fetches the query, i.e. runs its `queryFn` (through any configured\n * retryer/behavior) and updates the query's state with the result.\n * - If a fetch is already in flight, returns its promise instead of\n * starting a new one, unless `fetchOptions.cancelRefetch` is set and the\n * query already has data, in which case the current fetch is silently\n * cancelled first.\n * - If `options` is passed, it replaces the query's current options\n * before fetching.\n */\n async fetch(\n options?: QueryOptions<TQueryFnData, TError, TData, TQueryKey>,\n fetchOptions?: FetchOptions<TQueryFnData>,\n ): Promise<TData> {\n if (\n this.state.fetchStatus !== 'idle' &&\n // If the promise in the retryer is already rejected, we have to definitely\n // re-start the fetch; there is a chance that the query is still in a\n // pending state when that happens\n this.#retryer?.status() !== 'rejected'\n ) {\n if (this.state.data !== undefined && fetchOptions?.cancelRefetch) {\n // Silently cancel current fetch if the user wants to cancel refetch\n this.cancel({ silent: true })\n } else if (this.#retryer) {\n // make sure that retries that were potentially cancelled due to unmounts can continue\n this.#retryer.continueRetry()\n // Return current promise if we are already fetching\n return this.#retryer.promise\n }\n }\n\n // Update config if passed, otherwise the config from the last execution is used\n if (options) {\n this.setOptions(options)\n }\n\n // Use the options from the first observer with a query function if no function is found.\n // This can happen when the query is hydrated or created with setQueryData.\n if (!this.options.queryFn) {\n const observer = this.observers.find((x) => x.options.queryFn)\n if (observer) {\n this.setOptions(observer.options)\n }\n }\n\n if (process.env.NODE_ENV !== 'production') {\n if (!Array.isArray(this.options.queryKey)) {\n console.error(\n `As of v4, queryKey needs to be an Array. If you are using a string like 'repoData', please change it to an Array, e.g. ['repoData']`,\n )\n }\n }\n\n const abortController = new AbortController()\n\n // Adds an enumerable signal property to the object that\n // which sets abortSignalConsumed to true when the signal\n // is read.\n const addSignalProperty = (object: unknown) => {\n Object.defineProperty(object, 'signal', {\n enumerable: true,\n get: () => {\n this.#abortSignalConsumed = true\n return abortController.signal\n },\n })\n }\n\n // Create fetch function\n const fetchFn = () => {\n const queryFn = ensureQueryFn(this.options, fetchOptions)\n\n // Create query function context\n const createQueryFnContext = (): QueryFunctionContext<TQueryKey> => {\n const queryFnContext: OmitKeyof<\n QueryFunctionContext<TQueryKey>,\n 'signal'\n > = {\n client: this.#client,\n queryKey: this.queryKey,\n meta: this.meta,\n }\n addSignalProperty(queryFnContext)\n return queryFnContext as QueryFunctionContext<TQueryKey>\n }\n\n const queryFnContext = createQueryFnContext()\n\n this.#abortSignalConsumed = false\n if (this.options.persister) {\n return this.options.persister(\n queryFn,\n queryFnContext,\n this as unknown as Query,\n )\n }\n\n return queryFn(queryFnContext)\n }\n\n // Trigger behavior hook\n const createFetchContext = (): FetchContext<\n TQueryFnData,\n TError,\n TData,\n TQueryKey\n > => {\n const context: OmitKeyof<\n FetchContext<TQueryFnData, TError, TData, TQueryKey>,\n 'signal'\n > = {\n fetchOptions,\n options: this.options,\n queryKey: this.queryKey,\n client: this.#client,\n state: this.state,\n fetchFn,\n }\n\n addSignalProperty(context)\n return context as FetchContext<TQueryFnData, TError, TData, TQueryKey>\n }\n\n const context = createFetchContext()\n\n const behavior =\n this.#queryType === 'infinite'\n ? (infiniteQueryBehavior(\n (this.options as { pages?: number }).pages,\n ) as QueryBehavior<TQueryFnData, TError, TData, TQueryKey>)\n : this.options.behavior\n behavior?.onFetch(context, this as unknown as Query)\n\n // Store state in case the current fetch needs to be reverted\n this.#revertState = this.state\n\n // Set to fetching state if not already in it\n if (\n this.state.fetchStatus === 'idle' ||\n this.state.fetchMeta !== context.fetchOptions?.meta\n ) {\n this.#dispatch({ type: 'fetch', meta: context.fetchOptions?.meta })\n }\n\n // Try to fetch the data\n const retryer = (this.#retryer = createRetryer({\n initialPromise: fetchOptions?.initialPromise as\n | Promise<TData>\n | undefined,\n fn: context.fetchFn as () => Promise<TData>,\n onCancel: (error) => {\n if (error instanceof CancelledError && error.revert) {\n this.setState({\n ...this.#revertState,\n fetchStatus: 'idle' as const,\n })\n }\n abortController.abort()\n },\n onFail: (failureCount, error) => {\n this.#dispatch({ type: 'failed', failureCount, error })\n },\n onPause: () => {\n this.#dispatch({ type: 'pause' })\n },\n onContinue: () => {\n this.#dispatch({ type: 'continue' })\n },\n retry: context.options.retry,\n retryDelay: context.options.retryDelay,\n networkMode: context.options.networkMode,\n canRun: () => true,\n }))\n\n try {\n const data = await retryer.start()\n // this is more of a runtime guard\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition\n if (data === undefined) {\n if (process.env.NODE_ENV !== 'production') {\n console.error(\n `Query data cannot be undefined. Please make sure to return a value other than undefined from your query function. Affected query key: ${this.queryHash}`,\n )\n }\n throw new Error(`${this.queryHash} data is undefined`)\n }\n\n this.setData(data)\n\n // Notify cache callback\n this.#cache.config.onSuccess?.(data, this as Query<any, any, any, any>)\n this.#cache.config.onSettled?.(\n data,\n this.state.error as any,\n this as Query<any, any, any, any>,\n )\n return data\n } catch (error) {\n if (error instanceof CancelledError) {\n if (error.silent) {\n // silent cancellation implies a new fetch is going to be started,\n // so we piggyback onto that promise\n return this.#retryer.promise\n } else if (error.revert) {\n // transform error into reverted state data\n // if the initial fetch was cancelled, we have no data, so we have\n // to get reject with a CancelledError\n if (this.state.data === undefined) {\n throw error\n }\n return this.state.data\n }\n }\n this.#dispatch({\n type: 'error',\n error: error as TError,\n })\n\n // Notify cache callback\n this.#cache.config.onError?.(\n error as any,\n this as Query<any, any, any, any>,\n )\n this.#cache.config.onSettled?.(\n this.state.data,\n error as any,\n this as Query<any, any, any, any>,\n )\n\n throw error // rethrow the error for further handling\n } finally {\n // The settled retryer's promise would otherwise pin this fetch's raw\n // result (a second copy after structural sharing) for the query's lifetime\n if (this.#retryer === retryer) {\n this.#retryer = undefined\n }\n // Schedule query gc after fetching\n this.scheduleGc()\n }\n }\n\n #dispatch(action: Action<TData, TError>): void {\n const reducer = (\n state: QueryState<TData, TError>,\n ): QueryState<TData, TError> => {\n switch (action.type) {\n case 'failed':\n return {\n ...state,\n fetchFailureCount: action.failureCount,\n fetchFailureReason: action.error,\n }\n case 'pause':\n return {\n ...state,\n fetchStatus: 'paused',\n }\n case 'continue':\n return {\n ...state,\n fetchStatus: 'fetching',\n }\n case 'fetch':\n return {\n ...state,\n ...fetchState(state.data, this.options),\n fetchMeta: action.meta ?? null,\n }\n case 'success':\n const newState = {\n ...state,\n ...successState(action.data, action.dataUpdatedAt),\n dataUpdateCount: state.dataUpdateCount + 1,\n ...(!action.manual && {\n fetchStatus: 'idle' as const,\n fetchFailureCount: 0,\n fetchFailureReason: null,\n }),\n }\n // If fetching ends successfully, we don't need revertState as a fallback anymore.\n // For manual updates, capture the state to revert to it in case of a cancellation.\n this.#revertState = action.manual ? newState : undefined\n\n return newState\n case 'error':\n const error = action.error\n return {\n ...state,\n error,\n errorUpdateCount: state.errorUpdateCount + 1,\n errorUpdatedAt: Date.now(),\n fetchFailureCount: state.fetchFailureCount + 1,\n fetchFailureReason: error,\n fetchStatus: 'idle',\n status: 'error',\n // flag existing data as invalidated if we get a background error\n // note that \"no data\" always means stale so we can set unconditionally here\n isInvalidated: true,\n }\n case 'invalidate':\n return {\n ...state,\n isInvalidated: true,\n }\n case 'setState':\n return {\n ...state,\n ...action.state,\n }\n }\n }\n\n this.state = reducer(this.state)\n\n notifyManager.batch(() => {\n // Keep the current iteration stable if an observer unsubscribes\n // synchronously while it is being notified.\n this.observers.slice().forEach((observer) => {\n observer.onQueryUpdate()\n })\n\n this.#cache.notify({ query: this, type: 'updated', action })\n })\n }\n}\n\nexport function fetchState<\n TQueryFnData,\n TError,\n TData,\n TQueryKey extends QueryKey,\n>(\n data: TData | undefined,\n options: QueryOptions<TQueryFnData, TError, TData, TQueryKey>,\n) {\n return {\n fetchFailureCount: 0,\n fetchFailureReason: null,\n fetchStatus: canFetch(options.networkMode) ? 'fetching' : 'paused',\n ...(data === undefined &&\n ({\n error: null,\n status: 'pending',\n } as const)),\n } as const\n}\n\nfunction successState<TData>(data: TData | undefined, dataUpdatedAt?: number) {\n return {\n data,\n dataUpdatedAt: dataUpdatedAt ?? Date.now(),\n error: null,\n isInvalidated: false,\n status: 'success' as const,\n }\n}\n\nfunction getDefaultState<\n TQueryFnData,\n TError,\n TData,\n TQueryKey extends QueryKey,\n>(\n options: QueryOptions<TQueryFnData, TError, TData, TQueryKey>,\n): QueryState<TData, TError> {\n const data =\n typeof options.initialData === 'function'\n ? (options.initialData as InitialDataFunction<TData>)()\n : options.initialData\n\n const hasData = data !== undefined\n\n const initialDataUpdatedAt = hasData\n ? typeof options.initialDataUpdatedAt === 'function'\n ? options.initialDataUpdatedAt()\n : options.initialDataUpdatedAt\n : 0\n\n return {\n data,\n dataUpdateCount: 0,\n dataUpdatedAt: hasData ? (initialDataUpdatedAt ?? Date.now()) : 0,\n error: null,\n errorUpdateCount: 0,\n errorUpdatedAt: 0,\n fetchFailureCount: 0,\n fetchFailureReason: null,\n fetchMeta: null,\n isInvalidated: false,\n status: hasData ? 'success' : 'pending',\n fetchStatus: 'idle',\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAgOA,IAAa,QAAb,cAKU,UAAU;CAKlB;CAEA;CACA;CACA;CACA;CACA;CAEA;CACA;CAEA,YAAY,QAA6D;EACvE,MAAM;EAEN,KAAKA,uBAAuB;EAC5B,KAAKC,kBAAkB,OAAO;EAC9B,KAAK,WAAW,OAAO,OAAO;EAC9B,KAAK,YAAY,CAAC;EAClB,KAAKC,UAAU,OAAO;EACtB,KAAKC,SAAS,KAAKD,QAAQ,cAAc;EACzC,KAAK,WAAW,OAAO;EACvB,KAAK,YAAY,OAAO;EACxB,KAAKE,gBAAgB,gBAAgB,KAAK,OAAO;EACjD,KAAK,QAAQ,OAAO,SAAS,KAAKA;EAClC,KAAK,WAAW;CAClB;;;;CAIA,IAAI,OAA8B;EAChC,OAAO,KAAK,QAAQ;CACtB;;CAGA,IAAI,YAAY;EACd,OAAO,KAAKC;CACd;;;;;CAMA,IAAI,UAAsC;EACxC,OAAO,KAAKC,UAAU;CACxB;;CAGA,WACE,SACM;EACN,KAAK,UAAU;GAAE,GAAG,KAAKL;GAAiB,GAAG;EAAQ;EAErD,IAAI,SAAS,OACX,KAAKI,aAAa,QAAQ;EAG5B,KAAK,aAAa,KAAK,QAAQ,MAAM;EAGrC,IAAI,KAAK,SAAS,KAAK,MAAM,SAAS,KAAA,GAAW;GAC/C,M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,UAAU,SAAS,KAAA;CAEzB,MAAM,uBAAuB,UACzB,OAAO,QAAQ,yBAAyB,aACtC,QAAQ,qBAAqB,IAC7B,QAAQ,uBACV;CAEJ,OAAO;EACL;EACA,iBAAiB;EACjB,eAAe,UAAW,wBAAwB,KAAK,IAAI,IAAK;EAChE,OAAO;EACP,kBAAkB;EAClB,gBAAgB;EAChB,mBAAmB;EACnB,oBAAoB;EACpB,WAAW;EACX,eAAe;EACf,QAAQ,UAAU,YAAY;EAC9B,aAAa;CACf;AACF"}
1
+ {"version":3,"file":"query.js","names":[],"sources":["../../src/query.ts"],"sourcesContent":["import {\n ensureQueryFn,\n noop,\n replaceData,\n resolveQueryValue,\n skipToken,\n timeUntilStale,\n} from './utils'\nimport { notifyManager } from './notifyManager'\nimport { CancelledError, canFetch, createRetryer } from './retryer'\nimport { Removable } from './removable'\nimport { infiniteQueryBehavior } from './infiniteQueryBehavior'\nimport type { QueryCache } from './queryCache'\nimport type { QueryClient } from './queryClient'\nimport type {\n CancelOptions,\n DefaultError,\n FetchStatus,\n InitialDataFunction,\n OmitKeyof,\n QueryFunctionContext,\n QueryKey,\n QueryMeta,\n QueryOptions,\n QueryStatus,\n SetDataOptions,\n StaleTime,\n} from './types'\nimport type { QueryObserver } from './queryObserver'\nimport type { Retryer } from './retryer'\n\n// TYPES\n\ninterface QueryConfig<\n TQueryFnData,\n TError,\n TData,\n TQueryKey extends QueryKey = QueryKey,\n> {\n client: QueryClient\n queryKey: TQueryKey\n queryHash: string\n options?: QueryOptions<TQueryFnData, TError, TData, TQueryKey>\n defaultOptions?: QueryOptions<TQueryFnData, TError, TData, TQueryKey>\n state?: QueryState<TData, TError>\n}\n\n/**\n * The raw state stored on a `Query` instance. This is the underlying state\n * that observer results (e.g. `QueryObserverResult`) are derived from.\n */\nexport interface QueryState<TData = unknown, TError = DefaultError> {\n /**\n * The last successfully resolved data for the query.\n */\n data: TData | undefined\n /**\n * The number of times the query has successfully resolved.\n */\n dataUpdateCount: number\n /**\n * The timestamp for when the query most recently returned the `status` as `\"success\"`.\n */\n dataUpdatedAt: number\n /**\n * The error object for the query, if the last attempt resulted in an error.\n * - Defaults to `null`.\n */\n error: TError | null\n /**\n * The sum of all errors, incremented every time the query resolves with an error.\n */\n errorUpdateCount: number\n /**\n * The timestamp for when the query most recently returned the `status` as `\"error\"`.\n */\n errorUpdatedAt: number\n /**\n * The failure count for the current fetch.\n * - Incremented every time the fetch fails.\n * - Reset to `0` when the fetch succeeds.\n */\n fetchFailureCount: number\n /**\n * The reason the current fetch failed, as reported by the retryer.\n * - Reset to `null` when the fetch succeeds.\n */\n fetchFailureReason: TError | null\n /**\n * Metadata passed to the currently in-flight (or most recent) fetch, e.g. the\n * `fetchMore` direction for infinite queries.\n */\n fetchMeta: FetchMeta | null\n /**\n * Whether the query has been marked as invalidated via `invalidate()`.\n * - Reset to `false` whenever the query resolves successfully.\n */\n isInvalidated: boolean\n /**\n * The status of the query.\n * - `pending` if there's no cached data and no attempt was finished yet.\n * - `error` if the last attempt resulted in an error.\n * - `success` if the query has data.\n */\n status: QueryStatus\n /**\n * The fetch status of the query.\n * - `fetching`: the `queryFn` is currently executing.\n * - `paused`: a fetch wanted to run but has been paused (see network mode).\n * - `idle`: the query is not fetching.\n */\n fetchStatus: FetchStatus\n}\n\nexport interface FetchContext<\n TQueryFnData,\n TError,\n TData,\n TQueryKey extends QueryKey = QueryKey,\n> {\n fetchFn: () => unknown | Promise<unknown>\n fetchOptions?: FetchOptions\n signal: AbortSignal\n options: QueryOptions<TQueryFnData, TError, TData, any>\n client: QueryClient\n queryKey: TQueryKey\n state: QueryState<TData, TError>\n}\n\nexport interface QueryBehavior<\n TQueryFnData = unknown,\n TError = DefaultError,\n TData = TQueryFnData,\n TQueryKey extends QueryKey = QueryKey,\n> {\n onFetch: (\n context: FetchContext<TQueryFnData, TError, TData, TQueryKey>,\n query: Query,\n ) => void\n}\n\nexport type FetchDirection = 'forward' | 'backward'\n\nexport interface FetchMeta {\n fetchMore?: { direction: FetchDirection }\n}\n\nexport interface FetchOptions<TData = unknown> {\n cancelRefetch?: boolean\n meta?: FetchMeta\n initialPromise?: Promise<TData>\n}\n\ninterface FailedAction<TError> {\n type: 'failed'\n failureCount: number\n error: TError\n}\n\ninterface FetchAction {\n type: 'fetch'\n meta?: FetchMeta\n}\n\ninterface SuccessAction<TData> {\n data: TData | undefined\n type: 'success'\n dataUpdatedAt?: number\n manual?: boolean\n}\n\ninterface ErrorAction<TError> {\n type: 'error'\n error: TError\n}\n\ninterface InvalidateAction {\n type: 'invalidate'\n}\n\ninterface PauseAction {\n type: 'pause'\n}\n\ninterface ContinueAction {\n type: 'continue'\n}\n\ninterface SetStateAction<TData, TError> {\n type: 'setState'\n state: Partial<QueryState<TData, TError>>\n}\n\nexport type Action<TData, TError> =\n | ContinueAction\n | ErrorAction<TError>\n | FailedAction<TError>\n | FetchAction\n | InvalidateAction\n | PauseAction\n | SetStateAction<TData, TError>\n | SuccessAction<TData>\n\n// CLASS\n\n/**\n * Represents a single cached query. A `Query` holds the query's key, options,\n * state (data/error/status), and the observers currently subscribed to it.\n *\n * Instances are created and managed internally by `QueryCache`; application\n * code typically interacts with queries indirectly through `QueryClient` or\n * a framework hook like `useQuery`. Direct access to a `Query` instance is\n * possible via `queryCache.find()`/`findAll()` for inspecting cache state.\n *\n * @example\n * ```ts\n * const queryCache = queryClient.getQueryCache()\n * const query = queryCache.find({ queryKey: ['posts'] })\n *\n * if (query) {\n * console.log(query.state.dataUpdatedAt)\n * }\n * ```\n */\nexport class Query<\n TQueryFnData = unknown,\n TError = DefaultError,\n TData = TQueryFnData,\n TQueryKey extends QueryKey = QueryKey,\n> extends Removable {\n queryKey: TQueryKey\n queryHash: string\n options!: QueryOptions<TQueryFnData, TError, TData, TQueryKey>\n state: QueryState<TData, TError>\n #queryType?: 'infinite'\n\n #initialState: QueryState<TData, TError>\n #revertState?: QueryState<TData, TError>\n #cache: QueryCache\n #client: QueryClient\n #retryer?: Retryer<TData>\n observers: Array<QueryObserver<any, any, any, any, any>>\n #defaultOptions?: QueryOptions<TQueryFnData, TError, TData, TQueryKey>\n #abortSignalConsumed: boolean\n\n constructor(config: QueryConfig<TQueryFnData, TError, TData, TQueryKey>) {\n super()\n\n this.#abortSignalConsumed = false\n this.#defaultOptions = config.defaultOptions\n this.setOptions(config.options)\n this.observers = []\n this.#client = config.client\n this.#cache = this.#client.getQueryCache()\n this.queryKey = config.queryKey\n this.queryHash = config.queryHash\n this.#initialState = getDefaultState(this.options)\n this.state = config.state ?? this.#initialState\n this.scheduleGc()\n }\n /**\n * The `meta` object passed in the query's options, if any.\n */\n get meta(): QueryMeta | undefined {\n return this.options.meta\n }\n\n /** @internal */\n get queryType() {\n return this.#queryType\n }\n\n /**\n * The promise for the currently in-flight fetch, if the query is fetching.\n * `undefined` when the query is not fetching.\n */\n get promise(): Promise<TData> | undefined {\n return this.#retryer?.promise\n }\n\n /** @internal */\n setOptions(\n options?: QueryOptions<TQueryFnData, TError, TData, TQueryKey>,\n ): void {\n this.options = { ...this.#defaultOptions, ...options }\n\n if (options?._type) {\n this.#queryType = options._type\n }\n\n this.updateGcTime(this.options.gcTime)\n\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition\n if (this.state && this.state.data === undefined) {\n const defaultState = getDefaultState(this.options)\n if (defaultState.data !== undefined) {\n this.setState(\n successState(defaultState.data, defaultState.dataUpdatedAt),\n )\n this.#initialState = defaultState\n }\n }\n }\n\n protected optionalRemove() {\n if (!this.observers.length && this.state.fetchStatus === 'idle') {\n this.#cache.remove(this)\n }\n }\n\n /** @internal */\n setData(\n newData: TData,\n options?: SetDataOptions & { manual: boolean },\n ): TData {\n const data = replaceData(this.state.data, newData, this.options)\n\n // Set data and mark it as cached\n this.#dispatch({\n data,\n type: 'success',\n dataUpdatedAt: options?.updatedAt,\n manual: options?.manual,\n })\n\n return data\n }\n\n /**\n * Merges the given partial state directly into this query's state, notifying observers. Used\n * by persistence and broadcast plugins to restore a state snapshot, and by devtools to let a\n * user manually trigger a loading/error state or edit the cached data.\n */\n setState(state: Partial<QueryState<TData, TError>>): void {\n this.#dispatch({ type: 'setState', state })\n }\n\n /**\n * Cancels the query's currently in-flight fetch, if any.\n * - Returns a promise that resolves once the cancellation has settled.\n * - If no fetch is in progress, resolves immediately.\n *\n * @example\n * ```ts\n * await query.cancel()\n * ```\n */\n cancel(options?: CancelOptions): Promise<void> {\n const promise = this.#retryer?.promise\n this.#retryer?.cancel(options)\n return promise ? promise.then(noop).catch(noop) : Promise.resolve()\n }\n\n /**\n * Clears the query's garbage collection timeout and silently cancels any\n * in-flight fetch. Called by `QueryCache` when the query is removed from\n * the cache.\n *\n * @see {@link Query#cancel}\n */\n destroy(): void {\n super.destroy()\n\n this.cancel({ silent: true })\n }\n\n /** @internal */\n get resetState(): QueryState<TData, TError> {\n return this.#initialState\n }\n\n /**\n * Resets the query back to its initial state (the state it had when it was\n * first created, e.g. any `initialData`), destroying it first to cancel any\n * in-flight fetch.\n */\n reset(): void {\n this.destroy()\n this.setState(this.resetState)\n }\n\n /**\n * Returns `true` if the query has at least one observer for which `enabled`\n * does not resolve to `false`.\n */\n isActive(): boolean {\n return this.observers.some(\n (observer) => resolveQueryValue(observer.options.enabled, this) !== false,\n )\n }\n\n /**\n * Returns `true` if the query is disabled, meaning it will not fetch\n * automatically.\n * - If the query has observers, it is disabled when none of them are active\n * (see `isActive`).\n * - If the query has no observers, it is disabled when its `queryFn` is\n * `skipToken` or it has never been fetched.\n */\n isDisabled(): boolean {\n if (this.getObserversCount() > 0) {\n return !this.isActive()\n }\n // if a query has no observers, it should still be considered disabled if it never attempted a fetch\n return this.options.queryFn === skipToken || !this.isFetched()\n }\n\n /**\n * Returns `true` if the query has been fetched, i.e. it has resolved with\n * either data or an error at least once.\n */\n isFetched() {\n return this.state.dataUpdateCount + this.state.errorUpdateCount > 0\n }\n\n /**\n * Returns `true` if the query has at least one observer configured with\n * `staleTime: 'static'`, meaning it is treated as never stale.\n */\n isStatic(): boolean {\n if (this.getObserversCount() > 0) {\n return this.observers.some(\n (observer) =>\n resolveQueryValue(observer.options.staleTime, this) === 'static',\n )\n }\n\n return false\n }\n\n /**\n * Returns `true` if the query is stale.\n * - If the query has observers, defers to whether any observer's current\n * result reports `isStale` (which accounts for each observer's own\n * `staleTime` and `enabled` state).\n * - If the query has no observers, it is considered stale when it has no\n * data or has been invalidated.\n *\n * @see {@link Query#isStaleByTime}\n * @example\n * ```ts\n * if (query.isStale()) {\n * // refetch or otherwise treat the cached data as outdated\n * }\n * ```\n */\n isStale(): boolean {\n // check observers first, their `isStale` has the source of truth\n // calculated with `isStaleByTime` and it takes `enabled` into account\n if (this.getObserversCount() > 0) {\n return this.observers.some(\n (observer) => observer.getCurrentResult().isStale,\n )\n }\n\n return this.state.data === undefined || this.state.isInvalidated\n }\n\n /**\n * Returns `true` if the query's data is stale relative to the given\n * `staleTime` (defaults to `0`).\n * - A query with no data is always stale.\n * - `staleTime: 'static'` is never stale.\n * - An invalidated query is always stale.\n * - Otherwise, staleness is based on elapsed time since `dataUpdatedAt`.\n *\n * @see {@link Query#isStale}\n * @example\n * ```ts\n * const isStale = query.isStaleByTime(1000 * 60)\n * ```\n */\n isStaleByTime(staleTime: StaleTime = 0): boolean {\n // no data is always stale\n if (this.state.data === undefined) {\n return true\n }\n // static is never stale\n if (staleTime === 'static') {\n return false\n }\n // if the query is invalidated, it is stale\n if (this.state.isInvalidated) {\n return true\n }\n\n return !timeUntilStale(this.state.dataUpdatedAt, staleTime)\n }\n\n /** @internal */\n onFocus(): void {\n const observer = this.observers.find((x) => x.shouldFetchOnWindowFocus())\n\n observer?.refetch({ cancelRefetch: false })\n\n // Continue fetch if currently paused\n this.#retryer?.continue()\n }\n\n /** @internal */\n onOnline(): void {\n const observer = this.observers.find((x) => x.shouldFetchOnReconnect())\n\n observer?.refetch({ cancelRefetch: false })\n\n // Continue fetch if currently paused\n this.#retryer?.continue()\n }\n\n /** @internal */\n addObserver(observer: QueryObserver<any, any, any, any, any>): void {\n if (!this.observers.includes(observer)) {\n this.observers.push(observer)\n\n // Stop the query from being garbage collected\n this.clearGcTimeout()\n\n this.#cache.notify({ type: 'observerAdded', query: this, observer })\n }\n }\n\n /** @internal */\n removeObserver(observer: QueryObserver<any, any, any, any, any>): void {\n const index = this.observers.indexOf(observer)\n if (index !== -1) {\n this.observers.splice(index, 1)\n\n if (!this.observers.length) {\n // If the transport layer does not support cancellation\n // we'll let the query continue so the result can be cached\n if (this.#retryer) {\n if (\n this.#abortSignalConsumed ||\n (this.state.fetchStatus === 'paused' &&\n this.state.status === 'pending')\n ) {\n this.#retryer.cancel({ revert: true })\n } else {\n this.#retryer.cancelRetry()\n }\n }\n\n this.scheduleGc()\n }\n\n this.#cache.notify({ type: 'observerRemoved', query: this, observer })\n }\n }\n\n /**\n * Returns the number of observers currently subscribed to this query.\n *\n * @example\n * ```ts\n * if (query.getObserversCount() === 0) {\n * // no component is currently watching this query\n * }\n * ```\n */\n getObserversCount(): number {\n return this.observers.length\n }\n\n /**\n * Marks the query as invalidated, unless it is already invalidated. This\n * updates `state.isInvalidated` and notifies observers, but does not by\n * itself trigger a refetch.\n *\n * @example\n * ```ts\n * query.invalidate()\n * ```\n */\n invalidate(): void {\n if (!this.state.isInvalidated) {\n this.#dispatch({ type: 'invalidate' })\n }\n }\n\n /**\n * Fetches the query, i.e. runs its `queryFn` (through any configured\n * retryer/behavior) and updates the query's state with the result.\n * - If a fetch is already in flight, returns its promise instead of\n * starting a new one, unless `fetchOptions.cancelRefetch` is set and the\n * query already has data, in which case the current fetch is silently\n * cancelled first.\n * - If `options` is passed, it replaces the query's current options\n * before fetching.\n */\n async fetch(\n options?: QueryOptions<TQueryFnData, TError, TData, TQueryKey>,\n fetchOptions?: FetchOptions<TQueryFnData>,\n ): Promise<TData> {\n if (\n this.state.fetchStatus !== 'idle' &&\n // If the promise in the retryer is already rejected, we have to definitely\n // re-start the fetch; there is a chance that the query is still in a\n // pending state when that happens\n this.#retryer?.status() !== 'rejected'\n ) {\n if (this.state.data !== undefined && fetchOptions?.cancelRefetch) {\n // Silently cancel current fetch if the user wants to cancel refetch\n this.cancel({ silent: true })\n } else if (this.#retryer) {\n // make sure that retries that were potentially cancelled due to unmounts can continue\n this.#retryer.continueRetry()\n // Return current promise if we are already fetching\n return this.#retryer.promise\n }\n }\n\n // Update config if passed, otherwise the config from the last execution is used\n if (options) {\n this.setOptions(options)\n }\n\n // Use the options from the first observer with a query function if no function is found.\n // This can happen when the query is hydrated or created with setQueryData.\n if (!this.options.queryFn) {\n const observer = this.observers.find((x) => x.options.queryFn)\n if (observer) {\n this.setOptions(observer.options)\n }\n }\n\n if (process.env.NODE_ENV !== 'production') {\n if (!Array.isArray(this.options.queryKey)) {\n console.error(\n `As of v4, queryKey needs to be an Array. If you are using a string like 'repoData', please change it to an Array, e.g. ['repoData']`,\n )\n }\n }\n\n const abortController = new AbortController()\n\n // Adds an enumerable signal property to the object that\n // which sets abortSignalConsumed to true when the signal\n // is read.\n const addSignalProperty = (object: unknown) => {\n Object.defineProperty(object, 'signal', {\n enumerable: true,\n get: () => {\n this.#abortSignalConsumed = true\n return abortController.signal\n },\n })\n }\n\n // Create fetch function\n const fetchFn = () => {\n const queryFn = ensureQueryFn(this.options, fetchOptions)\n\n // Create query function context\n const createQueryFnContext = (): QueryFunctionContext<TQueryKey> => {\n const queryFnContext: OmitKeyof<\n QueryFunctionContext<TQueryKey>,\n 'signal'\n > = {\n client: this.#client,\n queryKey: this.queryKey,\n meta: this.meta,\n }\n addSignalProperty(queryFnContext)\n return queryFnContext as QueryFunctionContext<TQueryKey>\n }\n\n const queryFnContext = createQueryFnContext()\n\n this.#abortSignalConsumed = false\n if (this.options.persister) {\n return this.options.persister(\n queryFn,\n queryFnContext,\n this as unknown as Query,\n )\n }\n\n return queryFn(queryFnContext)\n }\n\n // Trigger behavior hook\n const createFetchContext = (): FetchContext<\n TQueryFnData,\n TError,\n TData,\n TQueryKey\n > => {\n const context: OmitKeyof<\n FetchContext<TQueryFnData, TError, TData, TQueryKey>,\n 'signal'\n > = {\n fetchOptions,\n options: this.options,\n queryKey: this.queryKey,\n client: this.#client,\n state: this.state,\n fetchFn,\n }\n\n addSignalProperty(context)\n return context as FetchContext<TQueryFnData, TError, TData, TQueryKey>\n }\n\n const context = createFetchContext()\n\n const behavior =\n this.#queryType === 'infinite'\n ? (infiniteQueryBehavior(\n (this.options as { pages?: number }).pages,\n ) as QueryBehavior<TQueryFnData, TError, TData, TQueryKey>)\n : this.options.behavior\n behavior?.onFetch(context, this as unknown as Query)\n\n // Store state in case the current fetch needs to be reverted\n this.#revertState = this.state\n\n // Set to fetching state if not already in it\n if (\n this.state.fetchStatus === 'idle' ||\n this.state.fetchMeta !== context.fetchOptions?.meta\n ) {\n this.#dispatch({ type: 'fetch', meta: context.fetchOptions?.meta })\n }\n\n // Try to fetch the data\n const retryer = (this.#retryer = createRetryer({\n initialPromise: fetchOptions?.initialPromise as\n Promise<TData> | undefined,\n fn: context.fetchFn as () => Promise<TData>,\n onCancel: (error) => {\n if (error instanceof CancelledError && error.revert) {\n this.setState({\n ...this.#revertState,\n fetchStatus: 'idle' as const,\n })\n }\n abortController.abort()\n },\n onFail: (failureCount, error) => {\n this.#dispatch({ type: 'failed', failureCount, error })\n },\n onPause: () => {\n this.#dispatch({ type: 'pause' })\n },\n onContinue: () => {\n this.#dispatch({ type: 'continue' })\n },\n retry: context.options.retry,\n retryDelay: context.options.retryDelay,\n networkMode: context.options.networkMode,\n canRun: () => true,\n }))\n\n try {\n const data = await retryer.start()\n // this is more of a runtime guard\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition\n if (data === undefined) {\n if (process.env.NODE_ENV !== 'production') {\n console.error(\n `Query data cannot be undefined. Please make sure to return a value other than undefined from your query function. Affected query key: ${this.queryHash}`,\n )\n }\n throw new Error(`${this.queryHash} data is undefined`)\n }\n\n this.setData(data)\n\n // Notify cache callback\n this.#cache.config.onSuccess?.(data, this as Query<any, any, any, any>)\n this.#cache.config.onSettled?.(\n data,\n this.state.error as any,\n this as Query<any, any, any, any>,\n )\n return data\n } catch (error) {\n if (error instanceof CancelledError) {\n if (error.silent) {\n // silent cancellation implies a new fetch is going to be started,\n // so we piggyback onto that promise\n return this.#retryer.promise\n } else if (error.revert) {\n // transform error into reverted state data\n // if the initial fetch was cancelled, we have no data, so we have\n // to get reject with a CancelledError\n if (this.state.data === undefined) {\n throw error\n }\n return this.state.data\n }\n }\n this.#dispatch({\n type: 'error',\n error: error as TError,\n })\n\n // Notify cache callback\n this.#cache.config.onError?.(\n error as any,\n this as Query<any, any, any, any>,\n )\n this.#cache.config.onSettled?.(\n this.state.data,\n error as any,\n this as Query<any, any, any, any>,\n )\n\n throw error // rethrow the error for further handling\n } finally {\n // The settled retryer's promise would otherwise pin this fetch's raw\n // result (a second copy after structural sharing) for the query's lifetime\n if (this.#retryer === retryer) {\n this.#retryer = undefined\n }\n // Schedule query gc after fetching\n this.scheduleGc()\n }\n }\n\n #dispatch(action: Action<TData, TError>): void {\n const reducer = (\n state: QueryState<TData, TError>,\n ): QueryState<TData, TError> => {\n switch (action.type) {\n case 'failed':\n return {\n ...state,\n fetchFailureCount: action.failureCount,\n fetchFailureReason: action.error,\n }\n case 'pause':\n return {\n ...state,\n fetchStatus: 'paused',\n }\n case 'continue':\n return {\n ...state,\n fetchStatus: 'fetching',\n }\n case 'fetch':\n return {\n ...state,\n ...fetchState(state.data, this.options),\n fetchMeta: action.meta ?? null,\n }\n case 'success':\n const newState = {\n ...state,\n ...successState(action.data, action.dataUpdatedAt),\n dataUpdateCount: state.dataUpdateCount + 1,\n ...(!action.manual && {\n fetchStatus: 'idle' as const,\n fetchFailureCount: 0,\n fetchFailureReason: null,\n }),\n }\n // If fetching ends successfully, we don't need revertState as a fallback anymore.\n // For manual updates, capture the state to revert to it in case of a cancellation.\n this.#revertState = action.manual ? newState : undefined\n\n return newState\n case 'error':\n const error = action.error\n return {\n ...state,\n error,\n errorUpdateCount: state.errorUpdateCount + 1,\n errorUpdatedAt: Date.now(),\n fetchFailureCount: state.fetchFailureCount + 1,\n fetchFailureReason: error,\n fetchStatus: 'idle',\n status: 'error',\n // flag existing data as invalidated if we get a background error\n // note that \"no data\" always means stale so we can set unconditionally here\n isInvalidated: true,\n }\n case 'invalidate':\n return {\n ...state,\n isInvalidated: true,\n }\n case 'setState':\n return {\n ...state,\n ...action.state,\n }\n }\n }\n\n this.state = reducer(this.state)\n\n notifyManager.batch(() => {\n // Keep the current iteration stable if an observer unsubscribes\n // synchronously while it is being notified.\n this.observers.slice().forEach((observer) => {\n observer.onQueryUpdate()\n })\n\n this.#cache.notify({ query: this, type: 'updated', action })\n })\n }\n}\n\nexport function fetchState<\n TQueryFnData,\n TError,\n TData,\n TQueryKey extends QueryKey,\n>(\n data: TData | undefined,\n options: QueryOptions<TQueryFnData, TError, TData, TQueryKey>,\n) {\n return {\n fetchFailureCount: 0,\n fetchFailureReason: null,\n fetchStatus: canFetch(options.networkMode) ? 'fetching' : 'paused',\n ...(data === undefined &&\n ({\n error: null,\n status: 'pending',\n } as const)),\n } as const\n}\n\nfunction successState<TData>(data: TData | undefined, dataUpdatedAt?: number) {\n return {\n data,\n dataUpdatedAt: dataUpdatedAt ?? Date.now(),\n error: null,\n isInvalidated: false,\n status: 'success' as const,\n }\n}\n\nfunction getDefaultState<\n TQueryFnData,\n TError,\n TData,\n TQueryKey extends QueryKey,\n>(\n options: QueryOptions<TQueryFnData, TError, TData, TQueryKey>,\n): QueryState<TData, TError> {\n const data =\n typeof options.initialData === 'function'\n ? (options.initialData as InitialDataFunction<TData>)()\n : options.initialData\n\n const hasData = data !== undefined\n\n const initialDataUpdatedAt = hasData\n ? typeof options.initialDataUpdatedAt === 'function'\n ? options.initialDataUpdatedAt()\n : options.initialDataUpdatedAt\n : 0\n\n return {\n data,\n dataUpdateCount: 0,\n dataUpdatedAt: hasData ? (initialDataUpdatedAt ?? Date.now()) : 0,\n error: null,\n errorUpdateCount: 0,\n errorUpdatedAt: 0,\n fetchFailureCount: 0,\n fetchFailureReason: null,\n fetchMeta: null,\n isInvalidated: false,\n status: hasData ? 'success' : 'pending',\n fetchStatus: 'idle',\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAgOA,IAAa,QAAb,cAKU,UAAU;CAKlB;CAEA;CACA;CACA;CACA;CACA;CAEA;CACA;CAEA,YAAY,QAA6D;EACvE,MAAM;EAEN,KAAK,uBAAuB;EAC5B,KAAK,kBAAkB,OAAO;EAC9B,KAAK,WAAW,OAAO,OAAO;EAC9B,KAAK,YAAY,CAAC;EAClB,KAAK,UAAU,OAAO;EACtB,KAAK,SAAS,KAAK,QAAQ,cAAc;EACzC,KAAK,WAAW,OAAO;EACvB,KAAK,YAAY,OAAO;EACxB,KAAK,gBAAgB,gBAAgB,KAAK,OAAO;EACjD,KAAK,QAAQ,OAAO,SAAS,KAAK;EAClC,KAAK,WAAW;CAClB;;;;CAIA,IAAI,OAA8B;EAChC,OAAO,KAAK,QAAQ;CACtB;;CAGA,IAAI,YAAY;EACd,OAAO,KAAK;CACd;;;;;CAMA,IAAI,UAAsC;EACxC,OAAO,KAAK,UAAU;CACxB;;CAGA,WACE,SACM;EACN,KAAK,UAAU;GAAE,GAAG,KAAK;GAAiB,GAAG;EAAQ;EAErD,IAAI,SAAS,OACX,KAAK,aAAa,QAAQ;EAG5B,KAAK,aAAa,KAAK,QAAQ,MAAM;EAGrC,IAAI,KAAK,SAAS,KAAK,MAAM,SAAS,KAAA,GAAW;GAC/C,MAAM,eAAe,gBAAgB,KAAK,OAAO;GACjD,IAAI,aAAa,SAAS,KAAA,GAAW;IACnC,KAAK,SACH,aAAa,aAAa,MAAM,aAAa,aAAa,CAC5D;IACA,KAAK,gBAAgB;GACvB;EACF;CACF;CAEA,iBAA2B;EACzB,IAAI,CAAC,KAAK,UAAU,UAAU,KAAK,MAAM,gBAAgB,QACvD,KAAK,OAAO,OAAO,IAAI;CAE3B;;CAGA,QACE,SACA,SACO;EACP,MAAM,OAAO,YAAY,KAAK,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names":["Subscribable","#queries","hashQueryKeyByOptions","Query","matchQuery"],"sources":["../../src/queryCache.ts"],"sourcesContent":["import { hashQueryKeyByOptions, matchQuery } from './utils'\nimport { Query } from './query'\nimport { notifyManager } from './notifyManager'\nimport { Subscribable } from './subscribable'\nimport type { QueryFilters } from './utils'\nimport type { Action, QueryState } from './query'\nimport type {\n DefaultError,\n NotifyEvent,\n QueryKey,\n QueryOptions,\n WithRequired,\n} from './types'\nimport type { QueryClient } from './queryClient'\nimport type { QueryObserver } from './queryObserver'\n\n// TYPES\n\n/**\n * Global callbacks that fire for every query handled by a `QueryCache`, regardless of which\n * component or observer triggered it. Unlike `QueryClient`'s `defaultOptions`, which a query can\n * override, these callbacks are always called. Unlike `MutationCacheConfig`'s callbacks, these\n * are fire-and-forget: their return value is not awaited before the query settles.\n */\nexport interface QueryCacheConfig {\n /** Called when any query in the cache encounters an error. */\n onError?: (\n error: DefaultError,\n query: Query<unknown, unknown, unknown>,\n ) => void\n /** Called when any query in the cache is successful. */\n onSuccess?: (data: unknown, query: Query<unknown, unknown, unknown>) => void\n /** Called when any query in the cache is settled, either successfully or with an error. */\n onSettled?: (\n data: unknown | undefined,\n error: DefaultError | null,\n query: Query<unknown, unknown, unknown>,\n ) => void\n}\n\ninterface NotifyEventQueryAdded extends NotifyEvent {\n type: 'added'\n query: Query<any, any, any, any>\n}\n\ninterface NotifyEventQueryRemoved extends NotifyEvent {\n type: 'removed'\n query: Query<any, any, any, any>\n}\n\ninterface NotifyEventQueryUpdated extends NotifyEvent {\n type: 'updated'\n query: Query<any, any, any, any>\n action: Action<any, any>\n}\n\ninterface NotifyEventQueryObserverAdded extends NotifyEvent {\n type: 'observerAdded'\n query: Query<any, any, any, any>\n observer: QueryObserver<any, any, any, any, any>\n}\n\ninterface NotifyEventQueryObserverRemoved extends NotifyEvent {\n type: 'observerRemoved'\n query: Query<any, any, any, any>\n observer: QueryObserver<any, any, any, any, any>\n}\n\ninterface NotifyEventQueryObserverResultsUpdated extends NotifyEvent {\n type: 'observerResultsUpdated'\n query: Query<any, any, any, any>\n}\n\ninterface NotifyEventQueryObserverOptionsUpdated extends NotifyEvent {\n type: 'observerOptionsUpdated'\n query: Query<any, any, any, any>\n observer: QueryObserver<any, any, any, any, any>\n}\n\n/**\n * The event passed to a `QueryCache` subscriber. Fired whenever a query is added or removed from\n * the cache, its state is updated (e.g. via `query.setState` or `queryClient.removeQueries`), or\n * one of its observers is added, removed, or has its results or options updated.\n */\nexport type QueryCacheNotifyEvent =\n | NotifyEventQueryAdded\n | NotifyEventQueryRemoved\n | NotifyEventQueryUpdated\n | NotifyEventQueryObserverAdded\n | NotifyEventQueryObserverRemoved\n | NotifyEventQueryObserverResultsUpdated\n | NotifyEventQueryObserverOptionsUpdated\n\ntype QueryCacheListener = (event: QueryCacheNotifyEvent) => void\n\nexport interface QueryStore {\n has: (queryHash: string) => boolean\n set: (queryHash: string, query: Query) => void\n get: (queryHash: string) => Query | undefined\n delete: (queryHash: string) => void\n values: () => IterableIterator<Query>\n}\n\n// CLASS\n\n/**\n * The `QueryCache` is the storage mechanism for TanStack Query. It stores all the data, meta\n * information, and state of the queries it contains.\n *\n * Normally, you will not interact with the `QueryCache` directly and instead use a `QueryClient`\n * for a specific cache. You can subscribe to it (inherited from `Subscribable`) to be informed of\n * safe/known updates to the cache, such as queries being added, removed, or updated — updates made\n * outside of the cache's own tracked mechanisms (e.g. mutating a query's state object directly) do\n * not notify subscribers.\n *\n * @example\n * ```ts\n * const unsubscribe = queryCache.subscribe((event) => {\n * console.log(event.type, event.query)\n * })\n * ```\n */\nexport class QueryCache extends Subscribable<QueryCacheListener> {\n #queries: QueryStore\n\n constructor(public config: QueryCacheConfig = {}) {\n super()\n this.#queries = new Map<string, Query>()\n }\n\n /**\n * Returns the existing `Query` instance for the given options' `queryKey`/`queryHash`, or\n * builds and adds a new one to the cache if none exists yet. Used by framework adapters and\n * plugins (e.g. broadcast/persistence) that need to get-or-create a `Query` directly, bypassing\n * the reactive `QueryObserver` machinery.\n *\n * @example\n * ```ts\n * const queryCache = queryClient.getQueryCache()\n *\n * const query = queryCache.build(queryClient, {\n * queryKey: ['posts'],\n * queryFn: fetchPosts,\n * })\n * ```\n */\n build<\n TQueryFnData = unknown,\n TError = DefaultError,\n TData = TQueryFnData,\n TQueryKey extends QueryKey = QueryKey,\n >(\n client: QueryClient,\n options: WithRequired<\n QueryOptions<TQueryFnData, TError, TData, TQueryKey>,\n 'queryKey'\n >,\n state?: QueryState<TData, TError>,\n ): Query<TQueryFnData, TError, TData, TQueryKey> {\n const queryKey = options.queryKey\n const queryHash =\n options.queryHash ?? hashQueryKeyByOptions(queryKey, options)\n let query = this.get<TQueryFnData, TError, TData, TQueryKey>(queryHash)\n\n if (!query) {\n query = new Query({\n client,\n queryKey,\n queryHash,\n options: client.defaultQueryOptions(options),\n state,\n defaultOptions: client.getQueryDefaults(queryKey),\n })\n this.add(query)\n }\n\n return query\n }\n\n /** @internal */\n add(query: Query<any, any, any, any>): void {\n if (!this.#queries.has(query.queryHash)) {\n this.#queries.set(query.queryHash, query)\n\n this.notify({\n type: 'added',\n query,\n })\n }\n }\n\n /**\n * Destroys the given `Query` and removes it from the cache, notifying subscribers with a\n * `'removed'` event. A no-op if the query is no longer the one currently stored under its hash\n * (e.g. it was already replaced). Used by plugins (e.g. the broadcast client) that mirror\n * removals across `QueryCache` instances.\n *\n * @example\n * ```ts\n * const queryCache = queryClient.getQueryCache()\n * const query = queryCache.find({ queryKey: ['posts'] })\n *\n * if (query) {\n * queryCache.remove(query)\n * }\n * ```\n */\n remove(query: Query<any, any, any, any>): void {\n const queryInMap = this.#queries.get(query.queryHash)\n\n if (queryInMap === query) {\n query.destroy()\n this.#queries.delete(query.queryHash)\n this.notify({ type: 'removed', query })\n }\n }\n\n /**\n * Removes all queries from the cache.\n *\n * @example\n * ```ts\n * const queryCache = queryClient.getQueryCache()\n *\n * queryCache.clear()\n * ```\n */\n clear(): void {\n notifyManager.batch(() => {\n this.getAll().forEach((query) => {\n this.remove(query)\n })\n })\n }\n\n /**\n * Returns the `Query` instance stored under the given `queryHash`, or `undefined` if none\n * exists. Unlike {@link QueryCache#find}, this looks up by the already-computed hash rather\n * than by `QueryFilters`. Used by plugins (e.g. broadcast/hydration) that already have a hash\n * to look up directly.\n *\n * @example\n * ```ts\n * const queryCache = queryClient.getQueryCache()\n * const queryHash = hashKey(['posts'])\n *\n * const query = queryCache.get(queryHash)\n * ```\n */\n get<\n TQueryFnData = unknown,\n TError = DefaultError,\n TData = TQueryFnData,\n TQueryKey extends QueryKey = QueryKey,\n >(\n queryHash: string,\n ): Query<TQueryFnData, TError, TData, TQueryKey> | undefined {\n return this.#queries.get(queryHash) as\n | Query<TQueryFnData, TError, TData, TQueryKey>\n | undefined\n }\n\n /**\n * Returns all queries within the cache.\n *\n * @example\n * ```ts\n * const queryCache = queryClient.getQueryCache()\n *\n * const queries = queryCache.getAll()\n * ```\n */\n getAll(): Array<Query> {\n return [...this.#queries.values()]\n }\n\n /**\n * A slightly more advanced method that can be used to get an existing query instance from the\n * cache. This instance not only contains all the state for the query, but all of the instances,\n * and underlying guts of the query as well. If the query does not exist, `undefined` is\n * returned.\n *\n * This is not typically needed for most applications, but can come in handy when needing more\n * information about a query in rare scenarios (e.g. looking at `query.state.dataUpdatedAt` to\n * decide whether a query is fresh enough to be used as an initial value).\n *\n * @see {@link QueryCache#findAll}\n * @example\n * ```ts\n * const queryCache = queryClient.getQueryCache()\n *\n * const query = queryCache.find({ queryKey: ['posts'] })\n * ```\n */\n find<TQueryFnData = unknown, TError = DefaultError, TData = TQueryFnData>(\n filters: WithRequired<QueryFilters, 'queryKey'>,\n ): Query<TQueryFnData, TError, TData> | undefined {\n const defaultedFilters = { exact: true, ...filters }\n\n return this.getAll().find((query) =>\n matchQuery(defaultedFilters, query),\n ) as Query<TQueryFnData, TError, TData> | undefined\n }\n\n /**\n * An even more advanced method that can be used to get existing query instances from the cache\n * that partially match a query key. If no queries match, an empty array is returned.\n *\n * This is not typically needed for most applications, but can come in handy when needing more\n * information about queries in rare scenarios.\n *\n * @see {@link QueryCache#find}\n * @example\n * ```ts\n * const queryCache = queryClient.getQueryCache()\n *\n * const queries = queryCache.findAll({ queryKey: ['posts'] })\n * ```\n */\n findAll(filters: QueryFilters<any> = {}): Array<Query> {\n const queries = this.getAll()\n return Object.keys(filters).length > 0\n ? queries.filter((query) => matchQuery(filters, query))\n : queries\n }\n\n /** @internal */\n notify(event: QueryCacheNotifyEvent): void {\n notifyManager.batch(() => {\n this.listeners.forEach((listener) => {\n listener(event)\n })\n })\n }\n\n /** @internal */\n onFocus(): void {\n notifyManager.batch(() => {\n this.getAll().forEach((query) => {\n query.onFocus()\n })\n })\n }\n\n /** @internal */\n onOnline(): void {\n notifyManager.batch(() => {\n this.getAll().forEach((query) => {\n query.onOnline()\n })\n })\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AA0HA,IAAa,aAAb,cAAgCA,qBAAAA,aAAiC;CAC/D;CAEA,YAAY,SAAkC,CAAC,GAAG;EAChD,MAAM;EADW,KAAA,SAAA;EAEjB,KAAKC,2BAAW,IAAI,IAAmB;CACzC;;;;;;;;;;;;;;;;;CAkBA,MAME,QACA,SAIA,OAC+C;EAC/C,MAAM,WAAW,QAAQ;EACzB,MAAM,YACJ,QAAQ,aAAaC,cAAAA,sBAAsB,UAAU,OAAO;EAC9D,IAAI,QAAQ,KAAK,IAA4C,SAAS;EAEtE,IAAI,CAAC,OAAO;GACV,QAAQ,IAAIC,cAAAA,MAAM;IAChB;IACA;IACA;IACA,SAAS,OAAO,oBAAoB,OAAO;IAC3C;IACA,gBAAgB,OAAO,iBAAiB,QAAQ;GAClD,CAAC;GACD,KAAK,IAAI,KAAK;EAChB;EAEA,OAAO;CACT;;CAGA,IAAI,OAAwC;EAC1C,IAAI,CAAC,KAAKF,SAAS,IAAI,MAAM,SAAS,GAAG;GACvC,KAAKA,SAAS,IAAI,MAAM,WAAW,KAAK;GAExC,KAAK,OAAO;IACV,MAAM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AO,CAAC,CAAC,SAAS,UAAU;IAC/B,MAAM,SAAS;GACjB,CAAC;EACH,CAAC;CACH;AACF"}
1
+ {"version":3,"file":"queryCache.cjs","names":["Subscribable","hashQueryKeyByOptions","Query","matchQuery"],"sources":["../../src/queryCache.ts"],"sourcesContent":["import { hashQueryKeyByOptions, matchQuery } from './utils'\nimport { Query } from './query'\nimport { notifyManager } from './notifyManager'\nimport { Subscribable } from './subscribable'\nimport type { QueryFilters } from './utils'\nimport type { Action, QueryState } from './query'\nimport type {\n DefaultError,\n NotifyEvent,\n QueryKey,\n QueryOptions,\n WithRequired,\n} from './types'\nimport type { QueryClient } from './queryClient'\nimport type { QueryObserver } from './queryObserver'\n\n// TYPES\n\n/**\n * Global callbacks that fire for every query handled by a `QueryCache`, regardless of which\n * component or observer triggered it. Unlike `QueryClient`'s `defaultOptions`, which a query can\n * override, these callbacks are always called. Unlike `MutationCacheConfig`'s callbacks, these\n * are fire-and-forget: their return value is not awaited before the query settles.\n */\nexport interface QueryCacheConfig {\n /** Called when any query in the cache encounters an error. */\n onError?: (\n error: DefaultError,\n query: Query<unknown, unknown, unknown>,\n ) => void\n /** Called when any query in the cache is successful. */\n onSuccess?: (data: unknown, query: Query<unknown, unknown, unknown>) => void\n /** Called when any query in the cache is settled, either successfully or with an error. */\n onSettled?: (\n data: unknown | undefined,\n error: DefaultError | null,\n query: Query<unknown, unknown, unknown>,\n ) => void\n}\n\ninterface NotifyEventQueryAdded extends NotifyEvent {\n type: 'added'\n query: Query<any, any, any, any>\n}\n\ninterface NotifyEventQueryRemoved extends NotifyEvent {\n type: 'removed'\n query: Query<any, any, any, any>\n}\n\ninterface NotifyEventQueryUpdated extends NotifyEvent {\n type: 'updated'\n query: Query<any, any, any, any>\n action: Action<any, any>\n}\n\ninterface NotifyEventQueryObserverAdded extends NotifyEvent {\n type: 'observerAdded'\n query: Query<any, any, any, any>\n observer: QueryObserver<any, any, any, any, any>\n}\n\ninterface NotifyEventQueryObserverRemoved extends NotifyEvent {\n type: 'observerRemoved'\n query: Query<any, any, any, any>\n observer: QueryObserver<any, any, any, any, any>\n}\n\ninterface NotifyEventQueryObserverResultsUpdated extends NotifyEvent {\n type: 'observerResultsUpdated'\n query: Query<any, any, any, any>\n}\n\ninterface NotifyEventQueryObserverOptionsUpdated extends NotifyEvent {\n type: 'observerOptionsUpdated'\n query: Query<any, any, any, any>\n observer: QueryObserver<any, any, any, any, any>\n}\n\n/**\n * The event passed to a `QueryCache` subscriber. Fired whenever a query is added or removed from\n * the cache, its state is updated (e.g. via `query.setState` or `queryClient.removeQueries`), or\n * one of its observers is added, removed, or has its results or options updated.\n */\nexport type QueryCacheNotifyEvent =\n | NotifyEventQueryAdded\n | NotifyEventQueryRemoved\n | NotifyEventQueryUpdated\n | NotifyEventQueryObserverAdded\n | NotifyEventQueryObserverRemoved\n | NotifyEventQueryObserverResultsUpdated\n | NotifyEventQueryObserverOptionsUpdated\n\ntype QueryCacheListener = (event: QueryCacheNotifyEvent) => void\n\nexport interface QueryStore {\n has: (queryHash: string) => boolean\n set: (queryHash: string, query: Query) => void\n get: (queryHash: string) => Query | undefined\n delete: (queryHash: string) => void\n values: () => IterableIterator<Query>\n}\n\n// CLASS\n\n/**\n * The `QueryCache` is the storage mechanism for TanStack Query. It stores all the data, meta\n * information, and state of the queries it contains.\n *\n * Normally, you will not interact with the `QueryCache` directly and instead use a `QueryClient`\n * for a specific cache. You can subscribe to it (inherited from `Subscribable`) to be informed of\n * safe/known updates to the cache, such as queries being added, removed, or updated — updates made\n * outside of the cache's own tracked mechanisms (e.g. mutating a query's state object directly) do\n * not notify subscribers.\n *\n * @example\n * ```ts\n * const unsubscribe = queryCache.subscribe((event) => {\n * console.log(event.type, event.query)\n * })\n * ```\n */\nexport class QueryCache extends Subscribable<QueryCacheListener> {\n #queries: QueryStore\n\n constructor(public config: QueryCacheConfig = {}) {\n super()\n this.#queries = new Map<string, Query>()\n }\n\n /**\n * Returns the existing `Query` instance for the given options' `queryKey`/`queryHash`, or\n * builds and adds a new one to the cache if none exists yet. Used by framework adapters and\n * plugins (e.g. broadcast/persistence) that need to get-or-create a `Query` directly, bypassing\n * the reactive `QueryObserver` machinery.\n *\n * @example\n * ```ts\n * const queryCache = queryClient.getQueryCache()\n *\n * const query = queryCache.build(queryClient, {\n * queryKey: ['posts'],\n * queryFn: fetchPosts,\n * })\n * ```\n */\n build<\n TQueryFnData = unknown,\n TError = DefaultError,\n TData = TQueryFnData,\n TQueryKey extends QueryKey = QueryKey,\n >(\n client: QueryClient,\n options: WithRequired<\n QueryOptions<TQueryFnData, TError, TData, TQueryKey>,\n 'queryKey'\n >,\n state?: QueryState<TData, TError>,\n ): Query<TQueryFnData, TError, TData, TQueryKey> {\n const queryKey = options.queryKey\n const queryHash =\n options.queryHash ?? hashQueryKeyByOptions(queryKey, options)\n let query = this.get<TQueryFnData, TError, TData, TQueryKey>(queryHash)\n\n if (!query) {\n query = new Query({\n client,\n queryKey,\n queryHash,\n options: client.defaultQueryOptions(options),\n state,\n defaultOptions: client.getQueryDefaults(queryKey),\n })\n this.add(query)\n }\n\n return query\n }\n\n /** @internal */\n add(query: Query<any, any, any, any>): void {\n if (!this.#queries.has(query.queryHash)) {\n this.#queries.set(query.queryHash, query)\n\n this.notify({\n type: 'added',\n query,\n })\n }\n }\n\n /**\n * Destroys the given `Query` and removes it from the cache, notifying subscribers with a\n * `'removed'` event. A no-op if the query is no longer the one currently stored under its hash\n * (e.g. it was already replaced). Used by plugins (e.g. the broadcast client) that mirror\n * removals across `QueryCache` instances.\n *\n * @example\n * ```ts\n * const queryCache = queryClient.getQueryCache()\n * const query = queryCache.find({ queryKey: ['posts'] })\n *\n * if (query) {\n * queryCache.remove(query)\n * }\n * ```\n */\n remove(query: Query<any, any, any, any>): void {\n const queryInMap = this.#queries.get(query.queryHash)\n\n if (queryInMap === query) {\n query.destroy()\n this.#queries.delete(query.queryHash)\n this.notify({ type: 'removed', query })\n }\n }\n\n /**\n * Removes all queries from the cache.\n *\n * @example\n * ```ts\n * const queryCache = queryClient.getQueryCache()\n *\n * queryCache.clear()\n * ```\n */\n clear(): void {\n notifyManager.batch(() => {\n this.getAll().forEach((query) => {\n this.remove(query)\n })\n })\n }\n\n /**\n * Returns the `Query` instance stored under the given `queryHash`, or `undefined` if none\n * exists. Unlike {@link QueryCache#find}, this looks up by the already-computed hash rather\n * than by `QueryFilters`. Used by plugins (e.g. broadcast/hydration) that already have a hash\n * to look up directly.\n *\n * @example\n * ```ts\n * const queryCache = queryClient.getQueryCache()\n * const queryHash = hashKey(['posts'])\n *\n * const query = queryCache.get(queryHash)\n * ```\n */\n get<\n TQueryFnData = unknown,\n TError = DefaultError,\n TData = TQueryFnData,\n TQueryKey extends QueryKey = QueryKey,\n >(\n queryHash: string,\n ): Query<TQueryFnData, TError, TData, TQueryKey> | undefined {\n return this.#queries.get(queryHash) as\n Query<TQueryFnData, TError, TData, TQueryKey> | undefined\n }\n\n /**\n * Returns all queries within the cache.\n *\n * @example\n * ```ts\n * const queryCache = queryClient.getQueryCache()\n *\n * const queries = queryCache.getAll()\n * ```\n */\n getAll(): Array<Query> {\n return [...this.#queries.values()]\n }\n\n /**\n * A slightly more advanced method that can be used to get an existing query instance from the\n * cache. This instance not only contains all the state for the query, but all of the instances,\n * and underlying guts of the query as well. If the query does not exist, `undefined` is\n * returned.\n *\n * This is not typically needed for most applications, but can come in handy when needing more\n * information about a query in rare scenarios (e.g. looking at `query.state.dataUpdatedAt` to\n * decide whether a query is fresh enough to be used as an initial value).\n *\n * @see {@link QueryCache#findAll}\n * @example\n * ```ts\n * const queryCache = queryClient.getQueryCache()\n *\n * const query = queryCache.find({ queryKey: ['posts'] })\n * ```\n */\n find<TQueryFnData = unknown, TError = DefaultError, TData = TQueryFnData>(\n filters: WithRequired<QueryFilters, 'queryKey'>,\n ): Query<TQueryFnData, TError, TData> | undefined {\n const defaultedFilters = { exact: true, ...filters }\n\n return this.getAll().find((query) =>\n matchQuery(defaultedFilters, query),\n ) as Query<TQueryFnData, TError, TData> | undefined\n }\n\n /**\n * An even more advanced method that can be used to get existing query instances from the cache\n * that partially match a query key. If no queries match, an empty array is returned.\n *\n * This is not typically needed for most applications, but can come in handy when needing more\n * information about queries in rare scenarios.\n *\n * @see {@link QueryCache#find}\n * @example\n * ```ts\n * const queryCache = queryClient.getQueryCache()\n *\n * const queries = queryCache.findAll({ queryKey: ['posts'] })\n * ```\n */\n findAll(filters: QueryFilters<any> = {}): Array<Query> {\n const queries = this.getAll()\n return Object.keys(filters).length > 0\n ? queries.filter((query) => matchQuery(filters, query))\n : queries\n }\n\n /** @internal */\n notify(event: QueryCacheNotifyEvent): void {\n notifyManager.batch(() => {\n this.listeners.forEach((listener) => {\n listener(event)\n })\n })\n }\n\n /** @internal */\n onFocus(): void {\n notifyManager.batch(() => {\n this.getAll().forEach((query) => {\n query.onFocus()\n })\n })\n }\n\n /** @internal */\n onOnline(): void {\n notifyManager.batch(() => {\n this.getAll().forEach((query) => {\n query.onOnline()\n })\n })\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AA0HA,IAAa,aAAb,cAAgCA,qBAAAA,aAAiC;CAC/D;CAEA,YAAY,SAAkC,CAAC,GAAG;EAChD,MAAM;EADW,KAAA,SAAA;EAEjB,KAAK,2BAAW,IAAI,IAAmB;CACzC;;;;;;;;;;;;;;;;;CAkBA,MAME,QACA,SAIA,OAC+C;EAC/C,MAAM,WAAW,QAAQ;EACzB,MAAM,YACJ,QAAQ,aAAaC,cAAAA,sBAAsB,UAAU,OAAO;EAC9D,IAAI,QAAQ,KAAK,IAA4C,SAAS;EAEtE,IAAI,CAAC,OAAO;GACV,QAAQ,IAAIC,cAAAA,MAAM;IAChB;IACA;IACA;IACA,SAAS,OAAO,oBAAoB,OAAO;IAC3C;IACA,gBAAgB,OAAO,iBAAiB,QAAQ;GAClD,CAAC;GACD,KAAK,IAAI,KAAK;EAChB;EAEA,OAAO;CACT;;CAGA,IAAI,OAAwC;EAC1C,IAAI,CAAC,KAAK,SA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AAM,QAAQ;GAChB,CAAC;EACH,CAAC;CACH;;CAGA,WAAiB;EACf,sBAAA,cAAc,YAAY;GACxB,KAAK,OAAO,CAAC,CAAC,SAAS,UAAU;IAC/B,MAAM,SAAS;GACjB,CAAC;EACH,CAAC;CACH;AACF"}
@@ -1,2 +1,2 @@
1
- import { cn as QueryCacheConfig, ln as QueryCacheNotifyEvent, sn as QueryCache, un as QueryStore } from "./hydration-DRcloXEn.cjs";
1
+ import { cn as QueryCacheConfig, ln as QueryCacheNotifyEvent, sn as QueryCache, un as QueryStore } from "./hydration-Br9VIGXa.cjs";
2
2
  export { QueryCache, QueryCacheConfig, QueryCacheNotifyEvent, QueryStore };
@@ -1,2 +1,2 @@
1
- import { cn as QueryCacheConfig, ln as QueryCacheNotifyEvent, sn as QueryCache, un as QueryStore } from "./hydration-Bp57N3SP.js";
1
+ import { cn as QueryCacheConfig, ln as QueryCacheNotifyEvent, sn as QueryCache, un as QueryStore } from "./hydration-B9t5w6NC.js";
2
2
  export { QueryCache, QueryCacheConfig, QueryCacheNotifyEvent, QueryStore };
@@ -1 +1 @@
1
- {"version":3,"file":"queryCache.js","names":["#queries"],"sources":["../../src/queryCache.ts"],"sourcesContent":["import { hashQueryKeyByOptions, matchQuery } from './utils'\nimport { Query } from './query'\nimport { notifyManager } from './notifyManager'\nimport { Subscribable } from './subscribable'\nimport type { QueryFilters } from './utils'\nimport type { Action, QueryState } from './query'\nimport type {\n DefaultError,\n NotifyEvent,\n QueryKey,\n QueryOptions,\n WithRequired,\n} from './types'\nimport type { QueryClient } from './queryClient'\nimport type { QueryObserver } from './queryObserver'\n\n// TYPES\n\n/**\n * Global callbacks that fire for every query handled by a `QueryCache`, regardless of which\n * component or observer triggered it. Unlike `QueryClient`'s `defaultOptions`, which a query can\n * override, these callbacks are always called. Unlike `MutationCacheConfig`'s callbacks, these\n * are fire-and-forget: their return value is not awaited before the query settles.\n */\nexport interface QueryCacheConfig {\n /** Called when any query in the cache encounters an error. */\n onError?: (\n error: DefaultError,\n query: Query<unknown, unknown, unknown>,\n ) => void\n /** Called when any query in the cache is successful. */\n onSuccess?: (data: unknown, query: Query<unknown, unknown, unknown>) => void\n /** Called when any query in the cache is settled, either successfully or with an error. */\n onSettled?: (\n data: unknown | undefined,\n error: DefaultError | null,\n query: Query<unknown, unknown, unknown>,\n ) => void\n}\n\ninterface NotifyEventQueryAdded extends NotifyEvent {\n type: 'added'\n query: Query<any, any, any, any>\n}\n\ninterface NotifyEventQueryRemoved extends NotifyEvent {\n type: 'removed'\n query: Query<any, any, any, any>\n}\n\ninterface NotifyEventQueryUpdated extends NotifyEvent {\n type: 'updated'\n query: Query<any, any, any, any>\n action: Action<any, any>\n}\n\ninterface NotifyEventQueryObserverAdded extends NotifyEvent {\n type: 'observerAdded'\n query: Query<any, any, any, any>\n observer: QueryObserver<any, any, any, any, any>\n}\n\ninterface NotifyEventQueryObserverRemoved extends NotifyEvent {\n type: 'observerRemoved'\n query: Query<any, any, any, any>\n observer: QueryObserver<any, any, any, any, any>\n}\n\ninterface NotifyEventQueryObserverResultsUpdated extends NotifyEvent {\n type: 'observerResultsUpdated'\n query: Query<any, any, any, any>\n}\n\ninterface NotifyEventQueryObserverOptionsUpdated extends NotifyEvent {\n type: 'observerOptionsUpdated'\n query: Query<any, any, any, any>\n observer: QueryObserver<any, any, any, any, any>\n}\n\n/**\n * The event passed to a `QueryCache` subscriber. Fired whenever a query is added or removed from\n * the cache, its state is updated (e.g. via `query.setState` or `queryClient.removeQueries`), or\n * one of its observers is added, removed, or has its results or options updated.\n */\nexport type QueryCacheNotifyEvent =\n | NotifyEventQueryAdded\n | NotifyEventQueryRemoved\n | NotifyEventQueryUpdated\n | NotifyEventQueryObserverAdded\n | NotifyEventQueryObserverRemoved\n | NotifyEventQueryObserverResultsUpdated\n | NotifyEventQueryObserverOptionsUpdated\n\ntype QueryCacheListener = (event: QueryCacheNotifyEvent) => void\n\nexport interface QueryStore {\n has: (queryHash: string) => boolean\n set: (queryHash: string, query: Query) => void\n get: (queryHash: string) => Query | undefined\n delete: (queryHash: string) => void\n values: () => IterableIterator<Query>\n}\n\n// CLASS\n\n/**\n * The `QueryCache` is the storage mechanism for TanStack Query. It stores all the data, meta\n * information, and state of the queries it contains.\n *\n * Normally, you will not interact with the `QueryCache` directly and instead use a `QueryClient`\n * for a specific cache. You can subscribe to it (inherited from `Subscribable`) to be informed of\n * safe/known updates to the cache, such as queries being added, removed, or updated — updates made\n * outside of the cache's own tracked mechanisms (e.g. mutating a query's state object directly) do\n * not notify subscribers.\n *\n * @example\n * ```ts\n * const unsubscribe = queryCache.subscribe((event) => {\n * console.log(event.type, event.query)\n * })\n * ```\n */\nexport class QueryCache extends Subscribable<QueryCacheListener> {\n #queries: QueryStore\n\n constructor(public config: QueryCacheConfig = {}) {\n super()\n this.#queries = new Map<string, Query>()\n }\n\n /**\n * Returns the existing `Query` instance for the given options' `queryKey`/`queryHash`, or\n * builds and adds a new one to the cache if none exists yet. Used by framework adapters and\n * plugins (e.g. broadcast/persistence) that need to get-or-create a `Query` directly, bypassing\n * the reactive `QueryObserver` machinery.\n *\n * @example\n * ```ts\n * const queryCache = queryClient.getQueryCache()\n *\n * const query = queryCache.build(queryClient, {\n * queryKey: ['posts'],\n * queryFn: fetchPosts,\n * })\n * ```\n */\n build<\n TQueryFnData = unknown,\n TError = DefaultError,\n TData = TQueryFnData,\n TQueryKey extends QueryKey = QueryKey,\n >(\n client: QueryClient,\n options: WithRequired<\n QueryOptions<TQueryFnData, TError, TData, TQueryKey>,\n 'queryKey'\n >,\n state?: QueryState<TData, TError>,\n ): Query<TQueryFnData, TError, TData, TQueryKey> {\n const queryKey = options.queryKey\n const queryHash =\n options.queryHash ?? hashQueryKeyByOptions(queryKey, options)\n let query = this.get<TQueryFnData, TError, TData, TQueryKey>(queryHash)\n\n if (!query) {\n query = new Query({\n client,\n queryKey,\n queryHash,\n options: client.defaultQueryOptions(options),\n state,\n defaultOptions: client.getQueryDefaults(queryKey),\n })\n this.add(query)\n }\n\n return query\n }\n\n /** @internal */\n add(query: Query<any, any, any, any>): void {\n if (!this.#queries.has(query.queryHash)) {\n this.#queries.set(query.queryHash, query)\n\n this.notify({\n type: 'added',\n query,\n })\n }\n }\n\n /**\n * Destroys the given `Query` and removes it from the cache, notifying subscribers with a\n * `'removed'` event. A no-op if the query is no longer the one currently stored under its hash\n * (e.g. it was already replaced). Used by plugins (e.g. the broadcast client) that mirror\n * removals across `QueryCache` instances.\n *\n * @example\n * ```ts\n * const queryCache = queryClient.getQueryCache()\n * const query = queryCache.find({ queryKey: ['posts'] })\n *\n * if (query) {\n * queryCache.remove(query)\n * }\n * ```\n */\n remove(query: Query<any, any, any, any>): void {\n const queryInMap = this.#queries.get(query.queryHash)\n\n if (queryInMap === query) {\n query.destroy()\n this.#queries.delete(query.queryHash)\n this.notify({ type: 'removed', query })\n }\n }\n\n /**\n * Removes all queries from the cache.\n *\n * @example\n * ```ts\n * const queryCache = queryClient.getQueryCache()\n *\n * queryCache.clear()\n * ```\n */\n clear(): void {\n notifyManager.batch(() => {\n this.getAll().forEach((query) => {\n this.remove(query)\n })\n })\n }\n\n /**\n * Returns the `Query` instance stored under the given `queryHash`, or `undefined` if none\n * exists. Unlike {@link QueryCache#find}, this looks up by the already-computed hash rather\n * than by `QueryFilters`. Used by plugins (e.g. broadcast/hydration) that already have a hash\n * to look up directly.\n *\n * @example\n * ```ts\n * const queryCache = queryClient.getQueryCache()\n * const queryHash = hashKey(['posts'])\n *\n * const query = queryCache.get(queryHash)\n * ```\n */\n get<\n TQueryFnData = unknown,\n TError = DefaultError,\n TData = TQueryFnData,\n TQueryKey extends QueryKey = QueryKey,\n >(\n queryHash: string,\n ): Query<TQueryFnData, TError, TData, TQueryKey> | undefined {\n return this.#queries.get(queryHash) as\n | Query<TQueryFnData, TError, TData, TQueryKey>\n | undefined\n }\n\n /**\n * Returns all queries within the cache.\n *\n * @example\n * ```ts\n * const queryCache = queryClient.getQueryCache()\n *\n * const queries = queryCache.getAll()\n * ```\n */\n getAll(): Array<Query> {\n return [...this.#queries.values()]\n }\n\n /**\n * A slightly more advanced method that can be used to get an existing query instance from the\n * cache. This instance not only contains all the state for the query, but all of the instances,\n * and underlying guts of the query as well. If the query does not exist, `undefined` is\n * returned.\n *\n * This is not typically needed for most applications, but can come in handy when needing more\n * information about a query in rare scenarios (e.g. looking at `query.state.dataUpdatedAt` to\n * decide whether a query is fresh enough to be used as an initial value).\n *\n * @see {@link QueryCache#findAll}\n * @example\n * ```ts\n * const queryCache = queryClient.getQueryCache()\n *\n * const query = queryCache.find({ queryKey: ['posts'] })\n * ```\n */\n find<TQueryFnData = unknown, TError = DefaultError, TData = TQueryFnData>(\n filters: WithRequired<QueryFilters, 'queryKey'>,\n ): Query<TQueryFnData, TError, TData> | undefined {\n const defaultedFilters = { exact: true, ...filters }\n\n return this.getAll().find((query) =>\n matchQuery(defaultedFilters, query),\n ) as Query<TQueryFnData, TError, TData> | undefined\n }\n\n /**\n * An even more advanced method that can be used to get existing query instances from the cache\n * that partially match a query key. If no queries match, an empty array is returned.\n *\n * This is not typically needed for most applications, but can come in handy when needing more\n * information about queries in rare scenarios.\n *\n * @see {@link QueryCache#find}\n * @example\n * ```ts\n * const queryCache = queryClient.getQueryCache()\n *\n * const queries = queryCache.findAll({ queryKey: ['posts'] })\n * ```\n */\n findAll(filters: QueryFilters<any> = {}): Array<Query> {\n const queries = this.getAll()\n return Object.keys(filters).length > 0\n ? queries.filter((query) => matchQuery(filters, query))\n : queries\n }\n\n /** @internal */\n notify(event: QueryCacheNotifyEvent): void {\n notifyManager.batch(() => {\n this.listeners.forEach((listener) => {\n listener(event)\n })\n })\n }\n\n /** @internal */\n onFocus(): void {\n notifyManager.batch(() => {\n this.getAll().forEach((query) => {\n query.onFocus()\n })\n })\n }\n\n /** @internal */\n onOnline(): void {\n notifyManager.batch(() => {\n this.getAll().forEach((query) => {\n query.onOnline()\n })\n })\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AA0HA,IA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M,mBAAmB;GAAE,OAAO;GAAM,GAAG;EAAQ;EAEnD,OAAO,KAAK,OAAO,CAAC,CAAC,MAAM,UACzB,WAAW,kBAAkB,KAAK,CACpC;CACF;;;;;;;;;;;;;;;;CAiBA,QAAQ,UAA6B,CAAC,GAAiB;EACrD,MAAM,UAAU,KAAK,OAAO;EAC5B,OAAO,OAAO,KAAK,OAAO,CAAC,CAAC,SAAS,IACjC,QAAQ,QAAQ,UAAU,WAAW,SAAS,KAAK,CAAC,IACpD;CACN;;CAGA,OAAO,OAAoC;EACzC,cAAc,YAAY;GACxB,KAAK,UAAU,SAAS,aAAa;IACnC,SAAS,KAAK;GAChB,CAAC;EACH,CAAC;CACH;;CAGA,UAAgB;EACd,cAAc,YAAY;GACxB,KAAK,OAAO,CAAC,CAAC,SAAS,UAAU;IAC/B,MAAM,QAAQ;GAChB,CAAC;EACH,CAAC;CACH;;CAGA,WAAiB;EACf,cAAc,YAAY;GACxB,KAAK,OAAO,CAAC,CAAC,SAAS,UAAU;IAC/B,MAAM,SAAS;GACjB,CAAC;EACH,CAAC;CACH;AACF"}
1
+ {"version":3,"file":"queryCache.js","names":[],"sources":["../../src/queryCache.ts"],"sourcesContent":["import { hashQueryKeyByOptions, matchQuery } from './utils'\nimport { Query } from './query'\nimport { notifyManager } from './notifyManager'\nimport { Subscribable } from './subscribable'\nimport type { QueryFilters } from './utils'\nimport type { Action, QueryState } from './query'\nimport type {\n DefaultError,\n NotifyEvent,\n QueryKey,\n QueryOptions,\n WithRequired,\n} from './types'\nimport type { QueryClient } from './queryClient'\nimport type { QueryObserver } from './queryObserver'\n\n// TYPES\n\n/**\n * Global callbacks that fire for every query handled by a `QueryCache`, regardless of which\n * component or observer triggered it. Unlike `QueryClient`'s `defaultOptions`, which a query can\n * override, these callbacks are always called. Unlike `MutationCacheConfig`'s callbacks, these\n * are fire-and-forget: their return value is not awaited before the query settles.\n */\nexport interface QueryCacheConfig {\n /** Called when any query in the cache encounters an error. */\n onError?: (\n error: DefaultError,\n query: Query<unknown, unknown, unknown>,\n ) => void\n /** Called when any query in the cache is successful. */\n onSuccess?: (data: unknown, query: Query<unknown, unknown, unknown>) => void\n /** Called when any query in the cache is settled, either successfully or with an error. */\n onSettled?: (\n data: unknown | undefined,\n error: DefaultError | null,\n query: Query<unknown, unknown, unknown>,\n ) => void\n}\n\ninterface NotifyEventQueryAdded extends NotifyEvent {\n type: 'added'\n query: Query<any, any, any, any>\n}\n\ninterface NotifyEventQueryRemoved extends NotifyEvent {\n type: 'removed'\n query: Query<any, any, any, any>\n}\n\ninterface NotifyEventQueryUpdated extends NotifyEvent {\n type: 'updated'\n query: Query<any, any, any, any>\n action: Action<any, any>\n}\n\ninterface NotifyEventQueryObserverAdded extends NotifyEvent {\n type: 'observerAdded'\n query: Query<any, any, any, any>\n observer: QueryObserver<any, any, any, any, any>\n}\n\ninterface NotifyEventQueryObserverRemoved extends NotifyEvent {\n type: 'observerRemoved'\n query: Query<any, any, any, any>\n observer: QueryObserver<any, any, any, any, any>\n}\n\ninterface NotifyEventQueryObserverResultsUpdated extends NotifyEvent {\n type: 'observerResultsUpdated'\n query: Query<any, any, any, any>\n}\n\ninterface NotifyEventQueryObserverOptionsUpdated extends NotifyEvent {\n type: 'observerOptionsUpdated'\n query: Query<any, any, any, any>\n observer: QueryObserver<any, any, any, any, any>\n}\n\n/**\n * The event passed to a `QueryCache` subscriber. Fired whenever a query is added or removed from\n * the cache, its state is updated (e.g. via `query.setState` or `queryClient.removeQueries`), or\n * one of its observers is added, removed, or has its results or options updated.\n */\nexport type QueryCacheNotifyEvent =\n | NotifyEventQueryAdded\n | NotifyEventQueryRemoved\n | NotifyEventQueryUpdated\n | NotifyEventQueryObserverAdded\n | NotifyEventQueryObserverRemoved\n | NotifyEventQueryObserverResultsUpdated\n | NotifyEventQueryObserverOptionsUpdated\n\ntype QueryCacheListener = (event: QueryCacheNotifyEvent) => void\n\nexport interface QueryStore {\n has: (queryHash: string) => boolean\n set: (queryHash: string, query: Query) => void\n get: (queryHash: string) => Query | undefined\n delete: (queryHash: string) => void\n values: () => IterableIterator<Query>\n}\n\n// CLASS\n\n/**\n * The `QueryCache` is the storage mechanism for TanStack Query. It stores all the data, meta\n * information, and state of the queries it contains.\n *\n * Normally, you will not interact with the `QueryCache` directly and instead use a `QueryClient`\n * for a specific cache. You can subscribe to it (inherited from `Subscribable`) to be informed of\n * safe/known updates to the cache, such as queries being added, removed, or updated — updates made\n * outside of the cache's own tracked mechanisms (e.g. mutating a query's state object directly) do\n * not notify subscribers.\n *\n * @example\n * ```ts\n * const unsubscribe = queryCache.subscribe((event) => {\n * console.log(event.type, event.query)\n * })\n * ```\n */\nexport class QueryCache extends Subscribable<QueryCacheListener> {\n #queries: QueryStore\n\n constructor(public config: QueryCacheConfig = {}) {\n super()\n this.#queries = new Map<string, Query>()\n }\n\n /**\n * Returns the existing `Query` instance for the given options' `queryKey`/`queryHash`, or\n * builds and adds a new one to the cache if none exists yet. Used by framework adapters and\n * plugins (e.g. broadcast/persistence) that need to get-or-create a `Query` directly, bypassing\n * the reactive `QueryObserver` machinery.\n *\n * @example\n * ```ts\n * const queryCache = queryClient.getQueryCache()\n *\n * const query = queryCache.build(queryClient, {\n * queryKey: ['posts'],\n * queryFn: fetchPosts,\n * })\n * ```\n */\n build<\n TQueryFnData = unknown,\n TError = DefaultError,\n TData = TQueryFnData,\n TQueryKey extends QueryKey = QueryKey,\n >(\n client: QueryClient,\n options: WithRequired<\n QueryOptions<TQueryFnData, TError, TData, TQueryKey>,\n 'queryKey'\n >,\n state?: QueryState<TData, TError>,\n ): Query<TQueryFnData, TError, TData, TQueryKey> {\n const queryKey = options.queryKey\n const queryHash =\n options.queryHash ?? hashQueryKeyByOptions(queryKey, options)\n let query = this.get<TQueryFnData, TError, TData, TQueryKey>(queryHash)\n\n if (!query) {\n query = new Query({\n client,\n queryKey,\n queryHash,\n options: client.defaultQueryOptions(options),\n state,\n defaultOptions: client.getQueryDefaults(queryKey),\n })\n this.add(query)\n }\n\n return query\n }\n\n /** @internal */\n add(query: Query<any, any, any, any>): void {\n if (!this.#queries.has(query.queryHash)) {\n this.#queries.set(query.queryHash, query)\n\n this.notify({\n type: 'added',\n query,\n })\n }\n }\n\n /**\n * Destroys the given `Query` and removes it from the cache, notifying subscribers with a\n * `'removed'` event. A no-op if the query is no longer the one currently stored under its hash\n * (e.g. it was already replaced). Used by plugins (e.g. the broadcast client) that mirror\n * removals across `QueryCache` instances.\n *\n * @example\n * ```ts\n * const queryCache = queryClient.getQueryCache()\n * const query = queryCache.find({ queryKey: ['posts'] })\n *\n * if (query) {\n * queryCache.remove(query)\n * }\n * ```\n */\n remove(query: Query<any, any, any, any>): void {\n const queryInMap = this.#queries.get(query.queryHash)\n\n if (queryInMap === query) {\n query.destroy()\n this.#queries.delete(query.queryHash)\n this.notify({ type: 'removed', query })\n }\n }\n\n /**\n * Removes all queries from the cache.\n *\n * @example\n * ```ts\n * const queryCache = queryClient.getQueryCache()\n *\n * queryCache.clear()\n * ```\n */\n clear(): void {\n notifyManager.batch(() => {\n this.getAll().forEach((query) => {\n this.remove(query)\n })\n })\n }\n\n /**\n * Returns the `Query` instance stored under the given `queryHash`, or `undefined` if none\n * exists. Unlike {@link QueryCache#find}, this looks up by the already-computed hash rather\n * than by `QueryFilters`. Used by plugins (e.g. broadcast/hydration) that already have a hash\n * to look up directly.\n *\n * @example\n * ```ts\n * const queryCache = queryClient.getQueryCache()\n * const queryHash = hashKey(['posts'])\n *\n * const query = queryCache.get(queryHash)\n * ```\n */\n get<\n TQueryFnData = unknown,\n TError = DefaultError,\n TData = TQueryFnData,\n TQueryKey extends QueryKey = QueryKey,\n >(\n queryHash: string,\n ): Query<TQueryFnData, TError, TData, TQueryKey> | undefined {\n return this.#queries.get(queryHash) as\n Query<TQueryFnData, TError, TData, TQueryKey> | undefined\n }\n\n /**\n * Returns all queries within the cache.\n *\n * @example\n * ```ts\n * const queryCache = queryClient.getQueryCache()\n *\n * const queries = queryCache.getAll()\n * ```\n */\n getAll(): Array<Query> {\n return [...this.#queries.values()]\n }\n\n /**\n * A slightly more advanced method that can be used to get an existing query instance from the\n * cache. This instance not only contains all the state for the query, but all of the instances,\n * and underlying guts of the query as well. If the query does not exist, `undefined` is\n * returned.\n *\n * This is not typically needed for most applications, but can come in handy when needing more\n * information about a query in rare scenarios (e.g. looking at `query.state.dataUpdatedAt` to\n * decide whether a query is fresh enough to be used as an initial value).\n *\n * @see {@link QueryCache#findAll}\n * @example\n * ```ts\n * const queryCache = queryClient.getQueryCache()\n *\n * const query = queryCache.find({ queryKey: ['posts'] })\n * ```\n */\n find<TQueryFnData = unknown, TError = DefaultError, TData = TQueryFnData>(\n filters: WithRequired<QueryFilters, 'queryKey'>,\n ): Query<TQueryFnData, TError, TData> | undefined {\n const defaultedFilters = { exact: true, ...filters }\n\n return this.getAll().find((query) =>\n matchQuery(defaultedFilters, query),\n ) as Query<TQueryFnData, TError, TData> | undefined\n }\n\n /**\n * An even more advanced method that can be used to get existing query instances from the cache\n * that partially match a query key. If no queries match, an empty array is returned.\n *\n * This is not typically needed for most applications, but can come in handy when needing more\n * information about queries in rare scenarios.\n *\n * @see {@link QueryCache#find}\n * @example\n * ```ts\n * const queryCache = queryClient.getQueryCache()\n *\n * const queries = queryCache.findAll({ queryKey: ['posts'] })\n * ```\n */\n findAll(filters: QueryFilters<any> = {}): Array<Query> {\n const queries = this.getAll()\n return Object.keys(filters).length > 0\n ? queries.filter((query) => matchQuery(filters, query))\n : queries\n }\n\n /** @internal */\n notify(event: QueryCacheNotifyEvent): void {\n notifyManager.batch(() => {\n this.listeners.forEach((listener) => {\n listener(event)\n })\n })\n }\n\n /** @internal */\n onFocus(): void {\n notifyManager.batch(() => {\n this.getAll().forEach((query) => {\n query.onFocus()\n })\n })\n }\n\n /** @internal */\n onOnline(): void {\n notifyManager.batch(() => {\n this.getAll().forEach((query) => {\n query.onOnline()\n })\n })\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AA0HA,IAAa,aAAb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OAAO;GAAM,GAAG;EAAQ;EAEnD,OAAO,KAAK,OAAO,CAAC,CAAC,MAAM,UACzB,WAAW,kBAAkB,KAAK,CACpC;CACF;;;;;;;;;;;;;;;;CAiBA,QAAQ,UAA6B,CAAC,GAAiB;EACrD,MAAM,UAAU,KAAK,OAAO;EAC5B,OAAO,OAAO,KAAK,OAAO,CAAC,CAAC,SAAS,IACjC,QAAQ,QAAQ,UAAU,WAAW,SAAS,KAAK,CAAC,IACpD;CACN;;CAGA,OAAO,OAAoC;EACzC,cAAc,YAAY;GACxB,KAAK,UAAU,SAAS,aAAa;IACnC,SAAS,KAAK;GAChB,CAAC;EACH,CAAC;CACH;;CAGA,UAAgB;EACd,cAAc,YAAY;GACxB,KAAK,OAAO,CAAC,CAAC,SAAS,UAAU;IAC/B,MAAM,QAAQ;GAChB,CAAC;EACH,CAAC;CACH;;CAGA,WAAiB;EACf,cAAc,YAAY;GACxB,KAAK,OAAO,CAAC,CAAC,SAAS,UAAU;IAC/B,MAAM,SAAS;GACjB,CAAC;EACH,CAAC;CACH;AACF"}
@@ -118,6 +118,7 @@ var QueryClient = class {
118
118
  * Hint: Do not use this function inside a component, because it won't receive updates.
119
119
  * Use `useQuery` to create a `QueryObserver` that subscribes to changes.
120
120
  *
121
+ * @returns The cached data for the query, or `undefined` if no query with this key has been observed yet.
121
122
  * @see {@link QueryClient#getQueriesData}
122
123
  */
123
124
  getQueryData(queryKey) {
@@ -146,6 +147,7 @@ var QueryClient = class {
146
147
  * every matched query holds the same shape — it is not checked against the actual cache
147
148
  * contents.
148
149
  *
150
+ * @returns An array of query key and data pairs. The data is `undefined` for a query with no cached data.
149
151
  * @see {@link QueryClient#getQueryData}
150
152
  * @example
151
153
  * ```ts
@@ -169,6 +171,9 @@ var QueryClient = class {
169
171
  * @param queryKey - The query key to set data for.
170
172
  * @param updater - Either the new data, or a function that receives the current data (which
171
173
  * may be `undefined`) and returns the new data.
174
+ * @param options - Set `updatedAt` to override the timestamp the written data is recorded with.
175
+ * @returns The data that was written, or `undefined` if the updater returned `undefined` — in that case
176
+ * the write is skipped and the cache is left unchanged.
172
177
  *
173
178
  * @example
174
179
  * ```ts
@@ -194,6 +199,8 @@ var QueryClient = class {
194
199
  * filters are updated; no new cache entries are created. Internally this calls
195
200
  * {@link QueryClient#setQueryData} for each matching query.
196
201
  *
202
+ * @returns One `[queryKey, data]` tuple per matched query, in the same shape and with the same
203
+ * `undefined` case as {@link QueryClient#setQueryData}.
197
204
  * @example
198
205
  * ```ts
199
206
  * queryClient.setQueriesData({ queryKey: ['posts'] }, (oldPosts) =>
@@ -1 +1 @@
1
- {"version":3,"file":"queryClient.cjs","names":["#queryCache","QueryCache","#mutationCache","MutationCache","#defaultOptions","#queryDefaults","#mutationDefaults","#mountCount","#unsubscribeFocus","focusManager","#unsubscribeOnline","onlineManager","resolveQueryValue","functionalUpdate","notifyManager","noop","hashKey","partialMatchKey","hashQueryKeyByOptions","skipToken"],"sources":["../../src/queryClient.ts"],"sourcesContent":["import {\n functionalUpdate,\n hashKey,\n hashQueryKeyByOptions,\n noop,\n partialMatchKey,\n resolveQueryValue,\n skipToken,\n} from './utils'\nimport { QueryCache } from './queryCache'\nimport { MutationCache } from './mutationCache'\nimport { focusManager } from './focusManager'\nimport { onlineManager } from './onlineManager'\nimport { notifyManager } from './notifyManager'\nimport type {\n CancelOptions,\n DefaultError,\n DefaultOptions,\n DefaultedQueryObserverOptions,\n EnsureInfiniteQueryDataOptions,\n EnsureQueryDataOptions,\n FetchInfiniteQueryOptions,\n FetchQueryOptions,\n InferDataFromTag,\n InferErrorFromTag,\n InfiniteData,\n InfiniteQueryExecuteOptions,\n InvalidateOptions,\n InvalidateQueryFilters,\n MutationKey,\n MutationObserverOptions,\n MutationOptions,\n OmitKeyof,\n QueryClientConfig,\n QueryExecuteOptions,\n QueryKey,\n QueryObserverOptions,\n QueryOptions,\n RefetchOptions,\n RefetchQueryFilters,\n ResetOptions,\n SetDataOptions,\n} from './types'\nimport type { QueryState } from './query'\nimport type { MutationFilters, QueryFilters, Updater } from './utils'\n\n// TYPES\n\ninterface QueryDefaults {\n queryKey: QueryKey\n defaultOptions: OmitKeyof<QueryOptions<any, any, any>, 'queryKey'>\n}\n\ninterface MutationDefaults {\n mutationKey: MutationKey\n defaultOptions: MutationOptions<any, any, any, any>\n}\n\n// CLASS\n\n/**\n * `QueryClient` is used to interact with a cache of queries and mutations. It owns a\n * `QueryCache` and a `MutationCache` (creating default ones if none are passed in) and holds\n * the default options that are applied to queries and mutations created through it.\n *\n * @example\n * ```ts\n * const queryClient = new QueryClient({\n * defaultOptions: {\n * queries: {\n * staleTime: Infinity,\n * },\n * },\n * })\n *\n * await queryClient.query({ queryKey: ['posts'], queryFn: fetchPosts })\n * ```\n */\nexport class QueryClient {\n #queryCache: QueryCache\n #mutationCache: MutationCache\n #defaultOptions: DefaultOptions\n #queryDefaults: Map<string, QueryDefaults>\n #mutationDefaults: Map<string, MutationDefaults>\n #mountCount: number\n #unsubscribeFocus?: () => void\n #unsubscribeOnline?: () => void\n\n constructor(config: QueryClientConfig = {}) {\n this.#queryCache = config.queryCache || new QueryCache()\n this.#mutationCache = config.mutationCache || new MutationCache()\n this.#defaultOptions = config.defaultOptions || {}\n this.#queryDefaults = new Map()\n this.#mutationDefaults = new Map()\n this.#mountCount = 0\n }\n\n /**\n * Called by a framework adapter's `QueryClientProvider`-equivalent when it mounts, to start\n * listening for focus/online events and resume paused mutations. Ref-counted via an internal\n * mount count, so nested or multiple providers sharing the same `QueryClient` don't tear down\n * the shared listeners until the last one unmounts.\n */\n mount(): void {\n this.#mountCount++\n if (this.#mountCount !== 1) return\n\n this.#unsubscribeFocus = focusManager.subscribe(async (focused) => {\n if (focused) {\n await this.resumePausedMutations()\n this.#queryCache.onFocus()\n }\n })\n this.#unsubscribeOnline = onlineManager.subscribe(async (online) => {\n if (online) {\n await this.resumePausedMutations()\n this.#queryCache.onOnline()\n }\n })\n }\n\n /**\n * The inverse of {@link QueryClient#mount} — called by a framework adapter's\n * `QueryClientProvider`-equivalent when it unmounts. Only tears down the focus/online\n * listeners once the mount count returns to `0`.\n */\n unmount(): void {\n this.#mountCount--\n if (this.#mountCount !== 0) return\n\n this.#unsubscribeFocus?.()\n this.#unsubscribeFocus = undefined\n\n this.#unsubscribeOnline?.()\n this.#unsubscribeOnline = undefined\n }\n\n /**\n * Returns the number of queries in the cache that are currently fetching, optionally\n * matching a set of filters. This includes background-fetching, loading new pages, and\n * loading more infinite query results.\n *\n * @example\n * ```ts\n * if (queryClient.isFetching()) {\n * console.log('At least one query is fetching!')\n * }\n * ```\n */\n isFetching<TQueryFilters extends QueryFilters<any> = QueryFilters>(\n filters?: TQueryFilters,\n ): number {\n return this.#queryCache.findAll({ ...filters, fetchStatus: 'fetching' })\n .length\n }\n\n /**\n * Returns the number of mutations in the cache that are currently pending, optionally\n * matching a set of filters.\n *\n * @example\n * ```ts\n * if (queryClient.isMutating()) {\n * console.log('At least one mutation is pending!')\n * }\n * ```\n */\n isMutating<\n TMutationFilters extends MutationFilters<any, any> = MutationFilters,\n >(filters?: TMutationFilters): number {\n return this.#mutationCache.findAll({ ...filters, status: 'pending' }).length\n }\n\n /**\n * Imperative (non-reactive) way to retrieve data for a QueryKey.\n * Should only be used in callbacks or functions where reading the latest data is necessary, e.g. for optimistic updates.\n *\n * Hint: Do not use this function inside a component, because it won't receive updates.\n * Use `useQuery` to create a `QueryObserver` that subscribes to changes.\n *\n * @see {@link QueryClient#getQueriesData}\n */\n getQueryData<\n TQueryFnData = unknown,\n TTaggedQueryKey extends QueryKey = QueryKey,\n TInferredQueryFnData = InferDataFromTag<TQueryFnData, TTaggedQueryKey>,\n >(queryKey: TTaggedQueryKey): TInferredQueryFnData | undefined {\n const options = this.defaultQueryOptions({ queryKey })\n\n return this.#queryCache.get<TInferredQueryFnData>(options.queryHash)?.state\n .data\n }\n\n /**\n * @deprecated Use queryClient.query({ ...options, staleTime: 'static' }) instead. This method will be removed in the next major version.\n */\n ensureQueryData<\n TQueryFnData,\n TError = DefaultError,\n TData = TQueryFnData,\n TQueryKey extends QueryKey = QueryKey,\n >(\n options: EnsureQueryDataOptions<TQueryFnData, TError, TData, TQueryKey>,\n ): Promise<TData> {\n const defaultedOptions = this.defaultQueryOptions(options)\n const query = this.#queryCache.build(this, defaultedOptions)\n const cachedData = query.state.data\n\n if (cachedData === undefined) {\n // eslint-disable-next-line no-restricted-syntax\n return this.fetchQuery(options)\n }\n\n if (\n options.revalidateIfStale &&\n query.isStaleByTime(resolveQueryValue(defaultedOptions.staleTime, query))\n ) {\n // eslint-disable-next-line no-restricted-syntax\n void this.prefetchQuery(defaultedOptions)\n }\n\n return Promise.resolve(cachedData)\n }\n\n /**\n * Imperative (non-reactive) way to retrieve the cached data of multiple queries at once.\n * Only queries matching the given filters are returned; if none match, an empty array is\n * returned.\n *\n * Because the matched queries can hold data of different shapes (e.g. a broad filter can match\n * queries with unrelated data types), the `TQueryFnData` generic defaults to `unknown` rather\n * than being inferred. Passing a more specific type is a convenience for call sites that know\n * every matched query holds the same shape — it is not checked against the actual cache\n * contents.\n *\n * @see {@link QueryClient#getQueryData}\n * @example\n * ```ts\n * const data = queryClient.getQueriesData({ queryKey: ['posts'] })\n * ```\n */\n getQueriesData<\n TQueryFnData = unknown,\n TQueryFilters extends QueryFilters<any> = QueryFilters,\n >(filters: TQueryFilters): Array<[QueryKey, TQueryFnData | undefined]> {\n return this.#queryCache.findAll(filters).map(({ queryKey, state }) => {\n const data = state.data as TQueryFnData | undefined\n return [queryKey, data]\n })\n }\n\n /**\n * Synchronous way to immediately update a query's cached data. If the updater (or the value\n * passed) resolves to `undefined`, the cache is left untouched and no query is created;\n * otherwise, if the query does not exist yet, it will be created. To update multiple queries\n * at once by partially matching query keys, use {@link QueryClient#setQueriesData} instead.\n *\n * Updates must be performed immutably: do not mutate `oldData`, or data previously retrieved\n * via {@link QueryClient#getQueryData}, in place.\n *\n * @param queryKey - The query key to set data for.\n * @param updater - Either the new data, or a function that receives the current data (which\n * may be `undefined`) and returns the new data.\n *\n * @example\n * ```ts\n * queryClient.setQueryData(['posts'], newPosts)\n *\n * // Or, using an updater function that receives the current data:\n * queryClient.setQueryData(['posts'], (oldPosts) => [...oldPosts, newPost])\n * ```\n */\n setQueryData<\n TQueryFnData = unknown,\n TTaggedQueryKey extends QueryKey = QueryKey,\n TInferredQueryFnData = InferDataFromTag<TQueryFnData, TTaggedQueryKey>,\n >(\n queryKey: TTaggedQueryKey,\n updater: Updater<\n NoInfer<TInferredQueryFnData> | undefined,\n NoInfer<TInferredQueryFnData> | undefined\n >,\n options?: SetDataOptions,\n ): NoInfer<TInferredQueryFnData> | undefined {\n const defaultedOptions = this.defaultQueryOptions<\n any,\n any,\n unknown,\n any,\n QueryKey\n >({ queryKey })\n\n const query = this.#queryCache.get<TInferredQueryFnData>(\n defaultedOptions.queryHash,\n )\n const prevData = query?.state.data\n const data = functionalUpdate(updater, prevData)\n\n if (data === undefined) {\n return undefined\n }\n\n return this.#queryCache\n .build(this, defaultedOptions)\n .setData(data, { ...options, manual: true })\n }\n\n /**\n * Synchronous way to immediately update the cached data of multiple queries at once, using\n * filters or partial query key matching. Only queries that already exist and match the given\n * filters are updated; no new cache entries are created. Internally this calls\n * {@link QueryClient#setQueryData} for each matching query.\n *\n * @example\n * ```ts\n * queryClient.setQueriesData({ queryKey: ['posts'] }, (oldPosts) =>\n * oldPosts ? oldPosts.filter((post) => post.id !== deletedId) : oldPosts,\n * )\n * ```\n */\n setQueriesData<\n TQueryFnData,\n TQueryFilters extends QueryFilters<any> = QueryFilters,\n >(\n filters: TQueryFilters,\n updater: Updater<\n NoInfer<TQueryFnData> | undefined,\n NoInfer<TQueryFnData> | undefined\n >,\n options?: SetDataOptions,\n ): Array<[QueryKey, TQueryFnData | undefined]> {\n return notifyManager.batch(() =>\n this.#queryCache\n .findAll(filters)\n .map(({ queryKey }) => [\n queryKey,\n this.setQueryData<TQueryFnData>(queryKey, updater, options),\n ]),\n )\n }\n\n /**\n * Imperative (non-reactive) way to retrieve an existing query's state. If the query does not\n * exist, `undefined` is returned.\n *\n * @example\n * ```ts\n * const state = queryClient.getQueryState(['posts'])\n * console.log(state?.dataUpdatedAt)\n * ```\n */\n getQueryState<\n TQueryFnData = unknown,\n TError = DefaultError,\n TTaggedQueryKey extends QueryKey = QueryKey,\n TInferredQueryFnData = InferDataFromTag<TQueryFnData, TTaggedQueryKey>,\n TInferredError = InferErrorFromTag<TError, TTaggedQueryKey>,\n >(\n queryKey: TTaggedQueryKey,\n ): QueryState<TInferredQueryFnData, TInferredError> | undefined {\n const options = this.defaultQueryOptions({ queryKey })\n return this.#queryCache.get<TInferredQueryFnData, TInferredError>(\n options.queryHash,\n )?.state\n }\n\n /**\n * Removes queries from the cache that match the given filters. Unlike\n * {@link QueryClient#invalidateQueries} or {@link QueryClient#refetchQueries}, this removes\n * matching queries from the cache instead of refetching them. Without filters, every query in\n * the cache is removed.\n *\n * @example\n * ```ts\n * queryClient.removeQueries({ queryKey: ['posts'], exact: true })\n * ```\n */\n removeQueries<TTaggedQueryKey extends QueryKey = QueryKey>(\n filters?: QueryFilters<TTaggedQueryKey>,\n ): void {\n const queryCache = this.#queryCache\n notifyManager.batch(() => {\n queryCache.findAll(filters).forEach((query) => {\n queryCache.remove(query)\n })\n })\n }\n\n /**\n * Resets queries matching the given filters back to their initial state (e.g. any\n * `initialData`), notifying subscribers rather than removing them. Active queries among the\n * matched set are then refetched, and the returned promise resolves once that refetch settles.\n *\n * @example\n * ```ts\n * await queryClient.resetQueries({ queryKey: ['posts'], exact: true })\n * ```\n */\n resetQueries<TTaggedQueryKey extends QueryKey = QueryKey>(\n filters?: QueryFilters<TTaggedQueryKey>,\n options?: ResetOptions,\n ): Promise<void> {\n const queryCache = this.#queryCache\n\n return notifyManager.batch(() => {\n const matched = queryCache.findAll(filters)\n const queriesToRefetch = new Set(matched)\n matched.forEach((query) => {\n query.reset()\n })\n return this.refetchQueries(\n {\n type: 'active',\n predicate: (query) => queriesToRefetch.has(query),\n },\n options,\n )\n })\n }\n\n /**\n * Cancels outgoing fetches for queries matching the given filters. Most useful when performing\n * optimistic updates, since any outgoing refetch that resolves afterwards would otherwise\n * overwrite the optimistic update. By default (`revert: true`), a cancelled query's data is\n * reverted to its state before the outgoing fetch started.\n *\n * The returned promise never rejects, even if individual cancellations fail.\n *\n * @example\n * ```ts\n * await queryClient.cancelQueries({ queryKey: ['posts'], exact: true })\n * ```\n */\n cancelQueries<TTaggedQueryKey extends QueryKey = QueryKey>(\n filters?: QueryFilters<TTaggedQueryKey>,\n cancelOptions: CancelOptions = {},\n ): Promise<void> {\n const defaultedCancelOptions = { revert: true, ...cancelOptions }\n\n const promises = notifyManager.batch(() =>\n this.#queryCache\n .findAll(filters)\n .map((query) => query.cancel(defaultedCancelOptions)),\n )\n\n return Promise.all(promises).then(noop).catch(noop)\n }\n\n /**\n * Marks queries matching the given filters as invalidated. Unlike\n * {@link QueryClient#removeQueries}, invalidated queries stay in the cache.\n *\n * Unless `filters.refetchType` is `'none'`, matching queries are then refetched via\n * {@link QueryClient#refetchQueries}, using `filters.refetchType` if set, otherwise\n * `filters.type`, otherwise `'active'`.\n *\n * @example\n * ```ts\n * await queryClient.invalidateQueries({ queryKey: ['posts'], refetchType: 'active' })\n * ```\n */\n invalidateQueries<TTaggedQueryKey extends QueryKey = QueryKey>(\n filters?: InvalidateQueryFilters<TTaggedQueryKey>,\n options: InvalidateOptions = {},\n ): Promise<void> {\n return notifyManager.batch(() => {\n this.#queryCache.findAll(filters).forEach((query) => {\n query.invalidate()\n })\n\n if (filters?.refetchType === 'none') {\n return Promise.resolve()\n }\n return this.refetchQueries(\n {\n ...filters,\n type: filters?.refetchType ?? filters?.type ?? 'active',\n },\n options,\n )\n })\n }\n\n /**\n * Refetches queries matching the given filters, regardless of whether they are stale. Without\n * filters, every query in the cache is refetched. Queries that are disabled, or static (only\n * have observers with a static `staleTime`), are never refetched.\n *\n * By default (`cancelRefetch: true`), a currently running fetch is cancelled before the new\n * one starts. The returned promise resolves once all matching queries have settled; it does\n * not reject on individual query failures unless `throwOnError` is set.\n *\n * @example\n * ```ts\n * // refetch all active queries partially matching a query key:\n * await queryClient.refetchQueries({ queryKey: ['posts'], type: 'active' })\n * ```\n */\n refetchQueries<TTaggedQueryKey extends QueryKey = QueryKey>(\n filters?: RefetchQueryFilters<TTaggedQueryKey>,\n options: RefetchOptions = {},\n ): Promise<void> {\n const fetchOptions = {\n ...options,\n cancelRefetch: options.cancelRefetch ?? true,\n }\n const promises = notifyManager.batch(() =>\n this.#queryCache\n .findAll(filters)\n .filter((query) => !query.isDisabled() && !query.isStatic())\n .map((query) => {\n let promise = query.fetch(undefined, fetchOptions)\n if (!fetchOptions.throwOnError) {\n promise = promise.catch(noop)\n }\n return query.state.fetchStatus === 'paused'\n ? Promise.resolve()\n : promise\n }),\n )\n\n return Promise.all(promises).then(noop)\n }\n\n /**\n * Asynchronous method to fetch and cache a query, resolving with the data or throwing with\n * the error.\n *\n * If the query already exists in the cache and its data is not stale (per the given\n * `staleTime`), the cached data is returned without fetching. Otherwise, the query is fetched\n * and the promise resolves once the fetch settles. If a `select` function is provided, it is\n * applied to the data in both cases (cached or freshly fetched) before it is returned.\n *\n * Unlike a reactive observer, retries are disabled by default here (`retry: false`) unless\n * explicitly configured, since there is no component to catch a thrown error and retry through\n * re-render.\n *\n * The accepted options are `QueryObserverOptions` minus the fields that only make sense for a\n * reactive observer — `enabled`, `refetchInterval`, `refetchIntervalInBackground`,\n * `refetchOnWindowFocus`, `refetchOnReconnect`, `refetchOnMount`, `retryOnMount`,\n * `notifyOnChangeProps`, `throwOnError`, `suspense`, and `placeholderData` are not part of this\n * method's options.\n *\n * This method replaces the deprecated `fetchQuery`, and — combined with\n * `{ staleTime: 'static' }` — the deprecated `ensureQueryData`.\n *\n * @example\n * ```ts\n * try {\n * const data = await queryClient.query({ queryKey, queryFn, staleTime: 10000 })\n * } catch (error) {\n * console.log(error)\n * }\n * ```\n */\n async query<\n TQueryFnData,\n TError = DefaultError,\n TData = TQueryFnData,\n TQueryData = TQueryFnData,\n TQueryKey extends QueryKey = QueryKey,\n TPageParam = never,\n >(\n options: QueryExecuteOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryData,\n TQueryKey,\n TPageParam\n >,\n ): Promise<TData> {\n const defaultedOptions = this.defaultQueryOptions(options)\n\n // https://github.com/tannerlinsley/react-query/issues/652\n if (defaultedOptions.retry === undefined) {\n defaultedOptions.retry = false\n }\n\n const query = this.#queryCache.build(this, defaultedOptions)\n\n const isStale = query.isStaleByTime(\n resolveQueryValue(defaultedOptions.staleTime, query),\n )\n\n const queryData = isStale\n ? await query.fetch(defaultedOptions)\n : (query.state.data as TQueryData)\n\n const select = defaultedOptions.select\n\n if (select) {\n return select(queryData)\n }\n\n return queryData as unknown as TData\n }\n\n /**\n * @deprecated Use queryClient.query(options) instead. This method will be removed in the next major version.\n */\n fetchQuery<\n TQueryFnData,\n TError = DefaultError,\n TData = TQueryFnData,\n TQueryKey extends QueryKey = QueryKey,\n TPageParam = never,\n >(\n options: FetchQueryOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryKey,\n TPageParam\n >,\n ): Promise<TData> {\n const defaultedOptions = this.defaultQueryOptions(options)\n\n // https://github.com/tannerlinsley/react-query/issues/652\n if (defaultedOptions.retry === undefined) {\n defaultedOptions.retry = false\n }\n\n const query = this.#queryCache.build(this, defaultedOptions)\n\n return query.isStaleByTime(\n resolveQueryValue(defaultedOptions.staleTime, query),\n )\n ? query.fetch(defaultedOptions)\n : Promise.resolve(query.state.data as TData)\n }\n\n /**\n * @deprecated Use queryClient.query(options) instead. You can swallow errors with `.catch(noop)`. This method will be removed in the next major version.\n */\n prefetchQuery<\n TQueryFnData = unknown,\n TError = DefaultError,\n TData = TQueryFnData,\n TQueryKey extends QueryKey = QueryKey,\n >(\n options: FetchQueryOptions<TQueryFnData, TError, TData, TQueryKey>,\n ): Promise<void> {\n // eslint-disable-next-line no-restricted-syntax\n return this.fetchQuery(options).then(noop).catch(noop)\n }\n\n /**\n * Asynchronous method to fetch and cache an infinite query, resolving with an\n * {@link InfiniteData} object or throwing with the error.\n *\n * Behaves like {@link QueryClient#query}, accepting the same options (minus\n * `initialPageParam`), plus the required `initialPageParam`, and an optional `pages` /\n * `getNextPageParam` pair used to refetch a fixed number of pages from the start.\n *\n * This method replaces the deprecated `fetchInfiniteQuery`, and — combined with\n * `{ staleTime: 'static' }` — the deprecated `ensureInfiniteQueryData`.\n *\n * @example\n * ```ts\n * try {\n * const data = await queryClient.infiniteQuery({ queryKey, queryFn, initialPageParam: 0 })\n * console.log(data.pages)\n * } catch (error) {\n * console.log(error)\n * }\n * ```\n */\n infiniteQuery<\n TQueryFnData,\n TError = DefaultError,\n TData = InfiniteData<TQueryFnData>,\n TQueryKey extends QueryKey = QueryKey,\n TPageParam = unknown,\n >(\n options: InfiniteQueryExecuteOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryKey,\n TPageParam\n >,\n ): Promise<\n Array<TData> extends Array<InfiniteData<TQueryFnData>>\n ? InfiniteData<TQueryFnData, TPageParam>\n : TData\n > {\n options._type = 'infinite'\n return this.query(options as any)\n }\n\n /**\n * @deprecated Use queryClient.infiniteQuery(options) instead. This method will be removed in the next major version.\n */\n fetchInfiniteQuery<\n TQueryFnData,\n TError = DefaultError,\n TData = TQueryFnData,\n TQueryKey extends QueryKey = QueryKey,\n TPageParam = unknown,\n >(\n options: FetchInfiniteQueryOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryKey,\n TPageParam\n >,\n ): Promise<InfiniteData<TData, TPageParam>> {\n options._type = 'infinite'\n // eslint-disable-next-line no-restricted-syntax\n return this.fetchQuery(options as any)\n }\n\n /**\n * @deprecated Use queryClient.infiniteQuery(options) instead. You can swallow errors with `.catch(noop)`. This method will be removed in the next major version.\n */\n prefetchInfiniteQuery<\n TQueryFnData,\n TError = DefaultError,\n TData = TQueryFnData,\n TQueryKey extends QueryKey = QueryKey,\n TPageParam = unknown,\n >(\n options: FetchInfiniteQueryOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryKey,\n TPageParam\n >,\n ): Promise<void> {\n // eslint-disable-next-line no-restricted-syntax\n return this.fetchInfiniteQuery(options).then(noop).catch(noop)\n }\n\n /**\n * @deprecated Use queryClient.infiniteQuery({ ...options, staleTime: 'static' }) instead. This method will be removed in the next major version.\n */\n ensureInfiniteQueryData<\n TQueryFnData,\n TError = DefaultError,\n TData = TQueryFnData,\n TQueryKey extends QueryKey = QueryKey,\n TPageParam = unknown,\n >(\n options: EnsureInfiniteQueryDataOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryKey,\n TPageParam\n >,\n ): Promise<InfiniteData<TData, TPageParam>> {\n options._type = 'infinite'\n\n // eslint-disable-next-line no-restricted-syntax\n return this.ensureQueryData(options as any)\n }\n\n /**\n * Resumes mutations that were paused because there was no network connection. Does nothing\n * (resolving immediately) if the client is currently offline.\n *\n * @example\n * ```ts\n * import { QueryClient } from '@tanstack/query-core'\n *\n * const queryClient = new QueryClient()\n * await queryClient.resumePausedMutations()\n * ```\n */\n resumePausedMutations(): Promise<unknown> {\n if (onlineManager.isOnline()) {\n return this.#mutationCache.resumePausedMutations()\n }\n return Promise.resolve()\n }\n\n /**\n * Returns the query cache this client is connected to.\n *\n * @example\n * ```ts\n * import { QueryClient } from '@tanstack/query-core'\n *\n * const queryClient = new QueryClient()\n * const queryCache = queryClient.getQueryCache()\n * const queries = queryCache.findAll({ queryKey: ['posts'] })\n * ```\n */\n getQueryCache(): QueryCache {\n return this.#queryCache\n }\n\n /**\n * Returns the mutation cache this client is connected to.\n *\n * @example\n * ```ts\n * import { QueryClient } from '@tanstack/query-core'\n *\n * const queryClient = new QueryClient()\n * const mutationCache = queryClient.getMutationCache()\n * const mutations = mutationCache.findAll({ status: 'pending' })\n * ```\n */\n getMutationCache(): MutationCache {\n return this.#mutationCache\n }\n\n /**\n * Returns the default options that were set when creating the client, or via\n * {@link QueryClient#setDefaultOptions}.\n *\n * @example\n * ```ts\n * import { QueryClient } from '@tanstack/query-core'\n *\n * const queryClient = new QueryClient()\n * const defaultOptions = queryClient.getDefaultOptions()\n * ```\n */\n getDefaultOptions(): DefaultOptions {\n return this.#defaultOptions\n }\n\n /**\n * Dynamically sets the default options for this client, overwriting any previously defined\n * default options.\n *\n * @see {@link QueryClient#getDefaultOptions}\n * @example\n * ```ts\n * import { QueryClient } from '@tanstack/query-core'\n *\n * const queryClient = new QueryClient()\n * queryClient.setDefaultOptions({\n * queries: {\n * staleTime: Infinity,\n * },\n * })\n * ```\n */\n setDefaultOptions(options: DefaultOptions): void {\n this.#defaultOptions = options\n }\n\n /**\n * Sets default options for queries whose query key partially matches the given `queryKey`.\n *\n * If several registered query defaults match a given query key, they are merged together in\n * registration order by {@link QueryClient#getQueryDefaults}, so register defaults from the\n * most generic key to the least generic one — more specific defaults should be registered\n * after more generic ones so they take precedence.\n *\n * @example\n * ```ts\n * queryClient.setQueryDefaults(['posts'], { queryFn: fetchPosts })\n *\n * await queryClient.query({ queryKey: ['posts'] })\n * ```\n */\n setQueryDefaults<\n TQueryFnData = unknown,\n TError = DefaultError,\n TData = TQueryFnData,\n TQueryData = TQueryFnData,\n >(\n queryKey: QueryKey,\n options: Partial<\n OmitKeyof<\n QueryObserverOptions<TQueryFnData, TError, TData, TQueryData>,\n 'queryKey'\n >\n >,\n ): void {\n this.#queryDefaults.set(hashKey(queryKey), {\n queryKey,\n defaultOptions: options,\n })\n }\n\n /**\n * Returns the default options registered for queries whose query key partially matches the\n * given `queryKey`, via {@link QueryClient#setQueryDefaults}. If multiple registered defaults\n * match, they are merged together in registration order.\n *\n * @example\n * ```ts\n * const defaultOptions = queryClient.getQueryDefaults(['posts'])\n * ```\n */\n getQueryDefaults(\n queryKey: QueryKey,\n ): OmitKeyof<QueryObserverOptions<any, any, any, any, any>, 'queryKey'> {\n const defaults = [...this.#queryDefaults.values()]\n\n const result: OmitKeyof<\n QueryObserverOptions<any, any, any, any, any>,\n 'queryKey'\n > = {}\n\n defaults.forEach((queryDefault) => {\n if (partialMatchKey(queryKey, queryDefault.queryKey)) {\n Object.assign(result, queryDefault.defaultOptions)\n }\n })\n return result\n }\n\n /**\n * Sets default options for mutations whose mutation key partially matches the given\n * `mutationKey`. As with {@link QueryClient#setQueryDefaults}, the order of registration\n * matters when several registered defaults match the same mutation key.\n *\n * @see {@link QueryClient#getMutationDefaults}\n * @example\n * ```ts\n * queryClient.setMutationDefaults(['addPost'], { mutationFn: addPost })\n * ```\n */\n setMutationDefaults<\n TData = unknown,\n TError = DefaultError,\n TVariables = void,\n TOnMutateResult = unknown,\n >(\n mutationKey: MutationKey,\n options: OmitKeyof<\n MutationObserverOptions<TData, TError, TVariables, TOnMutateResult>,\n 'mutationKey'\n >,\n ): void {\n this.#mutationDefaults.set(hashKey(mutationKey), {\n mutationKey,\n defaultOptions: options,\n })\n }\n\n /**\n * Returns the default options registered for mutations whose mutation key partially matches\n * the given `mutationKey`, via {@link QueryClient#setMutationDefaults}. If multiple registered\n * defaults match, they are merged together in registration order.\n *\n * @example\n * ```ts\n * const defaultOptions = queryClient.getMutationDefaults(['addPost'])\n * ```\n */\n getMutationDefaults(\n mutationKey: MutationKey,\n ): OmitKeyof<MutationObserverOptions<any, any, any, any>, 'mutationKey'> {\n const defaults = [...this.#mutationDefaults.values()]\n\n const result: OmitKeyof<\n MutationObserverOptions<any, any, any, any>,\n 'mutationKey'\n > = {}\n\n defaults.forEach((queryDefault) => {\n if (partialMatchKey(mutationKey, queryDefault.mutationKey)) {\n Object.assign(result, queryDefault.defaultOptions)\n }\n })\n\n return result\n }\n\n /**\n * Called by framework adapters (e.g. inside `useQuery`) to resolve the options passed by the\n * caller into their final, defaulted form: merging `queryClient.setQueryDefaults` for the\n * given `queryKey`, then the client's own `defaultOptions.queries`, then the caller's options\n * on top. A no-op if the options are already defaulted (`_defaulted: true`).\n */\n defaultQueryOptions<\n TQueryFnData = unknown,\n TError = DefaultError,\n TData = TQueryFnData,\n TQueryData = TQueryFnData,\n TQueryKey extends QueryKey = QueryKey,\n TPageParam = never,\n >(\n options:\n | QueryObserverOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryData,\n TQueryKey,\n TPageParam\n >\n | DefaultedQueryObserverOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryData,\n TQueryKey\n >,\n ): DefaultedQueryObserverOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryData,\n TQueryKey\n > {\n if (options._defaulted) {\n return options as DefaultedQueryObserverOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryData,\n TQueryKey\n >\n }\n\n const defaultedOptions = {\n ...this.#defaultOptions.queries,\n ...this.getQueryDefaults(options.queryKey),\n ...options,\n _defaulted: true,\n }\n\n if (!defaultedOptions.queryHash) {\n defaultedOptions.queryHash = hashQueryKeyByOptions(\n defaultedOptions.queryKey,\n defaultedOptions,\n )\n }\n\n // dependent default values\n if (defaultedOptions.refetchOnReconnect === undefined) {\n defaultedOptions.refetchOnReconnect =\n defaultedOptions.networkMode !== 'always'\n }\n if (defaultedOptions.throwOnError === undefined) {\n defaultedOptions.throwOnError = !!defaultedOptions.suspense\n }\n\n if (!defaultedOptions.networkMode && defaultedOptions.persister) {\n defaultedOptions.networkMode = 'offlineFirst'\n }\n\n if (defaultedOptions.queryFn === skipToken) {\n defaultedOptions.enabled = false\n }\n\n return defaultedOptions as DefaultedQueryObserverOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryData,\n TQueryKey\n >\n }\n\n /**\n * The mutation counterpart of {@link QueryClient#defaultQueryOptions}. Called by framework\n * adapters (e.g. inside `useMutation`) to merge `queryClient.setMutationDefaults` for the\n * given `mutationKey`, then the client's `defaultOptions.mutations`, then the caller's options\n * on top. A no-op if the options are already defaulted (`_defaulted: true`).\n */\n defaultMutationOptions<T extends MutationOptions<any, any, any, any>>(\n options?: T,\n ): T {\n if (options?._defaulted) {\n return options\n }\n return {\n ...this.#defaultOptions.mutations,\n ...(options?.mutationKey &&\n this.getMutationDefaults(options.mutationKey)),\n ...options,\n _defaulted: true,\n } as T\n }\n\n /**\n * Clears both the query cache and the mutation cache this client is connected to.\n *\n * @example\n * ```ts\n * import { QueryClient } from '@tanstack/query-core'\n *\n * const queryClient = new QueryClient()\n * queryClient.clear()\n * ```\n */\n clear(): void {\n this.#queryCache.clear()\n this.#mutationCache.clear()\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AA8EA,IAAa,cAAb,MAAyB;CACvB;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CAEA,YAAY,SAA4B,CAAC,GAAG;EAC1C,KAAKA,cAAc,OAAO,cAAc,IAAIC,mBAAAA,WAAW;EACvD,KAAKC,iBAAiB,OAAO,iBAAiB,IAAIC,sBAAAA,cAAc;EAChE,KAAKC,kBAAkB,OAAO,kBAAkB,CAAC;EACjD,KAAKC,iCAAiB,IAAI,IAAI;EAC9B,KAAKC,oCAAoB,IAAI,IAAI;EACjC,KAAKC,cAAc;CACrB;;;;;;;CAQA,QAAc;EACZ,KAAKA;EACL,IAAI,KAAKA,gBAAgB,GAAG;EAE5B,KAAKC,oBAAoBC,qBAAAA,aAAa,UAAU,OAAO,YAAY;GACjE,IAAI,SAAS;IACX,MAAM,KAAK,sBAAsB;IACjC,KAAKT,YAAY,QAAQ;GAC3B;EACF,CAAC;EACD,KAAKU,qBAAqBC,sBAAAA,cAAc,UAAU,OAAO,WAAW;GAClE,IAAI,QAAQ;IACV,MAAM,KAAK,sBAAsB;IACjC,KAAKX,YAAY,SAAS;GAC5B;EACF,CAAC;CACH;;;;;;CAOA,UAAgB;EACd,KAAKO;EACL,IAAI,KAAKA,gBAAgB,GAAG;EAE5B,KAAKC,oBAAoB;EACzB,KAAKA,oBAAoB,KAAA;EAEzB,KAAKE,qBAAqB;EAC1B,KAAKA,qBAAqB,KAAA;CAC5B;;;;;;;;;;;;;CAcA,WACE,SACQ;EACR,OAAO,KAAKV,YAAY,QAAQ;GAAE,GAAG;GAAS,aAAa;EAAW,CAAC,CAAC,CACrE;CACL;;;;;;;;;;;;C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AS,YACX,OAAO;EAET,OAAO;GACL,GAAG,KAAKf,gBAAgB;GACxB,GAAI,SAAS,eACX,KAAK,oBAAoB,QAAQ,WAAW;GAC9C,GAAG;GACH,YAAY;EACd;CACF;;;;;;;;;;;;CAaA,QAAc;EACZ,KAAKJ,YAAY,MAAM;EACvB,KAAKE,eAAe,MAAM;CAC5B;AACF"}
1
+ {"version":3,"file":"queryClient.cjs","names":["QueryCache","MutationCache","focusManager","onlineManager","resolveQueryValue","functionalUpdate","notifyManager","noop","hashKey","partialMatchKey","hashQueryKeyByOptions","skipToken"],"sources":["../../src/queryClient.ts"],"sourcesContent":["import {\n functionalUpdate,\n hashKey,\n hashQueryKeyByOptions,\n noop,\n partialMatchKey,\n resolveQueryValue,\n skipToken,\n} from './utils'\nimport { QueryCache } from './queryCache'\nimport { MutationCache } from './mutationCache'\nimport { focusManager } from './focusManager'\nimport { onlineManager } from './onlineManager'\nimport { notifyManager } from './notifyManager'\nimport type {\n CancelOptions,\n DefaultError,\n DefaultOptions,\n DefaultedQueryObserverOptions,\n EnsureInfiniteQueryDataOptions,\n EnsureQueryDataOptions,\n FetchInfiniteQueryOptions,\n FetchQueryOptions,\n InferDataFromTag,\n InferErrorFromTag,\n InfiniteData,\n InfiniteQueryExecuteOptions,\n InvalidateOptions,\n InvalidateQueryFilters,\n MutationKey,\n MutationObserverOptions,\n MutationOptions,\n OmitKeyof,\n QueryClientConfig,\n QueryExecuteOptions,\n QueryKey,\n QueryObserverOptions,\n QueryOptions,\n RefetchOptions,\n RefetchQueryFilters,\n ResetOptions,\n SetDataOptions,\n} from './types'\nimport type { QueryState } from './query'\nimport type { MutationFilters, QueryFilters, Updater } from './utils'\n\n// TYPES\n\ninterface QueryDefaults {\n queryKey: QueryKey\n defaultOptions: OmitKeyof<QueryOptions<any, any, any>, 'queryKey'>\n}\n\ninterface MutationDefaults {\n mutationKey: MutationKey\n defaultOptions: MutationOptions<any, any, any, any>\n}\n\n// CLASS\n\n/**\n * `QueryClient` is used to interact with a cache of queries and mutations. It owns a\n * `QueryCache` and a `MutationCache` (creating default ones if none are passed in) and holds\n * the default options that are applied to queries and mutations created through it.\n *\n * @example\n * ```ts\n * const queryClient = new QueryClient({\n * defaultOptions: {\n * queries: {\n * staleTime: Infinity,\n * },\n * },\n * })\n *\n * await queryClient.query({ queryKey: ['posts'], queryFn: fetchPosts })\n * ```\n */\nexport class QueryClient {\n #queryCache: QueryCache\n #mutationCache: MutationCache\n #defaultOptions: DefaultOptions\n #queryDefaults: Map<string, QueryDefaults>\n #mutationDefaults: Map<string, MutationDefaults>\n #mountCount: number\n #unsubscribeFocus?: () => void\n #unsubscribeOnline?: () => void\n\n constructor(config: QueryClientConfig = {}) {\n this.#queryCache = config.queryCache || new QueryCache()\n this.#mutationCache = config.mutationCache || new MutationCache()\n this.#defaultOptions = config.defaultOptions || {}\n this.#queryDefaults = new Map()\n this.#mutationDefaults = new Map()\n this.#mountCount = 0\n }\n\n /**\n * Called by a framework adapter's `QueryClientProvider`-equivalent when it mounts, to start\n * listening for focus/online events and resume paused mutations. Ref-counted via an internal\n * mount count, so nested or multiple providers sharing the same `QueryClient` don't tear down\n * the shared listeners until the last one unmounts.\n */\n mount(): void {\n this.#mountCount++\n if (this.#mountCount !== 1) return\n\n this.#unsubscribeFocus = focusManager.subscribe(async (focused) => {\n if (focused) {\n await this.resumePausedMutations()\n this.#queryCache.onFocus()\n }\n })\n this.#unsubscribeOnline = onlineManager.subscribe(async (online) => {\n if (online) {\n await this.resumePausedMutations()\n this.#queryCache.onOnline()\n }\n })\n }\n\n /**\n * The inverse of {@link QueryClient#mount} — called by a framework adapter's\n * `QueryClientProvider`-equivalent when it unmounts. Only tears down the focus/online\n * listeners once the mount count returns to `0`.\n */\n unmount(): void {\n this.#mountCount--\n if (this.#mountCount !== 0) return\n\n this.#unsubscribeFocus?.()\n this.#unsubscribeFocus = undefined\n\n this.#unsubscribeOnline?.()\n this.#unsubscribeOnline = undefined\n }\n\n /**\n * Returns the number of queries in the cache that are currently fetching, optionally\n * matching a set of filters. This includes background-fetching, loading new pages, and\n * loading more infinite query results.\n *\n * @example\n * ```ts\n * if (queryClient.isFetching()) {\n * console.log('At least one query is fetching!')\n * }\n * ```\n */\n isFetching<TQueryFilters extends QueryFilters<any> = QueryFilters>(\n filters?: TQueryFilters,\n ): number {\n return this.#queryCache.findAll({ ...filters, fetchStatus: 'fetching' })\n .length\n }\n\n /**\n * Returns the number of mutations in the cache that are currently pending, optionally\n * matching a set of filters.\n *\n * @example\n * ```ts\n * if (queryClient.isMutating()) {\n * console.log('At least one mutation is pending!')\n * }\n * ```\n */\n isMutating<\n TMutationFilters extends MutationFilters<any, any> = MutationFilters,\n >(filters?: TMutationFilters): number {\n return this.#mutationCache.findAll({ ...filters, status: 'pending' }).length\n }\n\n /**\n * Imperative (non-reactive) way to retrieve data for a QueryKey.\n * Should only be used in callbacks or functions where reading the latest data is necessary, e.g. for optimistic updates.\n *\n * Hint: Do not use this function inside a component, because it won't receive updates.\n * Use `useQuery` to create a `QueryObserver` that subscribes to changes.\n *\n * @returns The cached data for the query, or `undefined` if no query with this key has been observed yet.\n * @see {@link QueryClient#getQueriesData}\n */\n getQueryData<\n TQueryFnData = unknown,\n TTaggedQueryKey extends QueryKey = QueryKey,\n TInferredQueryFnData = InferDataFromTag<TQueryFnData, TTaggedQueryKey>,\n >(queryKey: TTaggedQueryKey): TInferredQueryFnData | undefined {\n const options = this.defaultQueryOptions({ queryKey })\n\n return this.#queryCache.get<TInferredQueryFnData>(options.queryHash)?.state\n .data\n }\n\n /**\n * @deprecated Use queryClient.query({ ...options, staleTime: 'static' }) instead. This method will be removed in the next major version.\n */\n ensureQueryData<\n TQueryFnData,\n TError = DefaultError,\n TData = TQueryFnData,\n TQueryKey extends QueryKey = QueryKey,\n >(\n options: EnsureQueryDataOptions<TQueryFnData, TError, TData, TQueryKey>,\n ): Promise<TData> {\n const defaultedOptions = this.defaultQueryOptions(options)\n const query = this.#queryCache.build(this, defaultedOptions)\n const cachedData = query.state.data\n\n if (cachedData === undefined) {\n // eslint-disable-next-line no-restricted-syntax\n return this.fetchQuery(options)\n }\n\n if (\n options.revalidateIfStale &&\n query.isStaleByTime(resolveQueryValue(defaultedOptions.staleTime, query))\n ) {\n // eslint-disable-next-line no-restricted-syntax\n void this.prefetchQuery(defaultedOptions)\n }\n\n return Promise.resolve(cachedData)\n }\n\n /**\n * Imperative (non-reactive) way to retrieve the cached data of multiple queries at once.\n * Only queries matching the given filters are returned; if none match, an empty array is\n * returned.\n *\n * Because the matched queries can hold data of different shapes (e.g. a broad filter can match\n * queries with unrelated data types), the `TQueryFnData` generic defaults to `unknown` rather\n * than being inferred. Passing a more specific type is a convenience for call sites that know\n * every matched query holds the same shape — it is not checked against the actual cache\n * contents.\n *\n * @returns An array of query key and data pairs. The data is `undefined` for a query with no cached data.\n * @see {@link QueryClient#getQueryData}\n * @example\n * ```ts\n * const data = queryClient.getQueriesData({ queryKey: ['posts'] })\n * ```\n */\n getQueriesData<\n TQueryFnData = unknown,\n TQueryFilters extends QueryFilters<any> = QueryFilters,\n >(filters: TQueryFilters): Array<[QueryKey, TQueryFnData | undefined]> {\n return this.#queryCache.findAll(filters).map(({ queryKey, state }) => {\n const data = state.data as TQueryFnData | undefined\n return [queryKey, data]\n })\n }\n\n /**\n * Synchronous way to immediately update a query's cached data. If the updater (or the value\n * passed) resolves to `undefined`, the cache is left untouched and no query is created;\n * otherwise, if the query does not exist yet, it will be created. To update multiple queries\n * at once by partially matching query keys, use {@link QueryClient#setQueriesData} instead.\n *\n * Updates must be performed immutably: do not mutate `oldData`, or data previously retrieved\n * via {@link QueryClient#getQueryData}, in place.\n *\n * @param queryKey - The query key to set data for.\n * @param updater - Either the new data, or a function that receives the current data (which\n * may be `undefined`) and returns the new data.\n * @param options - Set `updatedAt` to override the timestamp the written data is recorded with.\n * @returns The data that was written, or `undefined` if the updater returned `undefined` — in that case\n * the write is skipped and the cache is left unchanged.\n *\n * @example\n * ```ts\n * queryClient.setQueryData(['posts'], newPosts)\n *\n * // Or, using an updater function that receives the current data:\n * queryClient.setQueryData(['posts'], (oldPosts) => [...oldPosts, newPost])\n * ```\n */\n setQueryData<\n TQueryFnData = unknown,\n TTaggedQueryKey extends QueryKey = QueryKey,\n TInferredQueryFnData = InferDataFromTag<TQueryFnData, TTaggedQueryKey>,\n >(\n queryKey: TTaggedQueryKey,\n updater: Updater<\n NoInfer<TInferredQueryFnData> | undefined,\n NoInfer<TInferredQueryFnData> | undefined\n >,\n options?: SetDataOptions,\n ): NoInfer<TInferredQueryFnData> | undefined {\n const defaultedOptions = this.defaultQueryOptions<\n any,\n any,\n unknown,\n any,\n QueryKey\n >({ queryKey })\n\n const query = this.#queryCache.get<TInferredQueryFnData>(\n defaultedOptions.queryHash,\n )\n const prevData = query?.state.data\n const data = functionalUpdate(updater, prevData)\n\n if (data === undefined) {\n return undefined\n }\n\n return this.#queryCache\n .build(this, defaultedOptions)\n .setData(data, { ...options, manual: true })\n }\n\n /**\n * Synchronous way to immediately update the cached data of multiple queries at once, using\n * filters or partial query key matching. Only queries that already exist and match the given\n * filters are updated; no new cache entries are created. Internally this calls\n * {@link QueryClient#setQueryData} for each matching query.\n *\n * @returns One `[queryKey, data]` tuple per matched query, in the same shape and with the same\n * `undefined` case as {@link QueryClient#setQueryData}.\n * @example\n * ```ts\n * queryClient.setQueriesData({ queryKey: ['posts'] }, (oldPosts) =>\n * oldPosts ? oldPosts.filter((post) => post.id !== deletedId) : oldPosts,\n * )\n * ```\n */\n setQueriesData<\n TQueryFnData,\n TQueryFilters extends QueryFilters<any> = QueryFilters,\n >(\n filters: TQueryFilters,\n updater: Updater<\n NoInfer<TQueryFnData> | undefined,\n NoInfer<TQueryFnData> | undefined\n >,\n options?: SetDataOptions,\n ): Array<[QueryKey, TQueryFnData | undefined]> {\n return notifyManager.batch(() =>\n this.#queryCache\n .findAll(filters)\n .map(({ queryKey }) => [\n queryKey,\n this.setQueryData<TQueryFnData>(queryKey, updater, options),\n ]),\n )\n }\n\n /**\n * Imperative (non-reactive) way to retrieve an existing query's state. If the query does not\n * exist, `undefined` is returned.\n *\n * @example\n * ```ts\n * const state = queryClient.getQueryState(['posts'])\n * console.log(state?.dataUpdatedAt)\n * ```\n */\n getQueryState<\n TQueryFnData = unknown,\n TError = DefaultError,\n TTaggedQueryKey extends QueryKey = QueryKey,\n TInferredQueryFnData = InferDataFromTag<TQueryFnData, TTaggedQueryKey>,\n TInferredError = InferErrorFromTag<TError, TTaggedQueryKey>,\n >(\n queryKey: TTaggedQueryKey,\n ): QueryState<TInferredQueryFnData, TInferredError> | undefined {\n const options = this.defaultQueryOptions({ queryKey })\n return this.#queryCache.get<TInferredQueryFnData, TInferredError>(\n options.queryHash,\n )?.state\n }\n\n /**\n * Removes queries from the cache that match the given filters. Unlike\n * {@link QueryClient#invalidateQueries} or {@link QueryClient#refetchQueries}, this removes\n * matching queries from the cache instead of refetching them. Without filters, every query in\n * the cache is removed.\n *\n * @example\n * ```ts\n * queryClient.removeQueries({ queryKey: ['posts'], exact: true })\n * ```\n */\n removeQueries<TTaggedQueryKey extends QueryKey = QueryKey>(\n filters?: QueryFilters<TTaggedQueryKey>,\n ): void {\n const queryCache = this.#queryCache\n notifyManager.batch(() => {\n queryCache.findAll(filters).forEach((query) => {\n queryCache.remove(query)\n })\n })\n }\n\n /**\n * Resets queries matching the given filters back to their initial state (e.g. any\n * `initialData`), notifying subscribers rather than removing them. Active queries among the\n * matched set are then refetched, and the returned promise resolves once that refetch settles.\n *\n * @example\n * ```ts\n * await queryClient.resetQueries({ queryKey: ['posts'], exact: true })\n * ```\n */\n resetQueries<TTaggedQueryKey extends QueryKey = QueryKey>(\n filters?: QueryFilters<TTaggedQueryKey>,\n options?: ResetOptions,\n ): Promise<void> {\n const queryCache = this.#queryCache\n\n return notifyManager.batch(() => {\n const matched = queryCache.findAll(filters)\n const queriesToRefetch = new Set(matched)\n matched.forEach((query) => {\n query.reset()\n })\n return this.refetchQueries(\n {\n type: 'active',\n predicate: (query) => queriesToRefetch.has(query),\n },\n options,\n )\n })\n }\n\n /**\n * Cancels outgoing fetches for queries matching the given filters. Most useful when performing\n * optimistic updates, since any outgoing refetch that resolves afterwards would otherwise\n * overwrite the optimistic update. By default (`revert: true`), a cancelled query's data is\n * reverted to its state before the outgoing fetch started.\n *\n * The returned promise never rejects, even if individual cancellations fail.\n *\n * @example\n * ```ts\n * await queryClient.cancelQueries({ queryKey: ['posts'], exact: true })\n * ```\n */\n cancelQueries<TTaggedQueryKey extends QueryKey = QueryKey>(\n filters?: QueryFilters<TTaggedQueryKey>,\n cancelOptions: CancelOptions = {},\n ): Promise<void> {\n const defaultedCancelOptions = { revert: true, ...cancelOptions }\n\n const promises = notifyManager.batch(() =>\n this.#queryCache\n .findAll(filters)\n .map((query) => query.cancel(defaultedCancelOptions)),\n )\n\n return Promise.all(promises).then(noop).catch(noop)\n }\n\n /**\n * Marks queries matching the given filters as invalidated. Unlike\n * {@link QueryClient#removeQueries}, invalidated queries stay in the cache.\n *\n * Unless `filters.refetchType` is `'none'`, matching queries are then refetched via\n * {@link QueryClient#refetchQueries}, using `filters.refetchType` if set, otherwise\n * `filters.type`, otherwise `'active'`.\n *\n * @example\n * ```ts\n * await queryClient.invalidateQueries({ queryKey: ['posts'], refetchType: 'active' })\n * ```\n */\n invalidateQueries<TTaggedQueryKey extends QueryKey = QueryKey>(\n filters?: InvalidateQueryFilters<TTaggedQueryKey>,\n options: InvalidateOptions = {},\n ): Promise<void> {\n return notifyManager.batch(() => {\n this.#queryCache.findAll(filters).forEach((query) => {\n query.invalidate()\n })\n\n if (filters?.refetchType === 'none') {\n return Promise.resolve()\n }\n return this.refetchQueries(\n {\n ...filters,\n type: filters?.refetchType ?? filters?.type ?? 'active',\n },\n options,\n )\n })\n }\n\n /**\n * Refetches queries matching the given filters, regardless of whether they are stale. Without\n * filters, every query in the cache is refetched. Queries that are disabled, or static (only\n * have observers with a static `staleTime`), are never refetched.\n *\n * By default (`cancelRefetch: true`), a currently running fetch is cancelled before the new\n * one starts. The returned promise resolves once all matching queries have settled; it does\n * not reject on individual query failures unless `throwOnError` is set.\n *\n * @example\n * ```ts\n * // refetch all active queries partially matching a query key:\n * await queryClient.refetchQueries({ queryKey: ['posts'], type: 'active' })\n * ```\n */\n refetchQueries<TTaggedQueryKey extends QueryKey = QueryKey>(\n filters?: RefetchQueryFilters<TTaggedQueryKey>,\n options: RefetchOptions = {},\n ): Promise<void> {\n const fetchOptions = {\n ...options,\n cancelRefetch: options.cancelRefetch ?? true,\n }\n const promises = notifyManager.batch(() =>\n this.#queryCache\n .findAll(filters)\n .filter((query) => !query.isDisabled() && !query.isStatic())\n .map((query) => {\n let promise = query.fetch(undefined, fetchOptions)\n if (!fetchOptions.throwOnError) {\n promise = promise.catch(noop)\n }\n return query.state.fetchStatus === 'paused'\n ? Promise.resolve()\n : promise\n }),\n )\n\n return Promise.all(promises).then(noop)\n }\n\n /**\n * Asynchronous method to fetch and cache a query, resolving with the data or throwing with\n * the error.\n *\n * If the query already exists in the cache and its data is not stale (per the given\n * `staleTime`), the cached data is returned without fetching. Otherwise, the query is fetched\n * and the promise resolves once the fetch settles. If a `select` function is provided, it is\n * applied to the data in both cases (cached or freshly fetched) before it is returned.\n *\n * Unlike a reactive observer, retries are disabled by default here (`retry: false`) unless\n * explicitly configured, since there is no component to catch a thrown error and retry through\n * re-render.\n *\n * The accepted options are `QueryObserverOptions` minus the fields that only make sense for a\n * reactive observer — `enabled`, `refetchInterval`, `refetchIntervalInBackground`,\n * `refetchOnWindowFocus`, `refetchOnReconnect`, `refetchOnMount`, `retryOnMount`,\n * `notifyOnChangeProps`, `throwOnError`, `suspense`, and `placeholderData` are not part of this\n * method's options.\n *\n * This method replaces the deprecated `fetchQuery`, and — combined with\n * `{ staleTime: 'static' }` — the deprecated `ensureQueryData`.\n *\n * @example\n * ```ts\n * try {\n * const data = await queryClient.query({ queryKey, queryFn, staleTime: 10000 })\n * } catch (error) {\n * console.log(error)\n * }\n * ```\n */\n async query<\n TQueryFnData,\n TError = DefaultError,\n TData = TQueryFnData,\n TQueryData = TQueryFnData,\n TQueryKey extends QueryKey = QueryKey,\n TPageParam = never,\n >(\n options: QueryExecuteOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryData,\n TQueryKey,\n TPageParam\n >,\n ): Promise<TData> {\n const defaultedOptions = this.defaultQueryOptions(options)\n\n // https://github.com/tannerlinsley/react-query/issues/652\n if (defaultedOptions.retry === undefined) {\n defaultedOptions.retry = false\n }\n\n const query = this.#queryCache.build(this, defaultedOptions)\n\n const isStale = query.isStaleByTime(\n resolveQueryValue(defaultedOptions.staleTime, query),\n )\n\n const queryData = isStale\n ? await query.fetch(defaultedOptions)\n : (query.state.data as TQueryData)\n\n const select = defaultedOptions.select\n\n if (select) {\n return select(queryData)\n }\n\n return queryData as unknown as TData\n }\n\n /**\n * @deprecated Use queryClient.query(options) instead. This method will be removed in the next major version.\n */\n fetchQuery<\n TQueryFnData,\n TError = DefaultError,\n TData = TQueryFnData,\n TQueryKey extends QueryKey = QueryKey,\n TPageParam = never,\n >(\n options: FetchQueryOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryKey,\n TPageParam\n >,\n ): Promise<TData> {\n const defaultedOptions = this.defaultQueryOptions(options)\n\n // https://github.com/tannerlinsley/react-query/issues/652\n if (defaultedOptions.retry === undefined) {\n defaultedOptions.retry = false\n }\n\n const query = this.#queryCache.build(this, defaultedOptions)\n\n return query.isStaleByTime(\n resolveQueryValue(defaultedOptions.staleTime, query),\n )\n ? query.fetch(defaultedOptions)\n : Promise.resolve(query.state.data as TData)\n }\n\n /**\n * @deprecated Use queryClient.query(options) instead. You can swallow errors with `.catch(noop)`. This method will be removed in the next major version.\n */\n prefetchQuery<\n TQueryFnData = unknown,\n TError = DefaultError,\n TData = TQueryFnData,\n TQueryKey extends QueryKey = QueryKey,\n >(\n options: FetchQueryOptions<TQueryFnData, TError, TData, TQueryKey>,\n ): Promise<void> {\n // eslint-disable-next-line no-restricted-syntax\n return this.fetchQuery(options).then(noop).catch(noop)\n }\n\n /**\n * Asynchronous method to fetch and cache an infinite query, resolving with an\n * {@link InfiniteData} object or throwing with the error.\n *\n * Behaves like {@link QueryClient#query}, accepting the same options (minus\n * `initialPageParam`), plus the required `initialPageParam`, and an optional `pages` /\n * `getNextPageParam` pair used to refetch a fixed number of pages from the start.\n *\n * This method replaces the deprecated `fetchInfiniteQuery`, and — combined with\n * `{ staleTime: 'static' }` — the deprecated `ensureInfiniteQueryData`.\n *\n * @example\n * ```ts\n * try {\n * const data = await queryClient.infiniteQuery({ queryKey, queryFn, initialPageParam: 0 })\n * console.log(data.pages)\n * } catch (error) {\n * console.log(error)\n * }\n * ```\n */\n infiniteQuery<\n TQueryFnData,\n TError = DefaultError,\n TData = InfiniteData<TQueryFnData>,\n TQueryKey extends QueryKey = QueryKey,\n TPageParam = unknown,\n >(\n options: InfiniteQueryExecuteOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryKey,\n TPageParam\n >,\n ): Promise<\n Array<TData> extends Array<InfiniteData<TQueryFnData>>\n ? InfiniteData<TQueryFnData, TPageParam>\n : TData\n > {\n options._type = 'infinite'\n return this.query(options as any)\n }\n\n /**\n * @deprecated Use queryClient.infiniteQuery(options) instead. This method will be removed in the next major version.\n */\n fetchInfiniteQuery<\n TQueryFnData,\n TError = DefaultError,\n TData = TQueryFnData,\n TQueryKey extends QueryKey = QueryKey,\n TPageParam = unknown,\n >(\n options: FetchInfiniteQueryOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryKey,\n TPageParam\n >,\n ): Promise<InfiniteData<TData, TPageParam>> {\n options._type = 'infinite'\n // eslint-disable-next-line no-restricted-syntax\n return this.fetchQuery(options as any)\n }\n\n /**\n * @deprecated Use queryClient.infiniteQuery(options) instead. You can swallow errors with `.catch(noop)`. This method will be removed in the next major version.\n */\n prefetchInfiniteQuery<\n TQueryFnData,\n TError = DefaultError,\n TData = TQueryFnData,\n TQueryKey extends QueryKey = QueryKey,\n TPageParam = unknown,\n >(\n options: FetchInfiniteQueryOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryKey,\n TPageParam\n >,\n ): Promise<void> {\n // eslint-disable-next-line no-restricted-syntax\n return this.fetchInfiniteQuery(options).then(noop).catch(noop)\n }\n\n /**\n * @deprecated Use queryClient.infiniteQuery({ ...options, staleTime: 'static' }) instead. This method will be removed in the next major version.\n */\n ensureInfiniteQueryData<\n TQueryFnData,\n TError = DefaultError,\n TData = TQueryFnData,\n TQueryKey extends QueryKey = QueryKey,\n TPageParam = unknown,\n >(\n options: EnsureInfiniteQueryDataOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryKey,\n TPageParam\n >,\n ): Promise<InfiniteData<TData, TPageParam>> {\n options._type = 'infinite'\n\n // eslint-disable-next-line no-restricted-syntax\n return this.ensureQueryData(options as any)\n }\n\n /**\n * Resumes mutations that were paused because there was no network connection. Does nothing\n * (resolving immediately) if the client is currently offline.\n *\n * @example\n * ```ts\n * import { QueryClient } from '@tanstack/query-core'\n *\n * const queryClient = new QueryClient()\n * await queryClient.resumePausedMutations()\n * ```\n */\n resumePausedMutations(): Promise<unknown> {\n if (onlineManager.isOnline()) {\n return this.#mutationCache.resumePausedMutations()\n }\n return Promise.resolve()\n }\n\n /**\n * Returns the query cache this client is connected to.\n *\n * @example\n * ```ts\n * import { QueryClient } from '@tanstack/query-core'\n *\n * const queryClient = new QueryClient()\n * const queryCache = queryClient.getQueryCache()\n * const queries = queryCache.findAll({ queryKey: ['posts'] })\n * ```\n */\n getQueryCache(): QueryCache {\n return this.#queryCache\n }\n\n /**\n * Returns the mutation cache this client is connected to.\n *\n * @example\n * ```ts\n * import { QueryClient } from '@tanstack/query-core'\n *\n * const queryClient = new QueryClient()\n * const mutationCache = queryClient.getMutationCache()\n * const mutations = mutationCache.findAll({ status: 'pending' })\n * ```\n */\n getMutationCache(): MutationCache {\n return this.#mutationCache\n }\n\n /**\n * Returns the default options that were set when creating the client, or via\n * {@link QueryClient#setDefaultOptions}.\n *\n * @example\n * ```ts\n * import { QueryClient } from '@tanstack/query-core'\n *\n * const queryClient = new QueryClient()\n * const defaultOptions = queryClient.getDefaultOptions()\n * ```\n */\n getDefaultOptions(): DefaultOptions {\n return this.#defaultOptions\n }\n\n /**\n * Dynamically sets the default options for this client, overwriting any previously defined\n * default options.\n *\n * @see {@link QueryClient#getDefaultOptions}\n * @example\n * ```ts\n * import { QueryClient } from '@tanstack/query-core'\n *\n * const queryClient = new QueryClient()\n * queryClient.setDefaultOptions({\n * queries: {\n * staleTime: Infinity,\n * },\n * })\n * ```\n */\n setDefaultOptions(options: DefaultOptions): void {\n this.#defaultOptions = options\n }\n\n /**\n * Sets default options for queries whose query key partially matches the given `queryKey`.\n *\n * If several registered query defaults match a given query key, they are merged together in\n * registration order by {@link QueryClient#getQueryDefaults}, so register defaults from the\n * most generic key to the least generic one — more specific defaults should be registered\n * after more generic ones so they take precedence.\n *\n * @example\n * ```ts\n * queryClient.setQueryDefaults(['posts'], { queryFn: fetchPosts })\n *\n * await queryClient.query({ queryKey: ['posts'] })\n * ```\n */\n setQueryDefaults<\n TQueryFnData = unknown,\n TError = DefaultError,\n TData = TQueryFnData,\n TQueryData = TQueryFnData,\n >(\n queryKey: QueryKey,\n options: Partial<\n OmitKeyof<\n QueryObserverOptions<TQueryFnData, TError, TData, TQueryData>,\n 'queryKey'\n >\n >,\n ): void {\n this.#queryDefaults.set(hashKey(queryKey), {\n queryKey,\n defaultOptions: options,\n })\n }\n\n /**\n * Returns the default options registered for queries whose query key partially matches the\n * given `queryKey`, via {@link QueryClient#setQueryDefaults}. If multiple registered defaults\n * match, they are merged together in registration order.\n *\n * @example\n * ```ts\n * const defaultOptions = queryClient.getQueryDefaults(['posts'])\n * ```\n */\n getQueryDefaults(\n queryKey: QueryKey,\n ): OmitKeyof<QueryObserverOptions<any, any, any, any, any>, 'queryKey'> {\n const defaults = [...this.#queryDefaults.values()]\n\n const result: OmitKeyof<\n QueryObserverOptions<any, any, any, any, any>,\n 'queryKey'\n > = {}\n\n defaults.forEach((queryDefault) => {\n if (partialMatchKey(queryKey, queryDefault.queryKey)) {\n Object.assign(result, queryDefault.defaultOptions)\n }\n })\n return result\n }\n\n /**\n * Sets default options for mutations whose mutation key partially matches the given\n * `mutationKey`. As with {@link QueryClient#setQueryDefaults}, the order of registration\n * matters when several registered defaults match the same mutation key.\n *\n * @see {@link QueryClient#getMutationDefaults}\n * @example\n * ```ts\n * queryClient.setMutationDefaults(['addPost'], { mutationFn: addPost })\n * ```\n */\n setMutationDefaults<\n TData = unknown,\n TError = DefaultError,\n TVariables = void,\n TOnMutateResult = unknown,\n >(\n mutationKey: MutationKey,\n options: OmitKeyof<\n MutationObserverOptions<TData, TError, TVariables, TOnMutateResult>,\n 'mutationKey'\n >,\n ): void {\n this.#mutationDefaults.set(hashKey(mutationKey), {\n mutationKey,\n defaultOptions: options,\n })\n }\n\n /**\n * Returns the default options registered for mutations whose mutation key partially matches\n * the given `mutationKey`, via {@link QueryClient#setMutationDefaults}. If multiple registered\n * defaults match, they are merged together in registration order.\n *\n * @example\n * ```ts\n * const defaultOptions = queryClient.getMutationDefaults(['addPost'])\n * ```\n */\n getMutationDefaults(\n mutationKey: MutationKey,\n ): OmitKeyof<MutationObserverOptions<any, any, any, any>, 'mutationKey'> {\n const defaults = [...this.#mutationDefaults.values()]\n\n const result: OmitKeyof<\n MutationObserverOptions<any, any, any, any>,\n 'mutationKey'\n > = {}\n\n defaults.forEach((queryDefault) => {\n if (partialMatchKey(mutationKey, queryDefault.mutationKey)) {\n Object.assign(result, queryDefault.defaultOptions)\n }\n })\n\n return result\n }\n\n /**\n * Called by framework adapters (e.g. inside `useQuery`) to resolve the options passed by the\n * caller into their final, defaulted form: merging `queryClient.setQueryDefaults` for the\n * given `queryKey`, then the client's own `defaultOptions.queries`, then the caller's options\n * on top. A no-op if the options are already defaulted (`_defaulted: true`).\n */\n defaultQueryOptions<\n TQueryFnData = unknown,\n TError = DefaultError,\n TData = TQueryFnData,\n TQueryData = TQueryFnData,\n TQueryKey extends QueryKey = QueryKey,\n TPageParam = never,\n >(\n options:\n | QueryObserverOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryData,\n TQueryKey,\n TPageParam\n >\n | DefaultedQueryObserverOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryData,\n TQueryKey\n >,\n ): DefaultedQueryObserverOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryData,\n TQueryKey\n > {\n if (options._defaulted) {\n return options as DefaultedQueryObserverOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryData,\n TQueryKey\n >\n }\n\n const defaultedOptions = {\n ...this.#defaultOptions.queries,\n ...this.getQueryDefaults(options.queryKey),\n ...options,\n _defaulted: true,\n }\n\n if (!defaultedOptions.queryHash) {\n defaultedOptions.queryHash = hashQueryKeyByOptions(\n defaultedOptions.queryKey,\n defaultedOptions,\n )\n }\n\n // dependent default values\n if (defaultedOptions.refetchOnReconnect === undefined) {\n defaultedOptions.refetchOnReconnect =\n defaultedOptions.networkMode !== 'always'\n }\n if (defaultedOptions.throwOnError === undefined) {\n defaultedOptions.throwOnError = !!defaultedOptions.suspense\n }\n\n if (!defaultedOptions.networkMode && defaultedOptions.persister) {\n defaultedOptions.networkMode = 'offlineFirst'\n }\n\n if (defaultedOptions.queryFn === skipToken) {\n defaultedOptions.enabled = false\n }\n\n return defaultedOptions as DefaultedQueryObserverOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryData,\n TQueryKey\n >\n }\n\n /**\n * The mutation counterpart of {@link QueryClient#defaultQueryOptions}. Called by framework\n * adapters (e.g. inside `useMutation`) to merge `queryClient.setMutationDefaults` for the\n * given `mutationKey`, then the client's `defaultOptions.mutations`, then the caller's options\n * on top. A no-op if the options are already defaulted (`_defaulted: true`).\n */\n defaultMutationOptions<T extends MutationOptions<any, any, any, any>>(\n options?: T,\n ): T {\n if (options?._defaulted) {\n return options\n }\n return {\n ...this.#defaultOptions.mutations,\n ...(options?.mutationKey &&\n this.getMutationDefaults(options.mutationKey)),\n ...options,\n _defaulted: true,\n } as T\n }\n\n /**\n * Clears both the query cache and the mutation cache this client is connected to.\n *\n * @example\n * ```ts\n * import { QueryClient } from '@tanstack/query-core'\n *\n * const queryClient = new QueryClient()\n * queryClient.clear()\n * ```\n */\n clear(): void {\n this.#queryCache.clear()\n this.#mutationCache.clear()\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AA8EA,IAAa,cAAb,MAAyB;CACvB;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CAEA,YAAY,SAA4B,CAAC,GAAG;EAC1C,KAAK,cAAc,OAAO,cAAc,IAAIA,mBAAAA,WAAW;EACvD,KAAK,iBAAiB,OAAO,iBAAiB,IAAIC,sBAAAA,cAAc;EAChE,KAAK,kBAAkB,OAAO,kBAAkB,CAAC;EACjD,KAAK,iCAAiB,IAAI,IAAI;EAC9B,KAAK,oCAAoB,IAAI,IAAI;EACjC,KAAK,cAAc;CACrB;;;;;;;CAQA,QAAc;EACZ,KAAK;EACL,IAAI,KAAK,gBAAgB,GAAG;EAE5B,KAAK,oBAAoBC,qBAAAA,aAAa,UAAU,OAAO,YAAY;GACjE,IAAI,SAAS;IACX,MAAM,KAAK,sBAAsB;IACjC,KAAK,YAAY,QAAQ;GAC3B;EACF,CAAC;EACD,KAAK,qBAAqBC,sBAAAA,cAAc,UAAU,OAAO,WAAW;GAClE,IAAI,QAAQ;IACV,MAAM,KAAK,sBAAsB;IACjC,KAAK,YAAY,SAAS;GAC5B;EACF,CAAC;CACH;;;;;;CAOA,UAAgB;EACd,KAAK;EACL,IAAI,KAAK,gBAAgB,GAAG;EAE5B,KAAK,oBAAoB;EACzB,KAAK,oBAAoB,KAAA;EAEzB,KAAK,qBAAqB;EAC1B,KAAK,qBAAqB,KAAA;CAC5B;;;;;;;;;;;;;CAcA,WACE,SACQ;EACR,OAAO,KAAK,YAAY,QAAQ;GAAE,GAAG;GAAS,aAAa;EAAW,CAAC,CAAC,CACrE;CACL;;;;;;;;;;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AAO;GACL,GAAG,KAAK,gBAAgB;GACxB,GAAI,SAAS,eACX,KAAK,oBAAoB,QAAQ,WAAW;GAC9C,GAAG;GACH,YAAY;EACd;CACF;;;;;;;;;;;;CAaA,QAAc;EACZ,KAAK,YAAY,MAAM;EACvB,KAAK,eAAe,MAAM;CAC5B;AACF"}
@@ -1,2 +1,2 @@
1
- import { on as QueryClient } from "./hydration-DRcloXEn.cjs";
1
+ import { on as QueryClient } from "./hydration-Br9VIGXa.cjs";
2
2
  export { QueryClient };
@@ -1,2 +1,2 @@
1
- import { on as QueryClient } from "./hydration-Bp57N3SP.js";
1
+ import { on as QueryClient } from "./hydration-B9t5w6NC.js";
2
2
  export { QueryClient };