op

package
v0.2.4 Latest Latest
Warning

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

Go to latest
Published: Jun 3, 2026 License: MPL-2.0 Imports: 18 Imported by: 0

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

func CleanJSError(raw, entry string) string

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.)

func Dispatch

func Dispatch(args []string, stdout, stderr io.Writer) int

Dispatch routes `txco op <subcommand> …`.

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

func BuildFile(entryPath, workspaceRoot string) (Built, error)

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

func BuiltFromWasm(wasm []byte) Built

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.

Jump to

Keyboard shortcuts

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