@uns-kit/cron 0.0.7 → 0.0.9

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 CHANGED
@@ -16,15 +16,19 @@ You will also need `@uns-kit/core` in your project because the plugin augments `
16
16
 
17
17
  ```ts
18
18
  import UnsProxyProcess from "@uns-kit/core/uns/uns-proxy-process";
19
- import unsCronPlugin, { type UnsProxyProcessWithCron } from "@uns-kit/cron";
19
+ import type { UnsProxyProcessWithCron } from "@uns-kit/cron";
20
+ import "@uns-kit/cron";
20
21
 
21
- const process = new UnsProxyProcess("mqtt-broker:1883", { processName: "cron-demo" }) as UnsProxyProcessWithCron;
22
- unsCronPlugin;
22
+ async function main() {
23
+ const process = new UnsProxyProcess("mqtt-broker:1883", { processName: "cron-demo" }) as UnsProxyProcessWithCron;
23
24
 
24
- const cronProxy = await process.createCrontabProxy("* * * * * *");
25
- cronProxy.event.on("cronEvent", () => {
26
- console.log("tick");
27
- });
25
+ const cronProxy = await process.createCrontabProxy("*/5 * * * *");
26
+ cronProxy.event.on("cronEvent", () => {
27
+ console.log("tick");
28
+ });
29
+ }
30
+
31
+ void main();
28
32
  ```
29
33
 
30
34
  ## Scripts
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@uns-kit/cron",
3
- "version": "0.0.7",
3
+ "version": "0.0.9",
4
4
  "description": "Cron-driven plugin for UnsProxyProcess that emits UNS events on a schedule.",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -22,13 +22,17 @@
22
22
  "dist"
23
23
  ],
24
24
  "exports": {
25
+ ".": {
26
+ "types": "./dist/index.d.ts",
27
+ "import": "./dist/index.js"
28
+ },
25
29
  "./*": "./dist/*"
26
30
  },
27
31
  "main": "dist/index.js",
28
32
  "types": "dist/index.d.ts",
29
33
  "dependencies": {
30
34
  "node-cron": "^4.2.1",
31
- "@uns-kit/core": "0.0.19"
35
+ "@uns-kit/core": "0.0.21"
32
36
  },
33
37
  "scripts": {
34
38
  "build": "tsc -p tsconfig.build.json",
@@ -1 +0,0 @@
1
- export {};
@@ -1,41 +0,0 @@
1
- /**
2
- * Change this file according to your specifications and rename it to index.ts
3
- */
4
- import UnsProxyProcess from "@uns-kit/core/uns/uns-proxy-process";
5
- import { ConfigFile } from "@uns-kit/core/config-file";
6
- import logger from "@uns-kit/core/logger";
7
- import { PhysicalMeasurements } from "@uns-kit/core/uns/uns-measurements";
8
- import { UnsPacket } from "@uns-kit/core/uns/uns-packet";
9
- import unsCronPlugin from "./uns-cron-plugin.js";
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
- * Connect to the output broker and create a crontab proxy
18
- */
19
- const unsProxyProcess = new UnsProxyProcess(config.infra.host, { processName: config.uns.processName });
20
- unsCronPlugin;
21
- const mqttOutput = await unsProxyProcess.createUnsMqttProxy(config.output.host, "templateUnsRttOutput", config.uns.instanceMode, config.uns.handover, { publishThrottlingDelay: 1000 });
22
- const cronInput = await unsProxyProcess.createCrontabProxy("* * * * * *");
23
- /**
24
- * Event listener for cron events.
25
- * On each cron event, publish a message to the MQTT output broker.
26
- */
27
- cronInput.event.on("cronEvent", async (event) => {
28
- try {
29
- const time = UnsPacket.formatToISO8601(new Date());
30
- const numberValue = 42;
31
- const message = { data: { time, value: numberValue, uom: PhysicalMeasurements.MiliVolt } };
32
- const topic = "sij/";
33
- const tags = [];
34
- const packet = await UnsPacket.unsPacketFromUnsMessage(message);
35
- mqttOutput.publishMqttMessage({ topic, attribute: "data-number", packet, description: "Number value", tags });
36
- }
37
- catch (error) {
38
- logger.error(`Error publishing message to MQTT: ${error.message}`);
39
- throw error;
40
- }
41
- });