import type { IEvent } from './IEvent.ts'; import { isObject } from './isObject.ts'; import type { IMessageMeta } from './IMessageMeta.ts'; /** * Represents a wrapper for an event that can optionally contain additional metadata. * Used to extend event processing with context-specific data required by processors. */ export type DispatchPipelineEnvelope = { /** * Origin of the event. Can be used to distinguish between events coming from different sources. */ origin?: string; /** * When true, storage writers may bypass optimistic-concurrency checks for this batch. */ ignoreConcurrencyError?: boolean; event?: IEvent; } & IMessageMeta; /** * A batch of event envelopes. Can contain custom envelope types extending EventEnvelope. */ export type DispatchPipelineBatch = Readonly>; /** * Defines a processor that operates on a batch of event envelopes. * Allows transformations, side-effects, or filtering of events during dispatch. */ export interface IDispatchPipelineProcessor { process(batch: DispatchPipelineBatch): Promise>; revert?(batch: DispatchPipelineBatch): Promise; } export const isDispatchPipelineProcessor = (obj: unknown): obj is IDispatchPipelineProcessor => isObject(obj) && 'process' in obj && typeof (obj as IDispatchPipelineProcessor).process === 'function';