import { MongoClient, type ClientSession, type ClientSessionOptions, type Collection, type Db, type MongoClientOptions, type TransactionOptions } from 'mongodb'; import { LoggerFactory } from '@nl-framework/logger'; import type { DocumentClass, DocumentMetadata, BaseDocument } from '../interfaces/document'; import type { OrmConnection } from '../interfaces/driver'; import { WriteNotifier, type EntityWriteListener } from '../events/write-notifier'; export interface MongoConnectionOptions { uri: string; dbName?: string; clientOptions?: MongoClientOptions; connectionName: string; /** Create all indexes declared via `@Index` / `@Document({ indexes })` right after connecting. */ autoIndex?: boolean; } export interface WithTransactionOptions { session?: ClientSessionOptions; transaction?: TransactionOptions; } export declare class MongoConnection implements OrmConnection { private readonly options; private client?; private database?; private readonly entities; private readonly logger; private readonly writeNotifier; constructor(options: MongoConnectionOptions, loggerFactory: LoggerFactory); getWriteNotifier(): WriteNotifier; /** Subscribe to write events from every repository on this connection. Returns an unsubscribe function. */ onWrite(listener: EntityWriteListener): () => void; registerEntity(entity: DocumentClass): void; getRegisteredEntities(): DocumentMetadata[]; onModuleInit(): Promise; onModuleDestroy(): Promise; ensureConnection(): Promise; /** * Create every index declared on registered entities (via `@Index` or * `@Document({ indexes })`). Fails loud: the first index that cannot be * created throws instead of being swallowed. */ ensureIndexes(): Promise; startSession(options?: ClientSessionOptions): Promise; /** * Run `fn` inside a MongoDB transaction. The session must be passed to every * repository call inside the callback (all read/write methods accept a * `session` option). The session is always ended, and the callback's return * value is returned once the transaction commits. */ withTransaction(fn: (session: ClientSession) => Promise, options?: WithTransactionOptions): Promise; getClient(): MongoClient; getDatabase(): Db; getCollection(document: DocumentClass): Promise>; } //# sourceMappingURL=mongo-connection.d.ts.map