import { Batch, Database } from "./types.cjs"; //#region src/db/batch-with-flusher.d.ts /** * Default flush threshold in bytes. * Based on Go IAVL options.go DefaultOptions().FlushThreshold */ declare const DEFAULT_FLUSH_THRESHOLD = 100000; /** * BatchWithFlusher wraps a regular batch and automatically flushes * when the batch size exceeds a threshold. * * Thread-safety: While the Go implementation uses mutexes, Node.js is single-threaded * so we don't need explicit locking. Async operations are naturally serialized. * * Based on Go IAVL batch.go BatchWithFlusher */ declare class BatchWithFlusher implements Batch { private db; private batch; private flushThreshold; private currentSize; private closed; /** * Creates a new BatchWithFlusher. * * @param db - Database to create batches from * @param flushThreshold - Size threshold in bytes to trigger flush (default 100KB) */ constructor(db: Database, flushThreshold?: number); /** * Estimates the batch size after adding a key-value pair. * * Based on Go IAVL batch.go estimateSizeAfterSetting * * @param key - Key bytes * @param value - Value bytes * @returns Estimated size after addition */ private estimateSizeAfterSetting; /** * Sets a key-value pair in the batch. * If this would exceed the flush threshold, flushes first. * * Based on Go IAVL batch.go Set * * @param key - Key to set * @param value - Value to set */ set(key: Uint8Array, value: Uint8Array): void; /** * Deletes a key from the batch. * If this would exceed the flush threshold, flushes first. * * Based on Go IAVL batch.go Delete * * @param key - Key to delete */ delete(key: Uint8Array): void; /** * Synchronously flushes the current batch and creates a new one. * This is a private helper used during set/delete operations. * * Note: The Go implementation has async Write but we need sync here * to maintain operation ordering within set/delete. */ private flushSync; /** * Writes the batch to the database and creates a new batch. * * Based on Go IAVL batch.go Write */ write(): Promise; /** * Writes the batch to the database with sync flag and creates a new batch. * * Based on Go IAVL batch.go WriteSync * * Note: Our interface doesn't distinguish between Write and WriteSync, * but we provide this for API compatibility. */ writeSync(): Promise; /** * Closes the batch without writing. * * Based on Go IAVL batch.go Close */ close(): void; /** * Gets the current byte size of the batch. * * Based on Go IAVL batch.go GetByteSize * * @returns Current batch size in bytes */ getByteSize(): number; } /** * Async version of BatchWithFlusher that properly handles async flushes. * * This version queues operations and processes them asynchronously, * allowing for proper async flush operations when threshold is exceeded. */ declare class AsyncBatchWithFlusher { private db; private batch; private flushThreshold; private currentSize; private closed; private operations; private processing; private processPromise?; /** * Creates a new AsyncBatchWithFlusher. * * @param db - Database to create batches from * @param flushThreshold - Size threshold in bytes to trigger flush (default 100KB) */ constructor(db: Database, flushThreshold?: number); /** * Queues a set operation. * * @param key - Key to set * @param value - Value to set * @returns Promise that resolves when operation is processed */ set(key: Uint8Array, value: Uint8Array): Promise; /** * Queues a delete operation. * * @param key - Key to delete * @returns Promise that resolves when operation is processed */ delete(key: Uint8Array): Promise; /** * Processes queued operations, flushing when necessary. */ private processOperations; /** * Actually processes the operations. */ private doProcessOperations; /** * Estimates size after an operation. */ private estimateSizeAfterOp; /** * Flushes the current batch and creates a new one. */ private flush; /** * Writes any pending operations and the final batch. */ write(): Promise; /** * Writes any pending operations and the final batch with sync flag. * This ensures data is flushed to disk (fsync) before returning. * * Based on Go IAVL batch.go WriteSync */ writeSync(): Promise; /** * Closes the batch. */ close(): void; /** * Gets the current byte size. */ getByteSize(): number; } //#endregion export { AsyncBatchWithFlusher, BatchWithFlusher, DEFAULT_FLUSH_THRESHOLD }; //# sourceMappingURL=batch-with-flusher.d.cts.map