import { Ready } from "@ocap/util/lib/ready"; import { IIndexTable, IndexTableHookFn, Promisable } from "@ocap/types"; //#region src/index.d.ts type UniqueIndex = string | string[]; /** * Base class for index tables * Provides hook support (pre/post) and common operations * Subclasses must implement _insert, _get, _update, _reset, count */ declare class BaseIndex extends Ready implements IIndexTable { readonly name: string; readonly primaryKey: string; readonly uniqIndex: UniqueIndex; ready: boolean; readyCallbacks: Array<() => void>; pre: (hookName: string, fn: IndexTableHookFn) => void; post: (hookName: string, fn: IndexTableHookFn) => void; insert: (doc: T | Record) => Promise; get: (key: string | Record) => Promise; update: (key: string | Record, updates: Partial) => Promise; reset: () => Promise; constructor(name?: string, uniqIndex?: UniqueIndex); /** * Count documents matching query * Must be implemented by subclasses */ count(_query?: unknown): Promisable; /** * Internal insert implementation * Called by the public `insert` method after pre-hooks */ _insert(_doc: T | Record): Promisable; /** * Internal get implementation * Called by the public `get` method after pre-hooks */ _get(_key: string | Record): Promisable; /** * Internal update implementation * Called by the public `update` method after pre-hooks */ _update(_key: string | Record, _updates: Partial): Promisable; /** * Internal reset implementation * Called by the public `reset` method after pre-hooks */ _reset(): Promisable; /** * Generate primary key from document or key object * For composite keys, generates MD5 hash of joined values * @param doc - String key or document/key object * @returns Primary key string */ generatePrimaryKey(doc: string | Record): string; } //#endregion export { BaseIndex as default };