Skip to content

Commit f89d7e3

Browse files
committed
update v1 and v2 type names to ApiGatewayV1 and ApiGatewayV2
1 parent 21ca074 commit f89d7e3

File tree

4 files changed

+40
-33
lines changed

4 files changed

+40
-33
lines changed

packages/event-handler/src/rest/Router.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import type {
2424
RequestContext,
2525
ResolveStreamOptions,
2626
ResponseStream,
27+
ResponseType,
2728
RestRouteOptions,
2829
RestRouterOptions,
2930
RouteHandler,
@@ -217,7 +218,9 @@ class Router {
217218
throw new InvalidEventError();
218219
}
219220

220-
const responseType = isAPIGatewayProxyEventV2(event) ? 'v2' : 'v1';
221+
const responseType: ResponseType = isAPIGatewayProxyEventV2(event)
222+
? 'ApiGatewayV2'
223+
: 'ApiGatewayV1';
221224

222225
let req: Request;
223226
try {

packages/event-handler/src/rest/converters.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -198,13 +198,17 @@ const webHeadersToApiGatewayV2Headers = (webHeaders: Headers) => {
198198
const webHeadersToApiGatewayHeaders = <T extends ResponseType>(
199199
webHeaders: Headers,
200200
responseType: T
201-
): T extends 'v1' ? V1Headers : { headers: Record<string, string> } => {
202-
if (responseType === 'v1') {
203-
return webHeadersToApiGatewayV1Headers(webHeaders) as T extends 'v1'
201+
): T extends 'ApiGatewayV1'
202+
? V1Headers
203+
: { headers: Record<string, string> } => {
204+
if (responseType === 'ApiGatewayV1') {
205+
return webHeadersToApiGatewayV1Headers(
206+
webHeaders
207+
) as T extends 'ApiGatewayV1'
204208
? V1Headers
205209
: { headers: Record<string, string> };
206210
}
207-
return webHeadersToApiGatewayV2Headers(webHeaders) as T extends 'v1'
211+
return webHeadersToApiGatewayV2Headers(webHeaders) as T extends 'ApiGatewayV1'
208212
? V1Headers
209213
: { headers: Record<string, string> };
210214
};
@@ -317,7 +321,7 @@ const webResponseToProxyResult = <T extends ResponseType>(
317321
response: Response,
318322
responseType: T
319323
): Promise<ResponseTypeMap[T]> => {
320-
if (responseType === 'v1') {
324+
if (responseType === 'ApiGatewayV1') {
321325
return webResponseToProxyResultV1(response) as Promise<ResponseTypeMap[T]>;
322326
}
323327
return webResponseToProxyResultV2(response) as Promise<ResponseTypeMap[T]>;

packages/event-handler/src/types/rest.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@ import type { Route } from '../rest/Route.js';
1515
import type { HttpResponseStream } from '../rest/utils.js';
1616
import type { ResolveOptions } from './common.js';
1717

18-
type ResponseType = 'v1' | 'v2';
18+
type ResponseType = 'ApiGatewayV1' | 'ApiGatewayV2';
1919

2020
type ResponseTypeMap = {
21-
v1: APIGatewayProxyResult;
22-
v2: APIGatewayProxyStructuredResultV2;
21+
ApiGatewayV1: APIGatewayProxyResult;
22+
ApiGatewayV2: APIGatewayProxyStructuredResultV2;
2323
};
2424

2525
type RequestContext = {

packages/event-handler/tests/unit/rest/converters.test.ts

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -549,7 +549,7 @@ describe('Converters', () => {
549549
});
550550

551551
// Act
552-
const result = await webResponseToProxyResult(response, 'v1');
552+
const result = await webResponseToProxyResult(response, 'ApiGatewayV1');
553553

554554
// Assess
555555
expect(result.statusCode).toBe(200);
@@ -566,7 +566,7 @@ describe('Converters', () => {
566566
});
567567

568568
// Act
569-
const result = await webResponseToProxyResult(response, 'v1');
569+
const result = await webResponseToProxyResult(response, 'ApiGatewayV1');
570570

571571
// Assess
572572
expect(result.statusCode).toBe(201);
@@ -587,7 +587,7 @@ describe('Converters', () => {
587587
});
588588

589589
// Act
590-
const result = await webResponseToProxyResult(response, 'v1');
590+
const result = await webResponseToProxyResult(response, 'ApiGatewayV1');
591591

592592
// Assess
593593
expect(result.headers).toEqual({ 'content-type': 'application/json' });
@@ -607,7 +607,7 @@ describe('Converters', () => {
607607
});
608608

609609
// Act
610-
const result = await webResponseToProxyResult(response, 'v1');
610+
const result = await webResponseToProxyResult(response, 'ApiGatewayV1');
611611

612612
// Assess
613613
expect(result.headers).toEqual({
@@ -623,7 +623,7 @@ describe('Converters', () => {
623623
const response = new Response('Not Found', { status: 404 });
624624

625625
// Act
626-
const result = await webResponseToProxyResult(response, 'v1');
626+
const result = await webResponseToProxyResult(response, 'ApiGatewayV1');
627627

628628
// Assess
629629
expect(result.statusCode).toBe(404);
@@ -634,7 +634,7 @@ describe('Converters', () => {
634634
const response = new Response(null, { status: 204 });
635635

636636
// Act
637-
const result = await webResponseToProxyResult(response, 'v1');
637+
const result = await webResponseToProxyResult(response, 'ApiGatewayV1');
638638

639639
// Assess
640640
expect(result.statusCode).toBe(204);
@@ -651,7 +651,7 @@ describe('Converters', () => {
651651
});
652652

653653
// Act
654-
const result = await webResponseToProxyResult(response, 'v1');
654+
const result = await webResponseToProxyResult(response, 'ApiGatewayV1');
655655

656656
// Assess
657657
expect(result.isBase64Encoded).toBe(true);
@@ -672,7 +672,7 @@ describe('Converters', () => {
672672
});
673673

674674
// Act
675-
const result = await webResponseToProxyResult(response, 'v2');
675+
const result = await webResponseToProxyResult(response, 'ApiGatewayV2');
676676

677677
// Assess
678678
expect(result.statusCode).toBe(200);
@@ -690,7 +690,7 @@ describe('Converters', () => {
690690
});
691691

692692
// Act
693-
const result = await webResponseToProxyResult(response, 'v2');
693+
const result = await webResponseToProxyResult(response, 'ApiGatewayV2');
694694

695695
// Assess
696696
expect(result.statusCode).toBe(201);
@@ -711,7 +711,7 @@ describe('Converters', () => {
711711
});
712712

713713
// Act
714-
const result = await webResponseToProxyResult(response, 'v2');
714+
const result = await webResponseToProxyResult(response, 'ApiGatewayV2');
715715

716716
// Assess
717717
expect(result.headers).toEqual({ 'content-type': 'application/json' });
@@ -728,7 +728,7 @@ describe('Converters', () => {
728728
});
729729

730730
// Act
731-
const result = await webResponseToProxyResult(response, 'v2');
731+
const result = await webResponseToProxyResult(response, 'ApiGatewayV2');
732732

733733
// Assess
734734
expect(result.cookies).toEqual([
@@ -744,7 +744,7 @@ describe('Converters', () => {
744744
const response = new Response('Not Found', { status: 404 });
745745

746746
// Act
747-
const result = await webResponseToProxyResult(response, 'v2');
747+
const result = await webResponseToProxyResult(response, 'ApiGatewayV2');
748748

749749
// Assess
750750
expect(result.statusCode).toBe(404);
@@ -756,7 +756,7 @@ describe('Converters', () => {
756756
const response = new Response(null, { status: 204 });
757757

758758
// Act
759-
const result = await webResponseToProxyResult(response, 'v2');
759+
const result = await webResponseToProxyResult(response, 'ApiGatewayV2');
760760

761761
// Assess
762762
expect(result.statusCode).toBe(204);
@@ -773,7 +773,7 @@ describe('Converters', () => {
773773
});
774774

775775
// Act
776-
const result = await webResponseToProxyResult(response, 'v2');
776+
const result = await webResponseToProxyResult(response, 'ApiGatewayV2');
777777

778778
// Assess
779779
expect(result.isBase64Encoded).toBe(true);
@@ -945,7 +945,7 @@ describe('Converters', () => {
945945
});
946946

947947
// Act
948-
const result = webHeadersToApiGatewayHeaders(headers, 'v1');
948+
const result = webHeadersToApiGatewayHeaders(headers, 'ApiGatewayV1');
949949

950950
// Assess
951951
expect(result).toEqual({
@@ -965,7 +965,7 @@ describe('Converters', () => {
965965
});
966966

967967
// Act
968-
const result = webHeadersToApiGatewayHeaders(headers, 'v1');
968+
const result = webHeadersToApiGatewayHeaders(headers, 'ApiGatewayV1');
969969

970970
// Assess
971971
expect(result).toEqual({
@@ -984,7 +984,7 @@ describe('Converters', () => {
984984
});
985985

986986
// Act
987-
const result = webHeadersToApiGatewayHeaders(headers, 'v1');
987+
const result = webHeadersToApiGatewayHeaders(headers, 'ApiGatewayV1');
988988

989989
// Assess
990990
expect(result).toEqual({
@@ -1003,7 +1003,7 @@ describe('Converters', () => {
10031003
});
10041004

10051005
// Act
1006-
const result = webHeadersToApiGatewayHeaders(headers, 'v1');
1006+
const result = webHeadersToApiGatewayHeaders(headers, 'ApiGatewayV1');
10071007

10081008
// Assess
10091009
expect(result).toEqual({
@@ -1022,7 +1022,7 @@ describe('Converters', () => {
10221022
headers.append('x-custom', 'value2');
10231023

10241024
// Act
1025-
const result = webHeadersToApiGatewayHeaders(headers, 'v1');
1025+
const result = webHeadersToApiGatewayHeaders(headers, 'ApiGatewayV1');
10261026

10271027
// Assess
10281028
expect(result).toEqual({
@@ -1040,7 +1040,7 @@ describe('Converters', () => {
10401040
headers.append('x-custom', 'value2');
10411041

10421042
// Act
1043-
const result = webHeadersToApiGatewayHeaders(headers, 'v1');
1043+
const result = webHeadersToApiGatewayHeaders(headers, 'ApiGatewayV1');
10441044

10451045
// Assess
10461046
expect(result).toEqual({
@@ -1059,7 +1059,7 @@ describe('Converters', () => {
10591059
headers.append('accept', 'text/plain');
10601060

10611061
// Act
1062-
const result = webHeadersToApiGatewayHeaders(headers, 'v1');
1062+
const result = webHeadersToApiGatewayHeaders(headers, 'ApiGatewayV1');
10631063

10641064
// Assess
10651065
expect(result).toEqual({
@@ -1078,7 +1078,7 @@ describe('Converters', () => {
10781078
});
10791079

10801080
// Act
1081-
const result = webHeadersToApiGatewayHeaders(headers, 'v1');
1081+
const result = webHeadersToApiGatewayHeaders(headers, 'ApiGatewayV1');
10821082

10831083
// Assess
10841084
expect(result).toEqual({
@@ -1095,7 +1095,7 @@ describe('Converters', () => {
10951095
const headers = new Headers();
10961096

10971097
// Act
1098-
const result = webHeadersToApiGatewayHeaders(headers, 'v1');
1098+
const result = webHeadersToApiGatewayHeaders(headers, 'ApiGatewayV1');
10991099

11001100
// Assess
11011101
expect(result).toEqual({
@@ -1114,7 +1114,7 @@ describe('Converters', () => {
11141114
});
11151115

11161116
// Act
1117-
const result = webHeadersToApiGatewayHeaders(headers, 'v1');
1117+
const result = webHeadersToApiGatewayHeaders(headers, 'ApiGatewayV1');
11181118

11191119
// Assess
11201120
expect(result).toEqual({

0 commit comments

Comments
 (0)