@avatarsd-llc/libtracer-client 0.1.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 +94 -35
- package/dist/client.js +162 -57
- package/dist/fwd.d.ts +92 -47
- package/dist/fwd.js +126 -44
- package/dist/index.d.ts +17 -2
- package/dist/index.js +17 -13
- package/dist/tlv.d.ts +23 -16
- package/dist/tlv.js +34 -23
- package/package.json +3 -3
package/dist/fwd.d.ts
CHANGED
|
@@ -1,52 +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
|
-
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
15
|
+
* @brief Registered wire ERROR codes for a `kind=ERROR` reply's
|
|
16
|
+
* `STATUS{ ERROR{ VALUE u16 } }` payload (RFC-0002 §D registry — the u16 LE
|
|
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.
|
|
18
21
|
*/
|
|
19
22
|
export declare const FWD_ERROR: Readonly<{
|
|
20
|
-
readonly
|
|
21
|
-
readonly
|
|
22
|
-
readonly
|
|
23
|
-
readonly
|
|
24
|
-
readonly
|
|
25
|
-
readonly
|
|
26
|
-
readonly
|
|
27
|
-
readonly
|
|
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 */
|
|
28
38
|
}>;
|
|
29
|
-
/**
|
|
39
|
+
/**
|
|
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()`.
|
|
45
|
+
*/
|
|
46
|
+
export declare const FWD_ERROR_PATH: Readonly<Record<number, string>>;
|
|
47
|
+
/** @brief The human name of a wire ERROR code (or `UNKNOWN(0x..)`). */
|
|
30
48
|
export declare function fwdErrorName(code: number): string;
|
|
31
|
-
/**
|
|
49
|
+
/** @brief The canonical `tr::…` path of a wire ERROR code (or `null` when unregistered). */
|
|
50
|
+
export declare function fwdErrorPath(code: number): string | null;
|
|
51
|
+
/**
|
|
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.
|
|
54
|
+
*/
|
|
55
|
+
export declare function fwdErrorCodeForPath(path: string): number;
|
|
56
|
+
/** @brief One level of a `:field` selector chain (RFC-0004 §C, one NAME + optional index). */
|
|
32
57
|
export interface FieldLevel {
|
|
33
|
-
/** The level's field name (e.g. `"subscribers"`, `"settings"`). */
|
|
58
|
+
/** @brief The level's field name (e.g. `"subscribers"`, `"settings"`). */
|
|
34
59
|
readonly name: string;
|
|
35
60
|
/**
|
|
36
|
-
* The index when this level is an element selector (`[N]`).
|
|
37
|
-
*
|
|
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}.
|
|
38
65
|
*/
|
|
39
66
|
readonly index?: number;
|
|
40
67
|
/**
|
|
41
|
-
* `SCALAR` (no brackets, default), `ELEMENT` (`[N]` / append `[]`), or
|
|
42
|
-
* (`[*]` — subscriber-path targets only).
|
|
68
|
+
* @brief `SCALAR` (no brackets, default), `ELEMENT` (`[N]` / append `[]`), or
|
|
69
|
+
* `WILDCARD` (`[*]` — subscriber-path targets only).
|
|
43
70
|
*/
|
|
44
71
|
readonly mode?: 'SCALAR' | 'ELEMENT' | 'WILDCARD';
|
|
45
72
|
}
|
|
46
73
|
/**
|
|
47
|
-
* Parse a `:field` selector string into its levels.
|
|
48
|
-
*
|
|
49
|
-
*
|
|
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).
|
|
50
78
|
*
|
|
51
79
|
* `":subscribers[]"` → `[{ name: "subscribers", mode: "ELEMENT" }]`;
|
|
52
80
|
* `":subscribers[3]"` → `[{ name: "subscribers", index: 3, mode: "ELEMENT" }]`;
|
|
@@ -58,36 +86,40 @@ export interface FieldLevel {
|
|
|
58
86
|
*/
|
|
59
87
|
export declare function parseField(field: string): FieldLevel[];
|
|
60
88
|
/**
|
|
61
|
-
* Build a FIELD TLV (`type=0x10`, PL=1) from a selector string or
|
|
62
|
-
* 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`.
|
|
63
93
|
*
|
|
64
94
|
* @param field a `:field` string (see {@link parseField}) or its levels
|
|
65
95
|
* @returns the encoded FIELD TLV bytes
|
|
66
96
|
*/
|
|
67
97
|
export declare function encodeField(field: string | FieldLevel[]): Uint8Array;
|
|
68
|
-
/** 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. */
|
|
69
99
|
export interface FwdRequest {
|
|
70
|
-
/** The operation (a {@link FWD_OP} value). */
|
|
100
|
+
/** @brief The operation (a {@link FWD_OP} value). */
|
|
71
101
|
readonly op: number;
|
|
72
|
-
/** Forward route: the unresolved destination path segments (the PATH `dst`). */
|
|
102
|
+
/** @brief Forward route: the unresolved destination path segments (the PATH `dst`). */
|
|
73
103
|
readonly dst: string[];
|
|
74
|
-
/** 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`). */
|
|
75
105
|
readonly src: string[];
|
|
76
|
-
/** Optional `:field` selector (string or levels). */
|
|
106
|
+
/** @brief Optional `:field` selector (string or levels). */
|
|
77
107
|
readonly field?: string | FieldLevel[];
|
|
78
108
|
/**
|
|
79
|
-
* Optional payload — a complete TLV's encoded bytes (a VALUE to WRITE,
|
|
80
|
-
* 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.
|
|
81
111
|
*/
|
|
82
112
|
readonly payload?: Uint8Array;
|
|
83
|
-
/** REPLY only — the reply {@link FWD_KIND}. */
|
|
113
|
+
/** @brief REPLY only — the reply {@link FWD_KIND}. */
|
|
84
114
|
readonly kind?: number;
|
|
85
|
-
/** 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). */
|
|
86
116
|
readonly awaitTimeoutNs?: bigint;
|
|
87
117
|
}
|
|
88
118
|
/**
|
|
89
|
-
* Build a FWD TLV (`type=0x0F`, PL=1) — the remote-operation envelope
|
|
90
|
-
* §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`.
|
|
91
123
|
* Vector-pinned: `fwd-read`, `fwd-write-value`, `fwd-await-timeout`,
|
|
92
124
|
* `fwd-write-subscriber-field`, `fwd-reply-result`, `fwd-reply-error`.
|
|
93
125
|
*
|
|
@@ -95,33 +127,46 @@ export interface FwdRequest {
|
|
|
95
127
|
* @returns the encoded FWD TLV bytes (one complete frame)
|
|
96
128
|
*/
|
|
97
129
|
export declare function encodeFwd(req: FwdRequest): Uint8Array;
|
|
98
|
-
/** 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). */
|
|
99
131
|
export interface ParsedFwd {
|
|
100
|
-
/** The operation (a {@link FWD_OP} value). */
|
|
132
|
+
/** @brief The operation (a {@link FWD_OP} value). */
|
|
101
133
|
readonly op: number;
|
|
102
|
-
/** The `dst` PATH child. */
|
|
134
|
+
/** @brief The `dst` PATH child. */
|
|
103
135
|
readonly dst: Tlv;
|
|
104
|
-
/** The optional FIELD selector child (or `null`). */
|
|
136
|
+
/** @brief The optional FIELD selector child (or `null`). */
|
|
105
137
|
readonly field: Tlv | null;
|
|
106
|
-
/** The `src` PATH child. */
|
|
138
|
+
/** @brief The `src` PATH child. */
|
|
107
139
|
readonly src: Tlv;
|
|
108
|
-
/** The reply {@link FWD_KIND} (REPLY frames only, else `null`). */
|
|
140
|
+
/** @brief The reply {@link FWD_KIND} (REPLY frames only, else `null`). */
|
|
109
141
|
readonly kind: number | null;
|
|
110
|
-
/** 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`. */
|
|
111
143
|
readonly payload: Tlv | null;
|
|
112
|
-
/** The AWAIT `await_timeout` ns (else `null`). */
|
|
144
|
+
/** @brief The AWAIT `await_timeout` ns (else `null`). */
|
|
113
145
|
readonly awaitTimeoutNs: bigint | null;
|
|
114
146
|
}
|
|
115
|
-
/** Parse an already-decoded FWD {@link Tlv} positionally (RFC-0004 §B). */
|
|
147
|
+
/** @brief Parse an already-decoded FWD {@link Tlv} positionally (RFC-0004 §B). */
|
|
116
148
|
export declare function parseFwdTlv(fwd: Tlv): ParsedFwd;
|
|
117
149
|
/**
|
|
118
|
-
* Decode a complete FWD frame's bytes into its parsed children.
|
|
150
|
+
* @brief Decode a complete FWD frame's bytes into its parsed children.
|
|
119
151
|
*
|
|
120
152
|
* @param bytes one complete FWD TLV frame
|
|
121
153
|
* @returns the parsed FWD
|
|
122
154
|
* @throws if the bytes do not decode, or are not a FWD
|
|
123
155
|
*/
|
|
124
156
|
export declare function decodeFwd(bytes: Uint8Array): ParsedFwd;
|
|
125
|
-
/**
|
|
157
|
+
/**
|
|
158
|
+
* @brief The registered wire ERROR code of a `kind=ERROR` reply's
|
|
159
|
+
* `STATUS{ ERROR{ VALUE u16 } }` payload per RFC-0002 (or 0 when absent, or
|
|
160
|
+
* when the ERROR carries the string-form NAME identity — see
|
|
161
|
+
* {@link replyErrorPath}).
|
|
162
|
+
*/
|
|
126
163
|
export declare function replyErrorCode(reply: ParsedFwd): number;
|
|
164
|
+
/**
|
|
165
|
+
* @brief The string-form `tr::…` identity of a `kind=ERROR` reply's
|
|
166
|
+
* `STATUS{ ERROR{ NAME utf8-path } }` payload per RFC-0002 (or `null` when the
|
|
167
|
+
* reply carries no ERROR, or a registered-code identity — see
|
|
168
|
+
* {@link replyErrorCode}).
|
|
169
|
+
*/
|
|
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. */
|
|
127
172
|
export type { Opt };
|
package/dist/fwd.js
CHANGED
|
@@ -1,73 +1,124 @@
|
|
|
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
|
-
*
|
|
32
|
-
*
|
|
33
|
-
*
|
|
35
|
+
* @brief Registered wire ERROR codes for a `kind=ERROR` reply's
|
|
36
|
+
* `STATUS{ ERROR{ VALUE u16 } }` payload (RFC-0002 §D registry — the u16 LE
|
|
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.
|
|
34
41
|
*/
|
|
35
42
|
export const FWD_ERROR = Object.freeze({
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
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 */,
|
|
58
|
+
});
|
|
59
|
+
/**
|
|
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()`.
|
|
65
|
+
*/
|
|
66
|
+
export const FWD_ERROR_PATH = Object.freeze({
|
|
67
|
+
[FWD_ERROR.FRAME_TRUNCATED]: 'tr::frame::truncated',
|
|
68
|
+
[FWD_ERROR.FRAME_INVALID]: 'tr::frame::invalid',
|
|
69
|
+
[FWD_ERROR.FRAME_CRC_FAIL]: 'tr::frame::crc_fail',
|
|
70
|
+
[FWD_ERROR.TLV_NESTING_TOO_DEEP]: 'tr::tlv::nesting_too_deep',
|
|
71
|
+
[FWD_ERROR.NOT_FOUND]: 'tr::path::not_found',
|
|
72
|
+
[FWD_ERROR.INVALID_PATH]: 'tr::path::invalid',
|
|
73
|
+
[FWD_ERROR.PATH_IN_USE]: 'tr::path::in_use',
|
|
74
|
+
[FWD_ERROR.TYPE_MISMATCH]: 'tr::schema::type_mismatch',
|
|
75
|
+
[FWD_ERROR.SCHEMA_NOT_FOUND]: 'tr::schema::not_found',
|
|
76
|
+
[FWD_ERROR.BACKPRESSURE]: 'tr::flow::backpressure',
|
|
77
|
+
[FWD_ERROR.TIMEOUT]: 'tr::flow::timeout',
|
|
78
|
+
[FWD_ERROR.ADDRESS_SHIFT_GAP]: 'tr::flow::address_shift_gap',
|
|
79
|
+
[FWD_ERROR.PERMISSION_DENIED]: 'tr::access::denied',
|
|
80
|
+
[FWD_ERROR.TRANSPORT_DOWN]: 'tr::transport::down',
|
|
81
|
+
[FWD_ERROR.VERSION_MISMATCH]: 'tr::version::mismatch',
|
|
44
82
|
});
|
|
45
83
|
const FWD_ERROR_NAME = Object.freeze(Object.fromEntries(Object.entries(FWD_ERROR).map(([k, v]) => [v, k])));
|
|
46
|
-
|
|
84
|
+
const FWD_ERROR_CODE_BY_PATH = Object.freeze(Object.fromEntries(Object.entries(FWD_ERROR_PATH).map(([code, path]) => [path, Number(code)])));
|
|
85
|
+
/** @brief The human name of a wire ERROR code (or `UNKNOWN(0x..)`). */
|
|
47
86
|
export function fwdErrorName(code) {
|
|
48
87
|
return FWD_ERROR_NAME[code] ?? `UNKNOWN(0x${code.toString(16)})`;
|
|
49
88
|
}
|
|
89
|
+
/** @brief The canonical `tr::…` path of a wire ERROR code (or `null` when unregistered). */
|
|
90
|
+
export function fwdErrorPath(code) {
|
|
91
|
+
return FWD_ERROR_PATH[code] ?? null;
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
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.
|
|
96
|
+
*/
|
|
97
|
+
export function fwdErrorCodeForPath(path) {
|
|
98
|
+
return FWD_ERROR_CODE_BY_PATH[path] ?? 0;
|
|
99
|
+
}
|
|
50
100
|
/* ----------------------------------------------------------- value nodes --- */
|
|
51
|
-
/** A 1-byte VALUE TLV node (the op / kind discriminants). */
|
|
101
|
+
/** @brief A 1-byte VALUE TLV node (the op / kind discriminants). */
|
|
52
102
|
function valueU8(v) {
|
|
53
103
|
return { type: TYPE.VALUE, opt: opt(), payload: Uint8Array.of(v & 0xff), children: [], trailer: null };
|
|
54
104
|
}
|
|
55
|
-
/** A little-endian u32 VALUE TLV node (a FIELD `[N]` index). */
|
|
105
|
+
/** @brief A little-endian u32 VALUE TLV node (a FIELD `[N]` index). */
|
|
56
106
|
function valueU32(v) {
|
|
57
107
|
const p = new Uint8Array(4);
|
|
58
108
|
new DataView(p.buffer).setUint32(0, v >>> 0, true);
|
|
59
109
|
return { type: TYPE.VALUE, opt: opt(), payload: p, children: [], trailer: null };
|
|
60
110
|
}
|
|
61
|
-
/** 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). */
|
|
62
112
|
function valueU64(v) {
|
|
63
113
|
const p = new Uint8Array(8);
|
|
64
114
|
new DataView(p.buffer).setBigUint64(0, v, true);
|
|
65
115
|
return { type: TYPE.VALUE, opt: opt(), payload: p, children: [], trailer: null };
|
|
66
116
|
}
|
|
67
117
|
/**
|
|
68
|
-
* Parse a `:field` selector string into its levels.
|
|
69
|
-
*
|
|
70
|
-
*
|
|
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).
|
|
71
122
|
*
|
|
72
123
|
* `":subscribers[]"` → `[{ name: "subscribers", mode: "ELEMENT" }]`;
|
|
73
124
|
* `":subscribers[3]"` → `[{ name: "subscribers", index: 3, mode: "ELEMENT" }]`;
|
|
@@ -95,7 +146,7 @@ export function parseField(field) {
|
|
|
95
146
|
return { name, index: Number(m[2]), mode: 'ELEMENT' };
|
|
96
147
|
});
|
|
97
148
|
}
|
|
98
|
-
/** Build a FIELD TLV node from its levels (RFC-0004 §C). */
|
|
149
|
+
/** @brief Build a FIELD TLV node from its levels (RFC-0004 §C). */
|
|
99
150
|
function fieldTlv(levels) {
|
|
100
151
|
if (levels.length < 1)
|
|
101
152
|
throw new RangeError('a FIELD selector needs at least one level');
|
|
@@ -118,8 +169,10 @@ function fieldTlv(levels) {
|
|
|
118
169
|
return { type: TYPE.FIELD, opt: opt({ pl: true }), payload: new Uint8Array(0), children, trailer: null };
|
|
119
170
|
}
|
|
120
171
|
/**
|
|
121
|
-
* Build a FIELD TLV (`type=0x10`, PL=1) from a selector string or
|
|
122
|
-
* 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`.
|
|
123
176
|
*
|
|
124
177
|
* @param field a `:field` string (see {@link parseField}) or its levels
|
|
125
178
|
* @returns the encoded FIELD TLV bytes
|
|
@@ -127,13 +180,15 @@ function fieldTlv(levels) {
|
|
|
127
180
|
export function encodeField(field) {
|
|
128
181
|
return encode(fieldTlv(typeof field === 'string' ? parseField(field) : field));
|
|
129
182
|
}
|
|
130
|
-
/** 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). */
|
|
131
184
|
function payloadNode(payload) {
|
|
132
185
|
return decode(payload);
|
|
133
186
|
}
|
|
134
187
|
/**
|
|
135
|
-
* Build a FWD TLV (`type=0x0F`, PL=1) — the remote-operation envelope
|
|
136
|
-
* §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`.
|
|
137
192
|
* Vector-pinned: `fwd-read`, `fwd-write-value`, `fwd-await-timeout`,
|
|
138
193
|
* `fwd-write-subscriber-field`, `fwd-reply-result`, `fwd-reply-error`.
|
|
139
194
|
*
|
|
@@ -169,7 +224,7 @@ export function encodeFwd(req) {
|
|
|
169
224
|
return encode(fwd);
|
|
170
225
|
}
|
|
171
226
|
const u8 = (t) => (t.payload.length > 0 ? t.payload[0] : 0);
|
|
172
|
-
/** Parse an already-decoded FWD {@link Tlv} positionally (RFC-0004 §B). */
|
|
227
|
+
/** @brief Parse an already-decoded FWD {@link Tlv} positionally (RFC-0004 §B). */
|
|
173
228
|
export function parseFwdTlv(fwd) {
|
|
174
229
|
if (fwd.type !== TYPE.FWD)
|
|
175
230
|
throw new RangeError(`not a FWD TLV (type 0x${fwd.type.toString(16)})`);
|
|
@@ -209,7 +264,7 @@ export function parseFwdTlv(fwd) {
|
|
|
209
264
|
return { op, dst, field, src, kind, payload, awaitTimeoutNs };
|
|
210
265
|
}
|
|
211
266
|
/**
|
|
212
|
-
* Decode a complete FWD frame's bytes into its parsed children.
|
|
267
|
+
* @brief Decode a complete FWD frame's bytes into its parsed children.
|
|
213
268
|
*
|
|
214
269
|
* @param bytes one complete FWD TLV frame
|
|
215
270
|
* @returns the parsed FWD
|
|
@@ -218,11 +273,38 @@ export function parseFwdTlv(fwd) {
|
|
|
218
273
|
export function decodeFwd(bytes) {
|
|
219
274
|
return parseFwdTlv(decode(bytes));
|
|
220
275
|
}
|
|
221
|
-
/** The
|
|
222
|
-
|
|
276
|
+
/** @brief The ERROR TLV of a `kind=ERROR` reply's STATUS payload, or `null`. */
|
|
277
|
+
function replyErrorTlv(reply) {
|
|
223
278
|
const status = reply.payload;
|
|
224
279
|
if (status && status.type === TYPE.STATUS && status.children[0]?.type === TYPE.ERROR) {
|
|
225
|
-
return
|
|
280
|
+
return status.children[0];
|
|
281
|
+
}
|
|
282
|
+
return null;
|
|
283
|
+
}
|
|
284
|
+
/**
|
|
285
|
+
* @brief The registered wire ERROR code of a `kind=ERROR` reply's
|
|
286
|
+
* `STATUS{ ERROR{ VALUE u16 } }` payload per RFC-0002 (or 0 when absent, or
|
|
287
|
+
* when the ERROR carries the string-form NAME identity — see
|
|
288
|
+
* {@link replyErrorPath}).
|
|
289
|
+
*/
|
|
290
|
+
export function replyErrorCode(reply) {
|
|
291
|
+
const err = replyErrorTlv(reply);
|
|
292
|
+
const id = err?.children[0];
|
|
293
|
+
if (id?.type === TYPE.VALUE && id.payload.length >= 2) {
|
|
294
|
+
return id.payload[0] | (id.payload[1] << 8); // u16 LE registered code
|
|
226
295
|
}
|
|
227
296
|
return 0;
|
|
228
297
|
}
|
|
298
|
+
/**
|
|
299
|
+
* @brief The string-form `tr::…` identity of a `kind=ERROR` reply's
|
|
300
|
+
* `STATUS{ ERROR{ NAME utf8-path } }` payload per RFC-0002 (or `null` when the
|
|
301
|
+
* reply carries no ERROR, or a registered-code identity — see
|
|
302
|
+
* {@link replyErrorCode}).
|
|
303
|
+
*/
|
|
304
|
+
export function replyErrorPath(reply) {
|
|
305
|
+
const err = replyErrorTlv(reply);
|
|
306
|
+
const id = err?.children[0];
|
|
307
|
+
if (id?.type === TYPE.NAME)
|
|
308
|
+
return new TextDecoder().decode(id.payload);
|
|
309
|
+
return null;
|
|
310
|
+
}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,22 @@
|
|
|
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
|
-
export { LibtracerClient, FwdError } from './client.js';
|
|
17
|
+
export { LibtracerClient, FwdError, CompactFlowError } from './client.js';
|
|
3
18
|
export type { ClientTransport, ValueHandler, Unsubscribe, ClientOptions, } from './client.js';
|
|
4
19
|
export { encodeValue, encodePath, encodeSubscriber } from './tlv.js';
|
|
5
20
|
export type { ValueOptions, SubscriberOptions } from './tlv.js';
|
|
6
|
-
export { FWD_OP, FWD_KIND, FWD_ERROR, fwdErrorName, encodeFwd, encodeField, parseField, decodeFwd, parseFwdTlv, replyErrorCode, } from './fwd.js';
|
|
21
|
+
export { FWD_OP, FWD_KIND, FWD_ERROR, FWD_ERROR_PATH, fwdErrorName, fwdErrorPath, fwdErrorCodeForPath, encodeFwd, encodeField, parseField, decodeFwd, parseFwdTlv, replyErrorCode, replyErrorPath, } from './fwd.js';
|
|
7
22
|
export type { FwdRequest, ParsedFwd, FieldLevel } from './fwd.js';
|
package/dist/index.js
CHANGED
|
@@ -1,17 +1,21 @@
|
|
|
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
|
-
export { LibtracerClient, FwdError } from './client.js';
|
|
19
|
+
export { LibtracerClient, FwdError, CompactFlowError } from './client.js';
|
|
16
20
|
export { encodeValue, encodePath, encodeSubscriber } from './tlv.js';
|
|
17
|
-
export { FWD_OP, FWD_KIND, FWD_ERROR, fwdErrorName, encodeFwd, encodeField, parseField, decodeFwd, parseFwdTlv, replyErrorCode, } from './fwd.js';
|
|
21
|
+
export { FWD_OP, FWD_KIND, FWD_ERROR, FWD_ERROR_PATH, fwdErrorName, fwdErrorPath, fwdErrorCodeForPath, encodeFwd, encodeField, parseField, decodeFwd, parseFwdTlv, replyErrorCode, replyErrorPath, } from './fwd.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
|