import { KebabToCamel } from "./type-utils.mjs"; import { HTTPMethod, QueryParams } from "./types.mjs"; //#region src/plugin.d.ts /** * Route filter for hooks. Matches the stable route path, so client overrides do * not change which hooks run. */ type RouteMatcher = string | readonly string[] | ((ctx: { path: string; }) => boolean); /** * Mutable request context passed to `beforeRequest` hooks. Return the updated * context, or throw to abort the request. */ type RequestContext = { method: HTTPMethod; /** Path relative to `baseURL` (already includes the configured `basePath`). */ fullPath: string; /** Path relative to the client `basePath`. */ path: string; /** Stable route identifier, unaffected by client overrides. */ routePath: string; /** Full request URL. */ url: string; headers: Headers; body: unknown; }; /** * Mutable response context passed to `afterResponse` hooks. The body has * already been envelope-unwrapped. */ type ResponseContext = Omit & { /** Status code. */status: number; /** Whether the response is successful. */ ok: boolean; }; type BeforeRequestHook = { /** Optional route filter. Omit to run for every request. */match?: RouteMatcher; run: (req: RequestContext) => RequestContext | Promise; }; type AfterResponseHook = { match?: RouteMatcher; /** Run even for failed responses. */ allowOnFailure?: boolean; run: (res: ResponseContext) => ResponseContext | Promise; }; /** * Request and response hooks contributed by a plugin. */ type PluginHooks = { beforeRequest?: BeforeRequestHook[]; afterResponse?: AfterResponseHook[]; }; /** Options accepted by `ctx.fetch(path, init)`. */ type FetchInit = { method?: HTTPMethod; /** JSON body. The fetcher stringifies. */ body?: unknown; /** Appended as `?k=v` query string. */ query?: QueryParams; /** * Headers merged into the request, on top of the default `Content-Type` / * `Accept`. A per-request value overrides the client default. */ headers?: HeadersInit; /** * Resolve `path` from the client base path instead of the plugin base path. */ absolute?: boolean; /** * Request timeout in ms; `0` disables. Defaults to 30s. A per-request value * overrides the client default. */ timeout?: number; }; type FetchOptions = Omit; type PluginIdOf

= P extends { readonly id: infer Id extends string; } ? Id : never; type PluginClientOverride = { /** Replace the plugin's default base path (relative to the client `basePath`). */basePath?: string; }; /** * Per-plugin client overrides, keyed by camelCased plugin id. */ type PluginOverrides = Partial>, PluginClientOverride>>; //#endregion export { AfterResponseHook, BeforeRequestHook, FetchInit, FetchOptions, PluginClientOverride, PluginHooks, PluginIdOf, PluginOverrides, RequestContext, ResponseContext, RouteMatcher };