condeval

package
v0.87.2 Latest Latest
Warning

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

Go to latest
Published: Sep 23, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package condeval evaluates dal.Condition trees against record values.

It is the shared, adapter-independent evaluator behind row-level access conditions: a condition is validated once when a policy is compiled (Validate), its parameters are substituted from runtime values (Substitute), and the resolved condition is matched against a record's data (Match). Record data is normalised through a JSON round trip (ToMap), so struct fields are addressed by their JSON names, numbers compare as float64, and times compare as RFC 3339 strings — the same shape the in-memory adapter stores and queries.

The supported subset mirrors the core query model: comparisons of a field reference with a constant, an array (for In) or a parameter, combined with And/Or groups. Anything else is rejected by Validate and reported as an error by Match, never silently treated as a match.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ApplyUpdates added in v0.76.0

func ApplyUpdates(data map[string]any, updates []update.Update) error

ApplyUpdates applies field updates to JSON-shaped record data, producing the post-image of an Update: a field name addresses a top-level key, a field path a nested key, and update.DeleteField removes the leaf. Missing intermediate maps are created; an intermediate value that is not a map is an error, because the write would fail or corrupt the record and the policy must not guess the outcome.

func CloneMap added in v0.76.0

func CloneMap(data map[string]any) map[string]any

CloneMap deep-copies JSON-shaped record data (maps, slices and scalars) so a post-image can be computed without touching the pre-image.

func Lookup

func Lookup(data map[string]any, path string) (any, bool)

Lookup resolves a dotted field path ("address.city") in nested maps.

func Match

func Match(data map[string]any, condition dal.Condition) (bool, error)

Match reports whether data satisfies condition. A nil condition matches. A field the record lacks never satisfies a comparison. A condition outside the supported subset, or one still carrying a parameter, is an error.

func Substitute

func Substitute(condition dal.Condition, resolve func(name string) (any, bool)) (dal.Condition, error)

Substitute returns a copy of condition with every parameter replaced by the value resolve returns for its name: a slice or array becomes a dal.Array, anything else a dal.Constant. An unresolved parameter is an error that names it, so callers can fail closed and explain why.

func ToMap

func ToMap(data any) (map[string]any, error)

ToMap renders record data as the JSON-normalised map Match evaluates: struct fields under their JSON names, numbers as float64, times as RFC 3339 strings. Nil data is an empty map.

Types

type Info

type Info struct {
	Fields []string
	Params []string
}

Info describes the field and parameter names a condition references.

func Validate

func Validate(condition dal.Condition) (Info, error)

Validate checks that condition uses only the supported subset and returns the field and parameter names it references, each sorted and de-duplicated.

Jump to

Keyboard shortcuts

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