Skip to content

fix(typegen): use javascript deterministic sort for args join #930

New issue

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

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

Already on GitHub? # to your account

Merged
merged 1 commit into from
Apr 10, 2025
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
1 change: 1 addition & 0 deletions src/server/templates/typescript.ts
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,7 @@ export type Database = {
})
return `{ ${argsNameAndType.map(({ name, type, has_default }) => `${JSON.stringify(name)}${has_default ? '?' : ''}: ${type}`)} }`
})
.toSorted()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TIL .toSorted() 🔥

// A function can have multiples definitions with differents args, but will always return the same type
.join(' | ')}
Returns: ${(() => {
Expand Down
12 changes: 6 additions & 6 deletions test/server/typegen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -434,8 +434,8 @@ test('typegen: typescript', async () => {
}
get_todos_setof_rows: {
Args:
| { user_row: Database["public"]["Tables"]["users"]["Row"] }
| { todo_row: Database["public"]["Tables"]["todos"]["Row"] }
| { user_row: Database["public"]["Tables"]["users"]["Row"] }
Returns: {
details: string | null
id: number
Expand All @@ -452,7 +452,7 @@ test('typegen: typescript', async () => {
}[]
}
polymorphic_function: {
Args: { "": string } | { "": boolean }
Args: { "": boolean } | { "": string }
Returns: undefined
}
postgres_fdw_disconnect: {
Expand Down Expand Up @@ -1067,8 +1067,8 @@ test('typegen w/ one-to-one relationships', async () => {
}
get_todos_setof_rows: {
Args:
| { user_row: Database["public"]["Tables"]["users"]["Row"] }
| { todo_row: Database["public"]["Tables"]["todos"]["Row"] }
| { user_row: Database["public"]["Tables"]["users"]["Row"] }
Returns: {
details: string | null
id: number
Expand All @@ -1085,7 +1085,7 @@ test('typegen w/ one-to-one relationships', async () => {
}[]
}
polymorphic_function: {
Args: { "": string } | { "": boolean }
Args: { "": boolean } | { "": string }
Returns: undefined
}
postgres_fdw_disconnect: {
Expand Down Expand Up @@ -1700,8 +1700,8 @@ test('typegen: typescript w/ one-to-one relationships', async () => {
}
get_todos_setof_rows: {
Args:
| { user_row: Database["public"]["Tables"]["users"]["Row"] }
| { todo_row: Database["public"]["Tables"]["todos"]["Row"] }
| { user_row: Database["public"]["Tables"]["users"]["Row"] }
Returns: {
details: string | null
id: number
Expand All @@ -1718,7 +1718,7 @@ test('typegen: typescript w/ one-to-one relationships', async () => {
}[]
}
polymorphic_function: {
Args: { "": string } | { "": boolean }
Args: { "": boolean } | { "": string }
Returns: undefined
}
postgres_fdw_disconnect: {
Expand Down