import _ from "lodash"; /** * Resolve a table's effective definition. Tables with `parentTableName` * take their structure from the parent. Always returns a copy: the schema * objects are never mutated. */ export default function resolveTable({ table, db_schema, }) { if (!table.parentTableName) { return _.cloneDeep(table); } const parent_table = db_schema.tables.find((t) => t.tableName === table.parentTableName); if (!parent_table) { throw new Error(`Parent table \`${table.parentTableName}\` not found for \`${table.tableName}\``); } return _.merge(_.cloneDeep(parent_table), { tableName: table.tableName, tableDescription: table.tableDescription, }); }