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.1
    License
    Apache-2.0
    Last updated
    yesterday
    Downloads
    88

    #gaato/mooncakes_index

    Read the mooncakes.io registry index that moon update keeps on your machine. It holds every published version of every module, with its dependencies, publication date, yank state and what its moon.mod says about it. Use it for release reports, dependency analysis, or test fixtures that behave like the registry. For dependency trees and rankings built on these records, use gaato/mooncakes-graph.

    Unofficial, and not affiliated with mooncakes.io or the MoonBit team.

    #Install

    moon add gaato/mooncakes_index

    #Pick the current version of a module

    Each line of the index is one published version, in publication order. Parse the lines of a module and ask which version stands for it now:

    ///|
    test "the current version of a module" {
    let first =
    #|{"name":"a/core","version":"0.1.0","deps":{"moonbitlang/x":"0.4.0"},"yanked":false}
    let second =
    #|{"name":"a/core","version":"0.2.0","deps":{},"yanked":true,"yanked_reason":"broken build"}
    let versions = [
    @mooncakes_index.parse_line(first),
    @mooncakes_index.parse_line(second),
    ]
    let module_ = @mooncakes_index.Module::new("a/core", versions)
    let now = module_.current().unwrap()
    assert_eq(now.version, "0.1.0")
    assert_eq(now.deps.length(), 1)
    }

    Module::current() returns the last version that is not yanked, in publication order, so a yanked 0.2.0 leaves 0.1.0 current. When every version is yanked, it returns the last one. For an empty history, it returns None. Publication order is not semantic-version order: use compare_versions and release_line (the range a version stays compatible within) for questions about version numbers.

    #Read the index from disk

    Run moon update first. The index lives at $MOON_HOME/registry/index (by default ~/.moon/registry/index). Import gaato/mooncakes_index/fs, then @fs.read(@fs.index_dir().unwrap()) returns every module, sorted by name.

    • skipped counts lines that could not be parsed. They are skipped rather than failing the whole read.
    • fetched_at is when moon update last fetched, when known.
    • read raises NotFound(dir~) when there is no index, and Unreadable(path~, message~) when a file cannot be read.

    #Packages

    PackageWhat it isTargets
    gaato/mooncakes_indexRecords and versions. Pure: no I/O.Every backend
    gaato/mooncakes_index/fsReads the index directorynative, js, wasm

    Records are read-only. Build them for tests with VersionRecord::new, Dep::new and About::new. Their optional arguments let the index gain new fields without breaking your code.

    #License

    Apache-2.0. See LICENSE.

    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

    Exposes equal and not_equal as methods of ParseError.

    ParseError::not_equal

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

    Exposes equal and not_equal as methods of ParseError.

    ParseError::to_repr

    Exposes to_repr as a method of ParseError, for debug output.

    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

    Exposes equal and not_equal as methods of About.

    About::new

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

    What a version says about its module, for tests and tools that build records; every field is absent or empty when omitted.

    About::not_equal

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

    Exposes equal and not_equal as methods of About.

    About::to_json

    Exposes to_json as a method of About.

    About::to_repr

    Exposes to_repr as a method of About, for debug output.

    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

    Exposes equal and not_equal as methods of Dep.

    Dep::new

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

    A dependency on module name, for tests and tools that build records; the optional fields are absent when omitted.

    Dep::not_equal

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

    Exposes equal and not_equal as methods of Dep.

    Dep::to_repr

    Exposes to_repr as a method of Dep, for debug output.

    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

    Exposes equal and not_equal as methods of Module.

    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

    Exposes equal and not_equal as methods of Module.

    Module::to_repr

    Exposes to_repr as a method of Module, for debug output.

    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

    Exposes equal and not_equal as methods of VersionRecord.

    VersionRecord::new

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

    One published version of module name, for tests and tools that build records: no dependencies, not yanked and nothing in about unless given.

    VersionRecord::not_equal

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

    Exposes equal and not_equal as methods of VersionRecord.

    VersionRecord::to_json

    Exposes to_json as a method of VersionRecord.

    VersionRecord::to_repr

    Exposes to_repr as a method of VersionRecord, for debug output.

    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.