@fedify/h3
Version:
Integrate Fedify with h3
32 lines (31 loc) • 1.56 kB
text/typescript
import { Federation } from "@fedify/fedify";
import { EventHandler, EventHandlerRequest, EventHandlerResponse, H3Error, H3Event } from "h3";
//#region src/index.d.ts
/**
* A factory function that creates the context data that will be passed to the
* `Federation` instance.
* @template TContextData The type of the context data that will be passed to
* the `Federation` instance.
* @param event The event that triggered the handler.
* @param request The request that triggered the handler.
* @returns The context data that will be passed to the `Federation` instance.
* This can be a promise that resolves to the context data.
*/
type ContextDataFactory<TContextData> = (event: H3Event<EventHandlerRequest>, request: Request) => Promise<TContextData> | TContextData;
/**
* Integrates a `Federation` instance with an H3 handler.
* @param federation
* @param contextDataFactory
* @returns
*/
declare function integrateFederation<TContextData>(federation: Federation<TContextData>, contextDataFactory: ContextDataFactory<TContextData>): EventHandler<EventHandlerRequest, EventHandlerResponse>;
/**
* An error handler that responds with a 406 Not Acceptable if Fedify
* responded with a 406 Not Acceptable and the actual handler responded with
* a 404 Not Found.
* @param error The error that occurred.
* @param event The event that triggered the handler.
*/
declare function onError(error: H3Error<unknown>, event: H3Event<EventHandlerResponse>): Promise<void>;
//#endregion
export { ContextDataFactory, integrateFederation, onError };