@gregoriusrippenstein/node-red-contrib-introspection 0.15.7 → 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 +30 -7
- 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
|
@@ -11,16 +11,17 @@ module.exports = function (RED) {
|
|
|
11
11
|
|
|
12
12
|
function msgTracerOnReceiveHook(evnt) {
|
|
13
13
|
try {
|
|
14
|
-
let nde = RED.nodes.getNode(evnt.destination.id)
|
|
15
|
-
|
|
16
|
-
nde.status({ fill: "green", shape: "ring", text: "msg received" })
|
|
17
|
-
setTimeout(() => { nde.status({}) }, 1000)
|
|
18
|
-
|
|
19
14
|
RED.comms.publish("msgtracer:node-received",
|
|
20
15
|
RED.util.encodeObject({
|
|
21
16
|
nodeid: evnt.destination.id
|
|
22
17
|
})
|
|
23
18
|
)
|
|
19
|
+
|
|
20
|
+
let nde = RED.nodes.getNode(evnt.destination.id)
|
|
21
|
+
if (nde) {
|
|
22
|
+
nde.status({ fill: "green", shape: "ring", text: "msg received" })
|
|
23
|
+
setTimeout(() => { nde.status({}) }, 1000)
|
|
24
|
+
}
|
|
24
25
|
} catch (ex) {
|
|
25
26
|
console.error(ex)
|
|
26
27
|
}
|
|
@@ -30,6 +31,12 @@ module.exports = function (RED) {
|
|
|
30
31
|
try {
|
|
31
32
|
let nde = RED.nodes.getNode(evnt.destination.id)
|
|
32
33
|
|
|
34
|
+
if (!nde) {
|
|
35
|
+
console.log(`MsgTracer: ignoring event, node '${evnt.destination.id}' not found`)
|
|
36
|
+
console.log(evnt)
|
|
37
|
+
return
|
|
38
|
+
}
|
|
39
|
+
|
|
33
40
|
// don't publish debug messages for junctions because they
|
|
34
41
|
// cause errors in handleDebugMessages in the client.
|
|
35
42
|
if (nde.type == "junction") { return }
|
|
@@ -107,15 +114,24 @@ module.exports = function (RED) {
|
|
|
107
114
|
});
|
|
108
115
|
|
|
109
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
|
+
|
|
110
124
|
// msg object may cause problem if there are circular references, so
|
|
111
125
|
// do a pre-stringify before erroring out.
|
|
112
126
|
try {
|
|
113
127
|
JSON.stringify(msg)
|
|
114
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.
|
|
115
131
|
msg = `[Error in JSON.stringify(msg)]\n${e}\n[End Error]\n`
|
|
116
132
|
node.error(e)
|
|
117
133
|
}
|
|
118
|
-
|
|
134
|
+
|
|
119
135
|
let defaultValues = {}
|
|
120
136
|
|
|
121
137
|
let stupidLoop = (ruleIdx) => {
|
|
@@ -157,7 +173,14 @@ module.exports = function (RED) {
|
|
|
157
173
|
}
|
|
158
174
|
}
|
|
159
175
|
|
|
160
|
-
|
|
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
|
+
}
|
|
161
184
|
});
|
|
162
185
|
}
|
|
163
186
|
|