Documentation
¶
Overview ¶
Command eventmap-gen generates mapping code between domain events and event sourcing types.
Usage:
go run github.com/getpup/pupsourcing/cmd/eventmap-gen \ -input internal/core/component/user/domain/user/events \ -output internal/infrastructure/component/user/persistence/es/generated
The tool discovers domain event structs in the input directory and generates strongly-typed mapping functions for converting between domain events and pupsourcing core types (es.Event and es.PersistedEvent).
Versioned Events ¶
The tool supports event versioning through directory structure. Subdirectories named v1, v2, v3, etc. indicate the event version:
events/
v1/
user_registered.go
user_email_changed.go
v2/
user_registered.go // New version with different schema
If no version directory exists, the default version is 1.
Generated Code ¶
The tool generates:
- EventTypeOf(e any) - Resolves event type string from domain event
- ToESEvents(boundedContext, aggregateType, aggregateID, events, opts...) - Converts domain events to es.Event
- FromESEvents[T](events) - Converts es.PersistedEvent to domain events (using generics)
- Type-safe helpers per event (ToUserRegisteredV1, FromUserRegisteredV1, etc.)
Clean Architecture ¶
This tool maintains clean architecture boundaries:
- Domain events remain pure (no dependency on pupsourcing)
- Generated code lives in the infrastructure layer
- Generated code may depend on pupsourcing
- No runtime reflection or magic
- All mapping is explicit and inspectable
Click to show internal directories.
Click to hide internal directories.