Skip to content

Commit 0a55d33

Browse files
authored
Merge pull request #930 from supabase/fix/typescrypt-gen-args-sorting
fix(typegen): use javascript deterministic sort for args join
2 parents d64602f + f10d091 commit 0a55d33

File tree

2 files changed

+7
-6
lines changed

2 files changed

+7
-6
lines changed

Diff for: src/server/templates/typescript.ts

+1
Original file line numberDiff line numberDiff line change
@@ -296,6 +296,7 @@ export type Database = {
296296
})
297297
return `{ ${argsNameAndType.map(({ name, type, has_default }) => `${JSON.stringify(name)}${has_default ? '?' : ''}: ${type}`)} }`
298298
})
299+
.toSorted()
299300
// A function can have multiples definitions with differents args, but will always return the same type
300301
.join(' | ')}
301302
Returns: ${(() => {

Diff for: test/server/typegen.ts

+6-6
Original file line numberDiff line numberDiff line change
@@ -434,8 +434,8 @@ test('typegen: typescript', async () => {
434434
}
435435
get_todos_setof_rows: {
436436
Args:
437-
| { user_row: Database["public"]["Tables"]["users"]["Row"] }
438437
| { todo_row: Database["public"]["Tables"]["todos"]["Row"] }
438+
| { user_row: Database["public"]["Tables"]["users"]["Row"] }
439439
Returns: {
440440
details: string | null
441441
id: number
@@ -452,7 +452,7 @@ test('typegen: typescript', async () => {
452452
}[]
453453
}
454454
polymorphic_function: {
455-
Args: { "": string } | { "": boolean }
455+
Args: { "": boolean } | { "": string }
456456
Returns: undefined
457457
}
458458
postgres_fdw_disconnect: {
@@ -1067,8 +1067,8 @@ test('typegen w/ one-to-one relationships', async () => {
10671067
}
10681068
get_todos_setof_rows: {
10691069
Args:
1070-
| { user_row: Database["public"]["Tables"]["users"]["Row"] }
10711070
| { todo_row: Database["public"]["Tables"]["todos"]["Row"] }
1071+
| { user_row: Database["public"]["Tables"]["users"]["Row"] }
10721072
Returns: {
10731073
details: string | null
10741074
id: number
@@ -1085,7 +1085,7 @@ test('typegen w/ one-to-one relationships', async () => {
10851085
}[]
10861086
}
10871087
polymorphic_function: {
1088-
Args: { "": string } | { "": boolean }
1088+
Args: { "": boolean } | { "": string }
10891089
Returns: undefined
10901090
}
10911091
postgres_fdw_disconnect: {
@@ -1700,8 +1700,8 @@ test('typegen: typescript w/ one-to-one relationships', async () => {
17001700
}
17011701
get_todos_setof_rows: {
17021702
Args:
1703-
| { user_row: Database["public"]["Tables"]["users"]["Row"] }
17041703
| { todo_row: Database["public"]["Tables"]["todos"]["Row"] }
1704+
| { user_row: Database["public"]["Tables"]["users"]["Row"] }
17051705
Returns: {
17061706
details: string | null
17071707
id: number
@@ -1718,7 +1718,7 @@ test('typegen: typescript w/ one-to-one relationships', async () => {
17181718
}[]
17191719
}
17201720
polymorphic_function: {
1721-
Args: { "": string } | { "": boolean }
1721+
Args: { "": boolean } | { "": string }
17221722
Returns: undefined
17231723
}
17241724
postgres_fdw_disconnect: {

0 commit comments

Comments
 (0)