2020-08-05 18:38:55 +02:00
|
|
|
/*
|
|
|
|
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-09 22:44:07 +02:00
|
|
|
export const STORE_NAMES: Readonly<string[]> = Object.freeze([
|
2019-07-01 10:00:29 +02:00
|
|
|
"session",
|
|
|
|
"roomState",
|
|
|
|
"roomSummary",
|
2021-05-04 13:34:42 +02:00
|
|
|
"archivedRoomSummary",
|
2021-04-20 13:02:50 +02:00
|
|
|
"invites",
|
2020-06-26 23:26:24 +02:00
|
|
|
"roomMembers",
|
2019-07-01 10:00:29 +02:00
|
|
|
"timelineEvents",
|
2021-06-03 16:44:35 +02:00
|
|
|
"timelineRelations",
|
2019-07-01 10:00:29 +02:00
|
|
|
"timelineFragments",
|
|
|
|
"pendingEvents",
|
2020-08-31 14:38:03 +02:00
|
|
|
"userIdentities",
|
|
|
|
"deviceIdentities",
|
2020-09-01 17:59:59 +02:00
|
|
|
"olmSessions",
|
2020-09-02 14:24:38 +02:00
|
|
|
"inboundGroupSessions",
|
2020-09-03 17:49:20 +02:00
|
|
|
"outboundGroupSessions",
|
2020-09-04 15:31:00 +02:00
|
|
|
"groupSessionDecryptions",
|
2020-09-17 10:39:51 +02:00
|
|
|
"operations",
|
|
|
|
"accountData",
|
2019-07-01 10:00:29 +02:00
|
|
|
]);
|
2019-04-04 09:27:31 +02:00
|
|
|
|
2021-08-09 22:44:07 +02:00
|
|
|
export const STORE_MAP: Readonly<{ [name : string]: string }> = Object.freeze(STORE_NAMES.reduce((nameMap, name) => {
|
2019-04-04 09:27:31 +02:00
|
|
|
nameMap[name] = name;
|
|
|
|
return nameMap;
|
|
|
|
}, {}));
|
2019-06-26 22:00:50 +02:00
|
|
|
|
|
|
|
export class StorageError extends Error {
|
2021-08-09 22:44:07 +02:00
|
|
|
errcode?: string;
|
2021-08-20 19:41:15 +02:00
|
|
|
cause: Error | null;
|
2021-08-09 22:44:07 +02:00
|
|
|
|
2021-08-20 19:41:15 +02:00
|
|
|
constructor(message: string, cause: Error | null = null) {
|
2020-09-29 09:17:03 +02:00
|
|
|
super(message);
|
2019-07-26 22:03:57 +02:00
|
|
|
if (cause) {
|
|
|
|
this.errcode = cause.name;
|
|
|
|
}
|
2019-10-12 22:19:16 +02:00
|
|
|
this.cause = cause;
|
2019-06-26 22:00:50 +02:00
|
|
|
}
|
2020-08-18 17:27:40 +02:00
|
|
|
|
2021-08-09 22:44:07 +02:00
|
|
|
get name(): string {
|
2020-08-18 17:27:40 +02:00
|
|
|
return "StorageError";
|
|
|
|
}
|
2019-06-26 22:00:50 +02:00
|
|
|
}
|
2020-10-26 10:34:35 +01:00
|
|
|
|
|
|
|
export const KeyLimits = {
|
2021-08-09 22:44:07 +02:00
|
|
|
get minStorageKey(): number {
|
2020-10-26 10:34:35 +01:00
|
|
|
// for indexeddb, we use unsigned 32 bit integers as keys
|
|
|
|
return 0;
|
|
|
|
},
|
|
|
|
|
2021-08-09 22:44:07 +02:00
|
|
|
get middleStorageKey(): number {
|
2020-10-26 10:34:35 +01:00
|
|
|
// for indexeddb, we use unsigned 32 bit integers as keys
|
|
|
|
return 0x7FFFFFFF;
|
|
|
|
},
|
|
|
|
|
2021-08-09 22:44:07 +02:00
|
|
|
get maxStorageKey(): number {
|
2020-10-26 10:34:35 +01:00
|
|
|
// for indexeddb, we use unsigned 32 bit integers as keys
|
|
|
|
return 0xFFFFFFFF;
|
|
|
|
}
|
|
|
|
}
|