@universal-middleware/hattip
Version:
Hattip adapter for universal middlewares
34 lines (30 loc) • 1.98 kB
TypeScript
import { RequestHandler } from '@hattip/compose';
import { HattipHandler as HattipHandler$1, AdapterRequestContext } from '@hattip/core';
import { contextSymbol, Get, UniversalHandler, UniversalFn, UniversalMiddleware, RuntimeAdapter, UniversalRouter, UniversalRouterInterface, EnhancedMiddleware } from '@universal-middleware/core';
import { Router } from '@hattip/router';
declare module "@hattip/core" {
interface AdapterRequestContext {
[contextSymbol]?: Universal.Context;
}
}
type HattipHandler<In extends Universal.Context> = UniversalFn<UniversalHandler<In>, HattipHandler$1>;
type HattipMiddleware<In extends Universal.Context, Out extends Universal.Context> = UniversalFn<UniversalMiddleware<In, Out>, RequestHandler>;
/**
* Creates a request handler to be passed to hattip
*/
declare function createHandler<T extends unknown[], InContext extends Universal.Context>(handlerFactory: Get<T, UniversalHandler<InContext>>): Get<T, HattipHandler<InContext>>;
/**
* Creates a middleware to be passed to @hattip/compose or @hattip/router
*/
declare function createMiddleware<T extends unknown[], InContext extends Universal.Context, OutContext extends Universal.Context>(middlewareFactory: Get<T, UniversalMiddleware<InContext, OutContext>>): Get<T, HattipMiddleware<InContext, OutContext>>;
declare function getContext<InContext extends Universal.Context = Universal.Context>(context: AdapterRequestContext): InContext;
declare function getRuntime(context: AdapterRequestContext): RuntimeAdapter;
type App = Router;
declare class UniversalHattipRouter extends UniversalRouter implements UniversalRouterInterface {
#private;
constructor(app: App);
use(middleware: EnhancedMiddleware): this;
applyCatchAll(): this;
}
declare function apply(app: App, middlewares: EnhancedMiddleware[]): void;
export { type App, type HattipHandler, type HattipMiddleware, UniversalHattipRouter, apply, createHandler, createMiddleware, getContext, getRuntime };