@mtkruto/node 0.1.139 → 0.1.140

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 (287) hide show
  1. package/esm/3_types.d.ts +10 -36
  2. package/esm/3_types.js +10 -36
  3. package/esm/4_constants.d.ts +1 -1
  4. package/esm/4_constants.js +1 -1
  5. package/esm/5_client.d.ts +1 -1
  6. package/esm/5_client.js +1 -1
  7. package/esm/_dnt.polyfills.d.ts +6 -0
  8. package/esm/client/0_filters.d.ts +60 -0
  9. package/esm/client/0_filters.js +27 -0
  10. package/esm/client/0_message.js +2 -2
  11. package/esm/client/{3_params.d.ts → 0_params.d.ts} +30 -33
  12. package/esm/client/0_types.d.ts +39 -0
  13. package/esm/client/0_types.js +2 -0
  14. package/esm/client/0_utilities.d.ts +1 -47
  15. package/esm/client/0_utilities.js +0 -27
  16. package/esm/client/1_composer.d.ts +1 -1
  17. package/esm/client/1_composer.js +1 -1
  18. package/esm/client/1_file_manager.d.ts +10 -0
  19. package/esm/client/1_file_manager.js +241 -0
  20. package/esm/client/1_update_manager.d.ts +18 -0
  21. package/esm/client/1_update_manager.js +553 -0
  22. package/esm/client/2_message_manager.d.ts +40 -0
  23. package/esm/client/2_message_manager.js +621 -0
  24. package/esm/client/3_chat_list_manager.d.ts +21 -0
  25. package/esm/client/3_chat_list_manager.js +353 -0
  26. package/esm/client/3_reaction_manager.d.ts +16 -0
  27. package/esm/client/3_reaction_manager.js +61 -0
  28. package/esm/client/4_client.d.ts +187 -60
  29. package/esm/client/4_client.js +492 -1698
  30. package/esm/connection/1_connection_web_socket.js +6 -6
  31. package/esm/deps/raw.githubusercontent.com/MTKruto/debug/main/deps.d.ts +1 -1
  32. package/esm/deps/raw.githubusercontent.com/MTKruto/debug/main/deps.js +1 -1
  33. package/esm/deps/raw.githubusercontent.com/MTKruto/object-inspect/main/index.d.ts +1 -0
  34. package/esm/deps/raw.githubusercontent.com/MTKruto/object-inspect/main/index.js +524 -0
  35. package/esm/mod.d.ts +1 -0
  36. package/esm/mod.js +1 -0
  37. package/esm/storage/0_storage.d.ts +5 -3
  38. package/esm/storage/0_storage.js +14 -4
  39. package/esm/tl/1_tl_object.d.ts +1 -0
  40. package/esm/tl/1_tl_object.js +24 -0
  41. package/esm/types/0_bot_command.d.ts +1 -0
  42. package/esm/types/0_chat_member_rights.d.ts +37 -0
  43. package/esm/types/0_chat_photo.d.ts +4 -4
  44. package/esm/types/0_file_source.d.ts +5 -0
  45. package/esm/types/0_giveaway_parameters.js +2 -1
  46. package/esm/types/0_id.d.ts +4 -0
  47. package/esm/types/0_message_entity.d.ts +20 -20
  48. package/esm/types/1__getters.d.ts +2 -2
  49. package/esm/types/1_animation.d.ts +1 -1
  50. package/esm/types/1_bot_command_scope.d.ts +5 -4
  51. package/esm/types/1_chat_p.d.ts +5 -6
  52. package/esm/types/1_document.d.ts +1 -0
  53. package/esm/types/1_input_message_content.d.ts +88 -0
  54. package/esm/types/1_photo.d.ts +1 -1
  55. package/esm/types/1_sticker.d.ts +1 -1
  56. package/esm/types/1_user.d.ts +1 -1
  57. package/esm/types/1_video.d.ts +1 -1
  58. package/esm/types/1_video_note.d.ts +1 -1
  59. package/esm/types/2_inline_keyboard_button.d.ts +10 -10
  60. package/esm/types/2_message_reaction_count.d.ts +3 -0
  61. package/esm/types/2_message_reaction_count.js +17 -1
  62. package/esm/types/2_message_reactions.d.ts +15 -0
  63. package/esm/types/2_message_reactions.js +37 -0
  64. package/esm/types/3_reply_markup.d.ts +42 -0
  65. package/esm/types/3_reply_markup.js +117 -0
  66. package/esm/types/4_inline_query_result.d.ts +193 -0
  67. package/esm/types/{5_inline_query_result.js → 4_inline_query_result.js} +2 -2
  68. package/esm/types/4_message.d.ts +36 -39
  69. package/esm/types/4_message.js +7 -24
  70. package/esm/types/5_callback_query.d.ts +2 -1
  71. package/esm/types/5_chat.d.ts +8 -5
  72. package/esm/types/6_update.d.ts +12 -2
  73. package/esm/utilities/0_buffer.js +9 -6
  74. package/esm/utilities/0_object.d.ts +1 -1
  75. package/esm/utilities/0_object.js +1 -6
  76. package/esm/utilities/1_misc.d.ts +2 -0
  77. package/esm/utilities/1_misc.js +6 -0
  78. package/package.json +1 -2
  79. package/script/3_types.d.ts +10 -36
  80. package/script/3_types.js +10 -36
  81. package/script/4_constants.d.ts +1 -1
  82. package/script/4_constants.js +1 -1
  83. package/script/5_client.d.ts +1 -1
  84. package/script/5_client.js +1 -1
  85. package/script/_dnt.polyfills.d.ts +6 -0
  86. package/script/client/0_filters.d.ts +60 -0
  87. package/script/client/0_filters.js +31 -0
  88. package/script/client/0_message.js +1 -1
  89. package/script/client/{3_params.d.ts → 0_params.d.ts} +30 -33
  90. package/script/client/0_types.d.ts +39 -0
  91. package/script/client/0_types.js +6 -0
  92. package/script/client/0_utilities.d.ts +1 -47
  93. package/script/client/0_utilities.js +1 -29
  94. package/script/client/1_composer.d.ts +1 -1
  95. package/script/client/1_composer.js +2 -2
  96. package/script/client/1_file_manager.d.ts +10 -0
  97. package/script/client/1_file_manager.js +245 -0
  98. package/script/client/1_update_manager.d.ts +18 -0
  99. package/script/client/1_update_manager.js +557 -0
  100. package/script/client/2_message_manager.d.ts +40 -0
  101. package/script/client/2_message_manager.js +625 -0
  102. package/script/client/3_chat_list_manager.d.ts +21 -0
  103. package/script/client/3_chat_list_manager.js +357 -0
  104. package/script/client/3_reaction_manager.d.ts +16 -0
  105. package/script/client/3_reaction_manager.js +65 -0
  106. package/script/client/4_client.d.ts +187 -60
  107. package/script/client/4_client.js +491 -1698
  108. package/script/connection/1_connection_web_socket.js +5 -5
  109. package/script/deps/raw.githubusercontent.com/MTKruto/debug/main/deps.d.ts +1 -1
  110. package/script/deps/raw.githubusercontent.com/MTKruto/debug/main/deps.js +2 -2
  111. package/script/deps/raw.githubusercontent.com/MTKruto/object-inspect/main/index.d.ts +1 -0
  112. package/script/deps/raw.githubusercontent.com/MTKruto/object-inspect/main/index.js +550 -0
  113. package/script/mod.d.ts +1 -0
  114. package/script/mod.js +1 -0
  115. package/script/storage/0_storage.d.ts +5 -3
  116. package/script/storage/0_storage.js +14 -4
  117. package/script/tl/1_tl_object.d.ts +1 -0
  118. package/script/tl/1_tl_object.js +24 -0
  119. package/script/types/0_bot_command.d.ts +1 -0
  120. package/script/types/0_chat_member_rights.d.ts +37 -0
  121. package/script/types/0_chat_photo.d.ts +4 -4
  122. package/script/types/0_file_source.d.ts +5 -0
  123. package/script/types/0_giveaway_parameters.js +2 -1
  124. package/script/types/0_id.d.ts +4 -0
  125. package/script/types/0_message_entity.d.ts +20 -20
  126. package/script/types/1__getters.d.ts +2 -2
  127. package/script/types/1_animation.d.ts +1 -1
  128. package/script/types/1_bot_command_scope.d.ts +5 -4
  129. package/script/types/1_chat_p.d.ts +5 -6
  130. package/script/types/1_document.d.ts +1 -0
  131. package/script/types/1_input_message_content.d.ts +88 -0
  132. package/script/types/1_photo.d.ts +1 -1
  133. package/script/types/1_sticker.d.ts +1 -1
  134. package/script/types/1_user.d.ts +1 -1
  135. package/script/types/1_video.d.ts +1 -1
  136. package/script/types/1_video_note.d.ts +1 -1
  137. package/script/types/2_inline_keyboard_button.d.ts +10 -10
  138. package/script/types/2_message_reaction_count.d.ts +3 -0
  139. package/script/types/2_message_reaction_count.js +19 -0
  140. package/script/types/2_message_reactions.d.ts +15 -0
  141. package/script/types/2_message_reactions.js +41 -0
  142. package/script/types/3_reply_markup.d.ts +42 -0
  143. package/script/types/3_reply_markup.js +122 -0
  144. package/script/types/4_inline_query_result.d.ts +193 -0
  145. package/script/types/{5_inline_query_result.js → 4_inline_query_result.js} +3 -3
  146. package/script/types/4_message.d.ts +36 -39
  147. package/script/types/4_message.js +6 -23
  148. package/script/types/5_callback_query.d.ts +2 -1
  149. package/script/types/5_chat.d.ts +8 -5
  150. package/script/types/6_update.d.ts +12 -2
  151. package/script/utilities/0_buffer.js +9 -6
  152. package/script/utilities/0_object.d.ts +1 -1
  153. package/script/utilities/0_object.js +1 -6
  154. package/script/utilities/1_misc.d.ts +2 -0
  155. package/script/utilities/1_misc.js +9 -1
  156. package/esm/types/0_chat_id.d.ts +0 -4
  157. package/esm/types/0_force_reply.d.ts +0 -12
  158. package/esm/types/0_force_reply.js +0 -17
  159. package/esm/types/0_input_contact_message_content.d.ts +0 -11
  160. package/esm/types/0_input_location_message_content.d.ts +0 -15
  161. package/esm/types/0_input_venue_message_content.d.ts +0 -19
  162. package/esm/types/0_reply_keyboard_remove.d.ts +0 -10
  163. package/esm/types/0_reply_keyboard_remove.js +0 -8
  164. package/esm/types/1_input_invoice_message_content.d.ts +0 -23
  165. package/esm/types/1_input_text_message_content.d.ts +0 -8
  166. package/esm/types/1_input_text_message_content.js +0 -1
  167. package/esm/types/2_input_message_content.d.ts +0 -6
  168. package/esm/types/2_input_message_content.js +0 -1
  169. package/esm/types/2_reply_keyboard_markup.d.ts +0 -12
  170. package/esm/types/2_reply_keyboard_markup.js +0 -37
  171. package/esm/types/3_inline_keyboard_markup.d.ts +0 -8
  172. package/esm/types/3_inline_keyboard_markup.js +0 -24
  173. package/esm/types/4_inline_query_result_article.d.ts +0 -15
  174. package/esm/types/4_inline_query_result_article.js +0 -1
  175. package/esm/types/4_inline_query_result_audio.d.ts +0 -17
  176. package/esm/types/4_inline_query_result_audio.js +0 -1
  177. package/esm/types/4_inline_query_result_cached_audio.d.ts +0 -14
  178. package/esm/types/4_inline_query_result_cached_audio.js +0 -1
  179. package/esm/types/4_inline_query_result_cached_document.d.ts +0 -15
  180. package/esm/types/4_inline_query_result_cached_document.js +0 -1
  181. package/esm/types/4_inline_query_result_cached_gif.d.ts +0 -15
  182. package/esm/types/4_inline_query_result_cached_gif.js +0 -1
  183. package/esm/types/4_inline_query_result_cached_mpeg4_gif.d.ts +0 -15
  184. package/esm/types/4_inline_query_result_cached_mpeg4_gif.js +0 -1
  185. package/esm/types/4_inline_query_result_cached_photo.d.ts +0 -16
  186. package/esm/types/4_inline_query_result_cached_photo.js +0 -1
  187. package/esm/types/4_inline_query_result_cached_sticker.d.ts +0 -9
  188. package/esm/types/4_inline_query_result_cached_sticker.js +0 -1
  189. package/esm/types/4_inline_query_result_cached_video.d.ts +0 -16
  190. package/esm/types/4_inline_query_result_cached_video.js +0 -1
  191. package/esm/types/4_inline_query_result_cached_voice.d.ts +0 -15
  192. package/esm/types/4_inline_query_result_cached_voice.js +0 -1
  193. package/esm/types/4_inline_query_result_contact.d.ts +0 -15
  194. package/esm/types/4_inline_query_result_contact.js +0 -1
  195. package/esm/types/4_inline_query_result_document.d.ts +0 -18
  196. package/esm/types/4_inline_query_result_document.js +0 -1
  197. package/esm/types/4_inline_query_result_game.d.ts +0 -7
  198. package/esm/types/4_inline_query_result_game.js +0 -1
  199. package/esm/types/4_inline_query_result_gif.d.ts +0 -20
  200. package/esm/types/4_inline_query_result_gif.js +0 -1
  201. package/esm/types/4_inline_query_result_location.d.ts +0 -18
  202. package/esm/types/4_inline_query_result_location.js +0 -1
  203. package/esm/types/4_inline_query_result_mpeg4_gif.d.ts +0 -20
  204. package/esm/types/4_inline_query_result_mpeg4_gif.js +0 -1
  205. package/esm/types/4_inline_query_result_photo.d.ts +0 -19
  206. package/esm/types/4_inline_query_result_photo.js +0 -1
  207. package/esm/types/4_inline_query_result_venue.d.ts +0 -19
  208. package/esm/types/4_inline_query_result_venue.js +0 -1
  209. package/esm/types/4_inline_query_result_video.d.ts +0 -21
  210. package/esm/types/4_inline_query_result_video.js +0 -1
  211. package/esm/types/4_inline_query_result_voice.d.ts +0 -16
  212. package/esm/types/4_inline_query_result_voice.js +0 -1
  213. package/esm/types/4_reply_markup.d.ts +0 -7
  214. package/esm/types/4_reply_markup.js +0 -22
  215. package/esm/types/5_inline_query_result.d.ts +0 -28
  216. package/script/types/0_chat_id.d.ts +0 -4
  217. package/script/types/0_force_reply.d.ts +0 -12
  218. package/script/types/0_force_reply.js +0 -22
  219. package/script/types/0_input_contact_message_content.d.ts +0 -11
  220. package/script/types/0_input_location_message_content.d.ts +0 -15
  221. package/script/types/0_input_venue_message_content.d.ts +0 -19
  222. package/script/types/0_reply_keyboard_remove.d.ts +0 -10
  223. package/script/types/0_reply_keyboard_remove.js +0 -13
  224. package/script/types/1_input_invoice_message_content.d.ts +0 -23
  225. package/script/types/1_input_text_message_content.d.ts +0 -8
  226. package/script/types/1_input_text_message_content.js +0 -2
  227. package/script/types/2_input_message_content.d.ts +0 -6
  228. package/script/types/2_input_message_content.js +0 -2
  229. package/script/types/2_reply_keyboard_markup.d.ts +0 -12
  230. package/script/types/2_reply_keyboard_markup.js +0 -42
  231. package/script/types/3_inline_keyboard_markup.d.ts +0 -8
  232. package/script/types/3_inline_keyboard_markup.js +0 -29
  233. package/script/types/4_inline_query_result_article.d.ts +0 -15
  234. package/script/types/4_inline_query_result_article.js +0 -2
  235. package/script/types/4_inline_query_result_audio.d.ts +0 -17
  236. package/script/types/4_inline_query_result_audio.js +0 -2
  237. package/script/types/4_inline_query_result_cached_audio.d.ts +0 -14
  238. package/script/types/4_inline_query_result_cached_audio.js +0 -2
  239. package/script/types/4_inline_query_result_cached_document.d.ts +0 -15
  240. package/script/types/4_inline_query_result_cached_document.js +0 -2
  241. package/script/types/4_inline_query_result_cached_gif.d.ts +0 -15
  242. package/script/types/4_inline_query_result_cached_gif.js +0 -2
  243. package/script/types/4_inline_query_result_cached_mpeg4_gif.d.ts +0 -15
  244. package/script/types/4_inline_query_result_cached_mpeg4_gif.js +0 -2
  245. package/script/types/4_inline_query_result_cached_photo.d.ts +0 -16
  246. package/script/types/4_inline_query_result_cached_photo.js +0 -2
  247. package/script/types/4_inline_query_result_cached_sticker.d.ts +0 -9
  248. package/script/types/4_inline_query_result_cached_sticker.js +0 -2
  249. package/script/types/4_inline_query_result_cached_video.d.ts +0 -16
  250. package/script/types/4_inline_query_result_cached_video.js +0 -2
  251. package/script/types/4_inline_query_result_cached_voice.d.ts +0 -15
  252. package/script/types/4_inline_query_result_cached_voice.js +0 -2
  253. package/script/types/4_inline_query_result_contact.d.ts +0 -15
  254. package/script/types/4_inline_query_result_contact.js +0 -2
  255. package/script/types/4_inline_query_result_document.d.ts +0 -18
  256. package/script/types/4_inline_query_result_document.js +0 -2
  257. package/script/types/4_inline_query_result_game.d.ts +0 -7
  258. package/script/types/4_inline_query_result_game.js +0 -2
  259. package/script/types/4_inline_query_result_gif.d.ts +0 -20
  260. package/script/types/4_inline_query_result_gif.js +0 -2
  261. package/script/types/4_inline_query_result_location.d.ts +0 -18
  262. package/script/types/4_inline_query_result_location.js +0 -2
  263. package/script/types/4_inline_query_result_mpeg4_gif.d.ts +0 -20
  264. package/script/types/4_inline_query_result_mpeg4_gif.js +0 -2
  265. package/script/types/4_inline_query_result_photo.d.ts +0 -19
  266. package/script/types/4_inline_query_result_photo.js +0 -2
  267. package/script/types/4_inline_query_result_venue.d.ts +0 -19
  268. package/script/types/4_inline_query_result_venue.js +0 -2
  269. package/script/types/4_inline_query_result_video.d.ts +0 -21
  270. package/script/types/4_inline_query_result_video.js +0 -2
  271. package/script/types/4_inline_query_result_voice.d.ts +0 -16
  272. package/script/types/4_inline_query_result_voice.js +0 -2
  273. package/script/types/4_reply_markup.d.ts +0 -7
  274. package/script/types/4_reply_markup.js +0 -26
  275. package/script/types/5_inline_query_result.d.ts +0 -28
  276. /package/esm/{client/3_params.js → _dnt.polyfills.js} +0 -0
  277. /package/esm/{types/0_chat_id.js → client/0_params.js} +0 -0
  278. /package/esm/types/{0_input_contact_message_content.js → 0_chat_member_rights.js} +0 -0
  279. /package/esm/types/{0_input_location_message_content.js → 0_file_source.js} +0 -0
  280. /package/esm/types/{0_input_venue_message_content.js → 0_id.js} +0 -0
  281. /package/esm/types/{1_input_invoice_message_content.js → 1_input_message_content.js} +0 -0
  282. /package/script/{client/3_params.js → _dnt.polyfills.js} +0 -0
  283. /package/script/{types/0_chat_id.js → client/0_params.js} +0 -0
  284. /package/script/types/{0_input_contact_message_content.js → 0_chat_member_rights.js} +0 -0
  285. /package/script/types/{0_input_location_message_content.js → 0_file_source.js} +0 -0
  286. /package/script/types/{0_input_venue_message_content.js → 0_id.js} +0 -0
  287. /package/script/types/{1_input_invoice_message_content.js → 1_input_message_content.js} +0 -0
@@ -0,0 +1,241 @@
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, _FileManager_c, _FileManager_downloadInner;
13
+ import { debug, extension } from "../0_deps.js";
14
+ import { drop, getRandomId, mod, UNREACHABLE } from "../1_utilities.js";
15
+ import { as, types } from "../2_tl.js";
16
+ import { constructDocument, FileID, FileType, FileUniqueID, FileUniqueType, ThumbnailSource } from "../3_types.js";
17
+ import { FloodWait } from "../4_errors.js";
18
+ import { ConnectionError } from "./0_types.js";
19
+ const d = debug("FileManager");
20
+ export class FileManager {
21
+ constructor(c) {
22
+ _FileManager_instances.add(this);
23
+ _FileManager_c.set(this, void 0);
24
+ __classPrivateFieldSet(this, _FileManager_c, c, "f");
25
+ }
26
+ async upload(contents, params) {
27
+ const isBig = contents.length > 1048576; // 10 MB
28
+ const chunkSize = params?.chunkSize ?? 512 * 1024;
29
+ if (mod(chunkSize, 1024) != 0) {
30
+ throw new Error("chunkSize must be divisible by 1024");
31
+ }
32
+ const signal = params?.signal;
33
+ d("uploading " + (isBig ? "big " : "") + "file of size " + contents.length + " with chunk size of " + chunkSize);
34
+ const fileId = getRandomId();
35
+ const name = params?.fileName ?? fileId.toString();
36
+ const { api, disconnect, connect } = __classPrivateFieldGet(this, _FileManager_c, "f").apiFactory();
37
+ signal?.addEventListener("abort", () => drop(disconnect()));
38
+ await connect();
39
+ let part = 0;
40
+ const partCount = Math.ceil(contents.length / chunkSize);
41
+ try {
42
+ main: for (; part < partCount; part++) {
43
+ chunk: while (true) {
44
+ try {
45
+ const start = part * chunkSize;
46
+ const end = start + chunkSize;
47
+ const bytes = contents.slice(start, end);
48
+ if (bytes.length == 0) {
49
+ continue main;
50
+ }
51
+ if (isBig) {
52
+ await api.upload.saveBigFilePart({ file_id: fileId, file_part: part, bytes, file_total_parts: partCount });
53
+ }
54
+ else {
55
+ await api.upload.saveFilePart({ file_id: fileId, bytes, file_part: part });
56
+ }
57
+ d((part + 1) + " out of " + partCount + " chunks have been uploaded so far");
58
+ break chunk;
59
+ }
60
+ catch (err) {
61
+ if (signal?.aborted) {
62
+ break main;
63
+ }
64
+ if (err instanceof FloodWait) {
65
+ d("got a flood wait of " + err.seconds + " seconds");
66
+ await new Promise((r) => setTimeout(r, err.seconds * 1000));
67
+ }
68
+ else if (err instanceof ConnectionError) {
69
+ while (true) {
70
+ try {
71
+ await new Promise((r) => setTimeout(r, 3000));
72
+ await connect();
73
+ }
74
+ catch {
75
+ if (signal?.aborted) {
76
+ break main;
77
+ }
78
+ }
79
+ }
80
+ }
81
+ else {
82
+ throw err;
83
+ }
84
+ }
85
+ }
86
+ }
87
+ }
88
+ finally {
89
+ drop(disconnect());
90
+ }
91
+ d("uploaded all " + partCount + " chunk(s)");
92
+ if (isBig) {
93
+ return new types.InputFileBig({ id: fileId, parts: contents.length / chunkSize, name });
94
+ }
95
+ else {
96
+ return new types.InputFile({ id: fileId, name, parts: part, md5_checksum: "" });
97
+ }
98
+ }
99
+ async *download(fileId, params) {
100
+ const fileId_ = FileID.decode(fileId);
101
+ switch (fileId_.fileType) {
102
+ case FileType.ChatPhoto: {
103
+ const big = fileId_.params.thumbnailSource == ThumbnailSource.ChatPhotoBig;
104
+ const peer = await __classPrivateFieldGet(this, _FileManager_c, "f").getInputPeer(fileId_.params.chatId);
105
+ const location = new types.InputPeerPhotoFileLocation({ big: big ? true : undefined, peer, photo_id: fileId_.params.mediaId });
106
+ for await (const chunk of __classPrivateFieldGet(this, _FileManager_instances, "m", _FileManager_downloadInner).call(this, location, fileId_.dcId, params)) {
107
+ yield chunk;
108
+ }
109
+ break;
110
+ }
111
+ case FileType.Photo: {
112
+ if (fileId_.params.mediaId == undefined || fileId_.params.accessHash == undefined || fileId_.params.fileReference == undefined || fileId_.params.thumbnailSize == undefined) {
113
+ UNREACHABLE();
114
+ }
115
+ const location = new types.InputPhotoFileLocation({
116
+ id: fileId_.params.mediaId,
117
+ access_hash: fileId_.params.accessHash,
118
+ file_reference: fileId_.params.fileReference,
119
+ thumb_size: fileId_.params.thumbnailSize,
120
+ });
121
+ for await (const chunk of __classPrivateFieldGet(this, _FileManager_instances, "m", _FileManager_downloadInner).call(this, location, fileId_.dcId, params)) {
122
+ yield chunk;
123
+ }
124
+ break;
125
+ }
126
+ case FileType.Document:
127
+ case FileType.Sticker:
128
+ case FileType.VideoNote:
129
+ case FileType.Video:
130
+ case FileType.Audio:
131
+ case FileType.Voice:
132
+ case FileType.Animation: {
133
+ if (fileId_.params.mediaId == undefined || fileId_.params.accessHash == undefined || fileId_.params.fileReference == undefined || fileId_.params.thumbnailSize == undefined) {
134
+ UNREACHABLE();
135
+ }
136
+ const location = new types.InputDocumentFileLocation({
137
+ id: fileId_.params.mediaId,
138
+ access_hash: fileId_.params.accessHash,
139
+ file_reference: fileId_.params.fileReference,
140
+ thumb_size: fileId_.params.thumbnailSize,
141
+ });
142
+ for await (const chunk of __classPrivateFieldGet(this, _FileManager_instances, "m", _FileManager_downloadInner).call(this, location, fileId_.dcId, params)) {
143
+ yield chunk;
144
+ }
145
+ break;
146
+ }
147
+ default:
148
+ UNREACHABLE();
149
+ }
150
+ }
151
+ async getCustomEmojiDocuments(id) {
152
+ id = Array.isArray(id) ? id : [id];
153
+ if (!id.length) {
154
+ throw new Error("No custom emoji ID provided");
155
+ }
156
+ const documents = new Array();
157
+ let shouldFetch = false;
158
+ for (const [i, id_] of id.entries()) {
159
+ const maybeDocument = await __classPrivateFieldGet(this, _FileManager_c, "f").storage.getCustomEmojiDocument(BigInt(id_));
160
+ if (maybeDocument != null && Date.now() - maybeDocument[1].getTime() <= 30 * 60 * 1000) {
161
+ const document_ = maybeDocument[0];
162
+ const fileUniqueId = new FileUniqueID(FileUniqueType.Document, { mediaId: document_.id }).encode();
163
+ const fileId = new FileID(null, null, FileType.Document, document_.dc_id, {
164
+ mediaId: document_.id,
165
+ accessHash: document_.access_hash,
166
+ fileReference: document_.file_reference,
167
+ }).encode();
168
+ const document = constructDocument(document_, new types.DocumentAttributeFilename({ file_name: `${id[i] ?? "customEmoji"}.${extension(document_.mime_type)}` }), fileId, fileUniqueId);
169
+ documents.push(document);
170
+ }
171
+ else {
172
+ shouldFetch = true;
173
+ break;
174
+ }
175
+ }
176
+ if (!shouldFetch) {
177
+ return documents;
178
+ }
179
+ const documents_ = await __classPrivateFieldGet(this, _FileManager_c, "f").api.messages.getCustomEmojiDocuments({ document_id: id.map(BigInt) }).then((v) => v.map((v) => v[as](types.Document)));
180
+ for (const [i, document_] of documents_.entries()) {
181
+ const fileUniqueId = new FileUniqueID(FileUniqueType.Document, { mediaId: document_.id }).encode();
182
+ const fileId = new FileID(null, null, FileType.Document, document_.dc_id, {
183
+ mediaId: document_.id,
184
+ accessHash: document_.access_hash,
185
+ fileReference: document_.file_reference,
186
+ }).encode();
187
+ const document = constructDocument(document_, new types.DocumentAttributeFilename({ file_name: `${id[i] ?? "customEmoji"}.${extension(document_.mime_type)}` }), fileId, fileUniqueId);
188
+ documents.push(document);
189
+ }
190
+ return documents;
191
+ }
192
+ }
193
+ _FileManager_c = new WeakMap(), _FileManager_instances = new WeakSet(), _FileManager_downloadInner = async function* _FileManager_downloadInner(location, dcId, params) {
194
+ const id = "id" in location ? location.id : "photo_id" in location ? location.photo_id : null;
195
+ if (id != null) {
196
+ const file = await __classPrivateFieldGet(this, _FileManager_c, "f").storage.getFile(id);
197
+ const partOffset = file == null ? 0 : params?.offset ? Math.ceil(10 / file[1]) - 1 : 0;
198
+ if (file != null && file[0] > 0) {
199
+ for await (const part of __classPrivateFieldGet(this, _FileManager_c, "f").storage.iterFileParts(id, file[0], partOffset)) {
200
+ yield part;
201
+ }
202
+ return;
203
+ }
204
+ }
205
+ const chunkSize = params?.chunkSize ?? 1024 * 1024;
206
+ if (mod(chunkSize, 1024) != 0) {
207
+ throw new Error("chunkSize must be divisible by 1024");
208
+ }
209
+ const { api, connect, disconnect } = __classPrivateFieldGet(this, _FileManager_c, "f").apiFactory(dcId);
210
+ await connect();
211
+ const limit = chunkSize;
212
+ let offset = params?.offset ? BigInt(params.offset) : 0n;
213
+ let part = 0;
214
+ try {
215
+ while (true) {
216
+ const file = await api.upload.getFile({ location, offset, limit });
217
+ if (file instanceof types.upload.File) {
218
+ yield file.bytes;
219
+ if (id != null) {
220
+ await __classPrivateFieldGet(this, _FileManager_c, "f").storage.saveFilePart(id, part, file.bytes);
221
+ }
222
+ ++part;
223
+ if (file.bytes.length < limit) {
224
+ if (id != null) {
225
+ await __classPrivateFieldGet(this, _FileManager_c, "f").storage.setFilePartCount(id, part + 1, chunkSize);
226
+ }
227
+ break;
228
+ }
229
+ else {
230
+ offset += BigInt(file.bytes.length);
231
+ }
232
+ }
233
+ else {
234
+ UNREACHABLE();
235
+ }
236
+ }
237
+ }
238
+ finally {
239
+ drop(disconnect());
240
+ }
241
+ };
@@ -0,0 +1,18 @@
1
+ import { Queue } from "../1_utilities.js";
2
+ import { enums, ReadObject, TLObject } from "../2_tl.js";
3
+ import { C } from "./0_types.js";
4
+ type UpdateHandler = (update: enums.Update) => Promise<(() => Promise<unknown>)>;
5
+ export declare class UpdateManager {
6
+ #private;
7
+ static readonly MAIN_BOX_ID = 0n;
8
+ constructor(c: C);
9
+ fetchState(source: string): Promise<void>;
10
+ processChats(chats: enums.Chat[]): Promise<void>;
11
+ processResult(result: ReadObject): Promise<void>;
12
+ processUsers(users: enums.User[]): Promise<void>;
13
+ getHandleUpdateQueue(boxId: bigint): Queue;
14
+ processUpdates(updates: enums.Update | enums.Updates, checkGap: boolean, call?: TLObject | null, callback?: () => void): void;
15
+ recoverUpdateGap(source: string): Promise<void>;
16
+ setUpdateHandler(handler: UpdateHandler): void;
17
+ }
18
+ export {};