@formant/data-sdk 1.37.0 → 1.38.0

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.
@@ -24249,6 +24249,11 @@ class Device extends BaseDevice {
24249
24249
  o
24250
24250
  );
24251
24251
  }
24252
+ async queryEvents(t) {
24253
+ if (t.deviceIds)
24254
+ throw new Error("Cannot filter multiple devices via Device class");
24255
+ return t.deviceIds = [this.id], queryEvents(t);
24256
+ }
24252
24257
  async getTelemetryStreams() {
24253
24258
  var o, d;
24254
24259
  const t = await this.getConfiguration(), n = await fetch(
@@ -24356,7 +24361,88 @@ class PeerDevice extends BaseDevice {
24356
24361
  else if (d && c !== void 0)
24357
24362
  throw new Error("latestOnly and limit cannot be used together");
24358
24363
  let u = `${this.peerUrl}/v1/querydatapoints?stream_name=${n}&start=${r.toISOString()}&end=${l.toISOString()}`;
24359
- return c != null && c > 0 && (u += `&limit=${c}`), o != null && o >= 0 && (u += `&offset=${o}`), (await (await fetch(u)).json()).results;
24364
+ c != null && c > 0 && (u += `&limit=${c}`), o != null && o >= 0 && (u += `&offset=${o}`);
24365
+ const B = await (await fetch(u)).json(), R = [];
24366
+ for (const p of B.results) {
24367
+ const g = parseInt(p.timestamp), h = p.tags.data_type;
24368
+ delete p.tags.data_type, R.push({
24369
+ deviceId: this.id,
24370
+ name: p.stream,
24371
+ points: [[g, this.getPointPayload(h, p)]],
24372
+ tags: p.tags,
24373
+ type: h
24374
+ });
24375
+ }
24376
+ return R.reverse();
24377
+ }
24378
+ async queryEvents(n) {
24379
+ const r = [
24380
+ "id",
24381
+ "viewed",
24382
+ "keyword",
24383
+ "message",
24384
+ "sort",
24385
+ "eventTypes",
24386
+ "notificationEnabled",
24387
+ "userIds",
24388
+ "annotationTemplateIds",
24389
+ "disableNullMatches",
24390
+ "severities",
24391
+ "deviceIds",
24392
+ "names",
24393
+ "types",
24394
+ "tags",
24395
+ "notNames"
24396
+ ];
24397
+ this.checkKeysAndThrow(n, r);
24398
+ let l = `${this.peerUrl}/v1/queryevents?start=${n.start}&end=${n.end}`;
24399
+ n.count != null && n.count > 0 && (l += `&limit=${n.count}`), n.offset != null && n.offset >= 0 && (l += `&offset=${n.offset}`);
24400
+ const c = await (await fetch(l)).json(), o = [];
24401
+ for (const d of c.results) {
24402
+ const u = parseInt(d.timestamp), U = {
24403
+ deviceId: this.id,
24404
+ time: new Date(u).toISOString(),
24405
+ message: d.message,
24406
+ notificationEnabled: d.notificationEnabled
24407
+ };
24408
+ d.id !== "" && (U.id = d.id), d.type !== "" && (U.type = d.type), d.streamName !== "" && (U.streamName = d.streamName), d.streamType !== "" && (U.streamType = d.streamType), d.severity !== "" && (U.severity = d.severity.toLowerCase()), d.tags && (U.tags = d.tags), d.endTimestamp !== "0" && (U.endTime = new Date(parseInt(d.endTimestamp)).toISOString()), o.push(U);
24409
+ }
24410
+ return o.reverse();
24411
+ }
24412
+ checkKeysAndThrow(n, r) {
24413
+ const l = r.filter((s) => s in n);
24414
+ if (l.length > 0)
24415
+ throw new Error(
24416
+ `Filters not currently supported: ${l.join(", ")}.`
24417
+ );
24418
+ }
24419
+ getPointPayload(n, r) {
24420
+ switch (n) {
24421
+ case "numeric":
24422
+ return r.numeric.value;
24423
+ case "numeric set":
24424
+ return r.numericSet.numerics;
24425
+ case "text":
24426
+ return r.text.value;
24427
+ case "json":
24428
+ return r.json.value;
24429
+ case "bitset":
24430
+ const l = [], s = [];
24431
+ for (const c of r.bitset.bits)
24432
+ l.push(c.key), s.push(c.value);
24433
+ return {
24434
+ keys: l,
24435
+ values: s
24436
+ };
24437
+ case "location":
24438
+ return r.location;
24439
+ case "health":
24440
+ return r.health;
24441
+ case "battery":
24442
+ return r.battery;
24443
+ default:
24444
+ return {};
24445
+ }
24360
24446
  }
24361
24447
  subscribeToTelemetry() {
24362
24448
  this.telemetryStreamActive = !0;