@tanstack/vue-query 5.104.1 → 5.104.3
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.
- package/build/legacy/devtools/devtools.cjs +6 -0
- package/build/legacy/devtools/devtools.cjs.map +1 -1
- package/build/legacy/devtools/devtools.d.cts +7 -1
- package/build/legacy/devtools/devtools.d.cts.map +1 -1
- package/build/legacy/devtools/devtools.d.ts +7 -1
- package/build/legacy/devtools/devtools.d.ts.map +1 -1
- package/build/legacy/devtools/devtools.js +6 -0
- package/build/legacy/devtools/devtools.js.map +1 -1
- package/build/legacy/devtools/utils.cjs +21 -0
- package/build/legacy/devtools/utils.cjs.map +1 -1
- package/build/legacy/devtools/utils.d.cts +21 -0
- package/build/legacy/devtools/utils.d.cts.map +1 -1
- package/build/legacy/devtools/utils.d.ts +21 -0
- package/build/legacy/devtools/utils.d.ts.map +1 -1
- package/build/legacy/devtools/utils.js +21 -0
- package/build/legacy/devtools/utils.js.map +1 -1
- package/build/legacy/index.d.cts +6 -6
- package/build/legacy/index.d.ts +6 -6
- package/build/legacy/{infiniteQueryOptions-NucMX_M_.d.ts → infiniteQueryOptions-BaoKhSzb.d.ts} +26 -27
- package/build/legacy/infiniteQueryOptions-BaoKhSzb.d.ts.map +1 -0
- package/build/legacy/{infiniteQueryOptions-CnTRbIP5.d.cts → infiniteQueryOptions-ClNe2-FB.d.cts} +26 -27
- package/build/legacy/infiniteQueryOptions-ClNe2-FB.d.cts.map +1 -0
- package/build/legacy/infiniteQueryOptions.cjs.map +1 -1
- package/build/legacy/infiniteQueryOptions.d.cts +1 -1
- package/build/legacy/infiniteQueryOptions.d.ts +1 -1
- package/build/legacy/infiniteQueryOptions.js.map +1 -1
- package/build/legacy/mutationCache.cjs.map +1 -1
- package/build/legacy/mutationCache.d.cts +1 -1
- package/build/legacy/mutationCache.d.cts.map +1 -1
- package/build/legacy/mutationCache.d.ts +1 -1
- package/build/legacy/mutationCache.d.ts.map +1 -1
- package/build/legacy/mutationCache.js.map +1 -1
- package/build/legacy/mutationOptions.cjs.map +1 -1
- package/build/legacy/mutationOptions.d.cts +5 -13
- package/build/legacy/mutationOptions.d.cts.map +1 -1
- package/build/legacy/mutationOptions.d.ts +5 -13
- package/build/legacy/mutationOptions.d.ts.map +1 -1
- package/build/legacy/mutationOptions.js.map +1 -1
- package/build/legacy/queryCache.cjs.map +1 -1
- package/build/legacy/queryCache.d.cts +1 -1
- package/build/legacy/queryCache.d.cts.map +1 -1
- package/build/legacy/queryCache.d.ts +1 -1
- package/build/legacy/queryCache.d.ts.map +1 -1
- package/build/legacy/queryCache.js.map +1 -1
- package/build/legacy/{queryClient-Bn2Ql_Lu.d.cts → queryClient-BK9W57Qu.d.cts} +3 -3
- package/build/legacy/queryClient-BK9W57Qu.d.cts.map +1 -0
- package/build/legacy/{queryClient-B6mLtXOj.d.ts → queryClient-BoBzDWAZ.d.ts} +3 -3
- package/build/legacy/queryClient-BoBzDWAZ.d.ts.map +1 -0
- package/build/legacy/queryClient.cjs.map +1 -1
- package/build/legacy/queryClient.d.cts +1 -1
- package/build/legacy/queryClient.d.ts +1 -1
- package/build/legacy/queryClient.js.map +1 -1
- package/build/{modern/queryOptions-CwqQgQmQ.d.cts → legacy/queryOptions-BvmZtmiU.d.cts} +14 -19
- package/build/legacy/queryOptions-BvmZtmiU.d.cts.map +1 -0
- package/build/{modern/queryOptions-CsM5TXD2.d.ts → legacy/queryOptions-gpn5D4rf.d.ts} +14 -19
- package/build/legacy/queryOptions-gpn5D4rf.d.ts.map +1 -0
- package/build/legacy/queryOptions.cjs.map +1 -1
- package/build/legacy/queryOptions.d.cts +1 -1
- package/build/legacy/queryOptions.d.ts +1 -1
- package/build/legacy/queryOptions.js.map +1 -1
- package/build/{modern/types-JpJB72CS.d.cts → legacy/types-sdZdiLgo.d.cts} +48 -3
- package/build/legacy/types-sdZdiLgo.d.cts.map +1 -0
- package/build/legacy/{types-JpJB72CS.d.cts → types-sdZdiLgo.d.ts} +48 -3
- package/build/legacy/types-sdZdiLgo.d.ts.map +1 -0
- package/build/legacy/types.d.cts +1 -1
- package/build/legacy/types.d.ts +1 -1
- package/build/legacy/useBaseQuery.cjs +1 -1
- package/build/legacy/useBaseQuery.cjs.map +1 -1
- package/build/legacy/useBaseQuery.d.cts +1 -1
- package/build/legacy/useBaseQuery.d.ts +1 -1
- package/build/legacy/useBaseQuery.js +1 -1
- package/build/legacy/useBaseQuery.js.map +1 -1
- package/build/legacy/useInfiniteQuery.cjs.map +1 -1
- package/build/legacy/useInfiniteQuery.d.cts +1 -1
- package/build/legacy/useInfiniteQuery.d.ts +1 -1
- package/build/legacy/useInfiniteQuery.js.map +1 -1
- package/build/legacy/useIsFetching.cjs +0 -3
- package/build/legacy/useIsFetching.cjs.map +1 -1
- package/build/legacy/useIsFetching.d.cts +6 -5
- package/build/legacy/useIsFetching.d.cts.map +1 -1
- package/build/legacy/useIsFetching.d.ts +6 -5
- package/build/legacy/useIsFetching.d.ts.map +1 -1
- package/build/legacy/useIsFetching.js +0 -3
- package/build/legacy/useIsFetching.js.map +1 -1
- package/build/legacy/useMutation.cjs +2 -8
- package/build/legacy/useMutation.cjs.map +1 -1
- package/build/legacy/useMutation.d.cts +17 -11
- package/build/legacy/useMutation.d.cts.map +1 -1
- package/build/legacy/useMutation.d.ts +17 -11
- package/build/legacy/useMutation.d.ts.map +1 -1
- package/build/legacy/useMutation.js +2 -8
- package/build/legacy/useMutation.js.map +1 -1
- package/build/legacy/useMutationState.cjs +7 -6
- package/build/legacy/useMutationState.cjs.map +1 -1
- package/build/legacy/useMutationState.d.cts +16 -8
- package/build/legacy/useMutationState.d.cts.map +1 -1
- package/build/legacy/useMutationState.d.ts +16 -8
- package/build/legacy/useMutationState.d.ts.map +1 -1
- package/build/legacy/useMutationState.js +7 -6
- package/build/legacy/useMutationState.js.map +1 -1
- package/build/legacy/usePrefetchInfiniteQuery.cjs +5 -3
- package/build/legacy/usePrefetchInfiniteQuery.cjs.map +1 -1
- package/build/legacy/usePrefetchInfiniteQuery.d.cts +6 -5
- package/build/legacy/usePrefetchInfiniteQuery.d.cts.map +1 -1
- package/build/legacy/usePrefetchInfiniteQuery.d.ts +6 -5
- package/build/legacy/usePrefetchInfiniteQuery.d.ts.map +1 -1
- package/build/legacy/usePrefetchInfiniteQuery.js +5 -3
- package/build/legacy/usePrefetchInfiniteQuery.js.map +1 -1
- package/build/legacy/usePrefetchQuery.cjs +5 -3
- package/build/legacy/usePrefetchQuery.cjs.map +1 -1
- package/build/legacy/usePrefetchQuery.d.cts +6 -5
- package/build/legacy/usePrefetchQuery.d.cts.map +1 -1
- package/build/legacy/usePrefetchQuery.d.ts +6 -5
- package/build/legacy/usePrefetchQuery.d.ts.map +1 -1
- package/build/legacy/usePrefetchQuery.js +5 -3
- package/build/legacy/usePrefetchQuery.js.map +1 -1
- package/build/legacy/useQueries.cjs +1 -4
- package/build/legacy/useQueries.cjs.map +1 -1
- package/build/legacy/useQueries.d.cts +4 -7
- package/build/legacy/useQueries.d.cts.map +1 -1
- package/build/legacy/useQueries.d.ts +4 -7
- package/build/legacy/useQueries.d.ts.map +1 -1
- package/build/legacy/useQueries.js +1 -4
- package/build/legacy/useQueries.js.map +1 -1
- package/build/legacy/useQuery.cjs.map +1 -1
- package/build/legacy/useQuery.d.cts +12 -15
- package/build/legacy/useQuery.d.cts.map +1 -1
- package/build/legacy/useQuery.d.ts +12 -15
- package/build/legacy/useQuery.d.ts.map +1 -1
- package/build/legacy/useQuery.js.map +1 -1
- package/build/legacy/useQueryClient.cjs +3 -3
- package/build/legacy/useQueryClient.cjs.map +1 -1
- package/build/legacy/useQueryClient.d.cts +4 -4
- package/build/legacy/useQueryClient.d.ts +4 -4
- package/build/legacy/useQueryClient.js +3 -3
- package/build/legacy/useQueryClient.js.map +1 -1
- package/build/legacy/utils.cjs +54 -6
- package/build/legacy/utils.cjs.map +1 -1
- package/build/legacy/utils.d.cts +34 -7
- package/build/legacy/utils.d.cts.map +1 -1
- package/build/legacy/utils.d.ts +34 -7
- package/build/legacy/utils.d.ts.map +1 -1
- package/build/legacy/utils.js +54 -6
- package/build/legacy/utils.js.map +1 -1
- package/build/legacy/vueQueryPlugin.cjs +0 -3
- package/build/legacy/vueQueryPlugin.cjs.map +1 -1
- package/build/legacy/vueQueryPlugin.d.cts +6 -5
- package/build/legacy/vueQueryPlugin.d.cts.map +1 -1
- package/build/legacy/vueQueryPlugin.d.ts +6 -5
- package/build/legacy/vueQueryPlugin.d.ts.map +1 -1
- package/build/legacy/vueQueryPlugin.js +0 -3
- package/build/legacy/vueQueryPlugin.js.map +1 -1
- package/build/modern/devtools/devtools.cjs +6 -0
- package/build/modern/devtools/devtools.cjs.map +1 -1
- package/build/modern/devtools/devtools.d.cts +7 -1
- package/build/modern/devtools/devtools.d.cts.map +1 -1
- package/build/modern/devtools/devtools.d.ts +7 -1
- package/build/modern/devtools/devtools.d.ts.map +1 -1
- package/build/modern/devtools/devtools.js +6 -0
- package/build/modern/devtools/devtools.js.map +1 -1
- package/build/modern/devtools/utils.cjs +21 -0
- package/build/modern/devtools/utils.cjs.map +1 -1
- package/build/modern/devtools/utils.d.cts +21 -0
- package/build/modern/devtools/utils.d.cts.map +1 -1
- package/build/modern/devtools/utils.d.ts +21 -0
- package/build/modern/devtools/utils.d.ts.map +1 -1
- package/build/modern/devtools/utils.js +21 -0
- package/build/modern/devtools/utils.js.map +1 -1
- package/build/modern/index.d.cts +6 -6
- package/build/modern/index.d.ts +6 -6
- package/build/modern/{infiniteQueryOptions-NucMX_M_.d.ts → infiniteQueryOptions-BaoKhSzb.d.ts} +26 -27
- package/build/modern/infiniteQueryOptions-BaoKhSzb.d.ts.map +1 -0
- package/build/modern/{infiniteQueryOptions-CnTRbIP5.d.cts → infiniteQueryOptions-ClNe2-FB.d.cts} +26 -27
- package/build/modern/infiniteQueryOptions-ClNe2-FB.d.cts.map +1 -0
- package/build/modern/infiniteQueryOptions.cjs.map +1 -1
- package/build/modern/infiniteQueryOptions.d.cts +1 -1
- package/build/modern/infiniteQueryOptions.d.ts +1 -1
- package/build/modern/infiniteQueryOptions.js.map +1 -1
- package/build/modern/mutationCache.cjs.map +1 -1
- package/build/modern/mutationCache.d.cts +1 -1
- package/build/modern/mutationCache.d.cts.map +1 -1
- package/build/modern/mutationCache.d.ts +1 -1
- package/build/modern/mutationCache.d.ts.map +1 -1
- package/build/modern/mutationCache.js.map +1 -1
- package/build/modern/mutationOptions.cjs.map +1 -1
- package/build/modern/mutationOptions.d.cts +5 -13
- package/build/modern/mutationOptions.d.cts.map +1 -1
- package/build/modern/mutationOptions.d.ts +5 -13
- package/build/modern/mutationOptions.d.ts.map +1 -1
- package/build/modern/mutationOptions.js.map +1 -1
- package/build/modern/queryCache.cjs.map +1 -1
- package/build/modern/queryCache.d.cts +1 -1
- package/build/modern/queryCache.d.cts.map +1 -1
- package/build/modern/queryCache.d.ts +1 -1
- package/build/modern/queryCache.d.ts.map +1 -1
- package/build/modern/queryCache.js.map +1 -1
- package/build/modern/{queryClient-Bn2Ql_Lu.d.cts → queryClient-BK9W57Qu.d.cts} +3 -3
- package/build/modern/queryClient-BK9W57Qu.d.cts.map +1 -0
- package/build/modern/{queryClient-B6mLtXOj.d.ts → queryClient-BoBzDWAZ.d.ts} +3 -3
- package/build/modern/queryClient-BoBzDWAZ.d.ts.map +1 -0
- package/build/modern/queryClient.cjs.map +1 -1
- package/build/modern/queryClient.d.cts +1 -1
- package/build/modern/queryClient.d.ts +1 -1
- package/build/modern/queryClient.js.map +1 -1
- package/build/{legacy/queryOptions-CwqQgQmQ.d.cts → modern/queryOptions-BvmZtmiU.d.cts} +14 -19
- package/build/modern/queryOptions-BvmZtmiU.d.cts.map +1 -0
- package/build/{legacy/queryOptions-CsM5TXD2.d.ts → modern/queryOptions-gpn5D4rf.d.ts} +14 -19
- package/build/modern/queryOptions-gpn5D4rf.d.ts.map +1 -0
- package/build/modern/queryOptions.cjs.map +1 -1
- package/build/modern/queryOptions.d.cts +1 -1
- package/build/modern/queryOptions.d.ts +1 -1
- package/build/modern/queryOptions.js.map +1 -1
- package/build/modern/{types-JpJB72CS.d.ts → types-sdZdiLgo.d.cts} +48 -3
- package/build/modern/types-sdZdiLgo.d.cts.map +1 -0
- package/build/{legacy/types-JpJB72CS.d.ts → modern/types-sdZdiLgo.d.ts} +48 -3
- package/build/modern/types-sdZdiLgo.d.ts.map +1 -0
- package/build/modern/types.d.cts +1 -1
- package/build/modern/types.d.ts +1 -1
- package/build/modern/useBaseQuery.cjs +1 -1
- package/build/modern/useBaseQuery.cjs.map +1 -1
- package/build/modern/useBaseQuery.d.cts +1 -1
- package/build/modern/useBaseQuery.d.ts +1 -1
- package/build/modern/useBaseQuery.js +1 -1
- package/build/modern/useBaseQuery.js.map +1 -1
- package/build/modern/useInfiniteQuery.cjs.map +1 -1
- package/build/modern/useInfiniteQuery.d.cts +1 -1
- package/build/modern/useInfiniteQuery.d.ts +1 -1
- package/build/modern/useInfiniteQuery.js.map +1 -1
- package/build/modern/useIsFetching.cjs +0 -3
- package/build/modern/useIsFetching.cjs.map +1 -1
- package/build/modern/useIsFetching.d.cts +6 -5
- package/build/modern/useIsFetching.d.cts.map +1 -1
- package/build/modern/useIsFetching.d.ts +6 -5
- package/build/modern/useIsFetching.d.ts.map +1 -1
- package/build/modern/useIsFetching.js +0 -3
- package/build/modern/useIsFetching.js.map +1 -1
- package/build/modern/useMutation.cjs +2 -8
- package/build/modern/useMutation.cjs.map +1 -1
- package/build/modern/useMutation.d.cts +17 -11
- package/build/modern/useMutation.d.cts.map +1 -1
- package/build/modern/useMutation.d.ts +17 -11
- package/build/modern/useMutation.d.ts.map +1 -1
- package/build/modern/useMutation.js +2 -8
- package/build/modern/useMutation.js.map +1 -1
- package/build/modern/useMutationState.cjs +7 -6
- package/build/modern/useMutationState.cjs.map +1 -1
- package/build/modern/useMutationState.d.cts +16 -8
- package/build/modern/useMutationState.d.cts.map +1 -1
- package/build/modern/useMutationState.d.ts +16 -8
- package/build/modern/useMutationState.d.ts.map +1 -1
- package/build/modern/useMutationState.js +7 -6
- package/build/modern/useMutationState.js.map +1 -1
- package/build/modern/usePrefetchInfiniteQuery.cjs +5 -3
- package/build/modern/usePrefetchInfiniteQuery.cjs.map +1 -1
- package/build/modern/usePrefetchInfiniteQuery.d.cts +6 -5
- package/build/modern/usePrefetchInfiniteQuery.d.cts.map +1 -1
- package/build/modern/usePrefetchInfiniteQuery.d.ts +6 -5
- package/build/modern/usePrefetchInfiniteQuery.d.ts.map +1 -1
- package/build/modern/usePrefetchInfiniteQuery.js +5 -3
- package/build/modern/usePrefetchInfiniteQuery.js.map +1 -1
- package/build/modern/usePrefetchQuery.cjs +5 -3
- package/build/modern/usePrefetchQuery.cjs.map +1 -1
- package/build/modern/usePrefetchQuery.d.cts +6 -5
- package/build/modern/usePrefetchQuery.d.cts.map +1 -1
- package/build/modern/usePrefetchQuery.d.ts +6 -5
- package/build/modern/usePrefetchQuery.d.ts.map +1 -1
- package/build/modern/usePrefetchQuery.js +5 -3
- package/build/modern/usePrefetchQuery.js.map +1 -1
- package/build/modern/useQueries.cjs +1 -4
- package/build/modern/useQueries.cjs.map +1 -1
- package/build/modern/useQueries.d.cts +4 -7
- package/build/modern/useQueries.d.cts.map +1 -1
- package/build/modern/useQueries.d.ts +4 -7
- package/build/modern/useQueries.d.ts.map +1 -1
- package/build/modern/useQueries.js +1 -4
- package/build/modern/useQueries.js.map +1 -1
- package/build/modern/useQuery.cjs.map +1 -1
- package/build/modern/useQuery.d.cts +12 -15
- package/build/modern/useQuery.d.cts.map +1 -1
- package/build/modern/useQuery.d.ts +12 -15
- package/build/modern/useQuery.d.ts.map +1 -1
- package/build/modern/useQuery.js.map +1 -1
- package/build/modern/useQueryClient.cjs +3 -3
- package/build/modern/useQueryClient.cjs.map +1 -1
- package/build/modern/useQueryClient.d.cts +4 -4
- package/build/modern/useQueryClient.d.ts +4 -4
- package/build/modern/useQueryClient.js +3 -3
- package/build/modern/useQueryClient.js.map +1 -1
- package/build/modern/utils.cjs +54 -6
- package/build/modern/utils.cjs.map +1 -1
- package/build/modern/utils.d.cts +34 -7
- package/build/modern/utils.d.cts.map +1 -1
- package/build/modern/utils.d.ts +34 -7
- package/build/modern/utils.d.ts.map +1 -1
- package/build/modern/utils.js +54 -6
- package/build/modern/utils.js.map +1 -1
- package/build/modern/vueQueryPlugin.cjs +0 -3
- package/build/modern/vueQueryPlugin.cjs.map +1 -1
- package/build/modern/vueQueryPlugin.d.cts +6 -5
- package/build/modern/vueQueryPlugin.d.cts.map +1 -1
- package/build/modern/vueQueryPlugin.d.ts +6 -5
- package/build/modern/vueQueryPlugin.d.ts.map +1 -1
- package/build/modern/vueQueryPlugin.js +0 -3
- package/build/modern/vueQueryPlugin.js.map +1 -1
- package/package.json +4 -5
- package/src/devtools/devtools.ts +6 -0
- package/src/devtools/utils.ts +21 -0
- package/src/index.ts +5 -1
- package/src/infiniteQueryOptions.ts +2 -8
- package/src/mutationCache.ts +4 -2
- package/src/mutationOptions.ts +4 -12
- package/src/queryCache.ts +6 -2
- package/src/queryClient.ts +55 -52
- package/src/queryOptions.ts +22 -25
- package/src/types.ts +47 -2
- package/src/useBaseQuery.ts +8 -2
- package/src/useInfiniteQuery.ts +15 -14
- package/src/useIsFetching.ts +6 -4
- package/src/useMutation.ts +15 -9
- package/src/useMutationState.ts +23 -7
- package/src/usePrefetchInfiniteQuery.ts +9 -3
- package/src/usePrefetchQuery.ts +9 -3
- package/src/useQueries.ts +1 -4
- package/src/useQuery.ts +10 -12
- package/src/useQueryClient.ts +3 -3
- package/src/utils.ts +55 -9
- package/src/vueQueryPlugin.ts +4 -3
- package/build/legacy/infiniteQueryOptions-CnTRbIP5.d.cts.map +0 -1
- package/build/legacy/infiniteQueryOptions-NucMX_M_.d.ts.map +0 -1
- package/build/legacy/queryClient-B6mLtXOj.d.ts.map +0 -1
- package/build/legacy/queryClient-Bn2Ql_Lu.d.cts.map +0 -1
- package/build/legacy/queryOptions-CsM5TXD2.d.ts.map +0 -1
- package/build/legacy/queryOptions-CwqQgQmQ.d.cts.map +0 -1
- package/build/legacy/types-JpJB72CS.d.cts.map +0 -1
- package/build/legacy/types-JpJB72CS.d.ts.map +0 -1
- package/build/modern/infiniteQueryOptions-CnTRbIP5.d.cts.map +0 -1
- package/build/modern/infiniteQueryOptions-NucMX_M_.d.ts.map +0 -1
- package/build/modern/queryClient-B6mLtXOj.d.ts.map +0 -1
- package/build/modern/queryClient-Bn2Ql_Lu.d.cts.map +0 -1
- package/build/modern/queryOptions-CsM5TXD2.d.ts.map +0 -1
- package/build/modern/queryOptions-CwqQgQmQ.d.cts.map +0 -1
- package/build/modern/types-JpJB72CS.d.cts.map +0 -1
- 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-
|
|
2
|
-
import { t as QueryClient$1 } from "./queryClient-
|
|
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
|
-
|
|
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":"
|
|
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-
|
|
2
|
-
import { t as QueryClient$1 } from "./queryClient-
|
|
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
|
-
|
|
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":"
|
|
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
|
|
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-
|
|
2
|
-
import { t as QueryClient$1 } from "./queryClient-
|
|
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
|
|
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"}
|