mqtt-json-rpc 1.3.7 → 2.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/etc/eslint.mts ADDED
@@ -0,0 +1,129 @@
1
+ /*
2
+ ** MQTT-JSON-RPC -- JSON-RPC protocol over MQTT communication
3
+ ** Copyright (c) 2018-2025 Dr. Ralf S. Engelschall <rse@engelschall.com>
4
+ **
5
+ ** Permission is hereby granted, free of charge, to any person obtaining
6
+ ** a copy of this software and associated documentation files (the
7
+ ** "Software"), to deal in the Software without restriction, including
8
+ ** without limitation the rights to use, copy, modify, merge, publish,
9
+ ** distribute, sublicense, and/or sell copies of the Software, and to
10
+ ** permit persons to whom the Software is furnished to do so, subject to
11
+ ** the following conditions:
12
+ **
13
+ ** The above copyright notice and this permission notice shall be included
14
+ ** in all copies or substantial portions of the Software.
15
+ **
16
+ ** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ ** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ ** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19
+ ** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
20
+ ** CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
21
+ ** TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
22
+ ** SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23
+ */
24
+
25
+ import globals from "globals"
26
+ import path from "node:path"
27
+ import { fileURLToPath } from "node:url"
28
+ import js from "@eslint/js"
29
+ import { FlatCompat } from "@eslint/eslintrc"
30
+ import pluginTS from "typescript-eslint"
31
+ import parserTS from "@typescript-eslint/parser"
32
+
33
+ const __filename = fileURLToPath(import.meta.url)
34
+ const __dirname = path.dirname(__filename)
35
+ const compat = new FlatCompat({
36
+ baseDirectory: __dirname,
37
+ recommendedConfig: js.configs.recommended,
38
+ allConfig: js.configs.all
39
+ })
40
+
41
+ export default [
42
+ ...compat.extends("eslint:recommended"),
43
+ ...pluginTS.configs.strict,
44
+ ...pluginTS.configs.stylistic,
45
+ {
46
+ files: [ "**/*.ts" ],
47
+ languageOptions: {
48
+ ecmaVersion: 2022,
49
+ sourceType: "module",
50
+ parser: parserTS,
51
+ parserOptions: {
52
+ ecmaFeatures: { jsx: false }
53
+ },
54
+ globals: {
55
+ ...globals.browser,
56
+ ...Object.fromEntries(Object.entries(globals.node).map(([key]) => [key, "off"])),
57
+ ...globals.commonjs,
58
+ ...globals.worker,
59
+ ...globals.serviceworker,
60
+ process: true,
61
+ },
62
+ },
63
+ rules: {
64
+ "indent": [ "error", 4, { SwitchCase: 1 } ],
65
+ "linebreak-style": [ "error", "unix" ],
66
+ "semi": [ "error", "never" ],
67
+ "operator-linebreak": [ "error", "after", { overrides: { "&&": "before", "||": "before", ":": "before" } } ],
68
+ "brace-style": [ "error", "stroustrup", { allowSingleLine: true } ],
69
+ "quotes": [ "error", "double" ],
70
+ "no-multi-spaces": "off",
71
+ "no-multiple-empty-lines": "off",
72
+ "key-spacing": "off",
73
+ "object-property-newline": "off",
74
+ "curly": "off",
75
+ "space-in-parens": "off",
76
+ "no-console": "off",
77
+ "lines-between-class-members": "off",
78
+ "array-bracket-spacing": "off",
79
+
80
+ "@typescript-eslint/no-empty-function": "off",
81
+ "@typescript-eslint/no-explicit-any": "off",
82
+ "@typescript-eslint/no-unused-vars": "off",
83
+ "@typescript-eslint/no-non-null-assertion": "off",
84
+ "@typescript-eslint/consistent-type-definitions": "off",
85
+ "@typescript-eslint/array-type": "off",
86
+ "@typescript-eslint/consistent-indexed-object-style": "off",
87
+ "@typescript-eslint/no-dynamic-delete": "off",
88
+ "@typescript-eslint/no-inferrable-types": "off",
89
+ "@typescript-eslint/consistent-generic-constructors": "off",
90
+ },
91
+ },
92
+ {
93
+ files: [ "**/*.js" ],
94
+ languageOptions: {
95
+ ecmaVersion: 2022,
96
+ sourceType: "module",
97
+ parserOptions: {
98
+ ecmaFeatures: { jsx: false }
99
+ },
100
+ globals: {
101
+ ...globals.browser,
102
+ ...Object.fromEntries(Object.entries(globals.node).map(([key]) => [key, "off"])),
103
+ ...globals.commonjs,
104
+ ...globals.worker,
105
+ ...globals.serviceworker,
106
+ process: true,
107
+ },
108
+ },
109
+ rules: {
110
+ "indent": [ "error", 4, { SwitchCase: 1 } ],
111
+ "linebreak-style": [ "error", "unix" ],
112
+ "semi": [ "error", "never" ],
113
+ "operator-linebreak": [ "error", "after", { overrides: { "&&": "before", "||": "before", ":": "before" } } ],
114
+ "brace-style": [ "error", "stroustrup", { allowSingleLine: true } ],
115
+ "quotes": [ "error", "double" ],
116
+ "no-multi-spaces": "off",
117
+ "no-multiple-empty-lines": "off",
118
+ "key-spacing": "off",
119
+ "object-property-newline": "off",
120
+ "curly": "off",
121
+ "space-in-parens": "off",
122
+ "no-console": "off",
123
+ "lines-between-class-members": "off",
124
+ "array-bracket-spacing": "off",
125
+
126
+ "@typescript-eslint/no-require-imports": "off",
127
+ },
128
+ }
129
+ ]
package/etc/stx.conf ADDED
@@ -0,0 +1,29 @@
1
+ ##
2
+ ## MQTT-JSON-RPC -- JSON-RPC protocol over MQTT communication
3
+ ## Copyright (c) 2018-2025 Dr. Ralf S. Engelschall <rse@engelschall.com>
4
+ ## Licensed under MIT <https://spdx.org/licenses/MIT>
5
+ ##
6
+
7
+ # static code analysis (linting)
8
+ lint
9
+ tsc --project etc/tsc.json --noEmit && \
10
+ eslint --config etc/eslint.mts src/*.ts
11
+
12
+ # code compilation/transpiling (building)
13
+ build : lint
14
+ VITE_BUILD_FORMATS=es,cjs vite --config etc/vite.mts build --mode production
15
+ VITE_BUILD_FORMATS=umd vite --config etc/vite.mts build --mode production
16
+
17
+ # execute simple sample for testing
18
+ test
19
+ node sample/sample.ts
20
+
21
+ # cleanup (built artifacts)
22
+ clean
23
+ shx rm -rf dst
24
+
25
+ # cleanup (bootstrap artifacts)
26
+ distclean : clean
27
+ shx rm -f package-lock.json
28
+ shx rm -rf node_modules
29
+
package/etc/tsc.json ADDED
@@ -0,0 +1,27 @@
1
+ {
2
+ "compilerOptions": {
3
+ "outDir": "../dst",
4
+ "target": "es2022",
5
+ "module": "ESNext",
6
+ "moduleResolution": "Bundler",
7
+ "useDefineForClassFields": false,
8
+ "composite": false,
9
+ "strict": true,
10
+ "strictFunctionTypes": true,
11
+ "resolveJsonModule": false,
12
+ "isolatedModules": false,
13
+ "esModuleInterop": false,
14
+ "lib": [ "es2022", "dom" ],
15
+ "skipLibCheck": true,
16
+ "declaration": true,
17
+ "noEmit": false,
18
+ "rootDir": "../src"
19
+ },
20
+ "include": [
21
+ "../src/**/*.ts",
22
+ "../src/**/*.d.ts"
23
+ ],
24
+ "exclude": [
25
+ "../node_modules"
26
+ ]
27
+ }
@@ -0,0 +1 @@
1
+ {"root":["../src/mqtt-json-rpc.ts"],"version":"5.9.3"}
package/etc/vite.mts ADDED
@@ -0,0 +1,45 @@
1
+ /*
2
+ ** MQTT-JSON-RPC -- JSON-RPC protocol over MQTT communication
3
+ ** Copyright (c) 2018-2025 Dr. Ralf S. Engelschall <rse@engelschall.com>
4
+ ** Licensed under MIT <https://spdx.org/licenses/MIT>
5
+ */
6
+
7
+ import * as Vite from "vite"
8
+ import { tscPlugin } from "@wroud/vite-plugin-tsc"
9
+ import { viteSingleFile } from "vite-plugin-singlefile"
10
+ import { nodePolyfills } from "vite-plugin-node-polyfills"
11
+
12
+ const formats = process.env.VITE_BUILD_FORMATS ?? "esm"
13
+
14
+ export default Vite.defineConfig(({ command, mode }) => ({
15
+ logLevel: "info",
16
+ appType: "custom",
17
+ base: "",
18
+ root: "",
19
+ plugins: [
20
+ tscPlugin({
21
+ tscArgs: [ "--project", "etc/tsc.json" ],
22
+ packageManager: "npx",
23
+ prebuild: true
24
+ }),
25
+ ...(formats === "umd" ? [ nodePolyfills() ] : []),
26
+ viteSingleFile()
27
+ ],
28
+ build: {
29
+ lib: {
30
+ entry: "dst/mqtt-json-rpc.js",
31
+ formats: formats.split(","),
32
+ name: "MqttJsonRpc",
33
+ fileName: (format) => `mqtt-json-rpc.${format === "es" ? "esm" : format}.js`
34
+ },
35
+ target: "es2022",
36
+ outDir: "dst",
37
+ assetsDir: "",
38
+ emptyOutDir: (mode === "production") && formats !== "umd",
39
+ chunkSizeWarningLimit: 5000,
40
+ assetsInlineLimit: 0,
41
+ sourcemap: (mode === "development"),
42
+ minify: (mode === "production") && formats === "umd",
43
+ reportCompressedSize: (mode === "production")
44
+ }
45
+ }))
package/package.json CHANGED
@@ -1,40 +1,59 @@
1
1
  {
2
- "name": "mqtt-json-rpc",
3
- "version": "1.3.7",
4
- "description": "JSON-RPC protocol over MQTT communication",
5
- "keywords": [ "json-rpc", "json", "rpc", "mqtt" ],
6
- "main": "./mqtt-json-rpc.js",
7
- "license": "MIT",
8
- "repository": {
9
- "type": "git",
10
- "url": "https://github.com/rse/mqtt-json-rpc.git"
11
- },
2
+ "name": "mqtt-json-rpc",
3
+ "version": "2.1.0",
4
+ "description": "JSON-RPC protocol over MQTT communication",
5
+ "keywords": [ "json-rpc", "json", "rpc", "mqtt" ],
6
+ "license": "MIT",
7
+ "repository": "git+https://github.com/rse/mqtt-json-rpc.git",
8
+ "homepage": "https://github.com/rse/mqtt-json-rpc",
9
+ "bugs": "https://github.com/rse/mqtt-json-rpc/issues",
12
10
  "author": {
13
- "name": "Dr. Ralf S. Engelschall",
14
- "email": "rse@engelschall.com",
15
- "url": "http://engelschall.com"
11
+ "name": "Dr. Ralf S. Engelschall",
12
+ "email": "rse@engelschall.com",
13
+ "url": "http://engelschall.com"
14
+ },
15
+ "type": "module",
16
+ "types": "./dst/mqtt-json-rpc.d.ts",
17
+ "module": "./dst/mqtt-json-rpc.esm.js",
18
+ "main": "./dst/mqtt-json-rpc.cjs.js",
19
+ "browser": "./dst/mqtt-json-rpc.umd.js",
20
+ "exports": {
21
+ ".": {
22
+ "import": { "types": "./dst/mqtt-json-rpc.d.ts", "default": "./dst/mqtt-json-rpc.esm.js" },
23
+ "require": { "types": "./dst/mqtt-json-rpc.d.ts", "default": "./dst/mqtt-json-rpc.cjs.js" }
24
+ }
16
25
  },
17
- "homepage": "https://github.com/rse/mqtt-json-rpc",
18
- "bugs": "https://github.com/rse/mqtt-json-rpc/issues",
19
26
  "devDependencies": {
20
- "eslint": "8.36.0",
21
- "eslint-config-standard": "17.0.0",
22
- "eslint-plugin-import": "2.27.5",
23
- "eslint-plugin-node": "11.1.0",
24
- "mqtt": "4.3.7"
27
+ "@rse/stx": "1.1.4",
28
+ "shx": "0.4.0",
29
+ "eslint": "9.39.2",
30
+ "eslint-plugin-node": "11.1.0",
31
+ "globals": "17.0.0",
32
+ "@eslint/js": "9.39.2",
33
+ "@eslint/eslintrc": "3.3.3",
34
+ "typescript": "5.9.3",
35
+ "typescript-eslint": "8.51.0",
36
+ "@typescript-eslint/parser": "8.51.0",
37
+ "mqtt": "5.14.1",
38
+ "vite": "7.3.0",
39
+ "vite-plugin-singlefile": "2.3.0",
40
+ "vite-plugin-node-polyfills": "0.24.0",
41
+ "@wroud/vite-plugin-tsc": "0.12.2"
25
42
  },
26
43
  "peerDependencies": {
27
- "mqtt": ">=4.0.0"
44
+ "mqtt": ">=4.0.0"
28
45
  },
29
46
  "dependencies": {
30
- "pure-uuid": "1.6.3",
31
- "encodr": "1.3.4",
32
- "jsonrpc-lite": "2.2.0"
47
+ "pure-uuid": "2.0.0",
48
+ "encodr": "1.4.1",
49
+ "jsonrpc-lite": "2.2.0"
33
50
  },
34
51
  "engines": {
35
- "node": ">=12.0.0"
52
+ "node": ">=16.0.0"
36
53
  },
37
54
  "scripts": {
38
- "prepublishOnly": "eslint --config eslint.yaml mqtt-json-rpc.js sample/sample.js"
55
+ "prepublishOnly": "npm start build",
56
+ "start": "stx -v4 -c etc/stx.conf",
57
+ "test": "npm start test"
39
58
  }
40
59
  }
@@ -2,22 +2,21 @@
2
2
  "name": "sample",
3
3
  "version": "0.0.0",
4
4
  "description": "",
5
+ "type": "module",
5
6
  "dependencies": {
6
- "@babel/core": "7.17.9",
7
- "mqtt": "4.3.7",
7
+ "@babel/core": "7.28.5",
8
+ "mqtt": "5.14.1",
8
9
  "mqtt-json-rpc": ".."
9
10
  },
10
11
  "devDependencies": {
11
- "grunt": "1.5.2",
12
- "grunt-cli": "1.4.3",
13
- "grunt-browserify": "6.0.0",
14
- "browserify": "17.0.0",
15
- "babelify": "10.0.0",
16
- "@babel/preset-env": "7.16.11"
12
+ "vite": "7.3.0",
13
+ "vite-plugin-singlefile": "2.3.0",
14
+ "vite-plugin-node-polyfills": "0.24.0",
15
+ "@wroud/vite-plugin-tsc": "0.12.2"
17
16
  },
18
17
  "scripts": {
19
- "build": "grunt default",
20
- "start": "node sample.js",
18
+ "build": "vite --config vite.mjs build --mode production",
19
+ "start": "node sample.ts",
21
20
  "start:browser": "open sample.html",
22
21
  "clean": "rimraf node_modules sample.bundle.js"
23
22
  }
package/sample/sample.js CHANGED
@@ -1,32 +1,26 @@
1
-
2
- const MQTT = require("mqtt")
3
- const RPC = require("mqtt-json-rpc")
4
-
5
- const mqtt = MQTT.connect("wss://127.0.0.1:8889", {
1
+ import MQTT from "mqtt";
2
+ import RPC from "mqtt-json-rpc";
3
+ const mqtt = MQTT.connect("wss://10.1.0.10:8889", {
6
4
  rejectUnauthorized: false,
7
5
  username: "example",
8
6
  password: "example"
9
- })
10
-
11
- const rpc = new RPC(mqtt)
12
-
13
- rpc.on("error", (err) => { console.log("ERROR", err) })
14
- rpc.on("offline", () => { console.log("OFFLINE") })
15
- rpc.on("close", () => { console.log("CLOSE") })
16
- rpc.on("reconnect", () => { console.log("RECONNECT") })
17
- rpc.on("message", (topic, message) => { console.log("RECEIVED", topic, message.toString()) })
18
-
19
- rpc.on("connect", () => {
20
- console.log("CONNECT")
7
+ });
8
+ const rpc = new RPC(mqtt);
9
+ mqtt.on("error", (err) => { console.log("ERROR", err); });
10
+ mqtt.on("offline", () => { console.log("OFFLINE"); });
11
+ mqtt.on("close", () => { console.log("CLOSE"); });
12
+ mqtt.on("reconnect", () => { console.log("RECONNECT"); });
13
+ mqtt.on("message", (topic, message) => { console.log("RECEIVED", topic, message.toString()); });
14
+ mqtt.on("connect", () => {
15
+ console.log("CONNECT");
21
16
  rpc.register("example/hello", (a1, a2) => {
22
- console.log("example/hello: request: ", a1, a2)
23
- return `${a1}:${a2}`
24
- })
17
+ console.log("example/hello: request: ", a1, a2);
18
+ return `${a1}:${a2}`;
19
+ });
25
20
  rpc.call("example/hello", "world", 42).then((result) => {
26
- console.log("example/hello sucess: ", result)
27
- rpc.end()
21
+ console.log("example/hello sucess: ", result);
22
+ mqtt.end();
28
23
  }).catch((err) => {
29
- console.log("example/hello error: ", err)
30
- })
31
- })
32
-
24
+ console.log("example/hello error: ", err);
25
+ });
26
+ });
@@ -0,0 +1,34 @@
1
+
2
+ import MQTT from "mqtt"
3
+ import RPC from "mqtt-json-rpc"
4
+
5
+ const mqtt = MQTT.connect("wss://10.1.0.10:8889", {
6
+ rejectUnauthorized: false,
7
+ username: "example",
8
+ password: "example"
9
+ })
10
+
11
+ const rpc = new RPC(mqtt)
12
+
13
+ mqtt.on("error", (err) => { console.log("ERROR", err) })
14
+ mqtt.on("offline", () => { console.log("OFFLINE") })
15
+ mqtt.on("close", () => { console.log("CLOSE") })
16
+ mqtt.on("reconnect", () => { console.log("RECONNECT") })
17
+ mqtt.on("message", (topic, message) => { console.log("RECEIVED", topic, message.toString()) })
18
+
19
+ type Sample = (a: string, b: number) => string
20
+
21
+ mqtt.on("connect", () => {
22
+ console.log("CONNECT")
23
+ rpc.register<Sample>("example/hello", (a1, a2) => {
24
+ console.log("example/hello: request: ", a1, a2)
25
+ return `${a1}:${a2}`
26
+ })
27
+ rpc.call<Sample>("example/hello", "world", 42).then((result) => {
28
+ console.log("example/hello sucess: ", result)
29
+ mqtt.end()
30
+ }).catch((err) => {
31
+ console.log("example/hello error: ", err)
32
+ })
33
+ })
34
+
@@ -0,0 +1,26 @@
1
+ {
2
+ "compilerOptions": {
3
+ "outDir": ".",
4
+ "target": "es2024",
5
+ "module": "ESNext",
6
+ "moduleResolution": "Bundler",
7
+ "useDefineForClassFields": false,
8
+ "composite": false,
9
+ "strict": true,
10
+ "strictFunctionTypes": true,
11
+ "resolveJsonModule": false,
12
+ "isolatedModules": false,
13
+ "esModuleInterop": false,
14
+ "lib": [ "es2024", "dom" ],
15
+ "skipLibCheck": true,
16
+ "declaration": false,
17
+ "noEmit": false,
18
+ "rootDir": "."
19
+ },
20
+ "include": [
21
+ "./*.ts"
22
+ ],
23
+ "exclude": [
24
+ "./node_modules"
25
+ ]
26
+ }
@@ -0,0 +1 @@
1
+ {"root":["./sample.ts"],"version":"5.9.3"}
@@ -0,0 +1,36 @@
1
+
2
+ import * as Vite from "vite"
3
+ import { tscPlugin } from "@wroud/vite-plugin-tsc"
4
+ import { viteSingleFile } from "vite-plugin-singlefile"
5
+
6
+ export default Vite.defineConfig(({ command, mode }) => ({
7
+ logLevel: "info",
8
+ appType: "custom",
9
+ base: "",
10
+ root: "",
11
+ plugins: [
12
+ tscPlugin({
13
+ tscArgs: [ "--project", "tsc.json" ],
14
+ packageManager: "npx",
15
+ prebuild: true
16
+ }),
17
+ viteSingleFile()
18
+ ],
19
+ build: {
20
+ lib: {
21
+ entry: "sample.js",
22
+ formats: [ "umd" ],
23
+ name: "Sample",
24
+ fileName: (format) => "sample.bundle.js"
25
+ },
26
+ target: "es2024",
27
+ outDir: ".",
28
+ assetsDir: "",
29
+ emptyOutDir: false,
30
+ chunkSizeWarningLimit: 5000,
31
+ assetsInlineLimit: 0,
32
+ sourcemap: false,
33
+ minify: true,
34
+ reportCompressedSize: true
35
+ }
36
+ }))