import type { RouteSchema } from 'elysia' import type { EdenFetchError, MapError } from './errors' import type { IsNever, IsUnknown, ReplaceGeneratorWithAsyncGenerator } from './utils/types' type Files = File | FileList type ReplaceBlobWithFiles> = { [K in keyof RecordType]: RecordType[K] extends Blob | Blob[] ? Files : RecordType[K] } & {} /** */ export type InferRouteOptions< TRoute extends RouteSchema = RouteSchema, /** * Helper for removing certain properties from the input, e.g. "cursor" for infinite queries... */ TOmitInput extends string | number | symbol = never, > = (IsNever extends true ? { params?: Record } : { params: Omit }) & (IsNever extends true ? { query?: Record } : { query: Omit }) & (undefined extends TRoute['headers'] ? { headers?: Record } : { headers: TRoute['headers'] }) export type InferRouteBody< TRoute extends RouteSchema = RouteSchema, /** * Helper for removing certain properties from the input, e.g. "cursor" for infinite queries... */ TOmitInput extends string | number | symbol = never, > = IsUnknown extends false ? undefined extends TRoute['body'] ? ReplaceBlobWithFiles> | undefined : ReplaceBlobWithFiles> : unknown /** * Only returns the output for a successful response. */ export type InferRouteOutput = TRoute['response'] extends Record ? ReplaceGeneratorWithAsyncGenerator[200] : never export type InferRouteError = Record> = MapError extends infer Errors ? IsNever extends true ? EdenFetchError : Errors : EdenFetchError /** * Untyped eden-treaty response. Will either return nullish data and defined error, or vice versa. * Look at concrete implementation of eden-treaty for strongly-typed variant. */ export type TreatyResponse> = | { data: Res[200] error: null response: Response status: number headers: BunFetchRequestInit['headers'] } | { data: null error: Exclude extends never ? { status: unknown value: unknown } : { [Status in keyof Res]: { status: Status value: Res[Status] } }[Exclude] response: Response status: number headers: BunFetchRequestInit['headers'] } /** * Returns map of status codes to response types. */ export type InferRouteOutputAll = TRoute['response'] extends Record ? ReplaceGeneratorWithAsyncGenerator : never /** * Strongly typed route response. */ export type InferRouteResponse = TreatyResponse< InferRouteOutputAll >