Sign in

    mooncakes_index

    Reader for the mooncakes.io registry index that `moon update` keeps under $MOON_HOME: one record per published version, with dependencies, dates and yank state.

    mooncakes
    registry
    index
    Download zip
    Author
    Version
    0.1.0
    License
    Apache-2.0
    Last updated
    3 days ago
    Downloads
    24

    #gaato/mooncakes_index

    Reads the mooncakes.io registry index that moon update keeps at $MOON_HOME/registry/index (default ~/.moon/registry/index): every published version of every module, with its dependencies, dates, yank state and what its moon.mod says about it.

    let index = @fs.read(@fs.index_dir().unwrap())
    for m in index.modules {
    if m.current() is Some(now) {
    println("\{m.name} \{now.version}: \{now.deps.length()} deps")
    }
    }

    • gaato/mooncakes_index is pure and runs on every backend.
      • parse_line reads one line of the index into a VersionRecord.
      • Module::current picks the version that stands for a module now: the last one not yanked, or the last one when all are yanked.
      • compare_versions and release_line order semantic versions and give the line they stay compatible within.
    • gaato/mooncakes_index/fs reads the index directory (native, js, wasm). read counts broken lines in skipped instead of failing, and reports when moon update last fetched.

    Records are read-only; build them for tests with VersionRecord::new, Dep::new and About::new, whose optional arguments let the index grow new fields without breaking you.

    #License

    Apache-2.0

    ParseError

    pub(all) suberror ParseError {
    InvalidJson(message~ : String)
    MissingField(field~ : String)
    } derive(Eq,
    Debug
    )

    A line that is not a version record.

    ParseError::equal

    fn ParseError::equal(ParseError, ParseError) -> Bool

    ParseError::not_equal

    fn ParseError::not_equal(x : ParseError, y : ParseError) -> Bool

    About

    pub struct About {
    description : String?
    repository : String?
    license : String?
    keywords : Array[String]
    yanked_reason : String?
    } derive(Eq,
    Debug
    )

    What a version says about its module, from its moon.mod. Every field is optional in the index.
    impl ToJson for About

    About::equal

    fn About::equal(About, About) -> Bool

    About::new

    fn About::new(description? : String, repository? : String, license? : String, keywords? : Array[String], yanked_reason? : String) -> About

    About::not_equal

    fn About::not_equal(x : About, y : About) -> Bool

    About::to_json

    fn About::to_json(self : About) -> Json

    About::to_repr

    Dep

    pub struct Dep {
    name : String
    version : String?
    imported_as : String?
    path : String?
    } derive(Eq,
    Debug
    )

    A dependency of one published version, as its moon.mod declared it.

    Most are "name": "version". Some name a local path (with or without a version) or import the module under another name (alias in the index).

    Dep::equal

    fn Dep::equal(Dep, Dep) -> Bool

    Dep::new

    fn Dep::new(name : String, version? : String, imported_as? : String, path? : String) -> Dep

    Dep::not_equal

    fn Dep::not_equal(x : Dep, y : Dep) -> Bool

    Dep::to_repr

    Module

    pub struct Module {
    name : String
    versions : Array[VersionRecord]
    } derive(Eq,
    Debug
    )

    A module and every version it has published, in publication order (the order of the lines in the index).

    Module::all_yanked

    fn Module::all_yanked(self : Module) -> Bool

    Whether every version of the module is yanked.

    Module::current

    fn Module::current(self : Module) -> VersionRecord?

    The version that represents the module now: the last version that is not yanked, or the last version when every version is yanked. None only when there are no versions.

    test {
    let m = @mooncakes_index.Module::new("a/b", [
    @mooncakes_index.VersionRecord::new("a/b", version="0.1.0"),
    @mooncakes_index.VersionRecord::new("a/b", version="0.2.0", yanked=true),
    ])
    assert_eq(m.current().map(v => v.version), Some("0.1.0"))
    }

    Module::equal

    fn Module::equal(Module, Module) -> Bool

    Module::new

    fn Module::new(name : String, versions : Array[VersionRecord]) -> Module

    versions must be in publication order.

    Module::not_equal

    fn Module::not_equal(x : Module, y : Module) -> Bool

    Module::to_repr

    VersionRecord

    pub struct VersionRecord {
    name : String
    version : String
    deps : Array[Dep]
    created_at : String?
    yanked : Bool
    deprecated : String?
    about : About
    } derive(Eq,
    Debug
    )

    One line of the index: one published version of one module.

    VersionRecord::equal

    VersionRecord::new

    fn VersionRecord::new(name : String, version~ : String, deps? : Array[Dep], created_at? : String, yanked? : Bool, deprecated? : String, about? : About) -> VersionRecord

    VersionRecord::not_equal

    fn VersionRecord::not_equal(x : VersionRecord, y : VersionRecord) -> Bool

    VersionRecord::to_json

    fn VersionRecord::to_json(self : VersionRecord) -> Json

    compare_names

    fn compare_names(a : String, b : String) -> Int

    Lexicographic order by UTF-16 code unit, which for module names (ASCII) is byte order. String::compare orders by length first, so a sorted listing would not look sorted.

    compare_versions

    fn compare_versions(a : String, b : String) -> Int

    Semantic-version order: numeric major.minor.patch, a pre-release before its release, pre-release identifiers numerically when both are numbers, and build metadata ignored. Versions that are not x.y.z fall back to compare_names.

    is_version

    fn is_version(v : String) -> Bool

    Whether v is a semantic version, so compare_versions orders it as one. Requirements such as * or ^0.1.0 are not.

    owner

    fn owner(name : StringView) -> StringView

    The owner part of a module name: "moonbitlang/x" → "moonbitlang".

    parse_line

    fn parse_line(line : StringView) -> VersionRecord raise ParseError

    Parses one line of the index, or one line of the natural JSONL that VersionRecord::to_json writes; the latter is a subset of the former.

    Fields other than the ones in VersionRecord and About are ignored; empty strings in About read as absent. A dependency is either "name": "version" or an object with any of version, alias and path.

    release_line

    fn release_line(v : String) -> String?

    The release line semantic versioning keeps compatible within: "0.22" for 0.22.5 (a minor bump breaks before 1.0), "2" for 2.3.1.