fix(packages): polish cli and mcp package contracts
This commit is contained in:
@@ -16,6 +16,7 @@
|
||||
"./connections": "./dist/connections.js",
|
||||
"./database": "./dist/database.js",
|
||||
"./diagnostics": "./dist/diagnostics.js",
|
||||
"./format": "./dist/format.js",
|
||||
"./paths": "./dist/paths.js",
|
||||
"./schema-context": "./dist/schema-context.js",
|
||||
"./sql-safety": "./dist/sql-safety.js"
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
export function mdTable(headers: string[], rows: string[][]): string {
|
||||
const widths = headers.map((h, i) => Math.max(h.length, ...rows.map((r) => (r[i] || "").length), 3));
|
||||
const header = `| ${headers.map((h, i) => h.padEnd(widths[i])).join(" | ")} |`;
|
||||
const sep = `| ${widths.map((w) => "-".repeat(w)).join(" | ")} |`;
|
||||
const body = rows.map((r) => `| ${r.map((c, i) => (c || "").padEnd(widths[i])).join(" | ")} |`).join("\n");
|
||||
return body ? `${header}\n${sep}\n${body}` : `${header}\n${sep}`;
|
||||
}
|
||||
|
||||
export function formatCell(value: unknown): string {
|
||||
if (value === null || value === undefined) return "NULL";
|
||||
if (typeof value === "object") return JSON.stringify(value);
|
||||
return String(value);
|
||||
}
|
||||
@@ -3,6 +3,7 @@ export * from "./bridge.js";
|
||||
export * from "./connections.js";
|
||||
export * from "./database.js";
|
||||
export * from "./diagnostics.js";
|
||||
export * from "./format.js";
|
||||
export * from "./paths.js";
|
||||
export * from "./schema-context.js";
|
||||
export * from "./sql-safety.js";
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
import assert from "node:assert/strict";
|
||||
import test from "node:test";
|
||||
import { formatCell, mdTable } from "../src/format.js";
|
||||
|
||||
test("formats markdown tables", () => {
|
||||
assert.equal(mdTable(["Name", "Type"], [["local", "postgres"]]), "| Name | Type |\n| ----- | -------- |\n| local | postgres |");
|
||||
});
|
||||
|
||||
test("formats database cell values", () => {
|
||||
assert.equal(formatCell(null), "NULL");
|
||||
assert.equal(formatCell(undefined), "NULL");
|
||||
assert.equal(formatCell({ ok: true }), "{\"ok\":true}");
|
||||
assert.equal(formatCell("hello"), "hello");
|
||||
});
|
||||
Reference in New Issue
Block a user