Skip to content

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

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

avallete
Copy link
Member

@avallete avallete commented Aug 6, 2025

What kind of change does this PR introduce?

  • Introduce typing inferences for embeded functions returning setof and returns tables.

Additional context

Closes: CLIBS-249

@avallete avallete changed the title Feat/add embeded functions type inference feat(types): add embeded functions type inference Aug 6, 2025
Copy link
Member Author

@avallete avallete left a 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:

  1. Have the new introspection released.
  2. 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)
  3. Ensure the current postgrest-js latest version is fully released (see: supabase/supabase-js#1491 and supabase/ssr#119 )
  4. Allow users to opt-in to the new version and make sure there is no big issues.
  5. Release to the general channel.

Comment on lines -200 to -207
{
const result = await postgrest.rpc('get_status')
if (result.error) {
throw new Error(result.error.message)
}
expectType<'ONLINE' | 'OFFLINE'>(result.data)
}

Copy link
Member Author

Choose a reason for hiding this comment

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

Comment on lines +1 to +4
import { Database as OriginalDatabase } from './types.generated'
export type Json = unknown

export type Database = {
export type Database = OriginalDatabase & {
Copy link
Member Author

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.

Comment on lines +35 to +37
Views: {}
Enums: {}
CompositeTypes: {}
Copy link
Member Author

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
Copy link
Member Author

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>.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants