Summary
Extend the opt-in emitEvents capability (added for TypeScript in #79 / PR #80) to the Go (Gin + GORM) generator, so that opted-in entities produce a durable domain-event spine written in the same transaction as the state change.
Today emitEvents is parsed and honored only by the TypeScript generator; the Go generator inherits the base no-op (generateDomainEvents returns []), so emitEvents is silently ignored for Go projects.
Reference
#79 / PR #80 is the reference spec. The TypeScript implementation generates a DomainEvent entity (events table), a subscriber writing events transactionally, an app-overridable mapper (event-type taxonomy + payload), a relay (drain/retry; publish() is the app-supplied delivery hook), and a global module wired into the app. Flag resolution is entity.emitEvents ?? <top-level emitEvents> ?? false (global default with per-entity opt-out). Keep the same naming and the same extension-point boundaries.
Language-specific mechanism
The durability lever is ORM-specific. For GORM:
- Use GORM hooks (
AfterCreate/AfterUpdate/AfterDelete) or a registered callback/plugin to write the event row using the hook's *gorm.DB (tx), so the event is inserted within the same transaction as the state change.
- Map create/update/delete to
created/updated/removed.
- Recursion guard: never emit for the
DomainEvent model itself.
- Scope emission to the opted-in entities only.
- Provide mapper + relay as overridable extension points (delivery left to the app); a
DomainEvent model + events table; relay drains pending rows.
Scope / notes
Environment
Summary
Extend the opt-in
emitEventscapability (added for TypeScript in #79 / PR #80) to the Go (Gin + GORM) generator, so that opted-in entities produce a durable domain-event spine written in the same transaction as the state change.Today
emitEventsis parsed and honored only by the TypeScript generator; the Go generator inherits the base no-op (generateDomainEventsreturns[]), soemitEventsis silently ignored for Go projects.Reference
#79 / PR #80 is the reference spec. The TypeScript implementation generates a
DomainEvententity (eventstable), a subscriber writing events transactionally, an app-overridable mapper (event-type taxonomy + payload), a relay (drain/retry;publish()is the app-supplied delivery hook), and a global module wired into the app. Flag resolution isentity.emitEvents ?? <top-level emitEvents> ?? false(global default with per-entity opt-out). Keep the same naming and the same extension-point boundaries.Language-specific mechanism
The durability lever is ORM-specific. For GORM:
AfterCreate/AfterUpdate/AfterDelete) or a registered callback/plugin to write the event row using the hook's*gorm.DB(tx), so the event is inserted within the same transaction as the state change.created/updated/removed.DomainEventmodel itself.DomainEventmodel +eventstable; relay drains pending rows.Scope / notes
Environment
@apso/cli— language: go (Gin + GORM)