@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
package/src/useInfiniteQuery.ts
CHANGED
|
@@ -24,6 +24,11 @@ import type {
|
|
|
24
24
|
} from './types'
|
|
25
25
|
import type { QueryClient } from './queryClient'
|
|
26
26
|
|
|
27
|
+
/**
|
|
28
|
+
* The options accepted by `useInfiniteQuery`. Same as {@link InfiniteQueryObserverOptions} from
|
|
29
|
+
* `@tanstack/query-core`, plus the `shallow` option. Each option except `shallow` can also be a `ref` (and
|
|
30
|
+
* `enabled` a reactive getter).
|
|
31
|
+
*/
|
|
27
32
|
export type UseInfiniteQueryOptions<
|
|
28
33
|
TQueryFnData = unknown,
|
|
29
34
|
TError = DefaultError,
|
|
@@ -62,6 +67,10 @@ export type UseInfiniteQueryOptions<
|
|
|
62
67
|
} & ShallowOption
|
|
63
68
|
>
|
|
64
69
|
|
|
70
|
+
/**
|
|
71
|
+
* The result of `useInfiniteQuery`: {@link InfiniteQueryObserverResult} from `@tanstack/query-core`, with
|
|
72
|
+
* its properties wrapped in `Ref`s as in {@link UseBaseQueryReturnType}.
|
|
73
|
+
*/
|
|
65
74
|
export type UseInfiniteQueryReturnType<TData, TError> = UseBaseQueryReturnType<
|
|
66
75
|
TData,
|
|
67
76
|
TError,
|
|
@@ -78,10 +87,6 @@ export type UseInfiniteQueryReturnType<TData, TError> = UseBaseQueryReturnType<
|
|
|
78
87
|
* `enabled` tracks reactive dependencies automatically as a `ref`, a plain value, or a reactive getter
|
|
79
88
|
* (`() => ...`). `queryKey` reacts through a `ref` for the array itself, or `ref`s and reactive getters as
|
|
80
89
|
* individual entries — the array itself can't be a bare getter.
|
|
81
|
-
*
|
|
82
|
-
* @remarks Keep in mind that imperative fetch calls, such as `fetchNextPage`, may interfere with the default
|
|
83
|
-
* refetch behavior, resulting in outdated data. Make sure to call these functions only in response to user
|
|
84
|
-
* actions, or add conditions like `hasNextPage && !isFetching`.
|
|
85
90
|
* @param options - The {@link DefinedInitialDataInfiniteOptions} to use — everything you can pass to
|
|
86
91
|
* `useInfiniteQuery`, with `initialData` set.
|
|
87
92
|
* @param queryClient - Use this to use a custom `QueryClient`. Otherwise, the one provided by `VueQueryPlugin`
|
|
@@ -90,7 +95,9 @@ export type UseInfiniteQueryReturnType<TData, TError> = UseBaseQueryReturnType<
|
|
|
90
95
|
* `hasNextPage`, `hasPreviousPage`, `isFetchingNextPage`, and `isFetchingPreviousPage`. `data.value.pages` and
|
|
91
96
|
* `data.value.pageParams` are also added, as long as a `select` doesn't change `TData` away from its default
|
|
92
97
|
* `InfiniteData<TQueryFnData>` shape.
|
|
93
|
-
*
|
|
98
|
+
* @remarks Keep in mind that imperative fetch calls, such as `fetchNextPage`, may interfere with the default
|
|
99
|
+
* refetch behavior, resulting in outdated data. Make sure to call these functions only in response to user
|
|
100
|
+
* actions, or add conditions like `hasNextPage && !isFetching`.
|
|
94
101
|
* @example
|
|
95
102
|
* ```vue
|
|
96
103
|
* <script setup lang="ts">
|
|
@@ -143,10 +150,6 @@ export function useInfiniteQuery<
|
|
|
143
150
|
* `enabled` tracks reactive dependencies automatically as a `ref`, a plain value, or a reactive getter
|
|
144
151
|
* (`() => ...`). `queryKey` reacts through a `ref` for the array itself, or `ref`s and reactive getters as
|
|
145
152
|
* individual entries — the array itself can't be a bare getter.
|
|
146
|
-
*
|
|
147
|
-
* @remarks Keep in mind that imperative fetch calls, such as `fetchNextPage`, may interfere with the default
|
|
148
|
-
* refetch behavior, resulting in outdated data. Make sure to call these functions only in response to user
|
|
149
|
-
* actions, or add conditions like `hasNextPage && !isFetching`.
|
|
150
153
|
* @param options - The {@link UndefinedInitialDataInfiniteOptions} to use — everything you can pass to
|
|
151
154
|
* `useInfiniteQuery`.
|
|
152
155
|
* @param queryClient - Use this to use a custom `QueryClient`. Otherwise, the one provided by `VueQueryPlugin`
|
|
@@ -155,7 +158,9 @@ export function useInfiniteQuery<
|
|
|
155
158
|
* `hasNextPage`, `hasPreviousPage`, `isFetchingNextPage`, and `isFetchingPreviousPage`. `data.value.pages` and
|
|
156
159
|
* `data.value.pageParams` are also added, as long as a `select` doesn't change `TData` away from its default
|
|
157
160
|
* `InfiniteData<TQueryFnData>` shape.
|
|
158
|
-
*
|
|
161
|
+
* @remarks Keep in mind that imperative fetch calls, such as `fetchNextPage`, may interfere with the default
|
|
162
|
+
* refetch behavior, resulting in outdated data. Make sure to call these functions only in response to user
|
|
163
|
+
* actions, or add conditions like `hasNextPage && !isFetching`.
|
|
159
164
|
* @example
|
|
160
165
|
* Fetching the next page from a "Load More" button click:
|
|
161
166
|
* ```vue
|
|
@@ -194,7 +199,6 @@ export function useInfiniteQuery<
|
|
|
194
199
|
* </template>
|
|
195
200
|
* </template>
|
|
196
201
|
* ```
|
|
197
|
-
*
|
|
198
202
|
* @example
|
|
199
203
|
* Fetching the next page automatically as the user scrolls, using an `IntersectionObserver` on a
|
|
200
204
|
* sentinel element after the list:
|
|
@@ -278,14 +282,12 @@ export function useInfiniteQuery<
|
|
|
278
282
|
* `enabled` tracks reactive dependencies automatically as a `ref`, a plain value, or a reactive getter
|
|
279
283
|
* (`() => ...`). `queryKey` reacts through a `ref` for the array itself, or `ref`s and reactive getters as
|
|
280
284
|
* individual entries — the array itself can't be a bare getter.
|
|
281
|
-
*
|
|
282
285
|
* @param options - A `ref`, plain value, or reactive getter resolving to the {@link UseInfiniteQueryOptions} to
|
|
283
286
|
* use.
|
|
284
287
|
* @param queryClient - Use this to use a custom `QueryClient`. Otherwise, the one provided by `VueQueryPlugin`
|
|
285
288
|
* will be used.
|
|
286
289
|
* @returns The same properties as `useQuery`, with the addition of `fetchNextPage`, `fetchPreviousPage`,
|
|
287
290
|
* `hasNextPage`, `hasPreviousPage`, `isFetchingNextPage`, and `isFetchingPreviousPage`.
|
|
288
|
-
*
|
|
289
291
|
* @example
|
|
290
292
|
* Passing a whole-options getter so `maxPages` reacts to a setting stored elsewhere, not just `queryKey`:
|
|
291
293
|
* ```vue
|
|
@@ -309,7 +311,6 @@ export function useInfiniteQuery<
|
|
|
309
311
|
* </template>
|
|
310
312
|
* </template>
|
|
311
313
|
* ```
|
|
312
|
-
*
|
|
313
314
|
* @example
|
|
314
315
|
* A query that's disabled, type-safe, until `postId` is set — pass `skipToken` as `queryFn` instead of
|
|
315
316
|
* setting `enabled: false`. This requires a whole-options getter: `queryFn` isn't itself reactive, so the
|
package/src/useIsFetching.ts
CHANGED
|
@@ -6,8 +6,13 @@ import type { QueryFilters } from '@tanstack/query-core'
|
|
|
6
6
|
import type { MaybeRefDeep } from './types'
|
|
7
7
|
import type { QueryClient } from './queryClient'
|
|
8
8
|
|
|
9
|
+
/**
|
|
10
|
+
* The filters accepted by `useIsFetching`: {@link QueryFilters} as a plain object, a `ref`, or a reactive
|
|
11
|
+
* getter.
|
|
12
|
+
*/
|
|
9
13
|
export type UseIsFetchingFilters =
|
|
10
|
-
|
|
14
|
+
| MaybeRefDeep<QueryFilters>
|
|
15
|
+
| (() => MaybeRefDeep<QueryFilters>)
|
|
11
16
|
|
|
12
17
|
/**
|
|
13
18
|
* The `useIsFetching` composable returns a `ref` to the `number` of the queries that your application is
|
|
@@ -15,13 +20,11 @@ export type UseIsFetchingFilters =
|
|
|
15
20
|
*
|
|
16
21
|
* `fetchingFilters` may be a plain object, `MaybeRefDeep`, or a reactive getter (`() => ({ ... })`) — pass a
|
|
17
22
|
* getter if the filters themselves depend on other reactive state.
|
|
18
|
-
*
|
|
19
23
|
* @param fetchingFilters - The {@link QueryFilters} to narrow down the matched queries.
|
|
20
24
|
* @param queryClient - Use this to use a custom `QueryClient`. Otherwise, the one provided by `VueQueryPlugin`
|
|
21
25
|
* will be used.
|
|
22
26
|
* @returns A `ref` to the `number` of the queries that your application is currently loading or fetching in
|
|
23
27
|
* the background.
|
|
24
|
-
*
|
|
25
28
|
* @example
|
|
26
29
|
* ```vue
|
|
27
30
|
* <script setup lang="ts">
|
|
@@ -35,7 +38,6 @@ export type UseIsFetchingFilters =
|
|
|
35
38
|
* <span v-if="isFetchingPosts">Refreshing posts...</span>
|
|
36
39
|
* </template>
|
|
37
40
|
* ```
|
|
38
|
-
*
|
|
39
41
|
* @example
|
|
40
42
|
* A global loading indicator for any query fetching in the background, not just the ones on screen:
|
|
41
43
|
* ```vue
|
package/src/useMutation.ts
CHANGED
|
@@ -22,12 +22,20 @@ import type {
|
|
|
22
22
|
import type { MaybeRefDeep, MutationOptions } from './types'
|
|
23
23
|
import type { QueryClient } from './queryClient'
|
|
24
24
|
|
|
25
|
-
|
|
25
|
+
/**
|
|
26
|
+
* The {@link MutationObserverResult} properties without `mutate` and `reset`, which `useMutation` replaces with
|
|
27
|
+
* its own versions.
|
|
28
|
+
*/
|
|
29
|
+
export type MutationResult<TData, TError, TVariables, TOnMutateResult> =
|
|
26
30
|
DistributiveOmit<
|
|
27
31
|
MutationObserverResult<TData, TError, TVariables, TOnMutateResult>,
|
|
28
32
|
'mutate' | 'reset'
|
|
29
33
|
>
|
|
30
34
|
|
|
35
|
+
/**
|
|
36
|
+
* The options accepted by `useMutation`: {@link MutationOptions} as a plain object, a `ref`, or a reactive
|
|
37
|
+
* getter.
|
|
38
|
+
*/
|
|
31
39
|
export type UseMutationOptions<
|
|
32
40
|
TData = unknown,
|
|
33
41
|
TError = DefaultError,
|
|
@@ -50,6 +58,10 @@ type MutateSyncFunction<
|
|
|
50
58
|
>
|
|
51
59
|
) => void
|
|
52
60
|
|
|
61
|
+
/**
|
|
62
|
+
* The result of `useMutation`: the {@link MutationObserverResult} properties wrapped in `Ref`s, plus the
|
|
63
|
+
* fire-and-forget `mutate`, the awaitable `mutateAsync`, and `reset`.
|
|
64
|
+
*/
|
|
53
65
|
export type UseMutationReturnType<
|
|
54
66
|
TData,
|
|
55
67
|
TError,
|
|
@@ -73,9 +85,6 @@ export type UseMutationReturnType<
|
|
|
73
85
|
*
|
|
74
86
|
* `options` may be a plain object, a `ref`, or a reactive getter (`() => ({ ... })`) — pass a getter
|
|
75
87
|
* if the options themselves depend on other reactive state.
|
|
76
|
-
*
|
|
77
|
-
* @see {@link mutationOptions} to share these options across multiple `useMutation` call sites, or to look
|
|
78
|
-
* the mutation up elsewhere via its `mutationKey` (e.g. with `useMutationState`).
|
|
79
88
|
* @param options - The {@link UseMutationOptions} to use — everything you can pass to `useMutation`.
|
|
80
89
|
* @param queryClient - Use this to use a custom `QueryClient`. Otherwise, the one provided by `VueQueryPlugin`
|
|
81
90
|
* will be used.
|
|
@@ -83,7 +92,8 @@ export type UseMutationReturnType<
|
|
|
83
92
|
* argument, useful for triggering call-site side effects (e.g. navigation) without coupling them to the shared
|
|
84
93
|
* mutation definition. Hook-level callbacks (passed to `options`) fire for every mutation; per-call
|
|
85
94
|
* callbacks fire only for the latest call you've made.
|
|
86
|
-
*
|
|
95
|
+
* @see {@link mutationOptions} to share these options across multiple `useMutation` call sites, or to look
|
|
96
|
+
* the mutation up elsewhere via its `mutationKey` (e.g. with `useMutationState`).
|
|
87
97
|
* @example
|
|
88
98
|
* ```vue
|
|
89
99
|
* <script setup lang="ts">
|
|
@@ -107,7 +117,6 @@ export type UseMutationReturnType<
|
|
|
107
117
|
* <button @click="onAdd">Add</button>
|
|
108
118
|
* </template>
|
|
109
119
|
* ```
|
|
110
|
-
*
|
|
111
120
|
* @example
|
|
112
121
|
* Rendering the mutation's own state, rather than just firing it off:
|
|
113
122
|
* ```vue
|
|
@@ -130,7 +139,6 @@ export type UseMutationReturnType<
|
|
|
130
139
|
* </div>
|
|
131
140
|
* </template>
|
|
132
141
|
* ```
|
|
133
|
-
*
|
|
134
142
|
* @example
|
|
135
143
|
* Optimistic update via `onMutate`, rolling back on `onError`:
|
|
136
144
|
* ```vue
|
|
@@ -166,7 +174,6 @@ export type UseMutationReturnType<
|
|
|
166
174
|
* <button @click="addMutation.mutate('Item')">Add</button>
|
|
167
175
|
* </template>
|
|
168
176
|
* ```
|
|
169
|
-
*
|
|
170
177
|
* @example
|
|
171
178
|
* Callbacks passed per call to `mutate` only fire for the last call — `mutateAsync` gives you a
|
|
172
179
|
* promise per call instead, so you can wait for all of them when they succeed:
|
|
@@ -194,7 +201,6 @@ export type UseMutationReturnType<
|
|
|
194
201
|
* <button @click="handleAddAll(['Todo 1', 'Todo 2', 'Todo 3'])">Add all</button>
|
|
195
202
|
* </template>
|
|
196
203
|
* ```
|
|
197
|
-
*
|
|
198
204
|
* @example
|
|
199
205
|
* If some of the mutations above can fail independently of the others, and you want to know which ones
|
|
200
206
|
* did — rather than losing that information the moment the first one rejects — swap `Promise.all` for
|
package/src/useMutationState.ts
CHANGED
|
@@ -20,8 +20,13 @@ import type { MutationCache } from './mutationCache'
|
|
|
20
20
|
|
|
21
21
|
type VueMutationFilters = MaybeRefDeep<MutationFilters>
|
|
22
22
|
|
|
23
|
+
/**
|
|
24
|
+
* The filters accepted by `useIsMutating`: {@link MutationFilters} as a plain object, a `ref`, or a reactive
|
|
25
|
+
* getter.
|
|
26
|
+
*/
|
|
23
27
|
export type UseIsMutatingFilters =
|
|
24
|
-
|
|
28
|
+
| VueMutationFilters
|
|
29
|
+
| (() => VueMutationFilters)
|
|
25
30
|
|
|
26
31
|
/**
|
|
27
32
|
* The `useIsMutating` composable returns a `ref` to the `number` of mutations that your application currently
|
|
@@ -29,12 +34,10 @@ export type UseIsMutatingFilters =
|
|
|
29
34
|
*
|
|
30
35
|
* `filters` may be a plain object, `MaybeRefDeep`, or a reactive getter (`() => ({ ... })`) — pass a getter if
|
|
31
36
|
* the filters themselves depend on other reactive state.
|
|
32
|
-
*
|
|
33
37
|
* @param filters - The {@link MutationFilters} to narrow down the matched mutations.
|
|
34
38
|
* @param queryClient - Use this to use a custom `QueryClient`. Otherwise, the one provided by `VueQueryPlugin`
|
|
35
39
|
* will be used.
|
|
36
40
|
* @returns A `ref` to the `number` of the mutations that your application currently has `pending`.
|
|
37
|
-
*
|
|
38
41
|
* @example
|
|
39
42
|
* ```vue
|
|
40
43
|
* <script setup lang="ts">
|
|
@@ -88,15 +91,32 @@ type MutationTypeFromResult<TResult> = [TResult] extends [
|
|
|
88
91
|
? Mutation<TData, TError, TVariables, TOnMutateResult>
|
|
89
92
|
: Mutation
|
|
90
93
|
|
|
94
|
+
/**
|
|
95
|
+
* The options accepted by `useMutationState`: the `filters` matching the mutations, and `select` to map each
|
|
96
|
+
* one (to its state, by default).
|
|
97
|
+
*/
|
|
91
98
|
export type MutationStateOptions<
|
|
92
99
|
TResult = MutationState,
|
|
93
100
|
TMutation extends Mutation<any, any, any, any> =
|
|
94
101
|
MutationTypeFromResult<TResult>,
|
|
95
102
|
> = {
|
|
103
|
+
/**
|
|
104
|
+
* The filters that select the mutations to return the state of.
|
|
105
|
+
*/
|
|
96
106
|
filters?: VueMutationFilters
|
|
107
|
+
/**
|
|
108
|
+
* Maps each matching mutation to the value returned for it. Defaults to the mutation's `state`.
|
|
109
|
+
*/
|
|
97
110
|
select?: (mutation: TMutation) => TResult
|
|
98
111
|
}
|
|
99
112
|
|
|
113
|
+
/**
|
|
114
|
+
* Collects the mutations in the cache that match `options.filters`, mapped with `options.select`
|
|
115
|
+
* (or to their state, by default).
|
|
116
|
+
* @param mutationCache - The mutation cache to read.
|
|
117
|
+
* @param options - The `filters` to match and the `select` function to map each mutation with.
|
|
118
|
+
* @returns The selected value of every matching mutation.
|
|
119
|
+
*/
|
|
100
120
|
function getResult<
|
|
101
121
|
TResult = MutationState,
|
|
102
122
|
TMutation extends Mutation<any, any, any, any> =
|
|
@@ -122,13 +142,11 @@ function getResult<
|
|
|
122
142
|
*
|
|
123
143
|
* `options` may be a plain object or a reactive getter (`() => ({ ... })`) — pass a getter if the filters
|
|
124
144
|
* themselves depend on other reactive state.
|
|
125
|
-
*
|
|
126
145
|
* @param options - The `filters` to narrow down matched mutations, and an optional `select` to transform the
|
|
127
146
|
* mutation state.
|
|
128
147
|
* @param queryClient - Use this to use a custom `QueryClient`. Otherwise, the one provided by `VueQueryPlugin`
|
|
129
148
|
* will be used.
|
|
130
149
|
* @returns A `ref` to an Array of whatever `select` returns for each matching mutation.
|
|
131
|
-
*
|
|
132
150
|
* @example
|
|
133
151
|
* Get all variables of all running mutations:
|
|
134
152
|
* ```vue
|
|
@@ -143,7 +161,6 @@ function getResult<
|
|
|
143
161
|
*
|
|
144
162
|
* <template>{{ pendingVariables.length }} posts saving...</template>
|
|
145
163
|
* ```
|
|
146
|
-
*
|
|
147
164
|
* @example
|
|
148
165
|
* Get all data for specific mutations via the `mutationKey`:
|
|
149
166
|
* ```vue
|
|
@@ -171,7 +188,6 @@ function getResult<
|
|
|
171
188
|
* </button>
|
|
172
189
|
* </template>
|
|
173
190
|
* ```
|
|
174
|
-
*
|
|
175
191
|
* @example
|
|
176
192
|
* Access the latest successful mutation data via the `mutationKey`. Each invocation of `mutate` adds a new
|
|
177
193
|
* entry to the mutation cache for `gcTime` milliseconds — with the `status: 'success'` filter below, check the
|
|
@@ -13,6 +13,10 @@ import type {
|
|
|
13
13
|
import type { QueryClient } from './queryClient'
|
|
14
14
|
import type { MaybeRefDeep, MaybeRefOrGetter } from './types'
|
|
15
15
|
|
|
16
|
+
/**
|
|
17
|
+
* The options accepted by `usePrefetchInfiniteQuery` — everything you can pass to `queryClient.infiniteQuery`,
|
|
18
|
+
* except that `queryFn` can't be `skipToken`.
|
|
19
|
+
*/
|
|
16
20
|
export type UsePrefetchInfiniteQueryOptions<
|
|
17
21
|
TQueryFnData,
|
|
18
22
|
TError,
|
|
@@ -41,6 +45,11 @@ export type UsePrefetchInfiniteQueryOptions<
|
|
|
41
45
|
>
|
|
42
46
|
}
|
|
43
47
|
|
|
48
|
+
/**
|
|
49
|
+
* Checks whether an option was passed as a getter function.
|
|
50
|
+
* @param value - The option value.
|
|
51
|
+
* @returns `true` if `value` is a function.
|
|
52
|
+
*/
|
|
44
53
|
function isGetter<T>(value: MaybeRefOrGetter<T>): value is () => T {
|
|
45
54
|
return typeof value === 'function'
|
|
46
55
|
}
|
|
@@ -62,13 +71,10 @@ function isGetter<T>(value: MaybeRefOrGetter<T>): value is () => T {
|
|
|
62
71
|
*
|
|
63
72
|
* Fire this during render, before a suspense boundary that wraps a component using `useInfiniteQuery`'s
|
|
64
73
|
* `suspense()` — see the {@link https://tanstack.com/query/latest/docs/framework/vue/guides/suspense | Suspense guide}.
|
|
65
|
-
*
|
|
66
74
|
* @param options - A `ref`, plain value, or reactive getter resolving to the
|
|
67
75
|
* {@link UsePrefetchInfiniteQueryOptions} to use — everything you can pass to `queryClient.infiniteQuery`.
|
|
68
76
|
* @param queryClient - Use this to use a custom `QueryClient`. Otherwise, the one provided by `VueQueryPlugin`
|
|
69
77
|
* will be used.
|
|
70
|
-
* @returns `void` — nothing is returned.
|
|
71
|
-
*
|
|
72
78
|
* @example
|
|
73
79
|
* ```vue
|
|
74
80
|
* <script setup lang="ts">
|
package/src/usePrefetchQuery.ts
CHANGED
|
@@ -12,6 +12,10 @@ import type {
|
|
|
12
12
|
import type { QueryClient } from './queryClient'
|
|
13
13
|
import type { MaybeRefDeep, MaybeRefOrGetter } from './types'
|
|
14
14
|
|
|
15
|
+
/**
|
|
16
|
+
* The options accepted by `usePrefetchQuery` — everything you can pass to `queryClient.query`, except that
|
|
17
|
+
* `queryFn` can't be `skipToken`.
|
|
18
|
+
*/
|
|
15
19
|
export type UsePrefetchQueryOptions<
|
|
16
20
|
TQueryFnData,
|
|
17
21
|
TError,
|
|
@@ -42,6 +46,11 @@ export type UsePrefetchQueryOptions<
|
|
|
42
46
|
>
|
|
43
47
|
}
|
|
44
48
|
|
|
49
|
+
/**
|
|
50
|
+
* Checks whether an option was passed as a getter function.
|
|
51
|
+
* @param value - The option value.
|
|
52
|
+
* @returns `true` if `value` is a function.
|
|
53
|
+
*/
|
|
45
54
|
function isGetter<T>(value: MaybeRefOrGetter<T>): value is () => T {
|
|
46
55
|
return typeof value === 'function'
|
|
47
56
|
}
|
|
@@ -58,13 +67,10 @@ function isGetter<T>(value: MaybeRefOrGetter<T>): value is () => T {
|
|
|
58
67
|
*
|
|
59
68
|
* Fire this during render, before a suspense boundary that wraps a component using `useQuery`'s `suspense()`
|
|
60
69
|
* — see the {@link https://tanstack.com/query/latest/docs/framework/vue/guides/suspense | Suspense guide}.
|
|
61
|
-
*
|
|
62
70
|
* @param options - A `ref`, plain value, or reactive getter resolving to the {@link UsePrefetchQueryOptions} to
|
|
63
71
|
* use — everything you can pass to `queryClient.query`.
|
|
64
72
|
* @param queryClient - Use this to use a custom `QueryClient`. Otherwise, the one provided by `VueQueryPlugin`
|
|
65
73
|
* will be used.
|
|
66
|
-
* @returns `void` — nothing is returned.
|
|
67
|
-
*
|
|
68
74
|
* @example
|
|
69
75
|
* ```vue
|
|
70
76
|
* <script setup lang="ts">
|
package/src/useQueries.ts
CHANGED
|
@@ -247,12 +247,11 @@ type UseQueriesOptionsArg<T extends Array<any>> = readonly [
|
|
|
247
247
|
*
|
|
248
248
|
* `placeholderData` is supported here too, but unlike `useQuery`, it doesn't receive information from
|
|
249
249
|
* previously rendered queries, because the number of queries can differ between renders.
|
|
250
|
-
*
|
|
250
|
+
* @param options - The `queries` array to run, and the optional `combine` and `shallow` options.
|
|
251
251
|
* @param queryClient - Use this to use a custom `QueryClient`. Otherwise, the one provided by `VueQueryPlugin`
|
|
252
252
|
* will be used.
|
|
253
253
|
* @returns A `ref` to the combined result. Without `combine`, this is an array with all the query results, in
|
|
254
254
|
* the same order as the input. When `combine` is provided, this is the value returned by `combine` instead.
|
|
255
|
-
*
|
|
256
255
|
* @example
|
|
257
256
|
* ```vue
|
|
258
257
|
* <script setup lang="ts">
|
|
@@ -280,7 +279,6 @@ type UseQueriesOptionsArg<T extends Array<any>> = readonly [
|
|
|
280
279
|
* </ul>
|
|
281
280
|
* </template>
|
|
282
281
|
* ```
|
|
283
|
-
*
|
|
284
282
|
* @example
|
|
285
283
|
* Combining results into a single value:
|
|
286
284
|
* ```vue
|
|
@@ -311,7 +309,6 @@ type UseQueriesOptionsArg<T extends Array<any>> = readonly [
|
|
|
311
309
|
* </ul>
|
|
312
310
|
* </template>
|
|
313
311
|
* ```
|
|
314
|
-
*
|
|
315
312
|
* @example
|
|
316
313
|
* Typing `select` via {@link queryOptions}. Note that spreading a `queryOptions` result and overriding
|
|
317
314
|
* `select` inline still falls back to `unknown` — wrap the spread in `queryOptions` again so the override is
|
package/src/useQuery.ts
CHANGED
|
@@ -14,11 +14,19 @@ import type {
|
|
|
14
14
|
UseQueryOptions,
|
|
15
15
|
} from './queryOptions'
|
|
16
16
|
|
|
17
|
+
/**
|
|
18
|
+
* The result of `useQuery` when `initialData` is omitted or may be `undefined` — `data` may be `undefined`
|
|
19
|
+
* while the query is `pending`. See {@link UseBaseQueryReturnType}.
|
|
20
|
+
*/
|
|
17
21
|
export type UseQueryReturnType<TData, TError> = UseBaseQueryReturnType<
|
|
18
22
|
TData,
|
|
19
23
|
TError
|
|
20
24
|
>
|
|
21
25
|
|
|
26
|
+
/**
|
|
27
|
+
* The result of `useQuery` when `initialData` is set — `data` is never `undefined` (unless a `select` changes
|
|
28
|
+
* `TData` to include `undefined`).
|
|
29
|
+
*/
|
|
22
30
|
export type UseQueryDefinedReturnType<TData, TError> = UseBaseQueryReturnType<
|
|
23
31
|
TData,
|
|
24
32
|
TError,
|
|
@@ -33,7 +41,6 @@ export type UseQueryDefinedReturnType<TData, TError> = UseBaseQueryReturnType<
|
|
|
33
41
|
* (`() => ...`). `queryKey` reacts through a `ref` or a reactive getter for the array itself, or `ref`s and
|
|
34
42
|
* reactive getters as individual entries. Other options are read once when passed as a plain value, and stay
|
|
35
43
|
* reactive when passed as a `ref` or a `computed`.
|
|
36
|
-
*
|
|
37
44
|
* @param options - The {@link DefinedInitialQueryOptions} to use — everything you can pass to `useQuery`, with
|
|
38
45
|
* `initialData` set.
|
|
39
46
|
* @param queryClient - Use this to use a custom `QueryClient`. Otherwise, the one provided by `VueQueryPlugin`
|
|
@@ -41,7 +48,6 @@ export type UseQueryDefinedReturnType<TData, TError> = UseBaseQueryReturnType<
|
|
|
41
48
|
* @returns The current query result, typed so that `data` is never `undefined` (unless a `select` changes
|
|
42
49
|
* `TData` to include `undefined`). `status` never resolves to `pending` in this overload's type, since
|
|
43
50
|
* `initialData` guarantees data upfront.
|
|
44
|
-
*
|
|
45
51
|
* @example
|
|
46
52
|
* ```vue
|
|
47
53
|
* <script setup lang="ts">
|
|
@@ -79,13 +85,11 @@ export function useQuery<
|
|
|
79
85
|
* (`() => ...`). `queryKey` reacts through a `ref` or a reactive getter for the array itself, or `ref`s and
|
|
80
86
|
* reactive getters as individual entries. Other options are read once when passed as a plain value, and stay
|
|
81
87
|
* reactive when passed as a `ref` or a `computed`.
|
|
82
|
-
*
|
|
83
88
|
* @param options - The {@link UndefinedInitialQueryOptions} to use — everything you can pass to `useQuery`.
|
|
84
89
|
* @param queryClient - Use this to use a custom `QueryClient`. Otherwise, the one provided by `VueQueryPlugin`
|
|
85
90
|
* will be used.
|
|
86
91
|
* @returns The current query result. `status` is `pending` if there is no cached data to display, `error` if
|
|
87
92
|
* the last fetch attempt failed, or `success` if the query has data to display.
|
|
88
|
-
*
|
|
89
93
|
* @example
|
|
90
94
|
* A query key built from a reactive `ref` — the query refetches whenever `postId` changes:
|
|
91
95
|
* ```vue
|
|
@@ -106,7 +110,6 @@ export function useQuery<
|
|
|
106
110
|
* <h1 v-else>{{ data.title }}</h1>
|
|
107
111
|
* </template>
|
|
108
112
|
* ```
|
|
109
|
-
*
|
|
110
113
|
* @example
|
|
111
114
|
* `select` derives whatever `data` a component needs from the cached value, without changing what's
|
|
112
115
|
* actually stored in the cache — the cache still holds the full `Post[]`, but `data` here is a `number`:
|
|
@@ -127,7 +130,6 @@ export function useQuery<
|
|
|
127
130
|
* <span v-else>{{ data }} posts</span>
|
|
128
131
|
* </template>
|
|
129
132
|
* ```
|
|
130
|
-
*
|
|
131
133
|
* @example
|
|
132
134
|
* A dependent query, only enabled once `postId` is set — use `isLoading`, not `isPending`, so the
|
|
133
135
|
* loading state doesn't show while the query is disabled:
|
|
@@ -152,7 +154,6 @@ export function useQuery<
|
|
|
152
154
|
* <h1 v-else>{{ data?.title }}</h1>
|
|
153
155
|
* </template>
|
|
154
156
|
* ```
|
|
155
|
-
*
|
|
156
157
|
* @example
|
|
157
158
|
* Seeding a detail query from an already-cached list, to skip the loading state. `initialDataUpdatedAt` carries
|
|
158
159
|
* over the list's own fetch time, so that if you set a `staleTime`, it's measured from when the list was
|
|
@@ -181,7 +182,6 @@ export function useQuery<
|
|
|
181
182
|
* <h1 v-else>{{ data?.title }}</h1>
|
|
182
183
|
* </template>
|
|
183
184
|
* ```
|
|
184
|
-
*
|
|
185
185
|
* @example
|
|
186
186
|
* Paginated data, keeping the previous page's data visible while the next page loads:
|
|
187
187
|
* ```vue
|
|
@@ -230,12 +230,10 @@ export function useQuery<
|
|
|
230
230
|
*
|
|
231
231
|
* When `options` itself is a reactive getter, the whole object is re-evaluated on every change to its
|
|
232
232
|
* dependencies, so any option inside it — not just `queryKey` and `enabled` — can change over time.
|
|
233
|
-
*
|
|
234
233
|
* @param options - A `ref`, plain value, or reactive getter resolving to the {@link UseQueryOptions} to use.
|
|
235
234
|
* @param queryClient - Use this to use a custom `QueryClient`. Otherwise, the one provided by `VueQueryPlugin`
|
|
236
235
|
* will be used.
|
|
237
236
|
* @returns The current query result, with `data` typed as possibly `undefined`.
|
|
238
|
-
*
|
|
239
237
|
* @example
|
|
240
238
|
* Passing a whole-options getter so `staleTime` reacts to a setting stored elsewhere, not just `queryKey`:
|
|
241
239
|
* ```vue
|
|
@@ -255,7 +253,6 @@ export function useQuery<
|
|
|
255
253
|
* <h1 v-if="data">{{ data.title }}</h1>
|
|
256
254
|
* </template>
|
|
257
255
|
* ```
|
|
258
|
-
*
|
|
259
256
|
* @example
|
|
260
257
|
* `skipToken` disables the query in a type-safe way, without a non-null assertion on `props.postId` —
|
|
261
258
|
* `queryFn` is only ever called when it's defined. The whole-options getter re-evaluates `queryFn` on every
|
|
@@ -308,6 +305,7 @@ export function useQuery<
|
|
|
308
305
|
>,
|
|
309
306
|
queryClient?: QueryClient,
|
|
310
307
|
):
|
|
311
|
-
|
|
308
|
+
| UseQueryReturnType<TData, TError>
|
|
309
|
+
| UseQueryDefinedReturnType<TData, TError> {
|
|
312
310
|
return useBaseQuery(QueryObserver, options, queryClient)
|
|
313
311
|
}
|
package/src/useQueryClient.ts
CHANGED
|
@@ -6,11 +6,11 @@ import type { QueryClient } from './queryClient'
|
|
|
6
6
|
/**
|
|
7
7
|
* Retrieves the `QueryClient` installed by `VueQueryPlugin`, via Vue's `inject`. Must be called inside
|
|
8
8
|
* `setup()` or another function that supports an injection context.
|
|
9
|
-
*
|
|
10
9
|
* @param id - The `queryClientKey` passed to `VueQueryPlugin` — only needed when multiple `QueryClient`s are
|
|
11
10
|
* installed in the same app.
|
|
12
|
-
* @
|
|
13
|
-
*
|
|
11
|
+
* @returns The installed `QueryClient`.
|
|
12
|
+
* @throws {Error} If called outside an injection context, or if no `QueryClient` was installed via
|
|
13
|
+
* `VueQueryPlugin`.
|
|
14
14
|
* @example
|
|
15
15
|
* ```vue
|
|
16
16
|
* <script setup lang="ts">
|
package/src/utils.ts
CHANGED
|
@@ -1,16 +1,29 @@
|
|
|
1
1
|
import { isRef, unref } from 'vue-demi'
|
|
2
2
|
import type { MaybeRefDeep } from './types'
|
|
3
3
|
|
|
4
|
-
/**
|
|
4
|
+
/**
|
|
5
|
+
* Base Vue injection key `VueQueryPlugin` provides the `QueryClient` under.
|
|
6
|
+
* @internal
|
|
7
|
+
*/
|
|
5
8
|
export const VUE_QUERY_CLIENT = 'VUE_QUERY_CLIENT'
|
|
6
9
|
|
|
7
|
-
/**
|
|
10
|
+
/**
|
|
11
|
+
* Builds the injection key `useQueryClient`/`VueQueryPlugin` use for a given `queryClientKey`.
|
|
12
|
+
* @internal
|
|
13
|
+
* @param key - The `queryClientKey`. Without it, the base key is used.
|
|
14
|
+
* @returns The injection key.
|
|
15
|
+
*/
|
|
8
16
|
export function getClientKey(key?: string) {
|
|
9
17
|
const suffix = key ? `:${key}` : ''
|
|
10
18
|
return `${VUE_QUERY_CLIENT}${suffix}`
|
|
11
19
|
}
|
|
12
20
|
|
|
13
|
-
/**
|
|
21
|
+
/**
|
|
22
|
+
* Copies each property from `update` onto `state`, in place, for every key already on `state`.
|
|
23
|
+
* @internal
|
|
24
|
+
* @param state - The object to update.
|
|
25
|
+
* @param update - The object to copy the values from.
|
|
26
|
+
*/
|
|
14
27
|
export function updateState(
|
|
15
28
|
state: Record<string, any>,
|
|
16
29
|
update: Record<string, any>,
|
|
@@ -20,8 +33,16 @@ export function updateState(
|
|
|
20
33
|
})
|
|
21
34
|
}
|
|
22
35
|
|
|
23
|
-
|
|
24
|
-
|
|
36
|
+
/**
|
|
37
|
+
* Recursive implementation of {@link cloneDeep}, which also tracks the key and nesting level of
|
|
38
|
+
* the current node for `customize`.
|
|
39
|
+
* @param value - The value to clone.
|
|
40
|
+
* @param customize - Called for every node with its key and nesting level. If it returns a value
|
|
41
|
+
* other than `undefined`, that value is used instead of recursing.
|
|
42
|
+
* @param currentKey - The key of the current node.
|
|
43
|
+
* @param currentLevel - The nesting level of the current node.
|
|
44
|
+
* @returns The cloned value.
|
|
45
|
+
*/
|
|
25
46
|
function _cloneDeep<T>(
|
|
26
47
|
value: MaybeRefDeep<T>,
|
|
27
48
|
customize?: (
|
|
@@ -60,9 +81,14 @@ function _cloneDeep<T>(
|
|
|
60
81
|
}
|
|
61
82
|
|
|
62
83
|
/**
|
|
63
|
-
*
|
|
84
|
+
* Deep-clones `value`, recursing into arrays and plain objects. `customize`, if provided, can
|
|
64
85
|
* intercept any node (by key and nesting level) and substitute its own return value instead of recursing
|
|
65
86
|
* further.
|
|
87
|
+
* @internal
|
|
88
|
+
* @param value - The value to clone.
|
|
89
|
+
* @param customize - Called for every node with its key and nesting level. If it returns a value
|
|
90
|
+
* other than `undefined`, that value is used instead of recursing.
|
|
91
|
+
* @returns The cloned value.
|
|
66
92
|
*/
|
|
67
93
|
export function cloneDeep<T>(
|
|
68
94
|
value: MaybeRefDeep<T>,
|
|
@@ -76,10 +102,14 @@ export function cloneDeep<T>(
|
|
|
76
102
|
}
|
|
77
103
|
|
|
78
104
|
/**
|
|
79
|
-
*
|
|
105
|
+
* Deep-clones `value` like {@link cloneDeep}, additionally unwrapping any `ref`s it encounters (and,
|
|
80
106
|
* if `unrefGetters` is `true`, calling any functions it encounters and unwrapping their result too). Always
|
|
81
107
|
* resolves `queryKey` this way, regardless of `unrefGetters` — this is what lets a `queryKey` containing `ref`s
|
|
82
108
|
* be passed straight through to `@tanstack/query-core`.
|
|
109
|
+
* @internal
|
|
110
|
+
* @param obj - The value to clone.
|
|
111
|
+
* @param unrefGetters - Whether to also call functions and unwrap their result.
|
|
112
|
+
* @returns The cloned value, with `ref`s unwrapped.
|
|
83
113
|
*/
|
|
84
114
|
export function cloneDeepUnref<T>(
|
|
85
115
|
obj: MaybeRefDeep<T>,
|
|
@@ -110,7 +140,13 @@ export function cloneDeepUnref<T>(
|
|
|
110
140
|
})
|
|
111
141
|
}
|
|
112
142
|
|
|
113
|
-
|
|
143
|
+
/**
|
|
144
|
+
* Checks whether a value is a plain object, created with an object literal or
|
|
145
|
+
* `Object.create(null)`.
|
|
146
|
+
* @param value - The value to check.
|
|
147
|
+
* @returns `true` if `value` is a plain object.
|
|
148
|
+
*/
|
|
149
|
+
// oxlint-disable-next-line typescript/no-wrapper-object-types
|
|
114
150
|
function isPlainObject(value: unknown): value is Object {
|
|
115
151
|
if (Object.prototype.toString.call(value) !== '[object Object]') {
|
|
116
152
|
return false
|
|
@@ -120,11 +156,21 @@ function isPlainObject(value: unknown): value is Object {
|
|
|
120
156
|
return prototype === null || prototype === Object.prototype
|
|
121
157
|
}
|
|
122
158
|
|
|
159
|
+
/**
|
|
160
|
+
* Checks whether a value is a function.
|
|
161
|
+
* @param value - The value to check.
|
|
162
|
+
* @returns `true` if `value` is a function.
|
|
163
|
+
*/
|
|
123
164
|
function isFunction(value: unknown): value is Function {
|
|
124
165
|
return typeof value === 'function'
|
|
125
166
|
}
|
|
126
167
|
|
|
127
|
-
/**
|
|
168
|
+
/**
|
|
169
|
+
* Resolves `source` to a plain value — calls it if it's a function, otherwise deep-unwraps it.
|
|
170
|
+
* @internal
|
|
171
|
+
* @param source - A getter, or a value that may contain `ref`s.
|
|
172
|
+
* @returns The resolved plain value.
|
|
173
|
+
*/
|
|
128
174
|
export function toValueDeep<T>(source: (() => T) | MaybeRefDeep<T>): T {
|
|
129
175
|
return isFunction(source) ? source() : cloneDeepUnref(source)
|
|
130
176
|
}
|