34 lines
1.5 KiB
JavaScript
34 lines
1.5 KiB
JavaScript
#!/usr/bin/env node
|
|
// Data only: never load files, resolve repositories, or evaluate code.
|
|
import { parseQx } from "./source.js";
|
|
import { parseQuixosLockDocument } from "../resource-lock/parser.js";
|
|
import { instantiateWorkspaceIdentity } from "./structural-edits.js";
|
|
let input = "";
|
|
for await (const chunk of process.stdin) {
|
|
input += chunk;
|
|
if (Buffer.byteLength(input) > 6 * 1024 * 1024) throw new Error("Inspection input exceeds limit");
|
|
}
|
|
const document = JSON.parse(input);
|
|
if (!Array.isArray(document) && document?.operation === "instantiate-workspace") {
|
|
if (
|
|
typeof document.source !== "string" ||
|
|
document.source.length > 262144 ||
|
|
typeof document.workspaceId !== "string"
|
|
)
|
|
throw new Error("Invalid template identity request");
|
|
process.stdout.write(JSON.stringify({ source: instantiateWorkspaceIdentity(document.source, document.workspaceId) }));
|
|
process.exit(0);
|
|
}
|
|
const files: { path: string; source: string }[] = document;
|
|
if (!Array.isArray(files) || files.length > 128) throw new Error("Too many source files");
|
|
const result = files.map(({ path, source }) => {
|
|
if (typeof path !== "string" || typeof source !== "string" || source.length > 262144)
|
|
throw new Error("Invalid source input");
|
|
if (path.endsWith(".qx")) {
|
|
const parsed = parseQx(source, path);
|
|
return { path, root: parsed.root, diagnostics: parsed.diagnostics };
|
|
}
|
|
return { path, lock: parseQuixosLockDocument(source, path) };
|
|
});
|
|
process.stdout.write(JSON.stringify(result));
|