UNPKG

@tanstack/db

Version:

A reactive client store for building super fast apps on sync

47 lines (46 loc) • 2.63 kB
import { CompareOptions } from "../builder/types.cjs"; import { WindowOptions } from "./types.cjs"; import { OrderBy, OrderByClause, QueryIR, Select } from "../ir.cjs"; import { CollectionLike, NamespacedAndKeyedStream, NamespacedRow } from "../../types.cjs"; import { IStreamBuilder, KeyValue } from '@tanstack/db-ivm'; import { IndexReader } from "../../indexes/base-index.cjs"; import { Collection } from "../../collection/index.cjs"; export type OrderByOptimizationInfo = { sourceId: string; alias: string; orderBy: OrderBy; offset: number; limit: number; comparator: (a: Record<string, unknown> | null | undefined, b: Record<string, unknown> | null | undefined) => number; /** Extracts the leading provider order value from a raw row. */ valueExtractorForRawRow: (row: Record<string, unknown>) => unknown; /** Index on the first orderBy column - used for lazy loading */ index?: IndexReader<string | number>; dataNeeded?: () => number; /** Reads the source loader's synchronous request guard, when installed. */ isRequesting?: () => boolean; /** * Whether a provider-ordered finite prefix is insufficient for the local * plan, including when a custom local collation defines another order. */ requiresFullSource: boolean; /** Source whose lazy demand must settle before a joined-filter page. */ joinedFilterSourceId?: string; }; /** * Processes the ORDER BY clause * Works with the new structure that has both namespaced row data and $selected * Always uses fractional indexing and adds the index as __ordering_index to the result */ export declare function processOrderBy(rawQuery: QueryIR, pipeline: NamespacedAndKeyedStream, orderByClause: Array<OrderByClause>, selectClause: Select, collection: Collection, optimizableOrderByCollections: Record<string, OrderByOptimizationInfo>, setWindowFn: (windowFn: (options: WindowOptions) => void) => void, limit?: number, offset?: number, groupKeyFn?: (key: unknown, value: unknown) => unknown): IStreamBuilder<KeyValue<unknown, [ NamespacedRow, string ]>>; /** * Builds a comparison configuration object that uses the values provided in the orderBy clause. * If no string sort configuration is provided it defaults to the collection's string sort configuration. * Multi-source FROM queries pass their first source collection here as the * documented default. Use explicit orderBy compare options when branches need * different string collation behavior. */ export declare function buildCompareOptions(clause: OrderByClause, collection: CollectionLike<any, any>): CompareOptions;