1- import { Table as ClassicTable } from './Table' ;
2- import { RowType , TableV2 } from './TableV2' ;
1+ import { RowType , Table } from './Table' ;
32
4- type SchemaType = Record < string , TableV2 < any > > ;
3+ type SchemaType = Record < string , Table < any > > ;
54
65type SchemaTableType < S extends SchemaType > = {
76 [ K in keyof S ] : RowType < S [ K ] > ;
@@ -16,9 +15,9 @@ export class Schema<S extends SchemaType = SchemaType> {
1615 */
1716 readonly types : SchemaTableType < S > ;
1817 readonly props : S ;
19- readonly tables : ClassicTable [ ] ;
18+ readonly tables : Table [ ] ;
2019
21- constructor ( tables : ClassicTable [ ] | S ) {
20+ constructor ( tables : Table [ ] | S ) {
2221 if ( Array . isArray ( tables ) ) {
2322 this . tables = tables ;
2423 } else {
@@ -28,20 +27,29 @@ export class Schema<S extends SchemaType = SchemaType> {
2827 }
2928
3029 validate ( ) {
31- for ( const table of this . tables as ClassicTable [ ] ) {
30+ for ( const table of this . tables ) {
3231 table . validate ( ) ;
3332 }
3433 }
3534
3635 toJSON ( ) {
3736 return {
38- tables : ( this . tables as ClassicTable [ ] ) . map ( ( t ) => t . toJSON ( ) )
37+ // This is required because "name" field is not present in TableV2
38+ tables : this . tables . map ( ( t ) => t . toJSON ( ) )
3939 } ;
4040 }
4141
4242 private convertToClassicTables ( props : S ) {
4343 return Object . entries ( props ) . map ( ( [ name , table ] ) => {
44- return ClassicTable . createTable ( name , table ) ;
44+ const convertedTable = new Table ( {
45+ name,
46+ columns : table . columns ,
47+ indexes : table . indexes ,
48+ localOnly : table . localOnly ,
49+ insertOnly : table . insertOnly ,
50+ viewName : table . viewNameOverride || name
51+ } ) ;
52+ return convertedTable ;
4553 } ) ;
4654 }
4755}
0 commit comments