validation

package
v0.372.0 Latest Latest
Warning

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

Go to latest
Published: Nov 15, 2023 License: AGPL-3.0 Imports: 22 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

Functions

This section is empty.

Types

type Validator

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

func NewValidator

func NewValidator(asts []*parser.AST) *Validator

func (*Validator) RunAllValidators

func (v *Validator) RunAllValidators() (errs *errorhandling.ValidationErrors)

type Visitor

type Visitor struct {
	EnterModel func(n *parser.ModelNode)
	LeaveModel func(n *parser.ModelNode)

	EnterModelSection func(n *parser.ModelSectionNode)
	LeaveModelSection func(n *parser.ModelSectionNode)

	EnterMessage func(n *parser.MessageNode)
	LeaveMessage func(n *parser.MessageNode)

	EnterField func(n *parser.FieldNode)
	LeaveField func(n *parser.FieldNode)

	EnterAction func(n *parser.ActionNode)
	LeaveAction func(n *parser.ActionNode)

	EnterWith func(n *parser.ActionNode)
	LeaveWith func(n *parser.ActionNode)

	EnterActionInput func(n *parser.ActionInputNode)
	LeaveActionInput func(n *parser.ActionInputNode)

	EnterEnum func(n *parser.EnumNode)
	LeaveEnum func(n *parser.EnumNode)

	EnterRole func(n *parser.RoleNode)
	LeaveRole func(n *parser.RoleNode)

	EnterAttribute func(n *parser.AttributeNode)
	LeaveAttribute func(n *parser.AttributeNode)

	EnterAttributeArgument func(n *parser.AttributeArgumentNode)
	LeaveAttributeArgument func(n *parser.AttributeArgumentNode)

	EnterAPI func(n *parser.APINode)
	LeaveAPI func(n *parser.APINode)

	EnterJob func(n *parser.JobNode)
	LeaveJob func(n *parser.JobNode)

	EnterJobInput func(n *parser.JobInputNode)
	LeaveJobInput func(n *parser.JobInputNode)
}

Visitor lets you define "enter" and "leave" functions for AST nodes. This struct may not have fields for all AST nodes, so if you need to visit a node that is not currently supported add the necessary fields to this struct. For your functions to get called you must name these fields correctly.

For a node type called "SomethingNode" the hooks would be:

EnterSomething: func(n *parser.SomethingNode)
LeaveSomething: func(n *parser.SomethingNode)

func CasingRule

func CasingRule(_ []*parser.AST, errs *errorhandling.ValidationErrors) Visitor

Casing checks that entities in the schema conform to our casing conventions.

Models, enums, enum values, roles, and API's must written in UpperCamelCase. Fields, actions, and inputs must be written in lowerCamelCase.

func ConflictingInputsRule

func ConflictingInputsRule(_ []*parser.AST, errs *errorhandling.ValidationErrors) Visitor

ConflictingInputsRule checks for model inputs that are also used in @set or @where attributes. In this case one usage would cancel out the other, so it doesn't make sense to have both.

For example in the getThing operation `id` is listed as a model input but is also used in a @where expression.

func CreateNestedInputIsMany added in v0.369.1

func CreateNestedInputIsMany(asts []*parser.AST, errs *errorhandling.ValidationErrors) Visitor

func DuplicateDefinitionRule

func DuplicateDefinitionRule(asts []*parser.AST, errs *errorhandling.ValidationErrors) Visitor

DuplicateDefinitionRule checks the uniqueness of model, enum, message, and job names.

Model, enum, and message names need to be globally unique. There cannot be two jobs with the same name

func DuplicateInputsRule

func DuplicateInputsRule(asts []*parser.AST, errs *errorhandling.ValidationErrors) Visitor

DuplicateInputsRule checks that input names are not duplicated for an action.

func FunctionDisallowedBehavioursRule

func FunctionDisallowedBehavioursRule(asts []*parser.AST, errs *errorhandling.ValidationErrors) Visitor

FunctionDisallowedBehavioursRule will validate against usages of @set, @where and nested inputs for any actions marked with the @function attribute as we do not support these sets of functionality in @function's

func InvalidWithUsage

func InvalidWithUsage(asts []*parser.AST, errs *errorhandling.ValidationErrors) Visitor

InvalidWithUsage checks that the 'with' keyword is only used for actions that receive write values

func Jobs

func Jobs(asts []*parser.AST, errs *errorhandling.ValidationErrors) Visitor

func NameClashesRule

func NameClashesRule(asts []*parser.AST, errs *errorhandling.ValidationErrors) Visitor

NameClashes checks that the names of entities defined in a schema do not clash with built-in types or reserved keywords

func NotMutableInputs added in v0.370.1

func NotMutableInputs(_ []*parser.AST, errs *errorhandling.ValidationErrors) Visitor

NotMutableInputs checks that the write action inputs for update and create aren't setting the id of the root model and aren't setting the createdAt and updatedAt fields on any models.

func OnAttributeRule

func OnAttributeRule(asts []*parser.AST, errs *errorhandling.ValidationErrors) Visitor

func OrderByAttributeRule

func OrderByAttributeRule(asts []*parser.AST, errs *errorhandling.ValidationErrors) Visitor

func PermissionsAttributeArguments added in v0.370.1

func PermissionsAttributeArguments(asts []*parser.AST, errs *errorhandling.ValidationErrors) Visitor

func RelationshipsRules added in v0.369.1

func RelationshipsRules(asts []*parser.AST, errs *errorhandling.ValidationErrors) Visitor

func RepeatedScalarFieldRule

func RepeatedScalarFieldRule(_ []*parser.AST, errs *errorhandling.ValidationErrors) Visitor

RepeatedScalarFieldRule validates that you cannot define a repeated scalar field This will be temporary until we can support repeated fields at the database level

func RequiredFieldOfSameMessageType

func RequiredFieldOfSameMessageType(_ []*parser.AST, errs *errorhandling.ValidationErrors) Visitor

RequiredFieldOfSameMessageType ensures that a message cannot have a required field of the same type, as this results in an infinite recursion.

func RequiredFieldOfSameModelType

func RequiredFieldOfSameModelType(_ []*parser.AST, errs *errorhandling.ValidationErrors) Visitor

RequiredFieldOfSameModelType ensures that a model cannot have a required field of the same type, as this results in an infinite recursion.

func ScheduleAttributeRule

func ScheduleAttributeRule(asts []*parser.AST, errs *errorhandling.ValidationErrors) Visitor

func SetAttributeExpressionRules added in v0.370.1

func SetAttributeExpressionRules(asts []*parser.AST, errs *errorhandling.ValidationErrors) Visitor

func SortableAttributeRule

func SortableAttributeRule(asts []*parser.AST, errs *errorhandling.ValidationErrors) Visitor

func UniqueAttributeRule

func UniqueAttributeRule(asts []*parser.AST, errs *errorhandling.ValidationErrors) Visitor

UniqueAttributeRule validates that unique attributes are valid according to the following rules: - @unique can't be used on Timestamp fields - @unique can't be used on has-many relations - composite @unique attributes must not have duplicate field names - composite @unique can't specify has-many fields

func UniqueLookup added in v0.370.0

func UniqueLookup(asts []*parser.AST, errs *errorhandling.ValidationErrors) Visitor

UniqueLookup checks that the filters will guarantee that one or zero record returned for get, update and delete actions

func UnusedInputRule

func UnusedInputRule(_ []*parser.AST, errs *errorhandling.ValidationErrors) Visitor

UnusedInputRule checks that all named action inputs are used in either @set or @where expressions in the action.

type VisitorFunc

type VisitorFunc func([]*parser.AST, *errorhandling.ValidationErrors) Visitor

Directories

Path Synopsis
api

Jump to

Keyboard shortcuts

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