diff --git a/examples/angular/basic/src/app/app.config.ts b/examples/angular/basic/src/app/app.config.ts index b350efc083..db56fd38d5 100644 --- a/examples/angular/basic/src/app/app.config.ts +++ b/examples/angular/basic/src/app/app.config.ts @@ -1,9 +1,9 @@ import { provideHttpClient, withFetch } from '@angular/common/http' -import { ApplicationConfig } from '@angular/core' import { QueryClient, provideAngularQuery, } from '@tanstack/angular-query-experimental' +import type { ApplicationConfig } from '@angular/core' export const appConfig: ApplicationConfig = { providers: [ diff --git a/packages/angular-query-devtools-experimental/src/angular-query-devtools.component.ts b/packages/angular-query-devtools-experimental/src/angular-query-devtools.component.ts index 58f1be3659..568b305427 100644 --- a/packages/angular-query-devtools-experimental/src/angular-query-devtools.component.ts +++ b/packages/angular-query-devtools-experimental/src/angular-query-devtools.component.ts @@ -39,7 +39,9 @@ export class AngularQueryDevtools /* * It is intentional that there are no default values on inputs. * Core devtools will set defaults when values are undefined. - * */ + * + * Signal inputs are not used to remain compatible with previous Angular versions. + */ /** * Add this attribute if you want the dev tools to default to being open diff --git a/packages/angular-query-experimental/src/__tests__/inject-mutation-state.test.ts b/packages/angular-query-experimental/src/__tests__/inject-mutation-state.test.ts index 966af8047b..931a70f44f 100644 --- a/packages/angular-query-experimental/src/__tests__/inject-mutation-state.test.ts +++ b/packages/angular-query-experimental/src/__tests__/inject-mutation-state.test.ts @@ -3,7 +3,6 @@ import { QueryClient } from '@tanstack/query-core' import { TestBed } from '@angular/core/testing' import { describe, expect, test, vi } from 'vitest' import { By } from '@angular/platform-browser' -import { JsonPipe } from '@angular/common' import { injectMutation } from '../inject-mutation' import { injectMutationState } from '../inject-mutation-state' import { provideAngularQuery } from '../providers' @@ -139,7 +138,6 @@ describe('injectMutationState', () => { } `, standalone: true, - imports: [JsonPipe], }) class FakeComponent { name = input.required() diff --git a/packages/angular-query-experimental/src/create-base-query.ts b/packages/angular-query-experimental/src/create-base-query.ts index 7fd249020f..a834fb6cd0 100644 --- a/packages/angular-query-experimental/src/create-base-query.ts +++ b/packages/angular-query-experimental/src/create-base-query.ts @@ -31,7 +31,7 @@ export function createBaseQuery< TQueryData, TQueryKey extends QueryKey, >( - options: ( + optionsFn: ( client: QueryClient, ) => CreateBaseQueryOptions< TQueryFnData, @@ -57,7 +57,7 @@ export function createBaseQuery< */ const defaultedOptionsSignal = computed(() => { const defaultedOptions = queryClient.defaultQueryOptions( - options(queryClient), + optionsFn(queryClient), ) defaultedOptions._optimisticResults = 'optimistic' return defaultedOptions diff --git a/packages/angular-query-experimental/src/index.ts b/packages/angular-query-experimental/src/index.ts index d56be2adba..7f87c5a684 100644 --- a/packages/angular-query-experimental/src/index.ts +++ b/packages/angular-query-experimental/src/index.ts @@ -20,9 +20,5 @@ export * from './inject-mutation' export * from './inject-mutation-state' export * from './inject-queries' export * from './inject-query' -export { - injectQueryClient, - provideQueryClient, - QUERY_CLIENT, -} from './inject-query-client' +export { injectQueryClient, provideQueryClient } from './inject-query-client' export { provideAngularQuery } 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 dae1cdd848..1680e5d408 100644 --- a/packages/angular-query-experimental/src/infinite-query-options.ts +++ b/packages/angular-query-experimental/src/infinite-query-options.ts @@ -41,6 +41,14 @@ export type DefinedInitialDataInfiniteOptions< | (() => NonUndefinedGuard>) } +/** + * Allows to share and re-use infinite query options in a type-safe way. + * + * 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, TError = DefaultError, @@ -65,6 +73,14 @@ export function infiniteQueryOptions< queryKey: DataTag> } +/** + * Allows to share and re-use infinite query options in a type-safe way. + * + * 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, TError = DefaultError, @@ -89,6 +105,14 @@ export function infiniteQueryOptions< queryKey: DataTag> } +/** + * Allows to share and re-use infinite query options in a type-safe way. + * + * 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 42a0f64381..afcb1ea0d8 100644 --- a/packages/angular-query-experimental/src/inject-infinite-query.ts +++ b/packages/angular-query-experimental/src/inject-infinite-query.ts @@ -20,6 +20,14 @@ import type { UndefinedInitialDataInfiniteOptions, } from './infinite-query-options' +/** + * 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" + * @param optionsFn - A function that returns infinite query options. + * @param injector - The Angular injector to use. + * @returns The infinite query result. + * @public + */ export function injectInfiniteQuery< TQueryFnData, TError = DefaultError, @@ -27,7 +35,7 @@ export function injectInfiniteQuery< TQueryKey extends QueryKey = QueryKey, TPageParam = unknown, >( - options: ( + optionsFn: ( client: QueryClient, ) => UndefinedInitialDataInfiniteOptions< TQueryFnData, @@ -39,6 +47,14 @@ export function injectInfiniteQuery< injector?: Injector, ): CreateInfiniteQueryResult +/** + * 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" + * @param optionsFn - A function that returns infinite query options. + * @param injector - The Angular injector to use. + * @returns The infinite query result. + * @public + */ export function injectInfiniteQuery< TQueryFnData, TError = DefaultError, @@ -46,7 +62,7 @@ export function injectInfiniteQuery< TQueryKey extends QueryKey = QueryKey, TPageParam = unknown, >( - options: ( + optionsFn: ( client: QueryClient, ) => DefinedInitialDataInfiniteOptions< TQueryFnData, @@ -58,6 +74,14 @@ export function injectInfiniteQuery< injector?: Injector, ): DefinedCreateInfiniteQueryResult +/** + * 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" + * @param optionsFn - A function that returns infinite query options. + * @param injector - The Angular injector to use. + * @returns The infinite query result. + * @public + */ export function injectInfiniteQuery< TQueryFnData, TError = DefaultError, @@ -65,7 +89,7 @@ export function injectInfiniteQuery< TQueryKey extends QueryKey = QueryKey, TPageParam = unknown, >( - options: ( + optionsFn: ( client: QueryClient, ) => CreateInfiniteQueryOptions< TQueryFnData, @@ -78,14 +102,22 @@ export function injectInfiniteQuery< injector?: Injector, ): CreateInfiniteQueryResult +/** + * 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" + * @param optionsFn - A function that returns infinite query options. + * @param injector - The Angular injector to use. + * @returns The infinite query result. + * @public + */ export function injectInfiniteQuery( - options: (client: QueryClient) => CreateInfiniteQueryOptions, + optionsFn: (client: QueryClient) => CreateInfiniteQueryOptions, injector?: Injector, ) { return assertInjector(injectInfiniteQuery, injector, () => { const queryClient = injectQueryClient() return createBaseQuery( - options, + optionsFn, InfiniteQueryObserver as typeof QueryObserver, queryClient, ) diff --git a/packages/angular-query-experimental/src/inject-is-fetching.ts b/packages/angular-query-experimental/src/inject-is-fetching.ts index 492e07a495..2e7765af92 100644 --- a/packages/angular-query-experimental/src/inject-is-fetching.ts +++ b/packages/angular-query-experimental/src/inject-is-fetching.ts @@ -4,6 +4,16 @@ import { assertInjector } from './util/assert-injector/assert-injector' import { injectQueryClient } from './inject-query-client' import type { Injector, Signal } from '@angular/core' +/** + * Injects a signal that tracks the number of queries that your application is loading or + * fetching in the background. + * + * Can be used for app-wide loading indicators + * @param filters - The filters to apply to the query. + * @param injector - The Angular injector to use. + * @returns signal with number of loading or fetching queries. + * @public + */ export function injectIsFetching( filters?: QueryFilters, injector?: Injector, diff --git a/packages/angular-query-experimental/src/inject-is-mutating.ts b/packages/angular-query-experimental/src/inject-is-mutating.ts index 02541e56a9..833515654b 100644 --- a/packages/angular-query-experimental/src/inject-is-mutating.ts +++ b/packages/angular-query-experimental/src/inject-is-mutating.ts @@ -4,6 +4,15 @@ import { assertInjector } from './util/assert-injector/assert-injector' import { injectQueryClient } from './inject-query-client' import type { Injector, Signal } from '@angular/core' +/** + * Injects a signal that tracks the number of mutations that your application is fetching. + * + * Can be used for app-wide loading indicators + * @param filters - The filters to apply to the query. + * @param injector - The Angular injector to use. + * @returns signal with number of fetching mutations. + * @public + */ export function injectIsMutating( filters?: MutationFilters, injector?: Injector, diff --git a/packages/angular-query-experimental/src/inject-mutation-state.ts b/packages/angular-query-experimental/src/inject-mutation-state.ts index 653fc6108a..00cf66c193 100644 --- a/packages/angular-query-experimental/src/inject-mutation-state.ts +++ b/packages/angular-query-experimental/src/inject-mutation-state.ts @@ -43,10 +43,20 @@ function getResult( ) } +/** + * @public + */ export interface InjectMutationStateOptions { injector?: Injector } +/** + * Injects a signal that tracks the state of all mutations. + * @param mutationStateOptionsFn - 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( mutationStateOptionsFn: () => MutationStateOptions = () => ({}), options?: InjectMutationStateOptions, diff --git a/packages/angular-query-experimental/src/inject-mutation.ts b/packages/angular-query-experimental/src/inject-mutation.ts index 7bd474451e..f7948df617 100644 --- a/packages/angular-query-experimental/src/inject-mutation.ts +++ b/packages/angular-query-experimental/src/inject-mutation.ts @@ -26,13 +26,22 @@ import type { CreateMutationResult, } from './types' +/** + * Injects a mutation: an imperative function that can be invoked which typically performs server side effects. + * + * Unlike queries, mutations are not run automatically. + * @param optionsFn - A function that returns mutation options. + * @param injector - The Angular injector to use. + * @returns The mutation. + * @public + */ export function injectMutation< TData = unknown, TError = DefaultError, TVariables = void, TContext = unknown, >( - options: ( + optionsFn: ( client: QueryClient, ) => CreateMutationOptions, injector?: Injector, @@ -50,7 +59,7 @@ export function injectMutation< TError, TVariables, TContext - >(queryClient, options(queryClient)) + >(queryClient, optionsFn(queryClient)) const mutate: CreateMutateFunction< TData, TError, @@ -61,7 +70,7 @@ export function injectMutation< } effect(() => { - observer.setOptions(options(queryClient)) + observer.setOptions(optionsFn(queryClient)) }) const result = signal(observer.getCurrentResult()) diff --git a/packages/angular-query-experimental/src/inject-queries.ts b/packages/angular-query-experimental/src/inject-queries.ts index c6edc9c010..3e47a02295 100644 --- a/packages/angular-query-experimental/src/inject-queries.ts +++ b/packages/angular-query-experimental/src/inject-queries.ts @@ -119,6 +119,7 @@ type GetResults = /** * QueriesOptions reducer recursively unwraps function arguments to infer/enforce type param + * @public */ export type QueriesOptions< T extends Array, @@ -161,6 +162,7 @@ export type QueriesOptions< /** * QueriesResults reducer recursively maps type param to results + * @public */ export type QueriesResults< T extends Array, @@ -196,6 +198,9 @@ export type QueriesResults< : // Fallback Array +/** + * @public + */ export function injectQueries< T extends Array, TCombinedResult = QueriesResults, diff --git a/packages/angular-query-experimental/src/inject-query-client.ts b/packages/angular-query-experimental/src/inject-query-client.ts index f72b446a54..e570782038 100644 --- a/packages/angular-query-experimental/src/inject-query-client.ts +++ b/packages/angular-query-experimental/src/inject-query-client.ts @@ -1,7 +1,25 @@ import { createNoopInjectionToken } from './util/create-injection-token/create-injection-token' import type { QueryClient } from '@tanstack/query-core' -const [injectQueryClient, provideQueryClient, QUERY_CLIENT] = - createNoopInjectionToken('QueryClientToken') +const tokens = createNoopInjectionToken('QueryClientToken') -export { injectQueryClient, provideQueryClient, QUERY_CLIENT } +/** + * Injects the `QueryClient` instance into the component or service. + * + * **Example** + * ```ts + * const queryClient = injectQueryClient(); + * ``` + * @returns The `QueryClient` instance. + * @public + */ +export const injectQueryClient = tokens[0] + +/** + * Usually {@link provideAngularQuery} is used once to set up TanStack Query and the + * {@link https://tanstack.com/query/latest/docs/reference/QueryClient|QueryClient} + * for the entire application. You can use `provideQueryClient` to provide a + * different `QueryClient` instance for a part of the application. + * @public + */ +export const provideQueryClient = tokens[1] diff --git a/packages/angular-query-experimental/src/inject-query.ts b/packages/angular-query-experimental/src/inject-query.ts index 22f6f5de2e..6d67674c40 100644 --- a/packages/angular-query-experimental/src/inject-query.ts +++ b/packages/angular-query-experimental/src/inject-query.ts @@ -15,44 +15,176 @@ import type { UndefinedInitialDataOptions, } from './query-options' +/** + * Injects a query: a declarative dependency on an asynchronous source of data that is tied to a unique key. + * + * **Basic example** + * ```ts + * class ServiceOrComponent { + * query = injectQuery(() => ({ + * queryKey: ['repoData'], + * queryFn: () => + * this.#http.get('https://api.github.com/repos/tanstack/query'), + * })) + * } + * ``` + * + * **The options function can utilize signals** + * ```ts + * class ServiceOrComponent { + * filter = signal('') + * + * todosQuery = injectQuery(() => ({ + * queryKey: ['todos', this.filter()], + * queryFn: () => fetchTodos(this.filter()), + * // Signals can be combined with expressions + * enabled: !!this.filter(), + * })) + * } + * ``` + * @param optionsFn - A function that returns query options. + * @param injector - The Angular injector to use. + * @returns The query result. + * @public + * @see https://tanstack.com/query/latest/docs/framework/angular/guides/queries + */ export function injectQuery< TQueryFnData = unknown, TError = DefaultError, TData = TQueryFnData, TQueryKey extends QueryKey = QueryKey, >( - options: ( + optionsFn: ( client: QueryClient, - ) => UndefinedInitialDataOptions, + ) => DefinedInitialDataOptions, injector?: Injector, -): CreateQueryResult +): DefinedCreateQueryResult +/** + * Injects a query: a declarative dependency on an asynchronous source of data that is tied to a unique key. + * + * **Basic example** + * ```ts + * class ServiceOrComponent { + * query = injectQuery(() => ({ + * queryKey: ['repoData'], + * queryFn: () => + * this.#http.get('https://api.github.com/repos/tanstack/query'), + * })) + * } + * ``` + * + * **The options function can utilize signals** + * ```ts + * class ServiceOrComponent { + * filter = signal('') + * + * todosQuery = injectQuery(() => ({ + * queryKey: ['todos', this.filter()], + * queryFn: () => fetchTodos(this.filter()), + * // Signals can be combined with expressions + * enabled: !!this.filter(), + * })) + * } + * ``` + * @param optionsFn - A function that returns query options. + * @param injector - The Angular injector to use. + * @returns The query result. + * @public + * @see https://tanstack.com/query/latest/docs/framework/angular/guides/queries + */ export function injectQuery< TQueryFnData = unknown, TError = DefaultError, TData = TQueryFnData, TQueryKey extends QueryKey = QueryKey, >( - options: ( + optionsFn: ( client: QueryClient, - ) => DefinedInitialDataOptions, + ) => UndefinedInitialDataOptions, injector?: Injector, -): DefinedCreateQueryResult +): CreateQueryResult +/** + * Injects a query: a declarative dependency on an asynchronous source of data that is tied to a unique key. + * + * **Basic example** + * ```ts + * class ServiceOrComponent { + * query = injectQuery(() => ({ + * queryKey: ['repoData'], + * queryFn: () => + * this.#http.get('https://api.github.com/repos/tanstack/query'), + * })) + * } + * ``` + * + * **The options function can utilize signals** + * ```ts + * class ServiceOrComponent { + * filter = signal('') + * + * todosQuery = injectQuery(() => ({ + * queryKey: ['todos', this.filter()], + * queryFn: () => fetchTodos(this.filter()), + * // Signals can be combined with expressions + * enabled: !!this.filter(), + * })) + * } + * ``` + * @param optionsFn - A function that returns query options. + * @param injector - The Angular injector to use. + * @returns The query result. + * @public + * @see https://tanstack.com/query/latest/docs/framework/angular/guides/queries + */ export function injectQuery< TQueryFnData = unknown, TError = DefaultError, TData = TQueryFnData, TQueryKey extends QueryKey = QueryKey, >( - options: ( + optionsFn: ( client: QueryClient, ) => CreateQueryOptions, injector?: Injector, ): CreateQueryResult +/** + * Injects a query: a declarative dependency on an asynchronous source of data that is tied to a unique key. + * + * **Basic example** + * ```ts + * class ServiceOrComponent { + * query = injectQuery(() => ({ + * queryKey: ['repoData'], + * queryFn: () => + * this.#http.get('https://api.github.com/repos/tanstack/query'), + * })) + * } + * ``` + * + * **The options function can utilize signals** + * ```ts + * class ServiceOrComponent { + * filter = signal('') + * + * todosQuery = injectQuery(() => ({ + * queryKey: ['todos', this.filter()], + * queryFn: () => fetchTodos(this.filter()), + * // Signals can be combined with expressions + * enabled: !!this.filter(), + * })) + * } + * ``` + * @param optionsFn - A function that returns query options. + * @param injector - The Angular injector to use. + * @returns The query result. + * @public + * @see https://tanstack.com/query/latest/docs/framework/angular/guides/queries + */ export function injectQuery( - options: (client: QueryClient) => CreateQueryOptions, + optionsFn: (client: QueryClient) => CreateQueryOptions, injector?: Injector, ) { const assertedInjector = assertInjector(injectQuery, injector) @@ -60,7 +192,7 @@ export function injectQuery( const queryClient = injectQueryClient() return createBaseQuery( (client) => - runInInjectionContext(assertedInjector, () => options(client)), + runInInjectionContext(assertedInjector, () => optionsFn(client)), QueryObserver, queryClient, ) diff --git a/packages/angular-query-experimental/src/providers.ts b/packages/angular-query-experimental/src/providers.ts index 115d4c3ad2..6b5c3cf94a 100644 --- a/packages/angular-query-experimental/src/providers.ts +++ b/packages/angular-query-experimental/src/providers.ts @@ -8,6 +8,45 @@ import { provideQueryClient } from './inject-query-client' import type { EnvironmentProviders } from '@angular/core' import type { QueryClient } from '@tanstack/query-core' +/** + * Sets up providers necessary to enable TanStack Query functionality for Angular applications. + * + * Allows to configure a `QueryClient`. + * + * **Example - standalone** + * + * ```ts + * import { + * provideAngularQuery, + * QueryClient, + * } from '@tanstack/angular-query-experimental' + * + * bootstrapApplication(AppComponent, { + * providers: [provideAngularQuery(new QueryClient())], + * }) + * ``` + * + * **Example - NgModule-based** + * + * ```ts + * import { + * provideAngularQuery, + * QueryClient, + * } from '@tanstack/angular-query-experimental' + * + * @NgModule({ + * declarations: [AppComponent], + * imports: [BrowserModule], + * providers: [provideAngularQuery(new QueryClient())], + * bootstrap: [AppComponent], + * }) + * export class AppModule {} + * ``` + * @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 + */ export function provideAngularQuery( queryClient: QueryClient, ): EnvironmentProviders { diff --git a/packages/angular-query-experimental/src/query-options.ts b/packages/angular-query-experimental/src/query-options.ts index 7e958f3df7..dbc3b32460 100644 --- a/packages/angular-query-experimental/src/query-options.ts +++ b/packages/angular-query-experimental/src/query-options.ts @@ -1,6 +1,9 @@ import type { DataTag, DefaultError, QueryKey } from '@tanstack/query-core' import type { CreateQueryOptions } from './types' +/** + * @public + */ export type UndefinedInitialDataOptions< TQueryFnData = unknown, TError = DefaultError, @@ -12,6 +15,9 @@ export type UndefinedInitialDataOptions< type NonUndefinedGuard = T extends undefined ? never : T +/** + * @public + */ export type DefinedInitialDataOptions< TQueryFnData = unknown, TError = DefaultError, @@ -23,6 +29,28 @@ export type DefinedInitialDataOptions< | (() => NonUndefinedGuard) } +/** + * Allows to share and re-use query options in a type-safe way. + * + * The `queryKey` will be tagged with the type from `queryFn`. + * + * **Example** + * + * ```ts + * const { queryKey } = queryOptions({ + * queryKey: ['key'], + * queryFn: () => Promise.resolve(5), + * // ^? Promise + * }) + * + * const queryClient = new QueryClient() + * const data = queryClient.getQueryData(queryKey) + * // ^? number | undefined + * ``` + * @param options - The query options to tag with the type from `queryFn`. + * @returns The tagged query options. + * @public + */ export function queryOptions< TQueryFnData = unknown, TError = DefaultError, @@ -34,6 +62,28 @@ export function queryOptions< queryKey: DataTag } +/** + * Allows to share and re-use query options in a type-safe way. + * + * The `queryKey` will be tagged with the type from `queryFn`. + * + * **Example** + * + * ```ts + * const { queryKey } = queryOptions({ + * queryKey: ['key'], + * queryFn: () => Promise.resolve(5), + * // ^? Promise + * }) + * + * const queryClient = new QueryClient() + * const data = queryClient.getQueryData(queryKey) + * // ^? number | undefined + * ``` + * @param options - The query options to tag with the type from `queryFn`. + * @returns The tagged query options. + * @public + */ export function queryOptions< TQueryFnData = unknown, TError = DefaultError, @@ -45,6 +95,28 @@ export function queryOptions< queryKey: DataTag } +/** + * Allows to share and re-use query options in a type-safe way. + * + * The `queryKey` will be tagged with the type from `queryFn`. + * + * **Example** + * + * ```ts + * const { queryKey } = queryOptions({ + * queryKey: ['key'], + * queryFn: () => Promise.resolve(5), + * // ^? Promise + * }) + * + * const queryClient = new QueryClient() + * const data = queryClient.getQueryData(queryKey) + * // ^? number | undefined + * ``` + * @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/signal-proxy.ts b/packages/angular-query-experimental/src/signal-proxy.ts index 30f3a909d4..e2a9de345f 100644 --- a/packages/angular-query-experimental/src/signal-proxy.ts +++ b/packages/angular-query-experimental/src/signal-proxy.ts @@ -7,11 +7,9 @@ export type MapToSignals = { /** * Exposes fields of an object passed via an Angular `Signal` as `Computed` signals. - * * Functions on the object are passed through as-is. - * * @param inputSignal - `Signal` that must return an object. - * + * @returns A proxy object with the same fields as the input object, but with each field wrapped in a `Computed` signal. */ export function signalProxy>( inputSignal: Signal, diff --git a/packages/angular-query-experimental/src/types.ts b/packages/angular-query-experimental/src/types.ts index 7f29d7dafe..7eb8491951 100644 --- a/packages/angular-query-experimental/src/types.ts +++ b/packages/angular-query-experimental/src/types.ts @@ -16,6 +16,9 @@ import type { } from '@tanstack/query-core' import type { MapToSignals } from './signal-proxy' +/** + * @public + */ export interface CreateBaseQueryOptions< TQueryFnData = unknown, TError = DefaultError, @@ -30,6 +33,9 @@ export interface CreateBaseQueryOptions< TQueryKey > {} +/** + * @public + */ export interface CreateQueryOptions< TQueryFnData = unknown, TError = DefaultError, @@ -46,12 +52,18 @@ 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, @@ -76,6 +88,9 @@ export interface BaseQueryNarrowing { > } +/** + * @public + */ export interface CreateInfiniteQueryOptions< TQueryFnData = unknown, TError = DefaultError, @@ -95,6 +110,9 @@ export interface CreateInfiniteQueryOptions< 'suspense' > {} +/** + * @public + */ export type CreateBaseQueryResult< TData = unknown, TError = DefaultError, @@ -102,22 +120,34 @@ export type CreateBaseQueryResult< > = BaseQueryNarrowing & MapToSignals> +/** + * @public + */ export type CreateQueryResult< TData = unknown, TError = DefaultError, > = CreateBaseQueryResult +/** + * @public + */ export type DefinedCreateQueryResult< TData = unknown, TError = DefaultError, TDefinedQueryObserver = DefinedQueryObserverResult, > = MapToSignals +/** + * @public + */ export type CreateInfiniteQueryResult< TData = unknown, TError = DefaultError, > = MapToSignals> +/** + * @public + */ export type DefinedCreateInfiniteQueryResult< TData = unknown, TError = DefaultError, @@ -127,6 +157,9 @@ export type DefinedCreateInfiniteQueryResult< >, > = MapToSignals +/** + * @public + */ export interface CreateMutationOptions< TData = unknown, TError = DefaultError, @@ -137,6 +170,9 @@ export interface CreateMutationOptions< '_defaulted' > {} +/** + * @public + */ export type CreateMutateFunction< TData = unknown, TError = DefaultError, @@ -146,6 +182,9 @@ export type CreateMutateFunction< ...args: Parameters> ) => void +/** + * @public + */ export type CreateMutateAsyncFunction< TData = unknown, TError = DefaultError, @@ -153,6 +192,9 @@ export type CreateMutateAsyncFunction< TContext = unknown, > = MutateFunction +/** + * @public + */ export type CreateBaseMutationResult< TData = unknown, TError = DefaultError, @@ -165,6 +207,9 @@ export type CreateBaseMutationResult< mutateAsync: CreateMutateAsyncFunction } +/** + * @public + */ type CreateStatusBasedMutationResult< TStatus extends CreateBaseMutationResult['status'], TData = unknown, @@ -176,6 +221,9 @@ type CreateStatusBasedMutationResult< { status: TStatus } > +/** + * @public + */ export interface BaseMutationNarrowing< TData = unknown, TError = DefaultError, @@ -238,6 +286,9 @@ export interface BaseMutationNarrowing< > } +/** + * @public + */ export type CreateMutationResult< TData = unknown, TError = DefaultError,