From 46fd769dda690f239793a553df58a1bb6c06480e Mon Sep 17 00:00:00 2001 From: Bruno Windels Date: Mon, 26 Oct 2020 10:34:35 +0100 Subject: [PATCH] (re)move old (compile-time) platform code --- src/Platform.js | 17 --------- src/matrix/room/timeline/EventKey.js | 12 +++---- .../timeline/entries/FragmentBoundaryEntry.js | 6 ++-- src/matrix/storage/common.js | 17 +++++++++ .../storage/idb/stores/PendingEventStore.js | 6 ++-- .../storage/idb/stores/TimelineEventStore.js | 6 ++-- .../idb/stores/TimelineFragmentStore.js | 6 ++-- src/matrix/storage/idb/utils.js | 2 +- src/platform/web/WebPlatform.js | 36 ------------------- 9 files changed, 36 insertions(+), 72 deletions(-) delete mode 100644 src/Platform.js delete mode 100644 src/platform/web/WebPlatform.js diff --git a/src/Platform.js b/src/Platform.js deleted file mode 100644 index b8d763fd..00000000 --- a/src/Platform.js +++ /dev/null @@ -1,17 +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 {WebPlatform as Platform} from "./platform/web/WebPlatform.js"; diff --git a/src/matrix/room/timeline/EventKey.js b/src/matrix/room/timeline/EventKey.js index e1771258..11d625e6 100644 --- a/src/matrix/room/timeline/EventKey.js +++ b/src/matrix/room/timeline/EventKey.js @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -import {Platform} from "../../../Platform.js"; +import {KeyLimits} from "../../storage/common.js"; // key for events in the timelineEvents store export class EventKey { @@ -25,7 +25,7 @@ export class EventKey { nextFragmentKey() { // could take MIN_EVENT_INDEX here if it can't be paged back - return new EventKey(this.fragmentId + 1, Platform.middleStorageKey); + return new EventKey(this.fragmentId + 1, KeyLimits.middleStorageKey); } nextKeyForDirection(direction) { @@ -45,19 +45,19 @@ export class EventKey { } static get maxKey() { - return new EventKey(Platform.maxStorageKey, Platform.maxStorageKey); + return new EventKey(KeyLimits.maxStorageKey, KeyLimits.maxStorageKey); } static get minKey() { - return new EventKey(Platform.minStorageKey, Platform.minStorageKey); + return new EventKey(KeyLimits.minStorageKey, KeyLimits.minStorageKey); } static get defaultLiveKey() { - return EventKey.defaultFragmentKey(Platform.minStorageKey); + return EventKey.defaultFragmentKey(KeyLimits.minStorageKey); } static defaultFragmentKey(fragmentId) { - return new EventKey(fragmentId, Platform.middleStorageKey); + return new EventKey(fragmentId, KeyLimits.middleStorageKey); } toString() { diff --git a/src/matrix/room/timeline/entries/FragmentBoundaryEntry.js b/src/matrix/room/timeline/entries/FragmentBoundaryEntry.js index 791c7a9f..f43f273b 100644 --- a/src/matrix/room/timeline/entries/FragmentBoundaryEntry.js +++ b/src/matrix/room/timeline/entries/FragmentBoundaryEntry.js @@ -17,7 +17,7 @@ limitations under the License. import {BaseEntry} from "./BaseEntry.js"; import {Direction} from "../Direction.js"; import {isValidFragmentId} from "../common.js"; -import {Platform} from "../../../../Platform.js"; +import {KeyLimits} from "../../../storage/common.js"; export class FragmentBoundaryEntry extends BaseEntry { constructor(fragment, isFragmentStart, fragmentIdComparer) { @@ -53,9 +53,9 @@ export class FragmentBoundaryEntry extends BaseEntry { get entryIndex() { if (this.started) { - return Platform.minStorageKey; + return KeyLimits.minStorageKey; } else { - return Platform.maxStorageKey; + return KeyLimits.maxStorageKey; } } diff --git a/src/matrix/storage/common.js b/src/matrix/storage/common.js index d96dc359..3e9aca4f 100644 --- a/src/matrix/storage/common.js +++ b/src/matrix/storage/common.js @@ -50,3 +50,20 @@ export class StorageError extends Error { return "StorageError"; } } + +export const KeyLimits = { + get minStorageKey() { + // for indexeddb, we use unsigned 32 bit integers as keys + return 0; + }, + + get middleStorageKey() { + // for indexeddb, we use unsigned 32 bit integers as keys + return 0x7FFFFFFF; + }, + + get maxStorageKey() { + // for indexeddb, we use unsigned 32 bit integers as keys + return 0xFFFFFFFF; + } +} diff --git a/src/matrix/storage/idb/stores/PendingEventStore.js b/src/matrix/storage/idb/stores/PendingEventStore.js index 59b79a05..3659299f 100644 --- a/src/matrix/storage/idb/stores/PendingEventStore.js +++ b/src/matrix/storage/idb/stores/PendingEventStore.js @@ -15,7 +15,7 @@ limitations under the License. */ import { encodeUint32, decodeUint32 } from "../utils.js"; -import {Platform} from "../../../../Platform.js"; +import {KeyLimits} from "../../common.js"; function encodeKey(roomId, queueIndex) { return `${roomId}|${encodeUint32(queueIndex)}`; @@ -34,8 +34,8 @@ export class PendingEventStore { async getMaxQueueIndex(roomId) { const range = IDBKeyRange.bound( - encodeKey(roomId, Platform.minStorageKey), - encodeKey(roomId, Platform.maxStorageKey), + encodeKey(roomId, KeyLimits.minStorageKey), + encodeKey(roomId, KeyLimits.maxStorageKey), false, false, ); diff --git a/src/matrix/storage/idb/stores/TimelineEventStore.js b/src/matrix/storage/idb/stores/TimelineEventStore.js index b7712337..32468b21 100644 --- a/src/matrix/storage/idb/stores/TimelineEventStore.js +++ b/src/matrix/storage/idb/stores/TimelineEventStore.js @@ -17,7 +17,7 @@ limitations under the License. import {EventKey} from "../../../room/timeline/EventKey.js"; import { StorageError } from "../../common.js"; import { encodeUint32 } from "../utils.js"; -import {Platform} from "../../../../Platform.js"; +import {KeyLimits} from "../../common.js"; function encodeKey(roomId, fragmentId, eventIndex) { return `${roomId}|${encodeUint32(fragmentId)}|${encodeUint32(eventIndex)}`; @@ -52,7 +52,7 @@ class Range { if (this._lower && !this._upper) { return IDBKeyRange.bound( encodeKey(roomId, this._lower.fragmentId, this._lower.eventIndex), - encodeKey(roomId, this._lower.fragmentId, Platform.maxStorageKey), + encodeKey(roomId, this._lower.fragmentId, KeyLimits.maxStorageKey), this._lowerOpen, false ); @@ -61,7 +61,7 @@ class Range { // also bound as we don't want to move into another roomId if (!this._lower && this._upper) { return IDBKeyRange.bound( - encodeKey(roomId, this._upper.fragmentId, Platform.minStorageKey), + encodeKey(roomId, this._upper.fragmentId, KeyLimits.minStorageKey), encodeKey(roomId, this._upper.fragmentId, this._upper.eventIndex), false, this._upperOpen diff --git a/src/matrix/storage/idb/stores/TimelineFragmentStore.js b/src/matrix/storage/idb/stores/TimelineFragmentStore.js index 849e5204..8f11cb3e 100644 --- a/src/matrix/storage/idb/stores/TimelineFragmentStore.js +++ b/src/matrix/storage/idb/stores/TimelineFragmentStore.js @@ -15,7 +15,7 @@ limitations under the License. */ import { StorageError } from "../../common.js"; -import {Platform} from "../../../../Platform.js"; +import {KeyLimits} from "../../common.js"; import { encodeUint32 } from "../utils.js"; function encodeKey(roomId, fragmentId) { @@ -30,8 +30,8 @@ export class TimelineFragmentStore { _allRange(roomId) { try { return IDBKeyRange.bound( - encodeKey(roomId, Platform.minStorageKey), - encodeKey(roomId, Platform.maxStorageKey) + encodeKey(roomId, KeyLimits.minStorageKey), + encodeKey(roomId, KeyLimits.maxStorageKey) ); } catch (err) { throw new StorageError(`error from IDBKeyRange with roomId ${roomId}`, err); diff --git a/src/matrix/storage/idb/utils.js b/src/matrix/storage/idb/utils.js index ac9f3911..9d3a42d9 100644 --- a/src/matrix/storage/idb/utils.js +++ b/src/matrix/storage/idb/utils.js @@ -48,7 +48,7 @@ export async function checkNeedsSyncPromise() { return needsSyncPromise; } -// storage keys are defined to be unsigned 32bit numbers in WebPlatform.js, which is assumed by idb +// storage keys are defined to be unsigned 32bit numbers in KeyLimits, which is assumed by idb export function encodeUint32(n) { const hex = n.toString(16); return "0".repeat(8 - hex.length) + hex; diff --git a/src/platform/web/WebPlatform.js b/src/platform/web/WebPlatform.js deleted file mode 100644 index 22a41323..00000000 --- a/src/platform/web/WebPlatform.js +++ /dev/null @@ -1,36 +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 const WebPlatform = { - get minStorageKey() { - // for indexeddb, we use unsigned 32 bit integers as keys - return 0; - }, - - get middleStorageKey() { - // for indexeddb, we use unsigned 32 bit integers as keys - return 0x7FFFFFFF; - }, - - get maxStorageKey() { - // for indexeddb, we use unsigned 32 bit integers as keys - return 0xFFFFFFFF; - }, - - delay(ms) { - return new Promise(resolve => setTimeout(resolve, ms)); - } -}