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; var legacyMode = false;
try { try {
expr = jsonata(currentExpression); expr = jsonata(currentExpression);
expr.assign('flow',function(val) { expr.assign('flowContext',function(val) {
usesContext = true; usesContext = true;
return null; return null;
}); });
expr.assign('global',function(val) { expr.assign('globalContext',function(val) {
usesContext = true; usesContext = true;
return null; return null;
}); });
legacyMode = /(^|[^a-zA-Z0-9_'"])msg([^a-zA-Z0-9_'"]|$)/.test(currentExpression); legacyMode = /(^|[^a-zA-Z0-9_'"])msg([^a-zA-Z0-9_'"]|$)/.test(currentExpression);
} catch(err) { } catch(err) {
testResultEditor.setValue("Invalid jsonata expression:\n "+err.message); testResultEditor.setValue(RED._("expressionEditor.errors.invalid-expr",{message:err.message}));
return; return;
} }
$(".node-input-expression-legacy").toggle(legacyMode); $(".node-input-expression-legacy").toggle(legacyMode);
try { try {
parsedData = JSON.parse(value); parsedData = JSON.parse(value);
} catch(err) { } catch(err) {
testResultEditor.setValue("Invalid example message:\n "+err.toString()) testResultEditor.setValue(RED._("expressionEditor.errors.invalid-msg",{message:err.toString()}))
return; return;
} }
try { try {
var result = expr.evaluate(legacyMode?{msg:parsedData}:parsedData); var result = expr.evaluate(legacyMode?{msg:parsedData}:parsedData);
if (usesContext) { if (usesContext) {
testResultEditor.setValue("Cannot test a function that uses context values"); testResultEditor.setValue(RED._("expressionEditor.errors.context-unsupported"));
return; 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) { } 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", "result": "Result",
"format": "format expression", "format": "format expression",
"compatMode": "Compatibility mode enabled", "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": { "jsonEditor": {
"title": "JSON editor", "title": "JSON editor",