Commit 9d87c836 authored by Eric Myhre's avatar Eric Myhre

Ah yes, fix TypedLinkNode, the actual cycle cause.

This is the last part of the cleanup and cyclic import fix started
in the previous commit.
parent a2ea4706
package typed
import "github.com/ipld/go-ipld-prime"
// typed.LinkNode is a superset of the schema.TypedNode interface, and has one additional behavior.
//
// A typed.LinkNode contains a hint for the appropriate node builder to use for loading data
// on the other side of the link contained within the node, so that it can be assembled
// into a node representation and validated against the schema as quickly as possible
//
// So, for example, if you wanted to support loading the other side of a link
// with a code-gen'd node builder while utilizing the automatic loading facilities
// of the traversal package, you could write a LinkNodeBuilderChooser as follows:
//
// func LinkNodeBuilderChooser(lnk ipld.Link, lnkCtx ipld.LinkContext) ipld.NodeBuilder {
// if tlnkNd, ok := lnkCtx.LinkNode.(typed.LinkNode); ok {
// return tlnkNd.SuggestedNodeBuilder()
// }
// return ipldfree.NodeBuilder()
// }
//
type LinkNode interface {
ReferencedNodeBuilder() ipld.NodeBuilder
}
...@@ -50,3 +50,24 @@ type TypedNode interface { ...@@ -50,3 +50,24 @@ type TypedNode interface {
// if the streatgy is "tuple", then it will be ReprKind=="list". // if the streatgy is "tuple", then it will be ReprKind=="list".
Representation() ipld.Node Representation() ipld.Node
} }
// schema.TypedLinkNode is a superset of the schema.TypedNode interface, and has one additional behavior.
//
// A schema.TypedLinkNode contains a hint for the appropriate node builder to use for loading data
// on the other side of the link contained within the node, so that it can be assembled
// into a node representation and validated against the schema as quickly as possible
//
// So, for example, if you wanted to support loading the other side of a link
// with a code-gen'd node builder while utilizing the automatic loading facilities
// of the traversal package, you could write a LinkNodeBuilderChooser as follows:
//
// func LinkNodeBuilderChooser(lnk ipld.Link, lnkCtx ipld.LinkContext) ipld.NodeBuilder {
// if tlnkNd, ok := lnkCtx.LinkNode.(schema.TypedLinkNode); ok {
// return tlnkNd.LinkTargetNodeBuilder()
// }
// return ipldfree.NodeBuilder()
// }
//
type TypedLinkNode interface {
LinkTargetNodeBuilder() ipld.NodeBuilder
}
...@@ -6,7 +6,7 @@ import ( ...@@ -6,7 +6,7 @@ import (
"io" "io"
ipld "github.com/ipld/go-ipld-prime" ipld "github.com/ipld/go-ipld-prime"
"github.com/ipld/go-ipld-prime/impl/typed" "github.com/ipld/go-ipld-prime/schema"
) )
// init sets all the values in TraveralConfig to reasonable defaults // init sets all the values in TraveralConfig to reasonable defaults
...@@ -26,8 +26,8 @@ func (tc *Config) init() { ...@@ -26,8 +26,8 @@ func (tc *Config) init() {
} }
if tc.LinkNodeBuilderChooser == nil { if tc.LinkNodeBuilderChooser == nil {
tc.LinkNodeBuilderChooser = func(lnk ipld.Link, lnkCtx ipld.LinkContext) (ipld.NodeBuilder, error) { tc.LinkNodeBuilderChooser = func(lnk ipld.Link, lnkCtx ipld.LinkContext) (ipld.NodeBuilder, error) {
if tlnkNd, ok := lnkCtx.LinkNode.(typed.LinkNode); ok { if tlnkNd, ok := lnkCtx.LinkNode.(schema.TypedLinkNode); ok {
return tlnkNd.ReferencedNodeBuilder(), nil return tlnkNd.LinkTargetNodeBuilder(), nil
} }
return nil, fmt.Errorf("no LinkNodeBuilderChooser configured") return nil, fmt.Errorf("no LinkNodeBuilderChooser configured")
} }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment