@mtkruto/node 0.0.906 → 0.0.920

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 (115) hide show
  1. package/esm/{types/utilities → client}/0_html.d.ts +1 -1
  2. package/esm/{types/utilities → client}/0_html.js +2 -2
  3. package/esm/client/{utilities/0_message.d.ts → 0_message.d.ts} +2 -2
  4. package/esm/client/{utilities/0_message.js → 0_message.js} +10 -10
  5. package/esm/client/{utilities/0_password.d.ts → 0_password.d.ts} +2 -2
  6. package/esm/client/{utilities/0_password.js → 0_password.js} +5 -5
  7. package/{script/client/client_abstract.d.ts → esm/client/1_client_abstract.d.ts} +6 -5
  8. package/esm/client/{client_abstract.js → 1_client_abstract.js} +10 -4
  9. package/esm/client/{client_plain.d.ts → 2_client_plain.d.ts} +1 -1
  10. package/esm/client/{client_plain.js → 2_client_plain.js} +2 -2
  11. package/esm/client/{client.d.ts → 3_client.d.ts} +7 -5
  12. package/esm/client/{client.js → 3_client.js} +145 -83
  13. package/{script/connection/connection_web_socket.d.ts → esm/connection/1_connection_web_socket.d.ts} +1 -1
  14. package/esm/constants.d.ts +2 -2
  15. package/esm/constants.js +1 -1
  16. package/esm/deps.d.ts +1 -2
  17. package/esm/deps.js +0 -1
  18. package/esm/mod.d.ts +13 -13
  19. package/esm/mod.js +13 -13
  20. package/esm/storage/{storage.d.ts → 0_storage.d.ts} +1 -1
  21. package/{script/storage/storage_local_storage.d.ts → esm/storage/1_storage_local_storage.d.ts} +1 -1
  22. package/esm/storage/{storage_local_storage.js → 1_storage_local_storage.js} +1 -1
  23. package/{script/storage/storage_memory.d.ts → esm/storage/1_storage_memory.d.ts} +1 -1
  24. package/esm/storage/{storage_memory.js → 1_storage_memory.js} +1 -1
  25. package/esm/storage/{storage_session_storage.d.ts → 1_storage_session_storage.d.ts} +1 -1
  26. package/esm/storage/{storage_session_storage.js → 1_storage_session_storage.js} +1 -1
  27. package/esm/transport/{utilities/0_obfuscation.d.ts → 0_obfuscation.d.ts} +2 -2
  28. package/esm/transport/{utilities/0_obfuscation.js → 0_obfuscation.js} +3 -3
  29. package/esm/transport/{transport_abridged.d.ts → 1_transport_abridged.d.ts} +2 -2
  30. package/esm/transport/{transport_abridged.js → 1_transport_abridged.js} +2 -2
  31. package/esm/transport/{transport_intermediate.d.ts → 1_transport_intermediate.d.ts} +2 -2
  32. package/esm/transport/{transport_intermediate.js → 1_transport_intermediate.js} +2 -2
  33. package/{script/transport/transport_provider.d.ts → esm/transport/2_transport_provider.d.ts} +2 -2
  34. package/esm/transport/{transport_provider.js → 2_transport_provider.js} +2 -2
  35. package/esm/types/!0_file_id.d.ts +77 -0
  36. package/esm/types/!0_file_id.js +325 -0
  37. package/esm/types/0_chat_photo.d.ts +7 -14
  38. package/esm/types/0_chat_photo.js +32 -17
  39. package/esm/types/1_chat.js +4 -4
  40. package/esm/types/1_user.js +2 -2
  41. package/esm/types/3_message.js +9 -0
  42. package/esm/utilities/0_base64.d.ts +2 -0
  43. package/esm/utilities/0_base64.js +9 -0
  44. package/esm/utilities/0_rle.d.ts +2 -0
  45. package/esm/utilities/0_rle.js +49 -0
  46. package/package.json +1 -1
  47. package/script/{types/utilities → client}/0_html.d.ts +1 -1
  48. package/script/{types/utilities → client}/0_html.js +2 -2
  49. package/script/client/{utilities/0_message.d.ts → 0_message.d.ts} +2 -2
  50. package/script/client/{utilities/0_message.js → 0_message.js} +10 -10
  51. package/script/client/{utilities/0_password.d.ts → 0_password.d.ts} +2 -2
  52. package/script/client/{utilities/0_password.js → 0_password.js} +5 -5
  53. package/script/client/0_password_test.d.ts +1 -0
  54. package/{esm/client/client_abstract.d.ts → script/client/1_client_abstract.d.ts} +6 -5
  55. package/script/client/{client_abstract.js → 1_client_abstract.js} +10 -4
  56. package/script/client/{client_plain.d.ts → 2_client_plain.d.ts} +1 -1
  57. package/script/client/{client_plain.js → 2_client_plain.js} +3 -3
  58. package/script/client/{client.d.ts → 3_client.d.ts} +7 -5
  59. package/script/client/{client.js → 3_client.js} +146 -84
  60. package/{esm/connection/connection_web_socket.d.ts → script/connection/1_connection_web_socket.d.ts} +1 -1
  61. package/script/constants.d.ts +2 -2
  62. package/script/constants.js +1 -1
  63. package/script/deps.d.ts +1 -2
  64. package/script/deps.js +1 -3
  65. package/script/mod.d.ts +13 -13
  66. package/script/mod.js +13 -13
  67. package/script/storage/{storage.d.ts → 0_storage.d.ts} +1 -1
  68. package/{esm/storage/storage_local_storage.d.ts → script/storage/1_storage_local_storage.d.ts} +1 -1
  69. package/script/storage/{storage_local_storage.js → 1_storage_local_storage.js} +2 -2
  70. package/{esm/storage/storage_memory.d.ts → script/storage/1_storage_memory.d.ts} +1 -1
  71. package/script/storage/{storage_memory.js → 1_storage_memory.js} +2 -2
  72. package/script/storage/{storage_session_storage.d.ts → 1_storage_session_storage.d.ts} +1 -1
  73. package/script/storage/{storage_session_storage.js → 1_storage_session_storage.js} +2 -2
  74. package/script/transport/{utilities/0_obfuscation.d.ts → 0_obfuscation.d.ts} +2 -2
  75. package/script/transport/{utilities/0_obfuscation.js → 0_obfuscation.js} +3 -3
  76. package/script/transport/{transport_abridged.d.ts → 1_transport_abridged.d.ts} +2 -2
  77. package/script/transport/{transport_abridged.js → 1_transport_abridged.js} +3 -3
  78. package/script/transport/{transport_intermediate.d.ts → 1_transport_intermediate.d.ts} +2 -2
  79. package/script/transport/{transport_intermediate.js → 1_transport_intermediate.js} +3 -3
  80. package/{esm/transport/transport_provider.d.ts → script/transport/2_transport_provider.d.ts} +2 -2
  81. package/script/transport/{transport_provider.js → 2_transport_provider.js} +4 -4
  82. package/script/types/!0_file_id.d.ts +77 -0
  83. package/script/types/!0_file_id.js +329 -0
  84. package/script/types/0_chat_photo.d.ts +7 -14
  85. package/script/types/0_chat_photo.js +33 -18
  86. package/script/types/1_chat.js +4 -4
  87. package/script/types/1_user.js +2 -2
  88. package/script/types/3_message.js +9 -0
  89. package/script/utilities/0_base64.d.ts +2 -0
  90. package/script/utilities/0_base64.js +14 -0
  91. package/script/utilities/0_rle.d.ts +2 -0
  92. package/script/utilities/0_rle.js +54 -0
  93. package/script/utilities/0_rle_test.d.ts +1 -0
  94. package/esm/deps/deno.land/x/q@v0.0.1/mod.d.ts +0 -6
  95. package/esm/deps/deno.land/x/q@v0.0.1/mod.js +0 -71
  96. package/script/deps/deno.land/x/q@v0.0.1/mod.d.ts +0 -6
  97. package/script/deps/deno.land/x/q@v0.0.1/mod.js +0 -75
  98. /package/esm/client/{utilities/0_password_test.d.ts → 0_password_test.d.ts} +0 -0
  99. /package/esm/connection/{connection.d.ts → 0_connection.d.ts} +0 -0
  100. /package/esm/connection/{connection.js → 0_connection.js} +0 -0
  101. /package/esm/connection/{connection_web_socket.js → 1_connection_web_socket.js} +0 -0
  102. /package/esm/storage/{storage.js → 0_storage.js} +0 -0
  103. /package/esm/transport/{transport.d.ts → 0_transport.d.ts} +0 -0
  104. /package/esm/transport/{transport.js → 0_transport.js} +0 -0
  105. /package/esm/types/{utilities/0_id_color.d.ts → !0_id_color.d.ts} +0 -0
  106. /package/esm/types/{utilities/0_id_color.js → !0_id_color.js} +0 -0
  107. /package/{script/client/utilities/0_password_test.d.ts → esm/utilities/0_rle_test.d.ts} +0 -0
  108. /package/script/connection/{connection.d.ts → 0_connection.d.ts} +0 -0
  109. /package/script/connection/{connection.js → 0_connection.js} +0 -0
  110. /package/script/connection/{connection_web_socket.js → 1_connection_web_socket.js} +0 -0
  111. /package/script/storage/{storage.js → 0_storage.js} +0 -0
  112. /package/script/transport/{transport.d.ts → 0_transport.d.ts} +0 -0
  113. /package/script/transport/{transport.js → 0_transport.js} +0 -0
  114. /package/script/types/{utilities/0_id_color.d.ts → !0_id_color.d.ts} +0 -0
  115. /package/script/types/{utilities/0_id_color.js → !0_id_color.js} +0 -0
@@ -1,2 +1,2 @@
1
- import { MessageEntity } from "../0_message_entity.js";
1
+ import { MessageEntity } from "../types/0_message_entity.js";
2
2
  export declare function parseHtml(html: string): readonly [string, MessageEntity[]];
@@ -1,5 +1,5 @@
1
- import { Parser } from "../../deps.js";
2
- import { MessageEntityType } from "../0_message_entity.js";
1
+ import { Parser } from "../deps.js";
2
+ import { MessageEntityType } from "../types/0_message_entity.js";
3
3
  export function parseHtml(html) {
4
4
  let text = "";
5
5
  const entities = new Array();
@@ -1,5 +1,5 @@
1
- import { Message } from "../../tl/6_message.js";
2
- import { MessageContainer } from "../../tl/7_message_container.js";
1
+ import { Message } from "../tl/6_message.js";
2
+ import { MessageContainer } from "../tl/7_message_container.js";
3
3
  export declare function getMessageId(): bigint;
4
4
  export declare function packUnencryptedMessage(data: Uint8Array): Uint8Array;
5
5
  export declare function unpackUnencryptedMessage(buffer: Uint8Array): {
@@ -1,13 +1,13 @@
1
- import { assertEquals, ige256Decrypt, ige256Encrypt } from "../../deps.js";
2
- import { TLRawReader } from "../../tl/0_tl_raw_reader.js";
3
- import { TLRawWriter } from "../../tl/0_tl_raw_writer.js";
4
- import { id, serialize } from "../../tl/1_tl_object.js";
5
- import { TLReader } from "../../tl/3_tl_reader.js";
6
- import { RPCResult } from "../../tl/5_rpc_result.js";
7
- import { Message } from "../../tl/6_message.js";
8
- import { MessageContainer } from "../../tl/7_message_container.js";
9
- import { bufferFromBigInt, concat } from "../../utilities/0_buffer.js";
10
- import { sha256 } from "../../utilities/0_hash.js";
1
+ import { assertEquals, ige256Decrypt, ige256Encrypt } from "../deps.js";
2
+ import { TLRawReader } from "../tl/0_tl_raw_reader.js";
3
+ import { TLRawWriter } from "../tl/0_tl_raw_writer.js";
4
+ import { id, serialize } from "../tl/1_tl_object.js";
5
+ import { TLReader } from "../tl/3_tl_reader.js";
6
+ import { RPCResult } from "../tl/5_rpc_result.js";
7
+ import { Message } from "../tl/6_message.js";
8
+ import { MessageContainer } from "../tl/7_message_container.js";
9
+ import { bufferFromBigInt, concat } from "../utilities/0_buffer.js";
10
+ import { sha256 } from "../utilities/0_hash.js";
11
11
  let lastMsgId = 0n;
12
12
  export function getMessageId() {
13
13
  const now = new Date().getTime() / 1000 + 0;
@@ -1,5 +1,5 @@
1
- import * as types from "../../tl/2_types.js";
2
- import { sha256 } from "../../utilities/0_hash.js";
1
+ import * as types from "../tl/2_types.js";
2
+ import { sha256 } from "../utilities/0_hash.js";
3
3
  export declare function isSafePrime(primeBytes: Uint8Array, g: number): boolean;
4
4
  export declare const h: typeof sha256;
5
5
  export declare const sh: (data: Uint8Array, salt: Uint8Array) => Promise<Uint8Array>;
@@ -1,8 +1,8 @@
1
- import * as dntShim from "../../_dnt.shims.js";
2
- import * as types from "../../tl/2_types.js";
3
- import { bufferFromBigInt, concat } from "../../utilities/0_buffer.js";
4
- import { sha256 } from "../../utilities/0_hash.js";
5
- import { bigIntFromBuffer, getRandomBigInt, mod, modExp } from "../../utilities/0_bigint.js";
1
+ import * as dntShim from "../_dnt.shims.js";
2
+ import * as types from "../tl/2_types.js";
3
+ import { bufferFromBigInt, concat } from "../utilities/0_buffer.js";
4
+ import { sha256 } from "../utilities/0_hash.js";
5
+ import { bigIntFromBuffer, getRandomBigInt, mod, modExp } from "../utilities/0_bigint.js";
6
6
  export function isSafePrime(primeBytes, g) {
7
7
  // deno-fmt-ignore
8
8
  const goodPrime = new Uint8Array([
@@ -1,15 +1,16 @@
1
1
  import { MaybePromise } from "../utilities/0_types.js";
2
- import { Connection } from "../connection/connection.js";
3
- import { Transport } from "../transport/transport.js";
4
- import { DC } from "../transport/transport_provider.js";
2
+ import { Connection } from "../connection/0_connection.js";
3
+ import { Transport } from "../transport/0_transport.js";
4
+ import { DC } from "../transport/2_transport_provider.js";
5
5
  export declare abstract class ClientAbstract {
6
- protected transportProvider: import("../transport/transport_provider.js").TransportProvider;
6
+ protected transportProvider: import("../transport/2_transport_provider.js").TransportProvider;
7
+ protected readonly cdn: boolean;
7
8
  protected connection: Connection;
8
9
  protected transport: Transport;
9
10
  private _dcId;
10
11
  private _initialDc;
11
12
  get initialDc(): DC;
12
- constructor(transportProvider?: import("../transport/transport_provider.js").TransportProvider);
13
+ constructor(transportProvider?: import("../transport/2_transport_provider.js").TransportProvider, cdn?: boolean);
13
14
  get dcId(): number;
14
15
  setDc(dc: DC): MaybePromise<void>;
15
16
  get connected(): boolean;
@@ -1,17 +1,23 @@
1
1
  import { initTgCrypto } from "../deps.js";
2
2
  import { DEFAULT_INITIAL_DC } from "../constants.js";
3
- import { defaultTransportProvider } from "../transport/transport_provider.js";
3
+ import { defaultTransportProvider } from "../transport/2_transport_provider.js";
4
4
  export class ClientAbstract {
5
5
  get initialDc() {
6
6
  return this._initialDc;
7
7
  }
8
- constructor(transportProvider = defaultTransportProvider({ initialDc: DEFAULT_INITIAL_DC })) {
8
+ constructor(transportProvider = defaultTransportProvider({ initialDc: DEFAULT_INITIAL_DC }), cdn = false) {
9
9
  Object.defineProperty(this, "transportProvider", {
10
10
  enumerable: true,
11
11
  configurable: true,
12
12
  writable: true,
13
13
  value: transportProvider
14
14
  });
15
+ Object.defineProperty(this, "cdn", {
16
+ enumerable: true,
17
+ configurable: true,
18
+ writable: true,
19
+ value: cdn
20
+ });
15
21
  Object.defineProperty(this, "connection", {
16
22
  enumerable: true,
17
23
  configurable: true,
@@ -38,7 +44,7 @@ export class ClientAbstract {
38
44
  });
39
45
  const { initialDc, createTransport } = transportProvider;
40
46
  this._initialDc = initialDc;
41
- const { connection, transport, dcId } = createTransport({ cdn: false });
47
+ const { connection, transport, dcId } = createTransport({ cdn: this.cdn });
42
48
  this.connection = connection;
43
49
  this.transport = transport;
44
50
  this._dcId = dcId;
@@ -48,7 +54,7 @@ export class ClientAbstract {
48
54
  }
49
55
  // MaybePromise since `Client` has to deal with `Storage.set()`
50
56
  setDc(dc) {
51
- const { connection, transport, dcId } = this.transportProvider.createTransport({ dc, cdn: false });
57
+ const { connection, transport, dcId } = this.transportProvider.createTransport({ dc, cdn: this.cdn });
52
58
  this.connection = connection;
53
59
  this.transport = transport;
54
60
  this._dcId = dcId;
@@ -1,5 +1,5 @@
1
1
  import { Function } from "../tl/3_functions.js";
2
- import { ClientAbstract } from "./client_abstract.js";
2
+ import { ClientAbstract } from "./1_client_abstract.js";
3
3
  export declare class ClientPlain extends ClientAbstract {
4
4
  invoke<T extends Function<unknown>>(function_: T): Promise<T["__R"]>;
5
5
  createAuthKey(): Promise<{
@@ -9,8 +9,8 @@ import { serialize } from "../tl/1_tl_object.js";
9
9
  import { ClientDHInnerData, DHGenOK, PQInnerDataDC, ResPQ, ServerDHInnerData, ServerDHParamsOK } from "../tl/2_types.js";
10
10
  import { ReqDHParams, ReqPQMulti, SetClientDHParams } from "../tl/3_functions.js";
11
11
  import { TLReader } from "../tl/3_tl_reader.js";
12
- import { ClientAbstract } from "./client_abstract.js";
13
- import { packUnencryptedMessage, unpackUnencryptedMessage } from "./utilities/0_message.js";
12
+ import { ClientAbstract } from "./1_client_abstract.js";
13
+ import { packUnencryptedMessage, unpackUnencryptedMessage } from "./0_message.js";
14
14
  const d = debug("ClientPlain/createAuthKey");
15
15
  export class ClientPlain extends ClientAbstract {
16
16
  async invoke(function_) {
@@ -2,15 +2,15 @@ import { MaybePromise } from "../utilities/0_types.js";
2
2
  import * as types from "../tl/2_types.js";
3
3
  import * as functions from "../tl/3_functions.js";
4
4
  import { ReadObject } from "../tl/3_tl_reader.js";
5
- import { ClientAbstract } from "./client_abstract.js";
6
- import { Storage } from "../storage/storage.js";
7
- import { DC, TransportProvider } from "../transport/transport_provider.js";
5
+ import { Storage } from "../storage/0_storage.js";
6
+ import { DC, TransportProvider } from "../transport/2_transport_provider.js";
8
7
  import { MessageEntity } from "../types/0_message_entity.js";
9
8
  import { ReplyKeyboardRemove } from "../types/0_reply_keyboard_remove.js";
10
9
  import { ForceReply } from "../types/0_force_reply.js";
11
10
  import { ReplyKeyboardMarkup } from "../types/2_reply_keyboard_markup.js";
12
11
  import { InlineKeyboardMarkup } from "../types/2_inline_keyboard_markup.js";
13
12
  import { Message } from "../types/3_message.js";
13
+ import { ClientAbstract } from "./1_client_abstract.js";
14
14
  export declare const getEntity: unique symbol;
15
15
  export declare const restartAuth: unique symbol;
16
16
  export declare enum ParseMode {
@@ -83,7 +83,7 @@ export declare class Client extends ClientAbstract {
83
83
  * @param apiHash App's API hash from [my.telegram.org/apps](https://my.telegram.org/apps). Default to empty string (unset).
84
84
  * @param params Other parameters.
85
85
  */
86
- constructor(storage?: Storage, apiId?: number, apiHash?: string, params?: ClientParams);
86
+ constructor(storage?: Storage, apiId?: number, apiHash?: string, params?: ClientParams, cdn?: boolean);
87
87
  private storageInited;
88
88
  /**
89
89
  * Sets the DC and resets the auth key stored in the session provider
@@ -118,7 +118,6 @@ export declare class Client extends ClientAbstract {
118
118
  * [2]: https://core.telegram.org/method/updates.getState
119
119
  */
120
120
  authorize(params: string | types.AuthExportedAuthorization | AuthorizeUserParams): Promise<void>;
121
- private messageProcessQueue;
122
121
  private receiveLoop;
123
122
  private pingLoop;
124
123
  /**
@@ -138,6 +137,7 @@ export declare class Client extends ClientAbstract {
138
137
  private updateApplicationMutex;
139
138
  private applyUpdateNoGap;
140
139
  private applyUpdate;
140
+ private updateProcessLock;
141
141
  private processUpdates;
142
142
  private setUpdateStateDate;
143
143
  private getLocalState;
@@ -162,4 +162,6 @@ export declare class Client extends ClientAbstract {
162
162
  }): Promise<Omit<Message, "replyToMessage">>;
163
163
  getMessages(chatId: number | string, messageIds: number[]): Promise<Omit<Message, "replyToMessage">[]>;
164
164
  getMessage(chatId: number | string, messageId: number): Promise<Omit<Message, "replyToMessage"> | null>;
165
+ private downloadInner;
166
+ download(fileId_: string): Promise<AsyncGenerator<Uint8Array, void, unknown>>;
165
167
  }
@@ -1,4 +1,4 @@
1
- import { debug, gunzip, Mutex, queue } from "../deps.js";
1
+ import { debug, gunzip, Mutex } from "../deps.js";
2
2
  import { ackThreshold, CHANNEL_DIFFERENCE_LIMIT_BOT, CHANNEL_DIFFERENCE_LIMIT_USER, DEFAULT_APP_VERSION, DEFAULT_DEVICE_MODEL, DEFAULT_LANG_CODE, DEFAULT_LANG_PACK, DEFAULT_SYSTEM_LANG_CODE, DEFAULT_SYSTEM_VERSION, LAYER, MAX_CHANNEL_ID, MAX_CHAT_ID, USERNAME_TTL, ZERO_CHANNEL_ID } from "../constants.js";
3
3
  import { bigIntFromBuffer, getRandomBigInt, getRandomId } from "../utilities/0_bigint.js";
4
4
  import { UNREACHABLE } from "../utilities/0_control.js";
@@ -10,18 +10,19 @@ import { TLReader } from "../tl/3_tl_reader.js";
10
10
  import { RPCResult } from "../tl/5_rpc_result.js";
11
11
  import { Message as Message_ } from "../tl/6_message.js"; // MTProto API message
12
12
  import { MessageContainer } from "../tl/7_message_container.js";
13
- import { ClientAbstract } from "./client_abstract.js";
14
- import { ClientPlain } from "./client_plain.js";
15
- import { StorageMemory } from "../storage/storage_memory.js";
16
- import { parseHtml } from "../types/utilities/0_html.js";
13
+ import { StorageMemory } from "../storage/1_storage_memory.js";
14
+ import { FileID, FileType, ThumbnailSource } from "../types/!0_file_id.js";
17
15
  import { messageEntityToTlObject } from "../types/0_message_entity.js";
18
16
  import { replyKeyboardRemoveToTlObject } from "../types/0_reply_keyboard_remove.js";
19
17
  import { forceReplyToTlObject } from "../types/0_force_reply.js";
20
18
  import { replyKeyboardMarkupToTlObject } from "../types/2_reply_keyboard_markup.js";
21
19
  import { inlineKeyboardMarkupToTlObject } from "../types/2_inline_keyboard_markup.js";
22
20
  import { constructMessage } from "../types/3_message.js"; // high-level wrapper for Telegram API's message
23
- import { decryptMessage, encryptMessage, getMessageId } from "./utilities/0_message.js";
24
- import { checkPassword } from "./utilities/0_password.js";
21
+ import { decryptMessage, encryptMessage, getMessageId } from "./0_message.js";
22
+ import { parseHtml } from "./0_html.js";
23
+ import { checkPassword } from "./0_password.js";
24
+ import { ClientAbstract } from "./1_client_abstract.js";
25
+ import { ClientPlain } from "./2_client_plain.js";
25
26
  const d = debug("Client");
26
27
  const dGap = debug("Client/recoverUpdateGap");
27
28
  const dGapC = debug("Client/recoverChannelUpdateGap");
@@ -44,8 +45,8 @@ export class Client extends ClientAbstract {
44
45
  * @param apiHash App's API hash from [my.telegram.org/apps](https://my.telegram.org/apps). Default to empty string (unset).
45
46
  * @param params Other parameters.
46
47
  */
47
- constructor(storage = new StorageMemory(), apiId = 0, apiHash = "", params) {
48
- super(params?.transportProvider);
48
+ constructor(storage = new StorageMemory(), apiId = 0, apiHash = "", params, cdn = false) {
49
+ super(params?.transportProvider, cdn);
49
50
  Object.defineProperty(this, "storage", {
50
51
  enumerable: true,
51
52
  configurable: true,
@@ -154,68 +155,13 @@ export class Client extends ClientAbstract {
154
155
  writable: true,
155
156
  value: false
156
157
  });
157
- Object.defineProperty(this, "messageProcessQueue", {
158
+ Object.defineProperty(this, "updateApplicationMutex", {
158
159
  enumerable: true,
159
160
  configurable: true,
160
161
  writable: true,
161
- value: queue(async (message) => {
162
- let body = message.body;
163
- if (body instanceof types.GZIPPacked) {
164
- body = new TLReader(gunzip(body.packedData)).readObject();
165
- }
166
- dRecv("received %s", body.constructor.name);
167
- if (body instanceof types.Updates || body instanceof types.TypeUpdate) {
168
- await this.processUpdates(body);
169
- }
170
- else if (message.body instanceof RPCResult) {
171
- let result = message.body.result;
172
- if (result instanceof types.GZIPPacked) {
173
- result = new TLReader(gunzip(result.packedData)).readObject();
174
- }
175
- if (result instanceof types.RPCError) {
176
- dRecv("RPCResult: %d %s", result.errorCode, result.errorMessage);
177
- }
178
- else {
179
- dRecv("RPCResult: %s", result.constructor.name);
180
- }
181
- if (result instanceof types.Updates || result instanceof types.TypeUpdate) {
182
- await this.processUpdates(result);
183
- }
184
- else {
185
- await this.processResult(result);
186
- }
187
- const promise = this.promises.get(message.body.messageId);
188
- if (promise) {
189
- if (result instanceof types.RPCError) {
190
- promise.reject(result);
191
- }
192
- else {
193
- promise.resolve(result);
194
- }
195
- this.promises.delete(message.body.messageId);
196
- }
197
- }
198
- else if (message.body instanceof types.Pong) {
199
- const promise = this.promises.get(message.body.msgId);
200
- if (promise) {
201
- promise.resolve(message.body);
202
- this.promises.delete(message.body.msgId);
203
- }
204
- }
205
- else if (message.body instanceof types.BadMsgNotification || message.body instanceof types.BadServerSalt) {
206
- if (message.body instanceof types.BadServerSalt) {
207
- this.state.salt = message.body.newServerSalt;
208
- }
209
- const promise = this.promises.get(message.body.badMsgId);
210
- if (promise) {
211
- promise.resolve(message.body);
212
- this.promises.delete(message.body.badMsgId);
213
- }
214
- }
215
- this.toAcknowledge.add(message.id);
216
- }, 2)
162
+ value: new Mutex()
217
163
  });
218
- Object.defineProperty(this, "updateApplicationMutex", {
164
+ Object.defineProperty(this, "updateProcessLock", {
219
165
  enumerable: true,
220
166
  configurable: true,
221
167
  writable: true,
@@ -518,7 +464,64 @@ export class Client extends ClientAbstract {
518
464
  }
519
465
  const messages = decrypted instanceof MessageContainer ? decrypted.messages : [decrypted];
520
466
  for (const message of messages) {
521
- this.messageProcessQueue.push(message);
467
+ let body = message.body;
468
+ if (body instanceof types.GZIPPacked) {
469
+ body = new TLReader(gunzip(body.packedData)).readObject();
470
+ }
471
+ dRecv("received %s", body.constructor.name);
472
+ if (body instanceof types.Updates || body instanceof types.TypeUpdate) {
473
+ this.processUpdates(body);
474
+ }
475
+ else if (message.body instanceof RPCResult) {
476
+ let result = message.body.result;
477
+ if (result instanceof types.GZIPPacked) {
478
+ result = new TLReader(gunzip(result.packedData)).readObject();
479
+ }
480
+ if (result instanceof types.RPCError) {
481
+ dRecv("RPCResult: %d %s", result.errorCode, result.errorMessage);
482
+ }
483
+ else {
484
+ dRecv("RPCResult: %s", result.constructor.name);
485
+ }
486
+ const messageId = message.body.messageId;
487
+ const resolvePromise = () => {
488
+ const promise = this.promises.get(messageId);
489
+ if (promise) {
490
+ if (result instanceof types.RPCError) {
491
+ promise.reject(result);
492
+ }
493
+ else {
494
+ promise.resolve(result);
495
+ }
496
+ this.promises.delete(messageId);
497
+ }
498
+ };
499
+ if (result instanceof types.Updates || result instanceof types.TypeUpdate) {
500
+ this.processUpdates(result).then(resolvePromise);
501
+ }
502
+ else {
503
+ await this.processResult(result);
504
+ resolvePromise();
505
+ }
506
+ }
507
+ else if (message.body instanceof types.Pong) {
508
+ const promise = this.promises.get(message.body.msgId);
509
+ if (promise) {
510
+ promise.resolve(message.body);
511
+ this.promises.delete(message.body.msgId);
512
+ }
513
+ }
514
+ else if (message.body instanceof types.BadMsgNotification || message.body instanceof types.BadServerSalt) {
515
+ if (message.body instanceof types.BadServerSalt) {
516
+ this.state.salt = message.body.newServerSalt;
517
+ }
518
+ const promise = this.promises.get(message.body.badMsgId);
519
+ if (promise) {
520
+ promise.resolve(message.body);
521
+ this.promises.delete(message.body.badMsgId);
522
+ }
523
+ }
524
+ this.toAcknowledge.add(message.id);
522
525
  }
523
526
  }
524
527
  }
@@ -611,18 +614,20 @@ export class Client extends ClientAbstract {
611
614
  (update instanceof types.UpdateShortMessage) ||
612
615
  (update instanceof types.UpdateShortChatMessage) ||
613
616
  (update instanceof types.UpdateShortSentMessage)) {
614
- const localState = await this.getLocalState();
615
- if (localState.pts + update.ptsCount > update.pts) {
616
- // the update is already applied
617
- return;
618
- }
619
- else if (localState.pts + update.ptsCount < update.pts) {
620
- // there is an update gap that needs to be filled
621
- throw UPDATE_GAP;
617
+ if (update.pts != 0 && update.ptsCount != 0) {
618
+ const localState = await this.getLocalState();
619
+ if (localState.pts + update.ptsCount > update.pts) {
620
+ // the update is already applied
621
+ return;
622
+ }
623
+ else if (localState.pts + update.ptsCount < update.pts) {
624
+ // there is an update gap that needs to be filled
625
+ throw UPDATE_GAP;
626
+ }
627
+ localState.pts = update.pts;
628
+ d("applied update with pts %d", update.pts);
629
+ await this.storage.setState(localState);
622
630
  }
623
- localState.pts = update.pts;
624
- d("applied update with pts %d", update.pts);
625
- await this.storage.setState(localState);
626
631
  }
627
632
  else if (usePts &&
628
633
  ((update instanceof types.UpdateNewChannelMessage) ||
@@ -722,7 +727,8 @@ export class Client extends ClientAbstract {
722
727
  }
723
728
  }
724
729
  }
725
- async processUpdates(updates) {
730
+ async processUpdates(updates, release) {
731
+ release ??= await this.updateProcessLock.acquire();
726
732
  try {
727
733
  if (updates instanceof types.TypeUpdates) {
728
734
  if (updates instanceof types.Updates) {
@@ -730,7 +736,7 @@ export class Client extends ClientAbstract {
730
736
  await this.processUsers(updates.users);
731
737
  await this.setUpdateStateDate(updates.date);
732
738
  for (const update of updates.updates) {
733
- await this.processUpdates(update);
739
+ await this.processUpdates(update, release);
734
740
  }
735
741
  }
736
742
  else if (updates instanceof types.UpdateShortMessage ||
@@ -747,7 +753,7 @@ export class Client extends ClientAbstract {
747
753
  await this.processChats(updates.chats);
748
754
  await this.processUsers(updates.users);
749
755
  for (const update of updates.updates) {
750
- await this.processUpdates(update);
756
+ await this.processUpdates(update, release);
751
757
  }
752
758
  }
753
759
  }
@@ -776,6 +782,9 @@ export class Client extends ClientAbstract {
776
782
  catch (err) {
777
783
  d("error processing updates: %O", err);
778
784
  }
785
+ finally {
786
+ release();
787
+ }
779
788
  }
780
789
  async setUpdateStateDate(date) {
781
790
  const release = await this.updateApplicationMutex.acquire();
@@ -807,7 +816,7 @@ export class Client extends ClientAbstract {
807
816
  try {
808
817
  let state = await this.getLocalState();
809
818
  while (true) {
810
- const difference = await this.invoke(new functions.UpdatesGetDifference({ pts: state.pts, date: state.date, qts: state.qts }));
819
+ const difference = await this.invoke(new functions.UpdatesGetDifference({ pts: state.pts, date: state.date, qts: state.qts ?? 0 }));
811
820
  if (difference instanceof types.UpdatesDifference || difference instanceof types.UpdatesDifferenceSlice) {
812
821
  await this.processChats(difference.chats);
813
822
  await this.processUsers(difference.users);
@@ -818,6 +827,7 @@ export class Client extends ClientAbstract {
818
827
  await this.applyUpdateNoGap(update);
819
828
  }
820
829
  if (difference instanceof types.UpdatesDifference) {
830
+ await this.storage.setState(difference.state[as](types.UpdatesState));
821
831
  dGap("recovered from update gap");
822
832
  break;
823
833
  }
@@ -1111,4 +1121,56 @@ export class Client extends ClientAbstract {
1111
1121
  const messages = await this.getMessages(chatId, [messageId]);
1112
1122
  return messages[0] ?? null;
1113
1123
  }
1124
+ async *downloadInner(location, dcId) {
1125
+ let client = null;
1126
+ if (dcId != undefined && dcId != this.dcId) {
1127
+ const exportedAuth = await this.invoke(new functions.AuthExportAuthorization({ dcId }));
1128
+ client = new Client(new StorageMemory(), this.apiId, this.apiHash, {
1129
+ transportProvider: this.transportProvider,
1130
+ appVersion: this.appVersion,
1131
+ deviceModel: this.deviceModel,
1132
+ langCode: this.langCode,
1133
+ langPack: this.langPack,
1134
+ systemLangCode: this.systemLangCode,
1135
+ systemVersion: this.systemVersion,
1136
+ }, true);
1137
+ let dc = String(dcId);
1138
+ if (this.dcId < 0) {
1139
+ dc += "-test";
1140
+ }
1141
+ await client.setDc(dc);
1142
+ await client.connect();
1143
+ await client.authorize(exportedAuth);
1144
+ }
1145
+ const limit = 1024 * 1024;
1146
+ let offset = 0n;
1147
+ while (true) {
1148
+ const file = await (client ?? this).invoke(new functions.UploadGetFile({ location, offset, limit }));
1149
+ if (file instanceof types.UploadFile) {
1150
+ yield file.bytes;
1151
+ if (file.bytes.length < limit) {
1152
+ break;
1153
+ }
1154
+ else {
1155
+ offset += BigInt(file.bytes.length);
1156
+ }
1157
+ }
1158
+ else {
1159
+ UNREACHABLE();
1160
+ }
1161
+ }
1162
+ }
1163
+ async download(fileId_) {
1164
+ const fileId = FileID.decode(fileId_);
1165
+ switch (fileId.fileType) {
1166
+ case FileType.ChatPhoto: {
1167
+ const big = fileId.params.thumbnailSource == ThumbnailSource.ChatPhotoBig;
1168
+ const peer = await this.getInputPeer(fileId.params.chatId);
1169
+ const location = new types.InputPeerPhotoFileLocation({ big: big ? true : undefined, peer, photoId: fileId.params.mediaId });
1170
+ return this.downloadInner(location);
1171
+ }
1172
+ default:
1173
+ UNREACHABLE();
1174
+ }
1175
+ }
1114
1176
  }
@@ -1,4 +1,4 @@
1
- import { Connection } from "./connection.js";
1
+ import { Connection } from "./0_connection.js";
2
2
  export declare class ConnectionWebSocket implements Connection {
3
3
  private webSocket;
4
4
  private rMutex;
@@ -1,10 +1,10 @@
1
- import { DC } from "./transport/transport_provider.js";
1
+ import { DC } from "./transport/2_transport_provider.js";
2
2
  export declare const ackThreshold = 10;
3
3
  export declare const publicKeys: Map<bigint, [bigint, bigint]>;
4
4
  export declare const VECTOR_CONSTRUCTOR = 481674261;
5
5
  export declare const DEFAULT_INITIAL_DC: DC;
6
6
  export declare const LAYER = 158;
7
- export declare const DEFAULT_APP_VERSION = "MTKruto 0.0.906";
7
+ export declare const DEFAULT_APP_VERSION = "MTKruto 0.0.920";
8
8
  export declare const DEFAULT_DEVICE_MODEL: string;
9
9
  export declare const DEFAULT_LANG_CODE: string;
10
10
  export declare const DEFAULT_LANG_PACK = "";
package/esm/constants.js CHANGED
@@ -62,7 +62,7 @@ export const publicKeys = new Map([
62
62
  export const VECTOR_CONSTRUCTOR = 0x1CB5C415;
63
63
  export const DEFAULT_INITIAL_DC = "2-test";
64
64
  export const LAYER = 158;
65
- export const DEFAULT_APP_VERSION = "MTKruto 0.0.906";
65
+ export const DEFAULT_APP_VERSION = "MTKruto 0.0.920";
66
66
  // @ts-ignore: lib
67
67
  export const DEFAULT_DEVICE_MODEL = typeof dntShim.Deno === "undefined" ? typeof navigator === "undefined" ? typeof process === "undefined" ? "Unknown" : process.platform + "-" + process.arch : navigator.userAgent.split(" ")[0] : dntShim.Deno.build.os + "-" + dntShim.Deno.build.arch;
68
68
  export const DEFAULT_LANG_CODE = typeof navigator === "undefined" ? "en" : navigator.language.split("-")[0];
package/esm/deps.d.ts CHANGED
@@ -1,9 +1,8 @@
1
1
  export * from "./deps/deno.land/std@0.190.0/testing/asserts.js";
2
2
  export { ctr256Decrypt, ctr256Encrypt, factorize, ige256Decrypt, ige256Encrypt, init as initTgCrypto } from "./deps/deno.land/x/tgcrypto@0.1.3/mod.js";
3
3
  export { gunzip, gzip } from "./deps/raw.githubusercontent.com/MTKruto/compress/master/gzip/gzip.js";
4
- export { Mutex } from "async-mutex";
4
+ export { Mutex, type MutexInterface } from "async-mutex";
5
5
  export { Parser } from "./deps/deno.land/x/html_parser@v0.1.3/src/mod.js";
6
6
  import { debug as debug_ } from "./deps/raw.githubusercontent.com/MTKruto/debug/master/mod.js";
7
7
  export declare const debug: typeof debug_;
8
- export { queue } from "./deps/deno.land/x/q@v0.0.1/mod.js";
9
8
  export { decode as base64Decode, encode as base64Encode } from "./deps/deno.land/std@0.190.0/encoding/base64.js";
package/esm/deps.js CHANGED
@@ -5,5 +5,4 @@ export { Mutex } from "async-mutex";
5
5
  export { Parser } from "./deps/deno.land/x/html_parser@v0.1.3/src/mod.js";
6
6
  import { debug as debug_ } from "./deps/raw.githubusercontent.com/MTKruto/debug/master/mod.js";
7
7
  export const debug = (v) => debug_(`mtkruto/${v}`);
8
- export { queue } from "./deps/deno.land/x/q@v0.0.1/mod.js";
9
8
  export { decode as base64Decode, encode as base64Encode } from "./deps/deno.land/std@0.190.0/encoding/base64.js";
package/esm/mod.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { getRandomId } from "./utilities/0_bigint.js";
2
- import { checkPassword } from "./client/utilities/0_password.js";
2
+ import { checkPassword } from "./client/0_password.js";
3
3
  export declare const utils: {
4
4
  checkPassword: typeof checkPassword;
5
5
  getRandomId: typeof getRandomId;
@@ -10,16 +10,16 @@ export * as functions from "./tl/3_functions.js";
10
10
  export * from "./tl/5_rpc_result.js";
11
11
  export * from "./tl/6_message.js";
12
12
  export * from "./tl/7_message_container.js";
13
- export * from "./client/client_plain.js";
14
- export * from "./client/client.js";
15
- export * from "./storage/storage.js";
16
- export * from "./storage/storage_memory.js";
17
- export * from "./storage/storage_local_storage.js";
18
- export * from "./storage/storage_session_storage.js";
19
- export * from "./transport/transport_abridged.js";
20
- export * from "./transport/transport_intermediate.js";
21
- export * from "./transport/transport.js";
22
- export * from "./transport/transport_provider.js";
23
- export * from "./connection/connection.js";
24
- export * from "./connection/connection_web_socket.js";
13
+ export * from "./client/2_client_plain.js";
14
+ export * from "./client/3_client.js";
15
+ export * from "./storage/0_storage.js";
16
+ export * from "./storage/1_storage_memory.js";
17
+ export * from "./storage/1_storage_local_storage.js";
18
+ export * from "./storage/1_storage_session_storage.js";
19
+ export * from "./transport/1_transport_abridged.js";
20
+ export * from "./transport/1_transport_intermediate.js";
21
+ export * from "./transport/0_transport.js";
22
+ export * from "./transport/2_transport_provider.js";
23
+ export * from "./connection/0_connection.js";
24
+ export * from "./connection/1_connection_web_socket.js";
25
25
  export { DEFAULT_APP_VERSION, DEFAULT_DEVICE_MODEL, DEFAULT_INITIAL_DC, DEFAULT_LANG_CODE, DEFAULT_LANG_PACK, DEFAULT_SYSTEM_LANG_CODE, DEFAULT_SYSTEM_VERSION, LAYER } from "./constants.js";