Skip to content

Commit

Permalink
[web] add function to retrieve WASM module
Browse files Browse the repository at this point in the history
Summary:
Making sure that module is now typed in Flow, and making it easier to retrieve the module (will be helpful in tests later).

Depends on D8545

Test Plan:
 1. `flow`
 2. Check if result is still logged

Reviewers: michal, tomek

Reviewed By: michal

Subscribers: ashoat

Differential Revision: https://phab.comm.dev/D8547
  • Loading branch information
xsanm committed Jul 21, 2023
1 parent 97d89c0 commit 7a6f37f
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 11 deletions.
25 changes: 25 additions & 0 deletions web/database/db-module.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// @flow

import Module from './_generated/comm-query-executor.js';
import type { EmscriptenModule } from './types/module.js';
import { DEFAULT_COMM_QUERY_EXECUTOR_FILENAME } from './utils/constants.js';

function getDatabaseModule(
databaseModuleFilename?: ?string,
databaseModuleFilePath?: string,
): EmscriptenModule {
const fileName = databaseModuleFilename
? databaseModuleFilename
: DEFAULT_COMM_QUERY_EXECUTOR_FILENAME;

return Module({
locateFile: (path: string, prefix?: string) => {
if (databaseModuleFilePath) {
return `${databaseModuleFilePath}/${fileName}`;
}
return `${prefix ?? ''}${fileName}`;
},
});
}

export { getDatabaseModule };
2 changes: 2 additions & 0 deletions web/database/utils/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ export const CURRENT_USER_ID_KEY = 'current_user_id';
export const DATABASE_WORKER_PATH = '/worker/database';
export const SQLJS_FILE_PATH = '/compiled/webworkers';

export const DEFAULT_COMM_QUERY_EXECUTOR_FILENAME = 'comm_query_executor.wasm';

export const DB_SUPPORTED_OS: $ReadOnlyArray<string> = [
'Windows 10',
'Linux',
Expand Down
13 changes: 2 additions & 11 deletions web/database/worker/db-worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import {
type WorkerRequestProxyMessage,
workerWriteRequests,
} from '../../types/worker-types.js';
import Module from '../_generated/comm-query-executor.js';
import { getDatabaseModule } from '../db-module.js';
import { migrate, setupSQLiteDB } from '../queries/db-queries.js';
import {
getAllDrafts,
Expand Down Expand Up @@ -60,22 +60,13 @@ let encryptionKey: ?CryptoKey = null;
let persistNeeded: boolean = false;
let persistInProgress: boolean = false;

const defaultCommQueryExecutorFilename = 'comm_query_executor.wasm';

async function initDatabase(
sqljsFilePath: string,
sqljsFilename: ?string,
commQueryExecutorFilename: ?string,
encryptionKeyJWK?: ?SubtleCrypto$JsonWebKey,
) {
const dbModule = Module({
locateFile: function () {
if (commQueryExecutorFilename) {
return `${sqljsFilePath}/${commQueryExecutorFilename}`;
}
return `${sqljsFilePath}/${defaultCommQueryExecutorFilename}`;
},
});
const dbModule = getDatabaseModule(commQueryExecutorFilename, sqljsFilePath);

try {
const result = dbModule.CommQueryExecutor.testDBOperation();
Expand Down

0 comments on commit 7a6f37f

Please sign in to comment.