|
1 | 1 | import { TypeEqual } from 'ts-expect'
|
2 |
| -import { expectError, expectType } from 'tsd' |
| 2 | +import { expectType } from 'tsd' |
3 | 3 | import { PostgrestClient, PostgrestError } from '../src/index'
|
4 | 4 | import { Prettify } from '../src/types'
|
5 | 5 | import { Json } from '../src/select-query-parser/types'
|
6 | 6 | import { Database } from './types.override'
|
| 7 | +import { Database as DatabaseWithOptions } from './types.override-with-options-postgrest13' |
7 | 8 |
|
8 | 9 | const REST_URL = 'http://localhost:3000'
|
9 | 10 | const postgrest = new PostgrestClient<Database>(REST_URL)
|
| 11 | +const postgrestWithOptions = new PostgrestClient<DatabaseWithOptions>(REST_URL) |
10 | 12 |
|
11 | 13 | // table invalid type
|
12 | 14 | {
|
13 |
| - expectError(postgrest.from(42)) |
14 |
| - expectError(postgrest.from('nonexistent_table')) |
| 15 | + // @ts-expect-error should be error |
| 16 | + postgrest.from(42) |
| 17 | + // @ts-expect-error should be error |
| 18 | + postgrest.from('nonexistent_table') |
15 | 19 | }
|
16 | 20 |
|
17 | 21 | // `null` can't be used with `.eq()`
|
18 | 22 | {
|
19 | 23 | postgrest.from('users').select().eq('username', 'foo')
|
20 |
| - expectError(postgrest.from('users').select().eq('username', null)) |
| 24 | + // @ts-expect-error should be error |
| 25 | + postgrest.from('users').select().eq('username', null) |
21 | 26 |
|
22 | 27 | const nullableVar = 'foo' as string | null
|
23 |
| - expectError(postgrest.from('users').select().eq('username', nullableVar)) |
| 28 | + // @ts-expect-error should be error |
| 29 | + postgrest.from('users').select().eq('username', nullableVar) |
24 | 30 | }
|
25 | 31 |
|
26 | 32 | // `.eq()`, '.neq()' and `.in()` validate provided filter value when column is an enum.
|
27 | 33 | // Behaves the same for simple columns, as well as relationship filters.
|
28 | 34 | {
|
29 |
| - expectError(postgrest.from('users').select().eq('status', 'invalid')) |
30 |
| - expectError(postgrest.from('users').select().neq('status', 'invalid')) |
31 |
| - expectError(postgrest.from('users').select().in('status', ['invalid'])) |
| 35 | + // @ts-expect-error should be error |
| 36 | + postgrest.from('users').select().eq('status', 'invalid') |
| 37 | + // @ts-expect-error should be error |
| 38 | + postgrest.from('users').select().neq('status', 'invalid') |
| 39 | + // @ts-expect-error should be error |
| 40 | + postgrest.from('users').select().in('status', ['invalid']) |
| 41 | + |
| 42 | + // @ts-expect-error should be error |
| 43 | + postgrest.from('best_friends').select('users!first_user(status)').eq('users.status', 'invalid') |
| 44 | + // @ts-expect-error should be error |
| 45 | + postgrest.from('best_friends').select('users!first_user(status)').neq('users.status', 'invalid') |
| 46 | + postgrest |
| 47 | + .from('best_friends') |
| 48 | + .select('users!first_user(status)') |
| 49 | + // @ts-expect-error should be error |
| 50 | + .in('users.status', ['invalid']) |
32 | 51 |
|
33 |
| - expectError( |
34 |
| - postgrest.from('best_friends').select('users!first_user(status)').eq('users.status', 'invalid') |
35 |
| - ) |
36 |
| - expectError( |
37 |
| - postgrest.from('best_friends').select('users!first_user(status)').neq('users.status', 'invalid') |
38 |
| - ) |
39 |
| - expectError( |
40 |
| - postgrest |
41 |
| - .from('best_friends') |
42 |
| - .select('users!first_user(status)') |
43 |
| - .in('users.status', ['invalid']) |
44 |
| - ) |
45 | 52 | // Validate deeply nested embedded tables
|
46 |
| - expectError( |
47 |
| - postgrest.from('users').select('messages(channels(*))').eq('messages.channels.id', 'invalid') |
48 |
| - ) |
49 |
| - expectError( |
50 |
| - postgrest.from('users').select('messages(channels(*))').neq('messages.channels.id', 'invalid') |
51 |
| - ) |
52 |
| - expectError( |
53 |
| - postgrest.from('users').select('messages(channels(*))').in('messages.channels.id', ['invalid']) |
54 |
| - ) |
| 53 | + // @ts-expect-error should be error |
| 54 | + postgrest.from('users').select('messages(channels(*))').eq('messages.channels.id', 'invalid') |
| 55 | + // @ts-expect-error should be error |
| 56 | + postgrest.from('users').select('messages(channels(*))').neq('messages.channels.id', 'invalid') |
| 57 | + // @ts-expect-error should be error |
| 58 | + postgrest.from('users').select('messages(channels(*))').in('messages.channels.id', ['invalid']) |
55 | 59 |
|
56 | 60 | {
|
57 | 61 | const result = await postgrest.from('users').select('status').eq('status', 'ONLINE')
|
@@ -145,12 +149,14 @@ const postgrest = new PostgrestClient<Database>(REST_URL)
|
145 | 149 |
|
146 | 150 | // cannot update non-updatable views
|
147 | 151 | {
|
148 |
| - expectError(postgrest.from('updatable_view').update({ non_updatable_column: 0 })) |
| 152 | + // @ts-expect-error should be error |
| 153 | + postgrest.from('updatable_view').update({ non_updatable_column: 0 }) |
149 | 154 | }
|
150 | 155 |
|
151 | 156 | // cannot update non-updatable columns
|
152 | 157 | {
|
153 |
| - expectError(postgrest.from('updatable_view').update({ non_updatable_column: 0 })) |
| 158 | + // @ts-expect-error should be error |
| 159 | + postgrest.from('updatable_view').update({ non_updatable_column: 0 }) |
154 | 160 | }
|
155 | 161 |
|
156 | 162 | // spread resource with single column in select query
|
@@ -286,6 +292,14 @@ const postgrest = new PostgrestClient<Database>(REST_URL)
|
286 | 292 | }[]
|
287 | 293 | >(result.data)
|
288 | 294 | }
|
| 295 | + |
| 296 | +// Check that client options __InternalSupabase isn't considered like the other schemas |
| 297 | +{ |
| 298 | + await postgrestWithOptions |
| 299 | + // @ts-expect-error supabase internal shouldn't be available as one of the selectable schema |
| 300 | + .schema('__InternalSupabase') |
| 301 | +} |
| 302 | + |
289 | 303 | // Json string Accessor with custom types overrides
|
290 | 304 | {
|
291 | 305 | const result = await postgrest
|
|
0 commit comments