@avatarsd-llc/libtracer-client 0.17.0 → 0.18.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 +11 -0
- package/dist/client.d.ts +20 -2
- package/dist/client.js +37 -9
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -42,6 +42,17 @@ unsubscribe(); // local detach
|
|
|
42
42
|
client.onError((err) => console.error('inbound decode error', err));
|
|
43
43
|
```
|
|
44
44
|
|
|
45
|
+
**`await_` deadlines are the client's own.** A responder is not required to answer
|
|
46
|
+
`TIMEOUT` (RFC-0004 Amendment 3): it answers on the next write, and otherwise stays silent.
|
|
47
|
+
`await_` therefore always ends locally, at the shorter of `requestTimeoutMs` (10 s by
|
|
48
|
+
default, and still 10 s for `await_` when that option disables other deadlines) and its
|
|
49
|
+
`timeoutNs`, rejecting with a `FwdError` whose `codeName` is `"TIMEOUT"`.
|
|
50
|
+
|
|
51
|
+
**Do not pipeline a `read` behind an `await_` on the same vertex.** Replies name no request
|
|
52
|
+
op, so with both outstanding to one vertex over one connection the two RESULTs cannot be told
|
|
53
|
+
apart, and the `read`'s answer can be handed to the `await_`. Await and read different
|
|
54
|
+
vertices, or let one settle before sending the other.
|
|
55
|
+
|
|
45
56
|
The pure builders (the exact bytes, transport-free) are also exported — the FWD /
|
|
46
57
|
FIELD envelope builders and the payload builders, each pinned to a conformance
|
|
47
58
|
vector:
|
package/dist/client.d.ts
CHANGED
|
@@ -83,6 +83,12 @@ export declare class CompactFlowError extends Error {
|
|
|
83
83
|
*/
|
|
84
84
|
constructor(frameType: number);
|
|
85
85
|
}
|
|
86
|
+
/**
|
|
87
|
+
* @brief A remote await's local deadline in ms (RFC-0004 Amendment 3: the requester
|
|
88
|
+
* owns it). The shorter of the request deadline and the await timeout; the request
|
|
89
|
+
* deadline falls back to its 10 s default when disabled, so an await always ends.
|
|
90
|
+
*/
|
|
91
|
+
export declare function awaitDeadlineMs(requestTimeoutMs: number, timeoutNs?: bigint): number;
|
|
86
92
|
/**
|
|
87
93
|
* @brief A WebSocket/transport-agnostic libtracer client over the RFC-0004
|
|
88
94
|
* `FWD` plane.
|
|
@@ -165,6 +171,9 @@ export declare class LibtracerClient {
|
|
|
165
171
|
* @param frame the encoded request frame
|
|
166
172
|
* @param dst the request's destination segments — the key its reply's `src`
|
|
167
173
|
* echoes (see {@link correlate})
|
|
174
|
+
* @param deadlineMs this request's own deadline in ms, overriding
|
|
175
|
+
* `requestTimeoutMs` (used by {@link await_})
|
|
176
|
+
* @param onDeadline the rejection raised when the deadline elapses
|
|
168
177
|
*/
|
|
169
178
|
private request;
|
|
170
179
|
/** @brief Turn a RESULT reply into its payload TLV; throw {@link FwdError} on ERROR. */
|
|
@@ -234,10 +243,19 @@ export declare class LibtracerClient {
|
|
|
234
243
|
* Named `await_` because `await` is reserved; an `await` alias is installed
|
|
235
244
|
* on the prototype for the RFC-0004-spelled call site.
|
|
236
245
|
*
|
|
246
|
+
* The deadline is this client's own (RFC-0004 Amendment 3): a responder is not
|
|
247
|
+
* required to answer `TIMEOUT`, so the wait always ends locally, at the shorter
|
|
248
|
+
* of `requestTimeoutMs` (10 s by default; the default is used even when the
|
|
249
|
+
* option disables other requests' deadlines) and `timeoutNs`.
|
|
250
|
+
*
|
|
251
|
+
* Replies name no request op, so do not keep an `await_` and a `read` to the
|
|
252
|
+
* same vertex outstanding at once: their RESULTs cannot be told apart.
|
|
253
|
+
*
|
|
237
254
|
* @param path the destination path (string or segments)
|
|
238
|
-
* @param timeoutNs the await timeout in ns
|
|
255
|
+
* @param timeoutNs the await timeout in ns, sent as `await_timeout` and used as
|
|
256
|
+
* this call's local deadline when shorter than `requestTimeoutMs`
|
|
239
257
|
* @returns the next write's value TLV
|
|
240
|
-
* @throws {FwdError} with code TIMEOUT when the
|
|
258
|
+
* @throws {FwdError} with code TIMEOUT when the local deadline elapses first
|
|
241
259
|
*/
|
|
242
260
|
await_(path: string | string[], timeoutNs?: bigint): Promise<Tlv>;
|
|
243
261
|
/**
|
package/dist/client.js
CHANGED
|
@@ -29,7 +29,7 @@
|
|
|
29
29
|
*/
|
|
30
30
|
import { TYPE, decode, CodecError } from '@avatarsd-llc/libtracer';
|
|
31
31
|
import { encodeValue, encodePath, encodeSubscriber, pathSegments } from './tlv.js';
|
|
32
|
-
import { FWD_OP, FWD_KIND, encodeFwd, parseFwdTlv, replyErrorCode, replyErrorPath, fwdErrorName, fwdErrorPath, fwdErrorCodeForPath, } from './fwd.js';
|
|
32
|
+
import { FWD_OP, FWD_KIND, FWD_ERROR, encodeFwd, parseFwdTlv, replyErrorCode, replyErrorPath, fwdErrorName, fwdErrorPath, fwdErrorCodeForPath, } from './fwd.js';
|
|
33
33
|
/**
|
|
34
34
|
* @brief A `kind=ERROR` FWD reply, surfaced as a typed rejection.
|
|
35
35
|
*
|
|
@@ -82,6 +82,22 @@ export class CompactFlowError extends Error {
|
|
|
82
82
|
this.frameType = frameType;
|
|
83
83
|
}
|
|
84
84
|
}
|
|
85
|
+
/** @brief The request deadline used when `requestTimeoutMs` is not given. */
|
|
86
|
+
const DEFAULT_REQUEST_TIMEOUT_MS = 10000;
|
|
87
|
+
/**
|
|
88
|
+
* @brief A remote await's local deadline in ms (RFC-0004 Amendment 3: the requester
|
|
89
|
+
* owns it). The shorter of the request deadline and the await timeout; the request
|
|
90
|
+
* deadline falls back to its 10 s default when disabled, so an await always ends.
|
|
91
|
+
*/
|
|
92
|
+
export function awaitDeadlineMs(requestTimeoutMs, timeoutNs) {
|
|
93
|
+
const request = requestTimeoutMs > 0 && Number.isFinite(requestTimeoutMs)
|
|
94
|
+
? requestTimeoutMs
|
|
95
|
+
: DEFAULT_REQUEST_TIMEOUT_MS;
|
|
96
|
+
if (timeoutNs === undefined)
|
|
97
|
+
return request;
|
|
98
|
+
const own = Math.max(1, Math.ceil(Number(timeoutNs) / 1e6));
|
|
99
|
+
return Math.min(request, own);
|
|
100
|
+
}
|
|
85
101
|
/** @brief Settle a pending entry: clear its deadline and mark it consumed. */
|
|
86
102
|
function settle(p) {
|
|
87
103
|
p.settled = true;
|
|
@@ -113,7 +129,7 @@ export class LibtracerClient {
|
|
|
113
129
|
this.closed = null;
|
|
114
130
|
this.transport = transport;
|
|
115
131
|
this.replyEndpoint = [...(options.replyEndpoint ?? ['client'])];
|
|
116
|
-
this.requestTimeoutMs = options.requestTimeoutMs ??
|
|
132
|
+
this.requestTimeoutMs = options.requestTimeoutMs ?? DEFAULT_REQUEST_TIMEOUT_MS;
|
|
117
133
|
transport.onFrame((bytes) => this.dispatch(bytes));
|
|
118
134
|
transport.onClose?.((cause) => this.handleClose(cause));
|
|
119
135
|
}
|
|
@@ -260,21 +276,24 @@ export class LibtracerClient {
|
|
|
260
276
|
* @param frame the encoded request frame
|
|
261
277
|
* @param dst the request's destination segments — the key its reply's `src`
|
|
262
278
|
* echoes (see {@link correlate})
|
|
279
|
+
* @param deadlineMs this request's own deadline in ms, overriding
|
|
280
|
+
* `requestTimeoutMs` (used by {@link await_})
|
|
281
|
+
* @param onDeadline the rejection raised when the deadline elapses
|
|
263
282
|
*/
|
|
264
|
-
request(frame, dst) {
|
|
283
|
+
request(frame, dst, deadlineMs = this.requestTimeoutMs, onDeadline = () => new Error(`request timed out after ${deadlineMs}ms (no FWD reply)`)) {
|
|
265
284
|
return new Promise((resolve, reject) => {
|
|
266
285
|
if (this.closed) {
|
|
267
286
|
reject(this.closed);
|
|
268
287
|
return;
|
|
269
288
|
}
|
|
270
289
|
const entry = { resolve, reject, settled: false, timer: null, dst };
|
|
271
|
-
if (
|
|
290
|
+
if (deadlineMs > 0 && Number.isFinite(deadlineMs)) {
|
|
272
291
|
entry.timer = setTimeout(() => {
|
|
273
292
|
// Leave the settled entry in the FIFO (see Pending) — its slot is
|
|
274
293
|
// consumed by the late reply, if one ever arrives.
|
|
275
294
|
settle(entry);
|
|
276
|
-
entry.reject(
|
|
277
|
-
},
|
|
295
|
+
entry.reject(onDeadline());
|
|
296
|
+
}, deadlineMs);
|
|
278
297
|
// Don't hold a Node event loop open for a pending deadline (no-op in browsers).
|
|
279
298
|
entry.timer.unref?.();
|
|
280
299
|
}
|
|
@@ -392,10 +411,19 @@ export class LibtracerClient {
|
|
|
392
411
|
* Named `await_` because `await` is reserved; an `await` alias is installed
|
|
393
412
|
* on the prototype for the RFC-0004-spelled call site.
|
|
394
413
|
*
|
|
414
|
+
* The deadline is this client's own (RFC-0004 Amendment 3): a responder is not
|
|
415
|
+
* required to answer `TIMEOUT`, so the wait always ends locally, at the shorter
|
|
416
|
+
* of `requestTimeoutMs` (10 s by default; the default is used even when the
|
|
417
|
+
* option disables other requests' deadlines) and `timeoutNs`.
|
|
418
|
+
*
|
|
419
|
+
* Replies name no request op, so do not keep an `await_` and a `read` to the
|
|
420
|
+
* same vertex outstanding at once: their RESULTs cannot be told apart.
|
|
421
|
+
*
|
|
395
422
|
* @param path the destination path (string or segments)
|
|
396
|
-
* @param timeoutNs the await timeout in ns
|
|
423
|
+
* @param timeoutNs the await timeout in ns, sent as `await_timeout` and used as
|
|
424
|
+
* this call's local deadline when shorter than `requestTimeoutMs`
|
|
397
425
|
* @returns the next write's value TLV
|
|
398
|
-
* @throws {FwdError} with code TIMEOUT when the
|
|
426
|
+
* @throws {FwdError} with code TIMEOUT when the local deadline elapses first
|
|
399
427
|
*/
|
|
400
428
|
async await_(path, timeoutNs) {
|
|
401
429
|
const dst = splitPath(path);
|
|
@@ -404,7 +432,7 @@ export class LibtracerClient {
|
|
|
404
432
|
dst,
|
|
405
433
|
src: this.replyEndpoint,
|
|
406
434
|
awaitTimeoutNs: timeoutNs,
|
|
407
|
-
}), dst);
|
|
435
|
+
}), dst, awaitDeadlineMs(this.requestTimeoutMs, timeoutNs), () => new FwdError(FWD_ERROR.TIMEOUT));
|
|
408
436
|
const value = this.result(reply);
|
|
409
437
|
if (!value)
|
|
410
438
|
throw new FwdError(0);
|
package/dist/index.d.ts
CHANGED
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
* exported and vector-pinned — see docs/spec/rfcs/0004-remote-operation-addressing.md.
|
|
15
15
|
*/
|
|
16
16
|
export declare const CLIENT_EXPERIMENTAL: true;
|
|
17
|
-
export { LibtracerClient, FwdError, CompactFlowError } from './client.js';
|
|
17
|
+
export { LibtracerClient, FwdError, CompactFlowError, awaitDeadlineMs } from './client.js';
|
|
18
18
|
export type { ClientTransport, ValueHandler, Unsubscribe, ClientOptions, } from './client.js';
|
|
19
19
|
export { encodeValue, encodePath, encodeSubscriber, encodeConnSpec, firstChild, pathSegments, PACKED_ESCAPE_LEN, DELIVERY_DURABILITY_REQUEST, DELIVERY_CLASS, deliveryClassBits, deliveryClassOf, } from './tlv.js';
|
|
20
20
|
export type { ValueOptions, SubscriberOptions, ConnSpecOptions } from './tlv.js';
|
package/dist/index.js
CHANGED
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
* exported and vector-pinned — see docs/spec/rfcs/0004-remote-operation-addressing.md.
|
|
17
17
|
*/
|
|
18
18
|
export const CLIENT_EXPERIMENTAL = true;
|
|
19
|
-
export { LibtracerClient, FwdError, CompactFlowError } from './client.js';
|
|
19
|
+
export { LibtracerClient, FwdError, CompactFlowError, awaitDeadlineMs } from './client.js';
|
|
20
20
|
export { encodeValue, encodePath, encodeSubscriber, encodeConnSpec, firstChild, pathSegments, PACKED_ESCAPE_LEN, DELIVERY_DURABILITY_REQUEST, DELIVERY_CLASS, deliveryClassBits, deliveryClassOf, } from './tlv.js';
|
|
21
21
|
export { walkTopology, routeKey, CONN_ENDPOINT_NAME } from './topology.js';
|
|
22
22
|
export { FWD_OP, FWD_OPCODE_MASK, FWD_OP_FLAG_MINT_REQUEST, 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.18.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.18.0 <0.19.0",
|
|
37
|
+
"@avatarsd-llc/libtracer-ws": ">=0.18.0 <0.19.0"
|
|
38
38
|
},
|
|
39
39
|
"peerDependenciesMeta": {
|
|
40
40
|
"@avatarsd-llc/libtracer-ws": {
|