node-red-contrib-uos-nats 0.1.40 → 0.1.41
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/datahub-input.js +21 -8
- package/package.json +1 -1
package/nodes/datahub-input.js
CHANGED
|
@@ -131,28 +131,41 @@ module.exports = function (RED) {
|
|
|
131
131
|
}
|
|
132
132
|
|
|
133
133
|
try {
|
|
134
|
-
//
|
|
135
|
-
|
|
134
|
+
// Resolve requested variable names to IDs
|
|
135
|
+
let targetIds = [];
|
|
136
|
+
if (this.variables.length > 0) {
|
|
137
|
+
// Reverse lookup: Find Def by Key
|
|
138
|
+
// Only needed if we want to filter at source (which we do now to avoid empty list issues)
|
|
139
|
+
const requestedKeys = new Set(this.variables);
|
|
140
|
+
for (const def of defMap.values()) {
|
|
141
|
+
if (requestedKeys.has(def.key)) {
|
|
142
|
+
targetIds.push(Number(def.id));
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
if (targetIds.length === 0 && defMap.size > 0) {
|
|
146
|
+
// We have definitions but found no matching keys for our config.
|
|
147
|
+
// This implies misconfiguration or name changes.
|
|
148
|
+
this.warn(`Snapshot Warning: None of the ${this.variables.length} configured variables were found in the Provider Definition.`);
|
|
149
|
+
}
|
|
150
|
+
}
|
|
136
151
|
|
|
137
|
-
|
|
152
|
+
// If we have specific IDs, request only those. Otherwise request all (empty array).
|
|
153
|
+
const snapshotMsg = await nc.request(subjects.readVariablesQuery(this.providerId), payloads.buildReadVariablesQuery(targetIds), { timeout: 2000 });
|
|
138
154
|
|
|
139
155
|
const bb = new flatbuffers.ByteBuffer(snapshotMsg.data);
|
|
140
156
|
const snapshotObj = ReadVariablesQueryResponse.getRootAsReadVariablesQueryResponse(bb);
|
|
141
157
|
const states = payloads.decodeVariableList(snapshotObj.variables());
|
|
142
158
|
|
|
143
|
-
//
|
|
144
|
-
|
|
159
|
+
// Re-process states (lookup names, formatting)
|
|
145
160
|
const filteredSnapshot = processStates(states);
|
|
146
161
|
|
|
147
|
-
// this.warn(`Filtered down to ${filteredSnapshot.length} items. (Selected vars: ${this.variables.length})`);
|
|
148
|
-
|
|
149
162
|
if (filteredSnapshot.length) {
|
|
150
163
|
this.send({ payload: { type: 'snapshot', variables: filteredSnapshot } });
|
|
151
164
|
} else {
|
|
152
165
|
if (states.length > 0) {
|
|
153
166
|
this.warn(`Snapshot received data but everything was filtered out. Check Variable selection. Debug: First raw ID: ${states[0].id}, DefMap has it? ${defMap.has(states[0].id)}`);
|
|
154
167
|
} else {
|
|
155
|
-
this.warn(
|
|
168
|
+
this.warn(`Snapshot received empty list from Data Hub. (Requested ${targetIds.length > 0 ? targetIds.length + ' specific IDs' : 'ALL variables'}).`);
|
|
156
169
|
}
|
|
157
170
|
}
|
|
158
171
|
} catch (requestErr) {
|