Skip to content

BasePipelineContext

Defined in: packages/pipeline/src/pipeline.context.ts:27

Abstract base class with shared implementation for all pipeline contexts.

Provides default implementations for:

  • getBehaviorOptions() — reads from the pre-computed options map
  • response — readonly holder for the handler’s return value (set via Symbol)
  • Common fields (correlationId, startedAt, items)

Extend this class to create custom context variants for specialized pipelines. Behaviors should still type-hint against IPipelineContext (the interface).

TRequest = unknown

TResponse = unknown

new BasePipelineContext<TRequest, TResponse>(): BasePipelineContext<TRequest, TResponse>

Defined in: packages/pipeline/src/pipeline.context.ts:105

BasePipelineContext<TRequest, TResponse>

abstract protected readonly behaviorOptionsMap: Map<BehaviorId, Record<string, unknown>> | undefined

Defined in: packages/pipeline/src/pipeline.context.ts:101

Options per behavior for this handler: global [Behavior, opts] tuple options, shallowly overridden by the call site’s options.


abstract readonly handlerName: string

Defined in: packages/pipeline/src/pipeline.context.ts:71

The handler class name string, e.g. “CreateUserHandler”.

IPipelineContext.handlerName


abstract readonly handlerType: Constructor

Defined in: packages/pipeline/src/pipeline.context.ts:70

The handler class (constructor) that will process this request.

IPipelineContext.handlerType


readonly items: Map<string | symbol, unknown>

Defined in: packages/pipeline/src/pipeline.context.ts:79

Bag for sharing arbitrary data between behaviors in the same execution. Supports string and unique symbol keys.

IPipelineContext.items


abstract readonly request: TRequest

Defined in: packages/pipeline/src/pipeline.context.ts:67

The command/query/event instance with all its property values.

IPipelineContext.request


abstract readonly requestKind: "command" | "query" | "event" | "unknown"

Defined in: packages/pipeline/src/pipeline.context.ts:72

‘command’, ‘query’, or ‘event’: declared when wrapping, or read from the request’s brand.

IPipelineContext.requestKind


abstract readonly requestName: string

Defined in: packages/pipeline/src/pipeline.context.ts:69

The class name string, e.g. “CreateUserCommand”.

IPipelineContext.requestName


abstract readonly requestType: Constructor<TRequest>

Defined in: packages/pipeline/src/pipeline.context.ts:68

The class (constructor) of the command/query/event.

IPipelineContext.requestType


readonly startedAt: Date

Defined in: packages/pipeline/src/pipeline.context.ts:74

UTC timestamp when the pipeline execution started.

IPipelineContext.startedAt

get correlationId(): string

Defined in: packages/pipeline/src/pipeline.context.ts:34

Immutable correlation ID for distributed tracing: the current correlation id when the pipeline starts (from @cqrs-ddd/pipeline-correlation, or the enclosing pipeline), otherwise a new one from the correlation source’s create() (uuidv7() without one). Nested dispatches inherit it.

string

Immutable correlation ID for distributed tracing: the current correlation id when the pipeline starts (from @cqrs-ddd/pipeline-correlation, or the enclosing pipeline), otherwise a new one from the correlation source’s create() (uuidv7() without one). Nested dispatches inherit it.

IPipelineContext.correlationId


get response(): TResponse | undefined

Defined in: packages/pipeline/src/pipeline.context.ts:85

The handler’s return value. Read-only for behaviors.

TResponse | undefined

The handler’s return value, set automatically after the real handler executes. Available to behaviors in their post-next() code path. undefined before the handler runs or for event handlers that return void.

IPipelineContext.response


get tenantId(): string | undefined

Defined in: packages/pipeline/src/pipeline.context.ts:48

Active tenant identifier for multi-tenant pipeline executions.

string | undefined

Tenant of this execution: the current tenant when the pipeline starts (from @cqrs-ddd/pipeline-tenant, or the enclosing pipeline), which nested dispatches inherit. Absent when there is none; tenant-scoped behaviors then fail closed.

IPipelineContext.tenantId

[SET_CORRELATION_ID](value): void

Defined in: packages/pipeline/src/pipeline.context.ts:39

Internal

Assigns the ID before the behavior chain starts.

string

void


[SET_RESPONSE](value): void

Defined in: packages/pipeline/src/pipeline.context.ts:93

Symbol-keyed setter — only callable by code that imports SET_RESPONSE. This keeps response effectively readonly for behaviors.

TResponse | undefined

void


[SET_TENANT_ID](value): void

Defined in: packages/pipeline/src/pipeline.context.ts:58

Assigns the tenant once per execution. A different value after one is set (by the runner, from the tenant source or the enclosing pipeline) throws, so a behavior cannot move an execution to another tenant after an earlier behavior has used it.

string | undefined

void


getBehaviorOptions<T>(behaviorType): T | undefined

Defined in: packages/pipeline/src/pipeline.context.ts:115

Returns the options for a behavior on this handler: the options from a global [Behavior, opts] tuple, shallowly overridden by the options of the call site’s [Behavior, opts] entry.

T = Record<string, unknown>

Constructor

T | undefined

IPipelineContext.getBehaviorOptions