From 3ee160729883dd6ac71f1d1e05da112f18f54781 Mon Sep 17 00:00:00 2001 From: RMidhunSuresh Date: Tue, 16 Nov 2021 12:32:49 +0530 Subject: [PATCH] Convert utils to typescript --- src/logging/utils.js | 16 ---------------- src/logging/utils.ts | 18 ++++++++++++++++++ src/matrix/room/BaseRoom.js | 2 +- 3 files changed, 19 insertions(+), 17 deletions(-) delete mode 100644 src/logging/utils.js create mode 100644 src/logging/utils.ts diff --git a/src/logging/utils.js b/src/logging/utils.js deleted file mode 100644 index 659df055..00000000 --- a/src/logging/utils.js +++ /dev/null @@ -1,16 +0,0 @@ -// these are helper functions if you can't assume you always have a log item (e.g. some code paths call with one set, others don't) -// if you know you always have a log item, better to use the methods on the log item than these utility functions. - -import {Instance as NullLoggerInstance} from "./NullLogger"; - -export function wrapOrRunNullLogger(logItem, labelOrValues, callback, logLevel = null, filterCreator = null) { - if (logItem) { - return logItem.wrap(logItem, labelOrValues, callback, logLevel, filterCreator); - } else { - return NullLoggerInstance.run(null, callback); - } -} - -export function ensureLogItem(logItem) { - return logItem || NullLoggerInstance.item; -} diff --git a/src/logging/utils.ts b/src/logging/utils.ts new file mode 100644 index 00000000..61cbce80 --- /dev/null +++ b/src/logging/utils.ts @@ -0,0 +1,18 @@ +// these are helper functions if you can't assume you always have a log item (e.g. some code paths call with one set, others don't) +// if you know you always have a log item, better to use the methods on the log item than these utility functions. + +import {Instance as NullLoggerInstance} from "./NullLogger"; +import type {FilterCreator, ILogItem, LabelOrValues, LogCallback} from "./LogItem"; +import {LogLevel} from "./LogFilter"; + +export function wrapOrRunNullLogger(logItem: ILogItem | undefined, labelOrValues: LabelOrValues, callback: LogCallback, logLevel?: LogLevel, filterCreator?: FilterCreator): T | Promise { + if (logItem) { + return logItem.wrap(labelOrValues, callback, logLevel, filterCreator); + } else { + return NullLoggerInstance.run(null, callback); + } +} + +export function ensureLogItem(logItem: ILogItem): ILogItem { + return logItem || NullLoggerInstance.item; +} diff --git a/src/matrix/room/BaseRoom.js b/src/matrix/room/BaseRoom.js index 1aa8cb18..93973b71 100644 --- a/src/matrix/room/BaseRoom.js +++ b/src/matrix/room/BaseRoom.js @@ -27,7 +27,7 @@ import {Heroes} from "./members/Heroes.js"; import {EventEntry} from "./timeline/entries/EventEntry.js"; import {ObservedEventMap} from "./ObservedEventMap.js"; import {DecryptionSource} from "../e2ee/common.js"; -import {ensureLogItem} from "../../logging/utils.js"; +import {ensureLogItem} from "../../logging/utils"; import {PowerLevels} from "./PowerLevels.js"; import {RetainedObservableValue} from "../../observable/ObservableValue";