This repository has been archived by the owner on Dec 5, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtypes-express.ts
56 lines (46 loc) · 1.6 KB
/
types-express.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
// eslint-disable-next-line import/no-unresolved
import awsLambda from 'aws-lambda';
import express from 'express';
import httpLambda from 'http-lambda';
import {
LambdaContext
} from './types-lambda';
export interface ExpressHandler extends express.Handler {
disable?: (...args) => any;
}
export interface ExpressApp extends express.Application {
defaultMiddlewares?: {[key: string]: ExpressHandler;};
}
// ReturnType<ajv.compile>
export type ReturnTypeAjvCompileFn = ((data: any) => boolean) & {
errors?: any[];
schema: any;
};
export interface ExpressLambdaRequestExtensions {
ctx: LambdaContext;
validate?: ReturnTypeAjvCompileFn;
getSelfUrl: () => URL;
}
export type ExpressLambdaRequest = httpLambda.IncomingMessage & express.Request & ExpressLambdaRequestExtensions & {
res: ExpressLambdaResponse;
};
export interface ExpressLambdaResponseExtensions {
ctx: LambdaContext;
validate?: ReturnTypeAjvCompileFn;
oldSend?: (httpLambda.ServerResponse & express.Response)['send'];
oldType?: (httpLambda.ServerResponse & express.Response)['type'];
}
export type ExpressLambdaResponse = httpLambda.ServerResponse & express.Response & ExpressLambdaResponseExtensions & {
req: ExpressLambdaRequest;
};
// export type HttpLambdaHandler = (
// event: awsLambda.APIGatewayEvent,
// context: LambdaContext,
// callback?: awsLambda.Callback<awsLambda.APIGatewayProxyResult>
// ) => Promise<void>;
export type ExpressLambdaHandler = (
app: ExpressApp,
event: awsLambda.APIGatewayEvent,
context: LambdaContext,
callback?: awsLambda.Callback<awsLambda.APIGatewayProxyResult>
) => Promise<void>;