import type { ConnectionConfig, Driver } from '../drivers/Driver'; import { IdentityMap } from './IdentityMap'; import { QueryBuilder } from './QueryBuilder'; import type { AbstractDao } from './AbstractDao'; import { TypedEmitter } from './TypedEmitter'; import type { ChangeEvent, ConnectionEvents } from './events'; export type DriverName = 'postgres'; export interface OpenOptions extends ConnectionConfig { driver?: DriverName; } export type DaoCtor> = new (conn: Connection) => D; export declare class Connection { readonly driver: Driver; readonly schema: string; readonly qb: QueryBuilder; readonly identityMap: IdentityMap; readonly events: TypedEmitter; private readonly daos; /** Stack of pending event buffers, one per active transaction. Empty = autocommit. */ private readonly _eventBuffers; private constructor(); static open(opts: OpenOptions): Promise; /** Lazy-instantiate (and cache) a DAO. */ dao>(ctor: DaoCtor): D; transaction(fn: () => Promise): Promise; /** Internal: called by DAOs after a successful write. Buffers in tx, otherwise emits. */ _emitChange(ev: ChangeEvent): void; private _dispatch; close(): Promise; /** * Subscribe to a Postgres-style asynchronous notification channel (LISTEN / * pg_notify). Each handler is delivered the raw NOTIFY payload string; * decoding is up to the caller. Returns an unlisten function. * * Throws if the active driver doesn't support notifications. The Postgres * driver pins a dedicated pool client for the lifetime of the first * subscription and releases it on `Connection.close()`. */ listen(channel: string, handler: (payload: string) => void): Promise<() => Promise>; }