Skip to content

Commit 015b92f

Browse files
committed
Fix return type of wrapper
1 parent 56efea1 commit 015b92f

File tree

2 files changed

+8
-14
lines changed

2 files changed

+8
-14
lines changed

src/index.ts

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -45,20 +45,14 @@ export type TShallotSocketEvent<
4545
body?: TBody;
4646
};
4747

48-
type TShallotSocketHandler<TEvent extends TShallotSocketEvent = TShallotSocketEvent> = (
48+
const ShallotSocketWrapper = <TEvent extends TShallotSocketEvent = TShallotSocketEvent>(
4949
handler: ShallotRawHandler<TEvent>,
50-
successStatusCode?: number,
51-
middlewareOpts?: {
50+
successStatusCode = 200,
51+
middlewareOpts: {
5252
HttpErrorHandlerOpts?: TShallotErrorHandlerOptions;
5353
HttpJsonBodyParserOpts?: TShallotJSONBodyParserOptions;
54-
}
55-
) => ShallotAWSHandler<TEvent>;
56-
57-
const ShallotSocketWrapper: TShallotSocketHandler = (
58-
handler,
59-
successStatusCode = 200,
60-
middlewareOpts = {}
61-
) => {
54+
} = {}
55+
): ShallotAWSHandler<TEvent> => {
6256
const wrappedResponseHandler: Handler = async (...args) => {
6357
const res = await handler(...args);
6458
return {

tests/index.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,13 @@ describe('WebSocket Wrapper', () => {
2121
succeed: () => undefined,
2222
};
2323

24-
const mockHandler: ShallotRawHandler<TShallotSocketEvent<{ test: string }>> =
25-
async () => undefined;
24+
type MockEvent = TShallotSocketEvent<{ test: string }>;
25+
const mockHandler: ShallotRawHandler<MockEvent> = async () => undefined;
2626

2727
test('Smoke test CORS default usage', async () => {
2828
const wrappedHandler = ShallotAWSSocketWrapper(mockHandler);
2929

30-
const mockEvent: TShallotSocketEvent = {} as unknown as TShallotSocketEvent;
30+
const mockEvent: MockEvent = {} as unknown as MockEvent;
3131
await wrappedHandler(mockEvent, mockContext, jest.fn());
3232
});
3333
});

0 commit comments

Comments
 (0)