From 7097ba07d168d1a4156099dd9967310aebfa415a Mon Sep 17 00:00:00 2001 From: RMidhunSuresh Date: Mon, 15 Nov 2021 18:59:33 +0530 Subject: [PATCH] Replace LogLabelOrNull type with undefined --- src/logging/BaseLogger.ts | 11 +++++------ src/logging/IDBLogger.ts | 1 + src/logging/LogFilter.ts | 2 -- src/logging/LogItem.ts | 25 ++++++++++++------------ src/matrix/storage/idb/StorageFactory.ts | 5 ++--- src/matrix/storage/idb/Transaction.ts | 2 +- src/matrix/storage/idb/schema.ts | 4 ++-- 7 files changed, 23 insertions(+), 27 deletions(-) diff --git a/src/logging/BaseLogger.ts b/src/logging/BaseLogger.ts index 28602b17..6c377d48 100644 --- a/src/logging/BaseLogger.ts +++ b/src/logging/BaseLogger.ts @@ -18,7 +18,6 @@ limitations under the License. import {LogItem} from "./LogItem"; import {LogLevel, LogFilter} from "./LogFilter"; import type {FilterCreator, LabelOrValues, LogCallback, ILogItem} from "./LogItem"; -import type {LogLevelOrNull} from "./LogFilter"; // todo: should this import be here just for getting the type? should it instead be done when Platform.js --> Platform.ts? import type {Platform} from "../platform/web/Platform.js"; @@ -38,7 +37,7 @@ export abstract class BaseLogger { } /** if item is a log item, wrap the callback in a child of it, otherwise start a new root log item. */ - wrapOrRun(item: ILogItem, labelOrValues: LabelOrValues, callback: LogCallback, logLevel: LogLevelOrNull = null, filterCreator?: FilterCreator): unknown { + wrapOrRun(item: ILogItem, labelOrValues: LabelOrValues, callback: LogCallback, logLevel?: LogLevel, filterCreator?: FilterCreator): unknown { if (item) { return item.wrap(labelOrValues, callback, logLevel, filterCreator); } else { @@ -51,9 +50,9 @@ export abstract class BaseLogger { Useful to pair with LogItem.refDetached. @return {LogItem} the log item added, useful to pass to LogItem.refDetached */ - runDetached(labelOrValues: LabelOrValues, callback: LogCallback, logLevel: LogLevelOrNull = null, filterCreator?: FilterCreator): ILogItem { + runDetached(labelOrValues: LabelOrValues, callback: LogCallback, logLevel?: LogLevel, filterCreator?: FilterCreator): ILogItem { // todo: Remove jsdoc type? - if (logLevel === null) { + if (!logLevel) { logLevel = LogLevel.Info; } const item = new LogItem(labelOrValues, logLevel, this); @@ -64,8 +63,8 @@ export abstract class BaseLogger { /** run a callback wrapped in a log operation. Errors and duration are transparently logged, also for async operations. Whatever the callback returns is returned here. */ - run(labelOrValues: LabelOrValues, callback: LogCallback, logLevel: LogLevelOrNull = null, filterCreator?: FilterCreator): unknown { - if (logLevel === null) { + run(labelOrValues: LabelOrValues, callback: LogCallback, logLevel?: LogLevel, filterCreator?: FilterCreator): unknown { + if (!logLevel) { logLevel = LogLevel.Info; } const item = new LogItem(labelOrValues, logLevel, this); diff --git a/src/logging/IDBLogger.ts b/src/logging/IDBLogger.ts index 960db0da..d5ce2f9a 100644 --- a/src/logging/IDBLogger.ts +++ b/src/logging/IDBLogger.ts @@ -40,6 +40,7 @@ export class IDBLogger extends BaseLogger { private readonly _flushInterval: Interval; private _queuedItems: QueuedItem[]; + // todo: type constructor constructor(options) { super(options); const {name, flushInterval = 60 * 1000, limit = 3000} = options; diff --git a/src/logging/LogFilter.ts b/src/logging/LogFilter.ts index dc415ede..9968e63e 100644 --- a/src/logging/LogFilter.ts +++ b/src/logging/LogFilter.ts @@ -27,8 +27,6 @@ export enum LogLevel { Off } -export type LogLevelOrNull = LogLevel | null; - export class LogFilter { private _min?: LogLevel; private _parentFilter?: LogFilter; diff --git a/src/logging/LogItem.ts b/src/logging/LogItem.ts index c40d7c08..c0325ca7 100644 --- a/src/logging/LogItem.ts +++ b/src/logging/LogItem.ts @@ -16,7 +16,6 @@ limitations under the License. */ import {LogLevel, LogFilter} from "./LogFilter"; -import type {LogLevelOrNull} from "./LogFilter"; import type {BaseLogger} from "./BaseLogger"; interface ISerializedItem { @@ -43,17 +42,17 @@ export interface ILogItem { children: Array | null; values: LogItemValues; error: Error | null; - wrap(labelOrValues: LabelOrValues, callback: LogCallback, level: LogLevelOrNull, filterCreator?: FilterCreator): unknown; - log(labelOrValues: LabelOrValues, logLevel: LogLevelOrNull): void; + wrap(labelOrValues: LabelOrValues, callback: LogCallback, logLevel?: LogLevel, filterCreator?: FilterCreator): unknown; + log(labelOrValues: LabelOrValues, logLevel?: LogLevel): void; set(key: string | object, value: unknown): void; run(callback: LogCallback): unknown; - runDetached(labelOrValues: LabelOrValues, callback: LogCallback, logLevel: LogLevelOrNull, filterCreator: FilterCreator): ILogItem; - wrapDetached(labelOrValues: LabelOrValues, callback: LogCallback, logLevel: LogLevelOrNull, filterCreator: FilterCreator): void; - refDetached(logItem: ILogItem, logLevel: LogLevelOrNull): void; + runDetached(labelOrValues: LabelOrValues, callback: LogCallback, logLevel?: LogLevel, filterCreator?: FilterCreator): ILogItem; + wrapDetached(labelOrValues: LabelOrValues, callback: LogCallback, logLevel?: LogLevel, filterCreator?: FilterCreator): void; + refDetached(logItem: ILogItem, logLevel?: LogLevel): void; ensureRefId(): void; catch(err: Error): Error; finish(): void; - child(labelOrValues: LabelOrValues, logLevel: LogLevelOrNull, filterCreator: FilterCreator): ILogItem; + child(labelOrValues: LabelOrValues, logLevel?: LogLevel, filterCreator?: FilterCreator): ILogItem; serialize(filter: LogFilter, parentStartTime: number | null, forced: boolean): ISerializedItem | null; } @@ -94,18 +93,18 @@ export class LogItem implements ILogItem { } /** start a new root log item and run it detached mode, see BaseLogger.runDetached */ - runDetached(labelOrValues: LabelOrValues, callback: LogCallback, logLevel: LogLevelOrNull, filterCreator: FilterCreator): ILogItem { + runDetached(labelOrValues: LabelOrValues, callback: LogCallback, logLevel?: LogLevel, filterCreator?: FilterCreator): ILogItem { return this._logger.runDetached(labelOrValues, callback, logLevel, filterCreator); } /** start a new detached root log item and log a reference to it from this item */ - wrapDetached(labelOrValues: LabelOrValues, callback: LogCallback, logLevel: LogLevelOrNull, filterCreator: FilterCreator): void { + wrapDetached(labelOrValues: LabelOrValues, callback: LogCallback, logLevel?: LogLevel, filterCreator?: FilterCreator): void { this.refDetached(this.runDetached(labelOrValues, callback, logLevel, filterCreator)); } /** logs a reference to a different log item, usually obtained from runDetached. This is useful if the referenced operation can't be awaited. */ - refDetached(logItem: ILogItem, logLevel: LogLevelOrNull = null): void { + refDetached(logItem: ILogItem, logLevel?: LogLevel): void { logItem.ensureRefId(); this.log({ref: (logItem as LogItem)._values.refId}, logLevel); } @@ -119,7 +118,7 @@ export class LogItem implements ILogItem { /** * Creates a new child item and runs it in `callback`. */ - wrap(labelOrValues: LabelOrValues, callback: LogCallback, logLevel: LogLevelOrNull = null, filterCreator?: FilterCreator): unknown { + wrap(labelOrValues: LabelOrValues, callback: LogCallback, logLevel?: LogLevel, filterCreator?: FilterCreator): unknown { const item = this.child(labelOrValues, logLevel, filterCreator); return item.run(callback); } @@ -160,7 +159,7 @@ export class LogItem implements ILogItem { * * Hence, the child item is not returned. */ - log(labelOrValues: LabelOrValues, logLevel: LogLevelOrNull = null): void { + log(labelOrValues: LabelOrValues, logLevel?: LogLevel): void { const item = this.child(labelOrValues, logLevel); item.end = item.start; } @@ -291,7 +290,7 @@ export class LogItem implements ILogItem { return err; } - child(labelOrValues: LabelOrValues, logLevel: LogLevelOrNull, filterCreator?: FilterCreator): ILogItem { + child(labelOrValues: LabelOrValues, logLevel?: LogLevel, filterCreator?: FilterCreator): ILogItem { if (this.end !== null) { console.trace("log item is finished, additional logs will likely not be recorded"); } diff --git a/src/matrix/storage/idb/StorageFactory.ts b/src/matrix/storage/idb/StorageFactory.ts index 5c257bfb..120f73f5 100644 --- a/src/matrix/storage/idb/StorageFactory.ts +++ b/src/matrix/storage/idb/StorageFactory.ts @@ -101,8 +101,7 @@ async function createStores(db: IDBDatabase, txn: IDBTransaction, oldVersion: nu async (log) => { for (let i = startIdx; i < version; ++i) { const migrationFunc = schema[i]; - await log.wrap(`v${i + 1}`, (log) => migrationFunc(db, txn, localStorage, log), null); + await log.wrap(`v${i + 1}`, (log) => migrationFunc(db, txn, localStorage, log)); } - }, - null) as Promise; + }) as Promise; } diff --git a/src/matrix/storage/idb/Transaction.ts b/src/matrix/storage/idb/Transaction.ts index c68a1759..4c3d2b5c 100644 --- a/src/matrix/storage/idb/Transaction.ts +++ b/src/matrix/storage/idb/Transaction.ts @@ -226,7 +226,7 @@ export class Transaction { }; const label = `${this._writeErrors.length} storage write operation(s) failed`; if (parentItem) { - parentItem.wrap(label, callback, null); + parentItem.wrap(label, callback); } else { this.logger.run(label, callback); } diff --git a/src/matrix/storage/idb/schema.ts b/src/matrix/storage/idb/schema.ts index b21bd30f..6250980d 100644 --- a/src/matrix/storage/idb/schema.ts +++ b/src/matrix/storage/idb/schema.ts @@ -196,7 +196,7 @@ async function fixMissingRoomsInUserIdentities(db: IDBDatabase, txn: IDBTransact const updatedIdentity = addRoomToIdentity(identity, userId, roomId); if (updatedIdentity) { log.log({l: `fixing up`, id: userId, - roomsBefore: originalRoomCount, roomsAfter: updatedIdentity.roomIds.length}, null); + roomsBefore: originalRoomCount, roomsAfter: updatedIdentity.roomIds.length}); userIdentitiesStore.put(updatedIdentity); foundMissing = true; } @@ -207,7 +207,7 @@ async function fixMissingRoomsInUserIdentities(db: IDBDatabase, txn: IDBTransact // so we'll create a new one on the next message that will be properly shared outboundGroupSessionsStore.delete(roomId); } - }, null); + }); } }