Decorators
@system-inc/base-foundation · 515c140 · 11 symbols
@HttpBody
Injects the request body into a route handler parameter.
Without arguments, the body is provided as a ReadableStream. This is
useful for file uploads and streaming use cases.
With a TypeFunc, the body is parsed as JSON and deserialized to the given type.
With an HttpBodyOptions mode, the body is provided in the
specified format (stream, formData, text, arrayBuffer, or blob).
@HttpCookie
Injects a cookie value into a route handler parameter.
With a name, injects that single cookie's value — as a string, or converted when a TypeFunc is also given. With only a TypeFunc, all cookies are serialized into the given type.
nameOrTypeThe name of the cookie, or the type to serialize all cookies into.
typeThe type to convert the named cookie to.
@HttpHeader
Injects a request header into a route handler parameter.
With a name, injects that single header's value. With a TypeFunc, all request headers are serialized into the given type.
nameOrTypeThe name of the header, or the type to serialize all headers into.
typeThe type to convert the named header to.
@HttpPath
Injects a path parameter into a route handler parameter.
With a name, injects that single :name segment of the route path — as a
string, or converted when a TypeFunc is also given. With only a
TypeFunc, all path parameters are serialized into the given type.
Values are URL-decoded by default (HttpPathOptions).
nameOrTypeThe name of the path parameter, or the type to serialize all path parameters into.
typeOrOptionsThe type to convert the named parameter to, or options for the parameter.
optionsOptions for the parameter (only used when the second argument is a type).
@HttpQuery
Injects a query-string parameter into a route handler parameter.
With a name, injects that single query parameter — as a string, or converted when a TypeFunc is also given. With only a TypeFunc, all query parameters are serialized into the given type. Values are URL-decoded by default (HttpQueryOptions).
nameOrTypeThe name of the query parameter, or the type to serialize all query parameters into.
typeOrOptionsThe type to convert the named parameter to, or options for the parameter.
optionsOptions for the parameter (only used when the second argument is a type).
@HttpRoute
Registers a method of an @HttpService class as the handler for an HTTP
route. Path parameters are declared as :name segments and read with
@HttpPath.
methodThe HTTP method for the route, a list of methods to match, or `'ALL'` to match every method.
routeThe path for the route, e.g. `/accounts/:id`.
@HttpService
Marks a class as an HTTP service — the entry point for the @HttpRoute
handlers defined within it.
List the class in a module's (or the worker's) services; its routes are
bound at boot, and a fresh instance is resolved from the request-scoped
container for each incoming request.
@InjectRequestContext
Parameter decorator that injects the RequestContext or a specific value from it into a method parameter.
Works universally across HTTP routes, RPC handlers, and GraphQL resolvers.
Without a key it injects the entire RequestContext; with a
RequestContextKey it extracts that specific extension value from the
context's typed bag.
@resolveRequestContextParams
Resolves all @InjectRequestContext() decorated parameters for a method.
Call this from dispatch sites (Router, RpcDispatcher, GqlDispatcher/TypeGraphQL)
to populate the args array with RequestContext data.
prototypeThe prototype of the service instance
methodNameThe name of the method being called
requestContextThe RequestContext for the current request
argsThe arguments array to populate
@WithMiddleware
Decorator to add handler-scoped middleware to a class or method.
Accepts either a middleware function or a middleware class constructor, or an array of them. Classes are resolved from the DI container.
The middleware runs after the dispatcher has resolved rc.handler, so
implementations receive a HandlerRequestContext in which
rc.handler is guaranteed to be set.
@withRequestContext
Builds a method decorator that runs a guard against the current RequestContext before invoking the decorated method.
Internally this registers an @InjectRequestContext() at a trailing slot
just past the method's declared arity. The dispatcher fills that slot
with the RC, the wrapper reads it, trims it off the args, runs the guard,
and then forwards the original args to the underlying method.
Multiple decorators using this helper can be stacked on the same method — each one gets its own trailing slot (the metadata is an array) and the RC is written into every slot.
Use this when a decorator only needs to pre-inspect the RC. For post-invocation work or argument transformation, write a bespoke decorator.