Conversation
core/coreapi/dag.go
Outdated
| type DagAPI CoreAPI | ||
|
|
||
| func (api *DagAPI) Add(ctx context.Context, src io.Reader, inputEnc string, format cid.Prefix) ([]coreiface.Node, error) { | ||
| nds, err := coredag.ParseInputs(inputEnc, cid.CodecToStr[format.Codec], src, format.MhType, format.MhLength) |
There was a problem hiding this comment.
we should probably validate format.Codec, otherwise we would return bad data from the cid.CodeToStr map
13b7adb to
c780466
Compare
core/coreapi/interface/interface.go
Outdated
| } | ||
|
|
||
| type DagAPI interface { | ||
| Add(ctx context.Context, src io.Reader, inputEnc string, format cid.Prefix) ([]Node, error) |
There was a problem hiding this comment.
Maybe Put instead of Add?
I also think its important for people to be able to call these methods without having to import other packages. So making the format argument a pointer, and having some sort of defaults for when the user passes nil is something we should think about.
c780466 to
0a9cf52
Compare
53a14fd to
34fe6d0
Compare
core/coreapi/dag.go
Outdated
| return api.core().ResolveNode(ctx, path) | ||
| } | ||
|
|
||
| func (api *DagAPI) Tree(ctx context.Context, p coreiface.Path, depth int) ([]coreiface.Path, error) { |
There was a problem hiding this comment.
this makes me realize we should have an ipfs dag tree command
core/coreapi/dag_test.go
Outdated
| t.Error(err) | ||
| } | ||
|
|
||
| _, err = api.Dag().Put(ctx, strings.NewReader(`"Hello"`), "json", nil) |
There was a problem hiding this comment.
I would check the Cid of the created object. Just one more additional protection against us breaking things in the future.
core/coreapi/interface/interface.go
Outdated
|
|
||
| ResolvePath(context.Context, Path) (Path, error) | ||
| ResolveNode(context.Context, Path) (Node, error) | ||
| ResolveNode(context.Context, Path) (Node, error) //TODO: should this get dropped in favor of DagAPI.Get? |
There was a problem hiding this comment.
I think this is fine to keep as a helper alias
753540a to
7b5b4f1
Compare
7b5b4f1 to
11bc903
Compare
License: MIT Signed-off-by: Łukasz Magiera <magik6k@gmail.com>
License: MIT Signed-off-by: Łukasz Magiera <magik6k@gmail.com>
4b62309 to
b9be6c1
Compare
License: MIT Signed-off-by: Łukasz Magiera <magik6k@gmail.com>
b9be6c1 to
f153c01
Compare
|
This is the first PR in the coreapi series that needs to get merged, mostly due to test utils being done here. @whyrusleeping do you see anything more TODO here? |
core/coreapi/interface/interface.go
Outdated
| // DagAPI specifies the interface to IPLD | ||
| type DagAPI interface { | ||
| // Put inserts data using specified format and input encoding. | ||
| // If format is not specified (nil), default dag-cbor/sha256 is used |
There was a problem hiding this comment.
Unless used with WithCodec or WithHash, the defaults "dag-cbor" and "sha256" are used.
core/coreapi/interface/interface.go
Outdated
| type DagAPI interface { | ||
| // Put inserts data using specified format and input encoding. | ||
| // If format is not specified (nil), default dag-cbor/sha256 is used | ||
| Put(ctx context.Context, src io.Reader, opts ...options.DagPutOption) ([]Node, error) |
There was a problem hiding this comment.
Why is it desirable to have Put() return a slide of Nodes?
There was a problem hiding this comment.
I guess it could return a slice of cids instead. But we need to know what was added.
There was a problem hiding this comment.
I mean why is it desirable that it's a slice -- isn't there a root node for the added dag?
There was a problem hiding this comment.
hrm... I think all of our current usecases would be fine with just the 'root' cid. Can you confirm that @magik6k ?
There was a problem hiding this comment.
It will be fine, yes. I decided to return a slice as it is what was returned by coredag.ParseInputs, I think the reasoning behind it was that the reader can provide more than one node, though it's not implemented now.
There was a problem hiding this comment.
Mh okay but what's the scenario that makes us want a slice returned here, versus just calling Tree() with the Node.Cid() returned from Put()? We'll keep all those nodes around in memory to return them from a function whose purpose isn't to iterate a graph (that's what Tree() is for).
I feel like we can rather be consistent with js-ipfs here.
a3952e2 to
460e0ae
Compare
|
Made |
460e0ae to
f213060
Compare
|
@magik6k any idea why the tests are all failing? |
License: MIT Signed-off-by: Łukasz Magiera <magik6k@gmail.com>
f213060 to
db31833
Compare
TODO: