fix(packages): polish cli and mcp package contracts
This commit is contained in:
@@ -1,4 +1,6 @@
|
||||
import type { ConnectionConfig } from "@dbx-app/node-core";
|
||||
import { formatCell, mdTable, type ConnectionConfig } from "@dbx-app/node-core";
|
||||
|
||||
export { formatCell, mdTable };
|
||||
|
||||
export interface ConnectionSummary {
|
||||
name: string;
|
||||
@@ -43,20 +45,6 @@ function errorHint(code: string, message: string): string | undefined {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
export function csvTable<T extends object>(headers: string[], rows: T[]): string {
|
||||
const lines = [headers.map(csvCell).join(",")];
|
||||
for (const row of rows) {
|
||||
|
||||
Reference in New Issue
Block a user