Setu-TS
    Preparing search index...

    Function defineIntegrationEvent

    • 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.

      Type Parameters

      • T

        The event payload type parse produces

      Parameters

      • options: {
            orderingKey?: (
                envelope: IntegrationEventEnvelope<T>,
            ) => string | undefined;
            parse: (value: unknown) => T;
            topic: string;
            type: string;
            version: number;
        }

        The contract's four fields

      Returns IntegrationEventDefinition<T>

      The validated definition, with every field exposed unchanged

      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

      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 },
      });

      0.6.0