Skip to content

Commit

Permalink
Merge pull request #1330 from supabase/rc
Browse files Browse the repository at this point in the history
feat: reland query parser changes
  • Loading branch information
soedirgo authored Dec 16, 2024
2 parents 322129c + d76c7b3 commit faa4f77
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 8 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ First of all, you need to install the library:
npm install @supabase/supabase-js
```


Then you're able to import the library and establish the connection with the database:

```js
Expand Down
9 changes: 5 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
"@supabase/auth-js": "2.67.1",
"@supabase/functions-js": "2.4.3",
"@supabase/node-fetch": "2.6.15",
"@supabase/postgrest-js": "1.16.3",
"@supabase/postgrest-js": "1.17.7",
"@supabase/realtime-js": "2.11.2",
"@supabase/storage-js": "2.7.1"
},
Expand Down
4 changes: 3 additions & 1 deletion src/SupabaseClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,9 @@ export default class SupabaseClient<
? Fn['Returns'][number]
: never
: never,
Fn['Returns']
Fn['Returns'],
FnName,
null
> {
return this.rest.rpc(fn, args, options)
}
Expand Down
10 changes: 10 additions & 0 deletions src/lib/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,16 +80,26 @@ export type SupabaseClientOptions<SchemaName> = {
accessToken?: () => Promise<string>
}

export type GenericRelationship = {
foreignKeyName: string
columns: string[]
isOneToOne?: boolean
referencedRelation: string
referencedColumns: string[]
}

export type GenericTable = {
Row: Record<string, unknown>
Insert: Record<string, unknown>
Update: Record<string, unknown>
Relationships: GenericRelationship[]
}

export type GenericUpdatableView = GenericTable

export type GenericNonUpdatableView = {
Row: Record<string, unknown>
Relationships: GenericRelationship[]
}

export type GenericView = GenericUpdatableView | GenericNonUpdatableView
Expand Down
7 changes: 5 additions & 2 deletions test/index.test-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ const supabase = createClient<Database>(URL, KEY)
if (error) {
throw new Error(error.message)
}
expectType<Database['public']['Tables']['users']['Row'] | null>(message.user)
expectType<Database['public']['Tables']['users']['Row']>(message.user)
}

// one-to-many relationship
Expand All @@ -99,8 +99,11 @@ const supabase = createClient<Database>(URL, KEY)
// referencing missing column
{
type SelectQueryError<Message extends string> = { error: true } & Message

const res = await supabase.from('users').select('username, dat')
expectType<PostgrestSingleResponse<SelectQueryError<`Referencing missing column \`dat\``>[]>>(res)
expectType<
PostgrestSingleResponse<SelectQueryError<"column 'dat' does not exist on 'users'.">[]>
>(res)
}

// one-to-one relationship
Expand Down

0 comments on commit faa4f77

Please sign in to comment.