@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
package/README.md
CHANGED
|
@@ -1,3 +1,359 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @openrobops/iso21423 — TypeScript SDK for ISO 21423
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
A TypeScript/Node.js implementation of **ISO 21423** — *Robotics — Industrial mobile robots —
|
|
4
|
+
Communications and interoperability* — the open standard for how autonomous mobile robots (IMRs),
|
|
5
|
+
fleet managers (IMRFMs) and facility equipment talk to each other over **MQTT 3.1.1 + JSON**.
|
|
6
|
+
|
|
7
|
+
The SDK was developed as part of **[OpenRobOps](https://github.com/OpenRobOps)**, the open-source
|
|
8
|
+
robot operations platform, which uses it to run as an ISO 21423 fleet manager (see
|
|
9
|
+
[ISO 21423 in OpenRobOps](https://openrobops.org/docs/iso21423/overview)). It is independent of
|
|
10
|
+
OpenRobOps, though: anyone building an ISO 21423 robot, fleet manager, observer or facility
|
|
11
|
+
controller in Node.js can use it.
|
|
12
|
+
|
|
13
|
+
> **Status:** v0.1 — tracks **ISO/FDIS 21423:2026** (Final Draft). The API may still move before
|
|
14
|
+
> 1.0; the wire format follows the FDIS, with the deviations listed under
|
|
15
|
+
> [Spec deviations](#spec-deviations). Known defects in the draft are catalogued in
|
|
16
|
+
> [`docs/iso-fdis-21423-defects.md`](../docs/iso-fdis-21423-defects.md).
|
|
17
|
+
|
|
18
|
+
## What it gives you
|
|
19
|
+
|
|
20
|
+
- **Topics and resources** — the `/ISO_21423/v1/<entityType>/<uuid>/<resource>` namespace, Table B.1
|
|
21
|
+
QoS/retain/rate per resource, identity discovery wildcard, topic parsing, and deployment-defined
|
|
22
|
+
extension resources.
|
|
23
|
+
- **Session rules you cannot get wrong** — persistent session, 60 s keep-alive, the B.4 Last Will on
|
|
24
|
+
`disconnection` (QoS 1, retained), stale-will cleanup on (re)connect, streaming rate limits for
|
|
25
|
+
`odometry` / `localTrajectory`.
|
|
26
|
+
- **Typed messages + JSON Schema validation** — every Annex A object typed, validated on egress and
|
|
27
|
+
ingress (Ajv), with tolerant normalisation of known FDIS inconsistencies.
|
|
28
|
+
- **The request protocol** — `request` / `requestStatus` topics, the Figure C.3/C.4 state machines,
|
|
29
|
+
`activeRequestsStatus`, retained-request cleanup on terminal states, and all five C.2.2
|
|
30
|
+
concurrency strategies as ready-made execution policies.
|
|
31
|
+
- **Roles** — one `EntityHandle` abstraction that publishes, sends requests, and serves them, for
|
|
32
|
+
your own entity or for entities you manage on their behalf (B.5.2.4); a `FleetGateway` facade for
|
|
33
|
+
the IMRFM role; observer subscriptions with structured filters.
|
|
34
|
+
- **Geometry** — least-squares rigid 2D transform fitting between a local map and the facility
|
|
35
|
+
Common Coordinate System (Clause 4, Annex D).
|
|
36
|
+
- **Testing** — an in-process MQTT broker so you can test robots and fleet managers without
|
|
37
|
+
Mosquitto.
|
|
38
|
+
|
|
39
|
+
## Install
|
|
40
|
+
|
|
41
|
+
Requires Node.js ≥ 22. The package is published to npmjs:
|
|
42
|
+
|
|
43
|
+
```sh
|
|
44
|
+
npm install @openrobops/iso21423 mqtt
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
`mqtt@^5` is a peer dependency: install it, or inject your own `MqttTransport` (see
|
|
48
|
+
[Transports](#transports)). ESM and CJS builds with type declarations are included.
|
|
49
|
+
|
|
50
|
+
## Quick start
|
|
51
|
+
|
|
52
|
+
### A robot (IMR)
|
|
53
|
+
|
|
54
|
+
```ts
|
|
55
|
+
import { Iso21423Client, createMqttTransport } from '@openrobops/iso21423';
|
|
56
|
+
import type { MoveProps } from '@openrobops/iso21423';
|
|
57
|
+
|
|
58
|
+
const client = await Iso21423Client.connect({
|
|
59
|
+
transport: createMqttTransport('mqtt://broker.local:1883', { username: 'amr07', password: '…' }),
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
// Registering the self entity publishes the retained identity and arms the Last Will.
|
|
63
|
+
const robot = await client.registerSelfEntity({
|
|
64
|
+
entityUuid: '5f8c1e2a-6b3d-4a9f-8e11-2c7d9a4b1f00',
|
|
65
|
+
entityType: 'IMR',
|
|
66
|
+
manufacturerName: 'Acme Robotics',
|
|
67
|
+
details: {
|
|
68
|
+
imrModel: 'AMR-7', imrSerialNumber: 'A7-0042', imrHeight: 1.2,
|
|
69
|
+
imrFootprint: [{ x: 0.4, y: 0.3 }, { x: 0.4, y: -0.3 }, { x: -0.4, y: -0.3 }, { x: -0.4, y: 0.3 }],
|
|
70
|
+
imrWorkingArea: [], softwareVersions: [{ moduleName: 'nav', moduleVersion: '3.1.0' }],
|
|
71
|
+
},
|
|
72
|
+
capabilities: { provides: ['odometry', 'batteryStatus'], accepts: ['move', 'pauseImr', 'resumeImr', 'cancelRequest'] },
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
await robot.publishStatus({ states: ['MODE_AUTO', 'IDLE'] });
|
|
76
|
+
await robot.publishBatteryStatus({ batterySoc: 0.82, batteryChargingState: 'DISCHARGING' });
|
|
77
|
+
await robot.publishOdometry({
|
|
78
|
+
pose: { locationPoint: { ccsId: CCS_ID, x: 12.4, y: 8.1, z: 0 }, orientation: { yaw: 1.57, pitch: 0, roll: 0 } },
|
|
79
|
+
velocity: { linear: 0.5, angular: 0 },
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
// Serve requests. The SDK handles RECEIVED/ACCEPTED/EXECUTING/terminal statuses, activeRequestsStatus,
|
|
83
|
+
// retained-request cleanup and concurrency; you implement the action.
|
|
84
|
+
robot.onRequest<MoveProps>('move', async (action, ctx) => {
|
|
85
|
+
await nav.goTo(action.properties.location, ctx.signal); // ctx.signal aborts on cancel
|
|
86
|
+
ctx.progress({ distanceRemaining: 0 });
|
|
87
|
+
return ctx.succeeded();
|
|
88
|
+
});
|
|
89
|
+
robot.onRequest('pauseImr', async (_a, ctx) => { nav.pause(); return ctx.succeeded(); });
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
### A fleet manager (IMRFM) commanding robots
|
|
93
|
+
|
|
94
|
+
```ts
|
|
95
|
+
import { Iso21423Client, EntityFilter, move, RequestFailed } from '@openrobops/iso21423';
|
|
96
|
+
|
|
97
|
+
const client = await Iso21423Client.connect({ url: 'mqtt://broker.local:1883', security: { username, password } });
|
|
98
|
+
const fm = await client.registerSelfEntity({
|
|
99
|
+
entityUuid: IMRFM_ID, entityType: 'IMRFM', manufacturerName: 'Acme Fleet',
|
|
100
|
+
details: { softwareVersions: [{ moduleName: 'fleet', moduleVersion: '1.0.0' }] },
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
// Discover robots as their retained identities arrive (current ones are replayed synchronously).
|
|
104
|
+
await client.subscribeEntities(EntityFilter.ofType('IMR'), (identity) => console.log('IMR', identity.id));
|
|
105
|
+
await client.subscribeResource('odometry', EntityFilter.ofType('IMR'), (ev) => track(ev.entityUuid, ev.message));
|
|
106
|
+
|
|
107
|
+
// Send a request. The SDK refuses to send an action the robot does not advertise in `accepts`.
|
|
108
|
+
const handle = await fm.sendRequest({
|
|
109
|
+
destination: ROBOT_ID,
|
|
110
|
+
details: [move({ location: { ccsId: CCS_ID, x: 20, y: 5, z: 0 } })],
|
|
111
|
+
});
|
|
112
|
+
handle.onStatus((s) => console.log(s.status));
|
|
113
|
+
try {
|
|
114
|
+
await handle.completion(); // resolves on SUCCEEDED
|
|
115
|
+
} catch (e) {
|
|
116
|
+
if (e instanceof RequestFailed) console.log('ended', e.finalStatus);
|
|
117
|
+
}
|
|
118
|
+
// …or cancel it: sends a `cancelRequest` for this request.
|
|
119
|
+
await handle.cancel();
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
### A fleet manager publishing on behalf of robots
|
|
123
|
+
|
|
124
|
+
For robots that do not speak ISO 21423 themselves (B.5.2.4 "managed entities"), `FleetGateway`
|
|
125
|
+
owns the IMRFM identity, every managed robot's identity (with `manages` / `managedBy` links kept
|
|
126
|
+
consistent), and replays fleet-wide handlers onto each robot:
|
|
127
|
+
|
|
128
|
+
```ts
|
|
129
|
+
import { FleetGateway } from '@openrobops/iso21423';
|
|
130
|
+
|
|
131
|
+
const fleet = await FleetGateway.connect({
|
|
132
|
+
url: 'mqtt://broker.local:1883',
|
|
133
|
+
imrfm: { id: IMRFM_ID, manufacturerName: 'Acme Fleet', accepts: ['move'] },
|
|
134
|
+
});
|
|
135
|
+
const r1 = await fleet.registerImr({ id: ROBOT_1, manufacturerName: 'Legacy Co', accepts: ['move'] });
|
|
136
|
+
await r1.publishOdometry(sampleFromLegacyApi());
|
|
137
|
+
|
|
138
|
+
fleet.onRequest('move', async (action, ctx) => {
|
|
139
|
+
await legacy.goTo(ctx.entity.entityUuid, action.properties);
|
|
140
|
+
return ctx.succeeded();
|
|
141
|
+
});
|
|
142
|
+
// Requests with an empty `destination` ("IMRFM picks the robot") land here:
|
|
143
|
+
fleet.onDispatch((request, imrs) => imrs.find(isIdle)?.entityUuid ?? null);
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
The gateway also turns on two robustness features by default: a **retained-request janitor** that
|
|
147
|
+
clears retained requests left behind by crashed senders after a grace period, and a **publish
|
|
148
|
+
self-check** that verifies the session can actually publish under its own identity (catches
|
|
149
|
+
broker ACL misconfiguration early).
|
|
150
|
+
|
|
151
|
+
### An observer
|
|
152
|
+
|
|
153
|
+
```ts
|
|
154
|
+
const client = await Iso21423Client.connect({ url }); // no identity → no Last Will
|
|
155
|
+
await client.subscribeRequestStatus(RequestStatusFilter.all(), (ev) => dashboard.update(ev));
|
|
156
|
+
const catalog = client.discover(); // every entity seen so far
|
|
157
|
+
catalog.on('lost', (e) => alert(`${e.entityUuid} lost connection`));
|
|
158
|
+
```
|
|
159
|
+
|
|
160
|
+
## Concepts
|
|
161
|
+
|
|
162
|
+
### Entities and `EntityHandle`
|
|
163
|
+
|
|
164
|
+
Everything on the ISO network is an *entity* with a type (`IMR`, `IMRFM`, or a deployment-defined
|
|
165
|
+
type such as `DOOR`) and a UUID. `Iso21423Client` owns one MQTT session and hands out
|
|
166
|
+
`EntityHandle`s:
|
|
167
|
+
|
|
168
|
+
- `registerSelfEntity(reg)` — the entity *this process is*. The first call arms the B.4 Last Will
|
|
169
|
+
for it. Publishes the retained identity.
|
|
170
|
+
- `registerManagedEntity(managerUuid, reg)` — an entity this process publishes *for*, under the
|
|
171
|
+
entity's own topic tree, linked to its manager via `manages`/`managedBy`.
|
|
172
|
+
|
|
173
|
+
A handle publishes (`publishIdentity`, `updateIdentity`, `publishStatus`, `publishBatteryStatus`,
|
|
174
|
+
`publishOdometry`, `publishLocalTrajectory`, `publishGlobalPath`, `publishGlobalPlan`,
|
|
175
|
+
`publishExtension`), sends requests (`sendRequest`), and serves them (`onRequest`, or the low-level
|
|
176
|
+
`acceptRequests`). `unregister()` clears every retained topic except a final `OFFLINE` status
|
|
177
|
+
tombstone.
|
|
178
|
+
|
|
179
|
+
### Requests
|
|
180
|
+
|
|
181
|
+
`sendRequest` publishes a retained `request/<uuid>` (QoS 2), subscribes to its status *before*
|
|
182
|
+
publishing so no update is missed, and returns a `RequestHandle`:
|
|
183
|
+
|
|
184
|
+
| | |
|
|
185
|
+
|---|---|
|
|
186
|
+
| `onStatus(cb)` | every `requestStatus` for this request |
|
|
187
|
+
| `completion()` | resolves with the final status on `SUCCEEDED`, rejects with `RequestFailed` on `ABORTED`/`CANCELED`, `RequestTimeout` if no terminal status arrives in `timeoutMs`, `BrokerUnavailable` if the connection drops |
|
|
188
|
+
| `cancel()` | sends a `cancelRequest` naming this request |
|
|
189
|
+
|
|
190
|
+
Action builders in `@openrobops/iso21423` produce correctly-shaped `RequestDetail`s: `move`,
|
|
191
|
+
`dock`, `undock`, `pauseImr`, `resumeImr`, `cancelRequest`. Vendor actions are plain
|
|
192
|
+
`{ type, version, properties }` objects; a robot opts in by listing the type in
|
|
193
|
+
`capabilities.accepts`. Pass `requireCapability: false` to send to an entity whose capabilities are
|
|
194
|
+
unknown or that does not advertise the action.
|
|
195
|
+
|
|
196
|
+
On the serving side, `onRequest(type, handler)` registers an `ActionHandler` per action type. The
|
|
197
|
+
executor handles the whole lifecycle — `RECEIVED` before any handler runs, duplicate suppression,
|
|
198
|
+
admission by execution policy, `ACCEPTED`/`EXECUTING`, `blocking`/`atomic` semantics across a
|
|
199
|
+
multi-detail request, `recoveries`, terminal status, `activeRequestsStatus`, and clearing the
|
|
200
|
+
retained request with a zero-byte payload. The handler gets an `ActionContext` with the request,
|
|
201
|
+
an `AbortSignal` that fires on cancel, `progress()`, `succeeded()` and `aborted(reason)`.
|
|
202
|
+
|
|
203
|
+
**Execution policies** (`policies.*`, Clause C.2.2) decide what happens when a request arrives
|
|
204
|
+
while others are active: `abortNew()`, `queueReplace()`, `queueAfter()`, `parallel(max?)`
|
|
205
|
+
(default) and `priority()`. Set per entity (`executionPolicy` at registration,
|
|
206
|
+
`setExecutionPolicy`) or per client (`setDefaultExecutionPolicy`), or supply your own
|
|
207
|
+
`ExecutionPolicy`.
|
|
208
|
+
|
|
209
|
+
`sequenceId`s are monotonic per entity and survive restarts through a `SequenceStore` — by default
|
|
210
|
+
a JSON file under `$ISO21423_STATE_DIR` or `~/.iso21423`. Pass `sequenceStore: null` for
|
|
211
|
+
in-memory only (tests).
|
|
212
|
+
|
|
213
|
+
### Filters
|
|
214
|
+
|
|
215
|
+
Observer APIs take structured filters that compile to MQTT wildcards: `EntityFilter.all() /
|
|
216
|
+
ofType(t) / entity(uuid) / anyOf([...])`, `RequestFilter.all() / toEntity(uuid) / ofType(t)`,
|
|
217
|
+
`RequestStatusFilter.all() / ofEntity(uuid) / ofType(t)`, and `RequestAcceptanceFilter.all() /
|
|
218
|
+
actions([...]) / fromSource(uuid)` for `acceptRequests`.
|
|
219
|
+
|
|
220
|
+
### Extension resources
|
|
221
|
+
|
|
222
|
+
The standard leaves the resource catalogue open. Register a deployment-defined resource once on
|
|
223
|
+
each side and publish/subscribe it like any other:
|
|
224
|
+
|
|
225
|
+
```ts
|
|
226
|
+
import { registerExtensionResource } from '@openrobops/iso21423';
|
|
227
|
+
registerExtensionResource('customData', { qos: 1, retain: false });
|
|
228
|
+
await robot.publishExtension('customData', { timestamp: new Date().toISOString(), values: { echo: 'hi' } });
|
|
229
|
+
await client.subscribeResource('customData', EntityFilter.ofType('IMR'), (ev) => …);
|
|
230
|
+
```
|
|
231
|
+
|
|
232
|
+
Standard names cannot be redefined; identical re-registration is a no-op. Extension payloads are
|
|
233
|
+
not schema-validated.
|
|
234
|
+
|
|
235
|
+
### Geometry
|
|
236
|
+
|
|
237
|
+
`fitTransform(from, to)` fits a rigid 2D transform (rotation + translation, least squares) from
|
|
238
|
+
≥ 3 point pairs — e.g. reference points measured both in a robot's map frame and in the facility
|
|
239
|
+
CCS; `applyTransform`, `invertTransform` and `transformYaw` apply it. The standard defines the CCS
|
|
240
|
+
but no way to distribute it, so calibration data is deployment configuration.
|
|
241
|
+
|
|
242
|
+
### Transports
|
|
243
|
+
|
|
244
|
+
`createMqttTransport(url, { username, password, tls, reconnectPeriod })` builds a transport on
|
|
245
|
+
`mqtt@5`. `wrapMqttClient(client)` adopts a client you constructed — it is rejected if its `will`
|
|
246
|
+
does not match what the standard requires. Implement the small `MqttTransport` interface to use
|
|
247
|
+
any other client. `Iso21423Client.connect({ url, security })` is shorthand for the first form.
|
|
248
|
+
|
|
249
|
+
### Diagnostics and health
|
|
250
|
+
|
|
251
|
+
- `client.on('connection', s)` — `connected | reconnecting | offline | closed`.
|
|
252
|
+
- `client.on('validation-warning', w)` — inbound messages that were normalised or carry unknown
|
|
253
|
+
operating states.
|
|
254
|
+
- `client.on('diagnostic', e)` — non-fatal conditions: `duplicate-request-ignored`,
|
|
255
|
+
`legacy-cancel-normalized`, `inbound-illegal-transition`, `dispatch-rejected`, `janitor-cleared`,
|
|
256
|
+
`self-check-failed`, `sequence-store-unavailable`, `will-not-armed`.
|
|
257
|
+
- `client.health()` — connection state, entities, subscriptions, in-flight/serving counts and
|
|
258
|
+
publish/receive/warning/rejection counters.
|
|
259
|
+
|
|
260
|
+
Errors are subclasses of `Iso21423Error`: `ValidationError`, `RequestFailed`, `RequestTimeout`,
|
|
261
|
+
`BrokerUnavailable`, `AuthorizationDenied`, `NotCapableError`, `IllegalTransition`.
|
|
262
|
+
|
|
263
|
+
## Testing your integration
|
|
264
|
+
|
|
265
|
+
`@openrobops/iso21423/testing` ships `MemoryBroker`, an in-process broker with retained messages,
|
|
266
|
+
Last Will and subscription-denial simulation:
|
|
267
|
+
|
|
268
|
+
```ts
|
|
269
|
+
import { MemoryBroker } from '@openrobops/iso21423/testing';
|
|
270
|
+
|
|
271
|
+
const broker = new MemoryBroker();
|
|
272
|
+
const robotClient = await Iso21423Client.connect({ transport: broker.createTransport(), sequenceStore: null });
|
|
273
|
+
const fmClient = await Iso21423Client.connect({ transport: broker.createTransport(), sequenceStore: null });
|
|
274
|
+
// … register entities, send a request …
|
|
275
|
+
broker.retainedOn(`/ISO_21423/v1/IMR/${ROBOT}/identity`); // inspect the wire
|
|
276
|
+
broker.messagesUnder(`/ISO_21423/v1/IMR/${ROBOT}/request`);
|
|
277
|
+
```
|
|
278
|
+
|
|
279
|
+
## Module map
|
|
280
|
+
|
|
281
|
+
| Entry point | Contents |
|
|
282
|
+
|---|---|
|
|
283
|
+
| `@openrobops/iso21423` | everything below, re-exported |
|
|
284
|
+
| `…/types` | TypeScript types for every Annex A object, vocabularies (`KNOWN_OPERATING_STATES`, `REQUEST_STATES`, `DOCK_ACTIONS`, …), action builders |
|
|
285
|
+
| `…/schema` | `validateMessage`, `assertValid`, `normalizeInbound`, the bundled JSON Schema |
|
|
286
|
+
| `…/topics` | `topicFor`, `requestTopic`, `parseTopic`, `identityWildcard`, `RESOURCE_CONFIG`, `registerExtensionResource` |
|
|
287
|
+
| `…/geometry` | `fitTransform`, `applyTransform`, `invertTransform`, `transformYaw` |
|
|
288
|
+
| `…/session` | `Iso21423Session`, `MqttTransport`, `createMqttTransport`, `wrapMqttClient`, `RateGate` |
|
|
289
|
+
| `…/core` | `Iso21423Client`, `EntityHandle`, `RequestHandle`, `IncomingRequest`, filters, `policies`, `SequenceStore` |
|
|
290
|
+
| `…/gateway` | `FleetGateway`, `RetainedRequestJanitor`, `publishSelfCheck` |
|
|
291
|
+
| `…/testing` | `MemoryBroker`, `MemoryTransport` |
|
|
292
|
+
|
|
293
|
+
## Coverage
|
|
294
|
+
|
|
295
|
+
| ISO 21423 area | Status |
|
|
296
|
+
|---|---|
|
|
297
|
+
| Clause 4 CCS — types, Annex D transform fit | ✅ (no CCS transport: none is defined by the standard) |
|
|
298
|
+
| Clause 5/7 identity and capabilities (Tables 4, 7, A.3) | ✅ |
|
|
299
|
+
| Clause 6/8 status, all Table 5 / Table 9 states, battery, odometry, trajectories, NURBS global path | ✅ |
|
|
300
|
+
| Clause 9 / Annex C requests — envelope, details, status, state machines, all C.2.2 policies, recoveries, empty destination | ✅ |
|
|
301
|
+
| Clause 10 / Annex B — topics, QoS/retain, persistent session, Last Will, keep-alive, streaming rate bounds | ✅ |
|
|
302
|
+
| B.5.2.4 managed entities | ✅ (`FleetGateway`) |
|
|
303
|
+
| Annex A JSON Schema | 🌗 all objects except `ccs`, `referencePoint`, `entityFootprintHeight` |
|
|
304
|
+
| `footprint` resource | 🌗 QoS/retain entry only; no schema or typed publisher (the FDIS leaves it half specified) |
|
|
305
|
+
| Table 5 conditional rules (exactly one `MODE_*`, stop categories in manual modes) | ❌ unknown states only warn |
|
|
306
|
+
| Minimum publish frequency (6.3, Clause 8) | ❌ only the Table B.1 maxima are enforced |
|
|
307
|
+
| Broker provisioning, ACLs, credential issuance | out of scope — see how OpenRobOps does it |
|
|
308
|
+
|
|
309
|
+
## Spec deviations
|
|
310
|
+
|
|
311
|
+
Deliberate, documented positions on FDIS defects (details and rationale in
|
|
312
|
+
[`docs/iso-fdis-21423-defects.md`](../docs/iso-fdis-21423-defects.md) and the
|
|
313
|
+
[decision register](../docs/nodejs_design/docs/decision_register.md)):
|
|
314
|
+
|
|
315
|
+
- The cancel action is emitted as **`cancelRequest`**; the FDIS name `cancel` is accepted on
|
|
316
|
+
ingress and normalised (diagnostic `legacy-cancel-normalized`).
|
|
317
|
+
- Resource name **`activeRequestsStatus`** (Table B.1) over B.2.2's `activeRequestStatus`.
|
|
318
|
+
- Status messages use **`entityId` / `states`**; inbound `id` is renamed with a warning.
|
|
319
|
+
- The Last Will payload is valid JSON, **`{"states":["LOST_CONNECTION"]}`**, and `disconnection`
|
|
320
|
+
is treated as a first-class resource.
|
|
321
|
+
- Request/status topics always include the `<entityType>` segment.
|
|
322
|
+
- Comma decimal separators in timestamps are normalised to dots on ingress.
|
|
323
|
+
- `move.orientation`, odometry `orientation`, `imrName` and `disabledCapabilities` — present in the
|
|
324
|
+
FDIS schema/examples but not its tables — are supported.
|
|
325
|
+
|
|
326
|
+
## Development
|
|
327
|
+
|
|
328
|
+
```sh
|
|
329
|
+
nvm use # Node 22, see .nvmrc
|
|
330
|
+
npm install
|
|
331
|
+
npm run build # tsup → dist/ (ESM + CJS + .d.ts)
|
|
332
|
+
npm test # unit + integration (in-process broker)
|
|
333
|
+
npm run test:live # against a real broker: ISO21423_BROKER_URL=mqtt://localhost:1883
|
|
334
|
+
npm run typecheck
|
|
335
|
+
npm run lint
|
|
336
|
+
```
|
|
337
|
+
|
|
338
|
+
Layout: `src/` (see module map), `test/` (Vitest: unit suites, `integration/` scenarios on
|
|
339
|
+
`MemoryBroker`, `live/` round-trip against a real broker). Releases are published to GitHub
|
|
340
|
+
Packages by CI on `v*` tags.
|
|
341
|
+
|
|
342
|
+
### Code style
|
|
343
|
+
|
|
344
|
+
Every non-trivial exported class, interface, function and method carries a TSDoc comment stating
|
|
345
|
+
what the signature alone can't — units, ordering, throw conditions, side effects. Trivial members
|
|
346
|
+
stay bare. Spec references (ISO clause numbers, `ND-xx`, `D-xx` decision ids) are kept verbatim
|
|
347
|
+
wherever they appear.
|
|
348
|
+
|
|
349
|
+
## Further reading
|
|
350
|
+
|
|
351
|
+
- [Understanding ISO 21423](../docs/standard/README.md) — plain-language companion to the standard
|
|
352
|
+
- [NodeJS SDK design](../docs/nodejs_design/README.md) — decision register, API rationale, role examples
|
|
353
|
+
- [FDIS defects catalogue](../docs/iso-fdis-21423-defects.md)
|
|
354
|
+
- [ISO 21423 in OpenRobOps](https://openrobops.org/docs/iso21423/overview) — a production fleet manager built on this SDK, and its [coverage page](https://openrobops.org/docs/iso21423/coverage)
|
|
355
|
+
- [sim-flatland](https://github.com/OpenRobOps/sim-flatland) — a simulated robot with an ISO 21423 agent built on this SDK
|
|
356
|
+
|
|
357
|
+
## License
|
|
358
|
+
|
|
359
|
+
Apache-2.0.
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright 2026 InOrbit, Inc.
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
type Uuid = string;
|
|
17
|
+
/** ISO 8601-1 timestamp string, dot-decimal milliseconds, UTC. */
|
|
18
|
+
type IsoTimestamp = string;
|
|
19
|
+
declare function nowTimestamp(date?: Date): IsoTimestamp;
|
|
20
|
+
/** Accepts both dot and comma decimal separators (spec §3.1). */
|
|
21
|
+
declare function parseTimestamp(ts: string): Date;
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Copyright 2026 InOrbit, Inc.
|
|
25
|
+
*
|
|
26
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
27
|
+
* you may not use this file except in compliance with the License.
|
|
28
|
+
* You may obtain a copy of the License at
|
|
29
|
+
*
|
|
30
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
31
|
+
*
|
|
32
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
33
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
34
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
35
|
+
* See the License for the specific language governing permissions and
|
|
36
|
+
* limitations under the License.
|
|
37
|
+
*/
|
|
38
|
+
|
|
39
|
+
interface Point {
|
|
40
|
+
x: number;
|
|
41
|
+
y: number;
|
|
42
|
+
}
|
|
43
|
+
/** A named coordinate system, defined by the reference points it's anchored to. */
|
|
44
|
+
interface Ccs {
|
|
45
|
+
id: Uuid;
|
|
46
|
+
name: string;
|
|
47
|
+
referencePointIds: Uuid[];
|
|
48
|
+
}
|
|
49
|
+
interface ReferencePoint {
|
|
50
|
+
id: Uuid;
|
|
51
|
+
name: string;
|
|
52
|
+
x: number;
|
|
53
|
+
y: number;
|
|
54
|
+
}
|
|
55
|
+
/** A point expressed relative to a specific {@link Ccs} rather than global coordinates. */
|
|
56
|
+
interface LocationPoint {
|
|
57
|
+
ccsId: Uuid;
|
|
58
|
+
x: number;
|
|
59
|
+
y: number;
|
|
60
|
+
z: number;
|
|
61
|
+
}
|
|
62
|
+
/** Euler angles in radians. */
|
|
63
|
+
interface Orientation {
|
|
64
|
+
yaw: number;
|
|
65
|
+
pitch: number;
|
|
66
|
+
roll: number;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
export { type Ccs as C, type IsoTimestamp as I, type LocationPoint as L, type Orientation as O, type Point as P, type ReferencePoint as R, type Uuid as U, nowTimestamp as n, parseTimestamp as p };
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright 2026 InOrbit, Inc.
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
type Uuid = string;
|
|
17
|
+
/** ISO 8601-1 timestamp string, dot-decimal milliseconds, UTC. */
|
|
18
|
+
type IsoTimestamp = string;
|
|
19
|
+
declare function nowTimestamp(date?: Date): IsoTimestamp;
|
|
20
|
+
/** Accepts both dot and comma decimal separators (spec §3.1). */
|
|
21
|
+
declare function parseTimestamp(ts: string): Date;
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Copyright 2026 InOrbit, Inc.
|
|
25
|
+
*
|
|
26
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
27
|
+
* you may not use this file except in compliance with the License.
|
|
28
|
+
* You may obtain a copy of the License at
|
|
29
|
+
*
|
|
30
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
31
|
+
*
|
|
32
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
33
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
34
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
35
|
+
* See the License for the specific language governing permissions and
|
|
36
|
+
* limitations under the License.
|
|
37
|
+
*/
|
|
38
|
+
|
|
39
|
+
interface Point {
|
|
40
|
+
x: number;
|
|
41
|
+
y: number;
|
|
42
|
+
}
|
|
43
|
+
/** A named coordinate system, defined by the reference points it's anchored to. */
|
|
44
|
+
interface Ccs {
|
|
45
|
+
id: Uuid;
|
|
46
|
+
name: string;
|
|
47
|
+
referencePointIds: Uuid[];
|
|
48
|
+
}
|
|
49
|
+
interface ReferencePoint {
|
|
50
|
+
id: Uuid;
|
|
51
|
+
name: string;
|
|
52
|
+
x: number;
|
|
53
|
+
y: number;
|
|
54
|
+
}
|
|
55
|
+
/** A point expressed relative to a specific {@link Ccs} rather than global coordinates. */
|
|
56
|
+
interface LocationPoint {
|
|
57
|
+
ccsId: Uuid;
|
|
58
|
+
x: number;
|
|
59
|
+
y: number;
|
|
60
|
+
z: number;
|
|
61
|
+
}
|
|
62
|
+
/** Euler angles in radians. */
|
|
63
|
+
interface Orientation {
|
|
64
|
+
yaw: number;
|
|
65
|
+
pitch: number;
|
|
66
|
+
roll: number;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
export { type Ccs as C, type IsoTimestamp as I, type LocationPoint as L, type Orientation as O, type Point as P, type ReferencePoint as R, type Uuid as U, nowTimestamp as n, parseTimestamp as p };
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import {
|
|
2
|
+
PROTOCOL_VERSION
|
|
3
|
+
} from "./chunk-RD7PYTIT.js";
|
|
4
|
+
|
|
5
|
+
// src/types/actions.ts
|
|
6
|
+
function detail(type, properties, opts = {}) {
|
|
7
|
+
return {
|
|
8
|
+
type,
|
|
9
|
+
version: opts.version ?? PROTOCOL_VERSION,
|
|
10
|
+
format: "ISO-21423",
|
|
11
|
+
blocking: opts.blocking ?? true,
|
|
12
|
+
atomic: opts.atomic ?? false,
|
|
13
|
+
properties
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
var move = (props, opts) => detail("move", { ...props }, opts);
|
|
17
|
+
var pauseImr = (opts) => detail("pauseImr", {}, opts);
|
|
18
|
+
var resumeImr = (opts) => detail("resumeImr", {}, opts);
|
|
19
|
+
var cancelRequest = (props, opts) => detail("cancelRequest", { ...props }, opts);
|
|
20
|
+
var dock = (props, opts) => detail("dock", { ...props }, opts);
|
|
21
|
+
var undock = (opts) => detail("undock", {}, opts);
|
|
22
|
+
|
|
23
|
+
export {
|
|
24
|
+
move,
|
|
25
|
+
pauseImr,
|
|
26
|
+
resumeImr,
|
|
27
|
+
cancelRequest,
|
|
28
|
+
dock,
|
|
29
|
+
undock
|
|
30
|
+
};
|
|
31
|
+
//# sourceMappingURL=chunk-3JNSIJSX.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/types/actions.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 { PROTOCOL_VERSION, type DockAction } from './constants.js';\nimport type { Uuid } from './common.js';\nimport type { LocationPoint, Orientation } from './ccs.js';\nimport type { RequestDetail } from './requests.js';\n\nexport interface OrientationTolerance { yaw: number; pitch: number; roll: number }\n\nexport interface MoveProps {\n location: LocationPoint;\n orientation?: Orientation; // in examples but not Table C.3 (spec §3.1)\n toleranceRadius?: number;\n orientationTolerance?: OrientationTolerance;\n arrivalTime?: string;\n}\n\nexport interface CancelProps { source: Uuid; requestId: number; actionId?: number }\n\nexport interface DockProps {\n dockLocation: LocationPoint;\n dockId?: Uuid;\n dockActions?: DockAction[];\n toleranceRadius?: number;\n orientationTolerance?: OrientationTolerance;\n}\n\ninterface BuilderOpts { blocking?: boolean; atomic?: boolean; version?: string }\n\n/** Assembles a {@link RequestDetail}, filling in `format`/`version`/`blocking`/`atomic` defaults. */\nfunction detail(type: string, properties: Record<string, unknown>, opts: BuilderOpts = {}): RequestDetail {\n return {\n type,\n version: opts.version ?? PROTOCOL_VERSION,\n format: 'ISO-21423',\n blocking: opts.blocking ?? true,\n atomic: opts.atomic ?? false,\n properties,\n };\n}\n\nexport const move = (props: MoveProps, opts?: BuilderOpts): RequestDetail =>\n detail('move', { ...props }, opts);\nexport const pauseImr = (opts?: BuilderOpts): RequestDetail => detail('pauseImr', {}, opts);\nexport const resumeImr = (opts?: BuilderOpts): RequestDetail => detail('resumeImr', {}, opts);\n/** Builds a `cancelRequest` action detail targeting a previously-sent request/action by id. */\nexport const cancelRequest = (props: CancelProps, opts?: BuilderOpts): RequestDetail =>\n detail('cancelRequest', { ...props }, opts);\nexport const dock = (props: DockProps, opts?: BuilderOpts): RequestDetail =>\n detail('dock', { ...props }, opts);\nexport const undock = (opts?: BuilderOpts): RequestDetail => detail('undock', {}, opts);\n"],"mappings":";;;;;AA4CA,SAAS,OAAO,MAAc,YAAqC,OAAoB,CAAC,GAAkB;AACxG,SAAO;AAAA,IACL;AAAA,IACA,SAAS,KAAK,WAAW;AAAA,IACzB,QAAQ;AAAA,IACR,UAAU,KAAK,YAAY;AAAA,IAC3B,QAAQ,KAAK,UAAU;AAAA,IACvB;AAAA,EACF;AACF;AAEO,IAAM,OAAO,CAAC,OAAkB,SACrC,OAAO,QAAQ,EAAE,GAAG,MAAM,GAAG,IAAI;AAC5B,IAAM,WAAW,CAAC,SAAsC,OAAO,YAAY,CAAC,GAAG,IAAI;AACnF,IAAM,YAAY,CAAC,SAAsC,OAAO,aAAa,CAAC,GAAG,IAAI;AAErF,IAAM,gBAAgB,CAAC,OAAoB,SAChD,OAAO,iBAAiB,EAAE,GAAG,MAAM,GAAG,IAAI;AACrC,IAAM,OAAO,CAAC,OAAkB,SACrC,OAAO,QAAQ,EAAE,GAAG,MAAM,GAAG,IAAI;AAC5B,IAAM,SAAS,CAAC,SAAsC,OAAO,UAAU,CAAC,GAAG,IAAI;","names":[]}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import {
|
|
2
|
+
ROOT_NAMESPACE
|
|
3
|
+
} from "./chunk-RD7PYTIT.js";
|
|
4
|
+
|
|
5
|
+
// src/topics/topics.ts
|
|
6
|
+
function topicFor(ref, resource) {
|
|
7
|
+
return `${ROOT_NAMESPACE}/${ref.entityType}/${ref.entityUuid}/${resource}`;
|
|
8
|
+
}
|
|
9
|
+
function requestTopic(ref, requestUuid) {
|
|
10
|
+
return `${topicFor(ref, "request")}/${requestUuid}`;
|
|
11
|
+
}
|
|
12
|
+
function requestStatusTopic(ref, requestUuid) {
|
|
13
|
+
return `${requestTopic(ref, requestUuid)}/status`;
|
|
14
|
+
}
|
|
15
|
+
function disconnectionTopic(ref) {
|
|
16
|
+
return topicFor(ref, "disconnection");
|
|
17
|
+
}
|
|
18
|
+
function identityWildcard() {
|
|
19
|
+
return `${ROOT_NAMESPACE}/+/+/identity`;
|
|
20
|
+
}
|
|
21
|
+
function parseTopic(topic) {
|
|
22
|
+
if (!topic.startsWith(`${ROOT_NAMESPACE}/`)) return null;
|
|
23
|
+
const rest = topic.slice(ROOT_NAMESPACE.length + 1).split("/");
|
|
24
|
+
const [entityType, entityUuid, resource, ...tail] = rest;
|
|
25
|
+
if (!entityType || !entityUuid || !resource) return null;
|
|
26
|
+
if (resource === "request" && tail.length >= 1) {
|
|
27
|
+
const [requestUuid, maybeStatus] = tail;
|
|
28
|
+
if (!requestUuid || maybeStatus !== void 0 && maybeStatus !== "status" || tail.length > 2) return null;
|
|
29
|
+
return { entityType, entityUuid, resource, requestUuid, isRequestStatus: maybeStatus === "status" };
|
|
30
|
+
}
|
|
31
|
+
if (tail.length > 0) return null;
|
|
32
|
+
return { entityType, entityUuid, resource, isRequestStatus: false };
|
|
33
|
+
}
|
|
34
|
+
function topicFilterMatches(filter, topic) {
|
|
35
|
+
const f = filter.split("/");
|
|
36
|
+
const t = topic.split("/");
|
|
37
|
+
for (let i = 0; i < f.length; i++) {
|
|
38
|
+
const seg = f[i];
|
|
39
|
+
if (seg === "#") return true;
|
|
40
|
+
if (i >= t.length) return false;
|
|
41
|
+
if (seg !== "+" && seg !== t[i]) return false;
|
|
42
|
+
}
|
|
43
|
+
return f.length === t.length;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export {
|
|
47
|
+
topicFor,
|
|
48
|
+
requestTopic,
|
|
49
|
+
requestStatusTopic,
|
|
50
|
+
disconnectionTopic,
|
|
51
|
+
identityWildcard,
|
|
52
|
+
parseTopic,
|
|
53
|
+
topicFilterMatches
|
|
54
|
+
};
|
|
55
|
+
//# sourceMappingURL=chunk-5ZIUSUHF.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/topics/topics.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 { ROOT_NAMESPACE } from '../types/constants.js';\n\n/** Identifies an entity for topic-building purposes: its ISO type (\"IMR\"/\"IMRFM\") and its uuid. */\nexport interface EntityRef { entityType: string; entityUuid: string }\n\n/** Decomposed form of an ISO 21423 topic string, as produced by {@link parseTopic}. */\nexport interface ParsedTopic {\n entityType: string;\n entityUuid: string;\n resource: string;\n requestUuid?: string;\n isRequestStatus: boolean;\n}\n\nexport function topicFor(ref: EntityRef, resource: string): string {\n return `${ROOT_NAMESPACE}/${ref.entityType}/${ref.entityUuid}/${resource}`;\n}\n\nexport function requestTopic(ref: EntityRef, requestUuid: string): string {\n return `${topicFor(ref, 'request')}/${requestUuid}`;\n}\n\nexport function requestStatusTopic(ref: EntityRef, requestUuid: string): string {\n return `${requestTopic(ref, requestUuid)}/status`;\n}\n\nexport function disconnectionTopic(ref: EntityRef): string {\n return topicFor(ref, 'disconnection');\n}\n\n/** MQTT wildcard subscription matching every entity's identity topic, used to build the fleet-wide entity cache. */\nexport function identityWildcard(): string {\n return `${ROOT_NAMESPACE}/+/+/identity`;\n}\n\n/**\n * Splits a concrete topic string into its parts, or returns `null` if it doesn't\n * live under {@link ROOT_NAMESPACE} or has an unrecognized shape (e.g. extra path segments).\n */\nexport function parseTopic(topic: string): ParsedTopic | null {\n if (!topic.startsWith(`${ROOT_NAMESPACE}/`)) return null;\n const rest = topic.slice(ROOT_NAMESPACE.length + 1).split('/');\n const [entityType, entityUuid, resource, ...tail] = rest;\n if (!entityType || !entityUuid || !resource) return null;\n if (resource === 'request' && tail.length >= 1) {\n const [requestUuid, maybeStatus] = tail;\n if (!requestUuid || (maybeStatus !== undefined && maybeStatus !== 'status') || tail.length > 2) return null;\n return { entityType, entityUuid, resource, requestUuid, isRequestStatus: maybeStatus === 'status' };\n }\n if (tail.length > 0) return null;\n return { entityType, entityUuid, resource, isRequestStatus: false };\n}\n\n/** MQTT 3.1.1 topic filter matching (+ single level, # multi level). */\nexport function topicFilterMatches(filter: string, topic: string): boolean {\n const f = filter.split('/');\n const t = topic.split('/');\n for (let i = 0; i < f.length; i++) {\n const seg = f[i];\n if (seg === '#') return true;\n if (i >= t.length) return false;\n if (seg !== '+' && seg !== t[i]) return false;\n }\n return f.length === t.length;\n}\n"],"mappings":";;;;;AA8BO,SAAS,SAAS,KAAgB,UAA0B;AACjE,SAAO,GAAG,cAAc,IAAI,IAAI,UAAU,IAAI,IAAI,UAAU,IAAI,QAAQ;AAC1E;AAEO,SAAS,aAAa,KAAgB,aAA6B;AACxE,SAAO,GAAG,SAAS,KAAK,SAAS,CAAC,IAAI,WAAW;AACnD;AAEO,SAAS,mBAAmB,KAAgB,aAA6B;AAC9E,SAAO,GAAG,aAAa,KAAK,WAAW,CAAC;AAC1C;AAEO,SAAS,mBAAmB,KAAwB;AACzD,SAAO,SAAS,KAAK,eAAe;AACtC;AAGO,SAAS,mBAA2B;AACzC,SAAO,GAAG,cAAc;AAC1B;AAMO,SAAS,WAAW,OAAmC;AAC5D,MAAI,CAAC,MAAM,WAAW,GAAG,cAAc,GAAG,EAAG,QAAO;AACpD,QAAM,OAAO,MAAM,MAAM,eAAe,SAAS,CAAC,EAAE,MAAM,GAAG;AAC7D,QAAM,CAAC,YAAY,YAAY,UAAU,GAAG,IAAI,IAAI;AACpD,MAAI,CAAC,cAAc,CAAC,cAAc,CAAC,SAAU,QAAO;AACpD,MAAI,aAAa,aAAa,KAAK,UAAU,GAAG;AAC9C,UAAM,CAAC,aAAa,WAAW,IAAI;AACnC,QAAI,CAAC,eAAgB,gBAAgB,UAAa,gBAAgB,YAAa,KAAK,SAAS,EAAG,QAAO;AACvG,WAAO,EAAE,YAAY,YAAY,UAAU,aAAa,iBAAiB,gBAAgB,SAAS;AAAA,EACpG;AACA,MAAI,KAAK,SAAS,EAAG,QAAO;AAC5B,SAAO,EAAE,YAAY,YAAY,UAAU,iBAAiB,MAAM;AACpE;AAGO,SAAS,mBAAmB,QAAgB,OAAwB;AACzE,QAAM,IAAI,OAAO,MAAM,GAAG;AAC1B,QAAM,IAAI,MAAM,MAAM,GAAG;AACzB,WAAS,IAAI,GAAG,IAAI,EAAE,QAAQ,KAAK;AACjC,UAAM,MAAM,EAAE,CAAC;AACf,QAAI,QAAQ,IAAK,QAAO;AACxB,QAAI,KAAK,EAAE,OAAQ,QAAO;AAC1B,QAAI,QAAQ,OAAO,QAAQ,EAAE,CAAC,EAAG,QAAO;AAAA,EAC1C;AACA,SAAO,EAAE,WAAW,EAAE;AACxB;","names":[]}
|