Reuse document indexes in D&D validators
This commit is contained in:
@@ -48,10 +48,14 @@ func (v *Validator) Validate(_ context.Context, req contracts.TypedValidationReq
|
||||
// Validate checks only invariants owned by normalized combat-turn output. A
|
||||
// shape or source-reference failure is deliberately deferred to its owner.
|
||||
func Validate(doc *source.SourceDocument, value dnd.CombatTurnList) error {
|
||||
if combatshape.Validate(value) != nil || !sourceRefsValid(doc, value) {
|
||||
if combatshape.Validate(value) != nil {
|
||||
return nil
|
||||
}
|
||||
issues := issuesFor(shared.NewSourceRefOrder(doc), value)
|
||||
index := source.NewDocumentIndex(doc)
|
||||
if !sourceRefsValid(index, value) {
|
||||
return nil
|
||||
}
|
||||
issues := issuesFor(shared.NewSourceRefOrderWithIndex(doc, index), value)
|
||||
if len(issues) == 0 {
|
||||
return nil
|
||||
}
|
||||
@@ -97,10 +101,10 @@ func issuesFor(order shared.SourceRefOrder, value dnd.CombatTurnList) []string {
|
||||
return issues
|
||||
}
|
||||
|
||||
func sourceRefsValid(doc *source.SourceDocument, value dnd.CombatTurnList) bool {
|
||||
func sourceRefsValid(index source.DocumentIndex, value dnd.CombatTurnList) bool {
|
||||
for _, turn := range value.CombatTurns {
|
||||
for _, ref := range turn.SourceRefs {
|
||||
if source.ValidateRef(doc, ref) != nil {
|
||||
if index.ValidateRef(ref) != nil {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user