import { HonoBase } from "hono/hono-base"; import { Hono } from "hono"; import { ClientResponse, InferRequestType, hc } from "hono/client"; import { ExtractSchema, Schema as Schema$1 } from "hono/types"; //#region src/types/openapi.d.ts type ConvertPath

= P extends `${infer A}{${infer Param}}${infer B}` ? `${A}:${Param}${ConvertPath}` : P; type HttpMethod = "get" | "query" | "put" | "post" | "delete" | "options" | "head" | "patch" | "trace"; declare const optionalResponseStatuses: unique symbol; type WithOptionalResponseStatuses = Paths & { readonly [optionalResponseStatuses]?: Status; }; type ExtractOptionalResponseStatuses = Paths extends { readonly [optionalResponseStatuses]?: infer Status; } ? Extract : never; type NormalizeBasePathInner = BasePath extends `${infer Prefix}/` ? NormalizeBasePathInner : BasePath; type NormalizeBasePath = BasePath extends "" | "/" ? "" : NormalizeBasePathInner; type StripBasePath = NormalizeBasePath extends (infer NormalizedBasePath extends string) ? NormalizedBasePath extends "" ? Path : Path extends NormalizedBasePath ? "/" : Path extends `${NormalizedBasePath}/${infer Rest}` ? `/${Rest}` : never : never; type ParameterLocation = "path" | "query" | "header" | "cookie"; type ExtractParameterRecord = Source extends { parameters: infer Parameters extends object; } ? Location extends keyof Parameters ? NonNullable extends object ? NonNullable : never : never : never; type ExtractMergedParameterRecord = [ExtractParameterRecord] extends [never] ? ExtractParameterRecord : ExtractParameterRecord; type ExtractRequestBodyContent = Op extends { requestBody: { content: infer Content extends object; }; } ? ContentType extends keyof Content ? Content[ContentType] : never : never; type ExtractParam = ExtractMergedParameterRecord; type ExtractQuery = ExtractMergedParameterRecord; type ExtractHeader = ExtractMergedParameterRecord; type ExtractCookie = ExtractMergedParameterRecord; type ExtractJsonBody = ExtractRequestBodyContent; type ExtractFormBody = ExtractRequestBodyContent | ExtractRequestBodyContent; type HttpStatusFromKey = Key extends number ? Key : Key extends `${infer Status extends number}` ? Status : never; type ExtractResponseContent = Response extends { content: infer Content; } ? NonNullable extends object ? NonNullable : never : Response extends { content?: infer Content; } ? NonNullable extends object ? NonNullable : never : never; type OutputFormatForContentType = ContentType extends "application/json" | `${string}+json` ? "json" : ContentType extends "text/plain" ? "text" : "body"; type IntoHonoInput = ([ExtractParam] extends [never] ? object : { param: ExtractParam; }) & ([ExtractQuery] extends [never] ? object : { query: ExtractQuery; }) & ([ExtractHeader] extends [never] ? object : { header: ExtractHeader; }) & ([ExtractCookie] extends [never] ? object : { cookie: ExtractCookie; }) & ([ExtractJsonBody] extends [never] ? object : { json: ExtractJsonBody; }) & ([ExtractFormBody] extends [never] ? object : { form: ExtractFormBody; }); type IntoHonoResponseWithContent = { [ContentType in keyof Content & string]: { input: IntoHonoInput; output: Content[ContentType]; outputFormat: OutputFormatForContentType; status: Status; responseLabel: `${Status} ${ContentType}`; }; }[keyof Content & string]; type IntoHonoEmptyResponse = { input: IntoHonoInput; output: null; outputFormat: "body"; status: Status; responseLabel: `${Status} no content`; }; type IntoHonoResponse = HttpStatusFromKey extends (infer Status) ? [Status] extends [never] ? never : Status extends number ? [ExtractResponseContent] extends [never] ? IntoHonoEmptyResponse : ExtractResponseContent extends (infer Content extends object) ? IntoHonoResponseWithContent : never : never : never; type IntoHonoMethod = Op extends { responses: infer Responses extends object; } ? { [ResponseKey in keyof Responses]: IntoHonoResponse; }[keyof Responses] : { input: IntoHonoInput; }; type IntoHonoMethodOrInputOnly = [IntoHonoMethod] extends [never] ? { input: IntoHonoInput; } : IntoHonoMethod; type IntoHonoEndpoint = IntoHonoMethodOrInputOnly; type IntoSchemaMethod = IntoHonoEndpoint; type IntoSchema = { [P in keyof Paths as [StripBasePath

] extends [never] ? never : ConvertPath & string>]: { [M in keyof Paths[P] & HttpMethod as [NonNullable] extends [never] ? never : `$${M}`]: IntoSchemaMethod>; }; }; //#endregion //#region src/types/utility.d.ts type PrettyMethod = Method extends `$${infer Raw}` ? Uppercase : Uppercase; type UnionToIntersection = (Union extends unknown ? (arg: Union) => void : never) extends ((arg: infer Intersection) => void) ? Intersection : never; type NormalizeReason = [ReasonUnion] extends [never] ? unknown : UnionToIntersection; //#endregion //#region src/types/hono.d.ts type AnyHono = HonoBase; type SchemaPathEntry = { path: string; methods: Record; }; type SchemaEntries = Schema extends Record ? { [Path in keyof Schema & string]: { path: Path; methods: Schema[Path]; }; }[keyof Schema & string] : never; type NormalizeSchemaEntries = SchemaEntries extends (infer Entry) ? Entry extends SchemaPathEntry ? { path: Entry["path"]; methods: Entry["methods"]; } : never : never; type ExpectedEntries = NormalizeSchemaEntries>; type HonoClientReservedKey = "$path" | "$url" | "$ws"; type HonoClientForSchemaPath = App extends HonoBase ? ReturnType, BasePath>, "">> : never; type EndpointFromClientResponse = Response extends ClientResponse ? { input: Input; output: Output; outputFormat: Format; status: Status; } : never; type EndpointFromClientMethod = Method extends ((...args: any[]) => Promise) ? EndpointFromClientResponse> : never; type ClientEndpointMethods = { [Method in keyof Client & string as Method extends `$${string}` ? Method extends HonoClientReservedKey ? never : [EndpointFromClientMethod] extends [never] ? never : Method : never]: EndpointFromClientMethod; }; type TrimClientPathStartSlash = Path extends `/${infer Rest}` ? TrimClientPathStartSlash : Path; type ClientNodeAtPathSegments = Segments extends "" ? Client extends { index: infer Node; } ? Node : never : Segments extends `${infer Head}/${infer Rest}` ? Head extends keyof Client ? ClientNodeAtPathSegments : never : Segments extends keyof Client ? Client[Segments] : never; type ClientNodeAtPath = ClientNodeAtPathSegments>; type ActualEntryFromSchemaPath = ClientEndpointMethods, Path>> extends (infer Methods extends Record) ? [keyof Methods] extends [never] ? never : { path: Path; methods: Methods; } : never; type ActualEntries = ExtractSchema extends (infer Schema extends Schema$1) ? { [Path in keyof Schema & string]: ActualEntryFromSchemaPath; }[keyof Schema & string] : never; type PathMethodTableFromEntries = UnionToIntersection; } ? { [Key in Path]: Methods; } : never>; type ActualMethodTable = PathMethodTableFromEntries>; type FindActualMethodsForPath = Path extends keyof ActualMethodTable ? ActualMethodTable[Path] : never; type BasePathScopeReason = { [Key in `Base path ${NormalizeBasePath} has no matching OpenAPI paths`]: never; }; type CheckBasePathScope = NormalizeBasePath extends "" ? never : [ExpectedEntries] extends [never] ? BasePathScopeReason : never; type InputTarget = "param" | "query" | "header" | "cookie" | "json" | "form"; type ExpectedInputTargets = keyof ExpectedInput & InputTarget; type PrettyInputTarget = Target extends "param" ? "Path" : Target extends "json" ? "JSON" : Capitalize; type InputMismatchReason = { [Key in `${PrettyInputTarget} input mismatch at ${PrettyMethod} ${Path}`]: never; }; type InputTargetValue = Target extends keyof Input ? Input[Target] : never; type NarrowStringInput = [Exclude] extends [string] ? string extends Exclude ? never : Exclude : never; type HasArrayInput = [Extract, readonly unknown[] | unknown[]>] extends [never] ? false : true; type IsStringInputCompatible = [NarrowStringInput] extends [never] ? string extends ActualValue ? true : false : NarrowStringInput extends ActualValue ? true : false; type IsQueryInputCompatible = HasArrayInput extends true ? string[] extends ActualValue ? true : false : IsStringInputCompatible; type IsFormInputCompatible = HasArrayInput extends true ? string[] extends ActualValue ? true : false : IsStringInputCompatible; type AreTargetPropertiesCompatible, ExpectedTargetInput extends object, ActualTargetInput extends object> = [keyof ExpectedTargetInput] extends [never] ? true : false extends { [Key in keyof ExpectedTargetInput]-?: Key extends keyof ActualTargetInput ? Target extends "query" ? IsQueryInputCompatible : Target extends "form" ? IsFormInputCompatible : IsStringInputCompatible : false; }[keyof ExpectedTargetInput] ? false : true; type IsInputTargetCompatible> = Target extends keyof ActualInput ? Target extends "json" ? [InputTargetValue] extends [InputTargetValue] ? true : false : InputTargetValue extends object ? InputTargetValue extends object ? AreTargetPropertiesCompatible, InputTargetValue, InputTargetValue> : false : false : false; type CheckMethodInputTargetCompatibility> = [ActualMethod extends unknown ? ActualMethod extends { input: infer ActualInput extends object; } ? IsInputTargetCompatible extends true ? ActualInput : never : never : never] extends [never] ? InputMismatchReason : never; type CheckMethodInputCompatibility = ExpectedMethod extends { input: infer ExpectedInput extends object; } ? [ExpectedInputTargets] extends [never] ? never : { [Target in ExpectedInputTargets]: CheckMethodInputTargetCompatibility; }[ExpectedInputTargets] : never; type OutputMismatchReason