ipldbridge.go 2.39 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
package ipldbridge

import (
	"context"

	ipld "github.com/ipld/go-ipld-prime"
	ipldrepose "github.com/ipld/go-ipld-prime/repose"
	ipldtraversal "github.com/ipld/go-ipld-prime/traversal"
	ipldselector "github.com/ipld/go-ipld-prime/traversal/selector"
)

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

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

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

// RawLoader is an alias from ipld, in case it's renamed/moved.
type RawLoader = ipldrepose.ActualLoader

// 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.
type LinkContext = ipldtraversal.LinkContext

// 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

// IPLDBridge is an interface for making calls to IPLD, which can be
// replaced with alternative implementations
type IPLDBridge interface {
hannahhoward's avatar
hannahhoward committed
42
	// ComposeLinkLoader converts a raw block loader into an IPLD node loader.
43
	ComposeLinkLoader(actualLoader RawLoader) LinkLoader
hannahhoward's avatar
hannahhoward committed
44 45

	// ValidateSelectorSpec verifies if a node matches the selector spec.
46
	ValidateSelectorSpec(cidRootedSelector ipld.Node) []error
hannahhoward's avatar
hannahhoward committed
47 48

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

	// DecodeNode decodes bytes crossing a network to an IPLD Node.
52
	DecodeNode([]byte) (ipld.Node, error)
hannahhoward's avatar
hannahhoward committed
53 54 55

	// 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.
56
	DecodeSelectorSpec(cidRootedSelector ipld.Node) (ipld.Node, Selector, error)
hannahhoward's avatar
hannahhoward committed
57 58 59 60

	// 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.
61 62
	Traverse(ctx context.Context, loader LinkLoader, root ipld.Node, s Selector, fn AdvVisitFn) error
}