@kronos-integration/service-mqtt 1.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/.github/dependabot.yml +19 -0
- package/.github/pr_labeler.yml +61 -0
- package/.github/workflows/auto_approve.yml +11 -0
- package/.github/workflows/ci.yml +82 -0
- package/.github/workflows/codeql_analysis.yml +31 -0
- package/.github/workflows/pr_labeler.yml +14 -0
- package/.github/workflows/update_package_lock.yml +42 -0
- package/.github/workflows/update_readme_api.yml +29 -0
- package/LICENSE +12 -0
- package/README.md +62 -0
- package/package.json +68 -0
- package/src/service-mqtt.mjs +80 -0
- package/src/topic-endpoint.mjs +6 -0
- package/tests/mqtt-ava.mjs +30 -0
- package/types/service-mqtt.d.mts +17 -0
- package/types/topic-endpoint.d.mts +3 -0
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
version: 2
|
|
2
|
+
updates:
|
|
3
|
+
- package-ecosystem: npm
|
|
4
|
+
directory: /
|
|
5
|
+
schedule:
|
|
6
|
+
interval: daily
|
|
7
|
+
commit-message:
|
|
8
|
+
prefix: "fix(deps):"
|
|
9
|
+
prefix-development: "chore(deps):"
|
|
10
|
+
labels:
|
|
11
|
+
- npm dependencies
|
|
12
|
+
- package-ecosystem: github-actions
|
|
13
|
+
directory: /
|
|
14
|
+
schedule:
|
|
15
|
+
interval: daily
|
|
16
|
+
commit-message:
|
|
17
|
+
prefix: "chore(action):"
|
|
18
|
+
labels:
|
|
19
|
+
- dependencies
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
ci:
|
|
2
|
+
- changed-files:
|
|
3
|
+
- any-glob-to-any-file:
|
|
4
|
+
- .github/workflows/*
|
|
5
|
+
- .travis.yml
|
|
6
|
+
dependencies:
|
|
7
|
+
- changed-files:
|
|
8
|
+
- any-glob-to-any-file:
|
|
9
|
+
- package-lock.json
|
|
10
|
+
- yarn.lockfile
|
|
11
|
+
deployment:
|
|
12
|
+
- changed-files:
|
|
13
|
+
- any-glob-to-any-file:
|
|
14
|
+
- netlify.toml
|
|
15
|
+
- _redirects
|
|
16
|
+
documentation:
|
|
17
|
+
- changed-files:
|
|
18
|
+
- any-glob-to-any-file:
|
|
19
|
+
- docs/**/*
|
|
20
|
+
- "**/*.md"
|
|
21
|
+
github:
|
|
22
|
+
- changed-files:
|
|
23
|
+
- any-glob-to-any-file:
|
|
24
|
+
- .github/**/*
|
|
25
|
+
git:
|
|
26
|
+
- changed-files:
|
|
27
|
+
- any-glob-to-any-file:
|
|
28
|
+
- .gitignore
|
|
29
|
+
labels:
|
|
30
|
+
- changed-files:
|
|
31
|
+
- any-glob-to-any-file:
|
|
32
|
+
- .github/pr_labeler.yml
|
|
33
|
+
lint:
|
|
34
|
+
- changed-files:
|
|
35
|
+
- any-glob-to-any-file:
|
|
36
|
+
- .stylelintrc.json
|
|
37
|
+
npm:
|
|
38
|
+
- changed-files:
|
|
39
|
+
- any-glob-to-any-file:
|
|
40
|
+
- .npmignore
|
|
41
|
+
- package.json
|
|
42
|
+
- package-lock.json
|
|
43
|
+
openapi:
|
|
44
|
+
- changed-files:
|
|
45
|
+
- any-glob-to-any-file:
|
|
46
|
+
- openapi/*
|
|
47
|
+
rollup:
|
|
48
|
+
- changed-files:
|
|
49
|
+
- any-glob-to-any-file:
|
|
50
|
+
- rollup.config.mjs
|
|
51
|
+
styling:
|
|
52
|
+
- changed-files:
|
|
53
|
+
- any-glob-to-any-file:
|
|
54
|
+
- "**/*.css"
|
|
55
|
+
test:
|
|
56
|
+
- changed-files:
|
|
57
|
+
- any-glob-to-any-file: tests/**/*
|
|
58
|
+
vscode:
|
|
59
|
+
- changed-files:
|
|
60
|
+
- any-glob-to-any-file:
|
|
61
|
+
- .vscode/*
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
name: Auto approve
|
|
2
|
+
on: pull_request_target
|
|
3
|
+
jobs:
|
|
4
|
+
auto-approve:
|
|
5
|
+
runs-on: ubuntu-latest
|
|
6
|
+
steps:
|
|
7
|
+
- uses: hmarr/auto-approve-action@v4.0.0
|
|
8
|
+
if: github.actor == 'dependabot[bot]'
|
|
9
|
+
with:
|
|
10
|
+
github-token: ${{ secrets.GITHUB_TOKEN }}
|
|
11
|
+
review-message: Auto approved automated PR
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
name: CI
|
|
2
|
+
on:
|
|
3
|
+
push:
|
|
4
|
+
branches:
|
|
5
|
+
- master
|
|
6
|
+
- next
|
|
7
|
+
pull_request:
|
|
8
|
+
branches:
|
|
9
|
+
- master
|
|
10
|
+
- next
|
|
11
|
+
permissions:
|
|
12
|
+
contents: read
|
|
13
|
+
jobs:
|
|
14
|
+
test-node:
|
|
15
|
+
runs-on: ubuntu-latest
|
|
16
|
+
strategy:
|
|
17
|
+
matrix:
|
|
18
|
+
os:
|
|
19
|
+
- ubuntu-latest
|
|
20
|
+
- macos-latest
|
|
21
|
+
- windows-latest
|
|
22
|
+
node-version:
|
|
23
|
+
- 22.17.0
|
|
24
|
+
- 24.3.0
|
|
25
|
+
steps:
|
|
26
|
+
- name: checkout
|
|
27
|
+
uses: actions/checkout@v4.2.2
|
|
28
|
+
- name: prepare node
|
|
29
|
+
uses: actions/setup-node@v4.4.0
|
|
30
|
+
with:
|
|
31
|
+
node-version: ${{ matrix.node-version }}
|
|
32
|
+
cache: npm
|
|
33
|
+
cache-dependency-path: package-lock.json
|
|
34
|
+
- name: install
|
|
35
|
+
run: npm ci
|
|
36
|
+
- name: test and coverage
|
|
37
|
+
run: npm run cover --if-present
|
|
38
|
+
- name: coveralls
|
|
39
|
+
uses: coverallsapp/github-action@v2
|
|
40
|
+
with:
|
|
41
|
+
github-token: ${{ secrets.GITHUB_TOKEN }}
|
|
42
|
+
flag-name: run-${{ matrix.test_number }}
|
|
43
|
+
path-to-lcov: build/coverage/lcov.info
|
|
44
|
+
parallel: true
|
|
45
|
+
continue-on-error: true
|
|
46
|
+
release:
|
|
47
|
+
needs:
|
|
48
|
+
- test-node
|
|
49
|
+
runs-on: ubuntu-latest
|
|
50
|
+
permissions:
|
|
51
|
+
contents: write
|
|
52
|
+
issues: write
|
|
53
|
+
pull-requests: write
|
|
54
|
+
id-token: write
|
|
55
|
+
steps:
|
|
56
|
+
- name: checkout
|
|
57
|
+
uses: actions/checkout@v4.2.2
|
|
58
|
+
- name: prepare node
|
|
59
|
+
uses: actions/setup-node@v4.4.0
|
|
60
|
+
with:
|
|
61
|
+
node-version: 22.17.0
|
|
62
|
+
cache: npm
|
|
63
|
+
cache-dependency-path: package-lock.json
|
|
64
|
+
- name: install
|
|
65
|
+
run: npm ci
|
|
66
|
+
- name: release
|
|
67
|
+
run: npx semantic-release
|
|
68
|
+
env:
|
|
69
|
+
CI: "true"
|
|
70
|
+
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
|
|
71
|
+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
72
|
+
finish:
|
|
73
|
+
needs:
|
|
74
|
+
- test-node
|
|
75
|
+
runs-on: ubuntu-latest
|
|
76
|
+
steps:
|
|
77
|
+
- name: finish coveralls
|
|
78
|
+
uses: coverallsapp/github-action@v2
|
|
79
|
+
with:
|
|
80
|
+
github-token: ${{ secrets.GITHUB_TOKEN }}
|
|
81
|
+
path-to-lcov: build/coverage/lcov.info
|
|
82
|
+
parallel-finished: true
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
name: CodeQL
|
|
2
|
+
on:
|
|
3
|
+
push:
|
|
4
|
+
branches:
|
|
5
|
+
- master
|
|
6
|
+
pull_request:
|
|
7
|
+
branches:
|
|
8
|
+
- master
|
|
9
|
+
jobs:
|
|
10
|
+
analyze:
|
|
11
|
+
name: Analyze
|
|
12
|
+
runs-on: ubuntu-latest
|
|
13
|
+
steps:
|
|
14
|
+
- name: checkout
|
|
15
|
+
uses: actions/checkout@v4.2.2
|
|
16
|
+
- name: git checkout
|
|
17
|
+
run: git checkout
|
|
18
|
+
if: ${{ github.event_name == 'pull_request' }}
|
|
19
|
+
- name: initialize CodeQL
|
|
20
|
+
uses: github/codeql-action/init@v3
|
|
21
|
+
with:
|
|
22
|
+
languages: javascript
|
|
23
|
+
- name: prepare node
|
|
24
|
+
uses: actions/setup-node@v4.4.0
|
|
25
|
+
with:
|
|
26
|
+
node-version: 22.17.0
|
|
27
|
+
cache: npm
|
|
28
|
+
- name: install
|
|
29
|
+
run: npm ci
|
|
30
|
+
- name: perform CodeQL analysis
|
|
31
|
+
uses: github/codeql-action/analyze@v3
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
name: Pull Request Labeler
|
|
2
|
+
on: pull_request_target
|
|
3
|
+
jobs:
|
|
4
|
+
triage:
|
|
5
|
+
permissions:
|
|
6
|
+
contents: read
|
|
7
|
+
pull-requests: write
|
|
8
|
+
runs-on: ubuntu-latest
|
|
9
|
+
steps:
|
|
10
|
+
- uses: actions/labeler@v5
|
|
11
|
+
with:
|
|
12
|
+
repo-token: ${{ secrets.GITHUB_TOKEN }}
|
|
13
|
+
configuration-path: .github/pr_labeler.yml
|
|
14
|
+
sync-labels: false
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
name: Update package lock
|
|
2
|
+
on:
|
|
3
|
+
push:
|
|
4
|
+
paths:
|
|
5
|
+
- package.json
|
|
6
|
+
schedule:
|
|
7
|
+
- cron: 13 8 * * 6
|
|
8
|
+
jobs:
|
|
9
|
+
update_package_lock:
|
|
10
|
+
runs-on: ubuntu-latest
|
|
11
|
+
strategy:
|
|
12
|
+
matrix:
|
|
13
|
+
node-version:
|
|
14
|
+
- 22.17.0
|
|
15
|
+
browser:
|
|
16
|
+
- chrome
|
|
17
|
+
steps:
|
|
18
|
+
- name: checkout
|
|
19
|
+
uses: actions/checkout@v4.2.2
|
|
20
|
+
- name: prepare node
|
|
21
|
+
uses: actions/setup-node@v4.4.0
|
|
22
|
+
with:
|
|
23
|
+
node-version: ${{ matrix.node-version }}
|
|
24
|
+
- name: remove lock
|
|
25
|
+
run: rm package-lock.json
|
|
26
|
+
- name: install playwright
|
|
27
|
+
run: npx playwright install
|
|
28
|
+
- name: test
|
|
29
|
+
run: npm install-test
|
|
30
|
+
env:
|
|
31
|
+
BROWSER: ${{ matrix.browser }}
|
|
32
|
+
- name: create pull request
|
|
33
|
+
uses: gr2m/create-or-update-pull-request-action@v1.10.1
|
|
34
|
+
env:
|
|
35
|
+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
36
|
+
with:
|
|
37
|
+
path: package-lock.json
|
|
38
|
+
title: Regenerate package lock
|
|
39
|
+
body: bring lock in sync
|
|
40
|
+
branch: package-lock
|
|
41
|
+
labels: npm
|
|
42
|
+
commit-message: "chore(deps): lock"
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
name: API to readme
|
|
2
|
+
on:
|
|
3
|
+
schedule:
|
|
4
|
+
- cron: 31 14 * * 6
|
|
5
|
+
push:
|
|
6
|
+
paths:
|
|
7
|
+
- src/*
|
|
8
|
+
jobs:
|
|
9
|
+
update_readme_api:
|
|
10
|
+
runs-on: ubuntu-latest
|
|
11
|
+
steps:
|
|
12
|
+
- name: checkout
|
|
13
|
+
uses: actions/checkout@v4.2.2
|
|
14
|
+
- name: prepare node
|
|
15
|
+
uses: actions/setup-node@v4.4.0
|
|
16
|
+
with:
|
|
17
|
+
node-version: 22.17.0
|
|
18
|
+
- name: install
|
|
19
|
+
run: npm ci
|
|
20
|
+
- name: run docs
|
|
21
|
+
run: npm run docs
|
|
22
|
+
- uses: gr2m/create-or-update-pull-request-action@v1.10.1
|
|
23
|
+
env:
|
|
24
|
+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
25
|
+
with:
|
|
26
|
+
path: README.md
|
|
27
|
+
title: Sync API into README
|
|
28
|
+
branch: readme-api
|
|
29
|
+
commit-message: "docs(README): sync API"
|
package/LICENSE
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
Copyright (C) 2025 by arlac77
|
|
2
|
+
|
|
3
|
+
Permission to use, copy, modify, and/or distribute this software for any
|
|
4
|
+
purpose with or without fee is hereby granted.
|
|
5
|
+
|
|
6
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
7
|
+
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
8
|
+
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
9
|
+
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
10
|
+
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
11
|
+
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
12
|
+
PERFORMANCE OF THIS SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
[](https://spdx.org/licenses/0BSD.html)
|
|
2
|
+
[](https://typescriptlang.org)
|
|
3
|
+
[](https://github.com/Kronos-Integration/service-mqtt/issues)
|
|
4
|
+
[](https://actions-badge.atrox.dev/Kronos-Integration/service-mqtt/goto)
|
|
5
|
+
[](https://github.com/prettier/prettier)
|
|
6
|
+
[](http://commitizen.github.io/cz-cli/)
|
|
7
|
+
[](https://snyk.io/test/github/Kronos-Integration/service-mqtt)
|
|
8
|
+
[](https://coveralls.io/github/Kronos-Integration/service-mqtt)
|
|
9
|
+
|
|
10
|
+
# @kronos-integration/service-mqtt
|
|
11
|
+
|
|
12
|
+
mqtt client
|
|
13
|
+
|
|
14
|
+
# API
|
|
15
|
+
|
|
16
|
+
<!-- Generated by documentation.js. Update this documentation by updating the source code. -->
|
|
17
|
+
|
|
18
|
+
### Table of Contents
|
|
19
|
+
|
|
20
|
+
* [ServiceMQTT](#servicemqtt)
|
|
21
|
+
* [extendetName](#extendetname)
|
|
22
|
+
* [endpointFactoryFromConfig](#endpointfactoryfromconfig)
|
|
23
|
+
* [Parameters](#parameters)
|
|
24
|
+
* [name](#name)
|
|
25
|
+
|
|
26
|
+
## ServiceMQTT
|
|
27
|
+
|
|
28
|
+
**Extends Service**
|
|
29
|
+
|
|
30
|
+
MQTT client.
|
|
31
|
+
|
|
32
|
+
### extendetName
|
|
33
|
+
|
|
34
|
+
Returns **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** name with url
|
|
35
|
+
|
|
36
|
+
### endpointFactoryFromConfig
|
|
37
|
+
|
|
38
|
+
On demand create TopicEndpoint.
|
|
39
|
+
|
|
40
|
+
#### Parameters
|
|
41
|
+
|
|
42
|
+
* `name` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** 
|
|
43
|
+
* `definition` **([Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object) | [string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String))** 
|
|
44
|
+
* `ic`  
|
|
45
|
+
|
|
46
|
+
Returns **Class** TopicEndpoint if path is present of name starts with '/'
|
|
47
|
+
|
|
48
|
+
### name
|
|
49
|
+
|
|
50
|
+
Returns **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** 'mqtt'
|
|
51
|
+
|
|
52
|
+
# install
|
|
53
|
+
|
|
54
|
+
With [npm](http://npmjs.org) do:
|
|
55
|
+
|
|
56
|
+
```shell
|
|
57
|
+
npm install @kronos-integration/service-mqtt
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
# license
|
|
61
|
+
|
|
62
|
+
BSD-2-Clause
|
package/package.json
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@kronos-integration/service-mqtt",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"publishConfig": {
|
|
5
|
+
"access": "public",
|
|
6
|
+
"provenance": true
|
|
7
|
+
},
|
|
8
|
+
"types": "./types/service-mqtt.d.mts",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"default": "./src/service-mqtt.mjs",
|
|
12
|
+
"types": "./types/service-mqtt.d.mts"
|
|
13
|
+
}
|
|
14
|
+
},
|
|
15
|
+
"description": "http server",
|
|
16
|
+
"keywords": [
|
|
17
|
+
"mqtt",
|
|
18
|
+
"kronos-service"
|
|
19
|
+
],
|
|
20
|
+
"contributors": [
|
|
21
|
+
{
|
|
22
|
+
"name": "Markus Felten",
|
|
23
|
+
"email": "markus.felten@gmx.de"
|
|
24
|
+
}
|
|
25
|
+
],
|
|
26
|
+
"license": "BSD-2-Clause",
|
|
27
|
+
"scripts": {
|
|
28
|
+
"prepare": "node --run prepare:typescript",
|
|
29
|
+
"prepare:typescript": "tsc --allowJs --declaration --emitDeclarationOnly --declarationDir types --resolveJsonModule --target es2024 --lib es2024 -m esnext --module nodenext --moduleResolution nodenext --rootDir src ./src**/*.mjs",
|
|
30
|
+
"test": "node --run test:ava",
|
|
31
|
+
"test:ava": "ava --timeout 4m tests/*-ava.mjs tests/*-ava-node.mjs",
|
|
32
|
+
"cover": "c8 -x 'tests/**/*' --temp-directory build/tmp ava --timeout 4m tests/*-ava.mjs tests/*-ava-node.mjs && c8 report -r lcov -o build/coverage --temp-directory build/tmp",
|
|
33
|
+
"docs": "documentation readme --section=API ./src/**/*.mjs",
|
|
34
|
+
"lint": "node --run lint:docs && node --run lint:typescript",
|
|
35
|
+
"lint:docs": "documentation lint ./src/**/*.mjs",
|
|
36
|
+
"lint:typescript": "tsc --allowJs --checkJs --noEmit --resolveJsonModule --target es2024 --lib es2024 -m esnext --module nodenext --moduleResolution nodenext ./src**/*.mjs"
|
|
37
|
+
},
|
|
38
|
+
"dependencies": {
|
|
39
|
+
"@kronos-integration/service": "^11.2.8",
|
|
40
|
+
"attributes": "^0.1.337",
|
|
41
|
+
"mqtt": "^5.13.1"
|
|
42
|
+
},
|
|
43
|
+
"devDependencies": {
|
|
44
|
+
"@kronos-integration/test-interceptor": "^7.0.29",
|
|
45
|
+
"@types/node": "^24.0.7",
|
|
46
|
+
"ava": "^6.4.0",
|
|
47
|
+
"c8": "^10.1.3",
|
|
48
|
+
"documentation": "^14.0.3",
|
|
49
|
+
"got": "^14.4.7",
|
|
50
|
+
"network-address": "^1.1.2",
|
|
51
|
+
"semantic-release": "^24.2.5",
|
|
52
|
+
"typescript": "^5.8.3"
|
|
53
|
+
},
|
|
54
|
+
"engines": {
|
|
55
|
+
"node": ">=22.16.0"
|
|
56
|
+
},
|
|
57
|
+
"repository": {
|
|
58
|
+
"type": "git",
|
|
59
|
+
"url": "git+https://github.com/Kronos-Integration/service-mqtt.git"
|
|
60
|
+
},
|
|
61
|
+
"template": {
|
|
62
|
+
"inheritFrom": [
|
|
63
|
+
"arlac77/template-arlac77-github",
|
|
64
|
+
"arlac77/template-kronos-component",
|
|
65
|
+
"arlac77/template-typescript"
|
|
66
|
+
]
|
|
67
|
+
}
|
|
68
|
+
}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { mergeAttributes, createAttributes } from "model-attributes";
|
|
2
|
+
import { Service } from "@kronos-integration/service";
|
|
3
|
+
import { connect } from "mqtt";
|
|
4
|
+
import { TopicEndpoint } from "./topic-endpoint.mjs";
|
|
5
|
+
|
|
6
|
+
export { TopicEndpoint };
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* MQTT client.
|
|
10
|
+
*/
|
|
11
|
+
export class ServiceMQTT extends Service {
|
|
12
|
+
/**
|
|
13
|
+
* @return {string} 'mqtt'
|
|
14
|
+
*/
|
|
15
|
+
static get name() {
|
|
16
|
+
return "mqtt";
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
static get description() {
|
|
20
|
+
return "mqtt client";
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
static get configurationAttributes() {
|
|
24
|
+
return mergeAttributes(
|
|
25
|
+
createAttributes({
|
|
26
|
+
"url": {
|
|
27
|
+
description: "server listen definition",
|
|
28
|
+
|
|
29
|
+
attributes: {
|
|
30
|
+
url: {
|
|
31
|
+
description: "url of the mqtt server",
|
|
32
|
+
needsRestart: true,
|
|
33
|
+
type: "url"
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
}),
|
|
38
|
+
Service.configurationAttributes
|
|
39
|
+
);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* @return {string} name with url
|
|
44
|
+
*/
|
|
45
|
+
get extendetName() {
|
|
46
|
+
return `${this.name}(${this.url})`;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* On demand create TopicEndpoint.
|
|
51
|
+
* @param {string} name
|
|
52
|
+
* @param {Object|string} definition
|
|
53
|
+
* @return {Class} TopicEndpoint if path is present of name starts with '/'
|
|
54
|
+
*/
|
|
55
|
+
endpointFactoryFromConfig(name, definition, ic) {
|
|
56
|
+
|
|
57
|
+
if (
|
|
58
|
+
definition.method ||
|
|
59
|
+
definition.path ||
|
|
60
|
+
name[0] === "/" ||
|
|
61
|
+
name.match(/^\w+:\//)
|
|
62
|
+
) {
|
|
63
|
+
return TopicEndpoint;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
return super.endpointFactoryFromConfig(name, definition, ic);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
async _start() {
|
|
70
|
+
await super._start();
|
|
71
|
+
|
|
72
|
+
this.client = connect(this.url);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
async _stop() {
|
|
76
|
+
return super._stop();
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
export default ServiceMQTT;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import test from "ava";
|
|
2
|
+
|
|
3
|
+
import { ReceiveEndpoint } from "@kronos-integration/endpoint";
|
|
4
|
+
import {
|
|
5
|
+
StandaloneServiceProvider,
|
|
6
|
+
} from "@kronos-integration/service";
|
|
7
|
+
import {
|
|
8
|
+
ServiceMQTT, TopicEndpoint
|
|
9
|
+
} from "@kronos-integration/service-mqtt";
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
test("endpoint factory", async t => {
|
|
13
|
+
const sp = new StandaloneServiceProvider();
|
|
14
|
+
|
|
15
|
+
const r1 = new ReceiveEndpoint("r1", sp);
|
|
16
|
+
r1.receive = async () => "OK R1";
|
|
17
|
+
|
|
18
|
+
const mqtt = await sp.declareService({
|
|
19
|
+
type: ServiceMQTT,
|
|
20
|
+
listen: {
|
|
21
|
+
socket: 1241
|
|
22
|
+
},
|
|
23
|
+
endpoints: {
|
|
24
|
+
"/s1": { connected: r1,}
|
|
25
|
+
}
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
t.is(mqtt.endpoints["/s1"].name, "/s1");
|
|
29
|
+
t.true(mqtt.endpoints["/s1"] instanceof TopicEndpoint);
|
|
30
|
+
});
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export { TopicEndpoint };
|
|
2
|
+
/**
|
|
3
|
+
* MQTT client.
|
|
4
|
+
*/
|
|
5
|
+
export class ServiceMQTT extends Service {
|
|
6
|
+
/**
|
|
7
|
+
* On demand create TopicEndpoint.
|
|
8
|
+
* @param {string} name
|
|
9
|
+
* @param {Object|string} definition
|
|
10
|
+
* @return {Class} TopicEndpoint if path is present of name starts with '/'
|
|
11
|
+
*/
|
|
12
|
+
endpointFactoryFromConfig(name: string, definition: any | string, ic: any): Class;
|
|
13
|
+
client: import("mqtt").MqttClient;
|
|
14
|
+
}
|
|
15
|
+
export default ServiceMQTT;
|
|
16
|
+
import { TopicEndpoint } from "./topic-endpoint.mjs";
|
|
17
|
+
import { Service } from "@kronos-integration/service";
|