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

types.ts

105 lines3.7 KB

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