@blocksuite/store
Advanced tools
Comparing version 0.3.0-alpha.19 to 0.3.0
@@ -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() { |
@@ -48,3 +48,9 @@ import { Map as YMap } from 'yjs'; | ||
else { | ||
return Reflect.set(target, p, value, receiver); | ||
if (typeof p === 'string') { | ||
yMap.set(p, value); | ||
return Reflect.set(target, p, value, receiver); | ||
} | ||
else { | ||
throw new Error('key cannot be a symbol'); | ||
} | ||
} | ||
@@ -51,0 +57,0 @@ }, |
{ | ||
"name": "@blocksuite/store", | ||
"version": "0.3.0-alpha.19", | ||
"version": "0.3.0", | ||
"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 @@ |
@@ -62,3 +62,8 @@ import { Map as YMap } from 'yjs'; | ||
} else { | ||
return Reflect.set(target, p, value, receiver); | ||
if (typeof p === 'string') { | ||
yMap.set(p, value); | ||
return Reflect.set(target, p, value, receiver); | ||
} else { | ||
throw new Error('key cannot be a symbol'); | ||
} | ||
} | ||
@@ -65,0 +70,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
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
422056
13378
7062