import type { Adapter, ColumnTypes, Functions } from '@kubun/db-adapter'; import { type Logger } from '@kubun/logger'; import { Kysely } from 'kysely'; import { type Migration } from 'kysely/migration'; export type MigrationContext = { types: ColumnTypes; functions: Functions; }; export type StoreDefinition = { name: string; migrations: Record | ((ctx: MigrationContext) => Record); dependsOn?: Array; createAPI: (db: Kysely, adapter: Adapter) => API; }; export type StoreProvider = Record> = { getStore(name: S): Promise; onCommit(fn: () => void): void; /** * Run `fn` against a `StoreProvider` that scopes its writes to a transaction. * * On `KubunDB`, opens a fresh DB transaction and provides a transactional * `tx` provider; the outer provider's `onCommit` hooks fire after commit. * * On a transactional `tx` provider obtained from a parent * `withTransaction` call, this method runs `fn` inline with `this` as the * nested `tx`. The underlying driver does not nest transactions * (no savepoints), so atomicity is inherited from the outer transaction * — a throw in `fn` rolls the whole outer transaction back, exactly the * semantics callers expect for "register + bind atomically". */ withTransaction, R>(fn: (tx: StoreProvider) => Promise): Promise; }; export type KubunDBParams = { adapter: Adapter; logger?: Logger; }; export declare class KubunDB implements StoreProvider { #private; constructor(params: KubunDBParams); get adapter(): Adapter; register(store: StoreDefinition): void; getStore(name: string): Promise; onCommit(fn: () => void): void; /** * Runs `fn` inside a DB transaction and provides a scoped `StoreProvider`. * Concurrent calls on the same `KubunDB` instance are supported — the * underlying driver serializes them. * * Callers MUST use the provided `tx` inside the callback. Calling * `db.withTransaction` on the same instance inside the callback opens a * new independent transaction (no atomic nesting) and is a bug. */ withTransaction, R>(fn: (tx: StoreProvider) => Promise): Promise; close(): Promise; }