@mtkruto/node 0.0.835 → 0.0.901

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 (75) hide show
  1. package/esm/client/client.d.ts +23 -3
  2. package/esm/client/client.js +497 -76
  3. package/esm/client/client_abstract.d.ts +2 -0
  4. package/esm/client/client_abstract.js +14 -3
  5. package/esm/client/client_plain.js +18 -4
  6. package/esm/constants.d.ts +7 -5
  7. package/esm/constants.js +10 -6
  8. package/esm/deps/deno.land/std@0.190.0/encoding/base64.d.ts +11 -0
  9. package/esm/deps/deno.land/std@0.190.0/encoding/base64.js +140 -0
  10. package/esm/deps/deno.land/x/q@v0.0.1/mod.d.ts +6 -0
  11. package/esm/deps/deno.land/x/q@v0.0.1/mod.js +71 -0
  12. package/esm/deps.d.ts +2 -0
  13. package/esm/deps.js +2 -0
  14. package/esm/mod.d.ts +3 -3
  15. package/esm/mod.js +3 -3
  16. package/esm/storage/storage.d.ts +18 -0
  17. package/esm/storage/storage.js +103 -0
  18. package/esm/tl/1_tl_object.d.ts +0 -1
  19. package/esm/tl/1_tl_object.js +1 -1
  20. package/esm/tl/4_tl_writer.d.ts +5 -0
  21. package/esm/tl/5_rpc_result.d.ts +9 -0
  22. package/esm/tl/6_message.d.ts +10 -0
  23. package/esm/tl/{5_message.js → 6_message.js} +2 -2
  24. package/esm/tl/{6_message_container.d.ts → 7_message_container.d.ts} +1 -1
  25. package/esm/tl/{6_message_container.js → 7_message_container.js} +2 -2
  26. package/esm/transport/transport_provider.d.ts +7 -4
  27. package/esm/transport/transport_provider.js +11 -8
  28. package/esm/types/3_message.d.ts +5 -1
  29. package/esm/types/3_message.js +26 -22
  30. package/esm/utilities/1_message.d.ts +2 -2
  31. package/esm/utilities/1_message.js +3 -3
  32. package/esm/utilities/1_password.js +1 -1
  33. package/package.json +1 -1
  34. package/script/client/client.d.ts +23 -3
  35. package/script/client/client.js +497 -76
  36. package/script/client/client_abstract.d.ts +2 -0
  37. package/script/client/client_abstract.js +14 -3
  38. package/script/client/client_plain.js +18 -4
  39. package/script/constants.d.ts +7 -5
  40. package/script/constants.js +34 -7
  41. package/script/deps/deno.land/std@0.190.0/encoding/base64.d.ts +11 -0
  42. package/script/deps/deno.land/std@0.190.0/encoding/base64.js +145 -0
  43. package/script/deps/deno.land/x/q@v0.0.1/mod.d.ts +6 -0
  44. package/script/deps/deno.land/x/q@v0.0.1/mod.js +75 -0
  45. package/script/deps.d.ts +2 -0
  46. package/script/deps.js +6 -1
  47. package/script/mod.d.ts +3 -3
  48. package/script/mod.js +3 -3
  49. package/script/storage/storage.d.ts +18 -0
  50. package/script/storage/storage.js +126 -0
  51. package/script/tl/1_tl_object.d.ts +0 -1
  52. package/script/tl/1_tl_object.js +1 -1
  53. package/script/tl/4_tl_writer.d.ts +5 -0
  54. package/script/tl/5_rpc_result.d.ts +9 -0
  55. package/script/tl/6_message.d.ts +10 -0
  56. package/script/tl/{5_message.js → 6_message.js} +6 -6
  57. package/script/tl/{6_message_container.d.ts → 7_message_container.d.ts} +1 -1
  58. package/script/tl/{6_message_container.js → 7_message_container.js} +4 -4
  59. package/script/transport/transport_provider.d.ts +7 -4
  60. package/script/transport/transport_provider.js +11 -8
  61. package/script/types/3_message.d.ts +5 -1
  62. package/script/types/3_message.js +26 -22
  63. package/script/utilities/1_message.d.ts +2 -2
  64. package/script/utilities/1_message.js +9 -9
  65. package/script/utilities/1_password.js +1 -1
  66. package/esm/tl/3_tl_writer.d.ts +0 -5
  67. package/esm/tl/4_rpc_result.d.ts +0 -8
  68. package/esm/tl/5_message.d.ts +0 -11
  69. package/script/tl/3_tl_writer.d.ts +0 -5
  70. package/script/tl/4_rpc_result.d.ts +0 -8
  71. package/script/tl/5_message.d.ts +0 -11
  72. /package/esm/tl/{3_tl_writer.js → 4_tl_writer.js} +0 -0
  73. /package/esm/tl/{4_rpc_result.js → 5_rpc_result.js} +0 -0
  74. /package/script/tl/{3_tl_writer.js → 4_tl_writer.js} +0 -0
  75. /package/script/tl/{4_rpc_result.js → 5_rpc_result.js} +0 -0
@@ -11,13 +11,16 @@ const dcToNameMap = {
11
11
  "5": "flora",
12
12
  };
13
13
  export const defaultTransportProvider = ({ initialDc, wss }) => {
14
- return ({ dc, cdn }) => {
15
- dc ??= initialDc;
16
- wss ??= typeof location !== "undefined" && location.protocol == "http:" ? false : true;
17
- const url = `${wss ? "wss" : "ws"}://${dcToNameMap[dc]}${cdn ? "-1" : ""}.web.telegram.org/${dc.endsWith("-test") ? "apiws_test" : "apiws"}`;
18
- const connection = new ConnectionWebSocket(url);
19
- const transport = new TransportIntermediate(connection, true);
20
- const dcId = Number(dc[0]) + (dc.endsWith("-test") ? 10000 : 0) * (cdn ? -1 : 1);
21
- return { connection, transport, dcId };
14
+ return {
15
+ initialDc,
16
+ createTransport: ({ dc, cdn }) => {
17
+ dc ??= initialDc;
18
+ wss ??= typeof location !== "undefined" && location.protocol == "http:" ? false : true;
19
+ const url = `${wss ? "wss" : "ws"}://${dcToNameMap[dc]}${cdn ? "-1" : ""}.web.telegram.org/${dc.endsWith("-test") ? "apiws_test" : "apiws"}`;
20
+ const connection = new ConnectionWebSocket(url);
21
+ const transport = new TransportIntermediate(connection, true);
22
+ const dcId = Number(dc[0]) + (dc.endsWith("-test") ? 10000 : 0) * (cdn ? -1 : 1);
23
+ return { connection, transport, dcId };
24
+ },
22
25
  };
23
26
  };
@@ -19,4 +19,8 @@ export interface Message {
19
19
  views?: number;
20
20
  replyMarkup?: InlineKeyboardMarkup | ReplyKeyboardMarkup | ReplyKeyboardRemove | ForceReply;
21
21
  }
22
- export declare function constructMessage(message_: types.Message, users: types.TypeUser[], chats: types.TypeChat[]): Message;
22
+ export declare function constructMessage(message_: types.Message, getEntity: {
23
+ (peer: types.PeerUser): Promise<types.User | null>;
24
+ (peer: types.PeerChat): Promise<types.Chat | null>;
25
+ (peer: types.PeerChannel): Promise<types.Channel | null>;
26
+ }): Promise<Message>;
@@ -8,42 +8,46 @@ import { constructChat } from "./1_chat.js";
8
8
  import { constructUser } from "./1_user.js";
9
9
  import { constructInlineKeyboardMarkup } from "./2_inline_keyboard_markup.js";
10
10
  import { constructReplyKeyboardMarkup } from "./2_reply_keyboard_markup.js";
11
- export function constructMessage(message_, users, chats) {
11
+ export async function constructMessage(message_, getEntity) {
12
12
  let chat_ = null;
13
13
  if (message_.peerId instanceof types.PeerUser) {
14
- for (const user of users) {
15
- if (user instanceof types.User && user.id == message_.peerId.userId) {
16
- chat_ = constructChat(user);
17
- break;
18
- }
14
+ const entity = await getEntity(message_.peerId);
15
+ if (entity) {
16
+ chat_ = constructChat(entity);
17
+ }
18
+ else {
19
+ UNREACHABLE();
19
20
  }
20
21
  }
21
22
  else if (message_.peerId instanceof types.PeerChat) {
22
- for (const chat of chats) {
23
- if (chat instanceof types.Chat && chat.id == message_.peerId.chatId) {
24
- chat_ = constructChat(chat);
25
- break;
26
- }
23
+ const entity = await getEntity(message_.peerId);
24
+ if (entity) {
25
+ chat_ = constructChat(entity);
26
+ }
27
+ else {
28
+ UNREACHABLE();
27
29
  }
28
30
  }
29
31
  else if (message_.peerId instanceof types.PeerChannel) {
30
- for (const chat of chats) {
31
- if (chat instanceof types.Channel && chat.id == message_.peerId.channelId) {
32
- chat_ = constructChat(chat);
33
- break;
34
- }
32
+ const entity = await getEntity(message_.peerId);
33
+ if (entity) {
34
+ chat_ = constructChat(entity);
35
+ }
36
+ else {
37
+ UNREACHABLE();
35
38
  }
36
39
  }
37
- if (!chat_) {
40
+ else {
38
41
  UNREACHABLE();
39
42
  }
40
43
  const message = { id: message_.id, chat: chat_, views: message_.views };
41
44
  if (message_.fromId instanceof types.PeerUser) {
42
- for (const user of users) {
43
- if (user instanceof types.User && user.id == message_.fromId.userId) {
44
- message.from = constructUser(user);
45
- break;
46
- }
45
+ const entity = await getEntity(message_.fromId);
46
+ if (entity) {
47
+ message.from = constructUser(entity);
48
+ }
49
+ else {
50
+ UNREACHABLE();
47
51
  }
48
52
  }
49
53
  if (message_.message) {
@@ -1,5 +1,5 @@
1
- import { Message } from "../tl/5_message.js";
2
- import { MessageContainer } from "../tl/6_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): {
@@ -3,9 +3,9 @@ import { TLRawReader } from "../tl/0_tl_raw_reader.js";
3
3
  import { TLRawWriter } from "../tl/0_tl_raw_writer.js";
4
4
  import { id, serialize } from "../tl/1_tl_object.js";
5
5
  import { TLReader } from "../tl/3_tl_reader.js";
6
- import { RPCResult } from "../tl/4_rpc_result.js";
7
- import { Message } from "../tl/5_message.js";
8
- import { MessageContainer } from "../tl/6_message_container.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
9
  import { bufferFromBigInt, concat } from "./0_buffer.js";
10
10
  import { sha256 } from "./0_hash.js";
11
11
  let lastMsgId = 0n;
@@ -30,7 +30,7 @@ export function isSafePrime(primeBytes, g) {
30
30
  0xB9, 0x2F, 0xCC, 0x5B,
31
31
  ]);
32
32
  if (goodPrime.every((v, i) => v == primeBytes[i])) {
33
- if ([3, 4, 5, 7].includes(g)) { // It's good
33
+ if ([3, 4, 5, 7].includes(g)) {
34
34
  return true;
35
35
  }
36
36
  }
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "module": "./esm/mod.js",
3
3
  "main": "./script/mod.js",
4
4
  "name": "@mtkruto/node",
5
- "version": "0.0.835",
5
+ "version": "0.0.901",
6
6
  "description": "MTKruto for Node.js",
7
7
  "author": "Roj <rojvv@icloud.com>",
8
8
  "license": "LGPL-3.0-or-later",
@@ -1,6 +1,7 @@
1
1
  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
+ import { ReadObject } from "../tl/3_tl_reader.js";
4
5
  import { ClientAbstract } from "./client_abstract.js";
5
6
  import { Storage } from "../storage/storage.js";
6
7
  import { DC, TransportProvider } from "../transport/transport_provider.js";
@@ -9,6 +10,8 @@ import { ReplyKeyboardRemove } from "../types/0_reply_keyboard_remove.js";
9
10
  import { ForceReply } from "../types/0_force_reply.js";
10
11
  import { ReplyKeyboardMarkup } from "../types/2_reply_keyboard_markup.js";
11
12
  import { InlineKeyboardMarkup } from "../types/2_inline_keyboard_markup.js";
13
+ import { Message } from "../types/3_message.js";
14
+ export declare const getEntity: unique symbol;
12
15
  export declare const restartAuth: unique symbol;
13
16
  export declare enum ParseMode {
14
17
  None = "none",
@@ -19,7 +22,7 @@ export interface AuthorizeUserParams<S = string> {
19
22
  code: S | (() => MaybePromise<S>);
20
23
  password: S | (() => MaybePromise<S>);
21
24
  }
22
- export type UpdatesHandler = null | ((client: Client, update: types.Updates) => MaybePromise<void>);
25
+ export type UpdateHandler = null | ((client: Client, update: types.TypeUpdate) => MaybePromise<void>);
23
26
  export interface ClientParams {
24
27
  /**
25
28
  * Default parse mode. Defauls to `ParseMode.None`.
@@ -63,7 +66,8 @@ export declare class Client extends ClientAbstract {
63
66
  private state;
64
67
  private promises;
65
68
  private toAcknowledge;
66
- updatesHandler: UpdatesHandler;
69
+ private updateState?;
70
+ updateHandler: UpdateHandler;
67
71
  readonly parseMode: ParseMode;
68
72
  readonly appVersion: string;
69
73
  readonly deviceModel: string;
@@ -95,6 +99,7 @@ export declare class Client extends ClientAbstract {
95
99
  * Before establishing the connection, the session is saved.
96
100
  */
97
101
  connect(): Promise<void>;
102
+ private fetchState;
98
103
  /**
99
104
  * Calls [initConnection](1) and authorizes the client with one of the following:
100
105
  *
@@ -113,6 +118,7 @@ export declare class Client extends ClientAbstract {
113
118
  * [2]: https://core.telegram.org/method/updates.getState
114
119
  */
115
120
  authorize(params: string | types.AuthExportedAuthorization | AuthorizeUserParams): Promise<void>;
121
+ private messageProcessQueue;
116
122
  private receiveLoop;
117
123
  private pingLoop;
118
124
  /**
@@ -129,8 +135,20 @@ export declare class Client extends ClientAbstract {
129
135
  send<T extends (functions.Function<unknown> | types.Type) = functions.Function<unknown>>(function_: T): Promise<void>;
130
136
  private processChats;
131
137
  private processUsers;
138
+ private updateApplicationMutex;
139
+ private applyUpdateNoGap;
140
+ private applyUpdate;
132
141
  private processUpdates;
142
+ private setUpdateStateDate;
143
+ private getLocalState;
144
+ private updateGapRecoveryMutex;
145
+ private recoverUpdateGap;
146
+ private recoverChannelUpdateGap;
133
147
  getInputPeer(id: string | number): Promise<types.InputPeerChat | types.InputPeerUser | types.InputPeerChannel>;
148
+ [getEntity](peer: types.PeerUser): Promise<types.User | null>;
149
+ [getEntity](peer: types.PeerChat): Promise<types.Chat | null>;
150
+ [getEntity](peer: types.PeerChannel): Promise<types.Channel | null>;
151
+ processResult(result: ReadObject): Promise<void>;
134
152
  sendMessage(chatId: number | string, text: string, params?: {
135
153
  parseMode?: ParseMode;
136
154
  entities?: MessageEntity[];
@@ -141,5 +159,7 @@ export declare class Client extends ClientAbstract {
141
159
  messageThreadId?: number;
142
160
  sendAs?: number | string;
143
161
  replyMarkup?: InlineKeyboardMarkup | ReplyKeyboardMarkup | ReplyKeyboardRemove | ForceReply;
144
- }): Promise<import("../types/3_message.js").Message>;
162
+ }): Promise<Message>;
163
+ getMessages(chatId: number | string, messageIds: number[]): Promise<Message[]>;
164
+ getMessage(chatId: number | string, messageId: number): Promise<Message | null>;
145
165
  }