resource

package
v0.1.11 Latest Latest
Warning

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

Go to latest
Published: May 13, 2024 License: MPL-2.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

View Source
const IDEncodedMaxLen = 27

IDEncodedMaxLen is the max length of an encoded ID (it can sometimes encode to something shorter).

Variables

View Source
var (
	ErrExists   = errors.New("resource already exists")
	ErrNotFound = errors.New("resource not found")
)
View Source
var GlobalID = ID{}

GlobalID is the zero value of ID, representing the ID of the abstract top-level "global" entity to which all resources belong.

View Source
var GlobalResource = Resource{}

Functions

This section is empty.

Types

type Event

type Event[T any] struct {
	Type    EventType
	Payload T
}

Event represents an event in the lifecycle of a resource

func NewEvent

func NewEvent[T any](t EventType, payload T) Event[T]

type EventType

type EventType string

EventType identifies the type of event

const (
	CreatedEvent EventType = "created"
	UpdatedEvent EventType = "updated"
	DeletedEvent EventType = "deleted"
)

type ID

type ID struct {
	Kind Kind
	// contains filtered or unexported fields
}

ID is a unique identifier for a pug entity.

func NewID

func NewID(kind Kind) ID

func (ID) RowKey

func (id ID) RowKey() ID

RowKey implements tui/table.ResourceValue

func (ID) String

func (id ID) String() string

type Kind

type Kind int
const (
	Global Kind = iota
	Module
	Workspace
	Run
	Task
	Log
	StateResource
)

func (Kind) String

func (k Kind) String() string

type Publisher

type Publisher[T any] interface {
	Publish(EventType, T)
}

type Resource

type Resource struct {
	ID
	Parent *Resource
}

func New

func New(kind Kind, parent Resource) Resource

func (Resource) Ancestors

func (r Resource) Ancestors() (ancestors []Resource)

Ancestors provides a list of successive parents, starting with the direct parents.

func (Resource) HasAncestor

func (r Resource) HasAncestor(id ID) bool

func (Resource) Module

func (r Resource) Module() *Resource

func (Resource) Run

func (r Resource) Run() *Resource

func (Resource) Workspace

func (r Resource) Workspace() *Resource

type Table

type Table[T any] struct {
	// contains filtered or unexported fields
}

Table is an in-memory database table that emits events upon changes.

func NewTable

func NewTable[T any](pub Publisher[T]) *Table[T]

func (*Table[T]) Add

func (t *Table[T]) Add(id ID, row T)

func (*Table[T]) Delete

func (t *Table[T]) Delete(id ID)

func (*Table[T]) Get

func (t *Table[T]) Get(id ID) (T, error)

func (*Table[T]) List

func (t *Table[T]) List() []T

func (*Table[T]) Update

func (t *Table[T]) Update(id ID, updater func(existing T) error) (T, error)

Jump to

Keyboard shortcuts

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