changes

package
v0.13.0 Latest Latest
Warning

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

Go to latest
Published: Oct 30, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package changes reads the feeds in which registries list the packages that changed since a given point, so a cache or mirror can refresh just those.

Feeds are stateless: the caller keeps the Cursor, starting from Start and passing the one Changes returns to the next call. A caller that acts on the changes moves on to the new cursor only once it has, so a failure leaves the changes to be read again. A Cursor is a plain string and can be stored.

Index

Constants

View Source
const NPMURL = "https://replicate.npmjs.com/registry/_changes"

NPMURL is the change feed of the public npm registry.

View Source
const PackagistURL = "https://packagist.org/metadata/changes.json"

PackagistURL is the metadata change feed of packagist.org.

Variables

This section is empty.

Functions

func PackagistFeedURL

func PackagistFeedURL(apiURL string) string

PackagistFeedURL returns where a Packagist instance at apiURL, such as https://packagist.org, publishes its metadata change feed. Packagist advertises it as "metadata-changes-url" in its packages.json.

Types

type Changes

type Changes struct {
	// Names are the packages that changed, as the registry names them.
	Names []string
	// All is set when the feed can't say what changed since the cursor, so
	// every package has to be treated as changed.
	All bool
}

Changes is what one read of a feed found.

type Cursor

type Cursor string

Cursor is a position in a feed, as the feed's registry gives it. Treat it as opaque.

type Feed

type Feed interface {
	// Ecosystem is the ecosystem the changed names belong to.
	Ecosystem() string
	// Start returns the feed's current position, from which Changes reports
	// what changes next.
	Start(ctx context.Context) (Cursor, error)
	// Changes returns what changed after cursor, and the cursor to read on
	// from. On error the returned cursor is the one passed in.
	Changes(ctx context.Context, cursor Cursor) (Changes, Cursor, error)
}

Feed is one registry's change feed.

type NPM

type NPM struct {
	// contains filtered or unexported fields
}

NPM reads the npm registry's CouchDB-style changes feed at replicate.npmjs.com.

Its cursor is a sequence, which npm asks followers to treat as opaque; the database document at the feed's parent URL, with its trailing slash (without it the URL is 404), gives the current one as update_seq. A page holds at most 10000 changes (1000 when no limit is given), and Changes reads up to ten pages. Each result's id is a package name; design documents are left out.

func NewNPM

func NewNPM(opts ...Option) *NPM

NewNPM returns the feed of the public npm registry, or the one set with WithURL.

func (*NPM) Changes

func (f *NPM) Changes(ctx context.Context, cursor Cursor) (Changes, Cursor, error)

Changes reads pages until one is not full, or up to ten. When a later page fails, it returns what the earlier ones found with the cursor after them, and no error: the next call goes on from there.

func (*NPM) Ecosystem

func (*NPM) Ecosystem() string

func (*NPM) Start

func (f *NPM) Start(ctx context.Context) (Cursor, error)

type Option

type Option func(*options)

Option configures a feed.

func WithClient

func WithClient(c *client.Client) Option

WithClient sets the client a feed makes its requests with. The default is client.DefaultClient().

func WithURL

func WithURL(u string) Option

WithURL sets the URL of the feed, for a registry other than the public one.

type Packagist

type Packagist struct {
	// contains filtered or unexported fields
}

Packagist reads Packagist's metadata change feed (https://packagist.org/apidoc#track-package-updates).

Its cursor is a timestamp in units of 1/10000 s. Asked without one the feed answers 400 with the current timestamp; asked with one older than its 24 hours of history it answers with a single "resync" action, reported as Changes.All. Each update names the metadata file that changed, "vendor/package" or "vendor/package~dev" for its dev versions; a delete names the package and is reported as both.

func NewPackagist

func NewPackagist(opts ...Option) *Packagist

NewPackagist returns the feed of packagist.org, or of the instance set with WithURL (see PackagistFeedURL).

func (*Packagist) Changes

func (f *Packagist) Changes(ctx context.Context, cursor Cursor) (Changes, Cursor, error)

func (*Packagist) Ecosystem

func (*Packagist) Ecosystem() string

func (*Packagist) Start

func (f *Packagist) Start(ctx context.Context) (Cursor, error)

Jump to

Keyboard shortcuts

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