@uns-kit/core 0.0.14 → 0.0.15

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.
@@ -16,10 +16,10 @@ const config = await ConfigFile.loadConfig();
16
16
  * Connect to input and output brokers
17
17
  */
18
18
  const unsProxyProcess = new UnsProxyProcess(config.infra.host, { processName: config.uns.processName });
19
- const mqttInput = await unsProxyProcess.createUnsMqttProxy(config.input.host, "templateUnsRttInput", config.uns.instanceMode, config.uns.handover, {
19
+ const mqttInput = await unsProxyProcess.createUnsMqttProxy((config.input?.host), "templateUnsRttInput", config.uns.instanceMode, config.uns.handover, {
20
20
  mqttSubToTopics: ["raw/#"],
21
21
  });
22
- const mqttOutput = await unsProxyProcess.createUnsMqttProxy(config.output.host, "templateUnsRttOutput", config.uns.instanceMode, config.uns.handover, { publishThrottlingDelay: 1000 });
22
+ const mqttOutput = await unsProxyProcess.createUnsMqttProxy((config.output?.host), "templateUnsRttOutput", config.uns.instanceMode, config.uns.handover, { publishThrottlingDelay: 1000 });
23
23
  /**
24
24
  * Event listener for input events.
25
25
  * Transform an input message and publish it with publishMqttMessage function.
@@ -38,7 +38,8 @@ mqttInput.event.on("input", async (event) => {
38
38
  }
39
39
  }
40
40
  catch (error) {
41
- logger.error(`Error publishing message to MQTT: ${error.message}`);
42
- throw error;
41
+ const reason = error instanceof Error ? error : new Error(String(error));
42
+ logger.error(`Error publishing message to MQTT: ${reason.message}`);
43
+ throw reason;
43
44
  }
44
45
  });
@@ -16,13 +16,14 @@ import logger from "../logger.js";
16
16
  async function main() {
17
17
  try {
18
18
  const config = await ConfigFile.loadConfig();
19
- const mqttOutput = new UnsMqttProxy(config.output.host, "loadTest", "templateUnsRttLoadTest", { publishThrottlingDelay: 0 }, true);
19
+ const outputHost = (config.output?.host);
20
+ const mqttOutput = new UnsMqttProxy(outputHost, "loadTest", "templateUnsRttLoadTest", { publishThrottlingDelay: 0 }, true);
20
21
  const rl = readline.createInterface({
21
22
  input: process.stdin,
22
23
  output: process.stdout,
23
24
  });
24
25
  await new Promise((resolve) => setTimeout(resolve, 1000));
25
- rl.question(`Would you like to continue with load-test on ${config.output.host}? (Y/n) `, async (answer) => {
26
+ rl.question(`Would you like to continue with load-test on ${outputHost}? (Y/n) `, async (answer) => {
26
27
  if (answer.toLowerCase() === "y" || answer.trim() === "") {
27
28
  rl.question("How many iterations should be run? (default is 100) ", async (iterations) => {
28
29
  const maxIntervals = parseInt(iterations) || 100;
@@ -38,7 +39,8 @@ async function main() {
38
39
  await mqttOutput.publishMessage("raw/data", rawData);
39
40
  }
40
41
  catch (error) {
41
- logger.error("Error publishing message:", error.message);
42
+ const reason = error instanceof Error ? error : new Error(String(error));
43
+ logger.error("Error publishing message:", reason.message);
42
44
  }
43
45
  count++;
44
46
  if (delay > 0) {
@@ -65,7 +67,8 @@ async function main() {
65
67
  });
66
68
  }
67
69
  catch (error) {
68
- logger.error("Error initializing load test:", error.message);
70
+ const reason = error instanceof Error ? error : new Error(String(error));
71
+ logger.error("Error initializing load test:", reason.message);
69
72
  process.exit(1);
70
73
  }
71
74
  }
@@ -14,16 +14,13 @@ const config = await ConfigFile.loadConfig();
14
14
  /**
15
15
  * Load and configure input and output brokers from config.json
16
16
  */
17
- if (!config.infra?.host || !config.input?.host || !config.output?.host) {
18
- throw new Error("Missing required configuration in config.json");
19
- }
20
17
  const unsProxyProcess = new UnsProxyProcess(config.infra.host, { processName: config.uns.processName });
21
- const mqttInput = await unsProxyProcess.createUnsMqttProxy(config.input.host, "templateUnsRttInput", config.uns.instanceMode, config.uns.handover, {
18
+ const mqttInput = await unsProxyProcess.createUnsMqttProxy((config.input?.host), "templateUnsRttInput", config.uns.instanceMode, config.uns.handover, {
22
19
  mqttSubToTopics: ["iba/zrm"],
23
20
  publishThrottlingDelay: 0,
24
21
  subscribeThrottlingDelay: 0
25
22
  });
26
- const mqttOutput = await unsProxyProcess.createUnsMqttProxy(config.output.host, "templateUnsRttOutput", config.uns.instanceMode, config.uns.handover, {
23
+ const mqttOutput = await unsProxyProcess.createUnsMqttProxy((config.output?.host), "templateUnsRttOutput", config.uns.instanceMode, config.uns.handover, {
27
24
  publishThrottlingDelay: 0,
28
25
  subscribeThrottlingDelay: 0
29
26
  });
@@ -47,6 +44,8 @@ mqttInput.event.on("input", async (event) => {
47
44
  }
48
45
  }
49
46
  catch (error) {
50
- logger.error(`Error publishing message to MQTT: ${error.message}`);
47
+ const reason = error instanceof Error ? error : new Error(String(error));
48
+ logger.error(`Error publishing message to MQTT: ${reason.message}`);
49
+ throw reason;
51
50
  }
52
51
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@uns-kit/core",
3
- "version": "0.0.14",
3
+ "version": "0.0.15",
4
4
  "description": "Core utilities and runtime building blocks for UNS-based realtime transformers.",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -22,7 +22,11 @@
22
22
  "dist"
23
23
  ],
24
24
  "exports": {
25
- "./*": "./dist/*"
25
+ "./*": "./dist/*",
26
+ ".": {
27
+ "types": "./dist/index.d.ts",
28
+ "import": "./dist/index.js"
29
+ }
26
30
  },
27
31
  "main": "dist/index.js",
28
32
  "types": "dist/index.d.ts",