UNPKG

@tanstack/db

Version:

A reactive client store for building super fast apps on sync

55 lines (54 loc) 2.28 kB
import { comparisonFunctions } from '../query/builder/functions.js'; import { BasicExpression } from '../query/ir.js'; /** * Operations that indexes can support, imported from available comparison functions */ export declare const IndexOperation: readonly ["eq", "gt", "gte", "lt", "lte", "in", "like", "ilike"]; /** * Type for index operation values */ export type IndexOperation = (typeof comparisonFunctions)[number]; /** * Statistics about index usage and performance */ export interface IndexStats { readonly entryCount: number; readonly lookupCount: number; readonly averageLookupTime: number; readonly lastUpdated: Date; } /** * Base abstract class that all index types extend */ export declare abstract class BaseIndex<TKey extends string | number = string | number> { readonly id: number; readonly name?: string; readonly expression: BasicExpression; abstract readonly supportedOperations: Set<IndexOperation>; protected lookupCount: number; protected totalLookupTime: number; protected lastUpdated: Date; constructor(id: number, expression: BasicExpression, name?: string, options?: any); abstract add(key: TKey, item: any): void; abstract remove(key: TKey, item: any): void; abstract update(key: TKey, oldItem: any, newItem: any): void; abstract build(entries: Iterable<[TKey, any]>): void; abstract clear(): void; abstract lookup(operation: IndexOperation, value: any): Set<TKey>; abstract get keyCount(): number; supports(operation: IndexOperation): boolean; matchesField(fieldPath: Array<string>): boolean; getStats(): IndexStats; protected abstract initialize(options?: any): void; protected evaluateIndexExpression(item: any): any; protected trackLookup(startTime: number): void; protected updateTimestamp(): void; } /** * Type for index constructor */ export type IndexConstructor<TKey extends string | number = string | number> = new (id: number, expression: BasicExpression, name?: string, options?: any) => BaseIndex<TKey>; /** * Index resolver can be either a class constructor or async loader */ export type IndexResolver<TKey extends string | number = string | number> = IndexConstructor<TKey> | (() => Promise<IndexConstructor<TKey>>);