@@ -145,17 +145,28 @@ export interface Database {
145
145
}
146
146
}
147
147
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 ) => `{
153
164
Args: ${ ( ( ) => {
154
- if ( func . argument_types === '' ) {
165
+ if ( fn . argument_types === '' ) {
155
166
return 'Record<PropertyKey, never>'
156
167
}
157
168
158
- const splitArgs = func . argument_types . split ( ',' ) . map ( ( arg ) => arg . trim ( ) )
169
+ const splitArgs = fn . argument_types . split ( ',' ) . map ( ( arg ) => arg . trim ( ) )
159
170
if ( splitArgs . some ( ( arg ) => arg . includes ( '"' ) || ! arg . includes ( ' ' ) ) ) {
160
171
return 'Record<string, unknown>'
161
172
}
@@ -173,10 +184,12 @@ export interface Database {
173
184
( { name, type } ) => `${ JSON . stringify ( name ) } : ${ type } `
174
185
) } }`
175
186
} ) ( ) }
176
- Returns: ${ pgTypeToTsType ( func . return_type , types ) }
187
+ Returns: ${ pgTypeToTsType ( fn . return_type , types ) }
177
188
}`
178
- )
179
- }
189
+ )
190
+ . join ( '|' ) } `
191
+ )
192
+ } ) ( ) }
180
193
}
181
194
}`
182
195
} ) }
0 commit comments