Reference

Public API

Exact signatures come from generated declarations; this page identifies the public entrypoints and the job each exported symbol is meant to do.

Export Map

The package exposes three entrypoints.

Entrypoint Purpose
alien-middleware Core middleware chain, Web request context, fetch adapter, runtime filter, and shared types.
alien-middleware/srvx srvx-specific context creation and fetch adapter helpers.
alien-middleware/router Path and method router that can be composed as middleware.

To inspect the complete declaration surface from the package export map, run:

exports-md package.json --follow

The --follow flag includes helper declarations that appear inside exported types, which is useful for checking that declaration output has useful TSDoc.

Core Entrypoint

Import these symbols from alien-middleware.

Symbol Kind Use
chain function Create an empty chain or normalize an existing middleware or chain.
MiddlewareChain class Immutable middleware chain with .use(), .isolate(), .toHandler(), and middlewareCount.
createContext function Build a RequestContext from a Web Request and optional host metadata.
toFetchHandler function Adapt a RequestHandler into a plain fetch-compatible handler.
filterRuntime function Continue a branch only when context.host.runtime?.name matches.
RequestContext type Context received by middleware.
WebRequestContext interface Base context shape before plugin properties are intersected in.
Middleware type Request middleware function contract.
RequestPlugin type Object returned by middleware to extend context, env, runtime type, or response callbacks.
RequestMiddleware type Middleware function bound to a particular chain input context.
RequestHandler type Callable handler produced by a middleware chain.
RequestHost type Host metadata and lifecycle hooks used by contexts and fetch adapters.
RequestHostFactory type Per-request function that returns host metadata.
FetchHandler type Fetch-compatible request-to-response function.
CreateContextOptions interface Options accepted by createContext.
ToFetchHandlerOptions interface Options accepted by root and srvx toFetchHandler adapters.
EnvAccessor type Callable environment accessor used by context.env.
ResponseCallback type Callback that observes or replaces the generated response.
MiddlewareTypes type Type metadata carried by chains and handlers.
MiddlewareContext type Extract the context type produced by a chain or middleware list.
ApplyMiddleware type Compute chain metadata after appending one middleware.
ApplyMiddlewares type Compute chain metadata after applying a tuple of middleware.
ExtractMiddleware type Extract a middleware function type from a middleware or chain.
AnyMiddleware type Union of middleware functions and middleware chains.
AnyMiddlewareChain type Minimal metadata shape shared by middleware chains.
EmptyMiddlewareChain type Chain type used when no middleware has been added.

srvx Entrypoint

Import these symbols from alien-middleware/srvx.

Symbol Kind Use
toFetchHandler function Adapt a chain to srvx serve({ fetch }) and copy srvx request metadata into context.host.
createContextFromServerRequest function Build a RequestContext directly from a srvx ServerRequest.
SrvxRuntime type Runtime metadata type exposed by srvx requests.
SrvxRequestContext type RequestContext specialized with srvx runtime metadata.

Use this entrypoint instead of the root adapter when the handler receives srvx ServerRequest objects.

Router Entrypoint

Import these symbols from alien-middleware/router.

Symbol Kind Use
routes function Create a router that can be added to a middleware chain.
Router type Callable router with overloaded .use() route registration.
RouteContext type Context passed to route handlers, including typed params and method.
RouteHandler type Function contract for route handlers.
RouterContext type Extract the context type accepted by a router.

Router path params are inferred through pathic. Method filters accept one method, a readonly list of methods, or '*'.

Documentation Boundary

Keep stable behavior in TSDoc near the symbol it describes. Use guides for composition patterns and examples, not for duplicating every overload. When declaration output shows an unexpected symbol, treat that as a package boundary question before documenting it as intentional API.

The API table is the star chart; the alien monolith still insists you read the declaration files.