export declare const PG_SSL_REQUEST_CODE = 80877103; export declare const PG_GSS_ENC_REQUEST_CODE = 80877104; export declare const PG_PROTOCOL_VERSION_30 = 196608; export declare const MAX_PG_STARTUP_PACKET_LEN = 10000; export type WriteCallback = (error?: Error | null) => void; export interface WritableSocket { write?: { (chunk: Uint8Array | string, cb?: WriteCallback): boolean; (chunk: Uint8Array | string, encoding: BufferEncoding, cb?: WriteCallback): boolean; }; } /** * Wraps a socket and inspects the initial bytes written by the client driver to extract * the PostgreSQL v3 StartupMessage (user, database) pair for Auto-IAM refresh probes. * * Handles chunked streaming where the StartupMessage is split across multiple write() calls. * Follows the Node.js Writable stream contract where synchronization of concurrent writes * is the caller's responsibility, introducing zero locking overhead. Once the startup * message is detected or determined not to be a PostgreSQL v3 packet, startupMessageSent is * set to true, the buffer is cleared, and unbind() restores the original write method * (re-assigning own-property write handlers or deleting the wrapper property to restore * prototype-inherited write() on TLSSocket/net.Socket) for zero steady-state overhead. */ export declare class PostgresSocket { private readonly socket; private readonly onStartup; private readonly hasOwnWrite; private readonly rawWrite?; private readonly origWrite; private buf; startupMessageSent: boolean; constructor(socket: WritableSocket, onStartup: (user: string, database: string) => void); private unbind; private forwardOrigWrite; write(chunk: Uint8Array | string, cb?: WriteCallback): boolean; write(chunk: Uint8Array | string, encoding: BufferEncoding, cb?: WriteCallback): boolean; } export declare function attachPostgresSocket(socket: WritableSocket, onStartup: (user: string, database: string) => void): PostgresSocket; /** * Parses a buffer to extract the PostgreSQL v3 StartupMessage user and database parameters. * Accounts for prepended SSLRequest (80877103) or GSSENCRequest (80877104) packets. */ export declare function parsePostgresStartupPacket(buf: Buffer): { user: string; database: string; complete: boolean; }; /** * Builds a PostgreSQL v3.0 StartupMessage for (user, database). */ export declare function buildPostgresStartupPacket(user: string, database: string): Buffer; /** * Builds a PostgreSQL Terminate packet ('X' followed by int32 length 4). */ export declare function buildTerminatePacket(): Buffer; //# sourceMappingURL=postgres-socket.d.ts.map