Skip to content

Creating Elements

Information

Call functions in d.info to create information.

In practice, you don't always need to explicitly call functions. All nodes accept plain strings as parameters, so only use these functions when you need special annotation

id

Typically represents an aggregate id

ts
const bookId = d.info.id('bookId', 'Book ID note')

valueObj

Ordinary values without special meaning

ts
const bookName = d.info.valueObj('name', 'Book Name')

document

Experimental Feature

This is an experimental feature. Its business semantic necessity and universality are uncertain. Feedback is welcome.

Represents a document or binary file value

ts
d.info.document('networkPacket', 'Network packet')

func

Experimental Feature

This is an experimental feature. Its business semantic necessity and universality are uncertain. Feedback is welcome.

Represents a value that needs to be calculated by a function

ts
const bookValues = {
  bookPrice: i.valueObj('price', 'Book price'),
}
const orderValues = {
  quantity: i.valueObj('quantity', 'Order quantity'),
}
d.func(
      'FinalPrice',
      [bookValues.bookPrice, orderValues.quantity],
      `Final price = Book price * Order quantity`
    ),

version

Experimental Feature

This is an experimental feature. Its business semantic necessity and universality are uncertain. Feedback is welcome.

Represents a value with business meaning indicating version

ts
d.info.version(
  'wikiEntryVersion',
  `Wiki entry version number.
    Although version numbers might just be optimistic locking fields to technicians, they have concrete business meaning in "wiki entries"`
)

Nodes

Each node corresponds to a node in event storming

actor

ts
d.actor('Administrator')

facadeCmd

ts
d.facadeCmd(
  'CreateUserFacadeCmd',
  ['userName', 'email', ['gender', 'Gender']],
  'Create user facade command'
)

Equivalent to

ts
d.command(
  'CreateUserFacadeCmd',
  [
    d.info.valueObj('userName'),
    d.info.valueObj('email'),
    d.info.valueObj('gender', 'Gender'),
  ],
  'Create user facade command'
)

command

ts
d.command(
  'CreateUserCmd',
  ['userName', 'email', ['gender', 'Gender']],
  'Create user command'
)

Equivalent to

ts
d.command(
  'CreateUserCmd',
  [
    d.info.valueObj('userName'),
    d.info.valueObj('email'),
    d.info.valueObj('gender', 'Gender'),
  ],
  'Create user command'
)

agg

ts
d.agg(
  'OrderAgg',
  [d.info.id('orderId'), 'orderItems', ['orderStatus', 'Order status']],
  'Order aggregate'
)

Equivalent to

ts
d.agg(
  'OrderAgg',
  [
    d.info.id('orderId'),
    d.info.valueObject('orderItems'),
    d.info.valueObject('orderStatus', 'Order status'),
  ],
  'Order aggregate'
)

event

ts
d.event(
  'OrderPlaced',
  [d.info.id('orderSequence', 'Order serial number'), 'orderItems'],
  'Order placed'
)

Equivalent to

ts
d.event(
  'OrderPlaced',
  [d.info.id('orderSequence', 'Order serial number'), d.info.valueObject('orderItems')],
  'Order placed'
)

system

ts
d.system('MailSystem', 'Mail system')

service

ts
d.service('PaymentService', 'Payment service')

policy

ts
d.policy(
  'PaymentPolicy',
  `Payment rules
    1. xxx
    2. xxx
    ...`
)

readModel

ts
d.readModel(
  'OrderDetailReadModel',
  [d.info.id('orderId'), ['orderTime', 'Order time']],
  'Order detail read model'
)

Equivalent to

ts
d.readModel(
  'OrderDetailReadModel',
  [d.info.id('orderId'), d.info.valueObj('orderTime', 'Order time')],
  'Order detail read model'
)

Notes

Usually the last parameter of a function is an optional note. For less complex requirements, just passing strings is enough. But we can also choose to pass notes containing variable references generated by the note function.

For example:

ts
const i = d.info
// "Authorization system" needs multi-line, clear notes, so use TS template strings
const AuthorizationSystem = d.system(
  'AuthorizationSystem',
  `Authorization system
    Has the following responsibilities:
    1. Authentication
    2. Authorization
    3. Permission granting
    ...`
)
// "User recharged" doesn't need special notes, so pass a plain string
const UserRecharged = d.event('UserRecharged', [i.id('userId')], 'User recharged')
// "User status" is related to the authorization system, so use the note function
const UserStatus = d.info.valueObject(
  'userStatus',
  d.note`User status
    User status is not maintained by this system but synchronized from ${AuthorizationSystem}`
)