@mtkruto/node 0.2.7 → 0.2.10
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/esm/3_types.d.ts +4 -3
- package/esm/3_types.d.ts.map +1 -1
- package/esm/3_types.js +4 -3
- package/esm/4_constants.d.ts +1 -1
- package/esm/4_constants.js +1 -1
- package/esm/client/0_params.d.ts +24 -0
- package/esm/client/0_params.d.ts.map +1 -1
- package/esm/client/3_message_manager.d.ts +4 -3
- package/esm/client/3_message_manager.d.ts.map +1 -1
- package/esm/client/3_message_manager.js +61 -3
- package/esm/client/5_client.d.ts +15 -2
- package/esm/client/5_client.d.ts.map +1 -1
- package/esm/client/5_client.js +15 -0
- package/esm/connection/1_connection_tcp.node.d.ts +12 -0
- package/esm/connection/1_connection_tcp.node.d.ts.map +1 -0
- package/esm/connection/1_connection_tcp.node.js +122 -0
- package/esm/tl/0_api.d.ts +386 -33
- package/esm/tl/0_api.d.ts.map +1 -1
- package/esm/tl/0_api.js +621 -66
- package/esm/transport/3_transport_provider_tcp.js +1 -1
- package/esm/types/0_invoice.d.ts +10 -0
- package/esm/types/0_invoice.d.ts.map +1 -0
- package/esm/types/0_invoice.js +9 -0
- package/{script/types/0_poll_option.d.ts → esm/types/1_poll_option.d.ts} +4 -1
- package/esm/types/1_poll_option.d.ts.map +1 -0
- package/esm/types/{0_poll_option.js → 1_poll_option.js} +3 -1
- package/esm/types/{1_poll.d.ts → 2_poll.d.ts} +4 -2
- package/esm/types/2_poll.d.ts.map +1 -0
- package/esm/types/{1_poll.js → 2_poll.js} +3 -2
- package/esm/types/4_message.d.ts +15 -2
- package/esm/types/4_message.d.ts.map +1 -1
- package/esm/types/4_message.js +7 -1
- package/package.json +1 -1
- package/script/3_types.d.ts +4 -3
- package/script/3_types.d.ts.map +1 -1
- package/script/3_types.js +4 -3
- package/script/4_constants.d.ts +1 -1
- package/script/4_constants.js +1 -1
- package/script/client/0_params.d.ts +24 -0
- package/script/client/0_params.d.ts.map +1 -1
- package/script/client/3_message_manager.d.ts +4 -3
- package/script/client/3_message_manager.d.ts.map +1 -1
- package/script/client/3_message_manager.js +61 -3
- package/script/client/5_client.d.ts +15 -2
- package/script/client/5_client.d.ts.map +1 -1
- package/script/client/5_client.js +15 -0
- package/script/connection/1_connection_tcp.node.d.ts +12 -0
- package/script/connection/1_connection_tcp.node.d.ts.map +1 -0
- package/script/connection/1_connection_tcp.node.js +126 -0
- package/script/tl/0_api.d.ts +386 -33
- package/script/tl/0_api.d.ts.map +1 -1
- package/script/tl/0_api.js +621 -66
- package/script/transport/3_transport_provider_tcp.js +2 -2
- package/script/types/0_invoice.d.ts +10 -0
- package/script/types/0_invoice.d.ts.map +1 -0
- package/script/types/0_invoice.js +13 -0
- package/{esm/types/0_poll_option.d.ts → script/types/1_poll_option.d.ts} +4 -1
- package/script/types/1_poll_option.d.ts.map +1 -0
- package/script/types/{0_poll_option.js → 1_poll_option.js} +3 -1
- package/script/types/{1_poll.d.ts → 2_poll.d.ts} +4 -2
- package/script/types/2_poll.d.ts.map +1 -0
- package/script/types/{1_poll.js → 2_poll.js} +4 -3
- package/script/types/4_message.d.ts +15 -2
- package/script/types/4_message.d.ts.map +1 -1
- package/script/types/4_message.js +8 -2
- package/esm/connection/1_connection_tcp.d.ts +0 -34
- package/esm/connection/1_connection_tcp.d.ts.map +0 -1
- package/esm/connection/1_connection_tcp.js +0 -173
- package/esm/types/0_poll_option.d.ts.map +0 -1
- package/esm/types/1_poll.d.ts.map +0 -1
- package/script/connection/1_connection_tcp.d.ts +0 -34
- package/script/connection/1_connection_tcp.d.ts.map +0 -1
- package/script/connection/1_connection_tcp.js +0 -200
- package/script/types/0_poll_option.d.ts.map +0 -1
- package/script/types/1_poll.d.ts.map +0 -1
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
2
|
+
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
3
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
4
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
5
|
+
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
6
|
+
};
|
|
7
|
+
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
8
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
9
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
10
|
+
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
11
|
+
};
|
|
12
|
+
var _ConnectionTCP_instances, _ConnectionTCP_hostname, _ConnectionTCP_port, _ConnectionTCP_socket, _ConnectionTCP_rMutex, _ConnectionTCP_wMutex, _ConnectionTCP_buffer, _ConnectionTCP_nextResolve, _ConnectionTCP_rejectRead, _ConnectionTCP_assertConnected;
|
|
13
|
+
import { Socket } from "node:net";
|
|
14
|
+
import { Mutex } from "../1_utilities.js";
|
|
15
|
+
import { ConnectionError } from "../0_errors.js";
|
|
16
|
+
const errConnectionNotOpen = new ConnectionError("Connection not open");
|
|
17
|
+
export class ConnectionTCP {
|
|
18
|
+
constructor(hostname, port) {
|
|
19
|
+
_ConnectionTCP_instances.add(this);
|
|
20
|
+
_ConnectionTCP_hostname.set(this, void 0);
|
|
21
|
+
_ConnectionTCP_port.set(this, void 0);
|
|
22
|
+
_ConnectionTCP_socket.set(this, void 0);
|
|
23
|
+
_ConnectionTCP_rMutex.set(this, new Mutex());
|
|
24
|
+
_ConnectionTCP_wMutex.set(this, new Mutex());
|
|
25
|
+
_ConnectionTCP_buffer.set(this, new Array());
|
|
26
|
+
_ConnectionTCP_nextResolve.set(this, null);
|
|
27
|
+
Object.defineProperty(this, "stateChangeHandler", {
|
|
28
|
+
enumerable: true,
|
|
29
|
+
configurable: true,
|
|
30
|
+
writable: true,
|
|
31
|
+
value: void 0
|
|
32
|
+
});
|
|
33
|
+
__classPrivateFieldSet(this, _ConnectionTCP_hostname, hostname, "f");
|
|
34
|
+
__classPrivateFieldSet(this, _ConnectionTCP_port, port, "f");
|
|
35
|
+
}
|
|
36
|
+
open() {
|
|
37
|
+
__classPrivateFieldSet(this, _ConnectionTCP_socket, new Socket(), "f");
|
|
38
|
+
__classPrivateFieldGet(this, _ConnectionTCP_socket, "f").on("close", () => {
|
|
39
|
+
__classPrivateFieldGet(this, _ConnectionTCP_instances, "m", _ConnectionTCP_rejectRead).call(this);
|
|
40
|
+
this.stateChangeHandler?.(false);
|
|
41
|
+
});
|
|
42
|
+
const mutex = new Mutex();
|
|
43
|
+
__classPrivateFieldGet(this, _ConnectionTCP_socket, "f").on("data", async (data) => {
|
|
44
|
+
const unlock = await mutex.lock();
|
|
45
|
+
for (const byte of data) {
|
|
46
|
+
__classPrivateFieldGet(this, _ConnectionTCP_buffer, "f").push(byte);
|
|
47
|
+
}
|
|
48
|
+
if (__classPrivateFieldGet(this, _ConnectionTCP_nextResolve, "f") != null && __classPrivateFieldGet(this, _ConnectionTCP_buffer, "f").length >= __classPrivateFieldGet(this, _ConnectionTCP_nextResolve, "f")[0]) {
|
|
49
|
+
const resolve = __classPrivateFieldGet(this, _ConnectionTCP_nextResolve, "f")[1].resolve;
|
|
50
|
+
__classPrivateFieldSet(this, _ConnectionTCP_nextResolve, null, "f");
|
|
51
|
+
resolve();
|
|
52
|
+
}
|
|
53
|
+
unlock();
|
|
54
|
+
});
|
|
55
|
+
return new Promise((resolve, reject) => {
|
|
56
|
+
__classPrivateFieldGet(this, _ConnectionTCP_socket, "f").connect(__classPrivateFieldGet(this, _ConnectionTCP_port, "f"), __classPrivateFieldGet(this, _ConnectionTCP_hostname, "f"));
|
|
57
|
+
__classPrivateFieldGet(this, _ConnectionTCP_socket, "f").once("error", reject);
|
|
58
|
+
__classPrivateFieldGet(this, _ConnectionTCP_socket, "f").once("connect", () => {
|
|
59
|
+
__classPrivateFieldGet(this, _ConnectionTCP_socket, "f").off("error", reject);
|
|
60
|
+
resolve();
|
|
61
|
+
this.stateChangeHandler?.(true);
|
|
62
|
+
});
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
get connected() {
|
|
66
|
+
return __classPrivateFieldGet(this, _ConnectionTCP_socket, "f")?.readyState == "open";
|
|
67
|
+
}
|
|
68
|
+
async read(p) {
|
|
69
|
+
__classPrivateFieldGet(this, _ConnectionTCP_instances, "m", _ConnectionTCP_assertConnected).call(this);
|
|
70
|
+
const unlock = await __classPrivateFieldGet(this, _ConnectionTCP_rMutex, "f").lock();
|
|
71
|
+
try {
|
|
72
|
+
__classPrivateFieldGet(this, _ConnectionTCP_instances, "m", _ConnectionTCP_assertConnected).call(this);
|
|
73
|
+
if (__classPrivateFieldGet(this, _ConnectionTCP_buffer, "f").length < p.length) {
|
|
74
|
+
await new Promise((resolve, reject) => __classPrivateFieldSet(this, _ConnectionTCP_nextResolve, [p.length, { resolve, reject }], "f"));
|
|
75
|
+
}
|
|
76
|
+
p.set(__classPrivateFieldGet(this, _ConnectionTCP_buffer, "f").splice(0, p.length));
|
|
77
|
+
}
|
|
78
|
+
finally {
|
|
79
|
+
unlock();
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
async write(p) {
|
|
83
|
+
__classPrivateFieldGet(this, _ConnectionTCP_instances, "m", _ConnectionTCP_assertConnected).call(this);
|
|
84
|
+
const unlock = await __classPrivateFieldGet(this, _ConnectionTCP_wMutex, "f").lock();
|
|
85
|
+
try {
|
|
86
|
+
__classPrivateFieldGet(this, _ConnectionTCP_instances, "m", _ConnectionTCP_assertConnected).call(this);
|
|
87
|
+
try {
|
|
88
|
+
await new Promise((resolve, reject) => {
|
|
89
|
+
__classPrivateFieldGet(this, _ConnectionTCP_socket, "f").write(p, (err) => {
|
|
90
|
+
(err === undefined || err == null) ? resolve() : reject(err);
|
|
91
|
+
});
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
catch (err) {
|
|
95
|
+
if (!this.connected) {
|
|
96
|
+
throw errConnectionNotOpen;
|
|
97
|
+
}
|
|
98
|
+
else {
|
|
99
|
+
throw err;
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
finally {
|
|
104
|
+
unlock();
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
close() {
|
|
108
|
+
__classPrivateFieldGet(this, _ConnectionTCP_instances, "m", _ConnectionTCP_assertConnected).call(this);
|
|
109
|
+
__classPrivateFieldGet(this, _ConnectionTCP_socket, "f").destroy();
|
|
110
|
+
__classPrivateFieldSet(this, _ConnectionTCP_socket, undefined, "f");
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
_ConnectionTCP_hostname = new WeakMap(), _ConnectionTCP_port = new WeakMap(), _ConnectionTCP_socket = new WeakMap(), _ConnectionTCP_rMutex = new WeakMap(), _ConnectionTCP_wMutex = new WeakMap(), _ConnectionTCP_buffer = new WeakMap(), _ConnectionTCP_nextResolve = new WeakMap(), _ConnectionTCP_instances = new WeakSet(), _ConnectionTCP_rejectRead = function _ConnectionTCP_rejectRead() {
|
|
114
|
+
if (__classPrivateFieldGet(this, _ConnectionTCP_nextResolve, "f") != null) {
|
|
115
|
+
__classPrivateFieldGet(this, _ConnectionTCP_nextResolve, "f")[1].reject(errConnectionNotOpen);
|
|
116
|
+
__classPrivateFieldSet(this, _ConnectionTCP_nextResolve, null, "f");
|
|
117
|
+
}
|
|
118
|
+
}, _ConnectionTCP_assertConnected = function _ConnectionTCP_assertConnected() {
|
|
119
|
+
if (!this.connected) {
|
|
120
|
+
throw errConnectionNotOpen;
|
|
121
|
+
}
|
|
122
|
+
};
|