@autobe/agent
Version:
AI backend server code generator
59 lines • 3.46 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.AutoBeTestFunctionProgrammer = void 0;
const uuid_1 = require("uuid");
var AutoBeTestFunctionProgrammer;
(function (AutoBeTestFunctionProgrammer) {
function compile(props) {
return __awaiter(this, void 0, void 0, function* () {
const template = Object.fromEntries(Object.entries(yield props.compiler.getTemplate({
dbms: "sqlite",
phase: "test",
})).filter(([key]) => key.startsWith("test/utils") && key.endsWith(".ts")));
const artifacts = yield props.compiler.interface.write(props.document, []);
const sdk = Object.fromEntries(Object.entries(artifacts).filter(([key]) => key.startsWith("src/api") && !key.startsWith("src/api/structures")));
const dto = Object.fromEntries(Object.entries(artifacts).filter(([key]) => key.startsWith("src/api/structures")));
const everything = Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({}, template), sdk), dto), props.files), (yield props.compiler.test.getDefaultTypes()));
const result = yield props.compiler.test.compile({
files: everything,
});
return {
type: "testValidate",
id: (0, uuid_1.v7)(),
function: props.function,
result,
created_at: new Date().toISOString(),
step: props.step,
completed: ++props.progress.completed,
total: props.progress.total,
};
});
}
AutoBeTestFunctionProgrammer.compile = compile;
function writeImportStatements(schemas) {
const typeReferences = new Set(Object.keys(schemas).map((key) => key.split(".")[0]));
return [
`import { ArrayUtil, RandomGenerator, TestValidator } from "@nestia/e2e";`,
`import { IConnection } from "@nestia/fetcher";`,
`import { randint } from "tstl";`,
`import typia, { tags } from "typia";`,
`import api from "@ORGANIZATION/PROJECT-api";`,
`import { DeepPartial } from "@ORGANIZATION/PROJECT-api/lib/typings/DeepPartial";`,
`import { IEntity } from "@ORGANIZATION/PROJECT-api/lib/structures/IEntity";`,
...Array.from(typeReferences)
.sort()
.map((ref) => `import type { ${ref} } from "@ORGANIZATION/PROJECT-api/lib/structures/${ref}";`),
];
}
AutoBeTestFunctionProgrammer.writeImportStatements = writeImportStatements;
})(AutoBeTestFunctionProgrammer || (exports.AutoBeTestFunctionProgrammer = AutoBeTestFunctionProgrammer = {}));
//# sourceMappingURL=AutoBeTestFunctionProgrammer.js.map