-
-
Notifications
You must be signed in to change notification settings - Fork 170
feat(types): add embeded functions type inference #632
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?
Conversation
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.
This one was made by locally buidling: supabase/postgres-meta#971
And running it for introspection.
Then canary tested by passing this as a locally built dependency to supabase-js
and using it on our codebase with success.
I think this might introduce some breaking changes though and we might need to make a new major for it. As it happened in the past it's really easy for types changes to break users code, best would be to start with some canary testings and gather feedbacks.
I'm thinking something like:
- Have the new introspection released.
- Ensure that it doesn't break the current type inference (it revert the function introspections to an union of args+returns so this might cause some issues)
- Ensure the current
postgrest-js
latest version is fully released (see: supabase/supabase-js#1491 and supabase/ssr#119 ) - Allow users to opt-in to the new version and make sure there is no big issues.
- Release to the general channel.
{ | ||
const result = await postgrest.rpc('get_status') | ||
if (result.error) { | ||
throw new Error(result.error.message) | ||
} | ||
expectType<'ONLINE' | 'OFFLINE'>(result.data) | ||
} | ||
|
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.
comment
Moved in favor of runtime & type tests: https://github.com/supabase/postgrest-js/pull/632/files#diff-1496003b365eab7067c12b679d21e8db1289c1b1da1a7b36399894d21e0c5ef3R211-R249
import { Database as OriginalDatabase } from './types.generated' | ||
export type Json = unknown | ||
|
||
export type Database = { | ||
export type Database = OriginalDatabase & { |
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.
comment
Reduce the override to the minimum by leveraging the type union.
Views: {} | ||
Enums: {} | ||
CompositeTypes: {} |
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.
issue
For some reason, not declaring those with empty values now fail the merge with the utils types down the line 🤔
export type GenericFunction = { | ||
Args: Record<string, unknown> | ||
Args: Record<string, unknown> | never |
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.
comment
The generated function now use the never
as argument which allows to distinguish between "no params at all" and "param with empty name".
That should still be retro-compatible since Record<PropertyKey, never>
should be considered as Record<string, unknown>
.
b7344cf
to
d8b677f
Compare
What kind of change does this PR introduce?
Additional context
Closes: CLIBS-249