Skip to content

Commit a9c7c21

Browse files
authored
fix: type in enforceBase64 callable (#121)
* fix: type in enforceBase64 callable * fix: use LightMyRequestResponse from fastify package * feat: check for response type in ts test
1 parent 5d8ba4c commit a9c7c21

File tree

4 files changed

+9
-6
lines changed

4 files changed

+9
-6
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ $ npm i @fastify/aws-lambda
2323
| property | description | default value |
2424
| ------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------ | ------------- |
2525
| binaryMimeTypes | Array of binary MimeTypes to handle | `[]` |
26-
| enforceBase64 | Function that receives the reply and returns a boolean indicating if the response content is binary or not and should be base64-encoded | `undefined` |
26+
| enforceBase64 | Function that receives the response and returns a boolean indicating if the response content is binary or not and should be base64-encoded | `undefined` |
2727
| serializeLambdaArguments | Activate the serialization of lambda Event and Context in http header `x-apigateway-event` `x-apigateway-context` | `false` *(was `true` for <v2.0.0)* |
2828
| decorateRequest | Decorates the fastify request with the lambda Event and Context `request.awsLambda.event` `request.awsLambda.context` | `true` |
2929
| decorationPropertyName | The default property name for request decoration | `awsLambda` |

index.d.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
import { Context } from "aws-lambda";
2-
import { FastifyInstance, FastifyReply } from "fastify";
2+
import { FastifyInstance, LightMyRequestResponse } from "fastify";
33

44
export interface LambdaFastifyOptions {
55
binaryMimeTypes?: string[];
66
callbackWaitsForEmptyEventLoop?: boolean;
77
serializeLambdaArguments?: boolean;
88
decorateRequest?: boolean;
99
decorationPropertyName?: string;
10-
enforceBase64?: (reply: FastifyReply) => boolean;
10+
enforceBase64?: (response: LightMyRequestResponse) => boolean;
1111
}
1212

1313
export interface LambdaResponse {

index.test-d.ts

+5-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import fastify from "fastify";
1+
import fastify, {LightMyRequestResponse} from "fastify";
22
import awsLambdaFastify, {
33
PromiseHandler,
44
CallbackHandler,
@@ -70,7 +70,10 @@ expectAssignable<LambdaFastifyOptions>({
7070
serializeLambdaArguments: false,
7171
decorateRequest: true,
7272
decorationPropertyName: "myAWSstuff",
73-
enforceBase64: (reply) => false,
73+
enforceBase64: (response) => {
74+
expectType<LightMyRequestResponse>(response);
75+
return false;
76+
},
7477
});
7578

7679
expectError(awsLambdaFastify());

test/basic.test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ test('GET with custom binary check response', async (t) => {
138138
const proxy = awsLambdaFastify(app, {
139139
binaryMimeTypes: [],
140140
serializeLambdaArguments: true,
141-
enforceBase64: (reply) => reply.headers['x-base64-encoded'] === '1'
141+
enforceBase64: (response) => response.headers['x-base64-encoded'] === '1'
142142
})
143143
const ret = await proxy({
144144
httpMethod: 'GET',

0 commit comments

Comments
 (0)