mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-07-18 02:26:21 +08:00
27 lines
785 B
TypeScript
27 lines
785 B
TypeScript
import { AffineSchemas } from '@blocksuite/affine/schemas';
|
|
import { replaceIdMiddleware } from '@blocksuite/affine/shared/adapters';
|
|
import {
|
|
type DocSnapshot,
|
|
Schema,
|
|
Transformer,
|
|
type Workspace,
|
|
} from '@blocksuite/store';
|
|
|
|
export async function importFromSnapshot(
|
|
collection: Workspace,
|
|
snapshot: DocSnapshot
|
|
) {
|
|
const job = new Transformer({
|
|
schema: new Schema().register(AffineSchemas),
|
|
blobCRUD: collection.blobSync,
|
|
docCRUD: {
|
|
create: (id: string) => collection.createDoc(id).getStore({ id }),
|
|
get: (id: string) => collection.getDoc(id)?.getStore({ id }) ?? null,
|
|
delete: (id: string) => collection.removeDoc(id),
|
|
},
|
|
middlewares: [replaceIdMiddleware(collection.idGenerator)],
|
|
});
|
|
|
|
return job.snapshotToDoc(snapshot);
|
|
}
|