Files
mesh-delivery/contracts/go/clients/meshbuildsclient/client.go
T
jschoubben 02a4ef3497 CT13 (reserved's answers and its client): reserved answers released or error, and meshbuildsclient asks it
reserved answers module, version, artifacts and released (a boolean), or error alone; module, version and artifacts are
read as required only without error. contracts/go/clients/meshbuildsclient (artifact go-meshbuildsclient) has Reserved,
which answers the reservation or release, a Refusal for the error and an error for an answer that is not one.

Builds: design 47 G §679, §582, §586, §650

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

54 lines
2.3 KiB
Go

// Package meshbuildsclient is the mesh-builds seat's client (novox/hq ADR 0573 §1, ADR 0627 §1; design 47 G §586): the
// registry holders' call of `reserved`, its input and each of its answers, written once. The call is the caller's own (a
// bundle's stdio.Ask, a process's call of a seat verb), so the client holds no transport.
package meshbuildsclient
import (
"encoding/json"
"fmt"
seat "git.novox.be/novox/mesh-delivery/contracts/go/seats/meshbuilds"
)
// Address is the seat verb asked, as a manifest's `invokes` names it.
const Address = "seat:" + seat.Seat + "." + seat.VerbReserved
// Call asks one verb of the seat, `seat:<seat>.<verb>`, with a body, and answers its JSON.
type Call func(address string, body any) (json.RawMessage, error)
// Refusal is the error answer of `reserved`: a name no entry carries, or a version neither reserved nor released, in the
// builder's words.
type Refusal struct{ Words string }
func (r Refusal) Error() string { return Address + ": " + r.Words }
// Reservation is a reserved or a released version with each artifact and its digest (design 47 G §679).
type Reservation struct {
Module string
Version string
Artifacts []seat.ReservedAnswerArtifactsItem
// Released is true when the catalog holds the version released and Artifacts are the digests its release recorded.
Released bool
}
// Reserved asks the seat for a module's, or a package's, reserved version. It answers the reservation or release, a
// Refusal for the answer `error`, and an error for an answer that cannot be read or lacks a module or a version without
// saying error: an answer that cannot be read is never a yes.
func Reserved(call Call, in seat.ReservedInput) (Reservation, error) {
raw, err := call(Address, in)
if err != nil {
return Reservation{}, fmt.Errorf("%s did not answer: %w", Address, err)
}
var a seat.ReservedAnswer
if err := json.Unmarshal(raw, &a); err != nil {
return Reservation{}, fmt.Errorf("%s answered what cannot be read: %s", Address, raw)
}
if a.Error != "" {
return Reservation{}, Refusal{Words: a.Error}
}
if a.Module == "" || a.Version == "" {
return Reservation{}, fmt.Errorf("%s answered no reservation: %s", Address, raw)
}
return Reservation{Module: a.Module, Version: a.Version, Artifacts: a.Artifacts, Released: a.Released}, nil
}