@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
@@ -18,18 +18,7 @@
18
18
  * You should have received a copy of the GNU Lesser General Public License
19
19
  * along with this program. If not, see <https://www.gnu.org/licenses/>.
20
20
  */
21
- var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
22
- if (kind === "m") throw new TypeError("Private method is not writable");
23
- if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
24
- 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");
25
- return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
26
- };
27
- var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
28
- if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
29
- 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");
30
- return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
31
- };
32
- 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;
21
+ var _a;
33
22
  Object.defineProperty(exports, "__esModule", { value: true });
34
23
  exports.ClientEncrypted = void 0;
35
24
  const _0_errors_js_1 = require("../0_errors.js");
@@ -45,61 +34,44 @@ const _1_client_plain_js_1 = require("./1_client_plain.js");
45
34
  // global ClientEncrypted ID counter for logs
46
35
  let id = 0;
47
36
  class ClientEncrypted extends _0_client_abstract_js_1.ClientAbstract {
37
+ static #SEND_MAX_TRIES = 10;
38
+ static #AUTH_KEY_CREATION_MAX_TRIES = 10;
39
+ handlers = {};
40
+ #L;
41
+ #plain;
42
+ session;
43
+ #pendingRequests = new Map();
44
+ #apiId;
45
+ #appVersion;
46
+ #deviceModel;
47
+ #langCode;
48
+ #langPack;
49
+ #systemLangCode;
50
+ #systemVersion;
51
+ #disableUpdates;
48
52
  constructor(dc, apiId, params) {
49
53
  super();
50
- _ClientEncrypted_instances.add(this);
51
- Object.defineProperty(this, "handlers", {
52
- enumerable: true,
53
- configurable: true,
54
- writable: true,
55
- value: {}
56
- });
57
- _ClientEncrypted_L.set(this, void 0);
58
- _ClientEncrypted_plain.set(this, void 0);
59
- Object.defineProperty(this, "session", {
60
- enumerable: true,
61
- configurable: true,
62
- writable: true,
63
- value: void 0
64
- });
65
- _ClientEncrypted_pendingRequests.set(this, new Map());
66
- _ClientEncrypted_apiId.set(this, void 0);
67
- _ClientEncrypted_appVersion.set(this, void 0);
68
- _ClientEncrypted_deviceModel.set(this, void 0);
69
- _ClientEncrypted_langCode.set(this, void 0);
70
- _ClientEncrypted_langPack.set(this, void 0);
71
- _ClientEncrypted_systemLangCode.set(this, void 0);
72
- _ClientEncrypted_systemVersion.set(this, void 0);
73
- _ClientEncrypted_disableUpdates.set(this, void 0);
74
- _ClientEncrypted_createAuthKeyPromise.set(this, void 0);
75
- _ClientEncrypted_connectionInited.set(this, false);
76
- Object.defineProperty(this, "lastRequest", {
77
- enumerable: true,
78
- configurable: true,
79
- writable: true,
80
- value: void 0
81
- });
82
- __classPrivateFieldSet(this, _ClientEncrypted_L, (0, _1_utilities_js_1.getLogger)("ClientEncrypted").client(id++), "f");
83
- __classPrivateFieldSet(this, _ClientEncrypted_plain, new _1_client_plain_js_1.ClientPlain(dc, params), "f");
54
+ this.#L = (0, _1_utilities_js_1.getLogger)("ClientEncrypted").client(id++);
55
+ this.#plain = new _1_client_plain_js_1.ClientPlain(dc, params);
84
56
  this.session = new _4_session_js_1.SessionEncrypted(dc, params);
85
- this.session.handlers.onUpdate = __classPrivateFieldGet(this, _ClientEncrypted_instances, "m", _ClientEncrypted_onUpdate).bind(this);
86
- this.session.handlers.onNewServerSalt = __classPrivateFieldGet(this, _ClientEncrypted_instances, "m", _ClientEncrypted_onNewServerSalt).bind(this);
87
- this.session.handlers.onMessageFailed = __classPrivateFieldGet(this, _ClientEncrypted_instances, "m", _ClientEncrypted_onMessageFailed).bind(this);
88
- this.session.handlers.onRpcError = __classPrivateFieldGet(this, _ClientEncrypted_instances, "m", _ClientEncrypted_onRpcError).bind(this);
89
- this.session.handlers.onRpcResult = __classPrivateFieldGet(this, _ClientEncrypted_instances, "m", _ClientEncrypted_onRpcResult).bind(this);
90
- this.session.handlers.onPong = __classPrivateFieldGet(this, _ClientEncrypted_instances, "m", _ClientEncrypted_onPong).bind(this);
91
- __classPrivateFieldSet(this, _ClientEncrypted_apiId, apiId, "f");
92
- __classPrivateFieldSet(this, _ClientEncrypted_appVersion, params?.appVersion ?? _4_constants_js_1.APP_VERSION, "f");
93
- __classPrivateFieldSet(this, _ClientEncrypted_deviceModel, params?.deviceModel ?? _4_constants_js_1.DEVICE_MODEL, "f");
94
- __classPrivateFieldSet(this, _ClientEncrypted_langCode, params?.langCode ?? _4_constants_js_1.LANG_CODE, "f");
95
- __classPrivateFieldSet(this, _ClientEncrypted_langPack, params?.langPack ?? _4_constants_js_1.LANG_PACK, "f");
96
- __classPrivateFieldSet(this, _ClientEncrypted_systemLangCode, params?.systemLangCode ?? _4_constants_js_1.SYSTEM_LANG_CODE, "f");
97
- __classPrivateFieldSet(this, _ClientEncrypted_systemVersion, params?.systemVersion ?? _4_constants_js_1.SYSTEM_VERSION, "f");
98
- __classPrivateFieldSet(this, _ClientEncrypted_disableUpdates, params?.disableUpdates ?? false, "f");
57
+ this.session.handlers.onUpdate = this.#onUpdate.bind(this);
58
+ this.session.handlers.onNewServerSalt = this.#onNewServerSalt.bind(this);
59
+ this.session.handlers.onMessageFailed = this.#onMessageFailed.bind(this);
60
+ this.session.handlers.onRpcError = this.#onRpcError.bind(this);
61
+ this.session.handlers.onRpcResult = this.#onRpcResult.bind(this);
62
+ this.session.handlers.onPong = this.#onPong.bind(this);
63
+ this.#apiId = apiId;
64
+ this.#appVersion = params?.appVersion ?? _4_constants_js_1.APP_VERSION;
65
+ this.#deviceModel = params?.deviceModel ?? _4_constants_js_1.DEVICE_MODEL;
66
+ this.#langCode = params?.langCode ?? _4_constants_js_1.LANG_CODE;
67
+ this.#langPack = params?.langPack ?? _4_constants_js_1.LANG_PACK;
68
+ this.#systemLangCode = params?.systemLangCode ?? _4_constants_js_1.SYSTEM_LANG_CODE;
69
+ this.#systemVersion = params?.systemVersion ?? _4_constants_js_1.SYSTEM_VERSION;
70
+ this.#disableUpdates = params?.disableUpdates ?? false;
99
71
  }
100
72
  async connect() {
101
73
  if (!this.authKey.length) {
102
- await __classPrivateFieldGet(this, _ClientEncrypted_instances, "m", _ClientEncrypted_createAuthKey).call(this);
74
+ await this.#createAuthKey();
103
75
  }
104
76
  await super.connect();
105
77
  }
@@ -107,184 +79,195 @@ class ClientEncrypted extends _0_client_abstract_js_1.ClientAbstract {
107
79
  super.disconnect();
108
80
  this.lastRequest = undefined;
109
81
  }
110
- get authKey() {
111
- return this.session.authKey;
112
- }
113
- async setAuthKey(authKey) {
114
- await this.session.setAuthKey(authKey);
115
- }
116
- async invoke(function_) {
117
- const messageId = await __classPrivateFieldGet(this, _ClientEncrypted_instances, "m", _ClientEncrypted_send).call(this, function_);
118
- return (await new Promise((resolve, reject) => {
119
- __classPrivateFieldGet(this, _ClientEncrypted_pendingRequests, "f").set(messageId, { resolve, reject, call: function_ });
120
- }));
82
+ #createAuthKeyPromise;
83
+ #createAuthKey() {
84
+ return this.#createAuthKeyPromise ??= this.#createAuthKeyInner().finally(() => {
85
+ this.#createAuthKeyPromise = undefined;
86
+ });
121
87
  }
122
- }
123
- exports.ClientEncrypted = ClientEncrypted;
124
- _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() {
125
- return __classPrivateFieldSet(this, _ClientEncrypted_createAuthKeyPromise, __classPrivateFieldGet(this, _ClientEncrypted_createAuthKeyPromise, "f") ?? __classPrivateFieldGet(this, _ClientEncrypted_instances, "m", _ClientEncrypted_createAuthKeyInner).call(this).finally(() => {
126
- __classPrivateFieldSet(this, _ClientEncrypted_createAuthKeyPromise, undefined, "f");
127
- }), "f");
128
- }, _ClientEncrypted_createAuthKeyInner = async function _ClientEncrypted_createAuthKeyInner() {
129
- let lastErr;
130
- let errored = false;
131
- for (let i = 0; i < __classPrivateFieldGet(_a, _a, "f", _ClientEncrypted_AUTH_KEY_CREATION_MAX_TRIES); ++i) {
132
- try {
133
- await __classPrivateFieldGet(this, _ClientEncrypted_plain, "f").connect();
134
- const [authKey, serverSalt] = await __classPrivateFieldGet(this, _ClientEncrypted_plain, "f").createAuthKey();
135
- await this.setAuthKey(authKey);
136
- this.serverSalt = serverSalt;
137
- errored = false;
138
- break;
139
- }
140
- catch (err) {
141
- errored = true;
142
- lastErr = err;
143
- if (this.disconnected) {
88
+ async #createAuthKeyInner() {
89
+ let lastErr;
90
+ let errored = false;
91
+ for (let i = 0; i < _a.#AUTH_KEY_CREATION_MAX_TRIES; ++i) {
92
+ try {
93
+ await this.#plain.connect();
94
+ const [authKey, serverSalt] = await this.#plain.createAuthKey();
95
+ await this.setAuthKey(authKey);
96
+ this.serverSalt = serverSalt;
97
+ errored = false;
144
98
  break;
145
99
  }
146
- __classPrivateFieldGet(this, _ClientEncrypted_L, "f").error("failed to create auth key:", err);
100
+ catch (err) {
101
+ errored = true;
102
+ lastErr = err;
103
+ if (this.disconnected) {
104
+ break;
105
+ }
106
+ this.#L.error("failed to create auth key:", err);
107
+ }
108
+ finally {
109
+ this.#plain.disconnect();
110
+ }
147
111
  }
148
- finally {
149
- __classPrivateFieldGet(this, _ClientEncrypted_plain, "f").disconnect();
112
+ if (errored) {
113
+ throw lastErr;
150
114
  }
151
115
  }
152
- if (errored) {
153
- throw lastErr;
116
+ get authKey() {
117
+ return this.session.authKey;
154
118
  }
155
- }, _ClientEncrypted_send = async function _ClientEncrypted_send(function_) {
156
- this.lastRequest = new Date();
157
- let body;
158
- if (_2_tl_js_1.Mtproto.is("ping", function_)) {
159
- body = _2_tl_js_1.Mtproto.serializeObject(function_);
119
+ async setAuthKey(authKey) {
120
+ await this.session.setAuthKey(authKey);
160
121
  }
161
- else {
162
- if (__classPrivateFieldGet(this, _ClientEncrypted_disableUpdates, "f") && !(0, _0_utilities_js_1.isCdnFunction)(function_)) {
163
- function_ = { _: "invokeWithoutUpdates", query: function_ };
122
+ #connectionInited = false;
123
+ lastRequest;
124
+ async #send(function_) {
125
+ this.lastRequest = new Date();
126
+ let body;
127
+ if (_2_tl_js_1.Mtproto.is("ping", function_)) {
128
+ body = _2_tl_js_1.Mtproto.serializeObject(function_);
164
129
  }
165
- if (!__classPrivateFieldGet(this, _ClientEncrypted_connectionInited, "f")) {
166
- if (!__classPrivateFieldGet(this, _ClientEncrypted_apiId, "f")) {
167
- throw new _0_errors_js_1.InputError("apiId not set");
130
+ else {
131
+ if (this.#disableUpdates && !(0, _0_utilities_js_1.isCdnFunction)(function_)) {
132
+ function_ = { _: "invokeWithoutUpdates", query: function_ };
168
133
  }
169
- function_ = {
170
- _: "initConnection",
171
- api_id: __classPrivateFieldGet(this, _ClientEncrypted_apiId, "f"),
172
- app_version: __classPrivateFieldGet(this, _ClientEncrypted_appVersion, "f"),
173
- device_model: __classPrivateFieldGet(this, _ClientEncrypted_deviceModel, "f"),
174
- lang_code: __classPrivateFieldGet(this, _ClientEncrypted_langCode, "f"),
175
- lang_pack: __classPrivateFieldGet(this, _ClientEncrypted_langPack, "f"),
176
- query: {
177
- _: "invokeWithLayer",
178
- layer: _2_tl_js_1.Api.LAYER,
179
- query: function_,
180
- },
181
- system_lang_code: __classPrivateFieldGet(this, _ClientEncrypted_systemLangCode, "f"),
182
- system_version: __classPrivateFieldGet(this, _ClientEncrypted_systemVersion, "f"),
183
- };
184
- }
185
- body = _2_tl_js_1.Api.serializeObject(function_);
186
- }
187
- let lastErr;
188
- for (let i = 0; i < __classPrivateFieldGet(_a, _a, "f", _ClientEncrypted_SEND_MAX_TRIES); ++i) {
189
- let errored = false;
190
- try {
191
- return await this.session.send(body);
192
- }
193
- catch (err) {
194
- errored = true;
195
- lastErr = err;
196
- if (this.disconnected) {
197
- break;
134
+ if (!this.#connectionInited) {
135
+ if (!this.#apiId) {
136
+ throw new _0_errors_js_1.InputError("apiId not set");
137
+ }
138
+ function_ = {
139
+ _: "initConnection",
140
+ api_id: this.#apiId,
141
+ app_version: this.#appVersion,
142
+ device_model: this.#deviceModel,
143
+ lang_code: this.#langCode,
144
+ lang_pack: this.#langPack,
145
+ query: {
146
+ _: "invokeWithLayer",
147
+ layer: _2_tl_js_1.Api.LAYER,
148
+ query: function_,
149
+ },
150
+ system_lang_code: this.#systemLangCode,
151
+ system_version: this.#systemVersion,
152
+ };
198
153
  }
199
- __classPrivateFieldGet(this, _ClientEncrypted_L, "f").error("send failed:", err);
154
+ body = _2_tl_js_1.Api.serializeObject(function_);
200
155
  }
201
- finally {
202
- if (!errored) {
203
- __classPrivateFieldGet(this, _ClientEncrypted_L, "f").debug("invoked", (0, _0_utilities_js_1.repr)(function_));
204
- __classPrivateFieldGet(this, _ClientEncrypted_L, "f").out(function_);
156
+ let lastErr;
157
+ for (let i = 0; i < _a.#SEND_MAX_TRIES; ++i) {
158
+ let errored = false;
159
+ try {
160
+ return await this.session.send(body);
161
+ }
162
+ catch (err) {
163
+ errored = true;
164
+ lastErr = err;
165
+ if (this.disconnected) {
166
+ break;
167
+ }
168
+ this.#L.error("send failed:", err);
169
+ }
170
+ finally {
171
+ if (!errored) {
172
+ this.#L.debug("invoked", (0, _0_utilities_js_1.repr)(function_));
173
+ this.#L.out(function_);
174
+ }
205
175
  }
206
176
  }
177
+ throw new Error(`Failed to invoke function after ${_a.#SEND_MAX_TRIES} tries.`, { cause: lastErr });
207
178
  }
208
- throw new Error(`Failed to invoke function after ${__classPrivateFieldGet(_a, _a, "f", _ClientEncrypted_SEND_MAX_TRIES)} tries.`, { cause: lastErr });
209
- }, _ClientEncrypted_resend = async function _ClientEncrypted_resend(request) {
210
- try {
211
- const messageId = await __classPrivateFieldGet(this, _ClientEncrypted_instances, "m", _ClientEncrypted_send).call(this, request.call);
212
- __classPrivateFieldGet(this, _ClientEncrypted_pendingRequests, "f").set(messageId, request);
213
- }
214
- catch (err) {
215
- request.reject(err);
216
- }
217
- }, _ClientEncrypted_onUpdate = async function _ClientEncrypted_onUpdate(body) {
218
- let type;
219
- try {
220
- type = await _2_tl_js_1.Api.deserializeType(_2_tl_js_1.X, body);
221
- }
222
- catch (err) {
223
- __classPrivateFieldGet(this, _ClientEncrypted_L, "f").error("failed to deserialize update:", err);
224
- this.handlers.onDeserializationError?.();
225
- return;
226
- }
227
- if (_2_tl_js_1.Api.isOfEnum("Update", type) || _2_tl_js_1.Api.isOfEnum("Updates", type)) {
228
- this.handlers.onUpdate?.(type);
229
- }
230
- else {
231
- __classPrivateFieldGet(this, _ClientEncrypted_L, "f").warning("received unknown type:", (0, _0_utilities_js_1.repr)(type));
232
- }
233
- }, _ClientEncrypted_onNewServerSalt = function _ClientEncrypted_onNewServerSalt(serverSalt) {
234
- this.handlers.onNewServerSalt?.(serverSalt);
235
- }, _ClientEncrypted_onMessageFailed = async function _ClientEncrypted_onMessageFailed(msgId, error) {
236
- const request = __classPrivateFieldGet(this, _ClientEncrypted_pendingRequests, "f").get(msgId);
237
- if (request) {
238
- __classPrivateFieldGet(this, _ClientEncrypted_pendingRequests, "f").delete(msgId);
239
- if (error instanceof _4_session_js_1.SessionError) {
240
- await __classPrivateFieldGet(this, _ClientEncrypted_instances, "m", _ClientEncrypted_resend).call(this, request);
179
+ async #resend(request) {
180
+ try {
181
+ const messageId = await this.#send(request.call);
182
+ this.#pendingRequests.set(messageId, request);
241
183
  }
242
- else {
243
- request.reject(error);
184
+ catch (err) {
185
+ request.reject(err);
244
186
  }
245
187
  }
246
- }, _ClientEncrypted_onRpcError = async function _ClientEncrypted_onRpcError(msgId, error) {
247
- const request = __classPrivateFieldGet(this, _ClientEncrypted_pendingRequests, "f").get(msgId);
248
- if (request) {
249
- __classPrivateFieldGet(this, _ClientEncrypted_pendingRequests, "f").delete(msgId);
250
- const reason = (0, _4_errors_js_1.constructTelegramError)(error, request.call);
251
- if (reason instanceof _3_errors_js_1.ConnectionNotInited) {
252
- __classPrivateFieldSet(this, _ClientEncrypted_connectionInited, false, "f");
253
- await __classPrivateFieldGet(this, _ClientEncrypted_instances, "m", _ClientEncrypted_resend).call(this, request);
254
- }
255
- else {
256
- request.reject((0, _4_errors_js_1.constructTelegramError)(error, request.call));
257
- }
188
+ async invoke(function_) {
189
+ const messageId = await this.#send(function_);
190
+ return (await new Promise((resolve, reject) => {
191
+ this.#pendingRequests.set(messageId, { resolve, reject, call: function_ });
192
+ }));
258
193
  }
259
- }, _ClientEncrypted_onRpcResult = async function _ClientEncrypted_onRpcResult(msgId, body) {
260
- const request = __classPrivateFieldGet(this, _ClientEncrypted_pendingRequests, "f").get(msgId);
261
- if (request) {
194
+ async #onUpdate(body) {
262
195
  let type;
263
196
  try {
264
- type = await _2_tl_js_1.Api.deserializeType(_2_tl_js_1.Api.mustGetReturnType(request.call._), body);
265
- __classPrivateFieldGet(this, _ClientEncrypted_L, "f").in(type);
266
- __classPrivateFieldGet(this, _ClientEncrypted_L, "f").debug("received rpc_result", (0, _0_utilities_js_1.repr)(type));
267
- request.resolve(type);
197
+ type = await _2_tl_js_1.Api.deserializeType(_2_tl_js_1.X, body);
268
198
  }
269
199
  catch (err) {
270
- request.reject(err);
271
- __classPrivateFieldGet(this, _ClientEncrypted_L, "f").error("failed to deserialize RPC result body:", err);
200
+ this.#L.error("failed to deserialize update:", err);
272
201
  this.handlers.onDeserializationError?.();
273
202
  return;
274
203
  }
275
- finally {
276
- __classPrivateFieldGet(this, _ClientEncrypted_pendingRequests, "f").delete(msgId);
204
+ if (_2_tl_js_1.Api.isOfEnum("Update", type) || _2_tl_js_1.Api.isOfEnum("Updates", type)) {
205
+ this.handlers.onUpdate?.(type);
206
+ }
207
+ else {
208
+ this.#L.warning("received unknown type:", (0, _0_utilities_js_1.repr)(type));
277
209
  }
278
210
  }
279
- if (!__classPrivateFieldGet(this, _ClientEncrypted_connectionInited, "f")) {
280
- __classPrivateFieldSet(this, _ClientEncrypted_connectionInited, true, "f");
211
+ #onNewServerSalt(serverSalt) {
212
+ this.handlers.onNewServerSalt?.(serverSalt);
281
213
  }
282
- }, _ClientEncrypted_onPong = function _ClientEncrypted_onPong(pong) {
283
- const pendingRequest = __classPrivateFieldGet(this, _ClientEncrypted_pendingRequests, "f").get(pong.msg_id);
284
- if (pendingRequest) {
285
- pendingRequest.resolve(pong);
286
- __classPrivateFieldGet(this, _ClientEncrypted_pendingRequests, "f").delete(pong.msg_id);
214
+ async #onMessageFailed(msgId, error) {
215
+ const request = this.#pendingRequests.get(msgId);
216
+ if (request) {
217
+ this.#pendingRequests.delete(msgId);
218
+ if (error instanceof _4_session_js_1.SessionError) {
219
+ await this.#resend(request);
220
+ }
221
+ else {
222
+ request.reject(error);
223
+ }
224
+ }
287
225
  }
288
- };
289
- _ClientEncrypted_SEND_MAX_TRIES = { value: 10 };
290
- _ClientEncrypted_AUTH_KEY_CREATION_MAX_TRIES = { value: 10 };
226
+ async #onRpcError(msgId, error) {
227
+ const request = this.#pendingRequests.get(msgId);
228
+ if (request) {
229
+ this.#pendingRequests.delete(msgId);
230
+ const reason = (0, _4_errors_js_1.constructTelegramError)(error, request.call);
231
+ if (reason instanceof _3_errors_js_1.ConnectionNotInited) {
232
+ this.#connectionInited = false;
233
+ await this.#resend(request);
234
+ }
235
+ else {
236
+ request.reject((0, _4_errors_js_1.constructTelegramError)(error, request.call));
237
+ }
238
+ }
239
+ }
240
+ async #onRpcResult(msgId, body) {
241
+ const request = this.#pendingRequests.get(msgId);
242
+ if (request) {
243
+ let type;
244
+ try {
245
+ type = await _2_tl_js_1.Api.deserializeType(_2_tl_js_1.Api.mustGetReturnType(request.call._), body);
246
+ this.#L.in(type);
247
+ this.#L.debug("received rpc_result", (0, _0_utilities_js_1.repr)(type));
248
+ request.resolve(type);
249
+ }
250
+ catch (err) {
251
+ request.reject(err);
252
+ this.#L.error("failed to deserialize RPC result body:", err);
253
+ this.handlers.onDeserializationError?.();
254
+ return;
255
+ }
256
+ finally {
257
+ this.#pendingRequests.delete(msgId);
258
+ }
259
+ }
260
+ if (!this.#connectionInited) {
261
+ this.#connectionInited = true;
262
+ }
263
+ }
264
+ #onPong(pong) {
265
+ const pendingRequest = this.#pendingRequests.get(pong.msg_id);
266
+ if (pendingRequest) {
267
+ pendingRequest.resolve(pong);
268
+ this.#pendingRequests.delete(pong.msg_id);
269
+ }
270
+ }
271
+ }
272
+ exports.ClientEncrypted = ClientEncrypted;
273
+ _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"}