Reference

rouzer

export * from 'alien-middleware';

Functions

$error

Create a compile-time-only marker for a declared error response type.

export function $error<T>(): UncheckedError<T>;
export namespace $error {
    var symbol: symbol;
}

Remarks

$error<T>() marks a non-success response branch in a status-keyed response map. It is a type contract, not a runtime validator. On the server, handlers use ctx.error(status, body) to return declared errors. On the client, declared error responses resolve as [error, null, status] tuple entries instead of rejecting the promise.

Examples

import { $type, $error } from 'rouzer'
import * as http from 'rouzer/http'
const getUser = http.get('users/:id', {
 response: {
   200: $type<User>(),
   404: $error<{ code: string; message: string }>(),
 },
})

šŸ” $error on GitHub

$type

Create a compile-time-only marker for an action's JSON response payload type.

export function $type<T>(): Unchecked<T>;
export namespace $type {
    var symbol: symbol;
}

Remarks

$type<T>() does not validate handler return values at the server boundary. It lets Rouzer type server handler return values and client action functions for HTTP actions whose responses are expected to be JSON. Use it directly as response for one JSON success shape, or as a success entry in a status-keyed response map. Validate response data where it enters your server or client code when runtime integrity is required.

Examples

import { $type } from 'rouzer'
import * as http from 'rouzer/http'
const hello = http.get('hello/:name', {
 response: $type<{ message: string }>(),
})

šŸ” $type on GitHub

createClient

Create a typed fetch client for an HTTP route tree.

export function createClient<TRoutes extends HttpRouteTree = Record<string, never>>(config: {
    baseURL: string;
    headers?: Record<string, string>;
    routes: TRoutes;
    plugins?: readonly ClientResponsePlugin[];
    onJsonError?: (response: Response) => Promisable<unknown>;
    fetch?: typeof globalThis.fetch;
    clientHook?: RouzerClientHook;
}): ClientTree<TRoutes, ""> & {
    clientConfig: {
        baseURL: string;
        headers?: Record<string, string>;
        routes: TRoutes;
        plugins?: readonly ClientResponsePlugin[];
        onJsonError?: (response: Response) => Promisable<unknown>;
        fetch?: typeof globalThis.fetch;
        clientHook?: RouzerClientHook;
    };
};

Remarks

The returned client mirrors the resource tree and attaches direct action functions such as client.users.list(...).

Properties

  • baseURL Absolute base URL used for generated request URLs.

    Remarks

    A trailing slash is added when missing. In browsers, derive a relative API path with new URL('/api/', window.location.origin).href.

  • headers Default headers sent with every request.

    Remarks

    Per-request headers are merged on top of these values. Undefined per-request headers are removed before fetch.

  • routes HTTP route tree to attach as direct client action functions.

    Examples

    const client = createClient({ baseURL: 'https://example.com/api/', routes })
    await client.users.list({ page: 1 })
  • plugins Response codec plugins used by generated action functions.

  • onJsonError Custom handler for non-2xx responses from generated client action functions.

    Remarks

    When provided, the return value is returned from the client action as-is; Rouzer does not automatically parse a Response returned by this hook.

  • fetch Custom fetch implementation to use for requests.

  • clientHook Best-effort lifecycle observer for generated client action calls.

    Remarks

    Hook errors are swallowed and never change request behavior.

  • baseURL Absolute base URL used for generated request URLs.

    Remarks

    A trailing slash is added when missing. In browsers, derive a relative API path with new URL('/api/', window.location.origin).href.

  • headers Default headers sent with every request.

    Remarks

    Per-request headers are merged on top of these values. Undefined per-request headers are removed before fetch.

  • routes HTTP route tree to attach as direct client action functions.

    Examples

    const client = createClient({ baseURL: 'https://example.com/api/', routes })
    await client.users.list({ page: 1 })
  • plugins Response codec plugins used by generated action functions.

  • onJsonError Custom handler for non-2xx responses from generated client action functions.

    Remarks

    When provided, the return value is returned from the client action as-is; Rouzer does not automatically parse a Response returned by this hook.

  • fetch Custom fetch implementation to use for requests.

  • clientHook Best-effort lifecycle observer for generated client action calls.

    Remarks

    Hook errors are swallowed and never change request behavior.

šŸ” createClient on GitHub

createResponsePluginMap

Create a plugin lookup map and reject duplicate plugin ids.

export function createResponsePluginMap<TPlugin extends {
    readonly id: string;
}>(plugins?: readonly TPlugin[], label?: string): Map<string, TPlugin>;

šŸ” createResponsePluginMap on GitHub

createResponsePluginMarker

Create a response marker for a response plugin.

export function createResponsePluginMarker<TClient, TRouter = TClient, const TId extends string = string>(id: TId): ResponsePluginMarker<TClient, TRouter, TId>;

šŸ” createResponsePluginMarker on GitHub

createRouter

Create a Rouzer router that can be mounted as a fetch-compatible handler.

export function createRouter<TEnv extends object = {}, TProperties extends object = {}, TRuntime = unknown>(config?: RouterConfig): Router<MiddlewareTypes<TEnv, TProperties, TRuntime>>;

Parameters

  • config: Optional router configuration for base path, debug behavior, response plugins, and CORS origin restrictions.

Returns

A fetch-compatible handler with .use(...) methods for middleware and route registration.

šŸ” createRouter on GitHub

getResponsePluginMarkerId

Get the response plugin id from a plugin marker, if present.

export function getResponsePluginMarkerId(value: unknown): string | undefined;

šŸ” getResponsePluginMarkerId on GitHub

isResponsePluginMarker

Return true when a route response marker is handled by a response plugin.

export function isResponsePluginMarker(value: unknown): value is ResponsePluginMarker<unknown, unknown>;

šŸ” isResponsePluginMarker on GitHub

metadata

Attach runtime metadata to a route declaration.

export function metadata(value: RouteMetadata): object;

šŸ” metadata on GitHub

Types

BodyInput

type BodyInput<T> = T extends MutationRouteSchema ? T extends {
    body: infer TBody;
} ? TBody extends RawBodySchema ? unknown : z.infer<TBody> : unknown : unknown;

šŸ” BodyInput on GitHub

ClientResponsePlugin

Client-side response plugin used by createClient({ plugins }).

export type ClientResponsePlugin = {
    readonly id: string;
    decode(response: Response, context: {
        marker: ResponsePluginMarker<any, any>;
        request: ClientResponsePluginRequest;
    }): Promisable<unknown>;
};

Properties

  • id Stable response codec id matched against route response markers.

  • decode Decode a successful Response into the client action result.

šŸ” ClientResponsePlugin on GitHub

ClientResponsePluginRequest

Request metadata passed to client response plugins.

export type ClientResponsePluginRequest = {
    schema: RouteSchema;
    path: RoutePattern;
    method: string;
    input?: unknown;
    options?: RouteOptions;
};

šŸ” ClientResponsePluginRequest on GitHub

ClientTree

Client object shape produced from an HTTP route tree.

export type ClientTree<T extends HttpRouteTree, TPrefix extends string = ''> = {
    [K in keyof T]: T[K] extends HttpResource<infer P, infer C> ? ClientTree<C, Join<TPrefix, P>> : T[K] extends HttpAction<infer P, infer S, any> ? RouteFunction<S, Join<TPrefix, P>> : never;
};

šŸ” ClientTree on GitHub

HeaderInput

type HeaderInput<T> = T extends {
    headers: infer THeaders;
} ? Partial<z.infer<THeaders>> : Record<string, string | undefined>;

šŸ” HeaderInput on GitHub

InferActionHandler

export type InferActionHandler<TMiddleware extends AnyMiddlewareChain, TAction extends HttpAction, TPath extends string> = TAction['schema'] extends {
    response: infer R extends RouteResponseMap;
} ? TAction['method'] extends 'GET' ? RouteRequestHandler<TMiddleware, {
    path: TAction['schema'] extends {
        path: any;
    } ? z.infer<TAction['schema']['path']> : MatchParams<TPath>;
    query: TAction['schema'] extends {
        query: any;
    } ? z.infer<TAction['schema']['query']> : undefined;
    headers: TAction['schema'] extends {
        headers: any;
    } ? z.infer<TAction['schema']['headers']> : undefined;
}, InferRouteHandlerResult<Extract<TAction['schema'], RouteSchema>>, InferResponseMapErrors<R>, InferResponseMapSuccesses<R>> : RouteRequestHandler<TMiddleware, {
    path: TAction['schema'] extends {
        path: any;
    } ? z.infer<TAction['schema']['path']> : MatchParams<TPath>;
    body: InferHandlerBody<TAction['schema']>;
    headers: TAction['schema'] extends {
        headers: any;
    } ? z.infer<TAction['schema']['headers']> : undefined;
}, InferRouteHandlerResult<Extract<TAction['schema'], RouteSchema>>, InferResponseMapErrors<R>, InferResponseMapSuccesses<R>> : TAction['method'] extends 'GET' ? RouteRequestHandler<TMiddleware, {
    path: TAction['schema'] extends {
        path: any;
    } ? z.infer<TAction['schema']['path']> : MatchParams<TPath>;
    query: TAction['schema'] extends {
        query: any;
    } ? z.infer<TAction['schema']['query']> : undefined;
    headers: TAction['schema'] extends {
        headers: any;
    } ? z.infer<TAction['schema']['headers']> : undefined;
}, InferRouteHandlerResult<Extract<TAction['schema'], RouteSchema>>> : RouteRequestHandler<TMiddleware, {
    path: TAction['schema'] extends {
        path: any;
    } ? z.infer<TAction['schema']['path']> : MatchParams<TPath>;
    body: InferHandlerBody<TAction['schema']>;
    headers: TAction['schema'] extends {
        headers: any;
    } ? z.infer<TAction['schema']['headers']> : undefined;
}, InferRouteHandlerResult<Extract<TAction['schema'], RouteSchema>>>;

šŸ” InferActionHandler on GitHub

InferHandlerBody

type InferHandlerBody<T> = T extends {
    body: infer TBody;
} ? TBody extends RawBodySchema ? undefined : z.infer<TBody> : undefined;

šŸ” InferHandlerBody on GitHub

InferResponseMapClient

Helper: given a status-keyed response map, produce the discriminated tuple union for the client.

Each entry becomes:

  • $type<T>() → [null, T, Status]
  • $error<T>() → [T, null, Status]
type InferResponseMapClient<T extends RouteResponseMap> = {
    [K in keyof T & number]: T[K] extends UncheckedError<infer TError> ? [TError, null, K] : T[K] extends Unchecked<infer TSuccess> ? [null, TSuccess, K] : T[K] extends ResponsePluginMarker<infer TClient, any> ? [null, TClient, K] : never;
}[keyof T & number];

šŸ” InferResponseMapClient on GitHub

InferResponseMapErrors

Helper: given a status-keyed response map, extract error entries as a union of [status, body] pairs for typing ctx.error(status, body).

export type InferResponseMapErrors<T extends RouteResponseMap> = {
    [K in keyof T & number]: T[K] extends UncheckedError<infer TError> ? [K, TError] : never;
}[keyof T & number];

šŸ” InferResponseMapErrors on GitHub

InferResponseMapHandlerResult

Helper: given a status-keyed response map, produce the union of handler result types (success values the handler can return directly).

type InferResponseMapHandlerResult<T extends RouteResponseMap> = {
    [K in keyof T & number]: T[K] extends Unchecked<infer TSuccess> ? TSuccess : T[K] extends ResponsePluginMarker<any, infer TRouter> ? TRouter : never;
}[keyof T & number];

šŸ” InferResponseMapHandlerResult on GitHub

InferResponseMapSuccesses

Extract success entries as a union of [status, body] pairs.

export type InferResponseMapSuccesses<T extends RouteResponseMap> = {
    [K in keyof T & number]: T[K] extends Unchecked<infer TSuccess> ? [K, TSuccess] : T[K] extends ResponsePluginMarker<any, infer TRouter> ? [K, TRouter] : never;
}[keyof T & number];

šŸ” InferResponseMapSuccesses on GitHub

InferRouteBody

Infer the request body type from an action schema.

export type InferRouteBody<T> = T extends RouteSchema ? InferRouteSchemaBody<T> : never;

Remarks

HTTP action schemas can be inspected with InferRouteBody<typeof action.schema>. Schemas without a body schema infer unknown.

šŸ” InferRouteBody on GitHub

InferRouteHandlerResult

Infer the non-Response handler result type from an action schema.

export type InferRouteHandlerResult<T extends RouteSchema> = T extends {
    response: infer R;
} ? R extends ResponsePluginMarker<any, infer TRouter> ? TRouter : R extends Unchecked<infer TResponse> ? TResponse : R extends RouteResponseMap ? InferResponseMapHandlerResult<R> : void : void;

Remarks

For status-keyed response maps, this includes only success result values. Declared error responses are returned with ctx.error(status, body).

šŸ” InferRouteHandlerResult on GitHub

InferRouteResponse

Infer the generated client action result type from an action schema.

export type InferRouteResponse<T extends RouteSchema> = T extends {
    response: infer R;
} ? R extends ResponsePluginMarker<infer TClient, any> ? TClient : R extends Unchecked<infer TResponse> ? TResponse : R extends RouteResponseMap ? InferResponseMapClient<R> : void : void;

Remarks

Direct JSON markers infer their payload type, plugin markers infer their client result type, and status-keyed response maps infer a tuple union of [null, value, status] success entries and [error, null, status] error entries.

šŸ” InferRouteResponse on GitHub

InferRouteSchemaBody

type InferRouteSchemaBody<TSchema> = TSchema extends MutationRouteSchema ? TSchema extends {
    body: infer TBody;
} ? z.infer<TBody> : unknown : never;

šŸ” InferRouteSchemaBody on GitHub

Join

type Join<A extends string, B extends string> = A extends '' ? B : B extends '' ? A : `${A}/${B}`;

šŸ” Join on GitHub

MutationRouteSchema

Schema shape for mutation route methods.

export type MutationRouteSchema = {
    path?: z.ZodObject<any>;
    query?: never;
    body?: z.ZodObject<any> | RawBodySchema;
    headers?: z.ZodObject<any>;
    response?: RouteResponseSchema;
};

Properties

  • path Optional Zod object used to validate path params.

  • query Mutation routes do not accept query schemas.

  • body Optional Zod schema used to validate the JSON request body, or raw body marker.

  • headers Optional Zod object used to validate request headers.

  • response Optional compile-time-only JSON or plugin response type marker.

šŸ” MutationRouteSchema on GitHub

PathInput

type PathInput<T, P extends string> = T extends {
    path: infer TPath;
} ? z.infer<TPath> : MatchParams<P>;

šŸ” PathInput on GitHub

QueryInput

type QueryInput<T> = T extends QueryRouteSchema & {
    query: infer TQuery;
} ? z.infer<TQuery> : unknown;

šŸ” QueryInput on GitHub

QueryRouteSchema

Schema shape for GET route methods.

export type QueryRouteSchema = {
    path?: z.ZodObject<any>;
    query?: z.ZodObject<any>;
    body?: never;
    headers?: z.ZodObject<any>;
    response?: RouteResponseSchema;
};

Properties

  • path Optional Zod object used to validate path params.

  • query Optional Zod object used to validate URL query params.

  • body GET routes do not accept request bodies.

  • headers Optional Zod object used to validate request headers.

  • response Optional compile-time-only JSON or plugin response type marker.

šŸ” QueryRouteSchema on GitHub

RawBodySchema

Marker for request bodies passed through to fetch without JSON encoding.

export type RawBodySchema = {
    readonly __rawBody__: unique symbol;
};

šŸ” RawBodySchema on GitHub

RequestContext

type RequestContext<TMiddleware extends AnyMiddlewareChain> = MiddlewareContext<TMiddleware>;

šŸ” RequestContext on GitHub

ResponsePluginMarker

Compile-time response marker handled by a client/router response plugin pair.

export type ResponsePluginMarker<TClient, TRouter = TClient, TId extends string = string> = Record<number, unknown> & {
    readonly [responsePluginMarker]: {
        readonly id: TId;
        readonly client: TClient;
        readonly router: TRouter;
    };
};

Remarks

TClient is the value returned by generated client action functions. TRouter is the non-Response value accepted from route handlers. Plugin markers may be used directly as an action response or as success entries in a status-keyed response map.

šŸ” ResponsePluginMarker on GitHub

ResponsePluginMarker

Compile-time response marker handled by a client/router response plugin pair.

export type ResponsePluginMarker<TClient, TRouter = TClient, TId extends string = string> = Record<number, unknown> & {
    readonly [responsePluginMarker]: {
        readonly id: TId;
        readonly client: TClient;
        readonly router: TRouter;
    };
};

Remarks

TClient is the value returned by generated client action functions. TRouter is the non-Response value accepted from route handlers. Plugin markers may be used directly as an action response or as success entries in a status-keyed response map.

šŸ” ResponsePluginMarker on GitHub

RouteBodyOption

type RouteBodyOption<T> = T extends {
    body: RawBodySchema;
} ? {
    body: BodyInit | null;
} : {};

šŸ” RouteBodyOption on GitHub

RouteErrorResponse

Error response returned by ctx.error(status, body) in route handlers.

export type RouteErrorResponse = Response & {
    __routeError__: true;
};

Remarks

This is an opaque branded type returned by the error helper. Route handlers may return it to signal a declared error response.

šŸ” RouteErrorResponse on GitHub

RouteFetchOptions

Fetch options accepted by a generated client action.

export type RouteFetchOptions<T extends RouteSchema = any> = Omit<RequestInit, 'method' | 'body' | 'headers'> & {
    headers?: HeaderInput<T>;
};

Remarks

headers remains optional because required route headers may be supplied by createClient({ headers }) defaults. Raw-body routes with path or query input accept body here; raw-body routes without input accept the body as the first client action argument and these options as the second.

Properties

  • headers Headers for this request. Undefined values are removed before fetch.

šŸ” RouteFetchOptions on GitHub

RouteFunction

Client action function attached for each HTTP action leaf.

export type RouteFunction<T extends RouteSchema, P extends string> = T extends {
    body: RawBodySchema;
} ? RouteInput<T, P> extends infer TInput ? {} extends TInput ? (body: BodyInit | null, options?: RouteFetchOptions<T>) => Promise<T extends {
    response: any;
} ? InferRouteResponse<T> : Response> : (input: TInput, options: RouteOptions<T>) => Promise<T extends {
    response: any;
} ? InferRouteResponse<T> : Response> : never : (...p: RouteInput<T, P> extends infer TInput ? {} extends TInput ? [input?: TInput, options?: RouteOptions<T>] : [input: TInput, options?: RouteOptions<T>] : never) => Promise<T extends {
    response: any;
} ? InferRouteResponse<T> : Response>;

Remarks

Actions whose schema has response: $type<T>() return parsed JSON as T. Actions whose schema has a status-keyed response map return a tuple union of [null, value, status] success entries and [error, null, status] error entries. Actions whose schema has a plugin response marker return the plugin's client result type. Actions without a response marker return the raw Response. Raw-body actions with no path or query input accept (body, options); raw-body actions with route input accept (input, { body, ...options }).

šŸ” RouteFunction on GitHub

RouteInput

Semantic input accepted by a generated client action function.

export type RouteInput<T extends RouteSchema = any, P extends string = string> = [T] extends [Any] ? any : PathInput<T, P> & QueryInput<T> & BodyInput<T>;

Remarks

Path params, query params, and JSON body fields are flattened into a single object. Avoid declaring duplicate keys across path/query/body schemas, since a flat input cannot distinguish their source.

šŸ” RouteInput on GitHub

RouteMetadata

Runtime metadata attached to Rouzer route nodes.

export type RouteMetadata = {
    summary?: string;
    description?: string;
};

Properties

  • summary Short label for generated indexes, clients, CLIs, or docs.

  • description Human-readable route description for generated tooling.

šŸ” RouteMetadata on GitHub

RouteOptions

export type RouteOptions<T extends RouteSchema = any> = RouteFetchOptions<T> & RouteBodyOption<T>;

šŸ” RouteOptions on GitHub

Router

Fetch-compatible Rouzer handler with chainable middleware and route registration.

export interface Router<T extends MiddlewareTypes = any> extends RequestHandler<T>, MiddlewareChain<T> {
    use<const TMiddleware extends ExtractMiddleware<this>>(middleware: TMiddleware | null): Router<ApplyMiddleware<this, TMiddleware>>;
    use<TRoutes extends HttpRouteTree>(routes: TRoutes, handlers: RouteRequestHandlerMap<TRoutes, this>): Router<T>;
}

Properties

  • use Clone this router and add the given middleware to the end of the chain.

    Returns

    a new Router instance.

  • use Clone this router and add the given HTTP route tree and handlers to the chain.

    Remarks

    The handler object mirrors the resource tree. Resource nodes are nested objects, and action nodes are direct handler functions.

    Returns

    a new Router instance.

šŸ” Router on GitHub

RouterConfig

Configuration for createRouter.

export type RouterConfig = {
    basePath?: string;
    debug?: boolean;
    plugins?: readonly RouterResponsePlugin[];
    cors?: {
        allowOrigins?: string[];
    };
};

Properties

  • basePath Base path to prepend to all route patterns.

    Remarks

    Leading and trailing slashes are normalized so api, /api, and api/ all mount routes under /api/.

    Examples

    createRouter({ basePath: 'api/' })
  • debug Enable debug behavior for local development.

    Remarks

    Debug mode adds an X-Route-Name response header for matched routes, includes specific Zod error messages in 400 validation responses, and logs missing route handlers to the console.

  • plugins Response codec plugins used for route handler results.

  • cors CORS configuration for requests with an Origin header.

  • allowOrigins Allowed origins for CORS requests.

    Remarks

    Origins may contain wildcards for protocol and subdomain. The protocol is optional and defaults to https. Requests with an Origin header outside this list receive 403.

    Examples

    allowOrigins: ['example.net', 'https://*.example.com', '*://localhost:3000']

šŸ” RouterConfig on GitHub

RouteRequestHandler

export type RouteRequestHandler<TMiddleware extends AnyMiddlewareChain, TArgs extends object, TResult, TErrors = never, TSuccesses = never> = (context: RequestContext<TMiddleware> & TArgs & ([TErrors] extends [never] ? {} : {
    error: <TEntry extends TErrors>(...args: TEntry extends [infer S extends number, infer B] ? [status: S, body: B] : never) => RouteErrorResponse;
}) & ([TSuccesses] extends [never] ? {} : {
    success: <TEntry extends TSuccesses>(...args: TEntry extends [infer S extends number, infer B] ? [status: S, body: B] : never) => RouteSuccessResponse;
})) => Promisable<TResult | Response>;

Properties

  • error Return a declared error response.

    Remarks

    Only statuses declared with $error<T>() in the response map are accepted.

  • success Return a declared success response with an explicit status.

    Remarks

    Useful when a response map declares multiple 2xx statuses.

šŸ” RouteRequestHandler on GitHub

RouteRequestHandlerMap

Handler map shape required by createRouter().use(routes, handlers).

export type RouteRequestHandlerMap<TRoutes extends HttpRouteTree = HttpRouteTree, TMiddleware extends AnyMiddlewareChain = never, TPrefix extends string = ''> = {
    [K in keyof TRoutes]: TRoutes[K] extends HttpResource<infer P, infer C> ? RouteRequestHandlerMap<C, TMiddleware, Join<TPrefix, P>> : TRoutes[K] extends HttpAction<infer P, any, any> ? InferActionHandler<TMiddleware, TRoutes[K], Join<TPrefix, P>> : never;
};

Remarks

The handler object mirrors the HTTP route tree. Resource nodes become nested handler objects, while action nodes become direct handler functions. Handler context is inferred from middleware plus accumulated path params, query/body schemas, and header schemas.

šŸ” RouteRequestHandlerMap on GitHub

RouteResponse

Response whose .json() method resolves to a known payload type.

export type RouteResponse<TResult = any> = Response & {
    json(): Promise<TResult>;
};

šŸ” RouteResponse on GitHub

RouteResponseMap

Status-keyed response map for declaring multiple response types.

export type RouteResponseMap = {
    [status: number]: RouteResponseMarker;
};

Remarks

Numeric keys are HTTP status codes. Use $type<T>() or a response plugin marker for success responses and $error<T>() for declared error JSON responses.

šŸ” RouteResponseMap on GitHub

RouteResponseMarker

Single response marker accepted by status-keyed response maps.

export type RouteResponseMarker = Unchecked<any> | UncheckedError<any> | ResponsePluginMarker<any, any>;

šŸ” RouteResponseMarker on GitHub

RouteResponseSchema

Response marker accepted by HTTP action schemas.

export type RouteResponseSchema = Unchecked<any> | ResponsePluginMarker<any, any> | RouteResponseMap;

šŸ” RouteResponseSchema on GitHub

RouterResponsePlugin

Router-side response plugin used by createRouter({ plugins }).

export type RouterResponsePlugin = {
    readonly id: string;
    encode(value: unknown, context: {
        marker: ResponsePluginMarker<any, any>;
        request: Request;
    }): Promisable<Response>;
};

Properties

  • id Stable response codec id matched against route response markers.

  • encode Encode a handler result into the HTTP response.

šŸ” RouterResponsePlugin on GitHub

RouteSchema

Any HTTP action schema Rouzer can execute.

export type RouteSchema = QueryRouteSchema | MutationRouteSchema;

šŸ” RouteSchema on GitHub

RouteSuccessResponse

Response returned by ctx.success(status, body) in route handlers.

export type RouteSuccessResponse = Response & {
    __routeSuccess__: true;
};

šŸ” RouteSuccessResponse on GitHub

RouzerClient

Client type inferred from an HTTP route tree passed to createClient.

export type RouzerClient<TRoutes extends HttpRouteTree = Record<string, never>> = ReturnType<typeof createClient<TRoutes>>;

šŸ” RouzerClient on GitHub

RouzerClientHook

Best-effort observer for generated client action lifecycles.

export type RouzerClientHook = (event: RouzerClientHookEvent) => void;

šŸ” RouzerClientHook on GitHub

RouzerClientHookEvent

Lifecycle event emitted by generated client action functions.

export type RouzerClientHookEvent = {
    type: 'request.start';
    opId: string;
    routeName: string;
    method: string;
    pathPattern: string;
    payload: unknown;
} | {
    type: 'request.success';
    opId: string;
    routeName: string;
    method: string;
    pathPattern: string;
    payload: unknown;
    response: unknown;
    status?: number;
    durationMs: number;
} | {
    type: 'request.error';
    opId: string;
    routeName: string;
    method: string;
    pathPattern: string;
    payload: unknown;
    error: unknown;
    status?: number;
    durationMs: number;
};

šŸ” RouzerClientHookEvent on GitHub

Unchecked

Compile-time-only marker used by $type<T>() to carry an unchecked response type through route declarations.

export type Unchecked<T> = Record<number, unknown> & {
    __unchecked__: T;
};

Remarks

Consumers usually use $type<T>() instead of constructing this type directly.

šŸ” Unchecked on GitHub

UncheckedError

Compile-time-only marker used by $error<T>() to carry a declared error response type through route declarations.

export type UncheckedError<T> = {
    __uncheckedError__: T;
};

Remarks

Consumers usually use $error<T>() instead of constructing this type directly.

šŸ” UncheckedError on GitHub

import type { RoutePattern } from '@remix-run/route-pattern';

Constants

responsePluginMarker

Runtime key carried by response plugin markers.

export const responsePluginMarker: unique symbol;

šŸ” responsePluginMarker on GitHub

responsePluginMarker

Runtime key carried by response plugin markers.

export const responsePluginMarker: unique symbol;

šŸ” responsePluginMarker on GitHub

import { ApplyMiddleware, chain, ExtractMiddleware, MiddlewareChain, MiddlewareTypes, RequestHandler } from 'alien-middleware';
import type { MatchParams } from '@remix-run/route-pattern/match';

Classes

Any

class Any {
    private isAny;
}

šŸ” Any on GitHub

import type { MatchParams } from '@remix-run/route-pattern/match';
import type { AnyMiddlewareChain, MiddlewareContext } from 'alien-middleware';
import type { AnyMiddlewareChain } from 'alien-middleware';