supabase / postgrest-js

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

Unable to import helper types since 1.15.6 #551

Open olee opened 1 month ago

olee commented 1 month ago

Bug report

Describe the bug

Before 1.15.6 it was possible to import helper types from @supabase/postgrest-js to perform type mappings etc. like this:

import type { GetResult } from "@supabase/postgrest-js/dist/module/select-query-parser";

export type TablesSelect<
    Schema extends GenericSchema,
    TableName extends keyof Schema['Tables'],
    Query extends string,
> = GetResult<
    Schema,
    Schema['Tables'][TableName]['Row'],
    TableName,
    Schema['Tables'][TableName] extends { Relationships: infer R } ? R : never,
    Query
>;

However, starting from version 1.15.6 with the change to the package build (package.json etc), it became impossible to import any files from subdirectories of the build because of the exports configuration.

Expected behavior

All types of the library which are publicly exposed as part of generics, function arguments and whatsoever should be properly exported imho so that it is possible to properly type code depending on postgrest-js.

The easiest solution would probably be to export helper types through some namespace from index.ts.

soedirgo commented 1 month ago

Hi! These helper types have always been internal and subject to breaking changes - they're not part of the API. Can you share your use case and why you need them?

olee commented 2 weeks ago

The use case is exactly as described above: To generate types for table selects.

For example to write a component that accepts some data which has been selected somewhere else:

function MyUser(props: { entity: TablesSelect<'users', 'id,first_name,last_name,avatar'> }) {
  return (
    <div>...render user here...</div>
  );
}

// ... at some other location
await supabaseClient.from('users').select('id,first_name,last_name,avatar')....;

This is extremly useful and currently prevents us from upgrading supabase client as this is not possible anymore now. It also makes sense, as the other helper types (Tables, TablesInsert, TablesUpdate) are available, but no type is exported to get a subset of a table. Instead of exposing the internal type like GetResult, I would like even more for a TablesSelect type to be exported for everyone to use as part of the public API because it is extremely useful.

tobico commented 1 week ago

I'm also using GetResult extensively as the data fetched from my queries is passed around various places in my frontend and I want to correctly type all components and functions that process it.