@mtkruto/node 0.1.127 → 0.1.129
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/esm/4_constants.d.ts +1 -1
- package/esm/4_constants.js +1 -1
- package/esm/client/5_client.js +119 -12
- package/esm/storage/0_storage.d.ts +11 -6
- package/esm/storage/0_storage.js +53 -4
- package/esm/storage/1_storage_indexed_db.d.ts +5 -2
- package/esm/storage/1_storage_indexed_db.js +50 -8
- package/esm/storage/1_storage_local_storage.d.ts +4 -1
- package/esm/storage/1_storage_local_storage.js +24 -6
- package/esm/storage/1_storage_memory.d.ts +2 -0
- package/esm/storage/1_storage_memory.js +29 -2
- package/esm/storage/1_storage_session_storage.d.ts +4 -1
- package/esm/storage/1_storage_session_storage.js +24 -6
- package/esm/types/1__getters.d.ts +2 -2
- package/esm/types/1_chat_p.d.ts +2 -2
- package/esm/types/1_chat_p.js +16 -4
- package/package.json +1 -1
- package/script/4_constants.d.ts +1 -1
- package/script/4_constants.js +1 -1
- package/script/client/5_client.js +119 -12
- package/script/storage/0_storage.d.ts +11 -6
- package/script/storage/0_storage.js +53 -4
- package/script/storage/1_storage_indexed_db.d.ts +5 -2
- package/script/storage/1_storage_indexed_db.js +50 -8
- package/script/storage/1_storage_local_storage.d.ts +4 -1
- package/script/storage/1_storage_local_storage.js +24 -6
- package/script/storage/1_storage_memory.d.ts +2 -0
- package/script/storage/1_storage_memory.js +29 -2
- package/script/storage/1_storage_session_storage.d.ts +4 -1
- package/script/storage/1_storage_session_storage.js +24 -6
- package/script/types/1__getters.d.ts +2 -2
- package/script/types/1_chat_p.d.ts +2 -2
- package/script/types/1_chat_p.js +16 -4
package/esm/4_constants.d.ts
CHANGED
|
@@ -4,7 +4,7 @@ export type PublicKeys = readonly [bigint, [bigint, bigint]][];
|
|
|
4
4
|
export declare const PUBLIC_KEYS: PublicKeys;
|
|
5
5
|
export declare const INITIAL_DC: DC;
|
|
6
6
|
export declare const LAYER = 167;
|
|
7
|
-
export declare const APP_VERSION = "MTKruto 0.1.
|
|
7
|
+
export declare const APP_VERSION = "MTKruto 0.1.129";
|
|
8
8
|
export declare const DEVICE_MODEL: string;
|
|
9
9
|
export declare const LANG_CODE: string;
|
|
10
10
|
export declare const LANG_PACK = "";
|
package/esm/4_constants.js
CHANGED
|
@@ -53,7 +53,7 @@ export const PUBLIC_KEYS = Object.freeze([
|
|
|
53
53
|
]);
|
|
54
54
|
export const INITIAL_DC = "2";
|
|
55
55
|
export const LAYER = 167;
|
|
56
|
-
export const APP_VERSION = "MTKruto 0.1.
|
|
56
|
+
export const APP_VERSION = "MTKruto 0.1.129";
|
|
57
57
|
// @ts-ignore: lib
|
|
58
58
|
export const 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;
|
|
59
59
|
export const LANG_CODE = typeof navigator === "undefined" ? "en" : navigator.language.split("-")[0];
|
package/esm/client/5_client.js
CHANGED
|
@@ -9,7 +9,7 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
|
|
|
9
9
|
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");
|
|
10
10
|
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
11
11
|
};
|
|
12
|
-
var _Client_instances, _a, _Client_auth, _Client_sessionId, _Client_state, _Client_promises, _Client_toAcknowledge, _Client_updateState, _Client_publicKeys, _Client_autoStart, _Client_ignoreOutgoing, _Client_prefixes, _Client_namespaceProxies, _Client_constructContext, _Client_propagateConnectionState, _Client_lastPropagatedConnectionState, _Client_storageInited, _Client_setAuth, _Client_authKeyWasCreated, _Client_connectMutex, _Client_assertUser, _Client_assertBot, _Client_fetchState, _Client_connectionInited, _Client_initConnection, _Client_lastPropagatedAuthorizationState, _Client_propagateAuthorizationState, _Client_selfId, _Client_getSelfId, _Client_receiveLoop, _Client_pingLoopAbortSignal, _Client_pingInterval, _Client_pingLoop, _Client_pingLoopStarted, _Client_autoStarted, _Client_lastMsgId, _Client_invoke, _Client_handleInvokeError, _Client_processChats, _Client_processUsers, _Client_handleUpdateQueue, _Client_processUpdatesQueue, _Client_checkGap, _Client_checkChannelGap, _Client_lastUpdates, _Client_processUpdates, _Client_setUpdateStateDate, _Client_setUpdatePts, _Client_getLocalState, _Client_recoverUpdateGap, _Client_recoverChannelUpdateGap, _Client_getChannelAccessHash, _Client_getInputPeerInner, _Client_updatesToMessages, _Client_resolveSendAs, _Client_parseText, _Client_getMessagesInner, _Client_downloadInner, _Client_lastGetMe, _Client_getMe, _Client_handleUpdate, _Client_usernameResolver, _Client_constructReplyMarkup, _Client_assertMsgHas, _Client_handle, _Client_setMyInfo, _Client_getMyInfo, _Client_resolveFileId, _Client_sendMedia, _Client_sendChatUpdate, _Client_reassignChatLastMessage, _Client_chats, _Client_archivedChats, _Client_chatsLoadedFromStorage, _Client_getChatAnywhere, _Client_getChatList, _Client_loadChatsFromStorage, _Client_getLoadedChats, _Client_pinnedChats, _Client_pinnedArchiveChats, _Client_storageHadPinnedChats, _Client_pinnedChatsLoaded, _Client_loadPinnedChats, _Client_fetchPinnedChats, _Client_getPinnedChats, _Client_updatePinnedChats, _Client_fetchChats;
|
|
12
|
+
var _Client_instances, _a, _Client_auth, _Client_sessionId, _Client_state, _Client_promises, _Client_toAcknowledge, _Client_updateState, _Client_publicKeys, _Client_autoStart, _Client_ignoreOutgoing, _Client_prefixes, _Client_namespaceProxies, _Client_constructContext, _Client_propagateConnectionState, _Client_lastPropagatedConnectionState, _Client_storageInited, _Client_setAuth, _Client_authKeyWasCreated, _Client_connectMutex, _Client_assertUser, _Client_assertBot, _Client_fetchState, _Client_connectionInited, _Client_initConnection, _Client_lastPropagatedAuthorizationState, _Client_propagateAuthorizationState, _Client_selfId, _Client_getSelfId, _Client_receiveLoop, _Client_pingLoopAbortSignal, _Client_pingInterval, _Client_pingLoop, _Client_pingLoopStarted, _Client_autoStarted, _Client_lastMsgId, _Client_invoke, _Client_handleInvokeError, _Client_processChats, _Client_processUsers, _Client_handleUpdateQueue, _Client_processUpdatesQueue, _Client_checkGap, _Client_checkChannelGap, _Client_lastUpdates, _Client_processUpdates, _Client_setUpdateStateDate, _Client_setUpdatePts, _Client_getLocalState, _Client_recoverUpdateGap, _Client_recoverChannelUpdateGap, _Client_getChannelAccessHash, _Client_getInputPeerInner, _Client_updatesToMessages, _Client_resolveSendAs, _Client_parseText, _Client_getMessagesInner, _Client_downloadInner, _Client_lastGetMe, _Client_getMe, _Client_handleUpdate, _Client_usernameResolver, _Client_constructReplyMarkup, _Client_assertMsgHas, _Client_handle, _Client_setMyInfo, _Client_getMyInfo, _Client_resolveFileId, _Client_sendMedia, _Client_sendChatUpdate, _Client_reassignChatLastMessage, _Client_chats, _Client_archivedChats, _Client_chatsLoadedFromStorage, _Client_getChatAnywhere, _Client_getChatList, _Client_loadChatsFromStorage, _Client_getLoadedChats, _Client_pinnedChats, _Client_pinnedArchiveChats, _Client_storageHadPinnedChats, _Client_pinnedChatsLoaded, _Client_loadPinnedChats, _Client_fetchPinnedChats, _Client_getPinnedChats, _Client_updateOrAddChat, _Client_removeChat, _Client_updatePinnedChats, _Client_fetchChats;
|
|
13
13
|
import { contentType, debug, gunzip, Mutex } from "../0_deps.js";
|
|
14
14
|
import { bigIntFromBuffer, cleanObject, drop, getRandomBigInt, getRandomId, mod, mustPrompt, mustPromptOneOf, Queue, sha1, UNREACHABLE, ZERO_CHANNEL_ID } from "../1_utilities.js";
|
|
15
15
|
import { as, functions, getChannelChatId, Message_, MessageContainer, name, peerToChatId, RPCResult, TLError, TLReader, types } from "../2_tl.js";
|
|
@@ -996,6 +996,9 @@ export class Client extends ClientAbstract {
|
|
|
996
996
|
else if (chat instanceof types.Chat) {
|
|
997
997
|
await this.storage.setEntity(chat);
|
|
998
998
|
}
|
|
999
|
+
else if (chat instanceof types.ChannelForbidden || chat instanceof types.ChatForbidden) {
|
|
1000
|
+
await this.storage.removeEntity(chat);
|
|
1001
|
+
}
|
|
999
1002
|
}
|
|
1000
1003
|
}, _Client_processUsers = async function _Client_processUsers(users) {
|
|
1001
1004
|
for (const user of users) {
|
|
@@ -1152,6 +1155,14 @@ export class Client extends ClientAbstract {
|
|
|
1152
1155
|
}
|
|
1153
1156
|
else if (update instanceof types.UpdateUserName) {
|
|
1154
1157
|
await this.storage.updateUsernames("user", update.user_id, update.usernames.map((v) => v.username));
|
|
1158
|
+
const peer = new types.PeerUser(update);
|
|
1159
|
+
const entity = await this[getEntity](peer);
|
|
1160
|
+
if (entity != null) {
|
|
1161
|
+
entity.usernames = update.usernames;
|
|
1162
|
+
entity.first_name = update.first_name;
|
|
1163
|
+
entity.last_name = update.last_name;
|
|
1164
|
+
await this.storage.setEntity(entity);
|
|
1165
|
+
}
|
|
1155
1166
|
}
|
|
1156
1167
|
else if (update instanceof types.UpdatePtsChanged) {
|
|
1157
1168
|
await __classPrivateFieldGet(this, _Client_instances, "m", _Client_fetchState).call(this, "updatePtsChanged");
|
|
@@ -1178,7 +1189,7 @@ export class Client extends ClientAbstract {
|
|
|
1178
1189
|
}
|
|
1179
1190
|
}
|
|
1180
1191
|
/// If there were any Update, they will be passed to the update handling queue.
|
|
1181
|
-
if (update instanceof types._Update) {
|
|
1192
|
+
if (update instanceof types._Update || update instanceof types.UpdateShortMessage || update instanceof types.UpdateShortChatMessage || update instanceof types.UpdateShortSentMessage) {
|
|
1182
1193
|
updatesToHandle.push(update);
|
|
1183
1194
|
}
|
|
1184
1195
|
}
|
|
@@ -1645,12 +1656,21 @@ export class Client extends ClientAbstract {
|
|
|
1645
1656
|
}
|
|
1646
1657
|
}
|
|
1647
1658
|
async [(_Client_downloadInner = async function* _Client_downloadInner(location, dcId, params) {
|
|
1659
|
+
const id = "id" in location ? location.id : "photo_id" in location ? location.photo_id : null;
|
|
1660
|
+
if (id != null) {
|
|
1661
|
+
const partCount = await this.storage.getFile(id);
|
|
1662
|
+
if (partCount != null && partCount > 0) {
|
|
1663
|
+
for await (const part of this.storage.iterFileParts(id, partCount)) {
|
|
1664
|
+
yield part;
|
|
1665
|
+
}
|
|
1666
|
+
return;
|
|
1667
|
+
}
|
|
1668
|
+
}
|
|
1648
1669
|
const chunkSize = params?.chunkSize ?? 1024 * 1024;
|
|
1649
1670
|
if (mod(chunkSize, 1024) != 0) {
|
|
1650
1671
|
throw new Error("chunkSize must be divisible by 1024");
|
|
1651
1672
|
}
|
|
1652
|
-
const
|
|
1653
|
-
const client = new _a(new StorageMemory(), this.apiId, this.apiHash, {
|
|
1673
|
+
const client = new _a(dcId == this.dcId ? this.storage : this.storage.branch(`download_client_${dcId}`), this.apiId, this.apiHash, {
|
|
1654
1674
|
transportProvider: this.transportProvider,
|
|
1655
1675
|
appVersion: this.appVersion,
|
|
1656
1676
|
deviceModel: this.deviceModel,
|
|
@@ -1666,14 +1686,37 @@ export class Client extends ClientAbstract {
|
|
|
1666
1686
|
}
|
|
1667
1687
|
await client.setDc(dc);
|
|
1668
1688
|
await client.connect();
|
|
1669
|
-
await client.
|
|
1689
|
+
await __classPrivateFieldGet(client, _Client_instances, "m", _Client_initConnection).call(client);
|
|
1690
|
+
client.invoke.use(async (ctx, next) => {
|
|
1691
|
+
if (ctx.error instanceof AuthKeyUnregistered) {
|
|
1692
|
+
try {
|
|
1693
|
+
const exportedAuth = await this.invoke(new functions.auth.exportAuthorization({ dc_id: dcId }));
|
|
1694
|
+
await client.authorize(exportedAuth);
|
|
1695
|
+
return true;
|
|
1696
|
+
}
|
|
1697
|
+
catch (err) {
|
|
1698
|
+
throw err;
|
|
1699
|
+
}
|
|
1700
|
+
}
|
|
1701
|
+
else {
|
|
1702
|
+
return await next();
|
|
1703
|
+
}
|
|
1704
|
+
});
|
|
1670
1705
|
const limit = chunkSize;
|
|
1671
1706
|
let offset = 0n;
|
|
1707
|
+
let part = 0;
|
|
1672
1708
|
while (true) {
|
|
1673
1709
|
const file = await (client ?? this).invoke(new functions.upload.getFile({ location, offset, limit }));
|
|
1674
1710
|
if (file instanceof types.upload.File) {
|
|
1675
1711
|
yield file.bytes;
|
|
1712
|
+
if (id != null) {
|
|
1713
|
+
await this.storage.saveFilePart(id, part, file.bytes);
|
|
1714
|
+
}
|
|
1715
|
+
++part;
|
|
1676
1716
|
if (file.bytes.length < limit) {
|
|
1717
|
+
if (id != null) {
|
|
1718
|
+
await this.storage.setFilePartCount(id, part + 1);
|
|
1719
|
+
}
|
|
1677
1720
|
break;
|
|
1678
1721
|
}
|
|
1679
1722
|
else {
|
|
@@ -2315,7 +2358,9 @@ export class Client extends ClientAbstract {
|
|
|
2315
2358
|
}
|
|
2316
2359
|
if (messages.length < limit) {
|
|
2317
2360
|
d("have only %d messages but need %d more", messages.length, limit - messages.length);
|
|
2318
|
-
|
|
2361
|
+
if (messages.length > 0) {
|
|
2362
|
+
offsetId = messages[messages.length - 1].id; // TODO: track id of oldest message and don't send requests for it
|
|
2363
|
+
}
|
|
2319
2364
|
const result = await this.api.messages.getHistory({
|
|
2320
2365
|
peer: peer,
|
|
2321
2366
|
offset_id: offsetId,
|
|
@@ -2358,7 +2403,7 @@ async function _Client_handleUpdate(update) {
|
|
|
2358
2403
|
silent: update.silent,
|
|
2359
2404
|
id: update.id,
|
|
2360
2405
|
from_id: update.out ? new types.PeerUser({ user_id: await __classPrivateFieldGet(this, _Client_instances, "m", _Client_getSelfId).call(this).then(BigInt) }) : new types.PeerUser({ user_id: update.user_id }),
|
|
2361
|
-
peer_id: new types.
|
|
2406
|
+
peer_id: new types.PeerUser({ user_id: update.user_id }),
|
|
2362
2407
|
message: update.message,
|
|
2363
2408
|
date: update.date,
|
|
2364
2409
|
fwd_from: update.fwd_from,
|
|
@@ -2461,6 +2506,39 @@ async function _Client_handleUpdate(update) {
|
|
|
2461
2506
|
if (update instanceof types.UpdatePinnedDialogs) {
|
|
2462
2507
|
await __classPrivateFieldGet(this, _Client_instances, "m", _Client_updatePinnedChats).call(this, update);
|
|
2463
2508
|
}
|
|
2509
|
+
if (update instanceof types.UpdateChannel) {
|
|
2510
|
+
const peer = new types.PeerChannel(update);
|
|
2511
|
+
const channel = await this[getEntity](peer);
|
|
2512
|
+
if (channel != null && "left" in channel && channel.left) {
|
|
2513
|
+
await __classPrivateFieldGet(this, _Client_instances, "m", _Client_removeChat).call(this, peerToChatId(peer));
|
|
2514
|
+
}
|
|
2515
|
+
else if (channel instanceof types.ChannelForbidden) {
|
|
2516
|
+
await __classPrivateFieldGet(this, _Client_instances, "m", _Client_removeChat).call(this, peerToChatId(peer));
|
|
2517
|
+
}
|
|
2518
|
+
else if (channel instanceof types.Channel) {
|
|
2519
|
+
await __classPrivateFieldGet(this, _Client_instances, "m", _Client_updateOrAddChat).call(this, peerToChatId(peer));
|
|
2520
|
+
}
|
|
2521
|
+
}
|
|
2522
|
+
else if (update instanceof types.UpdateChat) { // TODO: handle deactivated (migration)
|
|
2523
|
+
const peer = new types.PeerChat(update);
|
|
2524
|
+
const chat = await this[getEntity](peer);
|
|
2525
|
+
if (chat != null && "left" in chat && chat.left) {
|
|
2526
|
+
await __classPrivateFieldGet(this, _Client_instances, "m", _Client_removeChat).call(this, peerToChatId(peer));
|
|
2527
|
+
}
|
|
2528
|
+
else if (chat instanceof types.ChatForbidden) {
|
|
2529
|
+
await __classPrivateFieldGet(this, _Client_instances, "m", _Client_removeChat).call(this, peerToChatId(peer));
|
|
2530
|
+
}
|
|
2531
|
+
else if (chat instanceof types.Chat) {
|
|
2532
|
+
await __classPrivateFieldGet(this, _Client_instances, "m", _Client_updateOrAddChat).call(this, peerToChatId(peer));
|
|
2533
|
+
}
|
|
2534
|
+
}
|
|
2535
|
+
else if (update instanceof types.UpdateUser || update instanceof types.UpdateUserName) {
|
|
2536
|
+
const peer = new types.PeerUser(update);
|
|
2537
|
+
const chat = await this[getEntity](peer);
|
|
2538
|
+
if (chat != null) {
|
|
2539
|
+
await __classPrivateFieldGet(this, _Client_instances, "m", _Client_updateOrAddChat).call(this, peerToChatId(peer));
|
|
2540
|
+
}
|
|
2541
|
+
}
|
|
2464
2542
|
}, _Client_constructReplyMarkup = async function _Client_constructReplyMarkup(params) {
|
|
2465
2543
|
if (params?.replyMarkup) {
|
|
2466
2544
|
await __classPrivateFieldGet(this, _Client_instances, "m", _Client_assertBot).call(this, "replyMarkup");
|
|
@@ -2532,12 +2610,12 @@ async function _Client_setMyInfo(info) {
|
|
|
2532
2610
|
catch {
|
|
2533
2611
|
return;
|
|
2534
2612
|
}
|
|
2535
|
-
const chat = __classPrivateFieldGet(this,
|
|
2613
|
+
const [chat] = __classPrivateFieldGet(this, _Client_instances, "m", _Client_getChatAnywhere).call(this, chatId);
|
|
2536
2614
|
const update = chat === undefined ? { deletedChat: { chatId } } : added ? { newChat: chat } : { editedChat: chat };
|
|
2537
2615
|
__classPrivateFieldGet(this, _Client_handleUpdateQueue, "f").add(async () => {
|
|
2538
2616
|
await __classPrivateFieldGet(this, _Client_handle, "f").call(this, await __classPrivateFieldGet(this, _Client_constructContext, "f").call(this, update), resolve);
|
|
2539
2617
|
});
|
|
2540
|
-
}, _Client_reassignChatLastMessage = async function _Client_reassignChatLastMessage(chatId, add = false) {
|
|
2618
|
+
}, _Client_reassignChatLastMessage = async function _Client_reassignChatLastMessage(chatId, add = false, sendUpdate = true) {
|
|
2541
2619
|
try {
|
|
2542
2620
|
await __classPrivateFieldGet(this, _Client_instances, "m", _Client_assertUser).call(this, "");
|
|
2543
2621
|
}
|
|
@@ -2565,7 +2643,9 @@ async function _Client_setMyInfo(info) {
|
|
|
2565
2643
|
__classPrivateFieldGet(this, _Client_chats, "f").set(chatId, chat);
|
|
2566
2644
|
await this.storage.setChat(listId, chatId, chat.pinned, chat.lastMessage?.id ?? 0, chat.lastMessage?.date ?? new Date(0));
|
|
2567
2645
|
}
|
|
2568
|
-
|
|
2646
|
+
if (sendUpdate) {
|
|
2647
|
+
await __classPrivateFieldGet(this, _Client_instances, "m", _Client_sendChatUpdate).call(this, chatId, !chat);
|
|
2648
|
+
}
|
|
2569
2649
|
return;
|
|
2570
2650
|
}
|
|
2571
2651
|
const message = await this.getHistory(chatId, { limit: 1 }).then((v) => v[0]);
|
|
@@ -2583,13 +2663,17 @@ async function _Client_setMyInfo(info) {
|
|
|
2583
2663
|
}
|
|
2584
2664
|
__classPrivateFieldGet(this, _Client_chats, "f").set(chatId, chat);
|
|
2585
2665
|
}
|
|
2586
|
-
|
|
2666
|
+
if (sendUpdate) {
|
|
2667
|
+
await __classPrivateFieldGet(this, _Client_instances, "m", _Client_sendChatUpdate).call(this, chatId, !chat);
|
|
2668
|
+
}
|
|
2587
2669
|
return;
|
|
2588
2670
|
}
|
|
2589
2671
|
if (chat) {
|
|
2590
2672
|
chat.order = getChatOrder(undefined, chat.pinned);
|
|
2591
2673
|
chat.lastMessage = undefined;
|
|
2592
|
-
|
|
2674
|
+
if (sendUpdate) {
|
|
2675
|
+
await __classPrivateFieldGet(this, _Client_instances, "m", _Client_sendChatUpdate).call(this, chatId, false);
|
|
2676
|
+
}
|
|
2593
2677
|
}
|
|
2594
2678
|
}, _Client_getChatAnywhere = function _Client_getChatAnywhere(chatId) {
|
|
2595
2679
|
let chat = __classPrivateFieldGet(this, _Client_chats, "f").get(chatId);
|
|
@@ -2682,6 +2766,29 @@ async function _Client_setMyInfo(info) {
|
|
|
2682
2766
|
default:
|
|
2683
2767
|
UNREACHABLE();
|
|
2684
2768
|
}
|
|
2769
|
+
}, _Client_updateOrAddChat = async function _Client_updateOrAddChat(chatId) {
|
|
2770
|
+
const [chat, listId] = __classPrivateFieldGet(this, _Client_instances, "m", _Client_getChatAnywhere).call(this, chatId);
|
|
2771
|
+
if (chat !== undefined) {
|
|
2772
|
+
const newChat = await constructChat2(chatId, chat.pinned, chat.lastMessage, this[getEntity].bind(this));
|
|
2773
|
+
if (newChat != null) {
|
|
2774
|
+
__classPrivateFieldGet(this, _Client_instances, "m", _Client_getChatList).call(this, listId).set(chatId, newChat);
|
|
2775
|
+
await __classPrivateFieldGet(this, _Client_instances, "m", _Client_sendChatUpdate).call(this, chatId, false);
|
|
2776
|
+
}
|
|
2777
|
+
}
|
|
2778
|
+
else {
|
|
2779
|
+
const chat = await constructChat3(chatId, -1, -1, this[getEntity].bind(this), this.getMessage.bind(this));
|
|
2780
|
+
if (chat != null) {
|
|
2781
|
+
__classPrivateFieldGet(this, _Client_instances, "m", _Client_getChatList).call(this, 0).set(chatId, chat);
|
|
2782
|
+
await __classPrivateFieldGet(this, _Client_instances, "m", _Client_reassignChatLastMessage).call(this, chatId, false, false);
|
|
2783
|
+
await __classPrivateFieldGet(this, _Client_instances, "m", _Client_sendChatUpdate).call(this, chatId, true);
|
|
2784
|
+
}
|
|
2785
|
+
}
|
|
2786
|
+
}, _Client_removeChat = async function _Client_removeChat(chatId) {
|
|
2787
|
+
const [chat, listId] = __classPrivateFieldGet(this, _Client_instances, "m", _Client_getChatAnywhere).call(this, chatId);
|
|
2788
|
+
if (chat !== undefined) {
|
|
2789
|
+
__classPrivateFieldGet(this, _Client_instances, "m", _Client_getChatList).call(this, listId).delete(chatId);
|
|
2790
|
+
await __classPrivateFieldGet(this, _Client_instances, "m", _Client_sendChatUpdate).call(this, chatId, false);
|
|
2791
|
+
}
|
|
2685
2792
|
}, _Client_updatePinnedChats = async function _Client_updatePinnedChats(update) {
|
|
2686
2793
|
const listId = update.folder_id ?? 0;
|
|
2687
2794
|
await __classPrivateFieldGet(this, _Client_instances, "m", _Client_fetchPinnedChats).call(this, update.folder_id);
|
|
@@ -18,6 +18,8 @@ export declare abstract class Storage {
|
|
|
18
18
|
limit?: number;
|
|
19
19
|
reverse?: boolean;
|
|
20
20
|
}): MaybePromise<Generator<[readonly StorageKeyPart[], T]> | AsyncGenerator<[readonly StorageKeyPart[], T]>>;
|
|
21
|
+
abstract get supportsFiles(): boolean;
|
|
22
|
+
abstract branch(id: string): Storage;
|
|
21
23
|
setDc(dc: DC | null): MaybePromise<void>;
|
|
22
24
|
getDc(): MaybePromise<DC | null>;
|
|
23
25
|
getAuthKey(): Promise<Uint8Array | null>;
|
|
@@ -40,13 +42,12 @@ export declare abstract class Storage {
|
|
|
40
42
|
getLastMessage(chatId: number): Promise<enums.Message | null>;
|
|
41
43
|
setChannelPts(channelId: bigint, pts: number): Promise<void>;
|
|
42
44
|
getChannelPts(channelId: bigint): MaybePromise<number | null>;
|
|
43
|
-
setEntity(
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
getEntity(type: "
|
|
47
|
-
getEntity(type: "chat", id: bigint): Promise<types.Chat | null>;
|
|
45
|
+
setEntity(entity: types.User | types.Channel | types.ChannelForbidden | types.Chat | types.ChatForbidden): Promise<void>;
|
|
46
|
+
removeEntity(entity: types.User | types.Channel | types.ChannelForbidden | types.Chat | types.ChatForbidden): Promise<void>;
|
|
47
|
+
getEntity(type: "channel", id: bigint): Promise<types.Channel | types.ChannelForbidden | null>;
|
|
48
|
+
getEntity(type: "chat", id: bigint): Promise<types.Chat | types.ChatForbidden | null>;
|
|
48
49
|
getEntity(type: "user", id: bigint): Promise<types.User | null>;
|
|
49
|
-
getEntity(type: "channel" | "chat" | "user", id: bigint): Promise<types.Channel | types.Chat | types.User | null>;
|
|
50
|
+
getEntity(type: "channel" | "chat" | "user", id: bigint): Promise<types.Channel | types.ChannelForbidden | types.Chat | types.ChatForbidden | types.User | null>;
|
|
50
51
|
setAccountType(type: "user" | "bot"): Promise<void>;
|
|
51
52
|
getAccountType(): MaybePromise<"bot" | "user" | null>;
|
|
52
53
|
updateStickerSetName(id: bigint, accessHash: bigint, name: string): Promise<void>;
|
|
@@ -66,4 +67,8 @@ export declare abstract class Storage {
|
|
|
66
67
|
setPinnedChats(listId: number, chatIds: number[] | null): Promise<void>;
|
|
67
68
|
getPinnedChats(listId: number): Promise<number[] | null>;
|
|
68
69
|
getHistory(chatId: number, offsetId: number, limit: number): Promise<enums.Message[]>;
|
|
70
|
+
getFile(id: bigint): Promise<number | null>;
|
|
71
|
+
iterFileParts(id: bigint, partCount: number): AsyncGenerator<Uint8Array, void, unknown>;
|
|
72
|
+
saveFilePart(id: bigint, index: number, bytes: Uint8Array): Promise<void>;
|
|
73
|
+
setFilePartCount(id: bigint, partCount: number): Promise<void>;
|
|
69
74
|
}
|
package/esm/storage/0_storage.js
CHANGED
|
@@ -9,7 +9,7 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
|
|
|
9
9
|
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");
|
|
10
10
|
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
11
11
|
};
|
|
12
|
-
var _Storage_instances, _Storage__authKeyId, _Storage_resetAuthKeyId;
|
|
12
|
+
var _Storage_instances, _Storage__authKeyId, _Storage_resetAuthKeyId, _Storage_getEntityType;
|
|
13
13
|
import { bigIntFromBuffer, rleDecode, rleEncode, sha1, UNREACHABLE, ZERO_CHANNEL_ID } from "../1_utilities.js";
|
|
14
14
|
import { serialize, TLReader, types } from "../2_tl.js";
|
|
15
15
|
const KPARTS__DC = ["dc"];
|
|
@@ -30,6 +30,8 @@ const KPARTS_CHATS = (listId) => ["chats", listId];
|
|
|
30
30
|
const KPARTS_CHAT = (listId, chatId) => ["chats", listId, chatId];
|
|
31
31
|
const KPARTS_PINNED_CHATS = (listId) => ["pinnedChats", listId];
|
|
32
32
|
const KPARTS_SERVER_SALT = ["serverSalt"];
|
|
33
|
+
const KPARTS_FILE = (fileId) => ["files", fileId];
|
|
34
|
+
const KPARTS_FILE_PART = (fileId, n) => ["fileParts", fileId, n];
|
|
33
35
|
export class Storage {
|
|
34
36
|
constructor() {
|
|
35
37
|
_Storage_instances.add(this);
|
|
@@ -129,9 +131,13 @@ export class Storage {
|
|
|
129
131
|
getChannelPts(channelId) {
|
|
130
132
|
return this.get(KPARTS__CHANNEL_PTS(channelId));
|
|
131
133
|
}
|
|
132
|
-
async setEntity(
|
|
133
|
-
const type =
|
|
134
|
-
await this.set(KPARTS__PEER(type,
|
|
134
|
+
async setEntity(entity) {
|
|
135
|
+
const type = __classPrivateFieldGet(this, _Storage_instances, "m", _Storage_getEntityType).call(this, entity);
|
|
136
|
+
await this.set(KPARTS__PEER(type, entity.id), rleEncode(entity[serialize]()));
|
|
137
|
+
}
|
|
138
|
+
async removeEntity(entity) {
|
|
139
|
+
const type = __classPrivateFieldGet(this, _Storage_instances, "m", _Storage_getEntityType).call(this, entity);
|
|
140
|
+
await this.set(KPARTS__PEER(type, entity.id), null);
|
|
135
141
|
}
|
|
136
142
|
async getEntity(type, id) {
|
|
137
143
|
const peer_ = await this.get(KPARTS__PEER(type, id));
|
|
@@ -219,6 +225,36 @@ export class Storage {
|
|
|
219
225
|
}
|
|
220
226
|
return messages;
|
|
221
227
|
}
|
|
228
|
+
async getFile(id) {
|
|
229
|
+
if (!this.supportsFiles) {
|
|
230
|
+
return null;
|
|
231
|
+
}
|
|
232
|
+
return await this.get(KPARTS_FILE(id));
|
|
233
|
+
}
|
|
234
|
+
async *iterFileParts(id, partCount) {
|
|
235
|
+
if (!this.supportsFiles) {
|
|
236
|
+
return;
|
|
237
|
+
}
|
|
238
|
+
for (let i = 0; i < partCount; i++) {
|
|
239
|
+
const part = await this.get(KPARTS_FILE_PART(id, i));
|
|
240
|
+
if (part == null) {
|
|
241
|
+
continue;
|
|
242
|
+
}
|
|
243
|
+
yield part;
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
async saveFilePart(id, index, bytes) {
|
|
247
|
+
if (!this.supportsFiles) {
|
|
248
|
+
return;
|
|
249
|
+
}
|
|
250
|
+
await this.set(KPARTS_FILE_PART(id, index), bytes);
|
|
251
|
+
}
|
|
252
|
+
async setFilePartCount(id, partCount) {
|
|
253
|
+
if (!this.supportsFiles) {
|
|
254
|
+
return;
|
|
255
|
+
}
|
|
256
|
+
await this.set(KPARTS_FILE(id), partCount);
|
|
257
|
+
}
|
|
222
258
|
}
|
|
223
259
|
_Storage__authKeyId = new WeakMap(), _Storage_instances = new WeakSet(), _Storage_resetAuthKeyId = async function _Storage_resetAuthKeyId(authKey) {
|
|
224
260
|
if (authKey != null) {
|
|
@@ -227,4 +263,17 @@ _Storage__authKeyId = new WeakMap(), _Storage_instances = new WeakSet(), _Storag
|
|
|
227
263
|
else {
|
|
228
264
|
__classPrivateFieldSet(this, _Storage__authKeyId, null, "f");
|
|
229
265
|
}
|
|
266
|
+
}, _Storage_getEntityType = function _Storage_getEntityType(entity) {
|
|
267
|
+
if (entity instanceof types.Channel || entity instanceof types.ChannelForbidden) {
|
|
268
|
+
return "channel";
|
|
269
|
+
}
|
|
270
|
+
else if (entity instanceof types.Chat || entity instanceof types.ChatForbidden) {
|
|
271
|
+
return "chat";
|
|
272
|
+
}
|
|
273
|
+
else if (entity instanceof types.User) {
|
|
274
|
+
return "user";
|
|
275
|
+
}
|
|
276
|
+
else {
|
|
277
|
+
UNREACHABLE();
|
|
278
|
+
}
|
|
230
279
|
};
|
|
@@ -1,11 +1,14 @@
|
|
|
1
1
|
import { GetManyFilter, Storage, StorageKeyPart } from "./0_storage.js";
|
|
2
2
|
export declare class StorageIndexedDB extends Storage {
|
|
3
|
-
|
|
3
|
+
#private;
|
|
4
4
|
database: IDBDatabase | null;
|
|
5
5
|
constructor(name: string);
|
|
6
|
+
get name(): string;
|
|
7
|
+
branch(id: string): StorageIndexedDB;
|
|
6
8
|
init(): Promise<void>;
|
|
9
|
+
get supportsFiles(): boolean;
|
|
7
10
|
set(k: readonly StorageKeyPart[], v: unknown, tx_?: IDBTransaction): Promise<void>;
|
|
8
|
-
get<T>(k: readonly StorageKeyPart[], tx_?: IDBTransaction): Promise<T | null>;
|
|
11
|
+
get<T>(k: readonly StorageKeyPart[], tx_?: IDBTransaction | null, fix?: boolean): Promise<T | null>;
|
|
9
12
|
getMany<T>(filter: GetManyFilter, params?: {
|
|
10
13
|
limit?: number;
|
|
11
14
|
reverse?: boolean;
|
|
@@ -1,3 +1,15 @@
|
|
|
1
|
+
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
2
|
+
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
3
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
4
|
+
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");
|
|
5
|
+
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
6
|
+
};
|
|
7
|
+
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
8
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
9
|
+
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");
|
|
10
|
+
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
11
|
+
};
|
|
12
|
+
var _StorageIndexedDB_instances, _StorageIndexedDB_name, _StorageIndexedDB_id, _StorageIndexedDB_fixKey;
|
|
1
13
|
import { Storage } from "./0_storage.js";
|
|
2
14
|
import { fixKey, getPrefixKeyRange, restoreKey } from "./0_utilities.js";
|
|
3
15
|
const VERSION = 1;
|
|
@@ -8,18 +20,24 @@ export class StorageIndexedDB extends Storage {
|
|
|
8
20
|
throw new Error("Unavailable in current environment");
|
|
9
21
|
}
|
|
10
22
|
super();
|
|
11
|
-
|
|
12
|
-
enumerable: true,
|
|
13
|
-
configurable: true,
|
|
14
|
-
writable: true,
|
|
15
|
-
value: name
|
|
16
|
-
});
|
|
23
|
+
_StorageIndexedDB_instances.add(this);
|
|
17
24
|
Object.defineProperty(this, "database", {
|
|
18
25
|
enumerable: true,
|
|
19
26
|
configurable: true,
|
|
20
27
|
writable: true,
|
|
21
28
|
value: null
|
|
22
29
|
});
|
|
30
|
+
_StorageIndexedDB_name.set(this, void 0);
|
|
31
|
+
_StorageIndexedDB_id.set(this, null);
|
|
32
|
+
__classPrivateFieldSet(this, _StorageIndexedDB_name, name, "f");
|
|
33
|
+
}
|
|
34
|
+
get name() {
|
|
35
|
+
return __classPrivateFieldGet(this, _StorageIndexedDB_name, "f");
|
|
36
|
+
}
|
|
37
|
+
branch(id) {
|
|
38
|
+
const storage = new StorageIndexedDB(this.name);
|
|
39
|
+
__classPrivateFieldSet(storage, _StorageIndexedDB_id, id, "f");
|
|
40
|
+
return storage;
|
|
23
41
|
}
|
|
24
42
|
init() {
|
|
25
43
|
const db = indexedDB.open(this.name, VERSION);
|
|
@@ -35,7 +53,11 @@ export class StorageIndexedDB extends Storage {
|
|
|
35
53
|
};
|
|
36
54
|
});
|
|
37
55
|
}
|
|
56
|
+
get supportsFiles() {
|
|
57
|
+
return true;
|
|
58
|
+
}
|
|
38
59
|
set(k, v, tx_) {
|
|
60
|
+
k = __classPrivateFieldGet(this, _StorageIndexedDB_instances, "m", _StorageIndexedDB_fixKey).call(this, k);
|
|
39
61
|
if (!this.database) {
|
|
40
62
|
throw new Error("Not initialized");
|
|
41
63
|
}
|
|
@@ -57,7 +79,10 @@ export class StorageIndexedDB extends Storage {
|
|
|
57
79
|
};
|
|
58
80
|
});
|
|
59
81
|
}
|
|
60
|
-
get(k, tx_) {
|
|
82
|
+
get(k, tx_, fix = true) {
|
|
83
|
+
if (fix) {
|
|
84
|
+
k = __classPrivateFieldGet(this, _StorageIndexedDB_instances, "m", _StorageIndexedDB_fixKey).call(this, k);
|
|
85
|
+
}
|
|
61
86
|
if (!this.database) {
|
|
62
87
|
throw new Error("Not initialized");
|
|
63
88
|
}
|
|
@@ -73,6 +98,15 @@ export class StorageIndexedDB extends Storage {
|
|
|
73
98
|
});
|
|
74
99
|
}
|
|
75
100
|
async *getMany(filter, params, tx_) {
|
|
101
|
+
if ("prefix" in filter && __classPrivateFieldGet(this, _StorageIndexedDB_id, "f") !== null) {
|
|
102
|
+
filter.prefix = __classPrivateFieldGet(this, _StorageIndexedDB_instances, "m", _StorageIndexedDB_fixKey).call(this, filter.prefix);
|
|
103
|
+
}
|
|
104
|
+
if ("start" in filter && __classPrivateFieldGet(this, _StorageIndexedDB_id, "f") !== null) {
|
|
105
|
+
filter.start = __classPrivateFieldGet(this, _StorageIndexedDB_instances, "m", _StorageIndexedDB_fixKey).call(this, filter.start);
|
|
106
|
+
}
|
|
107
|
+
if ("end" in filter && __classPrivateFieldGet(this, _StorageIndexedDB_id, "f") !== null) {
|
|
108
|
+
filter.end = __classPrivateFieldGet(this, _StorageIndexedDB_instances, "m", _StorageIndexedDB_fixKey).call(this, filter.end);
|
|
109
|
+
}
|
|
76
110
|
if (!this.database) {
|
|
77
111
|
throw new Error("Not initialized");
|
|
78
112
|
}
|
|
@@ -108,7 +142,7 @@ export class StorageIndexedDB extends Storage {
|
|
|
108
142
|
};
|
|
109
143
|
});
|
|
110
144
|
for (const key of keys) {
|
|
111
|
-
yield [key, await this.get(key)];
|
|
145
|
+
yield [key, await this.get(key, null, false)];
|
|
112
146
|
}
|
|
113
147
|
}
|
|
114
148
|
async incr(key, by) {
|
|
@@ -121,3 +155,11 @@ export class StorageIndexedDB extends Storage {
|
|
|
121
155
|
await this.set(key, (currentValue || 0) + by, tx);
|
|
122
156
|
}
|
|
123
157
|
}
|
|
158
|
+
_StorageIndexedDB_name = new WeakMap(), _StorageIndexedDB_id = new WeakMap(), _StorageIndexedDB_instances = new WeakSet(), _StorageIndexedDB_fixKey = function _StorageIndexedDB_fixKey(key) {
|
|
159
|
+
if (__classPrivateFieldGet(this, _StorageIndexedDB_id, "f") !== null) {
|
|
160
|
+
return ["__S" + __classPrivateFieldGet(this, _StorageIndexedDB_id, "f"), ...key];
|
|
161
|
+
}
|
|
162
|
+
else {
|
|
163
|
+
return key;
|
|
164
|
+
}
|
|
165
|
+
};
|
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
import { GetManyFilter, Storage, StorageKeyPart } from "./0_storage.js";
|
|
2
2
|
export declare class StorageLocalStorage extends Storage implements Storage {
|
|
3
|
-
private
|
|
3
|
+
#private;
|
|
4
4
|
constructor(prefix: string);
|
|
5
|
+
get prefix(): string;
|
|
6
|
+
branch(id: string): StorageLocalStorage;
|
|
5
7
|
init(): void;
|
|
8
|
+
get supportsFiles(): boolean;
|
|
6
9
|
get<T>(key_: readonly StorageKeyPart[]): T | null;
|
|
7
10
|
getMany<T>(filter: GetManyFilter, params?: {
|
|
8
11
|
limit?: number;
|
|
@@ -1,3 +1,15 @@
|
|
|
1
|
+
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
2
|
+
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
3
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
4
|
+
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");
|
|
5
|
+
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
6
|
+
};
|
|
7
|
+
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
8
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
9
|
+
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");
|
|
10
|
+
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
11
|
+
};
|
|
12
|
+
var _StorageLocalStorage_prefix;
|
|
1
13
|
import { Storage } from "./0_storage.js";
|
|
2
14
|
import { fromString, isInRange, toString } from "./0_utilities.js";
|
|
3
15
|
export class StorageLocalStorage extends Storage {
|
|
@@ -12,15 +24,20 @@ export class StorageLocalStorage extends Storage {
|
|
|
12
24
|
throw new Error("Unallowed prefix");
|
|
13
25
|
}
|
|
14
26
|
super();
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
27
|
+
_StorageLocalStorage_prefix.set(this, void 0);
|
|
28
|
+
__classPrivateFieldSet(this, _StorageLocalStorage_prefix, prefix, "f");
|
|
29
|
+
}
|
|
30
|
+
get prefix() {
|
|
31
|
+
return __classPrivateFieldGet(this, _StorageLocalStorage_prefix, "f");
|
|
32
|
+
}
|
|
33
|
+
branch(id) {
|
|
34
|
+
return new StorageLocalStorage(this.prefix + "S__" + id);
|
|
21
35
|
}
|
|
22
36
|
init() {
|
|
23
37
|
}
|
|
38
|
+
get supportsFiles() {
|
|
39
|
+
return false;
|
|
40
|
+
}
|
|
24
41
|
get(key_) {
|
|
25
42
|
const key = this.prefix + toString(key_);
|
|
26
43
|
const value = localStorage.getItem(key);
|
|
@@ -74,3 +91,4 @@ export class StorageLocalStorage extends Storage {
|
|
|
74
91
|
this.set(key, (this.get(key) || 0) + by);
|
|
75
92
|
}
|
|
76
93
|
}
|
|
94
|
+
_StorageLocalStorage_prefix = new WeakMap();
|
|
@@ -4,6 +4,8 @@ export declare class StorageMemory extends Storage implements Storage {
|
|
|
4
4
|
#private;
|
|
5
5
|
protected map: Map<string, unknown>;
|
|
6
6
|
init(): void;
|
|
7
|
+
branch(id: string): Storage;
|
|
8
|
+
get supportsFiles(): boolean;
|
|
7
9
|
get<T>(key: readonly StorageKeyPart[]): NonNullable<T> | null;
|
|
8
10
|
getMany<T>(filter: GetManyFilter, params?: {
|
|
9
11
|
limit?: number;
|
|
@@ -3,7 +3,13 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
|
|
|
3
3
|
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");
|
|
4
4
|
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
5
5
|
};
|
|
6
|
-
var
|
|
6
|
+
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
7
|
+
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
8
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
9
|
+
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");
|
|
10
|
+
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
11
|
+
};
|
|
12
|
+
var _StorageMemory_instances, _StorageMemory_id, _StorageMemory_fixKey, _StorageMemory_getEntries;
|
|
7
13
|
import { Storage } from "./0_storage.js";
|
|
8
14
|
import { fromString, isInRange, toString } from "./0_utilities.js";
|
|
9
15
|
export class StorageMemory extends Storage {
|
|
@@ -16,10 +22,20 @@ export class StorageMemory extends Storage {
|
|
|
16
22
|
writable: true,
|
|
17
23
|
value: new Map()
|
|
18
24
|
});
|
|
25
|
+
_StorageMemory_id.set(this, null);
|
|
19
26
|
}
|
|
20
27
|
init() {
|
|
21
28
|
}
|
|
29
|
+
branch(id) {
|
|
30
|
+
const storage = new StorageMemory();
|
|
31
|
+
__classPrivateFieldSet(storage, _StorageMemory_id, id, "f");
|
|
32
|
+
return storage;
|
|
33
|
+
}
|
|
34
|
+
get supportsFiles() {
|
|
35
|
+
return false;
|
|
36
|
+
}
|
|
22
37
|
get(key) {
|
|
38
|
+
key = __classPrivateFieldGet(this, _StorageMemory_instances, "m", _StorageMemory_fixKey).call(this, key);
|
|
23
39
|
return this.map.get(toString(key)) ?? null;
|
|
24
40
|
}
|
|
25
41
|
*getMany(filter, params) {
|
|
@@ -50,6 +66,7 @@ export class StorageMemory extends Storage {
|
|
|
50
66
|
}
|
|
51
67
|
}
|
|
52
68
|
set(key_, value) {
|
|
69
|
+
key_ = __classPrivateFieldGet(this, _StorageMemory_instances, "m", _StorageMemory_fixKey).call(this, key_);
|
|
53
70
|
const key = toString(key_);
|
|
54
71
|
if (value != null) {
|
|
55
72
|
this.map.set(key, value);
|
|
@@ -62,9 +79,19 @@ export class StorageMemory extends Storage {
|
|
|
62
79
|
this.set(key, (this.get(key) || 0) + by);
|
|
63
80
|
}
|
|
64
81
|
}
|
|
65
|
-
_StorageMemory_instances = new WeakSet(),
|
|
82
|
+
_StorageMemory_id = new WeakMap(), _StorageMemory_instances = new WeakSet(), _StorageMemory_fixKey = function _StorageMemory_fixKey(key) {
|
|
83
|
+
if (__classPrivateFieldGet(this, _StorageMemory_id, "f") !== null) {
|
|
84
|
+
return ["__S" + __classPrivateFieldGet(this, _StorageMemory_id, "f"), ...key];
|
|
85
|
+
}
|
|
86
|
+
else {
|
|
87
|
+
return key;
|
|
88
|
+
}
|
|
89
|
+
}, _StorageMemory_getEntries = function _StorageMemory_getEntries() {
|
|
66
90
|
const entries = new Array();
|
|
67
91
|
for (const entry of this.map.entries()) {
|
|
92
|
+
if (__classPrivateFieldGet(this, _StorageMemory_id, "f") !== null && !entry[0].startsWith("__S" + __classPrivateFieldGet(this, _StorageMemory_id, "f"))) {
|
|
93
|
+
continue;
|
|
94
|
+
}
|
|
68
95
|
entries.push(entry);
|
|
69
96
|
}
|
|
70
97
|
return entries;
|