@pgsql/cli
Version:
Unified CLI for PostgreSQL AST parsing, deparsing, and code generation
71 lines (68 loc) • 2.65 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.runtimeSchemaCommand = runtimeSchemaCommand;
const pg_proto_parser_1 = require("pg-proto-parser");
const fs_1 = require("fs");
const path_1 = require("path");
const chalk_1 = __importDefault(require("chalk"));
const help_1 = require("../utils/help");
async function runtimeSchemaCommand(argv) {
if (argv.help) {
(0, help_1.showHelp)('runtime-schema');
process.exit(0);
}
if (!argv.inFile || !argv.outDir) {
console.error(chalk_1.default.red('Error: --inFile and --outDir are required'));
(0, help_1.showHelp)('runtime-schema');
process.exit(1);
}
const format = argv.format || 'json';
const filename = argv.filename || 'runtime-schema';
try {
console.log(chalk_1.default.blue('Parsing protobuf file...'));
const options = (0, pg_proto_parser_1.getOptionsWithDefaults)({
outDir: argv.outDir
});
const parser = new pg_proto_parser_1.PgProtoParser(argv.inFile, options);
// Generate runtime schema
console.log(chalk_1.default.blue(`Generating runtime schema in ${format} format...`));
console.log(chalk_1.default.yellow('Warning: Runtime schema generation is not yet fully implemented'));
// Generate placeholder schema based on format
let content;
let fileExt;
if (format === 'typescript') {
// Generate TypeScript runtime schema placeholder
content = `// Runtime schema for PostgreSQL AST nodes
// Generated from: ${argv.inFile}
export interface RuntimeSchema {
// TODO: Implement runtime schema generation
nodes: Record<string, any>;
}
export const runtimeSchema: RuntimeSchema = {
nodes: {}
};
`;
fileExt = '.ts';
}
else {
// Generate JSON runtime schema placeholder
content = JSON.stringify({
generated: new Date().toISOString(),
source: argv.inFile,
nodes: {}
}, null, 2);
fileExt = '.json';
}
// Write file
const outputPath = (0, path_1.join)(argv.outDir, `${filename}${fileExt}`);
(0, fs_1.writeFileSync)(outputPath, content);
console.log(chalk_1.default.green(`✓ Runtime schema generated: ${outputPath}`));
}
catch (error) {
console.error(chalk_1.default.red('Runtime schema error:'), error.message || error);
process.exit(1);
}
}