@tanstack/vue-query 5.107.0 → 5.107.2

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 (219) hide show
  1. package/README.md +2 -3
  2. package/build/legacy/devtools/devtools.cjs +1 -1
  3. package/build/legacy/devtools/devtools.cjs.map +1 -1
  4. package/build/legacy/devtools/devtools.d.cts +1 -1
  5. package/build/legacy/devtools/devtools.d.ts +1 -1
  6. package/build/legacy/devtools/devtools.js +1 -1
  7. package/build/legacy/devtools/devtools.js.map +1 -1
  8. package/build/legacy/index.cjs +1 -1
  9. package/build/legacy/index.d.cts +4 -4
  10. package/build/legacy/index.d.ts +4 -4
  11. package/build/legacy/index.js +1 -1
  12. package/build/legacy/{infiniteQueryOptions-lJ_zR-As.d.cts → infiniteQueryOptions-CLfd_vOE.d.cts} +61 -17
  13. package/build/legacy/infiniteQueryOptions-CLfd_vOE.d.cts.map +1 -0
  14. package/build/legacy/{infiniteQueryOptions-CN37iZvc.d.ts → infiniteQueryOptions-vEnw-JaW.d.ts} +61 -17
  15. package/build/legacy/infiniteQueryOptions-vEnw-JaW.d.ts.map +1 -0
  16. package/build/legacy/infiniteQueryOptions.d.cts +1 -1
  17. package/build/legacy/infiniteQueryOptions.d.ts +1 -1
  18. package/build/{modern/queryClient-Ba4HSFnn.d.ts → legacy/queryClient-6AWIHAhP.d.ts} +2 -2
  19. package/build/legacy/{queryClient-Ba4HSFnn.d.ts.map → queryClient-6AWIHAhP.d.ts.map} +1 -1
  20. package/build/{modern/queryClient-BGn8uIej.d.cts → legacy/queryClient-yJW8K_VP.d.cts} +2 -2
  21. package/build/legacy/{queryClient-BGn8uIej.d.cts.map → queryClient-yJW8K_VP.d.cts.map} +1 -1
  22. package/build/legacy/queryClient.cjs +1 -1
  23. package/build/legacy/queryClient.cjs.map +1 -1
  24. package/build/legacy/queryClient.d.cts +1 -1
  25. package/build/legacy/queryClient.d.ts +1 -1
  26. package/build/legacy/queryClient.js +1 -1
  27. package/build/legacy/queryClient.js.map +1 -1
  28. package/build/{modern/queryOptions-BuZEBLtg.d.cts → legacy/queryOptions-nndmAASX.d.cts} +22 -11
  29. package/build/legacy/queryOptions-nndmAASX.d.cts.map +1 -0
  30. package/build/{modern/queryOptions-dXiBZnGk.d.ts → legacy/queryOptions-v0l6M7Eo.d.ts} +22 -11
  31. package/build/legacy/queryOptions-v0l6M7Eo.d.ts.map +1 -0
  32. package/build/legacy/queryOptions.cjs.map +1 -1
  33. package/build/legacy/queryOptions.d.cts +2 -2
  34. package/build/legacy/queryOptions.d.ts +2 -2
  35. package/build/legacy/queryOptions.js.map +1 -1
  36. package/build/legacy/types-u_Tu5Ybs.d.cts.map +1 -1
  37. package/build/legacy/types-u_Tu5Ybs.d.ts.map +1 -1
  38. package/build/legacy/useBaseQuery.cjs +11 -5
  39. package/build/legacy/useBaseQuery.cjs.map +1 -1
  40. package/build/legacy/useBaseQuery.d.cts +1 -1
  41. package/build/legacy/useBaseQuery.d.ts +1 -1
  42. package/build/legacy/useBaseQuery.js +11 -5
  43. package/build/legacy/useBaseQuery.js.map +1 -1
  44. package/build/legacy/useInfiniteQuery.cjs.map +1 -1
  45. package/build/legacy/useInfiniteQuery.d.cts +1 -1
  46. package/build/legacy/useInfiniteQuery.d.ts +1 -1
  47. package/build/legacy/useInfiniteQuery.js.map +1 -1
  48. package/build/legacy/useIsFetching.cjs.map +1 -1
  49. package/build/legacy/useIsFetching.d.cts +1 -1
  50. package/build/legacy/useIsFetching.d.ts +1 -1
  51. package/build/legacy/useIsFetching.js.map +1 -1
  52. package/build/legacy/useMutation.cjs.map +1 -1
  53. package/build/legacy/useMutation.d.cts +1 -1
  54. package/build/legacy/useMutation.d.ts +1 -1
  55. package/build/legacy/useMutation.js.map +1 -1
  56. package/build/legacy/useMutationState.cjs.map +1 -1
  57. package/build/legacy/useMutationState.d.cts +1 -1
  58. package/build/legacy/useMutationState.d.ts +1 -1
  59. package/build/legacy/useMutationState.js.map +1 -1
  60. package/build/legacy/usePrefetchInfiniteQuery.cjs.map +1 -1
  61. package/build/legacy/usePrefetchInfiniteQuery.d.cts +1 -1
  62. package/build/legacy/usePrefetchInfiniteQuery.d.ts +1 -1
  63. package/build/legacy/usePrefetchInfiniteQuery.js.map +1 -1
  64. package/build/legacy/usePrefetchQuery.cjs.map +1 -1
  65. package/build/legacy/usePrefetchQuery.d.cts +1 -1
  66. package/build/legacy/usePrefetchQuery.d.ts +1 -1
  67. package/build/legacy/usePrefetchQuery.js.map +1 -1
  68. package/build/legacy/useQueries.cjs +1 -1
  69. package/build/legacy/useQueries.cjs.map +1 -1
  70. package/build/legacy/useQueries.d.cts +2 -2
  71. package/build/legacy/useQueries.d.cts.map +1 -1
  72. package/build/legacy/useQueries.d.ts +2 -2
  73. package/build/legacy/useQueries.d.ts.map +1 -1
  74. package/build/legacy/useQueries.js +1 -1
  75. package/build/legacy/useQueries.js.map +1 -1
  76. package/build/legacy/useQuery.cjs.map +1 -1
  77. package/build/legacy/useQuery.d.cts +56 -22
  78. package/build/legacy/useQuery.d.cts.map +1 -1
  79. package/build/legacy/useQuery.d.ts +56 -22
  80. package/build/legacy/useQuery.d.ts.map +1 -1
  81. package/build/legacy/useQuery.js.map +1 -1
  82. package/build/legacy/useQueryClient.cjs.map +1 -1
  83. package/build/legacy/useQueryClient.d.cts +1 -1
  84. package/build/legacy/useQueryClient.d.cts.map +1 -1
  85. package/build/legacy/useQueryClient.d.ts +1 -1
  86. package/build/legacy/useQueryClient.d.ts.map +1 -1
  87. package/build/legacy/useQueryClient.js.map +1 -1
  88. package/build/legacy/utils.cjs.map +1 -1
  89. package/build/legacy/utils.js.map +1 -1
  90. package/build/legacy/vueQueryPlugin.cjs +1 -1
  91. package/build/legacy/vueQueryPlugin.cjs.map +1 -1
  92. package/build/legacy/vueQueryPlugin.d.cts +1 -1
  93. package/build/legacy/vueQueryPlugin.d.cts.map +1 -1
  94. package/build/legacy/vueQueryPlugin.d.ts +1 -1
  95. package/build/legacy/vueQueryPlugin.d.ts.map +1 -1
  96. package/build/legacy/vueQueryPlugin.js +1 -1
  97. package/build/legacy/vueQueryPlugin.js.map +1 -1
  98. package/build/modern/devtools/devtools.cjs +1 -1
  99. package/build/modern/devtools/devtools.cjs.map +1 -1
  100. package/build/modern/devtools/devtools.d.cts +1 -1
  101. package/build/modern/devtools/devtools.d.ts +1 -1
  102. package/build/modern/devtools/devtools.js +1 -1
  103. package/build/modern/devtools/devtools.js.map +1 -1
  104. package/build/modern/index.cjs +1 -1
  105. package/build/modern/index.d.cts +4 -4
  106. package/build/modern/index.d.ts +4 -4
  107. package/build/modern/index.js +1 -1
  108. package/build/modern/{infiniteQueryOptions-lJ_zR-As.d.cts → infiniteQueryOptions-CLfd_vOE.d.cts} +61 -17
  109. package/build/modern/infiniteQueryOptions-CLfd_vOE.d.cts.map +1 -0
  110. package/build/modern/{infiniteQueryOptions-CN37iZvc.d.ts → infiniteQueryOptions-vEnw-JaW.d.ts} +61 -17
  111. package/build/modern/infiniteQueryOptions-vEnw-JaW.d.ts.map +1 -0
  112. package/build/modern/infiniteQueryOptions.d.cts +1 -1
  113. package/build/modern/infiniteQueryOptions.d.ts +1 -1
  114. package/build/{legacy/queryClient-Ba4HSFnn.d.ts → modern/queryClient-6AWIHAhP.d.ts} +2 -2
  115. package/build/modern/{queryClient-Ba4HSFnn.d.ts.map → queryClient-6AWIHAhP.d.ts.map} +1 -1
  116. package/build/{legacy/queryClient-BGn8uIej.d.cts → modern/queryClient-yJW8K_VP.d.cts} +2 -2
  117. package/build/modern/{queryClient-BGn8uIej.d.cts.map → queryClient-yJW8K_VP.d.cts.map} +1 -1
  118. package/build/modern/queryClient.cjs +1 -1
  119. package/build/modern/queryClient.cjs.map +1 -1
  120. package/build/modern/queryClient.d.cts +1 -1
  121. package/build/modern/queryClient.d.ts +1 -1
  122. package/build/modern/queryClient.js +1 -1
  123. package/build/modern/queryClient.js.map +1 -1
  124. package/build/{legacy/queryOptions-BuZEBLtg.d.cts → modern/queryOptions-nndmAASX.d.cts} +22 -11
  125. package/build/modern/queryOptions-nndmAASX.d.cts.map +1 -0
  126. package/build/{legacy/queryOptions-dXiBZnGk.d.ts → modern/queryOptions-v0l6M7Eo.d.ts} +22 -11
  127. package/build/modern/queryOptions-v0l6M7Eo.d.ts.map +1 -0
  128. package/build/modern/queryOptions.cjs.map +1 -1
  129. package/build/modern/queryOptions.d.cts +2 -2
  130. package/build/modern/queryOptions.d.ts +2 -2
  131. package/build/modern/queryOptions.js.map +1 -1
  132. package/build/modern/types-u_Tu5Ybs.d.cts.map +1 -1
  133. package/build/modern/types-u_Tu5Ybs.d.ts.map +1 -1
  134. package/build/modern/useBaseQuery.cjs +11 -5
  135. package/build/modern/useBaseQuery.cjs.map +1 -1
  136. package/build/modern/useBaseQuery.d.cts +1 -1
  137. package/build/modern/useBaseQuery.d.ts +1 -1
  138. package/build/modern/useBaseQuery.js +11 -5
  139. package/build/modern/useBaseQuery.js.map +1 -1
  140. package/build/modern/useInfiniteQuery.cjs.map +1 -1
  141. package/build/modern/useInfiniteQuery.d.cts +1 -1
  142. package/build/modern/useInfiniteQuery.d.ts +1 -1
  143. package/build/modern/useInfiniteQuery.js.map +1 -1
  144. package/build/modern/useIsFetching.cjs.map +1 -1
  145. package/build/modern/useIsFetching.d.cts +1 -1
  146. package/build/modern/useIsFetching.d.ts +1 -1
  147. package/build/modern/useIsFetching.js.map +1 -1
  148. package/build/modern/useMutation.cjs.map +1 -1
  149. package/build/modern/useMutation.d.cts +1 -1
  150. package/build/modern/useMutation.d.ts +1 -1
  151. package/build/modern/useMutation.js.map +1 -1
  152. package/build/modern/useMutationState.cjs.map +1 -1
  153. package/build/modern/useMutationState.d.cts +1 -1
  154. package/build/modern/useMutationState.d.ts +1 -1
  155. package/build/modern/useMutationState.js.map +1 -1
  156. package/build/modern/usePrefetchInfiniteQuery.cjs.map +1 -1
  157. package/build/modern/usePrefetchInfiniteQuery.d.cts +1 -1
  158. package/build/modern/usePrefetchInfiniteQuery.d.ts +1 -1
  159. package/build/modern/usePrefetchInfiniteQuery.js.map +1 -1
  160. package/build/modern/usePrefetchQuery.cjs.map +1 -1
  161. package/build/modern/usePrefetchQuery.d.cts +1 -1
  162. package/build/modern/usePrefetchQuery.d.ts +1 -1
  163. package/build/modern/usePrefetchQuery.js.map +1 -1
  164. package/build/modern/useQueries.cjs +1 -1
  165. package/build/modern/useQueries.cjs.map +1 -1
  166. package/build/modern/useQueries.d.cts +2 -2
  167. package/build/modern/useQueries.d.cts.map +1 -1
  168. package/build/modern/useQueries.d.ts +2 -2
  169. package/build/modern/useQueries.d.ts.map +1 -1
  170. package/build/modern/useQueries.js +1 -1
  171. package/build/modern/useQueries.js.map +1 -1
  172. package/build/modern/useQuery.cjs.map +1 -1
  173. package/build/modern/useQuery.d.cts +56 -22
  174. package/build/modern/useQuery.d.cts.map +1 -1
  175. package/build/modern/useQuery.d.ts +56 -22
  176. package/build/modern/useQuery.d.ts.map +1 -1
  177. package/build/modern/useQuery.js.map +1 -1
  178. package/build/modern/useQueryClient.cjs.map +1 -1
  179. package/build/modern/useQueryClient.d.cts +1 -1
  180. package/build/modern/useQueryClient.d.cts.map +1 -1
  181. package/build/modern/useQueryClient.d.ts +1 -1
  182. package/build/modern/useQueryClient.d.ts.map +1 -1
  183. package/build/modern/useQueryClient.js.map +1 -1
  184. package/build/modern/utils.cjs.map +1 -1
  185. package/build/modern/utils.js.map +1 -1
  186. package/build/modern/vueQueryPlugin.cjs +1 -1
  187. package/build/modern/vueQueryPlugin.cjs.map +1 -1
  188. package/build/modern/vueQueryPlugin.d.cts +1 -1
  189. package/build/modern/vueQueryPlugin.d.cts.map +1 -1
  190. package/build/modern/vueQueryPlugin.d.ts +1 -1
  191. package/build/modern/vueQueryPlugin.d.ts.map +1 -1
  192. package/build/modern/vueQueryPlugin.js +1 -1
  193. package/build/modern/vueQueryPlugin.js.map +1 -1
  194. package/package.json +12 -2
  195. package/src/devtools/devtools.ts +2 -2
  196. package/src/index.ts +2 -0
  197. package/src/queryClient.ts +12 -12
  198. package/src/queryOptions.ts +40 -23
  199. package/src/types.ts +2 -0
  200. package/src/useBaseQuery.ts +71 -11
  201. package/src/useInfiniteQuery.ts +32 -28
  202. package/src/useIsFetching.ts +2 -2
  203. package/src/useMutation.ts +4 -4
  204. package/src/useMutationState.ts +2 -2
  205. package/src/usePrefetchInfiniteQuery.ts +1 -1
  206. package/src/usePrefetchQuery.ts +1 -1
  207. package/src/useQueries.ts +9 -5
  208. package/src/useQuery.ts +55 -21
  209. package/src/useQueryClient.ts +0 -1
  210. package/src/utils.ts +2 -2
  211. package/src/vueQueryPlugin.ts +2 -3
  212. package/build/legacy/infiniteQueryOptions-CN37iZvc.d.ts.map +0 -1
  213. package/build/legacy/infiniteQueryOptions-lJ_zR-As.d.cts.map +0 -1
  214. package/build/legacy/queryOptions-BuZEBLtg.d.cts.map +0 -1
  215. package/build/legacy/queryOptions-dXiBZnGk.d.ts.map +0 -1
  216. package/build/modern/infiniteQueryOptions-CN37iZvc.d.ts.map +0 -1
  217. package/build/modern/infiniteQueryOptions-lJ_zR-As.d.cts.map +0 -1
  218. package/build/modern/queryOptions-BuZEBLtg.d.cts.map +0 -1
  219. package/build/modern/queryOptions-dXiBZnGk.d.ts.map +0 -1
@@ -1,2 +1,2 @@
1
- import { a as UseInfiniteQueryOptions, i as UseInfiniteQueryDefinedReturnType, o as UseInfiniteQueryReturnType, s as useInfiniteQuery } from "./infiniteQueryOptions-CN37iZvc.js";
1
+ import { a as UseInfiniteQueryOptions, i as UseInfiniteQueryDefinedReturnType, o as UseInfiniteQueryReturnType, s as useInfiniteQuery } from "./infiniteQueryOptions-vEnw-JaW.js";
2
2
  export { UseInfiniteQueryDefinedReturnType, UseInfiniteQueryOptions, UseInfiniteQueryReturnType, useInfiniteQuery };
@@ -1 +1 @@
1
- {"version":3,"file":"useInfiniteQuery.js","names":[],"sources":["../../src/useInfiniteQuery.ts"],"sourcesContent":["import { InfiniteQueryObserver } from '@tanstack/query-core'\nimport { useBaseQuery } from './useBaseQuery'\nimport type {\n DefinedInitialDataInfiniteOptions,\n UndefinedInitialDataInfiniteOptions,\n} from './infiniteQueryOptions'\nimport type {\n DefaultError,\n DefinedInfiniteQueryObserverResult,\n InfiniteData,\n InfiniteQueryObserverOptions,\n InfiniteQueryObserverResult,\n QueryKey,\n QueryObserver,\n} from '@tanstack/query-core'\n\nimport type { UseBaseQueryReturnType } from './useBaseQuery'\n\nimport type {\n DeepUnwrapRef,\n MaybeRef,\n MaybeRefDeep,\n MaybeRefOrGetter,\n ShallowOption,\n} from './types'\nimport type { QueryClient } from './queryClient'\n\n/**\n * The options accepted by `useInfiniteQuery`. Same as {@link InfiniteQueryObserverOptions} from\n * `@tanstack/query-core`, plus the `shallow` option. Each option except `shallow` can also be a `ref` (and\n * `enabled` a reactive getter).\n */\nexport type UseInfiniteQueryOptions<\n TQueryFnData = unknown,\n TError = DefaultError,\n TData = TQueryFnData,\n TQueryKey extends QueryKey = QueryKey,\n TPageParam = unknown,\n> = MaybeRef<\n {\n [\n Property in keyof InfiniteQueryObserverOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryKey,\n TPageParam\n >\n ]: Property extends 'enabled'\n ? MaybeRefOrGetter<\n InfiniteQueryObserverOptions<\n TQueryFnData,\n TError,\n TData,\n DeepUnwrapRef<TQueryKey>,\n TPageParam\n >[Property]\n >\n : MaybeRefDeep<\n InfiniteQueryObserverOptions<\n TQueryFnData,\n TError,\n TData,\n DeepUnwrapRef<TQueryKey>,\n TPageParam\n >[Property]\n >\n } & ShallowOption\n>\n\n/**\n * The result of `useInfiniteQuery`: {@link InfiniteQueryObserverResult} from `@tanstack/query-core`, with\n * its properties wrapped in `Ref`s as in {@link UseBaseQueryReturnType}.\n */\nexport type UseInfiniteQueryReturnType<TData, TError> = UseBaseQueryReturnType<\n TData,\n TError,\n InfiniteQueryObserverResult<TData, TError>\n>\n\n/**\n * The result of `useInfiniteQuery` when `initialData` is set — `data` is never `undefined` (unless a `select`\n * changes `TData` to include `undefined`).\n */\nexport type UseInfiniteQueryDefinedReturnType<TData, TError> =\n UseBaseQueryReturnType<\n TData,\n TError,\n DefinedInfiniteQueryObserverResult<TData, TError>\n >\n\n/**\n * The options for `useInfiniteQuery` are identical to `useQuery`, with the addition of\n * `initialPageParam`, `getNextPageParam`, `getPreviousPageParam`, and `maxPages`.\n *\n * This overload is selected when `initialData` is known to be defined, so the resulting `data` is never\n * `undefined` (unless a `select` changes `TData` to include `undefined`).\n *\n * `enabled` tracks reactive dependencies automatically as a `ref`, a plain value, or a reactive getter\n * (`() => ...`). `queryKey` reacts through a `ref` for the array itself, or `ref`s and reactive getters as\n * individual entries — the array itself can't be a bare getter.\n * @param options - The {@link DefinedInitialDataInfiniteOptions} to use — everything you can pass to\n * `useInfiniteQuery`, with `initialData` known to be defined.\n * @param queryClient - Use this to use a custom `QueryClient`. Otherwise, the one provided by `VueQueryPlugin`\n * will be used.\n * @returns The same properties as `useQuery`, with the addition of `fetchNextPage`, `fetchPreviousPage`,\n * `hasNextPage`, `hasPreviousPage`, `isFetchingNextPage`, and `isFetchingPreviousPage`. `data.value.pages` and\n * `data.value.pageParams` are also added, as long as a `select` doesn't change `TData` away from its default\n * `InfiniteData<TQueryFnData>` shape.\n * @remarks Keep in mind that imperative fetch calls, such as `fetchNextPage`, may interfere with the default\n * refetch behavior, resulting in outdated data. Make sure to call these functions only in response to user\n * actions, or add conditions like `hasNextPage && !isFetching`.\n * @example\n * ```vue\n * <script setup lang=\"ts\">\n * import { useInfiniteQuery } from '@tanstack/vue-query'\n *\n * // `data` is never `undefined`, thanks to `initialData` — even if a refetch fails, so the\n * // list stays visible alongside the error.\n * const { data, isError, error } = useInfiniteQuery({\n * queryKey: ['projects'],\n * queryFn: ({ pageParam }) => fetchProjects(pageParam),\n * initialPageParam: 0,\n * getNextPageParam: (lastPage) => lastPage.nextId,\n * initialData: { pages: [], pageParams: [] },\n * })\n * </script>\n *\n * <template>\n * <span v-if=\"isError\">Error: {{ error.message }}</span>\n * <ul>\n * <template v-for=\"page in data.pages\" :key=\"page.nextId\">\n * <li v-for=\"project in page.projects\" :key=\"project.id\">{{ project.name }}</li>\n * </template>\n * </ul>\n * </template>\n * ```\n */\nexport function useInfiniteQuery<\n TQueryFnData,\n TError = DefaultError,\n TData = InfiniteData<TQueryFnData>,\n TQueryKey extends QueryKey = QueryKey,\n TPageParam = unknown,\n>(\n options: MaybeRefOrGetter<\n DefinedInitialDataInfiniteOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryKey,\n TPageParam\n >\n >,\n queryClient?: QueryClient,\n): UseInfiniteQueryDefinedReturnType<TData, TError>\n\n/**\n * The options for `useInfiniteQuery` are identical to `useQuery`, with the addition of\n * `initialPageParam`, `getNextPageParam`, `getPreviousPageParam`, and `maxPages`.\n *\n * `enabled` tracks reactive dependencies automatically as a `ref`, a plain value, or a reactive getter\n * (`() => ...`). `queryKey` reacts through a `ref` for the array itself, or `ref`s and reactive getters as\n * individual entries — the array itself can't be a bare getter.\n * @param options - The {@link UndefinedInitialDataInfiniteOptions} to use — everything you can pass to\n * `useInfiniteQuery`.\n * @param queryClient - Use this to use a custom `QueryClient`. Otherwise, the one provided by `VueQueryPlugin`\n * will be used.\n * @returns The same properties as `useQuery`, with the addition of `fetchNextPage`, `fetchPreviousPage`,\n * `hasNextPage`, `hasPreviousPage`, `isFetchingNextPage`, and `isFetchingPreviousPage`. `data.value.pages` and\n * `data.value.pageParams` are also added, as long as a `select` doesn't change `TData` away from its default\n * `InfiniteData<TQueryFnData>` shape.\n * @remarks Keep in mind that imperative fetch calls, such as `fetchNextPage`, may interfere with the default\n * refetch behavior, resulting in outdated data. Make sure to call these functions only in response to user\n * actions, or add conditions like `hasNextPage && !isFetching`.\n * @example\n * Fetching the next page from a \"Load More\" button click:\n * ```vue\n * <script setup lang=\"ts\">\n * import { useInfiniteQuery } from '@tanstack/vue-query'\n *\n * const {\n * data,\n * isPending,\n * isError,\n * error,\n * fetchNextPage,\n * hasNextPage,\n * isFetching,\n * isFetchingNextPage,\n * } = useInfiniteQuery({\n * queryKey: ['projects'],\n * queryFn: ({ pageParam }) => fetchProjects(pageParam),\n * initialPageParam: 0,\n * getNextPageParam: (lastPage) => lastPage.nextId,\n * })\n * </script>\n *\n * <template>\n * <span v-if=\"isPending\">Loading...</span>\n * <span v-else-if=\"isError\">Error: {{ error.message }}</span>\n * <template v-else>\n * <ul>\n * <template v-for=\"page in data.pages\" :key=\"page.nextId\">\n * <li v-for=\"project in page.projects\" :key=\"project.id\">{{ project.name }}</li>\n * </template>\n * </ul>\n * <button @click=\"fetchNextPage()\" :disabled=\"!hasNextPage || isFetching\">\n * {{ isFetchingNextPage ? 'Loading more...' : hasNextPage ? 'Load More' : 'Nothing more to load' }}\n * </button>\n * </template>\n * </template>\n * ```\n * @example\n * Fetching the next page automatically as the user scrolls, using an `IntersectionObserver` on a\n * sentinel element after the list:\n * ```vue\n * <script setup lang=\"ts\">\n * import { onUnmounted, ref, watch } from 'vue'\n * import { useInfiniteQuery } from '@tanstack/vue-query'\n *\n * const {\n * data,\n * isPending,\n * isError,\n * error,\n * fetchNextPage,\n * hasNextPage,\n * isFetching,\n * isFetchingNextPage,\n * } = useInfiniteQuery({\n * queryKey: ['projects'],\n * queryFn: ({ pageParam }) => fetchProjects(pageParam),\n * initialPageParam: 0,\n * getNextPageParam: (lastPage) => lastPage.nextId,\n * })\n *\n * const sentinel = ref<HTMLElement>()\n * let observer: IntersectionObserver | undefined\n *\n * watch(sentinel, (el) => {\n * observer?.disconnect()\n * if (el == null) return\n *\n * observer = new IntersectionObserver(([entry]) => {\n * if (entry?.isIntersecting && hasNextPage.value && !isFetching.value) {\n * fetchNextPage()\n * }\n * })\n * observer.observe(el)\n * })\n *\n * onUnmounted(() => observer?.disconnect())\n * </script>\n *\n * <template>\n * <span v-if=\"isPending\">Loading...</span>\n * <span v-else-if=\"isError\">Error: {{ error.message }}</span>\n * <template v-else>\n * <ul>\n * <template v-for=\"page in data.pages\" :key=\"page.nextId\">\n * <li v-for=\"project in page.projects\" :key=\"project.id\">{{ project.name }}</li>\n * </template>\n * </ul>\n * <div ref=\"sentinel\">{{ isFetchingNextPage ? 'Loading more...' : '' }}</div>\n * </template>\n * </template>\n * ```\n */\nexport function useInfiniteQuery<\n TQueryFnData,\n TError = DefaultError,\n TData = InfiniteData<TQueryFnData>,\n TQueryKey extends QueryKey = QueryKey,\n TPageParam = unknown,\n>(\n options: MaybeRefOrGetter<\n UndefinedInitialDataInfiniteOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryKey,\n TPageParam\n >\n >,\n queryClient?: QueryClient,\n): UseInfiniteQueryReturnType<TData, TError>\n\n/**\n * Fallback overload for options whose `initialData` presence isn't statically known — for example, a\n * `ref`/reactive object built up conditionally, rather than a plain object literal. Prefer one of the other\n * overloads when possible, since they infer whether `data` can be `undefined` from `initialData` directly.\n *\n * `enabled` tracks reactive dependencies automatically as a `ref`, a plain value, or a reactive getter\n * (`() => ...`). `queryKey` reacts through a `ref` for the array itself, or `ref`s and reactive getters as\n * individual entries — the array itself can't be a bare getter.\n * @param options - A `ref`, plain value, or reactive getter resolving to the {@link UseInfiniteQueryOptions} to\n * use.\n * @param queryClient - Use this to use a custom `QueryClient`. Otherwise, the one provided by `VueQueryPlugin`\n * will be used.\n * @returns The same properties as `useQuery`, with the addition of `fetchNextPage`, `fetchPreviousPage`,\n * `hasNextPage`, `hasPreviousPage`, `isFetchingNextPage`, and `isFetchingPreviousPage`.\n * @example\n * Passing a whole-options getter so `maxPages` reacts to a setting stored elsewhere, not just `queryKey`:\n * ```vue\n * <script setup lang=\"ts\">\n * import { useInfiniteQuery } from '@tanstack/vue-query'\n *\n * const props = defineProps<{ projectId: number; maxPages: number }>()\n *\n * const { data } = useInfiniteQuery(() => ({\n * queryKey: ['project', props.projectId, 'issues'],\n * queryFn: ({ pageParam }) => fetchIssues(props.projectId, pageParam),\n * initialPageParam: 0,\n * getNextPageParam: (lastPage) => lastPage.nextId,\n * maxPages: props.maxPages,\n * }))\n * </script>\n *\n * <template>\n * <template v-for=\"page in data?.pages\" :key=\"page.nextId\">\n * <li v-for=\"issue in page.issues\" :key=\"issue.id\">{{ issue.title }}</li>\n * </template>\n * </template>\n * ```\n * @example\n * A query that's disabled, type-safe, until `postId` is set — pass `skipToken` as `queryFn` instead of\n * setting `enabled: false`. This requires a whole-options getter: `queryFn` isn't itself reactive, so the\n * getter is what re-evaluates it on every change to `props.postId`:\n * ```vue\n * <script setup lang=\"ts\">\n * import { skipToken, useInfiniteQuery } from '@tanstack/vue-query'\n *\n * const props = defineProps<{ postId: string | undefined }>()\n *\n * // Use `isLoading`, not `isPending`, so the loading state doesn't show while the query is disabled.\n * const { data, isLoading, isError, error } = useInfiniteQuery(() => {\n * const postId = props.postId\n * return {\n * queryKey: ['post', postId, 'comments'],\n * queryFn:\n * postId != null\n * ? ({ pageParam }) => fetchComments(postId, pageParam)\n * : skipToken,\n * initialPageParam: 0,\n * getNextPageParam: (lastPage) => lastPage.nextId,\n * }\n * })\n * </script>\n *\n * <template>\n * <span v-if=\"props.postId == null\">Select a post</span>\n * <span v-else-if=\"isLoading\">Loading...</span>\n * <span v-else-if=\"isError\">Error: {{ error.message }}</span>\n * <ul v-else>\n * <template v-for=\"page in data.pages\" :key=\"page.nextId\">\n * <li v-for=\"comment in page.comments\" :key=\"comment.id\">{{ comment.text }}</li>\n * </template>\n * </ul>\n * </template>\n * ```\n */\nexport function useInfiniteQuery<\n TQueryFnData,\n TError = DefaultError,\n TData = InfiniteData<TQueryFnData>,\n TQueryKey extends QueryKey = QueryKey,\n TPageParam = unknown,\n>(\n options: MaybeRefOrGetter<\n UseInfiniteQueryOptions<TQueryFnData, TError, TData, TQueryKey, TPageParam>\n >,\n queryClient?: QueryClient,\n): UseInfiniteQueryReturnType<TData, TError>\n\nexport function useInfiniteQuery(\n options: MaybeRefOrGetter<UseInfiniteQueryOptions>,\n queryClient?: QueryClient,\n) {\n return useBaseQuery(\n InfiniteQueryObserver as typeof QueryObserver,\n options,\n queryClient,\n )\n}\n"],"mappings":";;;AAuXA,SAAgB,iBACd,SACA,aACA;CACA,OAAO,aACL,uBACA,SACA,WACF;AACF"}
1
+ {"version":3,"file":"useInfiniteQuery.js","names":[],"sources":["../../src/useInfiniteQuery.ts"],"sourcesContent":["import { InfiniteQueryObserver } from '@tanstack/query-core'\nimport { useBaseQuery } from './useBaseQuery'\nimport type {\n DefaultError,\n DefinedInfiniteQueryObserverResult,\n InfiniteData,\n InfiniteQueryObserverOptions,\n InfiniteQueryObserverResult,\n QueryKey,\n QueryObserver,\n} from '@tanstack/query-core'\nimport type {\n DefinedInitialDataInfiniteOptions,\n UndefinedInitialDataInfiniteOptions,\n} from './infiniteQueryOptions'\nimport type { QueryClient } from './queryClient'\nimport type { VueQueryEnabledOption } from './queryOptions'\nimport type {\n DeepUnwrapRef,\n MaybeRef,\n MaybeRefDeep,\n MaybeRefOrGetter,\n ShallowOption,\n} from './types'\nimport type { UseBaseQueryReturnType } from './useBaseQuery'\n\n/**\n * The options accepted by `useInfiniteQuery`. Extends {@link InfiniteQueryObserverOptions} from\n * `@tanstack/query-core` with the `vue-query`-specific `shallow` option. Each option except `shallow` can also\n * be a `ref` (and `enabled` a zero-argument getter or query-core's `(query) => boolean` callback).\n * @template TQueryFnData - The type of a single page, as your `queryFn` resolves it.\n * @template TError - The type of errors your `queryFn` may throw.\n * @template TData - The type `data` ends up as after `select` runs — defaults to `TQueryFnData`.\n * @template TQueryKey - The type of your `queryKey`.\n * @template TPageParam - The type of the parameter passed to `queryFn` to fetch a given page.\n */\nexport type UseInfiniteQueryOptions<\n TQueryFnData = unknown,\n TError = DefaultError,\n TData = TQueryFnData,\n TQueryKey extends QueryKey = QueryKey,\n TPageParam = unknown,\n> = MaybeRef<\n {\n [\n Property in keyof InfiniteQueryObserverOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryKey,\n TPageParam\n >\n ]: Property extends 'enabled'\n ? VueQueryEnabledOption<\n TQueryFnData,\n TError,\n InfiniteData<TQueryFnData, TPageParam>,\n DeepUnwrapRef<TQueryKey>\n >\n : MaybeRefDeep<\n InfiniteQueryObserverOptions<\n TQueryFnData,\n TError,\n TData,\n DeepUnwrapRef<TQueryKey>,\n TPageParam\n >[Property]\n >\n } & ShallowOption\n>\n\n/**\n * The result of `useInfiniteQuery`: {@link InfiniteQueryObserverResult} from `@tanstack/query-core`, with\n * its properties wrapped in `Ref`s as in {@link UseBaseQueryReturnType}.\n */\nexport type UseInfiniteQueryReturnType<TData, TError> = UseBaseQueryReturnType<\n TData,\n TError,\n InfiniteQueryObserverResult<TData, TError>\n>\n\n/**\n * The result of `useInfiniteQuery` when `initialData` is set — `data` is never `undefined` (unless a `select`\n * changes `TData` to include `undefined`).\n */\nexport type UseInfiniteQueryDefinedReturnType<TData, TError> =\n UseBaseQueryReturnType<\n TData,\n TError,\n DefinedInfiniteQueryObserverResult<TData, TError>\n >\n\n/**\n * The options for `useInfiniteQuery` are identical to `useQuery`, with the addition of\n * `initialPageParam`, `getNextPageParam`, `getPreviousPageParam`, and `maxPages`.\n *\n * This overload is selected when `initialData` is known to be defined, so the resulting `data` is never\n * `undefined` (unless a `select` changes `TData` to include `undefined`).\n *\n * `enabled` accepts a `ref`, a plain boolean, or a zero-argument getter (`() => ...`): a `ref` or a getter is\n * tracked, while a plain boolean isn't tracked on its own. query-core's `(query) => boolean` callback is\n * accepted too and is passed through untracked. `queryKey` reacts through a `ref` for the array itself, or\n * `ref`s and reactive getters as individual entries — the array itself can't be a bare getter.\n * @param options - The {@link DefinedInitialDataInfiniteOptions} to use — everything you can pass to\n * `useInfiniteQuery`, with `initialData` known to be defined.\n * @param queryClient - Use this to use a custom `QueryClient`. Otherwise, the one provided by `VueQueryPlugin`\n * will be used.\n * @returns The same properties as `useQuery`, with the addition of `fetchNextPage`, `fetchPreviousPage`,\n * `hasNextPage`, `hasPreviousPage`, `isFetchingNextPage`, and `isFetchingPreviousPage`. `data.value.pages` and\n * `data.value.pageParams` are also added, as long as a `select` doesn't change `TData` away from its default\n * `InfiniteData<TQueryFnData>` shape.\n * @remarks Keep in mind that imperative fetch calls, such as `fetchNextPage`, may interfere with the default\n * refetch behavior, resulting in outdated data. Make sure to call these functions only in response to user\n * actions, or add conditions like `hasNextPage && !isFetching`.\n * @example\n * ```vue\n * <script setup lang=\"ts\">\n * import { useInfiniteQuery } from '@tanstack/vue-query'\n *\n * // `data` is never `undefined`, thanks to `initialData` — even if a refetch fails, so the\n * // list stays visible alongside the error.\n * const { data, isError, error } = useInfiniteQuery({\n * queryKey: ['projects'],\n * queryFn: ({ pageParam }) => fetchProjects(pageParam),\n * initialPageParam: 0,\n * getNextPageParam: (lastPage) => lastPage.nextId,\n * initialData: { pages: [], pageParams: [] },\n * })\n * </script>\n *\n * <template>\n * <span v-if=\"isError\">Error: {{ error.message }}</span>\n * <ul>\n * <template v-for=\"page in data.pages\" :key=\"page.nextId\">\n * <li v-for=\"project in page.projects\" :key=\"project.id\">{{ project.name }}</li>\n * </template>\n * </ul>\n * </template>\n * ```\n */\nexport function useInfiniteQuery<\n TQueryFnData,\n TError = DefaultError,\n TData = InfiniteData<TQueryFnData>,\n TQueryKey extends QueryKey = QueryKey,\n TPageParam = unknown,\n>(\n options: MaybeRefOrGetter<\n DefinedInitialDataInfiniteOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryKey,\n TPageParam\n >\n >,\n queryClient?: QueryClient,\n): UseInfiniteQueryDefinedReturnType<TData, TError>\n\n/**\n * The options for `useInfiniteQuery` are identical to `useQuery`, with the addition of\n * `initialPageParam`, `getNextPageParam`, `getPreviousPageParam`, and `maxPages`.\n *\n * `enabled` accepts a `ref`, a plain boolean, or a zero-argument getter (`() => ...`): a `ref` or a getter is\n * tracked, while a plain boolean isn't tracked on its own. query-core's `(query) => boolean` callback is\n * accepted too and is passed through untracked. `queryKey` reacts through a `ref` for the array itself, or\n * `ref`s and reactive getters as individual entries — the array itself can't be a bare getter.\n * @param options - The {@link UndefinedInitialDataInfiniteOptions} to use — everything you can pass to\n * `useInfiniteQuery`.\n * @param queryClient - Use this to use a custom `QueryClient`. Otherwise, the one provided by `VueQueryPlugin`\n * will be used.\n * @returns The same properties as `useQuery`, with the addition of `fetchNextPage`, `fetchPreviousPage`,\n * `hasNextPage`, `hasPreviousPage`, `isFetchingNextPage`, and `isFetchingPreviousPage`. `data.value.pages` and\n * `data.value.pageParams` are also added, as long as a `select` doesn't change `TData` away from its default\n * `InfiniteData<TQueryFnData>` shape.\n * @remarks Keep in mind that imperative fetch calls, such as `fetchNextPage`, may interfere with the default\n * refetch behavior, resulting in outdated data. Make sure to call these functions only in response to user\n * actions, or add conditions like `hasNextPage && !isFetching`.\n * @example\n * Fetching the next page from a \"Load More\" button click:\n * ```vue\n * <script setup lang=\"ts\">\n * import { useInfiniteQuery } from '@tanstack/vue-query'\n *\n * const {\n * data,\n * isPending,\n * isError,\n * error,\n * fetchNextPage,\n * hasNextPage,\n * isFetching,\n * isFetchingNextPage,\n * } = useInfiniteQuery({\n * queryKey: ['projects'],\n * queryFn: ({ pageParam }) => fetchProjects(pageParam),\n * initialPageParam: 0,\n * getNextPageParam: (lastPage) => lastPage.nextId,\n * })\n * </script>\n *\n * <template>\n * <span v-if=\"isPending\">Loading...</span>\n * <span v-else-if=\"isError\">Error: {{ error.message }}</span>\n * <template v-else>\n * <ul>\n * <template v-for=\"page in data.pages\" :key=\"page.nextId\">\n * <li v-for=\"project in page.projects\" :key=\"project.id\">{{ project.name }}</li>\n * </template>\n * </ul>\n * <button @click=\"fetchNextPage()\" :disabled=\"!hasNextPage || isFetching\">\n * {{ isFetchingNextPage ? 'Loading more...' : hasNextPage ? 'Load More' : 'Nothing more to load' }}\n * </button>\n * </template>\n * </template>\n * ```\n * @example\n * Fetching the next page automatically as the user scrolls, using an `IntersectionObserver` on a\n * sentinel element after the list:\n * ```vue\n * <script setup lang=\"ts\">\n * import { onUnmounted, ref, watch } from 'vue'\n * import { useInfiniteQuery } from '@tanstack/vue-query'\n *\n * const {\n * data,\n * isPending,\n * isError,\n * error,\n * fetchNextPage,\n * hasNextPage,\n * isFetching,\n * isFetchingNextPage,\n * } = useInfiniteQuery({\n * queryKey: ['projects'],\n * queryFn: ({ pageParam }) => fetchProjects(pageParam),\n * initialPageParam: 0,\n * getNextPageParam: (lastPage) => lastPage.nextId,\n * })\n *\n * const sentinel = ref<HTMLElement>()\n * let observer: IntersectionObserver | undefined\n *\n * watch(sentinel, (el) => {\n * observer?.disconnect()\n * if (el == null) return\n *\n * observer = new IntersectionObserver(([entry]) => {\n * if (entry?.isIntersecting && hasNextPage.value && !isFetching.value) {\n * fetchNextPage()\n * }\n * })\n * observer.observe(el)\n * })\n *\n * onUnmounted(() => observer?.disconnect())\n * </script>\n *\n * <template>\n * <span v-if=\"isPending\">Loading...</span>\n * <span v-else-if=\"isError\">Error: {{ error.message }}</span>\n * <template v-else>\n * <ul>\n * <template v-for=\"page in data.pages\" :key=\"page.nextId\">\n * <li v-for=\"project in page.projects\" :key=\"project.id\">{{ project.name }}</li>\n * </template>\n * </ul>\n * <div ref=\"sentinel\">{{ isFetchingNextPage ? 'Loading more...' : '' }}</div>\n * </template>\n * </template>\n * ```\n */\nexport function useInfiniteQuery<\n TQueryFnData,\n TError = DefaultError,\n TData = InfiniteData<TQueryFnData>,\n TQueryKey extends QueryKey = QueryKey,\n TPageParam = unknown,\n>(\n options: MaybeRefOrGetter<\n UndefinedInitialDataInfiniteOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryKey,\n TPageParam\n >\n >,\n queryClient?: QueryClient,\n): UseInfiniteQueryReturnType<TData, TError>\n\n/**\n * Fallback overload for options whose `initialData` presence isn't statically known — for example, a\n * `ref`/reactive object built up conditionally, rather than a plain object literal. Prefer one of the other\n * overloads when possible, since they infer whether `data` can be `undefined` from `initialData` directly.\n *\n * `enabled` accepts a `ref`, a plain boolean, or a zero-argument getter (`() => ...`): a `ref` or a getter is\n * tracked, while a plain boolean isn't tracked on its own. query-core's `(query) => boolean` callback is\n * accepted too and is passed through untracked. `queryKey` reacts through a `ref` for the array itself, or\n * `ref`s and reactive getters as individual entries — the array itself can't be a bare getter.\n * @param options - A `ref`, plain value, or reactive getter resolving to the {@link UseInfiniteQueryOptions} to\n * use.\n * @param queryClient - Use this to use a custom `QueryClient`. Otherwise, the one provided by `VueQueryPlugin`\n * will be used.\n * @returns The same properties as `useQuery`, with the addition of `fetchNextPage`, `fetchPreviousPage`,\n * `hasNextPage`, `hasPreviousPage`, `isFetchingNextPage`, and `isFetchingPreviousPage`.\n * @example\n * Passing a whole-options getter so `maxPages` reacts to a setting stored elsewhere, not just `queryKey`:\n * ```vue\n * <script setup lang=\"ts\">\n * import { useInfiniteQuery } from '@tanstack/vue-query'\n *\n * const props = defineProps<{ projectId: number; maxPages: number }>()\n *\n * const { data } = useInfiniteQuery(() => ({\n * queryKey: ['project', props.projectId, 'issues'],\n * queryFn: ({ pageParam }) => fetchIssues(props.projectId, pageParam),\n * initialPageParam: 0,\n * getNextPageParam: (lastPage) => lastPage.nextId,\n * maxPages: props.maxPages,\n * }))\n * </script>\n *\n * <template>\n * <template v-for=\"page in data?.pages\" :key=\"page.nextId\">\n * <li v-for=\"issue in page.issues\" :key=\"issue.id\">{{ issue.title }}</li>\n * </template>\n * </template>\n * ```\n * @example\n * A query that's disabled, type-safe, until `postId` is set — pass `skipToken` as `queryFn` instead of\n * setting `enabled: false`. This requires a whole-options getter: `queryFn` isn't itself reactive, so the\n * getter is what re-evaluates it on every change to `props.postId`:\n * ```vue\n * <script setup lang=\"ts\">\n * import { skipToken, useInfiniteQuery } from '@tanstack/vue-query'\n *\n * const props = defineProps<{ postId: string | undefined }>()\n *\n * // Use `isLoading`, not `isPending`, so the loading state doesn't show while the query is disabled.\n * const { data, isLoading, isError, error } = useInfiniteQuery(() => {\n * const postId = props.postId\n * return {\n * queryKey: ['post', postId, 'comments'],\n * queryFn:\n * postId != null\n * ? ({ pageParam }) => fetchComments(postId, pageParam)\n * : skipToken,\n * initialPageParam: 0,\n * getNextPageParam: (lastPage) => lastPage.nextId,\n * }\n * })\n * </script>\n *\n * <template>\n * <span v-if=\"props.postId == null\">Select a post</span>\n * <span v-else-if=\"isLoading\">Loading...</span>\n * <span v-else-if=\"isError\">Error: {{ error.message }}</span>\n * <ul v-else>\n * <template v-for=\"page in data.pages\" :key=\"page.nextId\">\n * <li v-for=\"comment in page.comments\" :key=\"comment.id\">{{ comment.text }}</li>\n * </template>\n * </ul>\n * </template>\n * ```\n */\nexport function useInfiniteQuery<\n TQueryFnData,\n TError = DefaultError,\n TData = InfiniteData<TQueryFnData>,\n TQueryKey extends QueryKey = QueryKey,\n TPageParam = unknown,\n>(\n options: MaybeRefOrGetter<\n UseInfiniteQueryOptions<TQueryFnData, TError, TData, TQueryKey, TPageParam>\n >,\n queryClient?: QueryClient,\n): UseInfiniteQueryReturnType<TData, TError>\n\nexport function useInfiniteQuery(\n options: MaybeRefOrGetter<UseInfiniteQueryOptions>,\n queryClient?: QueryClient,\n) {\n return useBaseQuery(\n InfiniteQueryObserver as typeof QueryObserver,\n options,\n queryClient,\n )\n}\n"],"mappings":";;;AA2XA,SAAgB,iBACd,SACA,aACA;CACA,OAAO,aACL,uBACA,SACA,WACF;AACF"}
@@ -1 +1 @@
1
- {"version":3,"file":"useIsFetching.cjs","names":["getCurrentScope","useQueryClient","ref","cloneDeepUnref"],"sources":["../../src/useIsFetching.ts"],"sourcesContent":["import { getCurrentScope, onScopeDispose, ref, watchEffect } from 'vue-demi'\nimport { useQueryClient } from './useQueryClient'\nimport { cloneDeepUnref } from './utils'\nimport type { Ref } from 'vue-demi'\nimport type { QueryFilters } from '@tanstack/query-core'\nimport type { MaybeRefDeep } from './types'\nimport type { QueryClient } from './queryClient'\n\n/**\n * The filters accepted by `useIsFetching`: {@link QueryFilters} as a plain object, a `ref`, or a reactive\n * getter.\n */\nexport type UseIsFetchingFilters =\n | MaybeRefDeep<Omit<QueryFilters, 'fetchStatus'>>\n | (() => MaybeRefDeep<Omit<QueryFilters, 'fetchStatus'>>)\n\n/**\n * The `useIsFetching` composable returns a `ref` to the `number` of the queries that your application is\n * loading or fetching in the background (useful for app-wide loading indicators).\n *\n * `fetchingFilters` may be a plain object, `MaybeRefDeep`, or a reactive getter (`() => ({ ... })`) — pass a\n * getter if the filters themselves depend on other reactive state.\n * @param fetchingFilters - The {@link QueryFilters} to narrow down the matched queries.\n * @param queryClient - Use this to use a custom `QueryClient`. Otherwise, the one provided by `VueQueryPlugin`\n * will be used.\n * @returns A `ref` to the `number` of the queries that your application is currently loading or fetching in\n * the background.\n * @example\n * ```vue\n * <script setup lang=\"ts\">\n * import { useIsFetching } from '@tanstack/vue-query'\n *\n * // How many queries matching the posts prefix are fetching?\n * const isFetchingPosts = useIsFetching({ queryKey: ['posts'] })\n * </script>\n *\n * <template>\n * <span v-if=\"isFetchingPosts\">Refreshing posts...</span>\n * </template>\n * ```\n * @example\n * A global loading indicator for any query fetching in the background, not just the ones on screen:\n * ```vue\n * <script setup lang=\"ts\">\n * import { useIsFetching } from '@tanstack/vue-query'\n *\n * const isFetching = useIsFetching()\n * </script>\n *\n * <template>\n * <div v-if=\"isFetching\">Queries are fetching in the background...</div>\n * </template>\n * ```\n */\nexport function useIsFetching(\n fetchingFilters: UseIsFetchingFilters = {},\n queryClient?: QueryClient,\n): Ref<number> {\n if (process.env.NODE_ENV === 'development') {\n if (!getCurrentScope()) {\n console.warn(\n 'vue-query composable like \"useQuery()\" should only be used inside a \"setup()\" function or a running effect scope. They might otherwise lead to memory leaks.',\n )\n }\n }\n\n const client = queryClient || useQueryClient()\n\n const isFetching = ref()\n\n const listener = () => {\n const resolvedFilters =\n typeof fetchingFilters === 'function'\n ? fetchingFilters()\n : fetchingFilters\n isFetching.value = client.isFetching(cloneDeepUnref(resolvedFilters))\n }\n\n const unsubscribe = client.getQueryCache().subscribe(listener)\n\n watchEffect(listener)\n\n onScopeDispose(() => {\n unsubscribe()\n })\n\n return isFetching\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAsDA,SAAgB,cACd,kBAAwC,CAAC,GACzC,aACa;CACb,IAAI,QAAQ,IAAI,aAAa,eACvB;MAAA,EAAA,GAACA,SAAAA,gBAAAA,CAAgB,GACnB,QAAQ,KACN,kKACF;CAAA;CAIJ,MAAM,SAAS,eAAeC,uBAAAA,eAAe;CAE7C,MAAM,cAAA,GAAaC,SAAAA,IAAAA,CAAI;CAEvB,MAAM,iBAAiB;EACrB,MAAM,kBACJ,OAAO,oBAAoB,aACvB,gBAAgB,IAChB;EACN,WAAW,QAAQ,OAAO,WAAWC,cAAAA,eAAe,eAAe,CAAC;CACtE;CAEA,MAAM,cAAc,OAAO,cAAc,CAAC,CAAC,UAAU,QAAQ;CAE7D,CAAA,GAAA,SAAA,YAAA,CAAY,QAAQ;CAEpB,CAAA,GAAA,SAAA,eAAA,OAAqB;EACnB,YAAY;CACd,CAAC;CAED,OAAO;AACT"}
1
+ {"version":3,"file":"useIsFetching.cjs","names":["getCurrentScope","useQueryClient","ref","cloneDeepUnref"],"sources":["../../src/useIsFetching.ts"],"sourcesContent":["import { getCurrentScope, onScopeDispose, ref, watchEffect } from 'vue-demi'\nimport { useQueryClient } from './useQueryClient'\nimport { cloneDeepUnref } from './utils'\nimport type { QueryFilters } from '@tanstack/query-core'\nimport type { Ref } from 'vue-demi'\nimport type { QueryClient } from './queryClient'\nimport type { MaybeRefDeep } from './types'\n\n/**\n * The filters accepted by `useIsFetching`: {@link QueryFilters} as a plain object, a `ref`, or a reactive\n * getter.\n */\nexport type UseIsFetchingFilters =\n | MaybeRefDeep<Omit<QueryFilters, 'fetchStatus'>>\n | (() => MaybeRefDeep<Omit<QueryFilters, 'fetchStatus'>>)\n\n/**\n * The `useIsFetching` composable returns a `ref` to the `number` of the queries that your application is\n * loading or fetching in the background (useful for app-wide loading indicators).\n *\n * `fetchingFilters` may be a plain object, `MaybeRefDeep`, or a reactive getter (`() => ({ ... })`) — pass a\n * getter if the filters themselves depend on other reactive state.\n * @param fetchingFilters - The {@link QueryFilters} to narrow down the matched queries.\n * @param queryClient - Use this to use a custom `QueryClient`. Otherwise, the one provided by `VueQueryPlugin`\n * will be used.\n * @returns A `ref` to the `number` of the queries that your application is currently loading or fetching in\n * the background.\n * @example\n * ```vue\n * <script setup lang=\"ts\">\n * import { useIsFetching } from '@tanstack/vue-query'\n *\n * // How many queries matching the posts prefix are fetching?\n * const isFetchingPosts = useIsFetching({ queryKey: ['posts'] })\n * </script>\n *\n * <template>\n * <span v-if=\"isFetchingPosts\">Refreshing posts...</span>\n * </template>\n * ```\n * @example\n * A global loading indicator for any query fetching in the background, not just the ones on screen:\n * ```vue\n * <script setup lang=\"ts\">\n * import { useIsFetching } from '@tanstack/vue-query'\n *\n * const isFetching = useIsFetching()\n * </script>\n *\n * <template>\n * <div v-if=\"isFetching\">Queries are fetching in the background...</div>\n * </template>\n * ```\n */\nexport function useIsFetching(\n fetchingFilters: UseIsFetchingFilters = {},\n queryClient?: QueryClient,\n): Ref<number> {\n if (process.env.NODE_ENV === 'development') {\n if (!getCurrentScope()) {\n console.warn(\n 'vue-query composable like \"useQuery()\" should only be used inside a \"setup()\" function or a running effect scope. They might otherwise lead to memory leaks.',\n )\n }\n }\n\n const client = queryClient || useQueryClient()\n\n const isFetching = ref()\n\n const listener = () => {\n const resolvedFilters =\n typeof fetchingFilters === 'function'\n ? fetchingFilters()\n : fetchingFilters\n isFetching.value = client.isFetching(cloneDeepUnref(resolvedFilters))\n }\n\n const unsubscribe = client.getQueryCache().subscribe(listener)\n\n watchEffect(listener)\n\n onScopeDispose(() => {\n unsubscribe()\n })\n\n return isFetching\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAsDA,SAAgB,cACd,kBAAwC,CAAC,GACzC,aACa;CACb,IAAI,QAAQ,IAAI,aAAa,eACvB;MAAA,EAAA,GAACA,SAAAA,gBAAAA,CAAgB,GACnB,QAAQ,KACN,kKACF;CAAA;CAIJ,MAAM,SAAS,eAAeC,uBAAAA,eAAe;CAE7C,MAAM,cAAA,GAAaC,SAAAA,IAAAA,CAAI;CAEvB,MAAM,iBAAiB;EACrB,MAAM,kBACJ,OAAO,oBAAoB,aACvB,gBAAgB,IAChB;EACN,WAAW,QAAQ,OAAO,WAAWC,cAAAA,eAAe,eAAe,CAAC;CACtE;CAEA,MAAM,cAAc,OAAO,cAAc,CAAC,CAAC,UAAU,QAAQ;CAE7D,CAAA,GAAA,SAAA,YAAA,CAAY,QAAQ;CAEpB,CAAA,GAAA,SAAA,eAAA,OAAqB;EACnB,YAAY;CACd,CAAC;CAED,OAAO;AACT"}
@@ -1,5 +1,5 @@
1
1
  import { o as MaybeRefDeep } from "./types-u_Tu5Ybs.cjs";
2
- import { t as QueryClient$1 } from "./queryClient-BGn8uIej.cjs";
2
+ import { t as QueryClient$1 } from "./queryClient-yJW8K_VP.cjs";
3
3
  import { QueryFilters } from "@tanstack/query-core";
4
4
  import { Ref } from "vue-demi";
5
5
  /**
@@ -1,5 +1,5 @@
1
1
  import { o as MaybeRefDeep } from "./types-u_Tu5Ybs.js";
2
- import { t as QueryClient$1 } from "./queryClient-Ba4HSFnn.js";
2
+ import { t as QueryClient$1 } from "./queryClient-6AWIHAhP.js";
3
3
  import { QueryFilters } from "@tanstack/query-core";
4
4
  import { Ref } from "vue-demi";
5
5
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"useIsFetching.js","names":[],"sources":["../../src/useIsFetching.ts"],"sourcesContent":["import { getCurrentScope, onScopeDispose, ref, watchEffect } from 'vue-demi'\nimport { useQueryClient } from './useQueryClient'\nimport { cloneDeepUnref } from './utils'\nimport type { Ref } from 'vue-demi'\nimport type { QueryFilters } from '@tanstack/query-core'\nimport type { MaybeRefDeep } from './types'\nimport type { QueryClient } from './queryClient'\n\n/**\n * The filters accepted by `useIsFetching`: {@link QueryFilters} as a plain object, a `ref`, or a reactive\n * getter.\n */\nexport type UseIsFetchingFilters =\n | MaybeRefDeep<Omit<QueryFilters, 'fetchStatus'>>\n | (() => MaybeRefDeep<Omit<QueryFilters, 'fetchStatus'>>)\n\n/**\n * The `useIsFetching` composable returns a `ref` to the `number` of the queries that your application is\n * loading or fetching in the background (useful for app-wide loading indicators).\n *\n * `fetchingFilters` may be a plain object, `MaybeRefDeep`, or a reactive getter (`() => ({ ... })`) — pass a\n * getter if the filters themselves depend on other reactive state.\n * @param fetchingFilters - The {@link QueryFilters} to narrow down the matched queries.\n * @param queryClient - Use this to use a custom `QueryClient`. Otherwise, the one provided by `VueQueryPlugin`\n * will be used.\n * @returns A `ref` to the `number` of the queries that your application is currently loading or fetching in\n * the background.\n * @example\n * ```vue\n * <script setup lang=\"ts\">\n * import { useIsFetching } from '@tanstack/vue-query'\n *\n * // How many queries matching the posts prefix are fetching?\n * const isFetchingPosts = useIsFetching({ queryKey: ['posts'] })\n * </script>\n *\n * <template>\n * <span v-if=\"isFetchingPosts\">Refreshing posts...</span>\n * </template>\n * ```\n * @example\n * A global loading indicator for any query fetching in the background, not just the ones on screen:\n * ```vue\n * <script setup lang=\"ts\">\n * import { useIsFetching } from '@tanstack/vue-query'\n *\n * const isFetching = useIsFetching()\n * </script>\n *\n * <template>\n * <div v-if=\"isFetching\">Queries are fetching in the background...</div>\n * </template>\n * ```\n */\nexport function useIsFetching(\n fetchingFilters: UseIsFetchingFilters = {},\n queryClient?: QueryClient,\n): Ref<number> {\n if (process.env.NODE_ENV === 'development') {\n if (!getCurrentScope()) {\n console.warn(\n 'vue-query composable like \"useQuery()\" should only be used inside a \"setup()\" function or a running effect scope. They might otherwise lead to memory leaks.',\n )\n }\n }\n\n const client = queryClient || useQueryClient()\n\n const isFetching = ref()\n\n const listener = () => {\n const resolvedFilters =\n typeof fetchingFilters === 'function'\n ? fetchingFilters()\n : fetchingFilters\n isFetching.value = client.isFetching(cloneDeepUnref(resolvedFilters))\n }\n\n const unsubscribe = client.getQueryCache().subscribe(listener)\n\n watchEffect(listener)\n\n onScopeDispose(() => {\n unsubscribe()\n })\n\n return isFetching\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAsDA,SAAgB,cACd,kBAAwC,CAAC,GACzC,aACa;CACb,IAAI,QAAQ,IAAI,aAAa,eACvB;MAAA,CAAC,gBAAgB,GACnB,QAAQ,KACN,kKACF;CAAA;CAIJ,MAAM,SAAS,eAAe,eAAe;CAE7C,MAAM,aAAa,IAAI;CAEvB,MAAM,iBAAiB;EACrB,MAAM,kBACJ,OAAO,oBAAoB,aACvB,gBAAgB,IAChB;EACN,WAAW,QAAQ,OAAO,WAAW,eAAe,eAAe,CAAC;CACtE;CAEA,MAAM,cAAc,OAAO,cAAc,CAAC,CAAC,UAAU,QAAQ;CAE7D,YAAY,QAAQ;CAEpB,qBAAqB;EACnB,YAAY;CACd,CAAC;CAED,OAAO;AACT"}
1
+ {"version":3,"file":"useIsFetching.js","names":[],"sources":["../../src/useIsFetching.ts"],"sourcesContent":["import { getCurrentScope, onScopeDispose, ref, watchEffect } from 'vue-demi'\nimport { useQueryClient } from './useQueryClient'\nimport { cloneDeepUnref } from './utils'\nimport type { QueryFilters } from '@tanstack/query-core'\nimport type { Ref } from 'vue-demi'\nimport type { QueryClient } from './queryClient'\nimport type { MaybeRefDeep } from './types'\n\n/**\n * The filters accepted by `useIsFetching`: {@link QueryFilters} as a plain object, a `ref`, or a reactive\n * getter.\n */\nexport type UseIsFetchingFilters =\n | MaybeRefDeep<Omit<QueryFilters, 'fetchStatus'>>\n | (() => MaybeRefDeep<Omit<QueryFilters, 'fetchStatus'>>)\n\n/**\n * The `useIsFetching` composable returns a `ref` to the `number` of the queries that your application is\n * loading or fetching in the background (useful for app-wide loading indicators).\n *\n * `fetchingFilters` may be a plain object, `MaybeRefDeep`, or a reactive getter (`() => ({ ... })`) — pass a\n * getter if the filters themselves depend on other reactive state.\n * @param fetchingFilters - The {@link QueryFilters} to narrow down the matched queries.\n * @param queryClient - Use this to use a custom `QueryClient`. Otherwise, the one provided by `VueQueryPlugin`\n * will be used.\n * @returns A `ref` to the `number` of the queries that your application is currently loading or fetching in\n * the background.\n * @example\n * ```vue\n * <script setup lang=\"ts\">\n * import { useIsFetching } from '@tanstack/vue-query'\n *\n * // How many queries matching the posts prefix are fetching?\n * const isFetchingPosts = useIsFetching({ queryKey: ['posts'] })\n * </script>\n *\n * <template>\n * <span v-if=\"isFetchingPosts\">Refreshing posts...</span>\n * </template>\n * ```\n * @example\n * A global loading indicator for any query fetching in the background, not just the ones on screen:\n * ```vue\n * <script setup lang=\"ts\">\n * import { useIsFetching } from '@tanstack/vue-query'\n *\n * const isFetching = useIsFetching()\n * </script>\n *\n * <template>\n * <div v-if=\"isFetching\">Queries are fetching in the background...</div>\n * </template>\n * ```\n */\nexport function useIsFetching(\n fetchingFilters: UseIsFetchingFilters = {},\n queryClient?: QueryClient,\n): Ref<number> {\n if (process.env.NODE_ENV === 'development') {\n if (!getCurrentScope()) {\n console.warn(\n 'vue-query composable like \"useQuery()\" should only be used inside a \"setup()\" function or a running effect scope. They might otherwise lead to memory leaks.',\n )\n }\n }\n\n const client = queryClient || useQueryClient()\n\n const isFetching = ref()\n\n const listener = () => {\n const resolvedFilters =\n typeof fetchingFilters === 'function'\n ? fetchingFilters()\n : fetchingFilters\n isFetching.value = client.isFetching(cloneDeepUnref(resolvedFilters))\n }\n\n const unsubscribe = client.getQueryCache().subscribe(listener)\n\n watchEffect(listener)\n\n onScopeDispose(() => {\n unsubscribe()\n })\n\n return isFetching\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAsDA,SAAgB,cACd,kBAAwC,CAAC,GACzC,aACa;CACb,IAAI,QAAQ,IAAI,aAAa,eACvB;MAAA,CAAC,gBAAgB,GACnB,QAAQ,KACN,kKACF;CAAA;CAIJ,MAAM,SAAS,eAAe,eAAe;CAE7C,MAAM,aAAa,IAAI;CAEvB,MAAM,iBAAiB;EACrB,MAAM,kBACJ,OAAO,oBAAoB,aACvB,gBAAgB,IAChB;EACN,WAAW,QAAQ,OAAO,WAAW,eAAe,eAAe,CAAC;CACtE;CAEA,MAAM,cAAc,OAAO,cAAc,CAAC,CAAC,UAAU,QAAQ;CAE7D,YAAY,QAAQ;CAEpB,qBAAqB;EACnB,YAAY;CACd,CAAC;CAED,OAAO;AACT"}
@@ -1 +1 @@
1
- {"version":3,"file":"useMutation.cjs","names":["getCurrentScope","useQueryClient","computed","cloneDeepUnref","MutationObserver","shallowReactive","reactive","shallowReadonly","readonly","toRefs","shouldThrowError"],"sources":["../../src/useMutation.ts"],"sourcesContent":["import {\n computed,\n getCurrentScope,\n onScopeDispose,\n reactive,\n readonly,\n shallowReactive,\n shallowReadonly,\n toRefs,\n watch,\n} from 'vue-demi'\nimport { MutationObserver, shouldThrowError } from '@tanstack/query-core'\nimport { cloneDeepUnref, updateState } from './utils'\nimport { useQueryClient } from './useQueryClient'\nimport type { ToRefs } from 'vue-demi'\nimport type {\n DefaultError,\n DistributiveOmit,\n MutateFunction,\n MutationObserverResult,\n} from '@tanstack/query-core'\nimport type { MaybeRefDeep, MutationOptions } from './types'\nimport type { QueryClient } from './queryClient'\n\n/**\n * The {@link MutationObserverResult} properties without `mutate` and `reset`, which `useMutation` replaces with\n * its own versions.\n */\nexport type MutationResult<TData, TError, TVariables, TOnMutateResult> =\n DistributiveOmit<\n MutationObserverResult<TData, TError, TVariables, TOnMutateResult>,\n 'mutate' | 'reset'\n >\n\n/**\n * The options accepted by `useMutation`: {@link MutationOptions} as a plain object, a `ref`, or a reactive\n * getter.\n */\nexport type UseMutationOptions<\n TData = unknown,\n TError = DefaultError,\n TVariables = void,\n TOnMutateResult = unknown,\n> =\n | MaybeRefDeep<MutationOptions<TData, TError, TVariables, TOnMutateResult>>\n | (() => MaybeRefDeep<\n MutationOptions<TData, TError, TVariables, TOnMutateResult>\n >)\n\ntype MutateSyncFunction<\n TData = unknown,\n TError = DefaultError,\n TVariables = void,\n TOnMutateResult = unknown,\n> = (\n ...options: Parameters<\n MutateFunction<TData, TError, TVariables, TOnMutateResult>\n >\n) => void\n\n/**\n * The result of `useMutation`: the {@link MutationObserverResult} properties wrapped in `Ref`s, plus the\n * fire-and-forget `mutate`, the awaitable `mutateAsync`, and `reset`.\n */\nexport type UseMutationReturnType<\n TData,\n TError,\n TVariables,\n TOnMutateResult,\n TResult = MutationResult<TData, TError, TVariables, TOnMutateResult>,\n> = ToRefs<Readonly<TResult>> & {\n mutate: MutateSyncFunction<TData, TError, TVariables, TOnMutateResult>\n mutateAsync: MutateFunction<TData, TError, TVariables, TOnMutateResult>\n reset: MutationObserverResult<\n TData,\n TError,\n TVariables,\n TOnMutateResult\n >['reset']\n}\n\n/**\n * Unlike queries, mutations are typically used to create/update/delete data or perform server side-effects.\n * `useMutation` is the composable for that.\n *\n * `options` may be a plain object, a `ref`, or a reactive getter (`() => ({ ... })`) — pass a getter\n * if the options themselves depend on other reactive state.\n * @param options - The {@link UseMutationOptions} to use — everything you can pass to `useMutation`.\n * @param queryClient - Use this to use a custom `QueryClient`. Otherwise, the one provided by `VueQueryPlugin`\n * will be used.\n * @returns `mutate`/`mutateAsync` also accept per-call `onSuccess`/`onError`/`onSettled` callbacks as a second\n * argument, useful for triggering call-site side effects (e.g. navigation) without coupling them to the shared\n * mutation definition. Hook-level callbacks (passed to `options`) fire for every mutation; per-call\n * callbacks fire only for the latest call you've made.\n * @see {@link mutationOptions} to share these options across multiple `useMutation` call sites, or to look\n * the mutation up elsewhere via its `mutationKey` (e.g. with `useMutationState`).\n * @example\n * ```vue\n * <script setup lang=\"ts\">\n * import { useMutation, useQueryClient } from '@tanstack/vue-query'\n *\n * const queryClient = useQueryClient()\n *\n * const addMutation = useMutation({\n * mutationFn: addTodo,\n * onSuccess: () => queryClient.invalidateQueries({ queryKey: ['todos'] }),\n * })\n *\n * function onAdd() {\n * addMutation.mutate('Item', {\n * onError: (error) => console.error('Failed to add item:', error),\n * })\n * }\n * </script>\n *\n * <template>\n * <button @click=\"onAdd\">Add</button>\n * </template>\n * ```\n * @example\n * Rendering the mutation's own state, rather than just firing it off:\n * ```vue\n * <script setup lang=\"ts\">\n * import { useMutation, useQueryClient } from '@tanstack/vue-query'\n *\n * const queryClient = useQueryClient()\n *\n * const addMutation = useMutation({\n * mutationFn: addTodo,\n * onSuccess: () => queryClient.invalidateQueries({ queryKey: ['todos'] }),\n * })\n * </script>\n *\n * <template>\n * <div v-if=\"addMutation.isPending.value\">Adding todo...</div>\n * <div v-else>\n * <div v-if=\"addMutation.isError.value\">An error occurred: {{ addMutation.error.value.message }}</div>\n * <button @click=\"addMutation.mutate('Item')\">Add</button>\n * </div>\n * </template>\n * ```\n * @example\n * Optimistic update via `onMutate`, rolling back on `onError`:\n * ```vue\n * <script setup lang=\"ts\">\n * import { useMutation, useQueryClient } from '@tanstack/vue-query'\n *\n * const queryClient = useQueryClient()\n *\n * const addMutation = useMutation({\n * mutationFn: addTodo,\n * onMutate: async (newTodo: string) => {\n * await queryClient.cancelQueries({ queryKey: ['todos'] })\n * const previousTodos = queryClient.getQueryData<Array<string>>(['todos'])\n *\n * queryClient.setQueryData<Array<string>>(['todos'], (old) => [\n * ...(old ?? []),\n * newTodo,\n * ])\n *\n * // Passed to `onError` as `onMutateResult` if the mutation fails.\n * return { previousTodos }\n * },\n * onError: (_err, _newTodo, onMutateResult) => {\n * queryClient.setQueryData(['todos'], onMutateResult?.previousTodos)\n * },\n * onSettled: () => {\n * queryClient.invalidateQueries({ queryKey: ['todos'] })\n * },\n * })\n * </script>\n *\n * <template>\n * <button @click=\"addMutation.mutate('Item')\">Add</button>\n * </template>\n * ```\n * @example\n * Callbacks passed per call to `mutate` only fire for the last call — `mutateAsync` gives you a\n * promise per call instead, so you can wait for all of them when they succeed:\n * ```vue\n * <script setup lang=\"ts\">\n * import { useMutation, useQueryClient } from '@tanstack/vue-query'\n *\n * const queryClient = useQueryClient()\n *\n * const addMutation = useMutation({\n * mutationFn: addTodo,\n * onSuccess: () => queryClient.invalidateQueries({ queryKey: ['todos'] }),\n * })\n *\n * async function handleAddAll(todos: Array<string>) {\n * try {\n * await Promise.all(todos.map((todo) => addMutation.mutateAsync(todo)))\n * } catch (error) {\n * console.error('Failed to add todos:', error)\n * }\n * }\n * </script>\n *\n * <template>\n * <button @click=\"handleAddAll(['Todo 1', 'Todo 2', 'Todo 3'])\">Add all</button>\n * </template>\n * ```\n * @example\n * If some of the mutations above can fail independently of the others, and you want to know which ones\n * did — rather than losing that information the moment the first one rejects — swap `Promise.all` for\n * `Promise.allSettled`:\n * ```vue\n * <script setup lang=\"ts\">\n * import { useMutation, useQueryClient } from '@tanstack/vue-query'\n *\n * const queryClient = useQueryClient()\n *\n * const addMutation = useMutation({\n * mutationFn: addTodo,\n * onSuccess: () => queryClient.invalidateQueries({ queryKey: ['todos'] }),\n * })\n *\n * async function handleAddAll(todos: Array<string>) {\n * const addResults = await Promise.allSettled(\n * todos.map((todo) => addMutation.mutateAsync(todo)),\n * )\n *\n * addResults.forEach((addResult, index) => {\n * if (addResult.status === 'rejected') {\n * console.error(`Failed to add \"${todos[index]}\":`, addResult.reason)\n * }\n * })\n * }\n * </script>\n *\n * <template>\n * <button @click=\"handleAddAll(['Todo 1', 'Todo 2', 'Todo 3'])\">Add all</button>\n * </template>\n * ```\n */\nexport function useMutation<\n TData = unknown,\n TError = DefaultError,\n TVariables = void,\n TOnMutateResult = unknown,\n>(\n options: UseMutationOptions<TData, TError, TVariables, TOnMutateResult>,\n queryClient?: QueryClient,\n): UseMutationReturnType<TData, TError, TVariables, TOnMutateResult> {\n if (process.env.NODE_ENV === 'development') {\n if (!getCurrentScope()) {\n console.warn(\n 'vue-query composable like \"useQuery()\" should only be used inside a \"setup()\" function or a running effect scope. They might otherwise lead to memory leaks.',\n )\n }\n }\n\n const client = queryClient || useQueryClient()\n const defaultedOptions = computed(() => {\n const resolvedOptions = typeof options === 'function' ? options() : options\n return client.defaultMutationOptions(cloneDeepUnref(resolvedOptions))\n })\n const observer = new MutationObserver(client, defaultedOptions.value)\n const state = defaultedOptions.value.shallow\n ? shallowReactive(observer.getCurrentResult())\n : reactive(observer.getCurrentResult())\n\n const unsubscribe = observer.subscribe((result) => {\n updateState(state, result)\n })\n\n const mutate = (\n ...args: Parameters<\n MutateFunction<TData, TError, TVariables, TOnMutateResult>\n >\n ) => {\n observer.mutate(args[0] as TVariables, args[1]).catch(() => {\n // This is intentional\n })\n }\n\n watch(defaultedOptions, () => {\n observer.setOptions(defaultedOptions.value)\n })\n\n onScopeDispose(() => {\n unsubscribe()\n })\n\n const readonlyState = defaultedOptions.value.shallow\n ? shallowReadonly(state)\n : readonly(state)\n\n const resultRefs = toRefs(readonlyState) as ToRefs<\n Readonly<MutationResult<TData, TError, TVariables, TOnMutateResult>>\n >\n\n watch(\n () => state.error,\n (error) => {\n if (\n error &&\n shouldThrowError(defaultedOptions.value.throwOnError, [error as TError])\n ) {\n throw error\n }\n },\n )\n\n return {\n ...resultRefs,\n mutate,\n mutateAsync: state.mutate,\n reset: state.reset,\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA4OA,SAAgB,YAMd,SACA,aACmE;CACnE,IAAI,QAAQ,IAAI,aAAa,eACvB;MAAA,EAAA,GAACA,SAAAA,gBAAAA,CAAgB,GACnB,QAAQ,KACN,kKACF;CAAA;CAIJ,MAAM,SAAS,eAAeC,uBAAAA,eAAe;CAC7C,MAAM,oBAAA,GAAmBC,SAAAA,SAAAA,OAAe;EACtC,MAAM,kBAAkB,OAAO,YAAY,aAAa,QAAQ,IAAI;EACpE,OAAO,OAAO,uBAAuBC,cAAAA,eAAe,eAAe,CAAC;CACtE,CAAC;CACD,MAAM,WAAW,IAAIC,qBAAAA,iBAAiB,QAAQ,iBAAiB,KAAK;CACpE,MAAM,QAAQ,iBAAiB,MAAM,WAAA,GACjCC,SAAAA,gBAAAA,CAAgB,SAAS,iBAAiB,CAAC,KAAA,GAC3CC,SAAAA,SAAAA,CAAS,SAAS,iBAAiB,CAAC;CAExC,MAAM,cAAc,SAAS,WAAW,WAAW;EACjD,cAAA,YAAY,OAAO,MAAM;CAC3B,CAAC;CAED,MAAM,UACJ,GAAG,SAGA;EACH,SAAS,OAAO,KAAK,IAAkB,KAAK,EAAE,CAAC,CAAC,YAAY,CAE5D,CAAC;CACH;CAEA,CAAA,GAAA,SAAA,MAAA,CAAM,wBAAwB;EAC5B,SAAS,WAAW,iBAAiB,KAAK;CAC5C,CAAC;CAED,CAAA,GAAA,SAAA,eAAA,OAAqB;EACnB,YAAY;CACd,CAAC;CAED,MAAM,gBAAgB,iBAAiB,MAAM,WAAA,GACzCC,SAAAA,gBAAAA,CAAgB,KAAK,KAAA,GACrBC,SAAAA,SAAAA,CAAS,KAAK;CAElB,MAAM,cAAA,GAAaC,SAAAA,OAAAA,CAAO,aAAa;CAIvC,CAAA,GAAA,SAAA,MAAA,OACQ,MAAM,QACX,UAAU;EACT,IACE,UAAA,GACAC,qBAAAA,iBAAAA,CAAiB,iBAAiB,MAAM,cAAc,CAAC,KAAe,CAAC,GAEvE,MAAM;CAEV,CACF;CAEA,OAAO;EACL,GAAG;EACH;EACA,aAAa,MAAM;EACnB,OAAO,MAAM;CACf;AACF"}
1
+ {"version":3,"file":"useMutation.cjs","names":["getCurrentScope","useQueryClient","computed","cloneDeepUnref","MutationObserver","shallowReactive","reactive","shallowReadonly","readonly","toRefs","shouldThrowError"],"sources":["../../src/useMutation.ts"],"sourcesContent":["import { MutationObserver, shouldThrowError } from '@tanstack/query-core'\nimport {\n computed,\n getCurrentScope,\n onScopeDispose,\n reactive,\n readonly,\n shallowReactive,\n shallowReadonly,\n toRefs,\n watch,\n} from 'vue-demi'\nimport { useQueryClient } from './useQueryClient'\nimport { cloneDeepUnref, updateState } from './utils'\nimport type {\n DefaultError,\n DistributiveOmit,\n MutateFunction,\n MutationObserverResult,\n} from '@tanstack/query-core'\nimport type { ToRefs } from 'vue-demi'\nimport type { QueryClient } from './queryClient'\nimport type { MaybeRefDeep, MutationOptions } from './types'\n\n/**\n * The {@link MutationObserverResult} properties without `mutate` and `reset`, which `useMutation` replaces with\n * its own versions.\n */\nexport type MutationResult<TData, TError, TVariables, TOnMutateResult> =\n DistributiveOmit<\n MutationObserverResult<TData, TError, TVariables, TOnMutateResult>,\n 'mutate' | 'reset'\n >\n\n/**\n * The options accepted by `useMutation`: {@link MutationOptions} as a plain object, a `ref`, or a reactive\n * getter.\n */\nexport type UseMutationOptions<\n TData = unknown,\n TError = DefaultError,\n TVariables = void,\n TOnMutateResult = unknown,\n> =\n | MaybeRefDeep<MutationOptions<TData, TError, TVariables, TOnMutateResult>>\n | (() => MaybeRefDeep<\n MutationOptions<TData, TError, TVariables, TOnMutateResult>\n >)\n\ntype MutateSyncFunction<\n TData = unknown,\n TError = DefaultError,\n TVariables = void,\n TOnMutateResult = unknown,\n> = (\n ...options: Parameters<\n MutateFunction<TData, TError, TVariables, TOnMutateResult>\n >\n) => void\n\n/**\n * The result of `useMutation`: the {@link MutationObserverResult} properties wrapped in `Ref`s, plus the\n * fire-and-forget `mutate`, the awaitable `mutateAsync`, and `reset`.\n */\nexport type UseMutationReturnType<\n TData,\n TError,\n TVariables,\n TOnMutateResult,\n TResult = MutationResult<TData, TError, TVariables, TOnMutateResult>,\n> = ToRefs<Readonly<TResult>> & {\n mutate: MutateSyncFunction<TData, TError, TVariables, TOnMutateResult>\n mutateAsync: MutateFunction<TData, TError, TVariables, TOnMutateResult>\n reset: MutationObserverResult<\n TData,\n TError,\n TVariables,\n TOnMutateResult\n >['reset']\n}\n\n/**\n * Unlike queries, mutations are typically used to create/update/delete data or perform server side-effects.\n * `useMutation` is the composable for that.\n *\n * `options` may be a plain object, a `ref`, or a reactive getter (`() => ({ ... })`) — pass a getter\n * if the options themselves depend on other reactive state.\n * @param options - The {@link UseMutationOptions} to use — everything you can pass to `useMutation`.\n * @param queryClient - Use this to use a custom `QueryClient`. Otherwise, the one provided by `VueQueryPlugin`\n * will be used.\n * @returns `mutate`/`mutateAsync` also accept per-call `onSuccess`/`onError`/`onSettled` callbacks as a second\n * argument, useful for triggering call-site side effects (e.g. navigation) without coupling them to the shared\n * mutation definition. Hook-level callbacks (passed to `options`) fire for every mutation; per-call\n * callbacks fire only for the latest call you've made.\n * @see {@link mutationOptions} to share these options across multiple `useMutation` call sites, or to look\n * the mutation up elsewhere via its `mutationKey` (e.g. with `useMutationState`).\n * @example\n * ```vue\n * <script setup lang=\"ts\">\n * import { useMutation, useQueryClient } from '@tanstack/vue-query'\n *\n * const queryClient = useQueryClient()\n *\n * const addMutation = useMutation({\n * mutationFn: addTodo,\n * onSuccess: () => queryClient.invalidateQueries({ queryKey: ['todos'] }),\n * })\n *\n * function onAdd() {\n * addMutation.mutate('Item', {\n * onError: (error) => console.error('Failed to add item:', error),\n * })\n * }\n * </script>\n *\n * <template>\n * <button @click=\"onAdd\">Add</button>\n * </template>\n * ```\n * @example\n * Rendering the mutation's own state, rather than just firing it off:\n * ```vue\n * <script setup lang=\"ts\">\n * import { useMutation, useQueryClient } from '@tanstack/vue-query'\n *\n * const queryClient = useQueryClient()\n *\n * const addMutation = useMutation({\n * mutationFn: addTodo,\n * onSuccess: () => queryClient.invalidateQueries({ queryKey: ['todos'] }),\n * })\n * </script>\n *\n * <template>\n * <div v-if=\"addMutation.isPending.value\">Adding todo...</div>\n * <div v-else>\n * <div v-if=\"addMutation.isError.value\">An error occurred: {{ addMutation.error.value.message }}</div>\n * <button @click=\"addMutation.mutate('Item')\">Add</button>\n * </div>\n * </template>\n * ```\n * @example\n * Optimistic update via `onMutate`, rolling back on `onError`:\n * ```vue\n * <script setup lang=\"ts\">\n * import { useMutation, useQueryClient } from '@tanstack/vue-query'\n *\n * const queryClient = useQueryClient()\n *\n * const addMutation = useMutation({\n * mutationFn: addTodo,\n * onMutate: async (newTodo: string) => {\n * await queryClient.cancelQueries({ queryKey: ['todos'] })\n * const previousTodos = queryClient.getQueryData<Array<string>>(['todos'])\n *\n * queryClient.setQueryData<Array<string>>(['todos'], (old) => [\n * ...(old ?? []),\n * newTodo,\n * ])\n *\n * // Passed to `onError` as `onMutateResult` if the mutation fails.\n * return { previousTodos }\n * },\n * onError: (_err, _newTodo, onMutateResult) => {\n * queryClient.setQueryData(['todos'], onMutateResult?.previousTodos)\n * },\n * onSettled: () => {\n * queryClient.invalidateQueries({ queryKey: ['todos'] })\n * },\n * })\n * </script>\n *\n * <template>\n * <button @click=\"addMutation.mutate('Item')\">Add</button>\n * </template>\n * ```\n * @example\n * Callbacks passed per call to `mutate` only fire for the last call — `mutateAsync` gives you a\n * promise per call instead, so you can wait for all of them when they succeed:\n * ```vue\n * <script setup lang=\"ts\">\n * import { useMutation, useQueryClient } from '@tanstack/vue-query'\n *\n * const queryClient = useQueryClient()\n *\n * const addMutation = useMutation({\n * mutationFn: addTodo,\n * onSuccess: () => queryClient.invalidateQueries({ queryKey: ['todos'] }),\n * })\n *\n * async function handleAddAll(todos: Array<string>) {\n * try {\n * await Promise.all(todos.map((todo) => addMutation.mutateAsync(todo)))\n * } catch (error) {\n * console.error('Failed to add todos:', error)\n * }\n * }\n * </script>\n *\n * <template>\n * <button @click=\"handleAddAll(['Todo 1', 'Todo 2', 'Todo 3'])\">Add all</button>\n * </template>\n * ```\n * @example\n * If some of the mutations above can fail independently of the others, and you want to know which ones\n * did — rather than losing that information the moment the first one rejects — swap `Promise.all` for\n * `Promise.allSettled`:\n * ```vue\n * <script setup lang=\"ts\">\n * import { useMutation, useQueryClient } from '@tanstack/vue-query'\n *\n * const queryClient = useQueryClient()\n *\n * const addMutation = useMutation({\n * mutationFn: addTodo,\n * onSuccess: () => queryClient.invalidateQueries({ queryKey: ['todos'] }),\n * })\n *\n * async function handleAddAll(todos: Array<string>) {\n * const addResults = await Promise.allSettled(\n * todos.map((todo) => addMutation.mutateAsync(todo)),\n * )\n *\n * addResults.forEach((addResult, index) => {\n * if (addResult.status === 'rejected') {\n * console.error(`Failed to add \"${todos[index]}\":`, addResult.reason)\n * }\n * })\n * }\n * </script>\n *\n * <template>\n * <button @click=\"handleAddAll(['Todo 1', 'Todo 2', 'Todo 3'])\">Add all</button>\n * </template>\n * ```\n */\nexport function useMutation<\n TData = unknown,\n TError = DefaultError,\n TVariables = void,\n TOnMutateResult = unknown,\n>(\n options: UseMutationOptions<TData, TError, TVariables, TOnMutateResult>,\n queryClient?: QueryClient,\n): UseMutationReturnType<TData, TError, TVariables, TOnMutateResult> {\n if (process.env.NODE_ENV === 'development') {\n if (!getCurrentScope()) {\n console.warn(\n 'vue-query composable like \"useQuery()\" should only be used inside a \"setup()\" function or a running effect scope. They might otherwise lead to memory leaks.',\n )\n }\n }\n\n const client = queryClient || useQueryClient()\n const defaultedOptions = computed(() => {\n const resolvedOptions = typeof options === 'function' ? options() : options\n return client.defaultMutationOptions(cloneDeepUnref(resolvedOptions))\n })\n const observer = new MutationObserver(client, defaultedOptions.value)\n const state = defaultedOptions.value.shallow\n ? shallowReactive(observer.getCurrentResult())\n : reactive(observer.getCurrentResult())\n\n const unsubscribe = observer.subscribe((result) => {\n updateState(state, result)\n })\n\n const mutate = (\n ...args: Parameters<\n MutateFunction<TData, TError, TVariables, TOnMutateResult>\n >\n ) => {\n observer.mutate(args[0] as TVariables, args[1]).catch(() => {\n // This is intentional\n })\n }\n\n watch(defaultedOptions, () => {\n observer.setOptions(defaultedOptions.value)\n })\n\n onScopeDispose(() => {\n unsubscribe()\n })\n\n const readonlyState = defaultedOptions.value.shallow\n ? shallowReadonly(state)\n : readonly(state)\n\n const resultRefs = toRefs(readonlyState) as ToRefs<\n Readonly<MutationResult<TData, TError, TVariables, TOnMutateResult>>\n >\n\n watch(\n () => state.error,\n (error) => {\n if (\n error &&\n shouldThrowError(defaultedOptions.value.throwOnError, [error as TError])\n ) {\n throw error\n }\n },\n )\n\n return {\n ...resultRefs,\n mutate,\n mutateAsync: state.mutate,\n reset: state.reset,\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA4OA,SAAgB,YAMd,SACA,aACmE;CACnE,IAAI,QAAQ,IAAI,aAAa,eACvB;MAAA,EAAA,GAACA,SAAAA,gBAAAA,CAAgB,GACnB,QAAQ,KACN,kKACF;CAAA;CAIJ,MAAM,SAAS,eAAeC,uBAAAA,eAAe;CAC7C,MAAM,oBAAA,GAAmBC,SAAAA,SAAAA,OAAe;EACtC,MAAM,kBAAkB,OAAO,YAAY,aAAa,QAAQ,IAAI;EACpE,OAAO,OAAO,uBAAuBC,cAAAA,eAAe,eAAe,CAAC;CACtE,CAAC;CACD,MAAM,WAAW,IAAIC,qBAAAA,iBAAiB,QAAQ,iBAAiB,KAAK;CACpE,MAAM,QAAQ,iBAAiB,MAAM,WAAA,GACjCC,SAAAA,gBAAAA,CAAgB,SAAS,iBAAiB,CAAC,KAAA,GAC3CC,SAAAA,SAAAA,CAAS,SAAS,iBAAiB,CAAC;CAExC,MAAM,cAAc,SAAS,WAAW,WAAW;EACjD,cAAA,YAAY,OAAO,MAAM;CAC3B,CAAC;CAED,MAAM,UACJ,GAAG,SAGA;EACH,SAAS,OAAO,KAAK,IAAkB,KAAK,EAAE,CAAC,CAAC,YAAY,CAE5D,CAAC;CACH;CAEA,CAAA,GAAA,SAAA,MAAA,CAAM,wBAAwB;EAC5B,SAAS,WAAW,iBAAiB,KAAK;CAC5C,CAAC;CAED,CAAA,GAAA,SAAA,eAAA,OAAqB;EACnB,YAAY;CACd,CAAC;CAED,MAAM,gBAAgB,iBAAiB,MAAM,WAAA,GACzCC,SAAAA,gBAAAA,CAAgB,KAAK,KAAA,GACrBC,SAAAA,SAAAA,CAAS,KAAK;CAElB,MAAM,cAAA,GAAaC,SAAAA,OAAAA,CAAO,aAAa;CAIvC,CAAA,GAAA,SAAA,MAAA,OACQ,MAAM,QACX,UAAU;EACT,IACE,UAAA,GACAC,qBAAAA,iBAAAA,CAAiB,iBAAiB,MAAM,cAAc,CAAC,KAAe,CAAC,GAEvE,MAAM;CAEV,CACF;CAEA,OAAO;EACL,GAAG;EACH;EACA,aAAa,MAAM;EACnB,OAAO,MAAM;CACf;AACF"}
@@ -1,5 +1,5 @@
1
1
  import { c as MutationOptions, o as MaybeRefDeep } from "./types-u_Tu5Ybs.cjs";
2
- import { t as QueryClient$1 } from "./queryClient-BGn8uIej.cjs";
2
+ import { t as QueryClient$1 } from "./queryClient-yJW8K_VP.cjs";
3
3
  import { DefaultError, DistributiveOmit, MutateFunction, MutationObserverResult } from "@tanstack/query-core";
4
4
  import { ToRefs } from "vue-demi";
5
5
  /**
@@ -1,5 +1,5 @@
1
1
  import { c as MutationOptions, o as MaybeRefDeep } from "./types-u_Tu5Ybs.js";
2
- import { t as QueryClient$1 } from "./queryClient-Ba4HSFnn.js";
2
+ import { t as QueryClient$1 } from "./queryClient-6AWIHAhP.js";
3
3
  import { DefaultError, DistributiveOmit, MutateFunction, MutationObserverResult } from "@tanstack/query-core";
4
4
  import { ToRefs } from "vue-demi";
5
5
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"useMutation.js","names":[],"sources":["../../src/useMutation.ts"],"sourcesContent":["import {\n computed,\n getCurrentScope,\n onScopeDispose,\n reactive,\n readonly,\n shallowReactive,\n shallowReadonly,\n toRefs,\n watch,\n} from 'vue-demi'\nimport { MutationObserver, shouldThrowError } from '@tanstack/query-core'\nimport { cloneDeepUnref, updateState } from './utils'\nimport { useQueryClient } from './useQueryClient'\nimport type { ToRefs } from 'vue-demi'\nimport type {\n DefaultError,\n DistributiveOmit,\n MutateFunction,\n MutationObserverResult,\n} from '@tanstack/query-core'\nimport type { MaybeRefDeep, MutationOptions } from './types'\nimport type { QueryClient } from './queryClient'\n\n/**\n * The {@link MutationObserverResult} properties without `mutate` and `reset`, which `useMutation` replaces with\n * its own versions.\n */\nexport type MutationResult<TData, TError, TVariables, TOnMutateResult> =\n DistributiveOmit<\n MutationObserverResult<TData, TError, TVariables, TOnMutateResult>,\n 'mutate' | 'reset'\n >\n\n/**\n * The options accepted by `useMutation`: {@link MutationOptions} as a plain object, a `ref`, or a reactive\n * getter.\n */\nexport type UseMutationOptions<\n TData = unknown,\n TError = DefaultError,\n TVariables = void,\n TOnMutateResult = unknown,\n> =\n | MaybeRefDeep<MutationOptions<TData, TError, TVariables, TOnMutateResult>>\n | (() => MaybeRefDeep<\n MutationOptions<TData, TError, TVariables, TOnMutateResult>\n >)\n\ntype MutateSyncFunction<\n TData = unknown,\n TError = DefaultError,\n TVariables = void,\n TOnMutateResult = unknown,\n> = (\n ...options: Parameters<\n MutateFunction<TData, TError, TVariables, TOnMutateResult>\n >\n) => void\n\n/**\n * The result of `useMutation`: the {@link MutationObserverResult} properties wrapped in `Ref`s, plus the\n * fire-and-forget `mutate`, the awaitable `mutateAsync`, and `reset`.\n */\nexport type UseMutationReturnType<\n TData,\n TError,\n TVariables,\n TOnMutateResult,\n TResult = MutationResult<TData, TError, TVariables, TOnMutateResult>,\n> = ToRefs<Readonly<TResult>> & {\n mutate: MutateSyncFunction<TData, TError, TVariables, TOnMutateResult>\n mutateAsync: MutateFunction<TData, TError, TVariables, TOnMutateResult>\n reset: MutationObserverResult<\n TData,\n TError,\n TVariables,\n TOnMutateResult\n >['reset']\n}\n\n/**\n * Unlike queries, mutations are typically used to create/update/delete data or perform server side-effects.\n * `useMutation` is the composable for that.\n *\n * `options` may be a plain object, a `ref`, or a reactive getter (`() => ({ ... })`) — pass a getter\n * if the options themselves depend on other reactive state.\n * @param options - The {@link UseMutationOptions} to use — everything you can pass to `useMutation`.\n * @param queryClient - Use this to use a custom `QueryClient`. Otherwise, the one provided by `VueQueryPlugin`\n * will be used.\n * @returns `mutate`/`mutateAsync` also accept per-call `onSuccess`/`onError`/`onSettled` callbacks as a second\n * argument, useful for triggering call-site side effects (e.g. navigation) without coupling them to the shared\n * mutation definition. Hook-level callbacks (passed to `options`) fire for every mutation; per-call\n * callbacks fire only for the latest call you've made.\n * @see {@link mutationOptions} to share these options across multiple `useMutation` call sites, or to look\n * the mutation up elsewhere via its `mutationKey` (e.g. with `useMutationState`).\n * @example\n * ```vue\n * <script setup lang=\"ts\">\n * import { useMutation, useQueryClient } from '@tanstack/vue-query'\n *\n * const queryClient = useQueryClient()\n *\n * const addMutation = useMutation({\n * mutationFn: addTodo,\n * onSuccess: () => queryClient.invalidateQueries({ queryKey: ['todos'] }),\n * })\n *\n * function onAdd() {\n * addMutation.mutate('Item', {\n * onError: (error) => console.error('Failed to add item:', error),\n * })\n * }\n * </script>\n *\n * <template>\n * <button @click=\"onAdd\">Add</button>\n * </template>\n * ```\n * @example\n * Rendering the mutation's own state, rather than just firing it off:\n * ```vue\n * <script setup lang=\"ts\">\n * import { useMutation, useQueryClient } from '@tanstack/vue-query'\n *\n * const queryClient = useQueryClient()\n *\n * const addMutation = useMutation({\n * mutationFn: addTodo,\n * onSuccess: () => queryClient.invalidateQueries({ queryKey: ['todos'] }),\n * })\n * </script>\n *\n * <template>\n * <div v-if=\"addMutation.isPending.value\">Adding todo...</div>\n * <div v-else>\n * <div v-if=\"addMutation.isError.value\">An error occurred: {{ addMutation.error.value.message }}</div>\n * <button @click=\"addMutation.mutate('Item')\">Add</button>\n * </div>\n * </template>\n * ```\n * @example\n * Optimistic update via `onMutate`, rolling back on `onError`:\n * ```vue\n * <script setup lang=\"ts\">\n * import { useMutation, useQueryClient } from '@tanstack/vue-query'\n *\n * const queryClient = useQueryClient()\n *\n * const addMutation = useMutation({\n * mutationFn: addTodo,\n * onMutate: async (newTodo: string) => {\n * await queryClient.cancelQueries({ queryKey: ['todos'] })\n * const previousTodos = queryClient.getQueryData<Array<string>>(['todos'])\n *\n * queryClient.setQueryData<Array<string>>(['todos'], (old) => [\n * ...(old ?? []),\n * newTodo,\n * ])\n *\n * // Passed to `onError` as `onMutateResult` if the mutation fails.\n * return { previousTodos }\n * },\n * onError: (_err, _newTodo, onMutateResult) => {\n * queryClient.setQueryData(['todos'], onMutateResult?.previousTodos)\n * },\n * onSettled: () => {\n * queryClient.invalidateQueries({ queryKey: ['todos'] })\n * },\n * })\n * </script>\n *\n * <template>\n * <button @click=\"addMutation.mutate('Item')\">Add</button>\n * </template>\n * ```\n * @example\n * Callbacks passed per call to `mutate` only fire for the last call — `mutateAsync` gives you a\n * promise per call instead, so you can wait for all of them when they succeed:\n * ```vue\n * <script setup lang=\"ts\">\n * import { useMutation, useQueryClient } from '@tanstack/vue-query'\n *\n * const queryClient = useQueryClient()\n *\n * const addMutation = useMutation({\n * mutationFn: addTodo,\n * onSuccess: () => queryClient.invalidateQueries({ queryKey: ['todos'] }),\n * })\n *\n * async function handleAddAll(todos: Array<string>) {\n * try {\n * await Promise.all(todos.map((todo) => addMutation.mutateAsync(todo)))\n * } catch (error) {\n * console.error('Failed to add todos:', error)\n * }\n * }\n * </script>\n *\n * <template>\n * <button @click=\"handleAddAll(['Todo 1', 'Todo 2', 'Todo 3'])\">Add all</button>\n * </template>\n * ```\n * @example\n * If some of the mutations above can fail independently of the others, and you want to know which ones\n * did — rather than losing that information the moment the first one rejects — swap `Promise.all` for\n * `Promise.allSettled`:\n * ```vue\n * <script setup lang=\"ts\">\n * import { useMutation, useQueryClient } from '@tanstack/vue-query'\n *\n * const queryClient = useQueryClient()\n *\n * const addMutation = useMutation({\n * mutationFn: addTodo,\n * onSuccess: () => queryClient.invalidateQueries({ queryKey: ['todos'] }),\n * })\n *\n * async function handleAddAll(todos: Array<string>) {\n * const addResults = await Promise.allSettled(\n * todos.map((todo) => addMutation.mutateAsync(todo)),\n * )\n *\n * addResults.forEach((addResult, index) => {\n * if (addResult.status === 'rejected') {\n * console.error(`Failed to add \"${todos[index]}\":`, addResult.reason)\n * }\n * })\n * }\n * </script>\n *\n * <template>\n * <button @click=\"handleAddAll(['Todo 1', 'Todo 2', 'Todo 3'])\">Add all</button>\n * </template>\n * ```\n */\nexport function useMutation<\n TData = unknown,\n TError = DefaultError,\n TVariables = void,\n TOnMutateResult = unknown,\n>(\n options: UseMutationOptions<TData, TError, TVariables, TOnMutateResult>,\n queryClient?: QueryClient,\n): UseMutationReturnType<TData, TError, TVariables, TOnMutateResult> {\n if (process.env.NODE_ENV === 'development') {\n if (!getCurrentScope()) {\n console.warn(\n 'vue-query composable like \"useQuery()\" should only be used inside a \"setup()\" function or a running effect scope. They might otherwise lead to memory leaks.',\n )\n }\n }\n\n const client = queryClient || useQueryClient()\n const defaultedOptions = computed(() => {\n const resolvedOptions = typeof options === 'function' ? options() : options\n return client.defaultMutationOptions(cloneDeepUnref(resolvedOptions))\n })\n const observer = new MutationObserver(client, defaultedOptions.value)\n const state = defaultedOptions.value.shallow\n ? shallowReactive(observer.getCurrentResult())\n : reactive(observer.getCurrentResult())\n\n const unsubscribe = observer.subscribe((result) => {\n updateState(state, result)\n })\n\n const mutate = (\n ...args: Parameters<\n MutateFunction<TData, TError, TVariables, TOnMutateResult>\n >\n ) => {\n observer.mutate(args[0] as TVariables, args[1]).catch(() => {\n // This is intentional\n })\n }\n\n watch(defaultedOptions, () => {\n observer.setOptions(defaultedOptions.value)\n })\n\n onScopeDispose(() => {\n unsubscribe()\n })\n\n const readonlyState = defaultedOptions.value.shallow\n ? shallowReadonly(state)\n : readonly(state)\n\n const resultRefs = toRefs(readonlyState) as ToRefs<\n Readonly<MutationResult<TData, TError, TVariables, TOnMutateResult>>\n >\n\n watch(\n () => state.error,\n (error) => {\n if (\n error &&\n shouldThrowError(defaultedOptions.value.throwOnError, [error as TError])\n ) {\n throw error\n }\n },\n )\n\n return {\n ...resultRefs,\n mutate,\n mutateAsync: state.mutate,\n reset: state.reset,\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA4OA,SAAgB,YAMd,SACA,aACmE;CACnE,IAAI,QAAQ,IAAI,aAAa,eACvB;MAAA,CAAC,gBAAgB,GACnB,QAAQ,KACN,kKACF;CAAA;CAIJ,MAAM,SAAS,eAAe,eAAe;CAC7C,MAAM,mBAAmB,eAAe;EACtC,MAAM,kBAAkB,OAAO,YAAY,aAAa,QAAQ,IAAI;EACpE,OAAO,OAAO,uBAAuB,eAAe,eAAe,CAAC;CACtE,CAAC;CACD,MAAM,WAAW,IAAI,iBAAiB,QAAQ,iBAAiB,KAAK;CACpE,MAAM,QAAQ,iBAAiB,MAAM,UACjC,gBAAgB,SAAS,iBAAiB,CAAC,IAC3C,SAAS,SAAS,iBAAiB,CAAC;CAExC,MAAM,cAAc,SAAS,WAAW,WAAW;EACjD,YAAY,OAAO,MAAM;CAC3B,CAAC;CAED,MAAM,UACJ,GAAG,SAGA;EACH,SAAS,OAAO,KAAK,IAAkB,KAAK,EAAE,CAAC,CAAC,YAAY,CAE5D,CAAC;CACH;CAEA,MAAM,wBAAwB;EAC5B,SAAS,WAAW,iBAAiB,KAAK;CAC5C,CAAC;CAED,qBAAqB;EACnB,YAAY;CACd,CAAC;CAED,MAAM,gBAAgB,iBAAiB,MAAM,UACzC,gBAAgB,KAAK,IACrB,SAAS,KAAK;CAElB,MAAM,aAAa,OAAO,aAAa;CAIvC,YACQ,MAAM,QACX,UAAU;EACT,IACE,SACA,iBAAiB,iBAAiB,MAAM,cAAc,CAAC,KAAe,CAAC,GAEvE,MAAM;CAEV,CACF;CAEA,OAAO;EACL,GAAG;EACH;EACA,aAAa,MAAM;EACnB,OAAO,MAAM;CACf;AACF"}
1
+ {"version":3,"file":"useMutation.js","names":[],"sources":["../../src/useMutation.ts"],"sourcesContent":["import { MutationObserver, shouldThrowError } from '@tanstack/query-core'\nimport {\n computed,\n getCurrentScope,\n onScopeDispose,\n reactive,\n readonly,\n shallowReactive,\n shallowReadonly,\n toRefs,\n watch,\n} from 'vue-demi'\nimport { useQueryClient } from './useQueryClient'\nimport { cloneDeepUnref, updateState } from './utils'\nimport type {\n DefaultError,\n DistributiveOmit,\n MutateFunction,\n MutationObserverResult,\n} from '@tanstack/query-core'\nimport type { ToRefs } from 'vue-demi'\nimport type { QueryClient } from './queryClient'\nimport type { MaybeRefDeep, MutationOptions } from './types'\n\n/**\n * The {@link MutationObserverResult} properties without `mutate` and `reset`, which `useMutation` replaces with\n * its own versions.\n */\nexport type MutationResult<TData, TError, TVariables, TOnMutateResult> =\n DistributiveOmit<\n MutationObserverResult<TData, TError, TVariables, TOnMutateResult>,\n 'mutate' | 'reset'\n >\n\n/**\n * The options accepted by `useMutation`: {@link MutationOptions} as a plain object, a `ref`, or a reactive\n * getter.\n */\nexport type UseMutationOptions<\n TData = unknown,\n TError = DefaultError,\n TVariables = void,\n TOnMutateResult = unknown,\n> =\n | MaybeRefDeep<MutationOptions<TData, TError, TVariables, TOnMutateResult>>\n | (() => MaybeRefDeep<\n MutationOptions<TData, TError, TVariables, TOnMutateResult>\n >)\n\ntype MutateSyncFunction<\n TData = unknown,\n TError = DefaultError,\n TVariables = void,\n TOnMutateResult = unknown,\n> = (\n ...options: Parameters<\n MutateFunction<TData, TError, TVariables, TOnMutateResult>\n >\n) => void\n\n/**\n * The result of `useMutation`: the {@link MutationObserverResult} properties wrapped in `Ref`s, plus the\n * fire-and-forget `mutate`, the awaitable `mutateAsync`, and `reset`.\n */\nexport type UseMutationReturnType<\n TData,\n TError,\n TVariables,\n TOnMutateResult,\n TResult = MutationResult<TData, TError, TVariables, TOnMutateResult>,\n> = ToRefs<Readonly<TResult>> & {\n mutate: MutateSyncFunction<TData, TError, TVariables, TOnMutateResult>\n mutateAsync: MutateFunction<TData, TError, TVariables, TOnMutateResult>\n reset: MutationObserverResult<\n TData,\n TError,\n TVariables,\n TOnMutateResult\n >['reset']\n}\n\n/**\n * Unlike queries, mutations are typically used to create/update/delete data or perform server side-effects.\n * `useMutation` is the composable for that.\n *\n * `options` may be a plain object, a `ref`, or a reactive getter (`() => ({ ... })`) — pass a getter\n * if the options themselves depend on other reactive state.\n * @param options - The {@link UseMutationOptions} to use — everything you can pass to `useMutation`.\n * @param queryClient - Use this to use a custom `QueryClient`. Otherwise, the one provided by `VueQueryPlugin`\n * will be used.\n * @returns `mutate`/`mutateAsync` also accept per-call `onSuccess`/`onError`/`onSettled` callbacks as a second\n * argument, useful for triggering call-site side effects (e.g. navigation) without coupling them to the shared\n * mutation definition. Hook-level callbacks (passed to `options`) fire for every mutation; per-call\n * callbacks fire only for the latest call you've made.\n * @see {@link mutationOptions} to share these options across multiple `useMutation` call sites, or to look\n * the mutation up elsewhere via its `mutationKey` (e.g. with `useMutationState`).\n * @example\n * ```vue\n * <script setup lang=\"ts\">\n * import { useMutation, useQueryClient } from '@tanstack/vue-query'\n *\n * const queryClient = useQueryClient()\n *\n * const addMutation = useMutation({\n * mutationFn: addTodo,\n * onSuccess: () => queryClient.invalidateQueries({ queryKey: ['todos'] }),\n * })\n *\n * function onAdd() {\n * addMutation.mutate('Item', {\n * onError: (error) => console.error('Failed to add item:', error),\n * })\n * }\n * </script>\n *\n * <template>\n * <button @click=\"onAdd\">Add</button>\n * </template>\n * ```\n * @example\n * Rendering the mutation's own state, rather than just firing it off:\n * ```vue\n * <script setup lang=\"ts\">\n * import { useMutation, useQueryClient } from '@tanstack/vue-query'\n *\n * const queryClient = useQueryClient()\n *\n * const addMutation = useMutation({\n * mutationFn: addTodo,\n * onSuccess: () => queryClient.invalidateQueries({ queryKey: ['todos'] }),\n * })\n * </script>\n *\n * <template>\n * <div v-if=\"addMutation.isPending.value\">Adding todo...</div>\n * <div v-else>\n * <div v-if=\"addMutation.isError.value\">An error occurred: {{ addMutation.error.value.message }}</div>\n * <button @click=\"addMutation.mutate('Item')\">Add</button>\n * </div>\n * </template>\n * ```\n * @example\n * Optimistic update via `onMutate`, rolling back on `onError`:\n * ```vue\n * <script setup lang=\"ts\">\n * import { useMutation, useQueryClient } from '@tanstack/vue-query'\n *\n * const queryClient = useQueryClient()\n *\n * const addMutation = useMutation({\n * mutationFn: addTodo,\n * onMutate: async (newTodo: string) => {\n * await queryClient.cancelQueries({ queryKey: ['todos'] })\n * const previousTodos = queryClient.getQueryData<Array<string>>(['todos'])\n *\n * queryClient.setQueryData<Array<string>>(['todos'], (old) => [\n * ...(old ?? []),\n * newTodo,\n * ])\n *\n * // Passed to `onError` as `onMutateResult` if the mutation fails.\n * return { previousTodos }\n * },\n * onError: (_err, _newTodo, onMutateResult) => {\n * queryClient.setQueryData(['todos'], onMutateResult?.previousTodos)\n * },\n * onSettled: () => {\n * queryClient.invalidateQueries({ queryKey: ['todos'] })\n * },\n * })\n * </script>\n *\n * <template>\n * <button @click=\"addMutation.mutate('Item')\">Add</button>\n * </template>\n * ```\n * @example\n * Callbacks passed per call to `mutate` only fire for the last call — `mutateAsync` gives you a\n * promise per call instead, so you can wait for all of them when they succeed:\n * ```vue\n * <script setup lang=\"ts\">\n * import { useMutation, useQueryClient } from '@tanstack/vue-query'\n *\n * const queryClient = useQueryClient()\n *\n * const addMutation = useMutation({\n * mutationFn: addTodo,\n * onSuccess: () => queryClient.invalidateQueries({ queryKey: ['todos'] }),\n * })\n *\n * async function handleAddAll(todos: Array<string>) {\n * try {\n * await Promise.all(todos.map((todo) => addMutation.mutateAsync(todo)))\n * } catch (error) {\n * console.error('Failed to add todos:', error)\n * }\n * }\n * </script>\n *\n * <template>\n * <button @click=\"handleAddAll(['Todo 1', 'Todo 2', 'Todo 3'])\">Add all</button>\n * </template>\n * ```\n * @example\n * If some of the mutations above can fail independently of the others, and you want to know which ones\n * did — rather than losing that information the moment the first one rejects — swap `Promise.all` for\n * `Promise.allSettled`:\n * ```vue\n * <script setup lang=\"ts\">\n * import { useMutation, useQueryClient } from '@tanstack/vue-query'\n *\n * const queryClient = useQueryClient()\n *\n * const addMutation = useMutation({\n * mutationFn: addTodo,\n * onSuccess: () => queryClient.invalidateQueries({ queryKey: ['todos'] }),\n * })\n *\n * async function handleAddAll(todos: Array<string>) {\n * const addResults = await Promise.allSettled(\n * todos.map((todo) => addMutation.mutateAsync(todo)),\n * )\n *\n * addResults.forEach((addResult, index) => {\n * if (addResult.status === 'rejected') {\n * console.error(`Failed to add \"${todos[index]}\":`, addResult.reason)\n * }\n * })\n * }\n * </script>\n *\n * <template>\n * <button @click=\"handleAddAll(['Todo 1', 'Todo 2', 'Todo 3'])\">Add all</button>\n * </template>\n * ```\n */\nexport function useMutation<\n TData = unknown,\n TError = DefaultError,\n TVariables = void,\n TOnMutateResult = unknown,\n>(\n options: UseMutationOptions<TData, TError, TVariables, TOnMutateResult>,\n queryClient?: QueryClient,\n): UseMutationReturnType<TData, TError, TVariables, TOnMutateResult> {\n if (process.env.NODE_ENV === 'development') {\n if (!getCurrentScope()) {\n console.warn(\n 'vue-query composable like \"useQuery()\" should only be used inside a \"setup()\" function or a running effect scope. They might otherwise lead to memory leaks.',\n )\n }\n }\n\n const client = queryClient || useQueryClient()\n const defaultedOptions = computed(() => {\n const resolvedOptions = typeof options === 'function' ? options() : options\n return client.defaultMutationOptions(cloneDeepUnref(resolvedOptions))\n })\n const observer = new MutationObserver(client, defaultedOptions.value)\n const state = defaultedOptions.value.shallow\n ? shallowReactive(observer.getCurrentResult())\n : reactive(observer.getCurrentResult())\n\n const unsubscribe = observer.subscribe((result) => {\n updateState(state, result)\n })\n\n const mutate = (\n ...args: Parameters<\n MutateFunction<TData, TError, TVariables, TOnMutateResult>\n >\n ) => {\n observer.mutate(args[0] as TVariables, args[1]).catch(() => {\n // This is intentional\n })\n }\n\n watch(defaultedOptions, () => {\n observer.setOptions(defaultedOptions.value)\n })\n\n onScopeDispose(() => {\n unsubscribe()\n })\n\n const readonlyState = defaultedOptions.value.shallow\n ? shallowReadonly(state)\n : readonly(state)\n\n const resultRefs = toRefs(readonlyState) as ToRefs<\n Readonly<MutationResult<TData, TError, TVariables, TOnMutateResult>>\n >\n\n watch(\n () => state.error,\n (error) => {\n if (\n error &&\n shouldThrowError(defaultedOptions.value.throwOnError, [error as TError])\n ) {\n throw error\n }\n },\n )\n\n return {\n ...resultRefs,\n mutate,\n mutateAsync: state.mutate,\n reset: state.reset,\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA4OA,SAAgB,YAMd,SACA,aACmE;CACnE,IAAI,QAAQ,IAAI,aAAa,eACvB;MAAA,CAAC,gBAAgB,GACnB,QAAQ,KACN,kKACF;CAAA;CAIJ,MAAM,SAAS,eAAe,eAAe;CAC7C,MAAM,mBAAmB,eAAe;EACtC,MAAM,kBAAkB,OAAO,YAAY,aAAa,QAAQ,IAAI;EACpE,OAAO,OAAO,uBAAuB,eAAe,eAAe,CAAC;CACtE,CAAC;CACD,MAAM,WAAW,IAAI,iBAAiB,QAAQ,iBAAiB,KAAK;CACpE,MAAM,QAAQ,iBAAiB,MAAM,UACjC,gBAAgB,SAAS,iBAAiB,CAAC,IAC3C,SAAS,SAAS,iBAAiB,CAAC;CAExC,MAAM,cAAc,SAAS,WAAW,WAAW;EACjD,YAAY,OAAO,MAAM;CAC3B,CAAC;CAED,MAAM,UACJ,GAAG,SAGA;EACH,SAAS,OAAO,KAAK,IAAkB,KAAK,EAAE,CAAC,CAAC,YAAY,CAE5D,CAAC;CACH;CAEA,MAAM,wBAAwB;EAC5B,SAAS,WAAW,iBAAiB,KAAK;CAC5C,CAAC;CAED,qBAAqB;EACnB,YAAY;CACd,CAAC;CAED,MAAM,gBAAgB,iBAAiB,MAAM,UACzC,gBAAgB,KAAK,IACrB,SAAS,KAAK;CAElB,MAAM,aAAa,OAAO,aAAa;CAIvC,YACQ,MAAM,QACX,UAAU;EACT,IACE,SACA,iBAAiB,iBAAiB,MAAM,cAAc,CAAC,KAAe,CAAC,GAEvE,MAAM;CAEV,CACF;CAEA,OAAO;EACL,GAAG;EACH;EACA,aAAa,MAAM;EACnB,OAAO,MAAM;CACf;AACF"}
@@ -1 +1 @@
1
- {"version":3,"file":"useMutationState.cjs","names":["getCurrentScope","useQueryClient","computed","cloneDeepUnref","shallowRef","shallowReadonly"],"sources":["../../src/useMutationState.ts"],"sourcesContent":["import {\n computed,\n getCurrentScope,\n onScopeDispose,\n shallowReadonly,\n shallowRef,\n watch,\n} from 'vue-demi'\nimport { useQueryClient } from './useQueryClient'\nimport { cloneDeepUnref } from './utils'\nimport type { Ref } from 'vue-demi'\nimport type {\n Mutation,\n MutationFilters,\n MutationState,\n} from '@tanstack/query-core'\nimport type { QueryClient } from './queryClient'\nimport type { MaybeRefDeep } from './types'\nimport type { MutationCache } from './mutationCache'\n\ntype VueMutationFilters = MaybeRefDeep<MutationFilters>\n\n/**\n * The filters accepted by `useIsMutating`: {@link MutationFilters} as a plain object, a `ref`, or a reactive\n * getter.\n */\nexport type UseIsMutatingFilters =\n | MaybeRefDeep<Omit<MutationFilters, 'status'>>\n | (() => MaybeRefDeep<Omit<MutationFilters, 'status'>>)\n\n/**\n * The `useIsMutating` composable returns a `ref` to the `number` of mutations that your application currently\n * has `pending` (useful for app-wide loading indicators).\n *\n * `filters` may be a plain object, `MaybeRefDeep`, or a reactive getter (`() => ({ ... })`) — pass a getter if\n * the filters themselves depend on other reactive state.\n * @param filters - The {@link MutationFilters} to narrow down the matched mutations.\n * @param queryClient - Use this to use a custom `QueryClient`. Otherwise, the one provided by `VueQueryPlugin`\n * will be used.\n * @returns A `ref` to the `number` of the mutations that your application currently has `pending`.\n * @example\n * ```vue\n * <script setup lang=\"ts\">\n * import { useIsMutating } from '@tanstack/vue-query'\n *\n * // How many mutations matching the posts prefix are in progress?\n * const isMutatingPosts = useIsMutating({ mutationKey: ['posts'] })\n * </script>\n *\n * <template>\n * <span v-if=\"isMutatingPosts\">Saving posts...</span>\n * </template>\n * ```\n */\nexport function useIsMutating(\n filters: UseIsMutatingFilters = {},\n queryClient?: QueryClient,\n): Ref<number> {\n if (process.env.NODE_ENV === 'development') {\n if (!getCurrentScope()) {\n console.warn(\n 'vue-query composable like \"useQuery()\" should only be used inside a \"setup()\" function or a running effect scope. They might otherwise lead to memory leaks.',\n )\n }\n }\n\n const client = queryClient || useQueryClient()\n\n const mutationState = useMutationState(\n {\n filters: computed(() => ({\n ...cloneDeepUnref(typeof filters === 'function' ? filters() : filters),\n status: 'pending' as const,\n })),\n },\n client,\n )\n const length = computed(() => mutationState.value.length)\n\n return length\n}\n\ntype MutationTypeFromResult<TResult> = [TResult] extends [\n MutationState<\n infer TData,\n infer TError,\n infer TVariables,\n infer TOnMutateResult\n >,\n]\n ? Mutation<TData, TError, TVariables, TOnMutateResult>\n : Mutation\n\n/**\n * The options accepted by `useMutationState`: the `filters` matching the mutations, and `select` to map each\n * one (to its state, by default).\n */\nexport type MutationStateOptions<\n TResult = MutationState,\n TMutation extends Mutation<any, any, any, any> =\n MutationTypeFromResult<TResult>,\n> = {\n /**\n * The filters that select the mutations to return the state of.\n */\n filters?: VueMutationFilters\n /**\n * Maps each matching mutation to the value returned for it. Defaults to the mutation's `state`.\n */\n select?: (mutation: TMutation) => TResult\n}\n\n/**\n * Collects the mutations in the cache that match `options.filters`, mapped with `options.select`\n * (or to their state, by default).\n * @param mutationCache - The mutation cache to read.\n * @param options - The `filters` to match and the `select` function to map each mutation with.\n * @returns The selected value of every matching mutation.\n */\nfunction getResult<\n TResult = MutationState,\n TMutation extends Mutation<any, any, any, any> =\n MutationTypeFromResult<TResult>,\n>(\n mutationCache: MutationCache,\n options: MutationStateOptions<TResult, TMutation>,\n): Array<TResult> {\n return mutationCache\n .findAll(options.filters)\n .map(\n (mutation): TResult =>\n (options.select\n ? options.select(mutation as TMutation)\n : mutation.state) as TResult,\n )\n}\n\n/**\n * `useMutationState` is a composable that gives you access to all mutations in the `MutationCache`. You can\n * pass `filters` ({@link MutationFilters}) to narrow down your mutations, and `select` to transform the\n * mutation state.\n *\n * `options` may be a plain object or a reactive getter (`() => ({ ... })`) — pass a getter if the filters\n * themselves depend on other reactive state.\n * @param options - The `filters` to narrow down matched mutations, and an optional `select` to transform the\n * mutation state.\n * @param queryClient - Use this to use a custom `QueryClient`. Otherwise, the one provided by `VueQueryPlugin`\n * will be used.\n * @returns A `ref` to an Array of whatever `select` returns for each matching mutation.\n * @example\n * Get all variables of all running mutations:\n * ```vue\n * <script setup lang=\"ts\">\n * import { useMutationState } from '@tanstack/vue-query'\n *\n * const pendingVariables = useMutationState({\n * filters: { status: 'pending' },\n * select: (mutation) => mutation.state.variables,\n * })\n * </script>\n *\n * <template>{{ pendingVariables.length }} posts saving...</template>\n * ```\n * @example\n * Get all data for specific mutations via the `mutationKey`:\n * ```vue\n * <script setup lang=\"ts\">\n * import { useMutation, useMutationState } from '@tanstack/vue-query'\n *\n * const mutationKey = ['posts']\n *\n * // Some mutation that we want to get the state for\n * const mutation = useMutation({\n * mutationKey,\n * mutationFn: createPosts,\n * })\n *\n * const savedPosts = useMutationState({\n * // this mutation key needs to match the mutation key of the given mutation (see above)\n * filters: { mutationKey, status: 'success' },\n * select: (mutation) => mutation.state.data,\n * })\n * </script>\n *\n * <template>\n * <button @click=\"mutation.mutate(['New Post'])\">\n * Create post ({{ savedPosts.length }} saved so far)\n * </button>\n * </template>\n * ```\n * @example\n * Access the latest successful mutation data via the `mutationKey`. Each invocation of `mutate` adds a new\n * entry to the mutation cache for `gcTime` milliseconds — with the `status: 'success'` filter below, check the\n * last item that `useMutationState` returns to get the latest successful invocation:\n * ```vue\n * <script setup lang=\"ts\">\n * import { computed } from 'vue'\n * import { useMutationState } from '@tanstack/vue-query'\n *\n * const savedPosts = useMutationState({\n * filters: { mutationKey: ['posts'], status: 'success' },\n * select: (mutation) => mutation.state.data,\n * })\n *\n * const latestSavedPost = computed(() => savedPosts.value[savedPosts.value.length - 1])\n * </script>\n *\n * <template>{{ latestSavedPost ? 'Saved' : 'Nothing saved yet' }}</template>\n * ```\n */\nexport function useMutationState<\n TResult = MutationState,\n TMutation extends Mutation<any, any, any, any> =\n MutationTypeFromResult<TResult>,\n>(\n options:\n | MutationStateOptions<TResult, TMutation>\n | (() => MutationStateOptions<TResult, TMutation>) = {},\n queryClient?: QueryClient,\n): Readonly<Ref<Array<TResult>>> {\n const resolvedOptions = computed(() => {\n const newOptions = typeof options === 'function' ? options() : options\n return {\n filters: cloneDeepUnref(newOptions.filters),\n select: newOptions.select,\n }\n })\n const mutationCache = (queryClient || useQueryClient()).getMutationCache()\n const state = shallowRef(getResult(mutationCache, resolvedOptions.value))\n const unsubscribe = mutationCache.subscribe(() => {\n state.value = getResult(mutationCache, resolvedOptions.value)\n })\n\n watch(resolvedOptions, () => {\n state.value = getResult(mutationCache, resolvedOptions.value)\n })\n\n onScopeDispose(() => {\n unsubscribe()\n })\n\n return shallowReadonly(state)\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAsDA,SAAgB,cACd,UAAgC,CAAC,GACjC,aACa;CACb,IAAI,QAAQ,IAAI,aAAa,eACvB;MAAA,EAAA,GAACA,SAAAA,gBAAAA,CAAgB,GACnB,QAAQ,KACN,kKACF;CAAA;CAIJ,MAAM,SAAS,eAAeC,uBAAAA,eAAe;CAE7C,MAAM,gBAAgB,iBACpB,EACE,UAAA,GAASC,SAAAA,SAAAA,QAAgB;EACvB,GAAGC,cAAAA,eAAe,OAAO,YAAY,aAAa,QAAQ,IAAI,OAAO;EACrE,QAAQ;CACV,EAAE,EACJ,GACA,MACF;CAGA,QAAA,GAFeD,SAAAA,SAAAA,OAAe,cAAc,MAAM,MAEtC;AACd;;;;;;;;AAuCA,SAAS,UAKP,eACA,SACgB;CAChB,OAAO,cACJ,QAAQ,QAAQ,OAAO,CAAC,CACxB,KACE,aACE,QAAQ,SACL,QAAQ,OAAO,QAAqB,IACpC,SAAS,KACjB;AACJ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA2EA,SAAgB,iBAKd,UAEuD,CAAC,GACxD,aAC+B;CAC/B,MAAM,mBAAA,GAAkBA,SAAAA,SAAAA,OAAe;EACrC,MAAM,aAAa,OAAO,YAAY,aAAa,QAAQ,IAAI;EAC/D,OAAO;GACL,SAASC,cAAAA,eAAe,WAAW,OAAO;GAC1C,QAAQ,WAAW;EACrB;CACF,CAAC;CACD,MAAM,iBAAiB,eAAeF,uBAAAA,eAAe,EAAA,CAAG,iBAAiB;CACzE,MAAM,SAAA,GAAQG,SAAAA,WAAAA,CAAW,UAAU,eAAe,gBAAgB,KAAK,CAAC;CACxE,MAAM,cAAc,cAAc,gBAAgB;EAChD,MAAM,QAAQ,UAAU,eAAe,gBAAgB,KAAK;CAC9D,CAAC;CAED,CAAA,GAAA,SAAA,MAAA,CAAM,uBAAuB;EAC3B,MAAM,QAAQ,UAAU,eAAe,gBAAgB,KAAK;CAC9D,CAAC;CAED,CAAA,GAAA,SAAA,eAAA,OAAqB;EACnB,YAAY;CACd,CAAC;CAED,QAAA,GAAOC,SAAAA,gBAAAA,CAAgB,KAAK;AAC9B"}
1
+ {"version":3,"file":"useMutationState.cjs","names":["getCurrentScope","useQueryClient","computed","cloneDeepUnref","shallowRef","shallowReadonly"],"sources":["../../src/useMutationState.ts"],"sourcesContent":["import {\n computed,\n getCurrentScope,\n onScopeDispose,\n shallowReadonly,\n shallowRef,\n watch,\n} from 'vue-demi'\nimport { useQueryClient } from './useQueryClient'\nimport { cloneDeepUnref } from './utils'\nimport type {\n Mutation,\n MutationFilters,\n MutationState,\n} from '@tanstack/query-core'\nimport type { Ref } from 'vue-demi'\nimport type { MutationCache } from './mutationCache'\nimport type { QueryClient } from './queryClient'\nimport type { MaybeRefDeep } from './types'\n\ntype VueMutationFilters = MaybeRefDeep<MutationFilters>\n\n/**\n * The filters accepted by `useIsMutating`: {@link MutationFilters} as a plain object, a `ref`, or a reactive\n * getter.\n */\nexport type UseIsMutatingFilters =\n | MaybeRefDeep<Omit<MutationFilters, 'status'>>\n | (() => MaybeRefDeep<Omit<MutationFilters, 'status'>>)\n\n/**\n * The `useIsMutating` composable returns a `ref` to the `number` of mutations that your application currently\n * has `pending` (useful for app-wide loading indicators).\n *\n * `filters` may be a plain object, `MaybeRefDeep`, or a reactive getter (`() => ({ ... })`) — pass a getter if\n * the filters themselves depend on other reactive state.\n * @param filters - The {@link MutationFilters} to narrow down the matched mutations.\n * @param queryClient - Use this to use a custom `QueryClient`. Otherwise, the one provided by `VueQueryPlugin`\n * will be used.\n * @returns A `ref` to the `number` of the mutations that your application currently has `pending`.\n * @example\n * ```vue\n * <script setup lang=\"ts\">\n * import { useIsMutating } from '@tanstack/vue-query'\n *\n * // How many mutations matching the posts prefix are in progress?\n * const isMutatingPosts = useIsMutating({ mutationKey: ['posts'] })\n * </script>\n *\n * <template>\n * <span v-if=\"isMutatingPosts\">Saving posts...</span>\n * </template>\n * ```\n */\nexport function useIsMutating(\n filters: UseIsMutatingFilters = {},\n queryClient?: QueryClient,\n): Ref<number> {\n if (process.env.NODE_ENV === 'development') {\n if (!getCurrentScope()) {\n console.warn(\n 'vue-query composable like \"useQuery()\" should only be used inside a \"setup()\" function or a running effect scope. They might otherwise lead to memory leaks.',\n )\n }\n }\n\n const client = queryClient || useQueryClient()\n\n const mutationState = useMutationState(\n {\n filters: computed(() => ({\n ...cloneDeepUnref(typeof filters === 'function' ? filters() : filters),\n status: 'pending' as const,\n })),\n },\n client,\n )\n const length = computed(() => mutationState.value.length)\n\n return length\n}\n\ntype MutationTypeFromResult<TResult> = [TResult] extends [\n MutationState<\n infer TData,\n infer TError,\n infer TVariables,\n infer TOnMutateResult\n >,\n]\n ? Mutation<TData, TError, TVariables, TOnMutateResult>\n : Mutation\n\n/**\n * The options accepted by `useMutationState`: the `filters` matching the mutations, and `select` to map each\n * one (to its state, by default).\n */\nexport type MutationStateOptions<\n TResult = MutationState,\n TMutation extends Mutation<any, any, any, any> =\n MutationTypeFromResult<TResult>,\n> = {\n /**\n * The filters that select the mutations to return the state of.\n */\n filters?: VueMutationFilters\n /**\n * Maps each matching mutation to the value returned for it. Defaults to the mutation's `state`.\n */\n select?: (mutation: TMutation) => TResult\n}\n\n/**\n * Collects the mutations in the cache that match `options.filters`, mapped with `options.select`\n * (or to their state, by default).\n * @param mutationCache - The mutation cache to read.\n * @param options - The `filters` to match and the `select` function to map each mutation with.\n * @returns The selected value of every matching mutation.\n */\nfunction getResult<\n TResult = MutationState,\n TMutation extends Mutation<any, any, any, any> =\n MutationTypeFromResult<TResult>,\n>(\n mutationCache: MutationCache,\n options: MutationStateOptions<TResult, TMutation>,\n): Array<TResult> {\n return mutationCache\n .findAll(options.filters)\n .map(\n (mutation): TResult =>\n (options.select\n ? options.select(mutation as TMutation)\n : mutation.state) as TResult,\n )\n}\n\n/**\n * `useMutationState` is a composable that gives you access to all mutations in the `MutationCache`. You can\n * pass `filters` ({@link MutationFilters}) to narrow down your mutations, and `select` to transform the\n * mutation state.\n *\n * `options` may be a plain object or a reactive getter (`() => ({ ... })`) — pass a getter if the filters\n * themselves depend on other reactive state.\n * @param options - The `filters` to narrow down matched mutations, and an optional `select` to transform the\n * mutation state.\n * @param queryClient - Use this to use a custom `QueryClient`. Otherwise, the one provided by `VueQueryPlugin`\n * will be used.\n * @returns A `ref` to an Array of whatever `select` returns for each matching mutation.\n * @example\n * Get all variables of all running mutations:\n * ```vue\n * <script setup lang=\"ts\">\n * import { useMutationState } from '@tanstack/vue-query'\n *\n * const pendingVariables = useMutationState({\n * filters: { status: 'pending' },\n * select: (mutation) => mutation.state.variables,\n * })\n * </script>\n *\n * <template>{{ pendingVariables.length }} posts saving...</template>\n * ```\n * @example\n * Get all data for specific mutations via the `mutationKey`:\n * ```vue\n * <script setup lang=\"ts\">\n * import { useMutation, useMutationState } from '@tanstack/vue-query'\n *\n * const mutationKey = ['posts']\n *\n * // Some mutation that we want to get the state for\n * const mutation = useMutation({\n * mutationKey,\n * mutationFn: createPosts,\n * })\n *\n * const savedPosts = useMutationState({\n * // this mutation key needs to match the mutation key of the given mutation (see above)\n * filters: { mutationKey, status: 'success' },\n * select: (mutation) => mutation.state.data,\n * })\n * </script>\n *\n * <template>\n * <button @click=\"mutation.mutate(['New Post'])\">\n * Create post ({{ savedPosts.length }} saved so far)\n * </button>\n * </template>\n * ```\n * @example\n * Access the latest successful mutation data via the `mutationKey`. Each invocation of `mutate` adds a new\n * entry to the mutation cache for `gcTime` milliseconds — with the `status: 'success'` filter below, check the\n * last item that `useMutationState` returns to get the latest successful invocation:\n * ```vue\n * <script setup lang=\"ts\">\n * import { computed } from 'vue'\n * import { useMutationState } from '@tanstack/vue-query'\n *\n * const savedPosts = useMutationState({\n * filters: { mutationKey: ['posts'], status: 'success' },\n * select: (mutation) => mutation.state.data,\n * })\n *\n * const latestSavedPost = computed(() => savedPosts.value[savedPosts.value.length - 1])\n * </script>\n *\n * <template>{{ latestSavedPost ? 'Saved' : 'Nothing saved yet' }}</template>\n * ```\n */\nexport function useMutationState<\n TResult = MutationState,\n TMutation extends Mutation<any, any, any, any> =\n MutationTypeFromResult<TResult>,\n>(\n options:\n | MutationStateOptions<TResult, TMutation>\n | (() => MutationStateOptions<TResult, TMutation>) = {},\n queryClient?: QueryClient,\n): Readonly<Ref<Array<TResult>>> {\n const resolvedOptions = computed(() => {\n const newOptions = typeof options === 'function' ? options() : options\n return {\n filters: cloneDeepUnref(newOptions.filters),\n select: newOptions.select,\n }\n })\n const mutationCache = (queryClient || useQueryClient()).getMutationCache()\n const state = shallowRef(getResult(mutationCache, resolvedOptions.value))\n const unsubscribe = mutationCache.subscribe(() => {\n state.value = getResult(mutationCache, resolvedOptions.value)\n })\n\n watch(resolvedOptions, () => {\n state.value = getResult(mutationCache, resolvedOptions.value)\n })\n\n onScopeDispose(() => {\n unsubscribe()\n })\n\n return shallowReadonly(state)\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAsDA,SAAgB,cACd,UAAgC,CAAC,GACjC,aACa;CACb,IAAI,QAAQ,IAAI,aAAa,eACvB;MAAA,EAAA,GAACA,SAAAA,gBAAAA,CAAgB,GACnB,QAAQ,KACN,kKACF;CAAA;CAIJ,MAAM,SAAS,eAAeC,uBAAAA,eAAe;CAE7C,MAAM,gBAAgB,iBACpB,EACE,UAAA,GAASC,SAAAA,SAAAA,QAAgB;EACvB,GAAGC,cAAAA,eAAe,OAAO,YAAY,aAAa,QAAQ,IAAI,OAAO;EACrE,QAAQ;CACV,EAAE,EACJ,GACA,MACF;CAGA,QAAA,GAFeD,SAAAA,SAAAA,OAAe,cAAc,MAAM,MAEtC;AACd;;;;;;;;AAuCA,SAAS,UAKP,eACA,SACgB;CAChB,OAAO,cACJ,QAAQ,QAAQ,OAAO,CAAC,CACxB,KACE,aACE,QAAQ,SACL,QAAQ,OAAO,QAAqB,IACpC,SAAS,KACjB;AACJ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA2EA,SAAgB,iBAKd,UAEuD,CAAC,GACxD,aAC+B;CAC/B,MAAM,mBAAA,GAAkBA,SAAAA,SAAAA,OAAe;EACrC,MAAM,aAAa,OAAO,YAAY,aAAa,QAAQ,IAAI;EAC/D,OAAO;GACL,SAASC,cAAAA,eAAe,WAAW,OAAO;GAC1C,QAAQ,WAAW;EACrB;CACF,CAAC;CACD,MAAM,iBAAiB,eAAeF,uBAAAA,eAAe,EAAA,CAAG,iBAAiB;CACzE,MAAM,SAAA,GAAQG,SAAAA,WAAAA,CAAW,UAAU,eAAe,gBAAgB,KAAK,CAAC;CACxE,MAAM,cAAc,cAAc,gBAAgB;EAChD,MAAM,QAAQ,UAAU,eAAe,gBAAgB,KAAK;CAC9D,CAAC;CAED,CAAA,GAAA,SAAA,MAAA,CAAM,uBAAuB;EAC3B,MAAM,QAAQ,UAAU,eAAe,gBAAgB,KAAK;CAC9D,CAAC;CAED,CAAA,GAAA,SAAA,eAAA,OAAqB;EACnB,YAAY;CACd,CAAC;CAED,QAAA,GAAOC,SAAAA,gBAAAA,CAAgB,KAAK;AAC9B"}
@@ -1,5 +1,5 @@
1
1
  import { o as MaybeRefDeep } from "./types-u_Tu5Ybs.cjs";
2
- import { t as QueryClient$1 } from "./queryClient-BGn8uIej.cjs";
2
+ import { t as QueryClient$1 } from "./queryClient-yJW8K_VP.cjs";
3
3
  import { Mutation, MutationFilters, MutationState } from "@tanstack/query-core";
4
4
  import { Ref } from "vue-demi";
5
5
  type VueMutationFilters = MaybeRefDeep<MutationFilters>;
@@ -1,5 +1,5 @@
1
1
  import { o as MaybeRefDeep } from "./types-u_Tu5Ybs.js";
2
- import { t as QueryClient$1 } from "./queryClient-Ba4HSFnn.js";
2
+ import { t as QueryClient$1 } from "./queryClient-6AWIHAhP.js";
3
3
  import { Mutation, MutationFilters, MutationState } from "@tanstack/query-core";
4
4
  import { Ref } from "vue-demi";
5
5
  type VueMutationFilters = MaybeRefDeep<MutationFilters>;
@@ -1 +1 @@
1
- {"version":3,"file":"useMutationState.js","names":[],"sources":["../../src/useMutationState.ts"],"sourcesContent":["import {\n computed,\n getCurrentScope,\n onScopeDispose,\n shallowReadonly,\n shallowRef,\n watch,\n} from 'vue-demi'\nimport { useQueryClient } from './useQueryClient'\nimport { cloneDeepUnref } from './utils'\nimport type { Ref } from 'vue-demi'\nimport type {\n Mutation,\n MutationFilters,\n MutationState,\n} from '@tanstack/query-core'\nimport type { QueryClient } from './queryClient'\nimport type { MaybeRefDeep } from './types'\nimport type { MutationCache } from './mutationCache'\n\ntype VueMutationFilters = MaybeRefDeep<MutationFilters>\n\n/**\n * The filters accepted by `useIsMutating`: {@link MutationFilters} as a plain object, a `ref`, or a reactive\n * getter.\n */\nexport type UseIsMutatingFilters =\n | MaybeRefDeep<Omit<MutationFilters, 'status'>>\n | (() => MaybeRefDeep<Omit<MutationFilters, 'status'>>)\n\n/**\n * The `useIsMutating` composable returns a `ref` to the `number` of mutations that your application currently\n * has `pending` (useful for app-wide loading indicators).\n *\n * `filters` may be a plain object, `MaybeRefDeep`, or a reactive getter (`() => ({ ... })`) — pass a getter if\n * the filters themselves depend on other reactive state.\n * @param filters - The {@link MutationFilters} to narrow down the matched mutations.\n * @param queryClient - Use this to use a custom `QueryClient`. Otherwise, the one provided by `VueQueryPlugin`\n * will be used.\n * @returns A `ref` to the `number` of the mutations that your application currently has `pending`.\n * @example\n * ```vue\n * <script setup lang=\"ts\">\n * import { useIsMutating } from '@tanstack/vue-query'\n *\n * // How many mutations matching the posts prefix are in progress?\n * const isMutatingPosts = useIsMutating({ mutationKey: ['posts'] })\n * </script>\n *\n * <template>\n * <span v-if=\"isMutatingPosts\">Saving posts...</span>\n * </template>\n * ```\n */\nexport function useIsMutating(\n filters: UseIsMutatingFilters = {},\n queryClient?: QueryClient,\n): Ref<number> {\n if (process.env.NODE_ENV === 'development') {\n if (!getCurrentScope()) {\n console.warn(\n 'vue-query composable like \"useQuery()\" should only be used inside a \"setup()\" function or a running effect scope. They might otherwise lead to memory leaks.',\n )\n }\n }\n\n const client = queryClient || useQueryClient()\n\n const mutationState = useMutationState(\n {\n filters: computed(() => ({\n ...cloneDeepUnref(typeof filters === 'function' ? filters() : filters),\n status: 'pending' as const,\n })),\n },\n client,\n )\n const length = computed(() => mutationState.value.length)\n\n return length\n}\n\ntype MutationTypeFromResult<TResult> = [TResult] extends [\n MutationState<\n infer TData,\n infer TError,\n infer TVariables,\n infer TOnMutateResult\n >,\n]\n ? Mutation<TData, TError, TVariables, TOnMutateResult>\n : Mutation\n\n/**\n * The options accepted by `useMutationState`: the `filters` matching the mutations, and `select` to map each\n * one (to its state, by default).\n */\nexport type MutationStateOptions<\n TResult = MutationState,\n TMutation extends Mutation<any, any, any, any> =\n MutationTypeFromResult<TResult>,\n> = {\n /**\n * The filters that select the mutations to return the state of.\n */\n filters?: VueMutationFilters\n /**\n * Maps each matching mutation to the value returned for it. Defaults to the mutation's `state`.\n */\n select?: (mutation: TMutation) => TResult\n}\n\n/**\n * Collects the mutations in the cache that match `options.filters`, mapped with `options.select`\n * (or to their state, by default).\n * @param mutationCache - The mutation cache to read.\n * @param options - The `filters` to match and the `select` function to map each mutation with.\n * @returns The selected value of every matching mutation.\n */\nfunction getResult<\n TResult = MutationState,\n TMutation extends Mutation<any, any, any, any> =\n MutationTypeFromResult<TResult>,\n>(\n mutationCache: MutationCache,\n options: MutationStateOptions<TResult, TMutation>,\n): Array<TResult> {\n return mutationCache\n .findAll(options.filters)\n .map(\n (mutation): TResult =>\n (options.select\n ? options.select(mutation as TMutation)\n : mutation.state) as TResult,\n )\n}\n\n/**\n * `useMutationState` is a composable that gives you access to all mutations in the `MutationCache`. You can\n * pass `filters` ({@link MutationFilters}) to narrow down your mutations, and `select` to transform the\n * mutation state.\n *\n * `options` may be a plain object or a reactive getter (`() => ({ ... })`) — pass a getter if the filters\n * themselves depend on other reactive state.\n * @param options - The `filters` to narrow down matched mutations, and an optional `select` to transform the\n * mutation state.\n * @param queryClient - Use this to use a custom `QueryClient`. Otherwise, the one provided by `VueQueryPlugin`\n * will be used.\n * @returns A `ref` to an Array of whatever `select` returns for each matching mutation.\n * @example\n * Get all variables of all running mutations:\n * ```vue\n * <script setup lang=\"ts\">\n * import { useMutationState } from '@tanstack/vue-query'\n *\n * const pendingVariables = useMutationState({\n * filters: { status: 'pending' },\n * select: (mutation) => mutation.state.variables,\n * })\n * </script>\n *\n * <template>{{ pendingVariables.length }} posts saving...</template>\n * ```\n * @example\n * Get all data for specific mutations via the `mutationKey`:\n * ```vue\n * <script setup lang=\"ts\">\n * import { useMutation, useMutationState } from '@tanstack/vue-query'\n *\n * const mutationKey = ['posts']\n *\n * // Some mutation that we want to get the state for\n * const mutation = useMutation({\n * mutationKey,\n * mutationFn: createPosts,\n * })\n *\n * const savedPosts = useMutationState({\n * // this mutation key needs to match the mutation key of the given mutation (see above)\n * filters: { mutationKey, status: 'success' },\n * select: (mutation) => mutation.state.data,\n * })\n * </script>\n *\n * <template>\n * <button @click=\"mutation.mutate(['New Post'])\">\n * Create post ({{ savedPosts.length }} saved so far)\n * </button>\n * </template>\n * ```\n * @example\n * Access the latest successful mutation data via the `mutationKey`. Each invocation of `mutate` adds a new\n * entry to the mutation cache for `gcTime` milliseconds — with the `status: 'success'` filter below, check the\n * last item that `useMutationState` returns to get the latest successful invocation:\n * ```vue\n * <script setup lang=\"ts\">\n * import { computed } from 'vue'\n * import { useMutationState } from '@tanstack/vue-query'\n *\n * const savedPosts = useMutationState({\n * filters: { mutationKey: ['posts'], status: 'success' },\n * select: (mutation) => mutation.state.data,\n * })\n *\n * const latestSavedPost = computed(() => savedPosts.value[savedPosts.value.length - 1])\n * </script>\n *\n * <template>{{ latestSavedPost ? 'Saved' : 'Nothing saved yet' }}</template>\n * ```\n */\nexport function useMutationState<\n TResult = MutationState,\n TMutation extends Mutation<any, any, any, any> =\n MutationTypeFromResult<TResult>,\n>(\n options:\n | MutationStateOptions<TResult, TMutation>\n | (() => MutationStateOptions<TResult, TMutation>) = {},\n queryClient?: QueryClient,\n): Readonly<Ref<Array<TResult>>> {\n const resolvedOptions = computed(() => {\n const newOptions = typeof options === 'function' ? options() : options\n return {\n filters: cloneDeepUnref(newOptions.filters),\n select: newOptions.select,\n }\n })\n const mutationCache = (queryClient || useQueryClient()).getMutationCache()\n const state = shallowRef(getResult(mutationCache, resolvedOptions.value))\n const unsubscribe = mutationCache.subscribe(() => {\n state.value = getResult(mutationCache, resolvedOptions.value)\n })\n\n watch(resolvedOptions, () => {\n state.value = getResult(mutationCache, resolvedOptions.value)\n })\n\n onScopeDispose(() => {\n unsubscribe()\n })\n\n return shallowReadonly(state)\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAsDA,SAAgB,cACd,UAAgC,CAAC,GACjC,aACa;CACb,IAAI,QAAQ,IAAI,aAAa,eACvB;MAAA,CAAC,gBAAgB,GACnB,QAAQ,KACN,kKACF;CAAA;CAIJ,MAAM,SAAS,eAAe,eAAe;CAE7C,MAAM,gBAAgB,iBACpB,EACE,SAAS,gBAAgB;EACvB,GAAG,eAAe,OAAO,YAAY,aAAa,QAAQ,IAAI,OAAO;EACrE,QAAQ;CACV,EAAE,EACJ,GACA,MACF;CAGA,OAFe,eAAe,cAAc,MAAM,MAEtC;AACd;;;;;;;;AAuCA,SAAS,UAKP,eACA,SACgB;CAChB,OAAO,cACJ,QAAQ,QAAQ,OAAO,CAAC,CACxB,KACE,aACE,QAAQ,SACL,QAAQ,OAAO,QAAqB,IACpC,SAAS,KACjB;AACJ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA2EA,SAAgB,iBAKd,UAEuD,CAAC,GACxD,aAC+B;CAC/B,MAAM,kBAAkB,eAAe;EACrC,MAAM,aAAa,OAAO,YAAY,aAAa,QAAQ,IAAI;EAC/D,OAAO;GACL,SAAS,eAAe,WAAW,OAAO;GAC1C,QAAQ,WAAW;EACrB;CACF,CAAC;CACD,MAAM,iBAAiB,eAAe,eAAe,EAAA,CAAG,iBAAiB;CACzE,MAAM,QAAQ,WAAW,UAAU,eAAe,gBAAgB,KAAK,CAAC;CACxE,MAAM,cAAc,cAAc,gBAAgB;EAChD,MAAM,QAAQ,UAAU,eAAe,gBAAgB,KAAK;CAC9D,CAAC;CAED,MAAM,uBAAuB;EAC3B,MAAM,QAAQ,UAAU,eAAe,gBAAgB,KAAK;CAC9D,CAAC;CAED,qBAAqB;EACnB,YAAY;CACd,CAAC;CAED,OAAO,gBAAgB,KAAK;AAC9B"}
1
+ {"version":3,"file":"useMutationState.js","names":[],"sources":["../../src/useMutationState.ts"],"sourcesContent":["import {\n computed,\n getCurrentScope,\n onScopeDispose,\n shallowReadonly,\n shallowRef,\n watch,\n} from 'vue-demi'\nimport { useQueryClient } from './useQueryClient'\nimport { cloneDeepUnref } from './utils'\nimport type {\n Mutation,\n MutationFilters,\n MutationState,\n} from '@tanstack/query-core'\nimport type { Ref } from 'vue-demi'\nimport type { MutationCache } from './mutationCache'\nimport type { QueryClient } from './queryClient'\nimport type { MaybeRefDeep } from './types'\n\ntype VueMutationFilters = MaybeRefDeep<MutationFilters>\n\n/**\n * The filters accepted by `useIsMutating`: {@link MutationFilters} as a plain object, a `ref`, or a reactive\n * getter.\n */\nexport type UseIsMutatingFilters =\n | MaybeRefDeep<Omit<MutationFilters, 'status'>>\n | (() => MaybeRefDeep<Omit<MutationFilters, 'status'>>)\n\n/**\n * The `useIsMutating` composable returns a `ref` to the `number` of mutations that your application currently\n * has `pending` (useful for app-wide loading indicators).\n *\n * `filters` may be a plain object, `MaybeRefDeep`, or a reactive getter (`() => ({ ... })`) — pass a getter if\n * the filters themselves depend on other reactive state.\n * @param filters - The {@link MutationFilters} to narrow down the matched mutations.\n * @param queryClient - Use this to use a custom `QueryClient`. Otherwise, the one provided by `VueQueryPlugin`\n * will be used.\n * @returns A `ref` to the `number` of the mutations that your application currently has `pending`.\n * @example\n * ```vue\n * <script setup lang=\"ts\">\n * import { useIsMutating } from '@tanstack/vue-query'\n *\n * // How many mutations matching the posts prefix are in progress?\n * const isMutatingPosts = useIsMutating({ mutationKey: ['posts'] })\n * </script>\n *\n * <template>\n * <span v-if=\"isMutatingPosts\">Saving posts...</span>\n * </template>\n * ```\n */\nexport function useIsMutating(\n filters: UseIsMutatingFilters = {},\n queryClient?: QueryClient,\n): Ref<number> {\n if (process.env.NODE_ENV === 'development') {\n if (!getCurrentScope()) {\n console.warn(\n 'vue-query composable like \"useQuery()\" should only be used inside a \"setup()\" function or a running effect scope. They might otherwise lead to memory leaks.',\n )\n }\n }\n\n const client = queryClient || useQueryClient()\n\n const mutationState = useMutationState(\n {\n filters: computed(() => ({\n ...cloneDeepUnref(typeof filters === 'function' ? filters() : filters),\n status: 'pending' as const,\n })),\n },\n client,\n )\n const length = computed(() => mutationState.value.length)\n\n return length\n}\n\ntype MutationTypeFromResult<TResult> = [TResult] extends [\n MutationState<\n infer TData,\n infer TError,\n infer TVariables,\n infer TOnMutateResult\n >,\n]\n ? Mutation<TData, TError, TVariables, TOnMutateResult>\n : Mutation\n\n/**\n * The options accepted by `useMutationState`: the `filters` matching the mutations, and `select` to map each\n * one (to its state, by default).\n */\nexport type MutationStateOptions<\n TResult = MutationState,\n TMutation extends Mutation<any, any, any, any> =\n MutationTypeFromResult<TResult>,\n> = {\n /**\n * The filters that select the mutations to return the state of.\n */\n filters?: VueMutationFilters\n /**\n * Maps each matching mutation to the value returned for it. Defaults to the mutation's `state`.\n */\n select?: (mutation: TMutation) => TResult\n}\n\n/**\n * Collects the mutations in the cache that match `options.filters`, mapped with `options.select`\n * (or to their state, by default).\n * @param mutationCache - The mutation cache to read.\n * @param options - The `filters` to match and the `select` function to map each mutation with.\n * @returns The selected value of every matching mutation.\n */\nfunction getResult<\n TResult = MutationState,\n TMutation extends Mutation<any, any, any, any> =\n MutationTypeFromResult<TResult>,\n>(\n mutationCache: MutationCache,\n options: MutationStateOptions<TResult, TMutation>,\n): Array<TResult> {\n return mutationCache\n .findAll(options.filters)\n .map(\n (mutation): TResult =>\n (options.select\n ? options.select(mutation as TMutation)\n : mutation.state) as TResult,\n )\n}\n\n/**\n * `useMutationState` is a composable that gives you access to all mutations in the `MutationCache`. You can\n * pass `filters` ({@link MutationFilters}) to narrow down your mutations, and `select` to transform the\n * mutation state.\n *\n * `options` may be a plain object or a reactive getter (`() => ({ ... })`) — pass a getter if the filters\n * themselves depend on other reactive state.\n * @param options - The `filters` to narrow down matched mutations, and an optional `select` to transform the\n * mutation state.\n * @param queryClient - Use this to use a custom `QueryClient`. Otherwise, the one provided by `VueQueryPlugin`\n * will be used.\n * @returns A `ref` to an Array of whatever `select` returns for each matching mutation.\n * @example\n * Get all variables of all running mutations:\n * ```vue\n * <script setup lang=\"ts\">\n * import { useMutationState } from '@tanstack/vue-query'\n *\n * const pendingVariables = useMutationState({\n * filters: { status: 'pending' },\n * select: (mutation) => mutation.state.variables,\n * })\n * </script>\n *\n * <template>{{ pendingVariables.length }} posts saving...</template>\n * ```\n * @example\n * Get all data for specific mutations via the `mutationKey`:\n * ```vue\n * <script setup lang=\"ts\">\n * import { useMutation, useMutationState } from '@tanstack/vue-query'\n *\n * const mutationKey = ['posts']\n *\n * // Some mutation that we want to get the state for\n * const mutation = useMutation({\n * mutationKey,\n * mutationFn: createPosts,\n * })\n *\n * const savedPosts = useMutationState({\n * // this mutation key needs to match the mutation key of the given mutation (see above)\n * filters: { mutationKey, status: 'success' },\n * select: (mutation) => mutation.state.data,\n * })\n * </script>\n *\n * <template>\n * <button @click=\"mutation.mutate(['New Post'])\">\n * Create post ({{ savedPosts.length }} saved so far)\n * </button>\n * </template>\n * ```\n * @example\n * Access the latest successful mutation data via the `mutationKey`. Each invocation of `mutate` adds a new\n * entry to the mutation cache for `gcTime` milliseconds — with the `status: 'success'` filter below, check the\n * last item that `useMutationState` returns to get the latest successful invocation:\n * ```vue\n * <script setup lang=\"ts\">\n * import { computed } from 'vue'\n * import { useMutationState } from '@tanstack/vue-query'\n *\n * const savedPosts = useMutationState({\n * filters: { mutationKey: ['posts'], status: 'success' },\n * select: (mutation) => mutation.state.data,\n * })\n *\n * const latestSavedPost = computed(() => savedPosts.value[savedPosts.value.length - 1])\n * </script>\n *\n * <template>{{ latestSavedPost ? 'Saved' : 'Nothing saved yet' }}</template>\n * ```\n */\nexport function useMutationState<\n TResult = MutationState,\n TMutation extends Mutation<any, any, any, any> =\n MutationTypeFromResult<TResult>,\n>(\n options:\n | MutationStateOptions<TResult, TMutation>\n | (() => MutationStateOptions<TResult, TMutation>) = {},\n queryClient?: QueryClient,\n): Readonly<Ref<Array<TResult>>> {\n const resolvedOptions = computed(() => {\n const newOptions = typeof options === 'function' ? options() : options\n return {\n filters: cloneDeepUnref(newOptions.filters),\n select: newOptions.select,\n }\n })\n const mutationCache = (queryClient || useQueryClient()).getMutationCache()\n const state = shallowRef(getResult(mutationCache, resolvedOptions.value))\n const unsubscribe = mutationCache.subscribe(() => {\n state.value = getResult(mutationCache, resolvedOptions.value)\n })\n\n watch(resolvedOptions, () => {\n state.value = getResult(mutationCache, resolvedOptions.value)\n })\n\n onScopeDispose(() => {\n unsubscribe()\n })\n\n return shallowReadonly(state)\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAsDA,SAAgB,cACd,UAAgC,CAAC,GACjC,aACa;CACb,IAAI,QAAQ,IAAI,aAAa,eACvB;MAAA,CAAC,gBAAgB,GACnB,QAAQ,KACN,kKACF;CAAA;CAIJ,MAAM,SAAS,eAAe,eAAe;CAE7C,MAAM,gBAAgB,iBACpB,EACE,SAAS,gBAAgB;EACvB,GAAG,eAAe,OAAO,YAAY,aAAa,QAAQ,IAAI,OAAO;EACrE,QAAQ;CACV,EAAE,EACJ,GACA,MACF;CAGA,OAFe,eAAe,cAAc,MAAM,MAEtC;AACd;;;;;;;;AAuCA,SAAS,UAKP,eACA,SACgB;CAChB,OAAO,cACJ,QAAQ,QAAQ,OAAO,CAAC,CACxB,KACE,aACE,QAAQ,SACL,QAAQ,OAAO,QAAqB,IACpC,SAAS,KACjB;AACJ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA2EA,SAAgB,iBAKd,UAEuD,CAAC,GACxD,aAC+B;CAC/B,MAAM,kBAAkB,eAAe;EACrC,MAAM,aAAa,OAAO,YAAY,aAAa,QAAQ,IAAI;EAC/D,OAAO;GACL,SAAS,eAAe,WAAW,OAAO;GAC1C,QAAQ,WAAW;EACrB;CACF,CAAC;CACD,MAAM,iBAAiB,eAAe,eAAe,EAAA,CAAG,iBAAiB;CACzE,MAAM,QAAQ,WAAW,UAAU,eAAe,gBAAgB,KAAK,CAAC;CACxE,MAAM,cAAc,cAAc,gBAAgB;EAChD,MAAM,QAAQ,UAAU,eAAe,gBAAgB,KAAK;CAC9D,CAAC;CAED,MAAM,uBAAuB;EAC3B,MAAM,QAAQ,UAAU,eAAe,gBAAgB,KAAK;CAC9D,CAAC;CAED,qBAAqB;EACnB,YAAY;CACd,CAAC;CAED,OAAO,gBAAgB,KAAK;AAC9B"}
@@ -1 +1 @@
1
- {"version":3,"file":"usePrefetchInfiniteQuery.cjs","names":["getCurrentScope","useQueryClient","unref","cloneDeepUnref","noop"],"sources":["../../src/usePrefetchInfiniteQuery.ts"],"sourcesContent":["import { getCurrentScope, unref, watchEffect } from 'vue-demi'\nimport { noop } from '@tanstack/query-core'\nimport { useQueryClient } from './useQueryClient'\nimport { cloneDeepUnref } from './utils'\nimport type {\n DefaultError,\n DistributiveOmit,\n InfiniteData,\n InfiniteQueryExecuteOptions,\n QueryKey,\n SkipToken,\n} from '@tanstack/query-core'\nimport type { QueryClient } from './queryClient'\nimport type { MaybeRefDeep, MaybeRefOrGetter } from './types'\n\n/**\n * The options accepted by `usePrefetchInfiniteQuery` — everything you can pass to `queryClient.infiniteQuery`,\n * except that `queryFn` can't be `skipToken`.\n */\nexport type UsePrefetchInfiniteQueryOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryKey extends QueryKey,\n TPageParam,\n> = DistributiveOmit<\n InfiniteQueryExecuteOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryKey,\n TPageParam\n >,\n 'queryFn'\n> & {\n queryFn?: Exclude<\n InfiniteQueryExecuteOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryKey,\n TPageParam\n >['queryFn'],\n SkipToken\n >\n}\n\n/**\n * Checks whether an option was passed as a getter function.\n * @param value - The option value.\n * @returns `true` if `value` is a function.\n */\nfunction isGetter<T>(value: MaybeRefOrGetter<T>): value is () => T {\n return typeof value === 'function'\n}\n\n/**\n * `usePrefetchInfiniteQuery` does not return anything — it fires a prefetch as a reactive side effect, useful\n * for kicking off a fetch ahead of the component that will actually render the data with `useInfiniteQuery`.\n * You can pass everything to `usePrefetchInfiniteQuery` that you can pass to `queryClient.infiniteQuery`,\n * though `queryKey`, `initialPageParam`, and `getNextPageParam` are always required, and `queryFn` is required\n * unless a default query function has been defined.\n *\n * `getNextPageParam` receives both the last page of the infinite list of data and the full array of all pages,\n * as well as pageParam information, and should return a single variable that will be passed to your query\n * function as `context.pageParam`. Return `undefined` or `null` to indicate there is no next page available.\n *\n * The prefetch is skipped if the query already has any cached state — including a `pending`/`error` state left\n * over from a previous attempt — so it won't refetch data that's already there or already in flight. It\n * re-runs whenever a reactive dependency in `options` (built with `infiniteQueryOptions`, for example) changes.\n *\n * Fire this during render, before a suspense boundary that wraps a component using `useInfiniteQuery`'s\n * `suspense()` — see the {@link https://tanstack.com/query/latest/docs/framework/vue/guides/suspense | Suspense guide}.\n * @param options - A `ref`, plain value, or reactive getter resolving to the\n * {@link UsePrefetchInfiniteQueryOptions} to use — everything you can pass to `queryClient.infiniteQuery`.\n * @param queryClient - Use this to use a custom `QueryClient`. Otherwise, the one provided by `VueQueryPlugin`\n * will be used.\n * @example\n * ```vue\n * <script setup lang=\"ts\">\n * import { infiniteQueryOptions, usePrefetchInfiniteQuery } from '@tanstack/vue-query'\n * import Projects from './Projects.vue'\n *\n * const projectsOptions = infiniteQueryOptions({\n * queryKey: ['projects'],\n * queryFn: ({ pageParam }) => fetchProjects(pageParam),\n * initialPageParam: 0,\n * getNextPageParam: (lastPage) => lastPage.nextId,\n * })\n *\n * // Fire the prefetch as soon as this component runs, before `Projects` mounts and calls `useInfiniteQuery`.\n * usePrefetchInfiniteQuery(projectsOptions)\n * </script>\n *\n * <template>\n * <Projects />\n * </template>\n * ```\n */\nexport function usePrefetchInfiniteQuery<\n TQueryFnData = unknown,\n TError = DefaultError,\n TData = InfiniteData<TQueryFnData>,\n TQueryKey extends QueryKey = QueryKey,\n TPageParam = unknown,\n>(\n options: MaybeRefOrGetter<\n MaybeRefDeep<\n UsePrefetchInfiniteQueryOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryKey,\n TPageParam\n >\n >\n >,\n queryClient?: QueryClient,\n): void {\n if (process.env.NODE_ENV === 'development') {\n if (!getCurrentScope()) {\n console.warn(\n 'vue-query composable like \"useQuery()\" should only be used inside a \"setup()\" function or a running effect scope. They might otherwise lead to memory leaks.',\n )\n }\n }\n\n const client = queryClient || useQueryClient()\n\n watchEffect(() => {\n const resolvedOptions = isGetter(options) ? options() : unref(options)\n\n const clonedOptions: UsePrefetchInfiniteQueryOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryKey,\n TPageParam\n > = cloneDeepUnref(resolvedOptions)\n\n if (!client.getQueryState(clonedOptions.queryKey)) {\n void client.infiniteQuery(clonedOptions).then(noop).catch(noop)\n }\n })\n}\n"],"mappings":";;;;;;;;;;;AAoDA,SAAS,SAAY,OAA8C;CACjE,OAAO,OAAO,UAAU;AAC1B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA6CA,SAAgB,yBAOd,SAWA,aACM;CACN,IAAI,QAAQ,IAAI,aAAa,eACvB;MAAA,EAAA,GAACA,SAAAA,gBAAAA,CAAgB,GACnB,QAAQ,KACN,kKACF;CAAA;CAIJ,MAAM,SAAS,eAAeC,uBAAAA,eAAe;CAE7C,CAAA,GAAA,SAAA,YAAA,OAAkB;EAChB,MAAM,kBAAkB,SAAS,OAAO,IAAI,QAAQ,KAAA,GAAIC,SAAAA,MAAAA,CAAM,OAAO;EAErE,MAAM,gBAMFC,cAAAA,eAAe,eAAe;EAElC,IAAI,CAAC,OAAO,cAAc,cAAc,QAAQ,GAC9C,OAAY,cAAc,aAAa,CAAC,CAAC,KAAKC,qBAAAA,IAAI,CAAC,CAAC,MAAMA,qBAAAA,IAAI;CAElE,CAAC;AACH"}
1
+ {"version":3,"file":"usePrefetchInfiniteQuery.cjs","names":["getCurrentScope","useQueryClient","unref","cloneDeepUnref","noop"],"sources":["../../src/usePrefetchInfiniteQuery.ts"],"sourcesContent":["import { noop } from '@tanstack/query-core'\nimport { getCurrentScope, unref, watchEffect } from 'vue-demi'\nimport { useQueryClient } from './useQueryClient'\nimport { cloneDeepUnref } from './utils'\nimport type {\n DefaultError,\n DistributiveOmit,\n InfiniteData,\n InfiniteQueryExecuteOptions,\n QueryKey,\n SkipToken,\n} from '@tanstack/query-core'\nimport type { QueryClient } from './queryClient'\nimport type { MaybeRefDeep, MaybeRefOrGetter } from './types'\n\n/**\n * The options accepted by `usePrefetchInfiniteQuery` — everything you can pass to `queryClient.infiniteQuery`,\n * except that `queryFn` can't be `skipToken`.\n */\nexport type UsePrefetchInfiniteQueryOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryKey extends QueryKey,\n TPageParam,\n> = DistributiveOmit<\n InfiniteQueryExecuteOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryKey,\n TPageParam\n >,\n 'queryFn'\n> & {\n queryFn?: Exclude<\n InfiniteQueryExecuteOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryKey,\n TPageParam\n >['queryFn'],\n SkipToken\n >\n}\n\n/**\n * Checks whether an option was passed as a getter function.\n * @param value - The option value.\n * @returns `true` if `value` is a function.\n */\nfunction isGetter<T>(value: MaybeRefOrGetter<T>): value is () => T {\n return typeof value === 'function'\n}\n\n/**\n * `usePrefetchInfiniteQuery` does not return anything — it fires a prefetch as a reactive side effect, useful\n * for kicking off a fetch ahead of the component that will actually render the data with `useInfiniteQuery`.\n * You can pass everything to `usePrefetchInfiniteQuery` that you can pass to `queryClient.infiniteQuery`,\n * though `queryKey`, `initialPageParam`, and `getNextPageParam` are always required, and `queryFn` is required\n * unless a default query function has been defined.\n *\n * `getNextPageParam` receives both the last page of the infinite list of data and the full array of all pages,\n * as well as pageParam information, and should return a single variable that will be passed to your query\n * function as `context.pageParam`. Return `undefined` or `null` to indicate there is no next page available.\n *\n * The prefetch is skipped if the query already has any cached state — including a `pending`/`error` state left\n * over from a previous attempt — so it won't refetch data that's already there or already in flight. It\n * re-runs whenever a reactive dependency in `options` (built with `infiniteQueryOptions`, for example) changes.\n *\n * Fire this during render, before a suspense boundary that wraps a component using `useInfiniteQuery`'s\n * `suspense()` — see the {@link https://tanstack.com/query/latest/docs/framework/vue/guides/suspense | Suspense guide}.\n * @param options - A `ref`, plain value, or reactive getter resolving to the\n * {@link UsePrefetchInfiniteQueryOptions} to use — everything you can pass to `queryClient.infiniteQuery`.\n * @param queryClient - Use this to use a custom `QueryClient`. Otherwise, the one provided by `VueQueryPlugin`\n * will be used.\n * @example\n * ```vue\n * <script setup lang=\"ts\">\n * import { infiniteQueryOptions, usePrefetchInfiniteQuery } from '@tanstack/vue-query'\n * import Projects from './Projects.vue'\n *\n * const projectsOptions = infiniteQueryOptions({\n * queryKey: ['projects'],\n * queryFn: ({ pageParam }) => fetchProjects(pageParam),\n * initialPageParam: 0,\n * getNextPageParam: (lastPage) => lastPage.nextId,\n * })\n *\n * // Fire the prefetch as soon as this component runs, before `Projects` mounts and calls `useInfiniteQuery`.\n * usePrefetchInfiniteQuery(projectsOptions)\n * </script>\n *\n * <template>\n * <Projects />\n * </template>\n * ```\n */\nexport function usePrefetchInfiniteQuery<\n TQueryFnData = unknown,\n TError = DefaultError,\n TData = InfiniteData<TQueryFnData>,\n TQueryKey extends QueryKey = QueryKey,\n TPageParam = unknown,\n>(\n options: MaybeRefOrGetter<\n MaybeRefDeep<\n UsePrefetchInfiniteQueryOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryKey,\n TPageParam\n >\n >\n >,\n queryClient?: QueryClient,\n): void {\n if (process.env.NODE_ENV === 'development') {\n if (!getCurrentScope()) {\n console.warn(\n 'vue-query composable like \"useQuery()\" should only be used inside a \"setup()\" function or a running effect scope. They might otherwise lead to memory leaks.',\n )\n }\n }\n\n const client = queryClient || useQueryClient()\n\n watchEffect(() => {\n const resolvedOptions = isGetter(options) ? options() : unref(options)\n\n const clonedOptions: UsePrefetchInfiniteQueryOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryKey,\n TPageParam\n > = cloneDeepUnref(resolvedOptions)\n\n if (!client.getQueryState(clonedOptions.queryKey)) {\n void client.infiniteQuery(clonedOptions).then(noop).catch(noop)\n }\n })\n}\n"],"mappings":";;;;;;;;;;;AAoDA,SAAS,SAAY,OAA8C;CACjE,OAAO,OAAO,UAAU;AAC1B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA6CA,SAAgB,yBAOd,SAWA,aACM;CACN,IAAI,QAAQ,IAAI,aAAa,eACvB;MAAA,EAAA,GAACA,SAAAA,gBAAAA,CAAgB,GACnB,QAAQ,KACN,kKACF;CAAA;CAIJ,MAAM,SAAS,eAAeC,uBAAAA,eAAe;CAE7C,CAAA,GAAA,SAAA,YAAA,OAAkB;EAChB,MAAM,kBAAkB,SAAS,OAAO,IAAI,QAAQ,KAAA,GAAIC,SAAAA,MAAAA,CAAM,OAAO;EAErE,MAAM,gBAMFC,cAAAA,eAAe,eAAe;EAElC,IAAI,CAAC,OAAO,cAAc,cAAc,QAAQ,GAC9C,OAAY,cAAc,aAAa,CAAC,CAAC,KAAKC,qBAAAA,IAAI,CAAC,CAAC,MAAMA,qBAAAA,IAAI;CAElE,CAAC;AACH"}
@@ -1,5 +1,5 @@
1
1
  import { o as MaybeRefDeep, s as MaybeRefOrGetter } from "./types-u_Tu5Ybs.cjs";
2
- import { t as QueryClient$1 } from "./queryClient-BGn8uIej.cjs";
2
+ import { t as QueryClient$1 } from "./queryClient-yJW8K_VP.cjs";
3
3
  import { DefaultError, DistributiveOmit, InfiniteData, InfiniteQueryExecuteOptions, QueryKey, SkipToken } from "@tanstack/query-core";
4
4
  /**
5
5
  * The options accepted by `usePrefetchInfiniteQuery` — everything you can pass to `queryClient.infiniteQuery`,
@@ -1,5 +1,5 @@
1
1
  import { o as MaybeRefDeep, s as MaybeRefOrGetter } from "./types-u_Tu5Ybs.js";
2
- import { t as QueryClient$1 } from "./queryClient-Ba4HSFnn.js";
2
+ import { t as QueryClient$1 } from "./queryClient-6AWIHAhP.js";
3
3
  import { DefaultError, DistributiveOmit, InfiniteData, InfiniteQueryExecuteOptions, QueryKey, SkipToken } from "@tanstack/query-core";
4
4
  /**
5
5
  * The options accepted by `usePrefetchInfiniteQuery` — everything you can pass to `queryClient.infiniteQuery`,
@@ -1 +1 @@
1
- {"version":3,"file":"usePrefetchInfiniteQuery.js","names":[],"sources":["../../src/usePrefetchInfiniteQuery.ts"],"sourcesContent":["import { getCurrentScope, unref, watchEffect } from 'vue-demi'\nimport { noop } from '@tanstack/query-core'\nimport { useQueryClient } from './useQueryClient'\nimport { cloneDeepUnref } from './utils'\nimport type {\n DefaultError,\n DistributiveOmit,\n InfiniteData,\n InfiniteQueryExecuteOptions,\n QueryKey,\n SkipToken,\n} from '@tanstack/query-core'\nimport type { QueryClient } from './queryClient'\nimport type { MaybeRefDeep, MaybeRefOrGetter } from './types'\n\n/**\n * The options accepted by `usePrefetchInfiniteQuery` — everything you can pass to `queryClient.infiniteQuery`,\n * except that `queryFn` can't be `skipToken`.\n */\nexport type UsePrefetchInfiniteQueryOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryKey extends QueryKey,\n TPageParam,\n> = DistributiveOmit<\n InfiniteQueryExecuteOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryKey,\n TPageParam\n >,\n 'queryFn'\n> & {\n queryFn?: Exclude<\n InfiniteQueryExecuteOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryKey,\n TPageParam\n >['queryFn'],\n SkipToken\n >\n}\n\n/**\n * Checks whether an option was passed as a getter function.\n * @param value - The option value.\n * @returns `true` if `value` is a function.\n */\nfunction isGetter<T>(value: MaybeRefOrGetter<T>): value is () => T {\n return typeof value === 'function'\n}\n\n/**\n * `usePrefetchInfiniteQuery` does not return anything — it fires a prefetch as a reactive side effect, useful\n * for kicking off a fetch ahead of the component that will actually render the data with `useInfiniteQuery`.\n * You can pass everything to `usePrefetchInfiniteQuery` that you can pass to `queryClient.infiniteQuery`,\n * though `queryKey`, `initialPageParam`, and `getNextPageParam` are always required, and `queryFn` is required\n * unless a default query function has been defined.\n *\n * `getNextPageParam` receives both the last page of the infinite list of data and the full array of all pages,\n * as well as pageParam information, and should return a single variable that will be passed to your query\n * function as `context.pageParam`. Return `undefined` or `null` to indicate there is no next page available.\n *\n * The prefetch is skipped if the query already has any cached state — including a `pending`/`error` state left\n * over from a previous attempt — so it won't refetch data that's already there or already in flight. It\n * re-runs whenever a reactive dependency in `options` (built with `infiniteQueryOptions`, for example) changes.\n *\n * Fire this during render, before a suspense boundary that wraps a component using `useInfiniteQuery`'s\n * `suspense()` — see the {@link https://tanstack.com/query/latest/docs/framework/vue/guides/suspense | Suspense guide}.\n * @param options - A `ref`, plain value, or reactive getter resolving to the\n * {@link UsePrefetchInfiniteQueryOptions} to use — everything you can pass to `queryClient.infiniteQuery`.\n * @param queryClient - Use this to use a custom `QueryClient`. Otherwise, the one provided by `VueQueryPlugin`\n * will be used.\n * @example\n * ```vue\n * <script setup lang=\"ts\">\n * import { infiniteQueryOptions, usePrefetchInfiniteQuery } from '@tanstack/vue-query'\n * import Projects from './Projects.vue'\n *\n * const projectsOptions = infiniteQueryOptions({\n * queryKey: ['projects'],\n * queryFn: ({ pageParam }) => fetchProjects(pageParam),\n * initialPageParam: 0,\n * getNextPageParam: (lastPage) => lastPage.nextId,\n * })\n *\n * // Fire the prefetch as soon as this component runs, before `Projects` mounts and calls `useInfiniteQuery`.\n * usePrefetchInfiniteQuery(projectsOptions)\n * </script>\n *\n * <template>\n * <Projects />\n * </template>\n * ```\n */\nexport function usePrefetchInfiniteQuery<\n TQueryFnData = unknown,\n TError = DefaultError,\n TData = InfiniteData<TQueryFnData>,\n TQueryKey extends QueryKey = QueryKey,\n TPageParam = unknown,\n>(\n options: MaybeRefOrGetter<\n MaybeRefDeep<\n UsePrefetchInfiniteQueryOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryKey,\n TPageParam\n >\n >\n >,\n queryClient?: QueryClient,\n): void {\n if (process.env.NODE_ENV === 'development') {\n if (!getCurrentScope()) {\n console.warn(\n 'vue-query composable like \"useQuery()\" should only be used inside a \"setup()\" function or a running effect scope. They might otherwise lead to memory leaks.',\n )\n }\n }\n\n const client = queryClient || useQueryClient()\n\n watchEffect(() => {\n const resolvedOptions = isGetter(options) ? options() : unref(options)\n\n const clonedOptions: UsePrefetchInfiniteQueryOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryKey,\n TPageParam\n > = cloneDeepUnref(resolvedOptions)\n\n if (!client.getQueryState(clonedOptions.queryKey)) {\n void client.infiniteQuery(clonedOptions).then(noop).catch(noop)\n }\n })\n}\n"],"mappings":";;;;;;;;;;AAoDA,SAAS,SAAY,OAA8C;CACjE,OAAO,OAAO,UAAU;AAC1B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA6CA,SAAgB,yBAOd,SAWA,aACM;CACN,IAAI,QAAQ,IAAI,aAAa,eACvB;MAAA,CAAC,gBAAgB,GACnB,QAAQ,KACN,kKACF;CAAA;CAIJ,MAAM,SAAS,eAAe,eAAe;CAE7C,kBAAkB;EAChB,MAAM,kBAAkB,SAAS,OAAO,IAAI,QAAQ,IAAI,MAAM,OAAO;EAErE,MAAM,gBAMF,eAAe,eAAe;EAElC,IAAI,CAAC,OAAO,cAAc,cAAc,QAAQ,GAC9C,OAAY,cAAc,aAAa,CAAC,CAAC,KAAK,IAAI,CAAC,CAAC,MAAM,IAAI;CAElE,CAAC;AACH"}
1
+ {"version":3,"file":"usePrefetchInfiniteQuery.js","names":[],"sources":["../../src/usePrefetchInfiniteQuery.ts"],"sourcesContent":["import { noop } from '@tanstack/query-core'\nimport { getCurrentScope, unref, watchEffect } from 'vue-demi'\nimport { useQueryClient } from './useQueryClient'\nimport { cloneDeepUnref } from './utils'\nimport type {\n DefaultError,\n DistributiveOmit,\n InfiniteData,\n InfiniteQueryExecuteOptions,\n QueryKey,\n SkipToken,\n} from '@tanstack/query-core'\nimport type { QueryClient } from './queryClient'\nimport type { MaybeRefDeep, MaybeRefOrGetter } from './types'\n\n/**\n * The options accepted by `usePrefetchInfiniteQuery` — everything you can pass to `queryClient.infiniteQuery`,\n * except that `queryFn` can't be `skipToken`.\n */\nexport type UsePrefetchInfiniteQueryOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryKey extends QueryKey,\n TPageParam,\n> = DistributiveOmit<\n InfiniteQueryExecuteOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryKey,\n TPageParam\n >,\n 'queryFn'\n> & {\n queryFn?: Exclude<\n InfiniteQueryExecuteOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryKey,\n TPageParam\n >['queryFn'],\n SkipToken\n >\n}\n\n/**\n * Checks whether an option was passed as a getter function.\n * @param value - The option value.\n * @returns `true` if `value` is a function.\n */\nfunction isGetter<T>(value: MaybeRefOrGetter<T>): value is () => T {\n return typeof value === 'function'\n}\n\n/**\n * `usePrefetchInfiniteQuery` does not return anything — it fires a prefetch as a reactive side effect, useful\n * for kicking off a fetch ahead of the component that will actually render the data with `useInfiniteQuery`.\n * You can pass everything to `usePrefetchInfiniteQuery` that you can pass to `queryClient.infiniteQuery`,\n * though `queryKey`, `initialPageParam`, and `getNextPageParam` are always required, and `queryFn` is required\n * unless a default query function has been defined.\n *\n * `getNextPageParam` receives both the last page of the infinite list of data and the full array of all pages,\n * as well as pageParam information, and should return a single variable that will be passed to your query\n * function as `context.pageParam`. Return `undefined` or `null` to indicate there is no next page available.\n *\n * The prefetch is skipped if the query already has any cached state — including a `pending`/`error` state left\n * over from a previous attempt — so it won't refetch data that's already there or already in flight. It\n * re-runs whenever a reactive dependency in `options` (built with `infiniteQueryOptions`, for example) changes.\n *\n * Fire this during render, before a suspense boundary that wraps a component using `useInfiniteQuery`'s\n * `suspense()` — see the {@link https://tanstack.com/query/latest/docs/framework/vue/guides/suspense | Suspense guide}.\n * @param options - A `ref`, plain value, or reactive getter resolving to the\n * {@link UsePrefetchInfiniteQueryOptions} to use — everything you can pass to `queryClient.infiniteQuery`.\n * @param queryClient - Use this to use a custom `QueryClient`. Otherwise, the one provided by `VueQueryPlugin`\n * will be used.\n * @example\n * ```vue\n * <script setup lang=\"ts\">\n * import { infiniteQueryOptions, usePrefetchInfiniteQuery } from '@tanstack/vue-query'\n * import Projects from './Projects.vue'\n *\n * const projectsOptions = infiniteQueryOptions({\n * queryKey: ['projects'],\n * queryFn: ({ pageParam }) => fetchProjects(pageParam),\n * initialPageParam: 0,\n * getNextPageParam: (lastPage) => lastPage.nextId,\n * })\n *\n * // Fire the prefetch as soon as this component runs, before `Projects` mounts and calls `useInfiniteQuery`.\n * usePrefetchInfiniteQuery(projectsOptions)\n * </script>\n *\n * <template>\n * <Projects />\n * </template>\n * ```\n */\nexport function usePrefetchInfiniteQuery<\n TQueryFnData = unknown,\n TError = DefaultError,\n TData = InfiniteData<TQueryFnData>,\n TQueryKey extends QueryKey = QueryKey,\n TPageParam = unknown,\n>(\n options: MaybeRefOrGetter<\n MaybeRefDeep<\n UsePrefetchInfiniteQueryOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryKey,\n TPageParam\n >\n >\n >,\n queryClient?: QueryClient,\n): void {\n if (process.env.NODE_ENV === 'development') {\n if (!getCurrentScope()) {\n console.warn(\n 'vue-query composable like \"useQuery()\" should only be used inside a \"setup()\" function or a running effect scope. They might otherwise lead to memory leaks.',\n )\n }\n }\n\n const client = queryClient || useQueryClient()\n\n watchEffect(() => {\n const resolvedOptions = isGetter(options) ? options() : unref(options)\n\n const clonedOptions: UsePrefetchInfiniteQueryOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryKey,\n TPageParam\n > = cloneDeepUnref(resolvedOptions)\n\n if (!client.getQueryState(clonedOptions.queryKey)) {\n void client.infiniteQuery(clonedOptions).then(noop).catch(noop)\n }\n })\n}\n"],"mappings":";;;;;;;;;;AAoDA,SAAS,SAAY,OAA8C;CACjE,OAAO,OAAO,UAAU;AAC1B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA6CA,SAAgB,yBAOd,SAWA,aACM;CACN,IAAI,QAAQ,IAAI,aAAa,eACvB;MAAA,CAAC,gBAAgB,GACnB,QAAQ,KACN,kKACF;CAAA;CAIJ,MAAM,SAAS,eAAe,eAAe;CAE7C,kBAAkB;EAChB,MAAM,kBAAkB,SAAS,OAAO,IAAI,QAAQ,IAAI,MAAM,OAAO;EAErE,MAAM,gBAMF,eAAe,eAAe;EAElC,IAAI,CAAC,OAAO,cAAc,cAAc,QAAQ,GAC9C,OAAY,cAAc,aAAa,CAAC,CAAC,KAAK,IAAI,CAAC,CAAC,MAAM,IAAI;CAElE,CAAC;AACH"}
@@ -1 +1 @@
1
- {"version":3,"file":"usePrefetchQuery.cjs","names":["getCurrentScope","useQueryClient","unref","cloneDeepUnref","noop"],"sources":["../../src/usePrefetchQuery.ts"],"sourcesContent":["import { getCurrentScope, unref, watchEffect } from 'vue-demi'\nimport { noop } from '@tanstack/query-core'\nimport { useQueryClient } from './useQueryClient'\nimport { cloneDeepUnref } from './utils'\nimport type {\n DefaultError,\n OmitKeyof,\n QueryExecuteOptions,\n QueryKey,\n SkipToken,\n} from '@tanstack/query-core'\nimport type { QueryClient } from './queryClient'\nimport type { MaybeRefDeep, MaybeRefOrGetter } from './types'\n\n/**\n * The options accepted by `usePrefetchQuery` — everything you can pass to `queryClient.query`, except that\n * `queryFn` can't be `skipToken`.\n */\nexport type UsePrefetchQueryOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryData,\n TQueryKey extends QueryKey,\n> = OmitKeyof<\n QueryExecuteOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryData,\n TQueryKey,\n never\n >,\n 'queryFn'\n> & {\n queryFn?: Exclude<\n QueryExecuteOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryData,\n TQueryKey,\n never\n >['queryFn'],\n SkipToken\n >\n}\n\n/**\n * Checks whether an option was passed as a getter function.\n * @param value - The option value.\n * @returns `true` if `value` is a function.\n */\nfunction isGetter<T>(value: MaybeRefOrGetter<T>): value is () => T {\n return typeof value === 'function'\n}\n\n/**\n * `usePrefetchQuery` does not return anything — it fires a prefetch as a reactive side effect, useful for\n * kicking off a fetch ahead of the component that will actually render the data with `useQuery`. You can pass\n * everything to `usePrefetchQuery` that you can pass to `queryClient.query`, though `queryKey` is always\n * required, and `queryFn` is required unless a default query function has been defined.\n *\n * The prefetch is skipped if the query already has any cached state — including a `pending`/`error` state left\n * over from a previous attempt — so it won't refetch data that's already there or already in flight. It\n * re-runs whenever a reactive dependency in `options` (built with `queryOptions`, for example) changes.\n *\n * Fire this during render, before a suspense boundary that wraps a component using `useQuery`'s `suspense()`\n * — see the {@link https://tanstack.com/query/latest/docs/framework/vue/guides/suspense | Suspense guide}.\n * @param options - A `ref`, plain value, or reactive getter resolving to the {@link UsePrefetchQueryOptions} to\n * use — everything you can pass to `queryClient.query`.\n * @param queryClient - Use this to use a custom `QueryClient`. Otherwise, the one provided by `VueQueryPlugin`\n * will be used.\n * @example\n * ```vue\n * <script setup lang=\"ts\">\n * import { usePrefetchQuery } from '@tanstack/vue-query'\n * import Posts from './Posts.vue'\n *\n * // Fire the prefetch as soon as this component runs, before `Posts` mounts and calls `useQuery`.\n * usePrefetchQuery({\n * queryKey: ['posts'],\n * queryFn: fetchPosts,\n * })\n * </script>\n *\n * <template>\n * <Posts />\n * </template>\n * ```\n */\nexport function usePrefetchQuery<\n TQueryFnData = unknown,\n TError = DefaultError,\n TData = TQueryFnData,\n TQueryData = TQueryFnData,\n TQueryKey extends QueryKey = QueryKey,\n>(\n options: MaybeRefOrGetter<\n MaybeRefDeep<\n UsePrefetchQueryOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryData,\n TQueryKey\n >\n >\n >,\n queryClient?: QueryClient,\n): void {\n if (process.env.NODE_ENV === 'development') {\n if (!getCurrentScope()) {\n console.warn(\n 'vue-query composable like \"useQuery()\" should only be used inside a \"setup()\" function or a running effect scope. They might otherwise lead to memory leaks.',\n )\n }\n }\n\n const client = queryClient || useQueryClient()\n\n watchEffect(() => {\n const resolvedOptions = isGetter(options) ? options() : unref(options)\n const clonedOptions: UsePrefetchQueryOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryData,\n TQueryKey\n > = cloneDeepUnref(resolvedOptions)\n\n if (!client.getQueryState(clonedOptions.queryKey)) {\n void client.query(clonedOptions).catch(noop)\n }\n })\n}\n"],"mappings":";;;;;;;;;;;AAqDA,SAAS,SAAY,OAA8C;CACjE,OAAO,OAAO,UAAU;AAC1B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAoCA,SAAgB,iBAOd,SAWA,aACM;CACN,IAAI,QAAQ,IAAI,aAAa,eACvB;MAAA,EAAA,GAACA,SAAAA,gBAAAA,CAAgB,GACnB,QAAQ,KACN,kKACF;CAAA;CAIJ,MAAM,SAAS,eAAeC,uBAAAA,eAAe;CAE7C,CAAA,GAAA,SAAA,YAAA,OAAkB;EAChB,MAAM,kBAAkB,SAAS,OAAO,IAAI,QAAQ,KAAA,GAAIC,SAAAA,MAAAA,CAAM,OAAO;EACrE,MAAM,gBAMFC,cAAAA,eAAe,eAAe;EAElC,IAAI,CAAC,OAAO,cAAc,cAAc,QAAQ,GAC9C,OAAY,MAAM,aAAa,CAAC,CAAC,MAAMC,qBAAAA,IAAI;CAE/C,CAAC;AACH"}
1
+ {"version":3,"file":"usePrefetchQuery.cjs","names":["getCurrentScope","useQueryClient","unref","cloneDeepUnref","noop"],"sources":["../../src/usePrefetchQuery.ts"],"sourcesContent":["import { noop } from '@tanstack/query-core'\nimport { getCurrentScope, unref, watchEffect } from 'vue-demi'\nimport { useQueryClient } from './useQueryClient'\nimport { cloneDeepUnref } from './utils'\nimport type {\n DefaultError,\n OmitKeyof,\n QueryExecuteOptions,\n QueryKey,\n SkipToken,\n} from '@tanstack/query-core'\nimport type { QueryClient } from './queryClient'\nimport type { MaybeRefDeep, MaybeRefOrGetter } from './types'\n\n/**\n * The options accepted by `usePrefetchQuery` — everything you can pass to `queryClient.query`, except that\n * `queryFn` can't be `skipToken`.\n */\nexport type UsePrefetchQueryOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryData,\n TQueryKey extends QueryKey,\n> = OmitKeyof<\n QueryExecuteOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryData,\n TQueryKey,\n never\n >,\n 'queryFn'\n> & {\n queryFn?: Exclude<\n QueryExecuteOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryData,\n TQueryKey,\n never\n >['queryFn'],\n SkipToken\n >\n}\n\n/**\n * Checks whether an option was passed as a getter function.\n * @param value - The option value.\n * @returns `true` if `value` is a function.\n */\nfunction isGetter<T>(value: MaybeRefOrGetter<T>): value is () => T {\n return typeof value === 'function'\n}\n\n/**\n * `usePrefetchQuery` does not return anything — it fires a prefetch as a reactive side effect, useful for\n * kicking off a fetch ahead of the component that will actually render the data with `useQuery`. You can pass\n * everything to `usePrefetchQuery` that you can pass to `queryClient.query`, though `queryKey` is always\n * required, and `queryFn` is required unless a default query function has been defined.\n *\n * The prefetch is skipped if the query already has any cached state — including a `pending`/`error` state left\n * over from a previous attempt — so it won't refetch data that's already there or already in flight. It\n * re-runs whenever a reactive dependency in `options` (built with `queryOptions`, for example) changes.\n *\n * Fire this during render, before a suspense boundary that wraps a component using `useQuery`'s `suspense()`\n * — see the {@link https://tanstack.com/query/latest/docs/framework/vue/guides/suspense | Suspense guide}.\n * @param options - A `ref`, plain value, or reactive getter resolving to the {@link UsePrefetchQueryOptions} to\n * use — everything you can pass to `queryClient.query`.\n * @param queryClient - Use this to use a custom `QueryClient`. Otherwise, the one provided by `VueQueryPlugin`\n * will be used.\n * @example\n * ```vue\n * <script setup lang=\"ts\">\n * import { usePrefetchQuery } from '@tanstack/vue-query'\n * import Posts from './Posts.vue'\n *\n * // Fire the prefetch as soon as this component runs, before `Posts` mounts and calls `useQuery`.\n * usePrefetchQuery({\n * queryKey: ['posts'],\n * queryFn: fetchPosts,\n * })\n * </script>\n *\n * <template>\n * <Posts />\n * </template>\n * ```\n */\nexport function usePrefetchQuery<\n TQueryFnData = unknown,\n TError = DefaultError,\n TData = TQueryFnData,\n TQueryData = TQueryFnData,\n TQueryKey extends QueryKey = QueryKey,\n>(\n options: MaybeRefOrGetter<\n MaybeRefDeep<\n UsePrefetchQueryOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryData,\n TQueryKey\n >\n >\n >,\n queryClient?: QueryClient,\n): void {\n if (process.env.NODE_ENV === 'development') {\n if (!getCurrentScope()) {\n console.warn(\n 'vue-query composable like \"useQuery()\" should only be used inside a \"setup()\" function or a running effect scope. They might otherwise lead to memory leaks.',\n )\n }\n }\n\n const client = queryClient || useQueryClient()\n\n watchEffect(() => {\n const resolvedOptions = isGetter(options) ? options() : unref(options)\n const clonedOptions: UsePrefetchQueryOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryData,\n TQueryKey\n > = cloneDeepUnref(resolvedOptions)\n\n if (!client.getQueryState(clonedOptions.queryKey)) {\n void client.query(clonedOptions).catch(noop)\n }\n })\n}\n"],"mappings":";;;;;;;;;;;AAqDA,SAAS,SAAY,OAA8C;CACjE,OAAO,OAAO,UAAU;AAC1B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAoCA,SAAgB,iBAOd,SAWA,aACM;CACN,IAAI,QAAQ,IAAI,aAAa,eACvB;MAAA,EAAA,GAACA,SAAAA,gBAAAA,CAAgB,GACnB,QAAQ,KACN,kKACF;CAAA;CAIJ,MAAM,SAAS,eAAeC,uBAAAA,eAAe;CAE7C,CAAA,GAAA,SAAA,YAAA,OAAkB;EAChB,MAAM,kBAAkB,SAAS,OAAO,IAAI,QAAQ,KAAA,GAAIC,SAAAA,MAAAA,CAAM,OAAO;EACrE,MAAM,gBAMFC,cAAAA,eAAe,eAAe;EAElC,IAAI,CAAC,OAAO,cAAc,cAAc,QAAQ,GAC9C,OAAY,MAAM,aAAa,CAAC,CAAC,MAAMC,qBAAAA,IAAI;CAE/C,CAAC;AACH"}
@@ -1,5 +1,5 @@
1
1
  import { o as MaybeRefDeep, s as MaybeRefOrGetter } from "./types-u_Tu5Ybs.cjs";
2
- import { t as QueryClient$1 } from "./queryClient-BGn8uIej.cjs";
2
+ import { t as QueryClient$1 } from "./queryClient-yJW8K_VP.cjs";
3
3
  import { DefaultError, OmitKeyof, QueryExecuteOptions, QueryKey, SkipToken } from "@tanstack/query-core";
4
4
  /**
5
5
  * The options accepted by `usePrefetchQuery` — everything you can pass to `queryClient.query`, except that
@@ -1,5 +1,5 @@
1
1
  import { o as MaybeRefDeep, s as MaybeRefOrGetter } from "./types-u_Tu5Ybs.js";
2
- import { t as QueryClient$1 } from "./queryClient-Ba4HSFnn.js";
2
+ import { t as QueryClient$1 } from "./queryClient-6AWIHAhP.js";
3
3
  import { DefaultError, OmitKeyof, QueryExecuteOptions, QueryKey, SkipToken } from "@tanstack/query-core";
4
4
  /**
5
5
  * The options accepted by `usePrefetchQuery` — everything you can pass to `queryClient.query`, except that
@@ -1 +1 @@
1
- {"version":3,"file":"usePrefetchQuery.js","names":[],"sources":["../../src/usePrefetchQuery.ts"],"sourcesContent":["import { getCurrentScope, unref, watchEffect } from 'vue-demi'\nimport { noop } from '@tanstack/query-core'\nimport { useQueryClient } from './useQueryClient'\nimport { cloneDeepUnref } from './utils'\nimport type {\n DefaultError,\n OmitKeyof,\n QueryExecuteOptions,\n QueryKey,\n SkipToken,\n} from '@tanstack/query-core'\nimport type { QueryClient } from './queryClient'\nimport type { MaybeRefDeep, MaybeRefOrGetter } from './types'\n\n/**\n * The options accepted by `usePrefetchQuery` — everything you can pass to `queryClient.query`, except that\n * `queryFn` can't be `skipToken`.\n */\nexport type UsePrefetchQueryOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryData,\n TQueryKey extends QueryKey,\n> = OmitKeyof<\n QueryExecuteOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryData,\n TQueryKey,\n never\n >,\n 'queryFn'\n> & {\n queryFn?: Exclude<\n QueryExecuteOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryData,\n TQueryKey,\n never\n >['queryFn'],\n SkipToken\n >\n}\n\n/**\n * Checks whether an option was passed as a getter function.\n * @param value - The option value.\n * @returns `true` if `value` is a function.\n */\nfunction isGetter<T>(value: MaybeRefOrGetter<T>): value is () => T {\n return typeof value === 'function'\n}\n\n/**\n * `usePrefetchQuery` does not return anything — it fires a prefetch as a reactive side effect, useful for\n * kicking off a fetch ahead of the component that will actually render the data with `useQuery`. You can pass\n * everything to `usePrefetchQuery` that you can pass to `queryClient.query`, though `queryKey` is always\n * required, and `queryFn` is required unless a default query function has been defined.\n *\n * The prefetch is skipped if the query already has any cached state — including a `pending`/`error` state left\n * over from a previous attempt — so it won't refetch data that's already there or already in flight. It\n * re-runs whenever a reactive dependency in `options` (built with `queryOptions`, for example) changes.\n *\n * Fire this during render, before a suspense boundary that wraps a component using `useQuery`'s `suspense()`\n * — see the {@link https://tanstack.com/query/latest/docs/framework/vue/guides/suspense | Suspense guide}.\n * @param options - A `ref`, plain value, or reactive getter resolving to the {@link UsePrefetchQueryOptions} to\n * use — everything you can pass to `queryClient.query`.\n * @param queryClient - Use this to use a custom `QueryClient`. Otherwise, the one provided by `VueQueryPlugin`\n * will be used.\n * @example\n * ```vue\n * <script setup lang=\"ts\">\n * import { usePrefetchQuery } from '@tanstack/vue-query'\n * import Posts from './Posts.vue'\n *\n * // Fire the prefetch as soon as this component runs, before `Posts` mounts and calls `useQuery`.\n * usePrefetchQuery({\n * queryKey: ['posts'],\n * queryFn: fetchPosts,\n * })\n * </script>\n *\n * <template>\n * <Posts />\n * </template>\n * ```\n */\nexport function usePrefetchQuery<\n TQueryFnData = unknown,\n TError = DefaultError,\n TData = TQueryFnData,\n TQueryData = TQueryFnData,\n TQueryKey extends QueryKey = QueryKey,\n>(\n options: MaybeRefOrGetter<\n MaybeRefDeep<\n UsePrefetchQueryOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryData,\n TQueryKey\n >\n >\n >,\n queryClient?: QueryClient,\n): void {\n if (process.env.NODE_ENV === 'development') {\n if (!getCurrentScope()) {\n console.warn(\n 'vue-query composable like \"useQuery()\" should only be used inside a \"setup()\" function or a running effect scope. They might otherwise lead to memory leaks.',\n )\n }\n }\n\n const client = queryClient || useQueryClient()\n\n watchEffect(() => {\n const resolvedOptions = isGetter(options) ? options() : unref(options)\n const clonedOptions: UsePrefetchQueryOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryData,\n TQueryKey\n > = cloneDeepUnref(resolvedOptions)\n\n if (!client.getQueryState(clonedOptions.queryKey)) {\n void client.query(clonedOptions).catch(noop)\n }\n })\n}\n"],"mappings":";;;;;;;;;;AAqDA,SAAS,SAAY,OAA8C;CACjE,OAAO,OAAO,UAAU;AAC1B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAoCA,SAAgB,iBAOd,SAWA,aACM;CACN,IAAI,QAAQ,IAAI,aAAa,eACvB;MAAA,CAAC,gBAAgB,GACnB,QAAQ,KACN,kKACF;CAAA;CAIJ,MAAM,SAAS,eAAe,eAAe;CAE7C,kBAAkB;EAChB,MAAM,kBAAkB,SAAS,OAAO,IAAI,QAAQ,IAAI,MAAM,OAAO;EACrE,MAAM,gBAMF,eAAe,eAAe;EAElC,IAAI,CAAC,OAAO,cAAc,cAAc,QAAQ,GAC9C,OAAY,MAAM,aAAa,CAAC,CAAC,MAAM,IAAI;CAE/C,CAAC;AACH"}
1
+ {"version":3,"file":"usePrefetchQuery.js","names":[],"sources":["../../src/usePrefetchQuery.ts"],"sourcesContent":["import { noop } from '@tanstack/query-core'\nimport { getCurrentScope, unref, watchEffect } from 'vue-demi'\nimport { useQueryClient } from './useQueryClient'\nimport { cloneDeepUnref } from './utils'\nimport type {\n DefaultError,\n OmitKeyof,\n QueryExecuteOptions,\n QueryKey,\n SkipToken,\n} from '@tanstack/query-core'\nimport type { QueryClient } from './queryClient'\nimport type { MaybeRefDeep, MaybeRefOrGetter } from './types'\n\n/**\n * The options accepted by `usePrefetchQuery` — everything you can pass to `queryClient.query`, except that\n * `queryFn` can't be `skipToken`.\n */\nexport type UsePrefetchQueryOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryData,\n TQueryKey extends QueryKey,\n> = OmitKeyof<\n QueryExecuteOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryData,\n TQueryKey,\n never\n >,\n 'queryFn'\n> & {\n queryFn?: Exclude<\n QueryExecuteOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryData,\n TQueryKey,\n never\n >['queryFn'],\n SkipToken\n >\n}\n\n/**\n * Checks whether an option was passed as a getter function.\n * @param value - The option value.\n * @returns `true` if `value` is a function.\n */\nfunction isGetter<T>(value: MaybeRefOrGetter<T>): value is () => T {\n return typeof value === 'function'\n}\n\n/**\n * `usePrefetchQuery` does not return anything — it fires a prefetch as a reactive side effect, useful for\n * kicking off a fetch ahead of the component that will actually render the data with `useQuery`. You can pass\n * everything to `usePrefetchQuery` that you can pass to `queryClient.query`, though `queryKey` is always\n * required, and `queryFn` is required unless a default query function has been defined.\n *\n * The prefetch is skipped if the query already has any cached state — including a `pending`/`error` state left\n * over from a previous attempt — so it won't refetch data that's already there or already in flight. It\n * re-runs whenever a reactive dependency in `options` (built with `queryOptions`, for example) changes.\n *\n * Fire this during render, before a suspense boundary that wraps a component using `useQuery`'s `suspense()`\n * — see the {@link https://tanstack.com/query/latest/docs/framework/vue/guides/suspense | Suspense guide}.\n * @param options - A `ref`, plain value, or reactive getter resolving to the {@link UsePrefetchQueryOptions} to\n * use — everything you can pass to `queryClient.query`.\n * @param queryClient - Use this to use a custom `QueryClient`. Otherwise, the one provided by `VueQueryPlugin`\n * will be used.\n * @example\n * ```vue\n * <script setup lang=\"ts\">\n * import { usePrefetchQuery } from '@tanstack/vue-query'\n * import Posts from './Posts.vue'\n *\n * // Fire the prefetch as soon as this component runs, before `Posts` mounts and calls `useQuery`.\n * usePrefetchQuery({\n * queryKey: ['posts'],\n * queryFn: fetchPosts,\n * })\n * </script>\n *\n * <template>\n * <Posts />\n * </template>\n * ```\n */\nexport function usePrefetchQuery<\n TQueryFnData = unknown,\n TError = DefaultError,\n TData = TQueryFnData,\n TQueryData = TQueryFnData,\n TQueryKey extends QueryKey = QueryKey,\n>(\n options: MaybeRefOrGetter<\n MaybeRefDeep<\n UsePrefetchQueryOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryData,\n TQueryKey\n >\n >\n >,\n queryClient?: QueryClient,\n): void {\n if (process.env.NODE_ENV === 'development') {\n if (!getCurrentScope()) {\n console.warn(\n 'vue-query composable like \"useQuery()\" should only be used inside a \"setup()\" function or a running effect scope. They might otherwise lead to memory leaks.',\n )\n }\n }\n\n const client = queryClient || useQueryClient()\n\n watchEffect(() => {\n const resolvedOptions = isGetter(options) ? options() : unref(options)\n const clonedOptions: UsePrefetchQueryOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryData,\n TQueryKey\n > = cloneDeepUnref(resolvedOptions)\n\n if (!client.getQueryState(clonedOptions.queryKey)) {\n void client.query(clonedOptions).catch(noop)\n }\n })\n}\n"],"mappings":";;;;;;;;;;AAqDA,SAAS,SAAY,OAA8C;CACjE,OAAO,OAAO,UAAU;AAC1B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAoCA,SAAgB,iBAOd,SAWA,aACM;CACN,IAAI,QAAQ,IAAI,aAAa,eACvB;MAAA,CAAC,gBAAgB,GACnB,QAAQ,KACN,kKACF;CAAA;CAIJ,MAAM,SAAS,eAAe,eAAe;CAE7C,kBAAkB;EAChB,MAAM,kBAAkB,SAAS,OAAO,IAAI,QAAQ,IAAI,MAAM,OAAO;EACrE,MAAM,gBAMF,eAAe,eAAe;EAElC,IAAI,CAAC,OAAO,cAAc,cAAc,QAAQ,GAC9C,OAAY,MAAM,aAAa,CAAC,CAAC,MAAM,IAAI;CAE/C,CAAC;AACH"}
@@ -133,7 +133,7 @@ function useQueries({ queries, ...options }, queryClient) {
133
133
  const resolvedQueries = typeof queries === "function" ? queries() : queries;
134
134
  return (0, vue_demi.unref)(resolvedQueries).map((queryOptions) => {
135
135
  const clonedOptions = require_utils.cloneDeepUnref(queryOptions);
136
- if (typeof clonedOptions.enabled === "function") clonedOptions.enabled = queryOptions.enabled();
136
+ if (typeof clonedOptions.enabled === "function" && clonedOptions.enabled.length === 0) clonedOptions.enabled = clonedOptions.enabled();
137
137
  const defaulted = client.defaultQueryOptions(clonedOptions);
138
138
  defaulted._optimisticResults = client.isRestoring?.value ? "isRestoring" : "optimistic";
139
139
  return defaulted;