diff --git a/codecov.yml b/codecov.yml index ef21589e00..da56c6458c 100644 --- a/codecov.yml +++ b/codecov.yml @@ -19,10 +19,6 @@ comment: component_management: individual_components: - - component_id: angular-query-devtools-experimental - name: '@tanstack/angular-query-devtools-experimental' - paths: - - packages/angular-query-devtools-experimental/** - component_id: angular-query-experimental name: '@tanstack/angular-query-experimental' paths: diff --git a/docs/framework/angular/devtools.md b/docs/framework/angular/devtools.md index 7b3ad785b6..c0cfb9141c 100644 --- a/docs/framework/angular/devtools.md +++ b/docs/framework/angular/devtools.md @@ -13,27 +13,38 @@ title: Devtools The devtools help you debug and inspect your queries and mutations. You can enable the devtools by adding `withDevtools` to `provideTanStackQuery`. -By default, the devtools are enabled when Angular [`isDevMode`](https://angular.dev/api/core/isDevMode) returns true. So you don't need to worry about excluding them during a production build. The core tools are lazily loaded and excluded from bundled code. In most cases, all you'll need to do is add `withDevtools()` to `provideTanStackQuery` without any additional configuration. +By default, Angular Query Devtools are only included in development mode bundles, so you don't need to worry about excluding them during a production build. ```ts import { QueryClient, provideTanStackQuery, - withDevtools, } from '@tanstack/angular-query-experimental' +import { withDevtools } from '@tanstack/angular-query-experimental/devtools' + export const appConfig: ApplicationConfig = { providers: [provideTanStackQuery(new QueryClient(), withDevtools())], } ``` -## Configuring if devtools are loaded +## Devtools in production -If you need more control over when devtools are loaded, you can use the `loadDevtools` option. This is particularly useful if you want to load devtools based on environment configurations. For instance, you might have a test environment running in production mode but still require devtools to be available. +Devtools are automatically excluded from production builds. However, it might be desirable to lazy load the devtools in production. -When not setting the option or setting it to 'auto', the devtools will be loaded when Angular is in development mode. +To use `withDevtools` in production builds, import using the `production` sub-path. The function exported from the production subpath is identical to the main one, but won't be excluded from production builds. ```ts +import { withDevtools } from '@tanstack/angular-query-experimental/devtools/production' +``` + +To control when devtools are loaded, you can use the `loadDevtools` option. + +When not setting the option or setting it to 'auto', the devtools will be loaded automatically only when Angular runs in development mode. + +```ts +import { withDevtools } from '@tanstack/angular-query-experimental/devtools' + provideTanStackQuery(new QueryClient(), withDevtools()) // which is equivalent to @@ -45,10 +56,16 @@ provideTanStackQuery( When setting the option to true, the devtools will be loaded in both development and production mode. +This is useful if you want to load devtools based on [Angular environment configurations](https://angular.dev/tools/cli/environments). E.g. you could set this to true when the application is running on your production build staging environment. + ```ts +import { environment } from './environments/environment' +// Make sure to use the production sub-path to load devtools in production builds +import { withDevtools } from '@tanstack/angular-query-experimental/devtools/production' + provideTanStackQuery( new QueryClient(), - withDevtools(() => ({ loadDevtools: true })), + withDevtools(() => ({ loadDevtools: environment.loadDevtools })), ) ``` @@ -61,44 +78,66 @@ provideTanStackQuery( ) ``` -The `withDevtools` options are returned from a callback function to support reactivity through signals. In the following example -a signal is created from a RxJS observable that listens for a keyboard shortcut. When the event is triggered, the devtools are lazily loaded. -Using this technique allows you to support on-demand loading of the devtools even in production mode, without including the full tools in the bundled code. +## Derive options through reactivity + +Options are passed to `withDevtools` from a callback function to support reactivity through signals. In the following example +a signal is created from a RxJS observable that emits on a keyboard shortcut. When the derived signal is set to true, the devtools are lazily loaded. + +The example below always loads devtools in development mode and loads on-demand in production mode when a keyboard shortcut is pressed. ```ts +import { Injectable, isDevMode } from '@angular/core' +import { fromEvent, map, scan } from 'rxjs' +import { toSignal } from '@angular/core/rxjs-interop' + @Injectable({ providedIn: 'root' }) -class DevtoolsOptionsManager { +export class DevtoolsOptionsManager { loadDevtools = toSignal( fromEvent(document, 'keydown').pipe( map( (event): boolean => event.metaKey && event.ctrlKey && event.shiftKey && event.key === 'D', ), - scan((acc, curr) => acc || curr, false), + scan((acc, curr) => acc || curr, isDevMode()), ), { - initialValue: false, + initialValue: isDevMode(), }, ) } +``` + +If you want to use an injectable such as a service in the callback you can use `deps`. The injected value will be passed as parameter to the callback function. + +This is similar to `deps` in Angular's [`useFactory`](https://angular.dev/guide/di/dependency-injection-providers#factory-providers-usefactory) provider. + +```ts +// ... +// 👇 Note we import from the production sub-path to enable devtools lazy loading in production builds +import { withDevtools } from '@tanstack/angular-query-experimental/devtools/production' export const appConfig: ApplicationConfig = { providers: [ provideHttpClient(), provideTanStackQuery( new QueryClient(), - withDevtools(() => ({ - initialIsOpen: true, - loadDevtools: inject(DevtoolsOptionsManager).loadDevtools(), - })), + withDevtools( + (devToolsOptionsManager: DevtoolsOptionsManager) => ({ + loadDevtools: devToolsOptionsManager.loadDevtools(), + }), + { + // `deps` is used to inject and pass `DevtoolsOptionsManager` to the `withDevtools` callback. + deps: [DevtoolsOptionsManager], + }, + ), ), ], } ``` -### Options +### Options returned from the callback -Of these options `client`, `position`, `errorTypes`, `buttonPosition`, and `initialIsOpen` support reactivity through signals. +Of these options `loadDevtools`, `client`, `position`, `errorTypes`, `buttonPosition`, and `initialIsOpen` support reactivity through signals. - `loadDevtools?: 'auto' | boolean` - Defaults to `auto`: lazily loads devtools when in development mode. Skips loading in production mode. @@ -121,3 +160,5 @@ Of these options `client`, `position`, `errorTypes`, `buttonPosition`, and `init - `shadowDOMTarget?: ShadowRoot` - Default behavior will apply the devtool's styles to the head tag within the DOM. - Use this to pass a shadow DOM target to the devtools so that the styles will be applied within the shadow DOM instead of within the head tag in the light DOM. +- `hideDisabledQueries?: boolean` + - Set this to true to hide disabled queries from the devtools panel. diff --git a/docs/framework/angular/guides/query-cancellation.md b/docs/framework/angular/guides/query-cancellation.md index 572e8b5dc3..554cb28d1d 100644 --- a/docs/framework/angular/guides/query-cancellation.md +++ b/docs/framework/angular/guides/query-cancellation.md @@ -60,7 +60,7 @@ query = injectQuery(() => ({ [//]: # 'Example3' -```tsx +```ts import axios from 'axios' const query = injectQuery(() => ({ diff --git a/docs/framework/angular/reference/functions/infinitequeryoptions.md b/docs/framework/angular/reference/functions/infinitequeryoptions.md index 92894f5bcd..4f7055f247 100644 --- a/docs/framework/angular/reference/functions/infinitequeryoptions.md +++ b/docs/framework/angular/reference/functions/infinitequeryoptions.md @@ -3,6 +3,8 @@ id: infiniteQueryOptions title: infiniteQueryOptions --- + + # Function: infiniteQueryOptions() Allows to share and re-use infinite query options in a type-safe way. @@ -24,16 +26,19 @@ function infiniteQueryOptions< TPageParam, >( options, -): DefinedInitialDataInfiniteOptions< +): CreateInfiniteQueryOptions< TQueryFnData, TError, TData, TQueryKey, TPageParam > & + object & object ``` +Defined in: [infinite-query-options.ts:88](https://github.com/TanStack/query/blob/main/packages/angular-query-experimental/src/infinite-query-options.ts#L88) + Allows to share and re-use infinite query options in a type-safe way. The `queryKey` will be tagged with the type from `queryFn`. @@ -60,7 +65,7 @@ The infinite query options to tag with the type from `queryFn`. ### Returns -[`DefinedInitialDataInfiniteOptions`](../../type-aliases/definedinitialdatainfiniteoptions.md)\<`TQueryFnData`, `TError`, `TData`, `TQueryKey`, `TPageParam`\> & `object` +[`CreateInfiniteQueryOptions`](../../interfaces/createinfinitequeryoptions.md)\<`TQueryFnData`, `TError`, `TData`, `TQueryKey`, `TPageParam`\> & `object` & `object` The tagged infinite query options. @@ -70,10 +75,6 @@ The tagged infinite query options. The infinite query options to tag with the type from `queryFn`. -### Defined in - -[infinite-query-options.ts:94](https://github.com/TanStack/query/blob/main/packages/angular-query-experimental/src/infinite-query-options.ts#L94) - ## Call Signature ```ts @@ -85,16 +86,22 @@ function infiniteQueryOptions< TPageParam, >( options, -): UnusedSkipTokenInfiniteOptions< - TQueryFnData, - TError, - TData, - TQueryKey, - TPageParam +): OmitKeyof< + CreateInfiniteQueryOptions< + TQueryFnData, + TError, + TData, + TQueryKey, + TPageParam + >, + 'queryFn' > & + object & object ``` +Defined in: [infinite-query-options.ts:119](https://github.com/TanStack/query/blob/main/packages/angular-query-experimental/src/infinite-query-options.ts#L119) + Allows to share and re-use infinite query options in a type-safe way. The `queryKey` will be tagged with the type from `queryFn`. @@ -121,7 +128,7 @@ The infinite query options to tag with the type from `queryFn`. ### Returns -[`UnusedSkipTokenInfiniteOptions`](../../type-aliases/unusedskiptokeninfiniteoptions.md)\<`TQueryFnData`, `TError`, `TData`, `TQueryKey`, `TPageParam`\> & `object` +`OmitKeyof`\<[`CreateInfiniteQueryOptions`](../../interfaces/createinfinitequeryoptions.md)\<`TQueryFnData`, `TError`, `TData`, `TQueryKey`, `TPageParam`\>, `"queryFn"`\> & `object` & `object` The tagged infinite query options. @@ -131,10 +138,6 @@ The tagged infinite query options. The infinite query options to tag with the type from `queryFn`. -### Defined in - -[infinite-query-options.ts:126](https://github.com/TanStack/query/blob/main/packages/angular-query-experimental/src/infinite-query-options.ts#L126) - ## Call Signature ```ts @@ -146,16 +149,19 @@ function infiniteQueryOptions< TPageParam, >( options, -): UndefinedInitialDataInfiniteOptions< +): CreateInfiniteQueryOptions< TQueryFnData, TError, TData, TQueryKey, TPageParam > & + object & object ``` +Defined in: [infinite-query-options.ts:150](https://github.com/TanStack/query/blob/main/packages/angular-query-experimental/src/infinite-query-options.ts#L150) + Allows to share and re-use infinite query options in a type-safe way. The `queryKey` will be tagged with the type from `queryFn`. @@ -182,7 +188,7 @@ The infinite query options to tag with the type from `queryFn`. ### Returns -[`UndefinedInitialDataInfiniteOptions`](../../type-aliases/undefinedinitialdatainfiniteoptions.md)\<`TQueryFnData`, `TError`, `TData`, `TQueryKey`, `TPageParam`\> & `object` +[`CreateInfiniteQueryOptions`](../../interfaces/createinfinitequeryoptions.md)\<`TQueryFnData`, `TError`, `TData`, `TQueryKey`, `TPageParam`\> & `object` & `object` The tagged infinite query options. @@ -191,7 +197,3 @@ The tagged infinite query options. ### Param The infinite query options to tag with the type from `queryFn`. - -### Defined in - -[infinite-query-options.ts:158](https://github.com/TanStack/query/blob/main/packages/angular-query-experimental/src/infinite-query-options.ts#L158) diff --git a/docs/framework/angular/reference/functions/injectinfinitequery.md b/docs/framework/angular/reference/functions/injectinfinitequery.md index 7cc9e202e5..a8dff3e877 100644 --- a/docs/framework/angular/reference/functions/injectinfinitequery.md +++ b/docs/framework/angular/reference/functions/injectinfinitequery.md @@ -3,6 +3,8 @@ id: injectInfiniteQuery title: injectInfiniteQuery --- + + # Function: injectInfiniteQuery() Injects an infinite query: a declarative dependency on an asynchronous source of data that is tied to a unique key. @@ -31,6 +33,8 @@ function injectInfiniteQuery< ): DefinedCreateInfiniteQueryResult ``` +Defined in: [inject-infinite-query.ts:41](https://github.com/TanStack/query/blob/main/packages/angular-query-experimental/src/inject-infinite-query.ts#L41) + Injects an infinite query: a declarative dependency on an asynchronous source of data that is tied to a unique key. Infinite queries can additively "load more" data onto an existing set of data or "infinite scroll" @@ -76,10 +80,6 @@ A function that returns infinite query options. Additional configuration. -### Defined in - -[inject-infinite-query.ts:42](https://github.com/TanStack/query/blob/main/packages/angular-query-experimental/src/inject-infinite-query.ts#L42) - ## Call Signature ```ts @@ -92,6 +92,8 @@ function injectInfiniteQuery< >(injectInfiniteQueryFn, options?): CreateInfiniteQueryResult ``` +Defined in: [inject-infinite-query.ts:65](https://github.com/TanStack/query/blob/main/packages/angular-query-experimental/src/inject-infinite-query.ts#L65) + Injects an infinite query: a declarative dependency on an asynchronous source of data that is tied to a unique key. Infinite queries can additively "load more" data onto an existing set of data or "infinite scroll" @@ -137,10 +139,6 @@ A function that returns infinite query options. Additional configuration. -### Defined in - -[inject-infinite-query.ts:67](https://github.com/TanStack/query/blob/main/packages/angular-query-experimental/src/inject-infinite-query.ts#L67) - ## Call Signature ```ts @@ -153,6 +151,8 @@ function injectInfiniteQuery< >(injectInfiniteQueryFn, options?): CreateInfiniteQueryResult ``` +Defined in: [inject-infinite-query.ts:89](https://github.com/TanStack/query/blob/main/packages/angular-query-experimental/src/inject-infinite-query.ts#L89) + Injects an infinite query: a declarative dependency on an asynchronous source of data that is tied to a unique key. Infinite queries can additively "load more" data onto an existing set of data or "infinite scroll" @@ -172,7 +172,7 @@ Infinite queries can additively "load more" data onto an existing set of data or #### injectInfiniteQueryFn -() => [`CreateInfiniteQueryOptions`](../../interfaces/createinfinitequeryoptions.md)\<`TQueryFnData`, `TError`, `TData`, `TQueryFnData`, `TQueryKey`, `TPageParam`\> +() => [`CreateInfiniteQueryOptions`](../../interfaces/createinfinitequeryoptions.md)\<`TQueryFnData`, `TError`, `TData`, `TQueryKey`, `TPageParam`\> A function that returns infinite query options. @@ -197,7 +197,3 @@ A function that returns infinite query options. ### Param Additional configuration. - -### Defined in - -[inject-infinite-query.ts:92](https://github.com/TanStack/query/blob/main/packages/angular-query-experimental/src/inject-infinite-query.ts#L92) diff --git a/docs/framework/angular/reference/functions/injectisfetching.md b/docs/framework/angular/reference/functions/injectisfetching.md index acd90757c5..14555e20a0 100644 --- a/docs/framework/angular/reference/functions/injectisfetching.md +++ b/docs/framework/angular/reference/functions/injectisfetching.md @@ -3,12 +3,16 @@ id: injectIsFetching title: injectIsFetching --- + + # Function: injectIsFetching() ```ts function injectIsFetching(filters?, options?): Signal ``` +Defined in: [inject-is-fetching.ts:32](https://github.com/TanStack/query/blob/main/packages/angular-query-experimental/src/inject-is-fetching.ts#L32) + Injects a signal that tracks the number of queries that your application is loading or fetching in the background. @@ -33,7 +37,3 @@ Additional configuration `Signal`\<`number`\> signal with number of loading or fetching queries. - -## Defined in - -[inject-is-fetching.ts:32](https://github.com/TanStack/query/blob/main/packages/angular-query-experimental/src/inject-is-fetching.ts#L32) diff --git a/docs/framework/angular/reference/functions/injectismutating.md b/docs/framework/angular/reference/functions/injectismutating.md index 7ee99e51ab..74b6bc31a1 100644 --- a/docs/framework/angular/reference/functions/injectismutating.md +++ b/docs/framework/angular/reference/functions/injectismutating.md @@ -3,12 +3,16 @@ id: injectIsMutating title: injectIsMutating --- + + # Function: injectIsMutating() ```ts function injectIsMutating(filters?, options?): Signal ``` +Defined in: [inject-is-mutating.ts:30](https://github.com/TanStack/query/blob/main/packages/angular-query-experimental/src/inject-is-mutating.ts#L30) + Injects a signal that tracks the number of mutations that your application is fetching. Can be used for app-wide loading indicators @@ -32,7 +36,3 @@ Additional configuration `Signal`\<`number`\> signal with number of fetching mutations. - -## Defined in - -[inject-is-mutating.ts:31](https://github.com/TanStack/query/blob/main/packages/angular-query-experimental/src/inject-is-mutating.ts#L31) diff --git a/docs/framework/angular/reference/functions/injectisrestoring.md b/docs/framework/angular/reference/functions/injectisrestoring.md index abc69d04bd..dfae444b28 100644 --- a/docs/framework/angular/reference/functions/injectisrestoring.md +++ b/docs/framework/angular/reference/functions/injectisrestoring.md @@ -3,12 +3,16 @@ id: injectIsRestoring title: injectIsRestoring --- + + # Function: injectIsRestoring() ```ts function injectIsRestoring(options?): Signal ``` +Defined in: [inject-is-restoring.ts:32](https://github.com/TanStack/query/blob/main/packages/angular-query-experimental/src/inject-is-restoring.ts#L32) + Injects a signal that tracks whether a restore is currently in progress. [injectQuery](../injectquery.md) and friends also check this internally to avoid race conditions between the restore and initializing queries. ## Parameters @@ -23,8 +27,4 @@ Options for injectIsRestoring. `Signal`\<`boolean`\> -signal with boolean that indicates whether a restore is in progress. - -## Defined in - -[inject-is-restoring.ts:35](https://github.com/TanStack/query/blob/main/packages/angular-query-experimental/src/inject-is-restoring.ts#L35) +readonly signal with boolean that indicates whether a restore is in progress. diff --git a/docs/framework/angular/reference/functions/injectmutation.md b/docs/framework/angular/reference/functions/injectmutation.md index 6711e90c85..bb6abf188f 100644 --- a/docs/framework/angular/reference/functions/injectmutation.md +++ b/docs/framework/angular/reference/functions/injectmutation.md @@ -3,6 +3,8 @@ id: injectMutation title: injectMutation --- + + # Function: injectMutation() ```ts @@ -12,6 +14,8 @@ function injectMutation( ): CreateMutationResult ``` +Defined in: [inject-mutation.ts:44](https://github.com/TanStack/query/blob/main/packages/angular-query-experimental/src/inject-mutation.ts#L44) + Injects a mutation: an imperative function that can be invoked which typically performs server side effects. Unlike queries, mutations are not run automatically. @@ -45,7 +49,3 @@ Additional configuration [`CreateMutationResult`](../../type-aliases/createmutationresult.md)\<`TData`, `TError`, `TVariables`, `TContext`\> The mutation. - -## Defined in - -[inject-mutation.ts:42](https://github.com/TanStack/query/blob/main/packages/angular-query-experimental/src/inject-mutation.ts#L42) diff --git a/docs/framework/angular/reference/functions/injectmutationstate.md b/docs/framework/angular/reference/functions/injectmutationstate.md index 16e31386fc..67f5d3d1bf 100644 --- a/docs/framework/angular/reference/functions/injectmutationstate.md +++ b/docs/framework/angular/reference/functions/injectmutationstate.md @@ -3,6 +3,8 @@ id: injectMutationState title: injectMutationState --- + + # Function: injectMutationState() ```ts @@ -12,6 +14,8 @@ function injectMutationState( ): Signal ``` +Defined in: [inject-mutation-state.ts:60](https://github.com/TanStack/query/blob/main/packages/angular-query-experimental/src/inject-mutation-state.ts#L60) + Injects a signal that tracks the state of all mutations. ## Type Parameters @@ -37,7 +41,3 @@ The Angular injector to use. `Signal`\<`TResult`[]\> The signal that tracks the state of all mutations. - -## Defined in - -[inject-mutation-state.ts:64](https://github.com/TanStack/query/blob/main/packages/angular-query-experimental/src/inject-mutation-state.ts#L64) diff --git a/docs/framework/angular/reference/functions/injectqueries.md b/docs/framework/angular/reference/functions/injectqueries.md index 326e4faf2c..bc78ac6c4c 100644 --- a/docs/framework/angular/reference/functions/injectqueries.md +++ b/docs/framework/angular/reference/functions/injectqueries.md @@ -3,32 +3,36 @@ id: injectQueries title: injectQueries --- + + # Function: injectQueries() ```ts function injectQueries( - __namedParameters, + root0, injector?, ): Signal ``` +Defined in: [inject-queries.ts:202](https://github.com/TanStack/query/blob/main/packages/angular-query-experimental/src/inject-queries.ts#L202) + ## Type Parameters • **T** _extends_ `any`[] -• **TCombinedResult** = `T` _extends_ [] ? [] : `T` _extends_ [`Head`] ? [`GetResults`\<`Head`\>] : `T` _extends_ [`Head`, `...Tail[]`] ? [`...Tail[]`] _extends_ [] ? [] : [`...Tail[]`] _extends_ [`Head`] ? [`GetResults`\<`Head`\>, `GetResults`\<`Head`\>] : [`...Tail[]`] _extends_ [`Head`, `...Tail[]`] ? [`...Tail[]`] _extends_ [] ? [] : [`...Tail[]`] _extends_ [`Head`] ? [`GetResults`\<`Head`\>, `GetResults`\<`Head`\>, `GetResults`\<`Head`\>] : [`...Tail[]`] _extends_ [`Head`, `...Tail[]`] ? [`...(...)[]`] _extends_ [] ? [] : ... _extends_ ... ? ... : ... : [`...(...)[]`] _extends_ ...[] ? ...[] : ...[] : [`...Tail[]`] _extends_ `QueryObserverOptionsForCreateQueries`\<`TQueryFnData`, `TError`, `TData`, `any`\>[] ? `QueryObserverResult`\<`unknown` _extends_ `TData` ? `TQueryFnData` : `TData`, `unknown` _extends_ `TError` ? `Error` : `TError`\>[] : `QueryObserverResult`[] : `T` _extends_ `QueryObserverOptionsForCreateQueries`\<`TQueryFnData`, `TError`, `TData`, `any`\>[] ? `QueryObserverResult`\<`unknown` _extends_ `TData` ? `TQueryFnData` : `TData`, `unknown` _extends_ `TError` ? `Error` : `TError`\>[] : `QueryObserverResult`[] +• **TCombinedResult** = `T` _extends_ \[\] ? \[\] : `T` _extends_ \[`Head`\] ? \[`GetResults`\<`Head`\>\] : `T` _extends_ \[`Head`, `...Tail[]`\] ? \[`...Tail[]`\] _extends_ \[\] ? \[\] : \[`...Tail[]`\] _extends_ \[`Head`\] ? \[`GetResults`\<`Head`\>, `GetResults`\<`Head`\>\] : \[`...Tail[]`\] _extends_ \[`Head`, `...Tail[]`\] ? \[`...Tail[]`\] _extends_ \[\] ? \[\] : \[`...Tail[]`\] _extends_ \[`Head`\] ? \[`GetResults`\<`Head`\>, `GetResults`\<`Head`\>, `GetResults`\<`Head`\>\] : \[`...Tail[]`\] _extends_ \[`Head`, `...Tail[]`\] ? \[`...(...)[]`\] _extends_ \[\] ? \[\] : ... _extends_ ... ? ... : ... : \[`...(...)[]`\] _extends_ ...[] ? ...[] : ...[] : \[`...Tail[]`\] _extends_ `QueryObserverOptionsForCreateQueries`\<`TQueryFnData`, `TError`, `TData`, `any`\>[] ? `QueryObserverResult`\<`unknown` _extends_ `TData` ? `TQueryFnData` : `TData`, `unknown` _extends_ `TError` ? `Error` : `TError`\>[] : `QueryObserverResult`[] : `T` _extends_ `QueryObserverOptionsForCreateQueries`\<`TQueryFnData`, `TError`, `TData`, `any`\>[] ? `QueryObserverResult`\<`unknown` _extends_ `TData` ? `TQueryFnData` : `TData`, `unknown` _extends_ `TError` ? `Error` : `TError`\>[] : `QueryObserverResult`[] ## Parameters -### \_\_namedParameters +### root0 -#### combine +#### combine? (`result`) => `TCombinedResult` #### queries -`Signal`\<[`...(T extends [] ? [] : T extends [Head] ? [GetOptions] : T extends [Head, ...Tail[]] ? [...Tail[]] extends [] ? [] : [...Tail[]] extends [Head] ? [GetOptions, GetOptions] : [...Tail[]] extends [Head, ...Tail[]] ? [...(...)[]] extends [] ? [] : (...) extends (...) ? (...) : (...) : readonly (...)[] extends [...(...)[]] ? [...(...)[]] : (...) extends (...) ? (...) : (...) : readonly unknown[] extends T ? T : T extends QueryObserverOptionsForCreateQueries[] ? QueryObserverOptionsForCreateQueries[] : QueryObserverOptionsForCreateQueries[])[]`]\> +`Signal`\<\[`...(T extends [] ? [] : T extends [Head] ? [GetOptions] : T extends [Head, ...Tail[]] ? [...Tail[]] extends [] ? [] : [...Tail[]] extends [Head] ? [GetOptions, GetOptions] : [...Tail[]] extends [Head, ...Tail[]] ? [...(...)[]] extends [] ? [] : (...) extends (...) ? (...) : (...) : readonly (...)[] extends [...(...)[]] ? [...(...)[]] : (...) extends (...) ? (...) : (...) : readonly unknown[] extends T ? T : T extends QueryObserverOptionsForCreateQueries[] ? QueryObserverOptionsForCreateQueries[] : QueryObserverOptionsForCreateQueries[])[]`\]\> ### injector? @@ -37,7 +41,3 @@ function injectQueries( ## Returns `Signal`\<`TCombinedResult`\> - -## Defined in - -[inject-queries.ts:206](https://github.com/TanStack/query/blob/main/packages/angular-query-experimental/src/inject-queries.ts#L206) diff --git a/docs/framework/angular/reference/functions/injectquery.md b/docs/framework/angular/reference/functions/injectquery.md index 74a2c1ecf6..289eb21fc0 100644 --- a/docs/framework/angular/reference/functions/injectquery.md +++ b/docs/framework/angular/reference/functions/injectquery.md @@ -3,6 +3,8 @@ id: injectQuery title: injectQuery --- + + # Function: injectQuery() Injects a query: a declarative dependency on an asynchronous source of data that is tied to a unique key. @@ -59,6 +61,8 @@ function injectQuery( ): DefinedCreateQueryResult ``` +Defined in: [inject-query.ts:65](https://github.com/TanStack/query/blob/main/packages/angular-query-experimental/src/inject-query.ts#L65) + Injects a query: a declarative dependency on an asynchronous source of data that is tied to a unique key. **Basic example** @@ -140,10 +144,6 @@ https://tanstack.com/query/latest/docs/framework/angular/guides/queries https://tanstack.com/query/latest/docs/framework/angular/guides/queries -### Defined in - -[inject-query.ts:66](https://github.com/TanStack/query/blob/main/packages/angular-query-experimental/src/inject-query.ts#L66) - ## Call Signature ```ts @@ -153,6 +153,8 @@ function injectQuery( ): CreateQueryResult ``` +Defined in: [inject-query.ts:116](https://github.com/TanStack/query/blob/main/packages/angular-query-experimental/src/inject-query.ts#L116) + Injects a query: a declarative dependency on an asynchronous source of data that is tied to a unique key. **Basic example** @@ -234,10 +236,6 @@ https://tanstack.com/query/latest/docs/framework/angular/guides/queries https://tanstack.com/query/latest/docs/framework/angular/guides/queries -### Defined in - -[inject-query.ts:118](https://github.com/TanStack/query/blob/main/packages/angular-query-experimental/src/inject-query.ts#L118) - ## Call Signature ```ts @@ -247,6 +245,8 @@ function injectQuery( ): CreateQueryResult ``` +Defined in: [inject-query.ts:167](https://github.com/TanStack/query/blob/main/packages/angular-query-experimental/src/inject-query.ts#L167) + Injects a query: a declarative dependency on an asynchronous source of data that is tied to a unique key. **Basic example** @@ -327,7 +327,3 @@ https://tanstack.com/query/latest/docs/framework/angular/guides/queries ### See https://tanstack.com/query/latest/docs/framework/angular/guides/queries - -### Defined in - -[inject-query.ts:170](https://github.com/TanStack/query/blob/main/packages/angular-query-experimental/src/inject-query.ts#L170) diff --git a/docs/framework/angular/reference/functions/injectqueryclient.md b/docs/framework/angular/reference/functions/injectqueryclient.md index fbe1a39573..a5450f4dcf 100644 --- a/docs/framework/angular/reference/functions/injectqueryclient.md +++ b/docs/framework/angular/reference/functions/injectqueryclient.md @@ -3,12 +3,16 @@ id: injectQueryClient title: injectQueryClient --- + + # Function: ~~injectQueryClient()~~ ```ts function injectQueryClient(injectOptions): QueryClient ``` +Defined in: [inject-query-client.ts:18](https://github.com/TanStack/query/blob/main/packages/angular-query-experimental/src/inject-query-client.ts#L18) + Injects a `QueryClient` instance and allows passing a custom injector. ## Parameters @@ -35,7 +39,3 @@ If you need to get a `QueryClient` from a custom injector, use `injector.get(Que ```ts const queryClient = injectQueryClient() ``` - -## Defined in - -[inject-query-client.ts:19](https://github.com/TanStack/query/blob/main/packages/angular-query-experimental/src/inject-query-client.ts#L19) diff --git a/docs/framework/angular/reference/functions/mutationoptions.md b/docs/framework/angular/reference/functions/mutationoptions.md index ff7377df57..46e3844f40 100644 --- a/docs/framework/angular/reference/functions/mutationoptions.md +++ b/docs/framework/angular/reference/functions/mutationoptions.md @@ -3,14 +3,58 @@ id: mutationOptions title: mutationOptions --- + + # Function: mutationOptions() +Allows to share and re-use mutation options in a type-safe way. + +**Example** + +```ts +export class QueriesService { + private http = inject(HttpClient) + + updatePost(id: number) { + return mutationOptions({ + mutationFn: (post: Post) => Promise.resolve(post), + mutationKey: ['updatePost', id], + onSuccess: (newPost) => { + // ^? newPost: Post + this.queryClient.setQueryData(['posts', id], newPost) + }, + }) + } +} + +class ComponentOrService { + queries = inject(QueriesService) + id = signal(0) + mutation = injectMutation(() => this.queries.updatePost(this.id())) + + save() { + this.mutation.mutate({ title: 'New Title' }) + } +} +``` + +## Param + +The mutation options. + +## Call Signature + ```ts function mutationOptions( options, -): CreateMutationOptions +): WithRequired< + CreateMutationOptions, + 'mutationKey' +> ``` +Defined in: [mutation-options.ts:38](https://github.com/TanStack/query/blob/main/packages/angular-query-experimental/src/mutation-options.ts#L38) + Allows to share and re-use mutation options in a type-safe way. **Example** @@ -31,14 +75,18 @@ export class QueriesService { } } -queries = inject(QueriesService) -idSignal = new Signal(0) -mutation = injectMutation(() => this.queries.updatePost(this.idSignal())) +class ComponentOrService { + queries = inject(QueriesService) + id = signal(0) + mutation = injectMutation(() => this.queries.updatePost(this.id())) -mutation.mutate({ title: 'New Title' }) + save() { + this.mutation.mutate({ title: 'New Title' }) + } +} ``` -## Type Parameters +### Type Parameters • **TData** = `unknown` @@ -48,20 +96,96 @@ mutation.mutate({ title: 'New Title' }) • **TContext** = `unknown` -## Parameters +### Parameters -### options +#### options -`MutationObserverOptions`\<`TData`, `TError`, `TVariables`, `TContext`\> +`WithRequired`\<[`CreateMutationOptions`](../../interfaces/createmutationoptions.md)\<`TData`, `TError`, `TVariables`, `TContext`\>, `"mutationKey"`\> The mutation options. -## Returns +### Returns + +`WithRequired`\<[`CreateMutationOptions`](../../interfaces/createmutationoptions.md)\<`TData`, `TError`, `TVariables`, `TContext`\>, `"mutationKey"`\> -[`CreateMutationOptions`](../../interfaces/createmutationoptions.md)\<`TData`, `TError`, `TVariables`, `TContext`\> +Mutation options. Mutation options. -## Defined in +### Param + +The mutation options. + +## Call Signature + +```ts +function mutationOptions( + options, +): Omit< + CreateMutationOptions, + 'mutationKey' +> +``` + +Defined in: [mutation-options.ts:52](https://github.com/TanStack/query/blob/main/packages/angular-query-experimental/src/mutation-options.ts#L52) + +Allows to share and re-use mutation options in a type-safe way. -[mutation-options.ts:38](https://github.com/TanStack/query/blob/main/packages/angular-query-experimental/src/mutation-options.ts#L38) +**Example** + +```ts +export class QueriesService { + private http = inject(HttpClient) + + updatePost(id: number) { + return mutationOptions({ + mutationFn: (post: Post) => Promise.resolve(post), + mutationKey: ['updatePost', id], + onSuccess: (newPost) => { + // ^? newPost: Post + this.queryClient.setQueryData(['posts', id], newPost) + }, + }) + } +} + +class ComponentOrService { + queries = inject(QueriesService) + id = signal(0) + mutation = injectMutation(() => this.queries.updatePost(this.id())) + + save() { + this.mutation.mutate({ title: 'New Title' }) + } +} +``` + +### Type Parameters + +• **TData** = `unknown` + +• **TError** = `Error` + +• **TVariables** = `void` + +• **TContext** = `unknown` + +### Parameters + +#### options + +`Omit`\<[`CreateMutationOptions`](../../interfaces/createmutationoptions.md)\<`TData`, `TError`, `TVariables`, `TContext`\>, `"mutationKey"`\> + +The mutation options. + +### Returns + +`Omit`\<[`CreateMutationOptions`](../../interfaces/createmutationoptions.md)\<`TData`, `TError`, `TVariables`, `TContext`\>, `"mutationKey"`\> + +Mutation options. + +Mutation options. + +### Param + +The mutation options. diff --git a/docs/framework/angular/reference/functions/provideangularquery.md b/docs/framework/angular/reference/functions/provideangularquery.md new file mode 100644 index 0000000000..dbd57559fe --- /dev/null +++ b/docs/framework/angular/reference/functions/provideangularquery.md @@ -0,0 +1,40 @@ +--- +id: provideAngularQuery +title: provideAngularQuery +--- + + + +# Function: ~~provideAngularQuery()~~ + +```ts +function provideAngularQuery(queryClient): Provider[] +``` + +Defined in: [providers.ts:124](https://github.com/TanStack/query/blob/main/packages/angular-query-experimental/src/providers.ts#L124) + +Sets up providers necessary to enable TanStack Query functionality for Angular applications. + +Allows to configure a `QueryClient`. + +## Parameters + +### queryClient + +`QueryClient` + +A `QueryClient` instance. + +## Returns + +`Provider`[] + +A set of providers to set up TanStack Query. + +## See + +https://tanstack.com/query/v5/docs/framework/angular/quick-start + +## Deprecated + +Use `provideTanStackQuery` instead. diff --git a/docs/framework/angular/reference/functions/provideisrestoring.md b/docs/framework/angular/reference/functions/provideisrestoring.md index a920e0b6a2..ef5610b384 100644 --- a/docs/framework/angular/reference/functions/provideisrestoring.md +++ b/docs/framework/angular/reference/functions/provideisrestoring.md @@ -3,12 +3,16 @@ id: provideIsRestoring title: provideIsRestoring --- + + # Function: provideIsRestoring() ```ts function provideIsRestoring(isRestoring): Provider ``` +Defined in: [inject-is-restoring.ts:43](https://github.com/TanStack/query/blob/main/packages/angular-query-experimental/src/inject-is-restoring.ts#L43) + Used by TanStack Query Angular persist client plugin to provide the signal that tracks the restore state ## Parameters @@ -24,7 +28,3 @@ a readonly signal that returns a boolean `Provider` Provider for the `isRestoring` signal - -## Defined in - -[inject-is-restoring.ts:47](https://github.com/TanStack/query/blob/main/packages/angular-query-experimental/src/inject-is-restoring.ts#L47) diff --git a/docs/framework/angular/reference/functions/providequeryclient.md b/docs/framework/angular/reference/functions/providequeryclient.md index 8c67ee34fa..69dab5d6e3 100644 --- a/docs/framework/angular/reference/functions/providequeryclient.md +++ b/docs/framework/angular/reference/functions/providequeryclient.md @@ -3,12 +3,16 @@ id: provideQueryClient title: provideQueryClient --- + + # Function: provideQueryClient() ```ts function provideQueryClient(queryClient): Provider ``` +Defined in: [providers.ts:14](https://github.com/TanStack/query/blob/main/packages/angular-query-experimental/src/providers.ts#L14) + Usually [provideTanStackQuery](../providetanstackquery.md) is used once to set up TanStack Query and the [https://tanstack.com/query/latest/docs/reference/QueryClient\|QueryClient](https://tanstack.com/query/latest/docs/reference/QueryClient|QueryClient) for the entire application. Internally it calls `provideQueryClient`. @@ -28,7 +32,3 @@ A `QueryClient` instance, or an `InjectionToken` which provides a `QueryClient`. `Provider` a provider object that can be used to provide the `QueryClient` instance. - -## Defined in - -[providers.ts:31](https://github.com/TanStack/query/blob/main/packages/angular-query-experimental/src/providers.ts#L31) diff --git a/docs/framework/angular/reference/functions/providetanstackquery.md b/docs/framework/angular/reference/functions/providetanstackquery.md index 3c83ce2bb6..b70abdf030 100644 --- a/docs/framework/angular/reference/functions/providetanstackquery.md +++ b/docs/framework/angular/reference/functions/providetanstackquery.md @@ -3,12 +3,16 @@ id: provideTanStackQuery title: provideTanStackQuery --- + + # Function: provideTanStackQuery() ```ts function provideTanStackQuery(queryClient, ...features): Provider[] ``` +Defined in: [providers.ts:105](https://github.com/TanStack/query/blob/main/packages/angular-query-experimental/src/providers.ts#L105) + Sets up providers necessary to enable TanStack Query functionality for Angular applications. Allows to configure a `QueryClient` and optional features such as developer tools. @@ -73,6 +77,11 @@ export const MY_QUERY_CLIENT = new InjectionToken('', { providers: [provideTanStackQuery(MY_QUERY_CLIENT)] ``` +Using an InjectionToken for the QueryClient is an advanced optimization which allows TanStack Query to be absent from the main application bundle. +This can be beneficial if you want to include TanStack Query on lazy loaded routes only while still sharing a `QueryClient`. + +Note that this is a small optimization and for most applications it's preferable to provide the `QueryClient` in the main application config. + ## Parameters ### queryClient @@ -97,7 +106,3 @@ A set of providers to set up TanStack Query. - https://tanstack.com/query/v5/docs/framework/angular/quick-start - withDevtools - -## Defined in - -[providers.ts:118](https://github.com/TanStack/query/blob/main/packages/angular-query-experimental/src/providers.ts#L118) diff --git a/docs/framework/angular/reference/functions/queryfeature.md b/docs/framework/angular/reference/functions/queryfeature.md index 78d71ca0aa..f749616ba4 100644 --- a/docs/framework/angular/reference/functions/queryfeature.md +++ b/docs/framework/angular/reference/functions/queryfeature.md @@ -3,17 +3,21 @@ id: queryFeature title: queryFeature --- + + # Function: queryFeature() ```ts function queryFeature(kind, providers): QueryFeature ``` +Defined in: [providers.ts:146](https://github.com/TanStack/query/blob/main/packages/angular-query-experimental/src/providers.ts#L146) + Helper function to create an object that represents a Query feature. ## Type Parameters -• **TFeatureKind** _extends_ `"DeveloperTools"` \| `"PersistQueryClient"` +• **TFeatureKind** _extends_ `"Devtools"` \| `"PersistQueryClient"` ## Parameters @@ -30,7 +34,3 @@ Helper function to create an object that represents a Query feature. [`QueryFeature`](../../interfaces/queryfeature.md)\<`TFeatureKind`\> A Query feature. - -## Defined in - -[providers.ts:156](https://github.com/TanStack/query/blob/main/packages/angular-query-experimental/src/providers.ts#L156) diff --git a/docs/framework/angular/reference/functions/queryoptions.md b/docs/framework/angular/reference/functions/queryoptions.md index 27627d7672..d492b5a880 100644 --- a/docs/framework/angular/reference/functions/queryoptions.md +++ b/docs/framework/angular/reference/functions/queryoptions.md @@ -3,6 +3,8 @@ id: queryOptions title: queryOptions --- + + # Function: queryOptions() Allows to share and re-use query options in a type-safe way. @@ -32,9 +34,13 @@ The query options to tag with the type from `queryFn`. ```ts function queryOptions( options, -): DefinedInitialDataOptions & object +): Omit, 'queryFn'> & + object & + object ``` +Defined in: [query-options.ts:76](https://github.com/TanStack/query/blob/main/packages/angular-query-experimental/src/query-options.ts#L76) + Allows to share and re-use query options in a type-safe way. The `queryKey` will be tagged with the type from `queryFn`. @@ -73,7 +79,7 @@ The query options to tag with the type from `queryFn`. ### Returns -[`DefinedInitialDataOptions`](../../type-aliases/definedinitialdataoptions.md)\<`TQueryFnData`, `TError`, `TData`, `TQueryKey`\> & `object` +`Omit`\<[`CreateQueryOptions`](../../interfaces/createqueryoptions.md)\<`TQueryFnData`, `TError`, `TData`, `TQueryKey`\>, `"queryFn"`\> & `object` & `object` The tagged query options. @@ -83,18 +89,21 @@ The tagged query options. The query options to tag with the type from `queryFn`. -### Defined in - -[query-options.ts:78](https://github.com/TanStack/query/blob/main/packages/angular-query-experimental/src/query-options.ts#L78) - ## Call Signature ```ts function queryOptions( options, -): UnusedSkipTokenOptions & object +): OmitKeyof< + CreateQueryOptions, + 'queryFn' +> & + object & + object ``` +Defined in: [query-options.ts:108](https://github.com/TanStack/query/blob/main/packages/angular-query-experimental/src/query-options.ts#L108) + Allows to share and re-use query options in a type-safe way. The `queryKey` will be tagged with the type from `queryFn`. @@ -133,7 +142,7 @@ The query options to tag with the type from `queryFn`. ### Returns -[`UnusedSkipTokenOptions`](../../type-aliases/unusedskiptokenoptions.md)\<`TQueryFnData`, `TError`, `TData`, `TQueryKey`\> & `object` +`OmitKeyof`\<[`CreateQueryOptions`](../../interfaces/createqueryoptions.md)\<`TQueryFnData`, `TError`, `TData`, `TQueryKey`\>, `"queryFn"`\> & `object` & `object` The tagged query options. @@ -143,18 +152,16 @@ The tagged query options. The query options to tag with the type from `queryFn`. -### Defined in - -[query-options.ts:111](https://github.com/TanStack/query/blob/main/packages/angular-query-experimental/src/query-options.ts#L111) - ## Call Signature ```ts function queryOptions( options, -): UndefinedInitialDataOptions & object +): CreateQueryOptions & object & object ``` +Defined in: [query-options.ts:140](https://github.com/TanStack/query/blob/main/packages/angular-query-experimental/src/query-options.ts#L140) + Allows to share and re-use query options in a type-safe way. The `queryKey` will be tagged with the type from `queryFn`. @@ -193,7 +200,7 @@ The query options to tag with the type from `queryFn`. ### Returns -[`UndefinedInitialDataOptions`](../../type-aliases/undefinedinitialdataoptions.md)\<`TQueryFnData`, `TError`, `TData`, `TQueryKey`\> & `object` +[`CreateQueryOptions`](../../interfaces/createqueryoptions.md)\<`TQueryFnData`, `TError`, `TData`, `TQueryKey`\> & `object` & `object` The tagged query options. @@ -202,7 +209,3 @@ The tagged query options. ### Param The query options to tag with the type from `queryFn`. - -### Defined in - -[query-options.ts:144](https://github.com/TanStack/query/blob/main/packages/angular-query-experimental/src/query-options.ts#L144) diff --git a/docs/framework/angular/reference/functions/withdevtools.md b/docs/framework/angular/reference/functions/withdevtools.md deleted file mode 100644 index 6dfdac2d77..0000000000 --- a/docs/framework/angular/reference/functions/withdevtools.md +++ /dev/null @@ -1,49 +0,0 @@ ---- -id: withDevtools -title: withDevtools ---- - -# Function: withDevtools() - -```ts -function withDevtools(withDevtoolsFn?): DeveloperToolsFeature -``` - -Enables developer tools. - -**Example** - -```ts -export const appConfig: ApplicationConfig = { - providers: [provideTanStackQuery(new QueryClient(), withDevtools())], -} -``` - -By default the devtools will be loaded when Angular runs in development mode and rendered in ``. - -If you need more control over when devtools are loaded, you can use the `loadDevtools` option. This is particularly useful if you want to load devtools based on environment configurations. For instance, you might have a test environment running in production mode but still require devtools to be available. - -If you need more control over where devtools are rendered, consider `injectDevtoolsPanel`. This allows rendering devtools inside your own devtools for example. - -## Parameters - -### withDevtoolsFn? - -() => [`DevtoolsOptions`](../../interfaces/devtoolsoptions.md) - -A function that returns `DevtoolsOptions`. - -## Returns - -[`DeveloperToolsFeature`](../../type-aliases/developertoolsfeature.md) - -A set of providers for use with `provideTanStackQuery`. - -## See - -- [provideTanStackQuery](../providetanstackquery.md) -- [DevtoolsOptions](../../interfaces/devtoolsoptions.md) - -## Defined in - -[providers.ts:262](https://github.com/TanStack/query/blob/main/packages/angular-query-experimental/src/providers.ts#L262) diff --git a/docs/framework/angular/reference/index.md b/docs/framework/angular/reference/index.md index c8b1690d3d..d9d29d1e6a 100644 --- a/docs/framework/angular/reference/index.md +++ b/docs/framework/angular/reference/index.md @@ -3,6 +3,8 @@ id: '@tanstack/angular-query-experimental' title: '@tanstack/angular-query-experimental' --- + + # @tanstack/angular-query-experimental ## Interfaces @@ -13,7 +15,6 @@ title: '@tanstack/angular-query-experimental' - [CreateInfiniteQueryOptions](../interfaces/createinfinitequeryoptions.md) - [CreateMutationOptions](../interfaces/createmutationoptions.md) - [CreateQueryOptions](../interfaces/createqueryoptions.md) -- [DevtoolsOptions](../interfaces/devtoolsoptions.md) - [InjectInfiniteQueryOptions](../interfaces/injectinfinitequeryoptions.md) - [InjectIsFetchingOptions](../interfaces/injectisfetchingoptions.md) - [InjectIsMutatingOptions](../interfaces/injectismutatingoptions.md) @@ -39,17 +40,12 @@ title: '@tanstack/angular-query-experimental' - [PersistQueryClientFeature](../type-aliases/persistqueryclientfeature.md) - [QueriesOptions](../type-aliases/queriesoptions.md) - [QueriesResults](../type-aliases/queriesresults.md) -- [QueryFeatureKind](../type-aliases/queryfeaturekind.md) - [QueryFeatures](../type-aliases/queryfeatures.md) - [UndefinedInitialDataInfiniteOptions](../type-aliases/undefinedinitialdatainfiniteoptions.md) - [UndefinedInitialDataOptions](../type-aliases/undefinedinitialdataoptions.md) - [UnusedSkipTokenInfiniteOptions](../type-aliases/unusedskiptokeninfiniteoptions.md) - [UnusedSkipTokenOptions](../type-aliases/unusedskiptokenoptions.md) -## Variables - -- [queryFeatures](../variables/queryfeatures.md) - ## Functions - [infiniteQueryOptions](../functions/infinitequeryoptions.md) @@ -61,11 +57,11 @@ title: '@tanstack/angular-query-experimental' - [injectMutationState](../functions/injectmutationstate.md) - [injectQueries](../functions/injectqueries.md) - [injectQuery](../functions/injectquery.md) -- [injectQueryClient](../functions/injectqueryclient.md) +- [~~injectQueryClient~~](../functions/injectqueryclient.md) - [mutationOptions](../functions/mutationoptions.md) +- [~~provideAngularQuery~~](../functions/provideangularquery.md) - [provideIsRestoring](../functions/provideisrestoring.md) - [provideQueryClient](../functions/providequeryclient.md) - [provideTanStackQuery](../functions/providetanstackquery.md) - [queryFeature](../functions/queryfeature.md) - [queryOptions](../functions/queryoptions.md) -- [withDevtools](../functions/withdevtools.md) diff --git a/docs/framework/angular/reference/interfaces/basemutationnarrowing.md b/docs/framework/angular/reference/interfaces/basemutationnarrowing.md index b81171eaf6..8ea0f00f90 100644 --- a/docs/framework/angular/reference/interfaces/basemutationnarrowing.md +++ b/docs/framework/angular/reference/interfaces/basemutationnarrowing.md @@ -3,8 +3,12 @@ id: BaseMutationNarrowing title: BaseMutationNarrowing --- + + # Interface: BaseMutationNarrowing\ +Defined in: [types.ts:183](https://github.com/TanStack/query/blob/main/packages/angular-query-experimental/src/types.ts#L183) + ## Type Parameters • **TData** = `unknown` @@ -41,9 +45,7 @@ isError: SignalFunction< > ``` -#### Defined in - -[types.ts:242](https://github.com/TanStack/query/blob/main/packages/angular-query-experimental/src/types.ts#L242) +Defined in: [types.ts:206](https://github.com/TanStack/query/blob/main/packages/angular-query-experimental/src/types.ts#L206) --- @@ -71,9 +73,7 @@ isIdle: SignalFunction< > ``` -#### Defined in - -[types.ts:276](https://github.com/TanStack/query/blob/main/packages/angular-query-experimental/src/types.ts#L276) +Defined in: [types.ts:240](https://github.com/TanStack/query/blob/main/packages/angular-query-experimental/src/types.ts#L240) --- @@ -101,9 +101,7 @@ isPending: SignalFunction< > ``` -#### Defined in - -[types.ts:259](https://github.com/TanStack/query/blob/main/packages/angular-query-experimental/src/types.ts#L259) +Defined in: [types.ts:223](https://github.com/TanStack/query/blob/main/packages/angular-query-experimental/src/types.ts#L223) --- @@ -131,6 +129,4 @@ isSuccess: SignalFunction< > ``` -#### Defined in - -[types.ts:225](https://github.com/TanStack/query/blob/main/packages/angular-query-experimental/src/types.ts#L225) +Defined in: [types.ts:189](https://github.com/TanStack/query/blob/main/packages/angular-query-experimental/src/types.ts#L189) diff --git a/docs/framework/angular/reference/interfaces/basequerynarrowing.md b/docs/framework/angular/reference/interfaces/basequerynarrowing.md index bd1d7bee2a..3a8618c7ab 100644 --- a/docs/framework/angular/reference/interfaces/basequerynarrowing.md +++ b/docs/framework/angular/reference/interfaces/basequerynarrowing.md @@ -3,8 +3,12 @@ id: BaseQueryNarrowing title: BaseQueryNarrowing --- + + # Interface: BaseQueryNarrowing\ +Defined in: [types.ts:57](https://github.com/TanStack/query/blob/main/packages/angular-query-experimental/src/types.ts#L57) + ## Type Parameters • **TData** = `unknown` @@ -19,20 +23,18 @@ title: BaseQueryNarrowing isError: (this) => this is CreateBaseQueryResult>; ``` +Defined in: [types.ts:65](https://github.com/TanStack/query/blob/main/packages/angular-query-experimental/src/types.ts#L65) + #### Parameters ##### this -[`CreateBaseQueryResult`](../../type-aliases/createbasequeryresult.md)\<`TData`, `TError`, `QueryObserverResult`\<`TData`, `TError`\>\> +[`CreateBaseQueryResult`](../../type-aliases/createbasequeryresult.md)\<`TData`, `TError`\> #### Returns `this is CreateBaseQueryResult>` -#### Defined in - -[types.ts:76](https://github.com/TanStack/query/blob/main/packages/angular-query-experimental/src/types.ts#L76) - --- ### isPending() @@ -41,20 +43,18 @@ isError: (this) => this is CreateBaseQueryResult this is CreateBaseQueryResult>; ``` +Defined in: [types.ts:72](https://github.com/TanStack/query/blob/main/packages/angular-query-experimental/src/types.ts#L72) + #### Parameters ##### this -[`CreateBaseQueryResult`](../../type-aliases/createbasequeryresult.md)\<`TData`, `TError`, `QueryObserverResult`\<`TData`, `TError`\>\> +[`CreateBaseQueryResult`](../../type-aliases/createbasequeryresult.md)\<`TData`, `TError`\> #### Returns `this is CreateBaseQueryResult>` -#### Defined in - -[types.ts:83](https://github.com/TanStack/query/blob/main/packages/angular-query-experimental/src/types.ts#L83) - --- ### isSuccess() @@ -63,16 +63,14 @@ isPending: (this) => this is CreateBaseQueryResult this is CreateBaseQueryResult>; ``` +Defined in: [types.ts:58](https://github.com/TanStack/query/blob/main/packages/angular-query-experimental/src/types.ts#L58) + #### Parameters ##### this -[`CreateBaseQueryResult`](../../type-aliases/createbasequeryresult.md)\<`TData`, `TError`, `QueryObserverResult`\<`TData`, `TError`\>\> +[`CreateBaseQueryResult`](../../type-aliases/createbasequeryresult.md)\<`TData`, `TError`\> #### Returns `this is CreateBaseQueryResult>` - -#### Defined in - -[types.ts:69](https://github.com/TanStack/query/blob/main/packages/angular-query-experimental/src/types.ts#L69) diff --git a/docs/framework/angular/reference/interfaces/createbasequeryoptions.md b/docs/framework/angular/reference/interfaces/createbasequeryoptions.md index c371959980..e0d731d5b3 100644 --- a/docs/framework/angular/reference/interfaces/createbasequeryoptions.md +++ b/docs/framework/angular/reference/interfaces/createbasequeryoptions.md @@ -3,8 +3,12 @@ id: CreateBaseQueryOptions title: CreateBaseQueryOptions --- + + # Interface: CreateBaseQueryOptions\ +Defined in: [types.ts:21](https://github.com/TanStack/query/blob/main/packages/angular-query-experimental/src/types.ts#L21) + ## Extends - `QueryObserverOptions`\<`TQueryFnData`, `TError`, `TData`, `TQueryData`, `TQueryKey`\> diff --git a/docs/framework/angular/reference/interfaces/createinfinitequeryoptions.md b/docs/framework/angular/reference/interfaces/createinfinitequeryoptions.md index dade8e1e30..53ad6617ca 100644 --- a/docs/framework/angular/reference/interfaces/createinfinitequeryoptions.md +++ b/docs/framework/angular/reference/interfaces/createinfinitequeryoptions.md @@ -3,11 +3,15 @@ id: CreateInfiniteQueryOptions title: CreateInfiniteQueryOptions --- -# Interface: CreateInfiniteQueryOptions\ + + +# Interface: CreateInfiniteQueryOptions\ + +Defined in: [types.ts:81](https://github.com/TanStack/query/blob/main/packages/angular-query-experimental/src/types.ts#L81) ## Extends -- `OmitKeyof`\<`InfiniteQueryObserverOptions`\<`TQueryFnData`, `TError`, `TData`, `TQueryData`, `TQueryKey`, `TPageParam`\>, `"suspense"`\> +- `OmitKeyof`\<`InfiniteQueryObserverOptions`\<`TQueryFnData`, `TError`, `TData`, `TQueryKey`, `TPageParam`\>, `"suspense"`\> ## Type Parameters @@ -17,8 +21,6 @@ title: CreateInfiniteQueryOptions • **TData** = `TQueryFnData` -• **TQueryData** = `TQueryFnData` - • **TQueryKey** _extends_ `QueryKey` = `QueryKey` • **TPageParam** = `unknown` diff --git a/docs/framework/angular/reference/interfaces/createmutationoptions.md b/docs/framework/angular/reference/interfaces/createmutationoptions.md index ffca256828..ebc47be190 100644 --- a/docs/framework/angular/reference/interfaces/createmutationoptions.md +++ b/docs/framework/angular/reference/interfaces/createmutationoptions.md @@ -3,8 +3,12 @@ id: CreateMutationOptions title: CreateMutationOptions --- + + # Interface: CreateMutationOptions\ +Defined in: [types.ts:132](https://github.com/TanStack/query/blob/main/packages/angular-query-experimental/src/types.ts#L132) + ## Extends - `OmitKeyof`\<`MutationObserverOptions`\<`TData`, `TError`, `TVariables`, `TContext`\>, `"_defaulted"`\> diff --git a/docs/framework/angular/reference/interfaces/createqueryoptions.md b/docs/framework/angular/reference/interfaces/createqueryoptions.md index 372319f6d4..61baca7951 100644 --- a/docs/framework/angular/reference/interfaces/createqueryoptions.md +++ b/docs/framework/angular/reference/interfaces/createqueryoptions.md @@ -3,8 +3,12 @@ id: CreateQueryOptions title: CreateQueryOptions --- + + # Interface: CreateQueryOptions\ +Defined in: [types.ts:35](https://github.com/TanStack/query/blob/main/packages/angular-query-experimental/src/types.ts#L35) + ## Extends - `OmitKeyof`\<[`CreateBaseQueryOptions`](../createbasequeryoptions.md)\<`TQueryFnData`, `TError`, `TData`, `TQueryFnData`, `TQueryKey`\>, `"suspense"`\> diff --git a/docs/framework/angular/reference/interfaces/devtoolsoptions.md b/docs/framework/angular/reference/interfaces/devtoolsoptions.md deleted file mode 100644 index 0eccac40a8..0000000000 --- a/docs/framework/angular/reference/interfaces/devtoolsoptions.md +++ /dev/null @@ -1,143 +0,0 @@ ---- -id: DevtoolsOptions -title: DevtoolsOptions ---- - -# Interface: DevtoolsOptions - -Options for configuring the TanStack Query devtools. - -## Properties - -### buttonPosition? - -```ts -optional buttonPosition: DevtoolsButtonPosition; -``` - -The position of the TanStack logo to open and close the devtools panel. -`top-left` | `top-right` | `bottom-left` | `bottom-right` | `relative` -Defaults to `bottom-right`. - -#### Defined in - -[providers.ts:192](https://github.com/TanStack/query/blob/main/packages/angular-query-experimental/src/providers.ts#L192) - ---- - -### client? - -```ts -optional client: QueryClient; -``` - -Custom instance of QueryClient - -#### Defined in - -[providers.ts:202](https://github.com/TanStack/query/blob/main/packages/angular-query-experimental/src/providers.ts#L202) - ---- - -### errorTypes? - -```ts -optional errorTypes: DevtoolsErrorType[]; -``` - -Use this so you can define custom errors that can be shown in the devtools. - -#### Defined in - -[providers.ts:206](https://github.com/TanStack/query/blob/main/packages/angular-query-experimental/src/providers.ts#L206) - ---- - -### initialIsOpen? - -```ts -optional initialIsOpen: boolean; -``` - -Set this true if you want the devtools to default to being open - -#### Defined in - -[providers.ts:186](https://github.com/TanStack/query/blob/main/packages/angular-query-experimental/src/providers.ts#L186) - ---- - -### loadDevtools? - -```ts -optional loadDevtools: boolean | "auto"; -``` - -Whether the developer tools should load. - -- `auto`- (Default) Lazily loads devtools when in development mode. Skips loading in production mode. -- `true`- Always load the devtools, regardless of the environment. -- `false`- Never load the devtools, regardless of the environment. - -You can use `true` and `false` to override loading developer tools from an environment file. -For example, a test environment might run in production mode but you may want to load developer tools. - -Additionally, you can use a signal in the callback to dynamically load the devtools based on a condition. For example, -a signal created from a RxJS observable that listens for a keyboard shortcut. - -**Example** - -```ts -withDevtools(() => ({ - initialIsOpen: true, - loadDevtools: inject(ExampleService).loadDevtools(), -})) -``` - -#### Defined in - -[providers.ts:236](https://github.com/TanStack/query/blob/main/packages/angular-query-experimental/src/providers.ts#L236) - ---- - -### position? - -```ts -optional position: DevtoolsPosition; -``` - -The position of the TanStack Query devtools panel. -`top` | `bottom` | `left` | `right` -Defaults to `bottom`. - -#### Defined in - -[providers.ts:198](https://github.com/TanStack/query/blob/main/packages/angular-query-experimental/src/providers.ts#L198) - ---- - -### shadowDOMTarget? - -```ts -optional shadowDOMTarget: ShadowRoot; -``` - -Use this so you can attach the devtool's styles to a specific element in the DOM. - -#### Defined in - -[providers.ts:214](https://github.com/TanStack/query/blob/main/packages/angular-query-experimental/src/providers.ts#L214) - ---- - -### styleNonce? - -```ts -optional styleNonce: string; -``` - -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. - -#### Defined in - -[providers.ts:210](https://github.com/TanStack/query/blob/main/packages/angular-query-experimental/src/providers.ts#L210) diff --git a/docs/framework/angular/reference/interfaces/injectinfinitequeryoptions.md b/docs/framework/angular/reference/interfaces/injectinfinitequeryoptions.md index a1783d1f97..954c705fde 100644 --- a/docs/framework/angular/reference/interfaces/injectinfinitequeryoptions.md +++ b/docs/framework/angular/reference/interfaces/injectinfinitequeryoptions.md @@ -3,8 +3,12 @@ id: InjectInfiniteQueryOptions title: InjectInfiniteQueryOptions --- + + # Interface: InjectInfiniteQueryOptions +Defined in: [inject-infinite-query.ts:25](https://github.com/TanStack/query/blob/main/packages/angular-query-experimental/src/inject-infinite-query.ts#L25) + ## Properties ### injector? @@ -13,10 +17,8 @@ title: InjectInfiniteQueryOptions optional injector: Injector; ``` +Defined in: [inject-infinite-query.ts:31](https://github.com/TanStack/query/blob/main/packages/angular-query-experimental/src/inject-infinite-query.ts#L31) + The `Injector` in which to create the infinite query. If this is not provided, the current injection context will be used instead (via `inject`). - -#### Defined in - -[inject-infinite-query.ts:31](https://github.com/TanStack/query/blob/main/packages/angular-query-experimental/src/inject-infinite-query.ts#L31) diff --git a/docs/framework/angular/reference/interfaces/injectisfetchingoptions.md b/docs/framework/angular/reference/interfaces/injectisfetchingoptions.md index 55184b8053..d5de1f4ae3 100644 --- a/docs/framework/angular/reference/interfaces/injectisfetchingoptions.md +++ b/docs/framework/angular/reference/interfaces/injectisfetchingoptions.md @@ -3,8 +3,12 @@ id: InjectIsFetchingOptions title: InjectIsFetchingOptions --- + + # Interface: InjectIsFetchingOptions +Defined in: [inject-is-fetching.ts:13](https://github.com/TanStack/query/blob/main/packages/angular-query-experimental/src/inject-is-fetching.ts#L13) + ## Properties ### injector? @@ -13,10 +17,8 @@ title: InjectIsFetchingOptions optional injector: Injector; ``` +Defined in: [inject-is-fetching.ts:19](https://github.com/TanStack/query/blob/main/packages/angular-query-experimental/src/inject-is-fetching.ts#L19) + The `Injector` in which to create the isFetching signal. If this is not provided, the current injection context will be used instead (via `inject`). - -#### Defined in - -[inject-is-fetching.ts:19](https://github.com/TanStack/query/blob/main/packages/angular-query-experimental/src/inject-is-fetching.ts#L19) diff --git a/docs/framework/angular/reference/interfaces/injectismutatingoptions.md b/docs/framework/angular/reference/interfaces/injectismutatingoptions.md index daf4f69b66..393dfd44a0 100644 --- a/docs/framework/angular/reference/interfaces/injectismutatingoptions.md +++ b/docs/framework/angular/reference/interfaces/injectismutatingoptions.md @@ -3,8 +3,12 @@ id: InjectIsMutatingOptions title: InjectIsMutatingOptions --- + + # Interface: InjectIsMutatingOptions +Defined in: [inject-is-mutating.ts:13](https://github.com/TanStack/query/blob/main/packages/angular-query-experimental/src/inject-is-mutating.ts#L13) + ## Properties ### injector? @@ -13,10 +17,8 @@ title: InjectIsMutatingOptions optional injector: Injector; ``` +Defined in: [inject-is-mutating.ts:19](https://github.com/TanStack/query/blob/main/packages/angular-query-experimental/src/inject-is-mutating.ts#L19) + The `Injector` in which to create the isMutating signal. If this is not provided, the current injection context will be used instead (via `inject`). - -#### Defined in - -[inject-is-mutating.ts:19](https://github.com/TanStack/query/blob/main/packages/angular-query-experimental/src/inject-is-mutating.ts#L19) diff --git a/docs/framework/angular/reference/interfaces/injectmutationoptions.md b/docs/framework/angular/reference/interfaces/injectmutationoptions.md index 88dc930a57..0de78ed031 100644 --- a/docs/framework/angular/reference/interfaces/injectmutationoptions.md +++ b/docs/framework/angular/reference/interfaces/injectmutationoptions.md @@ -3,8 +3,12 @@ id: InjectMutationOptions title: InjectMutationOptions --- + + # Interface: InjectMutationOptions +Defined in: [inject-mutation.ts:27](https://github.com/TanStack/query/blob/main/packages/angular-query-experimental/src/inject-mutation.ts#L27) + ## Properties ### injector? @@ -13,10 +17,8 @@ title: InjectMutationOptions optional injector: Injector; ``` +Defined in: [inject-mutation.ts:33](https://github.com/TanStack/query/blob/main/packages/angular-query-experimental/src/inject-mutation.ts#L33) + The `Injector` in which to create the mutation. If this is not provided, the current injection context will be used instead (via `inject`). - -#### Defined in - -[inject-mutation.ts:30](https://github.com/TanStack/query/blob/main/packages/angular-query-experimental/src/inject-mutation.ts#L30) diff --git a/docs/framework/angular/reference/interfaces/injectmutationstateoptions.md b/docs/framework/angular/reference/interfaces/injectmutationstateoptions.md index 253f8cea32..022a878941 100644 --- a/docs/framework/angular/reference/interfaces/injectmutationstateoptions.md +++ b/docs/framework/angular/reference/interfaces/injectmutationstateoptions.md @@ -3,8 +3,12 @@ id: InjectMutationStateOptions title: InjectMutationStateOptions --- + + # Interface: InjectMutationStateOptions +Defined in: [inject-mutation-state.ts:45](https://github.com/TanStack/query/blob/main/packages/angular-query-experimental/src/inject-mutation-state.ts#L45) + ## Properties ### injector? @@ -13,10 +17,8 @@ title: InjectMutationStateOptions optional injector: Injector; ``` +Defined in: [inject-mutation-state.ts:51](https://github.com/TanStack/query/blob/main/packages/angular-query-experimental/src/inject-mutation-state.ts#L51) + The `Injector` in which to create the mutation state signal. If this is not provided, the current injection context will be used instead (via `inject`). - -#### Defined in - -[inject-mutation-state.ts:54](https://github.com/TanStack/query/blob/main/packages/angular-query-experimental/src/inject-mutation-state.ts#L54) diff --git a/docs/framework/angular/reference/interfaces/injectqueryoptions.md b/docs/framework/angular/reference/interfaces/injectqueryoptions.md index 202354d583..680e49ed3f 100644 --- a/docs/framework/angular/reference/interfaces/injectqueryoptions.md +++ b/docs/framework/angular/reference/interfaces/injectqueryoptions.md @@ -3,8 +3,12 @@ id: InjectQueryOptions title: InjectQueryOptions --- + + # Interface: InjectQueryOptions +Defined in: [inject-query.ts:20](https://github.com/TanStack/query/blob/main/packages/angular-query-experimental/src/inject-query.ts#L20) + ## Properties ### injector? @@ -13,10 +17,8 @@ title: InjectQueryOptions optional injector: Injector; ``` +Defined in: [inject-query.ts:26](https://github.com/TanStack/query/blob/main/packages/angular-query-experimental/src/inject-query.ts#L26) + The `Injector` in which to create the query. If this is not provided, the current injection context will be used instead (via `inject`). - -#### Defined in - -[inject-query.ts:26](https://github.com/TanStack/query/blob/main/packages/angular-query-experimental/src/inject-query.ts#L26) diff --git a/docs/framework/angular/reference/interfaces/queryfeature.md b/docs/framework/angular/reference/interfaces/queryfeature.md index c0c3e15028..70871d1f80 100644 --- a/docs/framework/angular/reference/interfaces/queryfeature.md +++ b/docs/framework/angular/reference/interfaces/queryfeature.md @@ -3,13 +3,17 @@ id: QueryFeature title: QueryFeature --- + + # Interface: QueryFeature\ +Defined in: [providers.ts:135](https://github.com/TanStack/query/blob/main/packages/angular-query-experimental/src/providers.ts#L135) + Helper type to represent a Query feature. ## Type Parameters -• **TFeatureKind** _extends_ [`QueryFeatureKind`](../../type-aliases/queryfeaturekind.md) +• **TFeatureKind** _extends_ `QueryFeatureKind` ## Properties @@ -19,9 +23,7 @@ Helper type to represent a Query feature. ɵkind: TFeatureKind ``` -#### Defined in - -[providers.ts:146](https://github.com/TanStack/query/blob/main/packages/angular-query-experimental/src/providers.ts#L146) +Defined in: [providers.ts:136](https://github.com/TanStack/query/blob/main/packages/angular-query-experimental/src/providers.ts#L136) --- @@ -31,6 +33,4 @@ Helper type to represent a Query feature. ɵproviders: Provider[]; ``` -#### Defined in - -[providers.ts:147](https://github.com/TanStack/query/blob/main/packages/angular-query-experimental/src/providers.ts#L147) +Defined in: [providers.ts:137](https://github.com/TanStack/query/blob/main/packages/angular-query-experimental/src/providers.ts#L137) diff --git a/docs/framework/angular/reference/type-aliases/createbasemutationresult.md b/docs/framework/angular/reference/type-aliases/createbasemutationresult.md index 5c05660689..39441b5f12 100644 --- a/docs/framework/angular/reference/type-aliases/createbasemutationresult.md +++ b/docs/framework/angular/reference/type-aliases/createbasemutationresult.md @@ -3,6 +3,8 @@ id: CreateBaseMutationResult title: CreateBaseMutationResult --- + + # Type Alias: CreateBaseMutationResult\ ```ts @@ -15,6 +17,8 @@ type CreateBaseMutationResult = Override< object ``` +Defined in: [types.ts:158](https://github.com/TanStack/query/blob/main/packages/angular-query-experimental/src/types.ts#L158) + ## Type declaration ### mutateAsync @@ -32,7 +36,3 @@ mutateAsync: CreateMutateAsyncFunction • **TVariables** = `unknown` • **TContext** = `unknown` - -## Defined in - -[types.ts:188](https://github.com/TanStack/query/blob/main/packages/angular-query-experimental/src/types.ts#L188) diff --git a/docs/framework/angular/reference/type-aliases/createbasequeryresult.md b/docs/framework/angular/reference/type-aliases/createbasequeryresult.md index f8b5b1d147..1dd27ac995 100644 --- a/docs/framework/angular/reference/type-aliases/createbasequeryresult.md +++ b/docs/framework/angular/reference/type-aliases/createbasequeryresult.md @@ -3,6 +3,8 @@ id: CreateBaseQueryResult title: CreateBaseQueryResult --- + + # Type Alias: CreateBaseQueryResult\ ```ts @@ -13,6 +15,8 @@ type CreateBaseQueryResult = BaseQueryNarrowing< MapToSignals> ``` +Defined in: [types.ts:98](https://github.com/TanStack/query/blob/main/packages/angular-query-experimental/src/types.ts#L98) + ## Type Parameters • **TData** = `unknown` @@ -20,7 +24,3 @@ type CreateBaseQueryResult = BaseQueryNarrowing< • **TError** = `DefaultError` • **TState** = `QueryObserverResult`\<`TData`, `TError`\> - -## Defined in - -[types.ts:117](https://github.com/TanStack/query/blob/main/packages/angular-query-experimental/src/types.ts#L117) diff --git a/docs/framework/angular/reference/type-aliases/createinfinitequeryresult.md b/docs/framework/angular/reference/type-aliases/createinfinitequeryresult.md index 4f38c46f78..a2db0e64fd 100644 --- a/docs/framework/angular/reference/type-aliases/createinfinitequeryresult.md +++ b/docs/framework/angular/reference/type-aliases/createinfinitequeryresult.md @@ -3,6 +3,8 @@ id: CreateInfiniteQueryResult title: CreateInfiniteQueryResult --- + + # Type Alias: CreateInfiniteQueryResult\ ```ts @@ -13,12 +15,10 @@ type CreateInfiniteQueryResult = BaseQueryNarrowing< MapToSignals> ``` +Defined in: [types.ts:117](https://github.com/TanStack/query/blob/main/packages/angular-query-experimental/src/types.ts#L117) + ## Type Parameters • **TData** = `unknown` • **TError** = `DefaultError` - -## Defined in - -[types.ts:145](https://github.com/TanStack/query/blob/main/packages/angular-query-experimental/src/types.ts#L145) diff --git a/docs/framework/angular/reference/type-aliases/createmutateasyncfunction.md b/docs/framework/angular/reference/type-aliases/createmutateasyncfunction.md index 789f636025..abe1503a1d 100644 --- a/docs/framework/angular/reference/type-aliases/createmutateasyncfunction.md +++ b/docs/framework/angular/reference/type-aliases/createmutateasyncfunction.md @@ -3,6 +3,8 @@ id: CreateMutateAsyncFunction title: CreateMutateAsyncFunction --- + + # Type Alias: CreateMutateAsyncFunction\ ```ts @@ -10,6 +12,8 @@ type CreateMutateAsyncFunction = MutateFunction ``` +Defined in: [types.ts:151](https://github.com/TanStack/query/blob/main/packages/angular-query-experimental/src/types.ts#L151) + ## Type Parameters • **TData** = `unknown` @@ -19,7 +23,3 @@ type CreateMutateAsyncFunction = • **TVariables** = `void` • **TContext** = `unknown` - -## Defined in - -[types.ts:178](https://github.com/TanStack/query/blob/main/packages/angular-query-experimental/src/types.ts#L178) diff --git a/docs/framework/angular/reference/type-aliases/createmutatefunction.md b/docs/framework/angular/reference/type-aliases/createmutatefunction.md index 006ab2ae9a..dba0f7aa6e 100644 --- a/docs/framework/angular/reference/type-aliases/createmutatefunction.md +++ b/docs/framework/angular/reference/type-aliases/createmutatefunction.md @@ -3,6 +3,8 @@ id: CreateMutateFunction title: CreateMutateFunction --- + + # Type Alias: CreateMutateFunction()\ ```ts @@ -11,6 +13,8 @@ type CreateMutateFunction = ( ) => void ``` +Defined in: [types.ts:142](https://github.com/TanStack/query/blob/main/packages/angular-query-experimental/src/types.ts#L142) + ## Type Parameters • **TData** = `unknown` @@ -30,7 +34,3 @@ type CreateMutateFunction = ( ## Returns `void` - -## Defined in - -[types.ts:166](https://github.com/TanStack/query/blob/main/packages/angular-query-experimental/src/types.ts#L166) diff --git a/docs/framework/angular/reference/type-aliases/createmutationresult.md b/docs/framework/angular/reference/type-aliases/createmutationresult.md index 3306bbe436..0800010d05 100644 --- a/docs/framework/angular/reference/type-aliases/createmutationresult.md +++ b/docs/framework/angular/reference/type-aliases/createmutationresult.md @@ -3,6 +3,8 @@ id: CreateMutationResult title: CreateMutationResult --- + + # Type Alias: CreateMutationResult\ ```ts @@ -11,6 +13,8 @@ type CreateMutationResult = MapToSignals> ``` +Defined in: [types.ts:259](https://github.com/TanStack/query/blob/main/packages/angular-query-experimental/src/types.ts#L259) + ## Type Parameters • **TData** = `unknown` @@ -22,7 +26,3 @@ type CreateMutationResult = • **TContext** = `unknown` • **TState** = `CreateStatusBasedMutationResult`\<[`CreateBaseMutationResult`](../createbasemutationresult.md)\[`"status"`\], `TData`, `TError`, `TVariables`, `TContext`\> - -## Defined in - -[types.ts:298](https://github.com/TanStack/query/blob/main/packages/angular-query-experimental/src/types.ts#L298) diff --git a/docs/framework/angular/reference/type-aliases/createqueryresult.md b/docs/framework/angular/reference/type-aliases/createqueryresult.md index 78ada66abc..16c95c6798 100644 --- a/docs/framework/angular/reference/type-aliases/createqueryresult.md +++ b/docs/framework/angular/reference/type-aliases/createqueryresult.md @@ -3,18 +3,18 @@ id: CreateQueryResult title: CreateQueryResult --- + + # Type Alias: CreateQueryResult\ ```ts type CreateQueryResult = CreateBaseQueryResult ``` +Defined in: [types.ts:105](https://github.com/TanStack/query/blob/main/packages/angular-query-experimental/src/types.ts#L105) + ## Type Parameters • **TData** = `unknown` • **TError** = `DefaultError` - -## Defined in - -[types.ts:127](https://github.com/TanStack/query/blob/main/packages/angular-query-experimental/src/types.ts#L127) diff --git a/docs/framework/angular/reference/type-aliases/definedcreateinfinitequeryresult.md b/docs/framework/angular/reference/type-aliases/definedcreateinfinitequeryresult.md index 77ae3e35ec..3585ab5bf1 100644 --- a/docs/framework/angular/reference/type-aliases/definedcreateinfinitequeryresult.md +++ b/docs/framework/angular/reference/type-aliases/definedcreateinfinitequeryresult.md @@ -3,6 +3,8 @@ id: DefinedCreateInfiniteQueryResult title: DefinedCreateInfiniteQueryResult --- + + # Type Alias: DefinedCreateInfiniteQueryResult\ ```ts @@ -13,6 +15,8 @@ type DefinedCreateInfiniteQueryResult< > = MapToSignals ``` +Defined in: [types.ts:123](https://github.com/TanStack/query/blob/main/packages/angular-query-experimental/src/types.ts#L123) + ## Type Parameters • **TData** = `unknown` @@ -20,7 +24,3 @@ type DefinedCreateInfiniteQueryResult< • **TError** = `DefaultError` • **TDefinedInfiniteQueryObserver** = `DefinedInfiniteQueryObserverResult`\<`TData`, `TError`\> - -## Defined in - -[types.ts:154](https://github.com/TanStack/query/blob/main/packages/angular-query-experimental/src/types.ts#L154) diff --git a/docs/framework/angular/reference/type-aliases/definedcreatequeryresult.md b/docs/framework/angular/reference/type-aliases/definedcreatequeryresult.md index abf57a2b9d..b3588c97c7 100644 --- a/docs/framework/angular/reference/type-aliases/definedcreatequeryresult.md +++ b/docs/framework/angular/reference/type-aliases/definedcreatequeryresult.md @@ -3,6 +3,8 @@ id: DefinedCreateQueryResult title: DefinedCreateQueryResult --- + + # Type Alias: DefinedCreateQueryResult\ ```ts @@ -13,6 +15,8 @@ type DefinedCreateQueryResult = BaseQueryNarrowing< MapToSignals> ``` +Defined in: [types.ts:110](https://github.com/TanStack/query/blob/main/packages/angular-query-experimental/src/types.ts#L110) + ## Type Parameters • **TData** = `unknown` @@ -20,7 +24,3 @@ type DefinedCreateQueryResult = BaseQueryNarrowing< • **TError** = `DefaultError` • **TState** = `DefinedQueryObserverResult`\<`TData`, `TError`\> - -## Defined in - -[types.ts:135](https://github.com/TanStack/query/blob/main/packages/angular-query-experimental/src/types.ts#L135) diff --git a/docs/framework/angular/reference/type-aliases/definedinitialdatainfiniteoptions.md b/docs/framework/angular/reference/type-aliases/definedinitialdatainfiniteoptions.md index 83ec9cc092..16025e3fc7 100644 --- a/docs/framework/angular/reference/type-aliases/definedinitialdatainfiniteoptions.md +++ b/docs/framework/angular/reference/type-aliases/definedinitialdatainfiniteoptions.md @@ -3,6 +3,8 @@ id: DefinedInitialDataInfiniteOptions title: DefinedInitialDataInfiniteOptions --- + + # Type Alias: DefinedInitialDataInfiniteOptions\ ```ts @@ -16,13 +18,14 @@ type DefinedInitialDataInfiniteOptions< TQueryFnData, TError, TData, - TQueryFnData, TQueryKey, TPageParam > & object ``` +Defined in: [infinite-query-options.ts:62](https://github.com/TanStack/query/blob/main/packages/angular-query-experimental/src/infinite-query-options.ts#L62) + ## Type declaration ### initialData @@ -45,7 +48,3 @@ initialData: • **TQueryKey** _extends_ `QueryKey` = `QueryKey` • **TPageParam** = `unknown` - -## Defined in - -[infinite-query-options.ts:66](https://github.com/TanStack/query/blob/main/packages/angular-query-experimental/src/infinite-query-options.ts#L66) diff --git a/docs/framework/angular/reference/type-aliases/definedinitialdataoptions.md b/docs/framework/angular/reference/type-aliases/definedinitialdataoptions.md index 742efded7e..a54c79c787 100644 --- a/docs/framework/angular/reference/type-aliases/definedinitialdataoptions.md +++ b/docs/framework/angular/reference/type-aliases/definedinitialdataoptions.md @@ -3,6 +3,8 @@ id: DefinedInitialDataOptions title: DefinedInitialDataOptions --- + + # Type Alias: DefinedInitialDataOptions\ ```ts @@ -13,6 +15,8 @@ type DefinedInitialDataOptions = Omit< object ``` +Defined in: [query-options.ts:40](https://github.com/TanStack/query/blob/main/packages/angular-query-experimental/src/query-options.ts#L40) + ## Type declaration ### initialData @@ -38,7 +42,3 @@ optional queryFn: QueryFunction; • **TData** = `TQueryFnData` • **TQueryKey** _extends_ `QueryKey` = `QueryKey` - -## Defined in - -[query-options.ts:41](https://github.com/TanStack/query/blob/main/packages/angular-query-experimental/src/query-options.ts#L41) diff --git a/docs/framework/angular/reference/type-aliases/developertoolsfeature.md b/docs/framework/angular/reference/type-aliases/developertoolsfeature.md index ad4c952ff7..b1278a3d2e 100644 --- a/docs/framework/angular/reference/type-aliases/developertoolsfeature.md +++ b/docs/framework/angular/reference/type-aliases/developertoolsfeature.md @@ -3,19 +3,19 @@ id: DeveloperToolsFeature title: DeveloperToolsFeature --- + + # Type Alias: DeveloperToolsFeature ```ts -type DeveloperToolsFeature = QueryFeature<'DeveloperTools'> +type DeveloperToolsFeature = QueryFeature<'Devtools'> ``` +Defined in: [providers.ts:158](https://github.com/TanStack/query/blob/main/packages/angular-query-experimental/src/providers.ts#L158) + A type alias that represents a feature which enables developer tools. The type is used to describe the return value of the `withDevtools` function. ## See -[withDevtools](../../functions/withdevtools.md) - -## Defined in - -[providers.ts:169](https://github.com/TanStack/query/blob/main/packages/angular-query-experimental/src/providers.ts#L169) +withDevtools diff --git a/docs/framework/angular/reference/type-aliases/persistqueryclientfeature.md b/docs/framework/angular/reference/type-aliases/persistqueryclientfeature.md index 18682f7f48..2e923a3c6a 100644 --- a/docs/framework/angular/reference/type-aliases/persistqueryclientfeature.md +++ b/docs/framework/angular/reference/type-aliases/persistqueryclientfeature.md @@ -3,15 +3,15 @@ id: PersistQueryClientFeature title: PersistQueryClientFeature --- + + # Type Alias: PersistQueryClientFeature ```ts type PersistQueryClientFeature = QueryFeature<'PersistQueryClient'> ``` +Defined in: [providers.ts:164](https://github.com/TanStack/query/blob/main/packages/angular-query-experimental/src/providers.ts#L164) + A type alias that represents a feature which enables persistence. The type is used to describe the return value of the `withPersistQueryClient` function. - -## Defined in - -[providers.ts:176](https://github.com/TanStack/query/blob/main/packages/angular-query-experimental/src/providers.ts#L176) diff --git a/docs/framework/angular/reference/type-aliases/queriesoptions.md b/docs/framework/angular/reference/type-aliases/queriesoptions.md index a9b1e1645c..88e9502ce3 100644 --- a/docs/framework/angular/reference/type-aliases/queriesoptions.md +++ b/docs/framework/angular/reference/type-aliases/queriesoptions.md @@ -3,6 +3,8 @@ id: QueriesOptions title: QueriesOptions --- + + # Type Alias: QueriesOptions\ ```ts @@ -35,16 +37,14 @@ type QueriesOptions = TDepth['length'] extends MAXIMUM_DEPTH : QueryObserverOptionsForCreateQueries[] ``` +Defined in: [inject-queries.ts:120](https://github.com/TanStack/query/blob/main/packages/angular-query-experimental/src/inject-queries.ts#L120) + QueriesOptions reducer recursively unwraps function arguments to infer/enforce type param ## Type Parameters • **T** _extends_ `any`[] -• **TResult** _extends_ `any`[] = [] - -• **TDepth** _extends_ `ReadonlyArray`\<`number`\> = [] - -## Defined in +• **TResult** _extends_ `any`[] = \[\] -[inject-queries.ts:121](https://github.com/TanStack/query/blob/main/packages/angular-query-experimental/src/inject-queries.ts#L121) +• **TDepth** _extends_ `ReadonlyArray`\<`number`\> = \[\] diff --git a/docs/framework/angular/reference/type-aliases/queriesresults.md b/docs/framework/angular/reference/type-aliases/queriesresults.md index 687bbb8d2b..b977f67923 100644 --- a/docs/framework/angular/reference/type-aliases/queriesresults.md +++ b/docs/framework/angular/reference/type-aliases/queriesresults.md @@ -3,6 +3,8 @@ id: QueriesResults title: QueriesResults --- + + # Type Alias: QueriesResults\ ```ts @@ -31,16 +33,14 @@ type QueriesResults = TDepth['length'] extends MAXIMUM_DEPTH : QueryObserverResult[] ``` +Defined in: [inject-queries.ts:162](https://github.com/TanStack/query/blob/main/packages/angular-query-experimental/src/inject-queries.ts#L162) + QueriesResults reducer recursively maps type param to results ## Type Parameters • **T** _extends_ `any`[] -• **TResult** _extends_ `any`[] = [] - -• **TDepth** _extends_ `ReadonlyArray`\<`number`\> = [] - -## Defined in +• **TResult** _extends_ `any`[] = \[\] -[inject-queries.ts:164](https://github.com/TanStack/query/blob/main/packages/angular-query-experimental/src/inject-queries.ts#L164) +• **TDepth** _extends_ `ReadonlyArray`\<`number`\> = \[\] diff --git a/docs/framework/angular/reference/type-aliases/queryfeaturekind.md b/docs/framework/angular/reference/type-aliases/queryfeaturekind.md deleted file mode 100644 index 6b45969712..0000000000 --- a/docs/framework/angular/reference/type-aliases/queryfeaturekind.md +++ /dev/null @@ -1,14 +0,0 @@ ---- -id: QueryFeatureKind -title: QueryFeatureKind ---- - -# Type Alias: QueryFeatureKind - -```ts -type QueryFeatureKind = (typeof queryFeatures)[number] -``` - -## Defined in - -[providers.ts:369](https://github.com/TanStack/query/blob/main/packages/angular-query-experimental/src/providers.ts#L369) diff --git a/docs/framework/angular/reference/type-aliases/queryfeatures.md b/docs/framework/angular/reference/type-aliases/queryfeatures.md index cb6a2eb82d..8167e22cf3 100644 --- a/docs/framework/angular/reference/type-aliases/queryfeatures.md +++ b/docs/framework/angular/reference/type-aliases/queryfeatures.md @@ -3,12 +3,16 @@ id: QueryFeatures title: QueryFeatures --- + + # Type Alias: QueryFeatures ```ts type QueryFeatures = DeveloperToolsFeature | PersistQueryClientFeature ``` +Defined in: [providers.ts:173](https://github.com/TanStack/query/blob/main/packages/angular-query-experimental/src/providers.ts#L173) + A type alias that represents all Query features available for use with `provideTanStackQuery`. Features can be enabled by adding special functions to the `provideTanStackQuery` call. See documentation for each symbol to find corresponding function name. See also `provideTanStackQuery` @@ -17,7 +21,3 @@ documentation on how to use those functions. ## See [provideTanStackQuery](../../functions/providetanstackquery.md) - -## Defined in - -[providers.ts:365](https://github.com/TanStack/query/blob/main/packages/angular-query-experimental/src/providers.ts#L365) diff --git a/docs/framework/angular/reference/type-aliases/undefinedinitialdatainfiniteoptions.md b/docs/framework/angular/reference/type-aliases/undefinedinitialdatainfiniteoptions.md index 88c03a01ff..0d33355981 100644 --- a/docs/framework/angular/reference/type-aliases/undefinedinitialdatainfiniteoptions.md +++ b/docs/framework/angular/reference/type-aliases/undefinedinitialdatainfiniteoptions.md @@ -3,6 +3,8 @@ id: UndefinedInitialDataInfiniteOptions title: UndefinedInitialDataInfiniteOptions --- + + # Type Alias: UndefinedInitialDataInfiniteOptions\ ```ts @@ -16,13 +18,14 @@ type UndefinedInitialDataInfiniteOptions< TQueryFnData, TError, TData, - TQueryFnData, TQueryKey, TPageParam > & object ``` +Defined in: [infinite-query-options.ts:13](https://github.com/TanStack/query/blob/main/packages/angular-query-experimental/src/infinite-query-options.ts#L13) + ## Type declaration ### initialData? @@ -44,7 +47,3 @@ optional initialData: • **TQueryKey** _extends_ `QueryKey` = `QueryKey` • **TPageParam** = `unknown` - -## Defined in - -[infinite-query-options.ts:12](https://github.com/TanStack/query/blob/main/packages/angular-query-experimental/src/infinite-query-options.ts#L12) diff --git a/docs/framework/angular/reference/type-aliases/undefinedinitialdataoptions.md b/docs/framework/angular/reference/type-aliases/undefinedinitialdataoptions.md index ec360cc9bd..3f5a06db66 100644 --- a/docs/framework/angular/reference/type-aliases/undefinedinitialdataoptions.md +++ b/docs/framework/angular/reference/type-aliases/undefinedinitialdataoptions.md @@ -3,6 +3,8 @@ id: UndefinedInitialDataOptions title: UndefinedInitialDataOptions --- + + # Type Alias: UndefinedInitialDataOptions\ ```ts @@ -10,6 +12,8 @@ type UndefinedInitialDataOptions = CreateQueryOptions & object ``` +Defined in: [query-options.ts:13](https://github.com/TanStack/query/blob/main/packages/angular-query-experimental/src/query-options.ts#L13) + ## Type declaration ### initialData? @@ -29,7 +33,3 @@ optional initialData: • **TData** = `TQueryFnData` • **TQueryKey** _extends_ `QueryKey` = `QueryKey` - -## Defined in - -[query-options.ts:12](https://github.com/TanStack/query/blob/main/packages/angular-query-experimental/src/query-options.ts#L12) diff --git a/docs/framework/angular/reference/type-aliases/unusedskiptokeninfiniteoptions.md b/docs/framework/angular/reference/type-aliases/unusedskiptokeninfiniteoptions.md index c03412d5cb..9634febe87 100644 --- a/docs/framework/angular/reference/type-aliases/unusedskiptokeninfiniteoptions.md +++ b/docs/framework/angular/reference/type-aliases/unusedskiptokeninfiniteoptions.md @@ -3,6 +3,8 @@ id: UnusedSkipTokenInfiniteOptions title: UnusedSkipTokenInfiniteOptions --- + + # Type Alias: UnusedSkipTokenInfiniteOptions\ ```ts @@ -17,7 +19,6 @@ type UnusedSkipTokenInfiniteOptions< TQueryFnData, TError, TData, - TQueryFnData, TQueryKey, TPageParam >, @@ -26,12 +27,14 @@ type UnusedSkipTokenInfiniteOptions< object ``` +Defined in: [infinite-query-options.ts:34](https://github.com/TanStack/query/blob/main/packages/angular-query-experimental/src/infinite-query-options.ts#L34) + ## Type declaration ### queryFn? ```ts -optional queryFn: Exclude["queryFn"], SkipToken | undefined>; +optional queryFn: Exclude["queryFn"], SkipToken | undefined>; ``` ## Type Parameters @@ -45,7 +48,3 @@ optional queryFn: Exclude + # Type Alias: UnusedSkipTokenOptions\ ```ts @@ -13,6 +15,8 @@ type UnusedSkipTokenOptions = OmitKeyof< object ``` +Defined in: [query-options.ts:25](https://github.com/TanStack/query/blob/main/packages/angular-query-experimental/src/query-options.ts#L25) + ## Type declaration ### queryFn? @@ -30,7 +34,3 @@ optional queryFn: Exclude injectDevtoolsPanel(this.devToolsOptions, { injector: this.injector, diff --git a/examples/angular/infinite-query-with-max-pages/src/app/app.config.ts b/examples/angular/infinite-query-with-max-pages/src/app/app.config.ts index bd9b7a03d1..06854c4a7d 100644 --- a/examples/angular/infinite-query-with-max-pages/src/app/app.config.ts +++ b/examples/angular/infinite-query-with-max-pages/src/app/app.config.ts @@ -6,8 +6,8 @@ import { import { QueryClient, provideTanStackQuery, - withDevtools, } from '@tanstack/angular-query-experimental' +import { withDevtools } from '@tanstack/angular-query-experimental/devtools' import { projectsMockInterceptor } from './api/projects-mock.interceptor' import type { ApplicationConfig } from '@angular/core' diff --git a/examples/angular/optimistic-updates/src/app/app.config.ts b/examples/angular/optimistic-updates/src/app/app.config.ts index 65a84a0c25..b9b2b6c36f 100644 --- a/examples/angular/optimistic-updates/src/app/app.config.ts +++ b/examples/angular/optimistic-updates/src/app/app.config.ts @@ -6,8 +6,8 @@ import { import { QueryClient, provideTanStackQuery, - withDevtools, } from '@tanstack/angular-query-experimental' +import { withDevtools } from '@tanstack/angular-query-experimental/devtools' import { mockInterceptor } from './interceptor/mock-api.interceptor' import type { ApplicationConfig } from '@angular/core' diff --git a/examples/angular/pagination/src/app/app.config.ts b/examples/angular/pagination/src/app/app.config.ts index 919a81f92c..dc3189ba84 100644 --- a/examples/angular/pagination/src/app/app.config.ts +++ b/examples/angular/pagination/src/app/app.config.ts @@ -6,8 +6,8 @@ import { import { QueryClient, provideTanStackQuery, - withDevtools, } from '@tanstack/angular-query-experimental' +import { withDevtools } from '@tanstack/angular-query-experimental/devtools' import { projectsMockInterceptor } from './api/projects-mock.interceptor' import type { ApplicationConfig } from '@angular/core' diff --git a/examples/angular/query-options-from-a-service/src/app/app.config.ts b/examples/angular/query-options-from-a-service/src/app/app.config.ts index 7dd1d37236..dd6675f997 100644 --- a/examples/angular/query-options-from-a-service/src/app/app.config.ts +++ b/examples/angular/query-options-from-a-service/src/app/app.config.ts @@ -3,9 +3,9 @@ import { provideRouter, withComponentInputBinding } from '@angular/router' import { QueryClient, provideTanStackQuery, - withDevtools, } from '@tanstack/angular-query-experimental' +import { withDevtools } from '@tanstack/angular-query-experimental/devtools' import { routes } from './app.routes' import type { ApplicationConfig } from '@angular/core' diff --git a/examples/angular/router/src/app/app.config.ts b/examples/angular/router/src/app/app.config.ts index de3234392a..3fbec800b1 100644 --- a/examples/angular/router/src/app/app.config.ts +++ b/examples/angular/router/src/app/app.config.ts @@ -3,9 +3,9 @@ import { provideRouter, withComponentInputBinding } from '@angular/router' import { QueryClient, provideTanStackQuery, - withDevtools, } from '@tanstack/angular-query-experimental' +import { withDevtools } from '@tanstack/angular-query-experimental/devtools' import { routes } from './app.routes' import type { ApplicationConfig } from '@angular/core' diff --git a/examples/angular/rxjs/src/app/app.config.ts b/examples/angular/rxjs/src/app/app.config.ts index 36f8212a03..27eb15a53b 100644 --- a/examples/angular/rxjs/src/app/app.config.ts +++ b/examples/angular/rxjs/src/app/app.config.ts @@ -6,8 +6,8 @@ import { import { QueryClient, provideTanStackQuery, - withDevtools, } from '@tanstack/angular-query-experimental' +import { withDevtools } from '@tanstack/angular-query-experimental/devtools' import { autocompleteMockInterceptor } from './api/autocomplete-mock.interceptor' import type { ApplicationConfig } from '@angular/core' diff --git a/examples/angular/simple/src/app/app.config.ts b/examples/angular/simple/src/app/app.config.ts index c4b9ca045e..9c7eda2597 100644 --- a/examples/angular/simple/src/app/app.config.ts +++ b/examples/angular/simple/src/app/app.config.ts @@ -2,8 +2,8 @@ import { provideHttpClient, withFetch } from '@angular/common/http' import { QueryClient, provideTanStackQuery, - withDevtools, } from '@tanstack/angular-query-experimental' +import { withDevtools } from '@tanstack/angular-query-experimental/devtools' import type { ApplicationConfig } from '@angular/core' export const appConfig: ApplicationConfig = { diff --git a/knip.json b/knip.json index bf142253e8..963a8a723d 100644 --- a/knip.json +++ b/knip.json @@ -25,6 +25,12 @@ "packages/vue-query": { "ignore": ["**/__mocks__/**"], "ignoreDependencies": ["vue2", "vue2.7"] + }, + "packages/angular-query-experimental": { + "entry": [ + "src/devtools/production/index.ts", + "src/devtools-panel/production/index.ts" + ] } } } diff --git a/package.json b/package.json index acce0acc68..de25e5c151 100644 --- a/package.json +++ b/package.json @@ -79,7 +79,6 @@ }, "pnpm": { "overrides": { - "@tanstack/angular-query-devtools-experimental": "workspace:*", "@tanstack/angular-query-experimental": "workspace:*", "@tanstack/eslint-plugin-query": "workspace:*", "@tanstack/query-async-storage-persister": "workspace:*", diff --git a/packages/angular-query-devtools-experimental/.attw.json b/packages/angular-query-devtools-experimental/.attw.json deleted file mode 100644 index 864f618c22..0000000000 --- a/packages/angular-query-devtools-experimental/.attw.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "ignoreRules": [ - "cjs-resolves-to-esm", - "internal-resolution-error", - "no-resolution" - ] -} diff --git a/packages/angular-query-devtools-experimental/eslint.config.js b/packages/angular-query-devtools-experimental/eslint.config.js deleted file mode 100644 index 131737bfa0..0000000000 --- a/packages/angular-query-devtools-experimental/eslint.config.js +++ /dev/null @@ -1,17 +0,0 @@ -// @ts-check - -import pluginJsdoc from 'eslint-plugin-jsdoc' -import rootConfig from './root.eslint.config.js' - -export default [ - ...rootConfig, - pluginJsdoc.configs['flat/recommended-typescript'], - { - rules: { - 'jsdoc/require-hyphen-before-param-description': 1, - 'jsdoc/sort-tags': 1, - 'jsdoc/require-throws': 1, - 'jsdoc/check-tag-names': ['warn'], - }, - }, -] diff --git a/packages/angular-query-devtools-experimental/package.json b/packages/angular-query-devtools-experimental/package.json deleted file mode 100644 index 55a0784528..0000000000 --- a/packages/angular-query-devtools-experimental/package.json +++ /dev/null @@ -1,68 +0,0 @@ -{ - "name": "@tanstack/angular-query-devtools-experimental", - "version": "5.87.5", - "description": "Developer tools to interact with and visualize the TanStack/angular-query cache", - "author": "Arnoud de Vries", - "license": "MIT", - "repository": { - "type": "git", - "url": "git+https://github.com/TanStack/query.git", - "directory": "packages/angular-query-devtools-experimental" - }, - "homepage": "https://tanstack.com/query", - "funding": { - "type": "github", - "url": "https://github.com/sponsors/tannerlinsley" - }, - "scripts": { - "clean": "premove ./build ./coverage ./dist-ts", - "compile": "tsc --build", - "test:eslint": "eslint ./src", - "test:types": "npm-run-all --serial test:types:*", - "test:types:ts51": "node ../../node_modules/typescript51/lib/tsc.js --build", - "test:types:ts52": "node ../../node_modules/typescript52/lib/tsc.js --build", - "test:types:ts53": "node ../../node_modules/typescript53/lib/tsc.js --build", - "test:types:ts54": "node ../../node_modules/typescript54/lib/tsc.js --build", - "test:types:ts55": "node ../../node_modules/typescript55/lib/tsc.js --build", - "test:types:ts56": "node ../../node_modules/typescript56/lib/tsc.js --build", - "test:types:ts57": "node ../../node_modules/typescript57/lib/tsc.js --build", - "test:types:tscurrent": "tsc --build", - "test:build": "publint --strict && attw --pack", - "build": "pnpm build:tsup", - "build:tsup": "tsup --tsconfig tsconfig.prod.json" - }, - "type": "module", - "types": "build/index.d.ts", - "module": "build/index.mjs", - "exports": { - ".": { - "@tanstack/custom-condition": "./src/index.ts", - "types": "./build/index.d.ts", - "default": "./build/index.mjs" - }, - "./package.json": { - "default": "./package.json" - } - }, - "sideEffects": false, - "files": [ - "build", - "src", - "!src/__tests__" - ], - "dependencies": { - "@tanstack/query-devtools": "workspace:*" - }, - "devDependencies": { - "@angular/core": "^20.0.0", - "@angular/platform-browser": "^20.0.0", - "@tanstack/angular-query-experimental": "workspace:*", - "eslint-plugin-jsdoc": "^50.5.0", - "npm-run-all2": "^5.0.0" - }, - "peerDependencies": { - "@angular/common": ">=16.0.0", - "@angular/core": ">=16.0.0", - "@tanstack/angular-query-experimental": "workspace:^" - } -} diff --git a/packages/angular-query-devtools-experimental/root.eslint.config.js b/packages/angular-query-devtools-experimental/root.eslint.config.js deleted file mode 120000 index 35dedbe5a4..0000000000 --- a/packages/angular-query-devtools-experimental/root.eslint.config.js +++ /dev/null @@ -1 +0,0 @@ -../../eslint.config.js \ No newline at end of file diff --git a/packages/angular-query-devtools-experimental/src/index.ts b/packages/angular-query-devtools-experimental/src/index.ts deleted file mode 100644 index 82c19d6916..0000000000 --- a/packages/angular-query-devtools-experimental/src/index.ts +++ /dev/null @@ -1 +0,0 @@ -export * from './inject-devtools-panel' diff --git a/packages/angular-query-devtools-experimental/src/inject-devtools-panel.ts b/packages/angular-query-devtools-experimental/src/inject-devtools-panel.ts deleted file mode 100644 index 0fdff618fc..0000000000 --- a/packages/angular-query-devtools-experimental/src/inject-devtools-panel.ts +++ /dev/null @@ -1,150 +0,0 @@ -import { - DestroyRef, - Injector, - PLATFORM_ID, - assertInInjectionContext, - computed, - effect, - inject, - runInInjectionContext, - untracked, -} from '@angular/core' -import { TanstackQueryDevtoolsPanel } from '@tanstack/query-devtools' -import { - QueryClient, - onlineManager, -} from '@tanstack/angular-query-experimental' -import { isPlatformBrowser } from '@angular/common' -import type { ElementRef } from '@angular/core' -import type { DevtoolsErrorType } from '@tanstack/query-devtools' - -export interface InjectDevtoolsPanelOptions { - /** - * The `Injector` in which to create the devtools panel. - * - * If this is not provided, the current injection context will be used instead (via `inject`). - */ - injector?: Injector -} - -/** - * Inject a TanStack Query devtools panel and render it in the DOM. - * - * Devtools panel allows programmatic control over the devtools, for example if you want to render - * the devtools as part of your own devtools. - * - * Consider `withDevtools` instead if you don't need this. - * @param injectDevtoolsPanelFn - A function that returns devtools panel options. - * @param options - Additional configuration - * @returns DevtoolsPanelRef - * @see https://tanstack.com/query/v5/docs/framework/angular/devtools - */ -export function injectDevtoolsPanel( - injectDevtoolsPanelFn: () => DevtoolsPanelOptions, - options?: InjectDevtoolsPanelOptions, -): DevtoolsPanelRef { - !options?.injector && assertInInjectionContext(injectDevtoolsPanel) - const currentInjector = options?.injector ?? inject(Injector) - - return runInInjectionContext(currentInjector, () => { - const destroyRef = inject(DestroyRef) - const isBrowser = isPlatformBrowser(inject(PLATFORM_ID)) - const injectedClient = inject(QueryClient, { optional: true }) - - const queryOptions = computed(injectDevtoolsPanelFn) - let devtools: TanstackQueryDevtoolsPanel | null = null - - const destroy = () => { - devtools?.unmount() - devtools = null - } - - if (!isBrowser) - return { - destroy, - } - - effect(() => { - const { - client = injectedClient, - errorTypes = [], - styleNonce, - shadowDOMTarget, - onClose, - hostElement, - } = queryOptions() - - untracked(() => { - if (!client) throw new Error('No QueryClient found') - if (!devtools && hostElement) { - devtools = new TanstackQueryDevtoolsPanel({ - client, - queryFlavor: 'Angular Query', - version: '5', - buttonPosition: 'bottom-left', - position: 'bottom', - initialIsOpen: true, - errorTypes, - styleNonce, - shadowDOMTarget, - onClose, - onlineManager, - }) - devtools.mount(hostElement.nativeElement) - } else if (devtools && hostElement) { - devtools.setClient(client) - devtools.setErrorTypes(errorTypes) - onClose && devtools.setOnClose(onClose) - } else if (devtools && !hostElement) { - destroy() - } - }) - }) - - destroyRef.onDestroy(destroy) - - return { - destroy, - } - }) -} - -/** - * A devtools panel, which can be manually destroyed. - */ -export interface DevtoolsPanelRef { - /** - * Destroy the panel, removing it from the DOM and stops listening to signal changes. - */ - destroy: () => void -} - -export interface DevtoolsPanelOptions { - /** - * Custom instance of QueryClient - */ - client?: QueryClient - /** - * Use this so you can define custom errors that can be shown in the devtools. - */ - errorTypes?: Array - /** - * 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. - */ - styleNonce?: string - /** - * Use this so you can attach the devtool's styles to specific element in the DOM. - */ - shadowDOMTarget?: ShadowRoot - - /** - * Callback function that is called when the devtools panel is closed - */ - onClose?: () => unknown - - /** - * Element where to render the devtools panel. When set to undefined or null, the devtools panel will not be created, or destroyed if existing. - * If changed from undefined to a ElementRef, the devtools panel will be created. - */ - hostElement?: ElementRef -} diff --git a/packages/angular-query-devtools-experimental/src/test-setup.ts b/packages/angular-query-devtools-experimental/src/test-setup.ts deleted file mode 100644 index ef53141bdc..0000000000 --- a/packages/angular-query-devtools-experimental/src/test-setup.ts +++ /dev/null @@ -1,7 +0,0 @@ -import { getTestBed } from '@angular/core/testing' -import { - BrowserTestingModule, - platformBrowserTesting, -} from '@angular/platform-browser/testing' - -getTestBed().initTestEnvironment(BrowserTestingModule, platformBrowserTesting()) diff --git a/packages/angular-query-devtools-experimental/tsconfig.json b/packages/angular-query-devtools-experimental/tsconfig.json deleted file mode 100644 index 59bdb26584..0000000000 --- a/packages/angular-query-devtools-experimental/tsconfig.json +++ /dev/null @@ -1,17 +0,0 @@ -{ - "extends": "../../tsconfig.json", - "compilerOptions": { - "outDir": "./dist-ts", - "rootDir": ".", - "noImplicitOverride": true, - "noPropertyAccessFromIndexSignature": true, - "noFallthroughCasesInSwitch": true, - "useDefineForClassFields": false, - "target": "ES2022" - }, - "include": ["src", "*.config.*", "package.json"], - "references": [ - { "path": "../query-devtools" }, - { "path": "../angular-query-experimental" } - ] -} diff --git a/packages/angular-query-devtools-experimental/tsconfig.prod.json b/packages/angular-query-devtools-experimental/tsconfig.prod.json deleted file mode 100644 index 0f4c92da06..0000000000 --- a/packages/angular-query-devtools-experimental/tsconfig.prod.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "extends": "./tsconfig.json", - "compilerOptions": { - "incremental": false, - "composite": false, - "rootDir": "../../" - } -} diff --git a/packages/angular-query-devtools-experimental/tsup.config.ts b/packages/angular-query-devtools-experimental/tsup.config.ts deleted file mode 100644 index a1e9d23c1c..0000000000 --- a/packages/angular-query-devtools-experimental/tsup.config.ts +++ /dev/null @@ -1,13 +0,0 @@ -import { defineConfig } from 'tsup' - -export default defineConfig({ - entry: ['src/index.ts'], - sourcemap: true, - clean: true, - format: ['esm'], - dts: true, - outDir: 'build', - outExtension({ format }) { - return format === 'esm' ? { js: '.mjs' } : { js: '.js' } - }, -}) diff --git a/packages/angular-query-devtools-experimental/vite.config.ts b/packages/angular-query-devtools-experimental/vite.config.ts deleted file mode 100644 index 25fdba1056..0000000000 --- a/packages/angular-query-devtools-experimental/vite.config.ts +++ /dev/null @@ -1,28 +0,0 @@ -import { defineConfig } from 'vitest/config' - -import packageJson from './package.json' - -export default defineConfig({ - // fix from https://github.com/vitest-dev/vitest/issues/6992#issuecomment-2509408660 - resolve: { - conditions: ['@tanstack/custom-condition'], - }, - environments: { - ssr: { - resolve: { - conditions: ['@tanstack/custom-condition'], - }, - }, - }, - test: { - name: packageJson.name, - dir: './src', - watch: false, - environment: 'jsdom', - setupFiles: ['src/test-setup.ts'], - coverage: { enabled: true, provider: 'istanbul', include: ['src/**/*'] }, - typecheck: { enabled: true }, - globals: true, - restoreMocks: true, - }, -}) diff --git a/packages/angular-query-experimental/eslint.config.js b/packages/angular-query-experimental/eslint.config.js index f3b2546b02..425162bf51 100644 --- a/packages/angular-query-experimental/eslint.config.js +++ b/packages/angular-query-experimental/eslint.config.js @@ -20,13 +20,7 @@ export default [ 'jsdoc/require-hyphen-before-param-description': 1, 'jsdoc/sort-tags': 1, 'jsdoc/require-throws': 1, - 'jsdoc/check-tag-names': [ - 'warn', - { - // Not compatible with Api Extractor @public - typed: false, - }, - ], + 'jsdoc/check-tag-names': ['warn'], }, }, { diff --git a/packages/angular-query-experimental/package.json b/packages/angular-query-experimental/package.json index 2ebff1e4c4..066abd0b3b 100644 --- a/packages/angular-query-experimental/package.json +++ b/packages/angular-query-experimental/package.json @@ -55,11 +55,29 @@ "types": "./dist/index.d.ts", "default": "./dist/index.mjs" }, + "./package.json": "./package.json", "./inject-queries-experimental": { "types": "./dist/inject-queries-experimental/index.d.ts", "default": "./dist/inject-queries-experimental/index.mjs" }, - "./package.json": "./package.json" + "./devtools": { + "types": "./dist/devtools/index.d.ts", + "development": "./dist/devtools/index.mjs", + "default": "./dist/devtools/stub.mjs" + }, + "./devtools/production": { + "types": "./dist/devtools/production/index.d.ts", + "default": "./dist/devtools/index.mjs" + }, + "./devtools-panel": { + "types": "./dist/devtools-panel/index.d.ts", + "development": "./dist/devtools-panel/index.mjs", + "default": "./dist/devtools-panel/stub.mjs" + }, + "./devtools-panel/production": { + "types": "./dist/devtools-panel/production/index.d.ts", + "default": "./dist/devtools-panel/index.mjs" + } }, "sideEffects": false, "files": [ @@ -68,8 +86,7 @@ "**/*.mjs.map" ], "dependencies": { - "@tanstack/query-core": "workspace:*", - "@tanstack/query-devtools": "workspace:*" + "@tanstack/query-core": "workspace:*" }, "devDependencies": { "@angular/common": "^20.0.0", @@ -83,6 +100,9 @@ "vite-plugin-externalize-deps": "^0.9.0", "vite-tsconfig-paths": "^5.1.4" }, + "optionalDependencies": { + "@tanstack/query-devtools": "workspace:*" + }, "peerDependencies": { "@angular/common": ">=16.0.0", "@angular/core": ">=16.0.0" diff --git a/packages/angular-query-devtools-experimental/src/__tests__/inject-devtools-panel.test.ts b/packages/angular-query-experimental/src/__tests__/inject-devtools-panel.test.ts similarity index 80% rename from packages/angular-query-devtools-experimental/src/__tests__/inject-devtools-panel.test.ts rename to packages/angular-query-experimental/src/__tests__/inject-devtools-panel.test.ts index 367bb708f5..7368deb32e 100644 --- a/packages/angular-query-devtools-experimental/src/__tests__/inject-devtools-panel.test.ts +++ b/packages/angular-query-experimental/src/__tests__/inject-devtools-panel.test.ts @@ -4,12 +4,10 @@ import { signal, } from '@angular/core' import { TestBed } from '@angular/core/testing' -import { - QueryClient, - provideTanStackQuery, -} from '@tanstack/angular-query-experimental' import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest' -import { injectDevtoolsPanel } from '../inject-devtools-panel' +import { QueryClient } from '@tanstack/query-core' +import { provideTanStackQuery } from '../providers' +import { injectDevtoolsPanel } from '../devtools-panel' const mockDevtoolsPanelInstance = { mount: vi.fn(), @@ -33,6 +31,12 @@ describe('injectDevtoolsPanel', () => { let queryClient: QueryClient let mockElementRef: ElementRef + const waitForDevtoolsToBeCreated = async () => { + await vi.waitFor(() => { + expect(mocks.mockTanstackQueryDevtoolsPanel).toHaveBeenCalledTimes(1) + }) + } + beforeEach(() => { queryClient = new QueryClient() mockElementRef = new ElementRef(document.createElement('div')) @@ -61,7 +65,7 @@ describe('injectDevtoolsPanel', () => { }) }) - it('should initialize TanstackQueryDevtoolsPanel', () => { + it('should initialize TanstackQueryDevtoolsPanel', async () => { TestBed.runInInjectionContext(() => { injectDevtoolsPanel(() => ({ hostElement: TestBed.inject(ElementRef), @@ -70,10 +74,12 @@ describe('injectDevtoolsPanel', () => { TestBed.tick() - expect(mocks.mockTanstackQueryDevtoolsPanel).toHaveBeenCalledTimes(1) + await waitForDevtoolsToBeCreated() + + expect(mockDevtoolsPanelInstance.mount).toHaveBeenCalledTimes(1) }) - it('should destroy TanstackQueryDevtoolsPanel', () => { + it('should destroy TanstackQueryDevtoolsPanel', async () => { const result = TestBed.runInInjectionContext(() => { return injectDevtoolsPanel(() => ({ hostElement: TestBed.inject(ElementRef), @@ -82,12 +88,14 @@ describe('injectDevtoolsPanel', () => { TestBed.tick() + await waitForDevtoolsToBeCreated() + result.destroy() expect(mockDevtoolsPanelInstance.unmount).toHaveBeenCalledTimes(1) }) - it('should destroy TanstackQueryDevtoolsPanel when hostElement is removed', () => { + it('should destroy TanstackQueryDevtoolsPanel when hostElement is removed', async () => { const hostElement = signal(mockElementRef) TestBed.runInInjectionContext(() => { @@ -98,6 +106,8 @@ describe('injectDevtoolsPanel', () => { TestBed.tick() + await waitForDevtoolsToBeCreated() + expect(mockDevtoolsPanelInstance.unmount).toHaveBeenCalledTimes(0) hostElement.set(null as unknown as ElementRef) @@ -107,7 +117,7 @@ describe('injectDevtoolsPanel', () => { expect(mockDevtoolsPanelInstance.unmount).toHaveBeenCalledTimes(1) }) - it('should update client', () => { + it('should update client', async () => { const client = signal(new QueryClient()) TestBed.runInInjectionContext(() => { @@ -119,6 +129,8 @@ describe('injectDevtoolsPanel', () => { TestBed.tick() + await waitForDevtoolsToBeCreated() + expect(mockDevtoolsPanelInstance.setClient).toHaveBeenCalledTimes(0) client.set(new QueryClient()) @@ -128,7 +140,7 @@ describe('injectDevtoolsPanel', () => { expect(mockDevtoolsPanelInstance.setClient).toHaveBeenCalledTimes(1) }) - it('should update error types', () => { + it('should update error types', async () => { const errorTypes = signal([]) TestBed.runInInjectionContext(() => { @@ -140,6 +152,8 @@ describe('injectDevtoolsPanel', () => { TestBed.tick() + await waitForDevtoolsToBeCreated() + expect(mockDevtoolsPanelInstance.setErrorTypes).toHaveBeenCalledTimes(0) errorTypes.set([]) @@ -149,7 +163,7 @@ describe('injectDevtoolsPanel', () => { expect(mockDevtoolsPanelInstance.setErrorTypes).toHaveBeenCalledTimes(1) }) - it('should update onclose', () => { + it('should update onclose', async () => { const functionA = () => {} const functionB = () => {} @@ -164,6 +178,8 @@ describe('injectDevtoolsPanel', () => { TestBed.tick() + await waitForDevtoolsToBeCreated() + expect(mockDevtoolsPanelInstance.setOnClose).toHaveBeenCalledTimes(0) onClose.set(functionB) diff --git a/packages/angular-query-experimental/src/__tests__/providers.test.ts b/packages/angular-query-experimental/src/__tests__/providers.test.ts deleted file mode 100644 index 3a41f03fc2..0000000000 --- a/packages/angular-query-experimental/src/__tests__/providers.test.ts +++ /dev/null @@ -1,321 +0,0 @@ -import { afterEach, beforeEach, describe, expect, it, test, vi } from 'vitest' -import { QueryClient } from '@tanstack/query-core' -import { TestBed } from '@angular/core/testing' -import { - ENVIRONMENT_INITIALIZER, - provideZonelessChangeDetection, - signal, -} from '@angular/core' -import { isDevMode } from '../util/is-dev-mode/is-dev-mode' -import { provideTanStackQuery, withDevtools } from '../providers' -import type { DevtoolsOptions } from '../providers' -import type { Mock } from 'vitest' -import type { - DevtoolsButtonPosition, - DevtoolsErrorType, - DevtoolsPosition, -} from '@tanstack/query-devtools' - -vi.mock('../util/is-dev-mode/is-dev-mode', () => ({ - isDevMode: vi.fn(), -})) - -const mockDevtoolsInstance = { - mount: vi.fn(), - unmount: vi.fn(), - setClient: vi.fn(), - setPosition: vi.fn(), - setErrorTypes: vi.fn(), - setButtonPosition: vi.fn(), - setInitialIsOpen: vi.fn(), -} - -const mockTanstackQueryDevtools = vi.fn(() => mockDevtoolsInstance) - -vi.mock('@tanstack/query-devtools', () => ({ - TanstackQueryDevtools: mockTanstackQueryDevtools, -})) - -describe('withDevtools feature', () => { - let isDevModeMock: Mock - - beforeEach(() => { - vi.useFakeTimers() - isDevModeMock = isDevMode as Mock - }) - - afterEach(() => { - vi.restoreAllMocks() - }) - - test.each([ - { - description: - 'should provide developer tools in development mode by default', - isDevModeValue: true, - expectedCalled: true, - }, - { - description: - 'should not provide developer tools in production mode by default', - isDevModeValue: false, - expectedCalled: false, - }, - { - description: `should provide developer tools in development mode when 'loadDeveloperTools' is set to 'auto'`, - isDevModeValue: true, - loadDevtools: 'auto', - expectedCalled: true, - }, - { - description: `should not provide developer tools in production mode when 'loadDeveloperTools' is set to 'auto'`, - isDevModeValue: false, - loadDevtools: 'auto', - expectedCalled: false, - }, - { - description: - "should provide developer tools in development mode when 'loadDevtools' is set to true", - isDevModeValue: true, - loadDevtools: true, - expectedCalled: true, - }, - { - description: - "should provide developer tools in production mode when 'loadDevtools' is set to true", - isDevModeValue: false, - loadDevtools: true, - expectedCalled: true, - }, - { - description: - "should not provide developer tools in development mode when 'loadDevtools' is set to false", - isDevModeValue: true, - loadDevtools: false, - expectedCalled: false, - }, - { - description: - "should not provide developer tools in production mode when 'loadDevtools' is set to false", - isDevModeValue: false, - loadDevtools: false, - expectedCalled: false, - }, - ])( - '$description', - async ({ isDevModeValue, loadDevtools, expectedCalled }) => { - isDevModeMock.mockReturnValue(isDevModeValue) - - const providers = [ - provideZonelessChangeDetection(), - provideTanStackQuery( - new QueryClient(), - loadDevtools !== undefined - ? withDevtools( - () => - ({ - loadDevtools, - }) as DevtoolsOptions, - ) - : withDevtools(), - ), - ] - - TestBed.configureTestingModule({ - providers, - }) - - TestBed.inject(ENVIRONMENT_INITIALIZER) - await vi.advanceTimersByTimeAsync(0) - - if (expectedCalled) { - expect(mockTanstackQueryDevtools).toHaveBeenCalled() - } else { - expect(mockTanstackQueryDevtools).not.toHaveBeenCalled() - } - }, - ) - - it('should update error types', async () => { - const errorTypes = signal([] as Array) - - TestBed.configureTestingModule({ - providers: [ - provideZonelessChangeDetection(), - provideTanStackQuery( - new QueryClient(), - withDevtools(() => ({ - loadDevtools: true, - errorTypes: errorTypes(), - })), - ), - ], - }) - - TestBed.inject(ENVIRONMENT_INITIALIZER) - await vi.advanceTimersByTimeAsync(0) - - TestBed.tick() - - expect(mockDevtoolsInstance.setErrorTypes).toHaveBeenCalledTimes(0) - - errorTypes.set([ - { - name: '', - initializer: () => new Error(), - }, - ]) - - TestBed.tick() - - expect(mockDevtoolsInstance.setErrorTypes).toHaveBeenCalledTimes(1) - }) - - it('should update client', async () => { - const client = signal(new QueryClient()) - - TestBed.configureTestingModule({ - providers: [ - provideZonelessChangeDetection(), - provideTanStackQuery( - new QueryClient(), - withDevtools(() => ({ - loadDevtools: true, - client: client(), - })), - ), - ], - }) - - TestBed.inject(ENVIRONMENT_INITIALIZER) - await vi.advanceTimersByTimeAsync(0) - - TestBed.tick() - - expect(mockDevtoolsInstance.setClient).toHaveBeenCalledTimes(0) - - client.set(new QueryClient()) - - TestBed.tick() - - expect(mockDevtoolsInstance.setClient).toHaveBeenCalledTimes(1) - }) - - it('should update position', async () => { - const position = signal('top') - - TestBed.configureTestingModule({ - providers: [ - provideZonelessChangeDetection(), - provideTanStackQuery( - new QueryClient(), - withDevtools(() => ({ - loadDevtools: true, - position: position(), - })), - ), - ], - }) - - TestBed.inject(ENVIRONMENT_INITIALIZER) - await vi.advanceTimersByTimeAsync(0) - - TestBed.tick() - - expect(mockDevtoolsInstance.setPosition).toHaveBeenCalledTimes(0) - - position.set('left') - - TestBed.tick() - - expect(mockDevtoolsInstance.setPosition).toHaveBeenCalledTimes(1) - }) - - it('should update button position', async () => { - const buttonPosition = signal('bottom-left') - - TestBed.configureTestingModule({ - providers: [ - provideZonelessChangeDetection(), - provideTanStackQuery( - new QueryClient(), - withDevtools(() => ({ - loadDevtools: true, - buttonPosition: buttonPosition(), - })), - ), - ], - }) - - TestBed.inject(ENVIRONMENT_INITIALIZER) - await vi.advanceTimersByTimeAsync(0) - - TestBed.tick() - - expect(mockDevtoolsInstance.setButtonPosition).toHaveBeenCalledTimes(0) - - buttonPosition.set('bottom-right') - - TestBed.tick() - - expect(mockDevtoolsInstance.setButtonPosition).toHaveBeenCalledTimes(1) - }) - - it('should update initialIsOpen', async () => { - const initialIsOpen = signal(false) - - TestBed.configureTestingModule({ - providers: [ - provideZonelessChangeDetection(), - provideTanStackQuery( - new QueryClient(), - withDevtools(() => ({ - loadDevtools: true, - initialIsOpen: initialIsOpen(), - })), - ), - ], - }) - - TestBed.inject(ENVIRONMENT_INITIALIZER) - await vi.advanceTimersByTimeAsync(0) - - TestBed.tick() - - expect(mockDevtoolsInstance.setInitialIsOpen).toHaveBeenCalledTimes(0) - - initialIsOpen.set(true) - - TestBed.tick() - - expect(mockDevtoolsInstance.setInitialIsOpen).toHaveBeenCalledTimes(1) - }) - - it('should destroy devtools', async () => { - const loadDevtools = signal(true) - - TestBed.configureTestingModule({ - providers: [ - provideZonelessChangeDetection(), - provideTanStackQuery( - new QueryClient(), - withDevtools(() => ({ - loadDevtools: loadDevtools(), - })), - ), - ], - }) - - TestBed.inject(ENVIRONMENT_INITIALIZER) - await vi.advanceTimersByTimeAsync(0) - - expect(mockDevtoolsInstance.mount).toHaveBeenCalledTimes(1) - expect(mockDevtoolsInstance.unmount).toHaveBeenCalledTimes(0) - - loadDevtools.set(false) - - TestBed.tick() - - expect(mockDevtoolsInstance.unmount).toHaveBeenCalledTimes(1) - }) -}) diff --git a/packages/angular-query-experimental/src/__tests__/with-devtools.test.ts b/packages/angular-query-experimental/src/__tests__/with-devtools.test.ts new file mode 100644 index 0000000000..7091f5a0c2 --- /dev/null +++ b/packages/angular-query-experimental/src/__tests__/with-devtools.test.ts @@ -0,0 +1,603 @@ +import { afterEach, beforeEach, describe, expect, it, test, vi } from 'vitest' +import { QueryClient } from '@tanstack/query-core' +import { TestBed } from '@angular/core/testing' +import { + ENVIRONMENT_INITIALIZER, + EnvironmentInjector, + InjectionToken, + PLATFORM_ID, + createEnvironmentInjector, + isDevMode, + provideZonelessChangeDetection, + signal, +} from '@angular/core' +import { provideTanStackQuery } from '../providers' +import { withDevtools } from '../devtools' +import type { + DevtoolsButtonPosition, + DevtoolsErrorType, + DevtoolsPosition, +} from '@tanstack/query-devtools' +import type { DevtoolsOptions } from '../devtools' + +const mockDevtoolsInstance = { + mount: vi.fn(), + unmount: vi.fn(), + setClient: vi.fn(), + setPosition: vi.fn(), + setErrorTypes: vi.fn(), + setButtonPosition: vi.fn(), + setInitialIsOpen: vi.fn(), +} + +const mockTanstackQueryDevtools = vi.fn(() => mockDevtoolsInstance) + +vi.mock('@tanstack/query-devtools', () => ({ + TanstackQueryDevtools: mockTanstackQueryDevtools, +})) + +vi.mock('@angular/core', async () => { + const actual = await vi.importActual('@angular/core') + return { + ...actual, + isDevMode: vi.fn(), + } +}) + +const mockIsDevMode = vi.mocked(isDevMode) + +describe('withDevtools feature', () => { + beforeEach(() => { + vi.clearAllMocks() + vi.useFakeTimers() + }) + + afterEach(() => { + vi.restoreAllMocks() + vi.useRealTimers() + TestBed.resetTestingModule() + }) + + test.each([ + { + description: 'should load devtools in development mode', + isDevMode: true, + expectedCalled: true, + }, + { + description: 'should not load devtools in production mode', + isDevMode: false, + expectedCalled: false, + }, + { + description: `should load devtools in development mode when 'loadDevtools' is set to 'auto'`, + isDevMode: true, + loadDevtools: 'auto', + expectedCalled: true, + }, + { + description: `should not load devtools in production mode when 'loadDevtools' is set to 'auto'`, + isDevMode: false, + loadDevtools: 'auto', + expectedCalled: false, + }, + { + description: + "should load devtools in development mode when 'loadDevtools' is set to true", + isDevMode: true, + loadDevtools: true, + expectedCalled: true, + }, + { + description: + "should load devtools in production mode when 'loadDevtools' is set to true", + isDevMode: false, + loadDevtools: true, + expectedCalled: true, + }, + { + description: + "should not load devtools in development mode when 'loadDevtools' is set to false", + isDevMode: true, + loadDevtools: false, + expectedCalled: false, + }, + { + description: + "should not load devtools in production mode when 'loadDevtools' is set to false", + isDevMode: false, + loadDevtools: false, + expectedCalled: false, + }, + ])( + '$description', + async ({ isDevMode: isDevModeValue, loadDevtools, expectedCalled }) => { + mockIsDevMode.mockReturnValue(isDevModeValue) + + const providers = [ + provideZonelessChangeDetection(), + provideTanStackQuery( + new QueryClient(), + loadDevtools !== undefined + ? withDevtools( + () => + ({ + loadDevtools, + }) as DevtoolsOptions, + ) + : withDevtools(), + ), + ] + + TestBed.configureTestingModule({ + providers, + }) + + TestBed.inject(ENVIRONMENT_INITIALIZER) + await vi.advanceTimersByTimeAsync(0) + TestBed.tick() + await vi.dynamicImportSettled() + TestBed.tick() + await vi.dynamicImportSettled() + + if (expectedCalled) { + expect(mockTanstackQueryDevtools).toHaveBeenCalled() + expect(mockDevtoolsInstance.mount).toHaveBeenCalled() + } else { + expect(mockTanstackQueryDevtools).not.toHaveBeenCalled() + expect(mockDevtoolsInstance.mount).not.toHaveBeenCalled() + } + }, + ) + + it('should not continue loading devtools after injector is destroyed', async () => { + TestBed.configureTestingModule({ + providers: [ + provideZonelessChangeDetection(), + provideTanStackQuery( + new QueryClient(), + withDevtools(() => ({ + loadDevtools: true, + })), + ), + ], + }) + + TestBed.inject(ENVIRONMENT_INITIALIZER) + // Destroys injector + TestBed.resetTestingModule() + await vi.advanceTimersByTimeAsync(0) + await vi.dynamicImportSettled() + + expect(mockTanstackQueryDevtools).not.toHaveBeenCalled() + }) + + it('should not create devtools again when already provided', async () => { + TestBed.configureTestingModule({ + providers: [ + provideZonelessChangeDetection(), + provideTanStackQuery( + new QueryClient(), + withDevtools(() => ({ + loadDevtools: true, + })), + ), + ], + }) + + TestBed.inject(ENVIRONMENT_INITIALIZER) + await vi.advanceTimersByTimeAsync(0) + + expect(mockTanstackQueryDevtools).toHaveBeenCalledTimes(1) + + const injector = TestBed.inject(EnvironmentInjector) + + createEnvironmentInjector( + [ + withDevtools(() => ({ + loadDevtools: true, + })).ɵproviders, + ], + injector, + ) + + TestBed.inject(ENVIRONMENT_INITIALIZER) + await vi.advanceTimersByTimeAsync(0) + + expect(mockTanstackQueryDevtools).toHaveBeenCalledTimes(1) + }) + + it('should not load devtools if platform is not browser', async () => { + TestBed.configureTestingModule({ + providers: [ + { + provide: PLATFORM_ID, + useValue: 'server', + }, + provideZonelessChangeDetection(), + provideTanStackQuery( + new QueryClient(), + withDevtools(() => ({ + loadDevtools: true, + })), + ), + ], + }) + + TestBed.inject(ENVIRONMENT_INITIALIZER) + await vi.runAllTimersAsync() + + expect(mockTanstackQueryDevtools).not.toHaveBeenCalled() + }) + + it('should update error types', async () => { + const errorTypes = signal([] as Array) + + TestBed.configureTestingModule({ + providers: [ + provideZonelessChangeDetection(), + provideTanStackQuery( + new QueryClient(), + withDevtools(() => ({ + loadDevtools: true, + errorTypes: errorTypes(), + })), + ), + ], + }) + + TestBed.inject(ENVIRONMENT_INITIALIZER) + await vi.advanceTimersByTimeAsync(0) + + TestBed.tick() + + expect(mockDevtoolsInstance.setErrorTypes).toHaveBeenCalledTimes(0) + + const newErrorTypes = [ + { + name: '', + initializer: () => new Error(), + }, + ] + + errorTypes.set(newErrorTypes) + + TestBed.tick() + + expect(mockDevtoolsInstance.setErrorTypes).toHaveBeenCalledTimes(1) + expect(mockDevtoolsInstance.setErrorTypes).toHaveBeenCalledWith( + newErrorTypes, + ) + }) + + it('should update client', async () => { + const client = signal(new QueryClient()) + + TestBed.configureTestingModule({ + providers: [ + provideZonelessChangeDetection(), + provideTanStackQuery( + new QueryClient(), + withDevtools(() => ({ + loadDevtools: true, + client: client(), + })), + ), + ], + }) + + TestBed.inject(ENVIRONMENT_INITIALIZER) + await vi.advanceTimersByTimeAsync(0) + + TestBed.tick() + + expect(mockDevtoolsInstance.setClient).toHaveBeenCalledTimes(0) + + const newClient = new QueryClient() + client.set(newClient) + + TestBed.tick() + + expect(mockDevtoolsInstance.setClient).toHaveBeenCalledTimes(1) + expect(mockDevtoolsInstance.setClient).toHaveBeenCalledWith(newClient) + }) + + it('should update position', async () => { + const position = signal('top') + + TestBed.configureTestingModule({ + providers: [ + provideZonelessChangeDetection(), + provideTanStackQuery( + new QueryClient(), + withDevtools(() => ({ + loadDevtools: true, + position: position(), + })), + ), + ], + }) + + TestBed.inject(ENVIRONMENT_INITIALIZER) + await vi.advanceTimersByTimeAsync(0) + + TestBed.tick() + + expect(mockDevtoolsInstance.setPosition).toHaveBeenCalledTimes(0) + + position.set('left') + + TestBed.tick() + + expect(mockDevtoolsInstance.setPosition).toHaveBeenCalledTimes(1) + expect(mockDevtoolsInstance.setPosition).toHaveBeenCalledWith('left') + }) + + it('should update button position', async () => { + const buttonPosition = signal('bottom-left') + + TestBed.configureTestingModule({ + providers: [ + provideZonelessChangeDetection(), + provideTanStackQuery( + new QueryClient(), + withDevtools(() => ({ + loadDevtools: true, + buttonPosition: buttonPosition(), + })), + ), + ], + }) + + TestBed.inject(ENVIRONMENT_INITIALIZER) + await vi.advanceTimersByTimeAsync(0) + + TestBed.tick() + + expect(mockDevtoolsInstance.setButtonPosition).toHaveBeenCalledTimes(0) + + buttonPosition.set('bottom-right') + + TestBed.tick() + + expect(mockDevtoolsInstance.setButtonPosition).toHaveBeenCalledTimes(1) + expect(mockDevtoolsInstance.setButtonPosition).toHaveBeenCalledWith( + 'bottom-right', + ) + }) + + it('should update initialIsOpen', async () => { + const initialIsOpen = signal(false) + + TestBed.configureTestingModule({ + providers: [ + provideZonelessChangeDetection(), + provideTanStackQuery( + new QueryClient(), + withDevtools(() => ({ + loadDevtools: true, + initialIsOpen: initialIsOpen(), + })), + ), + ], + }) + + TestBed.inject(ENVIRONMENT_INITIALIZER) + await vi.advanceTimersByTimeAsync(0) + + TestBed.tick() + + expect(mockDevtoolsInstance.setInitialIsOpen).toHaveBeenCalledTimes(0) + + initialIsOpen.set(true) + + TestBed.tick() + + expect(mockDevtoolsInstance.setInitialIsOpen).toHaveBeenCalledTimes(1) + expect(mockDevtoolsInstance.setInitialIsOpen).toHaveBeenCalledWith(true) + }) + + it('should destroy devtools', async () => { + const loadDevtools = signal(true) + + TestBed.configureTestingModule({ + providers: [ + provideZonelessChangeDetection(), + provideTanStackQuery( + new QueryClient(), + withDevtools(() => ({ + loadDevtools: loadDevtools(), + })), + ), + ], + }) + + TestBed.inject(ENVIRONMENT_INITIALIZER) + await vi.advanceTimersByTimeAsync(0) + + expect(mockDevtoolsInstance.mount).toHaveBeenCalledTimes(1) + expect(mockDevtoolsInstance.unmount).toHaveBeenCalledTimes(0) + + loadDevtools.set(false) + + TestBed.tick() + + expect(mockDevtoolsInstance.unmount).toHaveBeenCalledTimes(1) + }) + + it('should unmount devtools when injector is destroyed', async () => { + TestBed.configureTestingModule({ + providers: [ + provideZonelessChangeDetection(), + provideTanStackQuery( + new QueryClient(), + withDevtools(() => ({ + loadDevtools: true, + })), + ), + ], + }) + + TestBed.inject(ENVIRONMENT_INITIALIZER) + await vi.advanceTimersByTimeAsync(0) + TestBed.tick() + await vi.dynamicImportSettled() + + expect(mockTanstackQueryDevtools).toHaveBeenCalled() + expect(mockDevtoolsInstance.mount).toHaveBeenCalledTimes(1) + expect(mockDevtoolsInstance.unmount).toHaveBeenCalledTimes(0) + + // Destroy the injector + TestBed.resetTestingModule() + + expect(mockDevtoolsInstance.unmount).toHaveBeenCalledTimes(1) + }) + + it('should remount devtools when toggled from false to true', async () => { + const loadDevtools = signal(false) + + TestBed.configureTestingModule({ + providers: [ + provideZonelessChangeDetection(), + provideTanStackQuery( + new QueryClient(), + withDevtools(() => ({ + loadDevtools: loadDevtools(), + })), + ), + ], + }) + + TestBed.inject(ENVIRONMENT_INITIALIZER) + await vi.advanceTimersByTimeAsync(0) + + expect(mockTanstackQueryDevtools).not.toHaveBeenCalled() + expect(mockDevtoolsInstance.mount).not.toHaveBeenCalled() + + loadDevtools.set(true) + TestBed.tick() + await vi.dynamicImportSettled() + + expect(mockTanstackQueryDevtools).toHaveBeenCalledTimes(1) + expect(mockDevtoolsInstance.mount).toHaveBeenCalledTimes(1) + expect(mockDevtoolsInstance.unmount).not.toHaveBeenCalled() + + loadDevtools.set(false) + TestBed.tick() + + expect(mockDevtoolsInstance.unmount).toHaveBeenCalledTimes(1) + expect(mockDevtoolsInstance.mount).toHaveBeenCalledTimes(1) + + loadDevtools.set(true) + TestBed.tick() + await vi.dynamicImportSettled() + + // Should remount (mount called twice now) + expect(mockDevtoolsInstance.mount).toHaveBeenCalledTimes(2) + expect(mockDevtoolsInstance.unmount).toHaveBeenCalledTimes(1) + }) + + describe('deps parameter', () => { + it('should inject dependencies and pass them to withDevtoolsFn in correct order', async () => { + const mockService1 = { value: 'service1' } + const mockService2 = { value: 'service2' } + const mockService1Token = new InjectionToken('MockService1') + const mockService2Token = new InjectionToken('MockService2') + const withDevtoolsFn = vi.fn().mockReturnValue({ loadDevtools: true }) + + TestBed.configureTestingModule({ + providers: [ + provideZonelessChangeDetection(), + { + provide: mockService1Token, + useValue: mockService1, + }, + { + provide: mockService2Token, + useValue: mockService2, + }, + provideTanStackQuery( + new QueryClient(), + withDevtools(withDevtoolsFn, { + deps: [mockService1Token, mockService2Token], + }), + ), + ], + }) + + TestBed.inject(ENVIRONMENT_INITIALIZER) + await vi.advanceTimersByTimeAsync(0) + + expect(withDevtoolsFn).toHaveBeenCalledWith(mockService1, mockService2) + }) + + it('should work with empty deps array', async () => { + const withDevtoolsFn = vi.fn().mockReturnValue({ loadDevtools: true }) + + TestBed.configureTestingModule({ + providers: [ + provideZonelessChangeDetection(), + provideTanStackQuery( + new QueryClient(), + withDevtools(withDevtoolsFn, { + deps: [], + }), + ), + ], + }) + + TestBed.inject(ENVIRONMENT_INITIALIZER) + await vi.advanceTimersByTimeAsync(0) + + expect(withDevtoolsFn).toHaveBeenCalledWith() + }) + + it('should reactively update when injected services change', async () => { + class ReactiveService { + enabled = signal(false) + position = signal('bottom') + } + + const withDevtoolsFn = (service: ReactiveService) => ({ + loadDevtools: service.enabled(), + position: service.position(), + }) + + TestBed.configureTestingModule({ + providers: [ + provideZonelessChangeDetection(), + ReactiveService, + provideTanStackQuery( + new QueryClient(), + withDevtools(withDevtoolsFn, { + deps: [ReactiveService], + }), + ), + ], + }) + + TestBed.inject(ENVIRONMENT_INITIALIZER) + await vi.advanceTimersByTimeAsync(0) + + const service = TestBed.inject(ReactiveService) + + expect(mockTanstackQueryDevtools).not.toHaveBeenCalled() + + service.enabled.set(true) + TestBed.tick() + await vi.dynamicImportSettled() + + expect(mockTanstackQueryDevtools).toHaveBeenCalledTimes(1) + expect(mockTanstackQueryDevtools).toHaveBeenCalledWith( + expect.objectContaining({ + position: 'bottom', + }), + ) + + service.position.set('top') + TestBed.tick() + + expect(mockDevtoolsInstance.setPosition).toHaveBeenCalledWith('top') + }) + }) +}) diff --git a/packages/angular-query-experimental/src/devtools-panel/index.ts b/packages/angular-query-experimental/src/devtools-panel/index.ts new file mode 100644 index 0000000000..2742a15469 --- /dev/null +++ b/packages/angular-query-experimental/src/devtools-panel/index.ts @@ -0,0 +1,8 @@ +export type { + InjectDevtoolsPanel, + DevtoolsPanelOptions, + InjectDevtoolsPanelOptions, + DevtoolsPanelRef, +} from './types' + +export { injectDevtoolsPanel } from './inject-devtools-panel' diff --git a/packages/angular-query-experimental/src/devtools-panel/inject-devtools-panel.ts b/packages/angular-query-experimental/src/devtools-panel/inject-devtools-panel.ts new file mode 100644 index 0000000000..94aaa185ca --- /dev/null +++ b/packages/angular-query-experimental/src/devtools-panel/inject-devtools-panel.ts @@ -0,0 +1,110 @@ +import { + DestroyRef, + Injector, + PLATFORM_ID, + assertInInjectionContext, + computed, + effect, + inject, + runInInjectionContext, + untracked, +} from '@angular/core' +import { QueryClient, onlineManager } from '@tanstack/query-core' +import { isPlatformBrowser } from '@angular/common' +import type { TanstackQueryDevtoolsPanel } from '@tanstack/query-devtools' +import type { + DevtoolsPanelOptions, + InjectDevtoolsPanel, + InjectDevtoolsPanelOptions, +} from './types' + +/** + * Inject a TanStack Query devtools panel and render it in the DOM. + * + * Devtools panel allows programmatic control over the devtools, for example if you want to render + * the devtools as part of your own devtools. + * + * Consider `withDevtools` instead if you don't need this. + * @param injectDevtoolsPanelFn - A function that returns devtools panel options. + * @param options - Additional configuration + * @returns DevtoolsPanelRef + * @see https://tanstack.com/query/v5/docs/framework/angular/devtools + */ +export const injectDevtoolsPanel: InjectDevtoolsPanel = ( + injectDevtoolsPanelFn: () => DevtoolsPanelOptions, + options?: InjectDevtoolsPanelOptions, +) => { + !options?.injector && assertInInjectionContext(injectDevtoolsPanel) + const currentInjector = options?.injector ?? inject(Injector) + + return runInInjectionContext(currentInjector, () => { + const destroyRef = inject(DestroyRef) + const isBrowser = isPlatformBrowser(inject(PLATFORM_ID)) + const injectedClient = inject(QueryClient, { optional: true }) + + const queryOptions = computed(injectDevtoolsPanelFn) + let devtools: TanstackQueryDevtoolsPanel | null = null + + const destroy = () => { + devtools?.unmount() + devtools = null + } + + if (!isBrowser) + return { + destroy, + } + + effect(() => { + const { + client = injectedClient, + errorTypes = [], + styleNonce, + shadowDOMTarget, + onClose, + hostElement, + } = queryOptions() + + untracked(() => { + if (!client) throw new Error('No QueryClient found') + if (!devtools && hostElement) { + import('@tanstack/query-devtools') + .then((queryDevtools) => { + devtools = new queryDevtools.TanstackQueryDevtoolsPanel({ + client, + queryFlavor: 'Angular Query', + version: '5', + buttonPosition: 'bottom-left', + position: 'bottom', + initialIsOpen: true, + errorTypes, + styleNonce, + shadowDOMTarget, + onClose, + onlineManager, + }) + devtools.mount(hostElement.nativeElement) + }) + .catch((error) => { + console.error( + 'Install @tanstack/query-devtools or reinstall without --omit=optional.', + error, + ) + }) + } else if (devtools && hostElement) { + devtools.setClient(client) + devtools.setErrorTypes(errorTypes) + onClose && devtools.setOnClose(onClose) + } else if (devtools && !hostElement) { + destroy() + } + }) + }) + + destroyRef.onDestroy(destroy) + + return { + destroy, + } + }) +} diff --git a/packages/angular-query-experimental/src/devtools-panel/production/index.ts b/packages/angular-query-experimental/src/devtools-panel/production/index.ts new file mode 100644 index 0000000000..546becea7f --- /dev/null +++ b/packages/angular-query-experimental/src/devtools-panel/production/index.ts @@ -0,0 +1 @@ +export * from '..' diff --git a/packages/angular-query-experimental/src/devtools-panel/stub.ts b/packages/angular-query-experimental/src/devtools-panel/stub.ts new file mode 100644 index 0000000000..63e836eb5c --- /dev/null +++ b/packages/angular-query-experimental/src/devtools-panel/stub.ts @@ -0,0 +1,7 @@ +import { noop } from '@tanstack/query-core' +import type { InjectDevtoolsPanel } from './types' + +// Stub which replaces `injectDevtoolsPanel` in production builds +export const injectDevtoolsPanel: InjectDevtoolsPanel = () => ({ + destroy: noop, +}) diff --git a/packages/angular-query-experimental/src/devtools-panel/types.ts b/packages/angular-query-experimental/src/devtools-panel/types.ts new file mode 100644 index 0000000000..b87373ad95 --- /dev/null +++ b/packages/angular-query-experimental/src/devtools-panel/types.ts @@ -0,0 +1,57 @@ +import type { DevtoolsErrorType } from '@tanstack/query-devtools' +import type { ElementRef, Injector } from '@angular/core' +import type { QueryClient } from '@tanstack/query-core' + +export interface InjectDevtoolsPanelOptions { + /** + * The `Injector` in which to create the devtools panel. + * + * If this is not provided, the current injection context will be used instead (via `inject`). + */ + injector?: Injector +} + +/** + * A devtools panel, which can be manually destroyed. + */ +export interface DevtoolsPanelRef { + /** + * Destroy the panel, removing it from the DOM and stops listening to signal changes. + */ + destroy: () => void +} + +export interface DevtoolsPanelOptions { + /** + * Custom instance of QueryClient + */ + client?: QueryClient + /** + * Use this so you can define custom errors that can be shown in the devtools. + */ + errorTypes?: Array + /** + * 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. + */ + styleNonce?: string + /** + * Use this so you can attach the devtool's styles to specific element in the DOM. + */ + shadowDOMTarget?: ShadowRoot + + /** + * Callback function that is called when the devtools panel is closed + */ + onClose?: () => unknown + + /** + * Element where to render the devtools panel. When set to undefined or null, the devtools panel will not be created, or destroyed if existing. + * If changed from undefined to a ElementRef, the devtools panel will be created. + */ + hostElement?: ElementRef +} + +export type InjectDevtoolsPanel = ( + injectDevtoolsPanelFn: () => DevtoolsPanelOptions, + options?: InjectDevtoolsPanelOptions, +) => DevtoolsPanelRef diff --git a/packages/angular-query-experimental/src/devtools/index.ts b/packages/angular-query-experimental/src/devtools/index.ts new file mode 100644 index 0000000000..d4f7e9238f --- /dev/null +++ b/packages/angular-query-experimental/src/devtools/index.ts @@ -0,0 +1,8 @@ +export type { + DevtoolsOptions, + WithDevtools, + WithDevtoolsFn, + WithDevtoolsOptions, +} from './types' + +export { withDevtools } from './with-devtools' diff --git a/packages/angular-query-experimental/src/devtools/production/index.ts b/packages/angular-query-experimental/src/devtools/production/index.ts new file mode 100644 index 0000000000..546becea7f --- /dev/null +++ b/packages/angular-query-experimental/src/devtools/production/index.ts @@ -0,0 +1 @@ +export * from '..' diff --git a/packages/angular-query-experimental/src/devtools/stub.ts b/packages/angular-query-experimental/src/devtools/stub.ts new file mode 100644 index 0000000000..d8090a4b28 --- /dev/null +++ b/packages/angular-query-experimental/src/devtools/stub.ts @@ -0,0 +1,7 @@ +import type { WithDevtools } from './types' + +// Stub which replaces `withDevtools` in production builds +export const withDevtools: WithDevtools = () => ({ + ɵkind: 'Devtools', + ɵproviders: [], +}) diff --git a/packages/angular-query-experimental/src/devtools/types.ts b/packages/angular-query-experimental/src/devtools/types.ts new file mode 100644 index 0000000000..8ab243b97a --- /dev/null +++ b/packages/angular-query-experimental/src/devtools/types.ts @@ -0,0 +1,107 @@ +import type { QueryClient } from '@tanstack/query-core' +import type { + DevtoolsButtonPosition, + DevtoolsErrorType, + DevtoolsPosition, +} from '@tanstack/query-devtools' +import type { DeveloperToolsFeature } from '../providers' + +/** + * Options for configuring withDevtools. + */ +export interface WithDevtoolsOptions { + /** + * An array of dependencies to be injected and passed to the `withDevtoolsFn` function. + * + * **Example** + * ```ts + * export const appConfig: ApplicationConfig = { + * providers: [ + * provideTanStackQuery( + * new QueryClient(), + * withDevtools( + * (devToolsOptionsManager: DevtoolsOptionsManager) => ({ + * loadDevtools: devToolsOptionsManager.loadDevtools(), + * }), + * { + * deps: [DevtoolsOptionsManager], + * }, + * ), + * ), + * ], + * } + * ``` + */ + deps?: Array +} + +/** + * Options for configuring the TanStack Query devtools. + */ +export interface DevtoolsOptions { + /** + * Set this true if you want the devtools to default to being open + */ + initialIsOpen?: boolean + /** + * The position of the TanStack logo to open and close the devtools panel. + * `top-left` | `top-right` | `bottom-left` | `bottom-right` | `relative` + * Defaults to `bottom-right`. + */ + buttonPosition?: DevtoolsButtonPosition + /** + * The position of the TanStack Query devtools panel. + * `top` | `bottom` | `left` | `right` + * Defaults to `bottom`. + */ + position?: DevtoolsPosition + /** + * Custom instance of QueryClient + */ + client?: QueryClient + /** + * Use this so you can define custom errors that can be shown in the devtools. + */ + errorTypes?: Array + /** + * 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. + */ + styleNonce?: string + /** + * Use this so you can attach the devtool's styles to a specific element in the DOM. + */ + shadowDOMTarget?: ShadowRoot + /** + * Set this to true to hide disabled queries from the devtools panel. + */ + hideDisabledQueries?: boolean + + /** + * Whether the developer tools should load. + * - `auto`- (Default) Lazily loads devtools when in development mode. Skips loading in production mode. + * - `true`- Always load the devtools, regardless of the environment. + * - `false`- Never load the devtools, regardless of the environment. + * + * You can use `true` and `false` to override loading developer tools from an environment file. + * For example, a test environment might run in production mode but you may want to load developer tools. + * + * Additionally, you can use a signal in the callback to dynamically load the devtools based on a condition. For example, + * a signal created from a RxJS observable that listens for a keyboard shortcut. + * + * **Example** + * ```ts + * withDevtools(() => ({ + * initialIsOpen: true, + * loadDevtools: inject(ExampleService).loadDevtools() + * })) + * ``` + */ + loadDevtools?: 'auto' | boolean +} + +export type WithDevtoolsFn = (...deps: Array) => DevtoolsOptions + +export type WithDevtools = ( + withDevtoolsFn?: WithDevtoolsFn, + options?: WithDevtoolsOptions, +) => DeveloperToolsFeature diff --git a/packages/angular-query-experimental/src/devtools/with-devtools.ts b/packages/angular-query-experimental/src/devtools/with-devtools.ts new file mode 100644 index 0000000000..22ee80c1ca --- /dev/null +++ b/packages/angular-query-experimental/src/devtools/with-devtools.ts @@ -0,0 +1,180 @@ +import { isPlatformBrowser } from '@angular/common' +import { + DestroyRef, + ENVIRONMENT_INITIALIZER, + InjectionToken, + Injector, + PLATFORM_ID, + computed, + effect, + inject, + isDevMode, +} from '@angular/core' +import { QueryClient, noop, onlineManager } from '@tanstack/query-core' +import { queryFeature } from '../providers' +import type { Signal } from '@angular/core' +import type { + DevtoolsOptions, + WithDevtools, + WithDevtoolsFn, + WithDevtoolsOptions, +} from './types' +import type { TanstackQueryDevtools } from '@tanstack/query-devtools' + +/** + * Internal token used to prevent double providing of devtools in child injectors + */ +const DEVTOOLS_PROVIDED = new InjectionToken('', { + factory: () => ({ + isProvided: false, + }), +}) + +/** + * Internal token for providing devtools options + */ +const DEVTOOLS_OPTIONS_SIGNAL = new InjectionToken>('') + +/** + * Enables developer tools in Angular development builds. + * + * **Example** + * + * ```ts + * export const appConfig: ApplicationConfig = { + * providers: [ + * provideTanStackQuery(new QueryClient(), withDevtools()) + * ] + * } + * ``` + * The devtools will be rendered in ``. + * + * If you need more control over when devtools are loaded, you can use the `loadDevtools` option. + * + * If you need more control over where devtools are rendered, consider `injectDevtoolsPanel`. This allows rendering devtools inside your own devtools for example. + * @param withDevtoolsFn - A function that returns `DevtoolsOptions`. + * @param options - Additional options for configuring `withDevtools`. + * @returns A set of providers for use with `provideTanStackQuery`. + * @see {@link provideTanStackQuery} + * @see {@link DevtoolsOptions} + */ +export const withDevtools: WithDevtools = ( + withDevtoolsFn?: WithDevtoolsFn, + options: WithDevtoolsOptions = {}, +) => + queryFeature('Devtools', [ + { + provide: DEVTOOLS_OPTIONS_SIGNAL, + useFactory: (...deps: Array) => + computed(() => withDevtoolsFn?.(...deps) ?? {}), + deps: options.deps || [], + }, + { + // Do not use provideEnvironmentInitializer while Angular < v19 is supported + provide: ENVIRONMENT_INITIALIZER, + multi: true, + useFactory: () => { + const devtoolsProvided = inject(DEVTOOLS_PROVIDED) + if ( + !isPlatformBrowser(inject(PLATFORM_ID)) || + devtoolsProvided.isProvided + ) + return noop + + devtoolsProvided.isProvided = true + let injectorIsDestroyed = false + inject(DestroyRef).onDestroy(() => (injectorIsDestroyed = true)) + + return () => { + const injectedClient = inject(QueryClient, { + optional: true, + }) + const destroyRef = inject(DestroyRef) + const devtoolsOptions = inject(DEVTOOLS_OPTIONS_SIGNAL) + const injector = inject(Injector) + + let devtools: TanstackQueryDevtools | null = null + let el: HTMLElement | null = null + + const shouldLoadToolsSignal = computed(() => { + const { loadDevtools } = devtoolsOptions() + return typeof loadDevtools === 'boolean' + ? loadDevtools + : isDevMode() + }) + + const getResolvedQueryClient = () => { + const client = devtoolsOptions().client ?? injectedClient + if (!client) { + throw new Error('No QueryClient found') + } + return client + } + + const destroyDevtools = () => { + devtools?.unmount() + el?.remove() + devtools = null + } + + effect( + () => { + const shouldLoadTools = shouldLoadToolsSignal() + const { + client, + position, + errorTypes, + buttonPosition, + initialIsOpen, + } = devtoolsOptions() + + if (!shouldLoadTools) { + // Destroy or do nothing + devtools && destroyDevtools() + return + } + + if (devtools) { + // Update existing devtools config + client && devtools.setClient(client) + position && devtools.setPosition(position) + errorTypes && devtools.setErrorTypes(errorTypes) + buttonPosition && devtools.setButtonPosition(buttonPosition) + typeof initialIsOpen === 'boolean' && + devtools.setInitialIsOpen(initialIsOpen) + return + } + + // Create devtools + import('@tanstack/query-devtools') + .then((queryDevtools) => { + // As this code runs async, the injector could have been destroyed + if (injectorIsDestroyed) return + + devtools = new queryDevtools.TanstackQueryDevtools({ + ...devtoolsOptions(), + client: getResolvedQueryClient(), + queryFlavor: 'Angular Query', + version: '5', + onlineManager, + }) + + el = document.body.appendChild(document.createElement('div')) + el.classList.add('tsqd-parent-container') + devtools.mount(el) + + destroyRef.onDestroy(destroyDevtools) + }) + .catch((error) => { + console.error( + 'Install @tanstack/query-devtools or reinstall without --omit=optional.', + error, + ) + }) + }, + { injector }, + ) + } + }, + }, + ]) diff --git a/packages/angular-query-experimental/src/index.ts b/packages/angular-query-experimental/src/index.ts index d50f2a6078..bad24075cc 100644 --- a/packages/angular-query-experimental/src/index.ts +++ b/packages/angular-query-experimental/src/index.ts @@ -48,16 +48,13 @@ export { injectQueryClient } from './inject-query-client' export type { DeveloperToolsFeature, - DevtoolsOptions, PersistQueryClientFeature, QueryFeature, - QueryFeatureKind, QueryFeatures, } from './providers' export { + provideAngularQuery, provideQueryClient, provideTanStackQuery, queryFeature, - queryFeatures, - withDevtools, } from './providers' diff --git a/packages/angular-query-experimental/src/infinite-query-options.ts b/packages/angular-query-experimental/src/infinite-query-options.ts index fdc7396c99..fc18c0e94d 100644 --- a/packages/angular-query-experimental/src/infinite-query-options.ts +++ b/packages/angular-query-experimental/src/infinite-query-options.ts @@ -84,7 +84,6 @@ export type DefinedInitialDataInfiniteOptions< * The `queryKey` will be tagged with the type from `queryFn`. * @param options - The infinite query options to tag with the type from `queryFn`. * @returns The tagged infinite query options. - * @public */ export function infiniteQueryOptions< TQueryFnData, @@ -116,7 +115,6 @@ export function infiniteQueryOptions< * The `queryKey` will be tagged with the type from `queryFn`. * @param options - The infinite query options to tag with the type from `queryFn`. * @returns The tagged infinite query options. - * @public */ export function infiniteQueryOptions< TQueryFnData, @@ -148,7 +146,6 @@ export function infiniteQueryOptions< * The `queryKey` will be tagged with the type from `queryFn`. * @param options - The infinite query options to tag with the type from `queryFn`. * @returns The tagged infinite query options. - * @public */ export function infiniteQueryOptions< TQueryFnData, @@ -180,7 +177,6 @@ export function infiniteQueryOptions< * The `queryKey` will be tagged with the type from `queryFn`. * @param options - The infinite query options to tag with the type from `queryFn`. * @returns The tagged infinite query options. - * @public */ export function infiniteQueryOptions(options: unknown) { return options diff --git a/packages/angular-query-experimental/src/inject-infinite-query.ts b/packages/angular-query-experimental/src/inject-infinite-query.ts index 6df26a0bb5..ee6de03240 100644 --- a/packages/angular-query-experimental/src/inject-infinite-query.ts +++ b/packages/angular-query-experimental/src/inject-infinite-query.ts @@ -37,7 +37,6 @@ export interface InjectInfiniteQueryOptions { * @param injectInfiniteQueryFn - A function that returns infinite query options. * @param options - Additional configuration. * @returns The infinite query result. - * @public */ export function injectInfiniteQuery< TQueryFnData, @@ -62,7 +61,6 @@ export function injectInfiniteQuery< * @param injectInfiniteQueryFn - A function that returns infinite query options. * @param options - Additional configuration. * @returns The infinite query result. - * @public */ export function injectInfiniteQuery< TQueryFnData, @@ -87,7 +85,6 @@ export function injectInfiniteQuery< * @param injectInfiniteQueryFn - A function that returns infinite query options. * @param options - Additional configuration. * @returns The infinite query result. - * @public */ export function injectInfiniteQuery< TQueryFnData, @@ -112,7 +109,6 @@ export function injectInfiniteQuery< * @param injectInfiniteQueryFn - A function that returns infinite query options. * @param options - Additional configuration. * @returns The infinite query result. - * @public */ export function injectInfiniteQuery( injectInfiniteQueryFn: () => CreateInfiniteQueryOptions, diff --git a/packages/angular-query-experimental/src/inject-is-mutating.ts b/packages/angular-query-experimental/src/inject-is-mutating.ts index 21de13b90e..8f11291b0e 100644 --- a/packages/angular-query-experimental/src/inject-is-mutating.ts +++ b/packages/angular-query-experimental/src/inject-is-mutating.ts @@ -26,7 +26,6 @@ export interface InjectIsMutatingOptions { * @param filters - The filters to apply to the query. * @param options - Additional configuration * @returns signal with number of fetching mutations. - * @public */ export function injectIsMutating( filters?: MutationFilters, diff --git a/packages/angular-query-experimental/src/inject-is-restoring.ts b/packages/angular-query-experimental/src/inject-is-restoring.ts index 92e50d4342..2c7fb3ae68 100644 --- a/packages/angular-query-experimental/src/inject-is-restoring.ts +++ b/packages/angular-query-experimental/src/inject-is-restoring.ts @@ -7,30 +7,27 @@ import { } from '@angular/core' import type { Provider, Signal } from '@angular/core' -const IS_RESTORING = new InjectionToken( - typeof ngDevMode === 'undefined' || ngDevMode - ? 'TANSTACK_QUERY_IS_RESTORING' - : '', - { - // Default value when not provided - factory: () => signal(false).asReadonly(), - }, -) - /** - * The `Injector` in which to create the isRestoring signal. - * - * If this is not provided, the current injection context will be used instead (via `inject`). + * Internal token used to track isRestoring state, accessible in public API through `injectIsRestoring` and set via `provideIsRestoring` */ +const IS_RESTORING = new InjectionToken('', { + // Default value when not provided + factory: () => signal(false).asReadonly(), +}) + interface InjectIsRestoringOptions { + /** + * The `Injector` to use to get the isRestoring signal. + * + * If this is not provided, the current injection context will be used instead (via `inject`). + */ injector?: Injector } /** * Injects a signal that tracks whether a restore is currently in progress. {@link injectQuery} and friends also check this internally to avoid race conditions between the restore and initializing queries. * @param options - Options for injectIsRestoring. - * @returns signal with boolean that indicates whether a restore is in progress. - * @public + * @returns readonly signal with boolean that indicates whether a restore is in progress. */ export function injectIsRestoring(options?: InjectIsRestoringOptions) { !options?.injector && assertInInjectionContext(injectIsRestoring) @@ -42,7 +39,6 @@ export function injectIsRestoring(options?: InjectIsRestoringOptions) { * Used by TanStack Query Angular persist client plugin to provide the signal that tracks the restore state * @param isRestoring - a readonly signal that returns a boolean * @returns Provider for the `isRestoring` signal - * @public */ export function provideIsRestoring(isRestoring: Signal): Provider { return { diff --git a/packages/angular-query-experimental/src/inject-mutation-state.ts b/packages/angular-query-experimental/src/inject-mutation-state.ts index 89419f1037..5f8996b2b1 100644 --- a/packages/angular-query-experimental/src/inject-mutation-state.ts +++ b/packages/angular-query-experimental/src/inject-mutation-state.ts @@ -42,9 +42,6 @@ function getResult( ) } -/** - * @public - */ export interface InjectMutationStateOptions { /** * The `Injector` in which to create the mutation state signal. @@ -59,7 +56,6 @@ export interface InjectMutationStateOptions { * @param injectMutationStateFn - A function that returns mutation state options. * @param options - The Angular injector to use. * @returns The signal that tracks the state of all mutations. - * @public */ export function injectMutationState( injectMutationStateFn: () => MutationStateOptions = () => ({}), diff --git a/packages/angular-query-experimental/src/inject-mutation.ts b/packages/angular-query-experimental/src/inject-mutation.ts index af4ebbd93b..21ddf5ff85 100644 --- a/packages/angular-query-experimental/src/inject-mutation.ts +++ b/packages/angular-query-experimental/src/inject-mutation.ts @@ -40,7 +40,6 @@ export interface InjectMutationOptions { * @param injectMutationFn - A function that returns mutation options. * @param options - Additional configuration * @returns The mutation. - * @public */ export function injectMutation< TData = unknown, diff --git a/packages/angular-query-experimental/src/inject-queries.ts b/packages/angular-query-experimental/src/inject-queries.ts index 1889e9560c..0cbcf3fb6a 100644 --- a/packages/angular-query-experimental/src/inject-queries.ts +++ b/packages/angular-query-experimental/src/inject-queries.ts @@ -116,7 +116,6 @@ type GetResults = /** * QueriesOptions reducer recursively unwraps function arguments to infer/enforce type param - * @public */ export type QueriesOptions< T extends Array, @@ -159,7 +158,6 @@ export type QueriesOptions< /** * QueriesResults reducer recursively maps type param to results - * @public */ export type QueriesResults< T extends Array, @@ -200,8 +198,6 @@ export type QueriesResults< * @param root0.queries * @param root0.combine * @param injector - * @param injector - * @public */ export function injectQueries< T extends Array, diff --git a/packages/angular-query-experimental/src/inject-query-client.ts b/packages/angular-query-experimental/src/inject-query-client.ts index 3ac28e4d5e..7cd29e3850 100644 --- a/packages/angular-query-experimental/src/inject-query-client.ts +++ b/packages/angular-query-experimental/src/inject-query-client.ts @@ -6,7 +6,6 @@ import type { InjectOptions } from '@angular/core' * Injects a `QueryClient` instance and allows passing a custom injector. * @param injectOptions - Type of the options argument to inject and optionally a custom injector. * @returns The `QueryClient` instance. - * @public * @deprecated Use `inject(QueryClient)` instead. * If you need to get a `QueryClient` from a custom injector, use `injector.get(QueryClient)`. * diff --git a/packages/angular-query-experimental/src/inject-query.ts b/packages/angular-query-experimental/src/inject-query.ts index 0defdf18e9..1dac0ab694 100644 --- a/packages/angular-query-experimental/src/inject-query.ts +++ b/packages/angular-query-experimental/src/inject-query.ts @@ -60,7 +60,6 @@ export interface InjectQueryOptions { * @param injectQueryFn - A function that returns query options. * @param options - Additional configuration * @returns The query result. - * @public * @see https://tanstack.com/query/latest/docs/framework/angular/guides/queries */ export function injectQuery< @@ -112,7 +111,6 @@ export function injectQuery< * @param injectQueryFn - A function that returns query options. * @param options - Additional configuration * @returns The query result. - * @public * @see https://tanstack.com/query/latest/docs/framework/angular/guides/queries */ export function injectQuery< @@ -164,7 +162,6 @@ export function injectQuery< * @param injectQueryFn - A function that returns query options. * @param options - Additional configuration * @returns The query result. - * @public * @see https://tanstack.com/query/latest/docs/framework/angular/guides/queries */ export function injectQuery< @@ -216,7 +213,6 @@ export function injectQuery< * @param injectQueryFn - A function that returns query options. * @param options - Additional configuration * @returns The query result. - * @public * @see https://tanstack.com/query/latest/docs/framework/angular/guides/queries */ export function injectQuery( diff --git a/packages/angular-query-experimental/src/mutation-options.ts b/packages/angular-query-experimental/src/mutation-options.ts index 61dfc242cb..ec702cb45c 100644 --- a/packages/angular-query-experimental/src/mutation-options.ts +++ b/packages/angular-query-experimental/src/mutation-options.ts @@ -8,7 +8,8 @@ import type { CreateMutationOptions } from './types' * * ```ts * export class QueriesService { - * private http = inject(HttpClient); + * private http = inject(HttpClient) + * private queryClient = inject(QueryClient) * * updatePost(id: number) { * return mutationOptions({ @@ -26,10 +27,10 @@ import type { CreateMutationOptions } from './types' * queries = inject(QueriesService) * id = signal(0) * mutation = injectMutation(() => this.queries.updatePost(this.id())) - * } * - * save() { - * this.mutation.mutate({ title: 'New Title' }) + * save() { + * this.mutation.mutate({ title: 'New Title' }) + * } * } * ``` * @param options - The mutation options. @@ -71,7 +72,8 @@ export function mutationOptions< * * ```ts * export class QueriesService { - * private http = inject(HttpClient); + * private http = inject(HttpClient) + * private queryClient = inject(QueryClient) * * updatePost(id: number) { * return mutationOptions({ @@ -86,13 +88,13 @@ export function mutationOptions< * } * * class ComponentOrService { - * queries = inject(QueriesService) - * id = signal(0) + * queries = inject(QueriesService) + * id = signal(0) * mutation = injectMutation(() => this.queries.updatePost(this.id())) - * } * - * save() { - * this.mutation.mutate({ title: 'New Title' }) + * save() { + * this.mutation.mutate({ title: 'New Title' }) + * } * } * ``` * @param options - The mutation options. diff --git a/packages/angular-query-experimental/src/providers.ts b/packages/angular-query-experimental/src/providers.ts index d8c2806c10..3473c2affb 100644 --- a/packages/angular-query-experimental/src/providers.ts +++ b/packages/angular-query-experimental/src/providers.ts @@ -1,22 +1,6 @@ -import { - DestroyRef, - ENVIRONMENT_INITIALIZER, - InjectionToken, - PLATFORM_ID, - computed, - effect, - inject, -} from '@angular/core' -import { QueryClient, noop, onlineManager } from '@tanstack/query-core' -import { isPlatformBrowser } from '@angular/common' -import { isDevMode } from './util/is-dev-mode/is-dev-mode' +import { DestroyRef, InjectionToken, inject } from '@angular/core' +import { QueryClient } from '@tanstack/query-core' import type { Provider } from '@angular/core' -import type { - DevtoolsButtonPosition, - DevtoolsErrorType, - DevtoolsPosition, - TanstackQueryDevtools, -} from '@tanstack/query-devtools' /** * Usually {@link provideTanStackQuery} is used once to set up TanStack Query and the @@ -108,6 +92,10 @@ export function provideQueryClient( * // In a lazy loaded route or lazy loaded component's providers array: * providers: [provideTanStackQuery(MY_QUERY_CLIENT)] * ``` + * Using an InjectionToken for the QueryClient is an advanced optimization which allows TanStack Query to be absent from the main application bundle. + * This can be beneficial if you want to include TanStack Query on lazy loaded routes only while still sharing a `QueryClient`. + * + * Note that this is a small optimization and for most applications it's preferable to provide the `QueryClient` in the main application config. * @param queryClient - A `QueryClient` instance, or an `InjectionToken` which provides a `QueryClient`. * @param features - Optional features to configure additional Query functionality. * @returns A set of providers to set up TanStack Query. @@ -130,7 +118,6 @@ export function provideTanStackQuery( * Allows to configure a `QueryClient`. * @param queryClient - A `QueryClient` instance. * @returns A set of providers to set up TanStack Query. - * @public * @see https://tanstack.com/query/v5/docs/framework/angular/quick-start * @deprecated Use `provideTanStackQuery` instead. */ @@ -138,6 +125,10 @@ export function provideAngularQuery(queryClient: QueryClient): Array { return provideTanStackQuery(queryClient) } +const queryFeatures = ['Devtools', 'PersistQueryClient'] as const + +type QueryFeatureKind = (typeof queryFeatures)[number] + /** * Helper type to represent a Query feature. */ @@ -162,211 +153,21 @@ export function queryFeature( /** * A type alias that represents a feature which enables developer tools. * The type is used to describe the return value of the `withDevtools` function. - * @public * @see {@link withDevtools} */ -export type DeveloperToolsFeature = QueryFeature<'DeveloperTools'> +export type DeveloperToolsFeature = QueryFeature<'Devtools'> /** * A type alias that represents a feature which enables persistence. * The type is used to describe the return value of the `withPersistQueryClient` function. - * @public */ export type PersistQueryClientFeature = QueryFeature<'PersistQueryClient'> -/** - * Options for configuring the TanStack Query devtools. - * @public - */ -export interface DevtoolsOptions { - /** - * Set this true if you want the devtools to default to being open - */ - initialIsOpen?: boolean - /** - * The position of the TanStack logo to open and close the devtools panel. - * `top-left` | `top-right` | `bottom-left` | `bottom-right` | `relative` - * Defaults to `bottom-right`. - */ - buttonPosition?: DevtoolsButtonPosition - /** - * The position of the TanStack Query devtools panel. - * `top` | `bottom` | `left` | `right` - * Defaults to `bottom`. - */ - position?: DevtoolsPosition - /** - * Custom instance of QueryClient - */ - client?: QueryClient - /** - * Use this so you can define custom errors that can be shown in the devtools. - */ - errorTypes?: Array - /** - * 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. - */ - styleNonce?: string - /** - * Use this so you can attach the devtool's styles to a specific element in the DOM. - */ - shadowDOMTarget?: ShadowRoot - /** - * Set this to true to hide disabled queries from the devtools panel. - */ - hideDisabledQueries?: boolean - - /** - * Whether the developer tools should load. - * - `auto`- (Default) Lazily loads devtools when in development mode. Skips loading in production mode. - * - `true`- Always load the devtools, regardless of the environment. - * - `false`- Never load the devtools, regardless of the environment. - * - * You can use `true` and `false` to override loading developer tools from an environment file. - * For example, a test environment might run in production mode but you may want to load developer tools. - * - * Additionally, you can use a signal in the callback to dynamically load the devtools based on a condition. For example, - * a signal created from a RxJS observable that listens for a keyboard shortcut. - * - * **Example** - * ```ts - * withDevtools(() => ({ - * initialIsOpen: true, - * loadDevtools: inject(ExampleService).loadDevtools() - * })) - * ``` - */ - loadDevtools?: 'auto' | boolean -} - -/** - * Enables developer tools. - * - * **Example** - * - * ```ts - * export const appConfig: ApplicationConfig = { - * providers: [ - * provideTanStackQuery(new QueryClient(), withDevtools()) - * ] - * } - * ``` - * By default the devtools will be loaded when Angular runs in development mode and rendered in ``. - * - * If you need more control over when devtools are loaded, you can use the `loadDevtools` option. This is particularly useful if you want to load devtools based on environment configurations. For instance, you might have a test environment running in production mode but still require devtools to be available. - * - * If you need more control over where devtools are rendered, consider `injectDevtoolsPanel`. This allows rendering devtools inside your own devtools for example. - * @param withDevtoolsFn - A function that returns `DevtoolsOptions`. - * @returns A set of providers for use with `provideTanStackQuery`. - * @public - * @see {@link provideTanStackQuery} - * @see {@link DevtoolsOptions} - */ -export function withDevtools( - withDevtoolsFn?: () => DevtoolsOptions, -): DeveloperToolsFeature { - let providers: Array = [] - if (!isDevMode() && !withDevtoolsFn) { - providers = [] - } else { - providers = [ - { - // Do not use provideEnvironmentInitializer while Angular < v19 is supported - provide: ENVIRONMENT_INITIALIZER, - multi: true, - useFactory: () => { - if (!isPlatformBrowser(inject(PLATFORM_ID))) return noop - const injectedClient = inject(QueryClient, { - optional: true, - }) - const destroyRef = inject(DestroyRef) - - const options = computed(() => withDevtoolsFn?.() ?? {}) - - let devtools: TanstackQueryDevtools | null = null - let el: HTMLElement | null = null - - const shouldLoadToolsSignal = computed(() => { - const { loadDevtools } = options() - return typeof loadDevtools === 'boolean' - ? loadDevtools - : isDevMode() - }) - - const getResolvedQueryClient = () => { - const client = options().client ?? injectedClient - if (!client) { - throw new Error('No QueryClient found') - } - return client - } - - const destroyDevtools = () => { - devtools?.unmount() - el?.remove() - devtools = null - } - - return () => - effect(() => { - const shouldLoadTools = shouldLoadToolsSignal() - const { - client, - position, - errorTypes, - buttonPosition, - initialIsOpen, - } = options() - - if (devtools && !shouldLoadTools) { - destroyDevtools() - return - } else if (devtools && shouldLoadTools) { - client && devtools.setClient(client) - position && devtools.setPosition(position) - errorTypes && devtools.setErrorTypes(errorTypes) - buttonPosition && devtools.setButtonPosition(buttonPosition) - initialIsOpen && devtools.setInitialIsOpen(initialIsOpen) - return - } else if (!shouldLoadTools) { - return - } - - el = document.body.appendChild(document.createElement('div')) - el.classList.add('tsqd-parent-container') - - import('@tanstack/query-devtools').then((queryDevtools) => { - devtools = new queryDevtools.TanstackQueryDevtools({ - ...options(), - client: getResolvedQueryClient(), - queryFlavor: 'Angular Query', - version: '5', - onlineManager, - }) - - el && devtools.mount(el) - - // Unmount the devtools on application destroy - destroyRef.onDestroy(destroyDevtools) - }) - }) - }, - }, - ] - } - return queryFeature('DeveloperTools', providers) -} - /** * A type alias that represents all Query features available for use with `provideTanStackQuery`. * Features can be enabled by adding special functions to the `provideTanStackQuery` call. * See documentation for each symbol to find corresponding function name. See also `provideTanStackQuery` * documentation on how to use those functions. - * @public * @see {@link provideTanStackQuery} */ export type QueryFeatures = DeveloperToolsFeature | PersistQueryClientFeature - -export const queryFeatures = ['DeveloperTools', 'PersistQueryClient'] as const - -export type QueryFeatureKind = (typeof queryFeatures)[number] diff --git a/packages/angular-query-experimental/src/query-options.ts b/packages/angular-query-experimental/src/query-options.ts index e82540bee5..069472b903 100644 --- a/packages/angular-query-experimental/src/query-options.ts +++ b/packages/angular-query-experimental/src/query-options.ts @@ -72,7 +72,6 @@ export type DefinedInitialDataOptions< * ``` * @param options - The query options to tag with the type from `queryFn`. * @returns The tagged query options. - * @public */ export function queryOptions< TQueryFnData = unknown, @@ -105,7 +104,6 @@ export function queryOptions< * ``` * @param options - The query options to tag with the type from `queryFn`. * @returns The tagged query options. - * @public */ export function queryOptions< TQueryFnData = unknown, @@ -138,7 +136,6 @@ export function queryOptions< * ``` * @param options - The query options to tag with the type from `queryFn`. * @returns The tagged query options. - * @public */ export function queryOptions< TQueryFnData = unknown, @@ -171,7 +168,6 @@ export function queryOptions< * ``` * @param options - The query options to tag with the type from `queryFn`. * @returns The tagged query options. - * @public */ export function queryOptions(options: unknown) { return options diff --git a/packages/angular-query-experimental/src/types.ts b/packages/angular-query-experimental/src/types.ts index 7c5e3638c3..caee16822e 100644 --- a/packages/angular-query-experimental/src/types.ts +++ b/packages/angular-query-experimental/src/types.ts @@ -18,9 +18,6 @@ import type { import type { Signal } from '@angular/core' import type { MapToSignals } from './signal-proxy' -/** - * @public - */ export interface CreateBaseQueryOptions< TQueryFnData = unknown, TError = DefaultError, @@ -35,9 +32,6 @@ export interface CreateBaseQueryOptions< TQueryKey > {} -/** - * @public - */ export interface CreateQueryOptions< TQueryFnData = unknown, TError = DefaultError, @@ -54,18 +48,12 @@ export interface CreateQueryOptions< 'suspense' > {} -/** - * @public - */ type CreateStatusBasedQueryResult< TStatus extends QueryObserverResult['status'], TData = unknown, TError = DefaultError, > = Extract, { status: TStatus }> -/** - * @public - */ export interface BaseQueryNarrowing { isSuccess: ( this: CreateBaseQueryResult, @@ -90,9 +78,6 @@ export interface BaseQueryNarrowing { > } -/** - * @public - */ export interface CreateInfiniteQueryOptions< TQueryFnData = unknown, TError = DefaultError, @@ -110,9 +95,6 @@ export interface CreateInfiniteQueryOptions< 'suspense' > {} -/** - * @public - */ export type CreateBaseQueryResult< TData = unknown, TError = DefaultError, @@ -120,17 +102,11 @@ export type CreateBaseQueryResult< > = BaseQueryNarrowing & MapToSignals> -/** - * @public - */ export type CreateQueryResult< TData = unknown, TError = DefaultError, > = CreateBaseQueryResult -/** - * @public - */ export type DefinedCreateQueryResult< TData = unknown, TError = DefaultError, @@ -138,18 +114,12 @@ export type DefinedCreateQueryResult< > = BaseQueryNarrowing & MapToSignals> -/** - * @public - */ export type CreateInfiniteQueryResult< TData = unknown, TError = DefaultError, > = BaseQueryNarrowing & MapToSignals> -/** - * @public - */ export type DefinedCreateInfiniteQueryResult< TData = unknown, TError = DefaultError, @@ -169,9 +139,6 @@ export interface CreateMutationOptions< '_defaulted' > {} -/** - * @public - */ export type CreateMutateFunction< TData = unknown, TError = DefaultError, @@ -181,9 +148,6 @@ export type CreateMutateFunction< ...args: Parameters> ) => void -/** - * @public - */ export type CreateMutateAsyncFunction< TData = unknown, TError = DefaultError, @@ -191,9 +155,6 @@ export type CreateMutateAsyncFunction< TContext = unknown, > = MutateFunction -/** - * @public - */ export type CreateBaseMutationResult< TData = unknown, TError = DefaultError, @@ -206,9 +167,6 @@ export type CreateBaseMutationResult< mutateAsync: CreateMutateAsyncFunction } -/** - * @public - */ type CreateStatusBasedMutationResult< TStatus extends CreateBaseMutationResult['status'], TData = unknown, @@ -222,9 +180,6 @@ type CreateStatusBasedMutationResult< type SignalFunction any> = T & Signal> -/** - * @public - */ export interface BaseMutationNarrowing< TData = unknown, TError = DefaultError, @@ -301,9 +256,6 @@ export interface BaseMutationNarrowing< > } -/** - * @public - */ export type CreateMutationResult< TData = unknown, TError = DefaultError, diff --git a/packages/angular-query-experimental/src/util/is-dev-mode/is-dev-mode.ts b/packages/angular-query-experimental/src/util/is-dev-mode/is-dev-mode.ts deleted file mode 100644 index 5c18cfcf51..0000000000 --- a/packages/angular-query-experimental/src/util/is-dev-mode/is-dev-mode.ts +++ /dev/null @@ -1,3 +0,0 @@ -// Re-export for mocking in tests - -export { isDevMode } from '@angular/core' diff --git a/packages/angular-query-experimental/vite.config.ts b/packages/angular-query-experimental/vite.config.ts index e977cbc0d0..aae5cde9af 100644 --- a/packages/angular-query-experimental/vite.config.ts +++ b/packages/angular-query-experimental/vite.config.ts @@ -111,9 +111,16 @@ export default mergeConfig( config, tanstackViteConfig({ cjs: false, - entry: ['./src/index.ts', './src/inject-queries-experimental/index.ts'], - exclude: ['./src/__tests__'], + entry: [ + './src/index.ts', + './src/inject-queries-experimental/index.ts', + './src/devtools-panel/index.ts', + './src/devtools-panel/stub.ts', + './src/devtools/index.ts', + './src/devtools/stub.ts', + ], + exclude: ['src/__tests__'], srcDir: './src', - tsconfigPath: './tsconfig.prod.json', + tsconfigPath: 'tsconfig.prod.json', }), ) diff --git a/packages/angular-query-persist-client/package.json b/packages/angular-query-persist-client/package.json index 69650e4f90..3f455949cf 100644 --- a/packages/angular-query-persist-client/package.json +++ b/packages/angular-query-persist-client/package.json @@ -26,8 +26,8 @@ "test:types:ts53": "node ../../node_modules/typescript53/lib/tsc.js --build", "test:types:ts54": "node ../../node_modules/typescript54/lib/tsc.js --build", "test:types:ts55": "node ../../node_modules/typescript55/lib/tsc.js --build", - "test:types:ts56": "node ../../node_modules/typescript56/lib/tsc.js --build", - "test:types:ts57": "node ../../node_modules/typescript57/lib/tsc.js --build", + "test:types:ts56": "node ../../node_modules/typescript56/lib/tsc.js --build", + "test:types:ts57": "node ../../node_modules/typescript57/lib/tsc.js --build", "test:types:tscurrent": "tsc --build", "test:lib": "vitest", "test:lib:dev": "pnpm run test:lib --watch", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 3939ea1d6b..17e4257268 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -5,7 +5,6 @@ settings: excludeLinksFromLockfile: false overrides: - '@tanstack/angular-query-devtools-experimental': workspace:* '@tanstack/angular-query-experimental': workspace:* '@tanstack/eslint-plugin-query': workspace:* '@tanstack/query-async-storage-persister': workspace:* @@ -293,9 +292,6 @@ importers: '@angular/router': specifier: ^20.0.0 version: 20.0.0(@angular/common@20.0.0(@angular/core@20.0.0(@angular/compiler@20.0.0)(rxjs@7.8.2)(zone.js@0.15.0))(rxjs@7.8.2))(@angular/core@20.0.0(@angular/compiler@20.0.0)(rxjs@7.8.2)(zone.js@0.15.0))(@angular/platform-browser@20.0.0(@angular/animations@20.0.0(@angular/common@20.0.0(@angular/core@20.0.0(@angular/compiler@20.0.0)(rxjs@7.8.2)(zone.js@0.15.0))(rxjs@7.8.2))(@angular/core@20.0.0(@angular/compiler@20.0.0)(rxjs@7.8.2)(zone.js@0.15.0)))(@angular/common@20.0.0(@angular/core@20.0.0(@angular/compiler@20.0.0)(rxjs@7.8.2)(zone.js@0.15.0))(rxjs@7.8.2))(@angular/core@20.0.0(@angular/compiler@20.0.0)(rxjs@7.8.2)(zone.js@0.15.0)))(rxjs@7.8.2) - '@tanstack/angular-query-devtools-experimental': - specifier: workspace:* - version: link:../../../packages/angular-query-devtools-experimental '@tanstack/angular-query-experimental': specifier: workspace:* version: link:../../../packages/angular-query-experimental @@ -2243,39 +2239,11 @@ importers: specifier: ^2.2.8 version: 2.2.8(typescript@5.8.3) - packages/angular-query-devtools-experimental: - dependencies: - '@angular/common': - specifier: '>=16.0.0' - version: 20.0.0(@angular/core@20.0.0(@angular/compiler@20.0.0)(rxjs@7.8.2)(zone.js@0.15.0))(rxjs@7.8.2) - '@tanstack/query-devtools': - specifier: workspace:* - version: link:../query-devtools - devDependencies: - '@angular/core': - specifier: ^20.0.0 - version: 20.0.0(@angular/compiler@20.0.0)(rxjs@7.8.2)(zone.js@0.15.0) - '@angular/platform-browser': - specifier: ^20.0.0 - version: 20.0.0(@angular/animations@20.0.0(@angular/common@20.0.0(@angular/core@20.0.0(@angular/compiler@20.0.0)(rxjs@7.8.2)(zone.js@0.15.0))(rxjs@7.8.2))(@angular/core@20.0.0(@angular/compiler@20.0.0)(rxjs@7.8.2)(zone.js@0.15.0)))(@angular/common@20.0.0(@angular/core@20.0.0(@angular/compiler@20.0.0)(rxjs@7.8.2)(zone.js@0.15.0))(rxjs@7.8.2))(@angular/core@20.0.0(@angular/compiler@20.0.0)(rxjs@7.8.2)(zone.js@0.15.0)) - '@tanstack/angular-query-experimental': - specifier: workspace:* - version: link:../angular-query-experimental - eslint-plugin-jsdoc: - specifier: ^50.5.0 - version: 50.5.0(eslint@9.29.0(jiti@2.4.2)) - npm-run-all2: - specifier: ^5.0.0 - version: 5.0.2 - packages/angular-query-experimental: dependencies: '@tanstack/query-core': specifier: workspace:* version: link:../query-core - '@tanstack/query-devtools': - specifier: workspace:* - version: link:../query-devtools devDependencies: '@angular/common': specifier: ^20.0.0 @@ -2307,6 +2275,10 @@ importers: vite-tsconfig-paths: specifier: ^5.1.4 version: 5.1.4(typescript@5.8.3)(vite@6.3.5(@types/node@22.15.3)(jiti@2.4.2)(less@4.3.0)(lightningcss@1.29.2)(sass@1.88.0)(terser@5.39.1)(tsx@4.20.1)(yaml@2.8.0)) + optionalDependencies: + '@tanstack/query-devtools': + specifier: workspace:* + version: link:../query-devtools publishDirectory: dist packages/angular-query-persist-client: diff --git a/scripts/publish.ts b/scripts/publish.ts index a643bdf266..4b0d1e176d 100644 --- a/scripts/publish.ts +++ b/scripts/publish.ts @@ -82,10 +82,6 @@ await publish({ name: '@tanstack/vue-query-devtools', packageDir: 'packages/vue-query-devtools', }, - { - name: '@tanstack/angular-query-devtools-experimental', - packageDir: 'packages/angular-query-devtools-experimental', - }, { name: '@tanstack/angular-query-experimental', packageDir: 'packages/angular-query-experimental',