evaluate

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jul 26, 2022 License: Apache-2.0 Imports: 9 Imported by: 3

Documentation

Index

Constants

View Source
const DepthFull = -1

Variables

View Source
var (
	ArrayAnnotation     = Annotation{Name: "leg.relay.sh/array", Description: "array"}
	ExpansionAnnotation = Annotation{Name: "leg.relay.sh/expansion", Description: "expansion"}
	ObjectAnnotation    = Annotation{Name: "leg.relay.sh/object", Description: "object"}
)

Functions

func ContextWithMetadata

func ContextWithMetadata[T ref.References[T]](ctx context.Context, md *Metadata[T]) context.Context

func IsFullDepth

func IsFullDepth(depth int) bool

Types

type Annotation

type Annotation struct {
	Name        string
	Attributes  map[string]any
	Description string
}

func ArrayIndexAnnotation

func ArrayIndexAnnotation(idx int) Annotation

func ObjectKeyAnnotation

func ObjectKeyAnnotation(key string) Annotation

type Evaluator

type Evaluator[T ref.References[T]] interface {
	Evaluate(ctx context.Context, tree any, depth int) (*Result[T], error)
}

func CoalesceEvaluators

func CoalesceEvaluators[T ref.References[T]](evs ...Evaluator[T]) Evaluator[T]

func CoalesceEvaluatorsPreferringContext

func CoalesceEvaluatorsPreferringContext[T ref.References[T]](ctx context.Context, evs ...Evaluator[T]) Evaluator[T]

func DefaultEvaluator

func DefaultEvaluator[T ref.References[T]]() Evaluator[T]

func NewEvaluator

func NewEvaluator[T ref.References[T]](visitor Visitor[T]) Evaluator[T]

type Expandable

type Expandable[T ref.References[T]] interface {
	Expand(ctx context.Context, depth int) (*Result[T], error)
}

func MemoizedExpandable

func MemoizedExpandable[T ref.References[T]](delegate Expandable[T]) Expandable[T]

func StaticExpandable

func StaticExpandable[T ref.References[T]](r *Result[T]) Expandable[T]

type Metadata

type Metadata[T ref.References[T]] struct {
	Annotation Annotation
	References T
	Steps      []*Step[T]
	Evaluator  Evaluator[T]
}

func ContextWithEmptyMetadata

func ContextWithEmptyMetadata[T ref.References[T]](ctx context.Context) (context.Context, *Metadata[T])

func EmptyMetadata

func EmptyMetadata[T ref.References[T]]() *Metadata[T]

func EvaluateInto

func EvaluateInto[T ref.References[T]](ctx context.Context, ev Evaluator[T], from, to any) (*Metadata[T], error)

func MetadataFromContext

func MetadataFromContext[T ref.References[T]](ctx context.Context) *Metadata[T]

func NewMetadata

func NewMetadata[T ref.References[T]](refs T) *Metadata[T]

func (*Metadata[T]) AddStep

func (m *Metadata[T]) AddStep(step *Result[T], annotations ...Annotation)

func (*Metadata[T]) InsertSteps

func (m *Metadata[T]) InsertSteps(other *Metadata[T])

func (*Metadata[T]) MergeEvaluator

func (m *Metadata[T]) MergeEvaluator(other *Metadata[T])

func (*Metadata[T]) MergeEvaluatorIfNotSet

func (m *Metadata[T]) MergeEvaluatorIfNotSet(other *Metadata[T])

func (*Metadata[T]) MergeReferences

func (m *Metadata[T]) MergeReferences(other *Metadata[T])

func (*Metadata[T]) MergeSteps

func (m *Metadata[T]) MergeSteps(other *Metadata[T])

func (*Metadata[T]) OK

func (m *Metadata[T]) OK() bool

func (*Metadata[T]) Reduce

func (m *Metadata[T]) Reduce()

func (*Metadata[T]) Resolved

func (m *Metadata[T]) Resolved() bool

func (*Metadata[T]) SetAnnotation

func (m *Metadata[T]) SetAnnotation(annotation Annotation)

func (*Metadata[T]) SetEvaluator

func (m *Metadata[T]) SetEvaluator(ev Evaluator[T])

type PathEvaluationError

type PathEvaluationError struct {
	Path  string
	Cause error
}

func (*PathEvaluationError) Error

func (e *PathEvaluationError) Error() string

func (*PathEvaluationError) Propagate

func (e *PathEvaluationError) Propagate() bool

func (*PathEvaluationError) UnderlyingCause

func (e *PathEvaluationError) UnderlyingCause() error

func (*PathEvaluationError) Unwrap

func (e *PathEvaluationError) Unwrap() error

type Result

type Result[T ref.References[T]] struct {
	*Metadata[T]
	Value any
}

func ContextualizedResult

func ContextualizedResult[T ref.References[T]](m *Metadata[T]) *Result[T]

func EmptyResult

func EmptyResult[T ref.References[T]]() *Result[T]

func EvaluateAll

func EvaluateAll[T ref.References[T]](ctx context.Context, ev Evaluator[T], tree any) (*Result[T], error)

func NewResult

func NewResult[T ref.References[T]](m *Metadata[T], v any) *Result[T]

func StaticResult

func StaticResult[T ref.References[T]](v any) *Result[T]

func (*Result[T]) SetValue

func (r *Result[T]) SetValue(v any)

type Step

type Step[T ref.References[T]] struct {
	*Result[T]
	Annotations []Annotation
}

type UnsupportedValueError

type UnsupportedValueError struct {
	Type reflect.Type
}

func (*UnsupportedValueError) Error

func (e *UnsupportedValueError) Error() string

func (*UnsupportedValueError) Propagate

func (e *UnsupportedValueError) Propagate() bool

type Visitor

type Visitor[T ref.References[T]] interface {
	VisitExpandable(ctx context.Context, ex Expandable[T], depth int, next Evaluator[T]) (*Result[T], error)
	VisitSlice(ctx context.Context, s []any, depth int, next Evaluator[T]) (*Result[T], error)
	VisitMap(ctx context.Context, m map[string]any, depth int, next Evaluator[T]) (*Result[T], error)
	VisitString(ctx context.Context, s string, depth int, next Evaluator[T]) (*Result[T], error)
}

func DefaultVisitor

func DefaultVisitor[T ref.References[T]]() Visitor[T]

type VisitorFuncs

type VisitorFuncs[T ref.References[T]] struct {
	VisitExpandableFunc func(ctx context.Context, ex Expandable[T], depth int, next Evaluator[T]) (*Result[T], error)
	VisitSliceFunc      func(ctx context.Context, s []any, depth int, next Evaluator[T]) (*Result[T], error)
	VisitMapFunc        func(ctx context.Context, m map[string]any, depth int, next Evaluator[T]) (*Result[T], error)
	VisitStringFunc     func(ctx context.Context, s string, depth int, next Evaluator[T]) (*Result[T], error)
}

func (*VisitorFuncs[T]) VisitExpandable

func (vfs *VisitorFuncs[T]) VisitExpandable(ctx context.Context, ex Expandable[T], depth int, next Evaluator[T]) (*Result[T], error)

func (*VisitorFuncs[T]) VisitMap

func (vfs *VisitorFuncs[T]) VisitMap(ctx context.Context, m map[string]any, depth int, next Evaluator[T]) (*Result[T], error)

func (*VisitorFuncs[T]) VisitSlice

func (vfs *VisitorFuncs[T]) VisitSlice(ctx context.Context, s []any, depth int, next Evaluator[T]) (*Result[T], error)

func (*VisitorFuncs[T]) VisitString

func (vfs *VisitorFuncs[T]) VisitString(ctx context.Context, s string, depth int, next Evaluator[T]) (*Result[T], error)

Jump to

Keyboard shortcuts

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