@uns-kit/cli 2.0.36 → 2.0.38
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/README.md +2 -0
- package/package.json +6 -6
- package/templates/default/README.md +43 -0
- package/templates/default/src/index.ts +21 -3
package/README.md
CHANGED
|
@@ -37,6 +37,8 @@ pnpm run dev
|
|
|
37
37
|
|
|
38
38
|
The scaffold creates a project directory from the default TypeScript template, pins `@uns-kit/core` to the current version, and initialises a git repository if `git` is available.
|
|
39
39
|
|
|
40
|
+
The default template includes a Datahub REST client example (`UnsClient`) for last-value lookups, using a token-first pattern suitable for long-lived service tokens.
|
|
41
|
+
|
|
40
42
|
### Create from a service bundle
|
|
41
43
|
|
|
42
44
|
```bash
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@uns-kit/cli",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.38",
|
|
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.
|
|
29
|
+
"@uns-kit/core": "2.0.38"
|
|
30
30
|
},
|
|
31
31
|
"unsKitPackages": {
|
|
32
|
-
"@uns-kit/core": "2.0.
|
|
33
|
-
"@uns-kit/api": "2.0.
|
|
34
|
-
"@uns-kit/cron": "2.0.
|
|
35
|
-
"@uns-kit/temporal": "2.0.
|
|
32
|
+
"@uns-kit/core": "2.0.38",
|
|
33
|
+
"@uns-kit/api": "2.0.38",
|
|
34
|
+
"@uns-kit/cron": "2.0.38",
|
|
35
|
+
"@uns-kit/temporal": "2.0.38"
|
|
36
36
|
},
|
|
37
37
|
"scripts": {
|
|
38
38
|
"build": "tsc -p tsconfig.build.json",
|
|
@@ -23,6 +23,49 @@ pnpm run sync-uns-schema -- --controller-url http://localhost:3200 --token <admi
|
|
|
23
23
|
|
|
24
24
|
Update `config.json` with your broker, UNS URLs, and credentials. The generated file contains sensible defaults for local development.
|
|
25
25
|
|
|
26
|
+
## Validity / Liveliness
|
|
27
|
+
|
|
28
|
+
UNS attributes can declare how the controller decides whether they are live or stale. These fields are optional and default to `"interval"` with the controller default (~120s) if omitted.
|
|
29
|
+
|
|
30
|
+
- `validityMode`: `"interval" | "lifecycle" | "static"`
|
|
31
|
+
- `expectedIntervalMs`: required for `"interval"` mode (controller marks stale after ~2x this interval)
|
|
32
|
+
- `lifecycleEndValue`: required for `"lifecycle"` mode (end-state marker, e.g. `"EXITED"`)
|
|
33
|
+
|
|
34
|
+
Example:
|
|
35
|
+
|
|
36
|
+
```ts
|
|
37
|
+
await proxy.publishMqttMessage({
|
|
38
|
+
topic: "raw/data/",
|
|
39
|
+
asset: "line-1",
|
|
40
|
+
objectType: "motor",
|
|
41
|
+
objectId: "main",
|
|
42
|
+
attributes: {
|
|
43
|
+
attribute: "status",
|
|
44
|
+
data: { time: new Date().toISOString(), value: "RUNNING" },
|
|
45
|
+
validityMode: "lifecycle",
|
|
46
|
+
lifecycleEndValue: "STOPPED",
|
|
47
|
+
},
|
|
48
|
+
});
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
## Datahub client (last value)
|
|
52
|
+
|
|
53
|
+
`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.
|
|
54
|
+
|
|
55
|
+
```ts
|
|
56
|
+
import { UnsClient } from "@uns-kit/core";
|
|
57
|
+
|
|
58
|
+
const client = new UnsClient("https://datahub.example.com", {
|
|
59
|
+
token: process.env.UNS_SERVICE_TOKEN,
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
const values = await client.lastValue([
|
|
63
|
+
"raw/data/line-1/motor/main/temperature",
|
|
64
|
+
"raw/data/line-1/motor/main/status",
|
|
65
|
+
]);
|
|
66
|
+
console.log(values);
|
|
67
|
+
```
|
|
68
|
+
|
|
26
69
|
## Next Steps
|
|
27
70
|
|
|
28
71
|
- Install additional plugins: `pnpm add @uns-kit/api` etc.
|
|
@@ -6,10 +6,28 @@ async function main(): Promise<void> {
|
|
|
6
6
|
processName: name,
|
|
7
7
|
});
|
|
8
8
|
|
|
9
|
-
|
|
9
|
+
const proxy = await process.createMqttProxy("ts-output");
|
|
10
|
+
|
|
11
|
+
await proxy.publishMqttMessage({
|
|
12
|
+
topic: "example/site/area/line/",
|
|
13
|
+
asset: "demo-asset",
|
|
14
|
+
objectType: "utility-resource",
|
|
15
|
+
objectId: "main",
|
|
16
|
+
attributes: {
|
|
17
|
+
attribute: "status",
|
|
18
|
+
description: "Service startup marker",
|
|
19
|
+
data: {
|
|
20
|
+
time: new Date().toISOString(),
|
|
21
|
+
value: "started",
|
|
22
|
+
uom: "state",
|
|
23
|
+
dataGroup: "runtime",
|
|
24
|
+
},
|
|
25
|
+
validityMode: "lifecycle",
|
|
26
|
+
lifecycleEndValue: "stopped",
|
|
27
|
+
},
|
|
28
|
+
});
|
|
10
29
|
|
|
11
|
-
|
|
12
|
-
void process;
|
|
30
|
+
console.log(`UNS process '${name}' is ready. Edit src/index.ts to add your logic.`);
|
|
13
31
|
}
|
|
14
32
|
|
|
15
33
|
void main();
|