Documentation
¶
Overview ¶
Package scriptlib is managed-script libraries (#1941): a library is a script with no main(), pure code another script loads by name and pinned version, load("lib:<name>@<version>", "fn").
A library is shared. Its code reaches nothing (no platform, no run), so loading it grants nothing, and a library's name is unique across the deployment, whoever owns it. A load names a version, and a saved version never changes, so a new version of a library changes no script that did not ask for it.
Every execution of a script resolves its loads through Loader over one Source: a run, a draft, a test and a behavior replay read the same pinned source, so a test and a run cannot disagree about the library's code.
Index ¶
Constants ¶
const MaxDepth = 8
MaxDepth is how many libraries deep a chain of loads may go. A chain longer than this is refused on save and at run time alike.
const Prefix = "lib:"
Prefix is the scheme a library load names.
Variables ¶
var ErrNotFound = errors.New("no such library version")
ErrNotFound is what a Source answers for a library or version that does not exist.
Functions ¶
func IsLibrary ¶
IsLibrary reports whether file is a library: it defines no main() at its top level.
func Loader ¶
func Loader(ctx context.Context, src Source, env starlark.StringDict) func(*starlark.Thread, string) (starlark.StringDict, error)
Loader is the thread's Load for an execution: each library version is read from src once, executed in env (the predeclared names a library sees), and its frozen globals handed to every load of it. A load while the same version is still loading is a cycle; a chain deeper than MaxDepth is refused.
func SourceIsLibrary ¶
SourceIsLibrary is IsLibrary over source; a source that does not parse is not a library.
Types ¶
type Load ¶
Load is one load statement: the library version it names, or the error its module string is, and its line.
type Problem ¶
Problem is one load a save is refused for.
func Check ¶
Check resolves every load of source, and every load of the libraries it loads, against src: a save is refused for a load of a library or version that does not exist, a load cycle, or a chain deeper than MaxDepth. self is the library being saved, when it is one ("" otherwise), so a library that names itself is reported as the cycle it is. The findings are returned as one sentence each with its line in source.
type Ref ¶
type Ref struct {
Name string `json:"name" example:"date-windows"`
Version int `json:"version" example:"2"`
}
Ref names one version of a library.
func ParseModule ¶
ParseModule reads the module string of a load.