@gregoriusrippenstein/node-red-contrib-introspection 0.15.8 → 0.15.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/nodes/60-client-code.html +26 -6
- package/nodes/60-client-code.js +18 -2
- package/package.json +1 -1
|
@@ -19,6 +19,9 @@ function handleClientCodeFrontend(event,data){if("execfunc"==data.msg){let doSen
|
|
|
19
19
|
format: {
|
|
20
20
|
value: "javascript"
|
|
21
21
|
},
|
|
22
|
+
removereqres: {
|
|
23
|
+
value: false
|
|
24
|
+
},
|
|
22
25
|
rules: {
|
|
23
26
|
value: [{ t: "default", p: "payload", pt: "msg", to: "", tot: "str" }]
|
|
24
27
|
}
|
|
@@ -117,7 +120,7 @@ function handleClientCodeFrontend(event,data){if("execfunc"==data.msg){let doSen
|
|
|
117
120
|
tabs.activateTab("client-code-tabs-code-editor");
|
|
118
121
|
|
|
119
122
|
|
|
120
|
-
$('#node-inpclientcode-defaults-container').css('
|
|
123
|
+
$('#node-inpclientcode-defaults-container').css('max-height', '70vh').css('min-width', '15vw').editableList({
|
|
121
124
|
addItem: function (container, i, opt) {
|
|
122
125
|
var rule = opt;
|
|
123
126
|
if (!rule.hasOwnProperty('t')) {
|
|
@@ -293,7 +296,7 @@ function handleClientCodeFrontend(event,data){if("execfunc"==data.msg){let doSen
|
|
|
293
296
|
}
|
|
294
297
|
|
|
295
298
|
// footer
|
|
296
|
-
height -=
|
|
299
|
+
height -= 42;
|
|
297
300
|
|
|
298
301
|
var editorRow = $("#dialog-form #client-code-tabs-code-editor>div.node-text-editor-row");
|
|
299
302
|
height -= (parseInt(editorRow.css("marginTop"))+parseInt(editorRow.css("marginBottom")));
|
|
@@ -375,7 +378,17 @@ function handleClientCodeFrontend(event,data){if("execfunc"==data.msg){let doSen
|
|
|
375
378
|
id="node-input-clientcode-editor" ></div>
|
|
376
379
|
</div>
|
|
377
380
|
|
|
378
|
-
<input type="hidden" id="node-input-clientcode" autofocus="autofocus">
|
|
381
|
+
<input type="hidden" id="node-input-clientcode" autofocus="autofocus"></input>
|
|
382
|
+
|
|
383
|
+
<div class="form-row">
|
|
384
|
+
<input type="checkbox" id="node-input-removereqres"
|
|
385
|
+
style="display:inline-block; width:35px; vertical-align:baseline;">
|
|
386
|
+
<label style="display: inline-block; width: 40%;"
|
|
387
|
+
for="node-input-removereqres">
|
|
388
|
+
<i class="fa fa-filter"></i>
|
|
389
|
+
<span>Remove <code>msg.res</code> and <code>msg.req</code>?</span>
|
|
390
|
+
</label>
|
|
391
|
+
</div>
|
|
379
392
|
</div>
|
|
380
393
|
|
|
381
394
|
</div>
|
|
@@ -420,7 +433,7 @@ Functionality:
|
|
|
420
433
|
over the code defined in the node itself.
|
|
421
434
|
|
|
422
435
|
<p>
|
|
423
|
-
Handling of Default Values
|
|
436
|
+
<b>Handling of Default Values</b>
|
|
424
437
|
<p>
|
|
425
438
|
Each default value can either be default, overwrite or fixed:
|
|
426
439
|
<li>
|
|
@@ -429,8 +442,15 @@ Functionality:
|
|
|
429
442
|
<ul><b>Fixed</b> - the default value is always used, ignoring whether the value is already set or not on the msg object. This is useful for constants or JSONata expressions - see loop counter below.</ul>
|
|
430
443
|
</li>
|
|
431
444
|
<p>
|
|
432
|
-
Loop counters using jsonata
|
|
445
|
+
<b>Loop counters using jsonata</b>
|
|
433
446
|
<p>
|
|
434
447
|
One usage of the default values is as an loop counter for messages going around and around. To define a loopcounter which is only defined on the msg object, define a default value <code>loopcounter</code> with the following JSONata code <code>$filter([$$.loopcounter,0,0], function ($v) { $exists($v) })[0] + 1</code> ($filter returns a single value if the array only contains one value else it returns an array).
|
|
435
|
-
|
|
448
|
+
|
|
449
|
+
<p>
|
|
450
|
+
<b>Remove msg.req and msg.res</b>
|
|
451
|
+
<p>
|
|
452
|
+
The <code>msg.req</code> and <code>msg.res</code> can cause <code>Converting circular structure to JSON</code> errors when the message is passed to the ClientCode node. To avoid this from happening, remove these attributes from the message before passing the message to the node.
|
|
453
|
+
<p>
|
|
454
|
+
<b>Node:</b> activating this implies that a http response following this ClientCode node will not work.
|
|
455
|
+
<p>
|
|
436
456
|
</script>
|
package/nodes/60-client-code.js
CHANGED
|
@@ -114,15 +114,24 @@ module.exports = function (RED) {
|
|
|
114
114
|
});
|
|
115
115
|
|
|
116
116
|
node.on("input", function (msg, send, done) {
|
|
117
|
+
// these cause an circular "Converting circular structure to JSON" error when
|
|
118
|
+
// encoding to JSON, so remove them before doing the JSONification.
|
|
119
|
+
if (cfg.removereqres) {
|
|
120
|
+
delete msg.req
|
|
121
|
+
delete msg.res
|
|
122
|
+
}
|
|
123
|
+
|
|
117
124
|
// msg object may cause problem if there are circular references, so
|
|
118
125
|
// do a pre-stringify before erroring out.
|
|
119
126
|
try {
|
|
120
127
|
JSON.stringify(msg)
|
|
121
128
|
} catch (e) {
|
|
129
|
+
// overwrite msg because calling node.error(..) will failure with the same error!!!
|
|
130
|
+
// worse still, it will fail silently and cause Node-RED to stop.
|
|
122
131
|
msg = `[Error in JSON.stringify(msg)]\n${e}\n[End Error]\n`
|
|
123
132
|
node.error(e)
|
|
124
133
|
}
|
|
125
|
-
|
|
134
|
+
|
|
126
135
|
let defaultValues = {}
|
|
127
136
|
|
|
128
137
|
let stupidLoop = (ruleIdx) => {
|
|
@@ -164,7 +173,14 @@ module.exports = function (RED) {
|
|
|
164
173
|
}
|
|
165
174
|
}
|
|
166
175
|
|
|
167
|
-
|
|
176
|
+
try {
|
|
177
|
+
stupidLoop(0)
|
|
178
|
+
} catch(e) {
|
|
179
|
+
// overwrite msg because calling node.error(..) will failure with the same error!!!
|
|
180
|
+
// worse still, it will fail silently and cause Node-RED to stop.
|
|
181
|
+
msg = `[Error in JSON.stringify(msg)]\n${e}\n[End Error]\n`
|
|
182
|
+
node.error(e)
|
|
183
|
+
}
|
|
168
184
|
});
|
|
169
185
|
}
|
|
170
186
|
|