@uns-kit/cli 2.0.67 → 2.0.69

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@uns-kit/cli",
3
- "version": "2.0.67",
3
+ "version": "2.0.69",
4
4
  "description": "Command line scaffolding tool for UNS applications",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -26,13 +26,13 @@
26
26
  ],
27
27
  "dependencies": {
28
28
  "azure-devops-node-api": "^15.1.1",
29
- "@uns-kit/core": "2.0.67"
29
+ "@uns-kit/core": "2.0.69"
30
30
  },
31
31
  "unsKitPackages": {
32
- "@uns-kit/core": "2.0.67",
33
- "@uns-kit/api": "2.0.67",
34
- "@uns-kit/cron": "2.0.67",
35
- "@uns-kit/database": "2.0.67"
32
+ "@uns-kit/core": "2.0.69",
33
+ "@uns-kit/api": "2.0.69",
34
+ "@uns-kit/cron": "2.0.69",
35
+ "@uns-kit/database": "2.0.69"
36
36
  },
37
37
  "scripts": {
38
38
  "build": "tsc -p tsconfig.build.json",
@@ -55,6 +55,19 @@ shows how a producer publishes:
55
55
  These fields are retained in the produced-topics registry and stored by the
56
56
  UNS Datahub controller in `attribute_schema.schema_json`.
57
57
 
58
+ ## Sub-Asset Publishing
59
+
60
+ The template includes `src/examples/subasset-example.ts`, which shows the V1
61
+ sub-asset convention:
62
+
63
+ - put the full parent asset path in `topic`
64
+ - put only the leaf sub-asset name in `asset`
65
+
66
+ For example, `topic: "enterprise/site/area/line-1/"` and `asset: "pump-1"`
67
+ publish `enterprise/site/area/line-1/pump-1/equipment/main/temperature`.
68
+ Downstream QuestDB storage keeps the existing columns: `topic` is the parent
69
+ asset path and `asset` is the leaf sub-asset.
70
+
58
71
  ## Datahub client (last value)
59
72
 
60
73
  `UnsClient` provides a minimal REST client for the UNS Datahub API, including the batch last-value endpoint. Prefer a long-lived service token if available; you can pass it directly and skip username/password auth.
@@ -0,0 +1,76 @@
1
+ /**
2
+ * Example: publish a sub-asset under an existing parent asset.
3
+ *
4
+ * V1 sub-assets use the normal UNS publish fields:
5
+ * - topic is the full parent asset path
6
+ * - asset is only the leaf sub-asset name
7
+ */
8
+ import { ConfigFile, UnsProxyProcess, getLogger } from "@uns-kit/core";
9
+ import { registerAttributeDescriptions, registerObjectTypeDescriptions } from "@uns-kit/core/uns/uns-dictionary-registry.js";
10
+ import type { ISO8601 } from "@uns-kit/core/uns/uns-interfaces.js";
11
+ import { UnsTopics } from "@uns-kit/core/uns/uns-topics.js";
12
+ import { GeneratedPhysicalMeasurements } from "../uns/uns-measurements.generated.js";
13
+ import {
14
+ GeneratedAttributeDescriptions,
15
+ GeneratedAttributesByType,
16
+ GeneratedObjectTypeDescriptions,
17
+ GeneratedObjectTypes,
18
+ } from "../uns/uns-dictionary.generated.js";
19
+ import { resolveGeneratedAsset } from "../uns/uns-assets.js";
20
+
21
+ const logger = getLogger(import.meta.url);
22
+
23
+ const config = await ConfigFile.loadConfig();
24
+ registerObjectTypeDescriptions(GeneratedObjectTypeDescriptions);
25
+ registerAttributeDescriptions(GeneratedAttributeDescriptions);
26
+
27
+ const unsProxyProcess = new UnsProxyProcess(config.infra.host!, {
28
+ processName: config.uns.processName!,
29
+ });
30
+
31
+ const mqttOutput = await unsProxyProcess.createUnsMqttProxy(
32
+ config.output?.host!,
33
+ "templateSubassetExampleOutput",
34
+ config.uns.instanceMode!,
35
+ config.uns.handover!,
36
+ { publishThrottlingDelay: 1000 },
37
+ );
38
+
39
+ try {
40
+ const parentAssetTopic: UnsTopics = "enterprise/site/area/line-1/";
41
+ const subAsset = resolveGeneratedAsset("pump-1");
42
+ const now = new Date();
43
+ const time = now.toISOString() as ISO8601;
44
+ const intervalStart = new Date(now.getTime() - 1000).toISOString() as ISO8601;
45
+ const intervalEnd = time;
46
+
47
+ await mqttOutput.publishMqttMessage({
48
+ topic: parentAssetTopic,
49
+ asset: subAsset,
50
+ assetDescription: "Example pump owned by a separate microservice",
51
+ objectType: GeneratedObjectTypes["equipment"],
52
+ objectId: "main",
53
+ attributes: {
54
+ attribute: GeneratedAttributesByType["equipment"]["temperature"],
55
+ description: "Example sub-asset temperature",
56
+ valueType: "number",
57
+ presentationKind: "chart",
58
+ defaultAggregation: "last",
59
+ data: {
60
+ time,
61
+ value: 42,
62
+ uom: GeneratedPhysicalMeasurements.Celsius,
63
+ intervalStart,
64
+ intervalEnd,
65
+ },
66
+ },
67
+ });
68
+
69
+ logger.info(
70
+ "Published sub-asset example to " +
71
+ `${parentAssetTopic}${subAsset}/equipment/main/temperature`,
72
+ );
73
+ } finally {
74
+ await mqttOutput.stop();
75
+ unsProxyProcess.shutdown();
76
+ }