(re)move old (compile-time) platform code

This commit is contained in:
Bruno Windels 2020-10-26 10:34:35 +01:00
parent 06e4dea590
commit 46fd769dda
9 changed files with 36 additions and 72 deletions

View file

@ -1,17 +0,0 @@
/*
Copyright 2020 Bruno Windels <bruno@windels.cloud>
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";

View file

@ -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() {

View file

@ -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;
}
}

View file

@ -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;
}
}

View file

@ -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,
);

View file

@ -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

View file

@ -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);

View file

@ -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;

View file

@ -1,36 +0,0 @@
/*
Copyright 2020 Bruno Windels <bruno@windels.cloud>
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));
}
}