@avatarsd-llc/libtracer-client 0.3.0 → 0.5.0

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 CHANGED
@@ -1,6 +1,7 @@
1
1
  # @avatarsd-llc/libtracer-client (EXPERIMENTAL)
2
2
 
3
- The libtracer **client SDK** the strawberry web-UI builds against
3
+ The libtracer **client SDK** that the web-UI of the originating production
4
+ firmware (an ESP32-C6 smart-agriculture node) builds against
4
5
  ([#56](https://github.com/avatarsd-llc/libtracer/issues/56),
5
6
  [ADR-0034](../../../../docs/adr/0034-typescript-client-sdk.md) /
6
7
  [ADR-0035](../../../../docs/adr/0035-implementing-rfc-0004-remote-operation-addressing.md)).
package/dist/client.d.ts CHANGED
@@ -2,60 +2,63 @@ import type { Tlv } from '@avatarsd-llc/libtracer';
2
2
  import type { ValueOptions, SubscriberOptions } from './tlv.js';
3
3
  import type { FieldLevel } from './fwd.js';
4
4
  /**
5
- * The minimal connection seam the client drives. `TransportWs` from
6
- * `@avatarsd-llc/libtracer-ws` satisfies this structurally (so the client never
7
- * imports it — keeping the transport an optional peer).
5
+ * @brief The minimal connection seam the client drives.
6
+ *
7
+ * `TransportWs` from `@avatarsd-llc/libtracer-ws` satisfies this structurally
8
+ * (so the client never imports it — keeping the transport an optional peer).
8
9
  */
9
10
  export interface ClientTransport {
10
- /** Put one complete libtracer TLV frame on the wire. */
11
+ /** @brief Put one complete libtracer TLV frame on the wire. */
11
12
  send(frame: Uint8Array): void;
12
- /** Register (or clear with `null`) the inbound-frame receiver. */
13
+ /** @brief Register (or clear with `null`) the inbound-frame receiver. */
13
14
  onFrame(receiver: ((bytes: Uint8Array) => void) | null): void;
14
15
  /**
15
- * Register (or clear with `null`) the connection-closed notifier — invoked once
16
+ * @brief Register (or clear with `null`) the connection-closed notifier — invoked once
16
17
  * when the underlying connection closes or errors out, with the cause when one
17
18
  * is known. OPTIONAL: a transport without it never notifies the client of a
18
19
  * close, so pending requests only fail by timeout.
19
20
  */
20
21
  onClose?(handler: ((cause?: Error) => void) | null): void;
21
22
  }
22
- /** A delivered VALUE: its opaque payload bytes plus the decoded TLV it came from. */
23
+ /** @brief A delivered VALUE: its opaque payload bytes plus the decoded TLV it came from. */
23
24
  export type ValueHandler = (value: Uint8Array, tlv: Tlv) => void;
24
- /** Detach a {@link LibtracerClient.subscribe} handler (a local detach — see its docs). */
25
+ /** @brief Detach a {@link LibtracerClient.subscribe} handler (a local detach — see its docs). */
25
26
  export type Unsubscribe = () => void;
26
- /** Options for {@link LibtracerClient}. */
27
+ /** @brief Options for {@link LibtracerClient}. */
27
28
  export interface ClientOptions {
28
29
  /**
29
- * The originator's reply endpoint, as path segments — the `src` route seeded on
30
+ * @brief The originator's reply endpoint, as path segments — the `src` route seeded on
30
31
  * every outbound FWD and the SUBSCRIBER `target` on a subscribe. Over a single
31
32
  * ws hop the responder replies back over the same link, so any 1+-segment path
32
33
  * is fine; default `["client"]`.
33
34
  */
34
35
  readonly replyEndpoint?: string[];
35
36
  /**
36
- * Per-request deadline in milliseconds: a one-shot op whose FWD{REPLY} has not
37
+ * @brief Per-request deadline in milliseconds: a one-shot op whose FWD{REPLY} has not
37
38
  * arrived within this window rejects with a timeout {@link Error}. Default
38
39
  * 10 000 ms; pass `0` (or `Infinity`) to disable the deadline.
39
40
  */
40
41
  readonly requestTimeoutMs?: number;
41
42
  }
42
43
  /**
43
- * A `kind=ERROR` FWD reply, surfaced as a typed rejection. `.code` is the
44
- * registered u16 wire ERROR code (see {@link FWD_ERROR}); `.codeName` its
45
- * symbolic name.
44
+ * @brief A `kind=ERROR` FWD reply, surfaced as a typed rejection.
45
+ *
46
+ * `.code` is the registered u16 wire ERROR code (see {@link FWD_ERROR});
47
+ * `.codeName` its symbolic name.
46
48
  */
47
49
  export declare class FwdError extends Error {
48
- /** The registered u16 wire ERROR code (a {@link FWD_ERROR} value). */
50
+ /** @brief The registered u16 wire ERROR code (a {@link FWD_ERROR} value). */
49
51
  readonly code: number;
50
- /** The symbolic ERROR name (e.g. `"NOT_FOUND"`, `"TIMEOUT"`). */
52
+ /** @brief The symbolic ERROR name (e.g. `"NOT_FOUND"`, `"TIMEOUT"`). */
51
53
  readonly codeName: string;
52
54
  /**
53
- * The canonical `tr::<concept>::<error>` namespace path (RFC-0002 §A) — from
55
+ * @brief The canonical `tr::<concept>::<error>` namespace path (RFC-0002 §A) — from
54
56
  * the frozen registry for a registered code, or carried verbatim by a
55
57
  * string-form (NAME identity) ERROR reply. `null` when neither is known.
56
58
  */
57
59
  readonly path: string | null;
58
60
  /**
61
+ * @brief Build the typed rejection from either wire identity form.
59
62
  * @param code the registered u16 code carried in the reply's
60
63
  * `STATUS{ ERROR{ VALUE u16 } }` per RFC-0002 (0 when absent)
61
64
  * @param path the string-form `tr::…` identity when the reply carried a
@@ -64,19 +67,25 @@ export declare class FwdError extends Error {
64
67
  constructor(code: number, path?: string | null);
65
68
  }
66
69
  /**
67
- * An inbound ADVERTISE (`0x11`) / COMPACT (`0x12`) frame reached this client,
68
- * which does not implement the RFC-0004 compact (route-handle) delivery flow
69
- * yet. Routed to {@link LibtracerClient.onError} so the failure is diagnosable
70
+ * @brief An inbound ADVERTISE (`0x11`) / COMPACT (`0x12`) frame reached this
71
+ * client, which does not implement the RFC-0004 compact (route-handle) delivery
72
+ * flow yet.
73
+ *
74
+ * Routed to {@link LibtracerClient.onError} so the failure is diagnosable
70
75
  * instead of a silent drop; the sender should fall back to plain FWD delivery.
71
76
  */
72
77
  export declare class CompactFlowError extends Error {
73
- /** The offending wire type code (`0x11` ADVERTISE or `0x12` COMPACT). */
78
+ /** @brief The offending wire type code (`0x11` ADVERTISE or `0x12` COMPACT). */
74
79
  readonly frameType: number;
75
- /** @param frameType the inbound frame's wire type code */
80
+ /**
81
+ * @brief Name the offending frame kind in the error message.
82
+ * @param frameType the inbound frame's wire type code
83
+ */
76
84
  constructor(frameType: number);
77
85
  }
78
86
  /**
79
- * A WebSocket/transport-agnostic libtracer client over the RFC-0004 `FWD` plane.
87
+ * @brief A WebSocket/transport-agnostic libtracer client over the RFC-0004
88
+ * `FWD` plane.
80
89
  *
81
90
  * Construct over any {@link ClientTransport}; issue {@link read} / {@link write} /
82
91
  * {@link await_} / {@link readField} (resolving the responder's FWD{REPLY}), or
@@ -93,30 +102,33 @@ export declare class LibtracerClient {
93
102
  private errorHandler;
94
103
  private closed;
95
104
  /**
105
+ * @brief Bind to the injected transport and start receiving frames.
96
106
  * @param transport the injected connection seam (e.g. a connected `TransportWs`).
97
107
  * @param options optional reply-endpoint / request-timeout overrides.
98
108
  */
99
109
  constructor(transport: ClientTransport, options?: ClientOptions);
100
- /** Reject every pending request when the transport closes; fail-fast afterwards. */
110
+ /** @brief Reject every pending request when the transport closes; fail-fast afterwards. */
101
111
  private handleClose;
102
112
  /**
103
- * Register a handler for inbound VALUE deliveries. A delivery is a FWD{WRITE}
104
- * (delivery-is-a-write, RFC-0004 §D); a bare VALUE or a single ROUTER wrapper is
105
- * also accepted. Multiple handlers may be registered; each receives every delivery.
113
+ * @brief Register a handler for inbound VALUE deliveries.
114
+ *
115
+ * A delivery is a FWD{WRITE} (delivery-is-a-write, RFC-0004 §D); a bare VALUE
116
+ * or a single ROUTER wrapper is also accepted. Multiple handlers may be
117
+ * registered; each receives every delivery.
106
118
  */
107
119
  onValue(handler: ValueHandler): void;
108
- /** Register the sink for inbound decode failures and other client-side errors. */
120
+ /** @brief Register the sink for inbound decode failures and other client-side errors. */
109
121
  onError(handler: (err: Error) => void): void;
110
- /** Decode one inbound frame: correlate a REPLY, deliver a write, or shed/deliver a VALUE. */
122
+ /** @brief Decode one inbound frame: correlate a REPLY, deliver a write, or shed/deliver a VALUE. */
111
123
  private dispatch;
112
124
  private deliver;
113
125
  private emitError;
114
- /** Send a one-shot FWD and resolve its FWD{REPLY} (FIFO correlation). */
126
+ /** @brief Send a one-shot FWD and resolve its FWD{REPLY} (FIFO correlation). */
115
127
  private request;
116
- /** Turn a RESULT reply into its payload TLV; throw {@link FwdError} on ERROR. */
128
+ /** @brief Turn a RESULT reply into its payload TLV; throw {@link FwdError} on ERROR. */
117
129
  private result;
118
130
  /**
119
- * Read a remote vertex's value: `FWD{ op=READ, dst=path, src=<reply-ep> }`.
131
+ * @brief Read a remote vertex's value: `FWD{ op=READ, dst=path, src=<reply-ep> }`.
120
132
  *
121
133
  * @param path the destination path (a `/`-string like `"/sensor/temp"`, or segments)
122
134
  * @returns the RESULT's value TLV (decoded)
@@ -124,7 +136,9 @@ export declare class LibtracerClient {
124
136
  */
125
137
  read(path: string | string[]): Promise<Tlv>;
126
138
  /**
127
- * Read a remote vertex's `:field`: `FWD{ op=READ, dst=path, FIELD=selector, src=… }`.
139
+ * @brief Read a remote vertex's `:field`: `FWD{ op=READ, dst=path,
140
+ * FIELD=selector, src=… }`.
141
+ *
128
142
  * A whole-array field (e.g. `:subscribers[]`) resolves to a POINT of the slot TLVs.
129
143
  *
130
144
  * @param path the destination path (string or segments)
@@ -134,7 +148,7 @@ export declare class LibtracerClient {
134
148
  */
135
149
  readField(path: string | string[], selector: string | FieldLevel[]): Promise<Tlv>;
136
150
  /**
137
- * Write a value to a remote vertex: `FWD{ op=WRITE, dst=path, src=…, payload }`.
151
+ * @brief Write a value to a remote vertex: `FWD{ op=WRITE, dst=path, src=…, payload }`.
138
152
  *
139
153
  * @param path the destination path (string or segments)
140
154
  * @param valueTLV a complete VALUE TLV's bytes (e.g. from {@link encodeValue})
@@ -143,9 +157,32 @@ export declare class LibtracerClient {
143
157
  */
144
158
  write(path: string | string[], valueTLV: Uint8Array): Promise<void>;
145
159
  /**
146
- * Block for the next write to a remote vertex: `FWD{ op=AWAIT, dst=path, src=…,
147
- * await_timeout? }`. Named `await_` because `await` is reserved; an `await`
148
- * alias is installed on the prototype for the RFC-0004-spelled call site.
160
+ * @brief Write into a remote vertex's FIELD: `FWD{ op=WRITE, dst=path, field=selector,
161
+ * src=…, payload }` — the write counterpart of {@link readField}.
162
+ *
163
+ * The append form (`":children[]"` — a whole-array ELEMENT selector with no index) is
164
+ * how a vertex is CREATED in band: `writeField('/net', ':children[]', encodeConnSpec(…))`
165
+ * brings a transport link up on a remote device (ADR-0017 / ADR-0027, reference/13 §2),
166
+ * and `writeField('/sensor/temp', ':subscribers[]', encodeSubscriber(…))` binds a
167
+ * consumer-initiated subscription (ADR-0026). Neither was expressible from this client
168
+ * before: {@link write} takes no selector, so every field-addressed write — the entire
169
+ * in-band formation plane — was out of reach.
170
+ *
171
+ * Vector-pinned by `fwd-write-subscriber-field`.
172
+ *
173
+ * @param path the destination path (string or segments)
174
+ * @param selector the field selector (e.g. `":children[]"`, or parsed {@link FieldLevel}s)
175
+ * @param valueTLV a complete payload TLV's bytes (e.g. from {@link encodeConnSpec})
176
+ * @returns once the responder acks `kind=RESULT`
177
+ * @throws {FwdError} when the responder replies `kind=ERROR`
178
+ */
179
+ writeField(path: string | string[], selector: string | FieldLevel[], valueTLV: Uint8Array): Promise<void>;
180
+ /**
181
+ * @brief Block for the next write to a remote vertex: `FWD{ op=AWAIT,
182
+ * dst=path, src=…, await_timeout? }`.
183
+ *
184
+ * Named `await_` because `await` is reserved; an `await` alias is installed
185
+ * on the prototype for the RFC-0004-spelled call site.
149
186
  *
150
187
  * @param path the destination path (string or segments)
151
188
  * @param timeoutNs the await timeout in ns (absent ⇒ the responder's 1 s default)
@@ -154,8 +191,10 @@ export declare class LibtracerClient {
154
191
  */
155
192
  await_(path: string | string[], timeoutNs?: bigint): Promise<Tlv>;
156
193
  /**
157
- * Subscribe to a remote producer: a `WRITE` of a `SUBSCRIBER{ target=<reply-ep> }`
158
- * into `producer:subscribers[]` (RFC-0004 §C/§D — subscribe is a field-write).
194
+ * @brief Subscribe to a remote producer: a `WRITE` of a `SUBSCRIBER{
195
+ * target=<reply-ep> }` into `producer:subscribers[]` (RFC-0004 §C/§D —
196
+ * subscribe is a field-write).
197
+ *
159
198
  * Once the responder acks, `handler` fires for every inbound VALUE delivery.
160
199
  *
161
200
  * SCOPE: this issues the SUBSCRIBER and receives VALUEs the producer directly
@@ -171,10 +210,10 @@ export declare class LibtracerClient {
171
210
  * @throws {FwdError} when the subscribe-write is rejected
172
211
  */
173
212
  subscribe(producerPath: string | string[], handler: ValueHandler): Promise<Unsubscribe>;
174
- /** {@link encodeValue} — the exact VALUE TLV bytes, independently of any transport. */
213
+ /** @brief {@link encodeValue} — the exact VALUE TLV bytes, independently of any transport. */
175
214
  static encodeValue(value: Uint8Array, opts?: ValueOptions): Uint8Array;
176
- /** {@link encodePath} — the exact PATH TLV bytes. */
215
+ /** @brief {@link encodePath} — the exact PATH TLV bytes. */
177
216
  static encodePath(segments: string[]): Uint8Array;
178
- /** {@link encodeSubscriber} — the exact SUBSCRIBER TLV bytes. */
217
+ /** @brief {@link encodeSubscriber} — the exact SUBSCRIBER TLV bytes. */
179
218
  static encodeSubscriber(targetPath: string[], opts?: SubscriberOptions): Uint8Array;
180
219
  }
package/dist/client.js CHANGED
@@ -1,37 +1,42 @@
1
1
  // SPDX-License-Identifier: Apache-2.0
2
2
  // SPDX-FileCopyrightText: Copyright 2026 avatarsd LLC
3
- // LibtracerClient — the experimental browser/Node client SDK (#56, ADR-0034).
4
- //
5
- // It composes the cross-validated codec (@avatarsd-llc/libtracer) over an
6
- // INJECTED transport seam (`@avatarsd-llc/libtracer-ws`'s TransportWs satisfies
7
- // it structurally), so it is browser/Node-agnostic and testable against an
8
- // in-memory fake with no live socket.
9
- //
10
- // Now that RFC-0004 fills spec §3 (the remote-operation envelope ADR-0034
11
- // deferred), the client speaks the path-addressed higher operations over `FWD`:
12
- // - read(path) — FWD{ op=READ, dst=path, src=<reply-ep> }
13
- // - write(path, valueTLV) — FWD{ op=WRITE, dst=path, src=…, payload }
14
- // - await(path, ns?) — FWD{ op=AWAIT, dst=path, src=…, await_timeout? }
15
- // - readField(path, sel) — FWD{ op=READ, dst=path, FIELD=sel, src=… }
16
- // - subscribe(prod, h) — FWD{ op=WRITE, dst=prod, FIELD=:subscribers[],
17
- // src=…, payload=SUBSCRIBER{ target=<reply-ep> } }
18
- // Each one-shot op sends a FWD and resolves the FWD{REPLY} the responder
19
- // source-routes back (RESULT → the value, ERROR → a typed {@link FwdError}).
20
- //
21
- // Reply correlation is the transport's concern (RFC-0004 §D): over a single ws
22
- // link the responder replies in request order, so a simple per-link FIFO of
23
- // pending requests matches each REPLY to its request. `FWD` stays pure — no
24
- // end-to-end correlation id.
3
+ /**
4
+ * @brief LibtracerClient — the experimental browser/Node client SDK (#56,
5
+ * ADR-0034).
6
+ *
7
+ * It composes the cross-validated codec (@avatarsd-llc/libtracer) over an
8
+ * INJECTED transport seam (`@avatarsd-llc/libtracer-ws`'s TransportWs satisfies
9
+ * it structurally), so it is browser/Node-agnostic and testable against an
10
+ * in-memory fake with no live socket.
11
+ *
12
+ * Now that RFC-0004 fills spec §3 (the remote-operation envelope ADR-0034
13
+ * deferred), the client speaks the path-addressed higher operations over `FWD`:
14
+ * - read(path) — FWD{ op=READ, dst=path, src=<reply-ep> }
15
+ * - write(path, valueTLV) — FWD{ op=WRITE, dst=path, src=…, payload }
16
+ * - await(path, ns?) — FWD{ op=AWAIT, dst=path, src=…, await_timeout? }
17
+ * - readField(path, sel) — FWD{ op=READ, dst=path, FIELD=sel, src=… }
18
+ * - subscribe(prod, h) — FWD{ op=WRITE, dst=prod, FIELD=:subscribers[],
19
+ * src=…, payload=SUBSCRIBER{ target=<reply-ep> } }
20
+ * Each one-shot op sends a FWD and resolves the FWD{REPLY} the responder
21
+ * source-routes back (RESULT → the value, ERROR → a typed {@link FwdError}).
22
+ *
23
+ * Reply correlation is the transport's concern (RFC-0004 §D): over a single ws
24
+ * link the responder replies in request order, so a simple per-link FIFO of
25
+ * pending requests matches each REPLY to its request. `FWD` stays pure — no
26
+ * end-to-end correlation id.
27
+ */
25
28
  import { TYPE, decode, CodecError } from '@avatarsd-llc/libtracer';
26
29
  import { encodeValue, encodePath, encodeSubscriber } from './tlv.js';
27
30
  import { FWD_OP, FWD_KIND, encodeFwd, parseFwdTlv, replyErrorCode, replyErrorPath, fwdErrorName, fwdErrorPath, fwdErrorCodeForPath, } from './fwd.js';
28
31
  /**
29
- * A `kind=ERROR` FWD reply, surfaced as a typed rejection. `.code` is the
30
- * registered u16 wire ERROR code (see {@link FWD_ERROR}); `.codeName` its
31
- * symbolic name.
32
+ * @brief A `kind=ERROR` FWD reply, surfaced as a typed rejection.
33
+ *
34
+ * `.code` is the registered u16 wire ERROR code (see {@link FWD_ERROR});
35
+ * `.codeName` its symbolic name.
32
36
  */
33
37
  export class FwdError extends Error {
34
38
  /**
39
+ * @brief Build the typed rejection from either wire identity form.
35
40
  * @param code the registered u16 code carried in the reply's
36
41
  * `STATUS{ ERROR{ VALUE u16 } }` per RFC-0002 (0 when absent)
37
42
  * @param path the string-form `tr::…` identity when the reply carried a
@@ -50,18 +55,23 @@ export class FwdError extends Error {
50
55
  this.path = trPath;
51
56
  }
52
57
  }
53
- /** ADVERTISE (`0x11`) — a route-handle label binding (RFC-0004 route handles). */
58
+ /** @brief ADVERTISE (`0x11`) — a route-handle label binding (RFC-0004 route handles). */
54
59
  const TYPE_ADVERTISE = 0x11;
55
- /** COMPACT (`0x12`) — a label-compacted delivery (RFC-0004 route handles). */
60
+ /** @brief COMPACT (`0x12`) — a label-compacted delivery (RFC-0004 route handles). */
56
61
  const TYPE_COMPACT = 0x12;
57
62
  /**
58
- * An inbound ADVERTISE (`0x11`) / COMPACT (`0x12`) frame reached this client,
59
- * which does not implement the RFC-0004 compact (route-handle) delivery flow
60
- * yet. Routed to {@link LibtracerClient.onError} so the failure is diagnosable
63
+ * @brief An inbound ADVERTISE (`0x11`) / COMPACT (`0x12`) frame reached this
64
+ * client, which does not implement the RFC-0004 compact (route-handle) delivery
65
+ * flow yet.
66
+ *
67
+ * Routed to {@link LibtracerClient.onError} so the failure is diagnosable
61
68
  * instead of a silent drop; the sender should fall back to plain FWD delivery.
62
69
  */
63
70
  export class CompactFlowError extends Error {
64
- /** @param frameType the inbound frame's wire type code */
71
+ /**
72
+ * @brief Name the offending frame kind in the error message.
73
+ * @param frameType the inbound frame's wire type code
74
+ */
65
75
  constructor(frameType) {
66
76
  const kind = frameType === TYPE_ADVERTISE ? 'ADVERTISE' : 'COMPACT';
67
77
  super(`inbound ${kind} (0x${frameType.toString(16).padStart(2, '0')}) dropped: ` +
@@ -70,7 +80,7 @@ export class CompactFlowError extends Error {
70
80
  this.frameType = frameType;
71
81
  }
72
82
  }
73
- /** Settle a pending entry: clear its deadline and mark it consumed. */
83
+ /** @brief Settle a pending entry: clear its deadline and mark it consumed. */
74
84
  function settle(p) {
75
85
  p.settled = true;
76
86
  if (p.timer !== null) {
@@ -79,7 +89,8 @@ function settle(p) {
79
89
  }
80
90
  }
81
91
  /**
82
- * A WebSocket/transport-agnostic libtracer client over the RFC-0004 `FWD` plane.
92
+ * @brief A WebSocket/transport-agnostic libtracer client over the RFC-0004
93
+ * `FWD` plane.
83
94
  *
84
95
  * Construct over any {@link ClientTransport}; issue {@link read} / {@link write} /
85
96
  * {@link await_} / {@link readField} (resolving the responder's FWD{REPLY}), or
@@ -89,6 +100,7 @@ function settle(p) {
89
100
  */
90
101
  export class LibtracerClient {
91
102
  /**
103
+ * @brief Bind to the injected transport and start receiving frames.
92
104
  * @param transport the injected connection seam (e.g. a connected `TransportWs`).
93
105
  * @param options optional reply-endpoint / request-timeout overrides.
94
106
  */
@@ -103,7 +115,7 @@ export class LibtracerClient {
103
115
  transport.onFrame((bytes) => this.dispatch(bytes));
104
116
  transport.onClose?.((cause) => this.handleClose(cause));
105
117
  }
106
- /** Reject every pending request when the transport closes; fail-fast afterwards. */
118
+ /** @brief Reject every pending request when the transport closes; fail-fast afterwards. */
107
119
  handleClose(cause) {
108
120
  this.closed = new Error('transport closed' + (cause ? `: ${cause.message}` : ''));
109
121
  for (const p of this.pending) {
@@ -116,18 +128,20 @@ export class LibtracerClient {
116
128
  }
117
129
  /* ---------------------------------------------------------- inbound --- */
118
130
  /**
119
- * Register a handler for inbound VALUE deliveries. A delivery is a FWD{WRITE}
120
- * (delivery-is-a-write, RFC-0004 §D); a bare VALUE or a single ROUTER wrapper is
121
- * also accepted. Multiple handlers may be registered; each receives every delivery.
131
+ * @brief Register a handler for inbound VALUE deliveries.
132
+ *
133
+ * A delivery is a FWD{WRITE} (delivery-is-a-write, RFC-0004 §D); a bare VALUE
134
+ * or a single ROUTER wrapper is also accepted. Multiple handlers may be
135
+ * registered; each receives every delivery.
122
136
  */
123
137
  onValue(handler) {
124
138
  this.valueHandlers.add(handler);
125
139
  }
126
- /** Register the sink for inbound decode failures and other client-side errors. */
140
+ /** @brief Register the sink for inbound decode failures and other client-side errors. */
127
141
  onError(handler) {
128
142
  this.errorHandler = handler;
129
143
  }
130
- /** Decode one inbound frame: correlate a REPLY, deliver a write, or shed/deliver a VALUE. */
144
+ /** @brief Decode one inbound frame: correlate a REPLY, deliver a write, or shed/deliver a VALUE. */
131
145
  dispatch(bytes) {
132
146
  let tlv;
133
147
  try {
@@ -182,7 +196,7 @@ export class LibtracerClient {
182
196
  if (this.errorHandler)
183
197
  this.errorHandler(err);
184
198
  }
185
- /** Send a one-shot FWD and resolve its FWD{REPLY} (FIFO correlation). */
199
+ /** @brief Send a one-shot FWD and resolve its FWD{REPLY} (FIFO correlation). */
186
200
  request(frame) {
187
201
  return new Promise((resolve, reject) => {
188
202
  if (this.closed) {
@@ -211,7 +225,7 @@ export class LibtracerClient {
211
225
  }
212
226
  });
213
227
  }
214
- /** Turn a RESULT reply into its payload TLV; throw {@link FwdError} on ERROR. */
228
+ /** @brief Turn a RESULT reply into its payload TLV; throw {@link FwdError} on ERROR. */
215
229
  result(reply) {
216
230
  if (reply.kind === FWD_KIND.ERROR) {
217
231
  // Registered-code and string-form (NAME tr::… path) identities both
@@ -222,7 +236,7 @@ export class LibtracerClient {
222
236
  }
223
237
  /* --------------------------------------------------------- one-shot --- */
224
238
  /**
225
- * Read a remote vertex's value: `FWD{ op=READ, dst=path, src=<reply-ep> }`.
239
+ * @brief Read a remote vertex's value: `FWD{ op=READ, dst=path, src=<reply-ep> }`.
226
240
  *
227
241
  * @param path the destination path (a `/`-string like `"/sensor/temp"`, or segments)
228
242
  * @returns the RESULT's value TLV (decoded)
@@ -236,7 +250,9 @@ export class LibtracerClient {
236
250
  return value;
237
251
  }
238
252
  /**
239
- * Read a remote vertex's `:field`: `FWD{ op=READ, dst=path, FIELD=selector, src=… }`.
253
+ * @brief Read a remote vertex's `:field`: `FWD{ op=READ, dst=path,
254
+ * FIELD=selector, src=… }`.
255
+ *
240
256
  * A whole-array field (e.g. `:subscribers[]`) resolves to a POINT of the slot TLVs.
241
257
  *
242
258
  * @param path the destination path (string or segments)
@@ -252,7 +268,7 @@ export class LibtracerClient {
252
268
  return value;
253
269
  }
254
270
  /**
255
- * Write a value to a remote vertex: `FWD{ op=WRITE, dst=path, src=…, payload }`.
271
+ * @brief Write a value to a remote vertex: `FWD{ op=WRITE, dst=path, src=…, payload }`.
256
272
  *
257
273
  * @param path the destination path (string or segments)
258
274
  * @param valueTLV a complete VALUE TLV's bytes (e.g. from {@link encodeValue})
@@ -264,9 +280,41 @@ export class LibtracerClient {
264
280
  this.result(reply); // throws on ERROR; RESULT carries no payload
265
281
  }
266
282
  /**
267
- * Block for the next write to a remote vertex: `FWD{ op=AWAIT, dst=path, src=…,
268
- * await_timeout? }`. Named `await_` because `await` is reserved; an `await`
269
- * alias is installed on the prototype for the RFC-0004-spelled call site.
283
+ * @brief Write into a remote vertex's FIELD: `FWD{ op=WRITE, dst=path, field=selector,
284
+ * src=…, payload }` — the write counterpart of {@link readField}.
285
+ *
286
+ * The append form (`":children[]"` — a whole-array ELEMENT selector with no index) is
287
+ * how a vertex is CREATED in band: `writeField('/net', ':children[]', encodeConnSpec(…))`
288
+ * brings a transport link up on a remote device (ADR-0017 / ADR-0027, reference/13 §2),
289
+ * and `writeField('/sensor/temp', ':subscribers[]', encodeSubscriber(…))` binds a
290
+ * consumer-initiated subscription (ADR-0026). Neither was expressible from this client
291
+ * before: {@link write} takes no selector, so every field-addressed write — the entire
292
+ * in-band formation plane — was out of reach.
293
+ *
294
+ * Vector-pinned by `fwd-write-subscriber-field`.
295
+ *
296
+ * @param path the destination path (string or segments)
297
+ * @param selector the field selector (e.g. `":children[]"`, or parsed {@link FieldLevel}s)
298
+ * @param valueTLV a complete payload TLV's bytes (e.g. from {@link encodeConnSpec})
299
+ * @returns once the responder acks `kind=RESULT`
300
+ * @throws {FwdError} when the responder replies `kind=ERROR`
301
+ */
302
+ async writeField(path, selector, valueTLV) {
303
+ const reply = await this.request(encodeFwd({
304
+ op: FWD_OP.WRITE,
305
+ dst: splitPath(path),
306
+ field: selector,
307
+ src: this.replyEndpoint,
308
+ payload: valueTLV,
309
+ }));
310
+ this.result(reply); // throws on ERROR; RESULT carries no payload
311
+ }
312
+ /**
313
+ * @brief Block for the next write to a remote vertex: `FWD{ op=AWAIT,
314
+ * dst=path, src=…, await_timeout? }`.
315
+ *
316
+ * Named `await_` because `await` is reserved; an `await` alias is installed
317
+ * on the prototype for the RFC-0004-spelled call site.
270
318
  *
271
319
  * @param path the destination path (string or segments)
272
320
  * @param timeoutNs the await timeout in ns (absent ⇒ the responder's 1 s default)
@@ -286,8 +334,10 @@ export class LibtracerClient {
286
334
  return value;
287
335
  }
288
336
  /**
289
- * Subscribe to a remote producer: a `WRITE` of a `SUBSCRIBER{ target=<reply-ep> }`
290
- * into `producer:subscribers[]` (RFC-0004 §C/§D — subscribe is a field-write).
337
+ * @brief Subscribe to a remote producer: a `WRITE` of a `SUBSCRIBER{
338
+ * target=<reply-ep> }` into `producer:subscribers[]` (RFC-0004 §C/§D —
339
+ * subscribe is a field-write).
340
+ *
291
341
  * Once the responder acks, `handler` fires for every inbound VALUE delivery.
292
342
  *
293
343
  * SCOPE: this issues the SUBSCRIBER and receives VALUEs the producer directly
@@ -327,28 +377,31 @@ export class LibtracerClient {
327
377
  };
328
378
  }
329
379
  /* ------------------------------------------- pure builders (static) --- */
330
- /** {@link encodeValue} — the exact VALUE TLV bytes, independently of any transport. */
380
+ /** @brief {@link encodeValue} — the exact VALUE TLV bytes, independently of any transport. */
331
381
  static encodeValue(value, opts) {
332
382
  return encodeValue(value, opts);
333
383
  }
334
- /** {@link encodePath} — the exact PATH TLV bytes. */
384
+ /** @brief {@link encodePath} — the exact PATH TLV bytes. */
335
385
  static encodePath(segments) {
336
386
  return encodePath(segments);
337
387
  }
338
- /** {@link encodeSubscriber} — the exact SUBSCRIBER TLV bytes. */
388
+ /** @brief {@link encodeSubscriber} — the exact SUBSCRIBER TLV bytes. */
339
389
  static encodeSubscriber(targetPath, opts) {
340
390
  return encodeSubscriber(targetPath, opts);
341
391
  }
342
392
  }
343
- // `await` is a reserved word, so the method is `await_`; expose `client.await(...)`
344
- // too (a member name may be a keyword) for the RFC-0004-spelled ergonomic call.
393
+ /**
394
+ * @brief `await` is a reserved word, so the method is `await_`; expose
395
+ * `client.await(...)` too (a member name may be a keyword) for the
396
+ * RFC-0004-spelled ergonomic call.
397
+ */
345
398
  Object.defineProperty(LibtracerClient.prototype, 'await', {
346
399
  value: LibtracerClient.prototype.await_,
347
400
  writable: true,
348
401
  configurable: true,
349
402
  enumerable: false,
350
403
  });
351
- /** Normalize a `/`-path string (or segment array) into validated segments. */
404
+ /** @brief Normalize a `/`-path string (or segment array) into validated segments. */
352
405
  function splitPath(path) {
353
406
  if (Array.isArray(path))
354
407
  return path;