fix(production): preserve emitted plugin runtimes

This commit is contained in:
2026-08-13 18:00:30 +05:30
parent 94a6b436f5
commit 5106256401
6 changed files with 110 additions and 4 deletions
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "@wrnexus/db",
"version": "0.8.11",
"version": "0.8.12",
"private": true,
"type": "module",
"main": "./src/index.ts",
+5 -1
View File
@@ -188,6 +188,7 @@ export function generateQueriesFile(
): string {
const byTable = new Map(models.map((m) => [m.model.name, m]));
const usedModels = new Set<string>();
let usesExecResult = false;
const blocks: string[] = [];
for (const q of queries) {
@@ -202,6 +203,7 @@ export function generateQueriesFile(
const sig = argFields.length ? `db: Db, args: { ${argFields.join("; ")} }` : "db: Db";
if (q.kind === "exec") {
usesExecResult = true;
blocks.push(
`export async function ${q.name}(${sig}): Promise<ExecResult> {\n return db.exec(${sqlLit}, ${positional});\n}`,
);
@@ -224,7 +226,9 @@ export function generateQueriesFile(
);
}
const imports = [`import type { Db, ExecResult } from "@wrnexus/db";`];
const imports = [
`import type { Db${usesExecResult ? ", ExecResult" : ""} } from "@wrnexus/db";`,
];
if (usedModels.size > 0) {
imports.push(`import { ${[...usedModels].sort().join(", ")} } from "./schema.ts";`);
}
+7
View File
@@ -213,6 +213,13 @@ test("query generator infers params and result types", () => {
);
});
test("query generator omits ExecResult when there are no exec queries", () => {
const queries = parseQueries("-- name: ListUsers :many\nSELECT * FROM users;");
const code = generateQueriesFile(queries, [{ varName: "users", model: users }], "sqlite");
expect(code).toContain('import type { Db } from "@wrnexus/db";');
expect(code).not.toContain("ExecResult");
});
test("paginate returns a page window with correct metadata", async () => {
const { paginate } = await import("../src/index.ts");
const db = createDb(sqlite());