@transitive-sdk/utils-web 0.16.2 → 0.16.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.
Files changed (2) hide show
  1. package/dist/utils-web.js +37 -5
  2. package/package.json +1 -1
package/dist/utils-web.js CHANGED
@@ -469,6 +469,14 @@ var require_common = __commonJS({
469
469
  !parts.h && (rtv += `${parts.s}s`);
470
470
  return rtv.trim();
471
471
  };
472
+ var doOnceCache = {};
473
+ var doOnce = (fn, key = void 0) => {
474
+ key ||= fn.toString();
475
+ if (doOnceCache[key])
476
+ return;
477
+ fn();
478
+ doOnceCache[key] = true;
479
+ };
472
480
  module2.exports = {
473
481
  parseMQTTUsername,
474
482
  parseMQTTTopic,
@@ -503,7 +511,8 @@ var require_common = __commonJS({
503
511
  metaPathToSelectorPath,
504
512
  selectorPathToMetaPath,
505
513
  metaTopicToSelector,
506
- selectorToMetaTopic
514
+ selectorToMetaTopic,
515
+ doOnce
507
516
  };
508
517
  }
509
518
  });
@@ -754,7 +763,7 @@ var require_MqttSync = __commonJS({
754
763
  achieve the "should-be" state. Note that we cannot use a structured document
755
764
  for storing these publishedMessages since we need to be able to store separate
756
765
  values at non-leaf nodes in the object (just like mqtt, where you can have
757
- /a/b = 1 and /a/b/c = 1 at the same time). Note: not used in atomic mode.
766
+ `/a/b = 1` and `/a/b/c = 1` at the same time). Note: not used in atomic mode.
758
767
  Note: we use specialKey in this DataCache to allow overlapping
759
768
  topics (e.g., `/a/b/$_ = 1` and `/a/$_ = {b: 2}`)
760
769
  */
@@ -844,8 +853,8 @@ var require_MqttSync = __commonJS({
844
853
  /**
845
854
  * Publish all values at the given level of the given object under the given
846
855
  * topic (plus sub-key, of course).
847
- * TODO: Is this OK, or do we need to go through this.publish?
848
856
  */
857
+ // TODO: Is this OK, or do we need to go through this.publish?
849
858
  publishAtLevel(topic, value, level) {
850
859
  log2.debug(`publishingAtLevel ${level}`, topic, value);
851
860
  if (level > 0) {
@@ -1319,8 +1328,31 @@ var require_MqttSync = __commonJS({
1319
1328
  this.mqtt.publish(storageRequest, String(ttl), { retain: true });
1320
1329
  }
1321
1330
  /** 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} */
1331
+ * to the mqtt2clickhouse service. For details see `clickhouse.queryMQTTHistory`
1332
+ * in utils/clickhouse.
1333
+ * @param {object} params
1334
+ * @param {object} params.topic - A topic with wildcards selecting what
1335
+ * to retrieve.
1336
+ * @param {number} [params.since] - A time (seconds since epoch) from when on
1337
+ * to retrieve history.
1338
+ * @param {number} [params.until] - A time (seconds since epoch) until when on
1339
+ * to retrieve history.
1340
+ * @param {[string]} [params.path] - A path into the payload to extract, e.g.,
1341
+ * `['a', 'b']` would retrieve the value 123 from `{a: {b: 123}}`. Requires `type`.
1342
+ * @param {string} [params.type] - Type of element to extract using `path`.
1343
+ * For available types, see https://clickhouse.com/docs/sql-reference/data-types.
1344
+ * @param {string} [params.orderBy] - an `ORDER BY` statement to use for sorting
1345
+ * results.
1346
+ * @param {integer} [params.limit] - Max number of results to return, after grouping.
1347
+ * @param {integer} [params.bins] - Into how many bins to aggregate (if given,
1348
+ * requires `since`).
1349
+ * @param {string} [params.agg] - Aggregation function to use (if `aggSeconds`
1350
+ * or `bins` and `since` are given). Defaults to `count` (which works for any
1351
+ * data type). See
1352
+ * https://clickhouse.com/docs/sql-reference/aggregate-functions/reference.
1353
+ * @param {integer} [params.aggSeconds] - How many seconds to group together
1354
+ * (alternative to `bins` + `since`).
1355
+ * */
1324
1356
  async queryHistory(params) {
1325
1357
  const path = topicToPath2(params.topic);
1326
1358
  const rpc = selectorToMetaTopic(`${pathToTopic2(path.slice(0, 5))}/$queryMQTTHistory`);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@transitive-sdk/utils-web",
3
- "version": "0.16.2",
3
+ "version": "0.16.3",
4
4
  "description": "Web utils for the Transitive framework",
5
5
  "homepage": "https://transitiverobotics.com",
6
6
  "repository": {