@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
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
import { MaybePromise } from "../1_utilities.js";
|
|
2
2
|
import { GetManyFilter, Storage, StorageKeyPart } from "./0_storage.js";
|
|
3
3
|
export declare class StorageSessionStorage extends Storage implements Storage {
|
|
4
|
-
private
|
|
4
|
+
#private;
|
|
5
5
|
constructor(prefix: string);
|
|
6
|
+
get prefix(): string;
|
|
7
|
+
branch(id: string): StorageSessionStorage;
|
|
6
8
|
init(): void;
|
|
9
|
+
get supportsFiles(): boolean;
|
|
7
10
|
get<T>(key_: readonly StorageKeyPart[]): T | null;
|
|
8
11
|
getMany<T>(filter: GetManyFilter, params?: {
|
|
9
12
|
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 _StorageSessionStorage_prefix;
|
|
1
13
|
import { Storage } from "./0_storage.js";
|
|
2
14
|
import { fromString, isInRange, toString } from "./0_utilities.js";
|
|
3
15
|
export class StorageSessionStorage extends Storage {
|
|
@@ -12,15 +24,20 @@ export class StorageSessionStorage extends Storage {
|
|
|
12
24
|
throw new Error("Unallowed prefix");
|
|
13
25
|
}
|
|
14
26
|
super();
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
27
|
+
_StorageSessionStorage_prefix.set(this, void 0);
|
|
28
|
+
__classPrivateFieldSet(this, _StorageSessionStorage_prefix, prefix, "f");
|
|
29
|
+
}
|
|
30
|
+
get prefix() {
|
|
31
|
+
return __classPrivateFieldGet(this, _StorageSessionStorage_prefix, "f");
|
|
32
|
+
}
|
|
33
|
+
branch(id) {
|
|
34
|
+
return new StorageSessionStorage(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 = sessionStorage.getItem(key);
|
|
@@ -74,3 +91,4 @@ export class StorageSessionStorage extends Storage {
|
|
|
74
91
|
this.set(key, (this.get(key) || 0) + by);
|
|
75
92
|
}
|
|
76
93
|
}
|
|
94
|
+
_StorageSessionStorage_prefix = new WeakMap();
|
|
@@ -3,8 +3,8 @@ import { types } from "../2_tl.js";
|
|
|
3
3
|
import { ChatID } from "./0_chat_id.js";
|
|
4
4
|
export interface EntityGetter {
|
|
5
5
|
(peer: types.PeerUser): MaybePromise<types.User | null>;
|
|
6
|
-
(peer: types.PeerChat): MaybePromise<types.Chat | null>;
|
|
7
|
-
(peer: types.PeerChannel): MaybePromise<types.Channel | null>;
|
|
6
|
+
(peer: types.PeerChat): MaybePromise<types.Chat | types.ChatForbidden | null>;
|
|
7
|
+
(peer: types.PeerChannel): MaybePromise<types.Channel | types.ChannelForbidden | null>;
|
|
8
8
|
}
|
|
9
9
|
export interface InputPeerGetter {
|
|
10
10
|
(id: ChatID): Promise<types.InputPeerUser | types.InputPeerChannel | types.InputPeerChat>;
|
package/esm/types/1_chat_p.d.ts
CHANGED
|
@@ -68,5 +68,5 @@ export declare namespace ChatP {
|
|
|
68
68
|
/** This object represents a chat. */
|
|
69
69
|
export type ChatP = ChatP.Private | ChatP.Group | ChatP.Supergroup | ChatP.Channel;
|
|
70
70
|
export declare function constructChatP(chat: types.User): ChatP.Private;
|
|
71
|
-
export declare function constructChatP(chat: types.Chat): ChatP.Group;
|
|
72
|
-
export declare function constructChatP(chat: types.Channel): ChatP.Supergroup | ChatP.Channel;
|
|
71
|
+
export declare function constructChatP(chat: types.Chat | types.ChatForbidden): ChatP.Group;
|
|
72
|
+
export declare function constructChatP(chat: types.Channel | types.ChannelForbidden): ChatP.Supergroup | ChatP.Channel;
|
package/esm/types/1_chat_p.js
CHANGED
|
@@ -22,21 +22,33 @@ export function constructChatP(chat) {
|
|
|
22
22
|
}
|
|
23
23
|
return cleanObject(chat_);
|
|
24
24
|
}
|
|
25
|
-
else if (chat instanceof types.Chat) {
|
|
25
|
+
else if (chat instanceof types.Chat || chat instanceof types.ChatForbidden) {
|
|
26
26
|
const id = Number(-chat.id);
|
|
27
27
|
const chat_ = {
|
|
28
28
|
id,
|
|
29
29
|
type: "group",
|
|
30
30
|
color: getColorFromPeerId(id),
|
|
31
31
|
title: chat.title,
|
|
32
|
-
isCreator:
|
|
32
|
+
isCreator: false,
|
|
33
33
|
};
|
|
34
|
+
if (chat instanceof types.Chat) {
|
|
35
|
+
chat_.isCreator = chat.creator || false;
|
|
36
|
+
}
|
|
34
37
|
return cleanObject(chat_);
|
|
35
38
|
}
|
|
36
|
-
else if (chat instanceof types.Channel) {
|
|
39
|
+
else if (chat instanceof types.Channel || types.ChannelForbidden) {
|
|
37
40
|
let chat_;
|
|
38
|
-
const { title, scam: isScam = false, fake: isFake = false, verified: isVerified = false, restricted: isRestricted = false, } = chat;
|
|
39
41
|
const id = ZERO_CHANNEL_ID + -Number(chat.id);
|
|
42
|
+
if (chat instanceof types.ChannelForbidden) {
|
|
43
|
+
const { title } = chat;
|
|
44
|
+
if (chat.megagroup) {
|
|
45
|
+
return { id, color: getColorFromPeerId(id), title, type: "supergroup", isScam: false, isFake: false, isVerified: false, isRestricted: false, isForum: false };
|
|
46
|
+
}
|
|
47
|
+
else {
|
|
48
|
+
return { id, color: getColorFromPeerId(id), title, type: "channel", isScam: false, isFake: false, isVerified: false, isRestricted: false };
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
const { title, scam: isScam = false, fake: isFake = false, verified: isVerified = false, restricted: isRestricted = false, } = chat;
|
|
40
52
|
if (chat.megagroup) {
|
|
41
53
|
chat_ = {
|
|
42
54
|
id,
|
package/package.json
CHANGED
package/script/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/script/4_constants.js
CHANGED
|
@@ -79,7 +79,7 @@ exports.PUBLIC_KEYS = Object.freeze([
|
|
|
79
79
|
]);
|
|
80
80
|
exports.INITIAL_DC = "2";
|
|
81
81
|
exports.LAYER = 167;
|
|
82
|
-
exports.APP_VERSION = "MTKruto 0.1.
|
|
82
|
+
exports.APP_VERSION = "MTKruto 0.1.129";
|
|
83
83
|
// @ts-ignore: lib
|
|
84
84
|
exports.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;
|
|
85
85
|
exports.LANG_CODE = typeof navigator === "undefined" ? "en" : navigator.language.split("-")[0];
|
|
@@ -10,7 +10,7 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
|
|
|
10
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
11
|
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
12
12
|
};
|
|
13
|
-
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;
|
|
13
|
+
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;
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
15
|
exports.Client = exports.ConnectionError = exports.restartAuth = exports.skipInvoke = exports.handleMigrationError = void 0;
|
|
16
16
|
const _0_deps_js_1 = require("../0_deps.js");
|
|
@@ -1001,6 +1001,9 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
|
|
|
1001
1001
|
else if (chat instanceof _2_tl_js_1.types.Chat) {
|
|
1002
1002
|
await this.storage.setEntity(chat);
|
|
1003
1003
|
}
|
|
1004
|
+
else if (chat instanceof _2_tl_js_1.types.ChannelForbidden || chat instanceof _2_tl_js_1.types.ChatForbidden) {
|
|
1005
|
+
await this.storage.removeEntity(chat);
|
|
1006
|
+
}
|
|
1004
1007
|
}
|
|
1005
1008
|
}, _Client_processUsers = async function _Client_processUsers(users) {
|
|
1006
1009
|
for (const user of users) {
|
|
@@ -1157,6 +1160,14 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
|
|
|
1157
1160
|
}
|
|
1158
1161
|
else if (update instanceof _2_tl_js_1.types.UpdateUserName) {
|
|
1159
1162
|
await this.storage.updateUsernames("user", update.user_id, update.usernames.map((v) => v.username));
|
|
1163
|
+
const peer = new _2_tl_js_1.types.PeerUser(update);
|
|
1164
|
+
const entity = await this[getEntity](peer);
|
|
1165
|
+
if (entity != null) {
|
|
1166
|
+
entity.usernames = update.usernames;
|
|
1167
|
+
entity.first_name = update.first_name;
|
|
1168
|
+
entity.last_name = update.last_name;
|
|
1169
|
+
await this.storage.setEntity(entity);
|
|
1170
|
+
}
|
|
1160
1171
|
}
|
|
1161
1172
|
else if (update instanceof _2_tl_js_1.types.UpdatePtsChanged) {
|
|
1162
1173
|
await __classPrivateFieldGet(this, _Client_instances, "m", _Client_fetchState).call(this, "updatePtsChanged");
|
|
@@ -1183,7 +1194,7 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
|
|
|
1183
1194
|
}
|
|
1184
1195
|
}
|
|
1185
1196
|
/// If there were any Update, they will be passed to the update handling queue.
|
|
1186
|
-
if (update instanceof _2_tl_js_1.types._Update) {
|
|
1197
|
+
if (update instanceof _2_tl_js_1.types._Update || update instanceof _2_tl_js_1.types.UpdateShortMessage || update instanceof _2_tl_js_1.types.UpdateShortChatMessage || update instanceof _2_tl_js_1.types.UpdateShortSentMessage) {
|
|
1187
1198
|
updatesToHandle.push(update);
|
|
1188
1199
|
}
|
|
1189
1200
|
}
|
|
@@ -1650,12 +1661,21 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
|
|
|
1650
1661
|
}
|
|
1651
1662
|
}
|
|
1652
1663
|
async [(_Client_downloadInner = async function* _Client_downloadInner(location, dcId, params) {
|
|
1664
|
+
const id = "id" in location ? location.id : "photo_id" in location ? location.photo_id : null;
|
|
1665
|
+
if (id != null) {
|
|
1666
|
+
const partCount = await this.storage.getFile(id);
|
|
1667
|
+
if (partCount != null && partCount > 0) {
|
|
1668
|
+
for await (const part of this.storage.iterFileParts(id, partCount)) {
|
|
1669
|
+
yield part;
|
|
1670
|
+
}
|
|
1671
|
+
return;
|
|
1672
|
+
}
|
|
1673
|
+
}
|
|
1653
1674
|
const chunkSize = params?.chunkSize ?? 1024 * 1024;
|
|
1654
1675
|
if ((0, _1_utilities_js_1.mod)(chunkSize, 1024) != 0) {
|
|
1655
1676
|
throw new Error("chunkSize must be divisible by 1024");
|
|
1656
1677
|
}
|
|
1657
|
-
const
|
|
1658
|
-
const client = new _a(new _3_storage_js_1.StorageMemory(), this.apiId, this.apiHash, {
|
|
1678
|
+
const client = new _a(dcId == this.dcId ? this.storage : this.storage.branch(`download_client_${dcId}`), this.apiId, this.apiHash, {
|
|
1659
1679
|
transportProvider: this.transportProvider,
|
|
1660
1680
|
appVersion: this.appVersion,
|
|
1661
1681
|
deviceModel: this.deviceModel,
|
|
@@ -1671,14 +1691,37 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
|
|
|
1671
1691
|
}
|
|
1672
1692
|
await client.setDc(dc);
|
|
1673
1693
|
await client.connect();
|
|
1674
|
-
await client.
|
|
1694
|
+
await __classPrivateFieldGet(client, _Client_instances, "m", _Client_initConnection).call(client);
|
|
1695
|
+
client.invoke.use(async (ctx, next) => {
|
|
1696
|
+
if (ctx.error instanceof _4_errors_js_1.AuthKeyUnregistered) {
|
|
1697
|
+
try {
|
|
1698
|
+
const exportedAuth = await this.invoke(new _2_tl_js_1.functions.auth.exportAuthorization({ dc_id: dcId }));
|
|
1699
|
+
await client.authorize(exportedAuth);
|
|
1700
|
+
return true;
|
|
1701
|
+
}
|
|
1702
|
+
catch (err) {
|
|
1703
|
+
throw err;
|
|
1704
|
+
}
|
|
1705
|
+
}
|
|
1706
|
+
else {
|
|
1707
|
+
return await next();
|
|
1708
|
+
}
|
|
1709
|
+
});
|
|
1675
1710
|
const limit = chunkSize;
|
|
1676
1711
|
let offset = 0n;
|
|
1712
|
+
let part = 0;
|
|
1677
1713
|
while (true) {
|
|
1678
1714
|
const file = await (client ?? this).invoke(new _2_tl_js_1.functions.upload.getFile({ location, offset, limit }));
|
|
1679
1715
|
if (file instanceof _2_tl_js_1.types.upload.File) {
|
|
1680
1716
|
yield file.bytes;
|
|
1717
|
+
if (id != null) {
|
|
1718
|
+
await this.storage.saveFilePart(id, part, file.bytes);
|
|
1719
|
+
}
|
|
1720
|
+
++part;
|
|
1681
1721
|
if (file.bytes.length < limit) {
|
|
1722
|
+
if (id != null) {
|
|
1723
|
+
await this.storage.setFilePartCount(id, part + 1);
|
|
1724
|
+
}
|
|
1682
1725
|
break;
|
|
1683
1726
|
}
|
|
1684
1727
|
else {
|
|
@@ -2320,7 +2363,9 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
|
|
|
2320
2363
|
}
|
|
2321
2364
|
if (messages.length < limit) {
|
|
2322
2365
|
d("have only %d messages but need %d more", messages.length, limit - messages.length);
|
|
2323
|
-
|
|
2366
|
+
if (messages.length > 0) {
|
|
2367
|
+
offsetId = messages[messages.length - 1].id; // TODO: track id of oldest message and don't send requests for it
|
|
2368
|
+
}
|
|
2324
2369
|
const result = await this.api.messages.getHistory({
|
|
2325
2370
|
peer: peer,
|
|
2326
2371
|
offset_id: offsetId,
|
|
@@ -2364,7 +2409,7 @@ async function _Client_handleUpdate(update) {
|
|
|
2364
2409
|
silent: update.silent,
|
|
2365
2410
|
id: update.id,
|
|
2366
2411
|
from_id: update.out ? new _2_tl_js_1.types.PeerUser({ user_id: await __classPrivateFieldGet(this, _Client_instances, "m", _Client_getSelfId).call(this).then(BigInt) }) : new _2_tl_js_1.types.PeerUser({ user_id: update.user_id }),
|
|
2367
|
-
peer_id: new _2_tl_js_1.types.
|
|
2412
|
+
peer_id: new _2_tl_js_1.types.PeerUser({ user_id: update.user_id }),
|
|
2368
2413
|
message: update.message,
|
|
2369
2414
|
date: update.date,
|
|
2370
2415
|
fwd_from: update.fwd_from,
|
|
@@ -2467,6 +2512,39 @@ async function _Client_handleUpdate(update) {
|
|
|
2467
2512
|
if (update instanceof _2_tl_js_1.types.UpdatePinnedDialogs) {
|
|
2468
2513
|
await __classPrivateFieldGet(this, _Client_instances, "m", _Client_updatePinnedChats).call(this, update);
|
|
2469
2514
|
}
|
|
2515
|
+
if (update instanceof _2_tl_js_1.types.UpdateChannel) {
|
|
2516
|
+
const peer = new _2_tl_js_1.types.PeerChannel(update);
|
|
2517
|
+
const channel = await this[getEntity](peer);
|
|
2518
|
+
if (channel != null && "left" in channel && channel.left) {
|
|
2519
|
+
await __classPrivateFieldGet(this, _Client_instances, "m", _Client_removeChat).call(this, (0, _2_tl_js_1.peerToChatId)(peer));
|
|
2520
|
+
}
|
|
2521
|
+
else if (channel instanceof _2_tl_js_1.types.ChannelForbidden) {
|
|
2522
|
+
await __classPrivateFieldGet(this, _Client_instances, "m", _Client_removeChat).call(this, (0, _2_tl_js_1.peerToChatId)(peer));
|
|
2523
|
+
}
|
|
2524
|
+
else if (channel instanceof _2_tl_js_1.types.Channel) {
|
|
2525
|
+
await __classPrivateFieldGet(this, _Client_instances, "m", _Client_updateOrAddChat).call(this, (0, _2_tl_js_1.peerToChatId)(peer));
|
|
2526
|
+
}
|
|
2527
|
+
}
|
|
2528
|
+
else if (update instanceof _2_tl_js_1.types.UpdateChat) { // TODO: handle deactivated (migration)
|
|
2529
|
+
const peer = new _2_tl_js_1.types.PeerChat(update);
|
|
2530
|
+
const chat = await this[getEntity](peer);
|
|
2531
|
+
if (chat != null && "left" in chat && chat.left) {
|
|
2532
|
+
await __classPrivateFieldGet(this, _Client_instances, "m", _Client_removeChat).call(this, (0, _2_tl_js_1.peerToChatId)(peer));
|
|
2533
|
+
}
|
|
2534
|
+
else if (chat instanceof _2_tl_js_1.types.ChatForbidden) {
|
|
2535
|
+
await __classPrivateFieldGet(this, _Client_instances, "m", _Client_removeChat).call(this, (0, _2_tl_js_1.peerToChatId)(peer));
|
|
2536
|
+
}
|
|
2537
|
+
else if (chat instanceof _2_tl_js_1.types.Chat) {
|
|
2538
|
+
await __classPrivateFieldGet(this, _Client_instances, "m", _Client_updateOrAddChat).call(this, (0, _2_tl_js_1.peerToChatId)(peer));
|
|
2539
|
+
}
|
|
2540
|
+
}
|
|
2541
|
+
else if (update instanceof _2_tl_js_1.types.UpdateUser || update instanceof _2_tl_js_1.types.UpdateUserName) {
|
|
2542
|
+
const peer = new _2_tl_js_1.types.PeerUser(update);
|
|
2543
|
+
const chat = await this[getEntity](peer);
|
|
2544
|
+
if (chat != null) {
|
|
2545
|
+
await __classPrivateFieldGet(this, _Client_instances, "m", _Client_updateOrAddChat).call(this, (0, _2_tl_js_1.peerToChatId)(peer));
|
|
2546
|
+
}
|
|
2547
|
+
}
|
|
2470
2548
|
}, _Client_constructReplyMarkup = async function _Client_constructReplyMarkup(params) {
|
|
2471
2549
|
if (params?.replyMarkup) {
|
|
2472
2550
|
await __classPrivateFieldGet(this, _Client_instances, "m", _Client_assertBot).call(this, "replyMarkup");
|
|
@@ -2538,12 +2616,12 @@ async function _Client_setMyInfo(info) {
|
|
|
2538
2616
|
catch {
|
|
2539
2617
|
return;
|
|
2540
2618
|
}
|
|
2541
|
-
const chat = __classPrivateFieldGet(this,
|
|
2619
|
+
const [chat] = __classPrivateFieldGet(this, _Client_instances, "m", _Client_getChatAnywhere).call(this, chatId);
|
|
2542
2620
|
const update = chat === undefined ? { deletedChat: { chatId } } : added ? { newChat: chat } : { editedChat: chat };
|
|
2543
2621
|
__classPrivateFieldGet(this, _Client_handleUpdateQueue, "f").add(async () => {
|
|
2544
2622
|
await __classPrivateFieldGet(this, _Client_handle, "f").call(this, await __classPrivateFieldGet(this, _Client_constructContext, "f").call(this, update), _0_utilities_js_1.resolve);
|
|
2545
2623
|
});
|
|
2546
|
-
}, _Client_reassignChatLastMessage = async function _Client_reassignChatLastMessage(chatId, add = false) {
|
|
2624
|
+
}, _Client_reassignChatLastMessage = async function _Client_reassignChatLastMessage(chatId, add = false, sendUpdate = true) {
|
|
2547
2625
|
try {
|
|
2548
2626
|
await __classPrivateFieldGet(this, _Client_instances, "m", _Client_assertUser).call(this, "");
|
|
2549
2627
|
}
|
|
@@ -2571,7 +2649,9 @@ async function _Client_setMyInfo(info) {
|
|
|
2571
2649
|
__classPrivateFieldGet(this, _Client_chats, "f").set(chatId, chat);
|
|
2572
2650
|
await this.storage.setChat(listId, chatId, chat.pinned, chat.lastMessage?.id ?? 0, chat.lastMessage?.date ?? new Date(0));
|
|
2573
2651
|
}
|
|
2574
|
-
|
|
2652
|
+
if (sendUpdate) {
|
|
2653
|
+
await __classPrivateFieldGet(this, _Client_instances, "m", _Client_sendChatUpdate).call(this, chatId, !chat);
|
|
2654
|
+
}
|
|
2575
2655
|
return;
|
|
2576
2656
|
}
|
|
2577
2657
|
const message = await this.getHistory(chatId, { limit: 1 }).then((v) => v[0]);
|
|
@@ -2589,13 +2669,17 @@ async function _Client_setMyInfo(info) {
|
|
|
2589
2669
|
}
|
|
2590
2670
|
__classPrivateFieldGet(this, _Client_chats, "f").set(chatId, chat);
|
|
2591
2671
|
}
|
|
2592
|
-
|
|
2672
|
+
if (sendUpdate) {
|
|
2673
|
+
await __classPrivateFieldGet(this, _Client_instances, "m", _Client_sendChatUpdate).call(this, chatId, !chat);
|
|
2674
|
+
}
|
|
2593
2675
|
return;
|
|
2594
2676
|
}
|
|
2595
2677
|
if (chat) {
|
|
2596
2678
|
chat.order = (0, _3_types_js_1.getChatOrder)(undefined, chat.pinned);
|
|
2597
2679
|
chat.lastMessage = undefined;
|
|
2598
|
-
|
|
2680
|
+
if (sendUpdate) {
|
|
2681
|
+
await __classPrivateFieldGet(this, _Client_instances, "m", _Client_sendChatUpdate).call(this, chatId, false);
|
|
2682
|
+
}
|
|
2599
2683
|
}
|
|
2600
2684
|
}, _Client_getChatAnywhere = function _Client_getChatAnywhere(chatId) {
|
|
2601
2685
|
let chat = __classPrivateFieldGet(this, _Client_chats, "f").get(chatId);
|
|
@@ -2688,6 +2772,29 @@ async function _Client_setMyInfo(info) {
|
|
|
2688
2772
|
default:
|
|
2689
2773
|
(0, _1_utilities_js_1.UNREACHABLE)();
|
|
2690
2774
|
}
|
|
2775
|
+
}, _Client_updateOrAddChat = async function _Client_updateOrAddChat(chatId) {
|
|
2776
|
+
const [chat, listId] = __classPrivateFieldGet(this, _Client_instances, "m", _Client_getChatAnywhere).call(this, chatId);
|
|
2777
|
+
if (chat !== undefined) {
|
|
2778
|
+
const newChat = await (0, _3_types_js_1.constructChat2)(chatId, chat.pinned, chat.lastMessage, this[getEntity].bind(this));
|
|
2779
|
+
if (newChat != null) {
|
|
2780
|
+
__classPrivateFieldGet(this, _Client_instances, "m", _Client_getChatList).call(this, listId).set(chatId, newChat);
|
|
2781
|
+
await __classPrivateFieldGet(this, _Client_instances, "m", _Client_sendChatUpdate).call(this, chatId, false);
|
|
2782
|
+
}
|
|
2783
|
+
}
|
|
2784
|
+
else {
|
|
2785
|
+
const chat = await (0, _3_types_js_1.constructChat3)(chatId, -1, -1, this[getEntity].bind(this), this.getMessage.bind(this));
|
|
2786
|
+
if (chat != null) {
|
|
2787
|
+
__classPrivateFieldGet(this, _Client_instances, "m", _Client_getChatList).call(this, 0).set(chatId, chat);
|
|
2788
|
+
await __classPrivateFieldGet(this, _Client_instances, "m", _Client_reassignChatLastMessage).call(this, chatId, false, false);
|
|
2789
|
+
await __classPrivateFieldGet(this, _Client_instances, "m", _Client_sendChatUpdate).call(this, chatId, true);
|
|
2790
|
+
}
|
|
2791
|
+
}
|
|
2792
|
+
}, _Client_removeChat = async function _Client_removeChat(chatId) {
|
|
2793
|
+
const [chat, listId] = __classPrivateFieldGet(this, _Client_instances, "m", _Client_getChatAnywhere).call(this, chatId);
|
|
2794
|
+
if (chat !== undefined) {
|
|
2795
|
+
__classPrivateFieldGet(this, _Client_instances, "m", _Client_getChatList).call(this, listId).delete(chatId);
|
|
2796
|
+
await __classPrivateFieldGet(this, _Client_instances, "m", _Client_sendChatUpdate).call(this, chatId, false);
|
|
2797
|
+
}
|
|
2691
2798
|
}, _Client_updatePinnedChats = async function _Client_updatePinnedChats(update) {
|
|
2692
2799
|
const listId = update.folder_id ?? 0;
|
|
2693
2800
|
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
|
}
|
|
@@ -10,7 +10,7 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
|
|
|
10
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
11
|
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
12
12
|
};
|
|
13
|
-
var _Storage_instances, _Storage__authKeyId, _Storage_resetAuthKeyId;
|
|
13
|
+
var _Storage_instances, _Storage__authKeyId, _Storage_resetAuthKeyId, _Storage_getEntityType;
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
15
|
exports.Storage = void 0;
|
|
16
16
|
const _1_utilities_js_1 = require("../1_utilities.js");
|
|
@@ -33,6 +33,8 @@ const KPARTS_CHATS = (listId) => ["chats", listId];
|
|
|
33
33
|
const KPARTS_CHAT = (listId, chatId) => ["chats", listId, chatId];
|
|
34
34
|
const KPARTS_PINNED_CHATS = (listId) => ["pinnedChats", listId];
|
|
35
35
|
const KPARTS_SERVER_SALT = ["serverSalt"];
|
|
36
|
+
const KPARTS_FILE = (fileId) => ["files", fileId];
|
|
37
|
+
const KPARTS_FILE_PART = (fileId, n) => ["fileParts", fileId, n];
|
|
36
38
|
class Storage {
|
|
37
39
|
constructor() {
|
|
38
40
|
_Storage_instances.add(this);
|
|
@@ -132,9 +134,13 @@ class Storage {
|
|
|
132
134
|
getChannelPts(channelId) {
|
|
133
135
|
return this.get(KPARTS__CHANNEL_PTS(channelId));
|
|
134
136
|
}
|
|
135
|
-
async setEntity(
|
|
136
|
-
const type =
|
|
137
|
-
await this.set(KPARTS__PEER(type,
|
|
137
|
+
async setEntity(entity) {
|
|
138
|
+
const type = __classPrivateFieldGet(this, _Storage_instances, "m", _Storage_getEntityType).call(this, entity);
|
|
139
|
+
await this.set(KPARTS__PEER(type, entity.id), (0, _1_utilities_js_1.rleEncode)(entity[_2_tl_js_1.serialize]()));
|
|
140
|
+
}
|
|
141
|
+
async removeEntity(entity) {
|
|
142
|
+
const type = __classPrivateFieldGet(this, _Storage_instances, "m", _Storage_getEntityType).call(this, entity);
|
|
143
|
+
await this.set(KPARTS__PEER(type, entity.id), null);
|
|
138
144
|
}
|
|
139
145
|
async getEntity(type, id) {
|
|
140
146
|
const peer_ = await this.get(KPARTS__PEER(type, id));
|
|
@@ -222,6 +228,36 @@ class Storage {
|
|
|
222
228
|
}
|
|
223
229
|
return messages;
|
|
224
230
|
}
|
|
231
|
+
async getFile(id) {
|
|
232
|
+
if (!this.supportsFiles) {
|
|
233
|
+
return null;
|
|
234
|
+
}
|
|
235
|
+
return await this.get(KPARTS_FILE(id));
|
|
236
|
+
}
|
|
237
|
+
async *iterFileParts(id, partCount) {
|
|
238
|
+
if (!this.supportsFiles) {
|
|
239
|
+
return;
|
|
240
|
+
}
|
|
241
|
+
for (let i = 0; i < partCount; i++) {
|
|
242
|
+
const part = await this.get(KPARTS_FILE_PART(id, i));
|
|
243
|
+
if (part == null) {
|
|
244
|
+
continue;
|
|
245
|
+
}
|
|
246
|
+
yield part;
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
async saveFilePart(id, index, bytes) {
|
|
250
|
+
if (!this.supportsFiles) {
|
|
251
|
+
return;
|
|
252
|
+
}
|
|
253
|
+
await this.set(KPARTS_FILE_PART(id, index), bytes);
|
|
254
|
+
}
|
|
255
|
+
async setFilePartCount(id, partCount) {
|
|
256
|
+
if (!this.supportsFiles) {
|
|
257
|
+
return;
|
|
258
|
+
}
|
|
259
|
+
await this.set(KPARTS_FILE(id), partCount);
|
|
260
|
+
}
|
|
225
261
|
}
|
|
226
262
|
exports.Storage = Storage;
|
|
227
263
|
_Storage__authKeyId = new WeakMap(), _Storage_instances = new WeakSet(), _Storage_resetAuthKeyId = async function _Storage_resetAuthKeyId(authKey) {
|
|
@@ -231,4 +267,17 @@ _Storage__authKeyId = new WeakMap(), _Storage_instances = new WeakSet(), _Storag
|
|
|
231
267
|
else {
|
|
232
268
|
__classPrivateFieldSet(this, _Storage__authKeyId, null, "f");
|
|
233
269
|
}
|
|
270
|
+
}, _Storage_getEntityType = function _Storage_getEntityType(entity) {
|
|
271
|
+
if (entity instanceof _2_tl_js_1.types.Channel || entity instanceof _2_tl_js_1.types.ChannelForbidden) {
|
|
272
|
+
return "channel";
|
|
273
|
+
}
|
|
274
|
+
else if (entity instanceof _2_tl_js_1.types.Chat || entity instanceof _2_tl_js_1.types.ChatForbidden) {
|
|
275
|
+
return "chat";
|
|
276
|
+
}
|
|
277
|
+
else if (entity instanceof _2_tl_js_1.types.User) {
|
|
278
|
+
return "user";
|
|
279
|
+
}
|
|
280
|
+
else {
|
|
281
|
+
(0, _1_utilities_js_1.UNREACHABLE)();
|
|
282
|
+
}
|
|
234
283
|
};
|
|
@@ -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,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 _StorageIndexedDB_instances, _StorageIndexedDB_name, _StorageIndexedDB_id, _StorageIndexedDB_fixKey;
|
|
2
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
15
|
exports.StorageIndexedDB = void 0;
|
|
4
16
|
const _0_storage_js_1 = require("./0_storage.js");
|
|
@@ -11,18 +23,24 @@ class StorageIndexedDB extends _0_storage_js_1.Storage {
|
|
|
11
23
|
throw new Error("Unavailable in current environment");
|
|
12
24
|
}
|
|
13
25
|
super();
|
|
14
|
-
|
|
15
|
-
enumerable: true,
|
|
16
|
-
configurable: true,
|
|
17
|
-
writable: true,
|
|
18
|
-
value: name
|
|
19
|
-
});
|
|
26
|
+
_StorageIndexedDB_instances.add(this);
|
|
20
27
|
Object.defineProperty(this, "database", {
|
|
21
28
|
enumerable: true,
|
|
22
29
|
configurable: true,
|
|
23
30
|
writable: true,
|
|
24
31
|
value: null
|
|
25
32
|
});
|
|
33
|
+
_StorageIndexedDB_name.set(this, void 0);
|
|
34
|
+
_StorageIndexedDB_id.set(this, null);
|
|
35
|
+
__classPrivateFieldSet(this, _StorageIndexedDB_name, name, "f");
|
|
36
|
+
}
|
|
37
|
+
get name() {
|
|
38
|
+
return __classPrivateFieldGet(this, _StorageIndexedDB_name, "f");
|
|
39
|
+
}
|
|
40
|
+
branch(id) {
|
|
41
|
+
const storage = new StorageIndexedDB(this.name);
|
|
42
|
+
__classPrivateFieldSet(storage, _StorageIndexedDB_id, id, "f");
|
|
43
|
+
return storage;
|
|
26
44
|
}
|
|
27
45
|
init() {
|
|
28
46
|
const db = indexedDB.open(this.name, VERSION);
|
|
@@ -38,7 +56,11 @@ class StorageIndexedDB extends _0_storage_js_1.Storage {
|
|
|
38
56
|
};
|
|
39
57
|
});
|
|
40
58
|
}
|
|
59
|
+
get supportsFiles() {
|
|
60
|
+
return true;
|
|
61
|
+
}
|
|
41
62
|
set(k, v, tx_) {
|
|
63
|
+
k = __classPrivateFieldGet(this, _StorageIndexedDB_instances, "m", _StorageIndexedDB_fixKey).call(this, k);
|
|
42
64
|
if (!this.database) {
|
|
43
65
|
throw new Error("Not initialized");
|
|
44
66
|
}
|
|
@@ -60,7 +82,10 @@ class StorageIndexedDB extends _0_storage_js_1.Storage {
|
|
|
60
82
|
};
|
|
61
83
|
});
|
|
62
84
|
}
|
|
63
|
-
get(k, tx_) {
|
|
85
|
+
get(k, tx_, fix = true) {
|
|
86
|
+
if (fix) {
|
|
87
|
+
k = __classPrivateFieldGet(this, _StorageIndexedDB_instances, "m", _StorageIndexedDB_fixKey).call(this, k);
|
|
88
|
+
}
|
|
64
89
|
if (!this.database) {
|
|
65
90
|
throw new Error("Not initialized");
|
|
66
91
|
}
|
|
@@ -76,6 +101,15 @@ class StorageIndexedDB extends _0_storage_js_1.Storage {
|
|
|
76
101
|
});
|
|
77
102
|
}
|
|
78
103
|
async *getMany(filter, params, tx_) {
|
|
104
|
+
if ("prefix" in filter && __classPrivateFieldGet(this, _StorageIndexedDB_id, "f") !== null) {
|
|
105
|
+
filter.prefix = __classPrivateFieldGet(this, _StorageIndexedDB_instances, "m", _StorageIndexedDB_fixKey).call(this, filter.prefix);
|
|
106
|
+
}
|
|
107
|
+
if ("start" in filter && __classPrivateFieldGet(this, _StorageIndexedDB_id, "f") !== null) {
|
|
108
|
+
filter.start = __classPrivateFieldGet(this, _StorageIndexedDB_instances, "m", _StorageIndexedDB_fixKey).call(this, filter.start);
|
|
109
|
+
}
|
|
110
|
+
if ("end" in filter && __classPrivateFieldGet(this, _StorageIndexedDB_id, "f") !== null) {
|
|
111
|
+
filter.end = __classPrivateFieldGet(this, _StorageIndexedDB_instances, "m", _StorageIndexedDB_fixKey).call(this, filter.end);
|
|
112
|
+
}
|
|
79
113
|
if (!this.database) {
|
|
80
114
|
throw new Error("Not initialized");
|
|
81
115
|
}
|
|
@@ -111,7 +145,7 @@ class StorageIndexedDB extends _0_storage_js_1.Storage {
|
|
|
111
145
|
};
|
|
112
146
|
});
|
|
113
147
|
for (const key of keys) {
|
|
114
|
-
yield [key, await this.get(key)];
|
|
148
|
+
yield [key, await this.get(key, null, false)];
|
|
115
149
|
}
|
|
116
150
|
}
|
|
117
151
|
async incr(key, by) {
|
|
@@ -125,3 +159,11 @@ class StorageIndexedDB extends _0_storage_js_1.Storage {
|
|
|
125
159
|
}
|
|
126
160
|
}
|
|
127
161
|
exports.StorageIndexedDB = StorageIndexedDB;
|
|
162
|
+
_StorageIndexedDB_name = new WeakMap(), _StorageIndexedDB_id = new WeakMap(), _StorageIndexedDB_instances = new WeakSet(), _StorageIndexedDB_fixKey = function _StorageIndexedDB_fixKey(key) {
|
|
163
|
+
if (__classPrivateFieldGet(this, _StorageIndexedDB_id, "f") !== null) {
|
|
164
|
+
return ["__S" + __classPrivateFieldGet(this, _StorageIndexedDB_id, "f"), ...key];
|
|
165
|
+
}
|
|
166
|
+
else {
|
|
167
|
+
return key;
|
|
168
|
+
}
|
|
169
|
+
};
|