Documentation
¶
Index ¶
- Constants
- Variables
- func ApplyDefaults[T any](value T, defaults T) T
- type CELEvaluatorOption
- type CompileOption
- type CompiledRule
- type EvaluationError
- type Evaluator
- type EvaluatorLogEvent
- type EvaluatorLogger
- type EvaluatorLoggerFunc
- type ExprEvaluatorOption
- type FieldDescriptor
- type Function
- type FunctionEntry
- type FunctionRegistry
- type JSEvaluatorOption
- type Layer
- type LayerOption
- type Option
- func WithActivityHooks(hooks activity.Hooks) Option
- func WithCustomFunction(name string, fn Function) Option
- func WithEvaluator(e Evaluator) Option
- func WithEvaluatorLogger(logger EvaluatorLogger) Option
- func WithFunctionRegistry(registry *FunctionRegistry) Option
- func WithProgramCache(cache ProgramCache) Option
- func WithSchemaGenerator(generator SchemaGenerator) Option
- func WithScope(scope Scope) Option
- func WithScopeSchema(include bool) Option
- type Options
- func (o *Options[T]) ActivityHooks() activity.Hooks
- func (o *Options[T]) Clone() *Options[T]
- func (o *Options[T]) Evaluate(expr string) (Response[any], error)
- func (o *Options[T]) EvaluateWith(ctx RuleContext, expr string) (Response[any], error)
- func (o *Options[T]) FlattenWithProvenance() ([]Provenance, error)
- func (o *Options[T]) Get(path string) (any, error)
- func (o *Options[T]) LayerWith(layers ...T) *Options[T]
- func (o *Options[T]) MustSchema() SchemaDocument
- func (o *Options[T]) ResolveWithTrace(path string) (any, Trace, error)
- func (o *Options[T]) Schema() (SchemaDocument, error)
- func (o *Options[T]) Set(path string, value any) error
- func (o *Options[T]) Validate() error
- func (o *Options[T]) WithSchemaGenerator(generator SchemaGenerator) *Options[T]
- func (o *Options[T]) WithValue(value T) *Options[T]
- type ProgramCache
- type Provenance
- type Response
- type RuleContext
- type SchemaDocument
- type SchemaFormat
- type SchemaGenerator
- type SchemaScope
- type Scope
- type ScopeOption
- type Stack
- type Trace
Constants ¶
const ( // Recommended priorities for common layering patterns. Higher numbers win. ScopePrioritySystem = 100 ScopePriorityTenant = 200 ScopePriorityOrg = 300 ScopePriorityTeam = 400 ScopePriorityUser = 500 )
Variables ¶
var ( // ErrScopeNameRequired indicates a missing scope name. ErrScopeNameRequired = errors.New("scope: name must be provided") // ErrDuplicateScopeName indicates Stack construction received multiple // layers with the same scope name. ErrDuplicateScopeName = errors.New("scope: names must be unique") // ErrPriorityOrder indicates Stack construction detected duplicate or // unsorted priorities. ErrPriorityOrder = errors.New("scope: priorities must be strictly ordered") )
var ErrNoEvaluator = errors.New("opts: evaluator not configured")
Functions ¶
func ApplyDefaults ¶
func ApplyDefaults[T any](value T, defaults T) T
ApplyDefaults returns value if it is already populated, otherwise it falls back to defaults.
Types ¶
type CELEvaluatorOption ¶
type CELEvaluatorOption func(*celEvaluator)
CELEvaluatorOption configures the CEL evaluator.
func CELWithFunctionRegistry ¶
func CELWithFunctionRegistry(registry *FunctionRegistry) CELEvaluatorOption
CELWithFunctionRegistry wires a FunctionRegistry into the CEL evaluator.
func CELWithProgramCache ¶
func CELWithProgramCache(cache ProgramCache) CELEvaluatorOption
CELWithProgramCache wires a ProgramCache into the CEL evaluator.
type CompileOption ¶
type CompileOption interface {
// contains filtered or unexported methods
}
CompileOption configures evaluator compile behaviour.
type CompiledRule ¶
type CompiledRule interface {
Evaluate(ctx RuleContext) (any, error)
}
CompiledRule represents a reusable expression program.
type EvaluationError ¶
EvaluationError captures evaluator metadata alongside the originating error.
func (*EvaluationError) Error ¶
func (e *EvaluationError) Error() string
func (*EvaluationError) Unwrap ¶
func (e *EvaluationError) Unwrap() error
type Evaluator ¶
type Evaluator interface {
Evaluate(ctx RuleContext, expr string) (any, error)
Compile(expr string, opts ...CompileOption) (CompiledRule, error)
}
Evaluator executes expressions against a rule context.
func NewCELEvaluator ¶
func NewCELEvaluator(opts ...CELEvaluatorOption) Evaluator
NewCELEvaluator constructs an Evaluator backed by cel-go.
func NewExprEvaluator ¶
func NewExprEvaluator(opts ...ExprEvaluatorOption) Evaluator
NewExprEvaluator constructs an Evaluator backed by expr-lang/expr.
func NewJSEvaluator ¶
func NewJSEvaluator(opts ...JSEvaluatorOption) Evaluator
NewJSEvaluator is unavailable without the js_eval build tag.
type EvaluatorLogEvent ¶
type EvaluatorLogEvent struct {
Engine string
Expr string
Scope string
Duration time.Duration
Err error
}
EvaluatorLogEvent describes an evaluation attempt for logging.
type EvaluatorLogger ¶
type EvaluatorLogger interface {
LogEvaluation(EvaluatorLogEvent)
}
EvaluatorLogger records evaluator events.
type EvaluatorLoggerFunc ¶
type EvaluatorLoggerFunc func(EvaluatorLogEvent)
EvaluatorLoggerFunc adapts a function to EvaluatorLogger.
func (EvaluatorLoggerFunc) LogEvaluation ¶
func (f EvaluatorLoggerFunc) LogEvaluation(event EvaluatorLogEvent)
LogEvaluation implements EvaluatorLogger.
type ExprEvaluatorOption ¶
type ExprEvaluatorOption func(*exprEvaluator)
ExprEvaluatorOption configures an expr evaluator instance.
func ExprWithFunctionRegistry ¶
func ExprWithFunctionRegistry(registry *FunctionRegistry) ExprEvaluatorOption
ExprWithFunctionRegistry wires a FunctionRegistry into the expr evaluator.
func ExprWithProgramCache ¶
func ExprWithProgramCache(cache ProgramCache) ExprEvaluatorOption
ExprWithProgramCache wires a ProgramCache into the expr evaluator.
type FieldDescriptor ¶
FieldDescriptor describes a path and the inferred type.
type FunctionEntry ¶
FunctionEntry represents a single registration to apply to a registry.
type FunctionRegistry ¶
type FunctionRegistry struct {
// contains filtered or unexported fields
}
FunctionRegistry stores custom functions keyed by name.
func MustFunctionRegistry ¶
func MustFunctionRegistry(entries ...FunctionEntry) *FunctionRegistry
MustFunctionRegistry constructs a registry from entries and panics on failure.
func NewFunctionRegistry ¶
func NewFunctionRegistry() *FunctionRegistry
NewFunctionRegistry constructs an empty registry.
func NewFunctionRegistryFrom ¶
func NewFunctionRegistryFrom(entries ...FunctionEntry) (*FunctionRegistry, error)
NewFunctionRegistryFrom constructs a registry seeded with entries.
func (*FunctionRegistry) Call ¶
func (r *FunctionRegistry) Call(name string, args ...any) (any, error)
Call executes the function registered for name.
func (*FunctionRegistry) Clone ¶
func (r *FunctionRegistry) Clone() *FunctionRegistry
Clone returns a shallow copy of the registry.
func (*FunctionRegistry) Names ¶
func (r *FunctionRegistry) Names() []string
Names returns registered function names sorted alphabetically.
type JSEvaluatorOption ¶
type JSEvaluatorOption func(*jsEvaluatorConfig)
JSEvaluatorOption configures the JS evaluator.
func JSWithFunctionRegistry ¶
func JSWithFunctionRegistry(registry *FunctionRegistry) JSEvaluatorOption
JSWithFunctionRegistry applies a FunctionRegistry to the JS evaluator.
func JSWithProgramCache ¶
func JSWithProgramCache(cache ProgramCache) JSEvaluatorOption
JSWithProgramCache applies a ProgramCache to the JS evaluator.
type LayerOption ¶
LayerOption configures optional metadata for a layer.
func WithSnapshotID ¶
func WithSnapshotID[T any](id string) LayerOption[T]
WithSnapshotID sets the snapshot identifier used for auditing.
type Option ¶
type Option func(*optionsConfig)
func WithActivityHooks ¶ added in v0.5.0
WithActivityHooks attaches activity hooks to the Options configuration. Hooks are cloned and nil entries dropped to preserve immutability.
func WithCustomFunction ¶
WithCustomFunction registers fn under name for the wrapper.
func WithEvaluator ¶
WithEvaluator configures an evaluator on the Options wrapper.
func WithEvaluatorLogger ¶
func WithEvaluatorLogger(logger EvaluatorLogger) Option
WithEvaluatorLogger attaches an evaluator logger to the Options wrapper.
func WithFunctionRegistry ¶
func WithFunctionRegistry(registry *FunctionRegistry) Option
WithFunctionRegistry configures a wrapper to use registry.
func WithProgramCache ¶
func WithProgramCache(cache ProgramCache) Option
WithProgramCache registers a program cache on the Options wrapper.
func WithSchemaGenerator ¶
func WithSchemaGenerator(generator SchemaGenerator) Option
WithSchemaGenerator configures a custom schema generator implementation.
func WithScopeSchema ¶
WithScopeSchema toggles inclusion of scope metadata within generated schemas.
type Options ¶
type Options[T any] struct { Value T // contains filtered or unexported fields }
Options holds a typed options value and evaluator configuration.
func Load ¶
Load constructs an Options wrapper and runs validation when supported by the underlying type.
func SystemTenantOrgTeamUser ¶
SystemTenantOrgTeamUser assembles a canonical five-layer stack (system → tenant → org → team → user) and returns the merged options wrapper.
func (*Options[T]) ActivityHooks ¶ added in v0.5.0
ActivityHooks returns a cloned slice of activity hooks configured on the options wrapper. The returned slice can be safely mutated by the caller.
func (*Options[T]) Clone ¶
Clone returns a shallow copy of the Options wrapper preserving configuration.
func (*Options[T]) Evaluate ¶
Evaluate executes expr using the configured evaluator and wraps the result.
func (*Options[T]) EvaluateWith ¶
EvaluateWith executes expr using ctx, falling back to the wrapped value when ctx.Snapshot is nil.
func (*Options[T]) FlattenWithProvenance ¶
func (o *Options[T]) FlattenWithProvenance() ([]Provenance, error)
FlattenWithProvenance enumerates every reachable path in the wrapped value and reports which scope supplied the effective value.
func (*Options[T]) LayerWith ¶
LayerWith merges layers ordered strongest to weakest with the current snapshot as the fallback, returning a new wrapper with the merged value.
func (*Options[T]) MustSchema ¶
func (o *Options[T]) MustSchema() SchemaDocument
MustSchema generates a schema document and panics on error.
func (*Options[T]) ResolveWithTrace ¶
ResolveWithTrace returns the effective value for path along with provenance from each scope layer that was inspected.
func (*Options[T]) Schema ¶
func (o *Options[T]) Schema() (SchemaDocument, error)
Schema returns a schema document for the wrapped value.
func (*Options[T]) Validate ¶
Validate invokes the Validate method on the wrapped value when present.
func (*Options[T]) WithSchemaGenerator ¶
func (o *Options[T]) WithSchemaGenerator(generator SchemaGenerator) *Options[T]
WithSchemaGenerator returns a cloned wrapper configured with generator. Passing a nil generator removes any custom generator and falls back to the default.
type ProgramCache ¶
ProgramCache stores compiled expression programs keyed by expression strings.
type Provenance ¶
type Provenance struct {
Scope Scope `json:"scope"`
SnapshotID string `json:"snapshot_id,omitempty"`
Path string `json:"path"`
Value any `json:"value,omitempty"`
Found bool `json:"found"`
}
Provenance details how a specific scope contributed to a traced path.
type Response ¶
type Response[T any] struct { Value T }
Response stores a typed result produced by an evaluator.
type RuleContext ¶
type RuleContext struct {
Snapshot any
Now *time.Time
Args map[string]any
Metadata map[string]any
Scope Scope
ScopeName string
}
RuleContext carries inputs needed when evaluating an expression.
type SchemaDocument ¶
type SchemaDocument struct {
Format SchemaFormat
Document any
Scopes []SchemaScope
}
SchemaDocument encapsulates a generated schema output alongside its format identifier. Implementations must ensure Document is JSON-serialisable.
type SchemaFormat ¶
type SchemaFormat string
SchemaFormat identifies the representation a schema document encodes.
const ( // SchemaFormatDescriptors represents the flattened field descriptors. SchemaFormatDescriptors SchemaFormat = "descriptors" // SchemaFormatOpenAPI represents OpenAPI-compatible JSON Schema documents. SchemaFormatOpenAPI SchemaFormat = "openapi" )
type SchemaGenerator ¶
type SchemaGenerator interface {
Generate(value any) (SchemaDocument, error)
}
SchemaGenerator transforms an options value into a schema document. All implementations MUST be safe for concurrent use and handle nil inputs by returning an empty schema document.
func DefaultSchemaGenerator ¶
func DefaultSchemaGenerator() SchemaGenerator
DefaultSchemaGenerator returns the built-in descriptor-based schema generator.
type SchemaScope ¶
type SchemaScope struct {
Name string `json:"name"`
Label string `json:"label,omitempty"`
Priority int `json:"priority"`
Metadata map[string]any `json:"metadata,omitempty"`
SnapshotID string `json:"snapshot_id,omitempty"`
}
SchemaScope describes a single scope entry included in a schema document.
type Scope ¶
Scope models a named precedence bucket (system, tenant, user, etc.). Higher priority values represent stronger layers.
type ScopeOption ¶
type ScopeOption func(*scopeConfig)
ScopeOption configures metadata on Scope creation.
func WithScopeLabel ¶
func WithScopeLabel(label string) ScopeOption
WithScopeLabel sets a human-friendly label on the scope.
func WithScopeMetadata ¶
func WithScopeMetadata(metadata map[string]any) ScopeOption
WithScopeMetadata attaches arbitrary metadata to the scope. The map is copied so the resulting Scope remains immutable even if the caller mutates their reference.
type Stack ¶
type Stack[T any] struct { // contains filtered or unexported fields }
Stack represents an immutable, scope-aware layering configuration ordered from strongest to weakest precedence.
func NewStack ¶
NewStack validates and sorts the supplied layers so that the strongest scope (highest priority) is first. Layers and their snapshots are deep copied to guarantee read-only safety after construction.
type Trace ¶
type Trace struct {
Path string `json:"path"`
Layers []Provenance `json:"layers"`
}
Trace captures provenance information for a given path lookup across the scoped layers that produced the effective value.
func TraceFromJSON ¶
TraceFromJSON deserialises a JSON payload that was previously generated via ToJSON.
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
examples
|
|
|
activity
command
|
|
|
options
command
|
|
|
scope
command
|
|
|
state
command
|
|
|
internal
|
|
|
pkg
|
|
|
state
Package state defines persistence-facing contracts for loading and saving per-scope option snapshots, plus a small resolver that orchestrates scope loading and delegates layering/provenance to the core go-options primitives.
|
Package state defines persistence-facing contracts for loading and saving per-scope option snapshots, plus a small resolver that orchestrates scope loading and delegates layering/provenance to the core go-options primitives. |
|
schema
|
|