Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(typegen): sort polymorphic function variants #627

Merged
merged 2 commits into from
Nov 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading