@kronos-integration/service-mqtt 3.0.0 → 3.1.0

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.
@@ -18,6 +18,7 @@ jobs:
18
18
  os:
19
19
  - ubuntu-latest
20
20
  node-version:
21
+ - 22.17.1
21
22
  - 24.4.1
22
23
  steps:
23
24
  - name: checkout
@@ -25,10 +26,10 @@ jobs:
25
26
  - name: Start Mosquitto
26
27
  uses: namoshek/mosquitto-github-action@v1
27
28
  with:
28
- version: '2.0.22'
29
- ports: '1883:1883 8883:8883'
29
+ version: 2.0.22
30
+ ports: 1883:1883 8883:8883
30
31
  config: ${{ github.workspace }}/.github/mosquitto/mosquitto.conf
31
- container-name: 'mqtt'
32
+ container-name: mqtt
32
33
  - name: prepare node
33
34
  uses: actions/setup-node@v4.4.0
34
35
  with:
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kronos-integration/service-mqtt",
3
- "version": "3.0.0",
3
+ "version": "3.1.0",
4
4
  "publishConfig": {
5
5
  "access": "public",
6
6
  "provenance": true
@@ -36,12 +36,11 @@
36
36
  "lint:typescript": "tsc --allowJs --checkJs --noEmit --resolveJsonModule --target es2024 --lib es2024 -m esnext --module nodenext --moduleResolution nodenext ./src**/*.mjs"
37
37
  },
38
38
  "dependencies": {
39
- "@kronos-integration/service": "^13.0.0",
39
+ "@kronos-integration/service": "^13.0.1",
40
40
  "mqtt": "^5.13.3",
41
- "pacc": "^3.8.0"
41
+ "pacc": "^3.9.0"
42
42
  },
43
43
  "devDependencies": {
44
- "@types/node": "^24.0.15",
45
44
  "ava": "^6.4.1",
46
45
  "c8": "^10.1.3",
47
46
  "documentation": "^14.0.3",
@@ -11,25 +11,6 @@ import { TopicEndpoint } from "./topic-endpoint.mjs";
11
11
 
12
12
  export { TopicEndpoint };
13
13
 
14
- const ATTRIBUTES = prepareAttributesDefinitions({
15
- url: {
16
- ...url_attribute,
17
- description: "url of the mqtt server",
18
- needsRestart: true
19
- },
20
- clean: boolean_attribute,
21
- clientId: default_attribute,
22
- connectTimeout: {
23
- type: "integer"
24
- },
25
- reconnectPeriod: {
26
- type: "integer"
27
- },
28
- username: secret_attribute,
29
- password: secret_attribute,
30
- ...Service.attributes
31
- });
32
-
33
14
  /**
34
15
  * MQTT client.
35
16
  */
@@ -45,9 +26,26 @@ export class ServiceMQTT extends Service {
45
26
  return "mqtt client";
46
27
  }
47
28
 
48
- static get attributes() {
49
- return ATTRIBUTES;
50
- }
29
+ static attributes = prepareAttributesDefinitions(
30
+ {
31
+ url: {
32
+ ...url_attribute,
33
+ description: "url of the mqtt server",
34
+ needsRestart: true
35
+ },
36
+ clean: boolean_attribute,
37
+ clientId: default_attribute,
38
+ connectTimeout: {
39
+ type: "integer"
40
+ },
41
+ reconnectPeriod: {
42
+ type: "integer"
43
+ },
44
+ username: secret_attribute,
45
+ password: secret_attribute
46
+ },
47
+ Service.attributes
48
+ );
51
49
 
52
50
  /**
53
51
  * @return {string} name with url
@@ -56,21 +54,6 @@ export class ServiceMQTT extends Service {
56
54
  return `${this.name}(${this.url})`;
57
55
  }
58
56
 
59
- get options() {
60
- return Object.fromEntries(
61
- [
62
- "username",
63
- "password",
64
- "clean",
65
- "clientId",
66
- "connectTimeout",
67
- "reconnectPeriod"
68
- ]
69
- .filter(key => this[key] !== undefined)
70
- .map(key => [key, this[key]])
71
- );
72
- }
73
-
74
57
  get topics() {
75
58
  return Object.values(this.endpoints)
76
59
  .filter(e => e.topic)
@@ -94,7 +77,16 @@ export class ServiceMQTT extends Service {
94
77
  async _start() {
95
78
  await super._start();
96
79
 
97
- const client = connect(this.url, this.options);
80
+ const options = Object.fromEntries(
81
+ ["clean", "clientId", "connectTimeout", "reconnectPeriod"]
82
+ .filter(key => this[key] !== undefined)
83
+ .map(key => [key, this[key]])
84
+ );
85
+
86
+ options.password = await this.password;
87
+ options.username = await this.username;
88
+
89
+ const client = connect(this.url, options);
98
90
 
99
91
  this.client = client;
100
92
 
@@ -20,11 +20,8 @@ test("factory", async t => {
20
20
  }
21
21
  });
22
22
 
23
- t.deepEqual(mqtt.options, {
24
- clean: true,
25
- clientId: "test"
26
- });
27
- t.is(mqtt.url, "mqtt://localhost");
23
+ t.is(mqtt.clean, true);
24
+ t.is(mqtt.clientId, "test");
28
25
  t.is(mqtt.endpoints["s1"].name, "s1");
29
26
  t.is(mqtt.endpoints["s2"].name, "s2");
30
27
  t.true(mqtt.endpoints["s1"] instanceof TopicEndpoint);
@@ -3,9 +3,6 @@ export { TopicEndpoint };
3
3
  * MQTT client.
4
4
  */
5
5
  export class ServiceMQTT extends Service {
6
- get options(): {
7
- [k: string]: any;
8
- };
9
6
  get topics(): any[];
10
7
  /**
11
8
  * On demand create TopicEndpoint.