import type { SurrealClientView } from "../../src/types/adapter.js"; /** * In-memory `SurrealClientView` used by unit tests. Records every call. * * Lives under `src/` (not `tests/`) so coverage configs that exclude * `tests/**` still account for usage — but it is intentionally never * referenced by production exports (the root barrel never re-exports it), * so consumers do not see it. */ /** * The adapter rewrites named placeholders into positional `$pN` and passes * params as a positional array. FakeClient reconstructs a named record * keyed by `pN` so unit tests can inspect bound values predictably. */ export class FakeClient implements SurrealClientView { public isConnected = true; public log: Array<{ sql: string; params: readonly unknown[]; vars: Record; }> = []; protected readonly queryHandler: ( sql: string, vars: Record ) => Record[]; public constructor( handler: ( sql: string, vars: Record ) => Record[] = () => [] ) { this.queryHandler = handler; } public async query>( sql: string, params?: readonly unknown[] ): Promise { const arr = params ?? []; const vars: Record = {}; for (let i = 0; i < arr.length; i++) { vars[`p${i}`] = arr[i]; } this.log.push({ sql, params: arr, vars }); return this.queryHandler(sql, vars) as T[]; } public async execute(sql: string): Promise<{ rowsAffected: number }> { this.log.push({ sql, params: [], vars: {} }); return { rowsAffected: 0 }; } }