@mtcute/core 0.1.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 (502) hide show
  1. package/LICENSE +8 -0
  2. package/README.md +26 -0
  3. package/cjs/base-client.d.ts +297 -0
  4. package/cjs/base-client.js +324 -0
  5. package/cjs/base-client.js.map +1 -0
  6. package/cjs/index.d.ts +10 -0
  7. package/cjs/index.js +30 -0
  8. package/cjs/index.js.map +1 -0
  9. package/cjs/network/auth-key.d.ts +21 -0
  10. package/cjs/network/auth-key.js +101 -0
  11. package/cjs/network/auth-key.js.map +1 -0
  12. package/cjs/network/authorization.d.ts +9 -0
  13. package/cjs/network/authorization.js +332 -0
  14. package/cjs/network/authorization.js.map +1 -0
  15. package/cjs/network/config-manager.d.ts +33 -0
  16. package/cjs/network/config-manager.js +93 -0
  17. package/cjs/network/config-manager.js.map +1 -0
  18. package/cjs/network/index.d.ts +4 -0
  19. package/cjs/network/index.js +20 -0
  20. package/cjs/network/index.js.map +1 -0
  21. package/cjs/network/mtproto-session.d.ts +116 -0
  22. package/cjs/network/mtproto-session.js +209 -0
  23. package/cjs/network/mtproto-session.js.map +1 -0
  24. package/cjs/network/multi-session-connection.d.ts +33 -0
  25. package/cjs/network/multi-session-connection.js +243 -0
  26. package/cjs/network/multi-session-connection.js.map +1 -0
  27. package/cjs/network/network-manager.d.ts +190 -0
  28. package/cjs/network/network-manager.js +547 -0
  29. package/cjs/network/network-manager.js.map +1 -0
  30. package/cjs/network/persistent-connection.d.ts +51 -0
  31. package/cjs/network/persistent-connection.js +173 -0
  32. package/cjs/network/persistent-connection.js.map +1 -0
  33. package/cjs/network/reconnection.d.ts +11 -0
  34. package/cjs/network/reconnection.js +18 -0
  35. package/cjs/network/reconnection.js.map +1 -0
  36. package/cjs/network/session-connection.d.ts +72 -0
  37. package/cjs/network/session-connection.js +1363 -0
  38. package/cjs/network/session-connection.js.map +1 -0
  39. package/cjs/network/transports/abstract.d.ts +99 -0
  40. package/cjs/network/transports/abstract.js +38 -0
  41. package/cjs/network/transports/abstract.js.map +1 -0
  42. package/cjs/network/transports/index.d.ts +8 -0
  43. package/cjs/network/transports/index.js +26 -0
  44. package/cjs/network/transports/index.js.map +1 -0
  45. package/cjs/network/transports/intermediate.d.ts +20 -0
  46. package/cjs/network/transports/intermediate.js +67 -0
  47. package/cjs/network/transports/intermediate.js.map +1 -0
  48. package/cjs/network/transports/obfuscated.d.ts +18 -0
  49. package/cjs/network/transports/obfuscated.js +83 -0
  50. package/cjs/network/transports/obfuscated.js.map +1 -0
  51. package/cjs/network/transports/streamed.d.ts +24 -0
  52. package/cjs/network/transports/streamed.js +32 -0
  53. package/cjs/network/transports/streamed.js.map +1 -0
  54. package/cjs/network/transports/tcp.d.ts +33 -0
  55. package/cjs/network/transports/tcp.js +130 -0
  56. package/cjs/network/transports/tcp.js.map +1 -0
  57. package/cjs/network/transports/websocket.d.ts +47 -0
  58. package/cjs/network/transports/websocket.js +124 -0
  59. package/cjs/network/transports/websocket.js.map +1 -0
  60. package/cjs/network/transports/wrapped.d.ts +11 -0
  61. package/cjs/network/transports/wrapped.js +26 -0
  62. package/cjs/network/transports/wrapped.js.map +1 -0
  63. package/cjs/package.json +3 -0
  64. package/cjs/storage/abstract.d.ts +174 -0
  65. package/cjs/storage/abstract.js +3 -0
  66. package/cjs/storage/abstract.js.map +1 -0
  67. package/cjs/storage/index.d.ts +5 -0
  68. package/cjs/storage/index.js +22 -0
  69. package/cjs/storage/index.js.map +1 -0
  70. package/cjs/storage/json-file.d.ts +31 -0
  71. package/cjs/storage/json-file.js +90 -0
  72. package/cjs/storage/json-file.js.map +1 -0
  73. package/cjs/storage/json.d.ts +9 -0
  74. package/cjs/storage/json.js +65 -0
  75. package/cjs/storage/json.js.map +1 -0
  76. package/cjs/storage/localstorage.d.ts +7 -0
  77. package/cjs/storage/localstorage.js +25 -0
  78. package/cjs/storage/localstorage.js.map +1 -0
  79. package/cjs/storage/memory.d.ts +98 -0
  80. package/cjs/storage/memory.js +299 -0
  81. package/cjs/storage/memory.js.map +1 -0
  82. package/cjs/types/errors.d.ts +53 -0
  83. package/cjs/types/errors.js +58 -0
  84. package/cjs/types/errors.js.map +1 -0
  85. package/cjs/types/index.d.ts +3 -0
  86. package/cjs/types/index.js +20 -0
  87. package/cjs/types/index.js.map +1 -0
  88. package/cjs/types/peers.d.ts +4 -0
  89. package/cjs/types/peers.js +3 -0
  90. package/cjs/types/peers.js.map +1 -0
  91. package/cjs/types/utils.d.ts +6 -0
  92. package/cjs/types/utils.js +9 -0
  93. package/cjs/types/utils.js.map +1 -0
  94. package/cjs/utils/async-lock.d.ts +10 -0
  95. package/cjs/utils/async-lock.js +43 -0
  96. package/cjs/utils/async-lock.js.map +1 -0
  97. package/cjs/utils/bigint-utils.d.ts +40 -0
  98. package/cjs/utils/bigint-utils.js +104 -0
  99. package/cjs/utils/bigint-utils.js.map +1 -0
  100. package/cjs/utils/binary/asn1-parser.d.ts +17 -0
  101. package/cjs/utils/binary/asn1-parser.js +121 -0
  102. package/cjs/utils/binary/asn1-parser.js.map +1 -0
  103. package/cjs/utils/buffer-utils.d.ts +21 -0
  104. package/cjs/utils/buffer-utils.js +63 -0
  105. package/cjs/utils/buffer-utils.js.map +1 -0
  106. package/cjs/utils/condition-variable.d.ts +9 -0
  107. package/cjs/utils/condition-variable.js +28 -0
  108. package/cjs/utils/condition-variable.js.map +1 -0
  109. package/cjs/utils/controllable-promise.d.ts +16 -0
  110. package/cjs/utils/controllable-promise.js +25 -0
  111. package/cjs/utils/controllable-promise.js.map +1 -0
  112. package/cjs/utils/crypto/abstract.d.ts +23 -0
  113. package/cjs/utils/crypto/abstract.js +19 -0
  114. package/cjs/utils/crypto/abstract.js.map +1 -0
  115. package/cjs/utils/crypto/common.d.ts +12 -0
  116. package/cjs/utils/crypto/common.js +54 -0
  117. package/cjs/utils/crypto/common.js.map +1 -0
  118. package/cjs/utils/crypto/factorization.d.ts +5 -0
  119. package/cjs/utils/crypto/factorization.js +69 -0
  120. package/cjs/utils/crypto/factorization.js.map +1 -0
  121. package/cjs/utils/crypto/index.d.ts +5 -0
  122. package/cjs/utils/crypto/index.js +23 -0
  123. package/cjs/utils/crypto/index.js.map +1 -0
  124. package/cjs/utils/crypto/keys.d.ts +27 -0
  125. package/cjs/utils/crypto/keys.js +70 -0
  126. package/cjs/utils/crypto/keys.js.map +1 -0
  127. package/cjs/utils/crypto/miller-rabin.d.ts +2 -0
  128. package/cjs/utils/crypto/miller-rabin.js +44 -0
  129. package/cjs/utils/crypto/miller-rabin.js.map +1 -0
  130. package/cjs/utils/crypto/mtproto.d.ts +31 -0
  131. package/cjs/utils/crypto/mtproto.js +66 -0
  132. package/cjs/utils/crypto/mtproto.js.map +1 -0
  133. package/cjs/utils/crypto/node-crypto.d.ts +10 -0
  134. package/cjs/utils/crypto/node-crypto.js +46 -0
  135. package/cjs/utils/crypto/node-crypto.js.map +1 -0
  136. package/cjs/utils/crypto/password.d.ts +29 -0
  137. package/cjs/utils/crypto/password.js +106 -0
  138. package/cjs/utils/crypto/password.js.map +1 -0
  139. package/cjs/utils/crypto/subtle.d.ts +12 -0
  140. package/cjs/utils/crypto/subtle.js +86 -0
  141. package/cjs/utils/crypto/subtle.js.map +1 -0
  142. package/cjs/utils/crypto/utils.d.ts +14 -0
  143. package/cjs/utils/crypto/utils.js +30 -0
  144. package/cjs/utils/crypto/utils.js.map +1 -0
  145. package/cjs/utils/default-dcs.d.ts +7 -0
  146. package/cjs/utils/default-dcs.js +76 -0
  147. package/cjs/utils/default-dcs.js.map +1 -0
  148. package/cjs/utils/deque.d.ts +29 -0
  149. package/cjs/utils/deque.js +210 -0
  150. package/cjs/utils/deque.js.map +1 -0
  151. package/cjs/utils/early-timer.d.ts +42 -0
  152. package/cjs/utils/early-timer.js +79 -0
  153. package/cjs/utils/early-timer.js.map +1 -0
  154. package/cjs/utils/flood-control.d.ts +14 -0
  155. package/cjs/utils/flood-control.js +65 -0
  156. package/cjs/utils/flood-control.js.map +1 -0
  157. package/cjs/utils/function-utils.d.ts +13 -0
  158. package/cjs/utils/function-utils.js +30 -0
  159. package/cjs/utils/function-utils.js.map +1 -0
  160. package/cjs/utils/index.d.ts +24 -0
  161. package/cjs/utils/index.js +41 -0
  162. package/cjs/utils/index.js.map +1 -0
  163. package/cjs/utils/linked-list.d.ts +21 -0
  164. package/cjs/utils/linked-list.js +73 -0
  165. package/cjs/utils/linked-list.js.map +1 -0
  166. package/cjs/utils/links/bots.d.ts +71 -0
  167. package/cjs/utils/links/bots.js +259 -0
  168. package/cjs/utils/links/bots.js.map +1 -0
  169. package/cjs/utils/links/bundle.d.ts +7 -0
  170. package/cjs/utils/links/bundle.js +24 -0
  171. package/cjs/utils/links/bundle.js.map +1 -0
  172. package/cjs/utils/links/calls.d.ts +16 -0
  173. package/cjs/utils/links/calls.js +59 -0
  174. package/cjs/utils/links/calls.js.map +1 -0
  175. package/cjs/utils/links/chat.d.ts +46 -0
  176. package/cjs/utils/links/chat.js +160 -0
  177. package/cjs/utils/links/chat.js.map +1 -0
  178. package/cjs/utils/links/common.d.ts +31 -0
  179. package/cjs/utils/links/common.js +60 -0
  180. package/cjs/utils/links/common.js.map +1 -0
  181. package/cjs/utils/links/index.d.ts +2 -0
  182. package/cjs/utils/links/index.js +29 -0
  183. package/cjs/utils/links/index.js.map +1 -0
  184. package/cjs/utils/links/misc.d.ts +19 -0
  185. package/cjs/utils/links/misc.js +77 -0
  186. package/cjs/utils/links/misc.js.map +1 -0
  187. package/cjs/utils/links/proxy.d.ts +17 -0
  188. package/cjs/utils/links/proxy.js +61 -0
  189. package/cjs/utils/links/proxy.js.map +1 -0
  190. package/cjs/utils/links/stickers.d.ts +9 -0
  191. package/cjs/utils/links/stickers.js +28 -0
  192. package/cjs/utils/links/stickers.js.map +1 -0
  193. package/cjs/utils/links/user.d.ts +27 -0
  194. package/cjs/utils/links/user.js +81 -0
  195. package/cjs/utils/links/user.js.map +1 -0
  196. package/cjs/utils/logger.d.ts +54 -0
  197. package/cjs/utils/logger.js +158 -0
  198. package/cjs/utils/logger.js.map +1 -0
  199. package/cjs/utils/long-utils.d.ts +75 -0
  200. package/cjs/utils/long-utils.js +161 -0
  201. package/cjs/utils/long-utils.js.map +1 -0
  202. package/cjs/utils/lru-map.d.ts +21 -0
  203. package/cjs/utils/lru-map.js +107 -0
  204. package/cjs/utils/lru-map.js.map +1 -0
  205. package/cjs/utils/lru-set.d.ts +22 -0
  206. package/cjs/utils/lru-set.js +48 -0
  207. package/cjs/utils/lru-set.js.map +1 -0
  208. package/cjs/utils/misc-utils.d.ts +7 -0
  209. package/cjs/utils/misc-utils.js +15 -0
  210. package/cjs/utils/misc-utils.js.map +1 -0
  211. package/cjs/utils/peer-utils.d.ts +35 -0
  212. package/cjs/utils/peer-utils.js +188 -0
  213. package/cjs/utils/peer-utils.js.map +1 -0
  214. package/cjs/utils/platform/crypto.d.ts +1 -0
  215. package/cjs/utils/platform/crypto.js +8 -0
  216. package/cjs/utils/platform/crypto.js.map +1 -0
  217. package/cjs/utils/platform/crypto.web.d.ts +1 -0
  218. package/cjs/utils/platform/crypto.web.js +14 -0
  219. package/cjs/utils/platform/crypto.web.js.map +1 -0
  220. package/cjs/utils/platform/error-reporting.d.ts +3 -0
  221. package/cjs/utils/platform/error-reporting.js +22 -0
  222. package/cjs/utils/platform/error-reporting.js.map +1 -0
  223. package/cjs/utils/platform/logging.d.ts +1 -0
  224. package/cjs/utils/platform/logging.js +35 -0
  225. package/cjs/utils/platform/logging.js.map +1 -0
  226. package/cjs/utils/platform/logging.web.d.ts +1 -0
  227. package/cjs/utils/platform/logging.web.js +35 -0
  228. package/cjs/utils/platform/logging.web.js.map +1 -0
  229. package/cjs/utils/platform/random.d.ts +1 -0
  230. package/cjs/utils/platform/random.js +7 -0
  231. package/cjs/utils/platform/random.js.map +1 -0
  232. package/cjs/utils/platform/random.web.d.ts +1 -0
  233. package/cjs/utils/platform/random.web.js +10 -0
  234. package/cjs/utils/platform/random.web.js.map +1 -0
  235. package/cjs/utils/platform/transport.d.ts +1 -0
  236. package/cjs/utils/platform/transport.js +8 -0
  237. package/cjs/utils/platform/transport.js.map +1 -0
  238. package/cjs/utils/platform/transport.web.d.ts +1 -0
  239. package/cjs/utils/platform/transport.web.js +15 -0
  240. package/cjs/utils/platform/transport.web.js.map +1 -0
  241. package/cjs/utils/sorted-array.d.ts +17 -0
  242. package/cjs/utils/sorted-array.js +83 -0
  243. package/cjs/utils/sorted-array.js.map +1 -0
  244. package/cjs/utils/string-session.d.ts +11 -0
  245. package/cjs/utils/string-session.js +73 -0
  246. package/cjs/utils/string-session.js.map +1 -0
  247. package/cjs/utils/tl-json.d.ts +13 -0
  248. package/cjs/utils/tl-json.js +62 -0
  249. package/cjs/utils/tl-json.js.map +1 -0
  250. package/cjs/utils/type-assertions.d.ts +37 -0
  251. package/cjs/utils/type-assertions.js +70 -0
  252. package/cjs/utils/type-assertions.js.map +1 -0
  253. package/esm/base-client.d.ts +297 -0
  254. package/esm/base-client.js +317 -0
  255. package/esm/base-client.js.map +1 -0
  256. package/esm/index.d.ts +10 -0
  257. package/esm/index.js +11 -0
  258. package/esm/index.js.map +1 -0
  259. package/esm/network/auth-key.d.ts +21 -0
  260. package/esm/network/auth-key.js +97 -0
  261. package/esm/network/auth-key.js.map +1 -0
  262. package/esm/network/authorization.d.ts +9 -0
  263. package/esm/network/authorization.js +325 -0
  264. package/esm/network/authorization.js.map +1 -0
  265. package/esm/network/config-manager.d.ts +33 -0
  266. package/esm/network/config-manager.js +89 -0
  267. package/esm/network/config-manager.js.map +1 -0
  268. package/esm/network/index.d.ts +4 -0
  269. package/esm/network/index.js +4 -0
  270. package/esm/network/index.js.map +1 -0
  271. package/esm/network/mtproto-session.d.ts +116 -0
  272. package/esm/network/mtproto-session.js +202 -0
  273. package/esm/network/mtproto-session.js.map +1 -0
  274. package/esm/network/multi-session-connection.d.ts +33 -0
  275. package/esm/network/multi-session-connection.js +236 -0
  276. package/esm/network/multi-session-connection.js.map +1 -0
  277. package/esm/network/network-manager.d.ts +190 -0
  278. package/esm/network/network-manager.js +542 -0
  279. package/esm/network/network-manager.js.map +1 -0
  280. package/esm/network/persistent-connection.d.ts +51 -0
  281. package/esm/network/persistent-connection.js +166 -0
  282. package/esm/network/persistent-connection.js.map +1 -0
  283. package/esm/network/reconnection.d.ts +11 -0
  284. package/esm/network/reconnection.js +14 -0
  285. package/esm/network/reconnection.js.map +1 -0
  286. package/esm/network/session-connection.d.ts +72 -0
  287. package/esm/network/session-connection.js +1356 -0
  288. package/esm/network/session-connection.js.map +1 -0
  289. package/esm/network/transports/abstract.d.ts +99 -0
  290. package/esm/network/transports/abstract.js +34 -0
  291. package/esm/network/transports/abstract.js.map +1 -0
  292. package/esm/network/transports/index.d.ts +8 -0
  293. package/esm/network/transports/index.js +9 -0
  294. package/esm/network/transports/index.js.map +1 -0
  295. package/esm/network/transports/intermediate.d.ts +20 -0
  296. package/esm/network/transports/intermediate.js +62 -0
  297. package/esm/network/transports/intermediate.js.map +1 -0
  298. package/esm/network/transports/obfuscated.d.ts +18 -0
  299. package/esm/network/transports/obfuscated.js +79 -0
  300. package/esm/network/transports/obfuscated.js.map +1 -0
  301. package/esm/network/transports/streamed.d.ts +24 -0
  302. package/esm/network/transports/streamed.js +25 -0
  303. package/esm/network/transports/streamed.js.map +1 -0
  304. package/esm/network/transports/tcp.d.ts +33 -0
  305. package/esm/network/transports/tcp.js +122 -0
  306. package/esm/network/transports/tcp.js.map +1 -0
  307. package/esm/network/transports/websocket.d.ts +47 -0
  308. package/esm/network/transports/websocket.js +116 -0
  309. package/esm/network/transports/websocket.js.map +1 -0
  310. package/esm/network/transports/wrapped.d.ts +11 -0
  311. package/esm/network/transports/wrapped.js +19 -0
  312. package/esm/network/transports/wrapped.js.map +1 -0
  313. package/esm/storage/abstract.d.ts +174 -0
  314. package/esm/storage/abstract.js +2 -0
  315. package/esm/storage/abstract.js.map +1 -0
  316. package/esm/storage/index.d.ts +5 -0
  317. package/esm/storage/index.js +6 -0
  318. package/esm/storage/index.js.map +1 -0
  319. package/esm/storage/json-file.d.ts +31 -0
  320. package/esm/storage/json-file.js +63 -0
  321. package/esm/storage/json-file.js.map +1 -0
  322. package/esm/storage/json.d.ts +9 -0
  323. package/esm/storage/json.js +61 -0
  324. package/esm/storage/json.js.map +1 -0
  325. package/esm/storage/localstorage.d.ts +7 -0
  326. package/esm/storage/localstorage.js +21 -0
  327. package/esm/storage/localstorage.js.map +1 -0
  328. package/esm/storage/memory.d.ts +98 -0
  329. package/esm/storage/memory.js +295 -0
  330. package/esm/storage/memory.js.map +1 -0
  331. package/esm/types/errors.d.ts +53 -0
  332. package/esm/types/errors.js +49 -0
  333. package/esm/types/errors.js.map +1 -0
  334. package/esm/types/index.d.ts +3 -0
  335. package/esm/types/index.js +4 -0
  336. package/esm/types/index.js.map +1 -0
  337. package/esm/types/peers.d.ts +4 -0
  338. package/esm/types/peers.js +2 -0
  339. package/esm/types/peers.js.map +1 -0
  340. package/esm/types/utils.d.ts +6 -0
  341. package/esm/types/utils.js +5 -0
  342. package/esm/types/utils.js.map +1 -0
  343. package/esm/utils/async-lock.d.ts +10 -0
  344. package/esm/utils/async-lock.js +39 -0
  345. package/esm/utils/async-lock.js.map +1 -0
  346. package/esm/utils/bigint-utils.d.ts +40 -0
  347. package/esm/utils/bigint-utils.js +92 -0
  348. package/esm/utils/bigint-utils.js.map +1 -0
  349. package/esm/utils/binary/asn1-parser.d.ts +17 -0
  350. package/esm/utils/binary/asn1-parser.js +116 -0
  351. package/esm/utils/binary/asn1-parser.js.map +1 -0
  352. package/esm/utils/buffer-utils.d.ts +21 -0
  353. package/esm/utils/buffer-utils.js +55 -0
  354. package/esm/utils/buffer-utils.js.map +1 -0
  355. package/esm/utils/condition-variable.d.ts +9 -0
  356. package/esm/utils/condition-variable.js +24 -0
  357. package/esm/utils/condition-variable.js.map +1 -0
  358. package/esm/utils/controllable-promise.d.ts +16 -0
  359. package/esm/utils/controllable-promise.js +20 -0
  360. package/esm/utils/controllable-promise.js.map +1 -0
  361. package/esm/utils/crypto/abstract.d.ts +23 -0
  362. package/esm/utils/crypto/abstract.js +15 -0
  363. package/esm/utils/crypto/abstract.js.map +1 -0
  364. package/esm/utils/crypto/common.d.ts +12 -0
  365. package/esm/utils/crypto/common.js +50 -0
  366. package/esm/utils/crypto/common.js.map +1 -0
  367. package/esm/utils/crypto/factorization.d.ts +5 -0
  368. package/esm/utils/crypto/factorization.js +62 -0
  369. package/esm/utils/crypto/factorization.js.map +1 -0
  370. package/esm/utils/crypto/index.d.ts +5 -0
  371. package/esm/utils/crypto/index.js +6 -0
  372. package/esm/utils/crypto/index.js.map +1 -0
  373. package/esm/utils/crypto/keys.d.ts +27 -0
  374. package/esm/utils/crypto/keys.js +64 -0
  375. package/esm/utils/crypto/keys.js.map +1 -0
  376. package/esm/utils/crypto/miller-rabin.d.ts +2 -0
  377. package/esm/utils/crypto/miller-rabin.js +37 -0
  378. package/esm/utils/crypto/miller-rabin.js.map +1 -0
  379. package/esm/utils/crypto/mtproto.d.ts +31 -0
  380. package/esm/utils/crypto/mtproto.js +60 -0
  381. package/esm/utils/crypto/mtproto.js.map +1 -0
  382. package/esm/utils/crypto/node-crypto.d.ts +10 -0
  383. package/esm/utils/crypto/node-crypto.js +42 -0
  384. package/esm/utils/crypto/node-crypto.js.map +1 -0
  385. package/esm/utils/crypto/password.d.ts +29 -0
  386. package/esm/utils/crypto/password.js +97 -0
  387. package/esm/utils/crypto/password.js.map +1 -0
  388. package/esm/utils/crypto/subtle.d.ts +12 -0
  389. package/esm/utils/crypto/subtle.js +59 -0
  390. package/esm/utils/crypto/subtle.js.map +1 -0
  391. package/esm/utils/crypto/utils.d.ts +14 -0
  392. package/esm/utils/crypto/utils.js +25 -0
  393. package/esm/utils/crypto/utils.js.map +1 -0
  394. package/esm/utils/default-dcs.d.ts +7 -0
  395. package/esm/utils/default-dcs.js +73 -0
  396. package/esm/utils/default-dcs.js.map +1 -0
  397. package/esm/utils/deque.d.ts +29 -0
  398. package/esm/utils/deque.js +206 -0
  399. package/esm/utils/deque.js.map +1 -0
  400. package/esm/utils/early-timer.d.ts +42 -0
  401. package/esm/utils/early-timer.js +75 -0
  402. package/esm/utils/early-timer.js.map +1 -0
  403. package/esm/utils/flood-control.d.ts +14 -0
  404. package/esm/utils/flood-control.js +61 -0
  405. package/esm/utils/flood-control.js.map +1 -0
  406. package/esm/utils/function-utils.d.ts +13 -0
  407. package/esm/utils/function-utils.js +26 -0
  408. package/esm/utils/function-utils.js.map +1 -0
  409. package/esm/utils/index.d.ts +24 -0
  410. package/esm/utils/index.js +25 -0
  411. package/esm/utils/index.js.map +1 -0
  412. package/esm/utils/linked-list.d.ts +21 -0
  413. package/esm/utils/linked-list.js +69 -0
  414. package/esm/utils/linked-list.js.map +1 -0
  415. package/esm/utils/links/bots.d.ts +71 -0
  416. package/esm/utils/links/bots.js +256 -0
  417. package/esm/utils/links/bots.js.map +1 -0
  418. package/esm/utils/links/bundle.d.ts +7 -0
  419. package/esm/utils/links/bundle.js +8 -0
  420. package/esm/utils/links/bundle.js.map +1 -0
  421. package/esm/utils/links/calls.d.ts +16 -0
  422. package/esm/utils/links/calls.js +56 -0
  423. package/esm/utils/links/calls.js.map +1 -0
  424. package/esm/utils/links/chat.d.ts +46 -0
  425. package/esm/utils/links/chat.js +157 -0
  426. package/esm/utils/links/chat.js.map +1 -0
  427. package/esm/utils/links/common.d.ts +31 -0
  428. package/esm/utils/links/common.js +56 -0
  429. package/esm/utils/links/common.js.map +1 -0
  430. package/esm/utils/links/index.d.ts +2 -0
  431. package/esm/utils/links/index.js +3 -0
  432. package/esm/utils/links/index.js.map +1 -0
  433. package/esm/utils/links/misc.d.ts +19 -0
  434. package/esm/utils/links/misc.js +74 -0
  435. package/esm/utils/links/misc.js.map +1 -0
  436. package/esm/utils/links/proxy.d.ts +17 -0
  437. package/esm/utils/links/proxy.js +58 -0
  438. package/esm/utils/links/proxy.js.map +1 -0
  439. package/esm/utils/links/stickers.d.ts +9 -0
  440. package/esm/utils/links/stickers.js +25 -0
  441. package/esm/utils/links/stickers.js.map +1 -0
  442. package/esm/utils/links/user.d.ts +27 -0
  443. package/esm/utils/links/user.js +78 -0
  444. package/esm/utils/links/user.js.map +1 -0
  445. package/esm/utils/logger.d.ts +54 -0
  446. package/esm/utils/logger.js +154 -0
  447. package/esm/utils/logger.js.map +1 -0
  448. package/esm/utils/long-utils.d.ts +75 -0
  449. package/esm/utils/long-utils.js +148 -0
  450. package/esm/utils/long-utils.js.map +1 -0
  451. package/esm/utils/lru-map.d.ts +21 -0
  452. package/esm/utils/lru-map.js +103 -0
  453. package/esm/utils/lru-map.js.map +1 -0
  454. package/esm/utils/lru-set.d.ts +22 -0
  455. package/esm/utils/lru-set.js +44 -0
  456. package/esm/utils/lru-set.js.map +1 -0
  457. package/esm/utils/misc-utils.d.ts +7 -0
  458. package/esm/utils/misc-utils.js +10 -0
  459. package/esm/utils/misc-utils.js.map +1 -0
  460. package/esm/utils/peer-utils.d.ts +35 -0
  461. package/esm/utils/peer-utils.js +179 -0
  462. package/esm/utils/peer-utils.js.map +1 -0
  463. package/esm/utils/platform/crypto.d.ts +1 -0
  464. package/esm/utils/platform/crypto.js +4 -0
  465. package/esm/utils/platform/crypto.js.map +1 -0
  466. package/esm/utils/platform/crypto.web.d.ts +1 -0
  467. package/esm/utils/platform/crypto.web.js +10 -0
  468. package/esm/utils/platform/crypto.web.js.map +1 -0
  469. package/esm/utils/platform/error-reporting.d.ts +3 -0
  470. package/esm/utils/platform/error-reporting.js +18 -0
  471. package/esm/utils/platform/error-reporting.js.map +1 -0
  472. package/esm/utils/platform/logging.d.ts +1 -0
  473. package/esm/utils/platform/logging.js +32 -0
  474. package/esm/utils/platform/logging.js.map +1 -0
  475. package/esm/utils/platform/logging.web.d.ts +1 -0
  476. package/esm/utils/platform/logging.web.js +31 -0
  477. package/esm/utils/platform/logging.web.js.map +1 -0
  478. package/esm/utils/platform/random.d.ts +1 -0
  479. package/esm/utils/platform/random.js +4 -0
  480. package/esm/utils/platform/random.js.map +1 -0
  481. package/esm/utils/platform/random.web.d.ts +1 -0
  482. package/esm/utils/platform/random.web.js +6 -0
  483. package/esm/utils/platform/random.web.js.map +1 -0
  484. package/esm/utils/platform/transport.d.ts +1 -0
  485. package/esm/utils/platform/transport.js +4 -0
  486. package/esm/utils/platform/transport.js.map +1 -0
  487. package/esm/utils/platform/transport.web.d.ts +1 -0
  488. package/esm/utils/platform/transport.web.js +12 -0
  489. package/esm/utils/platform/transport.web.js.map +1 -0
  490. package/esm/utils/sorted-array.d.ts +17 -0
  491. package/esm/utils/sorted-array.js +79 -0
  492. package/esm/utils/sorted-array.js.map +1 -0
  493. package/esm/utils/string-session.d.ts +11 -0
  494. package/esm/utils/string-session.js +68 -0
  495. package/esm/utils/string-session.js.map +1 -0
  496. package/esm/utils/tl-json.d.ts +13 -0
  497. package/esm/utils/tl-json.js +57 -0
  498. package/esm/utils/tl-json.js.map +1 -0
  499. package/esm/utils/type-assertions.d.ts +37 -0
  500. package/esm/utils/type-assertions.js +61 -0
  501. package/esm/utils/type-assertions.js.map +1 -0
  502. package/package.json +50 -0
@@ -0,0 +1,65 @@
1
+ "use strict";
2
+ // based on https://github.dev/tdlib/td/blob/master/tdutils/td/utils/FloodControlStrict.h
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.FloodControl = void 0;
5
+ /**
6
+ * Flood limiter, based on TDlib
7
+ */
8
+ class FloodControl {
9
+ constructor() {
10
+ this._wakeupAt = 1;
11
+ this._withoutUpdate = 0;
12
+ this._events = [];
13
+ // pair: duration, count
14
+ this._limits = [];
15
+ }
16
+ // no more than count in each duration
17
+ addLimit(duration, count) {
18
+ this._limits.push({ duration, count, pos: 0 });
19
+ this._withoutUpdate = 0;
20
+ }
21
+ addEvent(now) {
22
+ this._events.push(now);
23
+ if (this._withoutUpdate > 0) {
24
+ this._withoutUpdate -= 1;
25
+ }
26
+ else {
27
+ this._update(now);
28
+ }
29
+ }
30
+ clear() {
31
+ this._events.length = 0;
32
+ this._withoutUpdate = 0;
33
+ this._wakeupAt = 1;
34
+ this._limits.forEach((limit) => (limit.pos = 0));
35
+ }
36
+ get wakeupAt() {
37
+ return this._wakeupAt;
38
+ }
39
+ _update(now) {
40
+ let minPos = this._events.length;
41
+ this._withoutUpdate = Infinity;
42
+ this._limits.forEach((limit) => {
43
+ if (limit.count < this._events.length - limit.pos) {
44
+ limit.pos = this._events.length - limit.count;
45
+ }
46
+ while (limit.pos < this._events.length && this._events[limit.pos] + limit.duration < now) {
47
+ limit.pos += 1;
48
+ }
49
+ if (limit.count + limit.pos < this._events.length) {
50
+ this._wakeupAt = Math.max(this._wakeupAt, this._events[limit.pos] + limit.duration);
51
+ this._withoutUpdate = 0;
52
+ }
53
+ else {
54
+ this._withoutUpdate = Math.min(this._withoutUpdate, limit.count + limit.pos - this._events.length - 1);
55
+ }
56
+ minPos = Math.min(minPos, limit.pos);
57
+ });
58
+ if (minPos * 2 > this._events.length) {
59
+ this._limits.forEach((limit) => (limit.pos -= minPos));
60
+ this._events.splice(0, minPos);
61
+ }
62
+ }
63
+ }
64
+ exports.FloodControl = FloodControl;
65
+ //# sourceMappingURL=flood-control.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"flood-control.js","sourceRoot":"","sources":["../../../src/utils/flood-control.ts"],"names":[],"mappings":";AAAA,yFAAyF;;;AAQzF;;GAEG;AACH,MAAa,YAAY;IAAzB;QACY,cAAS,GAAG,CAAC,CAAA;QACb,mBAAc,GAAG,CAAC,CAAA;QAClB,YAAO,GAAa,EAAE,CAAA;QAC9B,wBAAwB;QAChB,YAAO,GAAwB,EAAE,CAAA;IAyD7C,CAAC;IAvDG,sCAAsC;IACtC,QAAQ,CAAC,QAAgB,EAAE,KAAa;QACpC,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,QAAQ,EAAE,KAAK,EAAE,GAAG,EAAE,CAAC,EAAE,CAAC,CAAA;QAC9C,IAAI,CAAC,cAAc,GAAG,CAAC,CAAA;IAC3B,CAAC;IAED,QAAQ,CAAC,GAAW;QAChB,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,GAAG,CAAC,CAAA;QAEtB,IAAI,IAAI,CAAC,cAAc,GAAG,CAAC,EAAE;YACzB,IAAI,CAAC,cAAc,IAAI,CAAC,CAAA;SAC3B;aAAM;YACH,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,CAAA;SACpB;IACL,CAAC;IAED,KAAK;QACD,IAAI,CAAC,OAAO,CAAC,MAAM,GAAG,CAAC,CAAA;QACvB,IAAI,CAAC,cAAc,GAAG,CAAC,CAAA;QACvB,IAAI,CAAC,SAAS,GAAG,CAAC,CAAA;QAClB,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC,KAAK,CAAC,GAAG,GAAG,CAAC,CAAC,CAAC,CAAA;IACpD,CAAC;IAED,IAAI,QAAQ;QACR,OAAO,IAAI,CAAC,SAAS,CAAA;IACzB,CAAC;IAEO,OAAO,CAAC,GAAW;QACvB,IAAI,MAAM,GAAG,IAAI,CAAC,OAAO,CAAC,MAAM,CAAA;QAChC,IAAI,CAAC,cAAc,GAAG,QAAQ,CAAA;QAE9B,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,KAAK,EAAE,EAAE;YAC3B,IAAI,KAAK,CAAC,KAAK,GAAG,IAAI,CAAC,OAAO,CAAC,MAAM,GAAG,KAAK,CAAC,GAAG,EAAE;gBAC/C,KAAK,CAAC,GAAG,GAAG,IAAI,CAAC,OAAO,CAAC,MAAM,GAAG,KAAK,CAAC,KAAK,CAAA;aAChD;YAED,OAAO,KAAK,CAAC,GAAG,GAAG,IAAI,CAAC,OAAO,CAAC,MAAM,IAAI,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC,QAAQ,GAAG,GAAG,EAAE;gBACtF,KAAK,CAAC,GAAG,IAAI,CAAC,CAAA;aACjB;YAED,IAAI,KAAK,CAAC,KAAK,GAAG,KAAK,CAAC,GAAG,GAAG,IAAI,CAAC,OAAO,CAAC,MAAM,EAAE;gBAC/C,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,SAAS,EAAE,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC,QAAQ,CAAC,CAAA;gBACnF,IAAI,CAAC,cAAc,GAAG,CAAC,CAAA;aAC1B;iBAAM;gBACH,IAAI,CAAC,cAAc,GAAG,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,cAAc,EAAE,KAAK,CAAC,KAAK,GAAG,KAAK,CAAC,GAAG,GAAG,IAAI,CAAC,OAAO,CAAC,MAAM,GAAG,CAAC,CAAC,CAAA;aACzG;YAED,MAAM,GAAG,IAAI,CAAC,GAAG,CAAC,MAAM,EAAE,KAAK,CAAC,GAAG,CAAC,CAAA;QACxC,CAAC,CAAC,CAAA;QAEF,IAAI,MAAM,GAAG,CAAC,GAAG,IAAI,CAAC,OAAO,CAAC,MAAM,EAAE;YAClC,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC,KAAK,CAAC,GAAG,IAAI,MAAM,CAAC,CAAC,CAAA;YACtD,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,EAAE,MAAM,CAAC,CAAA;SACjC;IACL,CAAC;CACJ;AA9DD,oCA8DC","sourcesContent":["// based on https://github.dev/tdlib/td/blob/master/tdutils/td/utils/FloodControlStrict.h\n\ninterface FloodControlLimit {\n duration: number\n count: number\n pos: number\n}\n\n/**\n * Flood limiter, based on TDlib\n */\nexport class FloodControl {\n private _wakeupAt = 1\n private _withoutUpdate = 0\n private _events: number[] = []\n // pair: duration, count\n private _limits: FloodControlLimit[] = []\n\n // no more than count in each duration\n addLimit(duration: number, count: number): void {\n this._limits.push({ duration, count, pos: 0 })\n this._withoutUpdate = 0\n }\n\n addEvent(now: number): void {\n this._events.push(now)\n\n if (this._withoutUpdate > 0) {\n this._withoutUpdate -= 1\n } else {\n this._update(now)\n }\n }\n\n clear(): void {\n this._events.length = 0\n this._withoutUpdate = 0\n this._wakeupAt = 1\n this._limits.forEach((limit) => (limit.pos = 0))\n }\n\n get wakeupAt(): number {\n return this._wakeupAt\n }\n\n private _update(now: number): void {\n let minPos = this._events.length\n this._withoutUpdate = Infinity\n\n this._limits.forEach((limit) => {\n if (limit.count < this._events.length - limit.pos) {\n limit.pos = this._events.length - limit.count\n }\n\n while (limit.pos < this._events.length && this._events[limit.pos] + limit.duration < now) {\n limit.pos += 1\n }\n\n if (limit.count + limit.pos < this._events.length) {\n this._wakeupAt = Math.max(this._wakeupAt, this._events[limit.pos] + limit.duration)\n this._withoutUpdate = 0\n } else {\n this._withoutUpdate = Math.min(this._withoutUpdate, limit.count + limit.pos - this._events.length - 1)\n }\n\n minPos = Math.min(minPos, limit.pos)\n })\n\n if (minPos * 2 > this._events.length) {\n this._limits.forEach((limit) => (limit.pos -= minPos))\n this._events.splice(0, minPos)\n }\n }\n}\n"]}
@@ -0,0 +1,13 @@
1
+ /**
2
+ * Throttle a function with a given delay.
3
+ * Similar to lodash.
4
+ *
5
+ * Throttling `F` for a delay of `D` means that
6
+ * `F` will be called no more than 1 time every `D`.
7
+ * In this implementation, `F` is called after `D`
8
+ * has passed since the previous non-throttled invocation
9
+ *
10
+ * @param func Function to throttle
11
+ * @param delay Throttle delay
12
+ */
13
+ export declare function throttle(func: () => void, delay: number): () => void;
@@ -0,0 +1,30 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.throttle = void 0;
4
+ /**
5
+ * Throttle a function with a given delay.
6
+ * Similar to lodash.
7
+ *
8
+ * Throttling `F` for a delay of `D` means that
9
+ * `F` will be called no more than 1 time every `D`.
10
+ * In this implementation, `F` is called after `D`
11
+ * has passed since the previous non-throttled invocation
12
+ *
13
+ * @param func Function to throttle
14
+ * @param delay Throttle delay
15
+ */
16
+ function throttle(func, delay) {
17
+ let timeout;
18
+ return function () {
19
+ if (timeout) {
20
+ return;
21
+ }
22
+ const later = () => {
23
+ timeout = null;
24
+ func();
25
+ };
26
+ timeout = setTimeout(later, delay);
27
+ };
28
+ }
29
+ exports.throttle = throttle;
30
+ //# sourceMappingURL=function-utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"function-utils.js","sourceRoot":"","sources":["../../../src/utils/function-utils.ts"],"names":[],"mappings":";;;AAAA;;;;;;;;;;;GAWG;AACH,SAAgB,QAAQ,CAAC,IAAgB,EAAE,KAAa;IACpD,IAAI,OAA8B,CAAA;IAElC,OAAO;QACH,IAAI,OAAO,EAAE;YACT,OAAM;SACT;QAED,MAAM,KAAK,GAAG,GAAG,EAAE;YACf,OAAO,GAAG,IAAI,CAAA;YACd,IAAI,EAAE,CAAA;QACV,CAAC,CAAA;QACD,OAAO,GAAG,UAAU,CAAC,KAAK,EAAE,KAAK,CAAC,CAAA;IACtC,CAAC,CAAA;AACL,CAAC;AAdD,4BAcC","sourcesContent":["/**\n * Throttle a function with a given delay.\n * Similar to lodash.\n *\n * Throttling `F` for a delay of `D` means that\n * `F` will be called no more than 1 time every `D`.\n * In this implementation, `F` is called after `D`\n * has passed since the previous non-throttled invocation\n *\n * @param func Function to throttle\n * @param delay Throttle delay\n */\nexport function throttle(func: () => void, delay: number): () => void {\n let timeout: NodeJS.Timeout | null\n\n return function () {\n if (timeout) {\n return\n }\n\n const later = () => {\n timeout = null\n func()\n }\n timeout = setTimeout(later, delay)\n }\n}\n"]}
@@ -0,0 +1,24 @@
1
+ export * from './async-lock.js';
2
+ export * from './bigint-utils.js';
3
+ export * from './buffer-utils.js';
4
+ export * from './condition-variable.js';
5
+ export * from './controllable-promise.js';
6
+ export * from './crypto/index.js';
7
+ export * from './default-dcs.js';
8
+ export * from './deque.js';
9
+ export * from './early-timer.js';
10
+ export * from './flood-control.js';
11
+ export * from './function-utils.js';
12
+ export * from './linked-list.js';
13
+ export * from './links/index.js';
14
+ export * from './logger.js';
15
+ export * from './long-utils.js';
16
+ export * from './lru-map.js';
17
+ export * from './lru-set.js';
18
+ export * from './misc-utils.js';
19
+ export * from './peer-utils.js';
20
+ export * from './sorted-array.js';
21
+ export * from './string-session.js';
22
+ export * from './tl-json.js';
23
+ export * from './type-assertions.js';
24
+ export * from '@mtcute/tl-runtime';
@@ -0,0 +1,41 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./async-lock.js"), exports);
18
+ __exportStar(require("./bigint-utils.js"), exports);
19
+ __exportStar(require("./buffer-utils.js"), exports);
20
+ __exportStar(require("./condition-variable.js"), exports);
21
+ __exportStar(require("./controllable-promise.js"), exports);
22
+ __exportStar(require("./crypto/index.js"), exports);
23
+ __exportStar(require("./default-dcs.js"), exports);
24
+ __exportStar(require("./deque.js"), exports);
25
+ __exportStar(require("./early-timer.js"), exports);
26
+ __exportStar(require("./flood-control.js"), exports);
27
+ __exportStar(require("./function-utils.js"), exports);
28
+ __exportStar(require("./linked-list.js"), exports);
29
+ __exportStar(require("./links/index.js"), exports);
30
+ __exportStar(require("./logger.js"), exports);
31
+ __exportStar(require("./long-utils.js"), exports);
32
+ __exportStar(require("./lru-map.js"), exports);
33
+ __exportStar(require("./lru-set.js"), exports);
34
+ __exportStar(require("./misc-utils.js"), exports);
35
+ __exportStar(require("./peer-utils.js"), exports);
36
+ __exportStar(require("./sorted-array.js"), exports);
37
+ __exportStar(require("./string-session.js"), exports);
38
+ __exportStar(require("./tl-json.js"), exports);
39
+ __exportStar(require("./type-assertions.js"), exports);
40
+ __exportStar(require("@mtcute/tl-runtime"), exports);
41
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/utils/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,kDAA+B;AAC/B,oDAAiC;AACjC,oDAAiC;AACjC,0DAAuC;AACvC,4DAAyC;AACzC,oDAAiC;AACjC,mDAAgC;AAChC,6CAA0B;AAC1B,mDAAgC;AAChC,qDAAkC;AAClC,sDAAmC;AACnC,mDAAgC;AAChC,mDAAgC;AAChC,8CAA2B;AAC3B,kDAA+B;AAC/B,+CAA4B;AAC5B,+CAA4B;AAC5B,kDAA+B;AAC/B,kDAA+B;AAC/B,oDAAiC;AACjC,sDAAmC;AACnC,+CAA4B;AAC5B,uDAAoC;AACpC,qDAAkC","sourcesContent":["export * from './async-lock.js'\nexport * from './bigint-utils.js'\nexport * from './buffer-utils.js'\nexport * from './condition-variable.js'\nexport * from './controllable-promise.js'\nexport * from './crypto/index.js'\nexport * from './default-dcs.js'\nexport * from './deque.js'\nexport * from './early-timer.js'\nexport * from './flood-control.js'\nexport * from './function-utils.js'\nexport * from './linked-list.js'\nexport * from './links/index.js'\nexport * from './logger.js'\nexport * from './long-utils.js'\nexport * from './lru-map.js'\nexport * from './lru-set.js'\nexport * from './misc-utils.js'\nexport * from './peer-utils.js'\nexport * from './sorted-array.js'\nexport * from './string-session.js'\nexport * from './tl-json.js'\nexport * from './type-assertions.js'\nexport * from '@mtcute/tl-runtime'\n"]}
@@ -0,0 +1,21 @@
1
+ interface LinkedListItem<T> {
2
+ v: T;
3
+ n?: LinkedListItem<T>;
4
+ p?: LinkedListItem<T>;
5
+ }
6
+ /**
7
+ * A sorted linked list.
8
+ */
9
+ export declare class SortedLinkedList<T> {
10
+ private comparator;
11
+ _first?: LinkedListItem<T>;
12
+ _last?: LinkedListItem<T>;
13
+ _size: number;
14
+ constructor(comparator: (a: T, b: T) => number);
15
+ get length(): number;
16
+ _remove(item: LinkedListItem<T>): void;
17
+ popFront(): T | undefined;
18
+ add(item: T): void;
19
+ clear(): void;
20
+ }
21
+ export {};
@@ -0,0 +1,73 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SortedLinkedList = void 0;
4
+ /**
5
+ * A sorted linked list.
6
+ */
7
+ class SortedLinkedList {
8
+ constructor(comparator) {
9
+ this.comparator = comparator;
10
+ this._size = 0;
11
+ }
12
+ get length() {
13
+ return this._size;
14
+ }
15
+ _remove(item) {
16
+ if (this._first === item) {
17
+ this._first = item.n;
18
+ }
19
+ if (this._last === item) {
20
+ this._last = item.p;
21
+ }
22
+ if (item.p)
23
+ item.p.n = item.n;
24
+ if (item.n)
25
+ item.n.p = item.p;
26
+ this._size -= 1;
27
+ }
28
+ popFront() {
29
+ if (!this._first)
30
+ return undefined;
31
+ const it = this._first;
32
+ this._first = this._first.n;
33
+ if (!this._first)
34
+ this._last = undefined;
35
+ this._size -= 1;
36
+ return it.v;
37
+ }
38
+ add(item) {
39
+ const it = { v: item };
40
+ if (!this._first) {
41
+ this._first = this._last = it;
42
+ }
43
+ else {
44
+ let cur = this._first;
45
+ while (cur && this.comparator(cur.v, it.v) < 0) {
46
+ cur = cur.n;
47
+ }
48
+ if (!cur) {
49
+ // reached end, the item should be new last
50
+ this._last.n = it;
51
+ it.p = this._last;
52
+ this._last = it;
53
+ }
54
+ else {
55
+ // `cur` is the first item greater or equal than the given
56
+ it.n = cur;
57
+ it.p = cur.p;
58
+ if (cur.p)
59
+ cur.p.n = it;
60
+ cur.p = it;
61
+ if (cur === this._first)
62
+ this._first = it;
63
+ }
64
+ }
65
+ this._size += 1;
66
+ }
67
+ clear() {
68
+ this._first = this._last = undefined;
69
+ this._size = 0;
70
+ }
71
+ }
72
+ exports.SortedLinkedList = SortedLinkedList;
73
+ //# sourceMappingURL=linked-list.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"linked-list.js","sourceRoot":"","sources":["../../../src/utils/linked-list.ts"],"names":[],"mappings":";;;AAMA;;GAEG;AACH,MAAa,gBAAgB;IAKzB,YAAoB,UAAkC;QAAlC,eAAU,GAAV,UAAU,CAAwB;QAFtD,UAAK,GAAG,CAAC,CAAA;IAEgD,CAAC;IAE1D,IAAI,MAAM;QACN,OAAO,IAAI,CAAC,KAAK,CAAA;IACrB,CAAC;IAED,OAAO,CAAC,IAAuB;QAC3B,IAAI,IAAI,CAAC,MAAM,KAAK,IAAI,EAAE;YACtB,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,CAAC,CAAA;SACvB;QAED,IAAI,IAAI,CAAC,KAAK,KAAK,IAAI,EAAE;YACrB,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC,CAAC,CAAA;SACtB;QAED,IAAI,IAAI,CAAC,CAAC;YAAE,IAAI,CAAC,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,CAAC,CAAA;QAC7B,IAAI,IAAI,CAAC,CAAC;YAAE,IAAI,CAAC,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,CAAC,CAAA;QAE7B,IAAI,CAAC,KAAK,IAAI,CAAC,CAAA;IACnB,CAAC;IAED,QAAQ;QACJ,IAAI,CAAC,IAAI,CAAC,MAAM;YAAE,OAAO,SAAS,CAAA;QAElC,MAAM,EAAE,GAAG,IAAI,CAAC,MAAM,CAAA;QACtB,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC,CAAC,CAAA;QAC3B,IAAI,CAAC,IAAI,CAAC,MAAM;YAAE,IAAI,CAAC,KAAK,GAAG,SAAS,CAAA;QAExC,IAAI,CAAC,KAAK,IAAI,CAAC,CAAA;QAEf,OAAO,EAAE,CAAC,CAAC,CAAA;IACf,CAAC;IAED,GAAG,CAAC,IAAO;QACP,MAAM,EAAE,GAAsB,EAAE,CAAC,EAAE,IAAI,EAAE,CAAA;QAEzC,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE;YACd,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,KAAK,GAAG,EAAE,CAAA;SAChC;aAAM;YACH,IAAI,GAAG,GAAkC,IAAI,CAAC,MAAM,CAAA;YAEpD,OAAO,GAAG,IAAI,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,GAAG,CAAC,EAAE;gBAC5C,GAAG,GAAG,GAAG,CAAC,CAAC,CAAA;aACd;YAED,IAAI,CAAC,GAAG,EAAE;gBACN,2CAA2C;gBAE3C,IAAI,CAAC,KAAM,CAAC,CAAC,GAAG,EAAE,CAAA;gBAClB,EAAE,CAAC,CAAC,GAAG,IAAI,CAAC,KAAK,CAAA;gBACjB,IAAI,CAAC,KAAK,GAAG,EAAE,CAAA;aAClB;iBAAM;gBACH,0DAA0D;gBAC1D,EAAE,CAAC,CAAC,GAAG,GAAG,CAAA;gBACV,EAAE,CAAC,CAAC,GAAG,GAAG,CAAC,CAAC,CAAA;gBACZ,IAAI,GAAG,CAAC,CAAC;oBAAE,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,EAAE,CAAA;gBACvB,GAAG,CAAC,CAAC,GAAG,EAAE,CAAA;gBAEV,IAAI,GAAG,KAAK,IAAI,CAAC,MAAM;oBAAE,IAAI,CAAC,MAAM,GAAG,EAAE,CAAA;aAC5C;SACJ;QAED,IAAI,CAAC,KAAK,IAAI,CAAC,CAAA;IACnB,CAAC;IAED,KAAK;QACD,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,KAAK,GAAG,SAAS,CAAA;QACpC,IAAI,CAAC,KAAK,GAAG,CAAC,CAAA;IAClB,CAAC;CACJ;AA1ED,4CA0EC","sourcesContent":["interface LinkedListItem<T> {\n v: T\n n?: LinkedListItem<T>\n p?: LinkedListItem<T>\n}\n\n/**\n * A sorted linked list.\n */\nexport class SortedLinkedList<T> {\n _first?: LinkedListItem<T>\n _last?: LinkedListItem<T>\n _size = 0\n\n constructor(private comparator: (a: T, b: T) => number) {}\n\n get length(): number {\n return this._size\n }\n\n _remove(item: LinkedListItem<T>): void {\n if (this._first === item) {\n this._first = item.n\n }\n\n if (this._last === item) {\n this._last = item.p\n }\n\n if (item.p) item.p.n = item.n\n if (item.n) item.n.p = item.p\n\n this._size -= 1\n }\n\n popFront(): T | undefined {\n if (!this._first) return undefined\n\n const it = this._first\n this._first = this._first.n\n if (!this._first) this._last = undefined\n\n this._size -= 1\n\n return it.v\n }\n\n add(item: T): void {\n const it: LinkedListItem<T> = { v: item }\n\n if (!this._first) {\n this._first = this._last = it\n } else {\n let cur: LinkedListItem<T> | undefined = this._first\n\n while (cur && this.comparator(cur.v, it.v) < 0) {\n cur = cur.n\n }\n\n if (!cur) {\n // reached end, the item should be new last\n\n this._last!.n = it\n it.p = this._last\n this._last = it\n } else {\n // `cur` is the first item greater or equal than the given\n it.n = cur\n it.p = cur.p\n if (cur.p) cur.p.n = it\n cur.p = it\n\n if (cur === this._first) this._first = it\n }\n }\n\n this._size += 1\n }\n\n clear(): void {\n this._first = this._last = undefined\n this._size = 0\n }\n}\n"]}
@@ -0,0 +1,71 @@
1
+ import { tl } from '@mtcute/tl';
2
+ /**
3
+ * Bot deeplinks
4
+ *
5
+ * Used to link to bots with a start parameter
6
+ */
7
+ export declare const botStart: import("./common.js").Deeplink<{
8
+ /** Bot username */
9
+ username: string;
10
+ /** Start parameter */
11
+ parameter: string;
12
+ }>;
13
+ type BotAdminRight = Exclude<keyof tl.RawChatAdminRights, '_'>;
14
+ /**
15
+ * Bot add to group links
16
+ *
17
+ * Used to ask the user to add a bot to a group, optionally asking for admin rights.
18
+ * Note that the user is still free to choose which rights to grant, and
19
+ * whether to grant them at all.
20
+ */
21
+ export declare const botAddToGroup: import("./common.js").Deeplink<{
22
+ /** Bot username */
23
+ bot: string;
24
+ /** If specified, the client will call `/start parameter` on the bot once the bot has been added */
25
+ parameter?: string | undefined;
26
+ /** Admin rights to request */
27
+ admin?: BotAdminRight[] | undefined;
28
+ }>;
29
+ /**
30
+ * Bot add to channel links
31
+ *
32
+ * Used to ask the user to add a bot to a channel, optionally with admin rights.
33
+ * Note that the user is still free to choose which rights to grant, and
34
+ * whether to grant them at all.
35
+ */
36
+ export declare const botAddToChannel: import("./common.js").Deeplink<{
37
+ /** Bot username */
38
+ bot: string;
39
+ /** Admin rights to request */
40
+ admin?: BotAdminRight[] | undefined;
41
+ }>;
42
+ /**
43
+ * Game links
44
+ *
45
+ * Used to share games.
46
+ */
47
+ export declare const botGame: import("./common.js").Deeplink<{
48
+ /** Bot username */
49
+ bot: string;
50
+ /** Game short name */
51
+ game: string;
52
+ }>;
53
+ /**
54
+ * Named bot web app links
55
+ *
56
+ * Used to share named bot web apps.
57
+ *
58
+ * These links are different from bot attachment menu deep links,
59
+ * because they don't require the user to install an attachment menu,
60
+ * and a single bot can offer multiple named web apps, distinguished by
61
+ * their `short_name`.
62
+ */
63
+ export declare const botWebApp: import("./common.js").Deeplink<{
64
+ /** Bot username */
65
+ bot: string;
66
+ /** App short name */
67
+ app: string;
68
+ /** Parameter to be passed by the client to messages.requestAppWebView as `start_param` */
69
+ parameter?: string | undefined;
70
+ }>;
71
+ export {};
@@ -0,0 +1,259 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.botWebApp = exports.botGame = exports.botAddToChannel = exports.botAddToGroup = exports.botStart = void 0;
4
+ const type_assertions_js_1 = require("../type-assertions.js");
5
+ const common_js_1 = require("./common.js");
6
+ /**
7
+ * Bot deeplinks
8
+ *
9
+ * Used to link to bots with a start parameter
10
+ */
11
+ exports.botStart = (0, common_js_1.deeplinkBuilder)({
12
+ internalBuild: ({ username, parameter }) => ['resolve', { domain: username, start: parameter }],
13
+ internalParse: (path, query) => {
14
+ if (path !== 'resolve')
15
+ return null;
16
+ const username = query.get('domain');
17
+ const parameter = query.get('start');
18
+ if (!username || !parameter)
19
+ return null;
20
+ return { username, parameter };
21
+ },
22
+ externalBuild: ({ username, parameter }) => [username, { start: parameter }],
23
+ externalParse: (path, query) => {
24
+ if (path.includes('/') || path[0] === '+' || path.length <= 2)
25
+ return null;
26
+ const username = path;
27
+ const parameter = query.get('start');
28
+ if (!parameter)
29
+ return null;
30
+ return { username, parameter };
31
+ },
32
+ });
33
+ function normalizeBotAdmin(rights) {
34
+ if (!rights?.length)
35
+ return;
36
+ return rights
37
+ .map((it) => {
38
+ switch (it) {
39
+ case 'changeInfo':
40
+ return 'change_info';
41
+ case 'postMessages':
42
+ return 'post_messages';
43
+ case 'editMessages':
44
+ return 'edit_messages';
45
+ case 'deleteMessages':
46
+ return 'delete_messages';
47
+ case 'banUsers':
48
+ return 'restrict_members';
49
+ case 'inviteUsers':
50
+ return 'invite_users';
51
+ case 'pinMessages':
52
+ return 'pin_messages';
53
+ case 'manageTopics':
54
+ return 'manage_topics';
55
+ case 'addAdmins':
56
+ return 'promote_members';
57
+ case 'manageCall':
58
+ return 'manage_video_chats';
59
+ case 'anonymous':
60
+ return 'anonymous';
61
+ case 'other':
62
+ return 'manage_chat';
63
+ case 'postStories':
64
+ return 'post_stories';
65
+ case 'editStories':
66
+ return 'edit_stories';
67
+ case 'deleteStories':
68
+ return 'delete_stories';
69
+ }
70
+ })
71
+ .join('+');
72
+ }
73
+ function parseBotAdmin(rights) {
74
+ if (!rights)
75
+ return;
76
+ return rights
77
+ .split('+')
78
+ .map((it) => {
79
+ switch (it) {
80
+ case 'change_info':
81
+ return 'changeInfo';
82
+ case 'post_messages':
83
+ return 'postMessages';
84
+ case 'edit_messages':
85
+ return 'editMessages';
86
+ case 'delete_messages':
87
+ return 'deleteMessages';
88
+ case 'restrict_members':
89
+ return 'banUsers';
90
+ case 'invite_users':
91
+ return 'inviteUsers';
92
+ case 'pin_messages':
93
+ return 'pinMessages';
94
+ case 'manage_topics':
95
+ return 'manageTopics';
96
+ case 'promote_members':
97
+ return 'addAdmins';
98
+ case 'manage_video_chats':
99
+ return 'manageCall';
100
+ case 'anonymous':
101
+ return 'anonymous';
102
+ case 'manage_chat':
103
+ return 'other';
104
+ case 'post_stories':
105
+ return 'postStories';
106
+ case 'edit_stories':
107
+ return 'editStories';
108
+ case 'delete_stories':
109
+ return 'deleteStories';
110
+ default:
111
+ return null;
112
+ }
113
+ })
114
+ .filter(type_assertions_js_1.isPresent);
115
+ }
116
+ /**
117
+ * Bot add to group links
118
+ *
119
+ * Used to ask the user to add a bot to a group, optionally asking for admin rights.
120
+ * Note that the user is still free to choose which rights to grant, and
121
+ * whether to grant them at all.
122
+ */
123
+ exports.botAddToGroup = (0, common_js_1.deeplinkBuilder)({
124
+ internalBuild: ({ bot, parameter, admin }) => [
125
+ 'resolve',
126
+ { domain: bot, startgroup: parameter ?? true, admin: normalizeBotAdmin(admin) },
127
+ ],
128
+ internalParse: (path, query) => {
129
+ if (path !== 'resolve')
130
+ return null;
131
+ const bot = query.get('domain');
132
+ const parameter = query.get('startgroup');
133
+ const admin = query.get('admin');
134
+ if (!bot || parameter === null)
135
+ return null;
136
+ return {
137
+ bot,
138
+ parameter: parameter === '' ? undefined : parameter,
139
+ admin: parseBotAdmin(admin),
140
+ };
141
+ },
142
+ externalBuild: ({ bot, parameter, admin }) => [
143
+ bot,
144
+ { startgroup: parameter ?? true, admin: normalizeBotAdmin(admin) },
145
+ ],
146
+ externalParse: (path, query) => {
147
+ if (path.includes('/') || path[0] === '+' || path.length <= 2)
148
+ return null;
149
+ const bot = path;
150
+ const parameter = query.get('startgroup');
151
+ const admin = query.get('admin');
152
+ if (parameter === null)
153
+ return null;
154
+ return {
155
+ bot,
156
+ parameter: parameter === '' ? undefined : parameter,
157
+ admin: parseBotAdmin(admin),
158
+ };
159
+ },
160
+ });
161
+ /**
162
+ * Bot add to channel links
163
+ *
164
+ * Used to ask the user to add a bot to a channel, optionally with admin rights.
165
+ * Note that the user is still free to choose which rights to grant, and
166
+ * whether to grant them at all.
167
+ */
168
+ exports.botAddToChannel = (0, common_js_1.deeplinkBuilder)({
169
+ internalBuild: ({ bot, admin }) => [
170
+ 'resolve',
171
+ { domain: bot, startchannel: true, admin: normalizeBotAdmin(admin) },
172
+ ],
173
+ internalParse: (path, query) => {
174
+ if (path !== 'resolve')
175
+ return null;
176
+ const bot = query.get('domain');
177
+ const parameter = query.get('startchannel');
178
+ const admin = query.get('admin');
179
+ if (!bot || parameter === null)
180
+ return null;
181
+ return {
182
+ bot,
183
+ admin: parseBotAdmin(admin),
184
+ };
185
+ },
186
+ externalBuild: ({ bot, admin }) => [bot, { startchannel: true, admin: normalizeBotAdmin(admin) }],
187
+ externalParse: (path, query) => {
188
+ if (path.includes('/') || path[0] === '+' || path.length <= 2)
189
+ return null;
190
+ const bot = path;
191
+ const parameter = query.get('startchannel');
192
+ const admin = query.get('admin');
193
+ if (parameter === null)
194
+ return null;
195
+ return {
196
+ bot,
197
+ admin: parseBotAdmin(admin),
198
+ };
199
+ },
200
+ });
201
+ /**
202
+ * Game links
203
+ *
204
+ * Used to share games.
205
+ */
206
+ exports.botGame = (0, common_js_1.deeplinkBuilder)({
207
+ internalBuild: ({ bot, game }) => ['resolve', { domain: bot, game }],
208
+ internalParse: (path, query) => {
209
+ if (path !== 'resolve')
210
+ return null;
211
+ const bot = query.get('domain');
212
+ const game = query.get('game');
213
+ if (!bot || !game)
214
+ return null;
215
+ return { bot, game };
216
+ },
217
+ externalBuild: ({ bot, game }) => [bot, { game }],
218
+ externalParse: (path, query) => {
219
+ if (path.includes('/') || path[0] === '+' || path.length <= 2)
220
+ return null;
221
+ const bot = path;
222
+ const game = query.get('game');
223
+ if (!game)
224
+ return null;
225
+ return { bot, game };
226
+ },
227
+ });
228
+ /**
229
+ * Named bot web app links
230
+ *
231
+ * Used to share named bot web apps.
232
+ *
233
+ * These links are different from bot attachment menu deep links,
234
+ * because they don't require the user to install an attachment menu,
235
+ * and a single bot can offer multiple named web apps, distinguished by
236
+ * their `short_name`.
237
+ */
238
+ exports.botWebApp = (0, common_js_1.deeplinkBuilder)({
239
+ internalBuild: ({ bot, app, parameter }) => ['resolve', { domain: bot, appname: app, startapp: parameter }],
240
+ internalParse: (path, query) => {
241
+ if (path !== 'resolve')
242
+ return null;
243
+ const bot = query.get('domain');
244
+ const app = query.get('appname');
245
+ const parameter = query.get('startapp');
246
+ if (!bot || !app)
247
+ return null;
248
+ return { bot, app, parameter: parameter || undefined };
249
+ },
250
+ externalBuild: ({ bot, app, parameter }) => [`${bot}/${app}`, { startapp: parameter }],
251
+ externalParse: (path, query) => {
252
+ const [bot, app, rest] = path.split('/');
253
+ if (!app || rest)
254
+ return null;
255
+ const parameter = query.get('startapp');
256
+ return { bot, app, parameter: parameter || undefined };
257
+ },
258
+ });
259
+ //# sourceMappingURL=bots.js.map