/tsed:tsed-middlewaresfrom Ts.ED
Adds cross-cutting request logic to Ts.ED v8 apps with middlewares, auth guards, interceptors, and pipes. Covers @Middleware classes, global middleware registration, decorators like @UseBefore/@UseAuth, @Interceptor/@Intercept, @UsePipe, and @UseCache.
Ships in Ts.ED. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them.
Pick the narrowest tool first, then implement it as an injectable class.
| Need | Use | Package |
|---|---|---|
| Run before/after a route with access to request, response and endpoint metadata (auth, headers, tenant) | Middleware | @tsed/platform-middlewares |
| Wrap any injectable method: timing, retry, fallback, caching, transactions | Interceptor | @tsed/di |
| Transform or validate one handler parameter (id to entity, parsing) | Pipe | @tsed/platform-params, @tsed/schema |
React to application or request lifecycle ($onRequest, $onResponse, $onReady) | Hook | see tsed-di, https://tsed.dev/docs/hooks.md |
| Change the shape of every response or error | Response filter / exception filter | see tsed-exceptions |
Never import from @tsed/common.
import {Unauthorized} from "@tsed/exceptions";
import {Middleware, type MiddlewareMethods} from "@tsed/platform-middlewares";
import {Context} from "@tsed/platform-params";
@Middleware()
export class ApiKeyMiddleware implements MiddlewareMethods {
use(@Context() $ctx: Context) {
const options = $ctx.endpoint.get(ApiKeyMiddleware) || {};
if ($ctx.request.get("x-api-key") !== options.key) {
throw new Unauthorized("Invalid API key");
}
}
}
use(...). Inject what is needed with parameter decorators (@Context(), @HeaderParams(), @QueryParams()); inject services with @Inject() or inject().next(); throw an exception from @tsed/exceptions to stop the request.$ctx.endpoint.get(MiddlewareClass). This is only available for endpoint-level middlewares, not global ones.$ctx.request / $ctx.response (platform abstractions) so the code stays portable across Express, Koa and Fastify.@UseBefore(M): before the handler. @Use(M): just before the handler, after @UseBefore. @UseAfter(M): after the handler when it returned no data.@UseBefore runs once for the controller; @UseBeforeEach(M) runs before each of its endpoints.@tsed/platform-middlewares.@UseBefore, controller @UseBeforeEach, endpoint @UseBefore, controller @Use, endpoint @Use, handler, endpoint @UseAfter, send response. Once a handler returns data the response is sent and later @UseAfter and global middlewares are skipped.@UseAfter for post-processing.@Err(), four-argument functions); use exception filters (tsed-exceptions).import {Env} from "@tsed/core";
import {Configuration} from "@tsed/di";
import compression from "compression";
import helmet from "helmet";
import {RequestIdMiddleware} from "./middlewares/RequestIdMiddleware.js";
@Configuration({
middlewares: [
{use: helmet(), hook: "$afterInit"},
"json-parser",
{use: "urlencoded-parser", options: {extended: true}},
{use: compression(), env: Env.PROD},
RequestIdMiddleware
]
})
export class Server {}
{use, hook?, env?, options?}. Default hook: $beforeRoutesInit.json-parser, urlencoded-parser, text-parser, raw-parser. Any other string is imported as a module and called with options.$beforeRoutesInit or later. On $beforeInit, $onInit or $afterInit only raw framework middlewares are accepted and a class throws at startup.PlatformApplication from @tsed/platform-http in the server and call this.app.use(M) inside $beforeRoutesInit() or $afterRoutesInit(). Hook registrations run before the middlewares list.import {useDecorators} from "@tsed/core";
import {UseAuth} from "@tsed/platform-middlewares";
import {In, Returns, Security} from "@tsed/schema";
import {AuthMiddleware} from "../middlewares/AuthMiddleware.js";
export function Auth(options: {role?: string; scopes?: string[]} = {}): Function {
return useDecorators(
UseAuth(AuthMiddleware, options),
Security("oauth", ...(options.scopes || [])),
In("header").Name("Authorization").Type(String).Required(true),
Returns(401),
Returns(403)
);
}
UseAuth(Guard, options) adds the guard as @UseBefore once and merges options into the endpoint store. Read them with $ctx.endpoint.get(AuthMiddleware).Unauthorized for missing or invalid credentials and Forbidden for insufficient rights.Security name must match a security scheme declared in the OpenAPI configuration (tsed-openapi). Passport and OIDC: https://tsed.dev/docs/authentication.md.import {Interceptor, type InterceptorContext, type InterceptorMethods, type InterceptorNext} from "@tsed/di";
@Interceptor()
export class TimingInterceptor implements InterceptorMethods {
async intercept(context: InterceptorContext, next: InterceptorNext) {
const start = Date.now();
const result = await next();
console.log(String(context.propertyKey), Date.now() - start, context.options);
return result;
}
}
@Intercept(TimingInterceptor, options) from @tsed/di on a method, or on a class to wrap all its methods. Works on services and controllers.context exposes target, propertyKey, args, options. Always return the result of next(), or a fallback value.@UseInterceptor decorator (a doc snippet mentions it by mistake).@UseCache() from @tsed/platform-cache is a ready-made interceptor (GET endpoints and service methods). Setup: https://tsed.dev/docs/cache.md.import {Injectable} from "@tsed/di";
import {NotFound} from "@tsed/exceptions";
import type {JsonParameterStore, PipeMethods} from "@tsed/schema";
@Injectable()
export class UserPipe implements PipeMethods<string, Promise<User>> {
async transform(id: string, metadata: JsonParameterStore) {
const user = await findUser(id);
if (!user) throw new NotFound("User not found");
return user;
}
}
@RawPathParams("id") @UsePipe(UserPipe) user: User (both from @tsed/platform-params). Use the Raw* decorator when the pipe returns an object, otherwise the built-in deserializer and validator also run on the raw value.useDecorators(RawPathParams(expression), UsePipe(UserPipe, options)); read options with metadata.store.get(UserPipe). When a pipe throws, the handler is not called and the error goes to the exception filters.hook: "$afterInit": startup error. Remove the hook or use $beforeRoutesInit.$ctx.endpoint is undefined in a global middleware: the route is not resolved yet. Move the logic to @UseBefore.next() and also returning or throwing: double response. Do not inject @Next() in Ts.ED middlewares.json-parser / urlencoded-parser).Raw* parameter decorator.@Middleware(), implements use, throws typed exceptions.$beforeRoutesInit or later.Security, 401 and 403.@tsed/common import; relative imports end with .js.Depth: https://tsed.dev/docs/middlewares.md, https://tsed.dev/docs/interceptors.md, https://tsed.dev/docs/pipes.md, https://tsed.dev/docs/authentication.md, https://tsed.dev/docs/request-context.md.
What SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
13 skills in this plugin
/tsed-cliScaffolds Ts.ED v8 projects and generates files with the Ts.ED CLI v7, through its MCP server (tools set-workspace, init-project, list-templates, get-template, generate-file) or the tsed binary (tsed init, generate, template, add, run, update, dev, build). Use when creating a Ts.ED project, adding a controller, service, middleware, model, interceptor, pipe, decorator or custom template, when package.json has a "tsed" key or @tsed/cli, when a .templates/ directory exists, or on errors E_CWD_NOT_SET, E_PROJECT_NOT_INITIALIZED, E_TEMPLATE_UNKNOWN, E_ARGS_INVALID./tsed-configurationConfigure and bootstrap a Ts.ED v8 server - the @Configuration decorator or configuration() on the Server class, PlatformExpress/PlatformKoa/PlatformFastify.bootstrap, server options (mount, middlewares, httpPort, httpsPort, acceptMimes, logger, statics, views, responseFilters, imports), per-platform express/koa/fastify options, and @tsed/config sources (envs, dotenv, json, yaml). Use when editing Server.ts, index.ts or src/config, adding @tsed/config or the extends option, or reading settings with constant(), refValue(), @Constant, @Value or configuration().get()./tsed-controllersWrite Ts.ED v8 HTTP controllers and routes - @Controller paths and nested children, mounting through the `mount` configuration, verb decorators from @tsed/schema, parameter decorators from @tsed/platform-params, typed inputs, response decorators and custom endpoint decorators. Use when adding or fixing a REST endpoint, when a route returns 404 or is shadowed by another route, when @BodyParams/@QueryParams/@PathParams receive a plain object or the wrong type, or when working with @Returns, @Status, @Redirect, @View, @Hidden, @Req/@Res or useDecorators.npx claudepluginhub tsedio/tsed --plugin tsedOther plugins' skills for the same job