Documentation
¶
Overview ¶
Package operators provides built-in stateless operators for declarative workflows. Each builder turns a typed config into an ordinary Mailer function — a func(types.Record) bool for filters, or a func(types.Record) types.Record for field transforms — so a YAML operator behaves exactly like an equivalent hand-written SDK function.
The operators work on the JSON record model (workflow/record): records are decoded to a JSONRecord, fields are addressed by dotted path, and numbers are json.Number (exact, no float rounding).
Index ¶
- func BuildFilter(cfg FilterConfig) func(types.Record) bool
- func BuildRename(cfg RenameConfig) func(types.Record) types.Record
- func BuildSelect(cfg SelectConfig) func(types.Record) types.Record
- func BuildSet(cfg SetConfig) func(types.Record) types.Record
- func Compare(op CompareOp, fieldVal any, present bool, target any) (bool, error)
- type CompareOp
- type FieldRename
- type FieldSet
- type FilterConfig
- type RenameConfig
- type SelectConfig
- type SetConfig
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func BuildFilter ¶
func BuildFilter(cfg FilterConfig) func(types.Record) bool
BuildFilter returns an ordinary Mailer predicate. A record whose JSON cannot be decoded is dropped (returns false).
func BuildRename ¶
func BuildRename(cfg RenameConfig) func(types.Record) types.Record
BuildRename returns an ordinary Mailer map function that renames fields in order. A rename whose source field is absent is skipped.
func BuildSelect ¶
func BuildSelect(cfg SelectConfig) func(types.Record) types.Record
BuildSelect returns an ordinary Mailer map function that projects each record to the configured fields. A field absent from the input is simply omitted from the output.
func BuildSet ¶
BuildSet returns an ordinary Mailer map function that assigns each configured field.
func Compare ¶
Compare evaluates op against a field value. present says whether the field existed at all (a missing field is not equal to / greater than anything, but exists/not_exists still work). target is the configured comparison value.
Coercion makes YAML and JSON configs behave identically: record numbers are json.Number and config numbers arrive as int (YAML) or float64 (JSON); both are normalized before comparing. Numbers only compare with numbers, strings with strings, bools with bools — a number never equals a quoted string, so behavior is predictable.
Types ¶
type CompareOp ¶
type CompareOp string
CompareOp is a filter comparison operator.
const ( OpEquals CompareOp = "equals" OpNotEquals CompareOp = "not_equals" OpGreaterThan CompareOp = "greater_than" OpGreaterThanOrEqual CompareOp = "greater_than_or_equal" OpLessThan CompareOp = "less_than" OpLessThanOrEqual CompareOp = "less_than_or_equal" OpContains CompareOp = "contains" OpExists CompareOp = "exists" OpNotExists CompareOp = "not_exists" )
func (CompareOp) NeedsValue ¶
NeedsValue reports whether op compares against a configured value (everything except exists/not_exists).
type FieldRename ¶
FieldRename moves a field from one dotted path to another.
type FieldSet ¶
type FieldSet struct {
Field string `yaml:"field" json:"field"`
Value any `yaml:"value" json:"value"`
}
FieldSet assigns a constant value to a dotted field path.
type FilterConfig ¶
type FilterConfig struct {
Field string `yaml:"field" json:"field"`
Operator string `yaml:"operator" json:"operator"`
Value any `yaml:"value,omitempty" json:"value,omitempty"`
}
FilterConfig configures a built-in filter: keep records where the value at Field satisfies Operator against Value.
- id: completed-orders type: filter config: field: status operator: equals value: completed
func (FilterConfig) Validate ¶
func (cfg FilterConfig) Validate() error
Validate checks the config independently of any record.
type RenameConfig ¶
type RenameConfig struct {
Renames []FieldRename `yaml:"renames" json:"renames"`
}
RenameConfig configures a built-in rename: apply each rename in order.
- id: normalize type: rename_fields config: renames:
- { from: cust_id, to: customer_id }
- { from: amt, to: payment.amount }
func (RenameConfig) Validate ¶
func (cfg RenameConfig) Validate() error
Validate checks the config independently of any record.
type SelectConfig ¶
type SelectConfig struct {
Fields []string `yaml:"fields" json:"fields"`
}
SelectConfig configures a built-in select_fields (projection): keep only the listed fields, dropping everything else. Fields are dotted paths, so nested fields can be projected too.
- id: output-fields type: select_fields config: fields:
- customer_id
- amount
func (SelectConfig) Validate ¶
func (cfg SelectConfig) Validate() error
Validate checks the config independently of any record.
type SetConfig ¶
type SetConfig struct {
Sets []FieldSet `yaml:"sets" json:"sets"`
}
SetConfig configures a built-in set_fields: assign each field in order (creating nested objects as needed).
- id: tag type: set_fields config: sets:
- { field: source, value: web }
- { field: flags.processed, value: true }