Documentation ¶
Overview ¶
Package schema provides mechanisms for describing ecosystems that can be used to construct a resolve.LocalClient or a resolve.Graph suitable for use in tests.
Example (Schema) ¶
This schema declares three packages, each with versions that have imports.
package main import ( "fmt" "deps.dev/util/resolve" "deps.dev/util/resolve/schema" ) func main() { const text = ` # Package alice has two versions, each with one dependency. alice 1.0.0 # This version depends on bob # with the requirement ">=1.0.0". bob@>=1.0.0 2.0.0 bob@^1.0.0 # Package bob has one version that has two dependencies. bob 1.0.0 # This version depends on bob/pkg # with the requirement "1.0.0"... bob/pkg@1.0.0 # ... and optionally on cat with the # requirement "latest" Opt|cat@latest # Package bob/pkg has one version that has one dependency. bob/pkg 1.0.0 # This version depends on cat # with the requirement "main". cat@main # Package cat has one concrete version. # It has no dependencies. cat # This version line declares a concrete version, just like # those in the other packages above. c0d3f4c3 ` s, err := schema.New(text, resolve.NPM) if err != nil { panic(err) } fmt.Println(s.Package("alice").Version("2.0.0", resolve.Concrete).VersionKey) fmt.Println(s.Package("bob").Version("1.0.0", resolve.Concrete).VersionKey) fmt.Println(s.Package("bob").Version("1.0.0", resolve.Concrete).Requirements) fmt.Println(s.Package("bob/pkg").Version("1.0.0", resolve.Concrete).VersionKey) fmt.Println(s.Package("cat").Version("c0d3f4c3", resolve.Concrete).VersionKey) }
Output: NPM:alice[Concrete:2.0.0] NPM:bob[Concrete:1.0.0] [NPM:bob/pkg[Requirement:1.0.0] opt|NPM:cat[Requirement:latest]] NPM:bob/pkg[Concrete:1.0.0] NPM:cat[Concrete:c0d3f4c3]
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ParseResolve ¶
ParseResolve parses the given schema text and creates a resolve.Graph.
The schema describes a resolution graph of concrete versions (nodes) connected by requirement versions (edges) that is used to construct a resolve.Graph suitable for comparison to graphs returned by resolvers.
The schema may be declared using a simple, tab-sensitive grammar, with each level of indentation representing an edge and each line representing an edge specifier (a requirement) and a node (a concrete). Lines are trimmed, and empty lines or lines starting with a `#` are skipped.
Items (label, requirement, concrete) on a line are space separated. In the current implementation, names, requirements, concretes and labels must not contain spaces.
# name1 v1 --- name2@* ---> v2 -- name3@v1-4 --> v3 # \ # +- name4@v4 --> v4 name1 v1 name2@* v2 name3@v1-4 v3 name4@v4 v4
Each node can be labeled, so that it can be referenced in another line (in such case the referring line does not create a node, and simply represents an edge)
# name1 v1 --- name2@* ---> v2 -- name3@v1-4 ----> v3 # \ / # +- name4@v4 --> v4 -- name3@v2-5 --+ name1 v1 name2@* v2 label: [DepType|]name3@v1-4 v3 name4@v4 v4 [DepType|]$label@v2-5
The first line defines the graph root. It may or may not have a label:
[label: ]name concrete
Pattern of other lines, defining nodes, contains tabulation to implicitly create an edge:
tabs [label: ]name@requirement concrete
Pattern for rows referring a node by label:
tabs $label@requirement
Pattern for rows defining an error linked to the parent node:
tabs name@requirement ERROR: error
The indentation of a line is used to implicitly create an edge between nodes. If the current line has an indentation of n, an edge will be created from the closest preceding line that has an indentation of n-1 to the current line. Furthermore, if a line has an indentation of n, the line immediately after must have an indentation <= n+1 (it can reduce, stay, or increase by 1).
Types ¶
type Package ¶
type Package struct { resolve.PackageKey Versions []Version }
Package represents a package in a schema.
type Schema ¶
type Schema struct {
Packages []Package
}
Schema represents an ecosystem of packages, versions, and imports.
A Schema may be declared using a simple, tab-sensitive grammar, with each level of indentation representing the declaration of a package, version, import, and attributes:
# Comment Name [RefreshTime as YYYY-MM-DD] [VersionAttr|]Version ATTR: AttrKey AttrVal [DepType|]Name@RequirementVersion [DepType|]Name@ConcreteVersion SymbolicVersion -> ConcreteVersion
[VersionAttr|] is optional and defines the version attributes. An alternate way to add an attribute is to add lines, indented under the version, starting with "ATTR:" and defining an AttrKey and an AttrVal.
[DepType|] is optional and defines the dependency type. Attribute keys and values are space-separated.
See the "schema" example for a sample schema.
func New ¶
New parses a textual representation of a Schema and returns it. The given System is used for all packages in the schema.
func (Schema) NewClient ¶
func (s Schema) NewClient() *resolve.LocalClient
NewClient returns a resolve.Client that returns all of the packages and versions defined in the Schema.
func (Schema) Package ¶
Package returns the Package for the package with the given name, or nil if none exists in the schema.
func (Schema) ValidateClient ¶
func (s Schema) ValidateClient(client *resolve.LocalClient) error
ValidateClient checks that the given resolve.LocalClient holds all the elements of the Schema.
type Version ¶
type Version struct { resolve.VersionKey Attr version.AttrSet Requirements []resolve.RequirementVersion // For concrete versions. }
Version represents a version in a schema.