Skip to content

Commit 9b345d2

Browse files
committed
rename websocket property on signature
1 parent 3b92e6e commit 9b345d2

File tree

3 files changed

+10
-10
lines changed

3 files changed

+10
-10
lines changed

src/api/parser.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ export class Request {
99

1010
getProperties(): any {
1111
const event = this.event;
12-
const requestContext = event.requestContext ? event.requestContext : undefined;
12+
const websocket = event.requestContext ? event.requestContext : undefined;
1313
const path = event.pathParameters ? event.pathParameters : undefined;
1414
const query = event.queryStringParameters ? event.queryStringParameters : undefined;
1515
const auth = this.getAuth();
@@ -18,7 +18,7 @@ export class Request {
1818
const TEST_REQUEST_HEADER = process.env.TEST_REQUEST_HEADER || 'Test-Request';
1919
const testRequest = headers && headers[TEST_REQUEST_HEADER] ? JSON.parse(headers[TEST_REQUEST_HEADER]) : false;
2020
metrics.common({ body, path, query, auth, headers, testRequest });
21-
return { body, requestContext, path, query, auth, headers, testRequest };
21+
return { body, websocket, path, query, auth, headers, testRequest };
2222
}
2323

2424
private getAuth() {

src/api/wrapper.test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ describe('API wrapper', () => {
3131
// @ts-ignore
3232
function custom({
3333
event,
34-
requestContext,
34+
websocket,
3535
body,
3636
path,
3737
query,
@@ -46,7 +46,7 @@ describe('API wrapper', () => {
4646
error,
4747
}: ApiSignature) {
4848
expect(event).toEqual(requestEvent);
49-
expect(requestContext.connectionId).toEqual('abc-123');
49+
expect(websocket.connectionId).toEqual('abc-123');
5050
expect(body).toEqual({ hello: 'world' });
5151
expect(path).toEqual({ proxy: 'not today' });
5252
expect(query).toEqual({ name: 'a test' });
@@ -71,7 +71,7 @@ describe('API wrapper', () => {
7171
}
7272
function custom<CustomType>({
7373
event,
74-
requestContext,
74+
websocket,
7575
body,
7676
path,
7777
query,
@@ -86,7 +86,7 @@ describe('API wrapper', () => {
8686
error,
8787
}: ApiSignature<CustomType>) {
8888
expect(event).toEqual(requestEvent);
89-
expect(requestContext.connectionId).toEqual('abc-123');
89+
expect(websocket.connectionId).toEqual('abc-123');
9090
expect(body).toEqual({ hello: 'world' });
9191
expect(path).toEqual({ proxy: 'not today' });
9292
expect(query).toEqual({ name: 'a test' });

src/api/wrapper.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@ export function api<T = any>(
1212
custom: (props: ApiSignature<T>) => any
1313
): (event: APIGatewayEvent, context: Context, callback: Callback) => any {
1414
return function handler(event: APIGatewayEvent) {
15-
const { body, requestContext, path, query, auth, headers, testRequest } = new Request(event).getProperties();
15+
const { body, websocket, path, query, auth, headers, testRequest } = new Request(event).getProperties();
1616
const signature: ApiSignature<T> = {
1717
event,
1818
body,
19-
requestContext,
19+
websocket,
2020
path,
2121
query,
2222
headers,
@@ -36,7 +36,7 @@ export function api<T = any>(
3636
export interface ApiSignature<T = any> {
3737
event: APIGatewayEvent; // original event
3838
body: T; // JSON parsed body payload if exists (otherwise undefined)
39-
requestContext: WebsocketRequestContext; // websocket connection payload
39+
websocket: WebsocketRequest; // websocket connection payload
4040
path: { [name: string]: string }; // path param payload as key-value pairs if exists (otherwise undefined)
4141
query: { [name: string]: string }; // query param payload as key-value pairs if exists (otherwise undefined)
4242
headers: { [name: string]: string }; // header payload as key-value pairs if exists (otherwise undefined)
@@ -50,7 +50,7 @@ export interface ApiSignature<T = any> {
5050
error(error?: any): ApiResponse; // returns 500 status code with optional error as body
5151
}
5252

53-
export interface WebsocketRequestContext {
53+
export interface WebsocketRequest {
5454
accountId: string;
5555
apiId: string;
5656
connectedAt?: number;

0 commit comments

Comments
 (0)