Setu-TS
    Preparing search index...

    Interface IRequestContext

    Per-request context passed to middleware and route handlers. Each request gets a fresh context; request-scoped data lives here, never in globals.

    0.1.0

    interface IRequestContext {
        id: string;
        params: Readonly<Record<string, string>>;
        query: Readonly<Record<string, string>>;
        raw?: Request;
        request: IRequest;
        response: IResponse;
        services: IServiceRegistry;
        signal: AbortSignal;
        startTime: number;
        state: Map<string, unknown>;
        defer?(cleanup: () => void | Promise<void>): void;
        slot?<T>(key: object, create: () => T): T;
    }
    Index
    id: string

    Unique request ID (generated or propagated by middleware).

    params: Readonly<Record<string, string>>

    Path parameters extracted by the router (e.g. :id).

    query: Readonly<Record<string, string>>

    Query string parameters.

    raw?: Request

    The undisturbed web-standard Request, preserved for WebSocket upgrade and gRPC dispatch after the middleware pipeline.

    Threaded from IRequest.raw by the kernel's request-context factory. Absent when the adapter did not provide one (injected or test requests).

    0.3.0

    request: IRequest

    The incoming request.

    response: IResponse

    The response builder.

    Service resolution (application-scoped plus request-scoped services).

    signal: AbortSignal

    An abort signal that fires when the underlying HTTP connection is severed (client disconnect, timeout). Populated by the kernel's request-context factory from the native Request.signal; falls back to a non-aborting sentinel so handlers always have a live signal to listen on.

    Used by streaming producers (SSE heartbeats, channel cleanup) to stop work on client disconnect and avoid leaking producers.

    0.2.0

    startTime: number

    High-resolution timestamp captured when the context was created.

    state: Map<string, unknown>

    Request-scoped state for passing data between middleware and handlers.

    • Registers cleanup in reverse registration order. Buffered responses wait for cleanup; streaming responses clean up on end, error, or cancellation. Calls after completion run immediately. Failures are reported at warn. Each asynchronous cleanup is bounded at 5000 ms; expiry warns once and continues with the next cleanup. Later settlement is ignored. Synchronous cleanups stay synchronous and are not timed.

      Parameters

      • cleanup: () => void | Promise<void>

        Work to run at completion

      Returns void

      Nothing

      0.11.0

    • Returns this request's value for an owner key, creating it on first use. Keys compare by object identity. Entries cannot be enumerated or deleted and live only as long as this context; calls after completion work alike. A throwing factory stores nothing, so a later call can retry. create must not call slot with its own key.

      Type Parameters

      • T

        The stored value type

      Parameters

      • key: object

        A private object identifying the owner of the value

      • create: () => T

        Factory called only when this key has no stored value

      Returns T

      The cached or newly created value, including undefined

      If the factory throws; its error propagates unchanged

      const value = ctx.slot?.(ownerKey, () => createRequestResource());
      

      0.11.0