-
Notifications
You must be signed in to change notification settings - Fork 8
/
InvocationContext.d.ts
344 lines (288 loc) · 10.8 KB
/
InvocationContext.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
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
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the MIT License.
import { CosmosDBInput, CosmosDBOutput } from './cosmosDB';
import { EventGridOutput, EventGridPartialEvent } from './eventGrid';
import { EventHubOutput } from './eventHub';
import { HttpOutput, HttpResponse } from './http';
import { FunctionInput, FunctionOutput, FunctionTrigger, LogLevel } from './index';
import { ServiceBusQueueOutput, ServiceBusTopicOutput } from './serviceBus';
import { SqlInput, SqlOutput } from './sql';
import { StorageBlobInput, StorageBlobOutput, StorageQueueOutput } from './storage';
import { TableInput, TableOutput } from './table';
/**
* Contains metadata and helper methods specific to this invocation
*/
export declare class InvocationContext {
/**
* For testing purposes only. This will always be constructed for you when run in the context of the Azure Functions runtime
*/
constructor(init?: InvocationContextInit);
/**
* A unique guid specific to this invocation
*/
invocationId: string;
/**
* The name of the function that is being invoked
*/
functionName: string;
/**
* An object used to get secondary inputs
*/
extraInputs: InvocationContextExtraInputs;
/**
* An object used to set secondary outputs
*/
extraOutputs: InvocationContextExtraOutputs;
/**
* The recommended way to log data during invocation.
* Similar to Node.js's `console.log`, but has integration with Azure features like application insights
* Uses the 'information' log level
*/
log(...args: any[]): void;
/**
* The recommended way to log trace data (level 0) during invocation.
* Similar to Node.js's `console.trace`, but has integration with Azure features like application insights
*/
trace(...args: any[]): void;
/**
* The recommended way to log debug data (level 1) during invocation.
* Similar to Node.js's `console.debug`, but has integration with Azure features like application insights
*/
debug(...args: any[]): void;
/**
* The recommended way to log information data (level 2) during invocation.
* Similar to Node.js's `console.info`, but has integration with Azure features like application insights
*/
info(...args: any[]): void;
/**
* The recommended way to log warning data (level 3) during invocation.
* Similar to Node.js's `console.warn`, but has integration with Azure features like application insights
*/
warn(...args: any[]): void;
/**
* The recommended way to log error data (level 4) during invocation.
* Similar to Node.js's `console.error`, but has integration with Azure features like application insights
*/
error(...args: any[]): void;
/**
* The retry context of the current function execution if the retry policy is defined
*/
retryContext?: RetryContext;
/**
* TraceContext information to enable distributed tracing scenarios
*/
traceContext?: TraceContext;
/**
* Metadata about the trigger or undefined if the metadata is already represented elsewhere
* For example, this will be undefined for http and timer triggers because you can find that information on the request & timer object instead
*/
triggerMetadata?: TriggerMetadata;
/**
* The options used when registering the function
* NOTE: This value may differ slightly from the original because it has been validated and defaults may have been explicitly added
*/
options: EffectiveFunctionOptions;
}
/**
* An object used to get secondary inputs
*/
export interface InvocationContextExtraInputs {
/**
* Get a secondary storage blob entry input for this invocation
* @input the configuration object for this storage blob input
*/
get(input: StorageBlobInput): unknown;
/**
* Get a secondary table input for this invocation
* @input the configuration object for this table input
*/
get(input: TableInput): unknown;
/**
* Get a secondary Cosmos DB documents input for this invocation
* @input the configuration object for this Cosmos DB input
*/
get(input: CosmosDBInput): unknown;
/**
* Get a secondary SQL items input for this invocation
* @input the configuration object for this SQL input
*/
get(input: SqlInput): unknown;
/**
* Get a secondary generic input for this invocation
* @inputOrName the configuration object or name for this input
*/
get(inputOrName: FunctionInput | string): unknown;
/**
* Set a secondary generic input for this invocation
* @inputOrName the configuration object or name for this input
* @value the input value
*/
set(inputOrName: FunctionInput | string, value: unknown): void;
}
/**
* An object used to set secondary outputs
*/
export interface InvocationContextExtraOutputs {
/**
* Set a secondary http response output for this invocation
* @output the configuration object for this http output
* @response the http response output value
*/
set(output: HttpOutput, response: HttpResponse): void;
/**
* Set a secondary storage blob entry output for this invocation
* @output the configuration object for this storage blob output
* @blob the blob output value
*/
set(output: StorageBlobOutput, blob: unknown): void;
/**
* Set a secondary table output for this invocation
* @output the configuration object for this table output
* @tableEntity the table output value
*/
set(output: TableOutput, tableEntity: unknown): void;
/**
* Set a secondary storage queue entry output for this invocation
* @output the configuration object for this storage queue output
* @queueItem the queue entry output value
*/
set(output: StorageQueueOutput, queueItem: unknown): void;
/**
* Set a secondary Cosmos DB documents output for this invocation
* @output the configuration object for this Cosmos DB output
* @documents the output document(s) value
*/
set(output: CosmosDBOutput, documents: unknown): void;
/**
* Set a secondary SQL items output for this invocation
* @output the configuration object for this SQL output
* @documents the output item(s) value
*/
set(output: SqlOutput, items: unknown): void;
/**
* Set a secondary Service Bus queue output for this invocation
* @output the configuration object for this Service Bus output
* @message the output message(s) value
*/
set(output: ServiceBusQueueOutput, messages: unknown): void;
/**
* Set a secondary Service Bus topic output for this invocation
* @output the configuration object for this Service Bus output
* @message the output message(s) value
*/
set(output: ServiceBusTopicOutput, messages: unknown): void;
/**
* Set a secondary Event Hub output for this invocation
* @output the configuration object for this EventHub output
* @message the output message(s) value
*/
set(output: EventHubOutput, messages: unknown): void;
/**
* Set a secondary Event Grid output for this invocation
* @output the configuration object for this Event Grid output
* @message the output event(s) value
*/
set(output: EventGridOutput, events: EventGridPartialEvent | EventGridPartialEvent[]): void;
/**
* Set a secondary generic output for this invocation
* @outputOrName the configuration object or name for this output
* @value the output value
*/
set(outputOrName: FunctionOutput | string, value: unknown): void;
/**
* Get a secondary generic output for this invocation
* @outputOrName the configuration object or name for this output
*/
get(outputOrName: FunctionOutput | string): unknown;
}
/**
* Metadata related to the input that triggered your function
*/
export type TriggerMetadata = Record<string, unknown>;
export interface RetryContext {
/**
* Current retry count of the function executions.
*/
retryCount: number;
/**
* Max retry count is the maximum number of times an execution is retried before eventual failure. A value of -1 means to retry indefinitely.
*/
maxRetryCount: number;
/**
* Exception that caused the retry
*/
exception?: Exception;
}
export interface Exception {
source?: string;
stackTrace?: string;
message?: 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 | undefined;
/**
* Extends traceparent with vendor-specific data
*/
traceState?: string | undefined;
/**
* Holds additional properties being sent as part of request telemetry
*/
attributes?: Record<string, string>;
}
/**
* The options used when registering the function, as passed to a specific invocation
* NOTE: This value may differ slightly from the original because it has been validated and defaults may have been explicitly added
*/
export interface EffectiveFunctionOptions {
/**
* Configuration for the primary input to the function, aka the reason it will be triggered
* This is the only input that is passed as an argument to the function handler during invocation
*/
trigger: FunctionTrigger;
/**
* Configuration for the optional primary output of the function
* This is the main output that you should set as the return value of the function handler during invocation
*/
return?: FunctionOutput;
/**
* Configuration for an optional set of secondary inputs
* During invocation, get these values with `context.extraInputs.get()`
*/
extraInputs: FunctionInput[];
/**
* Configuration for an optional set of secondary outputs
* During invocation, set these values with `context.extraOutputs.set()`
*/
extraOutputs: FunctionOutput[];
}
/**
* For testing purposes only. This will always be constructed for you when run in the context of the Azure Functions runtime
*/
export interface InvocationContextInit {
/**
* Defaults to 'unknown' if not specified
*/
invocationId?: string;
/**
* Defaults to 'unknown' if not specified
*/
functionName?: string;
/**
* Defaults to Node.js console if not specified
*/
logHandler?: LogHandler;
traceContext?: TraceContext;
retryContext?: RetryContext;
triggerMetadata?: TriggerMetadata;
/**
* Defaults to a trigger with 'unknown' type and name if not specified
*/
options?: Partial<EffectiveFunctionOptions>;
}
export type LogHandler = (level: LogLevel, ...args: unknown[]) => void;