function defineIntegrationEvent
Since 0.6.0
defineIntegrationEvent<T>(options: { type: string; version: number; topic: string; parse: (value: unknown) => T; }): IntegrationEventDefinition<T>

Defines a versioned integration-event contract and validates it eagerly.

The versioned-topic rollout policy is enforced here rather than documented: the topic must end with the exact string .v${version} (for example orders.placed.v2 for version 2), so a version bump that leaves the topic unchanged is refused at definition time — at module load, loudly — instead of silently breaking every deployed consumer of the previous version. A pre-existing topic that predates this policy has no versioned suffix by design; keep using the raw broker.publish/broker.subscribe surface for it, which this milestone does not change.

Examples

Example 1

import { defineIntegrationEvent } from '@setu-ts/messaging-plugin';

const orderPlaced = defineIntegrationEvent<{ orderId: string }>({
  type: 'orders.placed',
  version: 1,
  topic: 'orders.placed.v1',
  parse: (value) => value as { orderId: string },
});

Type Parameters

The event payload type parse produces

Parameters

options: { type: string; version: number; topic: string; parse: (value: unknown) => T; }

The contract's four fields

Return Type

The validated definition, with every field exposed unchanged

Throws

TypeError

When type or topic is empty, version is not a positive safe integer, parse is absent, or topic does not end with the exact .v${version} suffix

Usage

import { defineIntegrationEvent } from "messaging-plugin/src/index.ts";