Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@blocksuite/store

Package Overview
Dependencies
Maintainers
5
Versions
1273
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@blocksuite/store - npm Package Compare versions

Comparing version 0.3.1-20230106002207-33202f0 to 0.3.1-20230106060050-1aad55d

53

dist/workspace/migrations.js
import * as Y from 'yjs';
import { initSysProps } from '../utils/utils.js';
import { uuidv4 } from '../utils/id-generator.js';
// New migration should be added to the end of this list
const migrations = [
{
desc: 'add initial affine:surface block',
desc: 'convert affine:group to affine:frame',
condition: doc => {

@@ -13,3 +14,3 @@ const yVersions = doc

return false;
return yVersions.get('affine:page') === 1;
return yVersions.get('affine:group') === 1;
},

@@ -22,22 +23,21 @@ migrate: doc => {

.map((a) => a.get('id'));
const yVersions = doc
.getMap('space:meta')
.get('versions');
yVersions.set('affine:page', 2);
yVersions.set('affine:surface', 1);
for (const pageId of pageIds) {
const spaceId = `space:${pageId}`;
const yBlocks = doc.getMap(spaceId);
const yBlock = new Y.Map();
const id = uuidv4();
initSysProps(yBlock, {
id,
flavour: 'affine:surface',
// @ts-ignore
yBlocks.forEach((yBlock) => {
if (yBlock.get('sys:flavour') === 'affine:group') {
yBlock.set('sys:flavour', 'affine:frame');
}
});
yBlocks.set(id, yBlock);
}
const yVersions = doc
.getMap('space:meta')
.get('versions');
yVersions.delete('affine:group');
yVersions.set('affine:frame', 1);
},
},
{
desc: 'convert affine:group to affine:frame',
desc: 'add affine:surface',
condition: doc => {

@@ -49,3 +49,3 @@ const yVersions = doc

return false;
return yVersions.get('affine:group') === 1;
return yVersions.get('affine:shape') === 1;
},

@@ -58,17 +58,24 @@ migrate: doc => {

.map((a) => a.get('id'));
const yVersions = doc
.getMap('space:meta')
.get('versions');
yVersions.delete('affine:shape');
yVersions.set('affine:surface', 1);
for (const pageId of pageIds) {
const spaceId = `space:${pageId}`;
const yBlocks = doc.getMap(spaceId);
const yBlock = new Y.Map();
const id = uuidv4();
initSysProps(yBlock, {
id,
flavour: 'affine:surface',
});
yBlocks.set(id, yBlock);
// @ts-ignore
yBlocks.forEach((yBlock) => {
if (yBlock.get('sys:flavour') === 'affine:group') {
yBlock.set('sys:flavour', 'affine:frame');
yBlocks.forEach((yBlock, id) => {
if (yBlock.get('sys:flavour') === 'affine:shape') {
yBlocks.delete(id);
}
});
}
const yVersions = doc
.getMap('space:meta')
.get('versions');
yVersions.delete('affine:group');
yVersions.set('affine:frame', 1);
},

@@ -75,0 +82,0 @@ },

{
"name": "@blocksuite/store",
"version": "0.3.1-20230106002207-33202f0",
"version": "0.3.1-20230106060050-1aad55d",
"description": "BlockSuite data store built for general purpose state management.",

@@ -5,0 +5,0 @@ "main": "dist/index.js",

@@ -25,3 +25,3 @@ import * as Y from 'yjs';

'affine:paragraph': 1,
'affine:page': 2,
'affine:page': 1,
'affine:list': 1,

@@ -31,3 +31,2 @@ 'affine:frame': 1,

'affine:embed': 1,
'affine:shape': 1,
'affine:code': 1,

@@ -50,3 +49,3 @@ 'affine:surface': 1,

test('migrate add surface', async () => {
test('migrate to surface block', async () => {
const doc = await loadBinary('legacy-surface');

@@ -58,3 +57,3 @@ tryMigrate(doc);

'affine:paragraph': 1,
'affine:page': 2,
'affine:page': 1,
'affine:list': 1,

@@ -64,3 +63,2 @@ 'affine:frame': 1,

'affine:embed': 1,
'affine:shape': 1,
'affine:code': 1,

@@ -70,13 +68,14 @@ 'affine:surface': 1,

const hasSurface = Object.entries(result['space:page0']).some(
([_, value]: [string, unknown]) => {
if (
(value as Record<string, unknown>)['sys:flavour'] === 'affine:surface'
) {
return true;
}
return false;
}
([_, value]: [string, unknown]) =>
(value as Record<string, unknown>)['sys:flavour'] === 'affine:surface'
);
const hasShape = Object.entries(result['space:page0']).some(
([_, value]: [string, unknown]) =>
(value as Record<string, unknown>)['sys:flavour'] === 'affine:shape'
);
expect(hasSurface).toBe(true);
expect(hasShape).toBe(false);
});
});

@@ -12,5 +12,6 @@ import * as Y from 'yjs';

// New migration should be added to the end of this list
const migrations: Migration[] = [
{
desc: 'add initial affine:surface block',
desc: 'convert affine:group to affine:frame',
condition: doc => {

@@ -21,3 +22,4 @@ const yVersions = doc

if (!yVersions) return false;
return yVersions.get('affine:page') === 1;
return yVersions.get('affine:group') === 1;
},

@@ -30,7 +32,2 @@ migrate: doc => {

.map((a: Y.Map<unknown>) => a.get('id')) as string[];
const yVersions = doc
.getMap('space:meta')
.get('versions') as Y.Map<number>;
yVersions.set('affine:page', 2);
yVersions.set('affine:surface', 1);

@@ -40,14 +37,19 @@ for (const pageId of pageIds) {

const yBlocks = doc.getMap(spaceId);
const yBlock = new Y.Map() as YBlock;
const id = uuidv4();
initSysProps(yBlock, {
id,
flavour: 'affine:surface',
// @ts-ignore
yBlocks.forEach((yBlock: Y.Map<unknown>) => {
if (yBlock.get('sys:flavour') === 'affine:group') {
yBlock.set('sys:flavour', 'affine:frame');
}
});
yBlocks.set(id, yBlock);
}
const yVersions = doc
.getMap('space:meta')
.get('versions') as Y.Map<number>;
yVersions.delete('affine:group');
yVersions.set('affine:frame', 1);
},
},
{
desc: 'convert affine:group to affine:frame',
desc: 'add affine:surface',
condition: doc => {

@@ -58,4 +60,3 @@ const yVersions = doc

if (!yVersions) return false;
return yVersions.get('affine:group') === 1;
return yVersions.get('affine:shape') === 1;
},

@@ -68,2 +69,7 @@ migrate: doc => {

.map((a: Y.Map<unknown>) => a.get('id')) as string[];
const yVersions = doc
.getMap('space:meta')
.get('versions') as Y.Map<number>;
yVersions.delete('affine:shape');
yVersions.set('affine:surface', 1);

@@ -73,15 +79,16 @@ for (const pageId of pageIds) {

const yBlocks = doc.getMap(spaceId);
const yBlock = new Y.Map() as YBlock;
const id = uuidv4();
initSysProps(yBlock, {
id,
flavour: 'affine:surface',
});
yBlocks.set(id, yBlock);
// @ts-ignore
yBlocks.forEach((yBlock: Y.Map<unknown>) => {
if (yBlock.get('sys:flavour') === 'affine:group') {
yBlock.set('sys:flavour', 'affine:frame');
yBlocks.forEach((yBlock: Y.Map<unknown>, id) => {
if (yBlock.get('sys:flavour') === 'affine:shape') {
yBlocks.delete(id);
}
});
}
const yVersions = doc
.getMap('space:meta')
.get('versions') as Y.Map<number>;
yVersions.delete('affine:group');
yVersions.set('affine:frame', 1);
},

@@ -88,0 +95,0 @@ },

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc