An issue message is a string describing a constraint violation. A constraints checker collects these messages for an AST object so invalid domain data can be identified and corrected near its context. section 9.2.2
Implement issue messages by:
- Checking each constraint with an explicit negated condition and pushing a corrective violation message when the condition fails. section 9.2.2
- Returning all messages from an issuesFor function instead of stopping at the first violation. section 9.2.2
- Computing issues in the frontend projection so the information remains close to the affected object and updates reactively. section 9.2.2
Invalid data attribute
When a Data Attribute has an empty or non-string name, the checker adds “An attribute must have a name.” The interface displays a warning marker and exposes the message through the attribute’s tooltip. section 9.2.2
Listing 9.1 The initial implementation of the constraints checker
const isNonEmptyString = (value) => #1
typeof value === "string" && value.trim().length > 0
const issuesFor = (astObject) => { #2
const issues = [] #3
const { settings } = astObject #4
switch (astObject.concept) { #5
case "Data Attribute": {
if (!isNonEmptyString(settings["name"])) { #6
issues.push( #7
"An attribute must have a name")
}
break #8
}
// ...cases for other concepts to be added... #9
}
return issues
}
module.exports.issuesFor = issuesFor
This listing shows the initial constraints checker: it validates a Data Attribute, accumulates its issue message, and returns the complete issue array. section 9.2.2
