Interfaces

@system-inc/base-foundation · 515c140 · 13 symbols

A class-based middleware. Runs for each request via run().

Prefer classes when you need dependency injection. Otherwise BaseMiddlewareFn is simpler.

Members

  • run(requestContext: RequestContext): void | Response | Promise<void | Response>

View source ↗

Members

  • append(action: () => Promise<unknown>): void

View source ↗

A class-based handler-scoped middleware. Runs after the dispatcher has resolved the handler, so rc.handler is guaranteed to be present.

Prefer classes when you need dependency injection.

Members

View source ↗

A RequestContext narrowed to guarantee the handler has been resolved. Passed to handler-scoped middleware so implementations do not have to null-check rc.handler — the dispatcher has already established the invariant by the time handler middleware runs.

extends RequestContext

Members

  • configuration: BaseConfiguration

    The application configuration.

  • container: BaseInjectionContainer

    The dependency injection container scoped to this request.

  • cookies: Readonly<Record<string, string>>

    The parsed cookies from the incoming request.

  • deferred: DeferredActions

    Deferred actions to run asynchronously after the response is sent.

  • eventBus: BaseEventBus

    Event bus for emitting events related to this request.

  • graphql: Omit<GqlContext, "request"> | undefined

    If this request is a GraphQL request, the GraphQL context.

  • handler: BaseHandler

    Information about the handler method being invoked for this request. Undefined before dispatch or for framework routes that don't map to a handler (e.g., /__version).

  • headers: Headers

    The HTTP headers from the incoming request.

  • ipAddress?: string

    The IP address of the caller, if available.

  • isGraphQL: boolean

    Whether this request is a GraphQL request.

  • isInternal: boolean

    Whether this request originated from an internal (service-to-service) caller.

  • isRpc: boolean

    Whether this request is an RPC request.

  • method: string

    The HTTP method of the incoming request (GET, POST, etc.).

  • origin: RequestOrigin

    Geographic and locale information derived from the request (country, timezone, language preferences, etc.).

  • platform: unknown

    Platform-specific properties about/for the request.

  • requestId: string

    Unique identifier for this request.

  • response: ResponseWriter

    Response data that will be sent back to the client. Use this to set cookies or append headers to the response.

  • route: string

    The matched route path.

  • routing: RoutingInfo

    Origin / routing information derived from the request.

  • rpc: string | undefined

    If this request is an RPC request, the name of the procedure being called.

  • stopWatch: StopWatch

    Stop watch for the request.

  • url: string

    The full URL of the incoming request.

  • userAgent: string

    The user agent string of the caller.

  • get(key: RequestContextKey<T>): T | undefined

    Get a typed extension value from this request context.

  • require(key: RequestContextKey<T>): T

    Get a typed extension value from this request context, throwing if it's not set.

  • set(key: RequestContextKey<T>, value: T): void

    Set a typed extension value on this request context. Use this from middleware to attach per-request data.

View source ↗

Members

  • mode?: HttpBodyMode

    How to parse the request body.

    • json (default): parses the body as JSON
    • stream: provides the raw ReadableStream body
    • formData: parses the body as multipart/form-data
    • text: reads the body as a string
    • arrayBuffer: reads the body as an ArrayBuffer
    • blob: reads the body as a Blob

View source ↗

Members

  • decode?: boolean

    Whether to URL decode the parameter value. Defaults to true.

View source ↗

Members

  • decode?: boolean

    Whether to URL decode the parameter value. Defaults to true.

View source ↗

The application-facing context for the current request.

RequestContext provides a safe, structured projection of the incoming request. It exposes the metadata and capabilities that application code typically needs — HTTP metadata, caller info, DI, and response control — without exposing the raw Request body or stream methods that could lead to accidental data leaks.

All framework-owned fields are readonly from the application's perspective. The framework populates them on the underlying concrete implementation; app code reads them and may only write to its own typed-key extension bag via set, get, and require.

Module-specific concerns (device ID, session, account, etc.) should be stored and retrieved via the typed extension mechanism using RequestContextKey.

Obtain an instance via the @InjectRequestContext() parameter decorator.

Members

  • configuration: BaseConfiguration

    The application configuration.

  • container: BaseInjectionContainer

    The dependency injection container scoped to this request.

  • cookies: Readonly<Record<string, string>>

    The parsed cookies from the incoming request.

  • deferred: DeferredActions

    Deferred actions to run asynchronously after the response is sent.

  • eventBus: BaseEventBus

    Event bus for emitting events related to this request.

  • graphql: Omit<GqlContext, "request"> | undefined

    If this request is a GraphQL request, the GraphQL context.

  • handler: BaseHandler | undefined

    Information about the handler method being invoked for this request. Undefined before dispatch or for framework routes that don't map to a handler (e.g., /__version).

  • headers: Headers

    The HTTP headers from the incoming request.

  • ipAddress?: string

    The IP address of the caller, if available.

  • isGraphQL: boolean

    Whether this request is a GraphQL request.

  • isInternal: boolean

    Whether this request originated from an internal (service-to-service) caller.

  • isRpc: boolean

    Whether this request is an RPC request.

  • method: string

    The HTTP method of the incoming request (GET, POST, etc.).

  • origin: RequestOrigin

    Geographic and locale information derived from the request (country, timezone, language preferences, etc.).

  • platform: PlatformType | undefined

    Platform-specific properties about/for the request.

  • requestId: string

    Unique identifier for this request.

  • response: ResponseWriter

    Response data that will be sent back to the client. Use this to set cookies or append headers to the response.

  • route: string

    The matched route path.

  • routing: RoutingInfo

    Origin / routing information derived from the request.

  • rpc: string | undefined

    If this request is an RPC request, the name of the procedure being called.

  • stopWatch: StopWatch

    Stop watch for the request.

  • url: string

    The full URL of the incoming request.

  • userAgent: string

    The user agent string of the caller.

  • get(key: RequestContextKey<T>): T | undefined

    Get a typed extension value from this request context.

  • require(key: RequestContextKey<T>): T

    Get a typed extension value from this request context, throwing if it's not set.

  • set(key: RequestContextKey<T>, value: T): void

    Set a typed extension value on this request context. Use this from middleware to attach per-request data.

View source ↗

Interface for response transformers.

Members

  • transformResponse(response: Response, request?: RequestContext<unknown>): Response | Promise<Response>

    Transforms the response from the route handler.

View source ↗

Members

  • appendHeader(name: string, value: string): void

  • setCookie(cookieOptions: SetCookieOptions): void

View source ↗

Members

  • allowCredentials?: boolean

    Whether credentials are allowed.

  • allowedHeaders?: string[]

    The allowed headers.

  • allowedMethods?: string[]

    The allowed methods.

  • allowedOrigins?: NamedConfiguration<AllowedOrigin>

    The allowed origins.

  • exposedHeaders?: string[]

    The exposed headers.

  • maxAge?: number

    The max age of the request.

  • preflight?: boolean

    Allow preflight requests.

View source ↗

Router settings for Base applications.

Members

  • cors?: RouterCorsSettings

    Cors settings for the router.

  • disableAccessLog?: boolean | string[]

    A map of routes that should not be logged or true to disable for all routes.

  • rewrite?: Record<string, string>

    A map of paths to rewrite to other paths.

View source ↗

RoutingInfo

interface

Members

  • origin?: string

  • originType: "public" | "internal"

View source ↗