@@ -45,7 +45,7 @@ export const apply = async ({
45
45
} ,
46
46
{ } as Record < number , ( typeof types ) [ number ] >
47
47
)
48
- const getTsReturnType = ( fn : PostgresFunction , returnType : string ) => {
48
+ const getFunctionTsReturnType = ( fn : PostgresFunction , returnType : string ) => {
49
49
return `${ returnType } ${ fn . is_set_returning_function && fn . returns_multiple_rows ? '[]' : '' }
50
50
${
51
51
fn . returns_set_of_table && fn . args . length === 1 && fn . args [ 0 ] . table_name
@@ -58,7 +58,7 @@ export const apply = async ({
58
58
} `
59
59
}
60
60
61
- const getReturnType = ( schema : PostgresSchema , fn : PostgresFunction ) : string => {
61
+ const getFunctionReturnType = ( schema : PostgresSchema , fn : PostgresFunction ) : string => {
62
62
// Case 1: `returns table`.
63
63
const tableArgs = fn . args . filter ( ( { mode } ) => mode === 'table' )
64
64
if ( tableArgs . length > 0 ) {
@@ -177,7 +177,8 @@ export type Database = {
177
177
...schemaFunctions
178
178
. filter ( ( fn ) => fn . argument_types === table . name )
179
179
. map (
180
- ( fn ) => `${ JSON . stringify ( fn . name ) } : ${ getReturnType ( schema , fn ) } | null`
180
+ ( fn ) =>
181
+ `${ JSON . stringify ( fn . name ) } : ${ getFunctionReturnType ( schema , fn ) } | null`
181
182
) ,
182
183
] }
183
184
}
@@ -512,7 +513,7 @@ export type Database = {
512
513
// No conflict - just add the no params signature
513
514
allSignatures . push ( `{
514
515
Args: Record<PropertyKey, never>
515
- Returns: ${ getTsReturnType ( noParamFn , getReturnType ( schema , noParamFn ) ) }
516
+ Returns: ${ getFunctionTsReturnType ( noParamFn , getFunctionReturnType ( schema , noParamFn ) ) }
516
517
}` )
517
518
}
518
519
}
@@ -539,7 +540,7 @@ export type Database = {
539
540
540
541
allSignatures . push ( `{
541
542
Args: { "": ${ tsType } }
542
- Returns: ${ getTsReturnType ( validUnnamedFn , getReturnType ( schema , validUnnamedFn ) ) }
543
+ Returns: ${ getFunctionTsReturnType ( validUnnamedFn , getFunctionReturnType ( schema , validUnnamedFn ) ) }
543
544
}` )
544
545
}
545
546
}
@@ -554,7 +555,7 @@ export type Database = {
554
555
if ( unnamedSetofFunctions . length > 0 ) {
555
556
const unnamedEmbededFunctionsSignatures = unnamedSetofFunctions . map (
556
557
( fn ) =>
557
- `{ IsUnnamedEmbededTable: true, Args: Record<PropertyKey, never>, Returns: ${ getTsReturnType ( fn , getReturnType ( schema , fn ) ) } }`
558
+ `{ IsUnnamedEmbededTable: true, Args: Record<PropertyKey, never>, Returns: ${ getFunctionTsReturnType ( fn , getFunctionReturnType ( schema , fn ) ) } }`
558
559
)
559
560
allSignatures . push ( ...unnamedEmbededFunctionsSignatures )
560
561
}
@@ -596,7 +597,7 @@ export type Database = {
596
597
}` )
597
598
} else if ( inArgs . length > 0 ) {
598
599
// Generate normal function signature
599
- const returnType = getReturnType ( schema , fn )
600
+ const returnType = getFunctionReturnType ( schema , fn )
600
601
allSignatures . push ( `{
601
602
Args: ${ `{ ${ inArgs
602
603
. map ( ( { name, type_id, has_default } ) => {
@@ -614,7 +615,7 @@ export type Database = {
614
615
} )
615
616
. sort ( )
616
617
. join ( ', ' ) } }`}
617
- Returns: ${ getTsReturnType ( fn , returnType ) }
618
+ Returns: ${ getFunctionTsReturnType ( fn , returnType ) }
618
619
}` )
619
620
}
620
621
} )
@@ -627,7 +628,7 @@ export type Database = {
627
628
// Remove duplicates, sort, and join with |
628
629
return `${ JSON . stringify ( fnName ) } : ${ signatures . join ( '\n | ' ) } `
629
630
} else {
630
- return `${ JSON . stringify ( fnName ) } : ${ fns . map ( ( fn ) => `{ Args: unknown , Returns: ${ getTsReturnType ( fn , getReturnType ( schema , fn ) ) } }` ) . join ( '\n |' ) } `
631
+ return `${ JSON . stringify ( fnName ) } : ${ fns . map ( ( fn ) => `{ Args: {} , Returns: ${ getFunctionTsReturnType ( fn , getFunctionReturnType ( schema , fn ) ) } }` ) . join ( '\n |' ) } `
631
632
}
632
633
} )
633
634
} ) ( ) }
0 commit comments