ipld / js-dag-json

JSON Directed Acyclic Graph for IPLD
Other
15 stars 6 forks source link

Can not load this format to IPLD #24

Closed Zippersk closed 4 years ago

Zippersk commented 4 years ago

I do not understand this repo. Is it format for IPLD like cbor or pb? If so, why does it have a different interface? How can I load this to IPLD?

I want to store JSON object in dag-json format to IPLD. This is my code:

await DAG.Put(obj, {
            format: 'dag-json',
            hashAlg: 'sha2-256'
        });

But it ends with error Missing IPLD format "297". Which is dag-json. I already tried to load this format to IPLD by specifying it in config when starting ipfs node, but it has a different interface as others formats. So I ends with error:

    TypeError: Cannot read property 'serialize' of undefined

      at IPLDResolver.put (node_modules/ipfs/node_modules/ipld/src/index.js:191:40
mikeal commented 4 years ago

This conforms to the new Block interface, not the old js-ipld interface. You can see how the usage works in the README https://github.com/ipld/js-dag-json#json-directed-acrylic-graph-for-ipld .

Are you using js-ipfs? I don’t think we have an up to date dag-json for the old interface that js-ipfs uses.

Zippersk commented 4 years ago

Thanks for answer! Yes, I am using js-ifps. Does it mean that this repo is unusable with js-ipfs as a codec for now? Is it usable with some other implementation of ipfs?

I think it would be really helpful (not only for me) to show in readme how to store data serialized with this codec in IPFS.

mikeal commented 4 years ago

I’m actually not sure how to load new/custom codecs into js-ipfs’s DAG API.

Maybe this is something @achingbrain or @alanshaw knows how to do. dag-json is definitely not loaded by default.

You may just want to use dag-cbor. It’s included by default and works a bit better than dag-json (the representation is smaller, mainly due to native binary support).

alanshaw commented 4 years ago

Use https://github.com/ipfs/js-ipfs/tree/master/packages/ipfs#optionsipld and pass in the loadFormat option.

Ah, scratch that, drive by comment! Like @mikeal said it won't work this is module. ipld-dag-cbor looks like your best bet for now...or maybe you could use the output of this module with the IPFS block API?