2020-08-05 22:08:55 +05:30
|
|
|
/*
|
|
|
|
Copyright 2020 Bruno Windels <bruno@windels.cloud>
|
|
|
|
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
you may not use this file except in compliance with the License.
|
|
|
|
You may obtain a copy of the License at
|
|
|
|
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
See the License for the specific language governing permissions and
|
|
|
|
limitations under the License.
|
|
|
|
*/
|
|
|
|
|
2021-08-21 01:03:06 +05:30
|
|
|
export enum StoreNames {
|
|
|
|
session = "session",
|
|
|
|
roomState = "roomState",
|
|
|
|
roomSummary = "roomSummary",
|
|
|
|
archivedRoomSummary = "archivedRoomSummary",
|
|
|
|
invites = "invites",
|
|
|
|
roomMembers = "roomMembers",
|
|
|
|
timelineEvents = "timelineEvents",
|
|
|
|
timelineRelations = "timelineRelations",
|
|
|
|
timelineFragments = "timelineFragments",
|
|
|
|
pendingEvents = "pendingEvents",
|
|
|
|
userIdentities = "userIdentities",
|
|
|
|
deviceIdentities = "deviceIdentities",
|
|
|
|
olmSessions = "olmSessions",
|
|
|
|
inboundGroupSessions = "inboundGroupSessions",
|
|
|
|
outboundGroupSessions = "outboundGroupSessions",
|
|
|
|
groupSessionDecryptions = "groupSessionDecryptions",
|
|
|
|
operations = "operations",
|
|
|
|
accountData = "accountData",
|
|
|
|
}
|
2019-04-04 12:57:31 +05:30
|
|
|
|
2021-08-21 01:03:06 +05:30
|
|
|
export const STORE_NAMES: Readonly<StoreNames[]> = Object.values(StoreNames);
|
2019-06-27 01:30:50 +05:30
|
|
|
|
|
|
|
export class StorageError extends Error {
|
2021-08-10 02:14:07 +05:30
|
|
|
errcode?: string;
|
2021-08-20 23:11:15 +05:30
|
|
|
cause: Error | null;
|
2021-08-10 02:14:07 +05:30
|
|
|
|
2021-08-20 23:11:15 +05:30
|
|
|
constructor(message: string, cause: Error | null = null) {
|
2020-09-29 12:47:03 +05:30
|
|
|
super(message);
|
2019-07-27 01:33:57 +05:30
|
|
|
if (cause) {
|
|
|
|
this.errcode = cause.name;
|
|
|
|
}
|
2019-10-13 01:49:16 +05:30
|
|
|
this.cause = cause;
|
2019-06-27 01:30:50 +05:30
|
|
|
}
|
2020-08-18 20:57:40 +05:30
|
|
|
|
2021-08-10 02:14:07 +05:30
|
|
|
get name(): string {
|
2020-08-18 20:57:40 +05:30
|
|
|
return "StorageError";
|
|
|
|
}
|
2019-06-27 01:30:50 +05:30
|
|
|
}
|
2020-10-26 15:04:35 +05:30
|
|
|
|
|
|
|
export const KeyLimits = {
|
2021-08-10 02:14:07 +05:30
|
|
|
get minStorageKey(): number {
|
2020-10-26 15:04:35 +05:30
|
|
|
// for indexeddb, we use unsigned 32 bit integers as keys
|
|
|
|
return 0;
|
|
|
|
},
|
|
|
|
|
2021-08-10 02:14:07 +05:30
|
|
|
get middleStorageKey(): number {
|
2020-10-26 15:04:35 +05:30
|
|
|
// for indexeddb, we use unsigned 32 bit integers as keys
|
|
|
|
return 0x7FFFFFFF;
|
|
|
|
},
|
|
|
|
|
2021-08-10 02:14:07 +05:30
|
|
|
get maxStorageKey(): number {
|
2020-10-26 15:04:35 +05:30
|
|
|
// for indexeddb, we use unsigned 32 bit integers as keys
|
|
|
|
return 0xFFFFFFFF;
|
|
|
|
}
|
|
|
|
}
|