import type { Observer, UnsubscribeFn } from '@trpc/server/observable';
import type { AnyRouter, inferRouterError, MaybePromise, TRPCResponseMessage } from '@trpc/server/unstable-core-do-not-import';
import { TRPCClientError } from '../TRPCClientError';
import type { Operation, TRPCLink } from './types';
type WSCallbackResult<TRouter extends AnyRouter, TOutput> = TRPCResponseMessage<TOutput, inferRouterError<TRouter>>;
type WSCallbackObserver<TRouter extends AnyRouter, TOutput> = Observer<WSCallbackResult<TRouter, TOutput>, TRPCClientError<TRouter>>;
declare const exponentialBackoff: (attemptIndex: number) => number;
export interface WebSocketClientOptions {
    /**
     * The URL to connect to (can be a function that returns a URL)
     */
    url: string | (() => MaybePromise<string>);
    /**
     * Ponyfill which WebSocket implementation to use
     */
    WebSocket?: typeof WebSocket;
    /**
     * The number of milliseconds before a reconnect is attempted.
     * @default {@link exponentialBackoff}
     */
    retryDelayMs?: typeof exponentialBackoff;
    /**
     * Triggered when a WebSocket connection is established
     */
    onOpen?: () => void;
    /**
     * Triggered when a WebSocket connection is closed
     */
    onClose?: (cause?: {
        code?: number;
    }) => void;
    /**
     * Lazy mode will close the WebSocket automatically after a period of inactivity (no messages sent or received and no pending requests)
     */
    lazy?: {
        /**
         * Enable lazy mode
         * @default false
         */
        enabled: boolean;
        /**
         * Close the WebSocket after this many milliseconds
         * @default 0
         */
        closeMs: number;
    };
}
export declare function createWSClient(opts: WebSocketClientOptions): {
    close: () => void;
    request: (op: Operation, callbacks: WSCallbackObserver<AnyRouter, unknown>) => UnsubscribeFn;
    readonly connection: ({
        id: number;
    } & ({
        state: 'open';
        ws: WebSocket;
    } | {
        state: 'closed';
        ws: WebSocket;
    } | {
        state: 'connecting';
        ws?: WebSocket | undefined;
    })) | null;
};
export type TRPCWebSocketClient = ReturnType<typeof createWSClient>;
export interface WebSocketLinkOptions {
    client: TRPCWebSocketClient;
}
/**
 * @link https://trpc.io/docs/v11/client/links/wsLink
 */
export declare function wsLink<TRouter extends AnyRouter>(opts: WebSocketLinkOptions): TRPCLink<TRouter>;
export {};
//# sourceMappingURL=wsLink.d.ts.map