Documentation
¶
Overview ¶
Package pub holds the naming rules, the request grammar, the package documents and the archive reader of the Dart and Flutter pub format: the hosted pub repository spec v2 served by pub.dev, spoken by "dart pub" and "flutter pub".
Index ¶
- Constants
- Variables
- func ArchiveName(name, version string) string
- func ArchivePath(name, version string) string
- func CheckDoc(r io.Reader, name string) error
- func CompareVersions(a, b string) int
- func IsPrerelease(v string) bool
- func IsReserved(name string) bool
- func MarshalVersion(v *Version, link Link) (json.RawMessage, error)
- func PackagePath(name string) string
- func ParseArchiveName(file string) (string, string, bool)
- func ValidName(s string) bool
- func ValidVersion(v string) bool
- type Doc
- type Kind
- type Link
- type Package
- type Path
- type Version
Constants ¶
const ( // MaxArchiveBytes bounds the compressed archive of one release (pub.dev's limit). MaxArchiveBytes = 100 << 20 // MaxUncompressedBytes bounds the total size of the files of an archive. MaxUncompressedBytes = 256 << 20 // MaxPubspecBytes bounds pubspec.yaml (pub.dev's limit). MaxPubspecBytes = 128 << 10 // MaxPubspecJSONBytes bounds the JSON a pubspec expands to; YAML aliases can // make it far larger than the source. MaxPubspecJSONBytes = 1 << 20 )
Limits on what ReadArchive accepts from an untrusted upload.
const ( // MaxDocBytes bounds a package document read from an upstream. Packages with // hundreds of releases carry a full pubspec each, so it is generous. MaxDocBytes = 64 << 20 // MaxVersions bounds the releases of one package document. MaxVersions = 50_000 // ContentType is the media type of the package documents and of the Accept // header the pub client sends for them. ContentType = "application/vnd.pub.v2+json" )
const ( // MaxNameLen is the longest package name (pub.dev's limit). MaxNameLen = 64 // MaxVersionLen is the longest package version. MaxVersionLen = 128 // ArchiveSuffix ends every package archive file name. ArchiveSuffix = ".tar.gz" )
const ( // PackagesDir is the directory of the package documents. PackagesDir = "api/packages/" // ArchivesDir is the directory of the package archives. ArchivesDir = "api/archives/" // NewPath, UploadPath and FinishPath are the three publish endpoints. NewPath = "api/packages/versions/new" UploadPath = "api/packages/versions/newUpload" FinishPath = "api/packages/versions/newUploadFinish" )
Path route segments shared by the handlers, the proxy and the group.
Variables ¶
var ErrInvalid = errors.New("invalid package")
ErrInvalid marks an archive that is not a valid package; its message says what is wrong and is meant for the publisher.
var ErrInvalidDoc = errors.New("invalid pub package document")
ErrInvalidDoc marks a document that is not a package document of the spec.
Functions ¶
func ArchiveName ¶
ArchiveName is the archive file name of a package version.
func ArchivePath ¶
ArchivePath is the path of a package archive.
func CompareVersions ¶
CompareVersions orders valid versions by precedence, the way pub_semver does: the numbers, then a pre-release below its release, then the build part (a version with a build part is above the one without). The result is 0 only for identical numbers, pre-release and build.
func IsPrerelease ¶
IsPrerelease reports whether the valid version v has a pre-release part.
func IsReserved ¶
IsReserved reports whether name is a Dart reserved word.
func MarshalVersion ¶
func MarshalVersion(v *Version, link Link) (json.RawMessage, error)
MarshalVersion renders one release entry with its archive URL replaced by link(v).
func PackagePath ¶
PackagePath is the path of a package document.
func ParseArchiveName ¶
ParseArchiveName splits "name-version.tar.gz" and reports whether both parts are valid.
func ValidName ¶
ValidName reports whether s is a valid package name: 1 to MaxNameLen lower-case letters, digits and underscores, not starting with a digit. The shape keeps every name safe in a URL path and a file name, and a name never holds "-", so an archive file name splits unambiguously.
func ValidVersion ¶
ValidVersion reports whether v is a package version (pub_semver).
Types ¶
type Doc ¶
Doc is the package document of the spec: GET /api/packages/<name>.
func Merge ¶
Merge combines the documents of one package from several repositories. A version listed by more than one document is taken from the first; the top-level fields besides the releases come from the first document; the releases are ordered by precedence.
func ParseDoc ¶
ParseDoc reads a package document. Entries without a valid version or without an archive URL are dropped, and the first entry of a repeated version wins.
type Kind ¶
type Kind uint8
Kind says what a request path of a pub repository asks for.
const ( // KindPackage is api/packages/<name>: the version list of a package. KindPackage Kind = iota + 1 // KindVersion is api/packages/<name>/versions/<version>. KindVersion // KindArchive is api/archives/<name>-<version>.tar.gz. KindArchive // KindNew is api/packages/versions/new: the start of a publish. KindNew // KindUpload is api/packages/versions/newUpload: the archive upload. KindUpload // KindFinish is api/packages/versions/newUploadFinish: the end of a publish. KindFinish )
The kinds of ParsePath.
type Package ¶
type Package struct {
Name string
Version string
// Pubspec is pubspec.yaml as JSON.
Pubspec json.RawMessage
}
Package is what a package archive says about itself.
func ParsePubspec ¶
ParsePubspec reads pubspec.yaml and checks the identity it states. The YAML is untrusted: it is size-bounded, its nesting is bounded, only the first document counts, and the JSON it expands to is bounded too.
func ReadArchive ¶
ReadArchive parses the gzipped tar archive of a release and checks it: the pubspec.yaml at its root (a valid package name that is not a reserved word, and a valid version) and the shape of the tar stream. An error wraps ErrInvalid when the archive is at fault, and is an I/O error otherwise.
type Version ¶
type Version struct {
Version string
ArchiveURL string
// SHA256 is the lower-case hex digest of the archive, "" when none is listed.
SHA256 string
// Published is when the release was published, zero when the document has no time.
Published time.Time
// Retracted marks a release its publisher withdrew.
Retracted bool
// contains filtered or unexported fields
}
Version is one release of a package document. Fields the spec does not name (and the ones a repository adds) are kept as they came, so a proxy hands a client everything the upstream said except the archive location.
func Latest ¶
Latest returns the release a client resolves "any" to: the highest stable release that is not retracted, else the highest pre-release that is not retracted, else the highest release. nil for an empty list.
func NewVersion ¶
func NewVersion(version, archiveURL, sha256 string, published time.Time, pubspec json.RawMessage) *Version
NewVersion builds the document entry of a release a repository holds. pubspec is the release's pubspec as JSON.
func (*Version) Pubspec ¶
func (v *Version) Pubspec() json.RawMessage
Pubspec is the pubspec of the release as JSON, nil when the entry has none.