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: `/`, the name the seat // answers it by (ADR 0605 §9's `//@…`). 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.`). func TagPrefix(path string) string { path = strings.Trim(path, "/") if path == "" || path == "." { return "v" } return path + "/v" }