MCPcopy Create free account
hub / github.com/Permify/permify / validateRelationTypeStatement

Method validateRelationTypeStatement

pkg/dsl/ast/validation.go:35–47  ·  view source on GitHub ↗

validateRelationTypeStatement - validates a single relation type statement to ensure that it meets certain requirements.

(ref RelationTypeStatement)

Source from the content-addressed store, hash-verified

33
34// validateRelationTypeStatement - validates a single relation type statement to ensure that it meets certain requirements.
35func (sch *Schema) validateRelationTypeStatement(ref RelationTypeStatement) error {
36 // Check that the entity reference in the relation type statement is valid.
37 if !sch.GetReferences().IsEntityReferenceExist(ref.Type.Literal) {
38 return validationError(ref.Type.PositionInfo, base.ErrorCode_ERROR_CODE_RELATION_REFERENCE_NOT_FOUND_IN_ENTITY_REFERENCES.String())
39 }
40 // If the relation type statement does not have a direct entity reference, check that the relation reference is valid.
41 if !IsDirectEntityReference(ref) {
42 if !sch.GetReferences().IsRelationReferenceExist(ref.Type.Literal + "#" + ref.Relation.Literal) {
43 return validationError(ref.Type.PositionInfo, base.ErrorCode_ERROR_CODE_RELATION_REFERENCE_NOT_FOUND_IN_ENTITY_REFERENCES.String())
44 }
45 }
46 return nil
47}
48
49// validationError - returns a formatted error message.
50func validationError(info token.PositionInfo, message string) error {

Callers 1

ValidateMethod · 0.95

Calls 6

GetReferencesMethod · 0.95
IsDirectEntityReferenceFunction · 0.85
validationErrorFunction · 0.70
StringMethod · 0.65

Tested by

no test coverage detected