state

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Dec 13, 2025 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// StateKeyPrefix is the prefix for state keys in storage
	StateKeyPrefix = "state:"

	// SnapshotKeyPrefix is the prefix for snapshot keys in storage
	SnapshotKeyPrefix = "snapshot:"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Manager

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

Manager implements the StateManager interface

func NewManager

func NewManager(storage interfaces.Storage) *Manager

NewManager creates a new state manager

func (*Manager) AddAfterSnapshotHook

func (m *Manager) AddAfterSnapshotHook(hook func(snapshotID string))

AddAfterSnapshotHook adds a hook to run after snapshots

func (*Manager) AddAfterTransitionHook

func (m *Manager) AddAfterTransitionHook(hook func(transition interfaces.StateTransition))

AddAfterTransitionHook adds a hook to run after state transitions

func (*Manager) AddBeforeSnapshotHook

func (m *Manager) AddBeforeSnapshotHook(hook func() error)

AddBeforeSnapshotHook adds a hook to run before snapshots

func (*Manager) AddBeforeTransitionHook

func (m *Manager) AddBeforeTransitionHook(hook func(transition interfaces.StateTransition) error)

AddBeforeTransitionHook adds a hook to run before state transitions

func (*Manager) ApplyStateTransition

func (m *Manager) ApplyStateTransition(transition interfaces.StateTransition) error

ApplyStateTransition applies a state transition

func (*Manager) BeginStateTransition

func (m *Manager) BeginStateTransition() interfaces.StateTransition

BeginStateTransition creates a new state transition

func (*Manager) CreateSnapshot

func (m *Manager) CreateSnapshot() (string, error)

CreateSnapshot creates a new state snapshot

func (*Manager) DeleteSnapshot

func (m *Manager) DeleteSnapshot(snapshotID string) error

DeleteSnapshot deletes a snapshot

func (*Manager) DeleteState

func (m *Manager) DeleteState(key string) error

DeleteState removes a state value

func (*Manager) GetState

func (m *Manager) GetState(key string) (any, error)

GetState retrieves a state value

func (*Manager) GetStateHash

func (m *Manager) GetStateHash() ([]byte, error)

GetStateHash returns the hash of the current state

func (*Manager) ListSnapshots

func (m *Manager) ListSnapshots() ([]string, error)

ListSnapshots returns all snapshot IDs

func (*Manager) RestoreSnapshot

func (m *Manager) RestoreSnapshot(snapshotID string) error

RestoreSnapshot restores state from a snapshot

func (*Manager) SetState

func (m *Manager) SetState(key string, value any) error

SetState sets a state value

func (*Manager) ValidateState

func (m *Manager) ValidateState() error

ValidateState validates the current state

type Snapshot

type Snapshot struct {
	ID        string
	Timestamp time.Time
	State     map[string]any
	Hash      []byte
}

Snapshot represents a state snapshot

type StateTransitionImpl

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

StateTransitionImpl implements the StateTransition interface

func (*StateTransitionImpl) AddChange

func (t *StateTransitionImpl) AddChange(key string, oldValue, newValue any)

AddChange adds a state change to the transition

func (*StateTransitionImpl) Apply

func (t *StateTransitionImpl) Apply() error

Apply applies the transition

func (*StateTransitionImpl) GetChanges

func (t *StateTransitionImpl) GetChanges() map[string]interfaces.StateChange

GetChanges returns all changes in the transition

func (*StateTransitionImpl) Rollback

func (t *StateTransitionImpl) Rollback() error

Rollback rolls back the transition

func (*StateTransitionImpl) Validate

func (t *StateTransitionImpl) Validate() error

Validate validates the transition

type SyncHooks

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

SyncHooks contains hooks for state synchronization

func NewSyncHooks

func NewSyncHooks() *SyncHooks

NewSyncHooks creates new synchronization hooks

func (*SyncHooks) AddAfterSnapshot

func (h *SyncHooks) AddAfterSnapshot(hook func(snapshotID string))

AddAfterSnapshot adds an after-snapshot hook

func (*SyncHooks) AddAfterTransition

func (h *SyncHooks) AddAfterTransition(hook func(transition interfaces.StateTransition))

AddAfterTransition adds an after-transition hook

func (*SyncHooks) AddBeforeSnapshot

func (h *SyncHooks) AddBeforeSnapshot(hook func() error)

AddBeforeSnapshot adds a before-snapshot hook

func (*SyncHooks) AddBeforeTransition

func (h *SyncHooks) AddBeforeTransition(hook func(transition interfaces.StateTransition) error)

AddBeforeTransition adds a before-transition hook

Jump to

Keyboard shortcuts

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