Documentation
¶
Overview ¶
Package wasmengine composes the services the browser engine serves (agni issue 178). It is separate from cmd/agni-wasm, which only bridges it to JavaScript, so the composition builds and is tested natively, against the server's, without a browser.
Index ¶
- Constants
- func ApplySeed(ctx context.Context, store service.BlobStore, seed []byte, ...) (int, error)
- func Build(root fs.FS) (http.Handler, error)
- func BuildWith(o Options) func(fs.FS) (http.Handler, error)
- func Seed(ctx context.Context, mount, uri string, files []SeedFile, version string) ([]byte, error)
- func StoreVersion() string
- func WithheldPlaceholder(sha256 string) []byte
- type Engine
- type Options
- type SeedFile
Constants ¶
const BrowserMount = "local"
BrowserMount is the mount a page puts dropped files in (agni issue 854). Its files exist only in the visitor's browser, and a `.zip` in it reads as the folder it was made from.
const Namespace = "agni"
Namespace is the global the wasm build's exports live under, globalThis.agni.
const SeedPath = "/agni-seed"
SeedPath is the engine's route a page posts a seed to. The body is the seed as the server sent it, and SeedVersionHeader names the version it was built under.
const SeedVersionHeader = "Agni-Store-Version"
SeedVersionHeader names the store version a seed was built under.
const SumsFile = ".agni-sums.json"
SumsFile is the manifest the page writes at a mount's root beside the design files it brings in (agni issue 1515). It names each file's sha256 and size as the server listed them. testdata/sums_twin.json holds it to the page's writer in web/src/wasm/client.ts.
Variables ¶
This section is empty.
Functions ¶
func ApplySeed ¶ added in v0.6.9
func ApplySeed(ctx context.Context, store service.BlobStore, seed []byte, version, want string) (int, error)
ApplySeed puts a seed's entries into store and reports how many it put. It puts nothing when the seed was built under another version than want.
func Build ¶
Build composes the engine over root and keeps nothing past the worker. Each top-level directory of root is a mount, as goapplib's wasmhost holds them.
func BuildWith ¶
BuildWith is Build with options, the rebuild function cmd/agni-wasm hands the host.
func Seed ¶ added in v0.6.9
Seed builds a design's store entries the way a browser worker would write them. The engine reads the design at uri with its board and draws the packed Board sheet, over a mount holding exactly files and the manifest the page writes beside them (SumsFile). That mount is what a worker holds, so every entry's fingerprint matches the worker's own reading of it.
It returns no seed for an empty version, since an engine with no version persists nothing. A design with no board still seeds what it read.
func StoreVersion ¶
func StoreVersion() string
StoreVersion names this build for the persistent tier: the commit, the uncommitted changes when there are any, and the layout of what is stored. A build that cannot say what it was built from gets an empty name, and an empty name persists nothing. Two such builds could read a file differently and still share a name.
func WithheldPlaceholder ¶ added in v0.3.0
WithheldPlaceholder is the placeholder for a held-back file whose content hash is sha256, as ListDesignFiles spells it.
Types ¶
type Engine ¶
type Engine struct {
// Handler serves the Connect API, as `agni serve` does at the same paths.
Handler http.Handler
// Paths are the service paths Handler answers.
Paths []string
// Warnings are the legitimate absences agni.New reports, such as no datasheet corpus.
Warnings []string
// Cache is the design cache every service reads through, for its counters.
Cache *service.DesignCache
}
Engine is one composition over one mount table. The browser rebuilds it when a mount changes, which is cheaper to reason about than services caching a project tree that moved under them.
func New ¶
New composes the engine over ms through agni.New. agni.New refuses a build missing the rule catalog or the fact relations. The refusal matters most here, because a browser bundle that silently shipped without the built-in rules would report every design clean.
The browser engine leaves four things out on purpose. It has no native renderer, since xschem and Lepton are processes. It has no review store, since nothing a visitor drops is kept. It has no datasheet corpus yet, and #852 decides whether one ships. And it has no query budget, since only the person who asked a query is waiting on it.
type Options ¶
type Options struct {
// Store keeps every parsed design, drawing and board past the worker, so another worker over the
// same files (a reload, a second lane, a lane's replacement) restores them rather than reading
// them again (agni issue 911). In the browser it is wasmhost.BrowserCache. Nil keeps nothing.
Store service.BlobStore
// Version names the engine that wrote what Store holds. Empty means StoreVersion().
Version string
// CollectBetweenRequests is set by a caller that has turned off the Go collector's automatic
// cycles with debug.SetGCPercent(-1), as cmd/agni-wasm does. The engine then collects after a
// request when the heap has doubled since its last collection. It does the same as each file
// opens, and after each layer it loads, so it never collects in the middle of evaluating (agni
// issue 1010). A native caller leaves it off, since its collector runs concurrently on other
// cores and is cheap there.
CollectBetweenRequests bool
}
Options configures an engine beyond its mount table.