import DataPack from "./datapack.js"; import { type Transaction } from "./edinburgh.js"; import { TypeWrapper } from "./types.js"; type IndexItem = { _setLoadedField(fieldName: string, value: any): void; _restoreLazyFields?(): void; }; type PrimaryKeyItem = IndexItem & { _oldValues: Record | undefined | null | false; _primaryKey: Uint8Array | undefined; _txn: Transaction; _setPrimaryKey(key: Uint8Array, hash?: number): void; }; type FieldTypes = ReadonlyMap>; type LoadPrimary = (txn: Transaction, primaryKey: Uint8Array, loadNow: boolean | Uint8Array) => ITEM | undefined; type QueueInitialization = () => void; type IndexArgTypes = { [I in keyof F]: ITEM[F[I]]; }; /** Cached information about a specific version of a primary index's value format. */ export interface VersionInfo { migrateHash: number; /** Non-key field names → TypeWrappers for deserialization of this version's data. */ nonKeyFields: Map>; /** Set of serialized secondary index signatures that existed in this version's data. */ secondaryKeys: Set; } /** * Iterator for range queries on indexes. * Handles common iteration logic for both primary and unique indexes. * Extends built-in Iterator to provide map/filter/reduce/toArray/etc. */ export declare class IndexRangeIterator extends Iterator { private txn; private iteratorId; private parentIndex; constructor(txn: Transaction, iteratorId: number, parentIndex: BaseIndex); [Symbol.iterator](): this; next(): IteratorResult; count(): number; fetch(): ITEM | undefined; } type ArrayOrOnlyItem = ARG_TYPES extends readonly [infer A] ? (A | Partial) : Partial; /** * Range-query options accepted by `find()`, `findBy()`, `batchProcess()`, and `batchProcessBy()`. * * Supports exact-match lookups via `is`, inclusive bounds via `from` / `to`, * exclusive bounds via `after` / `before`, and reverse scans. * * For single-field indexes, values can be passed directly. For composite indexes, * pass tuples or partial tuples for prefix matching. If an index field is a * `link(...)`, you may pass either the linked model instance or the linked * model's primary key. Composite linked primary keys are passed as tuples in * that slot. * * @template ARG_TYPES - Tuple of index argument types. * @template FETCH - Optional fetch mode used by overloads that return one row. */ export type FindOptions = (({ is: ArrayOrOnlyItem; } | (({ from: ArrayOrOnlyItem; } | { after: ArrayOrOnlyItem; } | {}) & ({ to: ArrayOrOnlyItem; } | { before: ArrayOrOnlyItem; } | {}))) & { reverse?: boolean; } & (FETCH extends undefined ? { fetch?: undefined; } : { fetch: FETCH; })); /** * Base class for database indexes for efficient lookups on model fields. * * Indexes enable fast queries on specific field combinations and enforce uniqueness constraints. */ export declare abstract class BaseIndex> { tableName: string; _indexFields: Map>; _computeFn?: (data: any) => any[]; _indexId?: number; _signature?: string; constructor(tableName: string, fieldNames: F); _initializeIndex(fields: FieldTypes, reset?: boolean, primaryFieldTypes?: FieldTypes): Promise; _argsToKeyBytes(args: [], allowPartial: boolean): DataPack; _argsToKeyBytes(args: Partial, allowPartial: boolean): DataPack; abstract _pairToInstance(txn: Transaction, keyBuffer: ArrayBuffer, valueBuffer: ArrayBuffer): ITEM | undefined; abstract _getTypeName(): string; _retrieveIndexId(fields: FieldTypes, primaryFieldTypes?: FieldTypes): Promise; _computeKeyBounds(opts: FindOptions): [DataPack | undefined, DataPack | undefined] | null; /** * Find rows using exact-match or range-query options. * * Supports exact matches, inclusive and exclusive bounds, open-ended ranges, * and reverse iteration. For single-field indexes, values can be passed * directly. For composite indexes, pass tuples or partial tuples. * * @example * ```typescript * const exact = User.find({ is: "user-123", fetch: "first" }); * const email = [...User.findBy("email", { from: "a@test.com", to: "m@test.com" })]; * const reverse = [...Product.findBy("category", { is: "electronics", reverse: true })]; * ``` */ find(opts: FindOptions): ITEM | undefined; find(opts: FindOptions): ITEM; find(opts?: FindOptions): IndexRangeIterator; /** * Process matching rows in batched transactions. * * Uses the same range options as {@link find}, plus optional row and time * limits that control when the current transaction is committed and a new one starts. * * @param opts Query options plus batch limits. * @param callback Called for each matching row inside a transaction. */ batchProcess(opts: (FindOptions & { limitSeconds?: number; limitRows?: number; }) | undefined, callback: (row: ITEM) => void | Promise): Promise; toString(): string; } export declare abstract class PrimaryKey> extends BaseIndex { _getTypeName(): string; abstract _serializeValue(data: Record): Uint8Array; _versionInfoKey(version: number): Uint8Array; _ensureVersionEntry(currentValueBytes: Uint8Array): Promise<{ version: number; created: boolean; }>; _serializePK(data: Record): DataPack; _pkToArray(key: Uint8Array): ARGS; _writePK(txn: Transaction, primaryKey: Uint8Array, data: Record): void; _deletePK(txn: Transaction, primaryKey: Uint8Array, _data: Record): void; } export declare abstract class NonPrimaryIndex> extends BaseIndex { protected _loadPrimary: LoadPrimary; _resetIndexFieldDescriptors: Record; constructor(tableName: string, fieldsOrFn: F | ((data: any) => any[]), _loadPrimary: LoadPrimary, queueInitialization: QueueInitialization); _initializeIndex(fields: FieldTypes, reset?: boolean, primaryFieldTypes?: FieldTypes): Promise; _buildKeyPacks(data: Record): DataPack[]; _serializeKeys(primaryKey: Uint8Array, data: Record): Uint8Array[]; abstract _writeKey(txn: Transaction, key: Uint8Array, primaryKey: Uint8Array): void; _write(txn: Transaction, primaryKey: Uint8Array, model: ITEM): void; _delete(txn: Transaction, primaryKey: Uint8Array, model: ITEM): void; _update(txn: Transaction, primaryKey: Uint8Array, newData: ITEM, oldData: Record): number; } export declare class UniqueIndex> extends NonPrimaryIndex { constructor(tableName: string, fieldsOrFn: F | ((data: any) => any[]), loadPrimary: LoadPrimary, queueInitialization: QueueInitialization); _getTypeName(): string; getPK(...args: ARGS): ITEM | undefined; _writeKey(txn: Transaction, key: Uint8Array, primaryKey: Uint8Array): void; _pairToInstance(txn: Transaction, keyBuffer: ArrayBuffer, valueBuffer: ArrayBuffer): ITEM | undefined; } export declare class SecondaryIndex> extends NonPrimaryIndex { constructor(tableName: string, fieldsOrFn: F | ((data: any) => any[]), loadPrimary: LoadPrimary, queueInitialization: QueueInitialization); _getTypeName(): string; _pairToInstance(txn: Transaction, keyBuffer: ArrayBuffer, _valueBuffer: ArrayBuffer): ITEM | undefined; _serializeKeys(primaryKey: Uint8Array, data: Record): Uint8Array[]; _writeKey(txn: Transaction, key: Uint8Array, _primaryKey: Uint8Array): void; } export declare function dump(): void; export {};