subscription

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Nov 15, 2026 License: Apache-2.0 Imports: 10 Imported by: 0 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 subscription matches release events to subscription filters.

Filters have the approved watch-file shape (docs/watch-file.md section 2.5). Matching is pure. Input is the minimal event view the future release event (#106) maps to.

Index

Constants

View Source
const (
	PrereleaseInherit = ""        // subscription only: no opinion, keep what the watch admitted
	PrereleaseNone    = "none"    // final versions only
	PrereleaseOnly    = "only"    // pre-releases only
	PrereleaseInclude = "include" // both
)

Pre-release modes, the same words as the watch policy's prerelease key.

View Source
const MaxCooldown = policy.MaxCooldown

MaxCooldown is the longest cooldown, the watch's limit.

Variables

This section is empty.

Functions

This section is empty.

Types

type Decision

type Decision struct {
	Verdict Verdict
	Until   time.Time
}

Decision is the result of Evaluate. Until is set only for Hold.

type Event

type Event struct {
	// Type is the event type; "release.yanked" is not subject to Policy.
	Type string
	// Prerelease reports whether the version is a pre-release.
	Prerelease bool
	// WatchPrerelease is the watch policy's prerelease mode ("none", "only"
	// or "include"); empty means unknown and is not checked.
	WatchPrerelease string
	// CooldownStart is the instant the watch policy's cooldown counts from.
	// The #106 match step must fill it from
	// Release.CooldownFrom(policy.TrustsPublishedAt(kind)). Zero (unknown)
	// fails closed: Evaluate counts from now, holding for the full
	// subscription cooldown.
	CooldownStart time.Time
	// WatchCooldown is the cooldown the watch policy applied.
	WatchCooldown time.Duration
}

Event is what Evaluate needs of the event and of the watch policy's result for it. None of it needs I/O.

type Filter

type Filter struct {
	// Source lists accepted source kinds; empty means any.
	Source []string `json:"source"`
	// Labels must all be present on the input with equal values.
	Labels map[string]string `json:"labels"`
	// Bump lists accepted bumps; empty means any.
	Bump []string `json:"bump"`
	// Package is a path.Match glob on the package name; empty means any.
	// The match is case-sensitive and "*" does not cross "/", so "@angular/*"
	// matches "@angular/core" but not "@angular/core/testing".
	Package string `json:"package"`
	// Type lists accepted event types; empty means any. The watch-file loader
	// fills in [release.published] when the file omits it, so a stored filter
	// normally has it set; this package adds no default.
	Type []string `json:"type"`
}

Filter selects events. Every non-empty field must match. The zero value matches everything. Field names and meaning follow the watch file.

func FromJSON

func FromJSON(b []byte) (Filter, error)

FromJSON decodes a stored filter (subscription.filter_json). Unknown keys are errors, so a typo is not silently a match-everything filter. Empty or "null" input yields the zero (match-all) filter.

func (Filter) Match

func (f Filter) Match(in Input) bool

Match reports whether the filter accepts the input. It is pure.

func (Filter) Validate

func (f Filter) Validate() error

Validate reports a filter that cannot match as intended: a bad glob, or a bump or type outside the values the watch file accepts.

type Input

type Input struct {
	// Source is the source kind of the watch ("npm", "pypi", ...), the
	// "ecosystem" of the PRD.
	Source string `json:"source"`
	// Package is the package name as the source normalised it ("@angular/core").
	Package string `json:"package"`
	// Labels are the labels of the watch that produced the event.
	Labels map[string]string `json:"labels"`
	// Bump is the classifier's result: "major", "minor", "patch",
	// "prerelease" or "other", or empty when unclassified. A filter with a
	// Bump list matches only a value in that list, so "prerelease", "other"
	// and "" never match it.
	Bump string `json:"bump"`
	// Type is the event type: "release.published", "release.yanked" or
	// "release.prerelease".
	Type string `json:"type"`
}

Input is what a filter looks at. It is the minimal shape the future release event (#106) maps to; none of the fields needs I/O to fill.

type Matcher

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

Matcher holds a set of subscriptions and finds those accepting an input. It is immutable after construction and safe for concurrent use.

func NewMatcher

func NewMatcher(subs []Subscription) *Matcher

NewMatcher builds a matcher over subs. Filters are deep-copied, so callers may reuse their slices and maps afterwards.

func (*Matcher) Len

func (m *Matcher) Len() int

Len returns the number of subscriptions.

func (*Matcher) Match

func (m *Matcher) Match(in Input, dst []string) []string

Match appends to dst the ids of the subscriptions accepting in, in the order they were given, and returns the extended slice.

type Policy

type Policy struct {
	// Prerelease is "", "none", "only" or "include". "" and "include"
	// narrow nothing.
	Prerelease string `json:"prerelease"`
	// Cooldown is the minimum age of a version, from the same start as the
	// watch's cooldown: the effective hold is max(watch, subscription).
	Cooldown time.Duration `json:"-"`
}

Policy is the narrowing policy of a subscription (ADR 0014). It can only receive less, later, than the watch policy admitted: Evaluate intersects it with the watch's result, so no value widens. The bump key is not here; it is Filter.Bump.

func PolicyFromJSON

func PolicyFromJSON(b []byte) (Policy, error)

PolicyFromJSON decodes subscription.policy_json. Empty, "null" and "{}" give the zero policy (inherit everything). Unknown keys are errors. The result is clamped.

func (Policy) Clamp

func (p Policy) Clamp() Policy

Clamp returns the policy with useless values cut to the nearest useful one: a negative cooldown becomes 0 and one above MaxCooldown becomes MaxCooldown. It never fails (ADR 0014 decision 2).

func (Policy) Evaluate

func (p Policy) Evaluate(ev Event, now time.Time) Decision

Evaluate decides what a subscription with policy p does with an event at time now: Drop when the pre-release mode of the watch or of the subscription excludes it, Hold until CooldownStart + max(WatchCooldown, p.Cooldown) when that is still ahead, Admit otherwise. The result is always a subset of what the watch admitted: the watch's mode is applied first, a cooldown shorter than the watch's changes nothing, and a yank notice ignores p. It is pure; the match step of #106 calls it once per matching subscription.

func (Policy) MarshalJSON

func (p Policy) MarshalJSON() ([]byte, error)

MarshalJSON writes the stored form, defaults filled.

type Subscription

type Subscription struct {
	ID     string
	Filter Filter
}

Subscription is a filter with the id of the subscription it belongs to.

type Verdict

type Verdict int

Verdict is what a subscription does with an event.

const (
	Admit Verdict = iota // create the delivery, due now
	Hold                 // create the delivery, due at Decision.Until
	Drop                 // create no delivery
)

The verdicts of Evaluate.

func (Verdict) String

func (v Verdict) String() string

Jump to

Keyboard shortcuts

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