-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathtypes.ts
216 lines (216 loc) · 6.18 KB
/
types.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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
/**
* Interface for your Azure Function code. This function must be exported (via module.exports or exports)
* and will execute when triggered. It is recommended that you declare this function as async, which
* implicitly returns a Promise.
* @param context Context object passed to your function from the Azure Functions runtime.
* @param {any[]} args Optional array of input and trigger binding data. These binding data are passed to the
* function in the same order that they are defined in function.json. Valid input types are string, HttpRequest,
* and Buffer.
* @returns Output bindings (optional). If you are returning a result from a Promise (or an async function), this
* result will be passed to JSON.stringify unless it is a string, Buffer, ArrayBufferView, or number.
*/
export declare type AzureFunction = ((
context: Context,
...args: any[]
) => Promise<any> | void | any);
/**
* The context object can be used for writing logs, reading data from bindings, setting outputs and using
* the context.done callback when your exported function is synchronous. A context object is passed
* to your function from the Azure Functions runtime on function invocation.
*/
export interface Context {
// /**
// * A unique GUID per function invocation.
// */
// invocationId: string;
// /**
// * Function execution metadata.
// */
// executionContext: ExecutionContext;
/**
* Input and trigger binding data, as defined in function.json. Properties on this object are dynamically
* generated and named based off of the "name" property in function.json.
*/
bindings: {
[key: string]: any;
};
/**
* Trigger metadata and function invocation data.
*/
bindingData: {
[key: string]: any;
};
// /**
// * TraceContext information to enable distributed tracing scenarios.
// */
// traceContext: TraceContext;
// /**
// * Bindings your function uses, as defined in function.json.
// */
// bindingDefinitions: BindingDefinition[];
/**
* Allows you to write streaming function logs. Calling directly allows you to write streaming function logs
* at the default trace level.
*/
log: Logger;
/**
* HTTP request object. Provided to your function when using HTTP Bindings.
*/
req?: HttpRequest;
/**
* HTTP response object. Provided to your function when using HTTP Bindings.
*/
res?: {
[key: string]: any;
};
}
/**
* HTTP request object. Provided to your function when using HTTP Bindings.
*/
export interface HttpRequest {
/**
* HTTP request method used to invoke this function.
*/
method: HttpMethod | null;
/**
* Request URL.
*/
url: string;
/**
* HTTP request headers.
*/
headers: {
[key: string]: string;
};
/**
* Query string parameter keys and values from the URL.
*/
query: {
[key: string]: string;
};
/**
* Route parameter keys and values.
*/
params: {
[key: string]: string;
};
/**
* The HTTP request body.
*/
body?: any;
/**
* The HTTP request body as a UTF-8 string.
*/
rawBody?: any;
}
/**
* Possible values for an HTTP request method.
*/
export declare type HttpMethod =
| "GET"
| "POST"
| "DELETE"
| "HEAD"
| "PATCH"
| "PUT"
| "OPTIONS"
| "TRACE"
| "CONNECT";
/**
* Http response cookie object to "Set-Cookie"
*/
export interface Cookie {
/** Cookie name */
name: string;
/** Cookie value */
value: string;
/** Specifies allowed hosts to receive the cookie */
domain?: string;
/** Specifies URL path that must exist in the requested URL */
path?: string;
/**
* NOTE: It is generally recommended that you use maxAge over expires.
* Sets the cookie to expire at a specific date instead of when the client closes.
* This can be a Javascript Date or Unix time in milliseconds.
*/
expires?: Date | number;
/** Sets the cookie to only be sent with an encrypted request */
secure?: boolean;
/** Sets the cookie to be inaccessible to JavaScript's Document.cookie API */
httpOnly?: boolean;
/** Can restrict the cookie to not be sent with cross-site requests */
sameSite?: "Strict" | "Lax" | undefined;
/** Number of seconds until the cookie expires. A zero or negative number will expire the cookie immediately. */
maxAge?: number;
}
export interface ExecutionContext {
/**
* A unique GUID per function invocation.
*/
invocationId: string;
/**
* The name of the function that is being invoked. The name of your function is always the same as the
* name of the corresponding function.json's parent directory.
*/
functionName: string;
/**
* The directory your function is in (this is the parent directory of this function's function.json).
*/
functionDirectory: string;
}
/**
* TraceContext information to enable distributed tracing scenarios.
*/
export interface TraceContext {
/** Describes the position of the incoming request in its trace graph in a portable, fixed-length format. */
traceparent: string | null | undefined;
/** Extends traceparent with vendor-specific data. */
tracestate: string | null | undefined;
/** Holds additional properties being sent as part of request telemetry. */
attributes:
| {
[k: string]: string;
}
| null
| undefined;
}
export interface BindingDefinition {
/**
* The name of your binding, as defined in function.json.
*/
name: string;
/**
* The type of your binding, as defined in function.json.
*/
type: string;
/**
* The direction of your binding, as defined in function.json.
*/
direction: "in" | "out" | "inout" | undefined;
}
/**
* Allows you to write streaming function logs.
*/
export interface Logger {
/**
* Writes streaming function logs at the default trace level.
*/
(message: string): void;
// /**
// * Writes to error level logging or lower.
// */
// error(...args: any[]): void;
// /**
// * Writes to warning level logging or lower.
// */
// warn(...args: any[]): void;
// /**
// * Writes to info level logging or lower.
// */
// info(...args: any[]): void;
// /**
// * Writes to verbose level logging.
// */
// verbose(...args: any[]): void;
logs: string[];
}