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