@gregoriusrippenstein/node-red-contrib-introspection 0.12.0 → 0.12.1
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.
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
[
|
|
2
|
+
{
|
|
3
|
+
"id": "94afd585fb41a438",
|
|
4
|
+
"type": "tab",
|
|
5
|
+
"label": "client code loop",
|
|
6
|
+
"disabled": false,
|
|
7
|
+
"info": "Using the client code default values feature, create a loop counter.\n\nCreating a max loop counter for loop through data or whatever.",
|
|
8
|
+
"env": []
|
|
9
|
+
},
|
|
10
|
+
{
|
|
11
|
+
"id": "e0c808876e8685bd",
|
|
12
|
+
"type": "ClientCode",
|
|
13
|
+
"z": "94afd585fb41a438",
|
|
14
|
+
"name": "",
|
|
15
|
+
"clientcode": "if (msg.MAXLOOP > msg.loopcounter) {\n node.send(msg)\n}",
|
|
16
|
+
"format": "javascript",
|
|
17
|
+
"rules": [
|
|
18
|
+
{
|
|
19
|
+
"t": "default",
|
|
20
|
+
"p": "MAXLOOP",
|
|
21
|
+
"pt": "msg",
|
|
22
|
+
"to": "12",
|
|
23
|
+
"tot": "num"
|
|
24
|
+
},
|
|
25
|
+
{
|
|
26
|
+
"t": "fixed",
|
|
27
|
+
"p": "loopcounter",
|
|
28
|
+
"pt": "msg",
|
|
29
|
+
"to": "$filter([$$.loopcounter,0,0], function ($v) { $exists($v) })[0] + 1",
|
|
30
|
+
"tot": "jsonata"
|
|
31
|
+
}
|
|
32
|
+
],
|
|
33
|
+
"x": 691,
|
|
34
|
+
"y": 357,
|
|
35
|
+
"wires": [
|
|
36
|
+
[
|
|
37
|
+
"893c3ec0bf9d100a",
|
|
38
|
+
"0fc98024bdd207cb"
|
|
39
|
+
]
|
|
40
|
+
]
|
|
41
|
+
},
|
|
42
|
+
{
|
|
43
|
+
"id": "523c5f1c268546ed",
|
|
44
|
+
"type": "inject",
|
|
45
|
+
"z": "94afd585fb41a438",
|
|
46
|
+
"name": "",
|
|
47
|
+
"props": [
|
|
48
|
+
{
|
|
49
|
+
"p": "MAXLOOP",
|
|
50
|
+
"v": "24",
|
|
51
|
+
"vt": "num"
|
|
52
|
+
},
|
|
53
|
+
{
|
|
54
|
+
"p": "topic",
|
|
55
|
+
"vt": "str"
|
|
56
|
+
}
|
|
57
|
+
],
|
|
58
|
+
"repeat": "",
|
|
59
|
+
"crontab": "",
|
|
60
|
+
"once": false,
|
|
61
|
+
"onceDelay": 0.1,
|
|
62
|
+
"topic": "",
|
|
63
|
+
"x": 513,
|
|
64
|
+
"y": 481,
|
|
65
|
+
"wires": [
|
|
66
|
+
[
|
|
67
|
+
"e0c808876e8685bd"
|
|
68
|
+
]
|
|
69
|
+
]
|
|
70
|
+
},
|
|
71
|
+
{
|
|
72
|
+
"id": "893c3ec0bf9d100a",
|
|
73
|
+
"type": "debug",
|
|
74
|
+
"z": "94afd585fb41a438",
|
|
75
|
+
"name": "debug 1",
|
|
76
|
+
"active": true,
|
|
77
|
+
"tosidebar": true,
|
|
78
|
+
"console": false,
|
|
79
|
+
"tostatus": false,
|
|
80
|
+
"complete": "true",
|
|
81
|
+
"targetType": "full",
|
|
82
|
+
"statusVal": "",
|
|
83
|
+
"statusType": "auto",
|
|
84
|
+
"x": 917,
|
|
85
|
+
"y": 273,
|
|
86
|
+
"wires": []
|
|
87
|
+
},
|
|
88
|
+
{
|
|
89
|
+
"id": "0fc98024bdd207cb",
|
|
90
|
+
"type": "delay",
|
|
91
|
+
"z": "94afd585fb41a438",
|
|
92
|
+
"name": "",
|
|
93
|
+
"pauseType": "delay",
|
|
94
|
+
"timeout": "500",
|
|
95
|
+
"timeoutUnits": "milliseconds",
|
|
96
|
+
"rate": "1",
|
|
97
|
+
"nbRateUnits": "1",
|
|
98
|
+
"rateUnits": "second",
|
|
99
|
+
"randomFirst": "1",
|
|
100
|
+
"randomLast": "5",
|
|
101
|
+
"randomUnits": "seconds",
|
|
102
|
+
"drop": false,
|
|
103
|
+
"allowrate": false,
|
|
104
|
+
"outputs": 1,
|
|
105
|
+
"x": 915,
|
|
106
|
+
"y": 358,
|
|
107
|
+
"wires": [
|
|
108
|
+
[
|
|
109
|
+
"e0c808876e8685bd"
|
|
110
|
+
]
|
|
111
|
+
]
|
|
112
|
+
}
|
|
113
|
+
]
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
function handleMsgTracePacket(e,r){if(r.nodeid){let a=RED.nodes.node(r.nodeid);if(a){var s,r=$("#node-input-msgtracer-trace-treelist").treeList("data");let t=!1;r.forEach(e=>{e.id==a.id&&(t=!0,e.seenCounter+=1,e.sublabel=e.seenCounter+" @ "+e.workspaceLabel)}),t?$("#node-input-msgtracer-trace-treelist").treeList("data",r):(s={id:a.id,label:"",_label:RED.utils.getNodeLabel(a),seenCounter:1,workspaceLabel:(RED.nodes.workspace(a.z)||{label:a.z}).label,sublabel:"1 @ "+(RED.nodes.workspace(a.z)||{label:a.z}).label,selected:!1,checkbox:!1,node:a,icon:RED.utils.createNodeIcon(a,!0)},$("#node-input-msgtracer-trace-treelist").treeList("data",[s,...r]))}}}RED.comms.subscribe("msgtracer:node-received",(e,t)=>{try{handleMsgTracePacket(e,t)}catch(e){console.error(e)}});
|
|
4
4
|
|
|
5
|
-
function handleClientCodeFrontend(event,data){if("execfunc"==data.msg){let doSend=(e,n,t)=>{"object"==typeof e&&(e={...t,...e}),$.ajax({url:"ClientCode/"+n,type:"POST",contentType:"application/json; charset=utf-8",data:JSON.stringify(e),success:function(e){},error:function(e,t,o){RED.notify("ClientCode Communcation Failure: "+n+": "+t,{type:"error",id:n,timeout:3e3})}})},doStatus=(e,n,t)=>{$.ajax({url:"ClientCode/"+n+"/status",type:"POST",contentType:"application/json; charset=utf-8",data:JSON.stringify(e),success:function(e){},error:function(e,t,o){RED.notify("ClientCode Communcation Failure: "+n+": "+t,{type:"error",id:n,timeout:3e3})}})},doError=(e,t,o)=>{RED.notify("ClientCode Failed: "+t+": "+e,{type:"error",id:t,timeout:3e3}),console.log("ClientCode: Error with node: "+t+": "+e)},nodeid=data.nodeid,_msg=data._msg,msg=data._msg??{},cfg=data._cfg,node=
|
|
5
|
+
function handleClientCodeFrontend(event,data){if("execfunc"==data.msg){let doSend=(e,n,t)=>{"object"==typeof e&&(e={...t,...e}),$.ajax({url:"ClientCode/"+n,type:"POST",contentType:"application/json; charset=utf-8",data:JSON.stringify(e),success:function(e){},error:function(e,t,o){RED.notify("ClientCode Communcation Failure: "+n+": "+t,{type:"error",id:n,timeout:3e3})}})},doStatus=(e,n,t)=>{$.ajax({url:"ClientCode/"+n+"/status",type:"POST",contentType:"application/json; charset=utf-8",data:JSON.stringify(e),success:function(e){},error:function(e,t,o){RED.notify("ClientCode Communcation Failure: "+n+": "+t,{type:"error",id:n,timeout:3e3})}})},doError=(e,t,o)=>{RED.notify("ClientCode Failed: "+t+": "+e,{type:"error",id:t,timeout:3e3}),console.log("ClientCode: Error with node: "+t+": "+e)},nodeid=data.nodeid,_msg=data._msg,msg=data._msg??{},cfg=data._cfg,node={id:data.nodeid,send:e=>{doSend(e,nodeid,_msg)},error:e=>{doError(e,nodeid,_msg)},status:e=>{doStatus(e,nodeid,_msg)}},payload=data.payload,topic=data.topic;eval(data.func)}}RED.comms.subscribe("introspect:client-code-perform",(e,t)=>{try{handleClientCodeFrontend(e,t)}catch(e){console.error(e)}});
|
|
6
6
|
|
|
7
7
|
RED.nodes.registerType('ClientCode',{
|
|
8
8
|
color: '#e5e4ef',
|
|
@@ -137,6 +137,7 @@ function handleClientCodeFrontend(event,data){if("execfunc"==data.msg){let doSen
|
|
|
137
137
|
var selectOptions = [
|
|
138
138
|
{ v: "default" },
|
|
139
139
|
{ v: "overwrite" },
|
|
140
|
+
{ v: "fixed" },
|
|
140
141
|
];
|
|
141
142
|
for (var i = 0; i < selectOptions.length; i++) {
|
|
142
143
|
let label = node._("clientcode.action." + (selectOptions[i].l || selectOptions[i].v))
|
|
@@ -417,4 +418,19 @@ Functionality:
|
|
|
417
418
|
The code to be executed by the client can also be passed in via the `msg` object using the
|
|
418
419
|
`clientcode` attribute on the `msg` object. If this attribute is set, it will take precendence
|
|
419
420
|
over the code defined in the node itself.
|
|
421
|
+
|
|
422
|
+
<p>
|
|
423
|
+
Handling of Default Values
|
|
424
|
+
<p>
|
|
425
|
+
Each default value can either be default, overwrite or fixed:
|
|
426
|
+
<li>
|
|
427
|
+
<ul><b>Default</b> - value is set on the message if value isn't set on the msg object already. Else the msg value is used.</ul>
|
|
428
|
+
<ul><b>Overwrite</b> - default value overwrites the existing value on the message. If the property does not exist on the message, then the default value is ignored. A default value will only overwrite if the value is already defined on the msg object.</ul>
|
|
429
|
+
<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
|
+
</li>
|
|
431
|
+
<p>
|
|
432
|
+
Loop counters using jsonata
|
|
433
|
+
<p>
|
|
434
|
+
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
|
+
|
|
420
436
|
</script>
|
package/nodes/60-client-code.js
CHANGED
|
@@ -116,7 +116,6 @@ module.exports = function (RED) {
|
|
|
116
116
|
}
|
|
117
117
|
|
|
118
118
|
let defaultValues = {}
|
|
119
|
-
let operationDefValue = {}
|
|
120
119
|
|
|
121
120
|
let stupidLoop = (ruleIdx) => {
|
|
122
121
|
if ( ruleIdx >= (cfg.rules || []).length) {
|
|
@@ -129,8 +128,7 @@ module.exports = function (RED) {
|
|
|
129
128
|
func: msg.clientcode || cfg.clientcode,
|
|
130
129
|
nodeid: node.id,
|
|
131
130
|
_msg: msg,
|
|
132
|
-
_cfg: defaultValues
|
|
133
|
-
_ops: operationDefValue
|
|
131
|
+
_cfg: defaultValues
|
|
134
132
|
})
|
|
135
133
|
);
|
|
136
134
|
done()
|
|
@@ -138,9 +136,17 @@ module.exports = function (RED) {
|
|
|
138
136
|
try {
|
|
139
137
|
let rule = cfg.rules[ruleIdx]
|
|
140
138
|
let name = rule.p
|
|
139
|
+
|
|
141
140
|
getToValue(msg, rule, (err, value) => {
|
|
142
141
|
defaultValues[name] = value
|
|
143
|
-
|
|
142
|
+
if ( rule.t == "fixed" ) {
|
|
143
|
+
msg[name] = value
|
|
144
|
+
} else if (rule.t == "default") {
|
|
145
|
+
msg[name] = msg[name] ?? value
|
|
146
|
+
} else if (rule.t == "overwrite" && msg.hasOwnProperty(name)) {
|
|
147
|
+
msg[name] = value ?? msg[name]
|
|
148
|
+
}
|
|
149
|
+
|
|
144
150
|
stupidLoop(ruleIdx+1)
|
|
145
151
|
})
|
|
146
152
|
} catch (e) {
|