Skip to content
This repository was archived by the owner on Oct 9, 2025. It is now read-only.

Conversation

@uncvrd
Copy link
Contributor

@uncvrd uncvrd commented Oct 12, 2024

What kind of change does this PR introduce?

Hi all! This PR simply re-exports a couple helper types that many of us were using to strongly type our query responses

Please let me know if I can help improve this!

What is the current behavior?

Ever since 1.15.6, these types had been removed, they were internal but recent discussion is that these should be re-exposed

It used to be

import { GenericSchema, GenericTable } from "@supabase/postgrest-js/dist/module/types";
import { GetResult } from "@supabase/postgrest-js/dist/module/select-query-parser";

Please link any relevant issues here.

See #551

What is the new behavior?

It is now:

import { GetResult, GenericSchema, GenericTable } from "@supabase/postgrest-js";

In order to do something like the following:

type Collection = SelectPublic<"Collection", "id,imageObjectId,type,name,workspaceId">

We can build a helper type like this:

export type SchemaKeyType = keyof DB;
export type DatabaseTableKeyType = keyof DB["public"]["Tables"];
type RawSelect<
    SchemaName extends SchemaKeyType,
    TableName extends DatabaseTableKeyType,
    Query extends string = "*",
    Schema extends GenericSchema = DB[SchemaName],
    Table extends GenericTable = Schema["Tables"][TableName],
    Relationships = Table extends { Relationships: infer R } ? R : unknown
> = GetResult<Schema, Table["Row"], TableName, Relationships, Query>;

export type SelectPublic<Table extends DatabaseTableKeyType, Query extends string = "*"> = RawSelect<"public", Table, Query>;

In order to do this we need access to: GetResult, GenericSchema, and GenericTable

So I've simply exported those from their respective files.

Now we get our get our types back :~)

image

@alexgorbatchev
Copy link

alexgorbatchev commented Oct 14, 2024

@olee @soedirgo please merge this

as a side note, this is used by supabase-cache-helpers which has a full video on the Supabase YouTube channel

@olee
Copy link

olee commented Nov 5, 2024

@alexgorbatchev afaik the GetResult type should still be considered internal and there was no intention to export it. (see this comment).
Instead, a proper helper type should be exported publicly, like eg. this:

// Exported from postgrest-js
export type TablesSelect<
    Schema extends GenericSchema,
    TableName extends ???,
    Query extends string = '*'
> = ...;

// usage:
type MyEntitySelected = TablesSelect<Database['public'], 'my_table', 'id,title'>;

However, as the current state of the library causes quite some issues with various users and even libraries depending on the exported GetResult I'd suggest exporting it with an unstable prefix eg. Unstable_GetResult<...>.
What do you think @soedirgo?

@soedirgo soedirgo linked an issue Dec 4, 2024 that may be closed by this pull request
@soedirgo
Copy link
Member

soedirgo commented Dec 4, 2024

Hey all, thanks for the wait. I couldn't come up with a stable helper type in time so I've added an unstable helper type as per @olee's suggestion.

I've omitted GenericTable and GenericSchema since these are also internal types and easily reimplemented - here's an example.

@soedirgo soedirgo merged commit c511128 into supabase:master Dec 4, 2024
1 check passed
@github-actions
Copy link

github-actions bot commented Dec 4, 2024

🎉 This PR is included in version 1.17.7 🎉

The release is available on:

Your semantic-release bot 📦🚀

@uncvrd
Copy link
Contributor Author

uncvrd commented Feb 14, 2025

@soedirgo thanks a lot for updating this, I just upgraded : ) fwiw for anyone else reading here, make sure to check the master branch of the example linked above as the Generic types have changed (I got stuck on this)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Unable to import helper types since 1.15.6

4 participants