ipldbridge.go 2.6 KB
Newer Older
1 2 3 4 5
package ipldbridge

import (
	"context"

6 7
	"github.com/ipld/go-ipld-prime/fluent"

8 9 10 11 12
	ipld "github.com/ipld/go-ipld-prime"
	ipldtraversal "github.com/ipld/go-ipld-prime/traversal"
	ipldselector "github.com/ipld/go-ipld-prime/traversal/selector"
)

13 14
// Loader is an alias from ipld, in case it's renamed/moved.
type Loader = ipld.Loader
15 16 17 18 19 20 21 22

// AdvVisitFn is an alias from ipld, in case it's renamed/moved.
type AdvVisitFn = ipldtraversal.AdvVisitFn

// Selector is an alias from ipld, in case it's renamed/moved.
type Selector = ipldselector.Selector

// LinkContext is an alias from ipld, in case it's renamed/moved.
23
type LinkContext = ipld.LinkContext
24 25 26 27 28 29 30

// TraversalProgress is an alias from ipld, in case it's renamed/moved.
type TraversalProgress = ipldtraversal.TraversalProgress

// TraversalReason is an alias from ipld, in case it's renamed/moved.
type TraversalReason = ipldtraversal.TraversalReason

31 32 33 34 35 36 37 38 39
// NodeBuilder is an alias from the ipld fluent nodebuilder, in case it's moved
type NodeBuilder = fluent.NodeBuilder

// ListBuilder is an alias from ipld fluent, in case it's moved
type ListBuilder = fluent.ListBuilder

// MapBuilder is an alias from ipld fluent, in case it's moved
type MapBuilder = fluent.MapBuilder

40 41 42 43
// SimpleNode is an alias from ipld fluent, to refer to its non error based
// node struct
type SimpleNode = fluent.Node

44 45 46
// IPLDBridge is an interface for making calls to IPLD, which can be
// replaced with alternative implementations
type IPLDBridge interface {
47 48 49 50 51 52 53

	// ExtractData provides an efficient mechanism for assembling nodes w/ fluent
	// interface
	ExtractData(ipld.Node, func(SimpleNode) interface{}) (interface{}, error)

	// BuildNode provides an efficient mechanism for assembling nodes w/ fluent
	// interface
54
	BuildNode(func(NodeBuilder) ipld.Node) (ipld.Node, error)
hannahhoward's avatar
hannahhoward committed
55 56

	// ValidateSelectorSpec verifies if a node matches the selector spec.
57
	ValidateSelectorSpec(rootedSelector ipld.Node) []error
hannahhoward's avatar
hannahhoward committed
58 59

	// EncodeNode encodes an IPLD Node to bytes for network transfer.
60
	EncodeNode(ipld.Node) ([]byte, error)
hannahhoward's avatar
hannahhoward committed
61 62

	// DecodeNode decodes bytes crossing a network to an IPLD Node.
63
	DecodeNode([]byte) (ipld.Node, error)
hannahhoward's avatar
hannahhoward committed
64 65 66

	// DecodeSelectorSpec checks if a generic IPLD node is a selector spec,
	// and if so, converts it to a root node and a go-ipld-prime Selector.
67
	DecodeSelectorSpec(rootedSelector ipld.Node) (ipld.Node, Selector, error)
hannahhoward's avatar
hannahhoward committed
68 69 70 71

	// Traverse performs a selector traversal, starting at a given root, using the given selector,
	// and the given link loader. The given visit function will be called for each node
	// visited.
72
	Traverse(ctx context.Context, loader Loader, root ipld.Node, s Selector, fn AdvVisitFn) error
73
}