@tanstack/angular-query-devtools 0.0.0 → 5.0.0-rc.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2021-present Tanner Linsley
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,45 +1,23 @@
1
1
  # @tanstack/angular-query-devtools
2
2
 
3
- ## ⚠️ IMPORTANT NOTICE ⚠️
3
+ Developer tools for `@tanstack/angular-query`.
4
4
 
5
- **This package is created solely for the purpose of setting up OIDC (OpenID Connect) trusted publishing with npm.**
5
+ ```sh
6
+ pnpm add -D @tanstack/angular-query-devtools
7
+ ```
6
8
 
7
- This is **NOT** a functional package and contains **NO** code or functionality beyond the OIDC setup configuration.
9
+ ```ts
10
+ import { QueryClient, provideTanStackQuery } from '@tanstack/angular-query'
11
+ import { withDevtools } from '@tanstack/angular-query-devtools'
8
12
 
9
- ## Purpose
13
+ export const appConfig: ApplicationConfig = {
14
+ providers: [provideTanStackQuery(() => new QueryClient(), withDevtools())],
15
+ }
16
+ ```
10
17
 
11
- This package exists to:
12
- 1. Configure OIDC trusted publishing for the package name `@tanstack/angular-query-devtools`
13
- 2. Enable secure, token-less publishing from CI/CD workflows
14
- 3. Establish provenance for packages published under this name
18
+ The default import resolves to a stub in production builds. To opt in to the
19
+ real implementation in production, import `withDevtools` from
20
+ `@tanstack/angular-query-devtools/production`.
15
21
 
16
- ## What is OIDC Trusted Publishing?
17
-
18
- OIDC trusted publishing allows package maintainers to publish packages directly from their CI/CD workflows without needing to manage npm access tokens. Instead, it uses OpenID Connect to establish trust between the CI/CD provider (like GitHub Actions) and npm.
19
-
20
- ## Setup Instructions
21
-
22
- To properly configure OIDC trusted publishing for this package:
23
-
24
- 1. Go to [npmjs.com](https://www.npmjs.com/) and navigate to your package settings
25
- 2. Configure the trusted publisher (e.g., GitHub Actions)
26
- 3. Specify the repository and workflow that should be allowed to publish
27
- 4. Use the configured workflow to publish your actual package
28
-
29
- ## DO NOT USE THIS PACKAGE
30
-
31
- This package is a placeholder for OIDC configuration only. It:
32
- - Contains no executable code
33
- - Provides no functionality
34
- - Should not be installed as a dependency
35
- - Exists only for administrative purposes
36
-
37
- ## More Information
38
-
39
- For more details about npm's trusted publishing feature, see:
40
- - [npm Trusted Publishing Documentation](https://docs.npmjs.com/generating-provenance-statements)
41
- - [GitHub Actions OIDC Documentation](https://docs.github.com/en/actions/deployment/security-hardening-your-deployments/about-security-hardening-with-openid-connect)
42
-
43
- ---
44
-
45
- **Maintained for OIDC setup purposes only**
22
+ The options callback runs inside an Angular injection context, so it can call
23
+ `inject()` and read signals directly.
@@ -0,0 +1,2 @@
1
+ export type { InjectDevtoolsPanel, DevtoolsPanelOptions, DevtoolsPanelRef, } from './types.js';
2
+ export { injectDevtoolsPanel } from './inject-devtools-panel.js';
@@ -0,0 +1,5 @@
1
+ import { injectDevtoolsPanel } from "./inject-devtools-panel.mjs";
2
+ export {
3
+ injectDevtoolsPanel
4
+ };
5
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":";"}
@@ -0,0 +1,13 @@
1
+ import { InjectDevtoolsPanel } from './types.js';
2
+ /**
3
+ * Inject a TanStack Query devtools panel and render it in the DOM.
4
+ *
5
+ * Devtools panel allows programmatic control over the devtools, for example if you want to render
6
+ * the devtools as part of your own devtools.
7
+ *
8
+ * Consider `withDevtools` instead if you don't need this.
9
+ * @param injectDevtoolsPanelFn - A function that returns devtools panel options.
10
+ * @returns DevtoolsPanelRef
11
+ * @see https://tanstack.com/query/v5/docs/framework/angular/devtools
12
+ */
13
+ export declare const injectDevtoolsPanel: InjectDevtoolsPanel;
@@ -0,0 +1,83 @@
1
+ import { assertInInjectionContext, inject, DestroyRef, PLATFORM_ID, computed, effect, untracked } from "@angular/core";
2
+ import { QueryClient, onlineManager } from "@tanstack/query-core";
3
+ import { isPlatformBrowser } from "@angular/common";
4
+ const injectDevtoolsPanel = (injectDevtoolsPanelFn) => {
5
+ assertInInjectionContext(injectDevtoolsPanel);
6
+ const destroyRef = inject(DestroyRef);
7
+ const isBrowser = isPlatformBrowser(inject(PLATFORM_ID));
8
+ const injectedClient = inject(QueryClient, { optional: true });
9
+ const queryOptions = computed(injectDevtoolsPanelFn);
10
+ let devtools = null;
11
+ let optionsEffect;
12
+ let manuallyDestroyed = false;
13
+ let loadGeneration = 0;
14
+ const unmount = () => {
15
+ devtools == null ? void 0 : devtools.unmount();
16
+ devtools = null;
17
+ };
18
+ const destroy = () => {
19
+ if (manuallyDestroyed) return;
20
+ manuallyDestroyed = true;
21
+ loadGeneration++;
22
+ optionsEffect == null ? void 0 : optionsEffect.destroy();
23
+ unmount();
24
+ };
25
+ if (!isBrowser)
26
+ return {
27
+ destroy
28
+ };
29
+ optionsEffect = effect(() => {
30
+ const generation = ++loadGeneration;
31
+ const {
32
+ client = injectedClient,
33
+ errorTypes = [],
34
+ theme = "system",
35
+ styleNonce,
36
+ shadowDOMTarget,
37
+ onClose,
38
+ hostElement
39
+ } = queryOptions();
40
+ untracked(() => {
41
+ if (!client) throw new Error("No QueryClient found");
42
+ if (!devtools && hostElement) {
43
+ import("@tanstack/query-devtools").then((queryDevtools) => {
44
+ if (manuallyDestroyed || destroyRef.destroyed || generation !== loadGeneration) {
45
+ return;
46
+ }
47
+ devtools = new queryDevtools.TanstackQueryDevtoolsPanel({
48
+ client,
49
+ queryFlavor: "Angular Query",
50
+ version: "5",
51
+ buttonPosition: "bottom-left",
52
+ position: "bottom",
53
+ initialIsOpen: true,
54
+ errorTypes,
55
+ theme,
56
+ styleNonce,
57
+ shadowDOMTarget,
58
+ onClose,
59
+ onlineManager
60
+ });
61
+ devtools.mount(hostElement.nativeElement);
62
+ }).catch((error) => {
63
+ console.error("Failed to load @tanstack/query-devtools.", error);
64
+ });
65
+ } else if (devtools && hostElement) {
66
+ devtools.setClient(client);
67
+ devtools.setErrorTypes(errorTypes);
68
+ devtools.setTheme(theme);
69
+ onClose && devtools.setOnClose(onClose);
70
+ } else if (devtools && !hostElement) {
71
+ unmount();
72
+ }
73
+ });
74
+ });
75
+ destroyRef.onDestroy(destroy);
76
+ return {
77
+ destroy
78
+ };
79
+ };
80
+ export {
81
+ injectDevtoolsPanel
82
+ };
83
+ //# sourceMappingURL=inject-devtools-panel.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"inject-devtools-panel.mjs","sources":["../../src/devtools-panel/inject-devtools-panel.ts"],"sourcesContent":["import {\n DestroyRef,\n PLATFORM_ID,\n assertInInjectionContext,\n computed,\n effect,\n inject,\n untracked,\n} from '@angular/core'\nimport { QueryClient, onlineManager } from '@tanstack/query-core'\nimport { isPlatformBrowser } from '@angular/common'\nimport type { TanstackQueryDevtoolsPanel } from '@tanstack/query-devtools'\nimport type { DevtoolsPanelOptions, InjectDevtoolsPanel } from './types'\n\n/**\n * Inject a TanStack Query devtools panel and render it in the DOM.\n *\n * Devtools panel allows programmatic control over the devtools, for example if you want to render\n * the devtools as part of your own devtools.\n *\n * Consider `withDevtools` instead if you don't need this.\n * @param injectDevtoolsPanelFn - A function that returns devtools panel options.\n * @returns DevtoolsPanelRef\n * @see https://tanstack.com/query/v5/docs/framework/angular/devtools\n */\nexport const injectDevtoolsPanel: InjectDevtoolsPanel = (\n injectDevtoolsPanelFn: () => DevtoolsPanelOptions,\n) => {\n assertInInjectionContext(injectDevtoolsPanel)\n const destroyRef = inject(DestroyRef)\n const isBrowser = isPlatformBrowser(inject(PLATFORM_ID))\n const injectedClient = inject(QueryClient, { optional: true })\n\n const queryOptions = computed(injectDevtoolsPanelFn)\n let devtools: TanstackQueryDevtoolsPanel | null = null\n let optionsEffect: ReturnType<typeof effect> | undefined\n let manuallyDestroyed = false\n let loadGeneration = 0\n\n const unmount = () => {\n devtools?.unmount()\n devtools = null\n }\n\n const destroy = () => {\n if (manuallyDestroyed) return\n\n manuallyDestroyed = true\n loadGeneration++\n optionsEffect?.destroy()\n unmount()\n }\n\n if (!isBrowser)\n return {\n destroy,\n }\n\n optionsEffect = effect(() => {\n const generation = ++loadGeneration\n const {\n client = injectedClient,\n errorTypes = [],\n theme = 'system',\n styleNonce,\n shadowDOMTarget,\n onClose,\n hostElement,\n } = queryOptions()\n\n untracked(() => {\n if (!client) throw new Error('No QueryClient found')\n if (!devtools && hostElement) {\n import('@tanstack/query-devtools')\n .then((queryDevtools) => {\n if (\n manuallyDestroyed ||\n destroyRef.destroyed ||\n generation !== loadGeneration\n ) {\n return\n }\n\n devtools = new queryDevtools.TanstackQueryDevtoolsPanel({\n client,\n queryFlavor: 'Angular Query',\n version: '5',\n buttonPosition: 'bottom-left',\n position: 'bottom',\n initialIsOpen: true,\n errorTypes,\n theme,\n styleNonce,\n shadowDOMTarget,\n onClose,\n onlineManager,\n })\n devtools.mount(hostElement.nativeElement)\n })\n .catch((error) => {\n console.error('Failed to load @tanstack/query-devtools.', error)\n })\n } else if (devtools && hostElement) {\n devtools.setClient(client)\n devtools.setErrorTypes(errorTypes)\n devtools.setTheme(theme)\n onClose && devtools.setOnClose(onClose)\n } else if (devtools && !hostElement) {\n unmount()\n }\n })\n })\n\n destroyRef.onDestroy(destroy)\n\n return {\n destroy,\n }\n}\n"],"names":[],"mappings":";;;AAyBO,MAAM,sBAA2C,CACtD,0BACG;AACH,2BAAyB,mBAAmB;AAC5C,QAAM,aAAa,OAAO,UAAU;AACpC,QAAM,YAAY,kBAAkB,OAAO,WAAW,CAAC;AACvD,QAAM,iBAAiB,OAAO,aAAa,EAAE,UAAU,MAAM;AAE7D,QAAM,eAAe,SAAS,qBAAqB;AACnD,MAAI,WAA8C;AAClD,MAAI;AACJ,MAAI,oBAAoB;AACxB,MAAI,iBAAiB;AAErB,QAAM,UAAU,MAAM;AACpB,yCAAU;AACV,eAAW;AAAA,EACb;AAEA,QAAM,UAAU,MAAM;AACpB,QAAI,kBAAmB;AAEvB,wBAAoB;AACpB;AACA,mDAAe;AACf,YAAA;AAAA,EACF;AAEA,MAAI,CAAC;AACH,WAAO;AAAA,MACL;AAAA,IAAA;AAGJ,kBAAgB,OAAO,MAAM;AAC3B,UAAM,aAAa,EAAE;AACrB,UAAM;AAAA,MACJ,SAAS;AAAA,MACT,aAAa,CAAA;AAAA,MACb,QAAQ;AAAA,MACR;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,IAAA,IACE,aAAA;AAEJ,cAAU,MAAM;AACd,UAAI,CAAC,OAAQ,OAAM,IAAI,MAAM,sBAAsB;AACnD,UAAI,CAAC,YAAY,aAAa;AAC5B,eAAO,0BAA0B,EAC9B,KAAK,CAAC,kBAAkB;AACvB,cACE,qBACA,WAAW,aACX,eAAe,gBACf;AACA;AAAA,UACF;AAEA,qBAAW,IAAI,cAAc,2BAA2B;AAAA,YACtD;AAAA,YACA,aAAa;AAAA,YACb,SAAS;AAAA,YACT,gBAAgB;AAAA,YAChB,UAAU;AAAA,YACV,eAAe;AAAA,YACf;AAAA,YACA;AAAA,YACA;AAAA,YACA;AAAA,YACA;AAAA,YACA;AAAA,UAAA,CACD;AACD,mBAAS,MAAM,YAAY,aAAa;AAAA,QAC1C,CAAC,EACA,MAAM,CAAC,UAAU;AAChB,kBAAQ,MAAM,4CAA4C,KAAK;AAAA,QACjE,CAAC;AAAA,MACL,WAAW,YAAY,aAAa;AAClC,iBAAS,UAAU,MAAM;AACzB,iBAAS,cAAc,UAAU;AACjC,iBAAS,SAAS,KAAK;AACvB,mBAAW,SAAS,WAAW,OAAO;AAAA,MACxC,WAAW,YAAY,CAAC,aAAa;AACnC,gBAAA;AAAA,MACF;AAAA,IACF,CAAC;AAAA,EACH,CAAC;AAED,aAAW,UAAU,OAAO;AAE5B,SAAO;AAAA,IACL;AAAA,EAAA;AAEJ;"}
@@ -0,0 +1,2 @@
1
+ export type { DevtoolsPanelOptions, DevtoolsPanelRef, InjectDevtoolsPanel, } from '../types.js';
2
+ export { injectDevtoolsPanel } from '../inject-devtools-panel.js';
@@ -0,0 +1,5 @@
1
+ import { injectDevtoolsPanel } from "../inject-devtools-panel.mjs";
2
+ export {
3
+ injectDevtoolsPanel
4
+ };
5
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":";"}
@@ -0,0 +1,3 @@
1
+ import { DevtoolsPanelOptions, DevtoolsPanelRef, InjectDevtoolsPanel } from './types.js';
2
+ export declare const injectDevtoolsPanel: InjectDevtoolsPanel;
3
+ export type { InjectDevtoolsPanel, DevtoolsPanelOptions, DevtoolsPanelRef };
@@ -0,0 +1,8 @@
1
+ import { noop } from "@tanstack/query-core";
2
+ const injectDevtoolsPanel = () => ({
3
+ destroy: noop
4
+ });
5
+ export {
6
+ injectDevtoolsPanel
7
+ };
8
+ //# sourceMappingURL=stub.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"stub.mjs","sources":["../../src/devtools-panel/stub.ts"],"sourcesContent":["import { noop } from '@tanstack/query-core'\nimport type {\n DevtoolsPanelOptions,\n DevtoolsPanelRef,\n InjectDevtoolsPanel,\n} from './types'\n\n// Stub which replaces `injectDevtoolsPanel` in production builds\nexport const injectDevtoolsPanel: InjectDevtoolsPanel = () => ({\n destroy: noop,\n})\n\nexport type { InjectDevtoolsPanel, DevtoolsPanelOptions, DevtoolsPanelRef }\n"],"names":[],"mappings":";AAQO,MAAM,sBAA2C,OAAO;AAAA,EAC7D,SAAS;AACX;"}
@@ -0,0 +1,45 @@
1
+ import { DevtoolsErrorType, Theme } from '@tanstack/query-devtools';
2
+ import { ElementRef } from '@angular/core';
3
+ import { QueryClient } from '@tanstack/query-core';
4
+ /**
5
+ * A devtools panel, which can be manually destroyed.
6
+ */
7
+ export interface DevtoolsPanelRef {
8
+ /**
9
+ * Destroy the panel, removing it from the DOM and stops listening to signal changes.
10
+ */
11
+ destroy: () => void;
12
+ }
13
+ export interface DevtoolsPanelOptions {
14
+ /**
15
+ * Custom instance of QueryClient
16
+ */
17
+ client?: QueryClient;
18
+ /**
19
+ * Use this so you can define custom errors that can be shown in the devtools.
20
+ */
21
+ errorTypes?: Array<DevtoolsErrorType>;
22
+ /**
23
+ * The theme of the devtools panel.
24
+ * @default 'system'
25
+ */
26
+ theme?: Theme;
27
+ /**
28
+ * 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.
29
+ */
30
+ styleNonce?: string;
31
+ /**
32
+ * Use this so you can attach the devtool's styles to specific element in the DOM.
33
+ */
34
+ shadowDOMTarget?: ShadowRoot;
35
+ /**
36
+ * Callback function that is called when the devtools panel is closed
37
+ */
38
+ onClose?: () => unknown;
39
+ /**
40
+ * Element where to render the devtools panel. When set to undefined or null, the devtools panel will not be created, or destroyed if existing.
41
+ * If changed from undefined to a ElementRef, the devtools panel will be created.
42
+ */
43
+ hostElement?: ElementRef | null;
44
+ }
45
+ export type InjectDevtoolsPanel = (injectDevtoolsPanelFn: () => DevtoolsPanelOptions) => DevtoolsPanelRef;
package/index.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ export type { DevtoolsOptions, WithDevtools, WithDevtoolsFn } from './types.js';
2
+ export { withDevtools } from './with-devtools.js';
package/index.mjs ADDED
@@ -0,0 +1,5 @@
1
+ import { withDevtools } from "./with-devtools.mjs";
2
+ export {
3
+ withDevtools
4
+ };
5
+ //# sourceMappingURL=index.mjs.map
package/index.mjs.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":";"}
package/package.json CHANGED
@@ -1,6 +1,65 @@
1
1
  {
2
2
  "name": "@tanstack/angular-query-devtools",
3
- "version": "0.0.0",
4
- "description": "OIDC trusted publishing setup package for @tanstack/angular-query-devtools",
5
- "keywords": ["oidc", "trusted-publishing", "setup"]
6
- }
3
+ "version": "5.0.0-rc.1",
4
+ "description": "Developer tools to interact with and visualize the TanStack Angular Query cache",
5
+ "author": "Arnoud de Vries",
6
+ "license": "MIT",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "git+https://github.com/TanStack/query.git",
10
+ "directory": "packages/angular-query-devtools"
11
+ },
12
+ "homepage": "https://tanstack.com/query",
13
+ "funding": {
14
+ "type": "github",
15
+ "url": "https://github.com/sponsors/tannerlinsley"
16
+ },
17
+ "keywords": [
18
+ "angular",
19
+ "angular query",
20
+ "devtools",
21
+ "tanstack"
22
+ ],
23
+ "type": "module",
24
+ "types": "./index.d.ts",
25
+ "module": "./index.mjs",
26
+ "exports": {
27
+ ".": {
28
+ "types": "./index.d.ts",
29
+ "development": "./index.mjs",
30
+ "default": "./stub.mjs"
31
+ },
32
+ "./package.json": "./package.json",
33
+ "./stub": {
34
+ "types": "./stub.d.ts",
35
+ "default": "./stub.mjs"
36
+ },
37
+ "./production": {
38
+ "types": "./production/index.d.ts",
39
+ "default": "./index.mjs"
40
+ },
41
+ "./devtools-panel": {
42
+ "types": "./devtools-panel/index.d.ts",
43
+ "development": "./devtools-panel/index.mjs",
44
+ "default": "./devtools-panel/stub.mjs"
45
+ },
46
+ "./devtools-panel/production": {
47
+ "types": "./devtools-panel/production/index.d.ts",
48
+ "default": "./devtools-panel/index.mjs"
49
+ },
50
+ "./devtools-panel/stub": {
51
+ "types": "./devtools-panel/stub.d.ts",
52
+ "default": "./devtools-panel/stub.mjs"
53
+ }
54
+ },
55
+ "sideEffects": false,
56
+ "dependencies": {
57
+ "@tanstack/query-core": "5.103.2",
58
+ "@tanstack/query-devtools": "5.103.2"
59
+ },
60
+ "peerDependencies": {
61
+ "@angular/common": ">=20.1.0",
62
+ "@angular/core": ">=20.1.0",
63
+ "@tanstack/angular-query": "^5.0.0-rc.1"
64
+ }
65
+ }
@@ -0,0 +1,2 @@
1
+ export type { DevtoolsOptions, WithDevtools, WithDevtoolsFn } from '../types.js';
2
+ export { withDevtools } from '../with-devtools.js';
@@ -0,0 +1,5 @@
1
+ import { withDevtools } from "../with-devtools.mjs";
2
+ export {
3
+ withDevtools
4
+ };
5
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":";"}
package/stub.d.ts ADDED
@@ -0,0 +1,3 @@
1
+ import { DevtoolsOptions, WithDevtools, WithDevtoolsFn } from './types.js';
2
+ export declare const withDevtools: WithDevtools;
3
+ export type { DevtoolsOptions, WithDevtools, WithDevtoolsFn };
package/stub.mjs ADDED
@@ -0,0 +1,7 @@
1
+ import { makeEnvironmentProviders } from "@angular/core";
2
+ import { queryFeature } from "@tanstack/angular-query/internal";
3
+ const withDevtools = () => queryFeature(makeEnvironmentProviders([]));
4
+ export {
5
+ withDevtools
6
+ };
7
+ //# sourceMappingURL=stub.mjs.map
package/stub.mjs.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"file":"stub.mjs","sources":["../src/stub.ts"],"sourcesContent":["import { makeEnvironmentProviders } from '@angular/core'\nimport { queryFeature } from '@tanstack/angular-query/internal'\nimport type { DevtoolsOptions, WithDevtools, WithDevtoolsFn } from './types'\n\n// Stub which replaces `withDevtools` in production builds\nexport const withDevtools: WithDevtools = () =>\n queryFeature(makeEnvironmentProviders([]))\n\nexport type { DevtoolsOptions, WithDevtools, WithDevtoolsFn }\n"],"names":[],"mappings":";;AAKO,MAAM,eAA6B,MACxC,aAAa,yBAAyB,EAAE,CAAC;"}
package/types.d.ts ADDED
@@ -0,0 +1,83 @@
1
+ import { QueryClient } from '@tanstack/query-core';
2
+ import { DevtoolsButtonPosition, DevtoolsErrorType, DevtoolsPosition, Theme } from '@tanstack/query-devtools';
3
+ import { QueryFeature } from '@tanstack/angular-query';
4
+ import { Signal } from '@angular/core';
5
+ /** A static devtools option or an Angular signal containing that option. */
6
+ type MaybeSignal<T> = T | Signal<T | undefined>;
7
+ /**
8
+ * Options for configuring the TanStack Query devtools.
9
+ */
10
+ export interface DevtoolsOptions {
11
+ /**
12
+ * Set this true if you want the devtools to default to being open
13
+ */
14
+ initialIsOpen?: MaybeSignal<boolean>;
15
+ /**
16
+ * The position of the TanStack logo to open and close the devtools panel.
17
+ * `top-left` | `top-right` | `bottom-left` | `bottom-right` | `relative`
18
+ * Defaults to `bottom-right`.
19
+ */
20
+ buttonPosition?: MaybeSignal<DevtoolsButtonPosition>;
21
+ /**
22
+ * The position of the TanStack Query devtools panel.
23
+ * `top` | `bottom` | `left` | `right`
24
+ * Defaults to `bottom`.
25
+ */
26
+ position?: MaybeSignal<DevtoolsPosition>;
27
+ /**
28
+ * Custom instance of QueryClient
29
+ */
30
+ client?: MaybeSignal<QueryClient>;
31
+ /**
32
+ * Use this so you can define custom errors that can be shown in the devtools.
33
+ */
34
+ errorTypes?: MaybeSignal<Array<DevtoolsErrorType>>;
35
+ /**
36
+ * 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.
37
+ */
38
+ styleNonce?: string;
39
+ /**
40
+ * Use this so you can attach the devtool's styles to a specific element in the DOM.
41
+ */
42
+ shadowDOMTarget?: ShadowRoot;
43
+ /**
44
+ * Set this to true to hide disabled queries from the devtools panel.
45
+ */
46
+ hideDisabledQueries?: boolean;
47
+ /**
48
+ * Set this to 'light', 'dark', or 'system' to change the theme of the devtools panel.
49
+ * Defaults to 'system'.
50
+ */
51
+ theme?: MaybeSignal<Theme>;
52
+ /**
53
+ * Whether the developer tools should be rendered.
54
+ * - `auto`- (Default) Renders devtools in development mode. Skips rendering in production mode.
55
+ * - `true`- Always render the devtools, regardless of the environment.
56
+ * - `false`- Never render the devtools, regardless of the environment.
57
+ *
58
+ * You can use `true` and `false` to override loading developer tools from an environment file.
59
+ * For example, a test environment might run in production mode but you may want to load developer tools.
60
+ *
61
+ * You can pass a signal to dynamically render the devtools based on a
62
+ * condition. For example, the signal could be created from an RxJS
63
+ * observable that listens for a keyboard shortcut.
64
+ *
65
+ * **Example**
66
+ * ```ts
67
+ * withDevtools(() => ({
68
+ * initialIsOpen: true,
69
+ * loadDevtools: inject(ExampleService).loadDevtools,
70
+ * }))
71
+ * ```
72
+ */
73
+ loadDevtools?: MaybeSignal<'auto' | boolean>;
74
+ }
75
+ /**
76
+ * Returns devtools options. The function runs once in an Angular injection
77
+ * context, so it can call `inject()`. Pass signals as option values to make
78
+ * mutable options reactive. `styleNonce`, `shadowDOMTarget`, and
79
+ * `hideDisabledQueries` are read only when the devtools are constructed.
80
+ */
81
+ export type WithDevtoolsFn = () => DevtoolsOptions;
82
+ export type WithDevtools = (withDevtoolsFn?: WithDevtoolsFn) => QueryFeature;
83
+ export {};
@@ -0,0 +1,26 @@
1
+ import { WithDevtools } from './types.js';
2
+ /**
3
+ * Enables developer tools in Angular development builds.
4
+ *
5
+ * **Example**
6
+ *
7
+ * ```ts
8
+ * export const appConfig: ApplicationConfig = {
9
+ * providers: [
10
+ * provideTanStackQuery(() => new QueryClient(), withDevtools()),
11
+ * ]
12
+ * }
13
+ * ```
14
+ * The devtools will be rendered in `<body>`.
15
+ *
16
+ * If you need more control over when devtools are loaded, you can use the `loadDevtools` option.
17
+ *
18
+ * If you need more control over where devtools are rendered, consider `injectDevtoolsPanel`. This allows rendering devtools inside your own devtools for example.
19
+ * @param withDevtoolsFn - A function that returns `DevtoolsOptions`. It runs
20
+ * once in an Angular injection context and can call `inject()`. Return signals
21
+ * as individual mutable option values to update them reactively.
22
+ * @returns A set of providers for use with `provideTanStackQuery`.
23
+ * @see {@link provideTanStackQuery}
24
+ * @see {@link DevtoolsOptions}
25
+ */
26
+ export declare const withDevtools: WithDevtools;
@@ -0,0 +1,109 @@
1
+ import { isPlatformBrowser } from "@angular/common";
2
+ import { InjectionToken, makeEnvironmentProviders, provideEnvironmentInitializer, inject, PLATFORM_ID, DestroyRef, afterNextRender, afterRenderEffect, isDevMode, isSignal } from "@angular/core";
3
+ import { queryFeature } from "@tanstack/angular-query/internal";
4
+ import { QueryClient, onlineManager } from "@tanstack/query-core";
5
+ import { TanstackQueryDevtools } from "@tanstack/query-devtools";
6
+ const DEVTOOLS_PROVIDED = new InjectionToken("", {
7
+ factory: () => ({
8
+ isProvided: false
9
+ })
10
+ });
11
+ const DEVTOOLS_OPTIONS = new InjectionToken("");
12
+ function resolveOption(option) {
13
+ return isSignal(option) ? option() : option;
14
+ }
15
+ const withDevtools = (withDevtoolsFn) => queryFeature(
16
+ makeEnvironmentProviders([
17
+ {
18
+ provide: DEVTOOLS_OPTIONS,
19
+ useFactory: () => (withDevtoolsFn == null ? void 0 : withDevtoolsFn()) ?? {}
20
+ },
21
+ provideEnvironmentInitializer(() => {
22
+ const devtoolsProvided = inject(DEVTOOLS_PROVIDED);
23
+ if (!isPlatformBrowser(inject(PLATFORM_ID)) || devtoolsProvided.isProvided)
24
+ return;
25
+ devtoolsProvided.isProvided = true;
26
+ const destroyRef = inject(DestroyRef);
27
+ const injectedClient = inject(QueryClient, { optional: true });
28
+ const options = inject(DEVTOOLS_OPTIONS);
29
+ const client = resolveOption(options.client) ?? injectedClient;
30
+ if (!client) throw new Error("No QueryClient found");
31
+ const devtools = new TanstackQueryDevtools({
32
+ client,
33
+ queryFlavor: "Angular Query",
34
+ version: "5",
35
+ onlineManager,
36
+ buttonPosition: resolveOption(options.buttonPosition),
37
+ position: resolveOption(options.position),
38
+ initialIsOpen: resolveOption(options.initialIsOpen),
39
+ errorTypes: resolveOption(options.errorTypes),
40
+ styleNonce: options.styleNonce,
41
+ shadowDOMTarget: options.shadowDOMTarget,
42
+ hideDisabledQueries: options.hideDisabledQueries,
43
+ theme: resolveOption(options.theme)
44
+ });
45
+ let renderCompleted = false;
46
+ let element = null;
47
+ const shouldMount = () => {
48
+ const loadDevtools = resolveOption(options.loadDevtools);
49
+ return typeof loadDevtools === "boolean" ? loadDevtools : isDevMode();
50
+ };
51
+ const mount = () => {
52
+ if (element || !renderCompleted || !shouldMount()) return;
53
+ element = document.body.appendChild(document.createElement("div"));
54
+ element.classList.add("tsqd-parent-container");
55
+ devtools.mount(element);
56
+ };
57
+ const unmount = () => {
58
+ if (!element) return;
59
+ devtools.unmount();
60
+ element.remove();
61
+ element = null;
62
+ };
63
+ afterNextRender({
64
+ write: () => {
65
+ if (destroyRef.destroyed) return;
66
+ renderCompleted = true;
67
+ mount();
68
+ destroyRef.onDestroy(unmount);
69
+ }
70
+ });
71
+ afterRenderEffect({
72
+ write: () => {
73
+ if (!renderCompleted) return;
74
+ shouldMount() ? mount() : unmount();
75
+ }
76
+ });
77
+ const registerOptionEffect = (option, update) => {
78
+ if (!isSignal(option)) return;
79
+ afterRenderEffect({
80
+ write: () => {
81
+ update(option());
82
+ }
83
+ });
84
+ };
85
+ registerOptionEffect(options.client, (value) => {
86
+ devtools.setClient(value ?? injectedClient);
87
+ });
88
+ registerOptionEffect(options.buttonPosition, (value) => {
89
+ devtools.setButtonPosition(value ?? "bottom-right");
90
+ });
91
+ registerOptionEffect(options.position, (value) => {
92
+ devtools.setPosition(value ?? "bottom");
93
+ });
94
+ registerOptionEffect(options.initialIsOpen, (value) => {
95
+ devtools.setInitialIsOpen(value ?? false);
96
+ });
97
+ registerOptionEffect(options.errorTypes, (value) => {
98
+ devtools.setErrorTypes(value ?? []);
99
+ });
100
+ registerOptionEffect(options.theme, (value) => {
101
+ devtools.setTheme(value);
102
+ });
103
+ })
104
+ ])
105
+ );
106
+ export {
107
+ withDevtools
108
+ };
109
+ //# sourceMappingURL=with-devtools.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"with-devtools.mjs","sources":["../src/with-devtools.ts"],"sourcesContent":["import { isPlatformBrowser } from '@angular/common'\nimport {\n DestroyRef,\n InjectionToken,\n PLATFORM_ID,\n afterNextRender,\n afterRenderEffect,\n inject,\n isDevMode,\n isSignal,\n makeEnvironmentProviders,\n provideEnvironmentInitializer,\n} from '@angular/core'\nimport { queryFeature } from '@tanstack/angular-query/internal'\nimport { QueryClient, onlineManager } from '@tanstack/query-core'\nimport { TanstackQueryDevtools } from '@tanstack/query-devtools'\nimport type { Signal } from '@angular/core'\nimport type { DevtoolsOptions, WithDevtools } from './types'\n\n/**\n * Internal token used to prevent double providing of devtools in child injectors\n */\nconst DEVTOOLS_PROVIDED = new InjectionToken('', {\n factory: () => ({\n isProvided: false,\n }),\n})\n\n/** Internal token for providing devtools options. */\nconst DEVTOOLS_OPTIONS = new InjectionToken<DevtoolsOptions>('')\n\nfunction resolveOption<T>(option: T | Signal<T | undefined> | undefined) {\n return isSignal(option) ? option() : option\n}\n\n/**\n * Enables developer tools in Angular development builds.\n *\n * **Example**\n *\n * ```ts\n * export const appConfig: ApplicationConfig = {\n * providers: [\n * provideTanStackQuery(() => new QueryClient(), withDevtools()),\n * ]\n * }\n * ```\n * The devtools will be rendered in `<body>`.\n *\n * If you need more control over when devtools are loaded, you can use the `loadDevtools` option.\n *\n * If you need more control over where devtools are rendered, consider `injectDevtoolsPanel`. This allows rendering devtools inside your own devtools for example.\n * @param withDevtoolsFn - A function that returns `DevtoolsOptions`. It runs\n * once in an Angular injection context and can call `inject()`. Return signals\n * as individual mutable option values to update them reactively.\n * @returns A set of providers for use with `provideTanStackQuery`.\n * @see {@link provideTanStackQuery}\n * @see {@link DevtoolsOptions}\n */\nexport const withDevtools: WithDevtools = (withDevtoolsFn) =>\n queryFeature(\n makeEnvironmentProviders([\n {\n provide: DEVTOOLS_OPTIONS,\n useFactory: () => withDevtoolsFn?.() ?? {},\n },\n provideEnvironmentInitializer(() => {\n const devtoolsProvided = inject(DEVTOOLS_PROVIDED)\n if (\n !isPlatformBrowser(inject(PLATFORM_ID)) ||\n devtoolsProvided.isProvided\n )\n return\n\n devtoolsProvided.isProvided = true\n\n const destroyRef = inject(DestroyRef)\n const injectedClient = inject(QueryClient, { optional: true })\n const options = inject(DEVTOOLS_OPTIONS)\n const client = resolveOption(options.client) ?? injectedClient\n\n if (!client) throw new Error('No QueryClient found')\n\n const devtools = new TanstackQueryDevtools({\n client,\n queryFlavor: 'Angular Query',\n version: '5',\n onlineManager,\n buttonPosition: resolveOption(options.buttonPosition),\n position: resolveOption(options.position),\n initialIsOpen: resolveOption(options.initialIsOpen),\n errorTypes: resolveOption(options.errorTypes),\n styleNonce: options.styleNonce,\n shadowDOMTarget: options.shadowDOMTarget,\n hideDisabledQueries: options.hideDisabledQueries,\n theme: resolveOption(options.theme),\n })\n\n let renderCompleted = false\n let element: HTMLElement | null = null\n\n const shouldMount = () => {\n const loadDevtools = resolveOption(options.loadDevtools)\n return typeof loadDevtools === 'boolean' ? loadDevtools : isDevMode()\n }\n\n const mount = () => {\n if (element || !renderCompleted || !shouldMount()) return\n\n element = document.body.appendChild(document.createElement('div'))\n element.classList.add('tsqd-parent-container')\n devtools.mount(element)\n }\n\n const unmount = () => {\n if (!element) return\n\n devtools.unmount()\n element.remove()\n element = null\n }\n\n afterNextRender({\n write: () => {\n if (destroyRef.destroyed) return\n\n renderCompleted = true\n mount()\n destroyRef.onDestroy(unmount)\n },\n })\n\n afterRenderEffect({\n write: () => {\n if (!renderCompleted) return\n shouldMount() ? mount() : unmount()\n },\n })\n\n const registerOptionEffect = <T>(\n option: T | Signal<T | undefined> | undefined,\n update: (value: T | undefined) => void,\n ) => {\n if (!isSignal(option)) return\n afterRenderEffect({\n write: () => {\n update(option())\n },\n })\n }\n\n registerOptionEffect(options.client, (value) => {\n devtools.setClient(value ?? injectedClient!)\n })\n registerOptionEffect(options.buttonPosition, (value) => {\n devtools.setButtonPosition(value ?? 'bottom-right')\n })\n registerOptionEffect(options.position, (value) => {\n devtools.setPosition(value ?? 'bottom')\n })\n registerOptionEffect(options.initialIsOpen, (value) => {\n devtools.setInitialIsOpen(value ?? false)\n })\n registerOptionEffect(options.errorTypes, (value) => {\n devtools.setErrorTypes(value ?? [])\n })\n registerOptionEffect(options.theme, (value) => {\n devtools.setTheme(value)\n })\n }),\n ]),\n )\n"],"names":[],"mappings":"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"}