Files
mesh-catalog/modules/nats/cmd/nats-tools/catalogview.go
T
jschoubben e4ef67adcd 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

58 lines
1.9 KiB
Go

package main
import (
"crypto/sha256"
"encoding/hex"
"encoding/json"
"fmt"
catalog "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshcatalog"
"git.novox.be/novox/mesh-sdk/go/catalogue"
"nats-tools/internal/keeper"
)
// The keeper reads a module's asks from the module's entry in the catalog half of its revision view, not from the
// indexer's event (design 47 G §344, §433).
// Asks is what one catalog graph entry says of a module for the keeper: what its manifest asks of the bus as an accepted
// verdict, the seats it claims, and whether it declares an event of its own (the facts keeper.Sends reads).
type Asks struct {
Accepted keeper.Accepted
Claims []string
EmitsOwn bool
}
// AsksOf reads one entry. An entry whose manifest is not accepted asks nothing of the bus now, as an accepted verdict of
// no entries does; the digest it carries is of the entries it asks, so an entry changed in nothing the bus module reads
// is not applied again.
func AsksOf(e catalog.CatalogEntry) (Asks, error) {
if e.Module == "" {
return Asks{}, fmt.Errorf("a catalog entry names no module")
}
raw, err := json.Marshal(e.Manifest)
if err != nil {
return Asks{}, fmt.Errorf("the manifest of %s is not readable: %w", e.Module, err)
}
var m catalogue.Manifest
if err := json.Unmarshal(raw, &m); err != nil {
return Asks{}, fmt.Errorf("the manifest of %s is not readable: %w", e.Module, err)
}
state := m.BusState
if e.Verdict != "" && e.Verdict != "accepted" {
state = nil
}
sum := sha256.Sum256(mustJSON(state))
out := Asks{Accepted: keeper.Accepted{Module: e.Module, Digest: hex.EncodeToString(sum[:]), BusState: state},
EmitsOwn: len(m.Emits) > 0 || len(e.Streams) > 0}
for _, c := range m.Claims {
out.Claims = append(out.Claims, c.Name)
}
return out, nil
}
func mustJSON(v any) []byte {
b, _ := json.Marshal(v)
return b
}