Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
89 changes: 32 additions & 57 deletions packages/core/postgrest-js/test/advanced_rpc.test.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { PostgrestClient } from '../src/index'
import { Database } from './types.override'
import { TypeEqual, expectType } from './types'
import { SelectQueryError } from '../src/select-query-parser/utils'
import type { RequiredDeep } from 'type-fest'
import { z } from 'zod'
import { RequiredDeep } from 'type-fest'
import { PostgrestClient } from '../src/index'
import type { SelectQueryError } from '../src/select-query-parser/utils'
import { expectType, type TypeEqual } from './types'
import type { Database } from './types.override'

const REST_URL = 'http://localhost:3000'
const postgrest = new PostgrestClient<Database>(REST_URL)
Expand Down Expand Up @@ -442,8 +442,7 @@ describe('advanced rpc', () => {
.select('channel_id, message, users(username, catchphrase)')
let result: Exclude<typeof res.data, null>
let expected: RequiredDeep<z.infer<typeof SelectWithUsersSchema>>[]
// TODO: works with latest postgrest-meta type introspection
// expectType<TypeEqual<typeof result, typeof expected>>(true)
expectType<TypeEqual<typeof result, typeof expected>>(true)
expect(res).toMatchInlineSnapshot(`
Object {
"count": null,
Expand Down Expand Up @@ -503,8 +502,7 @@ describe('advanced rpc', () => {
.select('id, username, users(username, catchphrase)')
let result: Exclude<typeof res.data, null>
let expected: RequiredDeep<z.infer<typeof SelectWithUsersProfileSchema>>
// TODO: works with latest postgrest-meta type introspection
// expectType<TypeEqual<typeof result, typeof expected>>(true)
expectType<TypeEqual<typeof result, typeof expected>>(true)
expect(res).toMatchInlineSnapshot(`
Object {
"count": null,
Expand Down Expand Up @@ -547,8 +545,7 @@ describe('advanced rpc', () => {
let result: Exclude<typeof res.data, null>
// Should be an error response due to ambiguous function resolution
let expected: SelectQueryError<'Could not choose the best candidate function between: public.postgrest_unresolvable_function(a => int4), public.postgrest_unresolvable_function(a => text). Try renaming the parameters or the function itself in the database so function overloading can be resolved'>
// TODO: works with latest postgrest-meta type introspection
// expectType<TypeEqual<typeof result, typeof expected>>(true)
expectType<TypeEqual<typeof result, typeof expected>>(true)
expect(res).toMatchInlineSnapshot(`
Object {
"count": null,
Expand All @@ -572,8 +569,7 @@ describe('advanced rpc', () => {
let result: Exclude<typeof res.data, null>
// Should be an error response due to ambiguous function resolution
let expected: SelectQueryError<'Could not choose the best candidate function between: public.postgrest_unresolvable_function(a => int4), public.postgrest_unresolvable_function(a => text). Try renaming the parameters or the function itself in the database so function overloading can be resolved'>
// TODO: works with latest postgrest-meta type introspection
// expectType<TypeEqual<typeof result, typeof expected>>(true)
expectType<TypeEqual<typeof result, typeof expected>>(true)
expect(res).toMatchInlineSnapshot(`
Object {
"count": null,
Expand Down Expand Up @@ -612,8 +608,7 @@ describe('advanced rpc', () => {
})
let result: Exclude<typeof res.data, null>
let expected: number
// TODO: works with latest postgrest-meta type introspection
// expectType<TypeEqual<typeof result, typeof expected>>(true)
expectType<TypeEqual<typeof result, typeof expected>>(true)
expect(res).toMatchInlineSnapshot(`
Object {
"count": null,
Expand All @@ -631,8 +626,7 @@ describe('advanced rpc', () => {
})
let result: Exclude<typeof res.data, null>
let expected: string
// TODO: works with latest postgrest-meta type introspection
// expectType<TypeEqual<typeof result, typeof expected>>(true)
expectType<TypeEqual<typeof result, typeof expected>>(true)
expect(res).toMatchInlineSnapshot(`
Object {
"count": null,
Expand All @@ -650,8 +644,7 @@ describe('advanced rpc', () => {
})
let result: Exclude<typeof res.data, null>
let expected: z.infer<typeof UserProfileSchema>[]
// TODO: works with latest postgrest-meta type introspection
// expectType<TypeEqual<typeof result, typeof expected>>(true)
expectType<TypeEqual<typeof result, typeof expected>>(true)
expect(res).toMatchInlineSnapshot(`
Object {
"count": null,
Expand All @@ -677,8 +670,7 @@ describe('advanced rpc', () => {
let result: Exclude<typeof res.data, null>
const ExpectedSchema = z.array(MessagesWithoutBlurbSchema)
let expected: RequiredDeep<z.infer<typeof ExpectedSchema>>
// TODO: works with latest postgrest-meta type introspection
// expectType<TypeEqual<typeof result, typeof expected>>(true)
expectType<TypeEqual<typeof result, typeof expected>>(true)
expect(res).toMatchInlineSnapshot(`
Object {
"count": null,
Expand Down Expand Up @@ -712,8 +704,7 @@ describe('advanced rpc', () => {
let result: Exclude<typeof res.data, null>
const ExpectedSchema = z.array(MessagesWithoutBlurbSchema)
let expected: RequiredDeep<z.infer<typeof ExpectedSchema>>
// TODO: works with latest postgrest-meta type introspection
// expectType<TypeEqual<typeof result, typeof expected>>(true)
expectType<TypeEqual<typeof result, typeof expected>>(true)
expect(res).toMatchInlineSnapshot(`
Object {
"count": null,
Expand Down Expand Up @@ -761,8 +752,7 @@ describe('advanced rpc', () => {
})
let result: Exclude<typeof res.data, null>
let expected: string
// TODO: works with latest postgrest-meta type introspection
// expectType<TypeEqual<typeof result, typeof expected>>(true)
expectType<TypeEqual<typeof result, typeof expected>>(true)
expect(res).toMatchInlineSnapshot(`
Object {
"count": null,
Expand All @@ -776,12 +766,9 @@ describe('advanced rpc', () => {

test('polymorphic function with bool param', async () => {
const res = await postgrest.rpc('polymorphic_function_with_different_return', {
// TODO: works with latest postgrest-meta type introspection
////@ts-expect-error Type 'boolean' is not assignable to type 'string'
// @ts-expect-error Type 'boolean' is not assignable to type 'string'
'': true,
})
// TODO: works with latest postgrest-meta type introspection
// expectType<TypeEqual<typeof result, typeof expected>>(true)
expect(res).toMatchInlineSnapshot(`
Object {
"count": null,
Expand All @@ -795,8 +782,7 @@ describe('advanced rpc', () => {

test('polymorphic function with unnamed int param', async () => {
const res = await postgrest.rpc(
// TODO: works with latest postgrest-meta type introspection
////@ts-expect-error Argument of type '"polymorphic_function_with_unnamed_integer"' is not assignable to parameter of type '"blurb_message" | "function_returning_row" | "function_returning_set_of_rows"
// @ts-expect-error Argument of type '"polymorphic_function_with_unnamed_integer"' is not assignable to parameter of type '"blurb_message" | "function_returning_row" | "function_returning_set_of_rows"
'polymorphic_function_with_unnamed_integer',
{
'': 1,
Expand Down Expand Up @@ -894,8 +880,7 @@ describe('advanced rpc', () => {
})
let result: Exclude<typeof res.data, null>
let expected: string
// TODO: works with latest postgrest-meta type introspection
// expectType<TypeEqual<typeof result, typeof expected>>(true)
expectType<TypeEqual<typeof result, typeof expected>>(true)
expect(res).toMatchInlineSnapshot(`
Object {
"count": null,
Expand All @@ -913,8 +898,7 @@ describe('advanced rpc', () => {
})
let result: Exclude<typeof res.data, null>
let expected: string
// TODO: works with latest postgrest-meta type introspection
// expectType<TypeEqual<typeof result, typeof expected>>(true)
expectType<TypeEqual<typeof result, typeof expected>>(true)
expect(res).toMatchInlineSnapshot(`
Object {
"count": null,
Expand All @@ -930,8 +914,7 @@ describe('advanced rpc', () => {
const res = await postgrest.rpc('polymorphic_function_with_unnamed_default')
let result: Exclude<typeof res.data, null>
let expected: SelectQueryError<'Could not choose the best candidate function between: public.polymorphic_function_with_unnamed_default(), public.polymorphic_function_with_unnamed_default( => text). Try renaming the parameters or the function itself in the database so function overloading can be resolved'>
// TODO: works with latest postgrest-meta type introspection
// expectType<TypeEqual<typeof result, typeof expected>>(true)
expectType<TypeEqual<typeof result, typeof expected>>(true)
expect(res).toMatchInlineSnapshot(`
Object {
"count": null,
Expand Down Expand Up @@ -977,8 +960,7 @@ describe('advanced rpc', () => {
})
let result: Exclude<typeof res.data, null>
let expected: string
// TODO: works with latest postgrest-meta type introspection
// expectType<TypeEqual<typeof result, typeof expected>>(true)
expectType<TypeEqual<typeof result, typeof expected>>(true)
expect(res).toMatchInlineSnapshot(`
Object {
"count": null,
Expand All @@ -994,8 +976,7 @@ describe('advanced rpc', () => {
const res = await postgrest.rpc('polymorphic_function_with_unnamed_default_overload')
let result: Exclude<typeof res.data, null>
let expected: SelectQueryError<'Could not choose the best candidate function between: public.polymorphic_function_with_unnamed_default_overload(), public.polymorphic_function_with_unnamed_default_overload( => text). Try renaming the parameters or the function itself in the database so function overloading can be resolved'>
// TODO: works with latest postgrest-meta type introspection
// expectType<TypeEqual<typeof result, typeof expected>>(true)
expectType<TypeEqual<typeof result, typeof expected>>(true)
expect(res).toMatchInlineSnapshot(`
Object {
"count": null,
Expand Down Expand Up @@ -1041,8 +1022,7 @@ describe('advanced rpc', () => {
})
let result: Exclude<typeof res.data, null>
let expected: string
// TODO: works with latest postgrest-meta type introspection
// expectType<TypeEqual<typeof result, typeof expected>>(true)
expectType<TypeEqual<typeof result, typeof expected>>(true)
expect(res).toMatchInlineSnapshot(`
Object {
"count": null,
Expand All @@ -1056,14 +1036,12 @@ describe('advanced rpc', () => {

test('polymorphic function with unnamed default overload bool param', async () => {
const res = await postgrest.rpc('polymorphic_function_with_unnamed_default_overload', {
// TODO: works with latest postgrest-meta type introspection
////@ts-expect-error Type 'boolean' is not assignable to type 'string'
// @ts-expect-error Type 'boolean' is not assignable to type 'string'
'': true,
})
let result: Exclude<typeof res.data, null>
let expected: string
// TODO: works with latest postgrest-meta type introspection
// expectType<TypeEqual<typeof result, typeof expected>>(true)
expectType<TypeEqual<typeof result, typeof expected>>(true)
expect(res).toMatchInlineSnapshot(`
Object {
"count": null,
Expand All @@ -1078,9 +1056,8 @@ describe('advanced rpc', () => {
test('function with blurb_message', async () => {
const res = await postgrest.rpc('blurb_message')
let result: Exclude<typeof res.data, null>
let expected: never
// TODO: works with latest postgrest-meta type introspection
// expectType<TypeEqual<typeof result, typeof expected>>(true)
let expected: SelectQueryError<'the function public.blurb_message with parameter or with a single unnamed json/jsonb parameter, but no matches were found in the schema cache'>
expectType<TypeEqual<typeof result, typeof expected>>(true)
expect(res).toMatchInlineSnapshot(`
Object {
"count": null,
Expand Down Expand Up @@ -1110,8 +1087,7 @@ describe('advanced rpc', () => {
})
let result: Exclude<typeof res.data, null>
let expected: SelectQueryError<'the function public.blurb_message with parameter or with a single unnamed json/jsonb parameter, but no matches were found in the schema cache'>
// TODO: works with latest postgrest-meta type introspection
// expectType<TypeEqual<typeof result, typeof expected>>(true)
expectType<TypeEqual<typeof result, typeof expected>>(true)
expect(res).toMatchInlineSnapshot(`
Object {
"count": null,
Expand Down Expand Up @@ -1275,7 +1251,7 @@ describe('advanced rpc', () => {
test('should be able to filter before and after select rpc', async () => {
const res = await postgrest
.rpc('get_user_profile', {
//@ts-expect-error Type '{ username: string; }' is missing the following properties from type '{ age_range: unknown; catchphrase: unknown; data: unknown; status: "ONLINE" | "OFFLINE" | null; username: string; }': age_range, catchphrase, data, status
// @ts-expect-error Type '{ username: string; }' is missing the following properties from type '{ age_range: unknown; catchphrase: unknown; data: unknown; status: "ONLINE" | "OFFLINE" | null; username: string; }': age_range, catchphrase, data, status
user_row: { username: 'supabot' },
})
.select('id, username, users(username, catchphrase)')
Expand All @@ -1292,7 +1268,7 @@ test('should be able to filter before and after select rpc', async () => {
`)
const res2 = await postgrest
.rpc('get_user_profile', {
//@ts-expect-error Type '{ username: string; }' is missing the following properties from type
// @ts-expect-error Type '{ username: string; }' is missing the following properties from type
user_row: { username: 'supabot' },
})
// should also be able to fitler before the select
Expand All @@ -1310,7 +1286,7 @@ test('should be able to filter before and after select rpc', async () => {
`)
const res3 = await postgrest
.rpc('get_user_profile', {
//@ts-expect-error Type '{ username: string; }' is missing the following properties from type
// @ts-expect-error Type '{ username: string; }' is missing the following properties from type
user_row: { username: 'supabot' },
})
// should also be able to fitler before the select
Expand Down Expand Up @@ -1374,7 +1350,6 @@ test('RPC call with subselect and computed field', async () => {
})
)
let expected: z.infer<typeof ExpectedSchema>
// TODO: works with latest postgrest-meta type introspection
// expectType<TypeEqual<typeof result, typeof expected>>(true)
expectType<TypeEqual<typeof result, typeof expected>>(true)
ExpectedSchema.parse(res.data)
})
2 changes: 1 addition & 1 deletion packages/core/postgrest-js/test/db/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ services:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
pgmeta:
image: supabase/postgres-meta:v0.91.5
image: supabase/postgres-meta:v0.92.0
ports:
- '8080:8080'
environment:
Expand Down
Loading