@@ -45,7 +45,7 @@ export const apply = async ({
4545 } ,
4646 { } as Record < number , ( typeof types ) [ number ] >
4747 )
48- const getTsReturnType = ( fn : PostgresFunction , returnType : string ) => {
48+ const getFunctionTsReturnType = ( fn : PostgresFunction , returnType : string ) => {
4949 return `${ returnType } ${ fn . is_set_returning_function && fn . returns_multiple_rows ? '[]' : '' }
5050 ${
5151 fn . returns_set_of_table && fn . args . length === 1 && fn . args [ 0 ] . table_name
@@ -58,7 +58,7 @@ export const apply = async ({
5858 } `
5959 }
6060
61- const getReturnType = ( schema : PostgresSchema , fn : PostgresFunction ) : string => {
61+ const getFunctionReturnType = ( schema : PostgresSchema , fn : PostgresFunction ) : string => {
6262 // Case 1: `returns table`.
6363 const tableArgs = fn . args . filter ( ( { mode } ) => mode === 'table' )
6464 if ( tableArgs . length > 0 ) {
@@ -177,7 +177,8 @@ export type Database = {
177177 ...schemaFunctions
178178 . filter ( ( fn ) => fn . argument_types === table . name )
179179 . map (
180- ( fn ) => `${ JSON . stringify ( fn . name ) } : ${ getReturnType ( schema , fn ) } | null`
180+ ( fn ) =>
181+ `${ JSON . stringify ( fn . name ) } : ${ getFunctionReturnType ( schema , fn ) } | null`
181182 ) ,
182183 ] }
183184 }
@@ -512,7 +513,7 @@ export type Database = {
512513 // No conflict - just add the no params signature
513514 allSignatures . push ( `{
514515 Args: Record<PropertyKey, never>
515- Returns: ${ getTsReturnType ( noParamFn , getReturnType ( schema , noParamFn ) ) }
516+ Returns: ${ getFunctionTsReturnType ( noParamFn , getFunctionReturnType ( schema , noParamFn ) ) }
516517 }` )
517518 }
518519 }
@@ -539,7 +540,7 @@ export type Database = {
539540
540541 allSignatures . push ( `{
541542 Args: { "": ${ tsType } }
542- Returns: ${ getTsReturnType ( validUnnamedFn , getReturnType ( schema , validUnnamedFn ) ) }
543+ Returns: ${ getFunctionTsReturnType ( validUnnamedFn , getFunctionReturnType ( schema , validUnnamedFn ) ) }
543544 }` )
544545 }
545546 }
@@ -554,7 +555,7 @@ export type Database = {
554555 if ( unnamedSetofFunctions . length > 0 ) {
555556 const unnamedEmbededFunctionsSignatures = unnamedSetofFunctions . map (
556557 ( 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 ) ) } }`
558559 )
559560 allSignatures . push ( ...unnamedEmbededFunctionsSignatures )
560561 }
@@ -596,7 +597,7 @@ export type Database = {
596597 }` )
597598 } else if ( inArgs . length > 0 ) {
598599 // Generate normal function signature
599- const returnType = getReturnType ( schema , fn )
600+ const returnType = getFunctionReturnType ( schema , fn )
600601 allSignatures . push ( `{
601602 Args: ${ `{ ${ inArgs
602603 . map ( ( { name, type_id, has_default } ) => {
@@ -614,7 +615,7 @@ export type Database = {
614615 } )
615616 . sort ( )
616617 . join ( ', ' ) } }`}
617- Returns: ${ getTsReturnType ( fn , returnType ) }
618+ Returns: ${ getFunctionTsReturnType ( fn , returnType ) }
618619 }` )
619620 }
620621 } )
@@ -627,7 +628,7 @@ export type Database = {
627628 // Remove duplicates, sort, and join with |
628629 return `${ JSON . stringify ( fnName ) } : ${ signatures . join ( '\n | ' ) } `
629630 } 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 |' ) } `
631632 }
632633 } )
633634 } ) ( ) }
0 commit comments