@uns-kit/cli 2.0.23 → 2.0.25

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 (60) hide show
  1. package/LICENSE +21 -21
  2. package/README.md +175 -175
  3. package/dist/index.js +37 -0
  4. package/package.json +6 -6
  5. package/templates/api/src/examples/api-example.ts +91 -91
  6. package/templates/azure-pipelines.yml +21 -21
  7. package/templates/codegen/codegen.ts +15 -15
  8. package/templates/codegen/src/uns/uns-tags.ts +1 -1
  9. package/templates/codegen/src/uns/uns-topics.ts +1 -1
  10. package/templates/config-files/config-docker.json +26 -26
  11. package/templates/config-files/config-localhost.json +26 -26
  12. package/templates/cron/AGENTS.md +24 -23
  13. package/templates/cron/src/examples/cron-example.ts +71 -71
  14. package/templates/default/.prettierignore +1 -1
  15. package/templates/default/.prettierrc +7 -7
  16. package/templates/default/AGENTS.md +24 -23
  17. package/templates/default/README.md +43 -41
  18. package/templates/default/config.json +27 -27
  19. package/templates/default/eslint.config.js +30 -30
  20. package/templates/default/gitignore +51 -51
  21. package/templates/default/package.json +49 -46
  22. package/templates/default/src/config/project.config.extension.example +23 -23
  23. package/templates/default/src/config/project.config.extension.ts +6 -6
  24. package/templates/default/src/examples/data-example.ts +86 -86
  25. package/templates/default/src/examples/load-test-data.ts +110 -110
  26. package/templates/default/src/examples/table-example.ts +97 -97
  27. package/templates/default/src/examples/table-window-load-test.ts +446 -446
  28. package/templates/default/src/examples/uns-gateway-cli.ts +10 -10
  29. package/templates/default/src/index.ts +15 -15
  30. package/templates/default/src/uns/uns-assets.ts +12 -12
  31. package/templates/default/src/uns/uns-dictionary.generated.ts +758 -758
  32. package/templates/default/src/uns/uns-measurements.generated.ts +366 -366
  33. package/templates/default/src/uns/uns-tags.ts +2 -2
  34. package/templates/default/src/uns/uns-topics.ts +2 -2
  35. package/templates/default/tsconfig.json +29 -29
  36. package/templates/python/app/README.md +8 -8
  37. package/templates/python/examples/README.md +134 -134
  38. package/templates/python/examples/api_handler.py +28 -28
  39. package/templates/python/examples/data_publish.py +11 -11
  40. package/templates/python/examples/data_subscribe.py +8 -8
  41. package/templates/python/examples/data_transformer.py +17 -17
  42. package/templates/python/examples/table_transformer.py +15 -15
  43. package/templates/python/gateway/cli.py +75 -75
  44. package/templates/python/gateway/client.py +155 -155
  45. package/templates/python/gateway/manager.py +97 -97
  46. package/templates/python/gitignore +47 -47
  47. package/templates/python/proto/uns-gateway.proto +102 -102
  48. package/templates/python/pyproject.toml +4 -4
  49. package/templates/python/runtime.json +4 -4
  50. package/templates/python/scripts/setup.sh +87 -87
  51. package/templates/temporal/src/examples/temporal-example.ts +37 -37
  52. package/templates/uns-dictionary/uns-dictionary.json +650 -650
  53. package/templates/uns-measurements/uns-measurements.json +360 -360
  54. package/templates/vscode/.vscode/launch.json +164 -164
  55. package/templates/vscode/.vscode/settings.json +9 -9
  56. package/templates/vscode/.vscode/tasks.json +27 -27
  57. package/templates/vscode/uns-kit.code-workspace +13 -13
  58. package/templates/python/gen/__init__.py +0 -1
  59. package/templates/python/gen/uns_gateway_pb2.py +0 -70
  60. package/templates/python/gen/uns_gateway_pb2_grpc.py +0 -312
@@ -1,110 +1,110 @@
1
- /**
2
- * Load the configuration from a file.
3
- * On the server, this file is provided by the `uns-datahub-controller`.
4
- * In the development environment, you are responsible for creating and maintaining this file and its contents.
5
- */
6
- import readline from "readline";
7
- import { ConfigFile, getLogger } from "@uns-kit/core";
8
- import UnsMqttProxy from "@uns-kit/core/uns-mqtt/uns-mqtt-proxy.js";
9
-
10
- const logger = getLogger(import.meta.url);
11
-
12
- /**
13
- * Produces a smooth oscillating value to mimic a real-world sensor signal.
14
- * Combines fast and slow sine waves plus tiny ripple so that subsequent values
15
- * rise and fall without appearing purely random.
16
- */
17
- function simulateSensorValue(step: number): number {
18
- const baseValue = 42; // arbitrary midpoint for the simulated signal
19
- const fastCycle = Math.sin(step / 5) * 3;
20
- const slowCycle = Math.sin(step / 25) * 6;
21
- const ripple = Math.sin(step / 2 + Math.PI / 4) * 0.5;
22
- const value = baseValue + fastCycle + slowCycle + ripple;
23
-
24
- return Number(value.toFixed(2));
25
- }
26
-
27
- /**
28
- * This script initializes an MQTT output proxy for load testing purposes.
29
- * It sets up a connection to the specified MQTT broker and configures
30
- * a proxy instance. The load test is designed to evaluate the performance
31
- * and reliability of the MQTT broker under simulated load conditions.
32
- */
33
- async function main() {
34
- try {
35
- const config = await ConfigFile.loadConfig();
36
- const outputHost = (config.output?.host)!;
37
-
38
- const mqttOutput = new UnsMqttProxy(
39
- outputHost,
40
- "loadTest",
41
- "templateUnsRttLoadTest",
42
- { publishThrottlingDelay: 0 },
43
- true
44
- );
45
-
46
- const rl = readline.createInterface({
47
- input: process.stdin,
48
- output: process.stdout,
49
- });
50
-
51
- await new Promise((resolve) => setTimeout(resolve, 1000));
52
-
53
- rl.question(`Would you like to continue with load-test on ${outputHost}? (Y/n) `, async (answer) => {
54
- if (answer.toLowerCase() === "y" || answer.trim() === "") {
55
- rl.question("How many iterations should be run? (default is 100) ", async (iterations) => {
56
- const maxIntervals = parseInt(iterations) || 100;
57
-
58
- rl.question("What should be the delay between intervals in milliseconds? (default is 0 ms) ", async (intervalDelay) => {
59
- const delay = parseInt(intervalDelay) || 0;
60
-
61
- logger.info(`Starting load test with ${maxIntervals} messages and ${delay} ms delay...`);
62
-
63
- let count = 0;
64
- const startTime = Date.now();
65
-
66
- while (count < maxIntervals) {
67
- try {
68
- const currentDate = new Date();
69
- const sensorValue = simulateSensorValue(count);
70
- const rawData = `${count},${currentDate.getTime()},${sensorValue}`;
71
- await mqttOutput.publishMessage("raw/data", rawData);
72
- } catch (error) {
73
- const reason = error instanceof Error ? error : new Error(String(error));
74
- logger.error("Error publishing message:", reason.message);
75
- }
76
-
77
- count++;
78
- if (delay > 0) {
79
- await new Promise((resolve) => setTimeout(resolve, delay));
80
- }
81
- }
82
-
83
- logger.info(`Sleeping for 50ms.`);
84
- await new Promise((resolve) => setTimeout(resolve, 50));
85
-
86
- const endTime = Date.now();
87
- const duration = (endTime - startTime) / 1000;
88
- const messagesPerSecond = maxIntervals / duration;
89
-
90
- logger.info(`Load test completed in ${duration.toFixed(2)} seconds.`);
91
- logger.info(`Message rate: ${messagesPerSecond.toFixed(2)} msg/s.`);
92
-
93
- rl.close();
94
- process.exit(0);
95
- });
96
- });
97
- } else {
98
- logger.info("Load test aborted.");
99
- rl.close();
100
- process.exit(0);
101
- }
102
- });
103
- } catch (error) {
104
- const reason = error instanceof Error ? error : new Error(String(error));
105
- logger.error("Error initializing load test:", reason.message);
106
- process.exit(1);
107
- }
108
- }
109
-
110
- main();
1
+ /**
2
+ * Load the configuration from a file.
3
+ * On the server, this file is provided by the `uns-datahub-controller`.
4
+ * In the development environment, you are responsible for creating and maintaining this file and its contents.
5
+ */
6
+ import readline from "readline";
7
+ import { ConfigFile, getLogger } from "@uns-kit/core";
8
+ import UnsMqttProxy from "@uns-kit/core/uns-mqtt/uns-mqtt-proxy.js";
9
+
10
+ const logger = getLogger(import.meta.url);
11
+
12
+ /**
13
+ * Produces a smooth oscillating value to mimic a real-world sensor signal.
14
+ * Combines fast and slow sine waves plus tiny ripple so that subsequent values
15
+ * rise and fall without appearing purely random.
16
+ */
17
+ function simulateSensorValue(step: number): number {
18
+ const baseValue = 42; // arbitrary midpoint for the simulated signal
19
+ const fastCycle = Math.sin(step / 5) * 3;
20
+ const slowCycle = Math.sin(step / 25) * 6;
21
+ const ripple = Math.sin(step / 2 + Math.PI / 4) * 0.5;
22
+ const value = baseValue + fastCycle + slowCycle + ripple;
23
+
24
+ return Number(value.toFixed(2));
25
+ }
26
+
27
+ /**
28
+ * This script initializes an MQTT output proxy for load testing purposes.
29
+ * It sets up a connection to the specified MQTT broker and configures
30
+ * a proxy instance. The load test is designed to evaluate the performance
31
+ * and reliability of the MQTT broker under simulated load conditions.
32
+ */
33
+ async function main() {
34
+ try {
35
+ const config = await ConfigFile.loadConfig();
36
+ const outputHost = (config.output?.host)!;
37
+
38
+ const mqttOutput = new UnsMqttProxy(
39
+ outputHost,
40
+ "loadTest",
41
+ "templateUnsRttLoadTest",
42
+ { publishThrottlingDelay: 0 },
43
+ true
44
+ );
45
+
46
+ const rl = readline.createInterface({
47
+ input: process.stdin,
48
+ output: process.stdout,
49
+ });
50
+
51
+ await new Promise((resolve) => setTimeout(resolve, 1000));
52
+
53
+ rl.question(`Would you like to continue with load-test on ${outputHost}? (Y/n) `, async (answer) => {
54
+ if (answer.toLowerCase() === "y" || answer.trim() === "") {
55
+ rl.question("How many iterations should be run? (default is 100) ", async (iterations) => {
56
+ const maxIntervals = parseInt(iterations) || 100;
57
+
58
+ rl.question("What should be the delay between intervals in milliseconds? (default is 0 ms) ", async (intervalDelay) => {
59
+ const delay = parseInt(intervalDelay) || 0;
60
+
61
+ logger.info(`Starting load test with ${maxIntervals} messages and ${delay} ms delay...`);
62
+
63
+ let count = 0;
64
+ const startTime = Date.now();
65
+
66
+ while (count < maxIntervals) {
67
+ try {
68
+ const currentDate = new Date();
69
+ const sensorValue = simulateSensorValue(count);
70
+ const rawData = `${count},${currentDate.getTime()},${sensorValue}`;
71
+ await mqttOutput.publishMessage("raw/data", rawData);
72
+ } catch (error) {
73
+ const reason = error instanceof Error ? error : new Error(String(error));
74
+ logger.error("Error publishing message:", reason.message);
75
+ }
76
+
77
+ count++;
78
+ if (delay > 0) {
79
+ await new Promise((resolve) => setTimeout(resolve, delay));
80
+ }
81
+ }
82
+
83
+ logger.info(`Sleeping for 50ms.`);
84
+ await new Promise((resolve) => setTimeout(resolve, 50));
85
+
86
+ const endTime = Date.now();
87
+ const duration = (endTime - startTime) / 1000;
88
+ const messagesPerSecond = maxIntervals / duration;
89
+
90
+ logger.info(`Load test completed in ${duration.toFixed(2)} seconds.`);
91
+ logger.info(`Message rate: ${messagesPerSecond.toFixed(2)} msg/s.`);
92
+
93
+ rl.close();
94
+ process.exit(0);
95
+ });
96
+ });
97
+ } else {
98
+ logger.info("Load test aborted.");
99
+ rl.close();
100
+ process.exit(0);
101
+ }
102
+ });
103
+ } catch (error) {
104
+ const reason = error instanceof Error ? error : new Error(String(error));
105
+ logger.error("Error initializing load test:", reason.message);
106
+ process.exit(1);
107
+ }
108
+ }
109
+
110
+ main();
@@ -1,97 +1,97 @@
1
- /**
2
- * Change this file according to your specifications and rename it to index.ts
3
- */
4
-
5
- import { UnsProxyProcess, ConfigFile, getLogger } from "@uns-kit/core";
6
- import { registerAttributeDescriptions, registerObjectTypeDescriptions } from "@uns-kit/core/uns/uns-dictionary-registry.js";
7
- import { UnsTopics } from "@uns-kit/core/uns/uns-topics.js";
8
- import {
9
- GeneratedObjectTypes,
10
- GeneratedAttributes,
11
- GeneratedAttributeDescriptions,
12
- GeneratedObjectTypeDescriptions,
13
- } from "../uns/uns-dictionary.generated.js";
14
- import { GeneratedAssets, resolveGeneratedAsset } from "../uns/uns-assets.js";
15
- import type { IUnsTableColumn } from "@uns-kit/core/uns/uns-interfaces.js";
16
- import type { ISO8601 } from "@uns-kit/core/uns/uns-interfaces.js";
17
- import { GeneratedPhysicalMeasurements } from "../uns/uns-measurements.generated.js";
18
-
19
- const logger = getLogger(import.meta.url);
20
-
21
- /**
22
- * Load the configuration from a file.
23
- * On the server, this file is provided by the `uns-datahub-controller`.
24
- * In the development environment, you are responsible for creating and maintaining this file and its contents.
25
- */
26
- const config = await ConfigFile.loadConfig();
27
- registerObjectTypeDescriptions(GeneratedObjectTypeDescriptions);
28
- registerAttributeDescriptions(GeneratedAttributeDescriptions);
29
-
30
- /**
31
- * Load and configure input and output brokers from config.json
32
- */
33
- const unsProxyProcess = new UnsProxyProcess(config.infra.host!, {processName: config.uns.processName!});
34
- const mqttInput = await unsProxyProcess.createUnsMqttProxy((config.input?.host)!, "templateUnsRttInput", config.uns.instanceMode!, config.uns.handover!, {
35
- mqttSubToTopics: ["raw/#"],
36
- });
37
- const mqttOutput = await unsProxyProcess.createUnsMqttProxy((config.output?.host)!, "templateUnsRttOutput", config.uns.instanceMode!, config.uns.handover!, {
38
- publishThrottlingDelay: 1000,
39
- });
40
-
41
- /**
42
- * The input worker connects to the upstream broker and listens for incoming messages.
43
- * It processes the messages and transforms them into a table-type IUnsMessage.
44
- * The resulting message is published to the output broker.
45
- */
46
- mqttInput.event.on("input", async (event) => {
47
- try {
48
- if (event.topic === "raw/data") {
49
- const values = event.message.split(",");
50
- const [countRaw, timestampRaw, sensorRaw] = values;
51
- if (!countRaw || !timestampRaw || !sensorRaw) {
52
- logger.warn(`Skipping malformed raw/data payload: ${event.message}`);
53
- return;
54
- }
55
-
56
- const currentValue = Number.parseFloat(countRaw);
57
- const eventDate = new Date(Number.parseInt(timestampRaw, 10));
58
- const sensorValue = Number.parseFloat(sensorRaw);
59
-
60
- const time: ISO8601 = eventDate.toISOString() as ISO8601;
61
- const intervalStart: ISO8601 = new Date(eventDate.getTime() - 1000).toISOString() as ISO8601;
62
- const intervalEnd: ISO8601 = eventDate.toISOString() as ISO8601;
63
- const dataGroup = "sensor_table";
64
- const columns: IUnsTableColumn[] = [
65
- { name: "current", type: "double", value: currentValue, uom: GeneratedPhysicalMeasurements.Ampere },
66
- { name: "voltage", type: "double", value: sensorValue },
67
- ];
68
- const topic: UnsTopics = "enterprise/site/area/line/";
69
- const asset = resolveGeneratedAsset("asset");
70
- const assetDescription = ""; // customize manually
71
- mqttOutput.publishMqttMessage({
72
- topic,
73
- asset,
74
- assetDescription,
75
- objectType: GeneratedObjectTypes["resource-status"],
76
- objectId: "main",
77
- attributes: [
78
- {
79
- attribute: GeneratedAttributes["status"] ?? "status",
80
- description: GeneratedAttributeDescriptions["status"] ?? "Table",
81
- table: {
82
- dataGroup,
83
- time,
84
- intervalStart,
85
- intervalEnd,
86
- columns,
87
- },
88
- },
89
- ],
90
- });
91
- }
92
- } catch (error) {
93
- const reason = error instanceof Error ? error : new Error(String(error));
94
- logger.error(`Error publishing message to MQTT: ${reason.message}`);
95
- throw reason;
96
- }
97
- });
1
+ /**
2
+ * Change this file according to your specifications and rename it to index.ts
3
+ */
4
+
5
+ import { UnsProxyProcess, ConfigFile, getLogger } from "@uns-kit/core";
6
+ import { registerAttributeDescriptions, registerObjectTypeDescriptions } from "@uns-kit/core/uns/uns-dictionary-registry.js";
7
+ import { UnsTopics } from "@uns-kit/core/uns/uns-topics.js";
8
+ import {
9
+ GeneratedObjectTypes,
10
+ GeneratedAttributes,
11
+ GeneratedAttributeDescriptions,
12
+ GeneratedObjectTypeDescriptions,
13
+ } from "../uns/uns-dictionary.generated.js";
14
+ import { GeneratedAssets, resolveGeneratedAsset } from "../uns/uns-assets.js";
15
+ import type { IUnsTableColumn } from "@uns-kit/core/uns/uns-interfaces.js";
16
+ import type { ISO8601 } from "@uns-kit/core/uns/uns-interfaces.js";
17
+ import { GeneratedPhysicalMeasurements } from "../uns/uns-measurements.generated.js";
18
+
19
+ const logger = getLogger(import.meta.url);
20
+
21
+ /**
22
+ * Load the configuration from a file.
23
+ * On the server, this file is provided by the `uns-datahub-controller`.
24
+ * In the development environment, you are responsible for creating and maintaining this file and its contents.
25
+ */
26
+ const config = await ConfigFile.loadConfig();
27
+ registerObjectTypeDescriptions(GeneratedObjectTypeDescriptions);
28
+ registerAttributeDescriptions(GeneratedAttributeDescriptions);
29
+
30
+ /**
31
+ * Load and configure input and output brokers from config.json
32
+ */
33
+ const unsProxyProcess = new UnsProxyProcess(config.infra.host!, {processName: config.uns.processName!});
34
+ const mqttInput = await unsProxyProcess.createUnsMqttProxy((config.input?.host)!, "templateUnsRttInput", config.uns.instanceMode!, config.uns.handover!, {
35
+ mqttSubToTopics: ["raw/#"],
36
+ });
37
+ const mqttOutput = await unsProxyProcess.createUnsMqttProxy((config.output?.host)!, "templateUnsRttOutput", config.uns.instanceMode!, config.uns.handover!, {
38
+ publishThrottlingDelay: 1000,
39
+ });
40
+
41
+ /**
42
+ * The input worker connects to the upstream broker and listens for incoming messages.
43
+ * It processes the messages and transforms them into a table-type IUnsMessage.
44
+ * The resulting message is published to the output broker.
45
+ */
46
+ mqttInput.event.on("input", async (event) => {
47
+ try {
48
+ if (event.topic === "raw/data") {
49
+ const values = event.message.split(",");
50
+ const [countRaw, timestampRaw, sensorRaw] = values;
51
+ if (!countRaw || !timestampRaw || !sensorRaw) {
52
+ logger.warn(`Skipping malformed raw/data payload: ${event.message}`);
53
+ return;
54
+ }
55
+
56
+ const currentValue = Number.parseFloat(countRaw);
57
+ const eventDate = new Date(Number.parseInt(timestampRaw, 10));
58
+ const sensorValue = Number.parseFloat(sensorRaw);
59
+
60
+ const time: ISO8601 = eventDate.toISOString() as ISO8601;
61
+ const intervalStart: ISO8601 = new Date(eventDate.getTime() - 1000).toISOString() as ISO8601;
62
+ const intervalEnd: ISO8601 = eventDate.toISOString() as ISO8601;
63
+ const dataGroup = "sensor_table";
64
+ const columns: IUnsTableColumn[] = [
65
+ { name: "current", type: "double", value: currentValue, uom: GeneratedPhysicalMeasurements.Ampere },
66
+ { name: "voltage", type: "double", value: sensorValue },
67
+ ];
68
+ const topic: UnsTopics = "enterprise/site/area/line/";
69
+ const asset = resolveGeneratedAsset("asset");
70
+ const assetDescription = ""; // customize manually
71
+ mqttOutput.publishMqttMessage({
72
+ topic,
73
+ asset,
74
+ assetDescription,
75
+ objectType: GeneratedObjectTypes["resource-status"],
76
+ objectId: "main",
77
+ attributes: [
78
+ {
79
+ attribute: GeneratedAttributes["status"] ?? "status",
80
+ description: GeneratedAttributeDescriptions["status"] ?? "Table",
81
+ table: {
82
+ dataGroup,
83
+ time,
84
+ intervalStart,
85
+ intervalEnd,
86
+ columns,
87
+ },
88
+ },
89
+ ],
90
+ });
91
+ }
92
+ } catch (error) {
93
+ const reason = error instanceof Error ? error : new Error(String(error));
94
+ logger.error(`Error publishing message to MQTT: ${reason.message}`);
95
+ throw reason;
96
+ }
97
+ });