Centralize builder request cloning

This commit is contained in:
2026-08-09 01:27:28 +00:00
parent 8e669a1f14
commit ffc179c822
5 changed files with 198 additions and 36 deletions

View File

@@ -50,16 +50,15 @@ func (c EffectiveCatalog) Lookup(name string) (string, bool) {
}
// ResolveEffectiveCatalog loads the embedded SRD catalog and applies the
// optional spell-catalog overlay found in the cloned reference set. It does
// not resolve paths or perform filesystem access.
// optional spell-catalog overlay found in its spell_catalog reference slot. It
// does not resolve paths or perform filesystem access.
func ResolveEffectiveCatalog(references contracts.ReferenceSet) (EffectiveCatalog, error) {
base, err := LoadSRD5E2014()
if err != nil {
return EffectiveCatalog{}, err
}
cloned := cloneReferenceSet(references)
slot, ok := cloned.Slots[SpellCatalogReferenceSlot]
slot, ok := references.Slots[SpellCatalogReferenceSlot]
if !ok || len(slot.Items) == 0 {
return composeEffectiveCatalog(base, nil)
}
@@ -407,21 +406,3 @@ func cloneStringMap(values map[string]string) map[string]string {
}
return out
}
func cloneReferenceSet(in contracts.ReferenceSet) contracts.ReferenceSet {
if len(in.Slots) == 0 {
return contracts.ReferenceSet{}
}
out := contracts.ReferenceSet{Slots: make(map[string]contracts.ResolvedReferenceSlot, len(in.Slots))}
for name, slot := range in.Slots {
slot.Slot.AcceptedMediaTypes = append([]string(nil), slot.Slot.AcceptedMediaTypes...)
items := make([]contracts.ReferenceItem, len(slot.Items))
for index, item := range slot.Items {
item.Content = append([]byte(nil), item.Content...)
items[index] = item
}
slot.Items = items
out.Slots[name] = slot
}
return out
}