@mtkruto/node 0.2.7 → 0.2.11

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.
Files changed (75) hide show
  1. package/esm/3_types.d.ts +4 -3
  2. package/esm/3_types.d.ts.map +1 -1
  3. package/esm/3_types.js +4 -3
  4. package/esm/4_constants.d.ts +1 -1
  5. package/esm/4_constants.js +1 -1
  6. package/esm/client/0_params.d.ts +24 -0
  7. package/esm/client/0_params.d.ts.map +1 -1
  8. package/esm/client/3_message_manager.d.ts +4 -3
  9. package/esm/client/3_message_manager.d.ts.map +1 -1
  10. package/esm/client/3_message_manager.js +61 -3
  11. package/esm/client/5_client.d.ts +15 -2
  12. package/esm/client/5_client.d.ts.map +1 -1
  13. package/esm/client/5_client.js +20 -11
  14. package/esm/connection/1_connection_tcp.node.d.ts +12 -0
  15. package/esm/connection/1_connection_tcp.node.d.ts.map +1 -0
  16. package/esm/connection/1_connection_tcp.node.js +122 -0
  17. package/esm/tl/0_api.d.ts +386 -33
  18. package/esm/tl/0_api.d.ts.map +1 -1
  19. package/esm/tl/0_api.js +621 -66
  20. package/esm/transport/3_transport_provider_tcp.js +1 -1
  21. package/esm/types/0_invoice.d.ts +10 -0
  22. package/esm/types/0_invoice.d.ts.map +1 -0
  23. package/esm/types/0_invoice.js +9 -0
  24. package/{script/types/0_poll_option.d.ts → esm/types/1_poll_option.d.ts} +4 -1
  25. package/esm/types/1_poll_option.d.ts.map +1 -0
  26. package/esm/types/{0_poll_option.js → 1_poll_option.js} +3 -1
  27. package/esm/types/{1_poll.d.ts → 2_poll.d.ts} +4 -2
  28. package/esm/types/2_poll.d.ts.map +1 -0
  29. package/esm/types/{1_poll.js → 2_poll.js} +3 -2
  30. package/esm/types/4_message.d.ts +15 -2
  31. package/esm/types/4_message.d.ts.map +1 -1
  32. package/esm/types/4_message.js +7 -1
  33. package/package.json +1 -1
  34. package/script/3_types.d.ts +4 -3
  35. package/script/3_types.d.ts.map +1 -1
  36. package/script/3_types.js +4 -3
  37. package/script/4_constants.d.ts +1 -1
  38. package/script/4_constants.js +1 -1
  39. package/script/client/0_params.d.ts +24 -0
  40. package/script/client/0_params.d.ts.map +1 -1
  41. package/script/client/3_message_manager.d.ts +4 -3
  42. package/script/client/3_message_manager.d.ts.map +1 -1
  43. package/script/client/3_message_manager.js +61 -3
  44. package/script/client/5_client.d.ts +15 -2
  45. package/script/client/5_client.d.ts.map +1 -1
  46. package/script/client/5_client.js +20 -11
  47. package/script/connection/1_connection_tcp.node.d.ts +12 -0
  48. package/script/connection/1_connection_tcp.node.d.ts.map +1 -0
  49. package/script/connection/1_connection_tcp.node.js +126 -0
  50. package/script/tl/0_api.d.ts +386 -33
  51. package/script/tl/0_api.d.ts.map +1 -1
  52. package/script/tl/0_api.js +621 -66
  53. package/script/transport/3_transport_provider_tcp.js +2 -2
  54. package/script/types/0_invoice.d.ts +10 -0
  55. package/script/types/0_invoice.d.ts.map +1 -0
  56. package/script/types/0_invoice.js +13 -0
  57. package/{esm/types/0_poll_option.d.ts → script/types/1_poll_option.d.ts} +4 -1
  58. package/script/types/1_poll_option.d.ts.map +1 -0
  59. package/script/types/{0_poll_option.js → 1_poll_option.js} +3 -1
  60. package/script/types/{1_poll.d.ts → 2_poll.d.ts} +4 -2
  61. package/script/types/2_poll.d.ts.map +1 -0
  62. package/script/types/{1_poll.js → 2_poll.js} +4 -3
  63. package/script/types/4_message.d.ts +15 -2
  64. package/script/types/4_message.d.ts.map +1 -1
  65. package/script/types/4_message.js +8 -2
  66. package/esm/connection/1_connection_tcp.d.ts +0 -34
  67. package/esm/connection/1_connection_tcp.d.ts.map +0 -1
  68. package/esm/connection/1_connection_tcp.js +0 -173
  69. package/esm/types/0_poll_option.d.ts.map +0 -1
  70. package/esm/types/1_poll.d.ts.map +0 -1
  71. package/script/connection/1_connection_tcp.d.ts +0 -34
  72. package/script/connection/1_connection_tcp.d.ts.map +0 -1
  73. package/script/connection/1_connection_tcp.js +0 -200
  74. package/script/types/0_poll_option.d.ts.map +0 -1
  75. package/script/types/1_poll.d.ts.map +0 -1
@@ -1,200 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
25
- var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
26
- if (kind === "m") throw new TypeError("Private method is not writable");
27
- if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
28
- 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");
29
- return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
30
- };
31
- var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
32
- if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
33
- 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");
34
- return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
35
- };
36
- var _ConnectionTCP_instances, _ConnectionTCP_hostname, _ConnectionTCP_port, _ConnectionTCP_connection, _ConnectionTCP_rMutex, _ConnectionTCP_wMutex, _ConnectionTCP_buffer, _ConnectionTCP_nextResolve, _ConnectionTCP_canRead, _ConnectionTCP_canWrite, _ConnectionTCP_assertConnected, _ConnectionTCP_rejectRead;
37
- Object.defineProperty(exports, "__esModule", { value: true });
38
- exports.ConnectionTCP = void 0;
39
- /**
40
- * MTKruto - Cross-runtime JavaScript library for building Telegram clients
41
- * Copyright (C) 2023-2024 Roj <https://roj.im/>
42
- *
43
- * This file is part of MTKruto.
44
- *
45
- * This program is free software: you can redistribute it and/or modify
46
- * it under the terms of the GNU Lesser General Public License as published by
47
- * the Free Software Foundation, either version 3 of the License, or
48
- * (at your option) any later version.
49
- *
50
- * This program is distributed in the hope that it will be useful,
51
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
52
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
53
- * GNU Lesser General Public License for more details.
54
- *
55
- * You should have received a copy of the GNU Lesser General Public License
56
- * along with this program. If not, see <https://www.gnu.org/licenses/>.
57
- */
58
- const dntShim = __importStar(require("../_dnt.shims.js"));
59
- const _0_deps_js_1 = require("../0_deps.js");
60
- const _0_errors_js_1 = require("../0_errors.js");
61
- const _1_utilities_js_1 = require("../1_utilities.js");
62
- const L = (0, _1_utilities_js_1.getLogger)("ConnectionTCP");
63
- class ConnectionTCP {
64
- constructor(hostname, port) {
65
- _ConnectionTCP_instances.add(this);
66
- _ConnectionTCP_hostname.set(this, void 0);
67
- _ConnectionTCP_port.set(this, void 0);
68
- _ConnectionTCP_connection.set(this, void 0);
69
- _ConnectionTCP_rMutex.set(this, new _1_utilities_js_1.Mutex());
70
- _ConnectionTCP_wMutex.set(this, new _1_utilities_js_1.Mutex());
71
- _ConnectionTCP_buffer.set(this, new Uint8Array());
72
- _ConnectionTCP_nextResolve.set(this, null);
73
- _ConnectionTCP_canRead.set(this, false);
74
- _ConnectionTCP_canWrite.set(this, false);
75
- Object.defineProperty(this, "connect", {
76
- enumerable: true,
77
- configurable: true,
78
- writable: true,
79
- value: dntShim.Deno.connect
80
- });
81
- Object.defineProperty(this, "stateChangeHandler", {
82
- enumerable: true,
83
- configurable: true,
84
- writable: true,
85
- value: void 0
86
- });
87
- Object.defineProperty(this, "callback", {
88
- enumerable: true,
89
- configurable: true,
90
- writable: true,
91
- value: void 0
92
- });
93
- __classPrivateFieldSet(this, _ConnectionTCP_hostname, hostname, "f");
94
- __classPrivateFieldSet(this, _ConnectionTCP_port, port, "f");
95
- }
96
- get connected() {
97
- return !!__classPrivateFieldGet(this, _ConnectionTCP_connection, "f") && __classPrivateFieldGet(this, _ConnectionTCP_canRead, "f") && __classPrivateFieldGet(this, _ConnectionTCP_canWrite, "f");
98
- }
99
- async open() {
100
- if (this.connected) {
101
- throw new Error("Connection already open");
102
- }
103
- const connection = await this.connect({
104
- hostname: __classPrivateFieldGet(this, _ConnectionTCP_hostname, "f"),
105
- port: __classPrivateFieldGet(this, _ConnectionTCP_port, "f"),
106
- });
107
- connection.setNoDelay(true);
108
- connection.setKeepAlive(true);
109
- __classPrivateFieldSet(this, _ConnectionTCP_canRead, __classPrivateFieldSet(this, _ConnectionTCP_canWrite, true, "f"), "f");
110
- this.stateChangeHandler?.(true);
111
- Promise.resolve().then(async () => {
112
- do {
113
- try {
114
- for await (const chunk of (0, _0_deps_js_1.iterateReader)(connection)) {
115
- this.callback?.read(chunk.length);
116
- __classPrivateFieldSet(this, _ConnectionTCP_buffer, (0, _0_deps_js_1.concat)([__classPrivateFieldGet(this, _ConnectionTCP_buffer, "f"), chunk]), "f");
117
- if (__classPrivateFieldGet(this, _ConnectionTCP_nextResolve, "f") != null && __classPrivateFieldGet(this, _ConnectionTCP_buffer, "f").length >= __classPrivateFieldGet(this, _ConnectionTCP_nextResolve, "f")[0]) {
118
- __classPrivateFieldGet(this, _ConnectionTCP_nextResolve, "f")[1].resolve();
119
- __classPrivateFieldSet(this, _ConnectionTCP_nextResolve, null, "f");
120
- }
121
- }
122
- __classPrivateFieldSet(this, _ConnectionTCP_canRead, false, "f");
123
- break;
124
- }
125
- catch (err) {
126
- __classPrivateFieldSet(this, _ConnectionTCP_canRead, false, "f");
127
- this.stateChangeHandler?.(false);
128
- __classPrivateFieldGet(this, _ConnectionTCP_instances, "m", _ConnectionTCP_rejectRead).call(this);
129
- L.error(err);
130
- }
131
- } while (this.connected);
132
- this.stateChangeHandler?.(false);
133
- });
134
- __classPrivateFieldSet(this, _ConnectionTCP_connection, connection, "f");
135
- }
136
- async read(p) {
137
- __classPrivateFieldGet(this, _ConnectionTCP_instances, "m", _ConnectionTCP_assertConnected).call(this);
138
- const unlock = await __classPrivateFieldGet(this, _ConnectionTCP_rMutex, "f").lock();
139
- try {
140
- __classPrivateFieldGet(this, _ConnectionTCP_instances, "m", _ConnectionTCP_assertConnected).call(this);
141
- if (__classPrivateFieldGet(this, _ConnectionTCP_buffer, "f").length < p.length) {
142
- await new Promise((resolve, reject) => __classPrivateFieldSet(this, _ConnectionTCP_nextResolve, [p.length, { resolve, reject }], "f"));
143
- }
144
- const slice = __classPrivateFieldGet(this, _ConnectionTCP_buffer, "f").slice(0, p.length);
145
- p.set(slice);
146
- __classPrivateFieldSet(this, _ConnectionTCP_buffer, __classPrivateFieldGet(this, _ConnectionTCP_buffer, "f").slice(slice.length), "f");
147
- }
148
- finally {
149
- unlock();
150
- }
151
- }
152
- async write(p) {
153
- __classPrivateFieldGet(this, _ConnectionTCP_instances, "m", _ConnectionTCP_assertConnected).call(this);
154
- const unlock = await __classPrivateFieldGet(this, _ConnectionTCP_wMutex, "f").lock();
155
- try {
156
- __classPrivateFieldGet(this, _ConnectionTCP_instances, "m", _ConnectionTCP_assertConnected).call(this);
157
- let written = 0;
158
- while (written < p.length) {
159
- try {
160
- const wrote = await __classPrivateFieldGet(this, _ConnectionTCP_connection, "f").write(p.subarray(written));
161
- this.callback?.write(wrote);
162
- written += wrote;
163
- }
164
- catch (err) {
165
- if (err instanceof dntShim.Deno.errors.BrokenPipe || err instanceof dntShim.Deno.errors.ConnectionReset || (err instanceof Error && "code" in err && err.code == "EAGAIN" || err.code == "ECONNRESET")) {
166
- __classPrivateFieldSet(this, _ConnectionTCP_canWrite, false, "f");
167
- }
168
- if (!this.connected) {
169
- this.stateChangeHandler?.(false);
170
- throw new _0_errors_js_1.ConnectionError("Connection was closed");
171
- }
172
- else {
173
- throw err;
174
- }
175
- }
176
- }
177
- }
178
- finally {
179
- unlock();
180
- }
181
- }
182
- close() {
183
- __classPrivateFieldGet(this, _ConnectionTCP_instances, "m", _ConnectionTCP_assertConnected).call(this);
184
- __classPrivateFieldGet(this, _ConnectionTCP_connection, "f").close();
185
- __classPrivateFieldSet(this, _ConnectionTCP_canRead, __classPrivateFieldSet(this, _ConnectionTCP_canWrite, false, "f"), "f");
186
- __classPrivateFieldSet(this, _ConnectionTCP_connection, undefined, "f");
187
- __classPrivateFieldGet(this, _ConnectionTCP_instances, "m", _ConnectionTCP_rejectRead).call(this);
188
- }
189
- }
190
- exports.ConnectionTCP = ConnectionTCP;
191
- _ConnectionTCP_hostname = new WeakMap(), _ConnectionTCP_port = new WeakMap(), _ConnectionTCP_connection = new WeakMap(), _ConnectionTCP_rMutex = new WeakMap(), _ConnectionTCP_wMutex = new WeakMap(), _ConnectionTCP_buffer = new WeakMap(), _ConnectionTCP_nextResolve = new WeakMap(), _ConnectionTCP_canRead = new WeakMap(), _ConnectionTCP_canWrite = new WeakMap(), _ConnectionTCP_instances = new WeakSet(), _ConnectionTCP_assertConnected = function _ConnectionTCP_assertConnected() {
192
- if (!this.connected) {
193
- throw new _0_errors_js_1.ConnectionError("Connection not open");
194
- }
195
- }, _ConnectionTCP_rejectRead = function _ConnectionTCP_rejectRead() {
196
- if (__classPrivateFieldGet(this, _ConnectionTCP_nextResolve, "f") != null) {
197
- __classPrivateFieldGet(this, _ConnectionTCP_nextResolve, "f")[1].reject(new _0_errors_js_1.ConnectionError("Connection was closed"));
198
- __classPrivateFieldSet(this, _ConnectionTCP_nextResolve, null, "f");
199
- }
200
- };
@@ -1 +0,0 @@
1
- {"version":3,"file":"0_poll_option.d.ts","sourceRoot":"","sources":["../../src/types/0_poll_option.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAEH,OAAO,EAAE,GAAG,EAAE,MAAM,YAAY,CAAC;AAEjC,qBAAqB;AACrB,MAAM,WAAW,UAAU;IACzB,4CAA4C;IAC5C,IAAI,EAAE,MAAM,CAAC;IACb,8CAA8C;IAC9C,UAAU,EAAE,MAAM,CAAC;CACpB;AAED,wBAAgB,mBAAmB,CAAC,MAAM,EAAE,GAAG,CAAC,UAAU,EAAE,OAAO,EAAE,KAAK,CAAC,GAAG,CAAC,gBAAgB,CAAC,GAAG,UAAU,CAK5G"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"1_poll.d.ts","sourceRoot":"","sources":["../../src/types/1_poll.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAGH,OAAO,EAAE,GAAG,EAAE,MAAM,YAAY,CAAC;AACjC,OAAO,EAA0B,aAAa,EAAE,MAAM,uBAAuB,CAAC;AAC9E,OAAO,EAAuB,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAErE,cAAc;AACd,MAAM,WAAW,IAAI;IACnB,kCAAkC;IAClC,EAAE,EAAE,MAAM,CAAC;IACX,2BAA2B;IAC3B,QAAQ,EAAE,MAAM,CAAC;IACjB,0BAA0B;IAC1B,OAAO,EAAE,UAAU,EAAE,CAAC;IACtB,6DAA6D;IAC7D,eAAe,EAAE,MAAM,CAAC;IACxB,kCAAkC;IAClC,QAAQ,EAAE,OAAO,CAAC;IAClB,qCAAqC;IACrC,WAAW,EAAE,OAAO,CAAC;IACrB,4BAA4B;IAC5B,IAAI,EAAE,SAAS,GAAG,MAAM,CAAC;IACzB,gDAAgD;IAChD,oBAAoB,CAAC,EAAE,OAAO,CAAC;IAC/B,mCAAmC;IACnC,kBAAkB,CAAC,EAAE,MAAM,CAAC;IAC5B,kEAAkE;IAClE,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,kCAAkC;IAClC,mBAAmB,CAAC,EAAE,aAAa,EAAE,CAAC;IACtC,uCAAuC;IACvC,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,iDAAiD;IACjD,SAAS,CAAC,EAAE,IAAI,CAAC;CAClB;AAED,wBAAgB,aAAa,CAAC,MAAM,EAAE,GAAG,CAAC,gBAAgB,GAAG,IAAI,CAoBhE"}