31 lines
1.1 KiB
Go
31 lines
1.1 KiB
Go
package engine
|
|
|
|
import "slices"
|
|
|
|
func transferredOperationOrigin(operation inheritanceOperation, destination Path) (Origin, bool) {
|
|
if inheritanceOperationIdentity(operation, destination) {
|
|
return Origin{}, false
|
|
}
|
|
relative, ok := relativeHistoryPath(operation.transfer.to, destination)
|
|
if !ok {
|
|
return Origin{}, false
|
|
}
|
|
source := appendInheritancePath(operation.transfer.from, relative)
|
|
origin, found := operation.parentOrigins[source.String()]
|
|
if !found {
|
|
return Origin{}, false
|
|
}
|
|
transferred := transferredInheritanceOrigins(map[string]Origin{source.String(): origin},
|
|
operation.transfer.from, operation.transfer.to, *operation.transfer)
|
|
return transferred[destination.String()], true
|
|
}
|
|
|
|
func inheritanceOperationIdentity(operation inheritanceOperation, path Path) bool {
|
|
if operation.transfer == nil || len(operation.identityFields) == 0 {
|
|
return false
|
|
}
|
|
relative, within := relativeHistoryPath(operation.transfer.to, path)
|
|
return within && len(relative.segments) != 0 && relative.segments[0].kind != pathSegmentIndex &&
|
|
slices.Contains(operation.identityFields, relative.segments[0].key)
|
|
}
|