package grants import ( "slices" "strings" "git.novox.be/novox/mesh-sdk/go/catalogue" ) // **A module's sent store is read by the modules it is for** (design 47 G §59, §124): the grants part derives, from the // catalog graph, never from a manifest field, a standing read of `_sent-objects` for every module invoking a verb of a // seat it claims (every account may call every verb, design 47 H §752, H-A-66), and for the consumers whose `consumes` declare // its events. The grant follows the catalog graph, so it is composed with each module's declaration at every pass. // sentStoresRead are the bus names of the sent stores the module m reads: of each module whose event it consumes (the module's // own, or the seat a module claims), and of each module claiming a seat whose verb m invokes. // Never m's own store, which its binding grants it. func sentStoresRead(m catalogue.Manifest, all map[string]catalogue.Manifest) []string { claimants := func(name string) []string { var out []string if _, ok := all[name]; ok { out = append(out, name) } for module, x := range all { if slices.ContainsFunc(x.Claims, func(c catalogue.Claim) bool { return c.Name == name }) { out = append(out, module) } } return out } var stores []string for _, c := range m.Consumes { name, _, ok := strings.Cut(strings.TrimPrefix(c, "seat:"), ".") if !ok || name == "*" { continue } for _, module := range claimants(name) { stores = append(stores, catalogue.SentObjectsName(module)) } } for _, in := range m.Invokes { seat, _, ok := catalogue.SeatInvoke(in) if !ok { continue } for module, x := range all { if slices.ContainsFunc(x.Claims, func(c catalogue.Claim) bool { return c.Name == seat }) { stores = append(stores, catalogue.SentObjectsName(module)) } } } stores = slices.DeleteFunc(stores, func(s string) bool { return s == catalogue.SentObjectsName(m.Module) }) slices.Sort(stores) return slices.Compact(stores) }