mirror of
https://github.com/node-red/node-red.git
synced 2025-03-01 10:36:34 +00:00
Merge branch 'dev' into pr_2439
This commit is contained in:
56
packages/node_modules/@node-red/util/lib/util.js
vendored
56
packages/node_modules/@node-red/util/lib/util.js
vendored
@@ -19,9 +19,9 @@
|
||||
* @mixin @node-red/util_util
|
||||
*/
|
||||
|
||||
|
||||
const clone = require("clone");
|
||||
const clonedeep = require("lodash.clonedeep");
|
||||
const jsonata = require("jsonata");
|
||||
const moment = require("moment-timezone");
|
||||
const safeJSONStringify = require("json-stringify-safe");
|
||||
const util = require("util");
|
||||
|
||||
@@ -81,22 +81,25 @@ function ensureBuffer(o) {
|
||||
* @memberof @node-red/util_util
|
||||
*/
|
||||
function cloneMessage(msg) {
|
||||
// Temporary fix for #97
|
||||
// TODO: remove this http-node-specific fix somehow
|
||||
var req = msg.req;
|
||||
var res = msg.res;
|
||||
delete msg.req;
|
||||
delete msg.res;
|
||||
var m = clone(msg);
|
||||
if (req) {
|
||||
m.req = req;
|
||||
msg.req = req;
|
||||
if (typeof msg !== "undefined" && msg !== null) {
|
||||
// Temporary fix for #97
|
||||
// TODO: remove this http-node-specific fix somehow
|
||||
var req = msg.req;
|
||||
var res = msg.res;
|
||||
delete msg.req;
|
||||
delete msg.res;
|
||||
var m = clonedeep(msg);
|
||||
if (req) {
|
||||
m.req = req;
|
||||
msg.req = req;
|
||||
}
|
||||
if (res) {
|
||||
m.res = res;
|
||||
msg.res = res;
|
||||
}
|
||||
return m;
|
||||
}
|
||||
if (res) {
|
||||
m.res = res;
|
||||
msg.res = res;
|
||||
}
|
||||
return m;
|
||||
return msg;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -566,16 +569,23 @@ function evaluateNodeProperty(value, type, node, msg, callback) {
|
||||
*/
|
||||
function prepareJSONataExpression(value,node) {
|
||||
var expr = jsonata(value);
|
||||
expr.assign('flowContext',function(val) {
|
||||
return node.context().flow.get(val);
|
||||
expr.assign('flowContext', function(val, store) {
|
||||
return node.context().flow.get(val, store);
|
||||
});
|
||||
expr.assign('globalContext',function(val) {
|
||||
return node.context().global.get(val);
|
||||
expr.assign('globalContext', function(val, store) {
|
||||
return node.context().global.get(val, store);
|
||||
});
|
||||
expr.assign('env', function(name) {
|
||||
var val = getSetting(node, name);
|
||||
return (val ? val : "");
|
||||
})
|
||||
if (typeof val !== 'undefined') {
|
||||
return val;
|
||||
} else {
|
||||
return "";
|
||||
}
|
||||
});
|
||||
expr.assign('moment', function(arg1, arg2, arg3, arg4) {
|
||||
return moment(arg1, arg2, arg3, arg4);
|
||||
});
|
||||
expr.registerFunction('clone', cloneMessage, '<(oa)-:o>');
|
||||
expr._legacyMode = /(^|[^a-zA-Z0-9_'"])msg([^a-zA-Z0-9_'"]|$)/.test(value);
|
||||
expr._node = node;
|
||||
|
Reference in New Issue
Block a user