import { CdcColumn, CdcTable, } from '@dadosfera/protospack-v2/dist/lib/Input/interfaces/entities'; /** What a caller knows about a CDC table before it is stored. The source * table is named `table_name` on the platform-facing bodies and `name` on * the create DTO (CdcTableReq); either works — deriving one from the other * happens only here. */ export interface CdcTableInput { // Optional on the create DTO (CdcTableReq); the platform validates it. table_schema?: string; table_name?: string; name?: string; primary_keys?: string[]; iceberg_table_name?: string; iceberg_qualify_table_name?: string; columns?: CdcColumn[]; column_exclude_list?: string[]; } /** * The only place maestro builds a protospack `CdcTable`. * * `name` is the identity key shared with batch `NewTable` (in-factory keys * update/soft-delete on it) and the proto keeps it required, so it mirrors * `table_name` here and nowhere else. Follow-up (protospack): make `name` * optional and let in-factory be its sole writer (it already backfills * `name ?? table_name`). */ export function toCdcTable(table: CdcTableInput): CdcTable { const tableName = table.table_name ?? table.name; return { table_schema: table.table_schema, table_name: tableName, name: tableName, primary_keys: table.primary_keys ?? [], iceberg_table_name: table.iceberg_table_name, iceberg_qualify_table_name: table.iceberg_qualify_table_name, columns: table.columns ?? [], column_exclude_list: table.column_exclude_list ?? [], }; }