From 287b5e06ea8a983eac77e7dddc1deedc8f288a28 Mon Sep 17 00:00:00 2001 From: igalklebanov Date: Sat, 6 Apr 2024 16:57:18 +0300 Subject: [PATCH] typings tests. .. --- tests/typings/index.d.ts | 1 + tests/typings/package.json | 3 + tests/typings/test-d/kyselify.test-d.ts | 106 ++++++++++++++++++++++++ tests/typings/tsconfig.json | 7 ++ 4 files changed, 117 insertions(+) create mode 100644 tests/typings/index.d.ts create mode 100644 tests/typings/package.json create mode 100644 tests/typings/test-d/kyselify.test-d.ts create mode 100644 tests/typings/tsconfig.json 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": "../../" + } +}