forked from Azure/azure-functions-nodejs-worker
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathFunctionInfo.ts
48 lines (42 loc) · 1.67 KB
/
FunctionInfo.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
import { AzureFunctionsRpcMessages as rpc } from '../azure-functions-language-worker-protobuf/src/rpc';
import { toTypedData, toRpcHttp } from './converters';
const returnBindingKey = "$return";
export class FunctionInfo {
public name: string;
public directory: string;
public bindings: {
[key: string]: rpc.IBindingInfo
};
public outputBindings: {
[key: string]: rpc.IBindingInfo & { converter: (any) => rpc.ITypedData }
};
public httpOutputName: string;
constructor(metadata: rpc.IRpcFunctionMetadata) {
this.name = <string>metadata.name;
this.directory = <string>metadata.directory;
this.bindings = {};
this.outputBindings = {};
this.httpOutputName = "";
if (metadata.bindings) {
let bindings = this.bindings = metadata.bindings;
// determine output bindings & assign rpc converter (http has quirks)
Object.keys(bindings)
.filter(name => bindings[name].direction !== rpc.BindingInfo.Direction.in)
.forEach(name => {
if (bindings[name].type === 'http') {
this.httpOutputName = name;
this.outputBindings[name] = Object.assign(bindings[name], { converter: toRpcHttp });
} else {
this.outputBindings[name] = Object.assign(bindings[name], { converter: toTypedData });
}
});
}
}
/**
* Return output binding details on the special key "$return" output binding
* Will be used in the future to address bugfix with breaking change: https://github.com/Azure/azure-functions-nodejs-worker/issues/228
*/
public getReturnBinding() {
return this.outputBindings[returnBindingKey];
}
}