mirror of
https://github.com/node-red/node-red.git
synced 2023-10-10 13:36:53 +02:00
Merge pull request #4021 from node-red/inject-async-context
Allow Inject node to work with async context stores
This commit is contained in:
commit
055d0081e1
@ -95,19 +95,24 @@ module.exports = function(RED) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
this.on("input", function(msg, send, done) {
|
this.on("input", function(msg, send, done) {
|
||||||
var errors = [];
|
const errors = [];
|
||||||
var props = this.props;
|
let props = this.props;
|
||||||
if (msg.__user_inject_props__ && Array.isArray(msg.__user_inject_props__)) {
|
if (msg.__user_inject_props__ && Array.isArray(msg.__user_inject_props__)) {
|
||||||
props = msg.__user_inject_props__;
|
props = msg.__user_inject_props__;
|
||||||
}
|
}
|
||||||
delete msg.__user_inject_props__;
|
delete msg.__user_inject_props__;
|
||||||
props.forEach(p => {
|
props = [...props]
|
||||||
var property = p.p;
|
function evaluateProperty(doneEvaluating) {
|
||||||
var value = p.v ? p.v : '';
|
if (props.length === 0) {
|
||||||
var valueType = p.vt ? p.vt : 'str';
|
doneEvaluating()
|
||||||
|
return
|
||||||
if (!property) return;
|
}
|
||||||
|
const p = props.shift()
|
||||||
|
const property = p.p;
|
||||||
|
const value = p.v ? p.v : '';
|
||||||
|
const valueType = p.vt ? p.vt : 'str';
|
||||||
|
|
||||||
|
if (property) {
|
||||||
if (valueType === "jsonata") {
|
if (valueType === "jsonata") {
|
||||||
if (p.v) {
|
if (p.v) {
|
||||||
try {
|
try {
|
||||||
@ -119,21 +124,35 @@ module.exports = function(RED) {
|
|||||||
errors.push(err.message);
|
errors.push(err.message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return;
|
evaluateProperty(doneEvaluating)
|
||||||
}
|
} else {
|
||||||
try {
|
try {
|
||||||
RED.util.setMessageProperty(msg,property,RED.util.evaluateNodeProperty(value, valueType, this, msg),true);
|
RED.util.evaluateNodeProperty(value, valueType, node, msg, (err, newValue) => {
|
||||||
|
if (err) {
|
||||||
|
errors.push(err.toString())
|
||||||
|
} else {
|
||||||
|
RED.util.setMessageProperty(msg,property,newValue,true);
|
||||||
|
}
|
||||||
|
evaluateProperty(doneEvaluating)
|
||||||
|
})
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
errors.push(err.toString());
|
errors.push(err.toString());
|
||||||
|
evaluateProperty(doneEvaluating)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
evaluateProperty(doneEvaluating)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
|
||||||
|
|
||||||
|
evaluateProperty(() => {
|
||||||
if (errors.length) {
|
if (errors.length) {
|
||||||
done(errors.join('; '));
|
done(errors.join('; '));
|
||||||
} else {
|
} else {
|
||||||
send(msg);
|
send(msg);
|
||||||
done();
|
done();
|
||||||
}
|
}
|
||||||
|
})
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user