@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.
Files changed (127) hide show
  1. package/esm/0_errors.d.ts.map +1 -1
  2. package/esm/0_errors.js +9 -31
  3. package/esm/3_errors.js +2 -12
  4. package/esm/4_errors.js +2 -12
  5. package/esm/_dnt.polyfills.d.ts +0 -99
  6. package/esm/_dnt.polyfills.d.ts.map +1 -1
  7. package/esm/_dnt.polyfills.js +1 -127
  8. package/esm/client/0_abortable_loop.js +26 -39
  9. package/esm/client/0_storage_operations.js +179 -218
  10. package/esm/client/1_client_plain.js +4 -22
  11. package/esm/client/2_account_manager.js +140 -149
  12. package/esm/client/2_bot_info_manager.js +26 -38
  13. package/esm/client/2_business_connection_manager.js +10 -23
  14. package/esm/client/2_client_encrypted.js +198 -215
  15. package/esm/client/2_file_manager.js +255 -262
  16. package/esm/client/2_network_statistics_manager.js +31 -44
  17. package/esm/client/2_payment_manager.js +7 -20
  18. package/esm/client/2_reaction_manager.js +7 -20
  19. package/esm/client/2_translations_manager.js +101 -111
  20. package/esm/client/2_update_manager.js +750 -745
  21. package/esm/client/3_client_encrypted_pool.js +10 -26
  22. package/esm/client/3_message_manager.js +503 -508
  23. package/esm/client/3_video_chat_manager.js +57 -68
  24. package/esm/client/4_callback_query_manager.js +18 -30
  25. package/esm/client/4_chat_list_manager.js +140 -146
  26. package/esm/client/4_chat_manager.js +161 -169
  27. package/esm/client/4_checklist_manager.js +26 -39
  28. package/esm/client/4_context.js +244 -259
  29. package/esm/client/4_forum_manager.js +67 -73
  30. package/esm/client/4_gift_manager.js +22 -35
  31. package/esm/client/4_inline_query_manager.js +16 -28
  32. package/esm/client/4_link_preview_manager.js +6 -19
  33. package/esm/client/4_poll_manager.js +44 -57
  34. package/esm/client/4_story_manager.js +41 -53
  35. package/esm/client/5_composer.js +13 -26
  36. package/esm/client/6_client.js +866 -896
  37. package/esm/client/6_client_dispatcher.js +308 -325
  38. package/esm/client/7_client_worker.js +16 -29
  39. package/esm/connection/1_connection_tcp.js +55 -82
  40. package/esm/connection/1_connection_web_socket.js +75 -91
  41. package/esm/deps/jsr.io/@roj/tgcrypto/1.0.1/dist/tgcrypto.js +3 -11
  42. package/esm/deps/jsr.io/@std/async/1.2.0/mux_async_iterator.js +31 -47
  43. package/esm/deps/jsr.io/@std/async/1.2.0/tee.js +11 -34
  44. package/esm/deps/jsr.io/@std/cache/0.2.2/lru_cache.js +30 -47
  45. package/esm/deps/jsr.io/@std/datetime/0.225.7/_date_time_formatter.js +4 -17
  46. package/esm/session/0_session_state.js +12 -38
  47. package/esm/session/1_session.js +49 -72
  48. package/esm/session/2_session_encrypted.js +422 -420
  49. package/esm/storage/2_storage_indexed_db.js +26 -44
  50. package/esm/storage/2_storage_local_storage.js +3 -16
  51. package/esm/storage/2_storage_memory.js +24 -41
  52. package/esm/storage/2_storage_session_storage.js +3 -16
  53. package/esm/tl/1_tl_reader.d.ts +1 -1
  54. package/esm/tl/1_tl_reader.d.ts.map +1 -1
  55. package/esm/tl/1_tl_reader.js +95 -103
  56. package/esm/tl/1_tl_writer.js +169 -178
  57. package/esm/transport/0_transport.js +1 -8
  58. package/esm/transport/1_transport_abridged.js +11 -24
  59. package/esm/transport/1_transport_intermediate.js +10 -23
  60. package/esm/utilities/0_mutex.js +4 -19
  61. package/esm/utilities/0_part_stream.js +11 -25
  62. package/esm/utilities/1_crypto.js +42 -53
  63. package/esm/utilities/2_queue.js +29 -47
  64. package/package.json +1 -1
  65. package/script/0_errors.d.ts.map +1 -1
  66. package/script/0_errors.js +9 -31
  67. package/script/3_errors.js +2 -12
  68. package/script/4_errors.js +2 -12
  69. package/script/_dnt.polyfills.d.ts +0 -99
  70. package/script/_dnt.polyfills.d.ts.map +1 -1
  71. package/script/_dnt.polyfills.js +0 -128
  72. package/script/client/0_abortable_loop.js +27 -40
  73. package/script/client/0_storage_operations.js +179 -218
  74. package/script/client/1_client_plain.js +4 -22
  75. package/script/client/2_account_manager.js +140 -149
  76. package/script/client/2_bot_info_manager.js +26 -38
  77. package/script/client/2_business_connection_manager.js +10 -23
  78. package/script/client/2_client_encrypted.js +199 -216
  79. package/script/client/2_file_manager.js +255 -262
  80. package/script/client/2_network_statistics_manager.js +32 -45
  81. package/script/client/2_payment_manager.js +7 -20
  82. package/script/client/2_reaction_manager.js +7 -20
  83. package/script/client/2_translations_manager.js +102 -112
  84. package/script/client/2_update_manager.js +750 -745
  85. package/script/client/3_client_encrypted_pool.js +10 -26
  86. package/script/client/3_message_manager.js +503 -508
  87. package/script/client/3_video_chat_manager.js +57 -68
  88. package/script/client/4_callback_query_manager.js +18 -30
  89. package/script/client/4_chat_list_manager.js +140 -146
  90. package/script/client/4_chat_manager.js +161 -169
  91. package/script/client/4_checklist_manager.js +26 -39
  92. package/script/client/4_context.js +244 -259
  93. package/script/client/4_forum_manager.js +67 -73
  94. package/script/client/4_gift_manager.js +22 -35
  95. package/script/client/4_inline_query_manager.js +16 -28
  96. package/script/client/4_link_preview_manager.js +6 -19
  97. package/script/client/4_poll_manager.js +44 -57
  98. package/script/client/4_story_manager.js +41 -53
  99. package/script/client/5_composer.js +13 -26
  100. package/script/client/6_client.js +866 -896
  101. package/script/client/6_client_dispatcher.js +308 -325
  102. package/script/client/7_client_worker.js +16 -29
  103. package/script/connection/1_connection_tcp.js +55 -82
  104. package/script/connection/1_connection_web_socket.js +75 -91
  105. package/script/deps/jsr.io/@roj/tgcrypto/1.0.1/dist/tgcrypto.js +3 -11
  106. package/script/deps/jsr.io/@std/async/1.2.0/mux_async_iterator.js +31 -47
  107. package/script/deps/jsr.io/@std/async/1.2.0/tee.js +11 -34
  108. package/script/deps/jsr.io/@std/cache/0.2.2/lru_cache.js +30 -47
  109. package/script/deps/jsr.io/@std/datetime/0.225.7/_date_time_formatter.js +4 -17
  110. package/script/session/0_session_state.js +12 -38
  111. package/script/session/1_session.js +49 -72
  112. package/script/session/2_session_encrypted.js +423 -421
  113. package/script/storage/2_storage_indexed_db.js +26 -44
  114. package/script/storage/2_storage_local_storage.js +3 -16
  115. package/script/storage/2_storage_memory.js +24 -41
  116. package/script/storage/2_storage_session_storage.js +3 -16
  117. package/script/tl/1_tl_reader.d.ts +1 -1
  118. package/script/tl/1_tl_reader.d.ts.map +1 -1
  119. package/script/tl/1_tl_reader.js +96 -104
  120. package/script/tl/1_tl_writer.js +170 -179
  121. package/script/transport/0_transport.js +1 -8
  122. package/script/transport/1_transport_abridged.js +11 -24
  123. package/script/transport/1_transport_intermediate.js +10 -23
  124. package/script/utilities/0_mutex.js +4 -19
  125. package/script/utilities/0_part_stream.js +11 -25
  126. package/script/utilities/1_crypto.js +43 -54
  127. 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
- __classPrivateFieldSet(this, _StorageIndexedDB_name, name, "f");
51
- __classPrivateFieldSet(this, _StorageIndexedDB_supportsFiles, params?.storeFiles ?? true, "f");
32
+ this.#name = name;
33
+ this.#supportsFiles = params?.storeFiles ?? true;
52
34
  }
53
35
  get name() {
54
- return __classPrivateFieldGet(this, _StorageIndexedDB_name, "f");
36
+ return this.#name;
55
37
  }
56
38
  branch(id) {
57
- const storage = new StorageIndexedDB(this.name, { storeFiles: __classPrivateFieldGet(this, _StorageIndexedDB_supportsFiles, "f") });
58
- __classPrivateFieldSet(storage, _StorageIndexedDB_id, id, "f");
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 __classPrivateFieldGet(this, _StorageIndexedDB_supportsFiles, "f");
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 = __classPrivateFieldGet(this, _StorageIndexedDB_instances, "m", _StorageIndexedDB_fixKey).call(this, 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 = __classPrivateFieldGet(this, _StorageIndexedDB_instances, "m", _StorageIndexedDB_fixKey).call(this, 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 && __classPrivateFieldGet(this, _StorageIndexedDB_id, "f") !== null) {
127
- filter.prefix = __classPrivateFieldGet(this, _StorageIndexedDB_instances, "m", _StorageIndexedDB_fixKey).call(this, filter.prefix);
116
+ if ("prefix" in filter && this.#id !== null) {
117
+ filter.prefix = this.#fixKey(filter.prefix);
128
118
  }
129
- if ("start" in filter && __classPrivateFieldGet(this, _StorageIndexedDB_id, "f") !== null) {
130
- filter.start = __classPrivateFieldGet(this, _StorageIndexedDB_instances, "m", _StorageIndexedDB_fixKey).call(this, filter.start);
119
+ if ("start" in filter && this.#id !== null) {
120
+ filter.start = this.#fixKey(filter.start);
131
121
  }
132
- if ("end" in filter && __classPrivateFieldGet(this, _StorageIndexedDB_id, "f") !== null) {
133
- filter.end = __classPrivateFieldGet(this, _StorageIndexedDB_instances, "m", _StorageIndexedDB_fixKey).call(this, 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
- __classPrivateFieldSet(this, _StorageLocalStorage_prefix, prefix, "f");
30
+ this.#prefix = prefix;
43
31
  }
44
32
  get prefix() {
45
- return __classPrivateFieldGet(this, _StorageLocalStorage_prefix, "f");
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
- __classPrivateFieldSet(storage, _StorageMemory_id, id, "f");
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 = __classPrivateFieldGet(this, _StorageMemory_instances, "m", _StorageMemory_fixKey).call(this, 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 = __classPrivateFieldGet(this, _StorageMemory_instances, "m", _StorageMemory_getEntries).call(this);
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_ = __classPrivateFieldGet(this, _StorageMemory_instances, "m", _StorageMemory_fixKey).call(this, 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
- __classPrivateFieldSet(this, _StorageSessionStorage_prefix, prefix, "f");
30
+ this.#prefix = prefix;
43
31
  }
44
32
  get mustSerialize() {
45
33
  return true;
46
34
  }
47
35
  get prefix() {
48
- return __classPrivateFieldGet(this, _StorageSessionStorage_prefix, "f");
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();
@@ -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(_buffer: Uint8Array);
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;;IAGP,SAAS,CAAC,OAAO,EAAE,UAAU;gBAAnB,OAAO,EAAE,UAAU;IAGzC,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"}
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"}
@@ -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
- constructor(_buffer) {
32
- _TLReader_instances.add(this);
33
- Object.defineProperty(this, "_buffer", {
34
- enumerable: true,
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", __classPrivateFieldGet(this, _TLReader_path, "f"));
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", __classPrivateFieldGet(this, _TLReader_path, "f"));
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 = __classPrivateFieldGet(this, _TLReader_instances, "m", _TLReader_deserializePrimitive).call(this, name);
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)}`, __classPrivateFieldGet(this, _TLReader_path, "f"));
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 __classPrivateFieldGet(this, _TLReader_instances, "m", _TLReader_deserializeVector).call(this, name, schema);
119
+ return await this.#deserializeVector(name, schema);
131
120
  }
132
121
  const definition = schema.definitions[name];
133
122
  if (definition) {
134
- return await __classPrivateFieldGet(this, _TLReader_instances, "m", _TLReader_deserializeType).call(this, name, definition, id, schema);
123
+ return await this.#deserializeType(name, definition, id, schema);
135
124
  }
136
- const deserializedEnum = await __classPrivateFieldGet(this, _TLReader_instances, "m", _TLReader_deserializeEnum).call(this, name, id, schema);
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)}`, __classPrivateFieldGet(this, _TLReader_path, "f"));
129
+ throw new TLError(`Unknown type: ${name}#${constructorIdToHex(id)}`, this.#path);
141
130
  }
142
- }
143
- _TLReader_path = new WeakMap(), _TLReader_instances = new WeakSet(), _TLReader_deserializeEnum = async function _TLReader_deserializeEnum(type, id, schema) {
144
- const name = schema.identifierToName[id];
145
- if (!name) {
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 pathElement = `[${type}.]${name}`;
173
- if (isFirstPathElementExisting) {
174
- __classPrivateFieldGet(this, _TLReader_path, "f")[__classPrivateFieldGet(this, _TLReader_path, "f").length - 1] = pathElement;
175
- }
176
- else {
177
- __classPrivateFieldGet(this, _TLReader_path, "f").push(pathElement);
178
- isFirstPathElementExisting = true;
179
- }
180
- const value = await this.readType(fieldType, schema);
181
- if (typeof value !== "boolean" || value) {
182
- type_[name] = value;
183
- }
184
- }
185
- return type_;
186
- }, _TLReader_deserializeVector = async function _TLReader_deserializeVector(type, schema) {
187
- const itemType = getVectorItemType(type);
188
- if (!itemType) {
189
- throw new TLError(`Expected Vector but received ${type}`, __classPrivateFieldGet(this, _TLReader_path, "f"));
190
- }
191
- const size = this.readInt32();
192
- const array = new Array();
193
- for (let i = 0; i < size; ++i) {
194
- array.push(await this.readType(itemType, schema));
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
- else if (id === BOOL_FALSE) {
219
- return false;
161
+ const pathElement = `[${type}.]${name}`;
162
+ if (isFirstPathElementExisting) {
163
+ this.#path[this.#path.length - 1] = pathElement;
220
164
  }
221
165
  else {
222
- throw new TLError(`Expected boolTrue or boolFalse but received ${constructorIdToHex(id)}`, __classPrivateFieldGet(this, _TLReader_path, "f"));
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
- case "string":
226
- return this.readString();
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
+ }