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 {
errcode?: string
cause?: Error
errcode?: string;
cause?: Error;
constructor(message: string, cause?: Error) {
super(message);

View file

@ -36,7 +36,7 @@ export class QueryTarget<T> {
this._target = target;
}
_openCursor(range?: IDBQuery, direction?: IDBCursorDirection) {
_openCursor(range?: IDBQuery, direction?: IDBCursorDirection): IDBRequest<IDBCursorWithValue | null> {
if (range && direction) {
return this._target.openCursor(range, direction);
} else if (range) {
@ -124,7 +124,7 @@ export class QueryTarget<T> {
async findMaxKey(range: IDBQuery): Promise<IDBValidKey | undefined> {
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<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");
await iterateCursor<T>(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<void> {
const cursor = this._target.openKeyCursor(range, "next");
await iterateCursor(cursor, (_, 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.
* `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 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<T> {
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");
await iterateCursor<T>(cursor, (value) => {
const passesPredicate = predicate(value);

View file

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

View file

@ -57,7 +57,7 @@ export class StorageFactory {
this._IDBKeyRange = IDBKeyRange;
}
async create(sessionId: string) {
async create(sessionId: string): Promise<Storage> {
await this._serviceWorkerHandler?.preventConcurrentSessionAccess(sessionId);
requestPersistedStorage().then(persisted => {
// 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;
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(", ")})`);

View file

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

View file

@ -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 || "<unknown store>";

View file

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

View file

@ -50,7 +50,7 @@ export class RoomMemberStore {
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
(member as any).key = encodeKey(member.roomId, member.userId);
return this._roomMembersStore.put(member as MemberStorageEntry);

View file

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

View file

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

View file

@ -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<IDBValidKey> {
(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<IDBValidKey> {
return this._store.put(fragment);
}
get(roomId: string, fragmentId: number): Promise<FragmentEntry | null> {