Files
mesh-delivery/modules/mesh-delivery-indexer/internal/index/events.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

53 lines
2.5 KiB
Go

package index
import (
"encoding/json"
"strconv"
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshcatalog"
"git.novox.be/novox/mesh-sdk/go/catalogue"
"git.novox.be/novox/mesh-sdk/go/keys"
)
// The bodies of the seat's events manifest-accepted and manifest-refused are the contract's types; the indexer, who says
// them, makes them from a verdict (novox/hq ADR 0634 §1: the logic of one holder stays with it).
// refusedOf is the body of manifest-refused for the verdict v on the manifest of digest.
func refusedOf(digest string, v meshcatalog.VerdictsByDigestValue) meshcatalog.ManifestRefusedEvent {
return meshcatalog.ManifestRefusedEvent{V: keys.Version, Module: v.Module, Digest: digest, Judge: v.Judge, Problems: v.Problems}
}
// acceptedEvent is the body of manifest-accepted for the verdict v accepting the manifest m of digest, its bus-state
// entries whole (novox/hq ADR 0595 §4); an empty list when m asks for none.
func acceptedEvent(digest string, v meshcatalog.VerdictsByDigestValue, m catalogue.Manifest) meshcatalog.ManifestAcceptedEvent {
// problems are the manifest validator's strings, the verdict's warnings in their order, an empty list when none (design 47 G §668, §692).
problems := append([]string{}, v.Warnings...)
return meshcatalog.ManifestAcceptedEvent{V: keys.Version, Module: v.Module, Digest: digest, Judge: v.Judge, BusState: busStateOf(m.BusState), Problems: problems}
}
// busStateOf is the manifest's bus-state entries in the event's form (the same JSON).
func busStateOf(entries []catalogue.BusStateEntry) []meshcatalog.ManifestAcceptedEventBusStateItem {
out := []meshcatalog.ManifestAcceptedEventBusStateItem{}
if len(entries) == 0 {
return out
}
raw, err := json.Marshal(entries)
if err == nil {
err = json.Unmarshal(raw, &out)
}
if err != nil {
return []meshcatalog.ManifestAcceptedEventBusStateItem{}
}
return out
}
// acceptedEventID is the event's id, one per manifest digest and judge, so the bus takes it once:
// `manifest-accepted-<digest>-<judge>`. The empty one of a module leaving the trunk carries no digest, so it is named by
// its module and the indexer's revision: `manifest-accepted-left-<module>-<revision>`, so two leaves are both kept.
func acceptedEventID(a meshcatalog.ManifestAcceptedEvent) string {
if a.Digest == "" {
return meshcatalog.EventManifestAccepted + "-left-" + a.Module + "-" + strconv.FormatInt(a.Revision, 10)
}
return meshcatalog.EventManifestAccepted + "-" + a.Digest + "-" + a.Judge
}