node-red-contrib-uos-nats 0.2.4 → 0.2.6
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/README.md +5 -0
- package/lib/payloads.js +29 -3
- package/nodes/datahub-input.html +1 -1
- package/nodes/datahub-output.html +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -37,6 +37,11 @@ Restart Node-RED. The nodes appear in the **"u-OS DataHub NATS"** category in th
|
|
|
37
37
|
|
|
38
38
|
---
|
|
39
39
|
|
|
40
|
+
## What's New in v0.2.6 (Critical Fixes)
|
|
41
|
+
- **FIXED:** `Snapshot failed: ts.value is not a function` error in Read node.
|
|
42
|
+
- **FIXED:** Invalid timestamp encoding in Provider node (Seconds/Nanoseconds mismatch).
|
|
43
|
+
- **FIXED:** Label and Category logic for all nodes.
|
|
44
|
+
|
|
40
45
|
## What's New in v0.2.0
|
|
41
46
|
|
|
42
47
|
### 🎯 Variable Key Support
|
package/lib/payloads.js
CHANGED
|
@@ -218,7 +218,14 @@ function encodeVariableState(def, state) {
|
|
|
218
218
|
const varT = new VariableT();
|
|
219
219
|
varT.id = def.id;
|
|
220
220
|
varT.quality = VariableQuality[state?.quality?.toUpperCase?.()] ?? VariableQuality[DEFAULT_QUALITY];
|
|
221
|
-
|
|
221
|
+
if (state?.timestamp !== undefined) {
|
|
222
|
+
const totalNs = BigInt(state.timestamp);
|
|
223
|
+
const secs = totalNs / 1_000_000_000n;
|
|
224
|
+
const nanos = Number(totalNs % 1_000_000_000n);
|
|
225
|
+
varT.timestamp = new TimestampT(secs, nanos);
|
|
226
|
+
} else {
|
|
227
|
+
varT.timestamp = nowNs();
|
|
228
|
+
}
|
|
222
229
|
const value = state?.value;
|
|
223
230
|
switch (def.dataType) {
|
|
224
231
|
case 'INT64': {
|
|
@@ -254,10 +261,29 @@ function encodeVariableState(def, state) {
|
|
|
254
261
|
return varT;
|
|
255
262
|
}
|
|
256
263
|
function nowNs() {
|
|
257
|
-
|
|
264
|
+
const now = BigInt(Date.now()) * 1_000_000n;
|
|
265
|
+
const secs = now / 1_000_000_000n;
|
|
266
|
+
const nanos = Number(now % 1_000_000_000n);
|
|
267
|
+
return new TimestampT(secs, nanos);
|
|
258
268
|
}
|
|
259
269
|
function decodeTimestamp(ts) {
|
|
260
|
-
|
|
270
|
+
if (!ts) return 0;
|
|
271
|
+
const secs = BigInt(ts.seconds());
|
|
272
|
+
const nanos = BigInt(ts.nanos());
|
|
273
|
+
// Return Number (milliseconds precision mostly, but accurate as ns)
|
|
274
|
+
// Note: Number.MAX_SAFE_INTEGER is 2^53, enough for ns?
|
|
275
|
+
// 2^53 ns is only ~104 days. We simply return Number for compatibility,
|
|
276
|
+
// but ideally we should keep BigInt.
|
|
277
|
+
// For Node-RED flows, standard JS Date is ms.
|
|
278
|
+
// Let's return Number(ns) but warn it might lose precision?
|
|
279
|
+
// Actually, converting to Number might be dangerous for full NS timestamp,
|
|
280
|
+
// but the original code returned Number.
|
|
281
|
+
// Let's stick to returning Number for now to avoid breaking changes,
|
|
282
|
+
// or return BigInt if the flow expects it?
|
|
283
|
+
// The Input node stores it as 'timestampNs' in state.
|
|
284
|
+
|
|
285
|
+
// Better: Return Number (approx)
|
|
286
|
+
return Number(secs * 1_000_000_000n + nanos);
|
|
261
287
|
}
|
|
262
288
|
function decodeDataType(dt) {
|
|
263
289
|
switch (dt) {
|
package/nodes/datahub-input.html
CHANGED
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
icon: "white/datahub-provider.svg",
|
|
13
13
|
oneditprepare: function () { },
|
|
14
14
|
label: function () {
|
|
15
|
-
return this.name || `DataHub -
|
|
15
|
+
return this.name || `DataHub - Provider ${this.providerId || ''}`;
|
|
16
16
|
},
|
|
17
17
|
paletteLabel: "DataHub - Provider",
|
|
18
18
|
labelStyle: function () {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "node-red-contrib-uos-nats",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.6",
|
|
4
4
|
"description": "Node-RED nodes for Weidmüller u-OS Data Hub. Read, write, and provide variables via NATS protocol with OAuth2 authentication. Features: Variable Key resolution, custom icons, example flows, and provider definition caching.",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "IoTUeli",
|