mqtt-plus 1.4.16 → 1.4.18
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/.claude/CLAUDE.md +1 -0
- package/.gemini/settings.json +5 -0
- package/AGENTS.md +86 -97
- package/CHANGELOG.md +41 -0
- package/README.md +1 -1
- package/doc/mqtt-plus-api.md +24 -15
- package/doc/mqtt-plus-architecture.md +1 -1
- package/doc/mqtt-plus-broker-setup.md +2 -2
- package/doc/mqtt-plus-comm.md +3 -2
- package/doc/mqtt-plus-internals.md +11 -1
- package/dst-stage1/mqtt-plus-auth.d.ts +1 -1
- package/dst-stage1/mqtt-plus-auth.js +18 -17
- package/dst-stage1/mqtt-plus-auth.js.map +1 -1
- package/dst-stage1/mqtt-plus-base.d.ts +2 -1
- package/dst-stage1/mqtt-plus-base.js +32 -7
- package/dst-stage1/mqtt-plus-base.js.map +1 -1
- package/dst-stage1/mqtt-plus-error.d.ts +1 -0
- package/dst-stage1/mqtt-plus-error.js +69 -39
- package/dst-stage1/mqtt-plus-error.js.map +1 -1
- package/dst-stage1/mqtt-plus-event.d.ts +4 -2
- package/dst-stage1/mqtt-plus-event.js +61 -13
- package/dst-stage1/mqtt-plus-event.js.map +1 -1
- package/dst-stage1/mqtt-plus-info.d.ts +2 -0
- package/dst-stage1/mqtt-plus-msg.d.ts +12 -8
- package/dst-stage1/mqtt-plus-msg.js +31 -23
- package/dst-stage1/mqtt-plus-msg.js.map +1 -1
- package/dst-stage1/mqtt-plus-options.d.ts +1 -1
- package/dst-stage1/mqtt-plus-service.d.ts +3 -0
- package/dst-stage1/mqtt-plus-service.js +146 -24
- package/dst-stage1/mqtt-plus-service.js.map +1 -1
- package/dst-stage1/mqtt-plus-sink.js +210 -92
- package/dst-stage1/mqtt-plus-sink.js.map +1 -1
- package/dst-stage1/mqtt-plus-source.d.ts +1 -0
- package/dst-stage1/mqtt-plus-source.js +186 -123
- package/dst-stage1/mqtt-plus-source.js.map +1 -1
- package/dst-stage1/mqtt-plus-subscription.d.ts +1 -0
- package/dst-stage1/mqtt-plus-subscription.js +23 -18
- package/dst-stage1/mqtt-plus-subscription.js.map +1 -1
- package/dst-stage1/mqtt-plus-timer.d.ts +2 -0
- package/dst-stage1/mqtt-plus-timer.js +52 -0
- package/dst-stage1/mqtt-plus-timer.js.map +1 -1
- package/dst-stage1/mqtt-plus-trace.js +10 -3
- package/dst-stage1/mqtt-plus-trace.js.map +1 -1
- package/dst-stage1/mqtt-plus-util.js +18 -10
- package/dst-stage1/mqtt-plus-util.js.map +1 -1
- package/dst-stage1/mqtt-plus-version.d.ts +2 -0
- package/dst-stage1/mqtt-plus-version.js +3 -0
- package/dst-stage1/mqtt-plus-version.js.map +1 -1
- package/dst-stage2/mqtt-plus.cjs.cjs +692 -323
- package/dst-stage2/mqtt-plus.esm.js +687 -318
- package/dst-stage2/mqtt-plus.umd.js +11 -11
- package/etc/d2.mts +47 -13
- package/etc/eslint.mts +6 -2
- package/etc/stx.conf +8 -6
- package/etc/vite.mts +14 -5
- package/package.d/{@typescript-eslint+typescript-estree+8.57.2.patch → @typescript-eslint+typescript-estree+8.58.1.patch} +1 -1
- package/package.d/{vite+8.0.3.patch → vite+8.0.8.patch} +2 -2
- package/package.json +16 -16
- package/src/mqtt-plus-auth.ts +18 -17
- package/src/mqtt-plus-base.ts +38 -7
- package/src/mqtt-plus-error.ts +73 -41
- package/src/mqtt-plus-event.ts +71 -17
- package/src/mqtt-plus-info.ts +6 -2
- package/src/mqtt-plus-msg.ts +35 -21
- package/src/mqtt-plus-options.ts +1 -1
- package/src/mqtt-plus-service.ts +157 -26
- package/src/mqtt-plus-sink.ts +227 -94
- package/src/mqtt-plus-source.ts +205 -126
- package/src/mqtt-plus-subscription.ts +26 -19
- package/src/mqtt-plus-timer.ts +56 -0
- package/src/mqtt-plus-trace.ts +10 -3
- package/src/mqtt-plus-util.ts +19 -10
- package/src/mqtt-plus-version.ts +5 -1
- package/tst/mqtt-plus-0-broker-mosquitto.ts +2 -2
- package/tst/mqtt-plus-3-service.spec.ts +3 -3
- package/tst/mqtt-plus-4-sink.spec.ts +3 -3
- package/tst/mqtt-plus-7-spool.spec.ts +65 -0
|
@@ -29,6 +29,8 @@ export class BaseTrait extends TraceTrait {
|
|
|
29
29
|
/* construct API class */
|
|
30
30
|
constructor(mqtt, options = {}) {
|
|
31
31
|
super(options);
|
|
32
|
+
/* lifecycle state */
|
|
33
|
+
this.destroyed = false;
|
|
32
34
|
/* central message callback registries */
|
|
33
35
|
this.onRequest = new Map();
|
|
34
36
|
this.onResponse = new Map();
|
|
@@ -56,6 +58,8 @@ export class BaseTrait extends TraceTrait {
|
|
|
56
58
|
/* hook into the MQTT message processing */
|
|
57
59
|
this.log("info", "hooking into MQTT client");
|
|
58
60
|
this.messageHandler = (topic, message, packet) => {
|
|
61
|
+
if (this.destroyed)
|
|
62
|
+
return;
|
|
59
63
|
/* convert message to codec-specific input format
|
|
60
64
|
(NOTICE: MQTT.js uses Buffer in its handler signature only,
|
|
61
65
|
but internally supports string or Buffer, while we are
|
|
@@ -75,17 +79,20 @@ export class BaseTrait extends TraceTrait {
|
|
|
75
79
|
}
|
|
76
80
|
/* destroy API class */
|
|
77
81
|
async destroy() {
|
|
82
|
+
this.destroyed = true;
|
|
78
83
|
this.log("info", "un-hooking from MQTT client");
|
|
79
84
|
this.mqtt.off("message", this.messageHandler);
|
|
80
85
|
this.onRequest.clear();
|
|
81
86
|
this.onResponse.clear();
|
|
82
87
|
}
|
|
83
88
|
/* create a registration for subsequent destruction */
|
|
84
|
-
makeRegistration(spool, kind, name
|
|
89
|
+
makeRegistration(spool, kind, name) {
|
|
90
|
+
let destroyed = false;
|
|
85
91
|
return {
|
|
86
92
|
destroy: async () => {
|
|
87
|
-
if (
|
|
88
|
-
|
|
93
|
+
if (destroyed)
|
|
94
|
+
return;
|
|
95
|
+
destroyed = true;
|
|
89
96
|
await spool.unroll(false)?.catch((err) => {
|
|
90
97
|
const error = ensureError(err, `destroy: ${kind} "${name}" failed to cleanup`);
|
|
91
98
|
this.error(error);
|
|
@@ -160,6 +167,8 @@ export class BaseTrait extends TraceTrait {
|
|
|
160
167
|
}
|
|
161
168
|
/* handle incoming MQTT message */
|
|
162
169
|
_onMessage(topic, data, _packet) {
|
|
170
|
+
if (this.destroyed)
|
|
171
|
+
return;
|
|
163
172
|
/* parse MQTT topic */
|
|
164
173
|
const topicMatch = this.options.topicMatch(topic);
|
|
165
174
|
if (topicMatch === null)
|
|
@@ -187,13 +196,24 @@ export class BaseTrait extends TraceTrait {
|
|
|
187
196
|
return;
|
|
188
197
|
}
|
|
189
198
|
this.log("debug", `received from MQTT topic "${topic}"`, { message });
|
|
199
|
+
/* warn on receiver mismatch on direct topics */
|
|
200
|
+
if (topicMatch.peerId !== undefined
|
|
201
|
+
&& message.receiver !== undefined
|
|
202
|
+
&& message.receiver !== topicMatch.peerId)
|
|
203
|
+
this.log("warning", `receiver mismatch on direct topic "${topic}"` +
|
|
204
|
+
` (expected "${topicMatch.peerId}", got "${message.receiver}")`);
|
|
190
205
|
/* dispatch MQTT+ message */
|
|
191
206
|
if (this.msg.isRequest(message)) {
|
|
192
207
|
/* dispatch request message */
|
|
193
208
|
const handler = this.onRequest.get(`${message.type}:${message.name}`);
|
|
194
209
|
if (handler !== undefined) {
|
|
195
|
-
Promise.resolve().then(() =>
|
|
196
|
-
this.
|
|
210
|
+
Promise.resolve().then(() => {
|
|
211
|
+
if (this.destroyed)
|
|
212
|
+
return;
|
|
213
|
+
return handler(message, topicMatch.name);
|
|
214
|
+
}).catch((err) => {
|
|
215
|
+
this.error(ensureError(err, `dispatching request message from MQTT topic "${topic}" ` +
|
|
216
|
+
`(type: ${message.type}, id: ${message.id}, name: ${message.name}) failed`));
|
|
197
217
|
});
|
|
198
218
|
}
|
|
199
219
|
}
|
|
@@ -201,8 +221,13 @@ export class BaseTrait extends TraceTrait {
|
|
|
201
221
|
/* dispatch response message */
|
|
202
222
|
const handler = this.onResponse.get(`${message.type}:${message.id}`);
|
|
203
223
|
if (handler !== undefined) {
|
|
204
|
-
Promise.resolve().then(() =>
|
|
205
|
-
this.
|
|
224
|
+
Promise.resolve().then(() => {
|
|
225
|
+
if (this.destroyed)
|
|
226
|
+
return;
|
|
227
|
+
return handler(message, topicMatch.name);
|
|
228
|
+
}).catch((err) => {
|
|
229
|
+
this.error(ensureError(err, `dispatching response message from MQTT topic "${topic}" ` +
|
|
230
|
+
`(type: ${message.type}, id: ${message.id}, name: ${message.name}) failed`));
|
|
206
231
|
});
|
|
207
232
|
}
|
|
208
233
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mqtt-plus-base.js","sourceRoot":"","sources":["../src/mqtt-plus-base.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;EAsBE;AAaF,OAAO,EAAE,UAAU,EAAE,MAAwB,mBAAmB,CAAA;AAChE,OAAO,EAAS,WAAW,EAAE,MAAgB,mBAAmB,CAAA;AAChE,OAAO,EAAE,KAAK,EAAE,MAA6B,kBAAkB,CAAA;AAE/D,mDAAmD;AACnD,MAAM,OAAO,SAA2C,SAAQ,UAAa;
|
|
1
|
+
{"version":3,"file":"mqtt-plus-base.js","sourceRoot":"","sources":["../src/mqtt-plus-base.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;EAsBE;AAaF,OAAO,EAAE,UAAU,EAAE,MAAwB,mBAAmB,CAAA;AAChE,OAAO,EAAS,WAAW,EAAE,MAAgB,mBAAmB,CAAA;AAChE,OAAO,EAAE,KAAK,EAAE,MAA6B,kBAAkB,CAAA;AAE/D,mDAAmD;AACnD,MAAM,OAAO,SAA2C,SAAQ,UAAa;IAWzE,2BAA2B;IAC3B,YACI,IAAuB,EACvB,UAA+B,EAAE;QAEjC,KAAK,CAAC,OAAO,CAAC,CAAA;QAZlB,uBAAuB;QACb,cAAS,GAAG,KAAK,CAAA;QAE3B,2CAA2C;QACjC,cAAS,GAAI,IAAI,GAAG,E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AG,CAAC,GAAG,OAAO,CAAC,IAAI,IAAI,OAAO,CAAC,EAAE,EAAE,CAAC,CAAA;YACpE,IAAI,OAAO,KAAK,SAAS,EAAE,CAAC;gBACxB,OAAO,CAAC,OAAO,EAAE,CAAC,IAAI,CAAC,GAAG,EAAE;oBACxB,IAAI,IAAI,CAAC,SAAS;wBACd,OAAM;oBACV,OAAO,OAAO,CAAC,OAAO,EAAE,UAAU,CAAC,IAAI,CAAC,CAAA;gBAC5C,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,GAAY,EAAE,EAAE;oBACtB,IAAI,CAAC,KAAK,CAAC,WAAW,CAAC,GAAG,EACtB,iDAAiD,KAAK,IAAI;wBAC1D,UAAU,OAAO,CAAC,IAAI,SAAS,OAAO,CAAC,EAAE,WAAW,OAAO,CAAC,IAAI,UAAU,CAAC,CAAC,CAAA;gBACpF,CAAC,CAAC,CAAA;YACN,CAAC;QACL,CAAC;IACL,CAAC;CACJ"}
|
|
@@ -26,6 +26,7 @@ export class Spool {
|
|
|
26
26
|
constructor() {
|
|
27
27
|
/* internal state */
|
|
28
28
|
this.resources = [];
|
|
29
|
+
this.pending = null;
|
|
29
30
|
}
|
|
30
31
|
roll(...args) {
|
|
31
32
|
/* determine parameters */
|
|
@@ -49,47 +50,74 @@ export class Spool {
|
|
|
49
50
|
/* create new spool */
|
|
50
51
|
const spool = new Spool();
|
|
51
52
|
/* roll sub-spool onto spool */
|
|
52
|
-
this.roll(spool, () =>
|
|
53
|
+
this.roll(spool, (s) => s.unroll());
|
|
53
54
|
/* return new spool */
|
|
54
55
|
return spool;
|
|
55
56
|
}
|
|
56
57
|
/* unroll all cleanup procedures from spool */
|
|
57
58
|
unroll(suppress = true) {
|
|
59
|
+
/* guard against concurrent unroll: if an unroll is already
|
|
60
|
+
in progress, return the existing promise so all callers
|
|
61
|
+
wait for the same completion */
|
|
62
|
+
if (this.pending !== null) {
|
|
63
|
+
if (suppress)
|
|
64
|
+
return this.pending.catch(() => { });
|
|
65
|
+
return this.pending;
|
|
66
|
+
}
|
|
67
|
+
/* atomically take ownership of the currently rolled
|
|
68
|
+
resources so re-entrant unroll() calls from within
|
|
69
|
+
a synchronous cleanup observe an empty spool */
|
|
70
|
+
const resources = this.resources;
|
|
71
|
+
this.resources = [];
|
|
58
72
|
/* NOTICE: we operate synchronously until the first
|
|
59
73
|
cleanup procedure returns a Promise. Then we continue
|
|
60
74
|
asynchronously, regardless of whether the following
|
|
61
75
|
cleanup procedures return a Promise or not! */
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
result = cleanup(resource);
|
|
76
|
+
const errors = [];
|
|
77
|
+
let promise;
|
|
78
|
+
while (resources.length > 0) {
|
|
79
|
+
const entry = resources.pop();
|
|
80
|
+
const resource = entry.resource;
|
|
81
|
+
const cleanup = entry.cleanup;
|
|
82
|
+
if (promise) {
|
|
83
|
+
/* async continuation: isolate each cleanup so one rejection
|
|
84
|
+
does not prevent remaining cleanups from executing */
|
|
85
|
+
promise = promise.then(() => cleanup(resource))
|
|
86
|
+
.catch((err) => { errors.push(err); });
|
|
87
|
+
}
|
|
88
|
+
else {
|
|
89
|
+
/* sync start: wrap individually so a throw
|
|
90
|
+
does not exit the while loop */
|
|
91
|
+
try {
|
|
92
|
+
const result = cleanup(resource);
|
|
80
93
|
if (result instanceof Promise)
|
|
81
|
-
promise = result;
|
|
94
|
+
promise = result.catch((err) => { errors.push(err); });
|
|
95
|
+
}
|
|
96
|
+
catch (err) {
|
|
97
|
+
errors.push(err);
|
|
82
98
|
}
|
|
83
99
|
}
|
|
84
|
-
if (promise)
|
|
85
|
-
return suppress ? promise.catch(() => { }) : promise;
|
|
86
|
-
else
|
|
87
|
-
return;
|
|
88
100
|
}
|
|
89
|
-
|
|
101
|
+
if (promise) {
|
|
102
|
+
/* store the pending promise for concurrent-caller guard */
|
|
103
|
+
this.pending = promise.then(() => {
|
|
104
|
+
if (errors.length === 1)
|
|
105
|
+
throw errors[0];
|
|
106
|
+
else if (errors.length > 1)
|
|
107
|
+
throw new AggregateError(errors, "multiple cleanup failures");
|
|
108
|
+
}).finally(() => {
|
|
109
|
+
this.pending = null;
|
|
110
|
+
});
|
|
90
111
|
if (suppress)
|
|
91
|
-
return;
|
|
92
|
-
|
|
112
|
+
return this.pending.catch(() => { });
|
|
113
|
+
return this.pending;
|
|
114
|
+
}
|
|
115
|
+
else {
|
|
116
|
+
if (!suppress && errors.length === 1)
|
|
117
|
+
throw errors[0];
|
|
118
|
+
else if (!suppress && errors.length > 1)
|
|
119
|
+
throw new AggregateError(errors, "multiple cleanup failures");
|
|
120
|
+
return;
|
|
93
121
|
}
|
|
94
122
|
}
|
|
95
123
|
}
|
|
@@ -112,7 +140,7 @@ export function ensureError(error, prefix, debug = false) {
|
|
|
112
140
|
else
|
|
113
141
|
return new Error(msg);
|
|
114
142
|
}
|
|
115
|
-
function runFinally(isAsync, onfinally) {
|
|
143
|
+
function runFinally(isAsync, onfinally, description) {
|
|
116
144
|
if (!onfinally) {
|
|
117
145
|
if (isAsync)
|
|
118
146
|
return Promise.resolve();
|
|
@@ -125,14 +153,16 @@ function runFinally(isAsync, onfinally) {
|
|
|
125
153
|
}
|
|
126
154
|
catch (error) {
|
|
127
155
|
if (isAsync)
|
|
128
|
-
return Promise.reject(error);
|
|
156
|
+
return Promise.reject(ensureError(error, description));
|
|
129
157
|
else
|
|
130
|
-
throw error;
|
|
158
|
+
throw ensureError(error, description);
|
|
131
159
|
}
|
|
132
160
|
if (!isAsync && result instanceof Promise)
|
|
133
161
|
throw new Error("onfinally callback returned Promise in non-async context");
|
|
134
162
|
if (isAsync && !(result instanceof Promise))
|
|
135
163
|
result = Promise.resolve(result);
|
|
164
|
+
if (isAsync && result instanceof Promise)
|
|
165
|
+
return result.catch((error) => { throw ensureError(error, description); });
|
|
136
166
|
return result;
|
|
137
167
|
}
|
|
138
168
|
function runUnroll(isAsync, spool) {
|
|
@@ -213,21 +243,21 @@ export function run(...args) {
|
|
|
213
243
|
}
|
|
214
244
|
catch (arg) {
|
|
215
245
|
error = ensureError(arg, description);
|
|
216
|
-
runFinally(false, onfinally);
|
|
246
|
+
runFinally(false, onfinally, description);
|
|
217
247
|
runUnroll(false, spool);
|
|
218
248
|
throw error;
|
|
219
249
|
}
|
|
220
|
-
runFinally(false, onfinally);
|
|
250
|
+
runFinally(false, onfinally, description);
|
|
221
251
|
return result;
|
|
222
252
|
}
|
|
223
|
-
runFinally(false, onfinally);
|
|
253
|
+
runFinally(false, onfinally, description);
|
|
224
254
|
runUnroll(false, spool);
|
|
225
255
|
throw error;
|
|
226
256
|
}
|
|
227
257
|
if (result instanceof Promise) {
|
|
228
258
|
/* asynchronous case (result or error branch) */
|
|
229
259
|
return result.then(async (result) => {
|
|
230
|
-
await runFinally(true, onfinally);
|
|
260
|
+
await runFinally(true, onfinally, description);
|
|
231
261
|
if (spool && oncleanup)
|
|
232
262
|
spool.roll(result, oncleanup);
|
|
233
263
|
return result;
|
|
@@ -236,25 +266,25 @@ export function run(...args) {
|
|
|
236
266
|
let error = ensureError(arg, description);
|
|
237
267
|
if (oncatch) {
|
|
238
268
|
try {
|
|
239
|
-
const result = oncatch(error);
|
|
240
|
-
await runFinally(true, onfinally);
|
|
269
|
+
const result = await oncatch(error);
|
|
270
|
+
await runFinally(true, onfinally, description);
|
|
241
271
|
return result;
|
|
242
272
|
}
|
|
243
273
|
catch (arg) {
|
|
244
274
|
error = ensureError(arg, description);
|
|
245
|
-
await runFinally(true, onfinally);
|
|
275
|
+
await runFinally(true, onfinally, description);
|
|
246
276
|
await runUnroll(true, spool);
|
|
247
277
|
throw error;
|
|
248
278
|
}
|
|
249
279
|
}
|
|
250
|
-
await runFinally(true, onfinally);
|
|
280
|
+
await runFinally(true, onfinally, description);
|
|
251
281
|
await runUnroll(true, spool);
|
|
252
282
|
throw error;
|
|
253
283
|
});
|
|
254
284
|
}
|
|
255
285
|
else {
|
|
256
286
|
/* synchronous case (result branch) */
|
|
257
|
-
runFinally(false, onfinally);
|
|
287
|
+
runFinally(false, onfinally, description);
|
|
258
288
|
if (spool && oncleanup)
|
|
259
289
|
spool.roll(result, oncleanup);
|
|
260
290
|
return result;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mqtt-plus-error.js","sourceRoot":"","sources":["../src/mqtt-plus-error.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;EAsBE;AAYF,+BAA+B;AAC/B,MAAM,OAAO,KAAK;IAAlB;QACI,sBAAsB;QACd,cAAS,GAA6B,EAAE,CAAA;
|
|
1
|
+
{"version":3,"file":"mqtt-plus-error.js","sourceRoot":"","sources":["../src/mqtt-plus-error.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;EAsBE;AAYF,+BAA+B;AAC/B,MAAM,OAAO,KAAK;IAAlB;QACI,sBAAsB;QACd,cAAS,GAA6B,EAAE,CAAA;QACxC,YAAO,GAA2B,IAAI,CAAA;IAkGlD,CAAC;IA7FG,IAAI,CAAE,GAAG,IAAW;QAChB,4BAA4B;QAC5B,IAAI,QAAiB,CAAA;QACrB,IAAI,OAA+B,CAAA;QACnC,IAAS,IAAI,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YAAC,QAAQ,GAAG,SAAS,CAAC;YAAC,OAAO,GAAI,IAAI,CAAC,CAAC,CAAC,CAAA;QAAC,CAAC;aACnE,IAAI,IAAI,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YAAC,QAAQ,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC;YAAG,OAAO,GAAI,IAAI,CAAC,CAAC,CAAC,CAAA;QAAC,CAAC;;YAEpE,MAAM,IAAI,KAAK,CAAC,6BAA6B,CAAC,CAAA;QAElD,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BAC5B,MAAM,KAAK,CAAA;gBACf,CAAC;YACL,CAAC;YACD,MAAM,UAAU,CAAC,IAAI,EAAE,SAAS,EAAE,WAAW,CAAC,CAAA;YAC9C,MAAM,SAAS,CAAC,IAAI,EAAE,KAAK,CAAC,CAAA;YAC5B,MAAM,KAAK,CAAA;QACf,CAAC,CAAC,CAAA;IACN,CAAC;SACI,CAAC;QACF,wCAAwC;QACxC,UAAU,CAAC,KAAK,EAAE,SAAS,EAAE,WAAW,CAAC,CAAA;QACzC,IAAI,KAAK,IAAI,SAAS;YAClB,KAAK,CAAC,IAAI,CAAC,MAAM,EAAE,SAAkC,CAAC,CAAA;QAC1D,OAAO,MAAM,CAAA;IACjB,CAAC;AACL,CAAC"}
|
|
@@ -3,6 +3,8 @@ import type { APISchema, EventKeys, Registration } from "./mqtt-plus-api";
|
|
|
3
3
|
import type { WithInfo, InfoEvent } from "./mqtt-plus-info";
|
|
4
4
|
import { AuthTrait, type AuthOption } from "./mqtt-plus-auth";
|
|
5
5
|
export declare class EventTrait<T extends APISchema = APISchema> extends AuthTrait<T> {
|
|
6
|
+
private eventControllers;
|
|
7
|
+
destroy(): Promise<void>;
|
|
6
8
|
event<K extends EventKeys<T> & string>(name: K, callback: WithInfo<T[K], InfoEvent>): Promise<Registration>;
|
|
7
9
|
event<K extends EventKeys<T> & string>(config: {
|
|
8
10
|
name: K;
|
|
@@ -11,14 +13,14 @@ export declare class EventTrait<T extends APISchema = APISchema> extends AuthTra
|
|
|
11
13
|
share?: string;
|
|
12
14
|
auth?: AuthOption;
|
|
13
15
|
}): Promise<Registration>;
|
|
14
|
-
emit<K extends EventKeys<T> & string>(name: K, ...params: Parameters<T[K]>): void
|
|
16
|
+
emit<K extends EventKeys<T> & string>(name: K, ...params: Parameters<T[K]>): Promise<void>;
|
|
15
17
|
emit<K extends EventKeys<T> & string>(config: {
|
|
16
18
|
name: K;
|
|
17
19
|
params: Parameters<T[K]>;
|
|
18
20
|
receiver?: string;
|
|
19
21
|
options?: IClientPublishOptions;
|
|
20
22
|
meta?: Record<string, any>;
|
|
21
|
-
}): void
|
|
23
|
+
}): Promise<void>;
|
|
22
24
|
emit<K extends EventKeys<T> & string>(config: {
|
|
23
25
|
name: K;
|
|
24
26
|
params: Parameters<T[K]>;
|
|
@@ -23,10 +23,25 @@
|
|
|
23
23
|
*/
|
|
24
24
|
import { nanoid } from "nanoid";
|
|
25
25
|
import { AuthTrait } from "./mqtt-plus-auth";
|
|
26
|
-
import { Spool, ensureError } from "./mqtt-plus-error";
|
|
26
|
+
import { Spool, ensureError, run } from "./mqtt-plus-error";
|
|
27
27
|
/* Event Emission Trait */
|
|
28
28
|
export class EventTrait extends AuthTrait {
|
|
29
|
+
constructor() {
|
|
30
|
+
super(...arguments);
|
|
31
|
+
/* event state */
|
|
32
|
+
this.eventControllers = new Map();
|
|
33
|
+
}
|
|
34
|
+
/* destroy trait */
|
|
35
|
+
async destroy() {
|
|
36
|
+
for (const controller of this.eventControllers.values())
|
|
37
|
+
controller.abort(new Error("event destroyed"));
|
|
38
|
+
this.eventControllers.clear();
|
|
39
|
+
await super.destroy();
|
|
40
|
+
}
|
|
29
41
|
async event(nameOrConfig, ...args) {
|
|
42
|
+
/* sanity check lifecycle */
|
|
43
|
+
if (this.destroyed)
|
|
44
|
+
throw new Error("event: instance already destroyed");
|
|
30
45
|
/* determine actual parameters */
|
|
31
46
|
let name;
|
|
32
47
|
let callback;
|
|
@@ -54,6 +69,15 @@ export class EventTrait extends AuthTrait {
|
|
|
54
69
|
/* sanity check situation */
|
|
55
70
|
if (this.onRequest.has(`event-emission:${name}`))
|
|
56
71
|
throw new Error(`event: event "${name}" already registered`);
|
|
72
|
+
/* create per-event controller tracking */
|
|
73
|
+
const requestIds = new Set();
|
|
74
|
+
spool.roll(() => {
|
|
75
|
+
for (const requestId of requestIds) {
|
|
76
|
+
this.eventControllers.get(requestId)?.abort(new Error(`event "${name}" destroyed`));
|
|
77
|
+
this.eventControllers.delete(requestId);
|
|
78
|
+
}
|
|
79
|
+
requestIds.clear();
|
|
80
|
+
});
|
|
57
81
|
/* generate the corresponding MQTT topics for broadcast and direct use */
|
|
58
82
|
const topicS = share !== "" ? `$share/${share}/${name}` : name;
|
|
59
83
|
const topicB = this.options.topicMake(topicS, "event-emission");
|
|
@@ -64,39 +88,65 @@ export class EventTrait extends AuthTrait {
|
|
|
64
88
|
if (request.receiver && request.receiver !== this.options.id)
|
|
65
89
|
return;
|
|
66
90
|
/* determine event information */
|
|
91
|
+
const requestId = request.id;
|
|
67
92
|
const senderId = request.sender;
|
|
68
|
-
if (senderId === undefined || senderId === "")
|
|
69
|
-
|
|
93
|
+
if (senderId === undefined || senderId === "") {
|
|
94
|
+
this.error(new Error("invalid request: missing sender"));
|
|
95
|
+
return;
|
|
96
|
+
}
|
|
97
|
+
/* sanity check topic/payload name */
|
|
98
|
+
if (topicName !== request.name) {
|
|
99
|
+
this.log("warning", `event name mismatch -- dropped request for "${name}"` +
|
|
100
|
+
` (topic: "${topicName}", payload: "${request.name}")`, { requestId });
|
|
101
|
+
return;
|
|
102
|
+
}
|
|
70
103
|
const params = request.params ?? [];
|
|
104
|
+
/* sanity check request id */
|
|
105
|
+
if (this.eventControllers.has(requestId)) {
|
|
106
|
+
this.log("warning", `duplicate event request id -- dropped request for event "${name}"`, { requestId });
|
|
107
|
+
return;
|
|
108
|
+
}
|
|
109
|
+
/* define abort controller and signal */
|
|
110
|
+
const abortController = new AbortController();
|
|
111
|
+
const abortSignal = abortController.signal;
|
|
112
|
+
requestIds.add(requestId);
|
|
113
|
+
this.eventControllers.set(requestId, abortController);
|
|
71
114
|
/* create information object */
|
|
72
|
-
const info = {
|
|
115
|
+
const info = {
|
|
116
|
+
sender: senderId,
|
|
117
|
+
signal: abortSignal
|
|
118
|
+
};
|
|
73
119
|
if (request.receiver)
|
|
74
120
|
info.receiver = request.receiver;
|
|
75
121
|
if (request.meta)
|
|
76
122
|
info.meta = request.meta;
|
|
77
123
|
/* asynchronously execute handler */
|
|
78
124
|
try {
|
|
79
|
-
if (topicName !== request.name)
|
|
80
|
-
throw new Error(`event name mismatch (topic: "${topicName}", payload: "${request.name}")`);
|
|
81
125
|
if (auth)
|
|
82
|
-
info.authenticated = await this.authenticated(senderId, request.auth, auth);
|
|
83
|
-
if (info.authenticated !== undefined && !info.authenticated)
|
|
84
|
-
throw new Error(`event "${name}" failed authentication`);
|
|
126
|
+
info.authenticated = await this.authenticated(senderId, request.auth, auth, `event "${name}"`);
|
|
85
127
|
await callback(...params, info);
|
|
86
128
|
}
|
|
87
129
|
catch (result) {
|
|
88
130
|
const error = ensureError(result);
|
|
89
131
|
this.error(error, `handler for event "${name}" failed`);
|
|
90
132
|
}
|
|
133
|
+
finally {
|
|
134
|
+
abortController.abort();
|
|
135
|
+
requestIds.delete(requestId);
|
|
136
|
+
this.eventControllers.delete(requestId);
|
|
137
|
+
}
|
|
91
138
|
});
|
|
92
139
|
spool.roll(() => { this.onRequest.delete(`event-emission:${name}`); });
|
|
93
140
|
/* subscribe to MQTT topics */
|
|
94
141
|
await this.subscribeTopicAndSpool(spool, topicB, options);
|
|
95
142
|
await this.subscribeTopicAndSpool(spool, topicD, options);
|
|
96
143
|
/* provide a registration for subsequent destruction */
|
|
97
|
-
return this.makeRegistration(spool, "event", name
|
|
144
|
+
return this.makeRegistration(spool, "event", name);
|
|
98
145
|
}
|
|
99
146
|
emit(nameOrConfig, ...args) {
|
|
147
|
+
/* sanity check lifecycle */
|
|
148
|
+
if (this.destroyed)
|
|
149
|
+
throw new Error("emit: instance already destroyed");
|
|
100
150
|
/* determine actual parameters */
|
|
101
151
|
let name;
|
|
102
152
|
let params;
|
|
@@ -133,9 +183,7 @@ export class EventTrait extends AuthTrait {
|
|
|
133
183
|
return { topic, payload: message, options: { qos: 2, ...options } };
|
|
134
184
|
else
|
|
135
185
|
/* publish message to MQTT topic */
|
|
136
|
-
this.publishToTopic(topic, message, { qos: 2, ...options })
|
|
137
|
-
this.error(err, `emitting event "${name}" failed`);
|
|
138
|
-
});
|
|
186
|
+
return run(`publish event as MQTT message to topic "${topic}"`, () => this.publishToTopic(topic, message, { qos: 2, ...options }));
|
|
139
187
|
}
|
|
140
188
|
}
|
|
141
189
|
//# sourceMappingURL=mqtt-plus-event.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mqtt-plus-event.js","sourceRoot":"","sources":["../src/mqtt-plus-event.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;EAsBE;AAKF,OAAO,EAAE,MAAM,EAAE,MAA0B,QAAQ,CAAA;AAOnD,OAAO,EAAE,SAAS,EAAmB,MAAM,kBAAkB,CAAA;AAC7D,OAAO,EAAE,KAAK,EAAE,WAAW,EAAE,
|
|
1
|
+
{"version":3,"file":"mqtt-plus-event.js","sourceRoot":"","sources":["../src/mqtt-plus-event.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;EAsBE;AAKF,OAAO,EAAE,MAAM,EAAE,MAA0B,QAAQ,CAAA;AAOnD,OAAO,EAAE,SAAS,EAAmB,MAAM,kBAAkB,CAAA;AAC7D,OAAO,EAAE,KAAK,EAAE,WAAW,EAAE,GAAG,EAAE,MAAS,mBAAmB,CAAA;AAE9D,4BAA4B;AAC5B,MAAM,OAAO,UAA4C,SAAQ,SAAY;IAA7E;;QACI,mBAAmB;QACX,qBAAgB,GAAG,IAAI,GAAG,EAA2B,CAAA;IA6OjE,CAAC;IA3OG,qBAAqB;IACZ,KAAK,CAAC,OAAO;QAClB,KAAK,MAAM,UAAU,IAAI,IAAI,CAAC,gBAAgB,CAAC,MAAM,EAAE;YACnD,UAAU,CAAC,KAAK,CAAC,IAAI,KAAK,CAAC,iBAAiB,CAAC,CAAC,CAAA;QAClD,IAAI,CAAC,gBAAgB,CAAC,KAAK,EAAE,CAAA;QAC7B,MAAM,KAAK,CAAC,OAAO,EAAE,CAAA;IACzB,CAAC;IAgBD,KAAK,CAAC,KAAK,CACP,YAMC,EACD,GAAG,IAAi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IAAI,CAAC,cAAc,CAAC,KAAK,EAAE,OAAO,EAAE,EAAE,GAAG,EAAE,CAAC,EAAE,GAAG,OAAO,EAAE,CAAC,CAAC,CAAA;IACxE,CAAC;CACJ"}
|
|
@@ -6,8 +6,10 @@ export interface InfoBase {
|
|
|
6
6
|
meta?: Record<string, any>;
|
|
7
7
|
}
|
|
8
8
|
export interface InfoEvent extends InfoBase {
|
|
9
|
+
signal: AbortSignal;
|
|
9
10
|
}
|
|
10
11
|
export interface InfoService extends InfoBase {
|
|
12
|
+
signal: AbortSignal;
|
|
11
13
|
}
|
|
12
14
|
export interface InfoSource extends InfoBase {
|
|
13
15
|
signal: AbortSignal;
|
|
@@ -21,19 +21,22 @@ export declare class ServiceCallRequest extends Base {
|
|
|
21
21
|
params?: any[] | undefined;
|
|
22
22
|
auth?: string[] | undefined;
|
|
23
23
|
meta?: Record<string, any> | undefined;
|
|
24
|
-
|
|
24
|
+
qos?: 0 | 1 | 2 | undefined;
|
|
25
|
+
constructor(id: string, name: string, params?: any[] | undefined, sender?: string, receiver?: string, auth?: string[] | undefined, meta?: Record<string, any> | undefined, qos?: 0 | 1 | 2 | undefined);
|
|
25
26
|
}
|
|
26
27
|
export declare class ServiceCallResponse extends Base {
|
|
28
|
+
name: string;
|
|
27
29
|
result?: any | undefined;
|
|
28
30
|
error?: string | undefined;
|
|
29
|
-
constructor(id: string, result?: any | undefined, error?: string | undefined, sender?: string, receiver?: string);
|
|
31
|
+
constructor(id: string, name: string, result?: any | undefined, error?: string | undefined, sender?: string, receiver?: string);
|
|
30
32
|
}
|
|
31
33
|
export declare class SinkPushRequest extends Base {
|
|
32
34
|
name: string;
|
|
33
35
|
params?: any[] | undefined;
|
|
34
36
|
auth?: string[] | undefined;
|
|
35
37
|
meta?: Record<string, any> | undefined;
|
|
36
|
-
|
|
38
|
+
qos?: 0 | 1 | 2 | undefined;
|
|
39
|
+
constructor(id: string, name: string, params?: any[] | undefined, sender?: string, receiver?: string, auth?: string[] | undefined, meta?: Record<string, any> | undefined, qos?: 0 | 1 | 2 | undefined);
|
|
37
40
|
}
|
|
38
41
|
export declare class SinkPushResponse extends Base {
|
|
39
42
|
name: string;
|
|
@@ -59,7 +62,8 @@ export declare class SourceFetchRequest extends Base {
|
|
|
59
62
|
auth?: string[] | undefined;
|
|
60
63
|
meta?: Record<string, any> | undefined;
|
|
61
64
|
credit?: number | undefined;
|
|
62
|
-
|
|
65
|
+
qos?: 0 | 1 | 2 | undefined;
|
|
66
|
+
constructor(id: string, name: string, params?: any[] | undefined, sender?: string, receiver?: string, auth?: string[] | undefined, meta?: Record<string, any> | undefined, credit?: number | undefined, qos?: 0 | 1 | 2 | undefined);
|
|
63
67
|
}
|
|
64
68
|
export declare class SourceFetchResponse extends Base {
|
|
65
69
|
name: string;
|
|
@@ -82,13 +86,13 @@ export declare class SourceFetchCredit extends Base {
|
|
|
82
86
|
export type Message = EventEmission | ServiceCallRequest | ServiceCallResponse | SinkPushRequest | SinkPushResponse | SinkPushChunk | SinkPushCredit | SourceFetchRequest | SourceFetchResponse | SourceFetchChunk | SourceFetchCredit;
|
|
83
87
|
declare class Msg {
|
|
84
88
|
makeEventEmission(id: string, name: string, params?: any[], sender?: string, receiver?: string, auth?: string[], meta?: Record<string, any>): EventEmission;
|
|
85
|
-
makeServiceCallRequest(id: string, name: string, params?: any[], sender?: string, receiver?: string, auth?: string[], meta?: Record<string, any
|
|
86
|
-
makeServiceCallResponse(id: string, result?: any, error?: string, sender?: string, receiver?: string): ServiceCallResponse;
|
|
87
|
-
makeSinkPushRequest(id: string, name: string, params?: any[], sender?: string, receiver?: string, auth?: string[], meta?: Record<string, any
|
|
89
|
+
makeServiceCallRequest(id: string, name: string, params?: any[], sender?: string, receiver?: string, auth?: string[], meta?: Record<string, any>, qos?: 0 | 1 | 2): ServiceCallRequest;
|
|
90
|
+
makeServiceCallResponse(id: string, name: string, result?: any, error?: string, sender?: string, receiver?: string): ServiceCallResponse;
|
|
91
|
+
makeSinkPushRequest(id: string, name: string, params?: any[], sender?: string, receiver?: string, auth?: string[], meta?: Record<string, any>, qos?: 0 | 1 | 2): SinkPushRequest;
|
|
88
92
|
makeSinkPushResponse(id: string, name: string, error?: string, sender?: string, receiver?: string, credit?: number): SinkPushResponse;
|
|
89
93
|
makeSinkPushChunk(id: string, name: string, chunk?: Uint8Array, error?: string, final?: boolean, sender?: string, receiver?: string): SinkPushChunk;
|
|
90
94
|
makeSinkPushCredit(id: string, name: string, credit: number, sender?: string, receiver?: string): SinkPushCredit;
|
|
91
|
-
makeSourceFetchRequest(id: string, name: string, params?: any[], sender?: string, receiver?: string, auth?: string[], meta?: Record<string, any>, credit?: number): SourceFetchRequest;
|
|
95
|
+
makeSourceFetchRequest(id: string, name: string, params?: any[], sender?: string, receiver?: string, auth?: string[], meta?: Record<string, any>, credit?: number, qos?: 0 | 1 | 2): SourceFetchRequest;
|
|
92
96
|
makeSourceFetchResponse(id: string, name: string, error?: string, sender?: string, receiver?: string, meta?: Record<string, any>): SourceFetchResponse;
|
|
93
97
|
makeSourceFetchChunk(id: string, name: string, chunk?: Uint8Array, error?: string, final?: boolean, sender?: string, receiver?: string): SourceFetchChunk;
|
|
94
98
|
makeSourceFetchCredit(id: string, name: string, credit: number, sender?: string, receiver?: string): SourceFetchCredit;
|