Use proper types for corredor exec automation fn
Arguments&results are no longer Any but Vars
This commit is contained in:
+6
-6
@@ -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
|
||||
|
||||
@@ -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 }
|
||||
|
||||
@@ -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'
|
||||
|
||||
Reference in New Issue
Block a user