Skip to content Search Apps Documentation Source Content Run Reset Eval Playground File Folder Download Copy Actions State String Boolean Number Struct Map Slice Pointer Function Closure Reference Nil Package Type Interface Unknown

v0 source pure

Readme View source

gno.land/p/moul/releases/v0

A project's changelog, and the answer every version of it needs: am I the latest, and if not, what am I still allowed to do? A revival of the quarantined p/demo/releases from gnolang/gno, extended with a status per version, a pause policy, and the banner an old version prepends to its page.

The state lives in r/moul/releases, which is also the live demo: one Project per name, each served as a stage homepage.

Status

status stored writes banner
📝 draft yes allowed "a draft"
🧪 prerelease yes allowed "a prerelease"
✅ supported yes allowed "still supported, the latest is ..."
🌟 latest computed allowed none
⚠️ deprecated yes allowed until its sunset height, read-only from it "deprecated, read-only from block N"
🚫 yanked yes, final paused "yanked, it accepts nothing"
🔴 vulnerable yes, can only be yanked paused "vulnerable, it accepts nothing"

Latest is the most recently added Supported release, computed on read, so shipping v2 never means rewriting v1. Severity() orders statuses by how much a reader should worry, Latest 0 to Vulnerable 5.

Policy: status and height in, pause state out

Policy(release, height) returns a p/moul/pausable State. It is a pure function of the stored status and the block height, so a deprecated version goes read-only at its sunset block with no transaction from anyone. An unknown status fails closed (paused); an unlisted path is running, because a registry that paused what it had not heard of would let a typo take a realm down.

API

p, _ := releases.NewProject("config", "moul's shared settings")
p.Add("v0", "gno.land/r/moul/config/v0", "", "first cut", releases.Supported, height)
p.Add("v1", "gno.land/r/moul/config/v1", "", "- pause levels", releases.Supported, height)
p.Deprecate("v0", "use v1", height+100000) // read-only from that block
p.Yank("v0", "leaks keys")                  // final

p.Latest()                    // Release{Version: "v1", ...}, true
p.ByVersion("v0"), p.ByPath("gno.land/r/moul/config/v0")
p.State(path, height)         // pausable.State
p.AssertWritable(path, height)
p.Banner(path, height, stageURL)  // "" for the latest
p.RenderStage(height, linkFn), p.RenderRelease("v0", height)

Lookups return a Release by value. The original ByVersion returned a pointer to a range-loop copy, which looked like a handle on the stored release and was not; there is no pointer here to get wrong. Storage is two p/nt/bptree indexes (version, package path) plus the insertion order.

Every owner-typed string (description, notes, reason, URL) is escaped where the markdown is built, because the registry is public and anyone can open a project in it.

Known limit

A version already on chain is immutable: it cannot gain the import. It can only be listed and labelled here, and its stage page and the newer versions say it is old. Only versions written after this package can show the banner and pause themselves.


Part of moul/gno-contracts — moul's versioned gno.land contracts. See the repository for the full catalog, build/test tooling, and usage.

Dependency graph:

gno.land/p/moul/releases/v0 dependency graph

⚠️ Disclaimer: provided as-is, without warranty; not security-audited. Full disclaimer: DISCLAIMER.

Constants 2

const Draft, Prerelease, Supported, Latest, Deprecated, Yanked, Vulnerable

 1const (
 2	// Draft is listed but not announced: the code may not be on chain yet.
 3	Draft Status = iota
 4	// Prerelease is on chain and usable, with no promise attached.
 5	Prerelease
 6	// Supported is a release its owner still answers for.
 7	Supported
 8	// Latest is the newest Supported release. Computed, never stored.
 9	Latest
10	// Deprecated still works, says so, and goes read-only at its sunset.
11	Deprecated
12	// Yanked was withdrawn: it stays listed, because a version that existed
13	// cannot un-exist, and every write is refused.
14	Yanked
15	// Vulnerable has a known flaw: it stays listed and everything is refused.
16	Vulnerable
17)
source

Variables 1

var ErrInvalidName, ErrInvalidVersion, ErrInvalidPkgPath, ErrInvalidText, ErrInvalidStatus, ErrInvalidSunset, ErrVersionExists, ErrPathExists, ErrNotFound, ErrFinal, ErrVulnerableIsFinal

 1var (
 2	ErrInvalidName       = errors.New("releases: invalid project name")
 3	ErrInvalidVersion    = errors.New("releases: invalid version")
 4	ErrInvalidPkgPath    = errors.New("releases: invalid package path")
 5	ErrInvalidText       = errors.New("releases: text too long or not printable")
 6	ErrInvalidStatus     = errors.New("releases: status cannot be stored")
 7	ErrInvalidSunset     = errors.New("releases: sunset height must not be negative")
 8	ErrVersionExists     = errors.New("releases: version already released")
 9	ErrPathExists        = errors.New("releases: package path already listed")
10	ErrNotFound          = errors.New("releases: no such version")
11	ErrFinal             = errors.New("releases: a yanked release cannot change status")
12	ErrVulnerableIsFinal = errors.New("releases: a vulnerable release can only be yanked")
13)
source

Functions 6

func Policy

1func Policy(r Release, height int64) pausable.State
source

Policy is what a release's status means for the realm that is that release, at block height `height`, as a p/moul/pausable State:

Example
1Draft, Prerelease, Supported, Latest  running
2Deprecated                            running until its sunset, read-only from it
3Yanked, Vulnerable                    paused

It is a pure function of the stored status and the height, so a deprecated version goes read-only at its sunset block with no transaction from anyone. An unknown status fails closed, like pausable.MustParse.

func ValidName

1func ValidName(s string) bool
source

ValidName reports whether s can name a project: a lower-case letter, then letters, digits and dashes. It is the realm's render path, so it is kept to characters that need no escaping anywhere.

func ValidPkgPath

1func ValidPkgPath(s string) bool
source

ValidPkgPath reports whether s looks like a gno.land package path. It does not ask the chain whether the package exists: a Draft is listed before its code is.

func ValidVersion

1func ValidVersion(s string) bool
source

ValidVersion reports whether s can be a version. Not semver-enforcing, for the reason p/moul/forge gives: gno.land versions as v0, v1 with no minor or patch, and a registry refusing those would refuse its own ecosystem.

func NewProject

1func NewProject(name, description string) (*Project, error)
source

NewProject opens an empty changelog.

func ParseStatus

1func ParseStatus(raw string) (Status, bool)
source

ParseStatus reads a status word, case-insensitively. ok is false for anything else, "latest" included, since a stored Latest would lie the moment a newer release ships.

Types 3

type Project

struct
1type Project struct {
2	name        string
3	description string
4	byVersion   *bptree.BPTree // version -> *Release
5	byPath      *bptree.BPTree // package path -> version
6	order       []string       // versions, in the order they were added
7}
source

Project is a changelog: the releases of one thing, in the order they were listed, each findable by version and by package path.

It holds no owner. Who may write is the storing realm's question, and the library stays usable by a realm with one owner, a DAO, or none.

Methods on Project

func Add

method on Project
1func (p *Project) Add(version, pkgPath, url, notes string, status Status, height int64) error
source

Add lists a release. Version and package path are both keys and neither can be listed twice: a version that pointed at different code later would be a lie told to everyone who pinned it.

func AssertWritable

method on Project
1func (p *Project) AssertWritable(pkgPath string, height int64)
source

AssertWritable aborts unless the release at pkgPath may still be written to at this height. A version puts it at the top of every state-changing function.

func Banner

method on Project
1func (p *Project) Banner(pkgPath string, height int64, stage string) string
source

Banner is the markdown a release prepends to its own Render, or "" when it is the Latest or not listed at all. It ends in a blank line, so

Example
1return reg.Banner(self) + body

is the whole integration. stage is the link to the project's stage page, or "" to leave it out.

func ByPath

method on Project
1func (p *Project) ByPath(pkgPath string) (Release, bool)
source

ByPath returns a copy of the release published at pkgPath.

func ByVersion

method on Project
1func (p *Project) ByVersion(version string) (Release, bool)
source

ByVersion returns a copy of the release listed under version.

func Deprecate

method on Project
1func (p *Project) Deprecate(version, reason string, sunset int64) error
source

Deprecate marks a release deprecated. It keeps working, with a banner, until block height sunset, and is read-only from then on. sunset 0 means never.

func IsLatest

method on Project
1func (p *Project) IsLatest(pkgPath string) bool
source

IsLatest reports whether pkgPath is this project's Latest.

func Latest

method on Project
1func (p *Project) Latest() (Release, bool)
source

Latest is the most recently added Supported release. Order of addition, not version order, decides: versions here need not be semver, and an owner who lists v2 before backfilling v1 meant v2.

func Name

method on Project
1func (p *Project) Name() string
source

func Releases

method on Project
1func (p *Project) Releases() []Release
source

Releases returns copies of every release, newest first.

func RenderRelease

method on Project
1func (p *Project) RenderRelease(version string, height int64) string
source

RenderRelease is one version's page: its status, what that means for writes at this height, where it lives, and its notes.

func RenderStage

method on Project
1func (p *Project) RenderStage(height int64, link func(version string) string) string
source

RenderStage is the project's homepage: the latest release up front, every version with its status, then the changelog, newest first. link turns a version into the URL of its RenderRelease page, or is nil for none.

func SetDescription

method on Project
1func (p *Project) SetDescription(d string) error
source

SetDescription replaces the one-line description.

func SetStatus

method on Project
1func (p *Project) SetStatus(version string, s Status, reason string) error
source

SetStatus moves a release to any storable status, with the reason readers will see. A yanked release is final, and a vulnerable one can only be yanked: neither can be made safe again, because its code cannot change. Setting Deprecated this way clears any sunset; Deprecate sets one.

func SetSuccessor

method on Project
1func (p *Project) SetSuccessor(version, successor string) error
source

SetSuccessor points readers of version at successor instead of at Latest, for a line that forked. An empty successor clears it.

func Size

method on Project
1func (p *Project) Size() int
source

func State

method on Project
1func (p *Project) State(pkgPath string, height int64) pausable.State
source

State is Policy for the release published at pkgPath. A path this project does not list is running: being unlisted is not a reason to stop, and a registry that paused whatever it had not heard of would let a typo take a realm down.

func StatusOf

method on Project
1func (p *Project) StatusOf(r Release) Status
source

StatusOf is the status a reader sees: the stored one, with Supported promoted to Latest for the one release it applies to.

func Yank

method on Project
1func (p *Project) Yank(version, reason string) error
source

Yank withdraws a release. It stays listed; every write to it is refused.

type Release

struct
 1type Release struct {
 2	Version    string // "v1", the key inside its project
 3	PkgPath    string // "gno.land/r/moul/config/v1", unique inside its project
 4	URL        string // optional link; the realm itself when empty
 5	Notes      string // the changelog entry, one item per line
 6	Status     Status // the stored status; Latest is never stored
 7	Reason     string // why the status is what it is, shown in banners
 8	ReleasedAt int64  // block height at which it was listed
 9	Sunset     int64  // Deprecated only: the height it goes read-only, 0 for never
10	Successor  string // optional version to send readers to instead of Latest
11}
source

Release is one version of a project: the package path it was published at, what changed, and where it stands.

Project hands Releases out by value, so a caller holding one cannot change the registry by writing to it. The quarantined p/demo/releases this package revives returned a pointer to a range-loop copy from ByVersion, which looked like a handle on the stored release and was not; there is no pointer here to get wrong.

Methods on Release

type Status

ident
1type Status int
source

Status is where a release stands. It is stored on the release, except Latest, which is computed: the newest Supported release of a project is its Latest, and storing that would mean rewriting the previous one every time a new version ships.

Methods on Status

func Emoji

method on Status
1func (s Status) Emoji() string
source

Emoji is the one-glyph form a table shows in front of the word.

func Label

method on Status
1func (s Status) Label() string
source

Label is the emoji and the word together, "⚠️ deprecated".

func Severity

method on Status
1func (s Status) Severity() int
source

Severity is 0 for Latest and grows with how much a reader should worry: Supported 1, Draft and Prerelease 2, Deprecated 3, Yanked 4, Vulnerable 5.

func Storable

method on Status
1func (s Status) Storable() bool
source

Storable reports whether an owner may set this status. Latest is refused, since it is derived from the others.

func String

method on Status
1func (s Status) String() string
source

String is the lower-case word, the same one ParseStatus reads back.

Dependencies

Source Files 7