import { RxQuery, RxDocument } from 'rxdb'; import { DeepReadonly } from 'rxdb/dist/types/types'; import { Override } from './type.helpers'; export type ResultMap = Map>; export type AnyQueryResult = DeepReadonly[] | RxDocument[]; export type RxQueryResult = { /** * Resulting documents. */ result: AnyQueryResult; /** * Indicates that fetching is in progress. */ isFetching: boolean; /** * Indicates that all available results have been already fetched. * Relevant in "infinite scroll" pagination mode */ isExhausted: boolean; /** * Total number of pages, based on total number of results and page size. * Relevant in "traditional" pagination mode */ pageCount: number; /** * The number of the current page. * Relevant in "infinite scroll" pagination mode */ currentPage: number; /** * Allows consumer to request a specific page of results. * Relevant in "traditional" pagination mode */ fetchPage: (page: number) => void; /** * Allows consumer to incrementally request more results. * Relevant in "infinite scroll" pagination mode */ fetchMore: () => void; /** * Allows consumer to reset results. * Relevant in "infinite scroll" pagination mode */ resetList: () => void; }; export type RxQueryResultJSON = Override, { result: DeepReadonly[]; }>; export type RxQueryResultDoc = Override, { result: RxDocument[]; }>; /** * Traditional: * Results are split into pages, starts by rendering the first page and total * pageCount is returned, allowing for requesting results of any specific page. * Requires `pageSize` to be defined * * Infinite: * First page of results is rendered, allowing for gradually requesting more. * Requires `pageSize` to be defined */ export type PaginationMode = 'Traditional' | 'Infinite'; export interface UseRxQueryOptions { /** * Controls page size, in both "infinite scroll" & "traditional" pagination */ pageSize?: number; /** * Determines pagination mode */ pagination?: PaginationMode; /** * Converts resulting RxDocuments to plain objects */ json?: boolean; } export type ObservableReturningQuery = RxQuery>> | RxQuery | null> | RxQuery[]>; export type AnyRxQuery = ObservableReturningQuery; declare function useRxQuery(query?: AnyRxQuery): RxQueryResultDoc; declare function useRxQuery(query: AnyRxQuery, options?: Override): RxQueryResultDoc; declare function useRxQuery(query: AnyRxQuery, options?: Override): RxQueryResultJSON; export default useRxQuery;