@fedify/hono
Version:
Integrate Fedify with Hono
37 lines (35 loc) • 1.56 kB
TypeScript
import { Federation } from "@fedify/fedify/federation";
//#region src/mod.d.ts
interface HonoRequest {
raw: Request;
}
interface HonoContext {
req: HonoRequest;
res: Response;
}
type HonoMiddleware<THonoContext extends HonoContext> = (ctx: THonoContext, next: () => Promise<void>) => Promise<Response | void>;
/**
* A factory function to create a context data for the {@link Federation}
* object.
*
* @template TContextData A type of the context data for the {@link Federation}
* object.
* @template THonoContext A type of the Hono context.
* @param context A Hono context object.
* @returns A context data for the {@link Federation} object.
*/
type ContextDataFactory<TContextData, THonoContext> = (context: THonoContext) => TContextData | Promise<TContextData>;
/**
* Create a Hono middleware to integrate with the {@link Federation} object.
*
* @template TContextData A type of the context data for the {@link Federation}
* object.
* @template THonoContext A type of the Hono context.
* @param federation A {@link Federation} object to integrate with Hono.
* @param contextDataFactory A function to create a context data for the
* {@link Federation} object.
* @returns A Hono middleware.
*/
declare function federation<TContextData, THonoContext extends HonoContext>(federation: Federation<TContextData>, contextDataFactory: ContextDataFactory<TContextData, THonoContext>): HonoMiddleware<THonoContext>;
//#endregion
export { ContextDataFactory, federation };