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:
269
server/pkg/codegen/assets/afunc.gen.go.tpl
Normal file
269
server/pkg/codegen/assets/afunc.gen.go.tpl
Normal file
@@ -0,0 +1,269 @@
|
||||
package {{ .Package }}
|
||||
|
||||
// This file is auto-generated.
|
||||
//
|
||||
// Changes to this file may cause incorrect behavior and will be lost if
|
||||
// the code is regenerated.
|
||||
//
|
||||
// Definitions file that controls how this file is generated:
|
||||
// {{ .Source }}
|
||||
|
||||
import (
|
||||
atypes "github.com/cortezaproject/corteza/server/automation/types"
|
||||
"context"
|
||||
"github.com/cortezaproject/corteza/server/pkg/expr"
|
||||
"github.com/cortezaproject/corteza/server/pkg/wfexec"
|
||||
{{- range .Imports }}
|
||||
{{ normalizeImport . }}
|
||||
{{- end }}
|
||||
)
|
||||
|
||||
var _ wfexec.ExecResponse
|
||||
|
||||
type (
|
||||
{{ $.Name }}HandlerRegistry interface {
|
||||
AddFunctions(ff ...*atypes.Function)
|
||||
Type(ref string) expr.Type
|
||||
}
|
||||
)
|
||||
|
||||
func (h {{ $.Name }}Handler) register() {
|
||||
h.reg.AddFunctions(
|
||||
{{- range .Functions }}
|
||||
h.{{ export .Name }}(),
|
||||
{{- end }}
|
||||
)
|
||||
}
|
||||
|
||||
{{ range .Functions }}
|
||||
{{ $REF := unexport $.Prefix $.Name .Name }}
|
||||
{{ $ARGS := unexport $.Name .Name "Args" }}
|
||||
{{ $RESULTS := unexport $.Name .Name "Results" }}
|
||||
|
||||
|
||||
type (
|
||||
{{ $ARGS }} struct {
|
||||
{{ range .Params }}
|
||||
{{ $name := .Name }}
|
||||
{{ $isArray := .IsArray }}
|
||||
has{{ export .Name }} bool
|
||||
{{- if gt (len .Types) 1 }}
|
||||
{{ export .Name }} interface{}
|
||||
{{- range .Types }}
|
||||
{{ $name }}{{ export .Suffix }} {{ if $isArray }}[]{{ end }}{{ .GoType }}
|
||||
{{- end }}
|
||||
{{- else -}}
|
||||
{{ range .Types }}
|
||||
{{ export $name }}{{ export .Suffix }} {{ if $isArray }}[]{{ end }}{{ .GoType }}
|
||||
{{- end }}
|
||||
{{- end -}}
|
||||
{{- end }}
|
||||
}
|
||||
|
||||
{{ if .Results }}
|
||||
{{ unexport $.Name .Name }}Results struct {
|
||||
{{ range .Results }}
|
||||
{{ export .Name }} {{ if .IsArray }}[]{{ end }}{{ .GoType }}
|
||||
{{- end }}
|
||||
}
|
||||
{{- end }}
|
||||
)
|
||||
|
||||
|
||||
|
||||
|
||||
{{ range .Params }}
|
||||
{{- if gt (len .Types) 1 }}
|
||||
{{ $name := .Name }}
|
||||
{{ $isArray := .IsArray }}
|
||||
func (a {{ $ARGS }}) {{ export "get" $name }}() (bool, {{ range .Types }}{{ if $isArray }}[]{{ end }}{{ .GoType }},{{ end }}) {
|
||||
return a.has{{ export $name }}{{ range .Types }}, a.{{ $name }}{{ export .Suffix }}{{ end }}
|
||||
}
|
||||
{{- end }}
|
||||
{{- end }}
|
||||
|
||||
|
||||
// {{ export .Name }} function {{ .Meta.Short }}
|
||||
//
|
||||
// expects implementation of {{ .Name }} function:
|
||||
// func (h {{ $.Name }}Handler) {{ .Name }}(ctx context.Context, args *{{ $ARGS }}) ({{ if .Results }}results *{{ $RESULTS }}, {{ end }}err error) {
|
||||
// return
|
||||
// }
|
||||
func (h {{ $.Name }}Handler) {{ export .Name }}() *atypes.Function {
|
||||
return &atypes.Function{
|
||||
Ref: {{ printf "%q" ( $REF ) }},
|
||||
Kind: {{ printf "%q" .Kind }},
|
||||
Labels: {{ printf "%#v" .Labels }},
|
||||
{{- if .Meta }}
|
||||
Meta: &atypes.FunctionMeta{
|
||||
{{- if .Meta.Short }}
|
||||
Short: {{ printf "%q" .Meta.Short }},
|
||||
{{- end }}
|
||||
{{- if .Meta.Description }}
|
||||
Description: {{ printf "%q" .Meta.Description }},
|
||||
{{- end }}
|
||||
{{- if .Meta.Visual }}
|
||||
Visual: {{ printf "%#v" .Meta.Visual }},
|
||||
{{- end }}
|
||||
},
|
||||
{{- end }}
|
||||
|
||||
Parameters: []*atypes.Param{
|
||||
{{- range .Params }}
|
||||
{
|
||||
Name: {{ printf "%q" .Name }},
|
||||
Types: []string{ {{ range .Types }}{{ printf "%q" .WorkflowType }},{{ end }} },
|
||||
{{- if .Required }}Required: true,{{ end }}
|
||||
{{- if .IsArray }}IsArray: true,{{ end }}
|
||||
{{- if .Meta }}
|
||||
Meta: &atypes.ParamMeta{
|
||||
{{- if .Meta.Label }}
|
||||
Label: {{ printf "%#v" .Meta.Label }},
|
||||
{{- end }}
|
||||
{{- if .Meta.Description }}
|
||||
Description: {{ printf "%#v" .Meta.Description }},
|
||||
{{- end }}
|
||||
{{- if .Meta.Visual }}
|
||||
Visual: {{ printf "%#v" .Meta.Visual }},
|
||||
{{- end }}
|
||||
},
|
||||
{{ end }}
|
||||
},
|
||||
{{- end }}
|
||||
},
|
||||
|
||||
|
||||
{{ if .Results }}
|
||||
Results: []*atypes.Param{
|
||||
{{ range .Results }}
|
||||
{
|
||||
Name: {{ printf "%q" .Name }},
|
||||
Types: []string{ {{ printf "%q" .WorkflowType }} },
|
||||
{{ if .IsArray }}IsArray: true,{{ end -}}
|
||||
{{ if .Meta -}}
|
||||
Meta: &atypes.ParamMeta{
|
||||
{{- if .Meta.Label }}
|
||||
Label: {{ printf "%#v" .Meta.Label }},
|
||||
{{- end }}
|
||||
{{- if .Meta.Description }}
|
||||
Description: {{ printf "%#v" .Meta.Description }},
|
||||
{{- end }}
|
||||
{{- if .Meta.Visual }}
|
||||
Visual: {{ printf "%#v" .Meta.Visual }},
|
||||
{{- end }}
|
||||
},
|
||||
{{ end }}
|
||||
},
|
||||
{{ end }}
|
||||
},
|
||||
{{ end }}
|
||||
|
||||
{{ if eq .Kind "iterator" }}
|
||||
Iterator: func(ctx context.Context, in *expr.Vars) (out wfexec.IteratorHandler, err error) {
|
||||
var (
|
||||
args = &{{ $ARGS }}{
|
||||
{{- range .Params }}
|
||||
has{{ export .Name }}: in.Has({{ printf "%q" .Name }}),
|
||||
{{- end }}
|
||||
}
|
||||
)
|
||||
|
||||
{{ template "params" .Params }}
|
||||
|
||||
return h.{{ .Name }}(ctx, args)
|
||||
},
|
||||
{{ else }}
|
||||
Handler: func(ctx context.Context, in *expr.Vars) (out *expr.Vars, err error) {
|
||||
var (
|
||||
args = &{{ $ARGS }}{
|
||||
{{- range .Params }}
|
||||
has{{ export .Name }}: in.Has({{ printf "%q" .Name }}),
|
||||
{{- end }}
|
||||
}
|
||||
)
|
||||
|
||||
{{ template "params" .Params }}
|
||||
|
||||
{{ if .Results }}
|
||||
var results *{{ $RESULTS }}
|
||||
if results, err = h.{{ .Name }}(ctx, args); err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
out = &expr.Vars{}
|
||||
|
||||
{{- range .Results }}
|
||||
{{ if .IsArray }}
|
||||
|
||||
{
|
||||
// converting results.{{ export .Name }} ({{ .GoType }}) to Array (of {{ .WorkflowType }})
|
||||
var (
|
||||
tval expr.TypedValue
|
||||
tarr = make([]expr.TypedValue, len(results.{{ export .Name }}))
|
||||
)
|
||||
|
||||
for i := range results.{{ export .Name }} {
|
||||
if tarr[i], err = h.reg.Type({{ printf "%q" .WorkflowType }}).Cast(results.{{ export .Name }}[i]); err != nil {
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
if tval, err = expr.NewArray(tarr); err != nil {
|
||||
return
|
||||
} else if err = expr.Assign(out, {{ printf "%q" .Name }}, tval); err != nil {
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
{{ else }}
|
||||
|
||||
{
|
||||
// converting results.{{ export .Name }} ({{ .GoType }}) to {{ .WorkflowType }}
|
||||
var (
|
||||
tval expr.TypedValue
|
||||
)
|
||||
|
||||
if tval, err = h.reg.Type({{ printf "%q" .WorkflowType }}).Cast(results.{{ export .Name }}); err != nil {
|
||||
return
|
||||
} else if err = expr.Assign(out, {{ printf "%q" .Name }}, tval); err != nil {
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
{{ end }}
|
||||
{{ end }}
|
||||
|
||||
return
|
||||
{{- else }}
|
||||
return out, h.{{ .Name }}(ctx, args)
|
||||
{{- end }}
|
||||
},
|
||||
{{ end }}
|
||||
}
|
||||
}
|
||||
{{ end }}
|
||||
|
||||
{{ define "params" }}
|
||||
if err = in.Decode(args); err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
{{ range . }}
|
||||
{{ $name := .Name }}
|
||||
{{ $isArray := .IsArray }}
|
||||
{{ if gt (len .Types) 1 }}
|
||||
// Converting {{ export .Name }} argument
|
||||
if args.has{{ export .Name }} {
|
||||
aux := expr.Must(expr.Select(in, {{ printf "%q" .Name }}))
|
||||
switch aux.Type() {
|
||||
{{- range .Types }}
|
||||
case h.reg.Type({{ printf "%q" .WorkflowType }}).Type():
|
||||
args.{{ $name }}{{ export .Suffix }} = aux.Get().({{ if $isArray }}[]{{ end }}{{ .GoType }})
|
||||
{{- end -}}
|
||||
}
|
||||
}
|
||||
|
||||
{{- end }}
|
||||
{{ end }}
|
||||
{{ end }}
|
||||
Reference in New Issue
Block a user