Open History to see the last commit
1/* istanbul ignore file */
2import type {
3 DefaultError,
4 DefinedInfiniteQueryObserverResult,
5 DefinedQueryObserverResult,
6 DistributiveOmit,
7 InfiniteData,
8 InfiniteQueryExecuteOptions,
9 InfiniteQueryObserverOptions,
10 InfiniteQueryObserverResult,
11 MutateFunction,
12 MutationObserverOptions,
13 MutationObserverResult,
14 OmitKeyof,
15 Override,
16 QueryExecuteOptions,
17 QueryKey,
18 QueryObserverOptions,
19 QueryObserverResult,
20 SkipToken,
21} from '@tanstack/query-core'
22β
23/**
24 * {@link UseBaseQueryOptions} with all type parameters set to `any`, useful when the specific types aren't
25 * relevant, e.g. when accepting options for any query in a helper function.
26 */
27export type AnyUseBaseQueryOptions = UseBaseQueryOptions<
28 any,
29 any,
30 any,
31 any,
32 any
33>
34/**
35 * The options shared by `useQuery` and `useSuspenseQuery`. Extends {@link QueryObserverOptions} from
36 * `@tanstack/query-core` with the `preact-query`-specific `subscribed` option.
37 * @template TQueryFnData - The type your `queryFn` resolves to.
38 * @template TError - The type of errors your `queryFn` may throw.
39 * @template TData - The type `data` ends up as after `select` runs. Defaults to `TQueryFnData` when no
40 * `select` is used.
41 * @template TQueryData - The type of the data actually held in the query cache β the input to `select` and
42 * `placeholderData`. Defaults to, and is usually the same as, `TQueryFnData`.
43 * @template TQueryKey - The type of your `queryKey`.
44 */
45export interface UseBaseQueryOptions<
46 TQueryFnData = unknown,
47 TError = DefaultError,
48 TData = TQueryFnData,
49 TQueryData = TQueryFnData,
50 TQueryKey extends QueryKey = QueryKey,
51> extends QueryObserverOptions<
52 TQueryFnData,
53 TError,
54 TData,
55 TQueryData,
56 TQueryKey
57> {
58 /**
59 * Set this to `false` to unsubscribe this observer from updates to the query cache.
60 * @defaultValue true
61 */
62 subscribed?: boolean
63}
64β
65/**
66 * The options accepted by `usePrefetchQuery` β everything you can pass to `queryClient.query`, except `queryFn`
67 * is required unless a default query function has been defined.
68 * @template TQueryFnData - The type your `queryFn` resolves to.
69 * @template TError - The type of errors your `queryFn` may throw.
70 * @template TData - The type `data` ends up as after `select` runs. Defaults to `TQueryFnData` when no
71 * `select` is used.
72 * @template TQueryData - The type of the data actually held in the query cache β the input to `select` and
73 * `placeholderData`. Defaults to, and is usually the same as, `TQueryFnData`.
74 * @template TQueryKey - The type of your `queryKey`.
75 */
76export type UsePrefetchQueryOptions<
77 TQueryFnData = unknown,
78 TError = DefaultError,
79 TData = TQueryFnData,
80 TQueryData = TQueryFnData,
81 TQueryKey extends QueryKey = QueryKey,
82> = DistributiveOmit<
83 QueryExecuteOptions<TQueryFnData, TError, TData, TQueryData, TQueryKey>,
84 'queryFn'
85> & {
86 /**
87 * `skipToken` is not allowed as a value here β a prefetch always needs a query function to actually run,
88 * unless a default query function has been defined.
89 */
90 queryFn?: Exclude<
91 QueryExecuteOptions<
92 TQueryFnData,
93 TError,
94 TData,
95 TQueryFnData,
96 TQueryKey
97 >['queryFn'],
98 SkipToken
99 >
100}
101β
102/**
103 * The options accepted by `usePrefetchInfiniteQuery` β everything you can pass to `queryClient.infiniteQuery`,
104 * except `queryFn` is required unless a default query function has been defined.
105 * @template TQueryFnData - The type of a single page, as your `queryFn` resolves it.
106 * @template TError - The type of errors your `queryFn` may throw.
107 * @template TData - The type `data` ends up as after `select` runs. Defaults to `TQueryFnData` (a single page)
108 * here, since a prefetch never reads `data` back out β this parameter only matters if you reuse these options
109 * elsewhere with `select` applied.
110 * @template TQueryKey - The type of your `queryKey`.
111 * @template TPageParam - The type of the parameter passed to `queryFn` to fetch a given page.
112 */
113export type UsePrefetchInfiniteQueryOptions<
114 TQueryFnData = unknown,
115 TError = DefaultError,
116 TData = TQueryFnData,
117 TQueryKey extends QueryKey = QueryKey,
118 TPageParam = unknown,
119> = DistributiveOmit<
120 InfiniteQueryExecuteOptions<
121 TQueryFnData,
122 TError,
123 TData,
124 TQueryKey,
125 TPageParam
126 >,
127 'queryFn'
128> & {
129 /**
130 * `skipToken` is not allowed as a value here β a prefetch always needs a query function to actually run,
131 * unless a default query function has been defined.
132 */
133 queryFn?: Exclude<
134 InfiniteQueryExecuteOptions<
135 TQueryFnData,
136 TError,
137 TData,
138 TQueryKey,
139 TPageParam
140 >['queryFn'],
141 SkipToken
142 >
143}
144β
145/**
146 * {@link UseQueryOptions} with all type parameters set to `any`, useful when the specific types aren't
147 * relevant, e.g. when accepting options for any query in a helper function.
148 */
149export type AnyUseQueryOptions = UseQueryOptions<any, any, any, any>
150/**
151 * The options accepted by `useQuery`. Same as {@link UseBaseQueryOptions}, minus `suspense` (which
152 * `preact-query` derives from which hook you call rather than exposing as an option).
153 * @template TQueryFnData - The type your `queryFn` resolves to.
154 * @template TError - The type of errors your `queryFn` may throw.
155 * @template TData - The type `data` ends up as after `select` runs. Defaults to `TQueryFnData` when no
156 * `select` is used.
157 * @template TQueryKey - The type of your `queryKey`.
158 */
159export interface UseQueryOptions<
160 TQueryFnData = unknown,
161 TError = DefaultError,
162 TData = TQueryFnData,
163 TQueryKey extends QueryKey = QueryKey,
164> extends OmitKeyof<
165 UseBaseQueryOptions<TQueryFnData, TError, TData, TQueryFnData, TQueryKey>,
166 'suspense'
167> {}
168β
169/**
170 * {@link UseSuspenseQueryOptions} with all type parameters set to `any`, useful when the specific types aren't
171 * relevant, e.g. when accepting options for any query in a helper function.
172 */
173export type AnyUseSuspenseQueryOptions = UseSuspenseQueryOptions<
174 any,
175 any,
176 any,
177 any
178>
179/**
180 * The options accepted by `useSuspenseQuery`. Same as {@link UseQueryOptions}, minus `enabled`, `throwOnError`,
181 * and `placeholderData` β Suspense hooks cannot render a "disabled" or "placeholder" state, so those options
182 * don't apply.
183 * @template TQueryFnData - The type your `queryFn` resolves to.
184 * @template TError - The type of errors your `queryFn` may throw.
185 * @template TData - The type `data` ends up as after `select` runs. Defaults to `TQueryFnData` when no
186 * `select` is used.
187 * @template TQueryKey - The type of your `queryKey`.
188 */
189export interface UseSuspenseQueryOptions<
190 TQueryFnData = unknown,
191 TError = DefaultError,
192 TData = TQueryFnData,
193 TQueryKey extends QueryKey = QueryKey,
194> extends OmitKeyof<
195 UseQueryOptions<TQueryFnData, TError, TData, TQueryKey>,
196 'queryFn' | 'enabled' | 'throwOnError' | 'placeholderData'
197> {
198 /**
199 * `skipToken` is not allowed here β Suspense hooks cannot render a "disabled" state, so a query function
200 * must always be provided, unless a default query function has been defined.
201 */
202 queryFn?: Exclude<
203 UseQueryOptions<TQueryFnData, TError, TData, TQueryKey>['queryFn'],
204 SkipToken
205 >
206}
207β
208/**
209 * {@link UseInfiniteQueryOptions} with all type parameters set to `any`, useful when the specific types aren't
210 * relevant, e.g. when accepting options for any query in a helper function.
211 */
212export type AnyUseInfiniteQueryOptions = UseInfiniteQueryOptions<
213 any,
214 any,
215 any,
216 any,
217 any
218>
219/**
220 * The options accepted by `useInfiniteQuery`. Extends {@link InfiniteQueryObserverOptions} from
221 * `@tanstack/query-core` with the `preact-query`-specific `subscribed` option, minus `suspense` (which
222 * `preact-query` derives from which hook you call rather than exposing as an option).
223 * @template TQueryFnData - The type of a single page, as your `queryFn` resolves it.
224 * @template TError - The type of errors your `queryFn` may throw.
225 * @template TData - The type `data` ends up as after `select` runs β defaults to `InfiniteData<TQueryFnData>`,
226 * the shape of all fetched pages plus their page params.
227 * @template TQueryKey - The type of your `queryKey`.
228 * @template TPageParam - The type of the parameter passed to `queryFn` to fetch a given page.
229 */
230export interface UseInfiniteQueryOptions<
231 TQueryFnData = unknown,
232 TError = DefaultError,
233 TData = InfiniteData<TQueryFnData>,
234 TQueryKey extends QueryKey = QueryKey,
235 TPageParam = unknown,
236> extends OmitKeyof<
237 InfiniteQueryObserverOptions<
238 TQueryFnData,
239 TError,
240 TData,
241 TQueryKey,
242 TPageParam
243 >,
244 'suspense'
245> {
246 /**
247 * Set this to `false` to unsubscribe this observer from updates to the query cache.
248 * @defaultValue true
249 */
250 subscribed?: boolean
251}
252β
253/**
254 * {@link UseSuspenseInfiniteQueryOptions} with all type parameters set to `any`, useful when the specific types
255 * aren't relevant, e.g. when accepting options for any query in a helper function.
256 */
257export type AnyUseSuspenseInfiniteQueryOptions =
258 UseSuspenseInfiniteQueryOptions<any, any, any, any, any>
259/**
260 * The options accepted by `useSuspenseInfiniteQuery`. Same as {@link UseInfiniteQueryOptions}, minus `enabled`,
261 * `throwOnError`, and `placeholderData` β Suspense hooks cannot render a "disabled" or "placeholder" state, so
262 * those options don't apply.
263 * @template TQueryFnData - The type of a single page, as your `queryFn` resolves it.
264 * @template TError - The type of errors your `queryFn` may throw.
265 * @template TData - The type `data` ends up as after `select` runs β defaults to `InfiniteData<TQueryFnData>`,
266 * the shape of all fetched pages plus their page params.
267 * @template TQueryKey - The type of your `queryKey`.
268 * @template TPageParam - The type of the parameter passed to `queryFn` to fetch a given page.
269 */
270export interface UseSuspenseInfiniteQueryOptions<
271 TQueryFnData = unknown,
272 TError = DefaultError,
273 TData = InfiniteData<TQueryFnData>,
274 TQueryKey extends QueryKey = QueryKey,
275 TPageParam = unknown,
276> extends OmitKeyof<
277 UseInfiniteQueryOptions<TQueryFnData, TError, TData, TQueryKey, TPageParam>,
278 'queryFn' | 'enabled' | 'throwOnError' | 'placeholderData'
279> {
280 /**
281 * `skipToken` is not allowed here β Suspense hooks cannot render a "disabled" state, so a query function
282 * must always be provided, unless a default query function has been defined.
283 */
284 queryFn?: Exclude<
285 UseInfiniteQueryOptions<
286 TQueryFnData,
287 TError,
288 TData,
289 TQueryKey,
290 TPageParam
291 >['queryFn'],
292 SkipToken
293 >
294}
295β
296/**
297 * The result of `useQuery` when `initialData` isn't set β `data` may be `undefined` while the query is
298 * `pending`. Re-exports {@link QueryObserverResult} from `@tanstack/query-core`. `useInfiniteQuery` returns
299 * {@link UseInfiniteQueryResult} instead.
300 * @template TData - The type `data` ends up as after `select` runs.
301 * @template TError - The type of errors your `queryFn` may throw.
302 */
303export type UseBaseQueryResult<
304 TData = unknown,
305 TError = DefaultError,
306> = QueryObserverResult<TData, TError>
307β
308/**
309 * The result of `useQuery`. Same as {@link UseBaseQueryResult}.
310 * @template TData - The type `data` ends up as after `select` runs.
311 * @template TError - The type of errors your `queryFn` may throw.
312 */
313export type UseQueryResult<
314 TData = unknown,
315 TError = DefaultError,
316> = UseBaseQueryResult<TData, TError>
317β
318/**
319 * The result of `useSuspenseQuery`. Same as {@link DefinedUseQueryResult}, minus `isPlaceholderData` β always
320 * `false` on that type, so this drops the dead field rather than an active state.
321 * @template TData - The type `data` ends up as after `select` runs.
322 * @template TError - The type of errors your `queryFn` may throw.
323 */
324export type UseSuspenseQueryResult<
325 TData = unknown,
326 TError = DefaultError,
327> = DistributiveOmit<
328 DefinedQueryObserverResult<TData, TError>,
329 'isPlaceholderData'
330>
331β
332/**
333 * The result of `useQuery` when `initialData` is set, or of `useSuspenseQuery` before the `isPlaceholderData`
334 * omission β `data` is never `undefined` (unless a `select` changes `TData` to include `undefined`).
335 * Re-exports {@link DefinedQueryObserverResult} from `@tanstack/query-core`.
336 * @template TData - The type `data` ends up as after `select` runs.
337 * @template TError - The type of errors your `queryFn` may throw.
338 */
339export type DefinedUseQueryResult<
340 TData = unknown,
341 TError = DefaultError,
342> = DefinedQueryObserverResult<TData, TError>
343β
344/**
345 * The result of `useInfiniteQuery` when `initialData` isn't set β `data` may be `undefined` while the query is
346 * `pending`. Re-exports {@link InfiniteQueryObserverResult} from `@tanstack/query-core`.
347 * @template TData - The type `data` ends up as after `select` runs.
348 * @template TError - The type of errors your `queryFn` may throw.
349 */
350export type UseInfiniteQueryResult<
351 TData = unknown,
352 TError = DefaultError,
353> = InfiniteQueryObserverResult<TData, TError>
354β
355/**
356 * The result of `useInfiniteQuery` when `initialData` is set β `data` is never `undefined` (unless a
357 * `select` changes `TData` to include `undefined`). Re-exports {@link DefinedInfiniteQueryObserverResult}
358 * from `@tanstack/query-core`.
359 * @template TData - The type `data` ends up as after `select` runs.
360 * @template TError - The type of errors your `queryFn` may throw.
361 */
362export type DefinedUseInfiniteQueryResult<
363 TData = unknown,
364 TError = DefaultError,
365> = DefinedInfiniteQueryObserverResult<TData, TError>
366β
367/**
368 * The result of `useSuspenseInfiniteQuery`. Same as {@link DefinedUseInfiniteQueryResult}, minus
369 * `isPlaceholderData` β Suspense hooks never render placeholder data.
370 * @template TData - The type `data` ends up as after `select` runs.
371 * @template TError - The type of errors your `queryFn` may throw.
372 */
373export type UseSuspenseInfiniteQueryResult<
374 TData = unknown,
375 TError = DefaultError,
376> = OmitKeyof<
377 DefinedInfiniteQueryObserverResult<TData, TError>,
378 'isPlaceholderData'
379>
380β
381/**
382 * {@link UseMutationOptions} with all type parameters set to `any`, useful when the specific types aren't
383 * relevant, e.g. when accepting options for any mutation in a helper function.
384 */
385export type AnyUseMutationOptions = UseMutationOptions<any, any, any, any>
386/**
387 * The options accepted by `useMutation`. Same as {@link MutationObserverOptions} from `@tanstack/query-core`,
388 * minus the internal `_defaulted` flag.
389 * @template TData - The type your mutation function resolves to.
390 * @template TError - The type of errors your mutation function may throw.
391 * @template TVariables - The type of the variable passed to `mutate`/`mutateAsync`.
392 * @template TOnMutateResult - The type returned by `onMutate`, passed to `onSuccess`/`onError`/`onSettled` as
393 * their `onMutateResult` parameter β useful for optimistic-update rollback data.
394 */
395export interface UseMutationOptions<
396 TData = unknown,
397 TError = DefaultError,
398 TVariables = void,
399 TOnMutateResult = unknown,
400> extends OmitKeyof<
401 MutationObserverOptions<TData, TError, TVariables, TOnMutateResult>,
402 '_defaulted'
403> {}
404β
405/**
406 * The type of `mutate`, as returned by `useMutation`. Forwards the variables (and an optional per-call
407 * `onSuccess`/`onError`/`onSettled`) to the underlying `mutate` call. Fire-and-forget β errors are surfaced
408 * through the mutation result instead of being thrown by `mutate`, unless `throwOnError` makes `useMutation`
409 * rethrow them.
410 * @template TData - The type your mutation function resolves to.
411 * @template TError - The type of errors your mutation function may throw.
412 * @template TVariables - The type of the variable passed to `mutate`.
413 * @template TOnMutateResult - The type returned by `onMutate`, passed to `onSuccess`/`onError`/`onSettled` as
414 * their `onMutateResult` parameter β useful for optimistic-update rollback data.
415 */
416export type UseMutateFunction<
417 TData = unknown,
418 TError = DefaultError,
419 TVariables = void,
420 TOnMutateResult = unknown,
421> = (
422 ...args: Parameters<
423 MutateFunction<TData, TError, TVariables, TOnMutateResult>
424 >
425) => void
426β
427/**
428 * The type of `mutateAsync`, as returned by `useMutation`. Similar to {@link UseMutateFunction}, but returns a
429 * promise which can be awaited.
430 * @template TData - The type your mutation function resolves to.
431 * @template TError - The type of errors your mutation function may throw.
432 * @template TVariables - The type of the variable passed to `mutateAsync`.
433 * @template TOnMutateResult - The type returned by `onMutate`, passed to `onSuccess`/`onError`/`onSettled` as
434 * their `onMutateResult` parameter β useful for optimistic-update rollback data.
435 */
436export type UseMutateAsyncFunction<
437 TData = unknown,
438 TError = DefaultError,
439 TVariables = void,
440 TOnMutateResult = unknown,
441> = MutateFunction<TData, TError, TVariables, TOnMutateResult>
442β
443/**
444 * The result of `useMutation`. Same as {@link MutationObserverResult} from `@tanstack/query-core`, with
445 * `mutate` narrowed to the fire-and-forget {@link UseMutateFunction} signature, plus the added `mutateAsync`.
446 * @template TData - The type your mutation function resolves to.
447 * @template TError - The type of errors your mutation function may throw.
448 * @template TVariables - The type of the variable passed to `mutate`/`mutateAsync`.
449 * @template TOnMutateResult - The type returned by `onMutate`, passed to `onSuccess`/`onError`/`onSettled` as
450 * their `onMutateResult` parameter β useful for optimistic-update rollback data.
451 */
452export type UseBaseMutationResult<
453 TData = unknown,
454 TError = DefaultError,
455 TVariables = unknown,
456 TOnMutateResult = unknown,
457> = Override<
458 MutationObserverResult<TData, TError, TVariables, TOnMutateResult>,
459 { mutate: UseMutateFunction<TData, TError, TVariables, TOnMutateResult> }
460> & {
461 /**
462 * Similar to `mutate`, but returns a promise which can be awaited.
463 */
464 mutateAsync: UseMutateAsyncFunction<
465 TData,
466 TError,
467 TVariables,
468 TOnMutateResult
469 >
470}
471β
472/**
473 * The result of `useMutation`. Same as {@link UseBaseMutationResult}.
474 * @template TData - The type your mutation function resolves to.
475 * @template TError - The type of errors your mutation function may throw.
476 * @template TVariables - The type of the variable passed to `mutate`/`mutateAsync`.
477 * @template TOnMutateResult - The type returned by `onMutate`, passed to `onSuccess`/`onError`/`onSettled` as
478 * their `onMutateResult` parameter β useful for optimistic-update rollback data.
479 */
480export type UseMutationResult<
481 TData = unknown,
482 TError = DefaultError,
483 TVariables = unknown,
484 TOnMutateResult = unknown,
485> = UseBaseMutationResult<TData, TError, TVariables, TOnMutateResult>