/** * db4ai Connection Pool * * Provides connection pooling and reuse for HTTP/RPC connections. * Implements lazy initialization, connection lifecycle management, * and efficient resource cleanup. * * @packageDocumentation */ import type { TransportOptions } from './rpc.js'; /** * Connection state enumeration. */ export type ConnectionState = 'idle' | 'active' | 'draining' | 'closed'; /** * Connection pool statistics. */ export interface PoolStats { /** Total connections created */ totalCreated: number; /** Currently active connections */ active: number; /** Currently idle connections */ idle: number; /** Total requests served */ totalRequests: number; /** Average connection reuse count */ averageReuse: number; /** Peak concurrent connections */ peakConcurrent: number; } /** * Connection pool configuration. */ export interface PoolConfig { /** Minimum connections to maintain (default: 0) */ minConnections?: number; /** Maximum connections allowed (default: 10) */ maxConnections?: number; /** Maximum idle time before closing connection (ms, default: 60000) */ idleTimeout?: number; /** Maximum connection lifetime (ms, default: 300000) */ maxLifetime?: number; /** Connection acquire timeout (ms, default: 30000) */ acquireTimeout?: number; /** Enable connection validation (default: true) */ validateOnAcquire?: boolean; /** Pre-warm connections on pool creation (default: false) */ prewarm?: boolean; } /** * Pooled connection interface. */ export interface PooledConnection { /** Unique connection ID */ id: string; /** Connection state */ state: ConnectionState; /** Creation timestamp */ createdAt: number; /** Last used timestamp */ lastUsedAt: number; /** Number of times this connection was reused */ reuseCount: number; /** Transport options for this connection */ options: TransportOptions; /** Release connection back to pool */ release(): void; /** Close connection permanently */ close(): void; } /** * High-performance connection pool for db4ai. * * Features: * - Lazy initialization of connections * - Connection reuse with configurable limits * - Automatic idle connection cleanup * - Connection lifetime management * - Pre-warming support * - Statistics tracking */ export declare class ConnectionPool { private readonly config; private readonly baseOptions; private readonly idleConnections; private readonly activeConnections; private readonly waitQueue; private connectionCounter; private totalCreated; private totalRequests; private totalReuseCount; private peakConcurrent; private cleanupTimer; private closed; constructor(options: TransportOptions, config?: PoolConfig); /** * Acquire a connection from the pool. */ acquire(): Promise; /** * Release a connection back to the pool. */ release(connectionId: string): void; /** * Close a specific connection. */ close(connectionId: string): void; /** * Shutdown the connection pool. */ shutdown(): Promise; /** * Get pool statistics. */ getStats(): PoolStats; /** * Get the current pool size. */ get size(): number; /** * Check if pool is closed. */ get isClosed(): boolean; private createConnection; private getIdleConnection; private activateConnection; private waitForConnection; private processWaitQueue; private destroyConnection; private cleanup; private prewarmConnections; } /** * Create a new connection pool. */ export declare function createConnectionPool(options: TransportOptions, config?: PoolConfig): ConnectionPool; //# sourceMappingURL=connection-pool.d.ts.map