chore: prohibit using mergeUpdates (#3701)

This commit is contained in:
Alex Yang
2023-08-11 11:55:17 -04:00
committed by GitHub
parent e9f4912665
commit 9639143df4
14 changed files with 142 additions and 94 deletions

View File

@@ -435,15 +435,13 @@ describe('utils', () => {
});
test('overwrite binary', async () => {
await overwriteBinary('test', new Uint8Array([1, 2, 3]));
const doc = new Doc();
const map = doc.getMap();
map.set('1', 1);
await overwriteBinary('test', new Uint8Array(encodeStateAsUpdate(doc)));
{
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]));
expect(binary).toEqual(new Uint8Array(encodeStateAsUpdate(doc)));
}
});
});

View File

@@ -6,7 +6,7 @@ import {
import { assertExists } from '@blocksuite/global/utils';
import { openDB } from 'idb';
import type { Doc } from 'yjs';
import { diffUpdate, mergeUpdates } from 'yjs';
import { diffUpdate } from 'yjs';
import {
type BlockSuiteBinaryDB,
@@ -16,6 +16,7 @@ import {
type UpdateMessage,
upgradeDB,
} from './shared';
import { mergeUpdates } from './utils';
let mergeCount = 500;

View File

@@ -1,12 +1,20 @@
import type { IDBPDatabase } from 'idb';
import { openDB } from 'idb';
import { mergeUpdates } from 'yjs';
import { applyUpdate, Doc, encodeStateAsUpdate } from 'yjs';
import type { BlockSuiteBinaryDB, OldYjsDB, UpdateMessage } from './shared';
import { dbVersion, DEFAULT_DB_NAME, upgradeDB } from './shared';
let allDb: IDBDatabaseInfo[];
export function mergeUpdates(updates: Uint8Array[]) {
const doc = new Doc();
updates.forEach(update => {
applyUpdate(doc, update);
});
return encodeStateAsUpdate(doc);
}
async function databaseExists(name: string): Promise<boolean> {
return new Promise(resolve => {
const req = indexedDB.open(name);