@avatarsd-llc/libtracer-client 0.1.0 → 0.3.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 +47 -6
- package/dist/client.js +95 -13
- package/dist/fwd.d.ts +45 -12
- package/dist/fwd.js +83 -14
- package/dist/index.d.ts +2 -2
- package/dist/index.js +2 -2
- package/package.json +3 -3
package/dist/client.d.ts
CHANGED
|
@@ -11,6 +11,13 @@ export interface ClientTransport {
|
|
|
11
11
|
send(frame: Uint8Array): void;
|
|
12
12
|
/** Register (or clear with `null`) the inbound-frame receiver. */
|
|
13
13
|
onFrame(receiver: ((bytes: Uint8Array) => void) | null): void;
|
|
14
|
+
/**
|
|
15
|
+
* Register (or clear with `null`) the connection-closed notifier — invoked once
|
|
16
|
+
* when the underlying connection closes or errors out, with the cause when one
|
|
17
|
+
* is known. OPTIONAL: a transport without it never notifies the client of a
|
|
18
|
+
* close, so pending requests only fail by timeout.
|
|
19
|
+
*/
|
|
20
|
+
onClose?(handler: ((cause?: Error) => void) | null): void;
|
|
14
21
|
}
|
|
15
22
|
/** A delivered VALUE: its opaque payload bytes plus the decoded TLV it came from. */
|
|
16
23
|
export type ValueHandler = (value: Uint8Array, tlv: Tlv) => void;
|
|
@@ -25,18 +32,48 @@ export interface ClientOptions {
|
|
|
25
32
|
* is fine; default `["client"]`.
|
|
26
33
|
*/
|
|
27
34
|
readonly replyEndpoint?: string[];
|
|
35
|
+
/**
|
|
36
|
+
* Per-request deadline in milliseconds: a one-shot op whose FWD{REPLY} has not
|
|
37
|
+
* arrived within this window rejects with a timeout {@link Error}. Default
|
|
38
|
+
* 10 000 ms; pass `0` (or `Infinity`) to disable the deadline.
|
|
39
|
+
*/
|
|
40
|
+
readonly requestTimeoutMs?: number;
|
|
28
41
|
}
|
|
29
42
|
/**
|
|
30
|
-
* A `kind=ERROR` FWD reply, surfaced as a typed rejection. `.code` is the
|
|
31
|
-
* ERROR
|
|
43
|
+
* A `kind=ERROR` FWD reply, surfaced as a typed rejection. `.code` is the
|
|
44
|
+
* registered u16 wire ERROR code (see {@link FWD_ERROR}); `.codeName` its
|
|
45
|
+
* symbolic name.
|
|
32
46
|
*/
|
|
33
47
|
export declare class FwdError extends Error {
|
|
34
|
-
/** The wire ERROR code (a {@link FWD_ERROR} value). */
|
|
48
|
+
/** The registered u16 wire ERROR code (a {@link FWD_ERROR} value). */
|
|
35
49
|
readonly code: number;
|
|
36
50
|
/** The symbolic ERROR name (e.g. `"NOT_FOUND"`, `"TIMEOUT"`). */
|
|
37
51
|
readonly codeName: string;
|
|
38
|
-
/**
|
|
39
|
-
|
|
52
|
+
/**
|
|
53
|
+
* The canonical `tr::<concept>::<error>` namespace path (RFC-0002 §A) — from
|
|
54
|
+
* the frozen registry for a registered code, or carried verbatim by a
|
|
55
|
+
* string-form (NAME identity) ERROR reply. `null` when neither is known.
|
|
56
|
+
*/
|
|
57
|
+
readonly path: string | null;
|
|
58
|
+
/**
|
|
59
|
+
* @param code the registered u16 code carried in the reply's
|
|
60
|
+
* `STATUS{ ERROR{ VALUE u16 } }` per RFC-0002 (0 when absent)
|
|
61
|
+
* @param path the string-form `tr::…` identity when the reply carried a
|
|
62
|
+
* `STATUS{ ERROR{ NAME utf8-path } }` instead of a registered code
|
|
63
|
+
*/
|
|
64
|
+
constructor(code: number, path?: string | null);
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* An inbound ADVERTISE (`0x11`) / COMPACT (`0x12`) frame reached this client,
|
|
68
|
+
* which does not implement the RFC-0004 compact (route-handle) delivery flow
|
|
69
|
+
* yet. Routed to {@link LibtracerClient.onError} so the failure is diagnosable
|
|
70
|
+
* instead of a silent drop; the sender should fall back to plain FWD delivery.
|
|
71
|
+
*/
|
|
72
|
+
export declare class CompactFlowError extends Error {
|
|
73
|
+
/** The offending wire type code (`0x11` ADVERTISE or `0x12` COMPACT). */
|
|
74
|
+
readonly frameType: number;
|
|
75
|
+
/** @param frameType the inbound frame's wire type code */
|
|
76
|
+
constructor(frameType: number);
|
|
40
77
|
}
|
|
41
78
|
/**
|
|
42
79
|
* A WebSocket/transport-agnostic libtracer client over the RFC-0004 `FWD` plane.
|
|
@@ -50,14 +87,18 @@ export declare class FwdError extends Error {
|
|
|
50
87
|
export declare class LibtracerClient {
|
|
51
88
|
private readonly transport;
|
|
52
89
|
private readonly replyEndpoint;
|
|
90
|
+
private readonly requestTimeoutMs;
|
|
53
91
|
private readonly valueHandlers;
|
|
54
92
|
private readonly pending;
|
|
55
93
|
private errorHandler;
|
|
94
|
+
private closed;
|
|
56
95
|
/**
|
|
57
96
|
* @param transport the injected connection seam (e.g. a connected `TransportWs`).
|
|
58
|
-
* @param options optional reply-endpoint
|
|
97
|
+
* @param options optional reply-endpoint / request-timeout overrides.
|
|
59
98
|
*/
|
|
60
99
|
constructor(transport: ClientTransport, options?: ClientOptions);
|
|
100
|
+
/** Reject every pending request when the transport closes; fail-fast afterwards. */
|
|
101
|
+
private handleClose;
|
|
61
102
|
/**
|
|
62
103
|
* Register a handler for inbound VALUE deliveries. A delivery is a FWD{WRITE}
|
|
63
104
|
* (delivery-is-a-write, RFC-0004 §D); a bare VALUE or a single ROUTER wrapper is
|
package/dist/client.js
CHANGED
|
@@ -24,19 +24,58 @@
|
|
|
24
24
|
// end-to-end correlation id.
|
|
25
25
|
import { TYPE, decode, CodecError } from '@avatarsd-llc/libtracer';
|
|
26
26
|
import { encodeValue, encodePath, encodeSubscriber } from './tlv.js';
|
|
27
|
-
import { FWD_OP, FWD_KIND, encodeFwd, parseFwdTlv, replyErrorCode, fwdErrorName } from './fwd.js';
|
|
27
|
+
import { FWD_OP, FWD_KIND, encodeFwd, parseFwdTlv, replyErrorCode, replyErrorPath, fwdErrorName, fwdErrorPath, fwdErrorCodeForPath, } from './fwd.js';
|
|
28
28
|
/**
|
|
29
|
-
* A `kind=ERROR` FWD reply, surfaced as a typed rejection. `.code` is the
|
|
30
|
-
* ERROR
|
|
29
|
+
* A `kind=ERROR` FWD reply, surfaced as a typed rejection. `.code` is the
|
|
30
|
+
* registered u16 wire ERROR code (see {@link FWD_ERROR}); `.codeName` its
|
|
31
|
+
* symbolic name.
|
|
31
32
|
*/
|
|
32
33
|
export class FwdError extends Error {
|
|
33
|
-
/**
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
34
|
+
/**
|
|
35
|
+
* @param code the registered u16 code carried in the reply's
|
|
36
|
+
* `STATUS{ ERROR{ VALUE u16 } }` per RFC-0002 (0 when absent)
|
|
37
|
+
* @param path the string-form `tr::…` identity when the reply carried a
|
|
38
|
+
* `STATUS{ ERROR{ NAME utf8-path } }` instead of a registered code
|
|
39
|
+
*/
|
|
40
|
+
constructor(code, path) {
|
|
41
|
+
// A string-form identity that names a registered error resolves back to its
|
|
42
|
+
// code, so both wire forms surface identically (never UNKNOWN).
|
|
43
|
+
const resolved = code === 0 && path ? fwdErrorCodeForPath(path) : code;
|
|
44
|
+
const trPath = path ?? fwdErrorPath(resolved);
|
|
45
|
+
const name = resolved === 0 && trPath ? trPath : fwdErrorName(resolved);
|
|
46
|
+
super(`FWD reply ERROR ${name} (0x${resolved.toString(16).padStart(4, '0')})`);
|
|
37
47
|
this.name = 'FwdError';
|
|
38
|
-
this.code =
|
|
48
|
+
this.code = resolved;
|
|
39
49
|
this.codeName = name;
|
|
50
|
+
this.path = trPath;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
/** ADVERTISE (`0x11`) — a route-handle label binding (RFC-0004 route handles). */
|
|
54
|
+
const TYPE_ADVERTISE = 0x11;
|
|
55
|
+
/** COMPACT (`0x12`) — a label-compacted delivery (RFC-0004 route handles). */
|
|
56
|
+
const TYPE_COMPACT = 0x12;
|
|
57
|
+
/**
|
|
58
|
+
* An inbound ADVERTISE (`0x11`) / COMPACT (`0x12`) frame reached this client,
|
|
59
|
+
* which does not implement the RFC-0004 compact (route-handle) delivery flow
|
|
60
|
+
* yet. Routed to {@link LibtracerClient.onError} so the failure is diagnosable
|
|
61
|
+
* instead of a silent drop; the sender should fall back to plain FWD delivery.
|
|
62
|
+
*/
|
|
63
|
+
export class CompactFlowError extends Error {
|
|
64
|
+
/** @param frameType the inbound frame's wire type code */
|
|
65
|
+
constructor(frameType) {
|
|
66
|
+
const kind = frameType === TYPE_ADVERTISE ? 'ADVERTISE' : 'COMPACT';
|
|
67
|
+
super(`inbound ${kind} (0x${frameType.toString(16).padStart(2, '0')}) dropped: ` +
|
|
68
|
+
'compact (route-handle) delivery is not supported by this client yet');
|
|
69
|
+
this.name = 'CompactFlowError';
|
|
70
|
+
this.frameType = frameType;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
/** Settle a pending entry: clear its deadline and mark it consumed. */
|
|
74
|
+
function settle(p) {
|
|
75
|
+
p.settled = true;
|
|
76
|
+
if (p.timer !== null) {
|
|
77
|
+
clearTimeout(p.timer);
|
|
78
|
+
p.timer = null;
|
|
40
79
|
}
|
|
41
80
|
}
|
|
42
81
|
/**
|
|
@@ -51,15 +90,29 @@ export class FwdError extends Error {
|
|
|
51
90
|
export class LibtracerClient {
|
|
52
91
|
/**
|
|
53
92
|
* @param transport the injected connection seam (e.g. a connected `TransportWs`).
|
|
54
|
-
* @param options optional reply-endpoint
|
|
93
|
+
* @param options optional reply-endpoint / request-timeout overrides.
|
|
55
94
|
*/
|
|
56
95
|
constructor(transport, options = {}) {
|
|
57
96
|
this.valueHandlers = new Set();
|
|
58
97
|
this.pending = [];
|
|
59
98
|
this.errorHandler = null;
|
|
99
|
+
this.closed = null;
|
|
60
100
|
this.transport = transport;
|
|
61
101
|
this.replyEndpoint = [...(options.replyEndpoint ?? ['client'])];
|
|
102
|
+
this.requestTimeoutMs = options.requestTimeoutMs ?? 10000;
|
|
62
103
|
transport.onFrame((bytes) => this.dispatch(bytes));
|
|
104
|
+
transport.onClose?.((cause) => this.handleClose(cause));
|
|
105
|
+
}
|
|
106
|
+
/** Reject every pending request when the transport closes; fail-fast afterwards. */
|
|
107
|
+
handleClose(cause) {
|
|
108
|
+
this.closed = new Error('transport closed' + (cause ? `: ${cause.message}` : ''));
|
|
109
|
+
for (const p of this.pending) {
|
|
110
|
+
if (p.settled)
|
|
111
|
+
continue;
|
|
112
|
+
settle(p);
|
|
113
|
+
p.reject(this.closed);
|
|
114
|
+
}
|
|
115
|
+
this.pending.length = 0;
|
|
63
116
|
}
|
|
64
117
|
/* ---------------------------------------------------------- inbound --- */
|
|
65
118
|
/**
|
|
@@ -95,8 +148,12 @@ export class LibtracerClient {
|
|
|
95
148
|
}
|
|
96
149
|
if (parsed.op === FWD_OP.REPLY) {
|
|
97
150
|
const waiter = this.pending.shift();
|
|
98
|
-
|
|
151
|
+
// A settled waiter (timed out) still consumes its FIFO slot; its late
|
|
152
|
+
// reply is dropped so later requests stay correlated.
|
|
153
|
+
if (waiter && !waiter.settled) {
|
|
154
|
+
settle(waiter);
|
|
99
155
|
waiter.resolve(parsed);
|
|
156
|
+
}
|
|
100
157
|
return;
|
|
101
158
|
}
|
|
102
159
|
// A delivery IS a FWD{WRITE} (RFC-0004 §D): deliver its VALUE payload.
|
|
@@ -105,6 +162,12 @@ export class LibtracerClient {
|
|
|
105
162
|
}
|
|
106
163
|
return;
|
|
107
164
|
}
|
|
165
|
+
// The compact (route-handle) flow is not implemented here: surface it loudly
|
|
166
|
+
// rather than silently dropping the delivery (v0.1 client limitation).
|
|
167
|
+
if (tlv.type === TYPE_ADVERTISE || tlv.type === TYPE_COMPACT) {
|
|
168
|
+
this.emitError(new CompactFlowError(tlv.type));
|
|
169
|
+
return;
|
|
170
|
+
}
|
|
108
171
|
// Non-FWD frame: shed exactly one ROUTER envelope, then deliver a VALUE
|
|
109
172
|
// (the directly-delivered / bridge-mounted path, ADR-0034 inbound rule).
|
|
110
173
|
const data = tlv.type === TYPE.ROUTER && tlv.children.length > 0 ? tlv.children[tlv.children.length - 1] : tlv;
|
|
@@ -122,20 +185,39 @@ export class LibtracerClient {
|
|
|
122
185
|
/** Send a one-shot FWD and resolve its FWD{REPLY} (FIFO correlation). */
|
|
123
186
|
request(frame) {
|
|
124
187
|
return new Promise((resolve, reject) => {
|
|
125
|
-
this.
|
|
188
|
+
if (this.closed) {
|
|
189
|
+
reject(this.closed);
|
|
190
|
+
return;
|
|
191
|
+
}
|
|
192
|
+
const entry = { resolve, reject, settled: false, timer: null };
|
|
193
|
+
if (this.requestTimeoutMs > 0 && Number.isFinite(this.requestTimeoutMs)) {
|
|
194
|
+
entry.timer = setTimeout(() => {
|
|
195
|
+
// Leave the settled entry in the FIFO (see Pending) — its slot is
|
|
196
|
+
// consumed by the late reply, if one ever arrives.
|
|
197
|
+
settle(entry);
|
|
198
|
+
entry.reject(new Error(`request timed out after ${this.requestTimeoutMs}ms (no FWD reply)`));
|
|
199
|
+
}, this.requestTimeoutMs);
|
|
200
|
+
// Don't hold a Node event loop open for a pending deadline (no-op in browsers).
|
|
201
|
+
entry.timer.unref?.();
|
|
202
|
+
}
|
|
203
|
+
this.pending.push(entry);
|
|
126
204
|
try {
|
|
127
205
|
this.transport.send(frame);
|
|
128
206
|
}
|
|
129
207
|
catch (err) {
|
|
130
208
|
this.pending.pop();
|
|
209
|
+
settle(entry);
|
|
131
210
|
reject(err instanceof Error ? err : new Error(String(err)));
|
|
132
211
|
}
|
|
133
212
|
});
|
|
134
213
|
}
|
|
135
214
|
/** Turn a RESULT reply into its payload TLV; throw {@link FwdError} on ERROR. */
|
|
136
215
|
result(reply) {
|
|
137
|
-
if (reply.kind === FWD_KIND.ERROR)
|
|
138
|
-
|
|
216
|
+
if (reply.kind === FWD_KIND.ERROR) {
|
|
217
|
+
// Registered-code and string-form (NAME tr::… path) identities both
|
|
218
|
+
// surface typed — a known path resolves back to its code, never UNKNOWN.
|
|
219
|
+
throw new FwdError(replyErrorCode(reply), replyErrorPath(reply));
|
|
220
|
+
}
|
|
139
221
|
return reply.payload;
|
|
140
222
|
}
|
|
141
223
|
/* --------------------------------------------------------- one-shot --- */
|
package/dist/fwd.d.ts
CHANGED
|
@@ -12,22 +12,43 @@ export declare const FWD_KIND: Readonly<{
|
|
|
12
12
|
readonly ERROR: 1;
|
|
13
13
|
}>;
|
|
14
14
|
/**
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
15
|
+
* 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). Mirrors the C++ reference
|
|
18
|
+
* `error.hpp` registry / `op_resolve.cpp` `error_code()` map.
|
|
18
19
|
*/
|
|
19
20
|
export declare const FWD_ERROR: Readonly<{
|
|
20
|
-
readonly
|
|
21
|
-
readonly
|
|
22
|
-
readonly
|
|
23
|
-
readonly
|
|
24
|
-
readonly
|
|
25
|
-
readonly
|
|
26
|
-
readonly
|
|
27
|
-
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;
|
|
28
36
|
}>;
|
|
37
|
+
/**
|
|
38
|
+
* The canonical `tr::<concept>::<error>` namespace path of each registered code
|
|
39
|
+
* (RFC-0002 §A/§D) — the string identity a NAME-form ERROR carries. Mirrors the
|
|
40
|
+
* C++ reference `error.hpp` `err_path()`.
|
|
41
|
+
*/
|
|
42
|
+
export declare const FWD_ERROR_PATH: Readonly<Record<number, string>>;
|
|
29
43
|
/** The human name of a wire ERROR code (or `UNKNOWN(0x..)`). */
|
|
30
44
|
export declare function fwdErrorName(code: number): string;
|
|
45
|
+
/** The canonical `tr::…` path of a wire ERROR code (or `null` when unregistered). */
|
|
46
|
+
export declare function fwdErrorPath(code: number): string | null;
|
|
47
|
+
/**
|
|
48
|
+
* The registered u16 code of a `tr::…` error path (RFC-0002 §A/§D), or 0 when
|
|
49
|
+
* the path is not in the frozen registry.
|
|
50
|
+
*/
|
|
51
|
+
export declare function fwdErrorCodeForPath(path: string): number;
|
|
31
52
|
/** One level of a `:field` selector chain (RFC-0004 §C, one NAME + optional index). */
|
|
32
53
|
export interface FieldLevel {
|
|
33
54
|
/** The level's field name (e.g. `"subscribers"`, `"settings"`). */
|
|
@@ -122,6 +143,18 @@ export declare function parseFwdTlv(fwd: Tlv): ParsedFwd;
|
|
|
122
143
|
* @throws if the bytes do not decode, or are not a FWD
|
|
123
144
|
*/
|
|
124
145
|
export declare function decodeFwd(bytes: Uint8Array): ParsedFwd;
|
|
125
|
-
/**
|
|
146
|
+
/**
|
|
147
|
+
* The registered wire ERROR code of a `kind=ERROR` reply's
|
|
148
|
+
* `STATUS{ ERROR{ VALUE u16 } }` payload per RFC-0002 (or 0 when absent, or
|
|
149
|
+
* when the ERROR carries the string-form NAME identity — see
|
|
150
|
+
* {@link replyErrorPath}).
|
|
151
|
+
*/
|
|
126
152
|
export declare function replyErrorCode(reply: ParsedFwd): number;
|
|
153
|
+
/**
|
|
154
|
+
* The string-form `tr::…` identity of a `kind=ERROR` reply's
|
|
155
|
+
* `STATUS{ ERROR{ NAME utf8-path } }` payload per RFC-0002 (or `null` when the
|
|
156
|
+
* reply carries no ERROR, or a registered-code identity — see
|
|
157
|
+
* {@link replyErrorCode}).
|
|
158
|
+
*/
|
|
159
|
+
export declare function replyErrorPath(reply: ParsedFwd): string | null;
|
|
127
160
|
export type { Opt };
|
package/dist/fwd.js
CHANGED
|
@@ -28,25 +28,67 @@ export const FWD_KIND = Object.freeze({
|
|
|
28
28
|
ERROR: 1,
|
|
29
29
|
});
|
|
30
30
|
/**
|
|
31
|
-
*
|
|
32
|
-
*
|
|
33
|
-
*
|
|
31
|
+
* Registered wire ERROR codes for a `kind=ERROR` reply's
|
|
32
|
+
* `STATUS{ ERROR{ VALUE u16 } }` payload (RFC-0002 §D registry — the u16 LE
|
|
33
|
+
* identity of each built-in `tr::…` error path). Mirrors the C++ reference
|
|
34
|
+
* `error.hpp` registry / `op_resolve.cpp` `error_code()` map.
|
|
34
35
|
*/
|
|
35
36
|
export const FWD_ERROR = Object.freeze({
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
37
|
+
FRAME_TRUNCATED: 0x0001, // tr::frame::truncated
|
|
38
|
+
FRAME_INVALID: 0x0002, // tr::frame::invalid
|
|
39
|
+
FRAME_CRC_FAIL: 0x0003, // tr::frame::crc_fail
|
|
40
|
+
TLV_NESTING_TOO_DEEP: 0x0010, // tr::tlv::nesting_too_deep
|
|
41
|
+
NOT_FOUND: 0x0020, // tr::path::not_found
|
|
42
|
+
INVALID_PATH: 0x0021, // tr::path::invalid
|
|
43
|
+
PATH_IN_USE: 0x0022, // tr::path::in_use
|
|
44
|
+
TYPE_MISMATCH: 0x0030, // tr::schema::type_mismatch
|
|
45
|
+
SCHEMA_NOT_FOUND: 0x0031, // tr::schema::not_found
|
|
46
|
+
BACKPRESSURE: 0x0040, // tr::flow::backpressure
|
|
47
|
+
TIMEOUT: 0x0041, // tr::flow::timeout
|
|
48
|
+
ADDRESS_SHIFT_GAP: 0x0042, // tr::flow::address_shift_gap
|
|
49
|
+
PERMISSION_DENIED: 0x0050, // tr::access::denied
|
|
50
|
+
TRANSPORT_DOWN: 0x0060, // tr::transport::down
|
|
51
|
+
VERSION_MISMATCH: 0x0070, // tr::version::mismatch
|
|
52
|
+
});
|
|
53
|
+
/**
|
|
54
|
+
* The canonical `tr::<concept>::<error>` namespace path of each registered code
|
|
55
|
+
* (RFC-0002 §A/§D) — the string identity a NAME-form ERROR carries. Mirrors the
|
|
56
|
+
* C++ reference `error.hpp` `err_path()`.
|
|
57
|
+
*/
|
|
58
|
+
export const FWD_ERROR_PATH = Object.freeze({
|
|
59
|
+
[FWD_ERROR.FRAME_TRUNCATED]: 'tr::frame::truncated',
|
|
60
|
+
[FWD_ERROR.FRAME_INVALID]: 'tr::frame::invalid',
|
|
61
|
+
[FWD_ERROR.FRAME_CRC_FAIL]: 'tr::frame::crc_fail',
|
|
62
|
+
[FWD_ERROR.TLV_NESTING_TOO_DEEP]: 'tr::tlv::nesting_too_deep',
|
|
63
|
+
[FWD_ERROR.NOT_FOUND]: 'tr::path::not_found',
|
|
64
|
+
[FWD_ERROR.INVALID_PATH]: 'tr::path::invalid',
|
|
65
|
+
[FWD_ERROR.PATH_IN_USE]: 'tr::path::in_use',
|
|
66
|
+
[FWD_ERROR.TYPE_MISMATCH]: 'tr::schema::type_mismatch',
|
|
67
|
+
[FWD_ERROR.SCHEMA_NOT_FOUND]: 'tr::schema::not_found',
|
|
68
|
+
[FWD_ERROR.BACKPRESSURE]: 'tr::flow::backpressure',
|
|
69
|
+
[FWD_ERROR.TIMEOUT]: 'tr::flow::timeout',
|
|
70
|
+
[FWD_ERROR.ADDRESS_SHIFT_GAP]: 'tr::flow::address_shift_gap',
|
|
71
|
+
[FWD_ERROR.PERMISSION_DENIED]: 'tr::access::denied',
|
|
72
|
+
[FWD_ERROR.TRANSPORT_DOWN]: 'tr::transport::down',
|
|
73
|
+
[FWD_ERROR.VERSION_MISMATCH]: 'tr::version::mismatch',
|
|
44
74
|
});
|
|
45
75
|
const FWD_ERROR_NAME = Object.freeze(Object.fromEntries(Object.entries(FWD_ERROR).map(([k, v]) => [v, k])));
|
|
76
|
+
const FWD_ERROR_CODE_BY_PATH = Object.freeze(Object.fromEntries(Object.entries(FWD_ERROR_PATH).map(([code, path]) => [path, Number(code)])));
|
|
46
77
|
/** The human name of a wire ERROR code (or `UNKNOWN(0x..)`). */
|
|
47
78
|
export function fwdErrorName(code) {
|
|
48
79
|
return FWD_ERROR_NAME[code] ?? `UNKNOWN(0x${code.toString(16)})`;
|
|
49
80
|
}
|
|
81
|
+
/** The canonical `tr::…` path of a wire ERROR code (or `null` when unregistered). */
|
|
82
|
+
export function fwdErrorPath(code) {
|
|
83
|
+
return FWD_ERROR_PATH[code] ?? null;
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* The registered u16 code of a `tr::…` error path (RFC-0002 §A/§D), or 0 when
|
|
87
|
+
* the path is not in the frozen registry.
|
|
88
|
+
*/
|
|
89
|
+
export function fwdErrorCodeForPath(path) {
|
|
90
|
+
return FWD_ERROR_CODE_BY_PATH[path] ?? 0;
|
|
91
|
+
}
|
|
50
92
|
/* ----------------------------------------------------------- value nodes --- */
|
|
51
93
|
/** A 1-byte VALUE TLV node (the op / kind discriminants). */
|
|
52
94
|
function valueU8(v) {
|
|
@@ -218,11 +260,38 @@ export function parseFwdTlv(fwd) {
|
|
|
218
260
|
export function decodeFwd(bytes) {
|
|
219
261
|
return parseFwdTlv(decode(bytes));
|
|
220
262
|
}
|
|
221
|
-
/** The
|
|
222
|
-
|
|
263
|
+
/** The ERROR TLV of a `kind=ERROR` reply's STATUS payload, or `null`. */
|
|
264
|
+
function replyErrorTlv(reply) {
|
|
223
265
|
const status = reply.payload;
|
|
224
266
|
if (status && status.type === TYPE.STATUS && status.children[0]?.type === TYPE.ERROR) {
|
|
225
|
-
return
|
|
267
|
+
return status.children[0];
|
|
268
|
+
}
|
|
269
|
+
return null;
|
|
270
|
+
}
|
|
271
|
+
/**
|
|
272
|
+
* The registered wire ERROR code of a `kind=ERROR` reply's
|
|
273
|
+
* `STATUS{ ERROR{ VALUE u16 } }` payload per RFC-0002 (or 0 when absent, or
|
|
274
|
+
* when the ERROR carries the string-form NAME identity — see
|
|
275
|
+
* {@link replyErrorPath}).
|
|
276
|
+
*/
|
|
277
|
+
export function replyErrorCode(reply) {
|
|
278
|
+
const err = replyErrorTlv(reply);
|
|
279
|
+
const id = err?.children[0];
|
|
280
|
+
if (id?.type === TYPE.VALUE && id.payload.length >= 2) {
|
|
281
|
+
return id.payload[0] | (id.payload[1] << 8); // u16 LE registered code
|
|
226
282
|
}
|
|
227
283
|
return 0;
|
|
228
284
|
}
|
|
285
|
+
/**
|
|
286
|
+
* The string-form `tr::…` identity of a `kind=ERROR` reply's
|
|
287
|
+
* `STATUS{ ERROR{ NAME utf8-path } }` payload per RFC-0002 (or `null` when the
|
|
288
|
+
* reply carries no ERROR, or a registered-code identity — see
|
|
289
|
+
* {@link replyErrorCode}).
|
|
290
|
+
*/
|
|
291
|
+
export function replyErrorPath(reply) {
|
|
292
|
+
const err = replyErrorTlv(reply);
|
|
293
|
+
const id = err?.children[0];
|
|
294
|
+
if (id?.type === TYPE.NAME)
|
|
295
|
+
return new TextDecoder().decode(id.payload);
|
|
296
|
+
return null;
|
|
297
|
+
}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export declare const CLIENT_EXPERIMENTAL: true;
|
|
2
|
-
export { LibtracerClient, FwdError } from './client.js';
|
|
2
|
+
export { LibtracerClient, FwdError, CompactFlowError } from './client.js';
|
|
3
3
|
export type { ClientTransport, ValueHandler, Unsubscribe, ClientOptions, } from './client.js';
|
|
4
4
|
export { encodeValue, encodePath, encodeSubscriber } from './tlv.js';
|
|
5
5
|
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';
|
|
6
|
+
export { FWD_OP, FWD_KIND, FWD_ERROR, FWD_ERROR_PATH, fwdErrorName, fwdErrorPath, fwdErrorCodeForPath, encodeFwd, encodeField, parseField, decodeFwd, parseFwdTlv, replyErrorCode, replyErrorPath, } from './fwd.js';
|
|
7
7
|
export type { FwdRequest, ParsedFwd, FieldLevel } from './fwd.js';
|
package/dist/index.js
CHANGED
|
@@ -12,6 +12,6 @@
|
|
|
12
12
|
// (VALUE / SUBSCRIBER / PATH) and the FWD / FIELD builders are independently
|
|
13
13
|
// exported and vector-pinned — see docs/spec/rfcs/0004-remote-operation-addressing.md.
|
|
14
14
|
export const CLIENT_EXPERIMENTAL = true;
|
|
15
|
-
export { LibtracerClient, FwdError } from './client.js';
|
|
15
|
+
export { LibtracerClient, FwdError, CompactFlowError } from './client.js';
|
|
16
16
|
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';
|
|
17
|
+
export { FWD_OP, FWD_KIND, FWD_ERROR, FWD_ERROR_PATH, fwdErrorName, fwdErrorPath, fwdErrorCodeForPath, encodeFwd, encodeField, parseField, decodeFwd, parseFwdTlv, replyErrorCode, replyErrorPath, } from './fwd.js';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@avatarsd-llc/libtracer-client",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.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": "
|
|
37
|
-
"@avatarsd-llc/libtracer-ws": "
|
|
36
|
+
"@avatarsd-llc/libtracer": ">=0.3.0 <0.4.0",
|
|
37
|
+
"@avatarsd-llc/libtracer-ws": ">=0.3.0 <0.4.0"
|
|
38
38
|
},
|
|
39
39
|
"peerDependenciesMeta": {
|
|
40
40
|
"@avatarsd-llc/libtracer-ws": {
|