@mtkruto/node 0.67.2 → 0.68.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.
Files changed (244) hide show
  1. package/esm/0_errors.js +2 -6
  2. package/esm/3_errors.js +2 -12
  3. package/esm/3_types.d.ts +1 -0
  4. package/esm/3_types.d.ts.map +1 -1
  5. package/esm/3_types.js +1 -0
  6. package/esm/4_errors.js +2 -12
  7. package/esm/_dnt.polyfills.d.ts +99 -0
  8. package/esm/_dnt.polyfills.d.ts.map +1 -1
  9. package/esm/_dnt.polyfills.js +127 -1
  10. package/esm/_dnt.test_polyfills.d.ts.map +1 -0
  11. package/esm/client/0_filters_test.d.ts.map +1 -1
  12. package/esm/client/0_markdown_test.d.ts.map +1 -1
  13. package/esm/client/0_params.d.ts +2 -0
  14. package/esm/client/0_params.d.ts.map +1 -1
  15. package/esm/client/0_password.d.ts +5 -5
  16. package/esm/client/0_password.d.ts.map +1 -1
  17. package/esm/client/0_password_test.d.ts.map +1 -1
  18. package/esm/client/0_storage_operations.js +143 -155
  19. package/esm/client/0_storage_operations_test.d.ts.map +1 -1
  20. package/esm/client/0_utilities.d.ts +1 -1
  21. package/esm/client/0_utilities_test.d.ts.map +1 -1
  22. package/esm/client/1_client_plain.js +4 -22
  23. package/esm/client/1_composer.js +8 -21
  24. package/esm/client/2_account_manager.js +85 -97
  25. package/esm/client/2_bot_info_manager.js +26 -38
  26. package/esm/client/2_business_connection_manager.js +10 -23
  27. package/esm/client/2_client_encrypted.js +194 -211
  28. package/esm/client/2_file_manager.d.ts +4 -3
  29. package/esm/client/2_file_manager.d.ts.map +1 -1
  30. package/esm/client/2_file_manager.js +268 -224
  31. package/esm/client/2_file_manager_test.d.ts.map +1 -1
  32. package/esm/client/2_network_statistics_manager.js +8 -21
  33. package/esm/client/2_payment_manager.js +7 -20
  34. package/esm/client/2_reaction_manager.js +7 -20
  35. package/esm/client/2_translations_manager.js +97 -107
  36. package/esm/client/2_update_manager.js +764 -759
  37. package/esm/client/3_client_encrypted_pool.js +10 -26
  38. package/esm/client/3_client_encrypted_pool_test.d.ts.map +1 -1
  39. package/esm/client/3_message_manager.d.ts +1 -1
  40. package/esm/client/3_message_manager.js +441 -448
  41. package/esm/client/3_message_manager_test.d.ts.map +1 -1
  42. package/esm/client/3_video_chat_manager.d.ts +1 -1
  43. package/esm/client/3_video_chat_manager.js +57 -68
  44. package/esm/client/4_callback_query_manager.js +18 -30
  45. package/esm/client/4_chat_list_manager.js +322 -318
  46. package/esm/client/4_chat_manager.js +118 -131
  47. package/esm/client/4_forum_manager.js +67 -73
  48. package/esm/client/4_gift_manager.js +16 -29
  49. package/esm/client/4_inline_query_manager.js +16 -28
  50. package/esm/client/4_link_preview_manager.js +6 -19
  51. package/esm/client/4_poll_manager.js +44 -57
  52. package/esm/client/4_story_manager.js +41 -53
  53. package/esm/client/5_client.d.ts +7 -0
  54. package/esm/client/5_client.d.ts.map +1 -1
  55. package/esm/client/5_client.js +1269 -1288
  56. package/esm/connection/1_connection_tcp.node.js +48 -65
  57. package/esm/connection/1_connection_web_socket.js +75 -91
  58. package/esm/deps/jsr.io/@roj/tgcrypto/1.0.1/dist/tgcrypto.js +3 -11
  59. package/esm/deps/jsr.io/@std/async/1.0.13/mux_async_iterator.js +31 -47
  60. package/esm/deps/jsr.io/@std/async/1.0.13/tee.js +11 -34
  61. package/esm/deps/jsr.io/@std/datetime/0.225.5/_date_time_formatter.js +4 -17
  62. package/esm/mod.js +2 -12
  63. package/esm/session/0_session_state.js +12 -38
  64. package/esm/session/1_session.js +49 -72
  65. package/esm/session/2_session_encrypted.js +324 -320
  66. package/esm/storage/1_utilities_test.d.ts.map +1 -1
  67. package/esm/storage/2_storage_indexed_db.js +26 -44
  68. package/esm/storage/2_storage_local_storage.node.js +12 -25
  69. package/esm/storage/2_storage_memory.js +24 -41
  70. package/esm/storage/2_storage_session_storage.js +3 -16
  71. package/esm/tl/0_utilities_test.d.ts.map +1 -1
  72. package/esm/tl/1_tl_reader.js +80 -88
  73. package/esm/tl/1_tl_reader_test.d.ts.map +1 -1
  74. package/esm/tl/1_tl_writer.js +155 -164
  75. package/esm/tl/1_tl_writer_test.d.ts.map +1 -1
  76. package/esm/transport/0_transport.js +1 -8
  77. package/esm/transport/1_transport_abridged.js +11 -24
  78. package/esm/transport/1_transport_intermediate.js +10 -23
  79. package/esm/transport/2_transport_provider_web_socket.d.ts.map +1 -1
  80. package/esm/types/0_upload_progress.d.ts +29 -0
  81. package/esm/types/0_upload_progress.d.ts.map +1 -0
  82. package/esm/types/0_upload_progress.js +20 -0
  83. package/esm/types/1_sticker.d.ts +1 -1
  84. package/esm/types/1_sticker.d.ts.map +1 -1
  85. package/esm/types/2_poll_answer.d.ts +19 -0
  86. package/esm/types/2_poll_answer.d.ts.map +1 -1
  87. package/esm/types/2_poll_answer.js +19 -0
  88. package/esm/types/7_update.d.ts +21 -2
  89. package/esm/types/7_update.d.ts.map +1 -1
  90. package/esm/utilities/0_bigint_test.d.ts.map +1 -1
  91. package/esm/utilities/0_buffer.d.ts +1 -1
  92. package/esm/utilities/0_buffer.d.ts.map +1 -1
  93. package/esm/utilities/0_buffer_test.d.ts.map +1 -1
  94. package/esm/utilities/0_hash.d.ts +2 -2
  95. package/esm/utilities/0_hash.d.ts.map +1 -1
  96. package/esm/utilities/0_mutex.js +4 -19
  97. package/esm/utilities/0_part_stream.js +11 -25
  98. package/esm/utilities/0_part_stream_test.d.ts.map +1 -1
  99. package/esm/utilities/0_rle.d.ts +2 -2
  100. package/esm/utilities/0_rle.d.ts.map +1 -1
  101. package/esm/utilities/0_rle_test.d.ts.map +1 -1
  102. package/esm/utilities/0_text.d.ts +20 -1
  103. package/esm/utilities/0_text.d.ts.map +1 -1
  104. package/esm/utilities/0_text.js +19 -0
  105. package/esm/utilities/1_auth.d.ts +1 -1
  106. package/esm/utilities/1_auth.d.ts.map +1 -1
  107. package/esm/utilities/1_base64.d.ts +1 -1
  108. package/esm/utilities/1_base64.d.ts.map +1 -1
  109. package/esm/utilities/1_base64_test.d.ts.map +1 -1
  110. package/esm/utilities/1_crypto.js +42 -53
  111. package/esm/utilities/1_crypto_test.d.ts.map +1 -1
  112. package/esm/utilities/1_logger.d.ts +2 -2
  113. package/esm/utilities/1_math_test.d.ts.map +1 -1
  114. package/esm/utilities/2_queue.js +29 -47
  115. package/package.json +1 -1
  116. package/script/0_errors.js +2 -6
  117. package/script/2_tl.js +17 -7
  118. package/script/3_errors.js +2 -12
  119. package/script/3_types.d.ts +1 -0
  120. package/script/3_types.d.ts.map +1 -1
  121. package/script/3_types.js +1 -0
  122. package/script/4_constants.js +17 -7
  123. package/script/4_errors.js +2 -12
  124. package/script/_dnt.polyfills.d.ts +99 -0
  125. package/script/_dnt.polyfills.d.ts.map +1 -1
  126. package/script/_dnt.polyfills.js +128 -0
  127. package/script/_dnt.test_polyfills.d.ts.map +1 -0
  128. package/script/client/0_filters_test.d.ts.map +1 -1
  129. package/script/client/0_markdown_test.d.ts.map +1 -1
  130. package/script/client/0_params.d.ts +2 -0
  131. package/script/client/0_params.d.ts.map +1 -1
  132. package/script/client/0_password.d.ts +5 -5
  133. package/script/client/0_password.d.ts.map +1 -1
  134. package/script/client/0_password.js +17 -7
  135. package/script/client/0_password_test.d.ts.map +1 -1
  136. package/script/client/0_storage_operations.js +143 -155
  137. package/script/client/0_storage_operations_test.d.ts.map +1 -1
  138. package/script/client/0_utilities.d.ts +1 -1
  139. package/script/client/0_utilities_test.d.ts.map +1 -1
  140. package/script/client/1_client_plain.js +4 -22
  141. package/script/client/1_composer.js +8 -21
  142. package/script/client/2_account_manager.js +85 -97
  143. package/script/client/2_bot_info_manager.js +26 -38
  144. package/script/client/2_business_connection_manager.js +10 -23
  145. package/script/client/2_client_encrypted.js +195 -212
  146. package/script/client/2_file_manager.d.ts +4 -3
  147. package/script/client/2_file_manager.d.ts.map +1 -1
  148. package/script/client/2_file_manager.js +285 -231
  149. package/script/client/2_file_manager_test.d.ts.map +1 -1
  150. package/script/client/2_network_statistics_manager.js +8 -21
  151. package/script/client/2_payment_manager.js +7 -20
  152. package/script/client/2_reaction_manager.js +7 -20
  153. package/script/client/2_translations_manager.js +98 -108
  154. package/script/client/2_update_manager.js +764 -759
  155. package/script/client/3_client_encrypted_pool.js +10 -26
  156. package/script/client/3_client_encrypted_pool_test.d.ts.map +1 -1
  157. package/script/client/3_message_manager.d.ts +1 -1
  158. package/script/client/3_message_manager.js +441 -448
  159. package/script/client/3_message_manager_test.d.ts.map +1 -1
  160. package/script/client/3_video_chat_manager.d.ts +1 -1
  161. package/script/client/3_video_chat_manager.js +57 -68
  162. package/script/client/4_callback_query_manager.js +18 -30
  163. package/script/client/4_chat_list_manager.js +322 -318
  164. package/script/client/4_chat_manager.js +118 -131
  165. package/script/client/4_forum_manager.js +67 -73
  166. package/script/client/4_gift_manager.js +16 -29
  167. package/script/client/4_inline_query_manager.js +16 -28
  168. package/script/client/4_link_preview_manager.js +6 -19
  169. package/script/client/4_poll_manager.js +44 -57
  170. package/script/client/4_story_manager.js +41 -53
  171. package/script/client/5_client.d.ts +7 -0
  172. package/script/client/5_client.d.ts.map +1 -1
  173. package/script/client/5_client.js +1269 -1288
  174. package/script/connection/1_connection_tcp.node.js +48 -65
  175. package/script/connection/1_connection_web_socket.js +92 -98
  176. package/script/deps/jsr.io/@roj/tgcrypto/1.0.1/dist/tgcrypto.js +3 -11
  177. package/script/deps/jsr.io/@std/assert/1.0.13/equal.js +17 -7
  178. package/script/deps/jsr.io/@std/async/1.0.13/delay.js +17 -7
  179. package/script/deps/jsr.io/@std/async/1.0.13/mux_async_iterator.js +31 -47
  180. package/script/deps/jsr.io/@std/async/1.0.13/tee.js +11 -34
  181. package/script/deps/jsr.io/@std/datetime/0.225.5/_date_time_formatter.js +4 -17
  182. package/script/deps/jsr.io/@std/internal/1.0.10/format.js +17 -7
  183. package/script/deps/jsr.io/@std/internal/1.0.10/styles.js +17 -7
  184. package/script/deps/jsr.io/@std/path/1.1.0/_os.js +17 -7
  185. package/script/mod.js +19 -19
  186. package/script/session/0_session_state.js +12 -38
  187. package/script/session/1_session.js +66 -79
  188. package/script/session/2_session_encrypted.js +325 -321
  189. package/script/storage/1_utilities_test.d.ts.map +1 -1
  190. package/script/storage/2_storage_indexed_db.js +26 -44
  191. package/script/storage/2_storage_local_storage.node.js +12 -25
  192. package/script/storage/2_storage_memory.js +24 -41
  193. package/script/storage/2_storage_session_storage.js +3 -16
  194. package/script/tl/0_utilities_test.d.ts.map +1 -1
  195. package/script/tl/1_tl_reader.js +81 -89
  196. package/script/tl/1_tl_reader_test.d.ts.map +1 -1
  197. package/script/tl/1_tl_writer.js +156 -165
  198. package/script/tl/1_tl_writer_test.d.ts.map +1 -1
  199. package/script/tl/2_telegram.js +17 -7
  200. package/script/transport/0_obfuscation.js +17 -7
  201. package/script/transport/0_transport.js +1 -8
  202. package/script/transport/1_transport_abridged.js +11 -24
  203. package/script/transport/1_transport_intermediate.js +10 -23
  204. package/script/transport/2_transport_provider_web_socket.d.ts.map +1 -1
  205. package/script/types/0_upload_progress.d.ts +29 -0
  206. package/script/types/0_upload_progress.d.ts.map +1 -0
  207. package/script/types/0_upload_progress.js +21 -0
  208. package/script/types/1_sticker.d.ts +1 -1
  209. package/script/types/1_sticker.d.ts.map +1 -1
  210. package/script/types/2_poll_answer.d.ts +19 -0
  211. package/script/types/2_poll_answer.d.ts.map +1 -1
  212. package/script/types/2_poll_answer.js +19 -0
  213. package/script/types/7_update.d.ts +21 -2
  214. package/script/types/7_update.d.ts.map +1 -1
  215. package/script/utilities/0_bigint.js +17 -7
  216. package/script/utilities/0_bigint_test.d.ts.map +1 -1
  217. package/script/utilities/0_buffer.d.ts +1 -1
  218. package/script/utilities/0_buffer.d.ts.map +1 -1
  219. package/script/utilities/0_buffer_test.d.ts.map +1 -1
  220. package/script/utilities/0_env.js +17 -7
  221. package/script/utilities/0_hash.d.ts +2 -2
  222. package/script/utilities/0_hash.d.ts.map +1 -1
  223. package/script/utilities/0_hash.js +17 -7
  224. package/script/utilities/0_misc.js +17 -7
  225. package/script/utilities/0_mutex.js +4 -19
  226. package/script/utilities/0_part_stream.js +11 -25
  227. package/script/utilities/0_part_stream_test.d.ts.map +1 -1
  228. package/script/utilities/0_rle.d.ts +2 -2
  229. package/script/utilities/0_rle.d.ts.map +1 -1
  230. package/script/utilities/0_rle_test.d.ts.map +1 -1
  231. package/script/utilities/0_text.d.ts +20 -1
  232. package/script/utilities/0_text.d.ts.map +1 -1
  233. package/script/utilities/0_text.js +19 -0
  234. package/script/utilities/1_auth.d.ts +1 -1
  235. package/script/utilities/1_auth.d.ts.map +1 -1
  236. package/script/utilities/1_auth.js +17 -7
  237. package/script/utilities/1_base64.d.ts +1 -1
  238. package/script/utilities/1_base64.d.ts.map +1 -1
  239. package/script/utilities/1_base64_test.d.ts.map +1 -1
  240. package/script/utilities/1_crypto.js +60 -61
  241. package/script/utilities/1_crypto_test.d.ts.map +1 -1
  242. package/script/utilities/1_logger.d.ts +2 -2
  243. package/script/utilities/1_math_test.d.ts.map +1 -1
  244. package/script/utilities/2_queue.js +30 -48
@@ -17,18 +17,7 @@
17
17
  * You should have received a copy of the GNU Lesser General Public License
18
18
  * along with this program. If not, see <https://www.gnu.org/licenses/>.
19
19
  */
20
- var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
21
- if (kind === "m") throw new TypeError("Private method is not writable");
22
- if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
23
- 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");
24
- return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
25
- };
26
- var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
27
- if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
28
- 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");
29
- return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
30
- };
31
- var _ClientEncrypted_instances, _a, _ClientEncrypted_SEND_MAX_TRIES, _ClientEncrypted_AUTH_KEY_CREATION_MAX_TRIES, _ClientEncrypted_L, _ClientEncrypted_plain, _ClientEncrypted_pendingRequests, _ClientEncrypted_apiId, _ClientEncrypted_appVersion, _ClientEncrypted_deviceModel, _ClientEncrypted_langCode, _ClientEncrypted_langPack, _ClientEncrypted_systemLangCode, _ClientEncrypted_systemVersion, _ClientEncrypted_disableUpdates, _ClientEncrypted_createAuthKeyPromise, _ClientEncrypted_createAuthKey, _ClientEncrypted_createAuthKeyInner, _ClientEncrypted_connectionInited, _ClientEncrypted_send, _ClientEncrypted_resend, _ClientEncrypted_onUpdate, _ClientEncrypted_onNewServerSalt, _ClientEncrypted_onMessageFailed, _ClientEncrypted_onRpcError, _ClientEncrypted_onRpcResult, _ClientEncrypted_onPong;
20
+ var _a;
32
21
  import { InputError } from "../0_errors.js";
33
22
  import { getLogger } from "../1_utilities.js";
34
23
  import { Api, Mtproto, X } from "../2_tl.js";
@@ -42,61 +31,44 @@ import { ClientPlain } from "./1_client_plain.js";
42
31
  // global ClientEncrypted ID counter for logs
43
32
  let id = 0;
44
33
  export class ClientEncrypted extends ClientAbstract {
34
+ static #SEND_MAX_TRIES = 10;
35
+ static #AUTH_KEY_CREATION_MAX_TRIES = 10;
36
+ handlers = {};
37
+ #L;
38
+ #plain;
39
+ session;
40
+ #pendingRequests = new Map();
41
+ #apiId;
42
+ #appVersion;
43
+ #deviceModel;
44
+ #langCode;
45
+ #langPack;
46
+ #systemLangCode;
47
+ #systemVersion;
48
+ #disableUpdates;
45
49
  constructor(dc, apiId, params) {
46
50
  super();
47
- _ClientEncrypted_instances.add(this);
48
- Object.defineProperty(this, "handlers", {
49
- enumerable: true,
50
- configurable: true,
51
- writable: true,
52
- value: {}
53
- });
54
- _ClientEncrypted_L.set(this, void 0);
55
- _ClientEncrypted_plain.set(this, void 0);
56
- Object.defineProperty(this, "session", {
57
- enumerable: true,
58
- configurable: true,
59
- writable: true,
60
- value: void 0
61
- });
62
- _ClientEncrypted_pendingRequests.set(this, new Map());
63
- _ClientEncrypted_apiId.set(this, void 0);
64
- _ClientEncrypted_appVersion.set(this, void 0);
65
- _ClientEncrypted_deviceModel.set(this, void 0);
66
- _ClientEncrypted_langCode.set(this, void 0);
67
- _ClientEncrypted_langPack.set(this, void 0);
68
- _ClientEncrypted_systemLangCode.set(this, void 0);
69
- _ClientEncrypted_systemVersion.set(this, void 0);
70
- _ClientEncrypted_disableUpdates.set(this, void 0);
71
- _ClientEncrypted_createAuthKeyPromise.set(this, void 0);
72
- _ClientEncrypted_connectionInited.set(this, false);
73
- Object.defineProperty(this, "lastRequest", {
74
- enumerable: true,
75
- configurable: true,
76
- writable: true,
77
- value: void 0
78
- });
79
- __classPrivateFieldSet(this, _ClientEncrypted_L, getLogger("ClientEncrypted").client(id++), "f");
80
- __classPrivateFieldSet(this, _ClientEncrypted_plain, new ClientPlain(dc, params), "f");
51
+ this.#L = getLogger("ClientEncrypted").client(id++);
52
+ this.#plain = new ClientPlain(dc, params);
81
53
  this.session = new SessionEncrypted(dc, params);
82
- this.session.handlers.onUpdate = __classPrivateFieldGet(this, _ClientEncrypted_instances, "m", _ClientEncrypted_onUpdate).bind(this);
83
- this.session.handlers.onNewServerSalt = __classPrivateFieldGet(this, _ClientEncrypted_instances, "m", _ClientEncrypted_onNewServerSalt).bind(this);
84
- this.session.handlers.onMessageFailed = __classPrivateFieldGet(this, _ClientEncrypted_instances, "m", _ClientEncrypted_onMessageFailed).bind(this);
85
- this.session.handlers.onRpcError = __classPrivateFieldGet(this, _ClientEncrypted_instances, "m", _ClientEncrypted_onRpcError).bind(this);
86
- this.session.handlers.onRpcResult = __classPrivateFieldGet(this, _ClientEncrypted_instances, "m", _ClientEncrypted_onRpcResult).bind(this);
87
- this.session.handlers.onPong = __classPrivateFieldGet(this, _ClientEncrypted_instances, "m", _ClientEncrypted_onPong).bind(this);
88
- __classPrivateFieldSet(this, _ClientEncrypted_apiId, apiId, "f");
89
- __classPrivateFieldSet(this, _ClientEncrypted_appVersion, params?.appVersion ?? APP_VERSION, "f");
90
- __classPrivateFieldSet(this, _ClientEncrypted_deviceModel, params?.deviceModel ?? DEVICE_MODEL, "f");
91
- __classPrivateFieldSet(this, _ClientEncrypted_langCode, params?.langCode ?? LANG_CODE, "f");
92
- __classPrivateFieldSet(this, _ClientEncrypted_langPack, params?.langPack ?? LANG_PACK, "f");
93
- __classPrivateFieldSet(this, _ClientEncrypted_systemLangCode, params?.systemLangCode ?? SYSTEM_LANG_CODE, "f");
94
- __classPrivateFieldSet(this, _ClientEncrypted_systemVersion, params?.systemVersion ?? SYSTEM_VERSION, "f");
95
- __classPrivateFieldSet(this, _ClientEncrypted_disableUpdates, params?.disableUpdates ?? false, "f");
54
+ this.session.handlers.onUpdate = this.#onUpdate.bind(this);
55
+ this.session.handlers.onNewServerSalt = this.#onNewServerSalt.bind(this);
56
+ this.session.handlers.onMessageFailed = this.#onMessageFailed.bind(this);
57
+ this.session.handlers.onRpcError = this.#onRpcError.bind(this);
58
+ this.session.handlers.onRpcResult = this.#onRpcResult.bind(this);
59
+ this.session.handlers.onPong = this.#onPong.bind(this);
60
+ this.#apiId = apiId;
61
+ this.#appVersion = params?.appVersion ?? APP_VERSION;
62
+ this.#deviceModel = params?.deviceModel ?? DEVICE_MODEL;
63
+ this.#langCode = params?.langCode ?? LANG_CODE;
64
+ this.#langPack = params?.langPack ?? LANG_PACK;
65
+ this.#systemLangCode = params?.systemLangCode ?? SYSTEM_LANG_CODE;
66
+ this.#systemVersion = params?.systemVersion ?? SYSTEM_VERSION;
67
+ this.#disableUpdates = params?.disableUpdates ?? false;
96
68
  }
97
69
  async connect() {
98
70
  if (!this.authKey.length) {
99
- await __classPrivateFieldGet(this, _ClientEncrypted_instances, "m", _ClientEncrypted_createAuthKey).call(this);
71
+ await this.#createAuthKey();
100
72
  }
101
73
  await super.connect();
102
74
  }
@@ -104,183 +76,194 @@ export class ClientEncrypted extends ClientAbstract {
104
76
  super.disconnect();
105
77
  this.lastRequest = undefined;
106
78
  }
107
- get authKey() {
108
- return this.session.authKey;
109
- }
110
- async setAuthKey(authKey) {
111
- await this.session.setAuthKey(authKey);
112
- }
113
- async invoke(function_) {
114
- const messageId = await __classPrivateFieldGet(this, _ClientEncrypted_instances, "m", _ClientEncrypted_send).call(this, function_);
115
- return (await new Promise((resolve, reject) => {
116
- __classPrivateFieldGet(this, _ClientEncrypted_pendingRequests, "f").set(messageId, { resolve, reject, call: function_ });
117
- }));
79
+ #createAuthKeyPromise;
80
+ #createAuthKey() {
81
+ return this.#createAuthKeyPromise ??= this.#createAuthKeyInner().finally(() => {
82
+ this.#createAuthKeyPromise = undefined;
83
+ });
118
84
  }
119
- }
120
- _a = ClientEncrypted, _ClientEncrypted_L = new WeakMap(), _ClientEncrypted_plain = new WeakMap(), _ClientEncrypted_pendingRequests = new WeakMap(), _ClientEncrypted_apiId = new WeakMap(), _ClientEncrypted_appVersion = new WeakMap(), _ClientEncrypted_deviceModel = new WeakMap(), _ClientEncrypted_langCode = new WeakMap(), _ClientEncrypted_langPack = new WeakMap(), _ClientEncrypted_systemLangCode = new WeakMap(), _ClientEncrypted_systemVersion = new WeakMap(), _ClientEncrypted_disableUpdates = new WeakMap(), _ClientEncrypted_createAuthKeyPromise = new WeakMap(), _ClientEncrypted_connectionInited = new WeakMap(), _ClientEncrypted_instances = new WeakSet(), _ClientEncrypted_createAuthKey = function _ClientEncrypted_createAuthKey() {
121
- return __classPrivateFieldSet(this, _ClientEncrypted_createAuthKeyPromise, __classPrivateFieldGet(this, _ClientEncrypted_createAuthKeyPromise, "f") ?? __classPrivateFieldGet(this, _ClientEncrypted_instances, "m", _ClientEncrypted_createAuthKeyInner).call(this).finally(() => {
122
- __classPrivateFieldSet(this, _ClientEncrypted_createAuthKeyPromise, undefined, "f");
123
- }), "f");
124
- }, _ClientEncrypted_createAuthKeyInner = async function _ClientEncrypted_createAuthKeyInner() {
125
- let lastErr;
126
- let errored = false;
127
- for (let i = 0; i < __classPrivateFieldGet(_a, _a, "f", _ClientEncrypted_AUTH_KEY_CREATION_MAX_TRIES); ++i) {
128
- try {
129
- await __classPrivateFieldGet(this, _ClientEncrypted_plain, "f").connect();
130
- const [authKey, serverSalt] = await __classPrivateFieldGet(this, _ClientEncrypted_plain, "f").createAuthKey();
131
- await this.setAuthKey(authKey);
132
- this.serverSalt = serverSalt;
133
- errored = false;
134
- break;
135
- }
136
- catch (err) {
137
- errored = true;
138
- lastErr = err;
139
- if (this.disconnected) {
85
+ async #createAuthKeyInner() {
86
+ let lastErr;
87
+ let errored = false;
88
+ for (let i = 0; i < _a.#AUTH_KEY_CREATION_MAX_TRIES; ++i) {
89
+ try {
90
+ await this.#plain.connect();
91
+ const [authKey, serverSalt] = await this.#plain.createAuthKey();
92
+ await this.setAuthKey(authKey);
93
+ this.serverSalt = serverSalt;
94
+ errored = false;
140
95
  break;
141
96
  }
142
- __classPrivateFieldGet(this, _ClientEncrypted_L, "f").error("failed to create auth key:", err);
97
+ catch (err) {
98
+ errored = true;
99
+ lastErr = err;
100
+ if (this.disconnected) {
101
+ break;
102
+ }
103
+ this.#L.error("failed to create auth key:", err);
104
+ }
105
+ finally {
106
+ this.#plain.disconnect();
107
+ }
143
108
  }
144
- finally {
145
- __classPrivateFieldGet(this, _ClientEncrypted_plain, "f").disconnect();
109
+ if (errored) {
110
+ throw lastErr;
146
111
  }
147
112
  }
148
- if (errored) {
149
- throw lastErr;
113
+ get authKey() {
114
+ return this.session.authKey;
150
115
  }
151
- }, _ClientEncrypted_send = async function _ClientEncrypted_send(function_) {
152
- this.lastRequest = new Date();
153
- let body;
154
- if (Mtproto.is("ping", function_)) {
155
- body = Mtproto.serializeObject(function_);
116
+ async setAuthKey(authKey) {
117
+ await this.session.setAuthKey(authKey);
156
118
  }
157
- else {
158
- if (__classPrivateFieldGet(this, _ClientEncrypted_disableUpdates, "f") && !isCdnFunction(function_)) {
159
- function_ = { _: "invokeWithoutUpdates", query: function_ };
119
+ #connectionInited = false;
120
+ lastRequest;
121
+ async #send(function_) {
122
+ this.lastRequest = new Date();
123
+ let body;
124
+ if (Mtproto.is("ping", function_)) {
125
+ body = Mtproto.serializeObject(function_);
160
126
  }
161
- if (!__classPrivateFieldGet(this, _ClientEncrypted_connectionInited, "f")) {
162
- if (!__classPrivateFieldGet(this, _ClientEncrypted_apiId, "f")) {
163
- throw new InputError("apiId not set");
127
+ else {
128
+ if (this.#disableUpdates && !isCdnFunction(function_)) {
129
+ function_ = { _: "invokeWithoutUpdates", query: function_ };
164
130
  }
165
- function_ = {
166
- _: "initConnection",
167
- api_id: __classPrivateFieldGet(this, _ClientEncrypted_apiId, "f"),
168
- app_version: __classPrivateFieldGet(this, _ClientEncrypted_appVersion, "f"),
169
- device_model: __classPrivateFieldGet(this, _ClientEncrypted_deviceModel, "f"),
170
- lang_code: __classPrivateFieldGet(this, _ClientEncrypted_langCode, "f"),
171
- lang_pack: __classPrivateFieldGet(this, _ClientEncrypted_langPack, "f"),
172
- query: {
173
- _: "invokeWithLayer",
174
- layer: Api.LAYER,
175
- query: function_,
176
- },
177
- system_lang_code: __classPrivateFieldGet(this, _ClientEncrypted_systemLangCode, "f"),
178
- system_version: __classPrivateFieldGet(this, _ClientEncrypted_systemVersion, "f"),
179
- };
180
- }
181
- body = Api.serializeObject(function_);
182
- }
183
- let lastErr;
184
- for (let i = 0; i < __classPrivateFieldGet(_a, _a, "f", _ClientEncrypted_SEND_MAX_TRIES); ++i) {
185
- let errored = false;
186
- try {
187
- return await this.session.send(body);
188
- }
189
- catch (err) {
190
- errored = true;
191
- lastErr = err;
192
- if (this.disconnected) {
193
- break;
131
+ if (!this.#connectionInited) {
132
+ if (!this.#apiId) {
133
+ throw new InputError("apiId not set");
134
+ }
135
+ function_ = {
136
+ _: "initConnection",
137
+ api_id: this.#apiId,
138
+ app_version: this.#appVersion,
139
+ device_model: this.#deviceModel,
140
+ lang_code: this.#langCode,
141
+ lang_pack: this.#langPack,
142
+ query: {
143
+ _: "invokeWithLayer",
144
+ layer: Api.LAYER,
145
+ query: function_,
146
+ },
147
+ system_lang_code: this.#systemLangCode,
148
+ system_version: this.#systemVersion,
149
+ };
194
150
  }
195
- __classPrivateFieldGet(this, _ClientEncrypted_L, "f").error("send failed:", err);
151
+ body = Api.serializeObject(function_);
196
152
  }
197
- finally {
198
- if (!errored) {
199
- __classPrivateFieldGet(this, _ClientEncrypted_L, "f").debug("invoked", repr(function_));
200
- __classPrivateFieldGet(this, _ClientEncrypted_L, "f").out(function_);
153
+ let lastErr;
154
+ for (let i = 0; i < _a.#SEND_MAX_TRIES; ++i) {
155
+ let errored = false;
156
+ try {
157
+ return await this.session.send(body);
158
+ }
159
+ catch (err) {
160
+ errored = true;
161
+ lastErr = err;
162
+ if (this.disconnected) {
163
+ break;
164
+ }
165
+ this.#L.error("send failed:", err);
166
+ }
167
+ finally {
168
+ if (!errored) {
169
+ this.#L.debug("invoked", repr(function_));
170
+ this.#L.out(function_);
171
+ }
201
172
  }
202
173
  }
174
+ throw new Error(`Failed to invoke function after ${_a.#SEND_MAX_TRIES} tries.`, { cause: lastErr });
203
175
  }
204
- throw new Error(`Failed to invoke function after ${__classPrivateFieldGet(_a, _a, "f", _ClientEncrypted_SEND_MAX_TRIES)} tries.`, { cause: lastErr });
205
- }, _ClientEncrypted_resend = async function _ClientEncrypted_resend(request) {
206
- try {
207
- const messageId = await __classPrivateFieldGet(this, _ClientEncrypted_instances, "m", _ClientEncrypted_send).call(this, request.call);
208
- __classPrivateFieldGet(this, _ClientEncrypted_pendingRequests, "f").set(messageId, request);
209
- }
210
- catch (err) {
211
- request.reject(err);
212
- }
213
- }, _ClientEncrypted_onUpdate = async function _ClientEncrypted_onUpdate(body) {
214
- let type;
215
- try {
216
- type = await Api.deserializeType(X, body);
217
- }
218
- catch (err) {
219
- __classPrivateFieldGet(this, _ClientEncrypted_L, "f").error("failed to deserialize update:", err);
220
- this.handlers.onDeserializationError?.();
221
- return;
222
- }
223
- if (Api.isOfEnum("Update", type) || Api.isOfEnum("Updates", type)) {
224
- this.handlers.onUpdate?.(type);
225
- }
226
- else {
227
- __classPrivateFieldGet(this, _ClientEncrypted_L, "f").warning("received unknown type:", repr(type));
228
- }
229
- }, _ClientEncrypted_onNewServerSalt = function _ClientEncrypted_onNewServerSalt(serverSalt) {
230
- this.handlers.onNewServerSalt?.(serverSalt);
231
- }, _ClientEncrypted_onMessageFailed = async function _ClientEncrypted_onMessageFailed(msgId, error) {
232
- const request = __classPrivateFieldGet(this, _ClientEncrypted_pendingRequests, "f").get(msgId);
233
- if (request) {
234
- __classPrivateFieldGet(this, _ClientEncrypted_pendingRequests, "f").delete(msgId);
235
- if (error instanceof SessionError) {
236
- await __classPrivateFieldGet(this, _ClientEncrypted_instances, "m", _ClientEncrypted_resend).call(this, request);
176
+ async #resend(request) {
177
+ try {
178
+ const messageId = await this.#send(request.call);
179
+ this.#pendingRequests.set(messageId, request);
237
180
  }
238
- else {
239
- request.reject(error);
181
+ catch (err) {
182
+ request.reject(err);
240
183
  }
241
184
  }
242
- }, _ClientEncrypted_onRpcError = async function _ClientEncrypted_onRpcError(msgId, error) {
243
- const request = __classPrivateFieldGet(this, _ClientEncrypted_pendingRequests, "f").get(msgId);
244
- if (request) {
245
- __classPrivateFieldGet(this, _ClientEncrypted_pendingRequests, "f").delete(msgId);
246
- const reason = constructTelegramError(error, request.call);
247
- if (reason instanceof ConnectionNotInited) {
248
- __classPrivateFieldSet(this, _ClientEncrypted_connectionInited, false, "f");
249
- await __classPrivateFieldGet(this, _ClientEncrypted_instances, "m", _ClientEncrypted_resend).call(this, request);
250
- }
251
- else {
252
- request.reject(constructTelegramError(error, request.call));
253
- }
185
+ async invoke(function_) {
186
+ const messageId = await this.#send(function_);
187
+ return (await new Promise((resolve, reject) => {
188
+ this.#pendingRequests.set(messageId, { resolve, reject, call: function_ });
189
+ }));
254
190
  }
255
- }, _ClientEncrypted_onRpcResult = async function _ClientEncrypted_onRpcResult(msgId, body) {
256
- const request = __classPrivateFieldGet(this, _ClientEncrypted_pendingRequests, "f").get(msgId);
257
- if (request) {
191
+ async #onUpdate(body) {
258
192
  let type;
259
193
  try {
260
- type = await Api.deserializeType(Api.mustGetReturnType(request.call._), body);
261
- __classPrivateFieldGet(this, _ClientEncrypted_L, "f").in(type);
262
- __classPrivateFieldGet(this, _ClientEncrypted_L, "f").debug("received rpc_result", repr(type));
263
- request.resolve(type);
194
+ type = await Api.deserializeType(X, body);
264
195
  }
265
196
  catch (err) {
266
- request.reject(err);
267
- __classPrivateFieldGet(this, _ClientEncrypted_L, "f").error("failed to deserialize RPC result body:", err);
197
+ this.#L.error("failed to deserialize update:", err);
268
198
  this.handlers.onDeserializationError?.();
269
199
  return;
270
200
  }
271
- finally {
272
- __classPrivateFieldGet(this, _ClientEncrypted_pendingRequests, "f").delete(msgId);
201
+ if (Api.isOfEnum("Update", type) || Api.isOfEnum("Updates", type)) {
202
+ this.handlers.onUpdate?.(type);
203
+ }
204
+ else {
205
+ this.#L.warning("received unknown type:", repr(type));
273
206
  }
274
207
  }
275
- if (!__classPrivateFieldGet(this, _ClientEncrypted_connectionInited, "f")) {
276
- __classPrivateFieldSet(this, _ClientEncrypted_connectionInited, true, "f");
208
+ #onNewServerSalt(serverSalt) {
209
+ this.handlers.onNewServerSalt?.(serverSalt);
277
210
  }
278
- }, _ClientEncrypted_onPong = function _ClientEncrypted_onPong(pong) {
279
- const pendingRequest = __classPrivateFieldGet(this, _ClientEncrypted_pendingRequests, "f").get(pong.msg_id);
280
- if (pendingRequest) {
281
- pendingRequest.resolve(pong);
282
- __classPrivateFieldGet(this, _ClientEncrypted_pendingRequests, "f").delete(pong.msg_id);
211
+ async #onMessageFailed(msgId, error) {
212
+ const request = this.#pendingRequests.get(msgId);
213
+ if (request) {
214
+ this.#pendingRequests.delete(msgId);
215
+ if (error instanceof SessionError) {
216
+ await this.#resend(request);
217
+ }
218
+ else {
219
+ request.reject(error);
220
+ }
221
+ }
283
222
  }
284
- };
285
- _ClientEncrypted_SEND_MAX_TRIES = { value: 10 };
286
- _ClientEncrypted_AUTH_KEY_CREATION_MAX_TRIES = { value: 10 };
223
+ async #onRpcError(msgId, error) {
224
+ const request = this.#pendingRequests.get(msgId);
225
+ if (request) {
226
+ this.#pendingRequests.delete(msgId);
227
+ const reason = constructTelegramError(error, request.call);
228
+ if (reason instanceof ConnectionNotInited) {
229
+ this.#connectionInited = false;
230
+ await this.#resend(request);
231
+ }
232
+ else {
233
+ request.reject(constructTelegramError(error, request.call));
234
+ }
235
+ }
236
+ }
237
+ async #onRpcResult(msgId, body) {
238
+ const request = this.#pendingRequests.get(msgId);
239
+ if (request) {
240
+ let type;
241
+ try {
242
+ type = await Api.deserializeType(Api.mustGetReturnType(request.call._), body);
243
+ this.#L.in(type);
244
+ this.#L.debug("received rpc_result", repr(type));
245
+ request.resolve(type);
246
+ }
247
+ catch (err) {
248
+ request.reject(err);
249
+ this.#L.error("failed to deserialize RPC result body:", err);
250
+ this.handlers.onDeserializationError?.();
251
+ return;
252
+ }
253
+ finally {
254
+ this.#pendingRequests.delete(msgId);
255
+ }
256
+ }
257
+ if (!this.#connectionInited) {
258
+ this.#connectionInited = true;
259
+ }
260
+ }
261
+ #onPong(pong) {
262
+ const pendingRequest = this.#pendingRequests.get(pong.msg_id);
263
+ if (pendingRequest) {
264
+ pendingRequest.resolve(pong);
265
+ this.#pendingRequests.delete(pong.msg_id);
266
+ }
267
+ }
268
+ }
269
+ _a = ClientEncrypted;
@@ -5,12 +5,13 @@ import { C } from "./1_types.js";
5
5
  export declare class FileManager {
6
6
  #private;
7
7
  constructor(c: C);
8
+ getProgressId(): Promise<string>;
8
9
  upload(file: FileSource, params?: _UploadCommon, checkName?: null | ((name: string) => string), allowStream?: boolean): Promise<Api.InputFile>;
9
- downloadInner(location: Api.InputFileLocation, dcId: number, params: DownloadParams | undefined): AsyncGenerator<Uint8Array, void, unknown>;
10
+ downloadInner(location: Api.InputFileLocation, dcId: number, params: DownloadParams | undefined): AsyncGenerator<Uint8Array<ArrayBufferLike>, void, any>;
10
11
  static validateChunkSize(chunkSize: number, max: number): void;
11
12
  static validateOffset(offset: number): void;
12
- download(fileId: string, params?: DownloadParams): AsyncGenerator<Uint8Array, void, unknown>;
13
- getStickerSetName(inputStickerSet: Api.inputStickerSetID, hash?: number): Promise<string>;
13
+ download(fileId: string, params?: DownloadParams): AsyncGenerator<Uint8Array<ArrayBufferLike>, void, any>;
14
+ getStickerSetName(inputStickerSet: Api.inputStickerSetID, hash?: number): Promise<string | undefined>;
14
15
  getCustomEmojiStickers(id: string | string[]): Promise<Sticker[]>;
15
16
  }
16
17
  //# sourceMappingURL=2_file_manager.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"2_file_manager.d.ts","sourceRoot":"","sources":["../../src/client/2_file_manager.ts"],"names":[],"mappings":"AAyBA,OAAO,EAAE,GAAG,EAAE,MAAM,YAAY,CAAC;AAEjC,OAAO,EAA+C,UAAU,EAA8C,OAAO,EAAkB,MAAM,eAAe,CAAC;AAE7J,OAAO,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAE9D,OAAO,EAAE,CAAC,EAAE,MAAM,cAAc,CAAC;AAEjC,qBAAa,WAAW;;gBAOV,CAAC,EAAE,CAAC;IAOV,MAAM,CAAC,IAAI,EAAE,UAAU,EAAE,MAAM,CAAC,EAAE,aAAa,EAAE,SAAS,CAAC,EAAE,IAAI,GAAG,CAAC,CAAC,IAAI,EAAE,MAAM,KAAK,MAAM,CAAC,EAAE,WAAW,UAAO,GAAG,OAAO,CAAC,GAAG,CAAC,SAAS,CAAC;IAgN1I,aAAa,CAAC,QAAQ,EAAE,GAAG,CAAC,iBAAiB,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,cAAc,GAAG,SAAS;IA4EtG,MAAM,CAAC,iBAAiB,CAAC,SAAS,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM;IAevD,MAAM,CAAC,cAAc,CAAC,MAAM,EAAE,MAAM;IAY7B,QAAQ,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,cAAc;IAmDjD,iBAAiB,CAAC,eAAe,EAAE,GAAG,CAAC,iBAAiB,EAAE,IAAI,SAAI;IAalE,sBAAsB,CAAC,EAAE,EAAE,MAAM,GAAG,MAAM,EAAE;CA6CnD"}
1
+ {"version":3,"file":"2_file_manager.d.ts","sourceRoot":"","sources":["../../src/client/2_file_manager.ts"],"names":[],"mappings":"AAyBA,OAAO,EAAE,GAAG,EAAE,MAAM,YAAY,CAAC;AAEjC,OAAO,EAA+C,UAAU,EAA8C,OAAO,EAAkB,MAAM,eAAe,CAAC;AAG7J,OAAO,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAE9D,OAAO,EAAE,CAAC,EAAE,MAAM,cAAc,CAAC;AAEjC,qBAAa,WAAW;;gBAOV,CAAC,EAAE,CAAC;IAQhB,aAAa;IASP,MAAM,CAAC,IAAI,EAAE,UAAU,EAAE,MAAM,CAAC,EAAE,aAAa,EAAE,SAAS,CAAC,EAAE,IAAI,GAAG,CAAC,CAAC,IAAI,EAAE,MAAM,KAAK,MAAM,CAAC,EAAE,WAAW,UAAO,GAAG,OAAO,CAAC,GAAG,CAAC,SAAS,CAAC;IAmP1I,aAAa,CAAC,QAAQ,EAAE,GAAG,CAAC,iBAAiB,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,cAAc,GAAG,SAAS;IA4EtG,MAAM,CAAC,iBAAiB,CAAC,SAAS,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM;IAevD,MAAM,CAAC,cAAc,CAAC,MAAM,EAAE,MAAM;IAY7B,QAAQ,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,cAAc;IAmDjD,iBAAiB,CAAC,eAAe,EAAE,GAAG,CAAC,iBAAiB,EAAE,IAAI,SAAI;IAqBlE,sBAAsB,CAAC,EAAE,EAAE,MAAM,GAAG,MAAM,EAAE;CA6CnD"}