UNPKG

@autobe/agent

Version:

AI backend server code generator

53 lines 2.71 kB
"use strict"; 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.replaceImportStatements = replaceImportStatements; const getRealizeWriteImportStatements_1 = require("./getRealizeWriteImportStatements"); function replaceImportStatements(ctx, props) { return __awaiter(this, void 0, void 0, function* () { let { code, decoratorType } = props; // Beautify code first for consistent formatting const compiler = yield ctx.compiler(); code = yield compiler.typescript.beautify(code); // Remove all LLM-generated imports code = code .split("\r\n") .join("\n") .split("\n") .filter((str) => str.trim().startsWith("import") === false) .join("\n"); // Build the standard imports const imports = (0, getRealizeWriteImportStatements_1.getRealizeWriteImportStatements)(props); // Only add decoratorType import if it exists if (decoratorType) { imports.push(`import { ${decoratorType} } from "../decorators/payload/${decoratorType}"`); } code = [...imports, "", code].join("\n"); // Clean up formatting issues code = code // Remove lines with only whitespace .replace(/^\s+$/gm, "") // Replace 3+ consecutive newlines with exactly 2 newlines .replace(/\n{3,}/g, "\n\n") // Ensure proper spacing after import section .replace(/(import.*?;)(\s*)(\n(?!import|\s*$))/g, "$1\n\n$3") // Trim and ensure single trailing newline .trim() + "\n"; // fix escaped codes code = code.replace(/\\n/g, "\n").replace(/\\"/g, '"').replace(/\\'/g, "'"); // Apply final beautification code = yield compiler.typescript.beautify(code); code = code.replaceAll("typia.tags.assert", "typia.assert"); return code; }); } //# sourceMappingURL=replaceImportStatements.js.map