moduleindex

package
v0.4.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 29, 2026 License: Apache-2.0 Imports: 15 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package moduleindex builds the module index of a release from the previous index, the release's packages, its tag and its withdrawals, refusing by the rules module-index.*; reads an index of any version of the format by the places every version keeps; and picks the version of a module for a new attempt: the newest by semver that is not withdrawn and lies in the format's window. The CLI's index and open call it, and api.

Build takes a Release — the previous index as its file, or First, the packages that package modulepackage built or read, the tag and the withdrawals — and gives module-index.json, the canonical text of the index from internal/canonical, or a *Refusal that names every breach of the rules of the index. Read reads an index by its members at their places alone, gives every entry of whatever format version, and takes a version as withdrawn whatever its reason. Newest picks the version of a new attempt, skipping an entry whose format version module-kit does not read. WithLatest marks in the index of a release the withdrawals that the index of the newest release knows, for the CLI's open. Versions are ordered by internal/semver. It checks no signature: spec's release-verify does, where a file enters NovaTrail.

Index

Constants

View Source
const (
	RuleEntriesKept      = "module-index.entries-kept"
	RuleOnePackage       = "module-index.one-package"
	RuleKnownWithdrawals = "module-index.known-withdrawals"
	RuleVersionAbove     = "module-index.version-above"
	RuleOneCourse        = "module-index.one-course"
	RuleCourseVersion    = "module-index.course-version-above"
	RuleCourseModules    = "module-index.course-modules"
	RuleCourseID         = "module-index.course-id"
)

The rules of the module index, which refuse to build an index rather than a module.

View Source
const File = "module-index.json"

File is the name of the module index among the files of a release of modules.

Variables

View Source
var (
	// ErrPrevious is a previous index that cannot be read: one built by a later format version than
	// module-kit reads, or one that is not what a build writes — the canonical text of a value valid
	// against the schema of the module index of the version module-kit reads, with teaches in order
	// —, or none where the release is not the first, or one where it is. Such a release fails: it does
	// not start a new index.
	ErrPrevious = errors.New("the previous index cannot be read")
	// ErrRelease is a release of which no index can be built: a tag that is not one of a release of
	// modules, withdrawals not in the form of $defs/withdrawals, a package that package
	// modulepackage did not build or read, a course that package course does not accept, or no
	// version at all to name.
	ErrRelease = errors.New("not a release whose index can be built")
)

The reasons Build builds no index other than the rules of the index, which its error wraps.

View Source
var ErrLatest = errors.New("not an index of a release at or after the release's")

ErrLatest is an index given as the newest that is not an index of a release at or after the one it is given with: it lacks an entry of that release's index, holds one otherwise than it was, or does not keep its withdrawal.

View Source
var ErrNotIndex = errors.New("no module index by the places every version of the format keeps")

ErrNotIndex is a text that Read does not read as a module index: no JSON object, or one whose members at the places every version of the format keeps are not in their forms.

Rules lists the rules of the module index, in the order the format lists them.

Functions

func Build

func Build(r Release) ([]byte, error)

Build builds the module index of a release by the format version module-kit reads, FormatVersion of package module, and gives its file, module-index.json: the canonical text of the index. Every entry of the previous index stands in the new one as it was; a package of a version that the previous index names keeps that entry, its release among it; every other package gets a new entry, which names the release's tag; the courses go the same way, every course entry of the previous index kept and a course file of a version that it does not name given a new entry; and last, the release's withdrawals are marked.

A release that breaks a rule of the index gives a *Refusal, with every breach in the order of the module or course, the version and the rule; the build is refused, rather than an index built without what breaks the rule. Any other error wraps ErrPrevious or ErrRelease, and comes before a refusal: the rules are read only on a release whose previous index, tag, withdrawals, packages and courses are in their forms.

func Newest

func Newest(index formatv0.ModuleIndex, id formatv0.ModuleID) (version formatv0.ModuleVersion, ok bool)

Newest gives the version of the module id that a new attempt takes: the newest by Semantic Versioning of the versions that the index names, of those not withdrawn, whatever the reason, and whose format version module-kit reads, ReadsFormat of package module. ok is false when the index names no such version. The same version is the one by which a module counts as teaching the anchor skills of its entry. A version not in the form X.Y.Z, which no index that Read or Build gives names, is skipped too.

func NewestCourse added in v0.4.0

func NewestCourse(index formatv0.ModuleIndex, id formatv0.ModuleID) (version formatv0.ModuleVersion, ok bool)

NewestCourse gives the current version of the course id: the newest by Semantic Versioning of the versions that the index names whose format version module-kit reads, ReadsFormat of package module. A course is not withdrawn. ok is false when the index names no such version, and a version not in the form X.Y.Z, which no index that Read or Build gives names, is skipped.

func Read

func Read(data []byte) (formatv0.ModuleIndex, error)

Read reads a module index of any version of the format by the places that every version keeps, and not by the schema of its own version, which refuses what a later version adds: module_format_version, modules and courses at its root, module_format_version, package_digest, release, teaches and withdrawn in an entry of a module, and module_format_version, release and course in an entry of a course. A member at another place, which a later version may add, is not read. Those members keep their forms in every version too, so one that is not in its form is no index of any version, and Read gives ErrNotIndex. A version is withdrawn whatever its reason: Withdrawn holds the reason as the index writes it, one that a later version adds among them.

Read gives every entry of a module, of whatever format version, so that the comparison of versions sees every published version of a module. A pick of a version, Newest, skips an entry whose format version module-kit does not read, rather than refuse the index. An entry of a course whose format version module-kit does not read Read skips itself, since its course is written by rules module-kit does not know, and so does it with a course left with no entry: only the format version and the release of such an entry are held to their forms. Read checks no signature: the index was checked where it entered NovaTrail. Nor does it hold the text to the canonical text, which a later version may change; a name that stands twice in one object, which no build writes, counts by its last member.

func WithLatest added in v0.2.1

func WithLatest(release, latest formatv0.ModuleIndex) (formatv0.ModuleIndex, error)

WithLatest gives the index of a release with the withdrawals that the index of the newest release marks: each entry of release as it is, but withdrawn whenever latest withdraws it, by latest's reason, and each entry of a course of release as it is, since a course is not withdrawn. Only the newest index knows of every withdrawal so far, and a version that it withdraws is no version to show, whatever the release that published it says. Newest of the index it gives is then the version that the page of samples of canvas takes of a module, as the CLI's open does.

Every later index keeps every entry as it was, and a withdrawal with its reason (module-index.entries-kept, module-index.known-withdrawals). So an entry of release that latest lacks, holds otherwise or does not keep withdrawn, of a module or of a course, gives ErrLatest, and so latest from a release before release's does too; an entry of latest that release lacks, of a later release, is left out. latest may be release itself. Neither index is changed.

Types

type Breach

type Breach struct {
	Rule    string
	Module  formatv0.ModuleID
	Version formatv0.ModuleVersion
	Message string
}

A Breach is a rule of the module index that the build of a release breaks, at the version of a module or of a course that breaks it, with what is wrong: Module is then the ID of the module or of the course.

func (Breach) String

func (b Breach) String() string

type Refusal

type Refusal struct {
	Breaches []Breach
}

A Refusal is why Build builds no index: the release breaks rules of the module index, and it names every breach.

func (*Refusal) Error

func (r *Refusal) Error() string

type Release

type Release struct {
	// Previous is the index of the release before, module-index.json as that release holds it,
	// byte for byte. The first release of modules has none, and says so by First: an empty
	// Previous is no index, so a file that could not be read does not start a new one.
	Previous []byte
	First    bool
	// Tag is the tag of the release, vX.Y.Z, which each new entry names.
	Tag formatv0.Release
	// Packages are the packages of the release, as package modulepackage built or read them. A
	// release may build every module or only those that changed: a package of a version that the
	// previous index names keeps its entry.
	Packages []*modulepackage.Package
	// Withdrawals are the versions that the release withdraws from publication, by module ID and
	// version, each with its reason, as $defs/withdrawals of module-index.schema.json gives them.
	// A release that withdraws none has nil.
	Withdrawals formatv0.Withdrawals
	// Courses are the course files of the release, each as package course reads it: the value of
	// the file, with no default filled in. A release may hold the files of every course or only of
	// those that changed: a course file of a version that the previous index names keeps its entry.
	Courses []formatv0.Course
}

A Release is what a release of modules gives the build of its index: the index of the release before it, its own packages and course files, its tag and its withdrawals.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL