operators

package
v0.7.2 Latest Latest
Warning

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

Go to latest
Published: Jul 19, 2026 License: MIT Imports: 6 Imported by: 0

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

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

func BuildSet(cfg SetConfig) func(types.Record) types.Record

BuildSet returns an ordinary Mailer map function that assigns each configured field.

func Compare

func Compare(op CompareOp, fieldVal any, present bool, target any) (bool, error)

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

func (op CompareOp) NeedsValue() bool

NeedsValue reports whether op compares against a configured value (everything except exists/not_exists).

func (CompareOp) Valid

func (op CompareOp) Valid() bool

Valid reports whether op is a supported comparison operator.

type FieldRename

type FieldRename struct {
	From string `yaml:"from" json:"from"`
	To   string `yaml:"to" json:"to"`
}

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 }

func (SetConfig) Validate

func (cfg SetConfig) Validate() error

Validate checks the config independently of any record.

Jump to

Keyboard shortcuts

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