@uns-kit/cli 0.0.36 → 0.0.37

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 (46) hide show
  1. package/LICENSE +21 -21
  2. package/README.md +128 -128
  3. package/dist/index.js +11 -5
  4. package/package.json +8 -2
  5. package/templates/api/src/examples/api-example.ts +62 -62
  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/src/examples/cron-example.ts +46 -46
  13. package/templates/default/README.md +32 -30
  14. package/templates/default/config.json +27 -27
  15. package/templates/default/gitignore +51 -51
  16. package/templates/default/package.json +38 -19
  17. package/templates/default/src/config/project.config.extension.example +23 -23
  18. package/templates/default/src/config/project.config.extension.ts +6 -6
  19. package/templates/default/src/examples/data-example.ts +68 -68
  20. package/templates/default/src/examples/load-test-data.ts +108 -108
  21. package/templates/default/src/examples/table-example.ts +66 -66
  22. package/templates/default/src/examples/uns-gateway-cli.ts +7 -7
  23. package/templates/default/src/index.ts +15 -15
  24. package/templates/default/src/uns/uns-tags.ts +2 -2
  25. package/templates/default/src/uns/uns-topics.ts +2 -2
  26. package/templates/default/tsconfig.json +29 -16
  27. package/templates/python/app/README.md +8 -8
  28. package/templates/python/examples/README.md +134 -134
  29. package/templates/python/examples/api_handler.py +28 -28
  30. package/templates/python/examples/data_publish.py +11 -11
  31. package/templates/python/examples/data_subscribe.py +8 -8
  32. package/templates/python/examples/data_transformer.py +17 -17
  33. package/templates/python/examples/table_transformer.py +15 -15
  34. package/templates/python/gateway/cli.py +75 -75
  35. package/templates/python/gateway/client.py +155 -155
  36. package/templates/python/gateway/manager.py +97 -97
  37. package/templates/python/proto/uns-gateway.proto +102 -102
  38. package/templates/python/pyproject.toml +4 -4
  39. package/templates/python/scripts/setup.sh +87 -87
  40. package/templates/temporal/src/examples/temporal-example.ts +35 -35
  41. package/templates/vscode/.vscode/launch.json +164 -164
  42. package/templates/vscode/.vscode/settings.json +9 -9
  43. package/templates/vscode/uns-kit.code-workspace +13 -13
  44. package/templates/python/gen/__init__.py +0 -1
  45. package/templates/python/gen/uns_gateway_pb2.py +0 -70
  46. package/templates/python/gen/uns_gateway_pb2_grpc.py +0 -312
@@ -1,108 +1,108 @@
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, logger } from "@uns-kit/core.js";
8
- import UnsMqttProxy from "@uns-kit/core/uns-mqtt/uns-mqtt-proxy.js";
9
-
10
- /**
11
- * Produces a smooth oscillating value to mimic a real-world sensor signal.
12
- * Combines fast and slow sine waves plus tiny ripple so that subsequent values
13
- * rise and fall without appearing purely random.
14
- */
15
- function simulateSensorValue(step: number): number {
16
- const baseValue = 42; // arbitrary midpoint for the simulated signal
17
- const fastCycle = Math.sin(step / 5) * 3;
18
- const slowCycle = Math.sin(step / 25) * 6;
19
- const ripple = Math.sin(step / 2 + Math.PI / 4) * 0.5;
20
- const value = baseValue + fastCycle + slowCycle + ripple;
21
-
22
- return Number(value.toFixed(2));
23
- }
24
-
25
- /**
26
- * This script initializes an MQTT output proxy for load testing purposes.
27
- * It sets up a connection to the specified MQTT broker and configures
28
- * a proxy instance. The load test is designed to evaluate the performance
29
- * and reliability of the MQTT broker under simulated load conditions.
30
- */
31
- async function main() {
32
- try {
33
- const config = await ConfigFile.loadConfig();
34
- const outputHost = (config.output?.host)!;
35
-
36
- const mqttOutput = new UnsMqttProxy(
37
- outputHost,
38
- "loadTest",
39
- "templateUnsRttLoadTest",
40
- { publishThrottlingDelay: 0 },
41
- true
42
- );
43
-
44
- const rl = readline.createInterface({
45
- input: process.stdin,
46
- output: process.stdout,
47
- });
48
-
49
- await new Promise((resolve) => setTimeout(resolve, 1000));
50
-
51
- rl.question(`Would you like to continue with load-test on ${outputHost}? (Y/n) `, async (answer) => {
52
- if (answer.toLowerCase() === "y" || answer.trim() === "") {
53
- rl.question("How many iterations should be run? (default is 100) ", async (iterations) => {
54
- const maxIntervals = parseInt(iterations) || 100;
55
-
56
- rl.question("What should be the delay between intervals in milliseconds? (default is 0 ms) ", async (intervalDelay) => {
57
- const delay = parseInt(intervalDelay) || 0;
58
-
59
- logger.info(`Starting load test with ${maxIntervals} messages and ${delay} ms delay...`);
60
-
61
- let count = 0;
62
- const startTime = Date.now();
63
-
64
- while (count < maxIntervals) {
65
- try {
66
- const currentDate = new Date();
67
- const sensorValue = simulateSensorValue(count);
68
- const rawData = `${count},${currentDate.getTime()},${sensorValue}`;
69
- await mqttOutput.publishMessage("raw/data", rawData);
70
- } catch (error) {
71
- const reason = error instanceof Error ? error : new Error(String(error));
72
- logger.error("Error publishing message:", reason.message);
73
- }
74
-
75
- count++;
76
- if (delay > 0) {
77
- await new Promise((resolve) => setTimeout(resolve, delay));
78
- }
79
- }
80
-
81
- logger.info(`Sleeping for 50ms.`);
82
- await new Promise((resolve) => setTimeout(resolve, 50));
83
-
84
- const endTime = Date.now();
85
- const duration = (endTime - startTime) / 1000;
86
- const messagesPerSecond = maxIntervals / duration;
87
-
88
- logger.info(`Load test completed in ${duration.toFixed(2)} seconds.`);
89
- logger.info(`Message rate: ${messagesPerSecond.toFixed(2)} msg/s.`);
90
-
91
- rl.close();
92
- process.exit(0);
93
- });
94
- });
95
- } else {
96
- logger.info("Load test aborted.");
97
- rl.close();
98
- process.exit(0);
99
- }
100
- });
101
- } catch (error) {
102
- const reason = error instanceof Error ? error : new Error(String(error));
103
- logger.error("Error initializing load test:", reason.message);
104
- process.exit(1);
105
- }
106
- }
107
-
108
- 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, logger } from "@uns-kit/core";
8
+ import UnsMqttProxy from "@uns-kit/core/uns-mqtt/uns-mqtt-proxy.js";
9
+
10
+ /**
11
+ * Produces a smooth oscillating value to mimic a real-world sensor signal.
12
+ * Combines fast and slow sine waves plus tiny ripple so that subsequent values
13
+ * rise and fall without appearing purely random.
14
+ */
15
+ function simulateSensorValue(step: number): number {
16
+ const baseValue = 42; // arbitrary midpoint for the simulated signal
17
+ const fastCycle = Math.sin(step / 5) * 3;
18
+ const slowCycle = Math.sin(step / 25) * 6;
19
+ const ripple = Math.sin(step / 2 + Math.PI / 4) * 0.5;
20
+ const value = baseValue + fastCycle + slowCycle + ripple;
21
+
22
+ return Number(value.toFixed(2));
23
+ }
24
+
25
+ /**
26
+ * This script initializes an MQTT output proxy for load testing purposes.
27
+ * It sets up a connection to the specified MQTT broker and configures
28
+ * a proxy instance. The load test is designed to evaluate the performance
29
+ * and reliability of the MQTT broker under simulated load conditions.
30
+ */
31
+ async function main() {
32
+ try {
33
+ const config = await ConfigFile.loadConfig();
34
+ const outputHost = (config.output?.host)!;
35
+
36
+ const mqttOutput = new UnsMqttProxy(
37
+ outputHost,
38
+ "loadTest",
39
+ "templateUnsRttLoadTest",
40
+ { publishThrottlingDelay: 0 },
41
+ true
42
+ );
43
+
44
+ const rl = readline.createInterface({
45
+ input: process.stdin,
46
+ output: process.stdout,
47
+ });
48
+
49
+ await new Promise((resolve) => setTimeout(resolve, 1000));
50
+
51
+ rl.question(`Would you like to continue with load-test on ${outputHost}? (Y/n) `, async (answer) => {
52
+ if (answer.toLowerCase() === "y" || answer.trim() === "") {
53
+ rl.question("How many iterations should be run? (default is 100) ", async (iterations) => {
54
+ const maxIntervals = parseInt(iterations) || 100;
55
+
56
+ rl.question("What should be the delay between intervals in milliseconds? (default is 0 ms) ", async (intervalDelay) => {
57
+ const delay = parseInt(intervalDelay) || 0;
58
+
59
+ logger.info(`Starting load test with ${maxIntervals} messages and ${delay} ms delay...`);
60
+
61
+ let count = 0;
62
+ const startTime = Date.now();
63
+
64
+ while (count < maxIntervals) {
65
+ try {
66
+ const currentDate = new Date();
67
+ const sensorValue = simulateSensorValue(count);
68
+ const rawData = `${count},${currentDate.getTime()},${sensorValue}`;
69
+ await mqttOutput.publishMessage("raw/data", rawData);
70
+ } catch (error) {
71
+ const reason = error instanceof Error ? error : new Error(String(error));
72
+ logger.error("Error publishing message:", reason.message);
73
+ }
74
+
75
+ count++;
76
+ if (delay > 0) {
77
+ await new Promise((resolve) => setTimeout(resolve, delay));
78
+ }
79
+ }
80
+
81
+ logger.info(`Sleeping for 50ms.`);
82
+ await new Promise((resolve) => setTimeout(resolve, 50));
83
+
84
+ const endTime = Date.now();
85
+ const duration = (endTime - startTime) / 1000;
86
+ const messagesPerSecond = maxIntervals / duration;
87
+
88
+ logger.info(`Load test completed in ${duration.toFixed(2)} seconds.`);
89
+ logger.info(`Message rate: ${messagesPerSecond.toFixed(2)} msg/s.`);
90
+
91
+ rl.close();
92
+ process.exit(0);
93
+ });
94
+ });
95
+ } else {
96
+ logger.info("Load test aborted.");
97
+ rl.close();
98
+ process.exit(0);
99
+ }
100
+ });
101
+ } catch (error) {
102
+ const reason = error instanceof Error ? error : new Error(String(error));
103
+ logger.error("Error initializing load test:", reason.message);
104
+ process.exit(1);
105
+ }
106
+ }
107
+
108
+ main();
@@ -1,66 +1,66 @@
1
- /**
2
- * Change this file according to your specifications and rename it to index.ts
3
- */
4
-
5
- import { UnsProxyProcess, ConfigFile, logger, type IUnsMessage } from "@uns-kit/core.js";
6
- import { UnsPacket } from "@uns-kit/core/uns/uns-packet.js";
7
- import { UnsTags } from "@uns-kit/core/uns/uns-tags.js";
8
- import { UnsTopics } from "@uns-kit/core/uns/uns-topics.js";
9
-
10
- /**
11
- * Load the configuration from a file.
12
- * On the server, this file is provided by the `uns-datahub-controller`.
13
- * In the development environment, you are responsible for creating and maintaining this file and its contents.
14
- */
15
- const config = await ConfigFile.loadConfig();
16
-
17
- /**
18
- * Load and configure input and output brokers from config.json
19
- */
20
- 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!, {
22
- mqttSubToTopics: ["integration/raw-table"],
23
- publishThrottlingDelay:0,
24
- subscribeThrottlingDelay:0
25
- });
26
- const mqttOutput = await unsProxyProcess.createUnsMqttProxy((config.output?.host)!, "templateUnsRttOutput", config.uns.instanceMode!, config.uns.handover!, {
27
- publishThrottlingDelay:0,
28
- subscribeThrottlingDelay:0
29
- });
30
-
31
- /**
32
- * The input worker connects to the upstream broker and listens for incoming messages.
33
- * It processes the messages and transforms them into a table-type IUnsMessage.
34
- * The resulting message is published to the output broker.
35
- */
36
- mqttInput.event.on("input", async (event) => {
37
- try {
38
- if (event.topic === "integration/raw-table") {
39
- const x = 10;
40
- const a = `{
41
- "kolona_a": "${x}",
42
- "kolona_b": "1",
43
- "kolona_c"; "${x}",
44
- "kolona_d": 3
45
- }`;
46
- type questDbCoulmnTypes = "number" | "float" | "string";
47
- const columnTypes:questDbCoulmnTypes[] = ['number', 'float', 'string', 'number', 'number'];
48
-
49
- const jsonObject = JSON.parse(a);
50
- const timestamp = jsonObject.Timestamp;
51
- // delete(jsonObject.Timestamp);
52
-
53
- const time = UnsPacket.formatToISO8601(new Date(timestamp));
54
- // const message: IUnsMessage = { table: {dataGroup:"demo_table", values:jsonObject, columnTypes, time}};
55
- const message: IUnsMessage = { table: {dataGroup:"demo_table", values:jsonObject, time}};
56
- const topic: UnsTopics = "example/factory-a/line-1/";
57
- const tags: UnsTags[] = [];
58
- const packet = await UnsPacket.unsPacketFromUnsMessage(message);
59
- mqttOutput.publishMqttMessage({ topic, attribute: "table-sample", packet, description: "Table", tags });
60
- }
61
- } catch (error) {
62
- const reason = error instanceof Error ? error : new Error(String(error));
63
- logger.error(`Error publishing message to MQTT: ${reason.message}`);
64
- throw reason;
65
- }
66
- });
1
+ /**
2
+ * Change this file according to your specifications and rename it to index.ts
3
+ */
4
+
5
+ import { UnsProxyProcess, ConfigFile, logger, type IUnsMessage } from "@uns-kit/core";
6
+ import { UnsPacket } from "@uns-kit/core/uns/uns-packet.js";
7
+ import { UnsTags } from "@uns-kit/core/uns/uns-tags.js";
8
+ import { UnsTopics } from "@uns-kit/core/uns/uns-topics.js";
9
+
10
+ /**
11
+ * Load the configuration from a file.
12
+ * On the server, this file is provided by the `uns-datahub-controller`.
13
+ * In the development environment, you are responsible for creating and maintaining this file and its contents.
14
+ */
15
+ const config = await ConfigFile.loadConfig();
16
+
17
+ /**
18
+ * Load and configure input and output brokers from config.json
19
+ */
20
+ 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!, {
22
+ mqttSubToTopics: ["integration/raw-table"],
23
+ publishThrottlingDelay:0,
24
+ subscribeThrottlingDelay:0
25
+ });
26
+ const mqttOutput = await unsProxyProcess.createUnsMqttProxy((config.output?.host)!, "templateUnsRttOutput", config.uns.instanceMode!, config.uns.handover!, {
27
+ publishThrottlingDelay:0,
28
+ subscribeThrottlingDelay:0
29
+ });
30
+
31
+ /**
32
+ * The input worker connects to the upstream broker and listens for incoming messages.
33
+ * It processes the messages and transforms them into a table-type IUnsMessage.
34
+ * The resulting message is published to the output broker.
35
+ */
36
+ mqttInput.event.on("input", async (event) => {
37
+ try {
38
+ if (event.topic === "integration/raw-table") {
39
+ const x = 10;
40
+ const a = `{
41
+ "kolona_a": "${x}",
42
+ "kolona_b": "1",
43
+ "kolona_c"; "${x}",
44
+ "kolona_d": 3
45
+ }`;
46
+ type questDbCoulmnTypes = "number" | "float" | "string";
47
+ const columnTypes:questDbCoulmnTypes[] = ['number', 'float', 'string', 'number', 'number'];
48
+
49
+ const jsonObject = JSON.parse(a);
50
+ const timestamp = jsonObject.Timestamp;
51
+ // delete(jsonObject.Timestamp);
52
+
53
+ const time = UnsPacket.formatToISO8601(new Date(timestamp));
54
+ // const message: IUnsMessage = { table: {dataGroup:"demo_table", values:jsonObject, columnTypes, time}};
55
+ const message: IUnsMessage = { table: {dataGroup:"demo_table", values:jsonObject, time}};
56
+ const topic: UnsTopics = "example/factory-a/line-1/";
57
+ const tags: UnsTags[] = [];
58
+ const packet = await UnsPacket.unsPacketFromUnsMessage(message);
59
+ mqttOutput.publishMqttMessage({ topic, attribute: "table-sample", packet, description: "Table", tags });
60
+ }
61
+ } catch (error) {
62
+ const reason = error instanceof Error ? error : new Error(String(error));
63
+ logger.error(`Error publishing message to MQTT: ${reason.message}`);
64
+ throw reason;
65
+ }
66
+ });
@@ -1,7 +1,7 @@
1
- import { startUnsGateway } from "@uns-kit/core/uns-grpc/uns-gateway-server.js";
2
-
3
- const addr = await startUnsGateway();
4
- console.log(`UNS Gateway listening on ${addr.address} (UDS=${addr.isUDS})`);
5
- // Keep alive
6
- setInterval(() => {}, 1 << 30);
7
-
1
+ import { startUnsGateway } from "@uns-kit/core/uns-grpc/uns-gateway-server.js";
2
+
3
+ const addr = await startUnsGateway();
4
+ console.log(`UNS Gateway listening on ${addr.address} (UDS=${addr.isUDS})`);
5
+ // Keep alive
6
+ setInterval(() => {}, 1 << 30);
7
+
@@ -1,15 +1,15 @@
1
- import { UnsProxyProcess } from "@uns-kit/core.js";
2
-
3
- async function main(): Promise<void> {
4
- const name = "__APP_NAME__";
5
- const process = new UnsProxyProcess("localhost:1883", {
6
- processName: name,
7
- });
8
-
9
- console.log(`UNS process '${name}' is ready. Edit src/index.ts to add your logic.`);
10
-
11
- // Keep the process alive or add plugin logic here
12
- void process;
13
- }
14
-
15
- void main();
1
+ import { UnsProxyProcess } from "@uns-kit/core";
2
+
3
+ async function main(): Promise<void> {
4
+ const name = "__APP_NAME__";
5
+ const process = new UnsProxyProcess("localhost:1883", {
6
+ processName: name,
7
+ });
8
+
9
+ console.log(`UNS process '${name}' is ready. Edit src/index.ts to add your logic.`);
10
+
11
+ // Keep the process alive or add plugin logic here
12
+ void process;
13
+ }
14
+
15
+ void main();
@@ -1,2 +1,2 @@
1
- // Generated UNS tag union. Run `pnpm refresh-uns` to update.
2
- export type UnsTags = string & {};
1
+ // Generated UNS tag union. Run `pnpm refresh-uns` to update.
2
+ export type UnsTags = string & {};
@@ -1,2 +1,2 @@
1
- // Generated UNS topic union. Run `pnpm refresh-uns` to update.
2
- export type UnsTopics = string & {};
1
+ // Generated UNS topic union. Run `pnpm refresh-uns` to update.
2
+ export type UnsTopics = string & {};
@@ -1,16 +1,29 @@
1
- {
2
- "compilerOptions": {
3
- "target": "ES2022",
4
- "lib": ["ES2022"],
5
- "module": "es2022",
6
- "moduleResolution": "bundler",
7
- "noEmit": false,
8
- "outDir": "dist",
9
- "rootDir": "src",
10
- "strict": true,
11
- "skipLibCheck": true,
12
- "esModuleInterop": true,
13
- "resolveJsonModule": true
14
- },
15
- "include": ["src/**/*.ts"]
16
- }
1
+ {
2
+ "compilerOptions": {
3
+ "target": "ES2023",
4
+ "lib": ["ES2023"],
5
+ "module": "NodeNext",
6
+ "moduleResolution": "NodeNext",
7
+ "moduleDetection": "force",
8
+ "noEmit": false,
9
+ "declaration": true,
10
+ "declarationMap": true,
11
+ "outDir": "dist",
12
+ "rootDir": "src",
13
+ "strict": true,
14
+ "exactOptionalPropertyTypes": true,
15
+ "noImplicitOverride": true,
16
+ "noPropertyAccessFromIndexSignature": true,
17
+ "noUncheckedIndexedAccess": true,
18
+ "useDefineForClassFields": true,
19
+ "forceConsistentCasingInFileNames": true,
20
+ "skipLibCheck": true,
21
+ "esModuleInterop": true,
22
+ "resolveJsonModule": true,
23
+ "incremental": true,
24
+ "isolatedModules": true,
25
+ "sourceMap": true,
26
+ "types": ["node"]
27
+ },
28
+ "include": ["src/**/*.ts"]
29
+ }
@@ -1,8 +1,8 @@
1
- This folder is reserved for your project-specific Python code.
2
-
3
- The update tools will NOT overwrite `python/app/**` (and also preserve legacy `python/rtt/**`, `python/venv`, `python/.venv`, and `python/__pycache__`).
4
-
5
- Suggested layout:
6
- - `python/app/` your packages, modules, or CLI scripts
7
- - Reference the gateway client in `python/gateway_client.py` if you interact with the UNS gateway from Python
8
-
1
+ This folder is reserved for your project-specific Python code.
2
+
3
+ The update tools will NOT overwrite `python/app/**` (and also preserve legacy `python/rtt/**`, `python/venv`, `python/.venv`, and `python/__pycache__`).
4
+
5
+ Suggested layout:
6
+ - `python/app/` your packages, modules, or CLI scripts
7
+ - Reference the gateway client in `python/gateway_client.py` if you interact with the UNS gateway from Python
8
+