-
-
Notifications
You must be signed in to change notification settings - Fork 148
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
176 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
import { PostgrestClient } from '../../src/index' | ||
import { expectType } from 'tsd' | ||
import { TypeEqual } from 'ts-expect' | ||
|
||
const REST_URL = 'http://localhost:3000' | ||
|
||
// Check for PostgrestClient without types provided to the client | ||
{ | ||
const postgrest = new PostgrestClient(REST_URL) | ||
const { data } = await postgrest.from('user_profile').select() | ||
expectType<TypeEqual<typeof data, any[] | null>>(true) | ||
} | ||
// basic embeding | ||
{ | ||
const postgrest = new PostgrestClient(REST_URL) | ||
const { data } = await postgrest | ||
.from('user_profile') | ||
.select( | ||
'user_id, some_embed(*), another_embed(first_field, second_field, renamed:field), aninnerembed!inner(id, name)' | ||
) | ||
.single() | ||
let result: Exclude<typeof data, null> | ||
let expected: { | ||
user_id: any | ||
some_embed: any[] | ||
another_embed: { | ||
first_field: any | ||
second_field: any | ||
renamed: any | ||
}[] | ||
aninnerembed: { | ||
id: any | ||
name: any | ||
}[] | ||
} | ||
expectType<TypeEqual<typeof result, typeof expected>>(true) | ||
} | ||
// spread operator with stars should return any | ||
{ | ||
const postgrest = new PostgrestClient(REST_URL) | ||
const { data } = await postgrest | ||
.from('user_profile') | ||
.select('user_id, some_embed(*), ...spreadstars(*)') | ||
.single() | ||
let result: Exclude<typeof data, null> | ||
let expected: any | ||
expectType<TypeEqual<typeof result, typeof expected>>(true) | ||
} | ||
// nested spread operator with stars should return any | ||
{ | ||
const postgrest = new PostgrestClient(REST_URL) | ||
const { data } = await postgrest | ||
.from('user_profile') | ||
.select('user_id, some_embed(*), some_other(id, ...spreadstars(*))') | ||
.single() | ||
let result: Exclude<typeof data, null> | ||
let expected: { | ||
user_id: any | ||
some_embed: any[] | ||
some_other: any[] | ||
} | ||
expectType<TypeEqual<typeof result, typeof expected>>(true) | ||
} | ||
// rpc without types should raise similar results | ||
{ | ||
const postgrest = new PostgrestClient(REST_URL) | ||
const { data } = await postgrest.rpc('user_profile').select('user_id, some_embed(*)').single() | ||
let result: Exclude<typeof data, null> | ||
let expected: { | ||
user_id: any | ||
some_embed: any[] | ||
} | ||
expectType<TypeEqual<typeof result, typeof expected>>(true) | ||
} | ||
// check for nested operators | ||
{ | ||
const postgrest = new PostgrestClient(REST_URL) | ||
const { data } = await postgrest | ||
.from('user_profile') | ||
.select( | ||
'user_id, some_embed(*), another_embed(first_field, second_field, renamed:field), aninnerembed!inner(id, name), ...spreadwithfields(field_spread, another)' | ||
) | ||
.single() | ||
let result: Exclude<typeof data, null> | ||
let expected: { | ||
user_id: any | ||
some_embed: any[] | ||
another_embed: { | ||
first_field: any | ||
second_field: any | ||
renamed: any | ||
}[] | ||
aninnerembed: { | ||
id: any | ||
name: any | ||
}[] | ||
field_spread: any | ||
another: any | ||
} | ||
expectType<TypeEqual<typeof result, typeof expected>>(true) | ||
} |