import { type NatsClient, type NatsStatus, type NatsStatusEvent } from './nats';
export declare const NATS_DEFAULTS: {
    readonly SHARED_CLOSE_DELAY_MS: 3000;
    readonly CONNECT_TIMEOUT_MS: 10000;
    readonly PING_INTERVAL_MS: 30000;
    readonly MAX_PING_OUT: 3;
    readonly RETRY_INITIAL_DELAY_MS: 1000;
    readonly RETRY_MAX_DELAY_MS: 30000;
    readonly RETRY_MULTIPLIER: 2;
};
export interface NatsReconnectionBackoff {
    /** Number of fast retries before exponential phase kicks in. Default: 0. */
    fastRetries?: number;
    /** Delay used during the fast-retry phase. Default: RETRY_INITIAL_DELAY_MS. */
    fastRetryDelayMs?: number;
    /** Base delay for the exponential phase. Default: RETRY_INITIAL_DELAY_MS. */
    initialDelayMs?: number;
    /** Upper cap on any single retry delay. Default: RETRY_MAX_DELAY_MS. */
    maxDelayMs?: number;
    /** Per-attempt multiplier during exponential phase. Default: RETRY_MULTIPLIER. */
    multiplier?: number;
}
export interface SharedConnection {
    wsUrl: string;
    client: NatsClient;
    connectPromise: Promise<void> | null;
    refCount: number;
    closeTimer: ReturnType<typeof setTimeout> | null;
    retryTimer: ReturnType<typeof setTimeout> | null;
    /**
     * Identity of the consumer driving reconnect. When set, other consumers
     * should observe status only and skip their own scheduleRetry — otherwise
     * each disconnect triggers multiple concurrent connect() calls racing over
     * connectPromise.
     */
    retryOwner: object | null;
}
export interface AcquireClientOptions {
    name?: string;
    user?: string;
    pass?: string;
    connectTimeoutMs?: number;
    pingIntervalMs?: number;
    maxPingOut?: number;
}
export interface ReleaseClientOptions {
    delayMs?: number;
}
export declare function getSharedConnection(): SharedConnection | null;
export declare function acquireClient(url: string, opts?: AcquireClientOptions): SharedConnection;
export declare function releaseClient(url: string, opts?: ReleaseClientOptions): void;
export declare function getSharedConnectionFor(url: string | null | undefined): SharedConnection | null;
export interface ConnectionLifecycleOptions {
    conn: SharedConnection;
    wsUrl: string;
    onBeforeReconnect?: () => Promise<void> | void;
    backoff?: NatsReconnectionBackoff;
    getFreshUrl: () => string | null;
    /** Called on every status change (after closed-guard). */
    onStatusChange?: (status: NatsStatus, evt: NatsStatusEvent) => void;
    /**
     * Decide which statuses should trigger a retry attempt. Defaults to closed +
     * disconnected. Override to skip 'error' (JetStream protocol errors that
     * don't close the WS) or include it.
     */
    shouldRetryOn?: (status: NatsStatus) => boolean;
}
export interface ConnectionLifecycleHandle {
    /** Stop observing status, clear any pending retry, release ownership if held. */
    stop(): void;
}
export declare function startConnectionLifecycle(options: ConnectionLifecycleOptions): ConnectionLifecycleHandle;
//# sourceMappingURL=shared-connection.d.ts.map