Skip to content

ExternalContextOptions

reference
2 min readUpdated

Kind: Interface

Source: packages/core/helpers/external-context-creator.ts

Part of: Core

ExternalContextOptions controls which framework-level enhancements are applied when creating an external execution context. It allows callers to enable or disable guards, interceptors, and exception filters independently for handlers invoked outside the standard request pipeline.

Properties

PropertyType
guardsboolean
interceptorsboolean
filtersboolean

Diagram

mermaid
graph LR
  A[External Context Creation] --> B[ExternalContextOptions]
  B --> C{guards enabled?}
  B --> D{interceptors enabled?}
  B --> E{filters enabled?}
  C --> F[Apply Guards]
  D --> G[Apply Interceptors]
  E --> H[Apply Exception Filters]

Usage

ts
import { ExternalContextOptions } from './helpers/external-context-creator';

const options: ExternalContextOptions = {
  guards: true,
  interceptors: true,
  filters: false,
};

// Pass options when creating an external handler context.
// Guards and interceptors run, while exception filters are skipped.
const handler = externalContextCreator.create(
  instance,
  method,
  methodName,
  options,
);

AI Coding Instructions

  • Provide all three boolean fields when constructing ExternalContextOptions; do not rely on implicit defaults.
  • Enable guards when external handlers must enforce authorization or access-control rules.
  • Enable interceptors when handlers require cross-cutting behavior such as logging, transformation, caching, or timing.
  • Enable filters when exceptions should be processed through configured exception filters instead of propagating directly.
  • Keep option values aligned with the execution environment so external contexts behave consistently with the intended application pipeline.

How it works

ExternalContextOptions is an exported TypeScript interface used as the options parameter of ExternalContextCreator.create() to select whether the generated external handler runs guards, creates/runs interceptors, and wraps execution in external exception-filter handling. Its three optional boolean fields are guards, interceptors, and filters. packages/core/helpers/external-context-creator.ts:32-36 packages/core/helpers/external-context-creator.ts:91-108

The options do not control pipe creation or parameter-pipe application: create() constructs pipes before testing these flags, and its handler applies parameter pipes when parameter metadata exists. packages/core/helpers/external-context-creator.ts:114-120 packages/core/helpers/external-context-creator.ts:153-162

Was this page helpful?

Download as PDF
ExternalContextOptions — NestJS head-to-head