//#region src/vitest/mocks/tailordb.d.ts type QueryResolver = (query: string, params: unknown[]) => unknown[] | undefined; /** Controls how unmatched TailorDB queries are handled. */ export interface MockTailordbOptions { /** Return an empty result or throw when no configured query behavior matches. */ onUnhandled?: "fallback" | "error"; } /** Matches a TailorDB query by SQL text and optionally by parameters. */ export interface QueryMatch { /** Exact SQL text or regular expression to match. */ sql: string | RegExp; /** Exact parameters or a predicate for parameter matching. */ params?: readonly unknown[] | ((params: unknown[]) => boolean); } /** Selects TailorDB queries that receive a configured response. */ export type QueryMatcher = string | RegExp | QueryMatch | ((query: string, params: unknown[]) => boolean); /** Configures persistent and one-time responses for matched queries. */ export interface QueryBehavior { /** Return these rows for every matching query after one-time responses are consumed. */ returnsRows(rows: Row[]): QueryBehavior; /** Return these rows for the next matching query. */ returnsRowsOnce(rows: Row[]): QueryBehavior; /** Reject every matching query after one-time responses are consumed. */ rejects(error: unknown): QueryBehavior; /** Reject the next matching query. */ rejectsOnce(error: unknown): QueryBehavior; } interface ExecutedQuery { query: string; params: unknown[]; } interface CreatedClient { namespace: string | undefined; ended: boolean; } declare class MockQueryResult { command: string; rowCount: number; rows: unknown[]; constructor(rows: unknown[]); } /** * Acquire a disposable mock for TailorDB operations. Installs a mock * `tailordb.Client` whose `queryObject` is a shared `vi.fn()` (so query * responses can be staged before the client is constructed). Restored on * dispose. * @param options - Query fallback behavior * @returns Disposable TailorDB mock control object * @example * ```typescript * import { mockTailordb } from "@tailor-platform/sdk/vitest"; * * test("query-based", async () => { * using db = mockTailordb(); * db.onQuery({ sql: /FROM users/, params: ["u-1"] }).returnsRows([{ age: 30 }]); * // … * expect(db.queryObject).toHaveBeenCalled(); * expect(db.Client).toHaveBeenCalledWith({ namespace: "tailordb" }); * }); * ``` */ export declare function mockTailordb(options?: MockTailordbOptions): { /** The mock `tailordb.Client` constructor (`vi.fn`). */ Client: import("vitest").Mock<(this: any, config?: { namespace?: string; }) => void>; /** The shared `queryObject` `vi.fn` used by every client and transaction. */ queryObject: import("vitest").Mock<(query: string, params?: unknown[]) => Promise>; /** * Set a fallback query resolver. Called when the enqueue queue is empty. * @param resolver - Function that returns rows for a given query and params */ setQueryResolver(resolver: QueryResolver): void; /** * Configure responses for queries matching SQL text, parameters, or a predicate. * More recently registered matchers take precedence. * Do not combine matchers with a direct `queryObject.mockImplementation()` override. * @param matcher - Query matcher * @returns Chainable query behavior */ onQuery(matcher: QueryMatcher): QueryBehavior; /** * Enqueue rows for the next `queryObject` call (FIFO; takes priority over * `setQueryResolver`). Call with no arguments for an empty result. * @param rows - Row objects to return from the next `queryObject` call */ enqueueResult(...rows: unknown[]): void; /** * Enqueue rows for multiple subsequent `queryObject` calls (FIFO). * @param rowsList - Rows arrays, one per upcoming query */ enqueueResults(...rowsList: unknown[][]): void; /** * Enqueue row arrays for subsequent queries whose exact order is under test. * @param rowsList - Rows arrays, one per upcoming query */ enqueueRows(...rowsList: unknown[][]): void; /** * All queries executed via `queryObject`, in order, derived from the vi.fn * call records. * @returns Executed queries array */ readonly executedQueries: ExecutedQuery[]; /** * All TailorDB clients created, with their namespace and end state. * @returns Created clients array */ readonly createdClients: CreatedClient[]; /** Clear recorded calls while preserving configured query behavior. */ clear(): void; /** Reset query responses and recorded calls (keeps the mock installed). */ reset(): void; } & Disposable; //#endregion