@@ -17,7 +17,6 @@ import {
17
17
import { apply as applyTypescriptTemplate } from './templates/typescript.js'
18
18
import { apply as applyGoTemplate } from './templates/go.js'
19
19
import { apply as applySwiftTemplate } from './templates/swift.js'
20
- import { getGeneratorMetadata } from '../lib/generators.js'
21
20
22
21
const logger = pino ( {
23
22
formatters : {
@@ -32,48 +31,6 @@ const app = buildApp({ logger })
32
31
const adminApp = buildAdminApp ( { logger } )
33
32
34
33
async function getTypeOutput ( ) : Promise < string | null > {
35
- const pgMeta : PostgresMeta = new PostgresMeta ( {
36
- ...DEFAULT_POOL_CONFIG ,
37
- connectionString : PG_CONNECTION ,
38
- } )
39
- const { data : generatorMetadata , error : generatorMetadataError } = await getGeneratorMetadata (
40
- pgMeta ,
41
- {
42
- includedSchemas : GENERATE_TYPES_INCLUDED_SCHEMAS ,
43
- }
44
- )
45
- if ( generatorMetadataError ) {
46
- throw new Error ( generatorMetadataError . message )
47
- }
48
-
49
- let output : string | null = null
50
- switch ( GENERATE_TYPES ) {
51
- case 'typescript' :
52
- output = await applyTypescriptTemplate ( {
53
- ...generatorMetadata ,
54
- detectOneToOneRelationships : GENERATE_TYPES_DETECT_ONE_TO_ONE_RELATIONSHIPS ,
55
- } )
56
- break
57
- case 'swift' :
58
- output = await applySwiftTemplate ( {
59
- ...generatorMetadata ,
60
- accessControl : GENERATE_TYPES_SWIFT_ACCESS_CONTROL ,
61
- } )
62
- case 'go' :
63
- output = applyGoTemplate ( generatorMetadata )
64
- break
65
- }
66
-
67
- return output
68
- }
69
-
70
- if ( EXPORT_DOCS ) {
71
- // TODO: Move to a separate script.
72
- await app . ready ( )
73
- // @ts -ignore: app.swagger() is a Fastify decorator, so doesn't show up in the types
74
- console . log ( JSON . stringify ( app . swagger ( ) , null , 2 ) )
75
- } else if ( GENERATE_TYPES === 'typescript' ) {
76
- // TODO: Move to a separate script.
77
34
const pgMeta : PostgresMeta = new PostgresMeta ( {
78
35
...DEFAULT_POOL_CONFIG ,
79
36
connectionString : PG_CONNECTION ,
@@ -154,26 +111,47 @@ if (EXPORT_DOCS) {
154
111
throw new Error ( typesError . message )
155
112
}
156
113
157
- console . log (
158
- await applyTypescriptTemplate ( {
159
- schemas : schemas ! . filter (
160
- ( { name } ) =>
161
- GENERATE_TYPES_INCLUDED_SCHEMAS . length === 0 ||
162
- GENERATE_TYPES_INCLUDED_SCHEMAS . includes ( name )
163
- ) ,
164
- tables : tables ! ,
165
- foreignTables : foreignTables ! ,
166
- views : views ! ,
167
- materializedViews : materializedViews ! ,
168
- columns : columns ! ,
169
- relationships : relationships ! ,
170
- functions : functions ! . filter (
171
- ( { return_type } ) => ! [ 'trigger' , 'event_trigger' ] . includes ( return_type )
172
- ) ,
173
- types : types ! ,
174
- detectOneToOneRelationships : GENERATE_TYPES_DETECT_ONE_TO_ONE_RELATIONSHIPS ,
175
- } )
176
- )
114
+ const config = {
115
+ schemas : schemas ! . filter (
116
+ ( { name } ) =>
117
+ GENERATE_TYPES_INCLUDED_SCHEMAS . length === 0 ||
118
+ GENERATE_TYPES_INCLUDED_SCHEMAS . includes ( name )
119
+ ) ,
120
+ tables : tables ! ,
121
+ foreignTables : foreignTables ! ,
122
+ views : views ! ,
123
+ materializedViews : materializedViews ! ,
124
+ columns : columns ! ,
125
+ relationships : relationships ! ,
126
+ functions : functions ! . filter (
127
+ ( { return_type } ) => ! [ 'trigger' , 'event_trigger' ] . includes ( return_type )
128
+ ) ,
129
+ types : types ! ,
130
+ detectOneToOneRelationships : GENERATE_TYPES_DETECT_ONE_TO_ONE_RELATIONSHIPS ,
131
+ }
132
+
133
+ switch ( GENERATE_TYPES ?. toLowerCase ( ) ) {
134
+ case 'typescript' :
135
+ return await applyTypescriptTemplate ( config )
136
+ case 'swift' :
137
+ return await applySwiftTemplate ( {
138
+ ...config ,
139
+ accessControl : GENERATE_TYPES_SWIFT_ACCESS_CONTROL ,
140
+ } )
141
+ case 'go' :
142
+ return applyGoTemplate ( config )
143
+ default :
144
+ throw new Error ( `Unsupported language for GENERATE_TYPES: ${ GENERATE_TYPES } ` )
145
+ }
146
+ }
147
+
148
+ if ( EXPORT_DOCS ) {
149
+ // TODO: Move to a separate script.
150
+ await app . ready ( )
151
+ // @ts -ignore: app.swagger() is a Fastify decorator, so doesn't show up in the types
152
+ console . log ( JSON . stringify ( app . swagger ( ) , null , 2 ) )
153
+ } else if ( GENERATE_TYPES ) {
154
+ console . log ( await getTypeOutput ( ) )
177
155
} else {
178
156
const closeListeners = closeWithGrace ( async ( { err } ) => {
179
157
if ( err ) {
0 commit comments