@tanstack/preact-query 5.103.1 → 5.103.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (113) hide show
  1. package/README.md +2 -2
  2. package/build/legacy/infiniteQueryOptions.cjs.map +1 -1
  3. package/build/legacy/infiniteQueryOptions.d.cts +1 -1
  4. package/build/legacy/infiniteQueryOptions.d.ts +1 -1
  5. package/build/legacy/infiniteQueryOptions.js.map +1 -1
  6. package/build/legacy/queryOptions.cjs.map +1 -1
  7. package/build/legacy/queryOptions.d.cts +3 -2
  8. package/build/legacy/queryOptions.d.cts.map +1 -1
  9. package/build/legacy/queryOptions.d.ts +3 -2
  10. package/build/legacy/queryOptions.d.ts.map +1 -1
  11. package/build/legacy/queryOptions.js.map +1 -1
  12. package/build/legacy/suspense.cjs.map +1 -1
  13. package/build/legacy/suspense.d.cts.map +1 -1
  14. package/build/legacy/suspense.d.ts.map +1 -1
  15. package/build/legacy/suspense.js.map +1 -1
  16. package/build/legacy/types.cjs.map +1 -1
  17. package/build/legacy/types.d.cts +5 -4
  18. package/build/legacy/types.d.cts.map +1 -1
  19. package/build/legacy/types.d.ts +5 -4
  20. package/build/legacy/types.d.ts.map +1 -1
  21. package/build/legacy/types.js.map +1 -1
  22. package/build/legacy/useBaseQuery.cjs.map +1 -1
  23. package/build/legacy/useBaseQuery.js.map +1 -1
  24. package/build/legacy/useQueries.cjs.map +1 -1
  25. package/build/legacy/useQueries.d.cts +6 -2
  26. package/build/legacy/useQueries.d.cts.map +1 -1
  27. package/build/legacy/useQueries.d.ts +6 -2
  28. package/build/legacy/useQueries.d.ts.map +1 -1
  29. package/build/legacy/useQueries.js.map +1 -1
  30. package/build/legacy/useQuery.cjs.map +1 -1
  31. package/build/legacy/useQuery.d.cts +7 -2
  32. package/build/legacy/useQuery.d.cts.map +1 -1
  33. package/build/legacy/useQuery.d.ts +7 -2
  34. package/build/legacy/useQuery.d.ts.map +1 -1
  35. package/build/legacy/useQuery.js.map +1 -1
  36. package/build/legacy/useSuspenseQueries.cjs.map +1 -1
  37. package/build/legacy/useSuspenseQueries.d.cts +7 -3
  38. package/build/legacy/useSuspenseQueries.d.cts.map +1 -1
  39. package/build/legacy/useSuspenseQueries.d.ts +7 -3
  40. package/build/legacy/useSuspenseQueries.d.ts.map +1 -1
  41. package/build/legacy/useSuspenseQueries.js.map +1 -1
  42. package/build/modern/infiniteQueryOptions.cjs.map +1 -1
  43. package/build/modern/infiniteQueryOptions.d.cts +1 -1
  44. package/build/modern/infiniteQueryOptions.d.ts +1 -1
  45. package/build/modern/infiniteQueryOptions.js.map +1 -1
  46. package/build/modern/queryOptions.cjs.map +1 -1
  47. package/build/modern/queryOptions.d.cts +3 -2
  48. package/build/modern/queryOptions.d.cts.map +1 -1
  49. package/build/modern/queryOptions.d.ts +3 -2
  50. package/build/modern/queryOptions.d.ts.map +1 -1
  51. package/build/modern/queryOptions.js.map +1 -1
  52. package/build/modern/suspense.cjs.map +1 -1
  53. package/build/modern/suspense.d.cts.map +1 -1
  54. package/build/modern/suspense.d.ts.map +1 -1
  55. package/build/modern/suspense.js.map +1 -1
  56. package/build/modern/types.cjs.map +1 -1
  57. package/build/modern/types.d.cts +5 -4
  58. package/build/modern/types.d.cts.map +1 -1
  59. package/build/modern/types.d.ts +5 -4
  60. package/build/modern/types.d.ts.map +1 -1
  61. package/build/modern/types.js.map +1 -1
  62. package/build/modern/useBaseQuery.cjs.map +1 -1
  63. package/build/modern/useBaseQuery.js.map +1 -1
  64. package/build/modern/useQueries.cjs.map +1 -1
  65. package/build/modern/useQueries.d.cts +6 -2
  66. package/build/modern/useQueries.d.cts.map +1 -1
  67. package/build/modern/useQueries.d.ts +6 -2
  68. package/build/modern/useQueries.d.ts.map +1 -1
  69. package/build/modern/useQueries.js.map +1 -1
  70. package/build/modern/useQuery.cjs.map +1 -1
  71. package/build/modern/useQuery.d.cts +7 -2
  72. package/build/modern/useQuery.d.cts.map +1 -1
  73. package/build/modern/useQuery.d.ts +7 -2
  74. package/build/modern/useQuery.d.ts.map +1 -1
  75. package/build/modern/useQuery.js.map +1 -1
  76. package/build/modern/useSuspenseQueries.cjs.map +1 -1
  77. package/build/modern/useSuspenseQueries.d.cts +7 -3
  78. package/build/modern/useSuspenseQueries.d.cts.map +1 -1
  79. package/build/modern/useSuspenseQueries.d.ts +7 -3
  80. package/build/modern/useSuspenseQueries.d.ts.map +1 -1
  81. package/build/modern/useSuspenseQueries.js.map +1 -1
  82. package/package.json +9 -10
  83. package/src/infiniteQueryOptions.ts +1 -1
  84. package/src/queryOptions.ts +4 -4
  85. package/src/suspense.ts +1 -2
  86. package/src/types.ts +5 -4
  87. package/src/useBaseQuery.ts +3 -6
  88. package/src/useQueries.ts +6 -2
  89. package/src/useQuery.ts +7 -2
  90. package/src/useSuspenseQueries.ts +7 -3
  91. package/build/query-codemods/eslint.config.js +0 -25
  92. package/build/query-codemods/package.json +0 -38
  93. package/build/query-codemods/root.eslint.config.js +0 -113
  94. package/build/query-codemods/tsconfig.json +0 -8
  95. package/build/query-codemods/vite.config.ts +0 -30
  96. /package/build/codemods/{src/utils → utils}/index.cjs +0 -0
  97. /package/build/codemods/{src/utils → utils}/transformers/query-cache-transformer.cjs +0 -0
  98. /package/build/codemods/{src/utils → utils}/transformers/query-client-transformer.cjs +0 -0
  99. /package/build/codemods/{src/utils → utils}/transformers/use-query-like-transformer.cjs +0 -0
  100. /package/build/codemods/{src/v4 → v4}/key-transformation.cjs +0 -0
  101. /package/build/codemods/{src/v4 → v4}/replace-import-specifier.cjs +0 -0
  102. /package/build/codemods/{src/v4 → v4}/utils/replacers/key-replacer.cjs +0 -0
  103. /package/build/codemods/{src/v5 → v5}/is-loading/is-loading.cjs +0 -0
  104. /package/build/codemods/{src/v5 → v5}/keep-previous-data/README.md +0 -0
  105. /package/build/codemods/{src/v5 → v5}/keep-previous-data/keep-previous-data.cjs +0 -0
  106. /package/build/codemods/{src/v5 → v5}/keep-previous-data/utils/already-has-placeholder-data-property.cjs +0 -0
  107. /package/build/codemods/{src/v5 → v5}/remove-overloads/remove-overloads.cjs +0 -0
  108. /package/build/codemods/{src/v5 → v5}/remove-overloads/transformers/filter-aware-usage-transformer.cjs +0 -0
  109. /package/build/codemods/{src/v5 → v5}/remove-overloads/transformers/query-fn-aware-usage-transformer.cjs +0 -0
  110. /package/build/codemods/{src/v5 → v5}/remove-overloads/utils/index.cjs +0 -0
  111. /package/build/codemods/{src/v5 → v5}/remove-overloads/utils/unknown-usage-error.cjs +0 -0
  112. /package/build/codemods/{src/v5 → v5}/rename-hydrate/rename-hydrate.cjs +0 -0
  113. /package/build/codemods/{src/v5 → v5}/rename-properties/rename-properties.cjs +0 -0
@@ -1 +1 @@
1
- {"version":3,"file":"types.js","names":[],"sources":["../../src/types.ts"],"sourcesContent":["/* istanbul ignore file */\nimport type {\n DefaultError,\n DefinedInfiniteQueryObserverResult,\n DefinedQueryObserverResult,\n DistributiveOmit,\n InfiniteData,\n InfiniteQueryExecuteOptions,\n InfiniteQueryObserverOptions,\n InfiniteQueryObserverResult,\n MutateFunction,\n MutationObserverOptions,\n MutationObserverResult,\n OmitKeyof,\n Override,\n QueryExecuteOptions,\n QueryKey,\n QueryObserverOptions,\n QueryObserverResult,\n SkipToken,\n} from '@tanstack/query-core'\n\n/**\n * {@link UseBaseQueryOptions} with all type parameters set to `any`, useful when the specific types aren't\n * relevant, e.g. when accepting options for any query in a helper function.\n */\nexport type AnyUseBaseQueryOptions = UseBaseQueryOptions<\n any,\n any,\n any,\n any,\n any\n>\n/**\n * The options shared by `useQuery` and `useSuspenseQuery`. Extends {@link QueryObserverOptions} from\n * `@tanstack/query-core` with the `preact-query`-specific `subscribed` option.\n *\n * @template TQueryFnData - The type your `queryFn` resolves to.\n * @template TError - The type of errors your `queryFn` may throw.\n * @template TData - The type `data` ends up as after `select` runs. Defaults to `TQueryFnData` when no\n * `select` is used.\n * @template TQueryData - The type of the data actually held in the query cache — the input to `select` and\n * `placeholderData`. Defaults to, and is usually the same as, `TQueryFnData`.\n * @template TQueryKey - The type of your `queryKey`.\n */\nexport interface UseBaseQueryOptions<\n TQueryFnData = unknown,\n TError = DefaultError,\n TData = TQueryFnData,\n TQueryData = TQueryFnData,\n TQueryKey extends QueryKey = QueryKey,\n> extends QueryObserverOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryData,\n TQueryKey\n> {\n /**\n * Set this to `false` to unsubscribe this observer from updates to the query cache.\n *\n * @defaultValue true\n */\n subscribed?: boolean\n}\n\n/**\n * The options accepted by `usePrefetchQuery` — everything you can pass to `queryClient.query`, except `queryFn`\n * is required unless a default query function has been defined.\n *\n * @template TQueryFnData - The type your `queryFn` resolves to.\n * @template TError - The type of errors your `queryFn` may throw.\n * @template TData - The type `data` ends up as after `select` runs. Defaults to `TQueryFnData` when no\n * `select` is used.\n * @template TQueryData - The type of the data actually held in the query cache — the input to `select` and\n * `placeholderData`. Defaults to, and is usually the same as, `TQueryFnData`.\n * @template TQueryKey - The type of your `queryKey`.\n */\nexport type UsePrefetchQueryOptions<\n TQueryFnData = unknown,\n TError = DefaultError,\n TData = TQueryFnData,\n TQueryData = TQueryFnData,\n TQueryKey extends QueryKey = QueryKey,\n> = DistributiveOmit<\n QueryExecuteOptions<TQueryFnData, TError, TData, TQueryData, TQueryKey>,\n 'queryFn'\n> & {\n /**\n * `skipToken` is not allowed as a value here — a prefetch always needs a query function to actually run,\n * unless a default query function has been defined.\n */\n queryFn?: Exclude<\n QueryExecuteOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryFnData,\n TQueryKey\n >['queryFn'],\n SkipToken\n >\n}\n\n/**\n * The options accepted by `usePrefetchInfiniteQuery` — everything you can pass to `queryClient.infiniteQuery`,\n * except `queryFn` is required unless a default query function has been defined.\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 `TQueryFnData` (a single page)\n * here, since a prefetch never reads `data` back out — this parameter only matters if you reuse these options\n * elsewhere with `select` applied.\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 UsePrefetchInfiniteQueryOptions<\n TQueryFnData = unknown,\n TError = DefaultError,\n TData = TQueryFnData,\n TQueryKey extends QueryKey = QueryKey,\n TPageParam = unknown,\n> = DistributiveOmit<\n InfiniteQueryExecuteOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryKey,\n TPageParam\n >,\n 'queryFn'\n> & {\n /**\n * `skipToken` is not allowed as a value here — a prefetch always needs a query function to actually run,\n * unless a default query function has been defined.\n */\n queryFn?: Exclude<\n InfiniteQueryExecuteOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryKey,\n TPageParam\n >['queryFn'],\n SkipToken\n >\n}\n\n/**\n * {@link UseQueryOptions} with all type parameters set to `any`, useful when the specific types aren't\n * relevant, e.g. when accepting options for any query in a helper function.\n */\nexport type AnyUseQueryOptions = UseQueryOptions<any, any, any, any>\n/**\n * The options accepted by `useQuery`. Same as {@link UseBaseQueryOptions}, minus `suspense` (which\n * `preact-query` derives from which hook you call rather than exposing as an option).\n *\n * @template TQueryFnData - The type your `queryFn` resolves to.\n * @template TError - The type of errors your `queryFn` may throw.\n * @template TData - The type `data` ends up as after `select` runs. Defaults to `TQueryFnData` when no\n * `select` is used.\n * @template TQueryKey - The type of your `queryKey`.\n */\nexport interface UseQueryOptions<\n TQueryFnData = unknown,\n TError = DefaultError,\n TData = TQueryFnData,\n TQueryKey extends QueryKey = QueryKey,\n> extends OmitKeyof<\n UseBaseQueryOptions<TQueryFnData, TError, TData, TQueryFnData, TQueryKey>,\n 'suspense'\n> {}\n\n/**\n * {@link UseSuspenseQueryOptions} with all type parameters set to `any`, useful when the specific types aren't\n * relevant, e.g. when accepting options for any query in a helper function.\n */\nexport type AnyUseSuspenseQueryOptions = UseSuspenseQueryOptions<\n any,\n any,\n any,\n any\n>\n/**\n * The options accepted by `useSuspenseQuery`. Same as {@link UseQueryOptions}, minus `enabled`, `throwOnError`,\n * and `placeholderData` — Suspense hooks cannot render a \"disabled\" or \"placeholder\" state, so those options\n * don't apply.\n *\n * @template TQueryFnData - The type your `queryFn` resolves to.\n * @template TError - The type of errors your `queryFn` may throw.\n * @template TData - The type `data` ends up as after `select` runs. Defaults to `TQueryFnData` when no\n * `select` is used.\n * @template TQueryKey - The type of your `queryKey`.\n */\nexport interface UseSuspenseQueryOptions<\n TQueryFnData = unknown,\n TError = DefaultError,\n TData = TQueryFnData,\n TQueryKey extends QueryKey = QueryKey,\n> extends OmitKeyof<\n UseQueryOptions<TQueryFnData, TError, TData, TQueryKey>,\n 'queryFn' | 'enabled' | 'throwOnError' | 'placeholderData'\n> {\n /**\n * `skipToken` is not allowed here — Suspense hooks cannot render a \"disabled\" state, so a query function\n * must always be provided, unless a default query function has been defined.\n */\n queryFn?: Exclude<\n UseQueryOptions<TQueryFnData, TError, TData, TQueryKey>['queryFn'],\n SkipToken\n >\n}\n\n/**\n * {@link UseInfiniteQueryOptions} with all type parameters set to `any`, useful when the specific types aren't\n * relevant, e.g. when accepting options for any query in a helper function.\n */\nexport type AnyUseInfiniteQueryOptions = UseInfiniteQueryOptions<\n any,\n any,\n any,\n any,\n any\n>\n/**\n * The options accepted by `useInfiniteQuery`. Extends {@link InfiniteQueryObserverOptions} from\n * `@tanstack/query-core` with the `preact-query`-specific `subscribed` option, minus `suspense` (which\n * `preact-query` derives from which hook you call rather than exposing as an option).\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 interface UseInfiniteQueryOptions<\n TQueryFnData = unknown,\n TError = DefaultError,\n TData = InfiniteData<TQueryFnData>,\n TQueryKey extends QueryKey = QueryKey,\n TPageParam = unknown,\n> extends OmitKeyof<\n InfiniteQueryObserverOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryKey,\n TPageParam\n >,\n 'suspense'\n> {\n /**\n * Set this to `false` to unsubscribe this observer from updates to the query cache.\n *\n * @defaultValue true\n */\n subscribed?: boolean\n}\n\n/**\n * {@link UseSuspenseInfiniteQueryOptions} with all type parameters set to `any`, useful when the specific types\n * aren't relevant, e.g. when accepting options for any query in a helper function.\n */\nexport type AnyUseSuspenseInfiniteQueryOptions =\n UseSuspenseInfiniteQueryOptions<any, any, any, any, any>\n/**\n * The options accepted by `useSuspenseInfiniteQuery`. Same as {@link UseInfiniteQueryOptions}, minus `enabled`,\n * `throwOnError`, and `placeholderData` — Suspense hooks cannot render a \"disabled\" or \"placeholder\" state, so\n * those options don't apply.\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 interface UseSuspenseInfiniteQueryOptions<\n TQueryFnData = unknown,\n TError = DefaultError,\n TData = InfiniteData<TQueryFnData>,\n TQueryKey extends QueryKey = QueryKey,\n TPageParam = unknown,\n> extends OmitKeyof<\n UseInfiniteQueryOptions<TQueryFnData, TError, TData, TQueryKey, TPageParam>,\n 'queryFn' | 'enabled' | 'throwOnError' | 'placeholderData'\n> {\n /**\n * `skipToken` is not allowed here — Suspense hooks cannot render a \"disabled\" state, so a query function\n * must always be provided, unless a default query function has been defined.\n */\n queryFn?: Exclude<\n UseInfiniteQueryOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryKey,\n TPageParam\n >['queryFn'],\n SkipToken\n >\n}\n\n/**\n * The result of `useQuery` when `initialData` isn't set — `data` may be `undefined` while the query is\n * `pending`. Re-exports {@link QueryObserverResult} from `@tanstack/query-core`. `useInfiniteQuery` returns\n * {@link UseInfiniteQueryResult} instead.\n *\n * @template TData - The type `data` ends up as after `select` runs.\n * @template TError - The type of errors your `queryFn` may throw.\n */\nexport type UseBaseQueryResult<\n TData = unknown,\n TError = DefaultError,\n> = QueryObserverResult<TData, TError>\n\n/**\n * The result of `useQuery`. Same as {@link UseBaseQueryResult}.\n *\n * @template TData - The type `data` ends up as after `select` runs.\n * @template TError - The type of errors your `queryFn` may throw.\n */\nexport type UseQueryResult<\n TData = unknown,\n TError = DefaultError,\n> = UseBaseQueryResult<TData, TError>\n\n/**\n * The result of `useSuspenseQuery`. Same as {@link DefinedUseQueryResult}, minus `isPlaceholderData` — always\n * `false` on that type, so this drops the dead field rather than an active state.\n *\n * @template TData - The type `data` ends up as after `select` runs.\n * @template TError - The type of errors your `queryFn` may throw.\n */\nexport type UseSuspenseQueryResult<\n TData = unknown,\n TError = DefaultError,\n> = DistributiveOmit<\n DefinedQueryObserverResult<TData, TError>,\n 'isPlaceholderData'\n>\n\n/**\n * The result of `useQuery` when `initialData` is set, or of `useSuspenseQuery` before the `isPlaceholderData`\n * omission — `data` is never `undefined`. Re-exports {@link DefinedQueryObserverResult} from\n * `@tanstack/query-core`.\n *\n * @template TData - The type `data` ends up as after `select` runs.\n * @template TError - The type of errors your `queryFn` may throw.\n */\nexport type DefinedUseQueryResult<\n TData = unknown,\n TError = DefaultError,\n> = DefinedQueryObserverResult<TData, TError>\n\n/**\n * The result of `useInfiniteQuery` when `initialData` isn't set — `data` may be `undefined` while the query is\n * `pending`. Re-exports {@link InfiniteQueryObserverResult} from `@tanstack/query-core`.\n *\n * @template TData - The type `data` ends up as after `select` runs.\n * @template TError - The type of errors your `queryFn` may throw.\n */\nexport type UseInfiniteQueryResult<\n TData = unknown,\n TError = DefaultError,\n> = InfiniteQueryObserverResult<TData, TError>\n\n/**\n * The result of `useInfiniteQuery` when `initialData` is set — `data` is never `undefined`. Re-exports\n * {@link DefinedInfiniteQueryObserverResult} from `@tanstack/query-core`.\n *\n * @template TData - The type `data` ends up as after `select` runs.\n * @template TError - The type of errors your `queryFn` may throw.\n */\nexport type DefinedUseInfiniteQueryResult<\n TData = unknown,\n TError = DefaultError,\n> = DefinedInfiniteQueryObserverResult<TData, TError>\n\n/**\n * The result of `useSuspenseInfiniteQuery`. Same as {@link DefinedUseInfiniteQueryResult}, minus\n * `isPlaceholderData` — Suspense hooks never render placeholder data.\n *\n * @template TData - The type `data` ends up as after `select` runs.\n * @template TError - The type of errors your `queryFn` may throw.\n */\nexport type UseSuspenseInfiniteQueryResult<\n TData = unknown,\n TError = DefaultError,\n> = OmitKeyof<\n DefinedInfiniteQueryObserverResult<TData, TError>,\n 'isPlaceholderData'\n>\n\n/**\n * {@link UseMutationOptions} with all type parameters set to `any`, useful when the specific types aren't\n * relevant, e.g. when accepting options for any mutation in a helper function.\n */\nexport type AnyUseMutationOptions = UseMutationOptions<any, any, any, any>\n/**\n * The options accepted by `useMutation`. Same as {@link MutationObserverOptions} from `@tanstack/query-core`,\n * minus the internal `_defaulted` flag.\n *\n * @template TData - The type your mutation function resolves to.\n * @template TError - The type of errors your mutation function may throw.\n * @template TVariables - The type of the variable passed to `mutate`/`mutateAsync`.\n * @template TOnMutateResult - The type returned by `onMutate`, passed to `onSuccess`/`onError`/`onSettled` as\n * their `onMutateResult` parameter — useful for optimistic-update rollback data.\n */\nexport interface UseMutationOptions<\n TData = unknown,\n TError = DefaultError,\n TVariables = void,\n TOnMutateResult = unknown,\n> extends OmitKeyof<\n MutationObserverOptions<TData, TError, TVariables, TOnMutateResult>,\n '_defaulted'\n> {}\n\n/**\n * The type of `mutate`, as returned by `useMutation`. Forwards the variables (and an optional per-call\n * `onSuccess`/`onError`/`onSettled`) to the underlying `mutate` call. Fire-and-forget — errors are surfaced\n * through the mutation result, not thrown.\n *\n * @template TData - The type your mutation function resolves to.\n * @template TError - The type of errors your mutation function may throw.\n * @template TVariables - The type of the variable passed to `mutate`.\n * @template TOnMutateResult - The type returned by `onMutate`, passed to `onSuccess`/`onError`/`onSettled` as\n * their `onMutateResult` parameter — useful for optimistic-update rollback data.\n */\nexport type UseMutateFunction<\n TData = unknown,\n TError = DefaultError,\n TVariables = void,\n TOnMutateResult = unknown,\n> = (\n ...args: Parameters<\n MutateFunction<TData, TError, TVariables, TOnMutateResult>\n >\n) => void\n\n/**\n * The type of `mutateAsync`, as returned by `useMutation`. Similar to {@link UseMutateFunction}, but returns a\n * promise which can be awaited.\n *\n * @template TData - The type your mutation function resolves to.\n * @template TError - The type of errors your mutation function may throw.\n * @template TVariables - The type of the variable passed to `mutateAsync`.\n * @template TOnMutateResult - The type returned by `onMutate`, passed to `onSuccess`/`onError`/`onSettled` as\n * their `onMutateResult` parameter — useful for optimistic-update rollback data.\n */\nexport type UseMutateAsyncFunction<\n TData = unknown,\n TError = DefaultError,\n TVariables = void,\n TOnMutateResult = unknown,\n> = MutateFunction<TData, TError, TVariables, TOnMutateResult>\n\n/**\n * The result of `useMutation`. Same as {@link MutationObserverResult} from `@tanstack/query-core`, with\n * `mutate` narrowed to the fire-and-forget {@link UseMutateFunction} signature, plus the added `mutateAsync`.\n *\n * @template TData - The type your mutation function resolves to.\n * @template TError - The type of errors your mutation function may throw.\n * @template TVariables - The type of the variable passed to `mutate`/`mutateAsync`.\n * @template TOnMutateResult - The type returned by `onMutate`, passed to `onSuccess`/`onError`/`onSettled` as\n * their `onMutateResult` parameter — useful for optimistic-update rollback data.\n */\nexport type UseBaseMutationResult<\n TData = unknown,\n TError = DefaultError,\n TVariables = unknown,\n TOnMutateResult = unknown,\n> = Override<\n MutationObserverResult<TData, TError, TVariables, TOnMutateResult>,\n { mutate: UseMutateFunction<TData, TError, TVariables, TOnMutateResult> }\n> & {\n /**\n * Similar to `mutate`, but returns a promise which can be awaited.\n */\n mutateAsync: UseMutateAsyncFunction<\n TData,\n TError,\n TVariables,\n TOnMutateResult\n >\n}\n\n/**\n * The result of `useMutation`. Same as {@link UseBaseMutationResult}.\n *\n * @template TData - The type your mutation function resolves to.\n * @template TError - The type of errors your mutation function may throw.\n * @template TVariables - The type of the variable passed to `mutate`/`mutateAsync`.\n * @template TOnMutateResult - The type returned by `onMutate`, passed to `onSuccess`/`onError`/`onSettled` as\n * their `onMutateResult` parameter — useful for optimistic-update rollback data.\n */\nexport type UseMutationResult<\n TData = unknown,\n TError = DefaultError,\n TVariables = unknown,\n TOnMutateResult = unknown,\n> = UseBaseMutationResult<TData, TError, TVariables, TOnMutateResult>\n"],"mappings":""}
1
+ {"version":3,"file":"types.js","names":[],"sources":["../../src/types.ts"],"sourcesContent":["/* istanbul ignore file */\nimport type {\n DefaultError,\n DefinedInfiniteQueryObserverResult,\n DefinedQueryObserverResult,\n DistributiveOmit,\n InfiniteData,\n InfiniteQueryExecuteOptions,\n InfiniteQueryObserverOptions,\n InfiniteQueryObserverResult,\n MutateFunction,\n MutationObserverOptions,\n MutationObserverResult,\n OmitKeyof,\n Override,\n QueryExecuteOptions,\n QueryKey,\n QueryObserverOptions,\n QueryObserverResult,\n SkipToken,\n} from '@tanstack/query-core'\n\n/**\n * {@link UseBaseQueryOptions} with all type parameters set to `any`, useful when the specific types aren't\n * relevant, e.g. when accepting options for any query in a helper function.\n */\nexport type AnyUseBaseQueryOptions = UseBaseQueryOptions<\n any,\n any,\n any,\n any,\n any\n>\n/**\n * The options shared by `useQuery` and `useSuspenseQuery`. Extends {@link QueryObserverOptions} from\n * `@tanstack/query-core` with the `preact-query`-specific `subscribed` option.\n *\n * @template TQueryFnData - The type your `queryFn` resolves to.\n * @template TError - The type of errors your `queryFn` may throw.\n * @template TData - The type `data` ends up as after `select` runs. Defaults to `TQueryFnData` when no\n * `select` is used.\n * @template TQueryData - The type of the data actually held in the query cache — the input to `select` and\n * `placeholderData`. Defaults to, and is usually the same as, `TQueryFnData`.\n * @template TQueryKey - The type of your `queryKey`.\n */\nexport interface UseBaseQueryOptions<\n TQueryFnData = unknown,\n TError = DefaultError,\n TData = TQueryFnData,\n TQueryData = TQueryFnData,\n TQueryKey extends QueryKey = QueryKey,\n> extends QueryObserverOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryData,\n TQueryKey\n> {\n /**\n * Set this to `false` to unsubscribe this observer from updates to the query cache.\n *\n * @defaultValue true\n */\n subscribed?: boolean\n}\n\n/**\n * The options accepted by `usePrefetchQuery` — everything you can pass to `queryClient.query`, except `queryFn`\n * is required unless a default query function has been defined.\n *\n * @template TQueryFnData - The type your `queryFn` resolves to.\n * @template TError - The type of errors your `queryFn` may throw.\n * @template TData - The type `data` ends up as after `select` runs. Defaults to `TQueryFnData` when no\n * `select` is used.\n * @template TQueryData - The type of the data actually held in the query cache — the input to `select` and\n * `placeholderData`. Defaults to, and is usually the same as, `TQueryFnData`.\n * @template TQueryKey - The type of your `queryKey`.\n */\nexport type UsePrefetchQueryOptions<\n TQueryFnData = unknown,\n TError = DefaultError,\n TData = TQueryFnData,\n TQueryData = TQueryFnData,\n TQueryKey extends QueryKey = QueryKey,\n> = DistributiveOmit<\n QueryExecuteOptions<TQueryFnData, TError, TData, TQueryData, TQueryKey>,\n 'queryFn'\n> & {\n /**\n * `skipToken` is not allowed as a value here — a prefetch always needs a query function to actually run,\n * unless a default query function has been defined.\n */\n queryFn?: Exclude<\n QueryExecuteOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryFnData,\n TQueryKey\n >['queryFn'],\n SkipToken\n >\n}\n\n/**\n * The options accepted by `usePrefetchInfiniteQuery` — everything you can pass to `queryClient.infiniteQuery`,\n * except `queryFn` is required unless a default query function has been defined.\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 `TQueryFnData` (a single page)\n * here, since a prefetch never reads `data` back out — this parameter only matters if you reuse these options\n * elsewhere with `select` applied.\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 UsePrefetchInfiniteQueryOptions<\n TQueryFnData = unknown,\n TError = DefaultError,\n TData = TQueryFnData,\n TQueryKey extends QueryKey = QueryKey,\n TPageParam = unknown,\n> = DistributiveOmit<\n InfiniteQueryExecuteOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryKey,\n TPageParam\n >,\n 'queryFn'\n> & {\n /**\n * `skipToken` is not allowed as a value here — a prefetch always needs a query function to actually run,\n * unless a default query function has been defined.\n */\n queryFn?: Exclude<\n InfiniteQueryExecuteOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryKey,\n TPageParam\n >['queryFn'],\n SkipToken\n >\n}\n\n/**\n * {@link UseQueryOptions} with all type parameters set to `any`, useful when the specific types aren't\n * relevant, e.g. when accepting options for any query in a helper function.\n */\nexport type AnyUseQueryOptions = UseQueryOptions<any, any, any, any>\n/**\n * The options accepted by `useQuery`. Same as {@link UseBaseQueryOptions}, minus `suspense` (which\n * `preact-query` derives from which hook you call rather than exposing as an option).\n *\n * @template TQueryFnData - The type your `queryFn` resolves to.\n * @template TError - The type of errors your `queryFn` may throw.\n * @template TData - The type `data` ends up as after `select` runs. Defaults to `TQueryFnData` when no\n * `select` is used.\n * @template TQueryKey - The type of your `queryKey`.\n */\nexport interface UseQueryOptions<\n TQueryFnData = unknown,\n TError = DefaultError,\n TData = TQueryFnData,\n TQueryKey extends QueryKey = QueryKey,\n> extends OmitKeyof<\n UseBaseQueryOptions<TQueryFnData, TError, TData, TQueryFnData, TQueryKey>,\n 'suspense'\n> {}\n\n/**\n * {@link UseSuspenseQueryOptions} with all type parameters set to `any`, useful when the specific types aren't\n * relevant, e.g. when accepting options for any query in a helper function.\n */\nexport type AnyUseSuspenseQueryOptions = UseSuspenseQueryOptions<\n any,\n any,\n any,\n any\n>\n/**\n * The options accepted by `useSuspenseQuery`. Same as {@link UseQueryOptions}, minus `enabled`, `throwOnError`,\n * and `placeholderData` — Suspense hooks cannot render a \"disabled\" or \"placeholder\" state, so those options\n * don't apply.\n *\n * @template TQueryFnData - The type your `queryFn` resolves to.\n * @template TError - The type of errors your `queryFn` may throw.\n * @template TData - The type `data` ends up as after `select` runs. Defaults to `TQueryFnData` when no\n * `select` is used.\n * @template TQueryKey - The type of your `queryKey`.\n */\nexport interface UseSuspenseQueryOptions<\n TQueryFnData = unknown,\n TError = DefaultError,\n TData = TQueryFnData,\n TQueryKey extends QueryKey = QueryKey,\n> extends OmitKeyof<\n UseQueryOptions<TQueryFnData, TError, TData, TQueryKey>,\n 'queryFn' | 'enabled' | 'throwOnError' | 'placeholderData'\n> {\n /**\n * `skipToken` is not allowed here — Suspense hooks cannot render a \"disabled\" state, so a query function\n * must always be provided, unless a default query function has been defined.\n */\n queryFn?: Exclude<\n UseQueryOptions<TQueryFnData, TError, TData, TQueryKey>['queryFn'],\n SkipToken\n >\n}\n\n/**\n * {@link UseInfiniteQueryOptions} with all type parameters set to `any`, useful when the specific types aren't\n * relevant, e.g. when accepting options for any query in a helper function.\n */\nexport type AnyUseInfiniteQueryOptions = UseInfiniteQueryOptions<\n any,\n any,\n any,\n any,\n any\n>\n/**\n * The options accepted by `useInfiniteQuery`. Extends {@link InfiniteQueryObserverOptions} from\n * `@tanstack/query-core` with the `preact-query`-specific `subscribed` option, minus `suspense` (which\n * `preact-query` derives from which hook you call rather than exposing as an option).\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 interface UseInfiniteQueryOptions<\n TQueryFnData = unknown,\n TError = DefaultError,\n TData = InfiniteData<TQueryFnData>,\n TQueryKey extends QueryKey = QueryKey,\n TPageParam = unknown,\n> extends OmitKeyof<\n InfiniteQueryObserverOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryKey,\n TPageParam\n >,\n 'suspense'\n> {\n /**\n * Set this to `false` to unsubscribe this observer from updates to the query cache.\n *\n * @defaultValue true\n */\n subscribed?: boolean\n}\n\n/**\n * {@link UseSuspenseInfiniteQueryOptions} with all type parameters set to `any`, useful when the specific types\n * aren't relevant, e.g. when accepting options for any query in a helper function.\n */\nexport type AnyUseSuspenseInfiniteQueryOptions =\n UseSuspenseInfiniteQueryOptions<any, any, any, any, any>\n/**\n * The options accepted by `useSuspenseInfiniteQuery`. Same as {@link UseInfiniteQueryOptions}, minus `enabled`,\n * `throwOnError`, and `placeholderData` — Suspense hooks cannot render a \"disabled\" or \"placeholder\" state, so\n * those options don't apply.\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 interface UseSuspenseInfiniteQueryOptions<\n TQueryFnData = unknown,\n TError = DefaultError,\n TData = InfiniteData<TQueryFnData>,\n TQueryKey extends QueryKey = QueryKey,\n TPageParam = unknown,\n> extends OmitKeyof<\n UseInfiniteQueryOptions<TQueryFnData, TError, TData, TQueryKey, TPageParam>,\n 'queryFn' | 'enabled' | 'throwOnError' | 'placeholderData'\n> {\n /**\n * `skipToken` is not allowed here — Suspense hooks cannot render a \"disabled\" state, so a query function\n * must always be provided, unless a default query function has been defined.\n */\n queryFn?: Exclude<\n UseInfiniteQueryOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryKey,\n TPageParam\n >['queryFn'],\n SkipToken\n >\n}\n\n/**\n * The result of `useQuery` when `initialData` isn't set — `data` may be `undefined` while the query is\n * `pending`. Re-exports {@link QueryObserverResult} from `@tanstack/query-core`. `useInfiniteQuery` returns\n * {@link UseInfiniteQueryResult} instead.\n *\n * @template TData - The type `data` ends up as after `select` runs.\n * @template TError - The type of errors your `queryFn` may throw.\n */\nexport type UseBaseQueryResult<\n TData = unknown,\n TError = DefaultError,\n> = QueryObserverResult<TData, TError>\n\n/**\n * The result of `useQuery`. Same as {@link UseBaseQueryResult}.\n *\n * @template TData - The type `data` ends up as after `select` runs.\n * @template TError - The type of errors your `queryFn` may throw.\n */\nexport type UseQueryResult<\n TData = unknown,\n TError = DefaultError,\n> = UseBaseQueryResult<TData, TError>\n\n/**\n * The result of `useSuspenseQuery`. Same as {@link DefinedUseQueryResult}, minus `isPlaceholderData` — always\n * `false` on that type, so this drops the dead field rather than an active state.\n *\n * @template TData - The type `data` ends up as after `select` runs.\n * @template TError - The type of errors your `queryFn` may throw.\n */\nexport type UseSuspenseQueryResult<\n TData = unknown,\n TError = DefaultError,\n> = DistributiveOmit<\n DefinedQueryObserverResult<TData, TError>,\n 'isPlaceholderData'\n>\n\n/**\n * The result of `useQuery` when `initialData` is set, or of `useSuspenseQuery` before the `isPlaceholderData`\n * omission — `data` is never `undefined` (unless a `select` changes `TData` to include `undefined`).\n * Re-exports {@link DefinedQueryObserverResult} from `@tanstack/query-core`.\n *\n * @template TData - The type `data` ends up as after `select` runs.\n * @template TError - The type of errors your `queryFn` may throw.\n */\nexport type DefinedUseQueryResult<\n TData = unknown,\n TError = DefaultError,\n> = DefinedQueryObserverResult<TData, TError>\n\n/**\n * The result of `useInfiniteQuery` when `initialData` isn't set — `data` may be `undefined` while the query is\n * `pending`. Re-exports {@link InfiniteQueryObserverResult} from `@tanstack/query-core`.\n *\n * @template TData - The type `data` ends up as after `select` runs.\n * @template TError - The type of errors your `queryFn` may throw.\n */\nexport type UseInfiniteQueryResult<\n TData = unknown,\n TError = DefaultError,\n> = InfiniteQueryObserverResult<TData, TError>\n\n/**\n * The result of `useInfiniteQuery` when `initialData` is set — `data` is never `undefined` (unless a\n * `select` changes `TData` to include `undefined`). Re-exports {@link DefinedInfiniteQueryObserverResult}\n * from `@tanstack/query-core`.\n *\n * @template TData - The type `data` ends up as after `select` runs.\n * @template TError - The type of errors your `queryFn` may throw.\n */\nexport type DefinedUseInfiniteQueryResult<\n TData = unknown,\n TError = DefaultError,\n> = DefinedInfiniteQueryObserverResult<TData, TError>\n\n/**\n * The result of `useSuspenseInfiniteQuery`. Same as {@link DefinedUseInfiniteQueryResult}, minus\n * `isPlaceholderData` — Suspense hooks never render placeholder data.\n *\n * @template TData - The type `data` ends up as after `select` runs.\n * @template TError - The type of errors your `queryFn` may throw.\n */\nexport type UseSuspenseInfiniteQueryResult<\n TData = unknown,\n TError = DefaultError,\n> = OmitKeyof<\n DefinedInfiniteQueryObserverResult<TData, TError>,\n 'isPlaceholderData'\n>\n\n/**\n * {@link UseMutationOptions} with all type parameters set to `any`, useful when the specific types aren't\n * relevant, e.g. when accepting options for any mutation in a helper function.\n */\nexport type AnyUseMutationOptions = UseMutationOptions<any, any, any, any>\n/**\n * The options accepted by `useMutation`. Same as {@link MutationObserverOptions} from `@tanstack/query-core`,\n * minus the internal `_defaulted` flag.\n *\n * @template TData - The type your mutation function resolves to.\n * @template TError - The type of errors your mutation function may throw.\n * @template TVariables - The type of the variable passed to `mutate`/`mutateAsync`.\n * @template TOnMutateResult - The type returned by `onMutate`, passed to `onSuccess`/`onError`/`onSettled` as\n * their `onMutateResult` parameter — useful for optimistic-update rollback data.\n */\nexport interface UseMutationOptions<\n TData = unknown,\n TError = DefaultError,\n TVariables = void,\n TOnMutateResult = unknown,\n> extends OmitKeyof<\n MutationObserverOptions<TData, TError, TVariables, TOnMutateResult>,\n '_defaulted'\n> {}\n\n/**\n * The type of `mutate`, as returned by `useMutation`. Forwards the variables (and an optional per-call\n * `onSuccess`/`onError`/`onSettled`) to the underlying `mutate` call. Fire-and-forget — errors are surfaced\n * through the mutation result, not thrown.\n *\n * @template TData - The type your mutation function resolves to.\n * @template TError - The type of errors your mutation function may throw.\n * @template TVariables - The type of the variable passed to `mutate`.\n * @template TOnMutateResult - The type returned by `onMutate`, passed to `onSuccess`/`onError`/`onSettled` as\n * their `onMutateResult` parameter — useful for optimistic-update rollback data.\n */\nexport type UseMutateFunction<\n TData = unknown,\n TError = DefaultError,\n TVariables = void,\n TOnMutateResult = unknown,\n> = (\n ...args: Parameters<\n MutateFunction<TData, TError, TVariables, TOnMutateResult>\n >\n) => void\n\n/**\n * The type of `mutateAsync`, as returned by `useMutation`. Similar to {@link UseMutateFunction}, but returns a\n * promise which can be awaited.\n *\n * @template TData - The type your mutation function resolves to.\n * @template TError - The type of errors your mutation function may throw.\n * @template TVariables - The type of the variable passed to `mutateAsync`.\n * @template TOnMutateResult - The type returned by `onMutate`, passed to `onSuccess`/`onError`/`onSettled` as\n * their `onMutateResult` parameter — useful for optimistic-update rollback data.\n */\nexport type UseMutateAsyncFunction<\n TData = unknown,\n TError = DefaultError,\n TVariables = void,\n TOnMutateResult = unknown,\n> = MutateFunction<TData, TError, TVariables, TOnMutateResult>\n\n/**\n * The result of `useMutation`. Same as {@link MutationObserverResult} from `@tanstack/query-core`, with\n * `mutate` narrowed to the fire-and-forget {@link UseMutateFunction} signature, plus the added `mutateAsync`.\n *\n * @template TData - The type your mutation function resolves to.\n * @template TError - The type of errors your mutation function may throw.\n * @template TVariables - The type of the variable passed to `mutate`/`mutateAsync`.\n * @template TOnMutateResult - The type returned by `onMutate`, passed to `onSuccess`/`onError`/`onSettled` as\n * their `onMutateResult` parameter — useful for optimistic-update rollback data.\n */\nexport type UseBaseMutationResult<\n TData = unknown,\n TError = DefaultError,\n TVariables = unknown,\n TOnMutateResult = unknown,\n> = Override<\n MutationObserverResult<TData, TError, TVariables, TOnMutateResult>,\n { mutate: UseMutateFunction<TData, TError, TVariables, TOnMutateResult> }\n> & {\n /**\n * Similar to `mutate`, but returns a promise which can be awaited.\n */\n mutateAsync: UseMutateAsyncFunction<\n TData,\n TError,\n TVariables,\n TOnMutateResult\n >\n}\n\n/**\n * The result of `useMutation`. Same as {@link UseBaseMutationResult}.\n *\n * @template TData - The type your mutation function resolves to.\n * @template TError - The type of errors your mutation function may throw.\n * @template TVariables - The type of the variable passed to `mutate`/`mutateAsync`.\n * @template TOnMutateResult - The type returned by `onMutate`, passed to `onSuccess`/`onError`/`onSettled` as\n * their `onMutateResult` parameter — useful for optimistic-update rollback data.\n */\nexport type UseMutationResult<\n TData = unknown,\n TError = DefaultError,\n TVariables = unknown,\n TOnMutateResult = unknown,\n> = UseBaseMutationResult<TData, TError, TVariables, TOnMutateResult>\n"],"mappings":""}
@@ -1 +1 @@
1
- {"version":3,"file":"useBaseQuery.cjs","names":["useIsRestoring","useQueryErrorResetBoundary","useQueryClient","useState","useCallback","notifyManager","noop","shouldSuspend","fetchOptimistic","getHasError"],"sources":["../../src/useBaseQuery.ts"],"sourcesContent":["import { noop, notifyManager } from '@tanstack/query-core'\nimport type {\n QueryClient,\n QueryKey,\n QueryObserver,\n QueryObserverResult,\n} from '@tanstack/query-core'\nimport { useCallback, useEffect, useState } from 'preact/hooks'\n\nimport { useIsRestoring } from './IsRestoringProvider'\nimport { useQueryClient } from './QueryClientProvider'\nimport { useQueryErrorResetBoundary } from './QueryErrorResetBoundary'\nimport {\n ensurePreventErrorBoundaryRetry,\n getHasError,\n useClearResetErrorBoundary,\n} from './errorBoundaryUtils'\nimport {\n ensureSuspenseTimers,\n fetchOptimistic,\n shouldSuspend,\n} from './suspense'\nimport type { UseBaseQueryOptions } from './types'\nimport { useSyncExternalStore } from './utils'\n\nexport function useBaseQuery<\n TQueryFnData,\n TError,\n TData,\n TQueryData,\n TQueryKey extends QueryKey,\n>(\n options: UseBaseQueryOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryData,\n TQueryKey\n >,\n Observer: typeof QueryObserver,\n queryClient?: QueryClient,\n): QueryObserverResult<TData, TError> {\n if (process.env.NODE_ENV !== 'production') {\n if (typeof options !== 'object' || Array.isArray(options)) {\n throw new Error(\n 'Bad argument type. Starting with v5, only the \"Object\" form is allowed when calling query related functions. Please use the error stack to find the culprit call. More info here: https://tanstack.com/query/latest/docs/react/guides/migrating-to-v5#supports-a-single-signature-one-object',\n )\n }\n }\n\n const isRestoring = useIsRestoring()\n const errorResetBoundary = useQueryErrorResetBoundary()\n const client = useQueryClient(queryClient)\n const defaultedOptions = client.defaultQueryOptions(options)\n\n const query = client\n .getQueryCache()\n .get<\n TQueryFnData,\n TError,\n TQueryData,\n TQueryKey\n >(defaultedOptions.queryHash)\n\n if (process.env.NODE_ENV !== 'production') {\n if (!defaultedOptions.queryFn) {\n console.error(\n `[${defaultedOptions.queryHash}]: No queryFn was passed as an option, and no default queryFn was found. The queryFn parameter is only optional when using a default queryFn. More info here: https://tanstack.com/query/latest/docs/framework/react/guides/default-query-function`,\n )\n }\n }\n\n // Make sure results are optimistically set in fetching state before subscribing or updating options\n defaultedOptions._optimisticResults = isRestoring\n ? 'isRestoring'\n : 'optimistic'\n\n ensureSuspenseTimers(defaultedOptions)\n ensurePreventErrorBoundaryRetry(defaultedOptions, errorResetBoundary, query)\n\n useClearResetErrorBoundary(errorResetBoundary)\n\n const [observer] = useState(\n () =>\n new Observer<TQueryFnData, TError, TData, TQueryData, TQueryKey>(\n client,\n defaultedOptions,\n ),\n )\n\n // note: this must be called before useSyncExternalStore\n const result = observer.getOptimisticResult(defaultedOptions)\n\n const shouldSubscribe = !isRestoring && options.subscribed !== false\n useSyncExternalStore(\n useCallback(\n (onStoreChange) => {\n const unsubscribe = shouldSubscribe\n ? observer.subscribe(notifyManager.batchCalls(onStoreChange))\n : noop\n\n // Update result to make sure we did not miss any query updates\n // between creating the observer and subscribing to it.\n observer.updateResult()\n\n return unsubscribe\n },\n [observer, shouldSubscribe],\n ),\n () => observer.getCurrentResult(),\n )\n\n useEffect(() => {\n observer.setOptions(defaultedOptions)\n }, [defaultedOptions, observer])\n\n // Handle suspense\n if (shouldSuspend(defaultedOptions, result)) {\n throw fetchOptimistic(defaultedOptions, observer, errorResetBoundary)\n }\n\n // Handle error boundary\n if (\n getHasError({\n result,\n errorResetBoundary,\n throwOnError: defaultedOptions.throwOnError,\n query,\n suspense: defaultedOptions.suspense,\n })\n ) {\n throw result.error\n }\n\n // Handle result property usage tracking\n return !defaultedOptions.notifyOnChangeProps\n ? observer.trackResult(result)\n : result\n}\n"],"mappings":";;;;;;;;;;AAyBA,SAAgB,aAOd,SAOA,UACA,aACoC;CACpC,IAAI,QAAQ,IAAI,aAAa,cACvB;MAAA,OAAO,YAAY,YAAY,MAAM,QAAQ,OAAO,GACtD,MAAM,IAAI,MACR,gSACF;CAAA;CAIJ,MAAM,cAAcA,4BAAAA,eAAe;CACnC,MAAM,qBAAqBC,gCAAAA,2BAA2B;CACtD,MAAM,SAASC,4BAAAA,eAAe,WAAW;CACzC,MAAM,mBAAmB,OAAO,oBAAoB,OAAO;CAE3D,MAAM,QAAQ,OACX,cAAc,CAAC,CACf,IAKC,iBAAiB,SAAS;CAE9B,IAAI,QAAQ,IAAI,aAAa,cACvB;MAAA,CAAC,iBAAiB,SACpB,QAAQ,MACN,IAAI,iBAAiB,UAAU,mPACjC;CAAA;CAKJ,iBAAiB,qBAAqB,cAClC,gBACA;CAEJ,iBAAA,qBAAqB,gBAAgB;CACrC,2BAAA,gCAAgC,kBAAkB,oBAAoB,KAAK;CAE3E,2BAAA,2BAA2B,kBAAkB;CAE7C,MAAM,CAAC,aAAA,GAAYC,aAAAA,SAAAA,OAEf,IAAI,SACF,QACA,gBACF,CACJ;CAGA,MAAM,SAAS,SAAS,oBAAoB,gBAAgB;CAE5D,MAAM,kBAAkB,CAAC,eAAe,QAAQ,eAAe;CAC/D,cAAA,sBAAA,GACEC,aAAAA,YAAAA,EACG,kBAAkB;EACjB,MAAM,cAAc,kBAChB,SAAS,UAAUC,qBAAAA,cAAc,WAAW,aAAa,CAAC,IAC1DC,qBAAAA;EAIJ,SAAS,aAAa;EAEtB,OAAO;CACT,GACA,CAAC,UAAU,eAAe,CAC5B,SACM,SAAS,iBAAiB,CAClC;CAEA,CAAA,GAAA,aAAA,UAAA,OAAgB;EACd,SAAS,WAAW,gBAAgB;CACtC,GAAG,CAAC,kBAAkB,QAAQ,CAAC;CAG/B,IAAIC,iBAAAA,cAAc,kBAAkB,MAAM,GACxC,MAAMC,iBAAAA,gBAAgB,kBAAkB,UAAU,kBAAkB;CAItE,IACEC,2BAAAA,YAAY;EACV;EACA;EACA,cAAc,iBAAiB;EAC/B;EACA,UAAU,iBAAiB;CAC7B,CAAC,GAED,MAAM,OAAO;CAIf,OAAO,CAAC,iBAAiB,sBACrB,SAAS,YAAY,MAAM,IAC3B;AACN"}
1
+ {"version":3,"file":"useBaseQuery.cjs","names":["useIsRestoring","useQueryErrorResetBoundary","useQueryClient","useState","useCallback","notifyManager","noop","shouldSuspend","fetchOptimistic","getHasError"],"sources":["../../src/useBaseQuery.ts"],"sourcesContent":["import { noop, notifyManager } from '@tanstack/query-core'\nimport type {\n QueryClient,\n QueryKey,\n QueryObserver,\n QueryObserverResult,\n} from '@tanstack/query-core'\nimport { useCallback, useEffect, useState } from 'preact/hooks'\n\nimport { useIsRestoring } from './IsRestoringProvider'\nimport { useQueryClient } from './QueryClientProvider'\nimport { useQueryErrorResetBoundary } from './QueryErrorResetBoundary'\nimport {\n ensurePreventErrorBoundaryRetry,\n getHasError,\n useClearResetErrorBoundary,\n} from './errorBoundaryUtils'\nimport {\n ensureSuspenseTimers,\n fetchOptimistic,\n shouldSuspend,\n} from './suspense'\nimport type { UseBaseQueryOptions } from './types'\nimport { useSyncExternalStore } from './utils'\n\nexport function useBaseQuery<\n TQueryFnData,\n TError,\n TData,\n TQueryData,\n TQueryKey extends QueryKey,\n>(\n options: UseBaseQueryOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryData,\n TQueryKey\n >,\n Observer: typeof QueryObserver,\n queryClient?: QueryClient,\n): QueryObserverResult<TData, TError> {\n if (process.env.NODE_ENV !== 'production') {\n if (typeof options !== 'object' || Array.isArray(options)) {\n throw new Error(\n 'Bad argument type. Starting with v5, only the \"Object\" form is allowed when calling query related functions. Please use the error stack to find the culprit call. More info here: https://tanstack.com/query/latest/docs/react/guides/migrating-to-v5#supports-a-single-signature-one-object',\n )\n }\n }\n\n const isRestoring = useIsRestoring()\n const errorResetBoundary = useQueryErrorResetBoundary()\n const client = useQueryClient(queryClient)\n const defaultedOptions = client.defaultQueryOptions(options)\n\n const query = client\n .getQueryCache()\n .get<TQueryFnData, TError, TQueryData, TQueryKey>(\n defaultedOptions.queryHash,\n )\n\n if (process.env.NODE_ENV !== 'production') {\n if (!defaultedOptions.queryFn) {\n console.error(\n `[${defaultedOptions.queryHash}]: No queryFn was passed as an option, and no default queryFn was found. The queryFn parameter is only optional when using a default queryFn. More info here: https://tanstack.com/query/latest/docs/framework/react/guides/default-query-function`,\n )\n }\n }\n\n // Make sure results are optimistically set in fetching state before subscribing or updating options\n defaultedOptions._optimisticResults = isRestoring\n ? 'isRestoring'\n : 'optimistic'\n\n ensureSuspenseTimers(defaultedOptions)\n ensurePreventErrorBoundaryRetry(defaultedOptions, errorResetBoundary, query)\n\n useClearResetErrorBoundary(errorResetBoundary)\n\n const [observer] = useState(\n () =>\n new Observer<TQueryFnData, TError, TData, TQueryData, TQueryKey>(\n client,\n defaultedOptions,\n ),\n )\n\n // note: this must be called before useSyncExternalStore\n const result = observer.getOptimisticResult(defaultedOptions)\n\n const shouldSubscribe = !isRestoring && options.subscribed !== false\n useSyncExternalStore(\n useCallback(\n (onStoreChange) => {\n const unsubscribe = shouldSubscribe\n ? observer.subscribe(notifyManager.batchCalls(onStoreChange))\n : noop\n\n // Update result to make sure we did not miss any query updates\n // between creating the observer and subscribing to it.\n observer.updateResult()\n\n return unsubscribe\n },\n [observer, shouldSubscribe],\n ),\n () => observer.getCurrentResult(),\n )\n\n useEffect(() => {\n observer.setOptions(defaultedOptions)\n }, [defaultedOptions, observer])\n\n // Handle suspense\n if (shouldSuspend(defaultedOptions, result)) {\n throw fetchOptimistic(defaultedOptions, observer, errorResetBoundary)\n }\n\n // Handle error boundary\n if (\n getHasError({\n result,\n errorResetBoundary,\n throwOnError: defaultedOptions.throwOnError,\n query,\n suspense: defaultedOptions.suspense,\n })\n ) {\n throw result.error\n }\n\n // Handle result property usage tracking\n return !defaultedOptions.notifyOnChangeProps\n ? observer.trackResult(result)\n : result\n}\n"],"mappings":";;;;;;;;;;AAyBA,SAAgB,aAOd,SAOA,UACA,aACoC;CACpC,IAAI,QAAQ,IAAI,aAAa,cACvB;MAAA,OAAO,YAAY,YAAY,MAAM,QAAQ,OAAO,GACtD,MAAM,IAAI,MACR,gSACF;CAAA;CAIJ,MAAM,cAAcA,4BAAAA,eAAe;CACnC,MAAM,qBAAqBC,gCAAAA,2BAA2B;CACtD,MAAM,SAASC,4BAAAA,eAAe,WAAW;CACzC,MAAM,mBAAmB,OAAO,oBAAoB,OAAO;CAE3D,MAAM,QAAQ,OACX,cAAc,CAAC,CACf,IACC,iBAAiB,SACnB;CAEF,IAAI,QAAQ,IAAI,aAAa,cACvB;MAAA,CAAC,iBAAiB,SACpB,QAAQ,MACN,IAAI,iBAAiB,UAAU,mPACjC;CAAA;CAKJ,iBAAiB,qBAAqB,cAClC,gBACA;CAEJ,iBAAA,qBAAqB,gBAAgB;CACrC,2BAAA,gCAAgC,kBAAkB,oBAAoB,KAAK;CAE3E,2BAAA,2BAA2B,kBAAkB;CAE7C,MAAM,CAAC,aAAA,GAAYC,aAAAA,SAAAA,OAEf,IAAI,SACF,QACA,gBACF,CACJ;CAGA,MAAM,SAAS,SAAS,oBAAoB,gBAAgB;CAE5D,MAAM,kBAAkB,CAAC,eAAe,QAAQ,eAAe;CAC/D,cAAA,sBAAA,GACEC,aAAAA,YAAAA,EACG,kBAAkB;EACjB,MAAM,cAAc,kBAChB,SAAS,UAAUC,qBAAAA,cAAc,WAAW,aAAa,CAAC,IAC1DC,qBAAAA;EAIJ,SAAS,aAAa;EAEtB,OAAO;CACT,GACA,CAAC,UAAU,eAAe,CAC5B,SACM,SAAS,iBAAiB,CAClC;CAEA,CAAA,GAAA,aAAA,UAAA,OAAgB;EACd,SAAS,WAAW,gBAAgB;CACtC,GAAG,CAAC,kBAAkB,QAAQ,CAAC;CAG/B,IAAIC,iBAAAA,cAAc,kBAAkB,MAAM,GACxC,MAAMC,iBAAAA,gBAAgB,kBAAkB,UAAU,kBAAkB;CAItE,IACEC,2BAAAA,YAAY;EACV;EACA;EACA,cAAc,iBAAiB;EAC/B;EACA,UAAU,iBAAiB;CAC7B,CAAC,GAED,MAAM,OAAO;CAIf,OAAO,CAAC,iBAAiB,sBACrB,SAAS,YAAY,MAAM,IAC3B;AACN"}
@@ -1 +1 @@
1
- {"version":3,"file":"useBaseQuery.js","names":[],"sources":["../../src/useBaseQuery.ts"],"sourcesContent":["import { noop, notifyManager } from '@tanstack/query-core'\nimport type {\n QueryClient,\n QueryKey,\n QueryObserver,\n QueryObserverResult,\n} from '@tanstack/query-core'\nimport { useCallback, useEffect, useState } from 'preact/hooks'\n\nimport { useIsRestoring } from './IsRestoringProvider'\nimport { useQueryClient } from './QueryClientProvider'\nimport { useQueryErrorResetBoundary } from './QueryErrorResetBoundary'\nimport {\n ensurePreventErrorBoundaryRetry,\n getHasError,\n useClearResetErrorBoundary,\n} from './errorBoundaryUtils'\nimport {\n ensureSuspenseTimers,\n fetchOptimistic,\n shouldSuspend,\n} from './suspense'\nimport type { UseBaseQueryOptions } from './types'\nimport { useSyncExternalStore } from './utils'\n\nexport function useBaseQuery<\n TQueryFnData,\n TError,\n TData,\n TQueryData,\n TQueryKey extends QueryKey,\n>(\n options: UseBaseQueryOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryData,\n TQueryKey\n >,\n Observer: typeof QueryObserver,\n queryClient?: QueryClient,\n): QueryObserverResult<TData, TError> {\n if (process.env.NODE_ENV !== 'production') {\n if (typeof options !== 'object' || Array.isArray(options)) {\n throw new Error(\n 'Bad argument type. Starting with v5, only the \"Object\" form is allowed when calling query related functions. Please use the error stack to find the culprit call. More info here: https://tanstack.com/query/latest/docs/react/guides/migrating-to-v5#supports-a-single-signature-one-object',\n )\n }\n }\n\n const isRestoring = useIsRestoring()\n const errorResetBoundary = useQueryErrorResetBoundary()\n const client = useQueryClient(queryClient)\n const defaultedOptions = client.defaultQueryOptions(options)\n\n const query = client\n .getQueryCache()\n .get<\n TQueryFnData,\n TError,\n TQueryData,\n TQueryKey\n >(defaultedOptions.queryHash)\n\n if (process.env.NODE_ENV !== 'production') {\n if (!defaultedOptions.queryFn) {\n console.error(\n `[${defaultedOptions.queryHash}]: No queryFn was passed as an option, and no default queryFn was found. The queryFn parameter is only optional when using a default queryFn. More info here: https://tanstack.com/query/latest/docs/framework/react/guides/default-query-function`,\n )\n }\n }\n\n // Make sure results are optimistically set in fetching state before subscribing or updating options\n defaultedOptions._optimisticResults = isRestoring\n ? 'isRestoring'\n : 'optimistic'\n\n ensureSuspenseTimers(defaultedOptions)\n ensurePreventErrorBoundaryRetry(defaultedOptions, errorResetBoundary, query)\n\n useClearResetErrorBoundary(errorResetBoundary)\n\n const [observer] = useState(\n () =>\n new Observer<TQueryFnData, TError, TData, TQueryData, TQueryKey>(\n client,\n defaultedOptions,\n ),\n )\n\n // note: this must be called before useSyncExternalStore\n const result = observer.getOptimisticResult(defaultedOptions)\n\n const shouldSubscribe = !isRestoring && options.subscribed !== false\n useSyncExternalStore(\n useCallback(\n (onStoreChange) => {\n const unsubscribe = shouldSubscribe\n ? observer.subscribe(notifyManager.batchCalls(onStoreChange))\n : noop\n\n // Update result to make sure we did not miss any query updates\n // between creating the observer and subscribing to it.\n observer.updateResult()\n\n return unsubscribe\n },\n [observer, shouldSubscribe],\n ),\n () => observer.getCurrentResult(),\n )\n\n useEffect(() => {\n observer.setOptions(defaultedOptions)\n }, [defaultedOptions, observer])\n\n // Handle suspense\n if (shouldSuspend(defaultedOptions, result)) {\n throw fetchOptimistic(defaultedOptions, observer, errorResetBoundary)\n }\n\n // Handle error boundary\n if (\n getHasError({\n result,\n errorResetBoundary,\n throwOnError: defaultedOptions.throwOnError,\n query,\n suspense: defaultedOptions.suspense,\n })\n ) {\n throw result.error\n }\n\n // Handle result property usage tracking\n return !defaultedOpt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,OAAO,CAAC,iBAAiB,sBACrB,SAAS,YAAY,MAAM,IAC3B;AACN"}
1
+ {"version":3,"file":"useBaseQuery.js","names":[],"sources":["../../src/useBaseQuery.ts"],"sourcesContent":["import { noop, notifyManager } from '@tanstack/query-core'\nimport type {\n QueryClient,\n QueryKey,\n QueryObserver,\n QueryObserverResult,\n} from '@tanstack/query-core'\nimport { useCallback, useEffect, useState } from 'preact/hooks'\n\nimport { useIsRestoring } from './IsRestoringProvider'\nimport { useQueryClient } from './QueryClientProvider'\nimport { useQueryErrorResetBoundary } from './QueryErrorResetBoundary'\nimport {\n ensurePreventErrorBoundaryRetry,\n getHasError,\n useClearResetErrorBoundary,\n} from './errorBoundaryUtils'\nimport {\n ensureSuspenseTimers,\n fetchOptimistic,\n shouldSuspend,\n} from './suspense'\nimport type { UseBaseQueryOptions } from './types'\nimport { useSyncExternalStore } from './utils'\n\nexport function useBaseQuery<\n TQueryFnData,\n TError,\n TData,\n TQueryData,\n TQueryKey extends QueryKey,\n>(\n options: UseBaseQueryOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryData,\n TQueryKey\n >,\n Observer: typeof QueryObserver,\n queryClient?: QueryClient,\n): QueryObserverResult<TData, TError> {\n if (process.env.NODE_ENV !== 'production') {\n if (typeof options !== 'object' || Array.isArray(options)) {\n throw new Error(\n 'Bad argument type. Starting with v5, only the \"Object\" form is allowed when calling query related functions. Please use the error stack to find the culprit call. More info here: https://tanstack.com/query/latest/docs/react/guides/migrating-to-v5#supports-a-single-signature-one-object',\n )\n }\n }\n\n const isRestoring = useIsRestoring()\n const errorResetBoundary = useQueryErrorResetBoundary()\n const client = useQueryClient(queryClient)\n const defaultedOptions = client.defaultQueryOptions(options)\n\n const query = client\n .getQueryCache()\n .get<TQueryFnData, TError, TQueryData, TQueryKey>(\n defaultedOptions.queryHash,\n )\n\n if (process.env.NODE_ENV !== 'production') {\n if (!defaultedOptions.queryFn) {\n console.error(\n `[${defaultedOptions.queryHash}]: No queryFn was passed as an option, and no default queryFn was found. The queryFn parameter is only optional when using a default queryFn. More info here: https://tanstack.com/query/latest/docs/framework/react/guides/default-query-function`,\n )\n }\n }\n\n // Make sure results are optimistically set in fetching state before subscribing or updating options\n defaultedOptions._optimisticResults = isRestoring\n ? 'isRestoring'\n : 'optimistic'\n\n ensureSuspenseTimers(defaultedOptions)\n ensurePreventErrorBoundaryRetry(defaultedOptions, errorResetBoundary, query)\n\n useClearResetErrorBoundary(errorResetBoundary)\n\n const [observer] = useState(\n () =>\n new Observer<TQueryFnData, TError, TData, TQueryData, TQueryKey>(\n client,\n defaultedOptions,\n ),\n )\n\n // note: this must be called before useSyncExternalStore\n const result = observer.getOptimisticResult(defaultedOptions)\n\n const shouldSubscribe = !isRestoring && options.subscribed !== false\n useSyncExternalStore(\n useCallback(\n (onStoreChange) => {\n const unsubscribe = shouldSubscribe\n ? observer.subscribe(notifyManager.batchCalls(onStoreChange))\n : noop\n\n // Update result to make sure we did not miss any query updates\n // between creating the observer and subscribing to it.\n observer.updateResult()\n\n return unsubscribe\n },\n [observer, shouldSubscribe],\n ),\n () => observer.getCurrentResult(),\n )\n\n useEffect(() => {\n observer.setOptions(defaultedOptions)\n }, [defaultedOptions, observer])\n\n // Handle suspense\n if (shouldSuspend(defaultedOptions, result)) {\n throw fetchOptimistic(defaultedOptions, observer, errorResetBoundary)\n }\n\n // Handle error boundary\n if (\n getHasError({\n result,\n errorResetBoundary,\n throwOnError: defaultedOptions.throwOnError,\n query,\n suspense: defaultedOptions.suspense,\n })\n ) {\n throw result.error\n }\n\n // Handle result property usage tracking\n return !defaultedOptions.notifyOnChangeProps\n ? observer.trackResult(result)\n : result\n}\n"],"mappings":";;;;;;;;;AAyBA,SAAgB,aAOd,SAOA,UACA,aACoC;CACpC,IAAI,QAAQ,IAAI,aAAa,cACvB;MAAA,OAAO,YAAY,YAAY,MAAM,QAAQ,OAAO,GACtD,MAAM,IAAI,MACR,gSACF;CAAA;CAIJ,MAAM,cAAc,eAAe;CACnC,MAAM,qBAAqB,2BAA2B;CACtD,MAAM,SAAS,eAAe,WAAW;CACzC,MAAM,mBAAmB,OAAO,oBAAoB,OAAO;CAE3D,MAAM,QAAQ,OACX,cAAc,CAAC,CACf,IACC,iBAAiB,SACnB;CAEF,IAAI,QAAQ,IAAI,aAAa,cACvB;MAAA,CAAC,iBAAiB,SACpB,QAAQ,MACN,IAAI,iBAAiB,UAAU,mPACjC;CAAA;CAKJ,iBAAiB,qBAAqB,cAClC,gBACA;CAEJ,qBAAqB,gBAAgB;CACrC,gCAAgC,kBAAkB,oBAAoB,KAAK;CAE3E,2BAA2B,kBAAkB;CAE7C,MAAM,CAAC,YAAY,eAEf,IAAI,SACF,QACA,gBACF,CACJ;CAGA,MAAM,SAAS,SAAS,oBAAoB,gBAAgB;CAE5D,MAAM,kBAAkB,CAAC,eAAe,QAAQ,eAAe;CAC/D,qBACE,aACG,kBAAkB;EACjB,MAAM,cAAc,kBAChB,SAAS,UAAU,cAAc,WAAW,aAAa,CAAC,IAC1D;EAIJ,SAAS,aAAa;EAEtB,OAAO;CACT,GACA,CAAC,UAAU,eAAe,CAC5B,SACM,SAAS,iBAAiB,CAClC;CAEA,gBAAgB;EACd,SAAS,WAAW,gBAAgB;CACtC,GAAG,CAAC,kBAAkB,QAAQ,CAAC;CAG/B,IAAI,cAAc,kBAAkB,MAAM,GACxC,MAAM,gBAAgB,kBAAkB,UAAU,kBAAkB;CAItE,IACE,YAAY;EACV;EACA;EACA,cAAc,iBAAiB;EAC/B;EACA,UAAU,iBAAiB;CAC7B,CAAC,GAED,MAAM,OAAO;CAIf,OAAO,CAAC,iBAAiB,sBACrB,SAAS,YAAY,MAAM,IAC3B;AACN"}
@@ -1 +1 @@
1
- {"version":3,"file":"useQueries.cjs","names":["useQueryClient","useIsRestoring","useQueryErrorResetBoundary","useMemo","useState","QueriesObserver","useCallback","notifyManager","noop","shouldSuspend","QueryObserver","fetchOptimistic","getHasError"],"sources":["../../src/useQueries.ts"],"sourcesContent":["import {\n QueriesObserver,\n QueryObserver,\n noop,\n notifyManager,\n} from '@tanstack/query-core'\nimport type {\n DefaultError,\n OmitKeyof,\n QueriesObserverOptions,\n QueriesPlaceholderDataFunction,\n QueryClient,\n QueryFunction,\n QueryKey,\n QueryObserverOptions,\n ThrowOnError,\n} from '@tanstack/query-core'\nimport { useCallback, useEffect, useMemo, useState } from 'preact/hooks'\n\nimport { useIsRestoring } from './IsRestoringProvider'\nimport { useQueryClient } from './QueryClientProvider'\nimport { useQueryErrorResetBoundary } from './QueryErrorResetBoundary'\nimport {\n ensurePreventErrorBoundaryRetry,\n getHasError,\n useClearResetErrorBoundary,\n} from './errorBoundaryUtils'\nimport {\n ensureSuspenseTimers,\n fetchOptimistic,\n shouldSuspend,\n} from './suspense'\nimport type {\n DefinedUseQueryResult,\n UseQueryOptions,\n UseQueryResult,\n} from './types'\nimport { useSyncExternalStore } from './utils'\n\n// This defines the `UseQueryOptions` that are accepted in `QueriesOptions` & `GetOptions`.\n// `placeholderData` function always gets undefined passed\ntype UseQueryOptionsForUseQueries<\n TQueryFnData = unknown,\n TError = DefaultError,\n TData = TQueryFnData,\n TQueryKey extends QueryKey = QueryKey,\n> = OmitKeyof<\n UseQueryOptions<TQueryFnData, TError, TData, TQueryKey>,\n 'placeholderData' | 'subscribed'\n> & {\n placeholderData?: TQueryFnData | QueriesPlaceholderDataFunction<TQueryFnData>\n}\n\n// Avoid TS depth-limit error in case of large array literal\ntype MAXIMUM_DEPTH = 20\n\n// Widen the type of the symbol to enable type inference even if skipToken is not immutable.\ntype SkipTokenForUseQueries = symbol\n\ntype GetUseQueryOptionsForUseQueries<T> =\n // Part 1: responsible for applying explicit type parameter to function arguments, if object { queryFnData: TQueryFnData, error: TError, data: TData }\n T extends {\n queryFnData: infer TQueryFnData\n error?: infer TError\n data: infer TData\n }\n ? UseQueryOptionsForUseQueries<TQueryFnData, TError, TData>\n : T extends { queryFnData: infer TQueryFnData; error?: infer TError }\n ? UseQueryOptionsForUseQueries<TQueryFnData, TError>\n : T extends { data: infer TData; error?: infer TError }\n ? UseQueryOptionsForUseQueries<unknown, TError, TData>\n : // Part 2: responsible for applying explicit type parameter to function arguments, if tuple [TQueryFnData, TError, TData]\n T extends [infer TQueryFnData, infer TError, infer TData]\n ? UseQueryOptionsForUseQueries<TQueryFnData, TError, TData>\n : T extends [infer TQueryFnData, infer TError]\n ? UseQueryOptionsForUseQueries<TQueryFnData, TError>\n : T extends [infer TQueryFnData]\n ? UseQueryOptionsForUseQueries<TQueryFnData>\n : // Part 3: responsible for inferring and enforcing type if no explicit parameter was provided\n T extends {\n queryFn?:\n | QueryFunction<infer TQueryFnData, infer TQueryKey>\n | SkipTokenForUseQueries\n select?: (data: any) => infer TData\n throwOnError?: ThrowOnError<any, infer TError, any, any>\n }\n ? UseQueryOptionsForUseQueries<\n TQueryFnData,\n unknown extends TError ? DefaultError : TError,\n unknown extends TData ? TQueryFnData : TData,\n TQueryKey\n >\n : // Fallback\n UseQueryOptionsForUseQueries\n\n// A defined initialData setting should return a DefinedUseQueryResult rather than UseQueryResult\ntype GetDefinedOrUndefinedQueryResult<T, TData, TError = unknown> = T extends {\n initialData?: infer TInitialData\n}\n ? unknown extends TInitialData\n ? UseQueryResult<TData, TError>\n : TInitialData extends TData\n ? DefinedUseQueryResult<TData, TError>\n : TInitialData extends () => infer TInitialDataResult\n ? unknown extends TInitialDataResult\n ? UseQueryResult<TData, TError>\n : TInitialDataResult extends TData\n ? DefinedUseQueryResult<TData, TError>\n : UseQueryResult<TData, TError>\n : UseQueryResult<TData, TError>\n : UseQueryResult<TData, TError>\n\ntype GetUseQueryResult<T> =\n // Part 1: responsible for mapping explicit type parameter to function result, if object\n T extends { queryFnData: any; error?: infer TError; data: infer TData }\n ? GetDefinedOrUndefinedQueryResult<T, TData, TError>\n : T extends { queryFnData: infer TQueryFnData; error?: infer TError }\n ? GetDefinedOrUndefinedQueryResult<T, TQueryFnData, TError>\n : T extends { data: infer TData; error?: infer TError }\n ? GetDefinedOrUndefinedQueryResult<T, TData, TError>\n : // Part 2: responsible for mapping explicit type parameter to function result, if tuple\n T extends [any, infer TError, infer TData]\n ? GetDefinedOrUndefinedQueryResult<T, TData, TError>\n : T extends [infer TQueryFnData, infer TError]\n ? GetDefinedOrUndefinedQueryResult<T, TQueryFnData, TError>\n : T extends [infer TQueryFnData]\n ? GetDefinedOrUndefinedQueryResult<T, TQueryFnData>\n : // Part 3: responsible for mapping inferred type to results, if no explicit parameter was provided\n T extends {\n queryFn?:\n | QueryFunction<infer TQueryFnData, any>\n | SkipTokenForUseQueries\n select?: (data: any) => infer TData\n throwOnError?: ThrowOnError<any, infer TError, any, any>\n }\n ? GetDefinedOrUndefinedQueryResult<\n T,\n unknown extends TData ? TQueryFnData : TData,\n unknown extends TError ? DefaultError : TError\n >\n : // Fallback\n UseQueryResult\n\n/**\n * The `queries` array accepted by `useQueries`. Recursively unwraps each tuple element so every entry's\n * `queryFn`/`select`/`throwOnError` are inferred individually, up to 20 elements. An opaque array (e.g.\n * `unknown[]`) is returned as-is; a non-tuple array of a known element type, or a tuple past 20 elements, falls\n * back to a single homogeneous options type.\n *\n * @template T - The type of the `queries` array as written at the call site.\n * @template TResults - The internal accumulator that this type builds during recursion. It is not meant\n * to be set explicitly.\n * @template TDepth - The internal recursion-depth counter, checked against the 20-element limit. It is not\n * meant to be set explicitly.\n */\nexport type QueriesOptions<\n T extends Array<any>,\n TResults extends Array<any> = [],\n TDepth extends ReadonlyArray<number> = [],\n> = TDepth['length'] extends MAXIMUM_DEPTH\n ? Array<UseQueryOptionsForUseQueries>\n : T extends []\n ? []\n : T extends [infer Head]\n ? [...TResults, GetUseQueryOptionsForUseQueries<Head>]\n : T extends [infer Head, ...infer Tails]\n ? QueriesOptions<\n [...Tails],\n [...TResults, GetUseQueryOptionsForUseQueries<Head>],\n [...TDepth, 1]\n >\n : ReadonlyArray<unknown> extends T\n ? T\n : // If T is *some* array but we couldn't assign unknown[] to it, then it must hold some known/homogeneous type!\n // use this to infer the param types in the case of Array.map() argument\n T extends Array<\n UseQueryOptionsForUseQueries<\n infer TQueryFnData,\n infer TError,\n infer TData,\n infer TQueryKey\n >\n >\n ? Array<\n UseQueryOptionsForUseQueries<\n TQueryFnData,\n TError,\n TData,\n TQueryKey\n >\n >\n : // Fallback\n Array<UseQueryOptionsForUseQueries>\n\n/**\n * The result type returned by `useQueries`, when no `combine` is provided. Mirrors {@link QueriesOptions}: each\n * tuple element's result type is inferred individually, up to 20 elements. A non-tuple array is mapped\n * per-element instead, still inferring each entry individually; only past 20 elements does this fall back to a\n * single homogeneous {@link UseQueryResult} type.\n *\n * @template T - The type of the `queries` array, as inferred by {@link QueriesOptions}.\n * @template TResults - The internal accumulator that this type builds during recursion. It is not meant\n * to be set explicitly.\n * @template TDepth - The internal recursion-depth counter, checked against the 20-element limit. It is not\n * meant to be set explicitly.\n */\nexport type QueriesResults<\n T extends Array<any>,\n TResults extends Array<any> = [],\n TDepth extends ReadonlyArray<number> = [],\n> = TDepth['length'] extends MAXIMUM_DEPTH\n ? Array<UseQueryResult>\n : T extends []\n ? []\n : T extends [infer Head]\n ? [...TResults, GetUseQueryResult<Head>]\n : T extends [infer Head, ...infer Tails]\n ? QueriesResults<\n [...Tails],\n [...TResults, GetUseQueryResult<Head>],\n [...TDepth, 1]\n >\n : { [K in keyof T]: GetUseQueryResult<T[K]> }\n\n/**\n * The `useQueries` hook can be used to fetch a variable number of queries.\n *\n * The `queries` key accepts an array with query option objects mostly identical to `useQuery` — see the\n * `queries` parameter below for the differences. A custom `QueryClient` is supplied once, as `useQueries`' own\n * top-level second argument, rather than per query.\n *\n * Having the same query key more than once in the array of query objects may cause some data to be shared\n * between queries. To avoid this, consider de-duplicating the queries and map the results back to the desired\n * structure.\n *\n * The `combine` option can be used to combine the results of the queries into a single value. The result will\n * be structurally shared to be as referentially stable as possible.\n *\n * @param queryClient - Use this to provide a custom `QueryClient`. Otherwise, the one from the nearest context\n * will be used.\n * @returns The combined result. Without `combine`, this is an array with all the query results, in the same\n * order as the input. When `combine` is provided, this is the value returned by `combine` instead.\n *\n * @example\n * ```tsx\n * import { useQueries } from '@tanstack/preact-query'\n *\n * function Posts({ ids }: { ids: Array<number> }) {\n * const postQueries = useQueries({\n * queries: ids.map((id) => ({\n * queryKey: ['post', id],\n * queryFn: () => fetchPost(id),\n * staleTime: Infinity,\n * })),\n * })\n *\n * return (\n * <ul>\n * {postQueries.map((query, index) => {\n * if (query.isPending) return <li key={ids[index]}>Loading...</li>\n * if (query.isError) return <li key={ids[index]}>Error: {query.error.message}</li>\n * return <li key={ids[index]}>{query.data.title}</li>\n * })}\n * </ul>\n * )\n * }\n * ```\n *\n * @example\n * Combining results into a single value:\n * ```tsx\n * import { useQueries } from '@tanstack/preact-query'\n *\n * function Posts({ ids }: { ids: Array<number> }) {\n * const { data, isPending, isError } = useQueries({\n * queries: ids.map((id) => ({\n * queryKey: ['post', id],\n * queryFn: () => fetchPost(id),\n * })),\n * combine: (postQueries) => {\n * return {\n * data: postQueries.map((query) => query.data),\n * isPending: postQueries.some((query) => query.isPending),\n * isError: postQueries.some((query) => query.isError),\n * }\n * },\n * })\n *\n * if (isPending) return 'Loading...'\n * if (isError) return 'Error loading posts'\n *\n * return (\n * <ul>\n * {data.map((post) => (\n * <li key={post?.id}>{post?.title}</li>\n * ))}\n * </ul>\n * )\n * }\n * ```\n */\nexport function useQueries<\n T extends Array<any>,\n TCombinedResult = QueriesResults<T>,\n>(\n {\n queries,\n ...options\n }: {\n /**\n * An array with query option objects, mostly identical to `useQuery` — except that `queryClient` and\n * `subscribed` aren't accepted per-query (`subscribed` is a top-level option here instead), and\n * `placeholderData` accepts a {@link QueriesPlaceholderDataFunction}, which is called with `previousData`\n * and `previousQuery` always `undefined`, rather than `useQuery`'s placeholder function.\n */\n queries:\n | readonly [...QueriesOptions<T>]\n | readonly [...{ [K in keyof T]: GetUseQueryOptionsForUseQueries<T[K]> }]\n /**\n * Use this to combine the results of the queries into a single value. The result will be structurally\n * shared to be as referentially stable as possible.\n */\n combine?: (result: QueriesResults<T>) => TCombinedResult\n /**\n * Set this to `false` to unsubscribe this observer from updates to the query cache.\n *\n * @defaultValue true\n */\n subscribed?: boolean\n },\n queryClient?: QueryClient,\n): TCombinedResult {\n const client = useQueryClient(queryClient)\n const isRestoring = useIsRestoring()\n const errorResetBoundary = useQueryErrorResetBoundary()\n const subscribed = options.subscribed !== false\n\n const defaultedQueries = useMemo(\n () =>\n queries.map((opts) => {\n const defaultedOptions = client.defaultQueryOptions(\n opts as QueryObserverOptions,\n )\n\n // Make sure the results are already in fetching state before subscribing or updating options\n defaultedOptions._optimisticResults = isRestoring\n ? 'isRestoring'\n : subscribed\n ? 'optimistic'\n : undefined\n\n return defaultedOptions\n }),\n [queries, client, isRestoring, subscribed],\n )\n\n defaultedQueries.forEach((queryOptions) => {\n ensureSuspenseTimers(queryOptions)\n const query = client.getQueryCache().get(queryOptions.queryHash)\n ensurePreventErrorBoundaryRetry(queryOptions, errorResetBoundary, query)\n })\n\n useClearResetErrorBoundary(errorResetBoundary)\n\n const [observer] = useState(\n () =>\n new QueriesObserver<TCombinedResult>(\n client,\n defaultedQueries,\n options as QueriesObserverOptions<TCombinedResult>,\n ),\n )\n\n // note: this must be called before useSyncExternalStore\n const [optimisticResult, getCombinedResult, trackResult] =\n observer.getOptimisticResult(\n defaultedQueries,\n (options as QueriesObserverOptions<TCombinedResult>).combine,\n )\n\n const shouldSubscribe = !isRestoring && subscribed\n useSyncExternalStore(\n useCallback(\n (onStoreChange) =>\n shouldSubscribe\n ? observer.subscribe(notifyManager.batchCalls(onStoreChange))\n : noop,\n [observer, shouldSubscribe],\n ),\n () => observer.getCurrentResult(),\n )\n\n useEffect(() => {\n observer.setQueries(\n defaultedQueries,\n options as QueriesObserverOptions<TCombinedResult>,\n )\n }, [defaultedQueries, options, observer])\n\n const shouldAtLeastOneSuspend = optimisticResult.some((result, index) =>\n shouldSuspend(defaultedQueries[index], result),\n )\n\n const suspensePromises = shouldAtLeastOneSuspend\n ? optimisticResult.flatMap((result, index) => {\n const opts = defaultedQueries[index]\n\n if (opts && shouldSuspend(opts, result)) {\n const queryObserver = new QueryObserver(client, opts)\n return fetchOptimistic(opts, queryObserver, errorResetBoundary)\n }\n return []\n })\n : []\n\n if (suspensePromises.length > 0) {\n throw Promise.all(suspensePromises)\n }\n const firstSingleResultWhichShouldThrow = optimisticResult.find(\n (result, index) => {\n const query = defaultedQueries[index]\n return (\n query &&\n getHasError({\n result,\n errorResetBoundary,\n throwOnError: query.throwOnError,\n query: client.getQueryCache().get(query.queryHash),\n suspense: query.suspense,\n })\n )\n },\n )\n\n if (firstSingleResultWhichShouldThrow) {\n throw firstSingleResultWhichShouldThrow.error\n }\n\n return getCombinedResult(trackResult())\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA6SA,SAAgB,WAId,EACE,SACA,GAAG,WAuBL,aACiB;CACjB,MAAM,SAASA,4BAAAA,eAAe,WAAW;CACzC,MAAM,cAAcC,4BAAAA,eAAe;CACnC,MAAM,qBAAqBC,gCAAAA,2BAA2B;CACtD,MAAM,aAAa,QAAQ,eAAe;CAE1C,MAAM,oBAAA,GAAmBC,aAAAA,QAAAA,OAErB,QAAQ,KAAK,SAAS;EACpB,MAAM,mBAAmB,OAAO,oBAC9B,IACF;EAGA,iBAAiB,qBAAqB,cAClC,gBACA,aACE,eACA,KAAA;EAEN,OAAO;CACT,CAAC,GACH;EAAC;EAAS;EAAQ;EAAa;CAAU,CAC3C;CAEA,iBAAiB,SAAS,iBAAiB;EACzC,iBAAA,qBAAqB,YAAY;EACjC,MAAM,QAAQ,OAAO,cAAc,CAAC,CAAC,IAAI,aAAa,SAAS;EAC/D,2BAAA,gCAAgC,cAAc,oBAAoB,KAAK;CACzE,CAAC;CAED,2BAAA,2BAA2B,kBAAkB;CAE7C,MAAM,CAAC,aAAA,GAAYC,aAAAA,SAAAA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useMemo","useState","QueriesObserver","useCallback","notifyManager","noop","shouldSuspend","QueryObserver","fetchOptimistic","getHasError"],"sources":["../../src/useQueries.ts"],"sourcesContent":["import {\n QueriesObserver,\n QueryObserver,\n noop,\n notifyManager,\n} from '@tanstack/query-core'\nimport type {\n DefaultError,\n OmitKeyof,\n QueriesObserverOptions,\n QueriesPlaceholderDataFunction,\n QueryClient,\n QueryFunction,\n QueryKey,\n QueryObserverOptions,\n ThrowOnError,\n} from '@tanstack/query-core'\nimport { useCallback, useEffect, useMemo, useState } from 'preact/hooks'\n\nimport { useIsRestoring } from './IsRestoringProvider'\nimport { useQueryClient } from './QueryClientProvider'\nimport { useQueryErrorResetBoundary } from './QueryErrorResetBoundary'\nimport {\n ensurePreventErrorBoundaryRetry,\n getHasError,\n useClearResetErrorBoundary,\n} from './errorBoundaryUtils'\nimport {\n ensureSuspenseTimers,\n fetchOptimistic,\n shouldSuspend,\n} from './suspense'\nimport type {\n DefinedUseQueryResult,\n UseQueryOptions,\n UseQueryResult,\n} from './types'\nimport { useSyncExternalStore } from './utils'\n\n// This defines the `UseQueryOptions` that are accepted in `QueriesOptions` & `GetOptions`.\n// `placeholderData` function always gets undefined passed\ntype UseQueryOptionsForUseQueries<\n TQueryFnData = unknown,\n TError = DefaultError,\n TData = TQueryFnData,\n TQueryKey extends QueryKey = QueryKey,\n> = OmitKeyof<\n UseQueryOptions<TQueryFnData, TError, TData, TQueryKey>,\n 'placeholderData' | 'subscribed'\n> & {\n placeholderData?: TQueryFnData | QueriesPlaceholderDataFunction<TQueryFnData>\n}\n\n// Avoid TS depth-limit error in case of large array literal\ntype MAXIMUM_DEPTH = 20\n\n// Widen the type of the symbol to enable type inference even if skipToken is not immutable.\ntype SkipTokenForUseQueries = symbol\n\ntype GetUseQueryOptionsForUseQueries<T> =\n // Part 1: responsible for applying explicit type parameter to function arguments, if object { queryFnData: TQueryFnData, error: TError, data: TData }\n T extends {\n queryFnData: infer TQueryFnData\n error?: infer TError\n data: infer TData\n }\n ? UseQueryOptionsForUseQueries<TQueryFnData, TError, TData>\n : T extends { queryFnData: infer TQueryFnData; error?: infer TError }\n ? UseQueryOptionsForUseQueries<TQueryFnData, TError>\n : T extends { data: infer TData; error?: infer TError }\n ? UseQueryOptionsForUseQueries<unknown, TError, TData>\n : // Part 2: responsible for applying explicit type parameter to function arguments, if tuple [TQueryFnData, TError, TData]\n T extends [infer TQueryFnData, infer TError, infer TData]\n ? UseQueryOptionsForUseQueries<TQueryFnData, TError, TData>\n : T extends [infer TQueryFnData, infer TError]\n ? UseQueryOptionsForUseQueries<TQueryFnData, TError>\n : T extends [infer TQueryFnData]\n ? UseQueryOptionsForUseQueries<TQueryFnData>\n : // Part 3: responsible for inferring and enforcing type if no explicit parameter was provided\n T extends {\n queryFn?:\n | QueryFunction<infer TQueryFnData, infer TQueryKey>\n | SkipTokenForUseQueries\n select?: (data: any) => infer TData\n throwOnError?: ThrowOnError<any, infer TError, any, any>\n }\n ? UseQueryOptionsForUseQueries<\n TQueryFnData,\n unknown extends TError ? DefaultError : TError,\n unknown extends TData ? TQueryFnData : TData,\n TQueryKey\n >\n : // Fallback\n UseQueryOptionsForUseQueries\n\n// A defined initialData setting should return a DefinedUseQueryResult rather than UseQueryResult\ntype GetDefinedOrUndefinedQueryResult<T, TData, TError = unknown> = T extends {\n initialData?: infer TInitialData\n}\n ? unknown extends TInitialData\n ? UseQueryResult<TData, TError>\n : TInitialData extends TData\n ? DefinedUseQueryResult<TData, TError>\n : TInitialData extends () => infer TInitialDataResult\n ? unknown extends TInitialDataResult\n ? UseQueryResult<TData, TError>\n : TInitialDataResult extends TData\n ? DefinedUseQueryResult<TData, TError>\n : UseQueryResult<TData, TError>\n : UseQueryResult<TData, TError>\n : UseQueryResult<TData, TError>\n\ntype GetUseQueryResult<T> =\n // Part 1: responsible for mapping explicit type parameter to function result, if object\n T extends { queryFnData: any; error?: infer TError; data: infer TData }\n ? GetDefinedOrUndefinedQueryResult<T, TData, TError>\n : T extends { queryFnData: infer TQueryFnData; error?: infer TError }\n ? GetDefinedOrUndefinedQueryResult<T, TQueryFnData, TError>\n : T extends { data: infer TData; error?: infer TError }\n ? GetDefinedOrUndefinedQueryResult<T, TData, TError>\n : // Part 2: responsible for mapping explicit type parameter to function result, if tuple\n T extends [any, infer TError, infer TData]\n ? GetDefinedOrUndefinedQueryResult<T, TData, TError>\n : T extends [infer TQueryFnData, infer TError]\n ? GetDefinedOrUndefinedQueryResult<T, TQueryFnData, TError>\n : T extends [infer TQueryFnData]\n ? GetDefinedOrUndefinedQueryResult<T, TQueryFnData>\n : // Part 3: responsible for mapping inferred type to results, if no explicit parameter was provided\n T extends {\n queryFn?:\n | QueryFunction<infer TQueryFnData, any>\n | SkipTokenForUseQueries\n select?: (data: any) => infer TData\n throwOnError?: ThrowOnError<any, infer TError, any, any>\n }\n ? GetDefinedOrUndefinedQueryResult<\n T,\n unknown extends TData ? TQueryFnData : TData,\n unknown extends TError ? DefaultError : TError\n >\n : // Fallback\n UseQueryResult\n\n/**\n * The `queries` array accepted by `useQueries`. Recursively unwraps each tuple element so every entry's\n * `queryFn`/`select`/`throwOnError` are inferred individually, up to 20 elements — past that, a tuple falls\n * back to a single homogeneous options type.\n *\n * An opaque array (e.g. `unknown[]`) is returned as-is; a non-tuple array whose element type structurally\n * matches a query options object is mapped per-element instead, still inferring each entry individually; any\n * other non-tuple array — one whose element type doesn't match the expected options shape — falls back to\n * that same homogeneous options type too.\n *\n * @template T - The type of the `queries` array as written at the call site.\n * @template TResults - The internal accumulator that this type builds during recursion. It is not meant\n * to be set explicitly.\n * @template TDepth - The internal recursion-depth counter, checked against the 20-element limit. It is not\n * meant to be set explicitly.\n */\nexport type QueriesOptions<\n T extends Array<any>,\n TResults extends Array<any> = [],\n TDepth extends ReadonlyArray<number> = [],\n> = TDepth['length'] extends MAXIMUM_DEPTH\n ? Array<UseQueryOptionsForUseQueries>\n : T extends []\n ? []\n : T extends [infer Head]\n ? [...TResults, GetUseQueryOptionsForUseQueries<Head>]\n : T extends [infer Head, ...infer Tails]\n ? QueriesOptions<\n [...Tails],\n [...TResults, GetUseQueryOptionsForUseQueries<Head>],\n [...TDepth, 1]\n >\n : ReadonlyArray<unknown> extends T\n ? T\n : // If T is *some* array but we couldn't assign unknown[] to it, then it must hold some known/homogeneous type!\n // use this to infer the param types in the case of Array.map() argument\n T extends Array<\n UseQueryOptionsForUseQueries<\n infer TQueryFnData,\n infer TError,\n infer TData,\n infer TQueryKey\n >\n >\n ? Array<\n UseQueryOptionsForUseQueries<\n TQueryFnData,\n TError,\n TData,\n TQueryKey\n >\n >\n : // Fallback\n Array<UseQueryOptionsForUseQueries>\n\n/**\n * The result type returned by `useQueries`, when no `combine` is provided. Mirrors {@link QueriesOptions}: each\n * tuple element's result type is inferred individually, up to 20 elements. A non-tuple array is mapped\n * per-element instead, still inferring each entry individually; only past 20 elements does this fall back to a\n * single homogeneous {@link UseQueryResult} type.\n *\n * @template T - The type of the `queries` array, as inferred by {@link QueriesOptions}.\n * @template TResults - The internal accumulator that this type builds during recursion. It is not meant\n * to be set explicitly.\n * @template TDepth - The internal recursion-depth counter, checked against the 20-element limit. It is not\n * meant to be set explicitly.\n */\nexport type QueriesResults<\n T extends Array<any>,\n TResults extends Array<any> = [],\n TDepth extends ReadonlyArray<number> = [],\n> = TDepth['length'] extends MAXIMUM_DEPTH\n ? Array<UseQueryResult>\n : T extends []\n ? []\n : T extends [infer Head]\n ? [...TResults, GetUseQueryResult<Head>]\n : T extends [infer Head, ...infer Tails]\n ? QueriesResults<\n [...Tails],\n [...TResults, GetUseQueryResult<Head>],\n [...TDepth, 1]\n >\n : { [K in keyof T]: GetUseQueryResult<T[K]> }\n\n/**\n * The `useQueries` hook can be used to fetch a variable number of queries.\n *\n * The `queries` key accepts an array with query option objects mostly identical to `useQuery` — see the\n * `queries` parameter below for the differences. A custom `QueryClient` is supplied once, as `useQueries`' own\n * top-level second argument, rather than per query.\n *\n * Having the same query key more than once in the array of query objects may cause some data to be shared\n * between queries. To avoid this, consider de-duplicating the queries and map the results back to the desired\n * structure.\n *\n * The `combine` option can be used to combine the results of the queries into a single value. The result will\n * be structurally shared to be as referentially stable as possible.\n *\n * @param queryClient - Use this to provide a custom `QueryClient`. Otherwise, the one from the nearest context\n * will be used.\n * @returns The combined result. Without `combine`, this is an array with all the query results, in the same\n * order as the input. When `combine` is provided, this is the value returned by `combine` instead.\n *\n * @example\n * ```tsx\n * import { useQueries } from '@tanstack/preact-query'\n *\n * function Posts({ ids }: { ids: Array<number> }) {\n * const postQueries = useQueries({\n * queries: ids.map((id) => ({\n * queryKey: ['post', id],\n * queryFn: () => fetchPost(id),\n * staleTime: Infinity,\n * })),\n * })\n *\n * return (\n * <ul>\n * {postQueries.map((query, index) => {\n * if (query.isPending) return <li key={ids[index]}>Loading...</li>\n * if (query.isError) return <li key={ids[index]}>Error: {query.error.message}</li>\n * return <li key={ids[index]}>{query.data.title}</li>\n * })}\n * </ul>\n * )\n * }\n * ```\n *\n * @example\n * Combining results into a single value:\n * ```tsx\n * import { useQueries } from '@tanstack/preact-query'\n *\n * function Posts({ ids }: { ids: Array<number> }) {\n * const { data, isPending, isError } = useQueries({\n * queries: ids.map((id) => ({\n * queryKey: ['post', id],\n * queryFn: () => fetchPost(id),\n * })),\n * combine: (postQueries) => {\n * return {\n * data: postQueries.map((query) => query.data),\n * isPending: postQueries.some((query) => query.isPending),\n * isError: postQueries.some((query) => query.isError),\n * }\n * },\n * })\n *\n * if (isPending) return 'Loading...'\n * if (isError) return 'Error loading posts'\n *\n * return (\n * <ul>\n * {data.map((post) => (\n * <li key={post?.id}>{post?.title}</li>\n * ))}\n * </ul>\n * )\n * }\n * ```\n */\nexport function useQueries<\n T extends Array<any>,\n TCombinedResult = QueriesResults<T>,\n>(\n {\n queries,\n ...options\n }: {\n /**\n * An array with query option objects, mostly identical to `useQuery` — except that `queryClient` and\n * `subscribed` aren't accepted per-query (`subscribed` is a top-level option here instead), and\n * `placeholderData` accepts a {@link QueriesPlaceholderDataFunction}, which is called with `previousData`\n * and `previousQuery` always `undefined`, rather than `useQuery`'s placeholder function.\n */\n queries:\n | readonly [...QueriesOptions<T>]\n | readonly [...{ [K in keyof T]: GetUseQueryOptionsForUseQueries<T[K]> }]\n /**\n * Use this to combine the results of the queries into a single value. The result will be structurally\n * shared to be as referentially stable as possible.\n */\n combine?: (result: QueriesResults<T>) => TCombinedResult\n /**\n * Set this to `false` to unsubscribe this observer from updates to the query cache.\n *\n * @defaultValue true\n */\n subscribed?: boolean\n },\n queryClient?: QueryClient,\n): TCombinedResult {\n const client = useQueryClient(queryClient)\n const isRestoring = useIsRestoring()\n const errorResetBoundary = useQueryErrorResetBoundary()\n const subscribed = options.subscribed !== false\n\n const defaultedQueries = useMemo(\n () =>\n queries.map((opts) => {\n const defaultedOptions = client.defaultQueryOptions(\n opts as QueryObserverOptions,\n )\n\n // Make sure the results are already in fetching state before subscribing or updating options\n defaultedOptions._optimisticResults = isRestoring\n ? 'isRestoring'\n : subscribed\n ? 'optimistic'\n : undefined\n\n return defaultedOptions\n }),\n [queries, client, isRestoring, subscribed],\n )\n\n defaultedQueries.forEach((queryOptions) => {\n ensureSuspenseTimers(queryOptions)\n const query = client.getQueryCache().get(queryOptions.queryHash)\n ensurePreventErrorBoundaryRetry(queryOptions, errorResetBoundary, query)\n })\n\n useClearResetErrorBoundary(errorResetBoundary)\n\n const [observer] = useState(\n () =>\n new QueriesObserver<TCombinedResult>(\n client,\n defaultedQueries,\n options as QueriesObserverOptions<TCombinedResult>,\n ),\n )\n\n // note: this must be called before useSyncExternalStore\n const [optimisticResult, getCombinedResult, trackResult] =\n observer.getOptimisticResult(\n defaultedQueries,\n (options as QueriesObserverOptions<TCombinedResult>).combine,\n )\n\n const shouldSubscribe = !isRestoring && subscribed\n useSyncExternalStore(\n useCallback(\n (onStoreChange) =>\n shouldSubscribe\n ? observer.subscribe(notifyManager.batchCalls(onStoreChange))\n : noop,\n [observer, shouldSubscribe],\n ),\n () => observer.getCurrentResult(),\n )\n\n useEffect(() => {\n observer.setQueries(\n defaultedQueries,\n options as QueriesObserverOptions<TCombinedResult>,\n )\n }, [defaultedQueries, options, observer])\n\n const shouldAtLeastOneSuspend = optimisticResult.some((result, index) =>\n shouldSuspend(defaultedQueries[index], result),\n )\n\n const suspensePromises = shouldAtLeastOneSuspend\n ? optimisticResult.flatMap((result, index) => {\n const opts = defaultedQueries[index]\n\n if (opts && shouldSuspend(opts, result)) {\n const queryObserver = new QueryObserver(client, opts)\n return fetchOptimistic(opts, queryObserver, errorResetBoundary)\n }\n return []\n })\n : []\n\n if (suspensePromises.length > 0) {\n throw Promise.all(suspensePromises)\n }\n const firstSingleResultWhichShouldThrow = optimisticResult.find(\n (result, index) => {\n const query = defaultedQueries[index]\n return (\n query &&\n getHasError({\n result,\n errorResetBoundary,\n throwOnError: query.throwOnError,\n query: client.getQueryCache().get(query.queryHash),\n suspense: query.suspense,\n })\n )\n },\n )\n\n if (firstSingleResultWhichShouldThrow) {\n throw firstSingleResultWhichShouldThrow.error\n }\n\n return getCombinedResult(trackResult())\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAiTA,SAAgB,WAId,EACE,SACA,GAAG,WAuBL,aACiB;CACjB,MAAM,SAASA,4BAAAA,eAAe,WAAW;CACzC,MAAM,cAAcC,4BAAAA,eAAe;CACnC,MAAM,qBAAqBC,gCAAAA,2BAA2B;CACtD,MAAM,aAAa,QAAQ,eAAe;CAE1C,MAAM,oBAAA,GAAmBC,aAAAA,QAAAA,OAErB,QAAQ,KAAK,SAAS;EACpB,MAAM,mBAAmB,OAAO,oBAC9B,IACF;EAGA,iBAAiB,qBAAqB,cAClC,gBACA,aACE,eACA,KAAA;EAEN,OAAO;CACT,CAAC,GACH;EAAC;EAAS;EAAQ;EAAa;CAAU,CAC3C;CAEA,iBAAiB,SAAS,iBAAiB;EACzC,iBAAA,qBAA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,IAAI,MAAM,SAAS;GACjD,UAAU,MAAM;EAClB,CAAC;CAEL,CACF;CAEA,IAAI,mCACF,MAAM,kCAAkC;CAG1C,OAAO,kBAAkB,YAAY,CAAC;AACxC"}
@@ -41,10 +41,14 @@ type GetUseQueryResult<T> = T extends {
41
41
  } ? GetDefinedOrUndefinedQueryResult<T, unknown extends TData ? TQueryFnData : TData, unknown extends TError ? DefaultError : TError> : UseQueryResult;
42
42
  /**
43
43
  * The `queries` array accepted by `useQueries`. Recursively unwraps each tuple element so every entry's
44
- * `queryFn`/`select`/`throwOnError` are inferred individually, up to 20 elements. An opaque array (e.g.
45
- * `unknown[]`) is returned as-is; a non-tuple array of a known element type, or a tuple past 20 elements, falls
44
+ * `queryFn`/`select`/`throwOnError` are inferred individually, up to 20 elements — past that, a tuple falls
46
45
  * back to a single homogeneous options type.
47
46
  *
47
+ * An opaque array (e.g. `unknown[]`) is returned as-is; a non-tuple array whose element type structurally
48
+ * matches a query options object is mapped per-element instead, still inferring each entry individually; any
49
+ * other non-tuple array — one whose element type doesn't match the expected options shape — falls back to
50
+ * that same homogeneous options type too.
51
+ *
48
52
  * @template T - The type of the `queries` array as written at the call site.
49
53
  * @template TResults - The internal accumulator that this type builds during recursion. It is not meant
50
54
  * to be set explicitly.
@@ -1 +1 @@
1
- {"version":3,"file":"useQueries.d.cts","names":[],"sources":["../../src/useQueries.ts"],"mappings":";;;KAyCK,6BACH,wBACA,SAAS,cACT,QAAQ,cACR,kBAAkB,WAAW,YAC3B,UACF,gBAAgB,cAAc,QAAQ,OAAO;EAG7C,kBAAkB,eAAe,+BAA+B;;KAI7D;KAGA;KAEA,gCAAgC,KAEnC;EACE,mBAAmB;EACnB,cAAc;EACd,YAAY;IAEV,6BAA6B,cAAc,QAAQ,SACnD;EAAY,mBAAmB;EAAc,cAAc;IACzD,6BAA6B,cAAc,UAC3C;EAAY,YAAY;EAAO,cAAc;IAC3C,sCAAsC,QAAQ,SAE9C,iBAAiB,oBAAoB,cAAc,S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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBA+EhC,WACd,UAAU,YACV,kBAAkB,eAAe,MAG/B,YACG;;;;;;;EAQH,sBACiB,eAAe,sBACZ,WAAW,IAAI,gCAAgC,EAAE;;;;;EAKrE,WAAW,QAAQ,eAAe,OAAO;;;;;;EAMzC;GAEF,cAAc,cACb"}
@@ -41,10 +41,14 @@ type GetUseQueryResult<T> = T extends {
41
41
  } ? GetDefinedOrUndefinedQueryResult<T, unknown extends TData ? TQueryFnData : TData, unknown extends TError ? DefaultError : TError> : UseQueryResult;
42
42
  /**
43
43
  * The `queries` array accepted by `useQueries`. Recursively unwraps each tuple element so every entry's
44
- * `queryFn`/`select`/`throwOnError` are inferred individually, up to 20 elements. An opaque array (e.g.
45
- * `unknown[]`) is returned as-is; a non-tuple array of a known element type, or a tuple past 20 elements, falls
44
+ * `queryFn`/`select`/`throwOnError` are inferred individually, up to 20 elements — past that, a tuple falls
46
45
  * back to a single homogeneous options type.
47
46
  *
47
+ * An opaque array (e.g. `unknown[]`) is returned as-is; a non-tuple array whose element type structurally
48
+ * matches a query options object is mapped per-element instead, still inferring each entry individually; any
49
+ * other non-tuple array — one whose element type doesn't match the expected options shape — falls back to
50
+ * that same homogeneous options type too.
51
+ *
48
52
  * @template T - The type of the `queries` array as written at the call site.
49
53
  * @template TResults - The internal accumulator that this type builds during recursion. It is not meant
50
54
  * to be set explicitly.
@@ -1 +1 @@
1
- {"version":3,"file":"useQueries.d.ts","names":[],"sources":["../../src/useQueries.ts"],"mappings":";;;KAyCK,6BACH,wBACA,SAAS,cACT,QAAQ,cACR,kBAAkB,WAAW,YAC3B,UACF,gBAAgB,cAAc,QAAQ,OAAO;EAG7C,kBAAkB,eAAe,+BAA+B;;KAI7D;KAGA;KAEA,gCAAgC,KAEnC;EACE,mBAAmB;EACnB,cAAc;EACd,YAAY;IAEV,6BAA6B,cAAc,QAAQ,SACnD;EAAY,mBAAmB;EAAc,cAAc;IACzD,6BAA6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BAAkB,YAC5B,iBAEH,WAAW,IAAI,kBAAkB,EAAE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBA+EhC,WACd,UAAU,YACV,kBAAkB,eAAe,MAG/B,YACG;;;;;;;EAQH,sBACiB,eAAe,sBACZ,WAAW,IAAI,gCAAgC,EAAE;;;;;EAKrE,WAAW,QAAQ,eAAe,OAAO;;;;;;EAMzC;GAEF,cAAc,cACb"}
@@ -1 +1 @@
1
- {"version":3,"file":"useQueries.js","names":[],"sources":["../../src/useQueries.ts"],"sourcesContent":["import {\n QueriesObserver,\n QueryObserver,\n noop,\n notifyManager,\n} from '@tanstack/query-core'\nimport type {\n DefaultError,\n OmitKeyof,\n QueriesObserverOptions,\n QueriesPlaceholderDataFunction,\n QueryClient,\n QueryFunction,\n QueryKey,\n QueryObserverOptions,\n ThrowOnError,\n} from '@tanstack/query-core'\nimport { useCallback, useEffect, useMemo, useState } from 'preact/hooks'\n\nimport { useIsRestoring } from './IsRestoringProvider'\nimport { useQueryClient } from './QueryClientProvider'\nimport { useQueryErrorResetBoundary } from './QueryErrorResetBoundary'\nimport {\n ensurePreventErrorBoundaryRetry,\n getHasError,\n useClearResetErrorBoundary,\n} from './errorBoundaryUtils'\nimport {\n ensureSuspenseTimers,\n fetchOptimistic,\n shouldSuspend,\n} from './suspense'\nimport type {\n DefinedUseQueryResult,\n UseQueryOptions,\n UseQueryResult,\n} from './types'\nimport { useSyncExternalStore } from './utils'\n\n// This defines the `UseQueryOptions` that are accepted in `QueriesOptions` & `GetOptions`.\n// `placeholderData` function always gets undefined passed\ntype UseQueryOptionsForUseQueries<\n TQueryFnData = unknown,\n TError = DefaultError,\n TData = TQueryFnData,\n TQueryKey extends QueryKey = QueryKey,\n> = OmitKeyof<\n UseQueryOptions<TQueryFnData, TError, TData, TQueryKey>,\n 'placeholderData' | 'subscribed'\n> & {\n placeholderData?: TQueryFnData | QueriesPlaceholderDataFunction<TQueryFnData>\n}\n\n// Avoid TS depth-limit error in case of large array literal\ntype MAXIMUM_DEPTH = 20\n\n// Widen the type of the symbol to enable type inference even if skipToken is not immutable.\ntype SkipTokenForUseQueries = symbol\n\ntype GetUseQueryOptionsForUseQueries<T> =\n // Part 1: responsible for applying explicit type parameter to function arguments, if object { queryFnData: TQueryFnData, error: TError, data: TData }\n T extends {\n queryFnData: infer TQueryFnData\n error?: infer TError\n data: infer TData\n }\n ? UseQueryOptionsForUseQueries<TQueryFnData, TError, TData>\n : T extends { queryFnData: infer TQueryFnData; error?: infer TError }\n ? UseQueryOptionsForUseQueries<TQueryFnData, TError>\n : T extends { data: infer TData; error?: infer TError }\n ? UseQueryOptionsForUseQueries<unknown, TError, TData>\n : // Part 2: responsible for applying explicit type parameter to function arguments, if tuple [TQueryFnData, TError, TData]\n T extends [infer TQueryFnData, infer TError, infer TData]\n ? UseQueryOptionsForUseQueries<TQueryFnData, TError, TData>\n : T extends [infer TQueryFnData, infer TError]\n ? UseQueryOptionsForUseQueries<TQueryFnData, TError>\n : T extends [infer TQueryFnData]\n ? UseQueryOptionsForUseQueries<TQueryFnData>\n : // Part 3: responsible for inferring and enforcing type if no explicit parameter was provided\n T extends {\n queryFn?:\n | QueryFunction<infer TQueryFnData, infer TQueryKey>\n | SkipTokenForUseQueries\n select?: (data: any) => infer TData\n throwOnError?: ThrowOnError<any, infer TError, any, any>\n }\n ? UseQueryOptionsForUseQueries<\n TQueryFnData,\n unknown extends TError ? DefaultError : TError,\n unknown extends TData ? TQueryFnData : TData,\n TQueryKey\n >\n : // Fallback\n UseQueryOptionsForUseQueries\n\n// A defined initialData setting should return a DefinedUseQueryResult rather than UseQueryResult\ntype GetDefinedOrUndefinedQueryResult<T, TData, TError = unknown> = T extends {\n initialData?: infer TInitialData\n}\n ? unknown extends TInitialData\n ? UseQueryResult<TData, TError>\n : TInitialData extends TData\n ? DefinedUseQueryResult<TData, TError>\n : TInitialData extends () => infer TInitialDataResult\n ? unknown extends TInitialDataResult\n ? UseQueryResult<TData, TError>\n : TInitialDataResult extends TData\n ? DefinedUseQueryResult<TData, TError>\n : UseQueryResult<TData, TError>\n : UseQueryResult<TData, TError>\n : UseQueryResult<TData, TError>\n\ntype GetUseQueryResult<T> =\n // Part 1: responsible for mapping explicit type parameter to function result, if object\n T extends { queryFnData: any; error?: infer TError; data: infer TData }\n ? GetDefinedOrUndefinedQueryResult<T, TData, TError>\n : T extends { queryFnData: infer TQueryFnData; error?: infer TError }\n ? GetDefinedOrUndefinedQueryResult<T, TQueryFnData, TError>\n : T extends { data: infer TData; error?: infer TError }\n ? GetDefinedOrUndefinedQueryResult<T, TData, TError>\n : // Part 2: responsible for mapping explicit type parameter to function result, if tuple\n T extends [any, infer TError, infer TData]\n ? GetDefinedOrUndefinedQueryResult<T, TData, TError>\n : T extends [infer TQueryFnData, infer TError]\n ? GetDefinedOrUndefinedQueryResult<T, TQueryFnData, TError>\n : T extends [infer TQueryFnData]\n ? GetDefinedOrUndefinedQueryResult<T, TQueryFnData>\n : // Part 3: responsible for mapping inferred type to results, if no explicit parameter was provided\n T extends {\n queryFn?:\n | QueryFunction<infer TQueryFnData, any>\n | SkipTokenForUseQueries\n select?: (data: any) => infer TData\n throwOnError?: ThrowOnError<any, infer TError, any, any>\n }\n ? GetDefinedOrUndefinedQueryResult<\n T,\n unknown extends TData ? TQueryFnData : TData,\n unknown extends TError ? DefaultError : TError\n >\n : // Fallback\n UseQueryResult\n\n/**\n * The `queries` array accepted by `useQueries`. Recursively unwraps each tuple element so every entry's\n * `queryFn`/`select`/`throwOnError` are inferred individually, up to 20 elements. An opaque array (e.g.\n * `unknown[]`) is returned as-is; a non-tuple array of a known element type, or a tuple past 20 elements, falls\n * back to a single homogeneous options type.\n *\n * @template T - The type of the `queries` array as written at the call site.\n * @template TResults - The internal accumulator that this type builds during recursion. It is not meant\n * to be set explicitly.\n * @template TDepth - The internal recursion-depth counter, checked against the 20-element limit. It is not\n * meant to be set explicitly.\n */\nexport type QueriesOptions<\n T extends Array<any>,\n TResults extends Array<any> = [],\n TDepth extends ReadonlyArray<number> = [],\n> = TDepth['length'] extends MAXIMUM_DEPTH\n ? Array<UseQueryOptionsForUseQueries>\n : T extends []\n ? []\n : T extends [infer Head]\n ? [...TResults, GetUseQueryOptionsForUseQueries<Head>]\n : T extends [infer Head, ...infer Tails]\n ? QueriesOptions<\n [...Tails],\n [...TResults, GetUseQueryOptionsForUseQueries<Head>],\n [...TDepth, 1]\n >\n : ReadonlyArray<unknown> extends T\n ? T\n : // If T is *some* array but we couldn't assign unknown[] to it, then it must hold some known/homogeneous type!\n // use this to infer the param types in the case of Array.map() argument\n T extends Array<\n UseQueryOptionsForUseQueries<\n infer TQueryFnData,\n infer TError,\n infer TData,\n infer TQueryKey\n >\n >\n ? Array<\n UseQueryOptionsForUseQueries<\n TQueryFnData,\n TError,\n TData,\n TQueryKey\n >\n >\n : // Fallback\n Array<UseQueryOptionsForUseQueries>\n\n/**\n * The result type returned by `useQueries`, when no `combine` is provided. Mirrors {@link QueriesOptions}: each\n * tuple element's result type is inferred individually, up to 20 elements. A non-tuple array is mapped\n * per-element instead, still inferring each entry individually; only past 20 elements does this fall back to a\n * single homogeneous {@link UseQueryResult} type.\n *\n * @template T - The type of the `queries` array, as inferred by {@link QueriesOptions}.\n * @template TResults - The internal accumulator that this type builds during recursion. It is not meant\n * to be set explicitly.\n * @template TDepth - The internal recursion-depth counter, checked against the 20-element limit. It is not\n * meant to be set explicitly.\n */\nexport type QueriesResults<\n T extends Array<any>,\n TResults extends Array<any> = [],\n TDepth extends ReadonlyArray<number> = [],\n> = TDepth['length'] extends MAXIMUM_DEPTH\n ? Array<UseQueryResult>\n : T extends []\n ? []\n : T extends [infer Head]\n ? [...TResults, GetUseQueryResult<Head>]\n : T extends [infer Head, ...infer Tails]\n ? QueriesResults<\n [...Tails],\n [...TResults, GetUseQueryResult<Head>],\n [...TDepth, 1]\n >\n : { [K in keyof T]: GetUseQueryResult<T[K]> }\n\n/**\n * The `useQueries` hook can be used to fetch a variable number of queries.\n *\n * The `queries` key accepts an array with query option objects mostly identical to `useQuery` — see the\n * `queries` parameter below for the differences. A custom `QueryClient` is supplied once, as `useQueries`' own\n * top-level second argument, rather than per query.\n *\n * Having the same query key more than once in the array of query objects may cause some data to be shared\n * between queries. To avoid this, consider de-duplicating the queries and map the results back to the desired\n * structure.\n *\n * The `combine` option can be used to combine the results of the queries into a single value. The result will\n * be structurally shared to be as referentially stable as possible.\n *\n * @param queryClient - Use this to provide a custom `QueryClient`. Otherwise, the one from the nearest context\n * will be used.\n * @returns The combined result. Without `combine`, this is an array with all the query results, in the same\n * order as the input. When `combine` is provided, this is the value returned by `combine` instead.\n *\n * @example\n * ```tsx\n * import { useQueries } from '@tanstack/preact-query'\n *\n * function Posts({ ids }: { ids: Array<number> }) {\n * const postQueries = useQueries({\n * queries: ids.map((id) => ({\n * queryKey: ['post', id],\n * queryFn: () => fetchPost(id),\n * staleTime: Infinity,\n * })),\n * })\n *\n * return (\n * <ul>\n * {postQueries.map((query, index) => {\n * if (query.isPending) return <li key={ids[index]}>Loading...</li>\n * if (query.isError) return <li key={ids[index]}>Error: {query.error.message}</li>\n * return <li key={ids[index]}>{query.data.title}</li>\n * })}\n * </ul>\n * )\n * }\n * ```\n *\n * @example\n * Combining results into a single value:\n * ```tsx\n * import { useQueries } from '@tanstack/preact-query'\n *\n * function Posts({ ids }: { ids: Array<number> }) {\n * const { data, isPending, isError } = useQueries({\n * queries: ids.map((id) => ({\n * queryKey: ['post', id],\n * queryFn: () => fetchPost(id),\n * })),\n * combine: (postQueries) => {\n * return {\n * data: postQueries.map((query) => query.data),\n * isPending: postQueries.some((query) => query.isPending),\n * isError: postQueries.some((query) => query.isError),\n * }\n * },\n * })\n *\n * if (isPending) return 'Loading...'\n * if (isError) return 'Error loading posts'\n *\n * return (\n * <ul>\n * {data.map((post) => (\n * <li key={post?.id}>{post?.title}</li>\n * ))}\n * </ul>\n * )\n * }\n * ```\n */\nexport function useQueries<\n T extends Array<any>,\n TCombinedResult = QueriesResults<T>,\n>(\n {\n queries,\n ...options\n }: {\n /**\n * An array with query option objects, mostly identical to `useQuery` — except that `queryClient` and\n * `subscribed` aren't accepted per-query (`subscribed` is a top-level option here instead), and\n * `placeholderData` accepts a {@link QueriesPlaceholderDataFunction}, which is called with `previousData`\n * and `previousQuery` always `undefined`, rather than `useQuery`'s placeholder function.\n */\n queries:\n | readonly [...QueriesOptions<T>]\n | readonly [...{ [K in keyof T]: GetUseQueryOptionsForUseQueries<T[K]> }]\n /**\n * Use this to combine the results of the queries into a single value. The result will be structurally\n * shared to be as referentially stable as possible.\n */\n combine?: (result: QueriesResults<T>) => TCombinedResult\n /**\n * Set this to `false` to unsubscribe this observer from updates to the query cache.\n *\n * @defaultValue true\n */\n subscribed?: boolean\n },\n queryClient?: QueryClient,\n): TCombinedResult {\n const client = useQueryClient(queryClient)\n const isRestoring = useIsRestoring()\n const errorResetBoundary = useQueryErrorResetBoundary()\n const subscribed = options.subscribed !== false\n\n const defaultedQueries = useMemo(\n () =>\n queries.map((opts) => {\n const defaultedOptions = client.defaultQueryOptions(\n opts as QueryObserverOptions,\n )\n\n // Make sure the results are already in fetching state before subscribing or updating options\n defaultedOptions._optimisticResults = isRestoring\n ? 'isRestoring'\n : subscribed\n ? 'optimistic'\n : undefined\n\n return defaultedOptions\n }),\n [queries, client, isRestoring, subscribed],\n )\n\n defaultedQueries.forEach((queryOptions) => {\n ensureSuspenseTimers(queryOptions)\n const query = client.getQueryCache().get(queryOptions.queryHash)\n ensurePreventErrorBoundaryRetry(queryOptions, errorResetBoundary, query)\n })\n\n useClearResetErrorBoundary(errorResetBoundary)\n\n const [observer] = useState(\n () =>\n new QueriesObserver<TCombinedResult>(\n client,\n defaultedQueries,\n options as QueriesObserverOptions<TCombinedResult>,\n ),\n )\n\n // note: this must be called before useSyncExternalStore\n const [optimisticResult, getCombinedResult, trackResult] =\n observer.getOptimisticResult(\n defaultedQueries,\n (options as QueriesObserverOptions<TCombinedResult>).combine,\n )\n\n const shouldSubscribe = !isRestoring && subscribed\n useSyncExternalStore(\n useCallback(\n (onStoreChange) =>\n shouldSubscribe\n ? observer.subscribe(notifyManager.batchCalls(onStoreChange))\n : noop,\n [observer, shouldSubscribe],\n ),\n () => observer.getCurrentResult(),\n )\n\n useEffect(() => {\n observer.setQueries(\n defaultedQueries,\n options as QueriesObserverOptions<TCombinedResult>,\n )\n }, [defaultedQueries, options, observer])\n\n const shouldAtLeastOneSuspend = optimisticResult.some((result, index) =>\n shouldSuspend(defaultedQueries[index], result),\n )\n\n const suspensePromises = shouldAtLeastOneSuspend\n ? optimisticResult.flatMap((result, index) => {\n const opts = defaultedQueries[index]\n\n if (opts && shouldSuspend(opts, result)) {\n const queryObserver = new QueryObserver(client, opts)\n return fetchOptimistic(opts, queryObserver, errorResetBoundary)\n }\n return []\n })\n : []\n\n if (suspensePromises.length > 0) {\n throw Promise.all(suspensePromises)\n }\n const firstSingleResultWhichShouldThrow = optimisticResult.find(\n (result, index) => {\n const query = defaultedQueries[index]\n return (\n query &&\n getHasError({\n result,\n errorResetBoundary,\n throwOnError: query.throwOnError,\n query: client.getQueryCache().get(query.queryHash),\n suspense: query.suspense,\n })\n )\n },\n )\n\n if (firstSingleResultWhichShouldThrow) {\n throw firstSingleResultWhichShouldThrow.error\n }\n\n return getCombinedResult(trackResult())\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA6SA,SAAgB,WAId,EACE,SACA,GAAG,WAuBL,aACiB;CACjB,MAAM,SAAS,eAAe,WAAW;CACzC,MAAM,cAAc,eAAe;CACnC,MAAM,qBAAqB,2BAA2B;CACtD,MAAM,aAAa,QAAQ,eAAe;CAE1C,MAAM,mBAAmB,cAErB,QAAQ,KAAK,SAAS;EACpB,MAAM,mBAAmB,OAAO,oBAC9B,IACF;EAGA,iBAA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S;GACjD,UAAU,MAAM;EAClB,CAAC;CAEL,CACF;CAEA,IAAI,mCACF,MAAM,kCAAkC;CAG1C,OAAO,kBAAkB,YAAY,CAAC;AACxC"}
1
+ {"version":3,"file":"useQueries.js","names":[],"sources":["../../src/useQueries.ts"],"sourcesContent":["import {\n QueriesObserver,\n QueryObserver,\n noop,\n notifyManager,\n} from '@tanstack/query-core'\nimport type {\n DefaultError,\n OmitKeyof,\n QueriesObserverOptions,\n QueriesPlaceholderDataFunction,\n QueryClient,\n QueryFunction,\n QueryKey,\n QueryObserverOptions,\n ThrowOnError,\n} from '@tanstack/query-core'\nimport { useCallback, useEffect, useMemo, useState } from 'preact/hooks'\n\nimport { useIsRestoring } from './IsRestoringProvider'\nimport { useQueryClient } from './QueryClientProvider'\nimport { useQueryErrorResetBoundary } from './QueryErrorResetBoundary'\nimport {\n ensurePreventErrorBoundaryRetry,\n getHasError,\n useClearResetErrorBoundary,\n} from './errorBoundaryUtils'\nimport {\n ensureSuspenseTimers,\n fetchOptimistic,\n shouldSuspend,\n} from './suspense'\nimport type {\n DefinedUseQueryResult,\n UseQueryOptions,\n UseQueryResult,\n} from './types'\nimport { useSyncExternalStore } from './utils'\n\n// This defines the `UseQueryOptions` that are accepted in `QueriesOptions` & `GetOptions`.\n// `placeholderData` function always gets undefined passed\ntype UseQueryOptionsForUseQueries<\n TQueryFnData = unknown,\n TError = DefaultError,\n TData = TQueryFnData,\n TQueryKey extends QueryKey = QueryKey,\n> = OmitKeyof<\n UseQueryOptions<TQueryFnData, TError, TData, TQueryKey>,\n 'placeholderData' | 'subscribed'\n> & {\n placeholderData?: TQueryFnData | QueriesPlaceholderDataFunction<TQueryFnData>\n}\n\n// Avoid TS depth-limit error in case of large array literal\ntype MAXIMUM_DEPTH = 20\n\n// Widen the type of the symbol to enable type inference even if skipToken is not immutable.\ntype SkipTokenForUseQueries = symbol\n\ntype GetUseQueryOptionsForUseQueries<T> =\n // Part 1: responsible for applying explicit type parameter to function arguments, if object { queryFnData: TQueryFnData, error: TError, data: TData }\n T extends {\n queryFnData: infer TQueryFnData\n error?: infer TError\n data: infer TData\n }\n ? UseQueryOptionsForUseQueries<TQueryFnData, TError, TData>\n : T extends { queryFnData: infer TQueryFnData; error?: infer TError }\n ? UseQueryOptionsForUseQueries<TQueryFnData, TError>\n : T extends { data: infer TData; error?: infer TError }\n ? UseQueryOptionsForUseQueries<unknown, TError, TData>\n : // Part 2: responsible for applying explicit type parameter to function arguments, if tuple [TQueryFnData, TError, TData]\n T extends [infer TQueryFnData, infer TError, infer TData]\n ? UseQueryOptionsForUseQueries<TQueryFnData, TError, TData>\n : T extends [infer TQueryFnData, infer TError]\n ? UseQueryOptionsForUseQueries<TQueryFnData, TError>\n : T extends [infer TQueryFnData]\n ? UseQueryOptionsForUseQueries<TQueryFnData>\n : // Part 3: responsible for inferring and enforcing type if no explicit parameter was provided\n T extends {\n queryFn?:\n | QueryFunction<infer TQueryFnData, infer TQueryKey>\n | SkipTokenForUseQueries\n select?: (data: any) => infer TData\n throwOnError?: ThrowOnError<any, infer TError, any, any>\n }\n ? UseQueryOptionsForUseQueries<\n TQueryFnData,\n unknown extends TError ? DefaultError : TError,\n unknown extends TData ? TQueryFnData : TData,\n TQueryKey\n >\n : // Fallback\n UseQueryOptionsForUseQueries\n\n// A defined initialData setting should return a DefinedUseQueryResult rather than UseQueryResult\ntype GetDefinedOrUndefinedQueryResult<T, TData, TError = unknown> = T extends {\n initialData?: infer TInitialData\n}\n ? unknown extends TInitialData\n ? UseQueryResult<TData, TError>\n : TInitialData extends TData\n ? DefinedUseQueryResult<TData, TError>\n : TInitialData extends () => infer TInitialDataResult\n ? unknown extends TInitialDataResult\n ? UseQueryResult<TData, TError>\n : TInitialDataResult extends TData\n ? DefinedUseQueryResult<TData, TError>\n : UseQueryResult<TData, TError>\n : UseQueryResult<TData, TError>\n : UseQueryResult<TData, TError>\n\ntype GetUseQueryResult<T> =\n // Part 1: responsible for mapping explicit type parameter to function result, if object\n T extends { queryFnData: any; error?: infer TError; data: infer TData }\n ? GetDefinedOrUndefinedQueryResult<T, TData, TError>\n : T extends { queryFnData: infer TQueryFnData; error?: infer TError }\n ? GetDefinedOrUndefinedQueryResult<T, TQueryFnData, TError>\n : T extends { data: infer TData; error?: infer TError }\n ? GetDefinedOrUndefinedQueryResult<T, TData, TError>\n : // Part 2: responsible for mapping explicit type parameter to function result, if tuple\n T extends [any, infer TError, infer TData]\n ? GetDefinedOrUndefinedQueryResult<T, TData, TError>\n : T extends [infer TQueryFnData, infer TError]\n ? GetDefinedOrUndefinedQueryResult<T, TQueryFnData, TError>\n : T extends [infer TQueryFnData]\n ? GetDefinedOrUndefinedQueryResult<T, TQueryFnData>\n : // Part 3: responsible for mapping inferred type to results, if no explicit parameter was provided\n T extends {\n queryFn?:\n | QueryFunction<infer TQueryFnData, any>\n | SkipTokenForUseQueries\n select?: (data: any) => infer TData\n throwOnError?: ThrowOnError<any, infer TError, any, any>\n }\n ? GetDefinedOrUndefinedQueryResult<\n T,\n unknown extends TData ? TQueryFnData : TData,\n unknown extends TError ? DefaultError : TError\n >\n : // Fallback\n UseQueryResult\n\n/**\n * The `queries` array accepted by `useQueries`. Recursively unwraps each tuple element so every entry's\n * `queryFn`/`select`/`throwOnError` are inferred individually, up to 20 elements — past that, a tuple falls\n * back to a single homogeneous options type.\n *\n * An opaque array (e.g. `unknown[]`) is returned as-is; a non-tuple array whose element type structurally\n * matches a query options object is mapped per-element instead, still inferring each entry individually; any\n * other non-tuple array — one whose element type doesn't match the expected options shape — falls back to\n * that same homogeneous options type too.\n *\n * @template T - The type of the `queries` array as written at the call site.\n * @template TResults - The internal accumulator that this type builds during recursion. It is not meant\n * to be set explicitly.\n * @template TDepth - The internal recursion-depth counter, checked against the 20-element limit. It is not\n * meant to be set explicitly.\n */\nexport type QueriesOptions<\n T extends Array<any>,\n TResults extends Array<any> = [],\n TDepth extends ReadonlyArray<number> = [],\n> = TDepth['length'] extends MAXIMUM_DEPTH\n ? Array<UseQueryOptionsForUseQueries>\n : T extends []\n ? []\n : T extends [infer Head]\n ? [...TResults, GetUseQueryOptionsForUseQueries<Head>]\n : T extends [infer Head, ...infer Tails]\n ? QueriesOptions<\n [...Tails],\n [...TResults, GetUseQueryOptionsForUseQueries<Head>],\n [...TDepth, 1]\n >\n : ReadonlyArray<unknown> extends T\n ? T\n : // If T is *some* array but we couldn't assign unknown[] to it, then it must hold some known/homogeneous type!\n // use this to infer the param types in the case of Array.map() argument\n T extends Array<\n UseQueryOptionsForUseQueries<\n infer TQueryFnData,\n infer TError,\n infer TData,\n infer TQueryKey\n >\n >\n ? Array<\n UseQueryOptionsForUseQueries<\n TQueryFnData,\n TError,\n TData,\n TQueryKey\n >\n >\n : // Fallback\n Array<UseQueryOptionsForUseQueries>\n\n/**\n * The result type returned by `useQueries`, when no `combine` is provided. Mirrors {@link QueriesOptions}: each\n * tuple element's result type is inferred individually, up to 20 elements. A non-tuple array is mapped\n * per-element instead, still inferring each entry individually; only past 20 elements does this fall back to a\n * single homogeneous {@link UseQueryResult} type.\n *\n * @template T - The type of the `queries` array, as inferred by {@link QueriesOptions}.\n * @template TResults - The internal accumulator that this type builds during recursion. It is not meant\n * to be set explicitly.\n * @template TDepth - The internal recursion-depth counter, checked against the 20-element limit. It is not\n * meant to be set explicitly.\n */\nexport type QueriesResults<\n T extends Array<any>,\n TResults extends Array<any> = [],\n TDepth extends ReadonlyArray<number> = [],\n> = TDepth['length'] extends MAXIMUM_DEPTH\n ? Array<UseQueryResult>\n : T extends []\n ? []\n : T extends [infer Head]\n ? [...TResults, GetUseQueryResult<Head>]\n : T extends [infer Head, ...infer Tails]\n ? QueriesResults<\n [...Tails],\n [...TResults, GetUseQueryResult<Head>],\n [...TDepth, 1]\n >\n : { [K in keyof T]: GetUseQueryResult<T[K]> }\n\n/**\n * The `useQueries` hook can be used to fetch a variable number of queries.\n *\n * The `queries` key accepts an array with query option objects mostly identical to `useQuery` — see the\n * `queries` parameter below for the differences. A custom `QueryClient` is supplied once, as `useQueries`' own\n * top-level second argument, rather than per query.\n *\n * Having the same query key more than once in the array of query objects may cause some data to be shared\n * between queries. To avoid this, consider de-duplicating the queries and map the results back to the desired\n * structure.\n *\n * The `combine` option can be used to combine the results of the queries into a single value. The result will\n * be structurally shared to be as referentially stable as possible.\n *\n * @param queryClient - Use this to provide a custom `QueryClient`. Otherwise, the one from the nearest context\n * will be used.\n * @returns The combined result. Without `combine`, this is an array with all the query results, in the same\n * order as the input. When `combine` is provided, this is the value returned by `combine` instead.\n *\n * @example\n * ```tsx\n * import { useQueries } from '@tanstack/preact-query'\n *\n * function Posts({ ids }: { ids: Array<number> }) {\n * const postQueries = useQueries({\n * queries: ids.map((id) => ({\n * queryKey: ['post', id],\n * queryFn: () => fetchPost(id),\n * staleTime: Infinity,\n * })),\n * })\n *\n * return (\n * <ul>\n * {postQueries.map((query, index) => {\n * if (query.isPending) return <li key={ids[index]}>Loading...</li>\n * if (query.isError) return <li key={ids[index]}>Error: {query.error.message}</li>\n * return <li key={ids[index]}>{query.data.title}</li>\n * })}\n * </ul>\n * )\n * }\n * ```\n *\n * @example\n * Combining results into a single value:\n * ```tsx\n * import { useQueries } from '@tanstack/preact-query'\n *\n * function Posts({ ids }: { ids: Array<number> }) {\n * const { data, isPending, isError } = useQueries({\n * queries: ids.map((id) => ({\n * queryKey: ['post', id],\n * queryFn: () => fetchPost(id),\n * })),\n * combine: (postQueries) => {\n * return {\n * data: postQueries.map((query) => query.data),\n * isPending: postQueries.some((query) => query.isPending),\n * isError: postQueries.some((query) => query.isError),\n * }\n * },\n * })\n *\n * if (isPending) return 'Loading...'\n * if (isError) return 'Error loading posts'\n *\n * return (\n * <ul>\n * {data.map((post) => (\n * <li key={post?.id}>{post?.title}</li>\n * ))}\n * </ul>\n * )\n * }\n * ```\n */\nexport function useQueries<\n T extends Array<any>,\n TCombinedResult = QueriesResults<T>,\n>(\n {\n queries,\n ...options\n }: {\n /**\n * An array with query option objects, mostly identical to `useQuery` — except that `queryClient` and\n * `subscribed` aren't accepted per-query (`subscribed` is a top-level option here instead), and\n * `placeholderData` accepts a {@link QueriesPlaceholderDataFunction}, which is called with `previousData`\n * and `previousQuery` always `undefined`, rather than `useQuery`'s placeholder function.\n */\n queries:\n | readonly [...QueriesOptions<T>]\n | readonly [...{ [K in keyof T]: GetUseQueryOptionsForUseQueries<T[K]> }]\n /**\n * Use this to combine the results of the queries into a single value. The result will be structurally\n * shared to be as referentially stable as possible.\n */\n combine?: (result: QueriesResults<T>) => TCombinedResult\n /**\n * Set this to `false` to unsubscribe this observer from updates to the query cache.\n *\n * @defaultValue true\n */\n subscribed?: boolean\n },\n queryClient?: QueryClient,\n): TCombinedResult {\n const client = useQueryClient(queryClient)\n const isRestoring = useIsRestoring()\n const errorResetBoundary = useQueryErrorResetBoundary()\n const subscribed = options.subscribed !== false\n\n const defaultedQueries = useMemo(\n () =>\n queries.map((opts) => {\n const defaultedOptions = client.defaultQueryOptions(\n opts as QueryObserverOptions,\n )\n\n // Make sure the results are already in fetching state before subscribing or updating options\n defaultedOptions._optimisticResults = isRestoring\n ? 'isRestoring'\n : subscribed\n ? 'optimistic'\n : undefined\n\n return defaultedOptions\n }),\n [queries, client, isRestoring, subscribed],\n )\n\n defaultedQueries.forEach((queryOptions) => {\n ensureSuspenseTimers(queryOptions)\n const query = client.getQueryCache().get(queryOptions.queryHash)\n ensurePreventErrorBoundaryRetry(queryOptions, errorResetBoundary, query)\n })\n\n useClearResetErrorBoundary(errorResetBoundary)\n\n const [observer] = useState(\n () =>\n new QueriesObserver<TCombinedResult>(\n client,\n defaultedQueries,\n options as QueriesObserverOptions<TCombinedResult>,\n ),\n )\n\n // note: this must be called before useSyncExternalStore\n const [optimisticResult, getCombinedResult, trackResult] =\n observer.getOptimisticResult(\n defaultedQueries,\n (options as QueriesObserverOptions<TCombinedResult>).combine,\n )\n\n const shouldSubscribe = !isRestoring && subscribed\n useSyncExternalStore(\n useCallback(\n (onStoreChange) =>\n shouldSubscribe\n ? observer.subscribe(notifyManager.batchCalls(onStoreChange))\n : noop,\n [observer, shouldSubscribe],\n ),\n () => observer.getCurrentResult(),\n )\n\n useEffect(() => {\n observer.setQueries(\n defaultedQueries,\n options as QueriesObserverOptions<TCombinedResult>,\n )\n }, [defaultedQueries, options, observer])\n\n const shouldAtLeastOneSuspend = optimisticResult.some((result, index) =>\n shouldSuspend(defaultedQueries[index], result),\n )\n\n const suspensePromises = shouldAtLeastOneSuspend\n ? optimisticResult.flatMap((result, index) => {\n const opts = defaultedQueries[index]\n\n if (opts && shouldSuspend(opts, result)) {\n const queryObserver = new QueryObserver(client, opts)\n return fetchOptimistic(opts, queryObserver, errorResetBoundary)\n }\n return []\n })\n : []\n\n if (suspensePromises.length > 0) {\n throw Promise.all(suspensePromises)\n }\n const firstSingleResultWhichShouldThrow = optimisticResult.find(\n (result, index) => {\n const query = defaultedQueries[index]\n return (\n query &&\n getHasError({\n result,\n errorResetBoundary,\n throwOnError: query.throwOnError,\n query: client.getQueryCache().get(query.queryHash),\n suspense: query.suspense,\n })\n )\n },\n )\n\n if (firstSingleResultWhichShouldThrow) {\n throw firstSingleResultWhichShouldThrow.error\n }\n\n return getCombinedResult(trackResult())\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAiTA,SAAgB,WAId,EACE,SACA,GAAG,WAuBL,aACiB;CACjB,MAAM,SAAS,eAAe,WAAW;CACzC,MAAM,cAAc,eAAe;CACnC,MAAM,qBAAqB,2BAA2B;CACtD,MAAM,aAAa,QAAQ,eAAe;CAE1C,MAAM,mBAAmB,cAErB,QAAQ,KAAK,SAAS;EACpB,MAAM,mBAAmB,OAAO,oBAC9B,IACF;EAGA,iBAAiB,qBAAqB,cAClC,gBACA,aACE,eACA,KAAA;EAEN,OAAO;CACT,CAAC,GACH;EAAC;EAAS;EAAQ;EAAa;CAAU,CAC3C;CAEA,iBAAiB,SAAS,i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 @@
1
- {"version":3,"file":"useQuery.cjs","names":["useBaseQuery","QueryObserver"],"sources":["../../src/useQuery.ts"],"sourcesContent":["import { QueryObserver } from '@tanstack/query-core'\nimport type { DefaultError, QueryClient, QueryKey } from '@tanstack/query-core'\n\nimport type {\n DefinedInitialDataOptions,\n UndefinedInitialDataOptions,\n} from './queryOptions'\nimport type {\n DefinedUseQueryResult,\n UseQueryOptions,\n UseQueryResult,\n} from './types'\nimport { useBaseQuery } from './useBaseQuery'\n\n/**\n * This overload is selected when `initialData` is set, so the resulting `data` is never `undefined`.\n *\n * @see {@link queryOptions} to share these options between `useQuery` and imperative APIs like `queryClient.query`.\n * @param options - The {@link DefinedInitialDataOptions} to use — everything you can pass to `useQuery`, with `initialData` set.\n * @param queryClient - Use this to use a custom `QueryClient`. Otherwise, the one from the nearest context will\n * be used.\n * @returns The current query result, typed so that `status` is `success` — or `error` if a fetch attempt\n * fails while keeping the existing data (`status` never resolves to `pending` in this overload's type,\n * since `initialData` guarantees data upfront). `isSuccess`/`isError` are derived booleans for convenience.\n *\n * @example\n * ```tsx\n * import { useQuery } from '@tanstack/preact-query'\n *\n * function Posts() {\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({\n * queryKey: ['posts'],\n * queryFn: fetchPosts,\n * initialData: [],\n * })\n *\n * return (\n * <div>\n * {isError ? <span>Error: {error.message}</span> : null}\n * <ul>\n * {data.map((post) => <li key={post.id}>{post.title}</li>)}\n * </ul>\n * </div>\n * )\n * }\n * ```\n */\nexport function useQuery<\n TQueryFnData = unknown,\n TError = DefaultError,\n TData = TQueryFnData,\n TQueryKey extends QueryKey = QueryKey,\n>(\n options: DefinedInitialDataOptions<TQueryFnData, TError, TData, TQueryKey>,\n queryClient?: QueryClient,\n): DefinedUseQueryResult<TData, TError>\n\n/**\n * @see {@link queryOptions} to share these options between `useQuery` and imperative APIs like `queryClient.query`.\n * @param options - The {@link UndefinedInitialDataOptions} to use — everything you can pass to `useQuery`.\n * @param queryClient - Use this to use a custom `QueryClient`. Otherwise, the one from the nearest context will\n * be used.\n * @returns The current query result. `status` is `pending` if there is no cached data to display, `error` if\n * the last fetch attempt failed, or `success` if the query has data to display. `isPending`/`isSuccess`/`isError`\n * are derived booleans for convenience.\n *\n * @example\n * ```tsx\n * import { useQuery } from '@tanstack/preact-query'\n *\n * function Posts() {\n * const { status, data, error, isFetching } = useQuery({\n * queryKey: ['posts'],\n * queryFn: fetchPosts,\n * })\n *\n * if (status === 'pending') return 'Loading...'\n * if (status === 'error') return <span>Error: {error.message}</span>\n *\n * return (\n * <div>\n * <ul>\n * {data.map((post) => (\n * <li key={post.id}>{post.title}</li>\n * ))}\n * </ul>\n * <div>{isFetching ? 'Background Updating...' : ' '}</div>\n * </div>\n * )\n * }\n * ```\n *\n * @example\n * The same query, checking `isPending`/`isError` instead of `status` — pick whichever reads better to you:\n * ```tsx\n * import { useQuery } from '@tanstack/preact-query'\n *\n * function Posts() {\n * const { isPending, isError, data, error } = useQuery({\n * queryKey: ['posts'],\n * queryFn: fetchPosts,\n * })\n *\n * if (isPending) return 'Loading...'\n * if (isError) return <span>Error: {error.message}</span>\n *\n * return (\n * <ul>\n * {data.map((post) => <li key={post.id}>{post.title}</li>)}\n * </ul>\n * )\n * }\n * ```\n */\nexport function useQuery<\n TQueryFnData = unknown,\n TError = DefaultError,\n TData = TQueryFnData,\n TQueryKey extends QueryKey = QueryKey,\n>(\n options: UndefinedInitialDataOptions<TQueryFnData, TError, TData, TQueryKey>,\n queryClient?: QueryClient,\n): UseQueryResult<TData, TError>\n\n/**\n * @see {@link queryOptions} to share these options between `useQuery` and imperative APIs like `queryClient.query`.\n * @param options - The {@link UseQueryOptions} to use — everything you can pass to `useQuery`.\n * @param queryClient - Use this to use a custom `QueryClient`. Otherwise, the one from the nearest context will\n * be used.\n * @returns The current query result. `status` is `pending` if there is no cached data to display, `error` if\n * the last fetch attempt failed, or `success` if the query has data to display. `isPending`/`isSuccess`/`isError`\n * are derived booleans for convenience.\n *\n * @example\n * ```tsx\n * import { useQuery } from '@tanstack/preact-query'\n *\n * function Posts() {\n * const { status, data, error, isFetching } = useQuery({\n * queryKey: ['posts'],\n * queryFn: fetchPosts,\n * })\n *\n * if (status === 'pending') return 'Loading...'\n * if (status === 'error') return <span>Error: {error.message}</span>\n *\n * return (\n * <div>\n * <ul>\n * {data.map((post) => (\n * <li key={post.id}>{post.title}</li>\n * ))}\n * </ul>\n * <div>{isFetching ? 'Background Updating...' : ' '}</div>\n * </div>\n * )\n * }\n * ```\n *\n * @example\n * `select` derives whatever `data` a component needs from the cached value, without changing what's\n * actually stored in the cache — the cache still holds the full `Post[]`, but `data` here is a `number`:\n * ```tsx\n * import { useQuery } from '@tanstack/preact-query'\n *\n * function PostCount() {\n * const { data, isPending, isError, error } = useQuery({\n * queryKey: ['posts'],\n * queryFn: fetchPosts,\n * select: (posts) => posts.length,\n * })\n *\n * if (isPending) return 'Loading...'\n * if (isError) return <span>Error: {error.message}</span>\n *\n * return <span>{data} posts</span>\n * }\n * ```\n *\n * @example\n * A dependent query, only enabled once `postId` is set — use `isLoading`, not `isPending`, so the\n * loading state doesn't show while the query is disabled:\n * ```tsx\n * import { useQuery } from '@tanstack/preact-query'\n *\n * function Post({ postId }: { postId: number | undefined }) {\n * const { data, isLoading, isError, error } = useQuery({\n * queryKey: ['post', postId],\n * queryFn: () => fetchPost(postId!),\n * enabled: postId != null,\n * })\n *\n * if (postId == null) return 'Select a post'\n * if (isLoading) return 'Loading...'\n * if (isError) return <span>Error: {error.message}</span>\n *\n * return <h1>{data?.title}</h1>\n * }\n * ```\n *\n * @example\n * The same dependent query, type safe: `skipToken` disables the query without needing the\n * non-null assertion above, since `queryFn` is only ever called when `postId` is defined.\n * `refetch` doesn't work while `queryFn` is `skipToken` — use `enabled: false` instead if you\n * need to trigger the query manually:\n * ```tsx\n * import { skipToken, useQuery } from '@tanstack/preact-query'\n *\n * function Post({ postId }: { postId: number | undefined }) {\n * const { data, isLoading, isError, error } = useQuery({\n * queryKey: ['post', postId],\n * queryFn: postId != null ? () => fetchPost(postId) : skipToken,\n * })\n *\n * if (postId == null) return 'Select a post'\n * if (isLoading) return 'Loading...'\n * if (isError) return <span>Error: {error.message}</span>\n *\n * return <h1>{data?.title}</h1>\n * }\n * ```\n *\n * @example\n * Seeding a detail query from an already-cached list, to skip the loading state:\n * ```tsx\n * import { useQuery, useQueryClient } from '@tanstack/preact-query'\n *\n * function Post({ postId }: { postId: number }) {\n * const queryClient = useQueryClient()\n *\n * const { data, isError, error } = useQuery({\n * queryKey: ['post', postId],\n * queryFn: () => fetchPost(postId),\n * initialData: () =>\n * queryClient\n * .getQueryData<Array<Post>>(['posts'])\n * ?.find((post) => post.id === postId),\n * })\n *\n * if (isError) return <span>Error: {error.message}</span>\n *\n * return <h1>{data?.title}</h1>\n * }\n * ```\n *\n * @example\n * Paginated data, keeping the previous page's data visible while the next page loads:\n * ```tsx\n * import { keepPreviousData, useQuery } from '@tanstack/preact-query'\n * import { useState } from 'preact/hooks'\n *\n * function Posts() {\n * const [page, setPage] = useState(0)\n *\n * const { data, isPlaceholderData, isError, error } = useQuery({\n * queryKey: ['posts', page],\n * queryFn: () => fetchPosts(page),\n * placeholderData: keepPreviousData,\n * })\n *\n * if (isError) return <span>Error: {error.message}</span>\n *\n * return (\n * <div>\n * <ul>\n * {data?.map((post) => <li key={post.id}>{post.title}</li>)}\n * </ul>\n * <button\n * disabled={isPlaceholderData}\n * onClick={() => setPage((old) => old + 1)}\n * >\n * Next Page\n * </button>\n * </div>\n * )\n * }\n * ```\n */\nexport function useQuery<\n TQueryFnData = unknown,\n TError = DefaultError,\n TData = TQueryFnData,\n TQueryKey extends QueryKey = QueryKey,\n>(\n options: UseQueryOptions<TQueryFnData, TError, TData, TQueryKey>,\n queryClient?: QueryClient,\n): UseQueryResult<TData, TError>\n\nexport function useQuery(options: UseQueryOptions, queryClient?: QueryClient) {\n return useBaseQuery(options, QueryObserver, queryClient)\n}\n"],"mappings":";;;;AAkSA,SAAgB,SAAS,SAA0B,aAA2B;CAC5E,OAAOA,qBAAAA,aAAa,SAASC,qBAAAA,eAAe,WAAW;AACzD"}
1
+ {"version":3,"file":"useQuery.cjs","names":["useBaseQuery","QueryObserver"],"sources":["../../src/useQuery.ts"],"sourcesContent":["import { QueryObserver } from '@tanstack/query-core'\nimport type { DefaultError, QueryClient, QueryKey } from '@tanstack/query-core'\n\nimport type {\n DefinedInitialDataOptions,\n UndefinedInitialDataOptions,\n} from './queryOptions'\nimport type {\n DefinedUseQueryResult,\n UseQueryOptions,\n UseQueryResult,\n} from './types'\nimport { useBaseQuery } from './useBaseQuery'\n\n/**\n * This overload is selected when `initialData` is set, so the resulting `data` is never `undefined` (unless\n * a `select` changes `TData` to include `undefined`).\n *\n * @see {@link queryOptions} to share these options between `useQuery` and imperative APIs like `queryClient.query`.\n * @param options - The {@link DefinedInitialDataOptions} to use — everything you can pass to `useQuery`, with `initialData` set.\n * @param queryClient - Use this to use a custom `QueryClient`. Otherwise, the one from the nearest context will\n * be used.\n * @returns The current query result, typed so that `status` is `success` — or `error` if a fetch attempt\n * fails while keeping the existing data (`status` never resolves to `pending` in this overload's type,\n * since `initialData` guarantees data upfront). `isSuccess`/`isError` are derived booleans for convenience.\n *\n * @example\n * ```tsx\n * import { useQuery } from '@tanstack/preact-query'\n *\n * function Posts() {\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({\n * queryKey: ['posts'],\n * queryFn: fetchPosts,\n * initialData: [],\n * })\n *\n * return (\n * <div>\n * {isError ? <span>Error: {error.message}</span> : null}\n * <ul>\n * {data.map((post) => <li key={post.id}>{post.title}</li>)}\n * </ul>\n * </div>\n * )\n * }\n * ```\n */\nexport function useQuery<\n TQueryFnData = unknown,\n TError = DefaultError,\n TData = TQueryFnData,\n TQueryKey extends QueryKey = QueryKey,\n>(\n options: DefinedInitialDataOptions<TQueryFnData, TError, TData, TQueryKey>,\n queryClient?: QueryClient,\n): DefinedUseQueryResult<TData, TError>\n\n/**\n * @see {@link queryOptions} to share these options between `useQuery` and imperative APIs like `queryClient.query`.\n * @param options - The {@link UndefinedInitialDataOptions} to use — everything you can pass to `useQuery`.\n * @param queryClient - Use this to use a custom `QueryClient`. Otherwise, the one from the nearest context will\n * be used.\n * @returns The current query result. `status` is `pending` if there is no cached data to display, `error` if\n * the last fetch attempt failed, or `success` if the query has data to display. `isPending`/`isSuccess`/`isError`\n * are derived booleans for convenience.\n *\n * @example\n * ```tsx\n * import { useQuery } from '@tanstack/preact-query'\n *\n * function Posts() {\n * const { status, data, error, isFetching } = useQuery({\n * queryKey: ['posts'],\n * queryFn: fetchPosts,\n * })\n *\n * if (status === 'pending') return 'Loading...'\n * if (status === 'error') return <span>Error: {error.message}</span>\n *\n * return (\n * <div>\n * <ul>\n * {data.map((post) => (\n * <li key={post.id}>{post.title}</li>\n * ))}\n * </ul>\n * <div>{isFetching ? 'Background Updating...' : ' '}</div>\n * </div>\n * )\n * }\n * ```\n *\n * @example\n * The same query, checking `isPending`/`isError` instead of `status` — pick whichever reads better to you:\n * ```tsx\n * import { useQuery } from '@tanstack/preact-query'\n *\n * function Posts() {\n * const { isPending, isError, data, error } = useQuery({\n * queryKey: ['posts'],\n * queryFn: fetchPosts,\n * })\n *\n * if (isPending) return 'Loading...'\n * if (isError) return <span>Error: {error.message}</span>\n *\n * return (\n * <ul>\n * {data.map((post) => <li key={post.id}>{post.title}</li>)}\n * </ul>\n * )\n * }\n * ```\n */\nexport function useQuery<\n TQueryFnData = unknown,\n TError = DefaultError,\n TData = TQueryFnData,\n TQueryKey extends QueryKey = QueryKey,\n>(\n options: UndefinedInitialDataOptions<TQueryFnData, TError, TData, TQueryKey>,\n queryClient?: QueryClient,\n): UseQueryResult<TData, TError>\n\n/**\n * @see {@link queryOptions} to share these options between `useQuery` and imperative APIs like `queryClient.query`.\n * @param options - The {@link UseQueryOptions} to use — everything you can pass to `useQuery`.\n * @param queryClient - Use this to use a custom `QueryClient`. Otherwise, the one from the nearest context will\n * be used.\n * @returns The current query result. `status` is `pending` if there is no cached data to display, `error` if\n * the last fetch attempt failed, or `success` if the query has data to display. `isPending`/`isSuccess`/`isError`\n * are derived booleans for convenience.\n *\n * @example\n * ```tsx\n * import { useQuery } from '@tanstack/preact-query'\n *\n * function Posts() {\n * const { status, data, error, isFetching } = useQuery({\n * queryKey: ['posts'],\n * queryFn: fetchPosts,\n * })\n *\n * if (status === 'pending') return 'Loading...'\n * if (status === 'error') return <span>Error: {error.message}</span>\n *\n * return (\n * <div>\n * <ul>\n * {data.map((post) => (\n * <li key={post.id}>{post.title}</li>\n * ))}\n * </ul>\n * <div>{isFetching ? 'Background Updating...' : ' '}</div>\n * </div>\n * )\n * }\n * ```\n *\n * @example\n * `select` derives whatever `data` a component needs from the cached value, without changing what's\n * actually stored in the cache — the cache still holds the full `Post[]`, but `data` here is a `number`:\n * ```tsx\n * import { useQuery } from '@tanstack/preact-query'\n *\n * function PostCount() {\n * const { data, isPending, isError, error } = useQuery({\n * queryKey: ['posts'],\n * queryFn: fetchPosts,\n * select: (posts) => posts.length,\n * })\n *\n * if (isPending) return 'Loading...'\n * if (isError) return <span>Error: {error.message}</span>\n *\n * return <span>{data} posts</span>\n * }\n * ```\n *\n * @example\n * A dependent query, only enabled once `postId` is set — use `isLoading`, not `isPending`, so the\n * loading state doesn't show while the query is disabled:\n * ```tsx\n * import { useQuery } from '@tanstack/preact-query'\n *\n * function Post({ postId }: { postId: number | undefined }) {\n * const { data, isLoading, isError, error } = useQuery({\n * queryKey: ['post', postId],\n * queryFn: () => fetchPost(postId!),\n * enabled: postId != null,\n * })\n *\n * if (postId == null) return 'Select a post'\n * if (isLoading) return 'Loading...'\n * if (isError) return <span>Error: {error.message}</span>\n *\n * return <h1>{data?.title}</h1>\n * }\n * ```\n *\n * @example\n * The same dependent query, type safe: `skipToken` disables the query without needing the\n * non-null assertion above, since `queryFn` is only ever called when `postId` is defined.\n * `refetch` doesn't work while `queryFn` is `skipToken` — use `enabled: false` instead if you\n * need to trigger the query manually:\n * ```tsx\n * import { skipToken, useQuery } from '@tanstack/preact-query'\n *\n * function Post({ postId }: { postId: number | undefined }) {\n * const { data, isLoading, isError, error } = useQuery({\n * queryKey: ['post', postId],\n * queryFn: postId != null ? () => fetchPost(postId) : skipToken,\n * })\n *\n * if (postId == null) return 'Select a post'\n * if (isLoading) return 'Loading...'\n * if (isError) return <span>Error: {error.message}</span>\n *\n * return <h1>{data?.title}</h1>\n * }\n * ```\n *\n * @example\n * Seeding a detail query from an already-cached list, to skip the loading state. `initialDataUpdatedAt` carries\n * over the list's own fetch time, so that if you set a `staleTime`, it's measured from when the list was\n * fetched rather than from now:\n * ```tsx\n * import { useQuery, useQueryClient } from '@tanstack/preact-query'\n *\n * function Post({ postId }: { postId: number }) {\n * const queryClient = useQueryClient()\n *\n * const { data, isError, error } = useQuery({\n * queryKey: ['post', postId],\n * queryFn: () => fetchPost(postId),\n * initialData: () =>\n * queryClient\n * .getQueryData<Array<Post>>(['posts'])\n * ?.find((post) => post.id === postId),\n * initialDataUpdatedAt: () =>\n * queryClient.getQueryState(['posts'])?.dataUpdatedAt,\n * })\n *\n * if (isError) return <span>Error: {error.message}</span>\n *\n * return <h1>{data?.title}</h1>\n * }\n * ```\n *\n * @example\n * Paginated data, keeping the previous page's data visible while the next page loads:\n * ```tsx\n * import { keepPreviousData, useQuery } from '@tanstack/preact-query'\n * import { useState } from 'preact/hooks'\n *\n * function Posts() {\n * const [page, setPage] = useState(0)\n *\n * const { data, isPlaceholderData, isError, error } = useQuery({\n * queryKey: ['posts', page],\n * queryFn: () => fetchPosts(page),\n * placeholderData: keepPreviousData,\n * })\n *\n * if (isError) return <span>Error: {error.message}</span>\n *\n * return (\n * <div>\n * <ul>\n * {data?.map((post) => <li key={post.id}>{post.title}</li>)}\n * </ul>\n * <button\n * disabled={isPlaceholderData}\n * onClick={() => setPage((old) => old + 1)}\n * >\n * Next Page\n * </button>\n * </div>\n * )\n * }\n * ```\n */\nexport function useQuery<\n TQueryFnData = unknown,\n TError = DefaultError,\n TData = TQueryFnData,\n TQueryKey extends QueryKey = QueryKey,\n>(\n options: UseQueryOptions<TQueryFnData, TError, TData, TQueryKey>,\n queryClient?: QueryClient,\n): UseQueryResult<TData, TError>\n\nexport function useQuery(options: UseQueryOptions, queryClient?: QueryClient) {\n return useBaseQuery(options, QueryObserver, queryClient)\n}\n"],"mappings":";;;;AAuSA,SAAgB,SAAS,SAA0B,aAA2B;CAC5E,OAAOA,qBAAAA,aAAa,SAASC,qBAAAA,eAAe,WAAW;AACzD"}
@@ -3,7 +3,8 @@ import { DefinedInitialDataOptions, UndefinedInitialDataOptions } from "./queryO
3
3
  import { DefaultError, QueryClient, QueryKey } from "@tanstack/query-core";
4
4
  //#region src/useQuery.d.ts
5
5
  /**
6
- * This overload is selected when `initialData` is set, so the resulting `data` is never `undefined`.
6
+ * This overload is selected when `initialData` is set, so the resulting `data` is never `undefined` (unless
7
+ * a `select` changes `TData` to include `undefined`).
7
8
  *
8
9
  * @see {@link queryOptions} to share these options between `useQuery` and imperative APIs like `queryClient.query`.
9
10
  * @param options - The {@link DefinedInitialDataOptions} to use — everything you can pass to `useQuery`, with `initialData` set.
@@ -195,7 +196,9 @@ declare function useQuery<TQueryFnData = unknown, TError = DefaultError, TData =
195
196
  * ```
196
197
  *
197
198
  * @example
198
- * Seeding a detail query from an already-cached list, to skip the loading state:
199
+ * Seeding a detail query from an already-cached list, to skip the loading state. `initialDataUpdatedAt` carries
200
+ * over the list's own fetch time, so that if you set a `staleTime`, it's measured from when the list was
201
+ * fetched rather than from now:
199
202
  * ```tsx
200
203
  * import { useQuery, useQueryClient } from '@tanstack/preact-query'
201
204
  *
@@ -209,6 +212,8 @@ declare function useQuery<TQueryFnData = unknown, TError = DefaultError, TData =
209
212
  * queryClient
210
213
  * .getQueryData<Array<Post>>(['posts'])
211
214
  * ?.find((post) => post.id === postId),
215
+ * initialDataUpdatedAt: () =>
216
+ * queryClient.getQueryState(['posts'])?.dataUpdatedAt,
212
217
  * })
213
218
  *
214
219
  * if (isError) return <span>Error: {error.message}</span>
@@ -1 +1 @@
1
- {"version":3,"file":"useQuery.d.cts","names":[],"sources":["../../src/useQuery.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAiDgB,SACd,wBACA,SAAS,cACT,QAAQ,cACR,kBAAkB,WAAW,UAE7B,SAAS,0BAA0B,cAAc,QAAQ,OAAO,YAChE,cAAc,cACb,sBAAsB,OAAO;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBA2DhB,SACd,wBACA,SAAS,cACT,QAAQ,cACR,kBAAkB,WAAW,UAE7B,SAAS,4BAA4B,cAAc,QAAQ,OAAO,YAClE,cAAc,cACb,eAAe,OAAO;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBA4JT,SACd,wBACA,SAAS,cACT,QAAQ,cACR,kBAAkB,WAAW,UAE7B,SAAS,gBAAgB,cAAc,QAAQ,OAAO,YACtD,cAAc,cACb,eAAe,OAAO"}
1
+ {"version":3,"file":"useQuery.d.cts","names":[],"sources":["../../src/useQuery.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAkDgB,SACd,wBACA,SAAS,cACT,QAAQ,cACR,kBAAkB,WAAW,UAE7B,SAAS,0BAA0B,cAAc,QAAQ,OAAO,YAChE,cAAc,cACb,sBAAsB,OAAO;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBA2DhB,SACd,wBACA,SAAS,cACT,QAAQ,cACR,kBAAkB,WAAW,UAE7B,SAAS,4BAA4B,cAAc,QAAQ,OAAO,YAClE,cAAc,cACb,eAAe,OAAO;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAgKT,SACd,wBACA,SAAS,cACT,QAAQ,cACR,kBAAkB,WAAW,UAE7B,SAAS,gBAAgB,cAAc,QAAQ,OAAO,YACtD,cAAc,cACb,eAAe,OAAO"}
@@ -3,7 +3,8 @@ import { DefinedInitialDataOptions, UndefinedInitialDataOptions } from "./queryO
3
3
  import { DefaultError, QueryClient, QueryKey } from "@tanstack/query-core";
4
4
  //#region src/useQuery.d.ts
5
5
  /**
6
- * This overload is selected when `initialData` is set, so the resulting `data` is never `undefined`.
6
+ * This overload is selected when `initialData` is set, so the resulting `data` is never `undefined` (unless
7
+ * a `select` changes `TData` to include `undefined`).
7
8
  *
8
9
  * @see {@link queryOptions} to share these options between `useQuery` and imperative APIs like `queryClient.query`.
9
10
  * @param options - The {@link DefinedInitialDataOptions} to use — everything you can pass to `useQuery`, with `initialData` set.
@@ -195,7 +196,9 @@ declare function useQuery<TQueryFnData = unknown, TError = DefaultError, TData =
195
196
  * ```
196
197
  *
197
198
  * @example
198
- * Seeding a detail query from an already-cached list, to skip the loading state:
199
+ * Seeding a detail query from an already-cached list, to skip the loading state. `initialDataUpdatedAt` carries
200
+ * over the list's own fetch time, so that if you set a `staleTime`, it's measured from when the list was
201
+ * fetched rather than from now:
199
202
  * ```tsx
200
203
  * import { useQuery, useQueryClient } from '@tanstack/preact-query'
201
204
  *
@@ -209,6 +212,8 @@ declare function useQuery<TQueryFnData = unknown, TError = DefaultError, TData =
209
212
  * queryClient
210
213
  * .getQueryData<Array<Post>>(['posts'])
211
214
  * ?.find((post) => post.id === postId),
215
+ * initialDataUpdatedAt: () =>
216
+ * queryClient.getQueryState(['posts'])?.dataUpdatedAt,
212
217
  * })
213
218
  *
214
219
  * if (isError) return <span>Error: {error.message}</span>
@@ -1 +1 @@
1
- {"version":3,"file":"useQuery.d.ts","names":[],"sources":["../../src/useQuery.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAiDgB,SACd,wBACA,SAAS,cACT,QAAQ,cACR,kBAAkB,WAAW,UAE7B,SAAS,0BAA0B,cAAc,QAAQ,OAAO,YAChE,cAAc,cACb,sBAAsB,OAAO;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBA2DhB,SACd,wBACA,SAAS,cACT,QAAQ,cACR,kBAAkB,WAAW,UAE7B,SAAS,4BAA4B,cAAc,QAAQ,OAAO,YAClE,cAAc,cACb,eAAe,OAAO;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBA4JT,SACd,wBACA,SAAS,cACT,QAAQ,cACR,kBAAkB,WAAW,UAE7B,SAAS,gBAAgB,cAAc,QAAQ,OAAO,YACtD,cAAc,cACb,eAAe,OAAO"}
1
+ {"version":3,"file":"useQuery.d.ts","names":[],"sources":["../../src/useQuery.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAkDgB,SACd,wBACA,SAAS,cACT,QAAQ,cACR,kBAAkB,WAAW,UAE7B,SAAS,0BAA0B,cAAc,QAAQ,OAAO,YAChE,cAAc,cACb,sBAAsB,OAAO;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBA2DhB,SACd,wBACA,SAAS,cACT,QAAQ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