Services run commands through a CommandRunner that runs one again (up to 5 times, waiting a little longer each time) when its aggregate changed underneath, e.g. a saga writing to the same ticket. Each command loads its aggregate fresh and stores its events in one transaction, so a ConcurrencyError means nothing was stored and running it again is safe. People no longer get a 409 for it, and the e2e suite stops flaking. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
api-shared-application
Contrato del event store y reconstrucción de agregados.
- Import:
@task-stream/api/shared/application - Capa:
application· Tags:scope:api-shared,type:application
Contenido
EventStore(puerto):persistygetEventsByStreamId.AggregateRehydrator: carga los eventos de un stream y devuelve el agregado reconstruido, ya enlazado con elEventPublisher.EventRecorder: guarda un evento en un stream que no es de ningún agregado propio (p. ej. un usuario de Pireon), en la siguiente posición, para que otros contextos reaccionen a él.SharedModule.withInfrastructure(...): módulo global que expone el event store, el rehydrator y el recorder a todos los contextos.
Comandos
npx nx lint api-shared-application
npx nx test api-shared-application # Jest
Reglas de dependencia entre capas: Arquitectura.