Help us shape the future of Go! Take the 2026 Go Developer Survey

s4wave_function

package
v0.57.30 Latest Latest
Warning

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

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

Documentation

Overview

Package s4wave_function is the contract of PureFunctions: TypeScript modules that turn protobuf input into protobuf output under a memory and instruction budget, and run the same on a Go daemon and in a browser.

Index

Constants

View Source
const DefaultInterruptChecks = 1000

DefaultInterruptChecks is the interrupt check limit of a budget that sets none, about ten million operations.

View Source
const DefaultMemoryLimitBytes = 32 << 20

DefaultMemoryLimitBytes is the heap limit of a budget that sets none.

View Source
const ModuleName = "/function.js"

ModuleName is the name a runner gives the function's module.

View Source
const PureFunctionTypeID = "function/pure"

PureFunctionTypeID is the type ID of PureFunction.

Variables

View Source
var ErrModuleRequired = errors.New("the function has no compiled module")

ErrModuleRequired is returned when a PureFunction has no compiled module.

View Source
var ErrTypeRequired = errors.New("the function needs an input and an output type")

ErrTypeRequired is returned when a PureFunction names no input or output type.

View Source
var FunctionTypes = []typeid.Type{
	{ID: PureFunctionTypeID, New: func() any { return new(PureFunction) }},
}

FunctionTypes lists the typed messages of function.proto.

Functions

func Compile

func Compile(source string) (string, error)

Compile compiles the TypeScript source of a PureFunction to the ES module a runner evaluates. A PureFunction imports nothing, so an import fails.

func CreatePureFunction

func CreatePureFunction(ctx context.Context, ws world.WorldState, key string, fn *PureFunction) error

CreatePureFunction creates the World object key as a function/pure holding fn.

func SetPureFunction

func SetPureFunction(ctx context.Context, ws world.WorldState, key string, fn *PureFunction) error

SetPureFunction stores fn at key, creating the function/pure object when it is missing. An existing function is changed in place, so the edges that reach it remain.

Types

type Budget

type Budget struct {

	// MemoryLimitBytes caps the JavaScript heap of a run. Zero uses 32 MiB.
	MemoryLimitBytes uint32 `protobuf:"varint,1,opt,name=memory_limit_bytes,json=memoryLimitBytes,proto3" json:"memoryLimitBytes,omitempty"`
	// InterruptChecks caps the interrupt checks of a run. QuickJS checks once
	// every 10,000 bytecode branches and calls, so a run gets about that many
	// operations per check, counted the same on a Go daemon and in a browser.
	// Zero uses 1,000.
	InterruptChecks uint32 `protobuf:"varint,2,opt,name=interrupt_checks,json=interruptChecks,proto3" json:"interruptChecks,omitempty"`
	// contains filtered or unexported fields
}

Budget bounds the resources of one PureFunction run. A run past either bound fails.

func (*Budget) CloneMessageVT

func (m *Budget) CloneMessageVT() protobuf_go_lite.CloneMessage

func (*Budget) CloneVT

func (m *Budget) CloneVT() *Budget

func (*Budget) EqualMessageVT

func (this *Budget) EqualMessageVT(thatMsg any) bool

func (*Budget) EqualVT

func (this *Budget) EqualVT(that *Budget) bool

func (*Budget) GetInterruptChecks

func (x *Budget) GetInterruptChecks() uint32

func (*Budget) GetInterruptLimit

func (b *Budget) GetInterruptLimit() uint32

GetInterruptLimit returns the interrupt check limit, applying the default.

func (*Budget) GetMemoryLimit

func (b *Budget) GetMemoryLimit() uint32

GetMemoryLimit returns the heap limit in bytes, applying the default.

func (*Budget) GetMemoryLimitBytes

func (x *Budget) GetMemoryLimitBytes() uint32

func (*Budget) MarshalJSON

func (x *Budget) MarshalJSON() ([]byte, error)

MarshalJSON marshals the Budget to JSON.

func (*Budget) MarshalProtoJSON

func (x *Budget) MarshalProtoJSON(s *json.MarshalState)

MarshalProtoJSON marshals the Budget message to JSON.

func (*Budget) MarshalProtoText

func (x *Budget) MarshalProtoText() string

func (*Budget) MarshalToSizedBufferVT

func (m *Budget) MarshalToSizedBufferVT(dAtA []byte) (int, error)

func (*Budget) MarshalToVT

func (m *Budget) MarshalToVT(dAtA []byte) (int, error)

func (*Budget) MarshalVT

func (m *Budget) MarshalVT() (dAtA []byte, err error)

func (*Budget) ProtoMessage

func (*Budget) ProtoMessage()

func (*Budget) Reset

func (x *Budget) Reset()

func (*Budget) SizeVT

func (m *Budget) SizeVT() (n int)

func (*Budget) String

func (x *Budget) String() string

func (*Budget) UnmarshalJSON

func (x *Budget) UnmarshalJSON(b []byte) error

UnmarshalJSON unmarshals the Budget from JSON.

func (*Budget) UnmarshalProtoJSON

func (x *Budget) UnmarshalProtoJSON(s *json.UnmarshalState)

UnmarshalProtoJSON unmarshals the Budget message from JSON.

func (*Budget) UnmarshalVT

func (m *Budget) UnmarshalVT(dAtA []byte) error

type PureFunction

type PureFunction struct {

	// Source is the TypeScript source as written.
	Source string `protobuf:"bytes,1,opt,name=source,proto3" json:"source,omitempty"`
	// Module is the ES module compiled from Source, which a runner evaluates.
	Module string `protobuf:"bytes,2,opt,name=module,proto3" json:"module,omitempty"`
	// InputType is the full name of the input message, such as
	// s4wave.prom.QueryResponse. The function reads it in protobuf JSON form.
	InputType string `protobuf:"bytes,3,opt,name=input_type,json=inputType,proto3" json:"inputType,omitempty"`
	// OutputType is the full name of the output message. The function returns
	// it in protobuf JSON form.
	OutputType string `protobuf:"bytes,4,opt,name=output_type,json=outputType,proto3" json:"outputType,omitempty"`
	// Budget bounds each run.
	Budget *Budget `protobuf:"bytes,5,opt,name=budget,proto3" json:"budget,omitempty"`
	// contains filtered or unexported fields
}

PureFunction is the root of a function/pure object: a TypeScript module whose default export turns one protobuf message into another. It runs with no SDK, network or clock of its own, so the same input gives the same output wherever it runs.

func ReadPureFunction

func ReadPureFunction(ctx context.Context, ws world.WorldState, key string) (*PureFunction, error)

ReadPureFunction reads the PureFunction key.

func (*PureFunction) CloneMessageVT

func (m *PureFunction) CloneMessageVT() protobuf_go_lite.CloneMessage

func (*PureFunction) CloneVT

func (m *PureFunction) CloneVT() *PureFunction

func (*PureFunction) EqualMessageVT

func (this *PureFunction) EqualMessageVT(thatMsg any) bool

func (*PureFunction) EqualVT

func (this *PureFunction) EqualVT(that *PureFunction) bool

func (*PureFunction) GetBudget

func (x *PureFunction) GetBudget() *Budget

func (*PureFunction) GetInputType

func (x *PureFunction) GetInputType() string

func (*PureFunction) GetModule

func (x *PureFunction) GetModule() string

func (*PureFunction) GetOutputType

func (x *PureFunction) GetOutputType() string

func (*PureFunction) GetSource

func (x *PureFunction) GetSource() string

func (*PureFunction) MarshalJSON

func (x *PureFunction) MarshalJSON() ([]byte, error)

MarshalJSON marshals the PureFunction to JSON.

func (*PureFunction) MarshalProtoJSON

func (x *PureFunction) MarshalProtoJSON(s *json.MarshalState)

MarshalProtoJSON marshals the PureFunction message to JSON.

func (*PureFunction) MarshalProtoText

func (x *PureFunction) MarshalProtoText() string

func (*PureFunction) MarshalToSizedBufferVT

func (m *PureFunction) MarshalToSizedBufferVT(dAtA []byte) (int, error)

func (*PureFunction) MarshalToVT

func (m *PureFunction) MarshalToVT(dAtA []byte) (int, error)

func (*PureFunction) MarshalVT

func (m *PureFunction) MarshalVT() (dAtA []byte, err error)

func (*PureFunction) ProtoMessage

func (*PureFunction) ProtoMessage()

func (*PureFunction) Reset

func (x *PureFunction) Reset()

func (*PureFunction) SizeVT

func (m *PureFunction) SizeVT() (n int)

func (*PureFunction) String

func (x *PureFunction) String() string

func (*PureFunction) TypeID

func (*PureFunction) TypeID() string

TypeID returns the type ID of PureFunction.

func (*PureFunction) UnmarshalJSON

func (x *PureFunction) UnmarshalJSON(b []byte) error

UnmarshalJSON unmarshals the PureFunction from JSON.

func (*PureFunction) UnmarshalProtoJSON

func (x *PureFunction) UnmarshalProtoJSON(s *json.UnmarshalState)

UnmarshalProtoJSON unmarshals the PureFunction message from JSON.

func (*PureFunction) UnmarshalVT

func (m *PureFunction) UnmarshalVT(dAtA []byte) error

func (*PureFunction) Validate

func (f *PureFunction) Validate() error

Validate checks that the function has a module and names its types.

Directories

Path Synopsis
Package function_run runs PureFunctions in the QuickJS-NG WASI reactor under wazero.
Package function_run runs PureFunctions in the QuickJS-NG WASI reactor under wazero.

Jump to

Keyboard shortcuts

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