Use proper types for corredor exec automation fn

Arguments&results are no longer Any but Vars
This commit is contained in:
Denis Arh
2021-05-06 13:51:21 +02:00
parent 31a4f55a8b
commit 9e4edd555e
3 changed files with 18 additions and 15 deletions
+6 -6
View File
@@ -36,11 +36,11 @@ type (
Script string
hasArgs bool
Args interface{}
Args *expr.Vars
}
corredorExecResults struct {
Results interface{}
Results *expr.Vars
}
)
@@ -67,7 +67,7 @@ func (h corredorHandler) Exec() *atypes.Function {
},
{
Name: "args",
Types: []string{"Any"},
Types: []string{"Vars"},
},
},
@@ -75,7 +75,7 @@ func (h corredorHandler) Exec() *atypes.Function {
{
Name: "results",
Types: []string{"Any"},
Types: []string{"Vars"},
},
},
@@ -99,12 +99,12 @@ func (h corredorHandler) Exec() *atypes.Function {
out = &expr.Vars{}
{
// converting results.Results (interface{}) to Any
// converting results.Results (*expr.Vars) to Vars
var (
tval expr.TypedValue
)
if tval, err = h.reg.Type("Any").Cast(results.Results); err != nil {
if tval, err = h.reg.Type("Vars").Cast(results.Results); err != nil {
return
} else if err = expr.Assign(out, "results", tval); err != nil {
return
+9 -7
View File
@@ -5,8 +5,8 @@ import (
"encoding/json"
"github.com/cortezaproject/corteza-server/pkg/corredor"
"github.com/cortezaproject/corteza-server/pkg/eventbus"
"github.com/cortezaproject/corteza-server/pkg/expr"
"github.com/cortezaproject/corteza-server/system/service/event"
"github.com/spf13/cast"
)
type (
@@ -41,18 +41,20 @@ func (h corredorHandler) exec(ctx context.Context, args *corredorExecArgs) (r *c
return
}
return &corredorExecResults{Results: sArgs.payload}, nil
r = &corredorExecResults{}
if r.Results, err = expr.NewVars(sArgs.payload); err != nil {
return nil, err
}
return
}
func makeScriptArgs(in interface{}) *scriptArgs {
return &scriptArgs{
payload: cast.ToStringMap(in),
}
func makeScriptArgs(in *expr.Vars) *scriptArgs {
return &scriptArgs{payload: in.Dict()}
}
// mimic onManual event on system:
func (scriptArgs) ResourceType() string { return event.SystemOnManual().ResourceType() }
func (scriptArgs) EventType() string { return event.SystemOnManual().EventType() }
func (scriptArgs) Match(eventbus.ConstraintMatcher) bool { return false }
+3 -2
View File
@@ -8,7 +8,8 @@ functions:
description: Executes script in Corredor Automation server
params:
script: { types: [ { wf: String } ], required: true }
args: { types: [ { wf: Any } ] }
args: { types: [ { wf: Vars, go: '*expr.Vars' } ] }
results:
results:
wf: Any
wf: Vars
go: '*expr.Vars'