import fastify, {LightMyRequestResponse} from "fastify"; import awsLambdaFastify, { PromiseHandler, CallbackHandler, LambdaFastifyOptions, LambdaResponse, } 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)); 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, }); expectError(awsLambdaFastify()); expectError(awsLambdaFastify(app, { neh: "definition" }));