@tanstack/vue-query 5.104.1 → 5.104.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 (343) hide show
  1. package/build/legacy/devtools/devtools.cjs +6 -0
  2. package/build/legacy/devtools/devtools.cjs.map +1 -1
  3. package/build/legacy/devtools/devtools.d.cts +7 -1
  4. package/build/legacy/devtools/devtools.d.cts.map +1 -1
  5. package/build/legacy/devtools/devtools.d.ts +7 -1
  6. package/build/legacy/devtools/devtools.d.ts.map +1 -1
  7. package/build/legacy/devtools/devtools.js +6 -0
  8. package/build/legacy/devtools/devtools.js.map +1 -1
  9. package/build/legacy/devtools/utils.cjs +21 -0
  10. package/build/legacy/devtools/utils.cjs.map +1 -1
  11. package/build/legacy/devtools/utils.d.cts +21 -0
  12. package/build/legacy/devtools/utils.d.cts.map +1 -1
  13. package/build/legacy/devtools/utils.d.ts +21 -0
  14. package/build/legacy/devtools/utils.d.ts.map +1 -1
  15. package/build/legacy/devtools/utils.js +21 -0
  16. package/build/legacy/devtools/utils.js.map +1 -1
  17. package/build/legacy/index.d.cts +6 -6
  18. package/build/legacy/index.d.ts +6 -6
  19. package/build/legacy/{infiniteQueryOptions-NucMX_M_.d.ts → infiniteQueryOptions-BaoKhSzb.d.ts} +26 -27
  20. package/build/legacy/infiniteQueryOptions-BaoKhSzb.d.ts.map +1 -0
  21. package/build/legacy/{infiniteQueryOptions-CnTRbIP5.d.cts → infiniteQueryOptions-ClNe2-FB.d.cts} +26 -27
  22. package/build/legacy/infiniteQueryOptions-ClNe2-FB.d.cts.map +1 -0
  23. package/build/legacy/infiniteQueryOptions.cjs.map +1 -1
  24. package/build/legacy/infiniteQueryOptions.d.cts +1 -1
  25. package/build/legacy/infiniteQueryOptions.d.ts +1 -1
  26. package/build/legacy/infiniteQueryOptions.js.map +1 -1
  27. package/build/legacy/mutationCache.cjs.map +1 -1
  28. package/build/legacy/mutationCache.d.cts +1 -1
  29. package/build/legacy/mutationCache.d.cts.map +1 -1
  30. package/build/legacy/mutationCache.d.ts +1 -1
  31. package/build/legacy/mutationCache.d.ts.map +1 -1
  32. package/build/legacy/mutationCache.js.map +1 -1
  33. package/build/legacy/mutationOptions.cjs.map +1 -1
  34. package/build/legacy/mutationOptions.d.cts +5 -13
  35. package/build/legacy/mutationOptions.d.cts.map +1 -1
  36. package/build/legacy/mutationOptions.d.ts +5 -13
  37. package/build/legacy/mutationOptions.d.ts.map +1 -1
  38. package/build/legacy/mutationOptions.js.map +1 -1
  39. package/build/legacy/queryCache.cjs.map +1 -1
  40. package/build/legacy/queryCache.d.cts +1 -1
  41. package/build/legacy/queryCache.d.cts.map +1 -1
  42. package/build/legacy/queryCache.d.ts +1 -1
  43. package/build/legacy/queryCache.d.ts.map +1 -1
  44. package/build/legacy/queryCache.js.map +1 -1
  45. package/build/legacy/{queryClient-Bn2Ql_Lu.d.cts → queryClient-BK9W57Qu.d.cts} +3 -3
  46. package/build/legacy/queryClient-BK9W57Qu.d.cts.map +1 -0
  47. package/build/legacy/{queryClient-B6mLtXOj.d.ts → queryClient-BoBzDWAZ.d.ts} +3 -3
  48. package/build/legacy/queryClient-BoBzDWAZ.d.ts.map +1 -0
  49. package/build/legacy/queryClient.cjs.map +1 -1
  50. package/build/legacy/queryClient.d.cts +1 -1
  51. package/build/legacy/queryClient.d.ts +1 -1
  52. package/build/legacy/queryClient.js.map +1 -1
  53. package/build/{modern/queryOptions-CwqQgQmQ.d.cts → legacy/queryOptions-BvmZtmiU.d.cts} +14 -19
  54. package/build/legacy/queryOptions-BvmZtmiU.d.cts.map +1 -0
  55. package/build/{modern/queryOptions-CsM5TXD2.d.ts → legacy/queryOptions-gpn5D4rf.d.ts} +14 -19
  56. package/build/legacy/queryOptions-gpn5D4rf.d.ts.map +1 -0
  57. package/build/legacy/queryOptions.cjs.map +1 -1
  58. package/build/legacy/queryOptions.d.cts +1 -1
  59. package/build/legacy/queryOptions.d.ts +1 -1
  60. package/build/legacy/queryOptions.js.map +1 -1
  61. package/build/{modern/types-JpJB72CS.d.cts → legacy/types-sdZdiLgo.d.cts} +48 -3
  62. package/build/legacy/types-sdZdiLgo.d.cts.map +1 -0
  63. package/build/legacy/{types-JpJB72CS.d.cts → types-sdZdiLgo.d.ts} +48 -3
  64. package/build/legacy/types-sdZdiLgo.d.ts.map +1 -0
  65. package/build/legacy/types.d.cts +1 -1
  66. package/build/legacy/types.d.ts +1 -1
  67. package/build/legacy/useBaseQuery.cjs +1 -1
  68. package/build/legacy/useBaseQuery.cjs.map +1 -1
  69. package/build/legacy/useBaseQuery.d.cts +1 -1
  70. package/build/legacy/useBaseQuery.d.ts +1 -1
  71. package/build/legacy/useBaseQuery.js +1 -1
  72. package/build/legacy/useBaseQuery.js.map +1 -1
  73. package/build/legacy/useInfiniteQuery.cjs.map +1 -1
  74. package/build/legacy/useInfiniteQuery.d.cts +1 -1
  75. package/build/legacy/useInfiniteQuery.d.ts +1 -1
  76. package/build/legacy/useInfiniteQuery.js.map +1 -1
  77. package/build/legacy/useIsFetching.cjs +0 -3
  78. package/build/legacy/useIsFetching.cjs.map +1 -1
  79. package/build/legacy/useIsFetching.d.cts +6 -5
  80. package/build/legacy/useIsFetching.d.cts.map +1 -1
  81. package/build/legacy/useIsFetching.d.ts +6 -5
  82. package/build/legacy/useIsFetching.d.ts.map +1 -1
  83. package/build/legacy/useIsFetching.js +0 -3
  84. package/build/legacy/useIsFetching.js.map +1 -1
  85. package/build/legacy/useMutation.cjs +2 -8
  86. package/build/legacy/useMutation.cjs.map +1 -1
  87. package/build/legacy/useMutation.d.cts +17 -11
  88. package/build/legacy/useMutation.d.cts.map +1 -1
  89. package/build/legacy/useMutation.d.ts +17 -11
  90. package/build/legacy/useMutation.d.ts.map +1 -1
  91. package/build/legacy/useMutation.js +2 -8
  92. package/build/legacy/useMutation.js.map +1 -1
  93. package/build/legacy/useMutationState.cjs +7 -6
  94. package/build/legacy/useMutationState.cjs.map +1 -1
  95. package/build/legacy/useMutationState.d.cts +16 -8
  96. package/build/legacy/useMutationState.d.cts.map +1 -1
  97. package/build/legacy/useMutationState.d.ts +16 -8
  98. package/build/legacy/useMutationState.d.ts.map +1 -1
  99. package/build/legacy/useMutationState.js +7 -6
  100. package/build/legacy/useMutationState.js.map +1 -1
  101. package/build/legacy/usePrefetchInfiniteQuery.cjs +5 -3
  102. package/build/legacy/usePrefetchInfiniteQuery.cjs.map +1 -1
  103. package/build/legacy/usePrefetchInfiniteQuery.d.cts +6 -5
  104. package/build/legacy/usePrefetchInfiniteQuery.d.cts.map +1 -1
  105. package/build/legacy/usePrefetchInfiniteQuery.d.ts +6 -5
  106. package/build/legacy/usePrefetchInfiniteQuery.d.ts.map +1 -1
  107. package/build/legacy/usePrefetchInfiniteQuery.js +5 -3
  108. package/build/legacy/usePrefetchInfiniteQuery.js.map +1 -1
  109. package/build/legacy/usePrefetchQuery.cjs +5 -3
  110. package/build/legacy/usePrefetchQuery.cjs.map +1 -1
  111. package/build/legacy/usePrefetchQuery.d.cts +6 -5
  112. package/build/legacy/usePrefetchQuery.d.cts.map +1 -1
  113. package/build/legacy/usePrefetchQuery.d.ts +6 -5
  114. package/build/legacy/usePrefetchQuery.d.ts.map +1 -1
  115. package/build/legacy/usePrefetchQuery.js +5 -3
  116. package/build/legacy/usePrefetchQuery.js.map +1 -1
  117. package/build/legacy/useQueries.cjs +1 -4
  118. package/build/legacy/useQueries.cjs.map +1 -1
  119. package/build/legacy/useQueries.d.cts +4 -7
  120. package/build/legacy/useQueries.d.cts.map +1 -1
  121. package/build/legacy/useQueries.d.ts +4 -7
  122. package/build/legacy/useQueries.d.ts.map +1 -1
  123. package/build/legacy/useQueries.js +1 -4
  124. package/build/legacy/useQueries.js.map +1 -1
  125. package/build/legacy/useQuery.cjs.map +1 -1
  126. package/build/legacy/useQuery.d.cts +12 -15
  127. package/build/legacy/useQuery.d.cts.map +1 -1
  128. package/build/legacy/useQuery.d.ts +12 -15
  129. package/build/legacy/useQuery.d.ts.map +1 -1
  130. package/build/legacy/useQuery.js.map +1 -1
  131. package/build/legacy/useQueryClient.cjs +3 -3
  132. package/build/legacy/useQueryClient.cjs.map +1 -1
  133. package/build/legacy/useQueryClient.d.cts +4 -4
  134. package/build/legacy/useQueryClient.d.ts +4 -4
  135. package/build/legacy/useQueryClient.js +3 -3
  136. package/build/legacy/useQueryClient.js.map +1 -1
  137. package/build/legacy/utils.cjs +54 -6
  138. package/build/legacy/utils.cjs.map +1 -1
  139. package/build/legacy/utils.d.cts +34 -7
  140. package/build/legacy/utils.d.cts.map +1 -1
  141. package/build/legacy/utils.d.ts +34 -7
  142. package/build/legacy/utils.d.ts.map +1 -1
  143. package/build/legacy/utils.js +54 -6
  144. package/build/legacy/utils.js.map +1 -1
  145. package/build/legacy/vueQueryPlugin.cjs +0 -3
  146. package/build/legacy/vueQueryPlugin.cjs.map +1 -1
  147. package/build/legacy/vueQueryPlugin.d.cts +6 -5
  148. package/build/legacy/vueQueryPlugin.d.cts.map +1 -1
  149. package/build/legacy/vueQueryPlugin.d.ts +6 -5
  150. package/build/legacy/vueQueryPlugin.d.ts.map +1 -1
  151. package/build/legacy/vueQueryPlugin.js +0 -3
  152. package/build/legacy/vueQueryPlugin.js.map +1 -1
  153. package/build/modern/devtools/devtools.cjs +6 -0
  154. package/build/modern/devtools/devtools.cjs.map +1 -1
  155. package/build/modern/devtools/devtools.d.cts +7 -1
  156. package/build/modern/devtools/devtools.d.cts.map +1 -1
  157. package/build/modern/devtools/devtools.d.ts +7 -1
  158. package/build/modern/devtools/devtools.d.ts.map +1 -1
  159. package/build/modern/devtools/devtools.js +6 -0
  160. package/build/modern/devtools/devtools.js.map +1 -1
  161. package/build/modern/devtools/utils.cjs +21 -0
  162. package/build/modern/devtools/utils.cjs.map +1 -1
  163. package/build/modern/devtools/utils.d.cts +21 -0
  164. package/build/modern/devtools/utils.d.cts.map +1 -1
  165. package/build/modern/devtools/utils.d.ts +21 -0
  166. package/build/modern/devtools/utils.d.ts.map +1 -1
  167. package/build/modern/devtools/utils.js +21 -0
  168. package/build/modern/devtools/utils.js.map +1 -1
  169. package/build/modern/index.d.cts +6 -6
  170. package/build/modern/index.d.ts +6 -6
  171. package/build/modern/{infiniteQueryOptions-NucMX_M_.d.ts → infiniteQueryOptions-BaoKhSzb.d.ts} +26 -27
  172. package/build/modern/infiniteQueryOptions-BaoKhSzb.d.ts.map +1 -0
  173. package/build/modern/{infiniteQueryOptions-CnTRbIP5.d.cts → infiniteQueryOptions-ClNe2-FB.d.cts} +26 -27
  174. package/build/modern/infiniteQueryOptions-ClNe2-FB.d.cts.map +1 -0
  175. package/build/modern/infiniteQueryOptions.cjs.map +1 -1
  176. package/build/modern/infiniteQueryOptions.d.cts +1 -1
  177. package/build/modern/infiniteQueryOptions.d.ts +1 -1
  178. package/build/modern/infiniteQueryOptions.js.map +1 -1
  179. package/build/modern/mutationCache.cjs.map +1 -1
  180. package/build/modern/mutationCache.d.cts +1 -1
  181. package/build/modern/mutationCache.d.cts.map +1 -1
  182. package/build/modern/mutationCache.d.ts +1 -1
  183. package/build/modern/mutationCache.d.ts.map +1 -1
  184. package/build/modern/mutationCache.js.map +1 -1
  185. package/build/modern/mutationOptions.cjs.map +1 -1
  186. package/build/modern/mutationOptions.d.cts +5 -13
  187. package/build/modern/mutationOptions.d.cts.map +1 -1
  188. package/build/modern/mutationOptions.d.ts +5 -13
  189. package/build/modern/mutationOptions.d.ts.map +1 -1
  190. package/build/modern/mutationOptions.js.map +1 -1
  191. package/build/modern/queryCache.cjs.map +1 -1
  192. package/build/modern/queryCache.d.cts +1 -1
  193. package/build/modern/queryCache.d.cts.map +1 -1
  194. package/build/modern/queryCache.d.ts +1 -1
  195. package/build/modern/queryCache.d.ts.map +1 -1
  196. package/build/modern/queryCache.js.map +1 -1
  197. package/build/modern/{queryClient-Bn2Ql_Lu.d.cts → queryClient-BK9W57Qu.d.cts} +3 -3
  198. package/build/modern/queryClient-BK9W57Qu.d.cts.map +1 -0
  199. package/build/modern/{queryClient-B6mLtXOj.d.ts → queryClient-BoBzDWAZ.d.ts} +3 -3
  200. package/build/modern/queryClient-BoBzDWAZ.d.ts.map +1 -0
  201. package/build/modern/queryClient.cjs.map +1 -1
  202. package/build/modern/queryClient.d.cts +1 -1
  203. package/build/modern/queryClient.d.ts +1 -1
  204. package/build/modern/queryClient.js.map +1 -1
  205. package/build/{legacy/queryOptions-CwqQgQmQ.d.cts → modern/queryOptions-BvmZtmiU.d.cts} +14 -19
  206. package/build/modern/queryOptions-BvmZtmiU.d.cts.map +1 -0
  207. package/build/{legacy/queryOptions-CsM5TXD2.d.ts → modern/queryOptions-gpn5D4rf.d.ts} +14 -19
  208. package/build/modern/queryOptions-gpn5D4rf.d.ts.map +1 -0
  209. package/build/modern/queryOptions.cjs.map +1 -1
  210. package/build/modern/queryOptions.d.cts +1 -1
  211. package/build/modern/queryOptions.d.ts +1 -1
  212. package/build/modern/queryOptions.js.map +1 -1
  213. package/build/modern/{types-JpJB72CS.d.ts → types-sdZdiLgo.d.cts} +48 -3
  214. package/build/modern/types-sdZdiLgo.d.cts.map +1 -0
  215. package/build/{legacy/types-JpJB72CS.d.ts → modern/types-sdZdiLgo.d.ts} +48 -3
  216. package/build/modern/types-sdZdiLgo.d.ts.map +1 -0
  217. package/build/modern/types.d.cts +1 -1
  218. package/build/modern/types.d.ts +1 -1
  219. package/build/modern/useBaseQuery.cjs +1 -1
  220. package/build/modern/useBaseQuery.cjs.map +1 -1
  221. package/build/modern/useBaseQuery.d.cts +1 -1
  222. package/build/modern/useBaseQuery.d.ts +1 -1
  223. package/build/modern/useBaseQuery.js +1 -1
  224. package/build/modern/useBaseQuery.js.map +1 -1
  225. package/build/modern/useInfiniteQuery.cjs.map +1 -1
  226. package/build/modern/useInfiniteQuery.d.cts +1 -1
  227. package/build/modern/useInfiniteQuery.d.ts +1 -1
  228. package/build/modern/useInfiniteQuery.js.map +1 -1
  229. package/build/modern/useIsFetching.cjs +0 -3
  230. package/build/modern/useIsFetching.cjs.map +1 -1
  231. package/build/modern/useIsFetching.d.cts +6 -5
  232. package/build/modern/useIsFetching.d.cts.map +1 -1
  233. package/build/modern/useIsFetching.d.ts +6 -5
  234. package/build/modern/useIsFetching.d.ts.map +1 -1
  235. package/build/modern/useIsFetching.js +0 -3
  236. package/build/modern/useIsFetching.js.map +1 -1
  237. package/build/modern/useMutation.cjs +2 -8
  238. package/build/modern/useMutation.cjs.map +1 -1
  239. package/build/modern/useMutation.d.cts +17 -11
  240. package/build/modern/useMutation.d.cts.map +1 -1
  241. package/build/modern/useMutation.d.ts +17 -11
  242. package/build/modern/useMutation.d.ts.map +1 -1
  243. package/build/modern/useMutation.js +2 -8
  244. package/build/modern/useMutation.js.map +1 -1
  245. package/build/modern/useMutationState.cjs +7 -6
  246. package/build/modern/useMutationState.cjs.map +1 -1
  247. package/build/modern/useMutationState.d.cts +16 -8
  248. package/build/modern/useMutationState.d.cts.map +1 -1
  249. package/build/modern/useMutationState.d.ts +16 -8
  250. package/build/modern/useMutationState.d.ts.map +1 -1
  251. package/build/modern/useMutationState.js +7 -6
  252. package/build/modern/useMutationState.js.map +1 -1
  253. package/build/modern/usePrefetchInfiniteQuery.cjs +5 -3
  254. package/build/modern/usePrefetchInfiniteQuery.cjs.map +1 -1
  255. package/build/modern/usePrefetchInfiniteQuery.d.cts +6 -5
  256. package/build/modern/usePrefetchInfiniteQuery.d.cts.map +1 -1
  257. package/build/modern/usePrefetchInfiniteQuery.d.ts +6 -5
  258. package/build/modern/usePrefetchInfiniteQuery.d.ts.map +1 -1
  259. package/build/modern/usePrefetchInfiniteQuery.js +5 -3
  260. package/build/modern/usePrefetchInfiniteQuery.js.map +1 -1
  261. package/build/modern/usePrefetchQuery.cjs +5 -3
  262. package/build/modern/usePrefetchQuery.cjs.map +1 -1
  263. package/build/modern/usePrefetchQuery.d.cts +6 -5
  264. package/build/modern/usePrefetchQuery.d.cts.map +1 -1
  265. package/build/modern/usePrefetchQuery.d.ts +6 -5
  266. package/build/modern/usePrefetchQuery.d.ts.map +1 -1
  267. package/build/modern/usePrefetchQuery.js +5 -3
  268. package/build/modern/usePrefetchQuery.js.map +1 -1
  269. package/build/modern/useQueries.cjs +1 -4
  270. package/build/modern/useQueries.cjs.map +1 -1
  271. package/build/modern/useQueries.d.cts +4 -7
  272. package/build/modern/useQueries.d.cts.map +1 -1
  273. package/build/modern/useQueries.d.ts +4 -7
  274. package/build/modern/useQueries.d.ts.map +1 -1
  275. package/build/modern/useQueries.js +1 -4
  276. package/build/modern/useQueries.js.map +1 -1
  277. package/build/modern/useQuery.cjs.map +1 -1
  278. package/build/modern/useQuery.d.cts +12 -15
  279. package/build/modern/useQuery.d.cts.map +1 -1
  280. package/build/modern/useQuery.d.ts +12 -15
  281. package/build/modern/useQuery.d.ts.map +1 -1
  282. package/build/modern/useQuery.js.map +1 -1
  283. package/build/modern/useQueryClient.cjs +3 -3
  284. package/build/modern/useQueryClient.cjs.map +1 -1
  285. package/build/modern/useQueryClient.d.cts +4 -4
  286. package/build/modern/useQueryClient.d.ts +4 -4
  287. package/build/modern/useQueryClient.js +3 -3
  288. package/build/modern/useQueryClient.js.map +1 -1
  289. package/build/modern/utils.cjs +54 -6
  290. package/build/modern/utils.cjs.map +1 -1
  291. package/build/modern/utils.d.cts +34 -7
  292. package/build/modern/utils.d.cts.map +1 -1
  293. package/build/modern/utils.d.ts +34 -7
  294. package/build/modern/utils.d.ts.map +1 -1
  295. package/build/modern/utils.js +54 -6
  296. package/build/modern/utils.js.map +1 -1
  297. package/build/modern/vueQueryPlugin.cjs +0 -3
  298. package/build/modern/vueQueryPlugin.cjs.map +1 -1
  299. package/build/modern/vueQueryPlugin.d.cts +6 -5
  300. package/build/modern/vueQueryPlugin.d.cts.map +1 -1
  301. package/build/modern/vueQueryPlugin.d.ts +6 -5
  302. package/build/modern/vueQueryPlugin.d.ts.map +1 -1
  303. package/build/modern/vueQueryPlugin.js +0 -3
  304. package/build/modern/vueQueryPlugin.js.map +1 -1
  305. package/package.json +4 -5
  306. package/src/devtools/devtools.ts +6 -0
  307. package/src/devtools/utils.ts +21 -0
  308. package/src/index.ts +5 -1
  309. package/src/infiniteQueryOptions.ts +2 -8
  310. package/src/mutationCache.ts +4 -2
  311. package/src/mutationOptions.ts +4 -12
  312. package/src/queryCache.ts +6 -2
  313. package/src/queryClient.ts +55 -52
  314. package/src/queryOptions.ts +22 -25
  315. package/src/types.ts +47 -2
  316. package/src/useBaseQuery.ts +8 -2
  317. package/src/useInfiniteQuery.ts +15 -14
  318. package/src/useIsFetching.ts +6 -4
  319. package/src/useMutation.ts +15 -9
  320. package/src/useMutationState.ts +23 -7
  321. package/src/usePrefetchInfiniteQuery.ts +9 -3
  322. package/src/usePrefetchQuery.ts +9 -3
  323. package/src/useQueries.ts +1 -4
  324. package/src/useQuery.ts +10 -12
  325. package/src/useQueryClient.ts +3 -3
  326. package/src/utils.ts +55 -9
  327. package/src/vueQueryPlugin.ts +4 -3
  328. package/build/legacy/infiniteQueryOptions-CnTRbIP5.d.cts.map +0 -1
  329. package/build/legacy/infiniteQueryOptions-NucMX_M_.d.ts.map +0 -1
  330. package/build/legacy/queryClient-B6mLtXOj.d.ts.map +0 -1
  331. package/build/legacy/queryClient-Bn2Ql_Lu.d.cts.map +0 -1
  332. package/build/legacy/queryOptions-CsM5TXD2.d.ts.map +0 -1
  333. package/build/legacy/queryOptions-CwqQgQmQ.d.cts.map +0 -1
  334. package/build/legacy/types-JpJB72CS.d.cts.map +0 -1
  335. package/build/legacy/types-JpJB72CS.d.ts.map +0 -1
  336. package/build/modern/infiniteQueryOptions-CnTRbIP5.d.cts.map +0 -1
  337. package/build/modern/infiniteQueryOptions-NucMX_M_.d.ts.map +0 -1
  338. package/build/modern/queryClient-B6mLtXOj.d.ts.map +0 -1
  339. package/build/modern/queryClient-Bn2Ql_Lu.d.cts.map +0 -1
  340. package/build/modern/queryOptions-CsM5TXD2.d.ts.map +0 -1
  341. package/build/modern/queryOptions-CwqQgQmQ.d.cts.map +0 -1
  342. package/build/modern/types-JpJB72CS.d.cts.map +0 -1
  343. package/build/modern/types-JpJB72CS.d.ts.map +0 -1
@@ -10,9 +10,6 @@ let vue_demi = require("vue-demi");
10
10
  *
11
11
  * `options` may be a plain object, a `ref`, or a reactive getter (`() => ({ ... })`) — pass a getter
12
12
  * if the options themselves depend on other reactive state.
13
- *
14
- * @see {@link mutationOptions} to share these options across multiple `useMutation` call sites, or to look
15
- * the mutation up elsewhere via its `mutationKey` (e.g. with `useMutationState`).
16
13
  * @param options - The {@link UseMutationOptions} to use — everything you can pass to `useMutation`.
17
14
  * @param queryClient - Use this to use a custom `QueryClient`. Otherwise, the one provided by `VueQueryPlugin`
18
15
  * will be used.
@@ -20,7 +17,8 @@ let vue_demi = require("vue-demi");
20
17
  * argument, useful for triggering call-site side effects (e.g. navigation) without coupling them to the shared
21
18
  * mutation definition. Hook-level callbacks (passed to `options`) fire for every mutation; per-call
22
19
  * callbacks fire only for the latest call you've made.
23
- *
20
+ * @see {@link mutationOptions} to share these options across multiple `useMutation` call sites, or to look
21
+ * the mutation up elsewhere via its `mutationKey` (e.g. with `useMutationState`).
24
22
  * @example
25
23
  * ```vue
26
24
  * <script setup lang="ts">
@@ -44,7 +42,6 @@ let vue_demi = require("vue-demi");
44
42
  * <button @click="onAdd">Add</button>
45
43
  * </template>
46
44
  * ```
47
- *
48
45
  * @example
49
46
  * Rendering the mutation's own state, rather than just firing it off:
50
47
  * ```vue
@@ -67,7 +64,6 @@ let vue_demi = require("vue-demi");
67
64
  * </div>
68
65
  * </template>
69
66
  * ```
70
- *
71
67
  * @example
72
68
  * Optimistic update via `onMutate`, rolling back on `onError`:
73
69
  * ```vue
@@ -103,7 +99,6 @@ let vue_demi = require("vue-demi");
103
99
  * <button @click="addMutation.mutate('Item')">Add</button>
104
100
  * </template>
105
101
  * ```
106
- *
107
102
  * @example
108
103
  * Callbacks passed per call to `mutate` only fire for the last call — `mutateAsync` gives you a
109
104
  * promise per call instead, so you can wait for all of them when they succeed:
@@ -131,7 +126,6 @@ let vue_demi = require("vue-demi");
131
126
  * <button @click="handleAddAll(['Todo 1', 'Todo 2', 'Todo 3'])">Add all</button>
132
127
  * </template>
133
128
  * ```
134
- *
135
129
  * @example
136
130
  * If some of the mutations above can fail independently of the others, and you want to know which ones
137
131
  * did — rather than losing that information the moment the first one rejects — swap `Promise.all` for
@@ -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\ntype MutationResult<TData, TError, TVariables, TOnMutateResult> =\n DistributiveOmit<\n MutationObserverResult<TData, TError, TVariables, TOnMutateResult>,\n 'mutate' | 'reset'\n >\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\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 *\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 * @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 *\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 *\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 *\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 *\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 *\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":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAsOA,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 {\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,11 +1,23 @@
1
- import { c as MutationOptions, o as MaybeRefDeep } from "./types-JpJB72CS.cjs";
2
- import { t as QueryClient$1 } from "./queryClient-Bn2Ql_Lu.cjs";
1
+ import { c as MutationOptions, o as MaybeRefDeep } from "./types-sdZdiLgo.cjs";
2
+ import { t as QueryClient$1 } from "./queryClient-BK9W57Qu.cjs";
3
3
  import { DefaultError, DistributiveOmit, MutateFunction, MutationObserverResult } from "@tanstack/query-core";
4
4
  import { ToRefs } from "vue-demi";
5
5
  //#region src/useMutation.d.ts
6
- type MutationResult<TData, TError, TVariables, TOnMutateResult> = DistributiveOmit<MutationObserverResult<TData, TError, TVariables, TOnMutateResult>, 'mutate' | 'reset'>;
6
+ /**
7
+ * The {@link MutationObserverResult} properties without `mutate` and `reset`, which `useMutation` replaces with
8
+ * its own versions.
9
+ */
10
+ export type MutationResult<TData, TError, TVariables, TOnMutateResult> = DistributiveOmit<MutationObserverResult<TData, TError, TVariables, TOnMutateResult>, 'mutate' | 'reset'>;
11
+ /**
12
+ * The options accepted by `useMutation`: {@link MutationOptions} as a plain object, a `ref`, or a reactive
13
+ * getter.
14
+ */
7
15
  export type UseMutationOptions<TData = unknown, TError = DefaultError, TVariables = void, TOnMutateResult = unknown> = MaybeRefDeep<MutationOptions<TData, TError, TVariables, TOnMutateResult>> | (() => MaybeRefDeep<MutationOptions<TData, TError, TVariables, TOnMutateResult>>);
8
16
  type MutateSyncFunction<TData = unknown, TError = DefaultError, TVariables = void, TOnMutateResult = unknown> = (...options: Parameters<MutateFunction<TData, TError, TVariables, TOnMutateResult>>) => void;
17
+ /**
18
+ * The result of `useMutation`: the {@link MutationObserverResult} properties wrapped in `Ref`s, plus the
19
+ * fire-and-forget `mutate`, the awaitable `mutateAsync`, and `reset`.
20
+ */
9
21
  export type UseMutationReturnType<TData, TError, TVariables, TOnMutateResult, TResult = MutationResult<TData, TError, TVariables, TOnMutateResult>> = ToRefs<Readonly<TResult>> & {
10
22
  mutate: MutateSyncFunction<TData, TError, TVariables, TOnMutateResult>;
11
23
  mutateAsync: MutateFunction<TData, TError, TVariables, TOnMutateResult>;
@@ -17,9 +29,6 @@ export type UseMutationReturnType<TData, TError, TVariables, TOnMutateResult, TR
17
29
  *
18
30
  * `options` may be a plain object, a `ref`, or a reactive getter (`() => ({ ... })`) — pass a getter
19
31
  * if the options themselves depend on other reactive state.
20
- *
21
- * @see {@link mutationOptions} to share these options across multiple `useMutation` call sites, or to look
22
- * the mutation up elsewhere via its `mutationKey` (e.g. with `useMutationState`).
23
32
  * @param options - The {@link UseMutationOptions} to use — everything you can pass to `useMutation`.
24
33
  * @param queryClient - Use this to use a custom `QueryClient`. Otherwise, the one provided by `VueQueryPlugin`
25
34
  * will be used.
@@ -27,7 +36,8 @@ export type UseMutationReturnType<TData, TError, TVariables, TOnMutateResult, TR
27
36
  * argument, useful for triggering call-site side effects (e.g. navigation) without coupling them to the shared
28
37
  * mutation definition. Hook-level callbacks (passed to `options`) fire for every mutation; per-call
29
38
  * callbacks fire only for the latest call you've made.
30
- *
39
+ * @see {@link mutationOptions} to share these options across multiple `useMutation` call sites, or to look
40
+ * the mutation up elsewhere via its `mutationKey` (e.g. with `useMutationState`).
31
41
  * @example
32
42
  * ```vue
33
43
  * <script setup lang="ts">
@@ -51,7 +61,6 @@ export type UseMutationReturnType<TData, TError, TVariables, TOnMutateResult, TR
51
61
  * <button @click="onAdd">Add</button>
52
62
  * </template>
53
63
  * ```
54
- *
55
64
  * @example
56
65
  * Rendering the mutation's own state, rather than just firing it off:
57
66
  * ```vue
@@ -74,7 +83,6 @@ export type UseMutationReturnType<TData, TError, TVariables, TOnMutateResult, TR
74
83
  * </div>
75
84
  * </template>
76
85
  * ```
77
- *
78
86
  * @example
79
87
  * Optimistic update via `onMutate`, rolling back on `onError`:
80
88
  * ```vue
@@ -110,7 +118,6 @@ export type UseMutationReturnType<TData, TError, TVariables, TOnMutateResult, TR
110
118
  * <button @click="addMutation.mutate('Item')">Add</button>
111
119
  * </template>
112
120
  * ```
113
- *
114
121
  * @example
115
122
  * Callbacks passed per call to `mutate` only fire for the last call — `mutateAsync` gives you a
116
123
  * promise per call instead, so you can wait for all of them when they succeed:
@@ -138,7 +145,6 @@ export type UseMutationReturnType<TData, TError, TVariables, TOnMutateResult, TR
138
145
  * <button @click="handleAddAll(['Todo 1', 'Todo 2', 'Todo 3'])">Add all</button>
139
146
  * </template>
140
147
  * ```
141
- *
142
148
  * @example
143
149
  * If some of the mutations above can fail independently of the others, and you want to know which ones
144
150
  * did — rather than losing that information the moment the first one rejects — swap `Promise.all` for
@@ -1 +1 @@
1
- {"version":3,"file":"useMutation.d.cts","names":["QueryClient"],"sources":["../../src/useMutation.ts"],"mappings":";;;;;KAwBK,eAAe,OAAO,QAAQ,YAAY,mBAC7C,iBACE,uBAAuB,OAAO,QAAQ,YAAY;YAI1C,mBACV,iBACA,SAAS,cACT,mBACA,6BAEE,aAAa,gBAAgB,OAAO,QAAQ,YAAY,2BACjD,aACL,gBAAgB,OAAO,QAAQ,YAAY;KAG5C,mBACH,iBACA,SAAS,cACT,mBACA,iCAEG,SAAS,WACV,eAAe,OAAO,QAAQ,YAAY;YAIlC,sBACV,OACA,QACA,YACA,iBACA,UAAU,eAAe,OAAO,QAAQ,YAAY,oBAClD,OAAO,SAAS;EAClB,QAAQ,mBAAmB,OAAO,QAAQ,YAAY;EACtD,aAAa,eAAe,OAAO,QAAQ,YAAY;EACvD,OAAO,uBACL,OACA,QACA,YACA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;wBAqKY,YACd,iBACA,SAAS,cACT,mBACA,2BAEA,SAAS,mBAAmB,OAAO,QAAQ,YAAY,kBACvD,cAAcA,gBACb,sBAAsB,OAAO,QAAQ,YAAY"}
1
+ {"version":3,"file":"useMutation.d.cts","names":["QueryClient"],"sources":["../../src/useMutation.ts"],"mappings":";;;;;;;;;YA4BY,eAAe,OAAO,QAAQ,YAAY,mBACpD,iBACE,uBAAuB,OAAO,QAAQ,YAAY;;;;;YAQ1C,mBACV,iBACA,SAAS,cACT,mBACA,6BAEE,aAAa,gBAAgB,OAAO,QAAQ,YAAY,2BACjD,aACL,gBAAgB,OAAO,QAAQ,YAAY;KAG5C,mBACH,iBACA,SAAS,cACT,mBACA,iCAEG,SAAS,WACV,eAAe,OAAO,QAAQ,YAAY;;;;;YAQlC,sBACV,OACA,QACA,YACA,iBACA,UAAU,eAAe,OAAO,QAAQ,YAAY,oBAClD,OAAO,SAAS;EAClB,QAAQ,mBAAmB,OAAO,QAAQ,YAAY;EACtD,aAAa,eAAe,OAAO,QAAQ,YAAY;EACvD,OAAO,uBACL,OACA,QACA,YACA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;wBA+JY,YACd,iBACA,SAAS,cACT,mBACA,2BAEA,SAAS,mBAAmB,OAAO,QAAQ,YAAY,kBACvD,cAAcA,gBACb,sBAAsB,OAAO,QAAQ,YAAY"}
@@ -1,11 +1,23 @@
1
- import { c as MutationOptions, o as MaybeRefDeep } from "./types-JpJB72CS.js";
2
- import { t as QueryClient$1 } from "./queryClient-B6mLtXOj.js";
1
+ import { c as MutationOptions, o as MaybeRefDeep } from "./types-sdZdiLgo.js";
2
+ import { t as QueryClient$1 } from "./queryClient-BoBzDWAZ.js";
3
3
  import { DefaultError, DistributiveOmit, MutateFunction, MutationObserverResult } from "@tanstack/query-core";
4
4
  import { ToRefs } from "vue-demi";
5
5
  //#region src/useMutation.d.ts
6
- type MutationResult<TData, TError, TVariables, TOnMutateResult> = DistributiveOmit<MutationObserverResult<TData, TError, TVariables, TOnMutateResult>, 'mutate' | 'reset'>;
6
+ /**
7
+ * The {@link MutationObserverResult} properties without `mutate` and `reset`, which `useMutation` replaces with
8
+ * its own versions.
9
+ */
10
+ export type MutationResult<TData, TError, TVariables, TOnMutateResult> = DistributiveOmit<MutationObserverResult<TData, TError, TVariables, TOnMutateResult>, 'mutate' | 'reset'>;
11
+ /**
12
+ * The options accepted by `useMutation`: {@link MutationOptions} as a plain object, a `ref`, or a reactive
13
+ * getter.
14
+ */
7
15
  export type UseMutationOptions<TData = unknown, TError = DefaultError, TVariables = void, TOnMutateResult = unknown> = MaybeRefDeep<MutationOptions<TData, TError, TVariables, TOnMutateResult>> | (() => MaybeRefDeep<MutationOptions<TData, TError, TVariables, TOnMutateResult>>);
8
16
  type MutateSyncFunction<TData = unknown, TError = DefaultError, TVariables = void, TOnMutateResult = unknown> = (...options: Parameters<MutateFunction<TData, TError, TVariables, TOnMutateResult>>) => void;
17
+ /**
18
+ * The result of `useMutation`: the {@link MutationObserverResult} properties wrapped in `Ref`s, plus the
19
+ * fire-and-forget `mutate`, the awaitable `mutateAsync`, and `reset`.
20
+ */
9
21
  export type UseMutationReturnType<TData, TError, TVariables, TOnMutateResult, TResult = MutationResult<TData, TError, TVariables, TOnMutateResult>> = ToRefs<Readonly<TResult>> & {
10
22
  mutate: MutateSyncFunction<TData, TError, TVariables, TOnMutateResult>;
11
23
  mutateAsync: MutateFunction<TData, TError, TVariables, TOnMutateResult>;
@@ -17,9 +29,6 @@ export type UseMutationReturnType<TData, TError, TVariables, TOnMutateResult, TR
17
29
  *
18
30
  * `options` may be a plain object, a `ref`, or a reactive getter (`() => ({ ... })`) — pass a getter
19
31
  * if the options themselves depend on other reactive state.
20
- *
21
- * @see {@link mutationOptions} to share these options across multiple `useMutation` call sites, or to look
22
- * the mutation up elsewhere via its `mutationKey` (e.g. with `useMutationState`).
23
32
  * @param options - The {@link UseMutationOptions} to use — everything you can pass to `useMutation`.
24
33
  * @param queryClient - Use this to use a custom `QueryClient`. Otherwise, the one provided by `VueQueryPlugin`
25
34
  * will be used.
@@ -27,7 +36,8 @@ export type UseMutationReturnType<TData, TError, TVariables, TOnMutateResult, TR
27
36
  * argument, useful for triggering call-site side effects (e.g. navigation) without coupling them to the shared
28
37
  * mutation definition. Hook-level callbacks (passed to `options`) fire for every mutation; per-call
29
38
  * callbacks fire only for the latest call you've made.
30
- *
39
+ * @see {@link mutationOptions} to share these options across multiple `useMutation` call sites, or to look
40
+ * the mutation up elsewhere via its `mutationKey` (e.g. with `useMutationState`).
31
41
  * @example
32
42
  * ```vue
33
43
  * <script setup lang="ts">
@@ -51,7 +61,6 @@ export type UseMutationReturnType<TData, TError, TVariables, TOnMutateResult, TR
51
61
  * <button @click="onAdd">Add</button>
52
62
  * </template>
53
63
  * ```
54
- *
55
64
  * @example
56
65
  * Rendering the mutation's own state, rather than just firing it off:
57
66
  * ```vue
@@ -74,7 +83,6 @@ export type UseMutationReturnType<TData, TError, TVariables, TOnMutateResult, TR
74
83
  * </div>
75
84
  * </template>
76
85
  * ```
77
- *
78
86
  * @example
79
87
  * Optimistic update via `onMutate`, rolling back on `onError`:
80
88
  * ```vue
@@ -110,7 +118,6 @@ export type UseMutationReturnType<TData, TError, TVariables, TOnMutateResult, TR
110
118
  * <button @click="addMutation.mutate('Item')">Add</button>
111
119
  * </template>
112
120
  * ```
113
- *
114
121
  * @example
115
122
  * Callbacks passed per call to `mutate` only fire for the last call — `mutateAsync` gives you a
116
123
  * promise per call instead, so you can wait for all of them when they succeed:
@@ -138,7 +145,6 @@ export type UseMutationReturnType<TData, TError, TVariables, TOnMutateResult, TR
138
145
  * <button @click="handleAddAll(['Todo 1', 'Todo 2', 'Todo 3'])">Add all</button>
139
146
  * </template>
140
147
  * ```
141
- *
142
148
  * @example
143
149
  * If some of the mutations above can fail independently of the others, and you want to know which ones
144
150
  * did — rather than losing that information the moment the first one rejects — swap `Promise.all` for
@@ -1 +1 @@
1
- {"version":3,"file":"useMutation.d.ts","names":["QueryClient"],"sources":["../../src/useMutation.ts"],"mappings":";;;;;KAwBK,eAAe,OAAO,QAAQ,YAAY,mBAC7C,iBACE,uBAAuB,OAAO,QAAQ,YAAY;YAI1C,mBACV,iBACA,SAAS,cACT,mBACA,6BAEE,aAAa,gBAAgB,OAAO,QAAQ,YAAY,2BACjD,aACL,gBAAgB,OAAO,QAAQ,YAAY;KAG5C,mBACH,iBACA,SAAS,cACT,mBACA,iCAEG,SAAS,WACV,eAAe,OAAO,QAAQ,YAAY;YAIlC,sBACV,OACA,QACA,YACA,iBACA,UAAU,eAAe,OAAO,QAAQ,YAAY,oBAClD,OAAO,SAAS;EAClB,QAAQ,mBAAmB,OAAO,QAAQ,YAAY;EACtD,aAAa,eAAe,OAAO,QAAQ,YAAY;EACvD,OAAO,uBACL,OACA,QACA,YACA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;wBAqKY,YACd,iBACA,SAAS,cACT,mBACA,2BAEA,SAAS,mBAAmB,OAAO,QAAQ,YAAY,kBACvD,cAAcA,gBACb,sBAAsB,OAAO,QAAQ,YAAY"}
1
+ {"version":3,"file":"useMutation.d.ts","names":["QueryClient"],"sources":["../../src/useMutation.ts"],"mappings":";;;;;;;;;YA4BY,eAAe,OAAO,QAAQ,YAAY,mBACpD,iBACE,uBAAuB,OAAO,QAAQ,YAAY;;;;;YAQ1C,mBACV,iBACA,SAAS,cACT,mBACA,6BAEE,aAAa,gBAAgB,OAAO,QAAQ,YAAY,2BACjD,aACL,gBAAgB,OAAO,QAAQ,YAAY;KAG5C,mBACH,iBACA,SAAS,cACT,mBACA,iCAEG,SAAS,WACV,eAAe,OAAO,QAAQ,YAAY;;;;;YAQlC,sBACV,OACA,QACA,YACA,iBACA,UAAU,eAAe,OAAO,QAAQ,YAAY,oBAClD,OAAO,SAAS;EAClB,QAAQ,mBAAmB,OAAO,QAAQ,YAAY;EACtD,aAAa,eAAe,OAAO,QAAQ,YAAY;EACvD,OAAO,uBACL,OACA,QACA,YACA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;wBA+JY,YACd,iBACA,SAAS,cACT,mBACA,2BAEA,SAAS,mBAAmB,OAAO,QAAQ,YAAY,kBACvD,cAAcA,gBACb,sBAAsB,OAAO,QAAQ,YAAY"}
@@ -9,9 +9,6 @@ import { computed, getCurrentScope, onScopeDispose, reactive, readonly, shallowR
9
9
  *
10
10
  * `options` may be a plain object, a `ref`, or a reactive getter (`() => ({ ... })`) — pass a getter
11
11
  * if the options themselves depend on other reactive state.
12
- *
13
- * @see {@link mutationOptions} to share these options across multiple `useMutation` call sites, or to look
14
- * the mutation up elsewhere via its `mutationKey` (e.g. with `useMutationState`).
15
12
  * @param options - The {@link UseMutationOptions} to use — everything you can pass to `useMutation`.
16
13
  * @param queryClient - Use this to use a custom `QueryClient`. Otherwise, the one provided by `VueQueryPlugin`
17
14
  * will be used.
@@ -19,7 +16,8 @@ import { computed, getCurrentScope, onScopeDispose, reactive, readonly, shallowR
19
16
  * argument, useful for triggering call-site side effects (e.g. navigation) without coupling them to the shared
20
17
  * mutation definition. Hook-level callbacks (passed to `options`) fire for every mutation; per-call
21
18
  * callbacks fire only for the latest call you've made.
22
- *
19
+ * @see {@link mutationOptions} to share these options across multiple `useMutation` call sites, or to look
20
+ * the mutation up elsewhere via its `mutationKey` (e.g. with `useMutationState`).
23
21
  * @example
24
22
  * ```vue
25
23
  * <script setup lang="ts">
@@ -43,7 +41,6 @@ import { computed, getCurrentScope, onScopeDispose, reactive, readonly, shallowR
43
41
  * <button @click="onAdd">Add</button>
44
42
  * </template>
45
43
  * ```
46
- *
47
44
  * @example
48
45
  * Rendering the mutation's own state, rather than just firing it off:
49
46
  * ```vue
@@ -66,7 +63,6 @@ import { computed, getCurrentScope, onScopeDispose, reactive, readonly, shallowR
66
63
  * </div>
67
64
  * </template>
68
65
  * ```
69
- *
70
66
  * @example
71
67
  * Optimistic update via `onMutate`, rolling back on `onError`:
72
68
  * ```vue
@@ -102,7 +98,6 @@ import { computed, getCurrentScope, onScopeDispose, reactive, readonly, shallowR
102
98
  * <button @click="addMutation.mutate('Item')">Add</button>
103
99
  * </template>
104
100
  * ```
105
- *
106
101
  * @example
107
102
  * Callbacks passed per call to `mutate` only fire for the last call — `mutateAsync` gives you a
108
103
  * promise per call instead, so you can wait for all of them when they succeed:
@@ -130,7 +125,6 @@ import { computed, getCurrentScope, onScopeDispose, reactive, readonly, shallowR
130
125
  * <button @click="handleAddAll(['Todo 1', 'Todo 2', 'Todo 3'])">Add all</button>
131
126
  * </template>
132
127
  * ```
133
- *
134
128
  * @example
135
129
  * If some of the mutations above can fail independently of the others, and you want to know which ones
136
130
  * did — rather than losing that information the moment the first one rejects — swap `Promise.all` for
@@ -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\ntype MutationResult<TData, TError, TVariables, TOnMutateResult> =\n DistributiveOmit<\n MutationObserverResult<TData, TError, TVariables, TOnMutateResult>,\n 'mutate' | 'reset'\n >\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\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 *\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 * @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 *\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 *\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 *\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 *\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 *\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":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAsOA,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 {\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"}
@@ -9,12 +9,10 @@ let vue_demi = require("vue-demi");
9
9
  *
10
10
  * `filters` may be a plain object, `MaybeRefDeep`, or a reactive getter (`() => ({ ... })`) — pass a getter if
11
11
  * the filters themselves depend on other reactive state.
12
- *
13
12
  * @param filters - The {@link MutationFilters} to narrow down the matched mutations.
14
13
  * @param queryClient - Use this to use a custom `QueryClient`. Otherwise, the one provided by `VueQueryPlugin`
15
14
  * will be used.
16
15
  * @returns A `ref` to the `number` of the mutations that your application currently has `pending`.
17
- *
18
16
  * @example
19
17
  * ```vue
20
18
  * <script setup lang="ts">
@@ -40,6 +38,13 @@ function useIsMutating(filters = {}, queryClient) {
40
38
  })) }, client);
41
39
  return (0, vue_demi.computed)(() => mutationState.value.length);
42
40
  }
41
+ /**
42
+ * Collects the mutations in the cache that match `options.filters`, mapped with `options.select`
43
+ * (or to their state, by default).
44
+ * @param mutationCache - The mutation cache to read.
45
+ * @param options - The `filters` to match and the `select` function to map each mutation with.
46
+ * @returns The selected value of every matching mutation.
47
+ */
43
48
  function getResult(mutationCache, options) {
44
49
  return mutationCache.findAll(options.filters).map((mutation) => options.select ? options.select(mutation) : mutation.state);
45
50
  }
@@ -50,13 +55,11 @@ function getResult(mutationCache, options) {
50
55
  *
51
56
  * `options` may be a plain object or a reactive getter (`() => ({ ... })`) — pass a getter if the filters
52
57
  * themselves depend on other reactive state.
53
- *
54
58
  * @param options - The `filters` to narrow down matched mutations, and an optional `select` to transform the
55
59
  * mutation state.
56
60
  * @param queryClient - Use this to use a custom `QueryClient`. Otherwise, the one provided by `VueQueryPlugin`
57
61
  * will be used.
58
62
  * @returns A `ref` to an Array of whatever `select` returns for each matching mutation.
59
- *
60
63
  * @example
61
64
  * Get all variables of all running mutations:
62
65
  * ```vue
@@ -71,7 +74,6 @@ function getResult(mutationCache, options) {
71
74
  *
72
75
  * <template>{{ pendingVariables.length }} posts saving...</template>
73
76
  * ```
74
- *
75
77
  * @example
76
78
  * Get all data for specific mutations via the `mutationKey`:
77
79
  * ```vue
@@ -99,7 +101,6 @@ function getResult(mutationCache, options) {
99
101
  * </button>
100
102
  * </template>
101
103
  * ```
102
- *
103
104
  * @example
104
105
  * Access the latest successful mutation data via the `mutationKey`. Each invocation of `mutate` adds a new
105
106
  * entry to the mutation cache for `gcTime` milliseconds — with the `status: 'success'` filter below, check the
@@ -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\nexport type UseIsMutatingFilters =\n VueMutationFilters | (() => VueMutationFilters)\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 *\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 *\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\nexport type MutationStateOptions<\n TResult = MutationState,\n TMutation extends Mutation<any, any, any, any> =\n MutationTypeFromResult<TResult>,\n> = {\n filters?: VueMutationFilters\n select?: (mutation: TMutation) => TResult\n}\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 *\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 *\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 *\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 *\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":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAmDA,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;AAsBA,SAAS,UAKP,eACA,SACgB;CAChB,OAAO,cACJ,QAAQ,QAAQ,OAAO,CAAC,CACxB,KACE,aACE,QAAQ,SACL,QAAQ,OAAO,QAAqB,IACpC,SAAS,KACjB;AACJ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA+EA,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 { 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 | VueMutationFilters\n | (() => VueMutationFilters)\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,9 +1,13 @@
1
- import { o as MaybeRefDeep } from "./types-JpJB72CS.cjs";
2
- import { t as QueryClient$1 } from "./queryClient-Bn2Ql_Lu.cjs";
1
+ import { o as MaybeRefDeep } from "./types-sdZdiLgo.cjs";
2
+ import { t as QueryClient$1 } from "./queryClient-BK9W57Qu.cjs";
3
3
  import { Mutation, MutationFilters, MutationState } from "@tanstack/query-core";
4
4
  import { Ref } from "vue-demi";
5
5
  //#region src/useMutationState.d.ts
6
6
  type VueMutationFilters = MaybeRefDeep<MutationFilters>;
7
+ /**
8
+ * The filters accepted by `useIsMutating`: {@link MutationFilters} as a plain object, a `ref`, or a reactive
9
+ * getter.
10
+ */
7
11
  export type UseIsMutatingFilters = VueMutationFilters | (() => VueMutationFilters);
8
12
  /**
9
13
  * The `useIsMutating` composable returns a `ref` to the `number` of mutations that your application currently
@@ -11,12 +15,10 @@ export type UseIsMutatingFilters = VueMutationFilters | (() => VueMutationFilter
11
15
  *
12
16
  * `filters` may be a plain object, `MaybeRefDeep`, or a reactive getter (`() => ({ ... })`) — pass a getter if
13
17
  * the filters themselves depend on other reactive state.
14
- *
15
18
  * @param filters - The {@link MutationFilters} to narrow down the matched mutations.
16
19
  * @param queryClient - Use this to use a custom `QueryClient`. Otherwise, the one provided by `VueQueryPlugin`
17
20
  * will be used.
18
21
  * @returns A `ref` to the `number` of the mutations that your application currently has `pending`.
19
- *
20
22
  * @example
21
23
  * ```vue
22
24
  * <script setup lang="ts">
@@ -33,8 +35,18 @@ export type UseIsMutatingFilters = VueMutationFilters | (() => VueMutationFilter
33
35
  */
34
36
  export declare function useIsMutating(filters?: UseIsMutatingFilters, queryClient?: QueryClient$1): Ref<number>;
35
37
  type MutationTypeFromResult<TResult> = [TResult] extends [MutationState<infer TData, infer TError, infer TVariables, infer TOnMutateResult>] ? Mutation<TData, TError, TVariables, TOnMutateResult> : Mutation;
38
+ /**
39
+ * The options accepted by `useMutationState`: the `filters` matching the mutations, and `select` to map each
40
+ * one (to its state, by default).
41
+ */
36
42
  export type MutationStateOptions<TResult = MutationState, TMutation extends Mutation<any, any, any, any> = MutationTypeFromResult<TResult>> = {
43
+ /**
44
+ * The filters that select the mutations to return the state of.
45
+ */
37
46
  filters?: VueMutationFilters;
47
+ /**
48
+ * Maps each matching mutation to the value returned for it. Defaults to the mutation's `state`.
49
+ */
38
50
  select?: (mutation: TMutation) => TResult;
39
51
  };
40
52
  /**
@@ -44,13 +56,11 @@ export type MutationStateOptions<TResult = MutationState, TMutation extends Muta
44
56
  *
45
57
  * `options` may be a plain object or a reactive getter (`() => ({ ... })`) — pass a getter if the filters
46
58
  * themselves depend on other reactive state.
47
- *
48
59
  * @param options - The `filters` to narrow down matched mutations, and an optional `select` to transform the
49
60
  * mutation state.
50
61
  * @param queryClient - Use this to use a custom `QueryClient`. Otherwise, the one provided by `VueQueryPlugin`
51
62
  * will be used.
52
63
  * @returns A `ref` to an Array of whatever `select` returns for each matching mutation.
53
- *
54
64
  * @example
55
65
  * Get all variables of all running mutations:
56
66
  * ```vue
@@ -65,7 +75,6 @@ export type MutationStateOptions<TResult = MutationState, TMutation extends Muta
65
75
  *
66
76
  * <template>{{ pendingVariables.length }} posts saving...</template>
67
77
  * ```
68
- *
69
78
  * @example
70
79
  * Get all data for specific mutations via the `mutationKey`:
71
80
  * ```vue
@@ -93,7 +102,6 @@ export type MutationStateOptions<TResult = MutationState, TMutation extends Muta
93
102
  * </button>
94
103
  * </template>
95
104
  * ```
96
- *
97
105
  * @example
98
106
  * Access the latest successful mutation data via the `mutationKey`. Each invocation of `mutate` adds a new
99
107
  * entry to the mutation cache for `gcTime` milliseconds — with the `status: 'success'` filter below, check the
@@ -1 +1 @@
1
- {"version":3,"file":"useMutationState.d.cts","names":["QueryClient"],"sources":["../../src/useMutationState.ts"],"mappings":";;;;;KAoBK,qBAAqB,aAAa;YAE3B,uBACV,4BAA4B;;;;;;;;;;;;;;;;;;;;;;;;;;;wBA4Bd,cACd,UAAS,sBACT,cAAcA,gBACb;KAyBE,uBAAuB,YAAY,kBACtC,oBACQ,aACA,cACA,kBACA,oBAGN,SAAS,OAAO,QAAQ,YAAY,mBACpC;YAEQ,qBACV,UAAU,eACV,kBAAkB,+BAChB,uBAAuB;EAEzB,UAAU;EACV,UAAU,UAAU,cAAc;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;wBAkGpB,iBACd,UAAU,eACV,kBAAkB,+BAChB,uBAAuB,UAEzB,UACI,qBAAqB,SAAS,oBACvB,qBAAqB,SAAS,aACzC,cAAcA,gBACb,SAAS,IAAI,MAAM"}
1
+ {"version":3,"file":"useMutationState.d.cts","names":["QueryClient"],"sources":["../../src/useMutationState.ts"],"mappings":";;;;;KAoBK,qBAAqB,aAAa;;;;;YAM3B,uBACR,4BACO;;;;;;;;;;;;;;;;;;;;;;;;;wBA0BK,cACd,UAAS,sBACT,cAAcA,gBACb;KAyBE,uBAAuB,YAAY,kBACtC,oBACQ,aACA,cACA,kBACA,oBAGN,SAAS,OAAO,QAAQ,YAAY,mBACpC;;;;;YAMQ,qBACV,UAAU,eACV,kBAAkB,+BAChB,uBAAuB;;;;EAKzB,UAAU;;;;EAIV,UAAU,UAAU,cAAc;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;wBAqGpB,iBACd,UAAU,eACV,kBAAkB,+BAChB,uBAAuB,UAEzB,UACI,qBAAqB,SAAS,oBACvB,qBAAqB,SAAS,aACzC,cAAcA,gBACb,SAAS,IAAI,MAAM"}