From 613e8aff82b31354b6babd6bad70dec92643c5f3 Mon Sep 17 00:00:00 2001 From: Tony133 Date: Tue, 28 Apr 2026 09:24:40 +0200 Subject: [PATCH 1/2] refactor(types): migrate from tsd to tstyche --- package.json | 9 +++------ test-types/initialization.test-d.ts | 8 ++++---- test-types/query.test-d.ts | 30 ----------------------------- test-types/query.tst.ts | 27 ++++++++++++++++++++++++++ test-types/transaction.test-d.ts | 12 ++++++------ 5 files changed, 40 insertions(+), 46 deletions(-) delete mode 100644 test-types/query.test-d.ts create mode 100644 test-types/query.tst.ts diff --git a/package.json b/package.json index 95af229..4da4197 100644 --- a/package.json +++ b/package.json @@ -14,7 +14,7 @@ "test": "npm run test:unit && npm run test:typescript", "test:unit": "c8 --100 node --test", "test:report": "standard && c8 --reporter html node --test", - "test:typescript": "tsd" + "test:typescript": "tstyche" }, "repository": { "type": "git", @@ -74,16 +74,13 @@ "neostandard": "^0.13.0", "pg": "^8.11.3", "pg-native": "^3.0.1", - "tsd": "^0.33.0", + "tstyche": "^7.0.0", "typescript": "~6.0.2" }, "peerDependencies": { "pg": ">=6.0.0" }, - "tsd": { - "directory": "test-types" - }, "publishConfig": { "access": "public" } -} +} \ No newline at end of file diff --git a/test-types/initialization.test-d.ts b/test-types/initialization.test-d.ts index c12c273..77fa9cd 100644 --- a/test-types/initialization.test-d.ts +++ b/test-types/initialization.test-d.ts @@ -1,7 +1,6 @@ import fastify from 'fastify' import * as pg from 'pg' -import { expectAssignable, expectType } from 'tsd' - +import { expect } from 'tstyche' import fastifyPostgres, { PostgresDb } from '../index' const app = fastify() @@ -34,6 +33,7 @@ app.register(fastifyPostgres, { // Plugin property available app.after(() => { - expectAssignable(app.pg) - expectType(app.pg.users) + expect(app.pg).type.toBeAssignableTo() + expect(app.pg.users).type.toBeAssignableTo() + expect(app.pg.posts).type.toBeAssignableTo() }) diff --git a/test-types/query.test-d.ts b/test-types/query.test-d.ts deleted file mode 100644 index 03049d4..0000000 --- a/test-types/query.test-d.ts +++ /dev/null @@ -1,30 +0,0 @@ -import fastify from 'fastify' -import { Client, Pool, PoolClient, QueryResult } from 'pg' -import { expectAssignable, expectType } from 'tsd' - -import fastifyPostgres, { PostgresDb } from '../index' - -const app = fastify() - -app.register(fastifyPostgres, { - connectionString: 'postgres://user:password@host:port/db', -}) - -app.get('/calc', async () => { - expectAssignable(app.pg) - - expectType(app.pg.pool) - expectType(app.pg.Client) - - const client = await app.pg.connect() - expectType(client) - - const sumResult = await client.query<{ sum: number }>('SELECT 2 + 2 as sum') - expectType>(sumResult) - - client.release() - - return { - sum: sumResult.rows, - } -}) diff --git a/test-types/query.tst.ts b/test-types/query.tst.ts new file mode 100644 index 0000000..f174611 --- /dev/null +++ b/test-types/query.tst.ts @@ -0,0 +1,27 @@ +import fastify from 'fastify' +import { type Client, type Pool, type PoolClient, type QueryResult } from 'pg' +import { expect } from 'tstyche' +import fastifyPostgres, { type PostgresDb } from '..' + +const app = fastify() + +app.register(fastifyPostgres, { + connectionString: 'postgres://user:password@host:port/db', +}) + +app.get('/calc', async () => { + expect(app.pg).type.toBeAssignableTo() + + expect(app.pg.pool).type.toBeAssignableTo() + expect(app.pg.Client).type.toBeAssignableTo() + + const client = await app.pg.connect() + expect(client).type.toBeAssignableTo() + + const sumResult = await client.query<{ sum: number }>('SELECT 2 + 2 as sum') + expect(sumResult).type.toBeAssignableTo>() + + client.release() + + return { sum: sumResult.rows } +}) diff --git a/test-types/transaction.test-d.ts b/test-types/transaction.test-d.ts index 38fd836..0f5c4d3 100644 --- a/test-types/transaction.test-d.ts +++ b/test-types/transaction.test-d.ts @@ -1,6 +1,6 @@ import fastify from 'fastify' import { PoolClient, QueryResult } from 'pg' -import { expectType } from 'tsd' +import { expect } from 'tstyche' // eslint-disable-next-line @typescript-eslint/no-unused-vars import fastifyPostgres, { PostgresDb } from '../index' @@ -19,12 +19,12 @@ app.post('/insert-async', async () => { ` const transactionResult = await app.pg.transact((client) => { - expectType(client) + expect(client).type.toBeAssignableTo() return client.query<{ sum: number }>(insertQuery) }) - expectType>(transactionResult) + expect(transactionResult).type.toBeAssignableTo>() return transactionResult }) @@ -38,13 +38,13 @@ app.post('/insert-cb', (_req, reply) => { app.pg.transact( (client) => { - expectType(client) + expect(client).type.toBeAssignableTo() return client.query<{ sum: number }>(insertQuery) }, (error, result) => { - expectType(error) - expectType | undefined>(result) + expect(error).type.toBeAssignableTo() + expect(result).type.toBeAssignableTo | undefined>() if (error) { reply.status(500).send(error) From 333a4c610e6ea0579ecb4ab4b3d1f0fbda6efd5a Mon Sep 17 00:00:00 2001 From: Tony133 Date: Tue, 28 Apr 2026 17:40:23 +0200 Subject: [PATCH 2/2] chore: updated --- test-types/{imports.test-d.ts => imports.tst.ts} | 0 ...tialization.test-d.ts => initialization.tst.ts} | 8 ++++---- test-types/query.tst.ts | 8 ++++---- .../{transaction.test-d.ts => transaction.tst.ts} | 14 ++++++-------- 4 files changed, 14 insertions(+), 16 deletions(-) rename test-types/{imports.test-d.ts => imports.tst.ts} (100%) rename test-types/{initialization.test-d.ts => initialization.tst.ts} (76%) rename test-types/{transaction.test-d.ts => transaction.tst.ts} (75%) diff --git a/test-types/imports.test-d.ts b/test-types/imports.tst.ts similarity index 100% rename from test-types/imports.test-d.ts rename to test-types/imports.tst.ts diff --git a/test-types/initialization.test-d.ts b/test-types/initialization.tst.ts similarity index 76% rename from test-types/initialization.test-d.ts rename to test-types/initialization.tst.ts index 77fa9cd..8669a4e 100644 --- a/test-types/initialization.test-d.ts +++ b/test-types/initialization.tst.ts @@ -1,7 +1,7 @@ import fastify from 'fastify' import * as pg from 'pg' import { expect } from 'tstyche' -import fastifyPostgres, { PostgresDb } from '../index' +import fastifyPostgres, { PostgresDb } from '..' const app = fastify() @@ -33,7 +33,7 @@ app.register(fastifyPostgres, { // Plugin property available app.after(() => { - expect(app.pg).type.toBeAssignableTo() - expect(app.pg.users).type.toBeAssignableTo() - expect(app.pg.posts).type.toBeAssignableTo() + expect(app.pg).type.toBeAssignableTo() + expect(app.pg.users).type.toBe() + expect(app.pg.posts).type.toBe() }) diff --git a/test-types/query.tst.ts b/test-types/query.tst.ts index f174611..2e172b4 100644 --- a/test-types/query.tst.ts +++ b/test-types/query.tst.ts @@ -12,14 +12,14 @@ app.register(fastifyPostgres, { app.get('/calc', async () => { expect(app.pg).type.toBeAssignableTo() - expect(app.pg.pool).type.toBeAssignableTo() - expect(app.pg.Client).type.toBeAssignableTo() + expect(app.pg.pool).type.toBe() + expect(app.pg.Client).type.toBe() const client = await app.pg.connect() - expect(client).type.toBeAssignableTo() + expect(client).type.toBe() const sumResult = await client.query<{ sum: number }>('SELECT 2 + 2 as sum') - expect(sumResult).type.toBeAssignableTo>() + expect(sumResult).type.toBe>() client.release() diff --git a/test-types/transaction.test-d.ts b/test-types/transaction.tst.ts similarity index 75% rename from test-types/transaction.test-d.ts rename to test-types/transaction.tst.ts index 0f5c4d3..d5b6c44 100644 --- a/test-types/transaction.test-d.ts +++ b/test-types/transaction.tst.ts @@ -1,9 +1,7 @@ import fastify from 'fastify' import { PoolClient, QueryResult } from 'pg' import { expect } from 'tstyche' - -// eslint-disable-next-line @typescript-eslint/no-unused-vars -import fastifyPostgres, { PostgresDb } from '../index' +import fastifyPostgres from '..' const app = fastify() @@ -19,12 +17,12 @@ app.post('/insert-async', async () => { ` const transactionResult = await app.pg.transact((client) => { - expect(client).type.toBeAssignableTo() + expect(client).type.toBe() return client.query<{ sum: number }>(insertQuery) }) - expect(transactionResult).type.toBeAssignableTo>() + expect(transactionResult).type.toBe>() return transactionResult }) @@ -38,13 +36,13 @@ app.post('/insert-cb', (_req, reply) => { app.pg.transact( (client) => { - expect(client).type.toBeAssignableTo() + expect(client).type.toBe() return client.query<{ sum: number }>(insertQuery) }, (error, result) => { - expect(error).type.toBeAssignableTo() - expect(result).type.toBeAssignableTo | undefined>() + expect(error).type.toBe() + expect(result).type.toBe | undefined>() if (error) { reply.status(500).send(error)