simple

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Dec 4, 2025 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrUnknownEntityType indicates no workflow definition exists for the requested entity.
	ErrUnknownEntityType = errors.New("workflow: entity type not registered")
	// ErrInvalidTransition indicates the requested transition is not allowed.
	ErrInvalidTransition = errors.New("workflow: transition not allowed")
	// ErrMissingTransition indicates neither a transition name nor target state were supplied.
	ErrMissingTransition = errors.New("workflow: transition name or target state required")
	// ErrNilEntityID signals input validation failure.
	ErrNilEntityID = errors.New("workflow: entity id required")
	// ErrDefinitionStatesRequired indicates a definition is missing states.
	ErrDefinitionStatesRequired = errors.New("workflow: definition requires at least one state")
	// ErrStateNameRequired indicates a workflow state is missing its name.
	ErrStateNameRequired = errors.New("workflow: state name required")
	// ErrDuplicateState indicates duplicate workflow state names were declared.
	ErrDuplicateState = errors.New("workflow: duplicate state")
	// ErrTransitionStateUnknown indicates a transition references an unknown state.
	ErrTransitionStateUnknown = errors.New("workflow: transition references unknown state")
	// ErrDuplicateTransition indicates the same transition name is declared multiple times for a state.
	ErrDuplicateTransition = errors.New("workflow: duplicate transition for state")
	// ErrTerminalState indicates a transition was attempted from a terminal state.
	ErrTerminalState = errors.New("workflow: terminal state reached")
	// ErrGuardAuthorizerRequired indicates a guard was present but no authorizer was configured.
	ErrGuardAuthorizerRequired = errors.New("workflow: guard authorizer required")
)

Functions

This section is empty.

Types

type Engine

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

Engine is a simple in-memory workflow engine that executes deterministic state transitions.

func New

func New(opts ...Option) *Engine

New constructs a workflow engine seeded with the default page workflow.

func (*Engine) AvailableTransitions

func (e *Engine) AvailableTransitions(ctx context.Context, query interfaces.TransitionQuery) ([]WorkflowTransition, error)

AvailableTransitions returns the transitions reachable from the supplied state.

func (*Engine) RegisterWorkflow

func (e *Engine) RegisterWorkflow(ctx context.Context, definition interfaces.WorkflowDefinition) error

RegisterWorkflow installs a workflow definition for the supplied entity type.

func (*Engine) Transition

Transition applies a workflow transition for an entity.

type Option

type Option func(*Engine)

Option configures the engine.

func WithAuthorizer added in v0.3.0

func WithAuthorizer(authorizer interfaces.WorkflowAuthorizer) Option

WithAuthorizer wires a guard authorizer to enforce guarded transitions.

func WithClock

func WithClock(clock func() time.Time) Option

WithClock overrides the clock used for transition timestamps (primarily for testing).

type WorkflowDefinition

type WorkflowDefinition = interfaces.WorkflowDefinition

WorkflowDefinition mirrors interfaces.WorkflowDefinition for return paths.

type WorkflowTransition

type WorkflowTransition = interfaces.WorkflowTransition

WorkflowTransition mirrors interfaces.WorkflowTransition while keeping the package self-contained for consumers of AvailableTransitions.

Jump to

Keyboard shortcuts

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