-
-
Notifications
You must be signed in to change notification settings - Fork 181
fix: function type generation for zero arg and scalar computed fields #1035
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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]>() | ||
| 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) { | ||
|
|
@@ -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
+201
to
+203
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this should already be covered by: https://github.com/supabase/postgres-meta/pull/1035/changes#diff-c903ec71df16a8ae5f665c19c21b273f74c2f8eb02f5e8a3552ebe69d18be18fR196-R198 🤔 |
||
| ) { | ||
| introspectionBySchema[func.schema].functions.push({ fn: func, inArgs }) | ||
| } | ||
|
|
@@ -410,7 +413,7 @@ export const apply = async ({ | |
| ) => { | ||
| return fns | ||
| .map(({ fn, inArgs }) => { | ||
| let argsType = 'never' | ||
| let argsType = 'Record<PropertyKey, never>' | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
| let returnType = getFunctionReturnType(schema, fn) | ||
|
|
||
| // Check for specific error cases | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.