@tanstack/vue-query 5.0.0-beta.20 → 5.0.0-beta.23
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/index.d.cts +1 -1
- package/build/legacy/index.d.ts +1 -1
- package/build/legacy/types.cjs.map +1 -1
- package/build/legacy/types.d.cts +7 -2
- package/build/legacy/types.d.ts +7 -2
- package/build/legacy/useBaseQuery.cjs +15 -4
- 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 +16 -4
- 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 +7 -0
- package/build/legacy/useIsFetching.cjs.map +1 -1
- package/build/legacy/useIsFetching.js +8 -1
- package/build/legacy/useIsFetching.js.map +1 -1
- package/build/legacy/useMutation.cjs +14 -3
- package/build/legacy/useMutation.cjs.map +1 -1
- package/build/legacy/useMutation.js +15 -3
- package/build/legacy/useMutation.js.map +1 -1
- package/build/legacy/useMutationState.cjs +7 -0
- package/build/legacy/useMutationState.cjs.map +1 -1
- package/build/legacy/useMutationState.js +15 -1
- package/build/legacy/useMutationState.js.map +1 -1
- package/build/legacy/useQueries.cjs +21 -10
- package/build/legacy/useQueries.cjs.map +1 -1
- package/build/legacy/useQueries.d.cts +1 -1
- package/build/legacy/useQueries.d.ts +1 -1
- package/build/legacy/useQueries.js +29 -11
- package/build/legacy/useQueries.js.map +1 -1
- package/build/legacy/{useQuery-ebff9211.d.ts → useQuery-42d67167.d.ts} +6 -6
- package/build/legacy/{useQuery-846c66db.d.ts → useQuery-ac350b9a.d.ts} +6 -6
- package/build/legacy/useQuery.cjs.map +1 -1
- package/build/legacy/useQuery.d.cts +1 -1
- package/build/legacy/useQuery.d.ts +1 -1
- package/build/legacy/useQuery.js.map +1 -1
- package/build/legacy/useQueryClient.cjs +4 -4
- package/build/legacy/useQueryClient.cjs.map +1 -1
- package/build/legacy/useQueryClient.js +5 -5
- package/build/legacy/useQueryClient.js.map +1 -1
- package/build/legacy/vueQueryPlugin.cjs +2 -0
- package/build/legacy/vueQueryPlugin.cjs.map +1 -1
- package/build/legacy/vueQueryPlugin.d.cts +1 -0
- package/build/legacy/vueQueryPlugin.d.ts +1 -0
- package/build/legacy/vueQueryPlugin.js +2 -0
- package/build/legacy/vueQueryPlugin.js.map +1 -1
- package/build/modern/index.d.cts +1 -1
- package/build/modern/index.d.ts +1 -1
- package/build/modern/types.cjs.map +1 -1
- package/build/modern/types.d.cts +7 -2
- package/build/modern/types.d.ts +7 -2
- package/build/modern/useBaseQuery.cjs +15 -4
- 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 +16 -4
- 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 +7 -0
- package/build/modern/useIsFetching.cjs.map +1 -1
- package/build/modern/useIsFetching.js +8 -1
- package/build/modern/useIsFetching.js.map +1 -1
- package/build/modern/useMutation.cjs +14 -3
- package/build/modern/useMutation.cjs.map +1 -1
- package/build/modern/useMutation.js +15 -3
- package/build/modern/useMutation.js.map +1 -1
- package/build/modern/useMutationState.cjs +7 -0
- package/build/modern/useMutationState.cjs.map +1 -1
- package/build/modern/useMutationState.js +15 -1
- package/build/modern/useMutationState.js.map +1 -1
- package/build/modern/useQueries.cjs +21 -10
- package/build/modern/useQueries.cjs.map +1 -1
- package/build/modern/useQueries.d.cts +1 -1
- package/build/modern/useQueries.d.ts +1 -1
- package/build/modern/useQueries.js +29 -11
- package/build/modern/useQueries.js.map +1 -1
- package/build/modern/{useQuery-ebff9211.d.ts → useQuery-42d67167.d.ts} +6 -6
- package/build/modern/{useQuery-846c66db.d.ts → useQuery-ac350b9a.d.ts} +6 -6
- package/build/modern/useQuery.cjs.map +1 -1
- package/build/modern/useQuery.d.cts +1 -1
- package/build/modern/useQuery.d.ts +1 -1
- package/build/modern/useQuery.js.map +1 -1
- package/build/modern/useQueryClient.cjs +4 -3
- package/build/modern/useQueryClient.cjs.map +1 -1
- package/build/modern/useQueryClient.js +5 -4
- package/build/modern/useQueryClient.js.map +1 -1
- package/build/modern/vueQueryPlugin.cjs +1 -0
- package/build/modern/vueQueryPlugin.cjs.map +1 -1
- package/build/modern/vueQueryPlugin.d.cts +1 -0
- package/build/modern/vueQueryPlugin.d.ts +1 -0
- package/build/modern/vueQueryPlugin.js +1 -0
- package/build/modern/vueQueryPlugin.js.map +1 -1
- package/package.json +6 -6
- package/src/__tests__/useQuery.test.ts +35 -6
- package/src/__tests__/useQueryClient.test.ts +4 -4
- package/src/types.ts +23 -1
- package/src/useBaseQuery.ts +17 -4
- package/src/useInfiniteQuery.ts +2 -3
- package/src/useIsFetching.ts +9 -1
- package/src/useMutation.ts +16 -3
- package/src/useMutationState.ts +16 -1
- package/src/useQueries.ts +30 -11
- package/src/useQuery.ts +10 -5
- package/src/useQueryClient.ts +6 -5
- package/src/vueQueryPlugin.ts +2 -0
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ToRefs } from 'vue-demi';
|
|
2
2
|
import { DefaultError, QueryKey, InfiniteQueryObserverOptions, WithRequired, InfiniteQueryObserverResult, InfiniteData, QueryObserverResult, QueryObserver, QueryObserverOptions, DefinedQueryObserverResult } from '@tanstack/query-core';
|
|
3
3
|
import { QueryClient } from './queryClient.cjs';
|
|
4
|
-
import { MaybeRefDeep, DistributiveOmit } from './types.cjs';
|
|
4
|
+
import { DeepUnwrapRef, MaybeRefDeep, DistributiveOmit, MaybeRef } from './types.cjs';
|
|
5
5
|
|
|
6
6
|
type UseInfiniteQueryOptions<TQueryFnData = unknown, TError = DefaultError, TData = TQueryFnData, TQueryData = TQueryFnData, TQueryKey extends QueryKey = QueryKey, TPageParam = unknown> = {
|
|
7
|
-
[Property in keyof InfiniteQueryObserverOptions<TQueryFnData, TError, TData, TQueryData, TQueryKey, TPageParam>]: Property extends 'queryFn' ? InfiniteQueryObserverOptions<TQueryFnData, TError, TData, TQueryData,
|
|
7
|
+
[Property in keyof InfiniteQueryObserverOptions<TQueryFnData, TError, TData, TQueryData, TQueryKey, TPageParam>]: Property extends 'queryFn' ? InfiniteQueryObserverOptions<TQueryFnData, TError, TData, TQueryData, DeepUnwrapRef<TQueryKey>, TPageParam>[Property] : MaybeRefDeep<WithRequired<InfiniteQueryObserverOptions<TQueryFnData, TError, TData, TQueryData, TQueryKey, TPageParam>, 'queryKey'>[Property]>;
|
|
8
8
|
};
|
|
9
9
|
type InfiniteQueryReturnType<TData, TError> = UseBaseQueryReturnType<TData, TError, InfiniteQueryObserverResult<TData, TError>>;
|
|
10
10
|
type UseInfiniteQueryReturnType<TData, TError> = DistributiveOmit<InfiniteQueryReturnType<TData, TError>, 'fetchNextPage' | 'fetchPreviousPage' | 'refetch'> & {
|
|
@@ -20,9 +20,9 @@ type UseBaseQueryReturnType<TData, TError, Result = QueryObserverResult<TData, T
|
|
|
20
20
|
type UseQueryOptionsGeneric<TQueryFnData, TError, TData, TQueryData, TQueryKey extends QueryKey = QueryKey, TPageParam = unknown> = UseQueryOptions<TQueryFnData, TError, TData, TQueryData, TQueryKey> | UseInfiniteQueryOptions<TQueryFnData, TError, TData, TQueryData, TQueryKey, TPageParam>;
|
|
21
21
|
declare function useBaseQuery<TQueryFnData, TError, TData, TQueryData, TQueryKey extends QueryKey, TPageParam>(Observer: typeof QueryObserver, options: UseQueryOptionsGeneric<TQueryFnData, TError, TData, TQueryData, TQueryKey, TPageParam>, queryClient?: QueryClient): UseBaseQueryReturnType<TData, TError>;
|
|
22
22
|
|
|
23
|
-
type UseQueryOptions<TQueryFnData = unknown, TError = DefaultError, TData = TQueryFnData, TQueryData = TQueryFnData, TQueryKey extends QueryKey = QueryKey> = {
|
|
24
|
-
[Property in keyof QueryObserverOptions<TQueryFnData, TError, TData, TQueryData, TQueryKey>]: Property extends 'queryFn' ? QueryObserverOptions<TQueryFnData, TError, TData, TQueryData,
|
|
25
|
-
}
|
|
23
|
+
type UseQueryOptions<TQueryFnData = unknown, TError = DefaultError, TData = TQueryFnData, TQueryData = TQueryFnData, TQueryKey extends QueryKey = QueryKey> = MaybeRef<{
|
|
24
|
+
[Property in keyof QueryObserverOptions<TQueryFnData, TError, TData, TQueryData, TQueryKey>]: Property extends 'queryFn' ? QueryObserverOptions<TQueryFnData, TError, TData, TQueryData, DeepUnwrapRef<TQueryKey>>[Property] : MaybeRefDeep<WithRequired<QueryObserverOptions<TQueryFnData, TError, TData, TQueryData, TQueryKey>, 'queryKey'>[Property]>;
|
|
25
|
+
}>;
|
|
26
26
|
type UseQueryReturnType<TData, TError> = DistributiveOmit<UseBaseQueryReturnType<TData, TError>, 'refetch'> & {
|
|
27
27
|
refetch: QueryObserverResult<TData, TError>['refetch'];
|
|
28
28
|
};
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ToRefs } from 'vue-demi';
|
|
2
2
|
import { DefaultError, QueryKey, InfiniteQueryObserverOptions, WithRequired, InfiniteQueryObserverResult, InfiniteData, QueryObserverResult, QueryObserver, QueryObserverOptions, DefinedQueryObserverResult } from '@tanstack/query-core';
|
|
3
3
|
import { QueryClient } from './queryClient.js';
|
|
4
|
-
import { MaybeRefDeep, DistributiveOmit } from './types.js';
|
|
4
|
+
import { DeepUnwrapRef, MaybeRefDeep, DistributiveOmit, MaybeRef } from './types.js';
|
|
5
5
|
|
|
6
6
|
type UseInfiniteQueryOptions<TQueryFnData = unknown, TError = DefaultError, TData = TQueryFnData, TQueryData = TQueryFnData, TQueryKey extends QueryKey = QueryKey, TPageParam = unknown> = {
|
|
7
|
-
[Property in keyof InfiniteQueryObserverOptions<TQueryFnData, TError, TData, TQueryData, TQueryKey, TPageParam>]: Property extends 'queryFn' ? InfiniteQueryObserverOptions<TQueryFnData, TError, TData, TQueryData,
|
|
7
|
+
[Property in keyof InfiniteQueryObserverOptions<TQueryFnData, TError, TData, TQueryData, TQueryKey, TPageParam>]: Property extends 'queryFn' ? InfiniteQueryObserverOptions<TQueryFnData, TError, TData, TQueryData, DeepUnwrapRef<TQueryKey>, TPageParam>[Property] : MaybeRefDeep<WithRequired<InfiniteQueryObserverOptions<TQueryFnData, TError, TData, TQueryData, TQueryKey, TPageParam>, 'queryKey'>[Property]>;
|
|
8
8
|
};
|
|
9
9
|
type InfiniteQueryReturnType<TData, TError> = UseBaseQueryReturnType<TData, TError, InfiniteQueryObserverResult<TData, TError>>;
|
|
10
10
|
type UseInfiniteQueryReturnType<TData, TError> = DistributiveOmit<InfiniteQueryReturnType<TData, TError>, 'fetchNextPage' | 'fetchPreviousPage' | 'refetch'> & {
|
|
@@ -20,9 +20,9 @@ type UseBaseQueryReturnType<TData, TError, Result = QueryObserverResult<TData, T
|
|
|
20
20
|
type UseQueryOptionsGeneric<TQueryFnData, TError, TData, TQueryData, TQueryKey extends QueryKey = QueryKey, TPageParam = unknown> = UseQueryOptions<TQueryFnData, TError, TData, TQueryData, TQueryKey> | UseInfiniteQueryOptions<TQueryFnData, TError, TData, TQueryData, TQueryKey, TPageParam>;
|
|
21
21
|
declare function useBaseQuery<TQueryFnData, TError, TData, TQueryData, TQueryKey extends QueryKey, TPageParam>(Observer: typeof QueryObserver, options: UseQueryOptionsGeneric<TQueryFnData, TError, TData, TQueryData, TQueryKey, TPageParam>, queryClient?: QueryClient): UseBaseQueryReturnType<TData, TError>;
|
|
22
22
|
|
|
23
|
-
type UseQueryOptions<TQueryFnData = unknown, TError = DefaultError, TData = TQueryFnData, TQueryData = TQueryFnData, TQueryKey extends QueryKey = QueryKey> = {
|
|
24
|
-
[Property in keyof QueryObserverOptions<TQueryFnData, TError, TData, TQueryData, TQueryKey>]: Property extends 'queryFn' ? QueryObserverOptions<TQueryFnData, TError, TData, TQueryData,
|
|
25
|
-
}
|
|
23
|
+
type UseQueryOptions<TQueryFnData = unknown, TError = DefaultError, TData = TQueryFnData, TQueryData = TQueryFnData, TQueryKey extends QueryKey = QueryKey> = MaybeRef<{
|
|
24
|
+
[Property in keyof QueryObserverOptions<TQueryFnData, TError, TData, TQueryData, TQueryKey>]: Property extends 'queryFn' ? QueryObserverOptions<TQueryFnData, TError, TData, TQueryData, DeepUnwrapRef<TQueryKey>>[Property] : MaybeRefDeep<WithRequired<QueryObserverOptions<TQueryFnData, TError, TData, TQueryData, TQueryKey>, 'queryKey'>[Property]>;
|
|
25
|
+
}>;
|
|
26
26
|
type UseQueryReturnType<TData, TError> = DistributiveOmit<UseBaseQueryReturnType<TData, TError>, 'refetch'> & {
|
|
27
27
|
refetch: QueryObserverResult<TData, TError>['refetch'];
|
|
28
28
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/useQuery.ts"],"sourcesContent":["import { QueryObserver } from '@tanstack/query-core'\nimport { useBaseQuery } from './useBaseQuery'\nimport type { ToRefs
|
|
1
|
+
{"version":3,"sources":["../../src/useQuery.ts"],"sourcesContent":["import { QueryObserver } from '@tanstack/query-core'\nimport { useBaseQuery } from './useBaseQuery'\nimport type { ToRefs } from 'vue-demi'\nimport type {\n DefaultError,\n DefinedQueryObserverResult,\n QueryKey,\n QueryObserverOptions,\n QueryObserverResult,\n WithRequired,\n} from '@tanstack/query-core'\nimport type { UseBaseQueryReturnType } from './useBaseQuery'\nimport type {\n DeepUnwrapRef,\n DistributiveOmit,\n MaybeRef,\n MaybeRefDeep,\n} from './types'\nimport type { QueryClient } from './queryClient'\n\nexport type UseQueryOptions<\n TQueryFnData = unknown,\n TError = DefaultError,\n TData = TQueryFnData,\n TQueryData = TQueryFnData,\n TQueryKey extends QueryKey = QueryKey,\n> = MaybeRef<{\n [Property in keyof QueryObserverOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryData,\n TQueryKey\n >]: Property extends 'queryFn'\n ? QueryObserverOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryData,\n DeepUnwrapRef<TQueryKey>\n >[Property]\n : MaybeRefDeep<\n WithRequired<\n QueryObserverOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryData,\n TQueryKey\n >,\n 'queryKey'\n >[Property]\n >\n}>\n\nexport type UseQueryReturnType<TData, TError> = DistributiveOmit<\n UseBaseQueryReturnType<TData, TError>,\n 'refetch'\n> & {\n refetch: QueryObserverResult<TData, TError>['refetch']\n}\n\nexport type UseQueryDefinedReturnType<TData, TError> = DistributiveOmit<\n ToRefs<Readonly<DefinedQueryObserverResult<TData, TError>>>,\n 'refetch'\n> & {\n suspense: () => Promise<QueryObserverResult<TData, TError>>\n refetch: QueryObserverResult<TData, TError>['refetch']\n}\n\nexport function useQuery<\n TQueryFnData = unknown,\n TError = DefaultError,\n TData = TQueryFnData,\n TQueryKey extends QueryKey = QueryKey,\n>(\n options: UseQueryOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryFnData,\n TQueryKey\n > & {\n initialData?: undefined\n },\n queryClient?: QueryClient,\n): UseQueryReturnType<TData, TError>\n\nexport function useQuery<\n TQueryFnData = unknown,\n TError = DefaultError,\n TData = TQueryFnData,\n TQueryKey extends QueryKey = QueryKey,\n>(\n options: UseQueryOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryFnData,\n TQueryKey\n > & {\n initialData: TQueryFnData | (() => TQueryFnData)\n },\n queryClient?: QueryClient,\n): UseQueryDefinedReturnType<TData, TError>\n\nexport function useQuery<\n TQueryFnData,\n TError = DefaultError,\n TData = TQueryFnData,\n TQueryKey extends QueryKey = QueryKey,\n>(\n options: UseQueryOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryFnData,\n TQueryKey\n >,\n queryClient?: QueryClient,\n):\n | UseQueryReturnType<TData, TError>\n | UseQueryDefinedReturnType<TData, TError> {\n const result = useBaseQuery(QueryObserver, options, queryClient)\n\n return {\n ...result,\n refetch: result.refetch.value,\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,wBAA8B;AAC9B,0BAA6B;AAyGtB,SAAS,SAMd,SAOA,aAG2C;AAC3C,QAAM,aAAS,kCAAa,iCAAe,SAAS,WAAW;AAE/D,SAAO;AAAA,IACL,GAAG;AAAA,IACH,SAAS,OAAO,QAAQ;AAAA,EAC1B;AACF;","names":[]}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import 'vue-demi';
|
|
2
2
|
import '@tanstack/query-core';
|
|
3
|
-
export { c as UseQueryDefinedReturnType, U as UseQueryOptions, b as UseQueryReturnType, u as useQuery } from './useQuery-
|
|
3
|
+
export { c as UseQueryDefinedReturnType, U as UseQueryOptions, b as UseQueryReturnType, u as useQuery } from './useQuery-42d67167.js';
|
|
4
4
|
import './types.cjs';
|
|
5
5
|
import './queryClient.cjs';
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import 'vue-demi';
|
|
2
2
|
import '@tanstack/query-core';
|
|
3
|
-
export { c as UseQueryDefinedReturnType, U as UseQueryOptions, b as UseQueryReturnType, u as useQuery } from './useQuery-
|
|
3
|
+
export { c as UseQueryDefinedReturnType, U as UseQueryOptions, b as UseQueryReturnType, u as useQuery } from './useQuery-ac350b9a.js';
|
|
4
4
|
import './types.js';
|
|
5
5
|
import './queryClient.js';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/useQuery.ts"],"sourcesContent":["import { QueryObserver } from '@tanstack/query-core'\nimport { useBaseQuery } from './useBaseQuery'\nimport type { ToRefs
|
|
1
|
+
{"version":3,"sources":["../../src/useQuery.ts"],"sourcesContent":["import { QueryObserver } from '@tanstack/query-core'\nimport { useBaseQuery } from './useBaseQuery'\nimport type { ToRefs } from 'vue-demi'\nimport type {\n DefaultError,\n DefinedQueryObserverResult,\n QueryKey,\n QueryObserverOptions,\n QueryObserverResult,\n WithRequired,\n} from '@tanstack/query-core'\nimport type { UseBaseQueryReturnType } from './useBaseQuery'\nimport type {\n DeepUnwrapRef,\n DistributiveOmit,\n MaybeRef,\n MaybeRefDeep,\n} from './types'\nimport type { QueryClient } from './queryClient'\n\nexport type UseQueryOptions<\n TQueryFnData = unknown,\n TError = DefaultError,\n TData = TQueryFnData,\n TQueryData = TQueryFnData,\n TQueryKey extends QueryKey = QueryKey,\n> = MaybeRef<{\n [Property in keyof QueryObserverOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryData,\n TQueryKey\n >]: Property extends 'queryFn'\n ? QueryObserverOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryData,\n DeepUnwrapRef<TQueryKey>\n >[Property]\n : MaybeRefDeep<\n WithRequired<\n QueryObserverOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryData,\n TQueryKey\n >,\n 'queryKey'\n >[Property]\n >\n}>\n\nexport type UseQueryReturnType<TData, TError> = DistributiveOmit<\n UseBaseQueryReturnType<TData, TError>,\n 'refetch'\n> & {\n refetch: QueryObserverResult<TData, TError>['refetch']\n}\n\nexport type UseQueryDefinedReturnType<TData, TError> = DistributiveOmit<\n ToRefs<Readonly<DefinedQueryObserverResult<TData, TError>>>,\n 'refetch'\n> & {\n suspense: () => Promise<QueryObserverResult<TData, TError>>\n refetch: QueryObserverResult<TData, TError>['refetch']\n}\n\nexport function useQuery<\n TQueryFnData = unknown,\n TError = DefaultError,\n TData = TQueryFnData,\n TQueryKey extends QueryKey = QueryKey,\n>(\n options: UseQueryOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryFnData,\n TQueryKey\n > & {\n initialData?: undefined\n },\n queryClient?: QueryClient,\n): UseQueryReturnType<TData, TError>\n\nexport function useQuery<\n TQueryFnData = unknown,\n TError = DefaultError,\n TData = TQueryFnData,\n TQueryKey extends QueryKey = QueryKey,\n>(\n options: UseQueryOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryFnData,\n TQueryKey\n > & {\n initialData: TQueryFnData | (() => TQueryFnData)\n },\n queryClient?: QueryClient,\n): UseQueryDefinedReturnType<TData, TError>\n\nexport function useQuery<\n TQueryFnData,\n TError = DefaultError,\n TData = TQueryFnData,\n TQueryKey extends QueryKey = QueryKey,\n>(\n options: UseQueryOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryFnData,\n TQueryKey\n >,\n queryClient?: QueryClient,\n):\n | UseQueryReturnType<TData, TError>\n | UseQueryDefinedReturnType<TData, TError> {\n const result = useBaseQuery(QueryObserver, options, queryClient)\n\n return {\n ...result,\n refetch: result.refetch.value,\n }\n}\n"],"mappings":";AAAA,SAAS,qBAAqB;AAC9B,SAAS,oBAAoB;AAyGtB,SAAS,SAMd,SAOA,aAG2C;AAC3C,QAAM,SAAS,aAAa,eAAe,SAAS,WAAW;AAE/D,SAAO;AAAA,IACL,GAAG;AAAA,IACH,SAAS,OAAO,QAAQ;AAAA,EAC1B;AACF;","names":[]}
|
|
@@ -26,9 +26,10 @@ module.exports = __toCommonJS(useQueryClient_exports);
|
|
|
26
26
|
var import_vue_demi = require("vue-demi");
|
|
27
27
|
var import_utils = require("./utils.cjs");
|
|
28
28
|
function useQueryClient(id = "") {
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
29
|
+
if (!(0, import_vue_demi.hasInjectionContext)()) {
|
|
30
|
+
throw new Error(
|
|
31
|
+
"vue-query hooks can only be used inside setup() function or functions that support injection context."
|
|
32
|
+
);
|
|
32
33
|
}
|
|
33
34
|
const key = (0, import_utils.getClientKey)(id);
|
|
34
35
|
const queryClient = (0, import_vue_demi.inject)(key);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/useQueryClient.ts"],"sourcesContent":["import {
|
|
1
|
+
{"version":3,"sources":["../../src/useQueryClient.ts"],"sourcesContent":["import { hasInjectionContext, inject } from 'vue-demi'\n\nimport { getClientKey } from './utils'\nimport type { QueryClient } from './queryClient'\n\nexport function useQueryClient(id = ''): QueryClient {\n // ensures that `inject()` can be used\n if (!hasInjectionContext()) {\n throw new Error(\n 'vue-query hooks can only be used inside setup() function or functions that support injection context.',\n )\n }\n\n const key = getClientKey(id)\n const queryClient = inject<QueryClient>(key)\n\n if (!queryClient) {\n throw new Error(\n \"No 'queryClient' found in Vue context, use 'VueQueryPlugin' to properly initialize the library.\",\n )\n }\n\n return queryClient\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,sBAA4C;AAE5C,mBAA6B;AAGtB,SAAS,eAAe,KAAK,IAAiB;AAEnD,MAAI,KAAC,qCAAoB,GAAG;AAC1B,UAAM,IAAI;AAAA,MACR;AAAA,IACF;AAAA,EACF;AAEA,QAAM,UAAM,2BAAa,EAAE;AAC3B,QAAM,kBAAc,wBAAoB,GAAG;AAE3C,MAAI,CAAC,aAAa;AAChB,UAAM,IAAI;AAAA,MACR;AAAA,IACF;AAAA,EACF;AAEA,SAAO;AACT;","names":[]}
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
// src/useQueryClient.ts
|
|
2
|
-
import {
|
|
2
|
+
import { hasInjectionContext, inject } from "vue-demi";
|
|
3
3
|
import { getClientKey } from "./utils.js";
|
|
4
4
|
function useQueryClient(id = "") {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
5
|
+
if (!hasInjectionContext()) {
|
|
6
|
+
throw new Error(
|
|
7
|
+
"vue-query hooks can only be used inside setup() function or functions that support injection context."
|
|
8
|
+
);
|
|
8
9
|
}
|
|
9
10
|
const key = getClientKey(id);
|
|
10
11
|
const queryClient = inject(key);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/useQueryClient.ts"],"sourcesContent":["import {
|
|
1
|
+
{"version":3,"sources":["../../src/useQueryClient.ts"],"sourcesContent":["import { hasInjectionContext, inject } from 'vue-demi'\n\nimport { getClientKey } from './utils'\nimport type { QueryClient } from './queryClient'\n\nexport function useQueryClient(id = ''): QueryClient {\n // ensures that `inject()` can be used\n if (!hasInjectionContext()) {\n throw new Error(\n 'vue-query hooks can only be used inside setup() function or functions that support injection context.',\n )\n }\n\n const key = getClientKey(id)\n const queryClient = inject<QueryClient>(key)\n\n if (!queryClient) {\n throw new Error(\n \"No 'queryClient' found in Vue context, use 'VueQueryPlugin' to properly initialize the library.\",\n )\n }\n\n return queryClient\n}\n"],"mappings":";AAAA,SAAS,qBAAqB,cAAc;AAE5C,SAAS,oBAAoB;AAGtB,SAAS,eAAe,KAAK,IAAiB;AAEnD,MAAI,CAAC,oBAAoB,GAAG;AAC1B,UAAM,IAAI;AAAA,MACR;AAAA,IACF;AAAA,EACF;AAEA,QAAM,MAAM,aAAa,EAAE;AAC3B,QAAM,cAAc,OAAoB,GAAG;AAE3C,MAAI,CAAC,aAAa;AAChB,UAAM,IAAI;AAAA,MACR;AAAA,IACF;AAAA,EACF;AAEA,SAAO;AACT;","names":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/vueQueryPlugin.ts"],"sourcesContent":["import { isVue2 } from 'vue-demi'\nimport { isServer } from '@tanstack/query-core'\n\nimport { QueryClient } from './queryClient'\nimport { getClientKey } from './utils'\nimport { setupDevtools } from './devtools/devtools'\nimport type { QueryClientConfig } from '@tanstack/query-core'\nimport type { MaybeRefDeep } from './types'\n\ntype ClientPersister = (client: QueryClient) => [() => void, Promise<void>]\n\ninterface CommonOptions {\n queryClientKey?: string\n clientPersister?: ClientPersister\n}\n\ninterface ConfigOptions extends CommonOptions {\n queryClientConfig?: MaybeRefDeep<QueryClientConfig>\n}\n\ninterface ClientOptions extends CommonOptions {\n queryClient?: QueryClient\n}\n\nexport type VueQueryPluginOptions = ConfigOptions | ClientOptions\n\nexport const VueQueryPlugin = {\n install: (app: any, options: VueQueryPluginOptions = {}) => {\n const clientKey = getClientKey(options.queryClientKey)\n let client: QueryClient\n\n if ('queryClient' in options && options.queryClient) {\n client = options.queryClient\n } else {\n const clientConfig =\n 'queryClientConfig' in options ? options.queryClientConfig : undefined\n client = new QueryClient(clientConfig)\n }\n\n if (!isServer) {\n client.mount()\n }\n\n let persisterUnmount = () => {\n // noop\n }\n\n if (options.clientPersister) {\n client.isRestoring.value = true\n const [unmount, promise] = options.clientPersister(client)\n persisterUnmount = unmount\n promise.then(() => {\n client.isRestoring.value = false\n })\n }\n\n const cleanup = () => {\n client.unmount()\n persisterUnmount()\n }\n\n if (app.onUnmount) {\n app.onUnmount(cleanup)\n } else {\n const originalUnmount = app.unmount\n app.unmount = function vueQueryUnmount() {\n cleanup()\n originalUnmount()\n }\n }\n\n if (isVue2) {\n app.mixin({\n beforeCreate() {\n // HACK: taken from provide(): https://github.com/vuejs/composition-api/blob/master/src/apis/inject.ts#L30\n if (!this._provided) {\n const provideCache = {}\n Object.defineProperty(this, '_provided', {\n get: () => provideCache,\n set: (v) => Object.assign(provideCache, v),\n })\n }\n\n this._provided[clientKey] = client\n\n if (process.env.NODE_ENV === 'development') {\n if (this === this.$root) {\n setupDevtools(this, client)\n }\n }\n },\n })\n } else {\n app.provide(clientKey, client)\n\n if (process.env.NODE_ENV === 'development') {\n setupDevtools(app, client)\n }\n }\n },\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,sBAAuB;AACvB,wBAAyB;AAEzB,yBAA4B;AAC5B,mBAA6B;AAC7B,sBAA8B;
|
|
1
|
+
{"version":3,"sources":["../../src/vueQueryPlugin.ts"],"sourcesContent":["import { isVue2 } from 'vue-demi'\nimport { isServer } from '@tanstack/query-core'\n\nimport { QueryClient } from './queryClient'\nimport { getClientKey } from './utils'\nimport { setupDevtools } from './devtools/devtools'\nimport type { QueryClientConfig } from '@tanstack/query-core'\nimport type { MaybeRefDeep } from './types'\n\ntype ClientPersister = (client: QueryClient) => [() => void, Promise<void>]\n\ninterface CommonOptions {\n queryClientKey?: string\n clientPersister?: ClientPersister\n clientPersisterOnSuccess?: (client: QueryClient) => void\n}\n\ninterface ConfigOptions extends CommonOptions {\n queryClientConfig?: MaybeRefDeep<QueryClientConfig>\n}\n\ninterface ClientOptions extends CommonOptions {\n queryClient?: QueryClient\n}\n\nexport type VueQueryPluginOptions = ConfigOptions | ClientOptions\n\nexport const VueQueryPlugin = {\n install: (app: any, options: VueQueryPluginOptions = {}) => {\n const clientKey = getClientKey(options.queryClientKey)\n let client: QueryClient\n\n if ('queryClient' in options && options.queryClient) {\n client = options.queryClient\n } else {\n const clientConfig =\n 'queryClientConfig' in options ? options.queryClientConfig : undefined\n client = new QueryClient(clientConfig)\n }\n\n if (!isServer) {\n client.mount()\n }\n\n let persisterUnmount = () => {\n // noop\n }\n\n if (options.clientPersister) {\n client.isRestoring.value = true\n const [unmount, promise] = options.clientPersister(client)\n persisterUnmount = unmount\n promise.then(() => {\n client.isRestoring.value = false\n options.clientPersisterOnSuccess?.(client)\n })\n }\n\n const cleanup = () => {\n client.unmount()\n persisterUnmount()\n }\n\n if (app.onUnmount) {\n app.onUnmount(cleanup)\n } else {\n const originalUnmount = app.unmount\n app.unmount = function vueQueryUnmount() {\n cleanup()\n originalUnmount()\n }\n }\n\n if (isVue2) {\n app.mixin({\n beforeCreate() {\n // HACK: taken from provide(): https://github.com/vuejs/composition-api/blob/master/src/apis/inject.ts#L30\n if (!this._provided) {\n const provideCache = {}\n Object.defineProperty(this, '_provided', {\n get: () => provideCache,\n set: (v) => Object.assign(provideCache, v),\n })\n }\n\n this._provided[clientKey] = client\n\n if (process.env.NODE_ENV === 'development') {\n if (this === this.$root) {\n setupDevtools(this, client)\n }\n }\n },\n })\n } else {\n app.provide(clientKey, client)\n\n if (process.env.NODE_ENV === 'development') {\n setupDevtools(app, client)\n }\n }\n },\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,sBAAuB;AACvB,wBAAyB;AAEzB,yBAA4B;AAC5B,mBAA6B;AAC7B,sBAA8B;AAsBvB,IAAM,iBAAiB;AAAA,EAC5B,SAAS,CAAC,KAAU,UAAiC,CAAC,MAAM;AAC1D,UAAM,gBAAY,2BAAa,QAAQ,cAAc;AACrD,QAAI;AAEJ,QAAI,iBAAiB,WAAW,QAAQ,aAAa;AACnD,eAAS,QAAQ;AAAA,IACnB,OAAO;AACL,YAAM,eACJ,uBAAuB,UAAU,QAAQ,oBAAoB;AAC/D,eAAS,IAAI,+BAAY,YAAY;AAAA,IACvC;AAEA,QAAI,CAAC,4BAAU;AACb,aAAO,MAAM;AAAA,IACf;AAEA,QAAI,mBAAmB,MAAM;AAAA,IAE7B;AAEA,QAAI,QAAQ,iBAAiB;AAC3B,aAAO,YAAY,QAAQ;AAC3B,YAAM,CAAC,SAAS,OAAO,IAAI,QAAQ,gBAAgB,MAAM;AACzD,yBAAmB;AACnB,cAAQ,KAAK,MAAM;AACjB,eAAO,YAAY,QAAQ;AAC3B,gBAAQ,2BAA2B,MAAM;AAAA,MAC3C,CAAC;AAAA,IACH;AAEA,UAAM,UAAU,MAAM;AACpB,aAAO,QAAQ;AACf,uBAAiB;AAAA,IACnB;AAEA,QAAI,IAAI,WAAW;AACjB,UAAI,UAAU,OAAO;AAAA,IACvB,OAAO;AACL,YAAM,kBAAkB,IAAI;AAC5B,UAAI,UAAU,SAAS,kBAAkB;AACvC,gBAAQ;AACR,wBAAgB;AAAA,MAClB;AAAA,IACF;AAEA,QAAI,wBAAQ;AACV,UAAI,MAAM;AAAA,QACR,eAAe;AAEb,cAAI,CAAC,KAAK,WAAW;AACnB,kBAAM,eAAe,CAAC;AACtB,mBAAO,eAAe,MAAM,aAAa;AAAA,cACvC,KAAK,MAAM;AAAA,cACX,KAAK,CAAC,MAAM,OAAO,OAAO,cAAc,CAAC;AAAA,YAC3C,CAAC;AAAA,UACH;AAEA,eAAK,UAAU,SAAS,IAAI;AAE5B,cAAI,QAAQ,IAAI,aAAa,eAAe;AAC1C,gBAAI,SAAS,KAAK,OAAO;AACvB,iDAAc,MAAM,MAAM;AAAA,YAC5B;AAAA,UACF;AAAA,QACF;AAAA,MACF,CAAC;AAAA,IACH,OAAO;AACL,UAAI,QAAQ,WAAW,MAAM;AAE7B,UAAI,QAAQ,IAAI,aAAa,eAAe;AAC1C,2CAAc,KAAK,MAAM;AAAA,MAC3B;AAAA,IACF;AAAA,EACF;AACF;","names":[]}
|
|
@@ -7,6 +7,7 @@ type ClientPersister = (client: QueryClient) => [() => void, Promise<void>];
|
|
|
7
7
|
interface CommonOptions {
|
|
8
8
|
queryClientKey?: string;
|
|
9
9
|
clientPersister?: ClientPersister;
|
|
10
|
+
clientPersisterOnSuccess?: (client: QueryClient) => void;
|
|
10
11
|
}
|
|
11
12
|
interface ConfigOptions extends CommonOptions {
|
|
12
13
|
queryClientConfig?: MaybeRefDeep<QueryClientConfig>;
|
|
@@ -7,6 +7,7 @@ type ClientPersister = (client: QueryClient) => [() => void, Promise<void>];
|
|
|
7
7
|
interface CommonOptions {
|
|
8
8
|
queryClientKey?: string;
|
|
9
9
|
clientPersister?: ClientPersister;
|
|
10
|
+
clientPersisterOnSuccess?: (client: QueryClient) => void;
|
|
10
11
|
}
|
|
11
12
|
interface ConfigOptions extends CommonOptions {
|
|
12
13
|
queryClientConfig?: MaybeRefDeep<QueryClientConfig>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/vueQueryPlugin.ts"],"sourcesContent":["import { isVue2 } from 'vue-demi'\nimport { isServer } from '@tanstack/query-core'\n\nimport { QueryClient } from './queryClient'\nimport { getClientKey } from './utils'\nimport { setupDevtools } from './devtools/devtools'\nimport type { QueryClientConfig } from '@tanstack/query-core'\nimport type { MaybeRefDeep } from './types'\n\ntype ClientPersister = (client: QueryClient) => [() => void, Promise<void>]\n\ninterface CommonOptions {\n queryClientKey?: string\n clientPersister?: ClientPersister\n}\n\ninterface ConfigOptions extends CommonOptions {\n queryClientConfig?: MaybeRefDeep<QueryClientConfig>\n}\n\ninterface ClientOptions extends CommonOptions {\n queryClient?: QueryClient\n}\n\nexport type VueQueryPluginOptions = ConfigOptions | ClientOptions\n\nexport const VueQueryPlugin = {\n install: (app: any, options: VueQueryPluginOptions = {}) => {\n const clientKey = getClientKey(options.queryClientKey)\n let client: QueryClient\n\n if ('queryClient' in options && options.queryClient) {\n client = options.queryClient\n } else {\n const clientConfig =\n 'queryClientConfig' in options ? options.queryClientConfig : undefined\n client = new QueryClient(clientConfig)\n }\n\n if (!isServer) {\n client.mount()\n }\n\n let persisterUnmount = () => {\n // noop\n }\n\n if (options.clientPersister) {\n client.isRestoring.value = true\n const [unmount, promise] = options.clientPersister(client)\n persisterUnmount = unmount\n promise.then(() => {\n client.isRestoring.value = false\n })\n }\n\n const cleanup = () => {\n client.unmount()\n persisterUnmount()\n }\n\n if (app.onUnmount) {\n app.onUnmount(cleanup)\n } else {\n const originalUnmount = app.unmount\n app.unmount = function vueQueryUnmount() {\n cleanup()\n originalUnmount()\n }\n }\n\n if (isVue2) {\n app.mixin({\n beforeCreate() {\n // HACK: taken from provide(): https://github.com/vuejs/composition-api/blob/master/src/apis/inject.ts#L30\n if (!this._provided) {\n const provideCache = {}\n Object.defineProperty(this, '_provided', {\n get: () => provideCache,\n set: (v) => Object.assign(provideCache, v),\n })\n }\n\n this._provided[clientKey] = client\n\n if (process.env.NODE_ENV === 'development') {\n if (this === this.$root) {\n setupDevtools(this, client)\n }\n }\n },\n })\n } else {\n app.provide(clientKey, client)\n\n if (process.env.NODE_ENV === 'development') {\n setupDevtools(app, client)\n }\n }\n },\n}\n"],"mappings":";AAAA,SAAS,cAAc;AACvB,SAAS,gBAAgB;AAEzB,SAAS,mBAAmB;AAC5B,SAAS,oBAAoB;AAC7B,SAAS,qBAAqB;
|
|
1
|
+
{"version":3,"sources":["../../src/vueQueryPlugin.ts"],"sourcesContent":["import { isVue2 } from 'vue-demi'\nimport { isServer } from '@tanstack/query-core'\n\nimport { QueryClient } from './queryClient'\nimport { getClientKey } from './utils'\nimport { setupDevtools } from './devtools/devtools'\nimport type { QueryClientConfig } from '@tanstack/query-core'\nimport type { MaybeRefDeep } from './types'\n\ntype ClientPersister = (client: QueryClient) => [() => void, Promise<void>]\n\ninterface CommonOptions {\n queryClientKey?: string\n clientPersister?: ClientPersister\n clientPersisterOnSuccess?: (client: QueryClient) => void\n}\n\ninterface ConfigOptions extends CommonOptions {\n queryClientConfig?: MaybeRefDeep<QueryClientConfig>\n}\n\ninterface ClientOptions extends CommonOptions {\n queryClient?: QueryClient\n}\n\nexport type VueQueryPluginOptions = ConfigOptions | ClientOptions\n\nexport const VueQueryPlugin = {\n install: (app: any, options: VueQueryPluginOptions = {}) => {\n const clientKey = getClientKey(options.queryClientKey)\n let client: QueryClient\n\n if ('queryClient' in options && options.queryClient) {\n client = options.queryClient\n } else {\n const clientConfig =\n 'queryClientConfig' in options ? options.queryClientConfig : undefined\n client = new QueryClient(clientConfig)\n }\n\n if (!isServer) {\n client.mount()\n }\n\n let persisterUnmount = () => {\n // noop\n }\n\n if (options.clientPersister) {\n client.isRestoring.value = true\n const [unmount, promise] = options.clientPersister(client)\n persisterUnmount = unmount\n promise.then(() => {\n client.isRestoring.value = false\n options.clientPersisterOnSuccess?.(client)\n })\n }\n\n const cleanup = () => {\n client.unmount()\n persisterUnmount()\n }\n\n if (app.onUnmount) {\n app.onUnmount(cleanup)\n } else {\n const originalUnmount = app.unmount\n app.unmount = function vueQueryUnmount() {\n cleanup()\n originalUnmount()\n }\n }\n\n if (isVue2) {\n app.mixin({\n beforeCreate() {\n // HACK: taken from provide(): https://github.com/vuejs/composition-api/blob/master/src/apis/inject.ts#L30\n if (!this._provided) {\n const provideCache = {}\n Object.defineProperty(this, '_provided', {\n get: () => provideCache,\n set: (v) => Object.assign(provideCache, v),\n })\n }\n\n this._provided[clientKey] = client\n\n if (process.env.NODE_ENV === 'development') {\n if (this === this.$root) {\n setupDevtools(this, client)\n }\n }\n },\n })\n } else {\n app.provide(clientKey, client)\n\n if (process.env.NODE_ENV === 'development') {\n setupDevtools(app, client)\n }\n }\n },\n}\n"],"mappings":";AAAA,SAAS,cAAc;AACvB,SAAS,gBAAgB;AAEzB,SAAS,mBAAmB;AAC5B,SAAS,oBAAoB;AAC7B,SAAS,qBAAqB;AAsBvB,IAAM,iBAAiB;AAAA,EAC5B,SAAS,CAAC,KAAU,UAAiC,CAAC,MAAM;AAC1D,UAAM,YAAY,aAAa,QAAQ,cAAc;AACrD,QAAI;AAEJ,QAAI,iBAAiB,WAAW,QAAQ,aAAa;AACnD,eAAS,QAAQ;AAAA,IACnB,OAAO;AACL,YAAM,eACJ,uBAAuB,UAAU,QAAQ,oBAAoB;AAC/D,eAAS,IAAI,YAAY,YAAY;AAAA,IACvC;AAEA,QAAI,CAAC,UAAU;AACb,aAAO,MAAM;AAAA,IACf;AAEA,QAAI,mBAAmB,MAAM;AAAA,IAE7B;AAEA,QAAI,QAAQ,iBAAiB;AAC3B,aAAO,YAAY,QAAQ;AAC3B,YAAM,CAAC,SAAS,OAAO,IAAI,QAAQ,gBAAgB,MAAM;AACzD,yBAAmB;AACnB,cAAQ,KAAK,MAAM;AACjB,eAAO,YAAY,QAAQ;AAC3B,gBAAQ,2BAA2B,MAAM;AAAA,MAC3C,CAAC;AAAA,IACH;AAEA,UAAM,UAAU,MAAM;AACpB,aAAO,QAAQ;AACf,uBAAiB;AAAA,IACnB;AAEA,QAAI,IAAI,WAAW;AACjB,UAAI,UAAU,OAAO;AAAA,IACvB,OAAO;AACL,YAAM,kBAAkB,IAAI;AAC5B,UAAI,UAAU,SAAS,kBAAkB;AACvC,gBAAQ;AACR,wBAAgB;AAAA,MAClB;AAAA,IACF;AAEA,QAAI,QAAQ;AACV,UAAI,MAAM;AAAA,QACR,eAAe;AAEb,cAAI,CAAC,KAAK,WAAW;AACnB,kBAAM,eAAe,CAAC;AACtB,mBAAO,eAAe,MAAM,aAAa;AAAA,cACvC,KAAK,MAAM;AAAA,cACX,KAAK,CAAC,MAAM,OAAO,OAAO,cAAc,CAAC;AAAA,YAC3C,CAAC;AAAA,UACH;AAEA,eAAK,UAAU,SAAS,IAAI;AAE5B,cAAI,QAAQ,IAAI,aAAa,eAAe;AAC1C,gBAAI,SAAS,KAAK,OAAO;AACvB,4BAAc,MAAM,MAAM;AAAA,YAC5B;AAAA,UACF;AAAA,QACF;AAAA,MACF,CAAC;AAAA,IACH,OAAO;AACL,UAAI,QAAQ,WAAW,MAAM;AAE7B,UAAI,QAAQ,IAAI,aAAa,eAAe;AAC1C,sBAAc,KAAK,MAAM;AAAA,MAC3B;AAAA,IACF;AAAA,EACF;AACF;","names":[]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tanstack/vue-query",
|
|
3
|
-
"version": "5.0.0-beta.
|
|
3
|
+
"version": "5.0.0-beta.23",
|
|
4
4
|
"description": "Hooks for managing, caching and syncing asynchronous and remote data in Vue",
|
|
5
5
|
"author": "Damian Osipiuk",
|
|
6
6
|
"license": "MIT",
|
|
@@ -48,18 +48,18 @@
|
|
|
48
48
|
"dependencies": {
|
|
49
49
|
"@tanstack/match-sorter-utils": "^8.8.4",
|
|
50
50
|
"@vue/devtools-api": "^6.5.0",
|
|
51
|
-
"vue-demi": "^0.
|
|
52
|
-
"@tanstack/query-core": "5.0.0-beta.
|
|
51
|
+
"vue-demi": "^0.14.6",
|
|
52
|
+
"@tanstack/query-core": "5.0.0-beta.23"
|
|
53
53
|
},
|
|
54
54
|
"devDependencies": {
|
|
55
|
-
"@vue/composition-api": "1.7.
|
|
56
|
-
"vue": "^3.
|
|
55
|
+
"@vue/composition-api": "1.7.2",
|
|
56
|
+
"vue": "^3.3.0",
|
|
57
57
|
"vue2": "npm:vue@2.6",
|
|
58
58
|
"vue2.7": "npm:vue@2.7"
|
|
59
59
|
},
|
|
60
60
|
"peerDependencies": {
|
|
61
61
|
"@vue/composition-api": "^1.1.2",
|
|
62
|
-
"vue": "^2.
|
|
62
|
+
"vue": "^2.6.0 || ^3.3.0"
|
|
63
63
|
},
|
|
64
64
|
"peerDependenciesMeta": {
|
|
65
65
|
"@vue/composition-api": {
|
|
@@ -138,8 +138,6 @@ describe('useQuery', () => {
|
|
|
138
138
|
})
|
|
139
139
|
|
|
140
140
|
secondKeyRef.value = 'key8'
|
|
141
|
-
await flushPromises()
|
|
142
|
-
|
|
143
141
|
expect(query).toMatchObject({
|
|
144
142
|
status: { value: 'pending' },
|
|
145
143
|
data: { value: undefined },
|
|
@@ -168,9 +166,6 @@ describe('useQuery', () => {
|
|
|
168
166
|
})
|
|
169
167
|
|
|
170
168
|
enabled.value = true
|
|
171
|
-
|
|
172
|
-
await flushPromises()
|
|
173
|
-
|
|
174
169
|
expect(query).toMatchObject({
|
|
175
170
|
fetchStatus: { value: 'fetching' },
|
|
176
171
|
data: { value: undefined },
|
|
@@ -191,16 +186,18 @@ describe('useQuery', () => {
|
|
|
191
186
|
|
|
192
187
|
const enabled = computed(() => !!data.value)
|
|
193
188
|
|
|
189
|
+
const dependentQueryFn = vi.fn().mockImplementation(simpleFetcher)
|
|
194
190
|
const { fetchStatus, status } = useQuery(
|
|
195
191
|
reactive({
|
|
196
192
|
queryKey: ['dependant2'],
|
|
197
|
-
queryFn:
|
|
193
|
+
queryFn: dependentQueryFn,
|
|
198
194
|
enabled,
|
|
199
195
|
}),
|
|
200
196
|
)
|
|
201
197
|
|
|
202
198
|
expect(data.value).toStrictEqual(undefined)
|
|
203
199
|
expect(fetchStatus.value).toStrictEqual('idle')
|
|
200
|
+
expect(dependentQueryFn).not.toHaveBeenCalled()
|
|
204
201
|
|
|
205
202
|
await flushPromises()
|
|
206
203
|
|
|
@@ -211,6 +208,10 @@ describe('useQuery', () => {
|
|
|
211
208
|
|
|
212
209
|
expect(fetchStatus.value).toStrictEqual('idle')
|
|
213
210
|
expect(status.value).toStrictEqual('success')
|
|
211
|
+
expect(dependentQueryFn).toHaveBeenCalledTimes(1)
|
|
212
|
+
expect(dependentQueryFn).toHaveBeenCalledWith(
|
|
213
|
+
expect.objectContaining({ queryKey: ['dependant2'] }),
|
|
214
|
+
)
|
|
214
215
|
})
|
|
215
216
|
|
|
216
217
|
test('should stop listening to changes on onScopeDispose', async () => {
|
|
@@ -235,6 +236,34 @@ describe('useQuery', () => {
|
|
|
235
236
|
expect(status.value).toStrictEqual('pending')
|
|
236
237
|
})
|
|
237
238
|
|
|
239
|
+
test('should use the current value for the queryKey when refetch is called', async () => {
|
|
240
|
+
const fetchFn = vi.fn()
|
|
241
|
+
const keyRef = ref('key11')
|
|
242
|
+
const query = useQuery({
|
|
243
|
+
queryKey: ['key10', keyRef],
|
|
244
|
+
queryFn: fetchFn,
|
|
245
|
+
enabled: false,
|
|
246
|
+
})
|
|
247
|
+
|
|
248
|
+
expect(fetchFn).not.toHaveBeenCalled()
|
|
249
|
+
await query.refetch()
|
|
250
|
+
expect(fetchFn).toHaveBeenCalledTimes(1)
|
|
251
|
+
expect(fetchFn).toHaveBeenCalledWith(
|
|
252
|
+
expect.objectContaining({
|
|
253
|
+
queryKey: ['key10', 'key11'],
|
|
254
|
+
}),
|
|
255
|
+
)
|
|
256
|
+
|
|
257
|
+
keyRef.value = 'key12'
|
|
258
|
+
await query.refetch()
|
|
259
|
+
expect(fetchFn).toHaveBeenCalledTimes(2)
|
|
260
|
+
expect(fetchFn).toHaveBeenCalledWith(
|
|
261
|
+
expect.objectContaining({
|
|
262
|
+
queryKey: ['key10', 'key12'],
|
|
263
|
+
}),
|
|
264
|
+
)
|
|
265
|
+
})
|
|
266
|
+
|
|
238
267
|
describe('throwOnError', () => {
|
|
239
268
|
test('should evaluate throwOnError when query is expected to throw', async () => {
|
|
240
269
|
const boundaryFn = vi.fn()
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { hasInjectionContext, inject } from 'vue-demi'
|
|
2
2
|
import { vi } from 'vitest'
|
|
3
3
|
import { useQueryClient } from '../useQueryClient'
|
|
4
4
|
import { VUE_QUERY_CLIENT } from '../utils'
|
|
@@ -6,7 +6,7 @@ import type { Mock } from 'vitest'
|
|
|
6
6
|
|
|
7
7
|
describe('useQueryClient', () => {
|
|
8
8
|
const injectSpy = inject as Mock
|
|
9
|
-
const
|
|
9
|
+
const hasInjectionContextSpy = hasInjectionContext as Mock
|
|
10
10
|
|
|
11
11
|
beforeEach(() => {
|
|
12
12
|
vi.restoreAllMocks()
|
|
@@ -32,10 +32,10 @@ describe('useQueryClient', () => {
|
|
|
32
32
|
})
|
|
33
33
|
|
|
34
34
|
test('should throw an error when used outside of setup function', () => {
|
|
35
|
-
|
|
35
|
+
hasInjectionContextSpy.mockReturnValueOnce(false)
|
|
36
36
|
|
|
37
37
|
expect(useQueryClient).toThrowError()
|
|
38
|
-
expect(
|
|
38
|
+
expect(hasInjectionContextSpy).toHaveBeenCalledTimes(1)
|
|
39
39
|
})
|
|
40
40
|
|
|
41
41
|
test('should call inject with a custom key as a suffix', () => {
|
package/src/types.ts
CHANGED
|
@@ -1,4 +1,16 @@
|
|
|
1
|
-
import type { Ref } from 'vue-demi'
|
|
1
|
+
import type { Ref, UnwrapRef } from 'vue-demi'
|
|
2
|
+
|
|
3
|
+
type Primitive = string | number | boolean | bigint | symbol | undefined | null
|
|
4
|
+
type UnwrapLeaf =
|
|
5
|
+
| Primitive
|
|
6
|
+
| Function
|
|
7
|
+
| Date
|
|
8
|
+
| Error
|
|
9
|
+
| RegExp
|
|
10
|
+
| Map<any, any>
|
|
11
|
+
| WeakMap<any, any>
|
|
12
|
+
| Set<any>
|
|
13
|
+
| WeakSet<any>
|
|
2
14
|
|
|
3
15
|
export type MaybeRef<T> = Ref<T> | T
|
|
4
16
|
|
|
@@ -12,6 +24,16 @@ export type MaybeRefDeep<T> = MaybeRef<
|
|
|
12
24
|
: T
|
|
13
25
|
>
|
|
14
26
|
|
|
27
|
+
export type DeepUnwrapRef<T> = T extends UnwrapLeaf
|
|
28
|
+
? T
|
|
29
|
+
: T extends Ref<infer U>
|
|
30
|
+
? DeepUnwrapRef<U>
|
|
31
|
+
: T extends {}
|
|
32
|
+
? {
|
|
33
|
+
[Property in keyof T]: DeepUnwrapRef<T[Property]>
|
|
34
|
+
}
|
|
35
|
+
: UnwrapRef<T>
|
|
36
|
+
|
|
15
37
|
export type DistributiveOmit<T, K extends keyof any> = T extends any
|
|
16
38
|
? Omit<T, K>
|
|
17
39
|
: never
|
package/src/useBaseQuery.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
computed,
|
|
3
|
+
getCurrentScope,
|
|
3
4
|
onScopeDispose,
|
|
4
5
|
reactive,
|
|
5
6
|
readonly,
|
|
@@ -64,6 +65,14 @@ export function useBaseQuery<
|
|
|
64
65
|
>,
|
|
65
66
|
queryClient?: QueryClient,
|
|
66
67
|
): UseBaseQueryReturnType<TData, TError> {
|
|
68
|
+
if (process.env.NODE_ENV === 'development') {
|
|
69
|
+
if (!getCurrentScope()) {
|
|
70
|
+
console.warn(
|
|
71
|
+
'vue-query composables like "uesQuery()" should only be used inside a "setup()" function or a running effect scope. They might otherwise lead to memory leaks.',
|
|
72
|
+
)
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
67
76
|
const client = queryClient || useQueryClient()
|
|
68
77
|
|
|
69
78
|
const defaultedOptions = computed(() => {
|
|
@@ -103,10 +112,14 @@ export function useBaseQuery<
|
|
|
103
112
|
{ immediate: true },
|
|
104
113
|
)
|
|
105
114
|
|
|
106
|
-
watch(
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
115
|
+
watch(
|
|
116
|
+
defaultedOptions,
|
|
117
|
+
() => {
|
|
118
|
+
observer.setOptions(defaultedOptions.value)
|
|
119
|
+
updateState(state, observer.getCurrentResult())
|
|
120
|
+
},
|
|
121
|
+
{ flush: 'sync' },
|
|
122
|
+
)
|
|
110
123
|
|
|
111
124
|
onScopeDispose(() => {
|
|
112
125
|
unsubscribe()
|
package/src/useInfiniteQuery.ts
CHANGED
|
@@ -12,9 +12,8 @@ import type {
|
|
|
12
12
|
|
|
13
13
|
import type { UseBaseQueryReturnType } from './useBaseQuery'
|
|
14
14
|
|
|
15
|
-
import type { DistributiveOmit, MaybeRefDeep } from './types'
|
|
15
|
+
import type { DeepUnwrapRef, DistributiveOmit, MaybeRefDeep } from './types'
|
|
16
16
|
import type { QueryClient } from './queryClient'
|
|
17
|
-
import type { UnwrapRef } from 'vue-demi'
|
|
18
17
|
|
|
19
18
|
export type UseInfiniteQueryOptions<
|
|
20
19
|
TQueryFnData = unknown,
|
|
@@ -37,7 +36,7 @@ export type UseInfiniteQueryOptions<
|
|
|
37
36
|
TError,
|
|
38
37
|
TData,
|
|
39
38
|
TQueryData,
|
|
40
|
-
|
|
39
|
+
DeepUnwrapRef<TQueryKey>,
|
|
41
40
|
TPageParam
|
|
42
41
|
>[Property]
|
|
43
42
|
: MaybeRefDeep<
|
package/src/useIsFetching.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { onScopeDispose, ref, watchSyncEffect } from 'vue-demi'
|
|
1
|
+
import { getCurrentScope, onScopeDispose, ref, watchSyncEffect } from 'vue-demi'
|
|
2
2
|
import { useQueryClient } from './useQueryClient'
|
|
3
3
|
import type { Ref } from 'vue-demi'
|
|
4
4
|
import type { QueryFilters as QF } from '@tanstack/query-core'
|
|
@@ -11,6 +11,14 @@ export function useIsFetching(
|
|
|
11
11
|
fetchingFilters: MaybeRefDeep<QF> = {},
|
|
12
12
|
queryClient?: QueryClient,
|
|
13
13
|
): Ref<number> {
|
|
14
|
+
if (process.env.NODE_ENV === 'development') {
|
|
15
|
+
if (!getCurrentScope()) {
|
|
16
|
+
console.warn(
|
|
17
|
+
'vue-query composables like "uesQuery()" should only be used inside a "setup()" function or a running effect scope. They might otherwise lead to memory leaks.',
|
|
18
|
+
)
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|
|
14
22
|
const client = queryClient || useQueryClient()
|
|
15
23
|
|
|
16
24
|
const isFetching = ref()
|
package/src/useMutation.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
computed,
|
|
3
|
+
getCurrentScope,
|
|
3
4
|
onScopeDispose,
|
|
4
5
|
reactive,
|
|
5
6
|
readonly,
|
|
@@ -64,6 +65,14 @@ export function useMutation<
|
|
|
64
65
|
>,
|
|
65
66
|
queryClient?: QueryClient,
|
|
66
67
|
): UseMutationReturnType<TData, TError, TVariables, TContext> {
|
|
68
|
+
if (process.env.NODE_ENV === 'development') {
|
|
69
|
+
if (!getCurrentScope()) {
|
|
70
|
+
console.warn(
|
|
71
|
+
'vue-query composables like "uesQuery()" should only be used inside a "setup()" function or a running effect scope. They might otherwise lead to memory leaks.',
|
|
72
|
+
)
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
67
76
|
const client = queryClient || useQueryClient()
|
|
68
77
|
const options = computed(() => {
|
|
69
78
|
return client.defaultMutationOptions(cloneDeepUnref(mutationOptions))
|
|
@@ -84,9 +93,13 @@ export function useMutation<
|
|
|
84
93
|
})
|
|
85
94
|
}
|
|
86
95
|
|
|
87
|
-
watch(
|
|
88
|
-
|
|
89
|
-
|
|
96
|
+
watch(
|
|
97
|
+
options,
|
|
98
|
+
() => {
|
|
99
|
+
observer.setOptions(options.value)
|
|
100
|
+
},
|
|
101
|
+
{ flush: 'sync' },
|
|
102
|
+
)
|
|
90
103
|
|
|
91
104
|
onScopeDispose(() => {
|
|
92
105
|
unsubscribe()
|
package/src/useMutationState.ts
CHANGED
|
@@ -1,4 +1,11 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
computed,
|
|
3
|
+
getCurrentScope,
|
|
4
|
+
onScopeDispose,
|
|
5
|
+
readonly,
|
|
6
|
+
ref,
|
|
7
|
+
watch,
|
|
8
|
+
} from 'vue-demi'
|
|
2
9
|
import { useQueryClient } from './useQueryClient'
|
|
3
10
|
import { cloneDeepUnref } from './utils'
|
|
4
11
|
import type { DeepReadonly, Ref } from 'vue-demi'
|
|
@@ -18,6 +25,14 @@ export function useIsMutating(
|
|
|
18
25
|
filters: MutationFilters = {},
|
|
19
26
|
queryClient?: QueryClient,
|
|
20
27
|
): Ref<number> {
|
|
28
|
+
if (process.env.NODE_ENV === 'development') {
|
|
29
|
+
if (!getCurrentScope()) {
|
|
30
|
+
console.warn(
|
|
31
|
+
'vue-query composables like "uesQuery()" should only be used inside a "setup()" function or a running effect scope. They might otherwise lead to memory leaks.',
|
|
32
|
+
)
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
21
36
|
const client = queryClient || useQueryClient()
|
|
22
37
|
const unreffedFilters = computed(() => ({
|
|
23
38
|
...cloneDeepUnref(filters),
|