script

package
v0.0.0-...-ce4a990 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 13, 2026 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Overview

Package script implements script environments for engine steps and predicates

Index

Constants

View Source
const (
	MatchTags                 = "tags"
	MatchType                 = "type"
	MatchHandling             = "handling"
	MatchAttributes           = "attributes"
	MatchAttributeRole        = "role"
	MatchAttributeCompensated = "compensated"
)

Variables

View Source
var (
	ErrJPathCompile = errors.New("jpath compile error")
	ErrJPathNoMatch = errors.New("jpath produced no matches")
)
View Source
var (
	ErrLuaLoad      = errors.New("lua load error")
	ErrLuaExecution = errors.New("lua execution error")
)
View Source
var MatchStep = &api.Step{
	Attributes: api.AttributeSpecs{
		matchValue: {Role: api.RoleRequired, Type: api.TypeAny},
	},
}

MatchStep returns the minimal synthetic step used as the compilation context for a required match predicate, exposing only the candidate value

Functions

func QBESelector

func QBESelector(qbe api.SpaceQuery) *api.ScriptConfig

QBESelector returns a JPath match script equivalent to the query by example, ANDing the tags within a term and ORing the terms, so a step matches when it carries every tag of any one of them

Types

type Compiled

type Compiled any

Compiled represents a compiled script for any supported language

type CompiledLua

type CompiledLua struct {
	// contains filtered or unexported fields
}

CompiledLua represents a compiled Lua script

type Environment

type Environment interface {
	// Validate checks if a script is syntactically valid
	Validate(st *api.Step, script string) error

	// Compile compiles a script and returns the compiled form
	Compile(*api.Step, *api.ScriptConfig) (Compiled, error)

	// EvaluateScript executes a compiled script with the given inputs
	EvaluateScript(Compiled, *api.Step, api.Args) (api.Args, error)

	// EvaluatePredicate evaluates a compiled predicate with given inputs
	EvaluatePredicate(Compiled, *api.Step, api.Args) (bool, error)

	// EvaluateMatch evaluates a compiled matcher with a single input
	EvaluateMatch(c Compiled, input any) (bool, error)
}

Environment defines the interface for script environments

type JPathEnv

type JPathEnv struct {
	// contains filtered or unexported fields
}

JPathEnv provides JPath predicate evaluation

func NewJPathEnv

func NewJPathEnv() *JPathEnv

NewJPathEnv creates a JPath predicate evaluation environment

func (JPathEnv) Compile

func (c JPathEnv) Compile(
	st *api.Step, cfg *api.ScriptConfig,
) (Compiled, error)

func (*JPathEnv) EvaluateMatch

func (*JPathEnv) EvaluateMatch(c Compiled, input any) (bool, error)

EvaluateMatch applies the compiled JPath expression to a single input and treats any match as success, including explicit null matches

func (*JPathEnv) EvaluatePredicate

func (*JPathEnv) EvaluatePredicate(
	c Compiled, _ *api.Step, inputs api.Args,
) (bool, error)

EvaluatePredicate applies the compiled JPath expression and treats any match as predicate success, including explicit null matches

func (*JPathEnv) EvaluateScript

func (*JPathEnv) EvaluateScript(
	c Compiled, _ *api.Step, inputs api.Args,
) (api.Args, error)

EvaluateScript evaluates a compiled JPath expression against mapping inputs

func (JPathEnv) Validate

func (c JPathEnv) Validate(st *api.Step, script string) error

type LuaEnv

type LuaEnv struct {
	// contains filtered or unexported fields
}

LuaEnv provides a Lua script execution environment with state pooling

func NewLuaEnv

func NewLuaEnv() *LuaEnv

NewLuaEnv creates a new Lua script execution environment with a state pool for efficient script reuse

func (LuaEnv) Compile

func (c LuaEnv) Compile(
	st *api.Step, cfg *api.ScriptConfig,
) (Compiled, error)

func (*LuaEnv) EvaluateMatch

func (e *LuaEnv) EvaluateMatch(c Compiled, input any) (bool, error)

EvaluateMatch executes a compiled Lua matcher with a single input and returns the boolean result

func (*LuaEnv) EvaluatePredicate

func (e *LuaEnv) EvaluatePredicate(
	c Compiled, _ *api.Step, inputs api.Args,
) (bool, error)

EvaluatePredicate executes a compiled Lua predicate with the provided inputs and returns the boolean result

func (*LuaEnv) EvaluateScript

func (e *LuaEnv) EvaluateScript(
	c Compiled, _ *api.Step, inputs api.Args,
) (api.Args, error)

EvaluateScript runs a compiled Lua script with the provided inputs and returns the output arguments

func (LuaEnv) Validate

func (c LuaEnv) Validate(st *api.Step, script string) error

type Registry

type Registry struct {
	// contains filtered or unexported fields
}

Registry manages script environments for different languages

func NewRegistry

func NewRegistry() *Registry

NewRegistry creates a new registry with JPath and Lua environments

func (*Registry) Compile

func (r *Registry) Compile(
	st *api.Step, cfg *api.ScriptConfig,
) (Compiled, error)

Compile compiles a script config

func (*Registry) Get

func (r *Registry) Get(language string) (Environment, error)

Get returns the script environment for the given language

func (*Registry) Register

func (r *Registry) Register(language string, env Environment)

func (*Registry) ValidateStep

func (r *Registry) ValidateStep(st *api.Step) error

ValidateStep checks that a step's predicate and attribute match scripts compile successfully against the registry

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL