-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.d.ts
132 lines (113 loc) · 2.97 KB
/
index.d.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
export interface ILog {
(...args: any[]): void;
}
export interface ILogger extends ILog {
error: ILog;
warn: ILog;
info: ILog;
verbose: ILog;
}
export interface IDict<TValue> {
[key: string]: TValue;
}
export interface IDoneCallback {
(err?: any, result?: any): void;
}
export interface IHttpRequestMethods {
get(field: string): string | undefined;
}
export interface IHttpRequest extends IDict<any> {
method: string;
url: string;
originalUrl: string;
headers?: IDict<string>;
query?: IDict<string>;
params?: IDict<string>;
body?: any;
rawbody?: any;
}
export type HttpRequest = IHttpRequest & IHttpRequestMethods;
type HttpResponseStatus =
| string
| number
| ((statusCode: string | number) => IHttpResponse);
export interface IHttpResponse extends IDict<any> {
headers?: IDict<any>;
status?: HttpResponseStatus;
statusCode?: HttpResponseStatus;
body?: any;
isRaw?: boolean;
}
export interface IHttpResponseMethods {
raw<T>(body: T): IHttpResponse;
end<T>(body?: T): IHttpResponse;
setHeader<T>(field: string, val: T): IHttpResponse;
getHeader(field: string): any;
removeHeader(field: string): IHttpResponse;
send<T>(body?: T): IHttpResponse;
header<T>(field: string, val: T): IHttpResponse;
get(field: string): any;
set<T>(field: string, val: T): IHttpResponse;
sendStatus(statusCode: string | number): IHttpResponse;
type(type: string): IHttpResponse;
json<T>(body: T): IHttpResponse;
}
export type HttpResponse = IHttpResponse & IHttpResponseMethods;
export interface IExecutionContext {
invocationId: string;
functionName: string;
functionDirectory: string;
}
export interface ISys {
methodName: string;
utcNow: Date;
}
export interface IBoundRequest {
requestUri: string;
}
export interface IBindingData extends IDict<any> {
invocationId: string;
sys: ISys;
}
export interface IEventHubBindingData extends IBindingData {
partitionContext: {
eventHubPath: string;
consumerGroupName: string;
};
partitionKey: any;
offset: string;
sequenceNumber: number;
enqueuedTimeUtc: Date;
properties: IDict<any>;
systemProperties: {
"iothub-connection-device-id": string;
"iothub-connection-auth-method": string;
"iothub-connection-auth-generation-id": string;
"iothub-enqueuedtime": Date;
"iothub-message-source": string;
"x-opt-sequence-number": number;
"x-opt-offset": string;
"x-opt-enqueued-time": Date;
enqueuedTimeUtc: Date;
sequenceNumber: number;
offset: string;
};
}
export interface IHttpBindingData extends IBindingData {
query?: IDict<string>;
req?: IBoundRequest;
$request?: IBoundRequest;
}
export interface IContext<T> {
invocationId: string;
executionContext: IExecutionContext;
bindings: IDict<any>;
bindingData: T;
log: ILogger;
done: IDoneCallback;
}
export interface IEventHubContext extends IContext<IEventHubBindingData> {}
export interface IHttpContext extends IContext<IHttpBindingData> {
req?: HttpRequest;
res?: HttpResponse;
}