Skip to content

Commit

Permalink
typings tests.
Browse files Browse the repository at this point in the history
..
  • Loading branch information
igalklebanov committed Apr 6, 2024
1 parent b565da9 commit 287b5e0
Show file tree
Hide file tree
Showing 4 changed files with 117 additions and 0 deletions.
1 change: 1 addition & 0 deletions tests/typings/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from '../..'
3 changes: 3 additions & 0 deletions tests/typings/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"types": "index.d.ts"
}
106 changes: 106 additions & 0 deletions tests/typings/test-d/kyselify.test-d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
import type {ColumnType} from 'kysely'
import {expectType} from 'tsd'
import type {IsEqual} from 'type-fest'
import type {KyselifyDatabase} from '..'
import type {Database as SupabaseDatabase} from '../../../schema.gen'

function testSingleSchemaDatabase() {
type Actual = KyselifyDatabase<SupabaseDatabase>
type Expected = {
person: {
id: ColumnType<number, number | undefined, number | undefined>
first_name: ColumnType<
string | null,
string | null | undefined,
string | null | undefined
>
middle_name: ColumnType<
string | null,
string | null | undefined,
string | null | undefined
>
last_name: ColumnType<
string | null,
string | null | undefined,
string | null | undefined
>
gender: ColumnType<string, string, string | undefined>
marital_status: ColumnType<
string | null,
string | null | undefined,
string | null | undefined
>
children: ColumnType<number, number | undefined, number | undefined>
}
pet: {
id: ColumnType<number, number | undefined, number | undefined>
name: ColumnType<string, string, string | undefined>
species: ColumnType<string, string, string | undefined>
owner_id: ColumnType<number, number, number | undefined>
}
toy: {
id: ColumnType<number, number | undefined, number | undefined>
name: ColumnType<string, string, string | undefined>
pet_id: ColumnType<number, number, number | undefined>
}
}

expectType<IsEqual<Actual, Expected>>(true)
}

function testMultiSchemaDatabase() {
type Actual = KyselifyDatabase<
SupabaseDatabase & {
my_schema: {
Tables: {
toy: SupabaseDatabase['public']['Tables']['toy']
}
}
}
>
type Expected = {
'public.person': {
id: ColumnType<number, number | undefined, number | undefined>
first_name: ColumnType<
string | null,
string | null | undefined,
string | null | undefined
>
middle_name: ColumnType<
string | null,
string | null | undefined,
string | null | undefined
>
last_name: ColumnType<
string | null,
string | null | undefined,
string | null | undefined
>
gender: ColumnType<string, string, string | undefined>
marital_status: ColumnType<
string | null,
string | null | undefined,
string | null | undefined
>
children: ColumnType<number, number | undefined, number | undefined>
}
'public.pet': {
id: ColumnType<number, number | undefined, number | undefined>
name: ColumnType<string, string, string | undefined>
species: ColumnType<string, string, string | undefined>
owner_id: ColumnType<number, number, number | undefined>
}
'public.toy': {
id: ColumnType<number, number | undefined, number | undefined>
name: ColumnType<string, string, string | undefined>
pet_id: ColumnType<number, number, number | undefined>
}
'my_schema.toy': {
id: ColumnType<number, number | undefined, number | undefined>
name: ColumnType<string, string, string | undefined>
pet_id: ColumnType<number, number, number | undefined>
}
}

expectType<IsEqual<Actual, Expected>>(true)
}
7 changes: 7 additions & 0 deletions tests/typings/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"extends": "../../tsconfig.json",
"include": ["./**/*"],
"compilerOptions": {
"rootDir": "../../"
}
}

0 comments on commit 287b5e0

Please sign in to comment.