UNPKG

@squidcloud/client

Version:

A typescript implementation of the Squid client

66 lines (65 loc) 2.43 kB
import { Observable } from 'rxjs'; /** * The state of a pagination. * @category Database */ export interface PaginationState<ReturnType> { /** The page data. */ data: Array<ReturnType>; /** Whether there is a next page. */ hasNext: boolean; /** Whether there is a previous page. */ hasPrev: boolean; } /** * Pagination options. * @category Database */ export interface PaginationOptions { /** Whether to show real-time updates. Defaults to true. */ subscribe: boolean; /** The number of items in a page. Defaults to 100. */ pageSize: number; } /** * Pagination provides a paginated view over a dataset, supporting navigation * through pages, real-time updates, and sorting based on predefined criteria. * @category Database */ export declare class Pagination<ReturnType> { private readonly paginateOptions; private internalStateObserver; private firstElement; private readonly isDestroyed; private templateSnapshotEmitter; private snapshotSubject; private onFirstPage; private navigatingToLastPage; private lastElement; /** Unsubscribes from the pagination. */ unsubscribe(): void; /** Returns a promise that resolves when the previous page of data is available. */ prev(): Promise<PaginationState<ReturnType>>; /** Returns a promise that resolves when the next page of data is available. */ next(): Promise<PaginationState<ReturnType>>; /** Returns a promise that resolves when the page data is available. */ waitForData(): Promise<PaginationState<ReturnType>>; /** Returns an observable that emits the current state of the pagination. */ observeState(): Observable<PaginationState<ReturnType>>; /** Jumps to the first page of the pagination. */ first(): Promise<PaginationState<ReturnType>>; /** Refreshes the current page of the pagination. */ refreshPage(): Promise<PaginationState<ReturnType>>; /** * Jumps to the last page of the pagination. This page will always have the last `pageSize` elements of the * underlying query, regardless of whether the total document count is evenly divisible by the page size. */ last(): Promise<PaginationState<ReturnType>>; private goToFirstPage; private compareObjects; private dataReceived; private doNewQuery; private waitForInternalState; private internalStateToState; private prevInternal; }