@mtkruto/node 0.67.1 → 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 (355) hide show
  1. package/esm/0_errors.js +2 -6
  2. package/esm/3_errors.js +2 -12
  3. package/esm/3_transport.d.ts +3 -3
  4. package/esm/3_transport.js +3 -3
  5. package/esm/3_types.d.ts +8 -7
  6. package/esm/3_types.d.ts.map +1 -1
  7. package/esm/3_types.js +8 -7
  8. package/esm/4_errors.js +2 -12
  9. package/esm/_dnt.polyfills.d.ts +99 -0
  10. package/esm/_dnt.polyfills.d.ts.map +1 -1
  11. package/esm/_dnt.polyfills.js +127 -1
  12. package/esm/_dnt.test_polyfills.d.ts.map +1 -0
  13. package/esm/client/0_filters_test.d.ts.map +1 -1
  14. package/esm/client/0_markdown_test.d.ts.map +1 -1
  15. package/esm/client/0_params.d.ts +2 -0
  16. package/esm/client/0_params.d.ts.map +1 -1
  17. package/esm/client/0_password.d.ts +5 -5
  18. package/esm/client/0_password.d.ts.map +1 -1
  19. package/esm/client/0_password_test.d.ts.map +1 -1
  20. package/esm/client/0_storage_operations.js +143 -155
  21. package/esm/client/0_storage_operations_test.d.ts.map +1 -1
  22. package/esm/client/0_utilities.d.ts +1 -1
  23. package/esm/client/0_utilities_test.d.ts.map +1 -1
  24. package/esm/client/1_client_plain.js +4 -22
  25. package/esm/client/1_composer.js +8 -21
  26. package/esm/client/2_account_manager.js +85 -97
  27. package/esm/client/2_bot_info_manager.js +26 -38
  28. package/esm/client/2_business_connection_manager.js +10 -23
  29. package/esm/client/2_client_encrypted.js +194 -211
  30. package/esm/client/2_file_manager.d.ts +4 -3
  31. package/esm/client/2_file_manager.d.ts.map +1 -1
  32. package/esm/client/2_file_manager.js +268 -224
  33. package/esm/client/2_file_manager_test.d.ts.map +1 -1
  34. package/esm/client/2_network_statistics_manager.js +8 -21
  35. package/esm/client/2_payment_manager.js +7 -20
  36. package/esm/client/2_reaction_manager.js +7 -20
  37. package/esm/client/2_translations_manager.js +97 -107
  38. package/esm/client/2_update_manager.js +764 -759
  39. package/esm/client/3_client_encrypted_pool.js +10 -26
  40. package/esm/client/3_client_encrypted_pool_test.d.ts.map +1 -1
  41. package/esm/client/3_message_manager.d.ts +1 -1
  42. package/esm/client/3_message_manager.js +441 -448
  43. package/esm/client/3_message_manager_test.d.ts.map +1 -1
  44. package/esm/client/3_video_chat_manager.d.ts +1 -1
  45. package/esm/client/3_video_chat_manager.js +57 -68
  46. package/esm/client/4_callback_query_manager.js +18 -30
  47. package/esm/client/4_chat_list_manager.js +322 -318
  48. package/esm/client/4_chat_manager.js +118 -131
  49. package/esm/client/4_forum_manager.js +67 -73
  50. package/esm/client/4_gift_manager.js +16 -29
  51. package/esm/client/4_inline_query_manager.js +16 -28
  52. package/esm/client/4_link_preview_manager.js +6 -19
  53. package/esm/client/4_poll_manager.js +44 -57
  54. package/esm/client/4_story_manager.js +41 -53
  55. package/esm/client/5_client.d.ts +7 -0
  56. package/esm/client/5_client.d.ts.map +1 -1
  57. package/esm/client/5_client.js +1271 -1290
  58. package/esm/connection/1_connection_tcp.node.js +48 -65
  59. package/esm/connection/1_connection_web_socket.js +75 -91
  60. package/esm/deps/jsr.io/@roj/tgcrypto/1.0.1/dist/tgcrypto.js +3 -11
  61. package/esm/deps/jsr.io/@std/assert/1.0.13/equals.js +4 -4
  62. package/esm/deps/jsr.io/@std/async/1.0.13/mux_async_iterator.js +31 -47
  63. package/esm/deps/jsr.io/@std/async/1.0.13/tee.js +11 -34
  64. package/esm/deps/jsr.io/@std/datetime/0.225.5/_date_time_formatter.js +4 -17
  65. package/esm/deps/jsr.io/@std/internal/1.0.10/build_message.d.ts.map +1 -0
  66. package/esm/deps/jsr.io/@std/internal/1.0.10/diff.d.ts.map +1 -0
  67. package/esm/deps/jsr.io/@std/internal/1.0.10/diff_str.d.ts.map +1 -0
  68. package/esm/deps/jsr.io/@std/internal/1.0.10/format.d.ts +29 -0
  69. package/esm/deps/jsr.io/@std/internal/1.0.10/format.d.ts.map +1 -0
  70. package/esm/deps/jsr.io/@std/internal/1.0.10/format.js +70 -0
  71. package/esm/deps/jsr.io/@std/internal/1.0.10/styles.d.ts.map +1 -0
  72. package/esm/deps/jsr.io/@std/internal/1.0.10/types.d.ts.map +1 -0
  73. package/esm/mod.js +2 -12
  74. package/esm/session/0_session_state.js +12 -38
  75. package/esm/session/1_session.js +49 -72
  76. package/esm/session/2_session_encrypted.js +324 -320
  77. package/esm/storage/1_utilities_test.d.ts.map +1 -1
  78. package/esm/storage/2_storage_indexed_db.js +26 -44
  79. package/esm/storage/2_storage_local_storage.node.js +12 -25
  80. package/esm/storage/2_storage_memory.js +24 -41
  81. package/esm/storage/2_storage_session_storage.js +3 -16
  82. package/esm/tl/0_utilities_test.d.ts.map +1 -1
  83. package/esm/tl/1_tl_reader.js +80 -88
  84. package/esm/tl/1_tl_reader_test.d.ts.map +1 -1
  85. package/esm/tl/1_tl_writer.js +155 -164
  86. package/esm/tl/1_tl_writer_test.d.ts.map +1 -1
  87. package/esm/tl/2_telegram.d.ts +9 -10
  88. package/esm/tl/2_telegram.d.ts.map +1 -1
  89. package/esm/tl/2_telegram.js +10 -10
  90. package/esm/transport/0_transport.js +1 -8
  91. package/esm/transport/1_transport_abridged.js +11 -24
  92. package/esm/transport/1_transport_intermediate.js +10 -23
  93. package/{script/transport/2_transport_provider.d.ts → esm/transport/1_transport_provider.d.ts} +1 -1
  94. package/esm/transport/{2_transport_provider.d.ts.map → 1_transport_provider.d.ts.map} +1 -1
  95. package/{script/transport/3_transport_provider_tcp.d.ts → esm/transport/2_transport_provider_tcp.d.ts} +2 -2
  96. package/esm/transport/{3_transport_provider_tcp.d.ts.map → 2_transport_provider_tcp.d.ts.map} +1 -1
  97. package/esm/transport/{3_transport_provider_tcp.js → 2_transport_provider_tcp.js} +1 -1
  98. package/esm/transport/{3_transport_provider_web_socket.d.ts → 2_transport_provider_web_socket.d.ts} +2 -2
  99. package/esm/transport/2_transport_provider_web_socket.d.ts.map +1 -0
  100. package/esm/transport/{3_transport_provider_web_socket.js → 2_transport_provider_web_socket.js} +1 -1
  101. package/esm/types/0_upload_progress.d.ts +29 -0
  102. package/esm/types/0_upload_progress.d.ts.map +1 -0
  103. package/esm/types/0_upload_progress.js +20 -0
  104. package/esm/types/{2_inline_keyboard_button.d.ts → 1_inline_keyboard_button.d.ts} +1 -1
  105. package/esm/types/{2_inline_keyboard_button.d.ts.map → 1_inline_keyboard_button.d.ts.map} +1 -1
  106. package/esm/types/1_sticker.d.ts +1 -1
  107. package/esm/types/1_sticker.d.ts.map +1 -1
  108. package/esm/types/2_chat.d.ts.map +1 -1
  109. package/esm/types/2_poll_answer.d.ts +19 -0
  110. package/esm/types/2_poll_answer.d.ts.map +1 -1
  111. package/esm/types/2_poll_answer.js +19 -0
  112. package/esm/types/2_pre_checkout_query.d.ts.map +1 -1
  113. package/esm/types/{3_reply_markup.d.ts → 2_reply_markup.d.ts} +2 -2
  114. package/esm/types/{3_reply_markup.d.ts.map → 2_reply_markup.d.ts.map} +1 -1
  115. package/esm/types/{3_reply_markup.js → 2_reply_markup.js} +1 -1
  116. package/esm/types/2_story_interactive_area.d.ts.map +1 -1
  117. package/esm/types/3_chat_member_updated.d.ts.map +1 -1
  118. package/esm/types/3_story.d.ts.map +1 -1
  119. package/esm/types/5_message.d.ts +1 -1
  120. package/esm/types/5_message.d.ts.map +1 -1
  121. package/esm/types/5_message.js +1 -1
  122. package/esm/types/6_inline_query_result.d.ts +1 -1
  123. package/esm/types/6_inline_query_result.js +1 -1
  124. package/esm/types/7_update.d.ts +21 -2
  125. package/esm/types/7_update.d.ts.map +1 -1
  126. package/esm/utilities/0_bigint_test.d.ts.map +1 -1
  127. package/esm/utilities/0_buffer.d.ts +1 -1
  128. package/esm/utilities/0_buffer.d.ts.map +1 -1
  129. package/esm/utilities/0_buffer_test.d.ts.map +1 -1
  130. package/esm/utilities/0_hash.d.ts +2 -2
  131. package/esm/utilities/0_hash.d.ts.map +1 -1
  132. package/esm/utilities/0_mutex.js +4 -19
  133. package/esm/utilities/0_part_stream.js +11 -25
  134. package/esm/utilities/0_part_stream_test.d.ts.map +1 -1
  135. package/esm/utilities/0_rle.d.ts +2 -2
  136. package/esm/utilities/0_rle.d.ts.map +1 -1
  137. package/esm/utilities/0_rle_test.d.ts.map +1 -1
  138. package/esm/utilities/0_text.d.ts +20 -1
  139. package/esm/utilities/0_text.d.ts.map +1 -1
  140. package/esm/utilities/0_text.js +19 -0
  141. package/esm/utilities/1_auth.d.ts +1 -1
  142. package/esm/utilities/1_auth.d.ts.map +1 -1
  143. package/esm/utilities/1_base64.d.ts +1 -1
  144. package/esm/utilities/1_base64.d.ts.map +1 -1
  145. package/esm/utilities/1_base64_test.d.ts.map +1 -1
  146. package/esm/utilities/1_crypto.js +42 -53
  147. package/esm/utilities/1_crypto_test.d.ts.map +1 -1
  148. package/esm/utilities/1_logger.d.ts +2 -2
  149. package/esm/utilities/1_math_test.d.ts.map +1 -1
  150. package/esm/utilities/2_queue.js +29 -47
  151. package/package.json +1 -1
  152. package/script/0_errors.js +2 -6
  153. package/script/2_tl.js +17 -7
  154. package/script/3_errors.js +2 -12
  155. package/script/3_transport.d.ts +3 -3
  156. package/script/3_transport.js +3 -3
  157. package/script/3_types.d.ts +8 -7
  158. package/script/3_types.d.ts.map +1 -1
  159. package/script/3_types.js +8 -7
  160. package/script/4_constants.js +17 -7
  161. package/script/4_errors.js +2 -12
  162. package/script/_dnt.polyfills.d.ts +99 -0
  163. package/script/_dnt.polyfills.d.ts.map +1 -1
  164. package/script/_dnt.polyfills.js +128 -0
  165. package/script/_dnt.test_polyfills.d.ts.map +1 -0
  166. package/script/client/0_filters_test.d.ts.map +1 -1
  167. package/script/client/0_markdown_test.d.ts.map +1 -1
  168. package/script/client/0_params.d.ts +2 -0
  169. package/script/client/0_params.d.ts.map +1 -1
  170. package/script/client/0_password.d.ts +5 -5
  171. package/script/client/0_password.d.ts.map +1 -1
  172. package/script/client/0_password.js +17 -7
  173. package/script/client/0_password_test.d.ts.map +1 -1
  174. package/script/client/0_storage_operations.js +143 -155
  175. package/script/client/0_storage_operations_test.d.ts.map +1 -1
  176. package/script/client/0_utilities.d.ts +1 -1
  177. package/script/client/0_utilities_test.d.ts.map +1 -1
  178. package/script/client/1_client_plain.js +4 -22
  179. package/script/client/1_composer.js +8 -21
  180. package/script/client/2_account_manager.js +85 -97
  181. package/script/client/2_bot_info_manager.js +26 -38
  182. package/script/client/2_business_connection_manager.js +10 -23
  183. package/script/client/2_client_encrypted.js +195 -212
  184. package/script/client/2_file_manager.d.ts +4 -3
  185. package/script/client/2_file_manager.d.ts.map +1 -1
  186. package/script/client/2_file_manager.js +285 -231
  187. package/script/client/2_file_manager_test.d.ts.map +1 -1
  188. package/script/client/2_network_statistics_manager.js +8 -21
  189. package/script/client/2_payment_manager.js +7 -20
  190. package/script/client/2_reaction_manager.js +7 -20
  191. package/script/client/2_translations_manager.js +98 -108
  192. package/script/client/2_update_manager.js +764 -759
  193. package/script/client/3_client_encrypted_pool.js +10 -26
  194. package/script/client/3_client_encrypted_pool_test.d.ts.map +1 -1
  195. package/script/client/3_message_manager.d.ts +1 -1
  196. package/script/client/3_message_manager.js +441 -448
  197. package/script/client/3_message_manager_test.d.ts.map +1 -1
  198. package/script/client/3_video_chat_manager.d.ts +1 -1
  199. package/script/client/3_video_chat_manager.js +57 -68
  200. package/script/client/4_callback_query_manager.js +18 -30
  201. package/script/client/4_chat_list_manager.js +322 -318
  202. package/script/client/4_chat_manager.js +118 -131
  203. package/script/client/4_forum_manager.js +67 -73
  204. package/script/client/4_gift_manager.js +16 -29
  205. package/script/client/4_inline_query_manager.js +16 -28
  206. package/script/client/4_link_preview_manager.js +6 -19
  207. package/script/client/4_poll_manager.js +44 -57
  208. package/script/client/4_story_manager.js +41 -53
  209. package/script/client/5_client.d.ts +7 -0
  210. package/script/client/5_client.d.ts.map +1 -1
  211. package/script/client/5_client.js +1271 -1290
  212. package/script/connection/1_connection_tcp.node.js +48 -65
  213. package/script/connection/1_connection_web_socket.js +92 -98
  214. package/script/deps/jsr.io/@roj/tgcrypto/1.0.1/dist/tgcrypto.js +3 -11
  215. package/script/deps/jsr.io/@std/assert/1.0.13/equal.js +17 -7
  216. package/script/deps/jsr.io/@std/assert/1.0.13/equals.js +4 -4
  217. package/script/deps/jsr.io/@std/async/1.0.13/delay.js +17 -7
  218. package/script/deps/jsr.io/@std/async/1.0.13/mux_async_iterator.js +31 -47
  219. package/script/deps/jsr.io/@std/async/1.0.13/tee.js +11 -34
  220. package/script/deps/jsr.io/@std/datetime/0.225.5/_date_time_formatter.js +4 -17
  221. package/script/deps/jsr.io/@std/internal/1.0.10/build_message.d.ts.map +1 -0
  222. package/script/deps/jsr.io/@std/internal/1.0.10/diff.d.ts.map +1 -0
  223. package/script/deps/jsr.io/@std/internal/1.0.10/diff_str.d.ts.map +1 -0
  224. package/script/deps/jsr.io/@std/internal/1.0.10/format.d.ts +29 -0
  225. package/script/deps/jsr.io/@std/internal/1.0.10/format.d.ts.map +1 -0
  226. package/script/deps/jsr.io/@std/internal/1.0.10/format.js +106 -0
  227. package/script/deps/jsr.io/@std/internal/1.0.10/styles.d.ts.map +1 -0
  228. package/script/deps/jsr.io/@std/internal/{1.0.9 → 1.0.10}/styles.js +17 -7
  229. package/script/deps/jsr.io/@std/internal/1.0.10/types.d.ts.map +1 -0
  230. package/script/deps/jsr.io/@std/path/1.1.0/_os.js +17 -7
  231. package/script/mod.js +19 -19
  232. package/script/session/0_session_state.js +12 -38
  233. package/script/session/1_session.js +66 -79
  234. package/script/session/2_session_encrypted.js +325 -321
  235. package/script/storage/1_utilities_test.d.ts.map +1 -1
  236. package/script/storage/2_storage_indexed_db.js +26 -44
  237. package/script/storage/2_storage_local_storage.node.js +12 -25
  238. package/script/storage/2_storage_memory.js +24 -41
  239. package/script/storage/2_storage_session_storage.js +3 -16
  240. package/script/tl/0_utilities_test.d.ts.map +1 -1
  241. package/script/tl/1_tl_reader.js +81 -89
  242. package/script/tl/1_tl_reader_test.d.ts.map +1 -1
  243. package/script/tl/1_tl_writer.js +156 -165
  244. package/script/tl/1_tl_writer_test.d.ts.map +1 -1
  245. package/script/tl/2_telegram.d.ts +9 -10
  246. package/script/tl/2_telegram.d.ts.map +1 -1
  247. package/script/tl/2_telegram.js +32 -10
  248. package/script/transport/0_obfuscation.js +17 -7
  249. package/script/transport/0_transport.js +1 -8
  250. package/script/transport/1_transport_abridged.js +11 -24
  251. package/script/transport/1_transport_intermediate.js +10 -23
  252. package/{esm/transport/2_transport_provider.d.ts → script/transport/1_transport_provider.d.ts} +1 -1
  253. package/script/transport/{2_transport_provider.d.ts.map → 1_transport_provider.d.ts.map} +1 -1
  254. package/{esm/transport/3_transport_provider_tcp.d.ts → script/transport/2_transport_provider_tcp.d.ts} +2 -2
  255. package/script/transport/{3_transport_provider_tcp.d.ts.map → 2_transport_provider_tcp.d.ts.map} +1 -1
  256. package/script/transport/{3_transport_provider_tcp.js → 2_transport_provider_tcp.js} +3 -3
  257. package/script/transport/{3_transport_provider_web_socket.d.ts → 2_transport_provider_web_socket.d.ts} +2 -2
  258. package/script/transport/2_transport_provider_web_socket.d.ts.map +1 -0
  259. package/script/transport/{3_transport_provider_web_socket.js → 2_transport_provider_web_socket.js} +2 -2
  260. package/script/types/0_upload_progress.d.ts +29 -0
  261. package/script/types/0_upload_progress.d.ts.map +1 -0
  262. package/script/types/0_upload_progress.js +21 -0
  263. package/script/types/{2_inline_keyboard_button.d.ts → 1_inline_keyboard_button.d.ts} +1 -1
  264. package/script/types/{2_inline_keyboard_button.d.ts.map → 1_inline_keyboard_button.d.ts.map} +1 -1
  265. package/script/types/1_sticker.d.ts +1 -1
  266. package/script/types/1_sticker.d.ts.map +1 -1
  267. package/script/types/2_chat.d.ts.map +1 -1
  268. package/script/types/2_poll_answer.d.ts +19 -0
  269. package/script/types/2_poll_answer.d.ts.map +1 -1
  270. package/script/types/2_poll_answer.js +19 -0
  271. package/script/types/2_pre_checkout_query.d.ts.map +1 -1
  272. package/script/types/{3_reply_markup.d.ts → 2_reply_markup.d.ts} +2 -2
  273. package/script/types/{3_reply_markup.d.ts.map → 2_reply_markup.d.ts.map} +1 -1
  274. package/script/types/{3_reply_markup.js → 2_reply_markup.js} +3 -3
  275. package/script/types/2_story_interactive_area.d.ts.map +1 -1
  276. package/script/types/3_chat_member_updated.d.ts.map +1 -1
  277. package/script/types/3_story.d.ts.map +1 -1
  278. package/script/types/5_message.d.ts +1 -1
  279. package/script/types/5_message.d.ts.map +1 -1
  280. package/script/types/5_message.js +2 -2
  281. package/script/types/6_inline_query_result.d.ts +1 -1
  282. package/script/types/6_inline_query_result.js +4 -4
  283. package/script/types/7_update.d.ts +21 -2
  284. package/script/types/7_update.d.ts.map +1 -1
  285. package/script/utilities/0_bigint.js +17 -7
  286. package/script/utilities/0_bigint_test.d.ts.map +1 -1
  287. package/script/utilities/0_buffer.d.ts +1 -1
  288. package/script/utilities/0_buffer.d.ts.map +1 -1
  289. package/script/utilities/0_buffer_test.d.ts.map +1 -1
  290. package/script/utilities/0_env.js +17 -7
  291. package/script/utilities/0_hash.d.ts +2 -2
  292. package/script/utilities/0_hash.d.ts.map +1 -1
  293. package/script/utilities/0_hash.js +17 -7
  294. package/script/utilities/0_misc.js +17 -7
  295. package/script/utilities/0_mutex.js +4 -19
  296. package/script/utilities/0_part_stream.js +11 -25
  297. package/script/utilities/0_part_stream_test.d.ts.map +1 -1
  298. package/script/utilities/0_rle.d.ts +2 -2
  299. package/script/utilities/0_rle.d.ts.map +1 -1
  300. package/script/utilities/0_rle_test.d.ts.map +1 -1
  301. package/script/utilities/0_text.d.ts +20 -1
  302. package/script/utilities/0_text.d.ts.map +1 -1
  303. package/script/utilities/0_text.js +19 -0
  304. package/script/utilities/1_auth.d.ts +1 -1
  305. package/script/utilities/1_auth.d.ts.map +1 -1
  306. package/script/utilities/1_auth.js +17 -7
  307. package/script/utilities/1_base64.d.ts +1 -1
  308. package/script/utilities/1_base64.d.ts.map +1 -1
  309. package/script/utilities/1_base64_test.d.ts.map +1 -1
  310. package/script/utilities/1_crypto.js +60 -61
  311. package/script/utilities/1_crypto_test.d.ts.map +1 -1
  312. package/script/utilities/1_logger.d.ts +2 -2
  313. package/script/utilities/1_math_test.d.ts.map +1 -1
  314. package/script/utilities/2_queue.js +30 -48
  315. package/esm/deps/jsr.io/@std/internal/1.0.9/build_message.d.ts.map +0 -1
  316. package/esm/deps/jsr.io/@std/internal/1.0.9/diff.d.ts.map +0 -1
  317. package/esm/deps/jsr.io/@std/internal/1.0.9/diff_str.d.ts.map +0 -1
  318. package/esm/deps/jsr.io/@std/internal/1.0.9/format.d.ts +0 -2
  319. package/esm/deps/jsr.io/@std/internal/1.0.9/format.d.ts.map +0 -1
  320. package/esm/deps/jsr.io/@std/internal/1.0.9/format.js +0 -37
  321. package/esm/deps/jsr.io/@std/internal/1.0.9/styles.d.ts.map +0 -1
  322. package/esm/deps/jsr.io/@std/internal/1.0.9/types.d.ts.map +0 -1
  323. package/esm/transport/3_transport_provider_web_socket.d.ts.map +0 -1
  324. package/script/deps/jsr.io/@std/internal/1.0.9/build_message.d.ts.map +0 -1
  325. package/script/deps/jsr.io/@std/internal/1.0.9/diff.d.ts.map +0 -1
  326. package/script/deps/jsr.io/@std/internal/1.0.9/diff_str.d.ts.map +0 -1
  327. package/script/deps/jsr.io/@std/internal/1.0.9/format.d.ts +0 -2
  328. package/script/deps/jsr.io/@std/internal/1.0.9/format.d.ts.map +0 -1
  329. package/script/deps/jsr.io/@std/internal/1.0.9/format.js +0 -63
  330. package/script/deps/jsr.io/@std/internal/1.0.9/styles.d.ts.map +0 -1
  331. package/script/deps/jsr.io/@std/internal/1.0.9/types.d.ts.map +0 -1
  332. package/script/transport/3_transport_provider_web_socket.d.ts.map +0 -1
  333. /package/esm/deps/jsr.io/@std/internal/{1.0.9 → 1.0.10}/build_message.d.ts +0 -0
  334. /package/esm/deps/jsr.io/@std/internal/{1.0.9 → 1.0.10}/build_message.js +0 -0
  335. /package/esm/deps/jsr.io/@std/internal/{1.0.9 → 1.0.10}/diff.d.ts +0 -0
  336. /package/esm/deps/jsr.io/@std/internal/{1.0.9 → 1.0.10}/diff.js +0 -0
  337. /package/esm/deps/jsr.io/@std/internal/{1.0.9 → 1.0.10}/diff_str.d.ts +0 -0
  338. /package/esm/deps/jsr.io/@std/internal/{1.0.9 → 1.0.10}/diff_str.js +0 -0
  339. /package/esm/deps/jsr.io/@std/internal/{1.0.9 → 1.0.10}/styles.d.ts +0 -0
  340. /package/esm/deps/jsr.io/@std/internal/{1.0.9 → 1.0.10}/styles.js +0 -0
  341. /package/esm/deps/jsr.io/@std/internal/{1.0.9 → 1.0.10}/types.d.ts +0 -0
  342. /package/esm/deps/jsr.io/@std/internal/{1.0.9 → 1.0.10}/types.js +0 -0
  343. /package/esm/transport/{2_transport_provider.js → 1_transport_provider.js} +0 -0
  344. /package/esm/types/{2_inline_keyboard_button.js → 1_inline_keyboard_button.js} +0 -0
  345. /package/script/deps/jsr.io/@std/internal/{1.0.9 → 1.0.10}/build_message.d.ts +0 -0
  346. /package/script/deps/jsr.io/@std/internal/{1.0.9 → 1.0.10}/build_message.js +0 -0
  347. /package/script/deps/jsr.io/@std/internal/{1.0.9 → 1.0.10}/diff.d.ts +0 -0
  348. /package/script/deps/jsr.io/@std/internal/{1.0.9 → 1.0.10}/diff.js +0 -0
  349. /package/script/deps/jsr.io/@std/internal/{1.0.9 → 1.0.10}/diff_str.d.ts +0 -0
  350. /package/script/deps/jsr.io/@std/internal/{1.0.9 → 1.0.10}/diff_str.js +0 -0
  351. /package/script/deps/jsr.io/@std/internal/{1.0.9 → 1.0.10}/styles.d.ts +0 -0
  352. /package/script/deps/jsr.io/@std/internal/{1.0.9 → 1.0.10}/types.d.ts +0 -0
  353. /package/script/deps/jsr.io/@std/internal/{1.0.9 → 1.0.10}/types.js +0 -0
  354. /package/script/transport/{2_transport_provider.js → 1_transport_provider.js} +0 -0
  355. /package/script/types/{2_inline_keyboard_button.js → 1_inline_keyboard_button.js} +0 -0
@@ -1,15 +1,4 @@
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 _FileManager_instances, _a, _FileManager_c, _FileManager_Lupload, _FileManager_UPLOAD_MAX_CHUNK_SIZE, _FileManager_DOWNLOAD_MAX_CHUNK_SIZE, _FileManager_BIG_FILE_THRESHOLD, _FileManager_uploadStream, _FileManager_uploadBuffer, _FileManager_uploadPart, _FileManager_handleError, _FileManager_getFileContents, _FileManager_CUSTOM_EMOJI_TTL;
1
+ var _a;
13
2
  /**
14
3
  * MTKruto - Cross-runtime JavaScript library for building Telegram clients
15
4
  * Copyright (C) 2023-2025 Roj <https://roj.im/>
@@ -37,39 +26,58 @@ import { Api } from "../2_tl.js";
37
26
  import { getDc } from "../3_transport.js";
38
27
  import { constructSticker, deserializeFileId, FileType, PhotoSourceType, serializeFileId, toUniqueFileId } from "../3_types.js";
39
28
  import { STICKER_SET_NAME_TTL } from "../4_constants.js";
29
+ import { StickersetInvalid } from "../4_errors.js";
40
30
  import { UPLOAD_REQUEST_PER_CONNECTION } from "./0_utilities.js";
41
31
  export class FileManager {
32
+ #c;
33
+ #Lupload;
34
+ static #UPLOAD_MAX_CHUNK_SIZE = 512 * kilobyte;
35
+ static #DOWNLOAD_MAX_CHUNK_SIZE = 1 * megabyte;
36
+ static #BIG_FILE_THRESHOLD = 10 * megabyte;
42
37
  constructor(c) {
43
- _FileManager_instances.add(this);
44
- _FileManager_c.set(this, void 0);
45
- _FileManager_Lupload.set(this, void 0);
46
- __classPrivateFieldSet(this, _FileManager_c, c, "f");
38
+ this.#c = c;
47
39
  const L = getLogger("FileManager").client(c.id);
48
- __classPrivateFieldSet(this, _FileManager_Lupload, L.branch("upload"), "f");
40
+ this.#Lupload = L.branch("upload");
41
+ }
42
+ #progressIds = new Set();
43
+ getProgressId() {
44
+ let id;
45
+ do {
46
+ id = getRandomId();
47
+ } while (id === 0n || this.#progressIds.has(id));
48
+ this.#progressIds.add(id);
49
+ return Promise.resolve(String(id));
49
50
  }
50
51
  async upload(file, params, checkName, allowStream = true) {
51
- let { size, name, contents } = await __classPrivateFieldGet(_a, _a, "m", _FileManager_getFileContents).call(_a, file, params, allowStream);
52
+ if (params?.progressId !== undefined && !this.#progressIds.has(BigInt(params.progressId))) {
53
+ throw new InputError("Invalid progressId.");
54
+ }
55
+ if (params?.progressId !== undefined) {
56
+ this.#progressIds.delete(BigInt(params.progressId));
57
+ }
58
+ let { size, name, contents } = await _a.#getFileContents(file, params, allowStream);
52
59
  if (checkName) {
53
60
  name = checkName(name);
54
61
  }
55
62
  if (size == 0 || size < -1) {
56
63
  throw new InputError("Invalid file size.");
57
64
  }
58
- const poolSize = await __classPrivateFieldGet(this, _FileManager_c, "f").getUploadPoolSize();
59
- const chunkSize = params?.chunkSize ?? __classPrivateFieldGet(_a, _a, "f", _FileManager_UPLOAD_MAX_CHUNK_SIZE);
60
- _a.validateChunkSize(chunkSize, __classPrivateFieldGet(_a, _a, "f", _FileManager_UPLOAD_MAX_CHUNK_SIZE));
61
- const fileId = getRandomId();
62
- const isBig = contents instanceof Uint8Array ? contents.length > __classPrivateFieldGet(_a, _a, "f", _FileManager_BIG_FILE_THRESHOLD) : true;
65
+ const poolSize = await this.#c.getUploadPoolSize();
66
+ const chunkSize = params?.chunkSize ?? _a.#UPLOAD_MAX_CHUNK_SIZE;
67
+ _a.validateChunkSize(chunkSize, _a.#UPLOAD_MAX_CHUNK_SIZE);
68
+ const mustTrackProgress = params?.progressId !== undefined;
69
+ const fileId = params?.progressId !== undefined ? BigInt(params.progressId) : getRandomId();
70
+ const isBig = contents instanceof Uint8Array ? contents.length > _a.#BIG_FILE_THRESHOLD : true;
63
71
  const whatIsUploaded = contents instanceof Uint8Array ? (isBig ? "big file" : "file") + " of size " + size : "stream";
64
- __classPrivateFieldGet(this, _FileManager_Lupload, "f").debug("uploading " + whatIsUploaded + " with chunk size of " + chunkSize + " and pool size of " + poolSize + " and file ID of " + fileId);
72
+ this.#Lupload.debug("uploading " + whatIsUploaded + " with chunk size of " + chunkSize + " and pool size of " + poolSize + " and file ID of " + fileId);
65
73
  let result;
66
74
  if (contents instanceof Uint8Array) {
67
- result = await __classPrivateFieldGet(this, _FileManager_instances, "m", _FileManager_uploadBuffer).call(this, contents, fileId, chunkSize, poolSize, params?.signal);
75
+ result = await this.#uploadBuffer(contents, fileId, mustTrackProgress, chunkSize, poolSize, params?.signal);
68
76
  }
69
77
  else {
70
- result = await __classPrivateFieldGet(this, _FileManager_instances, "m", _FileManager_uploadStream).call(this, contents, fileId, chunkSize, poolSize, params?.signal);
78
+ result = await this.#uploadStream(contents, fileId, mustTrackProgress, chunkSize, poolSize, params?.signal);
71
79
  }
72
- __classPrivateFieldGet(this, _FileManager_Lupload, "f").debug(`[${fileId}] uploaded ` + result.parts + " part(s)");
80
+ this.#Lupload.debug(`[${fileId}] uploaded ` + result.parts + " part(s)");
73
81
  if (result.small) {
74
82
  return { _: "inputFile", id: fileId, name, parts: result.parts, md5_checksum: "" };
75
83
  }
@@ -77,20 +85,222 @@ export class FileManager {
77
85
  return { _: "inputFileBig", id: fileId, name, parts: result.parts };
78
86
  }
79
87
  }
88
+ async #uploadStream(stream, fileId, mustTrackProgress, chunkSize, poolSize, signal) {
89
+ let part;
90
+ let promises = new Array();
91
+ let ms = 0.05;
92
+ let uploaded = 0;
93
+ for await (part of iterateReadableStream(stream.pipeThrough(new PartStream(chunkSize)))) {
94
+ if (!part.small && part.part > 0) {
95
+ await delay(ms);
96
+ ms = Math.max(ms * .8, 0.003);
97
+ }
98
+ promises.push(this.#uploadPart(fileId, part.totalParts, !part.small, part.part, part.bytes, signal).then(() => {
99
+ if (mustTrackProgress) {
100
+ uploaded += part.bytes.length;
101
+ this.#c.handleUpdate({
102
+ uploadProgress: {
103
+ id: String(fileId),
104
+ uploaded,
105
+ total: 0,
106
+ },
107
+ });
108
+ }
109
+ }));
110
+ if (promises.length == poolSize * UPLOAD_REQUEST_PER_CONNECTION) {
111
+ await Promise.all(promises);
112
+ promises = [];
113
+ }
114
+ }
115
+ await Promise.all(promises);
116
+ return { small: part.small, parts: part.totalParts };
117
+ }
118
+ async #uploadBuffer(buffer, fileId, mustTrackProgress, chunkSize, poolSize, signal) {
119
+ const isBig = buffer.byteLength > _a.#BIG_FILE_THRESHOLD;
120
+ const partCount = Math.ceil(buffer.byteLength / chunkSize);
121
+ let promises = new Array();
122
+ let started = false;
123
+ let ms = 0.05;
124
+ let uploaded = 0;
125
+ main: for (let part = 0; part < partCount;) {
126
+ for (let i = 0; i < poolSize; ++i) {
127
+ for (let i = 0; i < UPLOAD_REQUEST_PER_CONNECTION; ++i) {
128
+ const start = part * chunkSize;
129
+ const end = start + chunkSize;
130
+ const bytes = buffer.subarray(start, end);
131
+ if (!bytes.length) {
132
+ break main;
133
+ }
134
+ if (!started) {
135
+ started = true;
136
+ }
137
+ else if (isBig && part > 0) {
138
+ await delay(ms);
139
+ ms = Math.max(ms * .8, 0.003);
140
+ }
141
+ promises.push(this.#uploadPart(fileId, partCount, isBig, part++, bytes, signal).then(() => {
142
+ if (mustTrackProgress) {
143
+ uploaded += bytes.length;
144
+ this.#c.handleUpdate({
145
+ uploadProgress: {
146
+ id: String(fileId),
147
+ uploaded,
148
+ total: buffer.length,
149
+ },
150
+ });
151
+ }
152
+ }));
153
+ if (promises.length == poolSize * UPLOAD_REQUEST_PER_CONNECTION) {
154
+ await Promise.all(promises);
155
+ promises = [];
156
+ }
157
+ }
158
+ }
159
+ await Promise.all(promises);
160
+ promises = [];
161
+ }
162
+ await Promise.all(promises);
163
+ return { small: !isBig, parts: partCount };
164
+ }
165
+ async #uploadPart(fileId, partCount, isBig, index, bytes, signal) {
166
+ let retryIn = 1;
167
+ let errorCount = 0;
168
+ while (true) {
169
+ try {
170
+ signal?.throwIfAborted();
171
+ this.#Lupload.debug(`[${fileId}] uploading part ` + (index + 1));
172
+ if (isBig) {
173
+ await this.#c.invoke({ _: "upload.saveBigFilePart", file_id: fileId, file_part: index, bytes: bytes, file_total_parts: partCount }, { type: "upload" });
174
+ }
175
+ else {
176
+ await this.#c.invoke({ _: "upload.saveFilePart", file_id: fileId, bytes: bytes, file_part: index }, { type: "upload" });
177
+ }
178
+ this.#Lupload.debug(`[${fileId}] uploaded part ` + (index + 1));
179
+ break;
180
+ }
181
+ catch (err) {
182
+ signal?.throwIfAborted();
183
+ this.#Lupload.debug(`[${fileId}] failed to upload part ` + (index + 1));
184
+ ++errorCount;
185
+ if (errorCount > 20) {
186
+ retryIn = 0;
187
+ errorCount = 20;
188
+ }
189
+ await this.#handleError(err, retryIn, `[${fileId}-${index + 1}]`);
190
+ retryIn += 2;
191
+ if (retryIn > 11) {
192
+ retryIn = 11;
193
+ }
194
+ }
195
+ }
196
+ }
197
+ async #handleError(err, retryIn, logPrefix) {
198
+ if (retryIn > 0) {
199
+ this.#Lupload.warning(`${logPrefix} retrying in ${retryIn} seconds`);
200
+ await delay(retryIn * SECOND);
201
+ }
202
+ else {
203
+ throw err;
204
+ }
205
+ }
206
+ static async #getFileContents(source, params, allowStream) {
207
+ let name = params?.fileName?.trim() || "file";
208
+ let contents;
209
+ let size = -1;
210
+ if (source instanceof Uint8Array) {
211
+ contents = source;
212
+ size = source.byteLength;
213
+ }
214
+ else if (source instanceof ReadableStream) {
215
+ if (!allowStream) {
216
+ throw new InputError("Streamed upload not allowed.");
217
+ }
218
+ contents = source;
219
+ }
220
+ else if (typeof source === "object" && source != null && (Symbol.iterator in source || Symbol.asyncIterator in source)) {
221
+ if (!allowStream) {
222
+ throw new InputError("Streamed upload not allowed.");
223
+ }
224
+ contents = new ReadableStream({
225
+ pull: Symbol.asyncIterator in source
226
+ ? async (controller) => {
227
+ const { value, done } = await source.next();
228
+ done ? controller.close() : controller.enqueue(value);
229
+ }
230
+ : (controller) => {
231
+ const { value, done } = source.next();
232
+ done ? controller.close() : controller.enqueue(value);
233
+ },
234
+ });
235
+ }
236
+ else {
237
+ let url;
238
+ try {
239
+ url = new URL(source).toString();
240
+ }
241
+ catch {
242
+ let path_;
243
+ if (typeof source === "string") {
244
+ if (isAbsolute(source)) {
245
+ path_ = source;
246
+ }
247
+ else {
248
+ // @ts-ignore: lib
249
+ path_ = join(dntShim.Deno.cwd(), source);
250
+ }
251
+ url = toFileUrl(path_).toString();
252
+ name = basename(path_);
253
+ }
254
+ else {
255
+ unreachable();
256
+ }
257
+ }
258
+ const response = await fetch(url);
259
+ if (response.body == null) {
260
+ throw new InputError("Invalid response");
261
+ }
262
+ if (name == "file") {
263
+ const contentType = response.headers.get("content-type")?.split(";")[0].trim();
264
+ if (contentType) {
265
+ name += extension(contentType);
266
+ }
267
+ else {
268
+ const maybeFileName = new URL(response.url).pathname.split("/")
269
+ .filter((v) => v)
270
+ .slice(-1)[0]
271
+ .trim();
272
+ if (maybeFileName) {
273
+ name += extension(extname(maybeFileName));
274
+ }
275
+ }
276
+ }
277
+ const contentLength = Number(response.headers.get("content-length"));
278
+ if (!isNaN(contentLength)) {
279
+ size = contentLength;
280
+ }
281
+ if (allowStream) {
282
+ contents = response.body;
283
+ }
284
+ else {
285
+ contents = new Uint8Array(await response.arrayBuffer());
286
+ }
287
+ }
288
+ return { size: params?.fileSize ? params.fileSize : size, name, contents };
289
+ }
80
290
  async *downloadInner(location, dcId, params) {
81
291
  const signal = params?.signal;
82
292
  signal?.throwIfAborted();
83
293
  const id = "id" in location ? location.id : "photo_id" in location ? location.photo_id : null;
84
- if (id != null && __classPrivateFieldGet(this, _FileManager_c, "f").storage.supportsFiles) {
85
- const file = await __classPrivateFieldGet(this, _FileManager_c, "f").storage.getFile(id);
294
+ if (id != null && this.#c.storage.supportsFiles) {
295
+ const file = await this.#c.storage.getFile(id);
86
296
  const partOffset = file == null ? 0 : params?.offset ? Math.ceil(10 / file[1]) - 1 : 0;
87
297
  if (file != null && file[0] > 0) {
88
- yield* __classPrivateFieldGet(this, _FileManager_c, "f").storage.iterFileParts(id, file[0], partOffset, signal);
298
+ yield* this.#c.storage.iterFileParts(id, file[0], partOffset, signal);
89
299
  return;
90
300
  }
91
301
  }
92
- const chunkSize = params?.chunkSize ?? __classPrivateFieldGet(_a, _a, "f", _FileManager_DOWNLOAD_MAX_CHUNK_SIZE);
93
- _a.validateChunkSize(chunkSize, __classPrivateFieldGet(_a, _a, "f", _FileManager_DOWNLOAD_MAX_CHUNK_SIZE));
302
+ const chunkSize = params?.chunkSize ?? _a.#DOWNLOAD_MAX_CHUNK_SIZE;
303
+ _a.validateChunkSize(chunkSize, _a.#DOWNLOAD_MAX_CHUNK_SIZE);
94
304
  if (params?.offset !== undefined) {
95
305
  _a.validateOffset(params.offset);
96
306
  }
@@ -105,18 +315,18 @@ export class FileManager {
105
315
  let retryIn = 1;
106
316
  let errorCount = 0;
107
317
  try {
108
- const file = await __classPrivateFieldGet(this, _FileManager_c, "f").invoke({ _: "upload.getFile", location, offset, limit }, { dc, type: "download" });
318
+ const file = await this.#c.invoke({ _: "upload.getFile", location, offset, limit }, { dc, type: "download" });
109
319
  signal?.throwIfAborted();
110
320
  if (Api.is("upload.file", file)) {
111
321
  yield file.bytes;
112
322
  if (id != null) {
113
- await __classPrivateFieldGet(this, _FileManager_c, "f").storage.saveFilePart(id, part, file.bytes);
323
+ await this.#c.storage.saveFilePart(id, part, file.bytes);
114
324
  signal?.throwIfAborted();
115
325
  }
116
326
  ++part;
117
327
  if (file.bytes.length < limit) {
118
328
  if (id != null) {
119
- await __classPrivateFieldGet(this, _FileManager_c, "f").storage.setFilePartCount(id, part + 1, chunkSize);
329
+ await this.#c.storage.setFilePartCount(id, part + 1, chunkSize);
120
330
  signal?.throwIfAborted();
121
331
  }
122
332
  break;
@@ -140,7 +350,7 @@ export class FileManager {
140
350
  retryIn = 0;
141
351
  errorCount = 0;
142
352
  }
143
- await __classPrivateFieldGet(this, _FileManager_instances, "m", _FileManager_handleError).call(this, err, retryIn, `[${id}-${part + 1}]`);
353
+ await this.#handleError(err, retryIn, `[${id}-${part + 1}]`);
144
354
  signal?.throwIfAborted();
145
355
  retryIn += 2;
146
356
  if (retryIn > 11) {
@@ -183,7 +393,7 @@ export class FileManager {
183
393
  unreachable();
184
394
  }
185
395
  const big = fileId_.location.source.type == PhotoSourceType.ChatPhotoBig;
186
- const peer = await __classPrivateFieldGet(this, _FileManager_c, "f").getInputPeer(Number(fileId_.location.source.chatId));
396
+ const peer = await this.#c.getInputPeer(Number(fileId_.location.source.chatId));
187
397
  const location = { _: "inputPeerPhotoFileLocation", big: big ? true : undefined, peer, photo_id: fileId_.location.id };
188
398
  yield* this.downloadInner(location, fileId_.dcId, params);
189
399
  break;
@@ -227,17 +437,28 @@ export class FileManager {
227
437
  }
228
438
  }
229
439
  async getStickerSetName(inputStickerSet, hash = 0) {
230
- const maybeStickerSetName = await __classPrivateFieldGet(this, _FileManager_c, "f").messageStorage.getStickerSetName(inputStickerSet.id, inputStickerSet.access_hash);
440
+ const maybeStickerSetName = await this.#c.messageStorage.getStickerSetName(inputStickerSet.id, inputStickerSet.access_hash);
231
441
  if (maybeStickerSetName != null && Date.now() - maybeStickerSetName[1].getTime() < STICKER_SET_NAME_TTL) {
232
442
  return maybeStickerSetName[0];
233
443
  }
234
444
  else {
235
- const stickerSet = await __classPrivateFieldGet(this, _FileManager_c, "f").invoke({ _: "messages.getStickerSet", stickerset: inputStickerSet, hash });
236
- const name = Api.as("messages.stickerSet", stickerSet).set.short_name;
237
- await __classPrivateFieldGet(this, _FileManager_c, "f").messageStorage.updateStickerSetName(inputStickerSet.id, inputStickerSet.access_hash, name);
238
- return name;
445
+ try {
446
+ const stickerSet = await this.#c.invoke({ _: "messages.getStickerSet", stickerset: inputStickerSet, hash });
447
+ const name = Api.as("messages.stickerSet", stickerSet).set.short_name;
448
+ await this.#c.messageStorage.updateStickerSetName(inputStickerSet.id, inputStickerSet.access_hash, name);
449
+ return name;
450
+ }
451
+ catch (err) {
452
+ if (err instanceof StickersetInvalid) {
453
+ return undefined;
454
+ }
455
+ else {
456
+ throw err;
457
+ }
458
+ }
239
459
  }
240
460
  }
461
+ static #CUSTOM_EMOJI_TTL = 30 * MINUTE;
241
462
  async getCustomEmojiStickers(id) {
242
463
  id = Array.isArray(id) ? id : [id];
243
464
  if (!id.length) {
@@ -246,8 +467,8 @@ export class FileManager {
246
467
  const stickers = new Array();
247
468
  let shouldFetch = false;
248
469
  for (const id_ of id) {
249
- const maybeDocument = await __classPrivateFieldGet(this, _FileManager_c, "f").messageStorage.getCustomEmojiDocument(BigInt(id_));
250
- if (maybeDocument != null && Date.now() - maybeDocument[1].getTime() <= __classPrivateFieldGet(_a, _a, "f", _FileManager_CUSTOM_EMOJI_TTL)) {
470
+ const maybeDocument = await this.#c.messageStorage.getCustomEmojiDocument(BigInt(id_));
471
+ if (maybeDocument != null && Date.now() - maybeDocument[1].getTime() <= _a.#CUSTOM_EMOJI_TTL) {
251
472
  const document_ = maybeDocument[0];
252
473
  const fileId_ = {
253
474
  type: FileType.Document,
@@ -268,9 +489,9 @@ export class FileManager {
268
489
  if (!shouldFetch) {
269
490
  return stickers;
270
491
  }
271
- const documents_ = (await __classPrivateFieldGet(this, _FileManager_c, "f").invoke({ _: "messages.getCustomEmojiDocuments", document_id: id.map(BigInt) })).map((v) => Api.as("document", v));
492
+ const documents_ = (await this.#c.invoke({ _: "messages.getCustomEmojiDocuments", document_id: id.map(BigInt) })).map((v) => Api.as("document", v));
272
493
  for (const [i, document_] of documents_.entries()) {
273
- await __classPrivateFieldGet(this, _FileManager_c, "f").messageStorage.setCustomEmojiDocument(document_.id, document_);
494
+ await this.#c.messageStorage.setCustomEmojiDocument(document_.id, document_);
274
495
  const fileId_ = {
275
496
  type: FileType.Document,
276
497
  dcId: document_.dc_id,
@@ -285,181 +506,4 @@ export class FileManager {
285
506
  return stickers;
286
507
  }
287
508
  }
288
- _a = FileManager, _FileManager_c = new WeakMap(), _FileManager_Lupload = new WeakMap(), _FileManager_instances = new WeakSet(), _FileManager_uploadStream = async function _FileManager_uploadStream(stream, fileId, chunkSize, poolSize, signal) {
289
- let part;
290
- let promises = new Array();
291
- let ms = 0.05;
292
- for await (part of iterateReadableStream(stream.pipeThrough(new PartStream(chunkSize)))) {
293
- if (!part.small && part.part > 0) {
294
- await delay(ms);
295
- ms = Math.max(ms * .8, 0.003);
296
- }
297
- promises.push(__classPrivateFieldGet(this, _FileManager_instances, "m", _FileManager_uploadPart).call(this, fileId, part.totalParts, !part.small, part.part, part.bytes, signal));
298
- if (promises.length == poolSize * UPLOAD_REQUEST_PER_CONNECTION) {
299
- await Promise.all(promises);
300
- promises = [];
301
- }
302
- }
303
- await Promise.all(promises);
304
- return { small: part.small, parts: part.totalParts };
305
- }, _FileManager_uploadBuffer = async function _FileManager_uploadBuffer(buffer, fileId, chunkSize, poolSize, signal) {
306
- const isBig = buffer.byteLength > __classPrivateFieldGet(_a, _a, "f", _FileManager_BIG_FILE_THRESHOLD);
307
- const partCount = Math.ceil(buffer.byteLength / chunkSize);
308
- let promises = new Array();
309
- let started = false;
310
- let ms = 0.05;
311
- main: for (let part = 0; part < partCount;) {
312
- for (let i = 0; i < poolSize; ++i) {
313
- for (let i = 0; i < UPLOAD_REQUEST_PER_CONNECTION; ++i) {
314
- const start = part * chunkSize;
315
- const end = start + chunkSize;
316
- const bytes = buffer.subarray(start, end);
317
- if (!bytes.length) {
318
- break main;
319
- }
320
- if (!started) {
321
- started = true;
322
- }
323
- else if (isBig && part > 0) {
324
- await delay(ms);
325
- ms = Math.max(ms * .8, 0.003);
326
- }
327
- promises.push(__classPrivateFieldGet(this, _FileManager_instances, "m", _FileManager_uploadPart).call(this, fileId, partCount, isBig, part++, bytes, signal));
328
- if (promises.length == poolSize * UPLOAD_REQUEST_PER_CONNECTION) {
329
- await Promise.all(promises);
330
- promises = [];
331
- }
332
- }
333
- }
334
- await Promise.all(promises);
335
- promises = [];
336
- }
337
- await Promise.all(promises);
338
- return { small: !isBig, parts: partCount };
339
- }, _FileManager_uploadPart = async function _FileManager_uploadPart(fileId, partCount, isBig, index, bytes, signal) {
340
- let retryIn = 1;
341
- let errorCount = 0;
342
- while (true) {
343
- try {
344
- signal?.throwIfAborted();
345
- __classPrivateFieldGet(this, _FileManager_Lupload, "f").debug(`[${fileId}] uploading part ` + (index + 1));
346
- if (isBig) {
347
- await __classPrivateFieldGet(this, _FileManager_c, "f").invoke({ _: "upload.saveBigFilePart", file_id: fileId, file_part: index, bytes: bytes, file_total_parts: partCount }, { type: "upload" });
348
- }
349
- else {
350
- await __classPrivateFieldGet(this, _FileManager_c, "f").invoke({ _: "upload.saveFilePart", file_id: fileId, bytes: bytes, file_part: index }, { type: "upload" });
351
- }
352
- __classPrivateFieldGet(this, _FileManager_Lupload, "f").debug(`[${fileId}] uploaded part ` + (index + 1));
353
- break;
354
- }
355
- catch (err) {
356
- signal?.throwIfAborted();
357
- __classPrivateFieldGet(this, _FileManager_Lupload, "f").debug(`[${fileId}] failed to upload part ` + (index + 1));
358
- ++errorCount;
359
- if (errorCount > 20) {
360
- retryIn = 0;
361
- errorCount = 20;
362
- }
363
- await __classPrivateFieldGet(this, _FileManager_instances, "m", _FileManager_handleError).call(this, err, retryIn, `[${fileId}-${index + 1}]`);
364
- retryIn += 2;
365
- if (retryIn > 11) {
366
- retryIn = 11;
367
- }
368
- }
369
- }
370
- }, _FileManager_handleError = async function _FileManager_handleError(err, retryIn, logPrefix) {
371
- if (retryIn > 0) {
372
- __classPrivateFieldGet(this, _FileManager_Lupload, "f").warning(`${logPrefix} retrying in ${retryIn} seconds`);
373
- await delay(retryIn * SECOND);
374
- }
375
- else {
376
- throw err;
377
- }
378
- }, _FileManager_getFileContents = async function _FileManager_getFileContents(source, params, allowStream) {
379
- let name = params?.fileName?.trim() || "file";
380
- let contents;
381
- let size = -1;
382
- if (source instanceof Uint8Array) {
383
- contents = source;
384
- size = source.byteLength;
385
- }
386
- else if (source instanceof ReadableStream) {
387
- if (!allowStream) {
388
- throw new InputError("Streamed upload not allowed.");
389
- }
390
- contents = source;
391
- }
392
- else if (typeof source === "object" && source != null && (Symbol.iterator in source || Symbol.asyncIterator in source)) {
393
- if (!allowStream) {
394
- throw new InputError("Streamed upload not allowed.");
395
- }
396
- contents = new ReadableStream({
397
- pull: Symbol.asyncIterator in source
398
- ? async (controller) => {
399
- const { value, done } = await source.next();
400
- done ? controller.close() : controller.enqueue(value);
401
- }
402
- : (controller) => {
403
- const { value, done } = source.next();
404
- done ? controller.close() : controller.enqueue(value);
405
- },
406
- });
407
- }
408
- else {
409
- let url;
410
- try {
411
- url = new URL(source).toString();
412
- }
413
- catch {
414
- let path_;
415
- if (typeof source === "string") {
416
- if (isAbsolute(source)) {
417
- path_ = source;
418
- }
419
- else {
420
- // @ts-ignore: lib
421
- path_ = join(dntShim.Deno.cwd(), source);
422
- }
423
- url = toFileUrl(path_).toString();
424
- name = basename(path_);
425
- }
426
- else {
427
- unreachable();
428
- }
429
- }
430
- const response = await fetch(url);
431
- if (response.body == null) {
432
- throw new InputError("Invalid response");
433
- }
434
- if (name == "file") {
435
- const contentType = response.headers.get("content-type")?.split(";")[0].trim();
436
- if (contentType) {
437
- name += extension(contentType);
438
- }
439
- else {
440
- const maybeFileName = new URL(response.url).pathname.split("/")
441
- .filter((v) => v)
442
- .slice(-1)[0]
443
- .trim();
444
- if (maybeFileName) {
445
- name += extension(extname(maybeFileName));
446
- }
447
- }
448
- }
449
- const contentLength = Number(response.headers.get("content-length"));
450
- if (!isNaN(contentLength)) {
451
- size = contentLength;
452
- }
453
- if (allowStream) {
454
- contents = response.body;
455
- }
456
- else {
457
- contents = new Uint8Array(await response.arrayBuffer());
458
- }
459
- }
460
- return { size: params?.fileSize ? params.fileSize : size, name, contents };
461
- };
462
- _FileManager_UPLOAD_MAX_CHUNK_SIZE = { value: 512 * kilobyte };
463
- _FileManager_DOWNLOAD_MAX_CHUNK_SIZE = { value: 1 * megabyte };
464
- _FileManager_BIG_FILE_THRESHOLD = { value: 10 * megabyte };
465
- _FileManager_CUSTOM_EMOJI_TTL = { value: 30 * MINUTE };
509
+ _a = FileManager;
@@ -1 +1 @@
1
- {"version":3,"file":"2_file_manager_test.d.ts","sourceRoot":"","sources":["../../src/client/2_file_manager_test.ts"],"names":[],"mappings":""}
1
+ {"version":3,"file":"2_file_manager_test.d.ts","sourceRoot":"","sources":["../../src/client/2_file_manager_test.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AACH,OAAO,2BAA2B,CAAC"}
@@ -17,29 +17,17 @@
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 _NetworkStatisticsManager_c;
32
20
  export class NetworkStatisticsManager {
21
+ #c;
33
22
  constructor(c) {
34
- _NetworkStatisticsManager_c.set(this, void 0);
35
- __classPrivateFieldSet(this, _NetworkStatisticsManager_c, c, "f");
23
+ this.#c = c;
36
24
  }
37
25
  async getNetworkStatistics() {
38
26
  const [messagesRead, messagesWrite, cdnRead, cdnWrite] = await Promise.all([
39
- __classPrivateFieldGet(this, _NetworkStatisticsManager_c, "f").storage.get(["netstat_messages_read"]),
40
- __classPrivateFieldGet(this, _NetworkStatisticsManager_c, "f").storage.get(["netstat_messages_write"]),
41
- __classPrivateFieldGet(this, _NetworkStatisticsManager_c, "f").storage.get(["netstat_cdn_read"]),
42
- __classPrivateFieldGet(this, _NetworkStatisticsManager_c, "f").storage.get(["netstat_cdn_write"]),
27
+ this.#c.storage.get(["netstat_messages_read"]),
28
+ this.#c.storage.get(["netstat_messages_write"]),
29
+ this.#c.storage.get(["netstat_cdn_read"]),
30
+ this.#c.storage.get(["netstat_cdn_write"]),
43
31
  ]);
44
32
  const messages = {
45
33
  sent: Number(messagesWrite || 0),
@@ -55,13 +43,12 @@ export class NetworkStatisticsManager {
55
43
  return {
56
44
  read: async (count) => {
57
45
  const key = cdn ? "netstat_cdn_read" : "netstat_messages_read";
58
- await __classPrivateFieldGet(this, _NetworkStatisticsManager_c, "f").storage.incr([key], count);
46
+ await this.#c.storage.incr([key], count);
59
47
  },
60
48
  write: async (count) => {
61
49
  const key = cdn ? "netstat_cdn_write" : "netstat_messages_write";
62
- await __classPrivateFieldGet(this, _NetworkStatisticsManager_c, "f").storage.incr([key], count);
50
+ await this.#c.storage.incr([key], count);
63
51
  },
64
52
  };
65
53
  }
66
54
  }
67
- _NetworkStatisticsManager_c = new WeakMap();