@hediet/linkrpc-hub 0.0.2 → 0.0.3
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/chunks/{hubConnectionAcceptor-B5-8JsFY.js → hubConnectionAcceptor-CCxcwnI4.js} +40 -115
- package/dist/chunks/hubConnectionAcceptor-CCxcwnI4.js.map +1 -0
- package/dist/chunks/{hubConnectionAcceptor-BwydvFa4.d.ts → hubConnectionAcceptor-CRBR3wry.d.ts} +12 -14
- package/dist/chunks/{index-CLIUrV88.d.ts → index-BoxUtARp.d.ts} +2 -2
- package/dist/chunks/{runHub-P3YUwwdv.js → runHub-IV1W4Olz.js} +3 -3
- package/dist/chunks/{runHub-P3YUwwdv.js.map → runHub-IV1W4Olz.js.map} +1 -1
- package/dist/chunks/{server-BAxchQhy.js → server-cTYnojbZ.js} +2 -2
- package/dist/chunks/{server-BAxchQhy.js.map → server-cTYnojbZ.js.map} +1 -1
- package/dist/engine/runHub.d.ts +2 -2
- package/dist/engine/runHub.js +1 -1
- package/dist/hub/server/client.d.ts +1 -1
- package/dist/hub/server/client.js +1 -1
- package/dist/hub/server/index.d.ts +3 -3
- package/dist/hub/server/index.js +3 -3
- package/dist/index.d.ts +2 -2
- package/dist/index.js +2 -2
- package/dist/serve.js +1 -1
- package/package.json +9 -4
- package/dist/chunks/hubConnectionAcceptor-B5-8JsFY.js.map +0 -1
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { t as connectionTokenBinderInterface } from "./connectionTokenBinder.interfaces-B-beCg06.js";
|
|
2
|
-
import { ErrorCode, LinkRpcConnection, RpcError, STREAM_METHOD, StreamControlReason, StreamControlType, StreamDir, TransportPair, directoryInterface, directoryWatchNever, isNotification, isRequest, isResponse, methodNameToTarget,
|
|
2
|
+
import { ErrorCode, LinkRpcConnection, RpcError, STREAM_METHOD, StreamControlReason, StreamControlType, StreamDir, TransportPair, directoryInterface, directoryWatchNever, isNotification, isRequest, isResponse, methodNameToTarget, parseMethodName, permits, registerLazyIdentityOnOverlay, schemasInterface, verifyCall, verifyRpcCall } from "@hediet/linkrpc";
|
|
3
3
|
import { ROOT_SERVICE_ID, SERVICE_ID_SEPARATOR, hubGrantedServiceIdInterface, hubServiceIdRegistryInterface, isServiceIdUnder, isValidServiceId, normalizeServiceIdScopes, serviceIdMatchesScopes } from "@hediet/linkrpc/hub/common";
|
|
4
4
|
import { randomUUID } from "node:crypto";
|
|
5
|
-
import {
|
|
5
|
+
import { InspectionHost, nodeInterface } from "@hediet/linkrpc/inspection";
|
|
6
6
|
import { safeParse } from "zod/v4/core";
|
|
7
7
|
//#region src/hub/server/routing/forwardingTable.ts
|
|
8
8
|
/**
|
|
@@ -185,7 +185,7 @@ var ParticipantRoots = class {
|
|
|
185
185
|
};
|
|
186
186
|
//#endregion
|
|
187
187
|
//#region src/hub/server/routing/peerDiscovery.ts
|
|
188
|
-
const GET_NODE_ID_METHOD = `${nodeInterface
|
|
188
|
+
const GET_NODE_ID_METHOD = `${nodeInterface.info.id}::getNodeId`;
|
|
189
189
|
/** Background policy for direct-peer identity; forwarding never waits for it. */
|
|
190
190
|
var PeerDiscovery = class {
|
|
191
191
|
_options;
|
|
@@ -226,7 +226,7 @@ var PeerDiscovery = class {
|
|
|
226
226
|
const attempt = Promise.resolve().then(async () => {
|
|
227
227
|
if (this._peers.get(link) !== state) throw new Error("identifyPeer: link is detached");
|
|
228
228
|
const raw = await this._options.request(link, this._timeoutMs);
|
|
229
|
-
const parsed = safeParse(nodeInterface
|
|
229
|
+
const parsed = safeParse(nodeInterface.members.getNodeId.resultSchema, raw);
|
|
230
230
|
if (!parsed.success || parsed.data.nodeId.length === 0 || parsed.data.portId.length === 0) throw new Error(`identifyPeer: invalid result from ${GET_NODE_ID_METHOD}`);
|
|
231
231
|
const info = parsed.data;
|
|
232
232
|
if (this._peers.get(link) !== state) throw new Error("identifyPeer: link is detached");
|
|
@@ -1397,66 +1397,46 @@ function _withRequestId$1(m, requestId) {
|
|
|
1397
1397
|
//#region src/hub/server/hubInspector.ts
|
|
1398
1398
|
/** Publishes dynamically observed raw node transits through bounded traffic streams. */
|
|
1399
1399
|
var HubInspector = class {
|
|
1400
|
-
|
|
1401
|
-
|
|
1402
|
-
|
|
1403
|
-
|
|
1404
|
-
|
|
1405
|
-
constructor(_hub) {
|
|
1406
|
-
this._hub = _hub;
|
|
1407
|
-
this._observation = this._hub.observeTransits((transit) => {
|
|
1408
|
-
this._onTransit(transit);
|
|
1400
|
+
host;
|
|
1401
|
+
constructor(hub) {
|
|
1402
|
+
this.host = new InspectionHost({
|
|
1403
|
+
nodeId: hub.nodeId,
|
|
1404
|
+
kind: "hub"
|
|
1409
1405
|
});
|
|
1406
|
+
this.host.addSource(new HubInspectionSource(hub));
|
|
1410
1407
|
}
|
|
1411
1408
|
get observerCount() {
|
|
1412
|
-
return this.
|
|
1409
|
+
return this.host.observerCount;
|
|
1413
1410
|
}
|
|
1414
1411
|
subscribe(options, send) {
|
|
1415
|
-
|
|
1416
|
-
const subscriber = new BoundedTrafficSubscription(options, send, () => {
|
|
1417
|
-
this._subscribers.delete(subscriber);
|
|
1418
|
-
if (this._subscribers.size === 0) this._stopTrafficSources();
|
|
1419
|
-
});
|
|
1420
|
-
if (this._subscribers.size === 0) this._startTrafficSources();
|
|
1421
|
-
this._subscribers.add(subscriber);
|
|
1422
|
-
return subscriber;
|
|
1412
|
+
return this.host.subscribe(options, send);
|
|
1423
1413
|
}
|
|
1424
1414
|
dispose() {
|
|
1425
|
-
|
|
1426
|
-
this._subscribers.clear();
|
|
1427
|
-
this._observation.dispose();
|
|
1428
|
-
this._trafficWatches.clear();
|
|
1429
|
-
this._stopTrafficSources();
|
|
1430
|
-
this._trafficSources.clear();
|
|
1415
|
+
this.host.dispose();
|
|
1431
1416
|
}
|
|
1432
1417
|
/** Add an endpoint traffic source managed by this Hub inspection service. */
|
|
1433
1418
|
addTrafficSource(source) {
|
|
1434
|
-
|
|
1435
|
-
this._trafficSources.add(registered);
|
|
1436
|
-
if (this._subscribers.size !== 0) this._startTrafficSource(registered);
|
|
1437
|
-
let disposed = false;
|
|
1438
|
-
return { dispose: () => {
|
|
1439
|
-
if (disposed) return;
|
|
1440
|
-
disposed = true;
|
|
1441
|
-
this._trafficSources.delete(registered);
|
|
1442
|
-
registered.observation?.dispose();
|
|
1443
|
-
registered.observation = void 0;
|
|
1444
|
-
} };
|
|
1419
|
+
return this.host.addTrafficSource(source);
|
|
1445
1420
|
}
|
|
1446
|
-
|
|
1447
|
-
|
|
1421
|
+
};
|
|
1422
|
+
var HubInspectionSource = class {
|
|
1423
|
+
_hub;
|
|
1424
|
+
constructor(_hub) {
|
|
1425
|
+
this._hub = _hub;
|
|
1448
1426
|
}
|
|
1449
|
-
|
|
1450
|
-
|
|
1427
|
+
snapshotTopology() {
|
|
1428
|
+
const { nodes, links, routes } = this._hub.getTopologyGraph("");
|
|
1429
|
+
return {
|
|
1430
|
+
nodes,
|
|
1431
|
+
links,
|
|
1432
|
+
routes
|
|
1433
|
+
};
|
|
1451
1434
|
}
|
|
1452
|
-
|
|
1453
|
-
|
|
1454
|
-
source.observation?.dispose();
|
|
1455
|
-
source.observation = void 0;
|
|
1456
|
-
}
|
|
1435
|
+
onTopologyChanged(listener) {
|
|
1436
|
+
return { dispose: this._hub.onDidChangeTopology(listener) };
|
|
1457
1437
|
}
|
|
1458
|
-
|
|
1459
|
-
|
|
1438
|
+
observeTraffic(observer) {
|
|
1439
|
+
return this._hub.observeTransits((transit) => observer({
|
|
1460
1440
|
type: "transit",
|
|
1461
1441
|
timeMs: transit.timeMs,
|
|
1462
1442
|
nodeId: transit.nodeId,
|
|
@@ -1468,12 +1448,7 @@ var HubInspector = class {
|
|
|
1468
1448
|
params: transit.params,
|
|
1469
1449
|
result: transit.result,
|
|
1470
1450
|
error: transit.error
|
|
1471
|
-
};
|
|
1472
|
-
if (this._trafficWatches.accept(event)) return;
|
|
1473
|
-
if (this._subscribers.size !== 0) this._emitTransit(event);
|
|
1474
|
-
}
|
|
1475
|
-
_emitTransit(transit) {
|
|
1476
|
-
for (const subscriber of this._subscribers) subscriber.enqueue(transit);
|
|
1451
|
+
}));
|
|
1477
1452
|
}
|
|
1478
1453
|
};
|
|
1479
1454
|
function normalizeEndpoint(endpoint) {
|
|
@@ -1862,7 +1837,7 @@ var RootOverlay = class {
|
|
|
1862
1837
|
this.uplinkPortId = options.uplinkPortId ?? `port:${randomUUID()}`;
|
|
1863
1838
|
this._rootPair = new TransportPair();
|
|
1864
1839
|
this.root = LinkRpcConnection.fromTransport(this._rootPair.b);
|
|
1865
|
-
this.root.register(nodeInterface
|
|
1840
|
+
this.root.register(nodeInterface, { getNodeId: () => ({
|
|
1866
1841
|
nodeId: this.nodeId,
|
|
1867
1842
|
portId: this.participantPortId
|
|
1868
1843
|
}) });
|
|
@@ -2138,7 +2113,12 @@ function createHubServiceInterfaces(hub, options = {}) {
|
|
|
2138
2113
|
hub.markInspectionService(link, hubServiceId);
|
|
2139
2114
|
const connection = LinkRpcConnection.fromTransport(withRequestIdContext(link.transport));
|
|
2140
2115
|
const inspector = new HubInspector(hub);
|
|
2141
|
-
|
|
2116
|
+
inspector.host.expose(connection, {
|
|
2117
|
+
serviceId: hubServiceId,
|
|
2118
|
+
portId: link.portId,
|
|
2119
|
+
descriptors: options.descriptors,
|
|
2120
|
+
includeRoute: false
|
|
2121
|
+
});
|
|
2142
2122
|
registerHubReflection(connection, hub, hubServiceId, options.beforeDirectoryQuery);
|
|
2143
2123
|
registerHubServiceIdRegistry(connection, {
|
|
2144
2124
|
hub,
|
|
@@ -2155,61 +2135,6 @@ function createHubServiceInterfaces(hub, options = {}) {
|
|
|
2155
2135
|
}
|
|
2156
2136
|
};
|
|
2157
2137
|
}
|
|
2158
|
-
function registerInspectionInterfaces(connection, hub, inspector, hubServiceId, portId, descriptors) {
|
|
2159
|
-
connection.register(nodeInterface, { getNodeId: () => ({
|
|
2160
|
-
nodeId: hub.nodeId,
|
|
2161
|
-
portId,
|
|
2162
|
-
...descriptors !== void 0 ? { descriptors: [...descriptors] } : {}
|
|
2163
|
-
}) }, { serviceId: hubServiceId });
|
|
2164
|
-
connection.register(topologyInterface, {
|
|
2165
|
-
getGraph: () => hub.getTopologyGraph(hubServiceId),
|
|
2166
|
-
watchGraph: (_params, _ctx, stream) => new Promise((resolve) => {
|
|
2167
|
-
if (stream.signal.aborted) {
|
|
2168
|
-
resolve({});
|
|
2169
|
-
return;
|
|
2170
|
-
}
|
|
2171
|
-
let pending = false;
|
|
2172
|
-
const flush = () => {
|
|
2173
|
-
pending = false;
|
|
2174
|
-
if (!stream.signal.aborted) stream.send({}).catch(() => void 0);
|
|
2175
|
-
};
|
|
2176
|
-
const unsubscribe = hub.onDidChangeTopology(() => {
|
|
2177
|
-
if (pending) return;
|
|
2178
|
-
pending = true;
|
|
2179
|
-
queueMicrotask(flush);
|
|
2180
|
-
});
|
|
2181
|
-
stream.signal.addEventListener("abort", () => {
|
|
2182
|
-
unsubscribe();
|
|
2183
|
-
resolve({});
|
|
2184
|
-
}, { once: true });
|
|
2185
|
-
})
|
|
2186
|
-
}, { serviceId: hubServiceId });
|
|
2187
|
-
connection.register(trafficInterface, {
|
|
2188
|
-
watch: ({ methodPrefix, trafficIgnoreKey, focusRequest }, _ctx, stream) => runTrafficWatch(inspector, {
|
|
2189
|
-
methodPrefix,
|
|
2190
|
-
trafficIgnoreKey,
|
|
2191
|
-
focusRequest
|
|
2192
|
-
}, stream),
|
|
2193
|
-
watchWithPayloads: ({ methodPrefix, maxPayloadBytes, trafficIgnoreKey, focusRequest }, _ctx, stream) => runTrafficWatch(inspector, {
|
|
2194
|
-
methodPrefix,
|
|
2195
|
-
maxPayloadBytes,
|
|
2196
|
-
trafficIgnoreKey,
|
|
2197
|
-
focusRequest
|
|
2198
|
-
}, stream)
|
|
2199
|
-
}, { serviceId: hubServiceId });
|
|
2200
|
-
}
|
|
2201
|
-
async function runTrafficWatch(inspector, options, stream) {
|
|
2202
|
-
const subscription = inspector.subscribe(options, (event) => stream.send(event));
|
|
2203
|
-
const dispose = () => subscription.dispose();
|
|
2204
|
-
if (stream.signal.aborted) dispose();
|
|
2205
|
-
else stream.signal.addEventListener("abort", dispose, { once: true });
|
|
2206
|
-
try {
|
|
2207
|
-
return await subscription.closed;
|
|
2208
|
-
} finally {
|
|
2209
|
-
stream.signal.removeEventListener("abort", dispose);
|
|
2210
|
-
subscription.dispose();
|
|
2211
|
-
}
|
|
2212
|
-
}
|
|
2213
2138
|
/**
|
|
2214
2139
|
* Register the hub's **reflection** surface — `hubrpc.directory::list` /
|
|
2215
2140
|
* `hubrpc.schemas::get` — on `connection`, mounted under `hubServiceId`.
|
|
@@ -2763,6 +2688,6 @@ var HubConnectionAcceptor = class {
|
|
|
2763
2688
|
}
|
|
2764
2689
|
};
|
|
2765
2690
|
//#endregion
|
|
2766
|
-
export { validatePrefix as S, RootOverlay as _, anonymousHandler as a,
|
|
2691
|
+
export { validatePrefix as C, ForwardingTable as S, RootOverlay as _, anonymousHandler as a, HubInspector as b, provisionRoot as c, registerConnectionTokenBinderService as d, createHubServiceInterfaces as f, registerIdentityServices as g, registerHubServices as h, withVerifiedSignature as i, resolveConnectionHandler as l, withRequestIdContext as m, withForwardedCallGate as n, boundTokenHandler as o, registerHubServiceIdRegistry as p, withFullyQualifiedCallGate as r, fixedProvisionHandler as s, HubConnectionAcceptor as t, staticTokenHandler as u, OverlaySplitter as v, Hub as x, HubInspectionSource as y };
|
|
2767
2692
|
|
|
2768
|
-
//# sourceMappingURL=hubConnectionAcceptor-
|
|
2693
|
+
//# sourceMappingURL=hubConnectionAcceptor-CCxcwnI4.js.map
|