import { QueryClient, RefetchOptions } from './queryClient'; import { FetchOptions, QueryInfo, QueryInfoOptions } from './queryInfo'; export type ThrowOnError = boolean | ((error: unknown, query: QueryInfo) => boolean); type NonFunctionGuard = T extends (...args: any[]) => any ? never : T; export type PlaceholderDataFunction = (previousData: TQueryData | undefined, previousQueryInfo: QueryInfo | undefined) => TQueryData | undefined; export interface ObservableQueryOptions extends Omit, 'pages'> { /** * Set this to `false` to disable automatic refetching when the query mounts or changes query keys. * To refetch the query, use the `refetch` method returned from the `useQuery` instance. * Defaults to `true`. */ enabled?: boolean; /** * The time in milliseconds after datcreateResulta is considered stale. * If set to `Infinity`, the data will never be considered stale. */ staleTime?: number; /** * If set to a number, the query will continuously refetch at this frequency in milliseconds. * If set to a function, the function will be executed with the latest data and query to compute a frequency * Defaults to `false`. */ refetchInterval?: number | false | ((data: TData | undefined, queryInfo: QueryInfo) => number | false | undefined); /** * If set to `true`, the query will continue to refetch while their tab/window is in the background. * Defaults to `false`. */ refetchIntervalInBackground?: boolean; /** * If set to `true`, the query will refetch on window focus if the data is stale. * If set to `false`, the query will not refetch on window focus. * If set to `'always'`, the query will always refetch on window focus. * If set to a function, the function will be executed with the latest data and query to compute the value. * Defaults to `true`. */ refetchOnWindowFocus?: boolean | 'always' | ((queryInfo: QueryInfo) => boolean | 'always'); /** * If set to `true`, the query will refetch on reconnect if the data is stale. * If set to `false`, the query will not refetch on reconnect. * If set to `'always'`, the query will always refetch on reconnect. * If set to a function, the function will be executed with the latest data and query to compute the value. * Defaults to the value of `networkOnline` (`true`) */ refetchOnReconnect?: boolean | 'always' | ((queryInfo: QueryInfo) => boolean | 'always'); /** * If set to `true`, the query will refetch on mount if the data is stale. * If set to `false`, will disable additional instances of a query to trigger background refetches. * If set to `'always'`, the query will always refetch on mount. * If set to a function, the function will be executed with the latest data and query to compute the value * Defaults to `true`. */ refetchOnMount?: boolean | 'always' | ((queryInfo: QueryInfo) => boolean | 'always'); /** * If set to `false`, the query will not be retried on mount if it contains an error. * Defaults to `true`. */ retryOnMount?: boolean; /** * Whether errors should be thrown instead of setting the `error` property. * If set to `true` or `suspense` is `true`, all errors will be thrown to the error boundary. * If set to `false` and `suspense` is `false`, errors are returned as state. * If set to a function, it will be passed the error and the query, and it should return a boolean indicating whether to show the error in an error boundary (`true`) or return the error as state (`false`). * Defaults to `false`. */ throwOnError?: ThrowOnError; /** * This option can be used to transform or select a part of the data returned by the query function. */ select?: (data: TQueryData) => TData; /** * If set to `true`, the query will suspend when `status === 'pending'` * and throw errors when `status === 'error'`. * Defaults to `false`. */ suspense?: boolean; /** * If set, this value will be used as the placeholder data for this particular query observer while the query is still in the `loading` data and no initialData has been provided. */ placeholderData?: NonFunctionGuard | PlaceholderDataFunction; behavior?: (obsQuery: any) => any; _optimisticResults?: boolean; } export interface ObservableQueryBaseResult { data: TData | undefined; error: TError | null; isFetching: boolean; isLoading: boolean; isPlaceholderData: boolean; isStale: boolean; refetch: (options?: RefetchOptions) => Promise>; } export interface ObservableQueryLoadingResult extends ObservableQueryBaseResult { data: undefined; error: null; } export interface ObservableQueryLoadingErrorResult extends ObservableQueryBaseResult { data: undefined; error: TError; } export interface ObservableQuerySuccessResult extends ObservableQueryBaseResult { data: TData; error: null; } export type ObservableQueryResult = ObservableQueryLoadingResult | ObservableQueryLoadingErrorResult | ObservableQuerySuccessResult; export interface ObserverFetchOptions extends FetchOptions { throwOnError?: boolean; } export interface NotifyOptions { listeners?: boolean; } export interface ObservableQuery extends ReturnType> { } type ObservableQueryListener = (result: ObservableQueryResult) => void; export declare const createObservableQuery: (client: QueryClient, initialOptions: ObservableQueryOptions) => { subscribe: (listener: ObservableQueryListener) => () => void; onQueryUpdate: () => void; setOptions: (newOptions?: Partial> | undefined, notifyOptions?: NotifyOptions) => void; destroy: () => void; refetch: (options?: RefetchOptions) => Promise>; fetch: (fetchOptions?: ObserverFetchOptions) => Promise>; updateResult: (notifyOptions?: NotifyOptions) => void; getCurrentResult: () => ObservableQueryResult; shouldFetchOnReconnect: () => boolean; shouldFetchOnWindowFocus: () => boolean; getCurrentQueryInfo: () => QueryInfo; getOptimisticResult: (options: ObservableQueryOptions) => ObservableQueryResult; trackResult: (result: ObservableQueryResult) => ObservableQueryResult; fetchOptimistic(options: ObservableQueryOptions): Promise>; createResult: (queryInfo: QueryInfo, options: ObservableQueryOptions) => ObservableQueryResult; readonly options: ObservableQueryOptions; }; export {};