Skip to content

BasePipelineContext

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

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:107

BasePipelineContext<TRequest, TResponse>

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

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

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


abstract readonly handlerName: string

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

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

IPipelineContext.handlerName


abstract readonly handlerType: Type

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

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:81

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:69

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:74

‘command’, ‘query’, or ‘event’ — detected at bootstrap from NestJS metadata.

IPipelineContext.requestKind


abstract readonly requestName: string

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

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

IPipelineContext.requestName


abstract readonly requestType: Type<TRequest>

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

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

IPipelineContext.requestType


readonly startedAt: Date

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

UTC timestamp when the pipeline execution started.

IPipelineContext.startedAt

get correlationId(): string

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

Immutable correlation ID for distributed tracing: the current correlation id when the pipeline starts (from @nestjs-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 @nestjs-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:87

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:50

Active tenant identifier for multi-tenant pipeline executions.

string | undefined

Tenant of this execution: the current tenant when the pipeline starts (from @nestjs-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:41

Internal

Assigns the ID before the behavior chain starts.

string

void


[SET_RESPONSE](value): void

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

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:60

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:117

Returns the options for a behavior on this handler: the options from a global [Behavior, opts] tuple, shallowly overridden by the options from the handler’s @UsePipeline([Behavior, opts]).

T = Record<string, unknown>

Type

T | undefined

IPipelineContext.getBehaviorOptions