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
10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"
}
}
}
100 changes: 0 additions & 100 deletions types/index.test-d.ts

This file was deleted.

107 changes: 107 additions & 0 deletions types/index.tst.ts
Original file line number Diff line number Diff line change
@@ -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<unknown, unknown> = awsLambdaFastify(app);
expect(proxyCallback({}, lambdaCtx, (err, res) => {})).type.toBe<void>();

// --- Promise handler ---

// Generic type passed
const proxyPromise: PromiseHandler<unknown, Record<string, string>> = awsLambdaFastify(app);

expect(awsLambdaFastify(app)).type.toBe<PromiseHandler<unknown>>();
expect(proxyPromise({}, lambdaCtx)).type.toBe<Promise<Record<string, string>>>();
expect(awsLambdaFastify(app, {})).type.toBe<PromiseHandler<unknown, LambdaResponse>>();

expect(
awsLambdaFastify<unknown, {}, boolean>(app)
).type.toBe<PromiseHandler<unknown, boolean>>();

// Default type
const proxyDefault = awsLambdaFastify(app);
expect(proxyDefault({}, lambdaCtx)).type.toBe<Promise<LambdaResponse>>();

// Streamed default type
const proxyStreamed = awsLambdaFastify(app, { payloadAsStream: true });
expect(proxyStreamed({}, lambdaCtx)).type.toBe<Promise<LambdaResponseStreamed>>();

expect({ binaryMimeTypes: ["foo", "bar"] }).type.toBeAssignableTo<LambdaFastifyOptions>();
expect({ callbackWaitsForEmptyEventLoop: true }).type.toBeAssignableTo<LambdaFastifyOptions>();
expect({ serializeLambdaArguments: true }).type.toBeAssignableTo<LambdaFastifyOptions>();

expect({
binaryMimeTypes: ["foo", "bar"],
callbackWaitsForEmptyEventLoop: true,
serializeLambdaArguments: true,
}).type.toBeAssignableTo<LambdaFastifyOptions>();

expect({
binaryMimeTypes: ["foo", "bar"],
callbackWaitsForEmptyEventLoop: true,
serializeLambdaArguments: false,
decorateRequest: true,
decorationPropertyName: "myAWSstuff",
}).type.toBeAssignableTo<LambdaFastifyOptions>();

expect({
binaryMimeTypes: ["foo", "bar"],
callbackWaitsForEmptyEventLoop: true,
serializeLambdaArguments: false,
decorateRequest: true,
decorationPropertyName: "myAWSstuff",
enforceBase64: (response: LightMyRequestResponse) => {
expect(response).type.toBe<LightMyRequestResponse>();
return false;
},
}).type.toBeAssignableTo<LambdaFastifyOptions>();

expect({
binaryMimeTypes: ["foo", "bar"],
callbackWaitsForEmptyEventLoop: true,
serializeLambdaArguments: false,
decorateRequest: true,
decorationPropertyName: "myAWSstuff",
enforceBase64: (response: LightMyRequestResponse) => {
expect(response).type.toBe<LightMyRequestResponse>();
return false;
},
retainStage: true,
}).type.toBeAssignableTo<LambdaFastifyOptions>();

expect({
disableBase64Encoding: true,
}).type.toBeAssignableTo<LambdaFastifyOptions>();

// @ts-expect-error!
awsLambdaFastify();

// @ts-expect-error!
awsLambdaFastify(app, { neh: "definition" });
expect(
awsLambdaFastify(app, { neh: 'definition' } as any)
).type.not.toBeAssignableTo<LambdaFastifyOptions>();
Loading