From a2ff02e6c063816d4a4584f25955fd44097eee25 Mon Sep 17 00:00:00 2001 From: Danila Fedorin Date: Fri, 20 Aug 2021 12:33:06 -0700 Subject: [PATCH] Try using an enum for store names. --- src/matrix/storage/common.ts | 45 +++++++++++++++---------------- src/matrix/storage/idb/Storage.js | 8 ++---- 2 files changed, 23 insertions(+), 30 deletions(-) diff --git a/src/matrix/storage/common.ts b/src/matrix/storage/common.ts index 8d2dd2d2..23bb0d31 100644 --- a/src/matrix/storage/common.ts +++ b/src/matrix/storage/common.ts @@ -14,31 +14,28 @@ See the License for the specific language governing permissions and limitations under the License. */ -export const STORE_NAMES: Readonly = 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 = Object.values(StoreNames); export class StorageError extends Error { errcode?: string; diff --git a/src/matrix/storage/idb/Storage.js b/src/matrix/storage/idb/Storage.js index cef636fb..a0814a53 100644 --- a/src/matrix/storage/idb/Storage.js +++ b/src/matrix/storage/idb/Storage.js @@ -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) {