import { type DbFactory, type VoyantBindings, type VoyantDb } from "../types.js"; /** * Minimal structural slice of a Hono `Context` that the request-db * helpers need. Typed structurally so unit tests can pass a stub and so * this module doesn't constrain the app's `Variables` generic. */ export interface RequestDbContextLike { req: { raw: Request; }; env: TBindings; /** * Hono throws on `executionCtx` access in runtimes without one (Node * tests, some adapters) — callers of {@link acquireRequestDb} never * touch it directly; we read it defensively inside `release`. */ executionCtx?: unknown; } export interface RequestDbLease { db: VoyantDb; /** * Whether this lease created the underlying client. Only the creator's * `release()` disposes; reuse leases are no-ops, so the client stays * alive until the outermost (creating) middleware's `finally` runs — * which is after the entire downstream pipeline has completed. */ isCreator: boolean; /** * Settle the lease. For the creating lease this schedules `dispose()` * via `executionCtx.waitUntil` (or awaits inline outside Workers). * Idempotent; reuse leases resolve immediately. */ release: () => Promise; } /** * Resolve the shared per-request db client for `factory`, creating it on * first acquisition. The creating caller MUST call `lease.release()` in * a `finally` after its `next()` completes; later acquirers within the * same request reuse the client and their `release()` is a no-op. */ export declare function acquireRequestDb(c: RequestDbContextLike, factory: DbFactory): RequestDbLease;