Skip to main content

writeChannel

Callable

  • writeChannel(directory: string): (channel: Channel, options?: { override?: boolean; path?: string; versionExistingContent?: boolean }) => Promise<void>

  • Write a channel to EventCatalog.

    You can optionally override the path of the channel.

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

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

    // Write a channel to the catalog
    // channel would be written to channels/inventory.{env}.events
    await writeChannel({
    id: 'inventory.{env}.events',
    name: 'Inventory channel',
    version: '0.0.1',
    summary: 'This is a summary',
    markdown: '# Hello world',
    address: inventory.{env}.events,
    protocols: ['http'],
    });

    // Write a channel to the catalog but override the path
    // channel would be written to channels/Inventory/InventoryChannel
    await writeChannel({
    id: 'InventoryChannel',
    name: 'Update Inventory',
    version: '0.0.1',
    summary: 'This is a summary',
    markdown: '# Hello world',
    address: inventory.{env}.events,
    protocols: ['http'],
    }, { path: "/channels/Inventory/InventoryChannel"});

    // Write a channel to the catalog and override the existing content (if there is any)
    await writeChannel({
    id: 'InventoryChannel',
    name: 'Update Inventory',
    version: '0.0.1',
    summary: 'This is a summary',
    markdown: '# Hello world',
    address: inventory.{env}.events,
    protocols: ['http'],
    }, { override: true });

    // Write a channel to the catalog and version the previous version
    // only works if the new version is greater than the previous version
    await writeChannel({
    id: 'InventoryChannel',
    name: 'Update Inventory',
    version: '0.0.1',
    summary: 'This is a summary',
    markdown: '# Hello world',
    address: inventory.{env}.events,
    protocols: ['http'],
    }, { versionExistingContent: true });