mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-07-13 08:06:24 +08:00
25 lines
641 B
TypeScript
25 lines
641 B
TypeScript
import { replaceIdMiddleware } from '@blocksuite/blocks';
|
|
import {
|
|
type DocSnapshot,
|
|
Transformer,
|
|
type Workspace,
|
|
} from '@blocksuite/store';
|
|
|
|
export async function importFromSnapshot(
|
|
collection: Workspace,
|
|
snapshot: DocSnapshot
|
|
) {
|
|
const job = new Transformer({
|
|
schema: collection.schema,
|
|
blobCRUD: collection.blobSync,
|
|
docCRUD: {
|
|
create: (id: string) => collection.createDoc({ id }),
|
|
get: (id: string) => collection.getDoc(id),
|
|
delete: (id: string) => collection.removeDoc(id),
|
|
},
|
|
middlewares: [replaceIdMiddleware(collection.idGenerator)],
|
|
});
|
|
|
|
return job.snapshotToDoc(snapshot);
|
|
}
|