@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,41 +1,43 @@
1
- # __APP_NAME__
2
-
3
- Generated with `@uns-kit/cli`.
4
-
5
- Requires Node.js 22+ and pnpm (see `packageManager` in package.json).
6
-
7
- ## Scripts
8
-
9
- ```bash
10
- pnpm run dev # start the local development loop
11
- pnpm run build # emit dist/ output
12
- pnpm run start # run the compiled entrypoint
13
- pnpm run generate-config-schema # regenerate config.schema.json and AppConfig augmentations
14
- pnpm run generate-codegen # regenerate typed GraphQL operations (after configure-codegen)
15
- pnpm run generate-uns-topics-tags # rebuild UNS topics/tags from the live schema
16
- pnpm run generate-uns-dictionary # generate typed object/attribute dictionary from uns-dictionary.json
17
- pnpm run generate-uns-measurements # generate typed measurement units from uns-measurements.json
18
- pnpm run generate-uns-reference # run both dictionary + measurements generators
19
- ```
20
-
21
- ## Configuration
22
-
23
- Update `config.json` with your broker, UNS URLs, and credentials. The generated file contains sensible defaults for local development.
24
-
25
- ## Next Steps
26
-
27
- - Install additional plugins: `pnpm add @uns-kit/api` etc.
28
- - Create MQTT proxies or Temporal workflows inside `src/index.ts`.
29
- - Extend `src/config/project.config.extension.ts` with project-specific sections and run `pnpm run generate-config-schema` (reload your editor's TS server afterward if completions lag).
30
- - Run `uns-kit configure-devops` to add the Azure DevOps pull-request tooling.
31
- - Run `uns-kit configure-vscode` to copy workspace/launch configuration for VS Code.
32
- - Run `uns-kit configure-codegen` to scaffold GraphQL code generation and UNS refresh scripts.
33
- - Edit `uns-dictionary.json` (object types/attributes + descriptions) and run `pnpm run generate-uns-dictionary` to emit `src/uns/uns-dictionary.generated.ts` for IDE hints/metadata; publish calls will automatically fall back to these descriptions when you omit them.
34
- - Edit `uns-measurements.json` (units + descriptions) and run `pnpm run generate-uns-measurements` to emit `src/uns/uns-measurements.generated.ts` and feed measurement unit IntelliSense.
35
- - Run `uns-kit configure-api` / `configure-cron` / `configure-temporal` to pull in example stubs and install the matching UNS plugins (add `--overwrite` to refresh templates).
36
- - Run `uns-kit configure-python` to copy the Python gateway client template (examples, scripts, proto).
37
- - Commit your new project and start building!
38
-
39
- ## Agent Onboarding (for AI/code-assist tools)
40
-
41
- For agent guidance, see the local [`AGENTS.md`](./AGENTS.md).
1
+ # __APP_NAME__
2
+
3
+ Generated with `@uns-kit/cli`.
4
+
5
+ Requires Node.js 22+ and pnpm (see `packageManager` in package.json).
6
+
7
+ ## Scripts
8
+
9
+ ```bash
10
+ pnpm run dev # start the local development loop
11
+ pnpm run build # emit dist/ output
12
+ pnpm run start # run the compiled entrypoint
13
+ pnpm run generate-config-schema # regenerate config.schema.json and AppConfig augmentations
14
+ pnpm run generate-codegen # regenerate typed GraphQL operations (after configure-codegen)
15
+ pnpm run generate-uns-metadata # rebuild UNS topics/tags from the live schema
16
+ pnpm run generate-uns-dictionary # generate typed object/attribute dictionary from uns-dictionary.json
17
+ pnpm run generate-uns-measurements # generate typed measurement units from uns-measurements.json
18
+ pnpm run generate-uns-reference # run both dictionary + measurements generators
19
+ pnpm run sync-uns-schema -- --controller-url http://localhost:3200 --token <admin-bearer-token> # pull dictionary + measurements from the controller
20
+ ```
21
+
22
+ ## Configuration
23
+
24
+ Update `config.json` with your broker, UNS URLs, and credentials. The generated file contains sensible defaults for local development.
25
+
26
+ ## Next Steps
27
+
28
+ - Install additional plugins: `pnpm add @uns-kit/api` etc.
29
+ - Create MQTT proxies or Temporal workflows inside `src/index.ts`.
30
+ - Extend `src/config/project.config.extension.ts` with project-specific sections and run `pnpm run generate-config-schema` (reload your editor's TS server afterward if completions lag).
31
+ - Run `uns-kit configure-devops` to add the Azure DevOps pull-request tooling.
32
+ - Run `uns-kit configure-vscode` to copy workspace/launch configuration for VS Code.
33
+ - Run `uns-kit configure-codegen` to scaffold GraphQL code generation and UNS refresh scripts.
34
+ - Run `pnpm run sync-uns-schema -- --controller-url ... --token ...` to pull `uns-dictionary.json` and `uns-measurements.json` from the controller export into this project, then regenerate the typed files automatically.
35
+ - If you want to curate local files manually, edit `uns-dictionary.json` (object types/attributes + descriptions) and run `pnpm run generate-uns-dictionary` to emit `src/uns/uns-dictionary.generated.ts` for IDE hints/metadata; publish calls will automatically fall back to these descriptions when you omit them.
36
+ - Edit `uns-measurements.json` (units + descriptions) and run `pnpm run generate-uns-measurements` to emit `src/uns/uns-measurements.generated.ts` and feed measurement unit IntelliSense.
37
+ - Run `uns-kit configure-api` / `configure-cron` / `configure-temporal` to pull in example stubs and install the matching UNS plugins (add `--overwrite` to refresh templates).
38
+ - Run `uns-kit configure-python` to copy the Python gateway client template (examples, scripts, proto).
39
+ - Commit your new project and start building!
40
+
41
+ ## Agent Onboarding (for AI/code-assist tools)
42
+
43
+ For agent guidance, see the local [`AGENTS.md`](./AGENTS.md).
@@ -1,27 +1,27 @@
1
- {
2
- "uns": {
3
- "graphql": "http://localhost:3200/graphql",
4
- "rest": "http://localhost:3200/api",
5
- "processName": "__APP_NAME__",
6
- "instanceMode": "wait",
7
- "handover": true,
8
- "jwksWellKnownUrl": "http://localhost:3200/api/.well-known/jwks.json",
9
- "kidWellKnownUrl": "http://localhost:3200/api/.well-known/kid",
10
- "email": "user@example.com",
11
- "password": "123"
12
- },
13
- "infra": {
14
- "host": "localhost"
15
- },
16
- "output": {
17
- "host": "localhost"
18
- },
19
- "input": {
20
- "host": "localhost"
21
- },
22
- "devops": {
23
- "provider": "azure-devops",
24
- "organization": "example-org",
25
- "project": "example-project"
26
- }
27
- }
1
+ {
2
+ "uns": {
3
+ "graphql": "http://localhost:3200/graphql",
4
+ "rest": "http://localhost:3200/api",
5
+ "processName": "__APP_NAME__",
6
+ "instanceMode": "wait",
7
+ "handover": true,
8
+ "jwksWellKnownUrl": "http://localhost:3200/api/.well-known/jwks.json",
9
+ "kidWellKnownUrl": "http://localhost:3200/api/.well-known/kid",
10
+ "email": "user@example.com",
11
+ "password": "123"
12
+ },
13
+ "infra": {
14
+ "host": "localhost"
15
+ },
16
+ "output": {
17
+ "host": "localhost"
18
+ },
19
+ "input": {
20
+ "host": "localhost"
21
+ },
22
+ "devops": {
23
+ "provider": "azure-devops",
24
+ "organization": "example-org",
25
+ "project": "example-project"
26
+ }
27
+ }
@@ -1,30 +1,30 @@
1
- // eslint.config.js
2
-
3
- import { defineConfig } from 'eslint/config';
4
-
5
- export default defineConfig([
6
- // Apply to all source and test files
7
- {
8
- files: ['src/**/*', 'test/**/*'],
9
- ignores: ['dist/', 'node_modules/'], // Folders to ignore
10
- languageOptions: {
11
- parserOptions: {
12
- ecmaVersion: 'latest', // Use latest ECMAScript version
13
- sourceType: 'module', // Enable ES modules
14
- },
15
- },
16
- rules: {
17
- semi: ['warn', 'always'],
18
- },
19
- },
20
-
21
- // Override specifically for test files
22
- {
23
- files: ['test/**/*'],
24
- rules: {
25
- 'no-console': 'off',
26
- },
27
- },
28
-
29
- // Additional configurations can go here
30
- ]);
1
+ // eslint.config.js
2
+
3
+ import { defineConfig } from 'eslint/config';
4
+
5
+ export default defineConfig([
6
+ // Apply to all source and test files
7
+ {
8
+ files: ['src/**/*', 'test/**/*'],
9
+ ignores: ['dist/', 'node_modules/'], // Folders to ignore
10
+ languageOptions: {
11
+ parserOptions: {
12
+ ecmaVersion: 'latest', // Use latest ECMAScript version
13
+ sourceType: 'module', // Enable ES modules
14
+ },
15
+ },
16
+ rules: {
17
+ semi: ['warn', 'always'],
18
+ },
19
+ },
20
+
21
+ // Override specifically for test files
22
+ {
23
+ files: ['test/**/*'],
24
+ rules: {
25
+ 'no-console': 'off',
26
+ },
27
+ },
28
+
29
+ // Additional configurations can go here
30
+ ]);
@@ -1,51 +1,51 @@
1
- # Dependencies
2
- node_modules/
3
- .pnpm-store/
4
- .pnpm/
5
- .pnp.cjs
6
- .pnp.loader.mjs
7
-
8
- # Build outputs
9
- build/
10
- dist/
11
- tmp/
12
- temp/
13
- *.tsbuildinfo
14
-
15
- # Logs & diagnostics
16
- logs/
17
- *.log
18
- npm-debug.log*
19
- yarn-debug.log*
20
- pnpm-debug.log*
21
- lerna-debug.log*
22
-
23
- # Test & coverage artifacts
24
- coverage/
25
- .nyc_output/
26
- .vitest/
27
-
28
- # Runtime queues & sandboxes
29
- publisherQueue/
30
- sandbox-*
31
- tmp-rtt
32
- .tmp-rtt
33
-
34
- # Environment & secrets
35
- .env
36
- .env.*
37
- !.env.example
38
- !.env.sample
39
-
40
- # UNS configuration overrides
41
- config*.json
42
-
43
- # Editor files & OS cruft
44
- .idea/
45
- .DS_Store
46
- Thumbs.db
47
- *.swp
48
- *.swo
49
-
50
- # Package managers
51
- package-lock.json
1
+ # Dependencies
2
+ node_modules/
3
+ .pnpm-store/
4
+ .pnpm/
5
+ .pnp.cjs
6
+ .pnp.loader.mjs
7
+
8
+ # Build outputs
9
+ build/
10
+ dist/
11
+ tmp/
12
+ temp/
13
+ *.tsbuildinfo
14
+
15
+ # Logs & diagnostics
16
+ logs/
17
+ *.log
18
+ npm-debug.log*
19
+ yarn-debug.log*
20
+ pnpm-debug.log*
21
+ lerna-debug.log*
22
+
23
+ # Test & coverage artifacts
24
+ coverage/
25
+ .nyc_output/
26
+ .vitest/
27
+
28
+ # Runtime queues & sandboxes
29
+ publisherQueue/
30
+ sandbox-*
31
+ tmp-rtt
32
+ .tmp-rtt
33
+
34
+ # Environment & secrets
35
+ .env
36
+ .env.*
37
+ !.env.example
38
+ !.env.sample
39
+
40
+ # UNS configuration overrides
41
+ config*.json
42
+
43
+ # Editor files & OS cruft
44
+ .idea/
45
+ .DS_Store
46
+ Thumbs.db
47
+ *.swp
48
+ *.swo
49
+
50
+ # Package managers
51
+ package-lock.json
@@ -1,46 +1,49 @@
1
- {
2
- "name": "__APP_NAME__",
3
- "version": "0.0.0",
4
- "private": true,
5
- "description": "UNS application generated by @uns-kit/cli",
6
- "type": "module",
7
- "engines": {
8
- "node": ">=22"
9
- },
10
- "files": [
11
- "dist"
12
- ],
13
- "exports": {
14
- ".": {
15
- "types": "./dist/index.d.ts",
16
- "default": "./dist/index.js"
17
- }
18
- },
19
- "scripts": {
20
- "clean": "rimraf dist tsconfig.tsbuildinfo",
21
- "typecheck": "tsc --noEmit",
22
- "build": "pnpm run clean && tsc -p tsconfig.json",
23
- "dev": "tsx watch src/index.ts",
24
- "start": "node dist/index.js",
25
- "lint": "eslint src --ext .ts",
26
- "lint:fix": "eslint src --ext .ts --fix",
27
- "format": "prettier --write .",
28
- "format:check": "prettier --check .",
29
- "generate-config-schema": "node ./node_modules/@uns-kit/core/dist/tools/generate-config-schema.js",
30
- "generate-codegen": "graphql-code-generator --require dotenv/config --config codegen.ts",
31
- "generate-uns-metadata": "node ./node_modules/@uns-kit/core/dist/tools/refresh-uns.js",
32
- "generate-uns-measurements": "node ./node_modules/@uns-kit/core/dist/tools/generate-uns-measurements.js --input uns-measurements.json --output src/uns/uns-measurements.generated.ts"
33
- },
34
- "dependencies": {
35
- "@uns-kit/core": "__UNS_KIT_CORE_VERSION__",
36
- "zod": "^3.23.8"
37
- },
38
- "devDependencies": {
39
- "@types/node": "^22.19.1",
40
- "eslint": "^9.39.2",
41
- "prettier": "^3.8.0",
42
- "rimraf": "^6.1.2",
43
- "tsx": "^4.20.6",
44
- "typescript": "^5.9.3"
45
- }
46
- }
1
+ {
2
+ "name": "__APP_NAME__",
3
+ "version": "0.0.0",
4
+ "private": true,
5
+ "description": "UNS application generated by @uns-kit/cli",
6
+ "type": "module",
7
+ "engines": {
8
+ "node": ">=22"
9
+ },
10
+ "files": [
11
+ "dist"
12
+ ],
13
+ "exports": {
14
+ ".": {
15
+ "types": "./dist/index.d.ts",
16
+ "default": "./dist/index.js"
17
+ }
18
+ },
19
+ "scripts": {
20
+ "clean": "rimraf dist tsconfig.tsbuildinfo",
21
+ "typecheck": "tsc --noEmit",
22
+ "build": "pnpm run clean && tsc -p tsconfig.json",
23
+ "dev": "tsx watch src/index.ts",
24
+ "start": "node dist/index.js",
25
+ "lint": "eslint src --ext .ts",
26
+ "lint:fix": "eslint src --ext .ts --fix",
27
+ "format": "prettier --write .",
28
+ "format:check": "prettier --check .",
29
+ "generate-config-schema": "node ./node_modules/@uns-kit/core/dist/tools/generate-config-schema.js",
30
+ "generate-codegen": "graphql-code-generator --require dotenv/config --config codegen.ts",
31
+ "generate-uns-metadata": "node ./node_modules/@uns-kit/core/dist/tools/refresh-uns.js",
32
+ "generate-uns-dictionary": "node ./node_modules/@uns-kit/core/dist/tools/generate-uns-dictionary.js --input uns-dictionary.json --output src/uns/uns-dictionary.generated.ts",
33
+ "generate-uns-measurements": "node ./node_modules/@uns-kit/core/dist/tools/generate-uns-measurements.js --input uns-measurements.json --output src/uns/uns-measurements.generated.ts",
34
+ "generate-uns-reference": "node ./node_modules/@uns-kit/core/dist/tools/generate-uns-reference.js --dictionary uns-dictionary.json --dictionary-output src/uns/uns-dictionary.generated.ts --measurements uns-measurements.json --measurements-output src/uns/uns-measurements.generated.ts",
35
+ "sync-uns-schema": "node ./node_modules/@uns-kit/core/dist/tools/sync-uns-schema.js"
36
+ },
37
+ "dependencies": {
38
+ "@uns-kit/core": "__UNS_KIT_CORE_VERSION__",
39
+ "zod": "^3.23.8"
40
+ },
41
+ "devDependencies": {
42
+ "@types/node": "^22.19.1",
43
+ "eslint": "^9.39.2",
44
+ "prettier": "^3.8.0",
45
+ "rimraf": "^6.1.2",
46
+ "tsx": "^4.20.6",
47
+ "typescript": "^5.9.3"
48
+ }
49
+ }
@@ -1,23 +1,23 @@
1
- import { z } from "zod";
2
- import { secretValueSchema } from "@uns-kit/core/uns-config/secret-placeholders.js";
3
- import { hostValueSchema } from "@uns-kit/core/uns-config/host-placeholders.js";
4
-
5
- // Extend this schema with project-specific configuration sections.
6
- export const projectExtrasSchema = z.object({
7
- pg: z.object({
8
- user: z.string().min(1, "pg.user is required"),
9
- host: hostValueSchema,
10
- port: z.number().int().positive().default(5432),
11
- ssl: z.boolean().default(false),
12
- database: z.string().min(1, "pg.database is required"),
13
- isPoolConnection: z.boolean().default(false),
14
- password: secretValueSchema.optional(),
15
- }),
16
-
17
- caddy: z.object({
18
- adminUrl: z.string().url(),
19
- proxyHost: z.string().url(),
20
- }),
21
- });
22
-
23
- export type ProjectExtras = z.infer<typeof projectExtrasSchema>;
1
+ import { z } from "zod";
2
+ import { secretValueSchema } from "@uns-kit/core/uns-config/secret-placeholders.js";
3
+ import { hostValueSchema } from "@uns-kit/core/uns-config/host-placeholders.js";
4
+
5
+ // Extend this schema with project-specific configuration sections.
6
+ export const projectExtrasSchema = z.object({
7
+ pg: z.object({
8
+ user: z.string().min(1, "pg.user is required"),
9
+ host: hostValueSchema,
10
+ port: z.number().int().positive().default(5432),
11
+ ssl: z.boolean().default(false),
12
+ database: z.string().min(1, "pg.database is required"),
13
+ isPoolConnection: z.boolean().default(false),
14
+ password: secretValueSchema.optional(),
15
+ }),
16
+
17
+ caddy: z.object({
18
+ adminUrl: z.string().url(),
19
+ proxyHost: z.string().url(),
20
+ }),
21
+ });
22
+
23
+ export type ProjectExtras = z.infer<typeof projectExtrasSchema>;
@@ -1,6 +1,6 @@
1
- import { z } from "zod";
2
-
3
- // Extend this schema with project-specific configuration sections.
4
- export const projectExtrasSchema = z.object({});
5
-
6
- export type ProjectExtras = z.infer<typeof projectExtrasSchema>;
1
+ import { z } from "zod";
2
+
3
+ // Extend this schema with project-specific configuration sections.
4
+ export const projectExtrasSchema = z.object({});
5
+
6
+ export type ProjectExtras = z.infer<typeof projectExtrasSchema>;
@@ -1,86 +1,86 @@
1
- /**
2
- * Change this file according to your specifications and rename it to index.ts
3
- */
4
- import { UnsProxyProcess, ConfigFile, getLogger } from "@uns-kit/core";
5
- import { registerAttributeDescriptions, registerObjectTypeDescriptions } from "@uns-kit/core/uns/uns-dictionary-registry.js";
6
- import { GeneratedPhysicalMeasurements } from "../uns/uns-measurements.generated.js";
7
- import { UnsTopics } from "@uns-kit/core/uns/uns-topics.js";
8
- import {
9
- GeneratedObjectTypes,
10
- GeneratedAttributes,
11
- GeneratedAttributesByType,
12
- GeneratedObjectTypeDescriptions,
13
- } from "../uns/uns-dictionary.generated.js";
14
- import { GeneratedAssets, resolveGeneratedAsset } from "../uns/uns-assets.js";
15
- import type { ISO8601 } from "@uns-kit/core/uns/uns-interfaces.js";
16
-
17
- const logger = getLogger(import.meta.url);
18
-
19
- /**
20
- * Load the configuration from a file.
21
- * On the server, this file is provided by the `uns-datahub-controller`.
22
- * In the development environment, you are responsible for creating and maintaining this file and its contents.
23
- */
24
- const config = await ConfigFile.loadConfig();
25
- registerObjectTypeDescriptions(GeneratedObjectTypeDescriptions);
26
-
27
- /**
28
- * Connect to input and output brokers
29
- */
30
- const unsProxyProcess = new UnsProxyProcess(config.infra.host!, {processName: config.uns.processName!});
31
- const mqttInput = await unsProxyProcess.createUnsMqttProxy((config.input?.host)!, "templateUnsRttInput", config.uns.instanceMode!, config.uns.handover!, {
32
- mqttSubToTopics: ["raw/#"],
33
- });
34
- const mqttOutput = await unsProxyProcess.createUnsMqttProxy((config.output?.host)!, "templateUnsRttOutput", config.uns.instanceMode!, config.uns.handover!, { publishThrottlingDelay: 1000});
35
-
36
-
37
- /**
38
- * Event listener for input events.
39
- * Transform an input message and publish it with publishMqttMessage function.
40
- */
41
- mqttInput.event.on("input", async (event) => {
42
- try {
43
- if (event.topic === "raw/data") {
44
- const values = event.message.split(",");
45
- const [countRaw, timestampRaw, sensorRaw] = values;
46
- if (!countRaw || !timestampRaw || !sensorRaw) {
47
- logger.warn(`Skipping malformed raw/data payload: ${event.message}`);
48
- return;
49
- }
50
- const numberValue = Number.parseFloat(countRaw);
51
- const eventDate = new Date(Number.parseInt(timestampRaw, 10));
52
- const sensorValue = Number.parseFloat(sensorRaw);
53
- const time: ISO8601 = eventDate.toISOString() as ISO8601;
54
- const intervalStart: ISO8601 = new Date(eventDate.getTime() - 1000).toISOString() as ISO8601;
55
- const intervalEnd: ISO8601 = eventDate.toISOString() as ISO8601;
56
-
57
- const dataGroup = "sensor";
58
-
59
- const topic: UnsTopics = "enterprise/site/area/line/";
60
- const asset = resolveGeneratedAsset("asset");
61
- const assetDescription = ""; // customize manually
62
-
63
- mqttOutput.publishMqttMessage({
64
- topic,
65
- asset,
66
- assetDescription,
67
- objectType: GeneratedObjectTypes["energy-resource"],
68
- objectId: "main",
69
- attributes: [
70
- {
71
- attribute: GeneratedAttributesByType["energy-resource"]["current"],
72
- data: { dataGroup, time, value: numberValue, uom: GeneratedPhysicalMeasurements.Ampere, intervalStart, intervalEnd },
73
- },
74
- {
75
- attribute: GeneratedAttributes["voltage"],
76
- data: { dataGroup, time, value: sensorValue, uom: GeneratedPhysicalMeasurements.Volt, intervalStart, intervalEnd },
77
- },
78
- ],
79
- });
80
- }
81
- } catch (error) {
82
- const reason = error instanceof Error ? error : new Error(String(error));
83
- logger.error(`Error publishing message to MQTT: ${reason.message}`);
84
- throw reason;
85
- }
86
- });
1
+ /**
2
+ * Change this file according to your specifications and rename it to index.ts
3
+ */
4
+ import { UnsProxyProcess, ConfigFile, getLogger } from "@uns-kit/core";
5
+ import { registerAttributeDescriptions, registerObjectTypeDescriptions } from "@uns-kit/core/uns/uns-dictionary-registry.js";
6
+ import { GeneratedPhysicalMeasurements } from "../uns/uns-measurements.generated.js";
7
+ import { UnsTopics } from "@uns-kit/core/uns/uns-topics.js";
8
+ import {
9
+ GeneratedObjectTypes,
10
+ GeneratedAttributes,
11
+ GeneratedAttributesByType,
12
+ GeneratedObjectTypeDescriptions,
13
+ } from "../uns/uns-dictionary.generated.js";
14
+ import { GeneratedAssets, resolveGeneratedAsset } from "../uns/uns-assets.js";
15
+ import type { ISO8601 } from "@uns-kit/core/uns/uns-interfaces.js";
16
+
17
+ const logger = getLogger(import.meta.url);
18
+
19
+ /**
20
+ * Load the configuration from a file.
21
+ * On the server, this file is provided by the `uns-datahub-controller`.
22
+ * In the development environment, you are responsible for creating and maintaining this file and its contents.
23
+ */
24
+ const config = await ConfigFile.loadConfig();
25
+ registerObjectTypeDescriptions(GeneratedObjectTypeDescriptions);
26
+
27
+ /**
28
+ * Connect to input and output brokers
29
+ */
30
+ const unsProxyProcess = new UnsProxyProcess(config.infra.host!, {processName: config.uns.processName!});
31
+ const mqttInput = await unsProxyProcess.createUnsMqttProxy((config.input?.host)!, "templateUnsRttInput", config.uns.instanceMode!, config.uns.handover!, {
32
+ mqttSubToTopics: ["raw/#"],
33
+ });
34
+ const mqttOutput = await unsProxyProcess.createUnsMqttProxy((config.output?.host)!, "templateUnsRttOutput", config.uns.instanceMode!, config.uns.handover!, { publishThrottlingDelay: 1000});
35
+
36
+
37
+ /**
38
+ * Event listener for input events.
39
+ * Transform an input message and publish it with publishMqttMessage function.
40
+ */
41
+ mqttInput.event.on("input", async (event) => {
42
+ try {
43
+ if (event.topic === "raw/data") {
44
+ const values = event.message.split(",");
45
+ const [countRaw, timestampRaw, sensorRaw] = values;
46
+ if (!countRaw || !timestampRaw || !sensorRaw) {
47
+ logger.warn(`Skipping malformed raw/data payload: ${event.message}`);
48
+ return;
49
+ }
50
+ const numberValue = Number.parseFloat(countRaw);
51
+ const eventDate = new Date(Number.parseInt(timestampRaw, 10));
52
+ const sensorValue = Number.parseFloat(sensorRaw);
53
+ const time: ISO8601 = eventDate.toISOString() as ISO8601;
54
+ const intervalStart: ISO8601 = new Date(eventDate.getTime() - 1000).toISOString() as ISO8601;
55
+ const intervalEnd: ISO8601 = eventDate.toISOString() as ISO8601;
56
+
57
+ const dataGroup = "sensor";
58
+
59
+ const topic: UnsTopics = "enterprise/site/area/line/";
60
+ const asset = resolveGeneratedAsset("asset");
61
+ const assetDescription = ""; // customize manually
62
+
63
+ mqttOutput.publishMqttMessage({
64
+ topic,
65
+ asset,
66
+ assetDescription,
67
+ objectType: GeneratedObjectTypes["energy-resource"],
68
+ objectId: "main",
69
+ attributes: [
70
+ {
71
+ attribute: GeneratedAttributesByType["energy-resource"]["current"],
72
+ data: { dataGroup, time, value: numberValue, uom: GeneratedPhysicalMeasurements.Ampere, intervalStart, intervalEnd },
73
+ },
74
+ {
75
+ attribute: GeneratedAttributes["voltage"],
76
+ data: { dataGroup, time, value: sensorValue, uom: GeneratedPhysicalMeasurements.Volt, intervalStart, intervalEnd },
77
+ },
78
+ ],
79
+ });
80
+ }
81
+ } catch (error) {
82
+ const reason = error instanceof Error ? error : new Error(String(error));
83
+ logger.error(`Error publishing message to MQTT: ${reason.message}`);
84
+ throw reason;
85
+ }
86
+ });