@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 +2 -1
- package/dist/client.d.ts +81 -42
- package/dist/client.js +108 -55
- package/dist/fwd.d.ts +73 -61
- package/dist/fwd.js +70 -57
- package/dist/index.d.ts +19 -2
- package/dist/index.js +17 -12
- package/dist/tlv.d.ts +75 -16
- package/dist/tlv.js +139 -23
- package/dist/topology.d.ts +178 -0
- package/dist/topology.js +151 -0
- package/package.json +3 -3
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,7 +1,24 @@
|
|
|
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';
|
|
4
|
-
export { encodeValue, encodePath, encodeSubscriber } from './tlv.js';
|
|
5
|
-
export type { ValueOptions, SubscriberOptions } from './tlv.js';
|
|
19
|
+
export { encodeValue, encodePath, encodeSubscriber, encodeConnSpec } from './tlv.js';
|
|
20
|
+
export type { ValueOptions, SubscriberOptions, ConnSpecOptions, ConnRole } from './tlv.js';
|
|
21
|
+
export { walkTopology, routeKey } from './topology.js';
|
|
22
|
+
export type { TopologyGraph, TopologyNode, TopologyEdge, TopologyBusPeers, WalkOptions, } from './topology.js';
|
|
6
23
|
export { FWD_OP, FWD_KIND, FWD_ERROR, FWD_ERROR_PATH, fwdErrorName, fwdErrorPath, fwdErrorCodeForPath, encodeFwd, encodeField, parseField, decodeFwd, parseFwdTlv, replyErrorCode, replyErrorPath, } from './fwd.js';
|
|
7
24
|
export type { FwdRequest, ParsedFwd, FieldLevel } from './fwd.js';
|
package/dist/index.js
CHANGED
|
@@ -1,17 +1,22 @@
|
|
|
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
|
-
export { encodeValue, encodePath, encodeSubscriber } from './tlv.js';
|
|
20
|
+
export { encodeValue, encodePath, encodeSubscriber, encodeConnSpec } from './tlv.js';
|
|
21
|
+
export { walkTopology, routeKey } from './topology.js';
|
|
17
22
|
export { FWD_OP, FWD_KIND, FWD_ERROR, FWD_ERROR_PATH, fwdErrorName, fwdErrorPath, fwdErrorCodeForPath, encodeFwd, encodeField, parseField, decodeFwd, parseFwdTlv, replyErrorCode, replyErrorPath, } from './fwd.js';
|