import { PGliteClient } from "../pglite-kysely.mjs"; //#region src/vitest/mocks/tailordb-pglite.d.ts /** A query executed through the PGlite-backed TailorDB client. */ export interface ExecutedPGliteQuery { /** Namespace of the `getDB` call that issued the query. */ namespace: string; /** SQL text with positional (`$1`, `$2`, ...) placeholders. */ query: string; /** Parameter values bound to the placeholders. */ params: unknown[]; } /** Options for {@link mockTailordbWithPGlite}. */ export interface MockTailordbPGliteOptions { /** * PGlite instance per `getDB` namespace. A `getDB` call for a namespace * missing here throws instead of falling back to another instance. Pass the * same instance under several namespaces to share one database between them. */ namespaces: Record; } interface CreatedClient { namespace: string; ended: boolean; } /** * Acquire a disposable mock that backs the generated `getDB(namespace)` with * PGlite, so resolver/executor/workflow code runs unchanged and its queries * execute as real SQL on an in-memory Postgres. Restored on dispose; the * PGlite instances are borrowed, never closed — close them yourself (e.g. in * `afterAll`). * * Create the tables a test needs up front: run the script `kyselyTypePlugin` * writes when `pgliteSchemaPath` is set, or your own `CREATE TABLE` * statements matching the generated Kysely types. PGlite runs full PostgreSQL * while TailorDB supports a subset of it, so a statement passing here can * still be rejected by the platform. * * Transactions on a shared instance are serialized: while one is open, * queries from other `getDB` instances on the same PGlite instance wait for * it to finish. Do not run such tests with `test.concurrent`, and do not * query the same instance through a second `getDB` from inside a transaction * — that waits on itself. * @param options - PGlite instance registration per namespace * @returns Disposable TailorDB mock control object * @example * ```typescript * import { PGlite } from "@electric-sql/pglite"; * import { mockTailordbWithPGlite } from "@tailor-platform/sdk/vitest"; * import { getDB } from "../generated/tailordb"; * * const pglite = new PGlite(); * afterAll(() => pglite.close()); * * test("real SQL", async () => { * using _db = mockTailordbWithPGlite({ namespaces: { tailordb: pglite } }); * await pglite.query(`CREATE TABLE "User" ("id" uuid PRIMARY KEY, "name" text NOT NULL)`); * await getDB("tailordb").insertInto("User").values({ id: crypto.randomUUID(), name: "a" }).execute(); * }); * ``` */ export declare function mockTailordbWithPGlite(options: MockTailordbPGliteOptions): { /** The mock `tailordb.Client` constructor (`vi.fn`). */ Client: import("vitest").Mock<(this: any, config?: { namespace?: string; }) => void>; /** * All queries executed on the PGlite instances, in order, with the * namespace that issued each. * @returns Executed queries array */ readonly executedQueries: ExecutedPGliteQuery[]; /** * All TailorDB clients created, with their namespace and end state. * @returns Created clients array */ readonly createdClients: CreatedClient[]; /** * Clear recorded queries and clients while keeping the mock installed. * Throws if a transaction is open. */ clear(): void; /** * Reset recorded state and restore the default client behavior. * Throws if a transaction is open. */ reset(): void; } & Disposable; //#endregion