@mtkruto/browser 0.119.0 → 0.119.1
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/0_errors.d.ts.map +1 -1
- package/esm/0_errors.js +9 -31
- package/esm/3_errors.js +2 -12
- package/esm/4_errors.js +2 -12
- package/esm/_dnt.polyfills.d.ts +0 -99
- package/esm/_dnt.polyfills.d.ts.map +1 -1
- package/esm/_dnt.polyfills.js +1 -127
- package/esm/client/0_abortable_loop.js +26 -39
- package/esm/client/0_storage_operations.js +179 -218
- package/esm/client/1_client_plain.js +4 -22
- package/esm/client/2_account_manager.js +140 -149
- package/esm/client/2_bot_info_manager.js +26 -38
- package/esm/client/2_business_connection_manager.js +10 -23
- package/esm/client/2_client_encrypted.js +198 -215
- package/esm/client/2_file_manager.js +255 -262
- package/esm/client/2_network_statistics_manager.js +31 -44
- package/esm/client/2_payment_manager.js +7 -20
- package/esm/client/2_reaction_manager.js +7 -20
- package/esm/client/2_translations_manager.js +101 -111
- package/esm/client/2_update_manager.js +750 -745
- package/esm/client/3_client_encrypted_pool.js +10 -26
- package/esm/client/3_message_manager.js +503 -508
- package/esm/client/3_video_chat_manager.js +57 -68
- package/esm/client/4_callback_query_manager.js +18 -30
- package/esm/client/4_chat_list_manager.js +140 -146
- package/esm/client/4_chat_manager.js +161 -169
- package/esm/client/4_checklist_manager.js +26 -39
- package/esm/client/4_context.js +244 -259
- package/esm/client/4_forum_manager.js +67 -73
- package/esm/client/4_gift_manager.js +22 -35
- package/esm/client/4_inline_query_manager.js +16 -28
- package/esm/client/4_link_preview_manager.js +6 -19
- package/esm/client/4_poll_manager.js +44 -57
- package/esm/client/4_story_manager.js +41 -53
- package/esm/client/5_composer.js +13 -26
- package/esm/client/6_client.js +866 -896
- package/esm/client/6_client_dispatcher.js +308 -325
- package/esm/client/7_client_worker.js +16 -29
- package/esm/connection/1_connection_tcp.js +55 -82
- package/esm/connection/1_connection_web_socket.js +75 -91
- package/esm/deps/jsr.io/@roj/tgcrypto/1.0.1/dist/tgcrypto.js +3 -11
- package/esm/deps/jsr.io/@std/async/1.2.0/mux_async_iterator.js +31 -47
- package/esm/deps/jsr.io/@std/async/1.2.0/tee.js +11 -34
- package/esm/deps/jsr.io/@std/cache/0.2.2/lru_cache.js +30 -47
- package/esm/deps/jsr.io/@std/datetime/0.225.7/_date_time_formatter.js +4 -17
- package/esm/session/0_session_state.js +12 -38
- package/esm/session/1_session.js +49 -72
- package/esm/session/2_session_encrypted.js +422 -420
- package/esm/storage/2_storage_indexed_db.js +26 -44
- package/esm/storage/2_storage_local_storage.js +3 -16
- package/esm/storage/2_storage_memory.js +24 -41
- package/esm/storage/2_storage_session_storage.js +3 -16
- package/esm/tl/1_tl_reader.d.ts +1 -1
- package/esm/tl/1_tl_reader.d.ts.map +1 -1
- package/esm/tl/1_tl_reader.js +95 -103
- package/esm/tl/1_tl_writer.js +169 -178
- package/esm/transport/0_transport.js +1 -8
- package/esm/transport/1_transport_abridged.js +11 -24
- package/esm/transport/1_transport_intermediate.js +10 -23
- package/esm/utilities/0_mutex.js +4 -19
- package/esm/utilities/0_part_stream.js +11 -25
- package/esm/utilities/1_crypto.js +42 -53
- package/esm/utilities/2_queue.js +29 -47
- package/package.json +1 -1
- package/script/0_errors.d.ts.map +1 -1
- package/script/0_errors.js +9 -31
- package/script/3_errors.js +2 -12
- package/script/4_errors.js +2 -12
- package/script/_dnt.polyfills.d.ts +0 -99
- package/script/_dnt.polyfills.d.ts.map +1 -1
- package/script/_dnt.polyfills.js +0 -128
- package/script/client/0_abortable_loop.js +27 -40
- package/script/client/0_storage_operations.js +179 -218
- package/script/client/1_client_plain.js +4 -22
- package/script/client/2_account_manager.js +140 -149
- package/script/client/2_bot_info_manager.js +26 -38
- package/script/client/2_business_connection_manager.js +10 -23
- package/script/client/2_client_encrypted.js +199 -216
- package/script/client/2_file_manager.js +255 -262
- package/script/client/2_network_statistics_manager.js +32 -45
- package/script/client/2_payment_manager.js +7 -20
- package/script/client/2_reaction_manager.js +7 -20
- package/script/client/2_translations_manager.js +102 -112
- package/script/client/2_update_manager.js +750 -745
- package/script/client/3_client_encrypted_pool.js +10 -26
- package/script/client/3_message_manager.js +503 -508
- package/script/client/3_video_chat_manager.js +57 -68
- package/script/client/4_callback_query_manager.js +18 -30
- package/script/client/4_chat_list_manager.js +140 -146
- package/script/client/4_chat_manager.js +161 -169
- package/script/client/4_checklist_manager.js +26 -39
- package/script/client/4_context.js +244 -259
- package/script/client/4_forum_manager.js +67 -73
- package/script/client/4_gift_manager.js +22 -35
- package/script/client/4_inline_query_manager.js +16 -28
- package/script/client/4_link_preview_manager.js +6 -19
- package/script/client/4_poll_manager.js +44 -57
- package/script/client/4_story_manager.js +41 -53
- package/script/client/5_composer.js +13 -26
- package/script/client/6_client.js +866 -896
- package/script/client/6_client_dispatcher.js +308 -325
- package/script/client/7_client_worker.js +16 -29
- package/script/connection/1_connection_tcp.js +55 -82
- package/script/connection/1_connection_web_socket.js +75 -91
- package/script/deps/jsr.io/@roj/tgcrypto/1.0.1/dist/tgcrypto.js +3 -11
- package/script/deps/jsr.io/@std/async/1.2.0/mux_async_iterator.js +31 -47
- package/script/deps/jsr.io/@std/async/1.2.0/tee.js +11 -34
- package/script/deps/jsr.io/@std/cache/0.2.2/lru_cache.js +30 -47
- package/script/deps/jsr.io/@std/datetime/0.225.7/_date_time_formatter.js +4 -17
- package/script/session/0_session_state.js +12 -38
- package/script/session/1_session.js +49 -72
- package/script/session/2_session_encrypted.js +423 -421
- package/script/storage/2_storage_indexed_db.js +26 -44
- package/script/storage/2_storage_local_storage.js +3 -16
- package/script/storage/2_storage_memory.js +24 -41
- package/script/storage/2_storage_session_storage.js +3 -16
- package/script/tl/1_tl_reader.d.ts +1 -1
- package/script/tl/1_tl_reader.d.ts.map +1 -1
- package/script/tl/1_tl_reader.js +96 -104
- package/script/tl/1_tl_writer.js +170 -179
- package/script/transport/0_transport.js +1 -8
- package/script/transport/1_transport_abridged.js +11 -24
- package/script/transport/1_transport_intermediate.js +10 -23
- package/script/utilities/0_mutex.js +4 -19
- package/script/utilities/0_part_stream.js +11 -25
- package/script/utilities/1_crypto.js +43 -54
- package/script/utilities/2_queue.js +30 -48
|
@@ -18,47 +18,29 @@
|
|
|
18
18
|
* You should have received a copy of the GNU Lesser General Public License
|
|
19
19
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
20
20
|
*/
|
|
21
|
-
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
22
|
-
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
23
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
24
|
-
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
25
|
-
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
26
|
-
};
|
|
27
|
-
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
28
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
29
|
-
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
30
|
-
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
31
|
-
};
|
|
32
|
-
var _StorageIndexedDB_instances, _StorageIndexedDB_name, _StorageIndexedDB_id, _StorageIndexedDB_supportsFiles, _StorageIndexedDB_fixKey;
|
|
33
21
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
34
22
|
exports.StorageIndexedDB = void 0;
|
|
35
23
|
const _1_utilities_js_1 = require("./1_utilities.js");
|
|
36
24
|
const VERSION = 1;
|
|
37
25
|
const KV_OBJECT_STORE = "kv";
|
|
38
26
|
class StorageIndexedDB {
|
|
27
|
+
database = null;
|
|
28
|
+
#name;
|
|
29
|
+
#id = null;
|
|
30
|
+
#supportsFiles;
|
|
39
31
|
constructor(name, params) {
|
|
40
|
-
_StorageIndexedDB_instances.add(this);
|
|
41
|
-
Object.defineProperty(this, "database", {
|
|
42
|
-
enumerable: true,
|
|
43
|
-
configurable: true,
|
|
44
|
-
writable: true,
|
|
45
|
-
value: null
|
|
46
|
-
});
|
|
47
|
-
_StorageIndexedDB_name.set(this, void 0);
|
|
48
|
-
_StorageIndexedDB_id.set(this, null);
|
|
49
|
-
_StorageIndexedDB_supportsFiles.set(this, void 0);
|
|
50
32
|
if (typeof indexedDB === "undefined") {
|
|
51
33
|
throw new Error("Unavailable in current environment");
|
|
52
34
|
}
|
|
53
|
-
|
|
54
|
-
|
|
35
|
+
this.#name = name;
|
|
36
|
+
this.#supportsFiles = params?.storeFiles ?? true;
|
|
55
37
|
}
|
|
56
38
|
get name() {
|
|
57
|
-
return
|
|
39
|
+
return this.#name;
|
|
58
40
|
}
|
|
59
41
|
branch(id) {
|
|
60
|
-
const storage = new StorageIndexedDB(this.name, { storeFiles:
|
|
61
|
-
|
|
42
|
+
const storage = new StorageIndexedDB(this.name, { storeFiles: this.#supportsFiles });
|
|
43
|
+
storage.#id = id;
|
|
62
44
|
return storage;
|
|
63
45
|
}
|
|
64
46
|
initialize() {
|
|
@@ -76,7 +58,7 @@ class StorageIndexedDB {
|
|
|
76
58
|
});
|
|
77
59
|
}
|
|
78
60
|
get supportsFiles() {
|
|
79
|
-
return
|
|
61
|
+
return this.#supportsFiles;
|
|
80
62
|
}
|
|
81
63
|
get mustSerialize() {
|
|
82
64
|
return true;
|
|
@@ -84,8 +66,16 @@ class StorageIndexedDB {
|
|
|
84
66
|
get isMemory() {
|
|
85
67
|
return false;
|
|
86
68
|
}
|
|
69
|
+
#fixKey(key) {
|
|
70
|
+
if (this.#id !== null) {
|
|
71
|
+
return ["__S" + this.#id, ...key];
|
|
72
|
+
}
|
|
73
|
+
else {
|
|
74
|
+
return key;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
87
77
|
set(k, v, tx_) {
|
|
88
|
-
k =
|
|
78
|
+
k = this.#fixKey(k);
|
|
89
79
|
if (!this.database) {
|
|
90
80
|
throw new Error("Not initialized");
|
|
91
81
|
}
|
|
@@ -109,7 +99,7 @@ class StorageIndexedDB {
|
|
|
109
99
|
}
|
|
110
100
|
get(k, tx_, fix = true) {
|
|
111
101
|
if (fix) {
|
|
112
|
-
k =
|
|
102
|
+
k = this.#fixKey(k);
|
|
113
103
|
}
|
|
114
104
|
if (!this.database) {
|
|
115
105
|
throw new Error("Not initialized");
|
|
@@ -126,14 +116,14 @@ class StorageIndexedDB {
|
|
|
126
116
|
});
|
|
127
117
|
}
|
|
128
118
|
async *getMany(filter, params, tx_) {
|
|
129
|
-
if ("prefix" in filter &&
|
|
130
|
-
filter.prefix =
|
|
119
|
+
if ("prefix" in filter && this.#id !== null) {
|
|
120
|
+
filter.prefix = this.#fixKey(filter.prefix);
|
|
131
121
|
}
|
|
132
|
-
if ("start" in filter &&
|
|
133
|
-
filter.start =
|
|
122
|
+
if ("start" in filter && this.#id !== null) {
|
|
123
|
+
filter.start = this.#fixKey(filter.start);
|
|
134
124
|
}
|
|
135
|
-
if ("end" in filter &&
|
|
136
|
-
filter.end =
|
|
125
|
+
if ("end" in filter && this.#id !== null) {
|
|
126
|
+
filter.end = this.#fixKey(filter.end);
|
|
137
127
|
}
|
|
138
128
|
if (!this.database) {
|
|
139
129
|
throw new Error("Not initialized");
|
|
@@ -184,11 +174,3 @@ class StorageIndexedDB {
|
|
|
184
174
|
}
|
|
185
175
|
}
|
|
186
176
|
exports.StorageIndexedDB = StorageIndexedDB;
|
|
187
|
-
_StorageIndexedDB_name = new WeakMap(), _StorageIndexedDB_id = new WeakMap(), _StorageIndexedDB_supportsFiles = new WeakMap(), _StorageIndexedDB_instances = new WeakSet(), _StorageIndexedDB_fixKey = function _StorageIndexedDB_fixKey(key) {
|
|
188
|
-
if (__classPrivateFieldGet(this, _StorageIndexedDB_id, "f") !== null) {
|
|
189
|
-
return ["__S" + __classPrivateFieldGet(this, _StorageIndexedDB_id, "f"), ...key];
|
|
190
|
-
}
|
|
191
|
-
else {
|
|
192
|
-
return key;
|
|
193
|
-
}
|
|
194
|
-
};
|
|
@@ -18,34 +18,22 @@
|
|
|
18
18
|
* You should have received a copy of the GNU Lesser General Public License
|
|
19
19
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
20
20
|
*/
|
|
21
|
-
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
22
|
-
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
23
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
24
|
-
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
25
|
-
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
26
|
-
};
|
|
27
|
-
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
28
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
29
|
-
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
30
|
-
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
31
|
-
};
|
|
32
|
-
var _StorageLocalStorage_prefix;
|
|
33
21
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
34
22
|
exports.StorageLocalStorage = void 0;
|
|
35
23
|
const _1_utilities_js_1 = require("./1_utilities.js");
|
|
36
24
|
class StorageLocalStorage {
|
|
25
|
+
#prefix;
|
|
37
26
|
constructor(prefix) {
|
|
38
|
-
_StorageLocalStorage_prefix.set(this, void 0);
|
|
39
27
|
if (typeof localStorage === "undefined") {
|
|
40
28
|
throw new Error("Unavailable in current environment");
|
|
41
29
|
}
|
|
42
30
|
if (prefix.length <= 0) {
|
|
43
31
|
throw new Error("Empty prefix");
|
|
44
32
|
}
|
|
45
|
-
|
|
33
|
+
this.#prefix = prefix;
|
|
46
34
|
}
|
|
47
35
|
get prefix() {
|
|
48
|
-
return
|
|
36
|
+
return this.#prefix;
|
|
49
37
|
}
|
|
50
38
|
branch(id) {
|
|
51
39
|
return new StorageLocalStorage(this.prefix + "S__" + id);
|
|
@@ -115,4 +103,3 @@ class StorageLocalStorage {
|
|
|
115
103
|
}
|
|
116
104
|
}
|
|
117
105
|
exports.StorageLocalStorage = StorageLocalStorage;
|
|
118
|
-
_StorageLocalStorage_prefix = new WeakMap();
|
|
@@ -18,40 +18,30 @@
|
|
|
18
18
|
* You should have received a copy of the GNU Lesser General Public License
|
|
19
19
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
20
20
|
*/
|
|
21
|
-
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
22
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
23
|
-
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
24
|
-
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
25
|
-
};
|
|
26
|
-
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
27
|
-
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
28
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
29
|
-
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
30
|
-
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
31
|
-
};
|
|
32
|
-
var _StorageMemory_instances, _StorageMemory_id, _StorageMemory_fixKey, _StorageMemory_getEntries;
|
|
33
21
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
34
22
|
exports.StorageMemory = void 0;
|
|
35
23
|
const _1_utilities_js_1 = require("./1_utilities.js");
|
|
36
24
|
class StorageMemory {
|
|
25
|
+
map = new Map();
|
|
26
|
+
#id = null;
|
|
37
27
|
constructor() {
|
|
38
|
-
_StorageMemory_instances.add(this);
|
|
39
|
-
Object.defineProperty(this, "map", {
|
|
40
|
-
enumerable: true,
|
|
41
|
-
configurable: true,
|
|
42
|
-
writable: true,
|
|
43
|
-
value: new Map()
|
|
44
|
-
});
|
|
45
|
-
_StorageMemory_id.set(this, null);
|
|
46
28
|
}
|
|
47
29
|
get mustSerialize() {
|
|
48
30
|
return false;
|
|
49
31
|
}
|
|
50
32
|
initialize() {
|
|
51
33
|
}
|
|
34
|
+
#fixKey(key) {
|
|
35
|
+
if (this.#id !== null) {
|
|
36
|
+
return ["__S" + this.#id, ...key];
|
|
37
|
+
}
|
|
38
|
+
else {
|
|
39
|
+
return key;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
52
42
|
branch(id) {
|
|
53
43
|
const storage = new StorageMemory();
|
|
54
|
-
|
|
44
|
+
storage.#id = id;
|
|
55
45
|
return storage;
|
|
56
46
|
}
|
|
57
47
|
get supportsFiles() {
|
|
@@ -61,11 +51,21 @@ class StorageMemory {
|
|
|
61
51
|
return true;
|
|
62
52
|
}
|
|
63
53
|
get(key) {
|
|
64
|
-
key =
|
|
54
|
+
key = this.#fixKey(key);
|
|
65
55
|
return this.map.get((0, _1_utilities_js_1.toString)(key)) ?? null;
|
|
66
56
|
}
|
|
57
|
+
#getEntries() {
|
|
58
|
+
const entries = new Array();
|
|
59
|
+
for (const entry of this.map.entries()) {
|
|
60
|
+
if (this.#id !== null && !entry[0].startsWith("__S" + this.#id)) {
|
|
61
|
+
continue;
|
|
62
|
+
}
|
|
63
|
+
entries.push(entry);
|
|
64
|
+
}
|
|
65
|
+
return entries;
|
|
66
|
+
}
|
|
67
67
|
*getMany(filter, params) {
|
|
68
|
-
let entries =
|
|
68
|
+
let entries = this.#getEntries();
|
|
69
69
|
if (params?.reverse) {
|
|
70
70
|
entries.reverse();
|
|
71
71
|
}
|
|
@@ -92,7 +92,7 @@ class StorageMemory {
|
|
|
92
92
|
}
|
|
93
93
|
}
|
|
94
94
|
set(key_, value) {
|
|
95
|
-
key_ =
|
|
95
|
+
key_ = this.#fixKey(key_);
|
|
96
96
|
const key = (0, _1_utilities_js_1.toString)(key_);
|
|
97
97
|
if (value !== null) {
|
|
98
98
|
this.map.set(key, value);
|
|
@@ -106,20 +106,3 @@ class StorageMemory {
|
|
|
106
106
|
}
|
|
107
107
|
}
|
|
108
108
|
exports.StorageMemory = StorageMemory;
|
|
109
|
-
_StorageMemory_id = new WeakMap(), _StorageMemory_instances = new WeakSet(), _StorageMemory_fixKey = function _StorageMemory_fixKey(key) {
|
|
110
|
-
if (__classPrivateFieldGet(this, _StorageMemory_id, "f") !== null) {
|
|
111
|
-
return ["__S" + __classPrivateFieldGet(this, _StorageMemory_id, "f"), ...key];
|
|
112
|
-
}
|
|
113
|
-
else {
|
|
114
|
-
return key;
|
|
115
|
-
}
|
|
116
|
-
}, _StorageMemory_getEntries = function _StorageMemory_getEntries() {
|
|
117
|
-
const entries = new Array();
|
|
118
|
-
for (const entry of this.map.entries()) {
|
|
119
|
-
if (__classPrivateFieldGet(this, _StorageMemory_id, "f") !== null && !entry[0].startsWith("__S" + __classPrivateFieldGet(this, _StorageMemory_id, "f"))) {
|
|
120
|
-
continue;
|
|
121
|
-
}
|
|
122
|
-
entries.push(entry);
|
|
123
|
-
}
|
|
124
|
-
return entries;
|
|
125
|
-
};
|
|
@@ -18,37 +18,25 @@
|
|
|
18
18
|
* You should have received a copy of the GNU Lesser General Public License
|
|
19
19
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
20
20
|
*/
|
|
21
|
-
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
22
|
-
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
23
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
24
|
-
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
25
|
-
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
26
|
-
};
|
|
27
|
-
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
28
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
29
|
-
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
30
|
-
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
31
|
-
};
|
|
32
|
-
var _StorageSessionStorage_prefix;
|
|
33
21
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
34
22
|
exports.StorageSessionStorage = void 0;
|
|
35
23
|
const _1_utilities_js_1 = require("./1_utilities.js");
|
|
36
24
|
class StorageSessionStorage {
|
|
25
|
+
#prefix;
|
|
37
26
|
constructor(prefix) {
|
|
38
|
-
_StorageSessionStorage_prefix.set(this, void 0);
|
|
39
27
|
if (typeof sessionStorage === "undefined") {
|
|
40
28
|
throw new Error("Unavailable in current environment");
|
|
41
29
|
}
|
|
42
30
|
if (prefix.length <= 0) {
|
|
43
31
|
throw new Error("Empty prefix");
|
|
44
32
|
}
|
|
45
|
-
|
|
33
|
+
this.#prefix = prefix;
|
|
46
34
|
}
|
|
47
35
|
get mustSerialize() {
|
|
48
36
|
return true;
|
|
49
37
|
}
|
|
50
38
|
get prefix() {
|
|
51
|
-
return
|
|
39
|
+
return this.#prefix;
|
|
52
40
|
}
|
|
53
41
|
branch(id) {
|
|
54
42
|
return new StorageSessionStorage(this.prefix + "S__" + id);
|
|
@@ -115,4 +103,3 @@ class StorageSessionStorage {
|
|
|
115
103
|
}
|
|
116
104
|
}
|
|
117
105
|
exports.StorageSessionStorage = StorageSessionStorage;
|
|
118
|
-
_StorageSessionStorage_prefix = new WeakMap();
|
|
@@ -21,7 +21,7 @@ import type { Schema } from "./0_types.js";
|
|
|
21
21
|
export declare class TLReader {
|
|
22
22
|
#private;
|
|
23
23
|
protected _buffer: Uint8Array;
|
|
24
|
-
constructor(
|
|
24
|
+
constructor(buffer: Uint8Array);
|
|
25
25
|
get buffer(): Uint8Array;
|
|
26
26
|
read(byteCount: number): Uint8Array<ArrayBuffer>;
|
|
27
27
|
unread(count: number): void;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"1_tl_reader.d.ts","sourceRoot":"","sources":["../../src/tl/1_tl_reader.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAKH,OAAO,KAAK,EAAoB,MAAM,EAAE,MAAM,cAAc,CAAC;AAG7D,qBAAa,QAAQ;;
|
|
1
|
+
{"version":3,"file":"1_tl_reader.d.ts","sourceRoot":"","sources":["../../src/tl/1_tl_reader.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAKH,OAAO,KAAK,EAAoB,MAAM,EAAE,MAAM,cAAc,CAAC;AAG7D,qBAAa,QAAQ;;IAEnB,SAAS,CAAC,OAAO,EAAE,UAAU,CAAC;gBAElB,MAAM,EAAE,UAAU;IAI9B,IAAI,MAAM,IAAI,UAAU,CAEvB;IAED,IAAI,CAAC,SAAS,EAAE,MAAM,GAAG,UAAU,CAAC,WAAW,CAAC;IAUhD,MAAM,CAAC,KAAK,EAAE,MAAM;IASpB,SAAS,CAAC,QAAQ,UAAO,GAAG,MAAM;IAKlC,SAAS,CAAC,QAAQ,UAAO,GAAG,MAAM;IAKlC,WAAW;IAIX,SAAS,CAAC,QAAQ,UAAO,GAAG,MAAM;IAKlC,UAAU,IAAI,MAAM;IAKpB,UAAU,CAAC,QAAQ,UAAO,GAAG,MAAM;IAKnC,UAAU,CAAC,QAAQ,UAAO,GAAG,MAAM;IAKnC,SAAS,IAAI,UAAU,CAAC,WAAW,CAAC;IAiBpC,UAAU,IAAI,MAAM;IAId,QAAQ,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,GAAG,CAAC;CAkI3D"}
|
package/script/tl/1_tl_reader.js
CHANGED
|
@@ -19,34 +19,23 @@
|
|
|
19
19
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
20
20
|
*/
|
|
21
21
|
// deno-lint-ignore-file no-explicit-any
|
|
22
|
-
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
23
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
24
|
-
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
25
|
-
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
26
|
-
};
|
|
27
|
-
var _TLReader_instances, _TLReader_path, _TLReader_deserializeEnum, _TLReader_deserializeType, _TLReader_deserializeVector, _TLReader_deserializePrimitive;
|
|
28
22
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
23
|
exports.TLReader = void 0;
|
|
30
24
|
const _1_utilities_js_1 = require("../1_utilities.js");
|
|
31
25
|
const _0_errors_js_1 = require("../0_errors.js");
|
|
32
26
|
const _0_utilities_js_1 = require("./0_utilities.js");
|
|
33
27
|
class TLReader {
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
configurable: true,
|
|
39
|
-
writable: true,
|
|
40
|
-
value: _buffer
|
|
41
|
-
});
|
|
42
|
-
_TLReader_path.set(this, new Array());
|
|
28
|
+
#path = new Array();
|
|
29
|
+
_buffer;
|
|
30
|
+
constructor(buffer) {
|
|
31
|
+
this._buffer = buffer;
|
|
43
32
|
}
|
|
44
33
|
get buffer() {
|
|
45
34
|
return this._buffer;
|
|
46
35
|
}
|
|
47
36
|
read(byteCount) {
|
|
48
37
|
if (this._buffer.byteLength < byteCount) {
|
|
49
|
-
throw new _0_errors_js_1.TLError("No data remaining",
|
|
38
|
+
throw new _0_errors_js_1.TLError("No data remaining", this.#path);
|
|
50
39
|
}
|
|
51
40
|
const buffer = this._buffer.slice(0, byteCount);
|
|
52
41
|
this._buffer = this._buffer.subarray(byteCount);
|
|
@@ -55,7 +44,7 @@ class TLReader {
|
|
|
55
44
|
unread(count) {
|
|
56
45
|
const newOffest = this._buffer.byteOffset - count;
|
|
57
46
|
if (newOffest < 0) {
|
|
58
|
-
throw new _0_errors_js_1.TLError("No data has been read",
|
|
47
|
+
throw new _0_errors_js_1.TLError("No data has been read", this.#path);
|
|
59
48
|
}
|
|
60
49
|
this._buffer = new Uint8Array(this._buffer.buffer, newOffest);
|
|
61
50
|
}
|
|
@@ -110,7 +99,7 @@ class TLReader {
|
|
|
110
99
|
if ((0, _0_utilities_js_1.isOptionalParam)(name)) {
|
|
111
100
|
name = (0, _0_utilities_js_1.getOptionalParamInnerType)(name);
|
|
112
101
|
}
|
|
113
|
-
const primitive =
|
|
102
|
+
const primitive = this.#deserializePrimitive(name);
|
|
114
103
|
if (primitive !== undefined) {
|
|
115
104
|
return primitive;
|
|
116
105
|
}
|
|
@@ -124,109 +113,112 @@ class TLReader {
|
|
|
124
113
|
if (name === _0_utilities_js_1.X) {
|
|
125
114
|
const typeName = schema.identifierToName[id];
|
|
126
115
|
if (!typeName) {
|
|
127
|
-
throw new _0_errors_js_1.TLError(`Unknown constructor ID: ${(0, _0_utilities_js_1.constructorIdToHex)(id)}`,
|
|
116
|
+
throw new _0_errors_js_1.TLError(`Unknown constructor ID: ${(0, _0_utilities_js_1.constructorIdToHex)(id)}`, this.#path);
|
|
128
117
|
}
|
|
129
118
|
this.unreadInt32();
|
|
130
119
|
return await this.readType(typeName, schema);
|
|
131
120
|
}
|
|
132
121
|
if (id === _0_utilities_js_1.VECTOR) {
|
|
133
|
-
return await
|
|
122
|
+
return await this.#deserializeVector(name, schema);
|
|
134
123
|
}
|
|
135
124
|
const definition = schema.definitions[name];
|
|
136
125
|
if (definition) {
|
|
137
|
-
return await
|
|
126
|
+
return await this.#deserializeType(name, definition, id, schema);
|
|
138
127
|
}
|
|
139
|
-
const deserializedEnum = await
|
|
128
|
+
const deserializedEnum = await this.#deserializeEnum(name, id, schema);
|
|
140
129
|
if (deserializedEnum !== undefined) {
|
|
141
130
|
return deserializedEnum;
|
|
142
131
|
}
|
|
143
|
-
throw new _0_errors_js_1.TLError(`Unknown type: ${name}#${(0, _0_utilities_js_1.constructorIdToHex)(id)}`,
|
|
132
|
+
throw new _0_errors_js_1.TLError(`Unknown type: ${name}#${(0, _0_utilities_js_1.constructorIdToHex)(id)}`, this.#path);
|
|
144
133
|
}
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
if (!name) {
|
|
150
|
-
return;
|
|
151
|
-
}
|
|
152
|
-
const definition = schema.definitions[name];
|
|
153
|
-
if (definition[2] !== type) {
|
|
154
|
-
return;
|
|
155
|
-
}
|
|
156
|
-
return await __classPrivateFieldGet(this, _TLReader_instances, "m", _TLReader_deserializeType).call(this, name, definition, id, schema);
|
|
157
|
-
}, _TLReader_deserializeType = async function _TLReader_deserializeType(type, desc, id, schema) {
|
|
158
|
-
if (desc[0] !== id) {
|
|
159
|
-
throw new _0_errors_js_1.TLError(`Expected constructor with ID ${(0, _0_utilities_js_1.constructorIdToHex)(desc[0])} but received ${(0, _0_utilities_js_1.constructorIdToHex)(id)}`, __classPrivateFieldGet(this, _TLReader_path, "f"));
|
|
160
|
-
}
|
|
161
|
-
let isFirstPathElementExisting = false;
|
|
162
|
-
const type_ = { _: type };
|
|
163
|
-
const flagFields = {};
|
|
164
|
-
for (const [name, fieldType] of desc[1]) {
|
|
165
|
-
if ((0, _0_utilities_js_1.isOptionalParam)(fieldType)) {
|
|
166
|
-
const { flagField, bitIndex } = (0, _0_utilities_js_1.analyzeOptionalParam)(fieldType);
|
|
167
|
-
const bits = flagFields[flagField];
|
|
168
|
-
if ((bits & (1 << bitIndex)) === 0) {
|
|
169
|
-
continue;
|
|
170
|
-
}
|
|
171
|
-
}
|
|
172
|
-
if (fieldType === "#") {
|
|
173
|
-
flagFields[name] = this.readInt32();
|
|
174
|
-
continue;
|
|
134
|
+
async #deserializeEnum(type, id, schema) {
|
|
135
|
+
const name = schema.identifierToName[id];
|
|
136
|
+
if (!name) {
|
|
137
|
+
return;
|
|
175
138
|
}
|
|
176
|
-
const
|
|
177
|
-
if (
|
|
178
|
-
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
return array;
|
|
201
|
-
}, _TLReader_deserializePrimitive = function _TLReader_deserializePrimitive(type) {
|
|
202
|
-
switch (type) {
|
|
203
|
-
case "bytes":
|
|
204
|
-
return this.readBytes();
|
|
205
|
-
case "int128":
|
|
206
|
-
return this.readInt128();
|
|
207
|
-
case "int256":
|
|
208
|
-
return this.readInt256();
|
|
209
|
-
case "double":
|
|
210
|
-
return this.readDouble();
|
|
211
|
-
case "long":
|
|
212
|
-
return this.readInt64();
|
|
213
|
-
case "true":
|
|
214
|
-
return true;
|
|
215
|
-
case "int":
|
|
216
|
-
return this.readInt32();
|
|
217
|
-
case "Bool": {
|
|
218
|
-
const id = this.readInt32(false);
|
|
219
|
-
if (id === _0_utilities_js_1.BOOL_TRUE) {
|
|
220
|
-
return true;
|
|
139
|
+
const definition = schema.definitions[name];
|
|
140
|
+
if (definition[2] !== type) {
|
|
141
|
+
return;
|
|
142
|
+
}
|
|
143
|
+
return await this.#deserializeType(name, definition, id, schema);
|
|
144
|
+
}
|
|
145
|
+
async #deserializeType(type, desc, id, schema) {
|
|
146
|
+
if (desc[0] !== id) {
|
|
147
|
+
throw new _0_errors_js_1.TLError(`Expected constructor with ID ${(0, _0_utilities_js_1.constructorIdToHex)(desc[0])} but received ${(0, _0_utilities_js_1.constructorIdToHex)(id)}`, this.#path);
|
|
148
|
+
}
|
|
149
|
+
let isFirstPathElementExisting = false;
|
|
150
|
+
const type_ = { _: type };
|
|
151
|
+
const flagFields = {};
|
|
152
|
+
for (const [name, fieldType] of desc[1]) {
|
|
153
|
+
if ((0, _0_utilities_js_1.isOptionalParam)(fieldType)) {
|
|
154
|
+
const { flagField, bitIndex } = (0, _0_utilities_js_1.analyzeOptionalParam)(fieldType);
|
|
155
|
+
const bits = flagFields[flagField];
|
|
156
|
+
if ((bits & (1 << bitIndex)) === 0) {
|
|
157
|
+
continue;
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
if (fieldType === "#") {
|
|
161
|
+
flagFields[name] = this.readInt32();
|
|
162
|
+
continue;
|
|
221
163
|
}
|
|
222
|
-
|
|
223
|
-
|
|
164
|
+
const pathElement = `[${type}.]${name}`;
|
|
165
|
+
if (isFirstPathElementExisting) {
|
|
166
|
+
this.#path[this.#path.length - 1] = pathElement;
|
|
224
167
|
}
|
|
225
168
|
else {
|
|
226
|
-
|
|
169
|
+
this.#path.push(pathElement);
|
|
170
|
+
isFirstPathElementExisting = true;
|
|
171
|
+
}
|
|
172
|
+
const value = await this.readType(fieldType, schema);
|
|
173
|
+
if (typeof value !== "boolean" || value) {
|
|
174
|
+
type_[name] = value;
|
|
227
175
|
}
|
|
228
176
|
}
|
|
229
|
-
|
|
230
|
-
|
|
177
|
+
return type_;
|
|
178
|
+
}
|
|
179
|
+
async #deserializeVector(type, schema) {
|
|
180
|
+
const itemType = (0, _0_utilities_js_1.getVectorItemType)(type);
|
|
181
|
+
if (!itemType) {
|
|
182
|
+
throw new _0_errors_js_1.TLError(`Expected Vector but received ${type}`, this.#path);
|
|
183
|
+
}
|
|
184
|
+
const size = this.readInt32();
|
|
185
|
+
const array = new Array();
|
|
186
|
+
for (let i = 0; i < size; ++i) {
|
|
187
|
+
array.push(await this.readType(itemType, schema));
|
|
188
|
+
}
|
|
189
|
+
return array;
|
|
190
|
+
}
|
|
191
|
+
#deserializePrimitive(type) {
|
|
192
|
+
switch (type) {
|
|
193
|
+
case "bytes":
|
|
194
|
+
return this.readBytes();
|
|
195
|
+
case "int128":
|
|
196
|
+
return this.readInt128();
|
|
197
|
+
case "int256":
|
|
198
|
+
return this.readInt256();
|
|
199
|
+
case "double":
|
|
200
|
+
return this.readDouble();
|
|
201
|
+
case "long":
|
|
202
|
+
return this.readInt64();
|
|
203
|
+
case "true":
|
|
204
|
+
return true;
|
|
205
|
+
case "int":
|
|
206
|
+
return this.readInt32();
|
|
207
|
+
case "Bool": {
|
|
208
|
+
const id = this.readInt32(false);
|
|
209
|
+
if (id === _0_utilities_js_1.BOOL_TRUE) {
|
|
210
|
+
return true;
|
|
211
|
+
}
|
|
212
|
+
else if (id === _0_utilities_js_1.BOOL_FALSE) {
|
|
213
|
+
return false;
|
|
214
|
+
}
|
|
215
|
+
else {
|
|
216
|
+
throw new _0_errors_js_1.TLError(`Expected boolTrue or boolFalse but received ${(0, _0_utilities_js_1.constructorIdToHex)(id)}`, this.#path);
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
case "string":
|
|
220
|
+
return this.readString();
|
|
221
|
+
}
|
|
231
222
|
}
|
|
232
|
-
}
|
|
223
|
+
}
|
|
224
|
+
exports.TLReader = TLReader;
|