resource

package
v0.6.4 Latest Latest
Warning

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

Go to latest
Published: Dec 2, 2025 License: MPL-2.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

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

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

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 any

ID uniquely identifies a Pug resource.

type Identifiable added in v0.6.3

type Identifiable interface {
	GetID() ID
}

Identifiable is a Pug resource with an identity.

type Kind

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

func (Kind) String

func (k Kind) String() string

type MonotonicID added in v0.6.3

type MonotonicID struct {
	Serial uint
	Kind   Kind
}

MonotonicID is an identifier based on an ever-increasing serial number, and a kind to differentiate it from other kinds of identifiers.

func NewMonotonicID added in v0.6.3

func NewMonotonicID(kind Kind) MonotonicID

func (MonotonicID) String added in v0.6.3

func (id MonotonicID) String() string

String provides a human readable representation of the identifier.

type Publisher

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

type Resource

type Resource interface {
	// GetID retrieves the unique identifier for the resource.
	GetID() MonotonicID
	// String is a human-readable identifier for the resource. Not necessarily
	// unique across pug.
	String() string
}

Resource is a unique pug entity

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