registry

package
v0.90.0 Latest Latest
Warning

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

Go to latest
Published: Jan 20, 2026 License: AGPL-3.0 Imports: 11 Imported by: 0

Documentation

Overview

Package registry manages function metadata in RQLite and bytecode in IPFS.

Index

Constants

This section is empty.

Variables

View Source
var ErrFunctionNotFound = &NotFoundError{Resource: "function"}

Error types

View Source
var ErrVersionNotFound = &NotFoundError{Resource: "version"}

Functions

This section is empty.

Types

type DeployError

type DeployError struct {
	FunctionName string
	Cause        error
}

func (*DeployError) Error

func (e *DeployError) Error() string

func (*DeployError) Unwrap

func (e *DeployError) Unwrap() error

type Function

type Function struct {
	ID                string
	Name              string
	Namespace         string
	Version           int
	WASMCID           string
	SourceCID         string
	MemoryLimitMB     int
	TimeoutSeconds    int
	IsPublic          bool
	RetryCount        int
	RetryDelaySeconds int
	DLQTopic          string
	Status            FunctionStatus
	CreatedAt         time.Time
	UpdatedAt         time.Time
	CreatedBy         string
}

Function represents a deployed serverless function.

type FunctionDefinition

type FunctionDefinition struct {
	Name              string
	Namespace         string
	Version           int
	MemoryLimitMB     int
	TimeoutSeconds    int
	IsPublic          bool
	RetryCount        int
	RetryDelaySeconds int
	DLQTopic          string
	EnvVars           map[string]string
}

FunctionDefinition contains the configuration for deploying a function.

type FunctionRegistry

type FunctionRegistry interface {
	Register(ctx context.Context, fn *FunctionDefinition, wasmBytes []byte) (*Function, error)
	Get(ctx context.Context, namespace, name string, version int) (*Function, error)
	List(ctx context.Context, namespace string) ([]*Function, error)
	Delete(ctx context.Context, namespace, name string, version int) error
	GetWASMBytes(ctx context.Context, wasmCID string) ([]byte, error)
	GetLogs(ctx context.Context, namespace, name string, limit int) ([]LogEntry, error)
}

FunctionRegistry interface

type FunctionStatus

type FunctionStatus string

FunctionStatus represents the current state of a deployed function.

const (
	FunctionStatusActive   FunctionStatus = "active"
	FunctionStatusInactive FunctionStatus = "inactive"
	FunctionStatusError    FunctionStatus = "error"
)

type FunctionStore

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

FunctionStore handles database operations for function metadata.

func NewFunctionStore

func NewFunctionStore(db rqlite.Client, logger *zap.Logger) *FunctionStore

NewFunctionStore creates a new function store.

func (*FunctionStore) Delete

func (s *FunctionStore) Delete(ctx context.Context, namespace, name string, version int) error

Delete marks a function as inactive (soft delete).

func (*FunctionStore) Get

func (s *FunctionStore) Get(ctx context.Context, namespace, name string, version int) (*Function, error)

Get retrieves a function by name and optional version.

func (*FunctionStore) GetByID

func (s *FunctionStore) GetByID(ctx context.Context, id string) (*Function, error)

GetByID retrieves a function by its ID.

func (*FunctionStore) GetByNameInternal

func (s *FunctionStore) GetByNameInternal(ctx context.Context, namespace, name string) (*Function, error)

GetByNameInternal retrieves a function by name regardless of status.

func (*FunctionStore) GetEnvVars

func (s *FunctionStore) GetEnvVars(ctx context.Context, functionID string) (map[string]string, error)

GetEnvVars retrieves environment variables for a function.

func (*FunctionStore) List

func (s *FunctionStore) List(ctx context.Context, namespace string) ([]*Function, error)

List returns all active functions for a namespace.

func (*FunctionStore) ListVersions

func (s *FunctionStore) ListVersions(ctx context.Context, namespace, name string) ([]*Function, error)

ListVersions returns all versions of a function.

func (*FunctionStore) Save

func (s *FunctionStore) Save(ctx context.Context, fn *FunctionDefinition, wasmCID string, existingFunc *Function) (*Function, error)

Save inserts or updates a function in the database.

func (*FunctionStore) SaveEnvVars

func (s *FunctionStore) SaveEnvVars(ctx context.Context, functionID string, envVars map[string]string) error

SaveEnvVars saves environment variables for a function.

type IPFSStore

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

IPFSStore handles IPFS storage operations for WASM bytecode.

func NewIPFSStore

func NewIPFSStore(ipfsClient ipfs.IPFSClient, ipfsAPIURL string, logger *zap.Logger) *IPFSStore

NewIPFSStore creates a new IPFS store.

func (*IPFSStore) Get

func (s *IPFSStore) Get(ctx context.Context, wasmCID string) ([]byte, error)

Get retrieves WASM bytecode from IPFS by CID.

func (*IPFSStore) Upload

func (s *IPFSStore) Upload(ctx context.Context, wasmBytes []byte, name string) (string, error)

Upload uploads WASM bytecode to IPFS and returns the CID.

type InvocationLogger

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

InvocationLogger handles logging of function invocations and their logs.

func NewInvocationLogger

func NewInvocationLogger(db rqlite.Client, logger *zap.Logger) *InvocationLogger

NewInvocationLogger creates a new invocation logger.

func (*InvocationLogger) GetLogs

func (l *InvocationLogger) GetLogs(ctx context.Context, namespace, name string, limit int) ([]LogEntry, error)

GetLogs retrieves logs for a function.

func (*InvocationLogger) Log

Log records a function invocation and its logs to the database.

type InvocationRecordData

type InvocationRecordData struct {
	ID           string
	FunctionID   string
	RequestID    string
	TriggerType  string
	CallerWallet string
	InputSize    int
	OutputSize   int
	StartedAt    time.Time
	CompletedAt  time.Time
	DurationMS   int64
	Status       string
	ErrorMessage string
	MemoryUsedMB float64
	Logs         []LogData
}

type LogData

type LogData struct {
	Level     string
	Message   string
	Timestamp time.Time
}

type LogEntry

type LogEntry struct {
	Level     string
	Message   string
	Timestamp time.Time
}

LogEntry represents a log message from a function.

type NotFoundError

type NotFoundError struct {
	Resource string
}

func (*NotFoundError) Error

func (e *NotFoundError) Error() string

type Registry

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

Registry coordinates between function storage, IPFS storage, and logging.

func NewRegistry

func NewRegistry(db rqlite.Client, ipfsClient ipfs.IPFSClient, cfg RegistryConfig, logger *zap.Logger) *Registry

NewRegistry creates a new function registry.

func (*Registry) Delete

func (r *Registry) Delete(ctx context.Context, namespace, name string, version int) error

Delete removes a function. If version is 0, removes all versions.

func (*Registry) Get

func (r *Registry) Get(ctx context.Context, namespace, name string, version int) (*Function, error)

Get retrieves a function by name and optional version.

func (*Registry) GetByID

func (r *Registry) GetByID(ctx context.Context, id string) (*Function, error)

GetByID retrieves a function by its ID.

func (*Registry) GetEnvVars

func (r *Registry) GetEnvVars(ctx context.Context, functionID string) (map[string]string, error)

GetEnvVars retrieves environment variables for a function.

func (*Registry) GetLogs

func (r *Registry) GetLogs(ctx context.Context, namespace, name string, limit int) ([]LogEntry, error)

GetLogs retrieves logs for a function.

func (*Registry) GetWASMBytes

func (r *Registry) GetWASMBytes(ctx context.Context, wasmCID string) ([]byte, error)

GetWASMBytes retrieves the compiled WASM bytecode for a function.

func (*Registry) List

func (r *Registry) List(ctx context.Context, namespace string) ([]*Function, error)

List returns all functions for a namespace.

func (*Registry) ListVersions

func (r *Registry) ListVersions(ctx context.Context, namespace, name string) ([]*Function, error)

ListVersions returns all versions of a function.

func (*Registry) LogInvocation

func (r *Registry) LogInvocation(ctx context.Context,
	id, functionID, requestID string,
	triggerType interface{},
	callerWallet string,
	inputSize, outputSize int,
	startedAt, completedAt interface{},
	durationMS int64,
	status interface{},
	errorMessage string,
	memoryUsedMB float64,
	logs []LogEntry) error

LogInvocation records a function invocation and its logs to the database.

func (*Registry) Register

func (r *Registry) Register(ctx context.Context, fn *FunctionDefinition, wasmBytes []byte) (*Function, error)

Register deploys a new function or updates an existing one.

type RegistryConfig

type RegistryConfig struct {
	IPFSAPIURL string
}

RegistryConfig holds configuration for the Registry.

type ValidationError

type ValidationError struct {
	Field   string
	Message string
}

func (*ValidationError) Error

func (e *ValidationError) Error() string

Jump to

Keyboard shortcuts

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