@universal-middleware/hattip
Version:
Hattip adapter for universal middlewares
35 lines (31 loc) • 2.12 kB
TypeScript
import { RequestHandler } from '@hattip/compose';
import { HattipHandler as HattipHandler$1, AdapterRequestContext } from '@hattip/core';
import { contextSymbol, UniversalFn, UniversalHandler, UniversalMiddleware, Get, 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;
type EnhancedMiddlewareHattip = EnhancedMiddleware | EnhancedMiddleware<Universal.Context, Universal.Context, "hattip">;
declare class UniversalHattipRouter extends UniversalRouter implements UniversalRouterInterface {
#private;
constructor(app: App);
use(middleware: EnhancedMiddlewareHattip): this;
applyCatchAll(): this;
}
declare function apply(app: App, middlewares: EnhancedMiddlewareHattip[]): void;
export { type App, type HattipHandler, type HattipMiddleware, UniversalHattipRouter, apply, createHandler, createMiddleware, getContext, getRuntime };