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:
153
server/compose/envoy/jsonl_encode.go
Normal file
153
server/compose/envoy/jsonl_encode.go
Normal file
@@ -0,0 +1,153 @@
|
||||
package envoy
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/cortezaproject/corteza/server/pkg/envoyx"
|
||||
"github.com/cortezaproject/corteza/server/pkg/envoyx/datasource"
|
||||
"github.com/cortezaproject/corteza/server/pkg/j7s"
|
||||
)
|
||||
|
||||
type (
|
||||
JsonlEncoder struct{}
|
||||
)
|
||||
|
||||
func (e JsonlEncoder) Encode(ctx context.Context, p envoyx.EncodeParams, rt string, nodes envoyx.NodeSet, tt envoyx.Traverser) (err error) {
|
||||
w, err := e.getWriter(p)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
jw := json.NewEncoder(w)
|
||||
|
||||
switch rt {
|
||||
case ComposeRecordDatasourceAuxType:
|
||||
_, err = e.encodeRecordDatasources(ctx, jw, p, nodes, tt)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
func (e JsonlEncoder) encodeRecordDatasources(ctx context.Context, writer *json.Encoder, p envoyx.EncodeParams, nodes envoyx.NodeSet, tt envoyx.Traverser) (out any, err error) {
|
||||
for _, n := range nodes {
|
||||
_, err = e.encodeRecordDatasource(ctx, writer, p, n, tt)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
func (e JsonlEncoder) encodeRecordDatasource(ctx context.Context, writer *json.Encoder, p envoyx.EncodeParams, node *envoyx.Node, tt envoyx.Traverser) (_ any, err error) {
|
||||
rds := node.Datasource.(*RecordDatasource)
|
||||
|
||||
var loc *time.Location
|
||||
loc, err = resolveTimezone(p)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
header := make([]string, 0, 4)
|
||||
|
||||
hasID := false
|
||||
for _, m := range p.FieldMapping {
|
||||
header = append(header, m.Field)
|
||||
|
||||
hasID = hasID || strings.ToLower(m.Field) == "id"
|
||||
}
|
||||
|
||||
if !hasID {
|
||||
header = append([]string{"ID"}, header...)
|
||||
}
|
||||
|
||||
var more bool
|
||||
for {
|
||||
out := make(datasource.RawRecord)
|
||||
_, more, err = rds.Next(ctx, out)
|
||||
if err != nil || !more {
|
||||
break
|
||||
}
|
||||
|
||||
if len(header) == 0 {
|
||||
for k := range out {
|
||||
header = append(header, k)
|
||||
}
|
||||
}
|
||||
|
||||
row, _ := j7s.MakeMap()
|
||||
for _, h := range header {
|
||||
proc := func(h string) {
|
||||
v := out[h]
|
||||
if len(v.Values) == 0 {
|
||||
return
|
||||
}
|
||||
|
||||
srcKey := strings.TrimSuffix(h, " value")
|
||||
isDt := rds.datetimeFields[h] || rds.datetimeFields[srcKey]
|
||||
|
||||
if !rds.multivalues[h] {
|
||||
vv := v.Values[0]
|
||||
if isDt {
|
||||
vv = formatInTimezone(vv, loc)
|
||||
}
|
||||
|
||||
row, err = j7s.AddMap(row, h, vv)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
} else {
|
||||
auxv, _ := j7s.MakeSeq()
|
||||
for _, vv := range v.Values {
|
||||
if isDt {
|
||||
vv = formatInTimezone(vv, loc)
|
||||
}
|
||||
|
||||
auxv, err = j7s.AddSeq(auxv, vv)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
row, err = j7s.AddMap(row, h, auxv)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
proc(h)
|
||||
if _, ok := out[fmt.Sprintf("%s value", h)]; ok {
|
||||
proc(fmt.Sprintf("%s value", h))
|
||||
}
|
||||
}
|
||||
|
||||
err = writer.Encode(row)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
func (e JsonlEncoder) getWriter(p envoyx.EncodeParams) (out io.Writer, err error) {
|
||||
aux, ok := p.Params[paramsKeyWriter]
|
||||
if ok {
|
||||
out, ok = aux.(io.Writer)
|
||||
if ok {
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
err = fmt.Errorf("jsonl encoder expects a writer conforming to io.Writer interface")
|
||||
return
|
||||
}
|
||||
Reference in New Issue
Block a user