Skip to main content

Function: writeEntity()

writeEntity(directory): (entity, options) => Promise<void>

Defined in: entities.ts:108

Write an entity to EventCatalog.

You can optionally override the path of the entity.

Parameters

ParameterType
directorystring

Returns

Function

Parameters

ParameterType
entityEntity
options{ format: "md" | "mdx"; override: boolean; path: string; versionExistingContent: boolean; }
options.format?"md" | "mdx"
options.override?boolean
options.path?string
options.versionExistingContent?boolean

Returns

Promise<void>

Example

import utils from '@eventcatalog/utils';

const { writeEntity } = utils('/path/to/eventcatalog');

// Write an entity to the catalog
// Entity would be written to entities/User
await writeEntity({
id: 'User',
name: 'User',
version: '0.0.1',
summary: 'User entity',
markdown: '# User entity',
});

// Write an entity to the catalog but override the path
// Entity would be written to entities/Account/User
await writeEntity({
id: 'User',
name: 'User',
version: '0.0.1',
summary: 'User entity',
markdown: '# User entity',
}, { path: "/Account/User"});

// Write an entity to the catalog and override the existing content (if there is any)
await writeEntity({
id: 'User',
name: 'User',
version: '0.0.1',
summary: 'User entity',
markdown: '# User entity',
}, { override: true });

// Write an entity to the catalog and version the previous version
// only works if the new version is greater than the previous version
await writeEntity({
id: 'User',
name: 'User',
version: '0.0.1',
summary: 'User entity',
markdown: '# User entity',
}, { versionExistingContent: true });