diff --git a/package.json b/package.json index aa89ca6..3620f86 100644 --- a/package.json +++ b/package.json @@ -35,7 +35,7 @@ "lint:fix": "eslint --fix", "test": "npm run test:unit && npm run test:typescript", "test:unit": "node scripts/unit.js", - "test:typescript": "tsd", + "test:typescript": "tstyche", "performance": "npm run lint && node performanceTest/test", "preversion": "npm run test && git push", "postversion": "git push && git push --tags" @@ -50,14 +50,14 @@ "aws-serverless-express": "^3.4.0", "aws-serverless-fastify": "^3.1.3", "benchmark": "^2.1.4", - "eslint": "^10.2.1", + "eslint": "^9.39.0", "fast-glob": "^3.3.3", "fastify": "^5.8.4", - "neostandard": "^0.13.0", + "neostandard": "^0.12.0", "serverless-http": "^4.0.0", - "tsd": "^0.33.0" + "tstyche": "^7.0.0" }, "publishConfig": { "access": "public" } -} +} \ 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 84329c1..0000000 --- a/types/index.test-d.ts +++ /dev/null @@ -1,100 +0,0 @@ -import fastify, {LightMyRequestResponse} from "fastify"; -import awsLambdaFastify, { - PromiseHandler, - CallbackHandler, - LambdaFastifyOptions, - LambdaResponse, - LambdaResponseStreamed, -} from ".."; - -import { expectType, expectError, expectAssignable } from "tsd"; - -const app = fastify(); - -const lambdaCtx = { - callbackWaitsForEmptyEventLoop: false, - functionName: "func", - functionVersion: "2", - invokedFunctionArn: "arn", - memoryLimitInMB: "666", - awsRequestId: "1337", - logGroupName: "Log", - logStreamName: "stream", - getRemainingTimeInMillis: () => 1, - done: () => {}, - fail: () => {}, - succeed: () => {}, -}; - -// Callback handler -const proxyCallback: CallbackHandler = awsLambdaFastify(app); -expectType(proxyCallback({}, lambdaCtx, (err, res) => {})); - -// Promise handler - -// Generic type passed -const proxyPromise: PromiseHandler> = - awsLambdaFastify(app); -expectType>(awsLambdaFastify(app)); -expectType>>(proxyPromise({}, lambdaCtx)); -expectType>(awsLambdaFastify(app, {})); -expectType>( - awsLambdaFastify(app) -); - -// Default type -const proxyDefault = awsLambdaFastify(app); -expectType>(proxyDefault({}, lambdaCtx)); - -// Streamed default type -const proxyStreamed = awsLambdaFastify(app, { payloadAsStream: true }); -expectType>(proxyStreamed({}, lambdaCtx)); - -expectAssignable({ binaryMimeTypes: ["foo", "bar"] }); -expectAssignable({ - callbackWaitsForEmptyEventLoop: true, -}); -expectAssignable({ - serializeLambdaArguments: true, -}); -expectAssignable({ - binaryMimeTypes: ["foo", "bar"], - callbackWaitsForEmptyEventLoop: true, - serializeLambdaArguments: true, -}); -expectAssignable({ - binaryMimeTypes: ["foo", "bar"], - callbackWaitsForEmptyEventLoop: true, - serializeLambdaArguments: false, - decorateRequest: true, - decorationPropertyName: "myAWSstuff", -}); -expectAssignable({ - binaryMimeTypes: ["foo", "bar"], - callbackWaitsForEmptyEventLoop: true, - serializeLambdaArguments: false, - decorateRequest: true, - decorationPropertyName: "myAWSstuff", - enforceBase64: (response) => { - expectType(response); - return false; - }, -}); -expectAssignable({ - binaryMimeTypes: ["foo", "bar"], - callbackWaitsForEmptyEventLoop: true, - serializeLambdaArguments: false, - decorateRequest: true, - decorationPropertyName: "myAWSstuff", - enforceBase64: (response) => { - expectType(response); - return false; - }, - retainStage: true, -}); -expectAssignable({ - disableBase64Encoding: true, -}); - -expectError(awsLambdaFastify()); -expectError(awsLambdaFastify(app, { neh: "definition" })); diff --git a/types/index.tst.ts b/types/index.tst.ts new file mode 100644 index 0000000..5d306cb --- /dev/null +++ b/types/index.tst.ts @@ -0,0 +1,107 @@ +import fastify, { type LightMyRequestResponse } from "fastify"; +import awsLambdaFastify, { + type PromiseHandler, + type CallbackHandler, + type LambdaFastifyOptions, + type LambdaResponse, + type LambdaResponseStreamed, +} from "."; +import { expect } from "tstyche"; + +const app = fastify(); + +const lambdaCtx = { + callbackWaitsForEmptyEventLoop: false, + functionName: "func", + functionVersion: "2", + invokedFunctionArn: "arn", + memoryLimitInMB: "666", + awsRequestId: "1337", + logGroupName: "Log", + logStreamName: "stream", + getRemainingTimeInMillis: () => 1, + done: () => {}, + fail: () => {}, + succeed: () => {}, +}; + +// --- Callback handler --- +const proxyCallback: CallbackHandler = awsLambdaFastify(app); +expect(proxyCallback({}, lambdaCtx, (err, res) => {})).type.toBe(); + +// --- Promise handler --- + +// Generic type passed +const proxyPromise: PromiseHandler> = awsLambdaFastify(app); + +expect(awsLambdaFastify(app)).type.toBe>(); +expect(proxyPromise({}, lambdaCtx)).type.toBe>>(); +expect(awsLambdaFastify(app, {})).type.toBe>(); + +expect( + awsLambdaFastify(app) +).type.toBe>(); + +// Default type +const proxyDefault = awsLambdaFastify(app); +expect(proxyDefault({}, lambdaCtx)).type.toBe>(); + +// Streamed default type +const proxyStreamed = awsLambdaFastify(app, { payloadAsStream: true }); +expect(proxyStreamed({}, lambdaCtx)).type.toBe>(); + +expect({ binaryMimeTypes: ["foo", "bar"] }).type.toBeAssignableTo(); +expect({ callbackWaitsForEmptyEventLoop: true }).type.toBeAssignableTo(); +expect({ serializeLambdaArguments: true }).type.toBeAssignableTo(); + +expect({ + binaryMimeTypes: ["foo", "bar"], + callbackWaitsForEmptyEventLoop: true, + serializeLambdaArguments: true, +}).type.toBeAssignableTo(); + +expect({ + binaryMimeTypes: ["foo", "bar"], + callbackWaitsForEmptyEventLoop: true, + serializeLambdaArguments: false, + decorateRequest: true, + decorationPropertyName: "myAWSstuff", +}).type.toBeAssignableTo(); + +expect({ + binaryMimeTypes: ["foo", "bar"], + callbackWaitsForEmptyEventLoop: true, + serializeLambdaArguments: false, + decorateRequest: true, + decorationPropertyName: "myAWSstuff", + enforceBase64: (response: LightMyRequestResponse) => { + expect(response).type.toBe(); + return false; + }, +}).type.toBeAssignableTo(); + +expect({ + binaryMimeTypes: ["foo", "bar"], + callbackWaitsForEmptyEventLoop: true, + serializeLambdaArguments: false, + decorateRequest: true, + decorationPropertyName: "myAWSstuff", + enforceBase64: (response: LightMyRequestResponse) => { + expect(response).type.toBe(); + return false; + }, + retainStage: true, +}).type.toBeAssignableTo(); + +expect({ + disableBase64Encoding: true, +}).type.toBeAssignableTo(); + +// @ts-expect-error! +awsLambdaFastify(); + +// @ts-expect-error! +awsLambdaFastify(app, { neh: "definition" }); +expect( + awsLambdaFastify(app, { neh: 'definition' } as any) +).type.not.toBeAssignableTo(); \ No newline at end of file