@kronos-integration/service-mqtt 2.0.3 → 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.
- package/.github/workflows/ci.yml +4 -3
- package/package.json +3 -4
- package/src/service-mqtt.mjs +37 -49
- package/tests/mqtt-ava.mjs +7 -2
- package/types/service-mqtt.d.mts +0 -3
package/.github/workflows/ci.yml
CHANGED
|
@@ -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:
|
|
29
|
-
ports:
|
|
29
|
+
version: 2.0.22
|
|
30
|
+
ports: 1883:1883 8883:8883
|
|
30
31
|
config: ${{ github.workspace }}/.github/mosquitto/mosquitto.conf
|
|
31
|
-
container-name:
|
|
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
|
+
"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": "^
|
|
39
|
+
"@kronos-integration/service": "^13.0.1",
|
|
40
40
|
"mqtt": "^5.13.3",
|
|
41
|
-
"pacc": "^3.
|
|
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",
|
package/src/service-mqtt.mjs
CHANGED
|
@@ -1,4 +1,10 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
prepareAttributesDefinitions,
|
|
3
|
+
default_attribute,
|
|
4
|
+
url_attribute,
|
|
5
|
+
boolean_attribute,
|
|
6
|
+
secret_attribute
|
|
7
|
+
} from "pacc";
|
|
2
8
|
import { Service } from "@kronos-integration/service";
|
|
3
9
|
import { connect } from "mqtt";
|
|
4
10
|
import { TopicEndpoint } from "./topic-endpoint.mjs";
|
|
@@ -20,38 +26,26 @@ export class ServiceMQTT extends Service {
|
|
|
20
26
|
return "mqtt client";
|
|
21
27
|
}
|
|
22
28
|
|
|
23
|
-
static
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
username: {
|
|
44
|
-
type: "string",
|
|
45
|
-
private: true
|
|
46
|
-
},
|
|
47
|
-
password: {
|
|
48
|
-
type: "string",
|
|
49
|
-
private: true
|
|
50
|
-
}
|
|
51
|
-
}),
|
|
52
|
-
Service.configurationAttributes
|
|
53
|
-
);
|
|
54
|
-
}
|
|
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
|
+
);
|
|
55
49
|
|
|
56
50
|
/**
|
|
57
51
|
* @return {string} name with url
|
|
@@ -60,21 +54,6 @@ export class ServiceMQTT extends Service {
|
|
|
60
54
|
return `${this.name}(${this.url})`;
|
|
61
55
|
}
|
|
62
56
|
|
|
63
|
-
get options() {
|
|
64
|
-
return Object.fromEntries(
|
|
65
|
-
[
|
|
66
|
-
"username",
|
|
67
|
-
"password",
|
|
68
|
-
"clean",
|
|
69
|
-
"clientId",
|
|
70
|
-
"connectTimeout",
|
|
71
|
-
"reconnectPeriod"
|
|
72
|
-
]
|
|
73
|
-
.filter(key => this[key] !== undefined)
|
|
74
|
-
.map(key => [key, this[key]])
|
|
75
|
-
);
|
|
76
|
-
}
|
|
77
|
-
|
|
78
57
|
get topics() {
|
|
79
58
|
return Object.values(this.endpoints)
|
|
80
59
|
.filter(e => e.topic)
|
|
@@ -98,7 +77,16 @@ export class ServiceMQTT extends Service {
|
|
|
98
77
|
async _start() {
|
|
99
78
|
await super._start();
|
|
100
79
|
|
|
101
|
-
const
|
|
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);
|
|
102
90
|
|
|
103
91
|
this.client = client;
|
|
104
92
|
|
package/tests/mqtt-ava.mjs
CHANGED
|
@@ -4,19 +4,24 @@ import { ReceiveEndpoint } from "@kronos-integration/endpoint";
|
|
|
4
4
|
import { StandaloneServiceProvider } from "@kronos-integration/service";
|
|
5
5
|
import { ServiceMQTT, TopicEndpoint } from "@kronos-integration/service-mqtt";
|
|
6
6
|
|
|
7
|
-
test("
|
|
7
|
+
test("factory", async t => {
|
|
8
8
|
const sp = new StandaloneServiceProvider();
|
|
9
9
|
const r1 = new ReceiveEndpoint("r1", sp);
|
|
10
10
|
r1.receive = async () => "OK R1";
|
|
11
11
|
|
|
12
12
|
const mqtt = await sp.declareService({
|
|
13
13
|
type: ServiceMQTT,
|
|
14
|
+
clean: true,
|
|
15
|
+
clientId: "test",
|
|
16
|
+
url: "mqtt://localhost",
|
|
14
17
|
endpoints: {
|
|
15
18
|
s1: { topic: true, connected: r1 },
|
|
16
19
|
s2: { topic: "s2b", connected: r1 }
|
|
17
20
|
}
|
|
18
21
|
});
|
|
19
22
|
|
|
23
|
+
t.is(mqtt.clean, true);
|
|
24
|
+
t.is(mqtt.clientId, "test");
|
|
20
25
|
t.is(mqtt.endpoints["s1"].name, "s1");
|
|
21
26
|
t.is(mqtt.endpoints["s2"].name, "s2");
|
|
22
27
|
t.true(mqtt.endpoints["s1"] instanceof TopicEndpoint);
|
|
@@ -30,7 +35,7 @@ test("start / stop", async t => {
|
|
|
30
35
|
|
|
31
36
|
const received = [];
|
|
32
37
|
|
|
33
|
-
r1.receive = async
|
|
38
|
+
r1.receive = async message => received.push(message);
|
|
34
39
|
|
|
35
40
|
const mqtt = await sp.declareService({
|
|
36
41
|
type: ServiceMQTT,
|