@mtkruto/browser 0.119.0 → 0.120.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/README.md +1 -1
- 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
|
@@ -17,45 +17,27 @@
|
|
|
17
17
|
* You should have received a copy of the GNU Lesser General Public License
|
|
18
18
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
19
19
|
*/
|
|
20
|
-
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
21
|
-
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
22
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
23
|
-
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");
|
|
24
|
-
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
25
|
-
};
|
|
26
|
-
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
27
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
28
|
-
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");
|
|
29
|
-
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
30
|
-
};
|
|
31
|
-
var _StorageIndexedDB_instances, _StorageIndexedDB_name, _StorageIndexedDB_id, _StorageIndexedDB_supportsFiles, _StorageIndexedDB_fixKey;
|
|
32
20
|
import { fixKey, getPrefixKeyRange, restoreKey } from "./1_utilities.js";
|
|
33
21
|
const VERSION = 1;
|
|
34
22
|
const KV_OBJECT_STORE = "kv";
|
|
35
23
|
export class StorageIndexedDB {
|
|
24
|
+
database = null;
|
|
25
|
+
#name;
|
|
26
|
+
#id = null;
|
|
27
|
+
#supportsFiles;
|
|
36
28
|
constructor(name, params) {
|
|
37
|
-
_StorageIndexedDB_instances.add(this);
|
|
38
|
-
Object.defineProperty(this, "database", {
|
|
39
|
-
enumerable: true,
|
|
40
|
-
configurable: true,
|
|
41
|
-
writable: true,
|
|
42
|
-
value: null
|
|
43
|
-
});
|
|
44
|
-
_StorageIndexedDB_name.set(this, void 0);
|
|
45
|
-
_StorageIndexedDB_id.set(this, null);
|
|
46
|
-
_StorageIndexedDB_supportsFiles.set(this, void 0);
|
|
47
29
|
if (typeof indexedDB === "undefined") {
|
|
48
30
|
throw new Error("Unavailable in current environment");
|
|
49
31
|
}
|
|
50
|
-
|
|
51
|
-
|
|
32
|
+
this.#name = name;
|
|
33
|
+
this.#supportsFiles = params?.storeFiles ?? true;
|
|
52
34
|
}
|
|
53
35
|
get name() {
|
|
54
|
-
return
|
|
36
|
+
return this.#name;
|
|
55
37
|
}
|
|
56
38
|
branch(id) {
|
|
57
|
-
const storage = new StorageIndexedDB(this.name, { storeFiles:
|
|
58
|
-
|
|
39
|
+
const storage = new StorageIndexedDB(this.name, { storeFiles: this.#supportsFiles });
|
|
40
|
+
storage.#id = id;
|
|
59
41
|
return storage;
|
|
60
42
|
}
|
|
61
43
|
initialize() {
|
|
@@ -73,7 +55,7 @@ export class StorageIndexedDB {
|
|
|
73
55
|
});
|
|
74
56
|
}
|
|
75
57
|
get supportsFiles() {
|
|
76
|
-
return
|
|
58
|
+
return this.#supportsFiles;
|
|
77
59
|
}
|
|
78
60
|
get mustSerialize() {
|
|
79
61
|
return true;
|
|
@@ -81,8 +63,16 @@ export class StorageIndexedDB {
|
|
|
81
63
|
get isMemory() {
|
|
82
64
|
return false;
|
|
83
65
|
}
|
|
66
|
+
#fixKey(key) {
|
|
67
|
+
if (this.#id !== null) {
|
|
68
|
+
return ["__S" + this.#id, ...key];
|
|
69
|
+
}
|
|
70
|
+
else {
|
|
71
|
+
return key;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
84
74
|
set(k, v, tx_) {
|
|
85
|
-
k =
|
|
75
|
+
k = this.#fixKey(k);
|
|
86
76
|
if (!this.database) {
|
|
87
77
|
throw new Error("Not initialized");
|
|
88
78
|
}
|
|
@@ -106,7 +96,7 @@ export class StorageIndexedDB {
|
|
|
106
96
|
}
|
|
107
97
|
get(k, tx_, fix = true) {
|
|
108
98
|
if (fix) {
|
|
109
|
-
k =
|
|
99
|
+
k = this.#fixKey(k);
|
|
110
100
|
}
|
|
111
101
|
if (!this.database) {
|
|
112
102
|
throw new Error("Not initialized");
|
|
@@ -123,14 +113,14 @@ export class StorageIndexedDB {
|
|
|
123
113
|
});
|
|
124
114
|
}
|
|
125
115
|
async *getMany(filter, params, tx_) {
|
|
126
|
-
if ("prefix" in filter &&
|
|
127
|
-
filter.prefix =
|
|
116
|
+
if ("prefix" in filter && this.#id !== null) {
|
|
117
|
+
filter.prefix = this.#fixKey(filter.prefix);
|
|
128
118
|
}
|
|
129
|
-
if ("start" in filter &&
|
|
130
|
-
filter.start =
|
|
119
|
+
if ("start" in filter && this.#id !== null) {
|
|
120
|
+
filter.start = this.#fixKey(filter.start);
|
|
131
121
|
}
|
|
132
|
-
if ("end" in filter &&
|
|
133
|
-
filter.end =
|
|
122
|
+
if ("end" in filter && this.#id !== null) {
|
|
123
|
+
filter.end = this.#fixKey(filter.end);
|
|
134
124
|
}
|
|
135
125
|
if (!this.database) {
|
|
136
126
|
throw new Error("Not initialized");
|
|
@@ -180,11 +170,3 @@ export class StorageIndexedDB {
|
|
|
180
170
|
await this.set(key, (currentValue || 0) + by, tx);
|
|
181
171
|
}
|
|
182
172
|
}
|
|
183
|
-
_StorageIndexedDB_name = new WeakMap(), _StorageIndexedDB_id = new WeakMap(), _StorageIndexedDB_supportsFiles = new WeakMap(), _StorageIndexedDB_instances = new WeakSet(), _StorageIndexedDB_fixKey = function _StorageIndexedDB_fixKey(key) {
|
|
184
|
-
if (__classPrivateFieldGet(this, _StorageIndexedDB_id, "f") !== null) {
|
|
185
|
-
return ["__S" + __classPrivateFieldGet(this, _StorageIndexedDB_id, "f"), ...key];
|
|
186
|
-
}
|
|
187
|
-
else {
|
|
188
|
-
return key;
|
|
189
|
-
}
|
|
190
|
-
};
|
|
@@ -17,32 +17,20 @@
|
|
|
17
17
|
* You should have received a copy of the GNU Lesser General Public License
|
|
18
18
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
19
19
|
*/
|
|
20
|
-
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
21
|
-
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
22
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
23
|
-
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");
|
|
24
|
-
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
25
|
-
};
|
|
26
|
-
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
27
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
28
|
-
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");
|
|
29
|
-
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
30
|
-
};
|
|
31
|
-
var _StorageLocalStorage_prefix;
|
|
32
20
|
import { fromString, isInRange, toString } from "./1_utilities.js";
|
|
33
21
|
export class StorageLocalStorage {
|
|
22
|
+
#prefix;
|
|
34
23
|
constructor(prefix) {
|
|
35
|
-
_StorageLocalStorage_prefix.set(this, void 0);
|
|
36
24
|
if (typeof localStorage === "undefined") {
|
|
37
25
|
throw new Error("Unavailable in current environment");
|
|
38
26
|
}
|
|
39
27
|
if (prefix.length <= 0) {
|
|
40
28
|
throw new Error("Empty prefix");
|
|
41
29
|
}
|
|
42
|
-
|
|
30
|
+
this.#prefix = prefix;
|
|
43
31
|
}
|
|
44
32
|
get prefix() {
|
|
45
|
-
return
|
|
33
|
+
return this.#prefix;
|
|
46
34
|
}
|
|
47
35
|
branch(id) {
|
|
48
36
|
return new StorageLocalStorage(this.prefix + "S__" + id);
|
|
@@ -111,4 +99,3 @@ export class StorageLocalStorage {
|
|
|
111
99
|
this.set(key, (this.get(key) || 0) + by);
|
|
112
100
|
}
|
|
113
101
|
}
|
|
114
|
-
_StorageLocalStorage_prefix = new WeakMap();
|
|
@@ -17,38 +17,28 @@
|
|
|
17
17
|
* You should have received a copy of the GNU Lesser General Public License
|
|
18
18
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
19
19
|
*/
|
|
20
|
-
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
21
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
22
|
-
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");
|
|
23
|
-
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
24
|
-
};
|
|
25
|
-
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
26
|
-
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
27
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
28
|
-
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");
|
|
29
|
-
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
30
|
-
};
|
|
31
|
-
var _StorageMemory_instances, _StorageMemory_id, _StorageMemory_fixKey, _StorageMemory_getEntries;
|
|
32
20
|
import { fromString, isInRange, toString } from "./1_utilities.js";
|
|
33
21
|
export class StorageMemory {
|
|
22
|
+
map = new Map();
|
|
23
|
+
#id = null;
|
|
34
24
|
constructor() {
|
|
35
|
-
_StorageMemory_instances.add(this);
|
|
36
|
-
Object.defineProperty(this, "map", {
|
|
37
|
-
enumerable: true,
|
|
38
|
-
configurable: true,
|
|
39
|
-
writable: true,
|
|
40
|
-
value: new Map()
|
|
41
|
-
});
|
|
42
|
-
_StorageMemory_id.set(this, null);
|
|
43
25
|
}
|
|
44
26
|
get mustSerialize() {
|
|
45
27
|
return false;
|
|
46
28
|
}
|
|
47
29
|
initialize() {
|
|
48
30
|
}
|
|
31
|
+
#fixKey(key) {
|
|
32
|
+
if (this.#id !== null) {
|
|
33
|
+
return ["__S" + this.#id, ...key];
|
|
34
|
+
}
|
|
35
|
+
else {
|
|
36
|
+
return key;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
49
39
|
branch(id) {
|
|
50
40
|
const storage = new StorageMemory();
|
|
51
|
-
|
|
41
|
+
storage.#id = id;
|
|
52
42
|
return storage;
|
|
53
43
|
}
|
|
54
44
|
get supportsFiles() {
|
|
@@ -58,11 +48,21 @@ export class StorageMemory {
|
|
|
58
48
|
return true;
|
|
59
49
|
}
|
|
60
50
|
get(key) {
|
|
61
|
-
key =
|
|
51
|
+
key = this.#fixKey(key);
|
|
62
52
|
return this.map.get(toString(key)) ?? null;
|
|
63
53
|
}
|
|
54
|
+
#getEntries() {
|
|
55
|
+
const entries = new Array();
|
|
56
|
+
for (const entry of this.map.entries()) {
|
|
57
|
+
if (this.#id !== null && !entry[0].startsWith("__S" + this.#id)) {
|
|
58
|
+
continue;
|
|
59
|
+
}
|
|
60
|
+
entries.push(entry);
|
|
61
|
+
}
|
|
62
|
+
return entries;
|
|
63
|
+
}
|
|
64
64
|
*getMany(filter, params) {
|
|
65
|
-
let entries =
|
|
65
|
+
let entries = this.#getEntries();
|
|
66
66
|
if (params?.reverse) {
|
|
67
67
|
entries.reverse();
|
|
68
68
|
}
|
|
@@ -89,7 +89,7 @@ export class StorageMemory {
|
|
|
89
89
|
}
|
|
90
90
|
}
|
|
91
91
|
set(key_, value) {
|
|
92
|
-
key_ =
|
|
92
|
+
key_ = this.#fixKey(key_);
|
|
93
93
|
const key = toString(key_);
|
|
94
94
|
if (value !== null) {
|
|
95
95
|
this.map.set(key, value);
|
|
@@ -102,20 +102,3 @@ export class StorageMemory {
|
|
|
102
102
|
this.set(key, (this.get(key) || 0) + by);
|
|
103
103
|
}
|
|
104
104
|
}
|
|
105
|
-
_StorageMemory_id = new WeakMap(), _StorageMemory_instances = new WeakSet(), _StorageMemory_fixKey = function _StorageMemory_fixKey(key) {
|
|
106
|
-
if (__classPrivateFieldGet(this, _StorageMemory_id, "f") !== null) {
|
|
107
|
-
return ["__S" + __classPrivateFieldGet(this, _StorageMemory_id, "f"), ...key];
|
|
108
|
-
}
|
|
109
|
-
else {
|
|
110
|
-
return key;
|
|
111
|
-
}
|
|
112
|
-
}, _StorageMemory_getEntries = function _StorageMemory_getEntries() {
|
|
113
|
-
const entries = new Array();
|
|
114
|
-
for (const entry of this.map.entries()) {
|
|
115
|
-
if (__classPrivateFieldGet(this, _StorageMemory_id, "f") !== null && !entry[0].startsWith("__S" + __classPrivateFieldGet(this, _StorageMemory_id, "f"))) {
|
|
116
|
-
continue;
|
|
117
|
-
}
|
|
118
|
-
entries.push(entry);
|
|
119
|
-
}
|
|
120
|
-
return entries;
|
|
121
|
-
};
|
|
@@ -17,35 +17,23 @@
|
|
|
17
17
|
* You should have received a copy of the GNU Lesser General Public License
|
|
18
18
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
19
19
|
*/
|
|
20
|
-
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
21
|
-
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
22
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
23
|
-
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");
|
|
24
|
-
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
25
|
-
};
|
|
26
|
-
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
27
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
28
|
-
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");
|
|
29
|
-
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
30
|
-
};
|
|
31
|
-
var _StorageSessionStorage_prefix;
|
|
32
20
|
import { fromString, isInRange, toString } from "./1_utilities.js";
|
|
33
21
|
export class StorageSessionStorage {
|
|
22
|
+
#prefix;
|
|
34
23
|
constructor(prefix) {
|
|
35
|
-
_StorageSessionStorage_prefix.set(this, void 0);
|
|
36
24
|
if (typeof sessionStorage === "undefined") {
|
|
37
25
|
throw new Error("Unavailable in current environment");
|
|
38
26
|
}
|
|
39
27
|
if (prefix.length <= 0) {
|
|
40
28
|
throw new Error("Empty prefix");
|
|
41
29
|
}
|
|
42
|
-
|
|
30
|
+
this.#prefix = prefix;
|
|
43
31
|
}
|
|
44
32
|
get mustSerialize() {
|
|
45
33
|
return true;
|
|
46
34
|
}
|
|
47
35
|
get prefix() {
|
|
48
|
-
return
|
|
36
|
+
return this.#prefix;
|
|
49
37
|
}
|
|
50
38
|
branch(id) {
|
|
51
39
|
return new StorageSessionStorage(this.prefix + "S__" + id);
|
|
@@ -111,4 +99,3 @@ export class StorageSessionStorage {
|
|
|
111
99
|
this.set(key, (this.get(key) || 0) + by);
|
|
112
100
|
}
|
|
113
101
|
}
|
|
114
|
-
_StorageSessionStorage_prefix = new WeakMap();
|
package/esm/tl/1_tl_reader.d.ts
CHANGED
|
@@ -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/esm/tl/1_tl_reader.js
CHANGED
|
@@ -18,32 +18,21 @@
|
|
|
18
18
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
19
19
|
*/
|
|
20
20
|
// deno-lint-ignore-file no-explicit-any
|
|
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 _TLReader_instances, _TLReader_path, _TLReader_deserializeEnum, _TLReader_deserializeType, _TLReader_deserializeVector, _TLReader_deserializePrimitive;
|
|
27
21
|
import { decodeText, intFromBytes } from "../1_utilities.js";
|
|
28
22
|
import { TLError } from "../0_errors.js";
|
|
29
23
|
import { analyzeOptionalParam, BOOL_FALSE, BOOL_TRUE, constructorIdToHex, getOptionalParamInnerType, getVectorItemType, isOptionalParam, VECTOR, X } from "./0_utilities.js";
|
|
30
24
|
export class TLReader {
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
configurable: true,
|
|
36
|
-
writable: true,
|
|
37
|
-
value: _buffer
|
|
38
|
-
});
|
|
39
|
-
_TLReader_path.set(this, new Array());
|
|
25
|
+
#path = new Array();
|
|
26
|
+
_buffer;
|
|
27
|
+
constructor(buffer) {
|
|
28
|
+
this._buffer = buffer;
|
|
40
29
|
}
|
|
41
30
|
get buffer() {
|
|
42
31
|
return this._buffer;
|
|
43
32
|
}
|
|
44
33
|
read(byteCount) {
|
|
45
34
|
if (this._buffer.byteLength < byteCount) {
|
|
46
|
-
throw new TLError("No data remaining",
|
|
35
|
+
throw new TLError("No data remaining", this.#path);
|
|
47
36
|
}
|
|
48
37
|
const buffer = this._buffer.slice(0, byteCount);
|
|
49
38
|
this._buffer = this._buffer.subarray(byteCount);
|
|
@@ -52,7 +41,7 @@ export class TLReader {
|
|
|
52
41
|
unread(count) {
|
|
53
42
|
const newOffest = this._buffer.byteOffset - count;
|
|
54
43
|
if (newOffest < 0) {
|
|
55
|
-
throw new TLError("No data has been read",
|
|
44
|
+
throw new TLError("No data has been read", this.#path);
|
|
56
45
|
}
|
|
57
46
|
this._buffer = new Uint8Array(this._buffer.buffer, newOffest);
|
|
58
47
|
}
|
|
@@ -107,7 +96,7 @@ export class TLReader {
|
|
|
107
96
|
if (isOptionalParam(name)) {
|
|
108
97
|
name = getOptionalParamInnerType(name);
|
|
109
98
|
}
|
|
110
|
-
const primitive =
|
|
99
|
+
const primitive = this.#deserializePrimitive(name);
|
|
111
100
|
if (primitive !== undefined) {
|
|
112
101
|
return primitive;
|
|
113
102
|
}
|
|
@@ -121,108 +110,111 @@ export class TLReader {
|
|
|
121
110
|
if (name === X) {
|
|
122
111
|
const typeName = schema.identifierToName[id];
|
|
123
112
|
if (!typeName) {
|
|
124
|
-
throw new TLError(`Unknown constructor ID: ${constructorIdToHex(id)}`,
|
|
113
|
+
throw new TLError(`Unknown constructor ID: ${constructorIdToHex(id)}`, this.#path);
|
|
125
114
|
}
|
|
126
115
|
this.unreadInt32();
|
|
127
116
|
return await this.readType(typeName, schema);
|
|
128
117
|
}
|
|
129
118
|
if (id === VECTOR) {
|
|
130
|
-
return await
|
|
119
|
+
return await this.#deserializeVector(name, schema);
|
|
131
120
|
}
|
|
132
121
|
const definition = schema.definitions[name];
|
|
133
122
|
if (definition) {
|
|
134
|
-
return await
|
|
123
|
+
return await this.#deserializeType(name, definition, id, schema);
|
|
135
124
|
}
|
|
136
|
-
const deserializedEnum = await
|
|
125
|
+
const deserializedEnum = await this.#deserializeEnum(name, id, schema);
|
|
137
126
|
if (deserializedEnum !== undefined) {
|
|
138
127
|
return deserializedEnum;
|
|
139
128
|
}
|
|
140
|
-
throw new TLError(`Unknown type: ${name}#${constructorIdToHex(id)}`,
|
|
129
|
+
throw new TLError(`Unknown type: ${name}#${constructorIdToHex(id)}`, this.#path);
|
|
141
130
|
}
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
return;
|
|
147
|
-
}
|
|
148
|
-
const definition = schema.definitions[name];
|
|
149
|
-
if (definition[2] !== type) {
|
|
150
|
-
return;
|
|
151
|
-
}
|
|
152
|
-
return await __classPrivateFieldGet(this, _TLReader_instances, "m", _TLReader_deserializeType).call(this, name, definition, id, schema);
|
|
153
|
-
}, _TLReader_deserializeType = async function _TLReader_deserializeType(type, desc, id, schema) {
|
|
154
|
-
if (desc[0] !== id) {
|
|
155
|
-
throw new TLError(`Expected constructor with ID ${constructorIdToHex(desc[0])} but received ${constructorIdToHex(id)}`, __classPrivateFieldGet(this, _TLReader_path, "f"));
|
|
156
|
-
}
|
|
157
|
-
let isFirstPathElementExisting = false;
|
|
158
|
-
const type_ = { _: type };
|
|
159
|
-
const flagFields = {};
|
|
160
|
-
for (const [name, fieldType] of desc[1]) {
|
|
161
|
-
if (isOptionalParam(fieldType)) {
|
|
162
|
-
const { flagField, bitIndex } = analyzeOptionalParam(fieldType);
|
|
163
|
-
const bits = flagFields[flagField];
|
|
164
|
-
if ((bits & (1 << bitIndex)) === 0) {
|
|
165
|
-
continue;
|
|
166
|
-
}
|
|
167
|
-
}
|
|
168
|
-
if (fieldType === "#") {
|
|
169
|
-
flagFields[name] = this.readInt32();
|
|
170
|
-
continue;
|
|
131
|
+
async #deserializeEnum(type, id, schema) {
|
|
132
|
+
const name = schema.identifierToName[id];
|
|
133
|
+
if (!name) {
|
|
134
|
+
return;
|
|
171
135
|
}
|
|
172
|
-
const
|
|
173
|
-
if (
|
|
174
|
-
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
return array;
|
|
197
|
-
}, _TLReader_deserializePrimitive = function _TLReader_deserializePrimitive(type) {
|
|
198
|
-
switch (type) {
|
|
199
|
-
case "bytes":
|
|
200
|
-
return this.readBytes();
|
|
201
|
-
case "int128":
|
|
202
|
-
return this.readInt128();
|
|
203
|
-
case "int256":
|
|
204
|
-
return this.readInt256();
|
|
205
|
-
case "double":
|
|
206
|
-
return this.readDouble();
|
|
207
|
-
case "long":
|
|
208
|
-
return this.readInt64();
|
|
209
|
-
case "true":
|
|
210
|
-
return true;
|
|
211
|
-
case "int":
|
|
212
|
-
return this.readInt32();
|
|
213
|
-
case "Bool": {
|
|
214
|
-
const id = this.readInt32(false);
|
|
215
|
-
if (id === BOOL_TRUE) {
|
|
216
|
-
return true;
|
|
136
|
+
const definition = schema.definitions[name];
|
|
137
|
+
if (definition[2] !== type) {
|
|
138
|
+
return;
|
|
139
|
+
}
|
|
140
|
+
return await this.#deserializeType(name, definition, id, schema);
|
|
141
|
+
}
|
|
142
|
+
async #deserializeType(type, desc, id, schema) {
|
|
143
|
+
if (desc[0] !== id) {
|
|
144
|
+
throw new TLError(`Expected constructor with ID ${constructorIdToHex(desc[0])} but received ${constructorIdToHex(id)}`, this.#path);
|
|
145
|
+
}
|
|
146
|
+
let isFirstPathElementExisting = false;
|
|
147
|
+
const type_ = { _: type };
|
|
148
|
+
const flagFields = {};
|
|
149
|
+
for (const [name, fieldType] of desc[1]) {
|
|
150
|
+
if (isOptionalParam(fieldType)) {
|
|
151
|
+
const { flagField, bitIndex } = analyzeOptionalParam(fieldType);
|
|
152
|
+
const bits = flagFields[flagField];
|
|
153
|
+
if ((bits & (1 << bitIndex)) === 0) {
|
|
154
|
+
continue;
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
if (fieldType === "#") {
|
|
158
|
+
flagFields[name] = this.readInt32();
|
|
159
|
+
continue;
|
|
217
160
|
}
|
|
218
|
-
|
|
219
|
-
|
|
161
|
+
const pathElement = `[${type}.]${name}`;
|
|
162
|
+
if (isFirstPathElementExisting) {
|
|
163
|
+
this.#path[this.#path.length - 1] = pathElement;
|
|
220
164
|
}
|
|
221
165
|
else {
|
|
222
|
-
|
|
166
|
+
this.#path.push(pathElement);
|
|
167
|
+
isFirstPathElementExisting = true;
|
|
168
|
+
}
|
|
169
|
+
const value = await this.readType(fieldType, schema);
|
|
170
|
+
if (typeof value !== "boolean" || value) {
|
|
171
|
+
type_[name] = value;
|
|
223
172
|
}
|
|
224
173
|
}
|
|
225
|
-
|
|
226
|
-
|
|
174
|
+
return type_;
|
|
175
|
+
}
|
|
176
|
+
async #deserializeVector(type, schema) {
|
|
177
|
+
const itemType = getVectorItemType(type);
|
|
178
|
+
if (!itemType) {
|
|
179
|
+
throw new TLError(`Expected Vector but received ${type}`, this.#path);
|
|
180
|
+
}
|
|
181
|
+
const size = this.readInt32();
|
|
182
|
+
const array = new Array();
|
|
183
|
+
for (let i = 0; i < size; ++i) {
|
|
184
|
+
array.push(await this.readType(itemType, schema));
|
|
185
|
+
}
|
|
186
|
+
return array;
|
|
187
|
+
}
|
|
188
|
+
#deserializePrimitive(type) {
|
|
189
|
+
switch (type) {
|
|
190
|
+
case "bytes":
|
|
191
|
+
return this.readBytes();
|
|
192
|
+
case "int128":
|
|
193
|
+
return this.readInt128();
|
|
194
|
+
case "int256":
|
|
195
|
+
return this.readInt256();
|
|
196
|
+
case "double":
|
|
197
|
+
return this.readDouble();
|
|
198
|
+
case "long":
|
|
199
|
+
return this.readInt64();
|
|
200
|
+
case "true":
|
|
201
|
+
return true;
|
|
202
|
+
case "int":
|
|
203
|
+
return this.readInt32();
|
|
204
|
+
case "Bool": {
|
|
205
|
+
const id = this.readInt32(false);
|
|
206
|
+
if (id === BOOL_TRUE) {
|
|
207
|
+
return true;
|
|
208
|
+
}
|
|
209
|
+
else if (id === BOOL_FALSE) {
|
|
210
|
+
return false;
|
|
211
|
+
}
|
|
212
|
+
else {
|
|
213
|
+
throw new TLError(`Expected boolTrue or boolFalse but received ${constructorIdToHex(id)}`, this.#path);
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
case "string":
|
|
217
|
+
return this.readString();
|
|
218
|
+
}
|
|
227
219
|
}
|
|
228
|
-
}
|
|
220
|
+
}
|