import { type Socket } from 'node:net'; import { type ConnectionOptions as TLSConnectionOptions } from 'node:tls'; import { type CallbackWithPromise } from '../apis/callbacks.ts'; import { type Callback, type ResponseParser } from '../apis/definitions.ts'; import { type SASLMechanismValue } from '../apis/enumerations.ts'; import { type SaslAuthenticateResponse, type SASLAuthenticationAPI } from '../apis/security/sasl-authenticate-v2.ts'; import { TimeoutError } from '../errors.ts'; import { TypedEventEmitter, type TypedEvents } from '../events.ts'; import { Writer } from '../protocol/writer.ts'; export interface ConnectionEvents extends TypedEvents { connecting: () => void; timeout: (error: TimeoutError) => void; error: (error: Error) => void; connect: () => void; ready: () => void; close: () => void; closing: () => void; 'sasl:handshake': (mechanisms: string[]) => void; 'sasl:authentication': (authBytes?: Buffer) => void; 'sasl:authentication:extended': (authBytes?: Buffer) => void; drain: () => void; } export type CredentialProvider = () => T | Promise; export type SASLCredentialProvider = CredentialProvider; export interface Broker { host: string; port: number; } export type SASLCustomAuthenticator = (mechanism: SASLMechanismValue, connection: Connection, authenticate: SASLAuthenticationAPI, usernameProvider: string | CredentialProvider | undefined, passwordProvider: string | CredentialProvider | undefined, tokenProvider: string | CredentialProvider | undefined, callback: CallbackWithPromise) => void; export interface SASLOptions { mechanism: SASLMechanismValue; username?: string | CredentialProvider; password?: string | CredentialProvider; token?: string | CredentialProvider; oauthBearerExtensions?: Record | CredentialProvider>; authenticate?: SASLCustomAuthenticator; authBytesValidator?: (authBytes: Buffer, callback: CallbackWithPromise) => void; } export interface ConnectionOptions { connectTimeout?: number; requestTimeout?: number; maxInflights?: number; tls?: TLSConnectionOptions; ssl?: TLSConnectionOptions; tlsServerName?: string | boolean; sasl?: SASLOptions; ownerId?: number; handleBackPressure?: boolean; context?: unknown; } export interface Request { correlationId: number; apiKey: number; apiVersion: number; hasResponseHeaderTaggedFields: boolean; noResponse: boolean; payload: Buffer; parser: ResponseParser; callback: Callback; diagnostic: Record; timeoutHandle: NodeJS.Timeout | null; timedOut: boolean; } export declare const ConnectionStatuses: { readonly NONE: "none"; readonly CONNECTING: "connecting"; readonly AUTHENTICATING: "authenticating"; readonly REAUTHENTICATING: "reauthenticating"; readonly CONNECTED: "connected"; readonly CLOSED: "closed"; readonly CLOSING: "closing"; readonly ERROR: "error"; }; export type ConnectionStatus = keyof typeof ConnectionStatuses; export type ConnectionStatusValue = (typeof ConnectionStatuses)[keyof typeof ConnectionStatuses]; export declare const defaultOptions: { connectTimeout: number; requestTimeout: number; maxInflights: number; }; export declare class Connection extends TypedEventEmitter { #private; constructor(clientId?: string, options?: ConnectionOptions); get host(): string | undefined; get port(): number | undefined; get instanceId(): number; get ownerId(): number | undefined; get status(): ConnectionStatusValue; get context(): unknown; get socket(): Socket; isConnected(): boolean; connect(host: string, port: number, callback?: CallbackWithPromise): void | Promise; ready(callback: CallbackWithPromise): void; ready(): Promise; close(callback: CallbackWithPromise): void; close(): Promise; send(apiKey: number, apiVersion: number, createPayload: () => Writer, responseParser: ResponseParser, hasRequestHeaderTaggedFields: boolean, hasResponseHeaderTaggedFields: boolean, callback: Callback): void; reauthenticate(): void; }