@autobe/agent
Version:
AI backend server code generator
74 lines • 4.28 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.getAutoBeGenerated = getAutoBeGenerated;
function getAutoBeGenerated(compiler, state, histories, tokenUsage, options) {
return __awaiter(this, void 0, void 0, function* () {
var _a, _b, _c, _d, _e, _f;
// ANALYZE
const ret = {};
if (state.analyze === null)
return {};
Object.assign(ret, Object.fromEntries(Object.entries(state.analyze.files).map(([key, value]) => [
`docs/analysis/${key.split("/").at(-1)}`,
value,
])));
// PRISMA
if (((_a = state.prisma) === null || _a === void 0 ? void 0 : _a.step) === state.analyze.step) {
const schemaFiles = ((_b = options === null || options === void 0 ? void 0 : options.dbms) !== null && _b !== void 0 ? _b : "postgres") === "postgres"
? state.prisma.schemas
: yield compiler.prisma.write(state.prisma.result.data, options.dbms);
Object.assign(ret, Object.fromEntries(Object.entries(schemaFiles).map(([key, value]) => [
`prisma/schema/${key.split("/").at(-1)}`,
value,
])), {
"autobe/prisma.json": JSON.stringify(state.prisma.result.data),
});
if (state.prisma.compiled.type === "success")
ret["docs/ERD.md"] = state.prisma.compiled.document;
else if (state.prisma.compiled.type === "failure")
ret["prisma/compile-error-reason.log"] = state.prisma.compiled.reason;
}
// INTERFACE
if (((_c = state.interface) === null || _c === void 0 ? void 0 : _c.step) === state.analyze.step) {
const files = yield compiler.interface.write(state.interface.document);
Object.assign(ret, ((_d = state.test) === null || _d === void 0 ? void 0 : _d.step) === state.interface.step
? Object.fromEntries(Object.entries(files).filter(([key]) => key.startsWith("test/features/") === false))
: files, {
"autobe/document.json": JSON.stringify(state.interface.document),
});
}
// TEST
if (((_e = state.test) === null || _e === void 0 ? void 0 : _e.step) === state.analyze.step)
Object.assign(ret, Object.fromEntries(state.test.files.map((f) => [f.location, f.content])), yield compiler.test.getTemplate());
// REALIZE
if (((_f = state.realize) === null || _f === void 0 ? void 0 : _f.step) === state.analyze.step) {
Object.assign(ret, Object.assign(Object.assign(Object.assign(Object.assign({}, Object.fromEntries(state.realize.functions.map((f) => [f.location, f.content]))), Object.fromEntries(state.realize.authorizations
.map((auth) => [
[auth.decorator.location, auth.decorator.content],
[auth.provider.location, auth.provider.content],
[auth.payload.location, auth.payload.content],
])
.flat())), (yield compiler.realize.getTemplate())), (yield compiler.realize.controller({
document: state.interface.document,
functions: state.realize.functions,
authorizations: state.realize.authorizations,
}))));
}
// LOGGING
Object.assign(ret, {
"autobe/histories.json": JSON.stringify(histories),
"autobe/tokenUsage.json": JSON.stringify(tokenUsage),
});
return ret;
});
}
//# sourceMappingURL=getAutoBeGenerated.js.map