The numbering from before G goes (design 47 H §756, G §372): the builder keeps no state versions, marks no numbered entry on a registry seat's word and arms no numbered version's publish bound; the publishes' findings and the reservations still hear the same events (DQ-11), and a reserved version's bound is the reservation's (DQ-10). builder_versions keeps answering, from the reservations alone (DMC-5): what the seat mesh-builds' reserved answers for a name and, with a version and a digest, whether that version is reserved or released with that digest. Builds: design 47 H §756, G §372, G §381, H2 H-A-532 (DMC-5, DQ-10, DQ-11), spec 29, 41, 48
54 lines
2.0 KiB
Go
54 lines
2.0 KiB
Go
package versions
|
|
|
|
import (
|
|
"context"
|
|
"strings"
|
|
)
|
|
|
|
// The registry seats a version is published to (design 51 *The seats*), by what is published.
|
|
const (
|
|
SeatImages = "container-image-registry"
|
|
SeatArtifacts = "oci-artifact-registry"
|
|
SeatGoPackages = "go-package-registry"
|
|
SeatNPM = "npm-package-registry"
|
|
)
|
|
|
|
// SeatOf is the registry seat an artifact of kind in language is published to, and the kind the builder numbers it as;
|
|
// ok is false for what is not numbered (an upstream copy is mirrored by its pinned digest, design 51 *Publishing*).
|
|
func SeatOf(kind, language string) (seat, numberedAs string, ok bool) {
|
|
switch kind {
|
|
case KindImage:
|
|
return SeatImages, KindImage, true
|
|
case KindBundle, KindArchive:
|
|
return SeatArtifacts, kind, true
|
|
case KindPackage:
|
|
switch language {
|
|
case "go":
|
|
return SeatGoPackages, KindPackage, true
|
|
case "typescript", "javascript", "node":
|
|
return SeatNPM, KindPackage, true
|
|
}
|
|
}
|
|
return "", "", false
|
|
}
|
|
|
|
// NameOf is the name a module's image, bundle or archive is numbered under: `<module>/<artifact>`, the name the seat
|
|
// answers it by (ADR 0605 §9's `<registry>/<module>/<artifact>@…`). A package is numbered under its name in its own
|
|
// ecosystem instead (Numberer.Names).
|
|
func NameOf(module, artifact string) string { return module + "/" + artifact }
|
|
|
|
// PackageNames answers a package's name in its own ecosystem (design 32: a Go package's module path, an npm package's
|
|
// package.json name) for the module and artifact it is built from, as the indexer's packages state holds it; known is
|
|
// false when the state names none for it. An error is a state that cannot be read.
|
|
type PackageNames func(ctx context.Context, module, artifact string) (name string, known bool, err error)
|
|
|
|
// TagPrefix is the git tag prefix of a package in the module's directory path: `go/v` for mesh-sdk's `go`, `v` at the
|
|
// root (design 51: the builder tags each Go version `go/v0.1.<n>`).
|
|
func TagPrefix(path string) string {
|
|
path = strings.Trim(path, "/")
|
|
if path == "" || path == "." {
|
|
return "v"
|
|
}
|
|
return path + "/v"
|
|
}
|