@autobe/agent
Version:
AI backend server code generator
232 lines (227 loc) • 9.45 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.fixPreliminaryApplication = void 0;
const utils_1 = require("@autobe/utils");
const utils_2 = require("@typia/utils");
const typia_1 = __importDefault(require("typia"));
const fixPreliminaryApplication = (props) => {
if (props.preliminary.getKinds().some((k) => k.includes("previous")) === false)
return;
const func = props.application.functions.find((f) => f.name === "process");
if (func === undefined)
return;
const request = func.parameters.properties.request;
if (request === undefined)
return;
const eraseKind = (kind) => {
props.preliminary.getKinds().splice(props.preliminary.getKinds().indexOf(
// biome-ignore lint: intended
kind), 1);
// biome-ignore lint: intended
delete props.preliminary.getAll()[kind];
// biome-ignore lint: intended
delete props.preliminary.getLocal()[kind];
};
const eraseMetadata = getUnionErasure({
$defs: func.parameters.$defs,
request,
});
if (eraseMetadata === null)
return;
for (const kind of props.preliminary.getKinds().slice())
if (kind === "previousAnalysisSections") {
if (props.state.previousAnalyze === null) {
eraseMetadata("getPreviousAnalysisSections");
eraseKind(kind);
}
}
else if (kind === "previousDatabaseSchemas") {
if (props.state.previousDatabase === null) {
eraseMetadata("getPreviousDatabaseSchemas");
eraseKind(kind);
}
}
else if (kind === "previousInterfaceOperations") {
if (props.state.previousInterface === null) {
eraseMetadata("getPreviousInterfaceOperations");
eraseKind(kind);
}
}
else if (kind === "previousInterfaceSchemas") {
if (props.state.previousInterface === null) {
eraseMetadata("getPreviousInterfaceSchemas");
eraseKind(kind);
}
}
for (const kind of props.preliminary.getKinds()) {
const accessor = (kind.startsWith("previous")
? (() => {
const value = kind.replace("previous", "");
return value[0].toLowerCase() + value.substring(1);
})()
: kind);
if (props.enumerable === false &&
accessor !== "analysisSections" &&
accessor !== "databaseSchemas")
continue;
ApplicationFixer[accessor]({
$defs: func.parameters.$defs,
// biome-ignore lint: intended
controller: props.preliminary,
previous: kind.startsWith("previous"),
});
}
};
exports.fixPreliminaryApplication = fixPreliminaryApplication;
const getUnionErasure = (props) => {
var _a, _b;
if (utils_2.LlmTypeChecker.isAnyOf(props.request) === false)
return null;
else if (props.request.anyOf.some((s) => utils_2.LlmTypeChecker.isReference(s) === false))
return null;
const children = props.request
.anyOf;
const mapping = (_b = (_a = props.request["x-discriminator"]) === null || _a === void 0 ? void 0 : _a.mapping) !== null && _b !== void 0 ? _b : {};
return (key) => {
const type = `IAutoBePreliminary${key[0].toUpperCase()}${key.substring(1)}`;
const index = children.findIndex((c) => c.$ref.endsWith(`/${type}`));
if (index !== -1)
children.splice(index, 1);
delete props.$defs[key];
delete mapping[key];
};
};
var ApplicationFixer;
(function (ApplicationFixer) {
ApplicationFixer.analysisSections = (props) => {
const sections = props.controller.getAll()[props.previous ? "previousAnalysisSections" : "analysisSections"];
if (sections.length === 0)
return;
const type = props.$defs[props.previous
? "IAutoBePreliminaryGetPreviousAnalysisSections" : "IAutoBePreliminaryGetAnalysisSections"];
if (type === undefined)
return;
const array = type.properties.sectionIds;
if (array === undefined)
return;
else if (utils_2.LlmTypeChecker.isArray(array) === false)
return;
// describe(
// array,
// StringUtil.trim`
// Here is the catalog of analysis sections available for retrieval:
// ID | File | Unit | Section | Keywords
// ---|------|------|---------|----------
// ${sections
// .map(
// (s) =>
// `${s.id} | ${s.filename} | ${s.unitTitle} | ${s.sectionTitle} | ${s.keywords.join(", ")}`,
// )
// .join("\n")}
// `,
// );
const items = array.items;
if (utils_2.LlmTypeChecker.isInteger(items) === false)
return;
items.minimum = Math.min(...sections.map((s) => s.id));
items.maximum = Math.max(...sections.map((s) => s.id));
};
ApplicationFixer.databaseSchemas = (props) => {
const schemas = props.controller.getAll()[props.previous ? "previousDatabaseSchemas" : "databaseSchemas"];
if (schemas.length === 0)
return;
const type = props.$defs[props.previous
? "IAutoBePreliminaryGetPreviousDatabaseSchemas" : "IAutoBePreliminaryGetDatabaseSchemas"];
if (type === undefined)
return;
describe(type.properties.schemaNames, utils_1.StringUtil.trim `
Here is the list of database schemas available for retrieval:
${schemas
.slice()
.sort((a, b) => a.name.localeCompare(b.name))
.map((s) => `- ${s.name}`)
.join("\n")}
`);
};
ApplicationFixer.interfaceOperations = (props) => {
const operations = props.controller.getAll()[props.previous ? "previousInterfaceOperations" : "interfaceOperations"];
if (operations.length === 0)
return;
const type = props.$defs[props.previous
? "IAutoBePreliminaryGetPreviousInterfaceOperations" : "IAutoBePreliminaryGetInterfaceOperations"];
if (type === undefined)
return;
describe(type.properties.endpoints, utils_1.StringUtil.trim `
Here is the list of interface operations available for retrieval:
path | method
---- | ------
${operations
.slice()
.sort(utils_1.AutoBeOpenApiEndpointComparator.compare)
.map((o) => ` ${o.path} | ${o.method}`)
.join("\n")}
`);
};
ApplicationFixer.interfaceSchemas = (props) => {
const dtoTypeNames = Object.keys(props.controller.getAll()[props.previous ? "previousInterfaceSchemas" : "interfaceSchemas"]);
if (dtoTypeNames.length === 0)
return;
const type = props.$defs[props.previous
? "IAutoBePreliminaryGetPreviousInterfaceSchemas" : "IAutoBePreliminaryGetInterfaceSchemas"];
if (type === undefined)
return;
describe(type.properties.typeNames, utils_1.StringUtil.trim `
Here is the list of interface schemas available for retrieval:
${dtoTypeNames
.slice()
.sort((a, b) => a.localeCompare(b))
.map((name) => `- ${name}`)
.join("\n")}
`);
};
ApplicationFixer.realizeCollectors = (props) => {
if (props.controller.getAll().realizeCollectors.length === 0)
return;
const type = props.$defs["IAutoBePreliminaryGetRealizeCollectors"];
if (type === undefined)
return;
describe(type.properties.dtoTypeNames, utils_1.StringUtil.trim `
Here is the list of DTO types available for realize collectors:
${props.controller
.getAll()
.realizeCollectors.slice()
.sort((a, b) => a.plan.dtoTypeName.localeCompare(b.plan.dtoTypeName))
.map((x) => `- ${x.plan.dtoTypeName}`)
.join("\n")}
`);
};
// biome-ignore lint: no-op for control signal kind
ApplicationFixer.complete = (_props) => { };
ApplicationFixer.realizeTransformers = (props) => {
if (props.controller.getAll().realizeTransformers.length === 0)
return;
const type = props.$defs["IAutoBePreliminaryGetRealizeTransformers"];
if (type === undefined)
return;
describe(type.properties.dtoTypeNames, utils_1.StringUtil.trim `
Here is the list of DTO types available for realize transformers:
${props.controller
.getAll()
.realizeTransformers.slice()
.sort((a, b) => a.plan.dtoTypeName.localeCompare(b.plan.dtoTypeName))
.map((x) => `- ${x.plan.dtoTypeName}`)
.join("\n")}
`);
};
})(ApplicationFixer || (ApplicationFixer = {}));
const describe = (schema, content) => {
var _a;
(_a = schema.description) !== null && _a !== void 0 ? _a : (schema.description = "");
if (schema.description.length > 0)
schema.description += "\n\n";
schema.description += content;
};
//# sourceMappingURL=fixPrelminaryApplication.js.map