@@ -276,15 +276,23 @@ export type Database = {
276
276
: schemaViews . map (
277
277
( view ) => `${ JSON . stringify ( view . name ) } : {
278
278
Row: {
279
- ${ columnsByTableId [ view . id ] . map (
280
- ( column ) =>
281
- `${ JSON . stringify ( column . name ) } : ${ pgTypeToTsType ( schema , column . format , {
282
- types,
283
- schemas,
284
- tables,
285
- views,
286
- } ) } ${ column . is_nullable ? '| null' : '' } `
287
- ) }
279
+ ${ [
280
+ ...columnsByTableId [ view . id ] . map (
281
+ ( column ) =>
282
+ `${ JSON . stringify ( column . name ) } : ${ pgTypeToTsType ( schema , column . format , {
283
+ types,
284
+ schemas,
285
+ tables,
286
+ views,
287
+ } ) } ${ column . is_nullable ? '| null' : '' } `
288
+ ) ,
289
+ ...schemaFunctions
290
+ . filter ( ( fn ) => fn . argument_types === view . name )
291
+ . map (
292
+ ( fn ) =>
293
+ `${ JSON . stringify ( fn . name ) } : ${ getFunctionReturnType ( schema , fn ) } | null`
294
+ ) ,
295
+ ] }
288
296
}
289
297
${
290
298
'is_updatable' in view && view . is_updatable
@@ -409,8 +417,11 @@ export type Database = {
409
417
} ,
410
418
{ } as Record < string , PostgresFunction [ ] >
411
419
)
420
+ const sortedGroupdSchemaFunctions = Object . entries (
421
+ schemaFunctionsGroupedByName
422
+ ) . toSorted ( ( a , b ) => a [ 0 ] . localeCompare ( b [ 0 ] ) )
412
423
413
- return Object . entries ( schemaFunctionsGroupedByName ) . map ( ( [ fnName , fns ] ) => {
424
+ return sortedGroupdSchemaFunctions . map ( ( [ fnName , fns ] ) => {
414
425
// Group functions by their argument names signature to detect conflicts
415
426
const fnsByArgNames = new Map < string , PostgresFunction [ ] > ( )
416
427
fns . sort ( ( fn1 , fn2 ) => fn1 . id - fn2 . id )
@@ -553,10 +564,18 @@ export type Database = {
553
564
return inArgs . length === 1 && inArgs [ 0 ] . name === '' && fn . return_table_name
554
565
} )
555
566
if ( unnamedSetofFunctions . length > 0 ) {
556
- const unnamedEmbededFunctionsSignatures = unnamedSetofFunctions . map (
557
- ( fn ) =>
558
- `{ IsUnnamedEmbededTable: true, Args: Record<PropertyKey, never>, Returns: ${ getFunctionTsReturnType ( fn , getFunctionReturnType ( schema , fn ) ) } }`
559
- )
567
+ const unnamedEmbededFunctionsSignatures = unnamedSetofFunctions . map ( ( fn ) => {
568
+ const firstArgType = typesById [ fn . args [ 0 ] . type_id ]
569
+ const tsType = firstArgType
570
+ ? pgTypeToTsType ( schema , firstArgType . name , {
571
+ types,
572
+ schemas,
573
+ tables,
574
+ views,
575
+ } )
576
+ : 'Record<PropertyKey, never>'
577
+ return `{ Args: ${ tsType } , Returns: ${ getFunctionTsReturnType ( fn , getFunctionReturnType ( schema , fn ) ) } }`
578
+ } )
560
579
allSignatures . push ( ...unnamedEmbededFunctionsSignatures )
561
580
}
562
581
0 commit comments