Documentation
¶
Overview ¶
Package diff compares a target's known version set with the versions a source just fetched and reports what changed (architecture.md §3.4): new versions, including backports such as 1.9.4 released after 2.0.0, yank and un-yank transitions, and versions that stopped being listed upstream.
Compute is pure: it takes the known set and the fetched list and returns the changes and the rows to write. Result.Classify classifies the same changes under another scheme, because the scheme is chosen per watch while the known set belongs to the target. Apply runs one check inside the store's unit of work (store.Tx): it reads the known set and the target's watches, writes the known set, marks first-run baselines, and returns what each watch should hear about. The caller (fetch loop) commits it in the same transaction as the events and the target's fetch state.
Rules (ADR 0010):
- The known set is keyed by the raw upstream string (ADR 0007): "1.0" and "1.0.0" are two versions even when they compare equal. It is scheme-neutral: Normalized and Prerelease are written with the source kind's default scheme, never with a watch's override.
- Raw strings are used as the source gives them. Blank strings, strings with leading or trailing white space and repeated strings are skipped (normalisation is the source's job).
- The known set never shrinks. A version missing from a fetch with at least one usable entry is marked removed (RemovedAt) and reported once as KindRemoved; it emits nothing in Phase 0. If it is listed again it is reported as KindReturned, never as new. This assumes Source.List returns the complete list.
- A fetch without usable entries changes nothing: it is far more often a registry glitch than every version being deleted.
- Running the same check twice gives no changes the second time.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Change ¶
type Change struct {
Kind Kind
// Raw is the upstream version string, the key of the known set.
Raw string
// Version is Raw parsed with the classifying scheme, or with the
// lexical scheme when that scheme rejects it.
Version version.Version
// Upstream is the fetched entry. It is the zero value for KindRemoved.
Upstream source.Version
// Prerelease is, for KindNew, the upstream flag when the source gives
// one, otherwise the classifying scheme's opinion. For known versions it
// is the recorded value.
Prerelease bool
// Yanked is the version's yank state after this check.
Yanked bool
// Previous is the raw string of the version this one is compared with,
// or "" when there is none (ADR 0007 and ADR 0010):
// - a known version of equal precedence ("1.2.0" for "v1.2.0"), or an
// earlier entry of the same fetch with equal precedence; then Bump is
// "other";
// - otherwise the greatest version strictly below Version among the
// known and new versions parsed by the same scheme as Version.
Previous string
// Bump classifies Previous → Version; "" when Previous is "".
Bump version.Bump
// Backport is true when a known, not removed version is greater than
// Version, both parsed by the classifying scheme (1.9.4 released after
// 2.0.0).
Backport bool
// contains filtered or unexported fields
}
Change is one difference between the known set and the fetched versions.
type Input ¶
type Input struct {
TargetID string
// Fetched is what the source returned. NotModified means the known set
// is current: nothing is compared, but baselines are still marked.
Fetched source.Result
// Scheme is the source kind's default scheme, normally
// schemes.Select(kind, "", logger). It fills Normalized and Prerelease
// of new rows, so the known set never depends on a watch's override.
Scheme version.Scheme
// SchemeFor returns the scheme of a watch, normally
// schemes.Select(kind, override, logger). nil means every watch uses
// Scheme. Within one target, schemes are told apart by Name (Select
// gives one configuration per name and source kind).
SchemeFor func(store.Watch) (version.Scheme, error)
// Now stamps FirstSeenAt and RemovedAt.
Now time.Time
// Logger receives removals, returns, baselines and the aggregated
// warnings about unparseable or skipped versions. nil discards them.
Logger *slog.Logger
}
Input is one successful fetch of a target.
type Kind ¶
type Kind string
Kind is the kind of a change.
const ( // KindNew is a version that is not in the known set. KindNew Kind = "new" // KindYanked is a known version that upstream now marks yanked. KindYanked Kind = "yanked" // KindUnyanked is a known yanked version that upstream no longer marks yanked. KindUnyanked Kind = "unyanked" // KindRemoved is a known version that upstream stopped listing. Logged only. KindRemoved Kind = "removed" // KindReturned is a removed version that upstream lists again. Logged only. KindReturned Kind = "returned" )
Change kinds, in the order Compute reports them.
type Outcome ¶
type Outcome struct {
// Result is the diff classified with the default scheme.
Result
// Watches lists every watch on the target, ordered by ID.
Watches []WatchChanges
}
Outcome is what Apply wrote and what each watch should hear about.
func Apply ¶
Apply runs one check of in.TargetID inside tx: it reads the known set and the watches, computes the changes, writes new and updated versions, and marks the baseline of every watch that had none. It returns the per-watch changes for the policy engine; the caller writes events, deliveries and the fetch state in the same transaction and commits. On error the caller must roll back (store.Store.InTx does when fn returns the error).
When the known set was empty before the check and the fetch adds more than one version, the check is a baseline for every watch, even one whose baseline is already done: a target first fetched empty (a glitch, or a package not published yet) must not replay its whole history later. A single first version is reported.
type Result ¶
type Result struct {
// Changes, classified with the default scheme, grouped by kind (new,
// yanked, unyanked, removed, returned) and in ascending version order
// within a kind.
Changes []Change
// Add are the new rows of the known set, in the order of Changes.
Add []store.Version
// Update are the known rows whose Yanked or RemovedAt changed: listed
// ones in fetch order, then removed ones in known-set order.
Update []store.Version
// Fallbacks are the raw strings of new versions that the default scheme
// could not parse and that were ordered lexically instead.
Fallbacks []string
// Usable counts the fetched entries that were compared; Skipped those
// that were ignored (blank, surrounded by white space, or repeated).
Usable, Skipped int
// contains filtered or unexported fields
}
Result is the outcome of Compute.
func Compute ¶
func Compute(targetID string, known []store.Version, fetched []source.Version, def version.Scheme, now time.Time) Result
Compute compares known, the known set of targetID, with fetched, the versions a source listed. def is the source kind's default scheme: it classifies Changes and fills Normalized and Prerelease of the new rows. now stamps FirstSeenAt and RemovedAt. Compute does no I/O and does not modify its inputs.
func (Result) Classify ¶
Classify returns the changes of r classified with scheme: every change's Version, and for new versions Prerelease, Previous, Bump and Backport, in scheme order. It also returns the new versions that scheme parsed with the lexical fallback. Removed, yanked, unyanked and returned changes are the same for every scheme. r is not modified.
type WatchChanges ¶
type WatchChanges struct {
// Watch is the watch as it was before the check.
Watch store.Watch
// Scheme is the name of the scheme that classified Changes; "" for a
// baseline.
Scheme string
// Baseline is true when this check recorded a baseline for the watch
// (its first check, or the first non-empty fill of an empty known set):
// Changes is empty.
Baseline bool
// Changes are the changes whose Kind.Notifies(), classified with the
// watch's scheme, in that scheme's order. Each watch has its own slice.
Changes []Change
}
WatchChanges is what one watch gets from a check.