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

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

View file

@ -24,6 +24,7 @@ import type {
} from './model-types.d'; } from './model-types.d';
import * as Bytes from './Bytes'; import * as Bytes from './Bytes';
import * as Timers from './Timers'; import * as Timers from './Timers';
import * as indexedDb from './indexeddb';
import type { WhatIsThis } from './window.d'; import type { WhatIsThis } from './window.d';
import type { Receipt } from './types/Receipt'; import type { Receipt } from './types/Receipt';
import { getTitleBarVisibility, TitleBarVisibility } from './types/Settings'; import { getTitleBarVisibility, TitleBarVisibility } from './types/Settings';
@ -494,8 +495,6 @@ export async function startApp(): Promise<void> {
// of preload.js processing // of preload.js processing
window.setImmediate = window.nodeSetImmediate; window.setImmediate = window.nodeSetImmediate;
const { removeDatabase: removeIndexedDB, doesDatabaseExist } =
window.Signal.IndexedDB;
const { Message } = window.Signal.Types; const { Message } = window.Signal.Types;
const { const {
upgradeMessageSchema, upgradeMessageSchema,
@ -551,7 +550,7 @@ export async function startApp(): Promise<void> {
const version = await window.Signal.Data.getItemById('version'); const version = await window.Signal.Data.getItemById('version');
if (!version) { if (!version) {
const isIndexedDBPresent = await doesDatabaseExist(); const isIndexedDBPresent = await indexedDb.doesDatabaseExist();
if (isIndexedDBPresent) { if (isIndexedDBPresent) {
log.info('Found IndexedDB database.'); log.info('Found IndexedDB database.');
try { try {
@ -582,7 +581,7 @@ export async function startApp(): Promise<void> {
log.info('Deleting IndexedDB file...'); log.info('Deleting IndexedDB file...');
await Promise.all([ await Promise.all([
removeIndexedDB(), indexedDb.removeDatabase(),
window.Signal.Data.removeAll(), window.Signal.Data.removeAll(),
window.Signal.Data.removeIndexedDBFiles(), window.Signal.Data.removeIndexedDBFiles(),
]); ]);

View file

@ -1,18 +1,9 @@
// Copyright 2018-2022 Signal Messenger, LLC // Copyright 2018-2022 Signal Messenger, LLC
// SPDX-License-Identifier: AGPL-3.0-only // SPDX-License-Identifier: AGPL-3.0-only
/* global window, clearTimeout, setTimeout */
const LEGACY_DATABASE_ID = 'signal'; const LEGACY_DATABASE_ID = 'signal';
const MESSAGE_MINIMUM_VERSION = 7;
module.exports = { export async function doesDatabaseExist(): Promise<boolean> {
doesDatabaseExist,
MESSAGE_MINIMUM_VERSION,
removeDatabase,
};
async function doesDatabaseExist() {
window.SignalContext.log.info( window.SignalContext.log.info(
'Checking for the existence of IndexedDB data...' 'Checking for the existence of IndexedDB data...'
); );
@ -21,7 +12,7 @@ async function doesDatabaseExist() {
let existed = true; let existed = true;
let timer = setTimeout(() => { let timer: undefined | ReturnType<typeof setTimeout> = setTimeout(() => {
window.SignalContext.log.warn( window.SignalContext.log.warn(
'doesDatabaseExist: Timed out attempting to check IndexedDB status' 'doesDatabaseExist: Timed out attempting to check IndexedDB status'
); );
@ -53,7 +44,7 @@ async function doesDatabaseExist() {
}); });
} }
function removeDatabase() { export function removeDatabase(): void {
window.SignalContext.log.info( window.SignalContext.log.info(
`Deleting IndexedDB database '${LEGACY_DATABASE_ID}'` `Deleting IndexedDB database '${LEGACY_DATABASE_ID}'`
); );

4
ts/window.d.ts vendored
View file

@ -398,10 +398,6 @@ declare global {
WhatsNewLink: typeof WhatsNewLink; WhatsNewLink: typeof WhatsNewLink;
}; };
OS: typeof OS; OS: typeof OS;
IndexedDB: {
removeDatabase: WhatIsThis;
doesDatabaseExist: WhatIsThis;
};
Views: WhatIsThis; Views: WhatIsThis;
State: { State: {
createStore: typeof createStore; createStore: typeof createStore;