scriptlib

package
v1.138.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 29, 2026 License: Apache-2.0 Imports: 10 Imported by: 0

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

View Source
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.

View Source
const Prefix = "lib:"

Prefix is the scheme a library load names.

Variables

View Source
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

func IsLibrary(file *syntax.File) bool

IsLibrary reports whether file is a library: it defines no main() at its top level.

func Loader

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

func SourceIsLibrary(source string) bool

SourceIsLibrary is IsLibrary over source; a source that does not parse is not a library.

Types

type Load

type Load struct {
	Ref  Ref
	Err  error
	Line int
}

Load is one load statement: the library version it names, or the error its module string is, and its line.

func Loads

func Loads(file *syntax.File) []Load

Loads is every load statement of file, in source order.

type Problem

type Problem struct {
	Line    int
	Message string
}

Problem is one load a save is refused for.

func Check

func Check(ctx context.Context, src Source, source, self string) []Problem

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

func ParseModule(module string) (Ref, error)

ParseModule reads the module string of a load.

func Refs

func Refs(source string) []Ref

Refs is the library versions source loads, in source order, each once. A source that does not parse, and a load naming no library, contribute none.

func (Ref) String

func (r Ref) String() string

String is the module a load names the version by.

type Source

type Source interface {
	LibrarySource(ctx context.Context, name string, version int) (string, error)
}

Source reads the source of one saved version of a library.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL