Skip to content
Source
Sign inSign up
TanStack/query
Open History to see the last commit

types.ts

107 lines3.3 KB

1import type { QueryClient } from '@tanstack/query-core'
2import type {
3 DevtoolsButtonPosition,
4 DevtoolsErrorType,
5 DevtoolsPosition,
6} from '@tanstack/query-devtools'
7import type { DevtoolsFeature } from '@tanstack/angular-query-experimental'
8​
9/**
10 * Options for configuring withDevtools.
11 */
12export interface WithDevtoolsOptions {
13 /**
14 * An array of dependencies to be injected and passed to the `withDevtoolsFn` function.
15 *
16 * **Example**
17 * ```ts
18 * export const appConfig: ApplicationConfig = {
19 * providers: [
20 * provideTanStackQuery(
21 * new QueryClient(),
22 * withDevtools(
23 * (devToolsOptionsManager: DevtoolsOptionsManager) => ({
24 * loadDevtools: devToolsOptionsManager.loadDevtools(),
25 * }),
26 * {
27 * deps: [DevtoolsOptionsManager],
28 * },
29 * ),
30 * ),
31 * ],
32 * }
33 * ```
34 */
35 deps?: Array<any>
37​
38/**
39 * Options for configuring the TanStack Query devtools.
40 */
41export interface DevtoolsOptions {
42 /**
43 * Set this true if you want the devtools to default to being open
44 */
45 initialIsOpen?: boolean
46 /**
47 * The position of the TanStack logo to open and close the devtools panel.
48 * `top-left` | `top-right` | `bottom-left` | `bottom-right` | `relative`
49 * Defaults to `bottom-right`.
50 */
51 buttonPosition?: DevtoolsButtonPosition
52 /**
53 * The position of the TanStack Query devtools panel.
54 * `top` | `bottom` | `left` | `right`
55 * Defaults to `bottom`.
56 */
57 position?: DevtoolsPosition
58 /**
59 * Custom instance of QueryClient
60 */
61 client?: QueryClient
62 /**
63 * Use this so you can define custom errors that can be shown in the devtools.
64 */
65 errorTypes?: Array<DevtoolsErrorType>
66 /**
67 * Use this to pass a nonce to the style tag that is added to the document head. This is useful if you are using a Content Security Policy (CSP) nonce to allow inline styles.
68 */
69 styleNonce?: string
70 /**
71 * Use this so you can attach the devtool's styles to a specific element in the DOM.
72 */
73 shadowDOMTarget?: ShadowRoot
74 /**
75 * Set this to true to hide disabled queries from the devtools panel.
76 */
77 hideDisabledQueries?: boolean
78​
79 /**
80 * Whether the developer tools should load.
81 * - `auto`- (Default) Lazily loads devtools when in development mode. Skips loading in production mode.
82 * - `true`- Always load the devtools, regardless of the environment.
83 * - `false`- Never load the devtools, regardless of the environment.
84 *
85 * You can use `true` and `false` to override loading developer tools from an environment file.
86 * For example, a test environment might run in production mode but you may want to load developer tools.
87 *
88 * Additionally, you can use a signal in the callback to dynamically load the devtools based on a condition. For example,
89 * a signal created from a RxJS observable that listens for a keyboard shortcut.
90 *
91 * **Example**
92 * ```ts
93 * withDevtools(() => ({
94 * initialIsOpen: true,
95 * loadDevtools: inject(ExampleService).loadDevtools()
96 * }))
97 * ```
98 */
99 loadDevtools?: 'auto' | boolean
101​
102export type WithDevtoolsFn = (...deps: Array<any>) => DevtoolsOptions
103​
104export type WithDevtools = (
105 withDevtoolsFn?: WithDevtoolsFn,
106 options?: WithDevtoolsOptions,
107) => DevtoolsFeature