forked from middyjs/middy
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.d.ts
More file actions
57 lines (46 loc) · 1.88 KB
/
index.d.ts
File metadata and controls
57 lines (46 loc) · 1.88 KB
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
57
import {
Callback,
Context,
Handler
} from 'aws-lambda';
declare type EventType<T, C> =
T extends (event: infer EventArgType, context: C, callback: Callback<any>) => void ? EventArgType :
T extends (event: infer EventArgType, context: C) => Promise<any> ? EventArgType :
never;
declare type HandlerReturnType<T, C> =
T extends (event: any, context: C) => Promise<infer RetType> ? RetType :
T extends (event: any, context: C, callback: Callback<infer RetType>) => void ? RetType :
never;
declare type AsyncHandler<C extends Context> =
((event: any, context: C, callback: Callback<any>) => void) |
((event: any, context: C) => Promise<any>);
declare const middy: <H extends AsyncHandler<C>, C extends Context = Context>(handler: H) => middy.Middy<
EventType<H, C>,
HandlerReturnType<H, C>,
C
>;
declare namespace middy {
interface Middy<T, R, C extends Context = Context> extends Handler<T, R> {
use: <M extends MiddlewareObject<T, R, C>>(middleware: M) => Middy<T, R, C>;
before: (callbackFn: MiddlewareFunction<T, R, C>) => Middy<T, R, C>;
after: (callbackFn: MiddlewareFunction<T, R, C>) => Middy<T, R, C>;
onError: (callbackFn: MiddlewareFunction<T, R, C>) => Middy<T, R, C>;
}
type Middleware<C extends any, T = any, R = any> = (config?: C) => MiddlewareObject<T, R>;
interface MiddlewareObject<T, R, C extends Context = Context> {
before?: MiddlewareFunction<T, R, C>;
after?: MiddlewareFunction<T, R, C>;
onError?: MiddlewareFunction<T, R, C>;
}
type MiddlewareFunction<T, R, C extends Context = Context> = (handler: HandlerLambda<T, R, C>, next: NextFunction) => void | Promise<any>;
type NextFunction = (error?: any) => void;
interface HandlerLambda<T = any, V = any, C extends Context = Context> {
event: T;
context: C;
response: V;
error: Error;
callback: Callback<V>;
}
}
export = middy;
export as namespace middy;