Docs/Middlewarev1.0.0-rc.1

Middleware composition and decorators

In the RC, MiddlewarePipeline and functional composition helpers are public. The repository's middleware decorator implementation is not exported from the npm entry points. Do not import Handle, Next, When, Pipeline, UseMiddleware, CatchErrors, Measure or createMiddlewareFromClass from the package.

The root symbol Middleware is a type, not a decorator. Context is a reactive value class, not the internal middleware parameter decorator.

Public alternative

import assert from 'node:assert/strict';
import { MiddlewarePipeline, type BaseContext } from '@tagna/udiot';

const pipeline = new MiddlewarePipeline<BaseContext>();
pipeline.use({
  name: 'answer',
  priority: 10,
  handler: async (context, next) => {
    context.result = 42;
    await next();
  },
});
const result = await pipeline.execute({
  metadata: new Map(),
  timestamp: Date.now(),
});
assert.equal(result.result, 42);

Use composition helpers for conditions, timing, parallel work and error handling. Use built-in middleware for supported auth, caching and validation integrations.

Controller and DI decorators are a different public surface: Injectable, Controller, HTTP method decorators, RequireAuth and UseRateLimit are available. See decorator reference.

From the canonical UDIOT public documentation.Try it in the playground ↗