Skip to main content

Function: addMessageToDomain()

addMessageToDomain(directory): (id, direction, message, version?) => Promise<void>

Defined in: domains.ts:516

Add an event/command/query to a domain by its id.

Optionally specify a version to add the message to a specific version of the domain.

Parameters​

ParameterType
directorystring

Returns​

Function

Parameters​

ParameterType
idstring
directionstring
message{ id: string; version: string; }
message.idstring
message.version?string
version?string

Returns​

Promise<void>

Example​

import utils from '@eventcatalog/utils';

// Adds an event to the domain
const { addEventToDomain, addCommandToDomain, addQueryToDomain } = utils('/path/to/eventcatalog');

// Adds a new event (OrderCreated) that the Orders domain will send
await addEventToDomain('Orders', 'sends', { id: 'OrderCreated', version: '2.0.0' });

// Adds a new event (PaymentProcessed) that the Orders domain will receive
await addEventToDomain('Orders', 'receives', { id: 'PaymentProcessed', version: '1.0.0' });

// Adds a new command (ProcessOrder) that the Orders domain will receive
await addCommandToDomain('Orders', 'receives', { id: 'ProcessOrder', version: '1.0.0' });

// Adds a message to a specific version of the domain
await addEventToDomain('Orders', 'sends', { id: 'OrderShipped', version: '1.0.0' }, '2.0.0');