import { Kysely, OperationNode, OperationNodeKind, Transaction } from "kysely"; //#region src/vitest/mock-kysely.d.ts /** A single statement executed against the mock, captured in order. */ export interface ExecutedQuery { /** The Kysely operation node kind, e.g. `"SelectQueryNode"`. */ kind: OperationNodeKind; /** The compiled SQL string. */ sql: string; /** The bound parameter values, in positional order. */ parameters: readonly unknown[]; /** The compiled Kysely operation node. */ node: OperationNode; /** One `{ column: value }` map per row written by an insert. */ insertRows: () => Record[]; /** The `{ column: value }` map written by a single-row insert. */ insertValues: () => Record; /** The `{ column: value }` map written by an update's SET clause. */ updateValues: () => Record; } type MockRow = Record; type MockResult = MockRow[] | { rows?: MockRow[]; numAffectedRows?: number | bigint; }; type QueryResolver = (query: ExecutedQuery) => MockResult | undefined; /** Controls and assertions for a {@link createKyselyMock} instance. */ export interface KyselyMock { /** The mock Kysely instance to run queries against. */ db: Kysely; /** Every recorded query, in execution order. */ executedQueries: ExecutedQuery[]; /** Recorded SELECT queries. */ selects: ExecutedQuery[]; /** Recorded INSERT queries. */ inserts: ExecutedQuery[]; /** Recorded UPDATE queries. */ updates: ExecutedQuery[]; /** Recorded DELETE queries. */ deletes: ExecutedQuery[]; /** Stage the rows the next query returns. */ enqueueResult: (result: MockResult) => void; /** Stage the rows for several upcoming queries, consumed in order. */ enqueueResults: (...results: MockResult[]) => void; /** Set a resolver that returns rows by inspecting each query. */ setQueryResolver: (resolver: QueryResolver) => void; /** Run `fn` inside a real transaction and return its result. */ withTx: (fn: (trx: Transaction) => Promise) => Promise; /** Clear recorded queries and staged results. */ reset: () => void; /** Same as {@link KyselyMock.reset}; enables `using` disposal. */ [Symbol.dispose]: () => void; } /** * Create a mock Kysely instance for unit-testing code that runs Kysely queries. * Pass the namespace schema as the type argument, e.g. * `createKyselyMock()`. * @returns A {@link KyselyMock} with the mock `db`, recorded queries, and result staging. */ export declare function createKyselyMock>(): KyselyMock; //#endregion