/** * Society Protocol - Optimized Storage Layer * * Batched writes, connection pooling, and query optimization. * Reduces SQLite lock contention and improves throughput. */ import { Storage } from './storage.js'; import { EventEmitter } from 'events'; export interface BatchedOperation { execute: () => T; resolve: (value: T) => void; reject: (error: Error) => void; } export interface OptimizedStorageOptions { batchIntervalMs?: number; maxBatchSize?: number; maxQueueSize?: number; enablePooling?: boolean; } /** * Optimized storage with batching and pooling */ export declare class OptimizedStorage extends EventEmitter { private storage; private writeQueue; private batchIntervalMs; private maxBatchSize; private maxQueueSize; private isProcessing; private batchTimer?; private stats; constructor(storage: Storage, options?: OptimizedStorageOptions); /** * Queue a write operation for batching */ queueWrite(execute: () => T): Promise; /** * Immediate write ( bypass batching ) */ immediateWrite(execute: () => T): T; /** * Process batched writes */ private processBatch; /** * Force immediate processing of pending writes */ flush(): Promise; /** * Get queue length */ get queueLength(): number; /** * Get statistics */ getStats(): { batchedWrites: number; immediateWrites: number; queuedWrites: number; droppedWrites: number; batchErrors: number; }; /** * Reset statistics */ resetStats(): void; /** * Destroy and cleanup */ destroy(): void; } /** * Connection pool for parallel reads */ export declare class StoragePool extends EventEmitter { private connections; private available; private pending; private maxConnections; constructor(dbPath: string, maxConnections?: number); /** * Acquire a connection from the pool */ acquire(): Promise; /** * Release a connection back to the pool */ release(storage: Storage): void; /** * Execute with automatic acquire/release */ execute(fn: (storage: Storage) => Promise): Promise; /** * Close all connections */ close(): void; } /** * Query builder for optimized queries */ export declare class QueryBuilder { private conditions; private params; private orderByClause?; private limitClause?; private offsetClause?; where(condition: string, ...params: any[]): this; orderBy(column: string, direction?: 'ASC' | 'DESC'): this; limit(n: number): this; offset(n: number): this; build(): { sql: string; params: any[]; }; } //# sourceMappingURL=storage-optimized.d.ts.map