@tanstack/vue-query 5.103.2 → 5.103.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.d.cts +1 -1
- package/build/legacy/devtools/devtools.d.ts +1 -1
- package/build/legacy/devtools/utils.d.cts.map +1 -1
- package/build/legacy/devtools/utils.d.ts.map +1 -1
- package/build/legacy/index.d.cts +3 -3
- package/build/legacy/index.d.ts +3 -3
- package/build/legacy/{infiniteQueryOptions-qN6sOJM-.d.cts → infiniteQueryOptions-CnTRbIP5.d.cts} +16 -6
- package/build/legacy/infiniteQueryOptions-CnTRbIP5.d.cts.map +1 -0
- package/build/legacy/{infiniteQueryOptions-CEDiLwh5.d.ts → infiniteQueryOptions-NucMX_M_.d.ts} +16 -6
- package/build/legacy/infiniteQueryOptions-NucMX_M_.d.ts.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.d.cts.map +1 -1
- package/build/legacy/mutationCache.d.ts.map +1 -1
- package/build/legacy/mutationOptions.cjs.map +1 -1
- package/build/legacy/mutationOptions.d.cts +4 -0
- package/build/legacy/mutationOptions.d.cts.map +1 -1
- package/build/legacy/mutationOptions.d.ts +4 -0
- package/build/legacy/mutationOptions.d.ts.map +1 -1
- package/build/legacy/mutationOptions.js.map +1 -1
- package/build/legacy/queryCache.d.cts.map +1 -1
- package/build/legacy/queryCache.d.ts.map +1 -1
- package/build/legacy/{queryClient-Cv73nzNT.d.ts → queryClient-B6mLtXOj.d.ts} +9 -2
- package/build/legacy/queryClient-B6mLtXOj.d.ts.map +1 -0
- package/build/{modern/queryClient-CZeNAt68.d.cts → legacy/queryClient-Bn2Ql_Lu.d.cts} +9 -2
- package/build/legacy/queryClient-Bn2Ql_Lu.d.cts.map +1 -0
- package/build/legacy/queryClient.cjs +7 -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 +7 -0
- package/build/legacy/queryClient.js.map +1 -1
- package/build/{modern/queryOptions-DPDwdVBu.d.ts → legacy/queryOptions-CsM5TXD2.d.ts} +4 -3
- package/build/legacy/queryOptions-CsM5TXD2.d.ts.map +1 -0
- package/build/{modern/queryOptions-rkZ3sk6g.d.cts → legacy/queryOptions-CwqQgQmQ.d.cts} +4 -3
- package/build/legacy/queryOptions-CwqQgQmQ.d.cts.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/legacy/types-JpJB72CS.d.cts.map +1 -1
- package/build/legacy/types-JpJB72CS.d.ts.map +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.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.map +1 -1
- package/build/legacy/useIsFetching.d.cts +1 -1
- package/build/legacy/useIsFetching.d.cts.map +1 -1
- package/build/legacy/useIsFetching.d.ts +1 -1
- package/build/legacy/useIsFetching.d.ts.map +1 -1
- package/build/legacy/useIsFetching.js.map +1 -1
- package/build/legacy/useMutation.d.cts +1 -1
- package/build/legacy/useMutation.d.cts.map +1 -1
- package/build/legacy/useMutation.d.ts +1 -1
- package/build/legacy/useMutation.d.ts.map +1 -1
- package/build/legacy/useMutationState.cjs.map +1 -1
- package/build/legacy/useMutationState.d.cts +1 -1
- package/build/legacy/useMutationState.d.cts.map +1 -1
- package/build/legacy/useMutationState.d.ts +1 -1
- package/build/legacy/useMutationState.d.ts.map +1 -1
- package/build/legacy/useMutationState.js.map +1 -1
- package/build/legacy/usePrefetchInfiniteQuery.d.cts +1 -1
- package/build/legacy/usePrefetchInfiniteQuery.d.cts.map +1 -1
- package/build/legacy/usePrefetchInfiniteQuery.d.ts +1 -1
- package/build/legacy/usePrefetchInfiniteQuery.d.ts.map +1 -1
- package/build/legacy/usePrefetchQuery.d.cts +1 -1
- package/build/legacy/usePrefetchQuery.d.cts.map +1 -1
- package/build/legacy/usePrefetchQuery.d.ts +1 -1
- package/build/legacy/usePrefetchQuery.d.ts.map +1 -1
- package/build/legacy/useQueries.d.cts +2 -2
- package/build/legacy/useQueries.d.cts.map +1 -1
- package/build/legacy/useQueries.d.ts +2 -2
- package/build/legacy/useQueries.d.ts.map +1 -1
- package/build/legacy/useQuery.cjs.map +1 -1
- package/build/legacy/useQuery.d.cts +13 -7
- package/build/legacy/useQuery.d.cts.map +1 -1
- package/build/legacy/useQuery.d.ts +13 -7
- package/build/legacy/useQuery.d.ts.map +1 -1
- package/build/legacy/useQuery.js.map +1 -1
- package/build/legacy/useQueryClient.d.cts +1 -1
- package/build/legacy/useQueryClient.d.ts +1 -1
- package/build/legacy/vueQueryPlugin.d.cts +1 -1
- package/build/legacy/vueQueryPlugin.d.ts +1 -1
- package/build/modern/devtools/devtools.d.cts +1 -1
- package/build/modern/devtools/devtools.d.ts +1 -1
- package/build/modern/devtools/utils.d.cts.map +1 -1
- package/build/modern/devtools/utils.d.ts.map +1 -1
- package/build/modern/index.d.cts +3 -3
- package/build/modern/index.d.ts +3 -3
- package/build/modern/{infiniteQueryOptions-qN6sOJM-.d.cts → infiniteQueryOptions-CnTRbIP5.d.cts} +16 -6
- package/build/modern/infiniteQueryOptions-CnTRbIP5.d.cts.map +1 -0
- package/build/modern/{infiniteQueryOptions-CEDiLwh5.d.ts → infiniteQueryOptions-NucMX_M_.d.ts} +16 -6
- package/build/modern/infiniteQueryOptions-NucMX_M_.d.ts.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.d.cts.map +1 -1
- package/build/modern/mutationCache.d.ts.map +1 -1
- package/build/modern/mutationOptions.cjs.map +1 -1
- package/build/modern/mutationOptions.d.cts +4 -0
- package/build/modern/mutationOptions.d.cts.map +1 -1
- package/build/modern/mutationOptions.d.ts +4 -0
- package/build/modern/mutationOptions.d.ts.map +1 -1
- package/build/modern/mutationOptions.js.map +1 -1
- package/build/modern/queryCache.d.cts.map +1 -1
- package/build/modern/queryCache.d.ts.map +1 -1
- package/build/modern/{queryClient-Cv73nzNT.d.ts → queryClient-B6mLtXOj.d.ts} +9 -2
- package/build/modern/queryClient-B6mLtXOj.d.ts.map +1 -0
- package/build/{legacy/queryClient-CZeNAt68.d.cts → modern/queryClient-Bn2Ql_Lu.d.cts} +9 -2
- package/build/modern/queryClient-Bn2Ql_Lu.d.cts.map +1 -0
- package/build/modern/queryClient.cjs +7 -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 +7 -0
- package/build/modern/queryClient.js.map +1 -1
- package/build/{legacy/queryOptions-DPDwdVBu.d.ts → modern/queryOptions-CsM5TXD2.d.ts} +4 -3
- package/build/modern/queryOptions-CsM5TXD2.d.ts.map +1 -0
- package/build/{legacy/queryOptions-rkZ3sk6g.d.cts → modern/queryOptions-CwqQgQmQ.d.cts} +4 -3
- package/build/modern/queryOptions-CwqQgQmQ.d.cts.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.cts.map +1 -1
- package/build/modern/types-JpJB72CS.d.ts.map +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.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.map +1 -1
- package/build/modern/useIsFetching.d.cts +1 -1
- package/build/modern/useIsFetching.d.cts.map +1 -1
- package/build/modern/useIsFetching.d.ts +1 -1
- package/build/modern/useIsFetching.d.ts.map +1 -1
- package/build/modern/useIsFetching.js.map +1 -1
- package/build/modern/useMutation.d.cts +1 -1
- package/build/modern/useMutation.d.cts.map +1 -1
- package/build/modern/useMutation.d.ts +1 -1
- package/build/modern/useMutation.d.ts.map +1 -1
- package/build/modern/useMutationState.cjs.map +1 -1
- package/build/modern/useMutationState.d.cts +1 -1
- package/build/modern/useMutationState.d.cts.map +1 -1
- package/build/modern/useMutationState.d.ts +1 -1
- package/build/modern/useMutationState.d.ts.map +1 -1
- package/build/modern/useMutationState.js.map +1 -1
- package/build/modern/usePrefetchInfiniteQuery.d.cts +1 -1
- package/build/modern/usePrefetchInfiniteQuery.d.cts.map +1 -1
- package/build/modern/usePrefetchInfiniteQuery.d.ts +1 -1
- package/build/modern/usePrefetchInfiniteQuery.d.ts.map +1 -1
- package/build/modern/usePrefetchQuery.d.cts +1 -1
- package/build/modern/usePrefetchQuery.d.cts.map +1 -1
- package/build/modern/usePrefetchQuery.d.ts +1 -1
- package/build/modern/usePrefetchQuery.d.ts.map +1 -1
- package/build/modern/useQueries.d.cts +2 -2
- package/build/modern/useQueries.d.cts.map +1 -1
- package/build/modern/useQueries.d.ts +2 -2
- package/build/modern/useQueries.d.ts.map +1 -1
- package/build/modern/useQuery.cjs.map +1 -1
- package/build/modern/useQuery.d.cts +13 -7
- package/build/modern/useQuery.d.cts.map +1 -1
- package/build/modern/useQuery.d.ts +13 -7
- package/build/modern/useQuery.d.ts.map +1 -1
- package/build/modern/useQuery.js.map +1 -1
- package/build/modern/useQueryClient.d.cts +1 -1
- package/build/modern/useQueryClient.d.ts +1 -1
- package/build/modern/vueQueryPlugin.d.cts +1 -1
- package/build/modern/vueQueryPlugin.d.ts +1 -1
- package/package.json +8 -8
- package/src/infiniteQueryOptions.ts +3 -2
- package/src/mutationOptions.ts +4 -0
- package/src/queryClient.ts +7 -0
- package/src/queryOptions.ts +29 -26
- package/src/useBaseQuery.ts +9 -3
- package/src/useInfiniteQuery.ts +11 -8
- package/src/useIsFetching.ts +1 -2
- package/src/useMutationState.ts +1 -2
- package/src/useQuery.ts +11 -6
- package/build/legacy/infiniteQueryOptions-CEDiLwh5.d.ts.map +0 -1
- package/build/legacy/infiniteQueryOptions-qN6sOJM-.d.cts.map +0 -1
- package/build/legacy/queryClient-CZeNAt68.d.cts.map +0 -1
- package/build/legacy/queryClient-Cv73nzNT.d.ts.map +0 -1
- package/build/legacy/queryOptions-DPDwdVBu.d.ts.map +0 -1
- package/build/legacy/queryOptions-rkZ3sk6g.d.cts.map +0 -1
- package/build/modern/infiniteQueryOptions-CEDiLwh5.d.ts.map +0 -1
- package/build/modern/infiniteQueryOptions-qN6sOJM-.d.cts.map +0 -1
- package/build/modern/queryClient-CZeNAt68.d.cts.map +0 -1
- package/build/modern/queryClient-Cv73nzNT.d.ts.map +0 -1
- package/build/modern/queryOptions-DPDwdVBu.d.ts.map +0 -1
- package/build/modern/queryOptions-rkZ3sk6g.d.cts.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"queryOptions.cjs","names":[],"sources":["../../src/queryOptions.ts"],"sourcesContent":["import type {\n DeepUnwrapRef,\n MaybeRef,\n MaybeRefDeep,\n MaybeRefOrGetter,\n ShallowOption,\n} from './types'\nimport type {\n DefaultError,\n InitialDataFunction,\n NonUndefinedGuard,\n QueryBooleanOption,\n QueryKey,\n QueryKeyWithDataTag,\n QueryObserverOptions,\n} from '@tanstack/query-core'\n\n/**\n * The plain, unwrapped options that `queryOptions` hands back, and what `useQuery`, `useQueries`, and the\n * `queryClient` methods see once `ref`s have been resolved. To pass options in, use\n * {@link UseQueryOptions}, which accepts the same options as `ref`s and `computed`s too.\n *\n * @template TQueryFnData - The type your `queryFn` resolves to.\n * @template TError - The type of errors your `queryFn` may throw.\n * @template TData - The type `data` ends up as after `select` runs.\n * @template TQueryData - The type of data stored in the cache, before `select` runs. Defaults to\n * `TQueryFnData` and can be configured independently of it.\n * @template TQueryKey - The type of your `queryKey`.\n */\nexport type QueryOptions<\n TQueryFnData = unknown,\n TError = DefaultError,\n TData = TQueryFnData,\n TQueryData = TQueryFnData,\n TQueryKey extends QueryKey = QueryKey,\n> = {\n [Property in keyof QueryObserverOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryData,\n TQueryKey\n >]: Property extends 'enabled'\n ?\n | MaybeRefOrGetter<boolean | undefined>\n | (() => QueryBooleanOption<\n TQueryFnData,\n TError,\n TQueryData,\n DeepUnwrapRef<TQueryKey>\n >)\n : Property extends 'queryKey'\n ? MaybeRefOrGetter<TQueryKey>\n : QueryObserverOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryData,\n DeepUnwrapRef<TQueryKey>\n >[Property]\n} & ShallowOption\n\n// Widen the type of the symbol to enable type inference even if skipToken is not immutable.\ntype SkipTokenForUseQuery = symbol\n\n/**\n * The options accepted by `queryOptions`, `useQuery`, and the other query hooks. `enabled` tracks reactive\n * dependencies automatically as a `ref`, a plain value, or a reactive getter (`() => ...`). `queryKey` reacts\n * through a `ref` or a reactive getter for the array itself, or `ref`s and reactive getters as individual\n * entries. Other options are read once when passed as a plain value, and stay reactive when passed as a `ref`\n * or a `computed`. Only `enabled` and `queryKey` read a function as a getter, so `queryFn` reacts through a\n * `computed`: a function there is the query function itself.\n *\n * If you instead pass a getter for the whole options object (`useQuery(() => ({ ... }))`), every option\n * inside it — including `staleTime`, `retry`, and `select` — is re-evaluated whenever the getter's own\n * reactive dependencies change, since the entire object is recomputed.\n *\n * `select` only re-runs when `data` changes, or when the `select` function's own reference changes. Since a\n * Vue `setup()` function runs only once per component instance, an inline `select` function passed directly\n * to `queryOptions`/`useQuery` already has a stable reference across reactive updates. An inline `select`\n * created inside a whole-options getter is recreated — and so can change reference — every time that getter\n * re-evaluates.\n *\n * @template TQueryFnData - The type your `queryFn` resolves to.\n * @template TError - The type of errors your `queryFn` may throw.\n * @template TData - The type `data` ends up as after `select` runs.\n * @template TQueryData - The type of data stored in the cache, before `select` runs. Defaults to\n * `TQueryFnData` and can be configured independently of it.\n * @template TQueryKey - The type of your `queryKey`.\n */\nexport type UseQueryOptions<\n TQueryFnData = unknown,\n TError = DefaultError,\n TData = TQueryFnData,\n TQueryData = TQueryFnData,\n TQueryKey extends QueryKey = QueryKey,\n> = MaybeRef<\n {\n [Property in keyof QueryObserverOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryData,\n TQueryKey\n >]: Property extends 'enabled' | 'queryKey'\n ? QueryOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryData,\n TQueryKey\n >[Property]\n : Property extends 'queryFn'\n ? MaybeRefDeep<\n | QueryOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryData,\n TQueryKey\n >[Property]\n | SkipTokenForUseQuery\n >\n : MaybeRefDeep<\n QueryOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryData,\n TQueryKey\n >[Property]\n >\n } & ShallowOption\n>\n\ntype WithUndefinedInitialData<TQueryFnData> = {\n /**\n * If set, this value will be used as the initial data for the query cache (as long as the query hasn't been\n * created or cached yet). If set to a function, the function will be called **once** during the shared/root\n * query initialization, and be expected to synchronously return the initial data. Initial data is\n * considered stale by default unless a `staleTime` has been set. `initialData` **is persisted** to the\n * cache. Unlike `queryKey`/`enabled`, this is not reactive — it isn't re-evaluated on `ref` changes.\n */\n initialData?:\n | undefined\n | InitialDataFunction<NonUndefinedGuard<TQueryFnData>>\n | NonUndefinedGuard<TQueryFnData>\n}\n\ntype WithDefinedInitialData<TQueryFnData> = {\n /**\n * If set, this value will be used as the initial data for the query cache (as long as the query hasn't been\n * created or cached yet). If set to a function, the function will be called **once** during the shared/root\n * query initialization, and be expected to synchronously return the initial data. Initial data is\n * considered stale by default unless a `staleTime` has been set. `initialData` **is persisted** to the\n * cache. Unlike `queryKey`/`enabled`, this is not reactive — it isn't re-evaluated on `ref` changes.\n */\n initialData:\n | NonUndefinedGuard<TQueryFnData>\n | (() => NonUndefinedGuard<TQueryFnData>)\n}\n\n/**\n * The options accepted by the `queryOptions` overload selected when no `initialData` is set — `data` may be\n * `undefined` while the query is `pending`.\n *\n * @template TQueryFnData - The type your `queryFn` resolves to.\n * @template TError - The type of errors your `queryFn` may throw.\n * @template TData - The type `data` ends up as after `select` runs.\n * @template TQueryKey - The type of your `queryKey`.\n */\nexport type UndefinedInitialQueryOptions<\n TQueryFnData = unknown,\n TError = DefaultError,\n TData = TQueryFnData,\n TQueryKey extends QueryKey = QueryKey,\n> = UseQueryOptions<TQueryFnData, TError, TData, TQueryFnData, TQueryKey> &\n WithUndefinedInitialData<TQueryFnData>\n\n/**\n * The options accepted by the `queryOptions` overload selected when `initialData` is set — `data` is never\n * `undefined`.\n *\n * @template TQueryFnData - The type your `queryFn` resolves to.\n * @template TError - The type of errors your `queryFn` may throw.\n * @template TData - The type `data` ends up as after `select` runs.\n * @template TQueryKey - The type of your `queryKey`.\n */\nexport type DefinedInitialQueryOptions<\n TQueryFnData = unknown,\n TError = DefaultError,\n TData = TQueryFnData,\n TQueryKey extends QueryKey = QueryKey,\n> = UseQueryOptions<TQueryFnData, TError, TData, TQueryFnData, TQueryKey> &\n WithDefinedInitialData<TQueryFnData>\n\nexport type UndefinedInitialQueryOptionsWithDataTag<\n TQueryFnData = unknown,\n TError = DefaultError,\n TData = TQueryFnData,\n TQueryKey extends QueryKey = QueryKey,\n> = QueryOptions<TQueryFnData, TError, TData, TQueryFnData, TQueryKey> &\n WithUndefinedInitialData<TQueryFnData> &\n QueryKeyWithDataTag<TQueryKey, TQueryFnData, TError>\n\nexport type DefinedInitialQueryOptionsWithDataTag<\n TQueryFnData = unknown,\n TError = DefaultError,\n TData = TQueryFnData,\n TQueryKey extends QueryKey = QueryKey,\n> = QueryOptions<TQueryFnData, TError, TData, TQueryFnData, TQueryKey> &\n WithDefinedInitialData<TQueryFnData> &\n QueryKeyWithDataTag<TQueryKey, TQueryFnData, TError>\n\n/**\n * You can generally pass everything to `queryOptions` that you can also pass to `useQuery`. These options can\n * be shared across hooks and imperative APIs such as `queryClient.query`. `options.queryKey` is required and\n * is the query key to generate options for.\n *\n * This overload is selected when `initialData` is set, so the resulting `data` is never `undefined`.\n *\n * @see {@link useQuery} to run a query with these options.\n * @param options - The {@link DefinedInitialQueryOptions} to use — everything you can pass to `useQuery`, with\n * `initialData` set.\n * @returns The same options object, typed so that `queryKey` carries the inferred data type.\n *\n * @example\n * ```vue\n * <script setup lang=\"ts\">\n * import { queryOptions, useQuery } from '@tanstack/vue-query'\n *\n * const postsOptions = queryOptions({\n * queryKey: ['posts'],\n * queryFn: fetchPosts,\n * initialData: [],\n * })\n *\n * // `data` is `Post[]`, never `undefined`, thanks to `initialData` — even if a refetch fails,\n * // so the list stays visible alongside the error.\n * const { data, isError, error } = useQuery(postsOptions)\n * </script>\n * ```\n */\nexport function queryOptions<\n TQueryFnData = unknown,\n TError = DefaultError,\n TData = TQueryFnData,\n TQueryKey extends QueryKey = QueryKey,\n>(\n options: DefinedInitialQueryOptions<TQueryFnData, TError, TData, TQueryKey>,\n): DefinedInitialQueryOptionsWithDataTag<TQueryFnData, TError, TData, TQueryKey>\n\n/**\n * Same as the plain-object overload, but for options that close over reactive state (`ref`s read inside the\n * function body). Wrap them in a getter so `queryClient` methods like `invalidateQueries`/`fetchQuery` always\n * read the current values instead of the ones captured when the options were created.\n *\n * @see {@link useQuery} to run a query with these options.\n * @param options - A function returning the {@link DefinedInitialQueryOptions} to use, re-evaluated on demand.\n * @returns A function that returns the same options object, typed so that `queryKey` carries the inferred data\n * type.\n *\n * @example\n * ```vue\n * <script setup lang=\"ts\">\n * import { ref } from 'vue'\n * import { queryOptions, useQuery } from '@tanstack/vue-query'\n *\n * const postId = ref(1)\n * const postOptions = queryOptions(() => ({\n * queryKey: ['post', postId.value],\n * queryFn: () => fetchPost(postId.value),\n * initialData: { id: postId.value, title: '' },\n * }))\n *\n * // Pass the getter itself, not `postOptions()`, so the query keeps reacting to `postId` changes.\n * const { data } = useQuery(postOptions)\n * </script>\n * ```\n */\nexport function queryOptions<\n TQueryFnData = unknown,\n TError = DefaultError,\n TData = TQueryFnData,\n TQueryKey extends QueryKey = QueryKey,\n>(\n options: () => DefinedInitialQueryOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryKey\n >,\n): () => DefinedInitialQueryOptionsWithDataTag<\n TQueryFnData,\n TError,\n TData,\n TQueryKey\n>\n\n/**\n * You can generally pass everything to `queryOptions` that you can also pass to `useQuery`. These options can\n * be shared across hooks and imperative APIs such as `queryClient.query`. `options.queryKey` is required and\n * is the query key to generate options for.\n *\n * @see {@link useQuery} to run a query with these options.\n * @param options - The {@link UndefinedInitialQueryOptions} to use — everything you can pass to `useQuery`.\n * @returns The same options object, typed so that `queryKey` carries the inferred data type.\n *\n * @example\n * A parameterized factory, so the same options object can be reused per `id`:\n * ```vue\n * <script setup lang=\"ts\">\n * import { queryOptions, useQuery } from '@tanstack/vue-query'\n *\n * function postOptions(id: string) {\n * return queryOptions({\n * queryKey: ['post', id],\n * queryFn: () => fetchPost(id),\n * })\n * }\n *\n * const { data, isPending, isError, error } = useQuery(postOptions('1'))\n * </script>\n * ```\n */\nexport function queryOptions<\n TQueryFnData = unknown,\n TError = DefaultError,\n TData = TQueryFnData,\n TQueryKey extends QueryKey = QueryKey,\n>(\n options: UndefinedInitialQueryOptions<TQueryFnData, TError, TData, TQueryKey>,\n): UndefinedInitialQueryOptionsWithDataTag<\n TQueryFnData,\n TError,\n TData,\n TQueryKey\n>\n\n/**\n * Same as the plain-object overload, but for options that close over reactive state (`ref`s read inside the\n * function body). Wrap them in a getter so the `queryKey` — and anything else derived from a `ref` — reacts\n * to changes, and so `queryClient` methods like `invalidateQueries`/`fetchQuery` always read the current\n * values instead of the ones captured when the options were created.\n *\n * @see {@link useQuery} to run a query with these options.\n * @param options - A function returning the {@link UndefinedInitialQueryOptions} to use, re-evaluated on\n * demand.\n * @returns A function that returns the same options object, typed so that `queryKey` carries the inferred\n * data type.\n *\n * @example\n * ```vue\n * <script setup lang=\"ts\">\n * import { ref } from 'vue'\n * import { queryOptions, useQuery, useQueryClient } from '@tanstack/vue-query'\n *\n * const postId = ref(1)\n * const postOptions = queryOptions(() => ({\n * queryKey: ['post', postId.value],\n * queryFn: () => fetchPost(postId.value),\n * }))\n *\n * // Pass the getter itself, not `postOptions()`, so the query keeps reacting to `postId` changes.\n * const { data } = useQuery(postOptions)\n * const queryClient = useQueryClient()\n * // Here, call `postOptions()` so `invalidateQueries` reads the current `queryKey` right away.\n * queryClient.invalidateQueries(postOptions())\n * </script>\n * ```\n *\n * @example\n * A parameterized factory that disables the query, type safe, until `postId` is set. The whole-options getter\n * re-evaluates `queryFn` on every change to `postId`. `queryFn` can also be a `computed`, but never a bare\n * getter, since a function there is the query function itself:\n * ```vue\n * <script setup lang=\"ts\">\n * import { queryOptions, skipToken, useQuery } from '@tanstack/vue-query'\n *\n * function postOptions(postId: number | undefined) {\n * return queryOptions(() => ({\n * queryKey: ['post', postId],\n * queryFn: postId != null ? () => fetchPost(postId) : skipToken,\n * }))\n * }\n *\n * const props = defineProps<{ postId: number | undefined }>()\n * const { data, isLoading, isError, error } = useQuery(postOptions(props.postId))\n * </script>\n * ```\n */\nexport function queryOptions<\n TQueryFnData = unknown,\n TError = DefaultError,\n TData = TQueryFnData,\n TQueryKey extends QueryKey = QueryKey,\n>(\n options: () => UndefinedInitialQueryOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryKey\n >,\n): () => UndefinedInitialQueryOptionsWithDataTag<\n TQueryFnData,\n TError,\n TData,\n TQueryKey\n>\n\nexport function queryOptions(options: unknown) {\n return options\n}\n"],"mappings":";;AA0ZA,SAAgB,aAAa,SAAkB;CAC7C,OAAO;AACT"}
|
|
1
|
+
{"version":3,"file":"queryOptions.cjs","names":[],"sources":["../../src/queryOptions.ts"],"sourcesContent":["import type {\n DeepUnwrapRef,\n MaybeRef,\n MaybeRefDeep,\n MaybeRefOrGetter,\n ShallowOption,\n} from './types'\nimport type {\n DefaultError,\n InitialDataFunction,\n NonUndefinedGuard,\n QueryBooleanOption,\n QueryKey,\n QueryKeyWithDataTag,\n QueryObserverOptions,\n} from '@tanstack/query-core'\n\n/**\n * The plain, unwrapped options that `queryOptions` hands back, and what `useQuery`, `useQueries`, and the\n * `queryClient` methods see once `ref`s have been resolved. To pass options in, use\n * {@link UseQueryOptions}, which accepts the same options as `ref`s and `computed`s too.\n *\n * @template TQueryFnData - The type your `queryFn` resolves to.\n * @template TError - The type of errors your `queryFn` may throw.\n * @template TData - The type `data` ends up as after `select` runs.\n * @template TQueryData - The type of data stored in the cache, before `select` runs. Defaults to\n * `TQueryFnData` and can be configured independently of it.\n * @template TQueryKey - The type of your `queryKey`.\n */\nexport type QueryOptions<\n TQueryFnData = unknown,\n TError = DefaultError,\n TData = TQueryFnData,\n TQueryData = TQueryFnData,\n TQueryKey extends QueryKey = QueryKey,\n> = {\n [\n Property in keyof QueryObserverOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryData,\n TQueryKey\n >\n ]: Property extends 'enabled'\n ? | MaybeRefOrGetter<boolean | undefined>\n | (() => QueryBooleanOption<\n TQueryFnData,\n TError,\n TQueryData,\n DeepUnwrapRef<TQueryKey>\n >)\n : Property extends 'queryKey'\n ? MaybeRefOrGetter<TQueryKey>\n : QueryObserverOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryData,\n DeepUnwrapRef<TQueryKey>\n >[Property]\n} & ShallowOption\n\n// Widen the type of the symbol to enable type inference even if skipToken is not immutable.\ntype SkipTokenForUseQuery = symbol\n\n/**\n * The options accepted by `queryOptions`, `useQuery`, and the other query hooks. `enabled` tracks reactive\n * dependencies automatically as a `ref`, a plain value, or a reactive getter (`() => ...`). `queryKey` reacts\n * through a `ref` or a reactive getter for the array itself, or `ref`s and reactive getters as individual\n * entries. Other options are read once when passed as a plain value, and stay reactive when passed as a `ref`\n * or a `computed`. Only `enabled` and `queryKey` read a function as a getter, so `queryFn` reacts through a\n * `computed`: a function there is the query function itself.\n *\n * If you instead pass a getter for the whole options object (`useQuery(() => ({ ... }))`), every option\n * inside it — including `staleTime`, `retry`, and `select` — is re-evaluated whenever the getter's own\n * reactive dependencies change, since the entire object is recomputed.\n *\n * `select` only re-runs when `data` changes, or when the `select` function's own reference changes. Since a\n * Vue `setup()` function runs only once per component instance, an inline `select` function passed directly\n * to `queryOptions`/`useQuery` already has a stable reference across reactive updates. An inline `select`\n * created inside a whole-options getter is recreated — and so can change reference — every time that getter\n * re-evaluates.\n *\n * @template TQueryFnData - The type your `queryFn` resolves to.\n * @template TError - The type of errors your `queryFn` may throw.\n * @template TData - The type `data` ends up as after `select` runs.\n * @template TQueryData - The type of data stored in the cache, before `select` runs. Defaults to\n * `TQueryFnData` and can be configured independently of it.\n * @template TQueryKey - The type of your `queryKey`.\n */\nexport type UseQueryOptions<\n TQueryFnData = unknown,\n TError = DefaultError,\n TData = TQueryFnData,\n TQueryData = TQueryFnData,\n TQueryKey extends QueryKey = QueryKey,\n> = MaybeRef<\n {\n [\n Property in keyof QueryObserverOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryData,\n TQueryKey\n >\n ]: Property extends 'enabled' | 'queryKey'\n ? QueryOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryData,\n TQueryKey\n >[Property]\n : Property extends 'queryFn'\n ? MaybeRefDeep<\n | QueryOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryData,\n TQueryKey\n >[Property]\n | SkipTokenForUseQuery\n >\n : MaybeRefDeep<\n QueryOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryData,\n TQueryKey\n >[Property]\n >\n } & ShallowOption\n>\n\ntype WithUndefinedInitialData<TQueryFnData> = {\n /**\n * If set, this value will be used as the initial data for the query cache (as long as the query hasn't been\n * created or cached yet). If set to a function, the function will be called **once** during the shared/root\n * query initialization, and be expected to synchronously return the initial data. Initial data is\n * considered stale by default unless a `staleTime` has been set. `initialData` **is persisted** to the\n * cache. Unlike `queryKey`/`enabled`, this is not reactive — it isn't re-evaluated on `ref` changes.\n */\n initialData?:\n | undefined\n | InitialDataFunction<NonUndefinedGuard<TQueryFnData>>\n | NonUndefinedGuard<TQueryFnData>\n}\n\ntype WithDefinedInitialData<TQueryFnData> = {\n /**\n * If set, this value will be used as the initial data for the query cache (as long as the query hasn't been\n * created or cached yet). If set to a function, the function will be called **once** during the shared/root\n * query initialization, and be expected to synchronously return the initial data. Initial data is\n * considered stale by default unless a `staleTime` has been set. `initialData` **is persisted** to the\n * cache. Unlike `queryKey`/`enabled`, this is not reactive — it isn't re-evaluated on `ref` changes.\n */\n initialData:\n NonUndefinedGuard<TQueryFnData> | (() => NonUndefinedGuard<TQueryFnData>)\n}\n\n/**\n * The options accepted by the `queryOptions` overload selected when no `initialData` is set — `data` may be\n * `undefined` while the query is `pending`.\n *\n * @template TQueryFnData - The type your `queryFn` resolves to.\n * @template TError - The type of errors your `queryFn` may throw.\n * @template TData - The type `data` ends up as after `select` runs.\n * @template TQueryKey - The type of your `queryKey`.\n */\nexport type UndefinedInitialQueryOptions<\n TQueryFnData = unknown,\n TError = DefaultError,\n TData = TQueryFnData,\n TQueryKey extends QueryKey = QueryKey,\n> = UseQueryOptions<TQueryFnData, TError, TData, TQueryFnData, TQueryKey> &\n WithUndefinedInitialData<TQueryFnData>\n\n/**\n * The options accepted by the `queryOptions` overload selected when `initialData` is set — `data` is never\n * `undefined` (unless a `select` changes `TData` to include `undefined`).\n *\n * @template TQueryFnData - The type your `queryFn` resolves to.\n * @template TError - The type of errors your `queryFn` may throw.\n * @template TData - The type `data` ends up as after `select` runs.\n * @template TQueryKey - The type of your `queryKey`.\n */\nexport type DefinedInitialQueryOptions<\n TQueryFnData = unknown,\n TError = DefaultError,\n TData = TQueryFnData,\n TQueryKey extends QueryKey = QueryKey,\n> = UseQueryOptions<TQueryFnData, TError, TData, TQueryFnData, TQueryKey> &\n WithDefinedInitialData<TQueryFnData>\n\nexport type UndefinedInitialQueryOptionsWithDataTag<\n TQueryFnData = unknown,\n TError = DefaultError,\n TData = TQueryFnData,\n TQueryKey extends QueryKey = QueryKey,\n> = QueryOptions<TQueryFnData, TError, TData, TQueryFnData, TQueryKey> &\n WithUndefinedInitialData<TQueryFnData> &\n QueryKeyWithDataTag<TQueryKey, TQueryFnData, TError>\n\nexport type DefinedInitialQueryOptionsWithDataTag<\n TQueryFnData = unknown,\n TError = DefaultError,\n TData = TQueryFnData,\n TQueryKey extends QueryKey = QueryKey,\n> = QueryOptions<TQueryFnData, TError, TData, TQueryFnData, TQueryKey> &\n WithDefinedInitialData<TQueryFnData> &\n QueryKeyWithDataTag<TQueryKey, TQueryFnData, TError>\n\n/**\n * You can generally pass everything to `queryOptions` that you can also pass to `useQuery`. These options can\n * be shared across hooks and imperative APIs such as `queryClient.query`. `options.queryKey` is required and\n * is the query key to generate options for.\n *\n * This overload is selected when `initialData` is set, so the resulting `data` is never `undefined` (unless\n * a `select` changes `TData` to include `undefined`).\n *\n * @see {@link useQuery} to run a query with these options.\n * @param options - The {@link DefinedInitialQueryOptions} to use — everything you can pass to `useQuery`, with\n * `initialData` set.\n * @returns The same options object, typed so that `queryKey` carries the inferred data type.\n *\n * @example\n * ```vue\n * <script setup lang=\"ts\">\n * import { queryOptions, useQuery } from '@tanstack/vue-query'\n *\n * const postsOptions = queryOptions({\n * queryKey: ['posts'],\n * queryFn: fetchPosts,\n * initialData: [],\n * })\n *\n * // `data` is `Post[]`, never `undefined`, thanks to `initialData` — even if a refetch fails,\n * // so the list stays visible alongside the error.\n * const { data, isError, error } = useQuery(postsOptions)\n * </script>\n * ```\n */\nexport function queryOptions<\n TQueryFnData = unknown,\n TError = DefaultError,\n TData = TQueryFnData,\n TQueryKey extends QueryKey = QueryKey,\n>(\n options: DefinedInitialQueryOptions<TQueryFnData, TError, TData, TQueryKey>,\n): DefinedInitialQueryOptionsWithDataTag<TQueryFnData, TError, TData, TQueryKey>\n\n/**\n * Same as the plain-object overload, but for options that close over reactive state (`ref`s read inside the\n * function body). Wrap them in a getter so `queryClient` methods like `invalidateQueries`/`fetchQuery` always\n * read the current values instead of the ones captured when the options were created.\n *\n * @see {@link useQuery} to run a query with these options.\n * @param options - A function returning the {@link DefinedInitialQueryOptions} to use, re-evaluated on demand.\n * @returns A function that returns the same options object, typed so that `queryKey` carries the inferred data\n * type.\n *\n * @example\n * ```vue\n * <script setup lang=\"ts\">\n * import { ref } from 'vue'\n * import { queryOptions, useQuery } from '@tanstack/vue-query'\n *\n * const postId = ref(1)\n * const postOptions = queryOptions(() => ({\n * queryKey: ['post', postId.value],\n * queryFn: () => fetchPost(postId.value),\n * initialData: { id: postId.value, title: '' },\n * }))\n *\n * // Pass the getter itself, not `postOptions()`, so the query keeps reacting to `postId` changes.\n * const { data } = useQuery(postOptions)\n * </script>\n * ```\n */\nexport function queryOptions<\n TQueryFnData = unknown,\n TError = DefaultError,\n TData = TQueryFnData,\n TQueryKey extends QueryKey = QueryKey,\n>(\n options: () => DefinedInitialQueryOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryKey\n >,\n): () => DefinedInitialQueryOptionsWithDataTag<\n TQueryFnData,\n TError,\n TData,\n TQueryKey\n>\n\n/**\n * You can generally pass everything to `queryOptions` that you can also pass to `useQuery`. These options can\n * be shared across hooks and imperative APIs such as `queryClient.query`. `options.queryKey` is required and\n * is the query key to generate options for.\n *\n * @see {@link useQuery} to run a query with these options.\n * @param options - The {@link UndefinedInitialQueryOptions} to use — everything you can pass to `useQuery`.\n * @returns The same options object, typed so that `queryKey` carries the inferred data type.\n *\n * @example\n * A parameterized factory, so the same options object can be reused per `id`:\n * ```vue\n * <script setup lang=\"ts\">\n * import { queryOptions, useQuery } from '@tanstack/vue-query'\n *\n * function postOptions(id: string) {\n * return queryOptions({\n * queryKey: ['post', id],\n * queryFn: () => fetchPost(id),\n * })\n * }\n *\n * const { data, isPending, isError, error } = useQuery(postOptions('1'))\n * </script>\n * ```\n */\nexport function queryOptions<\n TQueryFnData = unknown,\n TError = DefaultError,\n TData = TQueryFnData,\n TQueryKey extends QueryKey = QueryKey,\n>(\n options: UndefinedInitialQueryOptions<TQueryFnData, TError, TData, TQueryKey>,\n): UndefinedInitialQueryOptionsWithDataTag<\n TQueryFnData,\n TError,\n TData,\n TQueryKey\n>\n\n/**\n * Same as the plain-object overload, but for options that close over reactive state (`ref`s read inside the\n * function body). Wrap them in a getter so the `queryKey` — and anything else derived from a `ref` — reacts\n * to changes, and so `queryClient` methods like `invalidateQueries`/`fetchQuery` always read the current\n * values instead of the ones captured when the options were created.\n *\n * @see {@link useQuery} to run a query with these options.\n * @param options - A function returning the {@link UndefinedInitialQueryOptions} to use, re-evaluated on\n * demand.\n * @returns A function that returns the same options object, typed so that `queryKey` carries the inferred\n * data type.\n *\n * @example\n * ```vue\n * <script setup lang=\"ts\">\n * import { ref } from 'vue'\n * import { queryOptions, useQuery, useQueryClient } from '@tanstack/vue-query'\n *\n * const postId = ref(1)\n * const postOptions = queryOptions(() => ({\n * queryKey: ['post', postId.value],\n * queryFn: () => fetchPost(postId.value),\n * }))\n *\n * // Pass the getter itself, not `postOptions()`, so the query keeps reacting to `postId` changes.\n * const { data } = useQuery(postOptions)\n * const queryClient = useQueryClient()\n * // Here, call `postOptions()` so `invalidateQueries` reads the current `queryKey` right away.\n * queryClient.invalidateQueries(postOptions())\n * </script>\n * ```\n *\n * @example\n * A parameterized factory that disables the query, type safe, until `postId` is set. The whole-options getter\n * re-evaluates `queryFn` on every change to `postId`. `queryFn` can also be a `computed`, but never a bare\n * getter, since a function there is the query function itself:\n * ```vue\n * <script setup lang=\"ts\">\n * import { queryOptions, skipToken, useQuery } from '@tanstack/vue-query'\n *\n * function postOptions(postId: number | undefined) {\n * return queryOptions(() => ({\n * queryKey: ['post', postId],\n * queryFn: postId != null ? () => fetchPost(postId) : skipToken,\n * }))\n * }\n *\n * const props = defineProps<{ postId: number | undefined }>()\n * const { data, isLoading, isError, error } = useQuery(postOptions(props.postId))\n * </script>\n * ```\n */\nexport function queryOptions<\n TQueryFnData = unknown,\n TError = DefaultError,\n TData = TQueryFnData,\n TQueryKey extends QueryKey = QueryKey,\n>(\n options: () => UndefinedInitialQueryOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryKey\n >,\n): () => UndefinedInitialQueryOptionsWithDataTag<\n TQueryFnData,\n TError,\n TData,\n TQueryKey\n>\n\nexport function queryOptions(options: unknown) {\n return options\n}\n"],"mappings":";;AA6ZA,SAAgB,aAAa,SAAkB;CAC7C,OAAO;AACT"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { a as UndefinedInitialQueryOptionsWithDataTag, i as UndefinedInitialQueryOptions, n as DefinedInitialQueryOptionsWithDataTag, o as UseQueryOptions, r as QueryOptions, s as queryOptions, t as DefinedInitialQueryOptions } from "./queryOptions-
|
|
1
|
+
import { a as UndefinedInitialQueryOptionsWithDataTag, i as UndefinedInitialQueryOptions, n as DefinedInitialQueryOptionsWithDataTag, o as UseQueryOptions, r as QueryOptions, s as queryOptions, t as DefinedInitialQueryOptions } from "./queryOptions-CwqQgQmQ.cjs";
|
|
2
2
|
export { DefinedInitialQueryOptions, DefinedInitialQueryOptionsWithDataTag, QueryOptions, UndefinedInitialQueryOptions, UndefinedInitialQueryOptionsWithDataTag, UseQueryOptions, queryOptions };
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { a as UndefinedInitialQueryOptionsWithDataTag, i as UndefinedInitialQueryOptions, n as DefinedInitialQueryOptionsWithDataTag, o as UseQueryOptions, r as QueryOptions, s as queryOptions, t as DefinedInitialQueryOptions } from "./queryOptions-
|
|
1
|
+
import { a as UndefinedInitialQueryOptionsWithDataTag, i as UndefinedInitialQueryOptions, n as DefinedInitialQueryOptionsWithDataTag, o as UseQueryOptions, r as QueryOptions, s as queryOptions, t as DefinedInitialQueryOptions } from "./queryOptions-CsM5TXD2.js";
|
|
2
2
|
export { DefinedInitialQueryOptions, DefinedInitialQueryOptionsWithDataTag, QueryOptions, UndefinedInitialQueryOptions, UndefinedInitialQueryOptionsWithDataTag, UseQueryOptions, queryOptions };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"queryOptions.js","names":[],"sources":["../../src/queryOptions.ts"],"sourcesContent":["import type {\n DeepUnwrapRef,\n MaybeRef,\n MaybeRefDeep,\n MaybeRefOrGetter,\n ShallowOption,\n} from './types'\nimport type {\n DefaultError,\n InitialDataFunction,\n NonUndefinedGuard,\n QueryBooleanOption,\n QueryKey,\n QueryKeyWithDataTag,\n QueryObserverOptions,\n} from '@tanstack/query-core'\n\n/**\n * The plain, unwrapped options that `queryOptions` hands back, and what `useQuery`, `useQueries`, and the\n * `queryClient` methods see once `ref`s have been resolved. To pass options in, use\n * {@link UseQueryOptions}, which accepts the same options as `ref`s and `computed`s too.\n *\n * @template TQueryFnData - The type your `queryFn` resolves to.\n * @template TError - The type of errors your `queryFn` may throw.\n * @template TData - The type `data` ends up as after `select` runs.\n * @template TQueryData - The type of data stored in the cache, before `select` runs. Defaults to\n * `TQueryFnData` and can be configured independently of it.\n * @template TQueryKey - The type of your `queryKey`.\n */\nexport type QueryOptions<\n TQueryFnData = unknown,\n TError = DefaultError,\n TData = TQueryFnData,\n TQueryData = TQueryFnData,\n TQueryKey extends QueryKey = QueryKey,\n> = {\n [Property in keyof QueryObserverOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryData,\n TQueryKey\n >]: Property extends 'enabled'\n ?\n | MaybeRefOrGetter<boolean | undefined>\n | (() => QueryBooleanOption<\n TQueryFnData,\n TError,\n TQueryData,\n DeepUnwrapRef<TQueryKey>\n >)\n : Property extends 'queryKey'\n ? MaybeRefOrGetter<TQueryKey>\n : QueryObserverOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryData,\n DeepUnwrapRef<TQueryKey>\n >[Property]\n} & ShallowOption\n\n// Widen the type of the symbol to enable type inference even if skipToken is not immutable.\ntype SkipTokenForUseQuery = symbol\n\n/**\n * The options accepted by `queryOptions`, `useQuery`, and the other query hooks. `enabled` tracks reactive\n * dependencies automatically as a `ref`, a plain value, or a reactive getter (`() => ...`). `queryKey` reacts\n * through a `ref` or a reactive getter for the array itself, or `ref`s and reactive getters as individual\n * entries. Other options are read once when passed as a plain value, and stay reactive when passed as a `ref`\n * or a `computed`. Only `enabled` and `queryKey` read a function as a getter, so `queryFn` reacts through a\n * `computed`: a function there is the query function itself.\n *\n * If you instead pass a getter for the whole options object (`useQuery(() => ({ ... }))`), every option\n * inside it — including `staleTime`, `retry`, and `select` — is re-evaluated whenever the getter's own\n * reactive dependencies change, since the entire object is recomputed.\n *\n * `select` only re-runs when `data` changes, or when the `select` function's own reference changes. Since a\n * Vue `setup()` function runs only once per component instance, an inline `select` function passed directly\n * to `queryOptions`/`useQuery` already has a stable reference across reactive updates. An inline `select`\n * created inside a whole-options getter is recreated — and so can change reference — every time that getter\n * re-evaluates.\n *\n * @template TQueryFnData - The type your `queryFn` resolves to.\n * @template TError - The type of errors your `queryFn` may throw.\n * @template TData - The type `data` ends up as after `select` runs.\n * @template TQueryData - The type of data stored in the cache, before `select` runs. Defaults to\n * `TQueryFnData` and can be configured independently of it.\n * @template TQueryKey - The type of your `queryKey`.\n */\nexport type UseQueryOptions<\n TQueryFnData = unknown,\n TError = DefaultError,\n TData = TQueryFnData,\n TQueryData = TQueryFnData,\n TQueryKey extends QueryKey = QueryKey,\n> = MaybeRef<\n {\n [Property in keyof QueryObserverOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryData,\n TQueryKey\n >]: Property extends 'enabled' | 'queryKey'\n ? QueryOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryData,\n TQueryKey\n >[Property]\n : Property extends 'queryFn'\n ? MaybeRefDeep<\n | QueryOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryData,\n TQueryKey\n >[Property]\n | SkipTokenForUseQuery\n >\n : MaybeRefDeep<\n QueryOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryData,\n TQueryKey\n >[Property]\n >\n } & ShallowOption\n>\n\ntype WithUndefinedInitialData<TQueryFnData> = {\n /**\n * If set, this value will be used as the initial data for the query cache (as long as the query hasn't been\n * created or cached yet). If set to a function, the function will be called **once** during the shared/root\n * query initialization, and be expected to synchronously return the initial data. Initial data is\n * considered stale by default unless a `staleTime` has been set. `initialData` **is persisted** to the\n * cache. Unlike `queryKey`/`enabled`, this is not reactive — it isn't re-evaluated on `ref` changes.\n */\n initialData?:\n | undefined\n | InitialDataFunction<NonUndefinedGuard<TQueryFnData>>\n | NonUndefinedGuard<TQueryFnData>\n}\n\ntype WithDefinedInitialData<TQueryFnData> = {\n /**\n * If set, this value will be used as the initial data for the query cache (as long as the query hasn't been\n * created or cached yet). If set to a function, the function will be called **once** during the shared/root\n * query initialization, and be expected to synchronously return the initial data. Initial data is\n * considered stale by default unless a `staleTime` has been set. `initialData` **is persisted** to the\n * cache. Unlike `queryKey`/`enabled`, this is not reactive — it isn't re-evaluated on `ref` changes.\n */\n initialData:\n | NonUndefinedGuard<TQueryFnData>\n | (() => NonUndefinedGuard<TQueryFnData>)\n}\n\n/**\n * The options accepted by the `queryOptions` overload selected when no `initialData` is set — `data` may be\n * `undefined` while the query is `pending`.\n *\n * @template TQueryFnData - The type your `queryFn` resolves to.\n * @template TError - The type of errors your `queryFn` may throw.\n * @template TData - The type `data` ends up as after `select` runs.\n * @template TQueryKey - The type of your `queryKey`.\n */\nexport type UndefinedInitialQueryOptions<\n TQueryFnData = unknown,\n TError = DefaultError,\n TData = TQueryFnData,\n TQueryKey extends QueryKey = QueryKey,\n> = UseQueryOptions<TQueryFnData, TError, TData, TQueryFnData, TQueryKey> &\n WithUndefinedInitialData<TQueryFnData>\n\n/**\n * The options accepted by the `queryOptions` overload selected when `initialData` is set — `data` is never\n * `undefined`.\n *\n * @template TQueryFnData - The type your `queryFn` resolves to.\n * @template TError - The type of errors your `queryFn` may throw.\n * @template TData - The type `data` ends up as after `select` runs.\n * @template TQueryKey - The type of your `queryKey`.\n */\nexport type DefinedInitialQueryOptions<\n TQueryFnData = unknown,\n TError = DefaultError,\n TData = TQueryFnData,\n TQueryKey extends QueryKey = QueryKey,\n> = UseQueryOptions<TQueryFnData, TError, TData, TQueryFnData, TQueryKey> &\n WithDefinedInitialData<TQueryFnData>\n\nexport type UndefinedInitialQueryOptionsWithDataTag<\n TQueryFnData = unknown,\n TError = DefaultError,\n TData = TQueryFnData,\n TQueryKey extends QueryKey = QueryKey,\n> = QueryOptions<TQueryFnData, TError, TData, TQueryFnData, TQueryKey> &\n WithUndefinedInitialData<TQueryFnData> &\n QueryKeyWithDataTag<TQueryKey, TQueryFnData, TError>\n\nexport type DefinedInitialQueryOptionsWithDataTag<\n TQueryFnData = unknown,\n TError = DefaultError,\n TData = TQueryFnData,\n TQueryKey extends QueryKey = QueryKey,\n> = QueryOptions<TQueryFnData, TError, TData, TQueryFnData, TQueryKey> &\n WithDefinedInitialData<TQueryFnData> &\n QueryKeyWithDataTag<TQueryKey, TQueryFnData, TError>\n\n/**\n * You can generally pass everything to `queryOptions` that you can also pass to `useQuery`. These options can\n * be shared across hooks and imperative APIs such as `queryClient.query`. `options.queryKey` is required and\n * is the query key to generate options for.\n *\n * This overload is selected when `initialData` is set, so the resulting `data` is never `undefined`.\n *\n * @see {@link useQuery} to run a query with these options.\n * @param options - The {@link DefinedInitialQueryOptions} to use — everything you can pass to `useQuery`, with\n * `initialData` set.\n * @returns The same options object, typed so that `queryKey` carries the inferred data type.\n *\n * @example\n * ```vue\n * <script setup lang=\"ts\">\n * import { queryOptions, useQuery } from '@tanstack/vue-query'\n *\n * const postsOptions = queryOptions({\n * queryKey: ['posts'],\n * queryFn: fetchPosts,\n * initialData: [],\n * })\n *\n * // `data` is `Post[]`, never `undefined`, thanks to `initialData` — even if a refetch fails,\n * // so the list stays visible alongside the error.\n * const { data, isError, error } = useQuery(postsOptions)\n * </script>\n * ```\n */\nexport function queryOptions<\n TQueryFnData = unknown,\n TError = DefaultError,\n TData = TQueryFnData,\n TQueryKey extends QueryKey = QueryKey,\n>(\n options: DefinedInitialQueryOptions<TQueryFnData, TError, TData, TQueryKey>,\n): DefinedInitialQueryOptionsWithDataTag<TQueryFnData, TError, TData, TQueryKey>\n\n/**\n * Same as the plain-object overload, but for options that close over reactive state (`ref`s read inside the\n * function body). Wrap them in a getter so `queryClient` methods like `invalidateQueries`/`fetchQuery` always\n * read the current values instead of the ones captured when the options were created.\n *\n * @see {@link useQuery} to run a query with these options.\n * @param options - A function returning the {@link DefinedInitialQueryOptions} to use, re-evaluated on demand.\n * @returns A function that returns the same options object, typed so that `queryKey` carries the inferred data\n * type.\n *\n * @example\n * ```vue\n * <script setup lang=\"ts\">\n * import { ref } from 'vue'\n * import { queryOptions, useQuery } from '@tanstack/vue-query'\n *\n * const postId = ref(1)\n * const postOptions = queryOptions(() => ({\n * queryKey: ['post', postId.value],\n * queryFn: () => fetchPost(postId.value),\n * initialData: { id: postId.value, title: '' },\n * }))\n *\n * // Pass the getter itself, not `postOptions()`, so the query keeps reacting to `postId` changes.\n * const { data } = useQuery(postOptions)\n * </script>\n * ```\n */\nexport function queryOptions<\n TQueryFnData = unknown,\n TError = DefaultError,\n TData = TQueryFnData,\n TQueryKey extends QueryKey = QueryKey,\n>(\n options: () => DefinedInitialQueryOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryKey\n >,\n): () => DefinedInitialQueryOptionsWithDataTag<\n TQueryFnData,\n TError,\n TData,\n TQueryKey\n>\n\n/**\n * You can generally pass everything to `queryOptions` that you can also pass to `useQuery`. These options can\n * be shared across hooks and imperative APIs such as `queryClient.query`. `options.queryKey` is required and\n * is the query key to generate options for.\n *\n * @see {@link useQuery} to run a query with these options.\n * @param options - The {@link UndefinedInitialQueryOptions} to use — everything you can pass to `useQuery`.\n * @returns The same options object, typed so that `queryKey` carries the inferred data type.\n *\n * @example\n * A parameterized factory, so the same options object can be reused per `id`:\n * ```vue\n * <script setup lang=\"ts\">\n * import { queryOptions, useQuery } from '@tanstack/vue-query'\n *\n * function postOptions(id: string) {\n * return queryOptions({\n * queryKey: ['post', id],\n * queryFn: () => fetchPost(id),\n * })\n * }\n *\n * const { data, isPending, isError, error } = useQuery(postOptions('1'))\n * </script>\n * ```\n */\nexport function queryOptions<\n TQueryFnData = unknown,\n TError = DefaultError,\n TData = TQueryFnData,\n TQueryKey extends QueryKey = QueryKey,\n>(\n options: UndefinedInitialQueryOptions<TQueryFnData, TError, TData, TQueryKey>,\n): UndefinedInitialQueryOptionsWithDataTag<\n TQueryFnData,\n TError,\n TData,\n TQueryKey\n>\n\n/**\n * Same as the plain-object overload, but for options that close over reactive state (`ref`s read inside the\n * function body). Wrap them in a getter so the `queryKey` — and anything else derived from a `ref` — reacts\n * to changes, and so `queryClient` methods like `invalidateQueries`/`fetchQuery` always read the current\n * values instead of the ones captured when the options were created.\n *\n * @see {@link useQuery} to run a query with these options.\n * @param options - A function returning the {@link UndefinedInitialQueryOptions} to use, re-evaluated on\n * demand.\n * @returns A function that returns the same options object, typed so that `queryKey` carries the inferred\n * data type.\n *\n * @example\n * ```vue\n * <script setup lang=\"ts\">\n * import { ref } from 'vue'\n * import { queryOptions, useQuery, useQueryClient } from '@tanstack/vue-query'\n *\n * const postId = ref(1)\n * const postOptions = queryOptions(() => ({\n * queryKey: ['post', postId.value],\n * queryFn: () => fetchPost(postId.value),\n * }))\n *\n * // Pass the getter itself, not `postOptions()`, so the query keeps reacting to `postId` changes.\n * const { data } = useQuery(postOptions)\n * const queryClient = useQueryClient()\n * // Here, call `postOptions()` so `invalidateQueries` reads the current `queryKey` right away.\n * queryClient.invalidateQueries(postOptions())\n * </script>\n * ```\n *\n * @example\n * A parameterized factory that disables the query, type safe, until `postId` is set. The whole-options getter\n * re-evaluates `queryFn` on every change to `postId`. `queryFn` can also be a `computed`, but never a bare\n * getter, since a function there is the query function itself:\n * ```vue\n * <script setup lang=\"ts\">\n * import { queryOptions, skipToken, useQuery } from '@tanstack/vue-query'\n *\n * function postOptions(postId: number | undefined) {\n * return queryOptions(() => ({\n * queryKey: ['post', postId],\n * queryFn: postId != null ? () => fetchPost(postId) : skipToken,\n * }))\n * }\n *\n * const props = defineProps<{ postId: number | undefined }>()\n * const { data, isLoading, isError, error } = useQuery(postOptions(props.postId))\n * </script>\n * ```\n */\nexport function queryOptions<\n TQueryFnData = unknown,\n TError = DefaultError,\n TData = TQueryFnData,\n TQueryKey extends QueryKey = QueryKey,\n>(\n options: () => UndefinedInitialQueryOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryKey\n >,\n): () => UndefinedInitialQueryOptionsWithDataTag<\n TQueryFnData,\n TError,\n TData,\n TQueryKey\n>\n\nexport function queryOptions(options: unknown) {\n return options\n}\n"],"mappings":";AA0ZA,SAAgB,aAAa,SAAkB;CAC7C,OAAO;AACT"}
|
|
1
|
+
{"version":3,"file":"queryOptions.js","names":[],"sources":["../../src/queryOptions.ts"],"sourcesContent":["import type {\n DeepUnwrapRef,\n MaybeRef,\n MaybeRefDeep,\n MaybeRefOrGetter,\n ShallowOption,\n} from './types'\nimport type {\n DefaultError,\n InitialDataFunction,\n NonUndefinedGuard,\n QueryBooleanOption,\n QueryKey,\n QueryKeyWithDataTag,\n QueryObserverOptions,\n} from '@tanstack/query-core'\n\n/**\n * The plain, unwrapped options that `queryOptions` hands back, and what `useQuery`, `useQueries`, and the\n * `queryClient` methods see once `ref`s have been resolved. To pass options in, use\n * {@link UseQueryOptions}, which accepts the same options as `ref`s and `computed`s too.\n *\n * @template TQueryFnData - The type your `queryFn` resolves to.\n * @template TError - The type of errors your `queryFn` may throw.\n * @template TData - The type `data` ends up as after `select` runs.\n * @template TQueryData - The type of data stored in the cache, before `select` runs. Defaults to\n * `TQueryFnData` and can be configured independently of it.\n * @template TQueryKey - The type of your `queryKey`.\n */\nexport type QueryOptions<\n TQueryFnData = unknown,\n TError = DefaultError,\n TData = TQueryFnData,\n TQueryData = TQueryFnData,\n TQueryKey extends QueryKey = QueryKey,\n> = {\n [\n Property in keyof QueryObserverOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryData,\n TQueryKey\n >\n ]: Property extends 'enabled'\n ? | MaybeRefOrGetter<boolean | undefined>\n | (() => QueryBooleanOption<\n TQueryFnData,\n TError,\n TQueryData,\n DeepUnwrapRef<TQueryKey>\n >)\n : Property extends 'queryKey'\n ? MaybeRefOrGetter<TQueryKey>\n : QueryObserverOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryData,\n DeepUnwrapRef<TQueryKey>\n >[Property]\n} & ShallowOption\n\n// Widen the type of the symbol to enable type inference even if skipToken is not immutable.\ntype SkipTokenForUseQuery = symbol\n\n/**\n * The options accepted by `queryOptions`, `useQuery`, and the other query hooks. `enabled` tracks reactive\n * dependencies automatically as a `ref`, a plain value, or a reactive getter (`() => ...`). `queryKey` reacts\n * through a `ref` or a reactive getter for the array itself, or `ref`s and reactive getters as individual\n * entries. Other options are read once when passed as a plain value, and stay reactive when passed as a `ref`\n * or a `computed`. Only `enabled` and `queryKey` read a function as a getter, so `queryFn` reacts through a\n * `computed`: a function there is the query function itself.\n *\n * If you instead pass a getter for the whole options object (`useQuery(() => ({ ... }))`), every option\n * inside it — including `staleTime`, `retry`, and `select` — is re-evaluated whenever the getter's own\n * reactive dependencies change, since the entire object is recomputed.\n *\n * `select` only re-runs when `data` changes, or when the `select` function's own reference changes. Since a\n * Vue `setup()` function runs only once per component instance, an inline `select` function passed directly\n * to `queryOptions`/`useQuery` already has a stable reference across reactive updates. An inline `select`\n * created inside a whole-options getter is recreated — and so can change reference — every time that getter\n * re-evaluates.\n *\n * @template TQueryFnData - The type your `queryFn` resolves to.\n * @template TError - The type of errors your `queryFn` may throw.\n * @template TData - The type `data` ends up as after `select` runs.\n * @template TQueryData - The type of data stored in the cache, before `select` runs. Defaults to\n * `TQueryFnData` and can be configured independently of it.\n * @template TQueryKey - The type of your `queryKey`.\n */\nexport type UseQueryOptions<\n TQueryFnData = unknown,\n TError = DefaultError,\n TData = TQueryFnData,\n TQueryData = TQueryFnData,\n TQueryKey extends QueryKey = QueryKey,\n> = MaybeRef<\n {\n [\n Property in keyof QueryObserverOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryData,\n TQueryKey\n >\n ]: Property extends 'enabled' | 'queryKey'\n ? QueryOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryData,\n TQueryKey\n >[Property]\n : Property extends 'queryFn'\n ? MaybeRefDeep<\n | QueryOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryData,\n TQueryKey\n >[Property]\n | SkipTokenForUseQuery\n >\n : MaybeRefDeep<\n QueryOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryData,\n TQueryKey\n >[Property]\n >\n } & ShallowOption\n>\n\ntype WithUndefinedInitialData<TQueryFnData> = {\n /**\n * If set, this value will be used as the initial data for the query cache (as long as the query hasn't been\n * created or cached yet). If set to a function, the function will be called **once** during the shared/root\n * query initialization, and be expected to synchronously return the initial data. Initial data is\n * considered stale by default unless a `staleTime` has been set. `initialData` **is persisted** to the\n * cache. Unlike `queryKey`/`enabled`, this is not reactive — it isn't re-evaluated on `ref` changes.\n */\n initialData?:\n | undefined\n | InitialDataFunction<NonUndefinedGuard<TQueryFnData>>\n | NonUndefinedGuard<TQueryFnData>\n}\n\ntype WithDefinedInitialData<TQueryFnData> = {\n /**\n * If set, this value will be used as the initial data for the query cache (as long as the query hasn't been\n * created or cached yet). If set to a function, the function will be called **once** during the shared/root\n * query initialization, and be expected to synchronously return the initial data. Initial data is\n * considered stale by default unless a `staleTime` has been set. `initialData` **is persisted** to the\n * cache. Unlike `queryKey`/`enabled`, this is not reactive — it isn't re-evaluated on `ref` changes.\n */\n initialData:\n NonUndefinedGuard<TQueryFnData> | (() => NonUndefinedGuard<TQueryFnData>)\n}\n\n/**\n * The options accepted by the `queryOptions` overload selected when no `initialData` is set — `data` may be\n * `undefined` while the query is `pending`.\n *\n * @template TQueryFnData - The type your `queryFn` resolves to.\n * @template TError - The type of errors your `queryFn` may throw.\n * @template TData - The type `data` ends up as after `select` runs.\n * @template TQueryKey - The type of your `queryKey`.\n */\nexport type UndefinedInitialQueryOptions<\n TQueryFnData = unknown,\n TError = DefaultError,\n TData = TQueryFnData,\n TQueryKey extends QueryKey = QueryKey,\n> = UseQueryOptions<TQueryFnData, TError, TData, TQueryFnData, TQueryKey> &\n WithUndefinedInitialData<TQueryFnData>\n\n/**\n * The options accepted by the `queryOptions` overload selected when `initialData` is set — `data` is never\n * `undefined` (unless a `select` changes `TData` to include `undefined`).\n *\n * @template TQueryFnData - The type your `queryFn` resolves to.\n * @template TError - The type of errors your `queryFn` may throw.\n * @template TData - The type `data` ends up as after `select` runs.\n * @template TQueryKey - The type of your `queryKey`.\n */\nexport type DefinedInitialQueryOptions<\n TQueryFnData = unknown,\n TError = DefaultError,\n TData = TQueryFnData,\n TQueryKey extends QueryKey = QueryKey,\n> = UseQueryOptions<TQueryFnData, TError, TData, TQueryFnData, TQueryKey> &\n WithDefinedInitialData<TQueryFnData>\n\nexport type UndefinedInitialQueryOptionsWithDataTag<\n TQueryFnData = unknown,\n TError = DefaultError,\n TData = TQueryFnData,\n TQueryKey extends QueryKey = QueryKey,\n> = QueryOptions<TQueryFnData, TError, TData, TQueryFnData, TQueryKey> &\n WithUndefinedInitialData<TQueryFnData> &\n QueryKeyWithDataTag<TQueryKey, TQueryFnData, TError>\n\nexport type DefinedInitialQueryOptionsWithDataTag<\n TQueryFnData = unknown,\n TError = DefaultError,\n TData = TQueryFnData,\n TQueryKey extends QueryKey = QueryKey,\n> = QueryOptions<TQueryFnData, TError, TData, TQueryFnData, TQueryKey> &\n WithDefinedInitialData<TQueryFnData> &\n QueryKeyWithDataTag<TQueryKey, TQueryFnData, TError>\n\n/**\n * You can generally pass everything to `queryOptions` that you can also pass to `useQuery`. These options can\n * be shared across hooks and imperative APIs such as `queryClient.query`. `options.queryKey` is required and\n * is the query key to generate options for.\n *\n * This overload is selected when `initialData` is set, so the resulting `data` is never `undefined` (unless\n * a `select` changes `TData` to include `undefined`).\n *\n * @see {@link useQuery} to run a query with these options.\n * @param options - The {@link DefinedInitialQueryOptions} to use — everything you can pass to `useQuery`, with\n * `initialData` set.\n * @returns The same options object, typed so that `queryKey` carries the inferred data type.\n *\n * @example\n * ```vue\n * <script setup lang=\"ts\">\n * import { queryOptions, useQuery } from '@tanstack/vue-query'\n *\n * const postsOptions = queryOptions({\n * queryKey: ['posts'],\n * queryFn: fetchPosts,\n * initialData: [],\n * })\n *\n * // `data` is `Post[]`, never `undefined`, thanks to `initialData` — even if a refetch fails,\n * // so the list stays visible alongside the error.\n * const { data, isError, error } = useQuery(postsOptions)\n * </script>\n * ```\n */\nexport function queryOptions<\n TQueryFnData = unknown,\n TError = DefaultError,\n TData = TQueryFnData,\n TQueryKey extends QueryKey = QueryKey,\n>(\n options: DefinedInitialQueryOptions<TQueryFnData, TError, TData, TQueryKey>,\n): DefinedInitialQueryOptionsWithDataTag<TQueryFnData, TError, TData, TQueryKey>\n\n/**\n * Same as the plain-object overload, but for options that close over reactive state (`ref`s read inside the\n * function body). Wrap them in a getter so `queryClient` methods like `invalidateQueries`/`fetchQuery` always\n * read the current values instead of the ones captured when the options were created.\n *\n * @see {@link useQuery} to run a query with these options.\n * @param options - A function returning the {@link DefinedInitialQueryOptions} to use, re-evaluated on demand.\n * @returns A function that returns the same options object, typed so that `queryKey` carries the inferred data\n * type.\n *\n * @example\n * ```vue\n * <script setup lang=\"ts\">\n * import { ref } from 'vue'\n * import { queryOptions, useQuery } from '@tanstack/vue-query'\n *\n * const postId = ref(1)\n * const postOptions = queryOptions(() => ({\n * queryKey: ['post', postId.value],\n * queryFn: () => fetchPost(postId.value),\n * initialData: { id: postId.value, title: '' },\n * }))\n *\n * // Pass the getter itself, not `postOptions()`, so the query keeps reacting to `postId` changes.\n * const { data } = useQuery(postOptions)\n * </script>\n * ```\n */\nexport function queryOptions<\n TQueryFnData = unknown,\n TError = DefaultError,\n TData = TQueryFnData,\n TQueryKey extends QueryKey = QueryKey,\n>(\n options: () => DefinedInitialQueryOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryKey\n >,\n): () => DefinedInitialQueryOptionsWithDataTag<\n TQueryFnData,\n TError,\n TData,\n TQueryKey\n>\n\n/**\n * You can generally pass everything to `queryOptions` that you can also pass to `useQuery`. These options can\n * be shared across hooks and imperative APIs such as `queryClient.query`. `options.queryKey` is required and\n * is the query key to generate options for.\n *\n * @see {@link useQuery} to run a query with these options.\n * @param options - The {@link UndefinedInitialQueryOptions} to use — everything you can pass to `useQuery`.\n * @returns The same options object, typed so that `queryKey` carries the inferred data type.\n *\n * @example\n * A parameterized factory, so the same options object can be reused per `id`:\n * ```vue\n * <script setup lang=\"ts\">\n * import { queryOptions, useQuery } from '@tanstack/vue-query'\n *\n * function postOptions(id: string) {\n * return queryOptions({\n * queryKey: ['post', id],\n * queryFn: () => fetchPost(id),\n * })\n * }\n *\n * const { data, isPending, isError, error } = useQuery(postOptions('1'))\n * </script>\n * ```\n */\nexport function queryOptions<\n TQueryFnData = unknown,\n TError = DefaultError,\n TData = TQueryFnData,\n TQueryKey extends QueryKey = QueryKey,\n>(\n options: UndefinedInitialQueryOptions<TQueryFnData, TError, TData, TQueryKey>,\n): UndefinedInitialQueryOptionsWithDataTag<\n TQueryFnData,\n TError,\n TData,\n TQueryKey\n>\n\n/**\n * Same as the plain-object overload, but for options that close over reactive state (`ref`s read inside the\n * function body). Wrap them in a getter so the `queryKey` — and anything else derived from a `ref` — reacts\n * to changes, and so `queryClient` methods like `invalidateQueries`/`fetchQuery` always read the current\n * values instead of the ones captured when the options were created.\n *\n * @see {@link useQuery} to run a query with these options.\n * @param options - A function returning the {@link UndefinedInitialQueryOptions} to use, re-evaluated on\n * demand.\n * @returns A function that returns the same options object, typed so that `queryKey` carries the inferred\n * data type.\n *\n * @example\n * ```vue\n * <script setup lang=\"ts\">\n * import { ref } from 'vue'\n * import { queryOptions, useQuery, useQueryClient } from '@tanstack/vue-query'\n *\n * const postId = ref(1)\n * const postOptions = queryOptions(() => ({\n * queryKey: ['post', postId.value],\n * queryFn: () => fetchPost(postId.value),\n * }))\n *\n * // Pass the getter itself, not `postOptions()`, so the query keeps reacting to `postId` changes.\n * const { data } = useQuery(postOptions)\n * const queryClient = useQueryClient()\n * // Here, call `postOptions()` so `invalidateQueries` reads the current `queryKey` right away.\n * queryClient.invalidateQueries(postOptions())\n * </script>\n * ```\n *\n * @example\n * A parameterized factory that disables the query, type safe, until `postId` is set. The whole-options getter\n * re-evaluates `queryFn` on every change to `postId`. `queryFn` can also be a `computed`, but never a bare\n * getter, since a function there is the query function itself:\n * ```vue\n * <script setup lang=\"ts\">\n * import { queryOptions, skipToken, useQuery } from '@tanstack/vue-query'\n *\n * function postOptions(postId: number | undefined) {\n * return queryOptions(() => ({\n * queryKey: ['post', postId],\n * queryFn: postId != null ? () => fetchPost(postId) : skipToken,\n * }))\n * }\n *\n * const props = defineProps<{ postId: number | undefined }>()\n * const { data, isLoading, isError, error } = useQuery(postOptions(props.postId))\n * </script>\n * ```\n */\nexport function queryOptions<\n TQueryFnData = unknown,\n TError = DefaultError,\n TData = TQueryFnData,\n TQueryKey extends QueryKey = QueryKey,\n>(\n options: () => UndefinedInitialQueryOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryKey\n >,\n): () => UndefinedInitialQueryOptionsWithDataTag<\n TQueryFnData,\n TError,\n TData,\n TQueryKey\n>\n\nexport function queryOptions(options: unknown) {\n return options\n}\n"],"mappings":";AA6ZA,SAAgB,aAAa,SAAkB;CAC7C,OAAO;AACT"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types-JpJB72CS.d.cts","names":[],"sources":["../../src/types.ts"],"mappings":";;;KAYK;KACA,aACD,YACA,WACA,OACA,QACA,SACA,gBACA,oBACA,WACA;;KAGQ,YAAY,KAAK,WAAW;;;;;KAM5B,SAAS,KAAK,IAAI,KAAK,YAAY,KAAK;;;;;;KAOxC,iBAAiB,KAAK,SAAS,YAAY;;;;;;KAO3C,aAAa,KAAK,SAC5B,UAAU,WACN,IACA,sBAEK,kBAAkB,IAAI,aAAa,EAAE,gBAExC;;KAII,UAAU,KAAK,eAAe,0BAA0B;;KAGxD,MAAM,UAAU,cACxB,QAAQ,UAAU,4BAA2B,QAAQ,UAAU;;KAOvD,cAAc,KAAK,UAAU,aACrC,IACA,UAAU,UAAU,KAClB,cAAc,KACd,kBAEK,kBAAkB,IAAI,cAAc,EAAE,gBAEzC,UAAU;KAEN;;;;EAIV;;KAGU,gBACV,iBACA,SAAS,cACT,mBACA,6BACE,UACF,wBAAwB,OAAO,QAAQ,YAAY,kCAGnD;
|
|
1
|
+
{"version":3,"file":"types-JpJB72CS.d.cts","names":["DefaultOptions"],"sources":["../../src/types.ts"],"mappings":";;;KAYK;KACA,aACD,YACA,WACA,OACA,QACA,SACA,gBACA,oBACA,WACA;;KAGQ,YAAY,KAAK,WAAW;;;;;KAM5B,SAAS,KAAK,IAAI,KAAK,YAAY,KAAK;;;;;;KAOxC,iBAAiB,KAAK,SAAS,YAAY;;;;;;KAO3C,aAAa,KAAK,SAC5B,UAAU,WACN,IACA,sBAEK,kBAAkB,IAAI,aAAa,EAAE,gBAExC;;KAII,UAAU,KAAK,eAAe,0BAA0B;;KAGxD,MAAM,UAAU,cACxB,QAAQ,UAAU,4BAA2B,QAAQ,UAAU;;KAOvD,cAAc,KAAK,UAAU,aACrC,IACA,UAAU,UAAU,KAClB,cAAc,KACd,kBAEK,kBAAkB,IAAI,cAAc,EAAE,gBAEzC,UAAU;KAEN;;;;EAIV;;KAGU,gBACV,iBACA,SAAS,cACT,mBACA,6BACE,UACF,wBAAwB,OAAO,QAAQ,YAAY,kCAGnD;UAEeA,iBAAe,SAAS;EACvC,UAAU,UAAU,8BAA8B,uBAChD;EACF,YAAY,iCAAiC,4BAC3C;EACF,UAAU;EACV,YAAY;;UAGG;EACf,aAAa;EACb,gBAAgB;EAChB,iBAAiBA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types-JpJB72CS.d.ts","names":[],"sources":["../../src/types.ts"],"mappings":";;;KAYK;KACA,aACD,YACA,WACA,OACA,QACA,SACA,gBACA,oBACA,WACA;;KAGQ,YAAY,KAAK,WAAW;;;;;KAM5B,SAAS,KAAK,IAAI,KAAK,YAAY,KAAK;;;;;;KAOxC,iBAAiB,KAAK,SAAS,YAAY;;;;;;KAO3C,aAAa,KAAK,SAC5B,UAAU,WACN,IACA,sBAEK,kBAAkB,IAAI,aAAa,EAAE,gBAExC;;KAII,UAAU,KAAK,eAAe,0BAA0B;;KAGxD,MAAM,UAAU,cACxB,QAAQ,UAAU,4BAA2B,QAAQ,UAAU;;KAOvD,cAAc,KAAK,UAAU,aACrC,IACA,UAAU,UAAU,KAClB,cAAc,KACd,kBAEK,kBAAkB,IAAI,cAAc,EAAE,gBAEzC,UAAU;KAEN;;;;EAIV;;KAGU,gBACV,iBACA,SAAS,cACT,mBACA,6BACE,UACF,wBAAwB,OAAO,QAAQ,YAAY,kCAGnD;
|
|
1
|
+
{"version":3,"file":"types-JpJB72CS.d.ts","names":["DefaultOptions"],"sources":["../../src/types.ts"],"mappings":";;;KAYK;KACA,aACD,YACA,WACA,OACA,QACA,SACA,gBACA,oBACA,WACA;;KAGQ,YAAY,KAAK,WAAW;;;;;KAM5B,SAAS,KAAK,IAAI,KAAK,YAAY,KAAK;;;;;;KAOxC,iBAAiB,KAAK,SAAS,YAAY;;;;;;KAO3C,aAAa,KAAK,SAC5B,UAAU,WACN,IACA,sBAEK,kBAAkB,IAAI,aAAa,EAAE,gBAExC;;KAII,UAAU,KAAK,eAAe,0BAA0B;;KAGxD,MAAM,UAAU,cACxB,QAAQ,UAAU,4BAA2B,QAAQ,UAAU;;KAOvD,cAAc,KAAK,UAAU,aACrC,IACA,UAAU,UAAU,KAClB,cAAc,KACd,kBAEK,kBAAkB,IAAI,cAAc,EAAE,gBAEzC,UAAU;KAEN;;;;EAIV;;KAGU,gBACV,iBACA,SAAS,cACT,mBACA,6BACE,UACF,wBAAwB,OAAO,QAAQ,YAAY,kCAGnD;UAEeA,iBAAe,SAAS;EACvC,UAAU,UAAU,8BAA8B,uBAChD;EACF,YAAY,iCAAiC,4BAC3C;EACF,UAAU;EACV,YAAY;;UAGG;EACf,aAAa;EACb,gBAAgB;EAChB,iBAAiBA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useBaseQuery.cjs","names":["getCurrentScope","useQueryClient","computed","cloneDeepUnref","shallowReactive","reactive","shouldThrowError","watch","shallowReadonly","readonly","toRefs"],"sources":["../../src/useBaseQuery.ts"],"sourcesContent":["import {\n computed,\n getCurrentScope,\n onScopeDispose,\n reactive,\n readonly,\n shallowReactive,\n shallowReadonly,\n toRefs,\n watch,\n} from 'vue-demi'\nimport { shouldThrowError } from '@tanstack/query-core'\nimport { useQueryClient } from './useQueryClient'\nimport { cloneDeepUnref, updateState } from './utils'\nimport type { Ref } from 'vue-demi'\nimport type {\n DefaultedQueryObserverOptions,\n QueryKey,\n QueryObserver,\n QueryObserverResult,\n} from '@tanstack/query-core'\nimport type { QueryClient } from './queryClient'\nimport type { UseQueryOptions } from './queryOptions'\nimport type { UseInfiniteQueryOptions } from './useInfiniteQuery'\nimport type { MaybeRefOrGetter } from './types'\n\nexport type UseBaseQueryReturnType<\n TData,\n TError,\n TResult = QueryObserverResult<TData, TError>,\n> = {\n [K in keyof TResult]: K extends\n
|
|
1
|
+
{"version":3,"file":"useBaseQuery.cjs","names":["getCurrentScope","useQueryClient","computed","cloneDeepUnref","shallowReactive","reactive","shouldThrowError","watch","shallowReadonly","readonly","toRefs"],"sources":["../../src/useBaseQuery.ts"],"sourcesContent":["import {\n computed,\n getCurrentScope,\n onScopeDispose,\n reactive,\n readonly,\n shallowReactive,\n shallowReadonly,\n toRefs,\n watch,\n} from 'vue-demi'\nimport { shouldThrowError } from '@tanstack/query-core'\nimport { useQueryClient } from './useQueryClient'\nimport { cloneDeepUnref, updateState } from './utils'\nimport type { Ref } from 'vue-demi'\nimport type {\n DefaultedQueryObserverOptions,\n QueryKey,\n QueryObserver,\n QueryObserverResult,\n} from '@tanstack/query-core'\nimport type { QueryClient } from './queryClient'\nimport type { UseQueryOptions } from './queryOptions'\nimport type { UseInfiniteQueryOptions } from './useInfiniteQuery'\nimport type { MaybeRefOrGetter } from './types'\n\nexport type UseBaseQueryReturnType<\n TData,\n TError,\n TResult = QueryObserverResult<TData, TError>,\n> = {\n [K in keyof TResult]: K extends\n 'fetchNextPage' | 'fetchPreviousPage' | 'refetch'\n ? TResult[K]\n : Ref<Readonly<TResult>[K]>\n} & {\n /**\n * Returns a promise for use with Vue's `Suspense` or `onServerPrefetch`. It fetches the query if it has no\n * data or its data is stale and resolves with the result once that fetch resolves (usually when the query\n * function finishes, but earlier after the first chunk of a streamed query or when data is set during the\n * fetch), or resolves immediately if the data is fresh. While the query is disabled, it waits until the query\n * is enabled. If the fetch fails, it resolves with the error result, unless `throwOnError` is (or returns)\n * `true`, in which case it rejects.\n */\n suspense: () => Promise<TResult>\n}\n\ntype UseQueryOptionsGeneric<\n TQueryFnData,\n TError,\n TData,\n TQueryData,\n TQueryKey extends QueryKey = QueryKey,\n TPageParam = unknown,\n> =\n | UseQueryOptions<TQueryFnData, TError, TData, TQueryData, TQueryKey>\n | UseInfiniteQueryOptions<TQueryFnData, TError, TData, TQueryKey, TPageParam>\n\n/**\n * Base implementation shared by `useQuery` and `useInfiniteQuery`.\n *\n * @param Observer - The observer class from query-core (`QueryObserver` or `InfiniteQueryObserver`).\n * @param options - A `ref`, plain value, or reactive getter resolving to the query options.\n * @param queryClient - Use this to use a custom `QueryClient`. Otherwise, the one provided by `VueQueryPlugin`\n * will be used.\n */\nexport function useBaseQuery<\n TQueryFnData,\n TError,\n TData,\n TQueryData,\n TQueryKey extends QueryKey,\n TPageParam,\n>(\n Observer: typeof QueryObserver,\n options: MaybeRefOrGetter<\n UseQueryOptionsGeneric<\n TQueryFnData,\n TError,\n TData,\n TQueryData,\n TQueryKey,\n TPageParam\n >\n >,\n queryClient?: QueryClient,\n): UseBaseQueryReturnType<TData, TError> {\n if (process.env.NODE_ENV === 'development') {\n if (!getCurrentScope()) {\n console.warn(\n 'vue-query composable like \"useQuery()\" should only be used inside a \"setup()\" function or a running effect scope. They might otherwise lead to memory leaks.',\n )\n }\n }\n\n const client = queryClient || useQueryClient()\n\n const defaultedOptions = computed(() => {\n let resolvedOptions = options\n if (typeof resolvedOptions === 'function') {\n resolvedOptions = resolvedOptions()\n }\n const clonedOptions = cloneDeepUnref(resolvedOptions as any)\n\n if (typeof clonedOptions.enabled === 'function') {\n clonedOptions.enabled = clonedOptions.enabled()\n }\n\n const defaulted: DefaultedQueryObserverOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryData,\n TQueryKey\n > = client.defaultQueryOptions(clonedOptions)\n\n defaulted._optimisticResults = client.isRestoring?.value\n ? 'isRestoring'\n : 'optimistic'\n\n return defaulted\n })\n\n const observer = new Observer(client, defaultedOptions.value)\n // @ts-expect-error\n const state = defaultedOptions.value.shallow\n ? shallowReactive(observer.getCurrentResult())\n : reactive(observer.getCurrentResult())\n\n let unsubscribe = () => {\n // noop\n }\n\n if (client.isRestoring) {\n watch(\n client.isRestoring,\n (isRestoring) => {\n if (!isRestoring) {\n unsubscribe()\n unsubscribe = observer.subscribe((result) => {\n updateState(state, result)\n })\n }\n },\n { immediate: true },\n )\n }\n\n const updater = () => {\n observer.setOptions(defaultedOptions.value)\n updateState(state, observer.getCurrentResult())\n }\n\n watch(defaultedOptions, updater)\n\n onScopeDispose(() => {\n unsubscribe()\n })\n\n // fix #5910\n const refetch = (...args: Parameters<(typeof state)['refetch']>) => {\n updater()\n return state.refetch(...args)\n }\n\n const suspense = () => {\n return new Promise<QueryObserverResult<TData, TError>>(\n (resolve, reject) => {\n let stopWatch = () => {\n // noop\n }\n const run = () => {\n if (defaultedOptions.value.enabled !== false) {\n // fix #6133\n observer.setOptions(defaultedOptions.value)\n const optimisticResult = observer.getOptimisticResult(\n defaultedOptions.value,\n )\n if (optimisticResult.isStale) {\n stopWatch()\n observer\n .fetchOptimistic(defaultedOptions.value)\n .then(resolve, (error: TError) => {\n if (\n shouldThrowError(defaultedOptions.value.throwOnError, [\n error,\n observer.getCurrentQuery(),\n ])\n ) {\n reject(error)\n } else {\n resolve(observer.getCurrentResult())\n }\n })\n } else {\n stopWatch()\n resolve(optimisticResult)\n }\n }\n }\n\n run()\n\n stopWatch = watch(defaultedOptions, run)\n },\n )\n }\n\n // Handle error boundary\n watch(\n () => state.error,\n (error) => {\n if (\n state.isError &&\n !state.isFetching &&\n shouldThrowError(defaultedOptions.value.throwOnError, [\n error as TError,\n observer.getCurrentQuery(),\n ])\n ) {\n throw error\n }\n },\n )\n\n // @ts-expect-error\n const readonlyState = defaultedOptions.value.shallow\n ? shallowReadonly(state)\n : readonly(state)\n\n const object: any = toRefs(readonlyState)\n for (const key in state) {\n if (typeof state[key as keyof typeof state] === 'function') {\n object[key] = state[key as keyof typeof state]\n }\n }\n\n object.suspense = suspense\n object.refetch = refetch\n\n return object as UseBaseQueryReturnType<TData, TError>\n}\n"],"mappings":";;;;;;;;;;;;;;AAkEA,SAAgB,aAQd,UACA,SAUA,aACuC;CACvC,IAAI,QAAQ,IAAI,aAAa,eACvB;MAAA,EAAA,GAACA,SAAAA,gBAAAA,CAAgB,GACnB,QAAQ,KACN,kKACF;CAAA;CAIJ,MAAM,SAAS,eAAeC,uBAAAA,eAAe;CAE7C,MAAM,oBAAA,GAAmBC,SAAAA,SAAAA,OAAe;EACtC,IAAI,kBAAkB;EACtB,IAAI,OAAO,oBAAoB,YAC7B,kBAAkB,gBAAgB;EAEpC,MAAM,gBAAgBC,cAAAA,eAAe,eAAsB;EAE3D,IAAI,OAAO,cAAc,YAAY,YACnC,cAAc,UAAU,cAAc,QAAQ;EAGhD,MAAM,YAMF,OAAO,oBAAoB,aAAa;EAE5C,UAAU,qBAAqB,OAAO,aAAa,QAC/C,gBACA;EAEJ,OAAO;CACT,CAAC;CAED,MAAM,WAAW,IAAI,SAAS,QAAQ,iBAAiB,KAAK;CAE5D,MAAM,QAAQ,iBAAiB,MAAM,WAAA,GACjCC,SAAAA,gBAAAA,CAAgB,SAAS,iBAAiB,CAAC,KAAA,GAC3CC,SAAAA,SAAAA,CAAS,SAAS,iBAAiB,CAAC;CAExC,IAAI,oBAAoB,CAExB;CAEA,IAAI,OAAO,aACT,CAAA,GAAA,SAAA,MAAA,CACE,OAAO,cACN,gBAAgB;EACf,IAAI,CAAC,aAAa;GAChB,YAAY;GACZ,cAAc,SAAS,WAAW,WAAW;IAC3C,cAAA,YAAY,OAAO,MAAM;GAC3B,CAAC;EACH;CACF,GACA,EAAE,WAAW,KAAK,CACpB;CAGF,MAAM,gBAAgB;EACpB,SAAS,WAAW,iBAAiB,KAAK;EAC1C,cAAA,YAAY,OAAO,SAAS,iBAAiB,CAAC;CAChD;CAEA,CAAA,GAAA,SAAA,MAAA,CAAM,kBAAkB,OAAO;CAE/B,CAAA,GAAA,SAAA,eAAA,OAAqB;EACnB,YAAY;CACd,CAAC;CAGD,MAAM,WAAW,GAAG,SAAgD;EAClE,QAAQ;EACR,OAAO,MAAM,QAAQ,GAAG,IAAI;CAC9B;CAEA,MAAM,iBAAiB;EACrB,OAAO,IAAI,SACR,SAAS,WAAW;GACnB,IAAI,kBAAkB,CAEtB;GACA,MAAM,YAAY;IAChB,IAAI,iBAAiB,MAAM,YAAY,OAAO;KAE5C,SAAS,WAAW,iBAAiB,KAAK;KAC1C,MAAM,mBAAmB,SAAS,oBAChC,iBAAiB,KACnB;KACA,IAAI,iBAAiB,SAAS;MAC5B,UAAU;MACV,SACG,gBAAgB,iBAAiB,KAAK,CAAC,CACvC,KAAK,UAAU,UAAkB;OAChC,KAAA,GACEC,qBAAAA,iBAAAA,CAAiB,iBAAiB,MAAM,cAAc,CACpD,OACA,SAAS,gBAAgB,CAC3B,CAAC,GAED,OAAO,KAAK;YAEZ,QAAQ,SAAS,iBAAiB,CAAC;MAEvC,CAAC;KACL,OAAO;MACL,UAAU;MACV,QAAQ,gBAAgB;KAC1B;IACF;GACF;GAEA,IAAI;GAEJ,aAAA,GAAYC,SAAAA,MAAAA,CAAM,kBAAkB,GAAG;EACzC,CACF;CACF;CAGA,CAAA,GAAA,SAAA,MAAA,OACQ,MAAM,QACX,UAAU;EACT,IACE,MAAM,WACN,CAAC,MAAM,eAAA,GACPD,qBAAAA,iBAAAA,CAAiB,iBAAiB,MAAM,cAAc,CACpD,OACA,SAAS,gBAAgB,CAC3B,CAAC,GAED,MAAM;CAEV,CACF;CAGA,MAAM,gBAAgB,iBAAiB,MAAM,WAAA,GACzCE,SAAAA,gBAAAA,CAAgB,KAAK,KAAA,GACrBC,SAAAA,SAAAA,CAAS,KAAK;CAElB,MAAM,UAAA,GAAcC,SAAAA,OAAAA,CAAO,aAAa;CACxC,KAAK,MAAM,OAAO,OAChB,IAAI,OAAO,MAAM,SAA+B,YAC9C,OAAO,OAAO,MAAM;CAIxB,OAAO,WAAW;CAClB,OAAO,UAAU;CAEjB,OAAO;AACT"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { c as useBaseQuery, s as UseBaseQueryReturnType } from "./infiniteQueryOptions-
|
|
1
|
+
import { c as useBaseQuery, s as UseBaseQueryReturnType } from "./infiniteQueryOptions-CnTRbIP5.cjs";
|
|
2
2
|
export { UseBaseQueryReturnType, useBaseQuery };
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { c as useBaseQuery, s as UseBaseQueryReturnType } from "./infiniteQueryOptions-
|
|
1
|
+
import { c as useBaseQuery, s as UseBaseQueryReturnType } from "./infiniteQueryOptions-NucMX_M_.js";
|
|
2
2
|
export { UseBaseQueryReturnType, useBaseQuery };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useBaseQuery.js","names":[],"sources":["../../src/useBaseQuery.ts"],"sourcesContent":["import {\n computed,\n getCurrentScope,\n onScopeDispose,\n reactive,\n readonly,\n shallowReactive,\n shallowReadonly,\n toRefs,\n watch,\n} from 'vue-demi'\nimport { shouldThrowError } from '@tanstack/query-core'\nimport { useQueryClient } from './useQueryClient'\nimport { cloneDeepUnref, updateState } from './utils'\nimport type { Ref } from 'vue-demi'\nimport type {\n DefaultedQueryObserverOptions,\n QueryKey,\n QueryObserver,\n QueryObserverResult,\n} from '@tanstack/query-core'\nimport type { QueryClient } from './queryClient'\nimport type { UseQueryOptions } from './queryOptions'\nimport type { UseInfiniteQueryOptions } from './useInfiniteQuery'\nimport type { MaybeRefOrGetter } from './types'\n\nexport type UseBaseQueryReturnType<\n TData,\n TError,\n TResult = QueryObserverResult<TData, TError>,\n> = {\n [K in keyof TResult]: K extends\n
|
|
1
|
+
{"version":3,"file":"useBaseQuery.js","names":[],"sources":["../../src/useBaseQuery.ts"],"sourcesContent":["import {\n computed,\n getCurrentScope,\n onScopeDispose,\n reactive,\n readonly,\n shallowReactive,\n shallowReadonly,\n toRefs,\n watch,\n} from 'vue-demi'\nimport { shouldThrowError } from '@tanstack/query-core'\nimport { useQueryClient } from './useQueryClient'\nimport { cloneDeepUnref, updateState } from './utils'\nimport type { Ref } from 'vue-demi'\nimport type {\n DefaultedQueryObserverOptions,\n QueryKey,\n QueryObserver,\n QueryObserverResult,\n} from '@tanstack/query-core'\nimport type { QueryClient } from './queryClient'\nimport type { UseQueryOptions } from './queryOptions'\nimport type { UseInfiniteQueryOptions } from './useInfiniteQuery'\nimport type { MaybeRefOrGetter } from './types'\n\nexport type UseBaseQueryReturnType<\n TData,\n TError,\n TResult = QueryObserverResult<TData, TError>,\n> = {\n [K in keyof TResult]: K extends\n 'fetchNextPage' | 'fetchPreviousPage' | 'refetch'\n ? TResult[K]\n : Ref<Readonly<TResult>[K]>\n} & {\n /**\n * Returns a promise for use with Vue's `Suspense` or `onServerPrefetch`. It fetches the query if it has no\n * data or its data is stale and resolves with the result once that fetch resolves (usually when the query\n * function finishes, but earlier after the first chunk of a streamed query or when data is set during the\n * fetch), or resolves immediately if the data is fresh. While the query is disabled, it waits until the query\n * is enabled. If the fetch fails, it resolves with the error result, unless `throwOnError` is (or returns)\n * `true`, in which case it rejects.\n */\n suspense: () => Promise<TResult>\n}\n\ntype UseQueryOptionsGeneric<\n TQueryFnData,\n TError,\n TData,\n TQueryData,\n TQueryKey extends QueryKey = QueryKey,\n TPageParam = unknown,\n> =\n | UseQueryOptions<TQueryFnData, TError, TData, TQueryData, TQueryKey>\n | UseInfiniteQueryOptions<TQueryFnData, TError, TData, TQueryKey, TPageParam>\n\n/**\n * Base implementation shared by `useQuery` and `useInfiniteQuery`.\n *\n * @param Observer - The observer class from query-core (`QueryObserver` or `InfiniteQueryObserver`).\n * @param options - A `ref`, plain value, or reactive getter resolving to the query options.\n * @param queryClient - Use this to use a custom `QueryClient`. Otherwise, the one provided by `VueQueryPlugin`\n * will be used.\n */\nexport function useBaseQuery<\n TQueryFnData,\n TError,\n TData,\n TQueryData,\n TQueryKey extends QueryKey,\n TPageParam,\n>(\n Observer: typeof QueryObserver,\n options: MaybeRefOrGetter<\n UseQueryOptionsGeneric<\n TQueryFnData,\n TError,\n TData,\n TQueryData,\n TQueryKey,\n TPageParam\n >\n >,\n queryClient?: QueryClient,\n): UseBaseQueryReturnType<TData, TError> {\n if (process.env.NODE_ENV === 'development') {\n if (!getCurrentScope()) {\n console.warn(\n 'vue-query composable like \"useQuery()\" should only be used inside a \"setup()\" function or a running effect scope. They might otherwise lead to memory leaks.',\n )\n }\n }\n\n const client = queryClient || useQueryClient()\n\n const defaultedOptions = computed(() => {\n let resolvedOptions = options\n if (typeof resolvedOptions === 'function') {\n resolvedOptions = resolvedOptions()\n }\n const clonedOptions = cloneDeepUnref(resolvedOptions as any)\n\n if (typeof clonedOptions.enabled === 'function') {\n clonedOptions.enabled = clonedOptions.enabled()\n }\n\n const defaulted: DefaultedQueryObserverOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryData,\n TQueryKey\n > = client.defaultQueryOptions(clonedOptions)\n\n defaulted._optimisticResults = client.isRestoring?.value\n ? 'isRestoring'\n : 'optimistic'\n\n return defaulted\n })\n\n const observer = new Observer(client, defaultedOptions.value)\n // @ts-expect-error\n const state = defaultedOptions.value.shallow\n ? shallowReactive(observer.getCurrentResult())\n : reactive(observer.getCurrentResult())\n\n let unsubscribe = () => {\n // noop\n }\n\n if (client.isRestoring) {\n watch(\n client.isRestoring,\n (isRestoring) => {\n if (!isRestoring) {\n unsubscribe()\n unsubscribe = observer.subscribe((result) => {\n updateState(state, result)\n })\n }\n },\n { immediate: true },\n )\n }\n\n const updater = () => {\n observer.setOptions(defaultedOptions.value)\n updateState(state, observer.getCurrentResult())\n }\n\n watch(defaultedOptions, updater)\n\n onScopeDispose(() => {\n unsubscribe()\n })\n\n // fix #5910\n const refetch = (...args: Parameters<(typeof state)['refetch']>) => {\n updater()\n return state.refetch(...args)\n }\n\n const suspense = () => {\n return new Promise<QueryObserverResult<TData, TError>>(\n (resolve, reject) => {\n let stopWatch = () => {\n // noop\n }\n const run = () => {\n if (defaultedOptions.value.enabled !== false) {\n // fix #6133\n observer.setOptions(defaultedOptions.value)\n const optimisticResult = observer.getOptimisticResult(\n defaultedOptions.value,\n )\n if (optimisticResult.isStale) {\n stopWatch()\n observer\n .fetchOptimistic(defaultedOptions.value)\n .then(resolve, (error: TError) => {\n if (\n shouldThrowError(defaultedOptions.value.throwOnError, [\n error,\n observer.getCurrentQuery(),\n ])\n ) {\n reject(error)\n } else {\n resolve(observer.getCurrentResult())\n }\n })\n } else {\n stopWatch()\n resolve(optimisticResult)\n }\n }\n }\n\n run()\n\n stopWatch = watch(defaultedOptions, run)\n },\n )\n }\n\n // Handle error boundary\n watch(\n () => state.error,\n (error) => {\n if (\n state.isError &&\n !state.isFetching &&\n shouldThrowError(defaultedOptions.value.throwOnError, [\n error as TError,\n observer.getCurrentQuery(),\n ])\n ) {\n throw error\n }\n },\n )\n\n // @ts-expect-error\n const readonlyState = defaultedOptions.value.shallow\n ? shallowReadonly(state)\n : readonly(state)\n\n const object: any = toRefs(readonlyState)\n for (const key in state) {\n if (typeof state[key as keyof typeof state] === 'function') {\n object[key] = state[key as keyof typeof state]\n }\n }\n\n object.suspense = suspense\n object.refetch = refetch\n\n return object as UseBaseQueryReturnType<TData, TError>\n}\n"],"mappings":";;;;;;;;;;;;;AAkEA,SAAgB,aAQd,UACA,SAUA,aACuC;CACvC,IAAI,QAAQ,IAAI,aAAa,eACvB;MAAA,CAAC,gBAAgB,GACnB,QAAQ,KACN,kKACF;CAAA;CAIJ,MAAM,SAAS,eAAe,eAAe;CAE7C,MAAM,mBAAmB,eAAe;EACtC,IAAI,kBAAkB;EACtB,IAAI,OAAO,oBAAoB,YAC7B,kBAAkB,gBAAgB;EAEpC,MAAM,gBAAgB,eAAe,eAAsB;EAE3D,IAAI,OAAO,cAAc,YAAY,YACnC,cAAc,UAAU,cAAc,QAAQ;EAGhD,MAAM,YAMF,OAAO,oBAAoB,aAAa;EAE5C,UAAU,qBAAqB,OAAO,aAAa,QAC/C,gBACA;EAEJ,OAAO;CACT,CAAC;CAED,MAAM,WAAW,IAAI,SAAS,QAAQ,iBAAiB,KAAK;CAE5D,MAAM,QAAQ,iBAAiB,MAAM,UACjC,gBAAgB,SAAS,iBAAiB,CAAC,IAC3C,SAAS,SAAS,iBAAiB,CAAC;CAExC,IAAI,oBAAoB,CAExB;CAEA,IAAI,OAAO,aACT,MACE,OAAO,cACN,gBAAgB;EACf,IAAI,CAAC,aAAa;GAChB,YAAY;GACZ,cAAc,SAAS,WAAW,WAAW;IAC3C,YAAY,OAAO,MAAM;GAC3B,CAAC;EACH;CACF,GACA,EAAE,WAAW,KAAK,CACpB;CAGF,MAAM,gBAAgB;EACpB,SAAS,WAAW,iBAAiB,KAAK;EAC1C,YAAY,OAAO,SAAS,iBAAiB,CAAC;CAChD;CAEA,MAAM,kBAAkB,OAAO;CAE/B,qBAAqB;EACnB,YAAY;CACd,CAAC;CAGD,MAAM,WAAW,GAAG,SAAgD;EAClE,QAAQ;EACR,OAAO,MAAM,QAAQ,GAAG,IAAI;CAC9B;CAEA,MAAM,iBAAiB;EACrB,OAAO,IAAI,SACR,SAAS,WAAW;GACnB,IAAI,kBAAkB,CAEtB;GACA,MAAM,YAAY;IAChB,IAAI,iBAAiB,MAAM,YAAY,OAAO;KAE5C,SAAS,WAAW,iBAAiB,KAAK;KAC1C,MAAM,mBAAmB,SAAS,oBAChC,iBAAiB,KACnB;KACA,IAAI,iBAAiB,SAAS;MAC5B,UAAU;MACV,SACG,gBAAgB,iBAAiB,KAAK,CAAC,CACvC,KAAK,UAAU,UAAkB;OAChC,IACE,iBAAiB,iBAAiB,MAAM,cAAc,CACpD,OACA,SAAS,gBAAgB,CAC3B,CAAC,GAED,OAAO,KAAK;YAEZ,QAAQ,SAAS,iBAAiB,CAAC;MAEvC,CAAC;KACL,OAAO;MACL,UAAU;MACV,QAAQ,gBAAgB;KAC1B;IACF;GACF;GAEA,IAAI;GAEJ,YAAY,MAAM,kBAAkB,GAAG;EACzC,CACF;CACF;CAGA,YACQ,MAAM,QACX,UAAU;EACT,IACE,MAAM,WACN,CAAC,MAAM,cACP,iBAAiB,iBAAiB,MAAM,cAAc,CACpD,OACA,SAAS,gBAAgB,CAC3B,CAAC,GAED,MAAM;CAEV,CACF;CAGA,MAAM,gBAAgB,iBAAiB,MAAM,UACzC,gBAAgB,KAAK,IACrB,SAAS,KAAK;CAElB,MAAM,SAAc,OAAO,aAAa;CACxC,KAAK,MAAM,OAAO,OAChB,IAAI,OAAO,MAAM,SAA+B,YAC9C,OAAO,OAAO,MAAM;CAIxB,OAAO,WAAW;CAClB,OAAO,UAAU;CAEjB,OAAO;AACT"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useInfiniteQuery.cjs","names":["useBaseQuery","InfiniteQueryObserver"],"sources":["../../src/useInfiniteQuery.ts"],"sourcesContent":["import { InfiniteQueryObserver } from '@tanstack/query-core'\nimport { useBaseQuery } from './useBaseQuery'\nimport type {\n DefinedInitialDataInfiniteOptions,\n UndefinedInitialDataInfiniteOptions,\n} from './infiniteQueryOptions'\nimport type {\n DefaultError,\n InfiniteData,\n InfiniteQueryObserverOptions,\n InfiniteQueryObserverResult,\n QueryKey,\n QueryObserver,\n} from '@tanstack/query-core'\n\nimport type { UseBaseQueryReturnType } from './useBaseQuery'\n\nimport type {\n DeepUnwrapRef,\n MaybeRef,\n MaybeRefDeep,\n MaybeRefOrGetter,\n ShallowOption,\n} from './types'\nimport type { QueryClient } from './queryClient'\n\nexport type UseInfiniteQueryOptions<\n TQueryFnData = unknown,\n TError = DefaultError,\n TData = TQueryFnData,\n TQueryKey extends QueryKey = QueryKey,\n TPageParam = unknown,\n> = MaybeRef<\n {\n [Property in keyof InfiniteQueryObserverOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryKey,\n TPageParam\n >]: Property extends 'enabled'\n ? MaybeRefOrGetter<\n InfiniteQueryObserverOptions<\n TQueryFnData,\n TError,\n TData,\n DeepUnwrapRef<TQueryKey>,\n TPageParam\n >[Property]\n >\n : MaybeRefDeep<\n InfiniteQueryObserverOptions<\n TQueryFnData,\n TError,\n TData,\n DeepUnwrapRef<TQueryKey>,\n TPageParam\n >[Property]\n >\n } & ShallowOption\n>\n\nexport type UseInfiniteQueryReturnType<TData, TError> = UseBaseQueryReturnType<\n TData,\n TError,\n InfiniteQueryObserverResult<TData, TError>\n>\n\n/**\n * The options for `useInfiniteQuery` are identical to `useQuery`, with the addition of\n * `initialPageParam`, `getNextPageParam`, `getPreviousPageParam`, and `maxPages`.\n *\n * This overload is selected when `initialData` is set, so the resulting `data` is never `undefined`.\n *\n * `enabled` tracks reactive dependencies automatically as a `ref`, a plain value, or a reactive getter\n * (`() => ...`). `queryKey` reacts through a `ref` for the array itself, or `ref`s and reactive getters as\n * individual entries — the array itself can't be a bare getter.\n *\n * @remarks Keep in mind that imperative fetch calls, such as `fetchNextPage`, may interfere with the default\n * refetch behavior, resulting in outdated data. Make sure to call these functions only in response to user\n * actions, or add conditions like `hasNextPage && !isFetching`.\n * @param options - The {@link DefinedInitialDataInfiniteOptions} to use — everything you can pass to\n * `useInfiniteQuery`, with `initialData` set.\n * @param queryClient - Use this to use a custom `QueryClient`. Otherwise, the one provided by `VueQueryPlugin`\n * will be used.\n * @returns The same properties as `useQuery`, with the addition of `fetchNextPage`, `fetchPreviousPage`,\n * `hasNextPage`, `hasPreviousPage`, `isFetchingNextPage`, and `isFetchingPreviousPage`. `data.value.pages` and\n * `data.value.pageParams` are also added, as long as a `select` doesn't change `TData` away from its default\n * `InfiniteData<TQueryFnData>` shape.\n *\n * @example\n * ```vue\n * <script setup lang=\"ts\">\n * import { useInfiniteQuery } from '@tanstack/vue-query'\n *\n * // `data` is never `undefined`, thanks to `initialData` — even if a refetch fails, so the\n * // list stays visible alongside the error.\n * const { data, isError, error } = useInfiniteQuery({\n * queryKey: ['projects'],\n * queryFn: ({ pageParam }) => fetchProjects(pageParam),\n * initialPageParam: 0,\n * getNextPageParam: (lastPage) => lastPage.nextId,\n * initialData: { pages: [], pageParams: [] },\n * })\n * </script>\n *\n * <template>\n * <span v-if=\"isError\">Error: {{ error.message }}</span>\n * <ul>\n * <template v-for=\"page in data.pages\" :key=\"page.nextId\">\n * <li v-for=\"project in page.projects\" :key=\"project.id\">{{ project.name }}</li>\n * </template>\n * </ul>\n * </template>\n * ```\n */\nexport function useInfiniteQuery<\n TQueryFnData,\n TError = DefaultError,\n TData = InfiniteData<TQueryFnData>,\n TQueryKey extends QueryKey = QueryKey,\n TPageParam = unknown,\n>(\n options: MaybeRefOrGetter<\n DefinedInitialDataInfiniteOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryKey,\n TPageParam\n >\n >,\n queryClient?: QueryClient,\n): UseInfiniteQueryReturnType<TData, TError>\n\n/**\n * The options for `useInfiniteQuery` are identical to `useQuery`, with the addition of\n * `initialPageParam`, `getNextPageParam`, `getPreviousPageParam`, and `maxPages`.\n *\n * `enabled` tracks reactive dependencies automatically as a `ref`, a plain value, or a reactive getter\n * (`() => ...`). `queryKey` reacts through a `ref` for the array itself, or `ref`s and reactive getters as\n * individual entries — the array itself can't be a bare getter.\n *\n * @remarks Keep in mind that imperative fetch calls, such as `fetchNextPage`, may interfere with the default\n * refetch behavior, resulting in outdated data. Make sure to call these functions only in response to user\n * actions, or add conditions like `hasNextPage && !isFetching`.\n * @param options - The {@link UndefinedInitialDataInfiniteOptions} to use — everything you can pass to\n * `useInfiniteQuery`.\n * @param queryClient - Use this to use a custom `QueryClient`. Otherwise, the one provided by `VueQueryPlugin`\n * will be used.\n * @returns The same properties as `useQuery`, with the addition of `fetchNextPage`, `fetchPreviousPage`,\n * `hasNextPage`, `hasPreviousPage`, `isFetchingNextPage`, and `isFetchingPreviousPage`. `data.value.pages` and\n * `data.value.pageParams` are also added, as long as a `select` doesn't change `TData` away from its default\n * `InfiniteData<TQueryFnData>` shape.\n *\n * @example\n * Fetching the next page from a \"Load More\" button click:\n * ```vue\n * <script setup lang=\"ts\">\n * import { useInfiniteQuery } from '@tanstack/vue-query'\n *\n * const {\n * data,\n * isPending,\n * isError,\n * error,\n * fetchNextPage,\n * hasNextPage,\n * isFetching,\n * isFetchingNextPage,\n * } = useInfiniteQuery({\n * queryKey: ['projects'],\n * queryFn: ({ pageParam }) => fetchProjects(pageParam),\n * initialPageParam: 0,\n * getNextPageParam: (lastPage) => lastPage.nextId,\n * })\n * </script>\n *\n * <template>\n * <span v-if=\"isPending\">Loading...</span>\n * <span v-else-if=\"isError\">Error: {{ error.message }}</span>\n * <template v-else>\n * <ul>\n * <template v-for=\"page in data.pages\" :key=\"page.nextId\">\n * <li v-for=\"project in page.projects\" :key=\"project.id\">{{ project.name }}</li>\n * </template>\n * </ul>\n * <button @click=\"fetchNextPage()\" :disabled=\"!hasNextPage || isFetching\">\n * {{ isFetchingNextPage ? 'Loading more...' : hasNextPage ? 'Load More' : 'Nothing more to load' }}\n * </button>\n * </template>\n * </template>\n * ```\n *\n * @example\n * Fetching the next page automatically as the user scrolls, using an `IntersectionObserver` on a\n * sentinel element after the list:\n * ```vue\n * <script setup lang=\"ts\">\n * import { onUnmounted, ref, watch } from 'vue'\n * import { useInfiniteQuery } from '@tanstack/vue-query'\n *\n * const {\n * data,\n * isPending,\n * isError,\n * error,\n * fetchNextPage,\n * hasNextPage,\n * isFetching,\n * isFetchingNextPage,\n * } = useInfiniteQuery({\n * queryKey: ['projects'],\n * queryFn: ({ pageParam }) => fetchProjects(pageParam),\n * initialPageParam: 0,\n * getNextPageParam: (lastPage) => lastPage.nextId,\n * })\n *\n * const sentinel = ref<HTMLElement>()\n * let observer: IntersectionObserver | undefined\n *\n * watch(sentinel, (el) => {\n * observer?.disconnect()\n * if (el == null) return\n *\n * observer = new IntersectionObserver(([entry]) => {\n * if (entry?.isIntersecting && hasNextPage.value && !isFetching.value) {\n * fetchNextPage()\n * }\n * })\n * observer.observe(el)\n * })\n *\n * onUnmounted(() => observer?.disconnect())\n * </script>\n *\n * <template>\n * <span v-if=\"isPending\">Loading...</span>\n * <span v-else-if=\"isError\">Error: {{ error.message }}</span>\n * <template v-else>\n * <ul>\n * <template v-for=\"page in data.pages\" :key=\"page.nextId\">\n * <li v-for=\"project in page.projects\" :key=\"project.id\">{{ project.name }}</li>\n * </template>\n * </ul>\n * <div ref=\"sentinel\">{{ isFetchingNextPage ? 'Loading more...' : '' }}</div>\n * </template>\n * </template>\n * ```\n */\nexport function useInfiniteQuery<\n TQueryFnData,\n TError = DefaultError,\n TData = InfiniteData<TQueryFnData>,\n TQueryKey extends QueryKey = QueryKey,\n TPageParam = unknown,\n>(\n options: MaybeRefOrGetter<\n UndefinedInitialDataInfiniteOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryKey,\n TPageParam\n >\n >,\n queryClient?: QueryClient,\n): UseInfiniteQueryReturnType<TData, TError>\n\n/**\n * Fallback overload for options whose `initialData` presence isn't statically known — for example, a\n * `ref`/reactive object built up conditionally, rather than a plain object literal. Prefer one of the other\n * overloads when possible, since they infer whether `data` can be `undefined` from `initialData` directly.\n *\n * `enabled` tracks reactive dependencies automatically as a `ref`, a plain value, or a reactive getter\n * (`() => ...`). `queryKey` reacts through a `ref` for the array itself, or `ref`s and reactive getters as\n * individual entries — the array itself can't be a bare getter.\n *\n * @param options - A `ref`, plain value, or reactive getter resolving to the {@link UseInfiniteQueryOptions} to\n * use.\n * @param queryClient - Use this to use a custom `QueryClient`. Otherwise, the one provided by `VueQueryPlugin`\n * will be used.\n * @returns The same properties as `useQuery`, with the addition of `fetchNextPage`, `fetchPreviousPage`,\n * `hasNextPage`, `hasPreviousPage`, `isFetchingNextPage`, and `isFetchingPreviousPage`.\n *\n * @example\n * Passing a whole-options getter so `maxPages` reacts to a setting stored elsewhere, not just `queryKey`:\n * ```vue\n * <script setup lang=\"ts\">\n * import { useInfiniteQuery } from '@tanstack/vue-query'\n *\n * const props = defineProps<{ projectId: number; maxPages: number }>()\n *\n * const { data } = useInfiniteQuery(() => ({\n * queryKey: ['project', props.projectId, 'issues'],\n * queryFn: ({ pageParam }) => fetchIssues(props.projectId, pageParam),\n * initialPageParam: 0,\n * getNextPageParam: (lastPage) => lastPage.nextId,\n * maxPages: props.maxPages,\n * }))\n * </script>\n *\n * <template>\n * <template v-for=\"page in data?.pages\" :key=\"page.nextId\">\n * <li v-for=\"issue in page.issues\" :key=\"issue.id\">{{ issue.title }}</li>\n * </template>\n * </template>\n * ```\n *\n * @example\n * A query that's disabled, type-safe, until `postId` is set — pass `skipToken` as `queryFn` instead of\n * setting `enabled: false`. This requires a whole-options getter: `queryFn` isn't itself reactive, so the\n * getter is what re-evaluates it on every change to `props.postId`:\n * ```vue\n * <script setup lang=\"ts\">\n * import { skipToken, useInfiniteQuery } from '@tanstack/vue-query'\n *\n * const props = defineProps<{ postId: string | undefined }>()\n *\n * // Use `isLoading`, not `isPending`, so the loading state doesn't show while the query is disabled.\n * const { data, isLoading, isError, error } = useInfiniteQuery(() => {\n * const postId = props.postId\n * return {\n * queryKey: ['post', postId, 'comments'],\n * queryFn:\n * postId != null\n * ? ({ pageParam }) => fetchComments(postId, pageParam)\n * : skipToken,\n * initialPageParam: 0,\n * getNextPageParam: (lastPage) => lastPage.nextId,\n * }\n * })\n * </script>\n *\n * <template>\n * <span v-if=\"props.postId == null\">Select a post</span>\n * <span v-else-if=\"isLoading\">Loading...</span>\n * <span v-else-if=\"isError\">Error: {{ error.message }}</span>\n * <ul v-else>\n * <template v-for=\"page in data.pages\" :key=\"page.nextId\">\n * <li v-for=\"comment in page.comments\" :key=\"comment.id\">{{ comment.text }}</li>\n * </template>\n * </ul>\n * </template>\n * ```\n */\nexport function useInfiniteQuery<\n TQueryFnData,\n TError = DefaultError,\n TData = InfiniteData<TQueryFnData>,\n TQueryKey extends QueryKey = QueryKey,\n TPageParam = unknown,\n>(\n options: MaybeRefOrGetter<\n UseInfiniteQueryOptions<TQueryFnData, TError, TData, TQueryKey, TPageParam>\n >,\n queryClient?: QueryClient,\n): UseInfiniteQueryReturnType<TData, TError>\n\nexport function useInfiniteQuery(\n options: MaybeRefOrGetter<UseInfiniteQueryOptions>,\n queryClient?: QueryClient,\n) {\n return useBaseQuery(\n InfiniteQueryObserver as typeof QueryObserver,\n options,\n queryClient,\n )\n}\n"],"mappings":";;;;AAuWA,SAAgB,iBACd,SACA,aACA;CACA,OAAOA,qBAAAA,aACLC,qBAAAA,uBACA,SACA,WACF;AACF"}
|
|
1
|
+
{"version":3,"file":"useInfiniteQuery.cjs","names":["useBaseQuery","InfiniteQueryObserver"],"sources":["../../src/useInfiniteQuery.ts"],"sourcesContent":["import { InfiniteQueryObserver } from '@tanstack/query-core'\nimport { useBaseQuery } from './useBaseQuery'\nimport type {\n DefinedInitialDataInfiniteOptions,\n UndefinedInitialDataInfiniteOptions,\n} from './infiniteQueryOptions'\nimport type {\n DefaultError,\n InfiniteData,\n InfiniteQueryObserverOptions,\n InfiniteQueryObserverResult,\n QueryKey,\n QueryObserver,\n} from '@tanstack/query-core'\n\nimport type { UseBaseQueryReturnType } from './useBaseQuery'\n\nimport type {\n DeepUnwrapRef,\n MaybeRef,\n MaybeRefDeep,\n MaybeRefOrGetter,\n ShallowOption,\n} from './types'\nimport type { QueryClient } from './queryClient'\n\nexport type UseInfiniteQueryOptions<\n TQueryFnData = unknown,\n TError = DefaultError,\n TData = TQueryFnData,\n TQueryKey extends QueryKey = QueryKey,\n TPageParam = unknown,\n> = MaybeRef<\n {\n [\n Property in keyof InfiniteQueryObserverOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryKey,\n TPageParam\n >\n ]: Property extends 'enabled'\n ? MaybeRefOrGetter<\n InfiniteQueryObserverOptions<\n TQueryFnData,\n TError,\n TData,\n DeepUnwrapRef<TQueryKey>,\n TPageParam\n >[Property]\n >\n : MaybeRefDeep<\n InfiniteQueryObserverOptions<\n TQueryFnData,\n TError,\n TData,\n DeepUnwrapRef<TQueryKey>,\n TPageParam\n >[Property]\n >\n } & ShallowOption\n>\n\nexport type UseInfiniteQueryReturnType<TData, TError> = UseBaseQueryReturnType<\n TData,\n TError,\n InfiniteQueryObserverResult<TData, TError>\n>\n\n/**\n * The options for `useInfiniteQuery` are identical to `useQuery`, with the addition of\n * `initialPageParam`, `getNextPageParam`, `getPreviousPageParam`, and `maxPages`.\n *\n * This overload is selected when `initialData` is set, so the resulting `data` is never `undefined` (unless\n * a `select` changes `TData` to include `undefined`).\n *\n * `enabled` tracks reactive dependencies automatically as a `ref`, a plain value, or a reactive getter\n * (`() => ...`). `queryKey` reacts through a `ref` for the array itself, or `ref`s and reactive getters as\n * individual entries — the array itself can't be a bare getter.\n *\n * @remarks Keep in mind that imperative fetch calls, such as `fetchNextPage`, may interfere with the default\n * refetch behavior, resulting in outdated data. Make sure to call these functions only in response to user\n * actions, or add conditions like `hasNextPage && !isFetching`.\n * @param options - The {@link DefinedInitialDataInfiniteOptions} to use — everything you can pass to\n * `useInfiniteQuery`, with `initialData` set.\n * @param queryClient - Use this to use a custom `QueryClient`. Otherwise, the one provided by `VueQueryPlugin`\n * will be used.\n * @returns The same properties as `useQuery`, with the addition of `fetchNextPage`, `fetchPreviousPage`,\n * `hasNextPage`, `hasPreviousPage`, `isFetchingNextPage`, and `isFetchingPreviousPage`. `data.value.pages` and\n * `data.value.pageParams` are also added, as long as a `select` doesn't change `TData` away from its default\n * `InfiniteData<TQueryFnData>` shape.\n *\n * @example\n * ```vue\n * <script setup lang=\"ts\">\n * import { useInfiniteQuery } from '@tanstack/vue-query'\n *\n * // `data` is never `undefined`, thanks to `initialData` — even if a refetch fails, so the\n * // list stays visible alongside the error.\n * const { data, isError, error } = useInfiniteQuery({\n * queryKey: ['projects'],\n * queryFn: ({ pageParam }) => fetchProjects(pageParam),\n * initialPageParam: 0,\n * getNextPageParam: (lastPage) => lastPage.nextId,\n * initialData: { pages: [], pageParams: [] },\n * })\n * </script>\n *\n * <template>\n * <span v-if=\"isError\">Error: {{ error.message }}</span>\n * <ul>\n * <template v-for=\"page in data.pages\" :key=\"page.nextId\">\n * <li v-for=\"project in page.projects\" :key=\"project.id\">{{ project.name }}</li>\n * </template>\n * </ul>\n * </template>\n * ```\n */\nexport function useInfiniteQuery<\n TQueryFnData,\n TError = DefaultError,\n TData = InfiniteData<TQueryFnData>,\n TQueryKey extends QueryKey = QueryKey,\n TPageParam = unknown,\n>(\n options: MaybeRefOrGetter<\n DefinedInitialDataInfiniteOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryKey,\n TPageParam\n >\n >,\n queryClient?: QueryClient,\n): UseInfiniteQueryReturnType<TData, TError>\n\n/**\n * The options for `useInfiniteQuery` are identical to `useQuery`, with the addition of\n * `initialPageParam`, `getNextPageParam`, `getPreviousPageParam`, and `maxPages`.\n *\n * `enabled` tracks reactive dependencies automatically as a `ref`, a plain value, or a reactive getter\n * (`() => ...`). `queryKey` reacts through a `ref` for the array itself, or `ref`s and reactive getters as\n * individual entries — the array itself can't be a bare getter.\n *\n * @remarks Keep in mind that imperative fetch calls, such as `fetchNextPage`, may interfere with the default\n * refetch behavior, resulting in outdated data. Make sure to call these functions only in response to user\n * actions, or add conditions like `hasNextPage && !isFetching`.\n * @param options - The {@link UndefinedInitialDataInfiniteOptions} to use — everything you can pass to\n * `useInfiniteQuery`.\n * @param queryClient - Use this to use a custom `QueryClient`. Otherwise, the one provided by `VueQueryPlugin`\n * will be used.\n * @returns The same properties as `useQuery`, with the addition of `fetchNextPage`, `fetchPreviousPage`,\n * `hasNextPage`, `hasPreviousPage`, `isFetchingNextPage`, and `isFetchingPreviousPage`. `data.value.pages` and\n * `data.value.pageParams` are also added, as long as a `select` doesn't change `TData` away from its default\n * `InfiniteData<TQueryFnData>` shape.\n *\n * @example\n * Fetching the next page from a \"Load More\" button click:\n * ```vue\n * <script setup lang=\"ts\">\n * import { useInfiniteQuery } from '@tanstack/vue-query'\n *\n * const {\n * data,\n * isPending,\n * isError,\n * error,\n * fetchNextPage,\n * hasNextPage,\n * isFetching,\n * isFetchingNextPage,\n * } = useInfiniteQuery({\n * queryKey: ['projects'],\n * queryFn: ({ pageParam }) => fetchProjects(pageParam),\n * initialPageParam: 0,\n * getNextPageParam: (lastPage) => lastPage.nextId,\n * })\n * </script>\n *\n * <template>\n * <span v-if=\"isPending\">Loading...</span>\n * <span v-else-if=\"isError\">Error: {{ error.message }}</span>\n * <template v-else>\n * <ul>\n * <template v-for=\"page in data.pages\" :key=\"page.nextId\">\n * <li v-for=\"project in page.projects\" :key=\"project.id\">{{ project.name }}</li>\n * </template>\n * </ul>\n * <button @click=\"fetchNextPage()\" :disabled=\"!hasNextPage || isFetching\">\n * {{ isFetchingNextPage ? 'Loading more...' : hasNextPage ? 'Load More' : 'Nothing more to load' }}\n * </button>\n * </template>\n * </template>\n * ```\n *\n * @example\n * Fetching the next page automatically as the user scrolls, using an `IntersectionObserver` on a\n * sentinel element after the list:\n * ```vue\n * <script setup lang=\"ts\">\n * import { onUnmounted, ref, watch } from 'vue'\n * import { useInfiniteQuery } from '@tanstack/vue-query'\n *\n * const {\n * data,\n * isPending,\n * isError,\n * error,\n * fetchNextPage,\n * hasNextPage,\n * isFetching,\n * isFetchingNextPage,\n * } = useInfiniteQuery({\n * queryKey: ['projects'],\n * queryFn: ({ pageParam }) => fetchProjects(pageParam),\n * initialPageParam: 0,\n * getNextPageParam: (lastPage) => lastPage.nextId,\n * })\n *\n * const sentinel = ref<HTMLElement>()\n * let observer: IntersectionObserver | undefined\n *\n * watch(sentinel, (el) => {\n * observer?.disconnect()\n * if (el == null) return\n *\n * observer = new IntersectionObserver(([entry]) => {\n * if (entry?.isIntersecting && hasNextPage.value && !isFetching.value) {\n * fetchNextPage()\n * }\n * })\n * observer.observe(el)\n * })\n *\n * onUnmounted(() => observer?.disconnect())\n * </script>\n *\n * <template>\n * <span v-if=\"isPending\">Loading...</span>\n * <span v-else-if=\"isError\">Error: {{ error.message }}</span>\n * <template v-else>\n * <ul>\n * <template v-for=\"page in data.pages\" :key=\"page.nextId\">\n * <li v-for=\"project in page.projects\" :key=\"project.id\">{{ project.name }}</li>\n * </template>\n * </ul>\n * <div ref=\"sentinel\">{{ isFetchingNextPage ? 'Loading more...' : '' }}</div>\n * </template>\n * </template>\n * ```\n */\nexport function useInfiniteQuery<\n TQueryFnData,\n TError = DefaultError,\n TData = InfiniteData<TQueryFnData>,\n TQueryKey extends QueryKey = QueryKey,\n TPageParam = unknown,\n>(\n options: MaybeRefOrGetter<\n UndefinedInitialDataInfiniteOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryKey,\n TPageParam\n >\n >,\n queryClient?: QueryClient,\n): UseInfiniteQueryReturnType<TData, TError>\n\n/**\n * Fallback overload for options whose `initialData` presence isn't statically known — for example, a\n * `ref`/reactive object built up conditionally, rather than a plain object literal. Prefer one of the other\n * overloads when possible, since they infer whether `data` can be `undefined` from `initialData` directly.\n *\n * `enabled` tracks reactive dependencies automatically as a `ref`, a plain value, or a reactive getter\n * (`() => ...`). `queryKey` reacts through a `ref` for the array itself, or `ref`s and reactive getters as\n * individual entries — the array itself can't be a bare getter.\n *\n * @param options - A `ref`, plain value, or reactive getter resolving to the {@link UseInfiniteQueryOptions} to\n * use.\n * @param queryClient - Use this to use a custom `QueryClient`. Otherwise, the one provided by `VueQueryPlugin`\n * will be used.\n * @returns The same properties as `useQuery`, with the addition of `fetchNextPage`, `fetchPreviousPage`,\n * `hasNextPage`, `hasPreviousPage`, `isFetchingNextPage`, and `isFetchingPreviousPage`.\n *\n * @example\n * Passing a whole-options getter so `maxPages` reacts to a setting stored elsewhere, not just `queryKey`:\n * ```vue\n * <script setup lang=\"ts\">\n * import { useInfiniteQuery } from '@tanstack/vue-query'\n *\n * const props = defineProps<{ projectId: number; maxPages: number }>()\n *\n * const { data } = useInfiniteQuery(() => ({\n * queryKey: ['project', props.projectId, 'issues'],\n * queryFn: ({ pageParam }) => fetchIssues(props.projectId, pageParam),\n * initialPageParam: 0,\n * getNextPageParam: (lastPage) => lastPage.nextId,\n * maxPages: props.maxPages,\n * }))\n * </script>\n *\n * <template>\n * <template v-for=\"page in data?.pages\" :key=\"page.nextId\">\n * <li v-for=\"issue in page.issues\" :key=\"issue.id\">{{ issue.title }}</li>\n * </template>\n * </template>\n * ```\n *\n * @example\n * A query that's disabled, type-safe, until `postId` is set — pass `skipToken` as `queryFn` instead of\n * setting `enabled: false`. This requires a whole-options getter: `queryFn` isn't itself reactive, so the\n * getter is what re-evaluates it on every change to `props.postId`:\n * ```vue\n * <script setup lang=\"ts\">\n * import { skipToken, useInfiniteQuery } from '@tanstack/vue-query'\n *\n * const props = defineProps<{ postId: string | undefined }>()\n *\n * // Use `isLoading`, not `isPending`, so the loading state doesn't show while the query is disabled.\n * const { data, isLoading, isError, error } = useInfiniteQuery(() => {\n * const postId = props.postId\n * return {\n * queryKey: ['post', postId, 'comments'],\n * queryFn:\n * postId != null\n * ? ({ pageParam }) => fetchComments(postId, pageParam)\n * : skipToken,\n * initialPageParam: 0,\n * getNextPageParam: (lastPage) => lastPage.nextId,\n * }\n * })\n * </script>\n *\n * <template>\n * <span v-if=\"props.postId == null\">Select a post</span>\n * <span v-else-if=\"isLoading\">Loading...</span>\n * <span v-else-if=\"isError\">Error: {{ error.message }}</span>\n * <ul v-else>\n * <template v-for=\"page in data.pages\" :key=\"page.nextId\">\n * <li v-for=\"comment in page.comments\" :key=\"comment.id\">{{ comment.text }}</li>\n * </template>\n * </ul>\n * </template>\n * ```\n */\nexport function useInfiniteQuery<\n TQueryFnData,\n TError = DefaultError,\n TData = InfiniteData<TQueryFnData>,\n TQueryKey extends QueryKey = QueryKey,\n TPageParam = unknown,\n>(\n options: MaybeRefOrGetter<\n UseInfiniteQueryOptions<TQueryFnData, TError, TData, TQueryKey, TPageParam>\n >,\n queryClient?: QueryClient,\n): UseInfiniteQueryReturnType<TData, TError>\n\nexport function useInfiniteQuery(\n options: MaybeRefOrGetter<UseInfiniteQueryOptions>,\n queryClient?: QueryClient,\n) {\n return useBaseQuery(\n InfiniteQueryObserver as typeof QueryObserver,\n options,\n queryClient,\n )\n}\n"],"mappings":";;;;AA0WA,SAAgB,iBACd,SACA,aACA;CACA,OAAOA,qBAAAA,aACLC,qBAAAA,uBACA,SACA,WACF;AACF"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { a as UseInfiniteQueryReturnType, i as UseInfiniteQueryOptions, o as useInfiniteQuery } from "./infiniteQueryOptions-
|
|
1
|
+
import { a as UseInfiniteQueryReturnType, i as UseInfiniteQueryOptions, o as useInfiniteQuery } from "./infiniteQueryOptions-CnTRbIP5.cjs";
|
|
2
2
|
export { UseInfiniteQueryOptions, UseInfiniteQueryReturnType, useInfiniteQuery };
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { a as UseInfiniteQueryReturnType, i as UseInfiniteQueryOptions, o as useInfiniteQuery } from "./infiniteQueryOptions-
|
|
1
|
+
import { a as UseInfiniteQueryReturnType, i as UseInfiniteQueryOptions, o as useInfiniteQuery } from "./infiniteQueryOptions-NucMX_M_.js";
|
|
2
2
|
export { UseInfiniteQueryOptions, UseInfiniteQueryReturnType, useInfiniteQuery };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useInfiniteQuery.js","names":[],"sources":["../../src/useInfiniteQuery.ts"],"sourcesContent":["import { InfiniteQueryObserver } from '@tanstack/query-core'\nimport { useBaseQuery } from './useBaseQuery'\nimport type {\n DefinedInitialDataInfiniteOptions,\n UndefinedInitialDataInfiniteOptions,\n} from './infiniteQueryOptions'\nimport type {\n DefaultError,\n InfiniteData,\n InfiniteQueryObserverOptions,\n InfiniteQueryObserverResult,\n QueryKey,\n QueryObserver,\n} from '@tanstack/query-core'\n\nimport type { UseBaseQueryReturnType } from './useBaseQuery'\n\nimport type {\n DeepUnwrapRef,\n MaybeRef,\n MaybeRefDeep,\n MaybeRefOrGetter,\n ShallowOption,\n} from './types'\nimport type { QueryClient } from './queryClient'\n\nexport type UseInfiniteQueryOptions<\n TQueryFnData = unknown,\n TError = DefaultError,\n TData = TQueryFnData,\n TQueryKey extends QueryKey = QueryKey,\n TPageParam = unknown,\n> = MaybeRef<\n {\n [Property in keyof InfiniteQueryObserverOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryKey,\n TPageParam\n >]: Property extends 'enabled'\n ? MaybeRefOrGetter<\n InfiniteQueryObserverOptions<\n TQueryFnData,\n TError,\n TData,\n DeepUnwrapRef<TQueryKey>,\n TPageParam\n >[Property]\n >\n : MaybeRefDeep<\n InfiniteQueryObserverOptions<\n TQueryFnData,\n TError,\n TData,\n DeepUnwrapRef<TQueryKey>,\n TPageParam\n >[Property]\n >\n } & ShallowOption\n>\n\nexport type UseInfiniteQueryReturnType<TData, TError> = UseBaseQueryReturnType<\n TData,\n TError,\n InfiniteQueryObserverResult<TData, TError>\n>\n\n/**\n * The options for `useInfiniteQuery` are identical to `useQuery`, with the addition of\n * `initialPageParam`, `getNextPageParam`, `getPreviousPageParam`, and `maxPages`.\n *\n * This overload is selected when `initialData` is set, so the resulting `data` is never `undefined`.\n *\n * `enabled` tracks reactive dependencies automatically as a `ref`, a plain value, or a reactive getter\n * (`() => ...`). `queryKey` reacts through a `ref` for the array itself, or `ref`s and reactive getters as\n * individual entries — the array itself can't be a bare getter.\n *\n * @remarks Keep in mind that imperative fetch calls, such as `fetchNextPage`, may interfere with the default\n * refetch behavior, resulting in outdated data. Make sure to call these functions only in response to user\n * actions, or add conditions like `hasNextPage && !isFetching`.\n * @param options - The {@link DefinedInitialDataInfiniteOptions} to use — everything you can pass to\n * `useInfiniteQuery`, with `initialData` set.\n * @param queryClient - Use this to use a custom `QueryClient`. Otherwise, the one provided by `VueQueryPlugin`\n * will be used.\n * @returns The same properties as `useQuery`, with the addition of `fetchNextPage`, `fetchPreviousPage`,\n * `hasNextPage`, `hasPreviousPage`, `isFetchingNextPage`, and `isFetchingPreviousPage`. `data.value.pages` and\n * `data.value.pageParams` are also added, as long as a `select` doesn't change `TData` away from its default\n * `InfiniteData<TQueryFnData>` shape.\n *\n * @example\n * ```vue\n * <script setup lang=\"ts\">\n * import { useInfiniteQuery } from '@tanstack/vue-query'\n *\n * // `data` is never `undefined`, thanks to `initialData` — even if a refetch fails, so the\n * // list stays visible alongside the error.\n * const { data, isError, error } = useInfiniteQuery({\n * queryKey: ['projects'],\n * queryFn: ({ pageParam }) => fetchProjects(pageParam),\n * initialPageParam: 0,\n * getNextPageParam: (lastPage) => lastPage.nextId,\n * initialData: { pages: [], pageParams: [] },\n * })\n * </script>\n *\n * <template>\n * <span v-if=\"isError\">Error: {{ error.message }}</span>\n * <ul>\n * <template v-for=\"page in data.pages\" :key=\"page.nextId\">\n * <li v-for=\"project in page.projects\" :key=\"project.id\">{{ project.name }}</li>\n * </template>\n * </ul>\n * </template>\n * ```\n */\nexport function useInfiniteQuery<\n TQueryFnData,\n TError = DefaultError,\n TData = InfiniteData<TQueryFnData>,\n TQueryKey extends QueryKey = QueryKey,\n TPageParam = unknown,\n>(\n options: MaybeRefOrGetter<\n DefinedInitialDataInfiniteOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryKey,\n TPageParam\n >\n >,\n queryClient?: QueryClient,\n): UseInfiniteQueryReturnType<TData, TError>\n\n/**\n * The options for `useInfiniteQuery` are identical to `useQuery`, with the addition of\n * `initialPageParam`, `getNextPageParam`, `getPreviousPageParam`, and `maxPages`.\n *\n * `enabled` tracks reactive dependencies automatically as a `ref`, a plain value, or a reactive getter\n * (`() => ...`). `queryKey` reacts through a `ref` for the array itself, or `ref`s and reactive getters as\n * individual entries — the array itself can't be a bare getter.\n *\n * @remarks Keep in mind that imperative fetch calls, such as `fetchNextPage`, may interfere with the default\n * refetch behavior, resulting in outdated data. Make sure to call these functions only in response to user\n * actions, or add conditions like `hasNextPage && !isFetching`.\n * @param options - The {@link UndefinedInitialDataInfiniteOptions} to use — everything you can pass to\n * `useInfiniteQuery`.\n * @param queryClient - Use this to use a custom `QueryClient`. Otherwise, the one provided by `VueQueryPlugin`\n * will be used.\n * @returns The same properties as `useQuery`, with the addition of `fetchNextPage`, `fetchPreviousPage`,\n * `hasNextPage`, `hasPreviousPage`, `isFetchingNextPage`, and `isFetchingPreviousPage`. `data.value.pages` and\n * `data.value.pageParams` are also added, as long as a `select` doesn't change `TData` away from its default\n * `InfiniteData<TQueryFnData>` shape.\n *\n * @example\n * Fetching the next page from a \"Load More\" button click:\n * ```vue\n * <script setup lang=\"ts\">\n * import { useInfiniteQuery } from '@tanstack/vue-query'\n *\n * const {\n * data,\n * isPending,\n * isError,\n * error,\n * fetchNextPage,\n * hasNextPage,\n * isFetching,\n * isFetchingNextPage,\n * } = useInfiniteQuery({\n * queryKey: ['projects'],\n * queryFn: ({ pageParam }) => fetchProjects(pageParam),\n * initialPageParam: 0,\n * getNextPageParam: (lastPage) => lastPage.nextId,\n * })\n * </script>\n *\n * <template>\n * <span v-if=\"isPending\">Loading...</span>\n * <span v-else-if=\"isError\">Error: {{ error.message }}</span>\n * <template v-else>\n * <ul>\n * <template v-for=\"page in data.pages\" :key=\"page.nextId\">\n * <li v-for=\"project in page.projects\" :key=\"project.id\">{{ project.name }}</li>\n * </template>\n * </ul>\n * <button @click=\"fetchNextPage()\" :disabled=\"!hasNextPage || isFetching\">\n * {{ isFetchingNextPage ? 'Loading more...' : hasNextPage ? 'Load More' : 'Nothing more to load' }}\n * </button>\n * </template>\n * </template>\n * ```\n *\n * @example\n * Fetching the next page automatically as the user scrolls, using an `IntersectionObserver` on a\n * sentinel element after the list:\n * ```vue\n * <script setup lang=\"ts\">\n * import { onUnmounted, ref, watch } from 'vue'\n * import { useInfiniteQuery } from '@tanstack/vue-query'\n *\n * const {\n * data,\n * isPending,\n * isError,\n * error,\n * fetchNextPage,\n * hasNextPage,\n * isFetching,\n * isFetchingNextPage,\n * } = useInfiniteQuery({\n * queryKey: ['projects'],\n * queryFn: ({ pageParam }) => fetchProjects(pageParam),\n * initialPageParam: 0,\n * getNextPageParam: (lastPage) => lastPage.nextId,\n * })\n *\n * const sentinel = ref<HTMLElement>()\n * let observer: IntersectionObserver | undefined\n *\n * watch(sentinel, (el) => {\n * observer?.disconnect()\n * if (el == null) return\n *\n * observer = new IntersectionObserver(([entry]) => {\n * if (entry?.isIntersecting && hasNextPage.value && !isFetching.value) {\n * fetchNextPage()\n * }\n * })\n * observer.observe(el)\n * })\n *\n * onUnmounted(() => observer?.disconnect())\n * </script>\n *\n * <template>\n * <span v-if=\"isPending\">Loading...</span>\n * <span v-else-if=\"isError\">Error: {{ error.message }}</span>\n * <template v-else>\n * <ul>\n * <template v-for=\"page in data.pages\" :key=\"page.nextId\">\n * <li v-for=\"project in page.projects\" :key=\"project.id\">{{ project.name }}</li>\n * </template>\n * </ul>\n * <div ref=\"sentinel\">{{ isFetchingNextPage ? 'Loading more...' : '' }}</div>\n * </template>\n * </template>\n * ```\n */\nexport function useInfiniteQuery<\n TQueryFnData,\n TError = DefaultError,\n TData = InfiniteData<TQueryFnData>,\n TQueryKey extends QueryKey = QueryKey,\n TPageParam = unknown,\n>(\n options: MaybeRefOrGetter<\n UndefinedInitialDataInfiniteOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryKey,\n TPageParam\n >\n >,\n queryClient?: QueryClient,\n): UseInfiniteQueryReturnType<TData, TError>\n\n/**\n * Fallback overload for options whose `initialData` presence isn't statically known — for example, a\n * `ref`/reactive object built up conditionally, rather than a plain object literal. Prefer one of the other\n * overloads when possible, since they infer whether `data` can be `undefined` from `initialData` directly.\n *\n * `enabled` tracks reactive dependencies automatically as a `ref`, a plain value, or a reactive getter\n * (`() => ...`). `queryKey` reacts through a `ref` for the array itself, or `ref`s and reactive getters as\n * individual entries — the array itself can't be a bare getter.\n *\n * @param options - A `ref`, plain value, or reactive getter resolving to the {@link UseInfiniteQueryOptions} to\n * use.\n * @param queryClient - Use this to use a custom `QueryClient`. Otherwise, the one provided by `VueQueryPlugin`\n * will be used.\n * @returns The same properties as `useQuery`, with the addition of `fetchNextPage`, `fetchPreviousPage`,\n * `hasNextPage`, `hasPreviousPage`, `isFetchingNextPage`, and `isFetchingPreviousPage`.\n *\n * @example\n * Passing a whole-options getter so `maxPages` reacts to a setting stored elsewhere, not just `queryKey`:\n * ```vue\n * <script setup lang=\"ts\">\n * import { useInfiniteQuery } from '@tanstack/vue-query'\n *\n * const props = defineProps<{ projectId: number; maxPages: number }>()\n *\n * const { data } = useInfiniteQuery(() => ({\n * queryKey: ['project', props.projectId, 'issues'],\n * queryFn: ({ pageParam }) => fetchIssues(props.projectId, pageParam),\n * initialPageParam: 0,\n * getNextPageParam: (lastPage) => lastPage.nextId,\n * maxPages: props.maxPages,\n * }))\n * </script>\n *\n * <template>\n * <template v-for=\"page in data?.pages\" :key=\"page.nextId\">\n * <li v-for=\"issue in page.issues\" :key=\"issue.id\">{{ issue.title }}</li>\n * </template>\n * </template>\n * ```\n *\n * @example\n * A query that's disabled, type-safe, until `postId` is set — pass `skipToken` as `queryFn` instead of\n * setting `enabled: false`. This requires a whole-options getter: `queryFn` isn't itself reactive, so the\n * getter is what re-evaluates it on every change to `props.postId`:\n * ```vue\n * <script setup lang=\"ts\">\n * import { skipToken, useInfiniteQuery } from '@tanstack/vue-query'\n *\n * const props = defineProps<{ postId: string | undefined }>()\n *\n * // Use `isLoading`, not `isPending`, so the loading state doesn't show while the query is disabled.\n * const { data, isLoading, isError, error } = useInfiniteQuery(() => {\n * const postId = props.postId\n * return {\n * queryKey: ['post', postId, 'comments'],\n * queryFn:\n * postId != null\n * ? ({ pageParam }) => fetchComments(postId, pageParam)\n * : skipToken,\n * initialPageParam: 0,\n * getNextPageParam: (lastPage) => lastPage.nextId,\n * }\n * })\n * </script>\n *\n * <template>\n * <span v-if=\"props.postId == null\">Select a post</span>\n * <span v-else-if=\"isLoading\">Loading...</span>\n * <span v-else-if=\"isError\">Error: {{ error.message }}</span>\n * <ul v-else>\n * <template v-for=\"page in data.pages\" :key=\"page.nextId\">\n * <li v-for=\"comment in page.comments\" :key=\"comment.id\">{{ comment.text }}</li>\n * </template>\n * </ul>\n * </template>\n * ```\n */\nexport function useInfiniteQuery<\n TQueryFnData,\n TError = DefaultError,\n TData = InfiniteData<TQueryFnData>,\n TQueryKey extends QueryKey = QueryKey,\n TPageParam = unknown,\n>(\n options: MaybeRefOrGetter<\n UseInfiniteQueryOptions<TQueryFnData, TError, TData, TQueryKey, TPageParam>\n >,\n queryClient?: QueryClient,\n): UseInfiniteQueryReturnType<TData, TError>\n\nexport function useInfiniteQuery(\n options: MaybeRefOrGetter<UseInfiniteQueryOptions>,\n queryClient?: QueryClient,\n) {\n return useBaseQuery(\n InfiniteQueryObserver as typeof QueryObserver,\n options,\n queryClient,\n )\n}\n"],"mappings":";;;AAuWA,SAAgB,iBACd,SACA,aACA;CACA,OAAO,aACL,uBACA,SACA,WACF;AACF"}
|
|
1
|
+
{"version":3,"file":"useInfiniteQuery.js","names":[],"sources":["../../src/useInfiniteQuery.ts"],"sourcesContent":["import { InfiniteQueryObserver } from '@tanstack/query-core'\nimport { useBaseQuery } from './useBaseQuery'\nimport type {\n DefinedInitialDataInfiniteOptions,\n UndefinedInitialDataInfiniteOptions,\n} from './infiniteQueryOptions'\nimport type {\n DefaultError,\n InfiniteData,\n InfiniteQueryObserverOptions,\n InfiniteQueryObserverResult,\n QueryKey,\n QueryObserver,\n} from '@tanstack/query-core'\n\nimport type { UseBaseQueryReturnType } from './useBaseQuery'\n\nimport type {\n DeepUnwrapRef,\n MaybeRef,\n MaybeRefDeep,\n MaybeRefOrGetter,\n ShallowOption,\n} from './types'\nimport type { QueryClient } from './queryClient'\n\nexport type UseInfiniteQueryOptions<\n TQueryFnData = unknown,\n TError = DefaultError,\n TData = TQueryFnData,\n TQueryKey extends QueryKey = QueryKey,\n TPageParam = unknown,\n> = MaybeRef<\n {\n [\n Property in keyof InfiniteQueryObserverOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryKey,\n TPageParam\n >\n ]: Property extends 'enabled'\n ? MaybeRefOrGetter<\n InfiniteQueryObserverOptions<\n TQueryFnData,\n TError,\n TData,\n DeepUnwrapRef<TQueryKey>,\n TPageParam\n >[Property]\n >\n : MaybeRefDeep<\n InfiniteQueryObserverOptions<\n TQueryFnData,\n TError,\n TData,\n DeepUnwrapRef<TQueryKey>,\n TPageParam\n >[Property]\n >\n } & ShallowOption\n>\n\nexport type UseInfiniteQueryReturnType<TData, TError> = UseBaseQueryReturnType<\n TData,\n TError,\n InfiniteQueryObserverResult<TData, TError>\n>\n\n/**\n * The options for `useInfiniteQuery` are identical to `useQuery`, with the addition of\n * `initialPageParam`, `getNextPageParam`, `getPreviousPageParam`, and `maxPages`.\n *\n * This overload is selected when `initialData` is set, so the resulting `data` is never `undefined` (unless\n * a `select` changes `TData` to include `undefined`).\n *\n * `enabled` tracks reactive dependencies automatically as a `ref`, a plain value, or a reactive getter\n * (`() => ...`). `queryKey` reacts through a `ref` for the array itself, or `ref`s and reactive getters as\n * individual entries — the array itself can't be a bare getter.\n *\n * @remarks Keep in mind that imperative fetch calls, such as `fetchNextPage`, may interfere with the default\n * refetch behavior, resulting in outdated data. Make sure to call these functions only in response to user\n * actions, or add conditions like `hasNextPage && !isFetching`.\n * @param options - The {@link DefinedInitialDataInfiniteOptions} to use — everything you can pass to\n * `useInfiniteQuery`, with `initialData` set.\n * @param queryClient - Use this to use a custom `QueryClient`. Otherwise, the one provided by `VueQueryPlugin`\n * will be used.\n * @returns The same properties as `useQuery`, with the addition of `fetchNextPage`, `fetchPreviousPage`,\n * `hasNextPage`, `hasPreviousPage`, `isFetchingNextPage`, and `isFetchingPreviousPage`. `data.value.pages` and\n * `data.value.pageParams` are also added, as long as a `select` doesn't change `TData` away from its default\n * `InfiniteData<TQueryFnData>` shape.\n *\n * @example\n * ```vue\n * <script setup lang=\"ts\">\n * import { useInfiniteQuery } from '@tanstack/vue-query'\n *\n * // `data` is never `undefined`, thanks to `initialData` — even if a refetch fails, so the\n * // list stays visible alongside the error.\n * const { data, isError, error } = useInfiniteQuery({\n * queryKey: ['projects'],\n * queryFn: ({ pageParam }) => fetchProjects(pageParam),\n * initialPageParam: 0,\n * getNextPageParam: (lastPage) => lastPage.nextId,\n * initialData: { pages: [], pageParams: [] },\n * })\n * </script>\n *\n * <template>\n * <span v-if=\"isError\">Error: {{ error.message }}</span>\n * <ul>\n * <template v-for=\"page in data.pages\" :key=\"page.nextId\">\n * <li v-for=\"project in page.projects\" :key=\"project.id\">{{ project.name }}</li>\n * </template>\n * </ul>\n * </template>\n * ```\n */\nexport function useInfiniteQuery<\n TQueryFnData,\n TError = DefaultError,\n TData = InfiniteData<TQueryFnData>,\n TQueryKey extends QueryKey = QueryKey,\n TPageParam = unknown,\n>(\n options: MaybeRefOrGetter<\n DefinedInitialDataInfiniteOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryKey,\n TPageParam\n >\n >,\n queryClient?: QueryClient,\n): UseInfiniteQueryReturnType<TData, TError>\n\n/**\n * The options for `useInfiniteQuery` are identical to `useQuery`, with the addition of\n * `initialPageParam`, `getNextPageParam`, `getPreviousPageParam`, and `maxPages`.\n *\n * `enabled` tracks reactive dependencies automatically as a `ref`, a plain value, or a reactive getter\n * (`() => ...`). `queryKey` reacts through a `ref` for the array itself, or `ref`s and reactive getters as\n * individual entries — the array itself can't be a bare getter.\n *\n * @remarks Keep in mind that imperative fetch calls, such as `fetchNextPage`, may interfere with the default\n * refetch behavior, resulting in outdated data. Make sure to call these functions only in response to user\n * actions, or add conditions like `hasNextPage && !isFetching`.\n * @param options - The {@link UndefinedInitialDataInfiniteOptions} to use — everything you can pass to\n * `useInfiniteQuery`.\n * @param queryClient - Use this to use a custom `QueryClient`. Otherwise, the one provided by `VueQueryPlugin`\n * will be used.\n * @returns The same properties as `useQuery`, with the addition of `fetchNextPage`, `fetchPreviousPage`,\n * `hasNextPage`, `hasPreviousPage`, `isFetchingNextPage`, and `isFetchingPreviousPage`. `data.value.pages` and\n * `data.value.pageParams` are also added, as long as a `select` doesn't change `TData` away from its default\n * `InfiniteData<TQueryFnData>` shape.\n *\n * @example\n * Fetching the next page from a \"Load More\" button click:\n * ```vue\n * <script setup lang=\"ts\">\n * import { useInfiniteQuery } from '@tanstack/vue-query'\n *\n * const {\n * data,\n * isPending,\n * isError,\n * error,\n * fetchNextPage,\n * hasNextPage,\n * isFetching,\n * isFetchingNextPage,\n * } = useInfiniteQuery({\n * queryKey: ['projects'],\n * queryFn: ({ pageParam }) => fetchProjects(pageParam),\n * initialPageParam: 0,\n * getNextPageParam: (lastPage) => lastPage.nextId,\n * })\n * </script>\n *\n * <template>\n * <span v-if=\"isPending\">Loading...</span>\n * <span v-else-if=\"isError\">Error: {{ error.message }}</span>\n * <template v-else>\n * <ul>\n * <template v-for=\"page in data.pages\" :key=\"page.nextId\">\n * <li v-for=\"project in page.projects\" :key=\"project.id\">{{ project.name }}</li>\n * </template>\n * </ul>\n * <button @click=\"fetchNextPage()\" :disabled=\"!hasNextPage || isFetching\">\n * {{ isFetchingNextPage ? 'Loading more...' : hasNextPage ? 'Load More' : 'Nothing more to load' }}\n * </button>\n * </template>\n * </template>\n * ```\n *\n * @example\n * Fetching the next page automatically as the user scrolls, using an `IntersectionObserver` on a\n * sentinel element after the list:\n * ```vue\n * <script setup lang=\"ts\">\n * import { onUnmounted, ref, watch } from 'vue'\n * import { useInfiniteQuery } from '@tanstack/vue-query'\n *\n * const {\n * data,\n * isPending,\n * isError,\n * error,\n * fetchNextPage,\n * hasNextPage,\n * isFetching,\n * isFetchingNextPage,\n * } = useInfiniteQuery({\n * queryKey: ['projects'],\n * queryFn: ({ pageParam }) => fetchProjects(pageParam),\n * initialPageParam: 0,\n * getNextPageParam: (lastPage) => lastPage.nextId,\n * })\n *\n * const sentinel = ref<HTMLElement>()\n * let observer: IntersectionObserver | undefined\n *\n * watch(sentinel, (el) => {\n * observer?.disconnect()\n * if (el == null) return\n *\n * observer = new IntersectionObserver(([entry]) => {\n * if (entry?.isIntersecting && hasNextPage.value && !isFetching.value) {\n * fetchNextPage()\n * }\n * })\n * observer.observe(el)\n * })\n *\n * onUnmounted(() => observer?.disconnect())\n * </script>\n *\n * <template>\n * <span v-if=\"isPending\">Loading...</span>\n * <span v-else-if=\"isError\">Error: {{ error.message }}</span>\n * <template v-else>\n * <ul>\n * <template v-for=\"page in data.pages\" :key=\"page.nextId\">\n * <li v-for=\"project in page.projects\" :key=\"project.id\">{{ project.name }}</li>\n * </template>\n * </ul>\n * <div ref=\"sentinel\">{{ isFetchingNextPage ? 'Loading more...' : '' }}</div>\n * </template>\n * </template>\n * ```\n */\nexport function useInfiniteQuery<\n TQueryFnData,\n TError = DefaultError,\n TData = InfiniteData<TQueryFnData>,\n TQueryKey extends QueryKey = QueryKey,\n TPageParam = unknown,\n>(\n options: MaybeRefOrGetter<\n UndefinedInitialDataInfiniteOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryKey,\n TPageParam\n >\n >,\n queryClient?: QueryClient,\n): UseInfiniteQueryReturnType<TData, TError>\n\n/**\n * Fallback overload for options whose `initialData` presence isn't statically known — for example, a\n * `ref`/reactive object built up conditionally, rather than a plain object literal. Prefer one of the other\n * overloads when possible, since they infer whether `data` can be `undefined` from `initialData` directly.\n *\n * `enabled` tracks reactive dependencies automatically as a `ref`, a plain value, or a reactive getter\n * (`() => ...`). `queryKey` reacts through a `ref` for the array itself, or `ref`s and reactive getters as\n * individual entries — the array itself can't be a bare getter.\n *\n * @param options - A `ref`, plain value, or reactive getter resolving to the {@link UseInfiniteQueryOptions} to\n * use.\n * @param queryClient - Use this to use a custom `QueryClient`. Otherwise, the one provided by `VueQueryPlugin`\n * will be used.\n * @returns The same properties as `useQuery`, with the addition of `fetchNextPage`, `fetchPreviousPage`,\n * `hasNextPage`, `hasPreviousPage`, `isFetchingNextPage`, and `isFetchingPreviousPage`.\n *\n * @example\n * Passing a whole-options getter so `maxPages` reacts to a setting stored elsewhere, not just `queryKey`:\n * ```vue\n * <script setup lang=\"ts\">\n * import { useInfiniteQuery } from '@tanstack/vue-query'\n *\n * const props = defineProps<{ projectId: number; maxPages: number }>()\n *\n * const { data } = useInfiniteQuery(() => ({\n * queryKey: ['project', props.projectId, 'issues'],\n * queryFn: ({ pageParam }) => fetchIssues(props.projectId, pageParam),\n * initialPageParam: 0,\n * getNextPageParam: (lastPage) => lastPage.nextId,\n * maxPages: props.maxPages,\n * }))\n * </script>\n *\n * <template>\n * <template v-for=\"page in data?.pages\" :key=\"page.nextId\">\n * <li v-for=\"issue in page.issues\" :key=\"issue.id\">{{ issue.title }}</li>\n * </template>\n * </template>\n * ```\n *\n * @example\n * A query that's disabled, type-safe, until `postId` is set — pass `skipToken` as `queryFn` instead of\n * setting `enabled: false`. This requires a whole-options getter: `queryFn` isn't itself reactive, so the\n * getter is what re-evaluates it on every change to `props.postId`:\n * ```vue\n * <script setup lang=\"ts\">\n * import { skipToken, useInfiniteQuery } from '@tanstack/vue-query'\n *\n * const props = defineProps<{ postId: string | undefined }>()\n *\n * // Use `isLoading`, not `isPending`, so the loading state doesn't show while the query is disabled.\n * const { data, isLoading, isError, error } = useInfiniteQuery(() => {\n * const postId = props.postId\n * return {\n * queryKey: ['post', postId, 'comments'],\n * queryFn:\n * postId != null\n * ? ({ pageParam }) => fetchComments(postId, pageParam)\n * : skipToken,\n * initialPageParam: 0,\n * getNextPageParam: (lastPage) => lastPage.nextId,\n * }\n * })\n * </script>\n *\n * <template>\n * <span v-if=\"props.postId == null\">Select a post</span>\n * <span v-else-if=\"isLoading\">Loading...</span>\n * <span v-else-if=\"isError\">Error: {{ error.message }}</span>\n * <ul v-else>\n * <template v-for=\"page in data.pages\" :key=\"page.nextId\">\n * <li v-for=\"comment in page.comments\" :key=\"comment.id\">{{ comment.text }}</li>\n * </template>\n * </ul>\n * </template>\n * ```\n */\nexport function useInfiniteQuery<\n TQueryFnData,\n TError = DefaultError,\n TData = InfiniteData<TQueryFnData>,\n TQueryKey extends QueryKey = QueryKey,\n TPageParam = unknown,\n>(\n options: MaybeRefOrGetter<\n UseInfiniteQueryOptions<TQueryFnData, TError, TData, TQueryKey, TPageParam>\n >,\n queryClient?: QueryClient,\n): UseInfiniteQueryReturnType<TData, TError>\n\nexport function useInfiniteQuery(\n options: MaybeRefOrGetter<UseInfiniteQueryOptions>,\n queryClient?: QueryClient,\n) {\n return useBaseQuery(\n InfiniteQueryObserver as typeof QueryObserver,\n options,\n queryClient,\n )\n}\n"],"mappings":";;;AA0WA,SAAgB,iBACd,SACA,aACA;CACA,OAAO,aACL,uBACA,SACA,WACF;AACF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useIsFetching.cjs","names":["getCurrentScope","useQueryClient","ref","cloneDeepUnref"],"sources":["../../src/useIsFetching.ts"],"sourcesContent":["import { getCurrentScope, onScopeDispose, ref, watchEffect } from 'vue-demi'\nimport { useQueryClient } from './useQueryClient'\nimport { cloneDeepUnref } from './utils'\nimport type { Ref } from 'vue-demi'\nimport type { QueryFilters } from '@tanstack/query-core'\nimport type { MaybeRefDeep } from './types'\nimport type { QueryClient } from './queryClient'\n\nexport type UseIsFetchingFilters =\n
|
|
1
|
+
{"version":3,"file":"useIsFetching.cjs","names":["getCurrentScope","useQueryClient","ref","cloneDeepUnref"],"sources":["../../src/useIsFetching.ts"],"sourcesContent":["import { getCurrentScope, onScopeDispose, ref, watchEffect } from 'vue-demi'\nimport { useQueryClient } from './useQueryClient'\nimport { cloneDeepUnref } from './utils'\nimport type { Ref } from 'vue-demi'\nimport type { QueryFilters } from '@tanstack/query-core'\nimport type { MaybeRefDeep } from './types'\nimport type { QueryClient } from './queryClient'\n\nexport type UseIsFetchingFilters =\n MaybeRefDeep<QueryFilters> | (() => MaybeRefDeep<QueryFilters>)\n\n/**\n * The `useIsFetching` composable returns a `ref` to the `number` of the queries that your application is\n * loading or fetching in the background (useful for app-wide loading indicators).\n *\n * `fetchingFilters` may be a plain object, `MaybeRefDeep`, or a reactive getter (`() => ({ ... })`) — pass a\n * getter if the filters themselves depend on other reactive state.\n *\n * @param fetchingFilters - The {@link QueryFilters} to narrow down the matched queries.\n * @param queryClient - Use this to use a custom `QueryClient`. Otherwise, the one provided by `VueQueryPlugin`\n * will be used.\n * @returns A `ref` to the `number` of the queries that your application is currently loading or fetching in\n * the background.\n *\n * @example\n * ```vue\n * <script setup lang=\"ts\">\n * import { useIsFetching } from '@tanstack/vue-query'\n *\n * // How many queries matching the posts prefix are fetching?\n * const isFetchingPosts = useIsFetching({ queryKey: ['posts'] })\n * </script>\n *\n * <template>\n * <span v-if=\"isFetchingPosts\">Refreshing posts...</span>\n * </template>\n * ```\n *\n * @example\n * A global loading indicator for any query fetching in the background, not just the ones on screen:\n * ```vue\n * <script setup lang=\"ts\">\n * import { useIsFetching } from '@tanstack/vue-query'\n *\n * const isFetching = useIsFetching()\n * </script>\n *\n * <template>\n * <div v-if=\"isFetching\">Queries are fetching in the background...</div>\n * </template>\n * ```\n */\nexport function useIsFetching(\n fetchingFilters: UseIsFetchingFilters = {},\n queryClient?: QueryClient,\n): Ref<number> {\n if (process.env.NODE_ENV === 'development') {\n if (!getCurrentScope()) {\n console.warn(\n 'vue-query composable like \"useQuery()\" should only be used inside a \"setup()\" function or a running effect scope. They might otherwise lead to memory leaks.',\n )\n }\n }\n\n const client = queryClient || useQueryClient()\n\n const isFetching = ref()\n\n const listener = () => {\n const resolvedFilters =\n typeof fetchingFilters === 'function'\n ? fetchingFilters()\n : fetchingFilters\n isFetching.value = client.isFetching(cloneDeepUnref(resolvedFilters))\n }\n\n const unsubscribe = client.getQueryCache().subscribe(listener)\n\n watchEffect(listener)\n\n onScopeDispose(() => {\n unsubscribe()\n })\n\n return isFetching\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAoDA,SAAgB,cACd,kBAAwC,CAAC,GACzC,aACa;CACb,IAAI,QAAQ,IAAI,aAAa,eACvB;MAAA,EAAA,GAACA,SAAAA,gBAAAA,CAAgB,GACnB,QAAQ,KACN,kKACF;CAAA;CAIJ,MAAM,SAAS,eAAeC,uBAAAA,eAAe;CAE7C,MAAM,cAAA,GAAaC,SAAAA,IAAAA,CAAI;CAEvB,MAAM,iBAAiB;EACrB,MAAM,kBACJ,OAAO,oBAAoB,aACvB,gBAAgB,IAChB;EACN,WAAW,QAAQ,OAAO,WAAWC,cAAAA,eAAe,eAAe,CAAC;CACtE;CAEA,MAAM,cAAc,OAAO,cAAc,CAAC,CAAC,UAAU,QAAQ;CAE7D,CAAA,GAAA,SAAA,YAAA,CAAY,QAAQ;CAEpB,CAAA,GAAA,SAAA,eAAA,OAAqB;EACnB,YAAY;CACd,CAAC;CAED,OAAO;AACT"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { o as MaybeRefDeep } from "./types-JpJB72CS.cjs";
|
|
2
|
-
import { t as QueryClient$1 } from "./queryClient-
|
|
2
|
+
import { t as QueryClient$1 } from "./queryClient-Bn2Ql_Lu.cjs";
|
|
3
3
|
import { QueryFilters } from "@tanstack/query-core";
|
|
4
4
|
import { Ref } from "vue-demi";
|
|
5
5
|
//#region src/useIsFetching.d.ts
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useIsFetching.d.cts","names":[],"sources":["../../src/useIsFetching.ts"],"mappings":";;;;;KAQY,
|
|
1
|
+
{"version":3,"file":"useIsFetching.d.cts","names":["QueryClient"],"sources":["../../src/useIsFetching.ts"],"mappings":";;;;;KAQY,uBACV,aAAa,uBAAuB,aAAa;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBA2CnC,cACd,kBAAiB,sBACjB,cAAcA,gBACb"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { o as MaybeRefDeep } from "./types-JpJB72CS.js";
|
|
2
|
-
import { t as QueryClient$1 } from "./queryClient-
|
|
2
|
+
import { t as QueryClient$1 } from "./queryClient-B6mLtXOj.js";
|
|
3
3
|
import { QueryFilters } from "@tanstack/query-core";
|
|
4
4
|
import { Ref } from "vue-demi";
|
|
5
5
|
//#region src/useIsFetching.d.ts
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useIsFetching.d.ts","names":[],"sources":["../../src/useIsFetching.ts"],"mappings":";;;;;KAQY,
|
|
1
|
+
{"version":3,"file":"useIsFetching.d.ts","names":["QueryClient"],"sources":["../../src/useIsFetching.ts"],"mappings":";;;;;KAQY,uBACV,aAAa,uBAAuB,aAAa;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBA2CnC,cACd,kBAAiB,sBACjB,cAAcA,gBACb"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useIsFetching.js","names":[],"sources":["../../src/useIsFetching.ts"],"sourcesContent":["import { getCurrentScope, onScopeDispose, ref, watchEffect } from 'vue-demi'\nimport { useQueryClient } from './useQueryClient'\nimport { cloneDeepUnref } from './utils'\nimport type { Ref } from 'vue-demi'\nimport type { QueryFilters } from '@tanstack/query-core'\nimport type { MaybeRefDeep } from './types'\nimport type { QueryClient } from './queryClient'\n\nexport type UseIsFetchingFilters =\n
|
|
1
|
+
{"version":3,"file":"useIsFetching.js","names":[],"sources":["../../src/useIsFetching.ts"],"sourcesContent":["import { getCurrentScope, onScopeDispose, ref, watchEffect } from 'vue-demi'\nimport { useQueryClient } from './useQueryClient'\nimport { cloneDeepUnref } from './utils'\nimport type { Ref } from 'vue-demi'\nimport type { QueryFilters } from '@tanstack/query-core'\nimport type { MaybeRefDeep } from './types'\nimport type { QueryClient } from './queryClient'\n\nexport type UseIsFetchingFilters =\n MaybeRefDeep<QueryFilters> | (() => MaybeRefDeep<QueryFilters>)\n\n/**\n * The `useIsFetching` composable returns a `ref` to the `number` of the queries that your application is\n * loading or fetching in the background (useful for app-wide loading indicators).\n *\n * `fetchingFilters` may be a plain object, `MaybeRefDeep`, or a reactive getter (`() => ({ ... })`) — pass a\n * getter if the filters themselves depend on other reactive state.\n *\n * @param fetchingFilters - The {@link QueryFilters} to narrow down the matched queries.\n * @param queryClient - Use this to use a custom `QueryClient`. Otherwise, the one provided by `VueQueryPlugin`\n * will be used.\n * @returns A `ref` to the `number` of the queries that your application is currently loading or fetching in\n * the background.\n *\n * @example\n * ```vue\n * <script setup lang=\"ts\">\n * import { useIsFetching } from '@tanstack/vue-query'\n *\n * // How many queries matching the posts prefix are fetching?\n * const isFetchingPosts = useIsFetching({ queryKey: ['posts'] })\n * </script>\n *\n * <template>\n * <span v-if=\"isFetchingPosts\">Refreshing posts...</span>\n * </template>\n * ```\n *\n * @example\n * A global loading indicator for any query fetching in the background, not just the ones on screen:\n * ```vue\n * <script setup lang=\"ts\">\n * import { useIsFetching } from '@tanstack/vue-query'\n *\n * const isFetching = useIsFetching()\n * </script>\n *\n * <template>\n * <div v-if=\"isFetching\">Queries are fetching in the background...</div>\n * </template>\n * ```\n */\nexport function useIsFetching(\n fetchingFilters: UseIsFetchingFilters = {},\n queryClient?: QueryClient,\n): Ref<number> {\n if (process.env.NODE_ENV === 'development') {\n if (!getCurrentScope()) {\n console.warn(\n 'vue-query composable like \"useQuery()\" should only be used inside a \"setup()\" function or a running effect scope. They might otherwise lead to memory leaks.',\n )\n }\n }\n\n const client = queryClient || useQueryClient()\n\n const isFetching = ref()\n\n const listener = () => {\n const resolvedFilters =\n typeof fetchingFilters === 'function'\n ? fetchingFilters()\n : fetchingFilters\n isFetching.value = client.isFetching(cloneDeepUnref(resolvedFilters))\n }\n\n const unsubscribe = client.getQueryCache().subscribe(listener)\n\n watchEffect(listener)\n\n onScopeDispose(() => {\n unsubscribe()\n })\n\n return isFetching\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAoDA,SAAgB,cACd,kBAAwC,CAAC,GACzC,aACa;CACb,IAAI,QAAQ,IAAI,aAAa,eACvB;MAAA,CAAC,gBAAgB,GACnB,QAAQ,KACN,kKACF;CAAA;CAIJ,MAAM,SAAS,eAAe,eAAe;CAE7C,MAAM,aAAa,IAAI;CAEvB,MAAM,iBAAiB;EACrB,MAAM,kBACJ,OAAO,oBAAoB,aACvB,gBAAgB,IAChB;EACN,WAAW,QAAQ,OAAO,WAAW,eAAe,eAAe,CAAC;CACtE;CAEA,MAAM,cAAc,OAAO,cAAc,CAAC,CAAC,UAAU,QAAQ;CAE7D,YAAY,QAAQ;CAEpB,qBAAqB;EACnB,YAAY;CACd,CAAC;CAED,OAAO;AACT"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { c as MutationOptions, o as MaybeRefDeep } from "./types-JpJB72CS.cjs";
|
|
2
|
-
import { t as QueryClient$1 } from "./queryClient-
|
|
2
|
+
import { t as QueryClient$1 } from "./queryClient-Bn2Ql_Lu.cjs";
|
|
3
3
|
import { DefaultError, DistributiveOmit, MutateFunction, MutationObserverResult } from "@tanstack/query-core";
|
|
4
4
|
import { ToRefs } from "vue-demi";
|
|
5
5
|
//#region src/useMutation.d.ts
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useMutation.d.cts","names":[],"sources":["../../src/useMutation.ts"],"mappings":";;;;;KAwBK,eAAe,OAAO,QAAQ,YAAY,mBAC7C,iBACE,uBAAuB,OAAO,QAAQ,YAAY;KAI1C,mBACV,iBACA,SAAS,cACT,mBACA,6BAEE,aAAa,gBAAgB,OAAO,QAAQ,YAAY,2BACjD,aACL,gBAAgB,OAAO,QAAQ,YAAY;KAG5C,mBACH,iBACA,SAAS,cACT,mBACA,iCAEG,SAAS,WACV,eAAe,OAAO,QAAQ,YAAY;KAIlC,sBACV,OACA,QACA,YACA,iBACA,UAAU,eAAe,OAAO,QAAQ,YAAY,oBAClD,OAAO,SAAS;EAClB,QAAQ,mBAAmB,OAAO,QAAQ,YAAY;EACtD,aAAa,eAAe,OAAO,QAAQ,YAAY;EACvD,OAAO,uBACL,OACA,QACA,YACA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAqKY,YACd,iBACA,SAAS,cACT,mBACA,2BAEA,SAAS,mBAAmB,OAAO,QAAQ,YAAY,kBACvD,
|
|
1
|
+
{"version":3,"file":"useMutation.d.cts","names":["QueryClient"],"sources":["../../src/useMutation.ts"],"mappings":";;;;;KAwBK,eAAe,OAAO,QAAQ,YAAY,mBAC7C,iBACE,uBAAuB,OAAO,QAAQ,YAAY;KAI1C,mBACV,iBACA,SAAS,cACT,mBACA,6BAEE,aAAa,gBAAgB,OAAO,QAAQ,YAAY,2BACjD,aACL,gBAAgB,OAAO,QAAQ,YAAY;KAG5C,mBACH,iBACA,SAAS,cACT,mBACA,iCAEG,SAAS,WACV,eAAe,OAAO,QAAQ,YAAY;KAIlC,sBACV,OACA,QACA,YACA,iBACA,UAAU,eAAe,OAAO,QAAQ,YAAY,oBAClD,OAAO,SAAS;EAClB,QAAQ,mBAAmB,OAAO,QAAQ,YAAY;EACtD,aAAa,eAAe,OAAO,QAAQ,YAAY;EACvD,OAAO,uBACL,OACA,QACA,YACA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAqKY,YACd,iBACA,SAAS,cACT,mBACA,2BAEA,SAAS,mBAAmB,OAAO,QAAQ,YAAY,kBACvD,cAAcA,gBACb,sBAAsB,OAAO,QAAQ,YAAY"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { c as MutationOptions, o as MaybeRefDeep } from "./types-JpJB72CS.js";
|
|
2
|
-
import { t as QueryClient$1 } from "./queryClient-
|
|
2
|
+
import { t as QueryClient$1 } from "./queryClient-B6mLtXOj.js";
|
|
3
3
|
import { DefaultError, DistributiveOmit, MutateFunction, MutationObserverResult } from "@tanstack/query-core";
|
|
4
4
|
import { ToRefs } from "vue-demi";
|
|
5
5
|
//#region src/useMutation.d.ts
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useMutation.d.ts","names":[],"sources":["../../src/useMutation.ts"],"mappings":";;;;;KAwBK,eAAe,OAAO,QAAQ,YAAY,mBAC7C,iBACE,uBAAuB,OAAO,QAAQ,YAAY;KAI1C,mBACV,iBACA,SAAS,cACT,mBACA,6BAEE,aAAa,gBAAgB,OAAO,QAAQ,YAAY,2BACjD,aACL,gBAAgB,OAAO,QAAQ,YAAY;KAG5C,mBACH,iBACA,SAAS,cACT,mBACA,iCAEG,SAAS,WACV,eAAe,OAAO,QAAQ,YAAY;KAIlC,sBACV,OACA,QACA,YACA,iBACA,UAAU,eAAe,OAAO,QAAQ,YAAY,oBAClD,OAAO,SAAS;EAClB,QAAQ,mBAAmB,OAAO,QAAQ,YAAY;EACtD,aAAa,eAAe,OAAO,QAAQ,YAAY;EACvD,OAAO,uBACL,OACA,QACA,YACA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAqKY,YACd,iBACA,SAAS,cACT,mBACA,2BAEA,SAAS,mBAAmB,OAAO,QAAQ,YAAY,kBACvD,
|
|
1
|
+
{"version":3,"file":"useMutation.d.ts","names":["QueryClient"],"sources":["../../src/useMutation.ts"],"mappings":";;;;;KAwBK,eAAe,OAAO,QAAQ,YAAY,mBAC7C,iBACE,uBAAuB,OAAO,QAAQ,YAAY;KAI1C,mBACV,iBACA,SAAS,cACT,mBACA,6BAEE,aAAa,gBAAgB,OAAO,QAAQ,YAAY,2BACjD,aACL,gBAAgB,OAAO,QAAQ,YAAY;KAG5C,mBACH,iBACA,SAAS,cACT,mBACA,iCAEG,SAAS,WACV,eAAe,OAAO,QAAQ,YAAY;KAIlC,sBACV,OACA,QACA,YACA,iBACA,UAAU,eAAe,OAAO,QAAQ,YAAY,oBAClD,OAAO,SAAS;EAClB,QAAQ,mBAAmB,OAAO,QAAQ,YAAY;EACtD,aAAa,eAAe,OAAO,QAAQ,YAAY;EACvD,OAAO,uBACL,OACA,QACA,YACA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAqKY,YACd,iBACA,SAAS,cACT,mBACA,2BAEA,SAAS,mBAAmB,OAAO,QAAQ,YAAY,kBACvD,cAAcA,gBACb,sBAAsB,OAAO,QAAQ,YAAY"}
|