GithubHelp home page GithubHelp logo

Comments (3)

doodlewind avatar doodlewind commented on June 25, 2024

You can try the snapshot API: https://blocksuite.io/guide/data-synchronization.html#snapshot-api

from blocksuite.

undefined-unknown avatar undefined-unknown commented on June 25, 2024

You can try the snapshot API: https://blocksuite.io/guide/data-synchronization.html#snapshot-api

Thanks for the answer!
One problem here is that I am doing const json = await job.docToSnapshot(doc); to store json in sql. I will do it again the next time I retrieve it.
const schema = new Schema().register(AffineSchemas); const collection = new DocCollection({ schema }); const job = new Job({ collection }); const doc = await job.snapshotToDoc(docSnapshot); doc.load();

Such an operation is not allowed because doc.meta.tags is not in the new collection instance. In this case, should I store it twice? That is
const collectionSnapshot = await job.collectionInfoToSnapshot();
Do it first the next time you use it

const schema = new Schema().register(AffineSchemas); const collection = new DocCollection({ schema }); const job = new Job({ collection }); job.snapshotToCollectionInfo(_collectionSnapshot); const doc = await job.snapshotToDoc(docSnapshot); doc.load();

from blocksuite.

vincenzodomina avatar vincenzodomina commented on June 25, 2024

Please re-open this issue, as I found it not to be straightforward to do JSON export-import with the Snapshot API.

In my case i applied the code like in the mentioned Snapshot API docs:
import { Job } from '@blocksuite/store';
const doc = createEmptyDoc().init();
const editor = new PageEditor();
editor.doc = doc;
const { collection } = doc;
const job = new Job({ collection });
const json = await job.docToSnapshot(doc);
const newDoc = await job.snapshotToDoc(json);

and it would throw me this:
text.js:19 Uncaught (in promise) TypeError: Cannot assign to read only property 'insert' of object '#<Object>' at new Text (text.js:19:34) at fromJSON (json.js:46:20) at eval (base.js:15:76) at Array.map (<anonymous>) at BaseBlockTransformer._propsFromSnapshot (base.js:14:61) at BaseBlockTransformer.fromSnapshot (base.js:26:28) at Job._snapshotToBlock (job.js:301:45) at Job._snapshotToBlock (job.js:308:24) at async Job._snapshotToBlock (job.js:308:13) at async Job.snapshotToBlock (job.js:60:27) at async Job.snapshotToDoc (job.js:95:13)

This error is caused by the job.snapshotToDoc(json) - method. If i feed this method with a "emptyDefaultSnapshot"-object it did not throw this error.

So how is the proper way to get exported JSON back in?

from blocksuite.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.