UNPKG

@autobe/agent

Version:

AI backend server code generator

73 lines (69 loc) 3.57 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.AutoBeDatabaseAuthorizationProgrammer = void 0; const utils_1 = require("@autobe/utils"); const utils_2 = require("@typia/utils"); const pluralize_1 = require("pluralize"); const AutoBeDatabaseComponentProgrammer_1 = require("./AutoBeDatabaseComponentProgrammer"); var AutoBeDatabaseAuthorizationProgrammer; (function (AutoBeDatabaseAuthorizationProgrammer) { /** Validate authorization tables for an actor. */ AutoBeDatabaseAuthorizationProgrammer.validate = (props) => { // validate common logic AutoBeDatabaseComponentProgrammer_1.AutoBeDatabaseComponentProgrammer.validate(props); // Validation: all tables must contain actor name const prefix = props.prefix ? `${props.prefix}_` : ""; const actorNames = props.actors.map((actor) => prefix + utils_2.NamingConvention.snake(actor.name)); props.tables.forEach((table, i) => { if (actorNames.some((an) => table.name.startsWith(an)) === false) props.errors.push({ path: `${props.path}[${i}].name`, expected: `\`\${${actorNames.map((s) => JSON.stringify(s)).join(" | ")}}\${string}\``, value: table.name, description: utils_1.StringUtil.trim ` Table "${table.name}" does not start with none of below: ${actorNames.map((an) => `- "${an}"`).join("\n")} Fix: Add one of above to the table name, or remove this table if it is unrelated to some actor. `, }); }); for (const actor of props.actors) { // Validation: actor table must exist const name = utils_2.NamingConvention.snake(actor.name); const tableNames = props.tables.map((t) => t.name); const expectedActorTable = `${prefix}${(0, pluralize_1.plural)(name)}`; if (tableNames.includes(expectedActorTable) === false) props.errors.push({ path: props.path, expected: utils_1.StringUtil.trim `{ name: ${JSON.stringify(expectedActorTable)}; description: string; }`, value: undefined, description: utils_1.StringUtil.trim ` Missing required actor table "${expectedActorTable}". Fix: Add table "${expectedActorTable}", or rename the table that serves as the main "${actor.name}" actor entity. `, }); // Validation: session table must exist const expectedSessionTable = `${prefix}${name}_sessions`; if (tableNames.includes(expectedSessionTable) === false) props.errors.push({ path: props.path, expected: utils_1.StringUtil.trim `{ name: ${JSON.stringify(expectedSessionTable)}; description: string; }`, value: undefined, description: utils_1.StringUtil.trim ` Missing required session table "${expectedSessionTable}". Fix: Add table "${expectedSessionTable}" for authentication session management of "${actor.name}" actor. `, }); } }; })(AutoBeDatabaseAuthorizationProgrammer || (exports.AutoBeDatabaseAuthorizationProgrammer = AutoBeDatabaseAuthorizationProgrammer = {})); //# sourceMappingURL=AutoBeDatabaseAuthorizationProgrammer.js.map