The running pre-G indexer publishes a repository's packages only when every package directory it published last is
still in the tree; G moved contracts/go and sdk to modules/, so mesh-delivery's packages, G's renamed paths among them,
are never published and nothing importing them builds (2026-11-13, indexer journal 'its packages are not published').
These are the trees of e70754ef, unchanged, without sdk/module.json (no second module). Nothing imports them; they go
once G's indexer runs and publishes without them.
Claude-Session: https://claude.ai/code/session_01NcbgfGKaxw984XyAPfLm4h
80 lines
2.7 KiB
Go
80 lines
2.7 KiB
Go
package meshcatalogclient
|
|
|
|
import (
|
|
"crypto/sha256"
|
|
"encoding/hex"
|
|
"encoding/json"
|
|
"fmt"
|
|
"unicode/utf8"
|
|
|
|
seat "git.novox.be/novox/mesh-delivery/contracts/go/seats/meshcatalog"
|
|
"git.novox.be/novox/mesh-sdk/go/keys"
|
|
)
|
|
|
|
// ManifestDigest is the hex sha256 of a manifest's bytes exactly as read at the commit: the key of a `manifests` value and
|
|
// the digest a `modules` value and a candidate's module carry (novox/hq ADR 0429 clause 16).
|
|
func ManifestDigest(raw []byte) string {
|
|
sum := sha256.Sum256(raw)
|
|
return hex.EncodeToString(sum[:])
|
|
}
|
|
|
|
// ManifestsKey is the key of a `manifests` value: the manifest's digest, 64 lowercase hex digits. The indexer writes it
|
|
// once, by a create that fails when the key exists.
|
|
func ManifestsKey(digest string) (string, error) {
|
|
if !keys.IsHex64(digest) {
|
|
return "", fmt.Errorf("meshcatalogclient: %q is not a manifest digest, 64 lowercase hex digits", digest)
|
|
}
|
|
return seat.ManifestsByDigestKey(digest), nil
|
|
}
|
|
|
|
// ParseManifestsKey is the inverse of ManifestsKey.
|
|
func ParseManifestsKey(key string) (string, error) {
|
|
digest, err := ManifestsKey(key)
|
|
if err != nil {
|
|
return "", fmt.Errorf("meshcatalogclient: %q is not a manifests key: %w", key, err)
|
|
}
|
|
return digest, nil
|
|
}
|
|
|
|
func checkManifest(m seat.ManifestsByDigestValue) error {
|
|
if err := keys.CheckName("module", m.Module); err != nil {
|
|
return err
|
|
}
|
|
if m.Manifest == "" {
|
|
return fmt.Errorf("meshcatalogclient: the manifest of %s is empty", m.Module)
|
|
}
|
|
if !utf8.ValidString(m.Manifest) {
|
|
return fmt.Errorf("meshcatalogclient: the manifest of %s is not UTF-8 text, which a value cannot hold byte for byte", m.Module)
|
|
}
|
|
if !json.Valid([]byte(m.Manifest)) {
|
|
return fmt.Errorf("meshcatalogclient: the manifest of %s is not JSON", m.Module)
|
|
}
|
|
return nil
|
|
}
|
|
|
|
// EncodeManifest is m as JSON at the kept values' version; it refuses a module that is not a name and a manifest that is
|
|
// empty, not UTF-8 or not JSON.
|
|
func EncodeManifest(m seat.ManifestsByDigestValue) ([]byte, error) {
|
|
if err := checkManifest(m); err != nil {
|
|
return nil, err
|
|
}
|
|
m.V = keys.Version
|
|
return json.Marshal(m)
|
|
}
|
|
|
|
// DecodeManifest reads a `manifests` value; it refuses an unknown version (keys.ErrUnknownVersion) and what EncodeManifest
|
|
// refuses.
|
|
func DecodeManifest(data []byte) (seat.ManifestsByDigestValue, error) {
|
|
if err := keys.CheckVersion(data); err != nil {
|
|
return seat.ManifestsByDigestValue{}, err
|
|
}
|
|
var m seat.ManifestsByDigestValue
|
|
if err := json.Unmarshal(data, &m); err != nil {
|
|
return seat.ManifestsByDigestValue{}, fmt.Errorf("meshcatalogclient: value does not fit its shape: %w", err)
|
|
}
|
|
if err := checkManifest(m); err != nil {
|
|
return seat.ManifestsByDigestValue{}, err
|
|
}
|
|
return m, nil
|
|
}
|