/**
 * @module connection-pool
 * HTTP connection pooling for xBind registry/gateway requests
 *
 * Provides connection reuse, keep-alive support, and automatic cleanup
 * to enhance performance for applications making frequent requests.
 *
 * @example
 * ```typescript
 * const pool = new ConnectionPool({
 *   maxConnections: 50,
 *   keepAliveTimeout: 30000,
 * });
 *
 * const response = await pool.fetch('https://api.example.com/data');
 * const data = await response.json();
 * ```
 */
/**
 * Connection pool configuration options
 */
export interface ConnectionPoolOptions {
    /**
     * Maximum number of connections per origin
     * @default 10
     */
    maxConnections?: number;
    /**
     * Minimum number of idle connections to maintain
     * @default 2
     */
    minConnections?: number;
    /**
     * Keep-alive timeout in milliseconds
     * @default 30000 (30 seconds)
     */
    keepAliveTimeout?: number;
    /**
     * Maximum time a connection can be idle before cleanup
     * @default 60000 (60 seconds)
     */
    idleTimeout?: number;
    /**
     * Request timeout in milliseconds
     * @default 30000 (30 seconds)
     */
    requestTimeout?: number;
    /**
     * Enable connection pooling metrics
     * @default true
     */
    enableMetrics?: boolean;
    /**
     * Retry failed connections
     * @default true
     */
    retryOnFailure?: boolean;
    /**
     * Maximum retry attempts for failed requests
     * @default 3
     */
    maxRetries?: number;
}
/**
 * Connection pool metrics
 */
export interface ConnectionPoolMetrics {
    /** Total number of connections */
    totalConnections: number;
    /** Number of active connections */
    activeConnections: number;
    /** Number of idle connections */
    idleConnections: number;
    /** Total requests served */
    totalRequests: number;
    /** Number of connection reuses */
    reuseCount: number;
    /** Number of failed requests */
    failedRequests: number;
    /** Average request duration in milliseconds */
    avgRequestDuration: number;
    /** Connection pool hit rate (0-1) */
    hitRate: number;
    /** Metrics by origin */
    byOrigin: Map<string, {
        connections: number;
        requests: number;
        avgDuration: number;
    }>;
}
/**
 * Connection pool for HTTP requests
 *
 * Manages connection lifecycle, keep-alive, and automatic cleanup
 * to optimize performance for frequent requests to the same origins.
 */
export declare class ConnectionPool {
    private options;
    private connections;
    private metrics;
    private cleanupInterval;
    /**
     * Create a new connection pool
     *
     * @param options - Pool configuration options
     */
    constructor(options?: ConnectionPoolOptions);
    /**
     * Make an HTTP request using the connection pool
     *
     * @param url - Target URL
     * @param init - Fetch options
     * @returns Response promise
     *
     * @example
     * ```typescript
     * const response = await pool.fetch('https://api.example.com/data', {
     *   method: 'POST',
     *   headers: { 'Content-Type': 'application/json' },
     *   body: JSON.stringify({ key: 'value' }),
     * });
     * ```
     */
    fetch(url: string, init?: RequestInit): Promise<Response>;
    /**
     * Retry a failed request with exponential backoff
     */
    private retryRequest;
    /**
     * Acquire a connection from the pool or create a new one
     */
    private acquireConnection;
    /**
     * Wait for a connection to become available
     */
    private waitForConnection;
    /**
     * Create a new connection
     */
    private createConnection;
    /**
     * Get origin from URL
     */
    private getOrigin;
    /**
     * Record request metrics
     */
    private recordMetrics;
    /**
     * Get connection pool metrics
     *
     * @returns Current metrics snapshot
     *
     * @example
     * ```typescript
     * const metrics = pool.getMetrics();
     * console.log(`Hit rate: ${(metrics.hitRate * 100).toFixed(1)}%`);
     * console.log(`Avg duration: ${metrics.avgRequestDuration}ms`);
     * ```
     */
    getMetrics(): ConnectionPoolMetrics;
    /**
     * Reset metrics counters
     *
     * @example
     * ```typescript
     * pool.resetMetrics();
     * // Start fresh measurements
     * ```
     */
    resetMetrics(): void;
    /**
     * Start automatic connection cleanup
     */
    private startCleanup;
    /**
     * Clean up idle and expired connections
     */
    private cleanup;
    /**
     * Manually trigger connection cleanup
     *
     * @example
     * ```typescript
     * // Force cleanup of idle connections
     * pool.cleanupNow();
     * ```
     */
    cleanupNow(): void;
    /**
     * Close all connections and shutdown the pool
     *
     * @example
     * ```typescript
     * // Cleanup on application shutdown
     * await pool.close();
     * ```
     */
    close(): Promise<void>;
    /**
     * Get the number of connections for a specific origin
     *
     * @param origin - Target origin (e.g., "https://api.example.com")
     * @returns Number of connections
     *
     * @example
     * ```typescript
     * const count = pool.getConnectionCount('https://api.example.com');
     * console.log(`Active connections: ${count}`);
     * ```
     */
    getConnectionCount(origin: string): number;
    /**
     * Get all origins with active connections
     *
     * @returns Array of origins
     *
     * @example
     * ```typescript
     * const origins = pool.getOrigins();
     * console.log(`Connected to ${origins.length} origins`);
     * ```
     */
    getOrigins(): string[];
    /**
     * Check if the pool is healthy
     *
     * @returns True if pool is operating normally
     *
     * @example
     * ```typescript
     * if (!pool.isHealthy()) {
     *   console.warn('Connection pool degraded');
     * }
     * ```
     */
    isHealthy(): boolean;
}
export declare function getGlobalPool(options?: ConnectionPoolOptions): ConnectionPool;
/**
 * Reset the global connection pool
 *
 * Closes the current pool and allows a new one to be created.
 *
 * @example
 * ```typescript
 * await resetGlobalPool();
 * // Next getGlobalPool() call will create a fresh instance
 * ```
 */
export declare function resetGlobalPool(): Promise<void>;
