Files
mesh-delivery/modules/mesh-delivery-sdk/seatdefs/domain.go
T
jschoubben 71a35a6376 MV1: move contracts and sdk under modules/, importers follow
The delivery repository's contracts and SDK live under modules/ as
mesh-delivery-contracts and mesh-delivery-sdk, their Go module paths
renamed to match the folders (the TypeScript names already did), and
every importer in mesh-delivery, mesh-catalog, mesh-host, mesh-tools
and mesh-sdk follows in the same group: a design as it should be, one
path per module, checked by the group's check building every importer.

Builds: design 47 G §427, §88

Claude-Session: https://claude.ai/code/session_01NcbgfGKaxw984XyAPfLm4h
2026-11-12 05:09:56 +01:00

65 lines
2.9 KiB
Go

package seatdefs
// Where a seat of the mesh's own contracts may be defined (novox/hq ADR 0636 §5, ADR 0634 §7): a definition names its
// glossary domain; a seat of the mesh's own contracts is taken only from that domain's contracts module
// (mesh-<domain>-contracts), or from mesh-contracts for a domain with none. A definition moving from mesh-contracts to
// its domain's contracts module is a handover: the new definer takes the seat over, and a removal from the module that is
// not the seat's domain's keeps the last trunk definition until the domain's module defines it.
import (
"fmt"
"slices"
"strings"
"git.novox.be/novox/mesh-sdk/go/seatdef"
)
// Fallback is the mesh's contracts module for a domain with no contracts module of its own.
const Fallback = "mesh-contracts"
// domainsWithContracts are the domains whose seats have a contracts module of their own (ADR 0634 §7). Every other
// domain's seats are defined in Fallback.
var domainsWithContracts = []string{"Delivery", "Provisioning", "Identity and access", "Health and repair",
"Connectivity", "Operator and conversation"}
// DomainContracts is the module that defines a domain's seats: mesh-<domain>-contracts, the heading lowercased with its
// spaces as dashes, or Fallback for a domain with none.
func DomainContracts(domain string) string {
if !slices.Contains(domainsWithContracts, domain) {
return Fallback
}
return "mesh-" + strings.ReplaceAll(strings.ToLower(domain), " ", "-") + "-contracts"
}
// Own says a contracts module is one of the mesh's own: Fallback or a domain's.
func Own(module string) bool {
return module == Fallback || slices.ContainsFunc(seatdef.Domains, func(d string) bool {
return module == DomainContracts(d) && module != Fallback
})
}
// Refusal is, for a definition a contracts module of the mesh's own holds, why it may not: the words naming the module
// and the domain's. Empty when the module may define the seat (a module outside the mesh's own contracts defines what it
// likes, ADR 0625 §7).
func Refusal(module string, d seatdef.Definition) string {
if !Own(module) {
return ""
}
if want := DomainContracts(d.Domain); want != module {
return fmt.Sprintf("it is a seat of the domain %q, whose seats %s defines, and %s defines it", d.Domain, want, module)
}
return ""
}
// HandsOver says a seat its holder defines is handed over to a definer: the holder is a module of the mesh's own that is
// not the definer, and the definer is the seat's domain's contracts module.
func HandsOver(holder, definer string, d seatdef.Definition) bool {
return holder != definer && Own(holder) && DomainContracts(d.Domain) == definer
}
// HandoverPending says a seat a holder of the mesh's own no longer defines waits for its domain's module: the holder is
// not the domain's (named by the definition it held), so its last definition stays until that module defines it.
func HandoverPending(holder, domain string) bool {
return Own(holder) && DomainContracts(domain) != holder
}