@uns-kit/cli 2.0.69 → 2.0.70
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/dist/index.js +11 -7
- package/package.json +6 -6
- package/templates/default/README.md +11 -8
- package/templates/default/src/examples/data-example.ts +19 -18
- package/templates/default/src/examples/load-test-data.ts +5 -5
- package/templates/default/src/examples/schema-system-metadata-example.ts +5 -4
- package/templates/default/src/examples/subasset-example.ts +5 -4
- package/templates/default/src/examples/table-example.ts +14 -13
- package/templates/default/src/examples/table-window-load-test.ts +5 -6
- package/templates/default/src/index.ts +9 -5
package/dist/index.js
CHANGED
|
@@ -369,8 +369,8 @@ async function main(): Promise<void> {
|
|
|
369
369
|
|
|
370
370
|
const time = new Date().toISOString() as ISO8601;
|
|
371
371
|
|
|
372
|
-
for (const output of outputContracts) {
|
|
373
|
-
await mqttOutput.publishMqttMessage({
|
|
372
|
+
for (const output of outputContracts) {
|
|
373
|
+
await mqttOutput.publishMqttMessage({
|
|
374
374
|
topic: topicPrefixForPublish(output.topicPrefix),
|
|
375
375
|
asset: output.asset,
|
|
376
376
|
objectType: output.objectType,
|
|
@@ -386,11 +386,15 @@ async function main(): Promise<void> {
|
|
|
386
386
|
validityMode: "interval",
|
|
387
387
|
expectedIntervalMs: output.expectedIntervalMs,
|
|
388
388
|
},
|
|
389
|
-
});
|
|
390
|
-
}
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
389
|
+
});
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
await mqttOutput.flush();
|
|
393
|
+
await mqttOutput.stop();
|
|
394
|
+
await unsProcess.shutdown();
|
|
395
|
+
|
|
396
|
+
console.log(\`UNS process '\${processName}' published \${outputContracts.length} interval example output(s).\`);
|
|
397
|
+
}
|
|
394
398
|
|
|
395
399
|
void main();
|
|
396
400
|
`;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@uns-kit/cli",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.70",
|
|
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.70"
|
|
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/database": "2.0.
|
|
32
|
+
"@uns-kit/core": "2.0.70",
|
|
33
|
+
"@uns-kit/api": "2.0.70",
|
|
34
|
+
"@uns-kit/cron": "2.0.70",
|
|
35
|
+
"@uns-kit/database": "2.0.70"
|
|
36
36
|
},
|
|
37
37
|
"scripts": {
|
|
38
38
|
"build": "tsc -p tsconfig.build.json",
|
|
@@ -27,22 +27,25 @@ UNS attributes can declare how the controller decides whether they are live or s
|
|
|
27
27
|
- `interval`: continuously refreshed values (stale after ~2× `expectedIntervalMs`)
|
|
28
28
|
- `lifecycle`: event-driven activity that stays active until a defined end value (`lifecycleEndValue`)
|
|
29
29
|
|
|
30
|
-
Example:
|
|
30
|
+
Example:
|
|
31
31
|
|
|
32
32
|
```ts
|
|
33
|
-
await proxy.publishMqttMessage({
|
|
34
|
-
topic: "raw/data/",
|
|
35
|
-
asset: "line-1",
|
|
33
|
+
await proxy.publishMqttMessage({
|
|
34
|
+
topic: "raw/data/",
|
|
35
|
+
asset: "line-1",
|
|
36
36
|
objectType: "motor",
|
|
37
37
|
objectId: "main",
|
|
38
38
|
attributes: {
|
|
39
39
|
attribute: "status",
|
|
40
40
|
data: { time: new Date().toISOString(), value: "RUNNING" },
|
|
41
41
|
validityMode: "lifecycle",
|
|
42
|
-
lifecycleEndValue: "STOPPED",
|
|
43
|
-
},
|
|
44
|
-
});
|
|
45
|
-
|
|
42
|
+
lifecycleEndValue: "STOPPED",
|
|
43
|
+
},
|
|
44
|
+
});
|
|
45
|
+
await proxy.flush();
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
`publishMqttMessage()` resolves when the message is accepted into the local bounded publisher queue, not when the broker confirms it. Queue-full is reported immediately to the caller. Broker publish failures are emitted later on the proxy `error` event, so use `await proxy.flush()` before shutdown or before assuming all accepted messages were published.
|
|
46
49
|
|
|
47
50
|
## Schema System Metadata
|
|
48
51
|
|
|
@@ -27,15 +27,15 @@ registerObjectTypeDescriptions(GeneratedObjectTypeDescriptions);
|
|
|
27
27
|
/**
|
|
28
28
|
* Connect to input and output brokers
|
|
29
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.
|
|
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
39
|
* Transform an input message and publish it with publishMqttMessage function.
|
|
40
40
|
*/
|
|
41
41
|
mqttInput.event.on("input", async (event) => {
|
|
@@ -60,12 +60,13 @@ mqttInput.event.on("input", async (event) => {
|
|
|
60
60
|
const asset = resolveGeneratedAsset("asset");
|
|
61
61
|
const assetDescription = ""; // customize manually
|
|
62
62
|
|
|
63
|
-
mqttOutput.publishMqttMessage({
|
|
64
|
-
topic,
|
|
65
|
-
asset,
|
|
66
|
-
assetDescription,
|
|
63
|
+
await mqttOutput.publishMqttMessage({
|
|
64
|
+
topic,
|
|
65
|
+
asset,
|
|
66
|
+
assetDescription,
|
|
67
67
|
objectType: GeneratedObjectTypes["energy-resource"],
|
|
68
68
|
objectId: "main",
|
|
69
|
+
virtualGroup: "metering",
|
|
69
70
|
attributes: [
|
|
70
71
|
{
|
|
71
72
|
attribute: GeneratedAttributesByType["energy-resource"]["current"],
|
|
@@ -85,11 +86,11 @@ mqttInput.event.on("input", async (event) => {
|
|
|
85
86
|
data: { dataGroup, time, value: numberValue, uom: GeneratedPhysicalMeasurements.KiloWattHour, intervalStart, intervalEnd },
|
|
86
87
|
},
|
|
87
88
|
],
|
|
88
|
-
});
|
|
89
|
-
}
|
|
90
|
-
} catch (error) {
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
} catch (error) {
|
|
91
92
|
const reason = error instanceof Error ? error : new Error(String(error));
|
|
92
93
|
logger.error(`Error publishing message to MQTT: ${reason.message}`);
|
|
93
94
|
throw reason;
|
|
94
|
-
}
|
|
95
|
-
});
|
|
95
|
+
}
|
|
96
|
+
});
|
|
@@ -80,11 +80,11 @@ async function main() {
|
|
|
80
80
|
}
|
|
81
81
|
}
|
|
82
82
|
|
|
83
|
-
|
|
84
|
-
await
|
|
85
|
-
|
|
86
|
-
const endTime = Date.now();
|
|
87
|
-
const duration = (endTime - startTime) / 1000;
|
|
83
|
+
await mqttOutput.flush();
|
|
84
|
+
await mqttOutput.stop();
|
|
85
|
+
|
|
86
|
+
const endTime = Date.now();
|
|
87
|
+
const duration = (endTime - startTime) / 1000;
|
|
88
88
|
const messagesPerSecond = maxIntervals / duration;
|
|
89
89
|
|
|
90
90
|
logger.info(`Load test completed in ${duration.toFixed(2)} seconds.`);
|
|
@@ -119,7 +119,8 @@ try {
|
|
|
119
119
|
});
|
|
120
120
|
|
|
121
121
|
logger.info(`Published schema-system metadata example for material ${currentMaterialId}.`);
|
|
122
|
-
} finally {
|
|
123
|
-
await mqttOutput.
|
|
124
|
-
|
|
125
|
-
|
|
122
|
+
} finally {
|
|
123
|
+
await mqttOutput.flush();
|
|
124
|
+
await mqttOutput.stop();
|
|
125
|
+
await unsProxyProcess.shutdown();
|
|
126
|
+
}
|
|
@@ -70,7 +70,8 @@ try {
|
|
|
70
70
|
"Published sub-asset example to " +
|
|
71
71
|
`${parentAssetTopic}${subAsset}/equipment/main/temperature`,
|
|
72
72
|
);
|
|
73
|
-
} finally {
|
|
74
|
-
await mqttOutput.
|
|
75
|
-
|
|
76
|
-
|
|
73
|
+
} finally {
|
|
74
|
+
await mqttOutput.flush();
|
|
75
|
+
await mqttOutput.stop();
|
|
76
|
+
await unsProxyProcess.shutdown();
|
|
77
|
+
}
|
|
@@ -33,12 +33,12 @@ const unsProxyProcess = new UnsProxyProcess(config.infra.host!, {processName: co
|
|
|
33
33
|
const mqttInput = await unsProxyProcess.createUnsMqttProxy((config.input?.host)!, "templateUnsRttInput", config.uns.instanceMode!, config.uns.handover!, {
|
|
34
34
|
mqttSubToTopics: ["raw/#"],
|
|
35
35
|
});
|
|
36
|
-
const mqttOutput = await unsProxyProcess.createUnsMqttProxy((config.output?.host)!, "templateUnsRttOutput", config.uns.instanceMode!, config.uns.handover!, {
|
|
37
|
-
publishThrottlingDelay: 1000,
|
|
38
|
-
});
|
|
39
|
-
|
|
40
|
-
/**
|
|
41
|
-
* The input worker connects to the upstream broker and listens for incoming messages.
|
|
36
|
+
const mqttOutput = await unsProxyProcess.createUnsMqttProxy((config.output?.host)!, "templateUnsRttOutput", config.uns.instanceMode!, config.uns.handover!, {
|
|
37
|
+
publishThrottlingDelay: 1000,
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* The input worker connects to the upstream broker and listens for incoming messages.
|
|
42
42
|
* It processes the messages and transforms them into a table-type IUnsMessage.
|
|
43
43
|
* The resulting message is published to the output broker.
|
|
44
44
|
*/
|
|
@@ -77,12 +77,13 @@ mqttInput.event.on("input", async (event) => {
|
|
|
77
77
|
const topic: UnsTopics = "enterprise/site/area/line/";
|
|
78
78
|
const asset = resolveGeneratedAsset("asset");
|
|
79
79
|
const assetDescription = ""; // customize manually
|
|
80
|
-
mqttOutput.publishMqttMessage({
|
|
81
|
-
topic,
|
|
82
|
-
asset,
|
|
83
|
-
assetDescription,
|
|
80
|
+
await mqttOutput.publishMqttMessage({
|
|
81
|
+
topic,
|
|
82
|
+
asset,
|
|
83
|
+
assetDescription,
|
|
84
84
|
objectType: GeneratedObjectTypes["energy-resource"],
|
|
85
85
|
objectId: "main",
|
|
86
|
+
virtualGroup: "metering",
|
|
86
87
|
attributes: [
|
|
87
88
|
{
|
|
88
89
|
attribute: "measurements",
|
|
@@ -97,9 +98,9 @@ mqttInput.event.on("input", async (event) => {
|
|
|
97
98
|
},
|
|
98
99
|
},
|
|
99
100
|
],
|
|
100
|
-
});
|
|
101
|
-
}
|
|
102
|
-
} catch (error) {
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
} catch (error) {
|
|
103
104
|
const reason = error instanceof Error ? error : new Error(String(error));
|
|
104
105
|
logger.error(`Error publishing message to MQTT: ${reason.message}`);
|
|
105
106
|
throw reason;
|
|
@@ -431,12 +431,11 @@ async function main() {
|
|
|
431
431
|
}
|
|
432
432
|
}
|
|
433
433
|
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
}
|
|
434
|
+
await mqttOutput?.flush();
|
|
435
|
+
} finally {
|
|
436
|
+
rl.close();
|
|
437
|
+
await mqttOutput?.stop();
|
|
438
|
+
}
|
|
440
439
|
}
|
|
441
440
|
|
|
442
441
|
main().catch((error) => {
|
|
@@ -17,7 +17,7 @@ async function main(): Promise<void> {
|
|
|
17
17
|
|
|
18
18
|
const time = new Date().toISOString() as ISO8601;
|
|
19
19
|
|
|
20
|
-
await mqttOutput.publishMqttMessage({
|
|
20
|
+
await mqttOutput.publishMqttMessage({
|
|
21
21
|
topic: "example/site/area/line/",
|
|
22
22
|
asset: "demo-asset",
|
|
23
23
|
objectType: "utility-resource",
|
|
@@ -33,9 +33,13 @@ async function main(): Promise<void> {
|
|
|
33
33
|
validityMode: "lifecycle",
|
|
34
34
|
lifecycleEndValue: "stopped",
|
|
35
35
|
},
|
|
36
|
-
});
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
await mqttOutput.flush();
|
|
39
|
+
await mqttOutput.stop();
|
|
40
|
+
await unsProcess.shutdown();
|
|
41
|
+
|
|
42
|
+
console.log(`UNS process '${processName}' is ready. Edit src/index.ts to add your logic.`);
|
|
43
|
+
}
|
|
40
44
|
|
|
41
45
|
void main();
|