Convert IDBLogger to ts
This commit is contained in:
parent
f3d0f88f95
commit
8c7a765e11
2 changed files with 22 additions and 5 deletions
|
@ -23,8 +23,21 @@ import {
|
||||||
fetchResults,
|
fetchResults,
|
||||||
} from "../matrix/storage/idb/utils";
|
} from "../matrix/storage/idb/utils";
|
||||||
import {BaseLogger} from "./BaseLogger";
|
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 {
|
export class IDBLogger extends BaseLogger {
|
||||||
|
private readonly _name: string;
|
||||||
|
private readonly _limit: number;
|
||||||
|
private readonly _flushInterval: Interval;
|
||||||
|
private _queuedItems: QueuedItem[];
|
||||||
|
|
||||||
constructor(options) {
|
constructor(options) {
|
||||||
super(options);
|
super(options);
|
||||||
const {name, flushInterval = 60 * 1000, limit = 3000} = options;
|
const {name, flushInterval = 60 * 1000, limit = 3000} = options;
|
||||||
|
@ -121,7 +134,7 @@ export class IDBLogger extends BaseLogger {
|
||||||
try {
|
try {
|
||||||
const txn = db.transaction(["logs"], "readonly");
|
const txn = db.transaction(["logs"], "readonly");
|
||||||
const logs = txn.objectStore("logs");
|
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);
|
const allItems = storedItems.concat(this._queuedItems);
|
||||||
return new IDBLogExport(allItems, this, this._platform);
|
return new IDBLogExport(allItems, this, this._platform);
|
||||||
} finally {
|
} finally {
|
||||||
|
@ -154,7 +167,11 @@ export class IDBLogger extends BaseLogger {
|
||||||
}
|
}
|
||||||
|
|
||||||
class IDBLogExport {
|
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._items = items;
|
||||||
this._logger = logger;
|
this._logger = logger;
|
||||||
this._platform = platform;
|
this._platform = platform;
|
||||||
|
@ -171,7 +188,7 @@ class IDBLogExport {
|
||||||
return this._logger._removeItems(this._items);
|
return this._logger._removeItems(this._items);
|
||||||
}
|
}
|
||||||
|
|
||||||
asBlob() {
|
asBlob(): BlobHandle {
|
||||||
const log = {
|
const log = {
|
||||||
formatVersion: 1,
|
formatVersion: 1,
|
||||||
appVersion: this._platform.updateService?.version,
|
appVersion: this._platform.updateService?.version,
|
||||||
|
@ -179,7 +196,7 @@ class IDBLogExport {
|
||||||
};
|
};
|
||||||
const json = JSON.stringify(log);
|
const json = JSON.stringify(log);
|
||||||
const buffer = this._platform.encoding.utf8.encode(json);
|
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;
|
return blob;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,7 +21,7 @@ import {SessionInfoStorage} from "../../matrix/sessioninfo/localstorage/SessionI
|
||||||
import {SettingsStorage} from "./dom/SettingsStorage.js";
|
import {SettingsStorage} from "./dom/SettingsStorage.js";
|
||||||
import {Encoding} from "./utils/Encoding.js";
|
import {Encoding} from "./utils/Encoding.js";
|
||||||
import {OlmWorker} from "../../matrix/e2ee/OlmWorker.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 {ConsoleLogger} from "../../logging/ConsoleLogger.js";
|
||||||
import {RootView} from "./ui/RootView.js";
|
import {RootView} from "./ui/RootView.js";
|
||||||
import {Clock} from "./dom/Clock.js";
|
import {Clock} from "./dom/Clock.js";
|
||||||
|
|
Reference in a new issue