@tanstack/preact-query 5.102.3 → 5.102.5

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 (296) hide show
  1. package/build/legacy/HydrationBoundary.cjs +43 -0
  2. package/build/legacy/HydrationBoundary.cjs.map +1 -1
  3. package/build/legacy/HydrationBoundary.d.cts +61 -0
  4. package/build/legacy/HydrationBoundary.d.cts.map +1 -1
  5. package/build/legacy/HydrationBoundary.d.ts +61 -0
  6. package/build/legacy/HydrationBoundary.d.ts.map +1 -1
  7. package/build/legacy/HydrationBoundary.js +43 -0
  8. package/build/legacy/HydrationBoundary.js.map +1 -1
  9. package/build/legacy/IsRestoringProvider.cjs +11 -0
  10. package/build/legacy/IsRestoringProvider.cjs.map +1 -1
  11. package/build/legacy/IsRestoringProvider.d.cts +11 -0
  12. package/build/legacy/IsRestoringProvider.d.cts.map +1 -1
  13. package/build/legacy/IsRestoringProvider.d.ts +11 -0
  14. package/build/legacy/IsRestoringProvider.d.ts.map +1 -1
  15. package/build/legacy/IsRestoringProvider.js +11 -0
  16. package/build/legacy/IsRestoringProvider.js.map +1 -1
  17. package/build/legacy/QueryClientProvider.cjs +30 -0
  18. package/build/legacy/QueryClientProvider.cjs.map +1 -1
  19. package/build/legacy/QueryClientProvider.d.cts +41 -0
  20. package/build/legacy/QueryClientProvider.d.cts.map +1 -1
  21. package/build/legacy/QueryClientProvider.d.ts +41 -0
  22. package/build/legacy/QueryClientProvider.d.ts.map +1 -1
  23. package/build/legacy/QueryClientProvider.js +30 -0
  24. package/build/legacy/QueryClientProvider.js.map +1 -1
  25. package/build/legacy/QueryErrorResetBoundary.cjs +77 -0
  26. package/build/legacy/QueryErrorResetBoundary.cjs.map +1 -1
  27. package/build/legacy/QueryErrorResetBoundary.d.cts +108 -0
  28. package/build/legacy/QueryErrorResetBoundary.d.cts.map +1 -1
  29. package/build/legacy/QueryErrorResetBoundary.d.ts +108 -0
  30. package/build/legacy/QueryErrorResetBoundary.d.ts.map +1 -1
  31. package/build/legacy/QueryErrorResetBoundary.js +77 -0
  32. package/build/legacy/QueryErrorResetBoundary.js.map +1 -1
  33. package/build/legacy/infiniteQueryOptions.cjs.map +1 -1
  34. package/build/legacy/infiniteQueryOptions.d.cts +187 -0
  35. package/build/legacy/infiniteQueryOptions.d.cts.map +1 -1
  36. package/build/legacy/infiniteQueryOptions.d.ts +187 -0
  37. package/build/legacy/infiniteQueryOptions.d.ts.map +1 -1
  38. package/build/legacy/infiniteQueryOptions.js.map +1 -1
  39. package/build/legacy/mutationOptions.cjs.map +1 -1
  40. package/build/legacy/mutationOptions.d.cts +68 -0
  41. package/build/legacy/mutationOptions.d.cts.map +1 -1
  42. package/build/legacy/mutationOptions.d.ts +68 -0
  43. package/build/legacy/mutationOptions.d.ts.map +1 -1
  44. package/build/legacy/mutationOptions.js.map +1 -1
  45. package/build/legacy/queryOptions.cjs.map +1 -1
  46. package/build/legacy/queryOptions.d.cts +198 -0
  47. package/build/legacy/queryOptions.d.cts.map +1 -1
  48. package/build/legacy/queryOptions.d.ts +198 -0
  49. package/build/legacy/queryOptions.d.ts.map +1 -1
  50. package/build/legacy/queryOptions.js.map +1 -1
  51. package/build/legacy/types.cjs.map +1 -1
  52. package/build/legacy/types.d.cts +228 -2
  53. package/build/legacy/types.d.cts.map +1 -1
  54. package/build/legacy/types.d.ts +228 -2
  55. package/build/legacy/types.d.ts.map +1 -1
  56. package/build/legacy/types.js.map +1 -1
  57. package/build/legacy/useInfiniteQuery.cjs.map +1 -1
  58. package/build/legacy/useInfiniteQuery.d.cts +120 -0
  59. package/build/legacy/useInfiniteQuery.d.cts.map +1 -1
  60. package/build/legacy/useInfiniteQuery.d.ts +120 -0
  61. package/build/legacy/useInfiniteQuery.d.ts.map +1 -1
  62. package/build/legacy/useInfiniteQuery.js.map +1 -1
  63. package/build/legacy/useIsFetching.cjs +34 -0
  64. package/build/legacy/useIsFetching.cjs.map +1 -1
  65. package/build/legacy/useIsFetching.d.cts +34 -0
  66. package/build/legacy/useIsFetching.d.cts.map +1 -1
  67. package/build/legacy/useIsFetching.d.ts +34 -0
  68. package/build/legacy/useIsFetching.d.ts.map +1 -1
  69. package/build/legacy/useIsFetching.js +34 -0
  70. package/build/legacy/useIsFetching.js.map +1 -1
  71. package/build/legacy/useMutation.cjs +170 -0
  72. package/build/legacy/useMutation.cjs.map +1 -1
  73. package/build/legacy/useMutation.d.cts +170 -0
  74. package/build/legacy/useMutation.d.cts.map +1 -1
  75. package/build/legacy/useMutation.d.ts +170 -0
  76. package/build/legacy/useMutation.d.ts.map +1 -1
  77. package/build/legacy/useMutation.js +170 -0
  78. package/build/legacy/useMutation.js.map +1 -1
  79. package/build/legacy/useMutationState.cjs +74 -0
  80. package/build/legacy/useMutationState.cjs.map +1 -1
  81. package/build/legacy/useMutationState.d.cts +74 -0
  82. package/build/legacy/useMutationState.d.cts.map +1 -1
  83. package/build/legacy/useMutationState.d.ts +74 -0
  84. package/build/legacy/useMutationState.d.ts.map +1 -1
  85. package/build/legacy/useMutationState.js +74 -0
  86. package/build/legacy/useMutationState.js.map +1 -1
  87. package/build/legacy/usePrefetchInfiniteQuery.cjs +44 -0
  88. package/build/legacy/usePrefetchInfiniteQuery.cjs.map +1 -1
  89. package/build/legacy/usePrefetchInfiniteQuery.d.cts +44 -0
  90. package/build/legacy/usePrefetchInfiniteQuery.d.cts.map +1 -1
  91. package/build/legacy/usePrefetchInfiniteQuery.d.ts +44 -0
  92. package/build/legacy/usePrefetchInfiniteQuery.d.ts.map +1 -1
  93. package/build/legacy/usePrefetchInfiniteQuery.js +44 -0
  94. package/build/legacy/usePrefetchInfiniteQuery.js.map +1 -1
  95. package/build/legacy/usePrefetchQuery.cjs +35 -0
  96. package/build/legacy/usePrefetchQuery.cjs.map +1 -1
  97. package/build/legacy/usePrefetchQuery.d.cts +35 -0
  98. package/build/legacy/usePrefetchQuery.d.cts.map +1 -1
  99. package/build/legacy/usePrefetchQuery.d.ts +35 -0
  100. package/build/legacy/usePrefetchQuery.d.ts.map +1 -1
  101. package/build/legacy/usePrefetchQuery.js +35 -0
  102. package/build/legacy/usePrefetchQuery.js.map +1 -1
  103. package/build/legacy/useQueries.cjs +50 -0
  104. package/build/legacy/useQueries.cjs.map +1 -1
  105. package/build/legacy/useQueries.d.cts +85 -2
  106. package/build/legacy/useQueries.d.cts.map +1 -1
  107. package/build/legacy/useQueries.d.ts +85 -2
  108. package/build/legacy/useQueries.d.ts.map +1 -1
  109. package/build/legacy/useQueries.js +50 -0
  110. package/build/legacy/useQueries.js.map +1 -1
  111. package/build/legacy/useQuery.cjs.map +1 -1
  112. package/build/legacy/useQuery.d.cts +186 -0
  113. package/build/legacy/useQuery.d.cts.map +1 -1
  114. package/build/legacy/useQuery.d.ts +186 -0
  115. package/build/legacy/useQuery.d.ts.map +1 -1
  116. package/build/legacy/useQuery.js.map +1 -1
  117. package/build/legacy/useSuspenseInfiniteQuery.cjs +56 -0
  118. package/build/legacy/useSuspenseInfiniteQuery.cjs.map +1 -1
  119. package/build/legacy/useSuspenseInfiniteQuery.d.cts +56 -0
  120. package/build/legacy/useSuspenseInfiniteQuery.d.cts.map +1 -1
  121. package/build/legacy/useSuspenseInfiniteQuery.d.ts +56 -0
  122. package/build/legacy/useSuspenseInfiniteQuery.d.ts.map +1 -1
  123. package/build/legacy/useSuspenseInfiniteQuery.js +56 -0
  124. package/build/legacy/useSuspenseInfiniteQuery.js.map +1 -1
  125. package/build/legacy/useSuspenseQueries.cjs.map +1 -1
  126. package/build/legacy/useSuspenseQueries.d.cts +196 -2
  127. package/build/legacy/useSuspenseQueries.d.cts.map +1 -1
  128. package/build/legacy/useSuspenseQueries.d.ts +196 -2
  129. package/build/legacy/useSuspenseQueries.d.ts.map +1 -1
  130. package/build/legacy/useSuspenseQueries.js.map +1 -1
  131. package/build/legacy/useSuspenseQuery.cjs +47 -0
  132. package/build/legacy/useSuspenseQuery.cjs.map +1 -1
  133. package/build/legacy/useSuspenseQuery.d.cts +47 -0
  134. package/build/legacy/useSuspenseQuery.d.cts.map +1 -1
  135. package/build/legacy/useSuspenseQuery.d.ts +47 -0
  136. package/build/legacy/useSuspenseQuery.d.ts.map +1 -1
  137. package/build/legacy/useSuspenseQuery.js +47 -0
  138. package/build/legacy/useSuspenseQuery.js.map +1 -1
  139. package/build/modern/HydrationBoundary.cjs +43 -0
  140. package/build/modern/HydrationBoundary.cjs.map +1 -1
  141. package/build/modern/HydrationBoundary.d.cts +61 -0
  142. package/build/modern/HydrationBoundary.d.cts.map +1 -1
  143. package/build/modern/HydrationBoundary.d.ts +61 -0
  144. package/build/modern/HydrationBoundary.d.ts.map +1 -1
  145. package/build/modern/HydrationBoundary.js +43 -0
  146. package/build/modern/HydrationBoundary.js.map +1 -1
  147. package/build/modern/IsRestoringProvider.cjs +11 -0
  148. package/build/modern/IsRestoringProvider.cjs.map +1 -1
  149. package/build/modern/IsRestoringProvider.d.cts +11 -0
  150. package/build/modern/IsRestoringProvider.d.cts.map +1 -1
  151. package/build/modern/IsRestoringProvider.d.ts +11 -0
  152. package/build/modern/IsRestoringProvider.d.ts.map +1 -1
  153. package/build/modern/IsRestoringProvider.js +11 -0
  154. package/build/modern/IsRestoringProvider.js.map +1 -1
  155. package/build/modern/QueryClientProvider.cjs +30 -0
  156. package/build/modern/QueryClientProvider.cjs.map +1 -1
  157. package/build/modern/QueryClientProvider.d.cts +41 -0
  158. package/build/modern/QueryClientProvider.d.cts.map +1 -1
  159. package/build/modern/QueryClientProvider.d.ts +41 -0
  160. package/build/modern/QueryClientProvider.d.ts.map +1 -1
  161. package/build/modern/QueryClientProvider.js +30 -0
  162. package/build/modern/QueryClientProvider.js.map +1 -1
  163. package/build/modern/QueryErrorResetBoundary.cjs +77 -0
  164. package/build/modern/QueryErrorResetBoundary.cjs.map +1 -1
  165. package/build/modern/QueryErrorResetBoundary.d.cts +108 -0
  166. package/build/modern/QueryErrorResetBoundary.d.cts.map +1 -1
  167. package/build/modern/QueryErrorResetBoundary.d.ts +108 -0
  168. package/build/modern/QueryErrorResetBoundary.d.ts.map +1 -1
  169. package/build/modern/QueryErrorResetBoundary.js +77 -0
  170. package/build/modern/QueryErrorResetBoundary.js.map +1 -1
  171. package/build/modern/infiniteQueryOptions.cjs.map +1 -1
  172. package/build/modern/infiniteQueryOptions.d.cts +187 -0
  173. package/build/modern/infiniteQueryOptions.d.cts.map +1 -1
  174. package/build/modern/infiniteQueryOptions.d.ts +187 -0
  175. package/build/modern/infiniteQueryOptions.d.ts.map +1 -1
  176. package/build/modern/infiniteQueryOptions.js.map +1 -1
  177. package/build/modern/mutationOptions.cjs.map +1 -1
  178. package/build/modern/mutationOptions.d.cts +68 -0
  179. package/build/modern/mutationOptions.d.cts.map +1 -1
  180. package/build/modern/mutationOptions.d.ts +68 -0
  181. package/build/modern/mutationOptions.d.ts.map +1 -1
  182. package/build/modern/mutationOptions.js.map +1 -1
  183. package/build/modern/queryOptions.cjs.map +1 -1
  184. package/build/modern/queryOptions.d.cts +198 -0
  185. package/build/modern/queryOptions.d.cts.map +1 -1
  186. package/build/modern/queryOptions.d.ts +198 -0
  187. package/build/modern/queryOptions.d.ts.map +1 -1
  188. package/build/modern/queryOptions.js.map +1 -1
  189. package/build/modern/types.cjs.map +1 -1
  190. package/build/modern/types.d.cts +228 -2
  191. package/build/modern/types.d.cts.map +1 -1
  192. package/build/modern/types.d.ts +228 -2
  193. package/build/modern/types.d.ts.map +1 -1
  194. package/build/modern/types.js.map +1 -1
  195. package/build/modern/useInfiniteQuery.cjs.map +1 -1
  196. package/build/modern/useInfiniteQuery.d.cts +120 -0
  197. package/build/modern/useInfiniteQuery.d.cts.map +1 -1
  198. package/build/modern/useInfiniteQuery.d.ts +120 -0
  199. package/build/modern/useInfiniteQuery.d.ts.map +1 -1
  200. package/build/modern/useInfiniteQuery.js.map +1 -1
  201. package/build/modern/useIsFetching.cjs +34 -0
  202. package/build/modern/useIsFetching.cjs.map +1 -1
  203. package/build/modern/useIsFetching.d.cts +34 -0
  204. package/build/modern/useIsFetching.d.cts.map +1 -1
  205. package/build/modern/useIsFetching.d.ts +34 -0
  206. package/build/modern/useIsFetching.d.ts.map +1 -1
  207. package/build/modern/useIsFetching.js +34 -0
  208. package/build/modern/useIsFetching.js.map +1 -1
  209. package/build/modern/useMutation.cjs +170 -0
  210. package/build/modern/useMutation.cjs.map +1 -1
  211. package/build/modern/useMutation.d.cts +170 -0
  212. package/build/modern/useMutation.d.cts.map +1 -1
  213. package/build/modern/useMutation.d.ts +170 -0
  214. package/build/modern/useMutation.d.ts.map +1 -1
  215. package/build/modern/useMutation.js +170 -0
  216. package/build/modern/useMutation.js.map +1 -1
  217. package/build/modern/useMutationState.cjs +74 -0
  218. package/build/modern/useMutationState.cjs.map +1 -1
  219. package/build/modern/useMutationState.d.cts +74 -0
  220. package/build/modern/useMutationState.d.cts.map +1 -1
  221. package/build/modern/useMutationState.d.ts +74 -0
  222. package/build/modern/useMutationState.d.ts.map +1 -1
  223. package/build/modern/useMutationState.js +74 -0
  224. package/build/modern/useMutationState.js.map +1 -1
  225. package/build/modern/usePrefetchInfiniteQuery.cjs +44 -0
  226. package/build/modern/usePrefetchInfiniteQuery.cjs.map +1 -1
  227. package/build/modern/usePrefetchInfiniteQuery.d.cts +44 -0
  228. package/build/modern/usePrefetchInfiniteQuery.d.cts.map +1 -1
  229. package/build/modern/usePrefetchInfiniteQuery.d.ts +44 -0
  230. package/build/modern/usePrefetchInfiniteQuery.d.ts.map +1 -1
  231. package/build/modern/usePrefetchInfiniteQuery.js +44 -0
  232. package/build/modern/usePrefetchInfiniteQuery.js.map +1 -1
  233. package/build/modern/usePrefetchQuery.cjs +35 -0
  234. package/build/modern/usePrefetchQuery.cjs.map +1 -1
  235. package/build/modern/usePrefetchQuery.d.cts +35 -0
  236. package/build/modern/usePrefetchQuery.d.cts.map +1 -1
  237. package/build/modern/usePrefetchQuery.d.ts +35 -0
  238. package/build/modern/usePrefetchQuery.d.ts.map +1 -1
  239. package/build/modern/usePrefetchQuery.js +35 -0
  240. package/build/modern/usePrefetchQuery.js.map +1 -1
  241. package/build/modern/useQueries.cjs +50 -0
  242. package/build/modern/useQueries.cjs.map +1 -1
  243. package/build/modern/useQueries.d.cts +85 -2
  244. package/build/modern/useQueries.d.cts.map +1 -1
  245. package/build/modern/useQueries.d.ts +85 -2
  246. package/build/modern/useQueries.d.ts.map +1 -1
  247. package/build/modern/useQueries.js +50 -0
  248. package/build/modern/useQueries.js.map +1 -1
  249. package/build/modern/useQuery.cjs.map +1 -1
  250. package/build/modern/useQuery.d.cts +186 -0
  251. package/build/modern/useQuery.d.cts.map +1 -1
  252. package/build/modern/useQuery.d.ts +186 -0
  253. package/build/modern/useQuery.d.ts.map +1 -1
  254. package/build/modern/useQuery.js.map +1 -1
  255. package/build/modern/useSuspenseInfiniteQuery.cjs +56 -0
  256. package/build/modern/useSuspenseInfiniteQuery.cjs.map +1 -1
  257. package/build/modern/useSuspenseInfiniteQuery.d.cts +56 -0
  258. package/build/modern/useSuspenseInfiniteQuery.d.cts.map +1 -1
  259. package/build/modern/useSuspenseInfiniteQuery.d.ts +56 -0
  260. package/build/modern/useSuspenseInfiniteQuery.d.ts.map +1 -1
  261. package/build/modern/useSuspenseInfiniteQuery.js +56 -0
  262. package/build/modern/useSuspenseInfiniteQuery.js.map +1 -1
  263. package/build/modern/useSuspenseQueries.cjs.map +1 -1
  264. package/build/modern/useSuspenseQueries.d.cts +196 -2
  265. package/build/modern/useSuspenseQueries.d.cts.map +1 -1
  266. package/build/modern/useSuspenseQueries.d.ts +196 -2
  267. package/build/modern/useSuspenseQueries.d.ts.map +1 -1
  268. package/build/modern/useSuspenseQueries.js.map +1 -1
  269. package/build/modern/useSuspenseQuery.cjs +47 -0
  270. package/build/modern/useSuspenseQuery.cjs.map +1 -1
  271. package/build/modern/useSuspenseQuery.d.cts +47 -0
  272. package/build/modern/useSuspenseQuery.d.cts.map +1 -1
  273. package/build/modern/useSuspenseQuery.d.ts +47 -0
  274. package/build/modern/useSuspenseQuery.d.ts.map +1 -1
  275. package/build/modern/useSuspenseQuery.js +47 -0
  276. package/build/modern/useSuspenseQuery.js.map +1 -1
  277. package/package.json +3 -3
  278. package/src/HydrationBoundary.tsx +61 -0
  279. package/src/IsRestoringProvider.ts +12 -0
  280. package/src/QueryClientProvider.tsx +41 -0
  281. package/src/QueryErrorResetBoundary.tsx +111 -0
  282. package/src/infiniteQueryOptions.ts +187 -0
  283. package/src/mutationOptions.ts +68 -0
  284. package/src/queryOptions.ts +198 -0
  285. package/src/types.ts +228 -2
  286. package/src/useInfiniteQuery.ts +120 -0
  287. package/src/useIsFetching.ts +34 -0
  288. package/src/useMutation.ts +170 -0
  289. package/src/useMutationState.ts +74 -0
  290. package/src/usePrefetchInfiniteQuery.tsx +44 -0
  291. package/src/usePrefetchQuery.tsx +35 -0
  292. package/src/useQueries.ts +85 -2
  293. package/src/useQuery.ts +186 -0
  294. package/src/useSuspenseInfiniteQuery.ts +56 -0
  295. package/src/useSuspenseQueries.ts +196 -2
  296. package/src/useSuspenseQuery.ts +47 -0
@@ -1,7 +1,75 @@
1
1
  import { UseMutationOptions } from "./types.js";
2
2
  import { DefaultError, WithRequired } from "@tanstack/query-core";
3
3
  //#region src/mutationOptions.d.ts
4
+ /**
5
+ * You can generally pass everything to `mutationOptions` that you can also pass to `useMutation`. A
6
+ * `mutationKey` is required on this overload so the mutation can be looked up later, e.g. with
7
+ * `useMutationState`.
8
+ *
9
+ * @see {@link useMutation} to run the mutation these options describe.
10
+ * @param options - The mutation options to use, identical to what you'd pass to `useMutation`, with a
11
+ * required `mutationKey`.
12
+ * @returns The same options object, unchanged.
13
+ *
14
+ * @example
15
+ * ```tsx
16
+ * import { mutationOptions, useMutation } from '@tanstack/preact-query'
17
+ *
18
+ * export const createPostOptions = mutationOptions({
19
+ * mutationKey: ['posts', 'create'],
20
+ * mutationFn: createPost,
21
+ * })
22
+ *
23
+ * function CreatePost() {
24
+ * const mutation = useMutation(createPostOptions)
25
+ * return <button onClick={() => mutation.mutate({ title: 'Hello' })}>Create</button>
26
+ * }
27
+ * ```
28
+ *
29
+ * @example
30
+ * Looking the mutation up elsewhere via its `mutationKey`, e.g. for a global "saving…" indicator:
31
+ * ```tsx
32
+ * import { mutationOptions, useMutationState } from '@tanstack/preact-query'
33
+ *
34
+ * const createPostOptions = mutationOptions({
35
+ * mutationKey: ['posts', 'create'],
36
+ * mutationFn: createPost,
37
+ * })
38
+ *
39
+ * function SavingIndicator() {
40
+ * const isCreatingPost = useMutationState({
41
+ * filters: { mutationKey: createPostOptions.mutationKey, status: 'pending' },
42
+ * }).length > 0
43
+ *
44
+ * return isCreatingPost ? <span>Saving…</span> : null
45
+ * }
46
+ * ```
47
+ */
4
48
  declare function mutationOptions<TData = unknown, TError = DefaultError, TVariables = void, TOnMutateResult = unknown>(options: WithRequired<UseMutationOptions<TData, TError, TVariables, TOnMutateResult>, 'mutationKey'>): WithRequired<UseMutationOptions<TData, TError, TVariables, TOnMutateResult>, 'mutationKey'>;
49
+ /**
50
+ * You can generally pass everything to `mutationOptions` that you can also pass to `useMutation`. No
51
+ * `mutationKey` is required on this overload — use this when you don't need to look the mutation up later
52
+ * (e.g. with `useMutationState`).
53
+ *
54
+ * @see {@link useMutation} to run the mutation these options describe.
55
+ * @param options - The mutation options to use, identical to what you'd pass to `useMutation`, without a
56
+ * `mutationKey`.
57
+ * @returns The same options object, unchanged.
58
+ *
59
+ * @example
60
+ * ```tsx
61
+ * import { mutationOptions, useMutation } from '@tanstack/preact-query'
62
+ *
63
+ * export const createPostOptions = mutationOptions({
64
+ * mutationFn: createPost,
65
+ * })
66
+ *
67
+ * function CreatePost() {
68
+ * const mutation = useMutation(createPostOptions)
69
+ * return <button onClick={() => mutation.mutate({ title: 'Hello' })}>Create</button>
70
+ * }
71
+ * ```
72
+ */
5
73
  declare function mutationOptions<TData = unknown, TError = DefaultError, TVariables = void, TOnMutateResult = unknown>(options: Omit<UseMutationOptions<TData, TError, TVariables, TOnMutateResult>, 'mutationKey'>): Omit<UseMutationOptions<TData, TError, TVariables, TOnMutateResult>, 'mutationKey'>;
6
74
  //#endregion
7
75
  export { mutationOptions };
@@ -1 +1 @@
1
- {"version":3,"file":"mutationOptions.d.ts","names":[],"sources":["../../src/mutationOptions.ts"],"mappings":";;;iBAIgB,gBACd,iBACA,SAAS,cACT,mBACA,2BAEA,SAAS,aACP,mBAAmB,OAAO,QAAQ,YAAY,mCAG/C,aACD,mBAAmB,OAAO,QAAQ,YAAY;iBAGhC,gBACd,iBACA,SAAS,cACT,mBACA,2BAEA,SAAS,KACP,mBAAmB,OAAO,QAAQ,YAAY,mCAG/C,KACD,mBAAmB,OAAO,QAAQ,YAAY"}
1
+ {"version":3,"file":"mutationOptions.d.ts","names":[],"sources":["../../src/mutationOptions.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAgDgB,gBACd,iBACA,SAAS,cACT,mBACA,2BAEA,SAAS,aACP,mBAAmB,OAAO,QAAQ,YAAY,mCAG/C,aACD,mBAAmB,OAAO,QAAQ,YAAY;;;;;;;;;;;;;;;;;;;;;;;;;iBA2BhC,gBACd,iBACA,SAAS,cACT,mBACA,2BAEA,SAAS,KACP,mBAAmB,OAAO,QAAQ,YAAY,mCAG/C,KACD,mBAAmB,OAAO,QAAQ,YAAY"}
@@ -1 +1 @@
1
- {"version":3,"file":"mutationOptions.js","names":[],"sources":["../../src/mutationOptions.ts"],"sourcesContent":["import type { DefaultError, WithRequired } from '@tanstack/query-core'\n\nimport type { UseMutationOptions } from './types'\n\nexport function mutationOptions<\n TData = unknown,\n TError = DefaultError,\n TVariables = void,\n TOnMutateResult = unknown,\n>(\n options: WithRequired<\n UseMutationOptions<TData, TError, TVariables, TOnMutateResult>,\n 'mutationKey'\n >,\n): WithRequired<\n UseMutationOptions<TData, TError, TVariables, TOnMutateResult>,\n 'mutationKey'\n>\nexport function mutationOptions<\n TData = unknown,\n TError = DefaultError,\n TVariables = void,\n TOnMutateResult = unknown,\n>(\n options: Omit<\n UseMutationOptions<TData, TError, TVariables, TOnMutateResult>,\n 'mutationKey'\n >,\n): Omit<\n UseMutationOptions<TData, TError, TVariables, TOnMutateResult>,\n 'mutationKey'\n>\nexport function mutationOptions<\n TData = unknown,\n TError = DefaultError,\n TVariables = void,\n TOnMutateResult = unknown,\n>(\n options: UseMutationOptions<TData, TError, TVariables, TOnMutateResult>,\n): UseMutationOptions<TData, TError, TVariables, TOnMutateResult> {\n return options\n}\n"],"mappings":";AAgCA,SAAgB,gBAMd,SACgE;CAChE,OAAO;AACT"}
1
+ {"version":3,"file":"mutationOptions.js","names":[],"sources":["../../src/mutationOptions.ts"],"sourcesContent":["import type { DefaultError, WithRequired } from '@tanstack/query-core'\n\nimport type { UseMutationOptions } from './types'\n\n/**\n * You can generally pass everything to `mutationOptions` that you can also pass to `useMutation`. A\n * `mutationKey` is required on this overload so the mutation can be looked up later, e.g. with\n * `useMutationState`.\n *\n * @see {@link useMutation} to run the mutation these options describe.\n * @param options - The mutation options to use, identical to what you'd pass to `useMutation`, with a\n * required `mutationKey`.\n * @returns The same options object, unchanged.\n *\n * @example\n * ```tsx\n * import { mutationOptions, useMutation } from '@tanstack/preact-query'\n *\n * export const createPostOptions = mutationOptions({\n * mutationKey: ['posts', 'create'],\n * mutationFn: createPost,\n * })\n *\n * function CreatePost() {\n * const mutation = useMutation(createPostOptions)\n * return <button onClick={() => mutation.mutate({ title: 'Hello' })}>Create</button>\n * }\n * ```\n *\n * @example\n * Looking the mutation up elsewhere via its `mutationKey`, e.g. for a global \"saving…\" indicator:\n * ```tsx\n * import { mutationOptions, useMutationState } from '@tanstack/preact-query'\n *\n * const createPostOptions = mutationOptions({\n * mutationKey: ['posts', 'create'],\n * mutationFn: createPost,\n * })\n *\n * function SavingIndicator() {\n * const isCreatingPost = useMutationState({\n * filters: { mutationKey: createPostOptions.mutationKey, status: 'pending' },\n * }).length > 0\n *\n * return isCreatingPost ? <span>Saving…</span> : null\n * }\n * ```\n */\nexport function mutationOptions<\n TData = unknown,\n TError = DefaultError,\n TVariables = void,\n TOnMutateResult = unknown,\n>(\n options: WithRequired<\n UseMutationOptions<TData, TError, TVariables, TOnMutateResult>,\n 'mutationKey'\n >,\n): WithRequired<\n UseMutationOptions<TData, TError, TVariables, TOnMutateResult>,\n 'mutationKey'\n>\n/**\n * You can generally pass everything to `mutationOptions` that you can also pass to `useMutation`. No\n * `mutationKey` is required on this overload — use this when you don't need to look the mutation up later\n * (e.g. with `useMutationState`).\n *\n * @see {@link useMutation} to run the mutation these options describe.\n * @param options - The mutation options to use, identical to what you'd pass to `useMutation`, without a\n * `mutationKey`.\n * @returns The same options object, unchanged.\n *\n * @example\n * ```tsx\n * import { mutationOptions, useMutation } from '@tanstack/preact-query'\n *\n * export const createPostOptions = mutationOptions({\n * mutationFn: createPost,\n * })\n *\n * function CreatePost() {\n * const mutation = useMutation(createPostOptions)\n * return <button onClick={() => mutation.mutate({ title: 'Hello' })}>Create</button>\n * }\n * ```\n */\nexport function mutationOptions<\n TData = unknown,\n TError = DefaultError,\n TVariables = void,\n TOnMutateResult = unknown,\n>(\n options: Omit<\n UseMutationOptions<TData, TError, TVariables, TOnMutateResult>,\n 'mutationKey'\n >,\n): Omit<\n UseMutationOptions<TData, TError, TVariables, TOnMutateResult>,\n 'mutationKey'\n>\nexport function mutationOptions<\n TData = unknown,\n TError = DefaultError,\n TVariables = void,\n TOnMutateResult = unknown,\n>(\n options: UseMutationOptions<TData, TError, TVariables, TOnMutateResult>,\n): UseMutationOptions<TData, TError, TVariables, TOnMutateResult> {\n return options\n}\n"],"mappings":";AAoGA,SAAgB,gBAMd,SACgE;CAChE,OAAO;AACT"}
@@ -1 +1 @@
1
- {"version":3,"file":"queryOptions.cjs","names":[],"sources":["../../src/queryOptions.ts"],"sourcesContent":["import type {\n DefaultError,\n InitialDataFunction,\n NonUndefinedGuard,\n OmitKeyof,\n QueryFunction,\n QueryKey,\n QueryKeyWithDataTag,\n SkipToken,\n} from '@tanstack/query-core'\n\nimport type { UseQueryOptions } from './types'\n\nexport type UndefinedInitialDataOptions<\n TQueryFnData = unknown,\n TError = DefaultError,\n TData = TQueryFnData,\n TQueryKey extends QueryKey = QueryKey,\n> = UseQueryOptions<TQueryFnData, TError, TData, TQueryKey> & {\n initialData?:\n | undefined\n | InitialDataFunction<NonUndefinedGuard<TQueryFnData>>\n | NonUndefinedGuard<TQueryFnData>\n}\n\nexport type UnusedSkipTokenOptions<\n TQueryFnData = unknown,\n TError = DefaultError,\n TData = TQueryFnData,\n TQueryKey extends QueryKey = QueryKey,\n> = OmitKeyof<\n UseQueryOptions<TQueryFnData, TError, TData, TQueryKey>,\n 'queryFn'\n> & {\n queryFn?: Exclude<\n UseQueryOptions<TQueryFnData, TError, TData, TQueryKey>['queryFn'],\n SkipToken | undefined\n >\n}\n\nexport type DefinedInitialDataOptions<\n TQueryFnData = unknown,\n TError = DefaultError,\n TData = TQueryFnData,\n TQueryKey extends QueryKey = QueryKey,\n> = Omit<UseQueryOptions<TQueryFnData, TError, TData, TQueryKey>, 'queryFn'> & {\n initialData:\n | NonUndefinedGuard<TQueryFnData>\n | (() => NonUndefinedGuard<TQueryFnData>)\n queryFn?: QueryFunction<TQueryFnData, TQueryKey>\n}\n\nexport function queryOptions<\n TQueryFnData = unknown,\n TError = DefaultError,\n TData = TQueryFnData,\n TQueryKey extends QueryKey = QueryKey,\n>(\n options: DefinedInitialDataOptions<TQueryFnData, TError, TData, TQueryKey>,\n): DefinedInitialDataOptions<TQueryFnData, TError, TData, TQueryKey> &\n QueryKeyWithDataTag<TQueryKey, TQueryFnData, TError>\n\nexport function queryOptions<\n TQueryFnData = unknown,\n TError = DefaultError,\n TData = TQueryFnData,\n TQueryKey extends QueryKey = QueryKey,\n>(\n options: UnusedSkipTokenOptions<TQueryFnData, TError, TData, TQueryKey>,\n): UnusedSkipTokenOptions<TQueryFnData, TError, TData, TQueryKey> &\n QueryKeyWithDataTag<TQueryKey, TQueryFnData, TError>\n\nexport function queryOptions<\n TQueryFnData = unknown,\n TError = DefaultError,\n TData = TQueryFnData,\n TQueryKey extends QueryKey = QueryKey,\n>(\n options: UndefinedInitialDataOptions<TQueryFnData, TError, TData, TQueryKey>,\n): UndefinedInitialDataOptions<TQueryFnData, TError, TData, TQueryKey> &\n QueryKeyWithDataTag<TQueryKey, TQueryFnData, TError>\n\nexport function queryOptions(options: unknown) {\n return options\n}\n"],"mappings":";;AAkFA,SAAgB,aAAa,SAAkB;CAC7C,OAAO;AACT"}
1
+ {"version":3,"file":"queryOptions.cjs","names":[],"sources":["../../src/queryOptions.ts"],"sourcesContent":["import type {\n DefaultError,\n InitialDataFunction,\n NonUndefinedGuard,\n OmitKeyof,\n QueryFunction,\n QueryKey,\n QueryKeyWithDataTag,\n SkipToken,\n} from '@tanstack/query-core'\n\nimport type { UseQueryOptions } from './types'\n\n/**\n * The options accepted by the `queryOptions` overload selected when no `initialData` is set — `data` may be\n * `undefined` while the query is `pending`.\n *\n * @template TQueryFnData - The type your `queryFn` resolves to.\n * @template TError - The type of errors your `queryFn` may throw.\n * @template TData - The type `data` ends up as after `select` runs.\n * @template TQueryKey - The type of your `queryKey`.\n */\nexport type UndefinedInitialDataOptions<\n TQueryFnData = unknown,\n TError = DefaultError,\n TData = TQueryFnData,\n TQueryKey extends QueryKey = QueryKey,\n> = UseQueryOptions<TQueryFnData, TError, TData, TQueryKey> & {\n /**\n * If set, this value will be used as the initial data for the query cache (as long as the query hasn't been\n * created or cached yet). If set to a function, the function will be called **once** during the shared/root\n * query initialization, and be expected to synchronously return the initial data. Initial data is\n * considered stale by default unless a `staleTime` has been set. `initialData` **is persisted** to the\n * cache.\n */\n initialData?:\n | undefined\n | InitialDataFunction<NonUndefinedGuard<TQueryFnData>>\n | NonUndefinedGuard<TQueryFnData>\n}\n\n/**\n * The options accepted by the `queryOptions` overload selected when no `initialData` is set and `queryFn` is\n * not `skipToken` — same as {@link UndefinedInitialDataOptions}, but `queryFn` may not be `skipToken`.\n *\n * @template TQueryFnData - The type your `queryFn` resolves to.\n * @template TError - The type of errors your `queryFn` may throw.\n * @template TData - The type `data` ends up as after `select` runs.\n * @template TQueryKey - The type of your `queryKey`.\n */\nexport type UnusedSkipTokenOptions<\n TQueryFnData = unknown,\n TError = DefaultError,\n TData = TQueryFnData,\n TQueryKey extends QueryKey = QueryKey,\n> = OmitKeyof<\n UseQueryOptions<TQueryFnData, TError, TData, TQueryKey>,\n 'queryFn'\n> & {\n /**\n * `skipToken` is not allowed as a value here — this overload is selected when no `initialData` is set. If\n * you don't intend to run the query yet, omit `queryFn` or use a default query function instead.\n */\n queryFn?: Exclude<\n UseQueryOptions<TQueryFnData, TError, TData, TQueryKey>['queryFn'],\n SkipToken | undefined\n >\n}\n\n/**\n * The options accepted by the `queryOptions` overload selected when `initialData` is set — `data` is never\n * `undefined`.\n *\n * @template TQueryFnData - The type your `queryFn` resolves to.\n * @template TError - The type of errors your `queryFn` may throw.\n * @template TData - The type `data` ends up as after `select` runs.\n * @template TQueryKey - The type of your `queryKey`.\n */\nexport type DefinedInitialDataOptions<\n TQueryFnData = unknown,\n TError = DefaultError,\n TData = TQueryFnData,\n TQueryKey extends QueryKey = QueryKey,\n> = Omit<UseQueryOptions<TQueryFnData, TError, TData, TQueryKey>, 'queryFn'> & {\n /**\n * If set, this value will be used as the initial data for the query cache (as long as the query hasn't been\n * created or cached yet). If set to a function, the function will be called **once** during the shared/root\n * query initialization, and be expected to synchronously return the initial data. Initial data is\n * considered stale by default unless a `staleTime` has been set. `initialData` **is persisted** to the\n * cache.\n */\n initialData:\n | NonUndefinedGuard<TQueryFnData>\n | (() => NonUndefinedGuard<TQueryFnData>)\n /**\n * Optional here, but omitting it is only safe when no fetch will be attempted — for example with\n * `enabled: false`, or when a default query function has been defined. Otherwise, an enabled query with no\n * `queryFn` still tries to fetch and fails with a \"Missing queryFn\" error; `initialData` does not prevent this.\n */\n queryFn?: QueryFunction<TQueryFnData, TQueryKey>\n}\n\n/**\n * You can generally pass everything to `queryOptions` that you can also pass to `useQuery`. These options can\n * be shared across hooks and imperative APIs such as `queryClient.query`. `options.queryKey` is required and\n * is the query key to generate options for.\n *\n * This overload is selected when `initialData` is set, so the resulting `data` is never `undefined`.\n *\n * @see {@link useQuery} to run a query with these options.\n * @param options - The {@link DefinedInitialDataOptions} to use — everything you can pass to `useQuery`, with `initialData` set.\n * @returns The same options object, typed so that `queryKey` carries the inferred data type.\n *\n * @example\n * ```tsx\n * import { queryOptions, useQuery } from '@tanstack/preact-query'\n *\n * export const postsOptions = queryOptions({\n * queryKey: ['posts'],\n * queryFn: fetchPosts,\n * initialData: [],\n * })\n *\n * function Posts() {\n * // `data` is `Post[]`, never `undefined`, thanks to `initialData`.\n * const { data } = useQuery(postsOptions)\n * return <>{data.map((post) => <p key={post.id}>{post.title}</p>)}</>\n * }\n * ```\n */\nexport function queryOptions<\n TQueryFnData = unknown,\n TError = DefaultError,\n TData = TQueryFnData,\n TQueryKey extends QueryKey = QueryKey,\n>(\n options: DefinedInitialDataOptions<TQueryFnData, TError, TData, TQueryKey>,\n): DefinedInitialDataOptions<TQueryFnData, TError, TData, TQueryKey> &\n QueryKeyWithDataTag<TQueryKey, TQueryFnData, TError>\n\n/**\n * You can generally pass everything to `queryOptions` that you can also pass to `useQuery`. These options can\n * be shared across hooks and imperative APIs such as `queryClient.query`. `options.queryKey` is required and\n * is the query key to generate options for.\n *\n * @see {@link useQuery} to run a query with these options.\n * @param options - The {@link UnusedSkipTokenOptions} to use — everything you can pass to `useQuery`.\n * @returns The same options object, typed so that `queryKey` carries the inferred data type.\n *\n * @example\n * ```tsx\n * import { queryOptions } from '@tanstack/preact-query'\n *\n * export const postsOptions = queryOptions({\n * queryKey: ['posts'],\n * queryFn: fetchPosts,\n * })\n * ```\n *\n * @example\n * A parameterized factory, reused across a hook and an imperative call with the same cache entry:\n * ```tsx\n * import { noop, queryOptions, useQuery } from '@tanstack/preact-query'\n *\n * export const postOptions = (id: string) =>\n * queryOptions({\n * queryKey: ['post', id],\n * queryFn: () => fetchPost(id),\n * })\n *\n * function Post({ id }: { id: string }) {\n * const { data } = useQuery(postOptions(id))\n * return <h1>{data?.title}</h1>\n * }\n *\n * // Elsewhere, e.g. to warm the cache before rendering `<Post>`:\n * queryClient.query(postOptions(id)).catch(noop)\n * ```\n *\n * @example\n * The same options object works with every API that accepts query options:\n * ```tsx\n * import {\n * noop,\n * queryOptions,\n * useQuery,\n * useSuspenseQuery,\n * } from '@tanstack/preact-query'\n *\n * const todosOptions = queryOptions({\n * queryKey: ['todos'],\n * queryFn: fetchTodos,\n * })\n *\n * useQuery(todosOptions)\n * useSuspenseQuery(todosOptions)\n * queryClient.query(todosOptions).catch(noop)\n * queryClient.getQueryData(todosOptions.queryKey) // typed as Array<Todo> | undefined\n * ```\n */\nexport function queryOptions<\n TQueryFnData = unknown,\n TError = DefaultError,\n TData = TQueryFnData,\n TQueryKey extends QueryKey = QueryKey,\n>(\n options: UnusedSkipTokenOptions<TQueryFnData, TError, TData, TQueryKey>,\n): UnusedSkipTokenOptions<TQueryFnData, TError, TData, TQueryKey> &\n QueryKeyWithDataTag<TQueryKey, TQueryFnData, TError>\n\n/**\n * You can generally pass everything to `queryOptions` that you can also pass to `useQuery`. These options can\n * be shared across hooks and imperative APIs such as `queryClient.query`. `options.queryKey` is required and\n * is the query key to generate options for.\n *\n * @see {@link useQuery} to run a query with these options.\n * @param options - The {@link UndefinedInitialDataOptions} to use — everything you can pass to `useQuery`.\n * @returns The same options object, typed so that `queryKey` carries the inferred data type.\n *\n * @example\n * ```tsx\n * import { queryOptions } from '@tanstack/preact-query'\n *\n * export const postsOptions = queryOptions({\n * queryKey: ['posts'],\n * queryFn: fetchPosts,\n * })\n * ```\n *\n * @example\n * A parameterized factory, reused across a hook and an imperative call with the same cache entry:\n * ```tsx\n * import { noop, queryOptions, useQuery } from '@tanstack/preact-query'\n *\n * export const postOptions = (id: string) =>\n * queryOptions({\n * queryKey: ['post', id],\n * queryFn: () => fetchPost(id),\n * })\n *\n * function Post({ id }: { id: string }) {\n * const { data } = useQuery(postOptions(id))\n * return <h1>{data?.title}</h1>\n * }\n *\n * // Elsewhere, e.g. to warm the cache before rendering `<Post>`:\n * queryClient.query(postOptions(id)).catch(noop)\n * ```\n *\n * @example\n * The same options object works with every API that accepts query options:\n * ```tsx\n * import {\n * noop,\n * queryOptions,\n * useQuery,\n * useSuspenseQuery,\n * } from '@tanstack/preact-query'\n *\n * const todosOptions = queryOptions({\n * queryKey: ['todos'],\n * queryFn: fetchTodos,\n * })\n *\n * useQuery(todosOptions)\n * useSuspenseQuery(todosOptions)\n * queryClient.query(todosOptions).catch(noop)\n * queryClient.getQueryData(todosOptions.queryKey) // typed as Array<Todo> | undefined\n * ```\n */\nexport function queryOptions<\n TQueryFnData = unknown,\n TError = DefaultError,\n TData = TQueryFnData,\n TQueryKey extends QueryKey = QueryKey,\n>(\n options: UndefinedInitialDataOptions<TQueryFnData, TError, TData, TQueryKey>,\n): UndefinedInitialDataOptions<TQueryFnData, TError, TData, TQueryKey> &\n QueryKeyWithDataTag<TQueryKey, TQueryFnData, TError>\n\nexport function queryOptions(options: unknown) {\n return options\n}\n"],"mappings":";;AAwRA,SAAgB,aAAa,SAAkB;CAC7C,OAAO;AACT"}
@@ -1,18 +1,216 @@
1
1
  import { UseQueryOptions } from "./types.cjs";
2
2
  import { DefaultError, InitialDataFunction, NonUndefinedGuard, OmitKeyof, QueryFunction, QueryKey, QueryKeyWithDataTag, SkipToken } from "@tanstack/query-core";
3
3
  //#region src/queryOptions.d.ts
4
+ /**
5
+ * The options accepted by the `queryOptions` overload selected when no `initialData` is set — `data` may be
6
+ * `undefined` while the query is `pending`.
7
+ *
8
+ * @template TQueryFnData - The type your `queryFn` resolves to.
9
+ * @template TError - The type of errors your `queryFn` may throw.
10
+ * @template TData - The type `data` ends up as after `select` runs.
11
+ * @template TQueryKey - The type of your `queryKey`.
12
+ */
4
13
  type UndefinedInitialDataOptions<TQueryFnData = unknown, TError = DefaultError, TData = TQueryFnData, TQueryKey extends QueryKey = QueryKey> = UseQueryOptions<TQueryFnData, TError, TData, TQueryKey> & {
14
+ /**
15
+ * If set, this value will be used as the initial data for the query cache (as long as the query hasn't been
16
+ * created or cached yet). If set to a function, the function will be called **once** during the shared/root
17
+ * query initialization, and be expected to synchronously return the initial data. Initial data is
18
+ * considered stale by default unless a `staleTime` has been set. `initialData` **is persisted** to the
19
+ * cache.
20
+ */
5
21
  initialData?: undefined | InitialDataFunction<NonUndefinedGuard<TQueryFnData>> | NonUndefinedGuard<TQueryFnData>;
6
22
  };
23
+ /**
24
+ * The options accepted by the `queryOptions` overload selected when no `initialData` is set and `queryFn` is
25
+ * not `skipToken` — same as {@link UndefinedInitialDataOptions}, but `queryFn` may not be `skipToken`.
26
+ *
27
+ * @template TQueryFnData - The type your `queryFn` resolves to.
28
+ * @template TError - The type of errors your `queryFn` may throw.
29
+ * @template TData - The type `data` ends up as after `select` runs.
30
+ * @template TQueryKey - The type of your `queryKey`.
31
+ */
7
32
  type UnusedSkipTokenOptions<TQueryFnData = unknown, TError = DefaultError, TData = TQueryFnData, TQueryKey extends QueryKey = QueryKey> = OmitKeyof<UseQueryOptions<TQueryFnData, TError, TData, TQueryKey>, 'queryFn'> & {
33
+ /**
34
+ * `skipToken` is not allowed as a value here — this overload is selected when no `initialData` is set. If
35
+ * you don't intend to run the query yet, omit `queryFn` or use a default query function instead.
36
+ */
8
37
  queryFn?: Exclude<UseQueryOptions<TQueryFnData, TError, TData, TQueryKey>['queryFn'], SkipToken | undefined>;
9
38
  };
39
+ /**
40
+ * The options accepted by the `queryOptions` overload selected when `initialData` is set — `data` is never
41
+ * `undefined`.
42
+ *
43
+ * @template TQueryFnData - The type your `queryFn` resolves to.
44
+ * @template TError - The type of errors your `queryFn` may throw.
45
+ * @template TData - The type `data` ends up as after `select` runs.
46
+ * @template TQueryKey - The type of your `queryKey`.
47
+ */
10
48
  type DefinedInitialDataOptions<TQueryFnData = unknown, TError = DefaultError, TData = TQueryFnData, TQueryKey extends QueryKey = QueryKey> = Omit<UseQueryOptions<TQueryFnData, TError, TData, TQueryKey>, 'queryFn'> & {
49
+ /**
50
+ * If set, this value will be used as the initial data for the query cache (as long as the query hasn't been
51
+ * created or cached yet). If set to a function, the function will be called **once** during the shared/root
52
+ * query initialization, and be expected to synchronously return the initial data. Initial data is
53
+ * considered stale by default unless a `staleTime` has been set. `initialData` **is persisted** to the
54
+ * cache.
55
+ */
11
56
  initialData: NonUndefinedGuard<TQueryFnData> | (() => NonUndefinedGuard<TQueryFnData>);
57
+ /**
58
+ * Optional here, but omitting it is only safe when no fetch will be attempted — for example with
59
+ * `enabled: false`, or when a default query function has been defined. Otherwise, an enabled query with no
60
+ * `queryFn` still tries to fetch and fails with a "Missing queryFn" error; `initialData` does not prevent this.
61
+ */
12
62
  queryFn?: QueryFunction<TQueryFnData, TQueryKey>;
13
63
  };
64
+ /**
65
+ * You can generally pass everything to `queryOptions` that you can also pass to `useQuery`. These options can
66
+ * be shared across hooks and imperative APIs such as `queryClient.query`. `options.queryKey` is required and
67
+ * is the query key to generate options for.
68
+ *
69
+ * This overload is selected when `initialData` is set, so the resulting `data` is never `undefined`.
70
+ *
71
+ * @see {@link useQuery} to run a query with these options.
72
+ * @param options - The {@link DefinedInitialDataOptions} to use — everything you can pass to `useQuery`, with `initialData` set.
73
+ * @returns The same options object, typed so that `queryKey` carries the inferred data type.
74
+ *
75
+ * @example
76
+ * ```tsx
77
+ * import { queryOptions, useQuery } from '@tanstack/preact-query'
78
+ *
79
+ * export const postsOptions = queryOptions({
80
+ * queryKey: ['posts'],
81
+ * queryFn: fetchPosts,
82
+ * initialData: [],
83
+ * })
84
+ *
85
+ * function Posts() {
86
+ * // `data` is `Post[]`, never `undefined`, thanks to `initialData`.
87
+ * const { data } = useQuery(postsOptions)
88
+ * return <>{data.map((post) => <p key={post.id}>{post.title}</p>)}</>
89
+ * }
90
+ * ```
91
+ */
14
92
  declare function queryOptions<TQueryFnData = unknown, TError = DefaultError, TData = TQueryFnData, TQueryKey extends QueryKey = QueryKey>(options: DefinedInitialDataOptions<TQueryFnData, TError, TData, TQueryKey>): DefinedInitialDataOptions<TQueryFnData, TError, TData, TQueryKey> & QueryKeyWithDataTag<TQueryKey, TQueryFnData, TError>;
93
+ /**
94
+ * You can generally pass everything to `queryOptions` that you can also pass to `useQuery`. These options can
95
+ * be shared across hooks and imperative APIs such as `queryClient.query`. `options.queryKey` is required and
96
+ * is the query key to generate options for.
97
+ *
98
+ * @see {@link useQuery} to run a query with these options.
99
+ * @param options - The {@link UnusedSkipTokenOptions} to use — everything you can pass to `useQuery`.
100
+ * @returns The same options object, typed so that `queryKey` carries the inferred data type.
101
+ *
102
+ * @example
103
+ * ```tsx
104
+ * import { queryOptions } from '@tanstack/preact-query'
105
+ *
106
+ * export const postsOptions = queryOptions({
107
+ * queryKey: ['posts'],
108
+ * queryFn: fetchPosts,
109
+ * })
110
+ * ```
111
+ *
112
+ * @example
113
+ * A parameterized factory, reused across a hook and an imperative call with the same cache entry:
114
+ * ```tsx
115
+ * import { noop, queryOptions, useQuery } from '@tanstack/preact-query'
116
+ *
117
+ * export const postOptions = (id: string) =>
118
+ * queryOptions({
119
+ * queryKey: ['post', id],
120
+ * queryFn: () => fetchPost(id),
121
+ * })
122
+ *
123
+ * function Post({ id }: { id: string }) {
124
+ * const { data } = useQuery(postOptions(id))
125
+ * return <h1>{data?.title}</h1>
126
+ * }
127
+ *
128
+ * // Elsewhere, e.g. to warm the cache before rendering `<Post>`:
129
+ * queryClient.query(postOptions(id)).catch(noop)
130
+ * ```
131
+ *
132
+ * @example
133
+ * The same options object works with every API that accepts query options:
134
+ * ```tsx
135
+ * import {
136
+ * noop,
137
+ * queryOptions,
138
+ * useQuery,
139
+ * useSuspenseQuery,
140
+ * } from '@tanstack/preact-query'
141
+ *
142
+ * const todosOptions = queryOptions({
143
+ * queryKey: ['todos'],
144
+ * queryFn: fetchTodos,
145
+ * })
146
+ *
147
+ * useQuery(todosOptions)
148
+ * useSuspenseQuery(todosOptions)
149
+ * queryClient.query(todosOptions).catch(noop)
150
+ * queryClient.getQueryData(todosOptions.queryKey) // typed as Array<Todo> | undefined
151
+ * ```
152
+ */
15
153
  declare function queryOptions<TQueryFnData = unknown, TError = DefaultError, TData = TQueryFnData, TQueryKey extends QueryKey = QueryKey>(options: UnusedSkipTokenOptions<TQueryFnData, TError, TData, TQueryKey>): UnusedSkipTokenOptions<TQueryFnData, TError, TData, TQueryKey> & QueryKeyWithDataTag<TQueryKey, TQueryFnData, TError>;
154
+ /**
155
+ * You can generally pass everything to `queryOptions` that you can also pass to `useQuery`. These options can
156
+ * be shared across hooks and imperative APIs such as `queryClient.query`. `options.queryKey` is required and
157
+ * is the query key to generate options for.
158
+ *
159
+ * @see {@link useQuery} to run a query with these options.
160
+ * @param options - The {@link UndefinedInitialDataOptions} to use — everything you can pass to `useQuery`.
161
+ * @returns The same options object, typed so that `queryKey` carries the inferred data type.
162
+ *
163
+ * @example
164
+ * ```tsx
165
+ * import { queryOptions } from '@tanstack/preact-query'
166
+ *
167
+ * export const postsOptions = queryOptions({
168
+ * queryKey: ['posts'],
169
+ * queryFn: fetchPosts,
170
+ * })
171
+ * ```
172
+ *
173
+ * @example
174
+ * A parameterized factory, reused across a hook and an imperative call with the same cache entry:
175
+ * ```tsx
176
+ * import { noop, queryOptions, useQuery } from '@tanstack/preact-query'
177
+ *
178
+ * export const postOptions = (id: string) =>
179
+ * queryOptions({
180
+ * queryKey: ['post', id],
181
+ * queryFn: () => fetchPost(id),
182
+ * })
183
+ *
184
+ * function Post({ id }: { id: string }) {
185
+ * const { data } = useQuery(postOptions(id))
186
+ * return <h1>{data?.title}</h1>
187
+ * }
188
+ *
189
+ * // Elsewhere, e.g. to warm the cache before rendering `<Post>`:
190
+ * queryClient.query(postOptions(id)).catch(noop)
191
+ * ```
192
+ *
193
+ * @example
194
+ * The same options object works with every API that accepts query options:
195
+ * ```tsx
196
+ * import {
197
+ * noop,
198
+ * queryOptions,
199
+ * useQuery,
200
+ * useSuspenseQuery,
201
+ * } from '@tanstack/preact-query'
202
+ *
203
+ * const todosOptions = queryOptions({
204
+ * queryKey: ['todos'],
205
+ * queryFn: fetchTodos,
206
+ * })
207
+ *
208
+ * useQuery(todosOptions)
209
+ * useSuspenseQuery(todosOptions)
210
+ * queryClient.query(todosOptions).catch(noop)
211
+ * queryClient.getQueryData(todosOptions.queryKey) // typed as Array<Todo> | undefined
212
+ * ```
213
+ */
16
214
  declare function queryOptions<TQueryFnData = unknown, TError = DefaultError, TData = TQueryFnData, TQueryKey extends QueryKey = QueryKey>(options: UndefinedInitialDataOptions<TQueryFnData, TError, TData, TQueryKey>): UndefinedInitialDataOptions<TQueryFnData, TError, TData, TQueryKey> & QueryKeyWithDataTag<TQueryKey, TQueryFnData, TError>;
17
215
  //#endregion
18
216
  export { DefinedInitialDataOptions, UndefinedInitialDataOptions, UnusedSkipTokenOptions, queryOptions };
@@ -1 +1 @@
1
- {"version":3,"file":"queryOptions.d.cts","names":[],"sources":["../../src/queryOptions.ts"],"mappings":";;;KAaY,4BACV,wBACA,SAAS,cACT,QAAQ,cACR,kBAAkB,WAAW,YAC3B,gBAAgB,cAAc,QAAQ,OAAO;EAC/C,0BAEI,oBAAoB,kBAAkB,iBACtC,kBAAkB;;KAGZ,uBACV,wBACA,SAAS,cACT,QAAQ,cACR,kBAAkB,WAAW,YAC3B,UACF,gBAAgB,cAAc,QAAQ,OAAO;EAG7C,UAAU,QACR,gBAAgB,cAAc,QAAQ,OAAO,uBAC7C;;KAIQ,0BACV,wBACA,SAAS,cACT,QAAQ,cACR,kBAAkB,WAAW,YAC3B,KAAK,gBAAgB,cAAc,QAAQ,OAAO;EACpD,aACI,kBAAkB,uBACX,kBAAkB;EAC7B,UAAU,cAAc,cAAc;;iBAGxB,aACd,wBACA,SAAS,cACT,QAAQ,cACR,kBAAkB,WAAW,UAE7B,SAAS,0BAA0B,cAAc,QAAQ,OAAO,aAC/D,0BAA0B,cAAc,QAAQ,OAAO,aACxD,oBAAoB,WAAW,cAAc;iBAE/B,aACd,wBACA,SAAS,cACT,QAAQ,cACR,kBAAkB,WAAW,UAE7B,SAAS,uBAAuB,cAAc,QAAQ,OAAO,aAC5D,uBAAuB,cAAc,QAAQ,OAAO,aACrD,oBAAoB,WAAW,cAAc;iBAE/B,aACd,wBACA,SAAS,cACT,QAAQ,cACR,kBAAkB,WAAW,UAE7B,SAAS,4BAA4B,cAAc,QAAQ,OAAO,aACjE,4BAA4B,cAAc,QAAQ,OAAO,aAC1D,oBAAoB,WAAW,cAAc"}
1
+ {"version":3,"file":"queryOptions.d.cts","names":[],"sources":["../../src/queryOptions.ts"],"mappings":";;;;;;;;;;;;KAsBY,4BACV,wBACA,SAAS,cACT,QAAQ,cACR,kBAAkB,WAAW,YAC3B,gBAAgB,cAAc,QAAQ,OAAO;;;;;;;;EAQ/C,0BAEI,oBAAoB,kBAAkB,iBACtC,kBAAkB;;;;;;;;;;;KAYZ,uBACV,wBACA,SAAS,cACT,QAAQ,cACR,kBAAkB,WAAW,YAC3B,UACF,gBAAgB,cAAc,QAAQ,OAAO;;;;;EAO7C,UAAU,QACR,gBAAgB,cAAc,QAAQ,OAAO,uBAC7C;;;;;;;;;;;KAaQ,0BACV,wBACA,SAAS,cACT,QAAQ,cACR,kBAAkB,WAAW,YAC3B,KAAK,gBAAgB,cAAc,QAAQ,OAAO;;;;;;;;EAQpD,aACI,kBAAkB,uBACX,kBAAkB;;;;;;EAM7B,UAAU,cAAc,cAAc;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBA+BxB,aACd,wBACA,SAAS,cACT,QAAQ,cACR,kBAAkB,WAAW,UAE7B,SAAS,0BAA0B,cAAc,QAAQ,OAAO,aAC/D,0BAA0B,cAAc,QAAQ,OAAO,aACxD,oBAAoB,WAAW,cAAc;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBA8D/B,aACd,wBACA,SAAS,cACT,QAAQ,cACR,kBAAkB,WAAW,UAE7B,SAAS,uBAAuB,cAAc,QAAQ,OAAO,aAC5D,uBAAuB,cAAc,QAAQ,OAAO,aACrD,oBAAoB,WAAW,cAAc;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBA8D/B,aACd,wBACA,SAAS,cACT,QAAQ,cACR,kBAAkB,WAAW,UAE7B,SAAS,4BAA4B,cAAc,QAAQ,OAAO,aACjE,4BAA4B,cAAc,QAAQ,OAAO,aAC1D,oBAAoB,WAAW,cAAc"}
@@ -1,18 +1,216 @@
1
1
  import { UseQueryOptions } from "./types.js";
2
2
  import { DefaultError, InitialDataFunction, NonUndefinedGuard, OmitKeyof, QueryFunction, QueryKey, QueryKeyWithDataTag, SkipToken } from "@tanstack/query-core";
3
3
  //#region src/queryOptions.d.ts
4
+ /**
5
+ * The options accepted by the `queryOptions` overload selected when no `initialData` is set — `data` may be
6
+ * `undefined` while the query is `pending`.
7
+ *
8
+ * @template TQueryFnData - The type your `queryFn` resolves to.
9
+ * @template TError - The type of errors your `queryFn` may throw.
10
+ * @template TData - The type `data` ends up as after `select` runs.
11
+ * @template TQueryKey - The type of your `queryKey`.
12
+ */
4
13
  type UndefinedInitialDataOptions<TQueryFnData = unknown, TError = DefaultError, TData = TQueryFnData, TQueryKey extends QueryKey = QueryKey> = UseQueryOptions<TQueryFnData, TError, TData, TQueryKey> & {
14
+ /**
15
+ * If set, this value will be used as the initial data for the query cache (as long as the query hasn't been
16
+ * created or cached yet). If set to a function, the function will be called **once** during the shared/root
17
+ * query initialization, and be expected to synchronously return the initial data. Initial data is
18
+ * considered stale by default unless a `staleTime` has been set. `initialData` **is persisted** to the
19
+ * cache.
20
+ */
5
21
  initialData?: undefined | InitialDataFunction<NonUndefinedGuard<TQueryFnData>> | NonUndefinedGuard<TQueryFnData>;
6
22
  };
23
+ /**
24
+ * The options accepted by the `queryOptions` overload selected when no `initialData` is set and `queryFn` is
25
+ * not `skipToken` — same as {@link UndefinedInitialDataOptions}, but `queryFn` may not be `skipToken`.
26
+ *
27
+ * @template TQueryFnData - The type your `queryFn` resolves to.
28
+ * @template TError - The type of errors your `queryFn` may throw.
29
+ * @template TData - The type `data` ends up as after `select` runs.
30
+ * @template TQueryKey - The type of your `queryKey`.
31
+ */
7
32
  type UnusedSkipTokenOptions<TQueryFnData = unknown, TError = DefaultError, TData = TQueryFnData, TQueryKey extends QueryKey = QueryKey> = OmitKeyof<UseQueryOptions<TQueryFnData, TError, TData, TQueryKey>, 'queryFn'> & {
33
+ /**
34
+ * `skipToken` is not allowed as a value here — this overload is selected when no `initialData` is set. If
35
+ * you don't intend to run the query yet, omit `queryFn` or use a default query function instead.
36
+ */
8
37
  queryFn?: Exclude<UseQueryOptions<TQueryFnData, TError, TData, TQueryKey>['queryFn'], SkipToken | undefined>;
9
38
  };
39
+ /**
40
+ * The options accepted by the `queryOptions` overload selected when `initialData` is set — `data` is never
41
+ * `undefined`.
42
+ *
43
+ * @template TQueryFnData - The type your `queryFn` resolves to.
44
+ * @template TError - The type of errors your `queryFn` may throw.
45
+ * @template TData - The type `data` ends up as after `select` runs.
46
+ * @template TQueryKey - The type of your `queryKey`.
47
+ */
10
48
  type DefinedInitialDataOptions<TQueryFnData = unknown, TError = DefaultError, TData = TQueryFnData, TQueryKey extends QueryKey = QueryKey> = Omit<UseQueryOptions<TQueryFnData, TError, TData, TQueryKey>, 'queryFn'> & {
49
+ /**
50
+ * If set, this value will be used as the initial data for the query cache (as long as the query hasn't been
51
+ * created or cached yet). If set to a function, the function will be called **once** during the shared/root
52
+ * query initialization, and be expected to synchronously return the initial data. Initial data is
53
+ * considered stale by default unless a `staleTime` has been set. `initialData` **is persisted** to the
54
+ * cache.
55
+ */
11
56
  initialData: NonUndefinedGuard<TQueryFnData> | (() => NonUndefinedGuard<TQueryFnData>);
57
+ /**
58
+ * Optional here, but omitting it is only safe when no fetch will be attempted — for example with
59
+ * `enabled: false`, or when a default query function has been defined. Otherwise, an enabled query with no
60
+ * `queryFn` still tries to fetch and fails with a "Missing queryFn" error; `initialData` does not prevent this.
61
+ */
12
62
  queryFn?: QueryFunction<TQueryFnData, TQueryKey>;
13
63
  };
64
+ /**
65
+ * You can generally pass everything to `queryOptions` that you can also pass to `useQuery`. These options can
66
+ * be shared across hooks and imperative APIs such as `queryClient.query`. `options.queryKey` is required and
67
+ * is the query key to generate options for.
68
+ *
69
+ * This overload is selected when `initialData` is set, so the resulting `data` is never `undefined`.
70
+ *
71
+ * @see {@link useQuery} to run a query with these options.
72
+ * @param options - The {@link DefinedInitialDataOptions} to use — everything you can pass to `useQuery`, with `initialData` set.
73
+ * @returns The same options object, typed so that `queryKey` carries the inferred data type.
74
+ *
75
+ * @example
76
+ * ```tsx
77
+ * import { queryOptions, useQuery } from '@tanstack/preact-query'
78
+ *
79
+ * export const postsOptions = queryOptions({
80
+ * queryKey: ['posts'],
81
+ * queryFn: fetchPosts,
82
+ * initialData: [],
83
+ * })
84
+ *
85
+ * function Posts() {
86
+ * // `data` is `Post[]`, never `undefined`, thanks to `initialData`.
87
+ * const { data } = useQuery(postsOptions)
88
+ * return <>{data.map((post) => <p key={post.id}>{post.title}</p>)}</>
89
+ * }
90
+ * ```
91
+ */
14
92
  declare function queryOptions<TQueryFnData = unknown, TError = DefaultError, TData = TQueryFnData, TQueryKey extends QueryKey = QueryKey>(options: DefinedInitialDataOptions<TQueryFnData, TError, TData, TQueryKey>): DefinedInitialDataOptions<TQueryFnData, TError, TData, TQueryKey> & QueryKeyWithDataTag<TQueryKey, TQueryFnData, TError>;
93
+ /**
94
+ * You can generally pass everything to `queryOptions` that you can also pass to `useQuery`. These options can
95
+ * be shared across hooks and imperative APIs such as `queryClient.query`. `options.queryKey` is required and
96
+ * is the query key to generate options for.
97
+ *
98
+ * @see {@link useQuery} to run a query with these options.
99
+ * @param options - The {@link UnusedSkipTokenOptions} to use — everything you can pass to `useQuery`.
100
+ * @returns The same options object, typed so that `queryKey` carries the inferred data type.
101
+ *
102
+ * @example
103
+ * ```tsx
104
+ * import { queryOptions } from '@tanstack/preact-query'
105
+ *
106
+ * export const postsOptions = queryOptions({
107
+ * queryKey: ['posts'],
108
+ * queryFn: fetchPosts,
109
+ * })
110
+ * ```
111
+ *
112
+ * @example
113
+ * A parameterized factory, reused across a hook and an imperative call with the same cache entry:
114
+ * ```tsx
115
+ * import { noop, queryOptions, useQuery } from '@tanstack/preact-query'
116
+ *
117
+ * export const postOptions = (id: string) =>
118
+ * queryOptions({
119
+ * queryKey: ['post', id],
120
+ * queryFn: () => fetchPost(id),
121
+ * })
122
+ *
123
+ * function Post({ id }: { id: string }) {
124
+ * const { data } = useQuery(postOptions(id))
125
+ * return <h1>{data?.title}</h1>
126
+ * }
127
+ *
128
+ * // Elsewhere, e.g. to warm the cache before rendering `<Post>`:
129
+ * queryClient.query(postOptions(id)).catch(noop)
130
+ * ```
131
+ *
132
+ * @example
133
+ * The same options object works with every API that accepts query options:
134
+ * ```tsx
135
+ * import {
136
+ * noop,
137
+ * queryOptions,
138
+ * useQuery,
139
+ * useSuspenseQuery,
140
+ * } from '@tanstack/preact-query'
141
+ *
142
+ * const todosOptions = queryOptions({
143
+ * queryKey: ['todos'],
144
+ * queryFn: fetchTodos,
145
+ * })
146
+ *
147
+ * useQuery(todosOptions)
148
+ * useSuspenseQuery(todosOptions)
149
+ * queryClient.query(todosOptions).catch(noop)
150
+ * queryClient.getQueryData(todosOptions.queryKey) // typed as Array<Todo> | undefined
151
+ * ```
152
+ */
15
153
  declare function queryOptions<TQueryFnData = unknown, TError = DefaultError, TData = TQueryFnData, TQueryKey extends QueryKey = QueryKey>(options: UnusedSkipTokenOptions<TQueryFnData, TError, TData, TQueryKey>): UnusedSkipTokenOptions<TQueryFnData, TError, TData, TQueryKey> & QueryKeyWithDataTag<TQueryKey, TQueryFnData, TError>;
154
+ /**
155
+ * You can generally pass everything to `queryOptions` that you can also pass to `useQuery`. These options can
156
+ * be shared across hooks and imperative APIs such as `queryClient.query`. `options.queryKey` is required and
157
+ * is the query key to generate options for.
158
+ *
159
+ * @see {@link useQuery} to run a query with these options.
160
+ * @param options - The {@link UndefinedInitialDataOptions} to use — everything you can pass to `useQuery`.
161
+ * @returns The same options object, typed so that `queryKey` carries the inferred data type.
162
+ *
163
+ * @example
164
+ * ```tsx
165
+ * import { queryOptions } from '@tanstack/preact-query'
166
+ *
167
+ * export const postsOptions = queryOptions({
168
+ * queryKey: ['posts'],
169
+ * queryFn: fetchPosts,
170
+ * })
171
+ * ```
172
+ *
173
+ * @example
174
+ * A parameterized factory, reused across a hook and an imperative call with the same cache entry:
175
+ * ```tsx
176
+ * import { noop, queryOptions, useQuery } from '@tanstack/preact-query'
177
+ *
178
+ * export const postOptions = (id: string) =>
179
+ * queryOptions({
180
+ * queryKey: ['post', id],
181
+ * queryFn: () => fetchPost(id),
182
+ * })
183
+ *
184
+ * function Post({ id }: { id: string }) {
185
+ * const { data } = useQuery(postOptions(id))
186
+ * return <h1>{data?.title}</h1>
187
+ * }
188
+ *
189
+ * // Elsewhere, e.g. to warm the cache before rendering `<Post>`:
190
+ * queryClient.query(postOptions(id)).catch(noop)
191
+ * ```
192
+ *
193
+ * @example
194
+ * The same options object works with every API that accepts query options:
195
+ * ```tsx
196
+ * import {
197
+ * noop,
198
+ * queryOptions,
199
+ * useQuery,
200
+ * useSuspenseQuery,
201
+ * } from '@tanstack/preact-query'
202
+ *
203
+ * const todosOptions = queryOptions({
204
+ * queryKey: ['todos'],
205
+ * queryFn: fetchTodos,
206
+ * })
207
+ *
208
+ * useQuery(todosOptions)
209
+ * useSuspenseQuery(todosOptions)
210
+ * queryClient.query(todosOptions).catch(noop)
211
+ * queryClient.getQueryData(todosOptions.queryKey) // typed as Array<Todo> | undefined
212
+ * ```
213
+ */
16
214
  declare function queryOptions<TQueryFnData = unknown, TError = DefaultError, TData = TQueryFnData, TQueryKey extends QueryKey = QueryKey>(options: UndefinedInitialDataOptions<TQueryFnData, TError, TData, TQueryKey>): UndefinedInitialDataOptions<TQueryFnData, TError, TData, TQueryKey> & QueryKeyWithDataTag<TQueryKey, TQueryFnData, TError>;
17
215
  //#endregion
18
216
  export { DefinedInitialDataOptions, UndefinedInitialDataOptions, UnusedSkipTokenOptions, queryOptions };
@@ -1 +1 @@
1
- {"version":3,"file":"queryOptions.d.ts","names":[],"sources":["../../src/queryOptions.ts"],"mappings":";;;KAaY,4BACV,wBACA,SAAS,cACT,QAAQ,cACR,kBAAkB,WAAW,YAC3B,gBAAgB,cAAc,QAAQ,OAAO;EAC/C,0BAEI,oBAAoB,kBAAkB,iBACtC,kBAAkB;;KAGZ,uBACV,wBACA,SAAS,cACT,QAAQ,cACR,kBAAkB,WAAW,YAC3B,UACF,gBAAgB,cAAc,QAAQ,OAAO;EAG7C,UAAU,QACR,gBAAgB,cAAc,QAAQ,OAAO,uBAC7C;;KAIQ,0BACV,wBACA,SAAS,cACT,QAAQ,cACR,kBAAkB,WAAW,YAC3B,KAAK,gBAAgB,cAAc,QAAQ,OAAO;EACpD,aACI,kBAAkB,uBACX,kBAAkB;EAC7B,UAAU,cAAc,cAAc;;iBAGxB,aACd,wBACA,SAAS,cACT,QAAQ,cACR,kBAAkB,WAAW,UAE7B,SAAS,0BAA0B,cAAc,QAAQ,OAAO,aAC/D,0BAA0B,cAAc,QAAQ,OAAO,aACxD,oBAAoB,WAAW,cAAc;iBAE/B,aACd,wBACA,SAAS,cACT,QAAQ,cACR,kBAAkB,WAAW,UAE7B,SAAS,uBAAuB,cAAc,QAAQ,OAAO,aAC5D,uBAAuB,cAAc,QAAQ,OAAO,aACrD,oBAAoB,WAAW,cAAc;iBAE/B,aACd,wBACA,SAAS,cACT,QAAQ,cACR,kBAAkB,WAAW,UAE7B,SAAS,4BAA4B,cAAc,QAAQ,OAAO,aACjE,4BAA4B,cAAc,QAAQ,OAAO,aAC1D,oBAAoB,WAAW,cAAc"}
1
+ {"version":3,"file":"queryOptions.d.ts","names":[],"sources":["../../src/queryOptions.ts"],"mappings":";;;;;;;;;;;;KAsBY,4BACV,wBACA,SAAS,cACT,QAAQ,cACR,kBAAkB,WAAW,YAC3B,gBAAgB,cAAc,QAAQ,OAAO;;;;;;;;EAQ/C,0BAEI,oBAAoB,kBAAkB,iBACtC,kBAAkB;;;;;;;;;;;KAYZ,uBACV,wBACA,SAAS,cACT,QAAQ,cACR,kBAAkB,WAAW,YAC3B,UACF,gBAAgB,cAAc,QAAQ,OAAO;;;;;EAO7C,UAAU,QACR,gBAAgB,cAAc,QAAQ,OAAO,uBAC7C;;;;;;;;;;;KAaQ,0BACV,wBACA,SAAS,cACT,QAAQ,cACR,kBAAkB,WAAW,YAC3B,KAAK,gBAAgB,cAAc,QAAQ,OAAO;;;;;;;;EAQpD,aACI,kBAAkB,uBACX,kBAAkB;;;;;;EAM7B,UAAU,cAAc,cAAc;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBA+BxB,aACd,wBACA,SAAS,cACT,QAAQ,cACR,kBAAkB,WAAW,UAE7B,SAAS,0BAA0B,cAAc,QAAQ,OAAO,aAC/D,0BAA0B,cAAc,QAAQ,OAAO,aACxD,oBAAoB,WAAW,cAAc;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBA8D/B,aACd,wBACA,SAAS,cACT,QAAQ,cACR,kBAAkB,WAAW,UAE7B,SAAS,uBAAuB,cAAc,QAAQ,OAAO,aAC5D,uBAAuB,cAAc,QAAQ,OAAO,aACrD,oBAAoB,WAAW,cAAc;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBA8D/B,aACd,wBACA,SAAS,cACT,QAAQ,cACR,kBAAkB,WAAW,UAE7B,SAAS,4BAA4B,cAAc,QAAQ,OAAO,aACjE,4BAA4B,cAAc,QAAQ,OAAO,aAC1D,oBAAoB,WAAW,cAAc"}
@@ -1 +1 @@
1
- {"version":3,"file":"queryOptions.js","names":[],"sources":["../../src/queryOptions.ts"],"sourcesContent":["import type {\n DefaultError,\n InitialDataFunction,\n NonUndefinedGuard,\n OmitKeyof,\n QueryFunction,\n QueryKey,\n QueryKeyWithDataTag,\n SkipToken,\n} from '@tanstack/query-core'\n\nimport type { UseQueryOptions } from './types'\n\nexport type UndefinedInitialDataOptions<\n TQueryFnData = unknown,\n TError = DefaultError,\n TData = TQueryFnData,\n TQueryKey extends QueryKey = QueryKey,\n> = UseQueryOptions<TQueryFnData, TError, TData, TQueryKey> & {\n initialData?:\n | undefined\n | InitialDataFunction<NonUndefinedGuard<TQueryFnData>>\n | NonUndefinedGuard<TQueryFnData>\n}\n\nexport type UnusedSkipTokenOptions<\n TQueryFnData = unknown,\n TError = DefaultError,\n TData = TQueryFnData,\n TQueryKey extends QueryKey = QueryKey,\n> = OmitKeyof<\n UseQueryOptions<TQueryFnData, TError, TData, TQueryKey>,\n 'queryFn'\n> & {\n queryFn?: Exclude<\n UseQueryOptions<TQueryFnData, TError, TData, TQueryKey>['queryFn'],\n SkipToken | undefined\n >\n}\n\nexport type DefinedInitialDataOptions<\n TQueryFnData = unknown,\n TError = DefaultError,\n TData = TQueryFnData,\n TQueryKey extends QueryKey = QueryKey,\n> = Omit<UseQueryOptions<TQueryFnData, TError, TData, TQueryKey>, 'queryFn'> & {\n initialData:\n | NonUndefinedGuard<TQueryFnData>\n | (() => NonUndefinedGuard<TQueryFnData>)\n queryFn?: QueryFunction<TQueryFnData, TQueryKey>\n}\n\nexport function queryOptions<\n TQueryFnData = unknown,\n TError = DefaultError,\n TData = TQueryFnData,\n TQueryKey extends QueryKey = QueryKey,\n>(\n options: DefinedInitialDataOptions<TQueryFnData, TError, TData, TQueryKey>,\n): DefinedInitialDataOptions<TQueryFnData, TError, TData, TQueryKey> &\n QueryKeyWithDataTag<TQueryKey, TQueryFnData, TError>\n\nexport function queryOptions<\n TQueryFnData = unknown,\n TError = DefaultError,\n TData = TQueryFnData,\n TQueryKey extends QueryKey = QueryKey,\n>(\n options: UnusedSkipTokenOptions<TQueryFnData, TError, TData, TQueryKey>,\n): UnusedSkipTokenOptions<TQueryFnData, TError, TData, TQueryKey> &\n QueryKeyWithDataTag<TQueryKey, TQueryFnData, TError>\n\nexport function queryOptions<\n TQueryFnData = unknown,\n TError = DefaultError,\n TData = TQueryFnData,\n TQueryKey extends QueryKey = QueryKey,\n>(\n options: UndefinedInitialDataOptions<TQueryFnData, TError, TData, TQueryKey>,\n): UndefinedInitialDataOptions<TQueryFnData, TError, TData, TQueryKey> &\n QueryKeyWithDataTag<TQueryKey, TQueryFnData, TError>\n\nexport function queryOptions(options: unknown) {\n return options\n}\n"],"mappings":";AAkFA,SAAgB,aAAa,SAAkB;CAC7C,OAAO;AACT"}
1
+ {"version":3,"file":"queryOptions.js","names":[],"sources":["../../src/queryOptions.ts"],"sourcesContent":["import type {\n DefaultError,\n InitialDataFunction,\n NonUndefinedGuard,\n OmitKeyof,\n QueryFunction,\n QueryKey,\n QueryKeyWithDataTag,\n SkipToken,\n} from '@tanstack/query-core'\n\nimport type { UseQueryOptions } from './types'\n\n/**\n * The options accepted by the `queryOptions` overload selected when no `initialData` is set — `data` may be\n * `undefined` while the query is `pending`.\n *\n * @template TQueryFnData - The type your `queryFn` resolves to.\n * @template TError - The type of errors your `queryFn` may throw.\n * @template TData - The type `data` ends up as after `select` runs.\n * @template TQueryKey - The type of your `queryKey`.\n */\nexport type UndefinedInitialDataOptions<\n TQueryFnData = unknown,\n TError = DefaultError,\n TData = TQueryFnData,\n TQueryKey extends QueryKey = QueryKey,\n> = UseQueryOptions<TQueryFnData, TError, TData, TQueryKey> & {\n /**\n * If set, this value will be used as the initial data for the query cache (as long as the query hasn't been\n * created or cached yet). If set to a function, the function will be called **once** during the shared/root\n * query initialization, and be expected to synchronously return the initial data. Initial data is\n * considered stale by default unless a `staleTime` has been set. `initialData` **is persisted** to the\n * cache.\n */\n initialData?:\n | undefined\n | InitialDataFunction<NonUndefinedGuard<TQueryFnData>>\n | NonUndefinedGuard<TQueryFnData>\n}\n\n/**\n * The options accepted by the `queryOptions` overload selected when no `initialData` is set and `queryFn` is\n * not `skipToken` — same as {@link UndefinedInitialDataOptions}, but `queryFn` may not be `skipToken`.\n *\n * @template TQueryFnData - The type your `queryFn` resolves to.\n * @template TError - The type of errors your `queryFn` may throw.\n * @template TData - The type `data` ends up as after `select` runs.\n * @template TQueryKey - The type of your `queryKey`.\n */\nexport type UnusedSkipTokenOptions<\n TQueryFnData = unknown,\n TError = DefaultError,\n TData = TQueryFnData,\n TQueryKey extends QueryKey = QueryKey,\n> = OmitKeyof<\n UseQueryOptions<TQueryFnData, TError, TData, TQueryKey>,\n 'queryFn'\n> & {\n /**\n * `skipToken` is not allowed as a value here — this overload is selected when no `initialData` is set. If\n * you don't intend to run the query yet, omit `queryFn` or use a default query function instead.\n */\n queryFn?: Exclude<\n UseQueryOptions<TQueryFnData, TError, TData, TQueryKey>['queryFn'],\n SkipToken | undefined\n >\n}\n\n/**\n * The options accepted by the `queryOptions` overload selected when `initialData` is set — `data` is never\n * `undefined`.\n *\n * @template TQueryFnData - The type your `queryFn` resolves to.\n * @template TError - The type of errors your `queryFn` may throw.\n * @template TData - The type `data` ends up as after `select` runs.\n * @template TQueryKey - The type of your `queryKey`.\n */\nexport type DefinedInitialDataOptions<\n TQueryFnData = unknown,\n TError = DefaultError,\n TData = TQueryFnData,\n TQueryKey extends QueryKey = QueryKey,\n> = Omit<UseQueryOptions<TQueryFnData, TError, TData, TQueryKey>, 'queryFn'> & {\n /**\n * If set, this value will be used as the initial data for the query cache (as long as the query hasn't been\n * created or cached yet). If set to a function, the function will be called **once** during the shared/root\n * query initialization, and be expected to synchronously return the initial data. Initial data is\n * considered stale by default unless a `staleTime` has been set. `initialData` **is persisted** to the\n * cache.\n */\n initialData:\n | NonUndefinedGuard<TQueryFnData>\n | (() => NonUndefinedGuard<TQueryFnData>)\n /**\n * Optional here, but omitting it is only safe when no fetch will be attempted — for example with\n * `enabled: false`, or when a default query function has been defined. Otherwise, an enabled query with no\n * `queryFn` still tries to fetch and fails with a \"Missing queryFn\" error; `initialData` does not prevent this.\n */\n queryFn?: QueryFunction<TQueryFnData, TQueryKey>\n}\n\n/**\n * You can generally pass everything to `queryOptions` that you can also pass to `useQuery`. These options can\n * be shared across hooks and imperative APIs such as `queryClient.query`. `options.queryKey` is required and\n * is the query key to generate options for.\n *\n * This overload is selected when `initialData` is set, so the resulting `data` is never `undefined`.\n *\n * @see {@link useQuery} to run a query with these options.\n * @param options - The {@link DefinedInitialDataOptions} to use — everything you can pass to `useQuery`, with `initialData` set.\n * @returns The same options object, typed so that `queryKey` carries the inferred data type.\n *\n * @example\n * ```tsx\n * import { queryOptions, useQuery } from '@tanstack/preact-query'\n *\n * export const postsOptions = queryOptions({\n * queryKey: ['posts'],\n * queryFn: fetchPosts,\n * initialData: [],\n * })\n *\n * function Posts() {\n * // `data` is `Post[]`, never `undefined`, thanks to `initialData`.\n * const { data } = useQuery(postsOptions)\n * return <>{data.map((post) => <p key={post.id}>{post.title}</p>)}</>\n * }\n * ```\n */\nexport function queryOptions<\n TQueryFnData = unknown,\n TError = DefaultError,\n TData = TQueryFnData,\n TQueryKey extends QueryKey = QueryKey,\n>(\n options: DefinedInitialDataOptions<TQueryFnData, TError, TData, TQueryKey>,\n): DefinedInitialDataOptions<TQueryFnData, TError, TData, TQueryKey> &\n QueryKeyWithDataTag<TQueryKey, TQueryFnData, TError>\n\n/**\n * You can generally pass everything to `queryOptions` that you can also pass to `useQuery`. These options can\n * be shared across hooks and imperative APIs such as `queryClient.query`. `options.queryKey` is required and\n * is the query key to generate options for.\n *\n * @see {@link useQuery} to run a query with these options.\n * @param options - The {@link UnusedSkipTokenOptions} to use — everything you can pass to `useQuery`.\n * @returns The same options object, typed so that `queryKey` carries the inferred data type.\n *\n * @example\n * ```tsx\n * import { queryOptions } from '@tanstack/preact-query'\n *\n * export const postsOptions = queryOptions({\n * queryKey: ['posts'],\n * queryFn: fetchPosts,\n * })\n * ```\n *\n * @example\n * A parameterized factory, reused across a hook and an imperative call with the same cache entry:\n * ```tsx\n * import { noop, queryOptions, useQuery } from '@tanstack/preact-query'\n *\n * export const postOptions = (id: string) =>\n * queryOptions({\n * queryKey: ['post', id],\n * queryFn: () => fetchPost(id),\n * })\n *\n * function Post({ id }: { id: string }) {\n * const { data } = useQuery(postOptions(id))\n * return <h1>{data?.title}</h1>\n * }\n *\n * // Elsewhere, e.g. to warm the cache before rendering `<Post>`:\n * queryClient.query(postOptions(id)).catch(noop)\n * ```\n *\n * @example\n * The same options object works with every API that accepts query options:\n * ```tsx\n * import {\n * noop,\n * queryOptions,\n * useQuery,\n * useSuspenseQuery,\n * } from '@tanstack/preact-query'\n *\n * const todosOptions = queryOptions({\n * queryKey: ['todos'],\n * queryFn: fetchTodos,\n * })\n *\n * useQuery(todosOptions)\n * useSuspenseQuery(todosOptions)\n * queryClient.query(todosOptions).catch(noop)\n * queryClient.getQueryData(todosOptions.queryKey) // typed as Array<Todo> | undefined\n * ```\n */\nexport function queryOptions<\n TQueryFnData = unknown,\n TError = DefaultError,\n TData = TQueryFnData,\n TQueryKey extends QueryKey = QueryKey,\n>(\n options: UnusedSkipTokenOptions<TQueryFnData, TError, TData, TQueryKey>,\n): UnusedSkipTokenOptions<TQueryFnData, TError, TData, TQueryKey> &\n QueryKeyWithDataTag<TQueryKey, TQueryFnData, TError>\n\n/**\n * You can generally pass everything to `queryOptions` that you can also pass to `useQuery`. These options can\n * be shared across hooks and imperative APIs such as `queryClient.query`. `options.queryKey` is required and\n * is the query key to generate options for.\n *\n * @see {@link useQuery} to run a query with these options.\n * @param options - The {@link UndefinedInitialDataOptions} to use — everything you can pass to `useQuery`.\n * @returns The same options object, typed so that `queryKey` carries the inferred data type.\n *\n * @example\n * ```tsx\n * import { queryOptions } from '@tanstack/preact-query'\n *\n * export const postsOptions = queryOptions({\n * queryKey: ['posts'],\n * queryFn: fetchPosts,\n * })\n * ```\n *\n * @example\n * A parameterized factory, reused across a hook and an imperative call with the same cache entry:\n * ```tsx\n * import { noop, queryOptions, useQuery } from '@tanstack/preact-query'\n *\n * export const postOptions = (id: string) =>\n * queryOptions({\n * queryKey: ['post', id],\n * queryFn: () => fetchPost(id),\n * })\n *\n * function Post({ id }: { id: string }) {\n * const { data } = useQuery(postOptions(id))\n * return <h1>{data?.title}</h1>\n * }\n *\n * // Elsewhere, e.g. to warm the cache before rendering `<Post>`:\n * queryClient.query(postOptions(id)).catch(noop)\n * ```\n *\n * @example\n * The same options object works with every API that accepts query options:\n * ```tsx\n * import {\n * noop,\n * queryOptions,\n * useQuery,\n * useSuspenseQuery,\n * } from '@tanstack/preact-query'\n *\n * const todosOptions = queryOptions({\n * queryKey: ['todos'],\n * queryFn: fetchTodos,\n * })\n *\n * useQuery(todosOptions)\n * useSuspenseQuery(todosOptions)\n * queryClient.query(todosOptions).catch(noop)\n * queryClient.getQueryData(todosOptions.queryKey) // typed as Array<Todo> | undefined\n * ```\n */\nexport function queryOptions<\n TQueryFnData = unknown,\n TError = DefaultError,\n TData = TQueryFnData,\n TQueryKey extends QueryKey = QueryKey,\n>(\n options: UndefinedInitialDataOptions<TQueryFnData, TError, TData, TQueryKey>,\n): UndefinedInitialDataOptions<TQueryFnData, TError, TData, TQueryKey> &\n QueryKeyWithDataTag<TQueryKey, TQueryFnData, TError>\n\nexport function queryOptions(options: unknown) {\n return options\n}\n"],"mappings":";AAwRA,SAAgB,aAAa,SAAkB;CAC7C,OAAO;AACT"}