1
0
mirror of https://github.com/node-red/node-red.git synced 2023-10-10 13:36:53 +02:00

NLS jsonata test messages

This commit is contained in:
Nick O'Leary 2017-05-05 13:43:18 +01:00
parent 6e8c978d12
commit 6b07f58e8e
No known key found for this signature in database
GPG Key ID: 4F2157149161A6C9
2 changed files with 22 additions and 9 deletions

View File

@ -1791,37 +1791,43 @@ RED.editor = (function() {
var legacyMode = false;
try {
expr = jsonata(currentExpression);
expr.assign('flow',function(val) {
expr.assign('flowContext',function(val) {
usesContext = true;
return null;
});
expr.assign('global',function(val) {
expr.assign('globalContext',function(val) {
usesContext = true;
return null;
});
legacyMode = /(^|[^a-zA-Z0-9_'"])msg([^a-zA-Z0-9_'"]|$)/.test(currentExpression);
} catch(err) {
testResultEditor.setValue("Invalid jsonata expression:\n "+err.message);
testResultEditor.setValue(RED._("expressionEditor.errors.invalid-expr",{message:err.message}));
return;
}
$(".node-input-expression-legacy").toggle(legacyMode);
try {
parsedData = JSON.parse(value);
} catch(err) {
testResultEditor.setValue("Invalid example message:\n "+err.toString())
testResultEditor.setValue(RED._("expressionEditor.errors.invalid-msg",{message:err.toString()}))
return;
}
try {
var result = expr.evaluate(legacyMode?{msg:parsedData}:parsedData);
if (usesContext) {
testResultEditor.setValue("Cannot test a function that uses context values");
testResultEditor.setValue(RED._("expressionEditor.errors.context-unsupported"));
return;
}
var formattedResult = JSON.stringify(result,null,4);
testResultEditor.setValue(formattedResult || "No match");
var formattedResult;
if (result !== undefined) {
formattedResult = JSON.stringify(result,null,4);
} else {
formattedResult = RED._("expressionEditor.noMatch");
}
testResultEditor.setValue(formattedResult);
} catch(err) {
testResultEditor.setValue("Error evaluating expression:\n "+err.message);
testResultEditor.setValue(RED._("expressionEditor.errors.eval",{message:err.message}));
}
}

View File

@ -403,7 +403,14 @@
"result": "Result",
"format": "format expression",
"compatMode": "Compatibility mode enabled",
"compatModeDesc": "<h3>JSONata compatibility mode</h3><p> The current expression appears to still reference <code>msg</code> so will be evaluated in compatibility mode. Please update the expression to not use <code>msg</code> as this mode will be removed in the future.</p><p> When JSONata support was first added to Node-RED, it required the expression to reference the <code>msg</code> object. For example <code>msg.payload</code> would be used to access the payload.</p><p> That is no longer necessary as the expression will be evaluated against the message directly. To access the payload, the expression should be just <code>payload</code>.</p>"
"compatModeDesc": "<h3>JSONata compatibility mode</h3><p> The current expression appears to still reference <code>msg</code> so will be evaluated in compatibility mode. Please update the expression to not use <code>msg</code> as this mode will be removed in the future.</p><p> When JSONata support was first added to Node-RED, it required the expression to reference the <code>msg</code> object. For example <code>msg.payload</code> would be used to access the payload.</p><p> That is no longer necessary as the expression will be evaluated against the message directly. To access the payload, the expression should be just <code>payload</code>.</p>",
"noMatch": "No matching result",
"errors": {
"invalid-expr": "Invalid JSONata expression:\n __message__",
"invalid-msg": "Invalid example JSON message:\n __message__",
"context-unsupported": "Cannot test context functions\n $flowContext or $globalContext",
"eval": "Error evaluating expression:\n __message__"
}
},
"jsonEditor": {
"title": "JSON editor",