Skip to main content

nexus-persistence

Core persistence abstractions for Nexus actors -- event sourcing, durable state, effects, and in-memory stores for testing. Defines the interfaces that backend packages (nexus-persistence-dbal, nexus-persistence-doctrine) implement.

Composer: nexus-actors/persistence

View class diagram

Root namespace

Monadial\Nexus\Persistence\

ClassDescription
PersistenceIdValue object identifying a persistent entity. Factory: of(string $entityType, string $entityId), fromString(string). Properties: entityType, entityId. Methods: toString(), equals(). Implements Stringable.

EventSourced namespace

Monadial\Nexus\Persistence\EventSourced\

ClassDescription
EventSourcedBehaviorFunctional builder for event-sourced actors. create(PersistenceId, object, Closure, Closure)withEventStore()withSnapshotStore()withSnapshotStrategy()withRetention()withLockingStrategy()toBehavior().
AbstractEventSourcedActorClass-based API. Abstract methods: persistenceId(), emptyState(), handleCommand(), applyEvent(). Methods: withSnapshotStore(), withSnapshotStrategy(), withRetention(), withLockingStrategy(), toBehavior(), toProps().
PersistenceEngineInternal engine wrapping user behaviors with recovery and persistence. Users do not call this directly.
EffectImmutable effect type. Factories: persist(object...), none(), unhandled(), stash(), stop(), reply(ActorRef, object). Chaining: thenReply(ActorRef, Closure), thenRun(Closure).
EffectTypeEnum: Persist, None, Unhandled, Stash, Stop, Reply.
SnapshotStrategySnapshot trigger configuration. Factories: everyN(int), never(), predicate(Closure). Method: shouldSnapshot(object, object, int): bool.
RetentionPolicyRetention configuration. Factories: none(), snapshotAndEvents(int, bool). Properties: keepSnapshots, deleteEventsToSnapshot.

Event namespace

Monadial\Nexus\Persistence\Event\

Class / InterfaceDescription
EventStoreInterface: persist(PersistenceId, EventEnvelope...), load(PersistenceId, int, int): iterable, deleteUpTo(PersistenceId, int), highestSequenceNr(PersistenceId): int.
EventEnvelopeReadonly wrapper. Properties: persistenceId, sequenceNr, event, eventType, timestamp, metadata. Method: withMetadata(array).
InMemoryEventStoreIn-memory EventStore implementation for testing.

Snapshot namespace

Monadial\Nexus\Persistence\Snapshot\

Class / InterfaceDescription
SnapshotStoreInterface: save(PersistenceId, SnapshotEnvelope), load(PersistenceId): ?SnapshotEnvelope, delete(PersistenceId, int).
SnapshotEnvelopeReadonly wrapper. Properties: persistenceId, sequenceNr, state, stateType, timestamp.
InMemorySnapshotStoreIn-memory SnapshotStore implementation for testing.

State namespace

Monadial\Nexus\Persistence\State\

Class / InterfaceDescription
DurableStateBehaviorFunctional builder for durable-state actors. create(PersistenceId, object, Closure)withStateStore()withLockingStrategy()toBehavior().
AbstractDurableStateActorClass-based API. Abstract methods: persistenceId(), emptyState(), handleCommand(). Methods: withLockingStrategy(), toBehavior(), toProps().
DurableStateEngineInternal engine for durable state actors. Users do not call this directly.
DurableEffectImmutable effect type. Factories: persist(object), none(), unhandled(), stash(), stop(), reply(ActorRef, object). Chaining: thenReply(ActorRef, Closure), thenRun(Closure).
DurableEffectTypeEnum: Persist, None, Unhandled, Stash, Stop, Reply.
DurableStateStoreInterface: get(PersistenceId): ?DurableStateEnvelope, upsert(PersistenceId, DurableStateEnvelope), delete(PersistenceId).
DurableStateEnvelopeReadonly wrapper. Properties: persistenceId, version, state, stateType, timestamp.
InMemoryDurableStateStoreIn-memory DurableStateStore implementation for testing.

Locking namespace

Monadial\Nexus\Persistence\Locking\

Class / InterfaceDescription
LockingStrategyReadonly value object configuring concurrency control. Factories: optimistic(), pessimistic(PessimisticLockProvider). Methods: isPessimistic(): bool, withLock(PersistenceId, Closure): mixed. For optimistic, withLock() is a no-op pass-through.
PessimisticLockProviderInterface for database-level locking. Method: withLock(PersistenceId, Closure): mixed. Implementations acquire an exclusive lock before executing the callback.

Exception namespace

Monadial\Nexus\Persistence\Exception\

ClassDescription
RecoveryExceptionThrown on recovery failure. Property: persistenceId.
ConcurrentModificationExceptionThrown on version conflict during persistence. Properties: persistenceId, expectedVersion.