{"version":3,"file":"infinite-query-options.mjs","sources":["../src/infinite-query-options.ts"],"sourcesContent":["import type {\n  DefaultError,\n  InfiniteData,\n  InitialDataFunction,\n  NonUndefinedGuard,\n  OmitKeyof,\n  QueryKey,\n  QueryKeyWithDataTag,\n  SkipToken,\n} from '@tanstack/query-core'\nimport type { CreateInfiniteQueryOptions } from './types'\n\n/**\n * The options accepted by the `infiniteQueryOptions` overload selected when no `initialData` is set — `data`\n * may be `undefined` while the query is `pending`.\n *\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 `InfiniteData<TQueryFnData>`,\n * the shape of all fetched pages plus their page params.\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 UndefinedInitialDataInfiniteOptions<\n  TQueryFnData,\n  TError = DefaultError,\n  TData = InfiniteData<TQueryFnData>,\n  TQueryKey extends QueryKey = QueryKey,\n  TPageParam = unknown,\n> = CreateInfiniteQueryOptions<\n  TQueryFnData,\n  TError,\n  TData,\n  TQueryKey,\n  TPageParam\n> & {\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.\n   */\n  initialData?:\n    | undefined\n    | NonUndefinedGuard<InfiniteData<TQueryFnData, TPageParam>>\n    | InitialDataFunction<\n        NonUndefinedGuard<InfiniteData<TQueryFnData, TPageParam>>\n      >\n}\n\n/**\n * The options accepted by the `infiniteQueryOptions` overload selected when no `initialData` is set and\n * `queryFn` is not `skipToken` — same as {@link UndefinedInitialDataInfiniteOptions}, but `queryFn` may not be\n * `skipToken`.\n *\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 `InfiniteData<TQueryFnData>`,\n * the shape of all fetched pages plus their page params.\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 UnusedSkipTokenInfiniteOptions<\n  TQueryFnData,\n  TError = DefaultError,\n  TData = InfiniteData<TQueryFnData>,\n  TQueryKey extends QueryKey = QueryKey,\n  TPageParam = unknown,\n> = OmitKeyof<\n  CreateInfiniteQueryOptions<\n    TQueryFnData,\n    TError,\n    TData,\n    TQueryKey,\n    TPageParam\n  >,\n  'queryFn'\n> & {\n  /**\n   * `skipToken` is not allowed as a value here — this overload is selected when no `initialData` is set. If\n   * you don't intend to run the query yet, set `enabled: false` — omitting `queryFn` alone still triggers a\n   * fetch that fails with \"Missing queryFn\" unless `enabled` is `false` or a default query function has been\n   * defined. A default query function only supplies `queryFn`; it doesn't defer the fetch on its own.\n   */\n  queryFn?: Exclude<\n    CreateInfiniteQueryOptions<\n      TQueryFnData,\n      TError,\n      TData,\n      TQueryKey,\n      TPageParam\n    >['queryFn'],\n    SkipToken | undefined\n  >\n}\n\n/**\n * The options accepted by the `infiniteQueryOptions` overload selected when `initialData` is set — `data` is\n * never `undefined` (unless a `select` changes `TData` to include `undefined`).\n *\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 `InfiniteData<TQueryFnData>`,\n * the shape of all fetched pages plus their page params.\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 DefinedInitialDataInfiniteOptions<\n  TQueryFnData,\n  TError = DefaultError,\n  TData = InfiniteData<TQueryFnData>,\n  TQueryKey extends QueryKey = QueryKey,\n  TPageParam = unknown,\n> = CreateInfiniteQueryOptions<\n  TQueryFnData,\n  TError,\n  TData,\n  TQueryKey,\n  TPageParam\n> & {\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.\n   */\n  initialData:\n    | NonUndefinedGuard<InfiniteData<TQueryFnData, TPageParam>>\n    | (() => NonUndefinedGuard<InfiniteData<TQueryFnData, TPageParam>>)\n    | undefined\n}\n\n/**\n * You can generally pass everything to `infiniteQueryOptions` that you can also pass to\n * `injectInfiniteQuery`. These options can be shared across functions and imperative APIs such as\n * `queryClient.fetchInfiniteQuery`. `options.queryKey` is required and is the query key to generate options\n * for.\n *\n * This overload is selected when `initialData` is set.\n *\n * @see {@link injectInfiniteQuery} to run an infinite query with these options.\n * @param options - The {@link DefinedInitialDataInfiniteOptions} to use — everything you can pass to\n * `injectInfiniteQuery`, with `initialData` set.\n * @returns The same options object, typed so that `queryKey` carries the inferred data type.\n * @remarks See {@link injectInfiniteQuery} for examples that fetch further pages, from a button click or\n * automatically as the user scrolls.\n *\n * @example\n * ```angular-ts\n * import { infiniteQueryOptions, injectInfiniteQuery } from '@tanstack/angular-query-experimental'\n *\n * export const projectsOptions = infiniteQueryOptions({\n *   queryKey: ['projects'],\n *   queryFn: ({ pageParam }) => fetchProjects(pageParam),\n *   initialPageParam: 0,\n *   getNextPageParam: (lastPage) => lastPage.nextId,\n *   initialData: { pages: [], pageParams: [] },\n * })\n *\n * @Component({\n *   selector: 'projects',\n *   template: `\n *     <!-- `projectsQuery.data()` is never `undefined`, thanks to `initialData` — even if a\n *     refetch fails, so the list stays visible alongside the error. -->\n *     <ul>\n *       @for (page of projectsQuery.data().pages; track $index) {\n *         @for (project of page.projects; track project.id) {\n *           <li>{{ project.name }}</li>\n *         }\n *       }\n *     </ul>\n *   `,\n * })\n * export class Projects {\n *   readonly projectsQuery = injectInfiniteQuery(() => projectsOptions)\n * }\n * ```\n */\nexport function infiniteQueryOptions<\n  TQueryFnData,\n  TError = DefaultError,\n  TData = InfiniteData<TQueryFnData>,\n  TQueryKey extends QueryKey = QueryKey,\n  TPageParam = unknown,\n>(\n  options: DefinedInitialDataInfiniteOptions<\n    TQueryFnData,\n    TError,\n    TData,\n    TQueryKey,\n    TPageParam\n  >,\n): DefinedInitialDataInfiniteOptions<\n  TQueryFnData,\n  TError,\n  TData,\n  TQueryKey,\n  TPageParam\n> &\n  QueryKeyWithDataTag<TQueryKey, InfiniteData<TQueryFnData>, TError>\n\n/**\n * You can generally pass everything to `infiniteQueryOptions` that you can also pass to\n * `injectInfiniteQuery`. These options can be shared across functions and imperative APIs such as\n * `queryClient.fetchInfiniteQuery`. `options.queryKey` is required and is the query key to generate options\n * for.\n *\n * @returns The same options object, typed so that `queryKey` carries the inferred data type.\n * @remarks See {@link injectInfiniteQuery} for examples that fetch further pages, from a button click or\n * automatically as the user scrolls.\n *\n * @example\n * A parameterized factory, so the same options object can be reused per `postId`:\n * ```angular-ts\n * import { infiniteQueryOptions, injectInfiniteQuery } from '@tanstack/angular-query-experimental'\n *\n * export const commentsOptions = (postId: string) =>\n *   infiniteQueryOptions({\n *     queryKey: ['post', postId, 'comments'],\n *     queryFn: ({ pageParam }) => fetchComments(postId, pageParam),\n *     initialPageParam: 0,\n *     getNextPageParam: (lastPage) => lastPage.nextId,\n *   })\n *\n * @Component({\n *   selector: 'comments',\n *   template: `\n *     @if (commentsQuery.isPending()) {\n *       Loading...\n *     } @else if (commentsQuery.isError()) {\n *       <span>Error: {{ commentsQuery.error()?.message }}</span>\n *     } @else {\n *       <ul>\n *         @for (page of commentsQuery.data().pages; track $index) {\n *           @for (comment of page.comments; track comment.id) {\n *             <li>{{ comment.text }}</li>\n *           }\n *         }\n *       </ul>\n *     }\n *   `,\n * })\n * export class Comments {\n *   readonly postId = signal('1')\n *   readonly commentsQuery = injectInfiniteQuery(() => commentsOptions(this.postId()))\n * }\n * ```\n *\n * @see {@link injectInfiniteQuery} to run an infinite query with these options.\n * @param options - The {@link UnusedSkipTokenInfiniteOptions} to use — everything you can pass to\n * `injectInfiniteQuery`.\n */\nexport function infiniteQueryOptions<\n  TQueryFnData,\n  TError = DefaultError,\n  TData = InfiniteData<TQueryFnData>,\n  TQueryKey extends QueryKey = QueryKey,\n  TPageParam = unknown,\n>(\n  options: UnusedSkipTokenInfiniteOptions<\n    TQueryFnData,\n    TError,\n    TData,\n    TQueryKey,\n    TPageParam\n  >,\n): UnusedSkipTokenInfiniteOptions<\n  TQueryFnData,\n  TError,\n  TData,\n  TQueryKey,\n  TPageParam\n> &\n  QueryKeyWithDataTag<TQueryKey, InfiniteData<TQueryFnData>, TError>\n\n/**\n * You can generally pass everything to `infiniteQueryOptions` that you can also pass to\n * `injectInfiniteQuery`. These options can be shared across functions and imperative APIs such as\n * `queryClient.fetchInfiniteQuery`. `options.queryKey` is required and is the query key to generate options\n * for.\n *\n * @returns The same options object, typed so that `queryKey` carries the inferred data type.\n * @remarks See {@link injectInfiniteQuery} for examples that fetch further pages (from a button click or\n * automatically as the user scrolls) and that use `skipToken` to disable the query until `postId` is set.\n *\n * @example\n * A parameterized factory, so the same options object can be reused per `postId`:\n * ```angular-ts\n * import { infiniteQueryOptions, injectInfiniteQuery } from '@tanstack/angular-query-experimental'\n *\n * export const commentsOptions = (postId: string) =>\n *   infiniteQueryOptions({\n *     queryKey: ['post', postId, 'comments'],\n *     queryFn: ({ pageParam }) => fetchComments(postId, pageParam),\n *     initialPageParam: 0,\n *     getNextPageParam: (lastPage) => lastPage.nextId,\n *   })\n *\n * @Component({\n *   selector: 'comments',\n *   template: `\n *     @if (commentsQuery.isPending()) {\n *       Loading...\n *     } @else if (commentsQuery.isError()) {\n *       <span>Error: {{ commentsQuery.error()?.message }}</span>\n *     } @else {\n *       <ul>\n *         @for (page of commentsQuery.data().pages; track $index) {\n *           @for (comment of page.comments; track comment.id) {\n *             <li>{{ comment.text }}</li>\n *           }\n *         }\n *       </ul>\n *     }\n *   `,\n * })\n * export class Comments {\n *   readonly postId = signal('1')\n *   readonly commentsQuery = injectInfiniteQuery(() => commentsOptions(this.postId()))\n * }\n * ```\n *\n * @see {@link injectInfiniteQuery} to run an infinite query with these options.\n * @param options - The {@link UndefinedInitialDataInfiniteOptions} to use — everything you can pass to\n * `injectInfiniteQuery`.\n */\nexport function infiniteQueryOptions<\n  TQueryFnData,\n  TError = DefaultError,\n  TData = InfiniteData<TQueryFnData>,\n  TQueryKey extends QueryKey = QueryKey,\n  TPageParam = unknown,\n>(\n  options: UndefinedInitialDataInfiniteOptions<\n    TQueryFnData,\n    TError,\n    TData,\n    TQueryKey,\n    TPageParam\n  >,\n): UndefinedInitialDataInfiniteOptions<\n  TQueryFnData,\n  TError,\n  TData,\n  TQueryKey,\n  TPageParam\n> &\n  QueryKeyWithDataTag<TQueryKey, InfiniteData<TQueryFnData>, TError>\n\nexport function infiniteQueryOptions(options: unknown) {\n  return options\n}\n"],"names":[],"mappings":"AA+VO,SAAS,qBAAqB,SAAkB;AACrD,SAAO;AACT;"}