Skip to content

Commit efa31c8

Browse files
cenkingunlugumuratcorlu
authored andcommitted
feat: TypeScript support
TypeScript support added. Thanks @cenkingunlugu !
1 parent ecc9291 commit efa31c8

File tree

5 files changed

+57
-0
lines changed

5 files changed

+57
-0
lines changed

package-lock.json

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
"semantic-release": "^15.13.21"
2626
},
2727
"dependencies": {
28+
"@types/aws-lambda": "^8.10.33",
2829
"accepts": "^1.3.7",
2930
"type-is": "^1.6.18"
3031
}

src/lambda-wrapper.d.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { Request } from './request';
2+
import { Response } from './response';
3+
import { APIGatewayProxyHandler } from 'aws-lambda';
4+
5+
export interface Middleware {
6+
(request: Request, response: Response, next: Function): void
7+
}
8+
9+
export function use(...handlers: Middleware[]): ApiGatewayProxyHandler;
10+
11+
export { Request } from './request';
12+
export { Response } from './response';

src/request.d.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
2+
import { APIGatewayProxyEvent } from 'aws-lambda';
3+
import { Accepts } from 'accepts';
4+
import { Readable } from 'stream';
5+
6+
export class Request extends Readable {
7+
constructor(event: APIGatewayProxyEvent);
8+
headers: { [name: string]: string };
9+
hostname: string | null;
10+
method: string;
11+
query: { [name: string]: string } | null;
12+
path: string;
13+
params: { [name: string]: string } | null;
14+
protocol: 'http' | 'https';
15+
secure: boolean;
16+
ips: string[];
17+
ip: string;
18+
host: string | null;
19+
xhr: boolean;
20+
event: APIGatewayProxyEvent;
21+
accept: Accepts;
22+
}

src/response.d.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import { Request } from "./request";
2+
import { APIGatewayProxyCallback, APIGatewayProxyResult } from 'aws-lambda';
3+
4+
export class Response {
5+
constructor(req: Request, callback: APIGatewayProxyCallback);
6+
req: Request;
7+
callback: APIGatewayProxyCallback;
8+
responseObj: APIGatewayProxyResult;
9+
end: () => void;
10+
get: (key: string) => string;
11+
format: (obj: Object) => Response;
12+
json: (body: Object) => void;
13+
send: (body: Object) => void;
14+
set: (key: string, value: string) => Response;
15+
status: (status: number) => Response;
16+
type: (type: string) => Response;
17+
}

0 commit comments

Comments
 (0)