blob: d85edff16571d7ad002d1d05a603aab607857cd1 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
|
package namespace
import "github.com/authzed/spicedb/pkg/schema"
// AnnotateNamespace annotates the namespace in the type system with computed aliasing and cache key
// metadata for more efficient dispatching.
func AnnotateNamespace(def *schema.ValidatedDefinition) error {
aliases, aerr := computePermissionAliases(def)
if aerr != nil {
return aerr
}
cacheKeys, cerr := computeCanonicalCacheKeys(def, aliases)
if cerr != nil {
return cerr
}
for _, rel := range def.Namespace().Relation {
if alias, ok := aliases[rel.Name]; ok {
rel.AliasingRelation = alias
}
if cacheKey, ok := cacheKeys[rel.Name]; ok {
rel.CanonicalCacheKey = cacheKey
}
}
return nil
}
|