Skip to content

Commit

Permalink
Merge pull request #627 from supabase/fix/typegen-function-variants-o…
Browse files Browse the repository at this point in the history
…rder

fix(typegen): sort polymorphic function variants
  • Loading branch information
soedirgo authored Nov 1, 2023
2 parents 709ad9e + 1745435 commit 994808b
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 8 deletions.
2 changes: 2 additions & 0 deletions src/server/templates/typescript.ts
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,8 @@ export interface Database {
})()})${is_set_returning_function ? '[]' : ''}
}`
)
// We only sorted by name on schemaFunctions - here we sort by arg names, arg types, and return type.
.sort()
.join('|')}`
)
})()}
Expand Down
3 changes: 3 additions & 0 deletions test/db/00-init.sql
Original file line number Diff line number Diff line change
Expand Up @@ -93,3 +93,6 @@ stable
as $$
select id, name from public.users;
$$;

create or replace function public.polymorphic_function(text) returns void language sql as '';
create or replace function public.polymorphic_function(bool) returns void language sql as '';
17 changes: 9 additions & 8 deletions test/server/column-privileges.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@ import { app } from './utils'

test('list column privileges', async () => {
const res = await app.inject({ method: 'GET', path: '/column-privileges' })
expect(
res
.json<PostgresColumnPrivileges[]>()
.find(
({ relation_schema, relation_name, column_name }) =>
relation_schema === 'public' && relation_name === 'todos' && column_name === 'id'
)
).toMatchInlineSnapshot(
const column = res
.json<PostgresColumnPrivileges[]>()
.find(
({ relation_schema, relation_name, column_name }) =>
relation_schema === 'public' && relation_name === 'todos' && column_name === 'id'
)!
// We don't guarantee order of privileges, but we want to keep the snapshots consistent.
column.privileges.sort((a, b) => JSON.stringify(a).localeCompare(JSON.stringify(b)))
expect(column).toMatchInlineSnapshot(
{ column_id: expect.stringMatching(/^\d+\.\d+$/) },
`
{
Expand Down
13 changes: 13 additions & 0 deletions test/server/typegen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,19 @@ test('typegen', async () => {
name: string
}[]
}
polymorphic_function:
| {
Args: {
"": boolean
}
Returns: undefined
}
| {
Args: {
"": string
}
Returns: undefined
}
postgres_fdw_disconnect: {
Args: {
"": string
Expand Down

0 comments on commit 994808b

Please sign in to comment.