Prepare deterministic D&D normalization in core

This commit is contained in:
2026-11-25 15:49:34 +00:00
parent e3ddc177ab
commit 99f00c808c
16 changed files with 172 additions and 79 deletions

View File

@@ -61,35 +61,35 @@ func (n *Normalizer) Key() string { return Key }
func (n *Normalizer) ReferenceSlots() []contracts.ReferenceSlot { return referenceSlots() }
func (n *Normalizer) Normalize(ctx context.Context, req contracts.TypedNormalizeRequest[dnd.NPCOccurrenceList]) (contracts.TypedNormalizeResult[dnd.NPCOccurrenceList], error) {
func (n *Normalizer) PrepareNormalize(ctx context.Context, req contracts.NormalizeInput[dnd.NPCOccurrenceList]) (contracts.PreparedOperation[dnd.NPCOccurrenceList], error) {
if n == nil || n.npcResolver == nil {
return contracts.TypedNormalizeResult[dnd.NPCOccurrenceList]{}, normalizerErrorf("normalizer must not be nil")
return nil, normalizerErrorf("normalizer must not be nil")
}
if ctx == nil {
return contracts.TypedNormalizeResult[dnd.NPCOccurrenceList]{}, normalizerErrorf("context must not be nil")
return nil, normalizerErrorf("context must not be nil")
}
if err := ctx.Err(); err != nil {
return contracts.TypedNormalizeResult[dnd.NPCOccurrenceList]{}, normalizerErrorf("context error before normalize: %w", err)
return nil, normalizerErrorf("context error before normalize: %w", err)
}
registry, err := n.npcResolver.Resolve(req.References)
if err != nil {
return contracts.TypedNormalizeResult[dnd.NPCOccurrenceList]{}, normalizerErrorf("resolve NPC registry: %w", err)
return nil, normalizerErrorf("resolve NPC registry: %w", err)
}
if !registry.Bound() {
return contracts.TypedNormalizeResult[dnd.NPCOccurrenceList]{}, normalizerErrorf("NPC registry reference is required")
return nil, normalizerErrorf("NPC registry reference is required")
}
index := source.NewDocumentIndex(req.Source)
order := shared.NewSourceRefOrderFromIndex(index)
value, findings, err := normalizeList(req.MergeOutput.Value, index, order, registry)
if err != nil {
return contracts.TypedNormalizeResult[dnd.NPCOccurrenceList]{}, normalizerErrorf("validate NPC registry pairs: %w", err)
return nil, normalizerErrorf("validate NPC registry pairs: %w", err)
}
diagnosticGroups, err := diagnostics.NormalizationDiagnostics(findings)
if err != nil {
return contracts.TypedNormalizeResult[dnd.NPCOccurrenceList]{}, normalizerErrorf("collect diagnostics: %w", err)
return nil, normalizerErrorf("collect diagnostics: %w", err)
}
return contracts.TypedNormalizeResult[dnd.NPCOccurrenceList]{Value: value, Diagnostics: diagnosticGroups}, nil
return contracts.DeterministicOperation[dnd.NPCOccurrenceList]{Evaluation: contracts.CandidateEvaluation[dnd.NPCOccurrenceList]{Result: contracts.EvaluationView[dnd.NPCOccurrenceList]{Candidate: &value, Diagnostics: diagnosticGroups}}}, nil
}
type normalizedRecord struct {