@mtkruto/node 0.1.107 → 0.1.109

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 (83) hide show
  1. package/esm/0_deps.d.ts +1 -1
  2. package/esm/0_deps.js +1 -1
  3. package/esm/4_constants.d.ts +2 -2
  4. package/esm/4_constants.js +3 -3
  5. package/esm/5_client.d.ts +1 -0
  6. package/esm/5_client.js +1 -0
  7. package/esm/client/0_html.js +26 -14
  8. package/esm/client/0_utilities.d.ts +1 -1
  9. package/esm/client/0_utilities.js +1 -2
  10. package/esm/client/1_client_abstract.d.ts +1 -1
  11. package/esm/client/1_client_abstract.js +16 -8
  12. package/esm/client/2_client_plain.d.ts +1 -2
  13. package/esm/client/2_client_plain.js +20 -15
  14. package/esm/client/3_types.d.ts +1 -1
  15. package/esm/client/4_client.d.ts +6 -57
  16. package/esm/client/4_client.js +619 -716
  17. package/esm/connection/1_connection_web_socket.d.ts +1 -9
  18. package/esm/connection/1_connection_web_socket.js +81 -108
  19. package/esm/storage/0_storage.d.ts +3 -2
  20. package/esm/storage/0_storage.js +35 -26
  21. package/esm/storage/0_utilities.d.ts +1 -1
  22. package/esm/storage/0_utilities.js +56 -26
  23. package/esm/storage/1_storage_local_storage.d.ts +1 -1
  24. package/esm/storage/1_storage_session_storage.d.ts +1 -1
  25. package/esm/tl/2_types.d.ts +441 -58
  26. package/esm/tl/2_types.js +1584 -118
  27. package/esm/tl/3_functions.d.ts +113 -16
  28. package/esm/tl/3_functions.js +364 -39
  29. package/esm/transport/1_transport_abridged.d.ts +1 -2
  30. package/esm/transport/1_transport_abridged.js +24 -19
  31. package/esm/transport/1_transport_intermediate.d.ts +1 -2
  32. package/esm/transport/1_transport_intermediate.js +23 -18
  33. package/esm/types/0_color.d.ts +2 -1
  34. package/esm/types/0_color.js +21 -1
  35. package/esm/types/0_message_entity.d.ts +1 -1
  36. package/esm/types/1_chat.js +5 -5
  37. package/esm/types/1_user.js +2 -2
  38. package/esm/types/3_message.js +1 -1
  39. package/esm/utilities/0_base64.js +3 -3
  40. package/esm/utilities/0_queue.d.ts +2 -4
  41. package/esm/utilities/0_queue.js +39 -36
  42. package/package.json +1 -1
  43. package/script/0_deps.d.ts +1 -1
  44. package/script/0_deps.js +3 -3
  45. package/script/4_constants.d.ts +2 -2
  46. package/script/4_constants.js +3 -3
  47. package/script/5_client.d.ts +1 -0
  48. package/script/5_client.js +1 -0
  49. package/script/client/0_html.js +26 -14
  50. package/script/client/0_utilities.d.ts +1 -1
  51. package/script/client/0_utilities.js +1 -2
  52. package/script/client/1_client_abstract.d.ts +1 -1
  53. package/script/client/1_client_abstract.js +16 -8
  54. package/script/client/2_client_plain.d.ts +1 -2
  55. package/script/client/2_client_plain.js +20 -15
  56. package/script/client/3_types.d.ts +1 -1
  57. package/script/client/4_client.d.ts +6 -57
  58. package/script/client/4_client.js +619 -716
  59. package/script/connection/1_connection_web_socket.d.ts +1 -9
  60. package/script/connection/1_connection_web_socket.js +81 -108
  61. package/script/storage/0_storage.d.ts +3 -2
  62. package/script/storage/0_storage.js +35 -26
  63. package/script/storage/0_utilities.d.ts +1 -1
  64. package/script/storage/0_utilities.js +55 -25
  65. package/script/storage/1_storage_local_storage.d.ts +1 -1
  66. package/script/storage/1_storage_session_storage.d.ts +1 -1
  67. package/script/tl/2_types.d.ts +441 -58
  68. package/script/tl/2_types.js +1646 -158
  69. package/script/tl/3_functions.d.ts +113 -16
  70. package/script/tl/3_functions.js +386 -53
  71. package/script/transport/1_transport_abridged.d.ts +1 -2
  72. package/script/transport/1_transport_abridged.js +24 -19
  73. package/script/transport/1_transport_intermediate.d.ts +1 -2
  74. package/script/transport/1_transport_intermediate.js +23 -18
  75. package/script/types/0_color.d.ts +2 -1
  76. package/script/types/0_color.js +24 -3
  77. package/script/types/0_message_entity.d.ts +1 -1
  78. package/script/types/1_chat.js +4 -4
  79. package/script/types/1_user.js +1 -1
  80. package/script/types/3_message.js +1 -1
  81. package/script/utilities/0_base64.js +2 -2
  82. package/script/utilities/0_queue.d.ts +2 -4
  83. package/script/utilities/0_queue.js +39 -36
@@ -1,17 +1,9 @@
1
1
  import { ConnectionUnframed } from "./0_connection.js";
2
2
  export declare class ConnectionWebSocket extends ConnectionUnframed implements ConnectionUnframed {
3
+ #private;
3
4
  private readonly url;
4
- private webSocket;
5
- private rMutex;
6
- private wMutex;
7
- private buffer;
8
- private nextResolve;
9
5
  constructor(url: string | URL);
10
- private initWs;
11
6
  get connected(): boolean;
12
- private wasConnected;
13
- private isConnecting;
14
- private connectionError;
15
7
  open(): Promise<void>;
16
8
  read(p: Uint8Array): Promise<void>;
17
9
  write(p: Uint8Array): Promise<void>;
@@ -22,6 +22,18 @@ var __importStar = (this && this.__importStar) || function (mod) {
22
22
  __setModuleDefault(result, mod);
23
23
  return result;
24
24
  };
25
+ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
26
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
27
+ 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");
28
+ return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
29
+ };
30
+ var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
31
+ if (kind === "m") throw new TypeError("Private method is not writable");
32
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
33
+ 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");
34
+ return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
35
+ };
36
+ var _ConnectionWebSocket_instances, _ConnectionWebSocket_webSocket, _ConnectionWebSocket_rMutex, _ConnectionWebSocket_wMutex, _ConnectionWebSocket_buffer, _ConnectionWebSocket_nextResolve, _ConnectionWebSocket_initWs, _ConnectionWebSocket_wasConnected, _ConnectionWebSocket_isConnecting, _ConnectionWebSocket_connectionError;
25
37
  Object.defineProperty(exports, "__esModule", { value: true });
26
38
  exports.ConnectionWebSocket = void 0;
27
39
  const dntShim = __importStar(require("../_dnt.shims.js"));
@@ -32,113 +44,39 @@ const d = (0, _0_deps_js_1.debug)("ConnectionWebSocket");
32
44
  class ConnectionWebSocket extends _0_connection_js_1.ConnectionUnframed {
33
45
  constructor(url) {
34
46
  super();
47
+ _ConnectionWebSocket_instances.add(this);
35
48
  Object.defineProperty(this, "url", {
36
49
  enumerable: true,
37
50
  configurable: true,
38
51
  writable: true,
39
52
  value: url
40
53
  });
41
- Object.defineProperty(this, "webSocket", {
42
- enumerable: true,
43
- configurable: true,
44
- writable: true,
45
- value: void 0
46
- });
47
- Object.defineProperty(this, "rMutex", {
48
- enumerable: true,
49
- configurable: true,
50
- writable: true,
51
- value: new _0_deps_js_1.Mutex()
52
- });
53
- Object.defineProperty(this, "wMutex", {
54
- enumerable: true,
55
- configurable: true,
56
- writable: true,
57
- value: new _0_deps_js_1.Mutex()
58
- });
59
- Object.defineProperty(this, "buffer", {
60
- enumerable: true,
61
- configurable: true,
62
- writable: true,
63
- value: new Array()
64
- });
65
- Object.defineProperty(this, "nextResolve", {
66
- enumerable: true,
67
- configurable: true,
68
- writable: true,
69
- value: null
70
- });
71
- Object.defineProperty(this, "wasConnected", {
72
- enumerable: true,
73
- configurable: true,
74
- writable: true,
75
- value: false
76
- });
77
- Object.defineProperty(this, "isConnecting", {
78
- enumerable: true,
79
- configurable: true,
80
- writable: true,
81
- value: false
82
- });
83
- Object.defineProperty(this, "connectionError", {
84
- enumerable: true,
85
- configurable: true,
86
- writable: true,
87
- value: null
88
- });
89
- this.webSocket = this.initWs();
90
- }
91
- initWs() {
92
- const webSocket = new dntShim.WebSocket(this.url, "binary");
93
- const mutex = new _0_deps_js_1.Mutex();
94
- webSocket.addEventListener("close", () => {
95
- this.stateChangeHandler?.(false);
96
- });
97
- webSocket.addEventListener("open", () => {
98
- this.stateChangeHandler?.(true);
99
- });
100
- webSocket.addEventListener("message", async (e) => {
101
- if (typeof e.data === "string") {
102
- return;
103
- }
104
- const release = await mutex.acquire();
105
- const data = new Uint8Array(await new Blob([e.data].map((v) => v instanceof Blob || v instanceof Uint8Array ? v : v instanceof ArrayBuffer ? v : (0, _1_utilities_js_1.UNREACHABLE)())).arrayBuffer());
106
- for (const byte of data) {
107
- this.buffer.push(byte);
108
- }
109
- if (this.nextResolve != null && this.buffer.length >= this.nextResolve[0]) {
110
- this.nextResolve[1].resolve();
111
- this.nextResolve = null;
112
- }
113
- release();
114
- });
115
- webSocket.addEventListener("error", (err) => {
116
- if (this.isConnecting) {
117
- // @ts-ignore: Node.js
118
- this.connectionError = err;
119
- }
120
- if (this.connected) {
121
- d("WebSocket error: %o", err);
122
- }
123
- });
124
- return webSocket;
54
+ _ConnectionWebSocket_webSocket.set(this, void 0);
55
+ _ConnectionWebSocket_rMutex.set(this, new _0_deps_js_1.Mutex());
56
+ _ConnectionWebSocket_wMutex.set(this, new _0_deps_js_1.Mutex());
57
+ _ConnectionWebSocket_buffer.set(this, new Array());
58
+ _ConnectionWebSocket_nextResolve.set(this, null);
59
+ _ConnectionWebSocket_wasConnected.set(this, false);
60
+ _ConnectionWebSocket_isConnecting.set(this, false);
61
+ _ConnectionWebSocket_connectionError.set(this, null);
62
+ __classPrivateFieldSet(this, _ConnectionWebSocket_webSocket, __classPrivateFieldGet(this, _ConnectionWebSocket_instances, "m", _ConnectionWebSocket_initWs).call(this), "f");
125
63
  }
126
64
  get connected() {
127
- return this.webSocket.readyState == dntShim.WebSocket.OPEN;
65
+ return __classPrivateFieldGet(this, _ConnectionWebSocket_webSocket, "f").readyState == dntShim.WebSocket.OPEN;
128
66
  }
129
67
  async open() {
130
- if (this.isConnecting) {
68
+ if (__classPrivateFieldGet(this, _ConnectionWebSocket_isConnecting, "f")) {
131
69
  throw new Error("Already connecting");
132
70
  }
133
- this.isConnecting = true;
134
- if (!this.connected && this.wasConnected) {
135
- this.webSocket = this.initWs();
71
+ __classPrivateFieldSet(this, _ConnectionWebSocket_isConnecting, true, "f");
72
+ if (!this.connected && __classPrivateFieldGet(this, _ConnectionWebSocket_wasConnected, "f")) {
73
+ __classPrivateFieldSet(this, _ConnectionWebSocket_webSocket, __classPrivateFieldGet(this, _ConnectionWebSocket_instances, "m", _ConnectionWebSocket_initWs).call(this), "f");
136
74
  }
137
75
  try {
138
- while (this.webSocket.readyState != dntShim.WebSocket.OPEN) {
139
- if (this.webSocket.readyState == dntShim.WebSocket.CLOSED) {
140
- if (this.connectionError instanceof ErrorEvent) {
141
- throw new Error(this.connectionError.message);
76
+ while (__classPrivateFieldGet(this, _ConnectionWebSocket_webSocket, "f").readyState != dntShim.WebSocket.OPEN) {
77
+ if (__classPrivateFieldGet(this, _ConnectionWebSocket_webSocket, "f").readyState == dntShim.WebSocket.CLOSED) {
78
+ if (__classPrivateFieldGet(this, _ConnectionWebSocket_connectionError, "f") instanceof ErrorEvent) {
79
+ throw new Error(__classPrivateFieldGet(this, _ConnectionWebSocket_connectionError, "f").message);
142
80
  }
143
81
  else {
144
82
  throw new Error("Connection was closed");
@@ -148,48 +86,83 @@ class ConnectionWebSocket extends _0_connection_js_1.ConnectionUnframed {
148
86
  await new Promise((r) => setTimeout(r, 5));
149
87
  }
150
88
  }
151
- this.wasConnected = true;
89
+ __classPrivateFieldSet(this, _ConnectionWebSocket_wasConnected, true, "f");
152
90
  }
153
91
  finally {
154
- this.isConnecting = false;
155
- this.connectionError = null;
92
+ __classPrivateFieldSet(this, _ConnectionWebSocket_isConnecting, false, "f");
93
+ __classPrivateFieldSet(this, _ConnectionWebSocket_connectionError, null, "f");
156
94
  }
157
95
  }
158
96
  async read(p) {
159
- if (this.webSocket.readyState != dntShim.WebSocket.OPEN) {
97
+ if (__classPrivateFieldGet(this, _ConnectionWebSocket_webSocket, "f").readyState != dntShim.WebSocket.OPEN) {
160
98
  throw new Error("Connection not open");
161
99
  }
162
- const release = await this.rMutex.acquire();
100
+ const release = await __classPrivateFieldGet(this, _ConnectionWebSocket_rMutex, "f").acquire();
163
101
  try {
164
- if (this.buffer.length < p.length) {
165
- await new Promise((resolve, reject) => this.nextResolve = [p.length, { resolve, reject }]);
102
+ if (__classPrivateFieldGet(this, _ConnectionWebSocket_buffer, "f").length < p.length) {
103
+ await new Promise((resolve, reject) => __classPrivateFieldSet(this, _ConnectionWebSocket_nextResolve, [p.length, { resolve, reject }], "f"));
166
104
  }
167
- p.set(this.buffer.splice(0, p.length));
105
+ p.set(__classPrivateFieldGet(this, _ConnectionWebSocket_buffer, "f").splice(0, p.length));
168
106
  }
169
107
  finally {
170
108
  release();
171
109
  }
172
110
  }
173
111
  async write(p) {
174
- if (this.webSocket.readyState == dntShim.WebSocket.CLOSED) {
112
+ if (__classPrivateFieldGet(this, _ConnectionWebSocket_webSocket, "f").readyState == dntShim.WebSocket.CLOSED) {
175
113
  throw new Error("Connection not open");
176
114
  }
177
- const release = await this.wMutex.acquire();
115
+ const release = await __classPrivateFieldGet(this, _ConnectionWebSocket_wMutex, "f").acquire();
178
116
  try {
179
- this.webSocket.send(p);
117
+ __classPrivateFieldGet(this, _ConnectionWebSocket_webSocket, "f").send(p);
180
118
  }
181
119
  finally {
182
120
  release();
183
121
  }
184
122
  }
185
123
  close() {
186
- if (this.webSocket.readyState == dntShim.WebSocket.CLOSED) {
124
+ if (__classPrivateFieldGet(this, _ConnectionWebSocket_webSocket, "f").readyState == dntShim.WebSocket.CLOSED) {
187
125
  throw new Error("Connection not open");
188
126
  }
189
- this.webSocket.close(1000, "method");
190
- if (this.nextResolve != null) {
191
- this.nextResolve[1].reject(new Error("Connection not open"));
127
+ __classPrivateFieldGet(this, _ConnectionWebSocket_webSocket, "f").close(1000, "method");
128
+ if (__classPrivateFieldGet(this, _ConnectionWebSocket_nextResolve, "f") != null) {
129
+ __classPrivateFieldGet(this, _ConnectionWebSocket_nextResolve, "f")[1].reject(new Error("Connection not open"));
192
130
  }
193
131
  }
194
132
  }
195
133
  exports.ConnectionWebSocket = ConnectionWebSocket;
134
+ _ConnectionWebSocket_webSocket = new WeakMap(), _ConnectionWebSocket_rMutex = new WeakMap(), _ConnectionWebSocket_wMutex = new WeakMap(), _ConnectionWebSocket_buffer = new WeakMap(), _ConnectionWebSocket_nextResolve = new WeakMap(), _ConnectionWebSocket_wasConnected = new WeakMap(), _ConnectionWebSocket_isConnecting = new WeakMap(), _ConnectionWebSocket_connectionError = new WeakMap(), _ConnectionWebSocket_instances = new WeakSet(), _ConnectionWebSocket_initWs = function _ConnectionWebSocket_initWs() {
135
+ const webSocket = new dntShim.WebSocket(this.url, "binary");
136
+ const mutex = new _0_deps_js_1.Mutex();
137
+ webSocket.addEventListener("close", () => {
138
+ this.stateChangeHandler?.(false);
139
+ });
140
+ webSocket.addEventListener("open", () => {
141
+ this.stateChangeHandler?.(true);
142
+ });
143
+ webSocket.addEventListener("message", async (e) => {
144
+ if (typeof e.data === "string") {
145
+ return;
146
+ }
147
+ const release = await mutex.acquire();
148
+ const data = new Uint8Array(await new Blob([e.data].map((v) => v instanceof Blob || v instanceof Uint8Array ? v : v instanceof ArrayBuffer ? v : (0, _1_utilities_js_1.UNREACHABLE)())).arrayBuffer());
149
+ for (const byte of data) {
150
+ __classPrivateFieldGet(this, _ConnectionWebSocket_buffer, "f").push(byte);
151
+ }
152
+ if (__classPrivateFieldGet(this, _ConnectionWebSocket_nextResolve, "f") != null && __classPrivateFieldGet(this, _ConnectionWebSocket_buffer, "f").length >= __classPrivateFieldGet(this, _ConnectionWebSocket_nextResolve, "f")[0]) {
153
+ __classPrivateFieldGet(this, _ConnectionWebSocket_nextResolve, "f")[1].resolve();
154
+ __classPrivateFieldSet(this, _ConnectionWebSocket_nextResolve, null, "f");
155
+ }
156
+ release();
157
+ });
158
+ webSocket.addEventListener("error", (err) => {
159
+ if (__classPrivateFieldGet(this, _ConnectionWebSocket_isConnecting, "f")) {
160
+ // @ts-ignore: Node.js
161
+ __classPrivateFieldSet(this, _ConnectionWebSocket_connectionError, err, "f");
162
+ }
163
+ if (this.connected) {
164
+ d("WebSocket error: %o", err);
165
+ }
166
+ });
167
+ return webSocket;
168
+ };
@@ -3,14 +3,13 @@ import { TLObject, types } from "../2_tl.js";
3
3
  import { DC } from "../3_transport.js";
4
4
  export type StorageKeyPart = string | number | bigint;
5
5
  export declare abstract class Storage {
6
- private _authKeyId;
6
+ #private;
7
7
  abstract init(): MaybePromise<void>;
8
8
  abstract set(key: readonly StorageKeyPart[], value: unknown): MaybePromise<void>;
9
9
  abstract get<T>(key: readonly StorageKeyPart[]): MaybePromise<T | null>;
10
10
  abstract getMany<T>(prefix: readonly StorageKeyPart[]): MaybePromise<Generator<[readonly StorageKeyPart[], T]> | AsyncGenerator<[readonly StorageKeyPart[], T]>>;
11
11
  setDc(dc: DC | null): MaybePromise<void>;
12
12
  getDc(): MaybePromise<DC | null>;
13
- private resetAuthKeyId;
14
13
  getAuthKey(): Promise<Uint8Array | null>;
15
14
  setAuthKey(authKey: Uint8Array | null): Promise<void>;
16
15
  get authKeyId(): bigint | null;
@@ -41,4 +40,6 @@ export declare abstract class Storage {
41
40
  getAccountType(): MaybePromise<"bot" | "user" | null>;
42
41
  updateStickerSetName(id: bigint, accessHash: bigint, name: string): Promise<void>;
43
42
  getStickerSetName(id: bigint, accessHash: bigint): MaybePromise<[string, Date] | null>;
43
+ setServerSalt(serverSalt: bigint): Promise<void>;
44
+ getServerSalt(): MaybePromise<bigint | null>;
44
45
  }
@@ -1,4 +1,16 @@
1
1
  "use strict";
2
+ var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
3
+ if (kind === "m") throw new TypeError("Private method is not writable");
4
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
5
+ 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");
6
+ return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
7
+ };
8
+ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
9
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
10
+ 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");
11
+ return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
12
+ };
13
+ var _Storage_instances, _Storage__authKeyId, _Storage_resetAuthKeyId;
2
14
  Object.defineProperty(exports, "__esModule", { value: true });
3
15
  exports.Storage = void 0;
4
16
  const _1_utilities_js_1 = require("../1_utilities.js");
@@ -18,12 +30,8 @@ const KPARTS_MESSAGE = (chatId, messageId) => ["messages", chatId, messageId];
18
30
  const KPARTS_MESSAGE_REF = (messageId) => ["messageRefs", messageId];
19
31
  class Storage {
20
32
  constructor() {
21
- Object.defineProperty(this, "_authKeyId", {
22
- enumerable: true,
23
- configurable: true,
24
- writable: true,
25
- value: null
26
- });
33
+ _Storage_instances.add(this);
34
+ _Storage__authKeyId.set(this, null);
27
35
  }
28
36
  setDc(dc) {
29
37
  return this.set(KPARTS__DC, dc);
@@ -31,25 +39,17 @@ class Storage {
31
39
  getDc() {
32
40
  return this.get(KPARTS__DC);
33
41
  }
34
- async resetAuthKeyId(authKey) {
35
- if (authKey != null) {
36
- this._authKeyId = await (0, _1_utilities_js_1.sha1)(authKey).then((hash) => (0, _1_utilities_js_1.bigIntFromBuffer)(hash.slice(-8), true, false));
37
- }
38
- else {
39
- this._authKeyId = null;
40
- }
41
- }
42
42
  async getAuthKey() {
43
43
  const authKey = await this.get(KPARTS__AUTH_KEY);
44
- await this.resetAuthKeyId(authKey);
44
+ await __classPrivateFieldGet(this, _Storage_instances, "m", _Storage_resetAuthKeyId).call(this, authKey);
45
45
  return authKey;
46
46
  }
47
47
  async setAuthKey(authKey) {
48
48
  await this.set(KPARTS__AUTH_KEY, authKey);
49
- await this.resetAuthKeyId(authKey);
49
+ await __classPrivateFieldGet(this, _Storage_instances, "m", _Storage_resetAuthKeyId).call(this, authKey);
50
50
  }
51
51
  get authKeyId() {
52
- return this._authKeyId;
52
+ return __classPrivateFieldGet(this, _Storage__authKeyId, "f");
53
53
  }
54
54
  setChannelAccessHash(id, accessHash) {
55
55
  return this.set(KPARTS__CHANNEL_ACCESS_HASH(id), accessHash);
@@ -66,17 +66,12 @@ class Storage {
66
66
  async updateUsernames(type, id, usernames) {
67
67
  for (let username of usernames) {
68
68
  username = username.toLowerCase();
69
- await this.set(KPARTS__USERNAME(username), [type, String(id), new Date()]);
69
+ await this.set(KPARTS__USERNAME(username), [type, id, new Date()]);
70
70
  }
71
71
  }
72
72
  async getUsername(username) {
73
73
  username = username.toLowerCase();
74
- const v = await this.get(KPARTS__USERNAME(username));
75
- if (v != null) {
76
- v[1] = BigInt(v[1]);
77
- v[2] = new Date(v[2]);
78
- }
79
- return v;
74
+ return await this.get(KPARTS__USERNAME(username));
80
75
  }
81
76
  async setTlObject(key, value) {
82
77
  if (value == null) {
@@ -128,12 +123,12 @@ class Storage {
128
123
  }
129
124
  async setEntity(peer) {
130
125
  const type = peer instanceof _2_tl_js_1.types.Channel ? "channel" : peer instanceof _2_tl_js_1.types.Chat ? "chat" : peer instanceof _2_tl_js_1.types.User ? "user" : (0, _1_utilities_js_1.UNREACHABLE)();
131
- await this.set(KPARTS__PEER(type, peer.id), peer[_2_tl_js_1.serialize]());
126
+ await this.set(KPARTS__PEER(type, peer.id), (0, _1_utilities_js_1.rleEncode)(peer[_2_tl_js_1.serialize]()));
132
127
  }
133
128
  async getEntity(type, id) {
134
129
  const peer_ = await this.get(KPARTS__PEER(type, id));
135
130
  if (peer_ != null) {
136
- return new _2_tl_js_1.TLReader(peer_).readObject();
131
+ return new _2_tl_js_1.TLReader((0, _1_utilities_js_1.rleDecode)(peer_)).readObject();
137
132
  }
138
133
  else {
139
134
  return null;
@@ -162,5 +157,19 @@ class Storage {
162
157
  getStickerSetName(id, accessHash) {
163
158
  return this.get(KPARTS__STICKER_SET_NAME(id, accessHash));
164
159
  }
160
+ async setServerSalt(serverSalt) {
161
+ await this.set(["serverSalt"], serverSalt);
162
+ }
163
+ getServerSalt() {
164
+ return this.get(["serverSalt"]);
165
+ }
165
166
  }
166
167
  exports.Storage = Storage;
168
+ _Storage__authKeyId = new WeakMap(), _Storage_instances = new WeakSet(), _Storage_resetAuthKeyId = async function _Storage_resetAuthKeyId(authKey) {
169
+ if (authKey != null) {
170
+ __classPrivateFieldSet(this, _Storage__authKeyId, await (0, _1_utilities_js_1.sha1)(authKey).then((hash) => (0, _1_utilities_js_1.bigIntFromBuffer)(hash.slice(-8), true, false)), "f");
171
+ }
172
+ else {
173
+ __classPrivateFieldSet(this, _Storage__authKeyId, null, "f");
174
+ }
175
+ };
@@ -9,6 +9,6 @@ export declare enum ValueType {
9
9
  Array = 6
10
10
  }
11
11
  export declare function toString(value: unknown): string;
12
- export declare function fromString<T>(string: string): any;
12
+ export declare function fromString<T>(string: string): T;
13
13
  export declare function fixKey(key: readonly StorageKeyPart[]): (string | number)[];
14
14
  export declare function getPrefixKeyRange(prefix: any): IDBKeyRange;
@@ -15,25 +15,34 @@ var ValueType;
15
15
  })(ValueType = exports.ValueType || (exports.ValueType = {}));
16
16
  function toString(value) {
17
17
  if (typeof value === "boolean") {
18
- return JSON.stringify([ValueType.Boolean, value]);
18
+ return `${ValueType.Boolean}${Number(value)}`;
19
19
  }
20
20
  else if (typeof value === "number") {
21
- return JSON.stringify([ValueType.Number, value]);
21
+ return `${ValueType.Number}${value}`;
22
22
  }
23
23
  else if (typeof value === "string") {
24
- return JSON.stringify([ValueType.String, value]);
24
+ return `${ValueType.String}${value}`;
25
25
  }
26
26
  else if (typeof value == "bigint") {
27
- return JSON.stringify([ValueType.BigInt, String(value)]);
27
+ return `${ValueType.BigInt}${value}`;
28
28
  }
29
29
  else if (value instanceof Date) {
30
- return JSON.stringify([ValueType.Date, value.getTime()]);
30
+ return `${ValueType.Date}${value.getTime()}`;
31
31
  }
32
32
  else if (value instanceof Uint8Array) {
33
- return JSON.stringify([ValueType.Uint8Array, (0, _0_deps_js_1.base64Encode)(value)]);
33
+ return `${ValueType.Uint8Array}${(0, _0_deps_js_1.encodeBase64)(value)}`;
34
34
  }
35
35
  else if (Array.isArray(value)) {
36
- return JSON.stringify([ValueType.Array, value.map(toString)]);
36
+ const items = value.map((v) => {
37
+ if (typeof v === "string" || v instanceof Uint8Array || Array.isArray(v)) {
38
+ const s = toString(v).slice(1);
39
+ return String(typeof v === "string" ? ValueType.String : v instanceof Uint8Array ? ValueType.Uint8Array : ValueType.Array) + toString(s.length).slice(1) + "\n" + s;
40
+ }
41
+ else {
42
+ return toString(v);
43
+ }
44
+ });
45
+ return `${ValueType.Array}${items.join("\n")}`;
37
46
  }
38
47
  else {
39
48
  (0, _1_utilities_js_1.UNREACHABLE)();
@@ -41,24 +50,45 @@ function toString(value) {
41
50
  }
42
51
  exports.toString = toString;
43
52
  function fromString(string) {
44
- const [type, value] = JSON.parse(string);
45
- if (type == ValueType.Boolean || type == ValueType.Number || type == ValueType.String) {
46
- return value;
47
- }
48
- else if (type == ValueType.BigInt) {
49
- return BigInt(value);
50
- }
51
- else if (type == ValueType.Date) {
52
- return new Date(value);
53
- }
54
- else if (type == ValueType.Uint8Array) {
55
- return (0, _0_deps_js_1.base64Decode)(value);
56
- }
57
- else if (type == ValueType.Array) {
58
- return value.map(fromString);
59
- }
60
- else {
61
- (0, _1_utilities_js_1.UNREACHABLE)();
53
+ const [type, value] = [Number(string[0]), string.slice(1)];
54
+ switch (type) {
55
+ case ValueType.Boolean:
56
+ return Boolean(Number(value));
57
+ case ValueType.Number:
58
+ return Number(value);
59
+ case ValueType.String:
60
+ return value;
61
+ case ValueType.BigInt:
62
+ return BigInt(value);
63
+ case ValueType.Date:
64
+ return new Date(Number(value));
65
+ case ValueType.Uint8Array:
66
+ return (0, _0_deps_js_1.decodeBase64)(value);
67
+ case ValueType.Array: {
68
+ const arr = [];
69
+ for (let i = 0; i < value.length; ++i) {
70
+ const type = Number(value[i]);
71
+ let value_ = "";
72
+ while (value[++i] != "\n") {
73
+ value_ += value[i];
74
+ if (i == value.length - 1) {
75
+ break;
76
+ }
77
+ }
78
+ switch (type) {
79
+ case ValueType.String:
80
+ case ValueType.Uint8Array:
81
+ case ValueType.Array: {
82
+ const len = Number(value_);
83
+ ++i;
84
+ value_ = value.slice(i, i + Number(value_));
85
+ i += len;
86
+ }
87
+ }
88
+ arr.push(fromString(`${type}${value_}`));
89
+ }
90
+ return arr;
91
+ }
62
92
  }
63
93
  }
64
94
  exports.fromString = fromString;
@@ -4,7 +4,7 @@ export declare class StorageLocalStorage extends Storage implements Storage {
4
4
  private readonly prefix;
5
5
  constructor(prefix: string);
6
6
  init(): void;
7
- get(key_: readonly StorageKeyPart[]): any;
7
+ get<T>(key_: readonly StorageKeyPart[]): T | null;
8
8
  getMany<T>(prefix: readonly StorageKeyPart[]): Generator<[readonly StorageKeyPart[], T], void, unknown>;
9
9
  set(key_: readonly StorageKeyPart[], value: unknown): MaybePromise<void>;
10
10
  }
@@ -4,7 +4,7 @@ export declare class StorageSessionStorage extends Storage implements Storage {
4
4
  private readonly prefix;
5
5
  constructor(prefix: string);
6
6
  init(): void;
7
- get(key_: readonly StorageKeyPart[]): any;
7
+ get<T>(key_: readonly StorageKeyPart[]): T | null;
8
8
  getMany<T>(prefix: readonly StorageKeyPart[]): Generator<[readonly StorageKeyPart[], T], void, unknown>;
9
9
  set(key_: readonly StorageKeyPart[], value: unknown): MaybePromise<void>;
10
10
  }