From f10d0912032aeb993158b01627c50516c9b00309 Mon Sep 17 00:00:00 2001 From: avallete Date: Wed, 9 Apr 2025 19:25:25 +0200 Subject: [PATCH] fix(typegen): use javascript deterministic sort for args join --- src/server/templates/typescript.ts | 1 + test/server/typegen.ts | 12 ++++++------ 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/src/server/templates/typescript.ts b/src/server/templates/typescript.ts index 6d2efde8..460887b5 100644 --- a/src/server/templates/typescript.ts +++ b/src/server/templates/typescript.ts @@ -296,6 +296,7 @@ export type Database = { }) return `{ ${argsNameAndType.map(({ name, type, has_default }) => `${JSON.stringify(name)}${has_default ? '?' : ''}: ${type}`)} }` }) + .toSorted() // A function can have multiples definitions with differents args, but will always return the same type .join(' | ')} Returns: ${(() => { diff --git a/test/server/typegen.ts b/test/server/typegen.ts index f62631e0..c0851ef1 100644 --- a/test/server/typegen.ts +++ b/test/server/typegen.ts @@ -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 @@ -452,7 +452,7 @@ test('typegen: typescript', async () => { }[] } polymorphic_function: { - Args: { "": string } | { "": boolean } + Args: { "": boolean } | { "": string } Returns: undefined } postgres_fdw_disconnect: { @@ -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 @@ -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: { @@ -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 @@ -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: {