Add missing return types and semicolons

This commit is contained in:
Danila Fedorin 2021-08-13 16:21:13 -07:00
parent 31b02f1eff
commit b31cf4fdce
12 changed files with 30 additions and 30 deletions

View File

@ -41,8 +41,8 @@ export const STORE_MAP: Readonly<{ [name : string]: string }> = Object.freeze(ST
}, {})); }, {}));
export class StorageError extends Error { export class StorageError extends Error {
errcode?: string errcode?: string;
cause?: Error cause?: Error;
constructor(message: string, cause?: Error) { constructor(message: string, cause?: Error) {
super(message); super(message);

View File

@ -36,7 +36,7 @@ export class QueryTarget<T> {
this._target = target; this._target = target;
} }
_openCursor(range?: IDBQuery, direction?: IDBCursorDirection) { _openCursor(range?: IDBQuery, direction?: IDBCursorDirection): IDBRequest<IDBCursorWithValue | null> {
if (range && direction) { if (range && direction) {
return this._target.openCursor(range, direction); return this._target.openCursor(range, direction);
} else if (range) { } else if (range) {
@ -124,7 +124,7 @@ export class QueryTarget<T> {
async findMaxKey(range: IDBQuery): Promise<IDBValidKey | undefined> { async findMaxKey(range: IDBQuery): Promise<IDBValidKey | undefined> {
const cursor = this._target.openKeyCursor(range, "prev"); const cursor = this._target.openKeyCursor(range, "prev");
let maxKey; let maxKey: IDBValidKey | undefined;
await iterateCursor(cursor, (_, key) => { await iterateCursor(cursor, (_, key) => {
maxKey = key; maxKey = key;
return {done: true}; return {done: true};
@ -133,14 +133,14 @@ export class QueryTarget<T> {
} }
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<void> {
const cursor = this._target.openCursor(range, "next"); const cursor = this._target.openCursor(range, "next");
await iterateCursor<T>(cursor, (value, key, cur) => { await iterateCursor<T>(cursor, (value, key, cur) => {
return {done: callback(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<void> {
const cursor = this._target.openKeyCursor(range, "next"); const cursor = this._target.openKeyCursor(range, "next");
await iterateCursor(cursor, (_, key, cur) => { await iterateCursor(cursor, (_, key, cur) => {
return {done: callback(key, cur)}; return {done: callback(key, cur)};
@ -153,7 +153,7 @@ export class QueryTarget<T> {
* If the callback returns true, the search is halted and callback won't be called again. * 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. * `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<void> {
const direction = backwards ? "prev" : "next"; const direction = backwards ? "prev" : "next";
const compareKeys = (a, b) => backwards ? -indexedDB.cmp(a, b) : indexedDB.cmp(a, b); const compareKeys = (a, b) => backwards ? -indexedDB.cmp(a, b) : indexedDB.cmp(a, b);
const sortedKeys = keys.slice().sort(compareKeys); const sortedKeys = keys.slice().sort(compareKeys);
@ -225,7 +225,7 @@ export class QueryTarget<T> {
return results; return results;
} }
async iterateWhile(range: IDBQuery, predicate: (v: T) => boolean) { async iterateWhile(range: IDBQuery, predicate: (v: T) => boolean): Promise<void> {
const cursor = this._openCursor(range, "next"); const cursor = this._openCursor(range, "next");
await iterateCursor<T>(cursor, (value) => { await iterateCursor<T>(cursor, (value) => {
const passesPredicate = predicate(value); const passesPredicate = predicate(value);

View File

@ -37,7 +37,7 @@ export class Storage {
this.storeNames = Object.freeze(nameMap); this.storeNames = Object.freeze(nameMap);
} }
_validateStoreNames(storeNames: string[]) { _validateStoreNames(storeNames: string[]): void {
const idx = storeNames.findIndex(name => !STORE_NAMES.includes(name)); const idx = storeNames.findIndex(name => !STORE_NAMES.includes(name));
if (idx !== -1) { if (idx !== -1) {
throw new StorageError(`Tried top, a transaction unknown store ${storeNames[idx]}`); throw new StorageError(`Tried top, a transaction unknown store ${storeNames[idx]}`);
@ -76,7 +76,7 @@ export class Storage {
} }
} }
close() { close(): void {
this._db.close(); this._db.close();
} }
} }

View File

@ -57,7 +57,7 @@ export class StorageFactory {
this._IDBKeyRange = IDBKeyRange; this._IDBKeyRange = IDBKeyRange;
} }
async create(sessionId: string) { async create(sessionId: string): Promise<Storage> {
await this._serviceWorkerHandler?.preventConcurrentSessionAccess(sessionId); await this._serviceWorkerHandler?.preventConcurrentSessionAccess(sessionId);
requestPersistedStorage().then(persisted => { requestPersistedStorage().then(persisted => {
// Firefox lies here though, and returns true even if the user denied the request // Firefox lies here though, and returns true even if the user denied the request

View File

@ -21,7 +21,7 @@ import {Transaction} from "./Transaction";
const LOG_REQUESTS = false; 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 storeName = source?.name;
const databaseName = source?.transaction?.db?.name; const databaseName = source?.transaction?.db?.name;
console.info(`${databaseName}.${storeName}.${method}(${params.map(p => JSON.stringify(p)).join(", ")})`); console.info(`${databaseName}.${storeName}.${method}(${params.map(p => JSON.stringify(p)).join(", ")})`);

View File

@ -136,11 +136,11 @@ export class Transaction {
return this._store("accountData", idbStore => new AccountDataStore(idbStore)); return this._store("accountData", idbStore => new AccountDataStore(idbStore));
} }
complete() { complete(): Promise<void> {
return txnAsPromise(this._txn); return txnAsPromise(this._txn);
} }
abort() { abort(): void {
// TODO: should we wrap the exception in a StorageError? // TODO: should we wrap the exception in a StorageError?
this._txn.abort(); this._txn.abort();
} }

View File

@ -18,8 +18,8 @@ limitations under the License.
import { StorageError } from "../common"; import { StorageError } from "../common";
export class IDBError extends StorageError { export class IDBError extends StorageError {
storeName: string storeName: string;
databaseName: string databaseName: string;
constructor(message: string, source, cause: DOMException | null) { constructor(message: string, source, cause: DOMException | null) {
const storeName = source?.name || "<unknown store>"; const storeName = source?.name || "<unknown store>";

View File

@ -27,7 +27,7 @@ interface InboundGroupSession {
key: string; key: string;
} }
function encodeKey(roomId: string, senderKey: string, sessionId: string) { function encodeKey(roomId: string, senderKey: string, sessionId: string): string {
return `${roomId}|${senderKey}|${sessionId}`; return `${roomId}|${senderKey}|${sessionId}`;
} }

View File

@ -50,7 +50,7 @@ export class RoomMemberStore {
return this._roomMembersStore.get(encodeKey(roomId, userId)); return this._roomMembersStore.get(encodeKey(roomId, userId));
} }
async set(member: MemberData) { async set(member: MemberData): Promise<IDBValidKey> {
// Object.assign would be more typesafe, but small objects // Object.assign would be more typesafe, but small objects
(member as any).key = encodeKey(member.roomId, member.userId); (member as any).key = encodeKey(member.roomId, member.userId);
return this._roomMembersStore.put(member as MemberStorageEntry); return this._roomMembersStore.put(member as MemberStorageEntry);

View File

@ -34,15 +34,15 @@ export class SessionStore {
} }
} }
set(key: string, value: any) { set(key: string, value: any): Promise<IDBValidKey> {
this._sessionStore.put({key, value}); return this._sessionStore.put({key, value});
} }
add(key: string, value: any) { add(key: string, value: any): Promise<IDBValidKey> {
this._sessionStore.add({key, value}); return this._sessionStore.add({key, value});
} }
remove(key: IDBValidKey) { remove(key: IDBValidKey): Promise<undefined> {
this._sessionStore.delete(key); return this._sessionStore.delete(key);
} }
} }

View File

@ -69,7 +69,7 @@ class Range {
this._upperOpen = upperOpen; this._upperOpen = upperOpen;
} }
asIDBKeyRange(roomId: string) { asIDBKeyRange(roomId: string): IDBKeyRange | undefined {
try { try {
// only // only
if (this._only) { if (this._only) {
@ -240,7 +240,7 @@ export class TimelineEventStore {
let firstFoundKey: string | undefined; let firstFoundKey: string | undefined;
// find first result that is found and has no undefined results before it // 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) { for(let i = 0; i < results.length; ++i) {
if (results[i] === undefined) { if (results[i] === undefined) {
return; return;

View File

@ -74,13 +74,13 @@ export class TimelineFragmentStore {
// should generate an id an return it? // should generate an id an return it?
// depends if we want to do anything smart with fragment ids, // depends if we want to do anything smart with fragment ids,
// like give them meaning depending on range. not for now probably ... // like give them meaning depending on range. not for now probably ...
add(fragment: Fragment) { add(fragment: Fragment): Promise<IDBValidKey> {
(fragment as any).key = encodeKey(fragment.roomId, fragment.id); (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) { update(fragment: FragmentEntry): Promise<IDBValidKey> {
this._store.put(fragment); return this._store.put(fragment);
} }
get(roomId: string, fragmentId: number): Promise<FragmentEntry | null> { get(roomId: string, fragmentId: number): Promise<FragmentEntry | null> {