@mtkruto/node 0.2.6 → 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.
Files changed (81) 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/2_update_manager.d.ts.map +1 -1
  9. package/esm/client/2_update_manager.js +15 -3
  10. package/esm/client/3_message_manager.d.ts +4 -3
  11. package/esm/client/3_message_manager.d.ts.map +1 -1
  12. package/esm/client/3_message_manager.js +61 -3
  13. package/esm/client/5_client.d.ts +15 -2
  14. package/esm/client/5_client.d.ts.map +1 -1
  15. package/esm/client/5_client.js +21 -6
  16. package/esm/connection/1_connection_tcp.node.d.ts +12 -0
  17. package/esm/connection/1_connection_tcp.node.d.ts.map +1 -0
  18. package/esm/connection/1_connection_tcp.node.js +122 -0
  19. package/esm/connection/1_connection_web_socket.js +1 -1
  20. package/esm/tl/0_api.d.ts +386 -33
  21. package/esm/tl/0_api.d.ts.map +1 -1
  22. package/esm/tl/0_api.js +621 -66
  23. package/esm/transport/3_transport_provider_tcp.js +1 -1
  24. package/esm/types/0_invoice.d.ts +10 -0
  25. package/esm/types/0_invoice.d.ts.map +1 -0
  26. package/esm/types/0_invoice.js +9 -0
  27. package/{script/types/0_poll_option.d.ts → esm/types/1_poll_option.d.ts} +4 -1
  28. package/esm/types/1_poll_option.d.ts.map +1 -0
  29. package/esm/types/{0_poll_option.js → 1_poll_option.js} +3 -1
  30. package/esm/types/{1_poll.d.ts → 2_poll.d.ts} +4 -2
  31. package/esm/types/2_poll.d.ts.map +1 -0
  32. package/esm/types/{1_poll.js → 2_poll.js} +3 -2
  33. package/esm/types/4_message.d.ts +15 -2
  34. package/esm/types/4_message.d.ts.map +1 -1
  35. package/esm/types/4_message.js +7 -1
  36. package/package.json +1 -1
  37. package/script/3_types.d.ts +4 -3
  38. package/script/3_types.d.ts.map +1 -1
  39. package/script/3_types.js +4 -3
  40. package/script/4_constants.d.ts +1 -1
  41. package/script/4_constants.js +1 -1
  42. package/script/client/0_params.d.ts +24 -0
  43. package/script/client/0_params.d.ts.map +1 -1
  44. package/script/client/2_update_manager.d.ts.map +1 -1
  45. package/script/client/2_update_manager.js +14 -2
  46. package/script/client/3_message_manager.d.ts +4 -3
  47. package/script/client/3_message_manager.d.ts.map +1 -1
  48. package/script/client/3_message_manager.js +61 -3
  49. package/script/client/5_client.d.ts +15 -2
  50. package/script/client/5_client.d.ts.map +1 -1
  51. package/script/client/5_client.js +21 -6
  52. package/script/connection/1_connection_tcp.node.d.ts +12 -0
  53. package/script/connection/1_connection_tcp.node.d.ts.map +1 -0
  54. package/script/connection/1_connection_tcp.node.js +126 -0
  55. package/script/connection/1_connection_web_socket.js +1 -1
  56. package/script/tl/0_api.d.ts +386 -33
  57. package/script/tl/0_api.d.ts.map +1 -1
  58. package/script/tl/0_api.js +621 -66
  59. package/script/transport/3_transport_provider_tcp.js +2 -2
  60. package/script/types/0_invoice.d.ts +10 -0
  61. package/script/types/0_invoice.d.ts.map +1 -0
  62. package/script/types/0_invoice.js +13 -0
  63. package/{esm/types/0_poll_option.d.ts → script/types/1_poll_option.d.ts} +4 -1
  64. package/script/types/1_poll_option.d.ts.map +1 -0
  65. package/script/types/{0_poll_option.js → 1_poll_option.js} +3 -1
  66. package/script/types/{1_poll.d.ts → 2_poll.d.ts} +4 -2
  67. package/script/types/2_poll.d.ts.map +1 -0
  68. package/script/types/{1_poll.js → 2_poll.js} +4 -3
  69. package/script/types/4_message.d.ts +15 -2
  70. package/script/types/4_message.d.ts.map +1 -1
  71. package/script/types/4_message.js +8 -2
  72. package/esm/connection/1_connection_tcp.d.ts +0 -34
  73. package/esm/connection/1_connection_tcp.d.ts.map +0 -1
  74. package/esm/connection/1_connection_tcp.js +0 -169
  75. package/esm/types/0_poll_option.d.ts.map +0 -1
  76. package/esm/types/1_poll.d.ts.map +0 -1
  77. package/script/connection/1_connection_tcp.d.ts +0 -34
  78. package/script/connection/1_connection_tcp.d.ts.map +0 -1
  79. package/script/connection/1_connection_tcp.js +0 -196
  80. package/script/types/0_poll_option.d.ts.map +0 -1
  81. package/script/types/1_poll.d.ts.map +0 -1
@@ -747,13 +747,13 @@ export class Client extends Composer {
747
747
  */
748
748
  async connect() {
749
749
  const unlock = await __classPrivateFieldGet(this, _Client_connectMutex, "f").lock();
750
- if (this.connected) {
751
- return;
752
- }
753
- if (__classPrivateFieldGet(this, _Client_lastConnect, "f") != null && Date.now() - __classPrivateFieldGet(this, _Client_lastConnect, "f").getTime() <= 10 * second) {
754
- await new Promise((r) => setTimeout(r, 3 * second));
755
- }
756
750
  try {
751
+ if (this.connected) {
752
+ return;
753
+ }
754
+ if (__classPrivateFieldGet(this, _Client_lastConnect, "f") != null && Date.now() - __classPrivateFieldGet(this, _Client_lastConnect, "f").getTime() <= 10 * second) {
755
+ await new Promise((r) => setTimeout(r, 3 * second));
756
+ }
757
757
  await __classPrivateFieldGet(this, _Client_instances, "m", _Client_initStorage).call(this);
758
758
  const [authKey, dc] = await Promise.all([this.storage.getAuthKey(), this.storage.getDc()]);
759
759
  if (authKey != null && dc != null) {
@@ -1532,6 +1532,21 @@ export class Client extends Composer {
1532
1532
  async sendPoll(chatId, question, options, params) {
1533
1533
  return await __classPrivateFieldGet(this, _Client_messageManager, "f").sendPoll(chatId, question, options, params);
1534
1534
  }
1535
+ /**
1536
+ * Send an invoice.
1537
+ *
1538
+ * @method ms
1539
+ * @param chatId The chat to send the invoice to.
1540
+ * @param title The invoice's title.
1541
+ * @param description The invoice's description.
1542
+ * @param payload The invoice's payload.
1543
+ * @param currency The invoice's currency.
1544
+ * @param prices The invoice's price tags.
1545
+ * @returns The sent invoice.
1546
+ */
1547
+ async sendInvoice(chatId, title, description, payload, currency, prices, params) {
1548
+ return await __classPrivateFieldGet(this, _Client_messageManager, "f").sendInvoice(chatId, title, description, payload, currency, prices, params);
1549
+ }
1535
1550
  /**
1536
1551
  * Edit a message's text.
1537
1552
  *
@@ -0,0 +1,12 @@
1
+ import { Connection } from "./0_connection.js";
2
+ export declare class ConnectionTCP implements Connection {
3
+ #private;
4
+ stateChangeHandler?: Connection["stateChangeHandler"];
5
+ constructor(hostname: string, port: number);
6
+ open(): Promise<void>;
7
+ get connected(): boolean;
8
+ read(p: Uint8Array): Promise<void>;
9
+ write(p: Uint8Array): Promise<void>;
10
+ close(): void;
11
+ }
12
+ //# sourceMappingURL=1_connection_tcp.node.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"1_connection_tcp.node.d.ts","sourceRoot":"","sources":["../../src/connection/1_connection_tcp.node.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAI/C,qBAAa,aAAc,YAAW,UAAU;;IAW9C,kBAAkB,CAAC,EAAE,UAAU,CAAC,oBAAoB,CAAC,CAAC;gBAE1C,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM;IAY1C,IAAI;IAsCJ,IAAI,SAAS,YAEZ;IAQK,IAAI,CAAC,CAAC,EAAE,UAAU;IAclB,KAAK,CAAC,CAAC,EAAE,UAAU;IA0BzB,KAAK;CAKN"}
@@ -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
+ };
@@ -34,7 +34,7 @@ import { concat, unreachable } from "../0_deps.js";
34
34
  import { ConnectionError } from "../0_errors.js";
35
35
  import { getLogger, Mutex } from "../1_utilities.js";
36
36
  const L = getLogger("ConnectionWebSocket");
37
- const errConnectionNotOpen = new Error("Connection not open");
37
+ const errConnectionNotOpen = new ConnectionError("Connection not open");
38
38
  export class ConnectionWebSocket {
39
39
  constructor(url) {
40
40
  _ConnectionWebSocket_instances.add(this);