import type { MiddlewareHandler } from "hono"; import { type DbSource, type VoyantBindings, type VoyantDb } from "../types.js"; import { DB_METRICS_CONTEXT_KEY, type RequestDbMetrics } from "./metrics.js"; export interface DbMiddlewareOptions { /** * Names of modules that require a transaction-capable db adapter * (those that set `Module.requiresTransactionalDb`). If non-empty * and the first resolved db reports * `dbSupportsTransactions(db) === false`, the middleware throws a * clear error naming the offending modules. A capability of * `undefined` (untagged drivers like raw `drizzle-orm/node-postgres`) * is treated as "assume capable" — only an explicit `false` * (neon-http) trips the assertion. */ requiresTransactionalDb?: readonly string[]; /** * Deployment prefix stripped before path-based DB surface selection. Must * match the app's auth/public-path basePath when the app is hosted under a * path prefix. */ basePath?: string; } /** * Resolves the per-request db client and stores it on Hono context. * * If the factory returns a {@link DisposableDb}, the middleware schedules * `dispose()` via `c.executionCtx.waitUntil` so request-owned resources close * cleanly after the response is sent. Process-owned Node pools may return a * no-op disposer through `openNodeDatabase` from `@voyant-travel/db/runtime`. * * Factories that return a plain {@link VoyantDb} (e.g. a long-lived * postgres-js client cached at the module level) are wired up as * before with no cleanup hook. * * The client is shared per request via {@link acquireRequestDb}: if the * auth middleware (which runs earlier) already created one for the same * factory, this middleware reuses it instead of opening a second Pool — * the creator's `release()` owns the dispose. */ export declare function db(source: DbSource, options?: DbMiddlewareOptions): MiddlewareHandler<{ Bindings: TBindings; Variables: { db: VoyantDb; [DB_METRICS_CONTEXT_KEY]?: RequestDbMetrics; }; }>;