expressions

package
v0.395.2 Latest Latest
Warning

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

Go to latest
Published: Sep 4, 2024 License: AGPL-3.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

View Source
const (
	TypeStringMap = "StringMap"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type ConditionResolver

type ConditionResolver struct {
	// contains filtered or unexported fields
}

func NewConditionResolver

func NewConditionResolver(condition *parser.Condition, asts []*parser.AST, context *ExpressionContext) *ConditionResolver

func (*ConditionResolver) Resolve

func (c *ConditionResolver) Resolve() (resolvedLhs *ExpressionScopeEntity, resolvedRhs *ExpressionScopeEntity, errors []error)

type ExpressionContext

type ExpressionContext struct {
	Model     *parser.ModelNode
	Action    *parser.ActionNode
	Attribute *parser.AttributeNode
	Field     *parser.FieldNode
}

ExpressionContext represents all of the metadata that we need to know about to resolve an expression. For example, we need to know the parent constructs in the schema such as the current model, the current attribute or the current action in order to determine what fragments are expected in an expression

type ExpressionObjectEntity

type ExpressionObjectEntity struct {
	Name   string
	Fields []*ExpressionScopeEntity
}

type ExpressionScope

type ExpressionScope struct {
	Parent   *ExpressionScope
	Entities []*ExpressionScopeEntity
}

ExpressionScope is used to represent things that should be in the scope of an expression. Operands in an expression are composed of fragments, which are dot separated identifiers: e.g post.title The base scope that is constructed before we start evaluating the first fragment contains things like ctx, any input parameters, the current model etc

func DefaultExpressionScope

func DefaultExpressionScope(asts []*parser.AST) *ExpressionScope

func (*ExpressionScope) Merge

type ExpressionScopeEntity

type ExpressionScopeEntity struct {
	Name string

	Object    *ExpressionObjectEntity
	Model     *parser.ModelNode
	Field     *parser.FieldNode
	Literal   *parser.Operand
	Enum      *parser.EnumNode
	EnumValue *parser.EnumValueNode
	Array     []*ExpressionScopeEntity

	// Type can be things like "Text", "Boolean" etc.. but can also be "Enum".
	// If the value is "Enum" then the Field attribute will be populated
	// with a model field that is an enum
	Type string

	Parent *ExpressionScopeEntity
}

An ExpressionScopeEntity is an individual item that is inserted into an expression scope. So a scope might have multiple entities of different types in it at one single time: example: &ExpressionScope{Entities: []*ExpressionScopeEntity{{ Name: "ctx": Object: {....} }}, Parent: nil} Parent is used to provide useful metadata about any upper scopes (e.g previous fragments that were evaluated)

func (*ExpressionScopeEntity) AllowedOperators

func (e *ExpressionScopeEntity) AllowedOperators(asts []*parser.AST) []string

func (*ExpressionScopeEntity) GetType

func (e *ExpressionScopeEntity) GetType() string

func (*ExpressionScopeEntity) IsEnumField

func (e *ExpressionScopeEntity) IsEnumField() bool

func (*ExpressionScopeEntity) IsEnumValue

func (e *ExpressionScopeEntity) IsEnumValue() bool

func (*ExpressionScopeEntity) IsNull

func (e *ExpressionScopeEntity) IsNull() bool

func (*ExpressionScopeEntity) IsOptional

func (e *ExpressionScopeEntity) IsOptional() bool

func (*ExpressionScopeEntity) IsRepeated

func (e *ExpressionScopeEntity) IsRepeated() bool

IsRepeated returns true if the entity is a repeated value This can be because it is a literal array e.g. [1,2,3] or because it's a repeated field or at least one parent entity is a repeated field e.g. order.items.product.price would be a list of prices (assuming order.items is an array of items)

type OperandPosition

type OperandPosition = string
const (
	OperandPositionLhs OperandPosition = "lhs"
	OperandPositionRhs OperandPosition = "rhs"
)

type OperandResolver

type OperandResolver struct {
	// contains filtered or unexported fields
}

func NewOperandResolver

func NewOperandResolver(operand *parser.Operand, asts []*parser.AST, context *ExpressionContext, position OperandPosition) *OperandResolver

func (*OperandResolver) Resolve

func (o *OperandResolver) Resolve() (entity *ExpressionScopeEntity, err *ResolutionError)

A condition is composed of a LHS operand (and an operator, and a RHS operand if not a value only condition like expression: true) Given an operand of a condition, tries to resolve all of the fragments defined within the operand an operand might be: - post.author.name - post.author - MyEnum.ValueName - "123" - true - ctx.identity.account - ctx.identity.account.name All of these types above are checked / attempted to be resolved in this method.

type ResolutionError

type ResolutionError struct {
	// contains filtered or unexported fields
}

func (*ResolutionError) Error

func (e *ResolutionError) Error() string

func (*ResolutionError) InScopeEntities

func (e *ResolutionError) InScopeEntities() []string

func (*ResolutionError) ToValidationError

func (e *ResolutionError) ToValidationError() *errorhandling.ValidationError

Jump to

Keyboard shortcuts

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