import { Connection } from 'mongoose'; import { ILogger } from './definitions'; export interface ConnectionValidationOptions { maxRetries?: number; pingTimeout?: number; retryDelay?: number; } /** * Validates connection is truly ready with ping test using MongoDB native driver * This addresses the race condition where readyState === 1 but connection is not usable * Uses native MongoDB driver to check actual connection state, not just Mongoose state * * @param connection - Mongoose connection to validate * @param domain - Domain identifier for logging * @param options - Validation options * @throws {Error} If connection validation fails after all retries */ export declare function ensureConnectionReady(connection: Connection, domain: string, options?: ConnectionValidationOptions & { logger?: ILogger; }): Promise; /** * Checks if an error is a MongoDB connection error */ export declare function isConnectionError(error: any): boolean; /** * Wraps repository operations with connection validation + retry logic * This is the CORE fix for connection issues * IMPROVED: Now includes force refresh mechanism for stale connections * * @param operation - The repository operation to execute * @param domain - Domain identifier * @param connection - MongoDB connection to use * @param options - Validation and retry options * @returns Result of the operation * @throws {Error} If operation fails after all retries */ export declare function withConnectionRetry(operation: () => Promise, domain: string, connection: Connection, options?: ConnectionValidationOptions & { maxRetries?: number; logger?: ILogger; recreateConnection?: (domain: string) => Promise; }): Promise; /** * Helper to wrap sync operations with connection validation * Use this for operations that don't inherently need async */ export declare function withValidatedConnection(domain: string, connection: Connection, operation: () => T, options?: ConnectionValidationOptions & { logger?: ILogger; }): Promise;