Files
mesh-delivery/modules/mesh-delivery-contracts/go/clients/meshbuildsclient/client.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

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/modules/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
}