@@ -13,12 +13,14 @@ export const apply = ({
1313 views,
1414 functions,
1515 types,
16+ arrayTypes,
1617} : {
1718 schemas : PostgresSchema [ ]
1819 tables : PostgresTable [ ]
1920 views : PostgresView [ ]
2021 functions : PostgresFunction [ ]
2122 types : PostgresType [ ]
23+ arrayTypes : PostgresType [ ]
2224} ) : string => {
2325 let output = `
2426export type Json = string | number | boolean | null | { [key: string]: Json } | Json[]
@@ -214,11 +216,20 @@ export interface Database {
214216 }
215217
216218 const argsNameAndType = inArgs . map ( ( { name, type_id } ) => {
217- const type = types . find ( ( { id } ) => id === type_id )
218- if ( ! type ) {
219- return { name, type : 'unknown' }
219+ let type = arrayTypes . find ( ( { id } ) => id === type_id )
220+ if ( type ) {
221+ // If it's an array type, the name looks like `_int8`.
222+ const elementTypeName = type . name . substring ( 1 )
223+ return {
224+ name,
225+ type : `(${ pgTypeToTsType ( elementTypeName , types , schemas ) } )[]` ,
226+ }
227+ }
228+ type = types . find ( ( { id } ) => id === type_id )
229+ if ( type ) {
230+ return { name, type : pgTypeToTsType ( type . name , types , schemas ) }
220231 }
221- return { name, type : pgTypeToTsType ( type . name , types , schemas ) }
232+ return { name, type : 'unknown' }
222233 } )
223234
224235 return `{ ${ argsNameAndType . map (
@@ -230,11 +241,20 @@ export interface Database {
230241
231242 if ( tableArgs . length > 0 ) {
232243 const argsNameAndType = tableArgs . map ( ( { name, type_id } ) => {
233- const type = types . find ( ( { id } ) => id === type_id )
234- if ( ! type ) {
235- return { name, type : 'unknown' }
244+ let type = arrayTypes . find ( ( { id } ) => id === type_id )
245+ if ( type ) {
246+ // If it's an array type, the name looks like `_int8`.
247+ const elementTypeName = type . name . substring ( 1 )
248+ return {
249+ name,
250+ type : `(${ pgTypeToTsType ( elementTypeName , types , schemas ) } )[]` ,
251+ }
236252 }
237- return { name, type : pgTypeToTsType ( type . name , types , schemas ) }
253+ type = types . find ( ( { id } ) => id === type_id )
254+ if ( type ) {
255+ return { name, type : pgTypeToTsType ( type . name , types , schemas ) }
256+ }
257+ return { name, type : 'unknown' }
238258 } )
239259
240260 return `{ ${ argsNameAndType . map (
0 commit comments