From 144e391c82ff57dfef42e75be14fffea08f93f45 Mon Sep 17 00:00:00 2001 From: Danila Fedorin Date: Tue, 10 Aug 2021 16:10:55 -0700 Subject: [PATCH] Migrate SessionStore.js to TypeScript. --- src/matrix/storage/idb/Transaction.js | 2 +- src/matrix/storage/idb/schema.js | 2 +- src/matrix/storage/idb/stores/SessionStore.js | 40 ---------------- src/matrix/storage/idb/stores/SessionStore.ts | 48 +++++++++++++++++++ 4 files changed, 50 insertions(+), 42 deletions(-) delete mode 100644 src/matrix/storage/idb/stores/SessionStore.js create mode 100644 src/matrix/storage/idb/stores/SessionStore.ts diff --git a/src/matrix/storage/idb/Transaction.js b/src/matrix/storage/idb/Transaction.js index 4c543f4c..d4949b02 100644 --- a/src/matrix/storage/idb/Transaction.js +++ b/src/matrix/storage/idb/Transaction.js @@ -17,7 +17,7 @@ limitations under the License. import {txnAsPromise} from "./utils"; import {StorageError} from "../common"; import {Store} from "./Store"; -import {SessionStore} from "./stores/SessionStore.js"; +import {SessionStore} from "./stores/SessionStore"; import {RoomSummaryStore} from "./stores/RoomSummaryStore.js"; import {InviteStore} from "./stores/InviteStore.js"; import {TimelineEventStore} from "./stores/TimelineEventStore.js"; diff --git a/src/matrix/storage/idb/schema.js b/src/matrix/storage/idb/schema.js index d593f6b9..fdfc78d7 100644 --- a/src/matrix/storage/idb/schema.js +++ b/src/matrix/storage/idb/schema.js @@ -1,7 +1,7 @@ import {iterateCursor, reqAsPromise} from "./utils"; import {RoomMember, EVENT_TYPE as MEMBER_EVENT_TYPE} from "../../room/members/RoomMember.js"; import {RoomMemberStore} from "./stores/RoomMemberStore.js"; -import {SessionStore} from "./stores/SessionStore.js"; +import {SessionStore} from "./stores/SessionStore"; import {encodeScopeTypeKey} from "./stores/OperationStore.js"; // FUNCTIONS SHOULD ONLY BE APPENDED!! diff --git a/src/matrix/storage/idb/stores/SessionStore.js b/src/matrix/storage/idb/stores/SessionStore.js deleted file mode 100644 index 3be8e875..00000000 --- a/src/matrix/storage/idb/stores/SessionStore.js +++ /dev/null @@ -1,40 +0,0 @@ -/* -Copyright 2020 Bruno Windels - -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. -*/ - -export class SessionStore { - constructor(sessionStore) { - this._sessionStore = sessionStore; - } - - async get(key) { - const entry = await this._sessionStore.get(key); - if (entry) { - return entry.value; - } - } - - set(key, value) { - this._sessionStore.put({key, value}); - } - - add(key, value) { - this._sessionStore.add({key, value}); - } - - remove(key) { - this._sessionStore.delete(key); - } -} diff --git a/src/matrix/storage/idb/stores/SessionStore.ts b/src/matrix/storage/idb/stores/SessionStore.ts new file mode 100644 index 00000000..bf3d6d11 --- /dev/null +++ b/src/matrix/storage/idb/stores/SessionStore.ts @@ -0,0 +1,48 @@ +/* +Copyright 2020 Bruno Windels + +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. +*/ +import {Store} from "../Store"; + +export interface SessionEntry { + key: string; + value: any; +} + +export class SessionStore { + private _sessionStore: Store + + constructor(sessionStore: Store) { + this._sessionStore = sessionStore; + } + + async get(key: IDBValidKey): Promise { + const entry = await this._sessionStore.get(key); + if (entry) { + return entry.value; + } + } + + set(key: string, value: any): Promise { + return this._sessionStore.put({key, value}); + } + + add(key: string, value: any): Promise { + return this._sessionStore.add({key, value}); + } + + remove(key: IDBValidKey): Promise { + return this._sessionStore.delete(key); + } +}