Documentation
¶
Overview ¶
Package store provides database interfaces and types for the Lunar application. It defines the DB interface for function, version, and execution operations, along with core data types used throughout the application.
Index ¶
- Variables
- type AIRequest
- type AIRequestStatus
- type APIToken
- type CronStatus
- type DB
- type EmailRequest
- type EmailRequestStatus
- type Execution
- type ExecutionStatus
- type ExecutionTrigger
- type Function
- type FunctionVersion
- type FunctionWithActiveVersion
- type LogLevel
- type MemoryDB
- func (db *MemoryDB) ActivateVersion(_ context.Context, versionID string) error
- func (db *MemoryDB) CreateAPIToken(_ context.Context, token APIToken) (APIToken, error)
- func (db *MemoryDB) CreateExecution(_ context.Context, exec Execution) (Execution, error)
- func (db *MemoryDB) CreateFunction(_ context.Context, fn Function) (Function, error)
- func (db *MemoryDB) CreateVersion(_ context.Context, functionID string, code string, createdBy *string) (FunctionVersion, error)
- func (db *MemoryDB) DeleteFunction(_ context.Context, id string) error
- func (db *MemoryDB) DeleteOldExecutions(_ context.Context, beforeTimestamp int64) (int64, error)
- func (db *MemoryDB) DeleteVersion(_ context.Context, versionID string) error
- func (db *MemoryDB) GetAPITokenByHash(_ context.Context, tokenHash string) (APIToken, error)
- func (db *MemoryDB) GetActiveVersion(_ context.Context, functionID string) (FunctionVersion, error)
- func (db *MemoryDB) GetExecution(_ context.Context, executionID string) (Execution, error)
- func (db *MemoryDB) GetFunction(_ context.Context, id string) (Function, error)
- func (db *MemoryDB) GetVersion(_ context.Context, functionID string, version int) (FunctionVersion, error)
- func (db *MemoryDB) GetVersionByID(_ context.Context, versionID string) (FunctionVersion, error)
- func (db *MemoryDB) ListAPITokens(_ context.Context) ([]APIToken, error)
- func (db *MemoryDB) ListExecutions(_ context.Context, functionID string, params PaginationParams) ([]Execution, int64, error)
- func (db *MemoryDB) ListFunctions(_ context.Context, params PaginationParams) ([]FunctionWithActiveVersion, int64, error)
- func (db *MemoryDB) ListFunctionsWithActiveCron(_ context.Context) ([]Function, error)
- func (db *MemoryDB) ListVersions(_ context.Context, functionID string, params PaginationParams) ([]FunctionVersion, int64, error)
- func (db *MemoryDB) Ping(_ context.Context) error
- func (db *MemoryDB) RevokeAPIToken(_ context.Context, id string) error
- func (db *MemoryDB) UpdateAPITokenLastUsed(_ context.Context, id string, timestamp int64) error
- func (db *MemoryDB) UpdateExecution(_ context.Context, executionID string, status ExecutionStatus, ...) error
- func (db *MemoryDB) UpdateFunction(_ context.Context, id string, updates UpdateFunctionRequest) error
- type PaginationInfo
- type PaginationParams
- type SQLiteDB
- func (db *SQLiteDB) ActivateVersion(ctx context.Context, versionID string) error
- func (db *SQLiteDB) CreateAPIToken(ctx context.Context, token APIToken) (APIToken, error)
- func (db *SQLiteDB) CreateExecution(ctx context.Context, exec Execution) (Execution, error)
- func (db *SQLiteDB) CreateFunction(ctx context.Context, fn Function) (Function, error)
- func (db *SQLiteDB) CreateVersion(ctx context.Context, functionID string, code string, createdBy *string) (FunctionVersion, error)
- func (db *SQLiteDB) DeleteFunction(ctx context.Context, id string) error
- func (db *SQLiteDB) DeleteOldExecutions(ctx context.Context, beforeTimestamp int64) (int64, error)
- func (db *SQLiteDB) DeleteVersion(ctx context.Context, versionID string) error
- func (db *SQLiteDB) GetAPITokenByHash(ctx context.Context, tokenHash string) (APIToken, error)
- func (db *SQLiteDB) GetActiveVersion(ctx context.Context, functionID string) (FunctionVersion, error)
- func (db *SQLiteDB) GetExecution(ctx context.Context, executionID string) (Execution, error)
- func (db *SQLiteDB) GetFunction(ctx context.Context, id string) (Function, error)
- func (db *SQLiteDB) GetVersion(ctx context.Context, functionID string, version int) (FunctionVersion, error)
- func (db *SQLiteDB) GetVersionByID(ctx context.Context, versionID string) (FunctionVersion, error)
- func (db *SQLiteDB) ListAPITokens(ctx context.Context) ([]APIToken, error)
- func (db *SQLiteDB) ListExecutions(ctx context.Context, functionID string, params PaginationParams) ([]Execution, int64, error)
- func (db *SQLiteDB) ListFunctions(ctx context.Context, params PaginationParams) ([]FunctionWithActiveVersion, int64, error)
- func (db *SQLiteDB) ListFunctionsWithActiveCron(ctx context.Context) ([]Function, error)
- func (db *SQLiteDB) ListVersions(ctx context.Context, functionID string, params PaginationParams) ([]FunctionVersion, int64, error)
- func (db *SQLiteDB) Ping(ctx context.Context) error
- func (db *SQLiteDB) RevokeAPIToken(ctx context.Context, id string) error
- func (db *SQLiteDB) UpdateAPITokenLastUsed(ctx context.Context, id string, timestamp int64) error
- func (db *SQLiteDB) UpdateExecution(ctx context.Context, executionID string, status ExecutionStatus, ...) error
- func (db *SQLiteDB) UpdateFunction(ctx context.Context, id string, updates UpdateFunctionRequest) error
- type UpdateFunctionRequest
Constants ¶
This section is empty.
Variables ¶
var ( ErrFunctionNotFound = errors.New("function not found") ErrVersionNotFound = errors.New("version not found") ErrNoActiveVersion = errors.New("no active version") ErrExecutionNotFound = errors.New("execution not found") ErrCannotDeleteActiveVersion = errors.New("cannot delete active version") ErrAPITokenNotFound = errors.New("api token not found") )
Functions ¶
This section is empty.
Types ¶
type AIRequest ¶
type AIRequest struct {
ID string `json:"id"`
ExecutionID string `json:"execution_id"`
Provider string `json:"provider"`
Model string `json:"model"`
Endpoint string `json:"endpoint"`
RequestJSON string `json:"request_json"`
ResponseJSON *string `json:"response_json,omitempty"`
Status AIRequestStatus `json:"status"`
ErrorMessage *string `json:"error_message,omitempty"`
InputTokens *int `json:"input_tokens,omitempty"`
OutputTokens *int `json:"output_tokens,omitempty"`
DurationMs int64 `json:"duration_ms"`
CreatedAt int64 `json:"created_at"`
}
AIRequest represents a tracked AI API request
type AIRequestStatus ¶
type AIRequestStatus string
AIRequestStatus represents the status of an AI API request
const ( AIRequestStatusSuccess AIRequestStatus = "success" AIRequestStatusError AIRequestStatus = "error" )
type APIToken ¶
type APIToken struct {
ID string `json:"id"`
TokenHash string `json:"-"`
Name string `json:"name"`
CreatedAt int64 `json:"created_at"`
LastUsed *int64 `json:"last_used,omitempty"`
Revoked bool `json:"revoked"`
}
APIToken represents a stored API token for CLI authentication
type CronStatus ¶
type CronStatus string
CronStatus represents the status of a cron schedule
const ( CronStatusActive CronStatus = "active" CronStatusPaused CronStatus = "paused" )
type DB ¶
type DB interface {
// CreateFunction creates a new function. Returns the created function with
// timestamps populated.
CreateFunction(ctx context.Context, fn Function) (Function, error)
// GetFunction retrieves a function by ID.
// Returns ErrFunctionNotFound if the function does not exist.
GetFunction(ctx context.Context, id string) (Function, error)
// ListFunctions returns paginated functions with their active versions.
ListFunctions(ctx context.Context, params PaginationParams) ([]FunctionWithActiveVersion, int64, error)
// UpdateFunction updates a function's fields.
// Returns ErrFunctionNotFound if the function does not exist.
UpdateFunction(ctx context.Context, id string, updates UpdateFunctionRequest) error
// DeleteFunction removes a function and its associated data.
// Returns ErrFunctionNotFound if the function does not exist.
DeleteFunction(ctx context.Context, id string) error
// CreateVersion creates a new version for a function and sets it as active.
// Returns ErrFunctionNotFound if the function does not exist.
CreateVersion(ctx context.Context, functionID string, code string, createdBy *string) (FunctionVersion, error)
// GetVersion retrieves a specific version by function ID and version number.
// Returns ErrVersionNotFound if the version does not exist.
GetVersion(ctx context.Context, functionID string, version int) (FunctionVersion, error)
// GetVersionByID retrieves a version by its unique ID.
// Returns ErrVersionNotFound if the version does not exist.
GetVersionByID(ctx context.Context, versionID string) (FunctionVersion, error)
// ListVersions returns paginated versions for a function.
ListVersions(ctx context.Context, functionID string, params PaginationParams) ([]FunctionVersion, int64, error)
// GetActiveVersion retrieves the currently active version for a function.
// Returns ErrNoActiveVersion if no version is active.
GetActiveVersion(ctx context.Context, functionID string) (FunctionVersion, error)
// ActivateVersion sets a specific version as the active version by its ID.
// Returns ErrVersionNotFound if the version does not exist.
ActivateVersion(ctx context.Context, versionID string) error
// DeleteVersion removes a specific version by its ID.
// Returns ErrVersionNotFound if the version does not exist.
// Returns ErrCannotDeleteActiveVersion if attempting to delete the active version.
DeleteVersion(ctx context.Context, versionID string) error
// CreateExecution records a new execution. Returns the execution with
// timestamps populated.
CreateExecution(ctx context.Context, exec Execution) (Execution, error)
// GetExecution retrieves an execution by ID.
// Returns ErrExecutionNotFound if the execution does not exist.
GetExecution(ctx context.Context, executionID string) (Execution, error)
// UpdateExecution updates an execution's status and results.
// Returns ErrExecutionNotFound if the execution does not exist.
UpdateExecution(ctx context.Context, executionID string, status ExecutionStatus, durationMs *int64, errorMsg *string, responseJSON *string) error
// ListExecutions returns paginated executions for a function.
ListExecutions(ctx context.Context, functionID string, params PaginationParams) ([]Execution, int64, error)
// DeleteOldExecutions removes executions older than the given timestamp.
// Returns the number of deleted records.
DeleteOldExecutions(ctx context.Context, beforeTimestamp int64) (int64, error)
// ListFunctionsWithActiveCron returns all functions that have an active cron schedule.
ListFunctionsWithActiveCron(ctx context.Context) ([]Function, error)
// Ping verifies the database connection is alive.
Ping(ctx context.Context) error
// CreateAPIToken stores a new API token.
CreateAPIToken(ctx context.Context, token APIToken) (APIToken, error)
// GetAPITokenByHash retrieves a non-revoked API token by its hash.
// Returns ErrAPITokenNotFound if no matching token exists.
GetAPITokenByHash(ctx context.Context, tokenHash string) (APIToken, error)
// ListAPITokens returns all API tokens ordered by creation date.
ListAPITokens(ctx context.Context) ([]APIToken, error)
// RevokeAPIToken marks an API token as revoked.
// Returns ErrAPITokenNotFound if the token does not exist.
RevokeAPIToken(ctx context.Context, id string) error
// UpdateAPITokenLastUsed updates the last_used timestamp for a token.
UpdateAPITokenLastUsed(ctx context.Context, id string, timestamp int64) error
}
DB defines the database interface for the Lunar API.
type EmailRequest ¶
type EmailRequest struct {
ID string `json:"id"`
ExecutionID string `json:"execution_id"`
From string `json:"from"`
To []string `json:"to"`
Subject string `json:"subject"`
HasText bool `json:"has_text"`
HasHTML bool `json:"has_html"`
RequestJSON string `json:"request_json"`
ResponseJSON *string `json:"response_json,omitempty"`
Status EmailRequestStatus `json:"status"`
ErrorMessage *string `json:"error_message,omitempty"`
EmailID *string `json:"email_id,omitempty"`
DurationMs int64 `json:"duration_ms"`
CreatedAt int64 `json:"created_at"`
}
EmailRequest represents a tracked email send request
type EmailRequestStatus ¶
type EmailRequestStatus string
EmailRequestStatus represents the status of an email request
const ( EmailRequestStatusSuccess EmailRequestStatus = "success" EmailRequestStatusError EmailRequestStatus = "error" )
type Execution ¶
type Execution struct {
ID string `json:"id"`
FunctionID string `json:"function_id"`
FunctionVersionID string `json:"function_version_id"`
Status ExecutionStatus `json:"status"`
DurationMs *int64 `json:"duration_ms,omitempty"`
ErrorMessage *string `json:"error_message,omitempty"`
EventJSON *string `json:"event_json,omitempty"`
ResponseJSON *string `json:"response_json,omitempty"`
Trigger ExecutionTrigger `json:"trigger"`
CreatedAt int64 `json:"created_at"`
}
Execution represents a function execution record
type ExecutionStatus ¶
type ExecutionStatus string
ExecutionStatus represents the status of a function execution
const ( ExecutionStatusPending ExecutionStatus = "pending" ExecutionStatusSuccess ExecutionStatus = "success" ExecutionStatusError ExecutionStatus = "error" )
type ExecutionTrigger ¶
type ExecutionTrigger string
ExecutionTrigger represents how an execution was triggered
const ( ExecutionTriggerHTTP ExecutionTrigger = "http" ExecutionTriggerCron ExecutionTrigger = "cron" )
type Function ¶
type Function struct {
ID string `json:"id"`
Name string `json:"name"`
Description *string `json:"description,omitempty"`
EnvVars map[string]string `json:"env_vars"`
Disabled bool `json:"disabled"`
RetentionDays *int `json:"retention_days,omitempty"`
CronSchedule *string `json:"cron_schedule,omitempty"`
CronStatus *string `json:"cron_status,omitempty"`
SaveResponse bool `json:"save_response"`
CreatedAt int64 `json:"created_at"`
UpdatedAt int64 `json:"updated_at"`
ScopedData map[string]string `json:"scoped_data"`
GlobalData map[string]string `json:"global_data"`
}
Function represents a serverless function
type FunctionVersion ¶
type FunctionVersion struct {
ID string `json:"id"`
FunctionID string `json:"function_id"`
Version int `json:"version"`
Code string `json:"code"`
CreatedAt int64 `json:"created_at"`
CreatedBy *string `json:"created_by,omitempty"`
IsActive bool `json:"is_active"`
}
FunctionVersion represents a specific version of a function
type FunctionWithActiveVersion ¶
type FunctionWithActiveVersion struct {
Function
ActiveVersion FunctionVersion `json:"active_version"`
}
FunctionWithActiveVersion includes the function and its active version
type MemoryDB ¶
type MemoryDB struct {
// contains filtered or unexported fields
}
MemoryDB is an in-memory implementation of the DB interface
func (*MemoryDB) ActivateVersion ¶
func (*MemoryDB) CreateAPIToken ¶
func (*MemoryDB) CreateExecution ¶
func (*MemoryDB) CreateFunction ¶
func (*MemoryDB) CreateVersion ¶
func (*MemoryDB) DeleteFunction ¶
func (*MemoryDB) DeleteOldExecutions ¶
func (*MemoryDB) DeleteVersion ¶
func (*MemoryDB) GetAPITokenByHash ¶
func (*MemoryDB) GetActiveVersion ¶
func (*MemoryDB) GetExecution ¶
func (*MemoryDB) GetFunction ¶
func (*MemoryDB) GetVersion ¶
func (*MemoryDB) GetVersionByID ¶
func (*MemoryDB) ListAPITokens ¶
func (*MemoryDB) ListExecutions ¶
func (*MemoryDB) ListFunctions ¶
func (db *MemoryDB) ListFunctions(_ context.Context, params PaginationParams) ([]FunctionWithActiveVersion, int64, error)
func (*MemoryDB) ListFunctionsWithActiveCron ¶
func (*MemoryDB) ListVersions ¶
func (db *MemoryDB) ListVersions(_ context.Context, functionID string, params PaginationParams) ([]FunctionVersion, int64, error)
func (*MemoryDB) RevokeAPIToken ¶
func (*MemoryDB) UpdateAPITokenLastUsed ¶
func (*MemoryDB) UpdateExecution ¶
func (*MemoryDB) UpdateFunction ¶
type PaginationInfo ¶
type PaginationInfo struct {
Total int64 `json:"total"` // Total number of items
Limit int `json:"limit"` // Items per page
Offset int `json:"offset"` // Items skipped
}
PaginationInfo contains pagination metadata
type PaginationParams ¶
type PaginationParams struct {
Limit int // Number of items per page (default: 20, max: 100)
Offset int // Number of items to skip (default: 0)
}
PaginationParams contains pagination parameters
func (PaginationParams) Normalize ¶
func (p PaginationParams) Normalize() PaginationParams
Normalize applies defaults and constraints to pagination parameters
type SQLiteDB ¶
type SQLiteDB struct {
// contains filtered or unexported fields
}
SQLiteDB is an SQLite implementation of the DB interface
func NewSQLiteDB ¶
NewSQLiteDB creates a new SQLite-backed API database
func (*SQLiteDB) ActivateVersion ¶
func (*SQLiteDB) CreateAPIToken ¶
func (*SQLiteDB) CreateExecution ¶
func (*SQLiteDB) CreateFunction ¶
func (*SQLiteDB) CreateVersion ¶
func (*SQLiteDB) DeleteFunction ¶
func (*SQLiteDB) DeleteOldExecutions ¶
func (*SQLiteDB) DeleteVersion ¶
func (*SQLiteDB) GetAPITokenByHash ¶
func (*SQLiteDB) GetActiveVersion ¶
func (*SQLiteDB) GetExecution ¶
func (*SQLiteDB) GetFunction ¶
func (*SQLiteDB) GetVersion ¶
func (*SQLiteDB) GetVersionByID ¶
func (*SQLiteDB) ListAPITokens ¶
func (*SQLiteDB) ListExecutions ¶
func (*SQLiteDB) ListFunctions ¶
func (db *SQLiteDB) ListFunctions(ctx context.Context, params PaginationParams) ([]FunctionWithActiveVersion, int64, error)
func (*SQLiteDB) ListFunctionsWithActiveCron ¶
func (*SQLiteDB) ListVersions ¶
func (db *SQLiteDB) ListVersions(ctx context.Context, functionID string, params PaginationParams) ([]FunctionVersion, int64, error)
func (*SQLiteDB) RevokeAPIToken ¶
func (*SQLiteDB) UpdateAPITokenLastUsed ¶
func (*SQLiteDB) UpdateExecution ¶
func (*SQLiteDB) UpdateFunction ¶
type UpdateFunctionRequest ¶
type UpdateFunctionRequest struct {
Name *string `json:"name,omitempty"`
Description *string `json:"description,omitempty"`
Code *string `json:"code,omitempty"`
Disabled *bool `json:"disabled,omitempty"`
RetentionDays *int `json:"retention_days,omitempty"`
CronSchedule *string `json:"cron_schedule,omitempty"`
CronStatus *string `json:"cron_status,omitempty"`
SaveResponse *bool `json:"save_response,omitempty"`
}
UpdateFunctionRequest is the request body for updating a function