@naeemo/capnp 0.7.0 → 0.8.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/index.cjs +5 -2
- package/dist/index.js +3 -3
- package/dist/{rpc-connection-C3-uEtpd.js → rpc-connection-CHjKsrMC.js} +366 -20
- package/dist/rpc-connection-CHjKsrMC.js.map +1 -0
- package/dist/rpc-connection-DWwgwaUX.js +3 -0
- package/dist/{rpc-connection-_eHtWsk2.js → rpc-connection-OuadMfAW.js} +383 -19
- package/dist/rpc-connection-OuadMfAW.js.map +1 -0
- package/dist/rpc-connection-uazTSCEw.js +3 -0
- package/package.json +1 -1
- package/dist/rpc-connection-C3-uEtpd.js.map +0 -1
- package/dist/rpc-connection-CDzawjwJ.js +0 -3
- package/dist/rpc-connection-_eHtWsk2.js.map +0 -1
- package/dist/rpc-connection-jIPnPyT6.js +0 -3
package/dist/index.cjs
CHANGED
|
@@ -27,7 +27,7 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
27
27
|
}) : target, mod));
|
|
28
28
|
|
|
29
29
|
//#endregion
|
|
30
|
-
const require_rpc_connection = require('./rpc-connection-
|
|
30
|
+
const require_rpc_connection = require('./rpc-connection-OuadMfAW.js');
|
|
31
31
|
let node_net = require("node:net");
|
|
32
32
|
node_net = __toESM(node_net);
|
|
33
33
|
let node_events = require("node:events");
|
|
@@ -2732,7 +2732,7 @@ var ConnectionManager = class {
|
|
|
2732
2732
|
}
|
|
2733
2733
|
}
|
|
2734
2734
|
async doEstablishConnection(vatId, address) {
|
|
2735
|
-
const { RpcConnection } = await Promise.resolve().then(() => require("./rpc-connection-
|
|
2735
|
+
const { RpcConnection } = await Promise.resolve().then(() => require("./rpc-connection-uazTSCEw.js"));
|
|
2736
2736
|
const connection = new RpcConnection(await this.options.connectionFactory(vatId, address), this.options.connectionOptions);
|
|
2737
2737
|
await connection.start();
|
|
2738
2738
|
this.registerConnection(vatId, connection);
|
|
@@ -10088,13 +10088,16 @@ exports.deserializeRpcMessage = deserializeRpcMessage;
|
|
|
10088
10088
|
exports.deserializeSchemaRequest = require_rpc_connection.deserializeSchemaRequest;
|
|
10089
10089
|
exports.deserializeSchemaResponse = require_rpc_connection.deserializeSchemaResponse;
|
|
10090
10090
|
exports.deserializeSturdyRef = deserializeSturdyRef;
|
|
10091
|
+
exports.disableDebug = require_rpc_connection.disableDebug;
|
|
10091
10092
|
exports.dumpDynamicReader = dumpDynamicReader;
|
|
10093
|
+
exports.enableDebug = require_rpc_connection.enableDebug;
|
|
10092
10094
|
exports.encodeListPointer = encodeListPointer;
|
|
10093
10095
|
exports.encodeStructPointer = encodeStructPointer;
|
|
10094
10096
|
exports.fastCopy = fastCopy;
|
|
10095
10097
|
exports.generateProvisionId = generateProvisionId;
|
|
10096
10098
|
exports.generateVatId = generateVatId;
|
|
10097
10099
|
exports.getGlobalMemoryPool = getGlobalMemoryPool;
|
|
10100
|
+
exports.isDebugEnabled = require_rpc_connection.isDebugEnabled;
|
|
10098
10101
|
exports.isPipelineClient = require_rpc_connection.isPipelineClient;
|
|
10099
10102
|
exports.isSameBuffer = isSameBuffer;
|
|
10100
10103
|
exports.isStream = isStream;
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { C as QuestionTable, S as ImportTable, _ as QueuedCallManager, a as serializeGetSchemaParams, b as AnswerTable, c as serializeSchemaRequest, d as parseSchemaNodes, f as SchemaFormat, g as PipelineResolutionTracker, h as PipelineOpTracker, i as deserializeSchemaResponse, l as serializeSchemaResponse, m as PIPELINE_CLIENT_SYMBOL, n as SCHEMA_MESSAGE_TYPES, o as serializeGetSchemaResults, p as SchemaNodeType, r as deserializeSchemaRequest, s as serializeListSchemasResults, t as RpcConnection, u as createSchemaRegistry, v as createPipelineClient, x as ExportTable, y as isPipelineClient } from "./rpc-connection-
|
|
1
|
+
import { C as QuestionTable, E as isDebugEnabled, S as ImportTable, T as enableDebug, _ as QueuedCallManager, a as serializeGetSchemaParams, b as AnswerTable, c as serializeSchemaRequest, d as parseSchemaNodes, f as SchemaFormat, g as PipelineResolutionTracker, h as PipelineOpTracker, i as deserializeSchemaResponse, l as serializeSchemaResponse, m as PIPELINE_CLIENT_SYMBOL, n as SCHEMA_MESSAGE_TYPES, o as serializeGetSchemaResults, p as SchemaNodeType, r as deserializeSchemaRequest, s as serializeListSchemasResults, t as RpcConnection, u as createSchemaRegistry, v as createPipelineClient, w as disableDebug, x as ExportTable, y as isPipelineClient } from "./rpc-connection-CHjKsrMC.js";
|
|
2
2
|
import { createRequire } from "node:module";
|
|
3
3
|
import * as net$1 from "node:net";
|
|
4
4
|
import { createConnection } from "node:net";
|
|
@@ -2733,7 +2733,7 @@ var ConnectionManager = class {
|
|
|
2733
2733
|
}
|
|
2734
2734
|
}
|
|
2735
2735
|
async doEstablishConnection(vatId, address) {
|
|
2736
|
-
const { RpcConnection } = await import("./rpc-connection-
|
|
2736
|
+
const { RpcConnection } = await import("./rpc-connection-DWwgwaUX.js");
|
|
2737
2737
|
const connection = new RpcConnection(await this.options.connectionFactory(vatId, address), this.options.connectionOptions);
|
|
2738
2738
|
await connection.start();
|
|
2739
2739
|
this.registerConnection(vatId, connection);
|
|
@@ -10008,5 +10008,5 @@ Example:
|
|
|
10008
10008
|
}
|
|
10009
10009
|
|
|
10010
10010
|
//#endregion
|
|
10011
|
-
export { AnswerTable, BaseCapabilityClient, BulkTransfer, BulkTransferManager, CapnpWebSocketProxy, ConnectionManager, DEFAULT_BULK_CONFIG, DEFAULT_ESCROW_CONFIG, DEFAULT_FLOW_CONTROL, DEFAULT_JOIN_OPTIONS, DEFAULT_JOIN_SECURITY_POLICY, DEFAULT_REALTIME_CONFIG, DEFAULT_STREAMING_CAPABILITIES, DropPolicy, ElementSize, ExportTable, EzRpcTransport, ImportTable, Level3Handlers, Level4Handlers, ListBuilder, ListReader, MemoryPool, MessageBuilder, MessageReader, MultiSegmentMessageBuilder, OptimizedRpcMessageBuilder, PIPELINE_CLIENT_SYMBOL, PipelineOpTracker, PipelineResolutionTracker, PointerTag, QuestionTable, QueuedCallManager, RealtimeStream, RealtimeStreamManager, RestoreHandler, RpcConnection, SCHEMA_MESSAGE_TYPES, SchemaCapabilityClient, SchemaCapabilityServer, SchemaFormat, Segment, Stream, StreamManager, StreamPriority, StreamType, StreamingRpcConnection, StructBuilder, StructReader, SturdyRefManager, TcpTransport, UnionBuilder, UnionReader, WORD_SIZE, WebSocketTransport, configureGlobalMemoryPool, createBulkTransferManager, createDynamicReader, createDynamicReaderByTypeId, createDynamicReaderFromStruct, createDynamicWriter, createDynamicWriterByTypeId, createNestedDynamicWriter, createPipelineClient, createProvisionId, createRealtimeStreamManager, createRecipientId, createSchemaRegistry, createStream, createStreamManager, createStreamingConnection, createSturdyRef, createThirdPartyCapId, createUnionBuilder, createUnionReader, createZeroCopyView, decodePointer, deserializeRpcMessage, deserializeSchemaRequest, deserializeSchemaResponse, deserializeSturdyRef, dumpDynamicReader, encodeListPointer, encodeStructPointer, fastCopy, generateProvisionId, generateVatId, getGlobalMemoryPool, isPipelineClient, isSameBuffer, isStream, isSturdyRefValid, parseSchemaNodes, serializeDynamic, serializeDynamicByTypeId, serializeGetSchemaParams, serializeGetSchemaResults, serializeListSchemasResults, serializeRpcMessage, serializeSchemaRequest, serializeSchemaResponse, serializeSturdyRef, supportsStreaming };
|
|
10011
|
+
export { AnswerTable, BaseCapabilityClient, BulkTransfer, BulkTransferManager, CapnpWebSocketProxy, ConnectionManager, DEFAULT_BULK_CONFIG, DEFAULT_ESCROW_CONFIG, DEFAULT_FLOW_CONTROL, DEFAULT_JOIN_OPTIONS, DEFAULT_JOIN_SECURITY_POLICY, DEFAULT_REALTIME_CONFIG, DEFAULT_STREAMING_CAPABILITIES, DropPolicy, ElementSize, ExportTable, EzRpcTransport, ImportTable, Level3Handlers, Level4Handlers, ListBuilder, ListReader, MemoryPool, MessageBuilder, MessageReader, MultiSegmentMessageBuilder, OptimizedRpcMessageBuilder, PIPELINE_CLIENT_SYMBOL, PipelineOpTracker, PipelineResolutionTracker, PointerTag, QuestionTable, QueuedCallManager, RealtimeStream, RealtimeStreamManager, RestoreHandler, RpcConnection, SCHEMA_MESSAGE_TYPES, SchemaCapabilityClient, SchemaCapabilityServer, SchemaFormat, Segment, Stream, StreamManager, StreamPriority, StreamType, StreamingRpcConnection, StructBuilder, StructReader, SturdyRefManager, TcpTransport, UnionBuilder, UnionReader, WORD_SIZE, WebSocketTransport, configureGlobalMemoryPool, createBulkTransferManager, createDynamicReader, createDynamicReaderByTypeId, createDynamicReaderFromStruct, createDynamicWriter, createDynamicWriterByTypeId, createNestedDynamicWriter, createPipelineClient, createProvisionId, createRealtimeStreamManager, createRecipientId, createSchemaRegistry, createStream, createStreamManager, createStreamingConnection, createSturdyRef, createThirdPartyCapId, createUnionBuilder, createUnionReader, createZeroCopyView, decodePointer, deserializeRpcMessage, deserializeSchemaRequest, deserializeSchemaResponse, deserializeSturdyRef, disableDebug, dumpDynamicReader, enableDebug, encodeListPointer, encodeStructPointer, fastCopy, generateProvisionId, generateVatId, getGlobalMemoryPool, isDebugEnabled, isPipelineClient, isSameBuffer, isStream, isSturdyRefValid, parseSchemaNodes, serializeDynamic, serializeDynamicByTypeId, serializeGetSchemaParams, serializeGetSchemaResults, serializeListSchemasResults, serializeRpcMessage, serializeSchemaRequest, serializeSchemaResponse, serializeSturdyRef, supportsStreaming };
|
|
10012
10012
|
//# sourceMappingURL=index.js.map
|
|
@@ -1,3 +1,84 @@
|
|
|
1
|
+
//#region src/debug/config.ts
|
|
2
|
+
/**
|
|
3
|
+
* Global debug state
|
|
4
|
+
*/
|
|
5
|
+
const debugState = {
|
|
6
|
+
enabled: false,
|
|
7
|
+
options: {
|
|
8
|
+
colors: true,
|
|
9
|
+
maxBytes: 256,
|
|
10
|
+
filter: ""
|
|
11
|
+
}
|
|
12
|
+
};
|
|
13
|
+
/**
|
|
14
|
+
* Check if running in Node.js environment
|
|
15
|
+
*/
|
|
16
|
+
function isNode$1() {
|
|
17
|
+
return typeof process !== "undefined" && process.versions != null && process.versions.node != null;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Check CAPNP_DEBUG environment variable in Node.js
|
|
21
|
+
*/
|
|
22
|
+
function checkEnvVar() {
|
|
23
|
+
if (isNode$1()) try {
|
|
24
|
+
const envValue = process.env.CAPNP_DEBUG;
|
|
25
|
+
return envValue === "1" || envValue === "true";
|
|
26
|
+
} catch {
|
|
27
|
+
return false;
|
|
28
|
+
}
|
|
29
|
+
return false;
|
|
30
|
+
}
|
|
31
|
+
if (checkEnvVar()) debugState.enabled = true;
|
|
32
|
+
/**
|
|
33
|
+
* Enable debug mode with optional configuration
|
|
34
|
+
*
|
|
35
|
+
* @param options - Debug configuration options
|
|
36
|
+
* @example
|
|
37
|
+
* ```typescript
|
|
38
|
+
* enableDebug({ colors: true, maxBytes: 512 });
|
|
39
|
+
* ```
|
|
40
|
+
*/
|
|
41
|
+
function enableDebug(options) {
|
|
42
|
+
debugState.enabled = true;
|
|
43
|
+
if (options) debugState.options = {
|
|
44
|
+
...debugState.options,
|
|
45
|
+
...options
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Disable debug mode
|
|
50
|
+
*
|
|
51
|
+
* @example
|
|
52
|
+
* ```typescript
|
|
53
|
+
* disableDebug();
|
|
54
|
+
* ```
|
|
55
|
+
*/
|
|
56
|
+
function disableDebug() {
|
|
57
|
+
debugState.enabled = false;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Check if debug mode is currently enabled
|
|
61
|
+
*
|
|
62
|
+
* @returns True if debug mode is enabled
|
|
63
|
+
* @example
|
|
64
|
+
* ```typescript
|
|
65
|
+
* if (isDebugEnabled()) {
|
|
66
|
+
* console.log('Debug is on');
|
|
67
|
+
* }
|
|
68
|
+
* ```
|
|
69
|
+
*/
|
|
70
|
+
function isDebugEnabled() {
|
|
71
|
+
return debugState.enabled;
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Get current debug options (internal use)
|
|
75
|
+
* @internal
|
|
76
|
+
*/
|
|
77
|
+
function getDebugOptions() {
|
|
78
|
+
return Object.freeze({ ...debugState.options });
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
//#endregion
|
|
1
82
|
//#region src/rpc/four-tables.ts
|
|
2
83
|
/** Manages the question table for outbound calls */
|
|
3
84
|
var QuestionTable = class {
|
|
@@ -196,6 +277,238 @@ var ExportTable = class {
|
|
|
196
277
|
}
|
|
197
278
|
};
|
|
198
279
|
|
|
280
|
+
//#endregion
|
|
281
|
+
//#region src/debug/index.ts
|
|
282
|
+
/**
|
|
283
|
+
* Default configuration for debug logging
|
|
284
|
+
*/
|
|
285
|
+
const DEFAULT_CONFIG = {
|
|
286
|
+
enabled: false,
|
|
287
|
+
colors: true,
|
|
288
|
+
maxBytesToLog: 1024
|
|
289
|
+
};
|
|
290
|
+
/**
|
|
291
|
+
* ANSI color codes for Node.js output
|
|
292
|
+
*/
|
|
293
|
+
const ANSI_COLORS = {
|
|
294
|
+
reset: "\x1B[0m",
|
|
295
|
+
bright: "\x1B[1m",
|
|
296
|
+
dim: "\x1B[2m",
|
|
297
|
+
red: "\x1B[31m",
|
|
298
|
+
green: "\x1B[32m",
|
|
299
|
+
yellow: "\x1B[33m",
|
|
300
|
+
blue: "\x1B[34m",
|
|
301
|
+
magenta: "\x1B[35m",
|
|
302
|
+
cyan: "\x1B[36m",
|
|
303
|
+
white: "\x1B[37m",
|
|
304
|
+
gray: "\x1B[90m"
|
|
305
|
+
};
|
|
306
|
+
/**
|
|
307
|
+
* CSS styles for browser console output
|
|
308
|
+
*/
|
|
309
|
+
const BROWSER_STYLES = {
|
|
310
|
+
header: "color: #6c757d; font-weight: bold;",
|
|
311
|
+
send: "color: #28a745; font-weight: bold;",
|
|
312
|
+
recv: "color: #007bff; font-weight: bold;",
|
|
313
|
+
hex: "color: #6c757d;",
|
|
314
|
+
ascii: "color: #495057;",
|
|
315
|
+
arrow: "color: #6c757d;",
|
|
316
|
+
parsed: "color: #17a2b8;"
|
|
317
|
+
};
|
|
318
|
+
/**
|
|
319
|
+
* Check if running in Node.js environment
|
|
320
|
+
*/
|
|
321
|
+
function isNode() {
|
|
322
|
+
return typeof process !== "undefined" && process.versions != null && process.versions.node != null;
|
|
323
|
+
}
|
|
324
|
+
/**
|
|
325
|
+
* Format a byte as two-digit hex string
|
|
326
|
+
*/
|
|
327
|
+
function byteToHex(byte) {
|
|
328
|
+
return byte.toString(16).padStart(2, "0");
|
|
329
|
+
}
|
|
330
|
+
/**
|
|
331
|
+
* Check if a byte is printable ASCII
|
|
332
|
+
*/
|
|
333
|
+
function isPrintable(byte) {
|
|
334
|
+
return byte >= 32 && byte < 127;
|
|
335
|
+
}
|
|
336
|
+
/**
|
|
337
|
+
* Format binary data as hex + ASCII (like hexdump -C)
|
|
338
|
+
*
|
|
339
|
+
* Output format:
|
|
340
|
+
* 00000000: 00 00 00 00 02 00 00 00 │........│
|
|
341
|
+
*
|
|
342
|
+
* @param data - The binary data to format
|
|
343
|
+
* @param maxBytes - Maximum number of bytes to format
|
|
344
|
+
* @param useColors - Whether to include ANSI colors
|
|
345
|
+
* @returns Array of formatted lines
|
|
346
|
+
*/
|
|
347
|
+
function formatHexDump(data, maxBytes = 1024, useColors = false) {
|
|
348
|
+
const lines = [];
|
|
349
|
+
const bytesToFormat = Math.min(data.length, maxBytes);
|
|
350
|
+
const bytesPerLine = 16;
|
|
351
|
+
for (let offset = 0; offset < bytesToFormat; offset += bytesPerLine) {
|
|
352
|
+
const chunk = data.slice(offset, Math.min(offset + bytesPerLine, bytesToFormat));
|
|
353
|
+
let line = `${byteToHex(offset >> 24 & 255)}${byteToHex(offset >> 16 & 255)}${byteToHex(offset >> 8 & 255)}${byteToHex(offset & 255)}: `;
|
|
354
|
+
const hexParts = [];
|
|
355
|
+
for (let i = 0; i < bytesPerLine; i++) {
|
|
356
|
+
if (i < chunk.length) hexParts.push(byteToHex(chunk[i]));
|
|
357
|
+
else hexParts.push(" ");
|
|
358
|
+
if (i === 7) hexParts.push("");
|
|
359
|
+
}
|
|
360
|
+
line += hexParts.join(" ");
|
|
361
|
+
let ascii = " │";
|
|
362
|
+
for (let i = 0; i < chunk.length; i++) ascii += isPrintable(chunk[i]) ? String.fromCharCode(chunk[i]) : ".";
|
|
363
|
+
ascii += "│";
|
|
364
|
+
line += ascii;
|
|
365
|
+
if (useColors && isNode()) {
|
|
366
|
+
const hexStart = line.indexOf(":") + 2;
|
|
367
|
+
const delimiterIndex = line.indexOf("│");
|
|
368
|
+
const hexPart = line.slice(hexStart, delimiterIndex);
|
|
369
|
+
const asciiPart = line.slice(delimiterIndex);
|
|
370
|
+
line = line.slice(0, hexStart) + ANSI_COLORS.gray + hexPart + ANSI_COLORS.reset + ANSI_COLORS.dim + asciiPart + ANSI_COLORS.reset;
|
|
371
|
+
}
|
|
372
|
+
lines.push(line);
|
|
373
|
+
}
|
|
374
|
+
if (data.length > maxBytes) {
|
|
375
|
+
const remaining = data.length - maxBytes;
|
|
376
|
+
lines.push(`... (${remaining} more bytes)`);
|
|
377
|
+
}
|
|
378
|
+
return lines;
|
|
379
|
+
}
|
|
380
|
+
/**
|
|
381
|
+
* Debug logger for Cap'n Proto RPC messages
|
|
382
|
+
*/
|
|
383
|
+
var DebugLogger = class {
|
|
384
|
+
config;
|
|
385
|
+
/**
|
|
386
|
+
* Create a new DebugLogger instance
|
|
387
|
+
* @param config - Partial configuration to override defaults
|
|
388
|
+
*/
|
|
389
|
+
constructor(config = {}) {
|
|
390
|
+
this.config = {
|
|
391
|
+
...DEFAULT_CONFIG,
|
|
392
|
+
...config
|
|
393
|
+
};
|
|
394
|
+
}
|
|
395
|
+
/**
|
|
396
|
+
* Update the logger configuration
|
|
397
|
+
* @param config - Partial configuration to merge
|
|
398
|
+
*/
|
|
399
|
+
setConfig(config) {
|
|
400
|
+
this.config = {
|
|
401
|
+
...this.config,
|
|
402
|
+
...config
|
|
403
|
+
};
|
|
404
|
+
}
|
|
405
|
+
/**
|
|
406
|
+
* Get current configuration
|
|
407
|
+
*/
|
|
408
|
+
getConfig() {
|
|
409
|
+
return { ...this.config };
|
|
410
|
+
}
|
|
411
|
+
/**
|
|
412
|
+
* Check if debugging is enabled
|
|
413
|
+
*/
|
|
414
|
+
isEnabled() {
|
|
415
|
+
return this.config.enabled;
|
|
416
|
+
}
|
|
417
|
+
/**
|
|
418
|
+
* Enable debug logging
|
|
419
|
+
*/
|
|
420
|
+
enable() {
|
|
421
|
+
this.config.enabled = true;
|
|
422
|
+
}
|
|
423
|
+
/**
|
|
424
|
+
* Disable debug logging
|
|
425
|
+
*/
|
|
426
|
+
disable() {
|
|
427
|
+
this.config.enabled = false;
|
|
428
|
+
}
|
|
429
|
+
/**
|
|
430
|
+
* Format the header for a log message
|
|
431
|
+
* @param direction - 'send' or 'recv'
|
|
432
|
+
* @param byteLength - Number of bytes
|
|
433
|
+
* @returns Formatted header string
|
|
434
|
+
*/
|
|
435
|
+
formatHeader(direction, byteLength) {
|
|
436
|
+
const prefix = direction === "send" ? "CAPNP:SEND" : "CAPNP:RECV";
|
|
437
|
+
if (isNode() && this.config.colors) return `${direction === "send" ? ANSI_COLORS.green : ANSI_COLORS.blue}[${prefix}]${ANSI_COLORS.reset} ${byteLength} bytes`;
|
|
438
|
+
return `[${prefix}] ${byteLength} bytes`;
|
|
439
|
+
}
|
|
440
|
+
/**
|
|
441
|
+
* Log a Cap'n Proto message
|
|
442
|
+
*
|
|
443
|
+
* Output format:
|
|
444
|
+
* [CAPNP:SEND] 64 bytes
|
|
445
|
+
* 00000000: 00 00 00 00 02 00 00 00 │........│
|
|
446
|
+
* → { messageType: 'Bootstrap', ... }
|
|
447
|
+
*
|
|
448
|
+
* @param direction - 'send' for outgoing, 'recv' for incoming
|
|
449
|
+
* @param data - The raw binary message data
|
|
450
|
+
* @param parsed - Optional parsed message object to display
|
|
451
|
+
*/
|
|
452
|
+
logMessage(direction, data, parsed) {
|
|
453
|
+
if (!this.config.enabled) return;
|
|
454
|
+
const isNodeEnv = isNode();
|
|
455
|
+
const useColors = this.config.colors;
|
|
456
|
+
const header = this.formatHeader(direction, data.length);
|
|
457
|
+
const hexLines = formatHexDump(data, this.config.maxBytesToLog, useColors);
|
|
458
|
+
if (isNodeEnv) {
|
|
459
|
+
console.log(header);
|
|
460
|
+
for (const line of hexLines) console.log(line);
|
|
461
|
+
if (parsed !== void 0) {
|
|
462
|
+
const arrow = useColors ? `${ANSI_COLORS.gray}→${ANSI_COLORS.reset}` : "→";
|
|
463
|
+
const parsedStr = JSON.stringify(parsed, null, 2);
|
|
464
|
+
const coloredParsed = useColors ? `${ANSI_COLORS.cyan}${parsedStr}${ANSI_COLORS.reset}` : parsedStr;
|
|
465
|
+
console.log(`${arrow} ${coloredParsed}`);
|
|
466
|
+
}
|
|
467
|
+
} else if (useColors) {
|
|
468
|
+
const style = direction === "send" ? BROWSER_STYLES.send : BROWSER_STYLES.recv;
|
|
469
|
+
console.log(`%c[CAPNP:${direction.toUpperCase()}]%c ${data.length} bytes`, style, "color: inherit;");
|
|
470
|
+
for (const line of hexLines) console.log(`%c${line}`, BROWSER_STYLES.hex);
|
|
471
|
+
if (parsed !== void 0) console.log("%c→%c %o", BROWSER_STYLES.arrow, BROWSER_STYLES.parsed, parsed);
|
|
472
|
+
} else {
|
|
473
|
+
console.log(header);
|
|
474
|
+
for (const line of hexLines) console.log(line);
|
|
475
|
+
if (parsed !== void 0) console.log("→", parsed);
|
|
476
|
+
}
|
|
477
|
+
}
|
|
478
|
+
/**
|
|
479
|
+
* Log a generic debug message (only if enabled)
|
|
480
|
+
* @param message - Message to log
|
|
481
|
+
* @param args - Additional arguments
|
|
482
|
+
*/
|
|
483
|
+
log(message, ...args) {
|
|
484
|
+
if (!this.config.enabled) return;
|
|
485
|
+
if (isNode() && this.config.colors) console.log(`${ANSI_COLORS.gray}[CAPNP:DEBUG]${ANSI_COLORS.reset} ${message}`, ...args);
|
|
486
|
+
else console.log(`[CAPNP:DEBUG] ${message}`, ...args);
|
|
487
|
+
}
|
|
488
|
+
/**
|
|
489
|
+
* Log an error message (always shown if debug is enabled)
|
|
490
|
+
* @param message - Error message
|
|
491
|
+
* @param error - Optional error object
|
|
492
|
+
*/
|
|
493
|
+
error(message, error) {
|
|
494
|
+
if (!this.config.enabled) return;
|
|
495
|
+
if (isNode() && this.config.colors) console.error(`${ANSI_COLORS.red}[CAPNP:ERROR]${ANSI_COLORS.reset} ${message}`, error ?? "");
|
|
496
|
+
else console.error(`[CAPNP:ERROR] ${message}`, error ?? "");
|
|
497
|
+
}
|
|
498
|
+
};
|
|
499
|
+
/**
|
|
500
|
+
* Create a default debug logger instance
|
|
501
|
+
* @param config - Optional configuration
|
|
502
|
+
* @returns DebugLogger instance
|
|
503
|
+
*/
|
|
504
|
+
function createDebugLogger(config) {
|
|
505
|
+
return new DebugLogger(config);
|
|
506
|
+
}
|
|
507
|
+
/**
|
|
508
|
+
* Global debug logger instance for convenience
|
|
509
|
+
*/
|
|
510
|
+
const debug = new DebugLogger();
|
|
511
|
+
|
|
199
512
|
//#endregion
|
|
200
513
|
//#region src/rpc/pipeline.ts
|
|
201
514
|
/**
|
|
@@ -1457,9 +1770,26 @@ function serializeListSchemasResults(results) {
|
|
|
1457
1770
|
|
|
1458
1771
|
//#endregion
|
|
1459
1772
|
//#region src/rpc/rpc-connection.ts
|
|
1773
|
+
/**
|
|
1774
|
+
* RpcConnection
|
|
1775
|
+
*
|
|
1776
|
+
* Manages a single RPC connection, handling message routing and the Four Tables.
|
|
1777
|
+
* This is the core of the RPC implementation.
|
|
1778
|
+
*
|
|
1779
|
+
* Phase 2 Updates:
|
|
1780
|
+
* - Added Promise Pipelining support
|
|
1781
|
+
* - Added capability passing
|
|
1782
|
+
* - Added Resolve/Release/Disembargo message handling
|
|
1783
|
+
*
|
|
1784
|
+
* Phase 4 Updates:
|
|
1785
|
+
* - Added Level 3 RPC support (Provide/Accept)
|
|
1786
|
+
* - Added third-party capability handling
|
|
1787
|
+
* - Integrated with ConnectionManager for multi-vat scenarios
|
|
1788
|
+
*/
|
|
1460
1789
|
var RpcConnection = class {
|
|
1461
1790
|
transport;
|
|
1462
1791
|
options;
|
|
1792
|
+
debugLogger = createDebugLogger();
|
|
1463
1793
|
questions = new QuestionTable();
|
|
1464
1794
|
answers = new AnswerTable();
|
|
1465
1795
|
imports = new ImportTable();
|
|
@@ -1478,6 +1808,11 @@ var RpcConnection = class {
|
|
|
1478
1808
|
this.transport = transport;
|
|
1479
1809
|
this.options = options;
|
|
1480
1810
|
this.level3Handlers = options.level3Handlers;
|
|
1811
|
+
if (options.debug ?? isDebugEnabled()) {
|
|
1812
|
+
this.debugLogger.enable();
|
|
1813
|
+
this.debugLogger.setConfig(getDebugOptions());
|
|
1814
|
+
this.debugLogger.log("RPC connection created");
|
|
1815
|
+
}
|
|
1481
1816
|
this.transport.onClose = (reason) => {
|
|
1482
1817
|
this.handleDisconnect(reason);
|
|
1483
1818
|
};
|
|
@@ -1508,7 +1843,7 @@ var RpcConnection = class {
|
|
|
1508
1843
|
type: "bootstrap",
|
|
1509
1844
|
bootstrap: { questionId: question.id }
|
|
1510
1845
|
};
|
|
1511
|
-
await this.
|
|
1846
|
+
await this.sendWithLogging(bootstrapMsg);
|
|
1512
1847
|
await question.completionPromise;
|
|
1513
1848
|
return {};
|
|
1514
1849
|
}
|
|
@@ -1533,7 +1868,7 @@ var RpcConnection = class {
|
|
|
1533
1868
|
sendResultsTo: { type: "caller" }
|
|
1534
1869
|
}
|
|
1535
1870
|
};
|
|
1536
|
-
await this.
|
|
1871
|
+
await this.sendWithLogging(callMsg);
|
|
1537
1872
|
return question.completionPromise;
|
|
1538
1873
|
}
|
|
1539
1874
|
/**
|
|
@@ -1559,7 +1894,7 @@ var RpcConnection = class {
|
|
|
1559
1894
|
sendResultsTo: { type: "caller" }
|
|
1560
1895
|
}
|
|
1561
1896
|
};
|
|
1562
|
-
await this.
|
|
1897
|
+
await this.sendWithLogging(callMsg);
|
|
1563
1898
|
return createPipelineClient({
|
|
1564
1899
|
connection: this,
|
|
1565
1900
|
questionId: question.id
|
|
@@ -1576,7 +1911,7 @@ var RpcConnection = class {
|
|
|
1576
1911
|
requireEarlyCancellationWorkaround: false
|
|
1577
1912
|
}
|
|
1578
1913
|
};
|
|
1579
|
-
await this.
|
|
1914
|
+
await this.sendWithLogging(finishMsg);
|
|
1580
1915
|
this.questions.markFinishSent(questionId);
|
|
1581
1916
|
this.questions.remove(questionId);
|
|
1582
1917
|
}
|
|
@@ -1589,7 +1924,7 @@ var RpcConnection = class {
|
|
|
1589
1924
|
referenceCount
|
|
1590
1925
|
}
|
|
1591
1926
|
};
|
|
1592
|
-
await this.
|
|
1927
|
+
await this.sendWithLogging(releaseMsg);
|
|
1593
1928
|
}
|
|
1594
1929
|
/** Send a resolve message to indicate a promise has resolved */
|
|
1595
1930
|
async resolve(promiseId, cap) {
|
|
@@ -1603,7 +1938,7 @@ var RpcConnection = class {
|
|
|
1603
1938
|
}
|
|
1604
1939
|
}
|
|
1605
1940
|
};
|
|
1606
|
-
await this.
|
|
1941
|
+
await this.sendWithLogging(resolveMsg);
|
|
1607
1942
|
}
|
|
1608
1943
|
/** Send a resolve message indicating a promise was broken */
|
|
1609
1944
|
async resolveException(promiseId, reason) {
|
|
@@ -1620,7 +1955,7 @@ var RpcConnection = class {
|
|
|
1620
1955
|
}
|
|
1621
1956
|
}
|
|
1622
1957
|
};
|
|
1623
|
-
await this.
|
|
1958
|
+
await this.sendWithLogging(resolveMsg);
|
|
1624
1959
|
}
|
|
1625
1960
|
/** Send a return message (internal use) */
|
|
1626
1961
|
async sendReturn(ret) {
|
|
@@ -1628,7 +1963,7 @@ var RpcConnection = class {
|
|
|
1628
1963
|
type: "return",
|
|
1629
1964
|
return: ret
|
|
1630
1965
|
};
|
|
1631
|
-
await this.
|
|
1966
|
+
await this.sendWithLogging(returnMsg);
|
|
1632
1967
|
}
|
|
1633
1968
|
/** Send a disembargo message (internal use) */
|
|
1634
1969
|
async sendDisembargo(disembargo) {
|
|
@@ -1636,7 +1971,7 @@ var RpcConnection = class {
|
|
|
1636
1971
|
type: "disembargo",
|
|
1637
1972
|
disembargo
|
|
1638
1973
|
};
|
|
1639
|
-
await this.
|
|
1974
|
+
await this.sendWithLogging(disembargoMsg);
|
|
1640
1975
|
}
|
|
1641
1976
|
/** Internal method: Create a new question (used by pipeline) */
|
|
1642
1977
|
createQuestion() {
|
|
@@ -1648,7 +1983,7 @@ var RpcConnection = class {
|
|
|
1648
1983
|
type: "call",
|
|
1649
1984
|
call
|
|
1650
1985
|
};
|
|
1651
|
-
await this.
|
|
1986
|
+
await this.sendWithLogging(callMsg);
|
|
1652
1987
|
}
|
|
1653
1988
|
/** Internal method: Wait for an answer (used by pipeline) */
|
|
1654
1989
|
async waitForAnswer(questionId) {
|
|
@@ -1659,7 +1994,7 @@ var RpcConnection = class {
|
|
|
1659
1994
|
/** Main message processing loop */
|
|
1660
1995
|
async messageLoop() {
|
|
1661
1996
|
while (this.running) try {
|
|
1662
|
-
const message = await this.
|
|
1997
|
+
const message = await this.receiveWithLogging();
|
|
1663
1998
|
if (message === null) break;
|
|
1664
1999
|
await this.handleMessage(message);
|
|
1665
2000
|
} catch (error) {
|
|
@@ -1724,7 +2059,7 @@ var RpcConnection = class {
|
|
|
1724
2059
|
}
|
|
1725
2060
|
}
|
|
1726
2061
|
};
|
|
1727
|
-
await this.
|
|
2062
|
+
await this.sendWithLogging(returnMsg);
|
|
1728
2063
|
this.answers.markReturnSent(bootstrap.questionId);
|
|
1729
2064
|
}
|
|
1730
2065
|
/** Handle incoming call */
|
|
@@ -1745,7 +2080,7 @@ var RpcConnection = class {
|
|
|
1745
2080
|
}
|
|
1746
2081
|
}
|
|
1747
2082
|
};
|
|
1748
|
-
await this.
|
|
2083
|
+
await this.sendWithLogging(returnMsg);
|
|
1749
2084
|
this.answers.markReturnSent(call.questionId);
|
|
1750
2085
|
}
|
|
1751
2086
|
/** Handle return message */
|
|
@@ -1815,7 +2150,7 @@ var RpcConnection = class {
|
|
|
1815
2150
|
}
|
|
1816
2151
|
}
|
|
1817
2152
|
};
|
|
1818
|
-
await this.
|
|
2153
|
+
await this.sendWithLogging(echoMsg);
|
|
1819
2154
|
}
|
|
1820
2155
|
}
|
|
1821
2156
|
/** Handle provide message (Level 3) */
|
|
@@ -1872,7 +2207,7 @@ var RpcConnection = class {
|
|
|
1872
2207
|
type: "unimplemented",
|
|
1873
2208
|
message: originalMessage
|
|
1874
2209
|
};
|
|
1875
|
-
await this.
|
|
2210
|
+
await this.sendWithLogging(msg);
|
|
1876
2211
|
}
|
|
1877
2212
|
/** Send return exception (helper) */
|
|
1878
2213
|
async sendReturnException(questionId, reason) {
|
|
@@ -1891,7 +2226,7 @@ var RpcConnection = class {
|
|
|
1891
2226
|
}
|
|
1892
2227
|
}
|
|
1893
2228
|
};
|
|
1894
|
-
await this.
|
|
2229
|
+
await this.sendWithLogging(returnMsg);
|
|
1895
2230
|
}
|
|
1896
2231
|
/**
|
|
1897
2232
|
* Set the Level 4 handlers for this connection.
|
|
@@ -2038,7 +2373,7 @@ var RpcConnection = class {
|
|
|
2038
2373
|
sendResultsTo: { type: "caller" }
|
|
2039
2374
|
}
|
|
2040
2375
|
};
|
|
2041
|
-
await this.
|
|
2376
|
+
await this.sendWithLogging(schemaRequestMsg);
|
|
2042
2377
|
const question = this.questions.create();
|
|
2043
2378
|
question.id = questionId;
|
|
2044
2379
|
try {
|
|
@@ -2132,7 +2467,7 @@ var RpcConnection = class {
|
|
|
2132
2467
|
sendResultsTo: { type: "caller" }
|
|
2133
2468
|
}
|
|
2134
2469
|
};
|
|
2135
|
-
await this.
|
|
2470
|
+
await this.sendWithLogging(listRequestMsg);
|
|
2136
2471
|
const question = this.questions.create();
|
|
2137
2472
|
question.id = questionId;
|
|
2138
2473
|
try {
|
|
@@ -2151,8 +2486,19 @@ var RpcConnection = class {
|
|
|
2151
2486
|
throw error;
|
|
2152
2487
|
}
|
|
2153
2488
|
}
|
|
2489
|
+
/** Send a message with debug logging */
|
|
2490
|
+
async sendWithLogging(message) {
|
|
2491
|
+
if (this.debugLogger.isEnabled()) this.debugLogger.log(`[RPC:SEND] ${message.type}`);
|
|
2492
|
+
await this.transport.send(message);
|
|
2493
|
+
}
|
|
2494
|
+
/** Receive a message with debug logging */
|
|
2495
|
+
async receiveWithLogging() {
|
|
2496
|
+
const message = await this.transport.receive();
|
|
2497
|
+
if (message !== null && this.debugLogger.isEnabled()) this.debugLogger.log(`[RPC:RECV] ${message.type}`);
|
|
2498
|
+
return message;
|
|
2499
|
+
}
|
|
2154
2500
|
};
|
|
2155
2501
|
|
|
2156
2502
|
//#endregion
|
|
2157
|
-
export { QuestionTable as C, ImportTable as S, QueuedCallManager as _, serializeGetSchemaParams as a, AnswerTable as b, serializeSchemaRequest as c, parseSchemaNodes as d, SchemaFormat as f, PipelineResolutionTracker as g, PipelineOpTracker as h, deserializeSchemaResponse as i, serializeSchemaResponse as l, PIPELINE_CLIENT_SYMBOL as m, SCHEMA_MESSAGE_TYPES as n, serializeGetSchemaResults as o, SchemaNodeType as p, deserializeSchemaRequest as r, serializeListSchemasResults as s, RpcConnection as t, createSchemaRegistry as u, createPipelineClient as v, ExportTable as x, isPipelineClient as y };
|
|
2158
|
-
//# sourceMappingURL=rpc-connection-
|
|
2503
|
+
export { QuestionTable as C, isDebugEnabled as E, ImportTable as S, enableDebug as T, QueuedCallManager as _, serializeGetSchemaParams as a, AnswerTable as b, serializeSchemaRequest as c, parseSchemaNodes as d, SchemaFormat as f, PipelineResolutionTracker as g, PipelineOpTracker as h, deserializeSchemaResponse as i, serializeSchemaResponse as l, PIPELINE_CLIENT_SYMBOL as m, SCHEMA_MESSAGE_TYPES as n, serializeGetSchemaResults as o, SchemaNodeType as p, deserializeSchemaRequest as r, serializeListSchemasResults as s, RpcConnection as t, createSchemaRegistry as u, createPipelineClient as v, disableDebug as w, ExportTable as x, isPipelineClient as y };
|
|
2504
|
+
//# sourceMappingURL=rpc-connection-CHjKsrMC.js.map
|