@@ -12,6 +12,7 @@ const { Swift } = require("../type-generation/languages/swift");
1212const { Java } = require ( "../type-generation/languages/java" ) ;
1313const { Dart } = require ( "../type-generation/languages/dart" ) ;
1414const { JavaScript } = require ( "../type-generation/languages/javascript" ) ;
15+ const { CSharp } = require ( "../type-generation/languages/csharp" ) ;
1516
1617/**
1718 * @param {string } language
@@ -33,6 +34,8 @@ function createLanguageMeta(language) {
3334 return new Java ( ) ;
3435 case "dart" :
3536 return new Dart ( ) ;
37+ case "cs" :
38+ return new CSharp ( ) ;
3639 default :
3740 throw new Error ( `Language '${ language } ' is not supported` ) ;
3841 }
@@ -55,7 +58,7 @@ const typesLanguageOption = new Option(
5558 "-l, --language <language>" ,
5659 "The language of the types"
5760)
58- . choices ( [ "auto" , "ts" , "js" , "php" , "kotlin" , "swift" , "java" , "dart" ] )
61+ . choices ( [ "auto" , "ts" , "js" , "php" , "kotlin" , "swift" , "java" , "dart" , "cs" ] )
5962 . default ( "auto" ) ;
6063
6164const typesStrictOption = new Option (
@@ -97,22 +100,58 @@ const typesCommand = actionRunner(async (rawOutputDirectory, {language, strict})
97100 fs . mkdirSync ( outputDirectory , { recursive : true } ) ;
98101 }
99102
100- const collections = localConfig . getCollections ( ) ;
101- if ( collections . length === 0 ) {
102- const configFileName = path . basename ( localConfig . path ) ;
103- throw new Error ( `No collections found in configuration. Make sure ${ configFileName } exists and contains collections.` ) ;
103+ // Try tables first, fallback to collections
104+ let tables = localConfig . getTables ( ) ;
105+ let collections = [ ] ;
106+ let dataSource = 'tables' ;
107+
108+ if ( tables . length === 0 ) {
109+ collections = localConfig . getCollections ( ) ;
110+ dataSource = 'collections' ;
111+
112+ if ( collections . length === 0 ) {
113+ const configFileName = path . basename ( localConfig . path ) ;
114+ throw new Error ( `No tables or collections found in configuration. Make sure ${ configFileName } exists and contains tables or collections.` ) ;
115+ }
116+ }
117+
118+ // Use tables if available, otherwise use collections
119+ let dataItems = tables . length > 0 ? tables : collections ;
120+ const itemType = tables . length > 0 ? 'tables' : 'collections' ;
121+
122+ // Normalize tables data: rename 'columns' to 'attributes' for template compatibility
123+ if ( tables . length > 0 ) {
124+ dataItems = dataItems . map ( table => {
125+ const { columns, ...rest } = table ;
126+ return {
127+ ...rest ,
128+ attributes : ( columns || [ ] ) . map ( column => {
129+ if ( column . relatedTable ) {
130+ const { relatedTable, ...columnRest } = column ;
131+ return {
132+ ...columnRest ,
133+ relatedCollection : relatedTable
134+ } ;
135+ }
136+ return column ;
137+ } )
138+ } ;
139+ } ) ;
104140 }
105141
106- log ( `Found ${ collections . length } collections: ${ collections . map ( c => c . name ) . join ( ", " ) } ` ) ;
142+ log ( `Found ${ dataItems . length } ${ itemType } : ${ dataItems . map ( c => c . name ) . join ( ", " ) } ` ) ;
143+
144+ // Use columns if available, otherwise use attributes
145+ const resourceType = tables . length > 0 ? 'columns' : 'attributes' ;
107146
108- const totalAttributes = collections . reduce ( ( count , collection ) => count + collection . attributes . length , 0 ) ;
109- log ( `Found ${ totalAttributes } attributes across all collections ` ) ;
147+ const totalAttributes = dataItems . reduce ( ( count , item ) => count + ( item . attributes || [ ] ) . length , 0 ) ;
148+ log ( `Found ${ totalAttributes } ${ resourceType } across all ${ itemType } ` ) ;
110149
111150 const templater = ejs . compile ( meta . getTemplate ( ) ) ;
112151
113152 if ( meta . isSingleFile ( ) ) {
114153 const content = templater ( {
115- collections,
154+ collections : dataItems ,
116155 strict,
117156 ...templateHelpers ,
118157 getType : meta . getType ,
@@ -123,23 +162,23 @@ const typesCommand = actionRunner(async (rawOutputDirectory, {language, strict})
123162 fs . writeFileSync ( destination , content ) ;
124163 log ( `Added types to ${ destination } ` ) ;
125164 } else {
126- for ( const collection of collections ) {
165+ for ( const item of dataItems ) {
127166 const content = templater ( {
128- collections,
129- collection,
167+ collections : dataItems ,
168+ collection : item ,
130169 strict,
131170 ...templateHelpers ,
132171 getType : meta . getType ,
133172 } ) ;
134173
135- const destination = path . join ( outputDirectory , meta . getFileName ( collection ) ) ;
174+ const destination = path . join ( outputDirectory , meta . getFileName ( item ) ) ;
136175
137176 fs . writeFileSync ( destination , content ) ;
138- log ( `Added types for ${ collection . name } to ${ destination } ` ) ;
177+ log ( `Added types for ${ item . name } to ${ destination } ` ) ;
139178 }
140179 }
141180
142- success ( `Generated types for all the listed collections ` ) ;
181+ success ( `Generated types for all the listed ${ itemType } ` ) ;
143182} ) ;
144183
145184const types = new Command ( "types" )
0 commit comments