Open History to see the last commit
1import type {
2 DefaultError,
3 DehydrateOptions,
4 HydrateOptions,
5 MutationCache,
6 MutationObserverOptions,
7 OmitKeyof,
8 QueryCache,
9 QueryObserverOptions,
10} from '@tanstack/query-core'
11import type { ComputedRef, Ref, UnwrapRef } from 'vue-demi'
12β
13type Primitive = string | number | boolean | bigint | symbol | undefined | null
14type UnwrapLeaf =
15 | Primitive
16 | Function
17 | Date
18 | Error
19 | RegExp
20 | Map<any, any>
21 | WeakMap<any, any>
22 | Set<any>
23 | WeakSet<any>
24β
25/** A plain value or a reactive getter (`() => T`) that returns one. */
26export type MaybeGetter<T> = T | (() => T)
27β
28/**
29 * A plain value, a `Ref`, or a `ComputedRef`. Accepting this instead of a bare `T` lets a composable take
30 * either a reactive or a static value for a given option β see the [Reactivity guide](../../reactivity.md).
31 */
32export type MaybeRef<T> = Ref<T> | ComputedRef<T> | T
33β
34/**
35 * A {@link MaybeRef}, or a reactive getter (`() => T`). Reactive getters are a lighter-weight alternative to
36 * `computed` for deriving a value from other reactive state β see the
37 * [Reactivity guide](../../reactivity.md#using-derived-state-inside-queries).
38 */
39export type MaybeRefOrGetter<T> = MaybeRef<T> | (() => T)
40β
41/**
42 * Like {@link MaybeRef}, but applied recursively to every property of `T` β so each field of an options object
43 * (for example, an entry inside a `queryKey` array) can independently be a plain value or a `ref`, not just the
44 * object as a whole.
45 */
46export type MaybeRefDeep<T> = MaybeRef<
47 T extends Function
48 ? T
49 : T extends object
50 ? {
51 [Property in keyof T]: MaybeRefDeep<T[Property]>
52 }
53 : T
54>
55β
56/**
57 * Rejects `unknown`, collapsing it to `never` β used to keep generic inference from silently widening.
58 * @internal
59 */
60export type NoUnknown<T> = Equal<unknown, T> extends true ? never : T
61β
62/**
63 * Type-level equality check between `TTargetA` and `TTargetB`.
64 * @internal
65 */
66export type Equal<TTargetA, TTargetB> =
67 (<T>() => T extends TTargetA ? 1 : 2) extends <T>() => T extends TTargetB
68 ? 1
69 : 2
70 ? true
71 : false
72β
73/** The inverse of {@link MaybeRefDeep} β recursively unwraps any `Ref`s in `T` back to their plain value types. */
74export type DeepUnwrapRef<T> = T extends UnwrapLeaf
75 ? T
76 : T extends Ref<infer U>
77 ? DeepUnwrapRef<U>
78 : T extends {}
79 ? {
80 [Property in keyof T]: DeepUnwrapRef<T[Property]>
81 }
82 : UnwrapRef<T>
83β
84/**
85 * The `vue-query`-specific `shallow` option, accepted by query and mutation options.
86 */
87export type ShallowOption = {
88 /**
89 * Return data in a shallow ref object (it is `false` by default). It can be set to `true` to return data in a shallow ref object, which can improve performance if your data does not need to be deeply reactive.
90 */
91 shallow?: boolean
92}
93β
94/**
95 * The options of a mutation. Same as {@link MutationObserverOptions} from `@tanstack/query-core`, minus the
96 * internal `_defaulted` flag, plus the `shallow` option.
97 */
98export type MutationOptions<
99 TData = unknown,
100 TError = DefaultError,
101 TVariables = void,
102 TOnMutateResult = unknown,
103> = OmitKeyof<
104 MutationObserverOptions<TData, TError, TVariables, TOnMutateResult>,
105 '_defaulted'
106> &
107 ShallowOption
108β
109/**
110 * The default options of a `QueryClient`, applied to every query (`queries`), mutation
111 * (`mutations`), `hydrate`, and `dehydrate` call unless overridden. Query and mutation defaults also
112 * accept the `shallow` option.
113 */
114export interface DefaultOptions<TError = DefaultError> {
115 /**
116 * Default options applied to every query, unless overridden per-query. Also accepts the
117 * `shallow` option.
118 */
119 queries?: OmitKeyof<QueryObserverOptions<unknown, TError>, 'queryKey'> &
120 ShallowOption
121 /**
122 * Default options applied to every mutation, unless overridden per-mutation. Also accepts the
123 * `shallow` option.
124 */
125 mutations?: MutationObserverOptions<unknown, TError, unknown, unknown> &
126 ShallowOption
127 /**
128 * Default options used when hydrating queries and mutations; see {@link HydrateOptions}.
129 */
130 hydrate?: HydrateOptions['defaultOptions']
131 /**
132 * Default options used when dehydrating the client's caches; see {@link DehydrateOptions}.
133 */
134 dehydrate?: DehydrateOptions
135}
136β
137/**
138 * The options of `new QueryClient()`: the `queryCache` and `mutationCache` to use, and the
139 * `defaultOptions` for its queries and mutations.
140 */
141export interface QueryClientConfig {
142 /**
143 * The `QueryCache` to use. A new one is created if omitted.
144 */
145 queryCache?: QueryCache
146 /**
147 * The `MutationCache` to use. A new one is created if omitted.
148 */
149 mutationCache?: MutationCache
150 /**
151 * The default options of the queries and mutations of this `QueryClient`.
152 */
153 defaultOptions?: DefaultOptions
154}