56 lines
2.1 KiB
Go
56 lines
2.1 KiB
Go
package engine
|
|
|
|
import "gitea.maximumdirect.net/eric/ConfigKit/internal/document"
|
|
|
|
func chargeInheritanceTemplateHistory(counter *retainedNodeCounter, result inheritanceTemplateResult, template inheritanceExecutionTemplate) *Diagnostic {
|
|
for _, operation := range result.operations {
|
|
if !counter.add(operation.parent) || !counter.add(operation.effective) {
|
|
diagnostic := inheritanceHistoryBudgetDiagnostic(template.path, template.entry.Value.Location)
|
|
return &diagnostic
|
|
}
|
|
}
|
|
for _, replacement := range result.replacements {
|
|
if !counter.add(replacement.before) || !counter.add(replacement.after) {
|
|
diagnostic := inheritanceHistoryBudgetDiagnostic(template.path, template.entry.Value.Location)
|
|
return &diagnostic
|
|
}
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func finalizeInheritanceScope(
|
|
adapter inheritanceScopeAdapter,
|
|
result *inheritanceScope,
|
|
templates []inheritanceExecutionTemplate,
|
|
resolved []*document.Node,
|
|
resolvedOrigins []map[string]Origin,
|
|
resolvedPolicies []collectionPolicyScope,
|
|
inputOrigins map[string]Origin,
|
|
limits projectionLimits,
|
|
) []Diagnostic {
|
|
root := adapter.rebuild(resolved)
|
|
result.collectionPolicies = collectionPolicyScope{}
|
|
result.origins = directInheritanceOrigins(&document.Node{Kind: root.Kind, Location: root.Location}, adapter.scopePath(), inputOrigins)
|
|
policyIndex := newInheritancePolicyIndex(adapter.collectionPolicies())
|
|
for _, slot := range adapter.slots() {
|
|
if slot.hasTemplate {
|
|
index := slot.template
|
|
projectInheritancePolicyRoots(&result.collectionPolicies, resolvedPolicies[index], templates[index].path)
|
|
for pointer, origin := range resolvedOrigins[index] {
|
|
result.origins[pointer] = origin
|
|
}
|
|
continue
|
|
}
|
|
localPolicies := policyIndex.localize(slot.path)
|
|
projectInheritancePolicyRoots(&result.collectionPolicies, localPolicies, slot.path)
|
|
for pointer, origin := range directInheritanceOrigins(slot.value, slot.path, inputOrigins) {
|
|
result.origins[pointer] = origin
|
|
}
|
|
}
|
|
result.root = root
|
|
if !inheritanceLowerBoundWithin(result.root, limits.nodes) {
|
|
return []Diagnostic{inheritanceBudgetDiagnostic(adapter.scopePath(), adapter.scope().Location)}
|
|
}
|
|
return nil
|
|
}
|