Documentation
¶
Index ¶
- func GetId() (uuid.UUID, error)
- func GetTx[T any](ctx context.Context) T
- type ActorRepository
- type AggregateIdMap
- type AggregateRepository
- type AggregatedIds
- type Caster
- type CommandRecord
- type CommandStore
- type EventRecord
- type EventStore
- type IdAssignment
- type IdAssignments
- func (a *IdAssignments) AddAssignment(name string, ids spry.Identifiers, id uuid.UUID)
- func (a *IdAssignments) CreateAssignment(name string, ids spry.Identifiers) uuid.UUID
- func (a *IdAssignments) GetAggregateId() uuid.UUID
- func (a *IdAssignments) GetIdFor(name string, ids spry.Identifiers) uuid.UUID
- type LastEventMap
- type MapStore
- type NoOpTx
- type Repository
- type Snapshot
- type SnapshotStore
- type Storage
- type Stores
- func (storage Stores[Tx]) AddCommand(ctx context.Context, actorName string, command CommandRecord) error
- func (storage Stores[Tx]) AddEvents(ctx context.Context, events []EventRecord) error
- func (storage Stores[Tx]) AddLink(ctx context.Context, parentName string, parentId uuid.UUID, childName string, ...) error
- func (storage Stores[Tx]) AddMap(ctx context.Context, actorName string, identifiers spry.Identifiers, ...) error
- func (storage Stores[Tx]) AddSnapshot(ctx context.Context, actorName string, snapshot Snapshot, allowPartition bool) error
- func (storage Stores[Tx]) Commit(ctx context.Context) error
- func (storage Stores[Tx]) FetchAggregatedEventsSince(ctx context.Context, actorName string, actorId uuid.UUID, eventId uuid.UUID, ...) ([]EventRecord, error)
- func (storage Stores[Tx]) FetchEventsSince(ctx context.Context, actorName string, actorId uuid.UUID, eventId uuid.UUID) ([]EventRecord, error)
- func (storage Stores[Tx]) FetchId(ctx context.Context, actorName string, identifiers spry.Identifiers) (uuid.UUID, error)
- func (storage Stores[Tx]) FetchIdMap(ctx context.Context, actorName string, actorId uuid.UUID) (AggregateIdMap, error)
- func (storage Stores[Tx]) FetchLatestSnapshot(ctx context.Context, actorName string, actorId uuid.UUID) (Snapshot, error)
- func (storage Stores[Tx]) GetContext(ctx context.Context) (context.Context, error)
- func (storage Stores[Tx]) RegisterPrimitives(types ...any)
- func (storage Stores[Tx]) Rollback(ctx context.Context) error
- type StringTemplate
- type TxProvider
- type TypeMap
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type ActorRepository ¶
type ActorRepository[T spry.Actor[T]] struct { Repository[T] }
func GetActorRepositoryFor ¶
func GetActorRepositoryFor[T spry.Actor[T]](storage Storage) ActorRepository[T]
func (ActorRepository[T]) Fetch ¶
func (repository ActorRepository[T]) Fetch(ids spry.Identifiers) (T, error)
type AggregateIdMap ¶
type AggregateIdMap struct {
ActorName string
ActorId uuid.UUID
Aggregated AggregatedIds
}
func CreateAggregateIdMap ¶
func CreateAggregateIdMap(actorName string, actorId uuid.UUID) AggregateIdMap
func EmptyAggregateIdMap ¶
func EmptyAggregateIdMap() AggregateIdMap
type AggregateRepository ¶
type AggregateRepository[T spry.Aggregate[T]] struct { Repository[T] }
func GetAggregateRepositoryFor ¶
func GetAggregateRepositoryFor[T spry.Aggregate[T]](storage Storage) AggregateRepository[T]
func (AggregateRepository[T]) Fetch ¶
func (repository AggregateRepository[T]) Fetch(ids spry.Identifiers) (T, error)
type AggregatedIds ¶
type CommandRecord ¶
type CommandRecord struct {
// a generated uuid for this event
Id uuid.UUID `json:"id"`
// the type name of the command
Type string `json:"type"`
// namespace for the command
Namespace string `json:"namespace"`
// the time the command was handled
CreatedOn time.Time `json:"createdOn"`
// the time the command was handled
ReceivedOn time.Time `json:"receivedOn"`
// the time the command was handled
HandledOn time.Time `json:"handledOn"`
// the id of the recipient actor
HandledBy uuid.UUID `json:"handledBy"`
// the version of the actor that handled the command
HandledVersion uint64
// the contents of the command
Data any `json:"data"`
}
func NewCommandRecord ¶
func NewCommandRecord(command spry.Command) (CommandRecord, error)
func (CommandRecord) IsValid ¶
func (command CommandRecord) IsValid() bool
type CommandStore ¶
type CommandStore interface {
Add(context.Context, string, CommandRecord) error
}
type EventRecord ¶
type EventRecord struct {
// a generated uuid for this event
Id uuid.UUID `json:"id"`
// the type name of the event
Type string `json:"type"`
// inferred from the actor emitting the event
ActorNamespace string `json:"namespace"`
// this is the addressable identity of the owning model
ActorId uuid.UUID `json:"actorId"`
// the type of the model the event was generated for
ActorName string `json:"actor"`
// UTC ISO date time string when event was created
CreatedOn time.Time `json:"createdOn"`
// the type of the actor instantiating the event
CreatedBy string `json:"createdBy"`
// the id of the snapshot instantiating the event
CreatedById uuid.UUID `json:"createdById"`
// the vector of the snapshot instantiating the event
CreatedByVector string `json:"createdByVector"`
// the version of the snapshot instantiating the event
CreatedByVersion uint64 `json:"createdByVersion"`
// the command type/topic that triggered the event
InitiatedBy string `json:"initiatedBy"`
// the id of the message that triggered the event
InitiatedById uuid.UUID `json:"initiatedById"`
// the contents of the event
Data any `json:"data"`
}
func NewEventRecord ¶
func NewEventRecord(event spry.Event) (EventRecord, error)
func (EventRecord) IsValid ¶
func (event EventRecord) IsValid() bool
type EventStore ¶
type IdAssignment ¶
type IdAssignment struct {
ActorName string
AssignedId uuid.UUID
Identifiers spry.Identifiers
Json string
}
func NewAssignment ¶
func NewAssignment(name string, ids spry.Identifiers, id uuid.UUID) IdAssignment
type IdAssignments ¶
type IdAssignments struct {
// contains filtered or unexported fields
}
func NewAssignments ¶
func NewAssignments(aggregateName string) IdAssignments
func (*IdAssignments) AddAssignment ¶
func (a *IdAssignments) AddAssignment(name string, ids spry.Identifiers, id uuid.UUID)
func (*IdAssignments) CreateAssignment ¶
func (a *IdAssignments) CreateAssignment(name string, ids spry.Identifiers) uuid.UUID
func (*IdAssignments) GetAggregateId ¶
func (a *IdAssignments) GetAggregateId() uuid.UUID
func (*IdAssignments) GetIdFor ¶
func (a *IdAssignments) GetIdFor(name string, ids spry.Identifiers) uuid.UUID
type LastEventMap ¶
func CreateLastEvents ¶
func CreateLastEvents() LastEventMap
func (*LastEventMap) AddLastEventFor ¶
func (*LastEventMap) UpdateFromMap ¶
func (last *LastEventMap) UpdateFromMap(idMap AggregateIdMap)
type Repository ¶
type Repository[T any] struct { ActorType reflect.Type ActorName string Storage Storage Mapping TypeMap }
func (Repository[T]) Apply ¶
func (repository Repository[T]) Apply(events []spry.Event, actor T) T
A side-effect free way of applying events to an actor instance
type Snapshot ¶
type Snapshot struct {
// aggregates track records and last events from each
// for each child type, track the last event per Identifier
LastEventMap
// a generated uuid (system id) for the snapshot instance
Id uuid.UUID `json:"id"`
// this is the addressable identity of the owning model
ActorId uuid.UUID `json:"actorId"`
// the type name of the actor
Type string `json:"type"`
// a serialized causal tracker
Vector string `json:"vector"`
// a numeric version of the model
Version uint64 `json:"version"`
// the causal tracker of the preceding snapshot
Ancestor string `json:"ancestor"`
// UTC ISO date time string when event was created
CreatedOn time.Time `json:"createdOn"`
// the number of events applied to reach the present state
EventsApplied uint64 `json:"eventsApplied"`
// the number of events since the last snapshot was created
EventSinceSnapshot int
// the UUID of the last event played against the instance
LastEventId uuid.UUID `json:"lastEventId"`
// the UUID of the last command handled
LastCommandId uuid.UUID `json:"lastCommandId"`
// the wall clock at the time of the last command
LastCommandOn time.Time `json:"lastCommandOn"`
// the wall clock at the time of the last event
LastEventOn time.Time `json:"lastEventOn"`
// the contents of the snapshot
Data any `json:"data"`
}
func NewSnapshot ¶
type SnapshotStore ¶
type Storage ¶
type Storage interface {
AddCommand(context.Context, string, CommandRecord) error
AddEvents(context.Context, []EventRecord) error
AddMap(context.Context, string, spry.Identifiers, uuid.UUID) error
AddSnapshot(context.Context, string, Snapshot, bool) error
AddLink(context.Context, string, uuid.UUID, string, uuid.UUID) error
Commit(context.Context) error
FetchAggregatedEventsSince(context.Context, string, uuid.UUID, uuid.UUID, LastEventMap) ([]EventRecord, error)
FetchEventsSince(context.Context, string, uuid.UUID, uuid.UUID) ([]EventRecord, error)
FetchId(context.Context, string, spry.Identifiers) (uuid.UUID, error)
FetchIdMap(context.Context, string, uuid.UUID) (AggregateIdMap, error)
FetchLatestSnapshot(context.Context, string, uuid.UUID) (Snapshot, error)
GetContext(context.Context) (context.Context, error)
RegisterPrimitives(...any)
Rollback(context.Context) error
}
func NewStorage ¶
func NewStorage[Tx any]( commands CommandStore, events EventStore, maps MapStore, snapshots SnapshotStore, txs TxProvider[Tx]) Storage
type Stores ¶
type Stores[Tx any] struct { Commands CommandStore Events EventStore Maps MapStore Primitives TypeMap Snapshots SnapshotStore Transactions TxProvider[Tx] }
func (Stores[Tx]) AddCommand ¶
func (Stores[Tx]) AddEvents ¶
func (storage Stores[Tx]) AddEvents(ctx context.Context, events []EventRecord) error
func (Stores[Tx]) AddSnapshot ¶
func (Stores[Tx]) FetchAggregatedEventsSince ¶
func (Stores[Tx]) FetchEventsSince ¶
func (Stores[Tx]) FetchIdMap ¶
func (Stores[Tx]) FetchLatestSnapshot ¶
func (Stores[Tx]) GetContext ¶
func (Stores[Tx]) RegisterPrimitives ¶
type StringTemplate ¶
type StringTemplate struct {
// contains filtered or unexported fields
}
func CreateTemplateFromFS ¶
func CreateTemplateFromFS(files fs.FS, paths ...string) (*StringTemplate, error)
type TxProvider ¶
Click to show internal directories.
Click to hide internal directories.