Documentation
¶
Overview ¶
Package compute implements the authoring CLI for sandboxed op:// computes (wired as `txco op`). It scaffolds a compute, bundles + builds it to a content-addressed WASI module, and runs it locally on the same wazero engine the chassis uses — so "works locally" means "works in production".
A compute is authored with the @txco/op SDK:
import { op } from "@txco/op";
export default op(async ({ input, log }) => ({ ok: true }));
The build pipeline is esbuild (bundle + resolve @txco/op from embedded sources + transpile TS) → javy (QuickJS → WASI module, event loop enabled so async handlers work). The build seam is per-language: any toolchain that emits a conforming WASI stdin→stdout module slots in without runtime changes.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CleanJSError ¶
CleanJSError tidies javy/QuickJS error text: it strips toolchain wrapper noise and points the QuickJS-internal "function.mjs" frames at the bundled entry so the message reads cleanly. (Precise author-line remapping via the esbuild sourcemap is a follow-up; the bundle is unminified so frames remain legible in the meantime.)
Types ¶
type Built ¶
type Built struct {
Wasm []byte
Alg string
Digest string
Engine string
Ref string // "compute://sha256/<digest>"
OutPath string
Entry string // author's entry file (for cleaning error locations)
}
Built is the result of compiling a compute: the module bytes, its content-addressed ref, and the engine that runs it. Consumed by `txco apply` to upload + resolve op://NAME.
func BuildFile ¶
BuildFile compiles a single colocated compute source (e.g. OPS/site/100/hello.js or .ts) into a WASI module: esbuild bundles it (with the embedded @txco/op SDK + TS transpile + tree-shaking), then javy compiles the bundle to wasm with the event loop enabled so async handlers run. Compiled artifacts are cached under <workspaceRoot>/.txco/compute keyed by the hash of the bundled JS, so an unchanged compute skips javy on re-apply.
func BuiltFromWasm ¶ added in v0.2.4
BuiltFromWasm wraps already-built wasm bytes as a Built, mirroring BuildFile's content-addressing (BuildFile dispatch.go:291-297) so a prebuilt <name>.wasm shipped in a package yields the SAME compute://sha256/<digest> a local build would. No esbuild/javy — the bytes ARE the artifact. Used by `txco apply` when a prebuilt wasm sibling is present, so consumers need no toolchain.