UNPKG

@tanstack/db

Version:

A reactive client store for building super fast apps on sync

48 lines (47 loc) 2.1 kB
import { IndexProxy, LazyIndexWrapper } from '../indexes/lazy-index.js'; import { BTreeIndex } from '../indexes/btree-index.js'; import { StandardSchemaV1 } from '@standard-schema/spec'; import { BaseIndex, IndexResolver } from '../indexes/base-index.js'; import { ChangeMessage } from '../types.js'; import { IndexOptions } from '../indexes/index-options.js'; import { SingleRowRefProxy } from '../query/builder/ref-proxy.js'; import { CollectionLifecycleManager } from './lifecycle.js'; import { CollectionStateManager } from './state.js'; export declare class CollectionIndexesManager<TOutput extends object = Record<string, unknown>, TKey extends string | number = string | number, TSchema extends StandardSchemaV1 = StandardSchemaV1, TInput extends object = TOutput> { private lifecycle; private state; lazyIndexes: Map<number, LazyIndexWrapper<TKey>>; resolvedIndexes: Map<number, BaseIndex<TKey>>; isIndexesResolved: boolean; indexCounter: number; constructor(); setDeps(deps: { state: CollectionStateManager<TOutput, TKey, TSchema, TInput>; lifecycle: CollectionLifecycleManager<TOutput, TKey, TSchema, TInput>; }): void; /** * Creates an index on a collection for faster queries. */ createIndex<TResolver extends IndexResolver<TKey> = typeof BTreeIndex>(indexCallback: (row: SingleRowRefProxy<TOutput>) => any, config?: IndexOptions<TResolver>): IndexProxy<TKey>; /** * Resolve all lazy indexes (called when collection first syncs) */ resolveAllIndexes(): Promise<void>; /** * Resolve a single index immediately */ private resolveSingleIndex; /** * Get resolved indexes for query optimization */ get indexes(): Map<number, BaseIndex<TKey>>; /** * Updates all indexes when the collection changes */ updateIndexes(changes: Array<ChangeMessage<TOutput, TKey>>): void; /** * Clean up the collection by stopping sync and clearing data * This can be called manually or automatically by garbage collection */ cleanup(): void; }