UNPKG

@tanstack/db

Version:

A reactive client store for building super fast apps on sync

56 lines (55 loc) 2.59 kB
import { Collection } from './collection/index.js'; import { CollectionStatus } from './types.js'; /** * A page-windowed view of a live query at a point in time. * * @internal This contract is unstable while RFC #1623 is being implemented. */ export interface LiveQueryWindowSnapshot<T extends object, TKey extends string | number> { /** Rows across all committed pages, with the peek-ahead row removed. */ data: ReadonlyArray<T>; /** Rows grouped into committed pages of `pageSize`. */ pages: ReadonlyArray<ReadonlyArray<T>>; /** `initialPageParam + i` for each committed page. */ pageParams: ReadonlyArray<number>; hasNextPage: boolean; isFetchingNextPage: boolean; /** The last pagination failure, cleared when a retry begins. */ error: unknown; /** Keyed results for the physical window, or `undefined` when disabled. */ state: ReadonlyMap<TKey, T> | undefined; collection: Collection<T, TKey, any> | undefined; status: CollectionStatus | `disabled`; isLoading: boolean; isReady: boolean; isIdle: boolean; isError: boolean; isCleanedUp: boolean; isEnabled: boolean; } /** @internal This contract is unstable while RFC #1623 is being implemented. */ export interface CreateLiveQueryWindowControllerOptions { /** Rows per page (default 20). Non-positive values use the default. */ pageSize?: number; /** Value of the first page's `pageParam` (default 0). */ initialPageParam?: number; /** Committed pages to preserve when a framework binding changes page shape. */ initialPageCount?: number; } /** @internal This contract is unstable while RFC #1623 is being implemented. */ export interface LiveQueryWindowController<T extends object, TKey extends string | number> { getSnapshot: () => LiveQueryWindowSnapshot<T, TKey>; subscribe: (listener: () => void) => () => void; /** Load one more page, resolving only after that page is committed. */ fetchNextPage: () => Promise<void>; /** Reset to the first page, resolving after the smaller window is accepted. */ reset: () => Promise<void>; preload: () => Promise<void>; dispose: () => void; } /** * Create an internal forward-window controller for an ordered live query. * * @internal This factory is unstable while RFC #1623 is being implemented. */ export declare function createLiveQueryWindowController<T extends object, TKey extends string | number>(collection: Collection<T, TKey, any> | null | undefined, options?: CreateLiveQueryWindowControllerOptions): LiveQueryWindowController<T, TKey>;