-
Notifications
You must be signed in to change notification settings - Fork 50
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
selectors: docs enhancements, new construction helpers.
- Loading branch information
Showing
2 changed files
with
67 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package selector | ||
|
||
import ( | ||
"strings" | ||
|
||
"github.com/ipld/go-ipld-prime/codec/json" | ||
"github.com/ipld/go-ipld-prime/node/basic" | ||
) | ||
|
||
// REVIEW: I feel sketchy about CompileJSONSelector because it brings in json as a transitive dependency. | ||
// This has consequences as far as dragging go-cid in because our json shares code with dagjson... | ||
// and then go-cid ends up in the transitives of the traversal package, since traversal depends on selector. | ||
// That's... not great. | ||
// On the other hand: trying to keep up that paper wall is creating a lot of strife. Maybe it's time to give up. | ||
|
||
func CompileJSONSelector(jsonStr string) (Selector, error) { | ||
na := basicnode.Prototype.Any.NewBuilder() | ||
if err := json.Decode(na, strings.NewReader(jsonStr)); err != nil { | ||
return nil, err | ||
} | ||
if s, err := CompileSelector(na.Build()); err != nil { | ||
return nil, err | ||
} else { | ||
return s, nil | ||
} | ||
} | ||
|
||
func must(s Selector, e error) Selector { | ||
if e != nil { | ||
panic(e) | ||
} | ||
return s | ||
} | ||
|
||
var CommonSelector_MatchPoint = must(CompileJSONSelector(`{".":{}}`)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters