Skip to main content

writeEvent

Callable

  • writeEvent(directory: string): (event: Event, options?: { override?: boolean; path?: string; versionExistingContent?: boolean }) => Promise<void>

  • Write an event to EventCatalog.

    You can optionally overide the path of the event.

    @example
    import utils from '@eventcatalog/utils';

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

    // Write an event to the catalog
    // Event would be written to events/InventoryAdjusted
    await writeEvent({
    id: 'InventoryAdjusted',
    name: 'Inventory Adjusted',
    version: '0.0.1',
    summary: 'This is a summary',
    markdown: '# Hello world',
    });

    // Write an event to the catalog but override the path
    // Event would be written to events/Inventory/InventoryAdjusted
    await writeEvent({
    id: 'InventoryAdjusted',
    name: 'Inventory Adjusted',
    version: '0.0.1',
    summary: 'This is a summary',
    markdown: '# Hello world',
    }, { path: "/Inventory/InventoryAdjusted"});

    // Write a event to the catalog and override the existing content (if there is any)
    await writeEvent({
    id: 'InventoryAdjusted',
    name: 'Inventory Adjusted',
    version: '0.0.1',
    summary: 'This is a summary',
    markdown: '# Hello world',
    }, { override: true });

    // Write a event to the catalog and version the previous version
    // only works if the new version is greater than the previous version
    await writeEvent({
    id: 'InventoryAdjusted',
    name: 'Inventory Adjusted',
    version: '0.0.1',
    summary: 'This is a summary',
    markdown: '# Hello world',
    }, { versionExistingContent: true });