⬆️ update dependencies, implement user store

This commit is contained in:
2020-10-09 18:35:44 +02:00
parent d2c0ebb043
commit 129df9d7f2
90 changed files with 6640 additions and 12741 deletions

View File

@@ -12,6 +12,7 @@ This document is designed to explain the structure of a GJSON Path through examp
- [Queries](#queries)
- [Dot vs Pipe](#dot-vs-pipe)
- [Modifiers](#modifiers)
- [Multipaths](#multipaths)
The definitive implemenation is [github.com/tidwall/gjson](https://github.com/tidwall/gjson).
Use the [GJSON Playground](https://gjson.dev) to experiment with the syntax online.
@@ -235,7 +236,7 @@ gjson.AddModifier("case", func(json, arg string) string {
"children.@case:lower.@reverse" ["jack","alex","sara"]
```
#### Multipaths
### Multipaths
Starting with v1.3.0, GJSON added the ability to join multiple paths together
to form new documents. Wrapping comma-separated paths between `{...}` or

View File

@@ -464,9 +464,9 @@ func ParseBytes(json []byte) Result {
}
func squash(json string) string {
// expects that the lead character is a '[' or '{'
// expects that the lead character is a '[' or '{' or '('
// squash the value, ignoring all nested arrays and objects.
// the first '[' or '{' has already been read
// the first '[' or '{' or '(', has already been read
depth := 1
for i := 1; i < len(json); i++ {
if json[i] >= '"' && json[i] <= '}' {
@@ -495,9 +495,9 @@ func squash(json string) string {
break
}
}
case '{', '[':
case '{', '[', '(':
depth++
case '}', ']':
case '}', ']', ')':
depth--
if depth == 0 {
return json[:i+1]
@@ -1056,9 +1056,9 @@ func parseObjectPath(path string) (r objectPathResult) {
}
func parseSquash(json string, i int) (int, string) {
// expects that the lead character is a '[' or '{'
// expects that the lead character is a '[' or '{' or '('
// squash the value, ignoring all nested arrays and objects.
// the first '[' or '{' has already been read
// the first '[' or '{' or '(' has already been read
s := i
i++
depth := 1
@@ -1089,9 +1089,9 @@ func parseSquash(json string, i int) (int, string) {
break
}
}
case '{', '[':
case '{', '[', '(':
depth++
case '}', ']':
case '}', ']', ')':
depth--
if depth == 0 {
i++
@@ -1556,19 +1556,30 @@ func parseArray(c *parseContext, i int, path string) (int, bool) {
var jsons = make([]byte, 0, 64)
jsons = append(jsons, '[')
for j, k := 0, 0; j < len(alog); j++ {
_, res, ok := parseAny(c.json, alog[j], true)
if ok {
res := res.Get(rp.alogkey)
if res.Exists() {
if k > 0 {
jsons = append(jsons, ',')
idx := alog[j]
for idx < len(c.json) {
switch c.json[idx] {
case ' ', '\t', '\r', '\n':
idx++
continue
}
break
}
if idx < len(c.json) && c.json[idx] != ']' {
_, res, ok := parseAny(c.json, idx, true)
if ok {
res := res.Get(rp.alogkey)
if res.Exists() {
if k > 0 {
jsons = append(jsons, ',')
}
raw := res.Raw
if len(raw) == 0 {
raw = res.String()
}
jsons = append(jsons, []byte(raw)...)
k++
}
raw := res.Raw
if len(raw) == 0 {
raw = res.String()
}
jsons = append(jsons, []byte(raw)...)
k++
}
}
}
@@ -1615,10 +1626,21 @@ func splitPossiblePipe(path string) (left, right string, ok bool) {
return
}
if len(path) > 0 && path[0] == '{' {
squashed := squash(path[1:])
if len(squashed) < len(path)-1 {
squashed = path[:len(squashed)+1]
remain := path[len(squashed):]
if remain[0] == '|' {
return squashed, remain[1:], true
}
}
return
}
// split the left and right side of the path with the pipe character as
// the delimiter. This is a little tricky because we'll need to basically
// parse the entire path.
for i := 0; i < len(path); i++ {
if path[i] == '\\' {
i++
@@ -1699,6 +1721,7 @@ type subSelector struct {
// first character in path is either '[' or '{', and has already been checked
// prior to calling this function.
func parseSubSelectors(path string) (sels []subSelector, out string, ok bool) {
modifer := 0
depth := 1
colon := 0
start := 1
@@ -1719,8 +1742,12 @@ func parseSubSelectors(path string) (sels []subSelector, out string, ok bool) {
switch path[i] {
case '\\':
i++
case '@':
if modifer == 0 && i > 0 && (path[i-1] == '.' || path[i-1] == '|') {
modifer = i
}
case ':':
if depth == 1 {
if modifer == 0 && colon == 0 && depth == 1 {
colon = i
}
case ',':