Skip to content

Commit 55e6b0d

Browse files
committed
chore: fix more tests
1 parent f371351 commit 55e6b0d

File tree

6 files changed

+97
-10
lines changed

6 files changed

+97
-10
lines changed

src/types.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,9 @@ export type GetRpcFunctionFilterBuilderByArgs<
2424
> = {
2525
0: Schema['Functions'][FnName]
2626
// If the Args is exactly never (function call without any params)
27-
1: IsNever<Args> extends true
27+
1: IsAny<Schema> extends true
28+
? any
29+
: IsNever<Args> extends true
2830
? ExtractExactFunction<Schema['Functions'][FnName], Args>
2931
: // Otherwise, we attempt to match with one of the function definition in the union based
3032
// on the function arguments provided

test/index.test-d.ts

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -194,15 +194,6 @@ const postgrest = new PostgrestClient<Database>(REST_URL)
194194
expectType<string>(result.data.baz)
195195
}
196196

197-
// rpc return type
198-
{
199-
const result = await postgrest.rpc('get_status')
200-
if (result.error) {
201-
throw new Error(result.error.message)
202-
}
203-
expectType<'ONLINE' | 'OFFLINE'>(result.data)
204-
}
205-
206197
// PostgrestBuilder's children retains class when using inherited methods
207198
{
208199
const x = postgrest.from('channels').select()

test/returns.test-d.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,9 @@ const postgrest = new PostgrestClient<Database>(REST_URL)
5353
.returns<{ username: string }[]>()
5454
expectType<
5555
PostgrestBuilder<
56+
{
57+
PostgrestVersion: '12'
58+
},
5659
{
5760
Error: 'Type mismatch: Cannot cast single object to array type. Remove Array wrapper from return type or make sure you are not using .single() up in the calling chain'
5861
},

test/rpc.test.ts

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,3 +207,43 @@ test('RPC call with field aggregate', async () => {
207207
expectType<TypeEqual<typeof result, typeof expected>>(true)
208208
ExpectedSchema.parse(res.data)
209209
})
210+
211+
test('RPC get_status with no params', async () => {
212+
const res = await postgrest.rpc('get_status')
213+
expect(res).toMatchInlineSnapshot(`
214+
Object {
215+
"count": null,
216+
"data": null,
217+
"error": Object {
218+
"code": "PGRST202",
219+
"details": "Searched for the function public.get_status without parameters or with a single unnamed json/jsonb parameter, but no matches were found in the schema cache.",
220+
"hint": null,
221+
"message": "Could not find the function public.get_status without parameters in the schema cache",
222+
},
223+
"status": 404,
224+
"statusText": "Not Found",
225+
}
226+
`)
227+
let result: Exclude<typeof res.data, null>
228+
// get_status without name param doesn't exist in the schema so we expect never
229+
let expected: never
230+
expectType<TypeEqual<typeof result, typeof expected>>(true)
231+
})
232+
233+
test('RPC get_status with name params', async () => {
234+
const res = await postgrest.rpc('get_status', { name_param: 'supabot' })
235+
expect(res).toMatchInlineSnapshot(`
236+
Object {
237+
"count": null,
238+
"data": "ONLINE",
239+
"error": null,
240+
"status": 200,
241+
"statusText": "OK",
242+
}
243+
`)
244+
let result: Exclude<typeof res.data, null>
245+
const ExpectedSchema = z.enum(['ONLINE', 'OFFLINE'] as const)
246+
let expected: z.infer<typeof ExpectedSchema>
247+
expectType<TypeEqual<typeof result, typeof expected>>(true)
248+
ExpectedSchema.parse(res.data)
249+
})

test/types.generated.ts

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,46 @@
11
export type Json = unknown
22

33
export type Database = {
4+
personal: {
5+
Tables: {
6+
users: {
7+
Row: {
8+
age_range: unknown | null
9+
data: Json | null
10+
status: Database['personal']['Enums']['user_status'] | null
11+
username: string
12+
}
13+
Insert: {
14+
age_range?: unknown | null
15+
data?: Json | null
16+
status?: Database['personal']['Enums']['user_status'] | null
17+
username: string
18+
}
19+
Update: {
20+
age_range?: unknown | null
21+
data?: Json | null
22+
status?: Database['personal']['Enums']['user_status'] | null
23+
username?: string
24+
}
25+
Relationships: []
26+
}
27+
}
28+
Views: {
29+
[_ in never]: never
30+
}
31+
Functions: {
32+
get_status: {
33+
Args: { name_param: string }
34+
Returns: Database['personal']['Enums']['user_status']
35+
}
36+
}
37+
Enums: {
38+
user_status: 'ONLINE' | 'OFFLINE'
39+
}
40+
CompositeTypes: {
41+
[_ in never]: never
42+
}
43+
}
444
public: {
545
Tables: {
646
best_friends: {
@@ -1067,6 +1107,11 @@ export type CompositeTypes<
10671107
: never
10681108

10691109
export const Constants = {
1110+
personal: {
1111+
Enums: {
1112+
user_status: ['ONLINE', 'OFFLINE'],
1113+
},
1114+
},
10701115
public: {
10711116
Enums: {
10721117
user_status: ['ONLINE', 'OFFLINE'],

test/types.override-with-options-postgrest13.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ export type Database = MergeDeep<
2828
}
2929
}
3030
}
31+
Views: {}
32+
Enums: {}
33+
CompositeTypes: {}
3134
}
3235
public: {
3336
Tables: {
@@ -43,6 +46,9 @@ export type Database = MergeDeep<
4346
}
4447
}
4548
}
49+
Views: {}
50+
Enums: {}
51+
CompositeTypes: {}
4652
}
4753
}
4854
>

0 commit comments

Comments
 (0)