diff --git a/tests/typings/index.d.ts b/tests/typings/index.d.ts new file mode 100644 index 0000000..31d591e --- /dev/null +++ b/tests/typings/index.d.ts @@ -0,0 +1 @@ +export * from '../..' diff --git a/tests/typings/package.json b/tests/typings/package.json new file mode 100644 index 0000000..ddd2ec3 --- /dev/null +++ b/tests/typings/package.json @@ -0,0 +1,3 @@ +{ + "types": "index.d.ts" +} diff --git a/tests/typings/test-d/kyselify.test-d.ts b/tests/typings/test-d/kyselify.test-d.ts new file mode 100644 index 0000000..6e0f2e3 --- /dev/null +++ b/tests/typings/test-d/kyselify.test-d.ts @@ -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 + type Expected = { + person: { + id: ColumnType + 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 + marital_status: ColumnType< + string | null, + string | null | undefined, + string | null | undefined + > + children: ColumnType + } + pet: { + id: ColumnType + name: ColumnType + species: ColumnType + owner_id: ColumnType + } + toy: { + id: ColumnType + name: ColumnType + pet_id: ColumnType + } + } + + expectType>(true) +} + +function testMultiSchemaDatabase() { + type Actual = KyselifyDatabase< + SupabaseDatabase & { + my_schema: { + Tables: { + toy: SupabaseDatabase['public']['Tables']['toy'] + } + } + } + > + type Expected = { + 'public.person': { + id: ColumnType + 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 + marital_status: ColumnType< + string | null, + string | null | undefined, + string | null | undefined + > + children: ColumnType + } + 'public.pet': { + id: ColumnType + name: ColumnType + species: ColumnType + owner_id: ColumnType + } + 'public.toy': { + id: ColumnType + name: ColumnType + pet_id: ColumnType + } + 'my_schema.toy': { + id: ColumnType + name: ColumnType + pet_id: ColumnType + } + } + + expectType>(true) +} diff --git a/tests/typings/tsconfig.json b/tests/typings/tsconfig.json new file mode 100644 index 0000000..8d45cf4 --- /dev/null +++ b/tests/typings/tsconfig.json @@ -0,0 +1,7 @@ +{ + "extends": "../../tsconfig.json", + "include": ["./**/*"], + "compilerOptions": { + "rootDir": "../../" + } +}