@universal-middleware/h3
Version:
h3 adapter for universal middlewares
37 lines (33 loc) • 2.11 kB
TypeScript
import * as h3 from 'h3';
import { EventHandler, H3Event, App } from 'h3';
export { App } from 'h3';
import { contextSymbol, Get, UniversalHandler, UniversalFn, UniversalMiddleware, UniversalRouter, UniversalRouterInterface, EnhancedMiddleware } from '@universal-middleware/core';
type H3Handler<In extends Universal.Context> = UniversalFn<UniversalHandler<In>, EventHandler>;
type H3Middleware<In extends Universal.Context, Out extends Universal.Context> = UniversalFn<UniversalMiddleware<In, Out>, EventHandler>;
declare const pendingMiddlewaresSymbol: unique symbol;
declare const wrappedResponseSymbol: unique symbol;
declare module "h3" {
interface H3EventContext {
[contextSymbol]?: Universal.Context;
[wrappedResponseSymbol]?: boolean;
[pendingMiddlewaresSymbol]?: ((response: Response) => Response | Promise<Response> | undefined | Promise<undefined>)[];
}
}
/**
* Creates a request handler to be passed to app.all() or any other route function
*/
declare function createHandler<T extends unknown[], InContext extends Universal.Context>(handlerFactory: Get<T, UniversalHandler<InContext>>): Get<T, H3Handler<InContext>>;
declare const universalOnBeforeResponse: h3._ResponseMiddleware<h3.EventHandlerRequest, any>;
/**
* Creates a middleware to be passed to app.use() or any route function
*/
declare function createMiddleware<T extends unknown[], InContext extends Universal.Context, OutContext extends Universal.Context>(middlewareFactory: Get<T, UniversalMiddleware<InContext, OutContext>>): Get<T, H3Middleware<InContext, OutContext>>;
declare function getContext<Context extends Universal.Context>(event: H3Event): Context;
declare class UniversalH3Router extends UniversalRouter implements UniversalRouterInterface {
#private;
constructor(app: App);
use(middleware: EnhancedMiddleware): this;
applyCatchAll(): this;
}
declare function apply(app: App, middlewares: EnhancedMiddleware[]): void;
export { type H3Handler, type H3Middleware, UniversalH3Router, apply, createHandler, createMiddleware, getContext, universalOnBeforeResponse };