UNPKG

midwinter

Version:

A next-gen middleware engine built for the WinterCG environments.

23 lines (20 loc) 1.49 kB
import { c as RequestHandler } from './types-DRjmZIz8.mjs'; import { S as Strip, M as MergeObjectsShallow } from './util-CHs1TI3T.mjs'; import { InferTypeof, TypeKey } from './util.mjs'; import 'midwinter'; type InferConfig<THandler extends RequestHandler> = THandler extends RequestHandler<infer $Meta, any> ? Strip<{ Query: InferTypeof<$Meta[TypeKey<"Query_In">]>; Params: $Meta["params"] extends string[] ? MergeObjectsShallow<{ [Key in $Meta["params"][number]]: string; }, InferTypeof<$Meta[TypeKey<"Params_In">], {}>> : InferTypeof<$Meta[TypeKey<"Params_In">]>; Body: InferTypeof<$Meta[TypeKey<"Body_In">]>; Output: InferTypeof<$Meta[TypeKey<"Output_Out">]>; }, never> : never; type FormatMethod<T extends string> = T extends "*" ? string : T; type InferMethod<THandler extends RequestHandler> = THandler extends RequestHandler<infer $Meta, any> ? $Meta["method"] extends string ? FormatMethod<$Meta["method"]> : $Meta["method"] extends string[] ? FormatMethod<$Meta["method"][number]> : never : never; type InferPath<THandler extends RequestHandler> = THandler["meta"]["path"] extends string ? THandler["meta"]["path"] : never; type InferAppInput = Record<PropertyKey, RequestHandler>; type InferApp<TInput extends InferAppInput> = { [Key in keyof TInput as `${Uppercase<InferMethod<TInput[Key]>>} ${InferPath<TInput[Key]>}`]: InferConfig<TInput[Key]>; }; export type { FormatMethod, InferApp, InferAppInput, InferConfig, InferMethod, InferPath };