@kuriousdesign/machine-sdk 1.0.3 → 1.0.5

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.
@@ -1,2 +1,3 @@
1
1
  export * from "./colorMapping";
2
2
  export * from "./topicMapping";
3
+ export * from "./mqtt-helpers";
@@ -16,3 +16,4 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
17
  __exportStar(require("./colorMapping"), exports);
18
18
  __exportStar(require("./topicMapping"), exports);
19
+ __exportStar(require("./mqtt-helpers"), exports);
@@ -0,0 +1,2 @@
1
+ import { DeviceRegistration } from "../custom-types";
2
+ export declare function buildFullTopicPath(device: DeviceRegistration, deviceMap: Map<number, DeviceRegistration>): string;
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.buildFullTopicPath = buildFullTopicPath;
4
+ function buildFullTopicPath(device, deviceMap) {
5
+ const parts = [];
6
+ let current = device;
7
+ while (current) {
8
+ parts.unshift(current.id);
9
+ if (!current.parentId || current.parentId === 0)
10
+ break;
11
+ const parent = deviceMap.get(current.parentId);
12
+ if (!parent) {
13
+ console.warn(`Parent device missing for device ${current.id}, parentId: ${current.parentId}`);
14
+ break;
15
+ }
16
+ current = parent;
17
+ }
18
+ return 'machine/' + parts.join('/');
19
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kuriousdesign/machine-sdk",
3
- "version": "1.0.3",
3
+ "version": "1.0.5",
4
4
  "description": "Shared data types and helpers for machine-related repositories",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -1,2 +1,3 @@
1
1
  export * from "./colorMapping";
2
2
  export * from "./topicMapping";
3
+ export * from "./mqtt-helpers";
@@ -0,0 +1,21 @@
1
+ import { DeviceRegistration } from "../custom-types";
2
+
3
+ export function buildFullTopicPath(device: DeviceRegistration, deviceMap: Map<number, DeviceRegistration>): string {
4
+ const parts: number[] = [];
5
+ let current: DeviceRegistration | undefined = device;
6
+
7
+ while (current) {
8
+ parts.unshift(current.id);
9
+
10
+ if (!current.parentId || current.parentId === 0) break;
11
+
12
+ const parent = deviceMap.get(current.parentId);
13
+ if (!parent) {
14
+ console.warn(`Parent device missing for device ${current.id}, parentId: ${current.parentId}`);
15
+ break;
16
+ }
17
+ current = parent;
18
+ }
19
+
20
+ return 'machine/' + parts.join('/');
21
+ }