selector

package
v1.7.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 29, 2021 License: MIT, MIT Imports: 2 Imported by: 0

Documentation

Index

Constants

View Source
const (
	SelectorKey_Matcher              = "."
	SelectorKey_ExploreAll           = "a"
	SelectorKey_ExploreFields        = "f"
	SelectorKey_ExploreIndex         = "i"
	SelectorKey_ExploreRange         = "r"
	SelectorKey_ExploreRecursive     = "R"
	SelectorKey_ExploreUnion         = "|"
	SelectorKey_ExploreConditional   = "&"
	SelectorKey_ExploreRecursiveEdge = "@"
	SelectorKey_Next                 = ">"
	SelectorKey_Fields               = "f>"
	SelectorKey_Index                = "i"
	SelectorKey_Start                = "^"
	SelectorKey_End                  = "$"
	SelectorKey_Sequence             = ":>"
	SelectorKey_Limit                = "l"
	SelectorKey_LimitDepth           = "depth"
	SelectorKey_LimitNone            = "none"
	SelectorKey_StopAt               = "!"
	SelectorKey_Condition            = "&"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type ExploreAll

type ExploreAll struct {
	// contains filtered or unexported fields
}

ExploreAll is similar to a `*` -- it traverses all elements of an array, or all entries in a map, and applies a next selector to the reached nodes.

func (ExploreAll) Decide

func (s ExploreAll) Decide(n ipld.Node) bool

Decide always returns false because this is not a matcher

func (ExploreAll) Explore

func (s ExploreAll) Explore(n ipld.Node, p ipld.PathSegment) Selector

Explore returns the node's selector for all fields

func (ExploreAll) Interests

func (s ExploreAll) Interests() []ipld.PathSegment

Interests for ExploreAll is nil (meaning traverse everything)

type ExploreFields

type ExploreFields struct {
	// contains filtered or unexported fields
}

ExploreFields traverses named fields in a map (or equivalently, struct, if traversing on typed/schema nodes) and applies a next selector to the reached nodes.

Note that a concept of "ExplorePath" (e.g. "foo/bar/baz") can be represented as a set of three nexted ExploreFields selectors, each specifying one field. (For this reason, we don't have a special "ExplorePath" feature; use this.)

ExploreFields also works for selecting specific elements out of a list; if a "field" is a base-10 int, it will be coerced and do the right thing. ExploreIndex or ExploreRange is more appropriate, however, and should be preferred.

func (ExploreFields) Decide

func (s ExploreFields) Decide(n ipld.Node) bool

Decide always returns false because this is not a matcher

func (ExploreFields) Explore

func (s ExploreFields) Explore(n ipld.Node, p ipld.PathSegment) Selector

Explore returns the selector for the given path if it is a field in the selector node or nil if not

func (ExploreFields) Interests

func (s ExploreFields) Interests() []ipld.PathSegment

Interests for ExploreFields are the fields listed in the selector node

type ExploreIndex

type ExploreIndex struct {
	// contains filtered or unexported fields
}

ExploreIndex traverses a specific index in a list, and applies a next selector to the reached node.

func (ExploreIndex) Decide

func (s ExploreIndex) Decide(n ipld.Node) bool

Decide always returns false because this is not a matcher

func (ExploreIndex) Explore

func (s ExploreIndex) Explore(n ipld.Node, p ipld.PathSegment) Selector

Explore returns the node's selector if the path matches the index for this selector or nil if not

func (ExploreIndex) Interests

func (s ExploreIndex) Interests() []ipld.PathSegment

Interests for ExploreIndex is just the index specified by the selector node

type ExploreRange

type ExploreRange struct {
	// contains filtered or unexported fields
}

ExploreRange traverses a list, and for each element in the range specified, will apply a next selector to those reached nodes.

func (ExploreRange) Decide

func (s ExploreRange) Decide(n ipld.Node) bool

Decide always returns false because this is not a matcher

func (ExploreRange) Explore

func (s ExploreRange) Explore(n ipld.Node, p ipld.PathSegment) Selector

Explore returns the node's selector if the path matches an index in the range of this selector

func (ExploreRange) Interests

func (s ExploreRange) Interests() []ipld.PathSegment

Interests for ExploreRange are all path segments within the iteration range

type ExploreRecursive

type ExploreRecursive struct {
	// contains filtered or unexported fields
}

ExploreRecursive traverses some structure recursively. To guide this exploration, it uses a "sequence", which is another Selector tree; some leaf node in this sequence should contain an ExploreRecursiveEdge selector, which denotes the place recursion should occur.

In implementation, whenever evaluation reaches an ExploreRecursiveEdge marker in the recursion sequence's Selector tree, the implementation logically produces another new Selector which is a copy of the original ExploreRecursive selector, but with a decremented maxDepth parameter, and continues evaluation thusly.

It is not valid for an ExploreRecursive selector's sequence to contain no instances of ExploreRecursiveEdge; it *is* valid for it to contain more than one ExploreRecursiveEdge.

ExploreRecursive can contain a nested ExploreRecursive! This is comparable to a nested for-loop. In these cases, any ExploreRecursiveEdge instance always refers to the nearest parent ExploreRecursive (in other words, ExploreRecursiveEdge can be thought of like the 'continue' statement, or end of a for-loop body; it is *not* a 'goto' statement).

Be careful when using ExploreRecursive with a large maxDepth parameter; it can easily cause very large traversals (especially if used in combination with selectors like ExploreAll inside the sequence).

func (ExploreRecursive) Decide

func (s ExploreRecursive) Decide(n ipld.Node) bool

Decide always returns false because this is not a matcher

func (ExploreRecursive) Explore

Explore returns the node's selector for all fields

func (ExploreRecursive) Interests

func (s ExploreRecursive) Interests() []ipld.PathSegment

Interests for ExploreRecursive is empty (meaning traverse everything)

type ExploreRecursiveEdge

type ExploreRecursiveEdge struct{}

ExploreRecursiveEdge is a special sentinel value which is used to mark the end of a sequence started by an ExploreRecursive selector: the recursion goes back to the initial state of the earlier ExploreRecursive selector, and proceeds again (with a decremented maxDepth value).

An ExploreRecursive selector that doesn't contain an ExploreRecursiveEdge is nonsensical. Containing more than one ExploreRecursiveEdge is valid. An ExploreRecursiveEdge without an enclosing ExploreRecursive is an error.

func (ExploreRecursiveEdge) Decide

func (s ExploreRecursiveEdge) Decide(n ipld.Node) bool

Decide should ultimately never get called for an ExploreRecursiveEdge selector

func (ExploreRecursiveEdge) Explore

Explore should ultimately never get called for an ExploreRecursiveEdge selector

func (ExploreRecursiveEdge) Interests

func (s ExploreRecursiveEdge) Interests() []ipld.PathSegment

Interests should ultimately never get called for an ExploreRecursiveEdge selector

type ExploreUnion

type ExploreUnion struct {
	Members []Selector
}

ExploreUnion allows selection to continue with two or more distinct selectors while exploring the same tree of data.

ExploreUnion can be used to apply a Matcher on one node (causing it to be considered part of a (possibly labelled) result set), while simultaneously continuing to explore deeper parts of the tree with another selector, for example.

func (ExploreUnion) Decide

func (s ExploreUnion) Decide(n ipld.Node) bool

Decide returns true for a Union selector if any of the member selectors return true

func (ExploreUnion) Explore

func (s ExploreUnion) Explore(n ipld.Node, p ipld.PathSegment) Selector

Explore for a Union selector calls explore for each member selector and returns: - a new union selector if more than one member returns a selector - if exactly one member returns a selector, that selector - nil if no members return a selector

func (ExploreUnion) Interests

func (s ExploreUnion) Interests() []ipld.PathSegment

Interests for ExploreUnion is: - nil (aka all) if any member selector has nil interests - the union of values returned by all member selectors otherwise

type Matcher

type Matcher struct{}

Matcher marks a node to be included in the "result" set. (All nodes traversed by a selector are in the "covered" set (which is a.k.a. "the merkle proof"); the "result" set is a subset of the "covered" set.)

In libraries using selectors, the "result" set is typically provided to some user-specified callback.

A selector tree with only "explore*"-type selectors and no Matcher selectors is valid; it will just generate a "covered" set of nodes and no "result" set. TODO: From spec: implement conditions and labels

func (Matcher) Decide

func (s Matcher) Decide(n ipld.Node) bool

Decide is always true for a match cause it's in the result set TODO: Implement boolean logic for conditionals

func (Matcher) Explore

func (s Matcher) Explore(n ipld.Node, p ipld.PathSegment) Selector

Explore will return nil because a matcher is a terminal selector

func (Matcher) Interests

func (s Matcher) Interests() []ipld.PathSegment

Interests are empty for a matcher (for now) because It is always just there to match, not explore further

type ParseContext

type ParseContext struct {
	// contains filtered or unexported fields
}

ParseContext tracks the progress when parsing a selector

func (ParseContext) ParseExploreAll

func (pc ParseContext) ParseExploreAll(n ipld.Node) (Selector, error)

ParseExploreAll assembles a Selector from a ExploreAll selector node

func (ParseContext) ParseExploreFields

func (pc ParseContext) ParseExploreFields(n ipld.Node) (Selector, error)

ParseExploreFields assembles a Selector from a ExploreFields selector node

func (ParseContext) ParseExploreIndex

func (pc ParseContext) ParseExploreIndex(n ipld.Node) (Selector, error)

ParseExploreIndex assembles a Selector from a ExploreIndex selector node

func (ParseContext) ParseExploreRange

func (pc ParseContext) ParseExploreRange(n ipld.Node) (Selector, error)

ParseExploreRange assembles a Selector from a ExploreRange selector node

func (ParseContext) ParseExploreRecursive

func (pc ParseContext) ParseExploreRecursive(n ipld.Node) (Selector, error)

ParseExploreRecursive assembles a Selector from a ExploreRecursive selector node

func (ParseContext) ParseExploreRecursiveEdge

func (pc ParseContext) ParseExploreRecursiveEdge(n ipld.Node) (Selector, error)

ParseExploreRecursiveEdge assembles a Selector from a exploreRecursiveEdge selector node

func (ParseContext) ParseExploreUnion

func (pc ParseContext) ParseExploreUnion(n ipld.Node) (Selector, error)

ParseExploreUnion assembles a Selector from an ExploreUnion selector node

func (ParseContext) ParseMatcher

func (pc ParseContext) ParseMatcher(n ipld.Node) (Selector, error)

ParseMatcher assembles a Selector from a matcher selector node TODO: Parse labels and conditions

func (ParseContext) ParseSelector

func (pc ParseContext) ParseSelector(n ipld.Node) (Selector, error)

ParseSelector creates a Selector from an IPLD Selector Node with the given context

func (ParseContext) PushParent

func (pc ParseContext) PushParent(parent ParsedParent) ParseContext

PushParent puts a parent onto the stack of parents for a parse context

type ParsedParent

type ParsedParent interface {
	Link(s Selector) bool
}

ParsedParent is created whenever you are parsing a selector node that may have child selectors nodes that need to know it

type RecursionLimit

type RecursionLimit struct {
	// contains filtered or unexported fields
}

RecursionLimit is a union type that captures all data about the recursion limit (both its type and data specific to the type)

func RecursionLimitDepth

func RecursionLimitDepth(depth int) RecursionLimit

RecursionLimitDepth returns a depth limited recursion to the given depth

func RecursionLimitNone

func RecursionLimitNone() RecursionLimit

RecursionLimitNone return recursion with no limit

func (RecursionLimit) Depth

func (rl RecursionLimit) Depth() int

Depth returns the depth for a depth recursion limit, or 0 otherwise

func (RecursionLimit) Mode

Mode returns the type for this recursion limit

type RecursionLimit_Mode

type RecursionLimit_Mode uint8

RecursionLimit_Mode is an enum that represents the type of a recursion limit -- either "depth" or "none" for now

const (
	// RecursionLimit_None means there is no recursion limit
	RecursionLimit_None RecursionLimit_Mode = 0
	// RecursionLimit_Depth mean recursion stops after the recursive selector
	// is copied to a given depth
	RecursionLimit_Depth RecursionLimit_Mode = 1
)

type SegmentIterator

type SegmentIterator interface {
	Next() (pathSegment ipld.PathSegment, value ipld.Node, err error)
	Done() bool
}

SegmentIterator iterates either a list or a map, generating PathSegments instead of indexes or keys

func NewSegmentIterator

func NewSegmentIterator(n ipld.Node) SegmentIterator

NewSegmentIterator generates a new iterator based on the node type

type Selector

type Selector interface {
	Interests() []ipld.PathSegment                // returns the segments we're likely interested in **or nil** if we're a high-cardinality or expression based matcher and need all segments proposed to us.
	Explore(ipld.Node, ipld.PathSegment) Selector // explore one step -- iteration comes from outside (either whole node, or by following suggestions of Interests).  returns nil if no interest.  you have to traverse to the next node yourself (the selector doesn't do it for you because you might be considering multiple selection reasons at the same time).
	Decide(ipld.Node) bool
}

Selector is the programmatic representation of an IPLD Selector Node and can be applied to traverse a given IPLD DAG

func ParseSelector

func ParseSelector(n ipld.Node) (Selector, error)

ParseSelector creates a Selector that can be traversed from an IPLD Selector node

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL