Files
mesh-delivery/modules/mesh-delivery-view/internal/view/source.go
T
jschoubben f8eea0000a V1: the view reads the H1 want, source, source-moved and held take-ins
A want counts as applied by its fingerprint and a motion event is keyed by
it; the want's newest and rule, and the state held back read from them, go
with the assigner's holds. A branch's source is {v, source, call, heads}
with no group, its source-moved is read by its source, and the delivered
event names no group. indexer_pending's held take-ins are said in the
tiers' pending words with their branch, source, why and since, naming no
module. The view reads no source stamp on a module. Its seat list, its
first-view tool answers and its manifest name no callers; its source invoke
reads call, not group.

Builds: design 47 H §737, §744, §750, §752, §764 (the gate's groups; the indexer's pending and groups; the assigner's holds; the callers lists); lead answers H-A-26, H-A-37, H-A-48, H-A-66, H-A-78, H-A-102, H-A-109 (hq 3433db0e)

Claude-Session: https://claude.ai/code/session_01JG73KHUnBze48rdua8u2sy
2026-11-20 04:20:33 +01:00

72 lines
2.9 KiB
Go

package view
import (
"encoding/json"
"fmt"
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/clients/meshdeliveryclient"
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshdelivery"
"git.novox.be/novox/mesh-sdk/go/buscalls"
"git.novox.be/novox/mesh-sdk/go/keys"
)
// SourceVerb is the seat mesh-delivery's verb source as the view's invokes names it: each watched branch's source revision,
// asked of the seat and never read from the gate's state (design 47 G §507, §512, A-173).
const SourceVerb = "seat:" + meshdelivery.Seat + "." + meshdelivery.VerbSource
// SourceOf asks the seat, through call, for one watched branch's source revision (branch as named) and reads its declared
// answer; an answer that carries an error is that error.
func SourceOf(call func(key string, body any) (json.RawMessage, error), branch string) (meshdelivery.SourceAnswer, error) {
raw, err := call(SourceVerb, meshdelivery.SourceInput{Branch: keys.EscapeName(branch)})
if err != nil {
return meshdelivery.SourceAnswer{}, fmt.Errorf("%s of %s: %w", SourceVerb, branch, err)
}
answer, said, ok := buscalls.Unwrap(raw)
if !ok {
return meshdelivery.SourceAnswer{}, fmt.Errorf("%s of %s answered: %s", SourceVerb, branch, said)
}
var a meshdelivery.SourceAnswer
if err := json.Unmarshal(answer, &a); err != nil {
return a, fmt.Errorf("the answer of %s of %s is not a source revision: %w", SourceVerb, branch, err)
}
if a.Error != "" {
return a, fmt.Errorf("%s of %s: %s", SourceVerb, branch, a.Error)
}
return a, nil
}
// SourceEntry is a branch's source answer as the model's entry of SourceBucket: keyed by the escaped branch, its revision the
// source revision, its value the heads by repository; a branch the gate holds no source revision of yet is a removal.
func SourceEntry(branch string, a meshdelivery.SourceAnswer) (Entry, error) {
heads := map[string]string{}
for _, h := range a.Repositories {
heads[h.Repository] = h.Head
}
e := Entry{Bucket: SourceBucket, Key: keys.EscapeName(branch), Revision: uint64(a.Revision)}
if a.Revision == 0 && len(heads) == 0 { // the gate holds no source revision of the branch yet
e.Deleted = true
return e, nil
}
v, err := meshdeliveryclient.EncodeSource(meshdelivery.SourceByBranchValue{Source: a.Revision, Call: a.Call, Heads: heads})
if err != nil {
return Entry{}, err
}
e.Value = v
return e, nil
}
// SourcesOf is Reader.Sources over the watched branches followed now: each one's newest source revision through call.
func SourcesOf(call func(key string, body any) (json.RawMessage, error), followed func() []string) func() (map[string]uint64, error) {
return func() (map[string]uint64, error) {
out := map[string]uint64{}
for _, branch := range followed() {
a, err := SourceOf(call, branch)
if err != nil {
return nil, err
}
out[branch] = uint64(a.Revision)
}
return out, nil
}
}