@fiberplane/hono-otel
Version:
Hono middleware to forward OpenTelemetry traces to a local instance of @fiberplane/studio
47 lines (46 loc) • 1.54 kB
TypeScript
/**
* Before you try to import Hono and use its types,
* it's good to know that Hono's types are not compatible across
* independently installed versions of Hono.
*
* I've kept *commented out* Hono derived types below for reference,
* so you know that they will not work.
*
* @TODO - Investigate requiring Hono as a peer dependency.
*/
import type { Bindings } from "hono/types";
type GlobalFetch = typeof globalThis.fetch;
type GlobalFetchArgs = Parameters<GlobalFetch>;
export type GlobalResponse = Awaited<ReturnType<GlobalFetch>>;
export type InputParam = GlobalFetchArgs[0];
export type InitParam = GlobalFetchArgs[1];
/**
* The type of the `env` parameter in the `fetch` function for a Hono app
*/
export type HonoLikeEnv = {} | Bindings | undefined;
/**
* Hack type to make our library's types play nicely with Hono types.
*/
export type HonoFetchResult = Response | Promise<Response>;
/**
* Hack type to make our library's types play nicely with Hono types.
*/
export type HonoResponse = Awaited<HonoFetchResult>;
/**
* Hack type to make our library's types play nicely with Hono types.
*/
export type HonoLikeFetch = (request: Request, env: HonoLikeEnv, executionContext?: ExecutionContext) => HonoFetchResult;
/**
* Hack type to make our library's types play nicely with Hono types.
*/
export type HonoLikeApp = {
fetch: HonoLikeFetch;
routes: RouterRoute[];
getOpenAPIDocument?: (...args: any[]) => any;
};
type RouterRoute = {
method: string;
path: string;
handler: Function;
};
export {};