@mtkruto/node 0.0.834 → 0.0.900
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.
- package/esm/client/client.d.ts +29 -4
- package/esm/client/client.js +528 -71
- package/esm/client/client_abstract.d.ts +1 -1
- package/esm/connection/connection.d.ts +1 -1
- package/esm/constants.d.ts +2 -0
- package/esm/constants.js +2 -0
- package/esm/deps/deno.land/std@0.190.0/encoding/base64.d.ts +11 -0
- package/esm/deps/deno.land/std@0.190.0/encoding/base64.js +140 -0
- package/esm/deps/deno.land/x/q@v0.0.1/mod.d.ts +6 -0
- package/esm/deps/deno.land/x/q@v0.0.1/mod.js +71 -0
- package/esm/deps.d.ts +2 -0
- package/esm/deps.js +2 -0
- package/esm/mod.d.ts +3 -3
- package/esm/mod.js +3 -3
- package/esm/storage/storage.d.ts +19 -1
- package/esm/storage/storage.js +103 -0
- package/esm/storage/storage_local_storage.d.ts +1 -1
- package/esm/storage/storage_memory.d.ts +1 -1
- package/esm/storage/storage_session_storage.d.ts +1 -1
- package/esm/tl/1_tl_object.d.ts +0 -1
- package/esm/tl/1_tl_object.js +1 -1
- package/esm/tl/4_tl_writer.d.ts +5 -0
- package/esm/tl/5_rpc_result.d.ts +9 -0
- package/esm/tl/6_message.d.ts +10 -0
- package/esm/tl/{5_message.js → 6_message.js} +2 -2
- package/esm/tl/{6_message_container.d.ts → 7_message_container.d.ts} +1 -1
- package/esm/tl/{6_message_container.js → 7_message_container.js} +2 -2
- package/esm/transport/transport.d.ts +1 -1
- package/esm/types/0_chat_administrator_rights.d.ts +17 -0
- package/esm/types/0_chat_administrator_rights.js +38 -0
- package/esm/types/0_chat_photo.d.ts +24 -0
- package/esm/types/0_chat_photo.js +28 -0
- package/esm/types/0_force_reply.d.ts +8 -0
- package/esm/types/0_force_reply.js +17 -0
- package/esm/types/0_keyboard_button_poll_type.d.ts +3 -0
- package/esm/types/0_login_url.d.ts +6 -0
- package/esm/types/0_login_url.js +1 -0
- package/esm/types/0_message_entity.d.ts +1 -1
- package/esm/types/0_message_entity.js +2 -2
- package/esm/types/0_reply_keyboard_remove.d.ts +7 -0
- package/esm/types/0_reply_keyboard_remove.js +8 -0
- package/esm/types/0_web_app_info.d.ts +4 -0
- package/esm/types/0_web_app_info.js +3 -0
- package/esm/types/1_chat.d.ts +60 -0
- package/esm/types/1_chat.js +70 -0
- package/esm/types/1_inline_keyboard_button.d.ts +33 -0
- package/esm/types/1_inline_keyboard_button.js +63 -0
- package/esm/types/1_keyboard_button.d.ts +43 -0
- package/esm/types/1_keyboard_button.js +133 -0
- package/esm/types/1_user.d.ts +19 -0
- package/esm/types/1_user.js +25 -0
- package/esm/types/2_inline_keyboard_markup.d.ts +7 -0
- package/esm/types/2_inline_keyboard_markup.js +25 -0
- package/esm/types/2_reply_keyboard_markup.d.ts +12 -0
- package/esm/types/2_reply_keyboard_markup.js +37 -0
- package/esm/types/3_message.d.ts +26 -0
- package/esm/types/3_message.js +91 -0
- package/esm/utilities/0_control.d.ts +1 -0
- package/esm/utilities/0_control.js +3 -0
- package/esm/utilities/0_object.d.ts +1 -0
- package/esm/utilities/0_object.js +14 -0
- package/esm/utilities/0_types.js +1 -0
- package/esm/utilities/1_message.d.ts +2 -2
- package/esm/utilities/1_message.js +3 -3
- package/esm/utilities/1_password.js +1 -1
- package/package.json +1 -1
- package/script/client/client.d.ts +29 -4
- package/script/client/client.js +528 -71
- package/script/client/client_abstract.d.ts +1 -1
- package/script/connection/connection.d.ts +1 -1
- package/script/constants.d.ts +2 -0
- package/script/constants.js +3 -1
- package/script/deps/deno.land/std@0.190.0/encoding/base64.d.ts +11 -0
- package/script/deps/deno.land/std@0.190.0/encoding/base64.js +145 -0
- package/script/deps/deno.land/x/q@v0.0.1/mod.d.ts +6 -0
- package/script/deps/deno.land/x/q@v0.0.1/mod.js +75 -0
- package/script/deps.d.ts +2 -0
- package/script/deps.js +6 -1
- package/script/mod.d.ts +3 -3
- package/script/mod.js +3 -3
- package/script/storage/storage.d.ts +19 -1
- package/script/storage/storage.js +126 -0
- package/script/storage/storage_local_storage.d.ts +1 -1
- package/script/storage/storage_memory.d.ts +1 -1
- package/script/storage/storage_session_storage.d.ts +1 -1
- package/script/tl/1_tl_object.d.ts +0 -1
- package/script/tl/1_tl_object.js +1 -1
- package/script/tl/4_tl_writer.d.ts +5 -0
- package/script/tl/5_rpc_result.d.ts +9 -0
- package/script/tl/6_message.d.ts +10 -0
- package/script/tl/{5_message.js → 6_message.js} +6 -6
- package/script/tl/{6_message_container.d.ts → 7_message_container.d.ts} +1 -1
- package/script/tl/{6_message_container.js → 7_message_container.js} +4 -4
- package/script/transport/transport.d.ts +1 -1
- package/script/types/0_chat_administrator_rights.d.ts +17 -0
- package/script/types/0_chat_administrator_rights.js +66 -0
- package/script/types/0_chat_photo.d.ts +24 -0
- package/script/types/0_chat_photo.js +55 -0
- package/script/types/0_force_reply.d.ts +8 -0
- package/script/types/0_force_reply.js +45 -0
- package/script/types/0_keyboard_button_poll_type.d.ts +3 -0
- package/script/types/0_login_url.d.ts +6 -0
- package/script/types/0_login_url.js +2 -0
- package/script/types/0_message_entity.d.ts +1 -1
- package/script/types/0_message_entity.js +2 -2
- package/script/types/0_reply_keyboard_remove.d.ts +7 -0
- package/script/types/0_reply_keyboard_remove.js +36 -0
- package/script/types/0_web_app_info.d.ts +4 -0
- package/script/types/0_web_app_info.js +7 -0
- package/script/types/1_chat.d.ts +60 -0
- package/script/types/1_chat.js +97 -0
- package/script/types/1_inline_keyboard_button.d.ts +33 -0
- package/script/types/1_inline_keyboard_button.js +91 -0
- package/script/types/1_keyboard_button.d.ts +43 -0
- package/script/types/1_keyboard_button.js +161 -0
- package/script/types/1_user.d.ts +19 -0
- package/script/types/1_user.js +52 -0
- package/script/types/2_inline_keyboard_markup.d.ts +7 -0
- package/script/types/2_inline_keyboard_markup.js +53 -0
- package/script/types/2_reply_keyboard_markup.d.ts +12 -0
- package/script/types/2_reply_keyboard_markup.js +65 -0
- package/script/types/3_message.d.ts +26 -0
- package/script/types/3_message.js +118 -0
- package/script/utilities/0_control.d.ts +1 -0
- package/script/utilities/0_control.js +7 -0
- package/script/utilities/0_object.d.ts +1 -0
- package/script/utilities/0_object.js +18 -0
- package/script/utilities/0_types.js +2 -0
- package/script/utilities/1_message.d.ts +2 -2
- package/script/utilities/1_message.js +9 -9
- package/script/utilities/1_password.js +1 -1
- package/esm/tl/3_tl_writer.d.ts +0 -5
- package/esm/tl/4_rpc_result.d.ts +0 -8
- package/esm/tl/5_message.d.ts +0 -11
- package/script/tl/3_tl_writer.d.ts +0 -5
- package/script/tl/4_rpc_result.d.ts +0 -8
- package/script/tl/5_message.d.ts +0 -11
- /package/esm/tl/{3_tl_writer.js → 4_tl_writer.js} +0 -0
- /package/esm/tl/{4_rpc_result.js → 5_rpc_result.js} +0 -0
- /package/esm/{types.js → types/0_keyboard_button_poll_type.js} +0 -0
- /package/esm/{types.d.ts → utilities/0_types.d.ts} +0 -0
- /package/script/tl/{3_tl_writer.js → 4_tl_writer.js} +0 -0
- /package/script/tl/{4_rpc_result.js → 5_rpc_result.js} +0 -0
- /package/script/{types.js → types/0_keyboard_button_poll_type.js} +0 -0
- /package/script/{types.d.ts → utilities/0_types.d.ts} +0 -0
|
@@ -1,7 +1,7 @@
|
|
|
1
|
+
import { MaybePromise } from "../utilities/0_types.js";
|
|
1
2
|
import { Connection } from "../connection/connection.js";
|
|
2
3
|
import { Transport } from "../transport/transport.js";
|
|
3
4
|
import { DC } from "../transport/transport_provider.js";
|
|
4
|
-
import { MaybePromise } from "../types.js";
|
|
5
5
|
export declare abstract class ClientAbstract {
|
|
6
6
|
protected transportProvider: import("../transport/transport_provider.js").TransportProvider;
|
|
7
7
|
protected connection: Connection;
|
package/esm/constants.d.ts
CHANGED
|
@@ -14,3 +14,5 @@ export declare const USERNAME_TTL = 86400;
|
|
|
14
14
|
export declare const MAX_CHAT_ID = 999999999999;
|
|
15
15
|
export declare const MAX_CHANNEL_ID = 997852516352;
|
|
16
16
|
export declare const ZERO_CHANNEL_ID = -1000000000000;
|
|
17
|
+
export declare const CHANNEL_DIFFERENCE_LIMIT_USER = 100;
|
|
18
|
+
export declare const CHANNEL_DIFFERENCE_LIMIT_BOT = 100000;
|
package/esm/constants.js
CHANGED
|
@@ -72,3 +72,5 @@ export const USERNAME_TTL = 86400;
|
|
|
72
72
|
export const MAX_CHAT_ID = 999999999999;
|
|
73
73
|
export const MAX_CHANNEL_ID = 997852516352;
|
|
74
74
|
export const ZERO_CHANNEL_ID = -1000000000000;
|
|
75
|
+
export const CHANNEL_DIFFERENCE_LIMIT_USER = 100;
|
|
76
|
+
export const CHANNEL_DIFFERENCE_LIMIT_BOT = 100000;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* CREDIT: https://gist.github.com/enepomnyaschih/72c423f727d395eeaa09697058238727
|
|
3
|
+
* Encodes a given Uint8Array, ArrayBuffer or string into RFC4648 base64 representation
|
|
4
|
+
* @param data
|
|
5
|
+
*/
|
|
6
|
+
export declare function encode(data: ArrayBuffer | string): string;
|
|
7
|
+
/**
|
|
8
|
+
* Decodes a given RFC4648 base64 encoded string
|
|
9
|
+
* @param b64
|
|
10
|
+
*/
|
|
11
|
+
export declare function decode(b64: string): Uint8Array;
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
|
|
2
|
+
// This module is browser compatible.
|
|
3
|
+
/**
|
|
4
|
+
* {@linkcode encode} and {@linkcode decode} for
|
|
5
|
+
* [base64](https://en.wikipedia.org/wiki/Base64) encoding.
|
|
6
|
+
*
|
|
7
|
+
* This module is browser compatible.
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```ts
|
|
11
|
+
* import {
|
|
12
|
+
* decode,
|
|
13
|
+
* encode,
|
|
14
|
+
* } from "https://deno.land/std@$STD_VERSION/encoding/base64.ts";
|
|
15
|
+
*
|
|
16
|
+
* const b64Repr = "Zm9vYg==";
|
|
17
|
+
*
|
|
18
|
+
* const binaryData = decode(b64Repr);
|
|
19
|
+
* console.log(binaryData);
|
|
20
|
+
* // => Uint8Array [ 102, 111, 111, 98 ]
|
|
21
|
+
*
|
|
22
|
+
* console.log(encode(binaryData));
|
|
23
|
+
* // => Zm9vYg==
|
|
24
|
+
* ```
|
|
25
|
+
*
|
|
26
|
+
* @module
|
|
27
|
+
*/
|
|
28
|
+
const base64abc = [
|
|
29
|
+
"A",
|
|
30
|
+
"B",
|
|
31
|
+
"C",
|
|
32
|
+
"D",
|
|
33
|
+
"E",
|
|
34
|
+
"F",
|
|
35
|
+
"G",
|
|
36
|
+
"H",
|
|
37
|
+
"I",
|
|
38
|
+
"J",
|
|
39
|
+
"K",
|
|
40
|
+
"L",
|
|
41
|
+
"M",
|
|
42
|
+
"N",
|
|
43
|
+
"O",
|
|
44
|
+
"P",
|
|
45
|
+
"Q",
|
|
46
|
+
"R",
|
|
47
|
+
"S",
|
|
48
|
+
"T",
|
|
49
|
+
"U",
|
|
50
|
+
"V",
|
|
51
|
+
"W",
|
|
52
|
+
"X",
|
|
53
|
+
"Y",
|
|
54
|
+
"Z",
|
|
55
|
+
"a",
|
|
56
|
+
"b",
|
|
57
|
+
"c",
|
|
58
|
+
"d",
|
|
59
|
+
"e",
|
|
60
|
+
"f",
|
|
61
|
+
"g",
|
|
62
|
+
"h",
|
|
63
|
+
"i",
|
|
64
|
+
"j",
|
|
65
|
+
"k",
|
|
66
|
+
"l",
|
|
67
|
+
"m",
|
|
68
|
+
"n",
|
|
69
|
+
"o",
|
|
70
|
+
"p",
|
|
71
|
+
"q",
|
|
72
|
+
"r",
|
|
73
|
+
"s",
|
|
74
|
+
"t",
|
|
75
|
+
"u",
|
|
76
|
+
"v",
|
|
77
|
+
"w",
|
|
78
|
+
"x",
|
|
79
|
+
"y",
|
|
80
|
+
"z",
|
|
81
|
+
"0",
|
|
82
|
+
"1",
|
|
83
|
+
"2",
|
|
84
|
+
"3",
|
|
85
|
+
"4",
|
|
86
|
+
"5",
|
|
87
|
+
"6",
|
|
88
|
+
"7",
|
|
89
|
+
"8",
|
|
90
|
+
"9",
|
|
91
|
+
"+",
|
|
92
|
+
"/",
|
|
93
|
+
];
|
|
94
|
+
/**
|
|
95
|
+
* CREDIT: https://gist.github.com/enepomnyaschih/72c423f727d395eeaa09697058238727
|
|
96
|
+
* Encodes a given Uint8Array, ArrayBuffer or string into RFC4648 base64 representation
|
|
97
|
+
* @param data
|
|
98
|
+
*/
|
|
99
|
+
export function encode(data) {
|
|
100
|
+
const uint8 = typeof data === "string"
|
|
101
|
+
? new TextEncoder().encode(data)
|
|
102
|
+
: data instanceof Uint8Array
|
|
103
|
+
? data
|
|
104
|
+
: new Uint8Array(data);
|
|
105
|
+
let result = "", i;
|
|
106
|
+
const l = uint8.length;
|
|
107
|
+
for (i = 2; i < l; i += 3) {
|
|
108
|
+
result += base64abc[uint8[i - 2] >> 2];
|
|
109
|
+
result += base64abc[((uint8[i - 2] & 0x03) << 4) | (uint8[i - 1] >> 4)];
|
|
110
|
+
result += base64abc[((uint8[i - 1] & 0x0f) << 2) | (uint8[i] >> 6)];
|
|
111
|
+
result += base64abc[uint8[i] & 0x3f];
|
|
112
|
+
}
|
|
113
|
+
if (i === l + 1) {
|
|
114
|
+
// 1 octet yet to write
|
|
115
|
+
result += base64abc[uint8[i - 2] >> 2];
|
|
116
|
+
result += base64abc[(uint8[i - 2] & 0x03) << 4];
|
|
117
|
+
result += "==";
|
|
118
|
+
}
|
|
119
|
+
if (i === l) {
|
|
120
|
+
// 2 octets yet to write
|
|
121
|
+
result += base64abc[uint8[i - 2] >> 2];
|
|
122
|
+
result += base64abc[((uint8[i - 2] & 0x03) << 4) | (uint8[i - 1] >> 4)];
|
|
123
|
+
result += base64abc[(uint8[i - 1] & 0x0f) << 2];
|
|
124
|
+
result += "=";
|
|
125
|
+
}
|
|
126
|
+
return result;
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* Decodes a given RFC4648 base64 encoded string
|
|
130
|
+
* @param b64
|
|
131
|
+
*/
|
|
132
|
+
export function decode(b64) {
|
|
133
|
+
const binString = atob(b64);
|
|
134
|
+
const size = binString.length;
|
|
135
|
+
const bytes = new Uint8Array(size);
|
|
136
|
+
for (let i = 0; i < size; i++) {
|
|
137
|
+
bytes[i] = binString.charCodeAt(i);
|
|
138
|
+
}
|
|
139
|
+
return bytes;
|
|
140
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export declare function queue<T, R>(runner: (task: T) => R, concurrency: number): {
|
|
2
|
+
push: (task: T | T[]) => void;
|
|
3
|
+
drain: (fn?: any) => void | Promise<any>;
|
|
4
|
+
onError: (fn: (task: T, error: Error) => any) => (task: T, error: Error) => any;
|
|
5
|
+
onDone: (fn: (task: T, result: R) => any) => (task: T, result: R) => any;
|
|
6
|
+
};
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
export function queue(runner, concurrency) {
|
|
2
|
+
if (concurrency <= 0) {
|
|
3
|
+
throw new RangeError('concurrency can only be a positive integer');
|
|
4
|
+
}
|
|
5
|
+
if (!Number.isInteger(concurrency)) {
|
|
6
|
+
throw new RangeError('concurrency can only be a positive integer');
|
|
7
|
+
}
|
|
8
|
+
const tasks = [];
|
|
9
|
+
let running = 0;
|
|
10
|
+
let drains = [];
|
|
11
|
+
let onError = () => { };
|
|
12
|
+
let onDone = () => { };
|
|
13
|
+
let drainAwaiters = [];
|
|
14
|
+
function drained() {
|
|
15
|
+
drains.forEach((d) => d());
|
|
16
|
+
drains = [];
|
|
17
|
+
drainAwaiters.forEach((s) => s());
|
|
18
|
+
drainAwaiters = [];
|
|
19
|
+
}
|
|
20
|
+
async function runNext() {
|
|
21
|
+
if (running < concurrency && tasks.length > 0) {
|
|
22
|
+
running++;
|
|
23
|
+
const task = tasks.shift();
|
|
24
|
+
if (task) {
|
|
25
|
+
try {
|
|
26
|
+
const result = await runner(task);
|
|
27
|
+
onDone(task, result);
|
|
28
|
+
}
|
|
29
|
+
catch (err) {
|
|
30
|
+
onError(task, err);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
running--;
|
|
34
|
+
if (tasks.length > 0) {
|
|
35
|
+
queueMicrotask(runNext); // to prevent "Maximum call stack size exceeded"
|
|
36
|
+
}
|
|
37
|
+
else if (running === 0) {
|
|
38
|
+
drained();
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
return {
|
|
43
|
+
push: (task) => {
|
|
44
|
+
let needed = 1;
|
|
45
|
+
if (Array.isArray(task)) {
|
|
46
|
+
tasks.push(...task);
|
|
47
|
+
needed = task.length;
|
|
48
|
+
}
|
|
49
|
+
else {
|
|
50
|
+
tasks.push(task);
|
|
51
|
+
}
|
|
52
|
+
const free = concurrency - running;
|
|
53
|
+
for (let i = 0; i < Math.max(free, needed); i++) {
|
|
54
|
+
runNext();
|
|
55
|
+
}
|
|
56
|
+
},
|
|
57
|
+
drain: (fn) => {
|
|
58
|
+
if (fn) {
|
|
59
|
+
drains.push(fn);
|
|
60
|
+
}
|
|
61
|
+
else if (tasks.length > 0 || running > 0) {
|
|
62
|
+
return new Promise((resolve) => drainAwaiters.push(resolve));
|
|
63
|
+
}
|
|
64
|
+
else {
|
|
65
|
+
return Promise.resolve();
|
|
66
|
+
}
|
|
67
|
+
},
|
|
68
|
+
onError: (fn) => (onError = fn),
|
|
69
|
+
onDone: (fn) => (onDone = fn),
|
|
70
|
+
};
|
|
71
|
+
}
|
package/esm/deps.d.ts
CHANGED
|
@@ -5,3 +5,5 @@ 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 declare const debug: typeof debug_;
|
|
8
|
+
export { queue } from "./deps/deno.land/x/q@v0.0.1/mod.js";
|
|
9
|
+
export { decode as base64Decode, encode as base64Encode } from "./deps/deno.land/std@0.190.0/encoding/base64.js";
|
package/esm/deps.js
CHANGED
|
@@ -5,3 +5,5 @@ 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
|
+
export { decode as base64Decode, encode as base64Encode } from "./deps/deno.land/std@0.190.0/encoding/base64.js";
|
package/esm/mod.d.ts
CHANGED
|
@@ -7,9 +7,9 @@ export declare const utils: {
|
|
|
7
7
|
export { as } from "./tl/1_tl_object.js";
|
|
8
8
|
export * as types from "./tl/2_types.js";
|
|
9
9
|
export * as functions from "./tl/3_functions.js";
|
|
10
|
-
export * from "./tl/
|
|
11
|
-
export * from "./tl/
|
|
12
|
-
export * from "./tl/
|
|
10
|
+
export * from "./tl/5_rpc_result.js";
|
|
11
|
+
export * from "./tl/6_message.js";
|
|
12
|
+
export * from "./tl/7_message_container.js";
|
|
13
13
|
export * from "./client/client_plain.js";
|
|
14
14
|
export * from "./client/client.js";
|
|
15
15
|
export * from "./storage/storage.js";
|
package/esm/mod.js
CHANGED
|
@@ -4,9 +4,9 @@ export const utils = { checkPassword, getRandomId };
|
|
|
4
4
|
export { as } from "./tl/1_tl_object.js";
|
|
5
5
|
export * as types from "./tl/2_types.js";
|
|
6
6
|
export * as functions from "./tl/3_functions.js";
|
|
7
|
-
export * from "./tl/
|
|
8
|
-
export * from "./tl/
|
|
9
|
-
export * from "./tl/
|
|
7
|
+
export * from "./tl/5_rpc_result.js";
|
|
8
|
+
export * from "./tl/6_message.js";
|
|
9
|
+
export * from "./tl/7_message_container.js";
|
|
10
10
|
export * from "./client/client_plain.js";
|
|
11
11
|
export * from "./client/client.js";
|
|
12
12
|
export * from "./storage/storage.js";
|
package/esm/storage/storage.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { MaybePromise } from "../
|
|
1
|
+
import { MaybePromise } from "../utilities/0_types.js";
|
|
2
2
|
import { DC } from "../transport/transport_provider.js";
|
|
3
|
+
import * as types from "../tl/2_types.js";
|
|
3
4
|
export declare abstract class Storage {
|
|
4
5
|
private _authKeyId;
|
|
5
6
|
abstract init(): MaybePromise<void>;
|
|
@@ -20,4 +21,21 @@ export declare abstract class Storage {
|
|
|
20
21
|
private readonly username__;
|
|
21
22
|
updateUsernames(type: "user" | "channel", id: bigint, usernames: string[]): Promise<void>;
|
|
22
23
|
getUsername(username: string): Promise<readonly ["channel" | "user", bigint, Date] | null>;
|
|
24
|
+
private readonly state__;
|
|
25
|
+
setState(state: types.UpdatesState): Promise<void>;
|
|
26
|
+
getState(): Promise<types.UpdatesState | null>;
|
|
27
|
+
private readonly channelPts__;
|
|
28
|
+
setChannelPts(channelId: bigint, pts: number): Promise<void>;
|
|
29
|
+
getChannelPts(channelId: bigint): Promise<number | null>;
|
|
30
|
+
private readonly peer__;
|
|
31
|
+
setEntity(peer: types.Channel): Promise<void>;
|
|
32
|
+
setEntity(peer: types.Chat): Promise<void>;
|
|
33
|
+
setEntity(peer: types.User): Promise<void>;
|
|
34
|
+
getEntity(type: "channel", id: bigint): Promise<types.Channel | null>;
|
|
35
|
+
getEntity(type: "chat", id: bigint): Promise<types.Chat | null>;
|
|
36
|
+
getEntity(type: "user", id: bigint): Promise<types.User | null>;
|
|
37
|
+
getEntity(type: "channel" | "chat" | "user", id: bigint): Promise<types.Channel | types.Chat | types.User | null>;
|
|
38
|
+
private readonly accountType__;
|
|
39
|
+
setAccountType(type: "user" | "bot"): Promise<void>;
|
|
40
|
+
getAccountType(): Promise<"bot" | "user">;
|
|
23
41
|
}
|
package/esm/storage/storage.js
CHANGED
|
@@ -1,5 +1,10 @@
|
|
|
1
|
+
import { base64Decode, base64Encode } from "../deps.js";
|
|
2
|
+
import { UNREACHABLE } from "../utilities/0_control.js";
|
|
1
3
|
import { sha1 } from "../utilities/0_hash.js";
|
|
2
4
|
import { bigIntFromBuffer } from "../utilities/0_bigint.js";
|
|
5
|
+
import { serialize } from "../tl/1_tl_object.js";
|
|
6
|
+
import * as types from "../tl/2_types.js";
|
|
7
|
+
import { TLReader } from "../tl/3_tl_reader.js";
|
|
3
8
|
export class Storage {
|
|
4
9
|
constructor() {
|
|
5
10
|
Object.defineProperty(this, "_authKeyId", {
|
|
@@ -26,6 +31,30 @@ export class Storage {
|
|
|
26
31
|
writable: true,
|
|
27
32
|
value: "username__"
|
|
28
33
|
});
|
|
34
|
+
Object.defineProperty(this, "state__", {
|
|
35
|
+
enumerable: true,
|
|
36
|
+
configurable: true,
|
|
37
|
+
writable: true,
|
|
38
|
+
value: "state__"
|
|
39
|
+
});
|
|
40
|
+
Object.defineProperty(this, "channelPts__", {
|
|
41
|
+
enumerable: true,
|
|
42
|
+
configurable: true,
|
|
43
|
+
writable: true,
|
|
44
|
+
value: "channelPts__"
|
|
45
|
+
});
|
|
46
|
+
Object.defineProperty(this, "peer__", {
|
|
47
|
+
enumerable: true,
|
|
48
|
+
configurable: true,
|
|
49
|
+
writable: true,
|
|
50
|
+
value: "peer__"
|
|
51
|
+
});
|
|
52
|
+
Object.defineProperty(this, "accountType__", {
|
|
53
|
+
enumerable: true,
|
|
54
|
+
configurable: true,
|
|
55
|
+
writable: true,
|
|
56
|
+
value: "accountType__"
|
|
57
|
+
});
|
|
29
58
|
}
|
|
30
59
|
setDc(dc) {
|
|
31
60
|
return this.set("dc", dc);
|
|
@@ -95,4 +124,78 @@ export class Storage {
|
|
|
95
124
|
return null;
|
|
96
125
|
}
|
|
97
126
|
}
|
|
127
|
+
async setState(state) {
|
|
128
|
+
await this.set(this.state__, JSON.stringify({
|
|
129
|
+
date: state.date,
|
|
130
|
+
pts: state.pts,
|
|
131
|
+
qts: state.qts,
|
|
132
|
+
seq: state.seq,
|
|
133
|
+
unreadCount: state.unreadCount,
|
|
134
|
+
}));
|
|
135
|
+
}
|
|
136
|
+
async getState() {
|
|
137
|
+
const state__ = await this.get(this.state__);
|
|
138
|
+
if (state__ != null) {
|
|
139
|
+
const state_ = JSON.parse(state__);
|
|
140
|
+
return new types.UpdatesState({
|
|
141
|
+
date: state_.date,
|
|
142
|
+
pts: state_.pts,
|
|
143
|
+
qts: state_.qts,
|
|
144
|
+
seq: state_.seq,
|
|
145
|
+
unreadCount: state_.unreadCount,
|
|
146
|
+
});
|
|
147
|
+
}
|
|
148
|
+
else {
|
|
149
|
+
return null;
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
async setChannelPts(channelId, pts) {
|
|
153
|
+
await this.set(`${this.channelPts__}${channelId}`, String(pts));
|
|
154
|
+
}
|
|
155
|
+
async getChannelPts(channelId) {
|
|
156
|
+
const pts = await this.get(`${this.channelPts__}${channelId}`);
|
|
157
|
+
if (pts != null) {
|
|
158
|
+
return Number(pts);
|
|
159
|
+
}
|
|
160
|
+
else {
|
|
161
|
+
return null;
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
async setEntity(peer) {
|
|
165
|
+
const type = peer instanceof types.Channel ? "channel" : peer instanceof types.Chat ? "chat" : peer instanceof types.User ? "user" : UNREACHABLE();
|
|
166
|
+
await this.set(`${this.peer__}${type}${peer.id}`, base64Encode(peer[serialize]()));
|
|
167
|
+
}
|
|
168
|
+
async getEntity(type, id) {
|
|
169
|
+
const peer_ = await this.get(`${this.peer__}${type}${id}`);
|
|
170
|
+
if (peer_ != null) {
|
|
171
|
+
const reader = new TLReader(base64Decode(peer_));
|
|
172
|
+
return reader.readObject();
|
|
173
|
+
}
|
|
174
|
+
else {
|
|
175
|
+
return null;
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
async setAccountType(type) {
|
|
179
|
+
try {
|
|
180
|
+
await this.getAccountType();
|
|
181
|
+
UNREACHABLE();
|
|
182
|
+
}
|
|
183
|
+
catch (err) {
|
|
184
|
+
if (!(err instanceof Error) || !(err.message == "Unreachable")) {
|
|
185
|
+
throw err;
|
|
186
|
+
}
|
|
187
|
+
else {
|
|
188
|
+
await this.set(this.accountType__, type);
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
async getAccountType() {
|
|
193
|
+
const accountType = await this.get(this.accountType__);
|
|
194
|
+
if (accountType != null) {
|
|
195
|
+
return accountType;
|
|
196
|
+
}
|
|
197
|
+
else {
|
|
198
|
+
UNREACHABLE();
|
|
199
|
+
}
|
|
200
|
+
}
|
|
98
201
|
}
|
package/esm/tl/1_tl_object.d.ts
CHANGED
|
@@ -31,7 +31,6 @@ export declare abstract class TLObject {
|
|
|
31
31
|
[serialize](): Uint8Array;
|
|
32
32
|
[as]<T extends TLObjectConstructor<InstanceType<T>>>(constructor: T): InstanceType<T>;
|
|
33
33
|
}
|
|
34
|
-
export type MaybeVectorTLObject = TLObject | Array<MaybeVectorTLObject | TLObject>;
|
|
35
34
|
export interface TLObjectConstructor<T = TLObject> {
|
|
36
35
|
new (params: any): T;
|
|
37
36
|
[paramDesc]: ParamDesc;
|
package/esm/tl/1_tl_object.js
CHANGED
|
@@ -28,7 +28,7 @@ function serializeSingleParam(writer, value, type, ntype) {
|
|
|
28
28
|
return;
|
|
29
29
|
}
|
|
30
30
|
else {
|
|
31
|
-
throw new TypeError(`Expected ${type.name}`);
|
|
31
|
+
throw new TypeError(`Expected ${type.name} but received ${value == null ? null : value.constructor.name}`);
|
|
32
32
|
}
|
|
33
33
|
}
|
|
34
34
|
if (type == Uint8Array) {
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { id } from "./1_tl_object.js";
|
|
2
|
+
import { ReadObject } from "./3_tl_reader.js";
|
|
3
|
+
export declare class RPCResult {
|
|
4
|
+
readonly messageId: bigint;
|
|
5
|
+
readonly result: ReadObject;
|
|
6
|
+
static get [id](): number;
|
|
7
|
+
constructor(messageId: bigint, result: ReadObject);
|
|
8
|
+
static deserialize(buffer: Uint8Array): RPCResult;
|
|
9
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { ReadObject, TLReader } from "./3_tl_reader.js";
|
|
2
|
+
import { RPCResult } from "./5_rpc_result.js";
|
|
3
|
+
export declare class Message {
|
|
4
|
+
readonly id: bigint;
|
|
5
|
+
readonly seqNo: number;
|
|
6
|
+
readonly body: ReadObject | RPCResult;
|
|
7
|
+
constructor(id: bigint, seqNo: number, body: ReadObject | RPCResult);
|
|
8
|
+
serialize(): Uint8Array;
|
|
9
|
+
static deserialize(reader: TLReader): Message;
|
|
10
|
+
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { id, serialize } from "./1_tl_object.js";
|
|
2
2
|
import { TLReader } from "./3_tl_reader.js";
|
|
3
|
-
import { TLWriter } from "./
|
|
4
|
-
import { RPCResult } from "./
|
|
3
|
+
import { TLWriter } from "./4_tl_writer.js";
|
|
4
|
+
import { RPCResult } from "./5_rpc_result.js";
|
|
5
5
|
// TODO: test
|
|
6
6
|
function calculateLength(object) {
|
|
7
7
|
let length = 0;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { id } from "./1_tl_object.js";
|
|
2
2
|
import { TLReader } from "./3_tl_reader.js";
|
|
3
|
-
import { TLWriter } from "./
|
|
4
|
-
import { Message } from "./
|
|
3
|
+
import { TLWriter } from "./4_tl_writer.js";
|
|
4
|
+
import { Message } from "./6_message.js";
|
|
5
5
|
export class MessageContainer {
|
|
6
6
|
static get [id]() {
|
|
7
7
|
return 0x73F1F8DC;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import * as types from "../tl/2_types.js";
|
|
2
|
+
export interface ChatAdministratorRights {
|
|
3
|
+
isAnonymous: boolean;
|
|
4
|
+
canManageChat: boolean;
|
|
5
|
+
canDeleteMessages: boolean;
|
|
6
|
+
canManageVideoChats: boolean;
|
|
7
|
+
canRestrictMembers: boolean;
|
|
8
|
+
canPromoteMembers: boolean;
|
|
9
|
+
canChangeInfo: boolean;
|
|
10
|
+
canInviteUsers: boolean;
|
|
11
|
+
canPostMessages?: boolean;
|
|
12
|
+
canEditMessages?: boolean;
|
|
13
|
+
canPinMessages?: boolean;
|
|
14
|
+
canManageTopics?: boolean;
|
|
15
|
+
}
|
|
16
|
+
export declare function constructChatAdministratorRights(rights_: types.ChatAdminRights): ChatAdministratorRights;
|
|
17
|
+
export declare function chatAdministratorRightsToTlObject(rights: ChatAdministratorRights): types.ChatAdminRights;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import * as types from "../tl/2_types.js";
|
|
2
|
+
export function constructChatAdministratorRights(rights_) {
|
|
3
|
+
const rights = {
|
|
4
|
+
isAnonymous: rights_.anonymous || false,
|
|
5
|
+
canManageChat: rights_.other || false,
|
|
6
|
+
canDeleteMessages: rights_.deleteMessages || false,
|
|
7
|
+
canManageVideoChats: rights_.manageCall || false,
|
|
8
|
+
canRestrictMembers: rights_.banUsers || false,
|
|
9
|
+
canPromoteMembers: rights_.addAdmins || false,
|
|
10
|
+
canChangeInfo: rights_.changeInfo || false,
|
|
11
|
+
canInviteUsers: rights_.inviteUsers || false,
|
|
12
|
+
};
|
|
13
|
+
if (rights_.postMessages) {
|
|
14
|
+
rights.canPostMessages = rights_.postMessages;
|
|
15
|
+
}
|
|
16
|
+
if (rights_.editMessages) {
|
|
17
|
+
rights.canEditMessages = rights_.editMessages;
|
|
18
|
+
}
|
|
19
|
+
if (rights_.pinMessages) {
|
|
20
|
+
rights.canPinMessages = rights_.pinMessages;
|
|
21
|
+
}
|
|
22
|
+
if (rights_.manageTopics) {
|
|
23
|
+
rights.canManageTopics = rights_.manageTopics;
|
|
24
|
+
}
|
|
25
|
+
return rights;
|
|
26
|
+
}
|
|
27
|
+
export function chatAdministratorRightsToTlObject(rights) {
|
|
28
|
+
return new types.ChatAdminRights({
|
|
29
|
+
anonymous: rights.isAnonymous || undefined,
|
|
30
|
+
other: rights.canManageChat || undefined,
|
|
31
|
+
deleteMessages: rights.canDeleteMessages || undefined,
|
|
32
|
+
manageCall: rights.canManageChat || undefined,
|
|
33
|
+
banUsers: rights.canRestrictMembers || undefined,
|
|
34
|
+
addAdmins: rights.canPromoteMembers || undefined,
|
|
35
|
+
changeInfo: rights.canChangeInfo || undefined,
|
|
36
|
+
inviteUsers: rights.canInviteUsers || undefined,
|
|
37
|
+
});
|
|
38
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import * as types from "../tl/2_types.js";
|
|
2
|
+
export declare enum ChatPhotoType {
|
|
3
|
+
Chat = "chat",
|
|
4
|
+
User = "user"
|
|
5
|
+
}
|
|
6
|
+
export declare namespace ChatPhoto {
|
|
7
|
+
interface Base {
|
|
8
|
+
type: ChatPhotoType;
|
|
9
|
+
hasVideo: boolean;
|
|
10
|
+
photoId: bigint;
|
|
11
|
+
strippedThumb?: Uint8Array;
|
|
12
|
+
dcId: number;
|
|
13
|
+
}
|
|
14
|
+
interface User extends Base {
|
|
15
|
+
type: ChatPhotoType;
|
|
16
|
+
personal: boolean;
|
|
17
|
+
}
|
|
18
|
+
interface Chat extends Base {
|
|
19
|
+
type: ChatPhotoType;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
export type ChatPhoto = ChatPhoto.User | ChatPhoto.Chat;
|
|
23
|
+
export declare function constructChatPhoto(photo: types.ChatPhoto): ChatPhoto.Chat;
|
|
24
|
+
export declare function constructChatPhoto(photo: types.UserProfilePhoto): ChatPhoto.User;
|