From f500c4327177f2a911863e365fe356f277b968e8 Mon Sep 17 00:00:00 2001 From: avallete Date: Mon, 4 Aug 2025 10:26:26 +0200 Subject: [PATCH] fix(typegen): ensure determinism in functions returns properties Fixes #959 --- src/server/templates/typescript.ts | 34 ++++++++++++++++-------------- 1 file changed, 18 insertions(+), 16 deletions(-) diff --git a/src/server/templates/typescript.ts b/src/server/templates/typescript.ts index c3cae645..4f9cac03 100644 --- a/src/server/templates/typescript.ts +++ b/src/server/templates/typescript.ts @@ -361,9 +361,9 @@ export type Database = { }) return `{ - ${argsNameAndType.map( - ({ name, type }) => `${JSON.stringify(name)}: ${type}` - )} + ${argsNameAndType + .toSorted((a, b) => a.name.localeCompare(b.name)) + .map(({ name, type }) => `${JSON.stringify(name)}: ${type}`)} }` } @@ -373,19 +373,21 @@ export type Database = { ) if (relation) { return `{ - ${columnsByTableId[relation.id].map( - (column) => - `${JSON.stringify(column.name)}: ${pgTypeToTsType( - schema, - column.format, - { - types, - schemas, - tables, - views, - } - )} ${column.is_nullable ? '| null' : ''}` - )} + ${columnsByTableId[relation.id] + .toSorted((a, b) => a.name.localeCompare(b.name)) + .map( + (column) => + `${JSON.stringify(column.name)}: ${pgTypeToTsType( + schema, + column.format, + { + types, + schemas, + tables, + views, + } + )} ${column.is_nullable ? '| null' : ''}` + )} }` }