@kronos-integration/service-mqtt 1.0.0 → 1.0.2
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 +2 -5
- package/.github/workflows/codeql_analysis.yml +1 -1
- package/.github/workflows/update_package_lock.yml +1 -1
- package/.github/workflows/update_readme_api.yml +1 -1
- package/package.json +9 -9
- package/src/service-mqtt.mjs +64 -18
- package/src/topic-endpoint.mjs +12 -2
- package/tests/mqtt-ava.mjs +7 -13
- package/types/service-mqtt.d.mts +4 -0
- package/types/topic-endpoint.d.mts +3 -0
package/.github/workflows/ci.yml
CHANGED
|
@@ -17,11 +17,8 @@ jobs:
|
|
|
17
17
|
matrix:
|
|
18
18
|
os:
|
|
19
19
|
- ubuntu-latest
|
|
20
|
-
- macos-latest
|
|
21
|
-
- windows-latest
|
|
22
20
|
node-version:
|
|
23
|
-
-
|
|
24
|
-
- 24.3.0
|
|
21
|
+
- 24.4.1
|
|
25
22
|
steps:
|
|
26
23
|
- name: checkout
|
|
27
24
|
uses: actions/checkout@v4.2.2
|
|
@@ -58,7 +55,7 @@ jobs:
|
|
|
58
55
|
- name: prepare node
|
|
59
56
|
uses: actions/setup-node@v4.4.0
|
|
60
57
|
with:
|
|
61
|
-
node-version: 22.17.
|
|
58
|
+
node-version: 22.17.1
|
|
62
59
|
cache: npm
|
|
63
60
|
cache-dependency-path: package-lock.json
|
|
64
61
|
- name: install
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kronos-integration/service-mqtt",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.2",
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public",
|
|
6
6
|
"provenance": true
|
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
"types": "./types/service-mqtt.d.mts"
|
|
13
13
|
}
|
|
14
14
|
},
|
|
15
|
-
"description": "
|
|
15
|
+
"description": "MQTT service",
|
|
16
16
|
"keywords": [
|
|
17
17
|
"mqtt",
|
|
18
18
|
"kronos-service"
|
|
@@ -36,23 +36,23 @@
|
|
|
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": "^11.2.
|
|
40
|
-
"attributes": "^
|
|
41
|
-
"mqtt": "^5.13.
|
|
39
|
+
"@kronos-integration/service": "^11.2.13",
|
|
40
|
+
"model-attributes": "^4.2.6",
|
|
41
|
+
"mqtt": "^5.13.2"
|
|
42
42
|
},
|
|
43
43
|
"devDependencies": {
|
|
44
44
|
"@kronos-integration/test-interceptor": "^7.0.29",
|
|
45
|
-
"@types/node": "^24.0.
|
|
46
|
-
"ava": "^6.4.
|
|
45
|
+
"@types/node": "^24.0.14",
|
|
46
|
+
"ava": "^6.4.1",
|
|
47
47
|
"c8": "^10.1.3",
|
|
48
48
|
"documentation": "^14.0.3",
|
|
49
49
|
"got": "^14.4.7",
|
|
50
50
|
"network-address": "^1.1.2",
|
|
51
|
-
"semantic-release": "^24.2.
|
|
51
|
+
"semantic-release": "^24.2.7",
|
|
52
52
|
"typescript": "^5.8.3"
|
|
53
53
|
},
|
|
54
54
|
"engines": {
|
|
55
|
-
"node": ">=22.
|
|
55
|
+
"node": ">=22.17.1"
|
|
56
56
|
},
|
|
57
57
|
"repository": {
|
|
58
58
|
"type": "git",
|
package/src/service-mqtt.mjs
CHANGED
|
@@ -23,16 +23,29 @@ export class ServiceMQTT extends Service {
|
|
|
23
23
|
static get configurationAttributes() {
|
|
24
24
|
return mergeAttributes(
|
|
25
25
|
createAttributes({
|
|
26
|
-
|
|
27
|
-
description: "
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
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
|
+
},
|
|
46
|
+
password: {
|
|
47
|
+
type: "string",
|
|
48
|
+
private: true
|
|
36
49
|
}
|
|
37
50
|
}),
|
|
38
51
|
Service.configurationAttributes
|
|
@@ -46,6 +59,27 @@ export class ServiceMQTT extends Service {
|
|
|
46
59
|
return `${this.name}(${this.url})`;
|
|
47
60
|
}
|
|
48
61
|
|
|
62
|
+
get options() {
|
|
63
|
+
return Object.fromEntries(
|
|
64
|
+
[
|
|
65
|
+
"username",
|
|
66
|
+
"password",
|
|
67
|
+
"clean",
|
|
68
|
+
"clientId",
|
|
69
|
+
"connectTimeout",
|
|
70
|
+
"reconnectPeriod"
|
|
71
|
+
]
|
|
72
|
+
.filter(key => this[key] !== undefined)
|
|
73
|
+
.map(key => [key, this[key]])
|
|
74
|
+
);
|
|
75
|
+
|
|
76
|
+
//return { username: this.username, password: this.password };
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
get topics() {
|
|
80
|
+
return Object.keys(this.endpoints).filter(e => e.topic);
|
|
81
|
+
}
|
|
82
|
+
|
|
49
83
|
/**
|
|
50
84
|
* On demand create TopicEndpoint.
|
|
51
85
|
* @param {string} name
|
|
@@ -53,13 +87,7 @@ export class ServiceMQTT extends Service {
|
|
|
53
87
|
* @return {Class} TopicEndpoint if path is present of name starts with '/'
|
|
54
88
|
*/
|
|
55
89
|
endpointFactoryFromConfig(name, definition, ic) {
|
|
56
|
-
|
|
57
|
-
if (
|
|
58
|
-
definition.method ||
|
|
59
|
-
definition.path ||
|
|
60
|
-
name[0] === "/" ||
|
|
61
|
-
name.match(/^\w+:\//)
|
|
62
|
-
) {
|
|
90
|
+
if (definition.topic) {
|
|
63
91
|
return TopicEndpoint;
|
|
64
92
|
}
|
|
65
93
|
|
|
@@ -69,7 +97,25 @@ export class ServiceMQTT extends Service {
|
|
|
69
97
|
async _start() {
|
|
70
98
|
await super._start();
|
|
71
99
|
|
|
72
|
-
|
|
100
|
+
console.log(this.options);
|
|
101
|
+
const client = connect(this.url, this.options);
|
|
102
|
+
|
|
103
|
+
this.client = client;
|
|
104
|
+
|
|
105
|
+
client.on("connect", err => {
|
|
106
|
+
client.subscribe(this.topics, (err, granted) => {
|
|
107
|
+
if (err) {
|
|
108
|
+
this.error(err);
|
|
109
|
+
}
|
|
110
|
+
});
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
client.on("message", (topic, message) => {
|
|
114
|
+
const ep = this.endpoints[topic];
|
|
115
|
+
if (ep) {
|
|
116
|
+
ep.receive(message);
|
|
117
|
+
}
|
|
118
|
+
});
|
|
73
119
|
}
|
|
74
120
|
|
|
75
121
|
async _stop() {
|
package/src/topic-endpoint.mjs
CHANGED
|
@@ -1,6 +1,16 @@
|
|
|
1
|
-
|
|
2
1
|
import { SendReceiveEndpoint } from "@kronos-integration/endpoint";
|
|
3
2
|
import { Service } from "@kronos-integration/service";
|
|
4
3
|
|
|
5
4
|
export class TopicEndpoint extends SendReceiveEndpoint {
|
|
6
|
-
|
|
5
|
+
constructor(name, owner, options) {
|
|
6
|
+
super(name, owner, options);
|
|
7
|
+
|
|
8
|
+
if (options.topic) {
|
|
9
|
+
this._topic = options.topic;
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
get topic() {
|
|
14
|
+
return this._topic || this.name;
|
|
15
|
+
}
|
|
16
|
+
}
|
package/tests/mqtt-ava.mjs
CHANGED
|
@@ -1,13 +1,8 @@
|
|
|
1
1
|
import test from "ava";
|
|
2
2
|
|
|
3
3
|
import { ReceiveEndpoint } from "@kronos-integration/endpoint";
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
} from "@kronos-integration/service";
|
|
7
|
-
import {
|
|
8
|
-
ServiceMQTT, TopicEndpoint
|
|
9
|
-
} from "@kronos-integration/service-mqtt";
|
|
10
|
-
|
|
4
|
+
import { StandaloneServiceProvider } from "@kronos-integration/service";
|
|
5
|
+
import { ServiceMQTT, TopicEndpoint } from "@kronos-integration/service-mqtt";
|
|
11
6
|
|
|
12
7
|
test("endpoint factory", async t => {
|
|
13
8
|
const sp = new StandaloneServiceProvider();
|
|
@@ -17,14 +12,13 @@ test("endpoint factory", async t => {
|
|
|
17
12
|
|
|
18
13
|
const mqtt = await sp.declareService({
|
|
19
14
|
type: ServiceMQTT,
|
|
20
|
-
listen: {
|
|
21
|
-
socket: 1241
|
|
22
|
-
},
|
|
23
15
|
endpoints: {
|
|
24
|
-
|
|
16
|
+
s1: { topic: "s1", connected: r1 }
|
|
25
17
|
}
|
|
26
18
|
});
|
|
27
19
|
|
|
28
|
-
t.is(mqtt.endpoints["
|
|
29
|
-
t.true(mqtt.endpoints["
|
|
20
|
+
t.is(mqtt.endpoints["s1"].name, "s1");
|
|
21
|
+
t.true(mqtt.endpoints["s1"] instanceof TopicEndpoint);
|
|
22
|
+
|
|
23
|
+
// t.deepEqual(mqtt.topics, ["s1"]);
|
|
30
24
|
});
|
package/types/service-mqtt.d.mts
CHANGED