resource

package
v0.3.3 Latest Latest
Warning

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

Go to latest
Published: Jul 4, 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.

Functions

This section is empty.

Types

type Common added in v0.2.0

type Common struct {
	ID
	Parent Resource
}

Common provides functionality common to all resources.

func New

func New(kind Kind, parent Resource) Common

func (Common) Ancestors added in v0.2.0

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

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

func (Common) GetParent added in v0.2.0

func (r Common) GetParent() Resource

func (Common) HasAncestor added in v0.2.0

func (r Common) HasAncestor(id ID) bool

func (Common) Module added in v0.2.0

func (r Common) Module() Resource

func (Common) Run added in v0.2.0

func (r Common) Run() Resource

func (Common) Workspace added in v0.2.0

func (r Common) Workspace() Resource

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) GetID added in v0.2.0

func (id ID) GetID() ID

GetID allows ID to be accessed via an interface value.

func (ID) GetKind added in v0.2.0

func (id ID) GetKind() Kind

GetKind allows Kind to be accessed via an interface value.

func (ID) String

func (id ID) String() string

type Kind

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

func (Kind) String

func (k Kind) String() string

type Publisher

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

type Resource

type Resource interface {
	// GetID retrieves the unique identifier for the resource.
	GetID() ID
	// GetKind retrieves the kind of resource.
	GetKind() Kind
	// GetParent retrieves the resource's parent, the resource from which the
	// resource was spawned.
	GetParent() Resource
	// HasAncestor determines whether the resource has an ancestor with the
	// given ID.
	HasAncestor(ID) bool
	// Ancestors retrieves a list of the resource's ancestors, nearest first.
	Ancestors() []Resource
	// String is a human-readable identifier for the resource. Not necessarily
	// unique across pug.
	String() string
	// Module retrieves the resource's module. Returns nil if the resource does
	// not have a module ancestor.
	Module() Resource
	// Workspace retrieves the resource's workspcae. Returns nil if the resource does
	// not have a workspace ancestor.
	Workspace() Resource
	// Run retrieves the resource's run. Returns nil if the resource does
	// not have a run ancestor.
	Run() Resource
}

Resource is a unique pug entity spawned from another entity.

var GlobalResource Resource = Common{}

GlobalResource is an abstract top-level pug resource from which all other pug resources are ultimately spawned.

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