UNPKG

@autobe/agent

Version:

AI backend server code generator

59 lines (51 loc) 5.86 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.transformInterfaceSchemaRenameHistory = void 0; const utils_1 = require("@autobe/utils"); const utils_2 = require("@typia/utils"); const pluralize_1 = require("pluralize"); const uuid_1 = require("uuid"); const transformInterfaceSchemaRenameHistory = (props) => { return { histories: [ { type: "systemMessage", id: (0, uuid_1.v7)(), created_at: new Date().toISOString(), text: "<!--\nfilename: INTERFACE_SCHEMA_RENAME.md\n-->\n# Schema Rename Agent\n\nYou detect and correct DTO type names that omit words from their database table name, or use concatenated variant suffixes instead of dot notation.\n\n**Function calling is MANDATORY** \u2014 call `rename` immediately without asking.\n\n## 1. The Two Rules\n\n### Rule A \u2014 Preserve All Table Words\n\nEvery word in the database table name must appear in the DTO type name, in order, converted to PascalCase singular with an `I` prefix.\n\n```\nshopping_sales \u2192 IShoppingSale \u2705\nshopping_sale_reviews \u2192 IShoppingSaleReview \u2705\nshopping_sale_reviews \u2192 ISaleReview \u274C missing \"Shopping\"\nbbs_article_comments \u2192 IBbsComment \u274C missing \"Article\"\n```\n\nExtra words beyond the table name are acceptable \u2014 only omissions are violations:\n\n```\nbbs_article_comments \u2192 IBbsArticleCommentContent \u2705 extra \"Content\" is fine\n```\n\n### Rule B \u2014 Dot-Separated Variant Suffixes\n\nType variants (`.ICreate`, `.IUpdate`, `.ISummary`, `.IRequest`, `.IInvert`, `.IAbridge`) use dot + `I` prefix notation.\n\n| Wrong (concatenated) | Correct |\n|---|---|\n| `IShoppingSaleICreate` | `IShoppingSale.ICreate` |\n| `IShoppingSaleSummary` | `IShoppingSale.ISummary` |\n| `IBbsArticleUpdate` | `IBbsArticle.IUpdate` |\n\nWhen you detect concatenation, strip the suffix to get the base type and provide a refactoring for the base type only \u2014 the system corrects dot separators automatically.\n\n## 2. Analysis Process\n\nFor each DTO type name:\n\n1. **Strip variant suffix** \u2014 check for `.ICreate`, `ICreate`, or bare `Create` (and other variants) at the end; extract the base type\n2. **Find the matching table** \u2014 convert base type from PascalCase to snake_case, match against the table list\n3. **Compare word components** \u2014 verify all table words appear in order in the base type\n4. **Record violation** \u2014 if words are omitted, output a `{ from, to }` for the base type\n\nSkip materialized views (`mv_*` tables).\n\n### Examples\n\n```\nTable: shopping_order_good_refunds\nType: IShoppingRefund.ICreate\nBase: IShoppingRefund\nWords: [\"shopping\", \"order\", \"good\", \"refund\"]\nMatch: \"Shopping\" \u2705, \"order\" \u274C MISSING, \"good\" \u274C MISSING, \"Refund\" \u2705\nFix: { from: \"IShoppingRefund\", to: \"IShoppingOrderGoodRefund\" }\n```\n\n```\nTable: bbs_articles\nType: IBbsArticle\nWords: [\"bbs\", \"article\"]\nMatch: \"Bbs\" \u2705, \"Article\" \u2705\nFix: none needed\n```\n\n## 3. Function Calling\n\n```typescript\nrename({\n refactors: AutoBeInterfaceSchemaRefactor[]\n // each: { from: string, to: string }\n})\n```\n\nOutput rules:\n- Include only base type names with violations (not variants like `ISale.ICreate`)\n- Omit correctly named types \u2014 do not map a type to itself\n- Return an empty `refactors` array if no violations exist\n\n## 4. Checklist\n\n- [ ] Analyzed all provided type names against all table names\n- [ ] Every table word preserved in order in the corrected name\n- [ ] Refactors contain base type names only (no variant suffixes)\n- [ ] No self-referencing entries (`from` !== `to`)\n- [ ] Empty array returned when all names are correct\n- [ ] PascalCase with `I` prefix, singular form" /* AutoBeSystemPromptConstant.INTERFACE_SCHEMA_RENAME */, }, { type: "assistantMessage", id: (0, uuid_1.v7)(), created_at: new Date().toISOString(), text: utils_1.StringUtil.trim ` ## Database Table Names Here is the complete list of table names from the database schema. Use these as the source of truth for determining correct DTO type names. Each table name should be converted to a DTO type name by: 1. Converting from snake_case to PascalCase 2. Preserving ALL words from the table name 3. Adding "I" prefix for interface types Table Name | Expected DTO Type Name -----------|------------------------ ${props.tableNames .map((name) => [name, `I${utils_2.NamingConvention.pascal((0, pluralize_1.singular)(name))}`].join(" | ")) .join("\n")} ## Current DTO Type Names Here is the list of existing DTO type names currently in the OpenAPI specification. Analyze these to identify which ones violate the naming rules by omitting intermediate words or service prefixes from their corresponding table names. **Current Type Names:** ${props.typeNames.map((name) => `- \`${name}\``).join("\n")} ## Your Task Compare the table names with the current type names to identify violations. For each type name that incorrectly omits words from its table name, provide a refactoring entry with the correct name that preserves all components. `, }, ], userMessage: "Analyze and provide schema type name refactorings please", }; }; exports.transformInterfaceSchemaRenameHistory = transformInterfaceSchemaRenameHistory; //# sourceMappingURL=transformInterfaceSchemaRenameHistory.js.map