//#region src/db/types.d.ts /** * Database abstraction interfaces for IAVL tree storage. * Based on the Go iavl db/types.go implementation. */ /** * Iterator for traversing database key-value pairs. * Iterators are stateful and must be closed when done. */ interface Iterator { /** * Returns the current key. Only valid when valid() returns true. */ key(): Uint8Array; /** * Returns the current value. Only valid when valid() returns true. */ value(): Uint8Array; /** * Checks if the iterator is positioned at a valid key-value pair. */ valid(): boolean; /** * Advances the iterator to the next key-value pair. * After calling next(), check valid() before accessing key()/value(). */ next(): void; /** * Releases resources held by the iterator. * Iterator must not be used after calling close(). */ close(): void; } /** * Batch allows accumulating multiple database operations * and committing them atomically. */ interface Batch { /** * Sets a key-value pair in the batch. * * @param key - Key to set * @param value - Value to set */ set(key: Uint8Array, value: Uint8Array): void; /** * Deletes a key from the database in the batch. * * @param key - Key to delete */ delete(key: Uint8Array): void; /** * Writes all batched operations to the database atomically. * After write(), the batch should not be used again. */ write(): Promise; /** * Releases resources held by the batch without writing. * Batch must not be used after calling close(). */ close(): void; } /** * Database interface for key-value storage. * All implementations must be safe for concurrent reads, * but writes may require external synchronization. */ interface Database { /** * Gets the value for a key. * * @param key - Key to retrieve * @returns Value if found, null if not found */ get(key: Uint8Array): Promise; /** * Checks if a key exists in the database. * * @param key - Key to check * @returns True if key exists */ has(key: Uint8Array): Promise; /** * Sets a key-value pair in the database. * * @param key - Key to set * @param value - Value to set */ set(key: Uint8Array, value: Uint8Array): Promise; /** * Deletes a key from the database. * * @param key - Key to delete */ delete(key: Uint8Array): Promise; /** * Creates an iterator over a key range. * The iterator must be closed when done. * * Note: This method is async to support database implementations that * require asynchronous initialization (e.g., CrossKvDB which fetches data from disk). * * @param start - Start key (inclusive), or undefined for beginning * @param end - End key (exclusive), or undefined for end * @returns Promise resolving to an iterator over the range */ iterator(start?: Uint8Array, end?: Uint8Array): Promise; /** * Creates a reverse iterator over a key range. * The iterator must be closed when done. * * Note: This method is async to support database implementations that * require asynchronous initialization (e.g., CrossKvDB which fetches data from disk). * * @param start - Start key (inclusive), or undefined for beginning * @param end - End key (exclusive), or undefined for end * @returns Promise resolving to a reverse iterator over the range */ reverseIterator(start?: Uint8Array, end?: Uint8Array): Promise; /** * Creates a new batch for atomic writes. * The batch must be closed when done. * * @returns New batch instance */ batch(): Batch; /** * Closes the database and releases resources. * Database must not be used after calling close(). */ close(): Promise; } /** * Options for creating a database instance. */ interface DatabaseOptions { /** * Whether to fsync writes to disk. * Default: false */ sync?: boolean; /** * Additional implementation-specific options. */ [key: string]: unknown; } //#endregion export { Batch, Database, DatabaseOptions, Iterator }; //# sourceMappingURL=types.d.ts.map