@rosepetal/node-red-contrib-utils 1.1.2 → 1.1.3

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.
@@ -102,8 +102,7 @@ module.exports = function registerCleanDebugNode(RED) {
102
102
  return;
103
103
  }
104
104
 
105
- const format = detectValueType(value);
106
- const debugMessage = {
105
+ var debugMessage = {
107
106
  id: node.id,
108
107
  z: node.z,
109
108
  _alias: node._alias,
@@ -112,13 +111,45 @@ module.exports = function registerCleanDebugNode(RED) {
112
111
  property: node.targetType === "full" ? "msg" : node.complete,
113
112
  propertyType: node.targetType,
114
113
  clean: node.clean,
115
- format,
116
114
  msg: value,
117
115
  _msgid: msg && msg._msgid
118
116
  };
119
117
 
118
+ encodeDebugValue(debugMessage);
119
+
120
120
  RED.comms.publish("debug", debugMessage);
121
121
  }
122
+
123
+ /**
124
+ * Encode debugMsg.msg and set debugMsg.format in-place so the value
125
+ * matches the format expected by Node-RED's debug-utils.js in the editor.
126
+ * RED.util.encodeObject expects the whole debug message object — it reads
127
+ * from debugMsg.msg and sets debugMsg.msg + debugMsg.format in-place.
128
+ * @param {object} debugMsg
129
+ */
130
+ function encodeDebugValue(debugMsg) {
131
+ var value = debugMsg.msg;
132
+ if (value === null || typeof value === "undefined") {
133
+ debugMsg.format = (value === null) ? "null" : "undefined";
134
+ debugMsg.msg = (value === null) ? "null" : "(undefined)";
135
+ } else if (typeof value === "object") {
136
+ try {
137
+ RED.util.encodeObject(debugMsg, { maxLength: DEFAULT_DEBUG_MAX_LENGTH });
138
+ } catch (_e) {
139
+ debugMsg.format = "error";
140
+ debugMsg.msg = "Failed to encode debug value";
141
+ }
142
+ } else if (typeof value === "boolean") {
143
+ debugMsg.format = "boolean";
144
+ debugMsg.msg = value.toString();
145
+ } else if (typeof value === "number") {
146
+ debugMsg.format = "number";
147
+ debugMsg.msg = value.toString();
148
+ } else {
149
+ debugMsg.format = "string[" + ("" + value).length + "]";
150
+ debugMsg.msg = "" + value;
151
+ }
152
+ }
122
153
  }
123
154
 
124
155
  /**
@@ -330,30 +361,6 @@ module.exports = function registerCleanDebugNode(RED) {
330
361
  return `[${type} withheld: ${detail}]`;
331
362
  }
332
363
 
333
- /**
334
- * Detect broad value type to help the editor render icons.
335
- * @param {*} value
336
- */
337
- function detectValueType(value) {
338
- if (value === null) {
339
- return "null";
340
- }
341
- if (value && typeof value === "object" && value.type === "Buffer" && Array.isArray(value.data)) {
342
- return "buffer";
343
- }
344
- const t = typeof value;
345
- if (t === "string" || t === "number" || t === "boolean" || t === "bigint") {
346
- return t;
347
- }
348
- if (Array.isArray(value)) {
349
- return "array";
350
- }
351
- if (value instanceof Date) {
352
- return "date";
353
- }
354
- return "object";
355
- }
356
-
357
364
  /**
358
365
  * Format for console/log output.
359
366
  * @param {*} value
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rosepetal/node-red-contrib-utils",
3
- "version": "1.1.2",
3
+ "version": "1.1.3",
4
4
  "description": "Utility and I/O nodes for Node-RED, including array helpers and file saving.",
5
5
  "scripts": {
6
6
  "test": "echo \"Error: no test specified\" && exit 1"