Convert IndexedDB code to TypeScript

This commit is contained in:
Evan Hahn 2022-06-01 16:51:30 +00:00 committed by GitHub
parent 638e3e3a58
commit 9c8fd2a714
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 6 additions and 22 deletions

View file

@ -1,61 +0,0 @@
// Copyright 2018-2022 Signal Messenger, LLC
// SPDX-License-Identifier: AGPL-3.0-only
/* global window, clearTimeout, setTimeout */
const LEGACY_DATABASE_ID = 'signal';
const MESSAGE_MINIMUM_VERSION = 7;
module.exports = {
doesDatabaseExist,
MESSAGE_MINIMUM_VERSION,
removeDatabase,
};
async function doesDatabaseExist() {
window.SignalContext.log.info(
'Checking for the existence of IndexedDB data...'
);
return new Promise((resolve, reject) => {
const req = window.indexedDB.open(LEGACY_DATABASE_ID);
let existed = true;
let timer = setTimeout(() => {
window.SignalContext.log.warn(
'doesDatabaseExist: Timed out attempting to check IndexedDB status'
);
return resolve(false);
}, 1000);
const clearTimer = () => {
if (timer !== undefined) {
clearTimeout(timer);
timer = undefined;
}
};
req.onerror = error => {
clearTimer();
reject(error);
};
req.onsuccess = () => {
clearTimer();
req.result.close();
resolve(existed);
};
req.onupgradeneeded = () => {
if (req.result.version === 1) {
existed = false;
window.indexedDB.deleteDatabase(LEGACY_DATABASE_ID);
}
};
});
}
function removeDatabase() {
window.SignalContext.log.info(
`Deleting IndexedDB database '${LEGACY_DATABASE_ID}'`
);
window.indexedDB.deleteDatabase(LEGACY_DATABASE_ID);
}

View file

@ -13,7 +13,6 @@ const Data = require('../../ts/sql/Client').default;
const EmojiLib = require('../../ts/components/emoji/lib');
const Groups = require('../../ts/groups');
const GroupChange = require('../../ts/groupChange');
const IndexedDB = require('./indexeddb');
const OS = require('../../ts/OS');
const Stickers = require('../../ts/types/Stickers');
const RemoteConfig = require('../../ts/RemoteConfig');
@ -419,7 +418,6 @@ exports.setup = (options = {}) => {
EmojiLib,
Groups,
GroupChange,
IndexedDB,
Migrations,
OS,
RemoteConfig,