From 27c6241853333ae313bf54878524967884805cf9 Mon Sep 17 00:00:00 2001 From: Tony133 Date: Wed, 29 Apr 2026 10:13:31 +0200 Subject: [PATCH 1/2] refactor(types): migrate from tsd to tstyche --- package.json | 8 +++--- types/index.test-d.ts | 47 -------------------------------- types/index.tst.ts | 62 +++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 66 insertions(+), 51 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 b2a56b4..5c2273c 100644 --- a/package.json +++ b/package.json @@ -44,19 +44,19 @@ "lint:fix": "eslint --fix", "test": "npm run test:unit && npm run test:typescript", "test:unit": "c8 --100 node --test", - "test:typescript": "tsd" + "test:typescript": "tstyche" }, "devDependencies": { - "@types/node": "^25.0.3", + "@types/node": "^25.6.0", "beautify-benchmark": "^0.2.4", "benchmark": "^2.1.4", "c8": "^11.0.0", "eslint": "^9.17.0", "neostandard": "^0.13.0", - "tsd": "^0.33.0" + "tstyche": "^7.0.0" }, "keywords": [ "csrf", "tokens" ] -} +} \ No newline at end of file diff --git a/types/index.test-d.ts b/types/index.test-d.ts deleted file mode 100644 index b64f029..0000000 --- a/types/index.test-d.ts +++ /dev/null @@ -1,47 +0,0 @@ -/* eslint-disable no-new -- Testing constructor types, so no need to assign */ -import { expectError, expectType } from 'tsd' -import { Tokens } from '..' - -Tokens() -new Tokens() -Tokens({}) -new Tokens({}) -Tokens({ algorithm: 'sha1' }) -Tokens({ algorithm: 'sha256' }) -Tokens({ saltLength: 10 }) -Tokens({ secretLength: 10 }) -Tokens({ userInfo: true }) -Tokens({ validity: 10000 }) -Tokens({ hmacKey: 'foo' }) -new Tokens({ saltLength: 10 }) -new Tokens({ secretLength: 10 }) -new Tokens({ userInfo: true }) -new Tokens({ validity: 10000 }) - -expectError(Tokens('secret')) -expectError(new Tokens('secret')) - -expectError(new Tokens({}).create('secret', 'userInfo')) -expectError(new Tokens({ userInfo: false }).create('secret', 'userInfo')) -expectError(new Tokens({ userInfo: true }).create('secret')) - -expectError(new Tokens({}).verify('secret', 'token', 'userinfo')) -expectError(new Tokens({ userInfo: false }).verify('secret', 'token', 'userInfo')) -expectError(new Tokens({ userInfo: true }).verify('secret', 'token')) - -expectError(new Tokens({ hmacKey: 123 })) - -expectType>(Tokens().secret()) -expectType>(new Tokens().secret()) - -expectType(Tokens().secret((err, secret) => { - expectType(err) - expectType(secret) -})) -expectType(new Tokens().secret((err, secret) => { - expectType(err) - expectType(secret) -})) - -expectType(Tokens().secretSync()) -expectType(new Tokens().secretSync()) diff --git a/types/index.tst.ts b/types/index.tst.ts new file mode 100644 index 0000000..a1b10e3 --- /dev/null +++ b/types/index.tst.ts @@ -0,0 +1,62 @@ +/* eslint-disable no-new -- Testing constructor types, so no need to assign */ +/// +import { expect } from 'tstyche' +import { Tokens } from '..' + +Tokens() +new Tokens() +Tokens({}) +new Tokens({}) +Tokens({ algorithm: 'sha1' }) +Tokens({ algorithm: 'sha256' }) +Tokens({ saltLength: 10 }) +Tokens({ secretLength: 10 }) +Tokens({ userInfo: true }) +Tokens({ validity: 10000 }) +Tokens({ hmacKey: 'foo' }) +new Tokens({ saltLength: 10 }) +new Tokens({ secretLength: 10 }) +new Tokens({ userInfo: true }) +new Tokens({ validity: 10000 }) + +// @ts-expect-error! +Tokens('secret') +// @ts-expect-error! +new Tokens('secret') + +// @ts-expect-error! +new Tokens({}).create('secret', 'userInfo') +// @ts-expect-error! +new Tokens({ userInfo: false }).create('secret', 'userInfo') +// @ts-expect-error! +new Tokens({ userInfo: true }).create('secret') + +// @ts-expect-error! +new Tokens({}).verify('secret', 'token', 'userinfo') +// @ts-expect-error! +new Tokens({ userInfo: false }).verify('secret', 'token', 'userInfo') +// @ts-expect-error! +new Tokens({ userInfo: true }).verify('secret', 'token') + +// @ts-expect-error! +new Tokens({ hmacKey: 123 }) + +expect(Tokens().secret()).type.toBe>() +expect(new Tokens().secret()).type.toBe>() + +expect( + Tokens().secret((err, secret) => { + expect(err).type.toBe() + expect(secret).type.toBe() + }) +).type.toBe() + +expect( + new Tokens().secret((err, secret) => { + expect(err).type.toBe() + expect(secret).type.toBe() + }) +).type.toBe() + +expect(Tokens().secretSync()).type.toBe() +expect(new Tokens().secretSync()).type.toBe() From 5e2dbbb7ecfbb3483bfed4cab3ba09279a15349b Mon Sep 17 00:00:00 2001 From: Antonio Tripodi Date: Wed, 29 Apr 2026 14:54:51 +0200 Subject: [PATCH 2/2] chore: update index.tst.ts Co-authored-by: Tom Mrazauskas Signed-off-by: Antonio Tripodi --- types/index.tst.ts | 33 ++++++++++++--------------------- 1 file changed, 12 insertions(+), 21 deletions(-) diff --git a/types/index.tst.ts b/types/index.tst.ts index a1b10e3..b942e3b 100644 --- a/types/index.tst.ts +++ b/types/index.tst.ts @@ -19,27 +19,18 @@ new Tokens({ secretLength: 10 }) new Tokens({ userInfo: true }) new Tokens({ validity: 10000 }) -// @ts-expect-error! -Tokens('secret') -// @ts-expect-error! -new Tokens('secret') - -// @ts-expect-error! -new Tokens({}).create('secret', 'userInfo') -// @ts-expect-error! -new Tokens({ userInfo: false }).create('secret', 'userInfo') -// @ts-expect-error! -new Tokens({ userInfo: true }).create('secret') - -// @ts-expect-error! -new Tokens({}).verify('secret', 'token', 'userinfo') -// @ts-expect-error! -new Tokens({ userInfo: false }).verify('secret', 'token', 'userInfo') -// @ts-expect-error! -new Tokens({ userInfo: true }).verify('secret', 'token') - -// @ts-expect-error! -new Tokens({ hmacKey: 123 }) +expect(Tokens).type.not.toBeCallableWith('secret') +expect(Tokens).type.not.toBeConstructableWith('secret') + +expect(new Tokens({}).create).type.not.toBeCallableWith('secret', 'userInfo') +expect(new Tokens({ userInfo: false }).create).type.not.toBeCallableWith('secret', 'userInfo') +expect(new Tokens({ userInfo: true }).create).type.not.toBeCallableWith('secret') + +expect(new Tokens({}).verify).type.not.toBeCallableWith('secret', 'token', 'userinfo') +expect(new Tokens({ userInfo: false }).verify).type.not.toBeCallableWith('secret', 'token', 'userInfo') +expect(new Tokens({ userInfo: true }).verify).type.not.toBeCallableWith('secret', 'token') + +expect(Tokens).type.not.toBeConstructableWith({ hmacKey: 123 }) expect(Tokens().secret()).type.toBe>() expect(new Tokens().secret()).type.toBe>()