supabase / postgrest-js

Isomorphic JavaScript client for PostgREST.
https://supabase.com
MIT License
967 stars 130 forks source link

fix: rpc return type #394

Closed soedirgo closed 1 year ago

soedirgo commented 1 year ago

What kind of change does this PR introduce?

Fixes #387.

RPC return types aren't getting propagated properly. E.g. if a function returns boolean, the data will be typed as boolean[].

To fix this, we change PostgrestBuilder's type parameter to be the actual type of data, instead of the element type of data (which assumes data is always an array, which is incorrect).

In doing so we effectively remove all usage of PostgrestResponse and PostgrestMaybeSingleResponse. We can stop exporting these on the next major version.

This also fixes the behavior of .returns<NewResult>(), which was inconsistent with the documentation (i.e. data was typed as NewResult[] instead of NewResult).

github-actions[bot] commented 1 year ago

:tada: This PR is included in version 1.3.1 :tada:

The release is available on:

Your semantic-release bot :package::rocket:

natedunn commented 1 year ago

oof, i was wondering why all my types got borked overnight.

soedirgo commented 1 year ago

Sorry about that @natedunn - do you mind sharing how it's breaking your types? While we consider it a bug here we do want to make sure the fix isn't causing more issues at least.

natedunn commented 1 year ago

@soedirgo Yeah I can understand the mentality there, so no worries.

There's not much to describe in terms of my issues. The PR description laid it out pretty well, so I knew what I had to change:

This stopped working

  .returns<SomeDefinedType>()

And this fixed the issue

  .returns<SomeDefinedType[]>()
bombillazo commented 1 year ago

I created this issue: https://github.com/supabase/postgrest-js/issues/430

It is probably related to this.