Skip to content

Commit 994808b

Browse files
authored
Merge pull request #627 from supabase/fix/typegen-function-variants-order
fix(typegen): sort polymorphic function variants
2 parents 709ad9e + 1745435 commit 994808b

File tree

4 files changed

+27
-8
lines changed

4 files changed

+27
-8
lines changed

src/server/templates/typescript.ts

+2
Original file line numberDiff line numberDiff line change
@@ -357,6 +357,8 @@ export interface Database {
357357
})()})${is_set_returning_function ? '[]' : ''}
358358
}`
359359
)
360+
// We only sorted by name on schemaFunctions - here we sort by arg names, arg types, and return type.
361+
.sort()
360362
.join('|')}`
361363
)
362364
})()}

test/db/00-init.sql

+3
Original file line numberDiff line numberDiff line change
@@ -93,3 +93,6 @@ stable
9393
as $$
9494
select id, name from public.users;
9595
$$;
96+
97+
create or replace function public.polymorphic_function(text) returns void language sql as '';
98+
create or replace function public.polymorphic_function(bool) returns void language sql as '';

test/server/column-privileges.ts

+9-8
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,15 @@ import { app } from './utils'
33

44
test('list column privileges', async () => {
55
const res = await app.inject({ method: 'GET', path: '/column-privileges' })
6-
expect(
7-
res
8-
.json<PostgresColumnPrivileges[]>()
9-
.find(
10-
({ relation_schema, relation_name, column_name }) =>
11-
relation_schema === 'public' && relation_name === 'todos' && column_name === 'id'
12-
)
13-
).toMatchInlineSnapshot(
6+
const column = res
7+
.json<PostgresColumnPrivileges[]>()
8+
.find(
9+
({ relation_schema, relation_name, column_name }) =>
10+
relation_schema === 'public' && relation_name === 'todos' && column_name === 'id'
11+
)!
12+
// We don't guarantee order of privileges, but we want to keep the snapshots consistent.
13+
column.privileges.sort((a, b) => JSON.stringify(a).localeCompare(JSON.stringify(b)))
14+
expect(column).toMatchInlineSnapshot(
1415
{ column_id: expect.stringMatching(/^\d+\.\d+$/) },
1516
`
1617
{

test/server/typegen.ts

+13
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,19 @@ test('typegen', async () => {
240240
name: string
241241
}[]
242242
}
243+
polymorphic_function:
244+
| {
245+
Args: {
246+
"": boolean
247+
}
248+
Returns: undefined
249+
}
250+
| {
251+
Args: {
252+
"": string
253+
}
254+
Returns: undefined
255+
}
243256
postgres_fdw_disconnect: {
244257
Args: {
245258
"": string

0 commit comments

Comments
 (0)