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
5 changes: 5 additions & 0 deletions .changeset/kysely-tailordb-own-client-type.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@tailor-platform/function-kysely-tailordb": patch
---

Stop depending on the global `Tailordb` type namespace. `TailordbDialect` now describes its client by shape (`connect`, `end` and `queryObject`), so the published declarations type-check without `@tailor-platform/function-types`, which is deprecated. Runtime behavior is unchanged, and both the legacy `Tailordb.Client` and the `tailordb.Client` of `@tailor-platform/sdk` can still be passed.
14 changes: 12 additions & 2 deletions packages/kysely-tailordb/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,23 @@

## Usage

We recommend installing [@tailor-platform/function-types](https://www.npmjs.com/package/@tailor-platform/function-types) along with @tailor-platform/function-kysely-tailordb, as you’ll need these types to use the dialect effectively.
`TailordbDialect` takes the `tailordb.Client` of the Tailor Platform function runtime. It describes the client by its shape (`connect`, `end` and `queryObject`), so it does not need any ambient type declarations to type-check.

To type the `tailordb` global in your own code, load the runtime globals of [@tailor-platform/sdk](https://www.npmjs.com/package/@tailor-platform/sdk) in `tsconfig.json`:

```sh
npm install -D @tailor-platform/function-types
npm install -D @tailor-platform/sdk
npm install @tailor-platform/function-kysely-tailordb
```

```json
{
"compilerOptions": {
"types": ["@tailor-platform/sdk/runtime/globals"]
}
}
```

```typescript
import { Kysely } from 'kysely';
import { TailordbDialect } from '@tailor-platform/function-kysely-tailordb';
Expand Down
3 changes: 2 additions & 1 deletion packages/kysely-tailordb/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"check-write": "biome check --write .",
"build": "tsup src/index.ts --format esm,cjs --dts --clean",
"clean": "rm -rf dist",
"type-check": "tsc --noEmit",
"type-check": "tsc --noEmit && tsc --noEmit -p type-tests",
"prepublishOnly": "pnpm run build"
},
"exports": {
Expand All @@ -31,6 +31,7 @@
"devDependencies": {
"@biomejs/biome": "1.9.4",
"@tailor-platform/function-types": "workspace:*",
"@tailor-platform/sdk": "2.38.0",
"@tsconfig/recommended": "1.0.13",
"kysely": "0.28.17",
"tsup": "8.5.1",
Expand Down
15 changes: 12 additions & 3 deletions packages/kysely-tailordb/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,17 @@ import {
type TransactionSettings,
} from "kysely";

interface TailordbClient {
connect(): Promise<void>;
end(): Promise<void>;
queryObject<O>(
sql: string,
args?: readonly unknown[],
): Promise<{ rows: O[]; command: string; rowCount: number }>;
}

export class TailordbDialect implements Dialect {
constructor(private client: Tailordb.Client) {}
constructor(private client: TailordbClient) {}

createDriver(): Driver {
return new TailordbDriver(this.client);
Expand All @@ -36,7 +45,7 @@ export class TailordbDialect implements Dialect {
}

class TailordbDriver implements Driver {
constructor(private client: Tailordb.Client) {}
constructor(private client: TailordbClient) {}

async init(): Promise<void> {
await this.client.connect();
Expand Down Expand Up @@ -72,7 +81,7 @@ class TailordbDriver implements Driver {
}

class TailordbConnection implements DatabaseConnection {
constructor(private client: Tailordb.Client) {}
constructor(private client: TailordbClient) {}

async executeQuery<O>(compiledQuery: CompiledQuery): Promise<QueryResult<O>> {
const result = await this.client.queryObject<O>(compiledQuery.sql, [
Expand Down
6 changes: 3 additions & 3 deletions packages/kysely-tailordb/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"extends": "@tsconfig/recommended/tsconfig.json",
"compilerOptions": {
"target": "ESNext",
"types": ["@tailor-platform/function-types"]
}
"target": "ESNext"
},
"include": ["src"]
}
10 changes: 10 additions & 0 deletions packages/kysely-tailordb/type-tests/client-compat.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/// <reference types="@tailor-platform/function-types" />
import type { TailordbClientInstance } from "@tailor-platform/sdk/runtime";
import type { TailordbDialect } from "../src/index";

type DialectClient = ConstructorParameters<typeof TailordbDialect>[0];

export const fromFunctionTypes = (client: Tailordb.Client): DialectClient =>
client;
export const fromSdk = (client: TailordbClientInstance): DialectClient =>
client;
10 changes: 10 additions & 0 deletions packages/kysely-tailordb/type-tests/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"extends": "@tsconfig/recommended/tsconfig.json",
"compilerOptions": {
"target": "ESNext",
"module": "preserve",
"moduleResolution": "bundler",
"noEmit": true
},
"include": ["./*.ts"]
}
Loading
Loading