| 787 | } |
| 788 | |
| 789 | function resolveTableColumns<columns extends TableColumnsDefinition>( |
| 790 | tableName: string, |
| 791 | columns: columns, |
| 792 | ): { [column in keyof columns & string]: ColumnDefinition } { |
| 793 | let columnDefinitions: Record<string, ColumnDefinition> = {} |
| 794 | |
| 795 | for (let columnName in columns) { |
| 796 | if (!Object.prototype.hasOwnProperty.call(columns, columnName)) { |
| 797 | continue |
| 798 | } |
| 799 | |
| 800 | let column = columns[columnName] |
| 801 | |
| 802 | if (!(column instanceof ColumnBuilder)) { |
| 803 | throw new Error( |
| 804 | 'Invalid column "' + |
| 805 | columnName + |
| 806 | '" for table "' + |
| 807 | tableName + |
| 808 | '". Expected a column(...) builder', |
| 809 | ) |
| 810 | } |
| 811 | |
| 812 | columnDefinitions[columnName] = column.build() |
| 813 | } |
| 814 | |
| 815 | return Object.freeze(columnDefinitions) as { |
| 816 | [column in keyof columns & string]: ColumnDefinition |
| 817 | } |
| 818 | } |
| 819 | |
| 820 | /** |
| 821 | * Defines a one-to-many relation from `source` to `target`. |