snapshot of https://github.com/cortezaproject/corteza.git (2024.9.x, 2026-09-18; blobs > 131072B omitted)
Some checks failed
SonarQube / SonarQube (push) Failing after 5m28s
E2e test on main branch push / server and client test (map[name:admin port:8080]) (push) Failing after 3m33s
Server and lib tests / Library test (js) (push) Failing after 1m36s
Server and lib tests / Library test (vue) (push) Successful in 2m24s
Server and lib tests / Web client test (admin) (push) Successful in 2m52s
Server and lib tests / Web client test (compose) (push) Successful in 3m23s
Server and lib tests / Web client test (discovery) (push) Successful in 2m49s
Server and lib tests / Web client test (one) (push) Successful in 2m52s
Server and lib tests / Web client test (privacy) (push) Successful in 2m44s
Server and lib tests / Web client test (reporter) (push) Successful in 2m56s
Server and lib tests / Web client test (workflow) (push) Successful in 3m0s
Server and lib tests / Server tests (push) Failing after 4m55s
E2e test on main branch push / notify-failure (push) Failing after 9s
Server and lib tests / Send matrix testing notification (push) Successful in 2s
Mark stale issues and pull requests / stale (push) Successful in 40s
Some checks failed
SonarQube / SonarQube (push) Failing after 5m28s
E2e test on main branch push / server and client test (map[name:admin port:8080]) (push) Failing after 3m33s
Server and lib tests / Library test (js) (push) Failing after 1m36s
Server and lib tests / Library test (vue) (push) Successful in 2m24s
Server and lib tests / Web client test (admin) (push) Successful in 2m52s
Server and lib tests / Web client test (compose) (push) Successful in 3m23s
Server and lib tests / Web client test (discovery) (push) Successful in 2m49s
Server and lib tests / Web client test (one) (push) Successful in 2m52s
Server and lib tests / Web client test (privacy) (push) Successful in 2m44s
Server and lib tests / Web client test (reporter) (push) Successful in 2m56s
Server and lib tests / Web client test (workflow) (push) Successful in 3m0s
Server and lib tests / Server tests (push) Failing after 4m55s
E2e test on main branch push / notify-failure (push) Failing after 9s
Server and lib tests / Send matrix testing notification (push) Successful in 2s
Mark stale issues and pull requests / stale (push) Successful in 40s
This commit is contained in:
30
server/vendor/github.com/PaesslerAG/jsonpath/.gitignore
generated
vendored
Normal file
30
server/vendor/github.com/PaesslerAG/jsonpath/.gitignore
generated
vendored
Normal file
@@ -0,0 +1,30 @@
|
||||
# Compiled Object files, Static and Dynamic libs (Shared Objects)
|
||||
*.o
|
||||
*.a
|
||||
*.so
|
||||
|
||||
# Folders
|
||||
_obj
|
||||
_test
|
||||
|
||||
# Architecture specific extensions/prefixes
|
||||
*.[568vq]
|
||||
[568vq].out
|
||||
|
||||
*.cgo1.go
|
||||
*.cgo2.c
|
||||
_cgo_defun.c
|
||||
_cgo_gotypes.go
|
||||
_cgo_export.*
|
||||
|
||||
_testmain.go
|
||||
|
||||
*.exe
|
||||
*.test
|
||||
coverage.out
|
||||
|
||||
manual_test.go
|
||||
*.out
|
||||
*.err
|
||||
|
||||
.vscode
|
||||
6
server/vendor/github.com/PaesslerAG/jsonpath/.travis.yml
generated
vendored
Normal file
6
server/vendor/github.com/PaesslerAG/jsonpath/.travis.yml
generated
vendored
Normal file
@@ -0,0 +1,6 @@
|
||||
language: go
|
||||
|
||||
script: ./test.sh
|
||||
|
||||
go:
|
||||
- 1.9
|
||||
12
server/vendor/github.com/PaesslerAG/jsonpath/LICENSE
generated
vendored
Normal file
12
server/vendor/github.com/PaesslerAG/jsonpath/LICENSE
generated
vendored
Normal file
@@ -0,0 +1,12 @@
|
||||
Copyright (c) 2017, Paessler AG <support@paessler.com>
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
|
||||
|
||||
2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
|
||||
3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
11
server/vendor/github.com/PaesslerAG/jsonpath/README.md
generated
vendored
Normal file
11
server/vendor/github.com/PaesslerAG/jsonpath/README.md
generated
vendored
Normal file
@@ -0,0 +1,11 @@
|
||||
JSONPath
|
||||
====
|
||||
|
||||
[](https://travis-ci.org/PaesslerAG/jsonpath)
|
||||
[](https://godoc.org/github.com/PaesslerAG/jsonpath)
|
||||
|
||||
JSONPath is a complete implementation of [http://goessner.net/articles/JsonPath/](http://goessner.net/articles/JsonPath/).
|
||||
JSONPath can be combined with a script language. In many web samples it's combined with javascript. This framework comes without a script language but can be easily extended with one. See [example](https://godoc.org/github.com/PaesslerAG/jsonpath#example-package--Gval).
|
||||
|
||||
It is based on [Gval](https://github.com/PaesslerAG/gval) and can be combined with the modular expression languages based on gval.
|
||||
So for script features like multiply, length, regex or many more take a look at the documentation in the [GoDoc](https://godoc.org/github.com/PaesslerAG/jsonpath).
|
||||
54
server/vendor/github.com/PaesslerAG/jsonpath/jsonpath.go
generated
vendored
Normal file
54
server/vendor/github.com/PaesslerAG/jsonpath/jsonpath.go
generated
vendored
Normal file
@@ -0,0 +1,54 @@
|
||||
// Package jsonpath is an implementation of http://goessner.net/articles/JsonPath/
|
||||
// If a JSONPath contains one of
|
||||
// [key1, key2 ...], .., *, [min:max], [min:max:step], (? expression)
|
||||
// all matchs are listed in an []interface{}
|
||||
//
|
||||
// The package comes with an extension of JSONPath to access the wildcard values of a match.
|
||||
// If the JSONPath is used inside of a JSON object, you can use placeholder '#' or '#i' with natural number i
|
||||
// to access all wildcards values or the ith wildcard
|
||||
//
|
||||
// This package can be extended with gval modules for script features like multiply, length, regex or many more.
|
||||
// So take a look at github.com/PaesslerAG/gval.
|
||||
package jsonpath
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/PaesslerAG/gval"
|
||||
)
|
||||
|
||||
// New returns an selector for given JSONPath
|
||||
func New(path string) (gval.Evaluable, error) {
|
||||
return lang.NewEvaluable(path)
|
||||
}
|
||||
|
||||
//Get executes given JSONPath on given value
|
||||
func Get(path string, value interface{}) (interface{}, error) {
|
||||
eval, err := lang.NewEvaluable(path)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return eval(context.Background(), value)
|
||||
}
|
||||
|
||||
var lang = gval.NewLanguage(
|
||||
gval.Base(),
|
||||
gval.PrefixExtension('$', parseRootPath),
|
||||
gval.PrefixExtension('@', parseCurrentPath),
|
||||
)
|
||||
|
||||
//Language is the JSONPath Language
|
||||
func Language() gval.Language {
|
||||
return lang
|
||||
}
|
||||
|
||||
var placeholderExtension = gval.NewLanguage(
|
||||
lang,
|
||||
gval.PrefixExtension('{', parseJSONObject),
|
||||
gval.PrefixExtension('#', parsePlaceholder),
|
||||
)
|
||||
|
||||
//PlaceholderExtension is the JSONPath Language with placeholder
|
||||
func PlaceholderExtension() gval.Language {
|
||||
return placeholderExtension
|
||||
}
|
||||
204
server/vendor/github.com/PaesslerAG/jsonpath/parse.go
generated
vendored
Normal file
204
server/vendor/github.com/PaesslerAG/jsonpath/parse.go
generated
vendored
Normal file
@@ -0,0 +1,204 @@
|
||||
package jsonpath
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"math"
|
||||
"text/scanner"
|
||||
|
||||
"github.com/PaesslerAG/gval"
|
||||
)
|
||||
|
||||
type parser struct {
|
||||
*gval.Parser
|
||||
path path
|
||||
}
|
||||
|
||||
func parseRootPath(ctx context.Context, gParser *gval.Parser) (r gval.Evaluable, err error) {
|
||||
p := newParser(gParser)
|
||||
return p.parse(ctx)
|
||||
}
|
||||
|
||||
func parseCurrentPath(ctx context.Context, gParser *gval.Parser) (r gval.Evaluable, err error) {
|
||||
p := newParser(gParser)
|
||||
p.appendPlainSelector(currentElementSelector())
|
||||
return p.parse(ctx)
|
||||
}
|
||||
|
||||
func newParser(p *gval.Parser) *parser {
|
||||
return &parser{Parser: p, path: plainPath{}}
|
||||
}
|
||||
|
||||
func (p *parser) parse(c context.Context) (r gval.Evaluable, err error) {
|
||||
err = p.parsePath(c)
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return p.path.evaluate, nil
|
||||
}
|
||||
|
||||
func (p *parser) parsePath(c context.Context) error {
|
||||
switch p.Scan() {
|
||||
case '.':
|
||||
return p.parseSelect(c)
|
||||
case '[':
|
||||
keys, seperator, err := p.parseBracket(c)
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
switch seperator {
|
||||
case ':':
|
||||
if len(keys) > 3 {
|
||||
return fmt.Errorf("range query has at least the parameter [min:max:step]")
|
||||
}
|
||||
keys = append(keys, []gval.Evaluable{
|
||||
p.Const(0), p.Const(float64(math.MaxInt32)), p.Const(1)}[len(keys):]...)
|
||||
p.appendAmbiguousSelector(rangeSelector(keys[0], keys[1], keys[2]))
|
||||
case '?':
|
||||
if len(keys) != 1 {
|
||||
return fmt.Errorf("filter needs exactly one key")
|
||||
}
|
||||
p.appendAmbiguousSelector(filterSelector(keys[0]))
|
||||
default:
|
||||
if len(keys) == 1 {
|
||||
p.appendPlainSelector(directSelector(keys[0]))
|
||||
} else {
|
||||
p.appendAmbiguousSelector(multiSelector(keys))
|
||||
}
|
||||
}
|
||||
return p.parsePath(c)
|
||||
case '(':
|
||||
return p.parseScript(c)
|
||||
default:
|
||||
p.Camouflage("jsonpath", '.', '[', '(')
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
func (p *parser) parseSelect(c context.Context) error {
|
||||
scan := p.Scan()
|
||||
switch scan {
|
||||
case scanner.Ident:
|
||||
p.appendPlainSelector(directSelector(p.Const(p.TokenText())))
|
||||
return p.parsePath(c)
|
||||
case '.':
|
||||
p.appendAmbiguousSelector(mapperSelector())
|
||||
return p.parseMapper(c)
|
||||
case '*':
|
||||
p.appendAmbiguousSelector(starSelector())
|
||||
return p.parsePath(c)
|
||||
default:
|
||||
return p.Expected("JSON select", scanner.Ident, '.', '*')
|
||||
}
|
||||
}
|
||||
|
||||
func (p *parser) parseBracket(c context.Context) (keys []gval.Evaluable, seperator rune, err error) {
|
||||
for {
|
||||
scan := p.Scan()
|
||||
skipScan := false
|
||||
switch scan {
|
||||
case '?':
|
||||
skipScan = true
|
||||
case ':':
|
||||
i := float64(0)
|
||||
if len(keys) == 1 {
|
||||
i = math.MaxInt32
|
||||
}
|
||||
keys = append(keys, p.Const(i))
|
||||
skipScan = true
|
||||
case '*':
|
||||
if p.Scan() != ']' {
|
||||
return nil, 0, p.Expected("JSON bracket star", ']')
|
||||
}
|
||||
return []gval.Evaluable{}, 0, nil
|
||||
case ']':
|
||||
if seperator == ':' {
|
||||
skipScan = true
|
||||
break
|
||||
}
|
||||
fallthrough
|
||||
default:
|
||||
p.Camouflage("jsonpath brackets")
|
||||
key, err := p.ParseExpression(c)
|
||||
if err != nil {
|
||||
return nil, 0, err
|
||||
}
|
||||
keys = append(keys, key)
|
||||
}
|
||||
if !skipScan {
|
||||
scan = p.Scan()
|
||||
}
|
||||
if seperator == 0 {
|
||||
seperator = scan
|
||||
}
|
||||
switch scan {
|
||||
case ':', ',':
|
||||
case ']':
|
||||
return
|
||||
case '?':
|
||||
if len(keys) != 0 {
|
||||
return nil, 0, p.Expected("JSON filter", ']')
|
||||
}
|
||||
default:
|
||||
return nil, 0, p.Expected("JSON bracket separator", ':', ',')
|
||||
}
|
||||
if seperator != scan {
|
||||
return nil, 0, fmt.Errorf("mixed %v and %v in JSON bracket", seperator, scan)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (p *parser) parseMapper(c context.Context) error {
|
||||
scan := p.Scan()
|
||||
switch scan {
|
||||
case scanner.Ident:
|
||||
p.appendPlainSelector(directSelector(p.Const(p.TokenText())))
|
||||
case '[':
|
||||
keys, seperator, err := p.parseBracket(c)
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
switch seperator {
|
||||
case ':':
|
||||
return fmt.Errorf("mapper can not be combined with range query")
|
||||
case '?':
|
||||
if len(keys) != 1 {
|
||||
return fmt.Errorf("filter needs exactly one key")
|
||||
}
|
||||
p.appendAmbiguousSelector(filterSelector(keys[0]))
|
||||
default:
|
||||
p.appendAmbiguousSelector(multiSelector(keys))
|
||||
}
|
||||
case '*':
|
||||
p.appendAmbiguousSelector(starSelector())
|
||||
case '(':
|
||||
return p.parseScript(c)
|
||||
default:
|
||||
return p.Expected("JSON mapper", '[', scanner.Ident, '*')
|
||||
}
|
||||
return p.parsePath(c)
|
||||
}
|
||||
|
||||
func (p *parser) parseScript(c context.Context) error {
|
||||
script, err := p.ParseExpression(c)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if p.Scan() != ')' {
|
||||
return p.Expected("jsnopath script", ')')
|
||||
}
|
||||
p.appendPlainSelector(newScript(script))
|
||||
return p.parsePath(c)
|
||||
}
|
||||
|
||||
func (p *parser) appendPlainSelector(next plainSelector) {
|
||||
p.path = p.path.withPlainSelector(next)
|
||||
}
|
||||
|
||||
func (p *parser) appendAmbiguousSelector(next ambiguousSelector) {
|
||||
p.path = p.path.withAmbiguousSelector(next)
|
||||
}
|
||||
103
server/vendor/github.com/PaesslerAG/jsonpath/path.go
generated
vendored
Normal file
103
server/vendor/github.com/PaesslerAG/jsonpath/path.go
generated
vendored
Normal file
@@ -0,0 +1,103 @@
|
||||
package jsonpath
|
||||
|
||||
import "context"
|
||||
|
||||
type path interface {
|
||||
evaluate(c context.Context, parameter interface{}) (interface{}, error)
|
||||
visitMatchs(c context.Context, r interface{}, visit pathMatcher)
|
||||
withPlainSelector(plainSelector) path
|
||||
withAmbiguousSelector(ambiguousSelector) path
|
||||
}
|
||||
|
||||
type plainPath []plainSelector
|
||||
|
||||
type ambiguousMatcher func(key, v interface{})
|
||||
|
||||
func (p plainPath) evaluate(ctx context.Context, root interface{}) (interface{}, error) {
|
||||
return p.evaluatePath(ctx, root, root)
|
||||
}
|
||||
|
||||
func (p plainPath) evaluatePath(ctx context.Context, root, value interface{}) (interface{}, error) {
|
||||
var err error
|
||||
for _, sel := range p {
|
||||
value, err = sel(ctx, root, value)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
return value, nil
|
||||
}
|
||||
|
||||
func (p plainPath) matcher(ctx context.Context, r interface{}, match ambiguousMatcher) ambiguousMatcher {
|
||||
if len(p) == 0 {
|
||||
return match
|
||||
}
|
||||
return func(k, v interface{}) {
|
||||
res, err := p.evaluatePath(ctx, r, v)
|
||||
if err == nil {
|
||||
match(k, res)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (p plainPath) visitMatchs(ctx context.Context, r interface{}, visit pathMatcher) {
|
||||
res, err := p.evaluatePath(ctx, r, r)
|
||||
if err == nil {
|
||||
visit(nil, res)
|
||||
}
|
||||
}
|
||||
|
||||
func (p plainPath) withPlainSelector(selector plainSelector) path {
|
||||
return append(p, selector)
|
||||
}
|
||||
func (p plainPath) withAmbiguousSelector(selector ambiguousSelector) path {
|
||||
return &ambiguousPath{
|
||||
parent: p,
|
||||
branch: selector,
|
||||
}
|
||||
}
|
||||
|
||||
type ambiguousPath struct {
|
||||
parent path
|
||||
branch ambiguousSelector
|
||||
ending plainPath
|
||||
}
|
||||
|
||||
func (p *ambiguousPath) evaluate(ctx context.Context, parameter interface{}) (interface{}, error) {
|
||||
matchs := []interface{}{}
|
||||
p.visitMatchs(ctx, parameter, func(keys []interface{}, match interface{}) {
|
||||
matchs = append(matchs, match)
|
||||
})
|
||||
return matchs, nil
|
||||
}
|
||||
|
||||
func (p *ambiguousPath) visitMatchs(ctx context.Context, r interface{}, visit pathMatcher) {
|
||||
p.parent.visitMatchs(ctx, r, func(keys []interface{}, v interface{}) {
|
||||
p.branch(ctx, r, v, p.ending.matcher(ctx, r, visit.matcher(keys)))
|
||||
})
|
||||
}
|
||||
|
||||
func (p *ambiguousPath) branchMatcher(ctx context.Context, r interface{}, m ambiguousMatcher) ambiguousMatcher {
|
||||
return func(k, v interface{}) {
|
||||
p.branch(ctx, r, v, m)
|
||||
}
|
||||
}
|
||||
|
||||
func (p *ambiguousPath) withPlainSelector(selector plainSelector) path {
|
||||
p.ending = append(p.ending, selector)
|
||||
return p
|
||||
}
|
||||
func (p *ambiguousPath) withAmbiguousSelector(selector ambiguousSelector) path {
|
||||
return &ambiguousPath{
|
||||
parent: p,
|
||||
branch: selector,
|
||||
}
|
||||
}
|
||||
|
||||
type pathMatcher func(keys []interface{}, match interface{})
|
||||
|
||||
func (m pathMatcher) matcher(keys []interface{}) ambiguousMatcher {
|
||||
return func(key, match interface{}) {
|
||||
m(append(keys, key), match)
|
||||
}
|
||||
}
|
||||
181
server/vendor/github.com/PaesslerAG/jsonpath/placeholder.go
generated
vendored
Normal file
181
server/vendor/github.com/PaesslerAG/jsonpath/placeholder.go
generated
vendored
Normal file
@@ -0,0 +1,181 @@
|
||||
package jsonpath
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"fmt"
|
||||
"strconv"
|
||||
"text/scanner"
|
||||
|
||||
"github.com/PaesslerAG/gval"
|
||||
)
|
||||
|
||||
type keyValueVisitor func(key string, value interface{})
|
||||
|
||||
type jsonObject interface {
|
||||
visitElements(c context.Context, v interface{}, visit keyValueVisitor) error
|
||||
}
|
||||
|
||||
type jsonObjectSlice []jsonObject
|
||||
|
||||
type keyValuePair struct {
|
||||
key gval.Evaluable
|
||||
value gval.Evaluable
|
||||
}
|
||||
|
||||
type keyValueMatcher struct {
|
||||
key gval.Evaluable
|
||||
matcher func(c context.Context, r interface{}, visit pathMatcher)
|
||||
}
|
||||
|
||||
func parseJSONObject(ctx context.Context, p *gval.Parser) (gval.Evaluable, error) {
|
||||
evals := jsonObjectSlice{}
|
||||
for {
|
||||
switch p.Scan() {
|
||||
default:
|
||||
hasWildcard := false
|
||||
|
||||
p.Camouflage("object", ',', '}')
|
||||
key, err := p.ParseExpression(context.WithValue(ctx, hasPlaceholdersContextKey{}, &hasWildcard))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if p.Scan() != ':' {
|
||||
if err != nil {
|
||||
return nil, p.Expected("object", ':')
|
||||
}
|
||||
}
|
||||
e, err := parseJSONObjectElement(ctx, p, hasWildcard, key)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
evals.addElements(e)
|
||||
case ',':
|
||||
case '}':
|
||||
return evals.evaluable, nil
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func parseJSONObjectElement(ctx context.Context, gParser *gval.Parser, hasWildcard bool, key gval.Evaluable) (jsonObject, error) {
|
||||
if hasWildcard {
|
||||
p := newParser(gParser)
|
||||
switch gParser.Scan() {
|
||||
case '$':
|
||||
case '@':
|
||||
p.appendPlainSelector(currentElementSelector())
|
||||
default:
|
||||
return nil, p.Expected("JSONPath key and value")
|
||||
}
|
||||
|
||||
if err := p.parsePath(ctx); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return keyValueMatcher{key, p.path.visitMatchs}, nil
|
||||
}
|
||||
value, err := gParser.ParseExpression(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return keyValuePair{key, value}, nil
|
||||
}
|
||||
|
||||
func (kv keyValuePair) visitElements(c context.Context, v interface{}, visit keyValueVisitor) error {
|
||||
value, err := kv.value(c, v)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
key, err := kv.key.EvalString(c, v)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
visit(key, value)
|
||||
return nil
|
||||
}
|
||||
|
||||
func (kv keyValueMatcher) visitElements(c context.Context, v interface{}, visit keyValueVisitor) (err error) {
|
||||
kv.matcher(c, v, func(keys []interface{}, match interface{}) {
|
||||
key, er := kv.key.EvalString(context.WithValue(c, placeholdersContextKey{}, keys), v)
|
||||
if er != nil {
|
||||
err = er
|
||||
}
|
||||
visit(key, match)
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
func (j *jsonObjectSlice) addElements(e jsonObject) {
|
||||
*j = append(*j, e)
|
||||
}
|
||||
|
||||
func (j jsonObjectSlice) evaluable(c context.Context, v interface{}) (interface{}, error) {
|
||||
vs := map[string]interface{}{}
|
||||
|
||||
err := j.visitElements(c, v, func(key string, value interface{}) { vs[key] = value })
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return vs, nil
|
||||
}
|
||||
|
||||
func (j jsonObjectSlice) visitElements(ctx context.Context, v interface{}, visit keyValueVisitor) (err error) {
|
||||
for _, e := range j {
|
||||
if err := e.visitElements(ctx, v, visit); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func parsePlaceholder(c context.Context, p *gval.Parser) (gval.Evaluable, error) {
|
||||
hasWildcard := c.Value(hasPlaceholdersContextKey{})
|
||||
if hasWildcard == nil {
|
||||
return nil, fmt.Errorf("JSONPath placeholder must only be used in an JSON object key")
|
||||
}
|
||||
*(hasWildcard.(*bool)) = true
|
||||
switch p.Scan() {
|
||||
case scanner.Int:
|
||||
id, err := strconv.Atoi(p.TokenText())
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return placeholder(id).evaluable, nil
|
||||
default:
|
||||
p.Camouflage("JSONPath placeholder")
|
||||
return allPlaceholders.evaluable, nil
|
||||
}
|
||||
}
|
||||
|
||||
type hasPlaceholdersContextKey struct{}
|
||||
|
||||
type placeholdersContextKey struct{}
|
||||
|
||||
type placeholder int
|
||||
|
||||
const allPlaceholders = placeholder(-1)
|
||||
|
||||
func (key placeholder) evaluable(c context.Context, v interface{}) (interface{}, error) {
|
||||
wildcards, ok := c.Value(placeholdersContextKey{}).([]interface{})
|
||||
if !ok || len(wildcards) <= int(key) {
|
||||
return nil, fmt.Errorf("JSONPath placeholder #%d is not available", key)
|
||||
}
|
||||
if key == allPlaceholders {
|
||||
sb := bytes.Buffer{}
|
||||
sb.WriteString("$")
|
||||
quoteWildcardValues(&sb, wildcards)
|
||||
return sb.String(), nil
|
||||
}
|
||||
return wildcards[int(key)], nil
|
||||
}
|
||||
|
||||
func quoteWildcardValues(sb *bytes.Buffer, wildcards []interface{}) {
|
||||
for _, w := range wildcards {
|
||||
if wildcards, ok := w.([]interface{}); ok {
|
||||
quoteWildcardValues(sb, wildcards)
|
||||
continue
|
||||
}
|
||||
sb.WriteString(fmt.Sprintf("[%v]",
|
||||
strconv.Quote(fmt.Sprint(w)),
|
||||
))
|
||||
}
|
||||
}
|
||||
203
server/vendor/github.com/PaesslerAG/jsonpath/selector.go
generated
vendored
Normal file
203
server/vendor/github.com/PaesslerAG/jsonpath/selector.go
generated
vendored
Normal file
@@ -0,0 +1,203 @@
|
||||
package jsonpath
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"strconv"
|
||||
|
||||
"github.com/PaesslerAG/gval"
|
||||
)
|
||||
|
||||
//plainSelector evaluate exactly one result
|
||||
type plainSelector func(c context.Context, r, v interface{}) (interface{}, error)
|
||||
|
||||
//ambiguousSelector evaluate wildcard
|
||||
type ambiguousSelector func(c context.Context, r, v interface{}, match ambiguousMatcher)
|
||||
|
||||
//@
|
||||
func currentElementSelector() plainSelector {
|
||||
return func(c context.Context, r, v interface{}) (interface{}, error) {
|
||||
return c.Value(currentElement{}), nil
|
||||
}
|
||||
}
|
||||
|
||||
type currentElement struct{}
|
||||
|
||||
func currentContext(c context.Context, v interface{}) context.Context {
|
||||
return context.WithValue(c, currentElement{}, v)
|
||||
}
|
||||
|
||||
//.x, [x]
|
||||
func directSelector(key gval.Evaluable) plainSelector {
|
||||
return func(c context.Context, r, v interface{}) (interface{}, error) {
|
||||
|
||||
e, _, err := selectValue(c, key, r, v)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return e, nil
|
||||
}
|
||||
}
|
||||
|
||||
// * / [*]
|
||||
func starSelector() ambiguousSelector {
|
||||
return func(c context.Context, r, v interface{}, match ambiguousMatcher) {
|
||||
visitAll(v, func(key string, val interface{}) { match(key, val) })
|
||||
}
|
||||
}
|
||||
|
||||
// [x, ...]
|
||||
func multiSelector(keys []gval.Evaluable) ambiguousSelector {
|
||||
if len(keys) == 0 {
|
||||
return starSelector()
|
||||
}
|
||||
return func(c context.Context, r, v interface{}, match ambiguousMatcher) {
|
||||
for _, k := range keys {
|
||||
e, wildcard, err := selectValue(c, k, r, v)
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
match(wildcard, e)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func selectValue(c context.Context, key gval.Evaluable, r, v interface{}) (value interface{}, jkey string, err error) {
|
||||
c = currentContext(c, v)
|
||||
switch o := v.(type) {
|
||||
case []interface{}:
|
||||
i, err := key.EvalInt(c, r)
|
||||
if err != nil {
|
||||
return nil, "", fmt.Errorf("could not select value, invalid key: %s", err)
|
||||
}
|
||||
if i < 0 || i >= len(o) {
|
||||
return nil, "", fmt.Errorf("index %d out of bounds", i)
|
||||
}
|
||||
return o[i], strconv.Itoa(i), nil
|
||||
case map[string]interface{}:
|
||||
k, err := key.EvalString(c, r)
|
||||
if err != nil {
|
||||
return nil, "", fmt.Errorf("could not select value, invalid key: %s", err)
|
||||
}
|
||||
|
||||
if r, ok := o[k]; ok {
|
||||
return r, k, nil
|
||||
}
|
||||
return nil, "", fmt.Errorf("unknown key %s", k)
|
||||
|
||||
default:
|
||||
return nil, "", fmt.Errorf("unsupported value type %T for select, expected map[string]interface{} or []interface{}", o)
|
||||
}
|
||||
}
|
||||
|
||||
//..
|
||||
func mapperSelector() ambiguousSelector {
|
||||
return mapper
|
||||
}
|
||||
|
||||
func mapper(c context.Context, r, v interface{}, match ambiguousMatcher) {
|
||||
match([]interface{}{}, v)
|
||||
visitAll(v, func(wildcard string, v interface{}) {
|
||||
mapper(c, r, v, func(key interface{}, v interface{}) {
|
||||
match(append([]interface{}{wildcard}, key.([]interface{})...), v)
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
func visitAll(v interface{}, visit func(key string, v interface{})) {
|
||||
switch v := v.(type) {
|
||||
case []interface{}:
|
||||
for i, e := range v {
|
||||
k := strconv.Itoa(i)
|
||||
visit(k, e)
|
||||
}
|
||||
case map[string]interface{}:
|
||||
for k, e := range v {
|
||||
visit(k, e)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//[? ]
|
||||
func filterSelector(filter gval.Evaluable) ambiguousSelector {
|
||||
return func(c context.Context, r, v interface{}, match ambiguousMatcher) {
|
||||
visitAll(v, func(wildcard string, v interface{}) {
|
||||
condition, err := filter.EvalBool(currentContext(c, v), r)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
if condition {
|
||||
match(wildcard, v)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
//[::]
|
||||
func rangeSelector(min, max, step gval.Evaluable) ambiguousSelector {
|
||||
return func(c context.Context, r, v interface{}, match ambiguousMatcher) {
|
||||
cs, ok := v.([]interface{})
|
||||
if !ok {
|
||||
return
|
||||
}
|
||||
|
||||
c = currentContext(c, v)
|
||||
|
||||
min, err := min.EvalInt(c, r)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
max, err := max.EvalInt(c, r)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
step, err := step.EvalInt(c, r)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
if min > max {
|
||||
return
|
||||
}
|
||||
|
||||
n := len(cs)
|
||||
min = negmax(min, n)
|
||||
max = negmax(max, n)
|
||||
|
||||
if step == 0 {
|
||||
step = 1
|
||||
}
|
||||
|
||||
if step > 0 {
|
||||
for i := min; i < max; i += step {
|
||||
match(strconv.Itoa(i), cs[i])
|
||||
}
|
||||
} else {
|
||||
for i := max - 1; i >= min; i += step {
|
||||
match(strconv.Itoa(i), cs[i])
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
func negmax(n, max int) int {
|
||||
if n < 0 {
|
||||
n = max + n
|
||||
if n < 0 {
|
||||
n = 0
|
||||
}
|
||||
} else if n > max {
|
||||
return max
|
||||
}
|
||||
return n
|
||||
}
|
||||
|
||||
// ()
|
||||
func newScript(script gval.Evaluable) plainSelector {
|
||||
return func(c context.Context, r, v interface{}) (interface{}, error) {
|
||||
return script(currentContext(c, v), r)
|
||||
}
|
||||
}
|
||||
15
server/vendor/github.com/PaesslerAG/jsonpath/test.sh
generated
vendored
Normal file
15
server/vendor/github.com/PaesslerAG/jsonpath/test.sh
generated
vendored
Normal file
@@ -0,0 +1,15 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Script that runs tests, code coverage, and benchmarks all at once.
|
||||
|
||||
JSONPath_PATH=$HOME/gopath/src/github.com/PaesslerAG/jsonpath
|
||||
|
||||
# run the actual tests.
|
||||
cd "${JSONPath_PATH}"
|
||||
go test -bench=. -benchmem -coverprofile coverage.out
|
||||
status=$?
|
||||
|
||||
if [ "${status}" != 0 ];
|
||||
then
|
||||
exit $status
|
||||
fi
|
||||
Reference in New Issue
Block a user