export class NameMapper {
    #tables = new Map();
    constructor(tables) {
        this.#tables = tables;
    }
    #getTable(src, ctx) {
        const table = this.#tables.get(src);
        if (!table) {
            throw new Error(`unknown table "${src}" ${!ctx ? '' : `in ${JSON.stringify(ctx)}`}`);
        }
        return table;
    }
    tableName(src, context) {
        return this.#getTable(src, context).tableName;
    }
    columnName(table, src, ctx) {
        const dst = this.#getTable(table, ctx).columns[src];
        if (!dst) {
            throw new Error(`unknown column "${src}" of "${table}" table ${!ctx ? '' : `in ${JSON.stringify(ctx)}`}`);
        }
        return dst;
    }
    row(table, row) {
        const dest = this.#getTable(table);
        const { allColumnsSame, columns } = dest;
        if (allColumnsSame) {
            return row;
        }
        const clientRow = {};
        for (const col in row) {
            // Note: columns with unknown names simply pass through.
            clientRow[columns[col] ?? col] = row[col];
        }
        return clientRow;
    }
    columns(table, cols) {
        const dest = this.#getTable(table);
        const { allColumnsSame, columns } = dest;
        // Note: Columns not defined in the schema simply pass through.
        return cols === undefined || allColumnsSame
            ? cols
            : cols.map(col => columns[col] ?? col);
    }
}
//# sourceMappingURL=name-mapper.js.map