@@ -145,17 +145,28 @@ export interface Database {
145145 }
146146 }
147147 Functions: {
148- ${
149- schemaFunctions . length === 0
150- ? '[_ in never]: never'
151- : schemaFunctions . map (
152- ( func ) => `${ JSON . stringify ( func . name ) } : {
148+ ${ ( ( ) => {
149+ if ( schemaFunctions . length === 0 ) {
150+ return '[_ in never]: never'
151+ }
152+
153+ const schemaFunctionsGroupedByName = schemaFunctions . reduce ( ( acc , curr ) => {
154+ acc [ curr . name ] ??= [ ]
155+ acc [ curr . name ] . push ( curr )
156+ return acc
157+ } , { } as Record < string , PostgresFunction [ ] > )
158+
159+ return Object . entries ( schemaFunctionsGroupedByName ) . map (
160+ ( [ fnName , fns ] ) =>
161+ `${ JSON . stringify ( fnName ) } : ${ fns
162+ . map (
163+ ( fn ) => `{
153164 Args: ${ ( ( ) => {
154- if ( func . argument_types === '' ) {
165+ if ( fn . argument_types === '' ) {
155166 return 'Record<PropertyKey, never>'
156167 }
157168
158- const splitArgs = func . argument_types . split ( ',' ) . map ( ( arg ) => arg . trim ( ) )
169+ const splitArgs = fn . argument_types . split ( ',' ) . map ( ( arg ) => arg . trim ( ) )
159170 if ( splitArgs . some ( ( arg ) => arg . includes ( '"' ) || ! arg . includes ( ' ' ) ) ) {
160171 return 'Record<string, unknown>'
161172 }
@@ -173,10 +184,12 @@ export interface Database {
173184 ( { name, type } ) => `${ JSON . stringify ( name ) } : ${ type } `
174185 ) } }`
175186 } ) ( ) }
176- Returns: ${ pgTypeToTsType ( func . return_type , types ) }
187+ Returns: ${ pgTypeToTsType ( fn . return_type , types ) }
177188 }`
178- )
179- }
189+ )
190+ . join ( '|' ) } `
191+ )
192+ } ) ( ) }
180193 }
181194 }`
182195 } ) }
0 commit comments