@openrobops/iso21423 0.0.0-stage → 0.1.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.
- package/README.md +358 -2
- package/dist/ccs-CU8XD5sl.d.cts +69 -0
- package/dist/ccs-CU8XD5sl.d.ts +69 -0
- package/dist/chunk-3JNSIJSX.js +31 -0
- package/dist/chunk-3JNSIJSX.js.map +1 -0
- package/dist/chunk-5ZIUSUHF.js +55 -0
- package/dist/chunk-5ZIUSUHF.js.map +1 -0
- package/dist/chunk-DMJ6T3RX.js +445 -0
- package/dist/chunk-DMJ6T3RX.js.map +1 -0
- package/dist/chunk-GPNR37CI.js +1915 -0
- package/dist/chunk-GPNR37CI.js.map +1 -0
- package/dist/chunk-JDO725KR.js +210 -0
- package/dist/chunk-JDO725KR.js.map +1 -0
- package/dist/chunk-JIYCTQXR.js +1 -0
- package/dist/chunk-JIYCTQXR.js.map +1 -0
- package/dist/chunk-JLUENXGS.js +48 -0
- package/dist/chunk-JLUENXGS.js.map +1 -0
- package/dist/chunk-JQAMNFAF.js +1 -0
- package/dist/chunk-JQAMNFAF.js.map +1 -0
- package/dist/chunk-LTPOAVGF.js +44 -0
- package/dist/chunk-LTPOAVGF.js.map +1 -0
- package/dist/chunk-ODBIFZN3.js +65 -0
- package/dist/chunk-ODBIFZN3.js.map +1 -0
- package/dist/chunk-OH2DOPKJ.js +107 -0
- package/dist/chunk-OH2DOPKJ.js.map +1 -0
- package/dist/chunk-QAA44UNO.js +1 -0
- package/dist/chunk-QAA44UNO.js.map +1 -0
- package/dist/chunk-RD7PYTIT.js +107 -0
- package/dist/chunk-RD7PYTIT.js.map +1 -0
- package/dist/chunk-UJC46NTA.js +13 -0
- package/dist/chunk-UJC46NTA.js.map +1 -0
- package/dist/chunk-UW6WTEPT.js +293 -0
- package/dist/chunk-UW6WTEPT.js.map +1 -0
- package/dist/chunk-W7DIDPTG.js +1 -0
- package/dist/chunk-W7DIDPTG.js.map +1 -0
- package/dist/core.cjs +2874 -0
- package/dist/core.cjs.map +1 -0
- package/dist/core.d.cts +996 -0
- package/dist/core.d.ts +996 -0
- package/dist/core.js +59 -0
- package/dist/core.js.map +1 -0
- package/dist/gateway.cjs +2937 -0
- package/dist/gateway.cjs.map +1 -0
- package/dist/gateway.d.cts +165 -0
- package/dist/gateway.d.ts +165 -0
- package/dist/gateway.js +21 -0
- package/dist/gateway.js.map +1 -0
- package/dist/geometry.cjs +98 -0
- package/dist/geometry.cjs.map +1 -0
- package/dist/geometry.d.cts +38 -0
- package/dist/geometry.d.ts +38 -0
- package/dist/geometry.js +14 -0
- package/dist/geometry.js.map +1 -0
- package/dist/identity-BGr2FJmC.d.cts +258 -0
- package/dist/identity-Bw8Dik5S.d.ts +258 -0
- package/dist/index.cjs +3327 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +118 -0
- package/dist/index.d.ts +118 -0
- package/dist/index.js +193 -0
- package/dist/index.js.map +1 -0
- package/dist/schema.cjs +375 -0
- package/dist/schema.cjs.map +1 -0
- package/dist/schema.d.cts +28 -0
- package/dist/schema.d.ts +28 -0
- package/dist/schema.js +14 -0
- package/dist/schema.js.map +1 -0
- package/dist/session-RV32MFpV.d.cts +139 -0
- package/dist/session-ueiESY7Y.d.ts +139 -0
- package/dist/session.cjs +855 -0
- package/dist/session.cjs.map +1 -0
- package/dist/session.d.cts +94 -0
- package/dist/session.d.ts +94 -0
- package/dist/session.js +20 -0
- package/dist/session.js.map +1 -0
- package/dist/testing.cjs +205 -0
- package/dist/testing.cjs.map +1 -0
- package/dist/testing.d.cts +94 -0
- package/dist/testing.d.ts +94 -0
- package/dist/testing.js +169 -0
- package/dist/testing.js.map +1 -0
- package/dist/topics-BiVeZyTW.d.cts +43 -0
- package/dist/topics-BiVeZyTW.d.ts +43 -0
- package/dist/topics.cjs +134 -0
- package/dist/topics.cjs.map +1 -0
- package/dist/topics.d.cts +41 -0
- package/dist/topics.d.ts +41 -0
- package/dist/topics.js +30 -0
- package/dist/topics.js.map +1 -0
- package/dist/transport-BT4AjTn9.d.cts +61 -0
- package/dist/transport-BT4AjTn9.d.ts +61 -0
- package/dist/types.cjs +186 -0
- package/dist/types.cjs.map +1 -0
- package/dist/types.d.cts +83 -0
- package/dist/types.d.ts +83 -0
- package/dist/types.js +50 -0
- package/dist/types.js.map +1 -0
- package/dist/validators-Be0ce1b8.d.cts +29 -0
- package/dist/validators-Be0ce1b8.d.ts +29 -0
- package/package.json +48 -4
|
@@ -0,0 +1,445 @@
|
|
|
1
|
+
import {
|
|
2
|
+
nowTimestamp
|
|
3
|
+
} from "./chunk-UJC46NTA.js";
|
|
4
|
+
import {
|
|
5
|
+
assertValid,
|
|
6
|
+
validateMessage
|
|
7
|
+
} from "./chunk-UW6WTEPT.js";
|
|
8
|
+
import {
|
|
9
|
+
RESOURCE_CONFIG
|
|
10
|
+
} from "./chunk-LTPOAVGF.js";
|
|
11
|
+
import {
|
|
12
|
+
disconnectionTopic,
|
|
13
|
+
parseTopic,
|
|
14
|
+
topicFilterMatches,
|
|
15
|
+
topicFor
|
|
16
|
+
} from "./chunk-5ZIUSUHF.js";
|
|
17
|
+
import {
|
|
18
|
+
LOST_CONNECTION_STATE,
|
|
19
|
+
ROOT_NAMESPACE
|
|
20
|
+
} from "./chunk-RD7PYTIT.js";
|
|
21
|
+
import {
|
|
22
|
+
AuthorizationDenied,
|
|
23
|
+
BrokerUnavailable,
|
|
24
|
+
Iso21423Error
|
|
25
|
+
} from "./chunk-JLUENXGS.js";
|
|
26
|
+
|
|
27
|
+
// src/session/rateGate.ts
|
|
28
|
+
var RateGate = class {
|
|
29
|
+
intervalMs;
|
|
30
|
+
lastEmit = -Infinity;
|
|
31
|
+
pending;
|
|
32
|
+
timer;
|
|
33
|
+
constructor(maxHz) {
|
|
34
|
+
if (!(maxHz > 0) || !Number.isFinite(maxHz)) {
|
|
35
|
+
throw new Iso21423Error(`RateGate requires a finite maxHz > 0, got ${maxHz}`);
|
|
36
|
+
}
|
|
37
|
+
this.intervalMs = 1e3 / maxHz;
|
|
38
|
+
}
|
|
39
|
+
/** Offers a value for emission; emits now if the interval has elapsed, else schedules a trailing emit and discards any previously-pending value. */
|
|
40
|
+
offer(value, emit) {
|
|
41
|
+
const now = Date.now();
|
|
42
|
+
if (now - this.lastEmit >= this.intervalMs) {
|
|
43
|
+
this.lastEmit = now;
|
|
44
|
+
emit(value);
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
this.pending = { value, emit };
|
|
48
|
+
if (this.timer === void 0) {
|
|
49
|
+
const wait = this.intervalMs - (now - this.lastEmit);
|
|
50
|
+
this.timer = setTimeout(() => {
|
|
51
|
+
this.timer = void 0;
|
|
52
|
+
const p = this.pending;
|
|
53
|
+
this.pending = void 0;
|
|
54
|
+
if (p) {
|
|
55
|
+
this.lastEmit = Date.now();
|
|
56
|
+
p.emit(p.value);
|
|
57
|
+
}
|
|
58
|
+
}, wait);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
/** Cancels any pending trailing emit. The pending value is dropped, not flushed. */
|
|
62
|
+
dispose() {
|
|
63
|
+
if (this.timer !== void 0) clearTimeout(this.timer);
|
|
64
|
+
this.timer = void 0;
|
|
65
|
+
this.pending = void 0;
|
|
66
|
+
}
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
// src/session/session.ts
|
|
70
|
+
var Iso21423Session = class _Iso21423Session {
|
|
71
|
+
constructor(transport, entity, validateOutbound, armWill) {
|
|
72
|
+
this.transport = transport;
|
|
73
|
+
this.entity = entity;
|
|
74
|
+
this.validateOutbound = validateOutbound;
|
|
75
|
+
this.armWill = armWill;
|
|
76
|
+
}
|
|
77
|
+
transport;
|
|
78
|
+
entity;
|
|
79
|
+
validateOutbound;
|
|
80
|
+
armWill;
|
|
81
|
+
retainedOwned = /* @__PURE__ */ new Map();
|
|
82
|
+
rateGates = /* @__PURE__ */ new Map();
|
|
83
|
+
topicSubs = [];
|
|
84
|
+
listeners = {
|
|
85
|
+
connection: [],
|
|
86
|
+
"validation-warning": [],
|
|
87
|
+
error: []
|
|
88
|
+
};
|
|
89
|
+
wasConnected = false;
|
|
90
|
+
state = "closed";
|
|
91
|
+
/**
|
|
92
|
+
* Connects the transport and, unless `armWill` is false, arms the B.4 Last Will and clears any
|
|
93
|
+
* stale retained LOST_CONNECTION left over from a prior ungraceful disconnect (spec §4).
|
|
94
|
+
*/
|
|
95
|
+
static async connect(opts) {
|
|
96
|
+
const armWill = opts.armWill ?? true;
|
|
97
|
+
const session = new _Iso21423Session(opts.transport, opts.entity, opts.validateOutbound ?? true, armWill);
|
|
98
|
+
opts.transport.onMessage((m) => session.dispatch(m.topic, m.payload));
|
|
99
|
+
opts.transport.onConnectionState((s) => session.handleConnectionState(s));
|
|
100
|
+
await opts.transport.connect({
|
|
101
|
+
clientId: `iso21423-${opts.entity.entityType}-${opts.entity.entityUuid}`,
|
|
102
|
+
cleanSession: false,
|
|
103
|
+
keepalive: 60,
|
|
104
|
+
username: opts.credentials?.username,
|
|
105
|
+
password: opts.credentials?.password,
|
|
106
|
+
will: armWill ? {
|
|
107
|
+
topic: disconnectionTopic(opts.entity),
|
|
108
|
+
payload: JSON.stringify({ states: [LOST_CONNECTION_STATE] }),
|
|
109
|
+
qos: 1,
|
|
110
|
+
retain: true
|
|
111
|
+
} : void 0
|
|
112
|
+
});
|
|
113
|
+
if (armWill) await session.clearRetained(disconnectionTopic(opts.entity));
|
|
114
|
+
return session;
|
|
115
|
+
}
|
|
116
|
+
/** Passthrough so `/core` never rebuilds topics itself (Task 3 implementer note). */
|
|
117
|
+
topicFor(ref, resource) {
|
|
118
|
+
return topicFor(ref, resource);
|
|
119
|
+
}
|
|
120
|
+
on(event, cb) {
|
|
121
|
+
this.listeners[event].push(cb);
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* Publishes a known resource (looked up in {@link RESOURCE_CONFIG} for its QoS/retain/rate).
|
|
125
|
+
* Retained resources are deduped on-change (a re-publish with identical body is a no-op) and
|
|
126
|
+
* rolled back from the dedup cache if the publish itself fails. Rate-limited (streaming)
|
|
127
|
+
* resources go through a per-topic {@link RateGate} and are fire-and-forget: publish failures
|
|
128
|
+
* there are reported via the `error` event, not thrown.
|
|
129
|
+
*/
|
|
130
|
+
async publishResource(ref, resource, kind, payload) {
|
|
131
|
+
const config = RESOURCE_CONFIG[resource];
|
|
132
|
+
if (!config) throw new Iso21423Error(`unknown resource "${resource}"`);
|
|
133
|
+
if (kind && this.validateOutbound) assertValid(kind, payload);
|
|
134
|
+
const topic = topicFor(ref, resource);
|
|
135
|
+
const body = JSON.stringify(payload);
|
|
136
|
+
if (config.retain) {
|
|
137
|
+
if (this.retainedOwned.get(topic)?.payload === body) return;
|
|
138
|
+
this.retainedOwned.set(topic, { payload: body, qos: config.qos });
|
|
139
|
+
try {
|
|
140
|
+
await this.transport.publish(topic, body, { qos: config.qos, retain: true });
|
|
141
|
+
} catch (err) {
|
|
142
|
+
this.retainedOwned.delete(topic);
|
|
143
|
+
throw err;
|
|
144
|
+
}
|
|
145
|
+
return;
|
|
146
|
+
}
|
|
147
|
+
if (config.maxHz !== void 0) {
|
|
148
|
+
let gate = this.rateGates.get(topic);
|
|
149
|
+
if (!gate) {
|
|
150
|
+
gate = new RateGate(config.maxHz);
|
|
151
|
+
this.rateGates.set(topic, gate);
|
|
152
|
+
}
|
|
153
|
+
gate.offer(body, (b) => {
|
|
154
|
+
this.transport.publish(topic, b, { qos: config.qos, retain: false }).catch((err) => this.emitError(err));
|
|
155
|
+
});
|
|
156
|
+
return;
|
|
157
|
+
}
|
|
158
|
+
await this.transport.publish(topic, body, { qos: config.qos, retain: false });
|
|
159
|
+
}
|
|
160
|
+
/** Last non-wildcard resource segment → Table B.1 QoS, defaulting to QoS 1 when unknown. */
|
|
161
|
+
qosForFilter(filter) {
|
|
162
|
+
const parsed = parseTopic(filter);
|
|
163
|
+
if (!parsed) return 1;
|
|
164
|
+
const key = parsed.isRequestStatus ? "requestStatus" : parsed.resource;
|
|
165
|
+
return RESOURCE_CONFIG[key]?.qos ?? 1;
|
|
166
|
+
}
|
|
167
|
+
/**
|
|
168
|
+
* Always issues a broker SUBSCRIBE (a real broker redelivers retained messages on every
|
|
169
|
+
* SUBSCRIBE, so a late second handler must see the current retained value); the broker-side
|
|
170
|
+
* unsubscribe still only fires once the last local listener on the filter leaves (ND-17).
|
|
171
|
+
*/
|
|
172
|
+
async subscribeTopic(topicFilter, kind, handler, opts = {}) {
|
|
173
|
+
const qos = opts.qos ?? this.qosForFilter(topicFilter);
|
|
174
|
+
const { granted } = await this.transport.subscribe(topicFilter, { qos });
|
|
175
|
+
if (!granted) {
|
|
176
|
+
throw new AuthorizationDenied(`subscription denied by broker: ${topicFilter}`, topicFilter);
|
|
177
|
+
}
|
|
178
|
+
const sub = { filter: topicFilter, kind, handler };
|
|
179
|
+
this.topicSubs.push(sub);
|
|
180
|
+
return {
|
|
181
|
+
unsubscribe: async () => {
|
|
182
|
+
this.topicSubs = this.topicSubs.filter((s) => s !== sub);
|
|
183
|
+
if (!this.topicSubs.some((s) => s.filter === topicFilter)) {
|
|
184
|
+
await this.transport.unsubscribe(topicFilter);
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
};
|
|
188
|
+
}
|
|
189
|
+
/** Publish to an exact topic (request / requestStatus topics are not plain resources). */
|
|
190
|
+
async publishTopic(topic, kind, payload, opts) {
|
|
191
|
+
if (kind && this.validateOutbound) assertValid(kind, payload);
|
|
192
|
+
await this.transport.publish(topic, JSON.stringify(payload), opts);
|
|
193
|
+
}
|
|
194
|
+
get connectionState() {
|
|
195
|
+
return this.state;
|
|
196
|
+
}
|
|
197
|
+
/**
|
|
198
|
+
* Subscribe to a resource topic with optional validation.
|
|
199
|
+
* When kind is null, handler receives raw payload text without parsing or validation.
|
|
200
|
+
*/
|
|
201
|
+
async subscribeResource(filter, resource, kind, handler) {
|
|
202
|
+
const config = RESOURCE_CONFIG[resource];
|
|
203
|
+
if (!config) throw new Iso21423Error(`unknown resource "${resource}"`);
|
|
204
|
+
const topicFilter = `${ROOT_NAMESPACE}/${filter.entityType ?? "+"}/${filter.entityUuid ?? "+"}/${resource}`;
|
|
205
|
+
const sub = await this.subscribeTopic(topicFilter, kind, handler, { qos: config.qos });
|
|
206
|
+
return { unsubscribe: sub.unsubscribe, [Symbol.asyncDispose]: sub.unsubscribe };
|
|
207
|
+
}
|
|
208
|
+
/** For subscribers that opt out of schema routing (kind: null) but still want to surface a
|
|
209
|
+
* malformed payload as the usual 'validation-warning' event (D-13's RequestServer). */
|
|
210
|
+
reportValidationWarning(w) {
|
|
211
|
+
this.emitWarning(w);
|
|
212
|
+
}
|
|
213
|
+
async publishRaw(topic, payload, opts) {
|
|
214
|
+
await this.transport.publish(topic, payload, opts);
|
|
215
|
+
}
|
|
216
|
+
/** Clears a retained topic by publishing an empty retained payload, and drops it from the owned-retained dedup cache. */
|
|
217
|
+
async clearRetained(topic) {
|
|
218
|
+
this.retainedOwned.delete(topic);
|
|
219
|
+
await this.transport.publish(topic, "", { qos: 1, retain: true });
|
|
220
|
+
}
|
|
221
|
+
/** Optionally publishes a final status, disposes all rate gates, then ends the transport. */
|
|
222
|
+
async close(finalStates) {
|
|
223
|
+
if (finalStates) {
|
|
224
|
+
await this.publishResource(this.entity, "status", "entityStatus", {
|
|
225
|
+
entityId: this.entity.entityUuid,
|
|
226
|
+
timestamp: nowTimestamp(),
|
|
227
|
+
states: finalStates
|
|
228
|
+
});
|
|
229
|
+
}
|
|
230
|
+
for (const gate of this.rateGates.values()) gate.dispose();
|
|
231
|
+
await this.transport.end();
|
|
232
|
+
}
|
|
233
|
+
/**
|
|
234
|
+
* Routes an inbound message to every registered {@link TopicSub} whose filter matches the
|
|
235
|
+
* topic. `kind: null` subscribers get the raw text with no parsing; typed subscribers get an
|
|
236
|
+
* empty payload treated as a retained-clear (skipped silently) and malformed/non-conformant
|
|
237
|
+
* payloads reported via `emitWarning` rather than delivered to the handler.
|
|
238
|
+
*/
|
|
239
|
+
dispatch(topic, payload) {
|
|
240
|
+
const parsed = parseTopic(topic);
|
|
241
|
+
if (!parsed) return;
|
|
242
|
+
const text = payload.toString();
|
|
243
|
+
const meta = {
|
|
244
|
+
topic,
|
|
245
|
+
entityType: parsed.entityType,
|
|
246
|
+
entityUuid: parsed.entityUuid,
|
|
247
|
+
resource: parsed.resource,
|
|
248
|
+
requestUuid: parsed.requestUuid,
|
|
249
|
+
isRequestStatus: parsed.isRequestStatus
|
|
250
|
+
};
|
|
251
|
+
for (const sub of this.topicSubs) {
|
|
252
|
+
if (!topicFilterMatches(sub.filter, topic)) continue;
|
|
253
|
+
if (!sub.kind) {
|
|
254
|
+
sub.handler(text, meta);
|
|
255
|
+
continue;
|
|
256
|
+
}
|
|
257
|
+
if (text === "") continue;
|
|
258
|
+
let value;
|
|
259
|
+
try {
|
|
260
|
+
value = JSON.parse(text);
|
|
261
|
+
} catch {
|
|
262
|
+
this.emitWarning({ topic, payload: text, errors: ["invalid JSON"] });
|
|
263
|
+
continue;
|
|
264
|
+
}
|
|
265
|
+
const result = validateMessage(sub.kind, value);
|
|
266
|
+
if (!result.ok) {
|
|
267
|
+
this.emitWarning({ topic, payload: text, errors: result.errors ?? [] });
|
|
268
|
+
continue;
|
|
269
|
+
}
|
|
270
|
+
sub.handler(result.value, meta);
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
handleConnectionState(s) {
|
|
274
|
+
this.state = s;
|
|
275
|
+
for (const cb of this.listeners.connection) cb(s);
|
|
276
|
+
if (s === "connected" && this.wasConnected) {
|
|
277
|
+
for (const [topic, { payload, qos }] of this.retainedOwned) {
|
|
278
|
+
this.transport.publish(topic, payload, { qos, retain: true }).catch((err) => this.emitError(err));
|
|
279
|
+
}
|
|
280
|
+
if (this.armWill) {
|
|
281
|
+
this.clearRetained(disconnectionTopic(this.entity)).catch((err) => this.emitError(err));
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
if (s === "connected") this.wasConnected = true;
|
|
285
|
+
}
|
|
286
|
+
emitWarning(w) {
|
|
287
|
+
for (const cb of this.listeners["validation-warning"]) cb(w);
|
|
288
|
+
}
|
|
289
|
+
emitError(err) {
|
|
290
|
+
const errorListeners = this.listeners.error;
|
|
291
|
+
if (errorListeners.length > 0) {
|
|
292
|
+
for (const cb of errorListeners) cb(err);
|
|
293
|
+
} else {
|
|
294
|
+
console.error("[Iso21423Session] async publish failed:", err);
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
};
|
|
298
|
+
|
|
299
|
+
// src/session/mqttTransport.ts
|
|
300
|
+
var MqttAdapter = class {
|
|
301
|
+
constructor(acquire, checkWill, ownsClient) {
|
|
302
|
+
this.acquire = acquire;
|
|
303
|
+
this.checkWill = checkWill;
|
|
304
|
+
this.ownsClient = ownsClient;
|
|
305
|
+
}
|
|
306
|
+
acquire;
|
|
307
|
+
checkWill;
|
|
308
|
+
ownsClient;
|
|
309
|
+
client;
|
|
310
|
+
ended = false;
|
|
311
|
+
wired = false;
|
|
312
|
+
messageCbs = [];
|
|
313
|
+
stateCbs = [];
|
|
314
|
+
/**
|
|
315
|
+
* Acquires the underlying mqtt client (via the constructor-supplied `acquire`) and wires
|
|
316
|
+
* message/connection-state listeners exactly once per adapter instance, so repeated `connect()`
|
|
317
|
+
* calls (e.g. reconnect flows) don't accumulate duplicate listeners. For a caller-constructed
|
|
318
|
+
* client whose will doesn't match `opts.will`, throws (P-4) rather than silently diverging.
|
|
319
|
+
*/
|
|
320
|
+
async connect(opts) {
|
|
321
|
+
const client = await this.acquire(opts);
|
|
322
|
+
if (this.checkWill && opts.will && client.options?.will?.topic !== opts.will.topic) {
|
|
323
|
+
throw new Iso21423Error(
|
|
324
|
+
`caller-constructed mqtt client must be created with will { topic: "${opts.will.topic}", payload: '${opts.will.payload}', qos: ${opts.will.qos}, retain: ${opts.will.retain} } (P-4)`
|
|
325
|
+
);
|
|
326
|
+
}
|
|
327
|
+
if (!this.wired) {
|
|
328
|
+
this.wired = true;
|
|
329
|
+
client.on("message", ((topic, payload, packet) => {
|
|
330
|
+
const msg = {
|
|
331
|
+
topic,
|
|
332
|
+
payload,
|
|
333
|
+
qos: packet?.qos ?? 0,
|
|
334
|
+
retain: packet?.retain ?? false
|
|
335
|
+
};
|
|
336
|
+
for (const cb of this.messageCbs) cb(msg);
|
|
337
|
+
}));
|
|
338
|
+
client.on("reconnect", (() => this.emitState("reconnecting")));
|
|
339
|
+
client.on("offline", (() => this.emitState("offline")));
|
|
340
|
+
client.on("close", (() => this.emitState("closed")));
|
|
341
|
+
client.on("connect", (() => this.emitState("connected")));
|
|
342
|
+
}
|
|
343
|
+
if (client.connected) {
|
|
344
|
+
this.client = client;
|
|
345
|
+
this.emitState("connected");
|
|
346
|
+
return;
|
|
347
|
+
}
|
|
348
|
+
let settled = false;
|
|
349
|
+
const resolveReject = { resolve: null, reject: null };
|
|
350
|
+
const onConnect = (() => {
|
|
351
|
+
if (settled) return;
|
|
352
|
+
settled = true;
|
|
353
|
+
this.client = client;
|
|
354
|
+
resolveReject.resolve();
|
|
355
|
+
});
|
|
356
|
+
const onError = ((err) => {
|
|
357
|
+
if (settled) return;
|
|
358
|
+
settled = true;
|
|
359
|
+
if (this.ownsClient) {
|
|
360
|
+
client.endAsync(true).catch(() => {
|
|
361
|
+
});
|
|
362
|
+
}
|
|
363
|
+
resolveReject.reject(new BrokerUnavailable(`mqtt connect failed: ${err.message}`));
|
|
364
|
+
});
|
|
365
|
+
try {
|
|
366
|
+
await new Promise((resolve, reject) => {
|
|
367
|
+
resolveReject.resolve = resolve;
|
|
368
|
+
resolveReject.reject = reject;
|
|
369
|
+
client.on("connect", onConnect);
|
|
370
|
+
client.on("error", onError);
|
|
371
|
+
});
|
|
372
|
+
} finally {
|
|
373
|
+
try {
|
|
374
|
+
const clientWithRemoval = client;
|
|
375
|
+
(clientWithRemoval.off ?? clientWithRemoval.removeListener)?.("connect", onConnect);
|
|
376
|
+
(clientWithRemoval.off ?? clientWithRemoval.removeListener)?.("error", onError);
|
|
377
|
+
} catch {
|
|
378
|
+
}
|
|
379
|
+
}
|
|
380
|
+
}
|
|
381
|
+
async publish(topic, payload, opts) {
|
|
382
|
+
await this.live().publishAsync(topic, payload, opts);
|
|
383
|
+
}
|
|
384
|
+
/** Subscribes and reports whether the broker granted it — false if any SUBACK return code was a refusal (>= 0x80, ND-15) or no grants came back. */
|
|
385
|
+
async subscribe(filter, opts) {
|
|
386
|
+
const grants = await this.live().subscribeAsync(filter, opts);
|
|
387
|
+
const granted = grants.length > 0 && grants.every((g) => g.qos < 128);
|
|
388
|
+
return { granted };
|
|
389
|
+
}
|
|
390
|
+
async unsubscribe(filter) {
|
|
391
|
+
await this.live().unsubscribeAsync(filter);
|
|
392
|
+
}
|
|
393
|
+
onMessage(cb) {
|
|
394
|
+
this.messageCbs.push(cb);
|
|
395
|
+
}
|
|
396
|
+
onConnectionState(cb) {
|
|
397
|
+
this.stateCbs.push(cb);
|
|
398
|
+
}
|
|
399
|
+
async end() {
|
|
400
|
+
this.ended = true;
|
|
401
|
+
if (this.client) await this.client.endAsync();
|
|
402
|
+
this.emitState("closed");
|
|
403
|
+
}
|
|
404
|
+
/** Returns the connected client or throws {@link BrokerUnavailable} if `end()` was called or `connect()` hasn't completed. */
|
|
405
|
+
live() {
|
|
406
|
+
if (this.ended || !this.client) throw new BrokerUnavailable("mqtt transport is not connected");
|
|
407
|
+
return this.client;
|
|
408
|
+
}
|
|
409
|
+
emitState(s) {
|
|
410
|
+
for (const cb of this.stateCbs) cb(s);
|
|
411
|
+
}
|
|
412
|
+
};
|
|
413
|
+
function wrapMqttClient(client) {
|
|
414
|
+
return new MqttAdapter(async () => client, true, false);
|
|
415
|
+
}
|
|
416
|
+
function createMqttTransport(url, opts = {}) {
|
|
417
|
+
return new MqttAdapter(async (connectOpts) => {
|
|
418
|
+
let mod;
|
|
419
|
+
try {
|
|
420
|
+
mod = await import("mqtt");
|
|
421
|
+
} catch (err) {
|
|
422
|
+
throw new BrokerUnavailable(
|
|
423
|
+
`the "mqtt" peer dependency is not installed: ${err.message}`
|
|
424
|
+
);
|
|
425
|
+
}
|
|
426
|
+
return mod.connect(url, {
|
|
427
|
+
...opts.tls,
|
|
428
|
+
clientId: connectOpts.clientId,
|
|
429
|
+
clean: connectOpts.cleanSession,
|
|
430
|
+
keepalive: connectOpts.keepalive,
|
|
431
|
+
username: connectOpts.username ?? opts.username,
|
|
432
|
+
password: connectOpts.password ?? opts.password,
|
|
433
|
+
reconnectPeriod: opts.reconnectPeriod,
|
|
434
|
+
will: connectOpts.will
|
|
435
|
+
});
|
|
436
|
+
}, false, true);
|
|
437
|
+
}
|
|
438
|
+
|
|
439
|
+
export {
|
|
440
|
+
RateGate,
|
|
441
|
+
Iso21423Session,
|
|
442
|
+
wrapMqttClient,
|
|
443
|
+
createMqttTransport
|
|
444
|
+
};
|
|
445
|
+
//# sourceMappingURL=chunk-DMJ6T3RX.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/session/rateGate.ts","../src/session/session.ts","../src/session/mqttTransport.ts"],"sourcesContent":["/**\n * Copyright 2026 InOrbit, Inc.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { Iso21423Error } from '../errors.js';\n\n/**\n * Latest-wins rate limiter for streaming telemetry (Table B.1 bounds).\n * Emits immediately when the minimum interval has elapsed; otherwise keeps\n * only the newest value and flushes it when the interval expires.\n */\nexport class RateGate {\n private readonly intervalMs: number;\n private lastEmit = -Infinity;\n private pending?: { value: unknown; emit: (v: never) => void };\n private timer?: ReturnType<typeof setTimeout>;\n\n constructor(maxHz: number) {\n if (!(maxHz > 0) || !Number.isFinite(maxHz)) {\n throw new Iso21423Error(`RateGate requires a finite maxHz > 0, got ${maxHz}`);\n }\n this.intervalMs = 1000 / maxHz;\n }\n\n /** Offers a value for emission; emits now if the interval has elapsed, else schedules a trailing emit and discards any previously-pending value. */\n offer<T>(value: T, emit: (v: T) => void): void {\n const now = Date.now();\n if (now - this.lastEmit >= this.intervalMs) {\n this.lastEmit = now;\n emit(value);\n return;\n }\n this.pending = { value, emit: emit as (v: never) => void };\n if (this.timer === undefined) {\n const wait = this.intervalMs - (now - this.lastEmit);\n this.timer = setTimeout(() => {\n this.timer = undefined;\n const p = this.pending;\n this.pending = undefined;\n if (p) {\n this.lastEmit = Date.now();\n (p.emit as (v: unknown) => void)(p.value);\n }\n }, wait);\n }\n }\n\n /** Cancels any pending trailing emit. The pending value is dropped, not flushed. */\n dispose(): void {\n if (this.timer !== undefined) clearTimeout(this.timer);\n this.timer = undefined;\n this.pending = undefined;\n }\n}\n","/**\n * Copyright 2026 InOrbit, Inc.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport type { MqttTransport, ConnectionState } from './transport.js';\nimport { RateGate } from './rateGate.js';\nimport { RESOURCE_CONFIG } from '../topics/resources.js';\nimport {\n topicFor, disconnectionTopic, parseTopic, topicFilterMatches, type EntityRef,\n} from '../topics/topics.js';\nimport { ROOT_NAMESPACE, LOST_CONNECTION_STATE } from '../types/constants.js';\nimport { nowTimestamp } from '../types/common.js';\nimport { validateMessage, assertValid, type MessageKind } from '../schema/validators.js';\nimport { AuthorizationDenied, Iso21423Error } from '../errors.js';\n\n/** Options for {@link Iso21423Session.connect}. */\nexport interface SessionOptions {\n transport: MqttTransport;\n entity: EntityRef;\n credentials?: { username?: string; password?: string };\n validateOutbound?: boolean;\n /** Arm the B.4 Last Will at connect time. Default true; false for identity-less sessions (R1). */\n armWill?: boolean;\n}\n\n/** Returned by `subscribeTopic` / `subscribeResource`: stop receiving on that filter. */\nexport interface SessionSubscription {\n unsubscribe(): Promise<void>;\n}\n\n/** Topic-derived metadata handed to subscription handlers alongside the parsed payload. */\nexport interface TopicMeta {\n topic: string;\n entityType: string;\n entityUuid: string;\n resource: string;\n requestUuid?: string;\n isRequestStatus: boolean;\n}\n\n/** Emitted on the `'validation-warning'` event when an inbound message fails schema validation or JSON parsing. */\nexport interface ValidationWarningEvent {\n topic: string;\n payload: string;\n errors: unknown[];\n}\n\ntype SessionEvents = {\n connection: (s: ConnectionState) => void;\n 'validation-warning': (w: ValidationWarningEvent) => void;\n error: (err: unknown) => void;\n};\n\ninterface TopicSub {\n filter: string;\n kind: MessageKind | null;\n handler: (msg: unknown, meta: TopicMeta) => void;\n}\n\n/**\n * Owns one MQTT connection for a single entity: topic-scoped subscribe/publish, retained-resource\n * dedup and republish-on-reconnect, streaming-resource rate gating, LWT arming, and inbound schema\n * validation. This is the layer `/core` builds its request/response semantics on top of.\n */\nexport class Iso21423Session {\n private retainedOwned = new Map<string, { payload: string; qos: 0 | 1 | 2 }>();\n private rateGates = new Map<string, RateGate>();\n private topicSubs: TopicSub[] = [];\n private listeners: { [K in keyof SessionEvents]: Array<SessionEvents[K]> } = {\n connection: [], 'validation-warning': [], error: [],\n };\n private wasConnected = false;\n private state: ConnectionState = 'closed';\n\n private constructor(\n private readonly transport: MqttTransport,\n readonly entity: EntityRef,\n private readonly validateOutbound: boolean,\n private readonly armWill: boolean,\n ) {}\n\n /**\n * Connects the transport and, unless `armWill` is false, arms the B.4 Last Will and clears any\n * stale retained LOST_CONNECTION left over from a prior ungraceful disconnect (spec §4).\n */\n static async connect(opts: SessionOptions): Promise<Iso21423Session> {\n const armWill = opts.armWill ?? true;\n const session = new Iso21423Session(opts.transport, opts.entity, opts.validateOutbound ?? true, armWill);\n opts.transport.onMessage((m) => session.dispatch(m.topic, m.payload));\n opts.transport.onConnectionState((s) => session.handleConnectionState(s));\n await opts.transport.connect({\n clientId: `iso21423-${opts.entity.entityType}-${opts.entity.entityUuid}`,\n cleanSession: false,\n keepalive: 60,\n username: opts.credentials?.username,\n password: opts.credentials?.password,\n will: armWill ? {\n topic: disconnectionTopic(opts.entity),\n payload: JSON.stringify({ states: [LOST_CONNECTION_STATE] }),\n qos: 1,\n retain: true,\n } : undefined,\n });\n // Clear stale retained LOST_CONNECTION from a prior crash (spec §4). Skipped when no will was\n // armed: an identity-less session never owns a disconnection topic, so there is nothing stale\n // to clear (R1 — implementer's choice).\n if (armWill) await session.clearRetained(disconnectionTopic(opts.entity));\n return session;\n }\n\n /** Passthrough so `/core` never rebuilds topics itself (Task 3 implementer note). */\n topicFor(ref: EntityRef, resource: string): string {\n return topicFor(ref, resource);\n }\n\n on<K extends keyof SessionEvents>(event: K, cb: SessionEvents[K]): void {\n this.listeners[event].push(cb);\n }\n\n /**\n * Publishes a known resource (looked up in {@link RESOURCE_CONFIG} for its QoS/retain/rate).\n * Retained resources are deduped on-change (a re-publish with identical body is a no-op) and\n * rolled back from the dedup cache if the publish itself fails. Rate-limited (streaming)\n * resources go through a per-topic {@link RateGate} and are fire-and-forget: publish failures\n * there are reported via the `error` event, not thrown.\n */\n async publishResource(ref: EntityRef, resource: string, kind: MessageKind | null, payload: unknown): Promise<void> {\n const config = RESOURCE_CONFIG[resource];\n if (!config) throw new Iso21423Error(`unknown resource \"${resource}\"`);\n if (kind && this.validateOutbound) assertValid(kind, payload);\n const topic = topicFor(ref, resource);\n const body = JSON.stringify(payload);\n\n if (config.retain) {\n if (this.retainedOwned.get(topic)?.payload === body) return; // on-change rule\n this.retainedOwned.set(topic, { payload: body, qos: config.qos });\n try {\n await this.transport.publish(topic, body, { qos: config.qos, retain: true });\n } catch (err) {\n this.retainedOwned.delete(topic);\n throw err;\n }\n return;\n }\n if (config.maxHz !== undefined) {\n let gate = this.rateGates.get(topic);\n if (!gate) {\n gate = new RateGate(config.maxHz);\n this.rateGates.set(topic, gate);\n }\n gate.offer(body, (b) => {\n this.transport.publish(topic, b, { qos: config.qos, retain: false })\n .catch((err) => this.emitError(err));\n });\n return;\n }\n await this.transport.publish(topic, body, { qos: config.qos, retain: false });\n }\n\n /** Last non-wildcard resource segment → Table B.1 QoS, defaulting to QoS 1 when unknown. */\n private qosForFilter(filter: string): 0 | 1 | 2 {\n const parsed = parseTopic(filter);\n if (!parsed) return 1;\n const key = parsed.isRequestStatus ? 'requestStatus' : parsed.resource;\n return RESOURCE_CONFIG[key]?.qos ?? 1;\n }\n\n /**\n * Always issues a broker SUBSCRIBE (a real broker redelivers retained messages on every\n * SUBSCRIBE, so a late second handler must see the current retained value); the broker-side\n * unsubscribe still only fires once the last local listener on the filter leaves (ND-17).\n */\n async subscribeTopic(\n topicFilter: string,\n kind: MessageKind | null,\n handler: (msg: unknown, meta: TopicMeta) => void,\n opts: { qos?: 0 | 1 | 2 } = {},\n ): Promise<SessionSubscription> {\n const qos = opts.qos ?? this.qosForFilter(topicFilter);\n const { granted } = await this.transport.subscribe(topicFilter, { qos });\n if (!granted) {\n throw new AuthorizationDenied(`subscription denied by broker: ${topicFilter}`, topicFilter);\n }\n const sub: TopicSub = { filter: topicFilter, kind, handler };\n this.topicSubs.push(sub);\n return {\n unsubscribe: async () => {\n this.topicSubs = this.topicSubs.filter((s) => s !== sub);\n if (!this.topicSubs.some((s) => s.filter === topicFilter)) {\n await this.transport.unsubscribe(topicFilter);\n }\n },\n };\n }\n\n /** Publish to an exact topic (request / requestStatus topics are not plain resources). */\n async publishTopic(\n topic: string,\n kind: MessageKind | null,\n payload: unknown,\n opts: { qos: 0 | 1 | 2; retain: boolean },\n ): Promise<void> {\n if (kind && this.validateOutbound) assertValid(kind, payload);\n await this.transport.publish(topic, JSON.stringify(payload), opts);\n }\n\n get connectionState(): ConnectionState {\n return this.state;\n }\n\n /**\n * Subscribe to a resource topic with optional validation.\n * When kind is null, handler receives raw payload text without parsing or validation.\n */\n async subscribeResource(\n filter: { entityType?: string; entityUuid?: string },\n resource: string,\n kind: MessageKind | null,\n handler: (msg: unknown, meta: TopicMeta) => void,\n ): Promise<SessionSubscription & { [Symbol.asyncDispose](): Promise<void> }> {\n const config = RESOURCE_CONFIG[resource];\n if (!config) throw new Iso21423Error(`unknown resource \"${resource}\"`);\n const topicFilter = `${ROOT_NAMESPACE}/${filter.entityType ?? '+'}/${filter.entityUuid ?? '+'}/${resource}`;\n const sub = await this.subscribeTopic(topicFilter, kind, handler, { qos: config.qos });\n return { unsubscribe: sub.unsubscribe, [Symbol.asyncDispose]: sub.unsubscribe };\n }\n\n /** For subscribers that opt out of schema routing (kind: null) but still want to surface a\n * malformed payload as the usual 'validation-warning' event (D-13's RequestServer). */\n reportValidationWarning(w: ValidationWarningEvent): void {\n this.emitWarning(w);\n }\n\n async publishRaw(topic: string, payload: string, opts: { qos: 0 | 1 | 2; retain: boolean }): Promise<void> {\n await this.transport.publish(topic, payload, opts);\n }\n\n /** Clears a retained topic by publishing an empty retained payload, and drops it from the owned-retained dedup cache. */\n async clearRetained(topic: string): Promise<void> {\n this.retainedOwned.delete(topic);\n await this.transport.publish(topic, '', { qos: 1, retain: true });\n }\n\n /** Optionally publishes a final status, disposes all rate gates, then ends the transport. */\n async close(finalStates?: string[]): Promise<void> {\n if (finalStates) {\n await this.publishResource(this.entity, 'status', 'entityStatus', {\n entityId: this.entity.entityUuid,\n timestamp: nowTimestamp(),\n states: finalStates,\n });\n }\n for (const gate of this.rateGates.values()) gate.dispose();\n await this.transport.end();\n }\n\n /**\n * Routes an inbound message to every registered {@link TopicSub} whose filter matches the\n * topic. `kind: null` subscribers get the raw text with no parsing; typed subscribers get an\n * empty payload treated as a retained-clear (skipped silently) and malformed/non-conformant\n * payloads reported via `emitWarning` rather than delivered to the handler.\n */\n private dispatch(topic: string, payload: Buffer): void {\n const parsed = parseTopic(topic);\n if (!parsed) return;\n const text = payload.toString();\n const meta: TopicMeta = {\n topic,\n entityType: parsed.entityType,\n entityUuid: parsed.entityUuid,\n resource: parsed.resource,\n requestUuid: parsed.requestUuid,\n isRequestStatus: parsed.isRequestStatus,\n };\n for (const sub of this.topicSubs) {\n if (!topicFilterMatches(sub.filter, topic)) continue;\n if (!sub.kind) {\n sub.handler(text, meta);\n continue;\n }\n // An empty payload on a validated subscription is a retained-clear, not malformed input.\n if (text === '') continue;\n let value: unknown;\n try {\n value = JSON.parse(text);\n } catch {\n this.emitWarning({ topic, payload: text, errors: ['invalid JSON'] });\n continue;\n }\n const result = validateMessage(sub.kind, value);\n if (!result.ok) {\n this.emitWarning({ topic, payload: text, errors: result.errors ?? [] });\n continue;\n }\n sub.handler(result.value, meta);\n }\n }\n\n private handleConnectionState(s: ConnectionState): void {\n this.state = s;\n for (const cb of this.listeners.connection) cb(s);\n if (s === 'connected' && this.wasConnected) {\n // Reconnect: republish owned retained resources (broker may have lost them).\n for (const [topic, { payload, qos }] of this.retainedOwned) {\n this.transport.publish(topic, payload, { qos, retain: true })\n .catch((err) => this.emitError(err));\n }\n // The LWT we armed at connect time has now fired (stale): clear it, same as the\n // stale-crash clear at initial connect (spec §4).\n if (this.armWill) {\n this.clearRetained(disconnectionTopic(this.entity)).catch((err) => this.emitError(err));\n }\n }\n if (s === 'connected') this.wasConnected = true;\n }\n\n private emitWarning(w: ValidationWarningEvent): void {\n for (const cb of this.listeners['validation-warning']) cb(w);\n }\n\n private emitError(err: unknown): void {\n const errorListeners = this.listeners.error;\n if (errorListeners.length > 0) {\n for (const cb of errorListeners) cb(err);\n } else {\n console.error('[Iso21423Session] async publish failed:', err);\n }\n }\n}\n","/**\n * Copyright 2026 InOrbit, Inc.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport type {\n ConnectionState, MqttTransport, TransportConnectOptions, TransportMessage,\n} from './transport.js';\nimport { BrokerUnavailable, Iso21423Error } from '../errors.js';\n\n/** The minimal mqtt@5 surface the adapter uses — keeps `mqtt` out of the public types. */\nexport interface MqttClientLike {\n options?: { will?: { topic?: string }; clean?: boolean };\n connected: boolean;\n on(event: string, cb: (...args: never[]) => void): void;\n publishAsync(\n topic: string, payload: string | Buffer, opts: { qos: 0 | 1 | 2; retain: boolean },\n ): Promise<unknown>;\n subscribeAsync(filter: string, opts: { qos: 0 | 1 | 2 }): Promise<Array<{ topic: string; qos: number }>>;\n unsubscribeAsync(filter: string): Promise<unknown>;\n endAsync(force?: boolean): Promise<void>;\n}\n\n/** Options for {@link createMqttTransport}. */\nexport interface MqttTransportOptions {\n username?: string;\n password?: string;\n /** TLS / socket options passed straight through to mqtt.connect (ND-15). */\n tls?: Record<string, unknown>;\n reconnectPeriod?: number;\n}\n\n/** {@link MqttTransport} implementation over mqtt@5, either owning its own client ({@link createMqttTransport}) or wrapping a caller-supplied one ({@link wrapMqttClient}). */\nclass MqttAdapter implements MqttTransport {\n private client?: MqttClientLike;\n private ended = false;\n private wired = false;\n private readonly messageCbs: Array<(m: TransportMessage) => void> = [];\n private readonly stateCbs: Array<(s: ConnectionState) => void> = [];\n\n constructor(\n private readonly acquire: (opts: TransportConnectOptions) => Promise<MqttClientLike>,\n private readonly checkWill: boolean,\n private readonly ownsClient: boolean,\n ) {}\n\n /**\n * Acquires the underlying mqtt client (via the constructor-supplied `acquire`) and wires\n * message/connection-state listeners exactly once per adapter instance, so repeated `connect()`\n * calls (e.g. reconnect flows) don't accumulate duplicate listeners. For a caller-constructed\n * client whose will doesn't match `opts.will`, throws (P-4) rather than silently diverging.\n */\n async connect(opts: TransportConnectOptions): Promise<void> {\n const client = await this.acquire(opts);\n if (this.checkWill && opts.will && client.options?.will?.topic !== opts.will.topic) {\n throw new Iso21423Error(\n `caller-constructed mqtt client must be created with will { topic: \"${opts.will.topic}\", ` +\n `payload: '${opts.will.payload}', qos: ${opts.will.qos}, retain: ${opts.will.retain} } (P-4)`,\n );\n }\n\n // Wire message/state listeners only once per adapter\n if (!this.wired) {\n this.wired = true;\n client.on('message', ((topic: string, payload: Buffer, packet: { qos?: 0 | 1 | 2; retain?: boolean }) => {\n const msg: TransportMessage = {\n topic, payload, qos: packet?.qos ?? 0, retain: packet?.retain ?? false,\n };\n for (const cb of this.messageCbs) cb(msg);\n }) as never);\n client.on('reconnect', (() => this.emitState('reconnecting')) as never);\n client.on('offline', (() => this.emitState('offline')) as never);\n client.on('close', (() => this.emitState('closed')) as never);\n // Persistent 'connect' listener: mqtt.js re-emits 'connect' after every auto-reconnect, not\n // just the initial handshake. This is the ONLY place that emits 'connected' — the initial\n // connect's own onConnect (below) fires after this one (registered later, same event) and\n // only settles the promise/records `this.client`, so each 'connect' event still produces\n // exactly one 'connected' state, initial or reconnect alike.\n client.on('connect', (() => this.emitState('connected')) as never);\n }\n\n if (client.connected) {\n // Already connected (e.g. a caller-constructed client via wrapMqttClient): no 'connect'\n // event will fire for this state, so emit it directly — the persistent listener above only\n // covers events, not the already-there case.\n this.client = client;\n this.emitState('connected');\n return;\n }\n\n // Local settled flag ensures onConnect/onError fires at most once per promise\n let settled = false;\n const resolveReject = { resolve: null as unknown as (v: void) => void, reject: null as unknown as (r: unknown) => void };\n\n const onConnect = (() => {\n if (settled) return;\n settled = true;\n // 'connected' itself is emitted by the persistent listener registered above (same event) —\n // this only needs to record the live client and settle the connect() promise.\n this.client = client;\n resolveReject.resolve();\n }) as (...args: never[]) => void;\n\n const onError = ((err: Error) => {\n if (settled) return;\n settled = true;\n // Clean up owned clients (createMqttTransport path)\n if (this.ownsClient) {\n client.endAsync(true).catch(() => {}); // fire-and-forget\n }\n resolveReject.reject(new BrokerUnavailable(`mqtt connect failed: ${err.message}`));\n }) as (...args: never[]) => void;\n\n try {\n await new Promise<void>((resolve, reject) => {\n resolveReject.resolve = resolve;\n resolveReject.reject = reject;\n client.on('connect', onConnect);\n client.on('error', onError);\n });\n } finally {\n // Clean up settled listeners to prevent accumulation on retry\n try {\n const clientWithRemoval = client as { off?: (ev: string, cb: unknown) => void; removeListener?: (ev: string, cb: unknown) => void };\n (clientWithRemoval.off ?? clientWithRemoval.removeListener)?.('connect', onConnect);\n (clientWithRemoval.off ?? clientWithRemoval.removeListener)?.('error', onError);\n } catch {\n // Ignore cleanup errors (client might be disconnected/destroyed)\n }\n }\n }\n\n async publish(\n topic: string, payload: string | Buffer, opts: { qos: 0 | 1 | 2; retain: boolean },\n ): Promise<void> {\n await this.live().publishAsync(topic, payload, opts);\n }\n\n /** Subscribes and reports whether the broker granted it — false if any SUBACK return code was a refusal (>= 0x80, ND-15) or no grants came back. */\n async subscribe(filter: string, opts: { qos: 0 | 1 | 2 }): Promise<{ granted: boolean }> {\n const grants = await this.live().subscribeAsync(filter, opts);\n // MQTT 3.1.1 SUBACK: return code >= 0x80 means the broker refused the filter (ND-15).\n const granted = grants.length > 0 && grants.every((g) => g.qos < 128);\n return { granted };\n }\n\n async unsubscribe(filter: string): Promise<void> {\n await this.live().unsubscribeAsync(filter);\n }\n\n onMessage(cb: (m: TransportMessage) => void): void {\n this.messageCbs.push(cb);\n }\n\n onConnectionState(cb: (s: ConnectionState) => void): void {\n this.stateCbs.push(cb);\n }\n\n async end(): Promise<void> {\n this.ended = true;\n if (this.client) await this.client.endAsync();\n this.emitState('closed');\n }\n\n /** Returns the connected client or throws {@link BrokerUnavailable} if `end()` was called or `connect()` hasn't completed. */\n private live(): MqttClientLike {\n if (this.ended || !this.client) throw new BrokerUnavailable('mqtt transport is not connected');\n return this.client;\n }\n\n private emitState(s: ConnectionState): void {\n for (const cb of this.stateCbs) cb(s);\n }\n}\n\n/** Adapt a caller-constructed mqtt client (D-07). Its will must match the SDK's (P-4). */\nexport function wrapMqttClient(client: MqttClientLike): MqttTransport {\n return new MqttAdapter(async () => client, true, false);\n}\n\n/**\n * Default adapter. `mqtt` is a peer dependency and is imported lazily inside connect(),\n * so importing this module never pulls mqtt into the graph (no top-level await, ND-19).\n */\nexport function createMqttTransport(url: string, opts: MqttTransportOptions = {}): MqttTransport {\n return new MqttAdapter(async (connectOpts) => {\n let mod: { connect: (url: string, o: Record<string, unknown>) => MqttClientLike };\n try {\n mod = (await import('mqtt')) as never;\n } catch (err) {\n throw new BrokerUnavailable(\n `the \"mqtt\" peer dependency is not installed: ${(err as Error).message}`,\n );\n }\n return mod.connect(url, {\n ...opts.tls,\n clientId: connectOpts.clientId,\n clean: connectOpts.cleanSession,\n keepalive: connectOpts.keepalive,\n username: connectOpts.username ?? opts.username,\n password: connectOpts.password ?? opts.password,\n reconnectPeriod: opts.reconnectPeriod,\n will: connectOpts.will,\n });\n }, false, true);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;AAuBO,IAAM,WAAN,MAAe;AAAA,EACH;AAAA,EACT,WAAW;AAAA,EACX;AAAA,EACA;AAAA,EAER,YAAY,OAAe;AACzB,QAAI,EAAE,QAAQ,MAAM,CAAC,OAAO,SAAS,KAAK,GAAG;AAC3C,YAAM,IAAI,cAAc,6CAA6C,KAAK,EAAE;AAAA,IAC9E;AACA,SAAK,aAAa,MAAO;AAAA,EAC3B;AAAA;AAAA,EAGA,MAAS,OAAU,MAA4B;AAC7C,UAAM,MAAM,KAAK,IAAI;AACrB,QAAI,MAAM,KAAK,YAAY,KAAK,YAAY;AAC1C,WAAK,WAAW;AAChB,WAAK,KAAK;AACV;AAAA,IACF;AACA,SAAK,UAAU,EAAE,OAAO,KAAiC;AACzD,QAAI,KAAK,UAAU,QAAW;AAC5B,YAAM,OAAO,KAAK,cAAc,MAAM,KAAK;AAC3C,WAAK,QAAQ,WAAW,MAAM;AAC5B,aAAK,QAAQ;AACb,cAA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