22 * Interface for your Azure Function code. This function must be exported (via module.exports or exports)
33 * and will execute when triggered. It is recommended that you declare this function as async, which
44 * implicitly returns a Promise.
5- * @param context IContext object passed to your function from the Azure Functions runtime.
5+ * @param context Context object passed to your function from the Azure Functions runtime.
66 * @param {any[] } args Optional array of input and trigger binding data. These binding data are passed to the
7- * function in the same order that they are defined in function.json.
8- * @returns Output bindings (optional).
7+ * function in the same order that they are defined in function.json. Valid input types are string, HttpRequest,
8+ * and Buffer.
9+ * @returns Output bindings (optional). If you are returning a result from a Promise (or an async function), this
10+ * result will be passed to JSON.stringify unless it is a string, Buffer, ArrayBufferView, or number.
911 */
10- export interface IFunction {
11- ( context : IContext , ...args : any [ ] ) : Promise < any > | void ;
12- }
12+ export type AzureFunction = ( ( context : Context , ...args : any [ ] ) => Promise < any > | void ) ;
1313
1414/**
1515 * The context object can be used for writing logs, reading data from bindings, setting outputs and using
1616 * the context.done callback when your exported function is synchronous. A context object is passed
1717 * to your function from the Azure Functions runtime on function invocation.
1818 */
19- export interface IContext {
19+ export interface Context {
2020 /**
2121 * A unique GUID per function invocation.
2222 */
2323 invocationId : string ;
2424 /**
2525 * Function execution metadata.
2626 */
27- executionContext : IExecutionContext ;
27+ executionContext : ExecutionContext ;
2828 /**
2929 * Input and trigger binding data, as defined in function.json. Properties on this object are dynamically
3030 * generated and named based off of the "name" property in function.json.
@@ -37,24 +37,26 @@ export interface IContext {
3737 /**
3838 * Bindings your function uses, as defined in function.json.
3939 */
40- bindingDefinitions : IBindingDefinition [ ] ;
40+ bindingDefinitions : BindingDefinition [ ] ;
4141 /**
42- * Calling directly allows you to write streaming function logs at the default trace level.
42+ * Allows you to write streaming function logs. Calling directly allows you to write streaming function logs
43+ * at the default trace level.
4344 */
44- log : ILogger ;
45+ log : Logger ;
4546 /**
4647 * A callback function that signals to the runtime that your code has completed. If your function is synchronous,
4748 * you must call context.done at the end of execution. If your function is asynchronous, you should not use this
4849 * callback.
4950 *
5051 * @param err A user-defined error to pass back to the runtime. If present, your function execution will fail.
51- * @param result An object containing output binding data.
52+ * @param result An object containing output binding data. `result` will be passed to JSON.stringify unless it is
53+ * a string, Buffer, ArrayBufferView, or number.
5254 */
53- done : IDoneCallback ;
55+ done ( err ?: Error | string , result ?: any ) : void ;
5456 /**
5557 * HTTP request object. Provided to your function when using HTTP Bindings.
5658 */
57- req ?: IRequest ;
59+ req ?: HttpRequest ;
5860 /**
5961 * HTTP response object. Provided to your function when using HTTP Bindings.
6062 */
@@ -64,7 +66,7 @@ export interface IContext {
6466/**
6567 * HTTP request object. Provided to your function when using HTTP Bindings.
6668 */
67- export interface IRequest {
69+ export interface HttpRequest {
6870 /**
6971 * HTTP request method used to invoke this function.
7072 */
@@ -86,16 +88,16 @@ export interface IRequest {
8688 */
8789 params : { [ key :string ] : string } ;
8890 /**
89- * The HTTP request body
91+ * The HTTP request body.
9092 */
9193 body ?: any ;
9294 /**
93- * The HTTP request body as a UTF-8 string
95+ * The HTTP request body as a UTF-8 string.
9496 */
9597 rawbody ?: any ;
9698}
9799
98- export interface IExecutionContext {
100+ export interface ExecutionContext {
99101 /**
100102 * A unique GUID per function invocation.
101103 */
@@ -111,7 +113,7 @@ export interface IExecutionContext {
111113 functionDirectory : string ;
112114}
113115
114- export interface IBindingDefinition {
116+ export interface BindingDefinition {
115117 /**
116118 * The name of your binding, as defined in function.json.
117119 */
@@ -121,37 +123,33 @@ export interface IBindingDefinition {
121123 */
122124 type : string ,
123125 /**
124- * The direction of your binding ('in', 'out', or 'inout') , as defined in function.json.
126+ * The direction of your binding, as defined in function.json.
125127 */
126- direction : string
128+ direction : 'in' | 'out' | 'inout' | undefined ;
127129}
128130
129- export interface ILog {
130- ( ...args : any [ ] ) : void ;
131- }
132-
133131/**
134132 * Allows you to write streaming function logs.
135133 */
136- export interface ILogger extends ILog {
134+ export interface Logger {
135+ /**
136+ * Writes streaming function logs at the default trace level.
137+ */
138+ ( ...args : any [ ] ) : void ;
137139 /**
138140 * Writes to error level logging or lower.
139141 */
140- error : ILog ;
142+ error ( ... args : any [ ] ) : void ;
141143 /**
142144 * Writes to warning level logging or lower.
143145 */
144- warn : ILog ;
146+ warn ( ... args : any [ ] ) : void ;
145147 /**
146148 * Writes to info level logging or lower.
147149 */
148- info : ILog ;
150+ info ( ... args : any [ ] ) : void ;
149151 /**
150152 * Writes to verbose level logging.
151153 */
152- verbose : ILog ;
154+ verbose ( ... args : any [ ] ) : void ;
153155}
154-
155- export interface IDoneCallback {
156- ( err ?: any , result ?: any ) : void ;
157- }
0 commit comments