@mtkruto/node 0.0.957 → 0.0.958

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 (33) hide show
  1. package/esm/client/3_client.d.ts +1 -1
  2. package/esm/client/3_client.js +2 -2
  3. package/esm/constants.d.ts +1 -1
  4. package/esm/constants.js +1 -1
  5. package/esm/storage/0_storage.d.ts +10 -17
  6. package/esm/storage/0_storage.js +40 -133
  7. package/esm/storage/0_utilities.d.ts +13 -0
  8. package/esm/storage/0_utilities.js +62 -0
  9. package/esm/storage/1_storage_indexed_db.d.ts +3 -3
  10. package/esm/storage/1_storage_indexed_db.js +4 -3
  11. package/esm/storage/1_storage_local_storage.d.ts +3 -3
  12. package/esm/storage/1_storage_local_storage.js +13 -6
  13. package/esm/storage/1_storage_memory.d.ts +4 -4
  14. package/esm/storage/1_storage_memory.js +4 -2
  15. package/esm/storage/1_storage_session_storage.d.ts +3 -3
  16. package/esm/storage/1_storage_session_storage.js +13 -6
  17. package/package.json +1 -1
  18. package/script/client/3_client.d.ts +1 -1
  19. package/script/client/3_client.js +2 -2
  20. package/script/constants.d.ts +1 -1
  21. package/script/constants.js +1 -1
  22. package/script/storage/0_storage.d.ts +10 -17
  23. package/script/storage/0_storage.js +40 -133
  24. package/script/storage/0_utilities.d.ts +13 -0
  25. package/script/storage/0_utilities.js +68 -0
  26. package/script/storage/1_storage_indexed_db.d.ts +3 -3
  27. package/script/storage/1_storage_indexed_db.js +4 -3
  28. package/script/storage/1_storage_local_storage.d.ts +3 -3
  29. package/script/storage/1_storage_local_storage.js +13 -6
  30. package/script/storage/1_storage_memory.d.ts +4 -4
  31. package/script/storage/1_storage_memory.js +4 -2
  32. package/script/storage/1_storage_session_storage.d.ts +3 -3
  33. package/script/storage/1_storage_session_storage.js +13 -6
@@ -178,5 +178,5 @@ export declare class Client extends ClientAbstract {
178
178
  download(fileId_: string): Promise<AsyncGenerator<Uint8Array, void, unknown>>;
179
179
  [getStickerSetName](inputStickerSet: types.InputStickerSetID, hash?: number): Promise<string>;
180
180
  forwardMessages(from: number | string, to: number | string, messageIds: number[], params?: ForwardMessagesParams): Promise<Message[]>;
181
- forwardMessage(from: number | string, to: number | string, messageId: number, params?: ForwardMessagesParams): Promise<Message[]>;
181
+ forwardMessage(from: number | string, to: number | string, messageId: number, params?: ForwardMessagesParams): Promise<Message>;
182
182
  }
@@ -1236,7 +1236,7 @@ export class Client extends ClientAbstract {
1236
1236
  }));
1237
1237
  return await this.updatesToMessages(to, result);
1238
1238
  }
1239
- forwardMessage(from, to, messageId, params) {
1240
- return this.forwardMessages(from, to, [messageId], params);
1239
+ async forwardMessage(from, to, messageId, params) {
1240
+ return await this.forwardMessages(from, to, [messageId], params).then((v) => v[0]);
1241
1241
  }
1242
1242
  }
@@ -4,7 +4,7 @@ export declare const publicKeys: Map<bigint, [bigint, bigint]>;
4
4
  export declare const VECTOR_CONSTRUCTOR = 481674261;
5
5
  export declare const DEFAULT_INITIAL_DC: DC;
6
6
  export declare const LAYER = 158;
7
- export declare const DEFAULT_APP_VERSION = "MTKruto 0.0.957";
7
+ export declare const DEFAULT_APP_VERSION = "MTKruto 0.0.958";
8
8
  export declare const DEFAULT_DEVICE_MODEL: string;
9
9
  export declare const DEFAULT_LANG_CODE: string;
10
10
  export declare const DEFAULT_LANG_PACK = "";
package/esm/constants.js CHANGED
@@ -62,7 +62,7 @@ export const publicKeys = new Map([
62
62
  export const VECTOR_CONSTRUCTOR = 0x1CB5C415;
63
63
  export const DEFAULT_INITIAL_DC = "2-test";
64
64
  export const LAYER = 158;
65
- export const DEFAULT_APP_VERSION = "MTKruto 0.0.957";
65
+ export const DEFAULT_APP_VERSION = "MTKruto 0.0.958";
66
66
  // @ts-ignore: lib
67
67
  export const DEFAULT_DEVICE_MODEL = typeof dntShim.Deno === "undefined" ? typeof navigator === "undefined" ? typeof process === "undefined" ? "Unknown" : process.platform + "-" + process.arch : navigator.userAgent.split(" ")[0] : dntShim.Deno.build.os + "-" + dntShim.Deno.build.arch;
68
68
  export const DEFAULT_LANG_CODE = typeof navigator === "undefined" ? "en" : navigator.language.split("-")[0];
@@ -1,33 +1,28 @@
1
1
  import { MaybePromise } from "../utilities/0_types.js";
2
2
  import { DC } from "../transport/2_transport_provider.js";
3
3
  import * as types from "../tl/2_types.js";
4
+ export type StorageKeyPart = string | number | bigint | Uint8Array;
4
5
  export declare abstract class Storage {
5
6
  private _authKeyId;
6
7
  abstract init(): MaybePromise<void>;
7
- abstract set(key: string, value: string | null): MaybePromise<void>;
8
- abstract get(key: string): MaybePromise<string | null>;
8
+ abstract set(key: readonly StorageKeyPart[], value: unknown): MaybePromise<void>;
9
+ abstract get<T>(key: readonly StorageKeyPart[]): MaybePromise<T | null>;
9
10
  setDc(dc: DC | null): MaybePromise<void>;
10
- getDc(): Promise<DC | null>;
11
+ getDc(): MaybePromise<DC | null>;
11
12
  private resetAuthKeyId;
12
13
  getAuthKey(): Promise<Uint8Array | null>;
13
14
  setAuthKey(authKey: Uint8Array | null): Promise<void>;
14
15
  get authKeyId(): bigint | null;
15
- private readonly channelAccessHash__;
16
16
  setChannelAccessHash(id: bigint, accessHash: bigint): MaybePromise<void>;
17
- getChannelAccessHash(id: bigint): Promise<bigint | null>;
18
- private readonly userAccessHash__;
17
+ getChannelAccessHash(id: bigint): MaybePromise<bigint | null>;
19
18
  setUserAccessHash(id: bigint, accessHash: bigint): MaybePromise<void>;
20
- getUserAccessHash(id: bigint): Promise<bigint | null>;
21
- private readonly username__;
19
+ getUserAccessHash(id: bigint): MaybePromise<bigint | null>;
22
20
  updateUsernames(type: "user" | "channel", id: bigint, usernames: string[]): Promise<void>;
23
- getUsername(username: string): Promise<readonly ["channel" | "user", bigint, Date] | null>;
24
- private readonly state__;
21
+ getUsername(username: string): MaybePromise<["channel" | "user", bigint, Date] | null>;
25
22
  setState(state: types.UpdatesState): Promise<void>;
26
23
  getState(): Promise<types.UpdatesState | null>;
27
- private readonly channelPts__;
28
24
  setChannelPts(channelId: bigint, pts: number): Promise<void>;
29
- getChannelPts(channelId: bigint): Promise<number | null>;
30
- private readonly peer__;
25
+ getChannelPts(channelId: bigint): MaybePromise<number | null>;
31
26
  setEntity(peer: types.Channel): Promise<void>;
32
27
  setEntity(peer: types.Chat): Promise<void>;
33
28
  setEntity(peer: types.User): Promise<void>;
@@ -35,10 +30,8 @@ export declare abstract class Storage {
35
30
  getEntity(type: "chat", id: bigint): Promise<types.Chat | null>;
36
31
  getEntity(type: "user", id: bigint): Promise<types.User | null>;
37
32
  getEntity(type: "channel" | "chat" | "user", id: bigint): Promise<types.Channel | types.Chat | types.User | null>;
38
- private readonly accountType__;
39
33
  setAccountType(type: "user" | "bot"): Promise<void>;
40
- getAccountType(): Promise<"bot" | "user">;
41
- private readonly stickerSetName__;
34
+ getAccountType(): MaybePromise<"bot" | "user" | null>;
42
35
  updateStickerSetName(id: bigint, accessHash: bigint, name: string): Promise<void>;
43
- getStickerSetName(id: bigint, accessHash: bigint): Promise<[string, Date] | null>;
36
+ getStickerSetName(id: bigint, accessHash: bigint): MaybePromise<[string, Date] | null>;
44
37
  }
@@ -1,11 +1,19 @@
1
- import { base64Decode, base64Encode } from "../deps.js";
2
1
  import { UNREACHABLE } from "../utilities/0_control.js";
3
2
  import { sha1 } from "../utilities/0_hash.js";
4
3
  import { bigIntFromBuffer } from "../utilities/0_bigint.js";
5
4
  import { serialize } from "../tl/1_tl_object.js";
6
5
  import * as types from "../tl/2_types.js";
7
6
  import { TLReader } from "../tl/3_tl_reader.js";
8
- import { rleDecode, rleEncode } from "../utilities/0_rle.js";
7
+ const KPARTS__DC = ["dc"];
8
+ const KPARTS__AUTH_KEY = ["authKey"];
9
+ const KPARTS__CHANNEL_ACCESS_HASH = (v) => ["channelAccessHash", v];
10
+ const KPARTS__USER_ACCESS_HASH = (v) => ["userAccessHash", v];
11
+ const KPARTS__USERNAME = (v) => ["username", v];
12
+ const KPARTS__STATE = ["state"];
13
+ const KPARTS__CHANNEL_PTS = (v) => ["channelPts", v];
14
+ const KPARTS__PEER = (type, id) => ["peer", type, id];
15
+ const KPARTS__ACCOUNT_TYPE = ["accountType"];
16
+ const KPARTS__STICKER_SET_NAME = (id, accessHash) => ["stickerSetName", id, accessHash];
9
17
  export class Storage {
10
18
  constructor() {
11
19
  Object.defineProperty(this, "_authKeyId", {
@@ -14,60 +22,12 @@ export class Storage {
14
22
  writable: true,
15
23
  value: null
16
24
  });
17
- Object.defineProperty(this, "channelAccessHash__", {
18
- enumerable: true,
19
- configurable: true,
20
- writable: true,
21
- value: "channelAccessHash__"
22
- });
23
- Object.defineProperty(this, "userAccessHash__", {
24
- enumerable: true,
25
- configurable: true,
26
- writable: true,
27
- value: "userAccessHash__"
28
- });
29
- Object.defineProperty(this, "username__", {
30
- enumerable: true,
31
- configurable: true,
32
- writable: true,
33
- value: "username__"
34
- });
35
- Object.defineProperty(this, "state__", {
36
- enumerable: true,
37
- configurable: true,
38
- writable: true,
39
- value: "state__"
40
- });
41
- Object.defineProperty(this, "channelPts__", {
42
- enumerable: true,
43
- configurable: true,
44
- writable: true,
45
- value: "channelPts__"
46
- });
47
- Object.defineProperty(this, "peer__", {
48
- enumerable: true,
49
- configurable: true,
50
- writable: true,
51
- value: "peer__"
52
- });
53
- Object.defineProperty(this, "accountType__", {
54
- enumerable: true,
55
- configurable: true,
56
- writable: true,
57
- value: "accountType__"
58
- });
59
- Object.defineProperty(this, "stickerSetName__", {
60
- enumerable: true,
61
- configurable: true,
62
- writable: true,
63
- value: "stickerSetName__"
64
- });
65
25
  }
66
26
  setDc(dc) {
67
- return this.set("dc", dc);
27
+ return this.set(KPARTS__DC, dc);
68
28
  }
69
- async getDc() {
70
- return await this.get("dc");
29
+ getDc() {
30
+ return this.get(KPARTS__DC);
71
31
  }
72
32
  async resetAuthKeyId(authKey) {
73
33
  if (authKey != null) {
@@ -78,105 +38,65 @@ export class Storage {
78
38
  }
79
39
  }
80
40
  async getAuthKey() {
81
- const authKey_ = await this.get("authKey");
82
- const authKey = authKey_ == null ? null : new Uint8Array(authKey_.split(/([0-9a-f]{2})/).filter((v) => v).map((v) => parseInt(v, 16)));
41
+ const authKey = await this.get(KPARTS__AUTH_KEY);
83
42
  await this.resetAuthKeyId(authKey);
84
43
  return authKey;
85
44
  }
86
45
  async setAuthKey(authKey) {
87
- await this.set("authKey", authKey == null ? null : Array.from(authKey).map((v) => v.toString(16)).map((v) => v.padStart(2, "0")).join(""));
46
+ await this.set(KPARTS__AUTH_KEY, authKey);
88
47
  await this.resetAuthKeyId(authKey);
89
48
  }
90
49
  get authKeyId() {
91
50
  return this._authKeyId;
92
51
  }
93
52
  setChannelAccessHash(id, accessHash) {
94
- return this.set(`${this.channelAccessHash__}${id}`, String(accessHash));
53
+ return this.set(KPARTS__CHANNEL_ACCESS_HASH(id), accessHash);
95
54
  }
96
- async getChannelAccessHash(id) {
97
- const accessHash = await this.get(`${this.channelAccessHash__}${id}`);
98
- if (accessHash != null) {
99
- return BigInt(accessHash);
100
- }
101
- else {
102
- return null;
103
- }
55
+ getChannelAccessHash(id) {
56
+ return this.get(KPARTS__CHANNEL_ACCESS_HASH(id));
104
57
  }
105
58
  setUserAccessHash(id, accessHash) {
106
- return this.set(`${this.userAccessHash__}${id}`, String(accessHash));
59
+ return this.set(KPARTS__USER_ACCESS_HASH(id), accessHash);
107
60
  }
108
- async getUserAccessHash(id) {
109
- const accessHash = await this.get(`${this.userAccessHash__}${id}`);
110
- if (accessHash != null) {
111
- return BigInt(accessHash);
112
- }
113
- else {
114
- return null;
115
- }
61
+ getUserAccessHash(id) {
62
+ return this.get(KPARTS__USER_ACCESS_HASH(id));
116
63
  }
117
64
  async updateUsernames(type, id, usernames) {
118
65
  for (let username of usernames) {
119
66
  username = username.toLowerCase();
120
- await this.set(`${this.username__}${username}`, JSON.stringify([type, String(id), new Date()]));
67
+ await this.set(KPARTS__USERNAME(username), [type, String(id), new Date()]);
121
68
  }
122
69
  }
123
- async getUsername(username) {
70
+ getUsername(username) {
124
71
  username = username.toLowerCase();
125
- const username_ = await this.get(`${this.username__}${username}`);
126
- if (username_ != null) {
127
- const [type, id, updatedAt] = JSON.parse(username_);
128
- return [type, BigInt(id), new Date(updatedAt)];
129
- }
130
- else {
131
- return null;
132
- }
72
+ return this.get(KPARTS__USERNAME(username));
133
73
  }
134
74
  async setState(state) {
135
- await this.set(this.state__, JSON.stringify({
136
- date: state.date,
137
- pts: state.pts,
138
- qts: state.qts,
139
- seq: state.seq,
140
- unreadCount: state.unreadCount,
141
- }));
75
+ await this.set(KPARTS__STATE, state[serialize]());
142
76
  }
143
77
  async getState() {
144
- const state__ = await this.get(this.state__);
145
- if (state__ != null) {
146
- const state_ = JSON.parse(state__);
147
- return new types.UpdatesState({
148
- date: state_.date,
149
- pts: state_.pts,
150
- qts: state_.qts,
151
- seq: state_.seq,
152
- unreadCount: state_.unreadCount,
153
- });
78
+ const state = await this.get(KPARTS__STATE);
79
+ if (state != null) {
80
+ return new TLReader(state).readObject();
154
81
  }
155
82
  else {
156
83
  return null;
157
84
  }
158
85
  }
159
86
  async setChannelPts(channelId, pts) {
160
- await this.set(`${this.channelPts__}${channelId}`, String(pts));
87
+ await this.set(KPARTS__CHANNEL_PTS(channelId), pts);
161
88
  }
162
- async getChannelPts(channelId) {
163
- const pts = await this.get(`${this.channelPts__}${channelId}`);
164
- if (pts != null) {
165
- return Number(pts);
166
- }
167
- else {
168
- return null;
169
- }
89
+ getChannelPts(channelId) {
90
+ return this.get(KPARTS__CHANNEL_PTS(channelId));
170
91
  }
171
92
  async setEntity(peer) {
172
93
  const type = peer instanceof types.Channel ? "channel" : peer instanceof types.Chat ? "chat" : peer instanceof types.User ? "user" : UNREACHABLE();
173
- await this.set(`${this.peer__}${type}${peer.id}`, base64Encode(rleEncode(peer[serialize]())));
94
+ await this.set(KPARTS__PEER(type, peer.id), peer[serialize]());
174
95
  }
175
96
  async getEntity(type, id) {
176
- const peer_ = await this.get(`${this.peer__}${type}${id}`);
97
+ const peer_ = await this.get(KPARTS__PEER(type, id));
177
98
  if (peer_ != null) {
178
- const reader = new TLReader(rleDecode(base64Decode(peer_)));
179
- return reader.readObject();
99
+ return new TLReader(peer_).readObject();
180
100
  }
181
101
  else {
182
102
  return null;
@@ -192,30 +112,17 @@ export class Storage {
192
112
  throw err;
193
113
  }
194
114
  else {
195
- await this.set(this.accountType__, type);
115
+ await this.set(KPARTS__ACCOUNT_TYPE, type);
196
116
  }
197
117
  }
198
118
  }
199
- async getAccountType() {
200
- const accountType = await this.get(this.accountType__);
201
- if (accountType != null) {
202
- return accountType;
203
- }
204
- else {
205
- UNREACHABLE();
206
- }
119
+ getAccountType() {
120
+ return this.get(KPARTS__ACCOUNT_TYPE);
207
121
  }
208
122
  async updateStickerSetName(id, accessHash, name) {
209
- await this.set(`${this.stickerSetName__}${id}${accessHash}`, JSON.stringify([name, new Date()]));
123
+ await this.set(KPARTS__STICKER_SET_NAME(id, accessHash), [name, new Date()]);
210
124
  }
211
- async getStickerSetName(id, accessHash) {
212
- const stickerSetName_ = await this.get(`${this.stickerSetName__}${id}${accessHash}`);
213
- if (stickerSetName_ != null) {
214
- const [name, updatedAt] = JSON.parse(stickerSetName_);
215
- return [name, new Date(updatedAt)];
216
- }
217
- else {
218
- return null;
219
- }
125
+ getStickerSetName(id, accessHash) {
126
+ return this.get(KPARTS__STICKER_SET_NAME(id, accessHash));
220
127
  }
221
128
  }
@@ -0,0 +1,13 @@
1
+ import { StorageKeyPart } from "./0_storage.js";
2
+ export declare enum ValueType {
3
+ Boolean = 0,
4
+ Number = 1,
5
+ String = 2,
6
+ BigInt = 3,
7
+ Date = 4,
8
+ Uint8Array = 5,
9
+ Array = 6
10
+ }
11
+ export declare function toString(value: unknown): string;
12
+ export declare function fromString<T>(string: string): any;
13
+ export declare function fixKey(key: StorageKeyPart[]): (string | number | Uint8Array)[];
@@ -0,0 +1,62 @@
1
+ import { base64Decode, base64Encode } from "../deps.js";
2
+ import { UNREACHABLE } from "../utilities/0_control.js";
3
+ export var ValueType;
4
+ (function (ValueType) {
5
+ ValueType[ValueType["Boolean"] = 0] = "Boolean";
6
+ ValueType[ValueType["Number"] = 1] = "Number";
7
+ ValueType[ValueType["String"] = 2] = "String";
8
+ ValueType[ValueType["BigInt"] = 3] = "BigInt";
9
+ ValueType[ValueType["Date"] = 4] = "Date";
10
+ ValueType[ValueType["Uint8Array"] = 5] = "Uint8Array";
11
+ ValueType[ValueType["Array"] = 6] = "Array";
12
+ })(ValueType || (ValueType = {}));
13
+ export function toString(value) {
14
+ if (typeof value === "boolean") {
15
+ return JSON.stringify([ValueType.Boolean, value]);
16
+ }
17
+ else if (typeof value === "number") {
18
+ return JSON.stringify([ValueType.Number, value]);
19
+ }
20
+ else if (typeof value === "string") {
21
+ return JSON.stringify([ValueType.String, value]);
22
+ }
23
+ else if (typeof value == "bigint") {
24
+ return JSON.stringify([ValueType.BigInt, String(value)]);
25
+ }
26
+ else if (value instanceof Date) {
27
+ return JSON.stringify([ValueType.Date, value.getTime()]);
28
+ }
29
+ else if (value instanceof Uint8Array) {
30
+ return JSON.stringify([ValueType.Uint8Array, base64Encode(value)]);
31
+ }
32
+ else if (Array.isArray(value)) {
33
+ return JSON.stringify([ValueType.Array, value.map(toString)]);
34
+ }
35
+ else {
36
+ UNREACHABLE();
37
+ }
38
+ }
39
+ export function fromString(string) {
40
+ const [type, value] = JSON.parse(string);
41
+ if (type == ValueType.Boolean || type == ValueType.Number || type == ValueType.String) {
42
+ return value;
43
+ }
44
+ else if (type == ValueType.BigInt) {
45
+ return BigInt(value);
46
+ }
47
+ else if (type == ValueType.Date) {
48
+ return new Date(value);
49
+ }
50
+ else if (type == ValueType.Uint8Array) {
51
+ return base64Decode(value);
52
+ }
53
+ else if (type == ValueType.Array) {
54
+ return value.map(fromString);
55
+ }
56
+ else {
57
+ UNREACHABLE();
58
+ }
59
+ }
60
+ export function fixKey(key) {
61
+ return key.map((v) => typeof v === "bigint" ? String(v) : v);
62
+ }
@@ -1,9 +1,9 @@
1
- import { Storage } from "./0_storage.js";
1
+ import { Storage, StorageKeyPart } from "./0_storage.js";
2
2
  export declare class StorageIndexedDB extends Storage {
3
3
  readonly name: string;
4
4
  database: IDBDatabase | null;
5
5
  constructor(name: string);
6
6
  init(): Promise<void>;
7
- set(k: string, v: string | null): Promise<void>;
8
- get(k: string): Promise<string | null>;
7
+ set(k: StorageKeyPart[], v: unknown): Promise<void>;
8
+ get<T>(k: StorageKeyPart[]): Promise<T | null>;
9
9
  }
@@ -1,4 +1,5 @@
1
1
  import { Storage } from "./0_storage.js";
2
+ import { fixKey } from "./0_utilities.js";
2
3
  const VERSION = 1;
3
4
  const KV_OBJECT_STORE = "kv";
4
5
  export class StorageIndexedDB extends Storage {
@@ -44,10 +45,10 @@ export class StorageIndexedDB extends Storage {
44
45
  // deno-lint-ignore no-explicit-any
45
46
  let tx;
46
47
  if (v == null) {
47
- tx = store.delete(k);
48
+ tx = store.delete(fixKey(k));
48
49
  }
49
50
  else {
50
- tx = store.put(v, k);
51
+ tx = store.put(v, fixKey(k));
51
52
  }
52
53
  return new Promise((res, rej) => {
53
54
  tx.onerror = rej;
@@ -63,7 +64,7 @@ export class StorageIndexedDB extends Storage {
63
64
  const tx = this.database
64
65
  .transaction(KV_OBJECT_STORE, "readonly")
65
66
  .objectStore(KV_OBJECT_STORE)
66
- .get(k);
67
+ .get(fixKey(k));
67
68
  return new Promise((res, rej) => {
68
69
  tx.onerror = rej;
69
70
  tx.onsuccess = () => {
@@ -1,9 +1,9 @@
1
1
  import { MaybePromise } from "../utilities/0_types.js";
2
- import { Storage } from "./0_storage.js";
2
+ import { Storage, StorageKeyPart } from "./0_storage.js";
3
3
  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: string): string | null;
8
- set(key: string, value: string | null): MaybePromise<void>;
7
+ get(key_: readonly StorageKeyPart[]): any;
8
+ set(key_: readonly StorageKeyPart[], value: unknown): MaybePromise<void>;
9
9
  }
@@ -1,4 +1,5 @@
1
1
  import { Storage } from "./0_storage.js";
2
+ import { fromString, toString } from "./0_utilities.js";
2
3
  export class StorageLocalStorage extends Storage {
3
4
  constructor(prefix) {
4
5
  if (typeof localStorage === "undefined") {
@@ -20,14 +21,20 @@ export class StorageLocalStorage extends Storage {
20
21
  }
21
22
  init() {
22
23
  }
23
- get(key) {
24
- key = this.prefix + key;
25
- return localStorage.getItem(key);
24
+ get(key_) {
25
+ const key = this.prefix + toString(key_);
26
+ const value = localStorage.getItem(key);
27
+ if (value != null) {
28
+ return fromString(value);
29
+ }
30
+ else {
31
+ return null;
32
+ }
26
33
  }
27
- set(key, value) {
28
- key = this.prefix + key;
34
+ set(key_, value) {
35
+ const key = this.prefix + toString(key_);
29
36
  if (value != null) {
30
- localStorage.setItem(key, value);
37
+ localStorage.setItem(key, toString(value));
31
38
  }
32
39
  else {
33
40
  localStorage.removeItem(key);
@@ -1,8 +1,8 @@
1
1
  import { MaybePromise } from "../utilities/0_types.js";
2
- import { Storage } from "./0_storage.js";
2
+ import { Storage, StorageKeyPart } from "./0_storage.js";
3
3
  export declare class StorageMemory extends Storage implements Storage {
4
- protected map: Map<string, string>;
4
+ protected map: Map<string, unknown>;
5
5
  init(): void;
6
- get(key: string): string | null;
7
- set(key: string, value: string | null): MaybePromise<void>;
6
+ get<T>(key: readonly StorageKeyPart[]): NonNullable<T> | null;
7
+ set(key_: readonly StorageKeyPart[], value: unknown): MaybePromise<void>;
8
8
  }
@@ -1,4 +1,5 @@
1
1
  import { Storage } from "./0_storage.js";
2
+ import { toString } from "./0_utilities.js";
2
3
  export class StorageMemory extends Storage {
3
4
  constructor() {
4
5
  super(...arguments);
@@ -12,9 +13,10 @@ export class StorageMemory extends Storage {
12
13
  init() {
13
14
  }
14
15
  get(key) {
15
- return this.map.get(key) ?? null;
16
+ return this.map.get(toString(key)) ?? null;
16
17
  }
17
- set(key, value) {
18
+ set(key_, value) {
19
+ const key = toString(key_);
18
20
  if (value != null) {
19
21
  this.map.set(key, value);
20
22
  }
@@ -1,9 +1,9 @@
1
1
  import { MaybePromise } from "../utilities/0_types.js";
2
- import { Storage } from "./0_storage.js";
2
+ import { Storage, StorageKeyPart } from "./0_storage.js";
3
3
  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: string): string | null;
8
- set(key: string, value: string | null): MaybePromise<void>;
7
+ get(key_: readonly StorageKeyPart[]): any;
8
+ set(key_: readonly StorageKeyPart[], value: unknown): MaybePromise<void>;
9
9
  }
@@ -1,4 +1,5 @@
1
1
  import { Storage } from "./0_storage.js";
2
+ import { fromString, toString } from "./0_utilities.js";
2
3
  export class StorageSessionStorage extends Storage {
3
4
  constructor(prefix) {
4
5
  if (typeof sessionStorage === "undefined") {
@@ -20,14 +21,20 @@ export class StorageSessionStorage extends Storage {
20
21
  }
21
22
  init() {
22
23
  }
23
- get(key) {
24
- key = this.prefix + key;
25
- return sessionStorage.getItem(key);
24
+ get(key_) {
25
+ const key = this.prefix + toString(key_);
26
+ const value = sessionStorage.getItem(key);
27
+ if (value != null) {
28
+ return fromString(value);
29
+ }
30
+ else {
31
+ return null;
32
+ }
26
33
  }
27
- set(key, value) {
28
- key = this.prefix + key;
34
+ set(key_, value) {
35
+ const key = this.prefix + toString(key_);
29
36
  if (value != null) {
30
- sessionStorage.setItem(key, value);
37
+ sessionStorage.setItem(key, toString(value));
31
38
  }
32
39
  else {
33
40
  sessionStorage.removeItem(key);
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "module": "./esm/mod.js",
3
3
  "main": "./script/mod.js",
4
4
  "name": "@mtkruto/node",
5
- "version": "0.0.957",
5
+ "version": "0.0.958",
6
6
  "description": "MTKruto for Node.js",
7
7
  "author": "Roj <rojvv@icloud.com>",
8
8
  "license": "LGPL-3.0-or-later",
@@ -178,5 +178,5 @@ export declare class Client extends ClientAbstract {
178
178
  download(fileId_: string): Promise<AsyncGenerator<Uint8Array, void, unknown>>;
179
179
  [getStickerSetName](inputStickerSet: types.InputStickerSetID, hash?: number): Promise<string>;
180
180
  forwardMessages(from: number | string, to: number | string, messageIds: number[], params?: ForwardMessagesParams): Promise<Message[]>;
181
- forwardMessage(from: number | string, to: number | string, messageId: number, params?: ForwardMessagesParams): Promise<Message[]>;
181
+ forwardMessage(from: number | string, to: number | string, messageId: number, params?: ForwardMessagesParams): Promise<Message>;
182
182
  }
@@ -1262,8 +1262,8 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
1262
1262
  }));
1263
1263
  return await this.updatesToMessages(to, result);
1264
1264
  }
1265
- forwardMessage(from, to, messageId, params) {
1266
- return this.forwardMessages(from, to, [messageId], params);
1265
+ async forwardMessage(from, to, messageId, params) {
1266
+ return await this.forwardMessages(from, to, [messageId], params).then((v) => v[0]);
1267
1267
  }
1268
1268
  }
1269
1269
  exports.Client = Client;
@@ -4,7 +4,7 @@ export declare const publicKeys: Map<bigint, [bigint, bigint]>;
4
4
  export declare const VECTOR_CONSTRUCTOR = 481674261;
5
5
  export declare const DEFAULT_INITIAL_DC: DC;
6
6
  export declare const LAYER = 158;
7
- export declare const DEFAULT_APP_VERSION = "MTKruto 0.0.957";
7
+ export declare const DEFAULT_APP_VERSION = "MTKruto 0.0.958";
8
8
  export declare const DEFAULT_DEVICE_MODEL: string;
9
9
  export declare const DEFAULT_LANG_CODE: string;
10
10
  export declare const DEFAULT_LANG_PACK = "";
@@ -88,7 +88,7 @@ exports.publicKeys = new Map([
88
88
  exports.VECTOR_CONSTRUCTOR = 0x1CB5C415;
89
89
  exports.DEFAULT_INITIAL_DC = "2-test";
90
90
  exports.LAYER = 158;
91
- exports.DEFAULT_APP_VERSION = "MTKruto 0.0.957";
91
+ exports.DEFAULT_APP_VERSION = "MTKruto 0.0.958";
92
92
  // @ts-ignore: lib
93
93
  exports.DEFAULT_DEVICE_MODEL = typeof dntShim.Deno === "undefined" ? typeof navigator === "undefined" ? typeof process === "undefined" ? "Unknown" : process.platform + "-" + process.arch : navigator.userAgent.split(" ")[0] : dntShim.Deno.build.os + "-" + dntShim.Deno.build.arch;
94
94
  exports.DEFAULT_LANG_CODE = typeof navigator === "undefined" ? "en" : navigator.language.split("-")[0];
@@ -1,33 +1,28 @@
1
1
  import { MaybePromise } from "../utilities/0_types.js";
2
2
  import { DC } from "../transport/2_transport_provider.js";
3
3
  import * as types from "../tl/2_types.js";
4
+ export type StorageKeyPart = string | number | bigint | Uint8Array;
4
5
  export declare abstract class Storage {
5
6
  private _authKeyId;
6
7
  abstract init(): MaybePromise<void>;
7
- abstract set(key: string, value: string | null): MaybePromise<void>;
8
- abstract get(key: string): MaybePromise<string | null>;
8
+ abstract set(key: readonly StorageKeyPart[], value: unknown): MaybePromise<void>;
9
+ abstract get<T>(key: readonly StorageKeyPart[]): MaybePromise<T | null>;
9
10
  setDc(dc: DC | null): MaybePromise<void>;
10
- getDc(): Promise<DC | null>;
11
+ getDc(): MaybePromise<DC | null>;
11
12
  private resetAuthKeyId;
12
13
  getAuthKey(): Promise<Uint8Array | null>;
13
14
  setAuthKey(authKey: Uint8Array | null): Promise<void>;
14
15
  get authKeyId(): bigint | null;
15
- private readonly channelAccessHash__;
16
16
  setChannelAccessHash(id: bigint, accessHash: bigint): MaybePromise<void>;
17
- getChannelAccessHash(id: bigint): Promise<bigint | null>;
18
- private readonly userAccessHash__;
17
+ getChannelAccessHash(id: bigint): MaybePromise<bigint | null>;
19
18
  setUserAccessHash(id: bigint, accessHash: bigint): MaybePromise<void>;
20
- getUserAccessHash(id: bigint): Promise<bigint | null>;
21
- private readonly username__;
19
+ getUserAccessHash(id: bigint): MaybePromise<bigint | null>;
22
20
  updateUsernames(type: "user" | "channel", id: bigint, usernames: string[]): Promise<void>;
23
- getUsername(username: string): Promise<readonly ["channel" | "user", bigint, Date] | null>;
24
- private readonly state__;
21
+ getUsername(username: string): MaybePromise<["channel" | "user", bigint, Date] | null>;
25
22
  setState(state: types.UpdatesState): Promise<void>;
26
23
  getState(): Promise<types.UpdatesState | null>;
27
- private readonly channelPts__;
28
24
  setChannelPts(channelId: bigint, pts: number): Promise<void>;
29
- getChannelPts(channelId: bigint): Promise<number | null>;
30
- private readonly peer__;
25
+ getChannelPts(channelId: bigint): MaybePromise<number | null>;
31
26
  setEntity(peer: types.Channel): Promise<void>;
32
27
  setEntity(peer: types.Chat): Promise<void>;
33
28
  setEntity(peer: types.User): Promise<void>;
@@ -35,10 +30,8 @@ export declare abstract class Storage {
35
30
  getEntity(type: "chat", id: bigint): Promise<types.Chat | null>;
36
31
  getEntity(type: "user", id: bigint): Promise<types.User | null>;
37
32
  getEntity(type: "channel" | "chat" | "user", id: bigint): Promise<types.Channel | types.Chat | types.User | null>;
38
- private readonly accountType__;
39
33
  setAccountType(type: "user" | "bot"): Promise<void>;
40
- getAccountType(): Promise<"bot" | "user">;
41
- private readonly stickerSetName__;
34
+ getAccountType(): MaybePromise<"bot" | "user" | null>;
42
35
  updateStickerSetName(id: bigint, accessHash: bigint, name: string): Promise<void>;
43
- getStickerSetName(id: bigint, accessHash: bigint): Promise<[string, Date] | null>;
36
+ getStickerSetName(id: bigint, accessHash: bigint): MaybePromise<[string, Date] | null>;
44
37
  }
@@ -24,14 +24,22 @@ var __importStar = (this && this.__importStar) || function (mod) {
24
24
  };
25
25
  Object.defineProperty(exports, "__esModule", { value: true });
26
26
  exports.Storage = void 0;
27
- const deps_js_1 = require("../deps.js");
28
27
  const _0_control_js_1 = require("../utilities/0_control.js");
29
28
  const _0_hash_js_1 = require("../utilities/0_hash.js");
30
29
  const _0_bigint_js_1 = require("../utilities/0_bigint.js");
31
30
  const _1_tl_object_js_1 = require("../tl/1_tl_object.js");
32
31
  const types = __importStar(require("../tl/2_types.js"));
33
32
  const _3_tl_reader_js_1 = require("../tl/3_tl_reader.js");
34
- const _0_rle_js_1 = require("../utilities/0_rle.js");
33
+ const KPARTS__DC = ["dc"];
34
+ const KPARTS__AUTH_KEY = ["authKey"];
35
+ const KPARTS__CHANNEL_ACCESS_HASH = (v) => ["channelAccessHash", v];
36
+ const KPARTS__USER_ACCESS_HASH = (v) => ["userAccessHash", v];
37
+ const KPARTS__USERNAME = (v) => ["username", v];
38
+ const KPARTS__STATE = ["state"];
39
+ const KPARTS__CHANNEL_PTS = (v) => ["channelPts", v];
40
+ const KPARTS__PEER = (type, id) => ["peer", type, id];
41
+ const KPARTS__ACCOUNT_TYPE = ["accountType"];
42
+ const KPARTS__STICKER_SET_NAME = (id, accessHash) => ["stickerSetName", id, accessHash];
35
43
  class Storage {
36
44
  constructor() {
37
45
  Object.defineProperty(this, "_authKeyId", {
@@ -40,60 +48,12 @@ class Storage {
40
48
  writable: true,
41
49
  value: null
42
50
  });
43
- Object.defineProperty(this, "channelAccessHash__", {
44
- enumerable: true,
45
- configurable: true,
46
- writable: true,
47
- value: "channelAccessHash__"
48
- });
49
- Object.defineProperty(this, "userAccessHash__", {
50
- enumerable: true,
51
- configurable: true,
52
- writable: true,
53
- value: "userAccessHash__"
54
- });
55
- Object.defineProperty(this, "username__", {
56
- enumerable: true,
57
- configurable: true,
58
- writable: true,
59
- value: "username__"
60
- });
61
- Object.defineProperty(this, "state__", {
62
- enumerable: true,
63
- configurable: true,
64
- writable: true,
65
- value: "state__"
66
- });
67
- Object.defineProperty(this, "channelPts__", {
68
- enumerable: true,
69
- configurable: true,
70
- writable: true,
71
- value: "channelPts__"
72
- });
73
- Object.defineProperty(this, "peer__", {
74
- enumerable: true,
75
- configurable: true,
76
- writable: true,
77
- value: "peer__"
78
- });
79
- Object.defineProperty(this, "accountType__", {
80
- enumerable: true,
81
- configurable: true,
82
- writable: true,
83
- value: "accountType__"
84
- });
85
- Object.defineProperty(this, "stickerSetName__", {
86
- enumerable: true,
87
- configurable: true,
88
- writable: true,
89
- value: "stickerSetName__"
90
- });
91
51
  }
92
52
  setDc(dc) {
93
- return this.set("dc", dc);
53
+ return this.set(KPARTS__DC, dc);
94
54
  }
95
- async getDc() {
96
- return await this.get("dc");
55
+ getDc() {
56
+ return this.get(KPARTS__DC);
97
57
  }
98
58
  async resetAuthKeyId(authKey) {
99
59
  if (authKey != null) {
@@ -104,105 +64,65 @@ class Storage {
104
64
  }
105
65
  }
106
66
  async getAuthKey() {
107
- const authKey_ = await this.get("authKey");
108
- const authKey = authKey_ == null ? null : new Uint8Array(authKey_.split(/([0-9a-f]{2})/).filter((v) => v).map((v) => parseInt(v, 16)));
67
+ const authKey = await this.get(KPARTS__AUTH_KEY);
109
68
  await this.resetAuthKeyId(authKey);
110
69
  return authKey;
111
70
  }
112
71
  async setAuthKey(authKey) {
113
- await this.set("authKey", authKey == null ? null : Array.from(authKey).map((v) => v.toString(16)).map((v) => v.padStart(2, "0")).join(""));
72
+ await this.set(KPARTS__AUTH_KEY, authKey);
114
73
  await this.resetAuthKeyId(authKey);
115
74
  }
116
75
  get authKeyId() {
117
76
  return this._authKeyId;
118
77
  }
119
78
  setChannelAccessHash(id, accessHash) {
120
- return this.set(`${this.channelAccessHash__}${id}`, String(accessHash));
79
+ return this.set(KPARTS__CHANNEL_ACCESS_HASH(id), accessHash);
121
80
  }
122
- async getChannelAccessHash(id) {
123
- const accessHash = await this.get(`${this.channelAccessHash__}${id}`);
124
- if (accessHash != null) {
125
- return BigInt(accessHash);
126
- }
127
- else {
128
- return null;
129
- }
81
+ getChannelAccessHash(id) {
82
+ return this.get(KPARTS__CHANNEL_ACCESS_HASH(id));
130
83
  }
131
84
  setUserAccessHash(id, accessHash) {
132
- return this.set(`${this.userAccessHash__}${id}`, String(accessHash));
85
+ return this.set(KPARTS__USER_ACCESS_HASH(id), accessHash);
133
86
  }
134
- async getUserAccessHash(id) {
135
- const accessHash = await this.get(`${this.userAccessHash__}${id}`);
136
- if (accessHash != null) {
137
- return BigInt(accessHash);
138
- }
139
- else {
140
- return null;
141
- }
87
+ getUserAccessHash(id) {
88
+ return this.get(KPARTS__USER_ACCESS_HASH(id));
142
89
  }
143
90
  async updateUsernames(type, id, usernames) {
144
91
  for (let username of usernames) {
145
92
  username = username.toLowerCase();
146
- await this.set(`${this.username__}${username}`, JSON.stringify([type, String(id), new Date()]));
93
+ await this.set(KPARTS__USERNAME(username), [type, String(id), new Date()]);
147
94
  }
148
95
  }
149
- async getUsername(username) {
96
+ getUsername(username) {
150
97
  username = username.toLowerCase();
151
- const username_ = await this.get(`${this.username__}${username}`);
152
- if (username_ != null) {
153
- const [type, id, updatedAt] = JSON.parse(username_);
154
- return [type, BigInt(id), new Date(updatedAt)];
155
- }
156
- else {
157
- return null;
158
- }
98
+ return this.get(KPARTS__USERNAME(username));
159
99
  }
160
100
  async setState(state) {
161
- await this.set(this.state__, JSON.stringify({
162
- date: state.date,
163
- pts: state.pts,
164
- qts: state.qts,
165
- seq: state.seq,
166
- unreadCount: state.unreadCount,
167
- }));
101
+ await this.set(KPARTS__STATE, state[_1_tl_object_js_1.serialize]());
168
102
  }
169
103
  async getState() {
170
- const state__ = await this.get(this.state__);
171
- if (state__ != null) {
172
- const state_ = JSON.parse(state__);
173
- return new types.UpdatesState({
174
- date: state_.date,
175
- pts: state_.pts,
176
- qts: state_.qts,
177
- seq: state_.seq,
178
- unreadCount: state_.unreadCount,
179
- });
104
+ const state = await this.get(KPARTS__STATE);
105
+ if (state != null) {
106
+ return new _3_tl_reader_js_1.TLReader(state).readObject();
180
107
  }
181
108
  else {
182
109
  return null;
183
110
  }
184
111
  }
185
112
  async setChannelPts(channelId, pts) {
186
- await this.set(`${this.channelPts__}${channelId}`, String(pts));
113
+ await this.set(KPARTS__CHANNEL_PTS(channelId), pts);
187
114
  }
188
- async getChannelPts(channelId) {
189
- const pts = await this.get(`${this.channelPts__}${channelId}`);
190
- if (pts != null) {
191
- return Number(pts);
192
- }
193
- else {
194
- return null;
195
- }
115
+ getChannelPts(channelId) {
116
+ return this.get(KPARTS__CHANNEL_PTS(channelId));
196
117
  }
197
118
  async setEntity(peer) {
198
119
  const type = peer instanceof types.Channel ? "channel" : peer instanceof types.Chat ? "chat" : peer instanceof types.User ? "user" : (0, _0_control_js_1.UNREACHABLE)();
199
- await this.set(`${this.peer__}${type}${peer.id}`, (0, deps_js_1.base64Encode)((0, _0_rle_js_1.rleEncode)(peer[_1_tl_object_js_1.serialize]())));
120
+ await this.set(KPARTS__PEER(type, peer.id), peer[_1_tl_object_js_1.serialize]());
200
121
  }
201
122
  async getEntity(type, id) {
202
- const peer_ = await this.get(`${this.peer__}${type}${id}`);
123
+ const peer_ = await this.get(KPARTS__PEER(type, id));
203
124
  if (peer_ != null) {
204
- const reader = new _3_tl_reader_js_1.TLReader((0, _0_rle_js_1.rleDecode)((0, deps_js_1.base64Decode)(peer_)));
205
- return reader.readObject();
125
+ return new _3_tl_reader_js_1.TLReader(peer_).readObject();
206
126
  }
207
127
  else {
208
128
  return null;
@@ -218,31 +138,18 @@ class Storage {
218
138
  throw err;
219
139
  }
220
140
  else {
221
- await this.set(this.accountType__, type);
141
+ await this.set(KPARTS__ACCOUNT_TYPE, type);
222
142
  }
223
143
  }
224
144
  }
225
- async getAccountType() {
226
- const accountType = await this.get(this.accountType__);
227
- if (accountType != null) {
228
- return accountType;
229
- }
230
- else {
231
- (0, _0_control_js_1.UNREACHABLE)();
232
- }
145
+ getAccountType() {
146
+ return this.get(KPARTS__ACCOUNT_TYPE);
233
147
  }
234
148
  async updateStickerSetName(id, accessHash, name) {
235
- await this.set(`${this.stickerSetName__}${id}${accessHash}`, JSON.stringify([name, new Date()]));
149
+ await this.set(KPARTS__STICKER_SET_NAME(id, accessHash), [name, new Date()]);
236
150
  }
237
- async getStickerSetName(id, accessHash) {
238
- const stickerSetName_ = await this.get(`${this.stickerSetName__}${id}${accessHash}`);
239
- if (stickerSetName_ != null) {
240
- const [name, updatedAt] = JSON.parse(stickerSetName_);
241
- return [name, new Date(updatedAt)];
242
- }
243
- else {
244
- return null;
245
- }
151
+ getStickerSetName(id, accessHash) {
152
+ return this.get(KPARTS__STICKER_SET_NAME(id, accessHash));
246
153
  }
247
154
  }
248
155
  exports.Storage = Storage;
@@ -0,0 +1,13 @@
1
+ import { StorageKeyPart } from "./0_storage.js";
2
+ export declare enum ValueType {
3
+ Boolean = 0,
4
+ Number = 1,
5
+ String = 2,
6
+ BigInt = 3,
7
+ Date = 4,
8
+ Uint8Array = 5,
9
+ Array = 6
10
+ }
11
+ export declare function toString(value: unknown): string;
12
+ export declare function fromString<T>(string: string): any;
13
+ export declare function fixKey(key: StorageKeyPart[]): (string | number | Uint8Array)[];
@@ -0,0 +1,68 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.fixKey = exports.fromString = exports.toString = exports.ValueType = void 0;
4
+ const deps_js_1 = require("../deps.js");
5
+ const _0_control_js_1 = require("../utilities/0_control.js");
6
+ var ValueType;
7
+ (function (ValueType) {
8
+ ValueType[ValueType["Boolean"] = 0] = "Boolean";
9
+ ValueType[ValueType["Number"] = 1] = "Number";
10
+ ValueType[ValueType["String"] = 2] = "String";
11
+ ValueType[ValueType["BigInt"] = 3] = "BigInt";
12
+ ValueType[ValueType["Date"] = 4] = "Date";
13
+ ValueType[ValueType["Uint8Array"] = 5] = "Uint8Array";
14
+ ValueType[ValueType["Array"] = 6] = "Array";
15
+ })(ValueType = exports.ValueType || (exports.ValueType = {}));
16
+ function toString(value) {
17
+ if (typeof value === "boolean") {
18
+ return JSON.stringify([ValueType.Boolean, value]);
19
+ }
20
+ else if (typeof value === "number") {
21
+ return JSON.stringify([ValueType.Number, value]);
22
+ }
23
+ else if (typeof value === "string") {
24
+ return JSON.stringify([ValueType.String, value]);
25
+ }
26
+ else if (typeof value == "bigint") {
27
+ return JSON.stringify([ValueType.BigInt, String(value)]);
28
+ }
29
+ else if (value instanceof Date) {
30
+ return JSON.stringify([ValueType.Date, value.getTime()]);
31
+ }
32
+ else if (value instanceof Uint8Array) {
33
+ return JSON.stringify([ValueType.Uint8Array, (0, deps_js_1.base64Encode)(value)]);
34
+ }
35
+ else if (Array.isArray(value)) {
36
+ return JSON.stringify([ValueType.Array, value.map(toString)]);
37
+ }
38
+ else {
39
+ (0, _0_control_js_1.UNREACHABLE)();
40
+ }
41
+ }
42
+ exports.toString = toString;
43
+ 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, deps_js_1.base64Decode)(value);
56
+ }
57
+ else if (type == ValueType.Array) {
58
+ return value.map(fromString);
59
+ }
60
+ else {
61
+ (0, _0_control_js_1.UNREACHABLE)();
62
+ }
63
+ }
64
+ exports.fromString = fromString;
65
+ function fixKey(key) {
66
+ return key.map((v) => typeof v === "bigint" ? String(v) : v);
67
+ }
68
+ exports.fixKey = fixKey;
@@ -1,9 +1,9 @@
1
- import { Storage } from "./0_storage.js";
1
+ import { Storage, StorageKeyPart } from "./0_storage.js";
2
2
  export declare class StorageIndexedDB extends Storage {
3
3
  readonly name: string;
4
4
  database: IDBDatabase | null;
5
5
  constructor(name: string);
6
6
  init(): Promise<void>;
7
- set(k: string, v: string | null): Promise<void>;
8
- get(k: string): Promise<string | null>;
7
+ set(k: StorageKeyPart[], v: unknown): Promise<void>;
8
+ get<T>(k: StorageKeyPart[]): Promise<T | null>;
9
9
  }
@@ -2,6 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.StorageIndexedDB = void 0;
4
4
  const _0_storage_js_1 = require("./0_storage.js");
5
+ const _0_utilities_js_1 = require("./0_utilities.js");
5
6
  const VERSION = 1;
6
7
  const KV_OBJECT_STORE = "kv";
7
8
  class StorageIndexedDB extends _0_storage_js_1.Storage {
@@ -47,10 +48,10 @@ class StorageIndexedDB extends _0_storage_js_1.Storage {
47
48
  // deno-lint-ignore no-explicit-any
48
49
  let tx;
49
50
  if (v == null) {
50
- tx = store.delete(k);
51
+ tx = store.delete((0, _0_utilities_js_1.fixKey)(k));
51
52
  }
52
53
  else {
53
- tx = store.put(v, k);
54
+ tx = store.put(v, (0, _0_utilities_js_1.fixKey)(k));
54
55
  }
55
56
  return new Promise((res, rej) => {
56
57
  tx.onerror = rej;
@@ -66,7 +67,7 @@ class StorageIndexedDB extends _0_storage_js_1.Storage {
66
67
  const tx = this.database
67
68
  .transaction(KV_OBJECT_STORE, "readonly")
68
69
  .objectStore(KV_OBJECT_STORE)
69
- .get(k);
70
+ .get((0, _0_utilities_js_1.fixKey)(k));
70
71
  return new Promise((res, rej) => {
71
72
  tx.onerror = rej;
72
73
  tx.onsuccess = () => {
@@ -1,9 +1,9 @@
1
1
  import { MaybePromise } from "../utilities/0_types.js";
2
- import { Storage } from "./0_storage.js";
2
+ import { Storage, StorageKeyPart } from "./0_storage.js";
3
3
  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: string): string | null;
8
- set(key: string, value: string | null): MaybePromise<void>;
7
+ get(key_: readonly StorageKeyPart[]): any;
8
+ set(key_: readonly StorageKeyPart[], value: unknown): MaybePromise<void>;
9
9
  }
@@ -2,6 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.StorageLocalStorage = void 0;
4
4
  const _0_storage_js_1 = require("./0_storage.js");
5
+ const _0_utilities_js_1 = require("./0_utilities.js");
5
6
  class StorageLocalStorage extends _0_storage_js_1.Storage {
6
7
  constructor(prefix) {
7
8
  if (typeof localStorage === "undefined") {
@@ -23,14 +24,20 @@ class StorageLocalStorage extends _0_storage_js_1.Storage {
23
24
  }
24
25
  init() {
25
26
  }
26
- get(key) {
27
- key = this.prefix + key;
28
- return localStorage.getItem(key);
27
+ get(key_) {
28
+ const key = this.prefix + (0, _0_utilities_js_1.toString)(key_);
29
+ const value = localStorage.getItem(key);
30
+ if (value != null) {
31
+ return (0, _0_utilities_js_1.fromString)(value);
32
+ }
33
+ else {
34
+ return null;
35
+ }
29
36
  }
30
- set(key, value) {
31
- key = this.prefix + key;
37
+ set(key_, value) {
38
+ const key = this.prefix + (0, _0_utilities_js_1.toString)(key_);
32
39
  if (value != null) {
33
- localStorage.setItem(key, value);
40
+ localStorage.setItem(key, (0, _0_utilities_js_1.toString)(value));
34
41
  }
35
42
  else {
36
43
  localStorage.removeItem(key);
@@ -1,8 +1,8 @@
1
1
  import { MaybePromise } from "../utilities/0_types.js";
2
- import { Storage } from "./0_storage.js";
2
+ import { Storage, StorageKeyPart } from "./0_storage.js";
3
3
  export declare class StorageMemory extends Storage implements Storage {
4
- protected map: Map<string, string>;
4
+ protected map: Map<string, unknown>;
5
5
  init(): void;
6
- get(key: string): string | null;
7
- set(key: string, value: string | null): MaybePromise<void>;
6
+ get<T>(key: readonly StorageKeyPart[]): NonNullable<T> | null;
7
+ set(key_: readonly StorageKeyPart[], value: unknown): MaybePromise<void>;
8
8
  }
@@ -2,6 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.StorageMemory = void 0;
4
4
  const _0_storage_js_1 = require("./0_storage.js");
5
+ const _0_utilities_js_1 = require("./0_utilities.js");
5
6
  class StorageMemory extends _0_storage_js_1.Storage {
6
7
  constructor() {
7
8
  super(...arguments);
@@ -15,9 +16,10 @@ class StorageMemory extends _0_storage_js_1.Storage {
15
16
  init() {
16
17
  }
17
18
  get(key) {
18
- return this.map.get(key) ?? null;
19
+ return this.map.get((0, _0_utilities_js_1.toString)(key)) ?? null;
19
20
  }
20
- set(key, value) {
21
+ set(key_, value) {
22
+ const key = (0, _0_utilities_js_1.toString)(key_);
21
23
  if (value != null) {
22
24
  this.map.set(key, value);
23
25
  }
@@ -1,9 +1,9 @@
1
1
  import { MaybePromise } from "../utilities/0_types.js";
2
- import { Storage } from "./0_storage.js";
2
+ import { Storage, StorageKeyPart } from "./0_storage.js";
3
3
  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: string): string | null;
8
- set(key: string, value: string | null): MaybePromise<void>;
7
+ get(key_: readonly StorageKeyPart[]): any;
8
+ set(key_: readonly StorageKeyPart[], value: unknown): MaybePromise<void>;
9
9
  }
@@ -2,6 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.StorageSessionStorage = void 0;
4
4
  const _0_storage_js_1 = require("./0_storage.js");
5
+ const _0_utilities_js_1 = require("./0_utilities.js");
5
6
  class StorageSessionStorage extends _0_storage_js_1.Storage {
6
7
  constructor(prefix) {
7
8
  if (typeof sessionStorage === "undefined") {
@@ -23,14 +24,20 @@ class StorageSessionStorage extends _0_storage_js_1.Storage {
23
24
  }
24
25
  init() {
25
26
  }
26
- get(key) {
27
- key = this.prefix + key;
28
- return sessionStorage.getItem(key);
27
+ get(key_) {
28
+ const key = this.prefix + (0, _0_utilities_js_1.toString)(key_);
29
+ const value = sessionStorage.getItem(key);
30
+ if (value != null) {
31
+ return (0, _0_utilities_js_1.fromString)(value);
32
+ }
33
+ else {
34
+ return null;
35
+ }
29
36
  }
30
- set(key, value) {
31
- key = this.prefix + key;
37
+ set(key_, value) {
38
+ const key = this.prefix + (0, _0_utilities_js_1.toString)(key_);
32
39
  if (value != null) {
33
- sessionStorage.setItem(key, value);
40
+ sessionStorage.setItem(key, (0, _0_utilities_js_1.toString)(value));
34
41
  }
35
42
  else {
36
43
  sessionStorage.removeItem(key);