import { Store } from '@servicetitan/react-ioc'; import type { QueryClientConfig, FetchQueryOptions, QueryKey } from '@tanstack/query-core'; import { QueryClient } from '@tanstack/query-core'; import { AxiosError } from 'axios'; import type { ClientStoreClientOptions } from '../types/client-store-client-options'; import type { QueryInvalidationOptions } from '../types/query-invalidation-options'; import type { GlobalClientOptions } from './client-helpers'; declare global { export interface Window { queryClients?: Map; pageQueryClientCount?: number; } } /** * Manages the TanStack QueryClient instance and provides methods for query manipulation. * Automatically provided when using getQueryClient() helper or can be injected directly. * * @remarks * This store creates and manages a QueryClient with sensible defaults: * - 10-minute stale time * - No refetch on window focus or reconnect * - 3 retry attempts with exponential backoff * - 5-minute garbage collection time * * @example * ```typescript * @injectable() * export class MyStore extends Store { * @inject(QueryClientStore) private queryClient?: QueryClientStore; * * async fetchData() { * return await this.queryClient?.fetchQuery({ * queryKey: ['myapp', 'data'], * queryFn: async () => await api.getData(), * }); * } * } * ``` */ export declare class QueryClientStore extends Store { #private; /** The underlying TanStack QueryClient instance */ queryClient: QueryClient; /** Configuration for global (page/app) client sharing */ globalClientOptions?: GlobalClientOptions; /** * When true, QueryApi/MutationApi skip `window.queryClients` even if `globalClient` is set. * ContainerBuilder sets this on its test client. Production leaves it unset so window sharing still applies. */ isolateFromWindowClients?: boolean; constructor(globalOptions?: GlobalClientOptions, queryConfig?: QueryClientConfig); dispose: () => void; /** * Manually fetches a query without subscribing to it. * Respects caching and stale time settings. * * @template T - The type of data returned by the query * @template TError - The error type * @param queryConfig - Query configuration (queryKey, queryFn, etc.) * @param options - Optional client options (use appClient for app-level cache) * @returns Promise that resolves with a deep clone of the query data * * @example * ```typescript * const report = await queryClientStore.fetchQuery({ * queryKey: ['reporting', 'report', reportId], * queryFn: async () => (await api.getReport(reportId)).data, * }); * ``` */ fetchQuery: (queryConfig: FetchQueryOptions, options?: ClientStoreClientOptions) => Promise; /** * Invalidates queries matching the provided key(s), causing them to refetch. * Invalidates across all query clients (current store client and all shared clients). * Can invalidate multiple queries at once. * * @param keys - Single query key or array of query keys to invalidate * @param options - Optional invalidation options * @param options.dedupe - Skip invalidation on a client if query is already invalidated there * @param options.invalidationKey - Use a different key for invalidation than the query key * * @example * ```typescript * // Invalidate a single query * queryClientStore.invalidate(['scheduling', 'jobs']); * * // Invalidate multiple queries * queryClientStore.invalidate([['scheduling', 'jobs'], ['scheduling', 'users']]); * * // Invalidate with deduplication * queryClientStore.invalidate(['scheduling', 'jobs'], { dedupe: true }); * ``` */ invalidate: (keys?: QueryKey | QueryKey[], options?: Omit) => void; /** * Cancels outbound requests for queries matching the provided key(s). * * @param keys - Single query key or array of query keys to cancel * @param options - Optional client options (use appClient for app-level cache) * * @example * ```typescript * // Cancel a single query * queryClientStore.cancel(['scheduling', 'jobs']); * * // Cancel multiple queries * queryClientStore.cancel([['scheduling', 'jobs'], ['scheduling', 'users']]); * ``` */ cancel: (keys?: QueryKey | QueryKey[], options?: ClientStoreClientOptions) => void; /** * Removes queries from the cache completely. * Unlike invalidate, this does not trigger a refetch. * * @param keys - Single query key or array of query keys to remove * * @example * ```typescript * // Remove a single query * queryClientStore.remove(['old', 'data']); * * // Remove multiple queries * queryClientStore.remove([['old', 'data'], ['stale', 'data']]); * ``` */ remove: (keys?: QueryKey | QueryKey[]) => void; } //# sourceMappingURL=query-client.store.d.ts.map