ipldbridge.go 1.81 KB
Newer Older
1 2 3 4 5 6 7 8 9 10
package ipldbridge

import (
	"context"

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

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

// 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.
21
type LinkContext = ipld.LinkContext
22 23 24 25 26 27 28 29 30 31

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

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

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

	// DecodeNode decodes bytes crossing a network to an IPLD Node.
40
	DecodeNode([]byte) (ipld.Node, error)
hannahhoward's avatar
hannahhoward committed
41 42 43

	// 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.
44
	DecodeSelectorSpec(rootedSelector ipld.Node) (ipld.Node, Selector, error)
hannahhoward's avatar
hannahhoward committed
45 46 47 48

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