Skip to content
Open
Changes from 2 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
9 changes: 6 additions & 3 deletions src/server/templates/typescript.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,13 +63,14 @@ export const apply = async ({
const columnsByTableId: Record<number, PostgresColumn[]> = {}
const tablesNamesByTableId: Record<number, string> = {}
const relationTypeByIds = new Map<number, (typeof types)[number]>()
// group types by id for quicker lookup
const typesById = new Map<number, (typeof types)[number]>()
Comment thread
7ttp marked this conversation as resolved.
const tablesLike = [...tables, ...foreignTables, ...views, ...materializedViews]
const tableAndViewNames = new Set<string>()

for (const tableLike of tablesLike) {
columnsByTableId[tableLike.id] = []
tablesNamesByTableId[tableLike.id] = tableLike.name
tableAndViewNames.add(tableLike.name)
}
for (const column of columns) {
if (column.table_id in columnsByTableId) {
Expand Down Expand Up @@ -197,7 +198,9 @@ export const apply = async ({
getTableNameFromRelationId(func.return_type_relation_id, func.return_type_id)) ||
// OR if the function takes a table row but doesn't qualify as embedded (for error reporting)
(relationTypeByIds.get(inArgs[0].type_id) &&
!getTableNameFromRelationId(func.return_type_relation_id, func.return_type_id))))
!getTableNameFromRelationId(func.return_type_relation_id, func.return_type_id)) ||
// OR if the function takes a table/view row (computed field)
tableAndViewNames.has(func.argument_types)))
Comment on lines +202 to +204
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

) {
introspectionBySchema[func.schema].functions.push({ fn: func, inArgs })
}
Expand Down Expand Up @@ -410,7 +413,7 @@ export const apply = async ({
) => {
return fns
.map(({ fn, inArgs }) => {
let argsType = 'never'
let argsType = 'Record<PropertyKey, never>'
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This needs to be tested with the inference within https://github.com/supabase/supabase-js/tree/master/packages/core/postgrest-js as I expect this might break a few things.

I remember having to use never specifically here to be able to detect the difference between actual functions with args, and functions with no args. Using a Record<string, never> in my memory didn't allowed that.

let returnType = getFunctionReturnType(schema, fn)

// Check for specific error cases
Expand Down
Loading