import { ObservableQuery } from './observableQuery'; import { PrimitiveQuery } from './primitiveQuery'; import { QueryCache } from './queryCache'; import { CancelOptions, NetworkMode, RetryDelayValue, RetryValue } from './retryer'; import { FetchMeta, QueryMeta, Updater } from './typeUtils'; export type QueryStatus = 'pending' | 'error' | 'success'; export type FetchStatus = 'fetching' | 'paused' | 'idle'; export type InitialDataFunction = () => T | undefined; export interface QueryBehavior { onFetch: (context: FetchContext) => void; } export type QueryKeyHashFunction = (queryKey: [string, TVars]) => string; export interface QueryInfoOptions { query: PrimitiveQuery; variables?: TVars; /** * If `false`, failed queries will not retry by default. * If `true`, failed queries will retry infinitely., failureCount: num * If set to an integer number, e.g. 3, failed queries will retry until the failed query count meets that number. * If set to a function `(failureCount, error) => boolean` failed queries will retry until the function returns false. */ retry?: RetryValue; retryDelay?: RetryDelayValue; networkMode?: NetworkMode; gcTime?: number; queryHash?: string; queryKeyHashFn?: QueryKeyHashFunction; initialData?: TQueryData | InitialDataFunction; initialDataUpdatedAt?: number | (() => number | undefined); /** * Set this to `false` to disable structural sharing between query results. * Set this to a function which accepts the old and new data and returns resolved data of the same type to implement custom structural sharing logic. * Defaults to `true`. */ structuralSharing?: boolean | ((oldData: TQueryData | undefined, newData: TQueryData) => TQueryData); _defaulted?: boolean; /** * Additional payload to be stored on each query. * Use this property to pass information that can be used in other places. */ meta?: QueryMeta; /** * Maximum number of pages to store in the data of an infinite query. */ maxPages?: number; pages?: number; } export interface QueryInfoConfig { options: QueryInfoOptions; cache: QueryCache; state?: QueryInfoState; queryHash: string; query: PrimitiveQuery; variables: TVars; } export interface FetchContext { query: PrimitiveQuery; variables: TVars; fetchOptions?: FetchOptions; options: QueryInfoOptions; state: QueryInfoState; fetchFn: () => unknown | Promise; signal: AbortSignal; } export interface SetDataOptions { updatedAt?: number; } export interface QueryInfoState { data: TQueryData | undefined; dataUpdatedAt: number; error: TError | null; errorUpdatedAt: number; fetchMeta: FetchMeta | null; isInvalidated: boolean; status: QueryStatus; fetchStatus: FetchStatus; } export interface FetchOptions { cancelRefetch?: boolean; meta?: FetchMeta; } interface FetchAction { type: 'fetch'; meta?: FetchMeta; } interface SuccessAction { data: TQueryData | undefined; type: 'success'; dataUpdatedAt?: number; manual?: boolean; } interface ErrorAction { type: 'error'; error: unknown; } interface InvalidateAction { type: 'invalidate'; } interface PauseAction { type: 'pause'; } interface ContinueAction { type: 'continue'; } interface SetStateAction { type: 'setState'; state: Partial>; setStateOptions?: SetStateOptions; } export interface SetStateOptions { meta?: any; } export type Action = ContinueAction | ErrorAction | FetchAction | InvalidateAction | PauseAction | SetStateAction | SuccessAction; export interface QueryInfo extends ReturnType> { } export declare function createQueryInfo(config: QueryInfoConfig): { subscribe: (listener: ObservableQuery) => () => void; scheduleGc: () => void; setState: (state: Partial>, setStateOptions?: SetStateOptions) => void; setIsFetchingOptimistic: (value: boolean) => void; fetch: (newOptions?: QueryInfoOptions, fetchOptions?: FetchOptions) => Promise; reset: () => void; cancel: (cancelOptions?: CancelOptions) => Promise; destroy: () => void; invalidate: () => void; queryHash: string; variables: TVars; isStaleByTime: (staleTime?: number) => boolean; isStale: () => boolean; onOnline: () => void; onFocus: () => void; isActive: () => boolean; isDisabled: () => boolean; setData: (updater: Updater, options?: SetDataOptions) => TQueryData | undefined; getObserversCount: () => number; readonly meta: QueryMeta | undefined; readonly options: QueryInfoOptions; readonly state: QueryInfoState; readonly query: PrimitiveQuery; }; export {};