Skip to content

Instantly share code, notes, and snippets.

@leegilmorecode
Created December 3, 2022 05:52
Show Gist options
  • Save leegilmorecode/58c060a5e5d3755e6ce3adb7ffd326f7 to your computer and use it in GitHub Desktop.
Save leegilmorecode/58c060a5e5d3755e6ce3adb7ffd326f7 to your computer and use it in GitHub Desktop.
Example repository for publishing domain events via a secondary adapter
import { DomainEvent } from '@entity/domain-event';
import { publishEvent } from '@adapters/secondary/event-adapter';
// this is the repository which the domain calls to utilise the adapter
// only working with domain entities, and translating dto's from the secondary adapters
// domain --> (repository) --> adapter
export async function publishDomainEvents(
events: DomainEvent[]
): Promise<void> {
const eventsToPublish: Promise<void>[] = events.map((item) =>
publishEvent(
item.event,
item.eventName,
item.source,
item.eventVersion,
item.eventDateTime
)
);
await Promise.all(eventsToPublish);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment