psm

package
v0.0.0-...-b66da45 Latest Latest
Warning

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

Go to latest
Published: Jul 30, 2025 License: MIT Imports: 32 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrDuplicateChainedEventID = errors.New("duplicate chained event ID")
View Source
var ErrDuplicateEventID = errors.New("duplicate event ID")
View Source
var TxOptions = &sqrlx.TxOptions{
	Isolation: sql.LevelReadCommitted,
	Retryable: true,
	ReadOnly:  false,
}

Functions

func MustSystemActor

func MustSystemActor(id string) struct{}

DEPRECATED: This does nothing.

func RunLinkHook

func RunLinkHook[
	K IKeyset,
	S IState[K, ST, SD],
	ST IStatusEnum,
	SD IStateData,
	E IEvent[K, S, ST, SD, IE],
	IE IInnerEvent,
	SE IInnerEvent,

	DK IKeyset,
	DIE IInnerEvent,
](
	ctx context.Context,
	destination LinkDestination[DK, DIE],
	callback func(context.Context, sqrlx.Transaction, S, SE, func(DK, DIE)) error,
	tx sqrlx.Transaction,
	state S,
	event E,
) error

Types

type BuilderFrom

type BuilderFrom[
	K IKeyset,
	S IState[K, ST, SD],
	ST IStatusEnum,
	SD IStateData,
	E IEvent[K, S, ST, SD, IE],
	IE IInnerEvent,
] struct {
	// contains filtered or unexported fields
}

func (BuilderFrom[K, S, ST, SD, E, IE]) DataHook

func (tb BuilderFrom[K, S, ST, SD, E, IE]) DataHook(
	hook transitionHook[K, S, ST, SD, E, IE],
) *TransitionBuilder[K, S, ST, SD, E, IE]

DEPRECATED: use Hook

func (BuilderFrom[K, S, ST, SD, E, IE]) Hook

func (tb BuilderFrom[K, S, ST, SD, E, IE]) Hook(
	hook transitionHook[K, S, ST, SD, E, IE],
) *TransitionBuilder[K, S, ST, SD, E, IE]

Hook is a shortcut for OnEvent().Hook() with the event type matching callback function.

func (BuilderFrom[K, S, ST, SD, E, IE]) LinkTo

func (tb BuilderFrom[K, S, ST, SD, E, IE]) LinkTo(
	link transitionHook[K, S, ST, SD, E, IE],
) *TransitionBuilder[K, S, ST, SD, E, IE]

DEPRECATED: use Hook

func (BuilderFrom[K, S, ST, SD, E, IE]) LogicHook

func (tb BuilderFrom[K, S, ST, SD, E, IE]) LogicHook(
	hook transitionHook[K, S, ST, SD, E, IE],
) *TransitionBuilder[K, S, ST, SD, E, IE]

DEPRECATED: use Hook

func (BuilderFrom[K, S, ST, SD, E, IE]) Mutate

func (tb BuilderFrom[K, S, ST, SD, E, IE]) Mutate(
	hook transitionMutation[K, S, ST, SD, E, IE],
) *TransitionBuilder[K, S, ST, SD, E, IE]

Mutate is a shortcut for OnEvent().Mutate() with the event type matching callback function.

func (BuilderFrom[K, S, ST, SD, E, IE]) OnEvent

func (tb BuilderFrom[K, S, ST, SD, E, IE]) OnEvent(event string) *TransitionBuilder[K, S, ST, SD, E, IE]

OnEvent identifies a specific transition from state(s) for an event.

type CallbackBaton

type CallbackBaton[
	K IKeyset,
	S IState[K, ST, SD],
	ST IStatusEnum,
	SD IStateData,
	E IEvent[K, S, ST, SD, IE],
	IE IInnerEvent,
] interface {
	SideEffect(o5msg.Message)
	DelayedSideEffect(o5msg.Message, time.Duration)
	ChainEvent(IE)
	FullCause() E
	AsCause() *psm_j5pb.Cause
	Publish(o5msg.Message)
}

CallbackBaton should only be used in generated code.

type DBStateMachine

type DBStateMachine[
	K IKeyset,
	S IState[K, ST, SD],
	ST IStatusEnum,
	SD IStateData,
	E IEvent[K, S, ST, SD, IE],
	IE IInnerEvent,
] struct {
	*StateMachine[K, S, ST, SD, E, IE]
	// contains filtered or unexported fields
}

DBStateMachine adds the 'Transaction' method to the state machine, which runs the transition in a new transaction from the state machine's database

func (DBStateMachine) EventDataHook

func (hs DBStateMachine) EventDataHook(hook GeneralEventHook[K, S, ST, SD, E, IE])

func (*DBStateMachine[K, S, ST, SD, E, IE]) FollowEvent

func (sm *DBStateMachine[K, S, ST, SD, E, IE]) FollowEvent(ctx context.Context, event E) error

FollowEvent stores the event in the database and runs all database updates and hooks, but does not run any Logic hooks and so does not produce side-effects or chain events. This is used when the state machine is not the Leader, or when it is restoring or loading from stored event history.

func (*DBStateMachine[K, S, ST, SD, E, IE]) FollowEvents

func (sm *DBStateMachine[K, S, ST, SD, E, IE]) FollowEvents(ctx context.Context, events []E) error

func (DBStateMachine) From

func (hs DBStateMachine) From(states ...ST) BuilderFrom[K, S, ST, SD, E, IE]

From creates a new transition builder for the state machine, which will run when the machine is transitioning from one of the given states. If the given list is empty (From()), matches ALL starting states.

func (DBStateMachine) LogicHook

func (hs DBStateMachine) LogicHook(hook GeneralEventHook[K, S, ST, SD, E, IE])

func (DBStateMachine) PublishEvent

func (hs DBStateMachine) PublishEvent(hook GeneralEventHook[K, S, ST, SD, E, IE])

func (DBStateMachine) PublishUpsert

func (hs DBStateMachine) PublishUpsert(hook GeneralStateHook[K, S, ST, SD, E, IE])

func (DBStateMachine) StateDataHook

func (hs DBStateMachine) StateDataHook(hook GeneralStateHook[K, S, ST, SD, E, IE])

func (*DBStateMachine[K, S, ST, SD, E, IE]) Transition

func (sm *DBStateMachine[K, S, ST, SD, E, IE]) Transition(ctx context.Context, event *EventSpec[K, S, ST, SD, E, IE]) (S, error)

Transition transitions the state machine in a new transaction from the state machine's database pool

type EventSpec

type EventSpec[
	K IKeyset,
	S IState[K, ST, SD],
	ST IStatusEnum,
	SD IStateData,
	E IEvent[K, S, ST, SD, IE],
	IE IInnerEvent,
] struct {
	// Keys must be set, to identify the state machine.
	Keys K

	// EventID is optional and will be set by the state machine if empty
	EventID string

	// The inner PSM Event type. Must be set for incoming events.
	Event IE

	// The cause of the event, Cause, Action or Message must be set for incoming events.
	Cause *psm_j5pb.Cause

	// The authenticated action cause for the event. Cause, Action or Message must be set
	// for incoming events.
	Action *auth_j5pb.Action

	// The message cause for the event. Cause, Action or Message must be set for
	// incoming events.
	Message *messaging_j5pb.MessageCause

	// Optional, defaults to the system time (if Zero())
	Timestamp time.Time
}

type EventTableSpec

type EventTableSpec struct {
	TableName string

	// The entire event message as JSONB
	Root *FieldSpec

	// a UUID holding the primary key of the event
	// TODO: Multi-column ID for Events?
	ID *FieldSpec

	// timestamptz The time of the event
	Timestamp *FieldSpec

	// int, The discrete integer for the event in the state machine
	Sequence *FieldSpec

	// jsonb, holds the state after the event
	StateSnapshot *FieldSpec
}

type FieldSpec

type FieldSpec struct {
	ColumnName string
}

type GeneralEventHook

type GeneralEventHook[
	K IKeyset,
	S IState[K, ST, SD],
	ST IStatusEnum,
	SD IStateData,
	E IEvent[K, S, ST, SD, IE],
	IE IInnerEvent,
] struct {
	Callback    func(context.Context, sqrlx.Transaction, CallbackBaton[K, S, ST, SD, E, IE], S, E) error
	RunOnFollow bool // If true, this hook runs on follow-up events, not just the initial transition.
}

GeneralHook runs after Transition mutations and hooks for all events and states.

type GeneralStateHook

type GeneralStateHook[
	K IKeyset,
	S IState[K, ST, SD],
	ST IStatusEnum,
	SD IStateData,
	E IEvent[K, S, ST, SD, IE],
	IE IInnerEvent,
] struct {
	Callback    func(context.Context, sqrlx.Transaction, CallbackBaton[K, S, ST, SD, E, IE], S) error
	RunOnFollow bool // If true, this hook runs on follow-up events, not just the initial transition.
}

GeneralStateHook runs after Transition mutations and hooks for all events and states.

type HookBaton

type HookBaton[
	K IKeyset,
	S IState[K, ST, SD],
	ST IStatusEnum,
	SD IStateData,
	E IEvent[K, S, ST, SD, IE],
	IE IInnerEvent,
] interface {
	SideEffect(o5msg.Message)
	DelayedSideEffect(o5msg.Message, time.Duration)
	ChainEvent(IE)
	FullCause() E
	AsCause() *psm_j5pb.Cause
}

HookBaton is sent with each logic transition hook to collect chain events and side effects

type IEvent

type IEvent[
	K IKeyset,
	S IState[K, ST, SD],
	ST IStatusEnum,
	SD IStateData,
	Inner any,
] interface {
	proto.Message
	UnwrapPSMEvent() Inner
	SetPSMEvent(Inner) error
	PSMKeys() K
	SetPSMKeys(K)
	PSMMetadata() *psm_j5pb.EventMetadata
	PSMIsSet() bool
}

IEvent is the Event Wrapper, the top level which has metadata, foreign keys to the state, and the event itself. e.g. *testpb.FooEvent, the concrete proto message

type IInnerEvent

type IInnerEvent interface {
	IPSMMessage
	PSMEventKey() string
}

IInnerEvent is the typed event *interface* which is the set of all possible events for the state machine e.g. testpb.FooPSMEvent interface - this is generated by the protoc plugin in _psm.pb.go It is set at compile time specifically to the interface type.

type IKeyset

type IKeyset interface {
	IPSMMessage
	PSMFullName() string
	PSMKeyValues() (map[string]any, error) // map of column_name to sql value
}

type IPSMMessage

type IPSMMessage interface {
	proto.Message
	PSMIsSet() bool
}

IGenericProtoMessage is the base extensions shared by all message entities in the PSM generated code

type IState

type IState[K IKeyset, ST IStatusEnum, SD IStateData] interface {
	IPSMMessage
	GetStatus() ST
	SetStatus(ST)
	PSMMetadata() *psm_j5pb.StateMetadata
	PSMKeys() K
	SetPSMKeys(K)
	PSMData() SD
}

IState[K, ST, SD]is the main State Entity e.g. *testpb.FooState

type IStateData

type IStateData interface {
	IPSMMessage
}

IStateData is the Data Entity e.g. *testpb.FooData

type IStatusEnum

type IStatusEnum interface {
	~int32
	ShortString() string
	String() string
}

IStatusEnum is enum representing the named state of the entity. e.g. *testpb.FooStatus (int32)

type KeyColumn

type KeyColumn struct {
	ColumnName string
	ProtoField protoreflect.FieldNumber
	ProtoName  protoreflect.Name

	Primary            bool
	Required           bool
	ExplicitlyOptional bool // makes strings pointers
	Unique             bool

	Schema *schema_j5pb.Field // The schema for this key field, used for validation and serialization.

}

type KeyField

type KeyField struct {
	ColumnName *string // Optional, stores in the table as a column.
	Primary    bool
	Unique     bool
	Path       *pgstore.Path
}

type LinkDestination

type LinkDestination[
	DK IKeyset,
	DIE IInnerEvent,
] interface {
	// contains filtered or unexported methods
}

type Publisher

type Publisher interface {
	Publish(o5msg.Message)
}

type QuerySpec

type QuerySpec[
	GetREQ pquery.GetRequest,
	GetRES pquery.GetResponse,
	ListREQ pquery.ListRequest,
	ListRES pquery.ListResponse,
	ListEventsREQ pquery.ListRequest,
	ListEventsRES pquery.ListResponse,
] struct {
	QueryTableSpec

	ListRequestFilter       func(ListREQ) (map[string]any, error)
	ListEventsRequestFilter func(ListEventsREQ) (map[string]any, error)
}

QuerySpec is the configuration for the query service side of the state machine. Can be partially derived from the state machine table spec, but contains types relating to the query service so cannot be fully derived.

type QueryTableSpec

type QueryTableSpec struct {
	EventType protoreflect.MessageDescriptor
	StateType protoreflect.MessageDescriptor
	TableMap
}

QueryTableSpec the TableMap with descriptors for the messages, without using generic parameters.

func BuildQueryTableSpec

func BuildQueryTableSpec(stateMessage, eventMessage protoreflect.MessageDescriptor) (QueryTableSpec, error)

type StateMachine

type StateMachine[
	K IKeyset,
	S IState[K, ST, SD],
	ST IStatusEnum,
	SD IStateData,
	E IEvent[K, S, ST, SD, IE],
	IE IInnerEvent,
] struct {
	// contains filtered or unexported fields
}

StateMachine is a database wrapper around the eventer. Using sane defaults with overrides for table configuration.

func NewStateMachine

func NewStateMachine[
	K IKeyset,
	S IState[K, ST, SD],
	ST IStatusEnum,
	SD IStateData,
	E IEvent[K, S, ST, SD, IE],
	IE IInnerEvent,
](
	cb *StateMachineConfig[K, S, ST, SD, E, IE],
) (*StateMachine[K, S, ST, SD, E, IE], error)

func (*StateMachine) EventDataHook

func (hs *StateMachine) EventDataHook(hook GeneralEventHook[K, S, ST, SD, E, IE])

func (*StateMachine) From

func (hs *StateMachine) From(states ...ST) BuilderFrom[K, S, ST, SD, E, IE]

From creates a new transition builder for the state machine, which will run when the machine is transitioning from one of the given states. If the given list is empty (From()), matches ALL starting states.

func (*StateMachine) LogicHook

func (hs *StateMachine) LogicHook(hook GeneralEventHook[K, S, ST, SD, E, IE])

func (*StateMachine) PublishEvent

func (hs *StateMachine) PublishEvent(hook GeneralEventHook[K, S, ST, SD, E, IE])

func (*StateMachine) PublishUpsert

func (hs *StateMachine) PublishUpsert(hook GeneralStateHook[K, S, ST, SD, E, IE])

func (*StateMachine) StateDataHook

func (hs *StateMachine) StateDataHook(hook GeneralStateHook[K, S, ST, SD, E, IE])

func (StateMachine[K, S, ST, SD, E, IE]) StateTableSpec

func (sm StateMachine[K, S, ST, SD, E, IE]) StateTableSpec() QueryTableSpec

func (*StateMachine[K, S, ST, SD, E, IE]) Transition

func (sm *StateMachine[K, S, ST, SD, E, IE]) Transition(ctx context.Context, db Transactor, event *EventSpec[K, S, ST, SD, E, IE]) (S, error)

func (*StateMachine[K, S, ST, SD, E, IE]) TransitionInTx

func (sm *StateMachine[K, S, ST, SD, E, IE]) TransitionInTx(ctx context.Context, tx sqrlx.Transaction, event *EventSpec[K, S, ST, SD, E, IE]) (S, error)

TransitionInTx uses an existing transaction to transition the state machine.

func (*StateMachine[K, S, ST, SD, E, IE]) WithDB

func (sm *StateMachine[K, S, ST, SD, E, IE]) WithDB(db Transactor) *DBStateMachine[K, S, ST, SD, E, IE]

type StateMachineConfig

type StateMachineConfig[
	K IKeyset,
	S IState[K, ST, SD],
	ST IStatusEnum,
	SD IStateData,
	E IEvent[K, S, ST, SD, IE],
	IE IInnerEvent,
] struct {
	// contains filtered or unexported fields
}

StateMachineConfig allows the generated code to build a default machine, but expose options to the user to override the defaults

func (*StateMachineConfig[K, S, ST, SD, E, IE]) BuildQueryTableSpec

func (smc *StateMachineConfig[K, S, ST, SD, E, IE]) BuildQueryTableSpec() (*QueryTableSpec, error)

func (*StateMachineConfig[K, S, ST, SD, E, IE]) BuildStateMachine

func (smc *StateMachineConfig[K, S, ST, SD, E, IE]) BuildStateMachine() (*StateMachine[K, S, ST, SD, E, IE], error)

func (*StateMachineConfig[K, S, ST, SD, E, IE]) DeriveKeyValues

func (smc *StateMachineConfig[K, S, ST, SD, E, IE]) DeriveKeyValues(cbFunc func(K) (map[string]any, error)) *StateMachineConfig[K, S, ST, SD, E, IE]

KeyFields derives the key values from the Key entity. Should return ID Strings, and omit entries for NULL values

func (*StateMachineConfig[K, S, ST, SD, E, IE]) InitialStateFunc

func (smc *StateMachineConfig[K, S, ST, SD, E, IE]) InitialStateFunc(cbFunc func(context.Context, sqrlx.Transaction, K) (IE, error)) *StateMachineConfig[K, S, ST, SD, E, IE]

InitialStateFunc is called when the state machine is created, and the state is not found in the database. It must return an 'initialization' event which will run prior to the event being processed. The DB transaction is available to read data from, for example, upsert data, but be sure that the data is either immutable, or there is an event to update it when it changes.

func (*StateMachineConfig[K, S, ST, SD, E, IE]) SystemActor

func (smc *StateMachineConfig[K, S, ST, SD, E, IE]) SystemActor(systemActor SystemActor) *StateMachineConfig[K, S, ST, SD, E, IE]

DEPRECATED: This does nothing.

func (*StateMachineConfig[K, S, ST, SD, E, IE]) TableMap

func (smc *StateMachineConfig[K, S, ST, SD, E, IE]) TableMap(tableMap *TableMap) *StateMachineConfig[K, S, ST, SD, E, IE]

func (*StateMachineConfig[K, S, ST, SD, E, IE]) TableName

func (smc *StateMachineConfig[K, S, ST, SD, E, IE]) TableName(tableName string) *StateMachineConfig[K, S, ST, SD, E, IE]

TableName sets both tables to {name} and {name_event}

type StateQueryOptions

type StateQueryOptions struct {
	Auth       pquery.AuthProvider
	AuthJoin   *pquery.LeftJoin
	SkipEvents bool
}

type StateQuerySet

type StateQuerySet[
	GetREQ pquery.GetRequest,
	GetRES pquery.GetResponse,
	ListREQ pquery.ListRequest,
	ListRES pquery.ListResponse,
	ListEventsREQ pquery.ListRequest,
	ListEventsRES pquery.ListResponse,
] struct {
	Getter      *pquery.Getter[GetREQ, GetRES]
	MainLister  *pquery.Lister[ListREQ, ListRES]
	EventLister *pquery.Lister[ListEventsREQ, ListEventsRES]
}

StateQuerySet is a shortcut for manually specifying three different query types following the 'standard model': 1. A getter for a single state 2. A lister for the main state 3. A lister for the events of the main state

func BuildStateQuerySet

func BuildStateQuerySet[
	GetREQ pquery.GetRequest,
	GetRES pquery.GetResponse,
	ListREQ pquery.ListRequest,
	ListRES pquery.ListResponse,
	ListEventsREQ pquery.ListRequest,
	ListEventsRES pquery.ListResponse,
](
	smSpec QuerySpec[GetREQ, GetRES, ListREQ, ListRES, ListEventsREQ, ListEventsRES],
	options StateQueryOptions,
) (*StateQuerySet[GetREQ, GetRES, ListREQ, ListRES, ListEventsREQ, ListEventsRES], error)

func (*StateQuerySet[GetREQ, GetRES, ListREQ, ListRES, ListEventsREQ, ListEventsRES]) Get

func (gc *StateQuerySet[
	GetREQ, GetRES,
	ListREQ, ListRES,
	ListEventsREQ, ListEventsRES,
]) Get(ctx context.Context, db Transactor, reqMsg GetREQ, resMsg GetRES) error

func (*StateQuerySet[GetREQ, GetRES, ListREQ, ListRES, ListEventsREQ, ListEventsRES]) List

func (gc *StateQuerySet[
	GetREQ, GetRES,
	ListREQ, ListRES,
	ListEventsREQ, ListEventsRES,
]) List(ctx context.Context, db Transactor, reqMsg proto.Message, resMsg proto.Message) error

func (*StateQuerySet[GetREQ, GetRES, ListREQ, ListRES, ListEventsREQ, ListEventsRES]) ListEvents

func (gc *StateQuerySet[
	GetREQ, GetRES,
	ListREQ, ListRES,
	ListEventsREQ, ListEventsRES,
]) ListEvents(ctx context.Context, db Transactor, reqMsg proto.Message, resMsg proto.Message) error

func (*StateQuerySet[GetREQ, GetRES, ListREQ, ListRES, ListEventsREQ, ListEventsRES]) SetQueryLogger

func (gc *StateQuerySet[
	GetREQ, GetRES,
	ListREQ, ListRES,
	ListEventsREQ, ListEventsRES,
]) SetQueryLogger(logger pquery.QueryLogger)

type StateTableSpec

type StateTableSpec struct {
	TableName string

	// The entire state message, as a JSONB
	Root *FieldSpec
}

type SystemActor

type SystemActor any

DEPRECATED: This does nothing.

type TableMap

type TableMap struct {

	// KeyColumns are stored in both state and event tables.
	// Keys marked primary combine to form the primary key of the State table,
	// and therefore a foreign key from the event table.
	// Non primary keys are included but not referenced.
	KeyColumns []KeyColumn

	State StateTableSpec
	Event EventTableSpec
}

func (*TableMap) Validate

func (tm *TableMap) Validate() error

type TenantFilterProvider

type TenantFilterProvider interface {
	GetRequiredTenantKeys(ctx context.Context) (map[string]string, error)
}

type TenantFilterProviderFunc

type TenantFilterProviderFunc func(ctx context.Context) (map[string]string, error)

func (TenantFilterProviderFunc) GetRequiredTenantKeys

func (f TenantFilterProviderFunc) GetRequiredTenantKeys(ctx context.Context) (map[string]string, error)

type Transactor

type Transactor interface {
	Transact(context.Context, *sqrlx.TxOptions, sqrlx.Callback) error
}

type TransitionBuilder

type TransitionBuilder[
	K IKeyset,
	S IState[K, ST, SD],
	ST IStatusEnum,
	SD IStateData,
	E IEvent[K, S, ST, SD, IE],
	IE IInnerEvent,
] struct {
	// contains filtered or unexported fields
}

func (*TransitionBuilder[K, S, ST, SD, E, IE]) DataHook

func (tb *TransitionBuilder[K, S, ST, SD, E, IE]) DataHook(
	hook transitionHook[K, S, ST, SD, E, IE],
) *TransitionBuilder[K, S, ST, SD, E, IE]

DEPRECATED: use Hook

func (*TransitionBuilder[K, S, ST, SD, E, IE]) Hook

func (tb *TransitionBuilder[K, S, ST, SD, E, IE]) Hook(
	hooks ...transitionHook[K, S, ST, SD, E, IE],
) *TransitionBuilder[K, S, ST, SD, E, IE]

Hook adds one or more TransitionHooks to the transition.

func (*TransitionBuilder[K, S, ST, SD, E, IE]) LinkTo

func (tb *TransitionBuilder[K, S, ST, SD, E, IE]) LinkTo(
	hook transitionHook[K, S, ST, SD, E, IE],
) *TransitionBuilder[K, S, ST, SD, E, IE]

DEPRECATED: use Hook

func (*TransitionBuilder[K, S, ST, SD, E, IE]) LogicHook

func (tb *TransitionBuilder[K, S, ST, SD, E, IE]) LogicHook(
	hook transitionHook[K, S, ST, SD, E, IE],
) *TransitionBuilder[K, S, ST, SD, E, IE]

DEPRECATED: use Hook

func (*TransitionBuilder[K, S, ST, SD, E, IE]) Mutate

func (tb *TransitionBuilder[K, S, ST, SD, E, IE]) Mutate(
	mutation transitionMutation[K, S, ST, SD, E, IE],
) *TransitionBuilder[K, S, ST, SD, E, IE]

Mutate adds a function which will merge data from the event into the state data. A transition can have zero or one mutate function. Multiple mutation callbacks may be registered.

func (*TransitionBuilder[K, S, ST, SD, E, IE]) Noop

func (tb *TransitionBuilder[K, S, ST, SD, E, IE]) Noop() *TransitionBuilder[K, S, ST, SD, E, IE]

Noop registers a transition which does nothing, but prevents the machine from erroring when the conditions are met.

func (*TransitionBuilder[K, S, ST, SD, E, IE]) SetStatus

func (tb *TransitionBuilder[K, S, ST, SD, E, IE]) SetStatus(
	status ST,
) *TransitionBuilder[K, S, ST, SD, E, IE]

SetStatus sets status which the state machine will have after the transition. Not all transitions will change the status, some will only mutate. Calling this function replaces any previous value.

type TransitionHook

type TransitionHook[
	K IKeyset,
	S IState[K, ST, SD],
	ST IStatusEnum,
	SD IStateData,
	E IEvent[K, S, ST, SD, IE],
	IE IInnerEvent,
] struct {
	Callback    func(context.Context, sqrlx.Transaction, CallbackBaton[K, S, ST, SD, E, IE], S, E) error
	RunOnFollow bool   // If true, this hook runs on follow-up events, not just the initial transition.
	EventType   string // If set, this hook only runs for the specific event type.
}

TransitionHook Executes after the mutations. This hook has access to the transaction and can trigger side effects, including chained events, which are additional events processed by the state machine.

type TransitionMutation

type TransitionMutation[
	K IKeyset,
	S IState[K, ST, SD],
	ST IStatusEnum,
	SD IStateData,
	E IEvent[K, S, ST, SD, IE],
	IE IInnerEvent,
	SE IInnerEvent,
] func(SD, SE) error

TransitionMutation runs at the start of a transition to merge the event information into the state data object. The state object is mutable in this context.

Jump to

Keyboard shortcuts

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