teleproto 1.214.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.
- package/CryptoFile.d.ts +2 -0
- package/CryptoFile.js +37 -0
- package/Helpers.d.ts +150 -0
- package/Helpers.js +477 -0
- package/LICENSE +23 -0
- package/Password.d.ts +14 -0
- package/Password.js +270 -0
- package/README.md +98 -0
- package/Utils.d.ts +227 -0
- package/Utils.js +1247 -0
- package/Version.d.ts +1 -0
- package/Version.js +4 -0
- package/client/2fa.d.ts +48 -0
- package/client/2fa.js +108 -0
- package/client/TelegramClient.d.ts +1043 -0
- package/client/TelegramClient.js +1181 -0
- package/client/account.d.ts +0 -0
- package/client/account.js +1 -0
- package/client/auth.d.ts +92 -0
- package/client/auth.js +388 -0
- package/client/bots.d.ts +6 -0
- package/client/bots.js +23 -0
- package/client/buttons.d.ts +4 -0
- package/client/buttons.js +86 -0
- package/client/chats.d.ts +45 -0
- package/client/chats.js +350 -0
- package/client/dialogs.d.ts +52 -0
- package/client/dialogs.js +174 -0
- package/client/downloads.d.ts +156 -0
- package/client/downloads.js +614 -0
- package/client/fs.d.ts +1 -0
- package/client/fs.js +17 -0
- package/client/index.d.ts +15 -0
- package/client/index.js +64 -0
- package/client/messageParse.d.ts +17 -0
- package/client/messageParse.js +191 -0
- package/client/messages.d.ts +263 -0
- package/client/messages.js +813 -0
- package/client/os.d.ts +2 -0
- package/client/os.js +37 -0
- package/client/path.d.ts +2 -0
- package/client/path.js +7 -0
- package/client/telegramBaseClient.d.ts +237 -0
- package/client/telegramBaseClient.js +368 -0
- package/client/updates.d.ts +33 -0
- package/client/updates.js +260 -0
- package/client/uploads.d.ts +136 -0
- package/client/uploads.js +514 -0
- package/client/users.d.ts +29 -0
- package/client/users.js +490 -0
- package/crypto/AuthKey.d.ts +19 -0
- package/crypto/AuthKey.js +76 -0
- package/crypto/CTR.d.ts +5 -0
- package/crypto/CTR.js +16 -0
- package/crypto/Factorizator.d.ts +19 -0
- package/crypto/Factorizator.js +74 -0
- package/crypto/IGE.d.ts +11 -0
- package/crypto/IGE.js +115 -0
- package/crypto/RSA.d.ts +14 -0
- package/crypto/RSA.js +70 -0
- package/crypto/converters.d.ts +19 -0
- package/crypto/converters.js +52 -0
- package/crypto/crypto.d.ts +19 -0
- package/crypto/crypto.js +58 -0
- package/crypto/words.d.ts +6 -0
- package/crypto/words.js +47 -0
- package/define.d.ts +77 -0
- package/entityCache.d.ts +7 -0
- package/entityCache.js +79 -0
- package/errors/Common.d.ts +71 -0
- package/errors/Common.js +122 -0
- package/errors/RPCBaseErrors.d.ts +84 -0
- package/errors/RPCBaseErrors.js +134 -0
- package/errors/RPCErrorList.d.ts +37 -0
- package/errors/RPCErrorList.js +117 -0
- package/errors/index.d.ts +11 -0
- package/errors/index.js +32 -0
- package/events/Album.d.ts +36 -0
- package/events/Album.js +104 -0
- package/events/CallbackQuery.d.ts +73 -0
- package/events/CallbackQuery.js +193 -0
- package/events/DeletedMessage.d.ts +45 -0
- package/events/DeletedMessage.js +63 -0
- package/events/EditedMessage.d.ts +30 -0
- package/events/EditedMessage.js +41 -0
- package/events/NewMessage.d.ts +89 -0
- package/events/NewMessage.js +182 -0
- package/events/Raw.d.ts +29 -0
- package/events/Raw.js +43 -0
- package/events/common.d.ts +66 -0
- package/events/common.js +141 -0
- package/events/index.d.ts +2 -0
- package/events/index.js +8 -0
- package/extensions/AsyncQueue.d.ts +10 -0
- package/extensions/AsyncQueue.js +32 -0
- package/extensions/BinaryReader.d.ts +99 -0
- package/extensions/BinaryReader.js +242 -0
- package/extensions/BinaryWriter.d.ts +6 -0
- package/extensions/BinaryWriter.js +15 -0
- package/extensions/Deferred.d.ts +8 -0
- package/extensions/Deferred.js +16 -0
- package/extensions/Logger.d.ts +54 -0
- package/extensions/Logger.js +128 -0
- package/extensions/MessagePacker.d.ts +21 -0
- package/extensions/MessagePacker.js +154 -0
- package/extensions/PendingState.d.ts +12 -0
- package/extensions/PendingState.js +29 -0
- package/extensions/PromisedNetSockets.d.ts +24 -0
- package/extensions/PromisedNetSockets.js +192 -0
- package/extensions/PromisedWebSockets.d.ts +18 -0
- package/extensions/PromisedWebSockets.js +124 -0
- package/extensions/html.d.ts +5 -0
- package/extensions/html.js +228 -0
- package/extensions/index.d.ts +7 -0
- package/extensions/index.js +17 -0
- package/extensions/markdown.d.ts +5 -0
- package/extensions/markdown.js +76 -0
- package/extensions/markdownv2.d.ts +5 -0
- package/extensions/markdownv2.js +51 -0
- package/extensions/net.d.ts +1 -0
- package/extensions/net.js +17 -0
- package/extensions/socks.d.ts +1 -0
- package/extensions/socks.js +17 -0
- package/index.d.ts +14 -0
- package/index.js +62 -0
- package/inspect.d.ts +1 -0
- package/inspect.js +5 -0
- package/network/Authenticator.d.ts +12 -0
- package/network/Authenticator.js +192 -0
- package/network/MTProtoPlainSender.d.ts +19 -0
- package/network/MTProtoPlainSender.js +74 -0
- package/network/MTProtoSender.d.ts +290 -0
- package/network/MTProtoSender.js +873 -0
- package/network/MTProtoState.d.ts +102 -0
- package/network/MTProtoState.js +267 -0
- package/network/RequestState.d.ts +18 -0
- package/network/RequestState.js +35 -0
- package/network/connection/Connection.d.ts +69 -0
- package/network/connection/Connection.js +162 -0
- package/network/connection/TCPAbridged.d.ts +19 -0
- package/network/connection/TCPAbridged.js +58 -0
- package/network/connection/TCPFull.d.ts +16 -0
- package/network/connection/TCPFull.js +61 -0
- package/network/connection/TCPMTProxy.d.ts +49 -0
- package/network/connection/TCPMTProxy.js +121 -0
- package/network/connection/TCPObfuscated.d.ts +18 -0
- package/network/connection/TCPObfuscated.js +78 -0
- package/network/connection/index.d.ts +4 -0
- package/network/connection/index.js +11 -0
- package/network/index.d.ts +11 -0
- package/network/index.js +23 -0
- package/package.json +50 -0
- package/requestIter.d.ts +24 -0
- package/requestIter.js +109 -0
- package/sessions/Abstract.d.ts +103 -0
- package/sessions/Abstract.js +6 -0
- package/sessions/Memory.d.ts +38 -0
- package/sessions/Memory.js +272 -0
- package/sessions/StoreSession.d.ts +14 -0
- package/sessions/StoreSession.js +77 -0
- package/sessions/StringSession.d.ts +32 -0
- package/sessions/StringSession.js +116 -0
- package/sessions/index.d.ts +4 -0
- package/sessions/index.js +11 -0
- package/sessions/localStorage.d.ts +1 -0
- package/sessions/localStorage.js +4 -0
- package/tl/AllTLObjects.d.ts +3 -0
- package/tl/AllTLObjects.js +17 -0
- package/tl/MTProtoRequest.d.ts +18 -0
- package/tl/MTProtoRequest.js +38 -0
- package/tl/api.d.ts +32488 -0
- package/tl/api.js +507 -0
- package/tl/apiTl.d.ts +2 -0
- package/tl/apiTl.js +2209 -0
- package/tl/core/GZIPPacked.d.ts +15 -0
- package/tl/core/GZIPPacked.js +51 -0
- package/tl/core/MessageContainer.d.ts +12 -0
- package/tl/core/MessageContainer.js +42 -0
- package/tl/core/RPCResult.d.ts +14 -0
- package/tl/core/RPCResult.js +32 -0
- package/tl/core/TLMessage.d.ts +10 -0
- package/tl/core/TLMessage.js +14 -0
- package/tl/core/index.d.ts +6 -0
- package/tl/core/index.js +16 -0
- package/tl/custom/button.d.ts +24 -0
- package/tl/custom/button.js +78 -0
- package/tl/custom/chatGetter.d.ts +29 -0
- package/tl/custom/chatGetter.js +116 -0
- package/tl/custom/dialog.d.ts +30 -0
- package/tl/custom/dialog.js +40 -0
- package/tl/custom/draft.d.ts +21 -0
- package/tl/custom/draft.js +48 -0
- package/tl/custom/file.d.ts +21 -0
- package/tl/custom/file.js +68 -0
- package/tl/custom/forward.d.ts +15 -0
- package/tl/custom/forward.js +47 -0
- package/tl/custom/index.d.ts +1 -0
- package/tl/custom/index.js +5 -0
- package/tl/custom/inlineResult.d.ts +32 -0
- package/tl/custom/inlineResult.js +87 -0
- package/tl/custom/inlineResults.d.ts +20 -0
- package/tl/custom/inlineResults.js +26 -0
- package/tl/custom/message.d.ts +427 -0
- package/tl/custom/message.js +716 -0
- package/tl/custom/messageButton.d.ts +54 -0
- package/tl/custom/messageButton.js +152 -0
- package/tl/custom/senderGetter.d.ts +28 -0
- package/tl/custom/senderGetter.js +55 -0
- package/tl/generateModule.d.ts +1 -0
- package/tl/generateModule.js +17 -0
- package/tl/generationHelpers.d.ts +11 -0
- package/tl/generationHelpers.js +289 -0
- package/tl/index.d.ts +3 -0
- package/tl/index.js +10 -0
- package/tl/patched/index.d.ts +2 -0
- package/tl/patched/index.js +76 -0
- package/tl/schemaTl.d.ts +2 -0
- package/tl/schemaTl.js +64 -0
- package/tl/types-generator/generate.d.ts +1 -0
- package/tl/types-generator/generate.js +84 -0
- package/tl/types-generator/template.d.ts +6 -0
- package/tl/types-generator/template.js +257 -0
package/tl/api.js
ADDED
|
@@ -0,0 +1,507 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
const { inspect } = require("../inspect");
|
|
3
|
+
const bigInt = require("big-integer");
|
|
4
|
+
const { generateRandomBytes, readBigIntFromBuffer, isArrayLike, betterConsoleLog, } = require("../Helpers");
|
|
5
|
+
const tlContent = require("./apiTl.js");
|
|
6
|
+
const schemeContent = require("./schemaTl.js");
|
|
7
|
+
function generateRandomBigInt() {
|
|
8
|
+
return readBigIntFromBuffer(generateRandomBytes(8), false, true);
|
|
9
|
+
}
|
|
10
|
+
const { parseTl, serializeBytes, serializeDate, } = require("./generationHelpers");
|
|
11
|
+
const { toSignedLittleBuffer } = require("../Helpers");
|
|
12
|
+
const NAMED_AUTO_CASTS = new Set(["chatId,int"]);
|
|
13
|
+
const NAMED_BLACKLIST = new Set(["discardEncryption"]);
|
|
14
|
+
const AUTO_CASTS = new Set([
|
|
15
|
+
"InputPeer",
|
|
16
|
+
"InputChannel",
|
|
17
|
+
"InputUser",
|
|
18
|
+
"InputDialogPeer",
|
|
19
|
+
"InputNotifyPeer",
|
|
20
|
+
"InputMedia",
|
|
21
|
+
"InputPhoto",
|
|
22
|
+
"InputMessage",
|
|
23
|
+
"InputDocument",
|
|
24
|
+
"InputChatPhoto",
|
|
25
|
+
]);
|
|
26
|
+
class CastError extends Error {
|
|
27
|
+
constructor(objectName, expected, actual, ...params) {
|
|
28
|
+
// Pass remaining arguments (including vendor specific ones) to parent constructor
|
|
29
|
+
const message = "Found wrong type for " +
|
|
30
|
+
objectName +
|
|
31
|
+
". expected " +
|
|
32
|
+
expected +
|
|
33
|
+
" but received " +
|
|
34
|
+
actual +
|
|
35
|
+
".If you think this is a mistake please report it.";
|
|
36
|
+
super(message, ...params);
|
|
37
|
+
// Maintains proper stack trace for where our error was thrown (only available on V8)
|
|
38
|
+
if (Error.captureStackTrace) {
|
|
39
|
+
Error.captureStackTrace(this, CastError);
|
|
40
|
+
}
|
|
41
|
+
this.name = "CastError";
|
|
42
|
+
// Custom debugging information
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
const CACHING_SUPPORTED = typeof self !== "undefined" && self.localStorage !== undefined;
|
|
46
|
+
const CACHE_KEY = "teleproto:apiCache";
|
|
47
|
+
function buildApiFromTlSchema() {
|
|
48
|
+
let definitions;
|
|
49
|
+
const fromCache = CACHING_SUPPORTED && loadFromCache();
|
|
50
|
+
if (fromCache) {
|
|
51
|
+
definitions = fromCache;
|
|
52
|
+
}
|
|
53
|
+
else {
|
|
54
|
+
definitions = loadFromTlSchemas();
|
|
55
|
+
if (CACHING_SUPPORTED) {
|
|
56
|
+
localStorage.setItem(CACHE_KEY, JSON.stringify(definitions));
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
return createClasses("all", definitions);
|
|
60
|
+
}
|
|
61
|
+
function loadFromCache() {
|
|
62
|
+
const jsonCache = localStorage.getItem(CACHE_KEY);
|
|
63
|
+
return jsonCache && JSON.parse(jsonCache);
|
|
64
|
+
}
|
|
65
|
+
function loadFromTlSchemas() {
|
|
66
|
+
const [constructorParamsApi, functionParamsApi] = extractParams(tlContent);
|
|
67
|
+
const [constructorParamsSchema, functionParamsSchema] = extractParams(schemeContent);
|
|
68
|
+
const constructors = [].concat(constructorParamsApi, constructorParamsSchema);
|
|
69
|
+
const requests = [].concat(functionParamsApi, functionParamsSchema);
|
|
70
|
+
return [].concat(constructors, requests);
|
|
71
|
+
}
|
|
72
|
+
function extractParams(fileContent) {
|
|
73
|
+
const f = parseTl(fileContent, 109);
|
|
74
|
+
const constructors = [];
|
|
75
|
+
const functions = [];
|
|
76
|
+
for (const d of f) {
|
|
77
|
+
d.isFunction ? functions.push(d) : constructors.push(d);
|
|
78
|
+
}
|
|
79
|
+
return [constructors, functions];
|
|
80
|
+
}
|
|
81
|
+
function argToBytes(x, type, argName, requestName) {
|
|
82
|
+
switch (type) {
|
|
83
|
+
case "int":
|
|
84
|
+
const i = Buffer.alloc(4);
|
|
85
|
+
i.writeInt32LE(x, 0);
|
|
86
|
+
return i;
|
|
87
|
+
case "long":
|
|
88
|
+
return toSignedLittleBuffer(x, 8);
|
|
89
|
+
case "int128":
|
|
90
|
+
return toSignedLittleBuffer(x, 16);
|
|
91
|
+
case "int256":
|
|
92
|
+
return toSignedLittleBuffer(x, 32);
|
|
93
|
+
case "double":
|
|
94
|
+
const d = Buffer.alloc(8);
|
|
95
|
+
d.writeDoubleLE(x, 0);
|
|
96
|
+
return d;
|
|
97
|
+
case "string":
|
|
98
|
+
return serializeBytes(x);
|
|
99
|
+
case "Bool":
|
|
100
|
+
return x
|
|
101
|
+
? Buffer.from("b5757299", "hex")
|
|
102
|
+
: Buffer.from("379779bc", "hex");
|
|
103
|
+
case "true":
|
|
104
|
+
return Buffer.alloc(0);
|
|
105
|
+
case "bytes":
|
|
106
|
+
return serializeBytes(x);
|
|
107
|
+
case "date":
|
|
108
|
+
return serializeDate(x);
|
|
109
|
+
default:
|
|
110
|
+
if (x === undefined || typeof x.getBytes !== "function") {
|
|
111
|
+
throw new Error(`Required object ${argName} of ${requestName} is undefined`);
|
|
112
|
+
}
|
|
113
|
+
return x.getBytes();
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
async function getInputFromResolve(utils, client, peer, peerType) {
|
|
117
|
+
switch (peerType) {
|
|
118
|
+
case "InputPeer":
|
|
119
|
+
return utils.getInputPeer(await client.getInputEntity(peer));
|
|
120
|
+
case "InputChannel":
|
|
121
|
+
return utils.getInputChannel(await client.getInputEntity(peer));
|
|
122
|
+
case "InputUser":
|
|
123
|
+
return utils.getInputUser(await client.getInputEntity(peer));
|
|
124
|
+
case "InputDialogPeer":
|
|
125
|
+
return await client._getInputDialog(peer);
|
|
126
|
+
case "InputNotifyPeer":
|
|
127
|
+
return await client._getInputNotify(peer);
|
|
128
|
+
case "InputMedia":
|
|
129
|
+
return utils.getInputMedia(peer);
|
|
130
|
+
case "InputPhoto":
|
|
131
|
+
return utils.getInputPhoto(peer);
|
|
132
|
+
case "InputMessage":
|
|
133
|
+
return utils.getInputMessage(peer);
|
|
134
|
+
case "InputDocument":
|
|
135
|
+
return utils.getInputDocument(peer);
|
|
136
|
+
case "InputChatPhoto":
|
|
137
|
+
return utils.getInputChatPhoto(peer);
|
|
138
|
+
case "chatId,int":
|
|
139
|
+
return await client.getPeerId(peer, false);
|
|
140
|
+
default:
|
|
141
|
+
throw new Error("unsupported peer type : " + peerType);
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
function getArgFromReader(reader, arg) {
|
|
145
|
+
if (arg.isVector) {
|
|
146
|
+
if (arg.useVectorId) {
|
|
147
|
+
reader.readInt();
|
|
148
|
+
}
|
|
149
|
+
const temp = [];
|
|
150
|
+
const len = reader.readInt();
|
|
151
|
+
arg.isVector = false;
|
|
152
|
+
for (let i = 0; i < len; i++) {
|
|
153
|
+
temp.push(getArgFromReader(reader, arg));
|
|
154
|
+
}
|
|
155
|
+
arg.isVector = true;
|
|
156
|
+
return temp;
|
|
157
|
+
}
|
|
158
|
+
else if (arg.flagIndicator) {
|
|
159
|
+
return reader.readInt();
|
|
160
|
+
}
|
|
161
|
+
else {
|
|
162
|
+
switch (arg.type) {
|
|
163
|
+
case "int":
|
|
164
|
+
return reader.readInt();
|
|
165
|
+
case "long":
|
|
166
|
+
return reader.readLong();
|
|
167
|
+
case "int128":
|
|
168
|
+
return reader.readLargeInt(128);
|
|
169
|
+
case "int256":
|
|
170
|
+
return reader.readLargeInt(256);
|
|
171
|
+
case "double":
|
|
172
|
+
return reader.readDouble();
|
|
173
|
+
case "string":
|
|
174
|
+
return reader.tgReadString();
|
|
175
|
+
case "Bool":
|
|
176
|
+
return reader.tgReadBool();
|
|
177
|
+
case "true":
|
|
178
|
+
return true;
|
|
179
|
+
case "bytes":
|
|
180
|
+
return reader.tgReadBytes();
|
|
181
|
+
case "date":
|
|
182
|
+
return reader.tgReadDate();
|
|
183
|
+
default:
|
|
184
|
+
if (!arg.skipConstructorId) {
|
|
185
|
+
return reader.tgReadObject();
|
|
186
|
+
}
|
|
187
|
+
else {
|
|
188
|
+
return api.constructors[arg.type].fromReader(reader);
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
function compareType(value, type) {
|
|
194
|
+
let correct = true;
|
|
195
|
+
switch (type) {
|
|
196
|
+
case "number":
|
|
197
|
+
correct = typeof value === "number" || value === undefined;
|
|
198
|
+
break;
|
|
199
|
+
case "string":
|
|
200
|
+
case "boolean":
|
|
201
|
+
correct = typeof value === type;
|
|
202
|
+
break;
|
|
203
|
+
case "bigInt":
|
|
204
|
+
correct =
|
|
205
|
+
bigInt.isInstance(value) ||
|
|
206
|
+
typeof value === "bigint" ||
|
|
207
|
+
typeof value === "number" ||
|
|
208
|
+
typeof value === "string" ||
|
|
209
|
+
value === undefined;
|
|
210
|
+
break;
|
|
211
|
+
case "true":
|
|
212
|
+
// true value is always correct
|
|
213
|
+
break;
|
|
214
|
+
case "buffer":
|
|
215
|
+
correct = Buffer.isBuffer(value);
|
|
216
|
+
break;
|
|
217
|
+
case "date":
|
|
218
|
+
correct =
|
|
219
|
+
(value &&
|
|
220
|
+
Object.prototype.toString.call(value) === "[object Date]" &&
|
|
221
|
+
!isNaN(value)) ||
|
|
222
|
+
typeof value === "number";
|
|
223
|
+
break;
|
|
224
|
+
default:
|
|
225
|
+
console.error(new Error("Unknown type." + type));
|
|
226
|
+
}
|
|
227
|
+
return correct;
|
|
228
|
+
}
|
|
229
|
+
function createClasses(classesType, params) {
|
|
230
|
+
const classes = {};
|
|
231
|
+
for (const classParams of params) {
|
|
232
|
+
const { name, constructorId, subclassOfId, argsConfig, namespace, isFunction, result, } = classParams;
|
|
233
|
+
const fullName = [namespace, name].join(".").replace(/^\./, "");
|
|
234
|
+
class VirtualClass {
|
|
235
|
+
constructor(args) {
|
|
236
|
+
this.CONSTRUCTOR_ID = constructorId;
|
|
237
|
+
this.SUBCLASS_OF_ID = subclassOfId;
|
|
238
|
+
this.className = fullName;
|
|
239
|
+
this.classType = isFunction ? "request" : "constructor";
|
|
240
|
+
args = args || {};
|
|
241
|
+
this.originalArgs = args;
|
|
242
|
+
this.init(args);
|
|
243
|
+
for (const argName in argsConfig) {
|
|
244
|
+
if (argName === "randomId" && !args[argName]) {
|
|
245
|
+
if (argsConfig[argName].isVector) {
|
|
246
|
+
const rands = [];
|
|
247
|
+
for (let i = 0; i < args["id"].length; i++) {
|
|
248
|
+
rands.push(generateRandomBigInt());
|
|
249
|
+
}
|
|
250
|
+
this[argName] = rands;
|
|
251
|
+
}
|
|
252
|
+
else {
|
|
253
|
+
this[argName] = generateRandomBigInt();
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
else {
|
|
257
|
+
this[argName] = args[argName];
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
init(args) { }
|
|
262
|
+
static fromReader(reader) {
|
|
263
|
+
const args = {};
|
|
264
|
+
for (const argName in argsConfig) {
|
|
265
|
+
if (argsConfig.hasOwnProperty(argName)) {
|
|
266
|
+
const arg = argsConfig[argName];
|
|
267
|
+
if (arg.isFlag) {
|
|
268
|
+
if (arg.type === "true") {
|
|
269
|
+
args[argName] = Boolean(args[arg.flagName] & (1 << arg.flagIndex));
|
|
270
|
+
continue;
|
|
271
|
+
}
|
|
272
|
+
if (args[arg.flagName] & (1 << arg.flagIndex)) {
|
|
273
|
+
args[argName] = getArgFromReader(reader, arg);
|
|
274
|
+
}
|
|
275
|
+
else {
|
|
276
|
+
args[argName] = null;
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
else {
|
|
280
|
+
if (arg.flagIndicator) {
|
|
281
|
+
arg.name = argName;
|
|
282
|
+
}
|
|
283
|
+
args[argName] = getArgFromReader(reader, arg);
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
return new this(args);
|
|
288
|
+
}
|
|
289
|
+
validate() {
|
|
290
|
+
for (const arg in argsConfig) {
|
|
291
|
+
if (argsConfig.hasOwnProperty(arg)) {
|
|
292
|
+
if (argsConfig[arg].flagIndicator ||
|
|
293
|
+
argsConfig[arg].isFlag) {
|
|
294
|
+
// we don't care about flags
|
|
295
|
+
continue;
|
|
296
|
+
}
|
|
297
|
+
const currentValue = this[arg];
|
|
298
|
+
this.assertType(arg, argsConfig[arg], currentValue);
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
assertType(objectName, object, value) {
|
|
303
|
+
let expected;
|
|
304
|
+
if (object["isVector"]) {
|
|
305
|
+
if (!isArrayLike(value)) {
|
|
306
|
+
console.error(new CastError(objectName, "array", value));
|
|
307
|
+
}
|
|
308
|
+
if (value == undefined) {
|
|
309
|
+
value = [];
|
|
310
|
+
}
|
|
311
|
+
for (const o of value) {
|
|
312
|
+
this.assertType(objectName, Object.assign(Object.assign({}, object), { isVector: false }), o);
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
else {
|
|
316
|
+
switch (object["type"]) {
|
|
317
|
+
case "int":
|
|
318
|
+
expected = "number";
|
|
319
|
+
break;
|
|
320
|
+
case "long":
|
|
321
|
+
case "int128":
|
|
322
|
+
case "int256":
|
|
323
|
+
expected = "bigInt";
|
|
324
|
+
break;
|
|
325
|
+
case "double":
|
|
326
|
+
expected = "number";
|
|
327
|
+
break;
|
|
328
|
+
case "string":
|
|
329
|
+
expected = "string";
|
|
330
|
+
break;
|
|
331
|
+
case "Bool":
|
|
332
|
+
expected = "boolean";
|
|
333
|
+
break;
|
|
334
|
+
case "true":
|
|
335
|
+
expected = "true";
|
|
336
|
+
break;
|
|
337
|
+
case "bytes":
|
|
338
|
+
expected = "buffer";
|
|
339
|
+
break;
|
|
340
|
+
case "date":
|
|
341
|
+
expected = "date";
|
|
342
|
+
break;
|
|
343
|
+
default:
|
|
344
|
+
expected = "object";
|
|
345
|
+
}
|
|
346
|
+
if (expected === "object") {
|
|
347
|
+
// will be validated in get byte();
|
|
348
|
+
}
|
|
349
|
+
else {
|
|
350
|
+
const isCorrectType = compareType(value, expected);
|
|
351
|
+
if (isCorrectType !== true) {
|
|
352
|
+
console.error(new CastError(objectName, expected, value));
|
|
353
|
+
}
|
|
354
|
+
}
|
|
355
|
+
}
|
|
356
|
+
}
|
|
357
|
+
getBytes() {
|
|
358
|
+
try {
|
|
359
|
+
this.validate();
|
|
360
|
+
}
|
|
361
|
+
catch (e) {
|
|
362
|
+
// feature still in alpha so errors are expected.
|
|
363
|
+
}
|
|
364
|
+
const idForBytes = this.CONSTRUCTOR_ID;
|
|
365
|
+
const c = Buffer.alloc(4);
|
|
366
|
+
c.writeUInt32LE(idForBytes, 0);
|
|
367
|
+
const buffers = [c];
|
|
368
|
+
for (const arg in argsConfig) {
|
|
369
|
+
if (argsConfig.hasOwnProperty(arg)) {
|
|
370
|
+
if (argsConfig[arg].isFlag) {
|
|
371
|
+
if ((this[arg] === false &&
|
|
372
|
+
argsConfig[arg].type !== "Bool") ||
|
|
373
|
+
this[arg] === null ||
|
|
374
|
+
this[arg] === undefined ||
|
|
375
|
+
argsConfig[arg].type === "true") {
|
|
376
|
+
continue;
|
|
377
|
+
}
|
|
378
|
+
}
|
|
379
|
+
if (argsConfig[arg].isVector) {
|
|
380
|
+
if (argsConfig[arg].useVectorId) {
|
|
381
|
+
buffers.push(Buffer.from("15c4b51c", "hex"));
|
|
382
|
+
}
|
|
383
|
+
const l = Buffer.alloc(4);
|
|
384
|
+
l.writeInt32LE(this[arg].length, 0);
|
|
385
|
+
buffers.push(l, Buffer.concat(this[arg].map((x) => argToBytes(x, argsConfig[arg].type, fullName))));
|
|
386
|
+
}
|
|
387
|
+
else if (argsConfig[arg].flagIndicator) {
|
|
388
|
+
if (!Object.values(argsConfig).some((f) => f.isFlag)) {
|
|
389
|
+
buffers.push(Buffer.alloc(4));
|
|
390
|
+
}
|
|
391
|
+
else {
|
|
392
|
+
let flagCalculate = 0;
|
|
393
|
+
for (const f in argsConfig) {
|
|
394
|
+
if (argsConfig[f].isFlag &&
|
|
395
|
+
arg === argsConfig[f].flagName) {
|
|
396
|
+
if ((this[f] === false &&
|
|
397
|
+
argsConfig[f].type !==
|
|
398
|
+
"Bool") ||
|
|
399
|
+
this[f] === undefined ||
|
|
400
|
+
this[f] === null) {
|
|
401
|
+
flagCalculate |= 0;
|
|
402
|
+
}
|
|
403
|
+
else {
|
|
404
|
+
flagCalculate |=
|
|
405
|
+
1 << argsConfig[f].flagIndex;
|
|
406
|
+
}
|
|
407
|
+
}
|
|
408
|
+
}
|
|
409
|
+
const f = Buffer.alloc(4);
|
|
410
|
+
f.writeUInt32LE(flagCalculate, 0);
|
|
411
|
+
buffers.push(f);
|
|
412
|
+
}
|
|
413
|
+
}
|
|
414
|
+
else {
|
|
415
|
+
buffers.push(argToBytes(this[arg], argsConfig[arg].type, arg, fullName));
|
|
416
|
+
if (this[arg] &&
|
|
417
|
+
typeof this[arg].getBytes === "function") {
|
|
418
|
+
let boxed = argsConfig[arg].type.charAt(argsConfig[arg].type.indexOf(".") + 1);
|
|
419
|
+
boxed = boxed === boxed.toUpperCase();
|
|
420
|
+
if (!boxed) {
|
|
421
|
+
buffers.shift();
|
|
422
|
+
}
|
|
423
|
+
}
|
|
424
|
+
}
|
|
425
|
+
}
|
|
426
|
+
}
|
|
427
|
+
return Buffer.concat(buffers);
|
|
428
|
+
}
|
|
429
|
+
readResult(reader) {
|
|
430
|
+
if (!isFunction) {
|
|
431
|
+
throw new Error("`readResult()` called for non-request instance");
|
|
432
|
+
}
|
|
433
|
+
const m = result.match(/Vector<(int|long)>/);
|
|
434
|
+
if (m) {
|
|
435
|
+
reader.readInt();
|
|
436
|
+
const temp = [];
|
|
437
|
+
const len = reader.readInt();
|
|
438
|
+
if (m[1] === "int") {
|
|
439
|
+
for (let i = 0; i < len; i++) {
|
|
440
|
+
temp.push(reader.readInt());
|
|
441
|
+
}
|
|
442
|
+
}
|
|
443
|
+
else {
|
|
444
|
+
for (let i = 0; i < len; i++) {
|
|
445
|
+
temp.push(reader.readLong());
|
|
446
|
+
}
|
|
447
|
+
}
|
|
448
|
+
return temp;
|
|
449
|
+
}
|
|
450
|
+
else {
|
|
451
|
+
return reader.tgReadObject();
|
|
452
|
+
}
|
|
453
|
+
}
|
|
454
|
+
async resolve(client, utils) {
|
|
455
|
+
if (!isFunction) {
|
|
456
|
+
throw new Error("`resolve()` called for non-request instance");
|
|
457
|
+
}
|
|
458
|
+
for (const arg in argsConfig) {
|
|
459
|
+
if (argsConfig.hasOwnProperty(arg)) {
|
|
460
|
+
if (!AUTO_CASTS.has(argsConfig[arg].type)) {
|
|
461
|
+
if (!NAMED_AUTO_CASTS.has(`${argsConfig[arg].name},${argsConfig[arg].type}`)) {
|
|
462
|
+
continue;
|
|
463
|
+
}
|
|
464
|
+
}
|
|
465
|
+
if (argsConfig[arg].isFlag) {
|
|
466
|
+
if (!this[arg]) {
|
|
467
|
+
continue;
|
|
468
|
+
}
|
|
469
|
+
}
|
|
470
|
+
if (argsConfig[arg].isVector) {
|
|
471
|
+
const temp = [];
|
|
472
|
+
for (const x of this[arg]) {
|
|
473
|
+
temp.push(await getInputFromResolve(utils, client, x, argsConfig[arg].type));
|
|
474
|
+
}
|
|
475
|
+
this[arg] = temp;
|
|
476
|
+
}
|
|
477
|
+
else {
|
|
478
|
+
this[arg] = await getInputFromResolve(utils, client, this[arg], argsConfig[arg].type);
|
|
479
|
+
}
|
|
480
|
+
}
|
|
481
|
+
}
|
|
482
|
+
}
|
|
483
|
+
[inspect.custom]() {
|
|
484
|
+
return betterConsoleLog(this);
|
|
485
|
+
}
|
|
486
|
+
toJSON() {
|
|
487
|
+
return Object.assign(Object.assign({}, this.originalArgs), { className: fullName });
|
|
488
|
+
}
|
|
489
|
+
}
|
|
490
|
+
VirtualClass.CONSTRUCTOR_ID = constructorId;
|
|
491
|
+
VirtualClass.SUBCLASS_OF_ID = subclassOfId;
|
|
492
|
+
VirtualClass.className = fullName;
|
|
493
|
+
VirtualClass.classType = isFunction ? "request" : "constructor";
|
|
494
|
+
if (namespace) {
|
|
495
|
+
if (!classes[namespace]) {
|
|
496
|
+
classes[namespace] = {};
|
|
497
|
+
}
|
|
498
|
+
classes[namespace][name] = VirtualClass;
|
|
499
|
+
}
|
|
500
|
+
else {
|
|
501
|
+
classes[name] = VirtualClass;
|
|
502
|
+
}
|
|
503
|
+
}
|
|
504
|
+
return classes;
|
|
505
|
+
}
|
|
506
|
+
const api = buildApiFromTlSchema();
|
|
507
|
+
module.exports = { Api: api };
|
package/tl/apiTl.d.ts
ADDED