import { Injector, Signal, Provider, EnvironmentProviders } from '@angular/core'; import { QueryKey, QueryFunctionContext, DefaultError, WithRequired, QueryObserverOptions, DataTag, QueryObserverResult, InfiniteData, InfiniteQueryObserverOptions, InfiniteQueryObserverResult, QueryFilters, MutationFilters, MutationObserverOptions, MutateOptions, MutationObserver, MutationObserverResult, DefinedQueryObserverResult, QueryClient as QueryClient$1, FetchQueryOptions, FetchInfiniteQueryOptions, QueryObserverLoadingErrorResult, QueryObserverSuccessResult, QueryClientConfig, QueryObserverBaseResult } from '@tanstack/query-core'; export * from '@tanstack/query-core'; import { Observable, OperatorFunction, MonoTypeOperatorFunction } from 'rxjs'; type QueryFunctionWithObservable = (context: QueryFunctionContext) => T | Promise | Observable; interface Options { injector?: Injector; } interface _CreateBaseQueryOptions extends WithRequired, 'queryKey'>, Options { } type CreateBaseQueryOptions = Omit<_CreateBaseQueryOptions, 'queryFn'> & { queryFn: QueryFunctionWithObservable; }; type UndefinedInitialDataOptions = CreateBaseQueryOptions & { initialData?: undefined; }; type NonUndefinedGuard = T extends undefined ? never : T; type DefinedInitialDataOptions = CreateBaseQueryOptions & { initialData: NonUndefinedGuard | (() => NonUndefinedGuard); }; declare function queryOptions(options: UndefinedInitialDataOptions): UndefinedInitialDataOptions & { queryKey: DataTag; }; declare function queryOptions(options: DefinedInitialDataOptions): DefinedInitialDataOptions & { queryKey: DataTag; }; declare function queryOptions(options: CreateInfiniteQueryOptions): CreateInfiniteQueryOptions & { queryKey: DataTag; }; type ObservableQueryResult = Observable>; type SignalQueryResult = Signal>; type Result = { result$: Observable; result: Signal; updateOptions(options: UndefinedInitialDataOptions | DefinedInitialDataOptions): void; }; interface _CreateInfiniteQueryOptions extends WithRequired, 'queryKey'>, Options { } type CreateInfiniteQueryOptions = Omit<_CreateInfiniteQueryOptions, 'queryFn'> & { queryFn: QueryFunctionWithObservable; }; interface InfiniteQueryObject { use: , TQueryKey extends QueryKey = QueryKey, TPageParam = unknown>(options: CreateInfiniteQueryOptions) => Result>; } /** * * Optionally pass an injector that will be used than the current one. * Can be useful if you want to use it in ngOnInit hook for example. * * @example * * injector = inject(Injector); * * ngOnInit() { * const infiniteQuery = injectInfiniteQuery({ injector: this.injector }); * } * */ declare function injectInfiniteQuery(options?: { injector?: Injector; }): , TQueryKey extends QueryKey = readonly unknown[], TPageParam = unknown>(options: CreateInfiniteQueryOptions) => Result>; interface IsFetchingObject { use: (filters?: QueryFilters) => { result$: Observable; toSignal: () => Signal; }; } /** * * Optionally pass an injector that will be used than the current one. * Can be useful if you want to use it in ngOnInit hook for example. * * @example * * injector = inject(Injector); * * ngOnInit() { * const isFetching = injectIsFetching({ injector: this.injector }); * } * */ declare function injectIsFetching(options?: { injector?: Injector; }): (filters?: QueryFilters) => { result$: Observable; toSignal: () => Signal; }; interface IsMutatingObject { use: (filters?: MutationFilters) => { result$: Observable; toSignal: () => Signal; }; } /** * * Optionally pass an injector that will be used than the current one. * Can be useful if you want to use it in ngOnInit hook for example. * * @example * * injector = inject(Injector); * * ngOnInit() { * const isMutating = injectIsMutating({ injector: this.injector }); * } * */ declare function injectIsMutating(options?: { injector?: Injector; }): (filters?: MutationFilters) => { result$: Observable; toSignal: () => Signal; }; type CreateMutationOptions = Omit, 'mutationFn'> & { mutationFn: (variables: TVariables) => Promise | Observable; }; type MutationResult = { mutateAsync: (variables: TVariables, options?: MutateOptions) => Promise; mutate: (variables: TVariables, options?: MutateOptions) => void; reset: MutationObserver['reset']; setOptions: MutationObserver['setOptions']; result$: Observable>; result: Signal>; }; interface MutationObject { use: (options: CreateMutationOptions) => MutationResult; } /** * * Optionally pass an injector that will be used than the current one. * Can be useful if you want to use it in ngOnInit hook for example. * * @example * * injector = inject(Injector); * * ngOnInit() { * const mutation = injectMutation({ injector: this.injector }); * } * */ declare function injectMutation(options?: { injector?: Injector; }): (options: CreateMutationOptions) => MutationResult; interface QueryObject { use: ((options: UndefinedInitialDataOptions) => Result>) | ((options: DefinedInitialDataOptions) => Result>) | ((options: CreateBaseQueryOptions) => any); } /** * * Optionally pass an injector that will be used than the current one. * Can be useful if you want to use it in ngOnInit hook for example. * * @example * * injector = inject(Injector); * * ngOnInit() { * const todos = getTodos({ injector: this.injector }).result; * } * */ declare function injectQuery(options?: { injector?: Injector; }): { (options: UndefinedInitialDataOptions): Result>; (options: DefinedInitialDataOptions): Result>; }; /** @public */ declare function provideQueryClient(queryClientOrFactory: QueryClient$1 | (() => QueryClient$1)): Provider; /** @public */ declare function injectQueryClient(): QueryClient; /** should be exported for @test */ declare class QueryClient extends QueryClient$1 { #private; /** * * Asynchronous function that can be used to get an existing query's cached data. * If the query does not exist, queryClient.fetchQuery will be called and its results * returned. * * @example * * queryClient = injectQueryClient(); * * const data = await queryClient.ensureQueryData({ queryKey, queryFn }) * */ ensureQueryData(options: CreateBaseQueryOptions): Promise; ensureQueryData(options: FetchQueryOptions): Promise; /** * * Asynchronous method that can be used to fetch and cache a query. * It will either resolve with the data or throw with the error. * Use the prefetchQuery method if you just want to fetch a query without * needing the result. * If the query exists and the data is not invalidated or older than the given * staleTime, then the data from the cache will be returned. * Otherwise it will try to fetch the latest data. * * @example * * queryClient = injectQueryClient(); * * const data = await queryClient.fetchQuery({ queryKey, queryFn }) * */ fetchQuery(options: CreateBaseQueryOptions): Promise; fetchQuery(options: FetchQueryOptions): Promise; /** * * Asynchronous method that can be used to prefetch a query before * it is needed or rendered with useQuery and friends. * The method works the same as fetchQuery except that it will not * throw or return any data. * * @example * * queryClient = injectQueryClient(); * * await queryClient.prefetchQuery({ queryKey, queryFn }) * */ prefetchQuery(options: CreateBaseQueryOptions): Promise; prefetchQuery(options: FetchQueryOptions): Promise; /** * * Similar to fetchQuery but can be used to fetch and cache an infinite query * * @example * * queryClient = injectQueryClient(); * * const data = await queryClient.fetchInfiniteQuery({ queryKey, queryFn, initialPageParam, getPreviousPageParam, getNextPageParam }) }) * */ fetchInfiniteQuery(options: CreateInfiniteQueryOptions): Promise>; fetchInfiniteQuery(options: FetchInfiniteQueryOptions): Promise>; /** * * Similar to prefetchQuery but can be used to prefetch and cache an infinite query. * * @example * * queryClient = injectQueryClient(); * * await queryClient.prefetchInfiniteQuery({ queryKey, queryFn, initialPageParam, getPreviousPageParam, getNextPageParam }) * */ prefetchInfiniteQuery(options: CreateInfiniteQueryOptions): Promise; prefetchInfiniteQuery(options: FetchInfiniteQueryOptions): Promise; } declare function mapResultData(mapFn: (data: NonNullable) => R): OperatorFunction>; declare function filterSuccessResult(): OperatorFunction, QueryObserverSuccessResult>; declare function filterErrorResult(): OperatorFunction, QueryObserverLoadingErrorResult>; declare function tapSuccessResult(cb: (data: NonNullable) => void): MonoTypeOperatorFunction; declare function tapErrorResult(cb: (error: NonNullable) => void): MonoTypeOperatorFunction; /** * An operator that takes values emitted by the source observable * until the `isFetching` property on the result is false. * It is intended to be used in scenarios where an observable stream should be listened to * until the result has finished fetching (e.g success or error). */ declare function takeUntilResultFinalize(): MonoTypeOperatorFunction; /** * An operator that takes values emitted by the source observable * until the `isSuccess` property on the result is true. * It is intended to be used in scenarios where an observable stream should be listened to * until a successful result is emitted. */ declare function takeUntilResultSuccess(): MonoTypeOperatorFunction; /** * An operator that takes values emitted by the source observable * until the `isError` property on the result is true. * It is intended to be used in scenarios where an observable stream should be listened to * until an error result is emitted. */ declare function takeUntilResultError(): MonoTypeOperatorFunction; declare function startWithPendingQueryResult(): MonoTypeOperatorFunction; type DataTypes$1>> = { [P in keyof T]: T[P] extends QueryObserverResult ? R : never; }; type UnifiedTypes$1 = T extends Array> ? DataTypes$1 : T extends Record> ? DataTypes$1 : never; /** * * This operator is used to merge multiple queries into one. * It will return a new base query result that will merge the results of all the queries. * * @example * * const query = combineLatest({ * todos: todos.result$, * posts: posts.result$, * }).pipe( * intersectResults$(({ todos, posts }) => { * return { ... } * }) * ) * @example * * const query = combineLatest([todos.result$, posts.result$]).pipe( * intersectResults$(([todos, posts]) => { * return { ... } * }) * ) */ declare function intersectResults$> | Record>, R>(mapFn: (values: UnifiedTypes$1) => R): OperatorFunction & { all: T; }>; type QueryClientConfigFn = () => QueryClientConfig; declare function provideQueryClientOptions(options: QueryClientConfig): EnvironmentProviders; declare function provideQueryClientOptions(options: QueryClientConfigFn): EnvironmentProviders; type DataTypes> | Record>>> = { [P in keyof T]: T[P] extends Signal> ? R : never; }; type UnifiedTypes = T extends Array>> ? DataTypes : T extends Record>> ? DataTypes : never; /** * * @experimental * * This function is used to merge multiple signal queries into one. * It will return a new base query result that will merge the results of all the queries. * Note that it should be used inside injection context * * @example * * const query = intersetResults({ * todos: todos.result$, * posts: posts.result$, * }, ({ todos, posts }) => { * return todos + posts; * }) * * * @example * * const query = intersectResults( * [ * this.todosService.getTodo('1').result, * this.todosService.getTodo('2').result, * ], * ([todoOne, todoTwo]) => { * return todoOne.title + todoTwo.title; * } * ); */ declare function intersectResults>> | Record>>, R>(signals: T, mapFn: (values: UnifiedTypes) => R): Signal & { all: T; }>; declare function toPromise({ source, signal, }: { source: Observable; signal?: AbortSignal; }): Promise; declare function createSuccessObserverResult(data: T): QueryObserverResult; declare function createPendingObserverResult(): QueryObserverResult; /** @public */ declare function provideQueryConfig(config: { query?: QueryObject | (() => QueryObject); mutation?: MutationObject | (() => MutationObject); isMutating?: IsMutatingObject | (() => IsMutatingObject); isFetching?: IsFetchingObject | (() => IsFetchingObject); infiniteQuery?: InfiniteQueryObject | (() => InfiniteQueryObject); }): Provider; export { createPendingObserverResult, createSuccessObserverResult, filterErrorResult, filterSuccessResult, injectInfiniteQuery, injectIsFetching, injectIsMutating, injectMutation, injectQuery, injectQueryClient, intersectResults, intersectResults$, mapResultData, provideQueryClient, provideQueryClientOptions, provideQueryConfig, queryOptions, startWithPendingQueryResult, takeUntilResultError, takeUntilResultFinalize, takeUntilResultSuccess, tapErrorResult, tapSuccessResult, toPromise }; export type { CreateMutationOptions, MutationResult, ObservableQueryResult, QueryClientConfigFn, SignalQueryResult };