This repository has been archived by the owner on Nov 22, 2023. It is now read-only.
/
sel.go
45 lines (40 loc) · 1.66 KB
/
sel.go
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
42
43
44
45
package selectors
import (
"github.com/ipld/go-ipld-prime"
basicnode "github.com/ipld/go-ipld-prime/node/basic"
"github.com/ipld/go-ipld-prime/traversal/selector"
"github.com/ipld/go-ipld-prime/traversal/selector/builder"
)
// All the default selector that reaches all the blocks
func All() ipld.Node {
ssb := builder.NewSelectorSpecBuilder(basicnode.Prototype.Any)
return ssb.ExploreRecursive(selector.RecursionLimitNone(),
ssb.ExploreAll(ssb.ExploreRecursiveEdge())).Node()
}
// Entries selects all entries of an IPLD collection without traversing any data linked in the entries
// Limitting the recursion depth to 1 will reach all the entries of a map but not beyond.
func Entries() ipld.Node {
ssb := builder.NewSelectorSpecBuilder(basicnode.Prototype.Any)
return ssb.ExploreRecursive(selector.RecursionLimitDepth(1),
ssb.ExploreAll(ssb.ExploreRecursiveEdge())).Node()
}
// Key selects the link and all the children associated with a given key in a Map
func Key(key string) ipld.Node {
ssb := builder.NewSelectorSpecBuilder(basicnode.Prototype.Any)
return ssb.ExploreUnion(ssb.Matcher(),
ssb.ExploreFields(func(efsb builder.ExploreFieldsSpecBuilder) {
efsb.Insert(key, ssb.ExploreRecursive(selector.RecursionLimitNone(),
ssb.ExploreAll(ssb.ExploreRecursiveEdge())))
})).Node()
}
// Hamt is used to query a HAMT without following the links in deferred nodes
func Hamt() ipld.Node {
ssb := builder.NewSelectorSpecBuilder(basicnode.Prototype.Any)
return ssb.ExploreRecursive(selector.RecursionLimitNone(),
ssb.ExploreAll(
ssb.ExploreFields(func(efsb builder.ExploreFieldsSpecBuilder) {
efsb.Insert("Value", ssb.ExploreRecursiveEdge())
}),
),
).Node()
}