scriptres

package
v1.148.0 Latest Latest
Warning

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

Go to latest
Published: Oct 19, 2026 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Overview

Package scriptres is the managed-resource text a script loads with load("res:<library>/<path>/<file>", NAME = "text") (#2113): a page script, a SQL file, an HTML template, kept as a file of its own and edited as one, rather than escaped into a Starlark string.

A save resolves every such load under its author's access and pins the file's current version; every run of the version it creates reads that version. A draft pins each file's version as the draft starts, under the caller's access, and records it, which is what the save it leads to will pin. A run's or a draft's recording keeps the version of each file it read, and a test replaying it reads those versions, so a replay of an older run reads the text that run read.

Index

Constants

View Source
const MaxTextBytes = 1 << 20

MaxTextBytes is the most text one load reads.

Variables

This section is empty.

Functions

func Current

func Current(ctx context.Context, r *scriptsrc.Reader, source string, claims resource.Claims) map[string]script.ResourcePin

Current resolves the version of each file source loads as it is now under claims, for a draft to read and record. A load that cannot be read is left out, so the draft fails at that load naming why.

func Pin

func Pin(ctx context.Context, r *scriptsrc.Reader, source string, claims resource.Claims) (pins map[string]script.ResourcePin, problems []string)

Pin resolves every res: load of source under claims and returns the version each reads, keyed by module, with a sentence for each load that cannot be read. A source that loads none returns an empty set.

func PinsOf

func PinsOf(src scriptlib.Source) map[string]script.ResourcePin

PinsOf is the version of each file an execution reading src reads, keyed by module: what its recording keeps.

func Replaying

func Replaying(src scriptlib.Source, files map[string]script.ResourcePin) scriptlib.Source

Replaying is src reading each file a recording's run read at the version it read, and any other file as src reads it.

func URI

func URI(module, scheme string) string

URI is the address a res: module names, in the library's scheme.

func With

func With(libraries scriptlib.Source, r *scriptsrc.Reader, pins map[string]script.ResourcePin, claims *resource.Claims) scriptlib.Source

With wraps libraries so an execution can read res: modules: pinned, or under claims when claims is not nil. A nil reader leaves libraries as they are, and a res: load is refused for want of a library.

Types

type Source

type Source struct {
	Libraries scriptlib.Source
	Reader    *scriptsrc.Reader
	Pins      map[string]script.ResourcePin
	Claims    *resource.Claims
}

Source is the library source an execution reads its loads through, with res: modules answered from the library: a pinned module reads its pinned version, and an unpinned one, in a draft or a test, reads the file as it is now under Claims. A run passes the pins its version holds and no claims, so a load its save did not pin is refused.

func (Source) LibrarySource

func (s Source) LibrarySource(ctx context.Context, name string, version int) (string, error)

LibrarySource implements scriptlib.Source.

func (Source) ResourceText

func (s Source) ResourceText(ctx context.Context, module string) (string, error)

ResourceText implements scriptlib.ResourceSource.

Jump to

Keyboard shortcuts

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