@kronos-integration/service-mqtt 2.0.2 → 3.0.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/package.json +3 -3
- package/src/service-mqtt.mjs +28 -32
- package/tests/mqtt-ava.mjs +10 -2
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kronos-integration/service-mqtt",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "3.0.0",
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public",
|
|
6
6
|
"provenance": true
|
|
@@ -36,9 +36,9 @@
|
|
|
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.0",
|
|
40
40
|
"mqtt": "^5.13.3",
|
|
41
|
-
"pacc": "^3.
|
|
41
|
+
"pacc": "^3.8.0"
|
|
42
42
|
},
|
|
43
43
|
"devDependencies": {
|
|
44
44
|
"@types/node": "^24.0.15",
|
package/src/service-mqtt.mjs
CHANGED
|
@@ -1,10 +1,35 @@
|
|
|
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";
|
|
5
11
|
|
|
6
12
|
export { TopicEndpoint };
|
|
7
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
|
+
|
|
8
33
|
/**
|
|
9
34
|
* MQTT client.
|
|
10
35
|
*/
|
|
@@ -20,37 +45,8 @@ export class ServiceMQTT extends Service {
|
|
|
20
45
|
return "mqtt client";
|
|
21
46
|
}
|
|
22
47
|
|
|
23
|
-
static get
|
|
24
|
-
return
|
|
25
|
-
prepareAttributesDefinitions({
|
|
26
|
-
url: {
|
|
27
|
-
description: "url of the mqtt server",
|
|
28
|
-
needsRestart: true,
|
|
29
|
-
type: "url"
|
|
30
|
-
},
|
|
31
|
-
clean: {
|
|
32
|
-
type: "boolean"
|
|
33
|
-
},
|
|
34
|
-
clientId: {
|
|
35
|
-
type: "string"
|
|
36
|
-
},
|
|
37
|
-
connectTimeout: {
|
|
38
|
-
type: "integer"
|
|
39
|
-
},
|
|
40
|
-
reconnectPeriod: {
|
|
41
|
-
type: "integer"
|
|
42
|
-
},
|
|
43
|
-
username: {
|
|
44
|
-
type: "string",
|
|
45
|
-
private: true
|
|
46
|
-
},
|
|
47
|
-
password: {
|
|
48
|
-
type: "string",
|
|
49
|
-
private: true
|
|
50
|
-
}
|
|
51
|
-
}),
|
|
52
|
-
Service.configurationAttributes
|
|
53
|
-
);
|
|
48
|
+
static get attributes() {
|
|
49
|
+
return ATTRIBUTES;
|
|
54
50
|
}
|
|
55
51
|
|
|
56
52
|
/**
|
package/tests/mqtt-ava.mjs
CHANGED
|
@@ -4,19 +4,27 @@ 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.deepEqual(mqtt.options, {
|
|
24
|
+
clean: true,
|
|
25
|
+
clientId: "test"
|
|
26
|
+
});
|
|
27
|
+
t.is(mqtt.url, "mqtt://localhost");
|
|
20
28
|
t.is(mqtt.endpoints["s1"].name, "s1");
|
|
21
29
|
t.is(mqtt.endpoints["s2"].name, "s2");
|
|
22
30
|
t.true(mqtt.endpoints["s1"] instanceof TopicEndpoint);
|
|
@@ -30,7 +38,7 @@ test("start / stop", async t => {
|
|
|
30
38
|
|
|
31
39
|
const received = [];
|
|
32
40
|
|
|
33
|
-
r1.receive = async
|
|
41
|
+
r1.receive = async message => received.push(message);
|
|
34
42
|
|
|
35
43
|
const mqtt = await sp.declareService({
|
|
36
44
|
type: ServiceMQTT,
|