@tanstack/vue-query 5.107.1 → 5.107.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -3
- package/build/legacy/devtools/devtools.cjs +1 -1
- package/build/legacy/devtools/devtools.cjs.map +1 -1
- package/build/legacy/devtools/devtools.d.cts +1 -1
- package/build/legacy/devtools/devtools.d.ts +1 -1
- package/build/legacy/devtools/devtools.js +1 -1
- package/build/legacy/devtools/devtools.js.map +1 -1
- package/build/legacy/index.cjs +1 -1
- package/build/legacy/index.d.cts +3 -3
- package/build/legacy/index.d.ts +3 -3
- package/build/legacy/index.js +1 -1
- package/build/legacy/{infiniteQueryOptions-BSwO8rvy.d.cts → infiniteQueryOptions-CLfd_vOE.d.cts} +23 -15
- package/build/legacy/infiniteQueryOptions-CLfd_vOE.d.cts.map +1 -0
- package/build/legacy/{infiniteQueryOptions-Bq8UQFvj.d.ts → infiniteQueryOptions-vEnw-JaW.d.ts} +23 -15
- package/build/legacy/infiniteQueryOptions-vEnw-JaW.d.ts.map +1 -0
- package/build/legacy/infiniteQueryOptions.d.cts +1 -1
- package/build/legacy/infiniteQueryOptions.d.ts +1 -1
- package/build/{modern/queryClient-Bgw9hMbf.d.ts → legacy/queryClient-6AWIHAhP.d.ts} +2 -2
- package/build/legacy/{queryClient-Bgw9hMbf.d.ts.map → queryClient-6AWIHAhP.d.ts.map} +1 -1
- package/build/{modern/queryClient-BSSPWSvX.d.cts → legacy/queryClient-yJW8K_VP.d.cts} +2 -2
- package/build/legacy/{queryClient-BSSPWSvX.d.cts.map → queryClient-yJW8K_VP.d.cts.map} +1 -1
- package/build/legacy/queryClient.cjs +1 -1
- 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 +1 -1
- package/build/legacy/queryClient.js.map +1 -1
- package/build/{modern/queryOptions-B-eHjgaY.d.cts → legacy/queryOptions-nndmAASX.d.cts} +17 -14
- package/build/legacy/queryOptions-nndmAASX.d.cts.map +1 -0
- package/build/{modern/queryOptions-D1-foH1W.d.ts → legacy/queryOptions-v0l6M7Eo.d.ts} +17 -14
- package/build/legacy/queryOptions-v0l6M7Eo.d.ts.map +1 -0
- package/build/legacy/queryOptions.cjs.map +1 -1
- package/build/legacy/queryOptions.d.cts +1 -1
- package/build/legacy/queryOptions.d.ts +1 -1
- package/build/legacy/queryOptions.js.map +1 -1
- package/build/legacy/types-u_Tu5Ybs.d.cts.map +1 -1
- package/build/legacy/types-u_Tu5Ybs.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.ts +1 -1
- package/build/legacy/useIsFetching.js.map +1 -1
- package/build/legacy/useMutation.cjs.map +1 -1
- package/build/legacy/useMutation.d.cts +1 -1
- package/build/legacy/useMutation.d.ts +1 -1
- package/build/legacy/useMutation.js.map +1 -1
- package/build/legacy/useMutationState.cjs.map +1 -1
- package/build/legacy/useMutationState.d.cts +1 -1
- package/build/legacy/useMutationState.d.ts +1 -1
- package/build/legacy/useMutationState.js.map +1 -1
- package/build/legacy/usePrefetchInfiniteQuery.cjs.map +1 -1
- package/build/legacy/usePrefetchInfiniteQuery.d.cts +1 -1
- package/build/legacy/usePrefetchInfiniteQuery.d.ts +1 -1
- package/build/legacy/usePrefetchInfiniteQuery.js.map +1 -1
- package/build/legacy/usePrefetchQuery.cjs.map +1 -1
- package/build/legacy/usePrefetchQuery.d.cts +1 -1
- package/build/legacy/usePrefetchQuery.d.ts +1 -1
- package/build/legacy/usePrefetchQuery.js.map +1 -1
- package/build/legacy/useQueries.cjs.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/useQueries.js.map +1 -1
- package/build/legacy/useQuery.cjs.map +1 -1
- package/build/legacy/useQuery.d.cts +37 -24
- package/build/legacy/useQuery.d.cts.map +1 -1
- package/build/legacy/useQuery.d.ts +37 -24
- package/build/legacy/useQuery.d.ts.map +1 -1
- package/build/legacy/useQuery.js.map +1 -1
- package/build/legacy/useQueryClient.cjs.map +1 -1
- package/build/legacy/useQueryClient.d.cts +1 -1
- package/build/legacy/useQueryClient.d.cts.map +1 -1
- package/build/legacy/useQueryClient.d.ts +1 -1
- package/build/legacy/useQueryClient.d.ts.map +1 -1
- package/build/legacy/useQueryClient.js.map +1 -1
- package/build/legacy/utils.cjs.map +1 -1
- package/build/legacy/utils.js.map +1 -1
- package/build/legacy/vueQueryPlugin.cjs +1 -1
- package/build/legacy/vueQueryPlugin.cjs.map +1 -1
- package/build/legacy/vueQueryPlugin.d.cts +1 -1
- package/build/legacy/vueQueryPlugin.d.cts.map +1 -1
- package/build/legacy/vueQueryPlugin.d.ts +1 -1
- package/build/legacy/vueQueryPlugin.d.ts.map +1 -1
- package/build/legacy/vueQueryPlugin.js +1 -1
- package/build/legacy/vueQueryPlugin.js.map +1 -1
- package/build/modern/devtools/devtools.cjs +1 -1
- package/build/modern/devtools/devtools.cjs.map +1 -1
- package/build/modern/devtools/devtools.d.cts +1 -1
- package/build/modern/devtools/devtools.d.ts +1 -1
- package/build/modern/devtools/devtools.js +1 -1
- package/build/modern/devtools/devtools.js.map +1 -1
- package/build/modern/index.cjs +1 -1
- package/build/modern/index.d.cts +3 -3
- package/build/modern/index.d.ts +3 -3
- package/build/modern/index.js +1 -1
- package/build/modern/{infiniteQueryOptions-BSwO8rvy.d.cts → infiniteQueryOptions-CLfd_vOE.d.cts} +23 -15
- package/build/modern/infiniteQueryOptions-CLfd_vOE.d.cts.map +1 -0
- package/build/modern/{infiniteQueryOptions-Bq8UQFvj.d.ts → infiniteQueryOptions-vEnw-JaW.d.ts} +23 -15
- package/build/modern/infiniteQueryOptions-vEnw-JaW.d.ts.map +1 -0
- package/build/modern/infiniteQueryOptions.d.cts +1 -1
- package/build/modern/infiniteQueryOptions.d.ts +1 -1
- package/build/{legacy/queryClient-Bgw9hMbf.d.ts → modern/queryClient-6AWIHAhP.d.ts} +2 -2
- package/build/modern/{queryClient-Bgw9hMbf.d.ts.map → queryClient-6AWIHAhP.d.ts.map} +1 -1
- package/build/{legacy/queryClient-BSSPWSvX.d.cts → modern/queryClient-yJW8K_VP.d.cts} +2 -2
- package/build/modern/{queryClient-BSSPWSvX.d.cts.map → queryClient-yJW8K_VP.d.cts.map} +1 -1
- package/build/modern/queryClient.cjs +1 -1
- 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 +1 -1
- package/build/modern/queryClient.js.map +1 -1
- package/build/{legacy/queryOptions-B-eHjgaY.d.cts → modern/queryOptions-nndmAASX.d.cts} +17 -14
- package/build/modern/queryOptions-nndmAASX.d.cts.map +1 -0
- package/build/{legacy/queryOptions-D1-foH1W.d.ts → modern/queryOptions-v0l6M7Eo.d.ts} +17 -14
- package/build/modern/queryOptions-v0l6M7Eo.d.ts.map +1 -0
- package/build/modern/queryOptions.cjs.map +1 -1
- package/build/modern/queryOptions.d.cts +1 -1
- package/build/modern/queryOptions.d.ts +1 -1
- package/build/modern/queryOptions.js.map +1 -1
- package/build/modern/types-u_Tu5Ybs.d.cts.map +1 -1
- package/build/modern/types-u_Tu5Ybs.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.ts +1 -1
- package/build/modern/useIsFetching.js.map +1 -1
- package/build/modern/useMutation.cjs.map +1 -1
- package/build/modern/useMutation.d.cts +1 -1
- package/build/modern/useMutation.d.ts +1 -1
- package/build/modern/useMutation.js.map +1 -1
- package/build/modern/useMutationState.cjs.map +1 -1
- package/build/modern/useMutationState.d.cts +1 -1
- package/build/modern/useMutationState.d.ts +1 -1
- package/build/modern/useMutationState.js.map +1 -1
- package/build/modern/usePrefetchInfiniteQuery.cjs.map +1 -1
- package/build/modern/usePrefetchInfiniteQuery.d.cts +1 -1
- package/build/modern/usePrefetchInfiniteQuery.d.ts +1 -1
- package/build/modern/usePrefetchInfiniteQuery.js.map +1 -1
- package/build/modern/usePrefetchQuery.cjs.map +1 -1
- package/build/modern/usePrefetchQuery.d.cts +1 -1
- package/build/modern/usePrefetchQuery.d.ts +1 -1
- package/build/modern/usePrefetchQuery.js.map +1 -1
- package/build/modern/useQueries.cjs.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/useQueries.js.map +1 -1
- package/build/modern/useQuery.cjs.map +1 -1
- package/build/modern/useQuery.d.cts +37 -24
- package/build/modern/useQuery.d.cts.map +1 -1
- package/build/modern/useQuery.d.ts +37 -24
- package/build/modern/useQuery.d.ts.map +1 -1
- package/build/modern/useQuery.js.map +1 -1
- package/build/modern/useQueryClient.cjs.map +1 -1
- package/build/modern/useQueryClient.d.cts +1 -1
- package/build/modern/useQueryClient.d.cts.map +1 -1
- package/build/modern/useQueryClient.d.ts +1 -1
- package/build/modern/useQueryClient.d.ts.map +1 -1
- package/build/modern/useQueryClient.js.map +1 -1
- package/build/modern/utils.cjs.map +1 -1
- package/build/modern/utils.js.map +1 -1
- package/build/modern/vueQueryPlugin.cjs +1 -1
- package/build/modern/vueQueryPlugin.cjs.map +1 -1
- package/build/modern/vueQueryPlugin.d.cts +1 -1
- package/build/modern/vueQueryPlugin.d.cts.map +1 -1
- package/build/modern/vueQueryPlugin.d.ts +1 -1
- package/build/modern/vueQueryPlugin.d.ts.map +1 -1
- package/build/modern/vueQueryPlugin.js +1 -1
- package/build/modern/vueQueryPlugin.js.map +1 -1
- package/package.json +12 -2
- package/src/devtools/devtools.ts +2 -2
- package/src/index.ts +1 -0
- package/src/queryClient.ts +12 -12
- package/src/queryOptions.ts +23 -20
- package/src/types.ts +2 -0
- package/src/useBaseQuery.ts +3 -3
- package/src/useInfiniteQuery.ts +27 -21
- package/src/useIsFetching.ts +2 -2
- package/src/useMutation.ts +4 -4
- package/src/useMutationState.ts +2 -2
- package/src/usePrefetchInfiniteQuery.ts +1 -1
- package/src/usePrefetchQuery.ts +1 -1
- package/src/useQueries.ts +2 -3
- package/src/useQuery.ts +36 -23
- package/src/useQueryClient.ts +0 -1
- package/src/utils.ts +2 -2
- package/src/vueQueryPlugin.ts +2 -3
- package/build/legacy/infiniteQueryOptions-BSwO8rvy.d.cts.map +0 -1
- package/build/legacy/infiniteQueryOptions-Bq8UQFvj.d.ts.map +0 -1
- package/build/legacy/queryOptions-B-eHjgaY.d.cts.map +0 -1
- package/build/legacy/queryOptions-D1-foH1W.d.ts.map +0 -1
- package/build/modern/infiniteQueryOptions-BSwO8rvy.d.cts.map +0 -1
- package/build/modern/infiniteQueryOptions-Bq8UQFvj.d.ts.map +0 -1
- package/build/modern/queryOptions-B-eHjgaY.d.cts.map +0 -1
- package/build/modern/queryOptions-D1-foH1W.d.ts.map +0 -1
|
@@ -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 * `enabled` for Vue Query. A `ref`, `computed`, or plain boolean is reactive. A zero-argument getter\n * (`() => ...`) is too: it is called while tracking dependencies. query-core's `(query) => boolean` is\n * kept as that callback and is not tracked by Vue — a `ref` read inside it is current when core calls it,\n * and a `ref` change does not by itself call it again.\n */\nexport type VueQueryEnabledOption<\n TQueryFnData,\n TError,\n TQueryData,\n TQueryKey extends QueryKey,\n> =\n | MaybeRefOrGetter<boolean | undefined>\n | QueryBooleanOption<TQueryFnData, TError, TQueryData, TQueryKey>\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 * @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 ? VueQueryEnabledOption<\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 as a `ref`, a plain boolean, or a zero-argument getter (`() => ...`). query-core's\n * `(query) => boolean` callback is accepted too and is passed through untracked. `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 * @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>\n | (() => NonUndefinedGuard<TQueryFnData>)\n}\n\n/**\n * The options accepted by the `queryOptions` overload selected when `initialData` is omitted, may be\n * `undefined`, or is a function that may return `undefined` — `data` may be `undefined` while the query is\n * `pending`.\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 known to be defined —\n * `data` is never `undefined` (unless a `select` changes `TData` to include `undefined`).\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\n/**\n * The options returned by the `queryOptions` overload selected when `initialData` is omitted, may be\n * `undefined`, or is a function that may return `undefined`, with the `queryKey` tagged with the query's data\n * and error types.\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\n/**\n * The options returned by the `queryOptions` overload selected when `initialData` is known to be defined,\n * with the `queryKey` tagged with the query's data and error types.\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 known to be defined, so the resulting `data` is never\n * `undefined` (unless a `select` changes `TData` to include `undefined`).\n * @param options - The {@link DefinedInitialQueryOptions} to use — everything you can pass to `useQuery`,\n * with `initialData` known to be defined.\n * @returns The same options object, typed so that `queryKey` carries the inferred data type.\n * @see {@link useQuery} to run a query with these options.\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 * @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 * @see {@link useQuery} to run a query with these options.\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 * @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 * @see {@link useQuery} to run a query with these options.\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 * @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 * @see {@link useQuery} to run a query with these options.\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 * @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":";AA0aA,SAAgB,aAAa,SAAkB;CAC7C,OAAO;AACT"}
|
|
1
|
+
{"version":3,"file":"queryOptions.js","names":[],"sources":["../../src/queryOptions.ts"],"sourcesContent":["import type {\n DefaultError,\n InitialDataFunction,\n NonUndefinedGuard,\n QueryBooleanOption,\n QueryKey,\n QueryKeyWithDataTag,\n QueryObserverOptions,\n} from '@tanstack/query-core'\nimport type {\n DeepUnwrapRef,\n MaybeRef,\n MaybeRefDeep,\n MaybeRefOrGetter,\n ShallowOption,\n} from './types'\n\n/**\n * `enabled` for Vue Query. A `ref` or `computed` is reactive, while a plain boolean isn't tracked on its own. A\n * zero-argument getter (`() => ...`) is reactive too: it is called while tracking dependencies. query-core's\n * `(query) => boolean` is kept as that callback and is not tracked by Vue — a `ref` read inside it is current\n * when core calls it, and a `ref` change does not by itself call it again. The two are told apart by the number\n * of declared parameters, so declare `query` as a required parameter.\n */\nexport type VueQueryEnabledOption<\n TQueryFnData,\n TError,\n TQueryData,\n TQueryKey extends QueryKey,\n> =\n | MaybeRefOrGetter<boolean | undefined>\n | QueryBooleanOption<TQueryFnData, TError, TQueryData, TQueryKey>\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 * @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. Defaults to `TQueryFnData` when no\n * `select` is used.\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 ? VueQueryEnabledOption<\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` accepts a `ref`, a\n * plain boolean, or a zero-argument getter (`() => ...`): a `ref` or a getter is tracked, while a plain boolean\n * isn't tracked on its own. query-core's `(query) => boolean` callback is accepted too and is passed through\n * untracked. `queryKey` reacts through a `ref` or a reactive getter for the array itself, or `ref`s and reactive\n * getters as individual entries. Other options are read once when passed as a plain value, and stay reactive\n * when passed as a `ref` or a `computed`. Only `enabled` and `queryKey` read a function as a getter, so\n * `queryFn` reacts through a `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 * @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. Defaults to `TQueryFnData` when no\n * `select` is used.\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>\n | (() => NonUndefinedGuard<TQueryFnData>)\n}\n\n/**\n * The options accepted by the `queryOptions` overload selected when `initialData` is omitted, may be\n * `undefined`, or is a function that may return `undefined` — `data` may be `undefined` while the query is\n * `pending`.\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 known to be defined —\n * `data` is never `undefined` (unless a `select` changes `TData` to include `undefined`).\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\n/**\n * The options returned by the `queryOptions` overload selected when `initialData` is omitted, may be\n * `undefined`, or is a function that may return `undefined`, with the `queryKey` tagged with the query's data\n * and error types.\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\n/**\n * The options returned by the `queryOptions` overload selected when `initialData` is known to be defined,\n * with the `queryKey` tagged with the query's data and error types.\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 known to be defined, so the resulting `data` is never\n * `undefined` (unless a `select` changes `TData` to include `undefined`).\n * @param options - The {@link DefinedInitialQueryOptions} to use — everything you can pass to `useQuery`,\n * with `initialData` known to be defined.\n * @returns The same options object, typed so that `queryKey` carries the inferred data type.\n * @see {@link useQuery} to run a query with these options.\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 * @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 * @see {@link useQuery} to run a query with these options.\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 * @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 * @see {@link useQuery} to run a query with these options.\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 * @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 * @see {@link useQuery} to run a query with these options.\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 * @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":";AA6aA,SAAgB,aAAa,SAAkB;CAC7C,OAAO;AACT"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types-u_Tu5Ybs.d.cts","names":["DefaultOptions"],"sources":["../../src/types.ts"],"mappings":";;KAYK;KACA,aACD,
|
|
1
|
+
{"version":3,"file":"types-u_Tu5Ybs.d.cts","names":["DefaultOptions"],"sources":["../../src/types.ts"],"mappings":";;KAYK;KACA,aACD,YAEA,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,SAE5B,UAAU,WACN,IACA,sBAEK,kBAAkB,IAAI,aAAa,EAAE,gBAExC;;;;;KAOI,UAAU,KAAK,eAAe,0BAA0B;;;;;KAMxD,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;;;;KAKN;;;;EAIV;;;;;;KAOU,gBACV,iBACA,SAAS,cACT,mBACA,6BACE,UACF,wBAAwB,OAAO,QAAQ,YAAY,kCAGnD;;;;;;UAOeA,iBAAe,SAAS;;;;;EAKvC,UAAU,UAAU,8BAA8B,uBAChD;;;;;EAKF,YAAY,iCAAiC,4BAC3C;;;;EAIF,UAAU;;;;EAIV,YAAY;;;;;;UAOG;;;;EAIf,aAAa;;;;EAIb,gBAAgB;;;;EAIhB,iBAAiBA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types-u_Tu5Ybs.d.ts","names":["DefaultOptions"],"sources":["../../src/types.ts"],"mappings":";;KAYK;KACA,aACD,
|
|
1
|
+
{"version":3,"file":"types-u_Tu5Ybs.d.ts","names":["DefaultOptions"],"sources":["../../src/types.ts"],"mappings":";;KAYK;KACA,aACD,YAEA,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,SAE5B,UAAU,WACN,IACA,sBAEK,kBAAkB,IAAI,aAAa,EAAE,gBAExC;;;;;KAOI,UAAU,KAAK,eAAe,0BAA0B;;;;;KAMxD,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;;;;KAKN;;;;EAIV;;;;;;KAOU,gBACV,iBACA,SAAS,cACT,mBACA,6BACE,UACF,wBAAwB,OAAO,QAAQ,YAAY,kCAGnD;;;;;;UAOeA,iBAAe,SAAS;;;;;EAKvC,UAAU,UAAU,8BAA8B,uBAChD;;;;;EAKF,YAAY,iCAAiC,4BAC3C;;;;EAIF,UAAU;;;;EAIV,YAAY;;;;;;UAOG;;;;EAIf,aAAa;;;;EAIb,gBAAgB;;;;EAIhB,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\n/**\n * Readonly view of a union that stays a union. A single `Readonly<Union>` collapses the members, which\n * drops the `status` / `isSuccess` / `isPending` discriminants.\n */\ntype ReadonlyQueryState<T> = T extends any\n ? { readonly [K in keyof T]: T[K] }\n : never\n\n/**\n * The result of the query composables: every property of the observer result wrapped in a `Ref`, except\n * the `refetch`, `fetchNextPage`, and `fetchPreviousPage` functions, plus `suspense` and `state`.\n */\nexport type UseBaseQueryReturnType<\n TData,\n TError,\n TResult = QueryObserverResult<TData, TError>,\n> = {\n [K in keyof TResult]: K extends\n | 'fetchNextPage'\n | 'fetchPreviousPage'\n | '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 * The query result as one readonly reactive object. `data`, `error`, `status`, `isPending`, and the other\n * fields are plain values — read `state.data`, not `state.data.value`.\n *\n * The object is a discriminated union, so a check on `status`, `isSuccess`, `isPending`, or `isError`\n * narrows the other fields. When `status` is `'success'` (or `isSuccess` is `true`), `data` is `TData`.\n * When `status` is `'pending'` (or `isPending` is `true`), `data` is `undefined` and `error` is `null`.\n * @example\n * ```vue\n * <script setup lang=\"ts\">\n * import { useQuery } from '@tanstack/vue-query'\n *\n * const { state } = useQuery({\n * queryKey: ['post'],\n * queryFn: fetchPost,\n * })\n *\n * if (state.status === 'success') {\n * // `state.data` is `Post`, not `Post | undefined`\n * console.log(state.data.title)\n * }\n * </script>\n *\n * <template>\n * <span v-if=\"state.status === 'pending'\">Loading...</span>\n * <span v-else-if=\"state.status === 'error'\">Error: {{ state.error.message }}</span>\n * <h1 v-else>{{ state.data.title }}</h1>\n * </template>\n * ```\n */\n state: ReadonlyQueryState<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 * @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 * @returns The query result as `ref`s, plus the `suspense` function.\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 // A zero-arg function is a Vue getter and must run here so its refs are tracked.\n // `(query) => boolean` is query-core's callback and is left for core to call.\n if (\n typeof clonedOptions.enabled === 'function' &&\n clonedOptions.enabled.length === 0\n ) {\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 // Replaced below with the wrapper. Declared here so the subscriber can put it\n // back after `updateState` copies the observer's own `refetch` onto `state`.\n let refetch: (typeof state)['refetch'] = (...args) =>\n observer.refetch(...args)\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 state.refetch = refetch\n })\n }\n },\n { immediate: true },\n )\n }\n\n const updater = () => {\n observer.setOptions(defaultedOptions.value)\n updateState(state, observer.getCurrentResult())\n state.refetch = refetch\n }\n\n watch(defaultedOptions, updater)\n\n onScopeDispose(() => {\n unsubscribe()\n })\n\n // fix #5910. Call `observer.refetch`: `state.refetch` is this wrapper, so\n // calling it would recurse.\n refetch = (...args) => {\n updater()\n return observer.refetch(...args)\n }\n state.refetch = refetch\n\n const suspense = () => {\n return new Promise<QueryObserverResult<TData, TError>>(\n (resolve, reject) => {\n let stopWatch = () => {\n // noop\n }\n const run = () => {\n // Apply the latest options before resolving `enabled`, so a query callback sees the current query.\n // fix #6133\n observer.setOptions(defaultedOptions.value)\n const { enabled } = defaultedOptions.value\n if (\n (typeof enabled === 'function'\n ? enabled(observer.getCurrentQuery())\n : enabled) !== false\n ) {\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 object.state = readonlyState\n\n return object as UseBaseQueryReturnType<TData, TError>\n}\n"],"mappings":"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"}
|
|
1
|
+
{"version":3,"file":"useBaseQuery.cjs","names":["getCurrentScope","useQueryClient","computed","cloneDeepUnref","shallowReactive","reactive","shouldThrowError","watch","shallowReadonly","readonly","toRefs"],"sources":["../../src/useBaseQuery.ts"],"sourcesContent":["import { shouldThrowError } from '@tanstack/query-core'\nimport {\n computed,\n getCurrentScope,\n onScopeDispose,\n reactive,\n readonly,\n shallowReactive,\n shallowReadonly,\n toRefs,\n watch,\n} from 'vue-demi'\nimport { useQueryClient } from './useQueryClient'\nimport { cloneDeepUnref, updateState } from './utils'\nimport type {\n DefaultedQueryObserverOptions,\n QueryKey,\n QueryObserver,\n QueryObserverResult,\n} from '@tanstack/query-core'\nimport type { Ref } from 'vue-demi'\nimport type { QueryClient } from './queryClient'\nimport type { UseQueryOptions } from './queryOptions'\nimport type { MaybeRefOrGetter } from './types'\nimport type { UseInfiniteQueryOptions } from './useInfiniteQuery'\n\n/**\n * Readonly view of a union that stays a union. A single `Readonly<Union>` collapses the members, which\n * drops the `status` / `isSuccess` / `isPending` discriminants.\n */\ntype ReadonlyQueryState<T> = T extends any\n ? { readonly [K in keyof T]: T[K] }\n : never\n\n/**\n * The result of the query composables: every property of the observer result wrapped in a `Ref`, except\n * the `refetch`, `fetchNextPage`, and `fetchPreviousPage` functions, plus `suspense` and `state`.\n */\nexport type UseBaseQueryReturnType<\n TData,\n TError,\n TResult = QueryObserverResult<TData, TError>,\n> = {\n [K in keyof TResult]: K extends\n | 'fetchNextPage'\n | 'fetchPreviousPage'\n | '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 * The query result as one readonly reactive object. `data`, `error`, `status`, `isPending`, and the other\n * fields are plain values — read `state.data`, not `state.data.value`.\n *\n * The object is a discriminated union, so a check on `status`, `isSuccess`, `isPending`, or `isError`\n * narrows the other fields. When `status` is `'success'` (or `isSuccess` is `true`), `data` is `TData`.\n * When `status` is `'pending'` (or `isPending` is `true`), `data` is `undefined` and `error` is `null`.\n * @example\n * ```vue\n * <script setup lang=\"ts\">\n * import { useQuery } from '@tanstack/vue-query'\n *\n * const { state } = useQuery({\n * queryKey: ['post'],\n * queryFn: fetchPost,\n * })\n *\n * if (state.status === 'success') {\n * // `state.data` is `Post`, not `Post | undefined`\n * console.log(state.data.title)\n * }\n * </script>\n *\n * <template>\n * <span v-if=\"state.status === 'pending'\">Loading...</span>\n * <span v-else-if=\"state.status === 'error'\">Error: {{ state.error.message }}</span>\n * <h1 v-else>{{ state.data.title }}</h1>\n * </template>\n * ```\n */\n state: ReadonlyQueryState<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 * @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 * @returns The query result as `ref`s, plus the `suspense` function.\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 // A zero-arg function is a Vue getter and must run here so its refs are tracked.\n // `(query) => boolean` is query-core's callback and is left for core to call.\n if (\n typeof clonedOptions.enabled === 'function' &&\n clonedOptions.enabled.length === 0\n ) {\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 // Replaced below with the wrapper. Declared here so the subscriber can put it\n // back after `updateState` copies the observer's own `refetch` onto `state`.\n let refetch: (typeof state)['refetch'] = (...args) =>\n observer.refetch(...args)\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 state.refetch = refetch\n })\n }\n },\n { immediate: true },\n )\n }\n\n const updater = () => {\n observer.setOptions(defaultedOptions.value)\n updateState(state, observer.getCurrentResult())\n state.refetch = refetch\n }\n\n watch(defaultedOptions, updater)\n\n onScopeDispose(() => {\n unsubscribe()\n })\n\n // fix #5910. Call `observer.refetch`: `state.refetch` is this wrapper, so\n // calling it would recurse.\n refetch = (...args) => {\n updater()\n return observer.refetch(...args)\n }\n state.refetch = refetch\n\n const suspense = () => {\n return new Promise<QueryObserverResult<TData, TError>>(\n (resolve, reject) => {\n let stopWatch = () => {\n // noop\n }\n const run = () => {\n // Apply the latest options before resolving `enabled`, so a query callback sees the current query.\n // fix #6133\n observer.setOptions(defaultedOptions.value)\n const { enabled } = defaultedOptions.value\n if (\n (typeof enabled === 'function'\n ? enabled(observer.getCurrentQuery())\n : enabled) !== false\n ) {\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 object.state = readonlyState\n\n return object as UseBaseQueryReturnType<TData, TError>\n}\n"],"mappings":"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"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { c as UseBaseQueryReturnType, l as useBaseQuery } from "./infiniteQueryOptions-
|
|
1
|
+
import { c as UseBaseQueryReturnType, l as useBaseQuery } from "./infiniteQueryOptions-CLfd_vOE.cjs";
|
|
2
2
|
export { UseBaseQueryReturnType, useBaseQuery };
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { c as UseBaseQueryReturnType, l as useBaseQuery } from "./infiniteQueryOptions-
|
|
1
|
+
import { c as UseBaseQueryReturnType, l as useBaseQuery } from "./infiniteQueryOptions-vEnw-JaW.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\n/**\n * Readonly view of a union that stays a union. A single `Readonly<Union>` collapses the members, which\n * drops the `status` / `isSuccess` / `isPending` discriminants.\n */\ntype ReadonlyQueryState<T> = T extends any\n ? { readonly [K in keyof T]: T[K] }\n : never\n\n/**\n * The result of the query composables: every property of the observer result wrapped in a `Ref`, except\n * the `refetch`, `fetchNextPage`, and `fetchPreviousPage` functions, plus `suspense` and `state`.\n */\nexport type UseBaseQueryReturnType<\n TData,\n TError,\n TResult = QueryObserverResult<TData, TError>,\n> = {\n [K in keyof TResult]: K extends\n | 'fetchNextPage'\n | 'fetchPreviousPage'\n | '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 * The query result as one readonly reactive object. `data`, `error`, `status`, `isPending`, and the other\n * fields are plain values — read `state.data`, not `state.data.value`.\n *\n * The object is a discriminated union, so a check on `status`, `isSuccess`, `isPending`, or `isError`\n * narrows the other fields. When `status` is `'success'` (or `isSuccess` is `true`), `data` is `TData`.\n * When `status` is `'pending'` (or `isPending` is `true`), `data` is `undefined` and `error` is `null`.\n * @example\n * ```vue\n * <script setup lang=\"ts\">\n * import { useQuery } from '@tanstack/vue-query'\n *\n * const { state } = useQuery({\n * queryKey: ['post'],\n * queryFn: fetchPost,\n * })\n *\n * if (state.status === 'success') {\n * // `state.data` is `Post`, not `Post | undefined`\n * console.log(state.data.title)\n * }\n * </script>\n *\n * <template>\n * <span v-if=\"state.status === 'pending'\">Loading...</span>\n * <span v-else-if=\"state.status === 'error'\">Error: {{ state.error.message }}</span>\n * <h1 v-else>{{ state.data.title }}</h1>\n * </template>\n * ```\n */\n state: ReadonlyQueryState<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 * @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 * @returns The query result as `ref`s, plus the `suspense` function.\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 // A zero-arg function is a Vue getter and must run here so its refs are tracked.\n // `(query) => boolean` is query-core's callback and is left for core to call.\n if (\n typeof clonedOptions.enabled === 'function' &&\n clonedOptions.enabled.length === 0\n ) {\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 // Replaced below with the wrapper. Declared here so the subscriber can put it\n // back after `updateState` copies the observer's own `refetch` onto `state`.\n let refetch: (typeof state)['refetch'] = (...args) =>\n observer.refetch(...args)\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 state.refetch = refetch\n })\n }\n },\n { immediate: true },\n )\n }\n\n const updater = () => {\n observer.setOptions(defaultedOptions.value)\n updateState(state, observer.getCurrentResult())\n state.refetch = refetch\n }\n\n watch(defaultedOptions, updater)\n\n onScopeDispose(() => {\n unsubscribe()\n })\n\n // fix #5910. Call `observer.refetch`: `state.refetch` is this wrapper, so\n // calling it would recurse.\n refetch = (...args) => {\n updater()\n return observer.refetch(...args)\n }\n state.refetch = refetch\n\n const suspense = () => {\n return new Promise<QueryObserverResult<TData, TError>>(\n (resolve, reject) => {\n let stopWatch = () => {\n // noop\n }\n const run = () => {\n // Apply the latest options before resolving `enabled`, so a query callback sees the current query.\n // fix #6133\n observer.setOptions(defaultedOptions.value)\n const { enabled } = defaultedOptions.value\n if (\n (typeof enabled === 'function'\n ? enabled(observer.getCurrentQuery())\n : enabled) !== false\n ) {\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 object.state = readonlyState\n\n return object as UseBaseQueryReturnType<TData, TError>\n}\n"],"mappings":"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"}
|
|
1
|
+
{"version":3,"file":"useBaseQuery.js","names":[],"sources":["../../src/useBaseQuery.ts"],"sourcesContent":["import { shouldThrowError } from '@tanstack/query-core'\nimport {\n computed,\n getCurrentScope,\n onScopeDispose,\n reactive,\n readonly,\n shallowReactive,\n shallowReadonly,\n toRefs,\n watch,\n} from 'vue-demi'\nimport { useQueryClient } from './useQueryClient'\nimport { cloneDeepUnref, updateState } from './utils'\nimport type {\n DefaultedQueryObserverOptions,\n QueryKey,\n QueryObserver,\n QueryObserverResult,\n} from '@tanstack/query-core'\nimport type { Ref } from 'vue-demi'\nimport type { QueryClient } from './queryClient'\nimport type { UseQueryOptions } from './queryOptions'\nimport type { MaybeRefOrGetter } from './types'\nimport type { UseInfiniteQueryOptions } from './useInfiniteQuery'\n\n/**\n * Readonly view of a union that stays a union. A single `Readonly<Union>` collapses the members, which\n * drops the `status` / `isSuccess` / `isPending` discriminants.\n */\ntype ReadonlyQueryState<T> = T extends any\n ? { readonly [K in keyof T]: T[K] }\n : never\n\n/**\n * The result of the query composables: every property of the observer result wrapped in a `Ref`, except\n * the `refetch`, `fetchNextPage`, and `fetchPreviousPage` functions, plus `suspense` and `state`.\n */\nexport type UseBaseQueryReturnType<\n TData,\n TError,\n TResult = QueryObserverResult<TData, TError>,\n> = {\n [K in keyof TResult]: K extends\n | 'fetchNextPage'\n | 'fetchPreviousPage'\n | '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 * The query result as one readonly reactive object. `data`, `error`, `status`, `isPending`, and the other\n * fields are plain values — read `state.data`, not `state.data.value`.\n *\n * The object is a discriminated union, so a check on `status`, `isSuccess`, `isPending`, or `isError`\n * narrows the other fields. When `status` is `'success'` (or `isSuccess` is `true`), `data` is `TData`.\n * When `status` is `'pending'` (or `isPending` is `true`), `data` is `undefined` and `error` is `null`.\n * @example\n * ```vue\n * <script setup lang=\"ts\">\n * import { useQuery } from '@tanstack/vue-query'\n *\n * const { state } = useQuery({\n * queryKey: ['post'],\n * queryFn: fetchPost,\n * })\n *\n * if (state.status === 'success') {\n * // `state.data` is `Post`, not `Post | undefined`\n * console.log(state.data.title)\n * }\n * </script>\n *\n * <template>\n * <span v-if=\"state.status === 'pending'\">Loading...</span>\n * <span v-else-if=\"state.status === 'error'\">Error: {{ state.error.message }}</span>\n * <h1 v-else>{{ state.data.title }}</h1>\n * </template>\n * ```\n */\n state: ReadonlyQueryState<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 * @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 * @returns The query result as `ref`s, plus the `suspense` function.\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 // A zero-arg function is a Vue getter and must run here so its refs are tracked.\n // `(query) => boolean` is query-core's callback and is left for core to call.\n if (\n typeof clonedOptions.enabled === 'function' &&\n clonedOptions.enabled.length === 0\n ) {\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 // Replaced below with the wrapper. Declared here so the subscriber can put it\n // back after `updateState` copies the observer's own `refetch` onto `state`.\n let refetch: (typeof state)['refetch'] = (...args) =>\n observer.refetch(...args)\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 state.refetch = refetch\n })\n }\n },\n { immediate: true },\n )\n }\n\n const updater = () => {\n observer.setOptions(defaultedOptions.value)\n updateState(state, observer.getCurrentResult())\n state.refetch = refetch\n }\n\n watch(defaultedOptions, updater)\n\n onScopeDispose(() => {\n unsubscribe()\n })\n\n // fix #5910. Call `observer.refetch`: `state.refetch` is this wrapper, so\n // calling it would recurse.\n refetch = (...args) => {\n updater()\n return observer.refetch(...args)\n }\n state.refetch = refetch\n\n const suspense = () => {\n return new Promise<QueryObserverResult<TData, TError>>(\n (resolve, reject) => {\n let stopWatch = () => {\n // noop\n }\n const run = () => {\n // Apply the latest options before resolving `enabled`, so a query callback sees the current query.\n // fix #6133\n observer.setOptions(defaultedOptions.value)\n const { enabled } = defaultedOptions.value\n if (\n (typeof enabled === 'function'\n ? enabled(observer.getCurrentQuery())\n : enabled) !== false\n ) {\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 object.state = readonlyState\n\n return object as UseBaseQueryReturnType<TData, TError>\n}\n"],"mappings":"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"}
|
|
@@ -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 { VueQueryEnabledOption } from './queryOptions'\nimport type {\n DefaultError,\n DefinedInfiniteQueryObserverResult,\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\n/**\n * The options accepted by `useInfiniteQuery`. Same as {@link InfiniteQueryObserverOptions} from\n * `@tanstack/query-core`, plus the `shallow` option. Each option except `shallow` can also be a `ref` (and\n * `enabled` a reactive getter).\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 ? VueQueryEnabledOption<\n TQueryFnData,\n TError,\n InfiniteData<TQueryFnData, TPageParam>,\n DeepUnwrapRef<TQueryKey>\n >\n : MaybeRefDeep<\n InfiniteQueryObserverOptions<\n TQueryFnData,\n TError,\n TData,\n DeepUnwrapRef<TQueryKey>,\n TPageParam\n >[Property]\n >\n } & ShallowOption\n>\n\n/**\n * The result of `useInfiniteQuery`: {@link InfiniteQueryObserverResult} from `@tanstack/query-core`, with\n * its properties wrapped in `Ref`s as in {@link UseBaseQueryReturnType}.\n */\nexport type UseInfiniteQueryReturnType<TData, TError> = UseBaseQueryReturnType<\n TData,\n TError,\n InfiniteQueryObserverResult<TData, TError>\n>\n\n/**\n * The result of `useInfiniteQuery` when `initialData` is set — `data` is never `undefined` (unless a `select`\n * changes `TData` to include `undefined`).\n */\nexport type UseInfiniteQueryDefinedReturnType<TData, TError> =\n UseBaseQueryReturnType<\n TData,\n TError,\n DefinedInfiniteQueryObserverResult<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 known to be defined, so the resulting `data` is never\n * `undefined` (unless 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 * @param options - The {@link DefinedInitialDataInfiniteOptions} to use — everything you can pass to\n * `useInfiniteQuery`, with `initialData` known to be defined.\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 * @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 * @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): UseInfiniteQueryDefinedReturnType<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 * @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 * @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 * @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 * @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 * @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 * @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 * @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":";;;;AAqXA,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 DefaultError,\n DefinedInfiniteQueryObserverResult,\n InfiniteData,\n InfiniteQueryObserverOptions,\n InfiniteQueryObserverResult,\n QueryKey,\n QueryObserver,\n} from '@tanstack/query-core'\nimport type {\n DefinedInitialDataInfiniteOptions,\n UndefinedInitialDataInfiniteOptions,\n} from './infiniteQueryOptions'\nimport type { QueryClient } from './queryClient'\nimport type { VueQueryEnabledOption } from './queryOptions'\nimport type {\n DeepUnwrapRef,\n MaybeRef,\n MaybeRefDeep,\n MaybeRefOrGetter,\n ShallowOption,\n} from './types'\nimport type { UseBaseQueryReturnType } from './useBaseQuery'\n\n/**\n * The options accepted by `useInfiniteQuery`. Extends {@link InfiniteQueryObserverOptions} from\n * `@tanstack/query-core` with the `vue-query`-specific `shallow` option. Each option except `shallow` can also\n * be a `ref` (and `enabled` a zero-argument getter or query-core's `(query) => boolean` callback).\n * @template TQueryFnData - The type of a single page, as your `queryFn` resolves it.\n * @template TError - The type of errors your `queryFn` may throw.\n * @template TData - The type `data` ends up as after `select` runs — defaults to `TQueryFnData`.\n * @template TQueryKey - The type of your `queryKey`.\n * @template TPageParam - The type of the parameter passed to `queryFn` to fetch a given page.\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 ? VueQueryEnabledOption<\n TQueryFnData,\n TError,\n InfiniteData<TQueryFnData, TPageParam>,\n DeepUnwrapRef<TQueryKey>\n >\n : MaybeRefDeep<\n InfiniteQueryObserverOptions<\n TQueryFnData,\n TError,\n TData,\n DeepUnwrapRef<TQueryKey>,\n TPageParam\n >[Property]\n >\n } & ShallowOption\n>\n\n/**\n * The result of `useInfiniteQuery`: {@link InfiniteQueryObserverResult} from `@tanstack/query-core`, with\n * its properties wrapped in `Ref`s as in {@link UseBaseQueryReturnType}.\n */\nexport type UseInfiniteQueryReturnType<TData, TError> = UseBaseQueryReturnType<\n TData,\n TError,\n InfiniteQueryObserverResult<TData, TError>\n>\n\n/**\n * The result of `useInfiniteQuery` when `initialData` is set — `data` is never `undefined` (unless a `select`\n * changes `TData` to include `undefined`).\n */\nexport type UseInfiniteQueryDefinedReturnType<TData, TError> =\n UseBaseQueryReturnType<\n TData,\n TError,\n DefinedInfiniteQueryObserverResult<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 known to be defined, so the resulting `data` is never\n * `undefined` (unless a `select` changes `TData` to include `undefined`).\n *\n * `enabled` accepts a `ref`, a plain boolean, or a zero-argument getter (`() => ...`): a `ref` or a getter is\n * tracked, while a plain boolean isn't tracked on its own. query-core's `(query) => boolean` callback is\n * accepted too and is passed through untracked. `queryKey` reacts through a `ref` for the array itself, or\n * `ref`s and reactive getters as individual entries — the array itself can't be a bare getter.\n * @param options - The {@link DefinedInitialDataInfiniteOptions} to use — everything you can pass to\n * `useInfiniteQuery`, with `initialData` known to be defined.\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 * @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 * @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): UseInfiniteQueryDefinedReturnType<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` accepts a `ref`, a plain boolean, or a zero-argument getter (`() => ...`): a `ref` or a getter is\n * tracked, while a plain boolean isn't tracked on its own. query-core's `(query) => boolean` callback is\n * accepted too and is passed through untracked. `queryKey` reacts through a `ref` for the array itself, or\n * `ref`s and reactive getters as individual entries — the array itself can't be a bare getter.\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 * @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 * @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 * @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` accepts a `ref`, a plain boolean, or a zero-argument getter (`() => ...`): a `ref` or a getter is\n * tracked, while a plain boolean isn't tracked on its own. query-core's `(query) => boolean` callback is\n * accepted too and is passed through untracked. `queryKey` reacts through a `ref` for the array itself, or\n * `ref`s and reactive getters as individual entries — the array itself can't be a bare getter.\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 * @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 * @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":";;;;AA2XA,SAAgB,iBACd,SACA,aACA;CACA,OAAOA,qBAAAA,aACLC,qBAAAA,uBACA,SACA,WACF;AACF"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { a as UseInfiniteQueryOptions, i as UseInfiniteQueryDefinedReturnType, o as UseInfiniteQueryReturnType, s as useInfiniteQuery } from "./infiniteQueryOptions-
|
|
1
|
+
import { a as UseInfiniteQueryOptions, i as UseInfiniteQueryDefinedReturnType, o as UseInfiniteQueryReturnType, s as useInfiniteQuery } from "./infiniteQueryOptions-CLfd_vOE.cjs";
|
|
2
2
|
export { UseInfiniteQueryDefinedReturnType, UseInfiniteQueryOptions, UseInfiniteQueryReturnType, useInfiniteQuery };
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { a as UseInfiniteQueryOptions, i as UseInfiniteQueryDefinedReturnType, o as UseInfiniteQueryReturnType, s as useInfiniteQuery } from "./infiniteQueryOptions-
|
|
1
|
+
import { a as UseInfiniteQueryOptions, i as UseInfiniteQueryDefinedReturnType, o as UseInfiniteQueryReturnType, s as useInfiniteQuery } from "./infiniteQueryOptions-vEnw-JaW.js";
|
|
2
2
|
export { UseInfiniteQueryDefinedReturnType, 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 { VueQueryEnabledOption } from './queryOptions'\nimport type {\n DefaultError,\n DefinedInfiniteQueryObserverResult,\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\n/**\n * The options accepted by `useInfiniteQuery`. Same as {@link InfiniteQueryObserverOptions} from\n * `@tanstack/query-core`, plus the `shallow` option. Each option except `shallow` can also be a `ref` (and\n * `enabled` a reactive getter).\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 ? VueQueryEnabledOption<\n TQueryFnData,\n TError,\n InfiniteData<TQueryFnData, TPageParam>,\n DeepUnwrapRef<TQueryKey>\n >\n : MaybeRefDeep<\n InfiniteQueryObserverOptions<\n TQueryFnData,\n TError,\n TData,\n DeepUnwrapRef<TQueryKey>,\n TPageParam\n >[Property]\n >\n } & ShallowOption\n>\n\n/**\n * The result of `useInfiniteQuery`: {@link InfiniteQueryObserverResult} from `@tanstack/query-core`, with\n * its properties wrapped in `Ref`s as in {@link UseBaseQueryReturnType}.\n */\nexport type UseInfiniteQueryReturnType<TData, TError> = UseBaseQueryReturnType<\n TData,\n TError,\n InfiniteQueryObserverResult<TData, TError>\n>\n\n/**\n * The result of `useInfiniteQuery` when `initialData` is set — `data` is never `undefined` (unless a `select`\n * changes `TData` to include `undefined`).\n */\nexport type UseInfiniteQueryDefinedReturnType<TData, TError> =\n UseBaseQueryReturnType<\n TData,\n TError,\n DefinedInfiniteQueryObserverResult<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 known to be defined, so the resulting `data` is never\n * `undefined` (unless 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 * @param options - The {@link DefinedInitialDataInfiniteOptions} to use — everything you can pass to\n * `useInfiniteQuery`, with `initialData` known to be defined.\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 * @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 * @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): UseInfiniteQueryDefinedReturnType<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 * @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 * @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 * @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 * @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 * @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 * @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 * @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":";;;AAqXA,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 DefaultError,\n DefinedInfiniteQueryObserverResult,\n InfiniteData,\n InfiniteQueryObserverOptions,\n InfiniteQueryObserverResult,\n QueryKey,\n QueryObserver,\n} from '@tanstack/query-core'\nimport type {\n DefinedInitialDataInfiniteOptions,\n UndefinedInitialDataInfiniteOptions,\n} from './infiniteQueryOptions'\nimport type { QueryClient } from './queryClient'\nimport type { VueQueryEnabledOption } from './queryOptions'\nimport type {\n DeepUnwrapRef,\n MaybeRef,\n MaybeRefDeep,\n MaybeRefOrGetter,\n ShallowOption,\n} from './types'\nimport type { UseBaseQueryReturnType } from './useBaseQuery'\n\n/**\n * The options accepted by `useInfiniteQuery`. Extends {@link InfiniteQueryObserverOptions} from\n * `@tanstack/query-core` with the `vue-query`-specific `shallow` option. Each option except `shallow` can also\n * be a `ref` (and `enabled` a zero-argument getter or query-core's `(query) => boolean` callback).\n * @template TQueryFnData - The type of a single page, as your `queryFn` resolves it.\n * @template TError - The type of errors your `queryFn` may throw.\n * @template TData - The type `data` ends up as after `select` runs — defaults to `TQueryFnData`.\n * @template TQueryKey - The type of your `queryKey`.\n * @template TPageParam - The type of the parameter passed to `queryFn` to fetch a given page.\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 ? VueQueryEnabledOption<\n TQueryFnData,\n TError,\n InfiniteData<TQueryFnData, TPageParam>,\n DeepUnwrapRef<TQueryKey>\n >\n : MaybeRefDeep<\n InfiniteQueryObserverOptions<\n TQueryFnData,\n TError,\n TData,\n DeepUnwrapRef<TQueryKey>,\n TPageParam\n >[Property]\n >\n } & ShallowOption\n>\n\n/**\n * The result of `useInfiniteQuery`: {@link InfiniteQueryObserverResult} from `@tanstack/query-core`, with\n * its properties wrapped in `Ref`s as in {@link UseBaseQueryReturnType}.\n */\nexport type UseInfiniteQueryReturnType<TData, TError> = UseBaseQueryReturnType<\n TData,\n TError,\n InfiniteQueryObserverResult<TData, TError>\n>\n\n/**\n * The result of `useInfiniteQuery` when `initialData` is set — `data` is never `undefined` (unless a `select`\n * changes `TData` to include `undefined`).\n */\nexport type UseInfiniteQueryDefinedReturnType<TData, TError> =\n UseBaseQueryReturnType<\n TData,\n TError,\n DefinedInfiniteQueryObserverResult<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 known to be defined, so the resulting `data` is never\n * `undefined` (unless a `select` changes `TData` to include `undefined`).\n *\n * `enabled` accepts a `ref`, a plain boolean, or a zero-argument getter (`() => ...`): a `ref` or a getter is\n * tracked, while a plain boolean isn't tracked on its own. query-core's `(query) => boolean` callback is\n * accepted too and is passed through untracked. `queryKey` reacts through a `ref` for the array itself, or\n * `ref`s and reactive getters as individual entries — the array itself can't be a bare getter.\n * @param options - The {@link DefinedInitialDataInfiniteOptions} to use — everything you can pass to\n * `useInfiniteQuery`, with `initialData` known to be defined.\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 * @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 * @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): UseInfiniteQueryDefinedReturnType<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` accepts a `ref`, a plain boolean, or a zero-argument getter (`() => ...`): a `ref` or a getter is\n * tracked, while a plain boolean isn't tracked on its own. query-core's `(query) => boolean` callback is\n * accepted too and is passed through untracked. `queryKey` reacts through a `ref` for the array itself, or\n * `ref`s and reactive getters as individual entries — the array itself can't be a bare getter.\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 * @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 * @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 * @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` accepts a `ref`, a plain boolean, or a zero-argument getter (`() => ...`): a `ref` or a getter is\n * tracked, while a plain boolean isn't tracked on its own. query-core's `(query) => boolean` callback is\n * accepted too and is passed through untracked. `queryKey` reacts through a `ref` for the array itself, or\n * `ref`s and reactive getters as individual entries — the array itself can't be a bare getter.\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 * @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 * @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":";;;AA2XA,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 {
|
|
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 { QueryFilters } from '@tanstack/query-core'\nimport type { Ref } from 'vue-demi'\nimport type { QueryClient } from './queryClient'\nimport type { MaybeRefDeep } from './types'\n\n/**\n * The filters accepted by `useIsFetching`: {@link QueryFilters} as a plain object, a `ref`, or a reactive\n * getter.\n */\nexport type UseIsFetchingFilters =\n | MaybeRefDeep<Omit<QueryFilters, 'fetchStatus'>>\n | (() => MaybeRefDeep<Omit<QueryFilters, 'fetchStatus'>>)\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 * @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 * @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 * @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":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAsDA,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-u_Tu5Ybs.cjs";
|
|
2
|
-
import { t as QueryClient$1 } from "./queryClient-
|
|
2
|
+
import { t as QueryClient$1 } from "./queryClient-yJW8K_VP.cjs";
|
|
3
3
|
import { QueryFilters } from "@tanstack/query-core";
|
|
4
4
|
import { Ref } from "vue-demi";
|
|
5
5
|
/**
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { o as MaybeRefDeep } from "./types-u_Tu5Ybs.js";
|
|
2
|
-
import { t as QueryClient$1 } from "./queryClient-
|
|
2
|
+
import { t as QueryClient$1 } from "./queryClient-6AWIHAhP.js";
|
|
3
3
|
import { QueryFilters } from "@tanstack/query-core";
|
|
4
4
|
import { Ref } from "vue-demi";
|
|
5
5
|
/**
|
|
@@ -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 {
|
|
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 { QueryFilters } from '@tanstack/query-core'\nimport type { Ref } from 'vue-demi'\nimport type { QueryClient } from './queryClient'\nimport type { MaybeRefDeep } from './types'\n\n/**\n * The filters accepted by `useIsFetching`: {@link QueryFilters} as a plain object, a `ref`, or a reactive\n * getter.\n */\nexport type UseIsFetchingFilters =\n | MaybeRefDeep<Omit<QueryFilters, 'fetchStatus'>>\n | (() => MaybeRefDeep<Omit<QueryFilters, 'fetchStatus'>>)\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 * @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 * @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 * @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":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAsDA,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 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useMutation.cjs","names":["getCurrentScope","useQueryClient","computed","cloneDeepUnref","MutationObserver","shallowReactive","reactive","shallowReadonly","readonly","toRefs","shouldThrowError"],"sources":["../../src/useMutation.ts"],"sourcesContent":["import {\n computed,\n getCurrentScope,\n onScopeDispose,\n reactive,\n readonly,\n shallowReactive,\n shallowReadonly,\n toRefs,\n watch,\n} from 'vue-demi'\nimport { MutationObserver, shouldThrowError } from '@tanstack/query-core'\nimport { cloneDeepUnref, updateState } from './utils'\nimport { useQueryClient } from './useQueryClient'\nimport type { ToRefs } from 'vue-demi'\nimport type {\n DefaultError,\n DistributiveOmit,\n MutateFunction,\n MutationObserverResult,\n} from '@tanstack/query-core'\nimport type { MaybeRefDeep, MutationOptions } from './types'\nimport type { QueryClient } from './queryClient'\n\n/**\n * The {@link MutationObserverResult} properties without `mutate` and `reset`, which `useMutation` replaces with\n * its own versions.\n */\nexport type MutationResult<TData, TError, TVariables, TOnMutateResult> =\n DistributiveOmit<\n MutationObserverResult<TData, TError, TVariables, TOnMutateResult>,\n 'mutate' | 'reset'\n >\n\n/**\n * The options accepted by `useMutation`: {@link MutationOptions} as a plain object, a `ref`, or a reactive\n * getter.\n */\nexport type UseMutationOptions<\n TData = unknown,\n TError = DefaultError,\n TVariables = void,\n TOnMutateResult = unknown,\n> =\n | MaybeRefDeep<MutationOptions<TData, TError, TVariables, TOnMutateResult>>\n | (() => MaybeRefDeep<\n MutationOptions<TData, TError, TVariables, TOnMutateResult>\n >)\n\ntype MutateSyncFunction<\n TData = unknown,\n TError = DefaultError,\n TVariables = void,\n TOnMutateResult = unknown,\n> = (\n ...options: Parameters<\n MutateFunction<TData, TError, TVariables, TOnMutateResult>\n >\n) => void\n\n/**\n * The result of `useMutation`: the {@link MutationObserverResult} properties wrapped in `Ref`s, plus the\n * fire-and-forget `mutate`, the awaitable `mutateAsync`, and `reset`.\n */\nexport type UseMutationReturnType<\n TData,\n TError,\n TVariables,\n TOnMutateResult,\n TResult = MutationResult<TData, TError, TVariables, TOnMutateResult>,\n> = ToRefs<Readonly<TResult>> & {\n mutate: MutateSyncFunction<TData, TError, TVariables, TOnMutateResult>\n mutateAsync: MutateFunction<TData, TError, TVariables, TOnMutateResult>\n reset: MutationObserverResult<\n TData,\n TError,\n TVariables,\n TOnMutateResult\n >['reset']\n}\n\n/**\n * Unlike queries, mutations are typically used to create/update/delete data or perform server side-effects.\n * `useMutation` is the composable for that.\n *\n * `options` may be a plain object, a `ref`, or a reactive getter (`() => ({ ... })`) — pass a getter\n * if the options themselves depend on other reactive state.\n * @param options - The {@link UseMutationOptions} to use — everything you can pass to `useMutation`.\n * @param queryClient - Use this to use a custom `QueryClient`. Otherwise, the one provided by `VueQueryPlugin`\n * will be used.\n * @returns `mutate`/`mutateAsync` also accept per-call `onSuccess`/`onError`/`onSettled` callbacks as a second\n * argument, useful for triggering call-site side effects (e.g. navigation) without coupling them to the shared\n * mutation definition. Hook-level callbacks (passed to `options`) fire for every mutation; per-call\n * callbacks fire only for the latest call you've made.\n * @see {@link mutationOptions} to share these options across multiple `useMutation` call sites, or to look\n * the mutation up elsewhere via its `mutationKey` (e.g. with `useMutationState`).\n * @example\n * ```vue\n * <script setup lang=\"ts\">\n * import { useMutation, useQueryClient } from '@tanstack/vue-query'\n *\n * const queryClient = useQueryClient()\n *\n * const addMutation = useMutation({\n * mutationFn: addTodo,\n * onSuccess: () => queryClient.invalidateQueries({ queryKey: ['todos'] }),\n * })\n *\n * function onAdd() {\n * addMutation.mutate('Item', {\n * onError: (error) => console.error('Failed to add item:', error),\n * })\n * }\n * </script>\n *\n * <template>\n * <button @click=\"onAdd\">Add</button>\n * </template>\n * ```\n * @example\n * Rendering the mutation's own state, rather than just firing it off:\n * ```vue\n * <script setup lang=\"ts\">\n * import { useMutation, useQueryClient } from '@tanstack/vue-query'\n *\n * const queryClient = useQueryClient()\n *\n * const addMutation = useMutation({\n * mutationFn: addTodo,\n * onSuccess: () => queryClient.invalidateQueries({ queryKey: ['todos'] }),\n * })\n * </script>\n *\n * <template>\n * <div v-if=\"addMutation.isPending.value\">Adding todo...</div>\n * <div v-else>\n * <div v-if=\"addMutation.isError.value\">An error occurred: {{ addMutation.error.value.message }}</div>\n * <button @click=\"addMutation.mutate('Item')\">Add</button>\n * </div>\n * </template>\n * ```\n * @example\n * Optimistic update via `onMutate`, rolling back on `onError`:\n * ```vue\n * <script setup lang=\"ts\">\n * import { useMutation, useQueryClient } from '@tanstack/vue-query'\n *\n * const queryClient = useQueryClient()\n *\n * const addMutation = useMutation({\n * mutationFn: addTodo,\n * onMutate: async (newTodo: string) => {\n * await queryClient.cancelQueries({ queryKey: ['todos'] })\n * const previousTodos = queryClient.getQueryData<Array<string>>(['todos'])\n *\n * queryClient.setQueryData<Array<string>>(['todos'], (old) => [\n * ...(old ?? []),\n * newTodo,\n * ])\n *\n * // Passed to `onError` as `onMutateResult` if the mutation fails.\n * return { previousTodos }\n * },\n * onError: (_err, _newTodo, onMutateResult) => {\n * queryClient.setQueryData(['todos'], onMutateResult?.previousTodos)\n * },\n * onSettled: () => {\n * queryClient.invalidateQueries({ queryKey: ['todos'] })\n * },\n * })\n * </script>\n *\n * <template>\n * <button @click=\"addMutation.mutate('Item')\">Add</button>\n * </template>\n * ```\n * @example\n * Callbacks passed per call to `mutate` only fire for the last call — `mutateAsync` gives you a\n * promise per call instead, so you can wait for all of them when they succeed:\n * ```vue\n * <script setup lang=\"ts\">\n * import { useMutation, useQueryClient } from '@tanstack/vue-query'\n *\n * const queryClient = useQueryClient()\n *\n * const addMutation = useMutation({\n * mutationFn: addTodo,\n * onSuccess: () => queryClient.invalidateQueries({ queryKey: ['todos'] }),\n * })\n *\n * async function handleAddAll(todos: Array<string>) {\n * try {\n * await Promise.all(todos.map((todo) => addMutation.mutateAsync(todo)))\n * } catch (error) {\n * console.error('Failed to add todos:', error)\n * }\n * }\n * </script>\n *\n * <template>\n * <button @click=\"handleAddAll(['Todo 1', 'Todo 2', 'Todo 3'])\">Add all</button>\n * </template>\n * ```\n * @example\n * If some of the mutations above can fail independently of the others, and you want to know which ones\n * did — rather than losing that information the moment the first one rejects — swap `Promise.all` for\n * `Promise.allSettled`:\n * ```vue\n * <script setup lang=\"ts\">\n * import { useMutation, useQueryClient } from '@tanstack/vue-query'\n *\n * const queryClient = useQueryClient()\n *\n * const addMutation = useMutation({\n * mutationFn: addTodo,\n * onSuccess: () => queryClient.invalidateQueries({ queryKey: ['todos'] }),\n * })\n *\n * async function handleAddAll(todos: Array<string>) {\n * const addResults = await Promise.allSettled(\n * todos.map((todo) => addMutation.mutateAsync(todo)),\n * )\n *\n * addResults.forEach((addResult, index) => {\n * if (addResult.status === 'rejected') {\n * console.error(`Failed to add \"${todos[index]}\":`, addResult.reason)\n * }\n * })\n * }\n * </script>\n *\n * <template>\n * <button @click=\"handleAddAll(['Todo 1', 'Todo 2', 'Todo 3'])\">Add all</button>\n * </template>\n * ```\n */\nexport function useMutation<\n TData = unknown,\n TError = DefaultError,\n TVariables = void,\n TOnMutateResult = unknown,\n>(\n options: UseMutationOptions<TData, TError, TVariables, TOnMutateResult>,\n queryClient?: QueryClient,\n): UseMutationReturnType<TData, TError, TVariables, TOnMutateResult> {\n if (process.env.NODE_ENV === 'development') {\n if (!getCurrentScope()) {\n console.warn(\n 'vue-query composable like \"useQuery()\" should only be used inside a \"setup()\" function or a running effect scope. They might otherwise lead to memory leaks.',\n )\n }\n }\n\n const client = queryClient || useQueryClient()\n const defaultedOptions = computed(() => {\n const resolvedOptions = typeof options === 'function' ? options() : options\n return client.defaultMutationOptions(cloneDeepUnref(resolvedOptions))\n })\n const observer = new MutationObserver(client, defaultedOptions.value)\n const state = defaultedOptions.value.shallow\n ? shallowReactive(observer.getCurrentResult())\n : reactive(observer.getCurrentResult())\n\n const unsubscribe = observer.subscribe((result) => {\n updateState(state, result)\n })\n\n const mutate = (\n ...args: Parameters<\n MutateFunction<TData, TError, TVariables, TOnMutateResult>\n >\n ) => {\n observer.mutate(args[0] as TVariables, args[1]).catch(() => {\n // This is intentional\n })\n }\n\n watch(defaultedOptions, () => {\n observer.setOptions(defaultedOptions.value)\n })\n\n onScopeDispose(() => {\n unsubscribe()\n })\n\n const readonlyState = defaultedOptions.value.shallow\n ? shallowReadonly(state)\n : readonly(state)\n\n const resultRefs = toRefs(readonlyState) as ToRefs<\n Readonly<MutationResult<TData, TError, TVariables, TOnMutateResult>>\n >\n\n watch(\n () => state.error,\n (error) => {\n if (\n error &&\n shouldThrowError(defaultedOptions.value.throwOnError, [error as TError])\n ) {\n throw error\n }\n },\n )\n\n return {\n ...resultRefs,\n mutate,\n mutateAsync: state.mutate,\n reset: state.reset,\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA4OA,SAAgB,YAMd,SACA,aACmE;CACnE,IAAI,QAAQ,IAAI,aAAa,eACvB;MAAA,EAAA,GAACA,SAAAA,gBAAAA,CAAgB,GACnB,QAAQ,KACN,kKACF;CAAA;CAIJ,MAAM,SAAS,eAAeC,uBAAAA,eAAe;CAC7C,MAAM,oBAAA,GAAmBC,SAAAA,SAAAA,OAAe;EACtC,MAAM,kBAAkB,OAAO,YAAY,aAAa,QAAQ,IAAI;EACpE,OAAO,OAAO,uBAAuBC,cAAAA,eAAe,eAAe,CAAC;CACtE,CAAC;CACD,MAAM,WAAW,IAAIC,qBAAAA,iBAAiB,QAAQ,iBAAiB,KAAK;CACpE,MAAM,QAAQ,iBAAiB,MAAM,WAAA,GACjCC,SAAAA,gBAAAA,CAAgB,SAAS,iBAAiB,CAAC,KAAA,GAC3CC,SAAAA,SAAAA,CAAS,SAAS,iBAAiB,CAAC;CAExC,MAAM,cAAc,SAAS,WAAW,WAAW;EACjD,cAAA,YAAY,OAAO,MAAM;CAC3B,CAAC;CAED,MAAM,UACJ,GAAG,SAGA;EACH,SAAS,OAAO,KAAK,IAAkB,KAAK,EAAE,CAAC,CAAC,YAAY,CAE5D,CAAC;CACH;CAEA,CAAA,GAAA,SAAA,MAAA,CAAM,wBAAwB;EAC5B,SAAS,WAAW,iBAAiB,KAAK;CAC5C,CAAC;CAED,CAAA,GAAA,SAAA,eAAA,OAAqB;EACnB,YAAY;CACd,CAAC;CAED,MAAM,gBAAgB,iBAAiB,MAAM,WAAA,GACzCC,SAAAA,gBAAAA,CAAgB,KAAK,KAAA,GACrBC,SAAAA,SAAAA,CAAS,KAAK;CAElB,MAAM,cAAA,GAAaC,SAAAA,OAAAA,CAAO,aAAa;CAIvC,CAAA,GAAA,SAAA,MAAA,OACQ,MAAM,QACX,UAAU;EACT,IACE,UAAA,GACAC,qBAAAA,iBAAAA,CAAiB,iBAAiB,MAAM,cAAc,CAAC,KAAe,CAAC,GAEvE,MAAM;CAEV,CACF;CAEA,OAAO;EACL,GAAG;EACH;EACA,aAAa,MAAM;EACnB,OAAO,MAAM;CACf;AACF"}
|
|
1
|
+
{"version":3,"file":"useMutation.cjs","names":["getCurrentScope","useQueryClient","computed","cloneDeepUnref","MutationObserver","shallowReactive","reactive","shallowReadonly","readonly","toRefs","shouldThrowError"],"sources":["../../src/useMutation.ts"],"sourcesContent":["import { MutationObserver, shouldThrowError } from '@tanstack/query-core'\nimport {\n computed,\n getCurrentScope,\n onScopeDispose,\n reactive,\n readonly,\n shallowReactive,\n shallowReadonly,\n toRefs,\n watch,\n} from 'vue-demi'\nimport { useQueryClient } from './useQueryClient'\nimport { cloneDeepUnref, updateState } from './utils'\nimport type {\n DefaultError,\n DistributiveOmit,\n MutateFunction,\n MutationObserverResult,\n} from '@tanstack/query-core'\nimport type { ToRefs } from 'vue-demi'\nimport type { QueryClient } from './queryClient'\nimport type { MaybeRefDeep, MutationOptions } from './types'\n\n/**\n * The {@link MutationObserverResult} properties without `mutate` and `reset`, which `useMutation` replaces with\n * its own versions.\n */\nexport type MutationResult<TData, TError, TVariables, TOnMutateResult> =\n DistributiveOmit<\n MutationObserverResult<TData, TError, TVariables, TOnMutateResult>,\n 'mutate' | 'reset'\n >\n\n/**\n * The options accepted by `useMutation`: {@link MutationOptions} as a plain object, a `ref`, or a reactive\n * getter.\n */\nexport type UseMutationOptions<\n TData = unknown,\n TError = DefaultError,\n TVariables = void,\n TOnMutateResult = unknown,\n> =\n | MaybeRefDeep<MutationOptions<TData, TError, TVariables, TOnMutateResult>>\n | (() => MaybeRefDeep<\n MutationOptions<TData, TError, TVariables, TOnMutateResult>\n >)\n\ntype MutateSyncFunction<\n TData = unknown,\n TError = DefaultError,\n TVariables = void,\n TOnMutateResult = unknown,\n> = (\n ...options: Parameters<\n MutateFunction<TData, TError, TVariables, TOnMutateResult>\n >\n) => void\n\n/**\n * The result of `useMutation`: the {@link MutationObserverResult} properties wrapped in `Ref`s, plus the\n * fire-and-forget `mutate`, the awaitable `mutateAsync`, and `reset`.\n */\nexport type UseMutationReturnType<\n TData,\n TError,\n TVariables,\n TOnMutateResult,\n TResult = MutationResult<TData, TError, TVariables, TOnMutateResult>,\n> = ToRefs<Readonly<TResult>> & {\n mutate: MutateSyncFunction<TData, TError, TVariables, TOnMutateResult>\n mutateAsync: MutateFunction<TData, TError, TVariables, TOnMutateResult>\n reset: MutationObserverResult<\n TData,\n TError,\n TVariables,\n TOnMutateResult\n >['reset']\n}\n\n/**\n * Unlike queries, mutations are typically used to create/update/delete data or perform server side-effects.\n * `useMutation` is the composable for that.\n *\n * `options` may be a plain object, a `ref`, or a reactive getter (`() => ({ ... })`) — pass a getter\n * if the options themselves depend on other reactive state.\n * @param options - The {@link UseMutationOptions} to use — everything you can pass to `useMutation`.\n * @param queryClient - Use this to use a custom `QueryClient`. Otherwise, the one provided by `VueQueryPlugin`\n * will be used.\n * @returns `mutate`/`mutateAsync` also accept per-call `onSuccess`/`onError`/`onSettled` callbacks as a second\n * argument, useful for triggering call-site side effects (e.g. navigation) without coupling them to the shared\n * mutation definition. Hook-level callbacks (passed to `options`) fire for every mutation; per-call\n * callbacks fire only for the latest call you've made.\n * @see {@link mutationOptions} to share these options across multiple `useMutation` call sites, or to look\n * the mutation up elsewhere via its `mutationKey` (e.g. with `useMutationState`).\n * @example\n * ```vue\n * <script setup lang=\"ts\">\n * import { useMutation, useQueryClient } from '@tanstack/vue-query'\n *\n * const queryClient = useQueryClient()\n *\n * const addMutation = useMutation({\n * mutationFn: addTodo,\n * onSuccess: () => queryClient.invalidateQueries({ queryKey: ['todos'] }),\n * })\n *\n * function onAdd() {\n * addMutation.mutate('Item', {\n * onError: (error) => console.error('Failed to add item:', error),\n * })\n * }\n * </script>\n *\n * <template>\n * <button @click=\"onAdd\">Add</button>\n * </template>\n * ```\n * @example\n * Rendering the mutation's own state, rather than just firing it off:\n * ```vue\n * <script setup lang=\"ts\">\n * import { useMutation, useQueryClient } from '@tanstack/vue-query'\n *\n * const queryClient = useQueryClient()\n *\n * const addMutation = useMutation({\n * mutationFn: addTodo,\n * onSuccess: () => queryClient.invalidateQueries({ queryKey: ['todos'] }),\n * })\n * </script>\n *\n * <template>\n * <div v-if=\"addMutation.isPending.value\">Adding todo...</div>\n * <div v-else>\n * <div v-if=\"addMutation.isError.value\">An error occurred: {{ addMutation.error.value.message }}</div>\n * <button @click=\"addMutation.mutate('Item')\">Add</button>\n * </div>\n * </template>\n * ```\n * @example\n * Optimistic update via `onMutate`, rolling back on `onError`:\n * ```vue\n * <script setup lang=\"ts\">\n * import { useMutation, useQueryClient } from '@tanstack/vue-query'\n *\n * const queryClient = useQueryClient()\n *\n * const addMutation = useMutation({\n * mutationFn: addTodo,\n * onMutate: async (newTodo: string) => {\n * await queryClient.cancelQueries({ queryKey: ['todos'] })\n * const previousTodos = queryClient.getQueryData<Array<string>>(['todos'])\n *\n * queryClient.setQueryData<Array<string>>(['todos'], (old) => [\n * ...(old ?? []),\n * newTodo,\n * ])\n *\n * // Passed to `onError` as `onMutateResult` if the mutation fails.\n * return { previousTodos }\n * },\n * onError: (_err, _newTodo, onMutateResult) => {\n * queryClient.setQueryData(['todos'], onMutateResult?.previousTodos)\n * },\n * onSettled: () => {\n * queryClient.invalidateQueries({ queryKey: ['todos'] })\n * },\n * })\n * </script>\n *\n * <template>\n * <button @click=\"addMutation.mutate('Item')\">Add</button>\n * </template>\n * ```\n * @example\n * Callbacks passed per call to `mutate` only fire for the last call — `mutateAsync` gives you a\n * promise per call instead, so you can wait for all of them when they succeed:\n * ```vue\n * <script setup lang=\"ts\">\n * import { useMutation, useQueryClient } from '@tanstack/vue-query'\n *\n * const queryClient = useQueryClient()\n *\n * const addMutation = useMutation({\n * mutationFn: addTodo,\n * onSuccess: () => queryClient.invalidateQueries({ queryKey: ['todos'] }),\n * })\n *\n * async function handleAddAll(todos: Array<string>) {\n * try {\n * await Promise.all(todos.map((todo) => addMutation.mutateAsync(todo)))\n * } catch (error) {\n * console.error('Failed to add todos:', error)\n * }\n * }\n * </script>\n *\n * <template>\n * <button @click=\"handleAddAll(['Todo 1', 'Todo 2', 'Todo 3'])\">Add all</button>\n * </template>\n * ```\n * @example\n * If some of the mutations above can fail independently of the others, and you want to know which ones\n * did — rather than losing that information the moment the first one rejects — swap `Promise.all` for\n * `Promise.allSettled`:\n * ```vue\n * <script setup lang=\"ts\">\n * import { useMutation, useQueryClient } from '@tanstack/vue-query'\n *\n * const queryClient = useQueryClient()\n *\n * const addMutation = useMutation({\n * mutationFn: addTodo,\n * onSuccess: () => queryClient.invalidateQueries({ queryKey: ['todos'] }),\n * })\n *\n * async function handleAddAll(todos: Array<string>) {\n * const addResults = await Promise.allSettled(\n * todos.map((todo) => addMutation.mutateAsync(todo)),\n * )\n *\n * addResults.forEach((addResult, index) => {\n * if (addResult.status === 'rejected') {\n * console.error(`Failed to add \"${todos[index]}\":`, addResult.reason)\n * }\n * })\n * }\n * </script>\n *\n * <template>\n * <button @click=\"handleAddAll(['Todo 1', 'Todo 2', 'Todo 3'])\">Add all</button>\n * </template>\n * ```\n */\nexport function useMutation<\n TData = unknown,\n TError = DefaultError,\n TVariables = void,\n TOnMutateResult = unknown,\n>(\n options: UseMutationOptions<TData, TError, TVariables, TOnMutateResult>,\n queryClient?: QueryClient,\n): UseMutationReturnType<TData, TError, TVariables, TOnMutateResult> {\n if (process.env.NODE_ENV === 'development') {\n if (!getCurrentScope()) {\n console.warn(\n 'vue-query composable like \"useQuery()\" should only be used inside a \"setup()\" function or a running effect scope. They might otherwise lead to memory leaks.',\n )\n }\n }\n\n const client = queryClient || useQueryClient()\n const defaultedOptions = computed(() => {\n const resolvedOptions = typeof options === 'function' ? options() : options\n return client.defaultMutationOptions(cloneDeepUnref(resolvedOptions))\n })\n const observer = new MutationObserver(client, defaultedOptions.value)\n const state = defaultedOptions.value.shallow\n ? shallowReactive(observer.getCurrentResult())\n : reactive(observer.getCurrentResult())\n\n const unsubscribe = observer.subscribe((result) => {\n updateState(state, result)\n })\n\n const mutate = (\n ...args: Parameters<\n MutateFunction<TData, TError, TVariables, TOnMutateResult>\n >\n ) => {\n observer.mutate(args[0] as TVariables, args[1]).catch(() => {\n // This is intentional\n })\n }\n\n watch(defaultedOptions, () => {\n observer.setOptions(defaultedOptions.value)\n })\n\n onScopeDispose(() => {\n unsubscribe()\n })\n\n const readonlyState = defaultedOptions.value.shallow\n ? shallowReadonly(state)\n : readonly(state)\n\n const resultRefs = toRefs(readonlyState) as ToRefs<\n Readonly<MutationResult<TData, TError, TVariables, TOnMutateResult>>\n >\n\n watch(\n () => state.error,\n (error) => {\n if (\n error &&\n shouldThrowError(defaultedOptions.value.throwOnError, [error as TError])\n ) {\n throw error\n }\n },\n )\n\n return {\n ...resultRefs,\n mutate,\n mutateAsync: state.mutate,\n reset: state.reset,\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA4OA,SAAgB,YAMd,SACA,aACmE;CACnE,IAAI,QAAQ,IAAI,aAAa,eACvB;MAAA,EAAA,GAACA,SAAAA,gBAAAA,CAAgB,GACnB,QAAQ,KACN,kKACF;CAAA;CAIJ,MAAM,SAAS,eAAeC,uBAAAA,eAAe;CAC7C,MAAM,oBAAA,GAAmBC,SAAAA,SAAAA,OAAe;EACtC,MAAM,kBAAkB,OAAO,YAAY,aAAa,QAAQ,IAAI;EACpE,OAAO,OAAO,uBAAuBC,cAAAA,eAAe,eAAe,CAAC;CACtE,CAAC;CACD,MAAM,WAAW,IAAIC,qBAAAA,iBAAiB,QAAQ,iBAAiB,KAAK;CACpE,MAAM,QAAQ,iBAAiB,MAAM,WAAA,GACjCC,SAAAA,gBAAAA,CAAgB,SAAS,iBAAiB,CAAC,KAAA,GAC3CC,SAAAA,SAAAA,CAAS,SAAS,iBAAiB,CAAC;CAExC,MAAM,cAAc,SAAS,WAAW,WAAW;EACjD,cAAA,YAAY,OAAO,MAAM;CAC3B,CAAC;CAED,MAAM,UACJ,GAAG,SAGA;EACH,SAAS,OAAO,KAAK,IAAkB,KAAK,EAAE,CAAC,CAAC,YAAY,CAE5D,CAAC;CACH;CAEA,CAAA,GAAA,SAAA,MAAA,CAAM,wBAAwB;EAC5B,SAAS,WAAW,iBAAiB,KAAK;CAC5C,CAAC;CAED,CAAA,GAAA,SAAA,eAAA,OAAqB;EACnB,YAAY;CACd,CAAC;CAED,MAAM,gBAAgB,iBAAiB,MAAM,WAAA,GACzCC,SAAAA,gBAAAA,CAAgB,KAAK,KAAA,GACrBC,SAAAA,SAAAA,CAAS,KAAK;CAElB,MAAM,cAAA,GAAaC,SAAAA,OAAAA,CAAO,aAAa;CAIvC,CAAA,GAAA,SAAA,MAAA,OACQ,MAAM,QACX,UAAU;EACT,IACE,UAAA,GACAC,qBAAAA,iBAAAA,CAAiB,iBAAiB,MAAM,cAAc,CAAC,KAAe,CAAC,GAEvE,MAAM;CAEV,CACF;CAEA,OAAO;EACL,GAAG;EACH;EACA,aAAa,MAAM;EACnB,OAAO,MAAM;CACf;AACF"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { c as MutationOptions, o as MaybeRefDeep } from "./types-u_Tu5Ybs.cjs";
|
|
2
|
-
import { t as QueryClient$1 } from "./queryClient-
|
|
2
|
+
import { t as QueryClient$1 } from "./queryClient-yJW8K_VP.cjs";
|
|
3
3
|
import { DefaultError, DistributiveOmit, MutateFunction, MutationObserverResult } from "@tanstack/query-core";
|
|
4
4
|
import { ToRefs } from "vue-demi";
|
|
5
5
|
/**
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { c as MutationOptions, o as MaybeRefDeep } from "./types-u_Tu5Ybs.js";
|
|
2
|
-
import { t as QueryClient$1 } from "./queryClient-
|
|
2
|
+
import { t as QueryClient$1 } from "./queryClient-6AWIHAhP.js";
|
|
3
3
|
import { DefaultError, DistributiveOmit, MutateFunction, MutationObserverResult } from "@tanstack/query-core";
|
|
4
4
|
import { ToRefs } from "vue-demi";
|
|
5
5
|
/**
|