Merge branch 'snowpack-ts-storage-1' into snowpack-ts-storage-2

This commit is contained in:
Danila Fedorin 2021-08-20 12:51:23 -07:00
commit e610087a79
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. limitations under the License.
*/ */
export const STORE_NAMES: Readonly<string[]> = Object.freeze([ export enum StoreNames {
"session", session = "session",
"roomState", roomState = "roomState",
"roomSummary", roomSummary = "roomSummary",
"archivedRoomSummary", archivedRoomSummary = "archivedRoomSummary",
"invites", invites = "invites",
"roomMembers", roomMembers = "roomMembers",
"timelineEvents", timelineEvents = "timelineEvents",
"timelineRelations", timelineRelations = "timelineRelations",
"timelineFragments", timelineFragments = "timelineFragments",
"pendingEvents", pendingEvents = "pendingEvents",
"userIdentities", userIdentities = "userIdentities",
"deviceIdentities", deviceIdentities = "deviceIdentities",
"olmSessions", olmSessions = "olmSessions",
"inboundGroupSessions", inboundGroupSessions = "inboundGroupSessions",
"outboundGroupSessions", outboundGroupSessions = "outboundGroupSessions",
"groupSessionDecryptions", groupSessionDecryptions = "groupSessionDecryptions",
"operations", operations = "operations",
"accountData", accountData = "accountData",
]); }
export const STORE_MAP: Readonly<{ [name : string]: string }> = Object.freeze(STORE_NAMES.reduce((nameMap, name) => { export const STORE_NAMES: Readonly<StoreNames[]> = Object.values(StoreNames);
nameMap[name] = name;
return nameMap;
}, {}));
export class StorageError extends Error { export class StorageError extends Error {
errcode?: string; errcode?: string;

View file

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