UNPKG

@tanstack/db

Version:

A reactive client store for building super fast apps on sync

58 lines (57 loc) 2.51 kB
import { StandardSchemaV1 } from '@standard-schema/spec'; import { BaseIndex, IndexConstructor } from '../indexes/base-index.cjs'; import { ChangeMessage } from '../types.cjs'; import { IndexOptions } from '../indexes/index-options.cjs'; import { SingleRowRefProxy } from '../query/builder/ref-proxy.cjs'; import { CollectionLifecycleManager } from './lifecycle.cjs'; import { CollectionStateManager } from './state.cjs'; import { CollectionEventsManager, CollectionIndexMetadata } from './events.cjs'; 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; private defaultIndexType; private events; indexes: Map<number, BaseIndex<TKey>>; indexMetadata: Map<number, CollectionIndexMetadata>; indexCounter: number; constructor(); setDeps(deps: { state: CollectionStateManager<TOutput, TKey, TSchema, TInput>; lifecycle: CollectionLifecycleManager<TOutput, TKey, TSchema, TInput>; defaultIndexType?: IndexConstructor<TKey>; events: CollectionEventsManager; }): void; /** * Creates an index on a collection for faster queries. * * @example * ```ts * // With explicit index type (recommended for tree-shaking) * import { BasicIndex } from '@tanstack/db' * collection.createIndex((row) => row.userId, { indexType: BasicIndex }) * * // With collection's default index type * collection.createIndex((row) => row.userId) * ``` */ createIndex<TIndexType extends IndexConstructor<TKey>>(indexCallback: (row: SingleRowRefProxy<TOutput>) => any, config?: IndexOptions<TIndexType>): BaseIndex<TKey>; /** * Removes an index from this collection. * Returns true when an index existed and was removed, false otherwise. */ removeIndex(indexOrId: BaseIndex<TKey> | number): boolean; /** * Returns a sorted snapshot of index metadata. * This allows persisted wrappers to bootstrap from indexes that were created * before they attached lifecycle listeners. */ getIndexMetadataSnapshot(): Array<CollectionIndexMetadata>; /** * Updates all indexes when the collection changes */ updateIndexes(changes: Array<ChangeMessage<TOutput, TKey>>): void; /** * Clean up indexes */ cleanup(): void; }