refactor: workspace provider (#2218)

This commit is contained in:
Himself65 authored and GitHub committed 2023-05-03 18:16:22 -05:00
1 parent ec39c23fb7
commit 9096ac2960
18 files changed
+377 -255

No files matched your search

@@ -340,7 +340,10 @@ describe('utils', () => {
provider.connect();
await provider.whenSynced;
provider.disconnect();
const update = await downloadBinary(workspace.id, rootDBName);
const update = (await downloadBinary(
workspace.id,
rootDBName
)) as Uint8Array;
expect(update).toBeInstanceOf(Uint8Array);
const newWorkspace = new Workspace({
id,
+2 -2
View File
@@ -129,7 +129,7 @@ export async function tryMigrate(
export async function downloadBinary(
id: string,
dbName = DEFAULT_DB_NAME
): Promise<UpdateMessage['update']> {
): Promise<UpdateMessage['update'] | false> {
const dbPromise = openDB<BlockSuiteBinaryDB>(dbName, dbVersion, {
upgrade: upgradeDB,
});
@@ -137,7 +137,7 @@ export async function downloadBinary(
const t = db.transaction('workspace', 'readonly').objectStore('workspace');
const doc = await t.get(id);
if (!doc) {
return new Uint8Array(0);
return false;
} else {
return mergeUpdates(doc.updates.map(({ update }) => update));
}