mirror of
https://github.com/vector-im/hydrogen-web.git
synced 2024-12-23 11:35:04 +01:00
(re)move old (compile-time) platform code
This commit is contained in:
parent
06e4dea590
commit
46fd769dda
@ -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";
|
|
@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
|
|||||||
limitations under the License.
|
limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import {Platform} from "../../../Platform.js";
|
import {KeyLimits} from "../../storage/common.js";
|
||||||
|
|
||||||
// key for events in the timelineEvents store
|
// key for events in the timelineEvents store
|
||||||
export class EventKey {
|
export class EventKey {
|
||||||
@ -25,7 +25,7 @@ export class EventKey {
|
|||||||
|
|
||||||
nextFragmentKey() {
|
nextFragmentKey() {
|
||||||
// could take MIN_EVENT_INDEX here if it can't be paged back
|
// 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) {
|
nextKeyForDirection(direction) {
|
||||||
@ -45,19 +45,19 @@ export class EventKey {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static get maxKey() {
|
static get maxKey() {
|
||||||
return new EventKey(Platform.maxStorageKey, Platform.maxStorageKey);
|
return new EventKey(KeyLimits.maxStorageKey, KeyLimits.maxStorageKey);
|
||||||
}
|
}
|
||||||
|
|
||||||
static get minKey() {
|
static get minKey() {
|
||||||
return new EventKey(Platform.minStorageKey, Platform.minStorageKey);
|
return new EventKey(KeyLimits.minStorageKey, KeyLimits.minStorageKey);
|
||||||
}
|
}
|
||||||
|
|
||||||
static get defaultLiveKey() {
|
static get defaultLiveKey() {
|
||||||
return EventKey.defaultFragmentKey(Platform.minStorageKey);
|
return EventKey.defaultFragmentKey(KeyLimits.minStorageKey);
|
||||||
}
|
}
|
||||||
|
|
||||||
static defaultFragmentKey(fragmentId) {
|
static defaultFragmentKey(fragmentId) {
|
||||||
return new EventKey(fragmentId, Platform.middleStorageKey);
|
return new EventKey(fragmentId, KeyLimits.middleStorageKey);
|
||||||
}
|
}
|
||||||
|
|
||||||
toString() {
|
toString() {
|
||||||
|
@ -17,7 +17,7 @@ limitations under the License.
|
|||||||
import {BaseEntry} from "./BaseEntry.js";
|
import {BaseEntry} from "./BaseEntry.js";
|
||||||
import {Direction} from "../Direction.js";
|
import {Direction} from "../Direction.js";
|
||||||
import {isValidFragmentId} from "../common.js";
|
import {isValidFragmentId} from "../common.js";
|
||||||
import {Platform} from "../../../../Platform.js";
|
import {KeyLimits} from "../../../storage/common.js";
|
||||||
|
|
||||||
export class FragmentBoundaryEntry extends BaseEntry {
|
export class FragmentBoundaryEntry extends BaseEntry {
|
||||||
constructor(fragment, isFragmentStart, fragmentIdComparer) {
|
constructor(fragment, isFragmentStart, fragmentIdComparer) {
|
||||||
@ -53,9 +53,9 @@ export class FragmentBoundaryEntry extends BaseEntry {
|
|||||||
|
|
||||||
get entryIndex() {
|
get entryIndex() {
|
||||||
if (this.started) {
|
if (this.started) {
|
||||||
return Platform.minStorageKey;
|
return KeyLimits.minStorageKey;
|
||||||
} else {
|
} else {
|
||||||
return Platform.maxStorageKey;
|
return KeyLimits.maxStorageKey;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -50,3 +50,20 @@ export class StorageError extends Error {
|
|||||||
return "StorageError";
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -15,7 +15,7 @@ limitations under the License.
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import { encodeUint32, decodeUint32 } from "../utils.js";
|
import { encodeUint32, decodeUint32 } from "../utils.js";
|
||||||
import {Platform} from "../../../../Platform.js";
|
import {KeyLimits} from "../../common.js";
|
||||||
|
|
||||||
function encodeKey(roomId, queueIndex) {
|
function encodeKey(roomId, queueIndex) {
|
||||||
return `${roomId}|${encodeUint32(queueIndex)}`;
|
return `${roomId}|${encodeUint32(queueIndex)}`;
|
||||||
@ -34,8 +34,8 @@ export class PendingEventStore {
|
|||||||
|
|
||||||
async getMaxQueueIndex(roomId) {
|
async getMaxQueueIndex(roomId) {
|
||||||
const range = IDBKeyRange.bound(
|
const range = IDBKeyRange.bound(
|
||||||
encodeKey(roomId, Platform.minStorageKey),
|
encodeKey(roomId, KeyLimits.minStorageKey),
|
||||||
encodeKey(roomId, Platform.maxStorageKey),
|
encodeKey(roomId, KeyLimits.maxStorageKey),
|
||||||
false,
|
false,
|
||||||
false,
|
false,
|
||||||
);
|
);
|
||||||
|
@ -17,7 +17,7 @@ limitations under the License.
|
|||||||
import {EventKey} from "../../../room/timeline/EventKey.js";
|
import {EventKey} from "../../../room/timeline/EventKey.js";
|
||||||
import { StorageError } from "../../common.js";
|
import { StorageError } from "../../common.js";
|
||||||
import { encodeUint32 } from "../utils.js";
|
import { encodeUint32 } from "../utils.js";
|
||||||
import {Platform} from "../../../../Platform.js";
|
import {KeyLimits} from "../../common.js";
|
||||||
|
|
||||||
function encodeKey(roomId, fragmentId, eventIndex) {
|
function encodeKey(roomId, fragmentId, eventIndex) {
|
||||||
return `${roomId}|${encodeUint32(fragmentId)}|${encodeUint32(eventIndex)}`;
|
return `${roomId}|${encodeUint32(fragmentId)}|${encodeUint32(eventIndex)}`;
|
||||||
@ -52,7 +52,7 @@ class Range {
|
|||||||
if (this._lower && !this._upper) {
|
if (this._lower && !this._upper) {
|
||||||
return IDBKeyRange.bound(
|
return IDBKeyRange.bound(
|
||||||
encodeKey(roomId, this._lower.fragmentId, this._lower.eventIndex),
|
encodeKey(roomId, this._lower.fragmentId, this._lower.eventIndex),
|
||||||
encodeKey(roomId, this._lower.fragmentId, Platform.maxStorageKey),
|
encodeKey(roomId, this._lower.fragmentId, KeyLimits.maxStorageKey),
|
||||||
this._lowerOpen,
|
this._lowerOpen,
|
||||||
false
|
false
|
||||||
);
|
);
|
||||||
@ -61,7 +61,7 @@ class Range {
|
|||||||
// also bound as we don't want to move into another roomId
|
// also bound as we don't want to move into another roomId
|
||||||
if (!this._lower && this._upper) {
|
if (!this._lower && this._upper) {
|
||||||
return IDBKeyRange.bound(
|
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),
|
encodeKey(roomId, this._upper.fragmentId, this._upper.eventIndex),
|
||||||
false,
|
false,
|
||||||
this._upperOpen
|
this._upperOpen
|
||||||
|
@ -15,7 +15,7 @@ limitations under the License.
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import { StorageError } from "../../common.js";
|
import { StorageError } from "../../common.js";
|
||||||
import {Platform} from "../../../../Platform.js";
|
import {KeyLimits} from "../../common.js";
|
||||||
import { encodeUint32 } from "../utils.js";
|
import { encodeUint32 } from "../utils.js";
|
||||||
|
|
||||||
function encodeKey(roomId, fragmentId) {
|
function encodeKey(roomId, fragmentId) {
|
||||||
@ -30,8 +30,8 @@ export class TimelineFragmentStore {
|
|||||||
_allRange(roomId) {
|
_allRange(roomId) {
|
||||||
try {
|
try {
|
||||||
return IDBKeyRange.bound(
|
return IDBKeyRange.bound(
|
||||||
encodeKey(roomId, Platform.minStorageKey),
|
encodeKey(roomId, KeyLimits.minStorageKey),
|
||||||
encodeKey(roomId, Platform.maxStorageKey)
|
encodeKey(roomId, KeyLimits.maxStorageKey)
|
||||||
);
|
);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
throw new StorageError(`error from IDBKeyRange with roomId ${roomId}`, err);
|
throw new StorageError(`error from IDBKeyRange with roomId ${roomId}`, err);
|
||||||
|
@ -48,7 +48,7 @@ export async function checkNeedsSyncPromise() {
|
|||||||
return needsSyncPromise;
|
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) {
|
export function encodeUint32(n) {
|
||||||
const hex = n.toString(16);
|
const hex = n.toString(16);
|
||||||
return "0".repeat(8 - hex.length) + hex;
|
return "0".repeat(8 - hex.length) + hex;
|
||||||
|
@ -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));
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Reference in New Issue
Block a user