Try using an enum for store names.

This commit is contained in:
Danila Fedorin 2021-08-20 12:33:06 -07:00
parent 0b8acb51a4
commit a2ff02e6c0
2 changed files with 23 additions and 30 deletions

View file

@ -14,31 +14,28 @@ See the License for the specific language governing permissions and
limitations under the License.
*/
export const STORE_NAMES: Readonly<string[]> = Object.freeze([
"session",
"roomState",
"roomSummary",
"archivedRoomSummary",
"invites",
"roomMembers",
"timelineEvents",
"timelineRelations",
"timelineFragments",
"pendingEvents",
"userIdentities",
"deviceIdentities",
"olmSessions",
"inboundGroupSessions",
"outboundGroupSessions",
"groupSessionDecryptions",
"operations",
"accountData",
]);
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",
}
export const STORE_MAP: Readonly<{ [name : string]: string }> = Object.freeze(STORE_NAMES.reduce((nameMap, name) => {
nameMap[name] = name;
return nameMap;
}, {}));
export const STORE_NAMES: Readonly<StoreNames[]> = Object.values(StoreNames);
export class StorageError extends Error {
errcode?: string;

View file

@ -15,7 +15,7 @@ limitations under the License.
*/
import {Transaction} from "./Transaction.js";
import { STORE_NAMES, StorageError } from "../common";
import { STORE_NAMES, StoreNames, StorageError } from "../common";
import { reqAsPromise } from "./utils";
const WEBKITEARLYCLOSETXNBUG_BOGUS_KEY = "782rh281re38-boguskey";
@ -25,11 +25,7 @@ export class Storage {
this._db = idbDatabase;
this._IDBKeyRange = IDBKeyRange;
this._hasWebkitEarlyCloseTxnBug = hasWebkitEarlyCloseTxnBug;
const nameMap = STORE_NAMES.reduce((nameMap, name) => {
nameMap[name] = name;
return nameMap;
}, {});
this.storeNames = Object.freeze(nameMap);
this.storeNames = StoreNames;
}
_validateStoreNames(storeNames) {