22 lines
1.6 KiB
TypeScript
22 lines
1.6 KiB
TypeScript
import { readFileSync, lstatSync } from "node:fs";
|
|
import { parseAllDocuments } from "yaml";
|
|
import { decode, DocumentError, runWorkspaceDocuments } from "../workspaces/documents.js";
|
|
import { validateDatabaseBootstrap } from "./bootstrap-documents.js";
|
|
|
|
/** Internal sibling protocol: only references cross back to Go, never secret contents. */
|
|
export function runBootstrapValidation(args: string[]): { status: number; output: string } {
|
|
try {
|
|
if (args.length !== 5 || args[0] !== "--directory" || args[2] !== "--bootstrap" || args[4] !== "--json") throw new Error("usage");
|
|
const checked = runWorkspaceDocuments(["validate", "--directory", args[1], "--json"]);
|
|
if (checked.status !== 0) return checked;
|
|
const info = lstatSync(args[3]);
|
|
if (!info.isFile() || info.isSymbolicLink() || info.size > 1024 * 1024) throw new Error("file");
|
|
const validated = decode(readFileSync(args[3], "utf8"), "database-bootstrap.yaml", (source) =>
|
|
validateDatabaseBootstrap(parseAllDocuments(source)[0].toJSON(), args[1]), "database bootstrap schema v1 and the Catalog binding contract");
|
|
return { status: 0, output: JSON.stringify({ schema_version: 1, ok: true, secret_files: validated.secretFiles, warnings: validated.warnings, issues: [] }) };
|
|
} catch (error) {
|
|
const issue = error instanceof DocumentError ? error.issue : { document: "database-bootstrap.yaml", field: "$", code: "bootstrap_invalid", correction: "Supply one complete Catalog database configuration per workspace in a readable local bootstrap document." };
|
|
return { status: 1, output: JSON.stringify({ schema_version: 1, ok: false, issues: [issue] }) };
|
|
}
|
|
}
|