Changeset View
Changeset View
Standalone View
Standalone View
web/database/database-module-provider.js
Show All 35 Lines | constructor() { | ||||
if (!isSupported) { | if (!isSupported) { | ||||
this.status = databaseStatuses.notSupported; | this.status = databaseStatuses.notSupported; | ||||
} else { | } else { | ||||
this.init(); | this.init(); | ||||
} | } | ||||
} | } | ||||
init() { | init(encryptionKey?: ?SubtleCrypto$JsonWebKey) { | ||||
this.status = databaseStatuses.initInProgress; | this.status = databaseStatuses.initInProgress; | ||||
this.worker = new SharedWorker(DATABASE_WORKER_PATH); | this.worker = new SharedWorker(DATABASE_WORKER_PATH); | ||||
this.worker.onerror = console.error; | this.worker.onerror = console.error; | ||||
this.workerProxy = new WorkerConnectionProxy( | this.workerProxy = new WorkerConnectionProxy( | ||||
this.worker.port, | this.worker.port, | ||||
console.error, | console.error, | ||||
); | ); | ||||
const origin = window.location.origin; | const origin = window.location.origin; | ||||
this.initPromise = (async () => { | this.initPromise = (async () => { | ||||
try { | try { | ||||
await this.workerProxy.scheduleOnWorker({ | await this.workerProxy.scheduleOnWorker({ | ||||
type: workerRequestMessageTypes.INIT, | type: workerRequestMessageTypes.INIT, | ||||
sqljsFilePath: `${origin}${SQLJS_FILE_PATH}`, | sqljsFilePath: `${origin}${SQLJS_FILE_PATH}`, | ||||
sqljsFilename, | sqljsFilename, | ||||
encryptionKey, | |||||
}); | }); | ||||
this.status = databaseStatuses.initSuccess; | this.status = databaseStatuses.initSuccess; | ||||
console.info('Database initialization success'); | console.info('Database initialization success'); | ||||
} catch (error) { | } catch (error) { | ||||
this.status = databaseStatuses.initError; | this.status = databaseStatuses.initError; | ||||
console.error(`Database initialization failure`, error); | console.error(`Database initialization failure`, error); | ||||
} | } | ||||
})(); | })(); | ||||
} | } | ||||
initDBForLoggedInUser(currentLoggedInUserID: ?string) { | initDBForLoggedInUser( | ||||
currentLoggedInUserID: ?string, | |||||
encryptionKey?: ?SubtleCrypto$JsonWebKey, | |||||
) { | |||||
if (this.status === databaseStatuses.initSuccess) { | if (this.status === databaseStatuses.initSuccess) { | ||||
return; | return; | ||||
} | } | ||||
if ( | if ( | ||||
this.status === databaseStatuses.notSupported && | this.status === databaseStatuses.notSupported && | ||||
isSQLiteSupported(currentLoggedInUserID) | isSQLiteSupported(currentLoggedInUserID) | ||||
) { | ) { | ||||
this.init(); | this.init(encryptionKey); | ||||
} | } | ||||
} | } | ||||
async clearSensitiveData(): Promise<void> { | async clearSensitiveData(): Promise<void> { | ||||
this.status = databaseStatuses.notSupported; | this.status = databaseStatuses.notSupported; | ||||
await this.workerProxy.scheduleOnWorker({ | await this.workerProxy.scheduleOnWorker({ | ||||
type: workerRequestMessageTypes.CLEAR_SENSITIVE_DATA, | type: workerRequestMessageTypes.CLEAR_SENSITIVE_DATA, | ||||
}); | }); | ||||
Show All 31 Lines |