diff --git a/src/matrix/storage/common.ts b/src/matrix/storage/common.ts index 4784862f..926ccbbf 100644 --- a/src/matrix/storage/common.ts +++ b/src/matrix/storage/common.ts @@ -41,8 +41,8 @@ export const STORE_MAP: Readonly<{ [name : string]: string }> = Object.freeze(ST }, {})); export class StorageError extends Error { - errcode?: string - cause?: Error + errcode?: string; + cause?: Error; constructor(message: string, cause?: Error) { super(message); diff --git a/src/matrix/storage/idb/QueryTarget.ts b/src/matrix/storage/idb/QueryTarget.ts index ac9e3d16..71da4d76 100644 --- a/src/matrix/storage/idb/QueryTarget.ts +++ b/src/matrix/storage/idb/QueryTarget.ts @@ -36,7 +36,7 @@ export class QueryTarget { this._target = target; } - _openCursor(range?: IDBQuery, direction?: IDBCursorDirection) { + _openCursor(range?: IDBQuery, direction?: IDBCursorDirection): IDBRequest { if (range && direction) { return this._target.openCursor(range, direction); } else if (range) { @@ -124,7 +124,7 @@ export class QueryTarget { async findMaxKey(range: IDBQuery): Promise { const cursor = this._target.openKeyCursor(range, "prev"); - let maxKey; + let maxKey: IDBValidKey | undefined; await iterateCursor(cursor, (_, key) => { maxKey = key; return {done: true}; @@ -133,14 +133,14 @@ export class QueryTarget { } - async iterateValues(range: IDBQuery, callback: (val: T, key: IDBValidKey, cur: IDBCursorWithValue) => boolean) { + async iterateValues(range: IDBQuery, callback: (val: T, key: IDBValidKey, cur: IDBCursorWithValue) => boolean): Promise { const cursor = this._target.openCursor(range, "next"); await iterateCursor(cursor, (value, key, cur) => { return {done: callback(value, key, cur)}; }); } - async iterateKeys(range: IDBQuery, callback: (key: IDBValidKey, cur: IDBCursor) => boolean) { + async iterateKeys(range: IDBQuery, callback: (key: IDBValidKey, cur: IDBCursor) => boolean): Promise { const cursor = this._target.openKeyCursor(range, "next"); await iterateCursor(cursor, (_, key, cur) => { return {done: callback(key, cur)}; @@ -153,7 +153,7 @@ export class QueryTarget { * If the callback returns true, the search is halted and callback won't be called again. * `callback` is called with the same instances of the key as given in `keys`, so direct comparison can be used. */ - async findExistingKeys(keys: IDBValidKey[], backwards: boolean, callback: (key: IDBValidKey, found: boolean) => boolean) { + async findExistingKeys(keys: IDBValidKey[], backwards: boolean, callback: (key: IDBValidKey, found: boolean) => boolean): Promise { const direction = backwards ? "prev" : "next"; const compareKeys = (a, b) => backwards ? -indexedDB.cmp(a, b) : indexedDB.cmp(a, b); const sortedKeys = keys.slice().sort(compareKeys); @@ -225,7 +225,7 @@ export class QueryTarget { return results; } - async iterateWhile(range: IDBQuery, predicate: (v: T) => boolean) { + async iterateWhile(range: IDBQuery, predicate: (v: T) => boolean): Promise { const cursor = this._openCursor(range, "next"); await iterateCursor(cursor, (value) => { const passesPredicate = predicate(value); diff --git a/src/matrix/storage/idb/Storage.ts b/src/matrix/storage/idb/Storage.ts index cc460b26..8dd33522 100644 --- a/src/matrix/storage/idb/Storage.ts +++ b/src/matrix/storage/idb/Storage.ts @@ -37,7 +37,7 @@ export class Storage { this.storeNames = Object.freeze(nameMap); } - _validateStoreNames(storeNames: string[]) { + _validateStoreNames(storeNames: string[]): void { const idx = storeNames.findIndex(name => !STORE_NAMES.includes(name)); if (idx !== -1) { throw new StorageError(`Tried top, a transaction unknown store ${storeNames[idx]}`); @@ -76,7 +76,7 @@ export class Storage { } } - close() { + close(): void { this._db.close(); } } diff --git a/src/matrix/storage/idb/StorageFactory.ts b/src/matrix/storage/idb/StorageFactory.ts index 93f4c3ac..ce181a0c 100644 --- a/src/matrix/storage/idb/StorageFactory.ts +++ b/src/matrix/storage/idb/StorageFactory.ts @@ -57,7 +57,7 @@ export class StorageFactory { this._IDBKeyRange = IDBKeyRange; } - async create(sessionId: string) { + async create(sessionId: string): Promise { await this._serviceWorkerHandler?.preventConcurrentSessionAccess(sessionId); requestPersistedStorage().then(persisted => { // Firefox lies here though, and returns true even if the user denied the request diff --git a/src/matrix/storage/idb/Store.ts b/src/matrix/storage/idb/Store.ts index 7dd0b588..585b3948 100644 --- a/src/matrix/storage/idb/Store.ts +++ b/src/matrix/storage/idb/Store.ts @@ -21,7 +21,7 @@ import {Transaction} from "./Transaction"; const LOG_REQUESTS = false; -function logRequest(method: string, params: any[], source: any) { +function logRequest(method: string, params: any[], source: any): void { const storeName = source?.name; const databaseName = source?.transaction?.db?.name; console.info(`${databaseName}.${storeName}.${method}(${params.map(p => JSON.stringify(p)).join(", ")})`); diff --git a/src/matrix/storage/idb/Transaction.ts b/src/matrix/storage/idb/Transaction.ts index 6ad66f22..5aa5fc18 100644 --- a/src/matrix/storage/idb/Transaction.ts +++ b/src/matrix/storage/idb/Transaction.ts @@ -136,11 +136,11 @@ export class Transaction { return this._store("accountData", idbStore => new AccountDataStore(idbStore)); } - complete() { + complete(): Promise { return txnAsPromise(this._txn); } - abort() { + abort(): void { // TODO: should we wrap the exception in a StorageError? this._txn.abort(); } diff --git a/src/matrix/storage/idb/error.ts b/src/matrix/storage/idb/error.ts index 3694b587..02953886 100644 --- a/src/matrix/storage/idb/error.ts +++ b/src/matrix/storage/idb/error.ts @@ -18,8 +18,8 @@ limitations under the License. import { StorageError } from "../common"; export class IDBError extends StorageError { - storeName: string - databaseName: string + storeName: string; + databaseName: string; constructor(message: string, source, cause: DOMException | null) { const storeName = source?.name || ""; diff --git a/src/matrix/storage/idb/stores/InboundGroupSessionStore.ts b/src/matrix/storage/idb/stores/InboundGroupSessionStore.ts index bc49e146..c1ebfc63 100644 --- a/src/matrix/storage/idb/stores/InboundGroupSessionStore.ts +++ b/src/matrix/storage/idb/stores/InboundGroupSessionStore.ts @@ -27,7 +27,7 @@ interface InboundGroupSession { key: string; } -function encodeKey(roomId: string, senderKey: string, sessionId: string) { +function encodeKey(roomId: string, senderKey: string, sessionId: string): string { return `${roomId}|${senderKey}|${sessionId}`; } diff --git a/src/matrix/storage/idb/stores/RoomMemberStore.ts b/src/matrix/storage/idb/stores/RoomMemberStore.ts index 1b3df104..847e8dae 100644 --- a/src/matrix/storage/idb/stores/RoomMemberStore.ts +++ b/src/matrix/storage/idb/stores/RoomMemberStore.ts @@ -50,7 +50,7 @@ export class RoomMemberStore { return this._roomMembersStore.get(encodeKey(roomId, userId)); } - async set(member: MemberData) { + async set(member: MemberData): Promise { // Object.assign would be more typesafe, but small objects (member as any).key = encodeKey(member.roomId, member.userId); return this._roomMembersStore.put(member as MemberStorageEntry); diff --git a/src/matrix/storage/idb/stores/SessionStore.ts b/src/matrix/storage/idb/stores/SessionStore.ts index 1f79839f..bf3d6d11 100644 --- a/src/matrix/storage/idb/stores/SessionStore.ts +++ b/src/matrix/storage/idb/stores/SessionStore.ts @@ -34,15 +34,15 @@ export class SessionStore { } } - set(key: string, value: any) { - this._sessionStore.put({key, value}); + set(key: string, value: any): Promise { + return this._sessionStore.put({key, value}); } - add(key: string, value: any) { - this._sessionStore.add({key, value}); + add(key: string, value: any): Promise { + return this._sessionStore.add({key, value}); } - remove(key: IDBValidKey) { - this._sessionStore.delete(key); + remove(key: IDBValidKey): Promise { + return this._sessionStore.delete(key); } } diff --git a/src/matrix/storage/idb/stores/TimelineEventStore.ts b/src/matrix/storage/idb/stores/TimelineEventStore.ts index e9bdce3a..764b886b 100644 --- a/src/matrix/storage/idb/stores/TimelineEventStore.ts +++ b/src/matrix/storage/idb/stores/TimelineEventStore.ts @@ -69,7 +69,7 @@ class Range { this._upperOpen = upperOpen; } - asIDBKeyRange(roomId: string) { + asIDBKeyRange(roomId: string): IDBKeyRange | undefined { try { // only if (this._only) { @@ -240,7 +240,7 @@ export class TimelineEventStore { let firstFoundKey: string | undefined; // find first result that is found and has no undefined results before it - function firstFoundAndPrecedingResolved() { + function firstFoundAndPrecedingResolved(): string | undefined { for(let i = 0; i < results.length; ++i) { if (results[i] === undefined) { return; diff --git a/src/matrix/storage/idb/stores/TimelineFragmentStore.ts b/src/matrix/storage/idb/stores/TimelineFragmentStore.ts index 7bbae73d..cb89211a 100644 --- a/src/matrix/storage/idb/stores/TimelineFragmentStore.ts +++ b/src/matrix/storage/idb/stores/TimelineFragmentStore.ts @@ -74,13 +74,13 @@ export class TimelineFragmentStore { // should generate an id an return it? // depends if we want to do anything smart with fragment ids, // like give them meaning depending on range. not for now probably ... - add(fragment: Fragment) { + add(fragment: Fragment): Promise { (fragment as any).key = encodeKey(fragment.roomId, fragment.id); - this._store.add(fragment as FragmentEntry); + return this._store.add(fragment as FragmentEntry); } - update(fragment: FragmentEntry) { - this._store.put(fragment); + update(fragment: FragmentEntry): Promise { + return this._store.put(fragment); } get(roomId: string, fragmentId: number): Promise {