move expr and js to different namespace

This commit is contained in:
Joel Wetzell
2025-11-25 07:42:32 -06:00
parent 9bf46dd3c8
commit efe3e546d5
2 changed files with 18 additions and 19 deletions

View File

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

View File

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