From 2c637a3c83af094736c1ae4f5419851577158f3c Mon Sep 17 00:00:00 2001 From: Mirone Date: Fri, 22 Nov 2024 19:12:06 +0900 Subject: [PATCH] chore: remove legacy migration (#8793) --- .../affine/block-surface/src/surface-model.ts | 129 +---------- .../src/blocks/database/database-model.ts | 39 +--- .../migration/migration.unit.spec.ts | 214 ------------------ .../__tests__/migration/ydocs/connector.ydoc | Bin 5874 -> 0 bytes .../ydocs/frame-element-to-block.ydoc | Bin 5608 -> 0 bytes .../migration/ydocs/page-database-v2-v3.ydoc | Bin 4442 -> 0 bytes .../migration/ydocs/page-surface-v3-v4.ydoc | Bin 2611 -> 0 bytes .../migration/ydocs/workspace-v1-v2.ydoc | Bin 563 -> 0 bytes .../blocks/src/_common/transformers/zip.ts | 29 +-- packages/framework/store/src/index.ts | 1 - .../framework/store/src/migration/index.ts | 7 - .../store/src/migration/migrate-collection.ts | 23 -- .../store/src/migration/migrate-doc.ts | 54 ----- packages/framework/store/src/schema/base.ts | 22 -- packages/framework/store/src/schema/schema.ts | 90 +------- .../apps/_common/components/pdf/worker.ts | 1 + 16 files changed, 7 insertions(+), 602 deletions(-) delete mode 100644 packages/blocks/src/__tests__/migration/migration.unit.spec.ts delete mode 100644 packages/blocks/src/__tests__/migration/ydocs/connector.ydoc delete mode 100644 packages/blocks/src/__tests__/migration/ydocs/frame-element-to-block.ydoc delete mode 100644 packages/blocks/src/__tests__/migration/ydocs/page-database-v2-v3.ydoc delete mode 100644 packages/blocks/src/__tests__/migration/ydocs/page-surface-v3-v4.ydoc delete mode 100644 packages/blocks/src/__tests__/migration/ydocs/workspace-v1-v2.ydoc delete mode 100644 packages/framework/store/src/migration/index.ts delete mode 100644 packages/framework/store/src/migration/migrate-collection.ts delete mode 100644 packages/framework/store/src/migration/migrate-doc.ts diff --git a/packages/affine/block-surface/src/surface-model.ts b/packages/affine/block-surface/src/surface-model.ts index 10d837178076..25e7eb16951d 100644 --- a/packages/affine/block-surface/src/surface-model.ts +++ b/packages/affine/block-surface/src/surface-model.ts @@ -1,134 +1,15 @@ import type { ConnectorElementModel } from '@blocksuite/affine-model'; import type { SurfaceBlockProps } from '@blocksuite/block-std/gfx'; -import type { MigrationRunner, Y } from '@blocksuite/store'; import { SurfaceBlockModel as BaseSurfaceModel } from '@blocksuite/block-std/gfx'; import { DisposableGroup } from '@blocksuite/global/utils'; -import { - Boxed, - defineBlockSchema, - DocCollection, - Text, -} from '@blocksuite/store'; +import { defineBlockSchema, DocCollection } from '@blocksuite/store'; import { elementsCtorMap } from './element-model/index.js'; import { SurfaceBlockTransformer } from './surface-transformer.js'; import { connectorWatcher } from './watchers/connector.js'; import { groupRelationWatcher } from './watchers/group.js'; -const migration = { - toV4: data => { - const { elements } = data; - if (elements instanceof Boxed) { - const value = elements.getValue(); - if (!value) { - return; - } - // eslint-disable-next-line @typescript-eslint/no-explicit-any - for (const [key, element] of (value as Record).entries()) { - const type = element.get('type') as string; - if (type === 'shape' || type === 'text') { - const isBold = element.get('isBold'); - const isItalic = element.get('isItalic'); - element.delete('isBold'); - element.delete('isItalic'); - if (isBold) { - element.set('bold', true); - } - if (isItalic) { - element.set('italic', true); - } - } - if (type === 'connector') { - const source = element.get('source'); - const target = element.get('target'); - const sourceId = source['id']; - const targetId = target['id']; - if (!source['position'] && !sourceId) { - value.delete(key); - return; - } - if (!target['position'] && !targetId) { - value.delete(key); - return; - } - } - } - } else { - for (const key of Object.keys(elements)) { - const element = elements[key] as Record; - const type = element['type'] as string; - if (type === 'shape' || type === 'text') { - const isBold = element['isBold']; - const isItalic = element['isItalic']; - delete element['isBold']; - delete element['isItalic']; - if (isBold) { - element['bold'] = true; - } - if (isItalic) { - element['italic'] = true; - } - } - if (type === 'connector') { - const source = element['source'] as Record; - const target = element['target'] as Record; - const sourceId = source['id']; - const targetId = target['id']; - // @ts-expect-error - if (!source['position'] && (!sourceId || !elements[sourceId])) { - delete elements[key]; - return; - } - // @ts-expect-error - if (!target['position'] && (!targetId || !elements[targetId])) { - delete elements[key]; - return; - } - } - } - } - }, - toV5: data => { - const { elements } = data; - if (!((elements as object | Boxed) instanceof Boxed)) { - const yMap = new DocCollection.Y.Map() as Y.Map>; - - Object.entries(elements).forEach(([key, value]) => { - const map = new DocCollection.Y.Map(); - Object.entries(value).forEach(([_key, _value]) => { - map.set( - _key, - _value instanceof DocCollection.Y.Text - ? _value.clone() - : _value instanceof Text - ? _value.yText.clone() - : _value - ); - }); - yMap.set(key, map); - }); - const wrapper = new Boxed(yMap); - data.elements = wrapper; - } - - const childrenMap = data.elements.getValue() as Y.Map>; - - for (const [id, element] of childrenMap) { - if ( - element.get('type') === 'mindmap' || - element.get('type') === 'group' - ) { - const children = element.get('children') as Y.Map>; - - if (children?.size === 0) { - childrenMap.delete(id); - } - } - } - }, -} satisfies Record>; - export const SurfaceBlockSchema = defineBlockSchema({ flavour: 'affine:surface', props: (internalPrimitives): SurfaceBlockProps => ({ @@ -147,14 +28,6 @@ export const SurfaceBlockSchema = defineBlockSchema({ 'affine:edgeless-text', ], }, - onUpgrade: (data, previousVersion, version) => { - if (previousVersion < 4 && version >= 4) { - migration.toV4(data); - } - if (previousVersion < 5 && version >= 5) { - migration.toV5(data); - } - }, transformer: () => new SurfaceBlockTransformer(), toModel: () => new SurfaceBlockModel(), }); diff --git a/packages/affine/model/src/blocks/database/database-model.ts b/packages/affine/model/src/blocks/database/database-model.ts index 19b321f1e49f..a5d67a23dab9 100644 --- a/packages/affine/model/src/blocks/database/database-model.ts +++ b/packages/affine/model/src/blocks/database/database-model.ts @@ -1,6 +1,6 @@ -import type { MigrationRunner, Text } from '@blocksuite/store'; +import type { Text } from '@blocksuite/store'; -import { BlockModel, defineBlockSchema, nanoid } from '@blocksuite/store'; +import { BlockModel, defineBlockSchema } from '@blocksuite/store'; import type { Column, SerializedCells, ViewBasicDataType } from './types.js'; @@ -13,36 +13,6 @@ export type DatabaseBlockProps = { export class DatabaseBlockModel extends BlockModel {} -const migration = { - toV3: data => { - const id = nanoid(); - // @ts-expect-error - const title = data['titleColumnName']; - // @ts-expect-error - const width = data['titleColumnWidth']; - // @ts-expect-error - delete data['titleColumnName']; - // @ts-expect-error - delete data['titleColumnWidth']; - data.columns.unshift({ - id, - type: 'title', - name: title, - data: {}, - }); - data.views.forEach(view => { - if (view.mode === 'table') { - // @ts-ignore - view.columns.unshift({ - id, - width, - statCalcType: 'none', - }); - } - }); - }, -} satisfies Record>; - export const DatabaseBlockSchema = defineBlockSchema({ flavour: 'affine:database', props: (internal): DatabaseBlockProps => ({ @@ -58,9 +28,4 @@ export const DatabaseBlockSchema = defineBlockSchema({ children: ['affine:paragraph', 'affine:list'], }, toModel: () => new DatabaseBlockModel(), - onUpgrade: (data, previousVersion, latestVersion) => { - if (previousVersion < 3 && latestVersion >= 3) { - migration.toV3(data); - } - }, }); diff --git a/packages/blocks/src/__tests__/migration/migration.unit.spec.ts b/packages/blocks/src/__tests__/migration/migration.unit.spec.ts deleted file mode 100644 index 7460b7e9a03c..000000000000 --- a/packages/blocks/src/__tests__/migration/migration.unit.spec.ts +++ /dev/null @@ -1,214 +0,0 @@ -import { SurfaceBlockSchema } from '@blocksuite/affine-block-surface'; -import { - DatabaseBlockSchema, - FrameBlockSchema, - ListBlockSchema, - NoteBlockSchema, - ParagraphBlockSchema, - RootBlockSchema, -} from '@blocksuite/affine-model'; -import { DocCollection, Schema, type Y } from '@blocksuite/store'; -// normal import -import { readFile } from 'node:fs/promises'; -import { join } from 'node:path'; -import { fileURLToPath } from 'node:url'; -import { assert, describe, expect, test } from 'vitest'; - -async function loadBinary(name: string) { - const originPath = fileURLToPath(import.meta.url); - const path = join(originPath, `../ydocs/${name}.ydoc`); - const buffer = await readFile(path); - const update = new Uint8Array(buffer); - const doc = new DocCollection.Y.Doc(); - DocCollection.Y.applyUpdate(doc, update); - return doc; -} - -const schema = new Schema(); -schema.register([ - RootBlockSchema, - SurfaceBlockSchema, - NoteBlockSchema, - ParagraphBlockSchema, - ListBlockSchema, - DatabaseBlockSchema, - FrameBlockSchema, -]); - -describe('collection migration', () => { - test('add pageVersion in collection meta', async () => { - const doc = await loadBinary('workspace-v1-v2'); - - const meta = doc.getMap('meta'); - const before = meta.toJSON(); - assert.equal(before['workspaceVersion'], 1); - assert.isUndefined(before['pageVersion']); - - schema.upgradeCollection(doc); - - const after = meta.toJSON(); - assert.equal(after['workspaceVersion'], 2); - assert.equal(after['pageVersion'], 1); - }); -}); - -describe('block migration', () => { - test('update shape and text element, `isBold` -> `bold`, `isItalic` -> `italic`, surface v3 -> v4', async () => { - const doc = await loadBinary('page-surface-v3-v4'); - - // @ts-ignore - let surfaceElements = doc - .getMap('blocks') - .get('zUHGq4EHQJ') - .get('prop:elements') as Y.Map; - let text = surfaceElements.get('Cj2MNGM9UK') as Y.Map; - let shape = surfaceElements.get('Rl2IT9rGoP') as Y.Map; - - assert.equal(text.get('isBold'), true); - assert.equal(text.get('isItalic'), true); - assert.equal((text.get('text') as Y.Text).toJSON(), 'aaa'); - assert.isUndefined(text.get('bold')); - assert.isUndefined(text.get('italic')); - - assert.equal(shape.get('isBold'), true); - assert.equal(shape.get('isItalic'), true); - assert.isUndefined(shape.get('bold')); - assert.isUndefined(shape.get('italic')); - - schema.upgradeDoc( - 0, - { - 'affine:page': 1, - 'affine:note': 1, - 'affine:paragraph': 1, - 'affine:surface': 3, - }, - doc - ); - - // @ts-ignore - surfaceElements = doc - .getMap('blocks') - .get('zUHGq4EHQJ') - .get('prop:elements') - .get('value') as Y.Map; - text = surfaceElements.get('Cj2MNGM9UK') as Y.Map; - shape = surfaceElements.get('Rl2IT9rGoP') as Y.Map; - - assert.isUndefined(text.get('isBold')); - assert.isUndefined(text.get('isItalic')); - assert.equal(text.get('bold'), true); - assert.equal(text.get('italic'), true); - - assert.equal((text.get('text') as Y.Text).toJSON(), 'aaa'); - - assert.isUndefined(shape.get('isBold')); - assert.isUndefined(shape.get('isItalic')); - assert.equal(shape.get('bold'), true); - assert.equal(shape.get('italic'), true); - }); - - test('fix wrong connector data', async () => { - const doc = await loadBinary('connector'); - // @ts-ignore - const surfaceElements = doc - .getMap('blocks') - .get('BOpLR3siGx') - .get('prop:elements') as Y.Map; - - let connector = surfaceElements.get('Gt8_2oZB8h') as Y.Map; - - assert.exists(connector); - - schema.upgradeDoc( - 0, - { - 'affine:list': 1, - 'affine:page': 1, - 'affine:note': 1, - 'affine:paragraph': 1, - 'affine:surface': 3, - }, - doc - ); - - connector = surfaceElements.get('Gt8_2oZB8h') as Y.Map; - - assert.notExists(connector); - }); - - test('frame element to block', async () => { - const doc = await loadBinary('frame-element-to-block'); - - const blocks = doc.getMap('blocks'); - - const page = blocks.get('H4fVFXmGUu') as Y.Map; - - // @ts-ignore - const surfaceElements = blocks - .get('eligOTIQu-') - .get('prop:elements') - .get('value') as Y.Map; - assert.exists(surfaceElements.get('2')); - - schema.upgradeDoc( - 0, - { - 'affine:surface': 5, - }, - doc - ); - - assert.notExists(surfaceElements.get('2')); - const pageChildren = page.get('sys:children') as Y.Array; - const id = pageChildren.get(pageChildren.length - 1); - assert.equal(id, '2'); - assert.exists(blocks.get(id)); - }); - - test('update database block title data', async () => { - const doc = await loadBinary('page-database-v2-v3'); - - let databaseBlock = ( - doc.getMap('blocks').get('Y76JkP9XRn') as Y.Map - ).toJSON(); - expect(databaseBlock['prop:titleColumnName']).toBe('Title'); - expect(databaseBlock['prop:titleColumnWidth']).toBe(200); - expect( - databaseBlock['prop:columns'].find( - (v: Record) => v.type === 'title' - ) - ).toBeUndefined(); - expect(databaseBlock['prop:views'].length).toBe(2); - - schema.upgradeDoc( - 0, - { - 'affine:page': 1, - 'affine:surface': 4, - 'affine:note': 1, - 'affine:paragraph': 1, - 'affine:database': 2, - }, - doc - ); - databaseBlock = ( - doc.getMap('blocks').get('Y76JkP9XRn') as Y.Map - ).toJSON(); - expect(databaseBlock['prop:titleColumnName']).toBeUndefined(); - expect(databaseBlock['prop:titleColumnWidth']).toBeUndefined(); - const titleColumn = databaseBlock['prop:columns'].find( - (v: Record) => v.type === 'title' - ); - expect(titleColumn.type).toBe('title'); - for (const view of databaseBlock['prop:views']) { - if (view['mode'] === 'table') { - expect( - view['columns'].find( - (v: Record) => v.id === titleColumn.id - ).width - ).toBe(200); - } - } - }); -}); diff --git a/packages/blocks/src/__tests__/migration/ydocs/connector.ydoc b/packages/blocks/src/__tests__/migration/ydocs/connector.ydoc deleted file mode 100644 index 2ce30a8579c37788b654e41f67bb2da588810f7e..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 5874 zcmb7IO^g)B6{d&z+1XhPks{>~OO!!`AMflhn;j!rhy@lyAPekn_>;4#>8_qBZ%Ks^0s)_r7{n*8A3t|NZ67%7&d*vFwM4-}`4;JX?fwCMp$UFuleY;vs0H_AoBSMgByl~aWD_#A4g^Q3alQYy2P3uyA&9GYN z=|>jwfc$Egcphu7nKCcBUJL>AsH1IVV71Zo3Fp>N_CIjrpA_J64R9?1cwEh@8GzHF zegM}Lz?&~j0Jx7pT+1gAzyA5@9XZ zuN)V9Qka{eFlAY;iD_|j{7oI(%ZVsi?d@qDn9(XHHuD`EcB{55JH11qdyh!OVkKU+ zNgapyR`=(z@GbxtCbr+jW9KXb%83wn_}s}hIjBKdGN2fv+Ip!Mlr5=Lhqw{qps5I2 z>Wj=$f=r@gc|kftf36HLk{d`kJPU4{-IcgITNj#?qaf9C1phgN(}qtR5d3{6tmtBA z`oPp-arUGR>#}9yGFBDWWve$Z&9+CmcJi{-H>k^2HmZSo1ez&`qasVKGPHEBp_nJT zN$h3NS49*E+o17FMf|e0{nP8Oy^aKFDa7Q}5FQ*pmzZTXVdnEz(I@agr{U!g;!#e6tAF|;jB*3Nb@a9}gvrXJxaB-pD83bF^%;Nd!h z?X_DB%4uoI}!3xXq8|= zmxf%71dhAyr|}ZkbCrxCS@x}D*}M;_o_zIoZVPg-z=*YdSgT2c3_ae_+ERo5pgVO= z({n3lD$!UKJ-2ebmH0S`xs~f%j<<5za?CX+R3WD0lAS~uKa?z({S^y;%56KyAj1Gu zS!JegM2BRA^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)mJiwn&V=mle_i=q)0~4HLP=LAC)T((~;Q$aVx|n}a-z+%v%ZFa+|@ z2Lff?B%$}>BfR$l55`9%{9=4W{7*(eqsK?M4LkAp)oy%@Ze*jliKF;WzP~3ZDfj@T zVRjD(U!XMXzl8rH(RutN(mK|cC!F#rrwoi_8fKIoAC)xgF+(x_jtu30IQ}zG5E;tP z_*wT4Wg6YlP=3Y=8?g!BsZMX? z5$@C%Ud)3vuy&(3jCNB$6}(Xwe|7SF|H}CI`4>Yd-l~h&&Z>CpcJYT*@njZ{nG5w> zch+w`DC%>;FL{tAXuSk`Pu{UEQ{y^UzqxWrlC2oi)@Or2d7xUijA>i*!T=0Hj9W6b1x=wI16M?-c{A|-fC@C6YhqA$Kr+Rh9ZpN zbV<4&czlks2E$tEo5`I?=Z$Umfo;pkk}0qIOoPw{BDM zXgMD-o5U=dR^zaBCm&lSAL%0EC~KyCo=VPW~QL+tuE4ANu&mCW`w z*t)sx6L#r~1s zneg4()F|G3O%{ZPw%{bQ6Jt;n0MIr%5&)v&2f2vsQ6Oe{aP zq#09cnZ{YO?DG@E$^y?C*{7=(pc*kP%dx1V8`RcyL!nk#6jR$Y`nXTd-fXt-iUIrp zB_&w3xpI0!HN!Tjg@F#q#yv%iPtOO^amkb@UaydQoJDmkcBvXx9( z1R67_WD=jsx20LwAhvvI#Imrwg-T3Q!vqsuZZcx)#370Zs6uFa>?LU&UhuDd zFP)<6CM2%RRi+hGdQhD>P8UM%t5y;U--B!&xveMDfF}|=tbjqOuQkmOTCxJ z{P^c@-Ks&d88`OHV3mDRY3T6YXf%S%un6X0s29N;6)JXr6Fo*x8_$q(-)LCqFW?&( AUH||9 diff --git a/packages/blocks/src/__tests__/migration/ydocs/workspace-v1-v2.ydoc b/packages/blocks/src/__tests__/migration/ydocs/workspace-v1-v2.ydoc deleted file mode 100644 index 074073e5d0bdb2770f9b61190e11cac733513287..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 563 zcmZuuyH3L}6!mRVTBQXlAwb;%OUu@|W5ov`A;El`+y*NTN4DF7P=A9NwtfNM!OBlC zup^PUcFDkC*}mtVdybD``2G3y(`RGwbJ93i3z@1CBf2B0xF}!)qaD;PF(Jh|%n$&^ zyF;tRV^|w-a$!qt&2>imjv$hRny#w_&$GvukKy|(8`)l8W1`p<92iyAGuyP*nl#TV zW^EkKGZCfMopKu89xfKVplKvxsythB-GMEaC^3;(J~S{#skLC!auiq2xYGZ07ovK_ zpTLn7i1~`gBpXQIB0M+q_m&((E#;!h88)6%KDLax5NVDwZ47fzj2h>tYQJyhAAHZ| z5|mPuBsC`mHrq3kt-GCfM5(JERcyyR4Yp>&C9K1H$|8|ds6{xd { - slots.afterImport.on(payload => { - if (payload.type === 'page') { - collection.schema.upgradeDoc( - info?.pageVersion ?? 0, - {}, - payload.page.spaceDoc - ); - } - }); - }; const job = new Job({ collection, - middlewares: [replaceIdMiddleware, migrationMiddleware, titleMiddleware], + middlewares: [replaceIdMiddleware, titleMiddleware], }); const assetsMap = job.assets; diff --git a/packages/framework/store/src/index.ts b/packages/framework/store/src/index.ts index 8570e3f12881..a7e7d8753e52 100644 --- a/packages/framework/store/src/index.ts +++ b/packages/framework/store/src/index.ts @@ -3,7 +3,6 @@ export type { Y }; export * from './adapter/index.js'; -export * from './migration/index.js'; export * from './reactive/index.js'; export * from './schema/index.js'; export * from './store/index.js'; diff --git a/packages/framework/store/src/migration/index.ts b/packages/framework/store/src/migration/index.ts deleted file mode 100644 index 0132901f3482..000000000000 --- a/packages/framework/store/src/migration/index.ts +++ /dev/null @@ -1,7 +0,0 @@ -import type { BlockSchemaType } from '../schema/base.js'; - -export * from './migrate-collection.js'; -export * from './migrate-doc.js'; - -export type MigrationRunner = - BlockSchema['onUpgrade']; diff --git a/packages/framework/store/src/migration/migrate-collection.ts b/packages/framework/store/src/migration/migrate-collection.ts deleted file mode 100644 index 8f19bcc1372d..000000000000 --- a/packages/framework/store/src/migration/migrate-collection.ts +++ /dev/null @@ -1,23 +0,0 @@ -import type * as Y from 'yjs'; - -interface ICollctionMigration { - desc: string; - condition: (rootDoc: Y.Doc) => boolean; - migrate: (rootDoc: Y.Doc) => void; -} - -export const collectionMigrations: ICollctionMigration[] = [ - { - desc: 'add pageVersion in meta', - condition: (rootDoc: Y.Doc) => { - const meta = rootDoc.getMap('meta'); - const workspaceVersion = meta.get('workspaceVersion') as number; - return workspaceVersion < 2; - }, - migrate: (rootDoc: Y.Doc) => { - const meta = rootDoc.getMap('meta'); - meta.set('pageVersion', 1); - meta.set('workspaceVersion', 2); - }, - }, -]; diff --git a/packages/framework/store/src/migration/migrate-doc.ts b/packages/framework/store/src/migration/migrate-doc.ts deleted file mode 100644 index 13ba6083feb9..000000000000 --- a/packages/framework/store/src/migration/migrate-doc.ts +++ /dev/null @@ -1,54 +0,0 @@ -import { assertExists } from '@blocksuite/global/utils'; -import * as Y from 'yjs'; - -interface IDocMigration { - desc: string; - condition: (oldPageVersion: number, docData: Y.Doc) => boolean; - migrate: (oldPageVersion: number, docData: Y.Doc) => void; -} - -export const docMigrations: IDocMigration[] = [ - { - desc: 'frame element --> frame block (doc v1 --> v2)', - condition: oldPageVersion => { - return oldPageVersion < 2; - }, - migrate: (_, docData) => { - const blocks = docData.getMap('blocks') as Y.Map>; - let rootModel!: Y.Map, surface!: Y.Map; - blocks.forEach(block => { - const flavour = block.get('sys:flavour'); - if (flavour === 'affine:page') { - rootModel = block; - } - if (flavour === 'affine:surface') { - surface = block; - } - }); - assertExists(rootModel); - assertExists(surface); - // @ts-ignore - const elements = surface.get('prop:elements').get('value') as Y.Map< - Y.Map - >; - elements.forEach(element => { - if (element.get('type') === 'frame') { - const frameModel = new Y.Map(); - const id = element.get('id') as string; - frameModel.set('sys:flavour', 'affine:frame'); - frameModel.set('sys:id', id); - frameModel.set('sys:children', new Y.Array()); - frameModel.set( - 'prop:title', - (element.get('title') as Y.Text).clone() - ); - frameModel.set('prop:xywh', element.get('xywh')); - frameModel.set('prop:index', element.get('index')); - blocks.set(id, frameModel); - (rootModel.get('sys:children') as Y.Array).push([id]); - elements.delete(id); - } - }); - }, - }, -]; diff --git a/packages/framework/store/src/schema/base.ts b/packages/framework/store/src/schema/base.ts index ec9612b3cf96..9b594d669fe3 100644 --- a/packages/framework/store/src/schema/base.ts +++ b/packages/framework/store/src/schema/base.ts @@ -49,11 +49,6 @@ export const BlockSchema = z.object({ .args() .returns(z.custom()) .optional(), - onUpgrade: z - .function() - .args(z.any(), z.number(), z.number()) - .returns(z.void()) - .optional(), }); export type BlockSchemaType = z.infer; @@ -90,11 +85,6 @@ export function defineBlockSchema< flavour: Flavour; metadata: Metadata; props?: (internalPrimitives: InternalPrimitives) => Props; - onUpgrade?: ( - data: Props, - previousVersion: number, - latestVersion: number - ) => void; toModel?: () => Model; transformer?: () => Transformer; }): { @@ -103,11 +93,6 @@ export function defineBlockSchema< props: PropsGetter; flavour: Flavour; } & Metadata; - onUpgrade?: ( - data: Props, - previousVersion: number, - latestVersion: number - ) => void; transformer?: () => Transformer; }; @@ -115,7 +100,6 @@ export function defineBlockSchema({ flavour, props, metadata, - onUpgrade, toModel, transformer, }: { @@ -127,11 +111,6 @@ export function defineBlockSchema({ children?: string[]; }; props?: (internalPrimitives: InternalPrimitives) => Record; - onUpgrade?: ( - data: Record, - previousVersion: number, - latestVersion: number - ) => void; toModel?: () => BlockModel; transformer?: () => BaseBlockTransformer; }): BlockSchemaType { @@ -145,7 +124,6 @@ export function defineBlockSchema({ props, toModel, }, - onUpgrade, transformer, } satisfies z.infer; BlockSchema.parse(schema); diff --git a/packages/framework/store/src/schema/schema.ts b/packages/framework/store/src/schema/schema.ts index 3e84db50e363..7fbf4bda4303 100644 --- a/packages/framework/store/src/schema/schema.ts +++ b/packages/framework/store/src/schema/schema.ts @@ -1,102 +1,14 @@ -import type * as Y from 'yjs'; - import { minimatch } from 'minimatch'; import type { BlockSchemaType } from './base.js'; import { SCHEMA_NOT_FOUND_MESSAGE } from '../consts.js'; -import { collectionMigrations, docMigrations } from '../migration/index.js'; -import { Block, type YBlock } from '../store/doc/block/index.js'; import { BlockSchema } from './base.js'; -import { MigrationError, SchemaValidateError } from './error.js'; +import { SchemaValidateError } from './error.js'; export class Schema { - private _upgradeBlockVersions = (rootData: Y.Doc) => { - const meta = rootData.getMap('meta'); - const blockVersions = meta.get('blockVersions') as Y.Map; - if (!blockVersions) { - return; - } - blockVersions.forEach((version, flavour) => { - const currentSchema = this.flavourSchemaMap.get(flavour); - if (currentSchema && version !== currentSchema.version) { - blockVersions.set(flavour, currentSchema.version); - } - }); - }; - readonly flavourSchemaMap = new Map(); - upgradeBlock = ( - flavour: string, - oldVersion: number, - blockData: Y.Map - ) => { - try { - const currentSchema = this.flavourSchemaMap.get(flavour); - if (!currentSchema) { - throw new MigrationError(`schema for flavour: ${flavour} not found`); - } - const { onUpgrade, version } = currentSchema; - if (!onUpgrade) { - return; - } - - const block = new Block(this, blockData as YBlock); - - return onUpgrade(block.model, oldVersion, version); - } catch (err) { - throw new MigrationError(`upgrade block ${flavour} failed. - ${err}`); - } - }; - - upgradeCollection = (rootData: Y.Doc) => { - this._upgradeBlockVersions(rootData); - collectionMigrations.forEach(migration => { - try { - if (migration.condition(rootData)) { - migration.migrate(rootData); - } - } catch (err) { - console.error(err); - throw new MigrationError(migration.desc); - } - }); - }; - - upgradeDoc = ( - oldPageVersion: number, - oldBlockVersions: Record, - docData: Y.Doc - ) => { - // block migrations - const blocks = docData.getMap('blocks') as Y.Map>; - Array.from(blocks.values()).forEach(block => { - const flavour = block.get('sys:flavour') as string; - const currentVersion = - (block.get('sys:version') as number) ?? oldBlockVersions[flavour] ?? 0; - if (currentVersion == null) { - throw new MigrationError( - `version for flavour ${flavour} not found in block` - ); - } - this.upgradeBlock(flavour, currentVersion, block); - }); - - // doc migrations - docMigrations.forEach(migration => { - try { - if (migration.condition(oldPageVersion, docData)) { - migration.migrate(oldPageVersion, docData); - } - } catch (err) { - throw new MigrationError(`${migration.desc} - ${err}`); - } - }); - }; - validate = ( flavour: string, parentFlavour?: string, diff --git a/packages/playground/apps/_common/components/pdf/worker.ts b/packages/playground/apps/_common/components/pdf/worker.ts index 4d0b1ed84e95..daaa292fc1a1 100644 --- a/packages/playground/apps/_common/components/pdf/worker.ts +++ b/packages/playground/apps/_common/components/pdf/worker.ts @@ -36,6 +36,7 @@ function renderToImageData(index: number, scale: number) { bitmap.fill(0, 0, width, height); page.render(bitmap, 0, 0, width, height, 0, flags); + // @ts-ignore const data = new Uint8ClampedArray(bitmap.toBytes()); bitmap.close();