go-ipld-prime icon indicating copy to clipboard operation
go-ipld-prime copied to clipboard

Reduce syntax load around selector usage starting from a CID

Open warpfork opened this issue 3 years ago • 1 comments

There's a lot of syntactic weight to using selectors if your starting point is a CID.

Some of this is a natural consequence of the fact that Selectors work on the node level rather than the block level. So, starting from a CID is a narrower case than the general. But it should be easy to add some helper functions that address this case.

Take this example of the problem: https://github.com/ipld/go-ipld-selector-text-lite/blob/fafd9c6f07cd53486d0464c12d1573ea81246e50/example_test.go#L54-L121 In this we can see:

  • biggest issue: the user is ending up calling nodePrototypeChooser and linkSystem.Load once, manually, to prime the pump. We can and should provide a helper function that just does this for you.

There's a couple other things to observe here in that example that could use improvement, but might be more complex:

  • people are gluing github.com/ipfs/go-ipld-format.DAGService to LinkSystem.StorageReadOpener... which is good and expected, but maybe we should make that glue code available and used in an example somewhere.
    • (antifeature: this'll add the old go-ipld-format repo to our go mod file, which is not ideal. Maybe there's a clever approach, though.)
    • maybe this will also go away as a problem if we push more of a replacement interface. We have storage.Memory; is it not obvious enough? Is it not providing enough? It was meant for examples like this.
  • bonus: the dagpb.AddSupportToChooser( thing keeps showing up in libraries rather than applications, so... something about this is... not good. (Is it the docs and communication, or is the API for this not composing well?)

warpfork avatar Jun 07 '21 16:06 warpfork

Something similar also shows up in the vincinity of https://github.com/ipfs/go-fetcher/blob/808966ec67e2383dd78fe70dc5bb896c9d69ac69/impl/blockservice/fetcher.go#L93 , and may (? I'm not sure) have influenced some of the functions appearing on interfaces in the area: https://github.com/ipfs/go-fetcher/blob/808966ec67e2383dd78fe70dc5bb896c9d69ac69/fetcher.go#L19

warpfork avatar Jun 07 '21 16:06 warpfork