package resolution import ( "encoding/json" "strings" mcat "git.novox.be/novox/mesh-sdk/go/catalogue" ) // Holding is what a node holds while it composes itself (design 47 H, H-A-306, H-A-335, H-A-337): the modules held this // pass, each composed as its stub, and each runtime process as it runs. A holder's words that every module gives a share // of (the secret places, the owned paths) take a held module's share from what runs, never from its stub, so two passes // with the same held set compose every runtime process the same. The zero Holding holds nothing: everything is composed // from the manifests, as before. type Holding struct { // Held is each module held on this node this pass (compose.Node.Held). Held map[string]bool // Runs is the environment of each runtime process as it runs, by its id: the tool runner's (`.runtime`) and // each runtime of a module of its own account (`.own-runtime`). Runs map[string]map[string]string } // ran is module's words in process's mcat.RuntimeToolEnv as it runs, or nil when nothing is held, the process does not // run, or it gives module no words. func (h Holding) ran(process, module string) map[string]string { if len(h.Held) == 0 { return nil } env, runs := h.Runs[process] if !runs { return nil } var words map[string]map[string]string if json.Unmarshal([]byte(env[mcat.RuntimeToolEnv]), &words) != nil { return nil } return words[module] } // notHeld is r with only the modules not in held, or r itself when none is held. func notHeld(r mcat.Resolution, held map[string]bool) mcat.Resolution { if len(held) == 0 { return r } modules := make([]mcat.Manifest, 0, len(r.Modules)) for _, m := range r.Modules { if !held[m.Module] { modules = append(modules, m) } } r.Modules = modules return r } // ownerOf is the module an owned path's entry names (resolutionOwnedPaths: ` ()`). func ownerOf(entry string) string { module, _, _ := strings.Cut(entry, " (") return module }