Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F3383626
D11236.id38132.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
31 KB
Referenced Files
None
Subscribers
None
D11236.id38132.diff
View Options
diff --git a/.eslintignore b/.eslintignore
--- a/.eslintignore
+++ b/.eslintignore
@@ -7,7 +7,7 @@
web/flow-typed
web/node_modules
web/opaque-ke-wasm/pkg
-web/database/_generated
+web/shared-worker/_generated
web/backup-client-wasm/wasm/backup-client-wasm.js
keyserver/app_compiled
keyserver/landing_compiled
diff --git a/.gitignore b/.gitignore
--- a/.gitignore
+++ b/.gitignore
@@ -9,8 +9,8 @@
web/node_modules
web/dist
-web/database/sqlite
-web/database/_generated/comm-query-executor.js.bak
+web/shared-worker/sqlite
+web/shared-worker/_generated/comm-query-executor.js.bak
web/backup-client-wasm/wasm/backup-client-wasm_bg.wasm
web/backup-client-wasm/wasm/backup-client-wasm.js
web/backup-client-wasm/target
diff --git a/web/account/account-hooks.js b/web/account/account-hooks.js
--- a/web/account/account-hooks.js
+++ b/web/account/account-hooks.js
@@ -29,7 +29,6 @@
encryptData,
exportKeyToJWK,
} from '../crypto/aes-gcm-crypto-utils.js';
-import { isDesktopSafari } from '../database/utils/db-utils.js';
import { initOlm } from '../olm/olm-utils.js';
import {
getOlmDataContentKeyForCookie,
@@ -37,6 +36,7 @@
} from '../push-notif/notif-crypto-utils.js';
import { setCryptoStore } from '../redux/crypto-store-reducer.js';
import { useSelector } from '../redux/redux-utils.js';
+import { isDesktopSafari } from '../shared-worker/utils/db-utils.js';
const CryptoStoreContext: React.Context<?CryptoStoreContextType> =
React.createContext(null);
diff --git a/web/app.react.js b/web/app.react.js
--- a/web/app.react.js
+++ b/web/app.react.js
@@ -50,7 +50,6 @@
import NavigationArrows from './components/navigation-arrows.react.js';
import { olmAPI } from './crypto/olm-api.js';
import { initOpaque } from './crypto/opaque-utils.js';
-import { getDatabaseModule } from './database/database-module-provider.js';
import electron from './electron.js';
import InputStateContainer from './input/input-state-container.react.js';
import InviteLinkHandler from './invite-links/invite-link-handler.react.js';
@@ -76,6 +75,7 @@
import AccountSettings from './settings/account-settings.react.js';
import DangerZone from './settings/danger-zone.react.js';
import KeyserverSelectionList from './settings/keyserver-selection-list.react.js';
+import { getCommSharedWorker } from './shared-worker/shared-worker-provider.js';
import CommunityPicker from './sidebar/community-picker.react.js';
import Splash from './splash/splash.react.js';
import './typography.css';
@@ -120,8 +120,8 @@
}
};
-// Start initializing the database immediately
-void getDatabaseModule();
+// Start initializing the shared worker immediately
+void getCommSharedWorker();
type BaseProps = {
+location: {
diff --git a/web/package.json b/web/package.json
--- a/web/package.json
+++ b/web/package.json
@@ -5,12 +5,12 @@
"private": true,
"license": "BSD-3-Clause",
"scripts": {
- "clean": "rm -rf dist/ && rm -rf node_modules/ && rm -rf database/sqlite/ && rm -f backup-client-wasm/wasm/backup-client-wasm_bg.wasm && rm -f backup-client-wasm/wasm/backup-client-wasm.js && rm -rf backup-client-wasm/target",
+ "clean": "rm -rf dist/ && rm -rf node_modules/ && rm -rf shared-worker/sqlite/ && rm -f backup-client-wasm/wasm/backup-client-wasm_bg.wasm && rm -f backup-client-wasm/wasm/backup-client-wasm.js && rm -rf backup-client-wasm/target",
"dev": "yarn workspace keyserver babel-build-comm-config && yarn concurrently --names=\"NODESSR,BROWSER,WORKERS\" -c \"bgBlue.bold,bgMagenta.bold,bgCyan.bold\" \"yarn webpack --config webpack.config.cjs --config-name=server --watch\" \"yarn webpack-dev-server --config webpack.config.cjs --config-name=browser\" \"yarn webpack --config webpack.config.cjs --config-name=webworkers --watch\"",
"prod": "yarn workspace keyserver babel-build-comm-config && yarn webpack --config webpack.config.cjs --env prod --progress",
"test": "jest",
"build-db-wasm": "./scripts/run_emscripten.sh",
- "clean-db-wasm": "rm -rf database/_generated/ && rm -rf database/sqlite/",
+ "clean-db-wasm": "rm -rf shared-worker/_generated/ && rm -rf shared-worker/sqlite/",
"build-backup-client-wasm": "./scripts/run-wasmpack.sh",
"codegen-identity-grpc": "./scripts/codegen-identity-grpc.sh",
"postinstall": "bash ./scripts/postinstall.sh"
diff --git a/web/push-notif/notif-crypto-utils.js b/web/push-notif/notif-crypto-utils.js
--- a/web/push-notif/notif-crypto-utils.js
+++ b/web/push-notif/notif-crypto-utils.js
@@ -19,12 +19,12 @@
encryptData,
importJWKKey,
} from '../crypto/aes-gcm-crypto-utils.js';
+import { initOlm } from '../olm/olm-utils.js';
import {
NOTIFICATIONS_OLM_DATA_CONTENT,
NOTIFICATIONS_OLM_DATA_ENCRYPTION_KEY,
-} from '../database/utils/constants.js';
-import { isDesktopSafari } from '../database/utils/db-utils.js';
-import { initOlm } from '../olm/olm-utils.js';
+} from '../shared-worker/utils/constants.js';
+import { isDesktopSafari } from '../shared-worker/utils/db-utils.js';
export type WebNotifDecryptionError = {
+id: string,
diff --git a/web/push-notif/push-notifs-handler.js b/web/push-notif/push-notifs-handler.js
--- a/web/push-notif/push-notifs-handler.js
+++ b/web/push-notif/push-notifs-handler.js
@@ -18,14 +18,14 @@
import { decryptDesktopNotification } from './notif-crypto-utils.js';
import { authoritativeKeyserverID } from '../authoritative-keyserver.js';
-import {
- WORKERS_MODULES_DIR_PATH,
- DEFAULT_OLM_FILENAME,
-} from '../database/utils/constants.js';
import electron from '../electron.js';
import PushNotifModal from '../modals/push-notif-modal.react.js';
import { updateNavInfoActionType } from '../redux/action-types.js';
import { useSelector } from '../redux/redux-utils.js';
+import {
+ WORKERS_MODULES_DIR_PATH,
+ DEFAULT_OLM_FILENAME,
+} from '../shared-worker/utils/constants.js';
import { useStaffCanSee } from '../utils/staff-utils.js';
declare var baseURL: string;
diff --git a/web/push-notif/service-worker.js b/web/push-notif/service-worker.js
--- a/web/push-notif/service-worker.js
+++ b/web/push-notif/service-worker.js
@@ -15,7 +15,7 @@
type WebNotifDecryptionError,
} from './notif-crypto-utils.js';
import { authoritativeKeyserverID } from '../authoritative-keyserver.js';
-import { localforageConfig } from '../database/utils/constants.js';
+import { localforageConfig } from '../shared-worker/utils/constants.js';
declare class PushMessageData {
json(): Object;
diff --git a/web/redux/comm-redux-storage-engine.js b/web/redux/comm-redux-storage-engine.js
--- a/web/redux/comm-redux-storage-engine.js
+++ b/web/redux/comm-redux-storage-engine.js
@@ -2,18 +2,18 @@
import storage from 'redux-persist/es/storage/index.js';
-import { getDatabaseModule } from '../database/database-module-provider.js';
+import { getCommSharedWorker } from '../shared-worker/shared-worker-provider.js';
import { workerRequestMessageTypes } from '../types/worker-types.js';
const commReduxStorageEngine = {
getItem: async (key: string): Promise<string> => {
- const databaseModule = await getDatabaseModule();
- const isSupported = await databaseModule.isDatabaseSupported();
+ const sharedWorker = await getCommSharedWorker();
+ const isSupported = await sharedWorker.isSupported();
if (!isSupported) {
return await storage.getItem(key);
}
- const result = await databaseModule.schedule({
+ const result = await sharedWorker.schedule({
type: workerRequestMessageTypes.GET_PERSIST_STORAGE_ITEM,
key,
});
@@ -23,28 +23,28 @@
return result.item;
},
setItem: async (key: string, item: string): Promise<void> => {
- const databaseModule = await getDatabaseModule();
- const isSupported = await databaseModule.isDatabaseSupported();
+ const sharedWorker = await getCommSharedWorker();
+ const isSupported = await sharedWorker.isSupported();
if (!isSupported) {
await storage.setItem(key, item);
return;
}
- await databaseModule.schedule({
+ await sharedWorker.schedule({
type: workerRequestMessageTypes.SET_PERSIST_STORAGE_ITEM,
key,
item,
});
},
removeItem: async (key: string): Promise<void> => {
- const databaseModule = await getDatabaseModule();
- const isSupported = await databaseModule.isDatabaseSupported();
+ const sharedWorker = await getCommSharedWorker();
+ const isSupported = await sharedWorker.isSupported();
if (!isSupported) {
await storage.removeItem(key);
return;
}
- await databaseModule.schedule({
+ await sharedWorker.schedule({
type: workerRequestMessageTypes.REMOVE_PERSIST_STORAGE_ITEM,
key,
});
diff --git a/web/redux/initial-state-gate.js b/web/redux/initial-state-gate.js
--- a/web/redux/initial-state-gate.js
+++ b/web/redux/initial-state-gate.js
@@ -21,11 +21,11 @@
} from './action-types.js';
import { useSelector } from './redux-utils.js';
import { authoritativeKeyserverID } from '../authoritative-keyserver.js';
+import Loading from '../loading.react.js';
import {
getClientDBStore,
processDBStoreOperations,
-} from '../database/utils/store.js';
-import Loading from '../loading.react.js';
+} from '../shared-worker/utils/store.js';
type Props = {
+persistor: Persistor,
diff --git a/web/redux/persist.js b/web/redux/persist.js
--- a/web/redux/persist.js
+++ b/web/redux/persist.js
@@ -35,8 +35,8 @@
import type { AppState } from './redux-setup.js';
import { nonUserSpecificFieldsWeb } from './redux-setup.js';
import { authoritativeKeyserverID } from '../authoritative-keyserver.js';
-import { getDatabaseModule } from '../database/database-module-provider.js';
-import { isSQLiteSupported } from '../database/utils/db-utils.js';
+import { getCommSharedWorker } from '../shared-worker/shared-worker-provider.js';
+import { isSQLiteSupported } from '../shared-worker/utils/db-utils.js';
import { workerRequestMessageTypes } from '../types/worker-types.js';
declare var keyserverURL: string;
@@ -94,18 +94,18 @@
};
}
- const databaseModule = await getDatabaseModule();
- const isDatabaseSupported = await databaseModule.isDatabaseSupported();
+ const sharedWorker = await getCommSharedWorker();
+ const isSupported = await sharedWorker.isSupported();
- if (!isDatabaseSupported) {
+ if (!isSupported) {
return newState;
}
- const stores = await databaseModule.schedule({
+ const stores = await sharedWorker.schedule({
type: workerRequestMessageTypes.GET_CLIENT_STORE,
});
invariant(stores?.store, 'Stores should exist');
- await databaseModule.schedule({
+ await sharedWorker.schedule({
type: workerRequestMessageTypes.PROCESS_STORE_OPERATIONS,
storeOperations: {
draftStoreOperations: generateIDSchemaMigrationOpsForDrafts(
@@ -134,9 +134,9 @@
};
},
[5]: async (state: any) => {
- const databaseModule = await getDatabaseModule();
- const isDatabaseSupported = await databaseModule.isDatabaseSupported();
- if (!isDatabaseSupported) {
+ const sharedWorker = await getCommSharedWorker();
+ const isSupported = await sharedWorker.isSupported();
+ if (!isSupported) {
return state;
}
@@ -154,7 +154,7 @@
});
}
- await databaseModule.schedule({
+ await sharedWorker.schedule({
type: workerRequestMessageTypes.PROCESS_STORE_OPERATIONS,
storeOperations: { draftStoreOperations },
});
@@ -229,9 +229,9 @@
};
},
[11]: async (state: AppState) => {
- const databaseModule = await getDatabaseModule();
- const isDatabaseSupported = await databaseModule.isDatabaseSupported();
- if (!isDatabaseSupported) {
+ const sharedWorker = await getCommSharedWorker();
+ const isSupported = await sharedWorker.isSupported();
+ if (!isSupported) {
return state;
}
@@ -252,7 +252,7 @@
]);
try {
- await databaseModule.schedule({
+ await sharedWorker.schedule({
type: workerRequestMessageTypes.PROCESS_STORE_OPERATIONS,
storeOperations: { keyserverStoreOperations },
});
@@ -265,8 +265,8 @@
};
const migrateStorageToSQLite: StorageMigrationFunction = async debug => {
- const databaseModule = await getDatabaseModule();
- const isSupported = await databaseModule.isDatabaseSupported();
+ const sharedWorker = await getCommSharedWorker();
+ const isSupported = await sharedWorker.isSupported();
if (!isSupported) {
return undefined;
}
diff --git a/web/redux/redux-setup.js b/web/redux/redux-setup.js
--- a/web/redux/redux-setup.js
+++ b/web/redux/redux-setup.js
@@ -63,8 +63,8 @@
import { onStateDifference } from './redux-debug-utils.js';
import { reduceServicesAccessToken } from './services-access-token-reducer.js';
import { getVisibility } from './visibility.js';
-import { processDBStoreOperations } from '../database/utils/store.js';
import { activeThreadSelector } from '../selectors/nav-selectors.js';
+import { processDBStoreOperations } from '../shared-worker/utils/store.js';
import type { InitialReduxState } from '../types/redux-types.js';
export type WindowDimensions = { width: number, height: number };
diff --git a/web/root.js b/web/root.js
--- a/web/root.js
+++ b/web/root.js
@@ -21,8 +21,6 @@
OlmSessionCreatorProvider,
} from './account/account-hooks.js';
import App from './app.react.js';
-import { SQLiteDataHandler } from './database/sqlite-data-handler.js';
-import { localforageConfig } from './database/utils/constants.js';
import ErrorBoundary from './error-boundary.react.js';
import IdentityServiceContextProvider from './grpc/identity-service-context-provider.react.js';
import { defaultWebState } from './redux/default-state.js';
@@ -34,6 +32,8 @@
tabSynchronizationMiddleware,
} from './redux/tab-synchronization.js';
import history from './router-history.js';
+import { SQLiteDataHandler } from './shared-worker/sqlite-data-handler.js';
+import { localforageConfig } from './shared-worker/utils/constants.js';
import Socket from './socket.react.js';
localforage.config(localforageConfig);
diff --git a/web/scripts/run_emscripten.sh b/web/scripts/run_emscripten.sh
--- a/web/scripts/run_emscripten.sh
+++ b/web/scripts/run_emscripten.sh
@@ -12,9 +12,9 @@
NATIVE_CPP_DIR="${SCRIPT_DIR}/../../native/cpp/"
INPUT_DIR="${NATIVE_CPP_DIR}CommonCpp/DatabaseManagers/"
ENTITIES_DIR="${NATIVE_CPP_DIR}CommonCpp/DatabaseManagers/entities/"
-SQLITE_DIR="${SCRIPT_DIR}/../database/sqlite/"
+SQLITE_DIR="${SCRIPT_DIR}/../shared-worker/sqlite/"
WEB_CPP_DIR="${SCRIPT_DIR}/../cpp/"
-OUTPUT_DIR="${SCRIPT_DIR}/../database/_generated/"
+OUTPUT_DIR="${SCRIPT_DIR}/../shared-worker/_generated/"
# files
SQLITE_SOURCE="${SQLITE_DIR}sqlite3.c"
diff --git a/web/settings/backup-test-restore-modal.react.js b/web/settings/backup-test-restore-modal.react.js
--- a/web/settings/backup-test-restore-modal.react.js
+++ b/web/settings/backup-test-restore-modal.react.js
@@ -7,9 +7,9 @@
import css from './backup-test-restore-modal.css';
import Button from '../components/button.react.js';
-import { getDatabaseModule } from '../database/database-module-provider.js';
import Input from '../modals/input.react.js';
import Modal from '../modals/modal.react.js';
+import { getCommSharedWorker } from '../shared-worker/shared-worker-provider.js';
import { workerRequestMessageTypes } from '../types/worker-types.js';
type Props = {
@@ -39,8 +39,8 @@
const authMetadata = await client.getAuthMetadata();
- const databaseModule = await getDatabaseModule();
- await databaseModule.schedule({
+ const sharedWorker = await getCommSharedWorker();
+ await sharedWorker.schedule({
type: workerRequestMessageTypes.BACKUP_RESTORE,
authMetadata,
backupID,
diff --git a/web/database/_generated/comm-query-executor.js b/web/shared-worker/_generated/comm-query-executor.js
rename from web/database/_generated/comm-query-executor.js
rename to web/shared-worker/_generated/comm-query-executor.js
diff --git a/web/database/_generated/comm_query_executor.wasm b/web/shared-worker/_generated/comm_query_executor.wasm
rename from web/database/_generated/comm_query_executor.wasm
rename to web/shared-worker/_generated/comm_query_executor.wasm
diff --git a/web/database/db-module.js b/web/shared-worker/db-module.js
rename from web/database/db-module.js
rename to web/shared-worker/db-module.js
diff --git a/web/database/db-module.test.js b/web/shared-worker/db-module.test.js
rename from web/database/db-module.test.js
rename to web/shared-worker/db-module.test.js
diff --git a/web/database/queries/communities-queries.test.js b/web/shared-worker/queries/communities-queries.test.js
rename from web/database/queries/communities-queries.test.js
rename to web/shared-worker/queries/communities-queries.test.js
diff --git a/web/database/queries/draft-queries.test.js b/web/shared-worker/queries/draft-queries.test.js
rename from web/database/queries/draft-queries.test.js
rename to web/shared-worker/queries/draft-queries.test.js
diff --git a/web/database/queries/keyservers-queries.test.js b/web/shared-worker/queries/keyservers-queries.test.js
rename from web/database/queries/keyservers-queries.test.js
rename to web/shared-worker/queries/keyservers-queries.test.js
diff --git a/web/database/queries/message-store-threads-queries.test.js b/web/shared-worker/queries/message-store-threads-queries.test.js
rename from web/database/queries/message-store-threads-queries.test.js
rename to web/shared-worker/queries/message-store-threads-queries.test.js
diff --git a/web/database/queries/message-to-device-queries.test.js b/web/shared-worker/queries/message-to-device-queries.test.js
rename from web/database/queries/message-to-device-queries.test.js
rename to web/shared-worker/queries/message-to-device-queries.test.js
diff --git a/web/database/queries/messages-and-media-queries.test.js b/web/shared-worker/queries/messages-and-media-queries.test.js
rename from web/database/queries/messages-and-media-queries.test.js
rename to web/shared-worker/queries/messages-and-media-queries.test.js
diff --git a/web/database/queries/metadata-queries.test.js b/web/shared-worker/queries/metadata-queries.test.js
rename from web/database/queries/metadata-queries.test.js
rename to web/shared-worker/queries/metadata-queries.test.js
diff --git a/web/database/queries/olm-persist-data-queries.test.js b/web/shared-worker/queries/olm-persist-data-queries.test.js
rename from web/database/queries/olm-persist-data-queries.test.js
rename to web/shared-worker/queries/olm-persist-data-queries.test.js
diff --git a/web/database/queries/report-queries.test.js b/web/shared-worker/queries/report-queries.test.js
rename from web/database/queries/report-queries.test.js
rename to web/shared-worker/queries/report-queries.test.js
diff --git a/web/database/queries/storage-engine-queries.test.js b/web/shared-worker/queries/storage-engine-queries.test.js
rename from web/database/queries/storage-engine-queries.test.js
rename to web/shared-worker/queries/storage-engine-queries.test.js
diff --git a/web/database/queries/threads-queries.test.js b/web/shared-worker/queries/threads-queries.test.js
rename from web/database/queries/threads-queries.test.js
rename to web/shared-worker/queries/threads-queries.test.js
diff --git a/web/database/queries/user-quries.test.js b/web/shared-worker/queries/user-quries.test.js
rename from web/database/queries/user-quries.test.js
rename to web/shared-worker/queries/user-quries.test.js
diff --git a/web/database/database-module-provider.js b/web/shared-worker/shared-worker-provider.js
rename from web/database/database-module-provider.js
rename to web/shared-worker/shared-worker-provider.js
--- a/web/database/database-module-provider.js
+++ b/web/shared-worker/shared-worker-provider.js
@@ -26,45 +26,49 @@
declare var commQueryExecutorFilename: string;
declare var backupClientFilename: string;
-const databaseStatuses = Object.freeze({
+const sharedWorkerStatuses = Object.freeze({
notRunning: 'NOT_RUNNING',
initSuccess: 'INIT_SUCCESS',
initInProgress: 'INIT_IN_PROGRESS',
initError: 'INIT_ERROR',
});
-type DatabaseStatus =
+type SharedWorkerStatus =
| { +type: 'NOT_RUNNING' | 'INIT_SUCCESS' | 'INIT_ERROR' }
| { +type: 'INIT_IN_PROGRESS', +initPromise: Promise<void> };
type InitOptions = { +clearDatabase: boolean };
-class DatabaseModule {
+class CommSharedWorker {
worker: ?SharedWorker;
workerProxy: ?WorkerConnectionProxy;
- status: DatabaseStatus = { type: databaseStatuses.notRunning };
+ status: SharedWorkerStatus = { type: sharedWorkerStatuses.notRunning };
async init({ clearDatabase }: InitOptions): Promise<void> {
if (!isSQLiteSupported()) {
console.warn('SQLite is not supported');
- this.status = { type: databaseStatuses.initError };
+ this.status = { type: sharedWorkerStatuses.initError };
return;
}
- if (this.status.type === databaseStatuses.initInProgress) {
+ if (this.status.type === sharedWorkerStatuses.initInProgress) {
await this.status.initPromise;
return;
}
if (
- (this.status.type === databaseStatuses.initSuccess && !clearDatabase) ||
- this.status.type === databaseStatuses.initError
+ (this.status.type === sharedWorkerStatuses.initSuccess &&
+ !clearDatabase) ||
+ this.status.type === sharedWorkerStatuses.initError
) {
return;
}
const initPromise = (async () => {
- if (clearDatabase && this.status.type === databaseStatuses.initSuccess) {
+ if (
+ clearDatabase &&
+ this.status.type === sharedWorkerStatuses.initSuccess
+ ) {
console.info('Clearing sensitive data');
invariant(this.workerProxy, 'Worker proxy should exist');
await this.workerProxy.scheduleOnWorker({
@@ -73,7 +77,7 @@
}
const codeVersion = getConfig().platformDetails.codeVersion ?? '';
- const workerName = `comm-app-database-${codeVersion}`;
+ const workerName = `comm-app-shared-worker-${codeVersion}`;
this.worker = new SharedWorker(DATABASE_WORKER_PATH, workerName);
this.worker.onerror = console.error;
@@ -97,38 +101,38 @@
commQueryExecutorFilename,
backupClientFilename,
});
- this.status = { type: databaseStatuses.initSuccess };
+ this.status = { type: sharedWorkerStatuses.initSuccess };
console.info('Database initialization success');
} catch (error) {
- this.status = { type: databaseStatuses.initError };
+ this.status = { type: sharedWorkerStatuses.initError };
console.error(`Database initialization failure`, error);
}
})();
- this.status = { type: databaseStatuses.initInProgress, initPromise };
+ this.status = { type: sharedWorkerStatuses.initInProgress, initPromise };
await initPromise;
}
- async isDatabaseSupported(): Promise<boolean> {
- if (this.status.type === databaseStatuses.initInProgress) {
+ async isSupported(): Promise<boolean> {
+ if (this.status.type === sharedWorkerStatuses.initInProgress) {
await this.status.initPromise;
}
- return this.status.type === databaseStatuses.initSuccess;
+ return this.status.type === sharedWorkerStatuses.initSuccess;
}
async schedule(
payload: WorkerRequestMessage,
): Promise<?WorkerResponseMessage> {
- if (this.status.type === databaseStatuses.notRunning) {
+ if (this.status.type === sharedWorkerStatuses.notRunning) {
throw new Error('Database not running');
}
- if (this.status.type === databaseStatuses.initInProgress) {
+ if (this.status.type === sharedWorkerStatuses.initInProgress) {
await this.status.initPromise;
}
- if (this.status.type === databaseStatuses.initError) {
+ if (this.status.type === sharedWorkerStatuses.initError) {
throw new Error('Database could not be initialized');
}
@@ -151,15 +155,15 @@
return await exportKeyToJWK(newEncryptionKey);
}
-let databaseModule: ?DatabaseModule = null;
-async function getDatabaseModule(): Promise<DatabaseModule> {
- if (databaseModule) {
- return databaseModule;
+let sharedWorker: ?CommSharedWorker = null;
+async function getCommSharedWorker(): Promise<CommSharedWorker> {
+ if (sharedWorker) {
+ return sharedWorker;
}
- const newModule = new DatabaseModule();
- databaseModule = newModule;
+ const newModule = new CommSharedWorker();
+ sharedWorker = newModule;
await newModule.init({ clearDatabase: false });
return newModule;
}
-export { getDatabaseModule };
+export { getCommSharedWorker };
diff --git a/web/database/sqlite-data-handler.js b/web/shared-worker/sqlite-data-handler.js
rename from web/database/sqlite-data-handler.js
rename to web/shared-worker/sqlite-data-handler.js
--- a/web/database/sqlite-data-handler.js
+++ b/web/shared-worker/sqlite-data-handler.js
@@ -5,7 +5,7 @@
import { getMessageForException } from 'lib/utils/errors.js';
import { useDispatch } from 'lib/utils/redux-utils.js';
-import { getDatabaseModule } from './database-module-provider.js';
+import { getCommSharedWorker } from './shared-worker-provider.js';
import { useSelector } from '../redux/redux-utils.js';
import { workerRequestMessageTypes } from '../types/worker-types.js';
@@ -19,11 +19,11 @@
);
const handleSensitiveData = React.useCallback(async () => {
- const databaseModule = await getDatabaseModule();
+ const sharedWorker = await getCommSharedWorker();
let currentDBUserID,
errorGettingUserID = false;
try {
- const currentUserData = await databaseModule.schedule({
+ const currentUserData = await sharedWorker.schedule({
type: workerRequestMessageTypes.GET_CURRENT_USER_ID,
});
currentDBUserID = currentUserData?.userID;
@@ -42,7 +42,7 @@
if (currentDBUserID || errorGettingUserID) {
try {
- await databaseModule.init({ clearDatabase: true });
+ await sharedWorker.init({ clearDatabase: true });
} catch (error) {
console.error(
`Error clearing sensitive data: ${
@@ -55,7 +55,7 @@
}
if (currentLoggedInUserID) {
try {
- await databaseModule.schedule({
+ await sharedWorker.schedule({
type: workerRequestMessageTypes.SET_CURRENT_USER_ID,
userID: currentLoggedInUserID,
});
@@ -71,13 +71,13 @@
React.useEffect(() => {
void (async () => {
- const databaseModule = await getDatabaseModule();
+ const sharedWorker = await getCommSharedWorker();
if (!rehydrateConcluded) {
return;
}
- const isSupported = await databaseModule.isDatabaseSupported();
+ const isSupported = await sharedWorker.isSupported();
if (!isSupported) {
return;
}
diff --git a/web/database/types/entities.js b/web/shared-worker/types/entities.js
rename from web/database/types/entities.js
rename to web/shared-worker/types/entities.js
diff --git a/web/database/types/entities.test.js b/web/shared-worker/types/entities.test.js
rename from web/database/types/entities.test.js
rename to web/shared-worker/types/entities.test.js
diff --git a/web/database/types/file-system.js b/web/shared-worker/types/file-system.js
rename from web/database/types/file-system.js
rename to web/shared-worker/types/file-system.js
diff --git a/web/database/types/module.js b/web/shared-worker/types/module.js
rename from web/database/types/module.js
rename to web/shared-worker/types/module.js
diff --git a/web/database/types/sqlite-query-executor.js b/web/shared-worker/types/sqlite-query-executor.js
rename from web/database/types/sqlite-query-executor.js
rename to web/shared-worker/types/sqlite-query-executor.js
diff --git a/web/database/utils/constants.js b/web/shared-worker/utils/constants.js
rename from web/database/utils/constants.js
rename to web/shared-worker/utils/constants.js
diff --git a/web/database/utils/db-utils.js b/web/shared-worker/utils/db-utils.js
rename from web/database/utils/db-utils.js
rename to web/shared-worker/utils/db-utils.js
diff --git a/web/database/utils/store.js b/web/shared-worker/utils/store.js
rename from web/database/utils/store.js
rename to web/shared-worker/utils/store.js
--- a/web/database/utils/store.js
+++ b/web/shared-worker/utils/store.js
@@ -12,10 +12,10 @@
import { defaultWebState } from '../../redux/default-state.js';
import { workerRequestMessageTypes } from '../../types/worker-types.js';
-import { getDatabaseModule } from '../database-module-provider.js';
+import { getCommSharedWorker } from '../shared-worker-provider.js';
async function getClientDBStore(): Promise<ClientStore> {
- const databaseModule = await getDatabaseModule();
+ const sharedWorker = await getCommSharedWorker();
let result: ClientStore = {
currentUserID: null,
drafts: [],
@@ -27,7 +27,7 @@
keyserverInfos: defaultWebState.keyserverStore.keyserverInfos,
communityInfos: null,
};
- const data = await databaseModule.schedule({
+ const data = await sharedWorker.schedule({
type: workerRequestMessageTypes.GET_CLIENT_STORE,
});
if (data?.store?.drafts) {
@@ -105,13 +105,13 @@
return;
}
- const databaseModule = await getDatabaseModule();
- const isSupported = await databaseModule.isDatabaseSupported();
+ const sharedWorker = await getCommSharedWorker();
+ const isSupported = await sharedWorker.isSupported();
if (!isSupported) {
return;
}
try {
- await databaseModule.schedule({
+ await sharedWorker.schedule({
type: workerRequestMessageTypes.PROCESS_STORE_OPERATIONS,
storeOperations: {
draftStoreOperations,
@@ -126,7 +126,7 @@
if (canUseDatabase) {
window.alert(e.message);
if (threadStoreOperations.length > 0) {
- await databaseModule.init({ clearDatabase: true });
+ await sharedWorker.init({ clearDatabase: true });
location.reload();
}
}
diff --git a/web/database/utils/worker-connection-proxy.js b/web/shared-worker/utils/worker-connection-proxy.js
rename from web/database/utils/worker-connection-proxy.js
rename to web/shared-worker/utils/worker-connection-proxy.js
diff --git a/web/database/utils/worker-crypto-utils.test.js b/web/shared-worker/utils/worker-crypto-utils.test.js
rename from web/database/utils/worker-crypto-utils.test.js
rename to web/shared-worker/utils/worker-crypto-utils.test.js
diff --git a/web/database/worker/backup.js b/web/shared-worker/worker/backup.js
rename from web/database/worker/backup.js
rename to web/shared-worker/worker/backup.js
diff --git a/web/database/worker/process-operations.js b/web/shared-worker/worker/process-operations.js
rename from web/database/worker/process-operations.js
rename to web/shared-worker/worker/process-operations.js
diff --git a/web/database/worker/db-worker.js b/web/shared-worker/worker/shared-worker.js
rename from web/database/worker/db-worker.js
rename to web/shared-worker/worker/shared-worker.js
diff --git a/web/webpack.config.cjs b/web/webpack.config.cjs
--- a/web/webpack.config.cjs
+++ b/web/webpack.config.cjs
@@ -120,7 +120,7 @@
const baseWebWorkersConfig = {
entry: {
pushNotif: './push-notif/service-worker.js',
- database: './database/worker/db-worker.js',
+ database: './shared-worker/worker/shared-worker.js',
},
output: {
filename: '[name].build.js',
@@ -139,7 +139,7 @@
new CopyPlugin({
patterns: [
{
- from: 'database/_generated/comm_query_executor.wasm',
+ from: 'shared-worker/_generated/comm_query_executor.wasm',
to: path.join(__dirname, 'dist', 'webworkers'),
},
],
@@ -166,7 +166,7 @@
new CopyPlugin({
patterns: [
{
- from: 'database/_generated/comm_query_executor.wasm',
+ from: 'shared-worker/_generated/comm_query_executor.wasm',
to: path.join(
__dirname,
'dist',
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Fri, Nov 29, 5:02 PM (21 h, 26 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2591407
Default Alt Text
D11236.id38132.diff (31 KB)
Attached To
Mode
D11236: [web] Rename database worker
Attached
Detach File
Event Timeline
Log In to Comment