resonator

package
v0.2.3 Latest Latest
Warning

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

Go to latest
Published: May 29, 2026 License: MPL-2.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Branch

type Branch struct {
	Path string `json:"path,omitempty"`
}

type BranchValue

type BranchValue struct {
	Path  string    `json:"path,omitempty"`  // .branch.subbranch
	Value ast.Value `json:"value,omitempty"` // ast.Literal{V: 42} today; ast.PathRef / ast.FunctionCall reserved
}

type Condition

type Condition struct {
	Star       bool         `json:"isStar,omitempty"`     // true = matches everything
	Branch     *Branch      `json:"branch,omitempty"`     // .branch.subbranch
	MatchType  MatchType    `json:"matchType,omitempty"`  // ==
	MatchValue interface{}  `json:"matchValue,omitempty"` // 5
	Adds       *BranchValue `json:"adds,omitempty"`       // for select, adding branches
	Prunes     *BranchValue `json:"prunes,omitempty"`     // for select, removing branches
}

type MatchType

type MatchType string
const (
	LT     MatchType = "lt"
	LT_EQ  MatchType = "lteq"
	GT     MatchType = "gt"
	GT_EQ  MatchType = "gteq"
	EQ     MatchType = "eq"
	NOT_EQ MatchType = "ne"
)

type Phrase

type Phrase struct {
	Type     PhraseType
	When     *When                `json:"when,omitempty"`
	Select   *Select              `json:"select,omitempty"`
	SetPre   *Set                 `json:"setPre,omitempty"`  // set before select
	SetPost  *Set                 `json:"setPost,omitempty"` // set after select
	With     map[string]ast.Value `json:"with,omitempty"`
	Priority int64                `json:"priority"`
	Exec     string               `json:"exec,omitempty"`
	Emit     *Set                 `json:"emit,omitempty"`
}

type PhraseType

type PhraseType string
const (
	WHEN     PhraseType = "WHEN"
	SETPRE   PhraseType = "SETPRE"
	SELECT   PhraseType = "SELECT"
	SETPOST  PhraseType = "SETPOST"
	WITH     PhraseType = "WITH"
	PRIORITY PhraseType = "PRIORITY"
	EXEC     PhraseType = "EXEC"
	EMIT     PhraseType = "EMIT"
)

type Resonator

type Resonator struct {
	When     *When                `json:"when,omitempty"`
	Select   *Select              `json:"select,omitempty"`
	SetPre   *Set                 `json:"setPre,omitempty"`  // set before select
	SetPost  *Set                 `json:"setPost,omitempty"` // set after select
	With     map[string]ast.Value `json:"with,omitempty"`
	Priority int64                `json:"priority"`
	Exec     string               `json:"exec,omitempty"`
	// Emit overlays values onto THIS rule's response after EXEC,
	// before the per-scope merge. Overwrite semantics (not the
	// set-if-absent behavior of SET POST). Lets a rule contribute
	// literal fields to the merged scope output without needing a
	// real HTTP/handler call: pair with EXEC for "enrich the
	// response", or write EMIT alone for a "synthetic emitter".
	Emit *Set `json:"emit,omitempty"`
}

Resonator is the parsed form of one txcl rule. Built by the parser, consumed by the processor at match-and-dispatch time.

func New

func New() *Resonator

func (Resonator) WhenMatches

func (res Resonator) WhenMatches(input string) bool

WhenMatches returns true if the WHEN clause matches the input envelope. Semantics preserved across the grammar v2 upgrade:

  • empty input never matches (caller contract)
  • nil/empty When matches everything (star)
  • legacy When{Conditions: [...]} is promoted to an Expr tree on the fly; any Star condition in the list short-circuits to match
  • new When{Expr: ...} is walked directly

type Select

type Select struct {
	Assignments []SelectAssignment `json:"assignments,omitempty"`
}

Select copies envelope values from path → path with optional literal fallback. Assignments run before the rule's EXEC (so the EXEC sees the copied values on its input view) and are also overlaid onto the rule's response so the writes persist even when the rule has no EXEC. Distinct from SET (literal RHS only, op-scoped, requires EXEC to commit) and EMIT (literal RHS only, post-EXEC overlay).

type SelectAssignment

type SelectAssignment struct {
	From       string    `json:"from"`
	To         string    `json:"to"`
	Default    ast.Value `json:"default,omitempty"`
	HasDefault bool      `json:"has_default,omitempty"`
}

SelectAssignment is one `<source> AS <dest> [DEFAULT <literal>]` clause inside a SELECT. From and To are envelope paths (with the leading `.` or `@` sugar accepted by the parser, normalized for gjson/sjson at evaluation time). Default is the literal used when From resolves to a missing path or the empty string.

type Set

type Set struct {
	Overrides []BranchValue `json:"overrides,omitempty"`
}

type When

type When struct {
	// Expr is the canonical tree shape produced by the parser. New rules
	// always populate Expr.
	Expr *WhenExpr `json:"expr,omitempty"`
	// Conditions is the legacy flat-AND shape. Programmatic callers (and
	// any in-flight JSON written before the grammar v2 upgrade) populate
	// this; WhenMatches promotes it to an Expr at evaluation time.
	Conditions []Condition `json:"conditions,omitempty"`
}

type WhenExpr

type WhenExpr struct {
	And     []WhenExpr `json:"and,omitempty"`
	Or      []WhenExpr `json:"or,omitempty"`
	Not     *WhenExpr  `json:"not,omitempty"`
	Leaf    Condition  `json:"leaf,omitempty"`
	HasLeaf bool       `json:"has_leaf,omitempty"`
	Star    bool       `json:"star,omitempty"`
}

WhenExpr is the boolean expression tree for a WHEN clause. Exactly one of {And, Or, Not, HasLeaf, Star} is set on each node.

And/Or are n-ary (slices of values), Not is unary and uses a pointer for self-recursion (Go can't embed a value-type into itself). Leaf is held by value with HasLeaf as the discriminator so the tree contains no leaf-level pointers and there's no aliasing back into any source slice.

Jump to

Keyboard shortcuts

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