@autobe/compiler
Version:
AI backend server code generator
81 lines • 3.85 kB
JavaScript
;
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.AutoBeInterfaceCompiler = void 0;
const utils_1 = require("@autobe/utils");
const migrate_1 = require("@nestia/migrate");
const ArrayUtil_1 = require("../utils/ArrayUtil");
const FilePrinter_1 = require("../utils/FilePrinter");
/**
* Custom Interface compiler that handles API specification and NestJS
* application generation.
*
* This compiler transforms validated {@link AutoBeOpenApi.IDocument} AST
* structures into comprehensive NestJS projects through a sophisticated
* multi-stage transformation pipeline. The Interface compiler bridges the gap
* between database design and application implementation, ensuring perfect
* alignment with business requirements and database schemas.
*
* The compiler leverages NestiaMigrateApplication for robust NestJS project
* generation and HttpMigration for bidirectional conversion between AutoBE AST
* and standard OpenAPI formats. All generated TypeScript code is automatically
* formatted with Prettier and organized with proper import sorting for
* production-ready quality.
*
* Key capabilities include generating complete NestJS applications with
* controllers, DTOs, client SDKs, and E2E test scaffolds, all enhanced with
* keyworded parameter optimization for AI consumption and comprehensive
* documentation derived from AST descriptions.
*
* @author Samchon
*/
class AutoBeInterfaceCompiler {
write(document, exclude) {
return __awaiter(this, void 0, void 0, function* () {
const migrate = new migrate_1.NestiaMigrateApplication((0, utils_1.transformOpenApiDocument)(document));
const files = migrate.nest({
keyword: true,
simulate: true,
e2e: true,
author: {
tag: "autobe",
value: "Generated by AutoBE - https://github.com/wrtnlabs/autobe",
},
});
return Object.fromEntries([
...(yield ArrayUtil_1.ArrayUtil.asyncMap(Object.entries(files).filter(([key, _]) => exclude.includes(key) === false), (_a) => __awaiter(this, [_a], void 0, function* ([key, value]) {
return [
key,
key.endsWith(".ts") && key.endsWith(".d.ts") === false
? yield FilePrinter_1.FilePrinter.beautify(value)
: value,
];
}))),
[
"packages/api/swagger.json",
JSON.stringify(migrate.getData().document(), null, 2),
],
]);
});
}
transform(document) {
return __awaiter(this, void 0, void 0, function* () {
return (0, utils_1.transformOpenApiDocument)(document);
});
}
invert(document) {
return __awaiter(this, void 0, void 0, function* () {
return (0, utils_1.invertOpenApiDocument)(document);
});
}
}
exports.AutoBeInterfaceCompiler = AutoBeInterfaceCompiler;
//# sourceMappingURL=AutoBeInterfaceCompiler.js.map