@blocksuite/store
Advanced tools
Comparing version 0.3.0-20221230041649-6b8fcf7 to 0.3.0-20221230094450-69c6395
@@ -16,3 +16,3 @@ import type { Page } from './workspace/index.js'; | ||
export declare class BaseBlockModel implements IBaseBlockProps { | ||
static version: [number, number]; | ||
static version: number; | ||
flavour: string; | ||
@@ -19,0 +19,0 @@ tag: StaticValue; |
@@ -427,3 +427,3 @@ import * as Y from 'yjs'; | ||
else { | ||
this.workspace.meta.validateVersion(); | ||
this.workspace.meta.validateVersion(this.workspace); | ||
} | ||
@@ -430,0 +430,0 @@ } |
@@ -47,3 +47,3 @@ import * as Y from 'yjs'; | ||
*/ | ||
validateVersion(): void; | ||
validateVersion(workspace: Workspace): void; | ||
private _handlePageEvent; | ||
@@ -50,0 +50,0 @@ private _handleCommonFieldsEvent; |
@@ -104,6 +104,3 @@ import * as Y from 'yjs'; | ||
workspace.flavourMap.forEach((model, flavour) => { | ||
const yVersion = new Y.Array(); | ||
const [major, minor] = model.version; | ||
yVersion.push([major, minor]); | ||
versions.set(flavour, yVersion); | ||
versions.set(flavour, model.version); | ||
}); | ||
@@ -114,4 +111,22 @@ } | ||
*/ | ||
validateVersion() { | ||
// TODO: validate version | ||
validateVersion(workspace) { | ||
const versions = this.proxy.versions.toJSON(); | ||
const dataFlavours = Object.keys(versions); | ||
// TODO: emit data validation error signals | ||
if (dataFlavours.length === 0) { | ||
throw new Error('Invalid workspace data, missing versions field. Please make sure the data is valid.'); | ||
} | ||
dataFlavours.forEach(dataFlavour => { | ||
const dataVersion = versions[dataFlavour]; | ||
const editorVersion = workspace.flavourMap.get(dataFlavour)?.version; | ||
if (!editorVersion) { | ||
throw new Error(`Editor missing ${dataFlavour} flavour. Please make sure this block flavour is registered.`); | ||
} | ||
else if (dataVersion > editorVersion) { | ||
throw new Error(`Editor doesn't support ${dataFlavour}@${dataVersion}. Please upgrade the editor.`); | ||
} | ||
else if (dataVersion < editorVersion) { | ||
throw new Error(`In workspace data, the block flavour ${dataFlavour}@${dataVersion} is outdated. Please downgrade the editor or try data migration.`); | ||
} | ||
}); | ||
} | ||
@@ -118,0 +133,0 @@ _handlePageEvent() { |
{ | ||
"name": "@blocksuite/store", | ||
"version": "0.3.0-20221230041649-6b8fcf7", | ||
"version": "0.3.0-20221230094450-69c6395", | ||
"description": "BlockSuite data store built for general purpose state management.", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
@@ -22,3 +22,3 @@ import type { Page } from './workspace/index.js'; | ||
export class BaseBlockModel implements IBaseBlockProps { | ||
static version: [number, number]; | ||
static version: number; | ||
flavour!: string; | ||
@@ -25,0 +25,0 @@ tag!: StaticValue; |
@@ -563,5 +563,5 @@ import * as Y from 'yjs'; | ||
else { | ||
this.workspace.meta.validateVersion(); | ||
this.workspace.meta.validateVersion(this.workspace); | ||
} | ||
} | ||
} |
@@ -122,6 +122,3 @@ import * as Y from 'yjs'; | ||
workspace.flavourMap.forEach((model, flavour) => { | ||
const yVersion = new Y.Array(); | ||
const [major, minor] = model.version; | ||
yVersion.push([major, minor]); | ||
versions.set(flavour, yVersion); | ||
versions.set(flavour, model.version); | ||
}); | ||
@@ -133,4 +130,30 @@ } | ||
*/ | ||
validateVersion() { | ||
// TODO: validate version | ||
validateVersion(workspace: Workspace) { | ||
const versions = this.proxy.versions.toJSON(); | ||
const dataFlavours = Object.keys(versions); | ||
// TODO: emit data validation error signals | ||
if (dataFlavours.length === 0) { | ||
throw new Error( | ||
'Invalid workspace data, missing versions field. Please make sure the data is valid.' | ||
); | ||
} | ||
dataFlavours.forEach(dataFlavour => { | ||
const dataVersion = versions[dataFlavour] as number; | ||
const editorVersion = workspace.flavourMap.get(dataFlavour)?.version; | ||
if (!editorVersion) { | ||
throw new Error( | ||
`Editor missing ${dataFlavour} flavour. Please make sure this block flavour is registered.` | ||
); | ||
} else if (dataVersion > editorVersion) { | ||
throw new Error( | ||
`Editor doesn't support ${dataFlavour}@${dataVersion}. Please upgrade the editor.` | ||
); | ||
} else if (dataVersion < editorVersion) { | ||
throw new Error( | ||
`In workspace data, the block flavour ${dataFlavour}@${dataVersion} is outdated. Please downgrade the editor or try data migration.` | ||
); | ||
} | ||
}); | ||
} | ||
@@ -137,0 +160,0 @@ |
@@ -6,3 +6,4 @@ import { defineConfig } from 'vitest/config'; | ||
include: ['src/__tests__/*.spec.ts'], | ||
testTimeout: 500, | ||
}, | ||
}); |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
422079
7062