@naeemo/capnp 0.5.0 → 0.5.2
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/cli.js +69 -22
- package/dist/cli.js.map +1 -1
- package/dist/index.cjs +412 -24
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +382 -24
- package/dist/index.js.map +1 -1
- package/dist/rpc-connection-CDzawjwJ.js +3 -0
- package/dist/{rpc-connection-CnyIwb0Z.js → rpc-connection-_eHtWsk2.js} +1 -25
- package/dist/{rpc-connection-CnyIwb0Z.js.map → rpc-connection-_eHtWsk2.js.map} +1 -1
- package/package.json +38 -26
- /package/dist/{rpc-connection-BPkslKv3.js → rpc-connection-jIPnPyT6.js} +0 -0
package/dist/index.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
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-C3-uEtpd.js";
|
|
2
2
|
import { createRequire } from "node:module";
|
|
3
|
+
import * as net from "node:net";
|
|
3
4
|
|
|
4
5
|
//#region \0rolldown/runtime.js
|
|
5
6
|
var __require = /* @__PURE__ */ createRequire(import.meta.url);
|
|
@@ -132,6 +133,7 @@ var Segment = class Segment {
|
|
|
132
133
|
*/
|
|
133
134
|
getWord(wordOffset) {
|
|
134
135
|
const byteOffset = wordOffset * WORD_SIZE;
|
|
136
|
+
if (byteOffset + 8 > this._size) throw new Error(`Offset ${wordOffset} is outside the bounds of the segment (${this.wordCount} words)`);
|
|
135
137
|
const low = BigInt(this.view.getUint32(byteOffset, true));
|
|
136
138
|
return BigInt(this.view.getUint32(byteOffset + 4, true)) << BigInt(32) | low;
|
|
137
139
|
}
|
|
@@ -140,6 +142,7 @@ var Segment = class Segment {
|
|
|
140
142
|
*/
|
|
141
143
|
setWord(wordOffset, value) {
|
|
142
144
|
const byteOffset = wordOffset * WORD_SIZE;
|
|
145
|
+
if (byteOffset + 8 > this.buffer.byteLength) throw new Error(`Offset ${wordOffset} is outside the bounds of the segment`);
|
|
143
146
|
this.view.setUint32(byteOffset, Number(value & BigInt(4294967295)), true);
|
|
144
147
|
this.view.setUint32(byteOffset + 4, Number(value >> BigInt(32)), true);
|
|
145
148
|
}
|
|
@@ -641,73 +644,113 @@ var StructReader = class StructReader {
|
|
|
641
644
|
getBool(bitOffset) {
|
|
642
645
|
const byteOffset = Math.floor(bitOffset / 8);
|
|
643
646
|
const bitInByte = bitOffset % 8;
|
|
644
|
-
|
|
647
|
+
const segment = this.message.getSegment(this.segmentIndex);
|
|
648
|
+
const dataOffset = this.wordOffset * WORD_SIZE + byteOffset;
|
|
649
|
+
const dataSectionEnd = this.wordOffset * WORD_SIZE + this.dataWords * WORD_SIZE;
|
|
650
|
+
if (dataOffset < 0 || dataOffset >= dataSectionEnd) return false;
|
|
651
|
+
return (segment.dataView.getUint8(dataOffset) & 1 << bitInByte) !== 0;
|
|
645
652
|
}
|
|
646
653
|
/**
|
|
647
654
|
* 获取 int8 字段
|
|
648
655
|
*/
|
|
649
656
|
getInt8(byteOffset) {
|
|
650
|
-
|
|
657
|
+
const segment = this.message.getSegment(this.segmentIndex);
|
|
658
|
+
const dataOffset = this.wordOffset * WORD_SIZE + byteOffset;
|
|
659
|
+
const dataSectionEnd = this.wordOffset * WORD_SIZE + this.dataWords * WORD_SIZE;
|
|
660
|
+
if (dataOffset < 0 || dataOffset >= dataSectionEnd) return 0;
|
|
661
|
+
return segment.dataView.getInt8(dataOffset);
|
|
651
662
|
}
|
|
652
663
|
/**
|
|
653
664
|
* 获取 int16 字段
|
|
654
665
|
*/
|
|
655
666
|
getInt16(byteOffset) {
|
|
656
|
-
|
|
667
|
+
const segment = this.message.getSegment(this.segmentIndex);
|
|
668
|
+
const dataOffset = this.wordOffset * WORD_SIZE + byteOffset;
|
|
669
|
+
const dataSectionEnd = this.wordOffset * WORD_SIZE + this.dataWords * WORD_SIZE;
|
|
670
|
+
if (dataOffset < 0 || dataOffset + 2 > dataSectionEnd) return 0;
|
|
671
|
+
return segment.dataView.getInt16(dataOffset, true);
|
|
657
672
|
}
|
|
658
673
|
/**
|
|
659
674
|
* 获取 int32 字段
|
|
660
675
|
*/
|
|
661
676
|
getInt32(byteOffset) {
|
|
662
|
-
|
|
677
|
+
const segment = this.message.getSegment(this.segmentIndex);
|
|
678
|
+
const dataOffset = this.wordOffset * WORD_SIZE + byteOffset;
|
|
679
|
+
const dataSectionEnd = this.wordOffset * WORD_SIZE + this.dataWords * WORD_SIZE;
|
|
680
|
+
if (dataOffset < 0 || dataOffset + 4 > dataSectionEnd) return 0;
|
|
681
|
+
return segment.dataView.getInt32(dataOffset, true);
|
|
663
682
|
}
|
|
664
683
|
/**
|
|
665
684
|
* 获取 int64 字段
|
|
666
685
|
*/
|
|
667
686
|
getInt64(byteOffset) {
|
|
668
687
|
const segment = this.message.getSegment(this.segmentIndex);
|
|
669
|
-
const
|
|
670
|
-
const
|
|
671
|
-
|
|
688
|
+
const dataOffset = this.wordOffset * WORD_SIZE + byteOffset;
|
|
689
|
+
const dataSectionEnd = this.wordOffset * WORD_SIZE + this.dataWords * WORD_SIZE;
|
|
690
|
+
if (dataOffset < 0 || dataOffset + 8 > dataSectionEnd) return BigInt(0);
|
|
691
|
+
const low = BigInt(segment.dataView.getUint32(dataOffset, true));
|
|
692
|
+
return BigInt(segment.dataView.getInt32(dataOffset + 4, true)) << BigInt(32) | low;
|
|
672
693
|
}
|
|
673
694
|
/**
|
|
674
695
|
* 获取 uint8 字段
|
|
675
696
|
*/
|
|
676
697
|
getUint8(byteOffset) {
|
|
677
|
-
|
|
698
|
+
const segment = this.message.getSegment(this.segmentIndex);
|
|
699
|
+
const dataOffset = this.wordOffset * WORD_SIZE + byteOffset;
|
|
700
|
+
const dataSectionEnd = this.wordOffset * WORD_SIZE + this.dataWords * WORD_SIZE;
|
|
701
|
+
if (dataOffset < 0 || dataOffset >= dataSectionEnd) return 0;
|
|
702
|
+
return segment.dataView.getUint8(dataOffset);
|
|
678
703
|
}
|
|
679
704
|
/**
|
|
680
705
|
* 获取 uint16 字段
|
|
681
706
|
*/
|
|
682
707
|
getUint16(byteOffset) {
|
|
683
|
-
|
|
708
|
+
const segment = this.message.getSegment(this.segmentIndex);
|
|
709
|
+
const dataOffset = this.wordOffset * WORD_SIZE + byteOffset;
|
|
710
|
+
const dataSectionEnd = this.wordOffset * WORD_SIZE + this.dataWords * WORD_SIZE;
|
|
711
|
+
if (dataOffset < 0 || dataOffset + 2 > dataSectionEnd) return 0;
|
|
712
|
+
return segment.dataView.getUint16(dataOffset, true);
|
|
684
713
|
}
|
|
685
714
|
/**
|
|
686
715
|
* 获取 uint32 字段
|
|
687
716
|
*/
|
|
688
717
|
getUint32(byteOffset) {
|
|
689
|
-
|
|
718
|
+
const segment = this.message.getSegment(this.segmentIndex);
|
|
719
|
+
const dataOffset = this.wordOffset * WORD_SIZE + byteOffset;
|
|
720
|
+
const dataSectionEnd = this.wordOffset * WORD_SIZE + this.dataWords * WORD_SIZE;
|
|
721
|
+
if (dataOffset < 0 || dataOffset + 4 > dataSectionEnd) return 0;
|
|
722
|
+
return segment.dataView.getUint32(dataOffset, true);
|
|
690
723
|
}
|
|
691
724
|
/**
|
|
692
725
|
* 获取 uint64 字段
|
|
693
726
|
*/
|
|
694
727
|
getUint64(byteOffset) {
|
|
695
728
|
const segment = this.message.getSegment(this.segmentIndex);
|
|
696
|
-
const
|
|
697
|
-
const
|
|
698
|
-
|
|
729
|
+
const dataOffset = this.wordOffset * WORD_SIZE + byteOffset;
|
|
730
|
+
const dataSectionEnd = this.wordOffset * WORD_SIZE + this.dataWords * WORD_SIZE;
|
|
731
|
+
if (dataOffset < 0 || dataOffset + 8 > dataSectionEnd) return BigInt(0);
|
|
732
|
+
const low = BigInt(segment.dataView.getUint32(dataOffset, true));
|
|
733
|
+
return BigInt(segment.dataView.getUint32(dataOffset + 4, true)) << BigInt(32) | low;
|
|
699
734
|
}
|
|
700
735
|
/**
|
|
701
736
|
* 获取 float32 字段
|
|
702
737
|
*/
|
|
703
738
|
getFloat32(byteOffset) {
|
|
704
|
-
|
|
739
|
+
const segment = this.message.getSegment(this.segmentIndex);
|
|
740
|
+
const dataOffset = this.wordOffset * WORD_SIZE + byteOffset;
|
|
741
|
+
const dataSectionEnd = this.wordOffset * WORD_SIZE + this.dataWords * WORD_SIZE;
|
|
742
|
+
if (dataOffset < 0 || dataOffset + 4 > dataSectionEnd) return 0;
|
|
743
|
+
return segment.dataView.getFloat32(dataOffset, true);
|
|
705
744
|
}
|
|
706
745
|
/**
|
|
707
746
|
* 获取 float64 字段
|
|
708
747
|
*/
|
|
709
748
|
getFloat64(byteOffset) {
|
|
710
|
-
|
|
749
|
+
const segment = this.message.getSegment(this.segmentIndex);
|
|
750
|
+
const dataOffset = this.wordOffset * WORD_SIZE + byteOffset;
|
|
751
|
+
const dataSectionEnd = this.wordOffset * WORD_SIZE + this.dataWords * WORD_SIZE;
|
|
752
|
+
if (dataOffset < 0 || dataOffset + 8 > dataSectionEnd) return 0;
|
|
753
|
+
return segment.dataView.getFloat64(dataOffset, true);
|
|
711
754
|
}
|
|
712
755
|
/**
|
|
713
756
|
* 获取文本字段
|
|
@@ -752,13 +795,18 @@ var StructReader = class StructReader {
|
|
|
752
795
|
let actualStructSize = structSize;
|
|
753
796
|
const segment = this.message.getSegment(segmentIndex);
|
|
754
797
|
if (listPtr.elementSize === ElementSize.COMPOSITE) {
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
798
|
+
if (targetOffset < 0 || targetOffset >= segment.wordCount) return;
|
|
799
|
+
try {
|
|
800
|
+
const tagWord = segment.getWord(targetOffset);
|
|
801
|
+
elementCount = Number(tagWord & BigInt(4294967295));
|
|
802
|
+
actualStructSize = {
|
|
803
|
+
dataWords: Number(tagWord >> BigInt(32) & BigInt(65535)),
|
|
804
|
+
pointerCount: Number(tagWord >> BigInt(48) & BigInt(65535))
|
|
805
|
+
};
|
|
806
|
+
targetOffset += 1;
|
|
807
|
+
} catch {
|
|
808
|
+
return;
|
|
809
|
+
}
|
|
762
810
|
}
|
|
763
811
|
return new ListReader(this.message, segmentIndex, listPtr.elementSize, elementCount, actualStructSize, targetOffset);
|
|
764
812
|
}
|
|
@@ -1698,6 +1746,316 @@ var WebSocketTransport = class WebSocketTransport {
|
|
|
1698
1746
|
}
|
|
1699
1747
|
};
|
|
1700
1748
|
|
|
1749
|
+
//#endregion
|
|
1750
|
+
//#region src/rpc/tcp-transport.ts
|
|
1751
|
+
/**
|
|
1752
|
+
* TCP Transport Implementation for Node.js
|
|
1753
|
+
*
|
|
1754
|
+
* Implements RpcTransport over raw TCP socket for C++ interop testing.
|
|
1755
|
+
* This allows direct communication with the official Cap'n Proto C++ implementation.
|
|
1756
|
+
*/
|
|
1757
|
+
/**
|
|
1758
|
+
* TCP Transport for Cap'n Proto RPC
|
|
1759
|
+
*
|
|
1760
|
+
* Uses length-prefixed binary message framing compatible with Cap'n Proto C++ implementation.
|
|
1761
|
+
* Format: [4 bytes: message length (little-endian)] [N bytes: message data]
|
|
1762
|
+
*/
|
|
1763
|
+
var TcpTransport = class TcpTransport {
|
|
1764
|
+
socket = null;
|
|
1765
|
+
messageQueue = [];
|
|
1766
|
+
receiveQueue = [];
|
|
1767
|
+
_connected = false;
|
|
1768
|
+
pendingBuffer = Buffer.alloc(0);
|
|
1769
|
+
pendingLength = 0;
|
|
1770
|
+
hasPendingLength = false;
|
|
1771
|
+
onClose;
|
|
1772
|
+
onError;
|
|
1773
|
+
constructor(host, port, options = {}) {
|
|
1774
|
+
this.host = host;
|
|
1775
|
+
this.port = port;
|
|
1776
|
+
this.options = options;
|
|
1777
|
+
}
|
|
1778
|
+
static async connect(host, port, options) {
|
|
1779
|
+
const transport = new TcpTransport(host, port, options);
|
|
1780
|
+
await transport.connect();
|
|
1781
|
+
return transport;
|
|
1782
|
+
}
|
|
1783
|
+
static fromSocket(socket, options) {
|
|
1784
|
+
const transport = new TcpTransport("", 0, options);
|
|
1785
|
+
transport.attachSocket(socket);
|
|
1786
|
+
return transport;
|
|
1787
|
+
}
|
|
1788
|
+
get connected() {
|
|
1789
|
+
return this._connected && this.socket?.readyState === "open";
|
|
1790
|
+
}
|
|
1791
|
+
connect() {
|
|
1792
|
+
return new Promise((resolve, reject) => {
|
|
1793
|
+
const timeout = setTimeout(() => {
|
|
1794
|
+
this.socket?.destroy();
|
|
1795
|
+
reject(/* @__PURE__ */ new Error("Connection timeout"));
|
|
1796
|
+
}, this.options.connectTimeoutMs ?? 1e4);
|
|
1797
|
+
this.socket = new net.Socket();
|
|
1798
|
+
this.socket.on("connect", () => {
|
|
1799
|
+
clearTimeout(timeout);
|
|
1800
|
+
this._connected = true;
|
|
1801
|
+
resolve();
|
|
1802
|
+
});
|
|
1803
|
+
this.socket.on("data", (data) => {
|
|
1804
|
+
this.handleData(data);
|
|
1805
|
+
});
|
|
1806
|
+
this.socket.on("close", (hadError) => {
|
|
1807
|
+
this._connected = false;
|
|
1808
|
+
this.flushReceiveQueue(null);
|
|
1809
|
+
if (hadError) this.onClose?.(/* @__PURE__ */ new Error("Connection closed with error"));
|
|
1810
|
+
else this.onClose?.();
|
|
1811
|
+
});
|
|
1812
|
+
this.socket.on("error", (err) => {
|
|
1813
|
+
clearTimeout(timeout);
|
|
1814
|
+
this._connected = false;
|
|
1815
|
+
this.onError?.(err);
|
|
1816
|
+
reject(err);
|
|
1817
|
+
});
|
|
1818
|
+
this.socket.on("end", () => {
|
|
1819
|
+
this._connected = false;
|
|
1820
|
+
});
|
|
1821
|
+
this.socket.connect(this.port, this.host);
|
|
1822
|
+
});
|
|
1823
|
+
}
|
|
1824
|
+
attachSocket(socket) {
|
|
1825
|
+
this.socket = socket;
|
|
1826
|
+
this._connected = socket.readyState === "open";
|
|
1827
|
+
socket.on("data", (data) => {
|
|
1828
|
+
this.handleData(data);
|
|
1829
|
+
});
|
|
1830
|
+
socket.on("close", (hadError) => {
|
|
1831
|
+
this._connected = false;
|
|
1832
|
+
this.flushReceiveQueue(null);
|
|
1833
|
+
if (hadError) this.onClose?.(/* @__PURE__ */ new Error("Connection closed with error"));
|
|
1834
|
+
else this.onClose?.();
|
|
1835
|
+
});
|
|
1836
|
+
socket.on("error", (err) => {
|
|
1837
|
+
this._connected = false;
|
|
1838
|
+
this.onError?.(err);
|
|
1839
|
+
});
|
|
1840
|
+
socket.on("end", () => {
|
|
1841
|
+
this._connected = false;
|
|
1842
|
+
});
|
|
1843
|
+
}
|
|
1844
|
+
handleData(data) {
|
|
1845
|
+
this.pendingBuffer = Buffer.concat([this.pendingBuffer, data]);
|
|
1846
|
+
while (this.pendingBuffer.length >= 4) {
|
|
1847
|
+
if (!this.hasPendingLength) {
|
|
1848
|
+
this.pendingLength = this.pendingBuffer.readUInt32LE(0);
|
|
1849
|
+
this.hasPendingLength = true;
|
|
1850
|
+
if (this.pendingLength > 64 * 1024 * 1024) {
|
|
1851
|
+
this.onError?.(/* @__PURE__ */ new Error(`Message too large: ${this.pendingLength} bytes`));
|
|
1852
|
+
this.close(/* @__PURE__ */ new Error("Message too large"));
|
|
1853
|
+
return;
|
|
1854
|
+
}
|
|
1855
|
+
}
|
|
1856
|
+
const totalLength = 4 + this.pendingLength;
|
|
1857
|
+
if (this.pendingBuffer.length < totalLength) break;
|
|
1858
|
+
const messageData = this.pendingBuffer.subarray(4, totalLength);
|
|
1859
|
+
this.pendingBuffer = this.pendingBuffer.subarray(totalLength);
|
|
1860
|
+
this.hasPendingLength = false;
|
|
1861
|
+
try {
|
|
1862
|
+
const message = deserializeRpcMessage(new Uint8Array(messageData));
|
|
1863
|
+
this.handleRpcMessage(message);
|
|
1864
|
+
} catch (err) {
|
|
1865
|
+
this.onError?.(err instanceof Error ? err : new Error(String(err)));
|
|
1866
|
+
}
|
|
1867
|
+
}
|
|
1868
|
+
}
|
|
1869
|
+
handleRpcMessage(message) {
|
|
1870
|
+
if (this.receiveQueue.length > 0) {
|
|
1871
|
+
const { resolve } = this.receiveQueue.shift();
|
|
1872
|
+
resolve(message);
|
|
1873
|
+
} else this.messageQueue.push(message);
|
|
1874
|
+
}
|
|
1875
|
+
async send(message) {
|
|
1876
|
+
if (!this.socket || this.socket.readyState !== "open") throw new Error("Socket not connected");
|
|
1877
|
+
const data = serializeRpcMessage(message);
|
|
1878
|
+
const frame = Buffer.allocUnsafe(4 + data.length);
|
|
1879
|
+
frame.writeUInt32LE(data.length, 0);
|
|
1880
|
+
frame.set(data, 4);
|
|
1881
|
+
return new Promise((resolve, reject) => {
|
|
1882
|
+
this.socket.write(frame, (err) => {
|
|
1883
|
+
if (err) reject(err);
|
|
1884
|
+
else resolve();
|
|
1885
|
+
});
|
|
1886
|
+
});
|
|
1887
|
+
}
|
|
1888
|
+
async receive() {
|
|
1889
|
+
if (this.messageQueue.length > 0) return this.messageQueue.shift();
|
|
1890
|
+
if (!this._connected) return null;
|
|
1891
|
+
return new Promise((resolve, reject) => {
|
|
1892
|
+
this.receiveQueue.push({
|
|
1893
|
+
resolve,
|
|
1894
|
+
reject
|
|
1895
|
+
});
|
|
1896
|
+
});
|
|
1897
|
+
}
|
|
1898
|
+
close(reason) {
|
|
1899
|
+
this._connected = false;
|
|
1900
|
+
this.socket?.end();
|
|
1901
|
+
this.socket?.destroy();
|
|
1902
|
+
this.flushReceiveQueue(null);
|
|
1903
|
+
this.onClose?.(reason);
|
|
1904
|
+
}
|
|
1905
|
+
flushReceiveQueue(value) {
|
|
1906
|
+
while (this.receiveQueue.length > 0) {
|
|
1907
|
+
const { resolve } = this.receiveQueue.shift();
|
|
1908
|
+
resolve(value);
|
|
1909
|
+
}
|
|
1910
|
+
}
|
|
1911
|
+
};
|
|
1912
|
+
|
|
1913
|
+
//#endregion
|
|
1914
|
+
//#region src/rpc/ezrpc-transport.ts
|
|
1915
|
+
/**
|
|
1916
|
+
* EzRpc TCP Transport
|
|
1917
|
+
*
|
|
1918
|
+
* Implements RpcTransport over raw TCP socket for C++ EzRpc compatibility.
|
|
1919
|
+
* Does NOT use length-prefixed framing - sends raw Cap'n Proto messages.
|
|
1920
|
+
*/
|
|
1921
|
+
/**
|
|
1922
|
+
* EzRpc TCP Transport
|
|
1923
|
+
*
|
|
1924
|
+
* Compatible with Cap'n Proto C++ EzRpcServer/EzRpcClient.
|
|
1925
|
+
* Sends raw Cap'n Proto messages without length prefix.
|
|
1926
|
+
*/
|
|
1927
|
+
var EzRpcTransport = class EzRpcTransport {
|
|
1928
|
+
socket = null;
|
|
1929
|
+
messageQueue = [];
|
|
1930
|
+
receiveQueue = [];
|
|
1931
|
+
_connected = false;
|
|
1932
|
+
pendingBuffer = Buffer.alloc(0);
|
|
1933
|
+
onClose;
|
|
1934
|
+
onError;
|
|
1935
|
+
constructor(host, port, options = {}) {
|
|
1936
|
+
this.host = host;
|
|
1937
|
+
this.port = port;
|
|
1938
|
+
this.options = options;
|
|
1939
|
+
}
|
|
1940
|
+
static async connect(host, port, options) {
|
|
1941
|
+
const transport = new EzRpcTransport(host, port, options);
|
|
1942
|
+
await transport.doConnect();
|
|
1943
|
+
return transport;
|
|
1944
|
+
}
|
|
1945
|
+
get connected() {
|
|
1946
|
+
return this._connected && this.socket !== null && !this.socket.destroyed;
|
|
1947
|
+
}
|
|
1948
|
+
doConnect() {
|
|
1949
|
+
return new Promise((resolve, reject) => {
|
|
1950
|
+
const timeout = setTimeout(() => {
|
|
1951
|
+
this.socket?.destroy();
|
|
1952
|
+
reject(/* @__PURE__ */ new Error(`Connection timeout: failed to connect to ${this.host}:${this.port}`));
|
|
1953
|
+
}, this.options.connectTimeoutMs ?? 1e4);
|
|
1954
|
+
this.socket = new net.Socket();
|
|
1955
|
+
this.socket.on("connect", () => {
|
|
1956
|
+
clearTimeout(timeout);
|
|
1957
|
+
this._connected = true;
|
|
1958
|
+
resolve();
|
|
1959
|
+
});
|
|
1960
|
+
this.socket.on("data", (data) => {
|
|
1961
|
+
try {
|
|
1962
|
+
this.handleData(data);
|
|
1963
|
+
} catch (err) {
|
|
1964
|
+
this.onError?.(err instanceof Error ? err : new Error(String(err)));
|
|
1965
|
+
}
|
|
1966
|
+
});
|
|
1967
|
+
this.socket.on("close", (hadError) => {
|
|
1968
|
+
const wasConnected = this._connected;
|
|
1969
|
+
this._connected = false;
|
|
1970
|
+
const error = hadError ? /* @__PURE__ */ new Error("Connection closed with error") : /* @__PURE__ */ new Error("Connection closed");
|
|
1971
|
+
this.flushReceiveQueueWithError(error);
|
|
1972
|
+
if (wasConnected) this.onClose?.(hadError ? error : void 0);
|
|
1973
|
+
});
|
|
1974
|
+
this.socket.on("error", (err) => {
|
|
1975
|
+
clearTimeout(timeout);
|
|
1976
|
+
this._connected = false;
|
|
1977
|
+
this.flushReceiveQueueWithError(err);
|
|
1978
|
+
this.onError?.(err);
|
|
1979
|
+
reject(err);
|
|
1980
|
+
});
|
|
1981
|
+
this.socket.connect(this.port, this.host);
|
|
1982
|
+
});
|
|
1983
|
+
}
|
|
1984
|
+
handleData(data) {
|
|
1985
|
+
if (this.pendingBuffer.length > 0) this.pendingBuffer = Buffer.concat([this.pendingBuffer, data]);
|
|
1986
|
+
else this.pendingBuffer = Buffer.from(data);
|
|
1987
|
+
while (this.pendingBuffer.length >= 8) {
|
|
1988
|
+
const segmentCount = this.pendingBuffer.readUInt32LE(0) + 1;
|
|
1989
|
+
const firstSegmentSize = this.pendingBuffer.readUInt32LE(4);
|
|
1990
|
+
let headerSize = 8;
|
|
1991
|
+
if (segmentCount > 1) headerSize += (segmentCount - 1) * 4;
|
|
1992
|
+
const messageSize = headerSize + firstSegmentSize * 8;
|
|
1993
|
+
if (this.pendingBuffer.length < messageSize) break;
|
|
1994
|
+
const messageData = this.pendingBuffer.subarray(0, messageSize);
|
|
1995
|
+
this.pendingBuffer = this.pendingBuffer.subarray(messageSize);
|
|
1996
|
+
try {
|
|
1997
|
+
const message = deserializeRpcMessage(new Uint8Array(messageData));
|
|
1998
|
+
if (this.receiveQueue.length > 0) {
|
|
1999
|
+
const { resolve } = this.receiveQueue.shift();
|
|
2000
|
+
resolve(message);
|
|
2001
|
+
} else this.messageQueue.push(message);
|
|
2002
|
+
} catch (err) {
|
|
2003
|
+
this.onError?.(err instanceof Error ? err : new Error(String(err)));
|
|
2004
|
+
}
|
|
2005
|
+
}
|
|
2006
|
+
}
|
|
2007
|
+
async send(message) {
|
|
2008
|
+
if (!this.connected) throw new Error(`Cannot send: socket not connected to ${this.host}:${this.port}`);
|
|
2009
|
+
const data = serializeRpcMessage(message);
|
|
2010
|
+
return new Promise((resolve, reject) => {
|
|
2011
|
+
this.socket.write(Buffer.from(data), (err) => {
|
|
2012
|
+
if (err) reject(/* @__PURE__ */ new Error(`Failed to send message: ${err.message}`));
|
|
2013
|
+
else resolve();
|
|
2014
|
+
});
|
|
2015
|
+
});
|
|
2016
|
+
}
|
|
2017
|
+
async receive() {
|
|
2018
|
+
if (this.messageQueue.length > 0) return this.messageQueue.shift();
|
|
2019
|
+
if (!this.connected) return null;
|
|
2020
|
+
return new Promise((resolve, reject) => {
|
|
2021
|
+
const timeoutId = setTimeout(() => {
|
|
2022
|
+
const index = this.receiveQueue.findIndex((item) => item.resolve === resolve);
|
|
2023
|
+
if (index !== -1) this.receiveQueue.splice(index, 1);
|
|
2024
|
+
reject(/* @__PURE__ */ new Error("Receive timeout"));
|
|
2025
|
+
}, 3e4);
|
|
2026
|
+
this.receiveQueue.push({
|
|
2027
|
+
resolve: (msg) => {
|
|
2028
|
+
clearTimeout(timeoutId);
|
|
2029
|
+
resolve(msg);
|
|
2030
|
+
},
|
|
2031
|
+
reject: (err) => {
|
|
2032
|
+
clearTimeout(timeoutId);
|
|
2033
|
+
reject(err);
|
|
2034
|
+
}
|
|
2035
|
+
});
|
|
2036
|
+
});
|
|
2037
|
+
}
|
|
2038
|
+
close(reason) {
|
|
2039
|
+
this._connected = false;
|
|
2040
|
+
this.socket?.end();
|
|
2041
|
+
this.socket?.destroy();
|
|
2042
|
+
this.flushReceiveQueue(null);
|
|
2043
|
+
this.onClose?.(reason);
|
|
2044
|
+
}
|
|
2045
|
+
flushReceiveQueueWithError(error) {
|
|
2046
|
+
while (this.receiveQueue.length > 0) {
|
|
2047
|
+
const { reject } = this.receiveQueue.shift();
|
|
2048
|
+
reject(error);
|
|
2049
|
+
}
|
|
2050
|
+
}
|
|
2051
|
+
flushReceiveQueue(value) {
|
|
2052
|
+
while (this.receiveQueue.length > 0) {
|
|
2053
|
+
const { resolve } = this.receiveQueue.shift();
|
|
2054
|
+
resolve(value);
|
|
2055
|
+
}
|
|
2056
|
+
}
|
|
2057
|
+
};
|
|
2058
|
+
|
|
1701
2059
|
//#endregion
|
|
1702
2060
|
//#region src/rpc/capability-client.ts
|
|
1703
2061
|
/** Base class for capability client implementations */
|
|
@@ -2310,7 +2668,7 @@ var ConnectionManager = class {
|
|
|
2310
2668
|
}
|
|
2311
2669
|
}
|
|
2312
2670
|
async doEstablishConnection(vatId, address) {
|
|
2313
|
-
const { RpcConnection } = await import("./rpc-connection-
|
|
2671
|
+
const { RpcConnection } = await import("./rpc-connection-jIPnPyT6.js");
|
|
2314
2672
|
const connection = new RpcConnection(await this.options.connectionFactory(vatId, address), this.options.connectionOptions);
|
|
2315
2673
|
await connection.start();
|
|
2316
2674
|
this.registerConnection(vatId, connection);
|
|
@@ -5834,5 +6192,5 @@ var SchemaCapabilityClient = class {
|
|
|
5834
6192
|
};
|
|
5835
6193
|
|
|
5836
6194
|
//#endregion
|
|
5837
|
-
export { AnswerTable, BaseCapabilityClient, BulkTransfer, BulkTransferManager, 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, 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, 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 };
|
|
6195
|
+
export { AnswerTable, BaseCapabilityClient, BulkTransfer, BulkTransferManager, 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 };
|
|
5838
6196
|
//# sourceMappingURL=index.js.map
|