/** * MongoDB Connection Management * * Singleton pool, connect/close, default db accessor. * Extracted from mongo.ts — pure code movement. */ import { type Collection, type Db, type Document, MongoClient } from 'mongodb'; type PoolPreset = 'high' | 'standard' | 'low'; interface PoolConfig { maxPoolSize: number; minPoolSize: number; } export interface ConnectOptions { /** Pool size preset or custom config */ pool?: PoolPreset | PoolConfig; /** Database name (defaults to DATABASE_NAME env or 'app') */ dbName?: string; /** Label for logging */ label?: string; /** Enable Next.js hot-reload persistence via globalThis */ nextjs?: boolean; } /** * Connect to MongoDB. Returns the same client/db for the same URI (singleton). * Safe to call multiple times — only connects once per URI. */ export declare function connect(uri?: string, options?: ConnectOptions): Promise<{ client: MongoClient; db: Db; }>; /** Close all connection pools. Call on graceful shutdown. */ export declare function closePool(): Promise; /** Get the default database instance. Connects automatically if needed. */ export declare function getDb(options?: ConnectOptions): Promise; /** Get a typed collection from the default database */ export declare function getCollection(name: string): Promise>; /** * Gracefully close all MongoDB pools and exit the process. * Safe to call multiple times — only runs once. * * Wire this to ALL process exit events in your entry point: * * ```typescript * import { gracefulShutdown } from '@/core/db/index.js'; * * process.on('SIGTERM', gracefulShutdown); * process.on('SIGINT', gracefulShutdown); * process.on('uncaughtException', (err) => { * console.error('Uncaught Exception:', err); * gracefulShutdown(1); * }); * process.on('unhandledRejection', (reason) => { * console.error('Unhandled Rejection:', reason); * gracefulShutdown(1); * }); * ``` */ export declare function gracefulShutdown(exitCode?: number | unknown): Promise; export {}; //# sourceMappingURL=mongo-connection.d.ts.map