mqtt-plus 1.4.1 → 1.4.3

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.
Files changed (74) hide show
  1. package/AGENTS.md +55 -44
  2. package/CHANGELOG.md +14 -0
  3. package/README.md +12 -5
  4. package/doc/mqtt-plus-api.md +693 -680
  5. package/doc/mqtt-plus-architecture.d2 +139 -0
  6. package/doc/mqtt-plus-architecture.md +10 -0
  7. package/doc/mqtt-plus-architecture.svg +95 -0
  8. package/doc/mqtt-plus-broker-setup.md +9 -3
  9. package/doc/mqtt-plus-comm.md +73 -0
  10. package/doc/mqtt-plus-internals.md +364 -44
  11. package/dst-stage1/mqtt-plus-auth.d.ts +1 -0
  12. package/dst-stage1/mqtt-plus-base.d.ts +3 -2
  13. package/dst-stage1/mqtt-plus-base.js +53 -22
  14. package/dst-stage1/mqtt-plus-event.d.ts +0 -2
  15. package/dst-stage1/mqtt-plus-event.js +6 -26
  16. package/dst-stage1/mqtt-plus-meta.d.ts +2 -2
  17. package/dst-stage1/mqtt-plus-meta.js +2 -2
  18. package/dst-stage1/mqtt-plus-msg.d.ts +2 -0
  19. package/dst-stage1/mqtt-plus-msg.js +17 -0
  20. package/dst-stage1/mqtt-plus-service.d.ts +0 -5
  21. package/dst-stage1/mqtt-plus-service.js +12 -48
  22. package/dst-stage1/mqtt-plus-sink.d.ts +0 -10
  23. package/dst-stage1/mqtt-plus-sink.js +25 -92
  24. package/dst-stage1/mqtt-plus-source.d.ts +0 -10
  25. package/dst-stage1/mqtt-plus-source.js +23 -88
  26. package/dst-stage1/mqtt-plus-subscription.d.ts +20 -0
  27. package/dst-stage1/mqtt-plus-subscription.js +126 -0
  28. package/dst-stage1/mqtt-plus-timer.d.ts +8 -0
  29. package/dst-stage1/mqtt-plus-timer.js +57 -0
  30. package/dst-stage1/mqtt-plus-topic.d.ts +20 -0
  31. package/dst-stage1/mqtt-plus-topic.js +112 -0
  32. package/dst-stage1/mqtt-plus-trace.js +2 -0
  33. package/dst-stage1/mqtt-plus-util.d.ts +0 -13
  34. package/dst-stage1/mqtt-plus-util.js +1 -77
  35. package/dst-stage1/mqtt-plus-version.d.ts +0 -1
  36. package/dst-stage1/mqtt-plus-version.js +0 -6
  37. package/dst-stage1/tsc.tsbuildinfo +1 -1
  38. package/dst-stage2/mqtt-plus.cjs.js +242 -292
  39. package/dst-stage2/mqtt-plus.esm.js +240 -290
  40. package/dst-stage2/mqtt-plus.umd.js +12 -12
  41. package/etc/knip.jsonc +1 -1
  42. package/etc/stx.conf +5 -4
  43. package/package.json +1 -1
  44. package/src/mqtt-plus-auth.ts +1 -1
  45. package/src/mqtt-plus-base.ts +56 -26
  46. package/src/mqtt-plus-event.ts +8 -24
  47. package/src/mqtt-plus-meta.ts +3 -3
  48. package/src/mqtt-plus-msg.ts +28 -0
  49. package/src/mqtt-plus-service.ts +12 -50
  50. package/src/mqtt-plus-sink.ts +32 -105
  51. package/src/mqtt-plus-source.ts +29 -99
  52. package/src/mqtt-plus-subscription.ts +141 -0
  53. package/src/mqtt-plus-timer.ts +61 -0
  54. package/src/mqtt-plus-trace.ts +4 -0
  55. package/src/mqtt-plus-util.ts +1 -81
  56. package/src/mqtt-plus-version.ts +0 -7
  57. package/tst/mqtt-plus-0-fixture.ts +2 -2
  58. package/tst/mqtt-plus-0-mosquitto.ts +5 -0
  59. package/tst/mqtt-plus-1-api.spec.ts +1 -1
  60. package/tst/mqtt-plus-2-event.spec.ts +0 -6
  61. package/tst/mqtt-plus-3-service.spec.ts +3 -7
  62. package/tst/mqtt-plus-4-sink.spec.ts +11 -6
  63. package/tst/mqtt-plus-5-source.spec.ts +8 -2
  64. package/tst/mqtt-plus-6-misc.spec.ts +8 -5
  65. package/doc/mqtt-plus-communication.md +0 -68
  66. /package/doc/{mqtt-plus-1-event-emission.d2 → mqtt-plus-comm-event-emission.d2} +0 -0
  67. /package/doc/{mqtt-plus-1-event-emission.svg → mqtt-plus-comm-event-emission.svg} +0 -0
  68. /package/doc/{mqtt-plus-2-service-call.d2 → mqtt-plus-comm-service-call.d2} +0 -0
  69. /package/doc/{mqtt-plus-2-service-call.svg → mqtt-plus-comm-service-call.svg} +0 -0
  70. /package/doc/{mqtt-plus-3-sink-push.d2 → mqtt-plus-comm-sink-push.d2} +0 -0
  71. /package/doc/{mqtt-plus-3-sink-push.svg → mqtt-plus-comm-sink-push.svg} +0 -0
  72. /package/doc/{mqtt-plus-4-source-fetch.d2 → mqtt-plus-comm-source-fetch.d2} +0 -0
  73. /package/doc/{mqtt-plus-4-source-fetch.svg → mqtt-plus-comm-source-fetch.svg} +0 -0
  74. /package/{doc/theme.d2 → etc/d2.theme.d2} +0 -0
package/AGENTS.md CHANGED
@@ -14,17 +14,26 @@ It uses `mqtt` as a peer dependency and builds to ESM, CJS, and UMD formats.
14
14
  Commands
15
15
  --------
16
16
 
17
+ MQTT+ plus uses NPM:
18
+
19
+ ```bash
20
+ npm install # install dependencies
21
+ ```
22
+
17
23
  Build and development commands use STX (`@rse/stx`) as the task runner:
18
24
 
19
25
  ```bash
20
- npm start lint # type-check (tsc), lint (eslint), dead-code check (knip)
21
- npm start build # lint + vite bundle (ESM, CJS, UMD into dst-stage2/)
22
- npm start test # lint test file + run mocha test suite
23
- npm start dev # watch mode (chokidar → rebuild on change)
24
- npm start sample # run sample/sample.ts via tsx
25
- npm start build-doc # generate SVG diagrams from D2 sources in doc/
26
+ npm start lint # standard: perform static code analysis
27
+ npm start build # standard: build everything
28
+ npm start test # standard: run unit test suite
29
+
30
+ npm start build-doc # generate SVG diagrams from D2 sources only
31
+ npm start dev # development watch mode (rebuild on change)
32
+ npm start sample # run sample/sample.ts via `tsx`
33
+
26
34
  npm start clean # remove dst-stage1/ and dst-stage2/
27
- npm start distclean # clean + remove node_modules/ and package-lock.json
35
+ npm start distclean # remove node_modules/ and package-lock.json
36
+
28
37
  ```
29
38
 
30
39
  Tests require a Mosquitto MQTT broker under run-time; the `mosquitto`
@@ -54,55 +63,57 @@ each extending the previous. The final exported class `MQTTp` sits at
54
63
  the bottom of this chain:
55
64
 
56
65
  ```
57
- OptionsTrait — configuration (id, codec, timeout, chunkSize, chunkCredit, topicMake/topicMatch)
58
- ↓ CodecTrait — CBOR/JSON codec handling
59
- ↓ EncodeTrait — message encoding/validation (valibot schemas)
60
- ↓ MsgTrait — message class definitions and parsing
61
- ↓ TraceTrait — EventEmitter + structured logging
62
- ↓ BaseTrait — MQTT client hookup, subscription management, message routing
63
- MetaTrait instance/per-request metadata
64
- AuthTrait JWT authentication (jose), role-based access
65
- EventTrait Event Emission pattern (event/emit)
66
- ServiceTrait Service Call / RPC pattern (service/call)
67
- SourceTrait Source Fetch pattern (source/fetch)
68
- SinkTrait Sink Push pattern (sink/push)
69
- MQTTp final exported class
66
+ OptionsTrait — configuration (id, codec, timeout, chunkSize, chunkCredit, topicMake/topicMatch)
67
+ ↓ CodecTrait — CBOR/JSON codec handling
68
+ ↓ EncodeTrait — message encoding/validation (valibot schemas)
69
+ ↓ MsgTrait — message class definitions and parsing
70
+ ↓ TraceTrait — EventEmitter + structured logging
71
+ ↓ BaseTrait — MQTT client hookup, subscription management, message routing
72
+ SubscriptionTrait ref-counted MQTT topic subscription management
73
+ MetaTrait instance/per-request metadata
74
+ AuthTrait JWT authentication (jose), role-based access
75
+ EventTrait Event Emission pattern (event/emit)
76
+ ServiceTrait Service Call / RPC pattern (service/call)
77
+ SourceTrait Source Fetch pattern (source/fetch)
78
+ SinkTrait Sink Push pattern (sink/push)
79
+ ↓ MQTTp — final exported class
70
80
  ```
71
81
 
72
82
  Each trait lives in its own file: `src/mqtt-plus-<trait>.ts`.
73
83
 
74
84
  ### Key Source Files
75
85
 
76
- | File | Role |
77
- |----------------------------|------|
78
- | `src/mqtt-plus.ts` | Main entry point, re-exports public API types and the final MQTTp class |
79
- | `src/mqtt-plus-api.ts` | Branded endpoint type definitions (Event, Service, Source, Sink) and APISchema generic |
80
- | `src/mqtt-plus-info.ts` | Info/context object types passed to pattern callbacks (sender metadata, etc.) |
81
- | `src/mqtt-plus-error.ts` | Spool (resource cleanup) and run (error handling) utilities |
82
- | `src/mqtt-plus-util.ts` | Stream/buffer conversion, RefCountedSubscription, and CreditGate flow control |
83
- | `src/mqtt-plus-version.ts` | Version utility for converting version strings to numeric format |
84
- | `src/mqtt-plus-options.ts` | OptionsTrait — configuration (id, codec, timeout, chunkSize, chunkCredit, topicMake/topicMatch) |
85
- | `src/mqtt-plus-codec.ts` | CodecTrait — CBOR and JSON codec encoding/decoding |
86
- | `src/mqtt-plus-encode.ts` | EncodeTrait — message validation and encoding via valibot schemas |
87
- | `src/mqtt-plus-msg.ts` | MsgTrait — message class definitions and parsing logic |
88
- | `src/mqtt-plus-trace.ts` | TraceTrait — EventEmitter and structured logging |
89
- | `src/mqtt-plus-base.ts` | BaseTrait — MQTT client connection, subscription management, message routing |
90
- | `src/mqtt-plus-meta.ts` | MetaTraitinstance and per-request metadata management |
91
- | `src/mqtt-plus-auth.ts` | AuthTraitJWT authentication (jose) and role-based access control |
92
- | `src/mqtt-plus-event.ts` | EventTraitEvent Emission communication pattern (event/emit) |
93
- | `src/mqtt-plus-service.ts` | ServiceTraitService Call / RPC communication pattern (service/call) |
94
- | `src/mqtt-plus-source.ts` | SourceTraitSource Fetch communication pattern (source/fetch) |
95
- | `src/mqtt-plus-sink.ts` | SinkTraitSink Push communication pattern (sink/push) |
86
+ | File | Role |
87
+ |---------------------------------|------|
88
+ | `src/mqtt-plus.ts` | Main entry point, re-exports public API types and the final MQTTp class |
89
+ | `src/mqtt-plus-api.ts` | Branded endpoint type definitions (Event, Service, Source, Sink) and APISchema generic |
90
+ | `src/mqtt-plus-info.ts` | Info/context object types passed to pattern callbacks (sender metadata, etc.) |
91
+ | `src/mqtt-plus-error.ts` | Spool (resource cleanup) and run (error handling) utilities |
92
+ | `src/mqtt-plus-util.ts` | Stream/buffer conversion, RefCountedSubscription, and CreditGate flow control |
93
+ | `src/mqtt-plus-version.ts` | Version utility for converting version strings to numeric format |
94
+ | `src/mqtt-plus-options.ts` | OptionsTrait — configuration (id, codec, timeout, chunkSize, chunkCredit, topicMake/topicMatch) |
95
+ | `src/mqtt-plus-codec.ts` | CodecTrait — CBOR and JSON codec encoding/decoding |
96
+ | `src/mqtt-plus-encode.ts` | EncodeTrait — message validation and encoding via valibot schemas |
97
+ | `src/mqtt-plus-msg.ts` | MsgTrait — message class definitions and parsing logic |
98
+ | `src/mqtt-plus-trace.ts` | TraceTrait — EventEmitter and structured logging |
99
+ | `src/mqtt-plus-base.ts` | BaseTrait — MQTT client connection, subscription management, message routing |
100
+ | `src/mqtt-plus-subscription.ts` | SubscriptionTraitref-counted MQTT topic subscription management |
101
+ | `src/mqtt-plus-meta.ts` | MetaTraitinstance and per-request metadata management |
102
+ | `src/mqtt-plus-auth.ts` | AuthTraitJWT authentication (jose) and role-based access control |
103
+ | `src/mqtt-plus-event.ts` | EventTraitEvent Emission communication pattern (event/emit) |
104
+ | `src/mqtt-plus-service.ts` | ServiceTraitService Call / RPC communication pattern (service/call) |
105
+ | `src/mqtt-plus-source.ts` | SourceTraitSource Fetch communication pattern (source/fetch) |
106
+ | `src/mqtt-plus-sink.ts` | SinkTrait — Sink Push communication pattern (sink/push) |
96
107
 
97
108
  ### Documentation
98
109
 
99
110
  The `doc/` directory contains D2 diagram sources and generated SVG files
100
111
  illustrating the four communication patterns:
101
112
 
102
- - `doc/mqtt-plus-1-event-emission.{d2,svg}`
103
- - `doc/mqtt-plus-2-service-call.{d2,svg}`
104
- - `doc/mqtt-plus-3-sink-push.{d2,svg}`
105
- - `doc/mqtt-plus-4-source-fetch.{d2,svg}`
113
+ - `doc/mqtt-plus-comm-event-emission.{d2,svg}`
114
+ - `doc/mqtt-plus-comm-service-call.{d2,svg}`
115
+ - `doc/mqtt-plus-comm-sink-push.{d2,svg}`
116
+ - `doc/mqtt-plus-comm-source-fetch.{d2,svg}`
106
117
  - `doc/theme.d2` — shared D2 theme
107
118
 
108
119
  Regenerate with `npm start build-doc` (requires the `etc/d2.mts` helper script).
package/CHANGELOG.md CHANGED
@@ -2,6 +2,20 @@
2
2
  ChangeLog
3
3
  =========
4
4
 
5
+ 1.4.3 (2026-02-21)
6
+ ------------------
7
+
8
+ - IMPROVEMENT: allow JWT expirations
9
+ - DOCUMENTATION: document more internals
10
+
11
+ 1.4.2 (2026-02-21)
12
+ ------------------
13
+
14
+ - DOCUMENTATION: add architecture overview
15
+ - CLEANUP: cleanup documentation
16
+ - CLEANUP: simplify internal message handling
17
+ - CLEANUP: simplify internal MQTT topic subscription handling
18
+
5
19
  1.4.1 (2026-02-21)
6
20
  ------------------
7
21
 
package/README.md CHANGED
@@ -4,7 +4,7 @@
4
4
  MQTT+
5
5
  =====
6
6
 
7
- [MQTT](http://mqtt.org/) [Communication Patterns](doc/mqtt-plus-communication.md)
7
+ [MQTT](http://mqtt.org/) [Communication Patterns](doc/mqtt-plus-comm.md)
8
8
 
9
9
  <p/>
10
10
  <img src="https://nodei.co/npm/mqtt-plus.png?downloads=true&stars=true" alt=""/>
@@ -19,7 +19,7 @@ About
19
19
  API [MQTT.js](https://www.npmjs.com/package/mqtt), providing
20
20
  additional communication patterns with full type safety for
21
21
  [MQTT](http://mqtt.org/). Currently the essential
22
- [communication patterns](doc/mqtt-plus-communication.md)
22
+ [communication patterns](doc/mqtt-plus-comm.md)
23
23
  *Event Emission*, *Service Call*, *Sink Push* and *Source Fetch* are
24
24
  supported.
25
25
 
@@ -117,9 +117,15 @@ mqtt.on("connect", async () => {
117
117
  Documentation
118
118
  -------------
119
119
 
120
- - [**Communication Patterns**](doc/mqtt-plus-communication.md)
120
+ Main documentation:
121
+
122
+ - [**Communication Patterns**](doc/mqtt-plus-comm.md)
121
123
  - [**Application Programming Interface (API)**](doc/mqtt-plus-api.md)
122
- - [Extra: Internals](doc/mqtt-plus-internals.md)
124
+
125
+ Additional auxilliary documentation:
126
+
127
+ - [Extra: Architecture Overview](doc/mqtt-plus-architecture.md)
128
+ - [Extra: Internal Protocol](doc/mqtt-plus-internals.md)
123
129
  - [Extra: Broker Setup](doc/mqtt-plus-broker-setup.md)
124
130
 
125
131
  Notice
@@ -138,7 +144,7 @@ Notice
138
144
  License
139
145
  -------
140
146
 
141
- Copyright (c) 2018-2026 Dr. Ralf S. Engelschall (http://engelschall.com/)
147
+ Copyright &copy; 2018-2026 Dr. Ralf S. Engelschall (http://engelschall.com/)
142
148
 
143
149
  Permission is hereby granted, free of charge, to any person obtaining
144
150
  a copy of this software and associated documentation files (the
@@ -158,3 +164,4 @@ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
158
164
  CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
159
165
  TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
160
166
  SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
167
+