Skip to content

Commit ac98447

Browse files
committed
chore: add arguments and returns sort
1 parent d20e386 commit ac98447

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

src/server/templates/typescript.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ export const apply = async ({
101101
}
102102
return { name, type: tsType }
103103
})
104-
.sort((a, b) => a.name.localeCompare(b.name))
104+
.toSorted((a, b) => a.name.localeCompare(b.name))
105105

106106
return `{
107107
${argsNameAndType.map(({ name, type }) => `${JSON.stringify(name)}: ${type}`)}
@@ -113,6 +113,7 @@ export const apply = async ({
113113
if (relation) {
114114
return `{
115115
${columnsByTableId[relation.id]
116+
.toSorted((a, b) => a.name.localeCompare(b.name))
116117
.map(
117118
(column) =>
118119
`${JSON.stringify(column.name)}: ${pgTypeToTsType(schema, column.format, {
@@ -571,7 +572,7 @@ export type Database = {
571572
}
572573
return { name, type: tsType, has_default }
573574
})
574-
argsType = `{ ${argsNameAndType.map(({ name, type, has_default }) => `${JSON.stringify(name)}${has_default ? '?' : ''}: ${type}`)} }`
575+
argsType = `{ ${argsNameAndType.toSorted((a, b) => a.name.localeCompare(b.name)).map(({ name, type, has_default }) => `${JSON.stringify(name)}${has_default ? '?' : ''}: ${type}`)} }`
575576
}
576577
returnType = `{ error: true } & ${JSON.stringify(conflictError)}`
577578
} else if (hasTableRowError(fn)) {
@@ -590,7 +591,7 @@ export type Database = {
590591
}
591592
return { name, type: tsType, has_default }
592593
})
593-
argsType = `{ ${argsNameAndType.map(({ name, type, has_default }) => `${JSON.stringify(name)}${has_default ? '?' : ''}: ${type}`)} }`
594+
argsType = `{ ${argsNameAndType.toSorted((a, b) => a.name.localeCompare(b.name)).map(({ name, type, has_default }) => `${JSON.stringify(name)}${has_default ? '?' : ''}: ${type}`)} }`
594595
}
595596
returnType = `{ error: true } & ${JSON.stringify(`the function ${schema.name}.${fn.name} with parameter or with a single unnamed json/jsonb parameter, but no matches were found in the schema cache`)}`
596597
} else if (inArgs.length > 0) {
@@ -607,7 +608,7 @@ export type Database = {
607608
}
608609
return { name, type: tsType, has_default }
609610
})
610-
argsType = `{ ${argsNameAndType.map(({ name, type, has_default }) => `${JSON.stringify(name)}${has_default ? '?' : ''}: ${type}`)} }`
611+
argsType = `{ ${argsNameAndType.toSorted((a, b) => a.name.localeCompare(b.name)).map(({ name, type, has_default }) => `${JSON.stringify(name)}${has_default ? '?' : ''}: ${type}`)} }`
611612
}
612613
613614
return `{ Args: ${argsType}; Returns: ${getFunctionTsReturnType(fn, returnType)} }`

0 commit comments

Comments
 (0)