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();