mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-15 05:37:32 +00:00
chore(editor): disable legacy validation (#9473)
This commit is contained in:
@@ -5,7 +5,6 @@ export interface BlockSuiteFlags {
|
||||
enable_database_attachment_note: boolean;
|
||||
enable_database_full_width: boolean;
|
||||
enable_block_query: boolean;
|
||||
enable_legacy_validation: boolean;
|
||||
enable_lasso_tool: boolean;
|
||||
enable_edgeless_text: boolean;
|
||||
enable_ai_onboarding: boolean;
|
||||
@@ -14,7 +13,6 @@ export interface BlockSuiteFlags {
|
||||
enable_mind_map_import: boolean;
|
||||
enable_advanced_block_visibility: boolean;
|
||||
enable_shape_shadow_blur: boolean;
|
||||
enable_new_dnd: boolean;
|
||||
enable_mobile_keyboard_toolbar: boolean;
|
||||
enable_mobile_linked_doc_menu: boolean;
|
||||
readonly: Record<string, boolean>;
|
||||
|
||||
@@ -94,14 +94,12 @@ describe('basic', () => {
|
||||
const options = createTestOptions();
|
||||
const collection = new DocCollection(options);
|
||||
collection.meta.initialize();
|
||||
assert.equal(collection.isEmpty, true);
|
||||
|
||||
const doc = collection.createDoc({ id: 'doc:home' });
|
||||
doc.load();
|
||||
const actual = serializCollection(collection.doc);
|
||||
const actualDoc = actual[spaceMetaId].pages[0] as DocMeta;
|
||||
|
||||
assert.equal(collection.isEmpty, false);
|
||||
assert.equal(typeof actualDoc.createDate, 'number');
|
||||
// @ts-expect-error ignore
|
||||
delete actualDoc.createDate;
|
||||
|
||||
@@ -52,7 +52,6 @@ const FLAGS_PRESET = {
|
||||
enable_database_number_formatting: false,
|
||||
enable_database_attachment_note: false,
|
||||
enable_database_full_width: false,
|
||||
enable_legacy_validation: true,
|
||||
enable_block_query: false,
|
||||
enable_lasso_tool: false,
|
||||
enable_edgeless_text: true,
|
||||
@@ -62,7 +61,6 @@ const FLAGS_PRESET = {
|
||||
enable_mind_map_import: false,
|
||||
enable_advanced_block_visibility: false,
|
||||
enable_shape_shadow_blur: false,
|
||||
enable_new_dnd: true,
|
||||
enable_mobile_keyboard_toolbar: false,
|
||||
enable_mobile_linked_doc_menu: false,
|
||||
readonly: {},
|
||||
@@ -106,20 +104,6 @@ export class DocCollection {
|
||||
return this.blockCollections;
|
||||
}
|
||||
|
||||
get isEmpty() {
|
||||
if (this.doc.store.clients.size === 0) return true;
|
||||
|
||||
let flag = false;
|
||||
if (this.doc.store.clients.size === 1) {
|
||||
const items = Array.from(this.doc.store.clients.values())[0];
|
||||
// workspaceVersion and pageVersion were set when the collection is initialized
|
||||
if (items.length <= 2) {
|
||||
flag = true;
|
||||
}
|
||||
}
|
||||
return flag;
|
||||
}
|
||||
|
||||
get schema() {
|
||||
return this._schema;
|
||||
}
|
||||
|
||||
@@ -252,11 +252,6 @@ export class BlockCollection {
|
||||
// Initialization from empty yDoc, indicating that the document is new.
|
||||
if (!this.collection.meta.hasVersion) {
|
||||
this.collection.meta.writeVersion(this.collection);
|
||||
} else {
|
||||
// Initialization from existing yDoc, indicating that the document is loaded from storage.
|
||||
if (this.awarenessStore.getFlag('enable_legacy_validation')) {
|
||||
this.collection.meta.validateVersion(this.collection);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
import { BlockSuiteError, ErrorCode } from '@blocksuite/global/exceptions';
|
||||
import { Slot } from '@blocksuite/global/utils';
|
||||
import type * as Y from 'yjs';
|
||||
|
||||
@@ -243,76 +242,6 @@ export class DocCollectionMeta {
|
||||
this.docMetaUpdated.emit();
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated Only used for legacy doc version validation
|
||||
*/
|
||||
validateVersion(collection: DocCollection) {
|
||||
const workspaceVersion = this._proxy.workspaceVersion;
|
||||
if (!workspaceVersion) {
|
||||
throw new BlockSuiteError(
|
||||
ErrorCode.DocCollectionError,
|
||||
'Invalid workspace data, workspace version is missing. Please make sure the data is valid.'
|
||||
);
|
||||
}
|
||||
if (workspaceVersion < COLLECTION_VERSION) {
|
||||
throw new BlockSuiteError(
|
||||
ErrorCode.DocCollectionError,
|
||||
`Workspace version ${workspaceVersion} is outdated. Please upgrade the editor.`
|
||||
);
|
||||
}
|
||||
|
||||
const pageVersion = this._proxy.pageVersion;
|
||||
if (!pageVersion) {
|
||||
throw new BlockSuiteError(
|
||||
ErrorCode.DocCollectionError,
|
||||
'Invalid workspace data, page version is missing. Please make sure the data is valid.'
|
||||
);
|
||||
}
|
||||
if (pageVersion < PAGE_VERSION) {
|
||||
throw new BlockSuiteError(
|
||||
ErrorCode.DocCollectionError,
|
||||
`Doc version ${pageVersion} is outdated. Please upgrade the editor.`
|
||||
);
|
||||
}
|
||||
|
||||
const blockVersions = { ...this._proxy.blockVersions };
|
||||
if (!blockVersions) {
|
||||
throw new BlockSuiteError(
|
||||
ErrorCode.DocCollectionError,
|
||||
'Invalid workspace data, versions data is missing. Please make sure the data is valid'
|
||||
);
|
||||
}
|
||||
const dataFlavours = Object.keys(blockVersions);
|
||||
if (dataFlavours.length === 0) {
|
||||
throw new BlockSuiteError(
|
||||
ErrorCode.DocCollectionError,
|
||||
'Invalid workspace data, missing versions field. Please make sure the data is valid.'
|
||||
);
|
||||
}
|
||||
|
||||
dataFlavours.forEach(dataFlavour => {
|
||||
const dataVersion = blockVersions[dataFlavour] as number;
|
||||
const editorVersion =
|
||||
collection.schema.flavourSchemaMap.get(dataFlavour)?.version;
|
||||
if (!editorVersion) {
|
||||
throw new BlockSuiteError(
|
||||
ErrorCode.DocCollectionError,
|
||||
`Editor missing ${dataFlavour} flavour. Please make sure this block flavour is registered.`
|
||||
);
|
||||
} else if (dataVersion > editorVersion) {
|
||||
throw new BlockSuiteError(
|
||||
ErrorCode.DocCollectionError,
|
||||
`Editor doesn't support ${dataFlavour}@${dataVersion}. Please upgrade the editor.`
|
||||
);
|
||||
} else if (dataVersion < editorVersion) {
|
||||
throw new BlockSuiteError(
|
||||
ErrorCode.DocCollectionError,
|
||||
`In workspace data, the block flavour ${dataFlavour}@${dataVersion} is outdated. Please downgrade the editor or try data migration.`
|
||||
);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @internal Only for doc initialization
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user