Skip to content

Commit 60397be

Browse files
authored
fix(typegen): ensure determinism in functions returns properties (#970)
Fixes #959
1 parent a142d73 commit 60397be

File tree

1 file changed

+18
-16
lines changed

1 file changed

+18
-16
lines changed

src/server/templates/typescript.ts

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -361,9 +361,9 @@ export type Database = {
361361
})
362362
363363
return `{
364-
${argsNameAndType.map(
365-
({ name, type }) => `${JSON.stringify(name)}: ${type}`
366-
)}
364+
${argsNameAndType
365+
.toSorted((a, b) => a.name.localeCompare(b.name))
366+
.map(({ name, type }) => `${JSON.stringify(name)}: ${type}`)}
367367
}`
368368
}
369369
@@ -373,19 +373,21 @@ export type Database = {
373373
)
374374
if (relation) {
375375
return `{
376-
${columnsByTableId[relation.id].map(
377-
(column) =>
378-
`${JSON.stringify(column.name)}: ${pgTypeToTsType(
379-
schema,
380-
column.format,
381-
{
382-
types,
383-
schemas,
384-
tables,
385-
views,
386-
}
387-
)} ${column.is_nullable ? '| null' : ''}`
388-
)}
376+
${columnsByTableId[relation.id]
377+
.toSorted((a, b) => a.name.localeCompare(b.name))
378+
.map(
379+
(column) =>
380+
`${JSON.stringify(column.name)}: ${pgTypeToTsType(
381+
schema,
382+
column.format,
383+
{
384+
types,
385+
schemas,
386+
tables,
387+
views,
388+
}
389+
)} ${column.is_nullable ? '| null' : ''}`
390+
)}
389391
}`
390392
}
391393

0 commit comments

Comments
 (0)