UNPKG

@tanstack/db

Version:

A reactive client store for building super fast apps on sync

71 lines (70 loc) • 3.17 kB
import { Collection } from "./collection/index.cjs"; import { DbClient } from "./client.cjs"; import { LiveQueryKey } from "./live-query-options.cjs"; import { LiveQueryWindowController } from "./live-query-window-controller.cjs"; /** Validated infinite-query page shape. */ export interface LiveQueryWindowPageShape { pageSize: number; /** First result-page label, not a server cursor or remote offset. */ initialPageParam: number; } /** * Read an infinite-query config's page shape. `getNextPageParam` is rejected: * the hook widens an ordered live query and has no server cursor to advance. */ export declare function readLiveQueryWindowPageShape(config: { pageSize?: number; initialPageParam?: number; }): LiveQueryWindowPageShape; /** * When a query input compiles again. * * - `identity`: when its identity dependencies change by structure, as for a * derived query identity or a `queryKey`. * - `always`: on every update, as for a reactive rerun, which happens only * when something the query reads changed. */ export type LiveQueryWindowRecompile = `identity` | `always`; export interface LiveQueryWindowUpdate extends LiveQueryWindowPageShape { /** * A supplied live-query Collection, or a callback that returns the query. * The binding calls the callback only when it compiles a new window * collection, except in `always` mode, where it calls it on every update. */ input: unknown; /** The query input's identity dependencies. */ dependencies?: ReadonlyArray<unknown>; /** Context compared by reference, such as the `DbClient` a query binds to. */ scope?: unknown; /** Hydration identity for a client-backed window. */ client?: DbClient; queryKey?: LiveQueryKey; recompile: LiveQueryWindowRecompile; } export interface LiveQueryWindowBinding extends LiveQueryWindowPageShape { /** The supplied Collection; `undefined` for a query input. */ supplied: Collection<any, any, any> | undefined; dependencies: ReadonlyArray<unknown> | undefined; scope: unknown; collection: Collection<any, any, any>; /** The transport identity of this binding's initial query window. */ queryHash: string | undefined; /** Whether this binding created `collection` from a query. */ ownsCollection: boolean; controller: LiveQueryWindowController<any, any>; /** * A developer hint about a newly bound supplied collection's window, for the * adapter to print once. Production builds carry none. */ warning: string | undefined; } /** * Bind an infinite-query update. Returns `previous` when it still serves the * update; otherwise returns a new binding whose controller the adapter * subscribes and later disposes. * * `uncommitted` is a binding built by an earlier update that never took * effect, such as a React render that did not commit. When it answers this * update, its window collection is reused instead of compiling another. */ export declare function bindLiveQueryWindow(previous: LiveQueryWindowBinding | null, update: LiveQueryWindowUpdate, uncommitted?: LiveQueryWindowBinding | null): LiveQueryWindowBinding;