move expr and js to different namespace

This commit is contained in:
Joel Wetzell
2025-11-25 10:31:29 -06:00
parent efe3e546d5
commit b3815c4a22
2 changed files with 18 additions and 18 deletions

View File

@@ -9,14 +9,14 @@ import (
)
// NOTE(jwetzell): see language definition https://expr-lang.org/docs/language-definition
type ProgramExpr struct {
type ScriptExpr struct {
config ProcessorConfig
Program *vm.Program
}
func (pe *ProgramExpr) Process(ctx context.Context, payload any) (any, error) {
func (se *ScriptExpr) Process(ctx context.Context, payload any) (any, error) {
output, err := expr.Run(pe.Program, payload)
output, err := expr.Run(se.Program, payload)
if err != nil {
return nil, err
}
@@ -24,26 +24,26 @@ func (pe *ProgramExpr) Process(ctx context.Context, payload any) (any, error) {
return output, nil
}
func (pe *ProgramExpr) Type() string {
return pe.config.Type
func (se *ScriptExpr) Type() string {
return se.config.Type
}
func init() {
RegisterProcessor(ProcessorRegistration{
Type: "program.expr",
Type: "script.expr",
New: func(config ProcessorConfig) (Processor, error) {
params := config.Params
expression, ok := params["expression"]
if !ok {
return nil, fmt.Errorf("program.expr requires an expression parameter")
return nil, fmt.Errorf("script.expr requires an expression parameter")
}
expressionString, ok := expression.(string)
if !ok {
return nil, fmt.Errorf("program.expr expression must be a string")
return nil, fmt.Errorf("script.expr expression must be a string")
}
program, err := expr.Compile(expressionString)
@@ -51,7 +51,7 @@ func init() {
return nil, err
}
return &ProgramExpr{config: config, Program: program}, nil
return &ScriptExpr{config: config, Program: program}, nil
},
})
}

View File

@@ -7,12 +7,12 @@ import (
"modernc.org/quickjs"
)
type ProgramJS struct {
type ScriptJS struct {
config ProcessorConfig
Program string
}
func (pj *ProgramJS) Process(ctx context.Context, payload any) (any, error) {
func (sj *ScriptJS) Process(ctx context.Context, payload any) (any, error) {
vm, err := quickjs.NewVM()
@@ -28,7 +28,7 @@ func (pj *ProgramJS) Process(ctx context.Context, payload any) (any, error) {
vm.SetProperty(vm.GlobalObject(), payloadAtom, payload)
output, err := vm.Eval(pj.Program, quickjs.EvalGlobal)
output, err := vm.Eval(sj.Program, quickjs.EvalGlobal)
if err != nil {
return nil, err
}
@@ -36,29 +36,29 @@ func (pj *ProgramJS) Process(ctx context.Context, payload any) (any, error) {
return output, nil
}
func (pj *ProgramJS) Type() string {
return pj.config.Type
func (sj *ScriptJS) Type() string {
return sj.config.Type
}
func init() {
RegisterProcessor(ProcessorRegistration{
Type: "program.js",
Type: "script.js",
New: func(config ProcessorConfig) (Processor, error) {
params := config.Params
program, ok := params["program"]
if !ok {
return nil, fmt.Errorf("program.js requires a program parameter")
return nil, fmt.Errorf("script.js requires a program parameter")
}
programString, ok := program.(string)
if !ok {
return nil, fmt.Errorf("program.js program must be a string")
return nil, fmt.Errorf("script.js program must be a string")
}
return &ProgramJS{config: config, Program: programString}, nil
return &ScriptJS{config: config, Program: programString}, nil
},
})
}