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

types.ts

95 lines3.3 KB

1import type { QueryClient } from '@tanstack/query-core'
2import type {
3 DevtoolsButtonPosition,
4 DevtoolsErrorType,
5 DevtoolsPosition,
6 Theme,
7} from '@tanstack/query-devtools'
8import type { QueryFeature } from '@tanstack/angular-query'
9import type { Signal } from '@angular/core'
10​
11/** A static devtools option or an Angular signal containing that option. */
12type MaybeSignal<T> = T | Signal<T | undefined>
13​
14/**
15 * Options for configuring the TanStack Query devtools.
16 */
17export interface DevtoolsOptions {
18 /**
19 * Set this true if you want the devtools to default to being open
20 */
21 initialIsOpen?: MaybeSignal<boolean>
22 /**
23 * The position of the TanStack logo to open and close the devtools panel.
24 * `top-left` | `top-right` | `bottom-left` | `bottom-right` | `relative`
25 * Defaults to `bottom-right`.
26 */
27 buttonPosition?: MaybeSignal<DevtoolsButtonPosition>
28 /**
29 * The position of the TanStack Query devtools panel.
30 * `top` | `bottom` | `left` | `right`
31 * Defaults to `bottom`.
32 */
33 position?: MaybeSignal<DevtoolsPosition>
34 /**
35 * Custom instance of QueryClient
36 */
37 client?: MaybeSignal<QueryClient>
38 /**
39 * Use this so you can define custom errors that can be shown in the devtools.
40 */
41 errorTypes?: MaybeSignal<Array<DevtoolsErrorType>>
42 /**
43 * 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.
44 */
45 styleNonce?: string
46 /**
47 * Use this so you can attach the devtool's styles to a specific element in the DOM.
48 */
49 shadowDOMTarget?: ShadowRoot
50 /**
51 * Set this to true to hide disabled queries from the devtools panel.
52 */
53 hideDisabledQueries?: boolean
54 /**
55 * Set this to 'light', 'dark', or 'system' to change the theme of the devtools panel.
56 * Defaults to 'system'.
57 */
58 theme?: MaybeSignal<Theme>
59​
60 /**
61 * Whether the developer tools should be rendered.
62 * - `auto`- (Default) Renders devtools in development mode. Skips rendering in production mode.
63 * - `true`- Always render the devtools, regardless of the environment.
64 * - `false`- Never render the devtools, regardless of the environment.
65 *
66 * You can use `true` and `false` to override loading developer tools from an environment file.
67 * For example, a test environment might run in production mode but you may want to load developer tools.
68 *
69 * You can pass a signal to dynamically render the devtools based on a
70 * condition. For example, the signal could be created from an RxJS
71 * observable that listens for a keyboard shortcut.
72 *
73 * **Example**
74 * ```ts
75 * withDevtools(() => ({
76 * initialIsOpen: true,
77 * loadDevtools: inject(ExampleService).loadDevtools,
78 * }))
79 * ```
80 */
81 loadDevtools?: MaybeSignal<'auto' | boolean>
83​
84/**
85 * Returns devtools options. The function runs once in an Angular injection
86 * context, so it can call `inject()`. Pass signals as option values to make
87 * mutable options reactive. `styleNonce`, `shadowDOMTarget`, and
88 * `hideDisabledQueries` are read only when the devtools are constructed.
89 */
90export type WithDevtoolsFn = () => DevtoolsOptions
91​
92/**
93 * Creates a Query feature from an optional factory of developer-tools options.
94 */
95export type WithDevtools = (withDevtoolsFn?: WithDevtoolsFn) => QueryFeature