diff --git a/red/runtime/util.js b/red/runtime/util.js index e5aa2b4ab..0a99eecee 100644 --- a/red/runtime/util.js +++ b/red/runtime/util.js @@ -408,9 +408,9 @@ function evaluateJSONataExpression(expr,msg,callback) { if (callback) { // If callback provided, need to override the pre-assigned sync // context functions to be their async variants - bindings.flowContext = function(val) { + bindings.flowContext = function(val, store) { return new Promise((resolve,reject) => { - expr._node.context().flow.get(val, function(err,value) { + expr._node.context().flow.get(val, store, function(err,value) { if (err) { reject(err); } else { @@ -419,9 +419,9 @@ function evaluateJSONataExpression(expr,msg,callback) { }) }); } - bindings.globalContext = function(val) { + bindings.globalContext = function(val, store) { return new Promise((resolve,reject) => { - expr._node.context().global.get(val, function(err,value) { + expr._node.context().global.get(val, store, function(err,value) { if (err) { reject(err); } else { diff --git a/test/red/runtime/util_spec.js b/test/red/runtime/util_spec.js index 1be194f42..02c704411 100644 --- a/test/red/runtime/util_spec.js +++ b/test/red/runtime/util_spec.js @@ -459,7 +459,7 @@ describe("red/util", function() { should.not.exist(result); }); it('handles async flow context access', function(done) { - var expr = util.prepareJSONataExpression('$flowContext("foo")',{context:function() { return {flow:{get: function(key,callback) { setTimeout(()=>{callback(null,{'foo':'bar'}[key])},10)}}}}}); + var expr = util.prepareJSONataExpression('$flowContext("foo")',{context:function() { return {flow:{get: function(key,store,callback) { setTimeout(()=>{callback(null,{'foo':'bar'}[key])},10)}}}}}); util.evaluateJSONataExpression(expr,{payload:"hello"},function(err,value) { try { should.not.exist(err); @@ -471,7 +471,7 @@ describe("red/util", function() { }); }) it('handles async global context access', function(done) { - var expr = util.prepareJSONataExpression('$globalContext("foo")',{context:function() { return {global:{get: function(key,callback) { setTimeout(()=>{callback(null,{'foo':'bar'}[key])},10)}}}}}); + var expr = util.prepareJSONataExpression('$globalContext("foo")',{context:function() { return {global:{get: function(key,store,callback) { setTimeout(()=>{callback(null,{'foo':'bar'}[key])},10)}}}}}); util.evaluateJSONataExpression(expr,{payload:"hello"},function(err,value) { try { should.not.exist(err); @@ -482,6 +482,34 @@ describe("red/util", function() { } }); }) + it('handles persistable store in flow context access', function(done) { + var storeName; + var expr = util.prepareJSONataExpression('$flowContext("foo", "flowStoreName")',{context:function() { return {flow:{get: function(key,store,callback) { storeName = store;setTimeout(()=>{callback(null,{'foo':'bar'}[key])},10)}}}}}); + util.evaluateJSONataExpression(expr,{payload:"hello"},function(err,value) { + try { + should.not.exist(err); + value.should.eql("bar"); + storeName.should.equal("flowStoreName"); + done(); + } catch(err2) { + done(err2); + } + }); + }) + it('handles persistable store in global context access', function(done) { + var storeName; + var expr = util.prepareJSONataExpression('$globalContext("foo", "globalStoreName")',{context:function() { return {global:{get: function(key,store,callback) { storeName = store;setTimeout(()=>{callback(null,{'foo':'bar'}[key])},10)}}}}}); + util.evaluateJSONataExpression(expr,{payload:"hello"},function(err,value) { + try { + should.not.exist(err); + value.should.eql("bar"); + storeName.should.equal("globalStoreName"); + done(); + } catch(err2) { + done(err2); + } + }); + }) });