mqtt-plus 1.4.0 → 1.4.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/AGENTS.md +55 -44
- package/CHANGELOG.md +14 -0
- package/README.md +4 -3
- package/doc/mqtt-plus-api.md +693 -680
- package/doc/mqtt-plus-architecture.d2 +139 -0
- package/doc/mqtt-plus-architecture.md +10 -0
- package/doc/mqtt-plus-architecture.svg +95 -0
- package/doc/mqtt-plus-broker-setup.md +9 -3
- package/doc/mqtt-plus-comm.md +73 -0
- package/doc/mqtt-plus-internals.md +3 -3
- package/dst-stage1/mqtt-plus-base.d.ts +3 -2
- package/dst-stage1/mqtt-plus-base.js +53 -22
- package/dst-stage1/mqtt-plus-event.d.ts +0 -2
- package/dst-stage1/mqtt-plus-event.js +6 -26
- package/dst-stage1/mqtt-plus-meta.d.ts +2 -2
- package/dst-stage1/mqtt-plus-meta.js +2 -2
- package/dst-stage1/mqtt-plus-msg.d.ts +2 -0
- package/dst-stage1/mqtt-plus-msg.js +17 -0
- package/dst-stage1/mqtt-plus-service.d.ts +0 -5
- package/dst-stage1/mqtt-plus-service.js +12 -48
- package/dst-stage1/mqtt-plus-sink.d.ts +0 -10
- package/dst-stage1/mqtt-plus-sink.js +25 -92
- package/dst-stage1/mqtt-plus-source.d.ts +0 -10
- package/dst-stage1/mqtt-plus-source.js +23 -88
- package/dst-stage1/mqtt-plus-subscription.d.ts +20 -0
- package/dst-stage1/mqtt-plus-subscription.js +126 -0
- package/dst-stage1/mqtt-plus-timer.d.ts +8 -0
- package/dst-stage1/mqtt-plus-timer.js +57 -0
- package/dst-stage1/mqtt-plus-topic.d.ts +20 -0
- package/dst-stage1/mqtt-plus-topic.js +112 -0
- package/dst-stage1/mqtt-plus-trace.js +2 -0
- package/dst-stage1/mqtt-plus-util.d.ts +0 -13
- package/dst-stage1/mqtt-plus-util.js +1 -77
- package/dst-stage1/mqtt-plus-version.d.ts +0 -1
- package/dst-stage1/mqtt-plus-version.js +0 -6
- package/dst-stage1/tsc.tsbuildinfo +1 -1
- package/dst-stage2/mqtt-plus.cjs.js +242 -292
- package/dst-stage2/mqtt-plus.esm.js +240 -290
- package/dst-stage2/mqtt-plus.umd.js +12 -12
- package/etc/knip.jsonc +1 -1
- package/etc/stx.conf +6 -4
- package/package.json +1 -1
- package/src/mqtt-plus-base.ts +56 -26
- package/src/mqtt-plus-event.ts +8 -24
- package/src/mqtt-plus-meta.ts +3 -3
- package/src/mqtt-plus-msg.ts +28 -0
- package/src/mqtt-plus-service.ts +12 -50
- package/src/mqtt-plus-sink.ts +32 -105
- package/src/mqtt-plus-source.ts +29 -99
- package/src/mqtt-plus-subscription.ts +141 -0
- package/src/mqtt-plus-timer.ts +61 -0
- package/src/mqtt-plus-trace.ts +4 -0
- package/src/mqtt-plus-util.ts +1 -81
- package/src/mqtt-plus-version.ts +0 -7
- package/tst/mqtt-plus-0-fixture.ts +2 -2
- package/tst/mqtt-plus-0-mosquitto.ts +5 -0
- package/tst/mqtt-plus-1-api.spec.ts +1 -1
- package/tst/mqtt-plus-2-event.spec.ts +0 -6
- package/tst/mqtt-plus-3-service.spec.ts +3 -7
- package/tst/mqtt-plus-4-sink.spec.ts +14 -9
- package/tst/mqtt-plus-5-source.spec.ts +11 -5
- package/tst/mqtt-plus-6-misc.spec.ts +23 -23
- package/tst/tsc.json +1 -1
- package/doc/mqtt-plus-communication.md +0 -68
- /package/doc/{mqtt-plus-1-event-emission.d2 → mqtt-plus-comm-event-emission.d2} +0 -0
- /package/doc/{mqtt-plus-1-event-emission.svg → mqtt-plus-comm-event-emission.svg} +0 -0
- /package/doc/{mqtt-plus-2-service-call.d2 → mqtt-plus-comm-service-call.d2} +0 -0
- /package/doc/{mqtt-plus-2-service-call.svg → mqtt-plus-comm-service-call.svg} +0 -0
- /package/doc/{mqtt-plus-3-sink-push.d2 → mqtt-plus-comm-sink-push.d2} +0 -0
- /package/doc/{mqtt-plus-3-sink-push.svg → mqtt-plus-comm-sink-push.svg} +0 -0
- /package/doc/{mqtt-plus-4-source-fetch.d2 → mqtt-plus-comm-source-fetch.d2} +0 -0
- /package/doc/{mqtt-plus-4-source-fetch.svg → mqtt-plus-comm-source-fetch.svg} +0 -0
- /package/{doc/theme.d2 → etc/d2.theme.d2} +0 -0
|
@@ -25,82 +25,6 @@
|
|
|
25
25
|
import { Buffer } from "node:buffer";
|
|
26
26
|
/* external requirements */
|
|
27
27
|
import PLazy from "p-lazy";
|
|
28
|
-
/* reference-counted subscription helper */
|
|
29
|
-
export class RefCountedSubscription {
|
|
30
|
-
constructor(subscribeFn, unsubscribeFn, lingerMs = 30 * 1000) {
|
|
31
|
-
this.subscribeFn = subscribeFn;
|
|
32
|
-
this.unsubscribeFn = unsubscribeFn;
|
|
33
|
-
this.lingerMs = lingerMs;
|
|
34
|
-
this.counts = new Map();
|
|
35
|
-
this.pending = new Map();
|
|
36
|
-
this.lingers = new Map();
|
|
37
|
-
}
|
|
38
|
-
async subscribe(topic, options = { qos: 2 }) {
|
|
39
|
-
/* increment count first to reserve our interest */
|
|
40
|
-
const count = this.counts.get(topic) ?? 0;
|
|
41
|
-
this.counts.set(topic, count + 1);
|
|
42
|
-
/* optionally just cancel a pending linger unsubscription
|
|
43
|
-
(subscription is still kept active on the broker) */
|
|
44
|
-
const linger = this.lingers.get(topic);
|
|
45
|
-
if (linger) {
|
|
46
|
-
clearTimeout(linger);
|
|
47
|
-
this.lingers.delete(topic);
|
|
48
|
-
return;
|
|
49
|
-
}
|
|
50
|
-
/* if we are the first, we must perform the actual subscription */
|
|
51
|
-
if (count === 0) {
|
|
52
|
-
const promise = this.subscribeFn(topic, options).finally(() => {
|
|
53
|
-
this.pending.delete(topic);
|
|
54
|
-
}).catch((err) => {
|
|
55
|
-
const count = this.counts.get(topic);
|
|
56
|
-
if (count) {
|
|
57
|
-
if (count <= 1)
|
|
58
|
-
this.counts.delete(topic);
|
|
59
|
-
else
|
|
60
|
-
this.counts.set(topic, count - 1);
|
|
61
|
-
}
|
|
62
|
-
throw err;
|
|
63
|
-
});
|
|
64
|
-
this.pending.set(topic, promise);
|
|
65
|
-
return promise;
|
|
66
|
-
}
|
|
67
|
-
else {
|
|
68
|
-
/* perhaps still need to wait for a pending subscription */
|
|
69
|
-
const pending = this.pending.get(topic);
|
|
70
|
-
if (pending)
|
|
71
|
-
return pending;
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
async unsubscribe(topic) {
|
|
75
|
-
const count = this.counts.get(topic);
|
|
76
|
-
if (count) {
|
|
77
|
-
if (count <= 1) {
|
|
78
|
-
this.counts.delete(topic);
|
|
79
|
-
if (this.lingerMs > 0) {
|
|
80
|
-
/* defer the actual broker unsubscription */
|
|
81
|
-
const timer = setTimeout(() => {
|
|
82
|
-
this.lingers.delete(topic);
|
|
83
|
-
this.unsubscribeFn(topic).catch(() => { });
|
|
84
|
-
}, this.lingerMs);
|
|
85
|
-
this.lingers.set(topic, timer);
|
|
86
|
-
}
|
|
87
|
-
else
|
|
88
|
-
await this.unsubscribeFn(topic).catch(() => { });
|
|
89
|
-
}
|
|
90
|
-
else
|
|
91
|
-
this.counts.set(topic, count - 1);
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
async flush() {
|
|
95
|
-
/* flush all pending linger timers and unsubscribe immediately */
|
|
96
|
-
const topics = [...this.lingers.keys()];
|
|
97
|
-
for (const topic of topics) {
|
|
98
|
-
clearTimeout(this.lingers.get(topic));
|
|
99
|
-
this.lingers.delete(topic);
|
|
100
|
-
await this.unsubscribeFn(topic).catch(() => { });
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
28
|
/* credit-based flow control gate for chunk producers */
|
|
105
29
|
export class CreditGate {
|
|
106
30
|
constructor(initialCredit) {
|
|
@@ -152,7 +76,7 @@ export class CreditGate {
|
|
|
152
76
|
this.waiters.shift()(true);
|
|
153
77
|
}
|
|
154
78
|
}
|
|
155
|
-
/* concatenate elements of
|
|
79
|
+
/* concatenate elements of a Uint8Array array */
|
|
156
80
|
function uint8ArrayConcat(arrays) {
|
|
157
81
|
const totalLength = arrays.reduce((acc, value) => acc + value.byteLength, 0);
|
|
158
82
|
const result = new Uint8Array(totalLength);
|
|
@@ -31,12 +31,6 @@ export const versionToNum = (str) => {
|
|
|
31
31
|
throw new Error("invalid version string: minor version exceeds 99");
|
|
32
32
|
return parseInt(m[1], 10) + minor / 100;
|
|
33
33
|
};
|
|
34
|
-
/* convert version number to string */
|
|
35
|
-
export const versionToStr = (num) => {
|
|
36
|
-
const intPart = Math.floor(num);
|
|
37
|
-
const decPart = Math.round((num - intPart) * 100);
|
|
38
|
-
return `${intPart.toFixed(0)}.${decPart.toFixed(0).padStart(2, "0")}`;
|
|
39
|
-
};
|
|
40
34
|
export const VERSION = __VERSION__;
|
|
41
35
|
/* package version (numeric format) */
|
|
42
36
|
export const version = versionToNum(VERSION);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"root":["../src/mqtt-plus-api.ts","../src/mqtt-plus-auth.ts","../src/mqtt-plus-base.ts","../src/mqtt-plus-codec.ts","../src/mqtt-plus-encode.ts","../src/mqtt-plus-error.ts","../src/mqtt-plus-event.ts","../src/mqtt-plus-info.ts","../src/mqtt-plus-meta.ts","../src/mqtt-plus-msg.ts","../src/mqtt-plus-options.ts","../src/mqtt-plus-service.ts","../src/mqtt-plus-sink.ts","../src/mqtt-plus-source.ts","../src/mqtt-plus-trace.ts","../src/mqtt-plus-util.ts","../src/mqtt-plus-version.ts","../src/mqtt-plus.ts"],"version":"5.9.3"}
|
|
1
|
+
{"root":["../src/mqtt-plus-api.ts","../src/mqtt-plus-auth.ts","../src/mqtt-plus-base.ts","../src/mqtt-plus-codec.ts","../src/mqtt-plus-encode.ts","../src/mqtt-plus-error.ts","../src/mqtt-plus-event.ts","../src/mqtt-plus-info.ts","../src/mqtt-plus-meta.ts","../src/mqtt-plus-msg.ts","../src/mqtt-plus-options.ts","../src/mqtt-plus-service.ts","../src/mqtt-plus-sink.ts","../src/mqtt-plus-source.ts","../src/mqtt-plus-subscription.ts","../src/mqtt-plus-timer.ts","../src/mqtt-plus-trace.ts","../src/mqtt-plus-util.ts","../src/mqtt-plus-version.ts","../src/mqtt-plus.ts"],"version":"5.9.3"}
|