From 8c7a765e1114762a65be741407e16613e5012877 Mon Sep 17 00:00:00 2001 From: RMidhunSuresh Date: Fri, 12 Nov 2021 15:06:21 +0530 Subject: [PATCH] Convert IDBLogger to ts --- src/logging/IDBLogger.ts | 25 +++++++++++++++++++++---- src/platform/web/Platform.js | 2 +- 2 files changed, 22 insertions(+), 5 deletions(-) diff --git a/src/logging/IDBLogger.ts b/src/logging/IDBLogger.ts index 2360b54c..93ba9549 100644 --- a/src/logging/IDBLogger.ts +++ b/src/logging/IDBLogger.ts @@ -23,8 +23,21 @@ import { fetchResults, } from "../matrix/storage/idb/utils"; import {BaseLogger} from "./BaseLogger"; +import type {Interval} from "../platform/web/dom/Clock"; +import type {Platform} from "../platform/web/Platform.js"; +import type {BlobHandle} from "../platform/web/dom/BlobHandle.js"; + +type QueuedItem = { + json: string; + id?: number; +} export class IDBLogger extends BaseLogger { + private readonly _name: string; + private readonly _limit: number; + private readonly _flushInterval: Interval; + private _queuedItems: QueuedItem[]; + constructor(options) { super(options); const {name, flushInterval = 60 * 1000, limit = 3000} = options; @@ -121,7 +134,7 @@ export class IDBLogger extends BaseLogger { try { const txn = db.transaction(["logs"], "readonly"); const logs = txn.objectStore("logs"); - const storedItems = await fetchResults(logs.openCursor(), () => false); + const storedItems: QueuedItem[] = await fetchResults(logs.openCursor(), () => false); const allItems = storedItems.concat(this._queuedItems); return new IDBLogExport(allItems, this, this._platform); } finally { @@ -154,7 +167,11 @@ export class IDBLogger extends BaseLogger { } class IDBLogExport { - constructor(items, logger, platform) { + private readonly _items: QueuedItem[]; + private readonly _logger: IDBLogger; + private readonly _platform: Platform; + + constructor(items: QueuedItem[], logger: IDBLogger, platform: Platform) { this._items = items; this._logger = logger; this._platform = platform; @@ -171,7 +188,7 @@ class IDBLogExport { return this._logger._removeItems(this._items); } - asBlob() { + asBlob(): BlobHandle { const log = { formatVersion: 1, appVersion: this._platform.updateService?.version, @@ -179,7 +196,7 @@ class IDBLogExport { }; const json = JSON.stringify(log); const buffer = this._platform.encoding.utf8.encode(json); - const blob = this._platform.createBlob(buffer, "application/json"); + const blob: BlobHandle = this._platform.createBlob(buffer, "application/json"); return blob; } } diff --git a/src/platform/web/Platform.js b/src/platform/web/Platform.js index 1530ed12..63cbac2e 100644 --- a/src/platform/web/Platform.js +++ b/src/platform/web/Platform.js @@ -21,7 +21,7 @@ import {SessionInfoStorage} from "../../matrix/sessioninfo/localstorage/SessionI import {SettingsStorage} from "./dom/SettingsStorage.js"; import {Encoding} from "./utils/Encoding.js"; import {OlmWorker} from "../../matrix/e2ee/OlmWorker.js"; -import {IDBLogger} from "../../logging/IDBLogger.js"; +import {IDBLogger} from "../../logging/IDBLogger"; import {ConsoleLogger} from "../../logging/ConsoleLogger.js"; import {RootView} from "./ui/RootView.js"; import {Clock} from "./dom/Clock.js";