@avatarsd-llc/libtracer-client 0.3.0 → 0.4.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/dist/client.d.ts +60 -42
- package/dist/client.js +78 -55
- package/dist/fwd.d.ts +73 -61
- package/dist/fwd.js +70 -57
- package/dist/index.d.ts +15 -0
- package/dist/index.js +15 -11
- package/dist/tlv.d.ts +23 -16
- package/dist/tlv.js +34 -23
- package/package.json +3 -3
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.
|
|
6
|
-
*
|
|
7
|
-
*
|
|
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.
|
|
44
|
-
*
|
|
45
|
-
*
|
|
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
|
|
68
|
-
* which does not implement the RFC-0004 compact (route-handle) delivery
|
|
69
|
-
* yet.
|
|
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
|
-
/**
|
|
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
|
|
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.
|
|
104
|
-
*
|
|
105
|
-
*
|
|
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,
|
|
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,11 @@ 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,
|
|
147
|
-
* await_timeout? }`.
|
|
148
|
-
*
|
|
160
|
+
* @brief Block for the next write to a remote vertex: `FWD{ op=AWAIT,
|
|
161
|
+
* dst=path, src=…, await_timeout? }`.
|
|
162
|
+
*
|
|
163
|
+
* Named `await_` because `await` is reserved; an `await` alias is installed
|
|
164
|
+
* on the prototype for the RFC-0004-spelled call site.
|
|
149
165
|
*
|
|
150
166
|
* @param path the destination path (string or segments)
|
|
151
167
|
* @param timeoutNs the await timeout in ns (absent ⇒ the responder's 1 s default)
|
|
@@ -154,8 +170,10 @@ export declare class LibtracerClient {
|
|
|
154
170
|
*/
|
|
155
171
|
await_(path: string | string[], timeoutNs?: bigint): Promise<Tlv>;
|
|
156
172
|
/**
|
|
157
|
-
* Subscribe to a remote producer: a `WRITE` of a `SUBSCRIBER{
|
|
158
|
-
* into `producer:subscribers[]` (RFC-0004 §C/§D —
|
|
173
|
+
* @brief Subscribe to a remote producer: a `WRITE` of a `SUBSCRIBER{
|
|
174
|
+
* target=<reply-ep> }` into `producer:subscribers[]` (RFC-0004 §C/§D —
|
|
175
|
+
* subscribe is a field-write).
|
|
176
|
+
*
|
|
159
177
|
* Once the responder acks, `handler` fires for every inbound VALUE delivery.
|
|
160
178
|
*
|
|
161
179
|
* SCOPE: this issues the SUBSCRIBER and receives VALUEs the producer directly
|
|
@@ -171,10 +189,10 @@ export declare class LibtracerClient {
|
|
|
171
189
|
* @throws {FwdError} when the subscribe-write is rejected
|
|
172
190
|
*/
|
|
173
191
|
subscribe(producerPath: string | string[], handler: ValueHandler): Promise<Unsubscribe>;
|
|
174
|
-
/** {@link encodeValue} — the exact VALUE TLV bytes, independently of any transport. */
|
|
192
|
+
/** @brief {@link encodeValue} — the exact VALUE TLV bytes, independently of any transport. */
|
|
175
193
|
static encodeValue(value: Uint8Array, opts?: ValueOptions): Uint8Array;
|
|
176
|
-
/** {@link encodePath} — the exact PATH TLV bytes. */
|
|
194
|
+
/** @brief {@link encodePath} — the exact PATH TLV bytes. */
|
|
177
195
|
static encodePath(segments: string[]): Uint8Array;
|
|
178
|
-
/** {@link encodeSubscriber} — the exact SUBSCRIBER TLV bytes. */
|
|
196
|
+
/** @brief {@link encodeSubscriber} — the exact SUBSCRIBER TLV bytes. */
|
|
179
197
|
static encodeSubscriber(targetPath: string[], opts?: SubscriberOptions): Uint8Array;
|
|
180
198
|
}
|
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
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
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.
|
|
30
|
-
*
|
|
31
|
-
*
|
|
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
|
|
59
|
-
* which does not implement the RFC-0004 compact (route-handle) delivery
|
|
60
|
-
* yet.
|
|
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
|
-
/**
|
|
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
|
|
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.
|
|
120
|
-
*
|
|
121
|
-
*
|
|
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,
|
|
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,11 @@ 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,
|
|
268
|
-
* await_timeout? }`.
|
|
269
|
-
*
|
|
283
|
+
* @brief Block for the next write to a remote vertex: `FWD{ op=AWAIT,
|
|
284
|
+
* dst=path, src=…, await_timeout? }`.
|
|
285
|
+
*
|
|
286
|
+
* Named `await_` because `await` is reserved; an `await` alias is installed
|
|
287
|
+
* on the prototype for the RFC-0004-spelled call site.
|
|
270
288
|
*
|
|
271
289
|
* @param path the destination path (string or segments)
|
|
272
290
|
* @param timeoutNs the await timeout in ns (absent ⇒ the responder's 1 s default)
|
|
@@ -286,8 +304,10 @@ export class LibtracerClient {
|
|
|
286
304
|
return value;
|
|
287
305
|
}
|
|
288
306
|
/**
|
|
289
|
-
* Subscribe to a remote producer: a `WRITE` of a `SUBSCRIBER{
|
|
290
|
-
* into `producer:subscribers[]` (RFC-0004 §C/§D —
|
|
307
|
+
* @brief Subscribe to a remote producer: a `WRITE` of a `SUBSCRIBER{
|
|
308
|
+
* target=<reply-ep> }` into `producer:subscribers[]` (RFC-0004 §C/§D —
|
|
309
|
+
* subscribe is a field-write).
|
|
310
|
+
*
|
|
291
311
|
* Once the responder acks, `handler` fires for every inbound VALUE delivery.
|
|
292
312
|
*
|
|
293
313
|
* SCOPE: this issues the SUBSCRIBER and receives VALUEs the producer directly
|
|
@@ -327,28 +347,31 @@ export class LibtracerClient {
|
|
|
327
347
|
};
|
|
328
348
|
}
|
|
329
349
|
/* ------------------------------------------- pure builders (static) --- */
|
|
330
|
-
/** {@link encodeValue} — the exact VALUE TLV bytes, independently of any transport. */
|
|
350
|
+
/** @brief {@link encodeValue} — the exact VALUE TLV bytes, independently of any transport. */
|
|
331
351
|
static encodeValue(value, opts) {
|
|
332
352
|
return encodeValue(value, opts);
|
|
333
353
|
}
|
|
334
|
-
/** {@link encodePath} — the exact PATH TLV bytes. */
|
|
354
|
+
/** @brief {@link encodePath} — the exact PATH TLV bytes. */
|
|
335
355
|
static encodePath(segments) {
|
|
336
356
|
return encodePath(segments);
|
|
337
357
|
}
|
|
338
|
-
/** {@link encodeSubscriber} — the exact SUBSCRIBER TLV bytes. */
|
|
358
|
+
/** @brief {@link encodeSubscriber} — the exact SUBSCRIBER TLV bytes. */
|
|
339
359
|
static encodeSubscriber(targetPath, opts) {
|
|
340
360
|
return encodeSubscriber(targetPath, opts);
|
|
341
361
|
}
|
|
342
362
|
}
|
|
343
|
-
|
|
344
|
-
|
|
363
|
+
/**
|
|
364
|
+
* @brief `await` is a reserved word, so the method is `await_`; expose
|
|
365
|
+
* `client.await(...)` too (a member name may be a keyword) for the
|
|
366
|
+
* RFC-0004-spelled ergonomic call.
|
|
367
|
+
*/
|
|
345
368
|
Object.defineProperty(LibtracerClient.prototype, 'await', {
|
|
346
369
|
value: LibtracerClient.prototype.await_,
|
|
347
370
|
writable: true,
|
|
348
371
|
configurable: true,
|
|
349
372
|
enumerable: false,
|
|
350
373
|
});
|
|
351
|
-
/** Normalize a `/`-path string (or segment array) into validated segments. */
|
|
374
|
+
/** @brief Normalize a `/`-path string (or segment array) into validated segments. */
|
|
352
375
|
function splitPath(path) {
|
|
353
376
|
if (Array.isArray(path))
|
|
354
377
|
return path;
|
package/dist/fwd.d.ts
CHANGED
|
@@ -1,73 +1,80 @@
|
|
|
1
1
|
import type { Opt, Tlv } from '@avatarsd-llc/libtracer';
|
|
2
|
-
/** FWD `op` discriminant (RFC-0004 §B — the first child, a VALUE u8). */
|
|
2
|
+
/** @brief FWD `op` discriminant (RFC-0004 §B — the first child, a VALUE u8). */
|
|
3
3
|
export declare const FWD_OP: Readonly<{
|
|
4
4
|
readonly READ: 0;
|
|
5
5
|
readonly WRITE: 1;
|
|
6
6
|
readonly AWAIT: 2;
|
|
7
7
|
readonly REPLY: 3;
|
|
8
8
|
}>;
|
|
9
|
-
/** FWD{REPLY} `kind` discriminant (RFC-0004 §D — a VALUE u8 after `src`). */
|
|
9
|
+
/** @brief FWD{REPLY} `kind` discriminant (RFC-0004 §D — a VALUE u8 after `src`). */
|
|
10
10
|
export declare const FWD_KIND: Readonly<{
|
|
11
11
|
readonly RESULT: 0;
|
|
12
12
|
readonly ERROR: 1;
|
|
13
13
|
}>;
|
|
14
14
|
/**
|
|
15
|
-
* Registered wire ERROR codes for a `kind=ERROR` reply's
|
|
15
|
+
* @brief Registered wire ERROR codes for a `kind=ERROR` reply's
|
|
16
16
|
* `STATUS{ ERROR{ VALUE u16 } }` payload (RFC-0002 §D registry — the u16 LE
|
|
17
|
-
* identity of each built-in `tr::…` error path).
|
|
18
|
-
*
|
|
17
|
+
* identity of each built-in `tr::…` error path).
|
|
18
|
+
*
|
|
19
|
+
* Mirrors the C++ reference `error.hpp` registry / `op_resolve.cpp`
|
|
20
|
+
* `error_code()` map.
|
|
19
21
|
*/
|
|
20
22
|
export declare const FWD_ERROR: Readonly<{
|
|
21
|
-
readonly FRAME_TRUNCATED: 1;
|
|
22
|
-
readonly FRAME_INVALID: 2;
|
|
23
|
-
readonly FRAME_CRC_FAIL: 3;
|
|
24
|
-
readonly TLV_NESTING_TOO_DEEP: 16;
|
|
25
|
-
readonly NOT_FOUND: 32;
|
|
26
|
-
readonly INVALID_PATH: 33;
|
|
27
|
-
readonly PATH_IN_USE: 34;
|
|
28
|
-
readonly TYPE_MISMATCH: 48;
|
|
29
|
-
readonly SCHEMA_NOT_FOUND: 49;
|
|
30
|
-
readonly BACKPRESSURE: 64;
|
|
31
|
-
readonly TIMEOUT: 65;
|
|
32
|
-
readonly ADDRESS_SHIFT_GAP: 66;
|
|
33
|
-
readonly PERMISSION_DENIED: 80;
|
|
34
|
-
readonly TRANSPORT_DOWN: 96;
|
|
35
|
-
readonly VERSION_MISMATCH: 112;
|
|
23
|
+
readonly FRAME_TRUNCATED: 1; /**< @brief tr::frame::truncated */
|
|
24
|
+
readonly FRAME_INVALID: 2; /**< @brief tr::frame::invalid */
|
|
25
|
+
readonly FRAME_CRC_FAIL: 3; /**< @brief tr::frame::crc_fail */
|
|
26
|
+
readonly TLV_NESTING_TOO_DEEP: 16; /**< @brief tr::tlv::nesting_too_deep */
|
|
27
|
+
readonly NOT_FOUND: 32; /**< @brief tr::path::not_found */
|
|
28
|
+
readonly INVALID_PATH: 33; /**< @brief tr::path::invalid */
|
|
29
|
+
readonly PATH_IN_USE: 34; /**< @brief tr::path::in_use */
|
|
30
|
+
readonly TYPE_MISMATCH: 48; /**< @brief tr::schema::type_mismatch */
|
|
31
|
+
readonly SCHEMA_NOT_FOUND: 49; /**< @brief tr::schema::not_found */
|
|
32
|
+
readonly BACKPRESSURE: 64; /**< @brief tr::flow::backpressure */
|
|
33
|
+
readonly TIMEOUT: 65; /**< @brief tr::flow::timeout */
|
|
34
|
+
readonly ADDRESS_SHIFT_GAP: 66; /**< @brief tr::flow::address_shift_gap */
|
|
35
|
+
readonly PERMISSION_DENIED: 80; /**< @brief tr::access::denied */
|
|
36
|
+
readonly TRANSPORT_DOWN: 96; /**< @brief tr::transport::down */
|
|
37
|
+
readonly VERSION_MISMATCH: 112; /**< @brief tr::version::mismatch */
|
|
36
38
|
}>;
|
|
37
39
|
/**
|
|
38
|
-
* The canonical `tr::<concept>::<error>` namespace path of each
|
|
39
|
-
* (RFC-0002 §A/§D) — the string identity a NAME-form ERROR
|
|
40
|
-
*
|
|
40
|
+
* @brief The canonical `tr::<concept>::<error>` namespace path of each
|
|
41
|
+
* registered code (RFC-0002 §A/§D) — the string identity a NAME-form ERROR
|
|
42
|
+
* carries.
|
|
43
|
+
*
|
|
44
|
+
* Mirrors the C++ reference `error.hpp` `err_path()`.
|
|
41
45
|
*/
|
|
42
46
|
export declare const FWD_ERROR_PATH: Readonly<Record<number, string>>;
|
|
43
|
-
/** The human name of a wire ERROR code (or `UNKNOWN(0x..)`). */
|
|
47
|
+
/** @brief The human name of a wire ERROR code (or `UNKNOWN(0x..)`). */
|
|
44
48
|
export declare function fwdErrorName(code: number): string;
|
|
45
|
-
/** The canonical `tr::…` path of a wire ERROR code (or `null` when unregistered). */
|
|
49
|
+
/** @brief The canonical `tr::…` path of a wire ERROR code (or `null` when unregistered). */
|
|
46
50
|
export declare function fwdErrorPath(code: number): string | null;
|
|
47
51
|
/**
|
|
48
|
-
* The registered u16 code of a `tr::…` error path (RFC-0002 §A/§D), or
|
|
49
|
-
* the path is not in the frozen registry.
|
|
52
|
+
* @brief The registered u16 code of a `tr::…` error path (RFC-0002 §A/§D), or
|
|
53
|
+
* 0 when the path is not in the frozen registry.
|
|
50
54
|
*/
|
|
51
55
|
export declare function fwdErrorCodeForPath(path: string): number;
|
|
52
|
-
/** One level of a `:field` selector chain (RFC-0004 §C, one NAME + optional index). */
|
|
56
|
+
/** @brief One level of a `:field` selector chain (RFC-0004 §C, one NAME + optional index). */
|
|
53
57
|
export interface FieldLevel {
|
|
54
|
-
/** The level's field name (e.g. `"subscribers"`, `"settings"`). */
|
|
58
|
+
/** @brief The level's field name (e.g. `"subscribers"`, `"settings"`). */
|
|
55
59
|
readonly name: string;
|
|
56
60
|
/**
|
|
57
|
-
* The index when this level is an element selector (`[N]`).
|
|
58
|
-
*
|
|
61
|
+
* @brief The index when this level is an element selector (`[N]`).
|
|
62
|
+
*
|
|
63
|
+
* When set, the level is encoded as `ELEMENT` regardless of
|
|
64
|
+
* {@link FieldLevel.mode}.
|
|
59
65
|
*/
|
|
60
66
|
readonly index?: number;
|
|
61
67
|
/**
|
|
62
|
-
* `SCALAR` (no brackets, default), `ELEMENT` (`[N]` / append `[]`), or
|
|
63
|
-
* (`[*]` — subscriber-path targets only).
|
|
68
|
+
* @brief `SCALAR` (no brackets, default), `ELEMENT` (`[N]` / append `[]`), or
|
|
69
|
+
* `WILDCARD` (`[*]` — subscriber-path targets only).
|
|
64
70
|
*/
|
|
65
71
|
readonly mode?: 'SCALAR' | 'ELEMENT' | 'WILDCARD';
|
|
66
72
|
}
|
|
67
73
|
/**
|
|
68
|
-
* Parse a `:field` selector string into its levels.
|
|
69
|
-
*
|
|
70
|
-
*
|
|
74
|
+
* @brief Parse a `:field` selector string into its levels.
|
|
75
|
+
*
|
|
76
|
+
* Accepts an optional leading `:`; levels are split on `.`; each level may
|
|
77
|
+
* carry a trailing `[N]`, `[]` (append), or `[*]` (wildcard).
|
|
71
78
|
*
|
|
72
79
|
* `":subscribers[]"` → `[{ name: "subscribers", mode: "ELEMENT" }]`;
|
|
73
80
|
* `":subscribers[3]"` → `[{ name: "subscribers", index: 3, mode: "ELEMENT" }]`;
|
|
@@ -79,36 +86,40 @@ export interface FieldLevel {
|
|
|
79
86
|
*/
|
|
80
87
|
export declare function parseField(field: string): FieldLevel[];
|
|
81
88
|
/**
|
|
82
|
-
* Build a FIELD TLV (`type=0x10`, PL=1) from a selector string or
|
|
83
|
-
* levels.
|
|
89
|
+
* @brief Build a FIELD TLV (`type=0x10`, PL=1) from a selector string or
|
|
90
|
+
* pre-parsed levels.
|
|
91
|
+
*
|
|
92
|
+
* Vector-pinned: `field-indexed`, `field-nested`, `field-append`.
|
|
84
93
|
*
|
|
85
94
|
* @param field a `:field` string (see {@link parseField}) or its levels
|
|
86
95
|
* @returns the encoded FIELD TLV bytes
|
|
87
96
|
*/
|
|
88
97
|
export declare function encodeField(field: string | FieldLevel[]): Uint8Array;
|
|
89
|
-
/** Request to build a {@link encodeFwd} frame. `op` selects the child layout. */
|
|
98
|
+
/** @brief Request to build a {@link encodeFwd} frame. `op` selects the child layout. */
|
|
90
99
|
export interface FwdRequest {
|
|
91
|
-
/** The operation (a {@link FWD_OP} value). */
|
|
100
|
+
/** @brief The operation (a {@link FWD_OP} value). */
|
|
92
101
|
readonly op: number;
|
|
93
|
-
/** Forward route: the unresolved destination path segments (the PATH `dst`). */
|
|
102
|
+
/** @brief Forward route: the unresolved destination path segments (the PATH `dst`). */
|
|
94
103
|
readonly dst: string[];
|
|
95
|
-
/** Accumulated return route: the originator's reply endpoint segments (the PATH `src`). */
|
|
104
|
+
/** @brief Accumulated return route: the originator's reply endpoint segments (the PATH `src`). */
|
|
96
105
|
readonly src: string[];
|
|
97
|
-
/** Optional `:field` selector (string or levels). */
|
|
106
|
+
/** @brief Optional `:field` selector (string or levels). */
|
|
98
107
|
readonly field?: string | FieldLevel[];
|
|
99
108
|
/**
|
|
100
|
-
* Optional payload — a complete TLV's encoded bytes (a VALUE to WRITE,
|
|
101
|
-
* SUBSCRIBER to subscribe, the RESULT/STATUS of a REPLY). Embedded verbatim.
|
|
109
|
+
* @brief Optional payload — a complete TLV's encoded bytes (a VALUE to WRITE,
|
|
110
|
+
* a SUBSCRIBER to subscribe, the RESULT/STATUS of a REPLY). Embedded verbatim.
|
|
102
111
|
*/
|
|
103
112
|
readonly payload?: Uint8Array;
|
|
104
|
-
/** REPLY only — the reply {@link FWD_KIND}. */
|
|
113
|
+
/** @brief REPLY only — the reply {@link FWD_KIND}. */
|
|
105
114
|
readonly kind?: number;
|
|
106
|
-
/** AWAIT only — the `await_timeout` in ns (absent ⇒ the responder's 1 s default). */
|
|
115
|
+
/** @brief AWAIT only — the `await_timeout` in ns (absent ⇒ the responder's 1 s default). */
|
|
107
116
|
readonly awaitTimeoutNs?: bigint;
|
|
108
117
|
}
|
|
109
118
|
/**
|
|
110
|
-
* Build a FWD TLV (`type=0x0F`, PL=1) — the remote-operation envelope
|
|
111
|
-
* §B).
|
|
119
|
+
* @brief Build a FWD TLV (`type=0x0F`, PL=1) — the remote-operation envelope
|
|
120
|
+
* (RFC-0004 §B).
|
|
121
|
+
*
|
|
122
|
+
* The children are assembled in the normative order for the request's `op`.
|
|
112
123
|
* Vector-pinned: `fwd-read`, `fwd-write-value`, `fwd-await-timeout`,
|
|
113
124
|
* `fwd-write-subscriber-field`, `fwd-reply-result`, `fwd-reply-error`.
|
|
114
125
|
*
|
|
@@ -116,27 +127,27 @@ export interface FwdRequest {
|
|
|
116
127
|
* @returns the encoded FWD TLV bytes (one complete frame)
|
|
117
128
|
*/
|
|
118
129
|
export declare function encodeFwd(req: FwdRequest): Uint8Array;
|
|
119
|
-
/** A decoded FWD frame, its children parsed positionally (RFC-0004 §B order). */
|
|
130
|
+
/** @brief A decoded FWD frame, its children parsed positionally (RFC-0004 §B order). */
|
|
120
131
|
export interface ParsedFwd {
|
|
121
|
-
/** The operation (a {@link FWD_OP} value). */
|
|
132
|
+
/** @brief The operation (a {@link FWD_OP} value). */
|
|
122
133
|
readonly op: number;
|
|
123
|
-
/** The `dst` PATH child. */
|
|
134
|
+
/** @brief The `dst` PATH child. */
|
|
124
135
|
readonly dst: Tlv;
|
|
125
|
-
/** The optional FIELD selector child (or `null`). */
|
|
136
|
+
/** @brief The optional FIELD selector child (or `null`). */
|
|
126
137
|
readonly field: Tlv | null;
|
|
127
|
-
/** The `src` PATH child. */
|
|
138
|
+
/** @brief The `src` PATH child. */
|
|
128
139
|
readonly src: Tlv;
|
|
129
|
-
/** The reply {@link FWD_KIND} (REPLY frames only, else `null`). */
|
|
140
|
+
/** @brief The reply {@link FWD_KIND} (REPLY frames only, else `null`). */
|
|
130
141
|
readonly kind: number | null;
|
|
131
|
-
/** The payload TLV child (WRITE payload / REPLY result / RESULT VALUE), or `null`. */
|
|
142
|
+
/** @brief The payload TLV child (WRITE payload / REPLY result / RESULT VALUE), or `null`. */
|
|
132
143
|
readonly payload: Tlv | null;
|
|
133
|
-
/** The AWAIT `await_timeout` ns (else `null`). */
|
|
144
|
+
/** @brief The AWAIT `await_timeout` ns (else `null`). */
|
|
134
145
|
readonly awaitTimeoutNs: bigint | null;
|
|
135
146
|
}
|
|
136
|
-
/** Parse an already-decoded FWD {@link Tlv} positionally (RFC-0004 §B). */
|
|
147
|
+
/** @brief Parse an already-decoded FWD {@link Tlv} positionally (RFC-0004 §B). */
|
|
137
148
|
export declare function parseFwdTlv(fwd: Tlv): ParsedFwd;
|
|
138
149
|
/**
|
|
139
|
-
* Decode a complete FWD frame's bytes into its parsed children.
|
|
150
|
+
* @brief Decode a complete FWD frame's bytes into its parsed children.
|
|
140
151
|
*
|
|
141
152
|
* @param bytes one complete FWD TLV frame
|
|
142
153
|
* @returns the parsed FWD
|
|
@@ -144,17 +155,18 @@ export declare function parseFwdTlv(fwd: Tlv): ParsedFwd;
|
|
|
144
155
|
*/
|
|
145
156
|
export declare function decodeFwd(bytes: Uint8Array): ParsedFwd;
|
|
146
157
|
/**
|
|
147
|
-
* The registered wire ERROR code of a `kind=ERROR` reply's
|
|
158
|
+
* @brief The registered wire ERROR code of a `kind=ERROR` reply's
|
|
148
159
|
* `STATUS{ ERROR{ VALUE u16 } }` payload per RFC-0002 (or 0 when absent, or
|
|
149
160
|
* when the ERROR carries the string-form NAME identity — see
|
|
150
161
|
* {@link replyErrorPath}).
|
|
151
162
|
*/
|
|
152
163
|
export declare function replyErrorCode(reply: ParsedFwd): number;
|
|
153
164
|
/**
|
|
154
|
-
* The string-form `tr::…` identity of a `kind=ERROR` reply's
|
|
165
|
+
* @brief The string-form `tr::…` identity of a `kind=ERROR` reply's
|
|
155
166
|
* `STATUS{ ERROR{ NAME utf8-path } }` payload per RFC-0002 (or `null` when the
|
|
156
167
|
* reply carries no ERROR, or a registered-code identity — see
|
|
157
168
|
* {@link replyErrorCode}).
|
|
158
169
|
*/
|
|
159
170
|
export declare function replyErrorPath(reply: ParsedFwd): string | null;
|
|
171
|
+
/** @brief Re-export Opt so consumers building raw nodes do not need the core import. */
|
|
160
172
|
export type { Opt };
|
package/dist/fwd.js
CHANGED
|
@@ -1,59 +1,67 @@
|
|
|
1
1
|
// SPDX-License-Identifier: Apache-2.0
|
|
2
2
|
// SPDX-FileCopyrightText: Copyright 2026 avatarsd LLC
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
3
|
+
/**
|
|
4
|
+
* @brief FWD (0x0F) / FIELD (0x10) builders + decoder for the libtracer client
|
|
5
|
+
* SDK (#56, RFC-0004, ADR-0034/0035).
|
|
6
|
+
*
|
|
7
|
+
* RFC-0004 §3 pins the remote-operation envelope the conservative ADR-0034
|
|
8
|
+
* slice deferred: a self-describing FWD frame carries a
|
|
9
|
+
* `read`/`write`/`await`/`subscribe` to a path-as-route, and a FWD{REPLY}
|
|
10
|
+
* routes the result back. These builders produce the EXACT bytes the shared
|
|
11
|
+
* conformance vectors pin (`tests/conformance/vectors/v1/fwd/`, `.../field/`)
|
|
12
|
+
* via the cross-validated core codec — nothing here invents wire structure.
|
|
13
|
+
*
|
|
14
|
+
* Child order (RFC-0004 §B): op, dst (PATH), FIELD? selector, src (PATH), then
|
|
15
|
+
* - REPLY: kind (VALUE u8), payload?
|
|
16
|
+
* - WRITE: payload?
|
|
17
|
+
* - AWAIT: await_timeout? (VALUE u64 ns)
|
|
18
|
+
* - READ : nothing
|
|
19
|
+
*/
|
|
16
20
|
import { TYPE, encode, decode } from '@avatarsd-llc/libtracer';
|
|
17
21
|
import { opt, pathTlv, nameTlv } from './tlv.js';
|
|
18
|
-
/** FWD `op` discriminant (RFC-0004 §B — the first child, a VALUE u8). */
|
|
22
|
+
/** @brief FWD `op` discriminant (RFC-0004 §B — the first child, a VALUE u8). */
|
|
19
23
|
export const FWD_OP = Object.freeze({
|
|
20
24
|
READ: 0,
|
|
21
25
|
WRITE: 1,
|
|
22
26
|
AWAIT: 2,
|
|
23
27
|
REPLY: 3,
|
|
24
28
|
});
|
|
25
|
-
/** FWD{REPLY} `kind` discriminant (RFC-0004 §D — a VALUE u8 after `src`). */
|
|
29
|
+
/** @brief FWD{REPLY} `kind` discriminant (RFC-0004 §D — a VALUE u8 after `src`). */
|
|
26
30
|
export const FWD_KIND = Object.freeze({
|
|
27
31
|
RESULT: 0,
|
|
28
32
|
ERROR: 1,
|
|
29
33
|
});
|
|
30
34
|
/**
|
|
31
|
-
* Registered wire ERROR codes for a `kind=ERROR` reply's
|
|
35
|
+
* @brief Registered wire ERROR codes for a `kind=ERROR` reply's
|
|
32
36
|
* `STATUS{ ERROR{ VALUE u16 } }` payload (RFC-0002 §D registry — the u16 LE
|
|
33
|
-
* identity of each built-in `tr::…` error path).
|
|
34
|
-
*
|
|
37
|
+
* identity of each built-in `tr::…` error path).
|
|
38
|
+
*
|
|
39
|
+
* Mirrors the C++ reference `error.hpp` registry / `op_resolve.cpp`
|
|
40
|
+
* `error_code()` map.
|
|
35
41
|
*/
|
|
36
42
|
export const FWD_ERROR = Object.freeze({
|
|
37
|
-
FRAME_TRUNCATED: 0x0001
|
|
38
|
-
FRAME_INVALID: 0x0002
|
|
39
|
-
FRAME_CRC_FAIL: 0x0003
|
|
40
|
-
TLV_NESTING_TOO_DEEP: 0x0010
|
|
41
|
-
NOT_FOUND: 0x0020
|
|
42
|
-
INVALID_PATH: 0x0021
|
|
43
|
-
PATH_IN_USE: 0x0022
|
|
44
|
-
TYPE_MISMATCH: 0x0030
|
|
45
|
-
SCHEMA_NOT_FOUND: 0x0031
|
|
46
|
-
BACKPRESSURE: 0x0040
|
|
47
|
-
TIMEOUT: 0x0041
|
|
48
|
-
ADDRESS_SHIFT_GAP: 0x0042
|
|
49
|
-
PERMISSION_DENIED: 0x0050
|
|
50
|
-
TRANSPORT_DOWN: 0x0060
|
|
51
|
-
VERSION_MISMATCH: 0x0070
|
|
43
|
+
FRAME_TRUNCATED: 0x0001 /**< @brief tr::frame::truncated */,
|
|
44
|
+
FRAME_INVALID: 0x0002 /**< @brief tr::frame::invalid */,
|
|
45
|
+
FRAME_CRC_FAIL: 0x0003 /**< @brief tr::frame::crc_fail */,
|
|
46
|
+
TLV_NESTING_TOO_DEEP: 0x0010 /**< @brief tr::tlv::nesting_too_deep */,
|
|
47
|
+
NOT_FOUND: 0x0020 /**< @brief tr::path::not_found */,
|
|
48
|
+
INVALID_PATH: 0x0021 /**< @brief tr::path::invalid */,
|
|
49
|
+
PATH_IN_USE: 0x0022 /**< @brief tr::path::in_use */,
|
|
50
|
+
TYPE_MISMATCH: 0x0030 /**< @brief tr::schema::type_mismatch */,
|
|
51
|
+
SCHEMA_NOT_FOUND: 0x0031 /**< @brief tr::schema::not_found */,
|
|
52
|
+
BACKPRESSURE: 0x0040 /**< @brief tr::flow::backpressure */,
|
|
53
|
+
TIMEOUT: 0x0041 /**< @brief tr::flow::timeout */,
|
|
54
|
+
ADDRESS_SHIFT_GAP: 0x0042 /**< @brief tr::flow::address_shift_gap */,
|
|
55
|
+
PERMISSION_DENIED: 0x0050 /**< @brief tr::access::denied */,
|
|
56
|
+
TRANSPORT_DOWN: 0x0060 /**< @brief tr::transport::down */,
|
|
57
|
+
VERSION_MISMATCH: 0x0070 /**< @brief tr::version::mismatch */,
|
|
52
58
|
});
|
|
53
59
|
/**
|
|
54
|
-
* The canonical `tr::<concept>::<error>` namespace path of each
|
|
55
|
-
* (RFC-0002 §A/§D) — the string identity a NAME-form ERROR
|
|
56
|
-
*
|
|
60
|
+
* @brief The canonical `tr::<concept>::<error>` namespace path of each
|
|
61
|
+
* registered code (RFC-0002 §A/§D) — the string identity a NAME-form ERROR
|
|
62
|
+
* carries.
|
|
63
|
+
*
|
|
64
|
+
* Mirrors the C++ reference `error.hpp` `err_path()`.
|
|
57
65
|
*/
|
|
58
66
|
export const FWD_ERROR_PATH = Object.freeze({
|
|
59
67
|
[FWD_ERROR.FRAME_TRUNCATED]: 'tr::frame::truncated',
|
|
@@ -74,42 +82,43 @@ export const FWD_ERROR_PATH = Object.freeze({
|
|
|
74
82
|
});
|
|
75
83
|
const FWD_ERROR_NAME = Object.freeze(Object.fromEntries(Object.entries(FWD_ERROR).map(([k, v]) => [v, k])));
|
|
76
84
|
const FWD_ERROR_CODE_BY_PATH = Object.freeze(Object.fromEntries(Object.entries(FWD_ERROR_PATH).map(([code, path]) => [path, Number(code)])));
|
|
77
|
-
/** The human name of a wire ERROR code (or `UNKNOWN(0x..)`). */
|
|
85
|
+
/** @brief The human name of a wire ERROR code (or `UNKNOWN(0x..)`). */
|
|
78
86
|
export function fwdErrorName(code) {
|
|
79
87
|
return FWD_ERROR_NAME[code] ?? `UNKNOWN(0x${code.toString(16)})`;
|
|
80
88
|
}
|
|
81
|
-
/** The canonical `tr::…` path of a wire ERROR code (or `null` when unregistered). */
|
|
89
|
+
/** @brief The canonical `tr::…` path of a wire ERROR code (or `null` when unregistered). */
|
|
82
90
|
export function fwdErrorPath(code) {
|
|
83
91
|
return FWD_ERROR_PATH[code] ?? null;
|
|
84
92
|
}
|
|
85
93
|
/**
|
|
86
|
-
* The registered u16 code of a `tr::…` error path (RFC-0002 §A/§D), or
|
|
87
|
-
* the path is not in the frozen registry.
|
|
94
|
+
* @brief The registered u16 code of a `tr::…` error path (RFC-0002 §A/§D), or
|
|
95
|
+
* 0 when the path is not in the frozen registry.
|
|
88
96
|
*/
|
|
89
97
|
export function fwdErrorCodeForPath(path) {
|
|
90
98
|
return FWD_ERROR_CODE_BY_PATH[path] ?? 0;
|
|
91
99
|
}
|
|
92
100
|
/* ----------------------------------------------------------- value nodes --- */
|
|
93
|
-
/** A 1-byte VALUE TLV node (the op / kind discriminants). */
|
|
101
|
+
/** @brief A 1-byte VALUE TLV node (the op / kind discriminants). */
|
|
94
102
|
function valueU8(v) {
|
|
95
103
|
return { type: TYPE.VALUE, opt: opt(), payload: Uint8Array.of(v & 0xff), children: [], trailer: null };
|
|
96
104
|
}
|
|
97
|
-
/** A little-endian u32 VALUE TLV node (a FIELD `[N]` index). */
|
|
105
|
+
/** @brief A little-endian u32 VALUE TLV node (a FIELD `[N]` index). */
|
|
98
106
|
function valueU32(v) {
|
|
99
107
|
const p = new Uint8Array(4);
|
|
100
108
|
new DataView(p.buffer).setUint32(0, v >>> 0, true);
|
|
101
109
|
return { type: TYPE.VALUE, opt: opt(), payload: p, children: [], trailer: null };
|
|
102
110
|
}
|
|
103
|
-
/** A little-endian u64 VALUE TLV node (the AWAIT `await_timeout` ns). */
|
|
111
|
+
/** @brief A little-endian u64 VALUE TLV node (the AWAIT `await_timeout` ns). */
|
|
104
112
|
function valueU64(v) {
|
|
105
113
|
const p = new Uint8Array(8);
|
|
106
114
|
new DataView(p.buffer).setBigUint64(0, v, true);
|
|
107
115
|
return { type: TYPE.VALUE, opt: opt(), payload: p, children: [], trailer: null };
|
|
108
116
|
}
|
|
109
117
|
/**
|
|
110
|
-
* Parse a `:field` selector string into its levels.
|
|
111
|
-
*
|
|
112
|
-
*
|
|
118
|
+
* @brief Parse a `:field` selector string into its levels.
|
|
119
|
+
*
|
|
120
|
+
* Accepts an optional leading `:`; levels are split on `.`; each level may
|
|
121
|
+
* carry a trailing `[N]`, `[]` (append), or `[*]` (wildcard).
|
|
113
122
|
*
|
|
114
123
|
* `":subscribers[]"` → `[{ name: "subscribers", mode: "ELEMENT" }]`;
|
|
115
124
|
* `":subscribers[3]"` → `[{ name: "subscribers", index: 3, mode: "ELEMENT" }]`;
|
|
@@ -137,7 +146,7 @@ export function parseField(field) {
|
|
|
137
146
|
return { name, index: Number(m[2]), mode: 'ELEMENT' };
|
|
138
147
|
});
|
|
139
148
|
}
|
|
140
|
-
/** Build a FIELD TLV node from its levels (RFC-0004 §C). */
|
|
149
|
+
/** @brief Build a FIELD TLV node from its levels (RFC-0004 §C). */
|
|
141
150
|
function fieldTlv(levels) {
|
|
142
151
|
if (levels.length < 1)
|
|
143
152
|
throw new RangeError('a FIELD selector needs at least one level');
|
|
@@ -160,8 +169,10 @@ function fieldTlv(levels) {
|
|
|
160
169
|
return { type: TYPE.FIELD, opt: opt({ pl: true }), payload: new Uint8Array(0), children, trailer: null };
|
|
161
170
|
}
|
|
162
171
|
/**
|
|
163
|
-
* Build a FIELD TLV (`type=0x10`, PL=1) from a selector string or
|
|
164
|
-
* levels.
|
|
172
|
+
* @brief Build a FIELD TLV (`type=0x10`, PL=1) from a selector string or
|
|
173
|
+
* pre-parsed levels.
|
|
174
|
+
*
|
|
175
|
+
* Vector-pinned: `field-indexed`, `field-nested`, `field-append`.
|
|
165
176
|
*
|
|
166
177
|
* @param field a `:field` string (see {@link parseField}) or its levels
|
|
167
178
|
* @returns the encoded FIELD TLV bytes
|
|
@@ -169,13 +180,15 @@ function fieldTlv(levels) {
|
|
|
169
180
|
export function encodeField(field) {
|
|
170
181
|
return encode(fieldTlv(typeof field === 'string' ? parseField(field) : field));
|
|
171
182
|
}
|
|
172
|
-
/** Build the FWD child node for an embedded payload (decode the caller's TLV bytes). */
|
|
183
|
+
/** @brief Build the FWD child node for an embedded payload (decode the caller's TLV bytes). */
|
|
173
184
|
function payloadNode(payload) {
|
|
174
185
|
return decode(payload);
|
|
175
186
|
}
|
|
176
187
|
/**
|
|
177
|
-
* Build a FWD TLV (`type=0x0F`, PL=1) — the remote-operation envelope
|
|
178
|
-
* §B).
|
|
188
|
+
* @brief Build a FWD TLV (`type=0x0F`, PL=1) — the remote-operation envelope
|
|
189
|
+
* (RFC-0004 §B).
|
|
190
|
+
*
|
|
191
|
+
* The children are assembled in the normative order for the request's `op`.
|
|
179
192
|
* Vector-pinned: `fwd-read`, `fwd-write-value`, `fwd-await-timeout`,
|
|
180
193
|
* `fwd-write-subscriber-field`, `fwd-reply-result`, `fwd-reply-error`.
|
|
181
194
|
*
|
|
@@ -211,7 +224,7 @@ export function encodeFwd(req) {
|
|
|
211
224
|
return encode(fwd);
|
|
212
225
|
}
|
|
213
226
|
const u8 = (t) => (t.payload.length > 0 ? t.payload[0] : 0);
|
|
214
|
-
/** Parse an already-decoded FWD {@link Tlv} positionally (RFC-0004 §B). */
|
|
227
|
+
/** @brief Parse an already-decoded FWD {@link Tlv} positionally (RFC-0004 §B). */
|
|
215
228
|
export function parseFwdTlv(fwd) {
|
|
216
229
|
if (fwd.type !== TYPE.FWD)
|
|
217
230
|
throw new RangeError(`not a FWD TLV (type 0x${fwd.type.toString(16)})`);
|
|
@@ -251,7 +264,7 @@ export function parseFwdTlv(fwd) {
|
|
|
251
264
|
return { op, dst, field, src, kind, payload, awaitTimeoutNs };
|
|
252
265
|
}
|
|
253
266
|
/**
|
|
254
|
-
* Decode a complete FWD frame's bytes into its parsed children.
|
|
267
|
+
* @brief Decode a complete FWD frame's bytes into its parsed children.
|
|
255
268
|
*
|
|
256
269
|
* @param bytes one complete FWD TLV frame
|
|
257
270
|
* @returns the parsed FWD
|
|
@@ -260,7 +273,7 @@ export function parseFwdTlv(fwd) {
|
|
|
260
273
|
export function decodeFwd(bytes) {
|
|
261
274
|
return parseFwdTlv(decode(bytes));
|
|
262
275
|
}
|
|
263
|
-
/** The ERROR TLV of a `kind=ERROR` reply's STATUS payload, or `null`. */
|
|
276
|
+
/** @brief The ERROR TLV of a `kind=ERROR` reply's STATUS payload, or `null`. */
|
|
264
277
|
function replyErrorTlv(reply) {
|
|
265
278
|
const status = reply.payload;
|
|
266
279
|
if (status && status.type === TYPE.STATUS && status.children[0]?.type === TYPE.ERROR) {
|
|
@@ -269,7 +282,7 @@ function replyErrorTlv(reply) {
|
|
|
269
282
|
return null;
|
|
270
283
|
}
|
|
271
284
|
/**
|
|
272
|
-
* The registered wire ERROR code of a `kind=ERROR` reply's
|
|
285
|
+
* @brief The registered wire ERROR code of a `kind=ERROR` reply's
|
|
273
286
|
* `STATUS{ ERROR{ VALUE u16 } }` payload per RFC-0002 (or 0 when absent, or
|
|
274
287
|
* when the ERROR carries the string-form NAME identity — see
|
|
275
288
|
* {@link replyErrorPath}).
|
|
@@ -283,7 +296,7 @@ export function replyErrorCode(reply) {
|
|
|
283
296
|
return 0;
|
|
284
297
|
}
|
|
285
298
|
/**
|
|
286
|
-
* The string-form `tr::…` identity of a `kind=ERROR` reply's
|
|
299
|
+
* @brief The string-form `tr::…` identity of a `kind=ERROR` reply's
|
|
287
300
|
* `STATUS{ ERROR{ NAME utf8-path } }` payload per RFC-0002 (or `null` when the
|
|
288
301
|
* reply carries no ERROR, or a registered-code identity — see
|
|
289
302
|
* {@link replyErrorCode}).
|
package/dist/index.d.ts
CHANGED
|
@@ -1,3 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @brief @avatarsd-llc/libtracer-client — the experimental libtracer client
|
|
3
|
+
* SDK (#56, ADR-0034).
|
|
4
|
+
*
|
|
5
|
+
* A curated composition over the cross-validated codec
|
|
6
|
+
* (@avatarsd-llc/libtracer, a peerDependency) and an injected transport seam
|
|
7
|
+
* (@avatarsd-llc/libtracer-ws's TransportWs satisfies it structurally).
|
|
8
|
+
*
|
|
9
|
+
* EXPERIMENTAL / pre-1.0 (0.1.0). With RFC-0004 (spec §3, the remote-operation
|
|
10
|
+
* envelope) implemented, the client now speaks the path-addressed higher
|
|
11
|
+
* operations over `FWD`: read / write / await / readField / subscribe, each a
|
|
12
|
+
* FWD frame whose FWD{REPLY} is source-routed back. The pure payload builders
|
|
13
|
+
* (VALUE / SUBSCRIBER / PATH) and the FWD / FIELD builders are independently
|
|
14
|
+
* exported and vector-pinned — see docs/spec/rfcs/0004-remote-operation-addressing.md.
|
|
15
|
+
*/
|
|
1
16
|
export declare const CLIENT_EXPERIMENTAL: true;
|
|
2
17
|
export { LibtracerClient, FwdError, CompactFlowError } from './client.js';
|
|
3
18
|
export type { ClientTransport, ValueHandler, Unsubscribe, ClientOptions, } from './client.js';
|
package/dist/index.js
CHANGED
|
@@ -1,16 +1,20 @@
|
|
|
1
1
|
// SPDX-License-Identifier: Apache-2.0
|
|
2
2
|
// SPDX-FileCopyrightText: Copyright 2026 avatarsd LLC
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
3
|
+
/**
|
|
4
|
+
* @brief @avatarsd-llc/libtracer-client — the experimental libtracer client
|
|
5
|
+
* SDK (#56, ADR-0034).
|
|
6
|
+
*
|
|
7
|
+
* A curated composition over the cross-validated codec
|
|
8
|
+
* (@avatarsd-llc/libtracer, a peerDependency) and an injected transport seam
|
|
9
|
+
* (@avatarsd-llc/libtracer-ws's TransportWs satisfies it structurally).
|
|
10
|
+
*
|
|
11
|
+
* EXPERIMENTAL / pre-1.0 (0.1.0). With RFC-0004 (spec §3, the remote-operation
|
|
12
|
+
* envelope) implemented, the client now speaks the path-addressed higher
|
|
13
|
+
* operations over `FWD`: read / write / await / readField / subscribe, each a
|
|
14
|
+
* FWD frame whose FWD{REPLY} is source-routed back. The pure payload builders
|
|
15
|
+
* (VALUE / SUBSCRIBER / PATH) and the FWD / FIELD builders are independently
|
|
16
|
+
* exported and vector-pinned — see docs/spec/rfcs/0004-remote-operation-addressing.md.
|
|
17
|
+
*/
|
|
14
18
|
export const CLIENT_EXPERIMENTAL = true;
|
|
15
19
|
export { LibtracerClient, FwdError, CompactFlowError } from './client.js';
|
|
16
20
|
export { encodeValue, encodePath, encodeSubscriber } from './tlv.js';
|
package/dist/tlv.d.ts
CHANGED
|
@@ -1,27 +1,30 @@
|
|
|
1
1
|
import type { Opt, Tlv } from '@avatarsd-llc/libtracer';
|
|
2
2
|
/**
|
|
3
|
-
* A fully-cleared option byte (all flags false), with selected flags
|
|
3
|
+
* @brief A fully-cleared option byte (all flags false), with selected flags
|
|
4
|
+
* overridden.
|
|
5
|
+
*
|
|
4
6
|
* Shared by the payload builders here and the FWD/FIELD builders in `./fwd.ts`.
|
|
5
7
|
*
|
|
6
8
|
* @param over flags to set true (e.g. `{ pl: true }` for a structured TLV)
|
|
7
9
|
* @returns a complete {@link Opt}
|
|
8
10
|
*/
|
|
9
11
|
export declare function opt(over?: Partial<Opt>): Opt;
|
|
10
|
-
/** Options for {@link encodeValue}. Mirror the wire opt/trailer fields the codec pins. */
|
|
12
|
+
/** @brief Options for {@link encodeValue}. Mirror the wire opt/trailer fields the codec pins. */
|
|
11
13
|
export interface ValueOptions {
|
|
12
|
-
/** Use the 32-bit length field (opt.LL=1, 6-byte header). Default: 16-bit. */
|
|
14
|
+
/** @brief Use the 32-bit length field (opt.LL=1, 6-byte header). Default: 16-bit. */
|
|
13
15
|
longLength?: boolean;
|
|
14
|
-
/** Emit a CRC trailer over the payload (+ timestamp bytes). Default: none. */
|
|
16
|
+
/** @brief Emit a CRC trailer over the payload (+ timestamp bytes). Default: none. */
|
|
15
17
|
crc?: boolean;
|
|
16
|
-
/** With {@link ValueOptions.crc}, use CRC-16-CCITT (opt.CW=1) instead of CRC-32C. */
|
|
18
|
+
/** @brief With {@link ValueOptions.crc}, use CRC-16-CCITT (opt.CW=1) instead of CRC-32C. */
|
|
17
19
|
crc16?: boolean;
|
|
18
|
-
/** Absolute u64 wire timestamp (ns since epoch) → opt.TS=1, TF=0 (absolute). */
|
|
20
|
+
/** @brief Absolute u64 wire timestamp (ns since epoch) → opt.TS=1, TF=0 (absolute). */
|
|
19
21
|
timestampNs?: bigint;
|
|
20
|
-
/** Relative i32 wire timestamp (ns) → opt.TS=1, TF=1 (relative). Ignored if {@link ValueOptions.timestampNs} is set. */
|
|
22
|
+
/** @brief Relative i32 wire timestamp (ns) → opt.TS=1, TF=1 (relative). Ignored if {@link ValueOptions.timestampNs} is set. */
|
|
21
23
|
timestampRelNs?: number;
|
|
22
24
|
}
|
|
23
25
|
/**
|
|
24
|
-
* Build a VALUE TLV (`type=0x01`) carrying an opaque application payload.
|
|
26
|
+
* @brief Build a VALUE TLV (`type=0x01`) carrying an opaque application payload.
|
|
27
|
+
*
|
|
25
28
|
* Vector-pinned: `value-bool-true`, `value-ll-u32`, `value-ts-abs`.
|
|
26
29
|
*
|
|
27
30
|
* @param value the opaque payload bytes (the publisher/subscriber agree on the shape out-of-band)
|
|
@@ -30,8 +33,8 @@ export interface ValueOptions {
|
|
|
30
33
|
*/
|
|
31
34
|
export declare function encodeValue(value: Uint8Array, opts?: ValueOptions): Uint8Array;
|
|
32
35
|
/**
|
|
33
|
-
* Build a NAME TLV (`type=0x02`) for one path segment, after validating
|
|
34
|
-
* against the addressing rules (1..64 UTF-8 bytes, no reserved characters).
|
|
36
|
+
* @brief Build a NAME TLV (`type=0x02`) for one path segment, after validating
|
|
37
|
+
* it against the addressing rules (1..64 UTF-8 bytes, no reserved characters).
|
|
35
38
|
*
|
|
36
39
|
* @param segment the segment text
|
|
37
40
|
* @returns a NAME TLV node (no trailer)
|
|
@@ -39,22 +42,26 @@ export declare function encodeValue(value: Uint8Array, opts?: ValueOptions): Uin
|
|
|
39
42
|
*/
|
|
40
43
|
export declare function nameTlv(segment: string): Tlv;
|
|
41
44
|
/**
|
|
42
|
-
* Build a PATH TLV (`type=0x06`, PL=1) from path segments — a NAME child
|
|
43
|
-
* segment.
|
|
45
|
+
* @brief Build a PATH TLV (`type=0x06`, PL=1) from path segments — a NAME child
|
|
46
|
+
* per segment.
|
|
47
|
+
*
|
|
48
|
+
* Vector-pinned: `path-sensor-temp`; normative byte layout: spec/v1.md §3.1.
|
|
44
49
|
*
|
|
45
50
|
* @param segments the path segments, e.g. `["sensor", "temp"]` for `/sensor/temp`
|
|
46
51
|
* @returns the encoded PATH TLV bytes
|
|
47
52
|
* @throws {RangeError} on an empty path or an invalid segment
|
|
48
53
|
*/
|
|
49
54
|
export declare function encodePath(segments: string[]): Uint8Array;
|
|
50
|
-
/** The PATH TLV node (shared by {@link encodePath}, {@link encodeSubscriber}, and `./fwd.ts`). */
|
|
55
|
+
/** @brief The PATH TLV node (shared by {@link encodePath}, {@link encodeSubscriber}, and `./fwd.ts`). */
|
|
51
56
|
export declare function pathTlv(segments: string[]): Tlv;
|
|
52
|
-
/** Options for {@link encodeSubscriber}. Optional QoS/ACL/id children are deferred (ADR-0034). */
|
|
57
|
+
/** @brief Options for {@link encodeSubscriber}. Optional QoS/ACL/id children are deferred (ADR-0034). */
|
|
53
58
|
export interface SubscriberOptions {
|
|
54
59
|
}
|
|
55
60
|
/**
|
|
56
|
-
* Build a SUBSCRIBER TLV (`type=0x04`, PL=1) wrapping a target PATH —
|
|
57
|
-
* payload of a subscribe-write (reference/04 §Subscribe).
|
|
61
|
+
* @brief Build a SUBSCRIBER TLV (`type=0x04`, PL=1) wrapping a target PATH —
|
|
62
|
+
* the payload of a subscribe-write (reference/04 §Subscribe).
|
|
63
|
+
*
|
|
64
|
+
* Vector-pinned:
|
|
58
65
|
* `subscriber-path` = `SUBSCRIBER{ PATH{ NAME "sensor", NAME "temp" } }`.
|
|
59
66
|
*
|
|
60
67
|
* The `targetPath` is the SUBSCRIBER's `target_path` child: where the producer
|
package/dist/tlv.js
CHANGED
|
@@ -1,25 +1,31 @@
|
|
|
1
1
|
// SPDX-License-Identifier: Apache-2.0
|
|
2
2
|
// SPDX-FileCopyrightText: Copyright 2026 avatarsd LLC
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
3
|
+
/**
|
|
4
|
+
* @brief Pure, side-effect-free TLV builders for the libtracer client SDK
|
|
5
|
+
* (#56, ADR-0034).
|
|
6
|
+
*
|
|
7
|
+
* Each function produces the EXACT wire bytes the shared conformance vectors
|
|
8
|
+
* pin (`tests/conformance/vectors/v1/`) via the cross-validated core codec
|
|
9
|
+
* (`@avatarsd-llc/libtracer`) — nothing here invents wire structure:
|
|
10
|
+
*
|
|
11
|
+
* - encodeValue -> VALUE TLV (0x01) : value-bool-true / value-ll-u32 / value-ts-abs
|
|
12
|
+
* - encodePath -> PATH TLV (0x06, PL=1) : path-sensor-temp + spec/v1.md §3.1
|
|
13
|
+
* - encodeSubscriber -> SUBSCRIBER TLV (0x04) : subscriber-path (the subscribe-write payload)
|
|
14
|
+
*
|
|
15
|
+
* These are the payload TLVs. The path-ADDRESSED request envelope (verb +
|
|
16
|
+
* destination vertex:field) is the FWD/FIELD frame RFC-0004 (spec §3) fixes —
|
|
17
|
+
* it is built in `./fwd.ts`, not here; these payloads ride inside it.
|
|
18
|
+
*/
|
|
15
19
|
import { TYPE, encode } from '@avatarsd-llc/libtracer';
|
|
16
|
-
/** Path-segment constraints from reference/03-addressing.md §path syntax. */
|
|
20
|
+
/** @brief Path-segment constraints from reference/03-addressing.md §path syntax. */
|
|
17
21
|
const MAX_SEGMENT_BYTES = 64;
|
|
18
|
-
/** Reserved characters that MUST NOT appear inside a NAME segment (reference/03, /05 §NAME). */
|
|
22
|
+
/** @brief Reserved characters that MUST NOT appear inside a NAME segment (reference/03, /05 §NAME). */
|
|
19
23
|
const RESERVED_SEGMENT_CHARS = /[/:.[\]*?]/;
|
|
20
24
|
const utf8 = new TextEncoder();
|
|
21
25
|
/**
|
|
22
|
-
* A fully-cleared option byte (all flags false), with selected flags
|
|
26
|
+
* @brief A fully-cleared option byte (all flags false), with selected flags
|
|
27
|
+
* overridden.
|
|
28
|
+
*
|
|
23
29
|
* Shared by the payload builders here and the FWD/FIELD builders in `./fwd.ts`.
|
|
24
30
|
*
|
|
25
31
|
* @param over flags to set true (e.g. `{ pl: true }` for a structured TLV)
|
|
@@ -29,7 +35,8 @@ export function opt(over = {}) {
|
|
|
29
35
|
return { pl: false, ts: false, cr: false, ll: false, cw: false, tf: false, ...over };
|
|
30
36
|
}
|
|
31
37
|
/**
|
|
32
|
-
* Build a VALUE TLV (`type=0x01`) carrying an opaque application payload.
|
|
38
|
+
* @brief Build a VALUE TLV (`type=0x01`) carrying an opaque application payload.
|
|
39
|
+
*
|
|
33
40
|
* Vector-pinned: `value-bool-true`, `value-ll-u32`, `value-ts-abs`.
|
|
34
41
|
*
|
|
35
42
|
* @param value the opaque payload bytes (the publisher/subscriber agree on the shape out-of-band)
|
|
@@ -57,8 +64,8 @@ export function encodeValue(value, opts = {}) {
|
|
|
57
64
|
return encode(tlv);
|
|
58
65
|
}
|
|
59
66
|
/**
|
|
60
|
-
* Build a NAME TLV (`type=0x02`) for one path segment, after validating
|
|
61
|
-
* against the addressing rules (1..64 UTF-8 bytes, no reserved characters).
|
|
67
|
+
* @brief Build a NAME TLV (`type=0x02`) for one path segment, after validating
|
|
68
|
+
* it against the addressing rules (1..64 UTF-8 bytes, no reserved characters).
|
|
62
69
|
*
|
|
63
70
|
* @param segment the segment text
|
|
64
71
|
* @returns a NAME TLV node (no trailer)
|
|
@@ -75,8 +82,10 @@ export function nameTlv(segment) {
|
|
|
75
82
|
return { type: TYPE.NAME, opt: opt(), payload: bytes, children: [], trailer: null };
|
|
76
83
|
}
|
|
77
84
|
/**
|
|
78
|
-
* Build a PATH TLV (`type=0x06`, PL=1) from path segments — a NAME child
|
|
79
|
-
* segment.
|
|
85
|
+
* @brief Build a PATH TLV (`type=0x06`, PL=1) from path segments — a NAME child
|
|
86
|
+
* per segment.
|
|
87
|
+
*
|
|
88
|
+
* Vector-pinned: `path-sensor-temp`; normative byte layout: spec/v1.md §3.1.
|
|
80
89
|
*
|
|
81
90
|
* @param segments the path segments, e.g. `["sensor", "temp"]` for `/sensor/temp`
|
|
82
91
|
* @returns the encoded PATH TLV bytes
|
|
@@ -85,7 +94,7 @@ export function nameTlv(segment) {
|
|
|
85
94
|
export function encodePath(segments) {
|
|
86
95
|
return encode(pathTlv(segments));
|
|
87
96
|
}
|
|
88
|
-
/** The PATH TLV node (shared by {@link encodePath}, {@link encodeSubscriber}, and `./fwd.ts`). */
|
|
97
|
+
/** @brief The PATH TLV node (shared by {@link encodePath}, {@link encodeSubscriber}, and `./fwd.ts`). */
|
|
89
98
|
export function pathTlv(segments) {
|
|
90
99
|
if (segments.length < 1)
|
|
91
100
|
throw new RangeError('a path must have at least one segment');
|
|
@@ -100,8 +109,10 @@ export function pathTlv(segments) {
|
|
|
100
109
|
};
|
|
101
110
|
}
|
|
102
111
|
/**
|
|
103
|
-
* Build a SUBSCRIBER TLV (`type=0x04`, PL=1) wrapping a target PATH —
|
|
104
|
-
* payload of a subscribe-write (reference/04 §Subscribe).
|
|
112
|
+
* @brief Build a SUBSCRIBER TLV (`type=0x04`, PL=1) wrapping a target PATH —
|
|
113
|
+
* the payload of a subscribe-write (reference/04 §Subscribe).
|
|
114
|
+
*
|
|
115
|
+
* Vector-pinned:
|
|
105
116
|
* `subscriber-path` = `SUBSCRIBER{ PATH{ NAME "sensor", NAME "temp" } }`.
|
|
106
117
|
*
|
|
107
118
|
* The `targetPath` is the SUBSCRIBER's `target_path` child: where the producer
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@avatarsd-llc/libtracer-client",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.0",
|
|
4
4
|
"description": "EXPERIMENTAL libtracer client SDK (#56, ADR-0034/0035) — a path-addressed client over the cross-validated codec (@avatarsd-llc/libtracer) and an injected transport seam (e.g. @avatarsd-llc/libtracer-ws). Speaks the RFC-0004 remote operations over FWD: read / write / await / readField / subscribe, each a FWD frame whose source-routed FWD{REPLY} is decoded back. Pre-1.0 and experimental.",
|
|
5
5
|
"author": "avatarsd LLC",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -33,8 +33,8 @@
|
|
|
33
33
|
"access": "public"
|
|
34
34
|
},
|
|
35
35
|
"peerDependencies": {
|
|
36
|
-
"@avatarsd-llc/libtracer": ">=0.
|
|
37
|
-
"@avatarsd-llc/libtracer-ws": ">=0.
|
|
36
|
+
"@avatarsd-llc/libtracer": ">=0.4.0 <0.5.0",
|
|
37
|
+
"@avatarsd-llc/libtracer-ws": ">=0.4.0 <0.5.0"
|
|
38
38
|
},
|
|
39
39
|
"peerDependenciesMeta": {
|
|
40
40
|
"@avatarsd-llc/libtracer-ws": {
|