mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-13 21:05:19 +00:00
1. **Major Architectural Change: Schema Management**
- Moved from `workspace.schema` to `store.schema` throughout the codebase
- Removed schema property from Workspace and Doc interfaces
- Added `BlockSchemaExtension` pattern across multiple block types
2. **Block Schema Extensions Added**
- Added new `BlockSchemaExtension` to numerous block types including:
- DataView, Surface, Attachment, Bookmark, Code
- Database, Divider, EdgelessText, Embed blocks (Figma, Github, HTML, etc.)
- Frame, Image, Latex, List, Note, Paragraph
- Root, Surface Reference, Table blocks
3. **Import/Export System Updates**
- Updated import functions to accept `schema` parameter:
- `importHTMLToDoc`
- `importHTMLZip`
- `importMarkdownToDoc`
- `importMarkdownZip`
- `importNotionZip`
- Modified export functions to use new schema pattern
4. **Test Infrastructure Updates**
- Updated test files to use new schema extensions
- Modified test document creation to include schema extensions
- Removed direct schema registration in favor of extensions
5. **Service Layer Changes**
- Updated various services to use `getAFFiNEWorkspaceSchema()`
- Modified transformer initialization to use document schema
- Updated collection initialization patterns
6. **Version Management**
- Removed version-related properties and methods from:
- `WorkspaceMetaImpl`
- `TestMeta`
- `DocImpl`
- Removed `blockVersions` and `workspaceVersion/pageVersion`
7. **Store and Extension Updates**
- Added new store extensions and adapters
- Updated store initialization patterns
- Added new schema-related functionality in store extension
This PR represents a significant architectural shift in how schemas are managed, moving from a workspace-centric to a store-centric approach, while introducing a more extensible block schema system through `BlockSchemaExtension`. The changes touch multiple layers of the application including core functionality, services, testing infrastructure, and import/export capabilities.
98 lines
2.9 KiB
TypeScript
98 lines
2.9 KiB
TypeScript
import { AffineSchemas, SpecProvider } from '@blocksuite/blocks';
|
|
import { nanoid, Schema, Transformer } from '@blocksuite/store';
|
|
import {
|
|
createAutoIncrementIdGenerator,
|
|
type DocCollectionOptions,
|
|
TestWorkspace,
|
|
} from '@blocksuite/store/test';
|
|
import {
|
|
type BlobSource,
|
|
BroadcastChannelAwarenessSource,
|
|
BroadcastChannelDocSource,
|
|
IndexedDBBlobSource,
|
|
MemoryBlobSource,
|
|
} from '@blocksuite/sync';
|
|
import * as Y from 'yjs';
|
|
|
|
import { MockServerBlobSource } from '../../_common/sync/blob/mock-server.js';
|
|
import type { InitFn } from '../data/utils.js';
|
|
|
|
const params = new URLSearchParams(location.search);
|
|
const room = params.get('room');
|
|
const isE2E = room?.startsWith('playwright');
|
|
const blobSourceArgs = (params.get('blobSource') ?? '').split(',');
|
|
|
|
export function createStarterDocCollection() {
|
|
const collectionId = room ?? 'starter';
|
|
const schema = new Schema();
|
|
schema.register(AffineSchemas);
|
|
const idGenerator = isE2E ? createAutoIncrementIdGenerator() : nanoid;
|
|
|
|
let docSources: DocCollectionOptions['docSources'];
|
|
if (room) {
|
|
docSources = {
|
|
main: new BroadcastChannelDocSource(`broadcast-channel-${room}`),
|
|
};
|
|
}
|
|
const id = room ?? `starter-${Math.random().toString(16).slice(2, 8)}`;
|
|
|
|
const blobSources = {
|
|
main: new MemoryBlobSource(),
|
|
shadows: [] as BlobSource[],
|
|
} satisfies DocCollectionOptions['blobSources'];
|
|
if (blobSourceArgs.includes('mock')) {
|
|
blobSources.shadows.push(new MockServerBlobSource(collectionId));
|
|
}
|
|
if (blobSourceArgs.includes('idb')) {
|
|
blobSources.shadows.push(new IndexedDBBlobSource(collectionId));
|
|
}
|
|
|
|
const options: DocCollectionOptions = {
|
|
id: collectionId,
|
|
idGenerator,
|
|
awarenessSources: [new BroadcastChannelAwarenessSource(id)],
|
|
docSources,
|
|
blobSources,
|
|
};
|
|
const collection = new TestWorkspace(options);
|
|
collection.storeExtensions = SpecProvider._.getSpec('store').value;
|
|
collection.start();
|
|
|
|
// debug info
|
|
window.collection = collection;
|
|
window.blockSchemas = AffineSchemas;
|
|
window.job = new Transformer({
|
|
schema,
|
|
blobCRUD: collection.blobSync,
|
|
docCRUD: {
|
|
create: (id: string) => collection.createDoc({ id }),
|
|
get: (id: string) => collection.getDoc(id),
|
|
delete: (id: string) => collection.removeDoc(id),
|
|
},
|
|
});
|
|
window.Y = Y;
|
|
|
|
return collection;
|
|
}
|
|
|
|
export async function initStarterDocCollection(collection: TestWorkspace) {
|
|
// use built-in init function
|
|
const functionMap = new Map<
|
|
string,
|
|
(collection: TestWorkspace, id: string) => Promise<void> | void
|
|
>();
|
|
Object.values(
|
|
(await import('../data/index.js')) as Record<string, InitFn>
|
|
).forEach(fn => functionMap.set(fn.id, fn));
|
|
const init = params.get('init') || 'preset';
|
|
if (functionMap.has(init)) {
|
|
collection.meta.initialize();
|
|
await functionMap.get(init)?.(collection, 'doc:home');
|
|
const doc = collection.getDoc('doc:home');
|
|
if (!doc?.loaded) {
|
|
doc?.load();
|
|
}
|
|
doc?.resetHistory();
|
|
}
|
|
}
|