appletpb

package module
v0.0.0-...-f1ff6bf Latest Latest
Warning

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

Go to latest
Published: Oct 19, 2026 License: MIT Imports: 14 Imported by: 0

Documentation

Overview

Package appletpb is the gRPC API of appletd, which builds and runs applets. applets.proto describes it, and most of this package is generated from it.

Clients can use the generated AppletsClient directly, or its helpers: Open sends the applets and waits until they are built, and Stream.Run streams objects through them, much like runner.Applet.Run does in-process. The generated CompileError and Error messages implement error.

Index

Constants

This section is empty.

Variables

View Source
var (
	Error_Reason_name = map[int32]string{
		0: "REASON_UNSPECIFIED",
		1: "APPLET_FAILED",
		2: "OUT_OF_MEMORY",
		3: "INVALID_OUTPUT",
		4: "NOT_DONE",
	}
	Error_Reason_value = map[string]int32{
		"REASON_UNSPECIFIED": 0,
		"APPLET_FAILED":      1,
		"OUT_OF_MEMORY":      2,
		"INVALID_OUTPUT":     3,
		"NOT_DONE":           4,
	}
)

Enum value maps for Error_Reason.

View Source
var (
	SourceError_Step_name = map[int32]string{
		0: "STEP_UNSPECIFIED",
		1: "TYPECHECK",
		2: "BUNDLE",
		3: "COMPILE",
	}
	SourceError_Step_value = map[string]int32{
		"STEP_UNSPECIFIED": 0,
		"TYPECHECK":        1,
		"BUNDLE":           2,
		"COMPILE":          3,
	}
)

Enum value maps for SourceError_Step.

View Source
var Applets_ServiceDesc = grpc.ServiceDesc{
	ServiceName: "applets.v1.Applets",
	HandlerType: (*AppletsServer)(nil),
	Methods:     []grpc.MethodDesc{},
	Streams: []grpc.StreamDesc{
		{
			StreamName:    "Run",
			Handler:       _Applets_Run_Handler,
			ServerStreams: true,
			ClientStreams: true,
		},
	},
	Metadata: "applets.proto",
}

Applets_ServiceDesc is the grpc.ServiceDesc for Applets service. It's only intended for direct use with grpc.RegisterService, and not to be introspected or modified (even as a copy)

View Source
var File_applets_proto protoreflect.FileDescriptor

Functions

func RegisterAppletsServer

func RegisterAppletsServer(s grpc.ServiceRegistrar, srv AppletsServer)

Types

type Applet

type Applet struct {

	// The TypeScript source of the applet.
	Source string `protobuf:"bytes,1,opt,name=source,proto3" json:"source,omitempty"`
	// A type the default export of the applet must be assignable to, e.g.
	// `import("go-applets").Applet<import("shop").Order>`. The applets in a
	// pipeline may have different signatures; the server does not check that
	// the output type of one applet is the input type of the next.
	Signature string `protobuf:"bytes,2,opt,name=signature,proto3" json:"signature,omitempty"`
	// The params of the applet as JSON, or empty if it has none. They are not
	// checked against the params type in the signature.
	Params []byte `protobuf:"bytes,3,opt,name=params,proto3" json:"params,omitempty"`
	// contains filtered or unexported fields
}

func (*Applet) Descriptor deprecated

func (*Applet) Descriptor() ([]byte, []int)

Deprecated: Use Applet.ProtoReflect.Descriptor instead.

func (*Applet) GetParams

func (x *Applet) GetParams() []byte

func (*Applet) GetSignature

func (x *Applet) GetSignature() string

func (*Applet) GetSource

func (x *Applet) GetSource() string

func (*Applet) ProtoMessage

func (*Applet) ProtoMessage()

func (*Applet) ProtoReflect

func (x *Applet) ProtoReflect() protoreflect.Message

func (*Applet) Reset

func (x *Applet) Reset()

func (*Applet) String

func (x *Applet) String() string

type AppletsClient

type AppletsClient interface {
	// Run builds the applets in Start, and runs them as a pipeline over the
	// objects the client sends.
	//
	// The client sends Start, then the input objects, and half-closes the
	// stream when the input ends. The server sends Running once the applets
	// are built, then output objects and log lines as they come, then exactly
	// one of Done, Error or CompileError, and ends the stream with status OK.
	// The client may cancel the stream at any time, which stops the applets.
	//
	// The server reads the next input object only when the first applet asks
	// for it, so a client that sends faster is held back by flow control.
	//
	// Problems with the request itself end the stream with an error status
	// instead: INVALID_ARGUMENT for a request that breaks the rules described
	// here or exceeds a limit of the server, and RESOURCE_EXHAUSTED when the
	// server runs too many streams.
	Run(ctx context.Context, opts ...grpc.CallOption) (Applets_RunClient, error)
}

AppletsClient is the client API for Applets service.

For semantics around ctx use and closing/ending streaming RPCs, please refer to https://pkg.go.dev/google.golang.org/grpc/?tab=doc#ClientConn.NewStream.

func NewAppletsClient

func NewAppletsClient(cc grpc.ClientConnInterface) AppletsClient

type AppletsServer

type AppletsServer interface {
	// Run builds the applets in Start, and runs them as a pipeline over the
	// objects the client sends.
	//
	// The client sends Start, then the input objects, and half-closes the
	// stream when the input ends. The server sends Running once the applets
	// are built, then output objects and log lines as they come, then exactly
	// one of Done, Error or CompileError, and ends the stream with status OK.
	// The client may cancel the stream at any time, which stops the applets.
	//
	// The server reads the next input object only when the first applet asks
	// for it, so a client that sends faster is held back by flow control.
	//
	// Problems with the request itself end the stream with an error status
	// instead: INVALID_ARGUMENT for a request that breaks the rules described
	// here or exceeds a limit of the server, and RESOURCE_EXHAUSTED when the
	// server runs too many streams.
	Run(Applets_RunServer) error
}

AppletsServer is the server API for Applets service. All implementations should embed UnimplementedAppletsServer for forward compatibility

type Applets_RunClient

type Applets_RunClient interface {
	Send(*RunRequest) error
	Recv() (*RunResponse, error)
	grpc.ClientStream
}

type Applets_RunServer

type Applets_RunServer interface {
	Send(*RunResponse) error
	Recv() (*RunRequest, error)
	grpc.ServerStream
}

type CompileError

type CompileError struct {
	Errors []*SourceError `protobuf:"bytes,1,rep,name=errors,proto3" json:"errors,omitempty"`
	// contains filtered or unexported fields
}

CompileError ends a run in which one or more applets did not build. It has the errors of every applet that did not build, and nothing ran.

func (*CompileError) Descriptor deprecated

func (*CompileError) Descriptor() ([]byte, []int)

Deprecated: Use CompileError.ProtoReflect.Descriptor instead.

func (*CompileError) Error

func (e *CompileError) Error() string

Error makes a CompileError an error, with one line per SourceError.

func (*CompileError) GetErrors

func (x *CompileError) GetErrors() []*SourceError

func (*CompileError) ProtoMessage

func (*CompileError) ProtoMessage()

func (*CompileError) ProtoReflect

func (x *CompileError) ProtoReflect() protoreflect.Message

func (*CompileError) Reset

func (x *CompileError) Reset()

func (*CompileError) String

func (x *CompileError) String() string

type Done

type Done struct {
	// contains filtered or unexported fields
}

Done ends a run in which every applet finished, and all output was sent.

func (*Done) Descriptor deprecated

func (*Done) Descriptor() ([]byte, []int)

Deprecated: Use Done.ProtoReflect.Descriptor instead.

func (*Done) ProtoMessage

func (*Done) ProtoMessage()

func (*Done) ProtoReflect

func (x *Done) ProtoReflect() protoreflect.Message

func (*Done) Reset

func (x *Done) Reset()

func (*Done) String

func (x *Done) String() string

type Error

type Error struct {

	// The index of the applet in Start.applets.
	Applet int32        `protobuf:"varint,1,opt,name=applet,proto3" json:"applet,omitempty"`
	Reason Error_Reason `protobuf:"varint,2,opt,name=reason,proto3,enum=applets.v1.Error_Reason" json:"reason,omitempty"`
	// The message and the stack come from the applet, and the server may cut
	// them short.
	Message string `protobuf:"bytes,3,opt,name=message,proto3" json:"message,omitempty"`
	// The JavaScript stack trace, if there is one.
	Stack string `protobuf:"bytes,4,opt,name=stack,proto3" json:"stack,omitempty"`
	// The index of the input object the applet was processing, counting the
	// input objects of this applet, if it was processing one.
	Input *int64 `protobuf:"varint,5,opt,name=input,proto3,oneof" json:"input,omitempty"`
	// contains filtered or unexported fields
}

Error ends a run in which an applet failed. The other applets are stopped.

func (*Error) Descriptor deprecated

func (*Error) Descriptor() ([]byte, []int)

Deprecated: Use Error.ProtoReflect.Descriptor instead.

func (*Error) Error

func (e *Error) Error() string

Error makes an Error an error. It leaves out the stack.

func (*Error) GetApplet

func (x *Error) GetApplet() int32

func (*Error) GetInput

func (x *Error) GetInput() int64

func (*Error) GetMessage

func (x *Error) GetMessage() string

func (*Error) GetReason

func (x *Error) GetReason() Error_Reason

func (*Error) GetStack

func (x *Error) GetStack() string

func (*Error) ProtoMessage

func (*Error) ProtoMessage()

func (*Error) ProtoReflect

func (x *Error) ProtoReflect() protoreflect.Message

func (*Error) Reset

func (x *Error) Reset()

func (*Error) String

func (x *Error) String() string

type Error_Reason

type Error_Reason int32
const (
	Error_REASON_UNSPECIFIED Error_Reason = 0
	// The applet threw an exception, or crashed.
	Error_APPLET_FAILED Error_Reason = 1
	// The applet exceeded its memory limit.
	Error_OUT_OF_MEMORY Error_Reason = 2
	// The applet output something that is not a JSON object, an object too
	// large for a message, or something after it finished.
	Error_INVALID_OUTPUT Error_Reason = 3
	// The applet stopped without finishing.
	Error_NOT_DONE Error_Reason = 4
)

func (Error_Reason) Descriptor

func (Error_Reason) Enum

func (x Error_Reason) Enum() *Error_Reason

func (Error_Reason) EnumDescriptor deprecated

func (Error_Reason) EnumDescriptor() ([]byte, []int)

Deprecated: Use Error_Reason.Descriptor instead.

func (Error_Reason) Number

func (Error_Reason) String

func (x Error_Reason) String() string

func (Error_Reason) Type

type Limits

type Limits struct {

	// The maximum size of each linear memory of each applet, in MiB.
	MemoryMib uint32 `protobuf:"varint,1,opt,name=memory_mib,json=memoryMib,proto3" json:"memory_mib,omitempty"`
	// If set, cancelling the stream no longer stops an applet that is running:
	// it is stopped only when it next waits for input or delivers output. This
	// makes applets run faster, but an applet that never does either keeps
	// running forever, so it weakens the sandbox. The server refuses it unless
	// it is configured to allow it.
	NoCloseOnContextDone bool `` /* 128-byte string literal not displayed */
	// contains filtered or unexported fields
}

Limits may lower the limits of the server for this stream. A field left unset means the server's limit; a value the server does not allow is refused with INVALID_ARGUMENT.

func (*Limits) Descriptor deprecated

func (*Limits) Descriptor() ([]byte, []int)

Deprecated: Use Limits.ProtoReflect.Descriptor instead.

func (*Limits) GetMemoryMib

func (x *Limits) GetMemoryMib() uint32

func (*Limits) GetNoCloseOnContextDone

func (x *Limits) GetNoCloseOnContextDone() bool

func (*Limits) ProtoMessage

func (*Limits) ProtoMessage()

func (*Limits) ProtoReflect

func (x *Limits) ProtoReflect() protoreflect.Message

func (*Limits) Reset

func (x *Limits) Reset()

func (*Limits) String

func (x *Limits) String() string

type Log

type Log struct {

	// The index of the applet in Start.applets.
	Applet int32 `protobuf:"varint,1,opt,name=applet,proto3" json:"applet,omitempty"`
	// The line, cut short if it does not fit in a message.
	Line string `protobuf:"bytes,2,opt,name=line,proto3" json:"line,omitempty"`
	// contains filtered or unexported fields
}

Log is a line an applet logged.

func (*Log) Descriptor deprecated

func (*Log) Descriptor() ([]byte, []int)

Deprecated: Use Log.ProtoReflect.Descriptor instead.

func (*Log) GetApplet

func (x *Log) GetApplet() int32

func (*Log) GetLine

func (x *Log) GetLine() string

func (*Log) ProtoMessage

func (*Log) ProtoMessage()

func (*Log) ProtoReflect

func (x *Log) ProtoReflect() protoreflect.Message

func (*Log) Reset

func (x *Log) Reset()

func (*Log) String

func (x *Log) String() string

type Object

type Object struct {

	// A JSON object.
	Json []byte `protobuf:"bytes,1,opt,name=json,proto3" json:"json,omitempty"`
	// contains filtered or unexported fields
}

func (*Object) Descriptor deprecated

func (*Object) Descriptor() ([]byte, []int)

Deprecated: Use Object.ProtoReflect.Descriptor instead.

func (*Object) GetJson

func (x *Object) GetJson() []byte

func (*Object) ProtoMessage

func (*Object) ProtoMessage()

func (*Object) ProtoReflect

func (x *Object) ProtoReflect() protoreflect.Message

func (*Object) Reset

func (x *Object) Reset()

func (*Object) String

func (x *Object) String() string

type RunRequest

type RunRequest struct {

	// Types that are assignable to Kind:
	//
	//	*RunRequest_Start
	//	*RunRequest_Object
	Kind isRunRequest_Kind `protobuf_oneof:"kind"`
	// contains filtered or unexported fields
}

func (*RunRequest) Descriptor deprecated

func (*RunRequest) Descriptor() ([]byte, []int)

Deprecated: Use RunRequest.ProtoReflect.Descriptor instead.

func (*RunRequest) GetKind

func (m *RunRequest) GetKind() isRunRequest_Kind

func (*RunRequest) GetObject

func (x *RunRequest) GetObject() *Object

func (*RunRequest) GetStart

func (x *RunRequest) GetStart() *Start

func (*RunRequest) ProtoMessage

func (*RunRequest) ProtoMessage()

func (*RunRequest) ProtoReflect

func (x *RunRequest) ProtoReflect() protoreflect.Message

func (*RunRequest) Reset

func (x *RunRequest) Reset()

func (*RunRequest) String

func (x *RunRequest) String() string

type RunRequest_Object

type RunRequest_Object struct {
	// An input object for the first applet.
	Object *Object `protobuf:"bytes,2,opt,name=object,proto3,oneof"`
}

type RunRequest_Start

type RunRequest_Start struct {
	// Start is the first message, and is sent only once.
	Start *Start `protobuf:"bytes,1,opt,name=start,proto3,oneof"`
}

type RunResponse

type RunResponse struct {

	// Types that are assignable to Kind:
	//
	//	*RunResponse_Running
	//	*RunResponse_Object
	//	*RunResponse_Log
	//	*RunResponse_Done
	//	*RunResponse_Error
	//	*RunResponse_CompileError
	Kind isRunResponse_Kind `protobuf_oneof:"kind"`
	// contains filtered or unexported fields
}

func (*RunResponse) Descriptor deprecated

func (*RunResponse) Descriptor() ([]byte, []int)

Deprecated: Use RunResponse.ProtoReflect.Descriptor instead.

func (*RunResponse) GetCompileError

func (x *RunResponse) GetCompileError() *CompileError

func (*RunResponse) GetDone

func (x *RunResponse) GetDone() *Done

func (*RunResponse) GetError

func (x *RunResponse) GetError() *Error

func (*RunResponse) GetKind

func (m *RunResponse) GetKind() isRunResponse_Kind

func (*RunResponse) GetLog

func (x *RunResponse) GetLog() *Log

func (*RunResponse) GetObject

func (x *RunResponse) GetObject() *Object

func (*RunResponse) GetRunning

func (x *RunResponse) GetRunning() *Running

func (*RunResponse) ProtoMessage

func (*RunResponse) ProtoMessage()

func (*RunResponse) ProtoReflect

func (x *RunResponse) ProtoReflect() protoreflect.Message

func (*RunResponse) Reset

func (x *RunResponse) Reset()

func (*RunResponse) String

func (x *RunResponse) String() string

type RunResponse_CompileError

type RunResponse_CompileError struct {
	CompileError *CompileError `protobuf:"bytes,6,opt,name=compile_error,json=compileError,proto3,oneof"`
}

type RunResponse_Done

type RunResponse_Done struct {
	Done *Done `protobuf:"bytes,4,opt,name=done,proto3,oneof"`
}

type RunResponse_Error

type RunResponse_Error struct {
	Error *Error `protobuf:"bytes,5,opt,name=error,proto3,oneof"`
}

type RunResponse_Log

type RunResponse_Log struct {
	Log *Log `protobuf:"bytes,3,opt,name=log,proto3,oneof"`
}

type RunResponse_Object

type RunResponse_Object struct {
	// An object produced by the last applet in the pipeline.
	Object *Object `protobuf:"bytes,2,opt,name=object,proto3,oneof"`
}

type RunResponse_Running

type RunResponse_Running struct {
	Running *Running `protobuf:"bytes,1,opt,name=running,proto3,oneof"`
}

type Running

type Running struct {
	// contains filtered or unexported fields
}

Running is sent once all applets are built, before any Object or Log. A client that only wants to check the applets can wait for Running or CompileError, then cancel the stream.

func (*Running) Descriptor deprecated

func (*Running) Descriptor() ([]byte, []int)

Deprecated: Use Running.ProtoReflect.Descriptor instead.

func (*Running) ProtoMessage

func (*Running) ProtoMessage()

func (*Running) ProtoReflect

func (x *Running) ProtoReflect() protoreflect.Message

func (*Running) Reset

func (x *Running) Reset()

func (*Running) String

func (x *Running) String() string

type SourceError

type SourceError struct {

	// The index of the applet in Start.applets.
	Applet int32 `protobuf:"varint,1,opt,name=applet,proto3" json:"applet,omitempty"`
	// The step of building that found the problem.
	Step SourceError_Step `protobuf:"varint,2,opt,name=step,proto3,enum=applets.v1.SourceError_Step" json:"step,omitempty"`
	// The 1-based line in the source, or 0 if the problem is not on a line.
	Line int32 `protobuf:"varint,3,opt,name=line,proto3" json:"line,omitempty"`
	// The 1-based column in the source.
	Column int32 `protobuf:"varint,4,opt,name=column,proto3" json:"column,omitempty"`
	// The tsc error code of a type error, e.g. "TS2322".
	Code    string `protobuf:"bytes,5,opt,name=code,proto3" json:"code,omitempty"`
	Message string `protobuf:"bytes,6,opt,name=message,proto3" json:"message,omitempty"`
	// contains filtered or unexported fields
}

SourceError is a problem in the source of an applet, such as a type error or a syntax error.

func (*SourceError) Descriptor deprecated

func (*SourceError) Descriptor() ([]byte, []int)

Deprecated: Use SourceError.ProtoReflect.Descriptor instead.

func (*SourceError) GetApplet

func (x *SourceError) GetApplet() int32

func (*SourceError) GetCode

func (x *SourceError) GetCode() string

func (*SourceError) GetColumn

func (x *SourceError) GetColumn() int32

func (*SourceError) GetLine

func (x *SourceError) GetLine() int32

func (*SourceError) GetMessage

func (x *SourceError) GetMessage() string

func (*SourceError) GetStep

func (x *SourceError) GetStep() SourceError_Step

func (*SourceError) ProtoMessage

func (*SourceError) ProtoMessage()

func (*SourceError) ProtoReflect

func (x *SourceError) ProtoReflect() protoreflect.Message

func (*SourceError) Reset

func (x *SourceError) Reset()

func (*SourceError) String

func (x *SourceError) String() string

type SourceError_Step

type SourceError_Step int32
const (
	SourceError_STEP_UNSPECIFIED SourceError_Step = 0
	SourceError_TYPECHECK        SourceError_Step = 1
	SourceError_BUNDLE           SourceError_Step = 2
	SourceError_COMPILE          SourceError_Step = 3
)

func (SourceError_Step) Descriptor

func (SourceError_Step) Enum

func (SourceError_Step) EnumDescriptor deprecated

func (SourceError_Step) EnumDescriptor() ([]byte, []int)

Deprecated: Use SourceError_Step.Descriptor instead.

func (SourceError_Step) Number

func (SourceError_Step) String

func (x SourceError_Step) String() string

func (SourceError_Step) Type

type Start

type Start struct {

	// The applets run in this order: the input objects go to the first, the
	// output objects of each are the input objects of the next, and the
	// output objects of the last go to the client. There is at least one; the
	// server may limit how many.
	Applets []*Applet `protobuf:"bytes,1,rep,name=applets,proto3" json:"applets,omitempty"`
	// The content of a .d.ts file with the ambient modules the applets may
	// import types from, e.g. `declare module "shop" { ... }`.
	Declarations string  `protobuf:"bytes,2,opt,name=declarations,proto3" json:"declarations,omitempty"`
	Limits       *Limits `protobuf:"bytes,3,opt,name=limits,proto3" json:"limits,omitempty"`
	// contains filtered or unexported fields
}

func (*Start) Descriptor deprecated

func (*Start) Descriptor() ([]byte, []int)

Deprecated: Use Start.ProtoReflect.Descriptor instead.

func (*Start) GetApplets

func (x *Start) GetApplets() []*Applet

func (*Start) GetDeclarations

func (x *Start) GetDeclarations() string

func (*Start) GetLimits

func (x *Start) GetLimits() *Limits

func (*Start) ProtoMessage

func (*Start) ProtoMessage()

func (*Start) ProtoReflect

func (x *Start) ProtoReflect() protoreflect.Message

func (*Start) Reset

func (x *Start) Reset()

func (*Start) String

func (x *Start) String() string

type Stream

type Stream struct {
	// contains filtered or unexported fields
}

Stream is a stream whose applets the server has built, ready to run once.

func Open

func Open(ctx context.Context, client AppletsClient, start *Start) (*Stream, error)

Open opens a stream on client, sends start, and waits until the server has built the applets. If they do not build, it returns the *CompileError. If the server refuses start, it returns a gRPC status error. The stream ends when ctx is done, or after Run or Close.

func (*Stream) Close

func (s *Stream) Close()

Close ends the stream. A client that only wants to check that the applets build can Close the stream instead of running it. Close may also be called while Run runs, to stop it.

func (*Stream) Run

func (s *Stream) Run(input iter.Seq2[json.RawMessage, error], output func(json.RawMessage) error, log func(applet int, line string)) error

Run streams objects through the applets:

  • Run sends the objects of input to the first applet, and ends its input when input ends. The server asks for input while output arrives, so input is called from another goroutine than output and log. If input yields an error, the run stops and Run returns that error. If the run ends before the input does, the iteration's yield returns false.
  • For each object the last applet outputs, Run calls output. If output returns an error, the run stops and Run returns that error.
  • For each line an applet logs, Run calls log with the index of the applet in Start.Applets.

output and log are called one at a time. input may be nil for no input, and output and log may be nil to discard what the applets output or log.

Run returns nil if the run succeeded, an *Error if an applet failed, and a gRPC status error for problems with the request. It returns after input has stopped, and ends the stream. Run may be called once.

func (*Stream) RunAll

func (s *Stream) RunAll(inputs []json.RawMessage, log func(applet int, line string)) ([]json.RawMessage, error)

RunAll runs the applets on the given input objects, and returns their output objects. It holds all input and output in memory at once, so it is meant for small runs and tests; Run streams them instead. If the run fails, RunAll also returns the output objects from before the failure. It calls log, if not nil, for each line an applet logs.

type UnimplementedAppletsServer

type UnimplementedAppletsServer struct {
}

UnimplementedAppletsServer should be embedded to have forward compatible implementations.

func (UnimplementedAppletsServer) Run

type UnsafeAppletsServer

type UnsafeAppletsServer interface {
	// contains filtered or unexported methods
}

UnsafeAppletsServer may be embedded to opt out of forward compatibility for this service. Use of this interface is not recommended, as added methods to AppletsServer will result in compilation errors.

Jump to

Keyboard shortcuts

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