Skip to content

Commit 648a372

Browse files
authored
Fix return output binding logic (#264)
* updates to make 2.0 worker 1.0 compatible * split validation logic so it's both v1 and v2 compatible * hard-coded solution to camelCase timer trigger while proper fix is out of scope for timeline * added test * adding unit test * properly convert data when defined as output array * testing both v1 behavior and v2 behavior * dont code without intellisense * remove e2e test until have better test on functions host v2 and v3 * fix worker validation logic and warning message on ts changes * add tests
1 parent cbb1270 commit 648a372

File tree

3 files changed

+245
-77
lines changed

3 files changed

+245
-77
lines changed

scripts/generateProtos.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,9 @@ async function generateProtos() {
2222
.catch(err => console.log(`Could not compile to JavaScript: ${err}`));
2323

2424
// Don't generate with Node.js v12 until resolved: https://github.com/protobufjs/protobuf.js/issues/1275
25-
if (!process.version.startsWith("v12")) {
25+
if (process.version.startsWith("v12") && process.platform === 'win32') {
26+
console.warn("Warning! Could not compile to TypeScript for Node.js 12 and Windows OS. Do not change public interfaces.");
27+
} else {
2628
genTs(allFiles)
2729
.then(data => console.log("Compiled to TypeScript."))
2830
.catch(err => console.log(`Could not compile to TypeScript: ${err}`));

src/WorkerChannel.ts

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -99,13 +99,11 @@ export class WorkerChannel implements IWorkerChannel {
9999
// Validate version
100100
let version = process.version;
101101
if (this._v1WorkerBehavior) {
102-
if (version.startsWith("v12."))
103-
{
102+
if (version.startsWith("v12.")) {
104103
systemWarn("The Node.js version you are using (" + version + ") is not fully supported with Azure Functions V2. We recommend using one the following major versions: 8, 10.");
105104
}
106105
} else {
107-
if (version.startsWith("v8."))
108-
{
106+
if (version.startsWith("v8.")) {
109107
let msg = "Incompatible Node.js version. The version you are using (" + version + ") is not supported with Azure Functions V3. Please use one of the following major versions: 10, 12.";
110108
systemError(msg);
111109
throw msg;
@@ -192,10 +190,22 @@ export class WorkerChannel implements IWorkerChannel {
192190
response.returnValue = toTypedData(result.return);
193191
} else {
194192
let returnBinding = info.getReturnBinding();
195-
response.returnValue = returnBinding ? returnBinding.converter(result.return) : toTypedData(result.return);
193+
// $return binding is found: return result data to $return binding
194+
if (returnBinding) {
195+
response.returnValue = returnBinding.converter(result.return);
196+
// $return binding is not found: read result as object of outputs
197+
} else if (result.return) {
198+
response.outputData = Object.keys(info.outputBindings)
199+
.filter(key => result.return[key] !== undefined)
200+
.map(key => <rpc.IParameterBinding>{
201+
name: key,
202+
data: info.outputBindings[key].converter(result.return[key])
203+
});
204+
}
196205
}
197206
}
198-
if (result.bindings) {
207+
// Data from return supersedes data from context.bindings
208+
if (result.bindings && !response.outputData) {
199209
response.outputData = Object.keys(info.outputBindings)
200210
.filter(key => result.bindings[key] !== undefined)
201211
.map(key => <rpc.IParameterBinding>{
@@ -207,7 +217,6 @@ export class WorkerChannel implements IWorkerChannel {
207217
} catch (e) {
208218
response.result = this.getStatus(e)
209219
}
210-
211220
this._eventStream.write({
212221
requestId: requestId,
213222
invocationResponse: response

0 commit comments

Comments
 (0)