Documentation
¶
Index ¶
- Constants
- Variables
- func CheckAttachmentContentType(ct string, ok bool) error
- func CheckAttachmentLength(declared int64, ok bool, actual int64) error
- func ComparePrerelease(a, b string) int
- func ComputeIntegrity(r io.Reader) (string, string, string, int64, error)
- func HideVersions(doc []byte, hide func(version string, published time.Time) bool) ([]byte, error)
- func MergePackuments(docs [][]byte) ([]byte, error)
- func PublishedAt(doc []byte, version string) (time.Time, bool, error)
- func RewriteTarballs(doc []byte, pkg, tarballBase string) ([]byte, error)
- func TarballFileOf(tarballURL string) string
- func ValidatePackageName(name string) error
- func ValidateSemver(v string) error
- func VerifyDist(r io.Reader, d Dist) (bool, error)
- func VersionManifest(doc []byte, versionOrTag string) ([]byte, bool, error)
- func WantsAbbreviated(accept string) bool
- type Dist
- type Path
- type PathKind
- type Release
- type VersionTime
Constants ¶
const AbbreviatedContentType = "application/vnd.npm.install-v1+json"
AbbreviatedContentType is the media type of the install-v1 (abbreviated) packument.
const AttachmentContentType = "application/octet-stream"
AttachmentContentType is the only content type npm publishes tarballs with.
const UpstreamAccept = AbbreviatedContentType + "; q=1.0, application/json; q=0.8, */*"
UpstreamAccept is the Accept header OpenArtifact sends upstream for an abbreviated packument (the value npm itself sends).
Variables ¶
var ErrAllVersionsHidden = errors.New("every version of the packument is hidden")
ErrAllVersionsHidden is returned by HideVersions when it would hide every version of a packument that had some.
var ErrIntegrityMismatch = errors.New("npm tarball integrity mismatch")
ErrIntegrityMismatch reports tarball bytes that do not match the digest the packument advertises.
var ErrInvalidAttachment = errors.New("invalid npm attachment")
ErrInvalidAttachment reports a malformed _attachments entry of a publish body.
var ErrInvalidPackageName = errors.New("invalid npm package name")
var ErrInvalidPath = errors.New("not an npm registry path")
ErrInvalidPath reports a path that is not a registry packument, version or tarball path.
var ErrInvalidSemver = errors.New("invalid semver")
var ErrNotObject = errors.New("npm packument is not a JSON object")
ErrNotObject reports a packument that is not a JSON object.
Functions ¶
func CheckAttachmentContentType ¶ added in v0.6.0
CheckAttachmentContentType validates the content_type of an attachment; ok is false when the field was absent or not a string.
func CheckAttachmentLength ¶ added in v0.6.0
CheckAttachmentLength validates that the declared attachment length matches the number of decoded bytes; ok is false when the field was absent or invalid.
func ComparePrerelease ¶ added in v0.15.0
ComparePrerelease orders two semver prerelease identifiers (semver 2.0.0, section 11): numeric identifiers numerically and below alphanumeric ones, alphanumeric ones lexically in ASCII order.
func HideVersions ¶ added in v0.16.0
HideVersions removes from a full packument every version hide reports true for. hide is asked about every version with its time entry (the zero time when the entry is absent or not an RFC 3339 time, so a rule that needs no date still applies): the version and its time entry go ("created" and "modified" stay), and a dist-tag that pointed at a removed version moves ("latest": to the highest remaining version that is not a prerelease, or the highest remaining one when only prereleases are left) or goes (every other tag). doc is returned as is when nothing is hidden; ErrAllVersionsHidden when nothing would be left of a packument that had versions.
func MergePackuments ¶ added in v0.6.0
MergePackuments merges packuments of the same package in member priority order: versions are the union (the first member that has a version wins), each dist-tag comes from the first member that has it, time entries and every other top-level field likewise come from the first member that has them. A single document is returned unchanged.
func PublishedAt ¶ added in v0.16.0
PublishedAt is the packument's time entry of version; ok is false when the packument has none for it or it is not an RFC 3339 time.
func RewriteTarballs ¶ added in v0.6.0
RewriteTarballs returns doc with every version's dist.tarball replaced by tarballBase + "/" + pkg + "/-/" + <filename of the old URL>, where tarballBase is "<server>/repos/<repo>". Integrity fields are untouched.
func TarballFileOf ¶ added in v0.6.0
TarballFileOf returns the filename of an upstream dist.tarball URL.
func ValidatePackageName ¶
func ValidateSemver ¶
func VerifyDist ¶ added in v0.6.0
VerifyDist hashes r and compares it with the digest in dist: dist.integrity (strongest listed SRI algorithm, any of its digests may match) or, when that is absent, dist.shasum. verified is false when dist advertises neither, in which case nothing was compared. A mismatch is ErrIntegrityMismatch.
func VersionManifest ¶ added in v0.6.0
VersionManifest extracts one version's manifest from a packument; versionOrTag is an exact version or a dist-tag.
func WantsAbbreviated ¶ added in v0.6.0
WantsAbbreviated reports whether the Accept header asks for the install-v1 (abbreviated) packument.
Types ¶
type Dist ¶ added in v0.6.0
type Dist struct {
Tarball string `json:"tarball"`
Integrity string `json:"integrity"`
Shasum string `json:"shasum"`
}
Dist is the dist object of one version.
type Path ¶ added in v0.6.0
type Path struct {
Kind PathKind
// Package is the decoded package name ("lodash", "@scope/name").
Package string
// Version is the version or dist-tag of a KindVersion path.
Version string
// File is the tarball filename of a KindTarball path.
File string
}
Path is a parsed repository-relative registry path.
type Release ¶ added in v0.16.0
type Release struct {
Version string
// Published is the packument's time[Version]; zero when it is absent or
// not an RFC 3339 time.
Published time.Time
Dist Dist
}
Release is one version of a packument as a tarball lookup finds it.
func FindRelease ¶ added in v0.16.0
FindRelease locates the version whose dist.tarball has the given filename and returns that version's upstream tarball URL, integrity and shasum and its publish time. The version named by the conventional filename is tried first.
type VersionTime ¶ added in v0.16.0
type VersionTime struct {
Version string
// Published is the zero time when the packument has no RFC 3339 time entry for it.
Published time.Time
}
VersionTime is one version of a packument with its time entry.
func Versions ¶ added in v0.16.0
func Versions(doc []byte) ([]VersionTime, error)
Versions lists the versions of a full packument with their time entries, in no particular order.