mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-16 13:57:02 +08:00
feat: update migration test page (#2871)
This commit is contained in:
@@ -20,6 +20,7 @@ import {
|
||||
downloadBinary,
|
||||
getMilestones,
|
||||
markMilestone,
|
||||
overwriteBinary,
|
||||
revertUpdate,
|
||||
setMergeCount,
|
||||
} from '../index';
|
||||
@@ -488,4 +489,17 @@ describe('utils', () => {
|
||||
}, 0)
|
||||
);
|
||||
});
|
||||
|
||||
test('overwrite binary', async () => {
|
||||
await overwriteBinary('test', new Uint8Array([1, 2, 3]));
|
||||
{
|
||||
const binary = await downloadBinary('test');
|
||||
expect(binary).toEqual(new Uint8Array([1, 2, 3]));
|
||||
}
|
||||
await overwriteBinary('test', new Uint8Array([0, 0]));
|
||||
{
|
||||
const binary = await downloadBinary('test');
|
||||
expect(binary).toEqual(new Uint8Array([0, 0]));
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
@@ -143,3 +143,24 @@ export async function downloadBinary(
|
||||
return mergeUpdates(doc.updates.map(({ update }) => update));
|
||||
}
|
||||
}
|
||||
|
||||
export async function overwriteBinary(
|
||||
guid: string,
|
||||
update: UpdateMessage['update'],
|
||||
dbName = DEFAULT_DB_NAME
|
||||
) {
|
||||
const dbPromise = openDB<BlockSuiteBinaryDB>(dbName, dbVersion, {
|
||||
upgrade: upgradeDB,
|
||||
});
|
||||
const db = await dbPromise;
|
||||
const t = db.transaction('workspace', 'readwrite').objectStore('workspace');
|
||||
await t.put({
|
||||
id: guid,
|
||||
updates: [
|
||||
{
|
||||
timestamp: Date.now(),
|
||||
update,
|
||||
},
|
||||
],
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user