mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-17 22:37:04 +08:00
chore: prohibit using mergeUpdates (#3701)
This commit is contained in:
@@ -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)));
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user