Skip to content

Commit 6d90bab

Browse files
committed
fix: allow arbitrary string on .from()
1 parent 61e69a4 commit 6d90bab

File tree

3 files changed

+9
-26
lines changed

3 files changed

+9
-26
lines changed

src/PostgrestClient.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,11 @@ export default class PostgrestClient<
6464
from<
6565
TableName extends string & keyof Schema['Tables'],
6666
Table extends Schema['Tables'][TableName]
67-
>(table: TableName): PostgrestQueryBuilder<Table> {
67+
>(table: TableName): PostgrestQueryBuilder<Table>
68+
from(table: string): PostgrestQueryBuilder<any>
69+
from(table: string): PostgrestQueryBuilder<any> {
6870
const url = new URL(`${this.url}/${table}`)
69-
return new PostgrestQueryBuilder<Table>(url, {
71+
return new PostgrestQueryBuilder<any>(url, {
7072
headers: { ...this.headers },
7173
schema: this.schema,
7274
fetch: this.fetch,

test/__snapshots__/index.test.ts.snap

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1044,21 +1044,6 @@ Object {
10441044
}
10451045
`;
10461046

1047-
exports[`missing table 1`] = `
1048-
Object {
1049-
"count": undefined,
1050-
"data": undefined,
1051-
"error": Object {
1052-
"code": "42P01",
1053-
"details": null,
1054-
"hint": null,
1055-
"message": "relation \\"public.missing_table\\" does not exist",
1056-
},
1057-
"status": 404,
1058-
"statusText": "Not Found",
1059-
}
1060-
`;
1061-
10621047
exports[`on_conflict insert 1`] = `
10631048
Object {
10641049
"count": undefined,

test/basic.ts

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -153,17 +153,15 @@ describe('basic insert, update, delete', () => {
153153
})
154154
})
155155

156-
test('missing table', async () => {
157-
// @ts-expect-error missing table
158-
const res = await postgrest.from('missing_table').select()
159-
expect(res).toMatchSnapshot()
156+
test('table invalid type', async () => {
157+
// @ts-expect-error table invalid type
158+
postgrest.from(42)
160159
})
161160

162161
test('throwOnError throws errors instead of returning them', async () => {
163162
let isErrorCaught = false
164163

165164
try {
166-
// @ts-expect-error missing table
167165
await postgrest.from('missing_table').select().throwOnError()
168166
} catch (error) {
169167
expect(error).toMatchSnapshot()
@@ -217,8 +215,7 @@ test('connection error w/o throwing', async () => {
217215
const postgrest = new PostgrestClient<Database>('http://foo.invalid')
218216
let isErrorCaught = false
219217
await postgrest
220-
// @ts-expect-error
221-
.from('user')
218+
.from('users')
222219
.select()
223220
.then(undefined, () => {
224221
isErrorCaught = true
@@ -230,8 +227,7 @@ test('connection error w/ throwOnError', async () => {
230227
const postgrest = new PostgrestClient<Database>('http://foo.invalid')
231228
let isErrorCaught = false
232229
await postgrest
233-
// @ts-expect-error
234-
.from('user')
230+
.from('users')
235231
.select()
236232
.throwOnError()
237233
.then(undefined, () => {

0 commit comments

Comments
 (0)