Skip to content

Commit

Permalink
feat: typecheck table names in .from() (#528)
Browse files Browse the repository at this point in the history
  • Loading branch information
soedirgo authored Mar 28, 2024
1 parent e26266a commit 9dd41d9
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 1 deletion.
1 change: 0 additions & 1 deletion src/PostgrestClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ export default class PostgrestClient<
from<ViewName extends string & keyof Schema['Views'], View extends Schema['Views'][ViewName]>(
relation: ViewName
): PostgrestQueryBuilder<Schema, View, ViewName>
from(relation: string): PostgrestQueryBuilder<Schema, any, any>
/**
* Perform a query on a table or a view.
*
Expand Down
2 changes: 2 additions & 0 deletions test/basic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -629,6 +629,7 @@ test('throwOnError throws errors instead of returning them', async () => {
let isErrorCaught = false

try {
// @ts-expect-error: nonexistent table
await postgrest.from('missing_table').select().throwOnError()
} catch (error) {
expect(error).toMatchInlineSnapshot(
Expand All @@ -642,6 +643,7 @@ test('throwOnError throws errors instead of returning them', async () => {

test('throwOnError throws errors which include stack', async () => {
try {
// @ts-expect-error: nonexistent table
await postgrest.from('does_not_exist').select().throwOnError()
} catch (err) {
expect(err instanceof Error).toBe(true)
Expand Down
1 change: 1 addition & 0 deletions test/index.test-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ const postgrest = new PostgrestClient<Database>(REST_URL)
// table invalid type
{
expectError(postgrest.from(42))
expectError(postgrest.from('nonexistent_table'))
}

// `null` can't be used with `.eq()`
Expand Down

0 comments on commit 9dd41d9

Please sign in to comment.