From e651f360f1f22127b1a1c9b8fb041eb5ec9a78f8 Mon Sep 17 00:00:00 2001 From: Tony133 Date: Wed, 6 May 2026 09:05:46 +0200 Subject: [PATCH 1/5] refactor(types): migrate from tsd to tstyche --- package.json | 6 +++--- test/index.test.js | 6 +++--- types/index.test-d.ts | 40 ---------------------------------------- types/index.tst.ts | 41 +++++++++++++++++++++++++++++++++++++++++ 4 files changed, 47 insertions(+), 46 deletions(-) delete mode 100644 types/index.test-d.ts create mode 100644 types/index.tst.ts diff --git a/package.json b/package.json index 7bbd89f..fb05e09 100644 --- a/package.json +++ b/package.json @@ -11,7 +11,7 @@ "redis": "docker run -p 6379:6379 --rm redis:7.2", "valkey": "docker run -p 6379:6379 --rm valkey/valkey:latest", "test": "npm run unit && npm run typescript", - "typescript": "tsd", + "typescript": "tstyche", "unit": "c8 --100 node --test" }, "keywords": [ @@ -53,7 +53,7 @@ "eslint": "^9.17.0", "fastify": "^5.0.0", "neostandard": "^0.12.0", - "tsd": "^0.33.0", + "tstyche": "^7.0.0", "why-is-node-running": "^3.2.2" }, "dependencies": { @@ -63,4 +63,4 @@ "publishConfig": { "access": "public" } -} +} \ No newline at end of file diff --git a/test/index.test.js b/test/index.test.js index 2f6c89e..f1cf9df 100644 --- a/test/index.test.js +++ b/test/index.test.js @@ -281,7 +281,7 @@ test('Should throw when trying to connect on an invalid host', async (t) => { t.after(() => fastify.close()) fastify.register(fastifyValkey, { - addresses: [{ host: 'invalid_host' }], + addresses: [{ host: 'invalid_host', port: 9999 }], connectionBackoff: { numberOfRetries: 0 } @@ -315,7 +315,7 @@ test('Should be able to register multiple namespaced @fastify/valkey instances', test('Should throw when @fastify/valkey is initialized with an option that makes valkey throw', async (t) => { t.plan(1) - const fastify = Fastify() + const fastify = Fastify({ pluginTimeout: 20000 }) t.after(() => fastify.close()) fastify.register(fastifyValkey, { addresses: [] }) @@ -326,7 +326,7 @@ test('Should throw when @fastify/valkey is initialized with an option that makes test('Should throw when @fastify/valkey is initialized with a namespace and an option that makes valkey throw', async (t) => { t.plan(1) - const fastify = Fastify() + const fastify = Fastify({ pluginTimeout: 20000 }) t.after(() => fastify.close()) fastify.register(fastifyValkey, { diff --git a/types/index.test-d.ts b/types/index.test-d.ts deleted file mode 100644 index eb884cb..0000000 --- a/types/index.test-d.ts +++ /dev/null @@ -1,40 +0,0 @@ -import Fastify, { FastifyInstance } from 'fastify' -import { GlideClient, GlideClusterClient } from '@valkey/valkey-glide' -import { expectAssignable, expectError, expectType } from 'tsd' -import fastifyValkey, { FastifyValkey, FastifyValkeyPluginOptions, FastifyValkeyNamespacedInstance, } from '..' - -const app:FastifyInstance = Fastify() -const valkey: GlideClient = await GlideClient.createClient({ addresses: [{ host: '127.0.0.1', port: 6379 }] }) -const valkeyCluster: GlideClusterClient = await GlideClusterClient.createClient({ addresses: [{ host: '127.0.0.1', port: 6379 }] }) - -app.register(fastifyValkey, { addresses: [{ host: '127.0.0.1', port: 6379 }] }) - -app.register(fastifyValkey, { - client: valkey, - closeClient: true, - namespace: 'one' -}) - -app.register(fastifyValkey, { - namespace: 'two', - addresses: [{ host: '127.0.0.1', port: 6379 }] -}) - -expectAssignable({ - client: valkeyCluster, -}) - -expectError(app.register(fastifyValkey, { - namespace: 'three', - unknownOption: 'this should trigger a typescript error' -})) - -// Plugin property available -app.after(() => { - expectAssignable(app.valkey) - expectType(app.valkey) - - expectAssignable(app.valkey) - expectType(app.valkey.one) - expectType(app.valkey.two) -}) diff --git a/types/index.tst.ts b/types/index.tst.ts new file mode 100644 index 0000000..3ca9c94 --- /dev/null +++ b/types/index.tst.ts @@ -0,0 +1,41 @@ +import Fastify, { FastifyInstance } from 'fastify' +import { GlideClient, GlideClusterClient } from '@valkey/valkey-glide' +import { expect } from 'tstyche' +import fastifyValkey, { FastifyValkey, FastifyValkeyPluginOptions, FastifyValkeyNamespacedInstance, } from '.' + +const app:FastifyInstance = Fastify() +const valkey = {} as GlideClient +const valkeyCluster = {} as GlideClusterClient +app.register(fastifyValkey, { addresses: [{ host: '127.0.0.1', port: 6379 }] }) + +app.register(fastifyValkey, { + client: valkey, + closeClient: true, + namespace: 'one' +}) + +app.register(fastifyValkey, { + namespace: 'two', + addresses: [{ host: '127.0.0.1', port: 6379 }] +}) + +expect({ + client: valkeyCluster, +}).type.toBeAssignableTo() + +expect({ + namespace: 'three', + unknownOption: 'this should trigger a typescript error' +}).type.not.toBeAssignableTo() + +// Plugin property available +app.after(() => { + expect(app.valkey).type.toBeAssignableTo() + expect(app.valkey).type.toBe() + + expect(app.valkey).type.toBeAssignableTo() + expect(app.valkey.one).type.toBe< + GlideClient | GlideClusterClient | undefined + >() + expect(app.valkey.two).type.toBe() +}) From aeb2f2406d3f38cc3aaa02b3147d403fa1432cc1 Mon Sep 17 00:00:00 2001 From: Tony133 Date: Wed, 6 May 2026 09:31:35 +0200 Subject: [PATCH 2/5] fix: update index.test.js --- test/index.test.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/test/index.test.js b/test/index.test.js index f1cf9df..18ab968 100644 --- a/test/index.test.js +++ b/test/index.test.js @@ -312,7 +312,7 @@ test('Should be able to register multiple namespaced @fastify/valkey instances', t.assert.ok(fastify.valkey.multiple_namespace2) }) -test('Should throw when @fastify/valkey is initialized with an option that makes valkey throw', async (t) => { +test('Should throw when @fastify/valkey is initialized with an option that makes valkey throw', (t, done) => { t.plan(1) const fastify = Fastify({ pluginTimeout: 20000 }) @@ -320,7 +320,10 @@ test('Should throw when @fastify/valkey is initialized with an option that makes fastify.register(fastifyValkey, { addresses: [] }) - await t.assert.rejects(fastify.ready()) + fastify.ready((err) => { + t.assert.ok(err) + done() + }) }) test('Should throw when @fastify/valkey is initialized with a namespace and an option that makes valkey throw', async (t) => { From 36aeefe6127a38d55eac7ae33d40afce9e73f507 Mon Sep 17 00:00:00 2001 From: Tony133 Date: Wed, 6 May 2026 09:51:52 +0200 Subject: [PATCH 3/5] fix: update index.test.js --- test/index.test.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/index.test.js b/test/index.test.js index 18ab968..c0753b1 100644 --- a/test/index.test.js +++ b/test/index.test.js @@ -312,7 +312,7 @@ test('Should be able to register multiple namespaced @fastify/valkey instances', t.assert.ok(fastify.valkey.multiple_namespace2) }) -test('Should throw when @fastify/valkey is initialized with an option that makes valkey throw', (t, done) => { +test('Should throw when @fastify/valkey is initialized with an option that makes valkey throw', { skip: process.platform === 'darwin' }, (t, done) => { t.plan(1) const fastify = Fastify({ pluginTimeout: 20000 }) @@ -326,7 +326,7 @@ test('Should throw when @fastify/valkey is initialized with an option that makes }) }) -test('Should throw when @fastify/valkey is initialized with a namespace and an option that makes valkey throw', async (t) => { +test('Should throw when @fastify/valkey is initialized with a namespace and an option that makes valkey throw', { skip: process.platform === 'darwin' }, async (t) => { t.plan(1) const fastify = Fastify({ pluginTimeout: 20000 }) From 75f5a74f128ed7a761f75538d956408f136b1676 Mon Sep 17 00:00:00 2001 From: Tony133 Date: Wed, 6 May 2026 10:11:36 +0200 Subject: [PATCH 4/5] fix: update index.test.js --- test/index.test.js | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/test/index.test.js b/test/index.test.js index c0753b1..d41984f 100644 --- a/test/index.test.js +++ b/test/index.test.js @@ -312,18 +312,15 @@ test('Should be able to register multiple namespaced @fastify/valkey instances', t.assert.ok(fastify.valkey.multiple_namespace2) }) -test('Should throw when @fastify/valkey is initialized with an option that makes valkey throw', { skip: process.platform === 'darwin' }, (t, done) => { +test('Should throw when @fastify/valkey is initialized with an option that makes valkey throw', { skip: process.platform === 'darwin' }, async (t) => { t.plan(1) - const fastify = Fastify({ pluginTimeout: 20000 }) + const fastify = Fastify() t.after(() => fastify.close()) fastify.register(fastifyValkey, { addresses: [] }) - fastify.ready((err) => { - t.assert.ok(err) - done() - }) + await t.assert.rejects(fastify.ready()) }) test('Should throw when @fastify/valkey is initialized with a namespace and an option that makes valkey throw', { skip: process.platform === 'darwin' }, async (t) => { From 91e477b3af10ac18d3170cde9a38cd61770a1afa Mon Sep 17 00:00:00 2001 From: Tony133 Date: Wed, 6 May 2026 22:54:46 +0200 Subject: [PATCH 5/5] chore: update index.tst.ts --- types/index.tst.ts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/types/index.tst.ts b/types/index.tst.ts index 3ca9c94..547919a 100644 --- a/types/index.tst.ts +++ b/types/index.tst.ts @@ -19,14 +19,14 @@ app.register(fastifyValkey, { addresses: [{ host: '127.0.0.1', port: 6379 }] }) -expect({ - client: valkeyCluster, -}).type.toBeAssignableTo() +expect().type.toBeAssignableFrom({ + client: valkeyCluster +}) -expect({ +expect().type.not.toBeAssignableFrom({ namespace: 'three', unknownOption: 'this should trigger a typescript error' -}).type.not.toBeAssignableTo() +}) // Plugin property available app.after(() => {