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

This commit is contained in:
upstream-mirror
2026-09-18 01:22:23 +05:00
commit 7e385fc126
8391 changed files with 1766236 additions and 0 deletions

158
server/pkg/payload/util.go Normal file
View File

@@ -0,0 +1,158 @@
package payload
import (
"encoding/json"
"fmt"
"strconv"
"strings"
"time"
"github.com/cortezaproject/corteza/server/pkg/filter"
"github.com/cortezaproject/corteza/server/pkg/handle"
"github.com/jmoiron/sqlx/types"
"github.com/spf13/cast"
)
func Uint64toa(i uint64) string {
return strconv.FormatUint(i, 10)
}
func Uint64stoa(uu []uint64) []string {
ss := make([]string, len(uu))
for i, u := range uu {
ss[i] = Uint64toa(u)
}
return ss
}
// ParseUint64 parses an string to uint64
func ParseUint64(s string) uint64 {
if s == "" {
return 0
}
i, _ := strconv.ParseUint(s, 10, 64)
return i
}
// ParseUint64s parses a slice of strings into a slice of uint64s
func ParseUint64s(ss []string) []uint64 {
uu := make([]uint64, len(ss))
for i, s := range ss {
uu[i] = ParseUint64(s)
}
return uu
}
func ParseJSONTextWithErr(s string) (types.JSONText, error) {
result := &types.JSONText{}
err := fmt.Errorf("error parsing JSONText: %w", result.Scan(s))
return *result, err
}
func ParseISODateWithErr(s string) (time.Time, error) {
return time.Parse(time.RFC3339, s)
}
func ParseISODatePtrWithErr(s string) (*time.Time, error) {
t, err := ParseISODateWithErr(s)
if err != nil {
return nil, err
}
return &t, nil
}
// ParseInt parses a string to int
func ParseInt(s string) int {
if s == "" {
return 0
}
i, _ := strconv.Atoi(s)
return i
}
// ParseUInt parses a string to uint64
func ParseUint(s string) uint {
if s == "" {
return 0
}
i, _ := strconv.ParseUint(s, 10, 32)
return uint(i)
}
// ParseUint64s parses a slice of strings into a slice of uint64s
func ParseUints(ss []string) []uint {
uu := make([]uint, len(ss))
for i, s := range ss {
uu[i] = ParseUint(s)
}
return uu
}
// ParseInt64 parses a string to int64
func ParseInt64(s string) int64 {
if s == "" {
return 0
}
i, _ := strconv.ParseInt(s, 10, 64)
return i
}
// parseUInt64 parses a string to uint64
func ParseBool(s string) bool {
return cast.ToBool(s)
}
func ParseFilterState(s string) filter.State {
return filter.State(cast.ToUint(s))
}
// similar to labels.ParseStrings but for map[string]any
func ParseMeta(ss []string) (m map[string]any, err error) {
if len(ss) == 0 {
return nil, nil
}
m = make(map[string]any)
for _, s := range ss {
if strings.HasPrefix(s, "{") && strings.HasSuffix(s, "}") {
// assume json
if err = json.Unmarshal([]byte(s), &m); err != nil {
return nil, err
}
for k := range m {
if !isValidMetaKey(k) {
return nil, fmt.Errorf("invalid metadata key format")
}
}
continue
}
kv := strings.SplitN(s, "=", 2)
if !handle.IsValid(kv[0]) {
return nil, fmt.Errorf("invalid metadata key format")
}
if len(kv) == 2 {
m[kv[0]] = kv[1]
} else {
m[kv[0]] = nil
}
}
return m, nil
}
// isValidMetaKey rejects keys that can not be safely used as part of a JSON path
//
// Store layer interpolates metadata keys into JSON path expressions where an
// unescaped quote would terminate the surrounding string literal
func isValidMetaKey(k string) bool {
return !strings.Contains(k, "'")
}