@transitive-sdk/utils-web 0.16.0 → 0.16.2
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/dist/utils-web.js +34 -9
- package/package.json +1 -1
package/dist/utils-web.js
CHANGED
|
@@ -406,8 +406,10 @@ var require_common = __commonJS({
|
|
|
406
406
|
callback && callback(count);
|
|
407
407
|
}, delay);
|
|
408
408
|
};
|
|
409
|
-
var
|
|
410
|
-
var
|
|
409
|
+
var metaPathToSelectorPath = (path) => path.map((value) => value[0] == "$" ? decodeURIComponent(value.slice(1)) : value);
|
|
410
|
+
var metaTopicToSelector = (topic) => pathToTopic2(metaPathToSelectorPath(topicToPath2(topic)));
|
|
411
|
+
var selectorPathToMetaPath = (path) => path.map((value) => ["+", "#"].includes(value[0]) ? `$${encodeURIComponent(value)}` : value);
|
|
412
|
+
var selectorToMetaTopic = (topic) => pathToTopic2(selectorPathToMetaPath(topicToPath2(topic)));
|
|
411
413
|
var getRandomId = (bytes = 6) => {
|
|
412
414
|
const buffer = new Uint8Array(bytes);
|
|
413
415
|
crypto.getRandomValues(buffer);
|
|
@@ -497,8 +499,11 @@ var require_common = __commonJS({
|
|
|
497
499
|
tryJSONParse,
|
|
498
500
|
decodeJWT: decodeJWT3,
|
|
499
501
|
visitAncestor,
|
|
500
|
-
storageRequestToSelector,
|
|
501
|
-
|
|
502
|
+
// storageRequestToSelector, selectorToStorageRequest
|
|
503
|
+
metaPathToSelectorPath,
|
|
504
|
+
selectorPathToMetaPath,
|
|
505
|
+
metaTopicToSelector,
|
|
506
|
+
selectorToMetaTopic
|
|
502
507
|
};
|
|
503
508
|
}
|
|
504
509
|
});
|
|
@@ -718,7 +723,8 @@ var require_MqttSync = __commonJS({
|
|
|
718
723
|
encodeTopicElement,
|
|
719
724
|
visitAncestor,
|
|
720
725
|
getRandomId,
|
|
721
|
-
|
|
726
|
+
selectorPathToMetaPath,
|
|
727
|
+
selectorToMetaTopic
|
|
722
728
|
} = require_common();
|
|
723
729
|
var { DataCache } = require_DataCache();
|
|
724
730
|
var log2 = getLogger2("MqttSync");
|
|
@@ -802,9 +808,6 @@ var require_MqttSync = __commonJS({
|
|
|
802
808
|
path = path.slice(sliceTopic);
|
|
803
809
|
topic = pathToTopic2(path);
|
|
804
810
|
}
|
|
805
|
-
if (!inclMeta && path.some((field) => field[0] == "$")) {
|
|
806
|
-
return;
|
|
807
|
-
}
|
|
808
811
|
const rpcHandler = this.getRPCHandler(topic);
|
|
809
812
|
if (rpcHandler) {
|
|
810
813
|
const json = mqttParsePayload(payload);
|
|
@@ -813,6 +816,9 @@ var require_MqttSync = __commonJS({
|
|
|
813
816
|
const json = mqttParsePayload(payload);
|
|
814
817
|
this.handleRPCResponse(topic, json);
|
|
815
818
|
} else if (packet.retain || ignoreRetain) {
|
|
819
|
+
if (!inclMeta && path.slice(0, 5).some((field) => field[0] == "$")) {
|
|
820
|
+
return;
|
|
821
|
+
}
|
|
816
822
|
if (this.isPublished(topic)) {
|
|
817
823
|
const json = mqttParsePayload(payload);
|
|
818
824
|
this.publishedMessages.updateFromArray([...path, specialKey], json);
|
|
@@ -1307,9 +1313,28 @@ var require_MqttSync = __commonJS({
|
|
|
1307
1313
|
* service is running -- as it usually is inside the
|
|
1308
1314
|
* transitiverobotics/clickhouse docker image). */
|
|
1309
1315
|
requestHistoryStorage(topic, ttl = 1) {
|
|
1310
|
-
const
|
|
1316
|
+
const path = selectorPathToMetaPath(topicToPath2(topic));
|
|
1317
|
+
path.splice(5, 0, "$store");
|
|
1318
|
+
const storageRequest = pathToTopic2(path);
|
|
1311
1319
|
this.mqtt.publish(storageRequest, String(ttl), { retain: true });
|
|
1312
1320
|
}
|
|
1321
|
+
/** Query a topics history (if stored). Convenience function to make RPC call
|
|
1322
|
+
* to the mqtt2clickhouse service.
|
|
1323
|
+
* @param params = {topic, since, until, orderBy, limit} */
|
|
1324
|
+
async queryHistory(params) {
|
|
1325
|
+
const path = topicToPath2(params.topic);
|
|
1326
|
+
const rpc = selectorToMetaTopic(`${pathToTopic2(path.slice(0, 5))}/$queryMQTTHistory`);
|
|
1327
|
+
const query = {
|
|
1328
|
+
subtopic: pathToTopic2(path.slice(5)),
|
|
1329
|
+
...params
|
|
1330
|
+
};
|
|
1331
|
+
delete query.topic;
|
|
1332
|
+
query.since && (query.since = query.since.getTime());
|
|
1333
|
+
query.until && (query.until = query.until.getTime());
|
|
1334
|
+
log2.info("queryHistory", { rpc, query });
|
|
1335
|
+
const result = await this.call(rpc, query);
|
|
1336
|
+
return result;
|
|
1337
|
+
}
|
|
1313
1338
|
};
|
|
1314
1339
|
module2.exports = MqttSync3;
|
|
1315
1340
|
}
|