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
- Variables
- func IsLibrary(file *syntax.File) bool
- func Loader(ctx context.Context, src Source, env starlark.StringDict) func(*starlark.Thread, string) (starlark.StringDict, error)
- func ResourceModules(source string) []string
- func SourceIsLibrary(source string) bool
- type Load
- type Problem
- type Ref
- type ResourceSource
- type Source
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.
const ResourcePrefix = "res:"
ResourcePrefix is the scheme a load of a managed resource's text names (#2113): load("res:<library>/<path>/<file>", PAGE_JS = "text") binds the file's text, as it was when the script was saved, to PAGE_JS. The rest of the module is the file's mcp:// address after the scheme.
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 neither main() nor an endpoint's handle() at its top level (#2172).
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 ResourceModules ¶ added in v1.145.0
ResourceModules is the res: modules source loads, in source order, each once. A source that does not parse names none.
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 resource module it names (#2113), 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.
type ResourceSource ¶ added in v1.145.0
ResourceSource reads the text a res: module names, as a Source that can answers it. A run reads the version its script version pinned; a draft and a test read the file as it is now.