Skip to content

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

Copy link

🚀 Preview release created!

supabase-js CI tests have been automatically triggered on feature branch to verify compatibility.

Preview package: https://pkg.pr.new/@supabase/postgrest-js@d8b677f

Results will be posted here once testing is complete.

@clientlibs-test-trigger
Copy link

clientlibs-test-trigger bot commented Aug 25, 2025

❌ supabase-js CI Test Results

Overall Status: FAILED
Tests triggered by preview release of postgrest-js

Test Suite Result
Type Check ❌ FAILED
Unit Tests ❌ FAILED
Integration Tests ❌ FAILED
Preview Package: https://pkg.pr.new/@supabase/postgrest-js@d8b677f
Commit: d8b677f94b571578f021577824c5d9b6d84d6501
⚠️ Some tests failed. Please review the failing tests before merging.
View workflow run View full test results

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

Successfully merging this pull request may close these issues.

3 participants