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

@@ -62,31 +62,31 @@ 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.EnemyEventList]) (contracts.TypedNormalizeResult[dnd.EnemyEventList], error) {
func (n *Normalizer) PrepareNormalize(ctx context.Context, req contracts.NormalizeInput[dnd.EnemyEventList]) (contracts.PreparedOperation[dnd.EnemyEventList], error) {
if n == nil || n.npcResolver == nil {
return contracts.TypedNormalizeResult[dnd.EnemyEventList]{}, normalizerErrorf("normalizer must not be nil")
return nil, normalizerErrorf("normalizer must not be nil")
}
if ctx == nil {
return contracts.TypedNormalizeResult[dnd.EnemyEventList]{}, normalizerErrorf("context must not be nil")
return nil, normalizerErrorf("context must not be nil")
}
if err := ctx.Err(); err != nil {
return contracts.TypedNormalizeResult[dnd.EnemyEventList]{}, 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.EnemyEventList]{}, normalizerErrorf("resolve NPC registry: %w", err)
return nil, normalizerErrorf("resolve NPC registry: %w", err)
}
if !registry.Bound() {
return contracts.TypedNormalizeResult[dnd.EnemyEventList]{}, 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 := normalizeList(req.MergeOutput.Value, order, registry)
diagnosticGroups, err := diagnostics.NormalizationDiagnostics(findings)
if err != nil {
return contracts.TypedNormalizeResult[dnd.EnemyEventList]{}, normalizerErrorf("collect diagnostics: %w", err)
return nil, normalizerErrorf("collect diagnostics: %w", err)
}
return contracts.TypedNormalizeResult[dnd.EnemyEventList]{Value: value, Diagnostics: diagnosticGroups}, nil
return contracts.DeterministicOperation[dnd.EnemyEventList]{Evaluation: contracts.CandidateEvaluation[dnd.EnemyEventList]{Result: contracts.EvaluationView[dnd.EnemyEventList]{Candidate: &value, Diagnostics: diagnosticGroups}}}, nil
}
type normalizedRecord struct {