runtime
import "github.com/nathabonfim59/pbvex/backend/internal/runtime"Index
- func ManifestFromContext(ctx context.Context) (deploy.DeploymentManifest, bool)
- func WithAuthContext(ctx context.Context, auth AuthContext) context.Context
- func WithScheduleNamespaces(ctx context.Context, owner, target string) context.Context
- type AuthContext
- type Bridge
- type Config
- type ContextExtender
- type Invocation
- type Manager
- func NewManager(config Config) *Manager
- func (m *Manager) AddContextExtender(ext ContextExtender)
- func (m *Manager) Compile(deploymentID, bundle string, descriptors []deploy.FunctionDescriptor, configs ...deploy.DeploymentConfig) error
- func (m *Manager) CompileDeployment(deploymentID, bundle string, descriptors []deploy.FunctionDescriptor, migrations []deploy.MigrationDescriptor, configs ...deploy.DeploymentConfig) error
- func (m *Manager) Drop(deploymentID string)
- func (m *Manager) Invoke(ctx context.Context, deploymentID, functionName string, args any, authArgs ...any) (any, error)
- func (m *Manager) InvokeHTTP(ctx context.Context, deploymentID, functionName string, httpEnvelope *deploy.HTTPRequestEnvelope, identity *auth.UserIdentity, requestID string) (*deploy.HTTPResponseEnvelope, error)
- func (m *Manager) InvokeHTTPWithDatabase(ctx context.Context, deploymentID, functionName string, httpEnvelope *deploy.HTTPRequestEnvelope, identity *auth.UserIdentity, requestID string, app core.App, manifest deploy.DeploymentManifest) (*deploy.HTTPResponseEnvelope, error)
- func (m *Manager) InvokeMigration(ctx context.Context, deploymentID, migrationID, direction string, document any, activationTime int64) (any, error)
- func (m *Manager) InvokeWithDatabase(ctx context.Context, deploymentID, functionName string, args any, extra ...any) (any, error)
- func (m *Manager) Verify(ctx context.Context, deploymentID, bundle string, descriptors []deploy.FunctionDescriptor) error
- func (m *Manager) VerifyDeployment(ctx context.Context, deploymentID, bundle string, descriptors []deploy.FunctionDescriptor, migrations []deploy.MigrationDescriptor) error
- type MigrationError
- type Pool
- type RuntimeInvoker
- type ScheduleNamespaces
- type Scheduler
- type WireLimitError
func ManifestFromContext
func ManifestFromContext(ctx context.Context) (deploy.DeploymentManifest, bool)ManifestFromContext exposes the authenticated deployment snapshot to host capabilities.
func WithAuthContext
func WithAuthContext(ctx context.Context, auth AuthContext) context.ContextWithAuthContext returns a context that carries the auth context.
func WithScheduleNamespaces
func WithScheduleNamespaces(ctx context.Context, owner, target string) context.ContextWithScheduleNamespaces binds durable component ownership to a scheduler operation without changing the public Scheduler interface.
type AuthContext
AuthContext carries the identity of the caller into the runtime so that storage and other host services can bind capabilities to the requester.
type AuthContext struct {
IsAuthenticated bool
// TokenIdentifier is stable across collection renames and globally unique
// across PocketBase auth collections.
TokenIdentifier string
Identity *auth.UserIdentity
RequestID string
}func AuthFromContext
func AuthFromContext(ctx context.Context) (AuthContext, bool)AuthFromContext extracts the auth context, if any.
type Bridge
Bridge is the host bridge exposed to the JS bundle.
type Bridge struct {
// contains filtered or unexported fields
}func (*Bridge) RegisterFunction
func (b *Bridge) RegisterFunction(descriptor goja.Value, handler goja.Value) errorRegisterFunction implements globalThis.__pbvex.registerFunction(descriptor, handler).
func (*Bridge) RegisterMigration
func (b *Bridge) RegisterMigration(descriptor, up, down goja.Value) errorRegisterMigration implements __pbvex.registerMigration(descriptor, up, down).
func (*Bridge) Verify
func (b *Bridge) Verify(descriptors []deploy.FunctionDescriptor, migrations []deploy.MigrationDescriptor) errorVerify ensures every manifest function is registered and descriptors match exactly.
type Config
Config controls the Goja runtime pool.
type Config struct {
PoolSize int
Timeout time.Duration
}func DefaultConfig
func DefaultConfig() ConfigDefaultConfig returns the default runtime pool configuration.
type ContextExtender
ContextExtender extends the JS invocation context with host capabilities (such as storage and auth) that live outside the runtime package. It is invoked after the runtime builds the base context object so the registrar can attach services without the runtime depending on them directly.
type ContextExtender func(vm *goja.Runtime, ctx context.Context, app core.App, fd deploy.FunctionDescriptor, obj *goja.Object) errortype Invocation
Invocation carries request-scoped context for a single function invocation. It is immutable except for the context/deadline information and the nested call bookkeeping.
type Invocation struct {
// Ctx is the caller context for cancellation and deadlines.
Ctx context.Context
// Identity is the authenticated user identity for this invocation, or nil
// for unauthenticated requests.
Identity *auth.UserIdentity
// RequestID is the request identifier propagated through HTTP/realtime and
// nested calls.
RequestID string
// DeploymentID identifies the deployment whose runtime is used.
DeploymentID string
// FunctionType is the type of the function being invoked.
FunctionType deploy.FunctionType
FunctionName string
// Namespace is root or the deterministic component namespace selected by
// the target function descriptor.
Namespace string
// HTTPRequest is the parsed HTTP request envelope for httpAction calls.
HTTPRequest *deploy.HTTPRequestEnvelope
// App and Manifest are set for database-aware invocations. When App is nil,
// the runtime uses no-op stubs for db/storage/scheduler.
App core.App
Manifest deploy.DeploymentManifest
// MaxArgsBytes and MaxReturnBytes are wire size limits from the manifest.
MaxArgsBytes int64
MaxReturnBytes int64
RequestTimeout time.Duration
// Depth is the current nested call depth (0 for the outer invocation).
Depth int
// Work is a shared, nonrefundable cumulative counter for all nested calls
// in the invocation tree. It is a pointer so that parent, child, and
// sibling calls all observe the same monotonically increasing budget.
Work *int
// NestedInvoke dispatches nested calls through a fresh runtime entry while
// preserving this invocation tree's request-scoped state.
NestedInvoke func(parent *Invocation, functionName string, targetType deploy.FunctionType, args any, depth int) (any, error)
}type Manager
Manager is a registry of bounded Goja runtime pools keyed by deployment id.
type Manager struct {
Scheduler Scheduler
// contains filtered or unexported fields
}func NewManager
func NewManager(config Config) *ManagerNewManager creates a new runtime manager.
func (*Manager) AddContextExtender
func (m *Manager) AddContextExtender(ext ContextExtender)AddContextExtender appends a host capability hook. Hooks run in registration order after the runtime has installed its base database capability and before the scheduler capability is attached. Existing pools are dropped so a hook registered after compilation cannot be silently omitted.
func (*Manager) Compile
func (m *Manager) Compile(deploymentID, bundle string, descriptors []deploy.FunctionDescriptor, configs ...deploy.DeploymentConfig) errorCompile compiles and stores the bundle program for a deployment.
func (*Manager) CompileDeployment
func (m *Manager) CompileDeployment(deploymentID, bundle string, descriptors []deploy.FunctionDescriptor, migrations []deploy.MigrationDescriptor, configs ...deploy.DeploymentConfig) errorCompileDeployment stores both function and migration registration contracts.
func (*Manager) Drop
func (m *Manager) Drop(deploymentID string)Drop removes an invalidated deployment runtime (trim, deletion, rollback transitions). It is safe for in-flight callers: they hold the old pool.
func (*Manager) Invoke
func (m *Manager) Invoke(ctx context.Context, deploymentID, functionName string, args any, authArgs ...any) (any, error)Invoke runs the named function in a fresh bounded runtime.
func (*Manager) InvokeHTTP
func (m *Manager) InvokeHTTP(ctx context.Context, deploymentID, functionName string, httpEnvelope *deploy.HTTPRequestEnvelope, identity *auth.UserIdentity, requestID string) (*deploy.HTTPResponseEnvelope, error)InvokeHTTP runs the named httpAction and returns an HTTP response envelope.
func (*Manager) InvokeHTTPWithDatabase
func (m *Manager) InvokeHTTPWithDatabase(ctx context.Context, deploymentID, functionName string, httpEnvelope *deploy.HTTPRequestEnvelope, identity *auth.UserIdentity, requestID string, app core.App, manifest deploy.DeploymentManifest) (*deploy.HTTPResponseEnvelope, error)InvokeHTTPWithDatabase preserves the app and manifest snapshot for nested calls issued by an HTTP action.
func (*Manager) InvokeMigration
func (m *Manager) InvokeMigration(ctx context.Context, deploymentID, migrationID, direction string, document any, activationTime int64) (any, error)InvokeMigration executes a pure synchronous up/down handler. The caller owns the surrounding database transaction; this method never starts one.
func (*Manager) InvokeWithDatabase
func (m *Manager) InvokeWithDatabase(ctx context.Context, deploymentID, functionName string, args any, extra ...any) (any, error)InvokeWithDatabase is used by deploy.Service for real requests that need database access. Mutations are wrapped in a PocketBase transaction so that invalid returns, timeouts, and cancellations roll back all writes.
func (*Manager) Verify
func (m *Manager) Verify(ctx context.Context, deploymentID, bundle string, descriptors []deploy.FunctionDescriptor) errorVerify loads the bundle in a fresh runtime and confirms that every declared function is registered with an exact descriptor match.
func (*Manager) VerifyDeployment
func (m *Manager) VerifyDeployment(ctx context.Context, deploymentID, bundle string, descriptors []deploy.FunctionDescriptor, migrations []deploy.MigrationDescriptor) errorVerifyDeployment requires exact function and migration registration parity.
type MigrationError
MigrationError is the bounded, document-free failure produced by ctx.fail.
type MigrationError struct{ Message string }func (*MigrationError) Error
func (e *MigrationError) Error() stringtype Pool
Pool is a bounded concurrency gate for Goja runtimes for a single deployment.
type Pool struct {
// contains filtered or unexported fields
}type RuntimeInvoker
RuntimeInvoker is the interface used by the deploy service.
type RuntimeInvoker interface {
Compile(deploymentID, bundle string, descriptors []deploy.FunctionDescriptor, config ...deploy.DeploymentConfig) error
Verify(ctx context.Context, deploymentID, bundle string, descriptors []deploy.FunctionDescriptor) error
Invoke(ctx context.Context, deploymentID, functionName string, args any, authArgs ...any) (any, error)
InvokeHTTP(ctx context.Context, deploymentID, functionName string, httpEnvelope *deploy.HTTPRequestEnvelope, identity *auth.UserIdentity, requestID string) (*deploy.HTTPResponseEnvelope, error)
}type ScheduleNamespaces
type ScheduleNamespaces struct {
Owner string
Target string
}func ScheduleNamespacesFromContext
func ScheduleNamespacesFromContext(ctx context.Context) (ScheduleNamespaces, bool)type Scheduler
Scheduler is the capability exposed to mutations and actions.
type Scheduler interface {
RunAfter(ctx context.Context, delayMs int64, deploymentID, functionName string, args any) (string, error)
RunAt(ctx context.Context, epochMs int64, deploymentID, functionName string, args any) (string, error)
Cancel(ctx context.Context, jobID string) error
}type WireLimitError
WireLimitError distinguishes adversarial resource-limit failures from a malformed ordinary value. Callers intentionally turn both into the same structured public error, but the type keeps tests and hosts from treating a rejected sparse array as an internal Go failure.
type WireLimitError struct{ Limit string }func (*WireLimitError) Error
func (e *WireLimitError) Error() stringGenerated by gomarkdoc