expressions

package
v0.386.0 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func TryResolveExpressionEarly

func TryResolveExpressionEarly(ctx context.Context, schema *proto.Schema, model *proto.Model, action *proto.Action, expression *parser.Expression, args map[string]any) (canResolveInMemory bool, resolvedValue bool)

TryResolveExpressionEarly attempts to evaluate the expression in the runtime process without generating a row-based query against the database.

Types

type OperandResolver

type OperandResolver struct {
	Context context.Context
	Schema  *proto.Schema
	Model   *proto.Model
	Action  *proto.Action
	// contains filtered or unexported fields
}

OperandResolver hides some of the complexity of expression parsing so that the runtime action code can reason about and execute expression logic without stepping through the AST.

func NewOperandResolver

func NewOperandResolver(ctx context.Context, schema *proto.Schema, model *proto.Model, action *proto.Action, operand *parser.Operand) *OperandResolver

func (*OperandResolver) GetOperandType

func (resolver *OperandResolver) GetOperandType() (proto.Type, bool, error)

GetOperandType returns the equivalent protobuf type for the expression operand and whether it is an array or not

func (*OperandResolver) IsContext added in v0.370.1

func (resolver *OperandResolver) IsContext() bool

func (*OperandResolver) IsContextDbColumn added in v0.369.1

func (resolver *OperandResolver) IsContextDbColumn() bool

IsContextDbColumn returns true if the expression refers to a value on the context which will require database access (such as with identity backlinks), such as: @permission(expression: ctx.identity.user.isActive)

func (*OperandResolver) IsContextField

func (resolver *OperandResolver) IsContextField() bool

IsContextField returns true if the expression operand refers to a value on the context which does not require to be read from the database. For example, a permission condition may check against the current identity, such as: @permission(thing.identity == ctx.identity)

However if the expression traverses onwards from identity (using an Identity-backlink) like this: "ctx.identity.user" then it returns false, because that can no longer be resolved solely from the in memory context data.

func (*OperandResolver) IsExplicitInput

func (resolver *OperandResolver) IsExplicitInput() bool

IsExplicitInput returns true if the expression operand refers to an explicit input on an action. For example, a where condition might use an explicit input, such as: list listThings(isActive: Boolean) @where(thing.isActive == isActive)

func (*OperandResolver) IsImplicitInput

func (resolver *OperandResolver) IsImplicitInput() bool

IsImplicitInput returns true if the expression operand refers to an implicit input on an action. For example, an input value provided in a create action might require validation, such as: create createThing() with (name) @validation(name != "")

func (*OperandResolver) IsLiteral

func (resolver *OperandResolver) IsLiteral() bool

IsLiteral returns true if the expression operand is a literal type. For example, a number or string literal written straight into the Keel schema, such as the right-hand side operand in @where(person.age > 21).

func (*OperandResolver) IsModelDbColumn added in v0.369.1

func (resolver *OperandResolver) IsModelDbColumn() bool

IsModelDbColumn returns true if the expression operand refers to a field value residing in the database. For example, a where condition might filter on reading data, such as: @where(post.author.isActive)

func (*OperandResolver) NormalisedFragments added in v0.369.1

func (resolver *OperandResolver) NormalisedFragments() ([]string, error)

NormalisedFragments will return the expression fragments "in full" so that they can be processed for query building For example, note the two expressions in the condition @where(account in ctx.identity.primaryAccount.following.followee) NormalisedFragments will transform each of these operands as follows:

account.id
ctx.identity.primaryAccount.following.followeeId

func (*OperandResolver) ResolveValue

func (resolver *OperandResolver) ResolveValue(args map[string]any) (any, error)

ResolveValue returns the actual value of the operand, provided a database read is not required.

Jump to

Keyboard shortcuts

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